@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/README.md +49 -2
- package/dist/index.cjs +2 -2
- package/dist/index.d.ts +80 -4
- package/dist/index.js +650 -540
- package/package.json +2 -10
package/dist/index.js
CHANGED
|
@@ -1,332 +1,332 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { useRef as R, useCallback as
|
|
3
|
-
import { createPortal as
|
|
4
|
-
const
|
|
5
|
-
function
|
|
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
|
|
8
|
+
function me(e, t) {
|
|
9
9
|
if (e && typeof e == "object" && "detail" in e) {
|
|
10
|
-
const
|
|
11
|
-
if (typeof
|
|
10
|
+
const n = e.detail;
|
|
11
|
+
if (typeof n == "string" && n.trim()) return n;
|
|
12
12
|
}
|
|
13
13
|
return t;
|
|
14
14
|
}
|
|
15
|
-
function
|
|
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
|
|
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:
|
|
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
|
|
28
|
-
return { token: t, expiresIn:
|
|
27
|
+
const n = typeof e.expires_in == "number" ? e.expires_in : N;
|
|
28
|
+
return { token: t, expiresIn: n };
|
|
29
29
|
}
|
|
30
|
-
async function
|
|
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
|
-
|
|
34
|
+
me(i, `Widget token request failed (${e.status})`)
|
|
35
35
|
);
|
|
36
36
|
}
|
|
37
|
-
const
|
|
38
|
-
if (!
|
|
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
|
|
41
|
-
return { token:
|
|
40
|
+
const o = typeof n.expires_in == "number" ? n.expires_in : t;
|
|
41
|
+
return { token: n.token, expiresIn: o };
|
|
42
42
|
}
|
|
43
|
-
function
|
|
43
|
+
function V({
|
|
44
44
|
apiUrl: e,
|
|
45
45
|
clientId: t,
|
|
46
|
-
getFirebaseIdToken:
|
|
47
|
-
getToken:
|
|
46
|
+
getFirebaseIdToken: n,
|
|
47
|
+
getToken: o
|
|
48
48
|
}) {
|
|
49
|
-
if (
|
|
50
|
-
throw new Error(
|
|
51
|
-
const i =
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
}, []),
|
|
56
|
-
const
|
|
57
|
-
if (
|
|
58
|
-
throw new Error(
|
|
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
|
|
61
|
-
if (i === "getToken" &&
|
|
62
|
-
|
|
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
|
|
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":
|
|
68
|
+
"X-Firebase-Id-Token": p
|
|
69
69
|
}
|
|
70
70
|
});
|
|
71
|
-
|
|
71
|
+
h = await ee(S, he);
|
|
72
72
|
} else {
|
|
73
|
-
const
|
|
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
|
-
|
|
77
|
+
h = await ee(p, N);
|
|
78
78
|
}
|
|
79
|
-
return
|
|
80
|
-
key:
|
|
81
|
-
token:
|
|
82
|
-
expiresAt: Date.now() +
|
|
83
|
-
},
|
|
84
|
-
} catch (
|
|
85
|
-
const
|
|
86
|
-
|
|
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
|
|
88
|
+
throw u === g.current && (x.current = { key: f, at: Date.now(), message: p }), new Error(p);
|
|
89
89
|
}
|
|
90
|
-
}, [e, t, i,
|
|
91
|
-
return { getWidgetToken:
|
|
92
|
-
const
|
|
93
|
-
if (
|
|
94
|
-
return
|
|
95
|
-
const
|
|
96
|
-
if (
|
|
97
|
-
return
|
|
98
|
-
const
|
|
99
|
-
var
|
|
100
|
-
((
|
|
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
|
|
103
|
-
}, [
|
|
102
|
+
return d.current = { key: f, promise: h }, h;
|
|
103
|
+
}, [f, l]), invalidateWidgetToken: B, authMode: i };
|
|
104
104
|
}
|
|
105
|
-
const
|
|
106
|
-
function
|
|
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
|
|
110
|
-
let
|
|
111
|
-
function
|
|
112
|
-
return `msg_${Date.now()}_${++
|
|
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
|
|
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:
|
|
121
|
+
body: JSON.stringify({ query: n })
|
|
122
122
|
});
|
|
123
123
|
}
|
|
124
|
-
function
|
|
124
|
+
function ie({
|
|
125
125
|
apiUrl: e,
|
|
126
126
|
clientId: t,
|
|
127
|
-
getFirebaseIdToken:
|
|
128
|
-
getToken:
|
|
129
|
-
welcomeMessage: i =
|
|
130
|
-
signedInWelcomeMessage:
|
|
127
|
+
getFirebaseIdToken: n,
|
|
128
|
+
getToken: o,
|
|
129
|
+
welcomeMessage: i = Se,
|
|
130
|
+
signedInWelcomeMessage: f
|
|
131
131
|
}) {
|
|
132
|
-
const { getWidgetToken:
|
|
132
|
+
const { getWidgetToken: a, invalidateWidgetToken: k, authMode: s } = V({
|
|
133
133
|
apiUrl: e,
|
|
134
134
|
clientId: t,
|
|
135
|
-
getFirebaseIdToken:
|
|
136
|
-
getToken:
|
|
137
|
-
}),
|
|
138
|
-
{ id:
|
|
139
|
-
]), [
|
|
140
|
-
|
|
141
|
-
}, [
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}, [
|
|
145
|
-
const S =
|
|
146
|
-
async (
|
|
147
|
-
const
|
|
148
|
-
if (!
|
|
149
|
-
const $ =
|
|
150
|
-
|
|
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
|
|
153
|
-
let
|
|
154
|
-
if (
|
|
152
|
+
const I = await a();
|
|
153
|
+
let c = await te(e, I, v);
|
|
154
|
+
if (c.status === 401) {
|
|
155
155
|
k();
|
|
156
|
-
const
|
|
157
|
-
|
|
156
|
+
const _ = await a();
|
|
157
|
+
c = await te(e, _, v);
|
|
158
158
|
}
|
|
159
|
-
if (!
|
|
160
|
-
if (!
|
|
161
|
-
if (
|
|
162
|
-
|
|
163
|
-
...
|
|
164
|
-
{ id:
|
|
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
|
|
169
|
-
throw new Error(
|
|
168
|
+
const _ = await c.json().catch(() => ({}));
|
|
169
|
+
throw new Error(_.detail || `Request failed (${c.status})`);
|
|
170
170
|
}
|
|
171
|
-
const
|
|
172
|
-
if (!
|
|
173
|
-
const
|
|
174
|
-
id:
|
|
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:
|
|
177
|
-
sources:
|
|
176
|
+
content: M.answer ?? "No response received.",
|
|
177
|
+
sources: E ? M.sources : void 0
|
|
178
178
|
};
|
|
179
|
-
|
|
180
|
-
} catch (
|
|
181
|
-
if (!
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
...
|
|
185
|
-
{ id:
|
|
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
|
-
|
|
188
|
+
T() && l(!1);
|
|
189
189
|
}
|
|
190
190
|
},
|
|
191
|
-
[e,
|
|
191
|
+
[e, a, k, B]
|
|
192
192
|
);
|
|
193
|
-
return { messages:
|
|
193
|
+
return { messages: x, isLoading: B, error: w, authMode: s, sendMessage: S, reset: h };
|
|
194
194
|
}
|
|
195
|
-
function
|
|
195
|
+
function se({
|
|
196
196
|
apiUrl: e,
|
|
197
197
|
clientId: t,
|
|
198
|
-
getFirebaseIdToken:
|
|
199
|
-
getToken:
|
|
198
|
+
getFirebaseIdToken: n,
|
|
199
|
+
getToken: o,
|
|
200
200
|
suggestedQuestions: i
|
|
201
201
|
}) {
|
|
202
|
-
const [
|
|
202
|
+
const [f, a] = C([]), { getWidgetToken: k, invalidateWidgetToken: s, authMode: d } = V({
|
|
203
203
|
apiUrl: e,
|
|
204
204
|
clientId: t,
|
|
205
|
-
getFirebaseIdToken:
|
|
206
|
-
getToken:
|
|
207
|
-
}),
|
|
208
|
-
return
|
|
209
|
-
if (
|
|
210
|
-
let
|
|
211
|
-
return
|
|
212
|
-
const
|
|
213
|
-
headers: { Authorization: `Bearer ${
|
|
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
|
|
217
|
-
if (
|
|
218
|
-
const
|
|
219
|
-
if (
|
|
220
|
-
const
|
|
221
|
-
(
|
|
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
|
-
|
|
223
|
+
a(u);
|
|
224
224
|
} catch {
|
|
225
225
|
}
|
|
226
226
|
})(), () => {
|
|
227
|
-
|
|
227
|
+
g = !0;
|
|
228
228
|
};
|
|
229
|
-
}, [e,
|
|
229
|
+
}, [e, d, k, s, x]), x ? i : f;
|
|
230
230
|
}
|
|
231
|
-
const
|
|
232
|
-
function
|
|
233
|
-
const t = (e.team_id ?? "").toString().trim().toLowerCase(),
|
|
234
|
-
if (
|
|
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 ? `${
|
|
236
|
+
return i ? `${n}id:${i}` : `${n}text:${(e.text ?? "").slice(0, 60)}`;
|
|
237
237
|
}
|
|
238
|
-
function
|
|
239
|
-
const
|
|
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
|
|
243
|
-
if (!
|
|
244
|
-
|
|
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) > (
|
|
247
|
+
(i.score ?? 0) > (a.score ?? 0) && n.set(f, i);
|
|
248
248
|
}
|
|
249
|
-
return
|
|
249
|
+
return o.map((i) => n.get(i));
|
|
250
250
|
}
|
|
251
|
-
function
|
|
251
|
+
function $e(e) {
|
|
252
252
|
return new Set(
|
|
253
|
-
e.map((
|
|
253
|
+
e.map((n) => (n.team_id ?? "").toString()).filter((n) => n.length > 0)
|
|
254
254
|
).size > 1;
|
|
255
255
|
}
|
|
256
|
-
function
|
|
257
|
-
const t = (e.clause_number ?? "").toString().trim(),
|
|
258
|
-
return t &&
|
|
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
|
|
260
|
+
function J({
|
|
261
261
|
sources: e,
|
|
262
262
|
colors: t,
|
|
263
|
-
compact:
|
|
264
|
-
minScore:
|
|
263
|
+
compact: n = !1,
|
|
264
|
+
minScore: o = ae
|
|
265
265
|
}) {
|
|
266
|
-
const [i,
|
|
267
|
-
() =>
|
|
268
|
-
[e,
|
|
269
|
-
), k =
|
|
270
|
-
if (
|
|
271
|
-
const
|
|
272
|
-
return /* @__PURE__ */
|
|
273
|
-
/* @__PURE__ */
|
|
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: () =>
|
|
277
|
-
style:
|
|
276
|
+
onClick: () => f((d) => !d),
|
|
277
|
+
style: Le(t, s),
|
|
278
278
|
children: [
|
|
279
|
-
/* @__PURE__ */
|
|
280
|
-
/* @__PURE__ */
|
|
281
|
-
|
|
279
|
+
/* @__PURE__ */ r(ze, { size: n ? 12 : 14, color: t.textMuted }),
|
|
280
|
+
/* @__PURE__ */ m("span", { children: [
|
|
281
|
+
a.length,
|
|
282
282
|
" source",
|
|
283
|
-
|
|
283
|
+
a.length > 1 ? "s" : "",
|
|
284
284
|
" cited"
|
|
285
285
|
] }),
|
|
286
|
-
/* @__PURE__ */
|
|
287
|
-
|
|
286
|
+
/* @__PURE__ */ r(
|
|
287
|
+
je,
|
|
288
288
|
{
|
|
289
289
|
direction: i ? "up" : "down",
|
|
290
|
-
size:
|
|
290
|
+
size: n ? 12 : 14,
|
|
291
291
|
color: t.textMuted
|
|
292
292
|
}
|
|
293
293
|
)
|
|
294
294
|
]
|
|
295
295
|
}
|
|
296
296
|
),
|
|
297
|
-
i && /* @__PURE__ */
|
|
298
|
-
const
|
|
299
|
-
return /* @__PURE__ */
|
|
300
|
-
/* @__PURE__ */
|
|
301
|
-
/* @__PURE__ */
|
|
302
|
-
/* @__PURE__ */
|
|
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:
|
|
305
|
+
title: B,
|
|
306
306
|
style: {
|
|
307
307
|
fontWeight: 600,
|
|
308
|
-
fontSize:
|
|
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:
|
|
315
|
+
children: B
|
|
316
316
|
}
|
|
317
317
|
),
|
|
318
|
-
|
|
319
|
-
(
|
|
318
|
+
d.score != null && /* @__PURE__ */ m("span", { style: _e(), children: [
|
|
319
|
+
(d.score * 100).toFixed(0),
|
|
320
320
|
"%"
|
|
321
321
|
] })
|
|
322
322
|
] }),
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
] }, `${
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
409
|
-
return /* @__PURE__ */
|
|
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__ */
|
|
422
|
-
/* @__PURE__ */
|
|
423
|
-
/* @__PURE__ */
|
|
424
|
-
/* @__PURE__ */
|
|
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
|
|
429
|
+
function je({
|
|
430
430
|
direction: e,
|
|
431
431
|
size: t,
|
|
432
|
-
color:
|
|
432
|
+
color: n
|
|
433
433
|
}) {
|
|
434
|
-
return /* @__PURE__ */
|
|
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:
|
|
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__ */
|
|
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
|
|
451
|
-
return /* @__PURE__ */
|
|
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__ */
|
|
465
|
-
/* @__PURE__ */
|
|
466
|
-
/* @__PURE__ */
|
|
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
|
|
472
|
-
return /* @__PURE__ */
|
|
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__ */
|
|
486
|
-
/* @__PURE__ */
|
|
487
|
-
/* @__PURE__ */
|
|
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
|
|
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
|
-
|
|
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
|
|
524
|
-
|
|
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
|
|
630
|
+
function ue(e) {
|
|
527
631
|
const t = e.split(`
|
|
528
|
-
`),
|
|
529
|
-
for (let
|
|
530
|
-
|
|
531
|
-
|
|
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
|
|
637
|
+
return O(Z, null, ...n);
|
|
534
638
|
}
|
|
535
|
-
function
|
|
536
|
-
const t = [],
|
|
537
|
-
let
|
|
538
|
-
for (; (i =
|
|
539
|
-
i.index >
|
|
540
|
-
|
|
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_${
|
|
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
|
-
),
|
|
554
|
-
return
|
|
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
|
|
660
|
+
function He({
|
|
557
661
|
apiUrl: e,
|
|
558
662
|
clientId: t,
|
|
559
|
-
getFirebaseIdToken:
|
|
560
|
-
getToken:
|
|
663
|
+
getFirebaseIdToken: n,
|
|
664
|
+
getToken: o,
|
|
561
665
|
title: i = "KnowLayer Assistant",
|
|
562
|
-
placeholder:
|
|
563
|
-
welcomeMessage:
|
|
666
|
+
placeholder: f = "Ask a question…",
|
|
667
|
+
welcomeMessage: a,
|
|
564
668
|
signedInWelcomeMessage: k,
|
|
565
|
-
theme:
|
|
566
|
-
position:
|
|
567
|
-
buttonSize:
|
|
568
|
-
popupWidth:
|
|
569
|
-
popupHeight:
|
|
570
|
-
suggestedQuestions:
|
|
571
|
-
showScopeHint:
|
|
572
|
-
showCitations:
|
|
573
|
-
citationMinScore:
|
|
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 [
|
|
679
|
+
const [h, p] = C(!1), S = G(s), L = se({
|
|
576
680
|
apiUrl: e,
|
|
577
681
|
clientId: t,
|
|
578
|
-
getFirebaseIdToken:
|
|
579
|
-
getToken:
|
|
580
|
-
suggestedQuestions:
|
|
682
|
+
getFirebaseIdToken: n,
|
|
683
|
+
getToken: o,
|
|
684
|
+
suggestedQuestions: l
|
|
581
685
|
});
|
|
582
|
-
return
|
|
583
|
-
/* @__PURE__ */
|
|
584
|
-
|
|
585
|
-
|
|
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:
|
|
590
|
-
getToken:
|
|
693
|
+
getFirebaseIdToken: n,
|
|
694
|
+
getToken: o,
|
|
591
695
|
title: i,
|
|
592
|
-
placeholder:
|
|
593
|
-
welcomeMessage:
|
|
696
|
+
placeholder: f,
|
|
697
|
+
welcomeMessage: a,
|
|
594
698
|
signedInWelcomeMessage: k,
|
|
595
699
|
colors: S,
|
|
596
|
-
position:
|
|
597
|
-
buttonSize:
|
|
598
|
-
popupWidth:
|
|
599
|
-
popupHeight:
|
|
600
|
-
onClose: () =>
|
|
601
|
-
suggestedQuestions:
|
|
602
|
-
showScopeHint:
|
|
603
|
-
showCitations:
|
|
604
|
-
citationMinScore:
|
|
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__ */
|
|
711
|
+
/* @__PURE__ */ r(
|
|
608
712
|
"button",
|
|
609
713
|
{
|
|
610
|
-
onClick: () =>
|
|
611
|
-
style:
|
|
612
|
-
"aria-label":
|
|
613
|
-
children:
|
|
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
|
|
724
|
+
function Ke({
|
|
621
725
|
apiUrl: e,
|
|
622
726
|
clientId: t,
|
|
623
|
-
getFirebaseIdToken:
|
|
624
|
-
getToken:
|
|
727
|
+
getFirebaseIdToken: n,
|
|
728
|
+
getToken: o,
|
|
625
729
|
title: i,
|
|
626
|
-
placeholder:
|
|
627
|
-
welcomeMessage:
|
|
730
|
+
placeholder: f,
|
|
731
|
+
welcomeMessage: a,
|
|
628
732
|
signedInWelcomeMessage: k,
|
|
629
|
-
colors:
|
|
630
|
-
position:
|
|
631
|
-
buttonSize:
|
|
632
|
-
popupWidth:
|
|
633
|
-
popupHeight:
|
|
634
|
-
onClose:
|
|
635
|
-
suggestedQuestions:
|
|
636
|
-
showScopeHint:
|
|
637
|
-
showCitations:
|
|
638
|
-
citationMinScore:
|
|
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:
|
|
744
|
+
const { messages: p, isLoading: S, error: L, authMode: v, sendMessage: $ } = ie({
|
|
641
745
|
apiUrl: e,
|
|
642
746
|
clientId: t,
|
|
643
|
-
getFirebaseIdToken:
|
|
644
|
-
getToken:
|
|
645
|
-
welcomeMessage:
|
|
747
|
+
getFirebaseIdToken: n,
|
|
748
|
+
getToken: o,
|
|
749
|
+
welcomeMessage: a,
|
|
646
750
|
signedInWelcomeMessage: k
|
|
647
|
-
}), [
|
|
648
|
-
|
|
649
|
-
var
|
|
650
|
-
(
|
|
651
|
-
}, [
|
|
652
|
-
const
|
|
653
|
-
|
|
654
|
-
},
|
|
655
|
-
return /* @__PURE__ */
|
|
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
|
-
...
|
|
661
|
-
width:
|
|
662
|
-
height:
|
|
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 ${
|
|
669
|
-
background:
|
|
670
|
-
color:
|
|
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__ */
|
|
677
|
-
/* @__PURE__ */
|
|
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 ${
|
|
686
|
-
background:
|
|
789
|
+
borderBottom: `1px solid ${s.border}`,
|
|
790
|
+
background: s.headerBg,
|
|
791
|
+
color: s.headerText
|
|
687
792
|
},
|
|
688
793
|
children: [
|
|
689
|
-
/* @__PURE__ */
|
|
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:
|
|
801
|
+
background: s.dot,
|
|
697
802
|
flexShrink: 0
|
|
698
803
|
}
|
|
699
804
|
}
|
|
700
805
|
),
|
|
701
|
-
/* @__PURE__ */
|
|
702
|
-
|
|
703
|
-
/* @__PURE__ */
|
|
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:
|
|
811
|
+
onClick: l,
|
|
707
812
|
style: {
|
|
708
813
|
background: "none",
|
|
709
814
|
border: "none",
|
|
710
815
|
cursor: "pointer",
|
|
711
|
-
color:
|
|
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__ */
|
|
822
|
+
children: /* @__PURE__ */ r(ce, {})
|
|
717
823
|
}
|
|
718
824
|
)
|
|
719
825
|
]
|
|
720
826
|
}
|
|
721
827
|
),
|
|
722
|
-
/* @__PURE__ */
|
|
723
|
-
|
|
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:
|
|
835
|
+
alignItems: b.role === "user" ? "flex-end" : "flex-start",
|
|
730
836
|
marginBottom: 10
|
|
731
837
|
},
|
|
732
838
|
children: [
|
|
733
|
-
/* @__PURE__ */
|
|
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:
|
|
745
|
-
color:
|
|
850
|
+
background: b.role === "user" ? s.userBubbleBg : s.assistantBubbleBg,
|
|
851
|
+
color: b.role === "user" ? s.userBubbleText : s.assistantBubbleText
|
|
746
852
|
},
|
|
747
|
-
children:
|
|
853
|
+
children: b.role === "assistant" ? ue(b.content) : b.content
|
|
748
854
|
}
|
|
749
855
|
),
|
|
750
|
-
|
|
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
|
-
|
|
859
|
+
b.id
|
|
754
860
|
)),
|
|
755
|
-
S && /* @__PURE__ */
|
|
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:
|
|
764
|
-
color:
|
|
869
|
+
background: s.assistantBubbleBg,
|
|
870
|
+
color: s.textMuted
|
|
765
871
|
},
|
|
766
872
|
children: "Thinking…"
|
|
767
873
|
}
|
|
768
874
|
) }),
|
|
769
|
-
|
|
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:
|
|
887
|
+
children: L
|
|
782
888
|
}
|
|
783
889
|
),
|
|
784
|
-
/* @__PURE__ */
|
|
890
|
+
/* @__PURE__ */ r("div", { ref: I })
|
|
785
891
|
] }),
|
|
786
|
-
|
|
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 ${
|
|
792
|
-
background:
|
|
897
|
+
borderTop: `1px solid ${s.border}`,
|
|
898
|
+
background: s.cardBg
|
|
793
899
|
},
|
|
794
900
|
children: [
|
|
795
|
-
/* @__PURE__ */
|
|
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:
|
|
910
|
+
color: s.textMuted,
|
|
805
911
|
marginBottom: 5
|
|
806
912
|
},
|
|
807
913
|
children: "Try asking"
|
|
808
914
|
}
|
|
809
915
|
),
|
|
810
|
-
/* @__PURE__ */
|
|
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
|
-
$(
|
|
921
|
+
$(b);
|
|
816
922
|
},
|
|
817
923
|
style: {
|
|
818
924
|
background: "none",
|
|
819
|
-
border: `1px solid ${
|
|
925
|
+
border: `1px solid ${s.border}`,
|
|
820
926
|
borderRadius: 999,
|
|
821
927
|
padding: "3px 8px",
|
|
822
928
|
fontSize: 11,
|
|
823
|
-
color:
|
|
929
|
+
color: s.textMuted,
|
|
824
930
|
cursor: "pointer",
|
|
825
931
|
whiteSpace: "nowrap"
|
|
826
932
|
},
|
|
827
|
-
children:
|
|
933
|
+
children: b
|
|
828
934
|
},
|
|
829
|
-
|
|
935
|
+
b
|
|
830
936
|
)) })
|
|
831
937
|
]
|
|
832
938
|
}
|
|
833
939
|
),
|
|
834
|
-
/* @__PURE__ */
|
|
940
|
+
/* @__PURE__ */ m(
|
|
835
941
|
"form",
|
|
836
942
|
{
|
|
837
|
-
onSubmit:
|
|
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 ${
|
|
844
|
-
background:
|
|
949
|
+
borderTop: `1px solid ${s.border}`,
|
|
950
|
+
background: s.cardBg
|
|
845
951
|
},
|
|
846
952
|
children: [
|
|
847
|
-
/* @__PURE__ */
|
|
953
|
+
/* @__PURE__ */ r(
|
|
848
954
|
"input",
|
|
849
955
|
{
|
|
850
|
-
value:
|
|
851
|
-
onChange: (
|
|
852
|
-
placeholder:
|
|
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 ${
|
|
858
|
-
background:
|
|
859
|
-
color:
|
|
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__ */
|
|
971
|
+
/* @__PURE__ */ r(
|
|
866
972
|
"button",
|
|
867
973
|
{
|
|
868
974
|
type: "submit",
|
|
869
|
-
disabled: !
|
|
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: !
|
|
876
|
-
color:
|
|
877
|
-
cursor: !
|
|
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: !
|
|
988
|
+
opacity: !T.trim() || S ? 0.5 : 1
|
|
883
989
|
},
|
|
884
|
-
children: /* @__PURE__ */
|
|
990
|
+
children: /* @__PURE__ */ r(Qe, {})
|
|
885
991
|
}
|
|
886
992
|
)
|
|
887
993
|
]
|
|
888
994
|
}
|
|
889
995
|
),
|
|
890
|
-
/* @__PURE__ */
|
|
996
|
+
/* @__PURE__ */ r(Y, { colors: s })
|
|
891
997
|
]
|
|
892
998
|
}
|
|
893
999
|
);
|
|
894
1000
|
}
|
|
895
|
-
function
|
|
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:
|
|
900
|
-
height:
|
|
1005
|
+
width: n,
|
|
1006
|
+
height: n,
|
|
901
1007
|
borderRadius: "50%",
|
|
902
1008
|
border: "none",
|
|
903
|
-
background: e.
|
|
904
|
-
color: e.
|
|
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
|
|
915
|
-
return /* @__PURE__ */
|
|
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
|
|
918
|
-
return /* @__PURE__ */
|
|
919
|
-
/* @__PURE__ */
|
|
920
|
-
/* @__PURE__ */
|
|
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
|
|
924
|
-
return /* @__PURE__ */
|
|
925
|
-
/* @__PURE__ */
|
|
926
|
-
/* @__PURE__ */
|
|
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
|
|
1035
|
+
function Ve({
|
|
930
1036
|
apiUrl: e,
|
|
931
1037
|
clientId: t,
|
|
932
|
-
getFirebaseIdToken:
|
|
933
|
-
getToken:
|
|
1038
|
+
getFirebaseIdToken: n,
|
|
1039
|
+
getToken: o,
|
|
934
1040
|
title: i = "KnowLayer Assistant",
|
|
935
|
-
placeholder:
|
|
936
|
-
welcomeMessage:
|
|
1041
|
+
placeholder: f = "Ask a question…",
|
|
1042
|
+
welcomeMessage: a,
|
|
937
1043
|
signedInWelcomeMessage: k,
|
|
938
|
-
theme:
|
|
939
|
-
height:
|
|
940
|
-
className:
|
|
941
|
-
suggestedQuestions:
|
|
942
|
-
showScopeHint:
|
|
943
|
-
showCitations:
|
|
944
|
-
citationMinScore:
|
|
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
|
|
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:
|
|
950
|
-
getToken:
|
|
951
|
-
welcomeMessage:
|
|
1055
|
+
getFirebaseIdToken: n,
|
|
1056
|
+
getToken: o,
|
|
1057
|
+
welcomeMessage: a,
|
|
952
1058
|
signedInWelcomeMessage: k
|
|
953
|
-
}),
|
|
1059
|
+
}), v = se({
|
|
954
1060
|
apiUrl: e,
|
|
955
1061
|
clientId: t,
|
|
956
|
-
getFirebaseIdToken:
|
|
957
|
-
getToken:
|
|
958
|
-
suggestedQuestions:
|
|
959
|
-
}), [$,
|
|
960
|
-
|
|
961
|
-
var
|
|
962
|
-
(
|
|
963
|
-
}, [
|
|
964
|
-
const
|
|
965
|
-
|
|
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__ */
|
|
968
|
-
/* @__PURE__ */
|
|
969
|
-
/* @__PURE__ */
|
|
970
|
-
/* @__PURE__ */
|
|
971
|
-
|
|
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__ */
|
|
974
|
-
|
|
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:
|
|
1086
|
+
alignItems: c.role === "user" ? "flex-end" : "flex-start",
|
|
981
1087
|
marginBottom: 12
|
|
982
1088
|
},
|
|
983
1089
|
children: [
|
|
984
|
-
/* @__PURE__ */
|
|
985
|
-
|
|
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
|
-
|
|
1094
|
+
c.id
|
|
989
1095
|
)),
|
|
990
|
-
|
|
991
|
-
|
|
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:
|
|
1109
|
+
children: p
|
|
1004
1110
|
}
|
|
1005
1111
|
),
|
|
1006
|
-
/* @__PURE__ */
|
|
1112
|
+
/* @__PURE__ */ r("div", { ref: W })
|
|
1007
1113
|
] }),
|
|
1008
|
-
|
|
1009
|
-
/* @__PURE__ */
|
|
1010
|
-
/* @__PURE__ */
|
|
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
|
-
|
|
1121
|
+
L(c);
|
|
1016
1122
|
},
|
|
1017
|
-
style:
|
|
1018
|
-
children:
|
|
1123
|
+
style: rt(u),
|
|
1124
|
+
children: c
|
|
1019
1125
|
},
|
|
1020
|
-
|
|
1126
|
+
c
|
|
1021
1127
|
)) })
|
|
1022
1128
|
] }),
|
|
1023
|
-
/* @__PURE__ */
|
|
1024
|
-
/* @__PURE__ */
|
|
1129
|
+
/* @__PURE__ */ m("form", { onSubmit: I, style: Ue(u), children: [
|
|
1130
|
+
/* @__PURE__ */ r(
|
|
1025
1131
|
"input",
|
|
1026
1132
|
{
|
|
1027
1133
|
value: $,
|
|
1028
|
-
onChange: (
|
|
1029
|
-
placeholder:
|
|
1030
|
-
style:
|
|
1134
|
+
onChange: (c) => T(c.target.value),
|
|
1135
|
+
placeholder: f,
|
|
1136
|
+
style: Ze(u)
|
|
1031
1137
|
}
|
|
1032
1138
|
),
|
|
1033
|
-
/* @__PURE__ */
|
|
1139
|
+
/* @__PURE__ */ r(
|
|
1034
1140
|
"button",
|
|
1035
1141
|
{
|
|
1036
1142
|
type: "submit",
|
|
1037
|
-
disabled: !$.trim() ||
|
|
1038
|
-
style:
|
|
1039
|
-
children: /* @__PURE__ */
|
|
1143
|
+
disabled: !$.trim() || h,
|
|
1144
|
+
style: et(u, !$.trim() || h),
|
|
1145
|
+
children: /* @__PURE__ */ r(ot, {})
|
|
1040
1146
|
}
|
|
1041
1147
|
)
|
|
1042
1148
|
] }),
|
|
1043
|
-
/* @__PURE__ */
|
|
1149
|
+
/* @__PURE__ */ r(Y, { colors: u })
|
|
1044
1150
|
] });
|
|
1045
1151
|
}
|
|
1046
|
-
function
|
|
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
|
|
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
|
|
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
|
|
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
|
|
1089
|
-
const
|
|
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:
|
|
1099
|
-
color:
|
|
1204
|
+
background: n ? t.userBubbleBg : t.assistantBubbleBg,
|
|
1205
|
+
color: n ? t.userBubbleText : t.assistantBubbleText
|
|
1100
1206
|
};
|
|
1101
1207
|
}
|
|
1102
|
-
function
|
|
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
|
|
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.
|
|
1223
|
+
border: `1px solid ${e.inputBorder}`,
|
|
1118
1224
|
background: e.inputBg,
|
|
1119
|
-
color: e.
|
|
1225
|
+
color: e.inputText,
|
|
1120
1226
|
fontSize: 14,
|
|
1121
1227
|
outline: "none"
|
|
1122
1228
|
};
|
|
1123
1229
|
}
|
|
1124
|
-
function
|
|
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.
|
|
1131
|
-
color: e.
|
|
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
|
|
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
|
|
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
|
|
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
|
|
1172
|
-
return /* @__PURE__ */
|
|
1173
|
-
/* @__PURE__ */
|
|
1174
|
-
/* @__PURE__ */
|
|
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
|
|
1283
|
+
function it({
|
|
1178
1284
|
apiUrl: e,
|
|
1179
1285
|
clientId: t,
|
|
1180
|
-
getFirebaseIdToken:
|
|
1181
|
-
getToken:
|
|
1286
|
+
getFirebaseIdToken: n,
|
|
1287
|
+
getToken: o,
|
|
1182
1288
|
welcomeMessage: i,
|
|
1183
|
-
placeholder:
|
|
1184
|
-
theme:
|
|
1289
|
+
placeholder: f = "Ask a question…",
|
|
1290
|
+
theme: a = "light",
|
|
1185
1291
|
showScopeHint: k = !0,
|
|
1186
|
-
showCitations:
|
|
1187
|
-
citationMinScore:
|
|
1292
|
+
showCitations: s = !0,
|
|
1293
|
+
citationMinScore: d
|
|
1188
1294
|
}) {
|
|
1189
|
-
const [
|
|
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:
|
|
1193
|
-
getToken:
|
|
1194
|
-
}), $ = R(0),
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
}, [
|
|
1198
|
-
const
|
|
1199
|
-
if (!
|
|
1200
|
-
const
|
|
1201
|
-
|
|
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
|
|
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 ${
|
|
1313
|
+
Authorization: `Bearer ${D}`
|
|
1208
1314
|
},
|
|
1209
|
-
body: JSON.stringify({ query:
|
|
1315
|
+
body: JSON.stringify({ query: x })
|
|
1210
1316
|
});
|
|
1211
|
-
let
|
|
1212
|
-
if (
|
|
1213
|
-
|
|
1214
|
-
const
|
|
1215
|
-
|
|
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 (!
|
|
1218
|
-
if (!
|
|
1219
|
-
if (
|
|
1220
|
-
|
|
1323
|
+
if (!c()) return;
|
|
1324
|
+
if (!b.ok) {
|
|
1325
|
+
if (b.status === 402) {
|
|
1326
|
+
l(q);
|
|
1221
1327
|
return;
|
|
1222
1328
|
}
|
|
1223
|
-
|
|
1329
|
+
l("Something went wrong.");
|
|
1224
1330
|
return;
|
|
1225
1331
|
}
|
|
1226
|
-
const
|
|
1227
|
-
if (!
|
|
1228
|
-
|
|
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
|
-
|
|
1336
|
+
c() && l("Something went wrong.");
|
|
1231
1337
|
} finally {
|
|
1232
|
-
|
|
1338
|
+
c() && h(!1);
|
|
1233
1339
|
}
|
|
1234
1340
|
};
|
|
1235
|
-
return /* @__PURE__ */
|
|
1236
|
-
i && /* @__PURE__ */
|
|
1237
|
-
/* @__PURE__ */
|
|
1238
|
-
/* @__PURE__ */
|
|
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:
|
|
1243
|
-
onChange: (
|
|
1244
|
-
onKeyDown: (
|
|
1245
|
-
placeholder:
|
|
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:
|
|
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__ */
|
|
1363
|
+
/* @__PURE__ */ r(
|
|
1256
1364
|
"button",
|
|
1257
1365
|
{
|
|
1258
|
-
onClick:
|
|
1259
|
-
disabled:
|
|
1366
|
+
onClick: W,
|
|
1367
|
+
disabled: y,
|
|
1260
1368
|
style: {
|
|
1261
1369
|
padding: "8px 16px",
|
|
1262
1370
|
borderRadius: 6,
|
|
1263
1371
|
border: "none",
|
|
1264
|
-
background:
|
|
1265
|
-
color:
|
|
1372
|
+
background: p.sendBtnBg,
|
|
1373
|
+
color: p.sendBtnText,
|
|
1266
1374
|
cursor: "pointer",
|
|
1267
1375
|
fontSize: 14
|
|
1268
1376
|
},
|
|
1269
|
-
children:
|
|
1377
|
+
children: y ? "…" : "Ask"
|
|
1270
1378
|
}
|
|
1271
1379
|
)
|
|
1272
1380
|
] }),
|
|
1273
|
-
k && /* @__PURE__ */
|
|
1274
|
-
|
|
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:
|
|
1282
|
-
border:
|
|
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:
|
|
1395
|
+
children: B
|
|
1287
1396
|
}
|
|
1288
1397
|
),
|
|
1289
|
-
|
|
1290
|
-
/* @__PURE__ */
|
|
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
|
|
1402
|
+
function lt({
|
|
1294
1403
|
chatType: e,
|
|
1295
|
-
apiUrl: t =
|
|
1296
|
-
...
|
|
1404
|
+
apiUrl: t = we,
|
|
1405
|
+
...n
|
|
1297
1406
|
}) {
|
|
1298
1407
|
switch (e) {
|
|
1299
1408
|
case "floating":
|
|
1300
|
-
return /* @__PURE__ */
|
|
1409
|
+
return /* @__PURE__ */ r(He, { apiUrl: t, ...n });
|
|
1301
1410
|
case "embedded":
|
|
1302
|
-
return /* @__PURE__ */
|
|
1411
|
+
return /* @__PURE__ */ r(Ve, { apiUrl: t, ...n });
|
|
1303
1412
|
case "search":
|
|
1304
|
-
return /* @__PURE__ */
|
|
1413
|
+
return /* @__PURE__ */ r(it, { apiUrl: t, ...n });
|
|
1305
1414
|
}
|
|
1306
1415
|
}
|
|
1307
1416
|
export {
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
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
|
};
|