@helpai/elements 0.10.0 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/elements.cjs.js CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  `))!==-1;){let l=o.slice(0,s);o=o.slice(s+2);let c=wi(l);c&&(yield c)}}}finally{n.releaseLock()}}function wi(e){let t="",n;for(let o of e.split(`
10
10
  `))if(!(o===""||o.startsWith(":"))){if(o.startsWith("data:")){let i=o.slice(5).replace(/^ /,"");t=t?`${t}
11
- ${i}`:i;continue}o.startsWith("id:")&&(n=o.slice(3).trim())}if(!t||t==="[DONE]")return null;try{let o=JSON.parse(t);return Si.trace("chunk",{type:o.type,eventId:n}),{chunk:o,eventId:n}}catch(o){return Si.trace("frame parse failed",{err:o,payload:t.slice(0,200)}),null}}function mc(e){let t=new TextEncoder().encode(e),n="";for(let o of t)n+=String.fromCharCode(o);return btoa(n).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}var ki=e=>e&&Object.keys(e).length>0?e:void 0;function Ei(e,t){let n=ki(e),o=ki(t);if(!n&&!o)return;let i={};return n&&(i.user=n),o&&(i.page=o),mc(JSON.stringify(i))}var ke={startSession:"/ai/agent/start-session",streamMessage:"/ai/agent/stream-message",streamResume:"/ai/agent/stream-resume",cancelStream:"/ai/agent/cancel-stream",listSessions:"/ai/agent/list-sessions",listMessages:"/ai/agent/list-messages",updateSettings:"/ai/agent/update-settings",markRead:"/ai/agent/mark-read",content:"/ai/agent/content"},Ci="context";function Ai(e){let n={messages:e.messages.map(a=>({id:a.id,parts:vc(a),role:a.role})),sessionId:e.sessionId,trigger:e.trigger??"submit-message"};e.visitorId&&(n.visitorId=e.visitorId),e.userPrefs&&(n.userPrefs=e.userPrefs);let o={},i=e.tools?.map(hc).filter(a=>a!==null);return i?.length&&(o.tools=i),e.responseMode&&(o.responseMode=e.responseMode),Object.keys(o).length>0&&(n.data=o),n}function hc(e){return typeof e=="string"?e?{code:e}:null:e?.code?e:null}function vc(e){let t=[];for(let n of e.parts)n.kind==="text"&&n.text&&t.push({text:n.text,type:"text"}),n.kind==="file"&&n.url&&t.push({mediaType:n.mediaType,type:"file",url:n.url});for(let n of e.attachments??[])n.url&&t.push({type:"file",url:n.url,mediaType:n.mediaType,filename:n.name,fileId:n.id,fileSize:n.size});return t}var q=M.scope("transport"),bc=3,Ri=400,Ti=3,xc=new Set([408,425,429,500,502,503,504]);function Ii(e){return Ri*2**e+Math.floor(Math.random()*250)}function Pc(e){let t=e.get("retry-after");if(!t)return null;let n=Number(t),o=Number.isFinite(n)?n*1e3:Date.parse(t)-Date.now();return Number.isFinite(o)&&o>=0?Math.min(o,3e4):null}function Mo(e,t){return new Promise(n=>{if(t?.aborted)return n();let o=setTimeout(a,e),i=()=>a();t?.addEventListener("abort",i,{once:!0});function a(){clearTimeout(o),t?.removeEventListener("abort",i),n()}})}var fn=class{constructor(t){W(this,"opts",t);W(this,"visitorId");W(this,"sessionId");W(this,"userContext");W(this,"pageContext")}setContext(t,n){this.userContext=t,this.pageContext=n}primeIdentity(t,n){t&&(this.visitorId=t),n&&(this.sessionId=n)}envelope(){let t={};this.visitorId&&(t.visitorId=this.visitorId),this.sessionId&&(t.sessionId=this.sessionId);let n=Ei(this.userContext,this.pageContext);return n&&(t[Ci]=n),t}withEnvelope(t){return{...this.envelope(),...t}}appendEnvelope(t){for(let[n,o]of Object.entries(this.envelope()))t.append(n,o);return t}withEnvelopeQuery(t){let n=new URL(this.url(t));for(let[o,i]of Object.entries(this.envelope()))n.searchParams.has(o)||n.searchParams.set(o,i);return n.toString()}async startSession(t){q.debug("startSession \u2192",{visitorId:t.visitorId,sessionId:t.sessionId,locale:t.locale});let n=await this.postJson(ke.startSession,t,"startSession");return q.debug("startSession \u2190",{visitorId:n.visitorId,sessionId:n.sessionId,canContinue:n.canContinue,hasMessages:!!n.messages?.length,hasWelcome:!!n.welcome,hasConfig:!!n.config,rebind:n.rebind}),Sc(n)||q.warn("startSession response did not match expected shape; using raw response",{response:n}),this.visitorId=n.visitorId??t.visitorId,this.sessionId=n.sessionId,n}async uploadFile(t){q.debug("uploadFile \u2192",{name:t.name,size:t.size,type:t.type});let n=new FormData;n.append("file",t,t.name);let o=await this.postForm(this.uploadPath,n,"upload");return q.debug("uploadFile \u2190",{id:o.id,url:o.url}),o}async transcribe(t,n="audio/webm"){q.debug("transcribe \u2192",{size:t.size,mimeType:n});let o=new FormData;o.append("audio",t,`voice.${yc(n)}`),o.append("mimeType",n);let i=await this.postForm(this.transcribePath,o,"transcribe");return q.debug("transcribe \u2190",{textLen:i.text.length}),i}async listSessions(t={}){let n=new URL(this.url(ke.listSessions));t.visitorId&&n.searchParams.set("visitorId",t.visitorId),t.limit&&n.searchParams.set("limit",String(t.limit)),t.cursor&&n.searchParams.set("cursor",t.cursor),q.debug("listSessions \u2192",{visitorId:t.visitorId??this.visitorId,limit:t.limit,cursor:t.cursor});let o=await this.getJson(n.toString(),"listSessions"),i=o.sessions??[];return q.debug("listSessions \u2190",{count:i.length,nextCursor:o.nextCursor}),{sessions:i.map(a=>({sessionId:a.sessionId,title:a.title,lastMessageAt:a.lastMessageAt,preview:a.preview,canContinue:a.canContinue,unreadCount:a.unreadCount})),nextCursor:o.nextCursor}}async loadSession(t){let n=new URL(this.url(ke.listMessages));n.searchParams.set("sessionId",t),q.debug("loadSession \u2192",{sessionId:t,visitorId:this.visitorId});let o=await this.getJson(n.toString(),"loadSession"),i=o.messages??[];return q.debug("loadSession \u2190",{sessionId:o.sessionId,canContinue:o.canContinue,messageCount:i.length,hasSuggestions:!!o.suggestions}),{sessionId:o.sessionId,canContinue:o.canContinue??!0,messages:i,agent:o.agent,suggestions:o.suggestions}}async markRead(t){if(!(!this.visitorId||!t)){q.debug("markRead \u2192",{sessionId:t,visitorId:this.visitorId});try{await this.postJson(ke.markRead,{sessionId:t},"markRead")}catch(n){q.debug("markRead failed (non-fatal)",{err:n})}}}async listContent(t={}){let n=new URL(this.url(ke.content));for(let[a,s]of Object.entries(t))s!==void 0&&n.searchParams.set(a,Array.isArray(s)?s.join(","):String(s));q.debug("listContent \u2192",t);let o=await this.getJson(n.toString(),"listContent"),i=o.items??[];return q.debug("listContent \u2190",{count:i.length,total:o.pagination?.total}),{...o,items:i}}async saveUserPrefs(t){q.debug("saveUserPrefs \u2192",{visitorId:this.visitorId,sessionId:this.sessionId,settingsKeys:Object.keys(t)});let n=await this.postJson(ke.updateSettings,{userPrefs:t},"saveUserPrefs");return q.debug("saveUserPrefs \u2190",{ok:n.ok}),n}get uploadPath(){return this.opts.endpoints?.upload??"/ai/agent/upload-file"}get transcribePath(){return this.opts.endpoints?.transcribe??"/ai/agent/transcribe-audio"}sendMessage(t){q.debug("message \u2192",{sessionId:t.sessionId,visitorId:t.visitorId,messageCount:t.messages.length,trigger:t.trigger,responseMode:t.data?.responseMode,tools:t.data?.tools?.map(s=>s.code)});let n=new AbortController,o=new Set;return{iter:this.runStream(t,n,o),cancel:()=>this.cancelStream(n,t.sessionId)}}resumeStream(){let t=new AbortController,n=new Set;return{iter:this.resumeStreamGen(t,n,!0),cancel:()=>t.abort()}}async*runStream(t,n,o){(yield*this.drain(this.openMessageStream(t,n.signal),o,n))||(yield*this.resumeStreamGen(n,o,!1))}async*resumeStreamGen(t,n,o){for(let i=1;i<=bc&&!t.signal.aborted;i++){if((!o||i>1)&&(await Mo(Ri*i,t.signal),t.signal.aborted))return;let a;try{a=await this.fetchImpl(this.resumeUrl(n.size),{method:"GET",credentials:"omit",headers:{accept:"text/event-stream",...this.opts.auth.headers()},signal:t.signal})}catch(l){if(t.signal.aborted)return;q.debug("resume fetch failed \u2014 retrying",{attempt:i,err:l});continue}if(a.status===204||!a.ok){q.debug("resume \u2192 no in-flight stream",{status:a.status});return}let s=n.size;if(yield*this.drain(Ro(a,t.signal),n,t))return;if(n.size===s){q.debug("resume \u2192 stream closed with no new events; nothing to resume");return}}if(!t.signal.aborted)throw new ve("stream incomplete after resume attempts","server")}async*drain(t,n,o){try{for await(let i of t){if(o.signal.aborted)return!0;if(i.eventId){if(n.has(i.eventId))continue;n.add(i.eventId)}if(yield i,i.chunk.type==="finish"||i.chunk.type==="error")return!0}}catch(i){if(o.signal.aborted)return!0;if(i instanceof ve&&i.status!==void 0)throw i;q.debug("stream segment dropped",{err:i})}return!1}cancelStream(t,n){t.signal.aborted||(q.debug("cancel stream",{sessionId:n,visitorId:this.visitorId}),t.abort(),!(!this.visitorId||!n)&&this.fetchImpl(this.url(ke.cancelStream),{method:"POST",credentials:"omit",headers:{"content-type":"application/json",...this.opts.auth.headers()},body:JSON.stringify(this.withEnvelope({})),keepalive:!0}).catch(o=>q.debug("cancel POST failed (non-fatal)",{err:o})))}async*openMessageStream(t,n){let o=await this.fetchImpl(this.url(ke.streamMessage),{method:"POST",credentials:"omit",headers:{accept:"text/event-stream","content-type":"application/json",...this.opts.auth.headers()},body:JSON.stringify(this.withEnvelope(t)),signal:n});yield*Ro(o,n)}resumeUrl(t){let n=new URL(this.withEnvelopeQuery(ke.streamResume));return n.searchParams.set("resumeAt",String(t)),n.toString()}async postJson(t,n,o){let i=await this.fetchWithRetry(()=>[this.url(t),{method:"POST",credentials:"omit",headers:{"content-type":"application/json",...this.opts.auth.headers()},body:JSON.stringify(this.withEnvelope(n))}],o);return this.assertOk(i,o)}async postForm(t,n,o){let i=await this.fetchImpl(this.url(t),{method:"POST",credentials:"omit",headers:this.opts.auth.headers(),body:this.appendEnvelope(n)});return this.assertOk(i,o)}async getJson(t,n){let o=await this.fetchWithRetry(()=>[this.withEnvelopeQuery(t),{method:"GET",credentials:"omit",headers:{accept:"application/json",...this.opts.auth.headers()}}],n);return this.assertOk(o,n)}async fetchWithRetry(t,n){for(let o=0;;o++){let[i,a]=t(),s;try{s=await this.fetchImpl(i,a)}catch(c){if(o>=Ti)throw new ve(`${n} failed: network error`,"network",void 0,c);q.debug("request network error \u2014 retrying",{label:n,attempt:o}),await Mo(Ii(o));continue}if(s.ok||!xc.has(s.status)||o>=Ti)return s;let l=Pc(s.headers)??Ii(o);q.debug("request retryable status \u2014 retrying",{label:n,status:s.status,attempt:o,wait:l}),await Mo(l)}}async assertOk(t,n){if(!t.ok)throw new ve(`${n} failed: ${t.status}`,"server",t.status);return await t.json()}url(t){return/^https?:\/\//i.test(t)?t:`${this.opts.baseUrl}${t}`}get fetchImpl(){return this.opts.fetchImpl??globalThis.fetch.bind(globalThis)}};function yc(e){return e.includes("webm")?"webm":e.includes("ogg")?"ogg":e.includes("mp4")||e.includes("m4a")?"m4a":e.includes("mpeg")?"mp3":e.includes("wav")?"wav":"bin"}function Sc(e){if(!e||typeof e!="object")return!1;let t=e;return typeof t.visitorId=="string"&&typeof t.sessionId=="string"&&typeof t.canContinue=="boolean"}function Mi(e,t){let n=e?[{kind:"text",id:"t0",textSig:L(e),doneSig:L(!0)}]:[];return{id:we(),role:"user",createdAt:Date.now(),status:"complete",attachments:t,partsSig:L(n)}}function Lo(){return{id:we(),role:"assistant",createdAt:Date.now(),status:"streaming",partsSig:L([])}}function Li(e){return{id:e.id,role:e.role,createdAt:Date.now(),status:"streaming",partsSig:L([{kind:"text",id:`${e.id}-t0`,textSig:L(""),doneSig:L(!1)}])}}function Ni(e){return wc({id:e.id,role:e.role,createdAt:Date.now(),status:"complete",parts:[{kind:"text",id:`${e.id}-t0`,text:e.text,done:!0}]})}function wc(e){return{id:e.id,role:e.role,createdAt:e.createdAt,status:e.status,errorText:e.errorText,finishReason:e.finishReason,attachments:e.attachments,partsSig:L(e.parts.map(kc))}}function No(e){let t=e.parts.map((n,o)=>n.type==="text"?{kind:"text",id:`${e.id}-t${o}`,textSig:L(n.text),doneSig:L(!0)}:n.type==="file"?{kind:"file",url:n.url,mediaType:n.mediaType}:null).filter(n=>n!==null);return{id:e.id,role:e.role,createdAt:Date.now(),status:"complete",partsSig:L(t)}}function Oi(e){return{id:e.id,role:e.role,createdAt:e.createdAt,status:e.status,errorText:e.errorText,finishReason:e.finishReason,attachments:e.attachments,parts:e.partsSig.value.map(Ec)}}function Oo(e){let t="";for(let n of e.partsSig.value)n.kind==="text"&&(t+=n.textSig.value);return t}function kc(e){return e.kind==="text"||e.kind==="reasoning"?{kind:e.kind,id:e.id,textSig:L(e.text),doneSig:L(e.done)}:e.kind==="tool"?{kind:"tool",toolCallId:e.toolCallId,toolName:e.toolName,inputPartialSig:L(e.inputPartial),inputSig:L(e.input),outputSig:L(e.output),errorSig:L(e.error),stateSig:L(e.state)}:e}function Ec(e){return e.kind==="text"||e.kind==="reasoning"?{kind:e.kind,id:e.id,text:e.textSig.value,done:e.doneSig.value}:e.kind==="tool"?{kind:"tool",toolCallId:e.toolCallId,toolName:e.toolName,inputPartial:e.inputPartialSig.value,input:e.inputSig.value,output:e.outputSig.value,error:e.errorSig.value,state:e.stateSig.value}:e}var Di=M.scope("reducer"),gn=class{constructor(t){W(this,"messagesSig",t);W(this,"active",null)}attach(t){this.active=t}detach(){this.active=null}apply(t){let n=this.active;if(n)switch(t.type){case"start":case"start-step":case"finish-step":return;case"finish":Di.debug("finish",{reason:t.finishReason,canContinue:t.canContinue}),n.status="complete",t.finishReason&&(n.finishReason=t.finishReason),this.bumpDone(n);return;case"error":Di.warn("stream error chunk",{errorText:t.errorText}),n.status="error",n.errorText=t.errorText,this.bumpDone(n);return;case"text-start":it(n,"text",t.id);return;case"text-delta":{let o=it(n,"text",t.id);o.textSig.value+=t.delta;return}case"text-end":it(n,"text",t.id).doneSig.value=!0;return;case"reasoning-start":it(n,"reasoning",t.id).doneSig.value=!1;return;case"reasoning-delta":{let o=it(n,"reasoning",t.id);o.textSig.value+=t.delta;return}case"reasoning-end":it(n,"reasoning",t.id).doneSig.value=!0;return;case"tool-input-start":case"tool-input-delta":case"tool-input-available":case"tool-output-available":case"tool-output-error":Cc(n,t);return;case"file":mn(n,{kind:"file",url:t.url,mediaType:t.mediaType});return;case"source-url":{if(n.partsSig.value.some(i=>i.kind==="source"&&i.sourceId===t.sourceId))return;mn(n,{kind:"source",sourceId:t.sourceId,url:t.url,title:t.title});return}case"data-notification":return;default:{let o=t}}}bumpDone(t){t.partsSig.value=[...t.partsSig.value],this.messagesSig.value=[...this.messagesSig.value]}};function it(e,t,n){let o=e.partsSig.value.find(a=>a.kind===t&&a.id===n);if(o)return o;let i={kind:t,id:n,textSig:L(""),doneSig:L(!1)};return mn(e,i),i}function Pt(e,t,n){let o=e.partsSig.value.find(a=>a.kind==="tool"&&a.toolCallId===t);if(o)return o;let i={kind:"tool",toolCallId:t,toolName:n??"tool",inputPartialSig:L(""),inputSig:L(void 0),outputSig:L(void 0),errorSig:L(void 0),stateSig:L("input")};return mn(e,i),i}function mn(e,t){e.partsSig.value=[...e.partsSig.value,t]}function Cc(e,t){switch(t.type){case"tool-input-start":Pt(e,t.toolCallId,t.toolName);return;case"tool-input-delta":{let n=Pt(e,t.toolCallId);n.inputPartialSig.value+=t.delta;return}case"tool-input-available":{let n=Pt(e,t.toolCallId,t.toolName);n.inputSig.value=t.input,n.stateSig.value="awaiting";return}case"tool-output-available":{let n=Pt(e,t.toolCallId);n.outputSig.value=t.output,n.stateSig.value="output";return}case"tool-output-error":{let n=Pt(e,t.toolCallId);n.errorSig.value=t.errorText,n.stateSig.value="error";return}default:return}}var hn=M.scope("persistence");function yt(e,t=an){let n=`${v.cssPrefix}.${e}`,o=`${n}.visitorId`,i=`${n}.sessionId`,a=`${n}.userPrefs`,s=`${n}.panelOpen`,l=`${n}.panelSize`,c=`${n}.calloutDismissed`,u=`${n}.sidebarCollapsed`,p=`${n}.activeModule`,d={getVisitorId(){let _=t.get(o);if(_)return _;let f=we();return t.set(o,f),f},setVisitorId(_){hn.debug("setVisitorId (rebind)",{id:_,widgetId:e}),t.set(o,_)},loadSessionId(){return t.get(i)??void 0},saveSessionId(_){hn.trace("saveSessionId",{id:_,widgetId:e}),_?t.set(i,_):t.remove(i)},loadUserPrefs(){let _=t.get(a);if(!_)return{};try{let f=JSON.parse(_);return Ac(f)?f:{}}catch(f){return hn.warn("loadUserPrefs parse failed",{error:f}),{}}},saveUserPrefs(_){try{t.set(a,JSON.stringify(_))}catch(f){hn.warn("saveUserPrefs serialise failed",{error:f})}},patchUserPrefs(_){let f=d.loadUserPrefs();d.saveUserPrefs({...f,..._})},loadPanelOpen(){let _=t.get(s);return _==="1"?!0:_==="0"?!1:null},savePanelOpen(_){t.set(s,_?"1":"0")},loadPanelSize(){let _=t.get(l);return _==="normal"||_==="expanded"||_==="fullscreen"?_:null},savePanelSize(_){t.set(l,_)},loadCalloutDismissed(_){if(!_)return!1;let f=t.get(c);return!!f&&f===_},saveCalloutDismissed(_){_?t.set(c,_):t.remove(c)},loadSidebarCollapsed(){let _=t.get(u);return _==="1"?!0:_==="0"?!1:null},saveSidebarCollapsed(_){t.set(u,_?"1":"0")},loadActiveModule(){return t.get(p)||null},saveActiveModule(_){t.set(p,_)},clearSession(){t.remove(i)}};return d}function Ac(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}var Hi=M.scope("feedback:audio"),vn=class{constructor(){W(this,"ctx",null);W(this,"master",null);W(this,"buffers",new Map)}unlock(){if(this.ctx){this.ctx.state==="suspended"&&this.ctx.resume();return}let t=globalThis.AudioContext??globalThis.webkitAudioContext;if(t)try{this.ctx=new t,this.master=this.ctx.createGain(),this.master.gain.value=1,this.master.connect(this.ctx.destination)}catch(n){Hi.warn("AudioContext init failed",{err:n})}}setVolume(t){if(!this.master||!this.ctx)return;let n=Math.max(0,Math.min(1,t));this.master.gain.setTargetAtTime(n,this.ctx.currentTime,.01)}playTone(t){let n=this.ctx,o=this.master;if(!n||!o||n.state!=="running")return;let i=n.currentTime,a=t.noteMs/1e3;t.notes.forEach((s,l)=>{let c=n.createOscillator();c.type=t.type,c.frequency.value=s;let u=n.createGain(),p=i+l*a;u.gain.setValueAtTime(1e-4,p),u.gain.exponentialRampToValueAtTime(t.peakGain,p+.005),u.gain.exponentialRampToValueAtTime(1e-4,p+a),c.connect(u).connect(o),c.start(p),c.stop(p+a+.01)})}async playUrl(t){let n=this.ctx,o=this.master;if(!n||!o||n.state!=="running")return;let i=await this.getBuffer(t);if(!i)return;let a=n.createBufferSource();a.buffer=i,a.connect(o),a.start()}destroy(){this.ctx&&this.ctx.close().catch(()=>{}),this.ctx=null,this.master=null,this.buffers.clear()}async getBuffer(t){if(!this.ctx)return null;let n=this.buffers.get(t);if(n)return n instanceof Promise,n;let o=this.ctx,i=fetch(t).then(a=>a.ok?a.arrayBuffer():Promise.reject(new Error(`fetch ${a.status}`))).then(a=>o.decodeAudioData(a)).then(a=>(this.buffers.set(t,a),a)).catch(a=>(Hi.warn("audio fetch/decode failed",{url:t,err:a}),this.buffers.delete(t),null));return this.buffers.set(t,i),i}};var Bi={messageReceived:10,messageSent:0,error:[20,40,20],voiceStart:10,voiceStop:0},$i={messageReceived:{notes:[880,1318.51],noteMs:90,type:"sine",peakGain:.45},messageSent:{notes:[1568],noteMs:60,type:"sine",peakGain:.25},error:{notes:[523.25,392],noteMs:120,type:"triangle",peakGain:.55},voiceStart:{notes:[1318.51],noteMs:50,type:"sine",peakGain:.3},voiceStop:{notes:[880],noteMs:50,type:"sine",peakGain:.3}};var Be=null,bn=0;function Tc(){return typeof navigator<"u"&&typeof navigator.vibrate=="function"}function Ic(){if(typeof document>"u")return null;let e=document.createElement("input");e.type="checkbox",e.setAttribute("switch",""),e.setAttribute("aria-hidden","true"),e.tabIndex=-1,e.id=`__${v.cssPrefix}_haptic_${Math.random().toString(36).slice(2)}`;let t=document.createElement("label");t.htmlFor=e.id,t.setAttribute("aria-hidden","true");let n="position:absolute!important;width:1px!important;height:1px!important;overflow:hidden!important;clip:rect(0,0,0,0)!important;opacity:0!important;pointer-events:none!important;";return e.style.cssText=n,t.style.cssText=n,document.body.append(e,t),{input:e,label:t}}function Ui(e){if(!(e===0||Array.isArray(e)&&e.every(t=>t===0))){if(Tc())try{navigator.vibrate(e);return}catch{}if(Be||(Be=Ic()),!!Be)try{Be.label.click()}catch{}}}function zi(){bn++;let e=!1;return()=>{e||(e=!0,bn=Math.max(0,bn-1),bn===0&&Be&&(Be.input.remove(),Be.label.remove(),Be=null))}}var Rc=M.scope("feedback"),Mc=100,xn=class{constructor(t,n){W(this,"mutedSig",L(!1));W(this,"audio",new vn);W(this,"releaseHaptics");W(this,"sound");W(this,"haptics");W(this,"lastPlayed",new Map);W(this,"reducedMotionMq",null);this.sound=t,this.haptics=n,this.releaseHaptics=zi(),this.audio.setVolume(this.effectiveVolume()),typeof matchMedia<"u"&&(this.reducedMotionMq=matchMedia("(prefers-reduced-motion: reduce)"))}unlock(){this.audio.unlock(),this.audio.setVolume(this.effectiveVolume())}update(t,n){this.sound=t,this.haptics=n,this.audio.setVolume(this.effectiveVolume())}setMuted(t){this.mutedSig.value!==t&&(this.mutedSig.value=t)}toggleMuted(){this.mutedSig.value=!this.mutedSig.value}play(t){this.mutedSig.value||this.isDeduped(t)||(this.lastPlayed.set(t,performance.now()),this.sound.enabled&&this.playSound(t),this.haptics.enabled&&this.isTouchDevice()&&this.playHaptic(t))}destroy(){this.audio.destroy(),this.releaseHaptics()}isDeduped(t){let n=this.lastPlayed.get(t);return n===void 0?!1:performance.now()-n<Mc}playSound(t){let n=this.sound.events?.[t];if(n===!1)return;if(typeof n=="string"){this.audio.playUrl(n).catch(i=>Rc.warn("audio play failed",{err:i,url:n}));return}let o=$i[t];o&&this.audio.playTone(o)}playHaptic(t){if(this.reducedMotionMq?.matches)return;let n=this.haptics.events?.[t];if(n===!1)return;let o=n===!0||n===void 0?Bi[t]:n;Ui(o)}effectiveVolume(){let t=this.sound.volume??.3;return this.reducedMotionMq?.matches?t*.5:t}isTouchDevice(){return typeof window>"u"?!1:matchMedia("(hover: none) and (pointer: coarse)").matches}};function Ge(e,t){return e instanceof ve&&e.status===429?t.errorRateLimited:t.errorGeneric}var Lc=0;function r(e,t,n,o,i,a){t||(t={});var s,l,c=t;if("ref"in c)for(l in c={},t)l=="ref"?s=t[l]:c[l]=t[l];var u={type:e,props:c,key:n,ref:s,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--Lc,__i:-1,__u:0,__source:i,__self:a};if(typeof e=="function"&&(s=e.defaultProps))for(l in s)c[l]===void 0&&(c[l]=s[l]);return H.vnode&&H.vnode(u),u}var T={fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,viewBox:"0 0 24 24"},Nc=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"M21 12a8 8 0 0 1-12 6.93L3 21l1.65-5.16A8 8 0 1 1 21 12Z"})}),Ee=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"M18 6 6 18M6 6l12 12"})}),Fi=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"M12 5v14M5 12h14"})}),Wi=()=>r("svg",{...T,"aria-hidden":"true",children:[r("path",{d:"m22 2-7 20-4-9-9-4Z"}),r("path",{d:"M22 2 11 13"})]}),Gi=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"M12 19V5M5 12l7-7 7 7"})}),Ki=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"M3 20V4l18 8-18 8Z"})}),Pn=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"m9 18 6-6-6-6"})}),Vi=()=>r("svg",{...T,"aria-hidden":"true",children:r("rect",{x:"6",y:"6",width:"12",height:"12",rx:"2"})}),qi=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"m21 11-9 9a5.5 5.5 0 0 1-7.78-7.78l8.49-8.49a3.67 3.67 0 0 1 5.19 5.19l-8.49 8.49a1.83 1.83 0 0 1-2.6-2.6l7.78-7.78"})}),Xi=()=>r("svg",{...T,"aria-hidden":"true",children:[r("rect",{x:"9",y:"2",width:"6",height:"12",rx:"3"}),r("path",{d:"M5 10a7 7 0 0 0 14 0M12 19v3"})]}),ji=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"M3 8V3h5M21 8V3h-5M3 16v5h5M21 16v5h-5"})}),Yi=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"M8 3v5H3M16 3v5h5M8 21v-5H3M16 21v-5h5"})}),Ji=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"M3 3h7v2H5v5H3zM21 3h-7v2h5v5h2zM3 21h7v-2H5v-5H3zM21 21h-7v-2h5v-5h2z"})}),Qi=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"M10 3v5H3M14 3v5h7M10 21v-5H3M14 21v-5h7"})}),Zi=()=>r("svg",{...T,"aria-hidden":"true",viewBox:"0 0 10 10",children:r("path",{d:"M9 1L1 9M9 5L5 9M9 9H9",strokeWidth:"1.5"})}),ea=()=>r("svg",{...T,"aria-hidden":"true",children:[r("circle",{cx:"12",cy:"5",r:"1.5",fill:"currentColor",stroke:"none"}),r("circle",{cx:"12",cy:"12",r:"1.5",fill:"currentColor",stroke:"none"}),r("circle",{cx:"12",cy:"19",r:"1.5",fill:"currentColor",stroke:"none"})]}),ta=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"M11 5 6 9H2v6h4l5 4zM15 9a5 5 0 0 1 0 6M18 7a9 9 0 0 1 0 10"})}),na=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"M11 5 6 9H2v6h4l5 4zM22 9l-6 6M16 9l6 6"})}),oa=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"M20 6 9 17l-5-5"})}),ra=()=>r("svg",{...T,"aria-hidden":"true",children:[r("path",{d:"M3 3v6h6"}),r("path",{d:"M3.05 13A9 9 0 1 0 6 5.3L3 9"}),r("path",{d:"M12 7v5l3 2"})]});var St=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"M19 12H5M12 19l-7-7 7-7"})}),ia=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"M15 3h6v6M10 14 21 3M21 14v5a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5"})}),aa=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"M3 6h18M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"})}),sa=()=>r("svg",{...T,"aria-hidden":"true",children:[r("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8Z"}),r("path",{d:"M14 2v6h6"})]}),Oc=()=>r("svg",{...T,"aria-hidden":"true",children:[r("path",{d:"m12 3-1.5 4.5L6 9l4.5 1.5L12 15l1.5-4.5L18 9l-4.5-1.5Z"}),r("path",{d:"M19 15v4M17 17h4M5 3v2M4 4h2"})]}),Dc=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2Z"})}),Do=()=>r("svg",{...T,"aria-hidden":"true",children:[r("circle",{cx:"12",cy:"12",r:"10"}),r("path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"}),r("path",{d:"M12 17h.01"})]}),Hc=()=>r("svg",{...T,"aria-hidden":"true",children:[r("path",{d:"m15 4 3 3-9 9-3-3z"}),r("path",{d:"M18 2v2M20 4h2M3 20l3-3M3 16h2M5 14v2"})]}),Bc=()=>r("svg",{...T,"aria-hidden":"true",children:[r("rect",{x:"4",y:"8",width:"16",height:"12",rx:"2"}),r("path",{d:"M12 8V4"}),r("circle",{cx:"12",cy:"3",r:"1"}),r("path",{d:"M2 14h2M20 14h2M9 13h.01M15 13h.01M9.5 17h5"})]}),$c=()=>r("svg",{...T,"aria-hidden":"true",children:[r("path",{d:"M4 14v-2a8 8 0 0 1 16 0v2"}),r("rect",{x:"2",y:"14",width:"4",height:"6",rx:"1.5"}),r("rect",{x:"18",y:"14",width:"4",height:"6",rx:"1.5"}),r("path",{d:"M20 20v1a3 3 0 0 1-3 3h-5"})]}),Uc=()=>r("svg",{...T,"aria-hidden":"true",children:[r("circle",{cx:"12",cy:"12",r:"10"}),r("circle",{cx:"12",cy:"12",r:"4"}),r("path",{d:"m4.93 4.93 4.24 4.24M14.83 14.83l4.24 4.24M14.83 9.17l4.24-4.24M4.93 19.07l4.24-4.24"})]}),Ho=()=>r("svg",{...T,"aria-hidden":"true",children:[r("circle",{cx:"11",cy:"11",r:"7"}),r("path",{d:"m21 21-4.3-4.3"})]}),la=()=>r("svg",{...T,"aria-hidden":"true",children:[r("circle",{cx:"12",cy:"12",r:"9"}),r("path",{d:"m8.5 12 2.5 2.5 4.5-5"})]}),ca=()=>r("svg",{...T,"aria-hidden":"true",children:[r("path",{d:"M3 9.5 12 3l9 6.5"}),r("path",{d:"M5 9v11a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V9"})]}),da=()=>r("svg",{...T,"aria-hidden":"true",children:[r("path",{d:"m3 11 15-5v12L3 13z"}),r("path",{d:"M3 11v2a2 2 0 0 0 2 2h1V9H5a2 2 0 0 0-2 2z"}),r("path",{d:"M7 15v3a2 2 0 0 0 4 0v-2"}),r("path",{d:"M21 10a3 3 0 0 1 0 4"})]}),wt=()=>r("svg",{...T,"aria-hidden":"true",children:[r("path",{d:"M14 9a2 2 0 0 1-2 2H6l-4 4V4a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2z"}),r("path",{d:"M18 9h2a2 2 0 0 1 2 2v11l-4-4h-6a2 2 0 0 1-2-2v-1"})]}),_a=()=>r("svg",{...T,"aria-hidden":"true",children:[r("circle",{cx:"12",cy:"12",r:"4"}),r("path",{d:"M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M4.93 19.07l1.41-1.41M17.66 6.34l1.41-1.41"})]}),ua=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"})}),pa=()=>r("svg",{...T,"aria-hidden":"true",children:[r("circle",{cx:"12",cy:"12",r:"9"}),r("path",{d:"M12 3v18"}),r("path",{d:"M12 3a9 9 0 0 1 0 18z",fill:"currentColor",stroke:"none"})]}),zc=()=>r("svg",{...T,"aria-hidden":"true",children:[r("circle",{cx:"10.5",cy:"10.5",r:"6.5"}),r("path",{d:"M8 11a2.5 2.5 0 0 0 5 0"}),r("path",{d:"m20 20-4.4-4.4"})]}),Fc=()=>r("svg",{...T,"aria-hidden":"true",children:[r("path",{d:"M12 3.5 13.6 9 19 10.5 13.6 12 12 17.5 10.4 12 5 10.5 10.4 9z"}),r("path",{d:"M18.5 4v3M20 5.5h-3M5.5 16v2.5M6.75 17.25h-2.5"})]}),Wc=()=>r("svg",{...T,"aria-hidden":"true",children:[r("path",{d:"M4 18h16"}),r("path",{d:"M5 18a7 7 0 0 1 14 0"}),r("path",{d:"M12 8V6"}),r("path",{d:"M10 6h4"})]}),Gc=()=>r("svg",{...T,"aria-hidden":"true",children:[r("path",{d:"M7 11V6.5a1.5 1.5 0 0 1 3 0V10"}),r("path",{d:"M10 10V5.5a1.5 1.5 0 0 1 3 0V10"}),r("path",{d:"M13 10V6.5a1.5 1.5 0 0 1 3 0V12"}),r("path",{d:"M16 9.5a1.5 1.5 0 0 1 3 0v2.5a7 7 0 0 1-7 7 7 7 0 0 1-6.4-4.2L4 12.5a1.5 1.5 0 0 1 2.6-1.5L7 11"})]}),fa={chat:Nc,message:Dc,bubbles:wt,spark:Oc,wand:Hc,bot:Bc,help:Do,lifebuoy:Uc,headset:$c,search:zc,sparkles:Fc,concierge:Wc,wave:Gc};var C=v.cssPrefix,y={launcher:`${C}-launcher`,callout:`${C}-callout`,calloutDismiss:`${C}-callout-dismiss`,panel:`${C}-panel`,panelHeader:`${C}-panel-header`,resizeGrip:`${C}-resize-grip`,actionClear:`${C}-action-clear`,actionExpand:`${C}-action-expand`,actionFullscreen:`${C}-action-fullscreen`,actionPopOut:`${C}-action-popout`,actionSound:`${C}-action-sound`,actionHistory:`${C}-action-history`,actionLanguage:`${C}-action-language`,actionTheme:`${C}-action-theme`,actionClose:`${C}-action-close`,actionOverflow:`${C}-action-overflow`,languageOption:`${C}-language-option`,themeOption:`${C}-theme-option`,composer:`${C}-composer`,composerInput:`${C}-composer-input`,composerSend:`${C}-composer-send`,composerStop:`${C}-composer-stop`,composerAttach:`${C}-composer-attach`,composerFileInput:`${C}-composer-file-input`,composerVoice:`${C}-composer-voice`,attachmentChip:`${C}-attachment-chip`,attachmentRemove:`${C}-attachment-remove`,suggestion:`${C}-suggestion`,messageBubble:`${C}-message`,messageRetry:`${C}-message-retry`,historyPane:`${C}-history-pane`,historyBack:`${C}-history-back`,historyItem:`${C}-history-item`,sidebar:`${C}-sidebar`,sidebarToggle:`${C}-sidebar-toggle`,sidebarNewChat:`${C}-sidebar-new-chat`,sidebarItem:`${C}-sidebar-item`,messengerHome:`${C}-messenger-home`,modulesEmpty:`${C}-modules-empty`,tab:`${C}-tab`,tabBadge:`${C}-tab-badge`,homeView:`${C}-home-view`,homeGreeting:`${C}-home-greeting`,homeBrand:`${C}-home-brand`,backHeader:`${C}-back-header`,contentView:`${C}-content-view`,contentScroll:`${C}-content-scroll`,homeSearch:`${C}-home-search`,helpSearch:`${C}-help-search`,homeRecent:`${C}-home-recent`,homeContentRow:`${C}-home-content-row`,helpArticle:`${C}-help-article`,newsItem:`${C}-news-item`};function ce(e,t){return`${e}-${t}`}var xp={clear:y.actionClear,expand:y.actionExpand,fullscreen:y.actionFullscreen,popOut:y.actionPopOut,sound:y.actionSound,history:y.actionHistory,language:y.actionLanguage,theme:y.actionTheme,close:y.actionClose};var yn=v.cssPrefix;function ga({onToggle:e,launcher:t,strings:n,leaving:o,edgeTab:i}){let a=t.variant!=="circle"&&!!t.label;return r("button",{type:"button",class:`${yn}-fab`,"data-variant":t.variant,"data-size":t.size,"data-edge-tab":i?"true":void 0,"data-leaving":o?"true":void 0,"data-testid":y.launcher,onClick:e,"aria-label":n.launcherOpen,children:[Kc(t.icon),a?r("span",{class:`${yn}-fab-label`,children:t.label}):null]})}function Kc(e){let t=fa[e];return t?r(t,{}):r(Vc,{source:e})}function Vc({source:e}){return r("span",{ref:t=>{t&&qc(t,e)},"aria-hidden":"true"})}function qc(e,t){if(e.dataset.svgMounted!==t)try{let o=new DOMParser().parseFromString(t,"image/svg+xml").documentElement;o&&o.tagName.toLowerCase()==="svg"&&(e.replaceChildren(document.importNode(o,!0)),e.dataset.svgMounted=t)}catch{}}function ma({callout:e,launcherPosition:t,closeLabel:n,onDismiss:o}){let[i,a]=k(!1);return w(()=>{let s=setTimeout(()=>a(!0),e.delayMs);return()=>clearTimeout(s)},[e.delayMs]),w(()=>{if(!i||e.autoDismissMs<=0)return;let s=setTimeout(o,e.autoDismissMs);return()=>clearTimeout(s)},[i,e.autoDismissMs,o]),i?r("div",{class:`${yn}-callout`,role:"status","data-shape":e.shape,"data-position":Xc(e.position,t),"data-animated":e.animated?"true":void 0,"data-testid":y.callout,children:[r("span",{children:e.text}),r("button",{type:"button",class:`${yn}-callout-close`,onClick:o,"aria-label":n,title:n,"data-testid":y.calloutDismiss,children:r(Ee,{})})]}):null}function Xc(e,t){let n=t.endsWith("-right"),o=t.startsWith("bottom-");return e==="vertical"?o?"top":"bottom":n?"left":"right"}function Sn({panelEl:e,resize:t,position:n,initialSize:o,onSizeChange:i,strings:a}){let s=v.cssPrefix,l=N(null);if(w(()=>{if(!e)return;let m=e.style;t.minWidth&&m.setProperty(`--${s}-resize-min-w`,t.minWidth),t.maxWidth&&m.setProperty(`--${s}-resize-max-w`,t.maxWidth),t.minHeight&&m.setProperty(`--${s}-resize-min-h`,t.minHeight),t.maxHeight&&m.setProperty(`--${s}-resize-max-h`,t.maxHeight),o&&(m.setProperty(`--${s}-widget-w`,`${o.width}px`),m.setProperty(`--${s}-widget-h`,`${o.height}px`))},[e,t.minWidth,t.maxWidth,t.minHeight,t.maxHeight,s,o]),!e)return null;let c=n.startsWith("top-"),u=n.endsWith("-right"),p=`${s}-resize-grip ${s}-resize-grip--${c?"bottom":"top"}-${u?"left":"right"}`,d=m=>{if(!e)return;let h=m.currentTarget,P=e.getBoundingClientRect();l.current={pointerId:m.pointerId,startX:m.clientX,startY:m.clientY,startW:P.width,startH:P.height,dirX:u?-1:1,dirY:c?1:-1},h.setPointerCapture(m.pointerId),m.preventDefault()},_=m=>{let h=l.current;if(!h||m.pointerId!==h.pointerId||!e)return;let P=(m.clientX-h.startX)*h.dirX,b=(m.clientY-h.startY)*h.dirY;e.style.setProperty(`--${s}-widget-w`,`${h.startW+P}px`),e.style.setProperty(`--${s}-widget-h`,`${h.startH+b}px`)},f=m=>{let h=l.current;if(!h||m.pointerId!==h.pointerId||!e)return;m.currentTarget.releasePointerCapture(m.pointerId);let P=e.getBoundingClientRect();i({width:Math.round(P.width),height:Math.round(P.height)}),l.current=null};return r("div",{class:p,role:"separator","aria-orientation":"vertical","aria-label":a.resizeHandle,title:a.resizeHandle,onPointerDown:d,onPointerMove:_,onPointerUp:f,onPointerCancel:f,"data-testid":y.resizeGrip,children:r(Zi,{})})}var Ke=v.cssPrefix,jc=`.${Ke}-header, .${Ke}-back-header, .${Ke}-home-hero`,Yc='button, a, input, textarea, select, [role="tab"], [contenteditable]',ha=56;function wn(e,t){w(()=>{if(!t||!e)return;let n=c=>Number.parseFloat(c)||0,o=(c,u)=>Math.min(u,Math.max(-u,c)),i=null,a=c=>{let u=c.target;if(!(u instanceof Element)||!u.closest(jc)||u.closest(Yc))return;let p=e.getBoundingClientRect();i={id:c.pointerId,x:c.clientX,y:c.clientY,dx:n(e.style.getPropertyValue(`--${Ke}-modal-dx`)),dy:n(e.style.getPropertyValue(`--${Ke}-modal-dy`)),maxX:(window.innerWidth+p.width)/2-ha,maxY:(window.innerHeight+p.height)/2-ha},e.dataset.dragging="true",c.preventDefault()},s=c=>{if(!i||c.pointerId!==i.id)return;let u=o(i.dx+c.clientX-i.x,i.maxX),p=o(i.dy+c.clientY-i.y,i.maxY);e.style.setProperty(`--${Ke}-modal-dx`,`${u}px`),e.style.setProperty(`--${Ke}-modal-dy`,`${p}px`)},l=c=>{!i||c.pointerId!==i.id||(i=null,delete e.dataset.dragging)};return e.addEventListener("pointerdown",a),window.addEventListener("pointermove",s),window.addEventListener("pointerup",l),window.addEventListener("pointercancel",l),()=>{e.removeEventListener("pointerdown",a),window.removeEventListener("pointermove",s),window.removeEventListener("pointerup",l),window.removeEventListener("pointercancel",l)}},[e,t])}function kt(e,t,n,o){switch(e){case"clear":case"sound":case"history":case"language":case"theme":return!0;case"expand":return t==="floating";case"fullscreen":return t!=="standalone";case"popOut":return t!=="standalone"&&!!o?.popOutUrl;case"close":return t==="standalone"||t==="page"?!1:t==="inline"?n==="fullscreen":!0}}function kn(e,t,n){return kt("close",e,t)?n.main.includes("close")||n.overflow.includes("close"):!1}function va(e,t){return e==="inline"&&t==="fullscreen"?"exit-fullscreen":"close"}var Jc='a[href],button:not([disabled]),textarea:not([disabled]),input:not([disabled]):not([type="hidden"]),select:not([disabled]),[tabindex]:not([tabindex="-1"])';function En(e){let t=n=>{if(n.key!=="Tab")return;let o=[...e.querySelectorAll(Jc)].filter(l=>l.offsetParent!==null||l===document.activeElement);if(o.length===0){n.preventDefault();return}let i=o[0],a=o[o.length-1];if(!i||!a)return;let s=e.getRootNode().activeElement;n.shiftKey&&s===i?(n.preventDefault(),a.focus()):!n.shiftKey&&s===a&&(n.preventDefault(),i.focus())};return e.addEventListener("keydown",t),()=>e.removeEventListener("keydown",t)}function Cn(e){return e.trim().split(/\s+/).slice(0,2).map(t=>t.charAt(0).toUpperCase()).join("")}var Bo=v.cssPrefix;function ba({agent:e}){let t=e.status??"online";return r("div",{class:`${Bo}-agent`,children:[r("div",{class:`${Bo}-agent-avatar`,"data-status":t,children:e.avatar?r("img",{src:e.avatar,alt:""}):r("span",{children:Cn(e.name)})}),r("div",{class:`${Bo}-agent-meta`,children:[r("strong",{children:e.name}),e.title?r("span",{children:e.title}):null]})]})}var xa=M.scope("attachments");function An(e,t,n){let o=Zc(e),i=[],a=[],s=nd(n.accept),l=t.reduce((u,p)=>u+p.size,0),c=t.length;for(let u of o){let p=Qc(u,c,l,n,s);if(p){a.push({file:u,reason:p});continue}i.push(td(u)),l+=u.size,c+=1}return(i.length||a.length)&&xa.debug("ingest",{accepted:i.length,rejected:a.map(u=>({name:u.file.name,reason:u.reason}))}),{accepted:i,rejected:a}}function $o(e){try{URL.revokeObjectURL(e.previewUrl)}catch(t){xa.debug("revokeObjectURL failed",{error:t})}}function Qc(e,t,n,o,i){return t>=o.maxCount?"count":n+e.size>o.maxBytes?"bytes":od(e,i)?null:"mime"}function Zc(e){return e?Array.isArray(e)?e.filter(t=>t instanceof File):[...e].map(t=>t instanceof File?t:ed(t)).filter(t=>t!==null):[]}function ed(e){let t=e;return!t?.getAsFile||t.kind!=="file"?null:t.getAsFile()}function td(e){return{file:e,id:we(),mediaType:e.type||"application/octet-stream",name:e.name||"pasted-file",previewUrl:URL.createObjectURL(e),size:e.size}}function nd(e){return e.split(",").map(t=>t.trim().toLowerCase()).filter(Boolean).map(t=>{if(t.startsWith("."))return{kind:"ext",ext:t};let[n="*",o="*"]=t.split("/");return{kind:"mime",type:n,subtype:o}})}function od(e,t){if(t.length===0)return!0;let[n="*",o="*"]=(e.type||"").toLowerCase().split("/"),i=(e.name||"").toLowerCase();return t.some(a=>a.kind==="ext"?i.endsWith(a.ext):(a.type==="*"||a.type===n)&&(a.subtype==="*"||a.subtype===o))}var Et=v.cssPrefix;function Pa({attachment:e,onRemove:t}){let n=e.mediaType.startsWith("image/");return r("span",{class:`${Et}-attachment-chip`,title:e.name,"data-testid":ce(y.attachmentChip,e.id),children:[n?r("img",{class:`${Et}-attachment-thumb`,src:e.previewUrl,alt:""}):r("span",{class:`${Et}-attachment-thumb`,"aria-hidden":"true",children:r(sa,{})}),r("span",{class:`${Et}-attachment-name`,children:e.name}),r("button",{type:"button",class:`${Et}-attachment-remove`,onClick:t,"aria-label":`Remove ${e.name}`,"data-testid":ce(y.attachmentRemove,e.id),children:r(Ee,{})})]})}var Uo={isSupported:!1,start:()=>{},stop:()=>{}};function zo(e,t,n){return e==="disabled"?Uo:e==="server"?sd(n):rd(t)}function rd(e){let t=id();if(!t)return Uo;let n=null;return{isSupported:!0,start(o,i){n=new t,n.continuous=!0,n.interimResults=!0,n.lang=e,n.addEventListener("result",s=>{let l=s,c="",u=!1;for(let p=l.resultIndex;p<l.results.length;p++){let d=l.results[p];d&&(c+=d[0].transcript,d.isFinal&&(u=!0))}o(c,u)});let a=()=>{n=null,i()};n.addEventListener("end",a),n.addEventListener("error",a),n.start()},stop(){n?.stop()}}}function id(){let e=globalThis;return e.SpeechRecognition??e.webkitSpeechRecognition}var ad=["audio/webm;codecs=opus","audio/webm","audio/ogg;codecs=opus","audio/mp4"];function sd(e){if(typeof MediaRecorder>"u"||!navigator?.mediaDevices?.getUserMedia)return Uo;let t=null,n=null,o=[],i=()=>{for(let a of n?.getTracks()??[])a.stop();n=null};return{isSupported:!0,async start(a,s){try{n=await navigator.mediaDevices.getUserMedia({audio:!0});let l=ld();t=new MediaRecorder(n,l?{mimeType:l}:void 0),o=[],t.addEventListener("dataavailable",c=>{c.data.size>0&&o.push(c.data)}),t.addEventListener("stop",async()=>{let c=t?.mimeType??"audio/webm";i();let u=new Blob(o,{type:c});o=[];try{let{text:p}=await e(u,c);p&&a(p,!0)}catch{}finally{s()}}),t.start()}catch{i(),s()}},stop(){t?.stop()}}}function ld(){for(let e of ad)if(MediaRecorder.isTypeSupported(e))return e}var he=v.cssPrefix,Ve=M.scope("composer");function at(e){return e.reduce((t,n)=>t+n.size,0)}var cd={arrowUp:Gi,paperPlane:Wi,send:Ki,chevron:Pn};function ya({options:e,transport:t,feedback:n,bus:o,isStreaming:i,onSend:a,onStop:s,attachApiRef:l}){let c=e.strings,[u,p]=k(""),[d,_]=k([]),[f,m]=k(!1),h=N(null),P=N(null),b=e.features.files,S=e.features.voice,[I,j]=k(()=>zo(S,e.locale,(E,z)=>t.transcribe(E,z)));w(()=>{f||S==="disabled"||j(zo(S,e.locale,(E,z)=>t.transcribe(E,z)))},[e.locale,S,t,f]),w(()=>{let E=h.current;if(!E)return;let z=E.getRootNode(),Y="activeElement"in z?z.activeElement:null;Y&&E.closest(`.${he}-panel`)?.contains(Y)||E.focus({preventScroll:!0})},[]),w(()=>{let E=h.current;if(E){if(u.length===0){E.style.height="";return}E.style.height="auto",E.style.height=`${Math.min(E.scrollHeight,160)}px`}},[u]);let U=N(d);U.current=d,w(()=>()=>U.current.forEach($o),[]),w(()=>{if(l)return l.current={attachFromDrop:E=>{let z=An(E,U.current,e.attachments);z.accepted.length!==0&&(Ve.info("attach (drop)",{count:z.accepted.length,totalBytes:at(z.accepted)}),o.emit("attach",{count:z.accepted.length,totalBytes:at(z.accepted)}),_(Y=>[...Y,...z.accepted]))}},()=>{l.current&&(l.current=null)}},[l,e.attachments]),w(()=>{let E=h.current;if(!E)return;let z=E.closest(`.${he}-panel`);if(!z)return;let Y=fe=>{let Ue=fe.clipboardData;if(!Ue)return;if(b){let ue=An(Ue.items,U.current,e.attachments);if(ue.accepted.length>0){fe.preventDefault(),Ve.info("attach (paste)",{count:ue.accepted.length,totalBytes:at(ue.accepted)}),o.emit("attach",{count:ue.accepted.length,totalBytes:at(ue.accepted)}),_(It=>[...It,...ue.accepted]);return}}if(fe.target===E)return;let _e=Ue.getData("text/plain");_e&&(fe.preventDefault(),p(ue=>ue+_e),E.focus())};return z.addEventListener("paste",Y),()=>z.removeEventListener("paste",Y)},[b,e.attachments,he]);let oe=()=>{let E=u.trim();!E&&d.length===0||i||(a(E,d),p(""),_([]))},O=E=>{E.key!=="Enter"||E.shiftKey||E.isComposing||(E.preventDefault(),i?s():oe())},le=E=>{let z=E.target,Y=An(z.files,d,e.attachments);Y.accepted.length>0&&(Ve.info("attach (file picker)",{count:Y.accepted.length,totalBytes:at(Y.accepted)}),o.emit("attach",{count:Y.accepted.length,totalBytes:at(Y.accepted)}),_(fe=>[...fe,...Y.accepted])),z.value=""},B=E=>{Ve.info("removeAttachment",{id:E}),o.emit("removeAttachment",{id:E}),_(z=>{let Y=z.find(fe=>fe.id===E);return Y&&$o(Y),z.filter(fe=>fe.id!==E)})},R=N(null),Ye=()=>{if(I.isSupported){if(f){let E=R.current?Date.now()-R.current:0;Ve.info("voiceStop",{durationMs:E}),o.emit("voiceStop",{durationMs:E}),I.stop(),m(!1),n.play("voiceStop"),R.current=null;return}R.current=Date.now(),Ve.info("voiceStart"),o.emit("voiceStart",void 0),m(!0),n.play("voiceStart"),I.start((E,z)=>p(Y=>z?`${Y}${E} `:Y),()=>{if(m(!1),R.current){let E=Date.now()-R.current;Ve.debug("voiceStop (auto)",{durationMs:E}),o.emit("voiceStop",{durationMs:E}),R.current=null}})}},de=cd[e.composer.sendButton.icon];return r("div",{class:`${he}-composer`,"data-testid":y.composer,children:[d.length>0?r("div",{class:`${he}-attachments`,children:d.map(E=>r(Pa,{attachment:E,onRemove:()=>B(E.id)},E.id))}):null,r("div",{class:`${he}-composer-row`,children:[r("div",{class:`${he}-composer-actions`,children:[b?r("button",{type:"button",class:`${he}-icon-btn`,onClick:()=>P.current?.click(),"aria-label":c.attach,"data-testid":y.composerAttach,children:r(qi,{})}):null,I.isSupported?r("button",{type:"button",class:`${he}-icon-btn`,onClick:Ye,"aria-label":f?c.micStop:c.micStart,"aria-pressed":f,"data-recording":f?"true":void 0,"data-testid":y.composerVoice,children:r(Xi,{})}):null]}),r("textarea",{ref:h,class:`${he}-textarea`,rows:1,value:u,placeholder:c.composerPlaceholder,onInput:E=>p(E.target.value),onKeyDown:O,"aria-label":c.composerPlaceholder,"data-testid":y.composerInput}),i?r("button",{type:"button",class:`${he}-send`,onClick:s,"aria-label":c.stop,"data-testid":y.composerStop,children:r(Vi,{})}):r("button",{type:"button",class:`${he}-send`,"data-shape":e.composer.sendButton.shape,"data-variant":e.composer.sendButton.variant,onClick:oe,disabled:!u.trim()&&d.length===0,"aria-label":c.send,"data-testid":y.composerSend,children:r(de,{})})]}),r("input",{ref:P,type:"file",multiple:!0,accept:e.attachments.accept,onChange:le,class:`${he}-sr-only`,"data-testid":y.composerFileInput})]})}var dd=v.cssPrefix;function Sa({visible:e,strings:t}){return e?r("div",{class:`${dd}-dropzone`,role:"status","aria-live":"polite",children:t.dropZone}):null}function Tn({containerRef:e,onDrop:t}){let[n,o]=k(!1);return w(()=>{let i=e.current;if(!i)return;let a=0,s=p=>{a+=1,p.dataTransfer?.types.includes("Files")&&(p.preventDefault(),o(!0))},l=()=>{a-=1,!(a>0)&&(a=0,o(!1))},c=p=>{p.dataTransfer?.types.includes("Files")&&p.preventDefault()},u=p=>{a=0,o(!1),p.dataTransfer&&(p.preventDefault(),t(p.dataTransfer.items))};return i.addEventListener("dragenter",s),i.addEventListener("dragleave",l),i.addEventListener("dragover",c),i.addEventListener("drop",u),()=>{i.removeEventListener("dragenter",s),i.removeEventListener("dragleave",l),i.removeEventListener("dragover",c),i.removeEventListener("drop",u)}},[e,t]),{visible:n}}function wa({itemCount:e,initialFocusIndex:t}){let[n,o]=k(!1),i=N(null),a=N(null),[s,l]=k(-1),c=D(()=>{o(!1),l(-1),i.current?.focus()},[]),u=D(()=>o(_=>!_),[]);w(()=>{if(!n)return;let _=f=>{let m=a.current,h=i.current;if(!m||!h)return;let P=f.composedPath();P.includes(m)||P.includes(h)||(o(!1),l(-1))};return document.addEventListener("click",_,!0),()=>document.removeEventListener("click",_,!0)},[n]),w(()=>{if(!n||e===0)return;let _=t?.()??0,f=_<0||_>=e?0:_;l(f)},[n,e,t]),w(()=>{if(!n||s<0)return;a.current?.querySelectorAll("[role='menuitem']")?.[s]?.focus()},[n,s]);let p=D(_=>{(_.key==="ArrowDown"||_.key==="Enter"||_.key===" ")&&(_.preventDefault(),o(!0))},[]),d=D(_=>{if(e!==0)switch(_.key){case"Escape":_.preventDefault(),c();return;case"ArrowDown":_.preventDefault(),l(f=>(f+1)%e);return;case"ArrowUp":_.preventDefault(),l(f=>(f-1+e)%e);return;case"Home":_.preventDefault(),l(0);return;case"End":_.preventDefault(),l(e-1)}},[e,c]);return{open:n,focusIndex:s,triggerRef:i,menuRef:a,toggle:u,close:c,onTriggerKey:p,onMenuKey:d}}function ka({items:e,triggerLabel:t}){let n=v.cssPrefix,o=wa({itemCount:e.length}),i=a=>{a.disabled||(a.onSelect(),a.keepOpen||o.close())};return r("div",{class:`${n}-menu-wrap`,children:[r("button",{ref:o.triggerRef,type:"button",class:`${n}-icon-btn`,"aria-label":t,"aria-haspopup":"menu","aria-expanded":o.open,title:t,onClick:o.toggle,onKeyDown:o.onTriggerKey,children:r(ea,{})}),o.open?r("div",{ref:o.menuRef,class:`${n}-menu`,role:"menu","aria-label":t,onKeyDown:o.onMenuKey,tabIndex:-1,children:e.map(a=>r("button",{type:"button",role:"menuitem",class:`${n}-menu-item`,"aria-pressed":a.type==="switch"?a.on:void 0,disabled:a.disabled,lang:a.lang,onClick:()=>i(a),children:[a.icon?r("span",{class:`${n}-menu-icon`,children:a.icon}):null,r("span",{class:`${n}-menu-label`,children:a.label}),a.type==="switch"&&a.on?r("span",{class:`${n}-menu-check`,"aria-hidden":"true",children:r(oa,{})}):null]},a.id))}):null]})}var Fo=v.cssPrefix,_d={auto:"dark",dark:"light",light:"auto"};function ud(e){return e==="light"?r(_a,{}):e==="dark"?r(ua,{}):r(pa,{})}function Ce({panelProps:e,variant:t}){let{options:n,panelSize:o,feedback:i,onClose:a,onClear:s,onExpand:l,onFullscreen:c,onPopOut:u,onSoundToggle:p}=e,{onToggleHistory:d,onLocaleChange:_,onThemeChange:f}=e,m=n.strings,h=n.mode,P=t==="chat",b=Se(()=>i.mutedSig.value).value,S=new Set([...n.actions.main,...n.actions.overflow]),I=R=>S.has(R),j=R=>kt(R,h,o,{popOutUrl:n.popOutUrl}),U=n.themeMode,oe={auto:m.themeAuto,light:m.themeLight,dark:m.themeDark},O=[];if(I("theme")&&O.push({id:"theme",icon:ud(U),label:`${m.theme}: ${oe[U]}`,onSelect:()=>f(_d[U]),keepOpen:!0}),I("language")&&n.availableLocales.length>1)for(let R of n.availableLocales)O.push({id:`language:${R}`,label:`${m.language} \u2014 ${R}`,lang:R,type:"switch",on:R===n.locale,onSelect:()=>_(R)});if(I("expand")&&j("expand")){let R=o==="expanded";O.push({id:"expand",icon:R?r(Yi,{}):r(ji,{}),label:R?m.collapse:m.expand,type:"switch",on:R,onSelect:l})}if(I("fullscreen")&&j("fullscreen")){let R=o==="fullscreen";O.push({id:"fullscreen",icon:R?r(Qi,{}):r(Ji,{}),label:R?m.exitFullscreen:m.fullscreen,type:"switch",on:R,onSelect:c})}I("popOut")&&j("popOut")&&O.push({id:"popOut",icon:r(ia,{}),label:m.popOut,onSelect:u}),P&&I("sound")&&O.push({id:"sound",icon:b?r(na,{}):r(ta,{}),label:b?m.soundOff:m.soundOn,type:"switch",on:!b,onSelect:p}),P&&I("clear")&&O.push({id:"clear",icon:r(aa,{}),label:m.newConversation,onSelect:s});let le=!!a&&kn(h,o,n.actions),B=P&&I("history");return r("div",{class:`${Fo}-header-actions`,children:[B?r("button",{type:"button",class:`${Fo}-icon-btn`,onClick:d,"aria-label":m.history,title:m.history,"data-testid":y.actionHistory,children:r(ra,{})}):null,le?r("button",{type:"button",class:`${Fo}-icon-btn`,onClick:a,"aria-label":m.close,title:m.close,"data-testid":y.actionClose,children:r(Ee,{})}):null,O.length>0?r(ka,{items:O,triggerLabel:m.moreActions}):null]})}var Ko=1,Ca=2,Aa=4,Ta=8,Ia=16;function pd(e){switch(e){case Ko:return"href";case Ca:return"src";case Aa:return"class";case Ta:return"checked";case Ia:return"start"}}var fd=e=>{switch(e){case 1:return 3;case 2:return 4;case 3:return 5;case 4:return 6;case 5:return 7;default:return 8}},gd=fd;var Ea=24;function qo(e){let t=new Uint32Array(Ea);return t[0]=1,{renderer:e,text:"",pending:"",tokens:t,len:0,token:1,fence_end:0,blockquote_idx:0,hr_char:"",hr_chars:0,fence_start:0,spaces:new Uint8Array(Ea),indent:"",indent_len:0,table_state:0}}function Ra(e){e.pending.length>0&&se(e,`
11
+ ${i}`:i;continue}o.startsWith("id:")&&(n=o.slice(3).trim())}if(!t||t==="[DONE]")return null;try{let o=JSON.parse(t);return Si.trace("chunk",{type:o.type,eventId:n}),{chunk:o,eventId:n}}catch(o){return Si.trace("frame parse failed",{err:o,payload:t.slice(0,200)}),null}}function mc(e){let t=new TextEncoder().encode(e),n="";for(let o of t)n+=String.fromCharCode(o);return btoa(n).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}var ki=e=>e&&Object.keys(e).length>0?e:void 0;function Ei(e,t){let n=ki(e),o=ki(t);if(!n&&!o)return;let i={};return n&&(i.user=n),o&&(i.page=o),mc(JSON.stringify(i))}var ke={startSession:"/ai/agent/start-session",streamMessage:"/ai/agent/stream-message",streamResume:"/ai/agent/stream-resume",cancelStream:"/ai/agent/cancel-stream",listSessions:"/ai/agent/list-sessions",listMessages:"/ai/agent/list-messages",updateSettings:"/ai/agent/update-settings",markRead:"/ai/agent/mark-read",content:"/ai/agent/content"},Ci="context";function Ai(e){let n={messages:e.messages.map(a=>({id:a.id,parts:vc(a),role:a.role})),sessionId:e.sessionId,trigger:e.trigger??"submit-message"};e.visitorId&&(n.visitorId=e.visitorId),e.userPrefs&&(n.userPrefs=e.userPrefs);let o={},i=e.tools?.map(hc).filter(a=>a!==null);return i?.length&&(o.tools=i),e.responseMode&&(o.responseMode=e.responseMode),Object.keys(o).length>0&&(n.data=o),n}function hc(e){return typeof e=="string"?e?{code:e}:null:e?.code?e:null}function vc(e){let t=[];for(let n of e.parts)n.kind==="text"&&n.text&&t.push({text:n.text,type:"text"}),n.kind==="file"&&n.url&&t.push({mediaType:n.mediaType,type:"file",url:n.url});for(let n of e.attachments??[])n.url&&t.push({type:"file",url:n.url,mediaType:n.mediaType,filename:n.name,fileId:n.id,fileSize:n.size});return t}var q=M.scope("transport"),bc=3,Ri=400,Ti=3,xc=new Set([408,425,429,500,502,503,504]);function Ii(e){return Ri*2**e+Math.floor(Math.random()*250)}function Pc(e){let t=e.get("retry-after");if(!t)return null;let n=Number(t),o=Number.isFinite(n)?n*1e3:Date.parse(t)-Date.now();return Number.isFinite(o)&&o>=0?Math.min(o,3e4):null}function Mo(e,t){return new Promise(n=>{if(t?.aborted)return n();let o=setTimeout(a,e),i=()=>a();t?.addEventListener("abort",i,{once:!0});function a(){clearTimeout(o),t?.removeEventListener("abort",i),n()}})}var fn=class{constructor(t){W(this,"opts",t);W(this,"visitorId");W(this,"sessionId");W(this,"userContext");W(this,"pageContext")}setContext(t,n){this.userContext=t,this.pageContext=n}primeIdentity(t,n){t&&(this.visitorId=t),n&&(this.sessionId=n)}envelope(){let t={};this.visitorId&&(t.visitorId=this.visitorId),this.sessionId&&(t.sessionId=this.sessionId);let n=Ei(this.userContext,this.pageContext);return n&&(t[Ci]=n),t}withEnvelope(t){return{...this.envelope(),...t}}appendEnvelope(t){for(let[n,o]of Object.entries(this.envelope()))t.append(n,o);return t}withEnvelopeQuery(t){let n=new URL(this.url(t));for(let[o,i]of Object.entries(this.envelope()))n.searchParams.has(o)||n.searchParams.set(o,i);return n.toString()}async startSession(t){q.debug("startSession \u2192",{visitorId:t.visitorId,sessionId:t.sessionId,locale:t.locale});let n=await this.postJson(ke.startSession,t,"startSession");return q.debug("startSession \u2190",{visitorId:n.visitorId,sessionId:n.sessionId,canContinue:n.canContinue,hasMessages:!!n.messages?.length,hasWelcome:!!n.welcome,hasConfig:!!n.config,rebind:n.rebind}),Sc(n)||q.warn("startSession response did not match expected shape; using raw response",{response:n}),this.visitorId=n.visitorId??t.visitorId,this.sessionId=n.sessionId,n}async uploadFile(t){q.debug("uploadFile \u2192",{name:t.name,size:t.size,type:t.type});let n=new FormData;n.append("file",t,t.name);let o=await this.postForm(this.uploadPath,n,"upload");return q.debug("uploadFile \u2190",{id:o.id,url:o.url}),o}async transcribe(t,n="audio/webm"){q.debug("transcribe \u2192",{size:t.size,mimeType:n});let o=new FormData;o.append("audio",t,`voice.${yc(n)}`),o.append("mimeType",n);let i=await this.postForm(this.transcribePath,o,"transcribe");return q.debug("transcribe \u2190",{textLen:i.text.length}),i}async listSessions(t={}){let n=new URL(this.url(ke.listSessions));t.visitorId&&n.searchParams.set("visitorId",t.visitorId),t.limit&&n.searchParams.set("limit",String(t.limit)),t.cursor&&n.searchParams.set("cursor",t.cursor),q.debug("listSessions \u2192",{visitorId:t.visitorId??this.visitorId,limit:t.limit,cursor:t.cursor});let o=await this.getJson(n.toString(),"listSessions"),i=o.sessions??[];return q.debug("listSessions \u2190",{count:i.length,nextCursor:o.nextCursor}),{sessions:i.map(a=>({sessionId:a.sessionId,title:a.title,lastMessageAt:a.lastMessageAt,preview:a.preview,canContinue:a.canContinue,unreadCount:a.unreadCount})),nextCursor:o.nextCursor}}async loadSession(t){let n=new URL(this.url(ke.listMessages));n.searchParams.set("sessionId",t),q.debug("loadSession \u2192",{sessionId:t,visitorId:this.visitorId});let o=await this.getJson(n.toString(),"loadSession"),i=o.messages??[];return q.debug("loadSession \u2190",{sessionId:o.sessionId,canContinue:o.canContinue,messageCount:i.length,hasSuggestions:!!o.suggestions}),{sessionId:o.sessionId,canContinue:o.canContinue??!0,messages:i,agent:o.agent,suggestions:o.suggestions}}async markRead(t){if(!(!this.visitorId||!t)){q.debug("markRead \u2192",{sessionId:t,visitorId:this.visitorId});try{await this.postJson(ke.markRead,{sessionId:t},"markRead")}catch(n){q.debug("markRead failed (non-fatal)",{err:n})}}}async listContent(t={}){let n=new URL(this.url(ke.content));for(let[a,s]of Object.entries(t))s!==void 0&&n.searchParams.set(a,Array.isArray(s)?s.join(","):String(s));q.debug("listContent \u2192",t);let o=await this.getJson(n.toString(),"listContent"),i=o.items??[];return q.debug("listContent \u2190",{count:i.length,total:o.pagination?.total}),{...o,items:i}}async saveUserPrefs(t){q.debug("saveUserPrefs \u2192",{visitorId:this.visitorId,sessionId:this.sessionId,settingsKeys:Object.keys(t)});let n=await this.postJson(ke.updateSettings,{userPrefs:t},"saveUserPrefs");return q.debug("saveUserPrefs \u2190",{ok:n.ok}),n}get uploadPath(){return this.opts.endpoints?.upload??"/ai/agent/upload-file"}get transcribePath(){return this.opts.endpoints?.transcribe??"/ai/agent/transcribe-audio"}sendMessage(t){q.debug("message \u2192",{sessionId:t.sessionId,visitorId:t.visitorId,messageCount:t.messages.length,trigger:t.trigger,responseMode:t.data?.responseMode,tools:t.data?.tools?.map(s=>s.code)});let n=new AbortController,o=new Set;return{iter:this.runStream(t,n,o),cancel:()=>this.cancelStream(n,t.sessionId)}}resumeStream(){let t=new AbortController,n=new Set;return{iter:this.resumeStreamGen(t,n,!0),cancel:()=>t.abort()}}async*runStream(t,n,o){(yield*this.drain(this.openMessageStream(t,n.signal),o,n))||(yield*this.resumeStreamGen(n,o,!1))}async*resumeStreamGen(t,n,o){for(let i=1;i<=bc&&!t.signal.aborted;i++){if((!o||i>1)&&(await Mo(Ri*i,t.signal),t.signal.aborted))return;let a;try{a=await this.fetchImpl(this.resumeUrl(n.size),{method:"GET",credentials:"omit",headers:{accept:"text/event-stream",...this.opts.auth.headers()},signal:t.signal})}catch(l){if(t.signal.aborted)return;q.debug("resume fetch failed \u2014 retrying",{attempt:i,err:l});continue}if(a.status===204||!a.ok){q.debug("resume \u2192 no in-flight stream",{status:a.status});return}let s=n.size;if(yield*this.drain(Ro(a,t.signal),n,t))return;if(n.size===s){q.debug("resume \u2192 stream closed with no new events; nothing to resume");return}}if(!t.signal.aborted)throw new ve("stream incomplete after resume attempts","server")}async*drain(t,n,o){try{for await(let i of t){if(o.signal.aborted)return!0;if(i.eventId){if(n.has(i.eventId))continue;n.add(i.eventId)}if(yield i,i.chunk.type==="finish"||i.chunk.type==="error")return!0}}catch(i){if(o.signal.aborted)return!0;if(i instanceof ve&&i.status!==void 0)throw i;q.debug("stream segment dropped",{err:i})}return!1}cancelStream(t,n){t.signal.aborted||(q.debug("cancel stream",{sessionId:n,visitorId:this.visitorId}),t.abort(),!(!this.visitorId||!n)&&this.fetchImpl(this.url(ke.cancelStream),{method:"POST",credentials:"omit",headers:{"content-type":"application/json",...this.opts.auth.headers()},body:JSON.stringify(this.withEnvelope({})),keepalive:!0}).catch(o=>q.debug("cancel POST failed (non-fatal)",{err:o})))}async*openMessageStream(t,n){let o=await this.fetchImpl(this.url(ke.streamMessage),{method:"POST",credentials:"omit",headers:{accept:"text/event-stream","content-type":"application/json",...this.opts.auth.headers()},body:JSON.stringify(this.withEnvelope(t)),signal:n});yield*Ro(o,n)}resumeUrl(t){let n=new URL(this.withEnvelopeQuery(ke.streamResume));return n.searchParams.set("resumeAt",String(t)),n.toString()}async postJson(t,n,o){let i=await this.fetchWithRetry(()=>[this.url(t),{method:"POST",credentials:"omit",headers:{"content-type":"application/json",...this.opts.auth.headers()},body:JSON.stringify(this.withEnvelope(n))}],o);return this.assertOk(i,o)}async postForm(t,n,o){let i=await this.fetchImpl(this.url(t),{method:"POST",credentials:"omit",headers:this.opts.auth.headers(),body:this.appendEnvelope(n)});return this.assertOk(i,o)}async getJson(t,n){let o=await this.fetchWithRetry(()=>[this.withEnvelopeQuery(t),{method:"GET",credentials:"omit",headers:{accept:"application/json",...this.opts.auth.headers()}}],n);return this.assertOk(o,n)}async fetchWithRetry(t,n){for(let o=0;;o++){let[i,a]=t(),s;try{s=await this.fetchImpl(i,a)}catch(c){if(o>=Ti)throw new ve(`${n} failed: network error`,"network",void 0,c);q.debug("request network error \u2014 retrying",{label:n,attempt:o}),await Mo(Ii(o));continue}if(s.ok||!xc.has(s.status)||o>=Ti)return s;let l=Pc(s.headers)??Ii(o);q.debug("request retryable status \u2014 retrying",{label:n,status:s.status,attempt:o,wait:l}),await Mo(l)}}async assertOk(t,n){if(!t.ok)throw new ve(`${n} failed: ${t.status}`,"server",t.status);return await t.json()}url(t){return/^https?:\/\//i.test(t)?t:`${this.opts.baseUrl}${t}`}get fetchImpl(){return this.opts.fetchImpl??globalThis.fetch.bind(globalThis)}};function yc(e){return e.includes("webm")?"webm":e.includes("ogg")?"ogg":e.includes("mp4")||e.includes("m4a")?"m4a":e.includes("mpeg")?"mp3":e.includes("wav")?"wav":"bin"}function Sc(e){if(!e||typeof e!="object")return!1;let t=e;return typeof t.visitorId=="string"&&typeof t.sessionId=="string"&&typeof t.canContinue=="boolean"}function Mi(e,t){let n=e?[{kind:"text",id:"t0",textSig:L(e),doneSig:L(!0)}]:[];return{id:we(),role:"user",createdAt:Date.now(),status:"complete",attachments:t,partsSig:L(n)}}function Lo(){return{id:we(),role:"assistant",createdAt:Date.now(),status:"streaming",partsSig:L([])}}function Li(e){return{id:e.id,role:e.role,createdAt:Date.now(),status:"streaming",partsSig:L([{kind:"text",id:`${e.id}-t0`,textSig:L(""),doneSig:L(!1)}])}}function Ni(e){return wc({id:e.id,role:e.role,createdAt:Date.now(),status:"complete",parts:[{kind:"text",id:`${e.id}-t0`,text:e.text,done:!0}]})}function wc(e){return{id:e.id,role:e.role,createdAt:e.createdAt,status:e.status,errorText:e.errorText,finishReason:e.finishReason,attachments:e.attachments,partsSig:L(e.parts.map(kc))}}function No(e){let t=e.parts.map((n,o)=>n.type==="text"?{kind:"text",id:`${e.id}-t${o}`,textSig:L(n.text),doneSig:L(!0)}:n.type==="file"?{kind:"file",url:n.url,mediaType:n.mediaType}:null).filter(n=>n!==null);return{id:e.id,role:e.role,createdAt:Date.now(),status:"complete",partsSig:L(t)}}function Oi(e){return{id:e.id,role:e.role,createdAt:e.createdAt,status:e.status,errorText:e.errorText,finishReason:e.finishReason,attachments:e.attachments,parts:e.partsSig.value.map(Ec)}}function Oo(e){let t="";for(let n of e.partsSig.value)n.kind==="text"&&(t+=n.textSig.value);return t}function kc(e){return e.kind==="text"||e.kind==="reasoning"?{kind:e.kind,id:e.id,textSig:L(e.text),doneSig:L(e.done)}:e.kind==="tool"?{kind:"tool",toolCallId:e.toolCallId,toolName:e.toolName,inputPartialSig:L(e.inputPartial),inputSig:L(e.input),outputSig:L(e.output),errorSig:L(e.error),stateSig:L(e.state)}:e}function Ec(e){return e.kind==="text"||e.kind==="reasoning"?{kind:e.kind,id:e.id,text:e.textSig.value,done:e.doneSig.value}:e.kind==="tool"?{kind:"tool",toolCallId:e.toolCallId,toolName:e.toolName,inputPartial:e.inputPartialSig.value,input:e.inputSig.value,output:e.outputSig.value,error:e.errorSig.value,state:e.stateSig.value}:e}var Di=M.scope("reducer"),gn=class{constructor(t){W(this,"messagesSig",t);W(this,"active",null)}attach(t){this.active=t}detach(){this.active=null}apply(t){let n=this.active;if(n)switch(t.type){case"start":case"start-step":case"finish-step":return;case"finish":Di.debug("finish",{reason:t.finishReason,canContinue:t.canContinue}),n.status="complete",t.finishReason&&(n.finishReason=t.finishReason),this.bumpDone(n);return;case"error":Di.warn("stream error chunk",{errorText:t.errorText}),n.status="error",n.errorText=t.errorText,this.bumpDone(n);return;case"text-start":it(n,"text",t.id);return;case"text-delta":{let o=it(n,"text",t.id);o.textSig.value+=t.delta;return}case"text-end":it(n,"text",t.id).doneSig.value=!0;return;case"reasoning-start":it(n,"reasoning",t.id).doneSig.value=!1;return;case"reasoning-delta":{let o=it(n,"reasoning",t.id);o.textSig.value+=t.delta;return}case"reasoning-end":it(n,"reasoning",t.id).doneSig.value=!0;return;case"tool-input-start":case"tool-input-delta":case"tool-input-available":case"tool-output-available":case"tool-output-error":Cc(n,t);return;case"file":mn(n,{kind:"file",url:t.url,mediaType:t.mediaType});return;case"source-url":{if(n.partsSig.value.some(i=>i.kind==="source"&&i.sourceId===t.sourceId))return;mn(n,{kind:"source",sourceId:t.sourceId,url:t.url,title:t.title});return}case"data-notification":return;default:{let o=t}}}bumpDone(t){t.partsSig.value=[...t.partsSig.value],this.messagesSig.value=[...this.messagesSig.value]}};function it(e,t,n){let o=e.partsSig.value.find(a=>a.kind===t&&a.id===n);if(o)return o;let i={kind:t,id:n,textSig:L(""),doneSig:L(!1)};return mn(e,i),i}function Pt(e,t,n){let o=e.partsSig.value.find(a=>a.kind==="tool"&&a.toolCallId===t);if(o)return o;let i={kind:"tool",toolCallId:t,toolName:n??"tool",inputPartialSig:L(""),inputSig:L(void 0),outputSig:L(void 0),errorSig:L(void 0),stateSig:L("input")};return mn(e,i),i}function mn(e,t){e.partsSig.value=[...e.partsSig.value,t]}function Cc(e,t){switch(t.type){case"tool-input-start":Pt(e,t.toolCallId,t.toolName);return;case"tool-input-delta":{let n=Pt(e,t.toolCallId);n.inputPartialSig.value+=t.delta;return}case"tool-input-available":{let n=Pt(e,t.toolCallId,t.toolName);n.inputSig.value=t.input,n.stateSig.value="awaiting";return}case"tool-output-available":{let n=Pt(e,t.toolCallId);n.outputSig.value=t.output,n.stateSig.value="output";return}case"tool-output-error":{let n=Pt(e,t.toolCallId);n.errorSig.value=t.errorText,n.stateSig.value="error";return}default:return}}var hn=M.scope("persistence");function yt(e,t=an){let n=`${v.cssPrefix}.${e}`,o=`${n}.visitorId`,i=`${n}.sessionId`,a=`${n}.userPrefs`,s=`${n}.panelOpen`,l=`${n}.panelSize`,c=`${n}.calloutDismissed`,u=`${n}.sidebarCollapsed`,p=`${n}.activeModule`,d={getVisitorId(){let _=t.get(o);if(_)return _;let f=we();return t.set(o,f),f},setVisitorId(_){hn.debug("setVisitorId (rebind)",{id:_,widgetId:e}),t.set(o,_)},loadSessionId(){return t.get(i)??void 0},saveSessionId(_){hn.trace("saveSessionId",{id:_,widgetId:e}),_?t.set(i,_):t.remove(i)},loadUserPrefs(){let _=t.get(a);if(!_)return{};try{let f=JSON.parse(_);return Ac(f)?f:{}}catch(f){return hn.warn("loadUserPrefs parse failed",{error:f}),{}}},saveUserPrefs(_){try{t.set(a,JSON.stringify(_))}catch(f){hn.warn("saveUserPrefs serialise failed",{error:f})}},patchUserPrefs(_){let f=d.loadUserPrefs();d.saveUserPrefs({...f,..._})},loadPanelOpen(){let _=t.get(s);return _==="1"?!0:_==="0"?!1:null},savePanelOpen(_){t.set(s,_?"1":"0")},loadPanelSize(){let _=t.get(l);return _==="normal"||_==="expanded"||_==="fullscreen"?_:null},savePanelSize(_){t.set(l,_)},loadCalloutDismissed(_){if(!_)return!1;let f=t.get(c);return!!f&&f===_},saveCalloutDismissed(_){_?t.set(c,_):t.remove(c)},loadSidebarCollapsed(){let _=t.get(u);return _==="1"?!0:_==="0"?!1:null},saveSidebarCollapsed(_){t.set(u,_?"1":"0")},loadActiveModule(){return t.get(p)||null},saveActiveModule(_){t.set(p,_)},clearSession(){t.remove(i)}};return d}function Ac(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}var Hi=M.scope("feedback:audio"),vn=class{constructor(){W(this,"ctx",null);W(this,"master",null);W(this,"buffers",new Map)}unlock(){if(this.ctx){this.ctx.state==="suspended"&&this.ctx.resume();return}let t=globalThis.AudioContext??globalThis.webkitAudioContext;if(t)try{this.ctx=new t,this.master=this.ctx.createGain(),this.master.gain.value=1,this.master.connect(this.ctx.destination)}catch(n){Hi.warn("AudioContext init failed",{err:n})}}setVolume(t){if(!this.master||!this.ctx)return;let n=Math.max(0,Math.min(1,t));this.master.gain.setTargetAtTime(n,this.ctx.currentTime,.01)}playTone(t){let n=this.ctx,o=this.master;if(!n||!o||n.state!=="running")return;let i=n.currentTime,a=t.noteMs/1e3;t.notes.forEach((s,l)=>{let c=n.createOscillator();c.type=t.type,c.frequency.value=s;let u=n.createGain(),p=i+l*a;u.gain.setValueAtTime(1e-4,p),u.gain.exponentialRampToValueAtTime(t.peakGain,p+.005),u.gain.exponentialRampToValueAtTime(1e-4,p+a),c.connect(u).connect(o),c.start(p),c.stop(p+a+.01)})}async playUrl(t){let n=this.ctx,o=this.master;if(!n||!o||n.state!=="running")return;let i=await this.getBuffer(t);if(!i)return;let a=n.createBufferSource();a.buffer=i,a.connect(o),a.start()}destroy(){this.ctx&&this.ctx.close().catch(()=>{}),this.ctx=null,this.master=null,this.buffers.clear()}async getBuffer(t){if(!this.ctx)return null;let n=this.buffers.get(t);if(n)return n instanceof Promise,n;let o=this.ctx,i=fetch(t).then(a=>a.ok?a.arrayBuffer():Promise.reject(new Error(`fetch ${a.status}`))).then(a=>o.decodeAudioData(a)).then(a=>(this.buffers.set(t,a),a)).catch(a=>(Hi.warn("audio fetch/decode failed",{url:t,err:a}),this.buffers.delete(t),null));return this.buffers.set(t,i),i}};var Bi={messageReceived:10,messageSent:0,error:[20,40,20],voiceStart:10,voiceStop:0},$i={messageReceived:{notes:[880,1318.51],noteMs:90,type:"sine",peakGain:.45},messageSent:{notes:[1568],noteMs:60,type:"sine",peakGain:.25},error:{notes:[523.25,392],noteMs:120,type:"triangle",peakGain:.55},voiceStart:{notes:[1318.51],noteMs:50,type:"sine",peakGain:.3},voiceStop:{notes:[880],noteMs:50,type:"sine",peakGain:.3}};var Be=null,bn=0;function Tc(){return typeof navigator<"u"&&typeof navigator.vibrate=="function"}function Ic(){if(typeof document>"u")return null;let e=document.createElement("input");e.type="checkbox",e.setAttribute("switch",""),e.setAttribute("aria-hidden","true"),e.tabIndex=-1,e.id=`__${v.cssPrefix}_haptic_${Math.random().toString(36).slice(2)}`;let t=document.createElement("label");t.htmlFor=e.id,t.setAttribute("aria-hidden","true");let n="position:absolute!important;width:1px!important;height:1px!important;overflow:hidden!important;clip:rect(0,0,0,0)!important;opacity:0!important;pointer-events:none!important;";return e.style.cssText=n,t.style.cssText=n,document.body.append(e,t),{input:e,label:t}}function Ui(e){if(!(e===0||Array.isArray(e)&&e.every(t=>t===0))){if(Tc())try{navigator.vibrate(e);return}catch{}if(Be||(Be=Ic()),!!Be)try{Be.label.click()}catch{}}}function zi(){bn++;let e=!1;return()=>{e||(e=!0,bn=Math.max(0,bn-1),bn===0&&Be&&(Be.input.remove(),Be.label.remove(),Be=null))}}var Rc=M.scope("feedback"),Mc=100,xn=class{constructor(t,n){W(this,"mutedSig",L(!1));W(this,"audio",new vn);W(this,"releaseHaptics");W(this,"sound");W(this,"haptics");W(this,"lastPlayed",new Map);W(this,"reducedMotionMq",null);this.sound=t,this.haptics=n,this.releaseHaptics=zi(),this.audio.setVolume(this.effectiveVolume()),typeof matchMedia<"u"&&(this.reducedMotionMq=matchMedia("(prefers-reduced-motion: reduce)"))}unlock(){this.audio.unlock(),this.audio.setVolume(this.effectiveVolume())}update(t,n){this.sound=t,this.haptics=n,this.audio.setVolume(this.effectiveVolume())}setMuted(t){this.mutedSig.value!==t&&(this.mutedSig.value=t)}toggleMuted(){this.mutedSig.value=!this.mutedSig.value}play(t){this.mutedSig.value||this.isDeduped(t)||(this.lastPlayed.set(t,performance.now()),this.sound.enabled&&this.playSound(t),this.haptics.enabled&&this.isTouchDevice()&&this.playHaptic(t))}destroy(){this.audio.destroy(),this.releaseHaptics()}isDeduped(t){let n=this.lastPlayed.get(t);return n===void 0?!1:performance.now()-n<Mc}playSound(t){let n=this.sound.events?.[t];if(n===!1)return;if(typeof n=="string"){this.audio.playUrl(n).catch(i=>Rc.warn("audio play failed",{err:i,url:n}));return}let o=$i[t];o&&this.audio.playTone(o)}playHaptic(t){if(this.reducedMotionMq?.matches)return;let n=this.haptics.events?.[t];if(n===!1)return;let o=n===!0||n===void 0?Bi[t]:n;Ui(o)}effectiveVolume(){let t=this.sound.volume??.3;return this.reducedMotionMq?.matches?t*.5:t}isTouchDevice(){return typeof window>"u"?!1:matchMedia("(hover: none) and (pointer: coarse)").matches}};function Ge(e,t){return e instanceof ve&&e.status===429?t.errorRateLimited:t.errorGeneric}var Lc=0;function r(e,t,n,o,i,a){t||(t={});var s,l,c=t;if("ref"in c)for(l in c={},t)l=="ref"?s=t[l]:c[l]=t[l];var u={type:e,props:c,key:n,ref:s,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--Lc,__i:-1,__u:0,__source:i,__self:a};if(typeof e=="function"&&(s=e.defaultProps))for(l in s)c[l]===void 0&&(c[l]=s[l]);return H.vnode&&H.vnode(u),u}var T={fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,viewBox:"0 0 24 24"},Nc=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"M21 12a8 8 0 0 1-12 6.93L3 21l1.65-5.16A8 8 0 1 1 21 12Z"})}),Ee=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"M18 6 6 18M6 6l12 12"})}),Fi=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"M12 5v14M5 12h14"})}),Wi=()=>r("svg",{...T,"aria-hidden":"true",children:[r("path",{d:"m22 2-7 20-4-9-9-4Z"}),r("path",{d:"M22 2 11 13"})]}),Gi=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"M12 19V5M5 12l7-7 7 7"})}),Ki=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"M3 20V4l18 8-18 8Z"})}),Pn=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"m9 18 6-6-6-6"})}),Vi=()=>r("svg",{...T,"aria-hidden":"true",children:r("rect",{x:"6",y:"6",width:"12",height:"12",rx:"2"})}),qi=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"m21 11-9 9a5.5 5.5 0 0 1-7.78-7.78l8.49-8.49a3.67 3.67 0 0 1 5.19 5.19l-8.49 8.49a1.83 1.83 0 0 1-2.6-2.6l7.78-7.78"})}),Xi=()=>r("svg",{...T,"aria-hidden":"true",children:[r("rect",{x:"9",y:"2",width:"6",height:"12",rx:"3"}),r("path",{d:"M5 10a7 7 0 0 0 14 0M12 19v3"})]}),ji=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"M3 8V3h5M21 8V3h-5M3 16v5h5M21 16v5h-5"})}),Yi=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"M8 3v5H3M16 3v5h5M8 21v-5H3M16 21v-5h5"})}),Ji=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"M3 3h7v2H5v5H3zM21 3h-7v2h5v5h2zM3 21h7v-2H5v-5H3zM21 21h-7v-2h5v-5h2z"})}),Qi=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"M10 3v5H3M14 3v5h7M10 21v-5H3M14 21v-5h7"})}),Zi=()=>r("svg",{...T,"aria-hidden":"true",viewBox:"0 0 10 10",children:r("path",{d:"M9 1L1 9M9 5L5 9M9 9H9",strokeWidth:"1.5"})}),ea=()=>r("svg",{...T,"aria-hidden":"true",children:[r("circle",{cx:"12",cy:"5",r:"1.5",fill:"currentColor",stroke:"none"}),r("circle",{cx:"12",cy:"12",r:"1.5",fill:"currentColor",stroke:"none"}),r("circle",{cx:"12",cy:"19",r:"1.5",fill:"currentColor",stroke:"none"})]}),ta=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"M11 5 6 9H2v6h4l5 4zM15 9a5 5 0 0 1 0 6M18 7a9 9 0 0 1 0 10"})}),na=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"M11 5 6 9H2v6h4l5 4zM22 9l-6 6M16 9l6 6"})}),oa=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"M20 6 9 17l-5-5"})}),ra=()=>r("svg",{...T,"aria-hidden":"true",children:[r("path",{d:"M3 3v6h6"}),r("path",{d:"M3.05 13A9 9 0 1 0 6 5.3L3 9"}),r("path",{d:"M12 7v5l3 2"})]});var St=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"M19 12H5M12 19l-7-7 7-7"})}),ia=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"M15 3h6v6M10 14 21 3M21 14v5a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5"})}),aa=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"M3 6h18M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"})}),sa=()=>r("svg",{...T,"aria-hidden":"true",children:[r("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8Z"}),r("path",{d:"M14 2v6h6"})]}),Oc=()=>r("svg",{...T,"aria-hidden":"true",children:[r("path",{d:"m12 3-1.5 4.5L6 9l4.5 1.5L12 15l1.5-4.5L18 9l-4.5-1.5Z"}),r("path",{d:"M19 15v4M17 17h4M5 3v2M4 4h2"})]}),Dc=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2Z"})}),Do=()=>r("svg",{...T,"aria-hidden":"true",children:[r("circle",{cx:"12",cy:"12",r:"10"}),r("path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"}),r("path",{d:"M12 17h.01"})]}),Hc=()=>r("svg",{...T,"aria-hidden":"true",children:[r("path",{d:"m15 4 3 3-9 9-3-3z"}),r("path",{d:"M18 2v2M20 4h2M3 20l3-3M3 16h2M5 14v2"})]}),Bc=()=>r("svg",{...T,"aria-hidden":"true",children:[r("rect",{x:"4",y:"8",width:"16",height:"12",rx:"2"}),r("path",{d:"M12 8V4"}),r("circle",{cx:"12",cy:"3",r:"1"}),r("path",{d:"M2 14h2M20 14h2M9 13h.01M15 13h.01M9.5 17h5"})]}),$c=()=>r("svg",{...T,"aria-hidden":"true",children:[r("path",{d:"M4 14v-2a8 8 0 0 1 16 0v2"}),r("rect",{x:"2",y:"14",width:"4",height:"6",rx:"1.5"}),r("rect",{x:"18",y:"14",width:"4",height:"6",rx:"1.5"}),r("path",{d:"M20 20v1a3 3 0 0 1-3 3h-5"})]}),Uc=()=>r("svg",{...T,"aria-hidden":"true",children:[r("circle",{cx:"12",cy:"12",r:"10"}),r("circle",{cx:"12",cy:"12",r:"4"}),r("path",{d:"m4.93 4.93 4.24 4.24M14.83 14.83l4.24 4.24M14.83 9.17l4.24-4.24M4.93 19.07l4.24-4.24"})]}),Ho=()=>r("svg",{...T,"aria-hidden":"true",children:[r("circle",{cx:"11",cy:"11",r:"7"}),r("path",{d:"m21 21-4.3-4.3"})]}),la=()=>r("svg",{...T,"aria-hidden":"true",children:[r("circle",{cx:"12",cy:"12",r:"9"}),r("path",{d:"m8.5 12 2.5 2.5 4.5-5"})]}),ca=()=>r("svg",{...T,"aria-hidden":"true",children:[r("path",{d:"M3 9.5 12 3l9 6.5"}),r("path",{d:"M5 9v11a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V9"})]}),da=()=>r("svg",{...T,"aria-hidden":"true",children:[r("path",{d:"m3 11 15-5v12L3 13z"}),r("path",{d:"M3 11v2a2 2 0 0 0 2 2h1V9H5a2 2 0 0 0-2 2z"}),r("path",{d:"M7 15v3a2 2 0 0 0 4 0v-2"}),r("path",{d:"M21 10a3 3 0 0 1 0 4"})]}),wt=()=>r("svg",{...T,"aria-hidden":"true",children:[r("path",{d:"M14 9a2 2 0 0 1-2 2H6l-4 4V4a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2z"}),r("path",{d:"M18 9h2a2 2 0 0 1 2 2v11l-4-4h-6a2 2 0 0 1-2-2v-1"})]}),_a=()=>r("svg",{...T,"aria-hidden":"true",children:[r("circle",{cx:"12",cy:"12",r:"4"}),r("path",{d:"M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M4.93 19.07l1.41-1.41M17.66 6.34l1.41-1.41"})]}),ua=()=>r("svg",{...T,"aria-hidden":"true",children:r("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"})}),pa=()=>r("svg",{...T,"aria-hidden":"true",children:[r("circle",{cx:"12",cy:"12",r:"9"}),r("path",{d:"M12 3v18"}),r("path",{d:"M12 3a9 9 0 0 1 0 18z",fill:"currentColor",stroke:"none"})]}),zc=()=>r("svg",{...T,"aria-hidden":"true",children:[r("circle",{cx:"10.5",cy:"10.5",r:"6.5"}),r("path",{d:"M8 11a2.5 2.5 0 0 0 5 0"}),r("path",{d:"m20 20-4.4-4.4"})]}),Fc=()=>r("svg",{...T,"aria-hidden":"true",children:[r("path",{d:"M12 3.5 13.6 9 19 10.5 13.6 12 12 17.5 10.4 12 5 10.5 10.4 9z"}),r("path",{d:"M18.5 4v3M20 5.5h-3M5.5 16v2.5M6.75 17.25h-2.5"})]}),Wc=()=>r("svg",{...T,"aria-hidden":"true",children:[r("path",{d:"M4 18h16"}),r("path",{d:"M5 18a7 7 0 0 1 14 0"}),r("path",{d:"M12 8V6"}),r("path",{d:"M10 6h4"})]}),Gc=()=>r("svg",{...T,"aria-hidden":"true",children:[r("path",{d:"M7 11V6.5a1.5 1.5 0 0 1 3 0V10"}),r("path",{d:"M10 10V5.5a1.5 1.5 0 0 1 3 0V10"}),r("path",{d:"M13 10V6.5a1.5 1.5 0 0 1 3 0V12"}),r("path",{d:"M16 9.5a1.5 1.5 0 0 1 3 0v2.5a7 7 0 0 1-7 7 7 7 0 0 1-6.4-4.2L4 12.5a1.5 1.5 0 0 1 2.6-1.5L7 11"})]}),fa={chat:Nc,message:Dc,bubbles:wt,spark:Oc,wand:Hc,bot:Bc,help:Do,lifebuoy:Uc,headset:$c,search:zc,sparkles:Fc,concierge:Wc,wave:Gc};var C=v.cssPrefix,y={launcher:`${C}-launcher`,callout:`${C}-callout`,calloutDismiss:`${C}-callout-dismiss`,panel:`${C}-panel`,panelHeader:`${C}-panel-header`,resizeGrip:`${C}-resize-grip`,actionClear:`${C}-action-clear`,actionExpand:`${C}-action-expand`,actionFullscreen:`${C}-action-fullscreen`,actionPopOut:`${C}-action-popout`,actionSound:`${C}-action-sound`,actionHistory:`${C}-action-history`,actionLanguage:`${C}-action-language`,actionTheme:`${C}-action-theme`,actionClose:`${C}-action-close`,actionOverflow:`${C}-action-overflow`,languageOption:`${C}-language-option`,themeOption:`${C}-theme-option`,composer:`${C}-composer`,composerInput:`${C}-composer-input`,composerSend:`${C}-composer-send`,composerStop:`${C}-composer-stop`,composerAttach:`${C}-composer-attach`,composerFileInput:`${C}-composer-file-input`,composerVoice:`${C}-composer-voice`,attachmentChip:`${C}-attachment-chip`,attachmentRemove:`${C}-attachment-remove`,suggestion:`${C}-suggestion`,messageBubble:`${C}-message`,messageRetry:`${C}-message-retry`,historyPane:`${C}-history-pane`,historyBack:`${C}-history-back`,historyItem:`${C}-history-item`,sidebar:`${C}-sidebar`,sidebarToggle:`${C}-sidebar-toggle`,sidebarNewChat:`${C}-sidebar-new-chat`,sidebarItem:`${C}-sidebar-item`,messengerHome:`${C}-messenger-home`,modulesEmpty:`${C}-modules-empty`,tab:`${C}-tab`,tabBadge:`${C}-tab-badge`,homeView:`${C}-home-view`,homeGreeting:`${C}-home-greeting`,homeBrand:`${C}-home-brand`,backHeader:`${C}-back-header`,contentView:`${C}-content-view`,contentScroll:`${C}-content-scroll`,homeSearch:`${C}-home-search`,helpSearch:`${C}-help-search`,homeRecent:`${C}-home-recent`,homeContentRow:`${C}-home-content-row`,helpArticle:`${C}-help-article`,newsItem:`${C}-news-item`};function ce(e,t){return`${e}-${t}`}var xp={clear:y.actionClear,expand:y.actionExpand,fullscreen:y.actionFullscreen,popOut:y.actionPopOut,sound:y.actionSound,history:y.actionHistory,language:y.actionLanguage,theme:y.actionTheme,close:y.actionClose};var yn=v.cssPrefix;function ga({onToggle:e,launcher:t,strings:n,leaving:o,edgeTab:i}){let a=t.variant!=="circle"&&!!t.label;return r("button",{type:"button",class:`${yn}-fab`,"data-variant":t.variant,"data-size":t.size,"data-edge-tab":i?"true":void 0,"data-leaving":o?"true":void 0,"data-testid":y.launcher,onClick:e,"aria-label":n.launcherOpen,children:[Kc(t.icon),a?r("span",{class:`${yn}-fab-label`,children:t.label}):null]})}function Kc(e){let t=fa[e];return t?r(t,{}):r(Vc,{source:e})}function Vc({source:e}){return r("span",{ref:t=>{t&&qc(t,e)},"aria-hidden":"true"})}function qc(e,t){if(e.dataset.svgMounted!==t)try{let o=new DOMParser().parseFromString(t,"image/svg+xml").documentElement;o&&o.tagName.toLowerCase()==="svg"&&(e.replaceChildren(document.importNode(o,!0)),e.dataset.svgMounted=t)}catch{}}function ma({callout:e,launcherPosition:t,closeLabel:n,onDismiss:o}){let[i,a]=k(!1);return w(()=>{let s=setTimeout(()=>a(!0),e.delayMs);return()=>clearTimeout(s)},[e.delayMs]),w(()=>{if(!i||e.autoDismissMs<=0)return;let s=setTimeout(o,e.autoDismissMs);return()=>clearTimeout(s)},[i,e.autoDismissMs,o]),i?r("div",{class:`${yn}-callout`,role:"status","data-shape":e.shape,"data-position":Xc(e.position,t),"data-animated":e.animated?"true":void 0,"data-testid":y.callout,children:[r("span",{children:e.text}),r("button",{type:"button",class:`${yn}-callout-close`,onClick:o,"aria-label":n,title:n,"data-testid":y.calloutDismiss,children:r(Ee,{})})]}):null}function Xc(e,t){let n=t.endsWith("-right"),o=t.startsWith("bottom-");return e==="vertical"?o?"top":"bottom":n?"left":"right"}function Sn({panelEl:e,resize:t,position:n,initialSize:o,onSizeChange:i,strings:a}){let s=v.cssPrefix,l=N(null);if(w(()=>{if(!e)return;let m=e.style;t.minWidth&&m.setProperty(`--${s}-resize-min-w`,t.minWidth),t.maxWidth&&m.setProperty(`--${s}-resize-max-w`,t.maxWidth),t.minHeight&&m.setProperty(`--${s}-resize-min-h`,t.minHeight),t.maxHeight&&m.setProperty(`--${s}-resize-max-h`,t.maxHeight),o&&(m.setProperty(`--${s}-widget-w`,`${o.width}px`),m.setProperty(`--${s}-widget-h`,`${o.height}px`))},[e,t.minWidth,t.maxWidth,t.minHeight,t.maxHeight,s,o]),!e)return null;let c=n.startsWith("top-"),u=n.endsWith("-right"),p=`${s}-resize-grip ${s}-resize-grip--${c?"bottom":"top"}-${u?"left":"right"}`,d=m=>{if(!e)return;let h=m.currentTarget,P=e.getBoundingClientRect();l.current={pointerId:m.pointerId,startX:m.clientX,startY:m.clientY,startW:P.width,startH:P.height,dirX:u?-1:1,dirY:c?1:-1},h.setPointerCapture(m.pointerId),m.preventDefault()},_=m=>{let h=l.current;if(!h||m.pointerId!==h.pointerId||!e)return;let P=(m.clientX-h.startX)*h.dirX,b=(m.clientY-h.startY)*h.dirY;e.style.setProperty(`--${s}-widget-w`,`${h.startW+P}px`),e.style.setProperty(`--${s}-widget-h`,`${h.startH+b}px`)},f=m=>{let h=l.current;if(!h||m.pointerId!==h.pointerId||!e)return;m.currentTarget.releasePointerCapture(m.pointerId);let P=e.getBoundingClientRect();i({width:Math.round(P.width),height:Math.round(P.height)}),l.current=null};return r("div",{class:p,role:"separator","aria-orientation":"vertical","aria-label":a.resizeHandle,title:a.resizeHandle,onPointerDown:d,onPointerMove:_,onPointerUp:f,onPointerCancel:f,"data-testid":y.resizeGrip,children:r(Zi,{})})}var Ke=v.cssPrefix,jc=`.${Ke}-header, .${Ke}-back-header, .${Ke}-home-hero`,Yc='button, a, input, textarea, select, [role="tab"], [contenteditable]',ha=56;function wn(e,t){w(()=>{if(!t||!e)return;let n=c=>Number.parseFloat(c)||0,o=(c,u)=>Math.min(u,Math.max(-u,c)),i=null,a=c=>{let u=c.target;if(!(u instanceof Element)||!u.closest(jc)||u.closest(Yc))return;let p=e.getBoundingClientRect();i={id:c.pointerId,x:c.clientX,y:c.clientY,dx:n(e.style.getPropertyValue(`--${Ke}-modal-dx`)),dy:n(e.style.getPropertyValue(`--${Ke}-modal-dy`)),maxX:(window.innerWidth+p.width)/2-ha,maxY:(window.innerHeight+p.height)/2-ha},e.dataset.dragging="true",c.preventDefault()},s=c=>{if(!i||c.pointerId!==i.id)return;let u=o(i.dx+c.clientX-i.x,i.maxX),p=o(i.dy+c.clientY-i.y,i.maxY);e.style.setProperty(`--${Ke}-modal-dx`,`${u}px`),e.style.setProperty(`--${Ke}-modal-dy`,`${p}px`)},l=c=>{!i||c.pointerId!==i.id||(i=null,delete e.dataset.dragging)};return e.addEventListener("pointerdown",a),window.addEventListener("pointermove",s),window.addEventListener("pointerup",l),window.addEventListener("pointercancel",l),()=>{e.removeEventListener("pointerdown",a),window.removeEventListener("pointermove",s),window.removeEventListener("pointerup",l),window.removeEventListener("pointercancel",l)}},[e,t])}function kt(e,t,n,o){switch(e){case"clear":case"sound":case"history":case"language":case"theme":return!0;case"expand":return t==="floating";case"fullscreen":return t!=="standalone";case"popOut":return t!=="standalone"&&!!o?.popOutUrl;case"close":return t==="standalone"||t==="page"?!1:t==="inline"?n==="fullscreen":!0}}function kn(e,t,n){return kt("close",e,t)?n.main.includes("close")||n.overflow.includes("close"):!1}function va(e,t){return e==="inline"&&t==="fullscreen"?"exit-fullscreen":"close"}var Jc='a[href],button:not([disabled]),textarea:not([disabled]),input:not([disabled]):not([type="hidden"]),select:not([disabled]),[tabindex]:not([tabindex="-1"])';function En(e){let t=n=>{if(n.key!=="Tab")return;let o=[...e.querySelectorAll(Jc)].filter(l=>l.offsetParent!==null||l===document.activeElement);if(o.length===0){n.preventDefault();return}let i=o[0],a=o[o.length-1];if(!i||!a)return;let s=e.getRootNode().activeElement;n.shiftKey&&s===i?(n.preventDefault(),a.focus()):!n.shiftKey&&s===a&&(n.preventDefault(),i.focus())};return e.addEventListener("keydown",t),()=>e.removeEventListener("keydown",t)}function Cn(e){return e.trim().split(/\s+/).slice(0,2).map(t=>t.charAt(0).toUpperCase()).join("")}var Bo=v.cssPrefix;function ba({agent:e}){let t=e.status??"online";return r("div",{class:`${Bo}-agent`,children:[r("div",{class:`${Bo}-agent-avatar`,"data-status":t,children:e.avatar?r("img",{src:e.avatar,alt:""}):r("span",{children:Cn(e.name)})}),r("div",{class:`${Bo}-agent-meta`,children:[r("strong",{children:e.name}),e.title?r("span",{children:e.title}):null]})]})}var xa=M.scope("attachments");function An(e,t,n){let o=Zc(e),i=[],a=[],s=nd(n.accept),l=t.reduce((u,p)=>u+p.size,0),c=t.length;for(let u of o){let p=Qc(u,c,l,n,s);if(p){a.push({file:u,reason:p});continue}i.push(td(u)),l+=u.size,c+=1}return(i.length||a.length)&&xa.debug("ingest",{accepted:i.length,rejected:a.map(u=>({name:u.file.name,reason:u.reason}))}),{accepted:i,rejected:a}}function $o(e){try{URL.revokeObjectURL(e.previewUrl)}catch(t){xa.debug("revokeObjectURL failed",{error:t})}}function Qc(e,t,n,o,i){return t>=o.maxCount?"count":n+e.size>o.maxBytes?"bytes":od(e,i)?null:"mime"}function Zc(e){return e?Array.isArray(e)?e.filter(t=>t instanceof File):[...e].map(t=>t instanceof File?t:ed(t)).filter(t=>t!==null):[]}function ed(e){let t=e;return!t?.getAsFile||t.kind!=="file"?null:t.getAsFile()}function td(e){return{file:e,id:we(),mediaType:e.type||"application/octet-stream",name:e.name||"pasted-file",previewUrl:URL.createObjectURL(e),size:e.size}}function nd(e){return e.split(",").map(t=>t.trim().toLowerCase()).filter(Boolean).map(t=>{if(t.startsWith("."))return{kind:"ext",ext:t};let[n="*",o="*"]=t.split("/");return{kind:"mime",type:n,subtype:o}})}function od(e,t){if(t.length===0)return!0;let[n="*",o="*"]=(e.type||"").toLowerCase().split("/"),i=(e.name||"").toLowerCase();return t.some(a=>a.kind==="ext"?i.endsWith(a.ext):(a.type==="*"||a.type===n)&&(a.subtype==="*"||a.subtype===o))}var Et=v.cssPrefix;function Pa({attachment:e,onRemove:t}){let n=e.mediaType.startsWith("image/");return r("span",{class:`${Et}-attachment-chip`,title:e.name,"data-testid":ce(y.attachmentChip,e.id),children:[n?r("img",{class:`${Et}-attachment-thumb`,src:e.previewUrl,alt:""}):r("span",{class:`${Et}-attachment-thumb`,"aria-hidden":"true",children:r(sa,{})}),r("span",{class:`${Et}-attachment-name`,children:e.name}),r("button",{type:"button",class:`${Et}-attachment-remove`,onClick:t,"aria-label":`Remove ${e.name}`,"data-testid":ce(y.attachmentRemove,e.id),children:r(Ee,{})})]})}var Uo={isSupported:!1,start:()=>{},stop:()=>{}};function zo(e,t,n){return e==="disabled"?Uo:e==="server"?sd(n):rd(t)}function rd(e){let t=id();if(!t)return Uo;let n=null;return{isSupported:!0,start(o,i){n=new t,n.continuous=!0,n.interimResults=!0,n.lang=e,n.addEventListener("result",s=>{let l=s,c="",u=!1;for(let p=l.resultIndex;p<l.results.length;p++){let d=l.results[p];d&&(c+=d[0].transcript,d.isFinal&&(u=!0))}o(c,u)});let a=()=>{n=null,i()};n.addEventListener("end",a),n.addEventListener("error",a),n.start()},stop(){n?.stop()}}}function id(){let e=globalThis;return e.SpeechRecognition??e.webkitSpeechRecognition}var ad=["audio/webm;codecs=opus","audio/webm","audio/ogg;codecs=opus","audio/mp4"];function sd(e){if(typeof MediaRecorder>"u"||!navigator?.mediaDevices?.getUserMedia)return Uo;let t=null,n=null,o=[],i=()=>{for(let a of n?.getTracks()??[])a.stop();n=null};return{isSupported:!0,async start(a,s){try{n=await navigator.mediaDevices.getUserMedia({audio:!0});let l=ld();t=new MediaRecorder(n,l?{mimeType:l}:void 0),o=[],t.addEventListener("dataavailable",c=>{c.data.size>0&&o.push(c.data)}),t.addEventListener("stop",async()=>{let c=t?.mimeType??"audio/webm";i();let u=new Blob(o,{type:c});o=[];try{let{text:p}=await e(u,c);p&&a(p,!0)}catch{}finally{s()}}),t.start()}catch{i(),s()}},stop(){t?.stop()}}}function ld(){for(let e of ad)if(MediaRecorder.isTypeSupported(e))return e}var he=v.cssPrefix,Ve=M.scope("composer");function at(e){return e.reduce((t,n)=>t+n.size,0)}var cd={arrowUp:Gi,paperPlane:Wi,send:Ki,chevron:Pn};function ya({options:e,transport:t,feedback:n,bus:o,isStreaming:i,onSend:a,onStop:s,attachApiRef:l}){let c=e.strings,[u,p]=k(""),[d,_]=k([]),[f,m]=k(!1),h=N(null),P=N(null),b=e.features.files,S=e.features.voice,[I,j]=k(()=>zo(S,e.locale,(E,z)=>t.transcribe(E,z)));w(()=>{f||S==="disabled"||j(zo(S,e.locale,(E,z)=>t.transcribe(E,z)))},[e.locale,S,t,f]),w(()=>{let E=h.current;if(!E)return;let z=E.getRootNode(),Y="activeElement"in z?z.activeElement:null;Y&&E.closest(`.${he}-panel`)?.contains(Y)||E.focus({preventScroll:!0})},[]),w(()=>{let E=h.current;if(E){if(u.length===0){E.style.height="";return}E.style.height="auto",E.style.height=`${Math.min(E.scrollHeight,160)}px`}},[u]);let U=N(d);U.current=d,w(()=>()=>U.current.forEach($o),[]),w(()=>{if(l)return l.current={attachFromDrop:E=>{let z=An(E,U.current,e.attachments);z.accepted.length!==0&&(Ve.info("attach (drop)",{count:z.accepted.length,totalBytes:at(z.accepted)}),o.emit("attach",{count:z.accepted.length,totalBytes:at(z.accepted)}),_(Y=>[...Y,...z.accepted]))}},()=>{l.current&&(l.current=null)}},[l,e.attachments]),w(()=>{let E=h.current;if(!E)return;let z=E.closest(`.${he}-panel`);if(!z)return;let Y=fe=>{let Ue=fe.clipboardData;if(!Ue)return;if(b){let ue=An(Ue.items,U.current,e.attachments);if(ue.accepted.length>0){fe.preventDefault(),Ve.info("attach (paste)",{count:ue.accepted.length,totalBytes:at(ue.accepted)}),o.emit("attach",{count:ue.accepted.length,totalBytes:at(ue.accepted)}),_(It=>[...It,...ue.accepted]);return}}if(fe.target===E)return;let _e=Ue.getData("text/plain");_e&&(fe.preventDefault(),p(ue=>ue+_e),E.focus())};return z.addEventListener("paste",Y),()=>z.removeEventListener("paste",Y)},[b,e.attachments,he]);let oe=()=>{let E=u.trim();!E&&d.length===0||i||(a(E,d),p(""),_([]))},O=E=>{E.key!=="Enter"||E.shiftKey||E.isComposing||(E.preventDefault(),i?s():oe())},le=E=>{let z=E.target,Y=An(z.files,d,e.attachments);Y.accepted.length>0&&(Ve.info("attach (file picker)",{count:Y.accepted.length,totalBytes:at(Y.accepted)}),o.emit("attach",{count:Y.accepted.length,totalBytes:at(Y.accepted)}),_(fe=>[...fe,...Y.accepted])),z.value=""},B=E=>{Ve.info("removeAttachment",{id:E}),o.emit("removeAttachment",{id:E}),_(z=>{let Y=z.find(fe=>fe.id===E);return Y&&$o(Y),z.filter(fe=>fe.id!==E)})},R=N(null),Ye=()=>{if(I.isSupported){if(f){let E=R.current?Date.now()-R.current:0;Ve.info("voiceStop",{durationMs:E}),o.emit("voiceStop",{durationMs:E}),I.stop(),m(!1),n.play("voiceStop"),R.current=null;return}R.current=Date.now(),Ve.info("voiceStart"),o.emit("voiceStart",void 0),m(!0),n.play("voiceStart"),I.start((E,z)=>p(Y=>z?`${Y}${E} `:Y),()=>{if(m(!1),R.current){let E=Date.now()-R.current;Ve.debug("voiceStop (auto)",{durationMs:E}),o.emit("voiceStop",{durationMs:E}),R.current=null}})}},de=cd[e.composer.sendButton.icon];return r("div",{class:`${he}-composer`,"data-testid":y.composer,children:[d.length>0?r("div",{class:`${he}-attachments`,children:d.map(E=>r(Pa,{attachment:E,onRemove:()=>B(E.id)},E.id))}):null,r("div",{class:`${he}-composer-row`,children:[r("div",{class:`${he}-composer-actions`,children:[b?r("button",{type:"button",class:`${he}-icon-btn`,onClick:()=>P.current?.click(),"aria-label":c.attach,"data-testid":y.composerAttach,children:r(qi,{})}):null,I.isSupported?r("button",{type:"button",class:`${he}-icon-btn`,onClick:Ye,"aria-label":f?c.micStop:c.micStart,"aria-pressed":f,"data-recording":f?"true":void 0,"data-testid":y.composerVoice,children:r(Xi,{})}):null]}),r("textarea",{ref:h,class:`${he}-textarea`,rows:1,value:u,placeholder:c.composerPlaceholder,onInput:E=>p(E.target.value),onKeyDown:O,"aria-label":c.composerPlaceholder,"data-testid":y.composerInput}),i?r("button",{type:"button",class:`${he}-send`,onClick:s,"aria-label":c.stop,"data-testid":y.composerStop,children:r(Vi,{})}):r("button",{type:"button",class:`${he}-send`,"data-shape":e.composer.sendButton.shape,"data-variant":e.composer.sendButton.variant,onClick:oe,disabled:!u.trim()&&d.length===0,"aria-label":c.send,"data-testid":y.composerSend,children:r(de,{})})]}),r("input",{ref:P,type:"file",multiple:!0,accept:e.attachments.accept,onChange:le,class:`${he}-sr-only`,"data-testid":y.composerFileInput})]})}var dd=v.cssPrefix;function Sa({visible:e,strings:t}){return e?r("div",{class:`${dd}-dropzone`,role:"status","aria-live":"polite",children:t.dropZone}):null}function Tn({containerRef:e,onDrop:t}){let[n,o]=k(!1);return w(()=>{let i=e.current;if(!i)return;let a=0,s=p=>{a+=1,p.dataTransfer?.types.includes("Files")&&(p.preventDefault(),o(!0))},l=()=>{a-=1,!(a>0)&&(a=0,o(!1))},c=p=>{p.dataTransfer?.types.includes("Files")&&p.preventDefault()},u=p=>{a=0,o(!1),p.dataTransfer&&(p.preventDefault(),t(p.dataTransfer.items))};return i.addEventListener("dragenter",s),i.addEventListener("dragleave",l),i.addEventListener("dragover",c),i.addEventListener("drop",u),()=>{i.removeEventListener("dragenter",s),i.removeEventListener("dragleave",l),i.removeEventListener("dragover",c),i.removeEventListener("drop",u)}},[e,t]),{visible:n}}function wa({itemCount:e,initialFocusIndex:t}){let[n,o]=k(!1),i=N(null),a=N(null),[s,l]=k(-1),c=D(()=>{o(!1),l(-1),i.current?.focus()},[]),u=D(()=>o(_=>!_),[]);w(()=>{if(!n)return;let _=f=>{let m=a.current,h=i.current;if(!m||!h)return;let P=f.composedPath();P.includes(m)||P.includes(h)||(o(!1),l(-1))};return document.addEventListener("click",_,!0),()=>document.removeEventListener("click",_,!0)},[n]),w(()=>{if(!n||e===0)return;let _=t?.()??0,f=_<0||_>=e?0:_;l(f)},[n,e,t]),w(()=>{if(!n||s<0)return;a.current?.querySelectorAll("[role='menuitem']")?.[s]?.focus()},[n,s]);let p=D(_=>{(_.key==="ArrowDown"||_.key==="Enter"||_.key===" ")&&(_.preventDefault(),o(!0))},[]),d=D(_=>{if(e!==0)switch(_.key){case"Escape":_.preventDefault(),c();return;case"ArrowDown":_.preventDefault(),l(f=>(f+1)%e);return;case"ArrowUp":_.preventDefault(),l(f=>(f-1+e)%e);return;case"Home":_.preventDefault(),l(0);return;case"End":_.preventDefault(),l(e-1)}},[e,c]);return{open:n,focusIndex:s,triggerRef:i,menuRef:a,toggle:u,close:c,onTriggerKey:p,onMenuKey:d}}function ka({items:e,triggerLabel:t}){let n=v.cssPrefix,o=wa({itemCount:e.length}),i=a=>{a.disabled||(a.onSelect(),a.keepOpen||o.close())};return r("div",{class:`${n}-menu-wrap`,children:[r("button",{ref:o.triggerRef,type:"button",class:`${n}-icon-btn`,"aria-label":t,"aria-haspopup":"menu","aria-expanded":o.open,title:t,onClick:o.toggle,onKeyDown:o.onTriggerKey,children:r(ea,{})}),o.open?r("div",{ref:o.menuRef,class:`${n}-menu`,role:"menu","aria-label":t,onKeyDown:o.onMenuKey,tabIndex:-1,children:e.map(a=>r("button",{type:"button",role:"menuitem",class:`${n}-menu-item`,"aria-pressed":a.type==="switch"?a.on:void 0,disabled:a.disabled,lang:a.lang,onClick:()=>i(a),children:[a.icon?r("span",{class:`${n}-menu-icon`,children:a.icon}):null,r("span",{class:`${n}-menu-label`,children:a.label}),a.type==="switch"&&a.on?r("span",{class:`${n}-menu-check`,"aria-hidden":"true",children:r(oa,{})}):null]},a.id))}):null]})}var Fo=v.cssPrefix,_d={auto:"dark",dark:"light",light:"auto"};function ud(e){return e==="light"?r(_a,{}):e==="dark"?r(ua,{}):r(pa,{})}function Ce({panelProps:e,variant:t}){let{options:n,panelSize:o,feedback:i,onClose:a,onClear:s,onExpand:l,onFullscreen:c,onPopOut:u,onSoundToggle:p}=e,{onToggleHistory:d,onLocaleChange:_,onThemeChange:f}=e,m=n.strings,h=n.mode,P=t==="chat",b=Se(()=>i.mutedSig.value).value,S=new Set([...n.actions.main,...n.actions.overflow]),I=R=>S.has(R),j=R=>kt(R,h,o,{popOutUrl:n.popOutUrl}),U=n.themeMode,oe={auto:m.themeAuto,light:m.themeLight,dark:m.themeDark},O=[];if(I("theme")&&O.push({id:"theme",icon:ud(U),label:`${m.theme}: ${oe[U]}`,onSelect:()=>f(_d[U]),keepOpen:!0}),I("language")&&n.availableLocales.length>1)for(let R of n.availableLocales)O.push({id:`language:${R}`,label:`${m.language} \u2014 ${R}`,lang:R,type:"switch",on:R===n.locale,onSelect:()=>_(R)});if(I("expand")&&j("expand")){let R=o==="expanded";O.push({id:"expand",icon:R?r(Yi,{}):r(ji,{}),label:R?m.collapse:m.expand,type:"switch",on:R,onSelect:l})}if(I("fullscreen")&&j("fullscreen")){let R=o==="fullscreen";O.push({id:"fullscreen",icon:R?r(Qi,{}):r(Ji,{}),label:R?m.exitFullscreen:m.fullscreen,type:"switch",on:R,onSelect:c})}I("popOut")&&j("popOut")&&O.push({id:"popOut",icon:r(ia,{}),label:m.popOut,onSelect:u}),P&&I("sound")&&O.push({id:"sound",icon:b?r(na,{}):r(ta,{}),label:b?m.soundOff:m.soundOn,type:"switch",on:!b,onSelect:p}),P&&I("clear")&&O.push({id:"clear",icon:r(aa,{}),label:m.newConversation,onSelect:s});let le=!!a&&kn(h,o,n.actions),B=P&&I("history");return r("div",{class:`${Fo}-header-actions`,children:[B?r("button",{type:"button",class:`${Fo}-icon-btn`,onClick:d,"aria-label":m.history,title:m.history,"data-testid":y.actionHistory,children:r(ra,{})}):null,O.length>0?r(ka,{items:O,triggerLabel:m.moreActions}):null,le?r("button",{type:"button",class:`${Fo}-icon-btn`,onClick:a,"aria-label":m.close,title:m.close,"data-testid":y.actionClose,children:r(Ee,{})}):null]})}var Ko=1,Ca=2,Aa=4,Ta=8,Ia=16;function pd(e){switch(e){case Ko:return"href";case Ca:return"src";case Aa:return"class";case Ta:return"checked";case Ia:return"start"}}var fd=e=>{switch(e){case 1:return 3;case 2:return 4;case 3:return 5;case 4:return 6;case 5:return 7;default:return 8}},gd=fd;var Ea=24;function qo(e){let t=new Uint32Array(Ea);return t[0]=1,{renderer:e,text:"",pending:"",tokens:t,len:0,token:1,fence_end:0,blockquote_idx:0,hr_char:"",hr_chars:0,fence_start:0,spaces:new Uint8Array(Ea),indent:"",indent_len:0,table_state:0}}function Ra(e){e.pending.length>0&&se(e,`
12
12
  `)}function $(e){e.text.length!==0&&(console.assert(e.len>0,"Never adding text to root"),e.renderer.add_text(e.renderer.data,e.text),e.text="")}function Z(e){console.assert(e.len>0,"No nodes to end"),e.len-=1,e.token=e.tokens[e.len],e.renderer.end_token(e.renderer.data)}function G(e,t){(e.tokens[e.len]===24||e.tokens[e.len]===23)&&t!==25&&Z(e),e.len+=1,e.tokens[e.len]=t,e.token=t,e.renderer.add_token(e.renderer.data,t)}function md(e,t,n){for(;n<=e.len;){if(e.tokens[n]===t)return n;n+=1}return-1}function qe(e,t){for(e.fence_start=0;e.len>t;)Z(e)}function In(e,t){let n=0;for(let o=0;o<=e.len&&(t-=e.spaces[o],!(t<0));o+=1)switch(e.tokens[o]){case 9:case 10:case 20:case 25:n=o;break}for(;e.len>n;)Z(e);return t}function Wo(e,t){let n=-1,o=-1;for(let i=e.blockquote_idx+1;i<=e.len;i+=1)if(e.tokens[i]===25){if(e.indent_len<e.spaces[i]){o=-1;break}o=i}else e.tokens[i]===t&&(n=i);return o===-1?n===-1?(qe(e,e.blockquote_idx),G(e,t),!0):(qe(e,n),!1):(qe(e,o),G(e,t),!0)}function Go(e,t){G(e,25),e.spaces[e.len]=e.indent_len+t,Me(e),e.token=103}function Me(e){e.indent="",e.indent_len=0,e.pending=""}function Vo(e){switch(e){case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return!0;default:return!1}}function hd(e){switch(e){case 32:case 58:case 59:case 41:case 44:case 33:case 46:case 63:case 93:case 10:return!0;default:return!1}}function vd(e){return Vo(e)||hd(e)}function se(e,t){for(let n of t){if(e.token===101){switch(n){case" ":e.indent_len+=1;continue;case" ":e.indent_len+=4;continue}let i=In(e,e.indent_len);e.indent_len=0,e.token=e.tokens[e.len],i>0&&se(e," ".repeat(i))}let o=e.pending+n;switch(e.token){case 21:case 1:case 20:case 24:case 23:switch(console.assert(e.text.length===0,"Root should not have any text"),e.pending[0]){case void 0:e.pending=n;continue;case" ":console.assert(e.pending.length===1),e.pending=n,e.indent+=" ",e.indent_len+=1;continue;case" ":console.assert(e.pending.length===1),e.pending=n,e.indent+=" ",e.indent_len+=4;continue;case`
13
13
  `:if(console.assert(e.pending.length===1),e.tokens[e.len]===25&&e.token===21){Z(e),Me(e),e.pending=n;continue}qe(e,e.blockquote_idx),Me(e),e.blockquote_idx=0,e.fence_start=0,e.pending=n;continue;case"#":switch(n){case"#":if(e.pending.length<6){e.pending=o;continue}break;case" ":In(e,e.indent_len),G(e,gd(e.pending.length)),Me(e);continue}break;case">":{let a=md(e,20,e.blockquote_idx+1);a===-1?(qe(e,e.blockquote_idx),e.blockquote_idx+=1,e.fence_start=0,G(e,20)):e.blockquote_idx=a,Me(e),e.pending=n;continue}case"-":case"*":case"_":if(e.hr_chars===0&&(console.assert(e.pending.length===1,"Pending should be one character"),e.hr_chars=1,e.hr_char=e.pending),e.hr_chars>0){switch(n){case e.hr_char:e.hr_chars+=1,e.pending=o;continue;case" ":e.pending=o;continue;case`
14
14
  `:if(e.hr_chars<3)break;In(e,e.indent_len),e.renderer.add_token(e.renderer.data,22),e.renderer.end_token(e.renderer.data),Me(e),e.hr_chars=0;continue}e.hr_chars=0}if(e.pending[0]!=="_"&&e.pending[1]===" "){Wo(e,23),Go(e,2),se(e,o.slice(2));continue}break;case"`":if(e.pending.length<3){if(n==="`"){e.pending=o,e.fence_start=o.length;continue}e.fence_start=0;break}switch(n){case"`":e.pending.length===e.fence_start?(e.pending=o,e.fence_start=o.length):(G(e,2),Me(e),e.fence_start=0,se(e,o));continue;case`