@webority/chat-react 0.128.0 → 0.133.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/dist/chat-react.js +14 -11
  2. package/dist/types/ChatAgentTyping.d.ts +4 -0
  3. package/dist/types/ChatAuthorBadge.d.ts +4 -0
  4. package/dist/types/ChatComposer.d.ts +10 -0
  5. package/dist/types/ChatConversationActions.d.ts +7 -0
  6. package/dist/types/ChatEmbed.d.ts +5 -0
  7. package/dist/types/ChatExplain.d.ts +16 -0
  8. package/dist/types/ChatFooter.d.ts +8 -0
  9. package/dist/types/ChatFrame.d.ts +26 -0
  10. package/dist/types/ChatHistory.d.ts +9 -0
  11. package/dist/types/ChatLauncher.d.ts +5 -0
  12. package/dist/types/ChatLiveStatus.d.ts +4 -0
  13. package/dist/types/ChatMessageActions.d.ts +10 -0
  14. package/dist/types/ChatNudge.d.ts +10 -0
  15. package/dist/types/ChatOpenTickets.d.ts +9 -0
  16. package/dist/types/ChatPage.d.ts +49 -0
  17. package/dist/types/ChatPanel.d.ts +9 -0
  18. package/dist/types/ChatPastChats.d.ts +9 -0
  19. package/dist/types/ChatReadAloudButton.d.ts +8 -0
  20. package/dist/types/ChatShell.d.ts +32 -0
  21. package/dist/types/ChatStarters.d.ts +8 -0
  22. package/dist/types/ChatThread.d.ts +15 -0
  23. package/dist/types/chatLive.d.ts +5 -0
  24. package/dist/types/chatPrint.d.ts +5 -0
  25. package/dist/types/chatShared.d.ts +10 -0
  26. package/dist/types/dictationText.d.ts +31 -0
  27. package/dist/types/index.d.ts +20 -14
  28. package/dist/types/loaders/ChatLoader.d.ts +21 -0
  29. package/dist/types/loaders/OrbLoader.d.ts +11 -0
  30. package/dist/types/loaders/PhrasesLoader.d.ts +14 -0
  31. package/dist/types/loaders/SkeletonLoader.d.ts +11 -0
  32. package/dist/types/loaders/StepsLoader.d.ts +12 -0
  33. package/dist/types/loaders/TypingPill.d.ts +12 -0
  34. package/dist/types/renderers/ActionPart.d.ts +4 -0
  35. package/dist/types/renderers/ChartPart.d.ts +4 -0
  36. package/dist/types/renderers/ChatLinkContext.d.ts +8 -0
  37. package/dist/types/renderers/FigureText.d.ts +5 -0
  38. package/dist/types/renderers/FiguresPart.d.ts +4 -0
  39. package/dist/types/renderers/FilePart.d.ts +4 -0
  40. package/dist/types/renderers/HandoffPart.d.ts +4 -0
  41. package/dist/types/renderers/ImagePart.d.ts +4 -0
  42. package/dist/types/renderers/InputRequestPart.d.ts +5 -0
  43. package/dist/types/renderers/NoticePart.d.ts +3 -0
  44. package/dist/types/renderers/QuickRepliesPart.d.ts +4 -0
  45. package/dist/types/renderers/RecordCardPart.d.ts +4 -0
  46. package/dist/types/renderers/SourcesPart.d.ts +4 -0
  47. package/dist/types/renderers/TablePart.d.ts +4 -0
  48. package/dist/types/renderers/TextPart.d.ts +5 -0
  49. package/dist/types/renderers/TicketPart.d.ts +4 -0
  50. package/dist/types/renderers/VoiceClipPart.d.ts +7 -0
  51. package/dist/types/renderers/index.d.ts +32 -0
  52. package/dist/types/useAutoOpen.d.ts +11 -0
  53. package/dist/types/useChat.d.ts +34 -76
  54. package/dist/types/useChatDictation.d.ts +24 -0
  55. package/dist/types/useChatExplain.d.ts +57 -0
  56. package/dist/types/useChatHandoff.d.ts +19 -0
  57. package/dist/types/useChatReadAloud.d.ts +16 -0
  58. package/dist/types/useChatSound.d.ts +5 -0
  59. package/dist/types/useChatSpeech.d.ts +7 -0
  60. package/dist/types/useLauncherAvoid.d.ts +1 -0
  61. package/dist/types/useReducedMotion.d.ts +1 -0
  62. package/dist/types/useTranscriptActions.d.ts +12 -0
  63. package/package.json +18 -20
  64. package/README.md +0 -320
  65. package/dist/guidance.json +0 -216
  66. package/dist/types/ChatMarkdown.meta.d.ts +0 -31
  67. package/dist/types/components/ActionCard.d.ts +0 -27
  68. package/dist/types/components/ActionCard.meta.d.ts +0 -89
  69. package/dist/types/components/ChatComposer.d.ts +0 -38
  70. package/dist/types/components/ChatComposer.meta.d.ts +0 -56
  71. package/dist/types/components/ChatConversationList.d.ts +0 -20
  72. package/dist/types/components/ChatConversationList.meta.d.ts +0 -37
  73. package/dist/types/components/ChatLauncher.d.ts +0 -31
  74. package/dist/types/components/ChatLauncher.meta.d.ts +0 -50
  75. package/dist/types/components/ChatMessage.d.ts +0 -61
  76. package/dist/types/components/ChatMessage.meta.d.ts +0 -173
  77. package/dist/types/components/ChatPanel.d.ts +0 -74
  78. package/dist/types/components/ChatPanel.meta.d.ts +0 -228
  79. package/dist/types/components/ChatThread.d.ts +0 -54
  80. package/dist/types/components/ChatThread.meta.d.ts +0 -151
  81. package/dist/types/components/CitationChip.d.ts +0 -15
  82. package/dist/types/components/CitationChip.meta.d.ts +0 -48
  83. package/dist/types/components/ComposerAttachments.d.ts +0 -14
  84. package/dist/types/components/ConfirmCard.d.ts +0 -24
  85. package/dist/types/components/ConfirmCard.meta.d.ts +0 -43
  86. package/dist/types/components/ReplyRating.d.ts +0 -16
  87. package/dist/types/components/ReplyRating.meta.d.ts +0 -34
  88. package/dist/types/markdown.d.ts +0 -22
  89. /package/{LICENSE → LICENSE.txt} +0 -0
@@ -1,11 +1,14 @@
1
- import{AppActionIcon as e,AppAlert as t,AppButton as n,AppCard as r,AppChip as i,AppChipGroup as a,AppConfirmDialog as o,AppCopyButton as s,AppDrawer as c,AppEmptyState as l,AppIcon as u,AppInput as d,AppMarkdown as f,AppProgress as p,AppSkeleton as m,AppSpinner as h,AppTextarea as g,useFloatingStack as _}from"@webority/ui-react";import{memo as v,useEffect as y,useId as b,useMemo as x,useRef as S,useState as C,useSyncExternalStore as w}from"react";import{Fragment as T,jsx as E,jsxs as D}from"react/jsx-runtime";import{formatDateTime as O}from"@webority/ui-elements/helpers";import{createPortal as k}from"react-dom";var A=/\[([^[\]\n]+)\](?!\()/g;function j(e,t){let n=[],r=0;A.lastIndex=0;for(let i of e.matchAll(A)){let a=i[1];t(a)&&(i.index>r&&n.push({text:e.slice(r,i.index)}),n.push({citation:a}),r=i.index+i[0].length)}return r<e.length&&n.push({text:e.slice(r)}),n}var M=/* @__PURE__ */ new Set(`!"#$%&'()*+,-./:;<=>?@[\\]^_\`{|}~`),N=/\[([^\]\n]+)\]\(((?:[^()\s]|\([^()\s]*\))+)\)/y,P=/!\[([^\]\n]*)\]\(((?:[^()\s]|\([^()\s]*\))+)\)/y,F=new RegExp(A.source,`y`),I=e=>/[\p{L}\p{N}]/u.test(e);function L(e,t){let n=0;for(let r=t-1;r>=0&&e.charAt(r)===`\\`;--r)n+=1;return n%2==1}function R(e,t,n){let r=n.length===1;for(let i=e.indexOf(n,t);i!==-1;i=e.indexOf(n,i+1)){let a=i>t&&!/\s/.test(e.charAt(t))&&!/\s/.test(e.charAt(i-1)),o=r&&(e.charAt(i+1)===n||e.charAt(i-1)===n),s=n===`_`&&I(e.charAt(i+n.length));if(a&&!o&&!s&&!L(e,i))return i}return-1}function z(e,t){let n=t?.isCitation,r=[],i=``,a=()=>{i&&=(r.push({type:`text`,text:i}),``)},o=0;for(;o<e.length;){let s=e.charAt(o),c=e.charAt(o+1);if(s===`\\`&&M.has(c)){i+=c,o+=2;continue}if(s==="`"){let t=e.indexOf("`",o+1);if(t>o+1){a(),r.push({type:`code`,text:e.slice(o+1,t)}),o=t+1;continue}}let l=s+c;if(l===`**`||l===`__`||l===`~~`){let n=R(e,o+2,l);if(n!==-1&&!(l===`__`&&I(e.charAt(o-1)))){a();let i=z(e.slice(o+2,n),t);l===`~~`?r.push({type:`strike`,children:i}):r.push({type:`strong`,children:i}),o=n+2;continue}i+=l,o+=2}else{if(s===`*`||s===`_`){let n=R(e,o+1,s);if(n!==-1&&!(s===`_`&&I(e.charAt(o-1)))){a(),r.push({type:`em`,children:z(e.slice(o+1,n),t)}),o=n+1;continue}}if(s===`[`){N.lastIndex=o;let t=N.exec(e);if(t){a(),r.push({type:`link`,href:t[2],children:z(t[1])}),o+=t[0].length;continue}if(n){F.lastIndex=o;let t=F.exec(e);if(t&&n(t[1])){a(),r.push({type:`citation`,text:t[1]}),o+=t[0].length;continue}}}if(s===`!`){P.lastIndex=o;let t=P.exec(e);if(t){a(),r.push({type:`image`,children:z(t[1])}),o+=t[0].length;continue}}i+=s,o+=1}}return a(),r.map((e,t)=>({...e,key:t}))}var B=/^\s*```/,V=/^\s*```\s*(\S*)/,H=/^\s{0,3}(#{1,6})\s+(.*?)(?:\s+#+)?\s*$/,U=/^\s*([-*_])(\s*\1){2,}\s*$/,W=/^(\s*)[-*+]\s+(.*)$/,G=/^(\s*)(\d{1,9})[.)]\s+(.*)$/,ee=/^\s*>\s?(.*)$/,te=/^\s*\|?\s*:?-{3,}:?\s*(\|\s*:?-{3,}:?\s*)*\|?\s*$/,ne=e=>e.includes(`|`);function re(e){let t=e.trim();return t.startsWith(`|`)&&(t=t.slice(1)),t.endsWith(`|`)&&(t=t.slice(0,-1)),t.split(`|`).map(e=>e.trim())}function ie(e,t){return ne(e[t])&&t+1<e.length&&e[t+1].includes(`|`)&&te.test(e[t+1])}function ae(e,t){let n=e[t];return B.test(n)||ee.test(n)||W.test(n)||G.test(n)||H.test(n)||U.test(n)||ie(e,t)}function oe(e){let t=e.replace(/\t/g,` `).length;return Math.min(Math.floor(t/2),4)}function se(e){let t=G.exec(e);if(t)return{text:t[3],depth:oe(t[1]),ordered:!0,number:Number(t[2])};let n=W.exec(e);return n?{text:n[2],depth:oe(n[1]),ordered:!1,number:0}:null}function ce(e){let t=(e??``).replace(/\r\n?/g,`
2
- `).split(`
3
- `),n=[],r=0;for(;r<t.length;){let e=t[r];if(!e.trim()){r+=1;continue}if(B.test(e)){let i=V.exec(e)?.[1]||null,a=[];for(r+=1;r<t.length&&!B.test(t[r]);)a.push(t[r]),r+=1;r+=1,n.push({type:`code`,text:a.join(`
4
- `),language:i});continue}if(ie(t,r)){let i=re(e),a=[];for(r+=2;r<t.length&&t[r].trim()&&ne(t[r]);)a.push(re(t[r])),r+=1;n.push({type:`table`,header:i,rows:a});continue}if(U.test(e)){n.push({type:`rule`}),r+=1;continue}let i=H.exec(e);if(i){n.push({type:`heading`,level:i[1].length,text:i[2]}),r+=1;continue}if(ee.test(e)){let e=[];for(;r<t.length;){let n=ee.exec(t[r]);if(!n)break;e.push(n[1]),r+=1}n.push({type:`quote`,lines:e});continue}let a=se(e);if(a){let e=[];for(;r<t.length&&t[r].trim();){let n=se(t[r]);if(n){if(n.depth===0&&n.ordered!==a.ordered)break;e.push(n)}else if(ae(t,r))break;else e[e.length-1].text+=` ${t[r].trim()}`;r+=1}n.push({type:`list`,ordered:a.ordered,start:a.ordered?a.number:1,items:e});continue}let o=[e];for(r+=1;r<t.length&&t[r].trim()&&!ae(t,r);)o.push(t[r]),r+=1;n.push({type:`paragraph`,lines:o})}return n.map((e,t)=>({...e,key:t}))}var le=e=>e.map(e=>e.type===`text`||e.type===`code`||e.type===`citation`?e.text:le(e.children)).join(``),K=e=>le(z(e));function ue(e){switch(e.type){case`paragraph`:case`quote`:return K(e.lines.join(` `));case`heading`:return K(e.text);case`list`:return e.items.map(e=>K(e.text)).join(`. `);case`table`:return[e.header,...e.rows].map(e=>e.map(K).join(`, `)).join(`. `);case`code`:return e.text;case`rule`:return``}}function de(e){return ce(e).map(ue).filter(Boolean).join(`
5
- `)}var q=Object.freeze({launcher:`Ask the assistant`,panelTitle:`Assistant`,newChat:`New chat`,close:`Close`,thread:`Conversation`,you:`You`,assistant:`Assistant`,thinking:`Thinking`,emptyTitle:`How can I help?`,emptyText:`Ask a question about what you see on this page.`,composer:`Your question`,placeholder:`Ask a question`,send:`Send`,composerHint:`Press Enter to send, Shift and Enter for a new line.`,allowance:e=>e===0?`You have no questions left today.`:e===1?`You have 1 question left today.`:`You have ${e} questions left today.`,disclaimer:`Answers are written by AI and can be wrong. Check anything important.`,loadingConversation:`Loading the conversation`,rateUp:`Helpful`,rateDown:`Not helpful`,rated:`Thanks for the feedback.`,ratingNote:`What was wrong with this answer?`,ratingNoteHint:`Optional.`,ratingNoteSend:`Send`,ratingNoteSkip:`Skip`,ratingFailed:`Your rating did not save. Please try again.`,actionRaiseTicket:`New support ticket`,actionReply:e=>`Reply on ${e}`,actionReopen:e=>`Reopen ${e}`,actionNote:`Nothing is sent until you confirm.`,actionConfirm:`Confirm`,actionDismiss:`Not now`,actionDismissed:`Not sent.`,actionExpired:`This request expired and was not sent. Ask again if you still need it.`,actionFailed:`We could not send this. Please try again.`,actionDone:`Done.`,actionDoneRaiseTicket:e=>`Ticket ${e} raised.`,actionDoneReply:e=>`Your reply was added to ${e}.`,actionDoneReopen:e=>`${e} is open again.`,viewTicket:`View ticket`,conversations:`Past chats`,conversationsEmptyTitle:`No past chats`,conversationsEmptyText:`Your conversations with the assistant show here.`,untitled:`Untitled chat`,deleteConversation:`Delete chat`,deleteConfirmTitle:`Delete this chat?`,deleteConfirmMessage:`The conversation is removed for good.`,deleteConfirm:`Delete`,deleteFailed:`We could not delete this chat. Please try again.`,cancel:`Cancel`,loadMore:`Show more`,loadFailed:`We could not load your chats. Please try again.`,retry:`Try again`,stop:`Stop`,stopped:`Stopped. Your question was not sent.`,regenerate:`New answer`,edit:`Edit`,editing:`Editing your question`,attach:`Attach a file`,attachHint:`Pictures or PDFs.`,removeAttachment:e=>`Remove ${e}`,attachmentUploading:`Uploading`,attachmentFailed:`That file did not upload. Please try again.`,attachmentLimit:e=>`You can attach up to ${e} files.`,assistantOutdated:`The assistant needs an update before it can answer. Please try again later.`,copy:`Copy`,copied:`Copied`,toolStep:e=>`Looking this up`,suggestions:`Suggested questions`,openCitation:e=>`Open ${e}`,renameConversation:`Rename chat`,conversationTitle:`Chat name`,renameSave:`Save`,renameFailed:`We could not rename this chat. Please try again.`,backToChat:`Back to the chat`}),J=e=>e?{...q,...e}:q,fe=e=>{let t=``,n=t=>{let n=`message`,r=[];for(let e of t.split(`
6
- `)){if(e===``||e.startsWith(`:`))continue;let t=e.indexOf(`:`),i=t===-1?e:e.slice(0,t),a=t===-1?``:e.slice(t+1);a.startsWith(` `)&&(a=a.slice(1)),i===`event`?n=a:i===`data`&&r.push(a)}if(r.length===0)return;let i;try{i=JSON.parse(r.join(`
7
- `))}catch{e({name:`error`,data:{code:`invalid-response`,message:null}});return}e({name:n,data:i})};return{push(e){if(!e)return;t=(t+e).replace(/\r\n/g,`
8
- `).replace(/\r(?!$)/g,`
9
- `);let r=t.split(`
10
-
11
- `);t=r.pop()??``;for(let e of r)n(e)},end(){let e=t.replace(/\r$/,``);t=``,e.trim()&&n(e)}}},Y=`Something went wrong. Please try again.`,pe=2,X=class extends Error{code;status;resetsAtUtc;constructor(e,t,n,r=null){super(t),this.name=`ChatApiError`,this.code=e,this.status=n,this.resetsAtUtc=r}},me=e=>{if(typeof e==`string`)try{return JSON.parse(e)}catch{return null}return e??null},he=(e,t)=>!!t?.aborted||e?.code===`ERR_CANCELED`||e?.name===`CanceledError`||e?.name===`AbortError`,ge=(e,t)=>{if(e instanceof X)return e;let n=e;if(he(n,t))return new X(`aborted`,`The request was cancelled.`);let r=n?.response;if(!r)return new X(`network`,Y);let i=me(r.data),a=typeof i?.code==`string`&&i.code?i.code:`unknown`,o=typeof i?.message==`string`&&i.message?i.message:Y,s=typeof i?.resetsAtUtc==`string`?i.resetsAtUtc:null;return new X(a,o,typeof r.status==`number`?r.status:void 0,s)},Z=async e=>{try{return(await e()).data}catch(e){throw ge(e)}},_e=e=>{let t=e?.event?.target;if(t&&typeof t.responseText==`string`&&!(typeof t.status==`number`&&(t.status<200||t.status>=300)))return t.responseText},ve=()=>{let e=globalThis.FormData;if(!e)throw Error(`FormData is not available.`);return new e},ye=e=>typeof e.uri==`string`,be=(e,t)=>{if(ye(t)){e.append(`file`,t);return}let n=t.name;if(typeof n!=`string`||n===``)throw Error(`The file needs a name.`);e.append(`file`,t,n)},xe=(e,{base:t})=>{if(typeof t!=`string`||t.trim()===``)throw TypeError(`createChatClient needs a base path, e.g. { base: "/api/assistant" }.`);let n=t.replace(/\/+$/,``),r=e=>`${n}/conversations/${encodeURIComponent(e)}`,i=e=>`${n}/attachments/${encodeURIComponent(e)}`,a=null,o=async()=>{try{let t=await Z(()=>e.get(`${n}/settings`));if(typeof t?.contractVersion!=`number`||t.contractVersion<2)throw new X(`assistant_outdated`,q.assistantOutdated);return t}catch(e){throw e instanceof X&&e.status===404?new X(`assistant_outdated`,q.assistantOutdated,404):e}},s=()=>(a||=o().catch(e=>{throw a=null,e}),a);return{sendMessage:async({message:t,conversationId:r,pageContext:i,replacesMessageId:a,attachmentIds:o},{signal:c,onEvent:l}={})=>{await s();let u=null,d=null,f=fe(({name:e,data:t})=>{d||u&&e!==`suggestions`||(e===`done`?(u=t,l?.(e,t)):e===`error`?d=t??{}:(e===`delta`||e===`reset`||e===`tool`||e===`actions`||e===`suggestions`)&&l?.(e,t))}),p=0,m=e=>{typeof e!=`string`||e.length<=p||(f.push(e.slice(p)),p=e.length)},h={message:t};r&&(h.conversationId=r),i!=null&&(h.pageContext=i),a&&(h.replacesMessageId=a),o&&o.length>0&&(h.attachmentIds=o);let g;try{g=await e.post(`${n}/chat`,h,{responseType:`text`,headers:{Accept:`text/event-stream`},signal:c,onDownloadProgress:e=>m(_e(e))})}catch(e){throw ge(e,c)}m(g.data),f.end();let _=d;if(_)throw new X(_.code||`unknown`,_.message||Y);let v=u;if(!v)throw new X(`invalid-response`,Y,g.status);return v},getSettings:s,uploadAttachment:async(t,{signal:r,onProgress:i}={})=>{await s();let a=ve();return be(a,t),Z(()=>e.post(`${n}/attachments`,a,{headers:{"Content-Type":`multipart/form-data`},timeout:3e5,signal:r,onUploadProgress:({loaded:e,total:t})=>{i&&t&&i((e??0)/t)}}))},deleteAttachment:async t=>{await s(),await Z(()=>e.delete(i(t)))},getAttachment:async t=>(await s(),Z(()=>e.get(i(t),{responseType:`arraybuffer`}))),getAllowance:async()=>(await s(),Z(()=>e.get(`${n}/allowance`))),listConversations:async({page:t,pageSize:r}={})=>{await s();let i=[];t!==void 0&&i.push(`page=${encodeURIComponent(String(t))}`),r!==void 0&&i.push(`pageSize=${encodeURIComponent(String(r))}`);let a=i.join(`&`),o=a?`${n}/conversations?${a}`:`${n}/conversations`;return Z(()=>e.get(o))},getConversation:async t=>(await s(),Z(()=>e.get(r(t)))),renameConversation:async(t,n)=>{await s(),await Z(()=>e.put(`${r(t)}/title`,{title:n}))},deleteConversation:async t=>{await s(),await Z(()=>e.delete(r(t)))},rateMessage:async(t,n,{rating:i,note:a})=>{await s();let o=typeof a==`string`?a.trim():``;await Z(()=>e.put(`${r(t)}/messages/${encodeURIComponent(n)}/rating`,{rating:i,note:o||null}))}}},Se=20,Ce=e=>e instanceof X?{code:e.code,message:e.message||q.loadFailed,resetsAtUtc:e.resetsAtUtc}:{code:`unknown`,message:q.loadFailed,resetsAtUtc:null},we=e=>{let t=e.client,n=e.pageSize??Se,r=/* @__PURE__ */ new Set,i={items:[],totalCount:null,loading:!1,error:null,hasMore:!1},a=0,o=!1,s=e=>{if(!o){i={...i,...e};for(let e of r)e()}};return{getState:()=>i,subscribe:e=>(r.add(e),()=>{r.delete(e)}),load:async()=>{a+=1;let e=a;s({loading:!0,error:null});try{let r=await t.listConversations({page:1,pageSize:n});if(o||e!==a)return;s({items:r.items,totalCount:r.totalCount,hasMore:r.page<r.totalPages,loading:!1})}catch(t){if(o||e!==a)return;s({loading:!1,error:Ce(t)})}},loadMore:async()=>{if(i.loading||!i.hasMore)return;let e=a,r=Math.floor(i.items.length/n)+1;s({loading:!0,error:null});try{let c=await t.listConversations({page:r,pageSize:n});if(o||e!==a)return;let l=new Set(i.items.map(e=>e.publicId)),u=c.items.filter(e=>!l.has(e.publicId));s({items:[...i.items,...u],totalCount:c.totalCount,hasMore:c.page<c.totalPages,loading:!1})}catch(t){if(o||e!==a)return;s({loading:!1,error:Ce(t)})}},rename:async(e,n)=>{let r=n.trim();if(await t.renameConversation(e,r),o)return;let a=r.replace(/\s+/g,` `);s({items:i.items.map(t=>t.publicId===e?{...t,title:a}:t)})},remove:async e=>{await t.deleteConversation(e),o||s({items:i.items.filter(t=>t.publicId!==e),totalCount:i.totalCount===null?null:i.totalCount-1})},dispose:()=>{o=!0,r.clear()}}},Q=globalThis,Te=e=>{if(Q.requestAnimationFrame&&Q.cancelAnimationFrame){let t=Q.requestAnimationFrame(()=>e());return()=>Q.cancelAnimationFrame?.(t)}let t=Q.setTimeout(e,16);return()=>Q.clearTimeout(t)},Ee=()=>({turns:[],conversationId:null,messagesLeftToday:null,streaming:!1,loading:!1,loadError:null,settings:null,settingsError:null,editing:null,attachments:[]}),De=e=>typeof e==`object`&&e?e:{},$=e=>{let t=De(e);return{code:typeof t.code==`string`&&t.code?t.code:`unknown`,message:typeof t.message==`string`&&t.message?t.message:`Something went wrong. Please try again.`,resetsAtUtc:typeof t.resetsAtUtc==`string`?t.resetsAtUtc:null}},Oe=e=>{if(!e)return[];let t=JSON.parse(e);return Array.isArray(t)?t:[]},ke=e=>{let t=[];for(let n of e){if(n.role===`User`){t.push({id:n.publicId,questionId:n.publicId,question:n.content,attachments:n.attachments,answer:``,streaming:!1,stopped:!1,step:null,error:null,actions:[],messageId:null,rating:null,ratingNote:null,suggestions:[]});continue}let e=t[t.length-1],r={answer:n.content,actions:Oe(n.actionsJson),messageId:n.publicId,rating:n.rating,ratingNote:n.ratingNote};e&&e.messageId===null&&e.answer===``?t[t.length-1]={...e,...r}:t.push({id:n.publicId,questionId:null,question:``,attachments:[],streaming:!1,stopped:!1,step:null,error:null,suggestions:[],...r})}return t},Ae=e=>{let t=De(e);return{fileName:typeof t.name==`string`?t.name:``,contentType:typeof t.type==`string`?t.type:``,length:typeof t.size==`number`?t.size:null}},je=e=>{let t=e.client,n=J(e.labels),r=e.schedule??Te,i=/* @__PURE__ */ new Set,a=Ee(),o=0,s=0,c=0,l=null,u=null,d=null,f=null,p=/* @__PURE__ */ new Map,m=/* @__PURE__ */ new Map,h=/* @__PURE__ */ new Set,g=/* @__PURE__ */ new Map,_=e=>{let t={...a,...e};e.turns&&(t.streaming=e.turns.some(e=>e.streaming)),a=t;for(let e of i)e()},v=(e,t)=>_({turns:a.turns.map(n=>n.id===e?{...n,...t}:n)}),y=(e,t)=>_({attachments:a.attachments.map(n=>n.key===e?{...n,...t}:n)}),b=()=>{f?.(),f=null},x=()=>{p.clear(),b()},S=()=>{if(p.size===0)return;let e=new Map(p);p.clear(),_({turns:a.turns.map(t=>{let n=e.get(t.id);return n===void 0?t:{...t,answer:t.answer+n,step:null}})})},C=(e,t)=>{p.set(e,(p.get(e)??``)+t),f||=r(()=>{f=null,S()})},w=()=>{S(),o+=1,l?.abort.abort(),l=null},T=()=>{u?.abort(),u=null},E=e=>{let t=e[e.length-1];return!t||t.suggestions.length===0?e:[...e.slice(0,-1),{...t,suggestions:[]}]},D=()=>{for(let e of g.values())e.abort();g.clear();for(let n of h){let r=m.get(n);r&&t.deleteAttachment(r.publicId).catch(e.onError)}h.clear(),m.clear()},O=()=>{if(d)return d;let e=t.getSettings().then(t=>{d===e&&_({settings:t})},t=>{if(d!==e)return;let r=$(t);r.code===`assistant_outdated`&&(r.message=n.assistantOutdated),_({settingsError:r})});return d=e,e},k=e=>{let t=m.get(e);if(!t)throw Error(`No uploaded file for composer attachment ${e}.`);return t},A=t=>{if(e.onError)e.onError(t);else throw t},j=async(e,r)=>{let i=new Q.AbortController;g.set(e,i);let a;try{a=await t.uploadAttachment(r,{signal:i.signal,onProgress:t=>{g.get(e)===i&&y(e,{progress:t})}})}catch{g.get(e)===i&&(g.delete(e),y(e,{status:`Failed`,progress:null,error:n.attachmentFailed}));return}g.get(e)===i?(g.delete(e),m.set(e,a),h.add(e),y(e,{status:`Ready`,progress:null})):t.deleteAttachment(a.publicId).catch(A)},M=async(n,r)=>{T();let i=o,c=new Q.AbortController;s+=1;let d=`turn-${s}`;l={id:d,abort:c};let f=()=>i===o&&!c.signal.aborted,p={id:d,questionId:null,question:n.text,attachments:n.attachments,answer:``,streaming:!0,stopped:!1,step:null,error:null,actions:[],messageId:null,rating:null,ratingNote:null,suggestions:[]};r&&(h.clear(),m.clear()),_({turns:[...E(n.before),p],...r?{editing:null,attachments:[]}:{}});let g=!1;try{if(await O(),!f())return;let r=a.settingsError;if(r){v(d,{streaming:!1,error:r});return}let i=await t.sendMessage({message:n.text,conversationId:a.conversationId,pageContext:e.pageContext?.(),replacesMessageId:n.replaces,attachmentIds:n.attachments.map(e=>e.publicId)},{signal:c.signal,onEvent:(e,t)=>{if(!f())return;let n=De(t);if(e===`delta`)C(d,typeof n.text==`string`?n.text:``);else if(S(),e===`reset`)v(d,{answer:``,step:null});else if(e===`tool`){let e=n.toolName;v(d,{step:typeof e==`string`&&e?e:null})}else if(e===`actions`)v(d,{actions:Array.isArray(n.actions)?n.actions:[]});else if(e===`suggestions`){let e=Array.isArray(n.suggestions)?n.suggestions:[];a.turns[a.turns.length-1]?.id===d&&v(d,{suggestions:e.filter(e=>typeof e==`string`)})}else if(e===`done`){let e=t;g=!0,v(d,{questionId:e.questionId,answer:e.reply,messageId:e.messageId??null,streaming:!1,step:null}),_({conversationId:e.conversationId,messagesLeftToday:e.messagesLeftToday??null}),l=null,u=c}}});if(S(),!f())return;g||(v(d,{questionId:i.questionId,answer:i.reply,messageId:i.messageId??null,streaming:!1,step:null}),_({conversationId:i.conversationId,messagesLeftToday:i.messagesLeftToday??null}))}catch(e){if(S(),!f()||g)return;let t=$(e);v(d,{answer:``,actions:[],streaming:!1,step:null,error:t}),t.code===`daily_limit`&&_({messagesLeftToday:0}),t.code===`conversation_not_found`&&_({conversationId:null})}finally{l?.id===d&&(l=null)}},N=async e=>{let t=typeof e==`string`?e.trim():``;if(!t||l||a.attachments.some(e=>e.status===`Uploading`))return;let n=a.attachments.filter(e=>e.status===`Ready`).map(e=>k(e.key)),r=a.turns,i=null;if(a.editing){let e=a.turns.findIndex(e=>e.id===a.editing?.turnId);e>=0&&(i=a.turns[e].questionId,r=a.turns.slice(0,e))}await M({text:t,replaces:i,attachments:n,before:r},!0)},P=()=>{if(!l)return;let{id:e,abort:t}=l;l=null,x(),t.abort(),_({turns:a.turns.map(t=>t.id===e?{...t,streaming:!1,stopped:!0,answer:``,step:null,actions:[]}:t)})};return{client:t,getState:()=>a,subscribe:e=>(i.add(e),d||O(),()=>{i.delete(e)}),submit:N,stop:P,retry:async e=>{let t=a.turns.length-1,n=a.turns[t];l||!n||n.id!==e||n.error===null&&!n.stopped||await M({text:n.question,replaces:null,attachments:n.attachments,before:a.turns.slice(0,t)},!1)},regenerate:async e=>{if(l)return;let t=a.turns.length-1;for(;t>=0&&a.turns[t].messageId===null;)--t;let n=a.turns[t];n&&n.id===e&&n.questionId!==null&&await M({text:n.question,replaces:n.questionId,attachments:n.attachments,before:a.turns.slice(0,t)},!1)},startEdit:e=>{let t=a.turns.find(t=>t.id===e);if(t&&t.questionId!==null){D();for(let e of t.attachments)m.set(e.publicId,e);_({turns:E(a.turns),editing:{turnId:e,text:t.question},attachments:t.attachments.map(e=>({key:e.publicId,fileName:e.fileName,contentType:e.contentType,length:e.length,status:`Ready`,progress:null,error:null}))})}},cancelEdit:()=>{a.editing&&(D(),_({editing:null,attachments:[]}))},attach:async e=>{await O();let t=a.settings?.attachments??null,r=t?t.maxFiles-a.attachments.filter(e=>e.status!==`Failed`).length:0,i=[],o=[];for(let a of e){let e=Ae(a);c+=1;let s=`file-${c}`,l={key:s,fileName:e.fileName,contentType:e.contentType,length:e.length??0};t?r<=0?i.push({...l,status:`Failed`,progress:null,error:n.attachmentLimit(t.maxFiles)}):e.length!==null&&e.length>t.maxFileBytes||!t.contentTypes.includes(e.contentType)?i.push({...l,status:`Failed`,progress:null,error:n.attachmentFailed}):(--r,i.push({...l,status:`Uploading`,progress:0,error:null}),o.push({key:s,file:a})):i.push({...l,status:`Failed`,progress:null,error:n.attachmentFailed})}_({attachments:[...a.attachments,...i]}),await Promise.all(o.map(({key:e,file:t})=>j(e,t)))},removeAttachment:async e=>{let n=g.get(e);n&&(g.delete(e),n.abort());let r=h.has(e)?m.get(e):void 0;r&&await t.deleteAttachment(r.publicId),h.delete(e),m.delete(e),_({attachments:a.attachments.filter(t=>t.key!==e)})},openConversation:async e=>{w(),T();let n=o;_({turns:[],conversationId:null,loadError:null,loading:!0,editing:null});try{let r=await t.getConversation(e);if(n!==o)return;_({turns:ke(r.messages),conversationId:r.publicId})}catch(e){if(n!==o)return;_({loadError:$(e)})}finally{n===o&&_({loading:!1})}},newConversation:()=>{D(),w(),T(),_({turns:[],conversationId:null,loadError:null,loading:!1,editing:null,attachments:[]})},rate:async(e,n,r)=>{let i=a.turns.find(t=>t.id===e),o=a.conversationId;if(!i?.messageId||!o)throw Error(`Only a stored reply can be rated.`);let s={rating:i.rating,ratingNote:i.ratingNote},c=typeof r==`string`&&r.trim()?r.trim():null;v(e,{rating:n,ratingNote:c});try{await t.rateMessage(o,i.messageId,{rating:n,note:c})}catch(t){throw v(e,s),t}},refreshAllowance:async()=>{let e=o,n=await t.getAllowance();e===o&&_({messagesLeftToday:n.messagesLeftToday})},reset:()=>{D(),x(),w(),T(),d=null,_(Ee())},dispose:()=>{i.clear(),o+=1,P(),T(),D(),x(),_({attachments:[],editing:null})}}};function Me(e,t){return e.kind===`Reply`?t.actionReply(e.ticketNumber):e.kind===`Reopen`?t.actionReopen(e.ticketNumber):t.actionRaiseTicket}function Ne(e,t,n){return e===`Reply`?n.actionDoneReply(t):e===`Reopen`?n.actionDoneReopen(t):n.actionDoneRaiseTicket(t)}function Pe({action:e,confirmAction:i,onViewTicket:a,labels:o}){let s=J(o),[c,l]=C(`ready`),[u,d]=C(null),[f,p]=C(``);if(c===`dismissed`)return/* @__PURE__ */ E(`p`,{className:`wui-text-sm text-body-secondary mb-0`,children:s.actionDismissed});if(c===`done`)return/* @__PURE__ */ E(t,{tone:`success`,role:`status`,size:`sm`,action:a?/* @__PURE__ */ E(n,{size:`sm`,variant:`ghost`,onClick:()=>a(u),children:s.viewTicket}):void 0,children:Ne(e.kind,u.number,s)});async function m(){l(`sending`),p(``);try{d(await i(e.token)),l(`done`)}catch(e){p(e?.message||s.actionFailed),l(`ready`)}}let h=c===`sending`,g=new Date(e.expiresDateTimeUtc).getTime()<=Date.now(),_=e.kind===`RaiseTicket`?[e.category,e.subject].filter(Boolean).join(` · `):``;return/* @__PURE__ */ E(r,{padding:`sm`,className:`border`,title:Me(e,s),subtitle:_||void 0,children:/* @__PURE__ */ D(`div`,{className:`d-flex flex-column gap-2`,children:[e.kind!==`Reopen`&&e.body&&/* @__PURE__ */ E(`p`,{className:`wui-text-sm mb-0`,style:{whiteSpace:`pre-wrap`,overflowWrap:`anywhere`},children:e.body}),g?/* @__PURE__ */ E(`p`,{className:`wui-text-sm text-body-secondary mb-0`,children:s.actionExpired}):/* @__PURE__ */ D(T,{children:[/* @__PURE__ */ E(`p`,{className:`wui-text-xs text-body-secondary mb-0`,children:s.actionNote}),f&&/* @__PURE__ */ E(t,{size:`sm`,tone:`danger`,children:f}),/* @__PURE__ */ D(`div`,{className:`d-flex flex-wrap gap-2`,children:[/* @__PURE__ */ E(n,{size:`sm`,loading:h,onClick:m,children:s.actionConfirm}),/* @__PURE__ */ E(n,{size:`sm`,variant:`secondary`,disabled:h,onClick:()=>l(`dismissed`),children:s.actionDismiss})]})]})]})})}function Fe({attachments:e,onRemove:t,labels:n}){return e.length===0?null:/* @__PURE__ */ D(`div`,{className:`d-flex flex-column gap-2`,children:[/* @__PURE__ */ E(a,{children:e.map(e=>/* @__PURE__ */ E(i,{label:e.fileName,tone:e.status===`Failed`?`danger`:`neutral`,onRemove:()=>t(e.key),removeLabel:n.removeAttachment(e.fileName)},e.key))}),e.map(e=>e.progress===null?null:/* @__PURE__ */ E(p,{value:e.progress,max:1,size:`sm`,label:e.fileName},e.key)),e.filter(e=>e.status===`Failed`).map(e=>/* @__PURE__ */ E(`span`,{className:`small text-danger`,role:`alert`,children:e.error},e.key))]})}function Ie({onSubmit:e,busy:t=!1,disabled:r=!1,maxLength:i=4e3,inputRef:a,attachments:o=[],onAttach:s,onRemoveAttachment:c,accept:l,onStop:u,editing:d=null,onCancelEdit:f,labels:p}){let m=J(p),h=b(),_=S(null),[v,x]=C(``),w=o.some(e=>e.status===`Uploading`),O=t||r||w||!v.trim();y(()=>{d&&x(d.text)},[d]);function k(){O||(e(v.trim()),x(``))}function A(e){let t=Array.from(e.target.files??[]);e.target.value=``,t.length>0&&s(t)}return/* @__PURE__ */ D(`div`,{className:`d-flex flex-column gap-2`,children:[d&&f&&/* @__PURE__ */ D(`div`,{className:`wui-chat-editing`,children:[/* @__PURE__ */ E(`span`,{className:`small text-body-secondary`,children:m.editing}),/* @__PURE__ */ E(n,{type:`button`,size:`sm`,variant:`ghost`,onClick:f,children:m.cancel})]}),/* @__PURE__ */ E(Fe,{attachments:o,onRemove:e=>c?.(e),labels:m}),/* @__PURE__ */ D(`form`,{className:`wui-chat-composer d-flex align-items-end gap-2`,"aria-label":m.composer,onSubmit:e=>{e.preventDefault(),k()},children:[s&&/* @__PURE__ */ D(T,{children:[/* @__PURE__ */ E(n,{type:`button`,variant:`ghost`,leftIcon:`paperclip`,disabled:r,"aria-describedby":`${h}-attach-hint`,onClick:()=>_.current?.click(),children:/* @__PURE__ */ E(`span`,{className:`visually-hidden`,children:m.attach})}),/* @__PURE__ */ E(`span`,{id:`${h}-attach-hint`,className:`visually-hidden`,children:m.attachHint}),/* @__PURE__ */ E(`input`,{ref:_,type:`file`,multiple:!0,accept:l,hidden:!0,onChange:A})]}),/* @__PURE__ */ E(g,{id:`${h}-message`,"aria-label":m.composer,"aria-describedby":`${h}-hint`,placeholder:m.placeholder,rows:1,autoGrow:!0,maxLength:i,value:v,disabled:r,ref:a,fieldClassName:`flex-grow-1 mb-0`,onChange:e=>x(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),k())}}),/* @__PURE__ */ E(`span`,{id:`${h}-hint`,className:`visually-hidden`,children:m.composerHint}),t&&u?/* @__PURE__ */ E(n,{type:`button`,leftIcon:`stop`,onClick:u,children:/* @__PURE__ */ E(`span`,{className:`visually-hidden`,children:m.stop})}):/* @__PURE__ */ E(n,{type:`submit`,leftIcon:`send`,disabled:O,children:/* @__PURE__ */ E(`span`,{className:`visually-hidden`,children:m.send})})]})]})}function Le({client:i,onOpen:a,onDeleted:s,pageSize:c=20,labels:u}){let f=J(u),p=x(()=>we({client:i,pageSize:c}),[i,c]),h=w(p.subscribe,p.getState),[g,_]=C(null),[v,b]=C(!1),[S,T]=C(``),[k,A]=C(null),[j,M]=C(``),[N,P]=C(!1),[F,I]=C(``),[L,R]=C(void 0),[z,B]=C(``);y(()=>(p.load(),p.dispose),[p]),y(()=>{if(typeof i.getSettings!=`function`)return;let e=!0;return Promise.resolve().then(()=>i.getSettings()).then(t=>{e&&R(t.titleMaxLength)}).catch(t=>{e&&B(t?.message||f.loadFailed)}),()=>{e=!1}},[i,f.loadFailed]);async function V(){b(!0),T(``);try{await p.remove(g.publicId),s?.(g.publicId),_(null)}catch(e){T(e?.message||f.deleteFailed)}finally{b(!1)}}function H(e){N||(A(e.publicId),M(e.title||``),I(``))}function U(){A(null),I(``)}async function W(e){if(!(N||j.trim()===``)){P(!0),I(``);try{await p.rename(e,j),A(null)}catch(e){I(e?.message||f.renameFailed)}finally{P(!1)}}}let G=h.totalCount===null&&h.error===null;return!h.loading&&!G&&!h.error&&h.items.length===0?/* @__PURE__ */ E(l,{icon:`chat`,size:`sm`,title:f.conversationsEmptyTitle,text:f.conversationsEmptyText}):/* @__PURE__ */ D(`div`,{className:`d-flex flex-column gap-3`,children:[h.error&&/* @__PURE__ */ E(t,{tone:`danger`,action:/* @__PURE__ */ E(n,{size:`sm`,variant:`secondary`,onClick:()=>p.load(),children:f.retry}),children:h.error.message}),h.items.length>0&&/* @__PURE__ */ E(`ul`,{className:`list-unstyled d-flex flex-column gap-2 mb-0`,"aria-label":f.conversations,children:h.items.map(i=>/* @__PURE__ */ E(`li`,{children:k===i.publicId?/* @__PURE__ */ D(r,{padding:`sm`,className:`border`,bodyClassName:`d-flex flex-column gap-2`,children:[/* @__PURE__ */ D(`div`,{className:`d-flex align-items-center gap-2`,children:[/* @__PURE__ */ E(d,{size:`sm`,"aria-label":f.conversationTitle,fieldClassName:`flex-grow-1 mb-0`,value:j,maxLength:L,autoFocus:!0,onChange:e=>M(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),W(i.publicId)):e.key===`Escape`&&(e.preventDefault(),U())}}),/* @__PURE__ */ E(n,{variant:`primary`,size:`sm`,loading:N,disabled:N||j.trim()===``,onClick:()=>W(i.publicId),children:f.renameSave}),/* @__PURE__ */ E(n,{variant:`secondary`,size:`sm`,onClick:U,children:f.cancel})]}),(F||z)&&/* @__PURE__ */ E(t,{tone:`danger`,size:`sm`,children:F||z})]}):/* @__PURE__ */ D(r,{padding:`sm`,className:`border`,bodyClassName:`d-flex align-items-center gap-2`,children:[/* @__PURE__ */ E(n,{variant:`ghost`,className:`flex-grow-1 text-start`,style:{minWidth:0},onClick:()=>a(i),children:/* @__PURE__ */ D(`span`,{className:`d-flex flex-column`,style:{minWidth:0},children:[/* @__PURE__ */ E(`span`,{className:`text-truncate fw-semibold`,children:i.title||f.untitled}),/* @__PURE__ */ E(`time`,{dateTime:i.lastMessageDateTimeUtc,className:`wui-text-xs text-body-secondary`,children:O(i.lastMessageDateTimeUtc)})]})}),/* @__PURE__ */ E(e,{icon:`edit`,label:f.renameConversation,onClick:()=>H(i)}),/* @__PURE__ */ E(e,{icon:`trash-2`,danger:!0,label:f.deleteConversation,onClick:()=>{T(``),_(i)}})]})},i.publicId))}),(h.loading||G)&&/* @__PURE__ */ D(`div`,{className:`d-flex flex-column gap-2`,"aria-hidden":`true`,children:[/* @__PURE__ */ E(m,{height:44}),/* @__PURE__ */ E(m,{height:44}),/* @__PURE__ */ E(m,{height:44})]}),!h.loading&&h.hasMore&&/* @__PURE__ */ E(n,{variant:`secondary`,className:`align-self-center`,onClick:()=>p.loadMore(),children:f.loadMore}),/* @__PURE__ */ E(o,{open:g!==null,title:f.deleteConfirmTitle,message:S?/* @__PURE__ */ E(t,{tone:`danger`,children:S}):f.deleteConfirmMessage,confirmLabel:f.deleteConfirm,cancelLabel:f.cancel,danger:!0,loading:v,onConfirm:V,onClose:()=>{v||_(null)}})]})}var Re={zIndex:`var(--wui-z-fixed)`,bottom:`var(--wui-consent-banner-block, 0px)`},ze={end:{insetInlineEnd:0},start:{insetInlineStart:0}};function Be({onClick:e,open:t=!1,position:r=`end`,icon:i=`sparkles`,compact:a=!1,className:o,style:s,labels:c}){let l=J(c);return a?/* @__PURE__ */ E(Ve,{onClick:e,open:t,position:r,icon:i,className:o,style:s,label:l.launcher}):/* @__PURE__ */ E(`span`,{"data-support-capture":`exclude`,className:[`position-fixed m-3`,o].filter(Boolean).join(` `),style:{...Re,...ze[r],...s},children:/* @__PURE__ */ E(n,{leftIcon:i,className:`rounded-pill`,onClick:e,"aria-haspopup":`dialog`,"aria-expanded":t,children:l.launcher})})}function Ve({onClick:e,open:t,position:r,icon:i,className:a,style:o,label:s}){let c=_(r);return c?k(/* @__PURE__ */ E(`span`,{className:[`wui-floating-stack-item wui-floating-stack-item--primary`,a].filter(Boolean).join(` `),style:o,children:/* @__PURE__ */ E(n,{className:`wui-floating-btn`,onClick:e,"aria-label":s,"aria-haspopup":`dialog`,"aria-expanded":t,tooltip:s,tooltipPlacement:r===`start`?`end`:`start`,children:/* @__PURE__ */ E(u,{name:i,size:24})})}),c):null}function He({text:e,resolveLink:t,linkComponent:n,isCitation:r,onOpenCitation:i,className:a}){return/* @__PURE__ */ E(f,{value:e,links:`app`,headings:`text`,resolveLink:t,linkComponent:n,isCitation:r,onOpenCitation:i,className:a})}function Ue({rating:e,onRate:r,noteMaxLength:i=1e3,labels:a}){let o=J(a),s=b(),[c,l]=C(!1),[u,d]=C(!1),[f,p]=C(``),[m,h]=C(``),[_,v]=C(!1);async function y(e,t){l(!0),h(``);try{await r(e,t),d(e===`Down`&&t===void 0),v(e===`Up`||t!==void 0),t!==void 0&&p(``)}catch{h(o.ratingFailed)}finally{l(!1)}}return/* @__PURE__ */ D(`div`,{className:`d-flex flex-column gap-2`,children:[/* @__PURE__ */ D(`div`,{className:`d-flex flex-wrap align-items-center gap-1`,children:[/* @__PURE__ */ E(n,{size:`sm`,variant:e===`Up`?`neutral`:`ghost`,leftIcon:`check`,"aria-pressed":e===`Up`,disabled:c,onClick:()=>y(`Up`),children:o.rateUp}),/* @__PURE__ */ E(n,{size:`sm`,variant:e===`Down`?`neutral`:`ghost`,leftIcon:`x`,"aria-pressed":e===`Down`,disabled:c,onClick:()=>y(`Down`),children:o.rateDown}),_&&!u&&/* @__PURE__ */ E(`span`,{className:`wui-text-xs text-body-secondary`,role:`status`,children:o.rated})]}),m&&/* @__PURE__ */ E(t,{size:`sm`,tone:`danger`,children:m}),u&&/* @__PURE__ */ D(`form`,{className:`d-flex flex-column gap-2`,onSubmit:e=>{e.preventDefault(),y(`Down`,f)},children:[/* @__PURE__ */ E(g,{id:`${s}-note`,label:o.ratingNote,hint:o.ratingNoteHint,rows:2,maxLength:i,value:f,onChange:e=>p(e.target.value)}),/* @__PURE__ */ D(`div`,{className:`d-flex gap-2`,children:[/* @__PURE__ */ E(n,{type:`submit`,size:`sm`,loading:c,children:o.ratingNoteSend}),/* @__PURE__ */ E(n,{size:`sm`,variant:`secondary`,disabled:c,onClick:()=>{d(!1),v(!0)},children:o.ratingNoteSkip})]})]})]})}var We={maxWidth:`85%`,whiteSpace:`pre-wrap`,overflowWrap:`anywhere`};function Ge({turn:a,onRate:o,onRetry:c,onRegenerate:l,canRegenerate:u,onEdit:d,onOpenAttachment:f,resolveLink:p,linkComponent:m,isCitation:g,onOpenCitation:_,onAskSuggestion:v,confirmAction:y,onViewTicket:b,renderReply:x,labels:S}){let C=J(S),w=a.streaming&&!a.answer,T=!!a.answer&&!a.streaming,O=a.step?C.toolStep(a.step):C.thinking;return/* @__PURE__ */ D(`li`,{className:`d-flex flex-column gap-2`,children:[a.question&&/* @__PURE__ */ D(`div`,{className:`d-flex align-items-center gap-1 align-self-end`,children:[d&&a.questionId&&/* @__PURE__ */ E(e,{icon:`edit`,label:C.edit,onClick:()=>d(a.id)}),/* @__PURE__ */ D(`div`,{style:We,children:[/* @__PURE__ */ D(`span`,{className:`visually-hidden`,children:[C.you,`: `]}),/* @__PURE__ */ D(r,{padding:`sm`,variant:`muted`,className:`wui-text-sm`,children:[a.question,a.attachments?.length>0&&/* @__PURE__ */ E(`div`,{className:`wui-chat-question-attachments mt-2`,children:a.attachments.map(e=>/* @__PURE__ */ E(i,{label:e.fileName,leadingIcon:`document`,onClick:f?()=>f(e):void 0},e.publicId))})]})]})]}),/* @__PURE__ */ D(`div`,{className:`d-flex flex-column gap-2`,style:{minWidth:0},children:[/* @__PURE__ */ D(`span`,{className:`visually-hidden`,children:[C.assistant,`: `]}),/* @__PURE__ */ E(`div`,{"aria-live":`polite`,"aria-busy":a.streaming,children:a.stopped?/* @__PURE__ */ E(t,{size:`sm`,tone:`neutral`,children:C.stopped}):w?/* @__PURE__ */ D(`span`,{className:`d-inline-flex align-items-center gap-2 wui-text-sm text-body-secondary`,children:[/* @__PURE__ */ E(h,{size:`sm`,label:O}),/* @__PURE__ */ E(`span`,{"aria-hidden":`true`,children:O})]}):a.answer&&(x?x(a,{streaming:!!a.streaming}):/* @__PURE__ */ E(He,{text:a.answer,resolveLink:p,linkComponent:m,isCitation:g,onOpenCitation:_}))}),a.error&&/* @__PURE__ */ E(t,{size:`sm`,tone:`danger`,children:a.error.message}),c&&(a.error||a.stopped)&&/* @__PURE__ */ E(`div`,{children:/* @__PURE__ */ E(n,{variant:`outline`,size:`sm`,onClick:()=>c(a.id),children:C.retry})}),y&&!a.streaming&&a.actions.map(e=>/* @__PURE__ */ E(Pe,{action:e,confirmAction:y,onViewTicket:b,labels:S},e.token)),(T||o&&a.messageId&&!a.streaming)&&/* @__PURE__ */ D(`div`,{className:`wui-chat-turn-actions align-items-center`,children:[T&&/* @__PURE__ */ E(s,{text:de(a.answer),label:C.copy,copiedLabel:C.copied,iconOnly:!0,size:`sm`,variant:`ghost`}),o&&a.messageId&&!a.streaming&&/* @__PURE__ */ E(Ue,{rating:a.rating,onRate:(e,t)=>o(a.id,e,t),labels:S}),l&&u&&T&&/* @__PURE__ */ E(n,{variant:`outline`,size:`sm`,leftIcon:`refresh`,onClick:()=>l(a.id),children:C.regenerate})]}),v&&!a.streaming&&a.suggestions.length>0&&/* @__PURE__ */ E(`div`,{className:`wui-chat-suggestions`,role:`group`,"aria-label":C.suggestions,children:a.suggestions.map(e=>/* @__PURE__ */ E(n,{variant:`outline`,size:`sm`,onClick:()=>v(e),children:e},e))})]})]})}var Ke=v(Ge);function qe(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 Je({turns:e,empty:t,onRate:n,resolveLink:r,linkComponent:i,confirmAction:a,onViewTicket:o,renderReply:s,onRetry:c,onRegenerate:u,onAskSuggestion:d,isCitation:f,onOpenCitation:p,onEdit:m,onOpenAttachment:h,labels:g}){let _=J(g),v=S(null),b=e[e.length-1];return y(()=>{let e=qe(v.current);e&&(e.scrollTop=e.scrollHeight)},[e.length,b?.answer,b?.error,b?.actions]),e.length===0?t??/* @__PURE__ */ E(l,{icon:`sparkles`,size:`sm`,title:_.emptyTitle,text:_.emptyText}):/* @__PURE__ */ D(T,{children:[/* @__PURE__ */ E(`ol`,{className:`list-unstyled d-flex flex-column gap-3 mb-0`,"aria-label":_.thread,children:e.map((t,l)=>/* @__PURE__ */ E(Ke,{turn:t,onRate:n,resolveLink:r,linkComponent:i,confirmAction:a,onViewTicket:o,renderReply:s,onRetry:l===e.length-1?c:void 0,onRegenerate:u,onAskSuggestion:l===e.length-1?d:void 0,isCitation:f,onOpenCitation:p,canRegenerate:l===e.length-1,onEdit:m,onOpenAttachment:h,labels:g},t.id))}),/* @__PURE__ */ E(`div`,{ref:v})]})}function Ye({chat:n,open:r,onClose:i,title:a,titleIcon:o=`sparkles`,headerActions:s,empty:l,disclaimer:d,maxLength:f=4e3,allowanceThreshold:p=10,width:m=`440px`,resolveLink:g,linkComponent:_,confirmAction:v,onViewTicket:b,rating:x=!0,renderReply:w,openAttachment:O,conversations:k=!1,isCitation:A,onOpenCitation:j,labels:M}){let N=J(M),P=S(null),{refreshAllowance:F}=n,I=n.settings?.attachments,L=I?.contentTypes.join(`,`),[R,z]=C(`chat`);y(()=>{r&&F().catch(()=>{})},[r,F]),y(()=>{r||z(`chat`)},[r]);let B=n.messagesLeftToday,V=a??N.panelTitle,H=k&&R===`conversations`,U=/* @__PURE__ */ D(`div`,{className:`drawer-header`,children:[/* @__PURE__ */ D(`div`,{className:`drawer-title`,children:[o&&/* @__PURE__ */ E(`span`,{className:`drawer-title-ic`,children:/* @__PURE__ */ E(u,{name:o,size:18})}),V]}),/* @__PURE__ */ D(`div`,{className:`d-flex align-items-center gap-1`,children:[s,H?/* @__PURE__ */ E(e,{icon:`arrow-left`,label:N.backToChat,onClick:()=>z(`chat`)}):/* @__PURE__ */ D(T,{children:[k&&/* @__PURE__ */ E(e,{icon:`history`,label:N.conversations,onClick:()=>z(`conversations`)}),/* @__PURE__ */ E(e,{icon:`plus`,label:N.newChat,onClick:n.newConversation,disabled:n.turns.length===0&&!n.loading})]}),/* @__PURE__ */ E(e,{icon:`x`,label:N.close,onClick:i})]})]}),W=/* @__PURE__ */ D(`div`,{className:`d-flex flex-column gap-2`,children:[B!==null&&B<=p&&/* @__PURE__ */ E(`p`,{className:`wui-text-xs text-body-secondary mb-0`,role:`status`,children:N.allowance(B)}),n.settingsError&&/* @__PURE__ */ E(t,{tone:`danger`,children:n.settingsError.message}),/* @__PURE__ */ E(Ie,{onSubmit:n.submit,busy:n.streaming||n.loading,disabled:B===0,maxLength:f,inputRef:P,attachments:n.attachments,onAttach:I?n.attach:void 0,onRemoveAttachment:n.removeAttachment,accept:L,onStop:n.streaming?n.stop:void 0,editing:n.editing,onCancelEdit:n.cancelEdit,labels:M}),/* @__PURE__ */ E(`p`,{className:`wui-text-xs text-body-secondary mb-0`,children:d??N.disclaimer})]});return/* @__PURE__ */ E(c,{open:r,onClose:i,sheet:!1,width:m,header:U,footer:H?void 0:W,ariaLabel:typeof V==`string`?V:N.panelTitle,onOpened:()=>P.current?.focus(),children:H?/* @__PURE__ */ E(Le,{client:n.client,onOpen:e=>{n.openConversation(e.publicId),z(`chat`)},onDeleted:e=>{e===n.conversationId&&n.newConversation()},labels:M}):n.loading?/* @__PURE__ */ E(`div`,{className:`d-flex justify-content-center py-4`,children:/* @__PURE__ */ E(h,{label:N.loadingConversation})}):n.loadError?/* @__PURE__ */ E(t,{tone:`danger`,children:n.loadError.message}):/* @__PURE__ */ E(Je,{turns:n.turns,empty:l,onRate:x?n.rate:void 0,onRetry:n.retry,onRegenerate:n.regenerate,onAskSuggestion:n.submit,isCitation:A,onOpenCitation:j,onEdit:n.startEdit,onOpenAttachment:O,resolveLink:g,linkComponent:_,confirmAction:v,onViewTicket:b,renderReply:w,labels:M})})}function Xe({citation:e,label:t,ariaLabel:n,onOpen:r}){return/* @__PURE__ */ E(i,{label:t??e,size:`sm`,tone:`primary`,variant:`outline`,leadingIcon:`book-1`,"aria-label":n??e,onClick:()=>r(e)})}function Ze({title:e,subtitle:i,lines:a,note:o,onConfirm:s,labels:c}){let l=J(c),[u,d]=C(`ready`),[f,p]=C(null),[m,h]=C(``);if(u===`dismissed`)return/* @__PURE__ */ E(`p`,{className:`wui-text-sm text-body-secondary mb-0`,children:l.actionDismissed});if(u===`done`)return/* @__PURE__ */ E(t,{tone:`success`,role:`status`,size:`sm`,children:f?.message||l.actionDone});async function g(){d(`sending`),h(``);try{let e=await s();p(e??null),d(`done`)}catch(e){h(e?.message||l.actionFailed),d(`ready`)}}let _=u===`sending`;return/* @__PURE__ */ E(r,{padding:`sm`,className:`border`,title:e,subtitle:i||void 0,children:/* @__PURE__ */ D(`div`,{className:`d-flex flex-column gap-2`,children:[(a??[]).map((e,t)=>/* @__PURE__ */ E(`p`,{className:`wui-text-sm mb-0`,style:{whiteSpace:`pre-wrap`,overflowWrap:`anywhere`},children:e},t)),/* @__PURE__ */ E(`p`,{className:`wui-text-xs text-body-secondary mb-0`,children:o??l.actionNote}),m&&/* @__PURE__ */ E(t,{size:`sm`,tone:`danger`,children:m}),/* @__PURE__ */ D(`div`,{className:`d-flex flex-wrap gap-2`,children:[/* @__PURE__ */ E(n,{size:`sm`,loading:_,onClick:g,children:l.actionConfirm}),/* @__PURE__ */ E(n,{size:`sm`,variant:`secondary`,disabled:_,onClick:()=>d(`dismissed`),children:l.actionDismiss})]})]})})}function Qe({client:e,pageContext:t}){let n=S(t);n.current=t;let r=x(()=>je({client:e,pageContext:()=>n.current}),[e]);y(()=>()=>r.dispose(),[r]);let i=w(r.subscribe,r.getState),a=x(()=>({submit:e=>r.submit(e),stop:()=>r.stop(),retry:e=>r.retry(e),regenerate:e=>r.regenerate(e),startEdit:e=>r.startEdit(e),cancelEdit:()=>r.cancelEdit(),attach:e=>r.attach(e),removeAttachment:e=>r.removeAttachment(e),openConversation:e=>r.openConversation(e),newConversation:()=>r.newConversation(),rate:(e,t,n)=>r.rate(e,t,n),refreshAllowance:()=>r.refreshAllowance(),reset:()=>r.reset()}),[r]);return{...i,...a,client:r.client}}export{Pe as ActionCard,pe as CHAT_CONTRACT_VERSION,X as ChatApiError,Ie as ChatComposer,Le as ChatConversationList,Be as ChatLauncher,He as ChatMarkdown,Ke as ChatMessage,Ye as ChatPanel,Je as ChatThread,Xe as CitationChip,Ze as ConfirmCard,q as DEFAULT_CHAT_LABELS,Ue as ReplyRating,xe as createChatClient,je as createChatSession,we as createConversationList,fe as createSseParser,J as mergeLabels,j as splitCitations,Qe as useChat};
1
+ import{AppBadge as e,AppButton as t,AppChart as n,AppDataTable as r,AppDescriptions as i,AppIcon as a,AppLightbox as o,AppMarkdown as s,AppMetricStrip as c,AppPopover as l,AppSkeleton as u,AppTooltip as d}from"@webority/ui-react";import{Fragment as f,createContext as p,useCallback as m,useContext as h,useEffect as g,useId as _,useLayoutEffect as v,useMemo as y,useRef as b,useState as x,useSyncExternalStore as S}from"react";import{LOADER_STYLES as C,buildTranscript as w,createChatSession as T,createConversationList as E,createDictation as D,createExplain as O,createTurnApi as k,emptyFeatures as A,formatChatDate as j,formatChatValue as M,formatClipTime as N,formatFigure as P,formatFileSize as F,isHandoffTarget as I,loaderView as L,mergeLabels as ee,mergeLook as te,messagePlainText as ne,resolveNudge as R,resolveStart as z,showsCaptchaNote as re,toFigureRuns as ie,toFigureText as B,transcriptToText as V,voiceClipBars as H}from"@webority/chat-core";import{createAvoidance as U,createBehaviourCollector as ae,createSound as oe,createWebSpeech as se,fitToViewport as ce,lockPageScroll as le,returnFocus as ue,switchPanel as de,trapTab as fe,vibrate as pe,watchAutoOpen as me,watchReducedMotion as he}from"@webority/chat-elements/web";import{Fragment as W,jsx as G,jsxs as K}from"react/jsx-runtime";import{parseInline as ge}from"@webority/markdown-core";function _e({value:e,span:t,selectionStart:n,selectionEnd:r,text:i,maxLength:a}){let o=t?t.start:n,s=t?t.end:r,c=!t&&o>0&&e.charAt(o-1).trim()!==``?` `:``,l=a-(e.length-(s-o))-c.length,u=i.slice(0,Math.max(0,l)),d=o+c.length,f=d+u.length;return{value:e.slice(0,o)+c+u+e.slice(s),span:{start:d,end:f},caret:f}}var q=4e3,ve=Object.freeze({status:`Idle`}),ye=()=>()=>void 0,be=()=>ve,xe=/* @__PURE__ */ new Set([`Blocked`,`NotHeard`,`Failed`]),Se={Blocked:`dictationBlocked`,NotHeard:`dictationNotHeard`,Failed:`dictationFailed`};function Ce({speech:e,enabled:t,labels:n,onText:r}){let i=b(null),a=b(r);a.current=r;let[o,s]=x(null);g(()=>{if(!e){s(null);return}let t=D({adapter:e,onText:(e,t)=>a.current(e,t),onLevel:e=>i.current?.style.setProperty(`--wui-chat-mic-level`,String(e))});return s({speech:e,instance:t}),()=>t.dispose()},[e]);let c=o!==null&&o.speech===e?o.instance:null,l=S(c?c.subscribe:ye,c?c.getState:be).status,u=l===`Listening`,[d,f]=x(!1);g(()=>{if(!xe.has(l)){f(!1);return}f(!0);let e=setTimeout(()=>f(!1),q);return()=>clearTimeout(e)},[l]),g(()=>{u||i.current?.style.removeProperty(`--wui-chat-mic-level`)},[u]);let p=m(()=>c?.toggle(),[c]),h=m(()=>c?.stop(),[c]),_=xe.has(l)&&d?l:null,v=_?n[Se[_]]:null;return{available:!!(t&&e?.dictation),listening:u,note:v,noteKind:_,toggle:p,stop:h,buttonRef:i}}var we=/* @__PURE__ */ new WeakMap;function Te(e){if(!e.profile?.speechAvailable||!e.features.Dictation&&!e.features.ReadAloud)return null;let t=we.get(e.client);return t||(t=se(e.client),we.set(e.client,t)),t}var Ee=10,De=.9;function J(e){e.style.height=`auto`,e.style.height=`${e.scrollHeight}px`}function Oe({chat:e,labels:n,maxLength:r,inputRef:i}){let{features:o}=e,s=_(),c=b(null),l=b(null),u=b(null),d=b(null),[f,p]=x(``),[m,h]=x(null);e.editing&&e.editing.messageId!==m&&(h(e.editing.messageId),p(e.editing.text)),!e.editing&&m!==null&&h(null),g(()=>{let t=e.draft;t&&!e.editing&&(u.current=null,c.current?.value!==t&&(d.current=t.length),p(t),c.current?.focus(),e.session.consumeDraft())},[e.draft,e.editing,e.session]);let y=Ce({speech:Te(e),enabled:e.features.Dictation,labels:n,onText:S});function S(e){let t=c.current;if(!t)return;let n=_e({value:t.value,span:u.current,selectionStart:t.selectionStart,selectionEnd:t.selectionEnd,text:e,maxLength:r});u.current=n.span,n.value===t.value?t.setSelectionRange(n.caret,n.caret):(d.current=n.caret,p(n.value))}v(()=>{let e=c.current;d.current!==null&&e&&e.value===f&&(J(e),e.setSelectionRange(d.current,d.current),d.current=null)},[f]),g(()=>{e.editing&&y.stop()},[e.editing,y.stop]),g(()=>{y.listening||(u.current=null)},[y.listening]);let C=e.messages.flatMap(e=>e.parts).filter(e=>e.kind===`InputRequest`&&e.state===`Open`).at(-1)?.fields[0],w=e.messagesLeftToday,T=e.profile?.limits,E=e.attachments.some(e=>e.status===`Uploading`),D=e.attachments.some(e=>e.status===`Ready`),O=o.Attachments&&(T?.maxAttachments??0)>0,k=e.streaming&&o.Stop,A=e.streaming&&!o.Stop||w===0||E||f.trim()===``&&!D,j=f.length>r*De,M=w!==null&&w<=Ee;function N(e){c.current=e,typeof i==`function`?i(e):i&&(i.current=e)}function P(){let t=f.trim();A||t===``&&!D||(y.stop(),u.current=null,e.submit(t),p(``),c.current&&(c.current.style.height=`auto`))}function F(t){let n=Array.from(t.target.files??[]);t.target.value=``,n.length>0&&e.attach(n)}return/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(`p`,{className:`wui-chat-allowance`,role:`status`,hidden:!M,children:M?n.allowance(w):``}),/* @__PURE__ */ G(`div`,{className:`wui-chat-editing`,hidden:!e.editing,children:e.editing&&/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(`span`,{children:n.editing}),/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,onClick:()=>e.cancelEdit(),children:n.cancel})]})}),/* @__PURE__ */ G(`div`,{className:`wui-chat-attachments`,hidden:e.attachments.length===0,children:e.attachments.map(t=>/* @__PURE__ */ K(`span`,{className:`wui-chat-chip`,title:t.status===`Failed`?t.error??``:void 0,children:[/* @__PURE__ */ G(`span`,{children:t.fileName}),/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-chip-remove`,"aria-label":n.removeAttachment(t.fileName),onClick:()=>e.removeAttachment(t.key),children:/* @__PURE__ */ G(a,{name:`x`,size:14,"aria-hidden":`true`})})]},t.key))}),/* @__PURE__ */ K(`form`,{className:`wui-chat-composer`,"aria-label":n.composer,onSubmit:e=>{e.preventDefault(),P()},children:[O&&/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-tool`,"aria-label":n.attach,title:n.attachHint,onClick:()=>l.current?.click(),children:/* @__PURE__ */ G(a,{name:`paperclip`,size:18,"aria-hidden":`true`})}),/* @__PURE__ */ G(`input`,{ref:l,type:`file`,multiple:!0,hidden:!0,accept:T.contentTypes.join(`,`),onChange:F})]}),/* @__PURE__ */ G(`textarea`,{ref:N,className:`wui-chat-input`,"aria-label":n.composer,"aria-describedby":s,placeholder:C?.label??n.placeholder,rows:1,maxLength:r,value:f,disabled:w===0,onChange:t=>{u.current=null,p(t.target.value),J(t.target),t.target.value!==``&&e.notifyTyping()},onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),P())}}),/* @__PURE__ */ G(`span`,{id:s,className:`visually-hidden`,children:n.composerHint}),/* @__PURE__ */ G(`span`,{className:`wui-chat-counter`,hidden:!j,children:j?n.counter(f.length,r):``}),y.available&&/* @__PURE__ */ K(`button`,{type:`button`,className:y.listening?`wui-chat-tool wui-chat-mic wui-chat-mic--listening`:`wui-chat-tool wui-chat-mic`,ref:y.buttonRef,"aria-pressed":y.listening,"aria-label":y.listening?n.dictateStop:n.dictate,title:y.listening?n.dictateStop:n.dictate,disabled:w===0,onClick:y.toggle,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-mic-ring`,"aria-hidden":`true`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-mic-ring wui-chat-mic-ring--late`,"aria-hidden":`true`}),/* @__PURE__ */ G(a,{name:`microphone`,size:18,"aria-hidden":`true`}),/* @__PURE__ */ K(`span`,{className:`wui-chat-mic-level`,"aria-hidden":`true`,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-mic-bar`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-mic-bar`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-mic-bar`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-mic-bar`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-mic-bar`})]})]}),k?/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-send wui-chat-send--stop`,"aria-label":n.stop,onClick:()=>e.stop(),children:/* @__PURE__ */ G(a,{name:`stop`,size:18,"aria-hidden":`true`})}):/* @__PURE__ */ G(`button`,{type:`submit`,className:`wui-chat-send`,"aria-label":n.send,disabled:A,children:/* @__PURE__ */ G(a,{name:`send`,size:18,"aria-hidden":`true`})})]}),y.note!==null&&/* @__PURE__ */ G(`p`,{className:`wui-chat-dictate-note`,role:y.noteKind===`Blocked`?`alert`:`status`,children:y.note})]})}var ke=6e4,Y=`
2
+ @page { margin: 16mm }
3
+ body { font-family: system-ui, sans-serif; font-size: 11pt; line-height: 1.5; color: CanvasText; background: Canvas }
4
+ h1 { font-size: 18pt; margin: 0 0 4pt }
5
+ .date { margin: 0 0 14pt; opacity: .7 }
6
+ section { margin: 0 0 12pt; break-inside: avoid-page }
7
+ h2 { font-size: 11pt; margin: 0 0 2pt }
8
+ p { margin: 0 0 6pt; white-space: pre-wrap }
9
+ ul, ol { margin: 0 0 6pt; padding-left: 18pt }
10
+ table { border-collapse: collapse; margin: 0 0 6pt; max-width: 100% }
11
+ caption { text-align: left; font-weight: 600 }
12
+ th, td { border: 1px solid currentColor; padding: 2pt 6pt; text-align: left; vertical-align: top }
13
+ thead { display: table-header-group }
14
+ `;function X(e,t,n){let r=e.createElement(t);return n!==void 0&&(r.textContent=n),r}function Z(e,t){if(t.kind===`paragraph`)return X(e,`p`,t.text);if(t.kind===`list`){let n=X(e,t.ordered?`ol`:`ul`);for(let r of t.items)n.append(X(e,`li`,r));return n}let n=X(e,`table`);if(t.title!==null&&n.append(X(e,`caption`,t.title)),t.head.length>0){let r=X(e,`thead`),i=X(e,`tr`);for(let n of t.head)i.append(X(e,`th`,n));r.append(i),n.append(r)}let r=X(e,`tbody`);for(let n of t.rows){let t=X(e,`tr`);for(let r of n)t.append(X(e,`td`,r));r.append(t)}return n.append(r),n}function Ae(e,t){if(typeof e.CSSStyleSheet==`function`&&`adoptedStyleSheets`in t){let n=new e.CSSStyleSheet;n.replaceSync(Y),t.adoptedStyleSheets=[n];return}let n=X(t,`style`,Y);t.head.append(n)}function je(e,t={}){let n=t.lang||document.documentElement.lang||`en`,r=document.createElement(`iframe`);r.title=`Print`,r.setAttribute(`aria-hidden`,`true`),r.tabIndex=-1;let i=r.style;i.position=`fixed`,i.right=`0`,i.bottom=`0`,i.width=`0`,i.height=`0`,i.border=`0`,document.body.append(r);let a=r.contentWindow,o=r.contentDocument;if(!a||!o)return r.remove(),!1;if(o.open(),o.write(`<!doctype html><title></title>`),o.close(),o.title=e.title,o.documentElement.lang=n,Ae(a,o),o.body.append(X(o,`h1`,e.title)),e.dateText!==null){let t=X(o,`p`,e.dateText);t.className=`date`,o.body.append(t)}for(let t of e.entries){let e=X(o,`section`);e.append(X(o,`h2`,t.speaker));for(let n of t.blocks)e.append(Z(o,n));o.body.append(e)}let s=()=>{r.isConnected&&r.remove(),clearTimeout(c)};a.addEventListener(`afterprint`,s);let c=setTimeout(s,ke);return a.focus(),a.print(),!0}var Me=3e3;function Ne(e,t){let[n,r]=x(null),i=b(null),a=b(!1);g(()=>(a.current=!0,()=>{a.current=!1,clearTimeout(i.current)}),[]);function o(e){a.current&&(clearTimeout(i.current),r(e),i.current=setTimeout(()=>r(null),Me))}let s={labels:t,title:e.title,figureText:e.features.FigureText},c=e.features.Share&&typeof navigator<`u`&&typeof navigator.share==`function`,l=e.features.Print&&typeof document<`u`;async function u(e,n){let r=w(e,s);if(r.entries.length===0)return;let i={title:r.title,text:V(r,{heading:n,speakers:n})};if(typeof navigator.canShare==`function`&&!navigator.canShare(i))o(t.shareFailed);else try{await navigator.share(i)}catch(e){e?.name!==`AbortError`&&o(t.shareFailed)}}function d(e){let n=w(e,s);n.entries.length!==0&&(je(n,{})||o(t.printFailed))}return{canShare:c,canPrint:l,notice:n,shareReply:e=>u([e],!1),printReply:e=>d([e]),shareConversation:()=>u(e.messages,!0),printConversation:()=>d(e.messages)}}function Pe({chat:e,labels:t}){let n=Ne(e,t);if(!n.canShare&&!n.canPrint||!e.messages.some(e=>!e.streaming))return null;let r=e.streaming||e.thinking;return/* @__PURE__ */ K(W,{children:[n.canShare&&/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-icon-btn`,disabled:r,"aria-label":t.shareConversation,title:t.shareConversation,onClick:()=>n.shareConversation(),children:/* @__PURE__ */ G(a,{name:`share`,size:18,"aria-hidden":`true`})}),n.canPrint&&/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-icon-btn`,disabled:r,"aria-label":t.printConversation,title:t.printConversation,onClick:()=>n.printConversation(),children:/* @__PURE__ */ G(a,{name:`printer`,size:18,"aria-hidden":`true`})}),n.notice!==null&&/* @__PURE__ */ G(`span`,{className:`wui-chat-action-notice`,role:`status`,children:n.notice})]})}function Fe({chat:e,labels:t}){let n=e.profile;if(!n)return null;let r=n.footer.disclaimer||t.disclaimer,i=n.footer.privacyUrl,a=n.footer.assuranceText,o=re(n);return!r&&!i&&!a&&!o?null:/* @__PURE__ */ K(`p`,{className:`wui-chat-footer`,children:[r&&/* @__PURE__ */ G(`span`,{className:`wui-chat-footer-text`,children:r}),i&&/* @__PURE__ */ G(`a`,{className:`wui-chat-footer-link`,href:i,children:t.footerPrivacy}),a&&/* @__PURE__ */ G(`span`,{className:`wui-chat-footer-text`,children:a}),o&&/* @__PURE__ */ K(`span`,{className:`wui-chat-footer-captcha`,children:[t.captchaNote,` `,/* @__PURE__ */ G(`a`,{className:`wui-chat-footer-link`,href:`https://policies.google.com/privacy`,target:`_blank`,rel:`noopener noreferrer`,children:t.captchaPrivacy}),` `,/* @__PURE__ */ G(`a`,{className:`wui-chat-footer-link`,href:`https://policies.google.com/terms`,target:`_blank`,rel:`noopener noreferrer`,children:t.captchaTerms})]})]})}var Ie=Object.freeze({items:[],totalCount:null,loading:!1,error:null,hasMore:!1}),Le=()=>()=>{};function Re({chat:e,labels:n,onOpen:r}){let[i,o]=x(null),s=i!==null&&i.client===e.client?i.list:null,c=m(e=>s?s.subscribe(e):Le(),[s]),l=m(()=>s?s.getState():Ie,[s]),u=S(c,l),[d,f]=x(null),[p,h]=x(``),[_,v]=x(!1),[y,b]=x(null),[C,w]=x(!1);g(()=>{let t=E({client:e.client});return o({client:e.client,list:t}),t.load(),()=>t.dispose()},[e.client]);function T(e){f(e.publicId),h(e.title||``),v(!1)}async function D(e){if(p.trim()!==``)try{await s.rename(e,p),f(null)}catch{v(!0)}}async function O(t){try{await s.remove(t),b(null),w(!1),t===e.conversationId&&e.newConversation()}catch{w(!0)}}let k=!u.loading&&u.error===null&&u.totalCount!==null&&u.items.length===0;return/* @__PURE__ */ K(`div`,{className:`wui-chat-history`,children:[u.error&&/* @__PURE__ */ K(`p`,{className:`wui-chat-history-error`,role:`alert`,children:[n.loadFailed,` `,/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,onClick:()=>s.load(),children:n.retry})]}),k&&/* @__PURE__ */ K(`p`,{className:`wui-chat-history-empty`,children:[/* @__PURE__ */ G(`span`,{children:n.historyEmptyTitle}),` `,/* @__PURE__ */ G(`span`,{children:n.historyEmptyText})]}),u.items.length>0&&/* @__PURE__ */ G(`ul`,{className:`wui-chat-history-list`,"aria-label":n.history,children:u.items.map(i=>d===i.publicId?/* @__PURE__ */ K(`li`,{className:`wui-chat-history-row wui-chat-history-row--editing`,children:[/* @__PURE__ */ G(`input`,{className:`wui-chat-history-input`,"aria-label":n.conversationTitle,maxLength:120,value:p,onChange:e=>h(e.target.value),onKeyDown:e=>{e.key===`Enter`&&D(i.publicId),e.key===`Escape`&&f(null)}}),/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,disabled:p.trim()===``,onClick:()=>D(i.publicId),children:n.renameSave}),/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,onClick:()=>f(null),children:n.cancel}),_&&/* @__PURE__ */ G(`p`,{className:`wui-chat-history-error`,role:`alert`,children:n.renameFailed})]},i.publicId):y===i.publicId?/* @__PURE__ */ K(`li`,{className:`wui-chat-history-row wui-chat-history-row--confirm`,children:[/* @__PURE__ */ G(`p`,{children:n.deleteConfirmTitle}),/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,tone:`danger`,onClick:()=>O(i.publicId),children:n.deleteConfirm}),/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,onClick:()=>b(null),children:n.cancel}),C&&/* @__PURE__ */ G(`p`,{className:`wui-chat-history-error`,role:`alert`,children:n.deleteFailed})]},i.publicId):/* @__PURE__ */ K(`li`,{className:`wui-chat-history-row`,children:[/* @__PURE__ */ K(`button`,{type:`button`,className:`wui-chat-history-open`,onClick:()=>{e.openConversation(i.publicId),r()},children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-history-title`,children:i.title||n.untitled}),/* @__PURE__ */ G(`span`,{className:`wui-chat-history-time`,children:j(i.lastActivityDateTimeUtc)})]}),e.features.Rename&&/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-icon-btn`,"aria-label":n.rename,title:n.rename,onClick:()=>T(i),children:/* @__PURE__ */ G(a,{name:`pencil`,size:18,"aria-hidden":`true`})}),e.features.Delete&&/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-icon-btn`,"aria-label":n.deleteChat,title:n.deleteChat,onClick:()=>{w(!1),b(i.publicId)},children:/* @__PURE__ */ G(a,{name:`trash`,size:18,"aria-hidden":`true`})})]},i.publicId))}),!u.loading&&u.hasMore&&/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`soft`,onClick:()=>s.loadMore(),children:n.loadMore})]})}var ze=/* @__PURE__ */ new Map([[`Open`,`info`],[`InProgress`,`info`],[`WaitingOnCustomer`,`warning`],[`Resolved`,`success`],[`Closed`,`success`]]);function Be(e){let t=(e??``).trim().split(/\s+/).filter(Boolean);if(t.length===0)return`?`;let n=Array.from(t[0])[0];return t.length===1?n.toUpperCase():`${n}${Array.from(t.at(-1))[0]}`.toUpperCase()}function Ve(e){return ze.get(e)??`neutral`}function He(e){for(let t=e.length-1;t>=0;--t){let{author:n}=e[t];if(n.kind===`Agent`&&typeof n.displayName==`string`&&n.displayName.trim()!==``)return n.displayName}return null}function Ue(e,t){return e.conversationState===`WaitingForAgent`?t.statusWaitingForAgent:e.conversationState===`WithAgent`?t.statusWithAgent(He(e.messages)??t.handoffAgentFallback):e.conversationState===`Closed`&&e.messages.some(e=>e.author.kind===`Agent`)?t.handoffEnded:null}function We(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 Ge({chat:e,labels:n}){let[r,i]=x(!1),[a,o]=x(null),s=Ue(e,n),c=We(e);if(s===null&&!c)return null;async function l(){i(!0),o(null);try{await e.requestHandoff()}catch(e){o(e?.message||n.errorGeneric)}finally{i(!1)}}return/* @__PURE__ */ K(W,{children:[s!==null&&/* @__PURE__ */ G(`p`,{className:`wui-chat-live-status`,role:`status`,children:s}),c&&/* @__PURE__ */ K(`div`,{className:`wui-chat-live-actions`,children:[/* @__PURE__ */ G(t,{variant:`outline`,size:`sm`,leftIcon:`user`,className:`wui-chat-handoff-request`,disabled:r,onClick:l,children:n.talkToPerson}),a&&/* @__PURE__ */ G(`p`,{className:`wui-chat-live-error`,role:`alert`,children:a})]})]})}var Ke=Object.freeze({state:`idle`,answer:null,pillVisible:!1,resetsAtUtc:null,offline:!1}),qe=()=>void 0,Je=()=>Ke;function Ye({request:e,enabled:t=!0}){let n=b(e);n.current=e;let[r,i]=x(null);g(()=>{let e=O({request:e=>n.current(e)});return i(e),()=>e.dispose()},[]);let a=m(e=>r?r.subscribe(e):qe,[r]),o=S(a,r?r.getSnapshot:Je),s=m(()=>{t&&r?.ask()},[t,r]),c=m(()=>r?.reset(),[r]),l=t?o:Ke;return{state:l.state,answer:l.answer,pillVisible:l.pillVisible,resetsAtUtc:l.resetsAtUtc,offline:l.offline,ask:s,reset:c}}function Xe(e){if(typeof e!=`string`||e===``)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`short`}).format(t)}var Ze=20,Qe=Object.freeze({items:[],totalCount:null,loading:!1,error:null,hasMore:!1}),$e=()=>void 0,et=()=>Qe;function tt(e,t){let n=Date.parse(e);if(Number.isNaN(n))return``;let r=(Date.now()-n)/1e3;if(r<60)return t.justNow;let i=new Intl.RelativeTimeFormat(void 0,{numeric:`auto`});return r<3600?i.format(-Math.floor(r/60),`minute`):r<86400?i.format(-Math.floor(r/3600),`hour`):r<604800?i.format(-Math.floor(r/86400),`day`):Xe(e)}function nt({chat:e,labels:t,open:n}){let r=e.features.History===!0,i=e.client,[a,o]=x(null);g(()=>{if(!r)return;let e=E({client:i,pageSize:Ze});return o(e),()=>e.dispose()},[i,r]);let s=m(e=>a?a.subscribe(e):$e,[a]),c=S(s,a?a.getState:et);g(()=>{n&&a&&a.load()},[n,a]);let l=e.features.ResumeLast?e.lastConversation?.publicId:void 0,u=c.items.filter(e=>e.publicId!==l).slice(0,Ze);return!r||c.error||u.length===0?null:/* @__PURE__ */ G(`div`,{className:`wui-chat-empty-rows wui-chat-past`,role:`group`,"aria-label":t.history,children:u.map(n=>/* @__PURE__ */ K(`button`,{type:`button`,className:`wui-chat-empty-row`,onClick:()=>e.openConversation(n.publicId),children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-empty-row-title`,children:n.title||t.earlierChat}),/* @__PURE__ */ G(`span`,{className:`wui-chat-empty-row-time`,title:Xe(n.lastActivityDateTimeUtc)||void 0,children:tt(n.lastActivityDateTimeUtc,t)})]},n.publicId))})}var rt=3;function it({chat:t,labels:n,onOpenTicket:r}){return!t.features.OpenTickets||t.openTickets.length===0?null:/* @__PURE__ */ G(`div`,{className:`wui-chat-open-tickets`,role:`group`,"aria-label":n.openTickets,children:t.openTickets.slice(0,rt).map(t=>{let i=/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-empty-row-label`,children:n.ticketAria(t.number)}),/* @__PURE__ */ G(`span`,{className:`wui-chat-empty-row-title`,children:t.subject}),/* @__PURE__ */ G(e,{className:`wui-chat-empty-row-status`,tone:Ve(t.status),children:n.ticketStatus(t.status)||t.status})]});return r?/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-empty-row`,onClick:()=>r({ticketId:t.ticketId,number:t.number}),children:i},t.ticketId):/* @__PURE__ */ G(`span`,{className:`wui-chat-empty-row`,children:i},t.ticketId)})})}function at({chat:e,labels:t,onOpenTicket:n}){let r=e.profile;if(!r)return null;let i=z(r,{pathname:window.location.pathname,returning:e.lastConversation!==null}),a=e.features.Starters&&i.starters.length>0,o=e.features.ResumeLast?e.lastConversation:null;return/* @__PURE__ */ K(`div`,{className:`wui-chat-empty`,children:[/* @__PURE__ */ K(`div`,{className:`wui-chat-empty-hero`,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-orb`,"aria-hidden":`true`}),/* @__PURE__ */ G(`h2`,{className:`wui-chat-greeting`,children:i.greeting})]}),a&&/* @__PURE__ */ G(`div`,{className:`wui-chat-starters`,role:`group`,"aria-label":t.starters,children:i.starters.map(t=>/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-starter`,onClick:()=>e.submit(t.message),children:t.label},t.id))}),o&&/* @__PURE__ */ G(`div`,{className:`wui-chat-empty-rows`,children:/* @__PURE__ */ K(`button`,{type:`button`,className:`wui-chat-empty-row`,onClick:()=>e.resumeLast(),children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-empty-row-label`,children:t.resumeLast}),/* @__PURE__ */ G(`span`,{className:`wui-chat-empty-row-title`,children:o.title||t.untitled}),/* @__PURE__ */ G(`span`,{className:`wui-chat-empty-row-time`,children:j(o.lastActivityDateTimeUtc)})]})}),/* @__PURE__ */ G(it,{chat:e,labels:t,onOpenTicket:n})]})}function ot({chat:e,labels:t}){let n=e.agentTyping;if(!n)return null;let r=typeof n==`object`&&n.displayName||He(e.messages)||t.handoffAgentFallback;return/* @__PURE__ */ G(`li`,{className:`wui-chat-message wui-chat-message--agent wui-chat-message--typing`,children:/* @__PURE__ */ K(`div`,{className:`wui-chat-typing`,role:`status`,children:[/* @__PURE__ */ K(`span`,{className:`wui-chat-typing-dots`,"aria-hidden":`true`,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-typing-dot`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-typing-dot`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-typing-dot`})]}),/* @__PURE__ */ G(`span`,{className:`visually-hidden`,children:t.agentTyping(r)})]})})}function st({author:e,labels:t}){if(e.kind!==`Agent`)return null;let n=typeof e.avatarUrl==`string`&&e.avatarUrl!==``?e.avatarUrl:null;return/* @__PURE__ */ K(`span`,{className:`wui-chat-author-badge`,children:[n?/* @__PURE__ */ G(`img`,{className:`wui-chat-author-avatar`,src:n,alt:``,"aria-hidden":`true`,width:24,height:24}):/* @__PURE__ */ G(`span`,{className:`wui-chat-author-avatar`,"aria-hidden":`true`,children:Be(e.displayName)}),/* @__PURE__ */ G(`span`,{className:`wui-chat-author-name`,children:e.displayName||t.agent}),/* @__PURE__ */ G(`span`,{className:`wui-chat-author-role`,children:t.handoffAgentFallback})]})}function ct({speech:e,enabled:t}){let n=!!(t&&e?.readAloud),[r,i]=x(!1),[a,o]=x(!1),s=b(null),c=b(!1);return g(()=>(c.current=!0,()=>{c.current=!1,s.current?.abort(),s.current=null}),[]),{available:n,speaking:r,failed:a,toggle:m(t=>{if(s.current){s.current.abort();return}if(!e||t.trim()===``)return;let n=new AbortController;s.current=n,i(!0),o(!1),e.speak(t,{signal:n.signal}).catch(()=>{!n.signal.aborted&&c.current&&o(!0)}).finally(()=>{s.current===n&&(s.current=null),c.current&&i(!1)})},[e])}}var lt=/* @__PURE__ */ new Set([`Assistant`,`Agent`,`Script`]);function ut({chat:e,labels:n,message:r}){let i=ct({speech:Te(e),enabled:e.features.ReadAloud});if(!i.available||r.streaming||!lt.has(r.author.kind))return null;let a=r.parts.filter(e=>e.kind===`Text`),o=e.features.FigureText?a.map(e=>({...e,text:B(e.text)})):a,s=ne(o);if(s.trim()===``)return null;let c=i.speaking?n.readAloudStop:n.readAloud;return/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(t,{className:i.speaking?`wui-chat-action-btn wui-chat-action-btn--active`:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,leftIcon:`volume-high`,"aria-pressed":i.speaking,"aria-label":c,title:c,onClick:()=>i.toggle(s),children:c}),i.failed&&/* @__PURE__ */ G(`span`,{className:`wui-chat-action-notice`,role:`status`,children:n.readAloudFailed})]})}function dt(e){return e===`wchat:muted`?globalThis.localStorage:globalThis.sessionStorage}var ft={get(e){try{return dt(e)?.getItem(e)??null}catch{return null}},set(e,t){try{dt(e)?.setItem(e,t)}catch{}}};async function pt(e){try{if(navigator.clipboard?.writeText)return await navigator.clipboard.writeText(e),!0}catch{}let t=document.createElement(`textarea`);t.value=e,t.setAttribute(`readonly`,``),t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();try{return document.execCommand(`copy`)}catch{return!1}finally{t.remove()}}async function mt(e,t){try{let n=await e.getAttachment(t.attachmentId),r=URL.createObjectURL(new Blob([n],{type:t.contentType}));return window.open(r,`_blank`,`noopener`),setTimeout(()=>URL.revokeObjectURL(r),6e4),!0}catch{return!1}}function ht(e){/^https?:\/\//i.test(e)?window.open(e,`_blank`,`noopener`):window.location.assign(e)}function gt(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 _t(e){let t=0;for(let n of e.parts)n.kind===`Text`&&(t+=n.text.length);return`${e.id}:${e.parts.length}:${t}`}function vt(e){return e===`Reduced`?`wui-chat--reduced`:``}var yt={Up:`check`,Down:`x`};function bt({chat:e,message:n,labels:r,isLast:i,isLastVisitor:a}){let{features:o}=e,[s,c]=x(!1),[l,u]=x(!1),[d,f]=x(!1),p=Ne(e,r),m=e.streaming||e.thinking;if(g(()=>{if(!s)return;let e=setTimeout(()=>c(!1),2e3);return()=>clearTimeout(e)},[s]),n.streaming)return null;let h=n.author.kind===`Assistant`||n.author.kind===`Agent`||n.author.kind===`Script`,_=h?ne(n.parts):``,v=h&&_!==``&&o.Copy,y=h&&_!==``&&o.ReadAloud,b=h&&_!==``&&o.Share&&p.canShare,S=h&&_!==``&&o.Print&&p.canPrint,C=i&&n.author.kind===`Assistant`&&!e.streaming&&o.Regenerate&&e.messages.some(e=>e.author.kind===`Visitor`&&e.stored),w=a&&o.Edit,T=o.Rating&&n.stored&&(n.author.kind===`Assistant`||n.author.kind===`Agent`);if(!v&&!y&&!b&&!S&&!C&&!w&&!T)return null;async function E(t){u(!1);try{await e.rate(n.id,t),f(!0)}catch{u(!0)}}return/* @__PURE__ */ K(W,{children:[v&&/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,leftIcon:`copy`,onClick:async()=>{let e=await pt(_);c(e)},children:s?r.copied:r.copy}),y&&/* @__PURE__ */ G(ut,{chat:e,labels:r,message:n}),b&&/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,leftIcon:`share`,disabled:m,onClick:()=>p.shareReply(n),children:r.share}),S&&/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,leftIcon:`printer`,disabled:m,onClick:()=>p.printReply(n),children:r.print}),C&&/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,leftIcon:`refresh`,onClick:()=>e.regenerate(),children:r.regenerate}),w&&/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,leftIcon:`pencil`,onClick:()=>e.startEdit(n.id),children:r.edit}),T&&/* @__PURE__ */ K(`div`,{className:`wui-chat-rating`,role:`group`,"aria-label":`${r.rateUp} / ${r.rateDown}`,children:[[`Up`,`Down`].map(e=>/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,leftIcon:yt[e],"aria-pressed":n.rating===e,"aria-label":e===`Up`?r.rateUp:r.rateDown,onClick:()=>E(e)},e)),l&&/* @__PURE__ */ G(`span`,{role:`status`,children:r.ratingFailed}),d&&!l&&/* @__PURE__ */ G(`span`,{role:`status`,children:r.rated})]}),p.notice!==null&&/* @__PURE__ */ G(`span`,{className:`wui-chat-action-notice`,role:`status`,children:p.notice})]})}function xt({view:e}){return/* @__PURE__ */ K(`div`,{className:`wui-chat-loader-orb`,children:[/* @__PURE__ */ K(`span`,{className:`wui-chat-loader-orb-mark`,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-orb-glow`,"aria-hidden":`true`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-orb-disc`,"aria-hidden":`true`})]}),/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-orb-label`,children:e.label})]})}var St=180;function Ct({view:e,motion:t}){let n=t===`Reduced`,[r,i]=x(()=>({id:0,label:e.label,previous:null}));e.label!==r.label&&i({id:r.id+1,label:e.label,previous:{id:r.id,label:r.label}}),g(()=>{if(!r.previous)return;let e=setTimeout(()=>i(e=>({...e,previous:null})),St);return()=>clearTimeout(e)},[r.previous]);let a=n?null:r.previous;return/* @__PURE__ */ K(`div`,{className:`wui-chat-loader-phrases`,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-phrases-orb`,"aria-hidden":`true`}),/* @__PURE__ */ K(`span`,{className:`wui-chat-loader-phrases-stage`,children:[a&&/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-phrases-text wui-chat-loader-phrases-text--out`,children:a.label},`out-${a.id}`),/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-phrases-text wui-chat-loader-phrases-text--in`,children:r.label},`in-${r.id}`)]})]})}var wt=[`92%`,`78%`,`85%`,`40%`];function Tt({view:e}){return/* @__PURE__ */ K(`div`,{className:`wui-chat-loader-skeleton`,children:[/* @__PURE__ */ G(`div`,{className:`wui-chat-loader-skeleton-label`,children:e.label}),/* @__PURE__ */ K(`div`,{className:`wui-chat-loader-skeleton-body`,children:[wt.map(e=>/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-skeleton-line`,"aria-hidden":`true`,style:{width:e}},e)),/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-skeleton-table`,"aria-hidden":`true`})]})]})}function Et(e,t){return e<t?`done`:e===t?`active`:`pending`}function Dt(e){let t=/* @__PURE__ */ new Map;return e.map(e=>{let n=(t.get(e)??0)+1;return t.set(e,n),{key:`${e}\u0000${n}`,text:e}})}function Ot({state:e}){return e===`done`?/* @__PURE__ */ G(`svg`,{viewBox:`0 0 16 16`,className:`wui-chat-loader-steps-check`,"aria-hidden":`true`,children:/* @__PURE__ */ G(`path`,{d:`M3 8.5 6.5 12 13 4.5`,pathLength:1})}):e===`active`?/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-steps-ring`,"aria-hidden":`true`}):/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-steps-dot`,"aria-hidden":`true`})}function kt({view:e}){return/* @__PURE__ */ G(`div`,{className:`wui-chat-loader-steps`,children:/* @__PURE__ */ G(`ol`,{className:`wui-chat-loader-steps-list`,children:Dt(e.steps).map(({key:t,text:n},r)=>{let i=Et(r,e.activeIndex);return/* @__PURE__ */ K(`li`,{className:`wui-chat-loader-steps-item`,"data-state":i,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-steps-icon`,"aria-hidden":`true`,children:/* @__PURE__ */ G(Ot,{state:i})}),/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-steps-text`,children:n})]},t)})})})}var At=500;function jt({style:e,view:t,motion:n}){return e===`Phrases`?/* @__PURE__ */ G(Ct,{view:t,motion:n}):G(e===`Orb`?xt:e===`Skeleton`?Tt:kt,{view:t})}function Mt({style:e=`Steps`,steps:t=[],phrases:n,intervalMs:r,announce:i,motion:a=`On`}){let o=a===`Reduced`,[s,c]=x({style:e,count:0}),[l,u]=x(!1);if(g(()=>{if(o)return;let t=setInterval(()=>c(t=>({style:e,count:t.count+1})),r);return()=>clearInterval(t)},[e,r,o]),g(()=>{let e=setTimeout(()=>u(!0),At);return()=>clearTimeout(e)},[]),!C.includes(e))throw Error(`ChatLoader style must be one of ${C.join(`, `)}, got "${e}".`);if(!(r>0))throw Error(`ChatLoader needs intervalMs, a positive number of milliseconds.`);s.style!==e&&c({style:e,count:0});let d=o?0:s.count,f=L(e,t,n,d);return/* @__PURE__ */ K(`div`,{className:o?`wui-chat-loader wui-chat-loader--reduced`:`wui-chat-loader`,role:`status`,"aria-label":f.label,children:[/* @__PURE__ */ G(`div`,{className:`wui-chat-loader-body`,children:/* @__PURE__ */ G(jt,{style:e,view:f,motion:a})}),/* @__PURE__ */ G(`span`,{className:`visually-hidden`,"aria-live":`polite`,children:l?i:``})]})}function Nt({motion:e,mark:t}){return/* @__PURE__ */ K(`div`,{className:e===`Reduced`?`wui-chat-loader-typing wui-chat-loader--reduced`:`wui-chat-loader-typing`,"aria-hidden":`true`,children:[t===`None`?null:/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-typing-orb`,"aria-hidden":`true`}),/* @__PURE__ */ K(`span`,{className:`wui-chat-loader-typing-dots`,"aria-hidden":`true`,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-typing-dot`,"aria-hidden":`true`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-typing-dot`,"aria-hidden":`true`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-typing-dot`,"aria-hidden":`true`})]})]})}var Pt=`ChatLeadCapture`,Ft=/^https?:\/\//i,It={strong:`strong`,em:`em`,strike:`s`};function Lt(e,t={next:0}){return e.map(e=>{let n=t.next++;if(e.type===`text`||e.type===`citation`)return e.text;if(e.type===`link`){let r=Lt(e.children,t);return Ft.test(e.href)?/* @__PURE__ */ G(`a`,{href:e.href,target:`_blank`,rel:`noopener noreferrer`,children:r},n):/* @__PURE__ */ G(f,{children:r},n)}if(e.type in It){let r=It[e.type];return/* @__PURE__ */ G(r,{children:Lt(e.children,t)},n)}return e.type===`code`?/* @__PURE__ */ G(`code`,{children:e.text},n):null})}function Rt(e,t){return e.state===`Repeat`?e.decidedDateTimeUtc?t.actionRepeat(j(e.decidedDateTimeUtc)):t.actionDone:{Confirmed:t.actionConfirmed,Done:t.actionDone,Rejected:t.actionRejected,Expired:t.actionExpired,Failed:t.actionFailed}[e.state]}function zt(e){let t=e.indexOf(`: `);return t<0?{term:e,detail:null}:{term:e.slice(0,t),detail:e.slice(t+2)}}function Bt(e,t){return{id:e,label:t,action:`Send`,target:null,navigateAfterMs:null,icon:null,variant:null}}function Vt({part:e,turn:t}){let{labels:n,features:r}=t,i=r.LeadRecap&&e.actionKind===Pt,a=e.state===`Pending`,o=e.editFields??[],s=i&&o.length>0,c=i&&e.confirmLabel||n.actionConfirm,l=i&&e.rejectLabel||n.actionDismiss,[u,d]=x(null),[f,p]=x(null),[m,h]=x(!1),v=_(),y=b(null),S=b(null),C=u!==null;g(()=>{m&&S.current?.querySelector(`[role="menuitem"]`)?.focus()},[m]);async function w(e,t){p(null),d(e);try{await t()}catch(e){p(e?.message||n.actionFailed),d(null)}}function T(e){h(!1),y.current?.focus(),t.chooseQuickReply(Bt(`lead.edit:${e.id}`,e.label))}function E(e){let t=[...e.currentTarget.querySelectorAll(`[role="menuitem"]`)],n=t.indexOf(e.target);e.key===`Escape`?(e.preventDefault(),h(!1),y.current?.focus()):e.key===`ArrowDown`?(e.preventDefault(),t[(n+1)%t.length]?.focus()):e.key===`ArrowUp`?(e.preventDefault(),t[n<=0?t.length-1:n-1]?.focus()):e.key===`Home`?(e.preventDefault(),t[0]?.focus()):e.key===`End`?(e.preventDefault(),t[t.length-1]?.focus()):e.key===`Tab`&&h(!1)}return/* @__PURE__ */ K(`div`,{className:`wui-chat-action wui-chat-action--${e.state.toLowerCase()}`,children:[/* @__PURE__ */ G(`strong`,{className:`wui-chat-action-title`,children:e.title}),e.lines.length>0&&(i?/* @__PURE__ */ G(`dl`,{className:`wui-chat-action-lines`,children:e.lines.map(e=>{let{term:t,detail:n}=zt(e);return/* @__PURE__ */ K(`div`,{className:`wui-chat-action-line`,children:[/* @__PURE__ */ G(`dt`,{children:t}),n!==null&&/* @__PURE__ */ G(`dd`,{children:n})]},e)})}):/* @__PURE__ */ G(`ul`,{className:`wui-chat-action-lines`,children:e.lines.map(e=>/* @__PURE__ */ G(`li`,{children:e},e))})),i&&e.consentText&&/* @__PURE__ */ G(`p`,{className:`wui-chat-action-consent`,children:Lt(ge(e.consentText))}),e.note&&/* @__PURE__ */ G(`p`,{className:`wui-chat-action-note`,children:e.note}),!a&&/* @__PURE__ */ K(`p`,{className:`wui-chat-action-status wui-chat-action-status--${e.state.toLowerCase()}`,children:[Rt(e,n),e.state===`Done`&&e.decidedDateTimeUtc&&/* @__PURE__ */ K(W,{children:[` `,/* @__PURE__ */ G(`time`,{dateTime:e.decidedDateTimeUtc,children:j(e.decidedDateTimeUtc)})]})]}),(a||s)&&/* @__PURE__ */ K(`div`,{className:`wui-chat-action-buttons`,children:[a&&/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(`button`,{className:`btn btn-primary btn-sm`,type:`button`,disabled:C,onClick:()=>w(`confirm`,()=>t.confirmAction(e.actionId)),children:u===`confirm`?n.actionWorking:c}),/* @__PURE__ */ G(`button`,{className:`btn btn-soft-primary btn-sm`,type:`button`,disabled:C,onClick:()=>w(`reject`,()=>t.rejectAction(e.actionId)),children:l})]}),s&&/* @__PURE__ */ G(`button`,{ref:y,className:`btn btn-soft-primary btn-sm wui-chat-action-edit`,type:`button`,"aria-haspopup":`menu`,"aria-expanded":m,"aria-controls":m?v:void 0,disabled:!a||C,onClick:()=>h(e=>!e),children:n.editSomething})]}),s&&m&&/* @__PURE__ */ G(`ul`,{id:v,ref:S,className:`list-group wui-chat-action-menu`,role:`menu`,"aria-label":n.editSomething,onKeyDown:E,children:o.map(e=>/* @__PURE__ */ G(`li`,{role:`none`,children:/* @__PURE__ */ G(`button`,{className:`list-group-item list-group-item-action wui-chat-action-menu-item`,type:`button`,role:`menuitem`,tabIndex:-1,onClick:()=>T(e),children:e.label})},e.id))}),f&&/* @__PURE__ */ G(`p`,{className:`wui-chat-action-error`,role:`alert`,children:f})]})}function Q({text:e,enabled:t}){if(!t||typeof e!=`string`)return e;let n=0;return/* @__PURE__ */ G(W,{children:ie(e).map(e=>{let t=`${n}-${e.kind}`;return n+=e.text.length,e.kind===`sub`?/* @__PURE__ */ G(`sub`,{children:e.text},t):e.kind===`sup`?/* @__PURE__ */ G(`sup`,{children:e.text},t):/* @__PURE__ */ G(f,{children:e.text},t)})})}function Ht(e,t){return t&&typeof e==`string`?B(e):e}var Ut={Bar:`column`,Line:`line`,Donut:`donut`},Wt=8,Gt=4;function Kt({part:e,turn:t}){if(!t.features.RichAnswers)return null;let r=t.features.FigureText,i=e.chartType===`Donut`?e.series.slice(0,1):e.series.slice(0,Wt),a=i.map(e=>new Map(e.points.map(e=>[e.label,e.value]))),o=[...new Set(i.flatMap(e=>e.points.map(e=>e.label)))].map(e=>{let t={label:Ht(e,r)};return a.forEach((n,r)=>{t[`s${r}`]=n.get(e)??null}),t}),s=e.unit?Ht(e.unit,r):null,c=i.map((e,t)=>{let n=Ht(e.name,r);return{key:`s${t}`,label:s?`${n} (${s})`:n,format:{style:`number`}}}),l=Math.max(0,...i.map(e=>e.points.length)),u=e.chartType===`Bar`&&l>Gt?300:240;return/* @__PURE__ */ K(`figure`,{className:`wui-chat-chart`,children:[e.title?/* @__PURE__ */ G(`figcaption`,{className:`wui-chat-rich-title`,children:/* @__PURE__ */ G(Q,{text:e.title,enabled:r})}):null,/* @__PURE__ */ G(n,{type:Ut[e.chartType],title:e.title===null?t.labels.chart:Ht(e.title,r),data:o,x:{key:`label`},series:c,height:u})]})}var qt={Neutral:`neutral`,Positive:`success`,Caution:`warning`,Negative:`danger`},Jt=/* @__PURE__ */ new Set([`Positive`,`Caution`,`Negative`]),Yt=3,Xt=5;function Zt(e){let t=0;return e.map(e=>{let n=`${t}-${e.kind}`;return t+=e.text.length,e.kind===`sub`?/* @__PURE__ */ G(`sub`,{children:e.text},n):e.kind===`sup`?/* @__PURE__ */ G(`sup`,{children:e.text},n):/* @__PURE__ */ G(`span`,{children:e.text},n)})}function Qt(e,t){let n=t?Zt(P(e.value)):M(e.value,`Decimal`,null);return e.unit?/* @__PURE__ */ K(W,{children:[n,` `,e.unit]}):n}function $t({part:e,turn:t}){if(!t.features.RichAnswers)return null;let n=t.features.FigureText,r=Math.min(Xt,Math.max(Yt,e.figures.length)),i=e.figures.map(e=>({label:/* @__PURE__ */ G(Q,{text:e.label,enabled:n}),value:Qt(e,n),tone:qt[e.status],note:Jt.has(e.status)?t.labels.figureStatus(e.status):void 0}));return/* @__PURE__ */ G(`div`,{className:`wui-chat-figures`,role:`group`,"aria-label":t.labels.figures,children:/* @__PURE__ */ G(c,{className:`wui-chat-figures-strip`,size:`sm`,columns:r,items:i})})}function en({part:e,turn:t}){let n=/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(`span`,{children:/* @__PURE__ */ G(a,{name:`document-text`,size:16})}),/* @__PURE__ */ G(`span`,{className:`wui-chat-file-name`,children:e.fileName}),/* @__PURE__ */ G(`span`,{className:`wui-chat-file-size`,children:F(e.length)})]});return/* @__PURE__ */ G(`div`,{className:`wui-chat-file`,children:t.openAttachment?/* @__PURE__ */ G(`button`,{className:`wui-chat-file-chip`,type:`button`,"aria-label":t.labels.fileOpen(e.fileName),onClick:()=>t.openAttachment(e),children:n}):/* @__PURE__ */ G(`span`,{className:`wui-chat-file-chip`,children:n})})}var tn=/* @__PURE__ */ new Set([`Requested`,`Waiting`,`Joined`,`Left`,`Ended`]);function nn({part:e,turn:t}){if(!tn.has(e.state))return null;let{labels:n}=t,r=e.agent?.displayName||null,i=e.agent?.avatarUrl||null,a=e.state.toLowerCase();return/* @__PURE__ */ K(`div`,{className:`wui-chat-handoff wui-chat-handoff--${a}`,role:`status`,children:[e.state===`Requested`&&/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-handoff-spinner`,"aria-hidden":`true`}),/* @__PURE__ */ G(`p`,{className:`wui-chat-handoff-text`,children:n.handoffRequested})]}),e.state===`Waiting`&&/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-handoff-spinner`,"aria-hidden":`true`}),/* @__PURE__ */ G(`p`,{className:`wui-chat-handoff-text`,children:n.handoffWaiting}),typeof e.queuePosition==`number`&&/* @__PURE__ */ G(`p`,{className:`wui-chat-handoff-queue`,children:n.handoffQueued(e.queuePosition)}),/* @__PURE__ */ G(`p`,{className:`wui-chat-handoff-note`,children:n.handoffQueuedText})]}),e.state===`Joined`&&/* @__PURE__ */ K(W,{children:[i?/* @__PURE__ */ G(`img`,{className:`wui-chat-handoff-avatar`,src:i,alt:``,"aria-hidden":`true`,width:32,height:32}):/* @__PURE__ */ G(`span`,{className:`wui-chat-handoff-avatar`,"aria-hidden":`true`,children:Be(r)}),/* @__PURE__ */ G(`p`,{className:`wui-chat-handoff-text`,children:n.handoffJoined(r??n.handoffAgentFallback)})]}),e.state===`Left`&&/* @__PURE__ */ G(`p`,{className:`wui-chat-handoff-text`,children:n.handoffLeft(r??n.handoffAgentFallback)}),e.state===`Ended`&&/* @__PURE__ */ G(`p`,{className:`wui-chat-handoff-text`,children:n.handoffEnded})]})}function rn({part:e,loadAttachmentUrl:t,turn:n}){let[r,i]=x({status:`loading`,url:null});return g(()=>{let n=!1;return t(e.attachmentId).then(e=>{n||i({status:`ready`,url:e})},()=>{n||i({status:`failed`,url:null})}),()=>{n=!0}},[t,e.attachmentId]),r.status===`loading`?/* @__PURE__ */ G(`div`,{className:`wui-chat-image-loading`,role:`status`,"aria-label":n.labels.imageLoading,children:/* @__PURE__ */ G(u,{height:160,radius:8})}):r.status===`failed`?/* @__PURE__ */ G(`p`,{className:`wui-chat-image-error`,role:`alert`,children:n.labels.imageFailed}):/* @__PURE__ */ G(o,{className:`wui-chat-image-view`,label:n.labels.imageViewer,items:[{key:e.attachmentId,src:r.url,alt:e.alt,name:e.alt}],download:!1})}function an({part:e,turn:t}){if(!t.features.RichAnswers)return null;let n=e.width&&e.height?{aspectRatio:`${e.width} / ${e.height}`}:void 0;return typeof t.loadAttachmentUrl==`function`?/* @__PURE__ */ G(`figure`,{className:`wui-chat-image`,style:n,children:/* @__PURE__ */ G(rn,{part:e,loadAttachmentUrl:t.loadAttachmentUrl,turn:t},e.attachmentId)}):/* @__PURE__ */ G(`figure`,{className:`wui-chat-image`,style:n,children:/* @__PURE__ */ G(`span`,{className:`wui-chat-image-alt`,children:e.alt})})}var on=/* @__PURE__ */ new Set([`ActionLimitReached`,`AssistantUnavailable`]);function sn({part:e}){let t=on.has(e.code)?`warning`:`info`;return/* @__PURE__ */ K(`div`,{className:`wui-chat-notice wui-chat-notice--${t}`,role:`status`,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-notice-icon`,"aria-hidden":`true`,children:/* @__PURE__ */ G(a,{name:`info`,size:16})}),/* @__PURE__ */ G(`span`,{className:`wui-chat-notice-text`,children:e.text})]})}var cn=[`Email`,`Phone`,`Name`,`Company`,`Text`,`LongText`,`Choice`,`MultiChoice`,`TimeSlot`,`File`,`Consent`],ln={Email:{type:`email`,autoComplete:`email`},Phone:{type:`tel`,autoComplete:`tel`},Name:{type:`text`,autoComplete:`name`},Company:{type:`text`,autoComplete:`organization`},Text:{type:`text`,autoComplete:void 0}},un=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`,month:`short`,hour:`numeric`,minute:`2-digit`});function dn(e,t){return e.state===`Answered`?e.answeredSummary||t.inputAnswered:e.state===`Skipped`?t.inputSkipped:t.inputExpired}function fn(e){return e.type===`Consent`?!1:e.type===`MultiChoice`?[]:``}function pn(e){return Object.fromEntries(e.map(e=>[e.key,fn(e)]))}function mn(e,t){return e.secret?t:t.trim()}function hn(e,t,n){return e.required?e.type===`Consent`?t?null:n.inputConsentRequired:e.type===`MultiChoice`?t.length>0?null:n.inputRequired:mn(e,t)?null:n.inputRequired:null}function gn(e,t){return e.type===`Consent`?t?`true`:`false`:e.type===`MultiChoice`?JSON.stringify((e.options??[]).map(e=>e.id).filter(e=>t.includes(e))):e.type===`Choice`||e.type===`TimeSlot`?t:mn(e,t)}function _n({field:e,value:t,error:n,file:r,disabled:i,id:a,labels:o,onChange:s,onFile:c,onRemove:l,controlRef:u}){let d=`${a}-error`,f=d,p=n?`true`:void 0,m=e.required||void 0,h=/* @__PURE__ */ G(`p`,{className:`wui-chat-field-error`,id:d,role:`alert`,hidden:!n,children:n}),g=e.required?null:/* @__PURE__ */ G(`span`,{className:`wui-chat-field-hint`,children:o.inputOptional});if(e.type===`Choice`){let n=`${a}-label`;return/* @__PURE__ */ K(`div`,{className:`wui-chat-field`,"data-key":e.key,children:[/* @__PURE__ */ G(`span`,{className:`form-label`,id:n,children:e.label}),g,/* @__PURE__ */ G(`div`,{role:`radiogroup`,"aria-labelledby":n,"aria-invalid":p,"aria-describedby":f,children:(e.options??[]).map((n,r)=>{let o=`${a}-${n.id}`;return/* @__PURE__ */ K(`div`,{className:`form-check`,children:[/* @__PURE__ */ G(`input`,{className:`form-check-input`,type:`radio`,id:o,name:e.key,value:n.id,checked:t===n.id,disabled:i,onChange:()=>s(n.id),ref:r===0?u:void 0}),/* @__PURE__ */ G(`label`,{className:`form-check-label`,htmlFor:o,children:n.label})]},n.id)})}),h]})}if(e.type===`MultiChoice`){let n=`${a}-label`;return/* @__PURE__ */ K(`div`,{className:`wui-chat-field`,"data-key":e.key,children:[/* @__PURE__ */ G(`span`,{className:`form-label`,id:n,children:e.label}),g,/* @__PURE__ */ G(`div`,{className:`wui-chat-input-choices`,role:`group`,"aria-labelledby":n,"aria-invalid":p,"aria-describedby":f,children:(e.options??[]).map((n,r)=>{let o=`${a}-${n.id}`;return/* @__PURE__ */ K(`div`,{className:`form-check`,children:[/* @__PURE__ */ G(`input`,{className:`form-check-input`,type:`checkbox`,id:o,name:e.key,value:n.id,checked:t.includes(n.id),disabled:i,onChange:e=>s(e.target.checked?[...t,n.id]:t.filter(e=>e!==n.id)),ref:r===0?u:void 0}),/* @__PURE__ */ G(`label`,{className:`form-check-label`,htmlFor:o,children:n.label})]},n.id)})}),h]})}if(e.type===`TimeSlot`){let n=`${a}-label`;return/* @__PURE__ */ K(`div`,{className:`wui-chat-field`,"data-key":e.key,children:[/* @__PURE__ */ G(`span`,{className:`form-label`,id:n,children:e.label}),g,/* @__PURE__ */ G(`div`,{className:`wui-chat-input-slots d-flex flex-wrap gap-2`,role:`radiogroup`,"aria-labelledby":n,"aria-invalid":p,"aria-describedby":f,children:(e.slots??[]).map((n,r)=>{let o=`${a}-${n.id}`;return/* @__PURE__ */ K(`div`,{className:`wui-chat-input-slot`,children:[/* @__PURE__ */ G(`input`,{className:`btn-check`,type:`radio`,id:o,name:e.key,value:n.id,checked:t===n.id,disabled:i,onChange:()=>s(n.id),ref:r===0?u:void 0}),/* @__PURE__ */ G(`label`,{className:`btn btn-outline-primary`,htmlFor:o,children:un.format(new Date(n.startDateTimeUtc))})]},n.id)})}),h]})}if(e.type===`File`)return/* @__PURE__ */ K(`div`,{className:`wui-chat-field`,"data-key":e.key,children:[/* @__PURE__ */ G(`label`,{className:`form-label`,htmlFor:a,children:e.label}),g,r?/* @__PURE__ */ K(`div`,{className:`wui-chat-input-file`,children:[r.status===`uploading`&&/* @__PURE__ */ G(`span`,{className:`wui-chat-input-file-status`,children:o.attachmentUploading}),/* @__PURE__ */ G(`span`,{className:`wui-chat-input-file-name`,children:r.name}),/* @__PURE__ */ G(`button`,{className:`btn btn-link`,type:`button`,disabled:i,onClick:l,children:o.inputRemoveFile(r.name)})]}):/* @__PURE__ */ G(`input`,{className:`form-control`,type:`file`,id:a,name:e.key,accept:e.accept?.join(`,`),disabled:i,"aria-label":o.inputChooseFile,"aria-required":m,"aria-invalid":p,"aria-describedby":f,onChange:e=>{let t=e.target.files?.[0];t&&c(t)},ref:u}),h]});if(e.type===`Consent`)return/* @__PURE__ */ K(`div`,{className:`wui-chat-field`,"data-key":e.key,children:[/* @__PURE__ */ K(`div`,{className:`form-check`,children:[/* @__PURE__ */ G(`input`,{className:`form-check-input`,type:`checkbox`,id:a,name:e.key,checked:t,disabled:i,"aria-invalid":p,"aria-describedby":f,onChange:e=>s(e.target.checked),ref:u}),/* @__PURE__ */ G(`label`,{className:`form-check-label`,htmlFor:a,children:e.consentText||e.label})]}),h]});let _=ln[e.type],v=e.type===`LongText`&&!e.secret?/* @__PURE__ */ G(`textarea`,{className:`form-control`,id:a,name:e.key,rows:3,value:t,placeholder:e.placeholder??void 0,maxLength:e.maxLength??void 0,disabled:i,"aria-required":m,"aria-invalid":p,"aria-describedby":f,onChange:e=>s(e.target.value),ref:u}):/* @__PURE__ */ G(`input`,{className:`form-control`,id:a,name:e.key,type:e.secret?`password`:_.type,autoComplete:e.secret?`off`:_.autoComplete,value:t,placeholder:e.placeholder??void 0,maxLength:e.maxLength??void 0,disabled:i,"aria-required":m,"aria-invalid":p,"aria-describedby":f,onChange:e=>s(e.target.value),ref:u});return/* @__PURE__ */ K(`div`,{className:`wui-chat-field`,"data-key":e.key,children:[/* @__PURE__ */ G(`label`,{className:`form-label`,htmlFor:a,children:e.label}),g,v,h]})}function vn({part:e,turn:t}){let{labels:n,features:r}=t,i=_(),[a,o]=x(()=>pn(e.fields)),[s,c]=x({}),[l,u]=x(null),[d,f]=x(!1),[p,m]=x(null),[h,v]=x({}),y=b({}),S=b({});g(()=>{p&&y.current[p.key]?.focus()},[p]);let C=e.fields.length===1?e.fields[0]:null,w=r.LeadShortcuts&&C!==null&&!C.required,T=r.LeadShortcuts&&e.cancellable,E=Object.values(h).some(e=>e.status===`uploading`);function D(t){return e.fields.find(e=>t[e.key])?.key??e.fields[0]?.key}function O(e,t){o(n=>({...n,[e]:t}))}async function k(e,r){let i={};S.current[e]=i,v(t=>({...t,[e]:{status:`uploading`,name:r.name}})),O(e,``),c(t=>({...t,[e]:void 0}));let a;try{a=await t.uploadInputFile(r)}catch{if(S.current[e]!==i)return;v(t=>({...t,[e]:{status:`failed`,name:r.name}})),c(t=>({...t,[e]:n.attachmentFailed}));return}S.current[e]===i&&(O(e,a),v(t=>({...t,[e]:{status:`ready`,name:r.name}})))}function A(e){S.current[e]=null,O(e,``),v(t=>Object.fromEntries(Object.entries(t).filter(([t])=>t!==e))),c(t=>({...t,[e]:void 0}))}async function j(r){if(r.preventDefault(),E)return;let i={};for(let t of e.fields){let e=t.type===`File`&&h[t.key]?.status===`failed`?n.attachmentFailed:hn(t,a[t.key],n);e&&(i[t.key]=e)}if(u(null),c(i),Object.keys(i).length>0){m({key:D(i)});return}f(!0);let o=Object.fromEntries(e.fields.map(e=>[e.key,gn(e,a[e.key])])),s;try{s=await t.answerInput(e.requestId,o)}catch{s={ok:!1,errors:{},message:n.errorGeneric}}if(s.ok)return;let l=Object.entries(s.errors).filter(([t])=>!e.fields.some(e=>e.key===t)).map(([,e])=>e),d=[s.message,...l].filter(Boolean);c(s.errors),u(d.length>0?d.join(` `):null),f(!1),m({key:D(s.errors)})}return/* @__PURE__ */ K(`form`,{className:`wui-chat-input-form`,noValidate:!0,"aria-label":e.title||e.submitLabel,onSubmit:j,children:[e.title&&/* @__PURE__ */ G(`h3`,{className:`wui-chat-input-title`,children:e.title}),e.fields.map(e=>/* @__PURE__ */ G(_n,{field:e,value:a[e.key],error:s[e.key],file:h[e.key],disabled:d,id:`${i}-${e.key}`,labels:n,onChange:t=>O(e.key,t),onFile:t=>k(e.key,t),onRemove:()=>A(e.key),controlRef:t=>{y.current[e.key]=t}},e.key)),/* @__PURE__ */ G(`p`,{className:`wui-chat-input-error`,role:`alert`,hidden:!l,children:l}),/* @__PURE__ */ K(`div`,{className:`d-flex flex-wrap gap-2`,children:[/* @__PURE__ */ G(`button`,{className:`btn btn-primary`,type:`submit`,"data-wui":`AppButton`,disabled:d||E,children:d?n.inputSubmitting:e.submitLabel}),w&&/* @__PURE__ */ G(`button`,{className:`btn btn-soft-primary`,type:`button`,"data-wui":`AppButton`,disabled:d,onClick:()=>t.skipInput(e.requestId),children:n.skip}),T&&/* @__PURE__ */ G(`button`,{className:`btn btn-link`,type:`button`,disabled:d,onClick:()=>t.cancelLead(),children:n.cancel})]}),e.allowTyped&&/* @__PURE__ */ G(`p`,{className:`wui-chat-input-typed`,children:n.typeAnswer})]})}function yn({part:e,message:t,turn:n}){if(e.fields.some(e=>!cn.includes(e.type)))return/* @__PURE__ */ G(sn,{part:{kind:`Notice`,code:`NeedsNewerApp`,text:n.labels.needsNewerApp},message:t,turn:n});let r=`wui-chat-input-request wui-chat-input-request--${e.state.toLowerCase()}`;return/* @__PURE__ */ G(`div`,{className:r,children:e.state===`Open`?/* @__PURE__ */ G(vn,{part:e,turn:n},e.requestId):/* @__PURE__ */ G(`p`,{className:`wui-chat-input-summary`,children:dn(e,n.labels)})})}var bn=p({resolveLink:null,linkComponent:null});function xn(){return h(bn)}var Sn={Primary:`wui-chat-quick-reply--primary`,Cta:`wui-chat-quick-reply--cta`};function Cn(e,t){return e.action===`Navigate`?!!t.features.LinkHandoff:e.action!==`Open`||!!e.target&&!!t.openTarget}function wn(e){return[`wui-chat-quick-reply`,Sn[e.variant]].filter(Boolean).join(` `)}function Tn(e,t,n){return I(e.target,t.handoffHosts)?n?n(e.target):e.target:null}function En(e){return e.icon?/* @__PURE__ */ G(`span`,{className:`wui-chat-quick-reply-icon`,"aria-hidden":`true`,children:/* @__PURE__ */ G(a,{name:e.icon,size:16})}):null}function Dn({part:e,turn:t}){let{resolveLink:n}=xn();if(!t.features.SuggestedReplies||!t.isLast||t.busy||e.replies.length===0)return null;let r=e.placement===`Composer`?`wui-chat-quick-replies wui-chat-quick-replies--composer`:`wui-chat-quick-replies`;if(t.handoffPause)return/* @__PURE__ */ G(`div`,{className:r,role:`status`,children:t.labels.handoffMoment});let i=e.replies.filter(e=>Cn(e,t));if(i.length===0)return null;let a=t.openTarget??(e=>globalThis.location.assign(e));return/* @__PURE__ */ G(`div`,{className:r,role:`group`,"aria-label":t.labels.quickReplies,children:i.map((e,r)=>{let i={"--wui-chat-i":r};return e.action===`Navigate`?Tn(e,t,n)===null||typeof t.beginHandoff!=`function`?/* @__PURE__ */ G(`span`,{className:`wui-chat-quick-reply-label`,style:i,children:e.label},e.id):/* @__PURE__ */ K(`button`,{type:`button`,className:wn(e),style:i,onClick:()=>t.beginHandoff(e,a),children:[En(e),/* @__PURE__ */ G(`span`,{className:`wui-chat-quick-reply-label`,children:e.label})]},e.id):/* @__PURE__ */ K(`button`,{type:`button`,className:wn(e),style:i,onClick:()=>e.action===`Open`?t.openTarget(e.target):t.chooseQuickReply(e),children:[En(e),/* @__PURE__ */ G(`span`,{className:`wui-chat-quick-reply-label`,children:e.label})]},e.id)})})}function On({part:e,turn:n}){let r=_();if(!n.features.RichAnswers)return null;let a=n.features.FigureText,o=e.fields.map(e=>({label:/* @__PURE__ */ G(Q,{text:e.label,enabled:a}),value:/* @__PURE__ */ G(Q,{text:M(e.value,e.type,null),enabled:a})})),s=!!e.target&&typeof n.openRecord==`function`;return/* @__PURE__ */ K(`article`,{className:`wui-chat-record`,"aria-labelledby":r,children:[/* @__PURE__ */ K(`header`,{className:`wui-chat-record-head`,children:[/* @__PURE__ */ G(`h3`,{className:`wui-chat-record-title`,id:r,children:/* @__PURE__ */ G(Q,{text:e.title,enabled:a})}),e.subtitle?/* @__PURE__ */ G(`p`,{className:`wui-chat-record-subtitle`,children:/* @__PURE__ */ G(Q,{text:e.subtitle,enabled:a})}):null]}),/* @__PURE__ */ G(i,{className:`wui-chat-record-fields`,columns:1,size:`sm`,layout:`summary`,items:o}),s?/* @__PURE__ */ G(`div`,{className:`wui-chat-record-actions`,children:/* @__PURE__ */ G(t,{className:`wui-chat-record-open`,size:`sm`,type:`button`,"aria-label":n.labels.recordOpenFor(e.title),onClick:()=>n.openRecord(e),children:n.labels.recordOpen})}):null]})}var kn=/^https?:\/\//i;function An({source:e}){return/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-source-marker`,children:e.marker}),/* @__PURE__ */ G(`span`,{className:`wui-chat-source-title`,children:e.title})]})}function jn({part:e,turn:t}){return!t.features.Sources||e.sources.length===0?null:/* @__PURE__ */ K(`div`,{className:`wui-chat-sources`,children:[/* @__PURE__ */ G(`p`,{className:`wui-chat-sources-label`,children:t.labels.sources}),/* @__PURE__ */ G(`ul`,{className:`wui-chat-sources-list`,"aria-label":t.labels.sources,children:e.sources.map(e=>/* @__PURE__ */ G(`li`,{children:kn.test(e.url??``)?/* @__PURE__ */ G(`a`,{className:`wui-chat-source`,href:e.url,target:`_blank`,rel:`noopener noreferrer`,"aria-label":t.labels.openSource(e.title),"data-marker":e.marker,children:/* @__PURE__ */ G(An,{source:e})}):/* @__PURE__ */ G(`span`,{className:`wui-chat-source`,tabIndex:-1,"data-marker":e.marker,children:/* @__PURE__ */ G(An,{source:e})})},e.marker))})]})}var Mn=/* @__PURE__ */ new Set([`Integer`,`Decimal`,`MoneyMinor`,`Percent`]),Nn=50;function Pn(e){return e.id}function Fn(e,t,n,r){return e==null?null:t.type===`Text`?/* @__PURE__ */ G(Q,{text:e,enabled:r}):M(e,t.type,n)}function In({part:e,turn:t}){if(!t.features.RichAnswers)return null;let n=t.features.FigureText,i=e.columns.map((e,t)=>({key:`c${t}`,label:/* @__PURE__ */ G(Q,{text:e.label,enabled:n}),...Mn.has(e.type)?{align:`num`}:{}})),a=e.rows.map((t,r)=>{let i={id:r};return e.columns.forEach((r,a)=>{i[`c${a}`]=Fn(t[a],r,e.currency,n)}),i}),o=a.length>Nn;return/* @__PURE__ */ K(`div`,{className:`wui-chat-table`,children:[e.title?/* @__PURE__ */ G(`p`,{className:`wui-chat-rich-title`,children:/* @__PURE__ */ G(Q,{text:e.title,enabled:n})}):null,/* @__PURE__ */ G(r,{density:`cozy`,ariaLabel:e.title?Ht(e.title,n):void 0,columns:i,rows:a,rowKey:Pn,empty:t.labels.tableEmpty,maxHeight:o?360:void 0,virtual:o})]})}var Ln=/* @__PURE__ */ new Set([`Visitor`,`Customer`]),Rn=/^\d+$/;function zn({part:e,message:t,turn:n}){let{resolveLink:r,linkComponent:i}=xn(),a=n.features.FigureText;if(Ln.has(t.author.kind))return/* @__PURE__ */ G(`div`,{className:`wui-chat-bubble`,children:/* @__PURE__ */ G(Q,{text:e.text,enabled:a})});let o=n.handoffHosts,c=e=>I(e,o)?r?r(e):e:null,l=n.openCitation?e=>n.openCitation(Number(e)):void 0,u=n.isCitation??(e=>Rn.test(e));return/* @__PURE__ */ G(s,{value:e.text,links:`app`,headings:`text`,className:`wui-chat-text`,resolveLink:c,linkComponent:i||void 0,isCitation:u,onOpenCitation:l})}function Bn({part:n,turn:r}){let{labels:i}=r,o=i.ticketStatus(n.status);return/* @__PURE__ */ K(`div`,{className:`wui-chat-ticket`,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-ticket-icon`,"aria-hidden":`true`,children:/* @__PURE__ */ G(a,{name:`tag`,size:20})}),/* @__PURE__ */ K(`div`,{className:`wui-chat-ticket-body`,children:[/* @__PURE__ */ G(`strong`,{className:`wui-chat-ticket-number`,children:i.ticketAria(n.number)}),/* @__PURE__ */ G(`p`,{className:`wui-chat-ticket-subject`,children:n.subject}),o&&/* @__PURE__ */ G(e,{className:`wui-chat-ticket-status`,tone:Ve(n.status),children:o})]}),r.openTicket&&/* @__PURE__ */ G(t,{variant:`outline`,size:`sm`,className:`wui-chat-ticket-open`,onClick:()=>r.openTicket(n),children:i.ticketView})]})}var Vn=40,$=null;function Hn({part:e,turn:t}){let[n,r]=x(!1),[i,o]=x(!1),[s,c]=x(!1),[l,u]=x(!1),[d,f]=x(0),[p,h]=x(()=>Math.max(1,e.durationMs/1e3)),_=b(null),v=b(null),S=b(!1),C=y(()=>H(`${e.attachmentId}|${e.durationMs}`,Vn).map((e,t)=>({id:`bar-${t}`,position:t,height:e})),[e.attachmentId,e.durationMs]),w=m(()=>{_.current?.pause(),$===w&&($=null),o(!1)},[]);if(g(()=>(S.current=!0,()=>{S.current=!1,_.current?.pause(),v.current&&URL.revokeObjectURL(v.current),$===w&&($=null)}),[w]),!t.features.VoiceClips)return e.transcript?/* @__PURE__ */ G(`p`,{className:`wui-chat-audio-transcript`,children:e.transcript}):null;async function T(){if(i)w();else{r(!0),c(!1);try{if(!_.current){let n=await t.readAttachment(e.attachmentId);if(!S.current)return;v.current=URL.createObjectURL(new Blob([n]));let r=new Audio(v.current);r.addEventListener(`loadedmetadata`,()=>{Number.isFinite(r.duration)&&r.duration>0&&h(r.duration)}),r.addEventListener(`timeupdate`,()=>f(r.currentTime)),r.addEventListener(`ended`,()=>{o(!1),f(0),r.currentTime=0,$===w&&($=null)}),r.addEventListener(`error`,()=>{c(!0),o(!1)}),_.current=r}$?.(),await _.current.play(),$=w,o(!0)}catch{c(!0)}finally{S.current&&r(!1)}}}let E=Math.floor(Math.min(1,d/p)*Vn);return/* @__PURE__ */ K(`div`,{className:i?`wui-chat-audio wui-chat-audio--playing`:`wui-chat-audio`,role:`group`,"aria-label":t.labels.voiceClip,children:[/* @__PURE__ */ K(`div`,{className:`wui-chat-audio-row`,children:[/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-audio-play`,"aria-label":i?t.labels.voiceClipPause:t.labels.voiceClipPlay,"aria-busy":n,disabled:n,onClick:T,children:/* @__PURE__ */ G(a,{name:i?`pause`:`play`,size:16,"aria-hidden":`true`})}),/* @__PURE__ */ G(`div`,{className:`wui-chat-audio-wave`,"aria-hidden":`true`,children:C.map(({id:e,position:t,height:n})=>/* @__PURE__ */ G(`span`,{className:t<E?`wui-chat-audio-bar wui-chat-audio-bar--played`:`wui-chat-audio-bar`,style:{"--wui-chat-bar-height":`${Math.round(n*100)}%`}},e))}),/* @__PURE__ */ G(`span`,{className:`wui-chat-audio-time`,children:`${N(d)} / ${N(p)}`})]}),s&&/* @__PURE__ */ G(`p`,{className:`wui-chat-audio-error`,role:`status`,children:t.labels.voiceClipFailed}),e.transcript?/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-audio-toggle`,"aria-expanded":l,onClick:()=>u(!l),children:l?t.labels.voiceClipHideTranscript:t.labels.voiceClipShowTranscript}),l&&/* @__PURE__ */ G(`p`,{className:`wui-chat-audio-transcript`,children:e.transcript})]}):null]})}var Un={Text:zn,Sources:jn,QuickReplies:Dn,InputRequest:yn,Action:Vt,Notice:sn,Table:In,Chart:Kt,Figures:$t,RecordCard:On,Image:an,File:en,Ticket:Bn,Handoff:nn,VoiceClip:Hn},Wn={Visitor:`you`,Customer:`you`,Agent:`agent`,Assistant:`assistant`,Script:`assistant`,System:`assistant`},Gn={kind:`Notice`,code:`NeedsNewerApp`};function Kn(e,t){let n=e.author.kind;return e.author.displayName&&n!==`Visitor`&&n!==`Customer`?e.author.displayName:t[Wn[n]??`assistant`]}function qn(e,t){for(let n=e.length-1;n>=0;--n)if(t(e[n]))return n;return-1}function Jn(e,t){let n=/* @__PURE__ */ new Map,r=[];for(let i of e){let e=t(i),a=n.get(e)??0;n.set(e,a+1),r.push({key:`${e}#${a}`,item:i})}return r}function Yn({chat:e,labels:n,renderers:r,layoutParts:i,loader:a,motion:o,onOpenAttachment:s,onOpenTarget:c,onOpenTicket:l,onNavigate:u}){let d=b(null),f=b(/* @__PURE__ */ new Map),p={...Un,...r},m=u??e.onNavigate,h=e.pending?.authorKind,_=h===`Agent`||h===`Customer`?`None`:a===`Orb`?`Orb`:`Assistant`,v=e.messages.at(-1),y=!e.streaming&&(e.turnError!==null||e.stopped),x=e.turnError?.code===`daily_limit`,S=e.pending?.typing===!0,C=`${v?_t(v):``}|${e.thinking}|${S}|${y}`,w=qn(e.messages,e=>e.author.kind===`Visitor`&&e.stored),T=e.profile?.experience.pacing,E=e.profile?.assistant.name??``;g(()=>{if(!C)return;let e=gt(d.current);e&&(e.scrollTop=e.scrollHeight)},[C]);function D(e,t){f.current.get(e)?.querySelector(`[data-marker="${t}"]`)?.focus()}function O(e,t,r,i){let a=Object.hasOwn(p,r.kind),o=a?r:{...Gn,text:n.needsNewerApp},s=o.kind.toLowerCase(),c=a?p[r.kind]:p.Notice;return/* @__PURE__ */ G(`div`,{className:`wui-chat-part wui-chat-part--${s}`,children:/* @__PURE__ */ G(c,{part:o,message:e,turn:t})},i)}return/* @__PURE__ */ K(`ol`,{ref:d,className:`wui-chat-thread`,"aria-label":n.thread,"aria-live":`polite`,children:[e.messages.map((t,r)=>{if(t.streaming&&t.parts.length===0)return null;let a=k(e.session,{messageId:t.id,labels:n,openAttachment:s??(t=>mt(e.client,t)),openTarget:c??ht,...l?{openTicket:l}:{},openCitation:e=>D(t.id,e),onNavigate:m}),o=i?i(t):null;return/* @__PURE__ */ K(`li`,{ref:e=>{e?f.current.set(t.id,e):f.current.delete(t.id)},className:`wui-chat-message wui-chat-message--${t.author.kind.toLowerCase()}`,"aria-busy":t.streaming?`true`:void 0,"data-restored":t.restored?``:void 0,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-author visually-hidden`,children:`${Kn(t,n)}: `}),/* @__PURE__ */ G(st,{author:t.author,labels:n}),/* @__PURE__ */ G(`div`,{className:`wui-chat-message-body`,children:o?Jn(o,e=>Array.isArray(e)?`group`:`part`).map(({key:e,item:n})=>/* @__PURE__ */ G(`div`,{className:`wui-chat-part-group`,children:Jn(Array.isArray(n)?n:[n],e=>e.kind).map(({key:e,item:n})=>O(t,a,n,e))},e)):Jn(t.parts,e=>e.kind).map(({key:e,item:n})=>O(t,a,n,e))}),/* @__PURE__ */ G(`div`,{className:`wui-chat-message-actions`,children:/* @__PURE__ */ G(bt,{chat:e,message:t,labels:n,isLast:t===v,isLastVisitor:r===w})})]},t.id)}),/* @__PURE__ */ G(ot,{chat:e,labels:n}),S&&/* @__PURE__ */ G(`li`,{className:`wui-chat-message wui-chat-message--assistant wui-chat-message--loading`,children:/* @__PURE__ */ G(`div`,{className:`wui-chat-loader-slot`,children:/* @__PURE__ */ G(Nt,{motion:o,mark:_})})}),e.thinking&&/* @__PURE__ */ G(`li`,{className:`wui-chat-message wui-chat-message--assistant wui-chat-message--loading`,children:/* @__PURE__ */ G(`div`,{className:`wui-chat-loader-slot`,children:/* @__PURE__ */ G(Mt,{style:a,steps:e.steps,phrases:T?.thinkingPhrases??[],intervalMs:T?.phraseIntervalMs??2500,announce:n.preparingAnswer(E),motion:o})})}),y&&/* @__PURE__ */ K(`li`,{className:`wui-chat-message wui-chat-message--system wui-chat-message--error`,children:[x?/* @__PURE__ */ K(`p`,{className:`wui-chat-error wui-chat-error--info`,role:`status`,children:[e.turnError.message,e.turnError.resetsAtUtc?` ${n.dailyLimitRefresh(Xe(e.turnError.resetsAtUtc))}`:``]}):/* @__PURE__ */ G(`p`,{className:`wui-chat-error`,role:`alert`,children:e.turnError?.message??n.stopped}),e.features.Retry&&!x&&/* @__PURE__ */ G(`div`,{className:`wui-chat-message-actions`,children:/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,onClick:()=>e.retry(),children:n.retry})})]})]})}function Xn(e){let t=e.features.Sounds?e.profile?.experience.sound??null:null,n=b(null),r=b(e);r.current=e;let i=b({open:e.open,streaming:e.streaming}),a=t!==null&&(t.open||t.sent||t.reply||t.vibrate);g(()=>{if(!a)return;let e=oe(t,ft);return n.current=e,e.setMuted(r.current.muted),()=>{e.destroy(),n.current=null}},[a,t]);let{open:o,streaming:s,muted:c,turnError:l}=e;g(()=>{n.current?.setMuted(c)},[c]),g(()=>{let e=n.current,a=i.current;if(i.current={open:o,streaming:s},e&&(o&&!a.open&&e.play(`open`),s&&!a.streaming&&e.play(`sent`),!s&&a.streaming&&!l)){let n=r.current.messages.at(-1);n&&(n.author.kind===`Assistant`||n.author.kind===`Script`)&&(e.play(`reply`),t.vibrate&&pe(t.vibrateMs,r.current.muted))}},[o,s,l,t])}function Zn({chat:e,labels:t,layout:n,onClose:r,panelId:i,inputRef:o,ariaLabelOverride:s,renderers:c,layoutParts:l,loader:u,motion:d,onOpenAttachment:f,onOpenTarget:p,onOpenTicket:m,onNavigate:h,resolveLink:g=null,linkComponent:_=null,onSwitch:v,open:b=!0,renderEmpty:S}){let[C,w]=x(`chat`),T=y(()=>({resolveLink:g,linkComponent:_}),[g,_]);Xn(e);let{features:E}=e,D=e.profile,O=C===`history`,k=e.messages.length>0,A=n===`launcher`||n===`docked`,j=D?.experience.sound,M=!!(E.Sounds&&j?.muteControl&&(j.open||j.sent||j.reply||j.vibrate)),N=A?`dialog`:`region`,P=s??D?.assistant.name??t.panelTitle,F=E.PanelSwitch===!0,I=n===`full-page`||n===`embedded`||k,L=F&&typeof v==`function`&&(n===`docked`||n===`full-page`),ee=n===`full-page`&&F&&typeof r==`function`;function te(){w(`chat`),r?.()}function ne(){if(e.profileError)return/* @__PURE__ */ G(`p`,{className:`wui-chat-profile-error`,role:`alert`,children:e.profileError.message});if(!D&&(n===`full-page`||n===`embedded`)||e.loading)return/* @__PURE__ */ G(`p`,{role:`status`,"aria-busy":`true`,children:t.loadingConversation});if(e.loadError)return/* @__PURE__ */ G(`p`,{className:`wui-chat-profile-error`,role:`alert`,children:e.loadError.message});if(!k){let n=/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(at,{chat:e,labels:t,onOpenTicket:m}),E.History&&/* @__PURE__ */ G(nt,{chat:e,labels:t,open:b})]});return S?S({chat:e,labels:t,open:b,defaultEmpty:n}):n}return/* @__PURE__ */ G(bn.Provider,{value:T,children:/* @__PURE__ */ G(Yn,{chat:e,labels:t,renderers:c,layoutParts:l,loader:u,motion:d,onOpenAttachment:f,onOpenTarget:p,onOpenTicket:m,onNavigate:h})})}return/* @__PURE__ */ K(`section`,{id:i,className:`wui-chat-panel`,role:N,"aria-label":P,children:[/* @__PURE__ */ K(`header`,{className:`wui-chat-header`,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-orb`,"aria-hidden":`true`}),/* @__PURE__ */ K(`div`,{className:`wui-chat-header-text`,children:[/* @__PURE__ */ G(`strong`,{className:`wui-chat-title`,children:D?.assistant.name??``}),/* @__PURE__ */ G(`span`,{className:`wui-chat-status`,children:Ue(e,t)??t.headerStatus})]}),/* @__PURE__ */ K(`div`,{className:`wui-chat-header-actions`,children:[!O&&/* @__PURE__ */ G(Pe,{chat:e,labels:t}),E.History&&(O?/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-icon-btn`,"aria-label":t.backToChat,title:t.backToChat,onClick:()=>w(`chat`),children:/* @__PURE__ */ G(a,{name:`arrow-left`,size:18,"aria-hidden":`true`})}):/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-icon-btn`,"aria-label":t.history,title:t.history,onClick:()=>w(`history`),children:/* @__PURE__ */ G(a,{name:`history`,size:18,"aria-hidden":`true`})})),M&&/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-icon-btn`,"aria-pressed":e.muted,"aria-label":e.muted?t.unmuteSounds:t.muteSounds,title:e.muted?t.unmuteSounds:t.muteSounds,onClick:()=>e.session.setMuted(!e.muted),children:/* @__PURE__ */ G(a,{name:e.muted?`volume-mute`:`volume-high`,size:18,"aria-hidden":`true`})}),!O&&I&&/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-icon-btn`,"aria-label":t.newChat,title:t.newChat,disabled:e.streaming,onClick:()=>e.newConversation(),children:/* @__PURE__ */ G(a,{name:`plus`,size:18,"aria-hidden":`true`})}),L&&/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-icon-btn wui-chat-icon-btn--switch`,"aria-label":n===`docked`?t.openFullScreen:t.openSidePanel,title:n===`docked`?t.openFullScreen:t.openSidePanel,disabled:e.streaming,onClick:()=>v(),children:/* @__PURE__ */ G(a,{name:n===`docked`?`maximize-4`:`maximize-3`,size:18,"aria-hidden":`true`})}),(A||ee)&&/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-icon-btn`,"aria-label":t.close,title:t.close,onClick:te,children:/* @__PURE__ */ G(a,{name:`x`,size:18,"aria-hidden":`true`})})]})]}),/* @__PURE__ */ G(`div`,{className:`wui-chat-body`,children:O?/* @__PURE__ */ G(Re,{chat:e,labels:t,onOpen:()=>w(`chat`)}):ne()}),!O&&/* @__PURE__ */ K(`div`,{className:`wui-chat-foot`,children:[/* @__PURE__ */ G(Ge,{chat:e,labels:t}),/* @__PURE__ */ G(Oe,{chat:e,labels:t,maxLength:D?.limits.maxMessageLength??4e3,inputRef:o}),/* @__PURE__ */ G(Fe,{chat:e,labels:t})]})]})}function Qn(e,t){let n=b(!1);g(()=>{n.current||(n.current=!0,typeof t?.conversationId==`string`&&t.conversationId!==``&&e.openConversation(t.conversationId),typeof t?.draft==`string`&&t.draft!==``&&e.session.open({draft:t.draft}))},[e,t])}function $n(e,t){let[n,r]=x(!1);return g(()=>{let n=he(e,t??null);r(n.reduced);let i=n.subscribe(()=>r(n.reduced));return()=>{i(),n.destroy()}},[e,t]),n}function er({chat:e,labels:t,renderers:n,layoutParts:r,loader:i,motion:a=`On`,onOpenAttachment:o,onOpenTarget:s,onNavigate:c,resolveLink:l,linkComponent:u,className:d,style:f,theme:p,look:m,onOpenSidePanel:h,onClose:g,renderEmpty:_,handoff:v}){let y=b(null);Qn(e,v??null);let x=e.features.PanelSwitch===!0&&typeof h==`function`?()=>{let t={conversationId:e.conversationId,draft:y.current?.value??``};de(()=>h(t),{target:`docked`}).catch(e=>globalThis.reportError?.(e))}:void 0;return/* @__PURE__ */ G(tr,{layout:`full-page`,chat:e,labelOverrides:t,renderers:n,layoutParts:r,loader:i,motion:a,onOpenAttachment:o,onOpenTarget:s,onNavigate:c,resolveLink:l,linkComponent:u,className:d,style:f,theme:p,look:m,inputRef:y,onSwitch:x,onClose:g,renderEmpty:_})}function tr({layout:e,chat:t,labelOverrides:n,renderers:r,layoutParts:i,loader:a,motion:o,onOpenAttachment:s,onOpenTarget:c,onNavigate:l,resolveLink:u=null,linkComponent:d=null,className:f,style:p,theme:m,look:h,inputRef:g,onSwitch:_,onClose:v,renderEmpty:b}){let x=y(()=>ee(n),[n]),S=$n(y(()=>te(h),[h]),t.profile?.experience??null),C=o===`Reduced`||S?`Reduced`:`On`;if(t.profile!==null&&!t.features.VisitorChat)return null;let w=[`wui-chat`,`wui-chat--${e}`,vt(C),f].filter(Boolean).join(` `);return/* @__PURE__ */ G(`div`,{className:w,style:p,"data-state":`open`,"data-theme":m===`auto`?void 0:m,children:/* @__PURE__ */ G(Zn,{chat:t,labels:x,layout:e,panelId:void 0,renderers:r,layoutParts:i,loader:a,motion:C,onOpenAttachment:s,onOpenTarget:c,onNavigate:l,resolveLink:u,linkComponent:d,inputRef:g,onSwitch:_,onClose:v,renderEmpty:b})})}function nr(e){return/* @__PURE__ */ G(tr,{...e,layout:`embedded`})}var rr=`a[href], button:not([disabled]), input:not([disabled]), [tabindex]:not([tabindex="-1"])`;function ir(e){let t=b(null);return g(()=>{let n=document.activeElement;return t.current?.querySelector(rr)?.focus({preventScroll:!0}),()=>(e.current??n)?.focus?.({preventScroll:!0})},[e]),g(()=>{let e=t.current;if(!e||typeof ResizeObserver>`u`)return;let n=0,r=new ResizeObserver(()=>{cancelAnimationFrame(n),n=requestAnimationFrame(()=>window.dispatchEvent(new Event(`scroll`)))});return r.observe(e),()=>{cancelAnimationFrame(n),r.disconnect()}},[]),t}function ar({x:e,labels:n,renderAnswer:r,renderFoot:i,askDraft:a,chat:o,close:s,triggerRef:c}){let l=ir(c),{state:u,answer:d,pillVisible:f,resetsAtUtc:p}=e,m=null;if((u===`thinking`||u===`slow`)&&f)m=/* @__PURE__ */ K(`div`,{className:`wui-chat-explain-pill`,role:`status`,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-explain-pill-dot`,"aria-hidden":`true`}),/* @__PURE__ */ G(`span`,{children:u===`slow`?n.explainSlow:n.thinking})]});else if(u===`answered`)m=/* @__PURE__ */ G(`div`,{className:`wui-chat-explain-answer`,children:r({answer:d,labels:n,close:s})});else if(u===`empty`)m=/* @__PURE__ */ G(`p`,{className:`wui-chat-explain-note`,children:n.explainEmpty});else if(u===`capacity`){let e=Xe(p);m=/* @__PURE__ */ G(`p`,{className:`wui-chat-explain-notice wui-chat-explain-notice--info`,role:`status`,children:e?n.explainCapacity(e):n.explainCapacityNoDate})}else u===`error`&&(m=/* @__PURE__ */ K(`div`,{className:`wui-chat-explain-notice wui-chat-explain-notice--error`,role:`alert`,children:[/* @__PURE__ */ G(`p`,{children:n.explainError}),/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,onClick:()=>e.ask(),children:n.explainRetry})]}));let h=typeof a==`string`&&a!==``&&typeof o.session?.open==`function`;return/* @__PURE__ */ K(`div`,{ref:l,className:`wui-chat-explain`,children:[m,/* @__PURE__ */ K(`div`,{className:`wui-chat-explain-foot`,children:[i?.({close:s}),h&&/* @__PURE__ */ G(t,{className:`wui-chat-explain-more`,size:`sm`,variant:`ghost`,onClick:()=>{s(),o.session.open({draft:a})},children:n.explainAskMore}),/* @__PURE__ */ G(`p`,{className:`wui-chat-explain-note`,children:n.explainNotCounted})]})]})}function or({chat:e,request:t,renderAnswer:n,label:r,renderFoot:i,askDraft:o,labels:s,placement:c=`auto`,className:u,triggerContent:f}){let p=y(()=>ee(s),[s]),[m,h]=x(!1),_=Ye({request:t,enabled:e.features.Explain===!0}),v=b(null),S=b(!1);if(g(()=>{if(!m)return;let e=e=>{S.current=!!e.target?.closest?.(`.wui-chat-panel`)};return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[m]),!e.features.Explain)return null;function C(e){!e&&(S.current||document.querySelector(`.wui-chat--docked[data-open=true]`))?S.current=!1:(h(e),e?_.ask():_.reset())}function w(){h(!1),_.reset()}let T=/* @__PURE__ */ K(`button`,{type:`button`,className:[`wui-chat-explain-trigger`,m?`wui-chat-explain-trigger--open`:null].filter(Boolean).join(` `),"aria-haspopup":`dialog`,"aria-label":p.explainTriggerLabel(r),disabled:_.offline,onClick:e=>{v.current=e.currentTarget},children:[/* @__PURE__ */ G(a,{name:`magic-star`,size:14,"aria-hidden":`true`}),f??p.explainTrigger]});return _.offline?/* @__PURE__ */ G(d,{content:p.explainOffline,children:/* @__PURE__ */ G(`span`,{className:`wui-chat-explain-offline`,children:T})}):/* @__PURE__ */ G(l,{trigger:T,title:r,placement:c,open:m,onOpenChange:C,role:`dialog`,className:[`wui-chat-explain-pop`,u].filter(Boolean).join(` `),children:/* @__PURE__ */ G(ar,{x:_,labels:p,renderAnswer:n,renderFoot:i,askDraft:o,chat:e,close:w,triggerRef:v})})}function sr({chat:e,labels:t,enabled:n,onActivate:r}){let i=e.profile?R(e.profile,e.features):null,[o,s]=x(!1),[c,l]=x(!1),u=(i?.delaySeconds??0)*1e3;return g(()=>{if(!n||!i||c){s(!1);return}let e=setTimeout(()=>s(!0),u);return()=>clearTimeout(e)},[n,i,u,c]),!o||!i||c?null:/* @__PURE__ */ K(`div`,{className:`wui-chat-nudge`,role:`status`,children:[/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-nudge-text`,onClick:r,children:i.text}),/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-nudge-close`,"aria-label":t.nudgeDismiss,onClick:()=>l(!0),children:/* @__PURE__ */ G(a,{name:`x`,size:14,"aria-hidden":`true`})})]})}function cr(e,t,n,r){g(()=>{let i=e.current;if(!r||!i||!n)return;let a=U(t,n,i);return()=>a.destroy()},[e,t,n,r])}var lr=620,ur=300,dr=`wchat:peeked`,fr=576,pr=200;function mr(e){return e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).toLowerCase()}function hr(e){return e?.querySelector(`:scope > .wui-chat-panel`)??null}function gr(e){let[t,n]=x(()=>globalThis.innerWidth<=e);return g(()=>{let t=()=>n(globalThis.innerWidth<=e);return t(),globalThis.addEventListener(`resize`,t),()=>globalThis.removeEventListener(`resize`,t)},[e]),t}function _r({chat:e,layout:t,labels:n,renderers:r,layoutParts:i,loader:o,motion:s=`On`,onOpenAttachment:c,onOpenTarget:l,onNavigate:u,resolveLink:d=null,linkComponent:f=null,className:p,style:h,theme:v,icon:S=`chat`,look:C,open:w,defaultOpen:T=!1,onOpenChange:E,position:D=`end`,offsetX:O=24,offsetY:k=24,panelId:A,switchConfig:j=null,renderEmpty:M}){let N=_(),P=A??N,F=y(()=>ee(n),[n]),I=y(()=>te(C),[C]),L=e.profile,ne=e.features,R=w!==void 0,z=R?w:e.open,re=$n(I,L?.experience??null),ie=s===`Reduced`||re?`Reduced`:`On`,B=L!==null&&ne.VisitorChat,V=t===`launcher`||t===`docked`,H=gr(I.phone.maxWidthPx),U=L?.experience.launcher??null,ae=I.launcher.style===`Pill`?`pill`:`round`,oe=I.launcher.labelReveal===`Expand`?`expand`:`bubble`,se=I.launcher.idle===`None`?`none`:mr(I.launcher.idle),pe=I.launcher.entrance===`None`?null:mr(I.launcher.entrance),me=U?.hideWhileOpen===!0,he=U?.peek===!0,W=U?.peekSeconds??3,ge=e.messages.length>0,_e=b(null),q=b(null),ve=b(null),ye=b(null),be=b(!1),xe=b(z),Se=b(z),Ce=b(!1),we=b(E);we.current=E;let[Te,Ee]=x(z?`open`:`closed`),[De,J]=x(null),[Oe,ke]=x(null),Y=De??(pe&&!H?`entering`:`idle`);cr(_e,I.avoid,U,t===`launcher`&&B);let X=m(e=>{xe.current!==e&&(xe.current=e,we.current?.(e))},[]),Z=m((t,n)=>{be.current=t,X(t),R||(t?e.session.open({trigger:`manual`}):e.session.close(n))},[R,e.session,X]);g(()=>{R&&(w&&!e.open&&e.session.open({trigger:`manual`}),!w&&e.open&&e.session.close(`button`))},[R,w,e.open,e.session]),g(()=>{!R&&T&&e.session.open({trigger:`manual`})},[R,T,e.session]),g(()=>{X(e.open)},[e.open,X]),g(()=>{if(z){Ee(e=>e===`open`?e:`opening`);let e=setTimeout(()=>Ee(`open`),lr);return()=>clearTimeout(e)}Ee(e=>e===`closed`?e:`closing`);let e=setTimeout(()=>Ee(`closed`),ur);return()=>clearTimeout(e)},[z]),g(()=>{Se.current!==z&&(Se.current=z,ke(z?`wui-chat-launcher--opening`:`wui-chat-launcher--closing`))},[z]),g(()=>{if(Te!==`opening`)return;let e=hr(q.current),t=ve.current;if(!e||!t)return;let n=t.getBoundingClientRect(),r=e.getBoundingClientRect();e.style.transformOrigin=`${n.left+n.width/2-r.left}px ${n.top+n.height/2-r.top}px`},[Te]),g(()=>{if(!me){J(e=>e===`hidden`?`idle`:e);return}if(z){J(`hidden`);return}let e=hr(q.current)?.contains(document.activeElement)??!1,t=setTimeout(()=>{Ce.current=e,J(`idle`)},pr);return()=>clearTimeout(t)},[z,me]),g(()=>{Y===`idle`&&Ce.current&&(Ce.current=!1,ue(ve.current))},[Y]),g(()=>{z||me||hr(q.current)?.contains(document.activeElement)&&ue(ve.current)},[z,me]),g(()=>{z&&J(e=>e===`peeking`?`idle`:e)},[z]),g(()=>{B&&Y===`idle`&&he&&!re&&!z&&(globalThis.innerWidth<fr||globalThis.sessionStorage.getItem(dr)!==null||(globalThis.sessionStorage.setItem(dr,`1`),J(`peeking`)))},[B,Y,he,re,z]),g(()=>{if(Y!==`peeking`)return;let e=setTimeout(()=>J(e=>e===`peeking`?`idle`:e),W*1e3);return()=>clearTimeout(e)},[Y,W]);let Ae=b(Z);Ae.current=Z,g(()=>{if(!z||!V)return;let e=e=>{e.key===`Escape`&&Ae.current(!1,`escape`)};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[z,V]),g(()=>{let e=hr(q.current);if(!B||!V||!e)return;let t=t=>fe(e,t);return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[B,V]),g(()=>{if(!z||!be.current)return;let e=setTimeout(()=>ye.current?.focus(),400);return()=>clearTimeout(e)},[z]),g(()=>{let e=hr(q.current);if(!B||!z||!H||!V||!e)return;let t=ce(e,I);return()=>t.destroy()},[B,z,H,V,I]),g(()=>{let e=q.current?.querySelector(`.wui-chat-thread`);if(B&&z&&H&&V&&ge&&e)return le(e)},[B,z,H,V,ge]),g(()=>{if(t!==`docked`||!z||typeof document>`u`)return;let e=document.documentElement,n=document.getElementById(P);e.dataset.wchatDocked=``;let r=null;if(n){let t=()=>e.style.setProperty(`--wchat-docked-width`,`${n.getBoundingClientRect().width}px`);t(),typeof ResizeObserver<`u`&&(r=new ResizeObserver(t),r.observe(n))}return()=>{r?.disconnect(),e.removeAttribute(`data-wchat-docked`),e.style.removeProperty(`--wchat-docked-width`)}},[t,z,P]);let je=j?.preload,Me=b(!1);if(g(()=>{if(z&&!Me.current){Me.current=!0;try{Promise.resolve(je?.()).catch(()=>void 0)}catch{}}},[z,je]),!B)return null;let Ne=j?()=>{let t={conversationId:e.conversationId,draft:ye.current?.value??``};de(()=>(Z(!1,`button`),j.onSwitch(t)),{target:j.target}).catch(e=>globalThis.reportError?.(e))}:void 0,Pe=[`wui-chat`,`wui-chat--${t}`,`wui-chat--${D}`,vt(ie),V&&H?`wui-chat--phone`:null,I.phone.mode===`Sheet`?`wui-chat--sheet`:null,p].filter(Boolean).join(` `),Fe={"--wui-chat-offset-x":`${O}px`,"--wui-chat-offset-y":`${k}px`,"--wui-chat-width":`${I.panel.widthPx}px`,"--wui-chat-panel-max-height":`${I.panel.maxHeightPx}px`,"--wui-chat-bottom-gap":`${I.panel.bottomGapPx}px`,"--wui-chat-sheet-height":`${I.phone.sheetHeightDvh}dvh`,"--wui-chat-sheet-max-height":`${I.phone.sheetMaxHeightPx}px`,...h},Ie=[`wui-chat-launcher-wrap`,Y===`entering`&&pe?`wui-chat-launcher--entrance-${pe}`:null,Y===`idle`&&se!==`none`&&(se!==`ring`||ae===`pill`)?`wui-chat-launcher--idle-${se}`:null].filter(Boolean).join(` `),Le=[`wui-chat-launcher`,`wui-chat-launcher--${ae}`,ae===`pill`&&I.launcher.compact?`wui-chat-launcher--compact`:null,`wui-chat-launcher--reveal-${oe}`,Oe].filter(Boolean).join(` `),Re=t===`launcher`&&!z&&ne.Nudges;return/* @__PURE__ */ K(`div`,{ref:q,className:Pe,style:Fe,"data-state":Te,"data-open":z?`true`:`false`,"data-theme":v===`auto`?void 0:v,children:[/* @__PURE__ */ K(`div`,{ref:_e,className:Ie,"data-launcher":Y,inert:Y===`hidden`,onAnimationEnd:e=>{e.target===e.currentTarget&&Y===`entering`&&J(`idle`)},children:[/* @__PURE__ */ G(sr,{chat:e,labels:F,enabled:Re,onActivate:()=>Z(!0,`manual`)}),/* @__PURE__ */ K(`button`,{ref:ve,type:`button`,className:Le,"aria-haspopup":`dialog`,"aria-expanded":z,"aria-controls":P,"aria-label":z?F.launcherClose:F.launcher,onClick:()=>Z(!z,`launcher`),onAnimationEnd:e=>{e.target===e.currentTarget&&ke(null)},children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-launcher-icon`,"aria-hidden":`true`,children:/* @__PURE__ */ G(a,{name:S,size:24,"aria-hidden":`true`})}),/* @__PURE__ */ G(`span`,{className:`wui-chat-launcher-close`,"aria-hidden":`true`,children:/* @__PURE__ */ G(a,{name:`x`,size:20,"aria-hidden":`true`})}),/* @__PURE__ */ G(`span`,{className:`wui-chat-launcher-label`,children:F.launcher})]}),/* @__PURE__ */ G(`span`,{className:`wui-chat-launcher-bubble`,"aria-hidden":`true`,children:U?.hoverLabel||F.launcher})]}),/* @__PURE__ */ G(Zn,{chat:e,labels:F,layout:t,panelId:P,inputRef:ye,onClose:()=>Z(!1,`button`),onSwitch:Ne,open:z,renderEmpty:M,renderers:r,layoutParts:i,loader:o,motion:ie,onOpenAttachment:c,onOpenTarget:l,onNavigate:u,resolveLink:d,linkComponent:f})]})}function vr({enabled:e,settings:t,look:n,session:r,isOpen:i,panelId:a}){let o=b(i);o.current=i,g(()=>{if(!e||!t)return;let i=me(t,n,{open:()=>r.open({trigger:`auto`}),isOpen:()=>o.current,panelRect:()=>document.getElementById(a)?.getBoundingClientRect()??null});return()=>i.cancel()},[e,t,n,r,a])}function yr(e){let{chat:t,look:n}=e,r=_(),i=y(()=>te(n),[n]);return vr({enabled:t.features.AutoOpen&&t.profile!==null,settings:t.profile?.experience.autoOpen??null,look:i,session:t.session,isOpen:t.open,panelId:r}),/* @__PURE__ */ G(_r,{...e,layout:`launcher`,panelId:r})}function br({onOpenFullScreen:e,preloadFullPage:t,...n}){let r=n.chat.features.PanelSwitch===!0&&typeof e==`function`?{onSwitch:e,target:`full-page`,preload:t}:null;return/* @__PURE__ */ G(_r,{...n,layout:`docked`,switchConfig:r})}var xr=e=>{if(typeof requestAnimationFrame==`function`){let t=requestAnimationFrame(()=>e());return()=>cancelAnimationFrame(t)}let t=setTimeout(e,16);return()=>clearTimeout(t)},Sr=()=>()=>void 0,Cr=Object.freeze({profile:null,profileError:null,features:Object.freeze(A()),conversationId:null,conversationState:`Open`,title:null,continuesConversationId:null,messages:[],thinking:!1,steps:[],streaming:!1,loading:!1,loadError:null,turnError:null,stopped:!1,messagesLeftToday:null,editing:null,attachments:[],lastConversation:null,open:!1,muted:!1,greeting:null,starters:[],pending:null,agent:null,agentTyping:null,live:`Off`,handoffPending:!1,handoffPause:!1,openTickets:[],draft:null}),wr=new Proxy({},{get:(e,t)=>{if(!(typeof t==`symbol`||t===`client`||t===`toJSON`||t.startsWith(`$$`))){if(t===`getState`)return()=>Cr;if(t===`subscribe`)return Sr;if(t!==`then`)return()=>Promise.resolve()}}});function Tr(e){let{client:t,screen:n,layout:r,narrow:i,conversationId:a,behaviour:o,attribution:s,prefs:c,pageContext:l,getCaptchaToken:u,onEvent:d,onError:f,onNavigate:p}=e,h=b(l);h.current=l;let _=b(u);_.current=u;let v=b(d);v.current=d;let C=b(f);C.current=f;let w=b(a);w.current=a;let E=b(o);E.current=o;let D=b(s);D.current=s;let O=b(c);O.current=c;let k=JSON.stringify(i??{}),A=b(null),j=b(null),[M,N]=x(null);g(()=>{j.current=null;let e=T(t,{screen:n,layout:r,narrow:JSON.parse(k),conversationId:w.current??null,pageContext:()=>h.current,behaviour:()=>{let e=A.current;return e?.getState().features.BehaviourStarters?E.current?E.current():(j.current||=ae(e.getState().profile?.start.behaviour?.servicePathPrefixes??[]),j.current()):null},attribution:()=>D.current?.()??null,prefs:O.current??ft,schedule:xr,getCaptchaToken:async e=>_.current?_.current(e):null,onEvent:(e,t)=>v.current?.(e,t),onError:e=>C.current?.(e)});return A.current=e,N({client:t,screen:n,layout:r,narrowKey:k,session:e}),()=>{A.current=null,e.dispose()}},[t,n,r,k]);let P=M!==null&&M.client===t&&M.screen===n&&M.layout===r&&M.narrowKey===k?M.session:wr,F=S(P.subscribe,P.getState),I=y(()=>({load:()=>P.load(),submit:e=>P.submit(e),chooseQuickReply:e=>P.chooseQuickReply(e),answerInput:(e,t)=>P.answerInput(e,t),confirmAction:e=>P.confirmAction(e),rejectAction:(e,t)=>P.rejectAction(e,t),stop:()=>P.stop(),retry:()=>P.retry(),regenerate:()=>P.regenerate(),notifyTyping:()=>P.notifyTyping(),requestHandoff:e=>P.requestHandoff(e),startEdit:e=>P.startEdit(e),cancelEdit:()=>P.cancelEdit(),attach:e=>P.attach(e),removeAttachment:e=>P.removeAttachment(e),openConversation:e=>P.openConversation(e),resumeLast:()=>P.resumeLast(),newConversation:()=>P.newConversation(),rate:(e,t,n)=>P.rate(e,t,n),reset:()=>P.reset()}),[P]),L=m((e,t)=>v.current?.(e,t),[]);return{...F,...I,session:P,client:t,emit:L,onNavigate:p}}export{Oe as ChatComposer,Pe as ChatConversationActions,nr as ChatEmbed,or as ChatExplain,Fe as ChatFooter,yr as ChatLauncher,Mt as ChatLoader,it as ChatOpenTickets,er as ChatPage,br as ChatPanel,nt as ChatPastChats,ut as ChatReadAloudButton,Yn as ChatThread,Un as defaultRenderers,Xe as formatResetTime,Tr as useChat,Ce as useChatDictation,Ye as useChatExplain,Qn as useChatHandoff,ct as useChatReadAloud,Ne as useTranscriptActions};
@@ -0,0 +1,4 @@
1
+ export default function ChatAgentTyping({ chat, labels }: {
2
+ chat: any;
3
+ labels: any;
4
+ }): import("react").JSX.Element | null;
@@ -0,0 +1,4 @@
1
+ export default function ChatAuthorBadge({ author, labels }: {
2
+ author: any;
3
+ labels: any;
4
+ }): import("react").JSX.Element | null;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The foot nodes of the chat: the allowance line, the edit banner, the attachment chips and the
3
+ * composer form, in that order, as CONTRACT-WEBDOM draws them.
4
+ */
5
+ export default function ChatComposer({ chat, labels, maxLength, inputRef }: {
6
+ chat: any;
7
+ inputRef: any;
8
+ labels: any;
9
+ maxLength: any;
10
+ }): import("react").JSX.Element;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Header buttons that share or print the whole conversation.
3
+ */
4
+ export default function ChatConversationActions({ chat, labels }: {
5
+ chat: any;
6
+ labels: any;
7
+ }): import("react").JSX.Element | null;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * The conversation embedded in a host page's own box. It is always open and takes the same
3
+ * surface props as the page.
4
+ */
5
+ export default function ChatEmbed(props: any): import("react").JSX.Element;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * A "Why?" control on one figure. It opens a card that loads the explanation on demand; the product
3
+ * draws the answer and its foot through renderAnswer and renderFoot.
4
+ */
5
+ export default function ChatExplain({ chat, request, renderAnswer, label, renderFoot, askDraft, labels: labelOverrides, placement, className, triggerContent, }: {
6
+ askDraft: any;
7
+ chat: any;
8
+ className: any;
9
+ label: any;
10
+ labels: any;
11
+ placement?: string | undefined;
12
+ renderAnswer: any;
13
+ renderFoot: any;
14
+ request: any;
15
+ triggerContent: any;
16
+ }): import("react").JSX.Element | null;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The disclaimer line under the composer: the disclaimer, the privacy link, the assurance text and
3
+ * the reCAPTCHA note with its Google links.
4
+ */
5
+ export default function ChatFooter({ chat, labels }: {
6
+ chat: any;
7
+ labels: any;
8
+ }): import("react").JSX.Element | null;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The panel of every layout: header, body and foot. The past chats view replaces the body and the
3
+ * foot until the person returns to the chat.
4
+ */
5
+ export default function ChatFrame({ chat, labels, layout, onClose, panelId, inputRef, ariaLabelOverride, renderers, layoutParts, loader, motion, onOpenAttachment, onOpenTarget, onOpenTicket, onNavigate, resolveLink, linkComponent, onSwitch, open, renderEmpty, }: {
6
+ ariaLabelOverride: any;
7
+ chat: any;
8
+ inputRef: any;
9
+ labels: any;
10
+ layout: any;
11
+ layoutParts: any;
12
+ linkComponent?: null | undefined;
13
+ loader: any;
14
+ motion: any;
15
+ onClose: any;
16
+ onNavigate: any;
17
+ onOpenAttachment: any;
18
+ onOpenTarget: any;
19
+ onOpenTicket: any;
20
+ onSwitch: any;
21
+ open?: boolean | undefined;
22
+ panelId: any;
23
+ renderEmpty: any;
24
+ renderers: any;
25
+ resolveLink?: null | undefined;
26
+ }): import("react").JSX.Element;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The past chats view. A row opens its conversation; rename and delete appear only when their
3
+ * features are on, and delete asks first.
4
+ */
5
+ export default function ChatHistory({ chat, labels, onOpen }: {
6
+ chat: any;
7
+ labels: any;
8
+ onOpen: any;
9
+ }): import("react").JSX.Element;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * The floating launcher that opens the chat panel. Auto-open is scheduled here, on the launcher the
3
+ * shell shares its panel id with.
4
+ */
5
+ export default function ChatLauncher(props: any): import("react").JSX.Element;
@@ -0,0 +1,4 @@
1
+ export default function ChatLiveStatus({ chat, labels }: {
2
+ chat: any;
3
+ labels: any;
4
+ }): import("react").JSX.Element | null;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The actions under one message: copy, read aloud, share, print, regenerate, edit and rating.
3
+ */
4
+ export default function ChatMessageActions({ chat, message, labels, isLast, isLastVisitor }: {
5
+ chat: any;
6
+ isLast: any;
7
+ isLastVisitor: any;
8
+ labels: any;
9
+ message: any;
10
+ }): import("react").JSX.Element | null;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The small prompt beside a closed launcher. It appears once after its delay and stays hidden for
3
+ * the rest of the component's life once dismissed.
4
+ */
5
+ export default function ChatNudge({ chat, labels, enabled, onActivate }: {
6
+ chat: any;
7
+ enabled: any;
8
+ labels: any;
9
+ onActivate: any;
10
+ }): import("react").JSX.Element | null;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The person's open tickets on the empty state: the ticket number, the subject and the status. A row opens
3
+ * its ticket only when the host passes onOpenTicket.
4
+ */
5
+ export default function ChatOpenTickets({ chat, labels, onOpenTicket }: {
6
+ chat: any;
7
+ labels: any;
8
+ onOpenTicket: any;
9
+ }): import("react").JSX.Element | null;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * The full-page conversation. It is always open and draws nothing when VisitorChat is off.
3
+ */
4
+ export default function ChatPage({ chat, labels: labelOverrides, renderers, layoutParts, loader, motion, onOpenAttachment, onOpenTarget, onNavigate, resolveLink, linkComponent, className, style, theme, look, onOpenSidePanel, onClose, renderEmpty, handoff, }: {
5
+ chat: any;
6
+ className: any;
7
+ handoff: any;
8
+ labels: any;
9
+ layoutParts: any;
10
+ linkComponent: any;
11
+ loader: any;
12
+ look: any;
13
+ motion?: string | undefined;
14
+ onClose: any;
15
+ onNavigate: any;
16
+ onOpenAttachment: any;
17
+ onOpenSidePanel: any;
18
+ onOpenTarget: any;
19
+ renderEmpty: any;
20
+ renderers: any;
21
+ resolveLink: any;
22
+ style: any;
23
+ theme: any;
24
+ }): import("react").JSX.Element;
25
+ /**
26
+ * The always-open surface shared by the full-page and embedded layouts.
27
+ */
28
+ export declare function ChatFullSurface({ layout, chat, labelOverrides, renderers, layoutParts, loader, motion, onOpenAttachment, onOpenTarget, onNavigate, resolveLink, linkComponent, className, style, theme, look, inputRef, onSwitch, onClose, renderEmpty, }: {
29
+ chat: any;
30
+ className: any;
31
+ inputRef: any;
32
+ labelOverrides: any;
33
+ layout: any;
34
+ layoutParts: any;
35
+ linkComponent?: null | undefined;
36
+ loader: any;
37
+ look: any;
38
+ motion: any;
39
+ onClose: any;
40
+ onNavigate: any;
41
+ onOpenAttachment: any;
42
+ onOpenTarget: any;
43
+ onSwitch: any;
44
+ renderEmpty: any;
45
+ renderers: any;
46
+ resolveLink?: null | undefined;
47
+ style: any;
48
+ theme: any;
49
+ }): import("react").JSX.Element | null;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The docked panel: the same conversation as the launcher, open beside the page's content. With the
3
+ * PanelSwitch feature on and an onOpenFullScreen callback, the panel hands the conversation to the full page.
4
+ */
5
+ export default function ChatPanel({ onOpenFullScreen, preloadFullPage, ...props }: {
6
+ [x: string]: any;
7
+ onOpenFullScreen: any;
8
+ preloadFullPage: any;
9
+ }): import("react").JSX.Element;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The past chats of the empty state. It re-reads the list each time the panel opens, so a chat that
3
+ * ended while the panel was closed appears.
4
+ */
5
+ export default function ChatPastChats({ chat, labels, open }: {
6
+ chat: any;
7
+ labels: any;
8
+ open: any;
9
+ }): import("react").JSX.Element | null;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The read-aloud action under one reply. It reads the Text parts only, so tables, sources and chips are not spoken.
3
+ */
4
+ export default function ChatReadAloudButton({ chat, labels, message }: {
5
+ chat: any;
6
+ labels: any;
7
+ message: any;
8
+ }): import("react").JSX.Element | null;