vpschatbotwidget 1.0.3 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist-lib/types/App.d.ts +1 -0
  2. package/dist-lib/types/chatbot/api/chatbot-api.d.ts +14 -3
  3. package/dist-lib/types/chatbot/api/chatbot-api.test.d.ts +1 -0
  4. package/dist-lib/types/chatbot/api/chatbot-types.d.ts +35 -0
  5. package/dist-lib/types/chatbot/core/AgentReasoning.d.ts +8 -0
  6. package/dist-lib/types/chatbot/core/ChatContext.d.ts +6 -1
  7. package/dist-lib/types/chatbot/core/ChatMarkdown.d.ts +3 -2
  8. package/dist-lib/types/chatbot/core/ChatProvider.d.ts +15 -1
  9. package/dist-lib/types/chatbot/core/ChatTypingIndicator.d.ts +1 -0
  10. package/dist-lib/types/chatbot/core/GroundedSources.d.ts +14 -0
  11. package/dist-lib/types/chatbot/core/grounding.test.d.ts +1 -0
  12. package/dist-lib/types/chatbot/embedded/EmbeddedChatbot.d.ts +14 -1
  13. package/dist-lib/types/chatbot/index.d.ts +1 -1
  14. package/dist-lib/types/chatbot/widget/ChatbotWidget.d.ts +14 -1
  15. package/dist-lib/vps-chatbot.cjs +53 -20
  16. package/dist-lib/vps-chatbot.js +1552 -980
  17. package/package.json +1 -1
  18. package/src/chatbot/api/chatbot-api.test.ts +48 -0
  19. package/src/chatbot/api/chatbot-api.ts +199 -5
  20. package/src/chatbot/api/chatbot-types.ts +39 -0
  21. package/src/chatbot/chatbot.test.tsx +24 -1
  22. package/src/chatbot/core/AgentReasoning.tsx +65 -0
  23. package/src/chatbot/core/ChatContext.tsx +6 -0
  24. package/src/chatbot/core/ChatInput.tsx +14 -1
  25. package/src/chatbot/core/ChatMarkdown.tsx +288 -54
  26. package/src/chatbot/core/ChatMessage.tsx +53 -45
  27. package/src/chatbot/core/ChatMessageList.tsx +1 -1
  28. package/src/chatbot/core/ChatProvider.tsx +184 -28
  29. package/src/chatbot/core/ChatTypingIndicator.tsx +11 -5
  30. package/src/chatbot/core/GroundedSources.tsx +179 -0
  31. package/src/chatbot/core/grounding.test.tsx +21 -0
  32. package/src/chatbot/embedded/EmbeddedChatbot.tsx +36 -4
  33. package/src/chatbot/index.ts +3 -0
  34. package/src/chatbot/widget/ChatbotWidget.tsx +36 -4
  35. package/src/index.css +927 -68
@@ -1,53 +1,55 @@
1
- import { jsx as o, jsxs as k, Fragment as oe } from "react/jsx-runtime";
2
- import * as c from "react";
3
- import Xe, { createContext as yt, useContext as Qe, useMemo as Ce, useState as j, useRef as K, useCallback as X, forwardRef as et, createElement as ke, useEffect as me } from "react";
4
- const wt = {};
5
- function ee(e) {
1
+ import { jsx as l, jsxs as w, Fragment as De } from "react/jsx-runtime";
2
+ import * as d from "react";
3
+ import oe, { createContext as Et, useContext as it, useMemo as ye, useState as U, useRef as re, useCallback as ue, forwardRef as ct, createElement as He, useEffect as ke } from "react";
4
+ const Rt = {};
5
+ function ve(e) {
6
6
  return e != null && e.trim() !== "" ? e.trim().replace(/\/+$/, "") : String("").trim().replace(/\/+$/, "");
7
7
  }
8
- function We(e, t) {
9
- const r = ee(e);
10
- if (!r)
8
+ function Pe(e, t) {
9
+ const n = ve(e);
10
+ if (!n)
11
11
  return t;
12
- if (r.endsWith("/api") && t.startsWith("/api/"))
13
- return `${r}${t.slice(4)}`;
14
- if (r.endsWith("/api") && t === "/health") {
15
- const s = r.slice(0, -4);
12
+ if (n.endsWith("/api") && t.startsWith("/api/"))
13
+ return `${n}${t.slice(4)}`;
14
+ if (n.endsWith("/api") && t === "/health") {
15
+ const s = n.slice(0, -4);
16
16
  return s ? `${s}/health` : "/health";
17
17
  }
18
- const n = t.startsWith("/") ? t : `/${t}`;
19
- return `${r}${n}`;
18
+ const r = t.startsWith("/") ? t : `/${t}`;
19
+ return `${n}${r}`;
20
20
  }
21
- function Ct(e) {
21
+ function Xe(e) {
22
22
  return e && typeof e == "object" && "data" in e && e.success !== !1 ? e.data : e;
23
23
  }
24
- function kt(e, t, r) {
25
- var l, a, i;
26
- const n = e, s = (l = n == null ? void 0 : n.error) == null ? void 0 : l.message;
27
- return s && !St(s) ? {
28
- code: (a = n == null ? void 0 : n.error) == null ? void 0 : a.code,
24
+ function Ze(e, t, n) {
25
+ var o, a, i;
26
+ const r = e, s = (o = r == null ? void 0 : r.error) == null ? void 0 : o.message;
27
+ return s && !At(s) ? {
28
+ code: (a = r == null ? void 0 : r.error) == null ? void 0 : a.code,
29
29
  message: s,
30
- requestId: (i = n == null ? void 0 : n.error) == null ? void 0 : i.request_id
31
- } : r >= 500 ? { message: "I couldn't process that request right now." } : r === 0 ? { message: "Something went wrong while connecting. Please try again." } : { message: t };
30
+ requestId: (i = r == null ? void 0 : r.error) == null ? void 0 : i.request_id
31
+ } : n >= 500 ? { message: "I couldn't process that request right now." } : n === 0 ? { message: "Something went wrong while connecting. Please try again." } : { message: t };
32
32
  }
33
- function St(e) {
33
+ function At(e) {
34
34
  return /traceback|sql|exception|stack|api[_ ]?key|password/i.test(e);
35
35
  }
36
- function Ft(e) {
36
+ function xe(e) {
37
37
  return {
38
38
  chunkId: e.chunk_id,
39
39
  source: e.source,
40
- score: e.score
40
+ score: e.score,
41
+ title: e.title,
42
+ snippet: e.snippet
41
43
  };
42
44
  }
43
- function Et(e) {
45
+ function Le(e) {
44
46
  return {
45
47
  toolName: e.tool_name,
46
48
  arguments: e.arguments ?? {},
47
49
  result: e.result ?? {}
48
50
  };
49
51
  }
50
- function Tt(e) {
52
+ function qe(e) {
51
53
  return {
52
54
  model: e.model,
53
55
  promptTokens: e.prompt_tokens,
@@ -55,7 +57,7 @@ function Tt(e) {
55
57
  totalTokens: e.total_tokens
56
58
  };
57
59
  }
58
- function Rt(e) {
60
+ function Nt(e) {
59
61
  const t = e.role === "user" || e.role === "system" ? e.role : "assistant";
60
62
  return {
61
63
  id: String(e.id),
@@ -71,7 +73,7 @@ function Rt(e) {
71
73
  } : void 0
72
74
  };
73
75
  }
74
- async function At(e) {
76
+ async function Oe(e) {
75
77
  const t = await e.text();
76
78
  if (!t) return {};
77
79
  try {
@@ -80,13 +82,13 @@ async function At(e) {
80
82
  return {};
81
83
  }
82
84
  }
83
- function tt(e) {
84
- const t = ee(e);
85
- async function r(n, s) {
86
- let l;
87
- const a = We(t, n);
85
+ function ut(e) {
86
+ const t = ve(e);
87
+ async function n(r, s) {
88
+ let o;
89
+ const a = Pe(t, r);
88
90
  try {
89
- l = await fetch(a, {
91
+ o = await fetch(a, {
90
92
  ...s,
91
93
  headers: {
92
94
  "Content-Type": "application/json",
@@ -96,55 +98,170 @@ function tt(e) {
96
98
  } catch {
97
99
  throw { message: "Something went wrong while connecting. Please try again." };
98
100
  }
99
- if (l.status === 204)
101
+ if (o.status === 204)
100
102
  return;
101
- const i = await At(l);
102
- if (!l.ok)
103
- throw kt(
103
+ const i = await Oe(o);
104
+ if (!o.ok)
105
+ throw Ze(
104
106
  i,
105
107
  "I couldn't process that request right now.",
106
- l.status
108
+ o.status
107
109
  );
108
- return Ct(i);
110
+ return Xe(i);
109
111
  }
110
112
  return {
111
113
  apiBaseUrl: t,
112
- async createSession() {
113
- const n = await r("/api/v1/sessions", {
114
+ async listModels() {
115
+ try {
116
+ const r = await n("/api/v1/models");
117
+ return { defaultModelId: r.default_model_id, complexModelId: r.complex_model_id, models: r.models || [] };
118
+ } catch {
119
+ return null;
120
+ }
121
+ },
122
+ async createSession(r) {
123
+ const s = await n("/api/v1/sessions", {
114
124
  method: "POST",
125
+ signal: r,
115
126
  body: JSON.stringify({})
116
127
  });
117
- return { sessionId: n.session_id, createdAt: n.created_at };
128
+ return { sessionId: s.session_id, createdAt: s.created_at };
118
129
  },
119
- async sendMessage(n, s) {
120
- const l = await r(
121
- `/api/v1/sessions/${n}/messages`,
130
+ async sendMessage(r, s, o, a) {
131
+ const i = await n(
132
+ `/api/v1/sessions/${r}/messages`,
122
133
  {
123
134
  method: "POST",
124
- body: JSON.stringify({ message: s })
135
+ signal: a,
136
+ body: JSON.stringify({
137
+ message: s,
138
+ ...(o == null ? void 0 : o.roleId) !== void 0 ? { role_id: o.roleId } : {},
139
+ ...o != null && o.client ? { client: o.client } : {},
140
+ ...o != null && o.modelId ? { model_id: o.modelId } : {}
141
+ })
125
142
  }
126
143
  );
127
144
  return {
128
- requestId: l.request_id,
129
- sessionId: l.session_id,
130
- answer: l.answer,
131
- sources: (l.sources || []).map(Ft),
132
- toolCalls: (l.tool_calls || []).map(Et),
133
- usage: Tt(l.usage)
145
+ requestId: i.request_id,
146
+ sessionId: i.session_id,
147
+ answer: i.answer,
148
+ sources: (i.sources || []).map(xe),
149
+ toolCalls: (i.tool_calls || []).map(Le),
150
+ usage: qe(i.usage),
151
+ durationMs: i.duration_ms
134
152
  };
135
153
  },
136
- async getHistory(n) {
154
+ async sendMessageStream(r, s, o, a, i, u) {
155
+ var g, f;
156
+ const h = Pe(t, `/api/v1/sessions/${r}/messages/stream`);
157
+ try {
158
+ const c = await fetch(h, {
159
+ method: "POST",
160
+ signal: u,
161
+ headers: {
162
+ "Content-Type": "application/json"
163
+ },
164
+ body: JSON.stringify({
165
+ message: s,
166
+ ...(o == null ? void 0 : o.roleId) !== void 0 ? { role_id: o.roleId } : {},
167
+ ...o != null && o.client ? { client: o.client } : {},
168
+ ...o != null && o.modelId ? { model_id: o.modelId } : {}
169
+ })
170
+ });
171
+ if (!c.ok) {
172
+ if (c.status === 404 || c.status === 405)
173
+ return await this.sendMessage(r, s, o, u);
174
+ const T = await Oe(c);
175
+ throw Ze(
176
+ T,
177
+ "I couldn't process that request right now.",
178
+ c.status
179
+ );
180
+ }
181
+ if (!c.body || (f = (g = c.headers) == null ? void 0 : g.get("content-type")) != null && f.includes("application/json")) {
182
+ const T = Xe(await Oe(c));
183
+ if (typeof T.answer != "string" || !T.usage)
184
+ throw { message: "The response stream ended unexpectedly." };
185
+ return {
186
+ requestId: T.request_id,
187
+ sessionId: T.session_id,
188
+ answer: T.answer,
189
+ sources: (T.sources || []).map(xe),
190
+ toolCalls: (T.tool_calls || []).map(Le),
191
+ usage: qe(T.usage),
192
+ durationMs: T.duration_ms
193
+ };
194
+ }
195
+ const p = c.body.getReader(), b = new TextDecoder();
196
+ let k = "";
197
+ const v = { value: null }, m = (T) => {
198
+ const x = T.split(/\r?\n/).filter((N) => N.startsWith("data:")).map((N) => N.slice(5).trimStart()).join(`
199
+ `);
200
+ if (!x) return;
201
+ let C = {};
202
+ try {
203
+ const N = JSON.parse(x);
204
+ if (!N || typeof N != "object") return;
205
+ C = N;
206
+ } catch {
207
+ return;
208
+ }
209
+ if (C.type === "progress" && typeof C.stage == "string")
210
+ a == null || a(C.stage);
211
+ else if (C.type === "token" && typeof C.text == "string")
212
+ i == null || i(C.text);
213
+ else if (C.type === "complete")
214
+ v.value = {
215
+ requestId: C.request_id || "",
216
+ sessionId: C.session_id || r,
217
+ answer: C.answer || "",
218
+ sources: (C.sources || []).map(xe),
219
+ toolCalls: (C.tool_calls || []).map(Le),
220
+ usage: C.usage ? qe(C.usage) : { model: "", promptTokens: 0, completionTokens: 0, totalTokens: 0 },
221
+ durationMs: C.duration_ms
222
+ };
223
+ else if (C.type === "error")
224
+ throw {
225
+ message: C.message || "I couldn't process that request right now.",
226
+ requestId: C.request_id
227
+ };
228
+ };
229
+ try {
230
+ for (; !v.value; ) {
231
+ const { done: T, value: x } = await p.read();
232
+ if (T) break;
233
+ if (k += b.decode(x, { stream: !0 }), k.length > 1e6)
234
+ throw { message: "The response stream was too large." };
235
+ const C = k.split(/\r?\n\r?\n/);
236
+ k = C.pop() || "";
237
+ for (const N of C)
238
+ if (m(N), v.value) break;
239
+ }
240
+ k += b.decode(), !v.value && k.trim() && m(k);
241
+ } finally {
242
+ await p.cancel().catch(() => {
243
+ }), p.releaseLock();
244
+ }
245
+ const B = v.value;
246
+ if (B)
247
+ return B;
248
+ throw { message: "The response stream ended before the answer was complete." };
249
+ } catch (c) {
250
+ throw !(c instanceof Error) && c && typeof c == "object" && "message" in c ? c : { message: "Something went wrong while connecting. Please try again." };
251
+ }
252
+ },
253
+ async getHistory(r) {
137
254
  try {
138
- return ((await r(
139
- `/api/v1/sessions/${n}/messages`
140
- )).messages || []).map(Rt);
255
+ return ((await n(
256
+ `/api/v1/sessions/${r}/messages`
257
+ )).messages || []).map(Nt);
141
258
  } catch {
142
259
  return [];
143
260
  }
144
261
  },
145
- async closeSession(n) {
262
+ async closeSession(r) {
146
263
  try {
147
- await r(`/api/v1/sessions/${n}`, { method: "DELETE" });
264
+ await n(`/api/v1/sessions/${r}`, { method: "DELETE" });
148
265
  } catch {
149
266
  }
150
267
  },
@@ -153,15 +270,15 @@ function tt(e) {
153
270
  },
154
271
  async checkHealth() {
155
272
  try {
156
- const n = We(t, "/health");
157
- return (await fetch(n)).ok;
273
+ const r = Pe(t, "/health");
274
+ return (await fetch(r)).ok;
158
275
  } catch {
159
276
  return !1;
160
277
  }
161
278
  }
162
279
  };
163
280
  }
164
- const hn = tt(), Bt = [
281
+ const Sn = ut(), It = [
165
282
  {
166
283
  label: "How do I access my reports?",
167
284
  query: "How do I access my reports in the VPS Customer Portal?"
@@ -178,20 +295,30 @@ const hn = tt(), Bt = [
178
295
  label: "How do I contact VPS Support?",
179
296
  query: "How can I contact VPS Customer Support?"
180
297
  }
181
- ], Ee = yt(null);
182
- function Dt() {
183
- const e = Qe(Ee);
298
+ ], Ve = Et(null);
299
+ function Mt() {
300
+ const e = it(Ve);
184
301
  if (!e)
185
302
  throw new Error("useChatbot must be used inside ChatProvider.");
186
303
  return e;
187
304
  }
188
- function rt() {
189
- return Qe(Ee);
190
- }
191
- function $e(e) {
305
+ function Ge() {
306
+ return it(Ve);
307
+ }
308
+ const Dt = `Hello! I am your **VPS Veritas assistant**.
309
+
310
+ I can help you with:
311
+ - **Fuel Quality Testing (FQT)** & **Oil Condition Monitoring (OCM)**
312
+ - **Fuel Defect Reporting (FDR)** — report and track bunker defect incidents
313
+ - **Bunker Master** — manage bunkering operations, BDN logs, and surveys
314
+ - **FSC & FSQ E-Forms** — paperless fuel system checks and bunker sample pre-registration
315
+ - **Samplogic** sample logistics, report downloads, and support tickets
316
+
317
+ Feel free to ask a question or select one of the suggested topics below!`;
318
+ function et(e) {
192
319
  return `${e}-${crypto.randomUUID()}`;
193
320
  }
194
- function Mt(e) {
321
+ function Bt(e) {
195
322
  if (e && typeof e == "object" && "message" in e) {
196
323
  const t = String(e.message);
197
324
  if (t && !/traceback|sql|exception|stack|api[_ ]?key|password/i.test(t))
@@ -199,133 +326,226 @@ function Mt(e) {
199
326
  }
200
327
  return "I couldn't process that request right now.";
201
328
  }
202
- const nt = ({
329
+ const dt = ({
203
330
  children: e,
204
331
  userContext: t = {},
205
- suggestions: r = Bt,
206
- disableSuggestions: n = !1,
207
- initialMessage: s,
208
- apiBaseUrl: l,
209
- apiUrl: a,
210
- proxyUrl: i,
211
- api: d
332
+ role: n,
333
+ roleId: r,
334
+ client: s,
335
+ welcomeMessage: o,
336
+ suggestions: a = It,
337
+ disableSuggestions: i = !1,
338
+ initialMessage: u,
339
+ apiBaseUrl: h,
340
+ apiUrl: g,
341
+ proxyUrl: f,
342
+ api: c,
343
+ hideInspectSources: p = !1,
344
+ showGroundedSources: b = !0,
345
+ modelId: k = "auto"
212
346
  }) => {
213
- const h = l ?? a ?? i, g = Ce(
214
- () => d ?? tt(h),
215
- [d, h]
216
- ), [v, f] = j(null), [u, m] = j([]), [T, _] = j("idle"), [D, V] = j(null), L = K(null), $ = K(!1), P = X(async () => {
217
- if (v) return v;
218
- _("connecting");
219
- const y = await g.createSession();
220
- return f(y.sessionId), y.sessionId;
221
- }, [v, g]), I = X(
222
- async (y) => {
223
- L.current = y;
224
- const S = {
225
- id: $e("user"),
347
+ const v = h ?? g ?? f, m = ye(
348
+ () => c ?? ut(v),
349
+ [c, v]
350
+ ), B = ye(() => ({
351
+ ...t,
352
+ ...n !== void 0 ? { role: n } : {},
353
+ ...r !== void 0 ? { roleId: r } : {},
354
+ ...s !== void 0 ? { client: s } : {}
355
+ }), [t, n, r, s]), T = ye(() => o === "" ? null : {
356
+ id: "welcome-default",
357
+ role: "assistant",
358
+ content: o || Dt,
359
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
360
+ status: "complete"
361
+ }, [o]), [x, C] = U(null), [N, I] = U(() => T ? [T] : []), [z, q] = U("idle"), [le, K] = U(null), y = re(null), A = re(!1), M = re(null), D = re(!1), [P, O] = U([]), [L, Y] = U(k);
362
+ oe.useEffect(() => Y(k), [k]), oe.useEffect(() => {
363
+ var S;
364
+ let R = !0;
365
+ return O([]), (S = m.listModels) == null || S.call(m).then((V) => {
366
+ R && O((V == null ? void 0 : V.models) || []);
367
+ }).catch(() => {
368
+ }), () => {
369
+ R = !1;
370
+ };
371
+ }, [m]);
372
+ const ee = ue((R) => {
373
+ !D.current && (R === "auto" || P.some((S) => S.id === R && S.configured)) && Y(R);
374
+ }, [P]);
375
+ oe.useEffect(() => () => {
376
+ var R;
377
+ return (R = M.current) == null ? void 0 : R.abort();
378
+ }, []);
379
+ const de = ue(async (R) => {
380
+ if (x) return x;
381
+ q("connecting");
382
+ const S = await m.createSession(R);
383
+ if (R.aborted) throw new DOMException("Aborted", "AbortError");
384
+ return C(S.sessionId), S.sessionId;
385
+ }, [x, m]), ne = ue(
386
+ async (R) => {
387
+ if (D.current) return;
388
+ D.current = !0;
389
+ const S = new AbortController();
390
+ M.current = S;
391
+ let V, fe = "";
392
+ const me = () => {
393
+ V !== void 0 && cancelAnimationFrame(V), V = void 0;
394
+ };
395
+ y.current = R;
396
+ const ie = {
397
+ id: et("user"),
226
398
  role: "user",
227
- content: y,
399
+ content: R,
228
400
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
229
401
  status: "complete"
230
- }, F = $e("asst"), B = {
231
- id: F,
402
+ }, se = et("asst"), ge = {
403
+ id: se,
232
404
  role: "assistant",
233
405
  content: "",
234
406
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
235
- status: "pending"
407
+ status: "pending",
408
+ progressText: "Preparing your answer…"
409
+ }, Ee = performance.now();
410
+ I((X) => [...X, ie, ge]), q("awaiting"), K(null);
411
+ const Re = (X) => {
412
+ S.signal.aborted || I(
413
+ (j) => j.map(
414
+ (Z) => Z.id === se ? { ...Z, progressText: X } : Z
415
+ )
416
+ );
236
417
  };
237
- m((A) => [...A, S, B]), _("awaiting"), V(null);
238
418
  try {
239
- const A = await P(), E = await g.sendMessage(A, y);
240
- m(
241
- (W) => W.map(
242
- (z) => z.id === F ? {
243
- ...z,
244
- id: E.requestId || F,
245
- content: E.answer,
419
+ const X = await de(S.signal), j = m.sendMessageStream ? await m.sendMessageStream(
420
+ X,
421
+ R,
422
+ {
423
+ roleId: B.roleId,
424
+ client: B.client,
425
+ modelId: L
426
+ },
427
+ Re,
428
+ (Z) => {
429
+ S.signal.aborted || (fe += Z, V === void 0 && (V = requestAnimationFrame(() => {
430
+ V = void 0, S.signal.aborted || I((Q) => Q.map((be) => be.id === se ? { ...be, content: fe } : be));
431
+ })));
432
+ },
433
+ S.signal
434
+ ) : await m.sendMessage(X, R, {
435
+ roleId: B.roleId,
436
+ client: B.client,
437
+ modelId: L
438
+ }, S.signal);
439
+ if (me(), S.signal.aborted) return;
440
+ I(
441
+ (Z) => Z.map(
442
+ (Q) => Q.id === se ? {
443
+ ...Q,
444
+ id: j.requestId || se,
445
+ content: j.answer,
246
446
  status: "complete",
247
- sources: E.sources,
248
- toolCalls: E.toolCalls,
249
- usage: E.usage
250
- } : z
447
+ progressText: void 0,
448
+ sources: j.sources,
449
+ toolCalls: j.toolCalls,
450
+ usage: j.usage,
451
+ durationMs: Math.max(
452
+ Math.round(performance.now() - Ee),
453
+ j.durationMs ?? 0
454
+ )
455
+ } : Q
251
456
  )
252
- ), _("idle");
253
- } catch (A) {
254
- const E = Mt(A);
255
- m(
256
- (W) => W.map(
257
- (z) => z.id === F ? { ...z, content: E, status: "error" } : z
457
+ ), q("idle");
458
+ } catch (X) {
459
+ if (me(), S.signal.aborted) return;
460
+ const j = Bt(X);
461
+ I(
462
+ (Z) => Z.map(
463
+ (Q) => Q.id === se ? { ...Q, content: j, status: "error", progressText: void 0 } : Q
258
464
  )
259
- ), V(E), _("error");
465
+ ), K(j), q("error");
466
+ } finally {
467
+ me(), M.current === S && (M.current = null, D.current = !1);
260
468
  }
261
469
  },
262
- [P, g]
263
- ), R = X(
264
- async (y) => {
265
- const S = y.trim();
266
- !S || T === "awaiting" || T === "connecting" || await I(S);
470
+ [de, m, B.client, B.roleId, L]
471
+ ), he = ue(
472
+ async (R) => {
473
+ const S = R.trim();
474
+ !S || z === "awaiting" || z === "connecting" || await ne(S);
267
475
  },
268
- [I, T]
269
- ), O = X(async () => {
270
- const y = L.current;
271
- y && (m((S) => S.filter((F) => F.status !== "error")), await I(y));
272
- }, [I]), N = X(async () => {
273
- }, []), Z = X(() => {
274
- }, []), U = X(async () => {
275
- v && await g.closeSession(v), f(null), m([]), _("idle"), V(null), L.current = null;
276
- }, [v, g]);
277
- Xe.useEffect(() => {
278
- !s || $.current || ($.current = !0, R(s));
279
- }, [s, R]);
280
- const b = Ce(
476
+ [ne, z]
477
+ ), J = ue(async () => {
478
+ if (D.current) return;
479
+ const R = y.current;
480
+ R && (I((S) => S.filter((V) => V.status !== "error")), await ne(R));
481
+ }, [ne]), ae = ue(async () => {
482
+ }, []), $ = ue(() => {
483
+ }, []), pe = ue(async () => {
484
+ var R;
485
+ (R = M.current) == null || R.abort(), M.current = null, D.current = !1, C(null), I(T ? [T] : []), q("idle"), K(null), y.current = null, x && await m.closeSession(x);
486
+ }, [x, m, T]);
487
+ oe.useEffect(() => {
488
+ !u || A.current || (A.current = !0, he(u));
489
+ }, [u, he]);
490
+ const Te = ye(
281
491
  () => ({
282
- messages: u,
283
- status: T,
284
- error: D,
285
- sessionId: v,
492
+ messages: N,
493
+ status: z,
494
+ error: le,
495
+ sessionId: x,
286
496
  pendingTicket: null,
287
497
  ticketBusy: !1,
288
498
  lastTicket: null,
289
- suggestions: r,
290
- showSuggestions: !n && u.length === 0,
291
- suggestionBadgesEnabled: !n,
292
- userContext: t,
293
- apiBaseUrl: g.apiBaseUrl,
294
- sendMessage: R,
295
- retryLast: O,
296
- confirmTicket: N,
297
- cancelTicket: Z,
298
- resetConversation: U
499
+ suggestions: a,
500
+ showSuggestions: !i && (N.length === 0 || N.length === 1 && N[0].id === "welcome-default"),
501
+ suggestionBadgesEnabled: !i,
502
+ userContext: B,
503
+ apiBaseUrl: m.apiBaseUrl,
504
+ hideInspectSources: p,
505
+ showGroundedSources: b,
506
+ sendMessage: he,
507
+ retryLast: J,
508
+ confirmTicket: ae,
509
+ cancelTicket: $,
510
+ resetConversation: pe,
511
+ models: P,
512
+ selectedModelId: L,
513
+ selectModel: ee
299
514
  }),
300
515
  [
301
- u,
302
- T,
303
- D,
304
- v,
305
- r,
306
- n,
307
- t,
308
- g.apiBaseUrl,
309
- R,
310
- O,
311
516
  N,
312
- Z,
313
- U
517
+ z,
518
+ le,
519
+ x,
520
+ a,
521
+ i,
522
+ B,
523
+ m.apiBaseUrl,
524
+ p,
525
+ b,
526
+ he,
527
+ J,
528
+ ae,
529
+ $,
530
+ pe,
531
+ P,
532
+ L,
533
+ ee
314
534
  ]
315
535
  );
316
- return /* @__PURE__ */ o(Ee.Provider, { value: b, children: e });
536
+ return /* @__PURE__ */ l(Ve.Provider, { value: Te, children: e });
317
537
  };
318
- function ve() {
319
- return Dt();
538
+ function Be() {
539
+ return Mt();
320
540
  }
321
- const It = ({ message: e, onRetry: t }) => /* @__PURE__ */ k(
541
+ const Pt = ({ message: e, onRetry: t }) => /* @__PURE__ */ w(
322
542
  "div",
323
543
  {
324
544
  className: "chat-error-banner",
325
545
  role: "alert",
326
546
  children: [
327
- /* @__PURE__ */ o("p", { children: e }),
328
- t && /* @__PURE__ */ o(
547
+ /* @__PURE__ */ l("p", { children: e }),
548
+ t && /* @__PURE__ */ l(
329
549
  "button",
330
550
  {
331
551
  type: "button",
@@ -343,14 +563,14 @@ const It = ({ message: e, onRetry: t }) => /* @__PURE__ */ k(
343
563
  * This source code is licensed under the ISC license.
344
564
  * See the LICENSE file in the root directory of this source tree.
345
565
  */
346
- const Nt = (e) => e.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase(), st = (...e) => e.filter((t, r, n) => !!t && t.trim() !== "" && n.indexOf(t) === r).join(" ").trim();
566
+ const xt = (e) => e.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase(), ht = (...e) => e.filter((t, n, r) => !!t && t.trim() !== "" && r.indexOf(t) === n).join(" ").trim();
347
567
  /**
348
568
  * @license lucide-react v0.468.0 - ISC
349
569
  *
350
570
  * This source code is licensed under the ISC license.
351
571
  * See the LICENSE file in the root directory of this source tree.
352
572
  */
353
- var Pt = {
573
+ var Lt = {
354
574
  xmlns: "http://www.w3.org/2000/svg",
355
575
  width: 24,
356
576
  height: 24,
@@ -367,31 +587,31 @@ var Pt = {
367
587
  * This source code is licensed under the ISC license.
368
588
  * See the LICENSE file in the root directory of this source tree.
369
589
  */
370
- const xt = et(
590
+ const qt = ct(
371
591
  ({
372
592
  color: e = "currentColor",
373
593
  size: t = 24,
374
- strokeWidth: r = 2,
375
- absoluteStrokeWidth: n,
594
+ strokeWidth: n = 2,
595
+ absoluteStrokeWidth: r,
376
596
  className: s = "",
377
- children: l,
597
+ children: o,
378
598
  iconNode: a,
379
599
  ...i
380
- }, d) => ke(
600
+ }, u) => He(
381
601
  "svg",
382
602
  {
383
- ref: d,
384
- ...Pt,
603
+ ref: u,
604
+ ...Lt,
385
605
  width: t,
386
606
  height: t,
387
607
  stroke: e,
388
- strokeWidth: n ? Number(r) * 24 / Number(t) : r,
389
- className: st("lucide", s),
608
+ strokeWidth: r ? Number(n) * 24 / Number(t) : n,
609
+ className: ht("lucide", s),
390
610
  ...i
391
611
  },
392
612
  [
393
- ...a.map(([h, g]) => ke(h, g)),
394
- ...Array.isArray(l) ? l : [l]
613
+ ...a.map(([h, g]) => He(h, g)),
614
+ ...Array.isArray(o) ? o : [o]
395
615
  ]
396
616
  )
397
617
  );
@@ -402,15 +622,15 @@ const xt = et(
402
622
  * See the LICENSE file in the root directory of this source tree.
403
623
  */
404
624
  const H = (e, t) => {
405
- const r = et(
406
- ({ className: n, ...s }, l) => ke(xt, {
407
- ref: l,
625
+ const n = ct(
626
+ ({ className: r, ...s }, o) => He(qt, {
627
+ ref: o,
408
628
  iconNode: t,
409
- className: st(`lucide-${Nt(e)}`, n),
629
+ className: ht(`lucide-${xt(e)}`, r),
410
630
  ...s
411
631
  })
412
632
  );
413
- return r.displayName = `${e}`, r;
633
+ return n.displayName = `${e}`, n;
414
634
  };
415
635
  /**
416
636
  * @license lucide-react v0.468.0 - ISC
@@ -418,7 +638,7 @@ const H = (e, t) => {
418
638
  * This source code is licensed under the ISC license.
419
639
  * See the LICENSE file in the root directory of this source tree.
420
640
  */
421
- const Lt = H("ArrowDown", [
641
+ const Ot = H("ArrowDown", [
422
642
  ["path", { d: "M12 5v14", key: "s699le" }],
423
643
  ["path", { d: "m19 12-7 7-7-7", key: "1idqje" }]
424
644
  ]);
@@ -428,7 +648,7 @@ const Lt = H("ArrowDown", [
428
648
  * This source code is licensed under the ISC license.
429
649
  * See the LICENSE file in the root directory of this source tree.
430
650
  */
431
- const Ot = H("ArrowLeft", [
651
+ const $t = H("ArrowLeft", [
432
652
  ["path", { d: "m12 19-7-7 7-7", key: "1l729n" }],
433
653
  ["path", { d: "M19 12H5", key: "x3x0zl" }]
434
654
  ]);
@@ -448,7 +668,23 @@ const Ht = H("ArrowUp", [
448
668
  * This source code is licensed under the ISC license.
449
669
  * See the LICENSE file in the root directory of this source tree.
450
670
  */
451
- const lt = H("BotMessageSquare", [
671
+ const zt = H("BookOpen", [
672
+ ["path", { d: "M12 7v14", key: "1akyts" }],
673
+ [
674
+ "path",
675
+ {
676
+ d: "M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z",
677
+ key: "ruj8y"
678
+ }
679
+ ]
680
+ ]);
681
+ /**
682
+ * @license lucide-react v0.468.0 - ISC
683
+ *
684
+ * This source code is licensed under the ISC license.
685
+ * See the LICENSE file in the root directory of this source tree.
686
+ */
687
+ const pt = H("BotMessageSquare", [
452
688
  ["path", { d: "M12 6V2H8", key: "1155em" }],
453
689
  ["path", { d: "m8 18-4 4V8a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2Z", key: "w2lp3e" }],
454
690
  ["path", { d: "M2 12h2", key: "1t8f8n" }],
@@ -462,14 +698,14 @@ const lt = H("BotMessageSquare", [
462
698
  * This source code is licensed under the ISC license.
463
699
  * See the LICENSE file in the root directory of this source tree.
464
700
  */
465
- const zt = H("Check", [["path", { d: "M20 6 9 17l-5-5", key: "1gmf2c" }]]);
701
+ const Wt = H("Check", [["path", { d: "M20 6 9 17l-5-5", key: "1gmf2c" }]]);
466
702
  /**
467
703
  * @license lucide-react v0.468.0 - ISC
468
704
  *
469
705
  * This source code is licensed under the ISC license.
470
706
  * See the LICENSE file in the root directory of this source tree.
471
707
  */
472
- const qt = H("ChevronDown", [
708
+ const Vt = H("ChevronDown", [
473
709
  ["path", { d: "m6 9 6 6 6-6", key: "qrunsl" }]
474
710
  ]);
475
711
  /**
@@ -485,7 +721,17 @@ const Gt = H("ChevronUp", [["path", { d: "m18 15-6-6-6 6", key: "153udz" }]]);
485
721
  * This source code is licensed under the ISC license.
486
722
  * See the LICENSE file in the root directory of this source tree.
487
723
  */
488
- const Vt = H("ClipboardCheck", [
724
+ const Ut = H("CircleCheck", [
725
+ ["circle", { cx: "12", cy: "12", r: "10", key: "1mglay" }],
726
+ ["path", { d: "m9 12 2 2 4-4", key: "dzmm74" }]
727
+ ]);
728
+ /**
729
+ * @license lucide-react v0.468.0 - ISC
730
+ *
731
+ * This source code is licensed under the ISC license.
732
+ * See the LICENSE file in the root directory of this source tree.
733
+ */
734
+ const jt = H("ClipboardCheck", [
489
735
  ["rect", { width: "8", height: "4", x: "8", y: "2", rx: "1", ry: "1", key: "tgr4d6" }],
490
736
  [
491
737
  "path",
@@ -502,12 +748,10 @@ const Vt = H("ClipboardCheck", [
502
748
  * This source code is licensed under the ISC license.
503
749
  * See the LICENSE file in the root directory of this source tree.
504
750
  */
505
- const Wt = H("FileText", [
506
- ["path", { d: "M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z", key: "1rqfz7" }],
507
- ["path", { d: "M14 2v4a2 2 0 0 0 2 2h4", key: "tnqrlb" }],
508
- ["path", { d: "M10 9H8", key: "b1mrlr" }],
509
- ["path", { d: "M16 13H8", key: "t4e002" }],
510
- ["path", { d: "M16 17H8", key: "z1uh3a" }]
751
+ const Yt = H("ExternalLink", [
752
+ ["path", { d: "M15 3h6v6", key: "1q9fwt" }],
753
+ ["path", { d: "M10 14 21 3", key: "gplh6r" }],
754
+ ["path", { d: "M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6", key: "a6xqqp" }]
511
755
  ]);
512
756
  /**
513
757
  * @license lucide-react v0.468.0 - ISC
@@ -515,7 +759,7 @@ const Wt = H("FileText", [
515
759
  * This source code is licensed under the ISC license.
516
760
  * See the LICENSE file in the root directory of this source tree.
517
761
  */
518
- const $t = H("FlaskConical", [
762
+ const Jt = H("FlaskConical", [
519
763
  [
520
764
  "path",
521
765
  {
@@ -532,7 +776,16 @@ const $t = H("FlaskConical", [
532
776
  * This source code is licensed under the ISC license.
533
777
  * See the LICENSE file in the root directory of this source tree.
534
778
  */
535
- const ot = H("MessageSquare", [
779
+ const Kt = H("LoaderCircle", [
780
+ ["path", { d: "M21 12a9 9 0 1 1-6.219-8.56", key: "13zald" }]
781
+ ]);
782
+ /**
783
+ * @license lucide-react v0.468.0 - ISC
784
+ *
785
+ * This source code is licensed under the ISC license.
786
+ * See the LICENSE file in the root directory of this source tree.
787
+ */
788
+ const ft = H("MessageSquare", [
536
789
  ["path", { d: "M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z", key: "1lielz" }]
537
790
  ]);
538
791
  /**
@@ -541,7 +794,7 @@ const ot = H("MessageSquare", [
541
794
  * This source code is licensed under the ISC license.
542
795
  * See the LICENSE file in the root directory of this source tree.
543
796
  */
544
- const Ut = H("Microscope", [
797
+ const Qt = H("Microscope", [
545
798
  ["path", { d: "M6 18h8", key: "1borvv" }],
546
799
  ["path", { d: "M3 22h18", key: "8prr45" }],
547
800
  ["path", { d: "M14 22a7 7 0 1 0 0-14h-1", key: "1jwaiy" }],
@@ -555,14 +808,14 @@ const Ut = H("Microscope", [
555
808
  * This source code is licensed under the ISC license.
556
809
  * See the LICENSE file in the root directory of this source tree.
557
810
  */
558
- const jt = H("Minus", [["path", { d: "M5 12h14", key: "1ays0h" }]]);
811
+ const Xt = H("Minus", [["path", { d: "M5 12h14", key: "1ays0h" }]]);
559
812
  /**
560
813
  * @license lucide-react v0.468.0 - ISC
561
814
  *
562
815
  * This source code is licensed under the ISC license.
563
816
  * See the LICENSE file in the root directory of this source tree.
564
817
  */
565
- const Yt = H("RefreshCw", [
818
+ const Zt = H("RefreshCw", [
566
819
  ["path", { d: "M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8", key: "v9h5vc" }],
567
820
  ["path", { d: "M21 3v5h-5", key: "1q7to0" }],
568
821
  ["path", { d: "M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16", key: "3uifl3" }],
@@ -574,7 +827,23 @@ const Yt = H("RefreshCw", [
574
827
  * This source code is licensed under the ISC license.
575
828
  * See the LICENSE file in the root directory of this source tree.
576
829
  */
577
- const Zt = H("TestTubeDiagonal", [
830
+ const er = H("ShieldCheck", [
831
+ [
832
+ "path",
833
+ {
834
+ d: "M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",
835
+ key: "oel41y"
836
+ }
837
+ ],
838
+ ["path", { d: "m9 12 2 2 4-4", key: "dzmm74" }]
839
+ ]);
840
+ /**
841
+ * @license lucide-react v0.468.0 - ISC
842
+ *
843
+ * This source code is licensed under the ISC license.
844
+ * See the LICENSE file in the root directory of this source tree.
845
+ */
846
+ const tr = H("TestTubeDiagonal", [
578
847
  [
579
848
  "path",
580
849
  { d: "M21 7 6.82 21.18a2.83 2.83 0 0 1-3.99-.01a2.83 2.83 0 0 1 0-4L17 3", key: "1ub6xw" }
@@ -588,55 +857,55 @@ const Zt = H("TestTubeDiagonal", [
588
857
  * This source code is licensed under the ISC license.
589
858
  * See the LICENSE file in the root directory of this source tree.
590
859
  */
591
- const Jt = H("X", [
860
+ const rr = H("X", [
592
861
  ["path", { d: "M18 6 6 18", key: "1bl5f8" }],
593
862
  ["path", { d: "m6 6 12 12", key: "d8bk6v" }]
594
- ]), Kt = {
863
+ ]), nr = {
595
864
  alpha: {
596
865
  label: "Alpha",
597
- Icon: $t,
866
+ Icon: Jt,
598
867
  variant: "env-badge--alpha",
599
868
  tooltip: "Alpha build — internal testing only"
600
869
  },
601
870
  beta: {
602
871
  label: "Beta",
603
- Icon: Zt,
872
+ Icon: tr,
604
873
  variant: "env-badge--beta",
605
874
  tooltip: "Beta build — public pre-release"
606
875
  },
607
876
  gamma: {
608
877
  label: "Gamma",
609
- Icon: Ut,
878
+ Icon: Qt,
610
879
  variant: "env-badge--gamma",
611
880
  tooltip: "Gamma / Release Candidate"
612
881
  },
613
882
  qa: {
614
883
  label: "QA",
615
- Icon: Vt,
884
+ Icon: jt,
616
885
  variant: "env-badge--qa",
617
886
  tooltip: "Quality Assurance build"
618
887
  }
619
- }, Xt = ({
888
+ }, sr = ({
620
889
  stage: e,
621
890
  pulse: t = !0,
622
- className: r = ""
891
+ className: n = ""
623
892
  }) => {
624
893
  if (!e) return null;
625
- const { label: n, Icon: s, variant: l, tooltip: a } = Kt[e];
626
- return /* @__PURE__ */ k(
894
+ const { label: r, Icon: s, variant: o, tooltip: a } = nr[e];
895
+ return /* @__PURE__ */ w(
627
896
  "span",
628
897
  {
629
- className: `env-badge-inline ${l} ${r}`.trim(),
898
+ className: `env-badge-inline ${o} ${n}`.trim(),
630
899
  title: a,
631
- "aria-label": `${n} build`,
900
+ "aria-label": `${r} build`,
632
901
  role: "status",
633
902
  children: [
634
- /* @__PURE__ */ o(s, { size: 10, className: "env-badge-icon", "aria-hidden": "true" }),
635
- /* @__PURE__ */ o("span", { className: "env-badge-inline-label", children: n })
903
+ /* @__PURE__ */ l(s, { size: 10, className: "env-badge-icon", "aria-hidden": "true" }),
904
+ /* @__PURE__ */ l("span", { className: "env-badge-inline-label", children: r })
636
905
  ]
637
906
  }
638
907
  );
639
- }, Qt = (e) => /* @__PURE__ */ o(
908
+ }, or = (e) => /* @__PURE__ */ l(
640
909
  "svg",
641
910
  {
642
911
  width: e.width || "24px",
@@ -646,97 +915,97 @@ const Jt = H("X", [
646
915
  xmlns: "http://www.w3.org/2000/svg",
647
916
  fill: e.Color || "currentColor",
648
917
  ...e,
649
- children: /* @__PURE__ */ o("path", { d: "M11.999 0c-2.25 0-4.5.06-6.6.21a5.57 5.57 0 0 0-5.19 5.1c-.24 3.21-.27 6.39-.06 9.6a5.644 5.644 0 0 0 5.7 5.19h3.15v-3.9h-3.15c-.93.03-1.74-.63-1.83-1.56-.18-3-.15-6 .06-9 .06-.84.72-1.47 1.56-1.53 2.04-.15 4.2-.21 6.36-.21s4.32.09 6.36.18c.81.06 1.5.69 1.56 1.53.24 3 .24 6 .06 9-.12.93-.9 1.62-1.83 1.59h-3.15l-6 3.9V24l6-3.9h3.15c2.97.03 5.46-2.25 5.7-5.19.21-3.18.18-6.39-.03-9.57a5.57 5.57 0 0 0-5.19-5.1c-2.13-.18-4.38-.24-6.63-.24zm-5.04 8.76c-.36 0-.66.3-.66.66v2.34c0 .33.18.63.48.78 1.62.78 3.42 1.2 5.22 1.26 1.8-.06 3.6-.48 5.22-1.26.3-.15.48-.45.48-.78V9.42c0-.09-.03-.15-.09-.21a.648.648 0 0 0-.87-.36c-1.5.66-3.12 1.02-4.77 1.05-1.65-.03-3.27-.42-4.77-1.08a.566.566 0 0 0-.24-.06z" })
918
+ children: /* @__PURE__ */ l("path", { d: "M11.999 0c-2.25 0-4.5.06-6.6.21a5.57 5.57 0 0 0-5.19 5.1c-.24 3.21-.27 6.39-.06 9.6a5.644 5.644 0 0 0 5.7 5.19h3.15v-3.9h-3.15c-.93.03-1.74-.63-1.83-1.56-.18-3-.15-6 .06-9 .06-.84.72-1.47 1.56-1.53 2.04-.15 4.2-.21 6.36-.21s4.32.09 6.36.18c.81.06 1.5.69 1.56 1.53.24 3 .24 6 .06 9-.12.93-.9 1.62-1.83 1.59h-3.15l-6 3.9V24l6-3.9h3.15c2.97.03 5.46-2.25 5.7-5.19.21-3.18.18-6.39-.03-9.57a5.57 5.57 0 0 0-5.19-5.1c-2.13-.18-4.38-.24-6.63-.24zm-5.04 8.76c-.36 0-.66.3-.66.66v2.34c0 .33.18.63.48.78 1.62.78 3.42 1.2 5.22 1.26 1.8-.06 3.6-.48 5.22-1.26.3-.15.48-.45.48-.78V9.42c0-.09-.03-.15-.09-.21a.648.648 0 0 0-.87-.36c-1.5.66-3.12 1.02-4.77 1.05-1.65-.03-3.27-.42-4.77-1.08a.566.566 0 0 0-.24-.06z" })
650
919
  }
651
- ), er = ({
920
+ ), lr = ({
652
921
  title: e = "VPS AI Assistant",
653
922
  subtitle: t = "Customer portal support",
654
- onClose: r,
655
- onReset: n,
923
+ onClose: n,
924
+ onReset: r,
656
925
  onBack: s,
657
- showMinimize: l = !1,
926
+ showMinimize: o = !1,
658
927
  envStage: a,
659
928
  envPulse: i = !0
660
- }) => /* @__PURE__ */ k("header", { className: "chat-header", children: [
661
- /* @__PURE__ */ k("div", { className: "chat-header-left", children: [
662
- s && /* @__PURE__ */ o(
929
+ }) => /* @__PURE__ */ w("header", { className: "chat-header", children: [
930
+ /* @__PURE__ */ w("div", { className: "chat-header-left", children: [
931
+ s && /* @__PURE__ */ l(
663
932
  "button",
664
933
  {
665
934
  type: "button",
666
935
  onClick: s,
667
936
  className: "icon-btn-back",
668
937
  "aria-label": "Back",
669
- children: /* @__PURE__ */ o(Ot, { size: 16 })
938
+ children: /* @__PURE__ */ l($t, { size: 16 })
670
939
  }
671
940
  ),
672
- /* @__PURE__ */ o(
941
+ /* @__PURE__ */ l(
673
942
  "div",
674
943
  {
675
944
  className: "avatar-circle",
676
945
  "aria-hidden": "true",
677
- children: /* @__PURE__ */ o(Qt, { width: "16px", height: "16px", color: "white" })
946
+ children: /* @__PURE__ */ l(or, { width: "16px", height: "16px", color: "white" })
678
947
  }
679
948
  ),
680
- /* @__PURE__ */ k("div", { children: [
681
- /* @__PURE__ */ k("div", { className: "chat-header-title-row", children: [
682
- /* @__PURE__ */ o("h2", { className: "chat-header-title", children: e }),
683
- /* @__PURE__ */ o(Xt, { stage: a, pulse: i })
949
+ /* @__PURE__ */ w("div", { children: [
950
+ /* @__PURE__ */ w("div", { className: "chat-header-title-row", children: [
951
+ /* @__PURE__ */ l("h2", { className: "chat-header-title", children: e }),
952
+ /* @__PURE__ */ l(sr, { stage: a, pulse: i })
684
953
  ] }),
685
- /* @__PURE__ */ o("p", { className: "chat-header-subtitle", children: t || "Customer portal support" })
954
+ /* @__PURE__ */ l("p", { className: "chat-header-subtitle", children: t || "Customer portal support" })
686
955
  ] })
687
956
  ] }),
688
- /* @__PURE__ */ k("div", { className: "chat-header-actions", children: [
689
- n && /* @__PURE__ */ o(
957
+ /* @__PURE__ */ w("div", { className: "chat-header-actions", children: [
958
+ r && /* @__PURE__ */ l(
690
959
  "button",
691
960
  {
692
961
  type: "button",
693
- onClick: n,
962
+ onClick: r,
694
963
  className: "icon-btn-action",
695
964
  "aria-label": "Start a new conversation",
696
965
  title: "New conversation",
697
- children: /* @__PURE__ */ o(Yt, { size: 15 })
966
+ children: /* @__PURE__ */ l(Zt, { size: 15 })
698
967
  }
699
968
  ),
700
- r && /* @__PURE__ */ o(
969
+ n && /* @__PURE__ */ l(
701
970
  "button",
702
971
  {
703
972
  type: "button",
704
- onClick: r,
973
+ onClick: n,
705
974
  className: "icon-btn-action",
706
- "aria-label": l ? "Minimize chat" : "Close chat",
707
- children: /* @__PURE__ */ o(jt, { size: 16 })
975
+ "aria-label": o ? "Minimize chat" : "Close chat",
976
+ children: /* @__PURE__ */ l(Xt, { size: 16 })
708
977
  }
709
978
  )
710
979
  ] })
711
980
  ] });
712
- function tr(e, t) {
713
- const r = K(e);
714
- me(() => {
715
- var n;
716
- r.current && !e && ((n = t.current) == null || n.focus()), r.current = e;
981
+ function ar(e, t) {
982
+ const n = re(e);
983
+ ke(() => {
984
+ var r;
985
+ n.current && !e && ((r = t.current) == null || r.focus()), n.current = e;
717
986
  }, [e, t]);
718
987
  }
719
- function rr(e, t) {
720
- const r = t.trim().toLowerCase();
721
- return r ? e.filter(
722
- (n) => n.label.toLowerCase().includes(r) || n.query.toLowerCase().includes(r)
988
+ function ir(e, t) {
989
+ const n = t.trim().toLowerCase();
990
+ return n ? e.filter(
991
+ (r) => r.label.toLowerCase().includes(n) || r.query.toLowerCase().includes(n)
723
992
  ) : e;
724
993
  }
725
- const nr = ({
994
+ const cr = ({
726
995
  suggestions: e,
727
996
  onSelect: t,
728
- disabled: r,
729
- variant: n = "list"
730
- }) => e.length ? n === "badge" ? /* @__PURE__ */ o(
997
+ disabled: n,
998
+ variant: r = "list"
999
+ }) => e.length ? r === "badge" ? /* @__PURE__ */ l(
731
1000
  "ul",
732
1001
  {
733
1002
  className: "suggestions-badge-list",
734
1003
  "aria-label": "Suggested questions",
735
- children: e.map((s) => /* @__PURE__ */ o("li", { className: "suggestion-badge-item", children: /* @__PURE__ */ o(
1004
+ children: e.map((s) => /* @__PURE__ */ l("li", { className: "suggestion-badge-item", children: /* @__PURE__ */ l(
736
1005
  "button",
737
1006
  {
738
1007
  type: "button",
739
- disabled: r,
1008
+ disabled: n,
740
1009
  onClick: () => t(s),
741
1010
  title: s.query,
742
1011
  className: "suggestion-badge-btn",
@@ -744,870 +1013,1145 @@ const nr = ({
744
1013
  }
745
1014
  ) }, s.query))
746
1015
  }
747
- ) : /* @__PURE__ */ o("div", { className: "suggestions-list", children: e.map((s) => /* @__PURE__ */ o(
1016
+ ) : /* @__PURE__ */ l("div", { className: "suggestions-list", children: e.map((s) => /* @__PURE__ */ l(
748
1017
  "button",
749
1018
  {
750
1019
  type: "button",
751
- disabled: r,
1020
+ disabled: n,
752
1021
  onClick: () => t(s),
753
1022
  className: "suggestion-list-btn",
754
1023
  children: s.label
755
1024
  },
756
1025
  s.query
757
- )) }) : null, sr = ({
1026
+ )) }) : null, ur = ({
758
1027
  onSend: e,
759
1028
  disabled: t = !1,
760
- placeholder: r = "Ask something…"
1029
+ placeholder: n = "Ask something…"
761
1030
  }) => {
762
- const { suggestions: n, showSuggestions: s, suggestionBadgesEnabled: l } = ve(), [a, i] = j(""), d = K(null), h = (u) => {
763
- u && (u.style.height = "auto", u.style.height = `${Math.min(u.scrollHeight, 96)}px`);
1031
+ const { suggestions: r, showSuggestions: s, suggestionBadgesEnabled: o, models: a, selectedModelId: i, selectModel: u } = Be(), [h, g] = U(""), f = re(null), c = oe.useId(), p = (m) => {
1032
+ m && (m.style.height = "auto", m.style.height = `${Math.min(m.scrollHeight, 96)}px`);
764
1033
  };
765
- tr(t, d), me(() => {
766
- h(d.current);
767
- }, [a]);
768
- const g = Ce(() => {
769
- if (!l || t) return [];
770
- const u = a.trim();
771
- return u ? rr(n, u) : s ? n : [];
772
- }, [t, s, l, n, a]), v = (u) => {
773
- i(u.query);
774
- const m = d.current;
775
- m == null || m.focus();
776
- }, f = () => {
777
- const u = a.trim();
778
- !u || t || (e(u), i(""), d.current && (d.current.style.height = "auto"));
1034
+ ar(t, f), ke(() => {
1035
+ p(f.current);
1036
+ }, [h]);
1037
+ const b = ye(() => {
1038
+ if (!o || t) return [];
1039
+ const m = h.trim();
1040
+ return m ? ir(r, m) : s ? r : [];
1041
+ }, [t, s, o, r, h]), k = (m) => {
1042
+ g(m.query);
1043
+ const B = f.current;
1044
+ B == null || B.focus();
1045
+ }, v = () => {
1046
+ const m = h.trim();
1047
+ !m || t || (e(m), g(""), f.current && (f.current.style.height = "auto"));
779
1048
  };
780
- return /* @__PURE__ */ k("div", { className: "chat-input-wrapper", children: [
781
- /* @__PURE__ */ o(
782
- nr,
1049
+ return /* @__PURE__ */ w("div", { className: "chat-input-wrapper", children: [
1050
+ /* @__PURE__ */ l(
1051
+ cr,
783
1052
  {
784
1053
  variant: "badge",
785
- suggestions: g,
786
- onSelect: v,
1054
+ suggestions: b,
1055
+ onSelect: k,
787
1056
  disabled: t
788
1057
  }
789
1058
  ),
790
- /* @__PURE__ */ o("label", { htmlFor: "vps-chat-input", className: "sr-only", children: "Chat message" }),
791
- /* @__PURE__ */ k("div", { className: "chat-input-row", children: [
792
- /* @__PURE__ */ o(
1059
+ /* @__PURE__ */ l("label", { htmlFor: "vps-chat-input", className: "sr-only", children: "Chat message" }),
1060
+ /* @__PURE__ */ w("div", { className: "chat-input-row", children: [
1061
+ /* @__PURE__ */ l(
793
1062
  "textarea",
794
1063
  {
795
1064
  id: "vps-chat-input",
796
- ref: d,
1065
+ ref: f,
797
1066
  rows: 1,
798
- value: a,
1067
+ value: h,
799
1068
  disabled: t,
800
- placeholder: r,
801
- onChange: (u) => {
802
- i(u.target.value), h(u.target);
1069
+ placeholder: n,
1070
+ onChange: (m) => {
1071
+ g(m.target.value), p(m.target);
803
1072
  },
804
- onKeyDown: (u) => {
805
- u.key === "Enter" && !u.shiftKey && (u.preventDefault(), f());
1073
+ onKeyDown: (m) => {
1074
+ m.key === "Enter" && !m.shiftKey && (m.preventDefault(), v());
806
1075
  },
807
1076
  className: "chat-textarea"
808
1077
  }
809
1078
  ),
810
- /* @__PURE__ */ o(
1079
+ /* @__PURE__ */ l(
811
1080
  "button",
812
1081
  {
813
1082
  type: "button",
814
- onClick: f,
815
- disabled: t || !a.trim(),
1083
+ onClick: v,
1084
+ disabled: t || !h.trim(),
816
1085
  "aria-label": "Send message",
817
1086
  className: "chat-send-btn",
818
- children: /* @__PURE__ */ o(Ht, { size: 16 })
1087
+ children: /* @__PURE__ */ l(Ht, { size: 16 })
1088
+ }
1089
+ )
1090
+ ] }),
1091
+ a.length > 1 && /* @__PURE__ */ w("div", { className: "chat-model-picker", children: [
1092
+ /* @__PURE__ */ l("label", { htmlFor: c, children: "AI model" }),
1093
+ /* @__PURE__ */ w(
1094
+ "select",
1095
+ {
1096
+ id: c,
1097
+ "aria-label": "AI model",
1098
+ value: i,
1099
+ disabled: t,
1100
+ onChange: (m) => u(m.target.value),
1101
+ children: [
1102
+ /* @__PURE__ */ l("option", { value: "auto", children: "Automatic" }),
1103
+ a.map((m) => /* @__PURE__ */ l("option", { value: m.id, disabled: !m.configured, children: m.label }, m.id))
1104
+ ]
819
1105
  }
820
1106
  )
821
1107
  ] }),
822
- /* @__PURE__ */ k("p", { className: "chat-input-footer", children: [
1108
+ /* @__PURE__ */ w("p", { className: "chat-input-footer", children: [
823
1109
  "Powered by ",
824
- /* @__PURE__ */ o("span", { className: "chat-input-footer-brand", children: "VPS Veritas AI" })
1110
+ /* @__PURE__ */ l("span", { className: "chat-input-footer-brand", children: "VPS Veritas AI" })
825
1111
  ] })
826
1112
  ] });
827
1113
  };
828
- function lr({ defaultTagName: e, props: t, render: r, state: n = {}, stateAttributesMapping: s }) {
829
- let l = Se(or(n, s), t);
830
- if (!r) return c.createElement(e, l);
831
- if (typeof r == "function") return r(l, n);
832
- if (!c.isValidElement(r)) return null;
833
- let a = r.props, i = { ...Se(l, a), ref: ae(l.ref, a.ref) };
834
- return c.cloneElement(r, i);
835
- }
836
- function Se(...e) {
1114
+ function dr({ defaultTagName: e, props: t, render: n, state: r = {}, stateAttributesMapping: s }) {
1115
+ let o = ze(hr(r, s), t);
1116
+ if (!n) return d.createElement(e, o);
1117
+ if (typeof n == "function") return n(o, r);
1118
+ if (!d.isValidElement(n)) return null;
1119
+ let a = n.props, i = { ...ze(o, a), ref: Se(o.ref, a.ref) };
1120
+ return d.cloneElement(n, i);
1121
+ }
1122
+ function ze(...e) {
837
1123
  let t = {};
838
- for (let r of e) {
839
- if (!r) continue;
840
- let n = r;
841
- for (let s of Object.keys(n)) {
842
- let l = n[s];
843
- if (l === void 0) continue;
1124
+ for (let n of e) {
1125
+ if (!n) continue;
1126
+ let r = n;
1127
+ for (let s of Object.keys(r)) {
1128
+ let o = r[s];
1129
+ if (o === void 0) continue;
844
1130
  let a = t[s];
845
- s === "className" ? t[s] = [a, l].filter(Boolean).join(" ") : s === "style" ? t[s] = { ...a, ...l } : s === "ref" ? t[s] = ae(a, l) : ir(s) && typeof a == "function" && typeof l == "function" ? t[s] = ar(l, a) : t[s] = l;
1131
+ s === "className" ? t[s] = [a, o].filter(Boolean).join(" ") : s === "style" ? t[s] = { ...a, ...o } : s === "ref" ? t[s] = Se(a, o) : fr(s) && typeof a == "function" && typeof o == "function" ? t[s] = pr(o, a) : t[s] = o;
846
1132
  }
847
1133
  }
848
1134
  return t;
849
1135
  }
850
- function or(e, t) {
851
- var n;
852
- let r = {};
1136
+ function hr(e, t) {
1137
+ var r;
1138
+ let n = {};
853
1139
  for (let s of Object.keys(e)) {
854
- let l = e[s], a = (n = t == null ? void 0 : t[s]) == null ? void 0 : n.call(t, l);
1140
+ let o = e[s], a = (r = t == null ? void 0 : t[s]) == null ? void 0 : r.call(t, o);
855
1141
  if (a) {
856
- Object.assign(r, a);
1142
+ Object.assign(n, a);
857
1143
  continue;
858
1144
  }
859
1145
  if (s === "slot") {
860
- r["data-slot"] = l;
1146
+ n["data-slot"] = o;
861
1147
  continue;
862
1148
  }
863
- let i = `data-${String(s).replace(/[A-Z]/g, (d) => `-${d.toLowerCase()}`)}`;
864
- typeof l == "boolean" ? r[i] = l ? "" : void 0 : l != null && (r[i] = String(l));
1149
+ let i = `data-${String(s).replace(/[A-Z]/g, (u) => `-${u.toLowerCase()}`)}`;
1150
+ typeof o == "boolean" ? n[i] = o ? "" : void 0 : o != null && (n[i] = String(o));
865
1151
  }
866
- return r;
1152
+ return n;
867
1153
  }
868
- function ar(e, t) {
869
- return function(r) {
870
- e(r), r.defaultPrevented || t(r);
1154
+ function pr(e, t) {
1155
+ return function(n) {
1156
+ e(n), n.defaultPrevented || t(n);
871
1157
  };
872
1158
  }
873
- function ir(e) {
1159
+ function fr(e) {
874
1160
  return /^on[A-Z]/.test(e);
875
1161
  }
876
- function ae(...e) {
1162
+ function Se(...e) {
877
1163
  let t = e.filter(Boolean);
878
- if (t.length !== 0) return (r) => {
879
- for (let n of t) typeof n == "function" ? n(r) : n && (n.current = r);
1164
+ if (t.length !== 0) return (n) => {
1165
+ for (let r of t) typeof r == "function" ? r(n) : r && (r.current = n);
880
1166
  };
881
1167
  }
882
- var cr = 8, ur = 64, dr = 0, be = 0.5, fr = 180, hr = /* @__PURE__ */ new Set(["ArrowDown", "ArrowUp", "End", "Home", "PageDown", "PageUp", " "]), at = { start: !1, end: !1 }, pr = [], _e = { currentAnchorId: null, visibleMessageIds: pr };
883
- function gr({ content: e, scrollEdgeThreshold: t, spacer: r, viewport: n }) {
884
- if (!n || !e) return at;
885
- let s = Te({ content: e, spacer: r, viewport: n });
886
- return { start: n.scrollTop > t, end: s - n.scrollTop - n.clientHeight > t };
887
- }
888
- function mr({ content: e, scrollMargin: t, scrollPreviousItemPeek: r, spacer: n, viewport: s, visibleMessageIds: l }) {
889
- if (!e || !s) return _e;
890
- let a = s.getBoundingClientRect(), i = a.top + t + r, d = typeof IntersectionObserver > "u", h = [], g = null;
891
- for (let v of le(e, n)) {
892
- let f = v.dataset.messageId;
893
- if (!f) continue;
894
- let u = v.dataset.scrollAnchor === "true", m = u || d ? v.getBoundingClientRect() : null;
895
- (d && m ? m.bottom > i && m.top < a.bottom : l.has(f)) && h.push(f), u && m && m.top <= i + be && (g = f);
1168
+ var mr = 8, gr = 64, br = 0, Ie = 0.5, vr = 180, _r = /* @__PURE__ */ new Set(["ArrowDown", "ArrowUp", "End", "Home", "PageDown", "PageUp", " "]), mt = { start: !1, end: !1 }, wr = [], Me = { currentAnchorId: null, visibleMessageIds: wr };
1169
+ function yr({ content: e, scrollEdgeThreshold: t, spacer: n, viewport: r }) {
1170
+ if (!r || !e) return mt;
1171
+ let s = Ue({ content: e, spacer: n, viewport: r });
1172
+ return { start: r.scrollTop > t, end: s - r.scrollTop - r.clientHeight > t };
1173
+ }
1174
+ function kr({ content: e, scrollMargin: t, scrollPreviousItemPeek: n, spacer: r, viewport: s, visibleMessageIds: o }) {
1175
+ if (!e || !s) return Me;
1176
+ let a = s.getBoundingClientRect(), i = a.top + t + n, u = typeof IntersectionObserver > "u", h = [], g = null;
1177
+ for (let f of Ce(e, r)) {
1178
+ let c = f.dataset.messageId;
1179
+ if (!c) continue;
1180
+ let p = f.dataset.scrollAnchor === "true", b = p || u ? f.getBoundingClientRect() : null;
1181
+ (u && b ? b.bottom > i && b.top < a.bottom : o.has(c)) && h.push(c), p && b && b.top <= i + Ie && (g = c);
896
1182
  }
897
- return h.length === 0 && g === null ? _e : { currentAnchorId: g, visibleMessageIds: h };
1183
+ return h.length === 0 && g === null ? Me : { currentAnchorId: g, visibleMessageIds: h };
898
1184
  }
899
- function le(e, t) {
900
- return Array.from(e.children).filter((r) => r instanceof HTMLElement && r !== t);
1185
+ function Ce(e, t) {
1186
+ return Array.from(e.children).filter((n) => n instanceof HTMLElement && n !== t);
901
1187
  }
902
- function br(e, t) {
903
- for (let r = t; r < e.length; r++) {
904
- let n = e[r];
905
- if ((n == null ? void 0 : n.dataset.scrollAnchor) === "true") return n;
1188
+ function Cr(e, t) {
1189
+ for (let n = t; n < e.length; n++) {
1190
+ let r = e[n];
1191
+ if ((r == null ? void 0 : r.dataset.scrollAnchor) === "true") return r;
906
1192
  }
907
1193
  return null;
908
1194
  }
909
- function _r(e, t) {
910
- for (let r of e) if (r.dataset.scrollAnchor === "true" && !t.has(r)) return r;
1195
+ function Sr(e, t) {
1196
+ for (let n of e) if (n.dataset.scrollAnchor === "true" && !t.has(n)) return n;
911
1197
  return null;
912
1198
  }
913
- function vr(e, t) {
914
- var n;
915
- let r = 0;
916
- for (let s = t; s < e.length; s++) if (((n = e[s]) == null ? void 0 : n.dataset.scrollAnchor) === "true" && (r += 1, r > 1)) return !0;
1199
+ function Fr(e, t) {
1200
+ var r;
1201
+ let n = 0;
1202
+ for (let s = t; s < e.length; s++) if (((r = e[s]) == null ? void 0 : r.dataset.scrollAnchor) === "true" && (n += 1, n > 1)) return !0;
917
1203
  return !1;
918
1204
  }
919
- function yr(e) {
1205
+ function Tr(e) {
920
1206
  for (let t = e.length - 1; t >= 0; t--) {
921
- let r = e[t];
922
- if ((r == null ? void 0 : r.dataset.scrollAnchor) === "true") return r;
1207
+ let n = e[t];
1208
+ if ((n == null ? void 0 : n.dataset.scrollAnchor) === "true") return n;
923
1209
  }
924
1210
  return null;
925
1211
  }
926
- function wr({ content: e, spacer: t, viewport: r }) {
927
- let n = r.getBoundingClientRect();
928
- for (let s of le(e, t)) {
1212
+ function Er({ content: e, spacer: t, viewport: n }) {
1213
+ let r = n.getBoundingClientRect();
1214
+ for (let s of Ce(e, t)) {
929
1215
  if (!s.dataset.messageId) continue;
930
- let l = s.getBoundingClientRect();
931
- if (l.bottom > n.top && l.top < n.bottom) return s;
1216
+ let o = s.getBoundingClientRect();
1217
+ if (o.bottom > r.top && o.top < r.bottom) return s;
932
1218
  }
933
1219
  return null;
934
1220
  }
935
- function Cr({ align: e, element: t, scrollMargin: r, spacer: n, viewport: s }) {
936
- let l = it(t, s), a = t.getBoundingClientRect().height, i = Fr(n);
1221
+ function Rr({ align: e, element: t, scrollMargin: n, spacer: r, viewport: s }) {
1222
+ let o = gt(t, s), a = t.getBoundingClientRect().height, i = Ir(r);
937
1223
  if (e === "center") {
938
- let d = Math.max(0, s.clientHeight - i.start - i.end);
939
- return l - i.start - (d - a) / 2 - r;
1224
+ let u = Math.max(0, s.clientHeight - i.start - i.end);
1225
+ return o - i.start - (u - a) / 2 - n;
940
1226
  }
941
- if (e === "end") return l - s.clientHeight + a + i.end + r;
1227
+ if (e === "end") return o - s.clientHeight + a + i.end + n;
942
1228
  if (e === "nearest") {
943
- let d = l + a, h = s.scrollTop + i.start, g = s.scrollTop + s.clientHeight - i.end;
944
- return l >= h && d <= g ? s.scrollTop : l < h ? l - i.start - r : d - s.clientHeight + i.end + r;
1229
+ let u = o + a, h = s.scrollTop + i.start, g = s.scrollTop + s.clientHeight - i.end;
1230
+ return o >= h && u <= g ? s.scrollTop : o < h ? o - i.start - n : u - s.clientHeight + i.end + n;
945
1231
  }
946
- return l - i.start - r;
1232
+ return o - i.start - n;
947
1233
  }
948
- function it(e, t) {
949
- let r = e.getBoundingClientRect(), n = t.getBoundingClientRect();
950
- return r.top - n.top + t.scrollTop;
1234
+ function gt(e, t) {
1235
+ let n = e.getBoundingClientRect(), r = t.getBoundingClientRect();
1236
+ return n.top - r.top + t.scrollTop;
951
1237
  }
952
- function pe(e, t) {
1238
+ function Ae(e, t) {
953
1239
  return e.getBoundingClientRect().top - t.getBoundingClientRect().top;
954
1240
  }
955
- function kr({ content: e, scrollTop: t, spacer: r, viewport: n }) {
956
- let s = Te({ content: e, spacer: r, viewport: n });
957
- return t + n.clientHeight - s;
1241
+ function Ar({ content: e, scrollTop: t, spacer: n, viewport: r }) {
1242
+ let s = Ue({ content: e, spacer: n, viewport: r });
1243
+ return t + r.clientHeight - s;
958
1244
  }
959
- function Te({ content: e, spacer: t, viewport: r }) {
960
- let n = le(e, t), s = ct(e), l = r.getBoundingClientRect(), a = r.scrollTop, i = s.start + s.end;
961
- for (let d of n) {
962
- let h = d.getBoundingClientRect();
963
- i = Math.max(i, h.bottom - l.top + a + s.end);
1245
+ function Ue({ content: e, spacer: t, viewport: n }) {
1246
+ let r = Ce(e, t), s = bt(e), o = n.getBoundingClientRect(), a = n.scrollTop, i = s.start + s.end;
1247
+ for (let u of r) {
1248
+ let h = u.getBoundingClientRect();
1249
+ i = Math.max(i, h.bottom - o.top + a + s.end);
964
1250
  }
965
1251
  return i;
966
1252
  }
967
- function Sr(e) {
1253
+ function Nr(e) {
968
1254
  return Math.max(0, e.scrollHeight - e.clientHeight);
969
1255
  }
970
- function ct(e) {
1256
+ function bt(e) {
971
1257
  let t = window.getComputedStyle(e);
972
- return { end: Fe(t.paddingBlockEnd || t.paddingBottom), start: Fe(t.paddingBlockStart || t.paddingTop) };
1258
+ return { end: We(t.paddingBlockEnd || t.paddingBottom), start: We(t.paddingBlockStart || t.paddingTop) };
973
1259
  }
974
- function Fr(e) {
1260
+ function Ir(e) {
975
1261
  let t = e == null ? void 0 : e.parentElement;
976
- return t ? ct(t) : { end: 0, start: 0 };
1262
+ return t ? bt(t) : { end: 0, start: 0 };
977
1263
  }
978
- function Er(e) {
1264
+ function Mr(e) {
979
1265
  if (!e) return 0;
980
- let t = window.getComputedStyle(e), r = t.rowGap === "normal" ? t.gap : t.rowGap;
981
- return Fe(r);
1266
+ let t = window.getComputedStyle(e), n = t.rowGap === "normal" ? t.gap : t.rowGap;
1267
+ return We(n);
982
1268
  }
983
- function Fe(e) {
1269
+ function We(e) {
984
1270
  if (!e) return 0;
985
1271
  let t = Number.parseFloat(e);
986
1272
  return Number.isFinite(t) ? t : 0;
987
1273
  }
988
- function ut(e, t) {
989
- let r = e, n = /* @__PURE__ */ new Set();
990
- return { getSnapshot: () => r, hasListeners: () => n.size > 0, setSnapshot: (s) => {
991
- t(r, s) || (r = s, n.forEach((l) => l()));
992
- }, subscribe: (s, l, a) => {
993
- let i = n.size === 0;
994
- return n.add(s), i && (l == null || l()), () => {
995
- n.delete(s), n.size === 0 && (a == null || a());
1274
+ function vt(e, t) {
1275
+ let n = e, r = /* @__PURE__ */ new Set();
1276
+ return { getSnapshot: () => n, hasListeners: () => r.size > 0, setSnapshot: (s) => {
1277
+ t(n, s) || (n = s, r.forEach((o) => o()));
1278
+ }, subscribe: (s, o, a) => {
1279
+ let i = r.size === 0;
1280
+ return r.add(s), i && (o == null || o()), () => {
1281
+ r.delete(s), r.size === 0 && (a == null || a());
996
1282
  };
997
1283
  } };
998
1284
  }
999
- function Ue(e, t) {
1000
- return ut(e, t);
1285
+ function tt(e, t) {
1286
+ return vt(e, t);
1001
1287
  }
1002
- function Tr() {
1003
- return ut(_e, Ar);
1288
+ function Dr() {
1289
+ return vt(Me, Pr);
1004
1290
  }
1005
- function Rr(e, t) {
1291
+ function Br(e, t) {
1006
1292
  return e.start === t.start && e.end === t.end;
1007
1293
  }
1008
- function Ar(e, t) {
1009
- return e.currentAnchorId !== t.currentAnchorId || e.visibleMessageIds.length !== t.visibleMessageIds.length ? !1 : e.visibleMessageIds.every((r, n) => r === t.visibleMessageIds[n]);
1294
+ function Pr(e, t) {
1295
+ return e.currentAnchorId !== t.currentAnchorId || e.visibleMessageIds.length !== t.visibleMessageIds.length ? !1 : e.visibleMessageIds.every((n, r) => n === t.visibleMessageIds[r]);
1010
1296
  }
1011
- function Br({ autoScroll: e, defaultScrollPosition: t, scrollEdgeThreshold: r, scrollMargin: n, scrollPreviousItemPeek: s }) {
1012
- let l = c.useRef(e), a = c.useRef(!1), i = c.useRef(null), d = c.useRef(!1), h = c.useRef(r), g = c.useRef(0), v = c.useRef(null), f = c.useRef(0), u = c.useRef(e ? "following-bottom" : "free-scrolling"), m = c.useRef(/* @__PURE__ */ new Map()), T = c.useRef(null), _ = c.useRef(null), D = c.useRef(null), V = c.useRef(s), L = c.useRef(!0), $ = c.useRef(null), P = c.useRef(n), I = c.useRef(null), R = c.useRef(0), O = c.useRef(0), N = c.useRef(null), Z = c.useRef(null), U = c.useRef(null), b = c.useRef(null), y = c.useRef(null), S = c.useRef(null), F = c.useRef(null), B = c.useRef(null), A = c.useRef(null), E = c.useRef(/* @__PURE__ */ new Set()), W = c.useRef(/* @__PURE__ */ new WeakSet());
1013
- return U.current === null && (U.current = Ue(t === "end" || t === "last-anchor", (z, ce) => z === ce)), b.current === null && (b.current = Ue(at, Rr)), A.current === null && (A.current = Tr()), l.current = e, h.current = r, P.current = n, V.current = s, { autoScrollRef: l, autoscrollingRef: a, autoscrollingTimeoutRef: y, streamingTurnRef: D, contentRef: i, defaultScrollPositionAppliedRef: d, firstItemRef: v, itemCountRef: g, lastScrollTopRef: f, messageElementsRef: m, modeRef: u, pendingScrollFrameRef: I, pendingScrollToMessageRef: T, prependRestoreRef: _, preserveScrollOnPrependRef: L, pendingDefaultScrollStore: U.current, rootRef: $, scrollEdgeThresholdRef: h, scrollMarginRef: P, scrollPreviousItemPeekRef: V, spacerGapRef: R, spacerHeightRef: O, spacerRef: N, stateFrameRef: Z, stateStore: b.current, viewportRef: S, visibilityFrameRef: F, visibilityObserverRef: B, visibilityStore: A.current, visibleMessageIdsRef: E, handledScrollAnchorsRef: W };
1297
+ function xr({ autoScroll: e, defaultScrollPosition: t, scrollEdgeThreshold: n, scrollMargin: r, scrollPreviousItemPeek: s }) {
1298
+ let o = d.useRef(e), a = d.useRef(!1), i = d.useRef(null), u = d.useRef(!1), h = d.useRef(n), g = d.useRef(0), f = d.useRef(null), c = d.useRef(0), p = d.useRef(e ? "following-bottom" : "free-scrolling"), b = d.useRef(/* @__PURE__ */ new Map()), k = d.useRef(null), v = d.useRef(null), m = d.useRef(null), B = d.useRef(s), T = d.useRef(!0), x = d.useRef(null), C = d.useRef(r), N = d.useRef(null), I = d.useRef(0), z = d.useRef(0), q = d.useRef(null), le = d.useRef(null), K = d.useRef(null), y = d.useRef(null), A = d.useRef(null), M = d.useRef(null), D = d.useRef(null), P = d.useRef(null), O = d.useRef(null), L = d.useRef(/* @__PURE__ */ new Set()), Y = d.useRef(/* @__PURE__ */ new WeakSet());
1299
+ return K.current === null && (K.current = tt(t === "end" || t === "last-anchor", (ee, de) => ee === de)), y.current === null && (y.current = tt(mt, Br)), O.current === null && (O.current = Dr()), o.current = e, h.current = n, C.current = r, B.current = s, { autoScrollRef: o, autoscrollingRef: a, autoscrollingTimeoutRef: A, streamingTurnRef: m, contentRef: i, defaultScrollPositionAppliedRef: u, firstItemRef: f, itemCountRef: g, lastScrollTopRef: c, messageElementsRef: b, modeRef: p, pendingScrollFrameRef: N, pendingScrollToMessageRef: k, prependRestoreRef: v, preserveScrollOnPrependRef: T, pendingDefaultScrollStore: K.current, rootRef: x, scrollEdgeThresholdRef: h, scrollMarginRef: C, scrollPreviousItemPeekRef: B, spacerGapRef: I, spacerHeightRef: z, spacerRef: q, stateFrameRef: le, stateStore: y.current, viewportRef: M, visibilityFrameRef: D, visibilityObserverRef: P, visibilityStore: O.current, visibleMessageIdsRef: L, handledScrollAnchorsRef: Y };
1014
1300
  }
1015
- function dt(e) {
1301
+ function _t(e) {
1016
1302
  e.pendingDefaultScrollStore.setSnapshot(!1);
1017
1303
  }
1018
- function ge(e) {
1019
- e.defaultScrollPositionAppliedRef.current = !0, dt(e);
1304
+ function Ne(e) {
1305
+ e.defaultScrollPositionAppliedRef.current = !0, _t(e);
1020
1306
  }
1021
- function Dr({ refs: e, commitScrollState: t, scheduleStateCommit: r, scheduleVisibilitySync: n }) {
1022
- let { streamingTurnRef: s, autoScrollRef: l, autoscrollingRef: a, autoscrollingTimeoutRef: i, contentRef: d, itemCountRef: h, messageElementsRef: g, modeRef: v, pendingScrollToMessageRef: f, prependRestoreRef: u, scrollMarginRef: m, scrollPreviousItemPeekRef: T, spacerGapRef: _, spacerHeightRef: D, spacerRef: V, viewportRef: L } = e, $ = c.useCallback((b) => {
1023
- i.current !== null && (window.clearTimeout(i.current), i.current = null), a.current !== b && (a.current = b, t()), b && (i.current = window.setTimeout(() => {
1307
+ function Lr({ refs: e, commitScrollState: t, scheduleStateCommit: n, scheduleVisibilitySync: r }) {
1308
+ let { streamingTurnRef: s, autoScrollRef: o, autoscrollingRef: a, autoscrollingTimeoutRef: i, contentRef: u, itemCountRef: h, messageElementsRef: g, modeRef: f, pendingScrollToMessageRef: c, prependRestoreRef: p, scrollMarginRef: b, scrollPreviousItemPeekRef: k, spacerGapRef: v, spacerHeightRef: m, spacerRef: B, viewportRef: T } = e, x = d.useCallback((y) => {
1309
+ i.current !== null && (window.clearTimeout(i.current), i.current = null), a.current !== y && (a.current = y, t()), y && (i.current = window.setTimeout(() => {
1024
1310
  i.current = null, a.current = !1, t();
1025
- }, fr));
1026
- }, [t]), P = c.useCallback((b) => {
1027
- let y = V.current;
1028
- if (!y) return;
1029
- let S = Math.max(0, Math.ceil(b));
1030
- D.current !== S && (D.current = S, y.hidden = S === 0, y.style.height = `${S}px`, y.style.marginTop = S > 0 ? `${-_.current}px` : "");
1031
- }, []), I = c.useCallback((b, { behavior: y = "auto", autoscrolling: S = !1 } = {}) => {
1032
- let F = L.current;
1033
- if (!F) return;
1034
- let B = Math.max(0, b);
1035
- if (Math.abs(F.scrollTop - B) <= be) {
1036
- F.scrollTop = B, t();
1311
+ }, vr));
1312
+ }, [t]), C = d.useCallback((y) => {
1313
+ let A = B.current;
1314
+ if (!A) return;
1315
+ let M = Math.max(0, Math.ceil(y));
1316
+ m.current !== M && (m.current = M, A.hidden = M === 0, A.style.height = `${M}px`, A.style.marginTop = M > 0 ? `${-v.current}px` : "");
1317
+ }, []), N = d.useCallback((y, { behavior: A = "auto", autoscrolling: M = !1 } = {}) => {
1318
+ let D = T.current;
1319
+ if (!D) return;
1320
+ let P = Math.max(0, y);
1321
+ if (Math.abs(D.scrollTop - P) <= Ie) {
1322
+ D.scrollTop = P, t();
1037
1323
  return;
1038
1324
  }
1039
- S && $(!0), F.scrollTo({ top: B, behavior: y }), r();
1040
- }, [t, r, $]), R = c.useCallback(({ behavior: b = "auto" } = {}) => L.current ? (P(0), s.current = null, v.current = "free-scrolling", I(0, { behavior: b }), n(), !0) : !1, [n, I, P]), O = c.useCallback(({ behavior: b = "auto" } = {}) => {
1041
- let y = L.current;
1042
- return y ? (P(0), s.current = null, v.current = l.current ? "following-bottom" : "free-scrolling", I(Sr(y), { autoscrolling: !0, behavior: b }), n(), !0) : !1;
1043
- }, [n, I, P]), N = c.useCallback((b, { align: y = "start", behavior: S = "auto", scrollMargin: F = m.current } = {}, { keepPreviousPeek: B = !1 } = {}) => {
1044
- let A = d.current, E = L.current;
1045
- if (!A || !E || !A.contains(b)) return !1;
1046
- let W = Cr({ align: y, element: b, scrollMargin: B ? F + T.current : F, spacer: V.current, viewport: E }), z = kr({ content: A, scrollTop: W, spacer: V.current, viewport: E });
1047
- return P(z), u.current = { element: b, viewportTop: pe(b, E) }, v.current = B ? "anchored-to-message" : "settling-jump", s.current = B ? b : null, I(W, { behavior: S }), n(), !0;
1048
- }, [n, I, P]), Z = c.useCallback(() => {
1049
- let b = s.current;
1050
- return !b || !b.isConnected || v.current !== "anchored-to-message" ? !1 : N(b, { align: "start" }, { keepPreviousPeek: !0 });
1051
- }, [N]), U = c.useCallback((b, y) => {
1052
- let S = g.current.get(b);
1053
- return S ? (ge(e), N(S, y) ? (f.current = null, !0) : (f.current = { messageId: b, options: y }, !0)) : h.current === 0 ? (f.current = { messageId: b, options: y }, ge(e), !0) : !1;
1054
- }, [N]);
1055
- return { flushPendingScrollToMessage: c.useCallback(() => {
1056
- let b = f.current;
1057
- if (!b) return !1;
1058
- let y = g.current.get(b.messageId);
1059
- return !y || !N(y, b.options) ? !1 : (f.current = null, ge(e), !0);
1060
- }, [N]), reanchorToAnchoredMessage: Z, scrollToElement: N, scrollToEnd: O, scrollToMessage: U, scrollToStart: R };
1061
- }
1062
- function je(e, t) {
1063
- return c.useCallback((r) => {
1064
- e.current = r, r && t();
1325
+ M && x(!0), D.scrollTo({ top: P, behavior: A }), n();
1326
+ }, [t, n, x]), I = d.useCallback(({ behavior: y = "auto" } = {}) => T.current ? (C(0), s.current = null, f.current = "free-scrolling", N(0, { behavior: y }), r(), !0) : !1, [r, N, C]), z = d.useCallback(({ behavior: y = "auto" } = {}) => {
1327
+ let A = T.current;
1328
+ return A ? (C(0), s.current = null, f.current = o.current ? "following-bottom" : "free-scrolling", N(Nr(A), { autoscrolling: !0, behavior: y }), r(), !0) : !1;
1329
+ }, [r, N, C]), q = d.useCallback((y, { align: A = "start", behavior: M = "auto", scrollMargin: D = b.current } = {}, { keepPreviousPeek: P = !1 } = {}) => {
1330
+ let O = u.current, L = T.current;
1331
+ if (!O || !L || !O.contains(y)) return !1;
1332
+ let Y = Rr({ align: A, element: y, scrollMargin: P ? D + k.current : D, spacer: B.current, viewport: L }), ee = Ar({ content: O, scrollTop: Y, spacer: B.current, viewport: L });
1333
+ return C(ee), p.current = { element: y, viewportTop: Ae(y, L) }, f.current = P ? "anchored-to-message" : "settling-jump", s.current = P ? y : null, N(Y, { behavior: M }), r(), !0;
1334
+ }, [r, N, C]), le = d.useCallback(() => {
1335
+ let y = s.current;
1336
+ return !y || !y.isConnected || f.current !== "anchored-to-message" ? !1 : q(y, { align: "start" }, { keepPreviousPeek: !0 });
1337
+ }, [q]), K = d.useCallback((y, A) => {
1338
+ let M = g.current.get(y);
1339
+ return M ? (Ne(e), q(M, A) ? (c.current = null, !0) : (c.current = { messageId: y, options: A }, !0)) : h.current === 0 ? (c.current = { messageId: y, options: A }, Ne(e), !0) : !1;
1340
+ }, [q]);
1341
+ return { flushPendingScrollToMessage: d.useCallback(() => {
1342
+ let y = c.current;
1343
+ if (!y) return !1;
1344
+ let A = g.current.get(y.messageId);
1345
+ return !A || !q(A, y.options) ? !1 : (c.current = null, Ne(e), !0);
1346
+ }, [q]), reanchorToAnchoredMessage: le, scrollToElement: q, scrollToEnd: z, scrollToMessage: K, scrollToStart: I };
1347
+ }
1348
+ function rt(e, t) {
1349
+ return d.useCallback((n) => {
1350
+ e.current = n, n && t();
1065
1351
  }, [e, t]);
1066
1352
  }
1067
- function Mr({ autoScroll: e = !1, defaultScrollPosition: t = "end", scrollEdgeThreshold: r = cr, scrollPreviousItemPeek: n = ur, scrollMargin: s = dr }) {
1068
- let l = Br({ autoScroll: e, defaultScrollPosition: t, scrollEdgeThreshold: r, scrollMargin: s, scrollPreviousItemPeek: n }), { streamingTurnRef: a, autoScrollRef: i, autoscrollingRef: d, autoscrollingTimeoutRef: h, contentRef: g, defaultScrollPositionAppliedRef: v, firstItemRef: f, itemCountRef: u, lastScrollTopRef: m, messageElementsRef: T, modeRef: _, pendingScrollFrameRef: D, pendingScrollToMessageRef: V, prependRestoreRef: L, preserveScrollOnPrependRef: $, pendingDefaultScrollStore: P, rootRef: I, scrollEdgeThresholdRef: R, scrollMarginRef: O, scrollPreviousItemPeekRef: N, spacerGapRef: Z, spacerHeightRef: U, spacerRef: b, stateFrameRef: y, stateStore: S, viewportRef: F, visibilityFrameRef: B, visibilityObserverRef: A, visibilityStore: E, visibleMessageIdsRef: W, handledScrollAnchorsRef: z } = l, ce = c.useRef(t);
1069
- ce.current !== t && (ce.current = t, v.current = !1);
1070
- let ue = c.useCallback((p) => {
1071
- let w = I.current, C = F.current, M = [p.start && "start", p.end && "end"].filter(Boolean).join(" "), J = d.current;
1072
- for (let G of [w, C]) G && (M ? G.setAttribute("data-scrollable", M) : G.removeAttribute("data-scrollable"), G.toggleAttribute("data-autoscrolling", J));
1073
- }, []), Re = c.useCallback((p) => {
1074
- var M;
1075
- let w = ((M = F.current) == null ? void 0 : M.scrollTop) ?? 0, C = w < m.current - be;
1076
- m.current = w, i.current && !p.end && _.current !== "settling-jump" && _.current !== "anchored-to-message" ? _.current = "following-bottom" : _.current === "following-bottom" && p.end && C && !d.current && (_.current = "free-scrolling");
1077
- }, []), Y = c.useCallback(() => {
1078
- let p = gr({ content: g.current, scrollEdgeThreshold: R.current, spacer: b.current, viewport: F.current });
1079
- Re(p);
1080
- let w = _.current === "following-bottom" ? { ...p, end: !1 } : p;
1081
- ue(w), S.setSnapshot(w);
1082
- }, [Re, S, ue]), ne = c.useCallback(() => {
1083
- y.current === null && (y.current = window.requestAnimationFrame(() => {
1084
- y.current = null, Y();
1353
+ function qr({ autoScroll: e = !1, defaultScrollPosition: t = "end", scrollEdgeThreshold: n = mr, scrollPreviousItemPeek: r = gr, scrollMargin: s = br }) {
1354
+ let o = xr({ autoScroll: e, defaultScrollPosition: t, scrollEdgeThreshold: n, scrollMargin: s, scrollPreviousItemPeek: r }), { streamingTurnRef: a, autoScrollRef: i, autoscrollingRef: u, autoscrollingTimeoutRef: h, contentRef: g, defaultScrollPositionAppliedRef: f, firstItemRef: c, itemCountRef: p, lastScrollTopRef: b, messageElementsRef: k, modeRef: v, pendingScrollFrameRef: m, pendingScrollToMessageRef: B, prependRestoreRef: T, preserveScrollOnPrependRef: x, pendingDefaultScrollStore: C, rootRef: N, scrollEdgeThresholdRef: I, scrollMarginRef: z, scrollPreviousItemPeekRef: q, spacerGapRef: le, spacerHeightRef: K, spacerRef: y, stateFrameRef: A, stateStore: M, viewportRef: D, visibilityFrameRef: P, visibilityObserverRef: O, visibilityStore: L, visibleMessageIdsRef: Y, handledScrollAnchorsRef: ee } = o, de = d.useRef(t);
1355
+ de.current !== t && (de.current = t, f.current = !1);
1356
+ let ne = d.useCallback((_) => {
1357
+ let F = N.current, E = D.current, W = [_.start && "start", _.end && "end"].filter(Boolean).join(" "), ce = u.current;
1358
+ for (let G of [F, E]) G && (W ? G.setAttribute("data-scrollable", W) : G.removeAttribute("data-scrollable"), G.toggleAttribute("data-autoscrolling", ce));
1359
+ }, []), he = d.useCallback((_) => {
1360
+ var W;
1361
+ let F = ((W = D.current) == null ? void 0 : W.scrollTop) ?? 0, E = F < b.current - Ie;
1362
+ b.current = F, i.current && !_.end && v.current !== "settling-jump" && v.current !== "anchored-to-message" ? v.current = "following-bottom" : v.current === "following-bottom" && _.end && E && !u.current && (v.current = "free-scrolling");
1363
+ }, []), J = d.useCallback(() => {
1364
+ let _ = yr({ content: g.current, scrollEdgeThreshold: I.current, spacer: y.current, viewport: D.current });
1365
+ he(_);
1366
+ let F = v.current === "following-bottom" ? { ..._, end: !1 } : _;
1367
+ ne(F), M.setSnapshot(F);
1368
+ }, [he, M, ne]), ae = d.useCallback(() => {
1369
+ A.current === null && (A.current = window.requestAnimationFrame(() => {
1370
+ A.current = null, J();
1085
1371
  }));
1086
- }, [Y]), x = c.useCallback(() => {
1087
- E.hasListeners() && B.current === null && (B.current = window.requestAnimationFrame(() => {
1088
- B.current = null, E.hasListeners() && E.setSnapshot(mr({ content: g.current, scrollMargin: O.current, scrollPreviousItemPeek: N.current, spacer: b.current, viewport: F.current, visibleMessageIds: W.current }));
1372
+ }, [J]), $ = d.useCallback(() => {
1373
+ L.hasListeners() && P.current === null && (P.current = window.requestAnimationFrame(() => {
1374
+ P.current = null, L.hasListeners() && L.setSnapshot(kr({ content: g.current, scrollMargin: z.current, scrollPreviousItemPeek: q.current, spacer: y.current, viewport: D.current, visibleMessageIds: Y.current }));
1089
1375
  }));
1090
- }, [E]), { flushPendingScrollToMessage: de, reanchorToAnchoredMessage: Ae, scrollToElement: se, scrollToEnd: q, scrollToMessage: Be, scrollToStart: fe } = Dr({ refs: l, commitScrollState: Y, scheduleStateCommit: ne, scheduleVisibilitySync: x }), De = c.useCallback(() => {
1091
- let p = L.current, w = F.current;
1092
- if (!p || !w || !p.element.isConnected) return !1;
1093
- let C = pe(p.element, w) - p.viewportTop;
1094
- return Math.abs(C) <= be ? !1 : (w.scrollTop += C, p.viewportTop = pe(p.element, w), ne(), x(), !0);
1095
- }, [ne, x]), Q = c.useCallback(() => {
1096
- let p = g.current, w = F.current;
1097
- if (!p || !w) {
1098
- L.current = null;
1376
+ }, [L]), { flushPendingScrollToMessage: pe, reanchorToAnchoredMessage: Te, scrollToElement: R, scrollToEnd: S, scrollToMessage: V, scrollToStart: fe } = Lr({ refs: o, commitScrollState: J, scheduleStateCommit: ae, scheduleVisibilitySync: $ }), me = d.useCallback(() => {
1377
+ let _ = T.current, F = D.current;
1378
+ if (!_ || !F || !_.element.isConnected) return !1;
1379
+ let E = Ae(_.element, F) - _.viewportTop;
1380
+ return Math.abs(E) <= Ie ? !1 : (F.scrollTop += E, _.viewportTop = Ae(_.element, F), ae(), $(), !0);
1381
+ }, [ae, $]), ie = d.useCallback(() => {
1382
+ let _ = g.current, F = D.current;
1383
+ if (!_ || !F) {
1384
+ T.current = null;
1099
1385
  return;
1100
1386
  }
1101
- let C = wr({ content: p, spacer: b.current, viewport: w });
1102
- L.current = C ? { element: C, viewportTop: pe(C, w) } : null;
1103
- }, []), Me = c.useCallback(() => {
1104
- D.current === null && (D.current = window.requestAnimationFrame(() => {
1105
- D.current = null, de() && Q();
1387
+ let E = Er({ content: _, spacer: y.current, viewport: F });
1388
+ T.current = E ? { element: E, viewportTop: Ae(E, F) } : null;
1389
+ }, []), se = d.useCallback(() => {
1390
+ m.current === null && (m.current = window.requestAnimationFrame(() => {
1391
+ m.current = null, pe() && ie();
1106
1392
  }));
1107
- }, [Q, de]), he = c.useCallback(() => {
1108
- if (!t || v.current || u.current === 0) return !1;
1109
- let p = !1;
1393
+ }, [ie, pe]), ge = d.useCallback(() => {
1394
+ if (!t || f.current || p.current === 0) return !1;
1395
+ let _ = !1;
1110
1396
  if (t === "last-anchor") {
1111
- let w = g.current, C = F.current, M = w && C ? yr(le(w, b.current)) : null;
1112
- if (!w || !C || !M) p = q({ behavior: "auto" });
1397
+ let F = g.current, E = D.current, W = F && E ? Tr(Ce(F, y.current)) : null;
1398
+ if (!F || !E || !W) _ = S({ behavior: "auto" });
1113
1399
  else {
1114
- let J = it(M, C);
1115
- p = Te({ content: w, spacer: b.current, viewport: C }) - J <= C.clientHeight ? q({ behavior: "auto" }) : se(M, { align: "start" }, { keepPreviousPeek: !0 });
1400
+ let ce = gt(W, E);
1401
+ _ = Ue({ content: F, spacer: y.current, viewport: E }) - ce <= E.clientHeight ? S({ behavior: "auto" }) : R(W, { align: "start" }, { keepPreviousPeek: !0 });
1116
1402
  }
1117
- } else p = t === "end" ? q({ behavior: "auto" }) : fe({ behavior: "auto" });
1118
- return p ? (ge(l), !0) : !1;
1119
- }, [t, se, q, fe]), Ie = c.useCallback(() => {
1120
- let p = g.current;
1121
- if (!p) return;
1122
- let w = le(p, b.current), C = u.current, M = f.current;
1123
- u.current = w.length, f.current = w[0] ?? null, (() => {
1124
- if (de()) return;
1125
- if (C === 0) {
1126
- if (he() || w.length > 0 && i.current && q({ behavior: "auto" })) return;
1127
- Y(), x();
1403
+ } else _ = t === "end" ? S({ behavior: "auto" }) : fe({ behavior: "auto" });
1404
+ return _ ? (Ne(o), !0) : !1;
1405
+ }, [t, R, S, fe]), Ee = d.useCallback(() => {
1406
+ let _ = g.current;
1407
+ if (!_) return;
1408
+ let F = Ce(_, y.current), E = p.current, W = c.current;
1409
+ p.current = F.length, c.current = F[0] ?? null, (() => {
1410
+ if (pe()) return;
1411
+ if (E === 0) {
1412
+ if (ge() || F.length > 0 && i.current && S({ behavior: "auto" })) return;
1413
+ J(), $();
1128
1414
  return;
1129
1415
  }
1130
- let J = M ? w.indexOf(M) : -1;
1131
- if ($.current && J > 0) {
1132
- De();
1416
+ let ce = W ? F.indexOf(W) : -1;
1417
+ if (x.current && ce > 0) {
1418
+ me();
1133
1419
  return;
1134
1420
  }
1135
- if (w.length > C) {
1136
- let G = br(w, C);
1421
+ if (F.length > E) {
1422
+ let G = Cr(F, E);
1137
1423
  if (G) {
1138
- if (i.current && _.current === "following-bottom" && vr(w, C)) {
1139
- q({ behavior: "auto" });
1424
+ if (i.current && v.current === "following-bottom" && Fr(F, E)) {
1425
+ S({ behavior: "auto" });
1140
1426
  return;
1141
1427
  }
1142
- se(G, { align: "start" }, { keepPreviousPeek: !0 }), z.current.add(G);
1428
+ R(G, { align: "start" }, { keepPreviousPeek: !0 }), ee.current.add(G);
1143
1429
  return;
1144
1430
  }
1145
1431
  }
1146
- if (w.length === C) {
1147
- let G = _r(w, z.current);
1432
+ if (F.length === E) {
1433
+ let G = Sr(F, ee.current);
1148
1434
  if (G) {
1149
- se(G, { align: "start" }, { keepPreviousPeek: !0 }), z.current.add(G);
1435
+ R(G, { align: "start" }, { keepPreviousPeek: !0 }), ee.current.add(G);
1150
1436
  return;
1151
1437
  }
1152
1438
  }
1153
- _.current === "following-bottom" && i.current ? q({ behavior: "auto" }) : (Y(), x());
1154
- })(), Q();
1155
- }, [he, Q, Y, de, De, x, se, q]), Ne = c.useCallback(() => {
1156
- if (_.current === "following-bottom" && i.current) {
1157
- q({ behavior: "auto" });
1439
+ v.current === "following-bottom" && i.current ? S({ behavior: "auto" }) : (J(), $());
1440
+ })(), ie();
1441
+ }, [ge, ie, J, pe, me, $, R, S]), Re = d.useCallback(() => {
1442
+ if (v.current === "following-bottom" && i.current) {
1443
+ S({ behavior: "auto" });
1158
1444
  return;
1159
1445
  }
1160
- let p = U.current;
1161
- if (Ae()) {
1162
- i.current && p > 0 && U.current === 0 && q({ behavior: "auto" });
1446
+ let _ = K.current;
1447
+ if (Te()) {
1448
+ i.current && _ > 0 && K.current === 0 && S({ behavior: "auto" });
1163
1449
  return;
1164
1450
  }
1165
- ne(), x();
1166
- }, [Ae, ne, x, q]), Pe = c.useCallback(() => {
1167
- let p = F.current;
1168
- if (!(!p || !E.hasListeners())) {
1451
+ ae(), $();
1452
+ }, [Te, ae, $, S]), X = d.useCallback(() => {
1453
+ let _ = D.current;
1454
+ if (!(!_ || !L.hasListeners())) {
1169
1455
  if (typeof IntersectionObserver > "u") {
1170
- x();
1456
+ $();
1171
1457
  return;
1172
1458
  }
1173
- A.current || (A.current = new IntersectionObserver((w) => {
1174
- for (let C of w) {
1175
- let M = C.target.dataset.messageId;
1176
- M && (C.isIntersecting ? W.current.add(M) : W.current.delete(M));
1459
+ O.current || (O.current = new IntersectionObserver((F) => {
1460
+ for (let E of F) {
1461
+ let W = E.target.dataset.messageId;
1462
+ W && (E.isIntersecting ? Y.current.add(W) : Y.current.delete(W));
1177
1463
  }
1178
- x();
1179
- }, { root: p, rootMargin: `${-(O.current + N.current)}px 0px 0px 0px`, threshold: [0, 0.01, 0.5, 1] })), T.current.forEach((w) => {
1180
- var C;
1181
- (C = A.current) == null || C.observe(w);
1182
- }), x();
1464
+ $();
1465
+ }, { root: _, rootMargin: `${-(z.current + q.current)}px 0px 0px 0px`, threshold: [0, 0.01, 0.5, 1] })), k.current.forEach((F) => {
1466
+ var E;
1467
+ (E = O.current) == null || E.observe(F);
1468
+ }), $();
1183
1469
  }
1184
- }, [x, E]), xe = c.useCallback(() => {
1185
- var p;
1186
- B.current !== null && (window.cancelAnimationFrame(B.current), B.current = null), (p = A.current) == null || p.disconnect(), A.current = null, W.current.clear(), E.setSnapshot(_e);
1187
- }, [E]), _t = c.useCallback((p, w, C) => {
1188
- var M, J, G;
1189
- if (w) {
1190
- T.current.set(p, w), (M = A.current) == null || M.observe(w), x(), ((J = V.current) == null ? void 0 : J.messageId) === p && Me();
1470
+ }, [$, L]), j = d.useCallback(() => {
1471
+ var _;
1472
+ P.current !== null && (window.cancelAnimationFrame(P.current), P.current = null), (_ = O.current) == null || _.disconnect(), O.current = null, Y.current.clear(), L.setSnapshot(Me);
1473
+ }, [L]), Z = d.useCallback((_, F, E) => {
1474
+ var W, ce, G;
1475
+ if (F) {
1476
+ k.current.set(_, F), (W = O.current) == null || W.observe(F), $(), ((ce = B.current) == null ? void 0 : ce.messageId) === _ && se();
1191
1477
  return;
1192
1478
  }
1193
- C && T.current.get(p) === C && (T.current.delete(p), W.current.delete(p), (G = A.current) == null || G.unobserve(C), x());
1194
- }, [Me, x]), Le = c.useCallback(() => {
1195
- (_.current === "following-bottom" || _.current === "anchored-to-message" || _.current === "settling-jump") && (a.current = null, _.current = "free-scrolling");
1196
- }, []), Oe = c.useCallback(() => ue(S.getSnapshot()), [S, ue]), He = je(I, Oe), ze = je(F, Oe), qe = c.useCallback((p) => {
1197
- g.current = p;
1198
- }, []), Ge = c.useCallback((p) => {
1199
- b.current = p, Z.current = Er((p == null ? void 0 : p.parentElement) ?? null);
1200
- }, []), Ve = c.useCallback(() => {
1201
- Y(), x(), Q();
1202
- }, [Q, Y, x]), vt = c.useMemo(() => ({ handleContentChange: Ie, handleResize: Ne, observeVisibility: Pe, pendingDefaultScrollStore: P, preserveScrollOnPrependRef: $, scrollToEnd: q, scrollToMessage: Be, scrollToStart: fe, setContentElement: qe, setRootElement: He, setSpacerElement: Ge, setViewportElement: ze, stateStore: S, syncAfterScroll: Ve, unobserveVisibility: xe, userScrollIntent: Le, viewportRef: F, visibilityStore: E }), [Ie, Ne, Pe, P, q, Be, fe, qe, He, Ge, ze, S, Ve, xe, Le, E]);
1203
- return c.useLayoutEffect(() => {
1204
- he() || u.current === 0 && dt(l);
1205
- }, [he]), c.useEffect(() => () => {
1206
- var p;
1207
- y.current !== null && (window.cancelAnimationFrame(y.current), y.current = null), B.current !== null && (window.cancelAnimationFrame(B.current), B.current = null), h.current !== null && (window.clearTimeout(h.current), h.current = null), D.current !== null && (window.cancelAnimationFrame(D.current), D.current = null), (p = A.current) == null || p.disconnect(), A.current = null;
1208
- }, []), c.useLayoutEffect(() => {
1209
- if (e && _.current === "following-bottom" && u.current > 0) {
1210
- q({ behavior: "auto" });
1479
+ E && k.current.get(_) === E && (k.current.delete(_), Y.current.delete(_), (G = O.current) == null || G.unobserve(E), $());
1480
+ }, [se, $]), Q = d.useCallback(() => {
1481
+ (v.current === "following-bottom" || v.current === "anchored-to-message" || v.current === "settling-jump") && (a.current = null, v.current = "free-scrolling");
1482
+ }, []), be = d.useCallback(() => ne(M.getSnapshot()), [M, ne]), je = rt(N, be), Ye = rt(D, be), Je = d.useCallback((_) => {
1483
+ g.current = _;
1484
+ }, []), Ke = d.useCallback((_) => {
1485
+ y.current = _, le.current = Mr((_ == null ? void 0 : _.parentElement) ?? null);
1486
+ }, []), Qe = d.useCallback(() => {
1487
+ J(), $(), ie();
1488
+ }, [ie, J, $]), Tt = d.useMemo(() => ({ handleContentChange: Ee, handleResize: Re, observeVisibility: X, pendingDefaultScrollStore: C, preserveScrollOnPrependRef: x, scrollToEnd: S, scrollToMessage: V, scrollToStart: fe, setContentElement: Je, setRootElement: je, setSpacerElement: Ke, setViewportElement: Ye, stateStore: M, syncAfterScroll: Qe, unobserveVisibility: j, userScrollIntent: Q, viewportRef: D, visibilityStore: L }), [Ee, Re, X, C, S, V, fe, Je, je, Ke, Ye, M, Qe, j, Q, L]);
1489
+ return d.useLayoutEffect(() => {
1490
+ ge() || p.current === 0 && _t(o);
1491
+ }, [ge]), d.useEffect(() => () => {
1492
+ var _;
1493
+ A.current !== null && (window.cancelAnimationFrame(A.current), A.current = null), P.current !== null && (window.cancelAnimationFrame(P.current), P.current = null), h.current !== null && (window.clearTimeout(h.current), h.current = null), m.current !== null && (window.cancelAnimationFrame(m.current), m.current = null), (_ = O.current) == null || _.disconnect(), O.current = null;
1494
+ }, []), d.useLayoutEffect(() => {
1495
+ if (e && v.current === "following-bottom" && p.current > 0) {
1496
+ S({ behavior: "auto" });
1211
1497
  return;
1212
1498
  }
1213
- Y();
1214
- }, [e, Y, q]), { context: vt, registerMessage: _t };
1499
+ J();
1500
+ }, [e, J, S]), { context: Tt, registerMessage: Z };
1215
1501
  }
1216
- function Ir(e) {
1217
- let t = c.useRef(e);
1502
+ function Or(e) {
1503
+ let t = d.useRef(e);
1218
1504
  return t.current = e, t;
1219
1505
  }
1220
- var ft = c.createContext(null), ht = c.createContext(null);
1221
- function ie() {
1222
- let e = c.useContext(ft);
1506
+ var wt = d.createContext(null), yt = d.createContext(null);
1507
+ function Fe() {
1508
+ let e = d.useContext(wt);
1223
1509
  if (!e) throw new Error("useMessageScroller must be used within a MessageScroller.");
1224
1510
  return e;
1225
1511
  }
1226
- function Nr() {
1227
- let e = c.useContext(ht);
1512
+ function $r() {
1513
+ let e = d.useContext(yt);
1228
1514
  if (!e) throw new Error("MessageScrollerItem must be used within a MessageScroller.");
1229
1515
  return e;
1230
1516
  }
1231
- function Pr({ autoScroll: e = !1, children: t, defaultScrollPosition: r = "end", scrollEdgeThreshold: n, scrollPreviousItemPeek: s, scrollMargin: l }) {
1232
- let { context: a, registerMessage: i } = Mr({ autoScroll: e, defaultScrollPosition: r, scrollEdgeThreshold: n, scrollPreviousItemPeek: s, scrollMargin: l });
1233
- return o(ft.Provider, { value: a, children: o(ht.Provider, { value: i, children: t }) });
1234
- }
1235
- function pt() {
1236
- let { pendingDefaultScrollStore: e } = ie();
1237
- return c.useSyncExternalStore(e.subscribe, e.getSnapshot, e.getSnapshot);
1238
- }
1239
- function xr({ children: e, ...t }) {
1240
- let { setRootElement: r } = ie(), n = pt();
1241
- return o("div", { ref: r, ...t, ...n ? { "data-pending-scroll": "" } : null, children: e });
1242
- }
1243
- function Lr({ "aria-label": e, children: t, onKeyDown: r, onScroll: n, onTouchMove: s, onWheel: l, preserveScrollOnPrepend: a = !0, ref: i, role: d, tabIndex: h, ...g }) {
1244
- let { handleResize: v, preserveScrollOnPrependRef: f, setViewportElement: u, syncAfterScroll: m, userScrollIntent: T, viewportRef: _ } = ie(), D = pt();
1245
- f.current = a;
1246
- let V = c.useCallback((R) => {
1247
- var O;
1248
- u(R), (O = ae(i)) == null || O(R);
1249
- }, [i, u]);
1250
- function L(R) {
1251
- m(), n == null || n(R);
1517
+ function Hr({ autoScroll: e = !1, children: t, defaultScrollPosition: n = "end", scrollEdgeThreshold: r, scrollPreviousItemPeek: s, scrollMargin: o }) {
1518
+ let { context: a, registerMessage: i } = qr({ autoScroll: e, defaultScrollPosition: n, scrollEdgeThreshold: r, scrollPreviousItemPeek: s, scrollMargin: o });
1519
+ return l(wt.Provider, { value: a, children: l(yt.Provider, { value: i, children: t }) });
1520
+ }
1521
+ function kt() {
1522
+ let { pendingDefaultScrollStore: e } = Fe();
1523
+ return d.useSyncExternalStore(e.subscribe, e.getSnapshot, e.getSnapshot);
1524
+ }
1525
+ function zr({ children: e, ...t }) {
1526
+ let { setRootElement: n } = Fe(), r = kt();
1527
+ return l("div", { ref: n, ...t, ...r ? { "data-pending-scroll": "" } : null, children: e });
1528
+ }
1529
+ function Wr({ "aria-label": e, children: t, onKeyDown: n, onScroll: r, onTouchMove: s, onWheel: o, preserveScrollOnPrepend: a = !0, ref: i, role: u, tabIndex: h, ...g }) {
1530
+ let { handleResize: f, preserveScrollOnPrependRef: c, setViewportElement: p, syncAfterScroll: b, userScrollIntent: k, viewportRef: v } = Fe(), m = kt();
1531
+ c.current = a;
1532
+ let B = d.useCallback((I) => {
1533
+ var z;
1534
+ p(I), (z = Se(i)) == null || z(I);
1535
+ }, [i, p]);
1536
+ function T(I) {
1537
+ b(), r == null || r(I);
1252
1538
  }
1253
- function $(R) {
1254
- T(), l == null || l(R);
1539
+ function x(I) {
1540
+ k(), o == null || o(I);
1255
1541
  }
1256
- function P(R) {
1257
- T(), s == null || s(R);
1542
+ function C(I) {
1543
+ k(), s == null || s(I);
1258
1544
  }
1259
- function I(R) {
1260
- hr.has(R.key) && T(), r == null || r(R);
1545
+ function N(I) {
1546
+ _r.has(I.key) && k(), n == null || n(I);
1261
1547
  }
1262
- return c.useEffect(() => {
1263
- let R = _.current;
1264
- if (!R || typeof ResizeObserver > "u") return;
1265
- let O = 0, N = new ResizeObserver(() => {
1266
- window.cancelAnimationFrame(O), O = window.requestAnimationFrame(v);
1548
+ return d.useEffect(() => {
1549
+ let I = v.current;
1550
+ if (!I || typeof ResizeObserver > "u") return;
1551
+ let z = 0, q = new ResizeObserver(() => {
1552
+ window.cancelAnimationFrame(z), z = window.requestAnimationFrame(f);
1267
1553
  });
1268
- return N.observe(R), () => {
1269
- window.cancelAnimationFrame(O), N.disconnect();
1554
+ return q.observe(I), () => {
1555
+ window.cancelAnimationFrame(z), q.disconnect();
1270
1556
  };
1271
- }, [v, _]), o("div", { ref: V, role: d ?? "region", "aria-label": e ?? "Messages", tabIndex: h ?? 0, onKeyDown: I, onScroll: L, onTouchMove: P, onWheel: $, ...g, ...D ? { "data-pending-scroll": "" } : null, children: t });
1272
- }
1273
- function Or({ "aria-relevant": e, children: t, ref: r, role: n, spacerClassName: s, ...l }) {
1274
- let { handleContentChange: a, handleResize: i, setContentElement: d, setSpacerElement: h } = ie(), g = c.useRef(null), v = c.useCallback((f) => {
1275
- var u;
1276
- g.current = f, d(f), (u = ae(r)) == null || u(f);
1277
- }, [r, d]);
1278
- return c.useLayoutEffect(() => {
1279
- let f = g.current;
1280
- if (!f || (a(), typeof MutationObserver > "u")) return;
1281
- let u = new MutationObserver(() => {
1557
+ }, [f, v]), l("div", { ref: B, role: u ?? "region", "aria-label": e ?? "Messages", tabIndex: h ?? 0, onKeyDown: N, onScroll: T, onTouchMove: C, onWheel: x, ...g, ...m ? { "data-pending-scroll": "" } : null, children: t });
1558
+ }
1559
+ function Vr({ "aria-relevant": e, children: t, ref: n, role: r, spacerClassName: s, ...o }) {
1560
+ let { handleContentChange: a, handleResize: i, setContentElement: u, setSpacerElement: h } = Fe(), g = d.useRef(null), f = d.useCallback((c) => {
1561
+ var p;
1562
+ g.current = c, u(c), (p = Se(n)) == null || p(c);
1563
+ }, [n, u]);
1564
+ return d.useLayoutEffect(() => {
1565
+ let c = g.current;
1566
+ if (!c || (a(), typeof MutationObserver > "u")) return;
1567
+ let p = new MutationObserver(() => {
1282
1568
  a();
1283
1569
  });
1284
- return u.observe(f, { childList: !0 }), () => u.disconnect();
1285
- }, [a]), c.useEffect(() => {
1286
- let f = g.current;
1287
- if (!f || typeof ResizeObserver > "u") return;
1288
- let u = 0, m = new ResizeObserver(() => {
1289
- window.cancelAnimationFrame(u), u = window.requestAnimationFrame(i);
1570
+ return p.observe(c, { childList: !0 }), () => p.disconnect();
1571
+ }, [a]), d.useEffect(() => {
1572
+ let c = g.current;
1573
+ if (!c || typeof ResizeObserver > "u") return;
1574
+ let p = 0, b = new ResizeObserver(() => {
1575
+ window.cancelAnimationFrame(p), p = window.requestAnimationFrame(i);
1290
1576
  });
1291
- return m.observe(f), () => {
1292
- window.cancelAnimationFrame(u), m.disconnect();
1577
+ return b.observe(c), () => {
1578
+ window.cancelAnimationFrame(p), b.disconnect();
1293
1579
  };
1294
- }, [i]), k("div", { ref: v, role: n ?? "log", "aria-relevant": e ?? "additions", ...l, children: [t, o("div", { ref: h, "aria-hidden": "true", "data-message-scroller-spacer": "", hidden: !0, className: s })] });
1580
+ }, [i]), w("div", { ref: f, role: r ?? "log", "aria-relevant": e ?? "additions", ...o, children: [t, l("div", { ref: h, "aria-hidden": "true", "data-message-scroller-spacer": "", hidden: !0, className: s })] });
1295
1581
  }
1296
- function Hr({ messageId: e, ref: t, scrollAnchor: r = !1, ...n }) {
1297
- let s = Nr(), l = c.useRef(null), a = c.useCallback((i) => {
1582
+ function Gr({ messageId: e, ref: t, scrollAnchor: n = !1, ...r }) {
1583
+ let s = $r(), o = d.useRef(null), a = d.useCallback((i) => {
1298
1584
  var h;
1299
- let d = l.current;
1300
- l.current = i, e && s(e, i, d), (h = ae(t)) == null || h(i);
1585
+ let u = o.current;
1586
+ o.current = i, e && s(e, i, u), (h = Se(t)) == null || h(i);
1301
1587
  }, [e, t, s]);
1302
- return o("div", { ref: a, "data-message-id": e, "data-scroll-anchor": r ? "true" : "false", ...n });
1303
- }
1304
- function zr({ behavior: e = "smooth", children: t, direction: r = "end", onClick: n, render: s, tabIndex: l, type: a = "button", ...i }) {
1305
- let { scrollToEnd: d, scrollToStart: h, stateStore: g } = ie(), v = Ir(n), f = c.useCallback((_) => g.subscribe(_), [g]), u = c.useCallback(() => {
1306
- let _ = g.getSnapshot();
1307
- return r === "start" ? _.start : _.end;
1308
- }, [r, g]), m = c.useSyncExternalStore(f, u, u), T = c.useCallback((_) => {
1309
- var D;
1310
- m && ((D = v.current) == null || D.call(v, _), _.defaultPrevented || (_.currentTarget.blur(), r === "start" ? h({ behavior: e }) : d({ behavior: e })));
1311
- }, [e, r, m, v, d, h]);
1312
- return lr({ defaultTagName: "button", props: Se({ type: a, inert: !m, tabIndex: m ? l : -1, children: t ?? k("span", { children: ["Scroll to ", r] }), onClick: T }, i), render: s, state: { active: m, direction: r }, stateAttributesMapping: { active: (_) => ({ "data-active": _ ? "true" : "false" }) } });
1313
- }
1314
- var te = { Provider: Pr, Root: xr, Viewport: Lr, Content: Or, Item: Hr, Button: zr };
1315
- function gt(e) {
1316
- var t, r, n = "";
1317
- if (typeof e == "string" || typeof e == "number") n += e;
1588
+ return l("div", { ref: a, "data-message-id": e, "data-scroll-anchor": n ? "true" : "false", ...r });
1589
+ }
1590
+ function Ur({ behavior: e = "smooth", children: t, direction: n = "end", onClick: r, render: s, tabIndex: o, type: a = "button", ...i }) {
1591
+ let { scrollToEnd: u, scrollToStart: h, stateStore: g } = Fe(), f = Or(r), c = d.useCallback((v) => g.subscribe(v), [g]), p = d.useCallback(() => {
1592
+ let v = g.getSnapshot();
1593
+ return n === "start" ? v.start : v.end;
1594
+ }, [n, g]), b = d.useSyncExternalStore(c, p, p), k = d.useCallback((v) => {
1595
+ var m;
1596
+ b && ((m = f.current) == null || m.call(f, v), v.defaultPrevented || (v.currentTarget.blur(), n === "start" ? h({ behavior: e }) : u({ behavior: e })));
1597
+ }, [e, n, b, f, u, h]);
1598
+ return dr({ defaultTagName: "button", props: ze({ type: a, inert: !b, tabIndex: b ? o : -1, children: t ?? w("span", { children: ["Scroll to ", n] }), onClick: k }, i), render: s, state: { active: b, direction: n }, stateAttributesMapping: { active: (v) => ({ "data-active": v ? "true" : "false" }) } });
1599
+ }
1600
+ var _e = { Provider: Hr, Root: zr, Viewport: Wr, Content: Vr, Item: Gr, Button: Ur };
1601
+ function Ct(e) {
1602
+ var t, n, r = "";
1603
+ if (typeof e == "string" || typeof e == "number") r += e;
1318
1604
  else if (typeof e == "object") if (Array.isArray(e)) {
1319
1605
  var s = e.length;
1320
- for (t = 0; t < s; t++) e[t] && (r = gt(e[t])) && (n && (n += " "), n += r);
1321
- } else for (r in e) e[r] && (n && (n += " "), n += r);
1322
- return n;
1606
+ for (t = 0; t < s; t++) e[t] && (n = Ct(e[t])) && (r && (r += " "), r += n);
1607
+ } else for (n in e) e[n] && (r && (r += " "), r += n);
1608
+ return r;
1323
1609
  }
1324
- function qr() {
1325
- for (var e, t, r = 0, n = "", s = arguments.length; r < s; r++) (e = arguments[r]) && (t = gt(e)) && (n && (n += " "), n += t);
1326
- return n;
1610
+ function jr() {
1611
+ for (var e, t, n = 0, r = "", s = arguments.length; n < s; n++) (e = arguments[n]) && (t = Ct(e)) && (r && (r += " "), r += t);
1612
+ return r;
1327
1613
  }
1328
- function re(...e) {
1329
- return qr(e);
1614
+ function we(...e) {
1615
+ return jr(e);
1330
1616
  }
1331
- function Gr(e) {
1332
- return /* @__PURE__ */ o(te.Provider, { ...e });
1617
+ function Yr(e) {
1618
+ return /* @__PURE__ */ l(_e.Provider, { ...e });
1333
1619
  }
1334
- function Vr({
1620
+ function Jr({
1335
1621
  className: e,
1336
1622
  ...t
1337
1623
  }) {
1338
- return /* @__PURE__ */ o(
1339
- te.Root,
1624
+ return /* @__PURE__ */ l(
1625
+ _e.Root,
1340
1626
  {
1341
1627
  "data-slot": "message-scroller",
1342
- className: re("msg-scroller-root", e),
1628
+ className: we("msg-scroller-root", e),
1343
1629
  ...t
1344
1630
  }
1345
1631
  );
1346
1632
  }
1347
- function Wr({
1633
+ function Kr({
1348
1634
  className: e,
1349
1635
  ...t
1350
1636
  }) {
1351
- return /* @__PURE__ */ o(
1352
- te.Viewport,
1637
+ return /* @__PURE__ */ l(
1638
+ _e.Viewport,
1353
1639
  {
1354
1640
  "data-slot": "message-scroller-viewport",
1355
- className: re("msg-scroller-viewport", e),
1641
+ className: we("msg-scroller-viewport", e),
1356
1642
  ...t
1357
1643
  }
1358
1644
  );
1359
1645
  }
1360
- function $r({
1646
+ function Qr({
1361
1647
  className: e,
1362
1648
  ...t
1363
1649
  }) {
1364
- return /* @__PURE__ */ o(
1365
- te.Content,
1650
+ return /* @__PURE__ */ l(
1651
+ _e.Content,
1366
1652
  {
1367
1653
  "data-slot": "message-scroller-content",
1368
- className: re("msg-scroller-content", e),
1654
+ className: we("msg-scroller-content", e),
1369
1655
  ...t
1370
1656
  }
1371
1657
  );
1372
1658
  }
1373
- function Ye({
1659
+ function nt({
1374
1660
  className: e,
1375
1661
  scrollAnchor: t = !1,
1376
- ...r
1662
+ ...n
1377
1663
  }) {
1378
- return /* @__PURE__ */ o(
1379
- te.Item,
1664
+ return /* @__PURE__ */ l(
1665
+ _e.Item,
1380
1666
  {
1381
1667
  "data-slot": "message-scroller-item",
1382
1668
  scrollAnchor: t,
1383
- className: re("msg-scroller-item", e),
1384
- ...r
1669
+ className: we("msg-scroller-item", e),
1670
+ ...n
1385
1671
  }
1386
1672
  );
1387
1673
  }
1388
- function Ur({
1674
+ function Xr({
1389
1675
  direction: e = "end",
1390
1676
  className: t,
1391
- children: r,
1392
- ...n
1677
+ children: n,
1678
+ ...r
1393
1679
  }) {
1394
- return /* @__PURE__ */ o(
1395
- te.Button,
1680
+ return /* @__PURE__ */ l(
1681
+ _e.Button,
1396
1682
  {
1397
1683
  "data-slot": "message-scroller-button",
1398
1684
  direction: e,
1399
- className: re("msg-scroller-btn", t),
1400
- ...n,
1401
- children: r ?? /* @__PURE__ */ k(oe, { children: [
1402
- /* @__PURE__ */ o(
1403
- Lt,
1685
+ className: we("msg-scroller-btn", t),
1686
+ ...r,
1687
+ children: n ?? /* @__PURE__ */ w(De, { children: [
1688
+ /* @__PURE__ */ l(
1689
+ Ot,
1404
1690
  {
1405
1691
  size: 16,
1406
1692
  "aria-hidden": "true",
1407
1693
  className: e === "start" ? "rotate-180" : void 0
1408
1694
  }
1409
1695
  ),
1410
- /* @__PURE__ */ o("span", { className: "sr-only", children: e === "end" ? "Jump to latest" : "Jump to start" })
1696
+ /* @__PURE__ */ l("span", { className: "sr-only", children: e === "end" ? "Jump to latest" : "Jump to start" })
1411
1697
  ] })
1412
1698
  }
1413
1699
  );
1414
1700
  }
1415
- const jr = () => /* @__PURE__ */ k("div", { className: "chat-empty-row", children: [
1416
- /* @__PURE__ */ o(
1701
+ const Zr = () => /* @__PURE__ */ w("div", { className: "chat-empty-row", children: [
1702
+ /* @__PURE__ */ l(
1417
1703
  "div",
1418
1704
  {
1419
1705
  className: "avatar-circle avatar-circle--mt",
1420
1706
  "aria-hidden": "true",
1421
- children: /* @__PURE__ */ o(lt, { size: 15 })
1707
+ children: /* @__PURE__ */ l(pt, { size: 15 })
1422
1708
  }
1423
1709
  ),
1424
- /* @__PURE__ */ o("div", { className: "chat-empty-bubble", children: /* @__PURE__ */ o("p", { children: "Hello — I am the VPS Veritas assistant. Ask about reports, sample status, registration, or support, or choose a question below the text box." }) })
1710
+ /* @__PURE__ */ l("div", { className: "chat-empty-bubble", children: /* @__PURE__ */ l("p", { children: "Hello — I am the VPS Veritas assistant. Ask about reports, sample status, registration, or support, or choose a question below the text box." }) })
1425
1711
  ] });
1426
- function ye(e) {
1427
- return e.split(/(\*\*[^*]+\*\*|`[^`]+`|https?:\/\/[^\s]+)/g).map((r, n) => r.startsWith("**") && r.endsWith("**") ? /* @__PURE__ */ o("strong", { children: r.slice(2, -2) }, n) : r.startsWith("`") && r.endsWith("`") ? /* @__PURE__ */ o(
1428
- "code",
1429
- {
1430
- className: "md-code",
1431
- children: r.slice(1, -1)
1432
- },
1433
- n
1434
- ) : /^https?:\/\//.test(r) ? /* @__PURE__ */ o(
1435
- "a",
1436
- {
1437
- href: r,
1438
- target: "_blank",
1439
- rel: "noopener noreferrer",
1440
- className: "md-link",
1441
- children: r
1442
- },
1443
- n
1444
- ) : /* @__PURE__ */ o(Xe.Fragment, { children: r }, n));
1712
+ function en(e) {
1713
+ const t = e.trim();
1714
+ if (!/[\u0000-\u001f\u007f]/.test(t) && /^(https?:\/\/|mailto:|\/(?!\/)|#)/i.test(t))
1715
+ return t;
1445
1716
  }
1446
- function Yr({ text: e }) {
1447
- if (!e) return null;
1448
- const t = e.split(/\n\n+/);
1449
- return /* @__PURE__ */ o(oe, { children: t.map((r, n) => {
1450
- if (r.trim().startsWith("- ") || r.trim().startsWith("* ")) {
1451
- const s = r.split(/\n/).filter((l) => l.trim().startsWith("- ") || l.trim().startsWith("* "));
1452
- return /* @__PURE__ */ o("ul", { className: "md-ul", children: s.map((l, a) => /* @__PURE__ */ o("li", { children: ye(l.replace(/^[-*]\s+/, "")) }, a)) }, n);
1453
- }
1454
- if (/^\d+\.\s+/.test(r.trim())) {
1455
- const s = r.split(/\n/).filter((l) => /^\d+\.\s+/.test(l.trim()));
1456
- return /* @__PURE__ */ o("ol", { className: "md-ol", children: s.map((l, a) => /* @__PURE__ */ o("li", { children: ye(l.replace(/^\d+\.\s+/, "")) }, a)) }, n);
1457
- }
1458
- if (r.startsWith("```")) {
1459
- const s = r.replace(/^```[a-zA-Z]*\n?/, "").replace(/```$/, "");
1460
- return /* @__PURE__ */ o(
1461
- "pre",
1717
+ function te(e) {
1718
+ if (!e) return [];
1719
+ const t = /(\[[^\]]+\]\([^)]+\)|\*\*[^*]+\*\*|\*[^*]+\*|`[^`]+`|https?:\/\/[^\s]+)/g;
1720
+ return e.split(t).map((r, s) => {
1721
+ if (!r) return null;
1722
+ const o = r.match(/^\[([^\]]+)\]\(([^)]+)\)$/);
1723
+ if (o) {
1724
+ const a = o[1], i = o[2], u = en(i);
1725
+ if (!u) return /* @__PURE__ */ l(oe.Fragment, { children: a }, s);
1726
+ const h = /^https?:\/\//i.test(i);
1727
+ return /* @__PURE__ */ l(
1728
+ "a",
1462
1729
  {
1463
- className: "md-pre",
1464
- children: /* @__PURE__ */ o("code", { children: s })
1730
+ href: u,
1731
+ target: h ? "_blank" : void 0,
1732
+ rel: h ? "noopener noreferrer" : void 0,
1733
+ className: "md-link",
1734
+ children: a
1465
1735
  },
1466
- n
1736
+ s
1467
1737
  );
1468
1738
  }
1469
- return /* @__PURE__ */ o("p", { className: "md-p", children: ye(r) }, n);
1470
- }) });
1739
+ return r.startsWith("**") && r.endsWith("**") && r.length >= 4 ? /* @__PURE__ */ l("strong", { children: r.slice(2, -2) }, s) : r.startsWith("*") && r.endsWith("*") && r.length >= 2 ? /* @__PURE__ */ l("em", { children: r.slice(1, -1) }, s) : r.startsWith("`") && r.endsWith("`") && r.length >= 2 ? /* @__PURE__ */ l("code", { className: "md-code", children: r.slice(1, -1) }, s) : /^https?:\/\//i.test(r) ? /* @__PURE__ */ l(
1740
+ "a",
1741
+ {
1742
+ href: r,
1743
+ target: "_blank",
1744
+ rel: "noopener noreferrer",
1745
+ className: "md-link",
1746
+ children: r
1747
+ },
1748
+ s
1749
+ ) : /* @__PURE__ */ l(oe.Fragment, { children: r }, s);
1750
+ });
1751
+ }
1752
+ function tn(e) {
1753
+ const t = e.replace(/\r\n/g, `
1754
+ `).split(`
1755
+ `), n = [];
1756
+ let r = 0;
1757
+ for (; r < t.length; ) {
1758
+ const o = t[r].trim();
1759
+ if (!o) {
1760
+ r++;
1761
+ continue;
1762
+ }
1763
+ if (o.startsWith("```")) {
1764
+ const u = o.slice(3).trim(), h = [];
1765
+ for (r++; r < t.length && !t[r].trim().startsWith("```"); )
1766
+ h.push(t[r]), r++;
1767
+ r < t.length && t[r].trim().startsWith("```") && r++, n.push({ type: "code", lang: u, code: h.join(`
1768
+ `) });
1769
+ continue;
1770
+ }
1771
+ if (/^(---|___|\*\*\*)$/.test(o)) {
1772
+ n.push({ type: "hr" }), r++;
1773
+ continue;
1774
+ }
1775
+ const a = o.match(/^(#{1,4})\s+(.*)$/);
1776
+ if (a) {
1777
+ n.push({
1778
+ type: "h",
1779
+ level: a[1].length,
1780
+ content: a[2]
1781
+ }), r++;
1782
+ continue;
1783
+ }
1784
+ if (o.startsWith(">")) {
1785
+ const u = [];
1786
+ for (; r < t.length && t[r].trim().startsWith(">"); )
1787
+ u.push(t[r].trim().replace(/^>\s?/, "")), r++;
1788
+ n.push({ type: "quote", lines: u });
1789
+ continue;
1790
+ }
1791
+ if (/^[-*]\s+/.test(o)) {
1792
+ const u = [];
1793
+ for (; r < t.length && /^[-*]\s+/.test(t[r].trim()); )
1794
+ u.push(t[r].trim().replace(/^[-*]\s+/, "")), r++;
1795
+ n.push({ type: "ul", items: u });
1796
+ continue;
1797
+ }
1798
+ if (/^\d+\.\s+/.test(o)) {
1799
+ const u = [];
1800
+ for (; r < t.length && /^\d+\.\s+/.test(t[r].trim()); )
1801
+ u.push(t[r].trim().replace(/^\d+\.\s+/, "")), r++;
1802
+ n.push({ type: "ol", items: u });
1803
+ continue;
1804
+ }
1805
+ if (o.startsWith("|") && o.endsWith("|")) {
1806
+ const u = [];
1807
+ for (; r < t.length && t[r].trim().startsWith("|") && t[r].trim().endsWith("|"); )
1808
+ u.push(t[r].trim()), r++;
1809
+ if (u.length >= 2) {
1810
+ const h = (p) => p.slice(1, -1).split("|").map((b) => b.trim()), g = h(u[0]), f = u[1].includes("-") ? 2 : 1, c = u.slice(f).map(h);
1811
+ n.push({ type: "table", headers: g, rows: c });
1812
+ continue;
1813
+ }
1814
+ }
1815
+ const i = [];
1816
+ for (; r < t.length && t[r].trim() && !t[r].trim().startsWith("```") && !/^(#{1,4})\s+/.test(t[r].trim()) && !/^[-*]\s+/.test(t[r].trim()) && !/^\d+\.\s+/.test(t[r].trim()) && !t[r].trim().startsWith(">") && !/^(---|___|\*\*\*)$/.test(t[r].trim()); )
1817
+ i.push(t[r].trim()), r++;
1818
+ i.length > 0 && n.push({ type: "p", lines: i });
1819
+ }
1820
+ return n;
1471
1821
  }
1472
- const Zr = ({ className: e }) => /* @__PURE__ */ k(
1822
+ const rn = oe.memo(function({ text: t }) {
1823
+ if (!t) return null;
1824
+ const n = tn(t);
1825
+ return /* @__PURE__ */ l("div", { className: "md-content", children: n.map((r, s) => {
1826
+ switch (r.type) {
1827
+ case "h":
1828
+ return r.level === 1 ? /* @__PURE__ */ l("h2", { className: "md-h1", children: te(r.content) }, s) : r.level === 2 ? /* @__PURE__ */ l("h3", { className: "md-h2", children: te(r.content) }, s) : r.level === 3 ? /* @__PURE__ */ l("h4", { className: "md-h3", children: te(r.content) }, s) : /* @__PURE__ */ l("h5", { className: "md-h4", children: te(r.content) }, s);
1829
+ case "ul":
1830
+ return /* @__PURE__ */ l("ul", { className: "md-ul", children: r.items.map((o, a) => /* @__PURE__ */ l("li", { className: "md-li", children: te(o) }, a)) }, s);
1831
+ case "ol":
1832
+ return /* @__PURE__ */ l("ol", { className: "md-ol", children: r.items.map((o, a) => /* @__PURE__ */ l("li", { className: "md-li", children: te(o) }, a)) }, s);
1833
+ case "code":
1834
+ return /* @__PURE__ */ l("pre", { className: "md-pre", children: /* @__PURE__ */ l("code", { children: r.code }) }, s);
1835
+ case "quote":
1836
+ return /* @__PURE__ */ l("blockquote", { className: "md-quote", children: r.lines.map((o, a) => /* @__PURE__ */ l("p", { children: te(o) }, a)) }, s);
1837
+ case "hr":
1838
+ return /* @__PURE__ */ l("hr", { className: "md-hr" }, s);
1839
+ case "table":
1840
+ return /* @__PURE__ */ l("div", { className: "md-table-wrap", children: /* @__PURE__ */ w("table", { className: "md-table", children: [
1841
+ /* @__PURE__ */ l("thead", { children: /* @__PURE__ */ l("tr", { children: r.headers.map((o, a) => /* @__PURE__ */ l("th", { children: te(o) }, a)) }) }),
1842
+ /* @__PURE__ */ l("tbody", { children: r.rows.map((o, a) => /* @__PURE__ */ l("tr", { children: o.map((i, u) => /* @__PURE__ */ l("td", { children: te(i) }, u)) }, a)) })
1843
+ ] }) }, s);
1844
+ case "p":
1845
+ default:
1846
+ return /* @__PURE__ */ l("p", { className: "md-p", children: r.lines.map((o, a) => /* @__PURE__ */ w(oe.Fragment, { children: [
1847
+ te(o),
1848
+ a < r.lines.length - 1 && /* @__PURE__ */ l("br", {})
1849
+ ] }, a)) }, s);
1850
+ }
1851
+ }) });
1852
+ }), nn = ({ className: e, text: t }) => /* @__PURE__ */ w(
1473
1853
  "div",
1474
1854
  {
1475
- className: re("typing-indicator", e),
1855
+ className: we("typing-indicator-container", e),
1476
1856
  role: "status",
1477
1857
  "aria-label": "Assistant is preparing a reply",
1478
1858
  children: [
1479
- /* @__PURE__ */ o("span", { className: "typing-dot" }),
1480
- /* @__PURE__ */ o("span", { className: "typing-dot" }),
1481
- /* @__PURE__ */ o("span", { className: "typing-dot" })
1859
+ /* @__PURE__ */ w("div", { className: "typing-indicator", "aria-hidden": "true", children: [
1860
+ /* @__PURE__ */ l("span", { className: "typing-dot" }),
1861
+ /* @__PURE__ */ l("span", { className: "typing-dot" }),
1862
+ /* @__PURE__ */ l("span", { className: "typing-dot" })
1863
+ ] }),
1864
+ t && /* @__PURE__ */ l("div", { className: "typing-progress-pill", children: t })
1482
1865
  ]
1483
1866
  }
1484
- );
1485
- function Jr(e) {
1486
- return e === "create_ticket" ? "Support ticket processed" : e === "get_customer" ? "Account verified" : e === "get_ticket" ? "Ticket status loaded" : "Information retrieved";
1867
+ ), sn = ({
1868
+ status: e = "complete",
1869
+ progressText: t,
1870
+ durationMs: n
1871
+ }) => {
1872
+ const r = e === "pending", [s, o] = U(0);
1873
+ ke(() => {
1874
+ if (!r) return;
1875
+ const i = Date.now(), u = setInterval(() => {
1876
+ o(Number(((Date.now() - i) / 1e3).toFixed(1)));
1877
+ }, 250);
1878
+ return () => clearInterval(u);
1879
+ }, [r]);
1880
+ const a = r ? `${s.toFixed(1)}s` : n === void 0 ? void 0 : `${(n / 1e3).toFixed(1)}s`;
1881
+ return /* @__PURE__ */ l("div", { className: `agent-reasoning-container${r ? " agent-reasoning--active" : ""}`, children: /* @__PURE__ */ l(
1882
+ "div",
1883
+ {
1884
+ className: "agent-reasoning-header",
1885
+ role: "status",
1886
+ "aria-live": "off",
1887
+ children: /* @__PURE__ */ w("div", { className: "agent-reasoning-header-left", children: [
1888
+ r ? /* @__PURE__ */ l(
1889
+ Kt,
1890
+ {
1891
+ size: 13,
1892
+ className: "agent-reasoning-spinner",
1893
+ "aria-hidden": "true"
1894
+ }
1895
+ ) : /* @__PURE__ */ l(
1896
+ Ut,
1897
+ {
1898
+ size: 13,
1899
+ className: "agent-reasoning-done-icon",
1900
+ "aria-hidden": "true"
1901
+ }
1902
+ ),
1903
+ /* @__PURE__ */ l("span", { className: "agent-reasoning-title", children: r ? `${t || "Working…"} · ${a}` : a ? `Response generated in ${a}` : "Response generated" })
1904
+ ] })
1905
+ }
1906
+ ) });
1907
+ }, on = {
1908
+ "fuel-defect-reporting": {
1909
+ label: "Fuel Defect Reporting",
1910
+ path: "/dashboard/fuel-Defect-Reporting"
1911
+ },
1912
+ "bunker-master": {
1913
+ label: "Bunker Master",
1914
+ path: "/dashboard/bunker-master"
1915
+ },
1916
+ "fsc-fsq-e-forms": {
1917
+ label: "Pre-Registration & E-Forms",
1918
+ path: "/dashboard/pre-registration"
1919
+ },
1920
+ "pre-registration-ship": {
1921
+ label: "Pre-Registration",
1922
+ path: "/dashboard/pre-registration"
1923
+ },
1924
+ "reports-fuel": {
1925
+ label: "Fuel Reports",
1926
+ path: "/dashboard/reports"
1927
+ },
1928
+ "sample-fuel": {
1929
+ label: "Sample Status",
1930
+ path: "/dashboard/sample-status"
1931
+ }
1932
+ };
1933
+ function ln(e) {
1934
+ const n = (e.split(/[/\\]/).pop() || "").replace(/\.md$/i, "").toLowerCase();
1935
+ for (const [r, s] of Object.entries(on))
1936
+ if (n.includes(r))
1937
+ return s;
1938
+ return null;
1487
1939
  }
1488
- function Kr({ sources: e }) {
1489
- const [t, r] = j(!1);
1490
- return e.length ? /* @__PURE__ */ k("div", { className: "sources-panel", children: [
1491
- /* @__PURE__ */ k(
1492
- "button",
1493
- {
1494
- type: "button",
1495
- className: "sources-toggle-btn",
1496
- onClick: () => r((n) => !n),
1497
- "aria-expanded": t,
1498
- children: [
1499
- /* @__PURE__ */ o(Wt, { size: 12, "aria-hidden": "true" }),
1500
- e.length,
1501
- " grounded source",
1502
- e.length > 1 ? "s" : "",
1503
- t ? /* @__PURE__ */ o(Gt, { size: 12 }) : /* @__PURE__ */ o(qt, { size: 12 })
1504
- ]
1505
- }
1506
- ),
1507
- t && /* @__PURE__ */ o("ul", { className: "sources-list", children: e.map((n) => /* @__PURE__ */ k(
1508
- "li",
1509
- {
1510
- className: "source-item",
1511
- children: [
1512
- /* @__PURE__ */ o("span", { className: "source-name", title: n.source, children: n.source.split(/[/\\]/).pop() || n.source }),
1513
- /* @__PURE__ */ k("span", { className: "source-score", children: [
1514
- Math.round(n.score * 100),
1515
- "%"
1516
- ] })
1517
- ]
1518
- },
1519
- n.chunkId
1520
- )) })
1521
- ] }) : null;
1940
+ function st(e) {
1941
+ return e.title ? e.title : (e.source.split(/[/\\]/).pop() || e.source).replace(/\.md$/i, "").replace(/[-_]/g, " ").replace(/\b\w/g, (n) => n.toUpperCase());
1942
+ }
1943
+ const an = ({
1944
+ sources: e,
1945
+ hideInspectSources: t = !1,
1946
+ showInspectSources: n = !0,
1947
+ defaultExpanded: r = !1,
1948
+ maxSources: s = 5
1949
+ }) => {
1950
+ const o = t || n === !1, [a, i] = U(r && !o), [u, h] = U(null);
1951
+ if (!e || !e.length) return null;
1952
+ const g = e.slice(0, s);
1953
+ return /* @__PURE__ */ w("div", { className: "grounded-sources-card", children: [
1954
+ /* @__PURE__ */ w("div", { className: "grounded-sources-header", children: [
1955
+ /* @__PURE__ */ w("div", { className: "grounded-sources-badge", children: [
1956
+ /* @__PURE__ */ l(er, { size: 13, className: "grounded-shield-icon" }),
1957
+ /* @__PURE__ */ w("span", { children: [
1958
+ g.length,
1959
+ " retrieved VPS sources"
1960
+ ] })
1961
+ ] }),
1962
+ !o && /* @__PURE__ */ w(
1963
+ "button",
1964
+ {
1965
+ type: "button",
1966
+ className: "grounded-toggle-btn",
1967
+ onClick: () => i((f) => !f),
1968
+ "aria-expanded": a,
1969
+ children: [
1970
+ /* @__PURE__ */ l("span", { children: a ? "Hide Details" : "Inspect Sources" }),
1971
+ a ? /* @__PURE__ */ l(Gt, { size: 12 }) : /* @__PURE__ */ l(Vt, { size: 12 })
1972
+ ]
1973
+ }
1974
+ )
1975
+ ] }),
1976
+ /* @__PURE__ */ l("div", { className: "grounded-pills-row", children: g.map((f, c) => {
1977
+ const p = st(f), b = u === c;
1978
+ return /* @__PURE__ */ w(
1979
+ "button",
1980
+ {
1981
+ type: "button",
1982
+ className: `grounded-source-pill${b ? " grounded-source-pill--selected" : ""}`,
1983
+ onClick: () => {
1984
+ o || (i(!0), h(b ? null : c));
1985
+ },
1986
+ title: f.source,
1987
+ children: [
1988
+ /* @__PURE__ */ l(zt, { size: 11, className: "grounded-book-icon" }),
1989
+ /* @__PURE__ */ w("span", { className: "grounded-pill-title", children: [
1990
+ "[S",
1991
+ c + 1,
1992
+ "] ",
1993
+ p
1994
+ ] }),
1995
+ /* @__PURE__ */ w("span", { className: "grounded-pill-score", title: "Ranking score, not a probability of correctness", children: [
1996
+ "Score ",
1997
+ f.score.toFixed(2)
1998
+ ] })
1999
+ ]
2000
+ },
2001
+ `${f.chunkId}-${c}`
2002
+ );
2003
+ }) }),
2004
+ !o && a && /* @__PURE__ */ l("div", { className: "grounded-sources-details-list", children: g.map((f, c) => {
2005
+ const p = st(f), b = ln(f.source);
2006
+ return /* @__PURE__ */ w(
2007
+ "div",
2008
+ {
2009
+ className: `grounded-detail-item${u === c ? " grounded-detail-item--highlighted" : ""}`,
2010
+ children: [
2011
+ /* @__PURE__ */ w("div", { className: "grounded-detail-top", children: [
2012
+ /* @__PURE__ */ w("div", { className: "grounded-detail-title-group", children: [
2013
+ /* @__PURE__ */ w("span", { className: "grounded-detail-index", children: [
2014
+ "[",
2015
+ c + 1,
2016
+ "]"
2017
+ ] }),
2018
+ /* @__PURE__ */ l("span", { className: "grounded-detail-title", children: p })
2019
+ ] }),
2020
+ /* @__PURE__ */ w("div", { className: "grounded-detail-meta", children: [
2021
+ /* @__PURE__ */ w("span", { className: "grounded-detail-score", children: [
2022
+ "Rank score ",
2023
+ f.score.toFixed(2)
2024
+ ] }),
2025
+ b && /* @__PURE__ */ w(
2026
+ "a",
2027
+ {
2028
+ href: b.path,
2029
+ onClick: (v) => {
2030
+ v.preventDefault(), window.location.href = b.path;
2031
+ },
2032
+ className: "grounded-route-link",
2033
+ title: `Navigate to ${b.label}`,
2034
+ children: [
2035
+ /* @__PURE__ */ l("span", { children: b.label }),
2036
+ /* @__PURE__ */ l(Yt, { size: 10 })
2037
+ ]
2038
+ }
2039
+ )
2040
+ ] })
2041
+ ] }),
2042
+ /* @__PURE__ */ l("div", { className: "grounded-detail-path", children: /* @__PURE__ */ l("code", { children: f.source }) }),
2043
+ f.snippet && /* @__PURE__ */ w("p", { className: "grounded-detail-snippet", children: [
2044
+ '"',
2045
+ f.snippet,
2046
+ '"'
2047
+ ] })
2048
+ ]
2049
+ },
2050
+ `detail-${f.chunkId}-${c}`
2051
+ );
2052
+ }) })
2053
+ ] });
2054
+ };
2055
+ function cn(e) {
2056
+ return e === "create_ticket" ? "Support ticket processed" : e === "get_customer" ? "Account verified" : e === "get_ticket" ? "Ticket status loaded" : "Information retrieved";
1522
2057
  }
1523
- function Xr({ toolCalls: e }) {
1524
- return e.length ? /* @__PURE__ */ o("div", { className: "tool-badges", children: e.map((t, r) => /* @__PURE__ */ o(
2058
+ function un({ toolCalls: e }) {
2059
+ return e.length ? /* @__PURE__ */ l("div", { className: "tool-badges", children: e.map((t, n) => /* @__PURE__ */ l(
1525
2060
  "span",
1526
2061
  {
1527
2062
  className: "tool-badge",
1528
- children: Jr(t.toolName)
2063
+ children: cn(t.toolName)
1529
2064
  },
1530
- `${t.toolName}-${r}`
2065
+ `${t.toolName}-${n}`
1531
2066
  )) }) : null;
1532
2067
  }
1533
- const Qr = ({ message: e }) => {
1534
- const t = e.role === "user", r = e.status === "error";
1535
- return /* @__PURE__ */ k("div", { className: `msg-row${t ? " msg-row--user" : ""}`, children: [
1536
- !t && /* @__PURE__ */ o(
2068
+ const dn = ({ message: e }) => {
2069
+ var g;
2070
+ const t = Ge(), n = (t == null ? void 0 : t.hideInspectSources) ?? !1, r = (t == null ? void 0 : t.showGroundedSources) ?? !0, s = e.role === "user", o = e.status === "error", a = e.status === "pending", i = e.id === "welcome-default" || e.id.startsWith("welcome") || e.id === "welcome", u = !!(a || e.durationMs !== void 0 || e.sources && e.sources.length > 0 || e.toolCalls && e.toolCalls.length > 0 || e.usage);
2071
+ return /* @__PURE__ */ w("div", { className: `msg-row${s ? " msg-row--user" : ""}`, children: [
2072
+ !s && /* @__PURE__ */ l(
1537
2073
  "div",
1538
2074
  {
1539
2075
  className: "avatar-circle avatar-circle--mt",
1540
2076
  "aria-hidden": "true",
1541
- children: /* @__PURE__ */ o(lt, { size: 15 })
2077
+ children: /* @__PURE__ */ l(pt, { size: 15 })
1542
2078
  }
1543
2079
  ),
1544
- /* @__PURE__ */ k("div", { className: `msg-col${t ? " msg-col--user" : ""}`, children: [
1545
- /* @__PURE__ */ k(
2080
+ /* @__PURE__ */ w("div", { className: `msg-col${s ? " msg-col--user" : ""}`, children: [
2081
+ /* @__PURE__ */ w(
1546
2082
  "div",
1547
2083
  {
1548
- className: t ? "msg-bubble msg-bubble--user" : r ? "msg-bubble msg-bubble--error" : "msg-bubble msg-bubble--bot",
2084
+ className: s ? "msg-bubble msg-bubble--user" : o ? "msg-bubble msg-bubble--error" : "msg-bubble msg-bubble--bot",
1549
2085
  children: [
1550
- e.status === "pending" ? /* @__PURE__ */ o(Zr, {}) : t ? /* @__PURE__ */ o("p", { className: "msg-user-pre", children: e.content }) : /* @__PURE__ */ o(Yr, { text: e.content }),
1551
- e.toolCalls ? /* @__PURE__ */ o(Xr, { toolCalls: e.toolCalls }) : null,
1552
- e.sources ? /* @__PURE__ */ o(Kr, { sources: e.sources }) : null
2086
+ !s && !o && !i && u && /* @__PURE__ */ l(
2087
+ sn,
2088
+ {
2089
+ status: a ? "pending" : "complete",
2090
+ progressText: e.progressText,
2091
+ durationMs: e.durationMs
2092
+ }
2093
+ ),
2094
+ a ? e.content ? /* @__PURE__ */ l("div", { className: "msg-content-wrapper msg-content-wrapper--streaming", children: /* @__PURE__ */ l("div", { className: "msg-streaming-text", children: e.content }) }) : /* @__PURE__ */ l(nn, {}) : s ? /* @__PURE__ */ l("p", { className: "msg-user-pre", children: e.content }) : /* @__PURE__ */ l("div", { className: "msg-content-wrapper", children: /* @__PURE__ */ l(rn, { text: e.content }) }),
2095
+ e.toolCalls ? /* @__PURE__ */ l(un, { toolCalls: e.toolCalls }) : null,
2096
+ !s && !a && !o && r && ((g = e.sources) != null && g.length) ? /* @__PURE__ */ l(an, { sources: e.sources, hideInspectSources: n }) : null
1553
2097
  ]
1554
2098
  }
1555
2099
  ),
1556
- t && e.status !== "error" && /* @__PURE__ */ o(zt, { size: 13, className: "msg-tick", "aria-hidden": "true" })
2100
+ s && e.status !== "error" && /* @__PURE__ */ l(Wt, { size: 13, className: "msg-tick", "aria-hidden": "true" })
1557
2101
  ] })
1558
2102
  ] });
1559
- }, en = () => {
1560
- const { messages: e, status: t, showSuggestions: r } = ve();
1561
- return /* @__PURE__ */ o(
1562
- Gr,
2103
+ }, hn = () => {
2104
+ const { messages: e, status: t, showSuggestions: n } = Be();
2105
+ return /* @__PURE__ */ l(
2106
+ Yr,
1563
2107
  {
1564
2108
  autoScroll: !0,
1565
2109
  defaultScrollPosition: "last-anchor",
1566
2110
  scrollPreviousItemPeek: 64,
1567
- children: /* @__PURE__ */ k(Vr, { children: [
1568
- /* @__PURE__ */ o(Wr, { "aria-label": "Chat messages", children: /* @__PURE__ */ k($r, { "aria-busy": t === "awaiting" || t === "connecting", children: [
1569
- r && /* @__PURE__ */ o(Ye, { messageId: "welcome", children: /* @__PURE__ */ o(jr, {}) }),
1570
- e.map((s) => /* @__PURE__ */ o(
1571
- Ye,
2111
+ children: /* @__PURE__ */ w(Jr, { children: [
2112
+ /* @__PURE__ */ l(Kr, { "aria-label": "Chat messages", children: /* @__PURE__ */ w(Qr, { "aria-busy": t === "awaiting" || t === "connecting", children: [
2113
+ e.length === 0 && /* @__PURE__ */ l(nt, { messageId: "welcome", children: /* @__PURE__ */ l(Zr, {}) }),
2114
+ e.map((s) => /* @__PURE__ */ l(
2115
+ nt,
1572
2116
  {
1573
2117
  messageId: s.id,
1574
2118
  scrollAnchor: s.role === "user",
1575
- children: /* @__PURE__ */ o(Qr, { message: s })
2119
+ children: /* @__PURE__ */ l(dn, { message: s })
1576
2120
  },
1577
2121
  s.id
1578
2122
  ))
1579
2123
  ] }) }),
1580
- /* @__PURE__ */ o(Ur, {})
2124
+ /* @__PURE__ */ l(Xr, {})
1581
2125
  ] })
1582
2126
  }
1583
2127
  );
1584
- }, tn = () => {
1585
- const { pendingTicket: e, ticketBusy: t, userContext: r, confirmTicket: n, cancelTicket: s } = ve(), l = !r.customerId && !r.email, [a, i] = j("");
1586
- return e ? /* @__PURE__ */ k(
2128
+ }, pn = () => {
2129
+ const { pendingTicket: e, ticketBusy: t, userContext: n, confirmTicket: r, cancelTicket: s } = Be(), o = !n.customerId && !n.email, [a, i] = U("");
2130
+ return e ? /* @__PURE__ */ w(
1587
2131
  "div",
1588
2132
  {
1589
2133
  className: "ticket-card",
1590
2134
  role: "region",
1591
2135
  "aria-label": "Create support ticket",
1592
2136
  children: [
1593
- /* @__PURE__ */ o("h3", { className: "ticket-card-title", children: "Create support ticket?" }),
1594
- /* @__PURE__ */ o("p", { className: "ticket-card-desc", children: "I can open a support request for you. Nothing is created until you confirm." }),
1595
- /* @__PURE__ */ o("p", { className: "ticket-card-body", children: e.description }),
1596
- l && /* @__PURE__ */ k("label", { className: "ticket-id-label", children: [
2137
+ /* @__PURE__ */ l("h3", { className: "ticket-card-title", children: "Create support ticket?" }),
2138
+ /* @__PURE__ */ l("p", { className: "ticket-card-desc", children: "I can open a support request for you. Nothing is created until you confirm." }),
2139
+ /* @__PURE__ */ l("p", { className: "ticket-card-body", children: e.description }),
2140
+ o && /* @__PURE__ */ w("label", { className: "ticket-id-label", children: [
1597
2141
  "Customer ID or email",
1598
- /* @__PURE__ */ o(
2142
+ /* @__PURE__ */ l(
1599
2143
  "input",
1600
2144
  {
1601
2145
  value: a,
1602
- onChange: (d) => i(d.target.value),
2146
+ onChange: (u) => i(u.target.value),
1603
2147
  className: "ticket-id-input",
1604
2148
  placeholder: "CUST-1001 or you@company.com",
1605
2149
  autoComplete: "email"
1606
2150
  }
1607
2151
  )
1608
2152
  ] }),
1609
- /* @__PURE__ */ k("div", { className: "ticket-actions", children: [
1610
- /* @__PURE__ */ o(
2153
+ /* @__PURE__ */ w("div", { className: "ticket-actions", children: [
2154
+ /* @__PURE__ */ l(
1611
2155
  "button",
1612
2156
  {
1613
2157
  type: "button",
@@ -1617,12 +2161,12 @@ const Qr = ({ message: e }) => {
1617
2161
  children: "Cancel"
1618
2162
  }
1619
2163
  ),
1620
- /* @__PURE__ */ o(
2164
+ /* @__PURE__ */ l(
1621
2165
  "button",
1622
2166
  {
1623
2167
  type: "button",
1624
- onClick: () => void n(a),
1625
- disabled: t || l && !a.trim(),
2168
+ onClick: () => void r(a),
2169
+ disabled: t || o && !a.trim(),
1626
2170
  className: "ticket-confirm-btn",
1627
2171
  children: t ? "Creating…" : "Create ticket"
1628
2172
  }
@@ -1631,72 +2175,72 @@ const Qr = ({ message: e }) => {
1631
2175
  ]
1632
2176
  }
1633
2177
  ) : null;
1634
- }, mt = ({
2178
+ }, St = ({
1635
2179
  className: e,
1636
2180
  onClose: t,
1637
- showMinimize: r,
1638
- title: n,
2181
+ showMinimize: n,
2182
+ title: r,
1639
2183
  subtitle: s,
1640
- envStage: l,
2184
+ envStage: o,
1641
2185
  envPulse: a = !0
1642
2186
  }) => {
1643
- const { sendMessage: i, status: d, error: h, resetConversation: g, retryLast: v, pendingTicket: f } = ve(), u = d === "awaiting" || d === "connecting" || !!f;
1644
- return /* @__PURE__ */ k(
2187
+ const { sendMessage: i, status: u, error: h, resetConversation: g, retryLast: f, pendingTicket: c } = Be(), p = u === "awaiting" || u === "connecting" || !!c;
2188
+ return /* @__PURE__ */ w(
1645
2189
  "section",
1646
2190
  {
1647
2191
  className: `chat-panel${e ? ` ${e}` : ""}`,
1648
2192
  "aria-label": "VPS AI Assistant",
1649
2193
  children: [
1650
- /* @__PURE__ */ o(
1651
- er,
2194
+ /* @__PURE__ */ l(
2195
+ lr,
1652
2196
  {
1653
- title: n,
2197
+ title: r,
1654
2198
  subtitle: s,
1655
2199
  onClose: t,
1656
2200
  onReset: () => void g(),
1657
- showMinimize: r,
1658
- envStage: l,
2201
+ showMinimize: n,
2202
+ envStage: o,
1659
2203
  envPulse: a
1660
2204
  }
1661
2205
  ),
1662
- /* @__PURE__ */ o("div", { className: "chat-panel-body", children: /* @__PURE__ */ o(en, {}) }),
1663
- h && d === "error" && /* @__PURE__ */ o(It, { message: h, onRetry: () => void v() }),
1664
- /* @__PURE__ */ o(tn, {}),
1665
- /* @__PURE__ */ o(
1666
- sr,
2206
+ /* @__PURE__ */ l("div", { className: "chat-panel-body", children: /* @__PURE__ */ l(hn, {}) }),
2207
+ h && u === "error" && /* @__PURE__ */ l(Pt, { message: h, onRetry: () => void f() }),
2208
+ /* @__PURE__ */ l(pn, {}),
2209
+ /* @__PURE__ */ l(
2210
+ ur,
1667
2211
  {
1668
- onSend: (m) => void i(m),
1669
- disabled: u
2212
+ onSend: (b) => void i(b),
2213
+ disabled: p
1670
2214
  }
1671
2215
  )
1672
2216
  ]
1673
2217
  }
1674
2218
  );
1675
- }, rn = ({
2219
+ }, fn = ({
1676
2220
  open: e,
1677
2221
  onClose: t,
1678
- envStage: r,
1679
- envPulse: n = !0
1680
- }) => e ? /* @__PURE__ */ o(
2222
+ envStage: n,
2223
+ envPulse: r = !0
2224
+ }) => e ? /* @__PURE__ */ l(
1681
2225
  "div",
1682
2226
  {
1683
2227
  id: "vps-chatbot-widget-panel",
1684
2228
  className: "widget-panel",
1685
- children: /* @__PURE__ */ o(
1686
- mt,
2229
+ children: /* @__PURE__ */ l(
2230
+ St,
1687
2231
  {
1688
2232
  onClose: t,
1689
2233
  showMinimize: !0,
1690
2234
  title: "VPS AI Assistant",
1691
- envStage: r,
1692
- envPulse: n
2235
+ envStage: n,
2236
+ envPulse: r
1693
2237
  }
1694
2238
  )
1695
2239
  }
1696
- ) : null, nn = ({
2240
+ ) : null, mn = ({
1697
2241
  open: e,
1698
2242
  onToggle: t
1699
- }) => /* @__PURE__ */ o(
2243
+ }) => /* @__PURE__ */ l(
1700
2244
  "button",
1701
2245
  {
1702
2246
  type: "button",
@@ -1705,61 +2249,75 @@ const Qr = ({ message: e }) => {
1705
2249
  "aria-controls": "vps-chatbot-widget-panel",
1706
2250
  "aria-label": e ? "Close assistant" : "Open assistant",
1707
2251
  className: "widget-trigger-btn",
1708
- children: e ? /* @__PURE__ */ o(Jt, { size: 22 }) : /* @__PURE__ */ o(ot, { size: 24 })
2252
+ children: e ? /* @__PURE__ */ l(rr, { size: 22 }) : /* @__PURE__ */ l(ft, { size: 24 })
1709
2253
  }
1710
- ), Ze = ({
2254
+ ), ot = ({
1711
2255
  defaultOpen: e = !1,
1712
2256
  open: t,
1713
- onOpenChange: r,
1714
- envStage: n,
2257
+ onOpenChange: n,
2258
+ envStage: r,
1715
2259
  envPulse: s = !0
1716
2260
  }) => {
1717
- const [l, a] = j(e), i = t ?? l, d = (h) => {
1718
- r == null || r(h), t === void 0 && a(h);
2261
+ const [o, a] = U(e), i = t ?? o, u = (h) => {
2262
+ n == null || n(h), t === void 0 && a(h);
1719
2263
  };
1720
- return /* @__PURE__ */ k(oe, { children: [
1721
- /* @__PURE__ */ o(
1722
- rn,
2264
+ return /* @__PURE__ */ w(De, { children: [
2265
+ /* @__PURE__ */ l(
2266
+ fn,
1723
2267
  {
1724
2268
  open: i,
1725
- onClose: () => d(!1),
1726
- envStage: n,
2269
+ onClose: () => u(!1),
2270
+ envStage: r,
1727
2271
  envPulse: s
1728
2272
  }
1729
2273
  ),
1730
- /* @__PURE__ */ o(nn, { open: i, onToggle: () => d(!i) })
2274
+ /* @__PURE__ */ l(mn, { open: i, onToggle: () => u(!i) })
1731
2275
  ] });
1732
- }, pn = ({
2276
+ }, Fn = ({
1733
2277
  apiBaseUrl: e,
1734
2278
  apiUrl: t,
1735
- proxyUrl: r,
1736
- userContext: n,
1737
- suggestions: s,
1738
- disableSuggestions: l,
1739
- initialMessage: a,
1740
- ...i
2279
+ proxyUrl: n,
2280
+ userContext: r,
2281
+ role: s,
2282
+ roleId: o,
2283
+ client: a,
2284
+ welcomeMessage: i,
2285
+ suggestions: u,
2286
+ disableSuggestions: h,
2287
+ initialMessage: g,
2288
+ hideInspectSources: f,
2289
+ showGroundedSources: c,
2290
+ modelId: p,
2291
+ ...b
1741
2292
  }) => {
1742
- const d = rt(), h = e ?? t ?? r;
1743
- return !!d && (!h || ee(h) === ee(d == null ? void 0 : d.apiBaseUrl)) && !n && !s && l === void 0 && !a ? /* @__PURE__ */ o(Ze, { ...i }) : /* @__PURE__ */ o(
1744
- nt,
2293
+ const k = Ge(), v = e ?? t ?? n;
2294
+ return !!k && (!v || ve(v) === ve(k == null ? void 0 : k.apiBaseUrl)) && !r && s === void 0 && o === void 0 && a === void 0 && i === void 0 && !u && h === void 0 && !g && f === void 0 && c === void 0 && p === void 0 ? /* @__PURE__ */ l(ot, { ...b }) : /* @__PURE__ */ l(
2295
+ dt,
1745
2296
  {
1746
- apiBaseUrl: h,
1747
- userContext: n,
1748
- suggestions: s,
1749
- disableSuggestions: l,
1750
- initialMessage: a,
1751
- children: /* @__PURE__ */ o(Ze, { ...i })
2297
+ apiBaseUrl: v,
2298
+ userContext: r,
2299
+ role: s,
2300
+ roleId: o,
2301
+ client: a,
2302
+ welcomeMessage: i,
2303
+ suggestions: u,
2304
+ disableSuggestions: h,
2305
+ initialMessage: g,
2306
+ hideInspectSources: f,
2307
+ showGroundedSources: c,
2308
+ modelId: p,
2309
+ children: /* @__PURE__ */ l(ot, { ...b })
1752
2310
  }
1753
2311
  );
1754
- }, sn = ({
2312
+ }, gn = ({
1755
2313
  open: e,
1756
2314
  onClose: t,
1757
- subtitle: r,
1758
- title: n,
2315
+ subtitle: n,
2316
+ title: r,
1759
2317
  envStage: s,
1760
- envPulse: l = !0
1761
- }) => /* @__PURE__ */ k(oe, { children: [
1762
- /* @__PURE__ */ o(
2318
+ envPulse: o = !0
2319
+ }) => /* @__PURE__ */ w(De, { children: [
2320
+ /* @__PURE__ */ l(
1763
2321
  "div",
1764
2322
  {
1765
2323
  className: `embedded-overlay ${e ? "embedded-overlay--open" : "embedded-overlay--closed"}`,
@@ -1768,38 +2326,38 @@ const Qr = ({ message: e }) => {
1768
2326
  "aria-hidden": "true"
1769
2327
  }
1770
2328
  ),
1771
- /* @__PURE__ */ o(
2329
+ /* @__PURE__ */ l(
1772
2330
  "aside",
1773
2331
  {
1774
2332
  id: "vps-embedded-chat-panel",
1775
2333
  className: `embedded-panel ${e ? "embedded-panel--open" : "embedded-panel--closed"}`,
1776
2334
  "aria-hidden": !e,
1777
- children: e && /* @__PURE__ */ o(
1778
- mt,
2335
+ children: e && /* @__PURE__ */ l(
2336
+ St,
1779
2337
  {
1780
2338
  onClose: t,
1781
- title: n || "VPS AI Assistant",
1782
- subtitle: r,
2339
+ title: r || "VPS AI Assistant",
2340
+ subtitle: n,
1783
2341
  envStage: s,
1784
- envPulse: l
2342
+ envPulse: o
1785
2343
  }
1786
2344
  )
1787
2345
  }
1788
2346
  )
1789
- ] }), ln = 5, we = 8, bt = "vps-embedded-assistant-top";
1790
- function on(e, t, r) {
1791
- return Math.min(r, Math.max(t, e));
1792
- }
1793
- function Je(e, t) {
1794
- const r = Math.max(
1795
- we,
1796
- window.innerHeight - t - we
2347
+ ] }), bn = 5, $e = 8, Ft = "vps-embedded-assistant-top";
2348
+ function vn(e, t, n) {
2349
+ return Math.min(n, Math.max(t, e));
2350
+ }
2351
+ function lt(e, t) {
2352
+ const n = Math.max(
2353
+ $e,
2354
+ window.innerHeight - t - $e
1797
2355
  );
1798
- return on(e, we, r);
2356
+ return vn(e, $e, n);
1799
2357
  }
1800
- function an() {
2358
+ function _n() {
1801
2359
  try {
1802
- const e = window.localStorage.getItem(bt);
2360
+ const e = window.localStorage.getItem(Ft);
1803
2361
  if (!e) return null;
1804
2362
  const t = Number(e);
1805
2363
  return Number.isFinite(t) ? t : null;
@@ -1807,78 +2365,78 @@ function an() {
1807
2365
  return null;
1808
2366
  }
1809
2367
  }
1810
- function cn(e) {
2368
+ function wn(e) {
1811
2369
  try {
1812
- window.localStorage.setItem(bt, String(e));
2370
+ window.localStorage.setItem(Ft, String(e));
1813
2371
  } catch {
1814
2372
  }
1815
2373
  }
1816
- const un = ({
2374
+ const yn = ({
1817
2375
  onOpen: e
1818
2376
  }) => {
1819
- const t = K(null), r = K({
2377
+ const t = re(null), n = re({
1820
2378
  pointerId: null,
1821
2379
  startY: 0,
1822
2380
  startTop: 0,
1823
2381
  moved: !1
1824
- }), [n, s] = j(
1825
- () => typeof window > "u" ? null : an()
1826
- ), l = K(n), a = K(!1), [i, d] = j(!1);
1827
- me(() => {
1828
- l.current = n;
1829
- }, [n]), me(() => {
1830
- const f = t.current;
1831
- if (!f) return;
1832
- const u = () => {
1833
- s((m) => {
1834
- const T = m ?? Math.round(window.innerHeight / 2 - f.offsetHeight / 2), _ = Je(T, f.offsetHeight);
1835
- return l.current = _, _;
2382
+ }), [r, s] = U(
2383
+ () => typeof window > "u" ? null : _n()
2384
+ ), o = re(r), a = re(!1), [i, u] = U(!1);
2385
+ ke(() => {
2386
+ o.current = r;
2387
+ }, [r]), ke(() => {
2388
+ const c = t.current;
2389
+ if (!c) return;
2390
+ const p = () => {
2391
+ s((b) => {
2392
+ const k = b ?? Math.round(window.innerHeight / 2 - c.offsetHeight / 2), v = lt(k, c.offsetHeight);
2393
+ return o.current = v, v;
1836
2394
  });
1837
2395
  };
1838
- return u(), window.addEventListener("resize", u), () => window.removeEventListener("resize", u);
2396
+ return p(), window.addEventListener("resize", p), () => window.removeEventListener("resize", p);
1839
2397
  }, []);
1840
- const h = (f) => {
1841
- if (f.button !== 0) return;
1842
- const u = f.currentTarget, m = u.getBoundingClientRect();
1843
- r.current = {
1844
- pointerId: f.pointerId,
1845
- startY: f.clientY,
1846
- startTop: m.top,
2398
+ const h = (c) => {
2399
+ if (c.button !== 0) return;
2400
+ const p = c.currentTarget, b = p.getBoundingClientRect();
2401
+ n.current = {
2402
+ pointerId: c.pointerId,
2403
+ startY: c.clientY,
2404
+ startTop: b.top,
1847
2405
  moved: !1
1848
2406
  };
1849
2407
  try {
1850
- u.setPointerCapture(f.pointerId);
2408
+ p.setPointerCapture(c.pointerId);
1851
2409
  } catch {
1852
2410
  }
1853
- }, g = (f) => {
1854
- if (r.current.pointerId !== f.pointerId) return;
1855
- const u = f.clientY - r.current.startY;
1856
- if (!r.current.moved && Math.abs(u) < ln) return;
1857
- r.current.moved = !0, d(!0);
1858
- const m = Je(
1859
- r.current.startTop + u,
1860
- f.currentTarget.offsetHeight
2411
+ }, g = (c) => {
2412
+ if (n.current.pointerId !== c.pointerId) return;
2413
+ const p = c.clientY - n.current.startY;
2414
+ if (!n.current.moved && Math.abs(p) < bn) return;
2415
+ n.current.moved = !0, u(!0);
2416
+ const b = lt(
2417
+ n.current.startTop + p,
2418
+ c.currentTarget.offsetHeight
1861
2419
  );
1862
- l.current = m, s(m);
1863
- }, v = (f) => {
1864
- var m, T;
1865
- if (r.current.pointerId !== f.pointerId) return;
2420
+ o.current = b, s(b);
2421
+ }, f = (c) => {
2422
+ var b, k;
2423
+ if (n.current.pointerId !== c.pointerId) return;
1866
2424
  try {
1867
- (T = (m = f.currentTarget).hasPointerCapture) != null && T.call(m, f.pointerId) && f.currentTarget.releasePointerCapture(f.pointerId);
2425
+ (k = (b = c.currentTarget).hasPointerCapture) != null && k.call(b, c.pointerId) && c.currentTarget.releasePointerCapture(c.pointerId);
1868
2426
  } catch {
1869
2427
  }
1870
- const u = r.current.moved;
1871
- r.current.pointerId = null, r.current.moved = !1, d(!1), u && (a.current = !0, l.current != null && cn(l.current));
2428
+ const p = n.current.moved;
2429
+ n.current.pointerId = null, n.current.moved = !1, u(!1), p && (a.current = !0, o.current != null && wn(o.current));
1872
2430
  };
1873
- return /* @__PURE__ */ k(
2431
+ return /* @__PURE__ */ w(
1874
2432
  "button",
1875
2433
  {
1876
2434
  ref: t,
1877
2435
  type: "button",
1878
2436
  onPointerDown: h,
1879
2437
  onPointerMove: g,
1880
- onPointerUp: v,
1881
- onPointerCancel: v,
2438
+ onPointerUp: f,
2439
+ onPointerCancel: f,
1882
2440
  onClick: () => {
1883
2441
  if (a.current) {
1884
2442
  a.current = !1;
@@ -1891,61 +2449,75 @@ const un = ({
1891
2449
  "aria-label": "Assistant",
1892
2450
  className: `embedded-trigger-btn ${i ? "embedded-trigger-btn--grabbing" : "embedded-trigger-btn--grab"}`,
1893
2451
  style: {
1894
- top: n ?? "50%",
1895
- transform: n == null ? "translateY(-50%)" : void 0
2452
+ top: r ?? "50%",
2453
+ transform: r == null ? "translateY(-50%)" : void 0
1896
2454
  },
1897
2455
  children: [
1898
- /* @__PURE__ */ o(ot, { size: 16 }),
2456
+ /* @__PURE__ */ l(ft, { size: 16 }),
1899
2457
  "Assistant"
1900
2458
  ]
1901
2459
  }
1902
2460
  );
1903
- }, Ke = ({
2461
+ }, at = ({
1904
2462
  defaultOpen: e = !1,
1905
2463
  open: t,
1906
- onOpenChange: r,
1907
- showTrigger: n = !0,
2464
+ onOpenChange: n,
2465
+ showTrigger: r = !0,
1908
2466
  envStage: s,
1909
- envPulse: l = !0
2467
+ envPulse: o = !0
1910
2468
  }) => {
1911
- const [a, i] = j(e), d = t ?? a, h = (g) => {
1912
- r == null || r(g), t === void 0 && i(g);
2469
+ const [a, i] = U(e), u = t ?? a, h = (g) => {
2470
+ n == null || n(g), t === void 0 && i(g);
1913
2471
  };
1914
- return /* @__PURE__ */ k(oe, { children: [
1915
- n && !d && /* @__PURE__ */ o(un, { onOpen: () => h(!0) }),
1916
- /* @__PURE__ */ o(
1917
- sn,
2472
+ return /* @__PURE__ */ w(De, { children: [
2473
+ r && !u && /* @__PURE__ */ l(yn, { onOpen: () => h(!0) }),
2474
+ /* @__PURE__ */ l(
2475
+ gn,
1918
2476
  {
1919
- open: d,
2477
+ open: u,
1920
2478
  onClose: () => h(!1),
1921
2479
  envStage: s,
1922
- envPulse: l
2480
+ envPulse: o
1923
2481
  }
1924
2482
  )
1925
2483
  ] });
1926
- }, gn = ({
2484
+ }, Tn = ({
1927
2485
  apiBaseUrl: e,
1928
2486
  apiUrl: t,
1929
- proxyUrl: r,
1930
- userContext: n,
1931
- suggestions: s,
1932
- disableSuggestions: l,
1933
- initialMessage: a,
1934
- ...i
2487
+ proxyUrl: n,
2488
+ userContext: r,
2489
+ role: s,
2490
+ roleId: o,
2491
+ client: a,
2492
+ welcomeMessage: i,
2493
+ suggestions: u,
2494
+ disableSuggestions: h,
2495
+ initialMessage: g,
2496
+ hideInspectSources: f,
2497
+ showGroundedSources: c,
2498
+ modelId: p,
2499
+ ...b
1935
2500
  }) => {
1936
- const d = rt(), h = e ?? t ?? r;
1937
- return !!d && (!h || ee(h) === ee(d == null ? void 0 : d.apiBaseUrl)) && !n && !s && l === void 0 && !a ? /* @__PURE__ */ o(Ke, { ...i }) : /* @__PURE__ */ o(
1938
- nt,
2501
+ const k = Ge(), v = e ?? t ?? n;
2502
+ return !!k && (!v || ve(v) === ve(k == null ? void 0 : k.apiBaseUrl)) && !r && s === void 0 && o === void 0 && a === void 0 && i === void 0 && !u && h === void 0 && !g && f === void 0 && c === void 0 && p === void 0 ? /* @__PURE__ */ l(at, { ...b }) : /* @__PURE__ */ l(
2503
+ dt,
1939
2504
  {
1940
- apiBaseUrl: h,
1941
- userContext: n,
1942
- suggestions: s,
1943
- disableSuggestions: l,
1944
- initialMessage: a,
1945
- children: /* @__PURE__ */ o(Ke, { ...i })
2505
+ apiBaseUrl: v,
2506
+ userContext: r,
2507
+ role: s,
2508
+ roleId: o,
2509
+ client: a,
2510
+ welcomeMessage: i,
2511
+ suggestions: u,
2512
+ disableSuggestions: h,
2513
+ initialMessage: g,
2514
+ hideInspectSources: f,
2515
+ showGroundedSources: c,
2516
+ modelId: p,
2517
+ children: /* @__PURE__ */ l(at, { ...b })
1946
2518
  }
1947
2519
  );
1948
- }, mn = {
2520
+ }, En = {
1949
2521
  Colors: {
1950
2522
  VPS_White: "#fff",
1951
2523
  VPS_Dark_Blue: "#1A1A31",
@@ -2110,16 +2682,16 @@ const un = ({
2110
2682
  }
2111
2683
  };
2112
2684
  export {
2113
- mt as ChatPanel,
2114
- nt as ChatProvider,
2115
- pn as ChatbotWidget,
2116
- mn as ColorPalette,
2117
- gn as EmbeddedChatbot,
2118
- We as buildApiUrl,
2119
- hn as chatApi,
2120
- tt as createChatApi,
2121
- ee as resolveApiBaseUrl,
2122
- Dt as useChatContext,
2123
- ve as useChatbot,
2124
- rt as useOptionalChatContext
2685
+ St as ChatPanel,
2686
+ dt as ChatProvider,
2687
+ Fn as ChatbotWidget,
2688
+ En as ColorPalette,
2689
+ Tn as EmbeddedChatbot,
2690
+ Pe as buildApiUrl,
2691
+ Sn as chatApi,
2692
+ ut as createChatApi,
2693
+ ve as resolveApiBaseUrl,
2694
+ Mt as useChatContext,
2695
+ Be as useChatbot,
2696
+ Ge as useOptionalChatContext
2125
2697
  };