@namiruai/chat 1.0.0 → 1.1.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,16 +1,16 @@
1
1
  export interface NamiruChatConfig {
2
2
  agentId: string;
3
- serverUrl?: string;
4
- wsUrl?: string;
5
- mode?: "button" | "inline";
6
- position?: "bottom-left" | "bottom-right";
7
- container?: HTMLElement;
8
- preChatEnabled?: boolean;
9
- preChatTemplate?: "ecommerce" | "saas" | "services" | "custom" | null;
10
- preChatCustom?: PreChatCustomConfig;
11
- greetingDelay?: number;
12
- width?: string;
13
- height?: string;
3
+ /** @internal */ serverUrl?: string;
4
+ /** @internal */ wsUrl?: string;
5
+ /** @internal */ mode?: "button" | "inline";
6
+ /** @internal */ container?: HTMLElement;
7
+ /** @internal */ preChatEnabled?: boolean;
8
+ /** @internal */ preChatTemplate?: "ecommerce" | "saas" | "services" | "custom" | null;
9
+ /** @internal */ preChatCustom?: PreChatCustomConfig;
10
+ /** @internal */ greetingDelay?: number;
11
+ /** @internal */ width?: string;
12
+ /** @internal */ height?: string;
13
+ /** @internal */ suggestedQuestions?: string[];
14
14
  onLeadCapture?: (lead: LeadCaptureData) => void;
15
15
  onFeedback?: (rating: "up" | "down") => void;
16
16
  onSessionStart?: (sessionId: string) => void;
@@ -71,7 +71,6 @@ export interface AgentBrandingData {
71
71
  escalationConfig?: {
72
72
  enabled: boolean;
73
73
  emailFallbackEnabled: boolean;
74
- ownerEmail?: string;
75
74
  customReplyMessage?: string;
76
75
  liveChatEnabled: boolean;
77
76
  };
@@ -1,14 +1,14 @@
1
- function fe(){return{state:"idle",messages:[],isOpen:!1,isLoading:!1,streamingContent:"",qualification:null,feedbackGiven:!1,sessionId:null,error:null}}function Ue(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 fe();default:return n}}var Y=class{constructor(){this.subscribers=new Set;this.state=fe()}getState(){return this.state}dispatch(e){let t=this.state;this.state=Ue(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)}/config`);if(!t.ok)throw new Error(`Failed to fetch agent config: ${t.status}`);let a=await t.json(),r=a.branding||{};function i(o,s){return typeof o=="string"&&/^#[0-9a-fA-F]{3,8}$/.test(o)?o:s}let l=[];if(Array.isArray(r.suggestedQuestions))l=r.suggestedQuestions;else if(typeof r.suggestedQuestions=="string")try{let o=JSON.parse(r.suggestedQuestions);Array.isArray(o)&&(l=o)}catch{}return{agentId:a.id,name:r.agentDisplayName||a.name,primaryColor:i(r.primaryColor,"#2563eb"),accentColor:i(r.accentColor,"#21DFFB"),logoUrl:r.agentAvatar||r.logoUrl||void 0,agentAvatar:r.agentAvatar||r.logoUrl||void 0,welcomeMessage:r.welcomeMessage||void 0,showPoweredBy:r.showPoweredBy??!0,showHeader:r.showHeader??!0,headerColor:i(r.headerColor,"")||void 0,headerTitle:r.headerTitle||void 0,headerSubtitle:r.headerSubtitle||void 0,presetTheme:r.presetTheme||"light",backgroundColor:i(r.backgroundColor,"")||void 0,textColor:i(r.textColor,"")||void 0,bubbleStyle:r.bubbleStyle||"modern",fontFamily:r.fontFamily||"system",fontSize:r.fontSize||"medium",userMessageColor:i(r.userMessageColor,"")||void 0,agentMessageColor:i(r.agentMessageColor,"")||void 0,bubbleGreeting:r.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,ownerEmail:a.escalationConfig.ownerEmail,customReplyMessage:a.escalationConfig.customReplyMessage,liveChatEnabled:a.escalationConfig.liveChatEnabled}:void 0,allowedDomains:Array.isArray(a.allowedDomains)?a.allowedDomains: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 r=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(!r.ok)throw new Error(`Failed to request transcript: ${r.status}`);return r.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 Q=class{constructor(e){this.ws=null;this.listeners=new Map;this.reconnectAttempts=0;this.isDestroyed=!1;this.isInitialized=!1;this.config=e,this.maxReconnectAttempts=e.maxReconnectAttempts??3}connect(){if(!this.isDestroyed)try{this.ws=new WebSocket(this.config.url),this.ws.onopen=this.handleOpen.bind(this),this.ws.onmessage=this.handleMessage.bind(this),this.ws.onclose=this.handleClose.bind(this),this.ws.onerror=this.handleError.bind(this)}catch(e){this.emit("error",{message:e instanceof Error?e.message:"WebSocket connection failed"})}}disconnect(){this.isDestroyed=!0,this.ws&&(this.ws.onclose=null,this.ws.close(),this.ws=null)}sendMessage(e){this.send({type:"message",content:e})}sendHandoffComplete(e){this.send({type:"handoff_complete",...e})}sendEscalationEmail(e){this.send({type:"escalation_email",email:e})}on(e,t){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),()=>{this.listeners.get(e)?.delete(t)}}send(e){this.ws&&this.ws.readyState===WebSocket.OPEN&&this.ws.send(JSON.stringify(e))}emit(e,t={}){let a={type:e,data:t};this.listeners.get(e)?.forEach(r=>{try{r(a)}catch(i){console.error(`NamiruChat: error in ${e} handler`,i)}})}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 K=class{constructor(e,t){this.timerId=null;this.minutes=e,this.callback=t}reset(){this.stop(),this.timerId=setTimeout(()=>{this.callback()},this.minutes*60*1e3)}stop(){this.timerId!==null&&(clearTimeout(this.timerId),this.timerId=null)}updateMinutes(e){this.minutes=e,this.timerId!==null&&this.reset()}};var V=!1;function be(n){V=n}var X=null;function xe(n,e,t){let a=typeof n=="string"?{primaryColor:n}:n,r=document.createElement("style");r.setAttribute("data-namiru","true"),r.textContent=Ye(a,t),e instanceof ShadowRoot||e.shadowRoot?e.appendChild(r):document.head.appendChild(r),X=r}function ve(){X&&(X.remove(),X=null)}function qe(n){return!n||n==="system"?'"Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif':n==="modern"?'"Inter", sans-serif':n==="classic"?'"Georgia", serif':n}function je(n){return n==="small"?"13px":n==="large"?"17px":"15px"}function re(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),r=parseInt(e.substring(4,6),16);return(t*299+a*587+r*114)/1e3>150}function Ye(n,e){let t=e?" !important":"",a=n.primaryColor,r=n.accentColor||"#21DFFB",i=qe(n.fontFamily),l=je(n.fontSize),o=n.presetTheme==="dark",s=n.backgroundColor||(o?"#0f0f1a":"#ffffff"),d=n.textColor||(o?"#ffffff":"#1f2937"),c=!re(s),p=c?"rgba(255,255,255,0.15)":"rgba(0,0,0,0.1)",w=c?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.02)",g=c?"rgba(255,255,255,0.6)":"rgba(0,0,0,0.45)",v=c?"rgba(255,255,255,0.2)":"rgba(0,0,0,0.12)",y=n.headerColor||s,k=n.headerColor?re(y)?"#1f2937":"#ffffff":d,C=n.headerColor?re(y)?"rgba(0,0,0,0.5)":"rgba(255,255,255,0.7)":g,N=c?"#0f0f1a":a,S=oe(c?"#0f0f1a":a,-15);return`
1
+ function be(){return{state:"idle",messages:[],isOpen:!1,isLoading:!1,streamingContent:"",qualification:null,feedbackGiven:!1,sessionId:null,error:null}}function qe(n,e){switch(e.type){case"SET_STATE":return{...n,state:e.state,error:null};case"SET_OPEN":return{...n,isOpen:e.isOpen};case"SET_LOADING":return{...n,isLoading:e.isLoading};case"ADD_MESSAGE":return{...n,messages:[...n.messages,e.message]};case"APPEND_STREAMING":return{...n,streamingContent:n.streamingContent+e.token};case"CLEAR_STREAMING":return{...n,streamingContent:""};case"SET_QUALIFICATION":return{...n,qualification:e.qualification};case"SET_FEEDBACK_GIVEN":return{...n,feedbackGiven:!0};case"SET_SESSION_ID":return{...n,sessionId:e.sessionId};case"SET_ERROR":return{...n,error:e.error,state:e.error?"error":n.state};case"RESET":return be();default:return n}}var Y=class{constructor(){this.subscribers=new Set;this.state=be()}getState(){return this.state}dispatch(e){let t=this.state;this.state=qe(t,e),this.state!==t&&this.notify()}subscribe(e){return this.subscribers.add(e),()=>{this.subscribers.delete(e)}}notify(){let e=this.state;this.subscribers.forEach(t=>{try{t(e)}catch(a){console.error("NamiruChat: error in store subscriber",a)}})}};var J=class{constructor(e){this.baseUrl=e.baseUrl.replace(/\/$/,"")}async fetchBranding(e){let t=await fetch(`${this.baseUrl}/api/public/agents/${encodeURIComponent(e)}/branding`);if(!t.ok)throw new Error(`Failed to fetch agent branding: ${t.status}`);let a=await t.json(),r=a.branding||{};function i(o,s){return typeof o=="string"&&/^#[0-9a-fA-F]{3,8}$/.test(o)?o:s}let l=[];if(Array.isArray(r.suggestedQuestions))l=r.suggestedQuestions;else if(typeof r.suggestedQuestions=="string")try{let o=JSON.parse(r.suggestedQuestions);Array.isArray(o)&&(l=o)}catch{}return{agentId:a.id,name:r.agentDisplayName||a.name,primaryColor:i(r.primaryColor,"#1f2937"),accentColor:i(r.accentColor,"#21DFFB"),logoUrl:r.agentAvatar||r.logoUrl||void 0,agentAvatar:r.agentAvatar||r.logoUrl||void 0,welcomeMessage:r.welcomeMessage||void 0,showPoweredBy:r.showPoweredBy??!0,showHeader:r.showHeader??!0,headerColor:i(r.headerColor,"")||void 0,headerTitle:r.headerTitle||void 0,headerSubtitle:r.headerSubtitle||void 0,presetTheme:r.presetTheme||"light",backgroundColor:i(r.backgroundColor,"")||void 0,textColor:i(r.textColor,"")||void 0,bubbleStyle:r.bubbleStyle||"modern",fontFamily:r.fontFamily||"system",fontSize:r.fontSize||"medium",userMessageColor:i(r.userMessageColor,"")||void 0,agentMessageColor:i(r.agentMessageColor,"")||void 0,bubbleGreeting:r.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}}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 r=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(!r.ok)throw new Error(`Failed to request transcript: ${r.status}`);return r.json()}async submitLimitMessage(e){let t=await fetch(`${this.baseUrl}/api/leads/limit-message`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw new Error(`Failed to submit limit message: ${t.status}`);return t.json()}async submitContactMessage(e,t){let a=await fetch(`${this.baseUrl}/api/public/agents/${encodeURIComponent(e)}/contact`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!a.ok)throw new Error(`Failed to submit contact message: ${a.status}`);return a.json()}async submitLead(e){let t=await fetch(`${this.baseUrl}/api/leads`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw new Error(`Failed to submit lead: ${t.status}`);return t.json()}};var K=class{constructor(e){this.ws=null;this.listeners=new Map;this.reconnectAttempts=0;this.isDestroyed=!1;this.isInitialized=!1;this.config=e,this.maxReconnectAttempts=e.maxReconnectAttempts??3}connect(){if(!this.isDestroyed)try{this.ws=new WebSocket(this.config.url),this.ws.onopen=this.handleOpen.bind(this),this.ws.onmessage=this.handleMessage.bind(this),this.ws.onclose=this.handleClose.bind(this),this.ws.onerror=this.handleError.bind(this)}catch(e){this.emit("error",{message:e instanceof Error?e.message:"WebSocket connection failed"})}}disconnect(){this.isDestroyed=!0,this.ws&&(this.ws.onclose=null,this.ws.close(),this.ws=null)}sendMessage(e){this.send({type:"message",content:e})}sendHandoffComplete(e){this.send({type:"handoff_complete",...e})}sendEscalationEmail(e){this.send({type:"escalation_email",email:e})}on(e,t){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),()=>{this.listeners.get(e)?.delete(t)}}send(e){this.ws&&this.ws.readyState===WebSocket.OPEN&&this.ws.send(JSON.stringify(e))}emit(e,t={}){let a={type:e,data:t};this.listeners.get(e)?.forEach(r=>{try{r(a)}catch(i){console.error(`NamiruChat: error in ${e} handler`,i)}})}handleOpen(){this.reconnectAttempts=0,this.emit("connected",{}),this.isInitialized||this.send({type:"init_agent",agentId:this.config.agentId,token:this.config.token||"",visitorId:this.config.visitorId||""})}handleMessage(e){let t;try{t=JSON.parse(e.data)}catch{return}switch(t.type){case"agent_initialized":this.isInitialized=!0,this.emit("agent_initialized",t);break;case"stream_token":this.emit("stream_token",t);break;case"final_response":this.emit("final_response",t);break;case"stream_end":this.emit("stream_end",t);break;case"tool_start":this.emit("tool_start",t);break;case"tool_end":this.handleToolEnd(t);break;case"usage_limit":this.emit("usage_limit",t),this.emit("error",{...t,usage_limit:!0});break;case"show_handoff_form":this.emit("show_handoff_form",t);break;case"handoff_active":this.emit("handoff_active",t);break;case"error":this.emit("error",t);break;case"status":this.emit("status",t);break;default:break}}handleToolEnd(e){if(this.emit("tool_end",e),e.output)try{let t=typeof e.output=="string"?JSON.parse(e.output):e.output;t.kitTrigger&&this.emit("kit_trigger",t.kitTrigger)}catch{}}handleClose(e){if(e.code===1008){this.isDestroyed=!0,this.emit("disconnected",{code:e.code,reason:e.reason,permanent:!0});return}if(this.emit("disconnected",{code:e.code,reason:e.reason}),!this.isDestroyed&&this.reconnectAttempts<this.maxReconnectAttempts){this.reconnectAttempts++;let t=1e3*Math.pow(2,this.reconnectAttempts-1);setTimeout(()=>this.connect(),t)}}handleError(){this.emit("error",{message:"WebSocket connection error"})}};var X=class{constructor(e,t){this.timerId=null;this.minutes=e,this.callback=t}reset(){this.stop(),this.timerId=setTimeout(()=>{this.callback()},this.minutes*60*1e3)}stop(){this.timerId!==null&&(clearTimeout(this.timerId),this.timerId=null)}updateMinutes(e){this.minutes=e,this.timerId!==null&&this.reset()}};var V=!1;function xe(n){V=n}var ee=null;function ye(n,e,t){let a=typeof n=="string"?{primaryColor:n}:n,r=document.createElement("style");r.setAttribute("data-namiru","true"),r.textContent=Ye(a,t),e instanceof ShadowRoot||e.shadowRoot?e.appendChild(r):document.head.appendChild(r),ee=r}function ve(){ee&&(ee.remove(),ee=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 Qe(n){return n==="small"?"13px":n==="large"?"17px":"15px"}function re(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),r=parseInt(e.substring(4,6),16);return(t*299+a*587+r*114)/1e3>150}function Ye(n,e){let t=e?" !important":"",a=n.primaryColor,r=n.accentColor||"#21DFFB",i=je(n.fontFamily),l=Qe(n.fontSize),o=n.presetTheme==="dark",s=n.backgroundColor||(o?"#0f0f1a":"#ffffff"),d=n.textColor||(o?"#ffffff":"#1f2937"),m=!re(s),p=m?"rgba(255,255,255,0.15)":"rgba(0,0,0,0.1)",k=m?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.02)",g=m?"rgba(255,255,255,0.6)":"rgba(0,0,0,0.45)",E=m?"rgba(255,255,255,0.2)":"rgba(0,0,0,0.12)",x=n.headerColor||s,C=n.headerColor?re(x)?"#1f2937":"#ffffff":d,y=n.headerColor?re(x)?"rgba(0,0,0,0.5)":"rgba(255,255,255,0.7)":g,A=m?"#0f0f1a":a,S=oe(m?"#0f0f1a":a,-15);return`
2
2
  /* Namiru Chat Widget Styles */
3
3
  .namiru-widget-root {
4
4
  --namiru-primary: ${a};
5
5
  --namiru-primary-hover: ${oe(a,-15)};
6
6
  --namiru-accent: ${r};
7
- --namiru-header-bg: ${y};
8
- --namiru-header-text: ${k};
9
- --namiru-header-text-secondary: ${C};
7
+ --namiru-header-bg: ${x};
8
+ --namiru-header-text: ${C};
9
+ --namiru-header-text-secondary: ${y};
10
10
  --namiru-bg: ${s};
11
- --namiru-bg-secondary: ${w};
11
+ --namiru-bg-secondary: ${k};
12
12
  --namiru-text: ${d};
13
13
  --namiru-text-secondary: ${g};
14
14
  --namiru-border: ${p};
@@ -16,10 +16,10 @@ function fe(){return{state:"idle",messages:[],isOpen:!1,isLoading:!1,streamingCo
16
16
  --namiru-radius: 12px;
17
17
  --namiru-font: ${i};
18
18
  --namiru-font-size: ${l};
19
- --namiru-scroll-thumb: ${v};
19
+ --namiru-scroll-thumb: ${E};
20
20
  --namiru-user-msg-bg: ${n.userMessageColor||a};
21
21
  --namiru-agent-msg-bg: ${n.agentMessageColor||"transparent"};
22
- --namiru-button-bg: ${N};
22
+ --namiru-button-bg: ${A};
23
23
  --namiru-button-bg-hover: ${S};
24
24
  font-family: var(--namiru-font)${t};
25
25
  font-size: var(--namiru-font-size)${t};
@@ -41,7 +41,7 @@ function fe(){return{state:"idle",messages:[],isOpen:!1,isLoading:!1,streamingCo
41
41
  height: 56px;
42
42
  border-radius: 50%;
43
43
  background: var(--namiru-button-bg);
44
- border: none;
44
+ border: 1px solid var(--namiru-border);
45
45
  cursor: pointer;
46
46
  display: flex;
47
47
  align-items: center;
@@ -370,9 +370,11 @@ function fe(){return{state:"idle",messages:[],isOpen:!1,isLoading:!1,streamingCo
370
370
  /* Suggested questions */
371
371
  .namiru-suggestions {
372
372
  display: flex;
373
- flex-wrap: wrap;
373
+ flex-direction: column;
374
+ align-items: flex-end;
375
+ max-width: 70%;
376
+ margin-left: auto;
374
377
  gap: 8px;
375
- justify-content: center;
376
378
  padding: 4px 0;
377
379
  }
378
380
 
@@ -384,12 +386,10 @@ function fe(){return{state:"idle",messages:[],isOpen:!1,isLoading:!1,streamingCo
384
386
  background: var(--namiru-bg-secondary);
385
387
  color: var(--namiru-text);
386
388
  cursor: pointer;
387
- max-width: 200px;
388
- white-space: nowrap;
389
- overflow: hidden;
390
- text-overflow: ellipsis;
389
+ white-space: normal;
391
390
  font-family: var(--namiru-font);
392
391
  transition: border-color 0.15s, background 0.15s;
392
+ text-align: right;
393
393
  }
394
394
 
395
395
  .namiru-suggestion-chip:hover {
@@ -1068,24 +1068,24 @@ function fe(){return{state:"idle",messages:[],isOpen:!1,isLoading:!1,streamingCo
1068
1068
  border-top: 1px solid rgba(0,0,0,0.1);
1069
1069
  margin: 0.6em 0;
1070
1070
  }
1071
- `}function oe(n,e){let t=n.replace("#",""),a=parseInt(t,16);if(isNaN(a)||t.length<6)return n;let r=Math.max(0,Math.min(255,(a>>16&255)+e)),i=Math.max(0,Math.min(255,(a>>8&255)+e)),l=Math.max(0,Math.min(255,(a&255)+e));return`#${(r<<16|i<<8|l).toString(16).padStart(6,"0")}`}function Je(n){return n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function ee(n){let e=Je(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(`
1072
- `),a=[],r=!1,i=!1;for(let d=0;d<t.length;d++){let c=t[d];if(c.includes('<hr class="namiru-md-hr">')){r&&(a.push("</ul>"),r=!1),i&&(a.push("</ol>"),i=!1),a.push(c);continue}let p=c.match(/^(\s*)[-*]\s+(.*)/),w=c.match(/^(\s*)\d+\.\s+(.*)/);p?(r||(i&&(a.push("</ol>"),i=!1),a.push('<ul class="namiru-md-ul">'),r=!0),a.push(`<li>${p[2]}</li>`)):w?(i||(r&&(a.push("</ul>"),r=!1),a.push('<ol class="namiru-md-ol">'),i=!0),a.push(`<li>${w[2]}</li>`)):(r&&(a.push("</ul>"),r=!1),i&&(a.push("</ol>"),i=!1),c.trim()===""?a.push(""):a.push(c))}r&&a.push("</ul>"),i&&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=V?"":" !important";return l=l.replace(/<p>/g,`<p style="color: var(--namiru-text)${s}; margin: 0 0 0.5em 0${s}; max-width: 100%${s}; word-wrap: break-word${s}; display: block${s}; visibility: visible${s};">`),l=l.replace(/<li>/g,`<li style="color: var(--namiru-text)${s}; margin: 0.2em 0${s}; display: list-item${s}; visibility: visible${s};">`),l=l.replace(/<strong>/g,`<strong style="color: var(--namiru-text)${s}; font-weight: 700${s}; display: inline${s}; visibility: visible${s}; font-size: inherit${s}; opacity: 1${s};">`),l=l.replace(/<em>/g,`<em style="color: var(--namiru-text)${s}; font-style: italic${s}; display: inline${s}; visibility: visible${s}; font-size: inherit${s}; opacity: 1${s};">`),l=l.replace(/<a href=/g,`<a style="color: var(--namiru-primary)${s}; text-decoration: underline${s}; display: inline${s}; visibility: visible${s};" href=`),l}function _(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 r=document.createElementNS("http://www.w3.org/2000/svg","path");r.setAttribute("d",a),t.appendChild(r)}return t}function ye(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 te(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 Ce(){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 ne(){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 Ee(){return _(["M231.87,114l-168-95.37A16,16,0,0,0,40.92,37.34L72.26,128,40.92,218.66a16,16,0,0,0,22.95,18.71l168-95.37A16,16,0,0,0,231.87,114ZM56,212.67l28.11-81.24A8,8,0,0,0,84.36,128H56L83.9,43.33,224,128Z"])}function we(){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 Se(){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 Qe(){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 Ke(){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 Xe(){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 ke(){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 et(){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 tt(){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 nt(){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 at(){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 it(){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 rt={ShoppingBag:Qe,Package:Ke,CreditCard:Xe,ChatCircle:ke,Rocket:et,Wrench:tt,Briefcase:nt,UserCircle:at,DotsThree:it};function Te(n){let e=rt[n];return e?e():ke()}function ot(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),r=parseInt(e.substring(4,6),16);return`${t}, ${a}, ${r}`}function Ae(n){let{store:e,branding:t,mode:a,onTranscriptClick:r,onNewChat:i,feedbackEnabled:l}=n;if(t.showHeader===!1){let g=document.createElement("div");return g.style.display="none",g}let o=document.createElement("div");o.className="namiru-header";let s=document.createElement("div");s.className="namiru-header-left";let d=ot(t.primaryColor);if(t.agentAvatar||t.logoUrl){let g=document.createElement("img");g.className="namiru-header-avatar",g.src=t.agentAvatar||t.logoUrl,g.alt=t.name,s.appendChild(g)}else{let g=document.createElement("div");g.className="namiru-header-avatar-fallback",g.style.background=`rgba(${d}, 0.06)`,g.style.border="none";let v=t.presetTheme==="dark",y=ye(v?"#ffffff":t.primaryColor);g.appendChild(y),s.appendChild(g)}let c=document.createElement("div");c.className="namiru-header-info";let p=document.createElement("div");if(p.className="namiru-header-name",p.textContent=t.headerTitle||t.name,c.appendChild(p),t.headerSubtitle){let g=document.createElement("div");g.className="namiru-header-subtitle",g.textContent=t.headerSubtitle,c.appendChild(g)}s.appendChild(c),o.appendChild(s);let w=document.createElement("div");if(w.className="namiru-header-actions",a==="button"){let g=document.createElement("button");g.className="namiru-header-btn",g.setAttribute("aria-label","Close chat"),g.appendChild(ne()),g.addEventListener("click",()=>{let v=e.getState();if(l&&!v.feedbackGiven&&v.state==="chatting"&&v.messages.length>0){e.dispatch({type:"SET_STATE",state:"feedback"});return}if(v.messages.length===0){e.dispatch({type:"SET_OPEN",isOpen:!1});return}st(o,e)}),w.appendChild(g)}return o.appendChild(w),o}function st(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 r=document.createElement("div");r.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 i=document.createElement("div");i.style.cssText="font-size:14px;font-weight:600;color:var(--namiru-text,#1f2937);margin-bottom:4px;",i.textContent="End conversation?",r.appendChild(i);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="Your chat history will not be saved.",r.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:"SET_OPEN",isOpen:!1})}),o.appendChild(s),o.appendChild(d),r.appendChild(o),a.appendChild(r),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=`
1071
+ `}function oe(n,e){let t=n.replace("#",""),a=parseInt(t,16);if(isNaN(a)||t.length<6)return n;let r=Math.max(0,Math.min(255,(a>>16&255)+e)),i=Math.max(0,Math.min(255,(a>>8&255)+e)),l=Math.max(0,Math.min(255,(a&255)+e));return`#${(r<<16|i<<8|l).toString(16).padStart(6,"0")}`}function Je(n){return n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function te(n){let e=Je(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(`
1072
+ `),a=[],r=!1,i=!1;for(let d=0;d<t.length;d++){let m=t[d];if(m.includes('<hr class="namiru-md-hr">')){r&&(a.push("</ul>"),r=!1),i&&(a.push("</ol>"),i=!1),a.push(m);continue}let p=m.match(/^(\s*)[-*]\s+(.*)/),k=m.match(/^(\s*)\d+\.\s+(.*)/);p?(r||(i&&(a.push("</ol>"),i=!1),a.push('<ul class="namiru-md-ul">'),r=!0),a.push(`<li>${p[2]}</li>`)):k?(i||(r&&(a.push("</ul>"),r=!1),a.push('<ol class="namiru-md-ol">'),i=!0),a.push(`<li>${k[2]}</li>`)):(r&&(a.push("</ul>"),r=!1),i&&(a.push("</ol>"),i=!1),m.trim()===""?a.push(""):a.push(m))}r&&a.push("</ul>"),i&&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=V?"":" !important";return l=l.replace(/<p>/g,`<p style="color: var(--namiru-text)${s}; margin: 0 0 0.5em 0${s}; max-width: 100%${s}; word-wrap: break-word${s}; display: block${s}; visibility: visible${s};">`),l=l.replace(/<li>/g,`<li style="color: var(--namiru-text)${s}; margin: 0.2em 0${s}; display: list-item${s}; visibility: visible${s};">`),l=l.replace(/<strong>/g,`<strong style="color: var(--namiru-text)${s}; font-weight: 700${s}; display: inline${s}; visibility: visible${s}; font-size: inherit${s}; opacity: 1${s};">`),l=l.replace(/<em>/g,`<em style="color: var(--namiru-text)${s}; font-style: italic${s}; display: inline${s}; visibility: visible${s}; font-size: inherit${s}; opacity: 1${s};">`),l=l.replace(/<a href=/g,`<a style="color: var(--namiru-primary)${s}; text-decoration: underline${s}; display: inline${s}; visibility: visible${s};" href=`),l}function L(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 r=document.createElementNS("http://www.w3.org/2000/svg","path");r.setAttribute("d",a),t.appendChild(r)}return t}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","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 ne(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 L(["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 L(["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 L(["M231.87,114l-168-95.37A16,16,0,0,0,40.92,37.34L72.26,128,40.92,218.66a16,16,0,0,0,22.95,18.71l168-95.37A16,16,0,0,0,231.87,114ZM56,212.67l28.11-81.24A8,8,0,0,0,84.36,128H56L83.9,43.33,224,128Z"])}function Se(){return L(["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 L(["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 Ke(){return L(["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 Xe(){return L(["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 et(){return L(["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 L(["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 tt(){return L(["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 nt(){return L(["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 at(){return L(["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 it(){return L(["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 rt(){return L(["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 ot={ShoppingBag:Ke,Package:Xe,CreditCard:et,ChatCircle:Te,Rocket:tt,Wrench:nt,Briefcase:at,UserCircle:it,DotsThree:rt};function Ae(n){let e=ot[n];return e?e():Te()}function st(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),r=parseInt(e.substring(4,6),16);return`${t}, ${a}, ${r}`}function Me(n){let{store:e,branding:t,mode:a,onTranscriptClick:r,onNewChat:i,feedbackEnabled:l}=n;if(t.showHeader===!1){let g=document.createElement("div");return g.style.display="none",g}let o=document.createElement("div");o.className="namiru-header";let s=document.createElement("div");s.className="namiru-header-left";let d=st(t.primaryColor);if(t.agentAvatar||t.logoUrl){let g=document.createElement("img");g.className="namiru-header-avatar",g.src=t.agentAvatar||t.logoUrl,g.alt=t.name,s.appendChild(g)}else{let g=document.createElement("div");g.className="namiru-header-avatar-fallback",g.style.background=`rgba(${d}, 0.06)`,g.style.border="none";let E=t.presetTheme==="dark",x=Ce(E?"#ffffff":t.primaryColor);g.appendChild(x),s.appendChild(g)}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 g=document.createElement("div");g.className="namiru-header-subtitle",g.textContent=t.headerSubtitle,m.appendChild(g)}s.appendChild(m),o.appendChild(s);let k=document.createElement("div");if(k.className="namiru-header-actions",a==="button"){let g=document.createElement("button");g.className="namiru-header-btn",g.setAttribute("aria-label","Close chat"),g.appendChild(ae()),g.addEventListener("click",()=>{let E=e.getState();if(l&&!E.feedbackGiven&&E.state==="chatting"&&E.messages.length>0){e.dispatch({type:"SET_STATE",state:"feedback"});return}if(E.messages.length===0){e.dispatch({type:"SET_OPEN",isOpen:!1});return}se(o,e)}),k.appendChild(g)}return o.appendChild(k),o}function se(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 r=document.createElement("div");r.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 i=document.createElement("div");i.style.cssText="font-size:14px;font-weight:600;color:var(--namiru-text,#1f2937);margin-bottom:4px;",i.textContent="End conversation?",r.appendChild(i);let l=document.createElement("div");l.style.cssText="font-size:13px;color:var(--namiru-text-secondary,#6b7280);line-height:1.4;margin-bottom:16px;",l.textContent="We've received your message. Your chat history will not be saved.",r.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),r.appendChild(o),a.appendChild(r),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=`
1073
1073
  @keyframes namiruConfirmFade { from { opacity: 0; } to { opacity: 1; } }
1074
1074
  @keyframes namiruConfirmSlide { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
1075
- `,t.appendChild(c)}t.style.position="relative",t.appendChild(a)}function Me(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 r=document.createElement("textarea");r.className="namiru-input",r.placeholder="Type your message...",r.rows=1,r.setAttribute("aria-label","Chat message"),V?r.style.color="var(--namiru-text)":r.style.setProperty("color","var(--namiru-text)","important");let i=document.createElement("button");i.className="namiru-send-btn",i.setAttribute("aria-label","Send message"),i.disabled=!0,i.appendChild(Ee());function l(){let o=r.value.trim();o&&(e(o),r.value="",r.style.height="auto",i.disabled=!0)}return r.addEventListener("input",()=>{i.disabled=!r.value.trim(),r.style.height="auto",r.style.height=Math.min(r.scrollHeight,100)+"px"}),r.addEventListener("keydown",o=>{o.key==="Enter"&&!o.shiftKey&&(o.preventDefault(),l())}),i.addEventListener("click",l),a.appendChild(r),a.appendChild(i),t.appendChild(a),t}function se(n){if(n.agentAvatar){let a=document.createElement("img");return a.src=n.agentAvatar,a.alt="Agent",a.className="namiru-message-avatar-img",a}let e=document.createElement("span"),t=n.presetTheme==="dark";return e.appendChild(te(t?"#ffffff":n.textColor)),e}function Ne(n){return{createBubble(e){return e.role==="user"?lt(e,n):ct(e,n)},createStreaming(){return dt(n)},createLoading(){return mt(n)}}}function lt(n,e){let t=document.createElement("div");t.className="namiru-message-row namiru-message-row--user";let a=document.createElement("div"),r="namiru-message namiru-message--user";return e.bubbleStyle==="rounded"?r+=" namiru-bubble--rounded":e.bubbleStyle==="square"&&(r+=" namiru-bubble--square"),a.className=r,a.textContent=n.content,t.appendChild(a),t}function ct(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(se(e)),t.appendChild(a);let r=document.createElement("div");return r.className="namiru-message namiru-message--assistant namiru-md",r.innerHTML=ee(n.content),t.appendChild(r),t}function dt(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(se(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 mt(n){let e=document.createElement("div");e.className="namiru-message-row namiru-message-row--assistant";let t=document.createElement("div");t.className="namiru-message-icon",t.appendChild(se(n)),e.appendChild(t);let a=document.createElement("div");a.className="namiru-loading";for(let r=0;r<3;r++){let i=document.createElement("div");i.className="namiru-loading-dot",a.appendChild(i)}return e.appendChild(a),e}function Le(n){let{question:e,options:t,onSelect:a}=n,r=document.createElement("div");r.className="namiru-prechat";let i=document.createElement("div");i.className="namiru-prechat-question",i.textContent=e,r.appendChild(i);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=Te(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 r.appendChild(l),r}function Ie(n){let{onFeedback:e,softPrompt:t}=n,a=document.createElement("div");a.className="namiru-feedback";let r=document.createElement("div");r.className="namiru-feedback-label",r.textContent="Feedback",a.appendChild(r);let i=document.createElement("div");i.className="namiru-feedback-text",i.textContent=t?"How did it go? Your feedback helps us improve.":"How was your experience?",a.appendChild(i);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(we());let s=document.createElement("button");s.className="namiru-feedback-btn namiru-feedback-btn-down",s.setAttribute("aria-label","Thumbs down"),s.appendChild(Se());function d(c){for(e(c);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",()=>d("up")),s.addEventListener("click",()=>d("down")),l.appendChild(o),l.appendChild(s),a.appendChild(l),a}function le(n){let{promptText:e,buttonText:t,onSubmit:a}=n,r=document.createElement("div");r.className="namiru-email-form";let i=document.createElement("div");i.className="namiru-email-form-text",i.textContent=e,r.appendChild(i);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(),i.remove();let p=document.createElement("div");p.className="namiru-email-sent",p.textContent="Thanks, we'll be in touch",r.appendChild(p)}return o.addEventListener("keydown",c=>{c.key==="Enter"&&(c.preventDefault(),d())}),s.addEventListener("click",d),l.appendChild(o),l.appendChild(s),r.appendChild(l),r}function _e(n){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(n.trim())}function $e(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 r=document.createElement("label");r.className="namiru-contact-label",r.textContent="Name (optional)",t.appendChild(r);let i=document.createElement("input");i.className="namiru-contact-input",i.type="text",i.placeholder="Your name",i.setAttribute("aria-label","Name"),t.appendChild(i);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 p=document.createElement("button");p.className="namiru-contact-submit",p.textContent="Send Message",p.disabled=!0,t.appendChild(p);function w(){let y=o.value.trim(),k=d.value.trim();return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(y)&&k.length>0}function g(){p.disabled=!w()}o.addEventListener("input",g),d.addEventListener("input",g);function v(){if(!w())return;let y={name:i.value.trim(),email:o.value.trim(),message:d.value.trim()};p.disabled=!0,p.textContent="Sending...",i.disabled=!0,o.disabled=!0,d.disabled=!0,e(y),t.textContent="";let k=document.createElement("div");k.className="namiru-contact-confirmation",k.textContent="Thanks! We'll get back to you shortly.",t.appendChild(k)}return p.addEventListener("click",v),o.addEventListener("keydown",y=>{y.key==="Enter"&&(y.preventDefault(),v())}),i.addEventListener("keydown",y=>{y.key==="Enter"&&(y.preventDefault(),v())}),t}function ut(){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 pt(){let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width","40"),n.setAttribute("height","40"),n.setAttribute("viewBox","0 0 256 256"),n.setAttribute("fill","none"),n.setAttribute("stroke","currentColor"),n.setAttribute("stroke-width","16"),n.setAttribute("stroke-linecap","round"),n.setAttribute("stroke-linejoin","round");let e=document.createElementNS("http://www.w3.org/2000/svg","circle");e.setAttribute("cx","128"),e.setAttribute("cy","128"),e.setAttribute("r","96"),n.appendChild(e);let t=document.createElementNS("http://www.w3.org/2000/svg","polyline");return t.setAttribute("points","88,136 112,160 168,104"),n.appendChild(t),n}function He(n){let{onSubmit:e,onNewChat:t}=n,a=document.createElement("div");a.className="namiru-limit-overlay";let r=document.createElement("div");r.className="namiru-limit-icon",r.appendChild(ut()),a.appendChild(r);let i=document.createElement("div");i.className="namiru-limit-heading",i.textContent="Conversation limit reached",a.appendChild(i);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 v=document.createElement("button");v.className="namiru-limit-newchat",v.textContent="Start New Chat",v.addEventListener("click",t),a.appendChild(v)}function p(){return s.value.trim().length>0}function w(){c.disabled=!p()}s.addEventListener("input",w);function g(){if(!p())return;let v=d.value.trim(),y={message:s.value.trim()};v&&(y.visitorEmail=v),c.disabled=!0,c.textContent="Sending...",s.disabled=!0,d.disabled=!0,e(y),a.textContent="";let k=document.createElement("div");k.className="namiru-limit-icon namiru-limit-icon--success",k.appendChild(pt()),a.appendChild(k);let C=document.createElement("div");if(C.className="namiru-limit-confirmation",C.textContent="Message sent! The team will get back to you soon.",a.appendChild(C),t){let N=document.createElement("button");N.className="namiru-limit-newchat",N.textContent="Start New Chat",N.addEventListener("click",t),a.appendChild(N)}}return c.addEventListener("click",g),a}function Oe(n){let{store:e,branding:t,agentId:a,mode:r,position:i,onSendMessage:l,onPreChatSelect:o,onFeedback:s,onEscalationEmail:d,onTranscriptEmail:c,onContactFormSubmit:p,onLimitMessage:w,onNewChat:g,feedbackEnabled:v}=n,y=t.agentAvatar||t.logoUrl,k=Ne({textColor:t.textColor,bubbleStyle:t.bubbleStyle,agentAvatar:y,presetTheme:t.presetTheme}),C=document.createElement("div");r==="button"?C.className=`namiru-popup namiru-popup--${i}`:C.className="namiru-inline";let N=Ae({store:e,branding:t,mode:r,...r==="button"?{onTranscriptClick:()=>{e.dispatch({type:"SET_STATE",state:"escalation"}),de()},onNewChat:g}:{},feedbackEnabled:v});C.appendChild(N);let S=document.createElement("div");S.className="namiru-messages",C.appendChild(S);let I=Me({onSend:l});I.style.display="none",C.appendChild(I);let Z=t.showPoweredBy!==!1;Z||(I.style.paddingBottom="12px");function B(){let m=document.createElement("div");m.className="namiru-powered",m.setAttribute("data-namiru-protected","true");let b=V?"":" !important";m.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",m.appendChild(document.createTextNode("Powered by ")),m.appendChild(E),m}if(Z){let b=B().innerHTML;C.appendChild(B());let E=!1;new MutationObserver(()=>{if(E)return;E=!0;let A=C.querySelector(".namiru-powered");if(!A)C.appendChild(B());else if(A.innerHTML!==b){let M=B();A.replaceWith(M)}else{let M=A.style,L=getComputedStyle(A);if(L.display==="none"||L.visibility==="hidden"||L.opacity==="0"){let F=V?"":" !important";M.cssText=`display:block${F};visibility:visible${F};opacity:1${F};`}}E=!1}).observe(C,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style","class"],characterData:!0})}t.fontFamily&&t.fontFamily!=="system"&&(C.style.fontFamily=t.fontFamily);let z=40,D=0,u=null,h=null,T=null,f=null,x=null,H=!1,$=null,W=null,U=null,P=null;function Fe(){if(P)return;P=document.createElement("div"),P.className="namiru-connecting";let m=document.createElement("div");m.className="namiru-loading-dots";for(let b=0;b<3;b++){let E=document.createElement("span");E.className="namiru-loading-dot",m.appendChild(E)}P.appendChild(m),S.appendChild(P)}function q(){P&&(P.remove(),P=null)}function ie(){S.textContent="",D=0,u=null,h=null,T=null,f=null,x=null,W=null,U=null,P=null,H=!1,$=null}function Ve(){if(H)return;H=!0;let m=t.welcomeMessage||"Hello! How can I help you today?",b=document.createElement("div");b.className="namiru-message-row namiru-message-row--assistant namiru-message-row--welcome";let E=document.createElement("div");if(E.className="namiru-message-icon",y){let M=document.createElement("img");M.src=y,M.alt="Agent",M.className="namiru-message-avatar-img",E.appendChild(M)}else E.appendChild(te(t.textColor));b.appendChild(E);let O=document.createElement("div");O.className="namiru-message namiru-message--assistant",O.textContent=m,b.appendChild(O),S.appendChild(b);let A=t.suggestedQuestions;A&&A.length>0&&($=document.createElement("div"),$.className="namiru-suggestions",A.slice(0,4).forEach(M=>{let L=document.createElement("button");L.className="namiru-suggestion-chip",L.textContent=M,L.addEventListener("click",()=>{l(M),$&&($.remove(),$=null)}),$.appendChild(L)}),S.appendChild($))}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"}]}},E,O;if(m.template==="custom"&&m.custom)E=m.custom.question,O=m.custom.options;else if(m.template&&b[m.template]){let A=b[m.template];E=A.question,O=A.options}else return;ie(),I.style.display="none",T=Le({question:E,options:O,onSelect:A=>{o(A),I.style.display=""}}),S.appendChild(T)}function de(){x||(x=le({promptText:"Want a copy of this conversation? Handy if you need to reference it later for support.",buttonText:"Send",onSubmit:m=>{c(m),x=null}}),S.appendChild(x),R())}function me(){x||(x=le({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),x=null}}),S.appendChild(x),R())}function ue(){W||(ie(),I.style.display="none",W=$e({onSubmit:m=>{p&&p(m),W=null}}),S.appendChild(W))}function pe(){U||(I.style.display="none",U=He({onSubmit:m=>{w&&w(m),U=null}}),S.style.position="relative",S.appendChild(U))}function Re(){for(;S.firstChild;)S.removeChild(S.firstChild);S.style.position="relative";let m=document.createElement("div");m.style.cssText=`
1075
+ `,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 r=document.createElement("textarea");r.className="namiru-input",r.placeholder="Type your message...",r.rows=1,r.setAttribute("aria-label","Chat message"),V?r.style.color="var(--namiru-text)":r.style.setProperty("color","var(--namiru-text)","important");let i=document.createElement("button");i.className="namiru-send-btn",i.setAttribute("aria-label","Send message"),i.disabled=!0,i.appendChild(we());function l(){let o=r.value.trim();o&&(e(o),r.value="",r.style.height="auto",i.disabled=!0)}return r.addEventListener("input",()=>{i.disabled=!r.value.trim(),r.style.height="auto",r.style.height=Math.min(r.scrollHeight,100)+"px"}),r.addEventListener("keydown",o=>{o.key==="Enter"&&!o.shiftKey&&(o.preventDefault(),l())}),i.addEventListener("click",l),a.appendChild(r),a.appendChild(i),t.appendChild(a),t}function le(n){if(n.agentAvatar){let a=document.createElement("img");return a.src=n.agentAvatar,a.alt="Agent",a.className="namiru-message-avatar-img",a}let e=document.createElement("span"),t=n.presetTheme==="dark";return e.appendChild(ne(t?"#ffffff":n.textColor)),e}function _e(n){return{createBubble(e){return e.role==="user"?lt(e,n):ct(e,n)},createStreaming(){return dt(n)},createLoading(){return mt(n)}}}function lt(n,e){let t=document.createElement("div");t.className="namiru-message-row namiru-message-row--user";let a=document.createElement("div"),r="namiru-message namiru-message--user";return e.bubbleStyle==="rounded"?r+=" namiru-bubble--rounded":e.bubbleStyle==="square"&&(r+=" namiru-bubble--square"),a.className=r,a.textContent=n.content,t.appendChild(a),t}function ct(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(le(e)),t.appendChild(a);let r=document.createElement("div");return r.className="namiru-message namiru-message--assistant namiru-md",r.innerHTML=te(n.content),t.appendChild(r),t}function dt(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(le(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 mt(n){let e=document.createElement("div");e.className="namiru-message-row namiru-message-row--assistant";let t=document.createElement("div");t.className="namiru-message-icon",t.appendChild(le(n)),e.appendChild(t);let a=document.createElement("div");a.className="namiru-loading";for(let r=0;r<3;r++){let i=document.createElement("div");i.className="namiru-loading-dot",a.appendChild(i)}return e.appendChild(a),e}function Ie(n){let{question:e,options:t,onSelect:a}=n,r=document.createElement("div");r.className="namiru-prechat";let i=document.createElement("div");i.className="namiru-prechat-question",i.textContent=e,r.appendChild(i);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 m=document.createElement("span");m.textContent=o.label,s.appendChild(m),s.addEventListener("click",()=>a(o.label)),l.appendChild(s)}return r.appendChild(l),r}function Le(n){let{onFeedback:e,softPrompt:t}=n,a=document.createElement("div");a.className="namiru-feedback";let r=document.createElement("div");r.className="namiru-feedback-label",r.textContent="Feedback",a.appendChild(r);let i=document.createElement("div");i.className="namiru-feedback-text",i.textContent=t?"How did it go? Your feedback helps us improve.":"How was your experience?",a.appendChild(i);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(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",()=>d("up")),s.addEventListener("click",()=>d("down")),l.appendChild(o),l.appendChild(s),a.appendChild(l),a}function ce(n){let{promptText:e,buttonText:t,onSubmit:a}=n,r=document.createElement("div");r.className="namiru-email-form";let i=document.createElement("div");i.className="namiru-email-form-text",i.textContent=e,r.appendChild(i);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 m=o.value.trim();if(!$e(m))return;a(m),l.remove(),i.remove();let p=document.createElement("div");p.className="namiru-email-sent",p.textContent="Thanks, we'll be in touch",r.appendChild(p)}return o.addEventListener("keydown",m=>{m.key==="Enter"&&(m.preventDefault(),d())}),s.addEventListener("click",d),l.appendChild(o),l.appendChild(s),r.appendChild(l),r}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 r=document.createElement("label");r.className="namiru-contact-label",r.textContent="Name (optional)",t.appendChild(r);let i=document.createElement("input");i.className="namiru-contact-input",i.type="text",i.placeholder="Your name",i.setAttribute("aria-label","Name"),t.appendChild(i);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 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 k(){let x=o.value.trim(),C=d.value.trim();return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(x)&&C.length>0}function g(){p.disabled=!k()}o.addEventListener("input",g),d.addEventListener("input",g);function E(){if(!k())return;let x={name:i.value.trim(),email:o.value.trim(),message:d.value.trim()};p.disabled=!0,p.textContent="Sending...",i.disabled=!0,o.disabled=!0,d.disabled=!0,e(x),t.textContent="";let C=document.createElement("div");C.className="namiru-contact-confirmation",C.textContent="Thanks! We'll get back to you shortly.",t.appendChild(C)}return p.addEventListener("click",E),o.addEventListener("keydown",x=>{x.key==="Enter"&&(x.preventDefault(),E())}),i.addEventListener("keydown",x=>{x.key==="Enter"&&(x.preventDefault(),E())}),t}function ut(){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 pt(){let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width","40"),n.setAttribute("height","40"),n.setAttribute("viewBox","0 0 256 256"),n.setAttribute("fill","none"),n.setAttribute("stroke","currentColor"),n.setAttribute("stroke-width","16"),n.setAttribute("stroke-linecap","round"),n.setAttribute("stroke-linejoin","round");let e=document.createElementNS("http://www.w3.org/2000/svg","circle");e.setAttribute("cx","128"),e.setAttribute("cy","128"),e.setAttribute("r","96"),n.appendChild(e);let t=document.createElementNS("http://www.w3.org/2000/svg","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 r=document.createElement("div");r.className="namiru-limit-icon",r.appendChild(ut()),a.appendChild(r);let i=document.createElement("div");i.className="namiru-limit-heading",i.textContent="Conversation limit reached",a.appendChild(i);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 m=document.createElement("button");if(m.className="namiru-limit-submit",m.textContent="Send Message",m.disabled=!0,o.appendChild(m),a.appendChild(o),t){let E=document.createElement("button");E.className="namiru-limit-newchat",E.textContent="Start New Chat",E.addEventListener("click",t),a.appendChild(E)}function p(){return s.value.trim().length>0}function k(){m.disabled=!p()}s.addEventListener("input",k);function g(){if(!p())return;let E=d.value.trim(),x={message:s.value.trim()};E&&(x.visitorEmail=E),m.disabled=!0,m.textContent="Sending...",s.disabled=!0,d.disabled=!0,e(x),a.textContent="";let C=document.createElement("div");C.className="namiru-limit-icon namiru-limit-icon--success",C.appendChild(pt()),a.appendChild(C);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 A=document.createElement("button");A.className="namiru-limit-newchat",A.textContent="Start New Chat",A.addEventListener("click",t),a.appendChild(A)}}return m.addEventListener("click",g),a}function De(n){let{store:e,branding:t,agentId:a,mode:r,position:i,onSendMessage:l,onPreChatSelect:o,onFeedback:s,onEscalationEmail:d,onTranscriptEmail:m,onContactFormSubmit:p,onLimitMessage:k,onNewChat:g,feedbackEnabled:E}=n,x=t.agentAvatar||t.logoUrl,C=_e({textColor:t.textColor,bubbleStyle:t.bubbleStyle,agentAvatar:x,presetTheme:t.presetTheme}),y=document.createElement("div");r==="button"?y.className=`namiru-popup namiru-popup--${i}`:y.className="namiru-inline";let A=Me({store:e,branding:t,mode:r,...r==="button"?{onTranscriptClick:()=>{e.dispatch({type:"SET_STATE",state:"escalation"}),me()},onNewChat:g}:{},feedbackEnabled:E});y.appendChild(A);let S=document.createElement("div");S.className="namiru-messages",y.appendChild(S);let M=Ne({onSend:l});M.style.display="none",y.appendChild(M);let Z=t.showPoweredBy!==!1;Z||(M.style.paddingBottom="12px");function B(){let c=document.createElement("div");c.className="namiru-powered",c.setAttribute("data-namiru-protected","true");let b=V?"":" !important";c.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",c.appendChild(document.createTextNode("Powered by ")),c.appendChild(w),c}if(Z){let b=B().innerHTML;y.appendChild(B());let w=!1;new MutationObserver(()=>{if(w)return;w=!0;let T=y.querySelector(".namiru-powered");if(!T)y.appendChild(B());else if(T.innerHTML!==b){let N=B();T.replaceWith(N)}else{let N=T.style,_=getComputedStyle(T);if(_.display==="none"||_.visibility==="hidden"||_.opacity==="0"){let F=V?"":" !important";N.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,D=0,u=null,f=null,I=null,h=null,v=null,H=!1,$=null,W=null,U=null,P=null;function Ve(){if(P)return;P=document.createElement("div"),P.className="namiru-connecting";let c=document.createElement("div");c.className="namiru-loading-dots";for(let b=0;b<3;b++){let w=document.createElement("span");w.className="namiru-loading-dot",c.appendChild(w)}P.appendChild(c),S.appendChild(P)}function q(){P&&(P.remove(),P=null)}function j(){S.textContent="",D=0,u=null,f=null,I=null,h=null,v=null,W=null,U=null,P=null,H=!1,$=null}function ze(){if(H)return;H=!0;let c=t.welcomeMessage||"Hello! How can I help you today?",b=document.createElement("div");b.className="namiru-message-row namiru-message-row--assistant namiru-message-row--welcome";let w=document.createElement("div");if(w.className="namiru-message-icon",x){let N=document.createElement("img");N.src=x,N.alt="Agent",N.className="namiru-message-avatar-img",w.appendChild(N)}else w.appendChild(ne(t.textColor));b.appendChild(w);let O=document.createElement("div");O.className="namiru-message namiru-message--assistant",O.textContent=c,b.appendChild(O),S.appendChild(b);let T=t.suggestedQuestions;console.log("[NamiruChat] renderWelcome suggestedQuestions:",T),T&&T.length>0&&($=document.createElement("div"),$.className="namiru-suggestions",T.slice(0,4).forEach(N=>{let _=document.createElement("button");_.className="namiru-suggestion-chip",_.textContent=N,_.addEventListener("click",()=>{l(N),$&&($.remove(),$=null)}),$.appendChild(_)}),S.appendChild($))}function Re(){let c=t.preChatConfig;if(!c||!c.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,O;if(c.template==="custom"&&c.custom)w=c.custom.question,O=c.custom.options;else if(c.template&&b[c.template]){let T=b[c.template];w=T.question,O=T.options}else return;j(),M.style.display="none",I=Ie({question:w,options:O,onSelect:T=>{o(T),M.style.display=""}}),S.appendChild(I)}function me(){v||(v=ce({promptText:"Want a copy of this conversation? Handy if you need to reference it later for support.",buttonText:"Send",onSubmit:c=>{m(c),v=null}}),S.appendChild(v),G())}function ue(){v||(v=ce({promptText:"We'll connect you with the team. Please share your email and we'll get back to you.",buttonText:"Submit",onSubmit:c=>{d(c),v=null}}),S.appendChild(v),G())}function pe(){W||(j(),M.style.display="none",W=He({onSubmit:c=>{p&&p(c),W=null}}),S.appendChild(W))}function ge(){U||(M.style.display="none",U=Oe({onSubmit:c=>{k&&k(c),U=null}}),S.style.position="relative",S.appendChild(U))}function Ge(){for(;S.firstChild;)S.removeChild(S.firstChild);S.style.position="relative";let c=document.createElement("div");c.style.cssText=`
1076
1076
  position: absolute; inset: 0; display: flex; flex-direction: column;
1077
1077
  align-items: center; justify-content: center; padding: 2rem; text-align: center;
1078
1078
  background: ${t.backgroundColor||"#ffffff"};
1079
1079
  color: ${t.textColor||"#1f2937"};
1080
- `;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),m.appendChild(b);let O=document.createElement("div");O.style.cssText="font-size: 18px; font-weight: 600; margin-bottom: 8px;",O.textContent="Domain Not Authorized",m.appendChild(O);let A=document.createElement("div");A.style.cssText="font-size: 14px; opacity: 0.7; margin-bottom: 24px; max-width: 300px; line-height: 1.5;",A.textContent="This chat widget is not authorized to run on this domain. Please update the allowed domain in your agent settings.",m.appendChild(A);let M=document.createElement("div");M.style.cssText="display: flex; gap: 12px; align-items: center;";let L=document.createElement("a");L.style.cssText=`
1080
+ `;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),c.appendChild(b);let O=document.createElement("div");O.style.cssText="font-size: 18px; font-weight: 600; margin-bottom: 8px;",O.textContent="Domain Not Authorized",c.appendChild(O);let T=document.createElement("div");T.style.cssText="font-size: 14px; opacity: 0.7; margin-bottom: 24px; max-width: 300px; line-height: 1.5;",T.textContent="This chat widget is not authorized to run on this domain. Please update the allowed domain in your agent settings.",c.appendChild(T);let N=document.createElement("div");N.style.cssText="display: flex; gap: 12px; align-items: center;";let _=document.createElement("a");_.style.cssText=`
1081
1081
  padding: 10px 24px; border-radius: 8px; border: none; cursor: pointer;
1082
1082
  font-size: 14px; font-weight: 500; text-decoration: none;
1083
1083
  display: inline-flex; align-items: center; box-sizing: border-box;
1084
- line-height: 1; background: ${t.primaryColor||"#4a7fff"}; color: #fff;
1085
- `,L.textContent="Go to Settings";let F=window.location.hostname,he=window.location.origin;F!=="localhost"&&F!=="127.0.0.1"&&F.endsWith("namiru.ai")&&(he=F.includes("test")?"https://test.namiru.ai":"https://namiru.ai"),L.href=`${he}/agent-builder/agent/${a}/settings?focus=domain`,L.target="_blank",L.rel="noopener",M.appendChild(L);let j=document.createElement("button");j.style.cssText=`
1084
+ line-height: 1; background: ${t.primaryColor||"#1f2937"}; color: #fff;
1085
+ `,_.textContent="Go to Settings";let F=window.location.hostname,fe=window.location.origin;F!=="localhost"&&F!=="127.0.0.1"&&F.endsWith("namiru.ai")&&(fe=F.includes("test")?"https://test.namiru.ai":"https://namiru.ai"),_.href=`${fe}/agent-builder/agent/${a}/settings?focus=domain`,_.target="_blank",_.rel="noopener",N.appendChild(_);let Q=document.createElement("button");Q.style.cssText=`
1086
1086
  padding: 10px 24px; border-radius: 8px; cursor: pointer;
1087
1087
  font-size: 14px; font-weight: 500; line-height: 1; box-sizing: border-box;
1088
1088
  background: transparent; color: ${t.textColor||"#1f2937"};
1089
1089
  border: 1px solid ${t.textColor?t.textColor+"33":"#e5e7eb"};
1090
- `,j.textContent="Reload",j.addEventListener("click",()=>window.location.reload()),M.appendChild(j),m.appendChild(M),S.appendChild(m)}function ge(m){f||(f=Ie({onFeedback:b=>{s(b),r==="button"&&setTimeout(()=>{e.dispatch({type:"SET_STATE",state:"chatting"}),e.dispatch({type:"SET_OPEN",isOpen:!1})},1200)},softPrompt:m}),S.appendChild(f),R())}function R(){requestAnimationFrame(()=>{S.scrollTop=S.scrollHeight})}function Ge(m){$&&m.some(b=>b.role==="user")&&($.remove(),$=null);for(let b=D;b<m.length;b++){let E=k.createBubble(m[b]);S.appendChild(E)}D=m.length,R()}function Ze(m){if(m){u||(h&&(h.remove(),h=null),u=k.createStreaming(),S.appendChild(u));let b=u._namiruTextEl,E=ee(m);b?b.innerHTML=E:u.innerHTML=E,R()}else u&&(u.remove(),u=null)}function We(m){m&&!h&&!u?(h=k.createLoading(),S.appendChild(h),R()):!m&&h&&(h.remove(),h=null)}let G=null;return e.subscribe(m=>{if(r==="button"&&(m.isOpen?C.classList.add("namiru-popup--open"):C.classList.remove("namiru-popup--open")),!G||G.state!==m.state)switch(m.state){case"connecting":I.style.display="none",Fe();break;case"pre_chat":ze();break;case"chatting":q(),G?.state==="pre_chat"&&ie(),I.style.display="",Ve();break;case"feedback":ge(!0);break;case"escalation":me();break;case"email_fallback":ue();break;case"conversation_limit":q(),I.style.display="none",pe();break;case"domain_error":q(),I.style.display="none",Re();break;case"error":q(),I.style.display="none";break}m.messages.length>D&&m.state!=="pre_chat"&&Ge(m.messages),m.state==="chatting"&&m.messages.length>=z&&e.dispatch({type:"SET_STATE",state:"conversation_limit"}),G?.streamingContent!==m.streamingContent&&Ze(m.streamingContent),G?.isLoading!==m.isLoading&&We(m.isLoading),G=m}),C._namiruShowEscalation=me,C._namiruShowFeedback=ge,C._namiruShowTranscript=de,C._namiruShowContactForm=ue,C._namiruShowLimitOverlay=pe,C}function De(n){let{position:e,store:t,welcomeMessage:a,greetingDelay:r,bubbleStyle:i}=n,l=document.createElement("div"),o=document.createElement("button");o.className=`namiru-button namiru-button--${e}`,i==="classic"&&o.classList.add("namiru-button--classic"),o.setAttribute("aria-label","Open chat");let s=Ce(),d=ne();d.style.display="none",o.appendChild(s),o.appendChild(d),o.addEventListener("click",()=>{let v=t.getState().isOpen;t.dispatch({type:"SET_OPEN",isOpen:!v})}),l.appendChild(o);let c=null,p=!1,w=null;if(a){c=document.createElement("div"),c.className=`namiru-greeting namiru-greeting--${e} namiru-greeting--hidden`;let v=document.createTextNode(a);c.appendChild(v);let y=document.createElement("button");y.className="namiru-greeting-close",y.setAttribute("aria-label","Dismiss"),y.textContent="\xD7",y.addEventListener("click",C=>{C.stopPropagation(),g()}),c.appendChild(y),c.addEventListener("click",()=>{g(),t.dispatch({type:"SET_OPEN",isOpen:!0})}),l.appendChild(c),w=setTimeout(()=>{!t.getState().isOpen&&c&&(c.classList.remove("namiru-greeting--hidden"),p=!0)},r??3e3)}function g(){p&&c&&(c.classList.add("namiru-greeting--hidden"),p=!1),w&&(clearTimeout(w),w=null)}return t.subscribe(v=>{v.isOpen?(s.style.display="none",d.style.display="",o.setAttribute("aria-label","Close chat"),g()):(s.style.display="",d.style.display="none",o.setAttribute("aria-label","Open chat"))}),l}function gt(n){try{let e=new URL(n),t=e.protocol==="https:"?"wss:":"ws:";return e.hostname==="localhost"||e.hostname==="127.0.0.1"?(e.port="3423",e.protocol=t,e.origin):e.hostname==="test.namiru.ai"?`${t}//ai-test.namiru.ai`:e.hostname==="namiru.ai"||e.hostname==="app.namiru.ai"?`${t}//ai.namiru.ai`:(e.protocol=t,e.origin)}catch{let e=n.startsWith("https")?"wss":"ws",t=n.replace(/^https?:\/\//,"");return`${e}://${t}`}}function ht(n){try{let e=new URL(n);return e.hostname.startsWith("app.")?(e.hostname=e.hostname.replace("app.","api."),e.origin):e.hostname==="test.namiru.ai"?(e.hostname="api-test.namiru.ai",e.origin):e.hostname==="namiru.ai"?(e.hostname="api.namiru.ai",e.origin):((e.hostname==="localhost"||e.hostname==="127.0.0.1")&&(e.port="3001"),e.origin)}catch{return n}}function ft(n){let e,t=null;if(n.serverUrl)e=n.serverUrl.replace(/\/$/,"");else{let a=document.querySelectorAll("script[src]");for(let r=a.length-1;r>=0;r--){let i=a[r].src;if(i.includes("namiru-chat")||i.includes("namiru"))try{t=new URL(i).origin;break}catch{}}e=ht(t||location.origin)}return{apiBase:e,wsUrl:n.wsUrl||gt(t||e)}}var Be="namiru_visitor_id";function ce(){try{let n=localStorage.getItem(Be);if(n)return n;let e=`v_${Date.now()}_${Math.random().toString(36).substring(2,11)}`;return localStorage.setItem(Be,e),e}catch{return`v_${Date.now()}_${Math.random().toString(36).substring(2,11)}`}}var Pe=0;function ae(){return Pe++,`msg-${Date.now()}-${Pe}`}function bt(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 xt(n){if(!n.agentId)throw new Error("NamiruChat: agentId is required");let e=n.mode||"button",t=n.position||"bottom-right",{apiBase:a,wsUrl:r}=ft(n),i=new Y,l=new J({baseUrl:a}),o=null,s=null,d=null,c=null,p=null,w=null,g=!1,v="handoff_accepted",y=!1,k=null,C=!1;s=document.createElement("div"),s.id="namiru-widget-host";let N=typeof s.attachShadow=="function";be(N),N&&(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 S=d||s;N&&(c.style.pointerEvents="auto"),S.appendChild(c);async function I(){try{let u=await l.fetchBranding(n.agentId);if(g)return;if(!bt(u.allowedDomains)){console.warn(`[Namiru Widget] Domain "${window.location.hostname}" is not allowed for this agent. Allowed: ${JSON.stringify(u.allowedDomains)}`);return}xe({primaryColor:u.primaryColor,accentColor:u.accentColor,headerColor:u.headerColor,fontFamily:u.fontFamily,presetTheme:u.presetTheme,backgroundColor:u.backgroundColor,textColor:u.textColor,fontSize:u.fontSize,userMessageColor:u.userMessageColor,agentMessageColor:u.agentMessageColor},S,!N);let h=n.preChatEnabled??u.preChatConfig?.enabled??!1;h&&(u.preChatConfig?(u.preChatConfig.enabled=!0,n.preChatTemplate!==void 0&&(u.preChatConfig.template=n.preChatTemplate),n.preChatCustom&&(u.preChatConfig.custom=n.preChatCustom)):u.preChatConfig={enabled:!0,template:n.preChatTemplate??null,custom:n.preChatCustom}),C=u.feedbackConfig?.enabled??!1;let T=u.feedbackConfig?.inactivityMinutes??3;if(C&&(k=new K(T,()=>{let f=i.getState();!f.feedbackGiven&&f.state==="chatting"&&f.messages.length>0&&i.dispatch({type:"SET_STATE",state:"feedback"})})),p=Oe({store:i,branding:u,agentId:n.agentId,mode:e,position:t,onSendMessage:f=>{let x={id:ae(),role:"user",content:f,timestamp:Date.now()};i.dispatch({type:"ADD_MESSAGE",message:x}),i.dispatch({type:"SET_LOADING",isLoading:!0}),o&&o.sendMessage(f)},onPreChatSelect:f=>{i.dispatch({type:"SET_QUALIFICATION",qualification:f}),i.dispatch({type:"SET_STATE",state:"connecting"}),B(f)},onFeedback:f=>{let x=i.getState().sessionId;x&&l.submitFeedback(n.agentId,{sessionId:x,rating:f}).catch(H=>console.error("NamiruChat: feedback submit failed",H)),i.dispatch({type:"SET_FEEDBACK_GIVEN"}),k?.stop(),n.onFeedback?.(f)},onEscalationEmail:f=>{let x=i.getState().sessionId;x&&l.submitEscalation(n.agentId,{sessionId:x,userEmail:f}).catch(H=>console.error("NamiruChat: escalation submit failed",H)),o&&o.sendEscalationEmail(f),n.onLeadCapture?.({email:f,sessionId:x||"",source:"email_fallback",qualification:i.getState().qualification||void 0})},onTranscriptEmail:f=>{let x=i.getState().sessionId;x&&l.requestTranscript(n.agentId,x,{email:f}).catch(H=>console.error("NamiruChat: transcript request failed",H))},onContactFormSubmit:f=>{let x=ce(),H=i.getState().sessionId;l.submitLead({agentId:n.agentId,name:f.name||void 0,email:f.email,message:f.message,visitorId:x,fallbackReason:v,conversationId:H||void 0}).catch($=>console.error("NamiruChat: lead submit failed",$)),o&&o.sendHandoffComplete({email:f.email,name:f.name||void 0,reason:v}),n.onLeadCapture?.({email:f.email,sessionId:H||"",source:"email_fallback",qualification:i.getState().qualification||void 0})},onLimitMessage:f=>{f.visitorEmail?l.submitContactMessage(n.agentId,{email:f.visitorEmail,message:f.message,visitorId:ce()}).catch(x=>console.error("NamiruChat: contact message submit failed",x)):l.submitLimitMessage({agentId:n.agentId,message:f.message}).catch(x=>console.error("NamiruChat: limit message submit failed",x))},feedbackEnabled:C,onNewChat:()=>{o&&(o.disconnect(),o=null),k?.stop(),i.dispatch({type:"RESET"}),i.dispatch({type:"SET_OPEN",isOpen:!0}),i.dispatch({type:"SET_STATE",state:"connecting"}),B()}}),c.appendChild(p),e==="button"&&(w=De({position:t,store:i,welcomeMessage:u.bubbleGreeting||void 0,greetingDelay:n.greetingDelay,bubbleStyle:u.bubbleStyle}),c.appendChild(w)),e==="inline"&&p){let f=n.width||"100%",x=n.height||"100%";p.style.width=f,p.style.height=x,p.style.maxHeight=x,c.style.height="100%"}N?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),h?i.dispatch({type:"SET_STATE",state:"pre_chat"}):(i.dispatch({type:"SET_STATE",state:"connecting"}),B()),e==="inline"&&i.dispatch({type:"SET_OPEN",isOpen:!0})}catch(u){console.error("NamiruChat: initialization failed",u),i.dispatch({type:"SET_ERROR",error:"Failed to load chat. Please try again later."})}}function Z(){y&&(y=!1,p&&setTimeout(()=>{let u=p?._namiruShowEscalation;typeof u=="function"&&u()},100))}function B(u){o||g||(o=new Q({url:r,agentId:n.agentId,visitorId:ce()}),o.on("connected",()=>{}),o.on("agent_initialized",h=>{i.dispatch({type:"SET_STATE",state:"chatting"}),i.dispatch({type:"SET_LOADING",isLoading:!1}),h.data.sessionId&&(i.dispatch({type:"SET_SESSION_ID",sessionId:h.data.sessionId}),n.onSessionStart?.(h.data.sessionId)),u&&o?.sendMessage(`[User selected: ${u}]`)}),o.on("stream_token",h=>{i.dispatch({type:"APPEND_STREAMING",token:h.data.token})}),o.on("final_response",h=>{i.dispatch({type:"CLEAR_STREAMING"});let T={id:ae(),role:"assistant",content:h.data.content||h.data.response||"",timestamp:Date.now()};i.dispatch({type:"ADD_MESSAGE",message:T}),i.dispatch({type:"SET_LOADING",isLoading:!1}),Z(),C&&h.data.conversationMayHaveEnded&&!i.getState().feedbackGiven?(setTimeout(()=>{let f=i.getState();!f.feedbackGiven&&f.state==="chatting"&&f.messages.length>0&&i.dispatch({type:"SET_STATE",state:"feedback"})},800),k?.stop()):k&&!i.getState().feedbackGiven&&k.reset()}),o.on("stream_end",()=>{let h=i.getState().streamingContent;if(h){i.dispatch({type:"CLEAR_STREAMING"});let T={id:ae(),role:"assistant",content:h,timestamp:Date.now()};i.dispatch({type:"ADD_MESSAGE",message:T})}i.dispatch({type:"SET_LOADING",isLoading:!1}),Z(),k&&!i.getState().feedbackGiven&&k.reset()}),o.on("tool_start",()=>{i.dispatch({type:"SET_LOADING",isLoading:!0})}),o.on("tool_end",()=>{}),o.on("kit_trigger",h=>{let T=h.data;(T==="escalation_email_form"||T?.type==="escalation_email_form")&&(y=!0)}),o.on("handoff_active",h=>{let T={id:ae(),role:"assistant",content:h.data?.message||"A human operator is currently handling this conversation. Please wait for their response.",timestamp:Date.now()};i.dispatch({type:"ADD_MESSAGE",message:T}),i.dispatch({type:"SET_LOADING",isLoading:!1})}),o.on("show_handoff_form",h=>{v=h.data?.reason||"handoff_accepted",i.dispatch({type:"SET_STATE",state:"email_fallback"}),i.dispatch({type:"SET_LOADING",isLoading:!1})}),o.on("error",h=>{if(h.data?.type==="usage_limit"||h.data?.usage_limit){i.dispatch({type:"SET_STATE",state:"conversation_limit"}),i.dispatch({type:"SET_LOADING",isLoading:!1});return}if(h.data?.message==="Domain not authorized"){i.dispatch({type:"SET_STATE",state:"domain_error"}),i.dispatch({type:"SET_LOADING",isLoading:!1});return}console.error("NamiruChat: WebSocket error",h.data),i.dispatch({type:"SET_ERROR",error:h.data?.message||"Connection error. Please try again."}),i.dispatch({type:"SET_LOADING",isLoading:!1})}),o.on("disconnected",()=>{}),o.connect())}I();let z=!1,D=!1;return i.subscribe(u=>{if(!(g||D)){if(z&&!u.isOpen&&o){D=!0,o.disconnect(),o=null,k?.stop(),setTimeout(()=>{D=!1,i.dispatch({type:"RESET"})},0),z=!1;return}!z&&u.isOpen&&!o&&u.state!=="pre_chat"&&(D=!0,i.dispatch({type:"SET_STATE",state:"connecting"}),B(),D=!1),z=u.isOpen}}),{open:()=>{g||i.dispatch({type:"SET_OPEN",isOpen:!0})},close:()=>{g||i.dispatch({type:"SET_OPEN",isOpen:!1})},toggle:()=>{if(!g){let u=i.getState().isOpen;i.dispatch({type:"SET_OPEN",isOpen:!u})}},destroy:()=>{if(g)return;g=!0,o?.disconnect(),k?.stop(),ve();let u=N?s:c;u&&u.parentNode&&u.parentNode.removeChild(u);let h=i.getState().sessionId;h&&n.onSessionEnd?.(h),i.dispatch({type:"RESET"}),s=null,d=null,c=null,p=null,w=null,o=null},updateConfig:u=>{if(!g){if(u.position&&u.position!==n.position){let h=n.position||"bottom-right",T=u.position;if(w){let f=w.querySelector(".namiru-button");f&&(f.classList.remove(`namiru-button--${h}`),f.classList.add(`namiru-button--${T}`));let x=w.querySelector(".namiru-greeting");x&&(x.classList.remove(`namiru-greeting--${h}`),x.classList.add(`namiru-greeting--${T}`))}p&&(p.classList.remove(`namiru-popup--${h}`),p.classList.add(`namiru-popup--${T}`))}Object.assign(n,u)}}}}if(typeof document<"u"&&document.currentScript){let n=document.currentScript,e=n.getAttribute("data-agent-id");if(e){let t=n.getAttribute("data-position")||"bottom-right",a=n.getAttribute("data-mode")||"button",r=n.getAttribute("data-server-url")||void 0,i=n.getAttribute("data-container-id");xt({agentId:e,position:t,mode:a,serverUrl:r,container:i&&document.getElementById(i)||void 0})}}export{xt as init};
1090
+ `,Q.textContent="Reload",Q.addEventListener("click",()=>window.location.reload()),N.appendChild(Q),c.appendChild(N),S.appendChild(c)}function he(c){h||(h=Le({onFeedback:b=>{s(b),r==="button"&&setTimeout(()=>{e.dispatch({type:"RESET"}),e.dispatch({type:"SET_OPEN",isOpen:!1})},800)},softPrompt:c}),S.appendChild(h),G())}function G(){requestAnimationFrame(()=>{S.scrollTop=S.scrollHeight})}function Ze(c){$&&c.some(b=>b.role==="user")&&($.remove(),$=null);for(let b=D;b<c.length;b++){let w=C.createBubble(c[b]);S.appendChild(w)}D=c.length,G()}function We(c){if(c){u||(f&&(f.remove(),f=null),u=C.createStreaming(),S.appendChild(u));let b=u._namiruTextEl,w=te(c);b?b.innerHTML=w:u.innerHTML=w,G()}else u&&(u.remove(),u=null)}function Ue(c){c&&!f&&!u?(f=C.createLoading(),S.appendChild(f),G()):!c&&f&&(f.remove(),f=null)}let R=null;return e.subscribe(c=>{if(console.log("[ChatWindow] subscriber:","state="+c.state,"msgs="+c.messages.length,"open="+c.isOpen,"input="+M?.style.display,"prev="+(R?.state||"null")),r==="button"&&(c.isOpen?y.classList.add("namiru-popup--open"):y.classList.remove("namiru-popup--open")),!R||R.state!==c.state)switch(c.state){case"idle":j(),M.style.display="none",q();break;case"connecting":M.style.display="none",Ve();break;case"pre_chat":Re();break;case"chatting":q(),R?.state==="pre_chat"&&j(),M.style.display="",ze();break;case"feedback":he(!0);break;case"escalation":ue();break;case"email_fallback":pe();break;case"conversation_limit":q(),M.style.display="none",ge();break;case"domain_error":q(),M.style.display="none",Ge();break;case"error":q(),M.style.display="none";break}c.messages.length>D&&c.state!=="pre_chat"&&Ze(c.messages),c.state==="chatting"&&c.messages.length>=z&&e.dispatch({type:"SET_STATE",state:"conversation_limit"}),R?.streamingContent!==c.streamingContent&&We(c.streamingContent),R?.isLoading!==c.isLoading&&Ue(c.isLoading),R=c}),y._namiruShowEscalation=ue,y._namiruShowFeedback=he,y._namiruShowTranscript=me,y._namiruShowContactForm=pe,y._namiruShowLimitOverlay=ge,y._namiruShowCloseConfirmation=()=>se(A,e),y}function Be(n){let{position:e,store:t,welcomeMessage:a,greetingDelay:r,bubbleStyle:i,onCloseRequest:l}=n,o=document.createElement("div"),s=document.createElement("button");s.className=`namiru-button namiru-button--${e}`,i==="classic"&&s.classList.add("namiru-button--classic"),s.setAttribute("aria-label","Open chat");let d=Ee(),m=ae();m.style.display="none",s.appendChild(d),s.appendChild(m),s.addEventListener("click",()=>{let x=t.getState().isOpen;x&&l?l():t.dispatch({type:"SET_OPEN",isOpen:!x})}),o.appendChild(s);let p=null,k=!1,g=null;if(a){p=document.createElement("div"),p.className=`namiru-greeting namiru-greeting--${e} namiru-greeting--hidden`;let x=document.createTextNode(a);p.appendChild(x);let C=document.createElement("button");C.className="namiru-greeting-close",C.setAttribute("aria-label","Dismiss"),C.textContent="\xD7",C.addEventListener("click",A=>{A.stopPropagation(),E()}),p.appendChild(C),p.addEventListener("click",()=>{E(),t.dispatch({type:"SET_OPEN",isOpen:!0})}),o.appendChild(p),g=setTimeout(()=>{!t.getState().isOpen&&p&&(p.classList.remove("namiru-greeting--hidden"),k=!0,setTimeout(()=>E(),3e4))},r??3e3)}function E(){k&&p&&(p.classList.add("namiru-greeting--hidden"),k=!1),g&&(clearTimeout(g),g=null)}return t.subscribe(x=>{x.isOpen?(d.style.display="none",m.style.display="",s.setAttribute("aria-label","Close chat"),E()):(d.style.display="",m.style.display="none",s.setAttribute("aria-label","Open chat"))}),o}function gt(n){try{let e=new URL(n),t=e.protocol==="https:"?"wss:":"ws:";return e.hostname==="localhost"||e.hostname==="127.0.0.1"?(e.port="3423",e.protocol=t,e.origin):e.hostname==="test.namiru.ai"?`${t}//ai-test.namiru.ai`:e.hostname==="namiru.ai"||e.hostname==="app.namiru.ai"||e.hostname==="api.namiru.ai"?`${t}//ai.namiru.ai`:(e.protocol=t,e.origin)}catch{let e=n.startsWith("https")?"wss":"ws",t=n.replace(/^https?:\/\//,"");return`${e}://${t}`}}function ht(n){try{let e=new URL(n);return e.hostname.startsWith("app.")?(e.hostname=e.hostname.replace("app.","api."),e.origin):e.hostname==="test.namiru.ai"?(e.hostname="api-test.namiru.ai",e.origin):e.hostname==="namiru.ai"?(e.hostname="api.namiru.ai",e.origin):((e.hostname==="localhost"||e.hostname==="127.0.0.1")&&(e.port="3001"),e.origin)}catch{return n}}function ft(n){let e,t=null;if(n.serverUrl)e=n.serverUrl.replace(/\/$/,"");else{let a=document.querySelectorAll("script[src]");for(let r=a.length-1;r>=0;r--){let i=a[r].src;if(i.includes("namiru-chat")||i.includes("namiru"))try{t=new URL(i).origin;break}catch{}}e=ht(t||location.origin)}return{apiBase:e,wsUrl:n.wsUrl||gt(t||e)}}var Pe="namiru_visitor_id";function de(){try{let n=localStorage.getItem(Pe);if(n)return n;let e=`v_${Date.now()}_${Math.random().toString(36).substring(2,11)}`;return localStorage.setItem(Pe,e),e}catch{return`v_${Date.now()}_${Math.random().toString(36).substring(2,11)}`}}var Fe=0;function ie(){return Fe++,`msg-${Date.now()}-${Fe}`}function bt(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 xt(n){if(!n.agentId)throw new Error("NamiruChat: agentId is required");let e=n.mode||"button",t="bottom-right",{apiBase:a,wsUrl:r}=ft(n),i=new Y,l=new J({baseUrl:a}),o=null,s=null,d=null,m=null,p=null,k=null,g=!1,E="handoff_accepted",x=!1,C=null,y=!1;s=document.createElement("div"),s.id="namiru-widget-host";let A=typeof s.attachShadow=="function";xe(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;",d=s.attachShadow({mode:"open"})),m=document.createElement("div"),m.className="namiru-widget-root";let S=d||s;A&&(m.style.pointerEvents="auto"),S.appendChild(m);async function M(){try{let u=await l.fetchBranding(n.agentId);if(g)return;if(!bt(u.allowedDomains)){console.warn(`[Namiru Widget] Domain "${window.location.hostname}" is not allowed for this agent. Allowed: ${JSON.stringify(u.allowedDomains)}`);return}ye({primaryColor:u.primaryColor,accentColor:u.accentColor,headerColor:u.headerColor,fontFamily:u.fontFamily,presetTheme:u.presetTheme,backgroundColor:u.backgroundColor,textColor:u.textColor,fontSize:u.fontSize,userMessageColor:u.userMessageColor,agentMessageColor:u.agentMessageColor},S,!A),n.suggestedQuestions&&n.suggestedQuestions.length>0&&(u.suggestedQuestions=n.suggestedQuestions),console.log("[NamiruChat] suggestedQuestions:",u.suggestedQuestions);let f=n.preChatEnabled??u.preChatConfig?.enabled??!1;f&&(u.preChatConfig?(u.preChatConfig.enabled=!0,n.preChatTemplate!==void 0&&(u.preChatConfig.template=n.preChatTemplate),n.preChatCustom&&(u.preChatConfig.custom=n.preChatCustom)):u.preChatConfig={enabled:!0,template:n.preChatTemplate??null,custom:n.preChatCustom}),y=u.feedbackConfig?.enabled??!1;let I=u.feedbackConfig?.inactivityMinutes??3;if(y&&(C=new X(I,()=>{let h=i.getState();!h.feedbackGiven&&h.state==="chatting"&&h.messages.length>0&&i.dispatch({type:"SET_STATE",state:"feedback"})})),p=De({store:i,branding:u,agentId:n.agentId,mode:e,position:t,onSendMessage:h=>{let v={id:ie(),role:"user",content:h,timestamp:Date.now()};i.dispatch({type:"ADD_MESSAGE",message:v}),i.dispatch({type:"SET_LOADING",isLoading:!0}),o&&o.sendMessage(h)},onPreChatSelect:h=>{i.dispatch({type:"SET_QUALIFICATION",qualification:h}),i.dispatch({type:"SET_STATE",state:"connecting"}),B(h)},onFeedback:h=>{let v=i.getState().sessionId;v&&l.submitFeedback(n.agentId,{sessionId:v,rating:h}).catch(H=>console.error("NamiruChat: feedback submit failed",H)),i.dispatch({type:"SET_FEEDBACK_GIVEN"}),C?.stop(),n.onFeedback?.(h)},onEscalationEmail:h=>{let v=i.getState().sessionId;v&&l.submitEscalation(n.agentId,{sessionId:v,userEmail:h}).catch(H=>console.error("NamiruChat: escalation submit failed",H)),o&&o.sendEscalationEmail(h),n.onLeadCapture?.({email:h,sessionId:v||"",source:"email_fallback",qualification:i.getState().qualification||void 0})},onTranscriptEmail:h=>{let v=i.getState().sessionId;v&&l.requestTranscript(n.agentId,v,{email:h}).catch(H=>console.error("NamiruChat: transcript request failed",H))},onContactFormSubmit:h=>{let v=de(),H=i.getState().sessionId;l.submitLead({agentId:n.agentId,name:h.name||void 0,email:h.email,message:h.message,visitorId:v,fallbackReason:E,conversationId:H||void 0}).catch($=>console.error("NamiruChat: lead submit failed",$)),o&&o.sendHandoffComplete({email:h.email,name:h.name||void 0,reason:E}),n.onLeadCapture?.({email:h.email,sessionId:H||"",source:"email_fallback",qualification:i.getState().qualification||void 0})},onLimitMessage:h=>{h.visitorEmail?l.submitContactMessage(n.agentId,{email:h.visitorEmail,message:h.message,visitorId:de()}).catch(v=>console.error("NamiruChat: contact message submit failed",v)):l.submitLimitMessage({agentId:n.agentId,message:h.message}).catch(v=>console.error("NamiruChat: limit message submit failed",v))},feedbackEnabled:y,onNewChat:()=>{o&&(o.disconnect(),o=null),C?.stop(),i.dispatch({type:"RESET"}),i.dispatch({type:"SET_OPEN",isOpen:!0}),i.dispatch({type:"SET_STATE",state:"connecting"}),B()}}),m.appendChild(p),e==="button"&&(k=Be({position:t,store:i,welcomeMessage:u.bubbleGreeting||void 0,greetingDelay:n.greetingDelay,bubbleStyle:u.bubbleStyle,onCloseRequest:()=>{let h=i.getState();if(y&&!h.feedbackGiven&&h.state==="chatting"&&h.messages.length>0){i.dispatch({type:"SET_STATE",state:"feedback"});return}if(h.messages.length===0){i.dispatch({type:"SET_OPEN",isOpen:!1});return}let v=p?._namiruShowCloseConfirmation;typeof v=="function"?v():i.dispatch({type:"SET_OPEN",isOpen:!1})}}),m.appendChild(k)),e==="inline"&&p){let h=n.width||"100%",v=n.height||"100%";p.style.width=h,p.style.height=v,p.style.maxHeight=v,m.style.height="100%"}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),f?i.dispatch({type:"SET_STATE",state:"pre_chat"}):(i.dispatch({type:"SET_STATE",state:"connecting"}),B()),e==="inline"&&i.dispatch({type:"SET_OPEN",isOpen:!0})}catch(u){console.error("NamiruChat: initialization failed",u),i.dispatch({type:"SET_ERROR",error:"Failed to load chat. Please try again later."})}}function Z(){x&&(x=!1,p&&setTimeout(()=>{let u=p?._namiruShowEscalation;typeof u=="function"&&u()},100))}function B(u){o||g||(o=new K({url:r,agentId:n.agentId,visitorId:de()}),o.on("connected",()=>{}),o.on("agent_initialized",f=>{i.dispatch({type:"SET_STATE",state:"chatting"}),i.dispatch({type:"SET_LOADING",isLoading:!1}),f.data.sessionId&&(i.dispatch({type:"SET_SESSION_ID",sessionId:f.data.sessionId}),n.onSessionStart?.(f.data.sessionId)),u&&o?.sendMessage(`[User selected: ${u}]`)}),o.on("stream_token",f=>{i.dispatch({type:"APPEND_STREAMING",token:f.data.token})}),o.on("final_response",f=>{i.dispatch({type:"CLEAR_STREAMING"});let I={id:ie(),role:"assistant",content:f.data.content||f.data.response||"",timestamp:Date.now()};i.dispatch({type:"ADD_MESSAGE",message:I}),i.dispatch({type:"SET_LOADING",isLoading:!1}),Z(),y&&f.data.conversationMayHaveEnded&&!i.getState().feedbackGiven?(setTimeout(()=>{let h=i.getState();!h.feedbackGiven&&h.state==="chatting"&&h.messages.length>0&&i.dispatch({type:"SET_STATE",state:"feedback"})},800),C?.stop()):C&&!i.getState().feedbackGiven&&C.reset()}),o.on("stream_end",()=>{let f=i.getState().streamingContent;if(f){i.dispatch({type:"CLEAR_STREAMING"});let I={id:ie(),role:"assistant",content:f,timestamp:Date.now()};i.dispatch({type:"ADD_MESSAGE",message:I})}i.dispatch({type:"SET_LOADING",isLoading:!1}),Z(),C&&!i.getState().feedbackGiven&&C.reset()}),o.on("tool_start",()=>{i.dispatch({type:"SET_LOADING",isLoading:!0})}),o.on("tool_end",()=>{}),o.on("kit_trigger",f=>{let I=f.data;(I==="escalation_email_form"||I?.type==="escalation_email_form")&&(x=!0)}),o.on("handoff_active",f=>{let I={id:ie(),role:"assistant",content:f.data?.message||"A human operator is currently handling this conversation. Please wait for their response.",timestamp:Date.now()};i.dispatch({type:"ADD_MESSAGE",message:I}),i.dispatch({type:"SET_LOADING",isLoading:!1})}),o.on("show_handoff_form",f=>{E=f.data?.reason||"handoff_accepted",i.dispatch({type:"SET_STATE",state:"email_fallback"}),i.dispatch({type:"SET_LOADING",isLoading:!1})}),o.on("error",f=>{if(f.data?.type==="usage_limit"||f.data?.usage_limit){i.dispatch({type:"SET_STATE",state:"conversation_limit"}),i.dispatch({type:"SET_LOADING",isLoading:!1});return}if(f.data?.message==="Domain not authorized"){i.dispatch({type:"SET_STATE",state:"domain_error"}),i.dispatch({type:"SET_LOADING",isLoading:!1});return}console.error("NamiruChat: WebSocket error",f.data),i.dispatch({type:"SET_ERROR",error:f.data?.message||"Connection error. Please try again."}),i.dispatch({type:"SET_LOADING",isLoading:!1})}),o.on("disconnected",()=>{}),o.connect())}M();let z=!1,D=!1;return i.subscribe(u=>{if(!(g||D)){if(z&&!u.isOpen){z=!1,D=!0,o&&(o.disconnect(),o=null),C?.stop(),D=!1;return}if(!z&&u.isOpen&&!o){z=!0,D=!0,i.dispatch({type:"SET_STATE",state:"connecting"}),B(),D=!1;return}z=u.isOpen}}),{open:()=>{g||i.dispatch({type:"SET_OPEN",isOpen:!0})},close:()=>{g||i.dispatch({type:"SET_OPEN",isOpen:!1})},toggle:()=>{if(!g){let u=i.getState().isOpen;i.dispatch({type:"SET_OPEN",isOpen:!u})}},destroy:()=>{if(g)return;g=!0,o?.disconnect(),C?.stop(),ve();let u=A?s:m;u&&u.parentNode&&u.parentNode.removeChild(u);let f=i.getState().sessionId;f&&n.onSessionEnd?.(f),i.dispatch({type:"RESET"}),s=null,d=null,m=null,p=null,k=null,o=null},updateConfig:u=>{g||Object.assign(n,u)}}}if(typeof document<"u"&&document.currentScript){let n=document.currentScript,e=n.getAttribute("data-agent-id");if(e){let t=n.getAttribute("data-mode")||"button",a=n.getAttribute("data-server-url")||void 0,r=n.getAttribute("data-container-id");xt({agentId:e,mode:t,serverUrl:a,container:r&&document.getElementById(r)||void 0})}}export{xt as init};
1091
1091
  //# sourceMappingURL=namiru-chat.esm.js.map