@docgenlab.com/chat-widget 0.4.2 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,48 +1,57 @@
1
- import { createRoot as $e } from "react-dom/client";
1
+ import { createRoot as Oe } from "react-dom/client";
2
2
  import * as e from "react";
3
- import { useRef as j, useState as f, useEffect as T, useCallback as be, createElement as Ee } from "react";
4
- const S = "/api/v1/public/kb", ye = "dgl-visitor-id";
5
- function ve() {
3
+ import { useRef as j, useState as p, useEffect as T, useCallback as ye, createElement as ve } from "react";
4
+ const I = "/api/v1/public/kb", Ne = "dgl-visitor-id";
5
+ function we() {
6
6
  const t = globalThis.crypto;
7
7
  return t && typeof t.randomUUID == "function" ? t.randomUUID() : "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (n) => {
8
- const i = Math.random() * 16 | 0;
9
- return (n === "x" ? i : i & 3 | 8).toString(16);
8
+ const r = Math.random() * 16 | 0;
9
+ return (n === "x" ? r : r & 3 | 8).toString(16);
10
10
  });
11
11
  }
12
- function Se() {
12
+ function Be() {
13
13
  try {
14
- let t = localStorage.getItem(ye);
15
- return t || (t = ve(), localStorage.setItem(ye, t)), t;
14
+ let t = localStorage.getItem(Ne);
15
+ return t || (t = we(), localStorage.setItem(Ne, t)), t;
16
16
  } catch (t) {
17
- return ve();
17
+ return we();
18
18
  }
19
19
  }
20
- class Te {
20
+ class Ae {
21
21
  constructor(n) {
22
- this.agentKey = n.agentKey, this.baseUrl = n.apiBaseUrl.replace(/\/+$/, ""), this.visitorId = n.endUserId ? `user:${n.endUserId}` : Se(), this.endUserHash = n.endUserHash;
22
+ this.agentKey = n.agentKey, this.baseUrl = n.apiBaseUrl.replace(/\/+$/, ""), this.visitorId = n.endUserId ? `user:${n.endUserId}` : Be(), this.endUserHash = n.endUserHash;
23
23
  }
24
24
  headers(n) {
25
- const i = {
25
+ const r = {
26
26
  "X-DocGenLab-Key": this.agentKey,
27
27
  "X-DocGenLab-Visitor-Id": this.visitorId,
28
28
  ...n || {}
29
29
  };
30
- return this.endUserHash && (i["X-DocGenLab-User-Hash"] = this.endUserHash), i;
30
+ return this.endUserHash && (r["X-DocGenLab-User-Hash"] = this.endUserHash), r;
31
31
  }
32
32
  async getAgent() {
33
- const n = await fetch(`${this.baseUrl}${S}/agent`, {
33
+ const n = await fetch(`${this.baseUrl}${I}/agent`, {
34
34
  method: "GET",
35
35
  headers: this.headers()
36
36
  });
37
37
  if (!n.ok) throw new Error(`getAgent failed: ${n.status}`);
38
38
  return n.json();
39
39
  }
40
+ /** List all conversations this visitor has had with this agent.
41
+ * Used by the "All chats" modal to let users browse + jump back
42
+ * to previous threads. Lightweight payload — message bodies are
43
+ * fetched on demand via getConversation when the user opens one. */
44
+ async listConversations() {
45
+ const n = `${this.baseUrl}${I}/conversations`, r = await fetch(n, { headers: this.headers() });
46
+ if (!r.ok) throw new Error(`listConversations failed: ${r.status}`);
47
+ return r.json();
48
+ }
40
49
  /** Load a previous conversation's messages so the widget can show
41
50
  * history after a refresh / re-open. The visitor-id header is the
42
51
  * authorization — the backend only returns conversations owned by
43
52
  * the requesting visitor on this agent. */
44
53
  async getConversation(n) {
45
- const i = `${this.baseUrl}${S}/conversations/${encodeURIComponent(n)}`, l = await fetch(i, { headers: this.headers() });
54
+ const r = `${this.baseUrl}${I}/conversations/${encodeURIComponent(n)}`, l = await fetch(r, { headers: this.headers() });
46
55
  if (!l.ok) throw new Error(`getConversation failed: ${l.status}`);
47
56
  return l.json();
48
57
  }
@@ -51,25 +60,25 @@ class Te {
51
60
  * raise-ticket / "already on it" / created cards after refresh.
52
61
  * Returns kind=null when nothing should show. */
53
62
  async getTicketCardState(n) {
54
- const i = `${this.baseUrl}${S}/conversations/${encodeURIComponent(n)}/ticket-card`, l = await fetch(i, { headers: this.headers() });
63
+ const r = `${this.baseUrl}${I}/conversations/${encodeURIComponent(n)}/ticket-card`, l = await fetch(r, { headers: this.headers() });
55
64
  if (!l.ok) throw new Error(`getTicketCardState failed: ${l.status}`);
56
65
  return l.json();
57
66
  }
58
67
  async uploadImage(n) {
59
- const i = new FormData();
60
- i.append("file", n);
61
- const l = await fetch(`${this.baseUrl}${S}/chat-image`, {
68
+ const r = new FormData();
69
+ r.append("file", n);
70
+ const l = await fetch(`${this.baseUrl}${I}/chat-image`, {
62
71
  method: "POST",
63
72
  headers: this.headers(),
64
73
  // browser sets Content-Type for FormData
65
- body: i
74
+ body: r
66
75
  });
67
76
  if (!l.ok) {
68
77
  let o = `${l.status} ${l.statusText}`;
69
78
  try {
70
- const s = await l.json();
71
- o = (s == null ? void 0 : s.detail) || o;
72
- } catch (s) {
79
+ const c = await l.json();
80
+ o = (c == null ? void 0 : c.detail) || o;
81
+ } catch (c) {
73
82
  }
74
83
  throw new Error(o);
75
84
  }
@@ -78,7 +87,7 @@ class Te {
78
87
  /** Fetch a previously-uploaded image as a blob URL. Caller must
79
88
  * URL.revokeObjectURL() when done to avoid memory leaks. */
80
89
  async fetchImage(n) {
81
- const i = `${this.baseUrl}${S}/chat-image?path=${encodeURIComponent(n)}&key=${encodeURIComponent(this.agentKey)}`, l = await fetch(i, {
90
+ const r = `${this.baseUrl}${I}/chat-image?path=${encodeURIComponent(n)}&key=${encodeURIComponent(this.agentKey)}`, l = await fetch(r, {
82
91
  method: "GET",
83
92
  headers: { "X-DocGenLab-Visitor-Id": this.visitorId }
84
93
  });
@@ -89,8 +98,8 @@ class Te {
89
98
  /** Raise a support ticket from a conversation. Requires explicit user
90
99
  * consent — the widget only calls this after the user clicks the
91
100
  * in-chat "Raise a ticket" chip. */
92
- async raiseTicket(n, i) {
93
- const l = `${this.baseUrl}${S}/conversations/${encodeURIComponent(n)}/raise-ticket`, a = await fetch(l, {
101
+ async raiseTicket(n, r) {
102
+ const l = `${this.baseUrl}${I}/conversations/${encodeURIComponent(n)}/raise-ticket`, a = await fetch(l, {
94
103
  method: "POST",
95
104
  headers: {
96
105
  "Content-Type": "application/json",
@@ -98,13 +107,13 @@ class Te {
98
107
  "X-DocGenLab-Visitor-Id": this.visitorId,
99
108
  ...this.endUserHash ? { "X-DocGenLab-User-Hash": this.endUserHash } : {}
100
109
  },
101
- body: JSON.stringify(i)
110
+ body: JSON.stringify(r)
102
111
  });
103
112
  if (!a.ok) {
104
113
  let o = `raiseTicket failed: ${a.status}`;
105
114
  try {
106
115
  o = (await a.json()).detail || o;
107
- } catch (s) {
116
+ } catch (c) {
108
117
  }
109
118
  throw new Error(o);
110
119
  }
@@ -114,7 +123,7 @@ class Te {
114
123
  * to hydrate ticket cards on conversation reload and to power the
115
124
  * "Manage tickets" modal. Optionally filtered by conversation. */
116
125
  async listTickets(n) {
117
- const i = n ? `?conversation_id=${encodeURIComponent(n)}` : "", l = `${this.baseUrl}${S}/tickets${i}`, a = await fetch(l, {
126
+ const r = n ? `?conversation_id=${encodeURIComponent(n)}` : "", l = `${this.baseUrl}${I}/tickets${r}`, a = await fetch(l, {
118
127
  headers: {
119
128
  "X-DocGenLab-Key": this.agentKey,
120
129
  "X-DocGenLab-Visitor-Id": this.visitorId
@@ -124,8 +133,8 @@ class Te {
124
133
  return a.json();
125
134
  }
126
135
  /** Fetch the latest status of a ticket the user raised. */
127
- async getTicket(n, i = !1) {
128
- const l = `${this.baseUrl}${S}/tickets/${encodeURIComponent(n)}${i ? "?refresh=1" : ""}`, a = await fetch(l, {
136
+ async getTicket(n, r = !1) {
137
+ const l = `${this.baseUrl}${I}/tickets/${encodeURIComponent(n)}${r ? "?refresh=1" : ""}`, a = await fetch(l, {
129
138
  headers: {
130
139
  "X-DocGenLab-Key": this.agentKey,
131
140
  "X-DocGenLab-Visitor-Id": this.visitorId
@@ -136,8 +145,8 @@ class Te {
136
145
  }
137
146
  /** Fetch a video-source frame attached to a citation chunk.
138
147
  * Same auth pattern as fetchImage. */
139
- async fetchSourceFrame(n, i) {
140
- const l = `${this.baseUrl}${S}/sources/${encodeURIComponent(n)}/frame?path=${encodeURIComponent(i)}&key=${encodeURIComponent(this.agentKey)}`, a = await fetch(l, {
148
+ async fetchSourceFrame(n, r) {
149
+ const l = `${this.baseUrl}${I}/sources/${encodeURIComponent(n)}/frame?path=${encodeURIComponent(r)}&key=${encodeURIComponent(this.agentKey)}`, a = await fetch(l, {
141
150
  method: "GET",
142
151
  headers: { "X-DocGenLab-Visitor-Id": this.visitorId }
143
152
  });
@@ -147,54 +156,54 @@ class Te {
147
156
  }
148
157
  /** Stream a chat response via SSE. Returns an abort fn the caller invokes
149
158
  * to cancel the stream. */
150
- streamChat(n, i) {
159
+ streamChat(n, r) {
151
160
  const l = new AbortController();
152
161
  return (async () => {
153
162
  try {
154
- const a = await fetch(`${this.baseUrl}${S}/chat`, {
163
+ const a = await fetch(`${this.baseUrl}${I}/chat`, {
155
164
  method: "POST",
156
165
  signal: l.signal,
157
166
  headers: this.headers({ "Content-Type": "application/json", Accept: "text/event-stream" }),
158
167
  body: JSON.stringify(n)
159
168
  });
160
169
  if (!a.ok || !a.body) {
161
- let d = `${a.status} ${a.statusText}`;
170
+ let u = `${a.status} ${a.statusText}`;
162
171
  try {
163
- const h = await a.json();
164
- d = (h == null ? void 0 : h.detail) || d;
165
- } catch (h) {
172
+ const E = await a.json();
173
+ u = (E == null ? void 0 : E.detail) || u;
174
+ } catch (E) {
166
175
  }
167
- i({ type: "error", error: d });
176
+ r({ type: "error", error: u });
168
177
  return;
169
178
  }
170
- const o = a.body.getReader(), s = new TextDecoder();
171
- let r = "";
179
+ const o = a.body.getReader(), c = new TextDecoder();
180
+ let i = "";
172
181
  for (; ; ) {
173
- const { value: d, done: h } = await o.read();
174
- if (h) break;
175
- r += s.decode(d, { stream: !0 });
176
- let w;
177
- for (; (w = r.indexOf(`
182
+ const { value: u, done: E } = await o.read();
183
+ if (E) break;
184
+ i += c.decode(u, { stream: !0 });
185
+ let x;
186
+ for (; (x = i.indexOf(`
178
187
 
179
188
  `)) !== -1; ) {
180
- const y = r.slice(0, w);
181
- r = r.slice(w + 2);
182
- const k = y.trim();
183
- if (k.startsWith("data:"))
189
+ const N = i.slice(0, x);
190
+ i = i.slice(x + 2);
191
+ const y = N.trim();
192
+ if (y.startsWith("data:"))
184
193
  try {
185
- const L = JSON.parse(k.slice(5).trim());
186
- i(L);
187
- } catch (L) {
194
+ const $ = JSON.parse(y.slice(5).trim());
195
+ r($);
196
+ } catch ($) {
188
197
  }
189
198
  }
190
199
  }
191
200
  } catch (a) {
192
- (a == null ? void 0 : a.name) !== "AbortError" && i({ type: "error", error: (a == null ? void 0 : a.message) || String(a) });
201
+ (a == null ? void 0 : a.name) !== "AbortError" && r({ type: "error", error: (a == null ? void 0 : a.message) || String(a) });
193
202
  }
194
203
  })(), () => l.abort();
195
204
  }
196
205
  }
197
- const F = {
206
+ const xe = "0.5.1", F = {
198
207
  apiBaseUrl: "https://api.docgenlab.com",
199
208
  position: "bottom-right",
200
209
  primary: "#4F46E5",
@@ -204,238 +213,254 @@ const F = {
204
213
  greeting: "How can I help you today?",
205
214
  greetingSub: "Ask anything about your uploaded documents. I'll only answer from what's in the knowledge base."
206
215
  };
207
- function le(t) {
208
- var de, me, ge, ue, he, fe, pe, ke;
209
- const n = t.apiBaseUrl || F.apiBaseUrl, i = t.enableImageUpload !== !1, l = j(null), a = `${t.agentKey}::${t.endUserId || ""}::${t.endUserHash || ""}`, o = j("");
210
- (!l.current || o.current !== a) && (l.current = new Te({
216
+ function re(t) {
217
+ var ue, ge, he, fe, pe, ke, Ee, be;
218
+ const n = t.apiBaseUrl || F.apiBaseUrl, r = t.enableImageUpload !== !1, l = j(null), a = `${t.agentKey}::${t.endUserId || ""}::${t.endUserHash || ""}`, o = j("");
219
+ (!l.current || o.current !== a) && (l.current = new Ae({
211
220
  agentKey: t.agentKey,
212
221
  apiBaseUrl: n,
213
222
  endUserId: t.endUserId,
214
223
  endUserHash: t.endUserHash
215
224
  }), o.current = a);
216
- const s = l.current, [r, d] = f(null), [h, w] = f(null), y = (r == null ? void 0 : r.widget_config) || {}, k = {
217
- position: t.position || y.position || F.position,
218
- primary: ((de = t.theme) == null ? void 0 : de.primary) || y.primary_color || F.primary,
219
- primaryText: ((me = t.theme) == null ? void 0 : me.primaryText) || y.primary_text_color || F.primaryText,
220
- radius: ((ge = t.theme) == null ? void 0 : ge.radius) || y.radius || F.radius,
221
- fontFamily: ((ue = t.theme) == null ? void 0 : ue.fontFamily) || F.fontFamily,
222
- greeting: t.greeting || y.greeting || F.greeting,
223
- agentName: t.agentName || y.agent_name || (r == null ? void 0 : r.name) || "Assistant",
224
- agentAvatarUrl: t.agentAvatarUrl || y.agent_avatar_url || void 0,
225
- launcherAvatarUrl: y.launcher_avatar_url || void 0,
226
- hideBranding: (fe = (he = t.hideBranding) != null ? he : y.hide_branding) != null ? fe : !1,
227
- openOnLoad: (ke = (pe = t.openOnLoad) != null ? pe : y.open_on_load) != null ? ke : !1
228
- }, L = {
229
- "--dgl-primary": k.primary,
230
- "--dgl-primary-text": k.primaryText,
231
- "--dgl-radius": k.radius,
232
- "--dgl-font": k.fontFamily
233
- }, [_, R] = f(k.openOnLoad), [C, P] = f(!1), [E, I] = f([]), [W, q] = f(""), [D, G] = f(!1), [K, J] = f(null), [re, Q] = f(null), [$, Z] = f(null), [H, ee] = f(!1), ie = j(null), te = j(null), X = j(""), V = j(null), [ae, ne] = f([]), [Ue, se] = f(!1);
225
+ const c = l.current, [i, u] = p(null), [E, x] = p(null), N = (i == null ? void 0 : i.widget_config) || {}, y = {
226
+ position: t.position || N.position || F.position,
227
+ primary: ((ue = t.theme) == null ? void 0 : ue.primary) || N.primary_color || F.primary,
228
+ primaryText: ((ge = t.theme) == null ? void 0 : ge.primaryText) || N.primary_text_color || F.primaryText,
229
+ radius: ((he = t.theme) == null ? void 0 : he.radius) || N.radius || F.radius,
230
+ fontFamily: ((fe = t.theme) == null ? void 0 : fe.fontFamily) || F.fontFamily,
231
+ greeting: t.greeting || N.greeting || F.greeting,
232
+ agentName: t.agentName || N.agent_name || (i == null ? void 0 : i.name) || "Assistant",
233
+ agentAvatarUrl: t.agentAvatarUrl || N.agent_avatar_url || void 0,
234
+ launcherAvatarUrl: N.launcher_avatar_url || void 0,
235
+ hideBranding: (ke = (pe = t.hideBranding) != null ? pe : N.hide_branding) != null ? ke : !1,
236
+ openOnLoad: (be = (Ee = t.openOnLoad) != null ? Ee : N.open_on_load) != null ? be : !1
237
+ }, $ = {
238
+ "--dgl-primary": y.primary,
239
+ "--dgl-primary-text": y.primaryText,
240
+ "--dgl-radius": y.radius,
241
+ "--dgl-font": y.fontFamily
242
+ }, [_, R] = p(y.openOnLoad), [U, K] = p(!1), [v, L] = p([]), [G, J] = p(""), [P, H] = p(!1), [O, V] = p(null), [se, Q] = p(null), [S, Z] = p(null), [X, ee] = p(!1), ce = j(null), te = j(null), Y = j(""), z = j(null), [ae, ne] = p([]), [Le, oe] = p(!1), [$e, le] = p(!1), [Ie, Se] = p([]);
234
243
  T(() => {
235
- !_ || r || s.getAgent().then((m) => {
236
- var b;
237
- d(m), (b = t.onReady) == null || b.call(t, m);
238
- }).catch((m) => {
239
- var b;
240
- w(m.message), (b = t.onError) == null || b.call(t, m.message);
244
+ !_ || i || c.getAgent().then((d) => {
245
+ var h;
246
+ u(d), (h = t.onReady) == null || h.call(t, d);
247
+ }).catch((d) => {
248
+ var h;
249
+ x(d.message), (h = t.onError) == null || h.call(t, d.message);
241
250
  });
242
- }, [_, r, s, t]), T(() => {
251
+ }, [_, i, c, t]), T(() => {
243
252
  if (!_ || t.disableTicketing) return;
244
- let m = !1;
245
- return s.listTickets().then((b) => {
246
- m || ne(b);
253
+ let d = !1;
254
+ return c.listTickets().then((h) => {
255
+ d || ne(h);
247
256
  }).catch(() => {
248
257
  }), () => {
249
- m = !0;
258
+ d = !0;
250
259
  };
251
- }, [_, s, t.disableTicketing]), T(() => {
260
+ }, [_, c, t.disableTicketing]), T(() => {
252
261
  if (!_) return;
253
- const m = `dgl-chat:${t.agentKey}`, b = localStorage.getItem(m);
254
- if (!b) return;
255
- let x = !1;
262
+ const d = `dgl-chat:${t.agentKey}`, h = localStorage.getItem(d);
263
+ if (!h) return;
264
+ let g = !1;
256
265
  return (async () => {
257
266
  try {
258
- const [v, p] = await Promise.all([
259
- s.getConversation(b),
260
- s.getTicketCardState(b).catch(() => null)
267
+ const [b, m] = await Promise.all([
268
+ c.getConversation(h),
269
+ c.getTicketCardState(h).catch(() => null)
261
270
  ]);
262
- if (x) return;
263
- const c = [];
264
- for (const U of v.messages || [])
265
- U.role === "user" ? c.push({
266
- id: U.id,
271
+ if (g) return;
272
+ const s = [];
273
+ for (const C of b.messages || [])
274
+ C.role === "user" ? s.push({
275
+ id: C.id,
267
276
  role: "user",
268
- content: U.content || "",
269
- imagePath: U.image_path || void 0
270
- }) : U.role === "assistant" && c.push({
271
- id: U.id,
277
+ content: C.content || "",
278
+ imagePath: C.image_path || void 0
279
+ }) : C.role === "assistant" && s.push({
280
+ id: C.id,
272
281
  role: "assistant",
273
- content: U.content || "",
274
- citations: U.retrieved_chunks || void 0
282
+ content: C.content || "",
283
+ citations: C.retrieved_chunks || void 0
275
284
  });
276
- if (p && p.kind && c.length) {
277
- let U = -1;
278
- for (let g = c.length - 1; g >= 0; g--)
279
- if (c[g].role === "assistant") {
280
- U = g;
285
+ if (m && m.kind && s.length) {
286
+ let C = -1;
287
+ for (let f = s.length - 1; f >= 0; f--)
288
+ if (s[f].role === "assistant") {
289
+ C = f;
281
290
  break;
282
291
  }
283
- if (U >= 0) {
284
- const g = c[U];
285
- p.kind === "offer" && p.conversation_id && p.connector_type && p.connector_name ? g.ticketOffer = {
286
- conversationId: p.conversation_id,
287
- connectorType: p.connector_type,
288
- connectorName: p.connector_name
289
- } : p.kind === "existing" && p.ticket_id && p.status ? g.ticketExisting = {
290
- ticketId: p.ticket_id,
291
- externalNumber: p.external_ticket_number || null,
292
- externalUrl: p.external_url || null,
293
- status: p.status
294
- } : p.kind === "created" && p.ticket_id && (g.ticketCreated = {
295
- id: p.ticket_id,
296
- externalNumber: p.external_ticket_number || null,
297
- externalUrl: p.external_url || null
292
+ if (C >= 0) {
293
+ const f = s[C];
294
+ m.kind === "offer" && m.conversation_id && m.connector_type && m.connector_name ? f.ticketOffer = {
295
+ conversationId: m.conversation_id,
296
+ connectorType: m.connector_type,
297
+ connectorName: m.connector_name
298
+ } : m.kind === "existing" && m.ticket_id && m.status ? f.ticketExisting = {
299
+ ticketId: m.ticket_id,
300
+ externalNumber: m.external_ticket_number || null,
301
+ externalUrl: m.external_url || null,
302
+ status: m.status
303
+ } : m.kind === "created" && m.ticket_id && (f.ticketCreated = {
304
+ id: m.ticket_id,
305
+ externalNumber: m.external_ticket_number || null,
306
+ externalUrl: m.external_url || null
298
307
  });
299
308
  }
300
309
  }
301
- J(b), I(c);
302
- } catch (v) {
303
- localStorage.removeItem(m);
310
+ V(h), L(s);
311
+ } catch (b) {
312
+ localStorage.removeItem(d);
304
313
  }
305
314
  })(), () => {
306
- x = !0;
315
+ g = !0;
307
316
  };
308
- }, [t.agentKey, s, _]), T(() => {
309
- K && localStorage.setItem(`dgl-chat:${t.agentKey}`, K);
310
- }, [K, t.agentKey]), T(() => {
311
- V.current && (V.current.scrollTop = V.current.scrollHeight);
312
- }, [E]);
313
- const ce = be(() => {
314
- $ && URL.revokeObjectURL($), Q(null), Z(null);
315
- }, [$]), oe = be((m) => {
316
- if (!m.type.startsWith("image/")) return;
317
- const b = 10 * 1024 * 1024;
318
- m.size > b || ($ && URL.revokeObjectURL($), Q(m), Z(URL.createObjectURL(m)));
319
- }, [$]), Ce = async (m) => {
320
- var p;
321
- if (m.preventDefault(), !W.trim() || D || H) return;
322
- const b = W.trim();
323
- let x, v;
324
- if (re) {
317
+ }, [t.agentKey, c, _]), T(() => {
318
+ O && localStorage.setItem(`dgl-chat:${t.agentKey}`, O);
319
+ }, [O, t.agentKey]), T(() => {
320
+ z.current && (z.current.scrollTop = z.current.scrollHeight);
321
+ }, [v]);
322
+ const de = ye(() => {
323
+ S && URL.revokeObjectURL(S), Q(null), Z(null);
324
+ }, [S]), me = ye((d) => {
325
+ if (!d.type.startsWith("image/")) return;
326
+ const h = 10 * 1024 * 1024;
327
+ d.size > h || (S && URL.revokeObjectURL(S), Q(d), Z(URL.createObjectURL(d)));
328
+ }, [S]), Te = async (d) => {
329
+ var m;
330
+ if (d.preventDefault(), !G.trim() || P || X) return;
331
+ const h = G.trim();
332
+ let g, b;
333
+ if (se) {
325
334
  try {
326
- ee(!0), x = await s.uploadImage(re);
327
- } catch (c) {
328
- (p = t.onError) == null || p.call(t, (c == null ? void 0 : c.message) || "Image upload failed"), ee(!1);
335
+ ee(!0), g = await c.uploadImage(se);
336
+ } catch (s) {
337
+ (m = t.onError) == null || m.call(t, (s == null ? void 0 : s.message) || "Image upload failed"), ee(!1);
329
338
  return;
330
339
  }
331
- ee(!1), v = $ || void 0;
340
+ ee(!1), b = S || void 0;
332
341
  }
333
- q(""), X.current = "", I((c) => [
334
- ...c,
335
- { role: "user", content: b, imagePath: x, imagePreviewUrl: v },
342
+ J(""), Y.current = "", L((s) => [
343
+ ...s,
344
+ { role: "user", content: h, imagePath: g, imagePreviewUrl: b },
336
345
  { role: "assistant", content: "", streaming: !0 }
337
- ]), G(!0), Q(null), Z(null), te.current = s.streamChat(
338
- { message: b, conversation_id: K || void 0, image_path: x },
339
- (c) => {
340
- var U;
341
- if (c.type === "conversation")
342
- J(c.conversation_id);
343
- else if (c.type === "token") {
344
- X.current += c.content;
345
- const g = X.current;
346
- I((u) => u.map(
347
- (N, Ie) => Ie === u.length - 1 && N.role === "assistant" ? { ...N, content: g } : N
346
+ ]), H(!0), Q(null), Z(null), te.current = c.streamChat(
347
+ { message: h, conversation_id: O || void 0, image_path: g },
348
+ (s) => {
349
+ var C;
350
+ if (s.type === "conversation")
351
+ V(s.conversation_id);
352
+ else if (s.type === "token") {
353
+ Y.current += s.content;
354
+ const f = Y.current;
355
+ L((k) => k.map(
356
+ (w, Fe) => Fe === k.length - 1 && w.role === "assistant" ? { ...w, content: f } : w
348
357
  ));
349
- } else if (c.type === "citations")
350
- I((g) => g.map(
351
- (u, N) => N === g.length - 1 && u.role === "assistant" ? { ...u, citations: c.citations } : u
358
+ } else if (s.type === "citations")
359
+ L((f) => f.map(
360
+ (k, w) => w === f.length - 1 && k.role === "assistant" ? { ...k, citations: s.citations } : k
352
361
  ));
353
- else if (c.type === "refused")
354
- X.current = c.content, I((g) => g.map(
355
- (u, N) => N === g.length - 1 && u.role === "assistant" ? { ...u, content: c.content, refused: !0 } : u
362
+ else if (s.type === "refused")
363
+ Y.current = s.content, L((f) => f.map(
364
+ (k, w) => w === f.length - 1 && k.role === "assistant" ? { ...k, content: s.content, refused: !0 } : k
356
365
  ));
357
- else if (c.type === "ticket_offer") {
366
+ else if (s.type === "ticket_offer") {
358
367
  if (t.disableTicketing) return;
359
- I((g) => g.map(
360
- (u, N) => N === g.length - 1 && u.role === "assistant" ? {
361
- ...u,
368
+ L((f) => f.map(
369
+ (k, w) => w === f.length - 1 && k.role === "assistant" ? {
370
+ ...k,
362
371
  ticketOffer: {
363
- conversationId: c.conversation_id,
364
- connectorType: c.connector_type,
365
- connectorName: c.connector_name
372
+ conversationId: s.conversation_id,
373
+ connectorType: s.connector_type,
374
+ connectorName: s.connector_name
366
375
  }
367
- } : u
376
+ } : k
368
377
  ));
369
- } else if (c.type === "ticket_existing") {
378
+ } else if (s.type === "ticket_existing") {
370
379
  if (t.disableTicketing) return;
371
- I((g) => g.map(
372
- (u, N) => N === g.length - 1 && u.role === "assistant" ? {
373
- ...u,
380
+ L((f) => f.map(
381
+ (k, w) => w === f.length - 1 && k.role === "assistant" ? {
382
+ ...k,
374
383
  ticketExisting: {
375
- ticketId: c.ticket_id,
376
- externalNumber: c.external_ticket_number,
377
- externalUrl: c.external_url,
378
- status: c.status
384
+ ticketId: s.ticket_id,
385
+ externalNumber: s.external_ticket_number,
386
+ externalUrl: s.external_url,
387
+ status: s.status
379
388
  }
380
- } : u
389
+ } : k
381
390
  ));
382
- } else c.type === "ticket_status_card" ? I((g) => g.map(
383
- (u, N) => N === g.length - 1 && u.role === "assistant" ? {
384
- ...u,
391
+ } else s.type === "ticket_status_card" ? L((f) => f.map(
392
+ (k, w) => w === f.length - 1 && k.role === "assistant" ? {
393
+ ...k,
385
394
  ticketStatus: {
386
- ticketId: c.ticket_id,
387
- externalNumber: c.external_number,
388
- externalUrl: c.external_url,
389
- status: c.status,
390
- title: c.title,
391
- priority: c.priority,
392
- lastUpdate: c.last_update,
393
- assignedTo: c.assigned_to,
394
- createdAt: c.created_at
395
+ ticketId: s.ticket_id,
396
+ externalNumber: s.external_number,
397
+ externalUrl: s.external_url,
398
+ status: s.status,
399
+ title: s.title,
400
+ priority: s.priority,
401
+ lastUpdate: s.last_update,
402
+ assignedTo: s.assigned_to,
403
+ createdAt: s.created_at
395
404
  }
396
- } : u
397
- )) : c.type === "done" ? (I((g) => g.map(
398
- (u, N) => N === g.length - 1 && u.role === "assistant" ? { ...u, streaming: !1, id: c.message_id, cacheHit: c.cache_hit } : u
399
- )), G(!1)) : c.type === "error" && (I((g) => g.map(
400
- (u, N) => N === g.length - 1 && u.role === "assistant" ? { ...u, content: `Error: ${c.error}`, streaming: !1, refused: !0 } : u
401
- )), G(!1), (U = t.onError) == null || U.call(t, c.error));
405
+ } : k
406
+ )) : s.type === "done" ? (L((f) => f.map(
407
+ (k, w) => w === f.length - 1 && k.role === "assistant" ? { ...k, streaming: !1, id: s.message_id, cacheHit: s.cache_hit } : k
408
+ )), H(!1)) : s.type === "error" && (L((f) => f.map(
409
+ (k, w) => w === f.length - 1 && k.role === "assistant" ? { ...k, content: `Error: ${s.error}`, streaming: !1, refused: !0 } : k
410
+ )), H(!1), (C = t.onError) == null || C.call(t, s.error));
402
411
  }
403
412
  );
404
- }, Le = () => {
405
- te.current && te.current(), I([]), J(null), G(!1), localStorage.removeItem(`dgl-chat:${t.agentKey}`), ce();
413
+ }, Re = () => {
414
+ te.current && te.current(), L([]), V(null), H(!1), localStorage.removeItem(`dgl-chat:${t.agentKey}`), de();
406
415
  };
407
- return /* @__PURE__ */ e.createElement("div", { className: `dgl-root dgl-pos-${k.position}`, style: L }, _ && /* @__PURE__ */ e.createElement("div", { className: `dgl-panel ${C ? "dgl-panel-expanded" : ""}` }, /* @__PURE__ */ e.createElement("div", { className: "dgl-header" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-header-info" }, k.agentAvatarUrl ? /* @__PURE__ */ e.createElement("img", { src: k.agentAvatarUrl, alt: "", className: "dgl-avatar" }) : /* @__PURE__ */ e.createElement("div", { className: "dgl-avatar dgl-avatar-fallback dgl-avatar-fallback-light" }, k.agentName.slice(0, 1).toUpperCase()), /* @__PURE__ */ e.createElement("div", { className: "dgl-header-text" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-title" }, k.agentName), (r == null ? void 0 : r.org_name) && /* @__PURE__ */ e.createElement("div", { className: "dgl-subtitle" }, r.org_name))), /* @__PURE__ */ e.createElement("div", { className: "dgl-header-actions" }, !t.disableTicketing && ae.length > 0 && /* @__PURE__ */ e.createElement(
416
+ return /* @__PURE__ */ e.createElement("div", { className: `dgl-root dgl-pos-${y.position}`, style: $ }, _ && /* @__PURE__ */ e.createElement("div", { className: `dgl-panel ${U ? "dgl-panel-expanded" : ""}` }, /* @__PURE__ */ e.createElement("div", { className: "dgl-header" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-header-info" }, y.agentAvatarUrl ? /* @__PURE__ */ e.createElement("img", { src: y.agentAvatarUrl, alt: "", className: "dgl-avatar" }) : /* @__PURE__ */ e.createElement("div", { className: "dgl-avatar dgl-avatar-fallback dgl-avatar-fallback-light" }, y.agentName.slice(0, 1).toUpperCase()), /* @__PURE__ */ e.createElement("div", { className: "dgl-header-text" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-title" }, y.agentName), (i == null ? void 0 : i.org_name) && /* @__PURE__ */ e.createElement("div", { className: "dgl-subtitle" }, i.org_name))), /* @__PURE__ */ e.createElement("div", { className: "dgl-header-actions" }, /* @__PURE__ */ e.createElement(
408
417
  "button",
409
418
  {
410
419
  type: "button",
411
- onClick: () => se(!0),
412
- className: "dgl-tix-btn",
420
+ onClick: async () => {
421
+ le(!0);
422
+ try {
423
+ const d = await c.listConversations();
424
+ Se(d);
425
+ } catch (d) {
426
+ }
427
+ },
428
+ className: "dgl-icon-btn",
429
+ title: "All chats",
430
+ "aria-label": "All chats"
431
+ },
432
+ ot()
433
+ ), !t.disableTicketing && /* @__PURE__ */ e.createElement(
434
+ "button",
435
+ {
436
+ type: "button",
437
+ onClick: () => oe(!0),
438
+ className: "dgl-icon-btn dgl-icon-btn-with-badge",
413
439
  title: "Your tickets",
414
440
  "aria-label": "Your tickets"
415
441
  },
416
- M(),
417
- /* @__PURE__ */ e.createElement("span", null, "Tickets"),
418
- /* @__PURE__ */ e.createElement("span", { className: "dgl-tix-btn-badge" }, ae.length)
442
+ D(),
443
+ ae.length > 0 && /* @__PURE__ */ e.createElement("span", { className: "dgl-icon-badge" }, ae.length)
419
444
  ), /* @__PURE__ */ e.createElement(
420
445
  "button",
421
446
  {
422
447
  type: "button",
423
- onClick: Le,
448
+ onClick: Re,
424
449
  className: "dgl-icon-btn",
425
450
  title: "New chat",
426
451
  "aria-label": "New chat"
427
452
  },
428
- Je()
453
+ nt()
429
454
  ), /* @__PURE__ */ e.createElement(
430
455
  "button",
431
456
  {
432
457
  type: "button",
433
- onClick: () => P((m) => !m),
458
+ onClick: () => K((d) => !d),
434
459
  className: "dgl-icon-btn dgl-hide-on-mobile",
435
- title: C ? "Restore size" : "Expand view",
436
- "aria-label": C ? "Restore size" : "Expand view"
460
+ title: U ? "Restore size" : "Expand view",
461
+ "aria-label": U ? "Restore size" : "Expand view"
437
462
  },
438
- C ? tt() : et()
463
+ U ? st() : it()
439
464
  ), /* @__PURE__ */ e.createElement(
440
465
  "button",
441
466
  {
@@ -445,102 +470,134 @@ function le(t) {
445
470
  title: "Close",
446
471
  "aria-label": "Close"
447
472
  },
448
- Y()
449
- ))), Ue && /* @__PURE__ */ e.createElement(
450
- Ve,
473
+ W()
474
+ ))), $e && /* @__PURE__ */ e.createElement(
475
+ Ze,
476
+ {
477
+ chats: Ie,
478
+ currentConvId: O,
479
+ onClose: () => le(!1),
480
+ onPick: async (d) => {
481
+ if (le(!1), d !== O)
482
+ try {
483
+ const [h, g] = await Promise.all([
484
+ c.getConversation(d),
485
+ c.getTicketCardState(d).catch(() => null)
486
+ ]), b = [];
487
+ for (const m of h.messages || [])
488
+ m.role === "user" ? b.push({ id: m.id, role: "user", content: m.content || "", imagePath: m.image_path || void 0 }) : m.role === "assistant" && b.push({ id: m.id, role: "assistant", content: m.content || "", citations: m.retrieved_chunks || void 0 });
489
+ if (g && g.kind && b.length) {
490
+ for (let m = b.length - 1; m >= 0; m--)
491
+ if (b[m].role === "assistant") {
492
+ const s = b[m];
493
+ g.kind === "offer" && g.conversation_id && g.connector_type && g.connector_name ? s.ticketOffer = { conversationId: g.conversation_id, connectorType: g.connector_type, connectorName: g.connector_name } : g.kind === "existing" && g.ticket_id && g.status ? s.ticketExisting = { ticketId: g.ticket_id, externalNumber: g.external_ticket_number || null, externalUrl: g.external_url || null, status: g.status } : g.kind === "created" && g.ticket_id && (s.ticketCreated = { id: g.ticket_id, externalNumber: g.external_ticket_number || null, externalUrl: g.external_url || null });
494
+ break;
495
+ }
496
+ }
497
+ V(d), L(b);
498
+ } catch (h) {
499
+ }
500
+ }
501
+ }
502
+ ), Le && /* @__PURE__ */ e.createElement(
503
+ Qe,
451
504
  {
452
505
  tickets: ae,
453
- onClose: () => se(!1),
506
+ onClose: () => oe(!1),
454
507
  onRefresh: async () => {
455
508
  try {
456
- const m = await s.listTickets();
457
- ne(m);
458
- } catch (m) {
509
+ const d = await c.listTickets(), h = /* @__PURE__ */ new Set(["open", "pending", "in_progress", "on_hold"]), g = d.filter((s) => h.has((s.status || "open").toLowerCase())), b = await Promise.all(
510
+ g.map((s) => c.getTicket(s.id, !0).catch(() => null))
511
+ ), m = /* @__PURE__ */ new Map();
512
+ b.forEach((s) => {
513
+ s && m.set(s.id, s);
514
+ }), ne(d.map((s) => m.get(s.id) || s));
515
+ } catch (d) {
459
516
  }
460
517
  }
461
518
  }
462
- ), /* @__PURE__ */ e.createElement("div", { className: "dgl-messages", ref: V }, E.length === 0 && !h && /* @__PURE__ */ e.createElement("div", { className: "dgl-empty" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-empty-icon" }, _e()), /* @__PURE__ */ e.createElement("div", { className: "dgl-empty-text" }, k.greeting), /* @__PURE__ */ e.createElement("div", { className: "dgl-empty-sub" }, (r == null ? void 0 : r.description) || F.greetingSub)), h && /* @__PURE__ */ e.createElement("div", { className: "dgl-error" }, "Couldn't load the assistant: ", h), E.map((m, b) => /* @__PURE__ */ e.createElement(
463
- Re,
519
+ ), /* @__PURE__ */ e.createElement("div", { className: "dgl-messages", ref: z }, v.length === 0 && !E && /* @__PURE__ */ e.createElement("div", { className: "dgl-empty" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-empty-icon" }, Ue()), /* @__PURE__ */ e.createElement("div", { className: "dgl-empty-text" }, y.greeting), /* @__PURE__ */ e.createElement("div", { className: "dgl-empty-sub" }, (i == null ? void 0 : i.description) || F.greetingSub)), E && /* @__PURE__ */ e.createElement("div", { className: "dgl-error" }, "Couldn't load the assistant: ", E), v.map((d, h) => /* @__PURE__ */ e.createElement(
520
+ Me,
464
521
  {
465
- key: b,
466
- message: m,
467
- client: s,
468
- isLast: b === E.length - 1,
469
- agentAvatarUrl: k.agentAvatarUrl,
470
- onPickFollowup: (x) => {
471
- q(x);
522
+ key: h,
523
+ message: d,
524
+ client: c,
525
+ isLast: h === v.length - 1,
526
+ agentAvatarUrl: y.agentAvatarUrl,
527
+ onPickFollowup: (g) => {
528
+ J(g);
472
529
  },
473
530
  defaultEmail: t.endUserEmail,
474
531
  defaultPhone: t.endUserPhone,
475
- conversationId: K || void 0,
476
- onTicketCreated: (x, v) => {
477
- I((p) => p.map((c) => c === x ? {
478
- ...c,
532
+ conversationId: O || void 0,
533
+ onTicketCreated: (g, b) => {
534
+ L((m) => m.map((s) => s === g ? {
535
+ ...s,
479
536
  // Either an existing-issue card OR a fresh offer
480
537
  // can land here — clear both, render created.
481
538
  ticketOffer: void 0,
482
539
  ticketExisting: void 0,
483
540
  ticketCreated: {
484
- id: v.id,
485
- externalNumber: v.external_ticket_number,
486
- externalUrl: v.external_url
541
+ id: b.id,
542
+ externalNumber: b.external_ticket_number,
543
+ externalUrl: b.external_url
487
544
  }
488
- } : c)), ne((p) => [v, ...p.filter((c) => c.id !== v.id)]);
545
+ } : s)), ne((m) => [b, ...m.filter((s) => s.id !== b.id)]);
489
546
  }
490
547
  }
491
- ))), /* @__PURE__ */ e.createElement("form", { className: "dgl-composer", onSubmit: Ce }, $ && /* @__PURE__ */ e.createElement("div", { className: "dgl-staged-image" }, /* @__PURE__ */ e.createElement("img", { src: $, alt: "attachment" }), /* @__PURE__ */ e.createElement(
548
+ ))), /* @__PURE__ */ e.createElement("form", { className: "dgl-composer", onSubmit: Te }, S && /* @__PURE__ */ e.createElement("div", { className: "dgl-staged-image" }, /* @__PURE__ */ e.createElement("img", { src: S, alt: "attachment" }), /* @__PURE__ */ e.createElement(
492
549
  "button",
493
550
  {
494
551
  type: "button",
495
- onClick: ce,
552
+ onClick: de,
496
553
  className: "dgl-staged-remove",
497
554
  "aria-label": "Remove image"
498
555
  },
499
- Y()
500
- )), /* @__PURE__ */ e.createElement("div", { className: "dgl-composer-row" }, i && /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement(
556
+ W()
557
+ )), /* @__PURE__ */ e.createElement("div", { className: "dgl-composer-row" }, r && /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement(
501
558
  "button",
502
559
  {
503
560
  type: "button",
504
561
  className: "dgl-icon-btn",
505
562
  onClick: () => {
506
- var m;
507
- return (m = ie.current) == null ? void 0 : m.click();
563
+ var d;
564
+ return (d = ce.current) == null ? void 0 : d.click();
508
565
  },
509
- disabled: D || H,
566
+ disabled: P || X,
510
567
  title: "Attach image",
511
568
  "aria-label": "Attach image"
512
569
  },
513
- Ze()
570
+ rt()
514
571
  ), /* @__PURE__ */ e.createElement(
515
572
  "input",
516
573
  {
517
- ref: ie,
574
+ ref: ce,
518
575
  type: "file",
519
576
  accept: "image/png,image/jpeg,image/webp,image/gif",
520
577
  style: { display: "none" },
521
- onChange: (m) => {
522
- var x;
523
- const b = (x = m.target.files) == null ? void 0 : x[0];
524
- b && oe(b), m.target && (m.target.value = "");
578
+ onChange: (d) => {
579
+ var g;
580
+ const h = (g = d.target.files) == null ? void 0 : g[0];
581
+ h && me(h), d.target && (d.target.value = "");
525
582
  }
526
583
  }
527
584
  )), /* @__PURE__ */ e.createElement(
528
585
  "input",
529
586
  {
530
587
  className: "dgl-input",
531
- value: W,
532
- onChange: (m) => q(m.target.value),
533
- placeholder: D ? "Thinking…" : $ ? "Describe what to know about this image…" : "Type your question…",
534
- disabled: D,
535
- onPaste: (m) => {
536
- var x;
537
- if (!i) return;
538
- const b = Array.from(((x = m.clipboardData) == null ? void 0 : x.items) || []).find(
539
- (v) => v.kind === "file" && v.type.startsWith("image/")
588
+ value: G,
589
+ onChange: (d) => J(d.target.value),
590
+ placeholder: P ? "Thinking…" : S ? "Describe what to know about this image…" : "Type your question…",
591
+ disabled: P,
592
+ onPaste: (d) => {
593
+ var g;
594
+ if (!r) return;
595
+ const h = Array.from(((g = d.clipboardData) == null ? void 0 : g.items) || []).find(
596
+ (b) => b.kind === "file" && b.type.startsWith("image/")
540
597
  );
541
- if (b) {
542
- const v = b.getAsFile();
543
- v && (m.preventDefault(), oe(v));
598
+ if (h) {
599
+ const b = h.getAsFile();
600
+ b && (d.preventDefault(), me(b));
544
601
  }
545
602
  }
546
603
  }
@@ -549,105 +606,105 @@ function le(t) {
549
606
  {
550
607
  type: "submit",
551
608
  className: "dgl-send-btn",
552
- disabled: !W.trim() || D || H,
609
+ disabled: !G.trim() || P || X,
553
610
  "aria-label": "Send"
554
611
  },
555
- D || H ? z() : Qe()
556
- )), !k.hideBranding && /* @__PURE__ */ e.createElement("div", { className: "dgl-branding" }, "Powered by ", /* @__PURE__ */ e.createElement("a", { href: "https://docgenlab.com", target: "_blank", rel: "noopener noreferrer" }, "DocGenLab")))), /* @__PURE__ */ e.createElement(
612
+ P || X ? q() : lt()
613
+ )), !y.hideBranding && /* @__PURE__ */ e.createElement("div", { className: "dgl-branding" }, "Powered by ", /* @__PURE__ */ e.createElement("a", { href: "https://docgenlab.com", target: "_blank", rel: "noopener noreferrer" }, "DocGenLab"), /* @__PURE__ */ e.createElement("span", { className: "dgl-branding-version", title: `Widget version ${xe}` }, "v", xe)))), /* @__PURE__ */ e.createElement(
557
614
  "button",
558
615
  {
559
616
  type: "button",
560
617
  className: "dgl-launcher",
561
- onClick: () => R((m) => !m),
618
+ onClick: () => R((d) => !d),
562
619
  "aria-label": _ ? "Close chat" : "Open chat"
563
620
  },
564
- _ ? qe() : k.launcherAvatarUrl ? /* @__PURE__ */ e.createElement("img", { src: k.launcherAvatarUrl, alt: "", className: "dgl-launcher-avatar" }) : ze()
621
+ _ ? at() : y.launcherAvatarUrl ? /* @__PURE__ */ e.createElement("img", { src: y.launcherAvatarUrl, alt: "", className: "dgl-launcher-avatar" }) : tt()
565
622
  ));
566
623
  }
567
- function Re({
624
+ function Me({
568
625
  message: t,
569
626
  client: n,
570
- isLast: i,
627
+ isLast: r,
571
628
  agentAvatarUrl: l,
572
629
  onPickFollowup: a,
573
630
  defaultEmail: o,
574
- defaultPhone: s,
575
- conversationId: r,
576
- onTicketCreated: d
631
+ defaultPhone: c,
632
+ conversationId: i,
633
+ onTicketCreated: u
577
634
  }) {
578
- var y;
635
+ var N;
579
636
  if (t.role === "user")
580
- return /* @__PURE__ */ e.createElement("div", { className: "dgl-msg dgl-msg-user" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-bubble dgl-bubble-user" }, (t.imagePath || t.imagePreviewUrl) && /* @__PURE__ */ e.createElement(Be, { client: n, imagePath: t.imagePath, previewUrl: t.imagePreviewUrl }), t.content));
581
- const h = Me(t.content), w = t.streaming ? [] : je(t.content);
582
- return /* @__PURE__ */ e.createElement("div", { className: "dgl-msg dgl-msg-assistant" }, l ? /* @__PURE__ */ e.createElement("img", { src: l, className: "dgl-avatar", alt: "" }) : /* @__PURE__ */ e.createElement("div", { className: "dgl-avatar dgl-avatar-fallback" }, _e()), /* @__PURE__ */ e.createElement("div", { className: "dgl-msg-body" }, t.refused ? /* @__PURE__ */ e.createElement("div", { className: "dgl-refused" }, h) : t.ticketStatus ? (
637
+ return /* @__PURE__ */ e.createElement("div", { className: "dgl-msg dgl-msg-user" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-bubble dgl-bubble-user" }, (t.imagePath || t.imagePreviewUrl) && /* @__PURE__ */ e.createElement(je, { client: n, imagePath: t.imagePath, previewUrl: t.imagePreviewUrl }), t.content));
638
+ const E = He(t.content), x = t.streaming ? [] : Ge(t.content);
639
+ return /* @__PURE__ */ e.createElement("div", { className: "dgl-msg dgl-msg-assistant" }, l ? /* @__PURE__ */ e.createElement("img", { src: l, className: "dgl-avatar", alt: "" }) : /* @__PURE__ */ e.createElement("div", { className: "dgl-avatar dgl-avatar-fallback" }, Ue()), /* @__PURE__ */ e.createElement("div", { className: "dgl-msg-body" }, t.refused ? /* @__PURE__ */ e.createElement("div", { className: "dgl-refused" }, E) : t.ticketStatus ? (
583
640
  /* Status query — suppress the markdown body and render
584
641
  the rich Jira-style card on its own. */
585
- /* @__PURE__ */ e.createElement(Xe, { ticket: t.ticketStatus })
586
- ) : /* @__PURE__ */ e.createElement("div", { className: "dgl-assistant-text" }, t.streaming && !h ? /* @__PURE__ */ e.createElement(Ke, null) : /* @__PURE__ */ e.createElement(e.Fragment, null, Pe(h), t.streaming && /* @__PURE__ */ e.createElement("span", { className: "dgl-typing-cursor" }, "▍"))), !t.streaming && !t.refused && !!((y = t.citations) != null && y.length) && !t.ticketStatus && /* @__PURE__ */ e.createElement(Oe, { citations: t.citations, client: n }), !t.streaming && !t.ticketStatus && t.ticketCreated ? /* @__PURE__ */ e.createElement(Ge, { created: t.ticketCreated }) : !t.streaming && !t.ticketStatus && t.ticketExisting ? /* @__PURE__ */ e.createElement(
587
- He,
642
+ /* @__PURE__ */ e.createElement(Je, { ticket: t.ticketStatus })
643
+ ) : /* @__PURE__ */ e.createElement("div", { className: "dgl-assistant-text" }, t.streaming && !E ? /* @__PURE__ */ e.createElement(Xe, null) : /* @__PURE__ */ e.createElement(e.Fragment, null, Ve(E), t.streaming && /* @__PURE__ */ e.createElement("span", { className: "dgl-typing-cursor" }, "▍"))), !t.streaming && !t.refused && !!((N = t.citations) != null && N.length) && !t.ticketStatus && /* @__PURE__ */ e.createElement(De, { citations: t.citations, client: n }), !t.streaming && !t.ticketStatus && t.ticketCreated ? /* @__PURE__ */ e.createElement(ze, { created: t.ticketCreated }) : !t.streaming && !t.ticketStatus && t.ticketExisting ? /* @__PURE__ */ e.createElement(
644
+ qe,
588
645
  {
589
646
  existing: t.ticketExisting,
590
647
  client: n,
591
- conversationId: r,
648
+ conversationId: i,
592
649
  defaultEmail: o,
593
- defaultPhone: s,
594
- onNewTicketRaised: (k) => d == null ? void 0 : d(t, k)
650
+ defaultPhone: c,
651
+ onNewTicketRaised: (y) => u == null ? void 0 : u(t, y)
595
652
  }
596
653
  ) : !t.streaming && !t.ticketStatus && t.ticketOffer ? /* @__PURE__ */ e.createElement(
597
- We,
654
+ Ye,
598
655
  {
599
656
  client: n,
600
657
  offer: t.ticketOffer,
601
658
  defaultEmail: o,
602
- defaultPhone: s,
603
- onCreated: (k) => d == null ? void 0 : d(t, k)
659
+ defaultPhone: c,
660
+ onCreated: (y) => u == null ? void 0 : u(t, y)
604
661
  }
605
- ) : null, w.length > 0 && /* @__PURE__ */ e.createElement(Fe, { suggestions: w, onPick: a })));
662
+ ) : null, x.length > 0 && /* @__PURE__ */ e.createElement(Pe, { suggestions: x, onPick: a })));
606
663
  }
607
- function Fe({
664
+ function Pe({
608
665
  suggestions: t,
609
666
  onPick: n
610
667
  }) {
611
- return /* @__PURE__ */ e.createElement("div", { className: "dgl-followups" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-followups-label" }, "Continue exploring"), /* @__PURE__ */ e.createElement("div", { className: "dgl-followups-list" }, t.map((i, l) => /* @__PURE__ */ e.createElement(
668
+ return /* @__PURE__ */ e.createElement("div", { className: "dgl-followups" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-followups-label" }, "Continue exploring"), /* @__PURE__ */ e.createElement("div", { className: "dgl-followups-list" }, t.map((r, l) => /* @__PURE__ */ e.createElement(
612
669
  "button",
613
670
  {
614
671
  key: l,
615
672
  type: "button",
616
673
  className: "dgl-followup-chip",
617
- onClick: () => n(i)
674
+ onClick: () => n(r)
618
675
  },
619
- i
676
+ r
620
677
  ))));
621
678
  }
622
- function Be({
679
+ function je({
623
680
  client: t,
624
681
  imagePath: n,
625
- previewUrl: i
682
+ previewUrl: r
626
683
  }) {
627
- const [l, a] = f(i || null), [o, s] = f(!1);
684
+ const [l, a] = p(r || null), [o, c] = p(!1);
628
685
  return T(() => {
629
- if (i || !n) return;
630
- let r = null;
631
- return t.fetchImage(n).then((d) => {
632
- r = d, a(d);
686
+ if (r || !n) return;
687
+ let i = null;
688
+ return t.fetchImage(n).then((u) => {
689
+ i = u, a(u);
633
690
  }).catch(() => a(null)), () => {
634
- r && URL.revokeObjectURL(r);
691
+ i && URL.revokeObjectURL(i);
635
692
  };
636
- }, [t, n, i]), T(() => {
693
+ }, [t, n, r]), T(() => {
637
694
  if (!o) return;
638
- const r = (h) => {
639
- h.key === "Escape" && s(!1);
695
+ const i = (E) => {
696
+ E.key === "Escape" && c(!1);
640
697
  };
641
- window.addEventListener("keydown", r);
642
- const d = document.body.style.overflow;
698
+ window.addEventListener("keydown", i);
699
+ const u = document.body.style.overflow;
643
700
  return document.body.style.overflow = "hidden", () => {
644
- window.removeEventListener("keydown", r), document.body.style.overflow = d;
701
+ window.removeEventListener("keydown", i), document.body.style.overflow = u;
645
702
  };
646
703
  }, [o]), l ? /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement(
647
704
  "button",
648
705
  {
649
706
  type: "button",
650
- onClick: () => s(!0),
707
+ onClick: () => c(!0),
651
708
  className: "dgl-user-image-btn",
652
709
  "aria-label": "View image"
653
710
  },
@@ -658,19 +715,19 @@ function Be({
658
715
  className: "dgl-lightbox",
659
716
  role: "dialog",
660
717
  "aria-modal": "true",
661
- onClick: () => s(!1)
718
+ onClick: () => c(!1)
662
719
  },
663
720
  /* @__PURE__ */ e.createElement(
664
721
  "button",
665
722
  {
666
723
  type: "button",
667
724
  className: "dgl-lightbox-close",
668
- onClick: (r) => {
669
- r.stopPropagation(), s(!1);
725
+ onClick: (i) => {
726
+ i.stopPropagation(), c(!1);
670
727
  },
671
728
  "aria-label": "Close image"
672
729
  },
673
- Y()
730
+ W()
674
731
  ),
675
732
  /* @__PURE__ */ e.createElement(
676
733
  "img",
@@ -678,98 +735,98 @@ function Be({
678
735
  src: l,
679
736
  className: "dgl-lightbox-img",
680
737
  alt: "attached",
681
- onClick: (r) => r.stopPropagation()
738
+ onClick: (i) => i.stopPropagation()
682
739
  }
683
740
  )
684
741
  )) : null;
685
742
  }
686
- function Oe({ citations: t, client: n }) {
687
- const i = {};
688
- for (const r of t) {
689
- const d = i[r.source_id];
690
- (!d || r.score > d.score) && (i[r.source_id] = r);
743
+ function De({ citations: t, client: n }) {
744
+ const r = {};
745
+ for (const i of t) {
746
+ const u = r[i.source_id];
747
+ (!u || i.score > u.score) && (r[i.source_id] = i);
691
748
  }
692
- const l = Object.values(i).sort((r, d) => d.score - r.score).slice(0, 3), a = Object.keys(i).length - l.length;
749
+ const l = Object.values(r).sort((i, u) => u.score - i.score).slice(0, 3), a = Object.keys(r).length - l.length;
693
750
  if (!l.length) return null;
694
- const [o, s] = f(null);
695
- return /* @__PURE__ */ e.createElement("div", { className: "dgl-citations" }, l.map((r) => /* @__PURE__ */ e.createElement(
696
- Ae,
751
+ const [o, c] = p(null);
752
+ return /* @__PURE__ */ e.createElement("div", { className: "dgl-citations" }, l.map((i) => /* @__PURE__ */ e.createElement(
753
+ Ke,
697
754
  {
698
- key: r.chunk_id,
699
- citation: r,
755
+ key: i.chunk_id,
756
+ citation: i,
700
757
  client: n,
701
- isOpen: o === r.chunk_id,
702
- onToggle: () => s(o === r.chunk_id ? null : r.chunk_id)
758
+ isOpen: o === i.chunk_id,
759
+ onToggle: () => c(o === i.chunk_id ? null : i.chunk_id)
703
760
  }
704
761
  )), a > 0 && /* @__PURE__ */ e.createElement("span", { className: "dgl-citation-more" }, "+", a, " more"));
705
762
  }
706
- function Ae({
763
+ function Ke({
707
764
  citation: t,
708
765
  client: n,
709
- isOpen: i,
766
+ isOpen: r,
710
767
  onToggle: l
711
768
  }) {
712
- const a = t, o = !!a.frame_path, s = a.heading ? `${a.heading}${a.subheading ? " › " + a.subheading : ""}` : null, r = a.start_seconds != null ? `${Math.floor(a.start_seconds / 60)}:${String(a.start_seconds % 60).padStart(2, "0")}` : null;
769
+ const a = t, o = !!a.frame_path, c = a.heading ? `${a.heading}${a.subheading ? " › " + a.subheading : ""}` : null, i = a.start_seconds != null ? `${Math.floor(a.start_seconds / 60)}:${String(a.start_seconds % 60).padStart(2, "0")}` : null;
713
770
  return /* @__PURE__ */ e.createElement("span", { className: "dgl-citation-wrap" }, /* @__PURE__ */ e.createElement(
714
771
  "button",
715
772
  {
716
773
  type: "button",
717
- className: `dgl-citation ${i ? "dgl-citation-open" : ""}`,
774
+ className: `dgl-citation ${r ? "dgl-citation-open" : ""}`,
718
775
  onClick: l,
719
776
  title: a.snippet || ""
720
777
  },
721
778
  o && /* @__PURE__ */ e.createElement("span", { className: "dgl-citation-icon" }, "▶"),
722
779
  a.source_name,
723
- r && /* @__PURE__ */ e.createElement("span", { className: "dgl-citation-stamp" }, " · ", r),
780
+ i && /* @__PURE__ */ e.createElement("span", { className: "dgl-citation-stamp" }, " · ", i),
724
781
  a.page && /* @__PURE__ */ e.createElement("span", { className: "dgl-citation-stamp" }, " · p", a.page)
725
- ), i && /* @__PURE__ */ e.createElement("div", { className: "dgl-citation-popover" }, a.frame_path && /* @__PURE__ */ e.createElement(
726
- De,
782
+ ), r && /* @__PURE__ */ e.createElement("div", { className: "dgl-citation-popover" }, a.frame_path && /* @__PURE__ */ e.createElement(
783
+ We,
727
784
  {
728
785
  client: n,
729
786
  sourceId: a.source_id,
730
787
  framePath: a.frame_path
731
788
  }
732
- ), s && /* @__PURE__ */ e.createElement("div", { className: "dgl-citation-breadcrumb" }, s), a.snippet && /* @__PURE__ */ e.createElement("div", { className: "dgl-citation-snippet" }, a.snippet)));
789
+ ), c && /* @__PURE__ */ e.createElement("div", { className: "dgl-citation-breadcrumb" }, c), a.snippet && /* @__PURE__ */ e.createElement("div", { className: "dgl-citation-snippet" }, a.snippet)));
733
790
  }
734
- function De({
791
+ function We({
735
792
  client: t,
736
793
  sourceId: n,
737
- framePath: i
794
+ framePath: r
738
795
  }) {
739
- const [l, a] = f(null);
796
+ const [l, a] = p(null);
740
797
  return T(() => {
741
798
  let o = null;
742
- return t.fetchSourceFrame(n, i).then((s) => {
743
- o = s, a(s);
799
+ return t.fetchSourceFrame(n, r).then((c) => {
800
+ o = c, a(c);
744
801
  }).catch(() => a(null)), () => {
745
802
  o && URL.revokeObjectURL(o);
746
803
  };
747
- }, [t, n, i]), l ? /* @__PURE__ */ e.createElement("a", { href: l, target: "_blank", rel: "noopener noreferrer", className: "dgl-citation-frame-link" }, /* @__PURE__ */ e.createElement("img", { src: l, alt: "", className: "dgl-citation-frame" })) : /* @__PURE__ */ e.createElement("div", { className: "dgl-citation-frame-loading" });
804
+ }, [t, n, r]), l ? /* @__PURE__ */ e.createElement("a", { href: l, target: "_blank", rel: "noopener noreferrer", className: "dgl-citation-frame-link" }, /* @__PURE__ */ e.createElement("img", { src: l, alt: "", className: "dgl-citation-frame" })) : /* @__PURE__ */ e.createElement("div", { className: "dgl-citation-frame-loading" });
748
805
  }
749
- function je(t) {
806
+ function Ge(t) {
750
807
  const n = t.match(/<followups>([\s\S]*?)<\/followups>/i);
751
808
  return n ? n[1].split(`
752
- `).map((i) => i.trim()).map((i) => i.replace(/^[-*•\d.)\s"']+|["']$/g, "").trim()).filter((i) => i.length >= 4 && i.length <= 120).slice(0, 3) : [];
809
+ `).map((r) => r.trim()).map((r) => r.replace(/^[-*•\d.)\s"']+|["']$/g, "").trim()).filter((r) => r.length >= 4 && r.length <= 120).slice(0, 3) : [];
753
810
  }
754
- function Me(t) {
755
- const n = /\s*I\s+(don'?t|do not)\s+have\s+(?:specific|enough|that|the|any)?\s*information\s+on\s+(?:this|that)[^.]*?\.(?:\s*Please\s+(?:contact|reach\s*out\s+to)\s+(?:your\s+)?(?:support|admin)[^.]*?\.)?/gi, i = /\n*<followups>[\s\S]*?(<\/followups>|$)/gi, l = t.replace(i, ""), a = l.replace(n, "").trim();
811
+ function He(t) {
812
+ const n = /\s*I\s+(don'?t|do not)\s+have\s+(?:specific|enough|that|the|any)?\s*information\s+on\s+(?:this|that)[^.]*?\.(?:\s*Please\s+(?:contact|reach\s*out\s+to)\s+(?:your\s+)?(?:support|admin)[^.]*?\.)?/gi, r = /\n*<followups>[\s\S]*?(<\/followups>|$)/gi, l = t.replace(r, ""), a = l.replace(n, "").trim();
756
813
  return (l.trim().length > 0 && a.length < 20 ? t : t.replace(n, "")).replace(/\n*<followups>[\s\S]*?(<\/followups>|$)/gi, "").replace(/\s*\[\s*Section:[^\]]*\]?/gi, "").replace(/\s*\[\s*doc:[^\]]*\]?/gi, "").replace(/\s*\[\s*(?:document|doc|source|ref|reference)[^\]]*\]?/gi, "").replace(/\s*\[\s*(?:p\.?\s*)?\d+(?:\s*[,–-]\s*\d+)*\s*\]/gi, "").replace(/[,;]?\s*doc:\s*[0-9a-fA-F][0-9a-fA-F-]{6,}\]?/gi, "").replace(/[,;]\s*(?:\d+|doc:?\s*[0-9a-fA-F-]+)\s*\]?/gi, "").replace(/([\w%])\s*\]/g, "$1").replace(/\s+([,.;:!?])/g, "$1").replace(/[ \t]+/g, " ").replace(/\n{3,}/g, `
757
814
 
758
815
  `).trim();
759
816
  }
760
- function Pe(t) {
761
- return t.split(/\n{2,}/).map((i, l) => {
762
- const a = i.split(`
817
+ function Ve(t) {
818
+ return t.split(/\n{2,}/).map((r, l) => {
819
+ const a = r.split(`
763
820
  `);
764
- if (a.every((s) => /^(\s*)([-*]|\d+\.)\s/.test(s)) && a.length > 0) {
765
- const s = /^\d+\./.test(a[0].trim()), r = a.map((h) => h.replace(/^\s*(?:[-*]|\d+\.)\s+/, "")), d = s ? "ol" : "ul";
766
- return /* @__PURE__ */ e.createElement(d, { key: l, className: `dgl-md-list ${s ? "dgl-md-ol" : "dgl-md-ul"}` }, r.map((h, w) => /* @__PURE__ */ e.createElement("li", { key: w }, Ne(h))));
821
+ if (a.every((c) => /^(\s*)([-*]|\d+\.)\s/.test(c)) && a.length > 0) {
822
+ const c = /^\d+\./.test(a[0].trim()), i = a.map((E) => E.replace(/^\s*(?:[-*]|\d+\.)\s+/, "")), u = c ? "ol" : "ul";
823
+ return /* @__PURE__ */ e.createElement(u, { key: l, className: `dgl-md-list ${c ? "dgl-md-ol" : "dgl-md-ul"}` }, i.map((E, x) => /* @__PURE__ */ e.createElement("li", { key: x }, _e(E))));
767
824
  }
768
- return /* @__PURE__ */ e.createElement("p", { key: l, className: "dgl-md-p" }, i.split(`
769
- `).map((s, r, d) => /* @__PURE__ */ e.createElement(e.Fragment, { key: r }, Ne(s), r < d.length - 1 && /* @__PURE__ */ e.createElement("br", null))));
825
+ return /* @__PURE__ */ e.createElement("p", { key: l, className: "dgl-md-p" }, r.split(`
826
+ `).map((c, i, u) => /* @__PURE__ */ e.createElement(e.Fragment, { key: i }, _e(c), i < u.length - 1 && /* @__PURE__ */ e.createElement("br", null))));
770
827
  });
771
828
  }
772
- function Ne(t) {
829
+ function _e(t) {
773
830
  const n = /(`[^`]+`|\*\*[^*\n]+\*\*|\*[^*\n]+\*|\[[^\]]+\]\([^)]+\))/g;
774
831
  return t.split(n).map((l, a) => {
775
832
  if (!l) return null;
@@ -783,27 +840,27 @@ function Ne(t) {
783
840
  return o ? /* @__PURE__ */ e.createElement("a", { key: a, href: o[2], target: "_blank", rel: "noopener noreferrer", className: "dgl-md-link" }, o[1]) : /* @__PURE__ */ e.createElement(e.Fragment, { key: a }, l);
784
841
  });
785
842
  }
786
- function Ke() {
843
+ function Xe() {
787
844
  return /* @__PURE__ */ e.createElement("span", { className: "dgl-thinking" }, /* @__PURE__ */ e.createElement("span", { className: "dgl-thinking-dot" }), /* @__PURE__ */ e.createElement("span", { className: "dgl-thinking-dot" }), /* @__PURE__ */ e.createElement("span", { className: "dgl-thinking-dot" }));
788
845
  }
789
- const A = {
846
+ const M = {
790
847
  open: { label: "Open", stripe: "linear-gradient(90deg,#3b82f6,#6366f1)", iconBg: "#3b82f6", pillBg: "#dbeafe", pillFg: "#1e40af" },
791
848
  in_progress: { label: "In progress", stripe: "linear-gradient(90deg,#8b5cf6,#d946ef)", iconBg: "#8b5cf6", pillBg: "#ede9fe", pillFg: "#5b21b6" },
792
849
  on_hold: { label: "On hold", stripe: "linear-gradient(90deg,#f59e0b,#f97316)", iconBg: "#f59e0b", pillBg: "#fef3c7", pillFg: "#92400e" },
793
850
  resolved: { label: "Resolved", stripe: "linear-gradient(90deg,#10b981,#14b8a6)", iconBg: "#10b981", pillBg: "#d1fae5", pillFg: "#065f46" },
794
851
  closed: { label: "Closed", stripe: "linear-gradient(90deg,#94a3b8,#64748b)", iconBg: "#64748b", pillBg: "#f1f5f9", pillFg: "#334155" },
795
852
  cancelled: { label: "Cancelled", stripe: "linear-gradient(90deg,#ef4444,#f43f5e)", iconBg: "#ef4444", pillBg: "#fee2e2", pillFg: "#991b1b" }
796
- }, we = {
853
+ }, Ce = {
797
854
  low: { bg: "#f1f5f9", fg: "#475569" },
798
855
  medium: { bg: "#dbeafe", fg: "#1e40af" },
799
856
  high: { bg: "#fef3c7", fg: "#92400e" },
800
857
  urgent: { bg: "#fee2e2", fg: "#991b1b" }
801
858
  };
802
- function xe(t) {
859
+ function ie(t) {
803
860
  if (!t) return "—";
804
- const n = new Date(t), i = Date.now() - n.getTime();
805
- if (Number.isNaN(i)) return t;
806
- const l = Math.floor(i / 6e4);
861
+ const n = new Date(t), r = Date.now() - n.getTime();
862
+ if (Number.isNaN(r)) return t;
863
+ const l = Math.floor(r / 6e4);
807
864
  if (l < 1) return "just now";
808
865
  if (l < 60) return `${l}m ago`;
809
866
  const a = Math.floor(l / 60);
@@ -811,41 +868,41 @@ function xe(t) {
811
868
  const o = Math.floor(a / 24);
812
869
  return o < 7 ? `${o}d ago` : n.toLocaleDateString();
813
870
  }
814
- function We({
871
+ function Ye({
815
872
  client: t,
816
873
  offer: n,
817
- defaultEmail: i,
874
+ defaultEmail: r,
818
875
  defaultPhone: l,
819
876
  onCreated: a
820
877
  }) {
821
- const [o, s] = f(i || ""), [r, d] = f(l || ""), [h, w] = f(!i), [y, k] = f("medium"), [L, _] = f(!1), [R, C] = f(null), P = async () => {
878
+ const [o, c] = p(r || ""), [i, u] = p(l || ""), [E, x] = p(!r), [N, y] = p("medium"), [$, _] = p(!1), [R, U] = p(null), K = async () => {
822
879
  if (!o.trim()) {
823
- C("Email is required so the team can follow up.");
880
+ U("Email is required so the team can follow up.");
824
881
  return;
825
882
  }
826
- _(!0), C(null);
883
+ _(!0), U(null);
827
884
  try {
828
- const E = await t.raiseTicket(n.conversationId, {
885
+ const v = await t.raiseTicket(n.conversationId, {
829
886
  consent: !0,
830
887
  end_user_email: o.trim(),
831
- end_user_phone: r.trim() || void 0,
832
- priority: y
888
+ end_user_phone: i.trim() || void 0,
889
+ priority: N
833
890
  });
834
- a(E);
835
- } catch (E) {
836
- C((E == null ? void 0 : E.message) || "Could not create ticket. Try again.");
891
+ a(v);
892
+ } catch (v) {
893
+ U((v == null ? void 0 : v.message) || "Could not create ticket. Try again.");
837
894
  } finally {
838
895
  _(!1);
839
896
  }
840
897
  };
841
- return /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-stripe", style: { background: "linear-gradient(90deg,#6366f1,#8b5cf6)" } }), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-body" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-head" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-icon", style: { background: "linear-gradient(135deg,#6366f1,#8b5cf6,#ec4899)" } }, M()), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-titles" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-eyebrow" }, "Support escalation"), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-title" }, "Need a human to look at this?"))), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-desc" }, "We'll summarise this chat and raise a ticket. Our team will follow up on the email below."), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-form-grid" }, /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-field-label" }, "Reply to"), h ? /* @__PURE__ */ e.createElement(
898
+ return /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-stripe", style: { background: "linear-gradient(90deg,#6366f1,#8b5cf6)" } }), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-body" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-head" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-icon", style: { background: "linear-gradient(135deg,#6366f1,#8b5cf6,#ec4899)" } }, D()), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-titles" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-eyebrow" }, "Support escalation"), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-title" }, "Need a human to look at this?"))), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-desc" }, "We'll summarise this chat and raise a ticket. Our team will follow up on the email below."), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-form-grid" }, /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-field-label" }, "Reply to"), E ? /* @__PURE__ */ e.createElement(
842
899
  "input",
843
900
  {
844
901
  type: "email",
845
902
  className: "dgl-ticket-input",
846
903
  value: o,
847
- onChange: (E) => s(E.target.value),
848
- onBlur: () => o && w(!1),
904
+ onChange: (v) => c(v.target.value),
905
+ onBlur: () => o && x(!1),
849
906
  placeholder: "you@example.com",
850
907
  autoFocus: !0
851
908
  }
@@ -854,7 +911,7 @@ function We({
854
911
  {
855
912
  type: "button",
856
913
  className: "dgl-ticket-email-link",
857
- onClick: () => w(!0),
914
+ onClick: () => x(!0),
858
915
  title: "Click to change"
859
916
  },
860
917
  o || "Set email",
@@ -864,8 +921,8 @@ function We({
864
921
  "select",
865
922
  {
866
923
  className: "dgl-ticket-input",
867
- value: y,
868
- onChange: (E) => k(E.target.value)
924
+ value: N,
925
+ onChange: (v) => y(v.target.value)
869
926
  },
870
927
  /* @__PURE__ */ e.createElement("option", { value: "low" }, "Low"),
871
928
  /* @__PURE__ */ e.createElement("option", { value: "medium" }, "Medium"),
@@ -876,65 +933,65 @@ function We({
876
933
  {
877
934
  type: "button",
878
935
  className: "dgl-ticket-submit",
879
- onClick: P,
880
- disabled: L || !o.trim()
936
+ onClick: K,
937
+ disabled: $ || !o.trim()
881
938
  },
882
- L ? z() : M(),
883
- /* @__PURE__ */ e.createElement("span", null, L ? "Submitting…" : "Submit ticket")
939
+ $ ? q() : D(),
940
+ /* @__PURE__ */ e.createElement("span", null, $ ? "Submitting…" : "Submit ticket")
884
941
  ))));
885
942
  }
886
- function Ge({ created: t }) {
887
- const n = A.open;
888
- return /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-stripe", style: { background: "linear-gradient(90deg,#10b981,#14b8a6)" } }), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-body" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-head" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-icon", style: { background: "linear-gradient(135deg,#10b981,#14b8a6)" } }, Ye()), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-titles" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-eyebrow", style: { color: "#059669" } }, "Ticket created"), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-title" }, "#", t.externalNumber || t.id.slice(0, 8))), t.externalUrl && /* @__PURE__ */ e.createElement("a", { className: "dgl-ticket-open-btn", href: t.externalUrl, target: "_blank", rel: "noopener noreferrer" }, "Open")), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-pills" }, /* @__PURE__ */ e.createElement("span", { className: "dgl-ticket-pill", style: { background: n.pillBg, color: n.pillFg } }, /* @__PURE__ */ e.createElement("span", { className: "dgl-ticket-pill-dot", style: { background: n.iconBg } }), " Open")), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-desc" }, "Support team has been notified — they'll follow up directly on your email.")));
943
+ function ze({ created: t }) {
944
+ const n = M.open;
945
+ return /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-stripe", style: { background: "linear-gradient(90deg,#10b981,#14b8a6)" } }), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-body" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-head" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-icon", style: { background: "linear-gradient(135deg,#10b981,#14b8a6)" } }, et()), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-titles" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-eyebrow", style: { color: "#059669" } }, "Ticket created"), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-title" }, "#", t.externalNumber || t.id.slice(0, 8))), t.externalUrl && /* @__PURE__ */ e.createElement("a", { className: "dgl-ticket-open-btn", href: t.externalUrl, target: "_blank", rel: "noopener noreferrer" }, "Open")), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-pills" }, /* @__PURE__ */ e.createElement("span", { className: "dgl-ticket-pill", style: { background: n.pillBg, color: n.pillFg } }, /* @__PURE__ */ e.createElement("span", { className: "dgl-ticket-pill-dot", style: { background: n.iconBg } }), " Open")), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-desc" }, "Support team has been notified — they'll follow up directly on your email.")));
889
946
  }
890
- function He({
947
+ function qe({
891
948
  existing: t,
892
949
  client: n,
893
- conversationId: i,
950
+ conversationId: r,
894
951
  defaultEmail: l,
895
952
  defaultPhone: a,
896
953
  onNewTicketRaised: o
897
954
  }) {
898
- const s = A[t.status] || A.open, [r, d] = f(!1), [h, w] = f(l || ""), [y, k] = f("medium"), [L, _] = f(!1), [R, C] = f(null), P = async () => {
899
- if (!h.trim()) {
900
- C("Email is required so the team can follow up.");
955
+ const c = M[t.status] || M.open, [i, u] = p(!1), [E, x] = p(l || ""), [N, y] = p("medium"), [$, _] = p(!1), [R, U] = p(null), K = async () => {
956
+ if (!E.trim()) {
957
+ U("Email is required so the team can follow up.");
901
958
  return;
902
959
  }
903
- if (!i) {
904
- C("Conversation not available yet.");
960
+ if (!r) {
961
+ U("Conversation not available yet.");
905
962
  return;
906
963
  }
907
- _(!0), C(null);
964
+ _(!0), U(null);
908
965
  try {
909
- const E = await n.raiseTicket(i, {
966
+ const v = await n.raiseTicket(r, {
910
967
  consent: !0,
911
- end_user_email: h.trim(),
968
+ end_user_email: E.trim(),
912
969
  end_user_phone: a || void 0,
913
- priority: y,
970
+ priority: N,
914
971
  force_new: !0
915
972
  });
916
- o == null || o(E);
917
- } catch (E) {
918
- C((E == null ? void 0 : E.message) || "Could not create ticket. Try again.");
973
+ o == null || o(v);
974
+ } catch (v) {
975
+ U((v == null ? void 0 : v.message) || "Could not create ticket. Try again.");
919
976
  } finally {
920
977
  _(!1);
921
978
  }
922
979
  };
923
- return /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-stripe", style: { background: s.stripe } }), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-body" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-head" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-icon", style: { background: s.iconBg } }, M()), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-titles" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-eyebrow" }, "We're already on it"), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-title" }, "#", t.externalNumber || t.ticketId.slice(0, 8))), t.externalUrl && /* @__PURE__ */ e.createElement("a", { className: "dgl-ticket-open-btn", href: t.externalUrl, target: "_blank", rel: "noopener noreferrer" }, "Open")), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-pills" }, /* @__PURE__ */ e.createElement("span", { className: "dgl-ticket-pill", style: { background: s.pillBg, color: s.pillFg } }, /* @__PURE__ */ e.createElement("span", { className: "dgl-ticket-pill-dot", style: { background: s.iconBg } }), " ", s.label)), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-desc" }, "A ticket has already been raised for this conversation. Our team will follow up — no need to file another."), r ? /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-diff-form" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-field-label", style: { marginTop: 4 } }, "File a separate ticket for a new issue"), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-form-grid" }, /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-field-label" }, "Reply to"), /* @__PURE__ */ e.createElement(
980
+ return /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-stripe", style: { background: c.stripe } }), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-body" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-head" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-icon", style: { background: c.iconBg } }, D()), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-titles" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-eyebrow" }, "We're already on it"), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-title" }, "#", t.externalNumber || t.ticketId.slice(0, 8))), t.externalUrl && /* @__PURE__ */ e.createElement("a", { className: "dgl-ticket-open-btn", href: t.externalUrl, target: "_blank", rel: "noopener noreferrer" }, "Open")), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-pills" }, /* @__PURE__ */ e.createElement("span", { className: "dgl-ticket-pill", style: { background: c.pillBg, color: c.pillFg } }, /* @__PURE__ */ e.createElement("span", { className: "dgl-ticket-pill-dot", style: { background: c.iconBg } }), " ", c.label)), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-desc" }, "A ticket has already been raised for this conversation. Our team will follow up — no need to file another."), i ? /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-diff-form" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-field-label", style: { marginTop: 4 } }, "File a separate ticket for a new issue"), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-form-grid" }, /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-field-label" }, "Reply to"), /* @__PURE__ */ e.createElement(
924
981
  "input",
925
982
  {
926
983
  type: "email",
927
984
  className: "dgl-ticket-input",
928
- value: h,
929
- onChange: (E) => w(E.target.value),
985
+ value: E,
986
+ onChange: (v) => x(v.target.value),
930
987
  placeholder: "you@example.com"
931
988
  }
932
989
  )), /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-field-label" }, "Priority"), /* @__PURE__ */ e.createElement(
933
990
  "select",
934
991
  {
935
992
  className: "dgl-ticket-input",
936
- value: y,
937
- onChange: (E) => k(E.target.value)
993
+ value: N,
994
+ onChange: (v) => y(v.target.value)
938
995
  },
939
996
  /* @__PURE__ */ e.createElement("option", { value: "low" }, "Low"),
940
997
  /* @__PURE__ */ e.createElement("option", { value: "medium" }, "Medium"),
@@ -945,7 +1002,7 @@ function He({
945
1002
  {
946
1003
  type: "button",
947
1004
  className: "dgl-ticket-diff-cancel",
948
- onClick: () => d(!1)
1005
+ onClick: () => u(!1)
949
1006
  },
950
1007
  "Cancel"
951
1008
  ), /* @__PURE__ */ e.createElement(
@@ -953,51 +1010,51 @@ function He({
953
1010
  {
954
1011
  type: "button",
955
1012
  className: "dgl-ticket-submit",
956
- onClick: P,
957
- disabled: L || !h.trim()
1013
+ onClick: K,
1014
+ disabled: $ || !E.trim()
958
1015
  },
959
- L ? z() : M(),
960
- /* @__PURE__ */ e.createElement("span", null, L ? "Submitting…" : "Submit new ticket")
1016
+ $ ? q() : D(),
1017
+ /* @__PURE__ */ e.createElement("span", null, $ ? "Submitting…" : "Submit new ticket")
961
1018
  ))) : /* @__PURE__ */ e.createElement(
962
1019
  "button",
963
1020
  {
964
1021
  type: "button",
965
1022
  className: "dgl-ticket-diff-link",
966
- onClick: () => d(!0)
1023
+ onClick: () => u(!0)
967
1024
  },
968
1025
  "Different issue? Raise new ticket →"
969
1026
  )));
970
1027
  }
971
- function Xe({
1028
+ function Je({
972
1029
  ticket: t
973
1030
  }) {
974
- const n = A[t.status] || A.open, i = we[(t.priority || "medium").toLowerCase()] || we.medium;
975
- return /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-stripe", style: { background: n.stripe } }), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-body" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-head" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-icon", style: { background: n.iconBg } }, M()), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-titles" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-eyebrow" }, "Support ticket"), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-title" }, "#", t.externalNumber || t.ticketId.slice(0, 8))), t.externalUrl && /* @__PURE__ */ e.createElement("a", { className: "dgl-ticket-open-btn", href: t.externalUrl, target: "_blank", rel: "noopener noreferrer" }, "Open")), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-pills" }, /* @__PURE__ */ e.createElement("span", { className: "dgl-ticket-pill", style: { background: n.pillBg, color: n.pillFg } }, /* @__PURE__ */ e.createElement("span", { className: "dgl-ticket-pill-dot", style: { background: n.iconBg } }), " ", n.label), /* @__PURE__ */ e.createElement("span", { className: "dgl-ticket-pill", style: { background: i.bg, color: i.fg } }, t.priority || "medium", " priority")), t.title && /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-body-title" }, t.title), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-meta-grid" }, /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-meta-label" }, "Last update"), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-meta-value" }, xe(t.lastUpdate))), /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-meta-label" }, "Assigned to"), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-meta-value" }, t.assignedTo || "Unassigned")))));
1031
+ const n = M[t.status] || M.open, r = Ce[(t.priority || "medium").toLowerCase()] || Ce.medium;
1032
+ return /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-stripe", style: { background: n.stripe } }), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-body" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-head" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-icon", style: { background: n.iconBg } }, D()), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-titles" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-eyebrow" }, "Support ticket"), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-title" }, "#", t.externalNumber || t.ticketId.slice(0, 8))), t.externalUrl && /* @__PURE__ */ e.createElement("a", { className: "dgl-ticket-open-btn", href: t.externalUrl, target: "_blank", rel: "noopener noreferrer" }, "Open")), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-pills" }, /* @__PURE__ */ e.createElement("span", { className: "dgl-ticket-pill", style: { background: n.pillBg, color: n.pillFg } }, /* @__PURE__ */ e.createElement("span", { className: "dgl-ticket-pill-dot", style: { background: n.iconBg } }), " ", n.label), /* @__PURE__ */ e.createElement("span", { className: "dgl-ticket-pill", style: { background: r.bg, color: r.fg } }, t.priority || "medium", " priority")), t.title && /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-card-body-title" }, t.title), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-meta-grid" }, /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-meta-label" }, "Last update"), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-meta-value" }, ie(t.lastUpdate))), /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-meta-label" }, "Assigned to"), /* @__PURE__ */ e.createElement("div", { className: "dgl-ticket-meta-value" }, t.assignedTo || "Unassigned")))));
976
1033
  }
977
- function Ve({
1034
+ function Qe({
978
1035
  tickets: t,
979
1036
  onClose: n,
980
- onRefresh: i
1037
+ onRefresh: r
981
1038
  }) {
982
- const [l, a] = f(!1);
1039
+ const [l, a] = p(!1);
983
1040
  T(() => {
984
- const r = (d) => {
985
- d.key === "Escape" && n();
1041
+ const i = (u) => {
1042
+ u.key === "Escape" && n();
986
1043
  };
987
- return window.addEventListener("keydown", r), () => window.removeEventListener("keydown", r);
1044
+ return window.addEventListener("keydown", i), () => window.removeEventListener("keydown", i);
988
1045
  }, [n]);
989
1046
  const o = async () => {
990
1047
  a(!0);
991
1048
  try {
992
- await i();
1049
+ await r();
993
1050
  } finally {
994
1051
  a(!1);
995
1052
  }
996
- }, s = [...t].sort((r, d) => {
997
- const h = r.created_at ? new Date(r.created_at).getTime() : 0;
998
- return (d.created_at ? new Date(d.created_at).getTime() : 0) - h;
1053
+ }, c = [...t].sort((i, u) => {
1054
+ const E = i.created_at ? new Date(i.created_at).getTime() : 0;
1055
+ return (u.created_at ? new Date(u.created_at).getTime() : 0) - E;
999
1056
  });
1000
- return /* @__PURE__ */ e.createElement("div", { className: "dgl-tix-modal-backdrop", onClick: n }, /* @__PURE__ */ e.createElement("div", { className: "dgl-tix-modal", onClick: (r) => r.stopPropagation() }, /* @__PURE__ */ e.createElement("div", { className: "dgl-tix-modal-header" }, /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement("div", { className: "dgl-tix-modal-title" }, "Your tickets"), /* @__PURE__ */ e.createElement("div", { className: "dgl-tix-modal-sub" }, t.length === 0 ? "No tickets yet" : `${t.length} ticket${t.length === 1 ? "" : "s"} on this assistant`)), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: 4 } }, /* @__PURE__ */ e.createElement(
1057
+ return /* @__PURE__ */ e.createElement("div", { className: "dgl-tix-modal-backdrop", onClick: n }, /* @__PURE__ */ e.createElement("div", { className: "dgl-tix-modal", onClick: (i) => i.stopPropagation() }, /* @__PURE__ */ e.createElement("div", { className: "dgl-tix-modal-header" }, /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement("div", { className: "dgl-tix-modal-title" }, "Your tickets"), /* @__PURE__ */ e.createElement("div", { className: "dgl-tix-modal-sub" }, t.length === 0 ? "No tickets yet" : `${t.length} ticket${t.length === 1 ? "" : "s"} on this assistant`)), /* @__PURE__ */ e.createElement("div", { style: { display: "flex", gap: 4 } }, /* @__PURE__ */ e.createElement(
1001
1058
  "button",
1002
1059
  {
1003
1060
  type: "button",
@@ -1008,7 +1065,7 @@ function Ve({
1008
1065
  disabled: l,
1009
1066
  style: { color: "#475569" }
1010
1067
  },
1011
- l ? z() : at()
1068
+ l ? q() : ct()
1012
1069
  ), /* @__PURE__ */ e.createElement(
1013
1070
  "button",
1014
1071
  {
@@ -1019,86 +1076,127 @@ function Ve({
1019
1076
  "aria-label": "Close",
1020
1077
  style: { color: "#475569" }
1021
1078
  },
1022
- Y()
1023
- ))), /* @__PURE__ */ e.createElement("div", { className: "dgl-tix-modal-list" }, s.length === 0 ? /* @__PURE__ */ e.createElement("div", { className: "dgl-tix-empty" }, "You haven't raised any support tickets here yet. They'll show up here once you do.") : s.map((r) => {
1024
- const d = A[r.status] || A.open;
1025
- return /* @__PURE__ */ e.createElement("div", { key: r.id, className: "dgl-tix-row" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-tix-row-head" }, /* @__PURE__ */ e.createElement("span", { className: "dgl-tix-row-num" }, "#", r.external_ticket_number || r.id.slice(0, 8)), /* @__PURE__ */ e.createElement(
1079
+ W()
1080
+ ))), /* @__PURE__ */ e.createElement("div", { className: "dgl-tix-modal-list" }, c.length === 0 ? /* @__PURE__ */ e.createElement("div", { className: "dgl-tix-empty" }, "You haven't raised any support tickets here yet. They'll show up here once you do.") : c.map((i) => {
1081
+ const u = M[i.status] || M.open;
1082
+ return /* @__PURE__ */ e.createElement("div", { key: i.id, className: "dgl-tix-row" }, /* @__PURE__ */ e.createElement("div", { className: "dgl-tix-row-head" }, /* @__PURE__ */ e.createElement("span", { className: "dgl-tix-row-num" }, "#", i.external_ticket_number || i.id.slice(0, 8)), /* @__PURE__ */ e.createElement(
1026
1083
  "span",
1027
1084
  {
1028
1085
  className: "dgl-ticket-pill",
1029
- style: { background: d.pillBg, color: d.pillFg }
1086
+ style: { background: u.pillBg, color: u.pillFg }
1030
1087
  },
1031
- /* @__PURE__ */ e.createElement("span", { className: "dgl-ticket-pill-dot", style: { background: d.iconBg } }),
1032
- d.label
1033
- ), r.external_url && /* @__PURE__ */ e.createElement(
1088
+ /* @__PURE__ */ e.createElement("span", { className: "dgl-ticket-pill-dot", style: { background: u.iconBg } }),
1089
+ u.label
1090
+ ), i.external_url && /* @__PURE__ */ e.createElement(
1034
1091
  "a",
1035
1092
  {
1036
- href: r.external_url,
1093
+ href: i.external_url,
1037
1094
  target: "_blank",
1038
1095
  rel: "noopener noreferrer",
1039
1096
  className: "dgl-ticket-open-btn",
1040
1097
  style: { marginLeft: "auto" }
1041
1098
  },
1042
1099
  "Open"
1043
- )), r.title && /* @__PURE__ */ e.createElement("div", { className: "dgl-tix-row-title" }, r.title), /* @__PURE__ */ e.createElement("div", { className: "dgl-tix-row-meta" }, r.priority || "medium", " priority · raised ", xe(r.created_at)));
1100
+ )), i.title && /* @__PURE__ */ e.createElement("div", { className: "dgl-tix-row-title" }, i.title), /* @__PURE__ */ e.createElement("div", { className: "dgl-tix-row-meta" }, i.priority || "medium", " priority · raised ", ie(i.created_at)));
1044
1101
  }))));
1045
1102
  }
1046
- function M() {
1103
+ function Ze({
1104
+ chats: t,
1105
+ currentConvId: n,
1106
+ onClose: r,
1107
+ onPick: l
1108
+ }) {
1109
+ return T(() => {
1110
+ const a = (o) => {
1111
+ o.key === "Escape" && r();
1112
+ };
1113
+ return window.addEventListener("keydown", a), () => window.removeEventListener("keydown", a);
1114
+ }, [r]), /* @__PURE__ */ e.createElement("div", { className: "dgl-tix-modal-backdrop", onClick: r }, /* @__PURE__ */ e.createElement("div", { className: "dgl-tix-modal", onClick: (a) => a.stopPropagation() }, /* @__PURE__ */ e.createElement("div", { className: "dgl-tix-modal-header" }, /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement("div", { className: "dgl-tix-modal-title" }, "Your chats"), /* @__PURE__ */ e.createElement("div", { className: "dgl-tix-modal-sub" }, t.length === 0 ? "No conversations yet" : `${t.length} conversation${t.length === 1 ? "" : "s"}`)), /* @__PURE__ */ e.createElement(
1115
+ "button",
1116
+ {
1117
+ type: "button",
1118
+ onClick: r,
1119
+ className: "dgl-icon-btn",
1120
+ title: "Close",
1121
+ "aria-label": "Close",
1122
+ style: { color: "#475569" }
1123
+ },
1124
+ W()
1125
+ )), /* @__PURE__ */ e.createElement("div", { className: "dgl-tix-modal-list" }, t.length === 0 ? /* @__PURE__ */ e.createElement("div", { className: "dgl-tix-empty" }, "Your conversations with this assistant will show up here.") : t.map((a) => {
1126
+ const o = a.id === n, c = a.title || a.preview || `Conversation ${a.id.slice(0, 8)}`;
1127
+ return /* @__PURE__ */ e.createElement(
1128
+ "button",
1129
+ {
1130
+ key: a.id,
1131
+ type: "button",
1132
+ onClick: () => l(a.id),
1133
+ className: `dgl-chat-row${o ? " dgl-chat-row-current" : ""}`,
1134
+ title: o ? "Current conversation" : "Open this conversation"
1135
+ },
1136
+ /* @__PURE__ */ e.createElement("div", { className: "dgl-chat-row-title" }, c),
1137
+ /* @__PURE__ */ e.createElement("div", { className: "dgl-chat-row-meta" }, a.message_count, " message", a.message_count === 1 ? "" : "s", a.updated_at ? ` · ${ie(a.updated_at)}` : "", o ? " · current" : "")
1138
+ );
1139
+ }))));
1140
+ }
1141
+ function D() {
1047
1142
  return /* @__PURE__ */ e.createElement("svg", { viewBox: "0 0 24 24", width: "16", height: "16", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }, /* @__PURE__ */ e.createElement("circle", { cx: "12", cy: "12", r: "10" }), /* @__PURE__ */ e.createElement("circle", { cx: "12", cy: "12", r: "4" }), /* @__PURE__ */ e.createElement("path", { d: "M4.93 4.93l4.24 4.24M14.83 14.83l4.24 4.24M14.83 9.17l4.24-4.24M14.83 9.17l3.53-3.53M4.93 19.07l4.24-4.24" }));
1048
1143
  }
1049
- function Ye() {
1144
+ function et() {
1050
1145
  return /* @__PURE__ */ e.createElement("svg", { viewBox: "0 0 24 24", width: "16", height: "16", fill: "none", stroke: "white", strokeWidth: "3", strokeLinecap: "round", strokeLinejoin: "round" }, /* @__PURE__ */ e.createElement("path", { d: "M20 6L9 17l-5-5" }));
1051
1146
  }
1052
- function ze() {
1147
+ function tt() {
1053
1148
  return /* @__PURE__ */ e.createElement("svg", { viewBox: "0 0 24 24", width: "22", height: "22", fill: "currentColor" }, /* @__PURE__ */ e.createElement("path", { d: "M4 4h16a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H8l-4 4V6a2 2 0 0 1 2-2z" }));
1054
1149
  }
1055
- function qe() {
1150
+ function at() {
1056
1151
  return /* @__PURE__ */ e.createElement("svg", { viewBox: "0 0 24 24", width: "22", height: "22", fill: "none", stroke: "currentColor", strokeWidth: "2.5", strokeLinecap: "round", strokeLinejoin: "round" }, /* @__PURE__ */ e.createElement("polyline", { points: "6 9 12 15 18 9" }));
1057
1152
  }
1058
- function Y() {
1153
+ function W() {
1059
1154
  return /* @__PURE__ */ e.createElement("svg", { viewBox: "0 0 24 24", width: "16", height: "16", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }, /* @__PURE__ */ e.createElement("line", { x1: "18", y1: "6", x2: "6", y2: "18" }), /* @__PURE__ */ e.createElement("line", { x1: "6", y1: "6", x2: "18", y2: "18" }));
1060
1155
  }
1061
- function Je() {
1156
+ function nt() {
1062
1157
  return /* @__PURE__ */ e.createElement("svg", { viewBox: "0 0 24 24", width: "16", height: "16", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }, /* @__PURE__ */ e.createElement("line", { x1: "12", y1: "5", x2: "12", y2: "19" }), /* @__PURE__ */ e.createElement("line", { x1: "5", y1: "12", x2: "19", y2: "12" }));
1063
1158
  }
1064
- function Qe() {
1159
+ function lt() {
1065
1160
  return /* @__PURE__ */ e.createElement("svg", { viewBox: "0 0 24 24", width: "16", height: "16", fill: "currentColor" }, /* @__PURE__ */ e.createElement("path", { d: "M2 21l21-9L2 3v7l15 2-15 2z" }));
1066
1161
  }
1067
- function Ze() {
1162
+ function rt() {
1068
1163
  return /* @__PURE__ */ e.createElement("svg", { viewBox: "0 0 24 24", width: "18", height: "18", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }, /* @__PURE__ */ e.createElement("rect", { x: "3", y: "3", width: "18", height: "18", rx: "2" }), /* @__PURE__ */ e.createElement("circle", { cx: "8.5", cy: "8.5", r: "1.5" }), /* @__PURE__ */ e.createElement("polyline", { points: "21 15 16 10 5 21" }));
1069
1164
  }
1070
- function z() {
1165
+ function q() {
1071
1166
  return /* @__PURE__ */ e.createElement("svg", { viewBox: "0 0 24 24", width: "16", height: "16", className: "dgl-spin", fill: "none", stroke: "currentColor", strokeWidth: "3", strokeLinecap: "round" }, /* @__PURE__ */ e.createElement("path", { d: "M21 12a9 9 0 1 1-6.219-8.56" }));
1072
1167
  }
1073
- function et() {
1168
+ function it() {
1074
1169
  return /* @__PURE__ */ e.createElement("svg", { viewBox: "0 0 24 24", width: "14", height: "14", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }, /* @__PURE__ */ e.createElement("polyline", { points: "15 3 21 3 21 9" }), /* @__PURE__ */ e.createElement("polyline", { points: "9 21 3 21 3 15" }), /* @__PURE__ */ e.createElement("line", { x1: "21", y1: "3", x2: "14", y2: "10" }), /* @__PURE__ */ e.createElement("line", { x1: "3", y1: "21", x2: "10", y2: "14" }));
1075
1170
  }
1076
- function tt() {
1171
+ function st() {
1077
1172
  return /* @__PURE__ */ e.createElement("svg", { viewBox: "0 0 24 24", width: "14", height: "14", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }, /* @__PURE__ */ e.createElement("polyline", { points: "4 14 10 14 10 20" }), /* @__PURE__ */ e.createElement("polyline", { points: "20 10 14 10 14 4" }), /* @__PURE__ */ e.createElement("line", { x1: "14", y1: "10", x2: "21", y2: "3" }), /* @__PURE__ */ e.createElement("line", { x1: "3", y1: "21", x2: "10", y2: "14" }));
1078
1173
  }
1079
- function at() {
1174
+ function ct() {
1080
1175
  return /* @__PURE__ */ e.createElement("svg", { viewBox: "0 0 24 24", width: "14", height: "14", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }, /* @__PURE__ */ e.createElement("polyline", { points: "23 4 23 10 17 10" }), /* @__PURE__ */ e.createElement("polyline", { points: "1 20 1 14 7 14" }), /* @__PURE__ */ e.createElement("path", { d: "M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15" }));
1081
1176
  }
1082
- function _e() {
1177
+ function ot() {
1178
+ return /* @__PURE__ */ e.createElement("svg", { viewBox: "0 0 24 24", width: "16", height: "16", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }, /* @__PURE__ */ e.createElement("path", { d: "M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" }), /* @__PURE__ */ e.createElement("line", { x1: "7", y1: "9", x2: "17", y2: "9" }), /* @__PURE__ */ e.createElement("line", { x1: "7", y1: "13", x2: "13", y2: "13" }));
1179
+ }
1180
+ function Ue() {
1083
1181
  return /* @__PURE__ */ e.createElement("svg", { viewBox: "0 0 24 24", width: "14", height: "14", fill: "currentColor" }, /* @__PURE__ */ e.createElement("path", { d: "M12 2l2.39 6.95L21 11l-6.61 2.05L12 20l-2.39-6.95L3 11l6.61-2.05L12 2z" }));
1084
1182
  }
1085
- let B = null, O = null;
1086
- function nt(t) {
1183
+ let B = null, A = null;
1184
+ function dt(t) {
1087
1185
  if (typeof document == "undefined")
1088
1186
  throw new Error("DocGenLab.init() requires a browser environment.");
1089
1187
  if (B) {
1090
- B.render(Ee(le, t));
1188
+ B.render(ve(re, t));
1091
1189
  return;
1092
1190
  }
1093
- O = document.createElement("div"), O.id = "docgenlab-chat-widget-root", document.body.appendChild(O), B = $e(O), B.render(Ee(le, t));
1191
+ A = document.createElement("div"), A.id = "docgenlab-chat-widget-root", document.body.appendChild(A), B = Oe(A), B.render(ve(re, t));
1094
1192
  }
1095
- function lt() {
1096
- B && (B.unmount(), B = null), O && (O.remove(), O = null);
1193
+ function mt() {
1194
+ B && (B.unmount(), B = null), A && (A.remove(), A = null);
1097
1195
  }
1098
- typeof window != "undefined" && (window.DocGenLab = { init: nt, destroy: lt, DocGenLabChat: le });
1196
+ typeof window != "undefined" && (window.DocGenLab = { init: dt, destroy: mt, DocGenLabChat: re });
1099
1197
  export {
1100
- le as DocGenLabChat,
1101
- lt as destroy,
1102
- nt as init
1198
+ re as DocGenLabChat,
1199
+ mt as destroy,
1200
+ dt as init
1103
1201
  };
1104
1202
  //# sourceMappingURL=index.js.map