@namiruai/chat 1.15.0 → 1.16.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 Ye(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=Ye(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})}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 R=!1;function fe(n){R=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=Xe(a,t),e instanceof ShadowRoot||e.shadowRoot?e.appendChild(i):document.head.appendChild(i),te=i}function ye(){te&&(te.remove(),te=null)}function Je(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 Ke(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 Xe(n,e){let t=e?" !important":"",a=n.primaryColor,i=n.accentColor||"#21DFFB",r=Je(n.fontFamily),l=Ke(n.fontSize),o=n.presetTheme==="dark",s=n.backgroundColor||(o?"#0f0f1a":"#ffffff"),d=n.textColor||(o?"#ffffff":"#1f2937"),c=!ee(s),g=n.borderColor||(c?"rgba(255,255,255,0.15)":"rgba(0,0,0,0.1)"),S=n.inputColor||(c?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.02)"),h=c?"rgba(255,255,255,0.6)":"rgba(0,0,0,0.45)",x=c?"rgba(255,255,255,0.2)":"rgba(0,0,0,0.12)",f=n.headerColor||s,v=n.headerColor?ee(f)?"#1f2937":"#ffffff":d,y=n.headerColor?ee(f)?"rgba(0,0,0,0.5)":"rgba(255,255,255,0.7)":h,T=n.buttonColor||(c?"#0f0f1a":a),E=be(T,-15),A=n.userMessageColor!==void 0?n.userMessageColor||"transparent":a,B=A==="transparent"?d:ee(A)?"#1f2937":"#ffffff";return`
1
+ function he(){return{state:"idle",messages:[],isOpen:!1,isLoading:!1,streamingContent:"",qualification:null,feedbackGiven:!1,sessionId:null,error:null}}function Ye(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=Ye(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})}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 R=!1;function fe(n){R=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=Xe(a,t),e instanceof ShadowRoot||e.shadowRoot?e.appendChild(i):document.head.appendChild(i),te=i}function ye(){te&&(te.remove(),te=null)}function Je(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 Ke(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 Xe(n,e){let t=e?" !important":"",a=n.primaryColor,i=n.accentColor||"#21DFFB",r=Je(n.fontFamily),l=Ke(n.fontSize),o=n.presetTheme==="dark",s=n.backgroundColor||(o?"#0f0f1a":"#ffffff"),c=n.textColor||(o?"#ffffff":"#1f2937"),m=!ee(s),p=n.borderColor||(m?"rgba(255,255,255,0.15)":"rgba(0,0,0,0.1)"),w=n.inputColor||(m?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.02)"),h=m?"rgba(255,255,255,0.6)":"rgba(0,0,0,0.45)",S=m?"rgba(255,255,255,0.2)":"rgba(0,0,0,0.12)",f=n.headerColor||s,v=n.headerColor?ee(f)?"#1f2937":"#ffffff":c,y=n.headerColor?ee(f)?"rgba(0,0,0,0.5)":"rgba(255,255,255,0.7)":h,A=n.buttonColor||(m?"#0f0f1a":a),x=be(A,-15),T=n.userMessageColor!==void 0?n.userMessageColor||"transparent":a,B=T==="transparent"?c:ee(T)?"#1f2937":"#ffffff";return`
2
2
  /* Namiru Chat Widget Styles */
3
3
  .namiru-widget-root {
4
4
  --namiru-primary: ${a};
@@ -8,20 +8,20 @@ function he(){return{state:"idle",messages:[],isOpen:!1,isLoading:!1,streamingCo
8
8
  --namiru-header-text: ${v};
9
9
  --namiru-header-text-secondary: ${y};
10
10
  --namiru-bg: ${s};
11
- --namiru-bg-secondary: ${S};
12
- --namiru-text: ${d};
11
+ --namiru-bg-secondary: ${w};
12
+ --namiru-text: ${c};
13
13
  --namiru-text-secondary: ${h};
14
- --namiru-border: ${g};
14
+ --namiru-border: ${p};
15
15
  --namiru-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
16
16
  --namiru-radius: 12px;
17
17
  --namiru-font: ${r};
18
18
  --namiru-font-size: ${l};
19
- --namiru-scroll-thumb: ${x};
20
- --namiru-user-msg-bg: ${A};
19
+ --namiru-scroll-thumb: ${S};
20
+ --namiru-user-msg-bg: ${T};
21
21
  --namiru-user-msg-text: ${B};
22
22
  --namiru-agent-msg-bg: ${n.agentMessageColor||"transparent"};
23
- --namiru-button-bg: ${T};
24
- --namiru-button-bg-hover: ${E};
23
+ --namiru-button-bg: ${A};
24
+ --namiru-button-bg-hover: ${x};
25
25
  font-family: var(--namiru-font)${t};
26
26
  font-size: var(--namiru-font-size)${t};
27
27
  color: var(--namiru-text)${t};
@@ -1072,15 +1072,15 @@ function he(){return{state:"idle",messages:[],isOpen:!1,isLoading:!1,streamingCo
1072
1072
  margin: 0.6em 0;
1073
1073
  }
1074
1074
  `}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 et(n){return n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function ne(n){let e=et(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(`
1075
- `),a=[],i=!1,r=!1;for(let d=0;d<t.length;d++){let c=t[d];if(c.includes('<hr class="namiru-md-hr">')){i&&(a.push("</ul>"),i=!1),r&&(a.push("</ol>"),r=!1),a.push(c);continue}let g=c.match(/^(\s*)[-*]\s+(.*)/),S=c.match(/^(\s*)\d+\.\s+(.*)/);g?(i||(r&&(a.push("</ol>"),r=!1),a.push('<ul class="namiru-md-ul">'),i=!0),a.push(`<li>${g[2]}</li>`)):S?(r||(i&&(a.push("</ul>"),i=!1),a.push('<ol class="namiru-md-ol">'),r=!0),a.push(`<li>${S[2]}</li>`)):(i&&(a.push("</ul>"),i=!1),r&&(a.push("</ol>"),r=!1),c.trim()===""?a.push(""):a.push(c))}i&&a.push("</ul>"),r&&a.push("</ol>");let l="",o=!1;for(let d of a)d.includes("<hr")?l+=d:d.startsWith("<ul")||d.startsWith("<ol")?(o=!0,l+=d):d==="</ul>"||d==="</ol>"?(o=!1,l+=d):d.startsWith("<li>")?l+=d:d.trim()===""?o||(l+="</p><p>"):(l.length>0&&!o&&!l.endsWith("<p>")&&!l.endsWith("</ul>")&&!l.endsWith("</ol>")&&!l.endsWith("</pre>")&&(l+="<br>"),l+=d);!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=R?"":" !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 _(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 _(["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 _(["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 _(["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 _(["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 _(["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 tt(){return _(["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 nt(){return _(["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 at(){return _(["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 _(["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 it(){return _(["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 rt(){return _(["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 ot(){return _(["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 st(){return _(["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 lt(){return _(["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 dt={ShoppingBag:tt,Package:nt,CreditCard:at,ChatCircle:Te,Rocket:it,Wrench:rt,Briefcase:ot,UserCircle:st,DotsThree:lt};function Ae(n){let e=dt[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 d=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(${d}, 0.06)`,h.style.border="none";let x=t.presetTheme==="dark",f=t.iconColor||(x?"#ffffff":t.primaryColor),v=ve(f);h.appendChild(v),s.appendChild(h)}let c=document.createElement("div");c.className="namiru-header-info";let g=document.createElement("div");if(g.className="namiru-header-name",g.textContent=t.headerTitle||t.name,c.appendChild(g),t.headerSubtitle){let h=document.createElement("div");h.className="namiru-header-subtitle",h.textContent=t.headerSubtitle,c.appendChild(h)}s.appendChild(c),o.appendChild(s);let S=document.createElement("div");if(S.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 x=e.getState();if(l&&!x.feedbackGiven&&x.state==="chatting"&&x.messages.length>0){e.dispatch({type:"SET_STATE",state:"feedback"});return}if(x.messages.length===0){e.dispatch({type:"SET_OPEN",isOpen:!1});return}ie(o,e)}),S.appendChild(h)}return o.appendChild(S),o}function ie(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="You can always come back and start fresh.",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 d=document.createElement("button");if(d.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;",d.textContent="End chat",d.addEventListener("mouseenter",()=>{d.style.opacity="0.85"}),d.addEventListener("mouseleave",()=>{d.style.opacity="1"}),d.addEventListener("click",()=>{a.remove(),e.dispatch({type:"RESET"}),e.dispatch({type:"SET_OPEN",isOpen:!1})}),o.appendChild(s),o.appendChild(d),i.appendChild(o),a.appendChild(i),a.addEventListener("click",c=>{c.target===a&&a.remove()}),!t.querySelector("style[data-namiru-confirm]")){let c=document.createElement("style");c.setAttribute("data-namiru-confirm",""),c.textContent=`
1075
+ `),a=[],i=!1,r=!1;for(let c=0;c<t.length;c++){let m=t[c];if(m.includes('<hr class="namiru-md-hr">')){i&&(a.push("</ul>"),i=!1),r&&(a.push("</ol>"),r=!1),a.push(m);continue}let p=m.match(/^(\s*)[-*]\s+(.*)/),w=m.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>`)):w?(r||(i&&(a.push("</ul>"),i=!1),a.push('<ol class="namiru-md-ol">'),r=!0),a.push(`<li>${w[2]}</li>`)):(i&&(a.push("</ul>"),i=!1),r&&(a.push("</ol>"),r=!1),m.trim()===""?a.push(""):a.push(m))}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=R?"":" !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 $(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 $(["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 $(["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 $(["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 $(["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 $(["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 tt(){return $(["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 nt(){return $(["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 at(){return $(["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 $(["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 it(){return $(["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 rt(){return $(["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 ot(){return $(["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 st(){return $(["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 lt(){return $(["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 ct={ShoppingBag:tt,Package:nt,CreditCard:at,ChatCircle:Te,Rocket:it,Wrench:rt,Briefcase:ot,UserCircle:st,DotsThree:lt};function Ae(n){let e=ct[n];return e?e():Te()}function dt(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=dt(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 S=t.presetTheme==="dark",f=t.iconColor||(S?"#ffffff":t.primaryColor),v=ve(f);h.appendChild(v),s.appendChild(h)}let m=document.createElement("div");m.className="namiru-header-info";let p=document.createElement("div");if(p.className="namiru-header-name",p.textContent=t.headerTitle||t.name,m.appendChild(p),t.headerSubtitle){let h=document.createElement("div");h.className="namiru-header-subtitle",h.textContent=t.headerSubtitle,m.appendChild(h)}s.appendChild(m),o.appendChild(s);let w=document.createElement("div");if(w.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 S=e.getState();if(l&&!S.feedbackGiven&&S.state==="chatting"&&S.messages.length>0){e.dispatch({type:"SET_STATE",state:"feedback"});return}if(S.messages.length===0){e.dispatch({type:"SET_OPEN",isOpen:!1});return}ie(o,e)}),w.appendChild(h)}return o.appendChild(w),o}function ie(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="You can always come back and start fresh.",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",m=>{m.target===a&&a.remove()}),!t.querySelector("style[data-namiru-confirm]")){let m=document.createElement("style");m.setAttribute("data-namiru-confirm",""),m.textContent=`
1076
1076
  @keyframes namiruConfirmFade { from { opacity: 0; } to { opacity: 1; } }
1077
1077
  @keyframes namiruConfirmSlide { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
1078
- `,t.appendChild(c)}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"),R?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 re(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"?mt(e,n):ut(e,n)},createStreaming(){return pt(n)},createLoading(){return gt(n)}}}function mt(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 ut(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(re(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 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(re(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 gt(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(re(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 Ie(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 d=Ae(o.icon);s.appendChild(d);let c=document.createElement("span");c.textContent=o.label,s.appendChild(c),s.addEventListener("click",()=>a(o.label)),l.appendChild(s)}return i.appendChild(l),i}function _e(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 d(c){for(e(c);a.firstChild;)a.removeChild(a.firstChild);let g=document.createElement("div");g.className="namiru-feedback-thanks",g.textContent="Thanks for your feedback!",a.appendChild(g)}return o.addEventListener("click",()=>d("up")),s.addEventListener("click",()=>d("down")),l.appendChild(o),l.appendChild(s),a.appendChild(l),a}function oe(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 d(){let c=o.value.trim();if(!$e(c))return;a(c),l.remove(),r.remove();let g=document.createElement("div");g.className="namiru-email-sent",g.textContent="Thanks, we'll be in touch",i.appendChild(g)}return o.addEventListener("keydown",c=>{c.key==="Enter"&&(c.preventDefault(),d())}),s.addEventListener("click",d),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 d=document.createElement("textarea");d.className="namiru-contact-textarea",d.placeholder="How can we help you?",d.rows=4,d.required=!0,d.setAttribute("aria-label","Message"),t.appendChild(d);let c=document.createElement("div");c.className="namiru-contact-error",c.style.display="none",t.appendChild(c);let g=document.createElement("button");g.className="namiru-contact-submit",g.textContent="Send Message",g.disabled=!0,t.appendChild(g);function S(){let f=o.value.trim(),v=d.value.trim();return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(f)&&v.length>0}function h(){g.disabled=!S()}o.addEventListener("input",h),d.addEventListener("input",h);function x(){if(!S())return;let f={name:r.value.trim(),email:o.value.trim(),message:d.value.trim()};g.disabled=!0,g.textContent="Sending...",r.disabled=!0,o.disabled=!0,d.disabled=!0,e(f),t.textContent="";let v=document.createElement("div");v.className="namiru-contact-confirmation",v.textContent="Thanks! We'll get back to you shortly.",t.appendChild(v)}return g.addEventListener("click",x),o.addEventListener("keydown",f=>{f.key==="Enter"&&(f.preventDefault(),x())}),r.addEventListener("keydown",f=>{f.key==="Enter"&&(f.preventDefault(),x())}),t}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","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 ft(){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(ht()),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 d=document.createElement("input");d.className="namiru-limit-email",d.type="email",d.placeholder="Your email (optional, for a reply)",d.setAttribute("aria-label","Email address (optional)"),o.appendChild(d);let c=document.createElement("button");if(c.className="namiru-limit-submit",c.textContent="Send Message",c.disabled=!0,o.appendChild(c),a.appendChild(o),t){let x=document.createElement("button");x.className="namiru-limit-newchat",x.textContent="Start New Chat",x.addEventListener("click",t),a.appendChild(x)}function g(){return s.value.trim().length>0}function S(){c.disabled=!g()}s.addEventListener("input",S);function h(){if(!g())return;let x=d.value.trim(),f={message:s.value.trim()};x&&(f.visitorEmail=x),c.disabled=!0,c.textContent="Sending...",s.disabled=!0,d.disabled=!0,e(f),a.textContent="";let v=document.createElement("div");v.className="namiru-limit-icon namiru-limit-icon--success",v.appendChild(ft()),a.appendChild(v);let y=document.createElement("div");if(y.className="namiru-limit-confirmation",y.textContent="Message sent! The team will get back to you soon.",a.appendChild(y),t){let T=document.createElement("button");T.className="namiru-limit-newchat",T.textContent="Start New Chat",T.addEventListener("click",t),a.appendChild(T)}}return c.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:d,onTranscriptEmail:c,onContactFormSubmit:g,onLimitMessage:S,onNewChat:h,feedbackEnabled:x}=n,f=t.agentAvatar||t.logoUrl,v=Le({textColor:t.textColor,bubbleStyle:t.bubbleStyle,agentAvatar:f,presetTheme:t.presetTheme,iconColor:t.iconColor}),y=document.createElement("div");i==="button"?y.className=`namiru-popup namiru-popup--${r}`:y.className="namiru-inline";let T=Me({store:e,branding:t,mode:i,...i==="button"?{onTranscriptClick:()=>{e.dispatch({type:"SET_STATE",state:"escalation"}),de()},onNewChat:h}:{},feedbackEnabled:x});y.appendChild(T);let E=document.createElement("div");E.className="namiru-messages",y.appendChild(E);let A=Ne({onSend:l});A.style.display="none",y.appendChild(A);let B=t.showPoweredBy!==!1;B||(A.style.paddingBottom="12px");function O(){let m=document.createElement("div");m.className="namiru-powered",m.setAttribute("data-namiru-protected","true");let b=R?"":" !important";m.style.cssText=`display:block${b};visibility:visible${b};opacity:1${b};`;let w=document.createElement("a");return w.href="https://namiru.ai",w.target="_blank",w.rel="noopener noreferrer",w.textContent="Namiru.ai",m.appendChild(document.createTextNode("Powered by ")),m.appendChild(w),m}if(B){let b=O().innerHTML;y.appendChild(O());let w=!1;new MutationObserver(()=>{if(w)return;w=!0;let L=y.querySelector(".namiru-powered");if(!L)y.appendChild(O());else if(L.innerHTML!==b){let H=O();L.replaceWith(H)}else{let H=L.style,D=getComputedStyle(L);if(D.display==="none"||D.visibility==="hidden"||D.opacity==="0"){let F=R?"":" !important";H.cssText=`display:block${F};visibility:visible${F};opacity:1${F};`}}w=!1}).observe(y,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style","class"],characterData:!0})}t.fontFamily&&t.fontFamily!=="system"&&(y.style.fontFamily=t.fontFamily);let z=40,p=0,k=null,I=null,u=null,C=null,M=null,P=!1,N=null,Z=null,q=null,V=null;function Ge(){if(V)return;V=document.createElement("div"),V.className="namiru-connecting";let m=document.createElement("div");m.className="namiru-loading-dots";for(let b=0;b<3;b++){let w=document.createElement("span");w.className="namiru-loading-dot",m.appendChild(w)}V.appendChild(m),E.appendChild(V)}function U(){V&&(V.remove(),V=null)}function j(){E.textContent="",p=0,k=null,I=null,u=null,C=null,M=null,Z=null,q=null,V=null,P=!1,N=null}function We(){if(P)return;P=!0;let b={id:"welcome",role:"assistant",content:t.welcomeMessage||"Hello! How can I help you today?",timestamp:Date.now()},w=v.createBubble(b);w.classList.add("namiru-message-row--welcome"),E.appendChild(w);let $=t.suggestedQuestions;console.log("[NamiruChat] renderWelcome suggestedQuestions:",$),$&&$.length>0&&(N=document.createElement("div"),N.className="namiru-suggestions",$.slice(0,4).forEach(L=>{let H=document.createElement("button");H.className="namiru-suggestion-chip",H.textContent=L,H.addEventListener("click",()=>{l(L),N&&(N.remove(),N=null)}),N.appendChild(H)}),E.appendChild(N))}function Ze(){let m=t.preChatConfig;if(!m||!m.enabled)return;let b={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"}]}},w,$;if(m.template==="custom"&&m.custom)w=m.custom.question,$=m.custom.options;else if(m.template&&b[m.template]){let L=b[m.template];w=L.question,$=L.options}else return;j(),A.style.display="none",u=Ie({question:w,options:$,onSelect:L=>{o(L),A.style.display=""}}),E.appendChild(u)}function de(){M||(M=oe({promptText:"Want a copy of this conversation? Handy if you need to reference it later for support.",buttonText:"Send",onSubmit:m=>{c(m),M=null}}),E.appendChild(M),W())}function ce(){M||(M=oe({promptText:"We'll connect you with the team. Please share your email and we'll get back to you.",buttonText:"Submit",onSubmit:m=>{d?.(m),M=null}}),E.appendChild(M),W())}function me(){Z||(j(),A.style.display="none",Z=He({onSubmit:m=>{g&&g(m),Z=null}}),E.appendChild(Z))}function ue(){q||(A.style.display="none",q=Oe({onSubmit:m=>{S&&S(m),q=null}}),E.style.position="relative",E.appendChild(q))}function qe(){for(;E.firstChild;)E.removeChild(E.firstChild);E.style.position="relative";let m=document.createElement("div");m.style.cssText=`
1078
+ `,t.appendChild(m)}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"),R?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 re(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"?mt(e,n):ut(e,n)},createStreaming(){return pt(n)},createLoading(){return gt(n)}}}function mt(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 ut(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(re(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 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(re(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 gt(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(re(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 Ie(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 m=document.createElement("span");m.textContent=o.label,s.appendChild(m),s.addEventListener("click",()=>a(o.label)),l.appendChild(s)}return i.appendChild(l),i}function _e(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(m){for(e(m);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 oe(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 m=o.value.trim();if(!$e(m))return;a(m),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",m=>{m.key==="Enter"&&(m.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 m=document.createElement("div");m.className="namiru-contact-error",m.style.display="none",t.appendChild(m);let p=document.createElement("button");p.className="namiru-contact-submit",p.textContent="Send Message",p.disabled=!0,t.appendChild(p);function w(){let f=o.value.trim(),v=c.value.trim();return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(f)&&v.length>0}function h(){p.disabled=!w()}o.addEventListener("input",h),c.addEventListener("input",h);function S(){if(!w())return;let f={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(f),t.textContent="";let v=document.createElement("div");v.className="namiru-contact-confirmation",v.textContent="Thanks! We'll get back to you shortly.",t.appendChild(v)}return p.addEventListener("click",S),o.addEventListener("keydown",f=>{f.key==="Enter"&&(f.preventDefault(),S())}),r.addEventListener("keydown",f=>{f.key==="Enter"&&(f.preventDefault(),S())}),t}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","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 ft(){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,initialMessage:a}=n,i=document.createElement("div");i.className="namiru-limit-overlay";let r=document.createElement("div");r.className="namiru-limit-icon",r.appendChild(ht()),i.appendChild(r);let l=document.createElement("div");l.className="namiru-limit-heading",l.textContent="Conversation limit reached",i.appendChild(l);let o=document.createElement("div");o.className="namiru-limit-subtext",o.textContent="AI responses are currently unavailable. Send a message and we'll forward it via email.",i.appendChild(o);let s=document.createElement("div");s.className="namiru-limit-form";let c=document.createElement("textarea");c.className="namiru-limit-textarea",c.placeholder="Your message...",c.rows=4,c.setAttribute("aria-label","Message"),a&&(c.value=a),s.appendChild(c);let m=document.createElement("input");m.className="namiru-limit-email",m.type="email",m.placeholder="Your email (optional, for a reply)",m.setAttribute("aria-label","Email address (optional)"),s.appendChild(m);let p=document.createElement("button");if(p.className="namiru-limit-submit",p.textContent="Send Message",p.disabled=!0,s.appendChild(p),i.appendChild(s),t){let f=document.createElement("button");f.className="namiru-limit-newchat",f.textContent="Start New Chat",f.addEventListener("click",t),i.appendChild(f)}function w(){return c.value.trim().length>0}function h(){p.disabled=!w()}c.addEventListener("input",h),h();function S(){if(!w())return;let f=m.value.trim(),v={message:c.value.trim()};f&&(v.visitorEmail=f),p.disabled=!0,p.textContent="Sending...",c.disabled=!0,m.disabled=!0,e(v),i.textContent="";let y=document.createElement("div");y.className="namiru-limit-icon namiru-limit-icon--success",y.appendChild(ft()),i.appendChild(y);let A=document.createElement("div");if(A.className="namiru-limit-confirmation",A.textContent="Message sent! The team will get back to you soon.",i.appendChild(A),t){let x=document.createElement("button");x.className="namiru-limit-newchat",x.textContent="Start New Chat",x.addEventListener("click",t),i.appendChild(x)}}return p.addEventListener("click",S),i}function De(n){let{store:e,branding:t,agentId:a,mode:i,position:r,onSendMessage:l,onPreChatSelect:o,onFeedback:s,onEscalationEmail:c,onTranscriptEmail:m,onContactFormSubmit:p,onLimitMessage:w,onNewChat:h,feedbackEnabled:S}=n,f=t.agentAvatar||t.logoUrl,v=Le({textColor:t.textColor,bubbleStyle:t.bubbleStyle,agentAvatar:f,presetTheme:t.presetTheme,iconColor:t.iconColor}),y=document.createElement("div");i==="button"?y.className=`namiru-popup namiru-popup--${r}`:y.className="namiru-inline";let A=Me({store:e,branding:t,mode:i,...i==="button"?{onTranscriptClick:()=>{e.dispatch({type:"SET_STATE",state:"escalation"}),ce()},onNewChat:h}:{},feedbackEnabled:S});y.appendChild(A);let x=document.createElement("div");x.className="namiru-messages",y.appendChild(x);let T=Ne({onSend:l});T.style.display="none",y.appendChild(T);let B=t.showPoweredBy!==!1;B||(T.style.paddingBottom="12px");function O(){let d=document.createElement("div");d.className="namiru-powered",d.setAttribute("data-namiru-protected","true");let b=R?"":" !important";d.style.cssText=`display:block${b};visibility:visible${b};opacity:1${b};`;let E=document.createElement("a");return E.href="https://namiru.ai",E.target="_blank",E.rel="noopener noreferrer",E.textContent="Namiru.ai",d.appendChild(document.createTextNode("Powered by ")),d.appendChild(E),d}if(B){let b=O().innerHTML;y.appendChild(O());let E=!1;new MutationObserver(()=>{if(E)return;E=!0;let L=y.querySelector(".namiru-powered");if(!L)y.appendChild(O());else if(L.innerHTML!==b){let H=O();L.replaceWith(H)}else{let H=L.style,D=getComputedStyle(L);if(D.display==="none"||D.visibility==="hidden"||D.opacity==="0"){let F=R?"":" !important";H.cssText=`display:block${F};visibility:visible${F};opacity:1${F};`}}E=!1}).observe(y,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style","class"],characterData:!0})}t.fontFamily&&t.fontFamily!=="system"&&(y.style.fontFamily=t.fontFamily);let z=40,g=0,k=null,I=null,u=null,C=null,M=null,P=!1,N=null,Z=null,q=null,V=null;function Ge(){if(V)return;V=document.createElement("div"),V.className="namiru-connecting";let d=document.createElement("div");d.className="namiru-loading-dots";for(let b=0;b<3;b++){let E=document.createElement("span");E.className="namiru-loading-dot",d.appendChild(E)}V.appendChild(d),x.appendChild(V)}function U(){V&&(V.remove(),V=null)}function j(){x.textContent="",g=0,k=null,I=null,u=null,C=null,M=null,Z=null,q=null,V=null,P=!1,N=null}function We(){if(P)return;P=!0;let b={id:"welcome",role:"assistant",content:t.welcomeMessage||"Hello! How can I help you today?",timestamp:Date.now()},E=v.createBubble(b);E.classList.add("namiru-message-row--welcome"),x.appendChild(E);let _=t.suggestedQuestions;console.log("[NamiruChat] renderWelcome suggestedQuestions:",_),_&&_.length>0&&(N=document.createElement("div"),N.className="namiru-suggestions",_.slice(0,4).forEach(L=>{let H=document.createElement("button");H.className="namiru-suggestion-chip",H.textContent=L,H.addEventListener("click",()=>{l(L),N&&(N.remove(),N=null)}),N.appendChild(H)}),x.appendChild(N))}function Ze(){let d=t.preChatConfig;if(!d||!d.enabled)return;let b={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"}]}},E,_;if(d.template==="custom"&&d.custom)E=d.custom.question,_=d.custom.options;else if(d.template&&b[d.template]){let L=b[d.template];E=L.question,_=L.options}else return;j(),T.style.display="none",u=Ie({question:E,options:_,onSelect:L=>{o(L),T.style.display=""}}),x.appendChild(u)}function ce(){M||(M=oe({promptText:"Want a copy of this conversation? Handy if you need to reference it later for support.",buttonText:"Send",onSubmit:d=>{m(d),M=null}}),x.appendChild(M),W())}function de(){M||(M=oe({promptText:"We'll connect you with the team. Please share your email and we'll get back to you.",buttonText:"Submit",onSubmit:d=>{c?.(d),M=null}}),x.appendChild(M),W())}function me(){Z||(j(),T.style.display="none",Z=He({onSubmit:d=>{p&&p(d),Z=null}}),x.appendChild(Z))}function ue(d){q||(T.style.display="none",q=Oe({initialMessage:d,onSubmit:b=>{w&&w(b),q=null}}),x.style.position="relative",x.appendChild(q))}function qe(){for(;x.firstChild;)x.removeChild(x.firstChild);x.style.position="relative";let d=document.createElement("div");d.style.cssText=`
1079
1079
  position: absolute; inset: 0; display: flex; flex-direction: column;
1080
1080
  align-items: center; justify-content: center; padding: 2rem; text-align: center;
1081
1081
  background: ${t.backgroundColor||"#ffffff"};
1082
1082
  color: ${t.textColor||"#1f2937"};
1083
- `;let b=document.createElementNS("http://www.w3.org/2000/svg","svg");b.setAttribute("viewBox","0 0 256 256"),b.setAttribute("width","72"),b.setAttribute("height","72"),b.setAttribute("fill","#ef4444"),b.style.cssText="margin-bottom: 20px; opacity: 0.8;";let w=document.createElementNS("http://www.w3.org/2000/svg","path");w.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"),b.appendChild(w),m.appendChild(b);let $=document.createElement("div");$.style.cssText="font-size: 18px; font-weight: 600; margin-bottom: 8px;",$.textContent="Domain Not Authorized",m.appendChild($);let L=document.createElement("div");L.style.cssText="font-size: 14px; opacity: 0.7; margin-bottom: 24px; max-width: 300px; line-height: 1.5;",L.textContent="This chat widget is not authorized to run on this domain. Please update the allowed domain in your agent settings.",m.appendChild(L);let H=document.createElement("div");H.style.cssText="display: flex; gap: 12px; align-items: center;";let D=document.createElement("a");D.style.cssText=`
1083
+ `;let b=document.createElementNS("http://www.w3.org/2000/svg","svg");b.setAttribute("viewBox","0 0 256 256"),b.setAttribute("width","72"),b.setAttribute("height","72"),b.setAttribute("fill","#ef4444"),b.style.cssText="margin-bottom: 20px; opacity: 0.8;";let E=document.createElementNS("http://www.w3.org/2000/svg","path");E.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"),b.appendChild(E),d.appendChild(b);let _=document.createElement("div");_.style.cssText="font-size: 18px; font-weight: 600; margin-bottom: 8px;",_.textContent="Domain Not Authorized",d.appendChild(_);let L=document.createElement("div");L.style.cssText="font-size: 14px; opacity: 0.7; margin-bottom: 24px; max-width: 300px; line-height: 1.5;",L.textContent="This chat widget is not authorized to run on this domain. Please update the allowed domain in your agent settings.",d.appendChild(L);let H=document.createElement("div");H.style.cssText="display: flex; gap: 12px; align-items: center;";let D=document.createElement("a");D.style.cssText=`
1084
1084
  padding: 10px 24px; border-radius: 8px; border: none; cursor: pointer;
1085
1085
  font-size: 14px; font-weight: 500; text-decoration: none;
1086
1086
  display: inline-flex; align-items: center; box-sizing: border-box;
@@ -1090,5 +1090,5 @@ function he(){return{state:"idle",messages:[],isOpen:!1,isLoading:!1,streamingCo
1090
1090
  font-size: 14px; font-weight: 500; line-height: 1; box-sizing: border-box;
1091
1091
  background: transparent; color: ${t.textColor||"#1f2937"};
1092
1092
  border: 1px solid ${t.textColor?t.textColor+"33":"#e5e7eb"};
1093
- `,Q.textContent="Reload",Q.addEventListener("click",()=>window.location.reload()),H.appendChild(Q),m.appendChild(H),E.appendChild(m)}function pe(m){C||(C=_e({onFeedback:b=>{s(b),i==="button"&&setTimeout(()=>{e.dispatch({type:"RESET"}),e.dispatch({type:"SET_OPEN",isOpen:!1})},800)},softPrompt:m}),E.appendChild(C),W())}function W(){requestAnimationFrame(()=>{E.scrollTop=E.scrollHeight})}function Ue(m){N&&m.some(b=>b.role==="user")&&(N.remove(),N=null);for(let b=p;b<m.length;b++){let w=v.createBubble(m[b]);E.appendChild(w)}p=m.length,W()}function je(m){if(m){k||(I&&(I.remove(),I=null),k=v.createStreaming(),E.appendChild(k));let b=k._namiruTextEl,w=ne(m);b?b.innerHTML=w:k.innerHTML=w,W()}else k&&(k.remove(),k=null)}function Qe(m){m&&!I&&!k?(I=v.createLoading(),E.appendChild(I),W()):!m&&I&&(I.remove(),I=null)}let G=null;return e.subscribe(m=>{if(console.log("[ChatWindow] subscriber:","state="+m.state,"msgs="+m.messages.length,"open="+m.isOpen,"input="+A?.style.display,"prev="+(G?.state||"null")),i==="button"&&(m.isOpen?y.classList.add("namiru-popup--open"):y.classList.remove("namiru-popup--open")),!G||G.state!==m.state)switch(m.state){case"idle":j(),A.style.display="none",U();break;case"connecting":A.style.display="none",Ge();break;case"pre_chat":Ze();break;case"chatting":U(),G?.state==="pre_chat"&&j(),A.style.display="",We();break;case"feedback":pe(!0);break;case"escalation":ce();break;case"email_fallback":me();break;case"conversation_limit":U(),A.style.display="none",ue();break;case"domain_error":U(),A.style.display="none",qe();break;case"error":U(),A.style.display="none";break}m.messages.length>p&&m.state!=="pre_chat"&&Ue(m.messages),m.state==="chatting"&&m.messages.length>=z&&e.dispatch({type:"SET_STATE",state:"conversation_limit"}),G?.streamingContent!==m.streamingContent&&je(m.streamingContent),G?.isLoading!==m.isLoading&&Qe(m.isLoading),G=m}),y._namiruShowEscalation=ce,y._namiruShowFeedback=pe,y._namiruShowTranscript=de,y._namiruShowContactForm=me,y._namiruShowLimitOverlay=ue,y._namiruShowCloseConfirmation=()=>ie(T,e),y}function Be(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 d=Ee(),c=ae();c.style.display="none",s.appendChild(d),s.appendChild(c),s.addEventListener("click",()=>{let f=t.getState().isOpen;f&&l?l():t.dispatch({type:"SET_OPEN",isOpen:!f})}),o.appendChild(s);let g=null,S=!1,h=null;if(a){g=document.createElement("div"),g.className=`namiru-greeting namiru-greeting--${e} namiru-greeting--hidden`;let f=document.createTextNode(a);g.appendChild(f);let v=document.createElement("button");v.className="namiru-greeting-close",v.setAttribute("aria-label","Dismiss"),v.textContent="\xD7",v.addEventListener("click",T=>{T.stopPropagation(),x()}),g.appendChild(v),g.addEventListener("click",()=>{x(),t.dispatch({type:"SET_OPEN",isOpen:!0})}),o.appendChild(g),h=setTimeout(()=>{!t.getState().isOpen&&g&&(g.classList.remove("namiru-greeting--hidden"),S=!0,setTimeout(()=>x(),3e4))},i??3e3)}function x(){S&&g&&(g.classList.add("namiru-greeting--hidden"),S=!1),h&&(clearTimeout(h),h=null)}return t.subscribe(f=>{f.isOpen?(d.style.display="none",c.style.display="",s.setAttribute("aria-label","Close chat"),x()):(d.style.display="",c.style.display="none",s.setAttribute("aria-label","Open chat"))}),o}var bt="https://api.namiru.ai",xt="wss://ai.namiru.ai",Pe="http://localhost:3001",Ve="ws://localhost:3423";function yt(n){return n?{apiBase:Pe,wsUrl:Ve}:document.querySelector("script[data-dev]")?{apiBase:Pe,wsUrl:Ve}:{apiBase:bt,wsUrl:xt}}var Fe="namiru_visitor_id";function se(){try{let n=localStorage.getItem(Fe);if(n)return n;let e=`v_${Date.now()}_${Math.random().toString(36).substring(2,11)}`;return localStorage.setItem(Fe,e),e}catch{return`v_${Date.now()}_${Math.random().toString(36).substring(2,11)}`}}var Re=0;function le(){return Re++,`msg-${Date.now()}-${Re}`}function ze(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 vt(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(){ze(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 Ct(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 Et(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}=yt(n.dev),r=new Y,l=new J({baseUrl:a}),o=null,s=null,d=null,c=null,g=null,S=null,h=!1,x="handoff_accepted",f=null,v=!1,y=null;s=document.createElement("div"),s.id="namiru-widget-host";let T=typeof s.attachShadow=="function";fe(T),T&&(s.style.cssText="all:initial;position:fixed;top:0;left:0;width:0;height:0;overflow:visible;z-index:2147483646;pointer-events:none;",d=s.attachShadow({mode:"open"})),c=document.createElement("div"),c.className="namiru-widget-root";let E=d||s;T&&(c.style.pointerEvents="auto"),E.appendChild(c);async function A(){try{let p=await l.fetchBranding(n.agentId);if(h)return;if(!Ct(p.allowedDomains)){console.warn(`[Namiru Widget] Domain "${window.location.hostname}" is not allowed for this agent. Allowed: ${JSON.stringify(p.allowedDomains)}`);return}if(ze(p.excludedRoutes)){console.info(`[Namiru Widget] Widget hidden on excluded route "${window.location.pathname}"`);return}xe({primaryColor:p.primaryColor,accentColor:p.accentColor,headerColor:p.headerColor,fontFamily:p.fontFamily,presetTheme:p.presetTheme,backgroundColor:p.backgroundColor,textColor:p.textColor,fontSize:p.fontSize,userMessageColor:p.userMessageColor,agentMessageColor:p.agentMessageColor,borderColor:p.borderColor,inputColor:p.inputColor,buttonColor:p.buttonColor},E,!T),n.suggestedQuestions&&n.suggestedQuestions.length>0&&(p.suggestedQuestions=n.suggestedQuestions),console.log("[NamiruChat] suggestedQuestions:",p.suggestedQuestions);let k=n.preChatEnabled??p.preChatConfig?.enabled??!1;k&&(p.preChatConfig?(p.preChatConfig.enabled=!0,n.preChatTemplate!==void 0&&(p.preChatConfig.template=n.preChatTemplate),n.preChatCustom&&(p.preChatConfig.custom=n.preChatCustom)):p.preChatConfig={enabled:!0,template:n.preChatTemplate??null,custom:n.preChatCustom}),v=p.feedbackConfig?.enabled??!1;let I=p.feedbackConfig?.inactivityMinutes??3;if(v&&(f=new X(I,()=>{let u=r.getState();!u.feedbackGiven&&u.state==="chatting"&&u.messages.length>0&&r.dispatch({type:"SET_STATE",state:"feedback"})})),g=De({store:r,branding:p,agentId:n.agentId,mode:e,position:t,onSendMessage:u=>{let C={id:le(),role:"user",content:u,timestamp:Date.now()};r.dispatch({type:"ADD_MESSAGE",message:C}),r.dispatch({type:"SET_LOADING",isLoading:!0}),o&&o.sendMessage(u)},onPreChatSelect:u=>{r.dispatch({type:"SET_QUALIFICATION",qualification:u}),r.dispatch({type:"SET_STATE",state:"connecting"}),B(u)},onFeedback:u=>{let C=r.getState().sessionId;C&&l.submitFeedback(n.agentId,{sessionId:C,rating:u}).catch(M=>console.error("NamiruChat: feedback submit failed",M)),r.dispatch({type:"SET_FEEDBACK_GIVEN"}),f?.stop(),n.onFeedback?.(u)},onTranscriptEmail:u=>{let C=r.getState().sessionId;C&&l.requestTranscript(n.agentId,C,{email:u}).catch(M=>console.error("NamiruChat: transcript request failed",M))},onContactFormSubmit:u=>{let C=se(),M=r.getState().sessionId;l.submitLead({agentId:n.agentId,name:u.name||void 0,email:u.email,message:u.message,visitorId:C,fallbackReason:x,conversationId:M||void 0}).catch(P=>console.error("NamiruChat: lead submit failed",P)),o&&o.sendHandoffComplete({email:u.email,name:u.name||void 0,reason:x}),n.onLeadCapture?.({email:u.email,sessionId:M||"",source:"email_fallback",qualification:r.getState().qualification||void 0})},onLimitMessage:u=>{u.visitorEmail?l.submitContactMessage(n.agentId,{email:u.visitorEmail,message:u.message,visitorId:se()}).catch(C=>console.error("NamiruChat: contact message submit failed",C)):l.submitLimitMessage({agentId:n.agentId,message:u.message}).catch(C=>console.error("NamiruChat: limit message submit failed",C))},feedbackEnabled:v,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"}),B()}}),c.appendChild(g),e==="button"&&(S=Be({position:t,store:r,welcomeMessage:p.bubbleGreeting||void 0,greetingDelay:n.greetingDelay,bubbleStyle:p.bubbleStyle,onCloseRequest:()=>{let u=r.getState();if(v&&!u.feedbackGiven&&u.state==="chatting"&&u.messages.length>0){r.dispatch({type:"SET_STATE",state:"feedback"});return}if(u.messages.length===0){r.dispatch({type:"SET_OPEN",isOpen:!1});return}let C=g?._namiruShowCloseConfirmation;typeof C=="function"?C():r.dispatch({type:"SET_OPEN",isOpen:!1})}}),c.appendChild(S)),e==="inline"&&g){let u=n.width||"100%",C=n.height||"100%";g.style.width=u,g.style.height=C,g.style.maxHeight=C,c.style.height="100%"}if(T?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(c):document.body.appendChild(c),k?r.dispatch({type:"SET_STATE",state:"pre_chat"}):(r.dispatch({type:"SET_STATE",state:"connecting"}),B()),e==="inline"&&r.dispatch({type:"SET_OPEN",isOpen:!0}),p.excludedRoutes&&p.excludedRoutes.length>0){let u=T?s:c;y=vt(p.excludedRoutes,u)}}catch(p){console.error("NamiruChat: initialization failed",p),r.dispatch({type:"SET_ERROR",error:"Failed to load chat. Please try again later."})}}function B(p){if(o||h)return;o=new K({url:i,agentId:n.agentId,visitorId:se()}),o.on("connected",()=>{}),o.on("agent_initialized",u=>{r.dispatch({type:"SET_STATE",state:"chatting"}),r.dispatch({type:"SET_LOADING",isLoading:!1}),u.data.sessionId&&(r.dispatch({type:"SET_SESSION_ID",sessionId:u.data.sessionId}),n.onSessionStart?.(u.data.sessionId)),p&&o?.sendMessage(`[User selected: ${p}]`)}),o.on("stream_token",u=>{r.dispatch({type:"APPEND_STREAMING",token:u.data.token})});let k=!1,I=!1;o.on("final_response",u=>{I=!0,k&&(k=!1),r.dispatch({type:"CLEAR_STREAMING"});let C=u.data.content||u.data.response||"",M=r.getState().messages,P=M[M.length-1];if(!P||P.role!=="assistant"||P.content!==C){let N={id:le(),role:"assistant",content:C,timestamp:Date.now()};r.dispatch({type:"ADD_MESSAGE",message:N})}r.dispatch({type:"SET_LOADING",isLoading:!1}),v&&u.data.conversationMayHaveEnded&&!r.getState().feedbackGiven?(setTimeout(()=>{let N=r.getState();!N.feedbackGiven&&N.state==="chatting"&&N.messages.length>0&&r.dispatch({type:"SET_STATE",state:"feedback"})},800),f?.stop()):f&&!r.getState().feedbackGiven&&f.reset()}),o.on("stream_end",()=>{r.dispatch({type:"CLEAR_STREAMING"}),I=!1,k=!1,r.dispatch({type:"SET_LOADING",isLoading:!1}),f&&!r.getState().feedbackGiven&&f.reset()}),o.on("tool_start",()=>{r.dispatch({type:"SET_LOADING",isLoading:!0}),k=!0}),o.on("tool_end",()=>{}),o.on("handoff_active",u=>{let C={id:le(),role:"assistant",content:u.data?.message||"A human operator is currently handling this conversation. Please wait for their response.",timestamp:Date.now()};r.dispatch({type:"ADD_MESSAGE",message:C}),r.dispatch({type:"SET_LOADING",isLoading:!1})}),o.on("show_handoff_form",u=>{x=u.data?.reason||"handoff_accepted",r.dispatch({type:"SET_STATE",state:"email_fallback"}),r.dispatch({type:"SET_LOADING",isLoading:!1})}),o.on("error",u=>{if(u.data?.type==="usage_limit"||u.data?.usage_limit){r.dispatch({type:"SET_STATE",state:"conversation_limit"}),r.dispatch({type:"SET_LOADING",isLoading:!1});return}if(u.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",u.data),r.dispatch({type:"SET_ERROR",error:u.data?.message||"Connection error. Please try again."}),r.dispatch({type:"SET_LOADING",isLoading:!1})}),o.on("disconnected",()=>{}),o.connect()}A();let O=!1,z=!1;return r.subscribe(p=>{if(!(h||z)){if(O&&!p.isOpen){O=!1,z=!0,o&&(o.disconnect(),o=null),f?.stop(),z=!1;return}if(!O&&p.isOpen&&!o){O=!0,z=!0,r.dispatch({type:"SET_STATE",state:"connecting"}),B(),z=!1;return}O=p.isOpen}}),{open:()=>{h||r.dispatch({type:"SET_OPEN",isOpen:!0})},close:()=>{h||r.dispatch({type:"SET_OPEN",isOpen:!1})},toggle:()=>{if(!h){let p=r.getState().isOpen;r.dispatch({type:"SET_OPEN",isOpen:!p})}},destroy:()=>{if(h)return;h=!0,y?.(),y=null,o?.disconnect(),f?.stop(),ye();let p=T?s:c;p&&p.parentNode&&p.parentNode.removeChild(p);let k=r.getState().sessionId;k&&n.onSessionEnd?.(k),r.dispatch({type:"RESET"}),s=null,d=null,c=null,g=null,S=null,o=null},updateConfig:p=>{h||Object.assign(n,p)}}}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-container-id");Et({agentId:e,mode:t,container:a&&document.getElementById(a)||void 0})}}export{Et as init};
1093
+ `,Q.textContent="Reload",Q.addEventListener("click",()=>window.location.reload()),H.appendChild(Q),d.appendChild(H),x.appendChild(d)}function pe(d){C||(C=_e({onFeedback:b=>{s(b),i==="button"&&setTimeout(()=>{e.dispatch({type:"RESET"}),e.dispatch({type:"SET_OPEN",isOpen:!1})},800)},softPrompt:d}),x.appendChild(C),W())}function W(){requestAnimationFrame(()=>{x.scrollTop=x.scrollHeight})}function Ue(d){N&&d.some(b=>b.role==="user")&&(N.remove(),N=null);for(let b=g;b<d.length;b++){let E=v.createBubble(d[b]);x.appendChild(E)}g=d.length,W()}function je(d){if(d){k||(I&&(I.remove(),I=null),k=v.createStreaming(),x.appendChild(k));let b=k._namiruTextEl,E=ne(d);b?b.innerHTML=E:k.innerHTML=E,W()}else k&&(k.remove(),k=null)}function Qe(d){d&&!I&&!k?(I=v.createLoading(),x.appendChild(I),W()):!d&&I&&(I.remove(),I=null)}let G=null;return e.subscribe(d=>{if(console.log("[ChatWindow] subscriber:","state="+d.state,"msgs="+d.messages.length,"open="+d.isOpen,"input="+T?.style.display,"prev="+(G?.state||"null")),i==="button"&&(d.isOpen?y.classList.add("namiru-popup--open"):y.classList.remove("namiru-popup--open")),!G||G.state!==d.state)switch(d.state){case"idle":j(),T.style.display="none",U();break;case"connecting":T.style.display="none",Ge();break;case"pre_chat":Ze();break;case"chatting":U(),G?.state==="pre_chat"&&j(),T.style.display="",We();break;case"feedback":pe(!0);break;case"escalation":de();break;case"email_fallback":me();break;case"conversation_limit":{U(),T.style.display="none";let E=[...e.getState().messages].reverse().find(_=>_.role==="user");ue(E?.content);break}case"domain_error":U(),T.style.display="none",qe();break;case"error":U(),T.style.display="none";break}d.messages.length>g&&d.state!=="pre_chat"&&Ue(d.messages),d.state==="chatting"&&d.messages.length>=z&&e.dispatch({type:"SET_STATE",state:"conversation_limit"}),G?.streamingContent!==d.streamingContent&&je(d.streamingContent),G?.isLoading!==d.isLoading&&Qe(d.isLoading),G=d}),y._namiruShowEscalation=de,y._namiruShowFeedback=pe,y._namiruShowTranscript=ce,y._namiruShowContactForm=me,y._namiruShowLimitOverlay=ue,y._namiruShowCloseConfirmation=()=>ie(A,e),y}function Be(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(),m=ae();m.style.display="none",s.appendChild(c),s.appendChild(m),s.addEventListener("click",()=>{let f=t.getState().isOpen;f&&l?l():t.dispatch({type:"SET_OPEN",isOpen:!f})}),o.appendChild(s);let p=null,w=!1,h=null;if(a){p=document.createElement("div"),p.className=`namiru-greeting namiru-greeting--${e} namiru-greeting--hidden`;let f=document.createTextNode(a);p.appendChild(f);let v=document.createElement("button");v.className="namiru-greeting-close",v.setAttribute("aria-label","Dismiss"),v.textContent="\xD7",v.addEventListener("click",A=>{A.stopPropagation(),S()}),p.appendChild(v),p.addEventListener("click",()=>{S(),t.dispatch({type:"SET_OPEN",isOpen:!0})}),o.appendChild(p),h=setTimeout(()=>{!t.getState().isOpen&&p&&(p.classList.remove("namiru-greeting--hidden"),w=!0,setTimeout(()=>S(),3e4))},i??3e3)}function S(){w&&p&&(p.classList.add("namiru-greeting--hidden"),w=!1),h&&(clearTimeout(h),h=null)}return t.subscribe(f=>{f.isOpen?(c.style.display="none",m.style.display="",s.setAttribute("aria-label","Close chat"),S()):(c.style.display="",m.style.display="none",s.setAttribute("aria-label","Open chat"))}),o}var bt="https://api.namiru.ai",xt="wss://ai.namiru.ai",Pe="http://localhost:3001",Ve="ws://localhost:3423";function yt(n){return n?{apiBase:Pe,wsUrl:Ve}:document.querySelector("script[data-dev]")?{apiBase:Pe,wsUrl:Ve}:{apiBase:bt,wsUrl:xt}}var Fe="namiru_visitor_id";function se(){try{let n=localStorage.getItem(Fe);if(n)return n;let e=`v_${Date.now()}_${Math.random().toString(36).substring(2,11)}`;return localStorage.setItem(Fe,e),e}catch{return`v_${Date.now()}_${Math.random().toString(36).substring(2,11)}`}}var Re=0;function le(){return Re++,`msg-${Date.now()}-${Re}`}function ze(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 vt(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(){ze(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 Ct(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 Et(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}=yt(n.dev),r=new Y,l=new J({baseUrl:a}),o=null,s=null,c=null,m=null,p=null,w=null,h=!1,S="handoff_accepted",f=null,v=!1,y=null;s=document.createElement("div"),s.id="namiru-widget-host";let A=typeof s.attachShadow=="function";fe(A),A&&(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"})),m=document.createElement("div"),m.className="namiru-widget-root";let x=c||s;A&&(m.style.pointerEvents="auto"),x.appendChild(m);async function T(){try{let g=await l.fetchBranding(n.agentId);if(h)return;if(!Ct(g.allowedDomains)){console.warn(`[Namiru Widget] Domain "${window.location.hostname}" is not allowed for this agent. Allowed: ${JSON.stringify(g.allowedDomains)}`);return}if(ze(g.excludedRoutes)){console.info(`[Namiru Widget] Widget hidden on excluded route "${window.location.pathname}"`);return}xe({primaryColor:g.primaryColor,accentColor:g.accentColor,headerColor:g.headerColor,fontFamily:g.fontFamily,presetTheme:g.presetTheme,backgroundColor:g.backgroundColor,textColor:g.textColor,fontSize:g.fontSize,userMessageColor:g.userMessageColor,agentMessageColor:g.agentMessageColor,borderColor:g.borderColor,inputColor:g.inputColor,buttonColor:g.buttonColor},x,!A),n.suggestedQuestions&&n.suggestedQuestions.length>0&&(g.suggestedQuestions=n.suggestedQuestions),console.log("[NamiruChat] suggestedQuestions:",g.suggestedQuestions);let k=n.preChatEnabled??g.preChatConfig?.enabled??!1;k&&(g.preChatConfig?(g.preChatConfig.enabled=!0,n.preChatTemplate!==void 0&&(g.preChatConfig.template=n.preChatTemplate),n.preChatCustom&&(g.preChatConfig.custom=n.preChatCustom)):g.preChatConfig={enabled:!0,template:n.preChatTemplate??null,custom:n.preChatCustom}),v=g.feedbackConfig?.enabled??!1;let I=g.feedbackConfig?.inactivityMinutes??3;if(v&&(f=new X(I,()=>{let u=r.getState();!u.feedbackGiven&&u.state==="chatting"&&u.messages.length>0&&r.dispatch({type:"SET_STATE",state:"feedback"})})),p=De({store:r,branding:g,agentId:n.agentId,mode:e,position:t,onSendMessage:u=>{let C={id:le(),role:"user",content:u,timestamp:Date.now()};r.dispatch({type:"ADD_MESSAGE",message:C}),r.dispatch({type:"SET_LOADING",isLoading:!0}),o&&o.sendMessage(u)},onPreChatSelect:u=>{r.dispatch({type:"SET_QUALIFICATION",qualification:u}),r.dispatch({type:"SET_STATE",state:"connecting"}),B(u)},onFeedback:u=>{let C=r.getState().sessionId;C&&l.submitFeedback(n.agentId,{sessionId:C,rating:u}).catch(M=>console.error("NamiruChat: feedback submit failed",M)),r.dispatch({type:"SET_FEEDBACK_GIVEN"}),f?.stop(),n.onFeedback?.(u)},onTranscriptEmail:u=>{let C=r.getState().sessionId;C&&l.requestTranscript(n.agentId,C,{email:u}).catch(M=>console.error("NamiruChat: transcript request failed",M))},onContactFormSubmit:u=>{let C=se(),M=r.getState().sessionId;l.submitLead({agentId:n.agentId,name:u.name||void 0,email:u.email,message:u.message,visitorId:C,fallbackReason:S,conversationId:M||void 0}).catch(P=>console.error("NamiruChat: lead submit failed",P)),o&&o.sendHandoffComplete({email:u.email,name:u.name||void 0,reason:S}),n.onLeadCapture?.({email:u.email,sessionId:M||"",source:"email_fallback",qualification:r.getState().qualification||void 0})},onLimitMessage:u=>{u.visitorEmail?l.submitContactMessage(n.agentId,{email:u.visitorEmail,message:u.message,visitorId:se()}).catch(C=>console.error("NamiruChat: contact message submit failed",C)):l.submitLimitMessage({agentId:n.agentId,message:u.message}).catch(C=>console.error("NamiruChat: limit message submit failed",C))},feedbackEnabled:v,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"}),B()}}),m.appendChild(p),e==="button"&&(w=Be({position:t,store:r,welcomeMessage:g.bubbleGreeting||void 0,greetingDelay:n.greetingDelay,bubbleStyle:g.bubbleStyle,onCloseRequest:()=>{let u=r.getState();if(v&&!u.feedbackGiven&&u.state==="chatting"&&u.messages.length>0){r.dispatch({type:"SET_STATE",state:"feedback"});return}if(u.messages.length===0){r.dispatch({type:"SET_OPEN",isOpen:!1});return}let C=p?._namiruShowCloseConfirmation;typeof C=="function"?C():r.dispatch({type:"SET_OPEN",isOpen:!1})}}),m.appendChild(w)),e==="inline"&&p){let u=n.width||"100%",C=n.height||"100%";p.style.width=u,p.style.height=C,p.style.maxHeight=C,m.style.height="100%"}if(A?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(m):document.body.appendChild(m),k?r.dispatch({type:"SET_STATE",state:"pre_chat"}):(r.dispatch({type:"SET_STATE",state:"connecting"}),B()),e==="inline"&&r.dispatch({type:"SET_OPEN",isOpen:!0}),g.excludedRoutes&&g.excludedRoutes.length>0){let u=A?s:m;y=vt(g.excludedRoutes,u)}}catch(g){console.error("NamiruChat: initialization failed",g),r.dispatch({type:"SET_ERROR",error:"Failed to load chat. Please try again later."})}}function B(g){if(o||h)return;o=new K({url:i,agentId:n.agentId,visitorId:se()}),o.on("connected",()=>{}),o.on("agent_initialized",u=>{r.dispatch({type:"SET_STATE",state:"chatting"}),r.dispatch({type:"SET_LOADING",isLoading:!1}),u.data.sessionId&&(r.dispatch({type:"SET_SESSION_ID",sessionId:u.data.sessionId}),n.onSessionStart?.(u.data.sessionId)),g&&o?.sendMessage(`[User selected: ${g}]`)}),o.on("stream_token",u=>{r.dispatch({type:"APPEND_STREAMING",token:u.data.token})});let k=!1,I=!1;o.on("final_response",u=>{I=!0,k&&(k=!1),r.dispatch({type:"CLEAR_STREAMING"});let C=u.data.content||u.data.response||"",M=r.getState().messages,P=M[M.length-1];if(!P||P.role!=="assistant"||P.content!==C){let N={id:le(),role:"assistant",content:C,timestamp:Date.now()};r.dispatch({type:"ADD_MESSAGE",message:N})}r.dispatch({type:"SET_LOADING",isLoading:!1}),v&&u.data.conversationMayHaveEnded&&!r.getState().feedbackGiven?(setTimeout(()=>{let N=r.getState();!N.feedbackGiven&&N.state==="chatting"&&N.messages.length>0&&r.dispatch({type:"SET_STATE",state:"feedback"})},800),f?.stop()):f&&!r.getState().feedbackGiven&&f.reset()}),o.on("stream_end",()=>{r.dispatch({type:"CLEAR_STREAMING"}),I=!1,k=!1,r.dispatch({type:"SET_LOADING",isLoading:!1}),f&&!r.getState().feedbackGiven&&f.reset()}),o.on("tool_start",()=>{r.dispatch({type:"SET_LOADING",isLoading:!0}),k=!0}),o.on("tool_end",()=>{}),o.on("handoff_active",u=>{let C={id:le(),role:"assistant",content:u.data?.message||"A human operator is currently handling this conversation. Please wait for their response.",timestamp:Date.now()};r.dispatch({type:"ADD_MESSAGE",message:C}),r.dispatch({type:"SET_LOADING",isLoading:!1})}),o.on("show_handoff_form",u=>{S=u.data?.reason||"handoff_accepted",r.dispatch({type:"SET_STATE",state:"email_fallback"}),r.dispatch({type:"SET_LOADING",isLoading:!1})}),o.on("error",u=>{if(u.data?.type==="usage_limit"||u.data?.usage_limit){r.dispatch({type:"SET_STATE",state:"conversation_limit"}),r.dispatch({type:"SET_LOADING",isLoading:!1});return}if(u.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",u.data),r.dispatch({type:"SET_ERROR",error:u.data?.message||"Connection error. Please try again."}),r.dispatch({type:"SET_LOADING",isLoading:!1})}),o.on("disconnected",()=>{}),o.connect()}T();let O=!1,z=!1;return r.subscribe(g=>{if(!(h||z)){if(O&&!g.isOpen){O=!1,z=!0,o&&(o.disconnect(),o=null),f?.stop(),z=!1;return}if(!O&&g.isOpen&&!o){O=!0,z=!0,r.dispatch({type:"SET_STATE",state:"connecting"}),B(),z=!1;return}O=g.isOpen}}),{open:()=>{h||r.dispatch({type:"SET_OPEN",isOpen:!0})},close:()=>{h||r.dispatch({type:"SET_OPEN",isOpen:!1})},toggle:()=>{if(!h){let g=r.getState().isOpen;r.dispatch({type:"SET_OPEN",isOpen:!g})}},destroy:()=>{if(h)return;h=!0,y?.(),y=null,o?.disconnect(),f?.stop(),ye();let g=A?s:m;g&&g.parentNode&&g.parentNode.removeChild(g);let k=r.getState().sessionId;k&&n.onSessionEnd?.(k),r.dispatch({type:"RESET"}),s=null,c=null,m=null,p=null,w=null,o=null},updateConfig:g=>{h||Object.assign(n,g)}}}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-container-id");Et({agentId:e,mode:t,container:a&&document.getElementById(a)||void 0})}}export{Et as init};
1094
1094
  //# sourceMappingURL=namiru-chat.esm.js.map