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