@getnexorai/sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,426 @@
1
+ var Nexor=(function(exports){'use strict';var P=class extends Error{constructor(t){super(t),this.name="NexorError";}},w=class extends P{constructor(t){var n;super(t.message),this.name="NexorAPIError",this.status=t.status,this.code=(n=t.code)!=null?n:we(t.status),this.body=t.body,this.requestId=t.requestId;}},S=class extends w{constructor(t){super({status:401,code:"unauthorized",...t}),this.name="NexorAuthError";}},O=class extends w{constructor(t){super({status:400,code:"validation_error",...t}),this.name="NexorValidationError";}},M=class extends P{constructor(t,n){super(t),this.name="NexorNetworkError",this.cause=n;}};function we(e){return e===400?"validation_error":e===401?"unauthorized":e===403?"forbidden":e===404?"not_found":e===409?"conflict":e===422?"unprocessable_entity":e===429?"rate_limited":e>=500?"server_error":"http_error"}var Ce="https://api.getnexor.ai",ve=3e4,Le=2,Te="0.1.0";function oe(e){var r,o,c,d;if(!e||typeof e.apiKey!="string"||e.apiKey.trim()==="")throw new Error("Nexor SDK: `apiKey` is required. Get one in the dashboard at https://app.getnexor.ai");let t=(r=e.fetch)!=null?r:typeof globalThis!="undefined"&&typeof globalThis.fetch=="function"?globalThis.fetch.bind(globalThis):void 0;if(!t)throw new Error("Nexor SDK: no global fetch found. Pass a `fetch` implementation via init() or upgrade to Node 18+.");let n=`nexor-sdk-js/${Te}${e.userAgentSuffix?` ${e.userAgentSuffix}`:""}`;return {apiKey:e.apiKey.trim(),baseUrl:Me((o=e.baseUrl)!=null?o:Ce),timeoutMs:(c=e.timeoutMs)!=null?c:ve,maxRetries:(d=e.maxRetries)!=null?d:Le,fetchImpl:t,userAgent:n}}async function g(e,t){var i,a,y,f,C,I,R;let n=Ne(e.baseUrl,t.path,t.query),r={"X-API-Key":e.apiKey,Accept:"application/json","User-Agent":e.userAgent};(i=t.options)!=null&&i.idempotencyKey&&(r["Idempotency-Key"]=t.options.idempotencyKey);let o;t.body!==void 0&&(r["Content-Type"]="application/json",o=JSON.stringify(t.body));let c=(y=(a=t.options)==null?void 0:a.timeoutMs)!=null?y:e.timeoutMs,d;for(let l=0;l<=e.maxRetries;l++){let v=new AbortController,h=(f=t.options)==null?void 0:f.signal,L=()=>v.abort();h&&(h.aborted?v.abort():h.addEventListener("abort",L));let k=setTimeout(()=>v.abort(),c);try{let u=await e.fetchImpl(n,{method:t.method,headers:r,body:o,signal:v.signal});clearTimeout(k),h==null||h.removeEventListener("abort",L);let T=(C=u.headers.get("x-request-id"))!=null?C:void 0;if(u.ok){if(u.status===204)return;let E=await u.text();if(!E)return;try{return JSON.parse(E)}catch(Y){throw new w({status:u.status,message:"Failed to parse JSON response",body:E,requestId:T})}}let A=await Re(u),K=(I=Ee(A))!=null?I:`HTTP ${u.status}`,U=Ie(u.status,K,A,T);if(ke(u.status)&&l<e.maxRetries){await re(ne(l,u)),d=U;continue}throw U}catch(u){if(clearTimeout(k),h==null||h.removeEventListener("abort",L),u instanceof w)throw u;let T=u instanceof Error&&(u.name==="AbortError"||/abort/i.test(u.message));if(T&&(h!=null&&h.aborted))throw u;if(d=u,l<e.maxRetries){await re(ne(l));continue}throw new M(T?`Request timed out after ${c}ms`:`Network error: ${(R=u==null?void 0:u.message)!=null?R:String(u)}`,u)}}throw d!=null?d:new M("Request failed")}function Ie(e,t,n,r){return e===401||e===403?new S({message:t,body:n,requestId:r}):e===400||e===422?new O({message:t,body:n,requestId:r}):new w({status:e,message:t,body:n,requestId:r})}function Ee(e){if(!e||typeof e!="object")return;let t=e;if(typeof t.message=="string")return t.message;if(typeof t.error=="string")return t.error}async function Re(e){try{let t=await e.text();if(!t)return null;try{return JSON.parse(t)}catch(n){return t}}catch(t){return null}}function ke(e){return e===429||e>=500&&e<=599}function ne(e,t){if(t){let r=t.headers.get("retry-after");if(r){let o=Number(r);if(!Number.isNaN(o)&&o>0)return Math.min(o*1e3,1e4)}}return 300*2**e+Math.floor(Math.random()*200)}function re(e){return new Promise(t=>setTimeout(t,e))}function Me(e){return e.endsWith("/")?e.slice(0,-1):e}function Ne(e,t,n){let r=t.startsWith("/")?t:`/${t}`,o=Pe(n);return `${e}${r}${o?`?${o}`:""}`}function Pe(e){if(!e)return "";let t=[];for(let[n,r]of Object.entries(e))if(r!=null)if(Array.isArray(r)){if(r.length===0)continue;t.push(`${encodeURIComponent(n)}=${encodeURIComponent(r.join(","))}`);}else t.push(`${encodeURIComponent(n)}=${encodeURIComponent(String(r))}`);return t.join("&")}var b="/api/public",N=class{constructor(t){this.cfg=oe(t);}createLead(t,n){return g(this.cfg,{method:"POST",path:`${b}/leads`,body:t,options:n})}createLeadsBulk(t,n){return g(this.cfg,{method:"POST",path:`${b}/leads`,body:t,options:n})}updateLead(t,n,r){return g(this.cfg,{method:"PUT",path:`${b}/leads/${encodeURIComponent(t)}`,body:n,options:r})}getLead(t,n){return g(this.cfg,{method:"GET",path:`${b}/leads/${encodeURIComponent(t)}`,options:n})}getLeadHistory(t,n={},r){let o=Array.isArray(n.channel)?n.channel:n.channel?[n.channel]:void 0;return g(this.cfg,{method:"GET",path:`${b}/leads/${encodeURIComponent(t)}/history`,query:{channel:o,limit:n.limit,offset:n.offset},options:r})}isLeadPaused(t,n={},r){return g(this.cfg,{method:"GET",path:`${b}/leads/${encodeURIComponent(t)}/is_paused`,query:{workflow_id:n.workflow_id},options:r})}stopAutomation(t,n,r){return g(this.cfg,{method:"POST",path:`${b}/leads/${encodeURIComponent(t)}/automation/stop`,body:n,options:r})}resumeAutomation(t,n,r){return g(this.cfg,{method:"POST",path:`${b}/leads/${encodeURIComponent(t)}/automation/resume`,body:n,options:r})}syncLeadTags(t,n){return g(this.cfg,{method:"POST",path:`${b}/leads/tags`,body:t,options:n})}listLeadMeetings(t,n={},r){let o=Array.isArray(n.status)?n.status.join(","):n.status;return g(this.cfg,{method:"GET",path:`${b}/leads/${encodeURIComponent(t)}/meetings`,query:{status:o},options:r})}listWorkflows(t){return g(this.cfg,{method:"GET",path:`${b}/workflows`,options:t})}listCampaigns(t){return g(this.cfg,{method:"GET",path:`${b}/campaigns`,options:t})}listTemplates(t={},n){return g(this.cfg,{method:"GET",path:`${b}/templates`,query:{status:t.status,category:t.category},options:n})}sendMessage(t,n){return g(this.cfg,{method:"POST",path:`${b}/messages`,body:t,options:n})}createMeeting(t,n){return g(this.cfg,{method:"POST",path:`${b}/meetings`,body:t,options:n})}createMeetingNotes(t,n){return g(this.cfg,{method:"POST",path:`${b}/meeting-notes`,body:t,options:n})}chat(t,n){return g(this.cfg,{method:"POST",path:`${b}/chat`,body:t,options:n})}};function se(e){var t,n,r,o,c,d,i,a,y,f,C,I,R,l,v,h,L,k,u;return {workflowId:e.workflowId,title:(t=e.title)!=null?t:"Chat with us",subtitle:(n=e.subtitle)!=null?n:"We typically reply in a few minutes",greeting:(r=e.greeting)!=null?r:"Hi there! \u{1F44B} How can we help?",errorText:(o=e.errorText)!=null?o:"Sorry, something went wrong. Please try again in a moment.",locale:(c=e.locale)!=null?c:typeof navigator!="undefined"?navigator.language:void 0,accentColor:(d=e.accentColor)!=null?d:"#111827",accentTextColor:(i=e.accentTextColor)!=null?i:"#ffffff",showBranding:(a=e.showBranding)!=null?a:true,position:(y=e.position)!=null?y:"bottom-right",openOnLoad:(f=e.openOnLoad)!=null?f:false,debounceMs:(C=e.debounceMs)!=null?C:700,container:e.container,systemPrompt:e.systemPrompt,clientPrompt:e.clientPrompt,lead:e.lead,capture:{fields:(R=(I=e.capture)==null?void 0:I.fields)!=null?R:["first_name","email"],mode:(v=(l=e.capture)==null?void 0:l.mode)!=null?v:"before",label:(L=(h=e.capture)==null?void 0:h.label)!=null?L:"Tell us a bit about you to get started:",submitLabel:(u=(k=e.capture)==null?void 0:k.submitLabel)!=null?u:"Start chat"},metadata:e.metadata,onOpen:e.onOpen,onClose:e.onClose,onMessage:e.onMessage,onLeadCaptured:e.onLeadCaptured,onError:e.onError}}function F(e){if(e.capture.mode==="skip")return false;if(e.lead){let t=e.lead;return e.capture.fields.some(n=>!t[n])}return true}var ie="nexor.chat.session_id";function ae(){let e=Date.now();try{let n=le();if(n&&e-n.ts<2592e6)return j(n.id,e),n.id}catch(n){}let t=`sess_${Se(16)}`;try{j(t,e);}catch(n){}return t}function de(){try{let e=le();e&&j(e.id,Date.now());}catch(e){}}function le(){let e=window.localStorage.getItem(ie);if(!e)return null;try{let t=JSON.parse(e);if(t&&typeof t.id=="string"&&typeof t.ts=="number")return t}catch(t){}return e.startsWith("sess_")?{id:e,ts:Date.now()}:null}function j(e,t){window.localStorage.setItem(ie,JSON.stringify({id:e,ts:t}));}function Se(e){let t=new Uint8Array(e);if(typeof crypto!="undefined"&&crypto.getRandomValues)crypto.getRandomValues(t);else for(let n=0;n<e;n++)t[n]=Math.floor(Math.random()*256);return Array.from(t,n=>n.toString(16).padStart(2,"0")).join("")}var ce=(e,t)=>`
2
+ .nexor-chat,
3
+ .nexor-chat * {
4
+ box-sizing: border-box;
5
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
6
+ }
7
+
8
+ .nexor-chat {
9
+ position: fixed;
10
+ z-index: 2147483640;
11
+ bottom: 20px;
12
+ right: 20px;
13
+ font-size: 14px;
14
+ line-height: 1.4;
15
+ color: #111;
16
+ }
17
+
18
+ .nexor-chat[data-position="bottom-left"] {
19
+ right: auto;
20
+ left: 20px;
21
+ }
22
+
23
+ /* \u2500\u2500 Launcher bubble \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
24
+ .nexor-chat__launcher {
25
+ width: 56px;
26
+ height: 56px;
27
+ border-radius: 9999px;
28
+ background: ${e};
29
+ color: ${t};
30
+ border: none;
31
+ cursor: pointer;
32
+ display: flex;
33
+ align-items: center;
34
+ justify-content: center;
35
+ box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
36
+ transition: transform 160ms cubic-bezier(.2,.7,.2,1.1),
37
+ box-shadow 160ms ease,
38
+ background 200ms ease;
39
+ padding: 0;
40
+ position: relative;
41
+ animation: nexor-launcher-in 360ms cubic-bezier(.2,.7,.2,1.1) both;
42
+ }
43
+ .nexor-chat__launcher:hover {
44
+ transform: translateY(-2px) scale(1.04);
45
+ box-shadow: 0 10px 24px rgba(0, 0, 0, 0.24);
46
+ }
47
+ .nexor-chat__launcher:active {
48
+ transform: translateY(0) scale(0.97);
49
+ transition-duration: 80ms;
50
+ }
51
+ .nexor-chat__launcher:focus-visible {
52
+ outline: 2px solid ${e};
53
+ outline-offset: 2px;
54
+ }
55
+ .nexor-chat[data-open="true"] .nexor-chat__launcher {
56
+ transform: scale(0.85);
57
+ opacity: 0.75;
58
+ }
59
+ .nexor-chat__launcher svg { width: 24px; height: 24px; transition: transform 200ms ease; }
60
+ .nexor-chat[data-open="true"] .nexor-chat__launcher svg { transform: rotate(8deg); }
61
+
62
+ .nexor-chat__unread {
63
+ position: absolute;
64
+ top: -4px;
65
+ right: -4px;
66
+ min-width: 18px;
67
+ height: 18px;
68
+ background: #ef4444;
69
+ color: #fff;
70
+ border-radius: 9999px;
71
+ font-size: 11px;
72
+ font-weight: 600;
73
+ padding: 0 5px;
74
+ display: flex;
75
+ align-items: center;
76
+ justify-content: center;
77
+ border: 2px solid #fff;
78
+ animation: nexor-pop-in 300ms cubic-bezier(.2,.7,.2,1.1) both;
79
+ }
80
+
81
+ @keyframes nexor-launcher-in {
82
+ from { transform: translateY(20px) scale(0.6); opacity: 0; }
83
+ to { transform: translateY(0) scale(1); opacity: 1; }
84
+ }
85
+ @keyframes nexor-pop-in {
86
+ from { transform: scale(0); }
87
+ to { transform: scale(1); }
88
+ }
89
+
90
+ /* \u2500\u2500 Panel \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
91
+ .nexor-chat__panel {
92
+ position: absolute;
93
+ bottom: 72px;
94
+ right: 0;
95
+ width: 360px;
96
+ max-width: calc(100vw - 32px);
97
+ height: 540px;
98
+ max-height: calc(100vh - 120px);
99
+ background: #fff;
100
+ border-radius: 14px;
101
+ box-shadow: 0 24px 60px rgba(0, 0, 0, 0.22);
102
+ display: flex;
103
+ flex-direction: column;
104
+ overflow: hidden;
105
+ transform: translateY(14px) scale(0.96);
106
+ opacity: 0;
107
+ pointer-events: none;
108
+ transition: transform 220ms cubic-bezier(.2,.7,.2,1.1),
109
+ opacity 220ms ease;
110
+ border: 1px solid rgba(0, 0, 0, 0.06);
111
+ /* Use visibility so screen readers don't read collapsed content */
112
+ visibility: hidden;
113
+ }
114
+ .nexor-chat[data-position="bottom-left"] .nexor-chat__panel {
115
+ right: auto;
116
+ left: 0;
117
+ }
118
+ .nexor-chat[data-open="true"] .nexor-chat__panel {
119
+ transform: translateY(0) scale(1);
120
+ opacity: 1;
121
+ pointer-events: auto;
122
+ visibility: visible;
123
+ }
124
+
125
+ .nexor-chat__header {
126
+ background: ${e};
127
+ color: ${t};
128
+ padding: 14px 16px;
129
+ display: flex;
130
+ align-items: center;
131
+ justify-content: space-between;
132
+ gap: 12px;
133
+ }
134
+ .nexor-chat__title {
135
+ font-weight: 600;
136
+ font-size: 15px;
137
+ margin: 0;
138
+ }
139
+ .nexor-chat__subtitle {
140
+ font-size: 12px;
141
+ opacity: 0.85;
142
+ margin: 2px 0 0;
143
+ }
144
+ .nexor-chat__status-dot {
145
+ display: inline-block;
146
+ width: 8px;
147
+ height: 8px;
148
+ border-radius: 9999px;
149
+ background: #34d399;
150
+ margin-right: 6px;
151
+ vertical-align: 1px;
152
+ animation: nexor-pulse 2.4s ease-in-out infinite;
153
+ box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.6);
154
+ }
155
+ @keyframes nexor-pulse {
156
+ 0%, 100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.55); }
157
+ 50% { box-shadow: 0 0 0 6px rgba(52, 211, 153, 0); }
158
+ }
159
+ .nexor-chat__close {
160
+ background: transparent;
161
+ border: none;
162
+ color: inherit;
163
+ cursor: pointer;
164
+ padding: 4px;
165
+ border-radius: 6px;
166
+ opacity: 0.9;
167
+ transition: background 140ms ease, transform 140ms ease;
168
+ }
169
+ .nexor-chat__close:hover { background: rgba(255,255,255,0.18); opacity: 1; }
170
+ .nexor-chat__close:active { transform: scale(0.92); }
171
+ .nexor-chat__close svg { width: 18px; height: 18px; display: block; }
172
+
173
+ /* \u2500\u2500 Body / messages \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
174
+ .nexor-chat__body {
175
+ flex: 1;
176
+ overflow-y: auto;
177
+ padding: 14px;
178
+ background: #f6f7f9;
179
+ display: flex;
180
+ flex-direction: column;
181
+ gap: 8px;
182
+ scroll-behavior: smooth;
183
+ /* Prevent layout shift when scrollbar appears */
184
+ scrollbar-gutter: stable;
185
+ }
186
+ .nexor-chat__body::-webkit-scrollbar { width: 6px; }
187
+ .nexor-chat__body::-webkit-scrollbar-thumb {
188
+ background: rgba(0,0,0,0.15);
189
+ border-radius: 9999px;
190
+ }
191
+
192
+ .nexor-chat__msg {
193
+ max-width: 80%;
194
+ padding: 8px 12px;
195
+ border-radius: 14px;
196
+ white-space: pre-wrap;
197
+ word-wrap: break-word;
198
+ animation: nexor-msg-in 240ms cubic-bezier(.2,.7,.2,1.1) both;
199
+ will-change: transform, opacity;
200
+ }
201
+ .nexor-chat__msg--bot {
202
+ background: #fff;
203
+ align-self: flex-start;
204
+ border: 1px solid rgba(0,0,0,0.06);
205
+ border-bottom-left-radius: 4px;
206
+ box-shadow: 0 1px 2px rgba(0,0,0,0.04);
207
+ }
208
+ .nexor-chat__msg--user {
209
+ background: ${e};
210
+ color: ${t};
211
+ align-self: flex-end;
212
+ border-bottom-right-radius: 4px;
213
+ animation-name: nexor-msg-in-user;
214
+ }
215
+ .nexor-chat__msg--system {
216
+ background: transparent;
217
+ color: #6b7280;
218
+ font-size: 12px;
219
+ align-self: center;
220
+ text-align: center;
221
+ max-width: 100%;
222
+ animation-name: nexor-fade-in;
223
+ }
224
+ .nexor-chat__msg-time {
225
+ display: block;
226
+ margin-top: 4px;
227
+ font-size: 10px;
228
+ line-height: 1;
229
+ opacity: 0.55;
230
+ text-align: right;
231
+ }
232
+ .nexor-chat__msg--bot .nexor-chat__msg-time { text-align: left; }
233
+
234
+ @keyframes nexor-msg-in {
235
+ from { transform: translateY(8px) scale(0.96); opacity: 0; }
236
+ to { transform: translateY(0) scale(1); opacity: 1; }
237
+ }
238
+ @keyframes nexor-msg-in-user {
239
+ from { transform: translateY(8px) translateX(8px) scale(0.96); opacity: 0; }
240
+ to { transform: translateY(0) translateX(0) scale(1); opacity: 1; }
241
+ }
242
+ @keyframes nexor-fade-in {
243
+ from { opacity: 0; }
244
+ to { opacity: 1; }
245
+ }
246
+
247
+ .nexor-chat__typing {
248
+ align-self: flex-start;
249
+ background: #fff;
250
+ border: 1px solid rgba(0,0,0,0.06);
251
+ border-radius: 14px;
252
+ border-bottom-left-radius: 4px;
253
+ padding: 10px 14px;
254
+ display: inline-flex;
255
+ gap: 4px;
256
+ animation: nexor-msg-in 240ms cubic-bezier(.2,.7,.2,1.1) both;
257
+ }
258
+ .nexor-chat__typing span {
259
+ width: 6px; height: 6px; border-radius: 9999px;
260
+ background: #9ca3af;
261
+ display: inline-block;
262
+ animation: nexor-blink 1.2s infinite ease-in-out;
263
+ }
264
+ .nexor-chat__typing span:nth-child(2) { animation-delay: 0.15s; }
265
+ .nexor-chat__typing span:nth-child(3) { animation-delay: 0.30s; }
266
+ @keyframes nexor-blink {
267
+ 0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
268
+ 30% { opacity: 1; transform: translateY(-3px); }
269
+ }
270
+
271
+ /* \u2500\u2500 Lead capture form \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
272
+ .nexor-chat__capture {
273
+ background: #fff;
274
+ border: 1px solid rgba(0,0,0,0.06);
275
+ border-radius: 12px;
276
+ padding: 12px;
277
+ display: flex;
278
+ flex-direction: column;
279
+ gap: 8px;
280
+ margin-top: 4px;
281
+ animation: nexor-msg-in 280ms cubic-bezier(.2,.7,.2,1.1) both;
282
+ box-shadow: 0 2px 8px rgba(0,0,0,0.05);
283
+ }
284
+ .nexor-chat__capture-label {
285
+ font-size: 12px;
286
+ color: #6b7280;
287
+ margin: 0;
288
+ }
289
+ .nexor-chat__capture-row {
290
+ display: flex;
291
+ gap: 8px;
292
+ }
293
+ .nexor-chat__capture-row > * { flex: 1; }
294
+ .nexor-chat__input,
295
+ .nexor-chat__capture input {
296
+ font: inherit;
297
+ padding: 8px 10px;
298
+ border: 1px solid #d1d5db;
299
+ border-radius: 8px;
300
+ background: #fff;
301
+ color: #111;
302
+ outline: none;
303
+ width: 100%;
304
+ transition: border-color 140ms ease, box-shadow 140ms ease;
305
+ }
306
+ .nexor-chat__input:focus,
307
+ .nexor-chat__capture input:focus {
308
+ border-color: ${e};
309
+ box-shadow: 0 0 0 3px ${e}33;
310
+ }
311
+ .nexor-chat__capture-submit {
312
+ background: ${e};
313
+ color: ${t};
314
+ border: none;
315
+ border-radius: 8px;
316
+ padding: 8px 12px;
317
+ font: inherit;
318
+ font-weight: 600;
319
+ cursor: pointer;
320
+ transition: transform 140ms ease, filter 140ms ease;
321
+ }
322
+ .nexor-chat__capture-submit:hover { filter: brightness(1.08); }
323
+ .nexor-chat__capture-submit:active { transform: scale(0.97); }
324
+ .nexor-chat__capture-submit[disabled] { opacity: 0.6; cursor: not-allowed; }
325
+
326
+ /* \u2500\u2500 Composer \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
327
+ .nexor-chat__composer {
328
+ display: flex;
329
+ gap: 8px;
330
+ padding: 10px;
331
+ background: #fff;
332
+ border-top: 1px solid rgba(0,0,0,0.06);
333
+ align-items: stretch;
334
+ }
335
+ .nexor-chat__send {
336
+ background: ${e};
337
+ color: ${t};
338
+ border: none;
339
+ border-radius: 8px;
340
+ padding: 0 14px;
341
+ font: inherit;
342
+ font-weight: 600;
343
+ cursor: pointer;
344
+ min-width: 44px;
345
+ display: flex;
346
+ align-items: center;
347
+ justify-content: center;
348
+ transition: transform 140ms ease, filter 140ms ease;
349
+ }
350
+ .nexor-chat__send:hover { filter: brightness(1.08); }
351
+ .nexor-chat__send:active { transform: scale(0.95); }
352
+ .nexor-chat__send[disabled] {
353
+ opacity: 0.6;
354
+ cursor: not-allowed;
355
+ transform: none;
356
+ }
357
+ .nexor-chat__send svg {
358
+ width: 18px;
359
+ height: 18px;
360
+ transition: transform 200ms ease;
361
+ }
362
+ .nexor-chat__send:not([disabled]):hover svg { transform: translateX(2px); }
363
+
364
+ /* Small spinner inside the send button while a turn is in flight */
365
+ .nexor-chat__send--loading svg { display: none; }
366
+ .nexor-chat__send--loading::after {
367
+ content: "";
368
+ width: 14px;
369
+ height: 14px;
370
+ border-radius: 9999px;
371
+ border: 2px solid currentColor;
372
+ border-top-color: transparent;
373
+ animation: nexor-spin 700ms linear infinite;
374
+ }
375
+ @keyframes nexor-spin {
376
+ to { transform: rotate(360deg); }
377
+ }
378
+
379
+ .nexor-chat__footer {
380
+ text-align: center;
381
+ font-size: 11px;
382
+ color: #9ca3af;
383
+ padding: 6px;
384
+ background: #fff;
385
+ border-top: 1px solid rgba(0,0,0,0.04);
386
+ }
387
+ .nexor-chat__footer a {
388
+ color: inherit;
389
+ text-decoration: none;
390
+ font-weight: 600;
391
+ }
392
+ .nexor-chat__footer a:hover { text-decoration: underline; }
393
+
394
+ /* Respect users who request reduced motion. */
395
+ @media (prefers-reduced-motion: reduce) {
396
+ .nexor-chat,
397
+ .nexor-chat * {
398
+ animation-duration: 0.001ms !important;
399
+ transition-duration: 0.001ms !important;
400
+ }
401
+ .nexor-chat__status-dot { animation: none; }
402
+ }
403
+ `;var ue="data-nexor-chat-styles";function me(e,t){if(document.querySelector(`style[${ue}]`))return;let n=document.createElement("style");n.setAttribute(ue,"1"),n.textContent=ce(e,t),document.head.appendChild(n);}function fe(){let e=document.createElement("button");e.type="button",e.className="nexor-chat__launcher",e.setAttribute("aria-label","Open chat"),e.innerHTML=`
404
+ <svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
405
+ <path d="M4 5.5C4 4.67 4.67 4 5.5 4h13c.83 0 1.5.67 1.5 1.5v9c0 .83-.67 1.5-1.5 1.5H9l-4 4V5.5Z"
406
+ stroke="currentColor" stroke-width="1.8" stroke-linejoin="round"/>
407
+ </svg>
408
+ `;let t=document.createElement("span");return t.className="nexor-chat__unread",t.style.display="none",e.appendChild(t),{el:e,badge:t}}function he(e){let t=document.createElement("div");t.className="nexor-chat__panel",t.setAttribute("role","dialog"),t.setAttribute("aria-label",e.title);let{header:n,closeBtn:r}=Oe(e),{body:o,captureForm:c,captureInputs:d}=He(e),{form:i,input:a,send:y}=Ue(),f=e.showBranding?$e():null;return t.appendChild(n),t.appendChild(o),t.appendChild(i),f&&t.appendChild(f),{el:t,closeBtn:r,body:o,form:i,input:a,send:y,captureForm:c,captureInputs:d}}function Oe(e){let t=document.createElement("div");t.className="nexor-chat__header";let n=e.subtitle?`<p class="nexor-chat__subtitle">
409
+ <span class="nexor-chat__status-dot" aria-hidden="true"></span>${pe(e.subtitle)}
410
+ </p>`:"";t.innerHTML=`
411
+ <div>
412
+ <p class="nexor-chat__title">${pe(e.title)}</p>
413
+ ${n}
414
+ </div>
415
+ `;let r=document.createElement("button");return r.type="button",r.className="nexor-chat__close",r.setAttribute("aria-label","Close chat"),r.innerHTML=`
416
+ <svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
417
+ <path d="M6 6l12 12M6 18L18 6" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
418
+ </svg>
419
+ `,t.appendChild(r),{header:t,closeBtn:r}}function He(e){let t=document.createElement("div");t.className="nexor-chat__body";let n={},r=null;return F(e)&&(r=Ae(e,n),t.appendChild(r)),{body:t,captureForm:r,captureInputs:n}}function Ae(e,t){var d,i,a,y;let n=document.createElement("form");n.className="nexor-chat__capture",n.noValidate=true;let r=document.createElement("p");r.className="nexor-chat__capture-label",r.textContent=e.capture.label,n.appendChild(r);let o=e.capture.fields;if(o.includes("first_name")||o.includes("last_name")){let f=document.createElement("div");f.className="nexor-chat__capture-row",o.includes("first_name")&&(t.first_name=z("first_name","First name","text",(d=e.lead)==null?void 0:d.first_name),f.appendChild(t.first_name)),o.includes("last_name")&&(t.last_name=z("last_name","Last name","text",(i=e.lead)==null?void 0:i.last_name),f.appendChild(t.last_name)),f.childElementCount>0&&n.appendChild(f);}o.includes("email")&&(t.email=z("email","Email","email",(a=e.lead)==null?void 0:a.email),n.appendChild(t.email)),o.includes("phone")&&(t.phone=z("phone","Phone","tel",(y=e.lead)==null?void 0:y.phone),n.appendChild(t.phone));let c=document.createElement("button");return c.type="submit",c.className="nexor-chat__capture-submit",c.textContent=e.capture.submitLabel,n.appendChild(c),n}function Ue(){let e=document.createElement("form");e.className="nexor-chat__composer";let t=document.createElement("input");t.type="text",t.className="nexor-chat__input",t.placeholder="Type a message\u2026",t.autocomplete="off";let n=document.createElement("button");return n.type="submit",n.className="nexor-chat__send",n.setAttribute("aria-label","Send message"),n.innerHTML=`
420
+ <svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
421
+ <path d="M3.4 11.2 20.5 4.3c.7-.3 1.4.4 1.1 1.1l-6.9 17.1c-.3.8-1.4.8-1.8 0L10 14l-7.5-3c-.8-.3-.8-1.5 0-1.8Z"
422
+ stroke="currentColor" stroke-width="1.6" stroke-linejoin="round" fill="currentColor"/>
423
+ </svg>
424
+ `,e.appendChild(t),e.appendChild(n),{form:e,input:t,send:n}}function $e(){let e=document.createElement("div");return e.className="nexor-chat__footer",e.innerHTML='Powered by <a href="https://www.getnexor.ai" target="_blank" rel="noopener noreferrer">Nexor</a>',e}function ge(e,t,n,r){let o=document.createElement("div");o.className=`nexor-chat__msg nexor-chat__msg--${e}`;let c=document.createElement("span");if(c.className="nexor-chat__msg-text",c.textContent=t,o.appendChild(c),e!=="system"&&n){let d=document.createElement("time");d.className="nexor-chat__msg-time",d.dataset.ts=String(n),d.textContent=G(n,r),o.appendChild(d);}return o}function G(e,t,n=Date.now()){try{let r=Math.max(0,n-e),o=Math.round(r/6e4),c=Math.round(r/36e5),d=Math.round(r/864e5),i=new Intl.RelativeTimeFormat(t,{numeric:"auto"});return r<45e3?i.format(0,"second"):o<60?i.format(-o,"minute"):c<24?i.format(-c,"hour"):d<7?i.format(-d,"day"):new Date(e).toLocaleDateString(t,{day:"numeric",month:"short"})}catch(r){try{return new Date(e).toLocaleTimeString(t,{hour:"2-digit",minute:"2-digit"})}catch(o){return ""}}}function xe(){let e=document.createElement("div");return e.className="nexor-chat__typing",e.innerHTML="<span></span><span></span><span></span>",e}function z(e,t,n,r){let o=document.createElement("input");return o.name=e,o.type=n,o.placeholder=t,r&&(o.value=r),o}function pe(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}var qe=220;function be(e,t){var X,Z,Q;if(Be(),!t||!t.workflowId)throw new Error("Nexor SDK: initChat() requires `workflowId`.");let n=se(t);me(n.accentColor,n.accentTextColor);let r=ae(),o=`nexor.chat.history.${r}`,c=Fe(n),d=fe(),i=he(n);c.appendChild(d.el),c.appendChild(i.el),((X=n.container)!=null?X:document.body).appendChild(c);let a={isOpen:false,unread:0,leadId:void 0,captured:!F(n),pendingLead:{...(Z=n.lead)!=null?Z:{}},history:[]};d.el.addEventListener("click",I),i.closeBtn.addEventListener("click",C),i.form.addEventListener("submit",v),(Q=i.captureForm)==null||Q.addEventListener("submit",R),V();let y=K();if(y.length){a.history=y;for(let s of y)E(s.role==="user"?"user":"bot",s.text,s.ts);J();}n.openOnLoad&&f();function f(){var s;a.isOpen||(a.isOpen=true,c.setAttribute("data-open","true"),_e(),a.history.length===0&&n.greeting&&a.captured&&T(n.greeting),i.input.focus(),(s=n.onOpen)==null||s.call(n));}function C(){var s;a.isOpen&&(a.isOpen=false,c.setAttribute("data-open","false"),(s=n.onClose)==null||s.call(n));}function I(){a.isOpen?C():f();}function R(s){var $,D;s.preventDefault();let p=ze(i),_=n.capture.fields;for(let q of _)if(!p[q]){($=i.captureInputs[q])==null||$.focus();return}a.pendingLead={...a.pendingLead,...p},a.captured=true,(D=i.captureForm)==null||D.remove(),V(),i.input.focus(),n.greeting&&a.history.length===0&&T(n.greeting);}let l={pending:[],timer:0,typingTimer:0,inFlight:false,typing:null};function v(s){s.preventDefault();let p=i.input.value.trim();p&&(i.input.value="",h(p));}function h(s){var p;if(!a.captured){(p=i.captureInputs.first_name)==null||p.focus();return}u(s),l.pending.push(s),L();}function L(){l.timer&&window.clearTimeout(l.timer),l.timer=window.setTimeout(()=>{k();},n.debounceMs);}async function k(){var _,$,D,q,ee;if(l.inFlight||l.pending.length===0)return;let p=l.pending.splice(0,l.pending.length).join(`
425
+ `);l.inFlight=true,l.typingTimer=window.setTimeout(()=>{l.typing=W(xe());},qe);try{let B=await e.chat({workflow_id:n.workflowId,session_id:r,message:p,system_prompt:n.systemPrompt,client_prompt:n.clientPrompt,lead:Object.keys(a.pendingLead).length?a.pendingLead:void 0,metadata:n.metadata});B.lead_id&&!a.leadId&&(a.leadId=B.lead_id,(_=n.onLeadCaptured)==null||_.call(n,a.leadId));let te=(($=B.reply)!=null?$:"").trim();te?T(te):(U(n.errorText),(D=n.onError)==null||D.call(n,new Error("Nexor SDK: empty reply from server")));}catch(B){U(n.errorText),(q=n.onError)==null||q.call(n,B);}finally{window.clearTimeout(l.typingTimer),(ee=l.typing)==null||ee.remove(),l.typing=null,l.inFlight=false,i.input.focus(),l.pending.length&&L();}}function u(s){var _;let p=Date.now();E("user",s,p),a.history.push({role:"user",text:s,ts:p}),A(),(_=n.onMessage)==null||_.call(n,{role:"user",text:s});}function T(s){var _;let p=Date.now();E("bot",s,p),a.history.push({role:"bot",text:s,ts:p}),A(),a.isOpen||ye(),(_=n.onMessage)==null||_.call(n,{role:"bot",text:s});}function A(){try{window.localStorage.setItem(o,JSON.stringify({ts:Date.now(),history:a.history})),de();}catch(s){}}function K(){try{let s=window.localStorage.getItem(o);if(!s)return [];let p=JSON.parse(s);return !p||!Array.isArray(p.history)?[]:Date.now()-(p.ts||0)>2592e6?(window.localStorage.removeItem(o),[]):p.history}catch(s){return []}}function U(s){E("system",s);}function E(s,p,_){return W(ge(s,p,_,n.locale))}let Y=window.setInterval(()=>{i.body.querySelectorAll(".nexor-chat__msg-time[data-ts]").forEach(s=>{let p=Number(s.dataset.ts);p&&(s.textContent=G(p,n.locale));});},6e4);function W(s){return i.body.appendChild(s),J(),s}function J(){i.body.scrollTop=i.body.scrollHeight;}function ye(){a.unread++,d.badge.textContent=String(a.unread),d.badge.style.display="flex";}function _e(){a.unread=0,d.badge.style.display="none";}function V(){let s=!a.captured;i.input.disabled=s,i.send.disabled=s,i.input.placeholder=s?"Complete the form above to start\u2026":"Type a message\u2026";}return {open:f,close:C,toggle:I,send:s=>(h(s),Promise.resolve()),destroy:()=>{l.timer&&window.clearTimeout(l.timer),l.typingTimer&&window.clearTimeout(l.typingTimer),window.clearInterval(Y),c.remove();},getSessionId:()=>r}}function Be(){if(typeof window=="undefined"||typeof document=="undefined")throw new Error("Nexor SDK: initChat() requires a browser environment.")}function Fe(e){let t=document.createElement("div");return t.className="nexor-chat",t.setAttribute("data-position",e.position),t.setAttribute("data-open","false"),t}function ze(e){let t={},n=e.captureInputs;return n.first_name&&(t.first_name=n.first_name.value.trim()),n.last_name&&(t.last_name=n.last_name.value.trim()),n.email&&(t.email=n.email.value.trim()),n.phone&&(t.phone=n.phone.value.trim()),t}function Ke(e){return new N(e)}var H=null;function x(){if(!H)throw new Error("Nexor SDK: call `nexor.init({ apiKey })` before using the API.");return H}function je(e){return H=new N(e),H}function Ge(){return H!==null}function Ye(){H=null;}var m={init:je,isInitialized:Ge,reset:Ye,createLead:((...e)=>x().createLead(...e)),createLeadsBulk:((...e)=>x().createLeadsBulk(...e)),updateLead:((...e)=>x().updateLead(...e)),getLead:((...e)=>x().getLead(...e)),getLeadHistory:((...e)=>x().getLeadHistory(...e)),isLeadPaused:((...e)=>x().isLeadPaused(...e)),stopAutomation:((...e)=>x().stopAutomation(...e)),resumeAutomation:((...e)=>x().resumeAutomation(...e)),syncLeadTags:((...e)=>x().syncLeadTags(...e)),listLeadMeetings:((...e)=>x().listLeadMeetings(...e)),listWorkflows:((...e)=>x().listWorkflows(...e)),listCampaigns:((...e)=>x().listCampaigns(...e)),listTemplates:((...e)=>x().listTemplates(...e)),sendMessage:((...e)=>x().sendMessage(...e)),createMeeting:((...e)=>x().createMeeting(...e)),createMeetingNotes:((...e)=>x().createMeetingNotes(...e)),initChat:e=>be(x(),e)};var gt=m.init,xt=m.isInitialized,bt=m.reset,yt=m.initChat,_t=m.createLead,wt=m.createLeadsBulk,Ct=m.updateLead,vt=m.getLead,Lt=m.getLeadHistory,Tt=m.isLeadPaused,It=m.stopAutomation,Et=m.resumeAutomation,Rt=m.syncLeadTags,kt=m.listLeadMeetings,Mt=m.listWorkflows,Nt=m.listCampaigns,Pt=m.listTemplates,St=m.sendMessage,Ot=m.createMeeting,Ht=m.createMeetingNotes;exports.NexorAPIError=w;exports.NexorAuthError=S;exports.NexorClient=N;exports.NexorError=P;exports.NexorNetworkError=M;exports.NexorValidationError=O;exports.createClient=Ke;exports.createLead=_t;exports.createLeadsBulk=wt;exports.createMeeting=Ot;exports.createMeetingNotes=Ht;exports.getLead=vt;exports.getLeadHistory=Lt;exports.init=gt;exports.initChat=yt;exports.isInitialized=xt;exports.isLeadPaused=Tt;exports.listCampaigns=Nt;exports.listLeadMeetings=kt;exports.listTemplates=Pt;exports.listWorkflows=Mt;exports.reset=bt;exports.resumeAutomation=Et;exports.sendMessage=St;exports.stopAutomation=It;exports.syncLeadTags=Rt;exports.updateLead=Ct;return exports;})({});//# sourceMappingURL=nexor.iife.js.map
426
+ //# sourceMappingURL=nexor.iife.js.map