@scrimpify-software/rag-widgets 0.0.0-stage → 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.
- package/README.md +306 -3
- package/dist/index.cjs +2 -0
- package/dist/index.d.ts +125 -0
- package/dist/index.js +1314 -0
- package/package.json +50 -6
package/dist/index.js
ADDED
|
@@ -0,0 +1,1314 @@
|
|
|
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) {
|
|
6
|
+
return e ? "getToken" : t ? "firebase" : "public";
|
|
7
|
+
}
|
|
8
|
+
function ue(e, t) {
|
|
9
|
+
if (e && typeof e == "object" && "detail" in e) {
|
|
10
|
+
const r = e.detail;
|
|
11
|
+
if (typeof r == "string" && r.trim()) return r;
|
|
12
|
+
}
|
|
13
|
+
return t;
|
|
14
|
+
}
|
|
15
|
+
function ce(e) {
|
|
16
|
+
return e.includes("eyJ") || e.length > 300 ? "Couldn't start the assistant. Please try again." : e;
|
|
17
|
+
}
|
|
18
|
+
function fe(e) {
|
|
19
|
+
if (typeof e == "string") {
|
|
20
|
+
if (!e)
|
|
21
|
+
throw new Error("getToken returned an empty token.");
|
|
22
|
+
return { token: e, expiresIn: P };
|
|
23
|
+
}
|
|
24
|
+
const t = e && typeof e.token == "string" && e.token ? e.token : e && typeof e.access_token == "string" ? e.access_token : "";
|
|
25
|
+
if (!t)
|
|
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 };
|
|
29
|
+
}
|
|
30
|
+
async function J(e, t) {
|
|
31
|
+
if (!e.ok) {
|
|
32
|
+
const i = await e.json().catch(() => ({}));
|
|
33
|
+
throw new Error(
|
|
34
|
+
ue(i, `Widget token request failed (${e.status})`)
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
const r = await e.json();
|
|
38
|
+
if (!r || typeof r.token != "string" || !r.token)
|
|
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 };
|
|
42
|
+
}
|
|
43
|
+
function H({
|
|
44
|
+
apiUrl: e,
|
|
45
|
+
clientId: t,
|
|
46
|
+
getFirebaseIdToken: r,
|
|
47
|
+
getToken: s
|
|
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);
|
|
59
|
+
try {
|
|
60
|
+
let u;
|
|
61
|
+
if (i === "getToken" && g.current)
|
|
62
|
+
u = fe(await g.current());
|
|
63
|
+
else if (i === "firebase" && k.current) {
|
|
64
|
+
const h = await k.current(), S = await fetch(`${e}/api/v1/teams/widget-token`, {
|
|
65
|
+
method: "POST",
|
|
66
|
+
headers: {
|
|
67
|
+
"X-KL-Client-Id": t,
|
|
68
|
+
"X-Firebase-Id-Token": h
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
u = await J(S, se);
|
|
72
|
+
} else {
|
|
73
|
+
const h = await fetch(`${e}/api/v1/teams/public-widget-session`, {
|
|
74
|
+
method: "POST",
|
|
75
|
+
headers: { "X-KL-Client-Id": t }
|
|
76
|
+
});
|
|
77
|
+
u = await J(h, P);
|
|
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."
|
|
87
|
+
);
|
|
88
|
+
throw d === x.current && (m.current = { key: c, at: Date.now(), message: h }), new Error(h);
|
|
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);
|
|
101
|
+
});
|
|
102
|
+
return l.current = { key: c, promise: u }, u;
|
|
103
|
+
}, [c, p]), invalidateWidgetToken: w, authMode: i };
|
|
104
|
+
}
|
|
105
|
+
const pe = "http://localhost:8000", F = "Chat quota is exhausted. Please contact your organization admin.";
|
|
106
|
+
function K(e) {
|
|
107
|
+
return e === "public" ? "Public documents" : "Signed in · includes your teams";
|
|
108
|
+
}
|
|
109
|
+
const ge = "Hello! Ask me anything about your documentation.";
|
|
110
|
+
let he = 0;
|
|
111
|
+
function A() {
|
|
112
|
+
return `msg_${Date.now()}_${++he}`;
|
|
113
|
+
}
|
|
114
|
+
async function Y(e, t, r) {
|
|
115
|
+
return fetch(`${e}/api/v1/teams/me/chat`, {
|
|
116
|
+
method: "POST",
|
|
117
|
+
headers: {
|
|
118
|
+
"Content-Type": "application/json",
|
|
119
|
+
Authorization: `Bearer ${t}`
|
|
120
|
+
},
|
|
121
|
+
body: JSON.stringify({ query: r })
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
function Z({
|
|
125
|
+
apiUrl: e,
|
|
126
|
+
clientId: t,
|
|
127
|
+
getFirebaseIdToken: r,
|
|
128
|
+
getToken: s,
|
|
129
|
+
welcomeMessage: i = ge,
|
|
130
|
+
signedInWelcomeMessage: c
|
|
131
|
+
}) {
|
|
132
|
+
const { getWidgetToken: g, invalidateWidgetToken: k, authMode: o } = H({
|
|
133
|
+
apiUrl: e,
|
|
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);
|
|
151
|
+
try {
|
|
152
|
+
const T = await g();
|
|
153
|
+
let a = await Y(e, T, B);
|
|
154
|
+
if (a.status === 401) {
|
|
155
|
+
k();
|
|
156
|
+
const E = await g();
|
|
157
|
+
a = await Y(e, E, B);
|
|
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 }
|
|
165
|
+
]);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
const E = await a.json().catch(() => ({}));
|
|
169
|
+
throw new Error(E.detail || `Request failed (${a.status})`);
|
|
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(),
|
|
175
|
+
role: "assistant",
|
|
176
|
+
content: I.answer ?? "No response received.",
|
|
177
|
+
sources: M ? I.sources : void 0
|
|
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." }
|
|
186
|
+
]);
|
|
187
|
+
} finally {
|
|
188
|
+
v() && p(!1);
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
[e, g, k, w]
|
|
192
|
+
);
|
|
193
|
+
return { messages: m, isLoading: w, error: C, authMode: o, sendMessage: S, reset: u };
|
|
194
|
+
}
|
|
195
|
+
function U({
|
|
196
|
+
apiUrl: e,
|
|
197
|
+
clientId: t,
|
|
198
|
+
getFirebaseIdToken: r,
|
|
199
|
+
getToken: s,
|
|
200
|
+
suggestedQuestions: i
|
|
201
|
+
}) {
|
|
202
|
+
const [c, g] = L([]), { getWidgetToken: k, invalidateWidgetToken: o, authMode: l } = H({
|
|
203
|
+
apiUrl: e,
|
|
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}` }
|
|
214
|
+
});
|
|
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
|
|
222
|
+
) : [];
|
|
223
|
+
g(d);
|
|
224
|
+
} catch {
|
|
225
|
+
}
|
|
226
|
+
})(), () => {
|
|
227
|
+
x = !0;
|
|
228
|
+
};
|
|
229
|
+
}, [e, l, k, o, m]), m ? i : c;
|
|
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}`;
|
|
235
|
+
const i = (e.document_id ?? "").toString().trim().toLowerCase();
|
|
236
|
+
return i ? `${r}id:${i}` : `${r}text:${(e.text ?? "").slice(0, 60)}`;
|
|
237
|
+
}
|
|
238
|
+
function xe(e, { minScore: t = ee } = {}) {
|
|
239
|
+
const r = /* @__PURE__ */ new Map(), s = [];
|
|
240
|
+
for (const i of e) {
|
|
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);
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
(i.score ?? 0) > (g.score ?? 0) && r.set(c, i);
|
|
248
|
+
}
|
|
249
|
+
return s.map((i) => r.get(i));
|
|
250
|
+
}
|
|
251
|
+
function be(e) {
|
|
252
|
+
return new Set(
|
|
253
|
+
e.map((r) => (r.team_id ?? "").toString()).filter((r) => r.length > 0)
|
|
254
|
+
).size > 1;
|
|
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;
|
|
259
|
+
}
|
|
260
|
+
function N({
|
|
261
|
+
sources: e,
|
|
262
|
+
colors: t,
|
|
263
|
+
compact: r = !1,
|
|
264
|
+
minScore: s = ee
|
|
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(
|
|
274
|
+
"button",
|
|
275
|
+
{
|
|
276
|
+
onClick: () => c((l) => !l),
|
|
277
|
+
style: we(t, o),
|
|
278
|
+
children: [
|
|
279
|
+
/* @__PURE__ */ n($e, { size: r ? 12 : 14, color: t.textMuted }),
|
|
280
|
+
/* @__PURE__ */ y("span", { children: [
|
|
281
|
+
g.length,
|
|
282
|
+
" source",
|
|
283
|
+
g.length > 1 ? "s" : "",
|
|
284
|
+
" cited"
|
|
285
|
+
] }),
|
|
286
|
+
/* @__PURE__ */ n(
|
|
287
|
+
Re,
|
|
288
|
+
{
|
|
289
|
+
direction: i ? "up" : "down",
|
|
290
|
+
size: r ? 12 : 14,
|
|
291
|
+
color: t.textMuted
|
|
292
|
+
}
|
|
293
|
+
)
|
|
294
|
+
]
|
|
295
|
+
}
|
|
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(
|
|
303
|
+
"span",
|
|
304
|
+
{
|
|
305
|
+
title: w,
|
|
306
|
+
style: {
|
|
307
|
+
fontWeight: 600,
|
|
308
|
+
fontSize: o,
|
|
309
|
+
overflow: "hidden",
|
|
310
|
+
textOverflow: "ellipsis",
|
|
311
|
+
whiteSpace: "nowrap",
|
|
312
|
+
flex: 1,
|
|
313
|
+
minWidth: 0
|
|
314
|
+
},
|
|
315
|
+
children: w
|
|
316
|
+
}
|
|
317
|
+
),
|
|
318
|
+
l.score != null && /* @__PURE__ */ y("span", { style: Be(), children: [
|
|
319
|
+
(l.score * 100).toFixed(0),
|
|
320
|
+
"%"
|
|
321
|
+
] })
|
|
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}`);
|
|
326
|
+
}) })
|
|
327
|
+
] });
|
|
328
|
+
}
|
|
329
|
+
function ke(e) {
|
|
330
|
+
return {
|
|
331
|
+
marginTop: 6,
|
|
332
|
+
borderRadius: 8,
|
|
333
|
+
border: `1px solid ${e.border}`,
|
|
334
|
+
background: e.cardBg,
|
|
335
|
+
padding: "6px 10px"
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
function we(e, t) {
|
|
339
|
+
return {
|
|
340
|
+
display: "flex",
|
|
341
|
+
alignItems: "center",
|
|
342
|
+
gap: 5,
|
|
343
|
+
width: "100%",
|
|
344
|
+
background: "none",
|
|
345
|
+
border: "none",
|
|
346
|
+
padding: 0,
|
|
347
|
+
cursor: "pointer",
|
|
348
|
+
fontSize: t,
|
|
349
|
+
fontWeight: 500,
|
|
350
|
+
color: e.textMuted
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
function Se(e, t) {
|
|
354
|
+
return {
|
|
355
|
+
padding: "6px 0",
|
|
356
|
+
borderTop: t ? `1px solid ${e.border}` : "none"
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
function ve(e) {
|
|
360
|
+
return {
|
|
361
|
+
width: 18,
|
|
362
|
+
height: 18,
|
|
363
|
+
borderRadius: 4,
|
|
364
|
+
background: e.primary + "1a",
|
|
365
|
+
color: e.primary,
|
|
366
|
+
display: "inline-flex",
|
|
367
|
+
alignItems: "center",
|
|
368
|
+
justifyContent: "center",
|
|
369
|
+
fontSize: 10,
|
|
370
|
+
fontWeight: 700,
|
|
371
|
+
flexShrink: 0
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
function Be() {
|
|
375
|
+
return {
|
|
376
|
+
fontSize: 10,
|
|
377
|
+
fontWeight: 600,
|
|
378
|
+
color: "#22c55e",
|
|
379
|
+
background: "rgba(34,197,94,0.12)",
|
|
380
|
+
borderRadius: 999,
|
|
381
|
+
padding: "1px 6px",
|
|
382
|
+
flexShrink: 0
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
function Te(e, t) {
|
|
386
|
+
return {
|
|
387
|
+
margin: "2px 0 0 24px",
|
|
388
|
+
fontSize: t - 1,
|
|
389
|
+
fontWeight: 500,
|
|
390
|
+
color: e.textMuted,
|
|
391
|
+
overflow: "hidden",
|
|
392
|
+
textOverflow: "ellipsis",
|
|
393
|
+
whiteSpace: "nowrap"
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
function Ce(e, t) {
|
|
397
|
+
return {
|
|
398
|
+
margin: "4px 0 0 24px",
|
|
399
|
+
fontSize: t - 1,
|
|
400
|
+
lineHeight: 1.45,
|
|
401
|
+
color: e.textMuted,
|
|
402
|
+
display: "-webkit-box",
|
|
403
|
+
WebkitLineClamp: 2,
|
|
404
|
+
WebkitBoxOrient: "vertical",
|
|
405
|
+
overflow: "hidden"
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
function $e({ size: e, color: t }) {
|
|
409
|
+
return /* @__PURE__ */ y(
|
|
410
|
+
"svg",
|
|
411
|
+
{
|
|
412
|
+
width: e,
|
|
413
|
+
height: e,
|
|
414
|
+
viewBox: "0 0 24 24",
|
|
415
|
+
fill: "none",
|
|
416
|
+
stroke: t,
|
|
417
|
+
strokeWidth: "2",
|
|
418
|
+
strokeLinecap: "round",
|
|
419
|
+
strokeLinejoin: "round",
|
|
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" })
|
|
425
|
+
]
|
|
426
|
+
}
|
|
427
|
+
);
|
|
428
|
+
}
|
|
429
|
+
function Re({
|
|
430
|
+
direction: e,
|
|
431
|
+
size: t,
|
|
432
|
+
color: r
|
|
433
|
+
}) {
|
|
434
|
+
return /* @__PURE__ */ n(
|
|
435
|
+
"svg",
|
|
436
|
+
{
|
|
437
|
+
width: t,
|
|
438
|
+
height: t,
|
|
439
|
+
viewBox: "0 0 24 24",
|
|
440
|
+
fill: "none",
|
|
441
|
+
stroke: r,
|
|
442
|
+
strokeWidth: "2",
|
|
443
|
+
strokeLinecap: "round",
|
|
444
|
+
strokeLinejoin: "round",
|
|
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" })
|
|
447
|
+
}
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
function q({ colors: e }) {
|
|
451
|
+
return /* @__PURE__ */ y(
|
|
452
|
+
"div",
|
|
453
|
+
{
|
|
454
|
+
style: {
|
|
455
|
+
display: "flex",
|
|
456
|
+
alignItems: "center",
|
|
457
|
+
justifyContent: "center",
|
|
458
|
+
gap: 4,
|
|
459
|
+
padding: "6px 12px",
|
|
460
|
+
fontSize: 11,
|
|
461
|
+
color: e.textMuted
|
|
462
|
+
},
|
|
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" })
|
|
467
|
+
]
|
|
468
|
+
}
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
function Le({ color: e }) {
|
|
472
|
+
return /* @__PURE__ */ y(
|
|
473
|
+
"svg",
|
|
474
|
+
{
|
|
475
|
+
width: "14",
|
|
476
|
+
height: "14",
|
|
477
|
+
viewBox: "0 0 24 24",
|
|
478
|
+
fill: "none",
|
|
479
|
+
stroke: e,
|
|
480
|
+
strokeWidth: "2",
|
|
481
|
+
strokeLinecap: "round",
|
|
482
|
+
strokeLinejoin: "round",
|
|
483
|
+
"aria-hidden": "true",
|
|
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" })
|
|
488
|
+
]
|
|
489
|
+
}
|
|
490
|
+
);
|
|
491
|
+
}
|
|
492
|
+
const We = {
|
|
493
|
+
bg: "#ffffff",
|
|
494
|
+
cardBg: "#f8fafc",
|
|
495
|
+
border: "#e2e8f0",
|
|
496
|
+
text: "#1e293b",
|
|
497
|
+
textMuted: "#64748b",
|
|
498
|
+
primary: "#2563eb",
|
|
499
|
+
primaryText: "#ffffff",
|
|
500
|
+
inputBg: "#ffffff",
|
|
501
|
+
userBubbleBg: "#2563eb",
|
|
502
|
+
userBubbleText: "#ffffff",
|
|
503
|
+
assistantBubbleBg: "#f1f5f9",
|
|
504
|
+
headerBg: "#ffffff",
|
|
505
|
+
headerText: "#1e293b",
|
|
506
|
+
dot: "#22c55e"
|
|
507
|
+
}, Ie = {
|
|
508
|
+
bg: "#0f172a",
|
|
509
|
+
cardBg: "#1e293b",
|
|
510
|
+
border: "#334155",
|
|
511
|
+
text: "#f1f5f9",
|
|
512
|
+
textMuted: "#94a3b8",
|
|
513
|
+
primary: "#3b82f6",
|
|
514
|
+
primaryText: "#ffffff",
|
|
515
|
+
inputBg: "#1e293b",
|
|
516
|
+
userBubbleBg: "#3b82f6",
|
|
517
|
+
userBubbleText: "#ffffff",
|
|
518
|
+
assistantBubbleBg: "#334155",
|
|
519
|
+
headerBg: "#1e293b",
|
|
520
|
+
headerText: "#f1f5f9",
|
|
521
|
+
dot: "#22c55e"
|
|
522
|
+
};
|
|
523
|
+
function Q(e) {
|
|
524
|
+
return e === "dark" ? Ie : We;
|
|
525
|
+
}
|
|
526
|
+
function te(e) {
|
|
527
|
+
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]))
|
|
532
|
+
);
|
|
533
|
+
return z(V, null, ...r);
|
|
534
|
+
}
|
|
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(
|
|
541
|
+
"code",
|
|
542
|
+
{
|
|
543
|
+
key: `c_${c++}`,
|
|
544
|
+
style: {
|
|
545
|
+
background: "rgba(0,0,0,0.08)",
|
|
546
|
+
padding: "1px 4px",
|
|
547
|
+
borderRadius: 3,
|
|
548
|
+
fontSize: "0.9em"
|
|
549
|
+
}
|
|
550
|
+
},
|
|
551
|
+
i[4]
|
|
552
|
+
)
|
|
553
|
+
), s = i.index + i[0].length;
|
|
554
|
+
return s < e.length && t.push(e.slice(s)), t.length === 0 && t.push(""), t;
|
|
555
|
+
}
|
|
556
|
+
function Ee({
|
|
557
|
+
apiUrl: e,
|
|
558
|
+
clientId: t,
|
|
559
|
+
getFirebaseIdToken: r,
|
|
560
|
+
getToken: s,
|
|
561
|
+
title: i = "KnowLayer Assistant",
|
|
562
|
+
placeholder: c = "Ask a question…",
|
|
563
|
+
welcomeMessage: g,
|
|
564
|
+
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
|
|
574
|
+
}) {
|
|
575
|
+
const [u, h] = L(!1), S = Q(o), W = U({
|
|
576
|
+
apiUrl: e,
|
|
577
|
+
clientId: t,
|
|
578
|
+
getFirebaseIdToken: r,
|
|
579
|
+
getToken: s,
|
|
580
|
+
suggestedQuestions: p
|
|
581
|
+
});
|
|
582
|
+
return oe(
|
|
583
|
+
/* @__PURE__ */ y(re, { children: [
|
|
584
|
+
u && /* @__PURE__ */ n(
|
|
585
|
+
Me,
|
|
586
|
+
{
|
|
587
|
+
apiUrl: e,
|
|
588
|
+
clientId: t,
|
|
589
|
+
getFirebaseIdToken: r,
|
|
590
|
+
getToken: s,
|
|
591
|
+
title: i,
|
|
592
|
+
placeholder: c,
|
|
593
|
+
welcomeMessage: g,
|
|
594
|
+
signedInWelcomeMessage: k,
|
|
595
|
+
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
|
|
605
|
+
}
|
|
606
|
+
),
|
|
607
|
+
/* @__PURE__ */ n(
|
|
608
|
+
"button",
|
|
609
|
+
{
|
|
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, {})
|
|
614
|
+
}
|
|
615
|
+
)
|
|
616
|
+
] }),
|
|
617
|
+
document.body
|
|
618
|
+
);
|
|
619
|
+
}
|
|
620
|
+
function Me({
|
|
621
|
+
apiUrl: e,
|
|
622
|
+
clientId: t,
|
|
623
|
+
getFirebaseIdToken: r,
|
|
624
|
+
getToken: s,
|
|
625
|
+
title: i,
|
|
626
|
+
placeholder: c,
|
|
627
|
+
welcomeMessage: g,
|
|
628
|
+
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
|
|
639
|
+
}) {
|
|
640
|
+
const { messages: h, isLoading: S, error: W, authMode: B, sendMessage: $ } = Z({
|
|
641
|
+
apiUrl: e,
|
|
642
|
+
clientId: t,
|
|
643
|
+
getFirebaseIdToken: r,
|
|
644
|
+
getToken: s,
|
|
645
|
+
welcomeMessage: g,
|
|
646
|
+
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(
|
|
656
|
+
"div",
|
|
657
|
+
{
|
|
658
|
+
style: {
|
|
659
|
+
position: "fixed",
|
|
660
|
+
...l === "bottom-left" ? { left: 20, bottom: I } : { right: 20, bottom: I },
|
|
661
|
+
width: x,
|
|
662
|
+
height: w,
|
|
663
|
+
zIndex: 2147483645,
|
|
664
|
+
fontFamily: "system-ui, -apple-system, sans-serif",
|
|
665
|
+
display: "flex",
|
|
666
|
+
flexDirection: "column",
|
|
667
|
+
borderRadius: 16,
|
|
668
|
+
border: `1px solid ${o.border}`,
|
|
669
|
+
background: o.bg,
|
|
670
|
+
color: o.text,
|
|
671
|
+
boxShadow: "0 8px 32px rgba(0,0,0,0.18)",
|
|
672
|
+
overflow: "hidden",
|
|
673
|
+
animation: "knowlayer-fadein 0.2s ease-out"
|
|
674
|
+
},
|
|
675
|
+
children: [
|
|
676
|
+
/* @__PURE__ */ n("style", { children: "@keyframes knowlayer-fadein { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }" }),
|
|
677
|
+
/* @__PURE__ */ y(
|
|
678
|
+
"div",
|
|
679
|
+
{
|
|
680
|
+
style: {
|
|
681
|
+
display: "flex",
|
|
682
|
+
alignItems: "center",
|
|
683
|
+
gap: 8,
|
|
684
|
+
padding: "12px 16px",
|
|
685
|
+
borderBottom: `1px solid ${o.border}`,
|
|
686
|
+
background: o.headerBg
|
|
687
|
+
},
|
|
688
|
+
children: [
|
|
689
|
+
/* @__PURE__ */ n(
|
|
690
|
+
"span",
|
|
691
|
+
{
|
|
692
|
+
style: {
|
|
693
|
+
width: 8,
|
|
694
|
+
height: 8,
|
|
695
|
+
borderRadius: "50%",
|
|
696
|
+
background: o.dot,
|
|
697
|
+
flexShrink: 0
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
),
|
|
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(
|
|
704
|
+
"button",
|
|
705
|
+
{
|
|
706
|
+
onClick: p,
|
|
707
|
+
style: {
|
|
708
|
+
background: "none",
|
|
709
|
+
border: "none",
|
|
710
|
+
cursor: "pointer",
|
|
711
|
+
color: o.textMuted,
|
|
712
|
+
padding: 4,
|
|
713
|
+
display: "flex"
|
|
714
|
+
},
|
|
715
|
+
"aria-label": "Close",
|
|
716
|
+
children: /* @__PURE__ */ n(ne, {})
|
|
717
|
+
}
|
|
718
|
+
)
|
|
719
|
+
]
|
|
720
|
+
}
|
|
721
|
+
),
|
|
722
|
+
/* @__PURE__ */ y("div", { style: { flex: 1, minHeight: 0, overflowY: "auto", padding: 14 }, children: [
|
|
723
|
+
h.map((f) => /* @__PURE__ */ y(
|
|
724
|
+
"div",
|
|
725
|
+
{
|
|
726
|
+
style: {
|
|
727
|
+
display: "flex",
|
|
728
|
+
flexDirection: "column",
|
|
729
|
+
alignItems: f.role === "user" ? "flex-end" : "flex-start",
|
|
730
|
+
marginBottom: 10
|
|
731
|
+
},
|
|
732
|
+
children: [
|
|
733
|
+
/* @__PURE__ */ n(
|
|
734
|
+
"div",
|
|
735
|
+
{
|
|
736
|
+
style: {
|
|
737
|
+
maxWidth: "82%",
|
|
738
|
+
padding: "8px 12px",
|
|
739
|
+
borderRadius: 12,
|
|
740
|
+
fontSize: 13,
|
|
741
|
+
lineHeight: 1.55,
|
|
742
|
+
whiteSpace: "pre-wrap",
|
|
743
|
+
wordBreak: "break-word",
|
|
744
|
+
background: f.role === "user" ? o.userBubbleBg : o.assistantBubbleBg,
|
|
745
|
+
color: f.role === "user" ? o.userBubbleText : o.text
|
|
746
|
+
},
|
|
747
|
+
children: f.role === "assistant" ? te(f.content) : f.content
|
|
748
|
+
}
|
|
749
|
+
),
|
|
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 }) })
|
|
751
|
+
]
|
|
752
|
+
},
|
|
753
|
+
f.id
|
|
754
|
+
)),
|
|
755
|
+
S && /* @__PURE__ */ n("div", { style: { marginBottom: 10 }, children: /* @__PURE__ */ n(
|
|
756
|
+
"div",
|
|
757
|
+
{
|
|
758
|
+
style: {
|
|
759
|
+
maxWidth: "82%",
|
|
760
|
+
padding: "8px 12px",
|
|
761
|
+
borderRadius: 12,
|
|
762
|
+
fontSize: 13,
|
|
763
|
+
background: o.assistantBubbleBg,
|
|
764
|
+
color: o.textMuted
|
|
765
|
+
},
|
|
766
|
+
children: "Thinking…"
|
|
767
|
+
}
|
|
768
|
+
) }),
|
|
769
|
+
W && /* @__PURE__ */ n(
|
|
770
|
+
"div",
|
|
771
|
+
{
|
|
772
|
+
style: {
|
|
773
|
+
padding: "6px 10px",
|
|
774
|
+
borderRadius: 8,
|
|
775
|
+
background: "#fef2f2",
|
|
776
|
+
border: "1px solid #fecaca",
|
|
777
|
+
color: "#dc2626",
|
|
778
|
+
fontSize: 12,
|
|
779
|
+
marginBottom: 10
|
|
780
|
+
},
|
|
781
|
+
children: W
|
|
782
|
+
}
|
|
783
|
+
),
|
|
784
|
+
/* @__PURE__ */ n("div", { ref: T })
|
|
785
|
+
] }),
|
|
786
|
+
C.length > 0 && h.length <= 1 && /* @__PURE__ */ y(
|
|
787
|
+
"div",
|
|
788
|
+
{
|
|
789
|
+
style: {
|
|
790
|
+
padding: "8px 12px",
|
|
791
|
+
borderTop: `1px solid ${o.border}`,
|
|
792
|
+
background: o.cardBg
|
|
793
|
+
},
|
|
794
|
+
children: [
|
|
795
|
+
/* @__PURE__ */ n(
|
|
796
|
+
"span",
|
|
797
|
+
{
|
|
798
|
+
style: {
|
|
799
|
+
display: "block",
|
|
800
|
+
fontSize: 10,
|
|
801
|
+
fontWeight: 600,
|
|
802
|
+
textTransform: "uppercase",
|
|
803
|
+
letterSpacing: "0.05em",
|
|
804
|
+
color: o.textMuted,
|
|
805
|
+
marginBottom: 5
|
|
806
|
+
},
|
|
807
|
+
children: "Try asking"
|
|
808
|
+
}
|
|
809
|
+
),
|
|
810
|
+
/* @__PURE__ */ n("div", { style: { display: "flex", flexWrap: "wrap", gap: 5 }, children: C.map((f) => /* @__PURE__ */ n(
|
|
811
|
+
"button",
|
|
812
|
+
{
|
|
813
|
+
type: "button",
|
|
814
|
+
onClick: () => {
|
|
815
|
+
$(f);
|
|
816
|
+
},
|
|
817
|
+
style: {
|
|
818
|
+
background: "none",
|
|
819
|
+
border: `1px solid ${o.border}`,
|
|
820
|
+
borderRadius: 999,
|
|
821
|
+
padding: "3px 8px",
|
|
822
|
+
fontSize: 11,
|
|
823
|
+
color: o.textMuted,
|
|
824
|
+
cursor: "pointer",
|
|
825
|
+
whiteSpace: "nowrap"
|
|
826
|
+
},
|
|
827
|
+
children: f
|
|
828
|
+
},
|
|
829
|
+
f
|
|
830
|
+
)) })
|
|
831
|
+
]
|
|
832
|
+
}
|
|
833
|
+
),
|
|
834
|
+
/* @__PURE__ */ y(
|
|
835
|
+
"form",
|
|
836
|
+
{
|
|
837
|
+
onSubmit: a,
|
|
838
|
+
style: {
|
|
839
|
+
display: "flex",
|
|
840
|
+
alignItems: "center",
|
|
841
|
+
gap: 8,
|
|
842
|
+
padding: "10px 12px",
|
|
843
|
+
borderTop: `1px solid ${o.border}`,
|
|
844
|
+
background: o.cardBg
|
|
845
|
+
},
|
|
846
|
+
children: [
|
|
847
|
+
/* @__PURE__ */ n(
|
|
848
|
+
"input",
|
|
849
|
+
{
|
|
850
|
+
value: v,
|
|
851
|
+
onChange: (f) => _(f.target.value),
|
|
852
|
+
placeholder: c,
|
|
853
|
+
style: {
|
|
854
|
+
flex: 1,
|
|
855
|
+
padding: "7px 10px",
|
|
856
|
+
borderRadius: 8,
|
|
857
|
+
border: `1px solid ${o.border}`,
|
|
858
|
+
background: o.inputBg,
|
|
859
|
+
color: o.text,
|
|
860
|
+
fontSize: 13,
|
|
861
|
+
outline: "none"
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
),
|
|
865
|
+
/* @__PURE__ */ n(
|
|
866
|
+
"button",
|
|
867
|
+
{
|
|
868
|
+
type: "submit",
|
|
869
|
+
disabled: !v.trim() || S,
|
|
870
|
+
style: {
|
|
871
|
+
width: 32,
|
|
872
|
+
height: 32,
|
|
873
|
+
borderRadius: 8,
|
|
874
|
+
border: "none",
|
|
875
|
+
background: !v.trim() || S ? o.border : o.primary,
|
|
876
|
+
color: o.primaryText,
|
|
877
|
+
cursor: !v.trim() || S ? "not-allowed" : "pointer",
|
|
878
|
+
display: "flex",
|
|
879
|
+
alignItems: "center",
|
|
880
|
+
justifyContent: "center",
|
|
881
|
+
flexShrink: 0,
|
|
882
|
+
opacity: !v.trim() || S ? 0.5 : 1
|
|
883
|
+
},
|
|
884
|
+
children: /* @__PURE__ */ n(je, {})
|
|
885
|
+
}
|
|
886
|
+
)
|
|
887
|
+
]
|
|
888
|
+
}
|
|
889
|
+
),
|
|
890
|
+
/* @__PURE__ */ n(q, { colors: o })
|
|
891
|
+
]
|
|
892
|
+
}
|
|
893
|
+
);
|
|
894
|
+
}
|
|
895
|
+
function Ae(e, t, r) {
|
|
896
|
+
return {
|
|
897
|
+
position: "fixed",
|
|
898
|
+
...t === "bottom-left" ? { left: 20, bottom: 20 } : { right: 20, bottom: 20 },
|
|
899
|
+
width: r,
|
|
900
|
+
height: r,
|
|
901
|
+
borderRadius: "50%",
|
|
902
|
+
border: "none",
|
|
903
|
+
background: e.primary,
|
|
904
|
+
color: e.primaryText,
|
|
905
|
+
cursor: "pointer",
|
|
906
|
+
display: "flex",
|
|
907
|
+
alignItems: "center",
|
|
908
|
+
justifyContent: "center",
|
|
909
|
+
boxShadow: "0 4px 14px rgba(0,0,0,0.25)",
|
|
910
|
+
zIndex: 2147483646,
|
|
911
|
+
transition: "transform 0.15s"
|
|
912
|
+
};
|
|
913
|
+
}
|
|
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" }) });
|
|
916
|
+
}
|
|
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" })
|
|
921
|
+
] });
|
|
922
|
+
}
|
|
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" })
|
|
927
|
+
] });
|
|
928
|
+
}
|
|
929
|
+
function Oe({
|
|
930
|
+
apiUrl: e,
|
|
931
|
+
clientId: t,
|
|
932
|
+
getFirebaseIdToken: r,
|
|
933
|
+
getToken: s,
|
|
934
|
+
title: i = "KnowLayer Assistant",
|
|
935
|
+
placeholder: c = "Ask a question…",
|
|
936
|
+
welcomeMessage: g,
|
|
937
|
+
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
|
|
945
|
+
}) {
|
|
946
|
+
const d = Q(o), { messages: b, isLoading: u, error: h, authMode: S, sendMessage: W } = Z({
|
|
947
|
+
apiUrl: e,
|
|
948
|
+
clientId: t,
|
|
949
|
+
getFirebaseIdToken: r,
|
|
950
|
+
getToken: s,
|
|
951
|
+
welcomeMessage: g,
|
|
952
|
+
signedInWelcomeMessage: k
|
|
953
|
+
}), B = U({
|
|
954
|
+
apiUrl: e,
|
|
955
|
+
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(""));
|
|
966
|
+
};
|
|
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) })
|
|
972
|
+
] }),
|
|
973
|
+
/* @__PURE__ */ y("div", { style: He(d), children: [
|
|
974
|
+
b.map((a) => /* @__PURE__ */ y(
|
|
975
|
+
"div",
|
|
976
|
+
{
|
|
977
|
+
style: {
|
|
978
|
+
display: "flex",
|
|
979
|
+
flexDirection: "column",
|
|
980
|
+
alignItems: a.role === "user" ? "flex-end" : "flex-start",
|
|
981
|
+
marginBottom: 12
|
|
982
|
+
},
|
|
983
|
+
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 }) })
|
|
986
|
+
]
|
|
987
|
+
},
|
|
988
|
+
a.id
|
|
989
|
+
)),
|
|
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(
|
|
992
|
+
"div",
|
|
993
|
+
{
|
|
994
|
+
style: {
|
|
995
|
+
padding: "8px 12px",
|
|
996
|
+
borderRadius: 8,
|
|
997
|
+
background: "#fef2f2",
|
|
998
|
+
border: "1px solid #fecaca",
|
|
999
|
+
color: "#dc2626",
|
|
1000
|
+
fontSize: 13,
|
|
1001
|
+
marginBottom: 12
|
|
1002
|
+
},
|
|
1003
|
+
children: h
|
|
1004
|
+
}
|
|
1005
|
+
),
|
|
1006
|
+
/* @__PURE__ */ n("div", { ref: _ })
|
|
1007
|
+
] }),
|
|
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(
|
|
1011
|
+
"button",
|
|
1012
|
+
{
|
|
1013
|
+
type: "button",
|
|
1014
|
+
onClick: () => {
|
|
1015
|
+
W(a);
|
|
1016
|
+
},
|
|
1017
|
+
style: Ve(d),
|
|
1018
|
+
children: a
|
|
1019
|
+
},
|
|
1020
|
+
a
|
|
1021
|
+
)) })
|
|
1022
|
+
] }),
|
|
1023
|
+
/* @__PURE__ */ y("form", { onSubmit: T, style: Ke(d), children: [
|
|
1024
|
+
/* @__PURE__ */ n(
|
|
1025
|
+
"input",
|
|
1026
|
+
{
|
|
1027
|
+
value: $,
|
|
1028
|
+
onChange: (a) => v(a.target.value),
|
|
1029
|
+
placeholder: c,
|
|
1030
|
+
style: Ne(d)
|
|
1031
|
+
}
|
|
1032
|
+
),
|
|
1033
|
+
/* @__PURE__ */ n(
|
|
1034
|
+
"button",
|
|
1035
|
+
{
|
|
1036
|
+
type: "submit",
|
|
1037
|
+
disabled: !$.trim() || u,
|
|
1038
|
+
style: qe(d, !$.trim() || u),
|
|
1039
|
+
children: /* @__PURE__ */ n(Je, {})
|
|
1040
|
+
}
|
|
1041
|
+
)
|
|
1042
|
+
] }),
|
|
1043
|
+
/* @__PURE__ */ n(q, { colors: d })
|
|
1044
|
+
] });
|
|
1045
|
+
}
|
|
1046
|
+
function De(e, t) {
|
|
1047
|
+
return {
|
|
1048
|
+
fontFamily: "system-ui, -apple-system, sans-serif",
|
|
1049
|
+
display: "flex",
|
|
1050
|
+
flexDirection: "column",
|
|
1051
|
+
height: t,
|
|
1052
|
+
borderRadius: 12,
|
|
1053
|
+
border: `1px solid ${e.border}`,
|
|
1054
|
+
background: e.bg,
|
|
1055
|
+
color: e.text,
|
|
1056
|
+
overflow: "hidden"
|
|
1057
|
+
};
|
|
1058
|
+
}
|
|
1059
|
+
function Pe(e) {
|
|
1060
|
+
return {
|
|
1061
|
+
display: "flex",
|
|
1062
|
+
alignItems: "center",
|
|
1063
|
+
gap: 8,
|
|
1064
|
+
padding: "12px 16px",
|
|
1065
|
+
borderBottom: `1px solid ${e.border}`,
|
|
1066
|
+
background: e.headerBg,
|
|
1067
|
+
color: e.headerText
|
|
1068
|
+
};
|
|
1069
|
+
}
|
|
1070
|
+
function Fe(e) {
|
|
1071
|
+
return {
|
|
1072
|
+
width: 8,
|
|
1073
|
+
height: 8,
|
|
1074
|
+
borderRadius: "50%",
|
|
1075
|
+
background: e.dot,
|
|
1076
|
+
flexShrink: 0
|
|
1077
|
+
};
|
|
1078
|
+
}
|
|
1079
|
+
function He(e) {
|
|
1080
|
+
return {
|
|
1081
|
+
flex: 1,
|
|
1082
|
+
minHeight: 0,
|
|
1083
|
+
overflowY: "auto",
|
|
1084
|
+
padding: 16,
|
|
1085
|
+
background: e.bg
|
|
1086
|
+
};
|
|
1087
|
+
}
|
|
1088
|
+
function G(e, t) {
|
|
1089
|
+
const r = e === "user";
|
|
1090
|
+
return {
|
|
1091
|
+
maxWidth: "80%",
|
|
1092
|
+
padding: "10px 14px",
|
|
1093
|
+
borderRadius: 12,
|
|
1094
|
+
fontSize: 14,
|
|
1095
|
+
lineHeight: 1.6,
|
|
1096
|
+
whiteSpace: "pre-wrap",
|
|
1097
|
+
wordBreak: "break-word",
|
|
1098
|
+
background: r ? t.userBubbleBg : t.assistantBubbleBg,
|
|
1099
|
+
color: r ? t.userBubbleText : t.text
|
|
1100
|
+
};
|
|
1101
|
+
}
|
|
1102
|
+
function Ke(e) {
|
|
1103
|
+
return {
|
|
1104
|
+
display: "flex",
|
|
1105
|
+
alignItems: "center",
|
|
1106
|
+
gap: 8,
|
|
1107
|
+
padding: "10px 12px",
|
|
1108
|
+
borderTop: `1px solid ${e.border}`,
|
|
1109
|
+
background: e.cardBg
|
|
1110
|
+
};
|
|
1111
|
+
}
|
|
1112
|
+
function Ne(e) {
|
|
1113
|
+
return {
|
|
1114
|
+
flex: 1,
|
|
1115
|
+
padding: "8px 12px",
|
|
1116
|
+
borderRadius: 8,
|
|
1117
|
+
border: `1px solid ${e.border}`,
|
|
1118
|
+
background: e.inputBg,
|
|
1119
|
+
color: e.text,
|
|
1120
|
+
fontSize: 14,
|
|
1121
|
+
outline: "none"
|
|
1122
|
+
};
|
|
1123
|
+
}
|
|
1124
|
+
function qe(e, t) {
|
|
1125
|
+
return {
|
|
1126
|
+
width: 36,
|
|
1127
|
+
height: 36,
|
|
1128
|
+
borderRadius: 8,
|
|
1129
|
+
border: "none",
|
|
1130
|
+
background: t ? e.border : e.primary,
|
|
1131
|
+
color: e.primaryText,
|
|
1132
|
+
cursor: t ? "not-allowed" : "pointer",
|
|
1133
|
+
display: "flex",
|
|
1134
|
+
alignItems: "center",
|
|
1135
|
+
justifyContent: "center",
|
|
1136
|
+
flexShrink: 0,
|
|
1137
|
+
opacity: t ? 0.5 : 1,
|
|
1138
|
+
transition: "opacity 0.15s"
|
|
1139
|
+
};
|
|
1140
|
+
}
|
|
1141
|
+
function Qe(e) {
|
|
1142
|
+
return {
|
|
1143
|
+
padding: "8px 14px",
|
|
1144
|
+
borderTop: `1px solid ${e.border}`,
|
|
1145
|
+
background: e.cardBg
|
|
1146
|
+
};
|
|
1147
|
+
}
|
|
1148
|
+
function Xe(e) {
|
|
1149
|
+
return {
|
|
1150
|
+
display: "block",
|
|
1151
|
+
fontSize: 11,
|
|
1152
|
+
fontWeight: 600,
|
|
1153
|
+
textTransform: "uppercase",
|
|
1154
|
+
letterSpacing: "0.05em",
|
|
1155
|
+
color: e.textMuted,
|
|
1156
|
+
marginBottom: 6
|
|
1157
|
+
};
|
|
1158
|
+
}
|
|
1159
|
+
function Ve(e) {
|
|
1160
|
+
return {
|
|
1161
|
+
background: "none",
|
|
1162
|
+
border: `1px solid ${e.border}`,
|
|
1163
|
+
borderRadius: 999,
|
|
1164
|
+
padding: "4px 10px",
|
|
1165
|
+
fontSize: 12,
|
|
1166
|
+
color: e.textMuted,
|
|
1167
|
+
cursor: "pointer",
|
|
1168
|
+
whiteSpace: "nowrap"
|
|
1169
|
+
};
|
|
1170
|
+
}
|
|
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" })
|
|
1175
|
+
] });
|
|
1176
|
+
}
|
|
1177
|
+
function Ye({
|
|
1178
|
+
apiUrl: e,
|
|
1179
|
+
clientId: t,
|
|
1180
|
+
getFirebaseIdToken: r,
|
|
1181
|
+
getToken: s,
|
|
1182
|
+
welcomeMessage: i,
|
|
1183
|
+
placeholder: c = "Ask a question…",
|
|
1184
|
+
theme: g = "light",
|
|
1185
|
+
showScopeHint: k = !0,
|
|
1186
|
+
showCitations: o = !0,
|
|
1187
|
+
citationMinScore: l
|
|
1188
|
+
}) {
|
|
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({
|
|
1190
|
+
apiUrl: e,
|
|
1191
|
+
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([]);
|
|
1202
|
+
try {
|
|
1203
|
+
const I = await S(), M = (j) => fetch(`${e}/api/v1/teams/me/chat`, {
|
|
1204
|
+
method: "POST",
|
|
1205
|
+
headers: {
|
|
1206
|
+
"Content-Type": "application/json",
|
|
1207
|
+
Authorization: `Bearer ${j}`
|
|
1208
|
+
},
|
|
1209
|
+
body: JSON.stringify({ query: m })
|
|
1210
|
+
});
|
|
1211
|
+
let f = await M(I);
|
|
1212
|
+
if (f.status === 401) {
|
|
1213
|
+
W();
|
|
1214
|
+
const j = await S();
|
|
1215
|
+
f = await M(j);
|
|
1216
|
+
}
|
|
1217
|
+
if (!a()) return;
|
|
1218
|
+
if (!f.ok) {
|
|
1219
|
+
if (f.status === 402) {
|
|
1220
|
+
p(F);
|
|
1221
|
+
return;
|
|
1222
|
+
}
|
|
1223
|
+
p("Something went wrong.");
|
|
1224
|
+
return;
|
|
1225
|
+
}
|
|
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);
|
|
1229
|
+
} catch {
|
|
1230
|
+
a() && p("Something went wrong.");
|
|
1231
|
+
} finally {
|
|
1232
|
+
a() && u(!1);
|
|
1233
|
+
}
|
|
1234
|
+
};
|
|
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(
|
|
1239
|
+
"input",
|
|
1240
|
+
{
|
|
1241
|
+
type: "text",
|
|
1242
|
+
value: m,
|
|
1243
|
+
onChange: (T) => x(T.target.value),
|
|
1244
|
+
onKeyDown: (T) => T.key === "Enter" && _(),
|
|
1245
|
+
placeholder: c,
|
|
1246
|
+
style: {
|
|
1247
|
+
flex: 1,
|
|
1248
|
+
padding: "8px 12px",
|
|
1249
|
+
borderRadius: 6,
|
|
1250
|
+
border: "1px solid #ccc",
|
|
1251
|
+
fontSize: 14
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
),
|
|
1255
|
+
/* @__PURE__ */ n(
|
|
1256
|
+
"button",
|
|
1257
|
+
{
|
|
1258
|
+
onClick: _,
|
|
1259
|
+
disabled: b,
|
|
1260
|
+
style: {
|
|
1261
|
+
padding: "8px 16px",
|
|
1262
|
+
borderRadius: 6,
|
|
1263
|
+
border: "none",
|
|
1264
|
+
background: "#2563eb",
|
|
1265
|
+
color: "#fff",
|
|
1266
|
+
cursor: "pointer",
|
|
1267
|
+
fontSize: 14
|
|
1268
|
+
},
|
|
1269
|
+
children: b ? "…" : "Ask"
|
|
1270
|
+
}
|
|
1271
|
+
)
|
|
1272
|
+
] }),
|
|
1273
|
+
k && /* @__PURE__ */ n("div", { style: { marginTop: 4, fontSize: 11, color: h.textMuted }, children: K(B) }),
|
|
1274
|
+
w && /* @__PURE__ */ n(
|
|
1275
|
+
"div",
|
|
1276
|
+
{
|
|
1277
|
+
style: {
|
|
1278
|
+
marginTop: 12,
|
|
1279
|
+
padding: 12,
|
|
1280
|
+
borderRadius: 6,
|
|
1281
|
+
background: "#f8fafc",
|
|
1282
|
+
border: "1px solid #e2e8f0",
|
|
1283
|
+
whiteSpace: "pre-wrap",
|
|
1284
|
+
fontSize: 14
|
|
1285
|
+
},
|
|
1286
|
+
children: w
|
|
1287
|
+
}
|
|
1288
|
+
),
|
|
1289
|
+
o && C.length > 0 && /* @__PURE__ */ n(N, { sources: C, colors: h, minScore: l }),
|
|
1290
|
+
/* @__PURE__ */ n(q, { colors: h })
|
|
1291
|
+
] });
|
|
1292
|
+
}
|
|
1293
|
+
function et({
|
|
1294
|
+
chatType: e,
|
|
1295
|
+
apiUrl: t = pe,
|
|
1296
|
+
...r
|
|
1297
|
+
}) {
|
|
1298
|
+
switch (e) {
|
|
1299
|
+
case "floating":
|
|
1300
|
+
return /* @__PURE__ */ n(Ee, { apiUrl: t, ...r });
|
|
1301
|
+
case "embedded":
|
|
1302
|
+
return /* @__PURE__ */ n(Oe, { apiUrl: t, ...r });
|
|
1303
|
+
case "search":
|
|
1304
|
+
return /* @__PURE__ */ n(Ye, { apiUrl: t, ...r });
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
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
|
|
1314
|
+
};
|