@scrimpify-software/rag-widgets 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,332 +1,332 @@
1
- import { jsxs as y, jsx as n, Fragment as re } from "react/jsx-runtime";
2
- import { useRef as R, useCallback as O, useState as L, useEffect as D, useMemo as X, createElement as z, Fragment as V } from "react";
3
- import { createPortal as oe } from "react-dom";
4
- const ie = 3e4, P = 600, se = 3600, ae = "KnowLayer widgets: getToken and getFirebaseIdToken are mutually exclusive.", de = 5e3;
5
- function le(e, t) {
1
+ import { jsxs as m, jsx as r, Fragment as fe } from "react/jsx-runtime";
2
+ import { useRef as R, useCallback as P, useState as C, useEffect as F, useMemo as U, createElement as O, Fragment as Z } from "react";
3
+ import { createPortal as pe } from "react-dom";
4
+ const ge = 3e4, N = 600, he = 3600, be = "KnowLayer widgets: getToken and getFirebaseIdToken are mutually exclusive.", xe = 5e3;
5
+ function ye(e, t) {
6
6
  return e ? "getToken" : t ? "firebase" : "public";
7
7
  }
8
- function ue(e, t) {
8
+ function me(e, t) {
9
9
  if (e && typeof e == "object" && "detail" in e) {
10
- const r = e.detail;
11
- if (typeof r == "string" && r.trim()) return r;
10
+ const n = e.detail;
11
+ if (typeof n == "string" && n.trim()) return n;
12
12
  }
13
13
  return t;
14
14
  }
15
- function ce(e) {
15
+ function ke(e) {
16
16
  return e.includes("eyJ") || e.length > 300 ? "Couldn't start the assistant. Please try again." : e;
17
17
  }
18
- function fe(e) {
18
+ function Be(e) {
19
19
  if (typeof e == "string") {
20
20
  if (!e)
21
21
  throw new Error("getToken returned an empty token.");
22
- return { token: e, expiresIn: P };
22
+ return { token: e, expiresIn: N };
23
23
  }
24
24
  const t = e && typeof e.token == "string" && e.token ? e.token : e && typeof e.access_token == "string" ? e.access_token : "";
25
25
  if (!t)
26
26
  throw new Error("getToken must return a token string or { token, expires_in }.");
27
- const r = typeof e.expires_in == "number" ? e.expires_in : P;
28
- return { token: t, expiresIn: r };
27
+ const n = typeof e.expires_in == "number" ? e.expires_in : N;
28
+ return { token: t, expiresIn: n };
29
29
  }
30
- async function J(e, t) {
30
+ async function ee(e, t) {
31
31
  if (!e.ok) {
32
32
  const i = await e.json().catch(() => ({}));
33
33
  throw new Error(
34
- ue(i, `Widget token request failed (${e.status})`)
34
+ me(i, `Widget token request failed (${e.status})`)
35
35
  );
36
36
  }
37
- const r = await e.json();
38
- if (!r || typeof r.token != "string" || !r.token)
37
+ const n = await e.json();
38
+ if (!n || typeof n.token != "string" || !n.token)
39
39
  throw new Error("Widget token response missing token.");
40
- const s = typeof r.expires_in == "number" ? r.expires_in : t;
41
- return { token: r.token, expiresIn: s };
40
+ const o = typeof n.expires_in == "number" ? n.expires_in : t;
41
+ return { token: n.token, expiresIn: o };
42
42
  }
43
- function H({
43
+ function V({
44
44
  apiUrl: e,
45
45
  clientId: t,
46
- getFirebaseIdToken: r,
47
- getToken: s
46
+ getFirebaseIdToken: n,
47
+ getToken: o
48
48
  }) {
49
- if (s && r)
50
- throw new Error(ae);
51
- const i = le(s, r), c = `${e}|${t}|${i}`, g = R(s), k = R(r);
52
- g.current = s, k.current = r;
53
- const o = R(null), l = R(null), m = R(null), x = R(0), w = O(() => {
54
- o.current = null, l.current = null, m.current = null, x.current += 1;
55
- }, []), p = O(async () => {
56
- const d = x.current, b = m.current;
57
- if (b && b.key === c && Date.now() - b.at < de)
58
- throw new Error(b.message);
49
+ if (o && n)
50
+ throw new Error(be);
51
+ const i = ye(o, n), f = `${e}|${t}|${i}`, a = R(o), k = R(n);
52
+ a.current = o, k.current = n;
53
+ const s = R(null), d = R(null), x = R(null), g = R(0), B = P(() => {
54
+ s.current = null, d.current = null, x.current = null, g.current += 1;
55
+ }, []), l = P(async () => {
56
+ const u = g.current, y = x.current;
57
+ if (y && y.key === f && Date.now() - y.at < xe)
58
+ throw new Error(y.message);
59
59
  try {
60
- let u;
61
- if (i === "getToken" && g.current)
62
- u = fe(await g.current());
60
+ let h;
61
+ if (i === "getToken" && a.current)
62
+ h = Be(await a.current());
63
63
  else if (i === "firebase" && k.current) {
64
- const h = await k.current(), S = await fetch(`${e}/api/v1/teams/widget-token`, {
64
+ const p = await k.current(), S = await fetch(`${e}/api/v1/teams/widget-token`, {
65
65
  method: "POST",
66
66
  headers: {
67
67
  "X-KL-Client-Id": t,
68
- "X-Firebase-Id-Token": h
68
+ "X-Firebase-Id-Token": p
69
69
  }
70
70
  });
71
- u = await J(S, se);
71
+ h = await ee(S, he);
72
72
  } else {
73
- const h = await fetch(`${e}/api/v1/teams/public-widget-session`, {
73
+ const p = await fetch(`${e}/api/v1/teams/public-widget-session`, {
74
74
  method: "POST",
75
75
  headers: { "X-KL-Client-Id": t }
76
76
  });
77
- u = await J(h, P);
77
+ h = await ee(p, N);
78
78
  }
79
- return d !== x.current || (o.current = {
80
- key: c,
81
- token: u.token,
82
- expiresAt: Date.now() + u.expiresIn * 1e3
83
- }, m.current = null), u.token;
84
- } catch (u) {
85
- const h = ce(
86
- u instanceof Error ? u.message : "Couldn't start the assistant. Please try again."
79
+ return u !== g.current || (s.current = {
80
+ key: f,
81
+ token: h.token,
82
+ expiresAt: Date.now() + h.expiresIn * 1e3
83
+ }, x.current = null), h.token;
84
+ } catch (h) {
85
+ const p = ke(
86
+ h instanceof Error ? h.message : "Couldn't start the assistant. Please try again."
87
87
  );
88
- throw d === x.current && (m.current = { key: c, at: Date.now(), message: h }), new Error(h);
88
+ throw u === g.current && (x.current = { key: f, at: Date.now(), message: p }), new Error(p);
89
89
  }
90
- }, [e, t, i, c]);
91
- return { getWidgetToken: O(async () => {
92
- const d = o.current;
93
- if (d && d.key === c && d.expiresAt - ie > Date.now())
94
- return d.token;
95
- const b = l.current;
96
- if (b && b.key === c)
97
- return b.promise;
98
- const u = p().finally(() => {
99
- var h;
100
- ((h = l.current) == null ? void 0 : h.promise) === u && (l.current = null);
90
+ }, [e, t, i, f]);
91
+ return { getWidgetToken: P(async () => {
92
+ const u = s.current;
93
+ if (u && u.key === f && u.expiresAt - ge > Date.now())
94
+ return u.token;
95
+ const y = d.current;
96
+ if (y && y.key === f)
97
+ return y.promise;
98
+ const h = l().finally(() => {
99
+ var p;
100
+ ((p = d.current) == null ? void 0 : p.promise) === h && (d.current = null);
101
101
  });
102
- return l.current = { key: c, promise: u }, u;
103
- }, [c, p]), invalidateWidgetToken: w, authMode: i };
102
+ return d.current = { key: f, promise: h }, h;
103
+ }, [f, l]), invalidateWidgetToken: B, authMode: i };
104
104
  }
105
- const pe = "http://localhost:8000", F = "Chat quota is exhausted. Please contact your organization admin.";
106
- function K(e) {
105
+ const we = "http://localhost:8000", q = "Chat quota is exhausted. Please contact your organization admin.";
106
+ function X(e) {
107
107
  return e === "public" ? "Public documents" : "Signed in · includes your teams";
108
108
  }
109
- const ge = "Hello! Ask me anything about your documentation.";
110
- let he = 0;
111
- function A() {
112
- return `msg_${Date.now()}_${++he}`;
109
+ const Se = "Hello! Ask me anything about your documentation.";
110
+ let Te = 0;
111
+ function z() {
112
+ return `msg_${Date.now()}_${++Te}`;
113
113
  }
114
- async function Y(e, t, r) {
114
+ async function te(e, t, n) {
115
115
  return fetch(`${e}/api/v1/teams/me/chat`, {
116
116
  method: "POST",
117
117
  headers: {
118
118
  "Content-Type": "application/json",
119
119
  Authorization: `Bearer ${t}`
120
120
  },
121
- body: JSON.stringify({ query: r })
121
+ body: JSON.stringify({ query: n })
122
122
  });
123
123
  }
124
- function Z({
124
+ function ie({
125
125
  apiUrl: e,
126
126
  clientId: t,
127
- getFirebaseIdToken: r,
128
- getToken: s,
129
- welcomeMessage: i = ge,
130
- signedInWelcomeMessage: c
127
+ getFirebaseIdToken: n,
128
+ getToken: o,
129
+ welcomeMessage: i = Se,
130
+ signedInWelcomeMessage: f
131
131
  }) {
132
- const { getWidgetToken: g, invalidateWidgetToken: k, authMode: o } = H({
132
+ const { getWidgetToken: a, invalidateWidgetToken: k, authMode: s } = V({
133
133
  apiUrl: e,
134
134
  clientId: t,
135
- getFirebaseIdToken: r,
136
- getToken: s
137
- }), l = o !== "public" && c ? c : i, [m, x] = L(() => [
138
- { id: A(), role: "assistant", content: l }
139
- ]), [w, p] = L(!1), [C, d] = L(null), b = R(0), u = O(() => {
140
- b.current += 1, x([{ id: A(), role: "assistant", content: l }]), d(null), p(!1);
141
- }, [l]), h = R(o);
142
- D(() => {
143
- h.current !== o && (h.current = o, u());
144
- }, [o, u]);
145
- const S = O(
146
- async (W) => {
147
- const B = W.trim();
148
- if (!B || w) return;
149
- const $ = b.current, v = () => $ === b.current, _ = { id: A(), role: "user", content: B };
150
- x((T) => [...T, _]), p(!0), d(null);
135
+ getFirebaseIdToken: n,
136
+ getToken: o
137
+ }), d = s !== "public" && f ? f : i, [x, g] = C(() => [
138
+ { id: z(), role: "assistant", content: d }
139
+ ]), [B, l] = C(!1), [w, u] = C(null), y = R(0), h = P(() => {
140
+ y.current += 1, g([{ id: z(), role: "assistant", content: d }]), u(null), l(!1);
141
+ }, [d]), p = R(s);
142
+ F(() => {
143
+ p.current !== s && (p.current = s, h());
144
+ }, [s, h]);
145
+ const S = P(
146
+ async (L) => {
147
+ const v = L.trim();
148
+ if (!v || B) return;
149
+ const $ = y.current, T = () => $ === y.current, W = { id: z(), role: "user", content: v };
150
+ g((I) => [...I, W]), l(!0), u(null);
151
151
  try {
152
- const T = await g();
153
- let a = await Y(e, T, B);
154
- if (a.status === 401) {
152
+ const I = await a();
153
+ let c = await te(e, I, v);
154
+ if (c.status === 401) {
155
155
  k();
156
- const E = await g();
157
- a = await Y(e, E, B);
156
+ const _ = await a();
157
+ c = await te(e, _, v);
158
158
  }
159
- if (!v()) return;
160
- if (!a.ok) {
161
- if (a.status === 402) {
162
- d(F), x((j) => [
163
- ...j,
164
- { id: A(), role: "assistant", content: F }
159
+ if (!T()) return;
160
+ if (!c.ok) {
161
+ if (c.status === 402) {
162
+ u(q), g((D) => [
163
+ ...D,
164
+ { id: z(), role: "assistant", content: q }
165
165
  ]);
166
166
  return;
167
167
  }
168
- const E = await a.json().catch(() => ({}));
169
- throw new Error(E.detail || `Request failed (${a.status})`);
168
+ const _ = await c.json().catch(() => ({}));
169
+ throw new Error(_.detail || `Request failed (${c.status})`);
170
170
  }
171
- const I = await a.json();
172
- if (!v()) return;
173
- const M = Array.isArray(I.sources) && !I.llm_unavailable, f = {
174
- id: A(),
171
+ const M = await c.json();
172
+ if (!T()) return;
173
+ const E = Array.isArray(M.sources) && !M.llm_unavailable, b = {
174
+ id: z(),
175
175
  role: "assistant",
176
- content: I.answer ?? "No response received.",
177
- sources: M ? I.sources : void 0
176
+ content: M.answer ?? "No response received.",
177
+ sources: E ? M.sources : void 0
178
178
  };
179
- x((E) => [...E, f]);
180
- } catch (T) {
181
- if (!v()) return;
182
- const a = T instanceof Error ? T.message : "Something went wrong.", I = a.includes("eyJ") || a.length > 300 ? "Couldn't start the assistant. Please try again." : a;
183
- d(I), x((M) => [
184
- ...M,
185
- { id: A(), role: "assistant", content: "Sorry, I couldn't get a response. Please try again." }
179
+ g((_) => [..._, b]);
180
+ } catch (I) {
181
+ if (!T()) return;
182
+ const c = I instanceof Error ? I.message : "Something went wrong.", M = c.includes("eyJ") || c.length > 300 ? "Couldn't start the assistant. Please try again." : c;
183
+ u(M), g((E) => [
184
+ ...E,
185
+ { id: z(), role: "assistant", content: "Sorry, I couldn't get a response. Please try again." }
186
186
  ]);
187
187
  } finally {
188
- v() && p(!1);
188
+ T() && l(!1);
189
189
  }
190
190
  },
191
- [e, g, k, w]
191
+ [e, a, k, B]
192
192
  );
193
- return { messages: m, isLoading: w, error: C, authMode: o, sendMessage: S, reset: u };
193
+ return { messages: x, isLoading: B, error: w, authMode: s, sendMessage: S, reset: h };
194
194
  }
195
- function U({
195
+ function se({
196
196
  apiUrl: e,
197
197
  clientId: t,
198
- getFirebaseIdToken: r,
199
- getToken: s,
198
+ getFirebaseIdToken: n,
199
+ getToken: o,
200
200
  suggestedQuestions: i
201
201
  }) {
202
- const [c, g] = L([]), { getWidgetToken: k, invalidateWidgetToken: o, authMode: l } = H({
202
+ const [f, a] = C([]), { getWidgetToken: k, invalidateWidgetToken: s, authMode: d } = V({
203
203
  apiUrl: e,
204
204
  clientId: t,
205
- getFirebaseIdToken: r,
206
- getToken: s
207
- }), m = !!(i && i.length > 0);
208
- return D(() => {
209
- if (m) return;
210
- let x = !1;
211
- return g([]), (async () => {
212
- const w = (p) => fetch(`${e}/api/v1/teams/me/suggested-questions`, {
213
- headers: { Authorization: `Bearer ${p}` }
205
+ getFirebaseIdToken: n,
206
+ getToken: o
207
+ }), x = !!(i && i.length > 0);
208
+ return F(() => {
209
+ if (x) return;
210
+ let g = !1;
211
+ return a([]), (async () => {
212
+ const B = (l) => fetch(`${e}/api/v1/teams/me/suggested-questions`, {
213
+ headers: { Authorization: `Bearer ${l}` }
214
214
  });
215
215
  try {
216
- let p = await w(await k());
217
- if (p.status === 401 && !x && (o(), p = await w(await k())), !p.ok || x) return;
218
- const C = await p.json();
219
- if (x) return;
220
- const d = Array.isArray(C.questions) ? C.questions.filter(
221
- (b) => typeof b == "string" && b.trim().length > 0
216
+ let l = await B(await k());
217
+ if (l.status === 401 && !g && (s(), l = await B(await k())), !l.ok || g) return;
218
+ const w = await l.json();
219
+ if (g) return;
220
+ const u = Array.isArray(w.questions) ? w.questions.filter(
221
+ (y) => typeof y == "string" && y.trim().length > 0
222
222
  ) : [];
223
- g(d);
223
+ a(u);
224
224
  } catch {
225
225
  }
226
226
  })(), () => {
227
- x = !0;
227
+ g = !0;
228
228
  };
229
- }, [e, l, k, o, m]), m ? i : c;
229
+ }, [e, d, k, s, x]), x ? i : f;
230
230
  }
231
- const ee = 0.65;
232
- function ye(e) {
233
- const t = (e.team_id ?? "").toString().trim().toLowerCase(), r = t ? `team:${t}|` : "", s = (e.filename ?? "").trim().toLowerCase();
234
- if (s) return `${r}file:${s}`;
231
+ const ae = 0.65;
232
+ function ve(e) {
233
+ const t = (e.team_id ?? "").toString().trim().toLowerCase(), n = t ? `team:${t}|` : "", o = (e.filename ?? "").trim().toLowerCase();
234
+ if (o) return `${n}file:${o}`;
235
235
  const i = (e.document_id ?? "").toString().trim().toLowerCase();
236
- return i ? `${r}id:${i}` : `${r}text:${(e.text ?? "").slice(0, 60)}`;
236
+ return i ? `${n}id:${i}` : `${n}text:${(e.text ?? "").slice(0, 60)}`;
237
237
  }
238
- function xe(e, { minScore: t = ee } = {}) {
239
- const r = /* @__PURE__ */ new Map(), s = [];
238
+ function Ie(e, { minScore: t = ae } = {}) {
239
+ const n = /* @__PURE__ */ new Map(), o = [];
240
240
  for (const i of e) {
241
241
  if (i.score != null && i.score < t) continue;
242
- const c = ye(i), g = r.get(c);
243
- if (!g) {
244
- r.set(c, i), s.push(c);
242
+ const f = ve(i), a = n.get(f);
243
+ if (!a) {
244
+ n.set(f, i), o.push(f);
245
245
  continue;
246
246
  }
247
- (i.score ?? 0) > (g.score ?? 0) && r.set(c, i);
247
+ (i.score ?? 0) > (a.score ?? 0) && n.set(f, i);
248
248
  }
249
- return s.map((i) => r.get(i));
249
+ return o.map((i) => n.get(i));
250
250
  }
251
- function be(e) {
251
+ function $e(e) {
252
252
  return new Set(
253
- e.map((r) => (r.team_id ?? "").toString()).filter((r) => r.length > 0)
253
+ e.map((n) => (n.team_id ?? "").toString()).filter((n) => n.length > 0)
254
254
  ).size > 1;
255
255
  }
256
- function me(e) {
257
- const t = (e.clause_number ?? "").toString().trim(), r = (e.section_title ?? "").trim();
258
- return t && r ? `§ ${t} ${r}` : t ? `§ ${t}` : r || (e.title ?? "").trim() || null;
256
+ function Re(e) {
257
+ const t = (e.clause_number ?? "").toString().trim(), n = (e.section_title ?? "").trim();
258
+ return t && n ? `§ ${t} ${n}` : t ? `§ ${t}` : n || (e.title ?? "").trim() || null;
259
259
  }
260
- function N({
260
+ function J({
261
261
  sources: e,
262
262
  colors: t,
263
- compact: r = !1,
264
- minScore: s = ee
263
+ compact: n = !1,
264
+ minScore: o = ae
265
265
  }) {
266
- const [i, c] = L(!1), g = X(
267
- () => xe(e, { minScore: s }),
268
- [e, s]
269
- ), k = X(() => be(g), [g]);
270
- if (g.length === 0) return null;
271
- const o = r ? 11 : 12;
272
- return /* @__PURE__ */ y("div", { style: ke(t), children: [
273
- /* @__PURE__ */ y(
266
+ const [i, f] = C(!1), a = U(
267
+ () => Ie(e, { minScore: o }),
268
+ [e, o]
269
+ ), k = U(() => $e(a), [a]);
270
+ if (a.length === 0) return null;
271
+ const s = n ? 11 : 12;
272
+ return /* @__PURE__ */ m("div", { style: Ce(t), children: [
273
+ /* @__PURE__ */ m(
274
274
  "button",
275
275
  {
276
- onClick: () => c((l) => !l),
277
- style: we(t, o),
276
+ onClick: () => f((d) => !d),
277
+ style: Le(t, s),
278
278
  children: [
279
- /* @__PURE__ */ n($e, { size: r ? 12 : 14, color: t.textMuted }),
280
- /* @__PURE__ */ y("span", { children: [
281
- g.length,
279
+ /* @__PURE__ */ r(ze, { size: n ? 12 : 14, color: t.textMuted }),
280
+ /* @__PURE__ */ m("span", { children: [
281
+ a.length,
282
282
  " source",
283
- g.length > 1 ? "s" : "",
283
+ a.length > 1 ? "s" : "",
284
284
  " cited"
285
285
  ] }),
286
- /* @__PURE__ */ n(
287
- Re,
286
+ /* @__PURE__ */ r(
287
+ je,
288
288
  {
289
289
  direction: i ? "up" : "down",
290
- size: r ? 12 : 14,
290
+ size: n ? 12 : 14,
291
291
  color: t.textMuted
292
292
  }
293
293
  )
294
294
  ]
295
295
  }
296
296
  ),
297
- i && /* @__PURE__ */ n("ul", { style: { margin: 0, padding: 0, listStyle: "none", marginTop: 6 }, children: g.map((l, m) => {
298
- const x = l.filename ?? "Unknown source", w = k && l.team_name ? `${l.team_name} · ${x}` : x, p = me(l);
299
- return /* @__PURE__ */ y("li", { style: Se(t, m > 0), children: [
300
- /* @__PURE__ */ y("div", { style: { display: "flex", alignItems: "center", gap: 6 }, children: [
301
- /* @__PURE__ */ n("span", { style: ve(t), children: m + 1 }),
302
- /* @__PURE__ */ n(
297
+ i && /* @__PURE__ */ r("ul", { style: { margin: 0, padding: 0, listStyle: "none", marginTop: 6 }, children: a.map((d, x) => {
298
+ const g = d.filename ?? "Unknown source", B = k && d.team_name ? `${d.team_name} · ${g}` : g, l = Re(d);
299
+ return /* @__PURE__ */ m("li", { style: Me(t, x > 0), children: [
300
+ /* @__PURE__ */ m("div", { style: { display: "flex", alignItems: "center", gap: 6 }, children: [
301
+ /* @__PURE__ */ r("span", { style: We(t), children: x + 1 }),
302
+ /* @__PURE__ */ r(
303
303
  "span",
304
304
  {
305
- title: w,
305
+ title: B,
306
306
  style: {
307
307
  fontWeight: 600,
308
- fontSize: o,
308
+ fontSize: s,
309
309
  overflow: "hidden",
310
310
  textOverflow: "ellipsis",
311
311
  whiteSpace: "nowrap",
312
312
  flex: 1,
313
313
  minWidth: 0
314
314
  },
315
- children: w
315
+ children: B
316
316
  }
317
317
  ),
318
- l.score != null && /* @__PURE__ */ y("span", { style: Be(), children: [
319
- (l.score * 100).toFixed(0),
318
+ d.score != null && /* @__PURE__ */ m("span", { style: _e(), children: [
319
+ (d.score * 100).toFixed(0),
320
320
  "%"
321
321
  ] })
322
322
  ] }),
323
- p && /* @__PURE__ */ n("p", { style: Te(t, o), children: p }),
324
- l.text && /* @__PURE__ */ n("p", { style: Ce(t, o), children: l.text.length > 120 ? l.text.slice(0, 120) + "…" : l.text })
325
- ] }, `${l.team_id ?? ""}-${l.filename ?? l.document_id ?? "source"}-${m}`);
323
+ l && /* @__PURE__ */ r("p", { style: Ee(t, s), children: l }),
324
+ d.text && /* @__PURE__ */ r("p", { style: Ae(t, s), children: d.text.length > 120 ? d.text.slice(0, 120) + "…" : d.text })
325
+ ] }, `${d.team_id ?? ""}-${d.filename ?? d.document_id ?? "source"}-${x}`);
326
326
  }) })
327
327
  ] });
328
328
  }
329
- function ke(e) {
329
+ function Ce(e) {
330
330
  return {
331
331
  marginTop: 6,
332
332
  borderRadius: 8,
@@ -335,7 +335,7 @@ function ke(e) {
335
335
  padding: "6px 10px"
336
336
  };
337
337
  }
338
- function we(e, t) {
338
+ function Le(e, t) {
339
339
  return {
340
340
  display: "flex",
341
341
  alignItems: "center",
@@ -350,13 +350,13 @@ function we(e, t) {
350
350
  color: e.textMuted
351
351
  };
352
352
  }
353
- function Se(e, t) {
353
+ function Me(e, t) {
354
354
  return {
355
355
  padding: "6px 0",
356
356
  borderTop: t ? `1px solid ${e.border}` : "none"
357
357
  };
358
358
  }
359
- function ve(e) {
359
+ function We(e) {
360
360
  return {
361
361
  width: 18,
362
362
  height: 18,
@@ -371,7 +371,7 @@ function ve(e) {
371
371
  flexShrink: 0
372
372
  };
373
373
  }
374
- function Be() {
374
+ function _e() {
375
375
  return {
376
376
  fontSize: 10,
377
377
  fontWeight: 600,
@@ -382,7 +382,7 @@ function Be() {
382
382
  flexShrink: 0
383
383
  };
384
384
  }
385
- function Te(e, t) {
385
+ function Ee(e, t) {
386
386
  return {
387
387
  margin: "2px 0 0 24px",
388
388
  fontSize: t - 1,
@@ -393,7 +393,7 @@ function Te(e, t) {
393
393
  whiteSpace: "nowrap"
394
394
  };
395
395
  }
396
- function Ce(e, t) {
396
+ function Ae(e, t) {
397
397
  return {
398
398
  margin: "4px 0 0 24px",
399
399
  fontSize: t - 1,
@@ -405,8 +405,8 @@ function Ce(e, t) {
405
405
  overflow: "hidden"
406
406
  };
407
407
  }
408
- function $e({ size: e, color: t }) {
409
- return /* @__PURE__ */ y(
408
+ function ze({ size: e, color: t }) {
409
+ return /* @__PURE__ */ m(
410
410
  "svg",
411
411
  {
412
412
  width: e,
@@ -418,37 +418,37 @@ function $e({ size: e, color: t }) {
418
418
  strokeLinecap: "round",
419
419
  strokeLinejoin: "round",
420
420
  children: [
421
- /* @__PURE__ */ n("path", { d: "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" }),
422
- /* @__PURE__ */ n("polyline", { points: "14 2 14 8 20 8" }),
423
- /* @__PURE__ */ n("line", { x1: "16", y1: "13", x2: "8", y2: "13" }),
424
- /* @__PURE__ */ n("line", { x1: "16", y1: "17", x2: "8", y2: "17" })
421
+ /* @__PURE__ */ r("path", { d: "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" }),
422
+ /* @__PURE__ */ r("polyline", { points: "14 2 14 8 20 8" }),
423
+ /* @__PURE__ */ r("line", { x1: "16", y1: "13", x2: "8", y2: "13" }),
424
+ /* @__PURE__ */ r("line", { x1: "16", y1: "17", x2: "8", y2: "17" })
425
425
  ]
426
426
  }
427
427
  );
428
428
  }
429
- function Re({
429
+ function je({
430
430
  direction: e,
431
431
  size: t,
432
- color: r
432
+ color: n
433
433
  }) {
434
- return /* @__PURE__ */ n(
434
+ return /* @__PURE__ */ r(
435
435
  "svg",
436
436
  {
437
437
  width: t,
438
438
  height: t,
439
439
  viewBox: "0 0 24 24",
440
440
  fill: "none",
441
- stroke: r,
441
+ stroke: n,
442
442
  strokeWidth: "2",
443
443
  strokeLinecap: "round",
444
444
  strokeLinejoin: "round",
445
445
  style: { marginLeft: "auto" },
446
- children: e === "down" ? /* @__PURE__ */ n("polyline", { points: "6 9 12 15 18 9" }) : /* @__PURE__ */ n("polyline", { points: "18 15 12 9 6 15" })
446
+ children: e === "down" ? /* @__PURE__ */ r("polyline", { points: "6 9 12 15 18 9" }) : /* @__PURE__ */ r("polyline", { points: "18 15 12 9 6 15" })
447
447
  }
448
448
  );
449
449
  }
450
- function q({ colors: e }) {
451
- return /* @__PURE__ */ y(
450
+ function Y({ colors: e }) {
451
+ return /* @__PURE__ */ m(
452
452
  "div",
453
453
  {
454
454
  style: {
@@ -461,15 +461,15 @@ function q({ colors: e }) {
461
461
  color: e.textMuted
462
462
  },
463
463
  children: [
464
- /* @__PURE__ */ n("span", { children: "Powered by" }),
465
- /* @__PURE__ */ n(Le, { color: e.primary }),
466
- /* @__PURE__ */ n("span", { style: { fontWeight: 600, color: e.text }, children: "KnowLayer" })
464
+ /* @__PURE__ */ r("span", { children: "Powered by" }),
465
+ /* @__PURE__ */ r(Oe, { color: e.primary }),
466
+ /* @__PURE__ */ r("span", { style: { fontWeight: 600, color: e.text }, children: "KnowLayer" })
467
467
  ]
468
468
  }
469
469
  );
470
470
  }
471
- function Le({ color: e }) {
472
- return /* @__PURE__ */ y(
471
+ function Oe({ color: e }) {
472
+ return /* @__PURE__ */ m(
473
473
  "svg",
474
474
  {
475
475
  width: "14",
@@ -482,14 +482,14 @@ function Le({ color: e }) {
482
482
  strokeLinejoin: "round",
483
483
  "aria-hidden": "true",
484
484
  children: [
485
- /* @__PURE__ */ n("polygon", { points: "12 2 2 7 12 12 22 7 12 2" }),
486
- /* @__PURE__ */ n("polyline", { points: "2 17 12 22 22 17" }),
487
- /* @__PURE__ */ n("polyline", { points: "2 12 12 17 22 12" })
485
+ /* @__PURE__ */ r("polygon", { points: "12 2 2 7 12 12 22 7 12 2" }),
486
+ /* @__PURE__ */ r("polyline", { points: "2 17 12 22 22 17" }),
487
+ /* @__PURE__ */ r("polyline", { points: "2 12 12 17 22 12" })
488
488
  ]
489
489
  }
490
490
  );
491
491
  }
492
- const We = {
492
+ const de = {
493
493
  bg: "#ffffff",
494
494
  cardBg: "#f8fafc",
495
495
  border: "#e2e8f0",
@@ -501,10 +501,17 @@ const We = {
501
501
  userBubbleBg: "#2563eb",
502
502
  userBubbleText: "#ffffff",
503
503
  assistantBubbleBg: "#f1f5f9",
504
+ assistantBubbleText: "#1e293b",
504
505
  headerBg: "#ffffff",
505
506
  headerText: "#1e293b",
506
- dot: "#22c55e"
507
- }, Ie = {
507
+ dot: "#22c55e",
508
+ launcherBg: "#2563eb",
509
+ launcherIcon: "#ffffff",
510
+ sendBtnBg: "#2563eb",
511
+ sendBtnText: "#ffffff",
512
+ inputText: "#1e293b",
513
+ inputBorder: "#e2e8f0"
514
+ }, De = {
508
515
  bg: "#0f172a",
509
516
  cardBg: "#1e293b",
510
517
  border: "#334155",
@@ -516,31 +523,128 @@ const We = {
516
523
  userBubbleBg: "#3b82f6",
517
524
  userBubbleText: "#ffffff",
518
525
  assistantBubbleBg: "#334155",
526
+ assistantBubbleText: "#f1f5f9",
519
527
  headerBg: "#1e293b",
520
528
  headerText: "#f1f5f9",
521
- dot: "#22c55e"
529
+ dot: "#22c55e",
530
+ launcherBg: "#3b82f6",
531
+ launcherIcon: "#ffffff",
532
+ sendBtnBg: "#3b82f6",
533
+ sendBtnText: "#ffffff",
534
+ inputText: "#f1f5f9",
535
+ inputBorder: "#334155"
536
+ };
537
+ function A(e) {
538
+ if (typeof e != "string") return null;
539
+ const t = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e.trim());
540
+ if (!t) return null;
541
+ let n = t[1] ?? "";
542
+ n.length === 3 && (n = n.split("").map((i) => i + i).join(""));
543
+ const o = parseInt(n, 16);
544
+ return [o >> 16 & 255, o >> 8 & 255, o & 255];
545
+ }
546
+ function le([e, t, n]) {
547
+ return "#" + [e, t, n].map((o) => Math.round(Math.min(255, Math.max(0, o))).toString(16).padStart(2, "0")).join("");
548
+ }
549
+ function Q([e, t, n]) {
550
+ const o = (i) => {
551
+ const f = i / 255;
552
+ return f <= 0.03928 ? f / 12.92 : Math.pow((f + 0.055) / 1.055, 2.4);
553
+ };
554
+ return 0.2126 * o(e) + 0.7152 * o(t) + 0.0722 * o(n);
555
+ }
556
+ function ne(e, t) {
557
+ const n = Q(e), o = Q(t);
558
+ return (Math.max(n, o) + 0.05) / (Math.min(n, o) + 0.05);
559
+ }
560
+ function K(e) {
561
+ return ne(e, [255, 255, 255]) >= ne(e, [0, 0, 0]) ? "#ffffff" : "#000000";
562
+ }
563
+ function H(e, t, n) {
564
+ return le([
565
+ e[0] + (t[0] - e[0]) * n,
566
+ e[1] + (t[1] - e[1]) * n,
567
+ e[2] + (t[2] - e[2]) * n
568
+ ]);
569
+ }
570
+ function j(e, t) {
571
+ if (e == null || e === "") return null;
572
+ const n = A(e);
573
+ return n ? le(n) : (typeof console < "u" && console.warn(
574
+ `[KnowLayer widget] Ignoring invalid theme color for "${t}": ${String(e)}. Use #rgb or #rrggbb.`
575
+ ), null);
576
+ }
577
+ function re(e) {
578
+ return e === "dark" ? De : de;
579
+ }
580
+ const Pe = {
581
+ launcherBackground: "launcherBg",
582
+ launcherIcon: "launcherIcon",
583
+ headerBackground: "headerBg",
584
+ headerText: "headerText",
585
+ chatBackground: "bg",
586
+ userBubbleBackground: "userBubbleBg",
587
+ userBubbleText: "userBubbleText",
588
+ botBubbleBackground: "assistantBubbleBg",
589
+ botBubbleText: "assistantBubbleText",
590
+ sendButtonBackground: "sendBtnBg",
591
+ sendButtonIcon: "sendBtnText",
592
+ inputBackground: "inputBg",
593
+ inputText: "inputText",
594
+ inputBorder: "inputBorder",
595
+ borderColor: "border"
522
596
  };
523
- function Q(e) {
524
- return e === "dark" ? Ie : We;
597
+ function G(e) {
598
+ if (e === void 0 || e === "light" || e === "dark")
599
+ return re(e ?? "light");
600
+ if (typeof e != "object" || e === null) return de;
601
+ const t = j(e.background, "background"), n = j(e.chatBackground, "chatBackground"), o = t ?? n, i = o ? A(o) : null, f = e.mode === "dark" || e.mode === "light" ? e.mode : i && Q(i) < 0.4 ? "dark" : "light", a = { ...re(f) }, k = i ?? A(a.bg), d = j(e.text, "text") ?? (i ? K(i) : null), x = d ? A(d) : null;
602
+ if (o) {
603
+ const l = x ?? A(a.text);
604
+ a.bg = o, a.cardBg = H(k, l, 0.04), a.assistantBubbleBg = H(k, l, 0.08), a.border = H(k, l, 0.15), a.inputBorder = a.border, t && (a.inputBg = t, a.headerBg = t);
605
+ }
606
+ d && x && (a.text = d, a.headerText = d, a.inputText = d, a.assistantBubbleText = d, a.textMuted = H(x, k, 0.4));
607
+ const g = j(e.primary, "primary");
608
+ if (g) {
609
+ const l = K(A(g));
610
+ a.primary = g, a.primaryText = l, a.userBubbleBg = g, a.userBubbleText = l, a.launcherBg = g, a.launcherIcon = l, a.sendBtnBg = g, a.sendBtnText = l;
611
+ }
612
+ const B = [
613
+ ["launcherBackground", "launcherIcon", "launcherIcon"],
614
+ ["headerBackground", "headerText", "headerText"],
615
+ ["userBubbleBackground", "userBubbleText", "userBubbleText"],
616
+ ["botBubbleBackground", "botBubbleText", "assistantBubbleText"],
617
+ ["sendButtonBackground", "sendButtonIcon", "sendBtnText"],
618
+ ["inputBackground", "inputText", "inputText"]
619
+ ];
620
+ for (const [l, w, u] of B) {
621
+ const y = j(e[l], l);
622
+ y && !e[w] && (a[u] = K(A(y)));
623
+ }
624
+ for (const [l, w] of Object.entries(Pe)) {
625
+ const u = j(e[l], l);
626
+ u && (a[w] = u);
627
+ }
628
+ return a;
525
629
  }
526
- function te(e) {
630
+ function ue(e) {
527
631
  const t = e.split(`
528
- `), r = [];
529
- for (let s = 0; s < t.length; s++)
530
- s > 0 && r.push(z("br", { key: `br_${s}` })), r.push(
531
- z(V, { key: `line_${s}` }, ..._e(t[s]))
632
+ `), n = [];
633
+ for (let o = 0; o < t.length; o++)
634
+ o > 0 && n.push(O("br", { key: `br_${o}` })), n.push(
635
+ O(Z, { key: `line_${o}` }, ...Fe(t[o]))
532
636
  );
533
- return z(V, null, ...r);
637
+ return O(Z, null, ...n);
534
638
  }
535
- function _e(e) {
536
- const t = [], r = /(\*\*(.+?)\*\*|\*(.+?)\*|`(.+?)`)/g;
537
- let s = 0, i, c = 0;
538
- for (; (i = r.exec(e)) !== null; )
539
- i.index > s && t.push(e.slice(s, i.index)), i[2] !== void 0 ? t.push(z("strong", { key: `b_${c++}` }, i[2])) : i[3] !== void 0 ? t.push(z("em", { key: `i_${c++}` }, i[3])) : i[4] !== void 0 && t.push(
540
- z(
639
+ function Fe(e) {
640
+ const t = [], n = /(\*\*(.+?)\*\*|\*(.+?)\*|`(.+?)`)/g;
641
+ let o = 0, i, f = 0;
642
+ for (; (i = n.exec(e)) !== null; )
643
+ i.index > o && t.push(e.slice(o, i.index)), i[2] !== void 0 ? t.push(O("strong", { key: `b_${f++}` }, i[2])) : i[3] !== void 0 ? t.push(O("em", { key: `i_${f++}` }, i[3])) : i[4] !== void 0 && t.push(
644
+ O(
541
645
  "code",
542
646
  {
543
- key: `c_${c++}`,
647
+ key: `c_${f++}`,
544
648
  style: {
545
649
  background: "rgba(0,0,0,0.08)",
546
650
  padding: "1px 4px",
@@ -550,131 +654,131 @@ function _e(e) {
550
654
  },
551
655
  i[4]
552
656
  )
553
- ), s = i.index + i[0].length;
554
- return s < e.length && t.push(e.slice(s)), t.length === 0 && t.push(""), t;
657
+ ), o = i.index + i[0].length;
658
+ return o < e.length && t.push(e.slice(o)), t.length === 0 && t.push(""), t;
555
659
  }
556
- function Ee({
660
+ function He({
557
661
  apiUrl: e,
558
662
  clientId: t,
559
- getFirebaseIdToken: r,
560
- getToken: s,
663
+ getFirebaseIdToken: n,
664
+ getToken: o,
561
665
  title: i = "KnowLayer Assistant",
562
- placeholder: c = "Ask a question…",
563
- welcomeMessage: g,
666
+ placeholder: f = "Ask a question…",
667
+ welcomeMessage: a,
564
668
  signedInWelcomeMessage: k,
565
- theme: o = "light",
566
- position: l = "bottom-right",
567
- buttonSize: m = 56,
568
- popupWidth: x = "380px",
569
- popupHeight: w = "520px",
570
- suggestedQuestions: p,
571
- showScopeHint: C = !0,
572
- showCitations: d = !0,
573
- citationMinScore: b
669
+ theme: s = "light",
670
+ position: d = "bottom-right",
671
+ buttonSize: x = 56,
672
+ popupWidth: g = "380px",
673
+ popupHeight: B = "520px",
674
+ suggestedQuestions: l,
675
+ showScopeHint: w = !0,
676
+ showCitations: u = !0,
677
+ citationMinScore: y
574
678
  }) {
575
- const [u, h] = L(!1), S = Q(o), W = U({
679
+ const [h, p] = C(!1), S = G(s), L = se({
576
680
  apiUrl: e,
577
681
  clientId: t,
578
- getFirebaseIdToken: r,
579
- getToken: s,
580
- suggestedQuestions: p
682
+ getFirebaseIdToken: n,
683
+ getToken: o,
684
+ suggestedQuestions: l
581
685
  });
582
- return oe(
583
- /* @__PURE__ */ y(re, { children: [
584
- u && /* @__PURE__ */ n(
585
- Me,
686
+ return pe(
687
+ /* @__PURE__ */ m(fe, { children: [
688
+ h && /* @__PURE__ */ r(
689
+ Ke,
586
690
  {
587
691
  apiUrl: e,
588
692
  clientId: t,
589
- getFirebaseIdToken: r,
590
- getToken: s,
693
+ getFirebaseIdToken: n,
694
+ getToken: o,
591
695
  title: i,
592
- placeholder: c,
593
- welcomeMessage: g,
696
+ placeholder: f,
697
+ welcomeMessage: a,
594
698
  signedInWelcomeMessage: k,
595
699
  colors: S,
596
- position: l,
597
- buttonSize: m,
598
- popupWidth: x,
599
- popupHeight: w,
600
- onClose: () => h(!1),
601
- suggestedQuestions: W,
602
- showScopeHint: C,
603
- showCitations: d,
604
- citationMinScore: b
700
+ position: d,
701
+ buttonSize: x,
702
+ popupWidth: g,
703
+ popupHeight: B,
704
+ onClose: () => p(!1),
705
+ suggestedQuestions: L,
706
+ showScopeHint: w,
707
+ showCitations: u,
708
+ citationMinScore: y
605
709
  }
606
710
  ),
607
- /* @__PURE__ */ n(
711
+ /* @__PURE__ */ r(
608
712
  "button",
609
713
  {
610
- onClick: () => h((B) => !B),
611
- style: Ae(S, l, m),
612
- "aria-label": u ? "Close chat" : "Open chat",
613
- children: u ? /* @__PURE__ */ n(ne, {}) : /* @__PURE__ */ n(ze, {})
714
+ onClick: () => p((v) => !v),
715
+ style: Ne(S, d, x),
716
+ "aria-label": h ? "Close chat" : "Open chat",
717
+ children: h ? /* @__PURE__ */ r(ce, {}) : /* @__PURE__ */ r(qe, {})
614
718
  }
615
719
  )
616
720
  ] }),
617
721
  document.body
618
722
  );
619
723
  }
620
- function Me({
724
+ function Ke({
621
725
  apiUrl: e,
622
726
  clientId: t,
623
- getFirebaseIdToken: r,
624
- getToken: s,
727
+ getFirebaseIdToken: n,
728
+ getToken: o,
625
729
  title: i,
626
- placeholder: c,
627
- welcomeMessage: g,
730
+ placeholder: f,
731
+ welcomeMessage: a,
628
732
  signedInWelcomeMessage: k,
629
- colors: o,
630
- position: l,
631
- buttonSize: m,
632
- popupWidth: x,
633
- popupHeight: w,
634
- onClose: p,
635
- suggestedQuestions: C = [],
636
- showScopeHint: d,
637
- showCitations: b,
638
- citationMinScore: u
733
+ colors: s,
734
+ position: d,
735
+ buttonSize: x,
736
+ popupWidth: g,
737
+ popupHeight: B,
738
+ onClose: l,
739
+ suggestedQuestions: w = [],
740
+ showScopeHint: u,
741
+ showCitations: y,
742
+ citationMinScore: h
639
743
  }) {
640
- const { messages: h, isLoading: S, error: W, authMode: B, sendMessage: $ } = Z({
744
+ const { messages: p, isLoading: S, error: L, authMode: v, sendMessage: $ } = ie({
641
745
  apiUrl: e,
642
746
  clientId: t,
643
- getFirebaseIdToken: r,
644
- getToken: s,
645
- welcomeMessage: g,
747
+ getFirebaseIdToken: n,
748
+ getToken: o,
749
+ welcomeMessage: a,
646
750
  signedInWelcomeMessage: k
647
- }), [v, _] = L(""), T = R(null);
648
- D(() => {
649
- var f;
650
- (f = T.current) == null || f.scrollIntoView({ behavior: "smooth" });
651
- }, [h, S]);
652
- const a = (f) => {
653
- f.preventDefault(), v.trim() && ($(v), _(""));
654
- }, I = m + 16;
655
- return /* @__PURE__ */ y(
751
+ }), [T, W] = C(""), I = R(null);
752
+ F(() => {
753
+ var b;
754
+ (b = I.current) == null || b.scrollIntoView({ behavior: "smooth" });
755
+ }, [p, S]);
756
+ const c = (b) => {
757
+ b.preventDefault(), T.trim() && ($(T), W(""));
758
+ }, M = x + 16;
759
+ return /* @__PURE__ */ m(
656
760
  "div",
657
761
  {
658
762
  style: {
659
763
  position: "fixed",
660
- ...l === "bottom-left" ? { left: 20, bottom: I } : { right: 20, bottom: I },
661
- width: x,
662
- height: w,
764
+ ...d === "bottom-left" ? { left: 20, bottom: M } : { right: 20, bottom: M },
765
+ width: g,
766
+ height: B,
663
767
  zIndex: 2147483645,
664
768
  fontFamily: "system-ui, -apple-system, sans-serif",
665
769
  display: "flex",
666
770
  flexDirection: "column",
667
771
  borderRadius: 16,
668
- border: `1px solid ${o.border}`,
669
- background: o.bg,
670
- color: o.text,
772
+ border: `1px solid ${s.border}`,
773
+ background: s.bg,
774
+ color: s.text,
671
775
  boxShadow: "0 8px 32px rgba(0,0,0,0.18)",
672
776
  overflow: "hidden",
673
777
  animation: "knowlayer-fadein 0.2s ease-out"
674
778
  },
675
779
  children: [
676
- /* @__PURE__ */ n("style", { children: "@keyframes knowlayer-fadein { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }" }),
677
- /* @__PURE__ */ y(
780
+ /* @__PURE__ */ r("style", { children: "@keyframes knowlayer-fadein { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }" }),
781
+ /* @__PURE__ */ m(
678
782
  "div",
679
783
  {
680
784
  style: {
@@ -682,55 +786,57 @@ function Me({
682
786
  alignItems: "center",
683
787
  gap: 8,
684
788
  padding: "12px 16px",
685
- borderBottom: `1px solid ${o.border}`,
686
- background: o.headerBg
789
+ borderBottom: `1px solid ${s.border}`,
790
+ background: s.headerBg,
791
+ color: s.headerText
687
792
  },
688
793
  children: [
689
- /* @__PURE__ */ n(
794
+ /* @__PURE__ */ r(
690
795
  "span",
691
796
  {
692
797
  style: {
693
798
  width: 8,
694
799
  height: 8,
695
800
  borderRadius: "50%",
696
- background: o.dot,
801
+ background: s.dot,
697
802
  flexShrink: 0
698
803
  }
699
804
  }
700
805
  ),
701
- /* @__PURE__ */ n("span", { style: { fontWeight: 600, fontSize: 14, flex: 1 }, children: i }),
702
- d && /* @__PURE__ */ n("span", { style: { fontSize: 10, color: o.textMuted }, children: K(B) }),
703
- /* @__PURE__ */ n(
806
+ /* @__PURE__ */ r("span", { style: { fontWeight: 600, fontSize: 14, flex: 1 }, children: i }),
807
+ u && /* @__PURE__ */ r("span", { style: { fontSize: 10, color: s.headerText, opacity: 0.7 }, children: X(v) }),
808
+ /* @__PURE__ */ r(
704
809
  "button",
705
810
  {
706
- onClick: p,
811
+ onClick: l,
707
812
  style: {
708
813
  background: "none",
709
814
  border: "none",
710
815
  cursor: "pointer",
711
- color: o.textMuted,
816
+ color: s.headerText,
817
+ opacity: 0.7,
712
818
  padding: 4,
713
819
  display: "flex"
714
820
  },
715
821
  "aria-label": "Close",
716
- children: /* @__PURE__ */ n(ne, {})
822
+ children: /* @__PURE__ */ r(ce, {})
717
823
  }
718
824
  )
719
825
  ]
720
826
  }
721
827
  ),
722
- /* @__PURE__ */ y("div", { style: { flex: 1, minHeight: 0, overflowY: "auto", padding: 14 }, children: [
723
- h.map((f) => /* @__PURE__ */ y(
828
+ /* @__PURE__ */ m("div", { style: { flex: 1, minHeight: 0, overflowY: "auto", padding: 14 }, children: [
829
+ p.map((b) => /* @__PURE__ */ m(
724
830
  "div",
725
831
  {
726
832
  style: {
727
833
  display: "flex",
728
834
  flexDirection: "column",
729
- alignItems: f.role === "user" ? "flex-end" : "flex-start",
835
+ alignItems: b.role === "user" ? "flex-end" : "flex-start",
730
836
  marginBottom: 10
731
837
  },
732
838
  children: [
733
- /* @__PURE__ */ n(
839
+ /* @__PURE__ */ r(
734
840
  "div",
735
841
  {
736
842
  style: {
@@ -741,18 +847,18 @@ function Me({
741
847
  lineHeight: 1.55,
742
848
  whiteSpace: "pre-wrap",
743
849
  wordBreak: "break-word",
744
- background: f.role === "user" ? o.userBubbleBg : o.assistantBubbleBg,
745
- color: f.role === "user" ? o.userBubbleText : o.text
850
+ background: b.role === "user" ? s.userBubbleBg : s.assistantBubbleBg,
851
+ color: b.role === "user" ? s.userBubbleText : s.assistantBubbleText
746
852
  },
747
- children: f.role === "assistant" ? te(f.content) : f.content
853
+ children: b.role === "assistant" ? ue(b.content) : b.content
748
854
  }
749
855
  ),
750
- b && f.role === "assistant" && f.sources && f.sources.length > 0 && /* @__PURE__ */ n("div", { style: { maxWidth: "82%" }, children: /* @__PURE__ */ n(N, { sources: f.sources, colors: o, compact: !0, minScore: u }) })
856
+ y && b.role === "assistant" && b.sources && b.sources.length > 0 && /* @__PURE__ */ r("div", { style: { maxWidth: "82%" }, children: /* @__PURE__ */ r(J, { sources: b.sources, colors: s, compact: !0, minScore: h }) })
751
857
  ]
752
858
  },
753
- f.id
859
+ b.id
754
860
  )),
755
- S && /* @__PURE__ */ n("div", { style: { marginBottom: 10 }, children: /* @__PURE__ */ n(
861
+ S && /* @__PURE__ */ r("div", { style: { marginBottom: 10 }, children: /* @__PURE__ */ r(
756
862
  "div",
757
863
  {
758
864
  style: {
@@ -760,13 +866,13 @@ function Me({
760
866
  padding: "8px 12px",
761
867
  borderRadius: 12,
762
868
  fontSize: 13,
763
- background: o.assistantBubbleBg,
764
- color: o.textMuted
869
+ background: s.assistantBubbleBg,
870
+ color: s.textMuted
765
871
  },
766
872
  children: "Thinking…"
767
873
  }
768
874
  ) }),
769
- W && /* @__PURE__ */ n(
875
+ L && /* @__PURE__ */ r(
770
876
  "div",
771
877
  {
772
878
  style: {
@@ -778,21 +884,21 @@ function Me({
778
884
  fontSize: 12,
779
885
  marginBottom: 10
780
886
  },
781
- children: W
887
+ children: L
782
888
  }
783
889
  ),
784
- /* @__PURE__ */ n("div", { ref: T })
890
+ /* @__PURE__ */ r("div", { ref: I })
785
891
  ] }),
786
- C.length > 0 && h.length <= 1 && /* @__PURE__ */ y(
892
+ w.length > 0 && p.length <= 1 && /* @__PURE__ */ m(
787
893
  "div",
788
894
  {
789
895
  style: {
790
896
  padding: "8px 12px",
791
- borderTop: `1px solid ${o.border}`,
792
- background: o.cardBg
897
+ borderTop: `1px solid ${s.border}`,
898
+ background: s.cardBg
793
899
  },
794
900
  children: [
795
- /* @__PURE__ */ n(
901
+ /* @__PURE__ */ r(
796
902
  "span",
797
903
  {
798
904
  style: {
@@ -801,107 +907,107 @@ function Me({
801
907
  fontWeight: 600,
802
908
  textTransform: "uppercase",
803
909
  letterSpacing: "0.05em",
804
- color: o.textMuted,
910
+ color: s.textMuted,
805
911
  marginBottom: 5
806
912
  },
807
913
  children: "Try asking"
808
914
  }
809
915
  ),
810
- /* @__PURE__ */ n("div", { style: { display: "flex", flexWrap: "wrap", gap: 5 }, children: C.map((f) => /* @__PURE__ */ n(
916
+ /* @__PURE__ */ r("div", { style: { display: "flex", flexWrap: "wrap", gap: 5 }, children: w.map((b) => /* @__PURE__ */ r(
811
917
  "button",
812
918
  {
813
919
  type: "button",
814
920
  onClick: () => {
815
- $(f);
921
+ $(b);
816
922
  },
817
923
  style: {
818
924
  background: "none",
819
- border: `1px solid ${o.border}`,
925
+ border: `1px solid ${s.border}`,
820
926
  borderRadius: 999,
821
927
  padding: "3px 8px",
822
928
  fontSize: 11,
823
- color: o.textMuted,
929
+ color: s.textMuted,
824
930
  cursor: "pointer",
825
931
  whiteSpace: "nowrap"
826
932
  },
827
- children: f
933
+ children: b
828
934
  },
829
- f
935
+ b
830
936
  )) })
831
937
  ]
832
938
  }
833
939
  ),
834
- /* @__PURE__ */ y(
940
+ /* @__PURE__ */ m(
835
941
  "form",
836
942
  {
837
- onSubmit: a,
943
+ onSubmit: c,
838
944
  style: {
839
945
  display: "flex",
840
946
  alignItems: "center",
841
947
  gap: 8,
842
948
  padding: "10px 12px",
843
- borderTop: `1px solid ${o.border}`,
844
- background: o.cardBg
949
+ borderTop: `1px solid ${s.border}`,
950
+ background: s.cardBg
845
951
  },
846
952
  children: [
847
- /* @__PURE__ */ n(
953
+ /* @__PURE__ */ r(
848
954
  "input",
849
955
  {
850
- value: v,
851
- onChange: (f) => _(f.target.value),
852
- placeholder: c,
956
+ value: T,
957
+ onChange: (b) => W(b.target.value),
958
+ placeholder: f,
853
959
  style: {
854
960
  flex: 1,
855
961
  padding: "7px 10px",
856
962
  borderRadius: 8,
857
- border: `1px solid ${o.border}`,
858
- background: o.inputBg,
859
- color: o.text,
963
+ border: `1px solid ${s.inputBorder}`,
964
+ background: s.inputBg,
965
+ color: s.inputText,
860
966
  fontSize: 13,
861
967
  outline: "none"
862
968
  }
863
969
  }
864
970
  ),
865
- /* @__PURE__ */ n(
971
+ /* @__PURE__ */ r(
866
972
  "button",
867
973
  {
868
974
  type: "submit",
869
- disabled: !v.trim() || S,
975
+ disabled: !T.trim() || S,
870
976
  style: {
871
977
  width: 32,
872
978
  height: 32,
873
979
  borderRadius: 8,
874
980
  border: "none",
875
- background: !v.trim() || S ? o.border : o.primary,
876
- color: o.primaryText,
877
- cursor: !v.trim() || S ? "not-allowed" : "pointer",
981
+ background: !T.trim() || S ? s.border : s.sendBtnBg,
982
+ color: s.sendBtnText,
983
+ cursor: !T.trim() || S ? "not-allowed" : "pointer",
878
984
  display: "flex",
879
985
  alignItems: "center",
880
986
  justifyContent: "center",
881
987
  flexShrink: 0,
882
- opacity: !v.trim() || S ? 0.5 : 1
988
+ opacity: !T.trim() || S ? 0.5 : 1
883
989
  },
884
- children: /* @__PURE__ */ n(je, {})
990
+ children: /* @__PURE__ */ r(Qe, {})
885
991
  }
886
992
  )
887
993
  ]
888
994
  }
889
995
  ),
890
- /* @__PURE__ */ n(q, { colors: o })
996
+ /* @__PURE__ */ r(Y, { colors: s })
891
997
  ]
892
998
  }
893
999
  );
894
1000
  }
895
- function Ae(e, t, r) {
1001
+ function Ne(e, t, n) {
896
1002
  return {
897
1003
  position: "fixed",
898
1004
  ...t === "bottom-left" ? { left: 20, bottom: 20 } : { right: 20, bottom: 20 },
899
- width: r,
900
- height: r,
1005
+ width: n,
1006
+ height: n,
901
1007
  borderRadius: "50%",
902
1008
  border: "none",
903
- background: e.primary,
904
- color: e.primaryText,
1009
+ background: e.launcherBg,
1010
+ color: e.launcherIcon,
905
1011
  cursor: "pointer",
906
1012
  display: "flex",
907
1013
  alignItems: "center",
@@ -911,84 +1017,84 @@ function Ae(e, t, r) {
911
1017
  transition: "transform 0.15s"
912
1018
  };
913
1019
  }
914
- function ze() {
915
- return /* @__PURE__ */ n("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ n("path", { d: "M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" }) });
1020
+ function qe() {
1021
+ return /* @__PURE__ */ r("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ r("path", { d: "M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" }) });
916
1022
  }
917
- function ne() {
918
- return /* @__PURE__ */ y("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
919
- /* @__PURE__ */ n("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
920
- /* @__PURE__ */ n("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
1023
+ function ce() {
1024
+ return /* @__PURE__ */ m("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
1025
+ /* @__PURE__ */ r("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
1026
+ /* @__PURE__ */ r("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
921
1027
  ] });
922
1028
  }
923
- function je() {
924
- return /* @__PURE__ */ y("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
925
- /* @__PURE__ */ n("line", { x1: "22", y1: "2", x2: "11", y2: "13" }),
926
- /* @__PURE__ */ n("polygon", { points: "22 2 15 22 11 13 2 9 22 2" })
1029
+ function Qe() {
1030
+ return /* @__PURE__ */ m("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
1031
+ /* @__PURE__ */ r("line", { x1: "22", y1: "2", x2: "11", y2: "13" }),
1032
+ /* @__PURE__ */ r("polygon", { points: "22 2 15 22 11 13 2 9 22 2" })
927
1033
  ] });
928
1034
  }
929
- function Oe({
1035
+ function Ve({
930
1036
  apiUrl: e,
931
1037
  clientId: t,
932
- getFirebaseIdToken: r,
933
- getToken: s,
1038
+ getFirebaseIdToken: n,
1039
+ getToken: o,
934
1040
  title: i = "KnowLayer Assistant",
935
- placeholder: c = "Ask a question…",
936
- welcomeMessage: g,
1041
+ placeholder: f = "Ask a question…",
1042
+ welcomeMessage: a,
937
1043
  signedInWelcomeMessage: k,
938
- theme: o = "light",
939
- height: l = "500px",
940
- className: m,
941
- suggestedQuestions: x,
942
- showScopeHint: w = !0,
943
- showCitations: p = !0,
944
- citationMinScore: C
1044
+ theme: s = "light",
1045
+ height: d = "500px",
1046
+ className: x,
1047
+ suggestedQuestions: g,
1048
+ showScopeHint: B = !0,
1049
+ showCitations: l = !0,
1050
+ citationMinScore: w
945
1051
  }) {
946
- const d = Q(o), { messages: b, isLoading: u, error: h, authMode: S, sendMessage: W } = Z({
1052
+ const u = G(s), { messages: y, isLoading: h, error: p, authMode: S, sendMessage: L } = ie({
947
1053
  apiUrl: e,
948
1054
  clientId: t,
949
- getFirebaseIdToken: r,
950
- getToken: s,
951
- welcomeMessage: g,
1055
+ getFirebaseIdToken: n,
1056
+ getToken: o,
1057
+ welcomeMessage: a,
952
1058
  signedInWelcomeMessage: k
953
- }), B = U({
1059
+ }), v = se({
954
1060
  apiUrl: e,
955
1061
  clientId: t,
956
- getFirebaseIdToken: r,
957
- getToken: s,
958
- suggestedQuestions: x
959
- }), [$, v] = L(""), _ = R(null);
960
- D(() => {
961
- var a;
962
- (a = _.current) == null || a.scrollIntoView({ behavior: "smooth" });
963
- }, [b, u]);
964
- const T = (a) => {
965
- a.preventDefault(), $.trim() && (W($), v(""));
1062
+ getFirebaseIdToken: n,
1063
+ getToken: o,
1064
+ suggestedQuestions: g
1065
+ }), [$, T] = C(""), W = R(null);
1066
+ F(() => {
1067
+ var c;
1068
+ (c = W.current) == null || c.scrollIntoView({ behavior: "smooth" });
1069
+ }, [y, h]);
1070
+ const I = (c) => {
1071
+ c.preventDefault(), $.trim() && (L($), T(""));
966
1072
  };
967
- return /* @__PURE__ */ y("div", { className: m, style: De(d, l), children: [
968
- /* @__PURE__ */ y("div", { style: Pe(d), children: [
969
- /* @__PURE__ */ n("span", { style: Fe(d) }),
970
- /* @__PURE__ */ n("span", { style: { fontWeight: 600, fontSize: 14, flex: 1 }, children: i }),
971
- w && /* @__PURE__ */ n("span", { style: { fontSize: 11, color: d.textMuted }, children: K(S) })
1073
+ return /* @__PURE__ */ m("div", { className: x, style: Xe(u, d), children: [
1074
+ /* @__PURE__ */ m("div", { style: Je(u), children: [
1075
+ /* @__PURE__ */ r("span", { style: Ye(u) }),
1076
+ /* @__PURE__ */ r("span", { style: { fontWeight: 600, fontSize: 14, flex: 1 }, children: i }),
1077
+ B && /* @__PURE__ */ r("span", { style: { fontSize: 11, color: u.headerText, opacity: 0.7 }, children: X(S) })
972
1078
  ] }),
973
- /* @__PURE__ */ y("div", { style: He(d), children: [
974
- b.map((a) => /* @__PURE__ */ y(
1079
+ /* @__PURE__ */ m("div", { style: Ge(u), children: [
1080
+ y.map((c) => /* @__PURE__ */ m(
975
1081
  "div",
976
1082
  {
977
1083
  style: {
978
1084
  display: "flex",
979
1085
  flexDirection: "column",
980
- alignItems: a.role === "user" ? "flex-end" : "flex-start",
1086
+ alignItems: c.role === "user" ? "flex-end" : "flex-start",
981
1087
  marginBottom: 12
982
1088
  },
983
1089
  children: [
984
- /* @__PURE__ */ n("div", { style: G(a.role, d), children: a.role === "assistant" ? te(a.content) : a.content }),
985
- p && a.role === "assistant" && a.sources && a.sources.length > 0 && /* @__PURE__ */ n("div", { style: { maxWidth: "80%" }, children: /* @__PURE__ */ n(N, { sources: a.sources, colors: d, minScore: C }) })
1090
+ /* @__PURE__ */ r("div", { style: oe(c.role, u), children: c.role === "assistant" ? ue(c.content) : c.content }),
1091
+ l && c.role === "assistant" && c.sources && c.sources.length > 0 && /* @__PURE__ */ r("div", { style: { maxWidth: "80%" }, children: /* @__PURE__ */ r(J, { sources: c.sources, colors: u, minScore: w }) })
986
1092
  ]
987
1093
  },
988
- a.id
1094
+ c.id
989
1095
  )),
990
- u && /* @__PURE__ */ n("div", { style: { marginBottom: 12 }, children: /* @__PURE__ */ n("div", { style: G("assistant", d), children: /* @__PURE__ */ n("span", { style: { opacity: 0.6 }, children: "Thinking…" }) }) }),
991
- h && /* @__PURE__ */ n(
1096
+ h && /* @__PURE__ */ r("div", { style: { marginBottom: 12 }, children: /* @__PURE__ */ r("div", { style: oe("assistant", u), children: /* @__PURE__ */ r("span", { style: { opacity: 0.6 }, children: "Thinking…" }) }) }),
1097
+ p && /* @__PURE__ */ r(
992
1098
  "div",
993
1099
  {
994
1100
  style: {
@@ -1000,50 +1106,50 @@ function Oe({
1000
1106
  fontSize: 13,
1001
1107
  marginBottom: 12
1002
1108
  },
1003
- children: h
1109
+ children: p
1004
1110
  }
1005
1111
  ),
1006
- /* @__PURE__ */ n("div", { ref: _ })
1112
+ /* @__PURE__ */ r("div", { ref: W })
1007
1113
  ] }),
1008
- B.length > 0 && b.length <= 1 && /* @__PURE__ */ y("div", { style: Qe(d), children: [
1009
- /* @__PURE__ */ n("span", { style: Xe(d), children: "Try asking" }),
1010
- /* @__PURE__ */ n("div", { style: { display: "flex", flexWrap: "wrap", gap: 6 }, children: B.map((a) => /* @__PURE__ */ n(
1114
+ v.length > 0 && y.length <= 1 && /* @__PURE__ */ m("div", { style: tt(u), children: [
1115
+ /* @__PURE__ */ r("span", { style: nt(u), children: "Try asking" }),
1116
+ /* @__PURE__ */ r("div", { style: { display: "flex", flexWrap: "wrap", gap: 6 }, children: v.map((c) => /* @__PURE__ */ r(
1011
1117
  "button",
1012
1118
  {
1013
1119
  type: "button",
1014
1120
  onClick: () => {
1015
- W(a);
1121
+ L(c);
1016
1122
  },
1017
- style: Ve(d),
1018
- children: a
1123
+ style: rt(u),
1124
+ children: c
1019
1125
  },
1020
- a
1126
+ c
1021
1127
  )) })
1022
1128
  ] }),
1023
- /* @__PURE__ */ y("form", { onSubmit: T, style: Ke(d), children: [
1024
- /* @__PURE__ */ n(
1129
+ /* @__PURE__ */ m("form", { onSubmit: I, style: Ue(u), children: [
1130
+ /* @__PURE__ */ r(
1025
1131
  "input",
1026
1132
  {
1027
1133
  value: $,
1028
- onChange: (a) => v(a.target.value),
1029
- placeholder: c,
1030
- style: Ne(d)
1134
+ onChange: (c) => T(c.target.value),
1135
+ placeholder: f,
1136
+ style: Ze(u)
1031
1137
  }
1032
1138
  ),
1033
- /* @__PURE__ */ n(
1139
+ /* @__PURE__ */ r(
1034
1140
  "button",
1035
1141
  {
1036
1142
  type: "submit",
1037
- disabled: !$.trim() || u,
1038
- style: qe(d, !$.trim() || u),
1039
- children: /* @__PURE__ */ n(Je, {})
1143
+ disabled: !$.trim() || h,
1144
+ style: et(u, !$.trim() || h),
1145
+ children: /* @__PURE__ */ r(ot, {})
1040
1146
  }
1041
1147
  )
1042
1148
  ] }),
1043
- /* @__PURE__ */ n(q, { colors: d })
1149
+ /* @__PURE__ */ r(Y, { colors: u })
1044
1150
  ] });
1045
1151
  }
1046
- function De(e, t) {
1152
+ function Xe(e, t) {
1047
1153
  return {
1048
1154
  fontFamily: "system-ui, -apple-system, sans-serif",
1049
1155
  display: "flex",
@@ -1056,7 +1162,7 @@ function De(e, t) {
1056
1162
  overflow: "hidden"
1057
1163
  };
1058
1164
  }
1059
- function Pe(e) {
1165
+ function Je(e) {
1060
1166
  return {
1061
1167
  display: "flex",
1062
1168
  alignItems: "center",
@@ -1067,7 +1173,7 @@ function Pe(e) {
1067
1173
  color: e.headerText
1068
1174
  };
1069
1175
  }
1070
- function Fe(e) {
1176
+ function Ye(e) {
1071
1177
  return {
1072
1178
  width: 8,
1073
1179
  height: 8,
@@ -1076,7 +1182,7 @@ function Fe(e) {
1076
1182
  flexShrink: 0
1077
1183
  };
1078
1184
  }
1079
- function He(e) {
1185
+ function Ge(e) {
1080
1186
  return {
1081
1187
  flex: 1,
1082
1188
  minHeight: 0,
@@ -1085,8 +1191,8 @@ function He(e) {
1085
1191
  background: e.bg
1086
1192
  };
1087
1193
  }
1088
- function G(e, t) {
1089
- const r = e === "user";
1194
+ function oe(e, t) {
1195
+ const n = e === "user";
1090
1196
  return {
1091
1197
  maxWidth: "80%",
1092
1198
  padding: "10px 14px",
@@ -1095,11 +1201,11 @@ function G(e, t) {
1095
1201
  lineHeight: 1.6,
1096
1202
  whiteSpace: "pre-wrap",
1097
1203
  wordBreak: "break-word",
1098
- background: r ? t.userBubbleBg : t.assistantBubbleBg,
1099
- color: r ? t.userBubbleText : t.text
1204
+ background: n ? t.userBubbleBg : t.assistantBubbleBg,
1205
+ color: n ? t.userBubbleText : t.assistantBubbleText
1100
1206
  };
1101
1207
  }
1102
- function Ke(e) {
1208
+ function Ue(e) {
1103
1209
  return {
1104
1210
  display: "flex",
1105
1211
  alignItems: "center",
@@ -1109,26 +1215,26 @@ function Ke(e) {
1109
1215
  background: e.cardBg
1110
1216
  };
1111
1217
  }
1112
- function Ne(e) {
1218
+ function Ze(e) {
1113
1219
  return {
1114
1220
  flex: 1,
1115
1221
  padding: "8px 12px",
1116
1222
  borderRadius: 8,
1117
- border: `1px solid ${e.border}`,
1223
+ border: `1px solid ${e.inputBorder}`,
1118
1224
  background: e.inputBg,
1119
- color: e.text,
1225
+ color: e.inputText,
1120
1226
  fontSize: 14,
1121
1227
  outline: "none"
1122
1228
  };
1123
1229
  }
1124
- function qe(e, t) {
1230
+ function et(e, t) {
1125
1231
  return {
1126
1232
  width: 36,
1127
1233
  height: 36,
1128
1234
  borderRadius: 8,
1129
1235
  border: "none",
1130
- background: t ? e.border : e.primary,
1131
- color: e.primaryText,
1236
+ background: t ? e.border : e.sendBtnBg,
1237
+ color: e.sendBtnText,
1132
1238
  cursor: t ? "not-allowed" : "pointer",
1133
1239
  display: "flex",
1134
1240
  alignItems: "center",
@@ -1138,14 +1244,14 @@ function qe(e, t) {
1138
1244
  transition: "opacity 0.15s"
1139
1245
  };
1140
1246
  }
1141
- function Qe(e) {
1247
+ function tt(e) {
1142
1248
  return {
1143
1249
  padding: "8px 14px",
1144
1250
  borderTop: `1px solid ${e.border}`,
1145
1251
  background: e.cardBg
1146
1252
  };
1147
1253
  }
1148
- function Xe(e) {
1254
+ function nt(e) {
1149
1255
  return {
1150
1256
  display: "block",
1151
1257
  fontSize: 11,
@@ -1156,7 +1262,7 @@ function Xe(e) {
1156
1262
  marginBottom: 6
1157
1263
  };
1158
1264
  }
1159
- function Ve(e) {
1265
+ function rt(e) {
1160
1266
  return {
1161
1267
  background: "none",
1162
1268
  border: `1px solid ${e.border}`,
@@ -1168,147 +1274,151 @@ function Ve(e) {
1168
1274
  whiteSpace: "nowrap"
1169
1275
  };
1170
1276
  }
1171
- function Je() {
1172
- return /* @__PURE__ */ y("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
1173
- /* @__PURE__ */ n("line", { x1: "22", y1: "2", x2: "11", y2: "13" }),
1174
- /* @__PURE__ */ n("polygon", { points: "22 2 15 22 11 13 2 9 22 2" })
1277
+ function ot() {
1278
+ return /* @__PURE__ */ m("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
1279
+ /* @__PURE__ */ r("line", { x1: "22", y1: "2", x2: "11", y2: "13" }),
1280
+ /* @__PURE__ */ r("polygon", { points: "22 2 15 22 11 13 2 9 22 2" })
1175
1281
  ] });
1176
1282
  }
1177
- function Ye({
1283
+ function it({
1178
1284
  apiUrl: e,
1179
1285
  clientId: t,
1180
- getFirebaseIdToken: r,
1181
- getToken: s,
1286
+ getFirebaseIdToken: n,
1287
+ getToken: o,
1182
1288
  welcomeMessage: i,
1183
- placeholder: c = "Ask a question…",
1184
- theme: g = "light",
1289
+ placeholder: f = "Ask a question…",
1290
+ theme: a = "light",
1185
1291
  showScopeHint: k = !0,
1186
- showCitations: o = !0,
1187
- citationMinScore: l
1292
+ showCitations: s = !0,
1293
+ citationMinScore: d
1188
1294
  }) {
1189
- const [m, x] = L(""), [w, p] = L(null), [C, d] = L([]), [b, u] = L(!1), h = Q(g), { getWidgetToken: S, invalidateWidgetToken: W, authMode: B } = H({
1295
+ const [x, g] = C(""), [B, l] = C(null), [w, u] = C([]), [y, h] = C(!1), p = G(a), { getWidgetToken: S, invalidateWidgetToken: L, authMode: v } = V({
1190
1296
  apiUrl: e,
1191
1297
  clientId: t,
1192
- getFirebaseIdToken: r,
1193
- getToken: s
1194
- }), $ = R(0), v = R(B);
1195
- D(() => {
1196
- v.current !== B && (v.current = B, $.current += 1, p(null), d([]), u(!1));
1197
- }, [B]);
1198
- const _ = async () => {
1199
- if (!m.trim()) return;
1200
- const T = ++$.current, a = () => T === $.current;
1201
- u(!0), p(null), d([]);
1298
+ getFirebaseIdToken: n,
1299
+ getToken: o
1300
+ }), $ = R(0), T = R(v);
1301
+ F(() => {
1302
+ T.current !== v && (T.current = v, $.current += 1, l(null), u([]), h(!1));
1303
+ }, [v]);
1304
+ const W = async () => {
1305
+ if (!x.trim()) return;
1306
+ const I = ++$.current, c = () => I === $.current;
1307
+ h(!0), l(null), u([]);
1202
1308
  try {
1203
- const I = await S(), M = (j) => fetch(`${e}/api/v1/teams/me/chat`, {
1309
+ const M = await S(), E = (D) => fetch(`${e}/api/v1/teams/me/chat`, {
1204
1310
  method: "POST",
1205
1311
  headers: {
1206
1312
  "Content-Type": "application/json",
1207
- Authorization: `Bearer ${j}`
1313
+ Authorization: `Bearer ${D}`
1208
1314
  },
1209
- body: JSON.stringify({ query: m })
1315
+ body: JSON.stringify({ query: x })
1210
1316
  });
1211
- let f = await M(I);
1212
- if (f.status === 401) {
1213
- W();
1214
- const j = await S();
1215
- f = await M(j);
1317
+ let b = await E(M);
1318
+ if (b.status === 401) {
1319
+ L();
1320
+ const D = await S();
1321
+ b = await E(D);
1216
1322
  }
1217
- if (!a()) return;
1218
- if (!f.ok) {
1219
- if (f.status === 402) {
1220
- p(F);
1323
+ if (!c()) return;
1324
+ if (!b.ok) {
1325
+ if (b.status === 402) {
1326
+ l(q);
1221
1327
  return;
1222
1328
  }
1223
- p("Something went wrong.");
1329
+ l("Something went wrong.");
1224
1330
  return;
1225
1331
  }
1226
- const E = await f.json();
1227
- if (!a()) return;
1228
- p(E.answer ?? "No response received."), Array.isArray(E.sources) && !E.llm_unavailable && d(E.sources);
1332
+ const _ = await b.json();
1333
+ if (!c()) return;
1334
+ l(_.answer ?? "No response received."), Array.isArray(_.sources) && !_.llm_unavailable && u(_.sources);
1229
1335
  } catch {
1230
- a() && p("Something went wrong.");
1336
+ c() && l("Something went wrong.");
1231
1337
  } finally {
1232
- a() && u(!1);
1338
+ c() && h(!1);
1233
1339
  }
1234
1340
  };
1235
- return /* @__PURE__ */ y("div", { style: { fontFamily: "system-ui, sans-serif" }, children: [
1236
- i && /* @__PURE__ */ n("p", { style: { marginTop: 0, marginBottom: 8, fontSize: 14, color: h.text }, children: i }),
1237
- /* @__PURE__ */ y("div", { style: { display: "flex", gap: 8 }, children: [
1238
- /* @__PURE__ */ n(
1341
+ return /* @__PURE__ */ m("div", { style: { fontFamily: "system-ui, sans-serif" }, children: [
1342
+ i && /* @__PURE__ */ r("p", { style: { marginTop: 0, marginBottom: 8, fontSize: 14, color: p.text }, children: i }),
1343
+ /* @__PURE__ */ m("div", { style: { display: "flex", gap: 8 }, children: [
1344
+ /* @__PURE__ */ r(
1239
1345
  "input",
1240
1346
  {
1241
1347
  type: "text",
1242
- value: m,
1243
- onChange: (T) => x(T.target.value),
1244
- onKeyDown: (T) => T.key === "Enter" && _(),
1245
- placeholder: c,
1348
+ value: x,
1349
+ onChange: (I) => g(I.target.value),
1350
+ onKeyDown: (I) => I.key === "Enter" && W(),
1351
+ placeholder: f,
1246
1352
  style: {
1247
1353
  flex: 1,
1248
1354
  padding: "8px 12px",
1249
1355
  borderRadius: 6,
1250
- border: "1px solid #ccc",
1356
+ border: `1px solid ${p.inputBorder}`,
1357
+ background: p.inputBg,
1358
+ color: p.inputText,
1251
1359
  fontSize: 14
1252
1360
  }
1253
1361
  }
1254
1362
  ),
1255
- /* @__PURE__ */ n(
1363
+ /* @__PURE__ */ r(
1256
1364
  "button",
1257
1365
  {
1258
- onClick: _,
1259
- disabled: b,
1366
+ onClick: W,
1367
+ disabled: y,
1260
1368
  style: {
1261
1369
  padding: "8px 16px",
1262
1370
  borderRadius: 6,
1263
1371
  border: "none",
1264
- background: "#2563eb",
1265
- color: "#fff",
1372
+ background: p.sendBtnBg,
1373
+ color: p.sendBtnText,
1266
1374
  cursor: "pointer",
1267
1375
  fontSize: 14
1268
1376
  },
1269
- children: b ? "…" : "Ask"
1377
+ children: y ? "…" : "Ask"
1270
1378
  }
1271
1379
  )
1272
1380
  ] }),
1273
- k && /* @__PURE__ */ n("div", { style: { marginTop: 4, fontSize: 11, color: h.textMuted }, children: K(B) }),
1274
- w && /* @__PURE__ */ n(
1381
+ k && /* @__PURE__ */ r("div", { style: { marginTop: 4, fontSize: 11, color: p.textMuted }, children: X(v) }),
1382
+ B && /* @__PURE__ */ r(
1275
1383
  "div",
1276
1384
  {
1277
1385
  style: {
1278
1386
  marginTop: 12,
1279
1387
  padding: 12,
1280
1388
  borderRadius: 6,
1281
- background: "#f8fafc",
1282
- border: "1px solid #e2e8f0",
1389
+ background: p.cardBg,
1390
+ border: `1px solid ${p.border}`,
1391
+ color: p.text,
1283
1392
  whiteSpace: "pre-wrap",
1284
1393
  fontSize: 14
1285
1394
  },
1286
- children: w
1395
+ children: B
1287
1396
  }
1288
1397
  ),
1289
- o && C.length > 0 && /* @__PURE__ */ n(N, { sources: C, colors: h, minScore: l }),
1290
- /* @__PURE__ */ n(q, { colors: h })
1398
+ s && w.length > 0 && /* @__PURE__ */ r(J, { sources: w, colors: p, minScore: d }),
1399
+ /* @__PURE__ */ r(Y, { colors: p })
1291
1400
  ] });
1292
1401
  }
1293
- function et({
1402
+ function lt({
1294
1403
  chatType: e,
1295
- apiUrl: t = pe,
1296
- ...r
1404
+ apiUrl: t = we,
1405
+ ...n
1297
1406
  }) {
1298
1407
  switch (e) {
1299
1408
  case "floating":
1300
- return /* @__PURE__ */ n(Ee, { apiUrl: t, ...r });
1409
+ return /* @__PURE__ */ r(He, { apiUrl: t, ...n });
1301
1410
  case "embedded":
1302
- return /* @__PURE__ */ n(Oe, { apiUrl: t, ...r });
1411
+ return /* @__PURE__ */ r(Ve, { apiUrl: t, ...n });
1303
1412
  case "search":
1304
- return /* @__PURE__ */ n(Ye, { apiUrl: t, ...r });
1413
+ return /* @__PURE__ */ r(it, { apiUrl: t, ...n });
1305
1414
  }
1306
1415
  }
1307
1416
  export {
1308
- ee as CITATION_SCORE_THRESHOLD,
1309
- Oe as EmbeddedChat,
1310
- Ee as FloatingChat,
1311
- et as KnowLayerWidget,
1312
- Ye as SearchWidget,
1313
- xe as uniqueCitations
1417
+ ae as CITATION_SCORE_THRESHOLD,
1418
+ Ve as EmbeddedChat,
1419
+ He as FloatingChat,
1420
+ lt as KnowLayerWidget,
1421
+ it as SearchWidget,
1422
+ G as resolveTheme,
1423
+ Ie as uniqueCitations
1314
1424
  };