@namiruai/chat 1.0.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.
@@ -0,0 +1,1091 @@
1
+ function fe(){return{state:"idle",messages:[],isOpen:!1,isLoading:!1,streamingContent:"",qualification:null,feedbackGiven:!1,sessionId:null,error:null}}function Ue(n,e){switch(e.type){case"SET_STATE":return{...n,state:e.state,error:null};case"SET_OPEN":return{...n,isOpen:e.isOpen};case"SET_LOADING":return{...n,isLoading:e.isLoading};case"ADD_MESSAGE":return{...n,messages:[...n.messages,e.message]};case"APPEND_STREAMING":return{...n,streamingContent:n.streamingContent+e.token};case"CLEAR_STREAMING":return{...n,streamingContent:""};case"SET_QUALIFICATION":return{...n,qualification:e.qualification};case"SET_FEEDBACK_GIVEN":return{...n,feedbackGiven:!0};case"SET_SESSION_ID":return{...n,sessionId:e.sessionId};case"SET_ERROR":return{...n,error:e.error,state:e.error?"error":n.state};case"RESET":return fe();default:return n}}var Y=class{constructor(){this.subscribers=new Set;this.state=fe()}getState(){return this.state}dispatch(e){let t=this.state;this.state=Ue(t,e),this.state!==t&&this.notify()}subscribe(e){return this.subscribers.add(e),()=>{this.subscribers.delete(e)}}notify(){let e=this.state;this.subscribers.forEach(t=>{try{t(e)}catch(a){console.error("NamiruChat: error in store subscriber",a)}})}};var J=class{constructor(e){this.baseUrl=e.baseUrl.replace(/\/$/,"")}async fetchBranding(e){let t=await fetch(`${this.baseUrl}/api/public/agents/${encodeURIComponent(e)}/config`);if(!t.ok)throw new Error(`Failed to fetch agent config: ${t.status}`);let a=await t.json(),r=a.branding||{};function i(o,s){return typeof o=="string"&&/^#[0-9a-fA-F]{3,8}$/.test(o)?o:s}let l=[];if(Array.isArray(r.suggestedQuestions))l=r.suggestedQuestions;else if(typeof r.suggestedQuestions=="string")try{let o=JSON.parse(r.suggestedQuestions);Array.isArray(o)&&(l=o)}catch{}return{agentId:a.id,name:r.agentDisplayName||a.name,primaryColor:i(r.primaryColor,"#2563eb"),accentColor:i(r.accentColor,"#21DFFB"),logoUrl:r.agentAvatar||r.logoUrl||void 0,agentAvatar:r.agentAvatar||r.logoUrl||void 0,welcomeMessage:r.welcomeMessage||void 0,showPoweredBy:r.showPoweredBy??!0,showHeader:r.showHeader??!0,headerColor:i(r.headerColor,"")||void 0,headerTitle:r.headerTitle||void 0,headerSubtitle:r.headerSubtitle||void 0,presetTheme:r.presetTheme||"light",backgroundColor:i(r.backgroundColor,"")||void 0,textColor:i(r.textColor,"")||void 0,bubbleStyle:r.bubbleStyle||"modern",fontFamily:r.fontFamily||"system",fontSize:r.fontSize||"medium",userMessageColor:i(r.userMessageColor,"")||void 0,agentMessageColor:i(r.agentMessageColor,"")||void 0,bubbleGreeting:r.bubbleGreeting||void 0,suggestedQuestions:l,preChatConfig:a.preChatConfig?{enabled:a.preChatConfig.enabled,template:a.preChatConfig.template,custom:a.preChatConfig.template==="custom"&&a.preChatConfig.customQuestion?{question:a.preChatConfig.customQuestion,options:a.preChatConfig.customOptions||[]}:void 0}:void 0,feedbackConfig:a.feedbackConfig??void 0,escalationConfig:a.escalationConfig?{enabled:a.escalationConfig.emailFallbackEnabled||a.escalationConfig.liveChatEnabled||!1,emailFallbackEnabled:a.escalationConfig.emailFallbackEnabled,ownerEmail:a.escalationConfig.ownerEmail,customReplyMessage:a.escalationConfig.customReplyMessage,liveChatEnabled:a.escalationConfig.liveChatEnabled}:void 0,allowedDomains:Array.isArray(a.allowedDomains)?a.allowedDomains:void 0}}async submitFeedback(e,t){let a=await fetch(`${this.baseUrl}/api/public/agents/${encodeURIComponent(e)}/feedback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!a.ok)throw new Error(`Failed to submit feedback: ${a.status}`)}async submitEscalation(e,t){let a=await fetch(`${this.baseUrl}/api/public/agents/${encodeURIComponent(e)}/escalate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!a.ok)throw new Error(`Failed to submit escalation: ${a.status}`)}async requestTranscript(e,t,a){let r=await fetch(`${this.baseUrl}/api/public/agents/${encodeURIComponent(e)}/sessions/${encodeURIComponent(t)}/transcript`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!r.ok)throw new Error(`Failed to request transcript: ${r.status}`);return r.json()}async submitLimitMessage(e){let t=await fetch(`${this.baseUrl}/api/leads/limit-message`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw new Error(`Failed to submit limit message: ${t.status}`);return t.json()}async submitContactMessage(e,t){let a=await fetch(`${this.baseUrl}/api/public/agents/${encodeURIComponent(e)}/contact`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!a.ok)throw new Error(`Failed to submit contact message: ${a.status}`);return a.json()}async submitLead(e){let t=await fetch(`${this.baseUrl}/api/leads`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw new Error(`Failed to submit lead: ${t.status}`);return t.json()}};var Q=class{constructor(e){this.ws=null;this.listeners=new Map;this.reconnectAttempts=0;this.isDestroyed=!1;this.isInitialized=!1;this.config=e,this.maxReconnectAttempts=e.maxReconnectAttempts??3}connect(){if(!this.isDestroyed)try{this.ws=new WebSocket(this.config.url),this.ws.onopen=this.handleOpen.bind(this),this.ws.onmessage=this.handleMessage.bind(this),this.ws.onclose=this.handleClose.bind(this),this.ws.onerror=this.handleError.bind(this)}catch(e){this.emit("error",{message:e instanceof Error?e.message:"WebSocket connection failed"})}}disconnect(){this.isDestroyed=!0,this.ws&&(this.ws.onclose=null,this.ws.close(),this.ws=null)}sendMessage(e){this.send({type:"message",content:e})}sendHandoffComplete(e){this.send({type:"handoff_complete",...e})}sendEscalationEmail(e){this.send({type:"escalation_email",email:e})}on(e,t){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),()=>{this.listeners.get(e)?.delete(t)}}send(e){this.ws&&this.ws.readyState===WebSocket.OPEN&&this.ws.send(JSON.stringify(e))}emit(e,t={}){let a={type:e,data:t};this.listeners.get(e)?.forEach(r=>{try{r(a)}catch(i){console.error(`NamiruChat: error in ${e} handler`,i)}})}handleOpen(){this.reconnectAttempts=0,this.emit("connected",{}),this.isInitialized||this.send({type:"init_agent",agentId:this.config.agentId,token:this.config.token||"",visitorId:this.config.visitorId||""})}handleMessage(e){let t;try{t=JSON.parse(e.data)}catch{return}switch(t.type){case"agent_initialized":this.isInitialized=!0,this.emit("agent_initialized",t);break;case"stream_token":this.emit("stream_token",t);break;case"final_response":this.emit("final_response",t);break;case"stream_end":this.emit("stream_end",t);break;case"tool_start":this.emit("tool_start",t);break;case"tool_end":this.handleToolEnd(t);break;case"usage_limit":this.emit("usage_limit",t),this.emit("error",{...t,usage_limit:!0});break;case"show_handoff_form":this.emit("show_handoff_form",t);break;case"handoff_active":this.emit("handoff_active",t);break;case"error":this.emit("error",t);break;case"status":this.emit("status",t);break;default:break}}handleToolEnd(e){if(this.emit("tool_end",e),e.output)try{let t=typeof e.output=="string"?JSON.parse(e.output):e.output;t.kitTrigger&&this.emit("kit_trigger",t.kitTrigger)}catch{}}handleClose(e){if(e.code===1008){this.isDestroyed=!0,this.emit("disconnected",{code:e.code,reason:e.reason,permanent:!0});return}if(this.emit("disconnected",{code:e.code,reason:e.reason}),!this.isDestroyed&&this.reconnectAttempts<this.maxReconnectAttempts){this.reconnectAttempts++;let t=1e3*Math.pow(2,this.reconnectAttempts-1);setTimeout(()=>this.connect(),t)}}handleError(){this.emit("error",{message:"WebSocket connection error"})}};var K=class{constructor(e,t){this.timerId=null;this.minutes=e,this.callback=t}reset(){this.stop(),this.timerId=setTimeout(()=>{this.callback()},this.minutes*60*1e3)}stop(){this.timerId!==null&&(clearTimeout(this.timerId),this.timerId=null)}updateMinutes(e){this.minutes=e,this.timerId!==null&&this.reset()}};var V=!1;function be(n){V=n}var X=null;function xe(n,e,t){let a=typeof n=="string"?{primaryColor:n}:n,r=document.createElement("style");r.setAttribute("data-namiru","true"),r.textContent=Ye(a,t),e instanceof ShadowRoot||e.shadowRoot?e.appendChild(r):document.head.appendChild(r),X=r}function ve(){X&&(X.remove(),X=null)}function qe(n){return!n||n==="system"?'"Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif':n==="modern"?'"Inter", sans-serif':n==="classic"?'"Georgia", serif':n}function je(n){return n==="small"?"13px":n==="large"?"17px":"15px"}function re(n){let e=n.replace("#","");if(e.length===3&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),e.length<6||!/^[0-9a-fA-F]{6}/.test(e))return!1;let t=parseInt(e.substring(0,2),16),a=parseInt(e.substring(2,4),16),r=parseInt(e.substring(4,6),16);return(t*299+a*587+r*114)/1e3>150}function Ye(n,e){let t=e?" !important":"",a=n.primaryColor,r=n.accentColor||"#21DFFB",i=qe(n.fontFamily),l=je(n.fontSize),o=n.presetTheme==="dark",s=n.backgroundColor||(o?"#0f0f1a":"#ffffff"),d=n.textColor||(o?"#ffffff":"#1f2937"),c=!re(s),p=c?"rgba(255,255,255,0.15)":"rgba(0,0,0,0.1)",w=c?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.02)",g=c?"rgba(255,255,255,0.6)":"rgba(0,0,0,0.45)",v=c?"rgba(255,255,255,0.2)":"rgba(0,0,0,0.12)",y=n.headerColor||s,k=n.headerColor?re(y)?"#1f2937":"#ffffff":d,C=n.headerColor?re(y)?"rgba(0,0,0,0.5)":"rgba(255,255,255,0.7)":g,N=c?"#0f0f1a":a,S=oe(c?"#0f0f1a":a,-15);return`
2
+ /* Namiru Chat Widget Styles */
3
+ .namiru-widget-root {
4
+ --namiru-primary: ${a};
5
+ --namiru-primary-hover: ${oe(a,-15)};
6
+ --namiru-accent: ${r};
7
+ --namiru-header-bg: ${y};
8
+ --namiru-header-text: ${k};
9
+ --namiru-header-text-secondary: ${C};
10
+ --namiru-bg: ${s};
11
+ --namiru-bg-secondary: ${w};
12
+ --namiru-text: ${d};
13
+ --namiru-text-secondary: ${g};
14
+ --namiru-border: ${p};
15
+ --namiru-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
16
+ --namiru-radius: 12px;
17
+ --namiru-font: ${i};
18
+ --namiru-font-size: ${l};
19
+ --namiru-scroll-thumb: ${v};
20
+ --namiru-user-msg-bg: ${n.userMessageColor||a};
21
+ --namiru-agent-msg-bg: ${n.agentMessageColor||"transparent"};
22
+ --namiru-button-bg: ${N};
23
+ --namiru-button-bg-hover: ${S};
24
+ font-family: var(--namiru-font)${t};
25
+ font-size: var(--namiru-font-size)${t};
26
+ color: var(--namiru-text)${t};
27
+ line-height: 1.5${t};
28
+ box-sizing: border-box${t};
29
+ }
30
+
31
+ .namiru-widget-root *, .namiru-widget-root *::before, .namiru-widget-root *::after {
32
+ box-sizing: border-box${t};
33
+ margin: 0;
34
+ padding: 0;
35
+ }
36
+
37
+ /* Button bubble */
38
+ .namiru-button {
39
+ position: fixed;
40
+ width: 56px;
41
+ height: 56px;
42
+ border-radius: 50%;
43
+ background: var(--namiru-button-bg);
44
+ border: none;
45
+ cursor: pointer;
46
+ display: flex;
47
+ align-items: center;
48
+ justify-content: center;
49
+ box-shadow: var(--namiru-shadow);
50
+ transition: transform 0.2s ease, background 0.2s ease;
51
+ z-index: 2147483646;
52
+ color: #ffffff;
53
+ }
54
+
55
+ .namiru-button:hover {
56
+ transform: scale(1.08);
57
+ background: var(--namiru-button-bg-hover);
58
+ }
59
+
60
+ .namiru-button--bottom-right {
61
+ bottom: 20px;
62
+ right: 20px;
63
+ }
64
+
65
+ .namiru-button--bottom-left {
66
+ bottom: 20px;
67
+ left: 20px;
68
+ }
69
+
70
+ .namiru-button svg {
71
+ width: 24px;
72
+ height: 24px;
73
+ fill: currentColor;
74
+ }
75
+
76
+ /* Chat popup */
77
+ .namiru-popup {
78
+ position: fixed;
79
+ width: 440px;
80
+ height: 600px;
81
+ border-radius: var(--namiru-radius);
82
+ background: var(--namiru-bg);
83
+ border: 1px solid var(--namiru-border);
84
+ box-shadow: var(--namiru-shadow);
85
+ display: flex;
86
+ flex-direction: column;
87
+ overflow: hidden;
88
+ z-index: 2147483647;
89
+ opacity: 0;
90
+ transform: scale(0.95) translateY(10px);
91
+ transition: opacity 0.2s ease, transform 0.2s ease;
92
+ pointer-events: none;
93
+ }
94
+
95
+ .namiru-popup--open {
96
+ opacity: 1;
97
+ transform: scale(1) translateY(0);
98
+ pointer-events: auto;
99
+ }
100
+
101
+ .namiru-popup--bottom-right {
102
+ bottom: 88px;
103
+ right: 20px;
104
+ }
105
+
106
+ .namiru-popup--bottom-left {
107
+ bottom: 88px;
108
+ left: 20px;
109
+ }
110
+
111
+ /* Inline mode */
112
+ .namiru-inline {
113
+ width: 100%;
114
+ height: 100%;
115
+ border-radius: var(--namiru-radius);
116
+ background: var(--namiru-bg);
117
+ border: 1px solid var(--namiru-border);
118
+ display: flex;
119
+ flex-direction: column;
120
+ overflow: hidden;
121
+ }
122
+
123
+ /* Header */
124
+ .namiru-header {
125
+ display: flex;
126
+ align-items: center;
127
+ justify-content: space-between;
128
+ padding: 12px 16px;
129
+ background: var(--namiru-header-bg);
130
+ border-bottom: 1px solid var(--namiru-border);
131
+ min-height: 52px;
132
+ flex-shrink: 0;
133
+ }
134
+
135
+ .namiru-header-left {
136
+ display: flex;
137
+ align-items: center;
138
+ gap: 12px;
139
+ min-width: 0;
140
+ }
141
+
142
+ .namiru-header-avatar {
143
+ width: 36px;
144
+ height: 36px;
145
+ border-radius: 10px;
146
+ object-fit: cover;
147
+ flex-shrink: 0;
148
+ }
149
+
150
+ .namiru-header-avatar-fallback {
151
+ width: 36px;
152
+ height: 36px;
153
+ border-radius: 50%;
154
+ display: flex;
155
+ align-items: center;
156
+ justify-content: center;
157
+ flex-shrink: 0;
158
+ }
159
+
160
+ .namiru-header-info {
161
+ min-width: 0;
162
+ }
163
+
164
+ .namiru-header-name {
165
+ font-weight: 600;
166
+ font-size: 14px;
167
+ color: var(--namiru-header-text);
168
+ white-space: nowrap;
169
+ overflow: hidden;
170
+ text-overflow: ellipsis;
171
+ }
172
+
173
+ .namiru-header-subtitle {
174
+ font-size: 12px;
175
+ color: var(--namiru-header-text-secondary);
176
+ white-space: nowrap;
177
+ overflow: hidden;
178
+ text-overflow: ellipsis;
179
+ }
180
+
181
+ .namiru-header-actions {
182
+ display: flex;
183
+ align-items: center;
184
+ gap: 4px;
185
+ }
186
+
187
+ .namiru-header-btn {
188
+ background: none;
189
+ border: none;
190
+ cursor: pointer;
191
+ color: var(--namiru-header-text-secondary);
192
+ padding: 4px;
193
+ border-radius: 6px;
194
+ display: flex;
195
+ align-items: center;
196
+ justify-content: center;
197
+ transition: color 0.15s, background 0.15s;
198
+ }
199
+
200
+ .namiru-header-btn:hover {
201
+ color: var(--namiru-header-text);
202
+ background: var(--namiru-bg-secondary);
203
+ }
204
+
205
+ .namiru-header-btn svg {
206
+ width: 18px;
207
+ height: 18px;
208
+ }
209
+
210
+ /* Messages area */
211
+ .namiru-messages {
212
+ flex: 1;
213
+ min-height: 0;
214
+ overflow-y: auto;
215
+ padding: 16px calc(max(16px, (100% - 540px) / 2));
216
+ display: flex;
217
+ flex-direction: column;
218
+ gap: 16px;
219
+ background: var(--namiru-bg);
220
+ }
221
+
222
+ .namiru-messages::-webkit-scrollbar {
223
+ width: 4px;
224
+ }
225
+
226
+ .namiru-messages::-webkit-scrollbar-thumb {
227
+ background: var(--namiru-scroll-thumb);
228
+ border-radius: 2px;
229
+ }
230
+
231
+ /* Message rows */
232
+ .namiru-message-row {
233
+ display: flex;
234
+ gap: 12px;
235
+ max-width: 100%;
236
+ }
237
+
238
+ .namiru-message-row--user {
239
+ justify-content: flex-end;
240
+ }
241
+
242
+ .namiru-message-row--assistant {
243
+ justify-content: flex-start;
244
+ gap: 6px;
245
+ }
246
+
247
+ .namiru-message-icon {
248
+ width: 32px;
249
+ height: 32px;
250
+ display: flex;
251
+ align-items: flex-end;
252
+ justify-content: center;
253
+ flex-shrink: 0;
254
+ margin-top: 4px;
255
+ }
256
+
257
+ .namiru-message-icon svg {
258
+ width: 20px;
259
+ height: 20px;
260
+ margin-top: 3px;
261
+ }
262
+
263
+ .namiru-message-avatar-img {
264
+ width: 24px;
265
+ height: 24px;
266
+ border-radius: 6px;
267
+ object-fit: cover;
268
+ }
269
+
270
+ /* Message bubbles */
271
+ .namiru-message {
272
+ max-width: 75%;
273
+ font-size: var(--namiru-font-size);
274
+ line-height: 1.6;
275
+ word-wrap: break-word;
276
+ white-space: pre-wrap;
277
+ }
278
+
279
+ .namiru-message--user {
280
+ padding: 10px 16px;
281
+ background: var(--namiru-user-msg-bg);
282
+ color: #ffffff;
283
+ border-radius: 1.25rem 1.25rem 0.25rem 1.25rem;
284
+ }
285
+
286
+ .namiru-message--user.namiru-bubble--rounded {
287
+ border-radius: 1rem;
288
+ }
289
+
290
+ .namiru-message--user.namiru-bubble--square {
291
+ border-radius: 0.25rem;
292
+ }
293
+
294
+ .namiru-message--assistant {
295
+ color: var(--namiru-text)${t};
296
+ background: transparent${t};
297
+ padding: 10px 8px${t};
298
+ border-radius: 0${t};
299
+ margin-top: 0${t};
300
+ }
301
+
302
+ .namiru-message-row--welcome .namiru-message--assistant {
303
+ margin-top: 4px${t};
304
+ }
305
+
306
+ /* Input area - rounded pill style */
307
+ .namiru-input-area {
308
+ padding: 12px calc(max(10px, (100% - 540px) / 2)) 8px;
309
+ flex-shrink: 0;
310
+ background: var(--namiru-bg);
311
+ }
312
+
313
+ .namiru-input-row {
314
+ display: flex;
315
+ align-items: center;
316
+ gap: 8px;
317
+ border-radius: 9999px;
318
+ border: 1px solid var(--namiru-border);
319
+ background: var(--namiru-bg-secondary);
320
+ padding: 6px 6px 6px 16px;
321
+ }
322
+
323
+ .namiru-input {
324
+ flex: 1;
325
+ border: none${t};
326
+ background: transparent${t};
327
+ font-size: 14px${t};
328
+ font-family: var(--namiru-font)${t};
329
+ outline: none${t};
330
+ resize: none${t};
331
+ max-height: 100px;
332
+ line-height: 1.4${t};
333
+ color: var(--namiru-text)${t};
334
+ padding: 4px 0${t};
335
+ }
336
+
337
+ .namiru-input::placeholder {
338
+ color: var(--namiru-text-secondary)${t};
339
+ }
340
+
341
+ .namiru-send-btn {
342
+ width: 28px;
343
+ height: 28px;
344
+ border-radius: 50%;
345
+ background: var(--namiru-primary);
346
+ border: none;
347
+ cursor: pointer;
348
+ display: flex;
349
+ align-items: center;
350
+ justify-content: center;
351
+ color: #ffffff;
352
+ flex-shrink: 0;
353
+ transition: background 0.15s, opacity 0.15s;
354
+ }
355
+
356
+ .namiru-send-btn:hover {
357
+ background: var(--namiru-primary-hover);
358
+ }
359
+
360
+ .namiru-send-btn:disabled {
361
+ opacity: 0.4;
362
+ cursor: not-allowed;
363
+ }
364
+
365
+ .namiru-send-btn svg {
366
+ width: 14px;
367
+ height: 14px;
368
+ }
369
+
370
+ /* Suggested questions */
371
+ .namiru-suggestions {
372
+ display: flex;
373
+ flex-wrap: wrap;
374
+ gap: 8px;
375
+ justify-content: center;
376
+ padding: 4px 0;
377
+ }
378
+
379
+ .namiru-suggestion-chip {
380
+ font-size: 12px;
381
+ padding: 6px 12px;
382
+ border-radius: 9999px;
383
+ border: 1px solid var(--namiru-border);
384
+ background: var(--namiru-bg-secondary);
385
+ color: var(--namiru-text);
386
+ cursor: pointer;
387
+ max-width: 200px;
388
+ white-space: nowrap;
389
+ overflow: hidden;
390
+ text-overflow: ellipsis;
391
+ font-family: var(--namiru-font);
392
+ transition: border-color 0.15s, background 0.15s;
393
+ }
394
+
395
+ .namiru-suggestion-chip:hover {
396
+ border-color: var(--namiru-primary);
397
+ background: var(--namiru-bg);
398
+ }
399
+
400
+ /* Pre-chat form */
401
+ .namiru-prechat {
402
+ flex: 1;
403
+ display: flex;
404
+ flex-direction: column;
405
+ align-items: center;
406
+ justify-content: center;
407
+ padding: 24px 20px;
408
+ gap: 20px;
409
+ }
410
+
411
+ .namiru-prechat-question {
412
+ font-size: 16px;
413
+ font-weight: 600;
414
+ text-align: center;
415
+ color: var(--namiru-text);
416
+ }
417
+
418
+ .namiru-prechat-options {
419
+ display: flex;
420
+ flex-direction: column;
421
+ gap: 10px;
422
+ width: 100%;
423
+ max-width: 300px;
424
+ }
425
+
426
+ .namiru-prechat-option {
427
+ display: flex;
428
+ align-items: center;
429
+ gap: 10px;
430
+ padding: 12px 16px;
431
+ border: 1px solid var(--namiru-border);
432
+ border-radius: 10px;
433
+ background: var(--namiru-bg);
434
+ cursor: pointer;
435
+ font-size: 14px;
436
+ font-family: var(--namiru-font);
437
+ color: var(--namiru-text);
438
+ transition: border-color 0.15s, background 0.15s;
439
+ text-align: left;
440
+ width: 100%;
441
+ }
442
+
443
+ .namiru-prechat-option:hover {
444
+ border-color: var(--namiru-primary);
445
+ background: var(--namiru-bg-secondary);
446
+ }
447
+
448
+ .namiru-prechat-option svg {
449
+ width: 20px;
450
+ height: 20px;
451
+ flex-shrink: 0;
452
+ color: var(--namiru-primary);
453
+ }
454
+
455
+ /* Feedback prompt */
456
+ .namiru-feedback {
457
+ display: flex;
458
+ flex-direction: column;
459
+ align-items: center;
460
+ gap: 10px;
461
+ padding: 20px 20px 12px;
462
+ margin: 12px auto;
463
+ max-width: 540px;
464
+ background: none;
465
+ border: none;
466
+ border-top: 1px solid var(--namiru-border);
467
+ border-radius: 0;
468
+ box-shadow: none;
469
+ }
470
+
471
+ .namiru-feedback-label {
472
+ font-size: 11px;
473
+ font-weight: 600;
474
+ text-transform: uppercase;
475
+ letter-spacing: 0.05em;
476
+ color: var(--namiru-primary);
477
+ opacity: 0.85;
478
+ }
479
+
480
+ .namiru-feedback-text {
481
+ font-size: 13px;
482
+ color: var(--namiru-text-secondary);
483
+ text-align: center;
484
+ line-height: 1.5;
485
+ }
486
+
487
+ .namiru-feedback-buttons {
488
+ display: flex;
489
+ gap: 12px;
490
+ }
491
+
492
+ .namiru-feedback-btn {
493
+ width: 40px;
494
+ height: 40px;
495
+ border-radius: 10px;
496
+ border: 1.5px solid var(--namiru-border);
497
+ background: var(--namiru-bg);
498
+ cursor: pointer;
499
+ display: flex;
500
+ align-items: center;
501
+ justify-content: center;
502
+ transition: background 0.15s, border-color 0.15s, color 0.15s;
503
+ color: var(--namiru-text-secondary);
504
+ }
505
+
506
+ .namiru-feedback-btn-up:hover {
507
+ border-color: #22c55e;
508
+ color: #22c55e;
509
+ }
510
+
511
+ .namiru-feedback-btn-down:hover {
512
+ border-color: #ef4444;
513
+ color: #ef4444;
514
+ }
515
+
516
+ .namiru-feedback-btn svg {
517
+ width: 20px;
518
+ height: 20px;
519
+ }
520
+
521
+ .namiru-feedback-thanks {
522
+ font-size: 14px;
523
+ color: var(--namiru-primary);
524
+ font-weight: 600;
525
+ padding: 4px 0;
526
+ }
527
+
528
+
529
+ /* Email form */
530
+ .namiru-email-form {
531
+ display: flex;
532
+ flex-direction: column;
533
+ gap: 10px;
534
+ padding: 14px;
535
+ margin: 8px 0;
536
+ background: var(--namiru-bg-secondary);
537
+ border-radius: 12px;
538
+ }
539
+
540
+ .namiru-email-form-text {
541
+ font-size: 13px;
542
+ color: var(--namiru-text-secondary);
543
+ }
544
+
545
+ .namiru-email-form-row {
546
+ display: flex;
547
+ gap: 8px;
548
+ }
549
+
550
+ .namiru-email-input {
551
+ flex: 1;
552
+ border: 1px solid var(--namiru-border);
553
+ border-radius: 8px;
554
+ padding: 8px 12px;
555
+ font-size: 13px;
556
+ font-family: var(--namiru-font);
557
+ outline: none;
558
+ background: var(--namiru-bg);
559
+ color: var(--namiru-text);
560
+ }
561
+
562
+ .namiru-email-input:focus {
563
+ border-color: var(--namiru-primary);
564
+ }
565
+
566
+ .namiru-email-submit {
567
+ padding: 8px 16px;
568
+ border: none;
569
+ border-radius: 8px;
570
+ background: var(--namiru-primary);
571
+ color: #ffffff;
572
+ font-size: 13px;
573
+ font-family: var(--namiru-font);
574
+ cursor: pointer;
575
+ white-space: nowrap;
576
+ transition: background 0.15s;
577
+ }
578
+
579
+ .namiru-email-submit:hover {
580
+ background: var(--namiru-primary-hover);
581
+ }
582
+
583
+ .namiru-email-submit:disabled {
584
+ opacity: 0.5;
585
+ cursor: not-allowed;
586
+ }
587
+
588
+ .namiru-email-sent {
589
+ font-size: 13px;
590
+ color: var(--namiru-primary);
591
+ font-weight: 500;
592
+ text-align: center;
593
+ padding: 8px;
594
+ }
595
+
596
+ /* Loading dots */
597
+ .namiru-loading {
598
+ display: flex;
599
+ align-items: center;
600
+ gap: 4px;
601
+ padding: 13px 8px;
602
+ align-self: center;
603
+ }
604
+
605
+ .namiru-loading-dot {
606
+ width: 6px;
607
+ height: 6px;
608
+ border-radius: 50%;
609
+ background: var(--namiru-text-secondary);
610
+ animation: namiru-bounce 1.4s infinite ease-in-out;
611
+ }
612
+
613
+ .namiru-loading-dot:nth-child(1) { animation-delay: 0s; }
614
+ .namiru-loading-dot:nth-child(2) { animation-delay: 0.16s; }
615
+ .namiru-loading-dot:nth-child(3) { animation-delay: 0.32s; }
616
+
617
+ @keyframes namiru-bounce {
618
+ 0%, 80%, 100% { transform: scale(0); }
619
+ 40% { transform: scale(1); }
620
+ }
621
+
622
+ /* Connecting indicator */
623
+ .namiru-connecting {
624
+ display: flex;
625
+ align-items: center;
626
+ justify-content: center;
627
+ flex: 1;
628
+ min-height: 80px;
629
+ }
630
+
631
+ .namiru-loading-dots {
632
+ display: flex;
633
+ gap: 4px;
634
+ }
635
+
636
+ /* Powered by */
637
+ .namiru-powered {
638
+ text-align: center;
639
+ padding: 4px 6px 12px;
640
+ font-size: 10px;
641
+ color: var(--namiru-text-secondary);
642
+ flex-shrink: 0;
643
+ background: var(--namiru-bg);
644
+ }
645
+
646
+ .namiru-powered a {
647
+ color: var(--namiru-primary);
648
+ text-decoration: none;
649
+ font-weight: 600;
650
+ }
651
+
652
+ .namiru-powered a:hover {
653
+ text-decoration: underline;
654
+ }
655
+
656
+ /* Greeting bubble */
657
+ .namiru-greeting {
658
+ position: fixed;
659
+ background: var(--namiru-bg);
660
+ color: var(--namiru-text);
661
+ padding: 12px 36px 12px 16px;
662
+ border-radius: 12px;
663
+ box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12), 0 1px 4px rgba(0, 0, 0, 0.08);
664
+ border: 1px solid var(--namiru-border);
665
+ max-width: 240px;
666
+ font-family: var(--namiru-font);
667
+ font-size: 14px;
668
+ line-height: 1.4;
669
+ z-index: 2147483647;
670
+ cursor: pointer;
671
+ transition: opacity 0.2s ease, transform 0.2s ease;
672
+ }
673
+
674
+ .namiru-greeting--bottom-right {
675
+ bottom: 84px;
676
+ right: 20px;
677
+ }
678
+
679
+ .namiru-greeting--bottom-left {
680
+ bottom: 84px;
681
+ left: 20px;
682
+ }
683
+
684
+ .namiru-greeting--hidden {
685
+ opacity: 0;
686
+ transform: translateY(4px);
687
+ pointer-events: none;
688
+ }
689
+
690
+ .namiru-greeting-close {
691
+ position: absolute;
692
+ top: 6px;
693
+ right: 8px;
694
+ width: 20px;
695
+ height: 20px;
696
+ border: none;
697
+ background: transparent;
698
+ cursor: pointer;
699
+ color: var(--namiru-text-secondary);
700
+ font-size: 14px;
701
+ line-height: 1;
702
+ padding: 0;
703
+ display: flex;
704
+ align-items: center;
705
+ justify-content: center;
706
+ border-radius: 50%;
707
+ }
708
+
709
+ .namiru-greeting-close:hover {
710
+ color: var(--namiru-text);
711
+ background: var(--namiru-bg-secondary);
712
+ }
713
+
714
+ /* Classic bubble style */
715
+ .namiru-button--classic {
716
+ border-radius: 16px;
717
+ width: 60px;
718
+ height: 48px;
719
+ }
720
+
721
+ /* Contact form (email fallback) */
722
+ .namiru-contact-form {
723
+ display: flex;
724
+ flex-direction: column;
725
+ gap: 12px;
726
+ padding: 20px;
727
+ flex: 1;
728
+ overflow-y: auto;
729
+ }
730
+
731
+ .namiru-contact-heading {
732
+ font-size: 15px;
733
+ font-weight: 500;
734
+ color: var(--namiru-text);
735
+ line-height: 1.5;
736
+ text-align: center;
737
+ padding-bottom: 4px;
738
+ }
739
+
740
+ .namiru-contact-label {
741
+ font-size: 12px;
742
+ font-weight: 500;
743
+ color: var(--namiru-text-secondary);
744
+ }
745
+
746
+ .namiru-contact-input {
747
+ border: 1px solid var(--namiru-border);
748
+ border-radius: 8px;
749
+ padding: 10px 12px;
750
+ font-size: 14px;
751
+ font-family: var(--namiru-font);
752
+ outline: none;
753
+ background: var(--namiru-bg);
754
+ color: var(--namiru-text);
755
+ width: 100%;
756
+ }
757
+
758
+ .namiru-contact-input:focus {
759
+ border-color: var(--namiru-primary);
760
+ }
761
+
762
+ .namiru-contact-textarea {
763
+ border: 1px solid var(--namiru-border);
764
+ border-radius: 8px;
765
+ padding: 10px 12px;
766
+ font-size: 14px;
767
+ font-family: var(--namiru-font);
768
+ outline: none;
769
+ background: var(--namiru-bg);
770
+ color: var(--namiru-text);
771
+ width: 100%;
772
+ resize: vertical;
773
+ min-height: 80px;
774
+ }
775
+
776
+ .namiru-contact-textarea:focus {
777
+ border-color: var(--namiru-primary);
778
+ }
779
+
780
+ .namiru-contact-error {
781
+ font-size: 12px;
782
+ color: #ef4444;
783
+ }
784
+
785
+ .namiru-contact-submit {
786
+ padding: 10px 20px;
787
+ border: none;
788
+ border-radius: 8px;
789
+ background: var(--namiru-primary);
790
+ color: #ffffff;
791
+ font-size: 14px;
792
+ font-weight: 500;
793
+ font-family: var(--namiru-font);
794
+ cursor: pointer;
795
+ transition: background 0.15s;
796
+ width: 100%;
797
+ }
798
+
799
+ .namiru-contact-submit:hover {
800
+ background: var(--namiru-primary-hover);
801
+ }
802
+
803
+ .namiru-contact-submit:disabled {
804
+ opacity: 0.5;
805
+ cursor: not-allowed;
806
+ }
807
+
808
+ .namiru-contact-confirmation {
809
+ display: flex;
810
+ align-items: center;
811
+ justify-content: center;
812
+ flex: 1;
813
+ font-size: 15px;
814
+ font-weight: 500;
815
+ color: var(--namiru-primary);
816
+ text-align: center;
817
+ padding: 20px;
818
+ }
819
+
820
+ /* Limit overlay */
821
+ .namiru-limit-overlay {
822
+ position: absolute;
823
+ top: 0;
824
+ left: 0;
825
+ right: 0;
826
+ bottom: 0;
827
+ display: flex;
828
+ flex-direction: column;
829
+ align-items: center;
830
+ justify-content: center;
831
+ padding: 24px 20px;
832
+ gap: 12px;
833
+ background: var(--namiru-bg);
834
+ z-index: 10;
835
+ }
836
+
837
+ .namiru-limit-icon {
838
+ color: var(--namiru-text-secondary);
839
+ display: flex;
840
+ align-items: center;
841
+ justify-content: center;
842
+ }
843
+
844
+ .namiru-limit-icon--success {
845
+ color: var(--namiru-primary);
846
+ }
847
+
848
+ .namiru-limit-heading {
849
+ font-size: 16px;
850
+ font-weight: 600;
851
+ color: var(--namiru-text);
852
+ text-align: center;
853
+ }
854
+
855
+ .namiru-limit-subtext {
856
+ font-size: 13px;
857
+ color: var(--namiru-text-secondary);
858
+ text-align: center;
859
+ line-height: 1.5;
860
+ max-width: 280px;
861
+ }
862
+
863
+ .namiru-limit-form {
864
+ display: flex;
865
+ flex-direction: column;
866
+ gap: 10px;
867
+ width: 100%;
868
+ max-width: 300px;
869
+ margin-top: 4px;
870
+ }
871
+
872
+ .namiru-limit-textarea {
873
+ border: 1px solid var(--namiru-border);
874
+ border-radius: 8px;
875
+ padding: 10px 12px;
876
+ font-size: 14px;
877
+ font-family: var(--namiru-font);
878
+ outline: none;
879
+ background: var(--namiru-bg-secondary);
880
+ color: var(--namiru-text);
881
+ width: 100%;
882
+ resize: vertical;
883
+ min-height: 80px;
884
+ }
885
+
886
+ .namiru-limit-textarea::placeholder {
887
+ color: var(--namiru-text-secondary);
888
+ }
889
+
890
+ .namiru-limit-textarea:focus {
891
+ border-color: var(--namiru-primary);
892
+ }
893
+
894
+ .namiru-limit-email {
895
+ border: 1px solid var(--namiru-border);
896
+ border-radius: 8px;
897
+ padding: 10px 12px;
898
+ font-size: 14px;
899
+ font-family: var(--namiru-font);
900
+ outline: none;
901
+ background: var(--namiru-bg-secondary);
902
+ color: var(--namiru-text);
903
+ width: 100%;
904
+ }
905
+
906
+ .namiru-limit-email::placeholder {
907
+ color: var(--namiru-text-secondary);
908
+ }
909
+
910
+ .namiru-limit-email:focus {
911
+ border-color: var(--namiru-primary);
912
+ }
913
+
914
+ .namiru-limit-submit {
915
+ padding: 10px 20px;
916
+ border: none;
917
+ border-radius: 8px;
918
+ background: var(--namiru-primary);
919
+ color: #ffffff;
920
+ font-size: 14px;
921
+ font-weight: 500;
922
+ font-family: var(--namiru-font);
923
+ cursor: pointer;
924
+ transition: background 0.15s;
925
+ width: 100%;
926
+ }
927
+
928
+ .namiru-limit-submit:hover {
929
+ background: var(--namiru-primary-hover);
930
+ }
931
+
932
+ .namiru-limit-submit:disabled {
933
+ opacity: 0.5;
934
+ cursor: not-allowed;
935
+ }
936
+
937
+ .namiru-limit-confirmation {
938
+ font-size: 15px;
939
+ font-weight: 500;
940
+ color: var(--namiru-primary);
941
+ text-align: center;
942
+ padding: 8px;
943
+ line-height: 1.5;
944
+ }
945
+
946
+ .namiru-limit-newchat {
947
+ padding: 10px 20px;
948
+ border: 1px solid var(--namiru-border);
949
+ border-radius: 8px;
950
+ background: transparent;
951
+ color: var(--namiru-text);
952
+ font-size: 14px;
953
+ font-weight: 500;
954
+ font-family: var(--namiru-font);
955
+ cursor: pointer;
956
+ transition: background 0.15s;
957
+ width: 100%;
958
+ max-width: 300px;
959
+ margin-top: 4px;
960
+ }
961
+
962
+ .namiru-limit-newchat:hover {
963
+ background: var(--namiru-bg-secondary);
964
+ }
965
+
966
+ /* Mobile responsive */
967
+ @media (max-width: 480px) {
968
+ .namiru-popup {
969
+ width: 100vw;
970
+ height: 100vh;
971
+ bottom: 0${t};
972
+ right: 0${t};
973
+ left: 0${t};
974
+ border-radius: 0;
975
+ }
976
+ .namiru-button {
977
+ width: 48px;
978
+ height: 48px;
979
+ }
980
+ .namiru-greeting {
981
+ max-width: calc(100vw - 80px);
982
+ }
983
+ .namiru-greeting--bottom-right,
984
+ .namiru-greeting--bottom-left {
985
+ bottom: 76px;
986
+ }
987
+ }
988
+
989
+ /* ---- Markdown styles for bot messages ---- */
990
+ .namiru-md,
991
+ .namiru-md *,
992
+ .namiru-md p,
993
+ .namiru-md span,
994
+ .namiru-md li {
995
+ color: var(--namiru-text)${t};
996
+ }
997
+
998
+ .namiru-md p {
999
+ margin: 0 0 0.5em 0${t};
1000
+ display: block${t};
1001
+ visibility: visible${t};
1002
+ }
1003
+ .namiru-md p:last-child {
1004
+ margin-bottom: 0;
1005
+ }
1006
+ .namiru-md strong {
1007
+ font-weight: 700${t};
1008
+ display: inline${t};
1009
+ visibility: visible${t};
1010
+ font-size: inherit${t};
1011
+ opacity: 1${t};
1012
+ }
1013
+ .namiru-md em {
1014
+ font-style: italic${t};
1015
+ display: inline${t};
1016
+ visibility: visible${t};
1017
+ font-size: inherit${t};
1018
+ opacity: 1${t};
1019
+ }
1020
+ .namiru-md a.namiru-md-link {
1021
+ color: var(--namiru-primary)${t};
1022
+ text-decoration: underline${t};
1023
+ display: inline${t};
1024
+ visibility: visible${t};
1025
+ }
1026
+ .namiru-md a.namiru-md-link:hover {
1027
+ opacity: 0.8;
1028
+ }
1029
+ .namiru-md .namiru-md-code {
1030
+ font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
1031
+ font-size: 0.9em;
1032
+ background: rgba(0, 0, 0, 0.06);
1033
+ padding: 0.15em 0.4em;
1034
+ border-radius: 0.25rem;
1035
+ }
1036
+ .namiru-md .namiru-md-pre {
1037
+ background: #1e1e2e;
1038
+ color: #cdd6f4;
1039
+ padding: 0.75rem 1rem;
1040
+ border-radius: 0.5rem;
1041
+ overflow-x: auto;
1042
+ margin: 0.5em 0;
1043
+ font-size: 0.85em;
1044
+ }
1045
+ .namiru-md .namiru-md-pre code {
1046
+ background: transparent;
1047
+ padding: 0;
1048
+ font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
1049
+ }
1050
+ .namiru-md .namiru-md-ul,
1051
+ .namiru-md .namiru-md-ol {
1052
+ margin: 0.4em 0;
1053
+ padding-left: 1.5em;
1054
+ }
1055
+ .namiru-md .namiru-md-ul {
1056
+ list-style: disc;
1057
+ }
1058
+ .namiru-md .namiru-md-ol {
1059
+ list-style: decimal;
1060
+ }
1061
+ .namiru-md li {
1062
+ margin: 0.2em 0;
1063
+ display: list-item${t};
1064
+ visibility: visible${t};
1065
+ }
1066
+ .namiru-md .namiru-md-hr {
1067
+ border: none;
1068
+ border-top: 1px solid rgba(0,0,0,0.1);
1069
+ margin: 0.6em 0;
1070
+ }
1071
+ `}function oe(n,e){let t=n.replace("#",""),a=parseInt(t,16);if(isNaN(a)||t.length<6)return n;let r=Math.max(0,Math.min(255,(a>>16&255)+e)),i=Math.max(0,Math.min(255,(a>>8&255)+e)),l=Math.max(0,Math.min(255,(a&255)+e));return`#${(r<<16|i<<8|l).toString(16).padStart(6,"0")}`}function Je(n){return n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function ee(n){let e=Je(n);e=e.replace(/\u2014/g,", "),e=e.replace(/```(?:\w*)\n([\s\S]*?)```/g,'<pre class="namiru-md-pre"><code>$1</code></pre>'),e=e.replace(/`([^`\n]+)`/g,'<code class="namiru-md-code">$1</code>'),e=e.replace(/\*\*\*(.+?)\*\*\*/g,"<strong><em>$1</em></strong>"),e=e.replace(/\*\*(.+?)\*\*/g,"<strong>$1</strong>"),e=e.replace(/__(.+?)__/g,"<strong>$1</strong>"),e=e.replace(/\*(.+?)\*/g,"<em>$1</em>"),e=e.replace(/(^|[\s(])_(.+?)_([\s).,!?]|$)/gm,"$1<em>$2</em>$3"),e=e.replace(/\[([^\]]+)\]\(([^)]+)\)/g,'<a href="$2" target="_blank" rel="noopener noreferrer" class="namiru-md-link">$1</a>'),e=e.replace(/^[ \t]*([-*_])\s*\1\s*\1[\s\-*_]*$/gm,'<hr class="namiru-md-hr">');let t=e.split(`
1072
+ `),a=[],r=!1,i=!1;for(let d=0;d<t.length;d++){let c=t[d];if(c.includes('<hr class="namiru-md-hr">')){r&&(a.push("</ul>"),r=!1),i&&(a.push("</ol>"),i=!1),a.push(c);continue}let p=c.match(/^(\s*)[-*]\s+(.*)/),w=c.match(/^(\s*)\d+\.\s+(.*)/);p?(r||(i&&(a.push("</ol>"),i=!1),a.push('<ul class="namiru-md-ul">'),r=!0),a.push(`<li>${p[2]}</li>`)):w?(i||(r&&(a.push("</ul>"),r=!1),a.push('<ol class="namiru-md-ol">'),i=!0),a.push(`<li>${w[2]}</li>`)):(r&&(a.push("</ul>"),r=!1),i&&(a.push("</ol>"),i=!1),c.trim()===""?a.push(""):a.push(c))}r&&a.push("</ul>"),i&&a.push("</ol>");let l="",o=!1;for(let d of a)d.includes("<hr")?l+=d:d.startsWith("<ul")||d.startsWith("<ol")?(o=!0,l+=d):d==="</ul>"||d==="</ol>"?(o=!1,l+=d):d.startsWith("<li>")?l+=d:d.trim()===""?o||(l+="</p><p>"):(l.length>0&&!o&&!l.endsWith("<p>")&&!l.endsWith("</ul>")&&!l.endsWith("</ol>")&&!l.endsWith("</pre>")&&(l+="<br>"),l+=d);!l.startsWith("<ul")&&!l.startsWith("<ol")&&!l.startsWith("<pre")&&(l=`<p>${l}</p>`),l=l.replace(/<p>\s*<\/p>/g,""),l=l.replace(/<p>(<(?:ul|ol|pre|hr)[^>]*>)/g,"$1"),l=l.replace(/(<\/(?:ul|ol|pre)>)<\/p>/g,"$1"),l=l.replace(/(<hr[^>]*>)<\/p>/g,"$1");let s=V?"":" !important";return l=l.replace(/<p>/g,`<p style="color: var(--namiru-text)${s}; margin: 0 0 0.5em 0${s}; max-width: 100%${s}; word-wrap: break-word${s}; display: block${s}; visibility: visible${s};">`),l=l.replace(/<li>/g,`<li style="color: var(--namiru-text)${s}; margin: 0.2em 0${s}; display: list-item${s}; visibility: visible${s};">`),l=l.replace(/<strong>/g,`<strong style="color: var(--namiru-text)${s}; font-weight: 700${s}; display: inline${s}; visibility: visible${s}; font-size: inherit${s}; opacity: 1${s};">`),l=l.replace(/<em>/g,`<em style="color: var(--namiru-text)${s}; font-style: italic${s}; display: inline${s}; visibility: visible${s}; font-size: inherit${s}; opacity: 1${s};">`),l=l.replace(/<a href=/g,`<a style="color: var(--namiru-primary)${s}; text-decoration: underline${s}; display: inline${s}; visibility: visible${s};" href=`),l}function _(n,e="0 0 256 256"){let t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("viewBox",e),t.setAttribute("fill","currentColor"),t.setAttribute("xmlns","http://www.w3.org/2000/svg");for(let a of n){let r=document.createElementNS("http://www.w3.org/2000/svg","path");r.setAttribute("d",a),t.appendChild(r)}return t}function ye(n){let e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 256 256"),e.setAttribute("xmlns","http://www.w3.org/2000/svg"),e.setAttribute("width","18"),e.setAttribute("height","18"),n?e.setAttribute("fill",n):e.setAttribute("fill","currentColor");let t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("d","M201.89,54.66A103.43,103.43,0,0,0,128.79,24H128A104,104,0,0,0,24,128v56a24,24,0,0,0,24,24H64a24,24,0,0,0,24-24V144a24,24,0,0,0-24-24H40.36A88,88,0,0,1,128,40h.67a87.71,87.71,0,0,1,87,80H192a24,24,0,0,0-24,24v40a24,24,0,0,0,24,24h8a8,8,0,0,0,0-16h-8a8,8,0,0,1-8-8V144a8,8,0,0,1,8-8h24a8,8,0,0,1,8,8v56a40,40,0,0,1-40,40H152a8,8,0,0,0,0,16h32a56.06,56.06,0,0,0,56-56V128A103.41,103.41,0,0,0,201.89,54.66ZM64,136a8,8,0,0,1,8,8v40a8,8,0,0,1-8,8H48a8,8,0,0,1-8-8V136Z"),e.appendChild(t),e}function te(n){let e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 256 256"),e.setAttribute("xmlns","http://www.w3.org/2000/svg"),e.setAttribute("width","20"),e.setAttribute("height","20"),n?e.setAttribute("fill",n):e.setAttribute("fill","currentColor");let t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("d","M201.89,54.66A103.43,103.43,0,0,0,128.79,24H128A104,104,0,0,0,24,128v56a24,24,0,0,0,24,24H64a24,24,0,0,0,24-24V144a24,24,0,0,0-24-24H40.36A88,88,0,0,1,128,40h.67a87.71,87.71,0,0,1,87,80H192a24,24,0,0,0-24,24v40a24,24,0,0,0,24,24h8a8,8,0,0,0,0-16h-8a8,8,0,0,1-8-8V144a8,8,0,0,1,8-8h24a8,8,0,0,1,8,8v56a40,40,0,0,1-40,40H152a8,8,0,0,0,0,16h32a56.06,56.06,0,0,0,56-56V128A103.41,103.41,0,0,0,201.89,54.66ZM64,136a8,8,0,0,1,8,8v40a8,8,0,0,1-8,8H48a8,8,0,0,1-8-8V136Z"),e.appendChild(t),e}function Ce(){return _(["M128,24A104,104,0,0,0,36.18,176.88L24.83,210.93a16,16,0,0,0,20.24,20.24l34.05-11.35A104,104,0,1,0,128,24Zm0,192a88.11,88.11,0,0,1-44.06-11.81,8,8,0,0,0-4-1.08,7.85,7.85,0,0,0-2.53.42L40,216l12.47-37.41a8,8,0,0,0-.66-6.54A88,88,0,1,1,128,216Z"])}function ne(){return _(["M205.66,194.34a8,8,0,0,1-11.32,11.32L128,139.31,61.66,205.66a8,8,0,0,1-11.32-11.32L116.69,128,50.34,61.66A8,8,0,0,1,61.66,50.34L128,116.69l66.34-66.35a8,8,0,0,1,11.32,11.32L139.31,128Z"])}function Ee(){return _(["M231.87,114l-168-95.37A16,16,0,0,0,40.92,37.34L72.26,128,40.92,218.66a16,16,0,0,0,22.95,18.71l168-95.37A16,16,0,0,0,231.87,114ZM56,212.67l28.11-81.24A8,8,0,0,0,84.36,128H56L83.9,43.33,224,128Z"])}function we(){return _(["M234,80.12A24,24,0,0,0,216,72H160V56a40,40,0,0,0-40-40,8,8,0,0,0-7.16,4.42L75.06,96H32a16,16,0,0,0-16,16v88a16,16,0,0,0,16,16H204a24,24,0,0,0,23.82-21.12l12-96A24,24,0,0,0,234,80.12ZM32,112H72v88H32ZM223.94,97l-12,96a8,8,0,0,1-7.94,7H88V105.89l36.71-73.43A24,24,0,0,1,144,56V80a8,8,0,0,0,8,8h64a8,8,0,0,1,7.94,9Z"])}function Se(){return _(["M239.82,157l-12-96A24,24,0,0,0,204,40H32A16,16,0,0,0,16,56v88a16,16,0,0,0,16,16H75.06l37.78,75.58A8,8,0,0,0,120,240a40,40,0,0,0,40-40V184h56a24,24,0,0,0,23.82-27ZM72,144H32V56H72Zm150,21.29a8,8,0,0,1-6,2.71H152a8,8,0,0,0-8,8v24a24,24,0,0,1-19.29,23.54L88,150.11V56H204a8,8,0,0,1,7.94,7l12,96A8,8,0,0,1,222,165.29Z"])}function Qe(){return _(["M216,64H176a48,48,0,0,0-96,0H40A16,16,0,0,0,24,80V200a16,16,0,0,0,16,16H216a16,16,0,0,0,16-16V80A16,16,0,0,0,216,64ZM128,32a32,32,0,0,1,32,32H96A32,32,0,0,1,128,32Zm88,168H40V80H80V96a8,8,0,0,0,16,0V80h64V96a8,8,0,0,0,16,0V80h40Z"])}function Ke(){return _(["M223.68,66.15,135.68,18a15.88,15.88,0,0,0-15.36,0l-88,48.17a16,16,0,0,0-8.32,14v95.64a16,16,0,0,0,8.32,14l88,48.17a15.88,15.88,0,0,0,15.36,0l88-48.17a16,16,0,0,0,8.32-14V80.18A16,16,0,0,0,223.68,66.15ZM128,32l80.34,44-29.77,16.3-80.35-44ZM128,120,47.66,76l33.9-18.56,80.34,44ZM40,90l80,43.78v85.79L40,175.82Zm96,129.57V133.82L216,90v85.78Z"])}function Xe(){return _(["M224,48H32A16,16,0,0,0,16,64V192a16,16,0,0,0,16,16H224a16,16,0,0,0,16-16V64A16,16,0,0,0,224,48Zm0,16V88H32V64ZM32,192V104H224v88Zm16-24a8,8,0,0,1,8-8H96a8,8,0,0,1,0,16H56A8,8,0,0,1,48,168Zm0-32a8,8,0,0,1,8-8h64a8,8,0,0,1,0,16H56A8,8,0,0,1,48,136Z"])}function ke(){return _(["M128,24A104,104,0,0,0,36.18,176.88L24.83,210.93a16,16,0,0,0,20.24,20.24l34.05-11.35A104,104,0,1,0,128,24Zm0,192a88.11,88.11,0,0,1-44.06-11.81,8,8,0,0,0-4-1.08,7.85,7.85,0,0,0-2.53.42L40,216l12.47-37.41a8,8,0,0,0-.66-6.54A88,88,0,1,1,128,216Z"])}function et(){return _(["M152,224a8,8,0,0,1-8,8H112a8,8,0,0,1,0-16h32A8,8,0,0,1,152,224Zm73.69-142.23-21.34-21.35C183.42,39.49,156.58,24,128,24s-55.42,15.49-76.35,36.42L30.31,81.77a16,16,0,0,0,0,22.63L64,138.09V184a16,16,0,0,0,4.69,11.31l24,24A16,16,0,0,0,104,224h48a16,16,0,0,0,11.31-4.69l24-24A16,16,0,0,0,192,184V138.09l33.69-33.69A16,16,0,0,0,225.69,81.77ZM128,40c22.59,0,43.85,12.28,60,32H68C84.15,52.28,105.41,40,128,40Zm48,144-24,24H104L80,184V88H176Zm36.28-79.6L192,172.69V88h17.94l4.34,4.34A.64.64,0,0,1,212.28,104.4ZM64,172.69,45.66,104.4a.64.64,0,0,1-2,0L48,100H64Z"])}function tt(){return _(["M226.76,69a8,8,0,0,0-12.84-2.88l-40.3,37.19-17.23-3.7-3.7-17.23,37.19-40.3A8,8,0,0,0,187,29.24,72,72,0,0,0,88,96c0,1.3,0,2.6.1,3.89L33.19,147.68a27.7,27.7,0,0,0,0,39.37l36.76,36.76a27.7,27.7,0,0,0,39.37,0l47.79-54.91c1.29.06,2.59.1,3.89.1a72,72,0,0,0,66.76-99ZM148.49,212.49a11.7,11.7,0,0,1-16.57,0L95.16,175.73a8,8,0,0,0-11.58.28L44.49,220.49a11.7,11.7,0,0,1-16.57,0L44.49,204a11.69,11.69,0,0,1,0-16.57l44.48-39.09a8,8,0,0,0,.28-11.58L52.49,100.05a56,56,0,0,1,89.36-63.58l-31.41,34a8,8,0,0,0-1.8,6.49l6,27.92a8,8,0,0,0,6.13,6.13l27.92,6a8,8,0,0,0,6.49-1.8l34-31.41A56,56,0,0,1,148.49,212.49Z"])}function nt(){return _(["M216,56H176V48a24,24,0,0,0-24-24H104A24,24,0,0,0,80,48v8H40A16,16,0,0,0,24,72V200a16,16,0,0,0,16,16H216a16,16,0,0,0,16-16V72A16,16,0,0,0,216,56ZM96,48a8,8,0,0,1,8-8h48a8,8,0,0,1,8,8v8H96ZM216,72v72H40V72Zm0,128H40V160H216v40Z"])}function at(){return _(["M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24ZM74.08,197.5a64,64,0,0,1,107.84,0,87.83,87.83,0,0,1-107.84,0ZM96,120a32,32,0,1,1,32,32A32,32,0,0,1,96,120Zm97.76,66.41a79.66,79.66,0,0,0-36.06-28.75,48,48,0,1,0-59.4,0,79.66,79.66,0,0,0-36.06,28.75,88,88,0,1,1,131.52,0Z"])}function it(){return _(["M140,128a12,12,0,1,1-12-12A12,12,0,0,1,140,128Zm56-12a12,12,0,1,0,12,12A12,12,0,0,0,196,116ZM60,116a12,12,0,1,0,12,12A12,12,0,0,0,60,116Z"])}var rt={ShoppingBag:Qe,Package:Ke,CreditCard:Xe,ChatCircle:ke,Rocket:et,Wrench:tt,Briefcase:nt,UserCircle:at,DotsThree:it};function Te(n){let e=rt[n];return e?e():ke()}function ot(n){let e=n.replace("#","");if(e.length===3&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),e.length<6||!/^[0-9a-fA-F]{6}/.test(e))return"74, 127, 255";let t=parseInt(e.substring(0,2),16),a=parseInt(e.substring(2,4),16),r=parseInt(e.substring(4,6),16);return`${t}, ${a}, ${r}`}function Ae(n){let{store:e,branding:t,mode:a,onTranscriptClick:r,onNewChat:i,feedbackEnabled:l}=n;if(t.showHeader===!1){let g=document.createElement("div");return g.style.display="none",g}let o=document.createElement("div");o.className="namiru-header";let s=document.createElement("div");s.className="namiru-header-left";let d=ot(t.primaryColor);if(t.agentAvatar||t.logoUrl){let g=document.createElement("img");g.className="namiru-header-avatar",g.src=t.agentAvatar||t.logoUrl,g.alt=t.name,s.appendChild(g)}else{let g=document.createElement("div");g.className="namiru-header-avatar-fallback",g.style.background=`rgba(${d}, 0.06)`,g.style.border="none";let v=t.presetTheme==="dark",y=ye(v?"#ffffff":t.primaryColor);g.appendChild(y),s.appendChild(g)}let c=document.createElement("div");c.className="namiru-header-info";let p=document.createElement("div");if(p.className="namiru-header-name",p.textContent=t.headerTitle||t.name,c.appendChild(p),t.headerSubtitle){let g=document.createElement("div");g.className="namiru-header-subtitle",g.textContent=t.headerSubtitle,c.appendChild(g)}s.appendChild(c),o.appendChild(s);let w=document.createElement("div");if(w.className="namiru-header-actions",a==="button"){let g=document.createElement("button");g.className="namiru-header-btn",g.setAttribute("aria-label","Close chat"),g.appendChild(ne()),g.addEventListener("click",()=>{let v=e.getState();if(l&&!v.feedbackGiven&&v.state==="chatting"&&v.messages.length>0){e.dispatch({type:"SET_STATE",state:"feedback"});return}if(v.messages.length===0){e.dispatch({type:"SET_OPEN",isOpen:!1});return}st(o,e)}),w.appendChild(g)}return o.appendChild(w),o}function st(n,e){let t=n.parentElement;if(!t){e.dispatch({type:"SET_OPEN",isOpen:!1});return}if(t.querySelector(".namiru-close-confirm-overlay"))return;let a=document.createElement("div");a.className="namiru-close-confirm-overlay",a.style.cssText="position:absolute;inset:0;z-index:50;display:flex;align-items:center;justify-content:center;padding:16px;background:rgba(0,0,0,0.35);backdrop-filter:blur(2px);animation:namiruConfirmFade 0.15s ease-out;";let r=document.createElement("div");r.style.cssText="background:var(--namiru-bg,#fff);border-radius:8px;border:1px solid var(--namiru-border,#e5e7eb);box-shadow:0 8px 24px rgba(0,0,0,0.12);padding:20px;width:100%;max-width:280px;animation:namiruConfirmSlide 0.2s cubic-bezier(0.16,1,0.3,1);";let i=document.createElement("div");i.style.cssText="font-size:14px;font-weight:600;color:var(--namiru-text,#1f2937);margin-bottom:4px;",i.textContent="End conversation?",r.appendChild(i);let l=document.createElement("div");l.style.cssText="font-size:13px;color:var(--namiru-text-secondary,#6b7280);line-height:1.4;margin-bottom:16px;",l.textContent="Your chat history will not be saved.",r.appendChild(l);let o=document.createElement("div");o.style.cssText="display:flex;gap:8px;";let s=document.createElement("button");s.style.cssText="flex:1;padding:8px 12px;border-radius:6px;font-size:13px;font-weight:500;cursor:pointer;border:1px solid var(--namiru-border,#e5e7eb);background:var(--namiru-bg,#fff);color:var(--namiru-text,#1f2937);transition:background 0.15s;",s.textContent="Cancel",s.addEventListener("mouseenter",()=>{s.style.background="var(--namiru-bg-secondary,#f3f4f6)"}),s.addEventListener("mouseleave",()=>{s.style.background="var(--namiru-bg,#fff)"}),s.addEventListener("click",()=>a.remove());let d=document.createElement("button");if(d.style.cssText="flex:1;padding:8px 12px;border-radius:6px;font-size:13px;font-weight:500;cursor:pointer;border:none;background:var(--namiru-text,#1f2937);color:var(--namiru-bg,#fff);transition:opacity 0.15s;",d.textContent="End chat",d.addEventListener("mouseenter",()=>{d.style.opacity="0.85"}),d.addEventListener("mouseleave",()=>{d.style.opacity="1"}),d.addEventListener("click",()=>{a.remove(),e.dispatch({type:"SET_OPEN",isOpen:!1})}),o.appendChild(s),o.appendChild(d),r.appendChild(o),a.appendChild(r),a.addEventListener("click",c=>{c.target===a&&a.remove()}),!t.querySelector("style[data-namiru-confirm]")){let c=document.createElement("style");c.setAttribute("data-namiru-confirm",""),c.textContent=`
1073
+ @keyframes namiruConfirmFade { from { opacity: 0; } to { opacity: 1; } }
1074
+ @keyframes namiruConfirmSlide { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
1075
+ `,t.appendChild(c)}t.style.position="relative",t.appendChild(a)}function Me(n){let{onSend:e}=n,t=document.createElement("div");t.className="namiru-input-area";let a=document.createElement("div");a.className="namiru-input-row";let r=document.createElement("textarea");r.className="namiru-input",r.placeholder="Type your message...",r.rows=1,r.setAttribute("aria-label","Chat message"),V?r.style.color="var(--namiru-text)":r.style.setProperty("color","var(--namiru-text)","important");let i=document.createElement("button");i.className="namiru-send-btn",i.setAttribute("aria-label","Send message"),i.disabled=!0,i.appendChild(Ee());function l(){let o=r.value.trim();o&&(e(o),r.value="",r.style.height="auto",i.disabled=!0)}return r.addEventListener("input",()=>{i.disabled=!r.value.trim(),r.style.height="auto",r.style.height=Math.min(r.scrollHeight,100)+"px"}),r.addEventListener("keydown",o=>{o.key==="Enter"&&!o.shiftKey&&(o.preventDefault(),l())}),i.addEventListener("click",l),a.appendChild(r),a.appendChild(i),t.appendChild(a),t}function se(n){if(n.agentAvatar){let a=document.createElement("img");return a.src=n.agentAvatar,a.alt="Agent",a.className="namiru-message-avatar-img",a}let e=document.createElement("span"),t=n.presetTheme==="dark";return e.appendChild(te(t?"#ffffff":n.textColor)),e}function Ne(n){return{createBubble(e){return e.role==="user"?lt(e,n):ct(e,n)},createStreaming(){return dt(n)},createLoading(){return mt(n)}}}function lt(n,e){let t=document.createElement("div");t.className="namiru-message-row namiru-message-row--user";let a=document.createElement("div"),r="namiru-message namiru-message--user";return e.bubbleStyle==="rounded"?r+=" namiru-bubble--rounded":e.bubbleStyle==="square"&&(r+=" namiru-bubble--square"),a.className=r,a.textContent=n.content,t.appendChild(a),t}function ct(n,e){let t=document.createElement("div");t.className="namiru-message-row namiru-message-row--assistant";let a=document.createElement("div");a.className="namiru-message-icon",a.appendChild(se(e)),t.appendChild(a);let r=document.createElement("div");return r.className="namiru-message namiru-message--assistant namiru-md",r.innerHTML=ee(n.content),t.appendChild(r),t}function dt(n){let e=document.createElement("div");e.className="namiru-message-row namiru-message-row--assistant";let t=document.createElement("div");t.className="namiru-message-icon",t.appendChild(se(n)),e.appendChild(t);let a=document.createElement("div");return a.className="namiru-message namiru-message--assistant namiru-md",a.textContent="",e.appendChild(a),e._namiruTextEl=a,e}function mt(n){let e=document.createElement("div");e.className="namiru-message-row namiru-message-row--assistant";let t=document.createElement("div");t.className="namiru-message-icon",t.appendChild(se(n)),e.appendChild(t);let a=document.createElement("div");a.className="namiru-loading";for(let r=0;r<3;r++){let i=document.createElement("div");i.className="namiru-loading-dot",a.appendChild(i)}return e.appendChild(a),e}function Le(n){let{question:e,options:t,onSelect:a}=n,r=document.createElement("div");r.className="namiru-prechat";let i=document.createElement("div");i.className="namiru-prechat-question",i.textContent=e,r.appendChild(i);let l=document.createElement("div");l.className="namiru-prechat-options";for(let o of t){let s=document.createElement("button");s.className="namiru-prechat-option";let d=Te(o.icon);s.appendChild(d);let c=document.createElement("span");c.textContent=o.label,s.appendChild(c),s.addEventListener("click",()=>a(o.label)),l.appendChild(s)}return r.appendChild(l),r}function Ie(n){let{onFeedback:e,softPrompt:t}=n,a=document.createElement("div");a.className="namiru-feedback";let r=document.createElement("div");r.className="namiru-feedback-label",r.textContent="Feedback",a.appendChild(r);let i=document.createElement("div");i.className="namiru-feedback-text",i.textContent=t?"How did it go? Your feedback helps us improve.":"How was your experience?",a.appendChild(i);let l=document.createElement("div");l.className="namiru-feedback-buttons";let o=document.createElement("button");o.className="namiru-feedback-btn namiru-feedback-btn-up",o.setAttribute("aria-label","Thumbs up"),o.appendChild(we());let s=document.createElement("button");s.className="namiru-feedback-btn namiru-feedback-btn-down",s.setAttribute("aria-label","Thumbs down"),s.appendChild(Se());function d(c){for(e(c);a.firstChild;)a.removeChild(a.firstChild);let p=document.createElement("div");p.className="namiru-feedback-thanks",p.textContent="Thanks for your feedback!",a.appendChild(p)}return o.addEventListener("click",()=>d("up")),s.addEventListener("click",()=>d("down")),l.appendChild(o),l.appendChild(s),a.appendChild(l),a}function le(n){let{promptText:e,buttonText:t,onSubmit:a}=n,r=document.createElement("div");r.className="namiru-email-form";let i=document.createElement("div");i.className="namiru-email-form-text",i.textContent=e,r.appendChild(i);let l=document.createElement("div");l.className="namiru-email-form-row";let o=document.createElement("input");o.className="namiru-email-input",o.type="email",o.placeholder="your@email.com",o.setAttribute("aria-label","Email address");let s=document.createElement("button");s.className="namiru-email-submit",s.textContent=t,s.disabled=!0,o.addEventListener("input",()=>{s.disabled=!_e(o.value)});function d(){let c=o.value.trim();if(!_e(c))return;a(c),l.remove(),i.remove();let p=document.createElement("div");p.className="namiru-email-sent",p.textContent="Thanks, we'll be in touch",r.appendChild(p)}return o.addEventListener("keydown",c=>{c.key==="Enter"&&(c.preventDefault(),d())}),s.addEventListener("click",d),l.appendChild(o),l.appendChild(s),r.appendChild(l),r}function _e(n){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(n.trim())}function $e(n){let{onSubmit:e}=n,t=document.createElement("div");t.className="namiru-contact-form";let a=document.createElement("div");a.className="namiru-contact-heading",a.textContent="Our team is here to help! Leave your message and we'll get back to you.",t.appendChild(a);let r=document.createElement("label");r.className="namiru-contact-label",r.textContent="Name (optional)",t.appendChild(r);let i=document.createElement("input");i.className="namiru-contact-input",i.type="text",i.placeholder="Your name",i.setAttribute("aria-label","Name"),t.appendChild(i);let l=document.createElement("label");l.className="namiru-contact-label",l.textContent="Email *",t.appendChild(l);let o=document.createElement("input");o.className="namiru-contact-input",o.type="email",o.placeholder="your@email.com",o.required=!0,o.setAttribute("aria-label","Email address"),t.appendChild(o);let s=document.createElement("label");s.className="namiru-contact-label",s.textContent="Message *",t.appendChild(s);let d=document.createElement("textarea");d.className="namiru-contact-textarea",d.placeholder="How can we help you?",d.rows=4,d.required=!0,d.setAttribute("aria-label","Message"),t.appendChild(d);let c=document.createElement("div");c.className="namiru-contact-error",c.style.display="none",t.appendChild(c);let p=document.createElement("button");p.className="namiru-contact-submit",p.textContent="Send Message",p.disabled=!0,t.appendChild(p);function w(){let y=o.value.trim(),k=d.value.trim();return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(y)&&k.length>0}function g(){p.disabled=!w()}o.addEventListener("input",g),d.addEventListener("input",g);function v(){if(!w())return;let y={name:i.value.trim(),email:o.value.trim(),message:d.value.trim()};p.disabled=!0,p.textContent="Sending...",i.disabled=!0,o.disabled=!0,d.disabled=!0,e(y),t.textContent="";let k=document.createElement("div");k.className="namiru-contact-confirmation",k.textContent="Thanks! We'll get back to you shortly.",t.appendChild(k)}return p.addEventListener("click",v),o.addEventListener("keydown",y=>{y.key==="Enter"&&(y.preventDefault(),v())}),i.addEventListener("keydown",y=>{y.key==="Enter"&&(y.preventDefault(),v())}),t}function ut(){let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width","40"),n.setAttribute("height","40"),n.setAttribute("viewBox","0 0 256 256"),n.setAttribute("fill","none"),n.setAttribute("stroke","currentColor"),n.setAttribute("stroke-width","16"),n.setAttribute("stroke-linecap","round"),n.setAttribute("stroke-linejoin","round");let e=document.createElementNS("http://www.w3.org/2000/svg","circle");e.setAttribute("cx","128"),e.setAttribute("cy","128"),e.setAttribute("r","96"),n.appendChild(e);let t=document.createElementNS("http://www.w3.org/2000/svg","line");t.setAttribute("x1","128"),t.setAttribute("y1","80"),t.setAttribute("x2","128"),t.setAttribute("y2","136"),n.appendChild(t);let a=document.createElementNS("http://www.w3.org/2000/svg","circle");return a.setAttribute("cx","128"),a.setAttribute("cy","172"),a.setAttribute("r","6"),a.setAttribute("fill","currentColor"),a.setAttribute("stroke","none"),n.appendChild(a),n}function pt(){let n=document.createElementNS("http://www.w3.org/2000/svg","svg");n.setAttribute("width","40"),n.setAttribute("height","40"),n.setAttribute("viewBox","0 0 256 256"),n.setAttribute("fill","none"),n.setAttribute("stroke","currentColor"),n.setAttribute("stroke-width","16"),n.setAttribute("stroke-linecap","round"),n.setAttribute("stroke-linejoin","round");let e=document.createElementNS("http://www.w3.org/2000/svg","circle");e.setAttribute("cx","128"),e.setAttribute("cy","128"),e.setAttribute("r","96"),n.appendChild(e);let t=document.createElementNS("http://www.w3.org/2000/svg","polyline");return t.setAttribute("points","88,136 112,160 168,104"),n.appendChild(t),n}function He(n){let{onSubmit:e,onNewChat:t}=n,a=document.createElement("div");a.className="namiru-limit-overlay";let r=document.createElement("div");r.className="namiru-limit-icon",r.appendChild(ut()),a.appendChild(r);let i=document.createElement("div");i.className="namiru-limit-heading",i.textContent="Conversation limit reached",a.appendChild(i);let l=document.createElement("div");l.className="namiru-limit-subtext",l.textContent="AI responses are currently unavailable. Send a message and we'll forward it via email.",a.appendChild(l);let o=document.createElement("div");o.className="namiru-limit-form";let s=document.createElement("textarea");s.className="namiru-limit-textarea",s.placeholder="Your message...",s.rows=4,s.setAttribute("aria-label","Message"),o.appendChild(s);let d=document.createElement("input");d.className="namiru-limit-email",d.type="email",d.placeholder="Your email (optional, for a reply)",d.setAttribute("aria-label","Email address (optional)"),o.appendChild(d);let c=document.createElement("button");if(c.className="namiru-limit-submit",c.textContent="Send Message",c.disabled=!0,o.appendChild(c),a.appendChild(o),t){let v=document.createElement("button");v.className="namiru-limit-newchat",v.textContent="Start New Chat",v.addEventListener("click",t),a.appendChild(v)}function p(){return s.value.trim().length>0}function w(){c.disabled=!p()}s.addEventListener("input",w);function g(){if(!p())return;let v=d.value.trim(),y={message:s.value.trim()};v&&(y.visitorEmail=v),c.disabled=!0,c.textContent="Sending...",s.disabled=!0,d.disabled=!0,e(y),a.textContent="";let k=document.createElement("div");k.className="namiru-limit-icon namiru-limit-icon--success",k.appendChild(pt()),a.appendChild(k);let C=document.createElement("div");if(C.className="namiru-limit-confirmation",C.textContent="Message sent! The team will get back to you soon.",a.appendChild(C),t){let N=document.createElement("button");N.className="namiru-limit-newchat",N.textContent="Start New Chat",N.addEventListener("click",t),a.appendChild(N)}}return c.addEventListener("click",g),a}function Oe(n){let{store:e,branding:t,agentId:a,mode:r,position:i,onSendMessage:l,onPreChatSelect:o,onFeedback:s,onEscalationEmail:d,onTranscriptEmail:c,onContactFormSubmit:p,onLimitMessage:w,onNewChat:g,feedbackEnabled:v}=n,y=t.agentAvatar||t.logoUrl,k=Ne({textColor:t.textColor,bubbleStyle:t.bubbleStyle,agentAvatar:y,presetTheme:t.presetTheme}),C=document.createElement("div");r==="button"?C.className=`namiru-popup namiru-popup--${i}`:C.className="namiru-inline";let N=Ae({store:e,branding:t,mode:r,...r==="button"?{onTranscriptClick:()=>{e.dispatch({type:"SET_STATE",state:"escalation"}),de()},onNewChat:g}:{},feedbackEnabled:v});C.appendChild(N);let S=document.createElement("div");S.className="namiru-messages",C.appendChild(S);let I=Me({onSend:l});I.style.display="none",C.appendChild(I);let Z=t.showPoweredBy!==!1;Z||(I.style.paddingBottom="12px");function B(){let m=document.createElement("div");m.className="namiru-powered",m.setAttribute("data-namiru-protected","true");let b=V?"":" !important";m.style.cssText=`display:block${b};visibility:visible${b};opacity:1${b};`;let E=document.createElement("a");return E.href="https://namiru.ai",E.target="_blank",E.rel="noopener noreferrer",E.textContent="Namiru.ai",m.appendChild(document.createTextNode("Powered by ")),m.appendChild(E),m}if(Z){let b=B().innerHTML;C.appendChild(B());let E=!1;new MutationObserver(()=>{if(E)return;E=!0;let A=C.querySelector(".namiru-powered");if(!A)C.appendChild(B());else if(A.innerHTML!==b){let M=B();A.replaceWith(M)}else{let M=A.style,L=getComputedStyle(A);if(L.display==="none"||L.visibility==="hidden"||L.opacity==="0"){let F=V?"":" !important";M.cssText=`display:block${F};visibility:visible${F};opacity:1${F};`}}E=!1}).observe(C,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style","class"],characterData:!0})}t.fontFamily&&t.fontFamily!=="system"&&(C.style.fontFamily=t.fontFamily);let z=40,D=0,u=null,h=null,T=null,f=null,x=null,H=!1,$=null,W=null,U=null,P=null;function Fe(){if(P)return;P=document.createElement("div"),P.className="namiru-connecting";let m=document.createElement("div");m.className="namiru-loading-dots";for(let b=0;b<3;b++){let E=document.createElement("span");E.className="namiru-loading-dot",m.appendChild(E)}P.appendChild(m),S.appendChild(P)}function q(){P&&(P.remove(),P=null)}function ie(){S.textContent="",D=0,u=null,h=null,T=null,f=null,x=null,W=null,U=null,P=null,H=!1,$=null}function Ve(){if(H)return;H=!0;let m=t.welcomeMessage||"Hello! How can I help you today?",b=document.createElement("div");b.className="namiru-message-row namiru-message-row--assistant namiru-message-row--welcome";let E=document.createElement("div");if(E.className="namiru-message-icon",y){let M=document.createElement("img");M.src=y,M.alt="Agent",M.className="namiru-message-avatar-img",E.appendChild(M)}else E.appendChild(te(t.textColor));b.appendChild(E);let O=document.createElement("div");O.className="namiru-message namiru-message--assistant",O.textContent=m,b.appendChild(O),S.appendChild(b);let A=t.suggestedQuestions;A&&A.length>0&&($=document.createElement("div"),$.className="namiru-suggestions",A.slice(0,4).forEach(M=>{let L=document.createElement("button");L.className="namiru-suggestion-chip",L.textContent=M,L.addEventListener("click",()=>{l(M),$&&($.remove(),$=null)}),$.appendChild(L)}),S.appendChild($))}function ze(){let m=t.preChatConfig;if(!m||!m.enabled)return;let b={ecommerce:{question:"What brings you here today?",options:[{label:"Product question",icon:"ShoppingBag"},{label:"Order help",icon:"Package"},{label:"Billing issue",icon:"CreditCard"},{label:"Something else",icon:"ChatCircle"}]},saas:{question:"What can we help you with?",options:[{label:"Getting started",icon:"Rocket"},{label:"Technical issue",icon:"Wrench"},{label:"Subscription question",icon:"CreditCard"},{label:"Something else",icon:"ChatCircle"}]},services:{question:"How can we assist you?",options:[{label:"Interested in services",icon:"Briefcase"},{label:"Existing client",icon:"UserCircle"},{label:"General question",icon:"ChatCircle"},{label:"Something else",icon:"DotsThree"}]}},E,O;if(m.template==="custom"&&m.custom)E=m.custom.question,O=m.custom.options;else if(m.template&&b[m.template]){let A=b[m.template];E=A.question,O=A.options}else return;ie(),I.style.display="none",T=Le({question:E,options:O,onSelect:A=>{o(A),I.style.display=""}}),S.appendChild(T)}function de(){x||(x=le({promptText:"Want a copy of this conversation? Handy if you need to reference it later for support.",buttonText:"Send",onSubmit:m=>{c(m),x=null}}),S.appendChild(x),R())}function me(){x||(x=le({promptText:"We'll connect you with the team. Please share your email and we'll get back to you.",buttonText:"Submit",onSubmit:m=>{d(m),x=null}}),S.appendChild(x),R())}function ue(){W||(ie(),I.style.display="none",W=$e({onSubmit:m=>{p&&p(m),W=null}}),S.appendChild(W))}function pe(){U||(I.style.display="none",U=He({onSubmit:m=>{w&&w(m),U=null}}),S.style.position="relative",S.appendChild(U))}function Re(){for(;S.firstChild;)S.removeChild(S.firstChild);S.style.position="relative";let m=document.createElement("div");m.style.cssText=`
1076
+ position: absolute; inset: 0; display: flex; flex-direction: column;
1077
+ align-items: center; justify-content: center; padding: 2rem; text-align: center;
1078
+ background: ${t.backgroundColor||"#ffffff"};
1079
+ color: ${t.textColor||"#1f2937"};
1080
+ `;let b=document.createElementNS("http://www.w3.org/2000/svg","svg");b.setAttribute("viewBox","0 0 256 256"),b.setAttribute("width","72"),b.setAttribute("height","72"),b.setAttribute("fill","#ef4444"),b.style.cssText="margin-bottom: 20px; opacity: 0.8;";let E=document.createElementNS("http://www.w3.org/2000/svg","path");E.setAttribute("d","M128,26A102,102,0,1,0,230,128,102.12,102.12,0,0,0,128,26Zm90,102a89.6,89.6,0,0,1-22.29,59.22L68.78,60.29A89.95,89.95,0,0,1,218,128ZM38,128A89.6,89.6,0,0,1,60.29,68.78L187.22,195.71A89.95,89.95,0,0,1,38,128Z"),b.appendChild(E),m.appendChild(b);let O=document.createElement("div");O.style.cssText="font-size: 18px; font-weight: 600; margin-bottom: 8px;",O.textContent="Domain Not Authorized",m.appendChild(O);let A=document.createElement("div");A.style.cssText="font-size: 14px; opacity: 0.7; margin-bottom: 24px; max-width: 300px; line-height: 1.5;",A.textContent="This chat widget is not authorized to run on this domain. Please update the allowed domain in your agent settings.",m.appendChild(A);let M=document.createElement("div");M.style.cssText="display: flex; gap: 12px; align-items: center;";let L=document.createElement("a");L.style.cssText=`
1081
+ padding: 10px 24px; border-radius: 8px; border: none; cursor: pointer;
1082
+ font-size: 14px; font-weight: 500; text-decoration: none;
1083
+ display: inline-flex; align-items: center; box-sizing: border-box;
1084
+ line-height: 1; background: ${t.primaryColor||"#4a7fff"}; color: #fff;
1085
+ `,L.textContent="Go to Settings";let F=window.location.hostname,he=window.location.origin;F!=="localhost"&&F!=="127.0.0.1"&&F.endsWith("namiru.ai")&&(he=F.includes("test")?"https://test.namiru.ai":"https://namiru.ai"),L.href=`${he}/agent-builder/agent/${a}/settings?focus=domain`,L.target="_blank",L.rel="noopener",M.appendChild(L);let j=document.createElement("button");j.style.cssText=`
1086
+ padding: 10px 24px; border-radius: 8px; cursor: pointer;
1087
+ font-size: 14px; font-weight: 500; line-height: 1; box-sizing: border-box;
1088
+ background: transparent; color: ${t.textColor||"#1f2937"};
1089
+ border: 1px solid ${t.textColor?t.textColor+"33":"#e5e7eb"};
1090
+ `,j.textContent="Reload",j.addEventListener("click",()=>window.location.reload()),M.appendChild(j),m.appendChild(M),S.appendChild(m)}function ge(m){f||(f=Ie({onFeedback:b=>{s(b),r==="button"&&setTimeout(()=>{e.dispatch({type:"SET_STATE",state:"chatting"}),e.dispatch({type:"SET_OPEN",isOpen:!1})},1200)},softPrompt:m}),S.appendChild(f),R())}function R(){requestAnimationFrame(()=>{S.scrollTop=S.scrollHeight})}function Ge(m){$&&m.some(b=>b.role==="user")&&($.remove(),$=null);for(let b=D;b<m.length;b++){let E=k.createBubble(m[b]);S.appendChild(E)}D=m.length,R()}function Ze(m){if(m){u||(h&&(h.remove(),h=null),u=k.createStreaming(),S.appendChild(u));let b=u._namiruTextEl,E=ee(m);b?b.innerHTML=E:u.innerHTML=E,R()}else u&&(u.remove(),u=null)}function We(m){m&&!h&&!u?(h=k.createLoading(),S.appendChild(h),R()):!m&&h&&(h.remove(),h=null)}let G=null;return e.subscribe(m=>{if(r==="button"&&(m.isOpen?C.classList.add("namiru-popup--open"):C.classList.remove("namiru-popup--open")),!G||G.state!==m.state)switch(m.state){case"connecting":I.style.display="none",Fe();break;case"pre_chat":ze();break;case"chatting":q(),G?.state==="pre_chat"&&ie(),I.style.display="",Ve();break;case"feedback":ge(!0);break;case"escalation":me();break;case"email_fallback":ue();break;case"conversation_limit":q(),I.style.display="none",pe();break;case"domain_error":q(),I.style.display="none",Re();break;case"error":q(),I.style.display="none";break}m.messages.length>D&&m.state!=="pre_chat"&&Ge(m.messages),m.state==="chatting"&&m.messages.length>=z&&e.dispatch({type:"SET_STATE",state:"conversation_limit"}),G?.streamingContent!==m.streamingContent&&Ze(m.streamingContent),G?.isLoading!==m.isLoading&&We(m.isLoading),G=m}),C._namiruShowEscalation=me,C._namiruShowFeedback=ge,C._namiruShowTranscript=de,C._namiruShowContactForm=ue,C._namiruShowLimitOverlay=pe,C}function De(n){let{position:e,store:t,welcomeMessage:a,greetingDelay:r,bubbleStyle:i}=n,l=document.createElement("div"),o=document.createElement("button");o.className=`namiru-button namiru-button--${e}`,i==="classic"&&o.classList.add("namiru-button--classic"),o.setAttribute("aria-label","Open chat");let s=Ce(),d=ne();d.style.display="none",o.appendChild(s),o.appendChild(d),o.addEventListener("click",()=>{let v=t.getState().isOpen;t.dispatch({type:"SET_OPEN",isOpen:!v})}),l.appendChild(o);let c=null,p=!1,w=null;if(a){c=document.createElement("div"),c.className=`namiru-greeting namiru-greeting--${e} namiru-greeting--hidden`;let v=document.createTextNode(a);c.appendChild(v);let y=document.createElement("button");y.className="namiru-greeting-close",y.setAttribute("aria-label","Dismiss"),y.textContent="\xD7",y.addEventListener("click",C=>{C.stopPropagation(),g()}),c.appendChild(y),c.addEventListener("click",()=>{g(),t.dispatch({type:"SET_OPEN",isOpen:!0})}),l.appendChild(c),w=setTimeout(()=>{!t.getState().isOpen&&c&&(c.classList.remove("namiru-greeting--hidden"),p=!0)},r??3e3)}function g(){p&&c&&(c.classList.add("namiru-greeting--hidden"),p=!1),w&&(clearTimeout(w),w=null)}return t.subscribe(v=>{v.isOpen?(s.style.display="none",d.style.display="",o.setAttribute("aria-label","Close chat"),g()):(s.style.display="",d.style.display="none",o.setAttribute("aria-label","Open chat"))}),l}function gt(n){try{let e=new URL(n),t=e.protocol==="https:"?"wss:":"ws:";return e.hostname==="localhost"||e.hostname==="127.0.0.1"?(e.port="3423",e.protocol=t,e.origin):e.hostname==="test.namiru.ai"?`${t}//ai-test.namiru.ai`:e.hostname==="namiru.ai"||e.hostname==="app.namiru.ai"?`${t}//ai.namiru.ai`:(e.protocol=t,e.origin)}catch{let e=n.startsWith("https")?"wss":"ws",t=n.replace(/^https?:\/\//,"");return`${e}://${t}`}}function ht(n){try{let e=new URL(n);return e.hostname.startsWith("app.")?(e.hostname=e.hostname.replace("app.","api."),e.origin):e.hostname==="test.namiru.ai"?(e.hostname="api-test.namiru.ai",e.origin):e.hostname==="namiru.ai"?(e.hostname="api.namiru.ai",e.origin):((e.hostname==="localhost"||e.hostname==="127.0.0.1")&&(e.port="3001"),e.origin)}catch{return n}}function ft(n){let e,t=null;if(n.serverUrl)e=n.serverUrl.replace(/\/$/,"");else{let a=document.querySelectorAll("script[src]");for(let r=a.length-1;r>=0;r--){let i=a[r].src;if(i.includes("namiru-chat")||i.includes("namiru"))try{t=new URL(i).origin;break}catch{}}e=ht(t||location.origin)}return{apiBase:e,wsUrl:n.wsUrl||gt(t||e)}}var Be="namiru_visitor_id";function ce(){try{let n=localStorage.getItem(Be);if(n)return n;let e=`v_${Date.now()}_${Math.random().toString(36).substring(2,11)}`;return localStorage.setItem(Be,e),e}catch{return`v_${Date.now()}_${Math.random().toString(36).substring(2,11)}`}}var Pe=0;function ae(){return Pe++,`msg-${Date.now()}-${Pe}`}function bt(n){if(!n||n.length===0)return!0;let e=window.location.hostname.toLowerCase();return e==="localhost"||e==="127.0.0.1"||e==="namiru.ai"||e.endsWith(".namiru.ai")?!0:n.some(t=>{let a=t.toLowerCase();return e===a||e.endsWith("."+a)})}function xt(n){if(!n.agentId)throw new Error("NamiruChat: agentId is required");let e=n.mode||"button",t=n.position||"bottom-right",{apiBase:a,wsUrl:r}=ft(n),i=new Y,l=new J({baseUrl:a}),o=null,s=null,d=null,c=null,p=null,w=null,g=!1,v="handoff_accepted",y=!1,k=null,C=!1;s=document.createElement("div"),s.id="namiru-widget-host";let N=typeof s.attachShadow=="function";be(N),N&&(s.style.cssText="all:initial;position:fixed;top:0;left:0;width:0;height:0;overflow:visible;z-index:2147483646;pointer-events:none;",d=s.attachShadow({mode:"open"})),c=document.createElement("div"),c.className="namiru-widget-root";let S=d||s;N&&(c.style.pointerEvents="auto"),S.appendChild(c);async function I(){try{let u=await l.fetchBranding(n.agentId);if(g)return;if(!bt(u.allowedDomains)){console.warn(`[Namiru Widget] Domain "${window.location.hostname}" is not allowed for this agent. Allowed: ${JSON.stringify(u.allowedDomains)}`);return}xe({primaryColor:u.primaryColor,accentColor:u.accentColor,headerColor:u.headerColor,fontFamily:u.fontFamily,presetTheme:u.presetTheme,backgroundColor:u.backgroundColor,textColor:u.textColor,fontSize:u.fontSize,userMessageColor:u.userMessageColor,agentMessageColor:u.agentMessageColor},S,!N);let h=n.preChatEnabled??u.preChatConfig?.enabled??!1;h&&(u.preChatConfig?(u.preChatConfig.enabled=!0,n.preChatTemplate!==void 0&&(u.preChatConfig.template=n.preChatTemplate),n.preChatCustom&&(u.preChatConfig.custom=n.preChatCustom)):u.preChatConfig={enabled:!0,template:n.preChatTemplate??null,custom:n.preChatCustom}),C=u.feedbackConfig?.enabled??!1;let T=u.feedbackConfig?.inactivityMinutes??3;if(C&&(k=new K(T,()=>{let f=i.getState();!f.feedbackGiven&&f.state==="chatting"&&f.messages.length>0&&i.dispatch({type:"SET_STATE",state:"feedback"})})),p=Oe({store:i,branding:u,agentId:n.agentId,mode:e,position:t,onSendMessage:f=>{let x={id:ae(),role:"user",content:f,timestamp:Date.now()};i.dispatch({type:"ADD_MESSAGE",message:x}),i.dispatch({type:"SET_LOADING",isLoading:!0}),o&&o.sendMessage(f)},onPreChatSelect:f=>{i.dispatch({type:"SET_QUALIFICATION",qualification:f}),i.dispatch({type:"SET_STATE",state:"connecting"}),B(f)},onFeedback:f=>{let x=i.getState().sessionId;x&&l.submitFeedback(n.agentId,{sessionId:x,rating:f}).catch(H=>console.error("NamiruChat: feedback submit failed",H)),i.dispatch({type:"SET_FEEDBACK_GIVEN"}),k?.stop(),n.onFeedback?.(f)},onEscalationEmail:f=>{let x=i.getState().sessionId;x&&l.submitEscalation(n.agentId,{sessionId:x,userEmail:f}).catch(H=>console.error("NamiruChat: escalation submit failed",H)),o&&o.sendEscalationEmail(f),n.onLeadCapture?.({email:f,sessionId:x||"",source:"email_fallback",qualification:i.getState().qualification||void 0})},onTranscriptEmail:f=>{let x=i.getState().sessionId;x&&l.requestTranscript(n.agentId,x,{email:f}).catch(H=>console.error("NamiruChat: transcript request failed",H))},onContactFormSubmit:f=>{let x=ce(),H=i.getState().sessionId;l.submitLead({agentId:n.agentId,name:f.name||void 0,email:f.email,message:f.message,visitorId:x,fallbackReason:v,conversationId:H||void 0}).catch($=>console.error("NamiruChat: lead submit failed",$)),o&&o.sendHandoffComplete({email:f.email,name:f.name||void 0,reason:v}),n.onLeadCapture?.({email:f.email,sessionId:H||"",source:"email_fallback",qualification:i.getState().qualification||void 0})},onLimitMessage:f=>{f.visitorEmail?l.submitContactMessage(n.agentId,{email:f.visitorEmail,message:f.message,visitorId:ce()}).catch(x=>console.error("NamiruChat: contact message submit failed",x)):l.submitLimitMessage({agentId:n.agentId,message:f.message}).catch(x=>console.error("NamiruChat: limit message submit failed",x))},feedbackEnabled:C,onNewChat:()=>{o&&(o.disconnect(),o=null),k?.stop(),i.dispatch({type:"RESET"}),i.dispatch({type:"SET_OPEN",isOpen:!0}),i.dispatch({type:"SET_STATE",state:"connecting"}),B()}}),c.appendChild(p),e==="button"&&(w=De({position:t,store:i,welcomeMessage:u.bubbleGreeting||void 0,greetingDelay:n.greetingDelay,bubbleStyle:u.bubbleStyle}),c.appendChild(w)),e==="inline"&&p){let f=n.width||"100%",x=n.height||"100%";p.style.width=f,p.style.height=x,p.style.maxHeight=x,c.style.height="100%"}N?e==="inline"&&n.container?(s.style.cssText="all:initial;display:block;height:100%;",n.container.appendChild(s)):document.body.appendChild(s):e==="inline"&&n.container?n.container.appendChild(c):document.body.appendChild(c),h?i.dispatch({type:"SET_STATE",state:"pre_chat"}):(i.dispatch({type:"SET_STATE",state:"connecting"}),B()),e==="inline"&&i.dispatch({type:"SET_OPEN",isOpen:!0})}catch(u){console.error("NamiruChat: initialization failed",u),i.dispatch({type:"SET_ERROR",error:"Failed to load chat. Please try again later."})}}function Z(){y&&(y=!1,p&&setTimeout(()=>{let u=p?._namiruShowEscalation;typeof u=="function"&&u()},100))}function B(u){o||g||(o=new Q({url:r,agentId:n.agentId,visitorId:ce()}),o.on("connected",()=>{}),o.on("agent_initialized",h=>{i.dispatch({type:"SET_STATE",state:"chatting"}),i.dispatch({type:"SET_LOADING",isLoading:!1}),h.data.sessionId&&(i.dispatch({type:"SET_SESSION_ID",sessionId:h.data.sessionId}),n.onSessionStart?.(h.data.sessionId)),u&&o?.sendMessage(`[User selected: ${u}]`)}),o.on("stream_token",h=>{i.dispatch({type:"APPEND_STREAMING",token:h.data.token})}),o.on("final_response",h=>{i.dispatch({type:"CLEAR_STREAMING"});let T={id:ae(),role:"assistant",content:h.data.content||h.data.response||"",timestamp:Date.now()};i.dispatch({type:"ADD_MESSAGE",message:T}),i.dispatch({type:"SET_LOADING",isLoading:!1}),Z(),C&&h.data.conversationMayHaveEnded&&!i.getState().feedbackGiven?(setTimeout(()=>{let f=i.getState();!f.feedbackGiven&&f.state==="chatting"&&f.messages.length>0&&i.dispatch({type:"SET_STATE",state:"feedback"})},800),k?.stop()):k&&!i.getState().feedbackGiven&&k.reset()}),o.on("stream_end",()=>{let h=i.getState().streamingContent;if(h){i.dispatch({type:"CLEAR_STREAMING"});let T={id:ae(),role:"assistant",content:h,timestamp:Date.now()};i.dispatch({type:"ADD_MESSAGE",message:T})}i.dispatch({type:"SET_LOADING",isLoading:!1}),Z(),k&&!i.getState().feedbackGiven&&k.reset()}),o.on("tool_start",()=>{i.dispatch({type:"SET_LOADING",isLoading:!0})}),o.on("tool_end",()=>{}),o.on("kit_trigger",h=>{let T=h.data;(T==="escalation_email_form"||T?.type==="escalation_email_form")&&(y=!0)}),o.on("handoff_active",h=>{let T={id:ae(),role:"assistant",content:h.data?.message||"A human operator is currently handling this conversation. Please wait for their response.",timestamp:Date.now()};i.dispatch({type:"ADD_MESSAGE",message:T}),i.dispatch({type:"SET_LOADING",isLoading:!1})}),o.on("show_handoff_form",h=>{v=h.data?.reason||"handoff_accepted",i.dispatch({type:"SET_STATE",state:"email_fallback"}),i.dispatch({type:"SET_LOADING",isLoading:!1})}),o.on("error",h=>{if(h.data?.type==="usage_limit"||h.data?.usage_limit){i.dispatch({type:"SET_STATE",state:"conversation_limit"}),i.dispatch({type:"SET_LOADING",isLoading:!1});return}if(h.data?.message==="Domain not authorized"){i.dispatch({type:"SET_STATE",state:"domain_error"}),i.dispatch({type:"SET_LOADING",isLoading:!1});return}console.error("NamiruChat: WebSocket error",h.data),i.dispatch({type:"SET_ERROR",error:h.data?.message||"Connection error. Please try again."}),i.dispatch({type:"SET_LOADING",isLoading:!1})}),o.on("disconnected",()=>{}),o.connect())}I();let z=!1,D=!1;return i.subscribe(u=>{if(!(g||D)){if(z&&!u.isOpen&&o){D=!0,o.disconnect(),o=null,k?.stop(),setTimeout(()=>{D=!1,i.dispatch({type:"RESET"})},0),z=!1;return}!z&&u.isOpen&&!o&&u.state!=="pre_chat"&&(D=!0,i.dispatch({type:"SET_STATE",state:"connecting"}),B(),D=!1),z=u.isOpen}}),{open:()=>{g||i.dispatch({type:"SET_OPEN",isOpen:!0})},close:()=>{g||i.dispatch({type:"SET_OPEN",isOpen:!1})},toggle:()=>{if(!g){let u=i.getState().isOpen;i.dispatch({type:"SET_OPEN",isOpen:!u})}},destroy:()=>{if(g)return;g=!0,o?.disconnect(),k?.stop(),ve();let u=N?s:c;u&&u.parentNode&&u.parentNode.removeChild(u);let h=i.getState().sessionId;h&&n.onSessionEnd?.(h),i.dispatch({type:"RESET"}),s=null,d=null,c=null,p=null,w=null,o=null},updateConfig:u=>{if(!g){if(u.position&&u.position!==n.position){let h=n.position||"bottom-right",T=u.position;if(w){let f=w.querySelector(".namiru-button");f&&(f.classList.remove(`namiru-button--${h}`),f.classList.add(`namiru-button--${T}`));let x=w.querySelector(".namiru-greeting");x&&(x.classList.remove(`namiru-greeting--${h}`),x.classList.add(`namiru-greeting--${T}`))}p&&(p.classList.remove(`namiru-popup--${h}`),p.classList.add(`namiru-popup--${T}`))}Object.assign(n,u)}}}}if(typeof document<"u"&&document.currentScript){let n=document.currentScript,e=n.getAttribute("data-agent-id");if(e){let t=n.getAttribute("data-position")||"bottom-right",a=n.getAttribute("data-mode")||"button",r=n.getAttribute("data-server-url")||void 0,i=n.getAttribute("data-container-id");xt({agentId:e,position:t,mode:a,serverUrl:r,container:i&&document.getElementById(i)||void 0})}}export{xt as init};
1091
+ //# sourceMappingURL=namiru-chat.esm.js.map