@namiruai/chat 1.8.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- function he(){return{state:"idle",messages:[],isOpen:!1,isLoading:!1,streamingContent:"",qualification:null,feedbackGiven:!1,sessionId:null,error:null}}function je(n,e){switch(e.type){case"SET_STATE":return{...n,state:e.state,error:null};case"SET_OPEN":return{...n,isOpen:e.isOpen};case"SET_LOADING":return{...n,isLoading:e.isLoading};case"ADD_MESSAGE":return{...n,messages:[...n.messages,e.message]};case"APPEND_STREAMING":return{...n,streamingContent:n.streamingContent+e.token};case"CLEAR_STREAMING":return{...n,streamingContent:""};case"SET_QUALIFICATION":return{...n,qualification:e.qualification};case"SET_FEEDBACK_GIVEN":return{...n,feedbackGiven:!0};case"SET_SESSION_ID":return{...n,sessionId:e.sessionId};case"SET_ERROR":return{...n,error:e.error,state:e.error?"error":n.state};case"RESET":return he();default:return n}}var Y=class{constructor(){this.subscribers=new Set;this.state=he()}getState(){return this.state}dispatch(e){let t=this.state;this.state=je(t,e),this.state!==t&&this.notify()}subscribe(e){return this.subscribers.add(e),()=>{this.subscribers.delete(e)}}notify(){let e=this.state;this.subscribers.forEach(t=>{try{t(e)}catch(a){console.error("NamiruChat: error in store subscriber",a)}})}};var J=class{constructor(e){this.baseUrl=e.baseUrl.replace(/\/$/,"")}async fetchBranding(e){let t=await fetch(`${this.baseUrl}/api/public/agents/${encodeURIComponent(e)}/branding`);if(!t.ok)throw new Error(`Failed to fetch agent branding: ${t.status}`);let a=await t.json(),i=a.branding||{};function r(o,s){return typeof o=="string"&&/^#[0-9a-fA-F]{3,8}$/.test(o)?o:s}let l=[];if(Array.isArray(i.suggestedQuestions))l=i.suggestedQuestions;else if(typeof i.suggestedQuestions=="string")try{let o=JSON.parse(i.suggestedQuestions);Array.isArray(o)&&(l=o)}catch{}return{agentId:a.id,name:i.agentDisplayName||a.name,primaryColor:r(i.primaryColor,"#1f2937"),accentColor:r(i.accentColor,"#21DFFB"),logoUrl:i.agentAvatar||i.logoUrl||void 0,agentAvatar:i.agentAvatar||i.logoUrl||void 0,welcomeMessage:i.welcomeMessage||void 0,showPoweredBy:i.showPoweredBy??!0,showHeader:i.showHeader??!0,headerColor:r(i.headerColor,"")||void 0,headerTitle:i.headerTitle||void 0,headerSubtitle:i.headerSubtitle||void 0,presetTheme:i.presetTheme||"light",backgroundColor:r(i.backgroundColor,"")||void 0,textColor:r(i.textColor,"")||void 0,bubbleStyle:i.bubbleStyle||"modern",fontFamily:i.fontFamily||"system",fontSize:i.fontSize||"medium",userMessageColor:i.userMessageColor===""?"":r(i.userMessageColor,"")||void 0,agentMessageColor:i.agentMessageColor===""?"":r(i.agentMessageColor,"")||void 0,iconColor:r(i.iconColor,"")||void 0,borderColor:r(i.borderColor,"")||void 0,inputColor:r(i.inputColor,"")||void 0,buttonColor:r(i.buttonColor,"")||void 0,bubbleGreeting:i.bubbleGreeting||void 0,suggestedQuestions:l,preChatConfig:a.preChatConfig?{enabled:a.preChatConfig.enabled,template:a.preChatConfig.template,custom:a.preChatConfig.template==="custom"&&a.preChatConfig.customQuestion?{question:a.preChatConfig.customQuestion,options:a.preChatConfig.customOptions||[]}:void 0}:void 0,feedbackConfig:a.feedbackConfig??void 0,escalationConfig:a.escalationConfig?{enabled:a.escalationConfig.emailFallbackEnabled||a.escalationConfig.liveChatEnabled||!1,emailFallbackEnabled:a.escalationConfig.emailFallbackEnabled,customReplyMessage:a.escalationConfig.customReplyMessage,liveChatEnabled:a.escalationConfig.liveChatEnabled}:void 0,allowedDomains:Array.isArray(a.allowedDomains)?a.allowedDomains:void 0,excludedRoutes:Array.isArray(a.excludedRoutes)?a.excludedRoutes:void 0}}async submitFeedback(e,t){let a=await fetch(`${this.baseUrl}/api/public/agents/${encodeURIComponent(e)}/feedback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!a.ok)throw new Error(`Failed to submit feedback: ${a.status}`)}async submitEscalation(e,t){let a=await fetch(`${this.baseUrl}/api/public/agents/${encodeURIComponent(e)}/escalate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!a.ok)throw new Error(`Failed to submit escalation: ${a.status}`)}async requestTranscript(e,t,a){let i=await fetch(`${this.baseUrl}/api/public/agents/${encodeURIComponent(e)}/sessions/${encodeURIComponent(t)}/transcript`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!i.ok)throw new Error(`Failed to request transcript: ${i.status}`);return i.json()}async submitLimitMessage(e){let t=await fetch(`${this.baseUrl}/api/leads/limit-message`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw new Error(`Failed to submit limit message: ${t.status}`);return t.json()}async submitContactMessage(e,t){let a=await fetch(`${this.baseUrl}/api/public/agents/${encodeURIComponent(e)}/contact`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!a.ok)throw new Error(`Failed to submit contact message: ${a.status}`);return a.json()}async submitLead(e){let t=await fetch(`${this.baseUrl}/api/leads`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw new Error(`Failed to submit lead: ${t.status}`);return t.json()}};var K=class{constructor(e){this.ws=null;this.listeners=new Map;this.reconnectAttempts=0;this.isDestroyed=!1;this.isInitialized=!1;this.config=e,this.maxReconnectAttempts=e.maxReconnectAttempts??3}connect(){if(!this.isDestroyed)try{this.ws=new WebSocket(this.config.url),this.ws.onopen=this.handleOpen.bind(this),this.ws.onmessage=this.handleMessage.bind(this),this.ws.onclose=this.handleClose.bind(this),this.ws.onerror=this.handleError.bind(this)}catch(e){this.emit("error",{message:e instanceof Error?e.message:"WebSocket connection failed"})}}disconnect(){this.isDestroyed=!0,this.ws&&(this.ws.onclose=null,this.ws.close(),this.ws=null)}sendMessage(e){this.send({type:"message",content:e})}sendHandoffComplete(e){this.send({type:"handoff_complete",...e})}sendEscalationEmail(e){this.send({type:"escalation_email",email:e})}on(e,t){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),()=>{this.listeners.get(e)?.delete(t)}}send(e){this.ws&&this.ws.readyState===WebSocket.OPEN&&this.ws.send(JSON.stringify(e))}emit(e,t={}){let a={type:e,data:t};this.listeners.get(e)?.forEach(i=>{try{i(a)}catch(r){console.error(`NamiruChat: error in ${e} handler`,r)}})}handleOpen(){this.reconnectAttempts=0,this.emit("connected",{}),this.isInitialized||this.send({type:"init_agent",agentId:this.config.agentId,token:this.config.token||"",visitorId:this.config.visitorId||""})}handleMessage(e){let t;try{t=JSON.parse(e.data)}catch{return}switch(t.type){case"agent_initialized":this.isInitialized=!0,this.emit("agent_initialized",t);break;case"stream_token":this.emit("stream_token",t);break;case"final_response":this.emit("final_response",t);break;case"stream_end":this.emit("stream_end",t);break;case"tool_start":this.emit("tool_start",t);break;case"tool_end":this.handleToolEnd(t);break;case"usage_limit":this.emit("usage_limit",t),this.emit("error",{...t,usage_limit:!0});break;case"show_handoff_form":this.emit("show_handoff_form",t);break;case"handoff_active":this.emit("handoff_active",t);break;case"error":this.emit("error",t);break;case"status":this.emit("status",t);break;default:break}}handleToolEnd(e){if(this.emit("tool_end",e),e.output)try{let t=typeof e.output=="string"?JSON.parse(e.output):e.output;t.kitTrigger&&this.emit("kit_trigger",t.kitTrigger)}catch{}}handleClose(e){if(e.code===1008){this.isDestroyed=!0,this.emit("disconnected",{code:e.code,reason:e.reason,permanent:!0});return}if(this.emit("disconnected",{code:e.code,reason:e.reason}),!this.isDestroyed&&this.reconnectAttempts<this.maxReconnectAttempts){this.reconnectAttempts++;let t=1e3*Math.pow(2,this.reconnectAttempts-1);setTimeout(()=>this.connect(),t)}}handleError(){this.emit("error",{message:"WebSocket connection error"})}};var X=class{constructor(e,t){this.timerId=null;this.minutes=e,this.callback=t}reset(){this.stop(),this.timerId=setTimeout(()=>{this.callback()},this.minutes*60*1e3)}stop(){this.timerId!==null&&(clearTimeout(this.timerId),this.timerId=null)}updateMinutes(e){this.minutes=e,this.timerId!==null&&this.reset()}};var V=!1;function fe(n){V=n}var te=null;function xe(n,e,t){let a=typeof n=="string"?{primaryColor:n}:n,i=document.createElement("style");i.setAttribute("data-namiru","true"),i.textContent=Je(a,t),e instanceof ShadowRoot||e.shadowRoot?e.appendChild(i):document.head.appendChild(i),te=i}function ye(){te&&(te.remove(),te=null)}function Qe(n){return!n||n==="system"?'"Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif':n==="modern"?'"Inter", sans-serif':n==="classic"?'"Georgia", serif':n}function Ye(n){return n==="small"?"13px":n==="large"?"17px":"15px"}function ee(n){let e=n.replace("#","");if(e.length===3&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),e.length<6||!/^[0-9a-fA-F]{6}/.test(e))return!1;let t=parseInt(e.substring(0,2),16),a=parseInt(e.substring(2,4),16),i=parseInt(e.substring(4,6),16);return(t*299+a*587+i*114)/1e3>150}function Je(n,e){let t=e?" !important":"",a=n.primaryColor,i=n.accentColor||"#21DFFB",r=Qe(n.fontFamily),l=Ye(n.fontSize),o=n.presetTheme==="dark",s=n.backgroundColor||(o?"#0f0f1a":"#ffffff"),c=n.textColor||(o?"#ffffff":"#1f2937"),d=!ee(s),p=n.borderColor||(d?"rgba(255,255,255,0.15)":"rgba(0,0,0,0.1)"),k=n.inputColor||(d?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.02)"),h=d?"rgba(255,255,255,0.6)":"rgba(0,0,0,0.45)",C=d?"rgba(255,255,255,0.2)":"rgba(0,0,0,0.12)",E=n.headerColor||s,f=n.headerColor?ee(E)?"#1f2937":"#ffffff":c,x=n.headerColor?ee(E)?"rgba(0,0,0,0.5)":"rgba(255,255,255,0.7)":h,N=n.buttonColor||(d?"#0f0f1a":a),y=be(N,-15),T=n.userMessageColor!==void 0?n.userMessageColor||"transparent":a,G=T==="transparent"?c:ee(T)?"#1f2937":"#ffffff";return`
1
+ function he(){return{state:"idle",messages:[],isOpen:!1,isLoading:!1,streamingContent:"",qualification:null,feedbackGiven:!1,sessionId:null,error:null}}function Qe(n,e){switch(e.type){case"SET_STATE":return{...n,state:e.state,error:null};case"SET_OPEN":return{...n,isOpen:e.isOpen};case"SET_LOADING":return{...n,isLoading:e.isLoading};case"ADD_MESSAGE":return{...n,messages:[...n.messages,e.message]};case"APPEND_STREAMING":return{...n,streamingContent:n.streamingContent+e.token};case"CLEAR_STREAMING":return{...n,streamingContent:""};case"SET_QUALIFICATION":return{...n,qualification:e.qualification};case"SET_FEEDBACK_GIVEN":return{...n,feedbackGiven:!0};case"SET_SESSION_ID":return{...n,sessionId:e.sessionId};case"SET_ERROR":return{...n,error:e.error,state:e.error?"error":n.state};case"RESET":return he();default:return n}}var Y=class{constructor(){this.subscribers=new Set;this.state=he()}getState(){return this.state}dispatch(e){let t=this.state;this.state=Qe(t,e),this.state!==t&&this.notify()}subscribe(e){return this.subscribers.add(e),()=>{this.subscribers.delete(e)}}notify(){let e=this.state;this.subscribers.forEach(t=>{try{t(e)}catch(a){console.error("NamiruChat: error in store subscriber",a)}})}};var J=class{constructor(e){this.baseUrl=e.baseUrl.replace(/\/$/,"")}async fetchBranding(e){let t=await fetch(`${this.baseUrl}/api/public/agents/${encodeURIComponent(e)}/branding`);if(!t.ok)throw new Error(`Failed to fetch agent branding: ${t.status}`);let a=await t.json(),i=a.branding||{};function r(o,s){return typeof o=="string"&&/^#[0-9a-fA-F]{3,8}$/.test(o)?o:s}let l=[];if(Array.isArray(i.suggestedQuestions))l=i.suggestedQuestions;else if(typeof i.suggestedQuestions=="string")try{let o=JSON.parse(i.suggestedQuestions);Array.isArray(o)&&(l=o)}catch{}return{agentId:a.id,name:i.agentDisplayName||a.name,primaryColor:r(i.primaryColor,"#1f2937"),accentColor:r(i.accentColor,"#21DFFB"),logoUrl:i.agentAvatar||i.logoUrl||void 0,agentAvatar:i.agentAvatar||i.logoUrl||void 0,welcomeMessage:i.welcomeMessage||void 0,showPoweredBy:i.showPoweredBy??!0,showHeader:i.showHeader??!0,headerColor:r(i.headerColor,"")||void 0,headerTitle:i.headerTitle||void 0,headerSubtitle:i.headerSubtitle||void 0,presetTheme:i.presetTheme||"light",backgroundColor:r(i.backgroundColor,"")||void 0,textColor:r(i.textColor,"")||void 0,bubbleStyle:i.bubbleStyle||"modern",fontFamily:i.fontFamily||"system",fontSize:i.fontSize||"medium",userMessageColor:i.userMessageColor===""?"":r(i.userMessageColor,"")||void 0,agentMessageColor:i.agentMessageColor===""?"":r(i.agentMessageColor,"")||void 0,iconColor:r(i.iconColor,"")||void 0,borderColor:r(i.borderColor,"")||void 0,inputColor:r(i.inputColor,"")||void 0,buttonColor:r(i.buttonColor,"")||void 0,bubbleGreeting:i.bubbleGreeting||void 0,suggestedQuestions:l,preChatConfig:a.preChatConfig?{enabled:a.preChatConfig.enabled,template:a.preChatConfig.template,custom:a.preChatConfig.template==="custom"&&a.preChatConfig.customQuestion?{question:a.preChatConfig.customQuestion,options:a.preChatConfig.customOptions||[]}:void 0}:void 0,feedbackConfig:a.feedbackConfig??void 0,escalationConfig:a.escalationConfig?{enabled:a.escalationConfig.emailFallbackEnabled||a.escalationConfig.liveChatEnabled||!1,emailFallbackEnabled:a.escalationConfig.emailFallbackEnabled,customReplyMessage:a.escalationConfig.customReplyMessage,liveChatEnabled:a.escalationConfig.liveChatEnabled}:void 0,allowedDomains:Array.isArray(a.allowedDomains)?a.allowedDomains:void 0,excludedRoutes:Array.isArray(a.excludedRoutes)?a.excludedRoutes:void 0}}async submitFeedback(e,t){let a=await fetch(`${this.baseUrl}/api/public/agents/${encodeURIComponent(e)}/feedback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!a.ok)throw new Error(`Failed to submit feedback: ${a.status}`)}async submitEscalation(e,t){let a=await fetch(`${this.baseUrl}/api/public/agents/${encodeURIComponent(e)}/escalate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!a.ok)throw new Error(`Failed to submit escalation: ${a.status}`)}async requestTranscript(e,t,a){let i=await fetch(`${this.baseUrl}/api/public/agents/${encodeURIComponent(e)}/sessions/${encodeURIComponent(t)}/transcript`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!i.ok)throw new Error(`Failed to request transcript: ${i.status}`);return i.json()}async submitLimitMessage(e){let t=await fetch(`${this.baseUrl}/api/leads/limit-message`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw new Error(`Failed to submit limit message: ${t.status}`);return t.json()}async submitContactMessage(e,t){let a=await fetch(`${this.baseUrl}/api/public/agents/${encodeURIComponent(e)}/contact`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!a.ok)throw new Error(`Failed to submit contact message: ${a.status}`);return a.json()}async submitLead(e){let t=await fetch(`${this.baseUrl}/api/leads`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw new Error(`Failed to submit lead: ${t.status}`);return t.json()}};var K=class{constructor(e){this.ws=null;this.listeners=new Map;this.reconnectAttempts=0;this.isDestroyed=!1;this.isInitialized=!1;this.config=e,this.maxReconnectAttempts=e.maxReconnectAttempts??3}connect(){if(!this.isDestroyed)try{this.ws=new WebSocket(this.config.url),this.ws.onopen=this.handleOpen.bind(this),this.ws.onmessage=this.handleMessage.bind(this),this.ws.onclose=this.handleClose.bind(this),this.ws.onerror=this.handleError.bind(this)}catch(e){this.emit("error",{message:e instanceof Error?e.message:"WebSocket connection failed"})}}disconnect(){this.isDestroyed=!0,this.ws&&(this.ws.onclose=null,this.ws.close(),this.ws=null)}sendMessage(e){this.send({type:"message",content:e})}sendHandoffComplete(e){this.send({type:"handoff_complete",...e})}sendEscalationEmail(e){this.send({type:"escalation_email",email:e})}on(e,t){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),()=>{this.listeners.get(e)?.delete(t)}}send(e){this.ws&&this.ws.readyState===WebSocket.OPEN&&this.ws.send(JSON.stringify(e))}emit(e,t={}){let a={type:e,data:t};this.listeners.get(e)?.forEach(i=>{try{i(a)}catch(r){console.error(`NamiruChat: error in ${e} handler`,r)}})}handleOpen(){this.reconnectAttempts=0,this.emit("connected",{}),this.isInitialized||this.send({type:"init_agent",agentId:this.config.agentId,token:this.config.token||"",visitorId:this.config.visitorId||""})}handleMessage(e){let t;try{t=JSON.parse(e.data)}catch{return}switch(t.type){case"agent_initialized":this.isInitialized=!0,this.emit("agent_initialized",t);break;case"stream_token":this.emit("stream_token",t);break;case"final_response":this.emit("final_response",t);break;case"stream_end":this.emit("stream_end",t);break;case"tool_start":this.emit("tool_start",t);break;case"tool_end":this.handleToolEnd(t);break;case"usage_limit":this.emit("usage_limit",t),this.emit("error",{...t,usage_limit:!0});break;case"show_handoff_form":this.emit("show_handoff_form",t);break;case"handoff_active":this.emit("handoff_active",t);break;case"error":this.emit("error",t);break;case"status":this.emit("status",t);break;default:break}}handleToolEnd(e){if(this.emit("tool_end",e),e.output)try{let t=typeof e.output=="string"?JSON.parse(e.output):e.output;t.kitTrigger&&this.emit("kit_trigger",t.kitTrigger)}catch{}}handleClose(e){if(e.code===1008){this.isDestroyed=!0,this.emit("disconnected",{code:e.code,reason:e.reason,permanent:!0});return}if(this.emit("disconnected",{code:e.code,reason:e.reason}),!this.isDestroyed&&this.reconnectAttempts<this.maxReconnectAttempts){this.reconnectAttempts++;let t=1e3*Math.pow(2,this.reconnectAttempts-1);setTimeout(()=>this.connect(),t)}}handleError(){this.emit("error",{message:"WebSocket connection error"})}};var X=class{constructor(e,t){this.timerId=null;this.minutes=e,this.callback=t}reset(){this.stop(),this.timerId=setTimeout(()=>{this.callback()},this.minutes*60*1e3)}stop(){this.timerId!==null&&(clearTimeout(this.timerId),this.timerId=null)}updateMinutes(e){this.minutes=e,this.timerId!==null&&this.reset()}};var V=!1;function fe(n){V=n}var te=null;function xe(n,e,t){let a=typeof n=="string"?{primaryColor:n}:n,i=document.createElement("style");i.setAttribute("data-namiru","true"),i.textContent=Ke(a,t),e instanceof ShadowRoot||e.shadowRoot?e.appendChild(i):document.head.appendChild(i),te=i}function ye(){te&&(te.remove(),te=null)}function Ye(n){return!n||n==="system"?'"Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif':n==="modern"?'"Inter", sans-serif':n==="classic"?'"Georgia", serif':n}function Je(n){return n==="small"?"13px":n==="large"?"17px":"15px"}function ee(n){let e=n.replace("#","");if(e.length===3&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),e.length<6||!/^[0-9a-fA-F]{6}/.test(e))return!1;let t=parseInt(e.substring(0,2),16),a=parseInt(e.substring(2,4),16),i=parseInt(e.substring(4,6),16);return(t*299+a*587+i*114)/1e3>150}function Ke(n,e){let t=e?" !important":"",a=n.primaryColor,i=n.accentColor||"#21DFFB",r=Ye(n.fontFamily),l=Je(n.fontSize),o=n.presetTheme==="dark",s=n.backgroundColor||(o?"#0f0f1a":"#ffffff"),c=n.textColor||(o?"#ffffff":"#1f2937"),d=!ee(s),p=n.borderColor||(d?"rgba(255,255,255,0.15)":"rgba(0,0,0,0.1)"),k=n.inputColor||(d?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.02)"),h=d?"rgba(255,255,255,0.6)":"rgba(0,0,0,0.45)",C=d?"rgba(255,255,255,0.2)":"rgba(0,0,0,0.12)",E=n.headerColor||s,f=n.headerColor?ee(E)?"#1f2937":"#ffffff":c,x=n.headerColor?ee(E)?"rgba(0,0,0,0.5)":"rgba(255,255,255,0.7)":h,N=n.buttonColor||(d?"#0f0f1a":a),y=be(N,-15),T=n.userMessageColor!==void 0?n.userMessageColor||"transparent":a,G=T==="transparent"?c:ee(T)?"#1f2937":"#ffffff";return`
2
2
  /* Namiru Chat Widget Styles */
3
3
  .namiru-widget-root {
4
4
  --namiru-primary: ${a};
@@ -1069,24 +1069,24 @@ function he(){return{state:"idle",messages:[],isOpen:!1,isLoading:!1,streamingCo
1069
1069
  border-top: 1px solid rgba(0,0,0,0.1);
1070
1070
  margin: 0.6em 0;
1071
1071
  }
1072
- `}function be(n,e){let t=n.replace("#",""),a=parseInt(t,16);if(isNaN(a)||t.length<6)return n;let i=Math.max(0,Math.min(255,(a>>16&255)+e)),r=Math.max(0,Math.min(255,(a>>8&255)+e)),l=Math.max(0,Math.min(255,(a&255)+e));return`#${(i<<16|r<<8|l).toString(16).padStart(6,"0")}`}function Ke(n){return n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function ne(n){let e=Ke(n);e=e.replace(/\u2014/g,", "),e=e.replace(/```(?:\w*)\n([\s\S]*?)```/g,'<pre class="namiru-md-pre"><code>$1</code></pre>'),e=e.replace(/`([^`\n]+)`/g,'<code class="namiru-md-code">$1</code>'),e=e.replace(/\*\*\*(.+?)\*\*\*/g,"<strong><em>$1</em></strong>"),e=e.replace(/\*\*(.+?)\*\*/g,"<strong>$1</strong>"),e=e.replace(/__(.+?)__/g,"<strong>$1</strong>"),e=e.replace(/\*(.+?)\*/g,"<em>$1</em>"),e=e.replace(/(^|[\s(])_(.+?)_([\s).,!?]|$)/gm,"$1<em>$2</em>$3"),e=e.replace(/\[([^\]]+)\]\(([^)]+)\)/g,'<a href="$2" target="_blank" rel="noopener noreferrer" class="namiru-md-link">$1</a>'),e=e.replace(/^[ \t]*([-*_])\s*\1\s*\1[\s\-*_]*$/gm,'<hr class="namiru-md-hr">');let t=e.split(`
1073
- `),a=[],i=!1,r=!1;for(let c=0;c<t.length;c++){let d=t[c];if(d.includes('<hr class="namiru-md-hr">')){i&&(a.push("</ul>"),i=!1),r&&(a.push("</ol>"),r=!1),a.push(d);continue}let p=d.match(/^(\s*)[-*]\s+(.*)/),k=d.match(/^(\s*)\d+\.\s+(.*)/);p?(i||(r&&(a.push("</ol>"),r=!1),a.push('<ul class="namiru-md-ul">'),i=!0),a.push(`<li>${p[2]}</li>`)):k?(r||(i&&(a.push("</ul>"),i=!1),a.push('<ol class="namiru-md-ol">'),r=!0),a.push(`<li>${k[2]}</li>`)):(i&&(a.push("</ul>"),i=!1),r&&(a.push("</ol>"),r=!1),d.trim()===""?a.push(""):a.push(d))}i&&a.push("</ul>"),r&&a.push("</ol>");let l="",o=!1;for(let c of a)c.includes("<hr")?l+=c:c.startsWith("<ul")||c.startsWith("<ol")?(o=!0,l+=c):c==="</ul>"||c==="</ol>"?(o=!1,l+=c):c.startsWith("<li>")?l+=c:c.trim()===""?o||(l+="</p><p>"):(l.length>0&&!o&&!l.endsWith("<p>")&&!l.endsWith("</ul>")&&!l.endsWith("</ol>")&&!l.endsWith("</pre>")&&(l+="<br>"),l+=c);!l.startsWith("<ul")&&!l.startsWith("<ol")&&!l.startsWith("<pre")&&(l=`<p>${l}</p>`),l=l.replace(/<p>\s*<\/p>/g,""),l=l.replace(/<p>(<(?:ul|ol|pre|hr)[^>]*>)/g,"$1"),l=l.replace(/(<\/(?:ul|ol|pre)>)<\/p>/g,"$1"),l=l.replace(/(<hr[^>]*>)<\/p>/g,"$1");let s=V?"":" !important";return l=l.replace(/<p>/g,`<p style="color: var(--namiru-text)${s}; margin: 0 0 0.5em 0${s}; max-width: 100%${s}; word-wrap: break-word${s}; display: block${s}; visibility: visible${s};">`),l=l.replace(/<li>/g,`<li style="color: var(--namiru-text)${s}; margin: 0.2em 0${s}; display: list-item${s}; visibility: visible${s};">`),l=l.replace(/<strong>/g,`<strong style="color: var(--namiru-text)${s}; font-weight: 700${s}; display: inline${s}; visibility: visible${s}; font-size: inherit${s}; opacity: 1${s};">`),l=l.replace(/<em>/g,`<em style="color: var(--namiru-text)${s}; font-style: italic${s}; display: inline${s}; visibility: visible${s}; font-size: inherit${s}; opacity: 1${s};">`),l=l.replace(/<a href=/g,`<a style="color: var(--namiru-primary)${s}; text-decoration: underline${s}; display: inline${s}; visibility: visible${s};" href=`),l}function I(n,e="0 0 256 256"){let t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("viewBox",e),t.setAttribute("fill","currentColor"),t.setAttribute("xmlns","http://www.w3.org/2000/svg");for(let a of n){let i=document.createElementNS("http://www.w3.org/2000/svg","path");i.setAttribute("d",a),t.appendChild(i)}return t}function ve(n){let e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 256 256"),e.setAttribute("xmlns","http://www.w3.org/2000/svg"),e.setAttribute("width","18"),e.setAttribute("height","18"),n?e.setAttribute("fill",n):e.setAttribute("fill","currentColor");let t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("d","M201.89,54.66A103.43,103.43,0,0,0,128.79,24H128A104,104,0,0,0,24,128v56a24,24,0,0,0,24,24H64a24,24,0,0,0,24-24V144a24,24,0,0,0-24-24H40.36A88,88,0,0,1,128,40h.67a87.71,87.71,0,0,1,87,80H192a24,24,0,0,0-24,24v40a24,24,0,0,0,24,24h8a8,8,0,0,0,0-16h-8a8,8,0,0,1-8-8V144a8,8,0,0,1,8-8h24a8,8,0,0,1,8,8v56a40,40,0,0,1-40,40H152a8,8,0,0,0,0,16h32a56.06,56.06,0,0,0,56-56V128A103.41,103.41,0,0,0,201.89,54.66ZM64,136a8,8,0,0,1,8,8v40a8,8,0,0,1-8,8H48a8,8,0,0,1-8-8V136Z"),e.appendChild(t),e}function Ce(n){let e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 256 256"),e.setAttribute("xmlns","http://www.w3.org/2000/svg"),e.setAttribute("width","20"),e.setAttribute("height","20"),n?e.setAttribute("fill",n):e.setAttribute("fill","currentColor");let t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("d","M201.89,54.66A103.43,103.43,0,0,0,128.79,24H128A104,104,0,0,0,24,128v56a24,24,0,0,0,24,24H64a24,24,0,0,0,24-24V144a24,24,0,0,0-24-24H40.36A88,88,0,0,1,128,40h.67a87.71,87.71,0,0,1,87,80H192a24,24,0,0,0-24,24v40a24,24,0,0,0,24,24h8a8,8,0,0,0,0-16h-8a8,8,0,0,1-8-8V144a8,8,0,0,1,8-8h24a8,8,0,0,1,8,8v56a40,40,0,0,1-40,40H152a8,8,0,0,0,0,16h32a56.06,56.06,0,0,0,56-56V128A103.41,103.41,0,0,0,201.89,54.66ZM64,136a8,8,0,0,1,8,8v40a8,8,0,0,1-8,8H48a8,8,0,0,1-8-8V136Z"),e.appendChild(t),e}function Ee(){return I(["M128,24A104,104,0,0,0,36.18,176.88L24.83,210.93a16,16,0,0,0,20.24,20.24l34.05-11.35A104,104,0,1,0,128,24Zm0,192a88.11,88.11,0,0,1-44.06-11.81,8,8,0,0,0-4-1.08,7.85,7.85,0,0,0-2.53.42L40,216l12.47-37.41a8,8,0,0,0-.66-6.54A88,88,0,1,1,128,216Z"])}function ae(){return I(["M205.66,194.34a8,8,0,0,1-11.32,11.32L128,139.31,61.66,205.66a8,8,0,0,1-11.32-11.32L116.69,128,50.34,61.66A8,8,0,0,1,61.66,50.34L128,116.69l66.34-66.35a8,8,0,0,1,11.32,11.32L139.31,128Z"])}function we(){return I(["M240,127.89a16,16,0,0,1-8.18,14L63.9,237.9A16.15,16.15,0,0,1,56,240a16,16,0,0,1-15-21.33l27-79.95A4,4,0,0,1,71.72,136H144a8,8,0,0,0,8-8.53,8.19,8.19,0,0,0-8.26-7.47h-72a4,4,0,0,1-3.79-2.72l-27-79.94A16,16,0,0,1,63.84,18.07l168,95.89A16,16,0,0,1,240,127.89Z"])}function Se(){return I(["M234,80.12A24,24,0,0,0,216,72H160V56a40,40,0,0,0-40-40,8,8,0,0,0-7.16,4.42L75.06,96H32a16,16,0,0,0-16,16v88a16,16,0,0,0,16,16H204a24,24,0,0,0,23.82-21.12l12-96A24,24,0,0,0,234,80.12ZM32,112H72v88H32ZM223.94,97l-12,96a8,8,0,0,1-7.94,7H88V105.89l36.71-73.43A24,24,0,0,1,144,56V80a8,8,0,0,0,8,8h64a8,8,0,0,1,7.94,9Z"])}function ke(){return I(["M239.82,157l-12-96A24,24,0,0,0,204,40H32A16,16,0,0,0,16,56v88a16,16,0,0,0,16,16H75.06l37.78,75.58A8,8,0,0,0,120,240a40,40,0,0,0,40-40V184h56a24,24,0,0,0,23.82-27ZM72,144H32V56H72Zm150,21.29a8,8,0,0,1-6,2.71H152a8,8,0,0,0-8,8v24a24,24,0,0,1-19.29,23.54L88,150.11V56H204a8,8,0,0,1,7.94,7l12,96A8,8,0,0,1,222,165.29Z"])}function Xe(){return I(["M216,64H176a48,48,0,0,0-96,0H40A16,16,0,0,0,24,80V200a16,16,0,0,0,16,16H216a16,16,0,0,0,16-16V80A16,16,0,0,0,216,64ZM128,32a32,32,0,0,1,32,32H96A32,32,0,0,1,128,32Zm88,168H40V80H80V96a8,8,0,0,0,16,0V80h64V96a8,8,0,0,0,16,0V80h40Z"])}function et(){return I(["M223.68,66.15,135.68,18a15.88,15.88,0,0,0-15.36,0l-88,48.17a16,16,0,0,0-8.32,14v95.64a16,16,0,0,0,8.32,14l88,48.17a15.88,15.88,0,0,0,15.36,0l88-48.17a16,16,0,0,0,8.32-14V80.18A16,16,0,0,0,223.68,66.15ZM128,32l80.34,44-29.77,16.3-80.35-44ZM128,120,47.66,76l33.9-18.56,80.34,44ZM40,90l80,43.78v85.79L40,175.82Zm96,129.57V133.82L216,90v85.78Z"])}function tt(){return I(["M224,48H32A16,16,0,0,0,16,64V192a16,16,0,0,0,16,16H224a16,16,0,0,0,16-16V64A16,16,0,0,0,224,48Zm0,16V88H32V64ZM32,192V104H224v88Zm16-24a8,8,0,0,1,8-8H96a8,8,0,0,1,0,16H56A8,8,0,0,1,48,168Zm0-32a8,8,0,0,1,8-8h64a8,8,0,0,1,0,16H56A8,8,0,0,1,48,136Z"])}function Te(){return I(["M128,24A104,104,0,0,0,36.18,176.88L24.83,210.93a16,16,0,0,0,20.24,20.24l34.05-11.35A104,104,0,1,0,128,24Zm0,192a88.11,88.11,0,0,1-44.06-11.81,8,8,0,0,0-4-1.08,7.85,7.85,0,0,0-2.53.42L40,216l12.47-37.41a8,8,0,0,0-.66-6.54A88,88,0,1,1,128,216Z"])}function nt(){return I(["M152,224a8,8,0,0,1-8,8H112a8,8,0,0,1,0-16h32A8,8,0,0,1,152,224Zm73.69-142.23-21.34-21.35C183.42,39.49,156.58,24,128,24s-55.42,15.49-76.35,36.42L30.31,81.77a16,16,0,0,0,0,22.63L64,138.09V184a16,16,0,0,0,4.69,11.31l24,24A16,16,0,0,0,104,224h48a16,16,0,0,0,11.31-4.69l24-24A16,16,0,0,0,192,184V138.09l33.69-33.69A16,16,0,0,0,225.69,81.77ZM128,40c22.59,0,43.85,12.28,60,32H68C84.15,52.28,105.41,40,128,40Zm48,144-24,24H104L80,184V88H176Zm36.28-79.6L192,172.69V88h17.94l4.34,4.34A.64.64,0,0,1,212.28,104.4ZM64,172.69,45.66,104.4a.64.64,0,0,1-2,0L48,100H64Z"])}function at(){return I(["M226.76,69a8,8,0,0,0-12.84-2.88l-40.3,37.19-17.23-3.7-3.7-17.23,37.19-40.3A8,8,0,0,0,187,29.24,72,72,0,0,0,88,96c0,1.3,0,2.6.1,3.89L33.19,147.68a27.7,27.7,0,0,0,0,39.37l36.76,36.76a27.7,27.7,0,0,0,39.37,0l47.79-54.91c1.29.06,2.59.1,3.89.1a72,72,0,0,0,66.76-99ZM148.49,212.49a11.7,11.7,0,0,1-16.57,0L95.16,175.73a8,8,0,0,0-11.58.28L44.49,220.49a11.7,11.7,0,0,1-16.57,0L44.49,204a11.69,11.69,0,0,1,0-16.57l44.48-39.09a8,8,0,0,0,.28-11.58L52.49,100.05a56,56,0,0,1,89.36-63.58l-31.41,34a8,8,0,0,0-1.8,6.49l6,27.92a8,8,0,0,0,6.13,6.13l27.92,6a8,8,0,0,0,6.49-1.8l34-31.41A56,56,0,0,1,148.49,212.49Z"])}function it(){return I(["M216,56H176V48a24,24,0,0,0-24-24H104A24,24,0,0,0,80,48v8H40A16,16,0,0,0,24,72V200a16,16,0,0,0,16,16H216a16,16,0,0,0,16-16V72A16,16,0,0,0,216,56ZM96,48a8,8,0,0,1,8-8h48a8,8,0,0,1,8,8v8H96ZM216,72v72H40V72Zm0,128H40V160H216v40Z"])}function rt(){return I(["M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24ZM74.08,197.5a64,64,0,0,1,107.84,0,87.83,87.83,0,0,1-107.84,0ZM96,120a32,32,0,1,1,32,32A32,32,0,0,1,96,120Zm97.76,66.41a79.66,79.66,0,0,0-36.06-28.75,48,48,0,1,0-59.4,0,79.66,79.66,0,0,0-36.06,28.75,88,88,0,1,1,131.52,0Z"])}function ot(){return I(["M140,128a12,12,0,1,1-12-12A12,12,0,0,1,140,128Zm56-12a12,12,0,1,0,12,12A12,12,0,0,0,196,116ZM60,116a12,12,0,1,0,12,12A12,12,0,0,0,60,116Z"])}var st={ShoppingBag:Xe,Package:et,CreditCard:tt,ChatCircle:Te,Rocket:nt,Wrench:at,Briefcase:it,UserCircle:rt,DotsThree:ot};function Ae(n){let e=st[n];return e?e():Te()}function lt(n){let e=n.replace("#","");if(e.length===3&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),e.length<6||!/^[0-9a-fA-F]{6}/.test(e))return"74, 127, 255";let t=parseInt(e.substring(0,2),16),a=parseInt(e.substring(2,4),16),i=parseInt(e.substring(4,6),16);return`${t}, ${a}, ${i}`}function Me(n){let{store:e,branding:t,mode:a,onTranscriptClick:i,onNewChat:r,feedbackEnabled:l}=n;if(t.showHeader===!1){let h=document.createElement("div");return h.style.display="none",h}let o=document.createElement("div");o.className="namiru-header";let s=document.createElement("div");s.className="namiru-header-left";let c=lt(t.primaryColor);if(t.agentAvatar||t.logoUrl){let h=document.createElement("img");h.className="namiru-header-avatar",h.src=t.agentAvatar||t.logoUrl,h.alt=t.name,s.appendChild(h)}else{let h=document.createElement("div");h.className="namiru-header-avatar-fallback",h.style.background=`rgba(${c}, 0.06)`,h.style.border="none";let C=t.presetTheme==="dark",E=t.iconColor||(C?"#ffffff":t.primaryColor),f=ve(E);h.appendChild(f),s.appendChild(h)}let d=document.createElement("div");d.className="namiru-header-info";let p=document.createElement("div");if(p.className="namiru-header-name",p.textContent=t.headerTitle||t.name,d.appendChild(p),t.headerSubtitle){let h=document.createElement("div");h.className="namiru-header-subtitle",h.textContent=t.headerSubtitle,d.appendChild(h)}s.appendChild(d),o.appendChild(s);let k=document.createElement("div");if(k.className="namiru-header-actions",a==="button"){let h=document.createElement("button");h.className="namiru-header-btn",h.setAttribute("aria-label","Close chat"),h.appendChild(ae()),h.addEventListener("click",()=>{let C=e.getState();if(l&&!C.feedbackGiven&&C.state==="chatting"&&C.messages.length>0){e.dispatch({type:"SET_STATE",state:"feedback"});return}if(C.messages.length===0){e.dispatch({type:"SET_OPEN",isOpen:!1});return}re(o,e)}),k.appendChild(h)}return o.appendChild(k),o}function re(n,e){let t=n.parentElement;if(!t){e.dispatch({type:"SET_OPEN",isOpen:!1});return}if(t.querySelector(".namiru-close-confirm-overlay"))return;let a=document.createElement("div");a.className="namiru-close-confirm-overlay",a.style.cssText="position:absolute;inset:0;z-index:50;display:flex;align-items:center;justify-content:center;padding:16px;background:rgba(0,0,0,0.35);backdrop-filter:blur(2px);animation:namiruConfirmFade 0.15s ease-out;";let i=document.createElement("div");i.style.cssText="background:var(--namiru-bg,#fff);border-radius:8px;border:1px solid var(--namiru-border,#e5e7eb);box-shadow:0 8px 24px rgba(0,0,0,0.12);padding:20px;width:100%;max-width:280px;animation:namiruConfirmSlide 0.2s cubic-bezier(0.16,1,0.3,1);";let r=document.createElement("div");r.style.cssText="font-size:14px;font-weight:600;color:var(--namiru-text,#1f2937);margin-bottom:4px;",r.textContent="End conversation?",i.appendChild(r);let l=document.createElement("div");l.style.cssText="font-size:13px;color:var(--namiru-text-secondary,#6b7280);line-height:1.4;margin-bottom:16px;",l.textContent="We've received your message. Your chat history will not be saved.",i.appendChild(l);let o=document.createElement("div");o.style.cssText="display:flex;gap:8px;";let s=document.createElement("button");s.style.cssText="flex:1;padding:8px 12px;border-radius:6px;font-size:13px;font-weight:500;cursor:pointer;border:1px solid var(--namiru-border,#e5e7eb);background:var(--namiru-bg,#fff);color:var(--namiru-text,#1f2937);transition:background 0.15s;",s.textContent="Cancel",s.addEventListener("mouseenter",()=>{s.style.background="var(--namiru-bg-secondary,#f3f4f6)"}),s.addEventListener("mouseleave",()=>{s.style.background="var(--namiru-bg,#fff)"}),s.addEventListener("click",()=>a.remove());let c=document.createElement("button");if(c.style.cssText="flex:1;padding:8px 12px;border-radius:6px;font-size:13px;font-weight:500;cursor:pointer;border:none;background:var(--namiru-text,#1f2937);color:var(--namiru-bg,#fff);transition:opacity 0.15s;",c.textContent="End chat",c.addEventListener("mouseenter",()=>{c.style.opacity="0.85"}),c.addEventListener("mouseleave",()=>{c.style.opacity="1"}),c.addEventListener("click",()=>{a.remove(),e.dispatch({type:"RESET"}),e.dispatch({type:"SET_OPEN",isOpen:!1})}),o.appendChild(s),o.appendChild(c),i.appendChild(o),a.appendChild(i),a.addEventListener("click",d=>{d.target===a&&a.remove()}),!t.querySelector("style[data-namiru-confirm]")){let d=document.createElement("style");d.setAttribute("data-namiru-confirm",""),d.textContent=`
1072
+ `}function be(n,e){let t=n.replace("#",""),a=parseInt(t,16);if(isNaN(a)||t.length<6)return n;let i=Math.max(0,Math.min(255,(a>>16&255)+e)),r=Math.max(0,Math.min(255,(a>>8&255)+e)),l=Math.max(0,Math.min(255,(a&255)+e));return`#${(i<<16|r<<8|l).toString(16).padStart(6,"0")}`}function Xe(n){return n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function ne(n){let e=Xe(n);e=e.replace(/\u2014/g,", "),e=e.replace(/```(?:\w*)\n([\s\S]*?)```/g,'<pre class="namiru-md-pre"><code>$1</code></pre>'),e=e.replace(/`([^`\n]+)`/g,'<code class="namiru-md-code">$1</code>'),e=e.replace(/\*\*\*(.+?)\*\*\*/g,"<strong><em>$1</em></strong>"),e=e.replace(/\*\*(.+?)\*\*/g,"<strong>$1</strong>"),e=e.replace(/__(.+?)__/g,"<strong>$1</strong>"),e=e.replace(/\*(.+?)\*/g,"<em>$1</em>"),e=e.replace(/(^|[\s(])_(.+?)_([\s).,!?]|$)/gm,"$1<em>$2</em>$3"),e=e.replace(/\[([^\]]+)\]\(([^)]+)\)/g,'<a href="$2" target="_blank" rel="noopener noreferrer" class="namiru-md-link">$1</a>'),e=e.replace(/^[ \t]*([-*_])\s*\1\s*\1[\s\-*_]*$/gm,'<hr class="namiru-md-hr">');let t=e.split(`
1073
+ `),a=[],i=!1,r=!1;for(let c=0;c<t.length;c++){let d=t[c];if(d.includes('<hr class="namiru-md-hr">')){i&&(a.push("</ul>"),i=!1),r&&(a.push("</ol>"),r=!1),a.push(d);continue}let p=d.match(/^(\s*)[-*]\s+(.*)/),k=d.match(/^(\s*)\d+\.\s+(.*)/);p?(i||(r&&(a.push("</ol>"),r=!1),a.push('<ul class="namiru-md-ul">'),i=!0),a.push(`<li>${p[2]}</li>`)):k?(r||(i&&(a.push("</ul>"),i=!1),a.push('<ol class="namiru-md-ol">'),r=!0),a.push(`<li>${k[2]}</li>`)):(i&&(a.push("</ul>"),i=!1),r&&(a.push("</ol>"),r=!1),d.trim()===""?a.push(""):a.push(d))}i&&a.push("</ul>"),r&&a.push("</ol>");let l="",o=!1;for(let c of a)c.includes("<hr")?l+=c:c.startsWith("<ul")||c.startsWith("<ol")?(o=!0,l+=c):c==="</ul>"||c==="</ol>"?(o=!1,l+=c):c.startsWith("<li>")?l+=c:c.trim()===""?o||(l+="</p><p>"):(l.length>0&&!o&&!l.endsWith("<p>")&&!l.endsWith("</ul>")&&!l.endsWith("</ol>")&&!l.endsWith("</pre>")&&(l+="<br>"),l+=c);!l.startsWith("<ul")&&!l.startsWith("<ol")&&!l.startsWith("<pre")&&(l=`<p>${l}</p>`),l=l.replace(/<p>\s*<\/p>/g,""),l=l.replace(/<p>(<(?:ul|ol|pre|hr)[^>]*>)/g,"$1"),l=l.replace(/(<\/(?:ul|ol|pre)>)<\/p>/g,"$1"),l=l.replace(/(<hr[^>]*>)<\/p>/g,"$1");let s=V?"":" !important";return l=l.replace(/<p>/g,`<p style="color: var(--namiru-text)${s}; margin: 0 0 0.5em 0${s}; max-width: 100%${s}; word-wrap: break-word${s}; display: block${s}; visibility: visible${s};">`),l=l.replace(/<li>/g,`<li style="color: var(--namiru-text)${s}; margin: 0.2em 0${s}; display: list-item${s}; visibility: visible${s};">`),l=l.replace(/<strong>/g,`<strong style="color: var(--namiru-text)${s}; font-weight: 700${s}; display: inline${s}; visibility: visible${s}; font-size: inherit${s}; opacity: 1${s};">`),l=l.replace(/<em>/g,`<em style="color: var(--namiru-text)${s}; font-style: italic${s}; display: inline${s}; visibility: visible${s}; font-size: inherit${s}; opacity: 1${s};">`),l=l.replace(/<a href=/g,`<a style="color: var(--namiru-primary)${s}; text-decoration: underline${s}; display: inline${s}; visibility: visible${s};" href=`),l}function I(n,e="0 0 256 256"){let t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("viewBox",e),t.setAttribute("fill","currentColor"),t.setAttribute("xmlns","http://www.w3.org/2000/svg");for(let a of n){let i=document.createElementNS("http://www.w3.org/2000/svg","path");i.setAttribute("d",a),t.appendChild(i)}return t}function ve(n){let e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 256 256"),e.setAttribute("xmlns","http://www.w3.org/2000/svg"),e.setAttribute("width","18"),e.setAttribute("height","18"),n?e.setAttribute("fill",n):e.setAttribute("fill","currentColor");let t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("d","M201.89,54.66A103.43,103.43,0,0,0,128.79,24H128A104,104,0,0,0,24,128v56a24,24,0,0,0,24,24H64a24,24,0,0,0,24-24V144a24,24,0,0,0-24-24H40.36A88,88,0,0,1,128,40h.67a87.71,87.71,0,0,1,87,80H192a24,24,0,0,0-24,24v40a24,24,0,0,0,24,24h8a8,8,0,0,0,0-16h-8a8,8,0,0,1-8-8V144a8,8,0,0,1,8-8h24a8,8,0,0,1,8,8v56a40,40,0,0,1-40,40H152a8,8,0,0,0,0,16h32a56.06,56.06,0,0,0,56-56V128A103.41,103.41,0,0,0,201.89,54.66ZM64,136a8,8,0,0,1,8,8v40a8,8,0,0,1-8,8H48a8,8,0,0,1-8-8V136Z"),e.appendChild(t),e}function Ce(n){let e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 256 256"),e.setAttribute("xmlns","http://www.w3.org/2000/svg"),e.setAttribute("width","20"),e.setAttribute("height","20"),n?e.setAttribute("fill",n):e.setAttribute("fill","currentColor");let t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("d","M201.89,54.66A103.43,103.43,0,0,0,128.79,24H128A104,104,0,0,0,24,128v56a24,24,0,0,0,24,24H64a24,24,0,0,0,24-24V144a24,24,0,0,0-24-24H40.36A88,88,0,0,1,128,40h.67a87.71,87.71,0,0,1,87,80H192a24,24,0,0,0-24,24v40a24,24,0,0,0,24,24h8a8,8,0,0,0,0-16h-8a8,8,0,0,1-8-8V144a8,8,0,0,1,8-8h24a8,8,0,0,1,8,8v56a40,40,0,0,1-40,40H152a8,8,0,0,0,0,16h32a56.06,56.06,0,0,0,56-56V128A103.41,103.41,0,0,0,201.89,54.66ZM64,136a8,8,0,0,1,8,8v40a8,8,0,0,1-8,8H48a8,8,0,0,1-8-8V136Z"),e.appendChild(t),e}function Ee(){return I(["M128,24A104,104,0,0,0,36.18,176.88L24.83,210.93a16,16,0,0,0,20.24,20.24l34.05-11.35A104,104,0,1,0,128,24Zm0,192a88.11,88.11,0,0,1-44.06-11.81,8,8,0,0,0-4-1.08,7.85,7.85,0,0,0-2.53.42L40,216l12.47-37.41a8,8,0,0,0-.66-6.54A88,88,0,1,1,128,216Z"])}function ae(){return I(["M205.66,194.34a8,8,0,0,1-11.32,11.32L128,139.31,61.66,205.66a8,8,0,0,1-11.32-11.32L116.69,128,50.34,61.66A8,8,0,0,1,61.66,50.34L128,116.69l66.34-66.35a8,8,0,0,1,11.32,11.32L139.31,128Z"])}function we(){return I(["M240,127.89a16,16,0,0,1-8.18,14L63.9,237.9A16.15,16.15,0,0,1,56,240a16,16,0,0,1-15-21.33l27-79.95A4,4,0,0,1,71.72,136H144a8,8,0,0,0,8-8.53,8.19,8.19,0,0,0-8.26-7.47h-72a4,4,0,0,1-3.79-2.72l-27-79.94A16,16,0,0,1,63.84,18.07l168,95.89A16,16,0,0,1,240,127.89Z"])}function Se(){return I(["M234,80.12A24,24,0,0,0,216,72H160V56a40,40,0,0,0-40-40,8,8,0,0,0-7.16,4.42L75.06,96H32a16,16,0,0,0-16,16v88a16,16,0,0,0,16,16H204a24,24,0,0,0,23.82-21.12l12-96A24,24,0,0,0,234,80.12ZM32,112H72v88H32ZM223.94,97l-12,96a8,8,0,0,1-7.94,7H88V105.89l36.71-73.43A24,24,0,0,1,144,56V80a8,8,0,0,0,8,8h64a8,8,0,0,1,7.94,9Z"])}function ke(){return I(["M239.82,157l-12-96A24,24,0,0,0,204,40H32A16,16,0,0,0,16,56v88a16,16,0,0,0,16,16H75.06l37.78,75.58A8,8,0,0,0,120,240a40,40,0,0,0,40-40V184h56a24,24,0,0,0,23.82-27ZM72,144H32V56H72Zm150,21.29a8,8,0,0,1-6,2.71H152a8,8,0,0,0-8,8v24a24,24,0,0,1-19.29,23.54L88,150.11V56H204a8,8,0,0,1,7.94,7l12,96A8,8,0,0,1,222,165.29Z"])}function et(){return I(["M216,64H176a48,48,0,0,0-96,0H40A16,16,0,0,0,24,80V200a16,16,0,0,0,16,16H216a16,16,0,0,0,16-16V80A16,16,0,0,0,216,64ZM128,32a32,32,0,0,1,32,32H96A32,32,0,0,1,128,32Zm88,168H40V80H80V96a8,8,0,0,0,16,0V80h64V96a8,8,0,0,0,16,0V80h40Z"])}function tt(){return I(["M223.68,66.15,135.68,18a15.88,15.88,0,0,0-15.36,0l-88,48.17a16,16,0,0,0-8.32,14v95.64a16,16,0,0,0,8.32,14l88,48.17a15.88,15.88,0,0,0,15.36,0l88-48.17a16,16,0,0,0,8.32-14V80.18A16,16,0,0,0,223.68,66.15ZM128,32l80.34,44-29.77,16.3-80.35-44ZM128,120,47.66,76l33.9-18.56,80.34,44ZM40,90l80,43.78v85.79L40,175.82Zm96,129.57V133.82L216,90v85.78Z"])}function nt(){return I(["M224,48H32A16,16,0,0,0,16,64V192a16,16,0,0,0,16,16H224a16,16,0,0,0,16-16V64A16,16,0,0,0,224,48Zm0,16V88H32V64ZM32,192V104H224v88Zm16-24a8,8,0,0,1,8-8H96a8,8,0,0,1,0,16H56A8,8,0,0,1,48,168Zm0-32a8,8,0,0,1,8-8h64a8,8,0,0,1,0,16H56A8,8,0,0,1,48,136Z"])}function Te(){return I(["M128,24A104,104,0,0,0,36.18,176.88L24.83,210.93a16,16,0,0,0,20.24,20.24l34.05-11.35A104,104,0,1,0,128,24Zm0,192a88.11,88.11,0,0,1-44.06-11.81,8,8,0,0,0-4-1.08,7.85,7.85,0,0,0-2.53.42L40,216l12.47-37.41a8,8,0,0,0-.66-6.54A88,88,0,1,1,128,216Z"])}function at(){return I(["M152,224a8,8,0,0,1-8,8H112a8,8,0,0,1,0-16h32A8,8,0,0,1,152,224Zm73.69-142.23-21.34-21.35C183.42,39.49,156.58,24,128,24s-55.42,15.49-76.35,36.42L30.31,81.77a16,16,0,0,0,0,22.63L64,138.09V184a16,16,0,0,0,4.69,11.31l24,24A16,16,0,0,0,104,224h48a16,16,0,0,0,11.31-4.69l24-24A16,16,0,0,0,192,184V138.09l33.69-33.69A16,16,0,0,0,225.69,81.77ZM128,40c22.59,0,43.85,12.28,60,32H68C84.15,52.28,105.41,40,128,40Zm48,144-24,24H104L80,184V88H176Zm36.28-79.6L192,172.69V88h17.94l4.34,4.34A.64.64,0,0,1,212.28,104.4ZM64,172.69,45.66,104.4a.64.64,0,0,1-2,0L48,100H64Z"])}function it(){return I(["M226.76,69a8,8,0,0,0-12.84-2.88l-40.3,37.19-17.23-3.7-3.7-17.23,37.19-40.3A8,8,0,0,0,187,29.24,72,72,0,0,0,88,96c0,1.3,0,2.6.1,3.89L33.19,147.68a27.7,27.7,0,0,0,0,39.37l36.76,36.76a27.7,27.7,0,0,0,39.37,0l47.79-54.91c1.29.06,2.59.1,3.89.1a72,72,0,0,0,66.76-99ZM148.49,212.49a11.7,11.7,0,0,1-16.57,0L95.16,175.73a8,8,0,0,0-11.58.28L44.49,220.49a11.7,11.7,0,0,1-16.57,0L44.49,204a11.69,11.69,0,0,1,0-16.57l44.48-39.09a8,8,0,0,0,.28-11.58L52.49,100.05a56,56,0,0,1,89.36-63.58l-31.41,34a8,8,0,0,0-1.8,6.49l6,27.92a8,8,0,0,0,6.13,6.13l27.92,6a8,8,0,0,0,6.49-1.8l34-31.41A56,56,0,0,1,148.49,212.49Z"])}function rt(){return I(["M216,56H176V48a24,24,0,0,0-24-24H104A24,24,0,0,0,80,48v8H40A16,16,0,0,0,24,72V200a16,16,0,0,0,16,16H216a16,16,0,0,0,16-16V72A16,16,0,0,0,216,56ZM96,48a8,8,0,0,1,8-8h48a8,8,0,0,1,8,8v8H96ZM216,72v72H40V72Zm0,128H40V160H216v40Z"])}function ot(){return I(["M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24ZM74.08,197.5a64,64,0,0,1,107.84,0,87.83,87.83,0,0,1-107.84,0ZM96,120a32,32,0,1,1,32,32A32,32,0,0,1,96,120Zm97.76,66.41a79.66,79.66,0,0,0-36.06-28.75,48,48,0,1,0-59.4,0,79.66,79.66,0,0,0-36.06,28.75,88,88,0,1,1,131.52,0Z"])}function st(){return I(["M140,128a12,12,0,1,1-12-12A12,12,0,0,1,140,128Zm56-12a12,12,0,1,0,12,12A12,12,0,0,0,196,116ZM60,116a12,12,0,1,0,12,12A12,12,0,0,0,60,116Z"])}var lt={ShoppingBag:et,Package:tt,CreditCard:nt,ChatCircle:Te,Rocket:at,Wrench:it,Briefcase:rt,UserCircle:ot,DotsThree:st};function Ae(n){let e=lt[n];return e?e():Te()}function ct(n){let e=n.replace("#","");if(e.length===3&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),e.length<6||!/^[0-9a-fA-F]{6}/.test(e))return"74, 127, 255";let t=parseInt(e.substring(0,2),16),a=parseInt(e.substring(2,4),16),i=parseInt(e.substring(4,6),16);return`${t}, ${a}, ${i}`}function Me(n){let{store:e,branding:t,mode:a,onTranscriptClick:i,onNewChat:r,feedbackEnabled:l}=n;if(t.showHeader===!1){let h=document.createElement("div");return h.style.display="none",h}let o=document.createElement("div");o.className="namiru-header";let s=document.createElement("div");s.className="namiru-header-left";let c=ct(t.primaryColor);if(t.agentAvatar||t.logoUrl){let h=document.createElement("img");h.className="namiru-header-avatar",h.src=t.agentAvatar||t.logoUrl,h.alt=t.name,s.appendChild(h)}else{let h=document.createElement("div");h.className="namiru-header-avatar-fallback",h.style.background=`rgba(${c}, 0.06)`,h.style.border="none";let C=t.presetTheme==="dark",E=t.iconColor||(C?"#ffffff":t.primaryColor),f=ve(E);h.appendChild(f),s.appendChild(h)}let d=document.createElement("div");d.className="namiru-header-info";let p=document.createElement("div");if(p.className="namiru-header-name",p.textContent=t.headerTitle||t.name,d.appendChild(p),t.headerSubtitle){let h=document.createElement("div");h.className="namiru-header-subtitle",h.textContent=t.headerSubtitle,d.appendChild(h)}s.appendChild(d),o.appendChild(s);let k=document.createElement("div");if(k.className="namiru-header-actions",a==="button"){let h=document.createElement("button");h.className="namiru-header-btn",h.setAttribute("aria-label","Close chat"),h.appendChild(ae()),h.addEventListener("click",()=>{let C=e.getState();if(l&&!C.feedbackGiven&&C.state==="chatting"&&C.messages.length>0){e.dispatch({type:"SET_STATE",state:"feedback"});return}if(C.messages.length===0){e.dispatch({type:"SET_OPEN",isOpen:!1});return}re(o,e)}),k.appendChild(h)}return o.appendChild(k),o}function re(n,e){let t=n.parentElement;if(!t){e.dispatch({type:"SET_OPEN",isOpen:!1});return}if(t.querySelector(".namiru-close-confirm-overlay"))return;let a=document.createElement("div");a.className="namiru-close-confirm-overlay",a.style.cssText="position:absolute;inset:0;z-index:50;display:flex;align-items:center;justify-content:center;padding:16px;background:rgba(0,0,0,0.35);backdrop-filter:blur(2px);animation:namiruConfirmFade 0.15s ease-out;";let i=document.createElement("div");i.style.cssText="background:var(--namiru-bg,#fff);border-radius:8px;border:1px solid var(--namiru-border,#e5e7eb);box-shadow:0 8px 24px rgba(0,0,0,0.12);padding:20px;width:100%;max-width:280px;animation:namiruConfirmSlide 0.2s cubic-bezier(0.16,1,0.3,1);";let r=document.createElement("div");r.style.cssText="font-size:14px;font-weight:600;color:var(--namiru-text,#1f2937);margin-bottom:4px;",r.textContent="End conversation?",i.appendChild(r);let l=document.createElement("div");l.style.cssText="font-size:13px;color:var(--namiru-text-secondary,#6b7280);line-height:1.4;margin-bottom:16px;",l.textContent="We've received your message. Your chat history will not be saved.",i.appendChild(l);let o=document.createElement("div");o.style.cssText="display:flex;gap:8px;";let s=document.createElement("button");s.style.cssText="flex:1;padding:8px 12px;border-radius:6px;font-size:13px;font-weight:500;cursor:pointer;border:1px solid var(--namiru-border,#e5e7eb);background:var(--namiru-bg,#fff);color:var(--namiru-text,#1f2937);transition:background 0.15s;",s.textContent="Cancel",s.addEventListener("mouseenter",()=>{s.style.background="var(--namiru-bg-secondary,#f3f4f6)"}),s.addEventListener("mouseleave",()=>{s.style.background="var(--namiru-bg,#fff)"}),s.addEventListener("click",()=>a.remove());let c=document.createElement("button");if(c.style.cssText="flex:1;padding:8px 12px;border-radius:6px;font-size:13px;font-weight:500;cursor:pointer;border:none;background:var(--namiru-text,#1f2937);color:var(--namiru-bg,#fff);transition:opacity 0.15s;",c.textContent="End chat",c.addEventListener("mouseenter",()=>{c.style.opacity="0.85"}),c.addEventListener("mouseleave",()=>{c.style.opacity="1"}),c.addEventListener("click",()=>{a.remove(),e.dispatch({type:"RESET"}),e.dispatch({type:"SET_OPEN",isOpen:!1})}),o.appendChild(s),o.appendChild(c),i.appendChild(o),a.appendChild(i),a.addEventListener("click",d=>{d.target===a&&a.remove()}),!t.querySelector("style[data-namiru-confirm]")){let d=document.createElement("style");d.setAttribute("data-namiru-confirm",""),d.textContent=`
1074
1074
  @keyframes namiruConfirmFade { from { opacity: 0; } to { opacity: 1; } }
1075
1075
  @keyframes namiruConfirmSlide { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
1076
- `,t.appendChild(d)}t.appendChild(a)}function Ne(n){let{onSend:e}=n,t=document.createElement("div");t.className="namiru-input-area";let a=document.createElement("div");a.className="namiru-input-row";let i=document.createElement("textarea");i.className="namiru-input",i.placeholder="Type your message...",i.rows=1,i.setAttribute("aria-label","Chat message"),V?i.style.color="var(--namiru-text)":i.style.setProperty("color","var(--namiru-text)","important");let r=document.createElement("button");r.className="namiru-send-btn",r.setAttribute("aria-label","Send message"),r.disabled=!0,r.appendChild(we());function l(){let o=i.value.trim();o&&(e(o),i.value="",i.style.height="auto",r.disabled=!0)}return i.addEventListener("input",()=>{r.disabled=!i.value.trim(),i.style.height="auto",i.style.height=Math.min(i.scrollHeight,100)+"px"}),i.addEventListener("keydown",o=>{o.key==="Enter"&&!o.shiftKey&&(o.preventDefault(),l())}),r.addEventListener("click",l),a.appendChild(i),a.appendChild(r),t.appendChild(a),t}function oe(n){if(n.agentAvatar){let i=document.createElement("img");return i.src=n.agentAvatar,i.alt="Agent",i.className="namiru-message-avatar-img",i}let e=document.createElement("span"),t=n.presetTheme==="dark",a=n.iconColor||(t?"#ffffff":n.textColor);return e.appendChild(Ce(a)),e}function Le(n){return{createBubble(e){return e.role==="user"?ct(e,n):dt(e,n)},createStreaming(){return mt(n)},createLoading(){return ut(n)}}}function ct(n,e){let t=document.createElement("div");t.className="namiru-message-row namiru-message-row--user";let a=document.createElement("div"),i="namiru-message namiru-message--user";return e.bubbleStyle==="rounded"?i+=" namiru-bubble--rounded":e.bubbleStyle==="square"&&(i+=" namiru-bubble--square"),a.className=i,a.textContent=n.content,t.appendChild(a),t}function dt(n,e){let t=document.createElement("div");t.className="namiru-message-row namiru-message-row--assistant";let a=document.createElement("div");a.className="namiru-message-icon",a.appendChild(oe(e)),t.appendChild(a);let i=document.createElement("div");return i.className="namiru-message namiru-message--assistant namiru-md",i.innerHTML=ne(n.content),t.appendChild(i),t}function mt(n){let e=document.createElement("div");e.className="namiru-message-row namiru-message-row--assistant";let t=document.createElement("div");t.className="namiru-message-icon",t.appendChild(oe(n)),e.appendChild(t);let a=document.createElement("div");return a.className="namiru-message namiru-message--assistant namiru-md",a.textContent="",e.appendChild(a),e._namiruTextEl=a,e}function ut(n){let e=document.createElement("div");e.className="namiru-message-row namiru-message-row--assistant";let t=document.createElement("div");t.className="namiru-message-icon",t.appendChild(oe(n)),e.appendChild(t);let a=document.createElement("div");a.className="namiru-loading";for(let i=0;i<3;i++){let r=document.createElement("div");r.className="namiru-loading-dot",a.appendChild(r)}return e.appendChild(a),e}function _e(n){let{question:e,options:t,onSelect:a}=n,i=document.createElement("div");i.className="namiru-prechat";let r=document.createElement("div");r.className="namiru-prechat-question",r.textContent=e,i.appendChild(r);let l=document.createElement("div");l.className="namiru-prechat-options";for(let o of t){let s=document.createElement("button");s.className="namiru-prechat-option";let c=Ae(o.icon);s.appendChild(c);let d=document.createElement("span");d.textContent=o.label,s.appendChild(d),s.addEventListener("click",()=>a(o.label)),l.appendChild(s)}return i.appendChild(l),i}function Ie(n){let{onFeedback:e,softPrompt:t}=n,a=document.createElement("div");a.className="namiru-feedback";let i=document.createElement("div");i.className="namiru-feedback-label",i.textContent="Feedback",a.appendChild(i);let r=document.createElement("div");r.className="namiru-feedback-text",r.textContent=t?"How did it go? Your feedback helps us improve.":"How was your experience?",a.appendChild(r);let l=document.createElement("div");l.className="namiru-feedback-buttons";let o=document.createElement("button");o.className="namiru-feedback-btn namiru-feedback-btn-up",o.setAttribute("aria-label","Thumbs up"),o.appendChild(Se());let s=document.createElement("button");s.className="namiru-feedback-btn namiru-feedback-btn-down",s.setAttribute("aria-label","Thumbs down"),s.appendChild(ke());function c(d){for(e(d);a.firstChild;)a.removeChild(a.firstChild);let p=document.createElement("div");p.className="namiru-feedback-thanks",p.textContent="Thanks for your feedback!",a.appendChild(p)}return o.addEventListener("click",()=>c("up")),s.addEventListener("click",()=>c("down")),l.appendChild(o),l.appendChild(s),a.appendChild(l),a}function se(n){let{promptText:e,buttonText:t,onSubmit:a}=n,i=document.createElement("div");i.className="namiru-email-form";let r=document.createElement("div");r.className="namiru-email-form-text",r.textContent=e,i.appendChild(r);let l=document.createElement("div");l.className="namiru-email-form-row";let o=document.createElement("input");o.className="namiru-email-input",o.type="email",o.placeholder="your@email.com",o.setAttribute("aria-label","Email address");let s=document.createElement("button");s.className="namiru-email-submit",s.textContent=t,s.disabled=!0,o.addEventListener("input",()=>{s.disabled=!$e(o.value)});function c(){let d=o.value.trim();if(!$e(d))return;a(d),l.remove(),r.remove();let p=document.createElement("div");p.className="namiru-email-sent",p.textContent="Thanks, we'll be in touch",i.appendChild(p)}return o.addEventListener("keydown",d=>{d.key==="Enter"&&(d.preventDefault(),c())}),s.addEventListener("click",c),l.appendChild(o),l.appendChild(s),i.appendChild(l),i}function $e(n){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(n.trim())}function He(n){let{onSubmit:e}=n,t=document.createElement("div");t.className="namiru-contact-form";let a=document.createElement("div");a.className="namiru-contact-heading",a.textContent="Our team is here to help! Leave your message and we'll get back to you.",t.appendChild(a);let i=document.createElement("label");i.className="namiru-contact-label",i.textContent="Name (optional)",t.appendChild(i);let r=document.createElement("input");r.className="namiru-contact-input",r.type="text",r.placeholder="Your name",r.setAttribute("aria-label","Name"),t.appendChild(r);let l=document.createElement("label");l.className="namiru-contact-label",l.textContent="Email *",t.appendChild(l);let o=document.createElement("input");o.className="namiru-contact-input",o.type="email",o.placeholder="your@email.com",o.required=!0,o.setAttribute("aria-label","Email address"),t.appendChild(o);let s=document.createElement("label");s.className="namiru-contact-label",s.textContent="Message *",t.appendChild(s);let c=document.createElement("textarea");c.className="namiru-contact-textarea",c.placeholder="How can we help you?",c.rows=4,c.required=!0,c.setAttribute("aria-label","Message"),t.appendChild(c);let d=document.createElement("div");d.className="namiru-contact-error",d.style.display="none",t.appendChild(d);let p=document.createElement("button");p.className="namiru-contact-submit",p.textContent="Send Message",p.disabled=!0,t.appendChild(p);function k(){let E=o.value.trim(),f=c.value.trim();return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(E)&&f.length>0}function h(){p.disabled=!k()}o.addEventListener("input",h),c.addEventListener("input",h);function C(){if(!k())return;let E={name:r.value.trim(),email:o.value.trim(),message:c.value.trim()};p.disabled=!0,p.textContent="Sending...",r.disabled=!0,o.disabled=!0,c.disabled=!0,e(E),t.textContent="";let f=document.createElement("div");f.className="namiru-contact-confirmation",f.textContent="Thanks! We'll get back to you shortly.",t.appendChild(f)}return p.addEventListener("click",C),o.addEventListener("keydown",E=>{E.key==="Enter"&&(E.preventDefault(),C())}),r.addEventListener("keydown",E=>{E.key==="Enter"&&(E.preventDefault(),C())}),t}function pt(){let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width","40"),n.setAttribute("height","40"),n.setAttribute("viewBox","0 0 256 256"),n.setAttribute("fill","none"),n.setAttribute("stroke","currentColor"),n.setAttribute("stroke-width","16"),n.setAttribute("stroke-linecap","round"),n.setAttribute("stroke-linejoin","round");let e=document.createElementNS("http://www.w3.org/2000/svg","circle");e.setAttribute("cx","128"),e.setAttribute("cy","128"),e.setAttribute("r","96"),n.appendChild(e);let t=document.createElementNS("http://www.w3.org/2000/svg","line");t.setAttribute("x1","128"),t.setAttribute("y1","80"),t.setAttribute("x2","128"),t.setAttribute("y2","136"),n.appendChild(t);let a=document.createElementNS("http://www.w3.org/2000/svg","circle");return a.setAttribute("cx","128"),a.setAttribute("cy","172"),a.setAttribute("r","6"),a.setAttribute("fill","currentColor"),a.setAttribute("stroke","none"),n.appendChild(a),n}function gt(){let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width","40"),n.setAttribute("height","40"),n.setAttribute("viewBox","0 0 256 256"),n.setAttribute("fill","none"),n.setAttribute("stroke","currentColor"),n.setAttribute("stroke-width","16"),n.setAttribute("stroke-linecap","round"),n.setAttribute("stroke-linejoin","round");let e=document.createElementNS("http://www.w3.org/2000/svg","circle");e.setAttribute("cx","128"),e.setAttribute("cy","128"),e.setAttribute("r","96"),n.appendChild(e);let t=document.createElementNS("http://www.w3.org/2000/svg","polyline");return t.setAttribute("points","88,136 112,160 168,104"),n.appendChild(t),n}function Oe(n){let{onSubmit:e,onNewChat:t}=n,a=document.createElement("div");a.className="namiru-limit-overlay";let i=document.createElement("div");i.className="namiru-limit-icon",i.appendChild(pt()),a.appendChild(i);let r=document.createElement("div");r.className="namiru-limit-heading",r.textContent="Conversation limit reached",a.appendChild(r);let l=document.createElement("div");l.className="namiru-limit-subtext",l.textContent="AI responses are currently unavailable. Send a message and we'll forward it via email.",a.appendChild(l);let o=document.createElement("div");o.className="namiru-limit-form";let s=document.createElement("textarea");s.className="namiru-limit-textarea",s.placeholder="Your message...",s.rows=4,s.setAttribute("aria-label","Message"),o.appendChild(s);let c=document.createElement("input");c.className="namiru-limit-email",c.type="email",c.placeholder="Your email (optional, for a reply)",c.setAttribute("aria-label","Email address (optional)"),o.appendChild(c);let d=document.createElement("button");if(d.className="namiru-limit-submit",d.textContent="Send Message",d.disabled=!0,o.appendChild(d),a.appendChild(o),t){let C=document.createElement("button");C.className="namiru-limit-newchat",C.textContent="Start New Chat",C.addEventListener("click",t),a.appendChild(C)}function p(){return s.value.trim().length>0}function k(){d.disabled=!p()}s.addEventListener("input",k);function h(){if(!p())return;let C=c.value.trim(),E={message:s.value.trim()};C&&(E.visitorEmail=C),d.disabled=!0,d.textContent="Sending...",s.disabled=!0,c.disabled=!0,e(E),a.textContent="";let f=document.createElement("div");f.className="namiru-limit-icon namiru-limit-icon--success",f.appendChild(gt()),a.appendChild(f);let x=document.createElement("div");if(x.className="namiru-limit-confirmation",x.textContent="Message sent! The team will get back to you soon.",a.appendChild(x),t){let N=document.createElement("button");N.className="namiru-limit-newchat",N.textContent="Start New Chat",N.addEventListener("click",t),a.appendChild(N)}}return d.addEventListener("click",h),a}function De(n){let{store:e,branding:t,agentId:a,mode:i,position:r,onSendMessage:l,onPreChatSelect:o,onFeedback:s,onEscalationEmail:c,onTranscriptEmail:d,onContactFormSubmit:p,onLimitMessage:k,onNewChat:h,feedbackEnabled:C}=n,E=t.agentAvatar||t.logoUrl,f=Le({textColor:t.textColor,bubbleStyle:t.bubbleStyle,agentAvatar:E,presetTheme:t.presetTheme,iconColor:t.iconColor}),x=document.createElement("div");i==="button"?x.className=`namiru-popup namiru-popup--${r}`:x.className="namiru-inline";let N=Me({store:e,branding:t,mode:i,...i==="button"?{onTranscriptClick:()=>{e.dispatch({type:"SET_STATE",state:"escalation"}),ce()},onNewChat:h}:{},feedbackEnabled:C});x.appendChild(N);let y=document.createElement("div");y.className="namiru-messages",x.appendChild(y);let T=Ne({onSend:l});T.style.display="none",x.appendChild(T);let G=t.showPoweredBy!==!1;G||(T.style.paddingBottom="12px");function F(){let m=document.createElement("div");m.className="namiru-powered",m.setAttribute("data-namiru-protected","true");let v=V?"":" !important";m.style.cssText=`display:block${v};visibility:visible${v};opacity:1${v};`;let S=document.createElement("a");return S.href="https://namiru.ai",S.target="_blank",S.rel="noopener noreferrer",S.textContent="Namiru.ai",m.appendChild(document.createTextNode("Powered by ")),m.appendChild(S),m}if(G){let v=F().innerHTML;x.appendChild(F());let S=!1;new MutationObserver(()=>{if(S)return;S=!0;let M=x.querySelector(".namiru-powered");if(!M)x.appendChild(F());else if(M.innerHTML!==v){let H=F();M.replaceWith(H)}else{let H=M.style,D=getComputedStyle(M);if(D.display==="none"||D.visibility==="hidden"||D.opacity==="0"){let B=V?"":" !important";H.cssText=`display:block${B};visibility:visible${B};opacity:1${B};`}}S=!1}).observe(x,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style","class"],characterData:!0})}t.fontFamily&&t.fontFamily!=="system"&&(x.style.fontFamily=t.fontFamily);let W=40,O=0,L=null,u=null,b=null,_=null,g=null,w=!1,A=null,R=null,U=null,P=null;function Re(){if(P)return;P=document.createElement("div"),P.className="namiru-connecting";let m=document.createElement("div");m.className="namiru-loading-dots";for(let v=0;v<3;v++){let S=document.createElement("span");S.className="namiru-loading-dot",m.appendChild(S)}P.appendChild(m),y.appendChild(P)}function q(){P&&(P.remove(),P=null)}function j(){y.textContent="",O=0,L=null,u=null,b=null,_=null,g=null,R=null,U=null,P=null,w=!1,A=null}function ze(){if(w)return;w=!0;let v={id:"welcome",role:"assistant",content:t.welcomeMessage||"Hello! How can I help you today?",timestamp:Date.now()},S=f.createBubble(v);S.classList.add("namiru-message-row--welcome"),y.appendChild(S);let $=t.suggestedQuestions;console.log("[NamiruChat] renderWelcome suggestedQuestions:",$),$&&$.length>0&&(A=document.createElement("div"),A.className="namiru-suggestions",$.slice(0,4).forEach(M=>{let H=document.createElement("button");H.className="namiru-suggestion-chip",H.textContent=M,H.addEventListener("click",()=>{l(M),A&&(A.remove(),A=null)}),A.appendChild(H)}),y.appendChild(A))}function Ge(){let m=t.preChatConfig;if(!m||!m.enabled)return;let v={ecommerce:{question:"What brings you here today?",options:[{label:"Product question",icon:"ShoppingBag"},{label:"Order help",icon:"Package"},{label:"Billing issue",icon:"CreditCard"},{label:"Something else",icon:"ChatCircle"}]},saas:{question:"What can we help you with?",options:[{label:"Getting started",icon:"Rocket"},{label:"Technical issue",icon:"Wrench"},{label:"Subscription question",icon:"CreditCard"},{label:"Something else",icon:"ChatCircle"}]},services:{question:"How can we assist you?",options:[{label:"Interested in services",icon:"Briefcase"},{label:"Existing client",icon:"UserCircle"},{label:"General question",icon:"ChatCircle"},{label:"Something else",icon:"DotsThree"}]}},S,$;if(m.template==="custom"&&m.custom)S=m.custom.question,$=m.custom.options;else if(m.template&&v[m.template]){let M=v[m.template];S=M.question,$=M.options}else return;j(),T.style.display="none",b=_e({question:S,options:$,onSelect:M=>{o(M),T.style.display=""}}),y.appendChild(b)}function ce(){g||(g=se({promptText:"Want a copy of this conversation? Handy if you need to reference it later for support.",buttonText:"Send",onSubmit:m=>{d(m),g=null}}),y.appendChild(g),Z())}function de(){g||(g=se({promptText:"We'll connect you with the team. Please share your email and we'll get back to you.",buttonText:"Submit",onSubmit:m=>{c(m),g=null}}),y.appendChild(g),Z())}function me(){R||(j(),T.style.display="none",R=He({onSubmit:m=>{p&&p(m),R=null}}),y.appendChild(R))}function ue(){U||(T.style.display="none",U=Oe({onSubmit:m=>{k&&k(m),U=null}}),y.style.position="relative",y.appendChild(U))}function We(){for(;y.firstChild;)y.removeChild(y.firstChild);y.style.position="relative";let m=document.createElement("div");m.style.cssText=`
1076
+ `,t.appendChild(d)}t.appendChild(a)}function Ne(n){let{onSend:e}=n,t=document.createElement("div");t.className="namiru-input-area";let a=document.createElement("div");a.className="namiru-input-row";let i=document.createElement("textarea");i.className="namiru-input",i.placeholder="Type your message...",i.rows=1,i.setAttribute("aria-label","Chat message"),V?i.style.color="var(--namiru-text)":i.style.setProperty("color","var(--namiru-text)","important");let r=document.createElement("button");r.className="namiru-send-btn",r.setAttribute("aria-label","Send message"),r.disabled=!0,r.appendChild(we());function l(){let o=i.value.trim();o&&(e(o),i.value="",i.style.height="auto",r.disabled=!0)}return i.addEventListener("input",()=>{r.disabled=!i.value.trim(),i.style.height="auto",i.style.height=Math.min(i.scrollHeight,100)+"px"}),i.addEventListener("keydown",o=>{o.key==="Enter"&&!o.shiftKey&&(o.preventDefault(),l())}),r.addEventListener("click",l),a.appendChild(i),a.appendChild(r),t.appendChild(a),t}function oe(n){if(n.agentAvatar){let i=document.createElement("img");return i.src=n.agentAvatar,i.alt="Agent",i.className="namiru-message-avatar-img",i}let e=document.createElement("span"),t=n.presetTheme==="dark",a=n.iconColor||(t?"#ffffff":n.textColor);return e.appendChild(Ce(a)),e}function _e(n){return{createBubble(e){return e.role==="user"?dt(e,n):mt(e,n)},createStreaming(){return ut(n)},createLoading(){return pt(n)}}}function dt(n,e){let t=document.createElement("div");t.className="namiru-message-row namiru-message-row--user";let a=document.createElement("div"),i="namiru-message namiru-message--user";return e.bubbleStyle==="rounded"?i+=" namiru-bubble--rounded":e.bubbleStyle==="square"&&(i+=" namiru-bubble--square"),a.className=i,a.textContent=n.content,t.appendChild(a),t}function mt(n,e){let t=document.createElement("div");t.className="namiru-message-row namiru-message-row--assistant";let a=document.createElement("div");a.className="namiru-message-icon",a.appendChild(oe(e)),t.appendChild(a);let i=document.createElement("div");return i.className="namiru-message namiru-message--assistant namiru-md",i.innerHTML=ne(n.content),t.appendChild(i),t}function ut(n){let e=document.createElement("div");e.className="namiru-message-row namiru-message-row--assistant";let t=document.createElement("div");t.className="namiru-message-icon",t.appendChild(oe(n)),e.appendChild(t);let a=document.createElement("div");return a.className="namiru-message namiru-message--assistant namiru-md",a.textContent="",e.appendChild(a),e._namiruTextEl=a,e}function pt(n){let e=document.createElement("div");e.className="namiru-message-row namiru-message-row--assistant";let t=document.createElement("div");t.className="namiru-message-icon",t.appendChild(oe(n)),e.appendChild(t);let a=document.createElement("div");a.className="namiru-loading";for(let i=0;i<3;i++){let r=document.createElement("div");r.className="namiru-loading-dot",a.appendChild(r)}return e.appendChild(a),e}function Le(n){let{question:e,options:t,onSelect:a}=n,i=document.createElement("div");i.className="namiru-prechat";let r=document.createElement("div");r.className="namiru-prechat-question",r.textContent=e,i.appendChild(r);let l=document.createElement("div");l.className="namiru-prechat-options";for(let o of t){let s=document.createElement("button");s.className="namiru-prechat-option";let c=Ae(o.icon);s.appendChild(c);let d=document.createElement("span");d.textContent=o.label,s.appendChild(d),s.addEventListener("click",()=>a(o.label)),l.appendChild(s)}return i.appendChild(l),i}function Ie(n){let{onFeedback:e,softPrompt:t}=n,a=document.createElement("div");a.className="namiru-feedback";let i=document.createElement("div");i.className="namiru-feedback-label",i.textContent="Feedback",a.appendChild(i);let r=document.createElement("div");r.className="namiru-feedback-text",r.textContent=t?"How did it go? Your feedback helps us improve.":"How was your experience?",a.appendChild(r);let l=document.createElement("div");l.className="namiru-feedback-buttons";let o=document.createElement("button");o.className="namiru-feedback-btn namiru-feedback-btn-up",o.setAttribute("aria-label","Thumbs up"),o.appendChild(Se());let s=document.createElement("button");s.className="namiru-feedback-btn namiru-feedback-btn-down",s.setAttribute("aria-label","Thumbs down"),s.appendChild(ke());function c(d){for(e(d);a.firstChild;)a.removeChild(a.firstChild);let p=document.createElement("div");p.className="namiru-feedback-thanks",p.textContent="Thanks for your feedback!",a.appendChild(p)}return o.addEventListener("click",()=>c("up")),s.addEventListener("click",()=>c("down")),l.appendChild(o),l.appendChild(s),a.appendChild(l),a}function se(n){let{promptText:e,buttonText:t,onSubmit:a}=n,i=document.createElement("div");i.className="namiru-email-form";let r=document.createElement("div");r.className="namiru-email-form-text",r.textContent=e,i.appendChild(r);let l=document.createElement("div");l.className="namiru-email-form-row";let o=document.createElement("input");o.className="namiru-email-input",o.type="email",o.placeholder="your@email.com",o.setAttribute("aria-label","Email address");let s=document.createElement("button");s.className="namiru-email-submit",s.textContent=t,s.disabled=!0,o.addEventListener("input",()=>{s.disabled=!$e(o.value)});function c(){let d=o.value.trim();if(!$e(d))return;a(d),l.remove(),r.remove();let p=document.createElement("div");p.className="namiru-email-sent",p.textContent="Thanks, we'll be in touch",i.appendChild(p)}return o.addEventListener("keydown",d=>{d.key==="Enter"&&(d.preventDefault(),c())}),s.addEventListener("click",c),l.appendChild(o),l.appendChild(s),i.appendChild(l),i}function $e(n){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(n.trim())}function He(n){let{onSubmit:e}=n,t=document.createElement("div");t.className="namiru-contact-form";let a=document.createElement("div");a.className="namiru-contact-heading",a.textContent="Our team is here to help! Leave your message and we'll get back to you.",t.appendChild(a);let i=document.createElement("label");i.className="namiru-contact-label",i.textContent="Name (optional)",t.appendChild(i);let r=document.createElement("input");r.className="namiru-contact-input",r.type="text",r.placeholder="Your name",r.setAttribute("aria-label","Name"),t.appendChild(r);let l=document.createElement("label");l.className="namiru-contact-label",l.textContent="Email *",t.appendChild(l);let o=document.createElement("input");o.className="namiru-contact-input",o.type="email",o.placeholder="your@email.com",o.required=!0,o.setAttribute("aria-label","Email address"),t.appendChild(o);let s=document.createElement("label");s.className="namiru-contact-label",s.textContent="Message *",t.appendChild(s);let c=document.createElement("textarea");c.className="namiru-contact-textarea",c.placeholder="How can we help you?",c.rows=4,c.required=!0,c.setAttribute("aria-label","Message"),t.appendChild(c);let d=document.createElement("div");d.className="namiru-contact-error",d.style.display="none",t.appendChild(d);let p=document.createElement("button");p.className="namiru-contact-submit",p.textContent="Send Message",p.disabled=!0,t.appendChild(p);function k(){let E=o.value.trim(),f=c.value.trim();return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(E)&&f.length>0}function h(){p.disabled=!k()}o.addEventListener("input",h),c.addEventListener("input",h);function C(){if(!k())return;let E={name:r.value.trim(),email:o.value.trim(),message:c.value.trim()};p.disabled=!0,p.textContent="Sending...",r.disabled=!0,o.disabled=!0,c.disabled=!0,e(E),t.textContent="";let f=document.createElement("div");f.className="namiru-contact-confirmation",f.textContent="Thanks! We'll get back to you shortly.",t.appendChild(f)}return p.addEventListener("click",C),o.addEventListener("keydown",E=>{E.key==="Enter"&&(E.preventDefault(),C())}),r.addEventListener("keydown",E=>{E.key==="Enter"&&(E.preventDefault(),C())}),t}function gt(){let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width","40"),n.setAttribute("height","40"),n.setAttribute("viewBox","0 0 256 256"),n.setAttribute("fill","none"),n.setAttribute("stroke","currentColor"),n.setAttribute("stroke-width","16"),n.setAttribute("stroke-linecap","round"),n.setAttribute("stroke-linejoin","round");let e=document.createElementNS("http://www.w3.org/2000/svg","circle");e.setAttribute("cx","128"),e.setAttribute("cy","128"),e.setAttribute("r","96"),n.appendChild(e);let t=document.createElementNS("http://www.w3.org/2000/svg","line");t.setAttribute("x1","128"),t.setAttribute("y1","80"),t.setAttribute("x2","128"),t.setAttribute("y2","136"),n.appendChild(t);let a=document.createElementNS("http://www.w3.org/2000/svg","circle");return a.setAttribute("cx","128"),a.setAttribute("cy","172"),a.setAttribute("r","6"),a.setAttribute("fill","currentColor"),a.setAttribute("stroke","none"),n.appendChild(a),n}function ht(){let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width","40"),n.setAttribute("height","40"),n.setAttribute("viewBox","0 0 256 256"),n.setAttribute("fill","none"),n.setAttribute("stroke","currentColor"),n.setAttribute("stroke-width","16"),n.setAttribute("stroke-linecap","round"),n.setAttribute("stroke-linejoin","round");let e=document.createElementNS("http://www.w3.org/2000/svg","circle");e.setAttribute("cx","128"),e.setAttribute("cy","128"),e.setAttribute("r","96"),n.appendChild(e);let t=document.createElementNS("http://www.w3.org/2000/svg","polyline");return t.setAttribute("points","88,136 112,160 168,104"),n.appendChild(t),n}function Oe(n){let{onSubmit:e,onNewChat:t}=n,a=document.createElement("div");a.className="namiru-limit-overlay";let i=document.createElement("div");i.className="namiru-limit-icon",i.appendChild(gt()),a.appendChild(i);let r=document.createElement("div");r.className="namiru-limit-heading",r.textContent="Conversation limit reached",a.appendChild(r);let l=document.createElement("div");l.className="namiru-limit-subtext",l.textContent="AI responses are currently unavailable. Send a message and we'll forward it via email.",a.appendChild(l);let o=document.createElement("div");o.className="namiru-limit-form";let s=document.createElement("textarea");s.className="namiru-limit-textarea",s.placeholder="Your message...",s.rows=4,s.setAttribute("aria-label","Message"),o.appendChild(s);let c=document.createElement("input");c.className="namiru-limit-email",c.type="email",c.placeholder="Your email (optional, for a reply)",c.setAttribute("aria-label","Email address (optional)"),o.appendChild(c);let d=document.createElement("button");if(d.className="namiru-limit-submit",d.textContent="Send Message",d.disabled=!0,o.appendChild(d),a.appendChild(o),t){let C=document.createElement("button");C.className="namiru-limit-newchat",C.textContent="Start New Chat",C.addEventListener("click",t),a.appendChild(C)}function p(){return s.value.trim().length>0}function k(){d.disabled=!p()}s.addEventListener("input",k);function h(){if(!p())return;let C=c.value.trim(),E={message:s.value.trim()};C&&(E.visitorEmail=C),d.disabled=!0,d.textContent="Sending...",s.disabled=!0,c.disabled=!0,e(E),a.textContent="";let f=document.createElement("div");f.className="namiru-limit-icon namiru-limit-icon--success",f.appendChild(ht()),a.appendChild(f);let x=document.createElement("div");if(x.className="namiru-limit-confirmation",x.textContent="Message sent! The team will get back to you soon.",a.appendChild(x),t){let N=document.createElement("button");N.className="namiru-limit-newchat",N.textContent="Start New Chat",N.addEventListener("click",t),a.appendChild(N)}}return d.addEventListener("click",h),a}function Be(n){let{store:e,branding:t,agentId:a,mode:i,position:r,onSendMessage:l,onPreChatSelect:o,onFeedback:s,onEscalationEmail:c,onTranscriptEmail:d,onContactFormSubmit:p,onLimitMessage:k,onNewChat:h,feedbackEnabled:C}=n,E=t.agentAvatar||t.logoUrl,f=_e({textColor:t.textColor,bubbleStyle:t.bubbleStyle,agentAvatar:E,presetTheme:t.presetTheme,iconColor:t.iconColor}),x=document.createElement("div");i==="button"?x.className=`namiru-popup namiru-popup--${r}`:x.className="namiru-inline";let N=Me({store:e,branding:t,mode:i,...i==="button"?{onTranscriptClick:()=>{e.dispatch({type:"SET_STATE",state:"escalation"}),ce()},onNewChat:h}:{},feedbackEnabled:C});x.appendChild(N);let y=document.createElement("div");y.className="namiru-messages",x.appendChild(y);let T=Ne({onSend:l});T.style.display="none",x.appendChild(T);let G=t.showPoweredBy!==!1;G||(T.style.paddingBottom="12px");function F(){let m=document.createElement("div");m.className="namiru-powered",m.setAttribute("data-namiru-protected","true");let v=V?"":" !important";m.style.cssText=`display:block${v};visibility:visible${v};opacity:1${v};`;let S=document.createElement("a");return S.href="https://namiru.ai",S.target="_blank",S.rel="noopener noreferrer",S.textContent="Namiru.ai",m.appendChild(document.createTextNode("Powered by ")),m.appendChild(S),m}if(G){let v=F().innerHTML;x.appendChild(F());let S=!1;new MutationObserver(()=>{if(S)return;S=!0;let M=x.querySelector(".namiru-powered");if(!M)x.appendChild(F());else if(M.innerHTML!==v){let H=F();M.replaceWith(H)}else{let H=M.style,B=getComputedStyle(M);if(B.display==="none"||B.visibility==="hidden"||B.opacity==="0"){let P=V?"":" !important";H.cssText=`display:block${P};visibility:visible${P};opacity:1${P};`}}S=!1}).observe(x,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style","class"],characterData:!0})}t.fontFamily&&t.fontFamily!=="system"&&(x.style.fontFamily=t.fontFamily);let W=40,O=0,_=null,u=null,b=null,L=null,g=null,w=!1,A=null,R=null,U=null,D=null;function ze(){if(D)return;D=document.createElement("div"),D.className="namiru-connecting";let m=document.createElement("div");m.className="namiru-loading-dots";for(let v=0;v<3;v++){let S=document.createElement("span");S.className="namiru-loading-dot",m.appendChild(S)}D.appendChild(m),y.appendChild(D)}function q(){D&&(D.remove(),D=null)}function j(){y.textContent="",O=0,_=null,u=null,b=null,L=null,g=null,R=null,U=null,D=null,w=!1,A=null}function Ge(){if(w)return;w=!0;let v={id:"welcome",role:"assistant",content:t.welcomeMessage||"Hello! How can I help you today?",timestamp:Date.now()},S=f.createBubble(v);S.classList.add("namiru-message-row--welcome"),y.appendChild(S);let $=t.suggestedQuestions;console.log("[NamiruChat] renderWelcome suggestedQuestions:",$),$&&$.length>0&&(A=document.createElement("div"),A.className="namiru-suggestions",$.slice(0,4).forEach(M=>{let H=document.createElement("button");H.className="namiru-suggestion-chip",H.textContent=M,H.addEventListener("click",()=>{l(M),A&&(A.remove(),A=null)}),A.appendChild(H)}),y.appendChild(A))}function We(){let m=t.preChatConfig;if(!m||!m.enabled)return;let v={ecommerce:{question:"What brings you here today?",options:[{label:"Product question",icon:"ShoppingBag"},{label:"Order help",icon:"Package"},{label:"Billing issue",icon:"CreditCard"},{label:"Something else",icon:"ChatCircle"}]},saas:{question:"What can we help you with?",options:[{label:"Getting started",icon:"Rocket"},{label:"Technical issue",icon:"Wrench"},{label:"Subscription question",icon:"CreditCard"},{label:"Something else",icon:"ChatCircle"}]},services:{question:"How can we assist you?",options:[{label:"Interested in services",icon:"Briefcase"},{label:"Existing client",icon:"UserCircle"},{label:"General question",icon:"ChatCircle"},{label:"Something else",icon:"DotsThree"}]}},S,$;if(m.template==="custom"&&m.custom)S=m.custom.question,$=m.custom.options;else if(m.template&&v[m.template]){let M=v[m.template];S=M.question,$=M.options}else return;j(),T.style.display="none",b=Le({question:S,options:$,onSelect:M=>{o(M),T.style.display=""}}),y.appendChild(b)}function ce(){g||(g=se({promptText:"Want a copy of this conversation? Handy if you need to reference it later for support.",buttonText:"Send",onSubmit:m=>{d(m),g=null}}),y.appendChild(g),Z())}function de(){g||(g=se({promptText:"We'll connect you with the team. Please share your email and we'll get back to you.",buttonText:"Submit",onSubmit:m=>{c(m),g=null}}),y.appendChild(g),Z())}function me(){R||(j(),T.style.display="none",R=He({onSubmit:m=>{p&&p(m),R=null}}),y.appendChild(R))}function ue(){U||(T.style.display="none",U=Oe({onSubmit:m=>{k&&k(m),U=null}}),y.style.position="relative",y.appendChild(U))}function Ze(){for(;y.firstChild;)y.removeChild(y.firstChild);y.style.position="relative";let m=document.createElement("div");m.style.cssText=`
1077
1077
  position: absolute; inset: 0; display: flex; flex-direction: column;
1078
1078
  align-items: center; justify-content: center; padding: 2rem; text-align: center;
1079
1079
  background: ${t.backgroundColor||"#ffffff"};
1080
1080
  color: ${t.textColor||"#1f2937"};
1081
- `;let v=document.createElementNS("http://www.w3.org/2000/svg","svg");v.setAttribute("viewBox","0 0 256 256"),v.setAttribute("width","72"),v.setAttribute("height","72"),v.setAttribute("fill","#ef4444"),v.style.cssText="margin-bottom: 20px; opacity: 0.8;";let S=document.createElementNS("http://www.w3.org/2000/svg","path");S.setAttribute("d","M128,26A102,102,0,1,0,230,128,102.12,102.12,0,0,0,128,26Zm90,102a89.6,89.6,0,0,1-22.29,59.22L68.78,60.29A89.95,89.95,0,0,1,218,128ZM38,128A89.6,89.6,0,0,1,60.29,68.78L187.22,195.71A89.95,89.95,0,0,1,38,128Z"),v.appendChild(S),m.appendChild(v);let $=document.createElement("div");$.style.cssText="font-size: 18px; font-weight: 600; margin-bottom: 8px;",$.textContent="Domain Not Authorized",m.appendChild($);let M=document.createElement("div");M.style.cssText="font-size: 14px; opacity: 0.7; margin-bottom: 24px; max-width: 300px; line-height: 1.5;",M.textContent="This chat widget is not authorized to run on this domain. Please update the allowed domain in your agent settings.",m.appendChild(M);let H=document.createElement("div");H.style.cssText="display: flex; gap: 12px; align-items: center;";let D=document.createElement("a");D.style.cssText=`
1081
+ `;let v=document.createElementNS("http://www.w3.org/2000/svg","svg");v.setAttribute("viewBox","0 0 256 256"),v.setAttribute("width","72"),v.setAttribute("height","72"),v.setAttribute("fill","#ef4444"),v.style.cssText="margin-bottom: 20px; opacity: 0.8;";let S=document.createElementNS("http://www.w3.org/2000/svg","path");S.setAttribute("d","M128,26A102,102,0,1,0,230,128,102.12,102.12,0,0,0,128,26Zm90,102a89.6,89.6,0,0,1-22.29,59.22L68.78,60.29A89.95,89.95,0,0,1,218,128ZM38,128A89.6,89.6,0,0,1,60.29,68.78L187.22,195.71A89.95,89.95,0,0,1,38,128Z"),v.appendChild(S),m.appendChild(v);let $=document.createElement("div");$.style.cssText="font-size: 18px; font-weight: 600; margin-bottom: 8px;",$.textContent="Domain Not Authorized",m.appendChild($);let M=document.createElement("div");M.style.cssText="font-size: 14px; opacity: 0.7; margin-bottom: 24px; max-width: 300px; line-height: 1.5;",M.textContent="This chat widget is not authorized to run on this domain. Please update the allowed domain in your agent settings.",m.appendChild(M);let H=document.createElement("div");H.style.cssText="display: flex; gap: 12px; align-items: center;";let B=document.createElement("a");B.style.cssText=`
1082
1082
  padding: 10px 24px; border-radius: 8px; border: none; cursor: pointer;
1083
1083
  font-size: 14px; font-weight: 500; text-decoration: none;
1084
1084
  display: inline-flex; align-items: center; box-sizing: border-box;
1085
1085
  line-height: 1; background: ${t.primaryColor||"#1f2937"}; color: #fff;
1086
- `,D.textContent="Go to Settings";let B=window.location.hostname,ge=window.location.origin;B!=="localhost"&&B!=="127.0.0.1"&&B.endsWith("namiru.ai")&&(ge=B.includes("test")?"https://test.namiru.ai":"https://namiru.ai"),D.href=`${ge}/agent-builder/agent/${a}/settings?focus=domain`,D.target="_blank",D.rel="noopener",H.appendChild(D);let Q=document.createElement("button");Q.style.cssText=`
1086
+ `,B.textContent="Go to Settings";let P=window.location.hostname,ge=window.location.origin;P!=="localhost"&&P!=="127.0.0.1"&&P.endsWith("namiru.ai")&&(ge=P.includes("test")?"https://test.namiru.ai":"https://namiru.ai"),B.href=`${ge}/agent-builder/agent/${a}/settings?focus=domain`,B.target="_blank",B.rel="noopener",H.appendChild(B);let Q=document.createElement("button");Q.style.cssText=`
1087
1087
  padding: 10px 24px; border-radius: 8px; cursor: pointer;
1088
1088
  font-size: 14px; font-weight: 500; line-height: 1; box-sizing: border-box;
1089
1089
  background: transparent; color: ${t.textColor||"#1f2937"};
1090
1090
  border: 1px solid ${t.textColor?t.textColor+"33":"#e5e7eb"};
1091
- `,Q.textContent="Reload",Q.addEventListener("click",()=>window.location.reload()),H.appendChild(Q),m.appendChild(H),y.appendChild(m)}function pe(m){_||(_=Ie({onFeedback:v=>{s(v),i==="button"&&setTimeout(()=>{e.dispatch({type:"RESET"}),e.dispatch({type:"SET_OPEN",isOpen:!1})},800)},softPrompt:m}),y.appendChild(_),Z())}function Z(){requestAnimationFrame(()=>{y.scrollTop=y.scrollHeight})}function Ze(m){A&&m.some(v=>v.role==="user")&&(A.remove(),A=null);for(let v=O;v<m.length;v++){let S=f.createBubble(m[v]);y.appendChild(S)}O=m.length,Z()}function Ue(m){if(m){L||(u&&(u.remove(),u=null),L=f.createStreaming(),y.appendChild(L));let v=L._namiruTextEl,S=ne(m);v?v.innerHTML=S:L.innerHTML=S,Z()}else L&&(L.remove(),L=null)}function qe(m){m&&!u&&!L?(u=f.createLoading(),y.appendChild(u),Z()):!m&&u&&(u.remove(),u=null)}let z=null;return e.subscribe(m=>{if(console.log("[ChatWindow] subscriber:","state="+m.state,"msgs="+m.messages.length,"open="+m.isOpen,"input="+T?.style.display,"prev="+(z?.state||"null")),i==="button"&&(m.isOpen?x.classList.add("namiru-popup--open"):x.classList.remove("namiru-popup--open")),!z||z.state!==m.state)switch(m.state){case"idle":j(),T.style.display="none",q();break;case"connecting":T.style.display="none",Re();break;case"pre_chat":Ge();break;case"chatting":q(),z?.state==="pre_chat"&&j(),T.style.display="",ze();break;case"feedback":pe(!0);break;case"escalation":de();break;case"email_fallback":me();break;case"conversation_limit":q(),T.style.display="none",ue();break;case"domain_error":q(),T.style.display="none",We();break;case"error":q(),T.style.display="none";break}m.messages.length>O&&m.state!=="pre_chat"&&Ze(m.messages),m.state==="chatting"&&m.messages.length>=W&&e.dispatch({type:"SET_STATE",state:"conversation_limit"}),z?.streamingContent!==m.streamingContent&&Ue(m.streamingContent),z?.isLoading!==m.isLoading&&qe(m.isLoading),z=m}),x._namiruShowEscalation=de,x._namiruShowFeedback=pe,x._namiruShowTranscript=ce,x._namiruShowContactForm=me,x._namiruShowLimitOverlay=ue,x._namiruShowCloseConfirmation=()=>re(N,e),x}function Pe(n){let{position:e,store:t,welcomeMessage:a,greetingDelay:i,bubbleStyle:r,onCloseRequest:l}=n,o=document.createElement("div"),s=document.createElement("button");s.className=`namiru-button namiru-button--${e}`,r==="classic"&&s.classList.add("namiru-button--classic"),s.setAttribute("aria-label","Open chat");let c=Ee(),d=ae();d.style.display="none",s.appendChild(c),s.appendChild(d),s.addEventListener("click",()=>{let E=t.getState().isOpen;E&&l?l():t.dispatch({type:"SET_OPEN",isOpen:!E})}),o.appendChild(s);let p=null,k=!1,h=null;if(a){p=document.createElement("div"),p.className=`namiru-greeting namiru-greeting--${e} namiru-greeting--hidden`;let E=document.createTextNode(a);p.appendChild(E);let f=document.createElement("button");f.className="namiru-greeting-close",f.setAttribute("aria-label","Dismiss"),f.textContent="\xD7",f.addEventListener("click",N=>{N.stopPropagation(),C()}),p.appendChild(f),p.addEventListener("click",()=>{C(),t.dispatch({type:"SET_OPEN",isOpen:!0})}),o.appendChild(p),h=setTimeout(()=>{!t.getState().isOpen&&p&&(p.classList.remove("namiru-greeting--hidden"),k=!0,setTimeout(()=>C(),3e4))},i??3e3)}function C(){k&&p&&(p.classList.add("namiru-greeting--hidden"),k=!1),h&&(clearTimeout(h),h=null)}return t.subscribe(E=>{E.isOpen?(c.style.display="none",d.style.display="",s.setAttribute("aria-label","Close chat"),C()):(c.style.display="",d.style.display="none",s.setAttribute("aria-label","Open chat"))}),o}function ht(n){try{let e=new URL(n),t=e.protocol==="https:"?"wss:":"ws:";return e.hostname==="localhost"||e.hostname==="127.0.0.1"?(e.port="3423",e.protocol=t,e.origin):e.hostname==="test.namiru.ai"?`${t}//ai-test.namiru.ai`:e.hostname==="namiru.ai"||e.hostname==="app.namiru.ai"||e.hostname==="api.namiru.ai"?`${t}//ai.namiru.ai`:(e.protocol=t,e.origin)}catch{let e=n.startsWith("https")?"wss":"ws",t=n.replace(/^https?:\/\//,"");return`${e}://${t}`}}function ft(n){try{let e=new URL(n);return e.hostname.startsWith("app.")?(e.hostname=e.hostname.replace("app.","api."),e.origin):e.hostname==="test.namiru.ai"?(e.hostname="api-test.namiru.ai",e.origin):e.hostname==="namiru.ai"?(e.hostname="api.namiru.ai",e.origin):((e.hostname==="localhost"||e.hostname==="127.0.0.1")&&(e.port="3001"),e.origin)}catch{return n}}function bt(n){let e,t=null;if(n.serverUrl)e=n.serverUrl.replace(/\/$/,"");else{let a=document.querySelectorAll("script[src]");for(let i=a.length-1;i>=0;i--){let r=a[i].src;if(r.includes("namiru-chat")||r.includes("namiru"))try{t=new URL(r).origin;break}catch{}}e=ft(t||location.origin)}return{apiBase:e,wsUrl:n.wsUrl||ht(t||e)}}var Be="namiru_visitor_id";function le(){try{let n=localStorage.getItem(Be);if(n)return n;let e=`v_${Date.now()}_${Math.random().toString(36).substring(2,11)}`;return localStorage.setItem(Be,e),e}catch{return`v_${Date.now()}_${Math.random().toString(36).substring(2,11)}`}}var Ve=0;function ie(){return Ve++,`msg-${Date.now()}-${Ve}`}function Fe(n){if(!n||n.length===0)return!1;let e=window.location.pathname;return n.some(t=>{if(t.endsWith("/*")){let a=t.slice(0,-1);return e.startsWith(a)||e===a.slice(0,-1)}if(t.endsWith("*")){let a=t.slice(0,-1);return e.startsWith(a)}return e===t})}function xt(n,e){if(!e)return()=>{};let t="namiru:locationchange",a=history.pushState.bind(history),i=history.replaceState.bind(history);history.pushState=function(...l){a(...l),window.dispatchEvent(new Event(t))},history.replaceState=function(...l){i(...l),window.dispatchEvent(new Event(t))};function r(){Fe(n)?e.style.display="none":e.style.display=""}return window.addEventListener(t,r),window.addEventListener("popstate",r),()=>{history.pushState=a,history.replaceState=i,window.removeEventListener(t,r),window.removeEventListener("popstate",r)}}function yt(n){if(!n||n.length===0)return!0;let e=window.location.hostname.toLowerCase();return e==="localhost"||e==="127.0.0.1"||e==="namiru.ai"||e.endsWith(".namiru.ai")?!0:n.some(t=>{let a=t.toLowerCase();return e===a||e.endsWith("."+a)})}function vt(n){if(!n.agentId)throw new Error("NamiruChat: agentId is required");let e=n.mode||"button",t=n.position||"bottom-right",{apiBase:a,wsUrl:i}=bt(n),r=new Y,l=new J({baseUrl:a}),o=null,s=null,c=null,d=null,p=null,k=null,h=!1,C="handoff_accepted",E=!1,f=null,x=!1,N=null;s=document.createElement("div"),s.id="namiru-widget-host";let y=typeof s.attachShadow=="function";fe(y),y&&(s.style.cssText="all:initial;position:fixed;top:0;left:0;width:0;height:0;overflow:visible;z-index:2147483646;pointer-events:none;",c=s.attachShadow({mode:"open"})),d=document.createElement("div"),d.className="namiru-widget-root";let T=c||s;y&&(d.style.pointerEvents="auto"),T.appendChild(d);async function G(){try{let u=await l.fetchBranding(n.agentId);if(h)return;if(!yt(u.allowedDomains)){console.warn(`[Namiru Widget] Domain "${window.location.hostname}" is not allowed for this agent. Allowed: ${JSON.stringify(u.allowedDomains)}`);return}if(Fe(u.excludedRoutes)){console.info(`[Namiru Widget] Widget hidden on excluded route "${window.location.pathname}"`);return}xe({primaryColor:u.primaryColor,accentColor:u.accentColor,headerColor:u.headerColor,fontFamily:u.fontFamily,presetTheme:u.presetTheme,backgroundColor:u.backgroundColor,textColor:u.textColor,fontSize:u.fontSize,userMessageColor:u.userMessageColor,agentMessageColor:u.agentMessageColor,borderColor:u.borderColor,inputColor:u.inputColor,buttonColor:u.buttonColor},T,!y),n.suggestedQuestions&&n.suggestedQuestions.length>0&&(u.suggestedQuestions=n.suggestedQuestions),console.log("[NamiruChat] suggestedQuestions:",u.suggestedQuestions);let b=n.preChatEnabled??u.preChatConfig?.enabled??!1;b&&(u.preChatConfig?(u.preChatConfig.enabled=!0,n.preChatTemplate!==void 0&&(u.preChatConfig.template=n.preChatTemplate),n.preChatCustom&&(u.preChatConfig.custom=n.preChatCustom)):u.preChatConfig={enabled:!0,template:n.preChatTemplate??null,custom:n.preChatCustom}),x=u.feedbackConfig?.enabled??!1;let _=u.feedbackConfig?.inactivityMinutes??3;if(x&&(f=new X(_,()=>{let g=r.getState();!g.feedbackGiven&&g.state==="chatting"&&g.messages.length>0&&r.dispatch({type:"SET_STATE",state:"feedback"})})),p=De({store:r,branding:u,agentId:n.agentId,mode:e,position:t,onSendMessage:g=>{let w={id:ie(),role:"user",content:g,timestamp:Date.now()};r.dispatch({type:"ADD_MESSAGE",message:w}),r.dispatch({type:"SET_LOADING",isLoading:!0}),o&&o.sendMessage(g)},onPreChatSelect:g=>{r.dispatch({type:"SET_QUALIFICATION",qualification:g}),r.dispatch({type:"SET_STATE",state:"connecting"}),W(g)},onFeedback:g=>{let w=r.getState().sessionId;w&&l.submitFeedback(n.agentId,{sessionId:w,rating:g}).catch(A=>console.error("NamiruChat: feedback submit failed",A)),r.dispatch({type:"SET_FEEDBACK_GIVEN"}),f?.stop(),n.onFeedback?.(g)},onEscalationEmail:g=>{let w=r.getState().sessionId;w&&l.submitEscalation(n.agentId,{sessionId:w,userEmail:g}).catch(A=>console.error("NamiruChat: escalation submit failed",A)),o&&o.sendEscalationEmail(g),n.onLeadCapture?.({email:g,sessionId:w||"",source:"email_fallback",qualification:r.getState().qualification||void 0})},onTranscriptEmail:g=>{let w=r.getState().sessionId;w&&l.requestTranscript(n.agentId,w,{email:g}).catch(A=>console.error("NamiruChat: transcript request failed",A))},onContactFormSubmit:g=>{let w=le(),A=r.getState().sessionId;l.submitLead({agentId:n.agentId,name:g.name||void 0,email:g.email,message:g.message,visitorId:w,fallbackReason:C,conversationId:A||void 0}).catch(R=>console.error("NamiruChat: lead submit failed",R)),o&&o.sendHandoffComplete({email:g.email,name:g.name||void 0,reason:C}),n.onLeadCapture?.({email:g.email,sessionId:A||"",source:"email_fallback",qualification:r.getState().qualification||void 0})},onLimitMessage:g=>{g.visitorEmail?l.submitContactMessage(n.agentId,{email:g.visitorEmail,message:g.message,visitorId:le()}).catch(w=>console.error("NamiruChat: contact message submit failed",w)):l.submitLimitMessage({agentId:n.agentId,message:g.message}).catch(w=>console.error("NamiruChat: limit message submit failed",w))},feedbackEnabled:x,onNewChat:()=>{o&&(o.disconnect(),o=null),f?.stop(),r.dispatch({type:"RESET"}),r.dispatch({type:"SET_OPEN",isOpen:!0}),r.dispatch({type:"SET_STATE",state:"connecting"}),W()}}),d.appendChild(p),e==="button"&&(k=Pe({position:t,store:r,welcomeMessage:u.bubbleGreeting||void 0,greetingDelay:n.greetingDelay,bubbleStyle:u.bubbleStyle,onCloseRequest:()=>{let g=r.getState();if(x&&!g.feedbackGiven&&g.state==="chatting"&&g.messages.length>0){r.dispatch({type:"SET_STATE",state:"feedback"});return}if(g.messages.length===0){r.dispatch({type:"SET_OPEN",isOpen:!1});return}let w=p?._namiruShowCloseConfirmation;typeof w=="function"?w():r.dispatch({type:"SET_OPEN",isOpen:!1})}}),d.appendChild(k)),e==="inline"&&p){let g=n.width||"100%",w=n.height||"100%";p.style.width=g,p.style.height=w,p.style.maxHeight=w,d.style.height="100%"}if(y?e==="inline"&&n.container?(s.style.cssText="all:initial;display:block;height:100%;",n.container.appendChild(s)):document.body.appendChild(s):e==="inline"&&n.container?n.container.appendChild(d):document.body.appendChild(d),b?r.dispatch({type:"SET_STATE",state:"pre_chat"}):(r.dispatch({type:"SET_STATE",state:"connecting"}),W()),e==="inline"&&r.dispatch({type:"SET_OPEN",isOpen:!0}),u.excludedRoutes&&u.excludedRoutes.length>0){let g=y?s:d;N=xt(u.excludedRoutes,g)}}catch(u){console.error("NamiruChat: initialization failed",u),r.dispatch({type:"SET_ERROR",error:"Failed to load chat. Please try again later."})}}function F(){E&&(E=!1,p&&setTimeout(()=>{let u=p?._namiruShowEscalation;typeof u=="function"&&u()},100))}function W(u){o||h||(o=new K({url:i,agentId:n.agentId,visitorId:le()}),o.on("connected",()=>{}),o.on("agent_initialized",b=>{r.dispatch({type:"SET_STATE",state:"chatting"}),r.dispatch({type:"SET_LOADING",isLoading:!1}),b.data.sessionId&&(r.dispatch({type:"SET_SESSION_ID",sessionId:b.data.sessionId}),n.onSessionStart?.(b.data.sessionId)),u&&o?.sendMessage(`[User selected: ${u}]`)}),o.on("stream_token",b=>{r.dispatch({type:"APPEND_STREAMING",token:b.data.token})}),o.on("final_response",b=>{r.dispatch({type:"CLEAR_STREAMING"});let _={id:ie(),role:"assistant",content:b.data.content||b.data.response||"",timestamp:Date.now()};r.dispatch({type:"ADD_MESSAGE",message:_}),r.dispatch({type:"SET_LOADING",isLoading:!1}),F(),x&&b.data.conversationMayHaveEnded&&!r.getState().feedbackGiven?(setTimeout(()=>{let g=r.getState();!g.feedbackGiven&&g.state==="chatting"&&g.messages.length>0&&r.dispatch({type:"SET_STATE",state:"feedback"})},800),f?.stop()):f&&!r.getState().feedbackGiven&&f.reset()}),o.on("stream_end",()=>{let b=r.getState().streamingContent;if(b){r.dispatch({type:"CLEAR_STREAMING"});let _={id:ie(),role:"assistant",content:b,timestamp:Date.now()};r.dispatch({type:"ADD_MESSAGE",message:_})}r.dispatch({type:"SET_LOADING",isLoading:!1}),F(),f&&!r.getState().feedbackGiven&&f.reset()}),o.on("tool_start",()=>{r.dispatch({type:"SET_LOADING",isLoading:!0})}),o.on("tool_end",()=>{}),o.on("kit_trigger",b=>{let _=b.data;(_==="escalation_email_form"||_?.type==="escalation_email_form")&&(E=!0)}),o.on("handoff_active",b=>{let _={id:ie(),role:"assistant",content:b.data?.message||"A human operator is currently handling this conversation. Please wait for their response.",timestamp:Date.now()};r.dispatch({type:"ADD_MESSAGE",message:_}),r.dispatch({type:"SET_LOADING",isLoading:!1})}),o.on("show_handoff_form",b=>{C=b.data?.reason||"handoff_accepted",r.dispatch({type:"SET_STATE",state:"email_fallback"}),r.dispatch({type:"SET_LOADING",isLoading:!1})}),o.on("error",b=>{if(b.data?.type==="usage_limit"||b.data?.usage_limit){r.dispatch({type:"SET_STATE",state:"conversation_limit"}),r.dispatch({type:"SET_LOADING",isLoading:!1});return}if(b.data?.message==="Domain not authorized"){r.dispatch({type:"SET_STATE",state:"domain_error"}),r.dispatch({type:"SET_LOADING",isLoading:!1});return}console.error("NamiruChat: WebSocket error",b.data),r.dispatch({type:"SET_ERROR",error:b.data?.message||"Connection error. Please try again."}),r.dispatch({type:"SET_LOADING",isLoading:!1})}),o.on("disconnected",()=>{}),o.connect())}G();let O=!1,L=!1;return r.subscribe(u=>{if(!(h||L)){if(O&&!u.isOpen){O=!1,L=!0,o&&(o.disconnect(),o=null),f?.stop(),L=!1;return}if(!O&&u.isOpen&&!o){O=!0,L=!0,r.dispatch({type:"SET_STATE",state:"connecting"}),W(),L=!1;return}O=u.isOpen}}),{open:()=>{h||r.dispatch({type:"SET_OPEN",isOpen:!0})},close:()=>{h||r.dispatch({type:"SET_OPEN",isOpen:!1})},toggle:()=>{if(!h){let u=r.getState().isOpen;r.dispatch({type:"SET_OPEN",isOpen:!u})}},destroy:()=>{if(h)return;h=!0,N?.(),N=null,o?.disconnect(),f?.stop(),ye();let u=y?s:d;u&&u.parentNode&&u.parentNode.removeChild(u);let b=r.getState().sessionId;b&&n.onSessionEnd?.(b),r.dispatch({type:"RESET"}),s=null,c=null,d=null,p=null,k=null,o=null},updateConfig:u=>{h||Object.assign(n,u)}}}if(typeof document<"u"&&document.currentScript){let n=document.currentScript,e=n.getAttribute("data-agent-id");if(e){let t=n.getAttribute("data-mode")||"button",a=n.getAttribute("data-server-url")||void 0,i=n.getAttribute("data-container-id");vt({agentId:e,mode:t,serverUrl:a,container:i&&document.getElementById(i)||void 0})}}export{vt as init};
1091
+ `,Q.textContent="Reload",Q.addEventListener("click",()=>window.location.reload()),H.appendChild(Q),m.appendChild(H),y.appendChild(m)}function pe(m){L||(L=Ie({onFeedback:v=>{s(v),i==="button"&&setTimeout(()=>{e.dispatch({type:"RESET"}),e.dispatch({type:"SET_OPEN",isOpen:!1})},800)},softPrompt:m}),y.appendChild(L),Z())}function Z(){requestAnimationFrame(()=>{y.scrollTop=y.scrollHeight})}function Ue(m){A&&m.some(v=>v.role==="user")&&(A.remove(),A=null);for(let v=O;v<m.length;v++){let S=f.createBubble(m[v]);y.appendChild(S)}O=m.length,Z()}function qe(m){if(m){_||(u&&(u.remove(),u=null),_=f.createStreaming(),y.appendChild(_));let v=_._namiruTextEl,S=ne(m);v?v.innerHTML=S:_.innerHTML=S,Z()}else _&&(_.remove(),_=null)}function je(m){m&&!u&&!_?(u=f.createLoading(),y.appendChild(u),Z()):!m&&u&&(u.remove(),u=null)}let z=null;return e.subscribe(m=>{if(console.log("[ChatWindow] subscriber:","state="+m.state,"msgs="+m.messages.length,"open="+m.isOpen,"input="+T?.style.display,"prev="+(z?.state||"null")),i==="button"&&(m.isOpen?x.classList.add("namiru-popup--open"):x.classList.remove("namiru-popup--open")),!z||z.state!==m.state)switch(m.state){case"idle":j(),T.style.display="none",q();break;case"connecting":T.style.display="none",ze();break;case"pre_chat":We();break;case"chatting":q(),z?.state==="pre_chat"&&j(),T.style.display="",Ge();break;case"feedback":pe(!0);break;case"escalation":de();break;case"email_fallback":me();break;case"conversation_limit":q(),T.style.display="none",ue();break;case"domain_error":q(),T.style.display="none",Ze();break;case"error":q(),T.style.display="none";break}m.messages.length>O&&m.state!=="pre_chat"&&Ue(m.messages),m.state==="chatting"&&m.messages.length>=W&&e.dispatch({type:"SET_STATE",state:"conversation_limit"}),z?.streamingContent!==m.streamingContent&&qe(m.streamingContent),z?.isLoading!==m.isLoading&&je(m.isLoading),z=m}),x._namiruShowEscalation=de,x._namiruShowFeedback=pe,x._namiruShowTranscript=ce,x._namiruShowContactForm=me,x._namiruShowLimitOverlay=ue,x._namiruShowCloseConfirmation=()=>re(N,e),x}function De(n){let{position:e,store:t,welcomeMessage:a,greetingDelay:i,bubbleStyle:r,onCloseRequest:l}=n,o=document.createElement("div"),s=document.createElement("button");s.className=`namiru-button namiru-button--${e}`,r==="classic"&&s.classList.add("namiru-button--classic"),s.setAttribute("aria-label","Open chat");let c=Ee(),d=ae();d.style.display="none",s.appendChild(c),s.appendChild(d),s.addEventListener("click",()=>{let E=t.getState().isOpen;E&&l?l():t.dispatch({type:"SET_OPEN",isOpen:!E})}),o.appendChild(s);let p=null,k=!1,h=null;if(a){p=document.createElement("div"),p.className=`namiru-greeting namiru-greeting--${e} namiru-greeting--hidden`;let E=document.createTextNode(a);p.appendChild(E);let f=document.createElement("button");f.className="namiru-greeting-close",f.setAttribute("aria-label","Dismiss"),f.textContent="\xD7",f.addEventListener("click",N=>{N.stopPropagation(),C()}),p.appendChild(f),p.addEventListener("click",()=>{C(),t.dispatch({type:"SET_OPEN",isOpen:!0})}),o.appendChild(p),h=setTimeout(()=>{!t.getState().isOpen&&p&&(p.classList.remove("namiru-greeting--hidden"),k=!0,setTimeout(()=>C(),3e4))},i??3e3)}function C(){k&&p&&(p.classList.add("namiru-greeting--hidden"),k=!1),h&&(clearTimeout(h),h=null)}return t.subscribe(E=>{E.isOpen?(c.style.display="none",d.style.display="",s.setAttribute("aria-label","Close chat"),C()):(c.style.display="",d.style.display="none",s.setAttribute("aria-label","Open chat"))}),o}var ft="https://api.namiru.ai",Pe="wss://ai.namiru.ai",bt="https://api-test.namiru.ai",xt="wss://ai-test.namiru.ai";function yt(n){return n==="localhost"||n==="127.0.0.1"||n==="0.0.0.0"}function vt(n){if(n.serverUrl)return{apiBase:n.serverUrl.replace(/\/$/,""),wsUrl:n.wsUrl||Pe};let e=window.location.hostname;return yt(e)?{apiBase:`${window.location.protocol}//${e}:3001`,wsUrl:n.wsUrl||`${window.location.protocol==="https:"?"wss:":"ws:"}//${e}:3423`}:e==="test.namiru.ai"?{apiBase:bt,wsUrl:n.wsUrl||xt}:{apiBase:ft,wsUrl:n.wsUrl||Pe}}var Ve="namiru_visitor_id";function le(){try{let n=localStorage.getItem(Ve);if(n)return n;let e=`v_${Date.now()}_${Math.random().toString(36).substring(2,11)}`;return localStorage.setItem(Ve,e),e}catch{return`v_${Date.now()}_${Math.random().toString(36).substring(2,11)}`}}var Fe=0;function ie(){return Fe++,`msg-${Date.now()}-${Fe}`}function Re(n){if(!n||n.length===0)return!1;let e=window.location.pathname;return n.some(t=>{if(t.endsWith("/*")){let a=t.slice(0,-1);return e.startsWith(a)||e===a.slice(0,-1)}if(t.endsWith("*")){let a=t.slice(0,-1);return e.startsWith(a)}return e===t})}function Ct(n,e){if(!e)return()=>{};let t="namiru:locationchange",a=history.pushState.bind(history),i=history.replaceState.bind(history);history.pushState=function(...l){a(...l),window.dispatchEvent(new Event(t))},history.replaceState=function(...l){i(...l),window.dispatchEvent(new Event(t))};function r(){Re(n)?e.style.display="none":e.style.display=""}return window.addEventListener(t,r),window.addEventListener("popstate",r),()=>{history.pushState=a,history.replaceState=i,window.removeEventListener(t,r),window.removeEventListener("popstate",r)}}function Et(n){if(!n||n.length===0)return!0;let e=window.location.hostname.toLowerCase();return e==="localhost"||e==="127.0.0.1"||e==="namiru.ai"||e.endsWith(".namiru.ai")?!0:n.some(t=>{let a=t.toLowerCase();return e===a||e.endsWith("."+a)})}function wt(n){if(!n.agentId)throw new Error("NamiruChat: agentId is required");let e=n.mode||"button",t=n.position||"bottom-right",{apiBase:a,wsUrl:i}=vt(n),r=new Y,l=new J({baseUrl:a}),o=null,s=null,c=null,d=null,p=null,k=null,h=!1,C="handoff_accepted",E=!1,f=null,x=!1,N=null;s=document.createElement("div"),s.id="namiru-widget-host";let y=typeof s.attachShadow=="function";fe(y),y&&(s.style.cssText="all:initial;position:fixed;top:0;left:0;width:0;height:0;overflow:visible;z-index:2147483646;pointer-events:none;",c=s.attachShadow({mode:"open"})),d=document.createElement("div"),d.className="namiru-widget-root";let T=c||s;y&&(d.style.pointerEvents="auto"),T.appendChild(d);async function G(){try{let u=await l.fetchBranding(n.agentId);if(h)return;if(!Et(u.allowedDomains)){console.warn(`[Namiru Widget] Domain "${window.location.hostname}" is not allowed for this agent. Allowed: ${JSON.stringify(u.allowedDomains)}`);return}if(Re(u.excludedRoutes)){console.info(`[Namiru Widget] Widget hidden on excluded route "${window.location.pathname}"`);return}xe({primaryColor:u.primaryColor,accentColor:u.accentColor,headerColor:u.headerColor,fontFamily:u.fontFamily,presetTheme:u.presetTheme,backgroundColor:u.backgroundColor,textColor:u.textColor,fontSize:u.fontSize,userMessageColor:u.userMessageColor,agentMessageColor:u.agentMessageColor,borderColor:u.borderColor,inputColor:u.inputColor,buttonColor:u.buttonColor},T,!y),n.suggestedQuestions&&n.suggestedQuestions.length>0&&(u.suggestedQuestions=n.suggestedQuestions),console.log("[NamiruChat] suggestedQuestions:",u.suggestedQuestions);let b=n.preChatEnabled??u.preChatConfig?.enabled??!1;b&&(u.preChatConfig?(u.preChatConfig.enabled=!0,n.preChatTemplate!==void 0&&(u.preChatConfig.template=n.preChatTemplate),n.preChatCustom&&(u.preChatConfig.custom=n.preChatCustom)):u.preChatConfig={enabled:!0,template:n.preChatTemplate??null,custom:n.preChatCustom}),x=u.feedbackConfig?.enabled??!1;let L=u.feedbackConfig?.inactivityMinutes??3;if(x&&(f=new X(L,()=>{let g=r.getState();!g.feedbackGiven&&g.state==="chatting"&&g.messages.length>0&&r.dispatch({type:"SET_STATE",state:"feedback"})})),p=Be({store:r,branding:u,agentId:n.agentId,mode:e,position:t,onSendMessage:g=>{let w={id:ie(),role:"user",content:g,timestamp:Date.now()};r.dispatch({type:"ADD_MESSAGE",message:w}),r.dispatch({type:"SET_LOADING",isLoading:!0}),o&&o.sendMessage(g)},onPreChatSelect:g=>{r.dispatch({type:"SET_QUALIFICATION",qualification:g}),r.dispatch({type:"SET_STATE",state:"connecting"}),W(g)},onFeedback:g=>{let w=r.getState().sessionId;w&&l.submitFeedback(n.agentId,{sessionId:w,rating:g}).catch(A=>console.error("NamiruChat: feedback submit failed",A)),r.dispatch({type:"SET_FEEDBACK_GIVEN"}),f?.stop(),n.onFeedback?.(g)},onEscalationEmail:g=>{let w=r.getState().sessionId;w&&l.submitEscalation(n.agentId,{sessionId:w,userEmail:g}).catch(A=>console.error("NamiruChat: escalation submit failed",A)),o&&o.sendEscalationEmail(g),n.onLeadCapture?.({email:g,sessionId:w||"",source:"email_fallback",qualification:r.getState().qualification||void 0})},onTranscriptEmail:g=>{let w=r.getState().sessionId;w&&l.requestTranscript(n.agentId,w,{email:g}).catch(A=>console.error("NamiruChat: transcript request failed",A))},onContactFormSubmit:g=>{let w=le(),A=r.getState().sessionId;l.submitLead({agentId:n.agentId,name:g.name||void 0,email:g.email,message:g.message,visitorId:w,fallbackReason:C,conversationId:A||void 0}).catch(R=>console.error("NamiruChat: lead submit failed",R)),o&&o.sendHandoffComplete({email:g.email,name:g.name||void 0,reason:C}),n.onLeadCapture?.({email:g.email,sessionId:A||"",source:"email_fallback",qualification:r.getState().qualification||void 0})},onLimitMessage:g=>{g.visitorEmail?l.submitContactMessage(n.agentId,{email:g.visitorEmail,message:g.message,visitorId:le()}).catch(w=>console.error("NamiruChat: contact message submit failed",w)):l.submitLimitMessage({agentId:n.agentId,message:g.message}).catch(w=>console.error("NamiruChat: limit message submit failed",w))},feedbackEnabled:x,onNewChat:()=>{o&&(o.disconnect(),o=null),f?.stop(),r.dispatch({type:"RESET"}),r.dispatch({type:"SET_OPEN",isOpen:!0}),r.dispatch({type:"SET_STATE",state:"connecting"}),W()}}),d.appendChild(p),e==="button"&&(k=De({position:t,store:r,welcomeMessage:u.bubbleGreeting||void 0,greetingDelay:n.greetingDelay,bubbleStyle:u.bubbleStyle,onCloseRequest:()=>{let g=r.getState();if(x&&!g.feedbackGiven&&g.state==="chatting"&&g.messages.length>0){r.dispatch({type:"SET_STATE",state:"feedback"});return}if(g.messages.length===0){r.dispatch({type:"SET_OPEN",isOpen:!1});return}let w=p?._namiruShowCloseConfirmation;typeof w=="function"?w():r.dispatch({type:"SET_OPEN",isOpen:!1})}}),d.appendChild(k)),e==="inline"&&p){let g=n.width||"100%",w=n.height||"100%";p.style.width=g,p.style.height=w,p.style.maxHeight=w,d.style.height="100%"}if(y?e==="inline"&&n.container?(s.style.cssText="all:initial;display:block;height:100%;",n.container.appendChild(s)):document.body.appendChild(s):e==="inline"&&n.container?n.container.appendChild(d):document.body.appendChild(d),b?r.dispatch({type:"SET_STATE",state:"pre_chat"}):(r.dispatch({type:"SET_STATE",state:"connecting"}),W()),e==="inline"&&r.dispatch({type:"SET_OPEN",isOpen:!0}),u.excludedRoutes&&u.excludedRoutes.length>0){let g=y?s:d;N=Ct(u.excludedRoutes,g)}}catch(u){console.error("NamiruChat: initialization failed",u),r.dispatch({type:"SET_ERROR",error:"Failed to load chat. Please try again later."})}}function F(){E&&(E=!1,p&&setTimeout(()=>{let u=p?._namiruShowEscalation;typeof u=="function"&&u()},100))}function W(u){o||h||(o=new K({url:i,agentId:n.agentId,visitorId:le()}),o.on("connected",()=>{}),o.on("agent_initialized",b=>{r.dispatch({type:"SET_STATE",state:"chatting"}),r.dispatch({type:"SET_LOADING",isLoading:!1}),b.data.sessionId&&(r.dispatch({type:"SET_SESSION_ID",sessionId:b.data.sessionId}),n.onSessionStart?.(b.data.sessionId)),u&&o?.sendMessage(`[User selected: ${u}]`)}),o.on("stream_token",b=>{r.dispatch({type:"APPEND_STREAMING",token:b.data.token})}),o.on("final_response",b=>{r.dispatch({type:"CLEAR_STREAMING"});let L={id:ie(),role:"assistant",content:b.data.content||b.data.response||"",timestamp:Date.now()};r.dispatch({type:"ADD_MESSAGE",message:L}),r.dispatch({type:"SET_LOADING",isLoading:!1}),F(),x&&b.data.conversationMayHaveEnded&&!r.getState().feedbackGiven?(setTimeout(()=>{let g=r.getState();!g.feedbackGiven&&g.state==="chatting"&&g.messages.length>0&&r.dispatch({type:"SET_STATE",state:"feedback"})},800),f?.stop()):f&&!r.getState().feedbackGiven&&f.reset()}),o.on("stream_end",()=>{let b=r.getState().streamingContent;if(b){r.dispatch({type:"CLEAR_STREAMING"});let L={id:ie(),role:"assistant",content:b,timestamp:Date.now()};r.dispatch({type:"ADD_MESSAGE",message:L})}r.dispatch({type:"SET_LOADING",isLoading:!1}),F(),f&&!r.getState().feedbackGiven&&f.reset()}),o.on("tool_start",()=>{r.dispatch({type:"SET_LOADING",isLoading:!0})}),o.on("tool_end",()=>{}),o.on("kit_trigger",b=>{let L=b.data;(L==="escalation_email_form"||L?.type==="escalation_email_form")&&(E=!0)}),o.on("handoff_active",b=>{let L={id:ie(),role:"assistant",content:b.data?.message||"A human operator is currently handling this conversation. Please wait for their response.",timestamp:Date.now()};r.dispatch({type:"ADD_MESSAGE",message:L}),r.dispatch({type:"SET_LOADING",isLoading:!1})}),o.on("show_handoff_form",b=>{C=b.data?.reason||"handoff_accepted",r.dispatch({type:"SET_STATE",state:"email_fallback"}),r.dispatch({type:"SET_LOADING",isLoading:!1})}),o.on("error",b=>{if(b.data?.type==="usage_limit"||b.data?.usage_limit){r.dispatch({type:"SET_STATE",state:"conversation_limit"}),r.dispatch({type:"SET_LOADING",isLoading:!1});return}if(b.data?.message==="Domain not authorized"){r.dispatch({type:"SET_STATE",state:"domain_error"}),r.dispatch({type:"SET_LOADING",isLoading:!1});return}console.error("NamiruChat: WebSocket error",b.data),r.dispatch({type:"SET_ERROR",error:b.data?.message||"Connection error. Please try again."}),r.dispatch({type:"SET_LOADING",isLoading:!1})}),o.on("disconnected",()=>{}),o.connect())}G();let O=!1,_=!1;return r.subscribe(u=>{if(!(h||_)){if(O&&!u.isOpen){O=!1,_=!0,o&&(o.disconnect(),o=null),f?.stop(),_=!1;return}if(!O&&u.isOpen&&!o){O=!0,_=!0,r.dispatch({type:"SET_STATE",state:"connecting"}),W(),_=!1;return}O=u.isOpen}}),{open:()=>{h||r.dispatch({type:"SET_OPEN",isOpen:!0})},close:()=>{h||r.dispatch({type:"SET_OPEN",isOpen:!1})},toggle:()=>{if(!h){let u=r.getState().isOpen;r.dispatch({type:"SET_OPEN",isOpen:!u})}},destroy:()=>{if(h)return;h=!0,N?.(),N=null,o?.disconnect(),f?.stop(),ye();let u=y?s:d;u&&u.parentNode&&u.parentNode.removeChild(u);let b=r.getState().sessionId;b&&n.onSessionEnd?.(b),r.dispatch({type:"RESET"}),s=null,c=null,d=null,p=null,k=null,o=null},updateConfig:u=>{h||Object.assign(n,u)}}}if(typeof document<"u"&&document.currentScript){let n=document.currentScript,e=n.getAttribute("data-agent-id");if(e){let t=n.getAttribute("data-mode")||"button",a=n.getAttribute("data-server-url")||void 0,i=n.getAttribute("data-container-id");wt({agentId:e,mode:t,serverUrl:a,container:i&&document.getElementById(i)||void 0})}}export{wt as init};
1092
1092
  //# sourceMappingURL=namiru-chat.esm.js.map