@icanbwell/baileyai-chat-ui 1.0.20 → 1.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/baileyai-chat-ui.cjs +2 -2
- package/dist/baileyai-chat-ui.js +359 -359
- package/dist/index.d.ts +3 -1
- package/package.json +1 -1
package/dist/baileyai-chat-ui.js
CHANGED
|
@@ -6,23 +6,23 @@ import * as h from "@radix-ui/react-dropdown-menu";
|
|
|
6
6
|
import * as g from "@radix-ui/react-tooltip";
|
|
7
7
|
import { Fragment as _, jsx as v, jsxs as y } from "react/jsx-runtime";
|
|
8
8
|
//#region src/utils/pseudoToolCalls.ts
|
|
9
|
-
var b = "search_tools|call_tool|function_calls|function_result",
|
|
10
|
-
function
|
|
11
|
-
let t =
|
|
9
|
+
var b = "search_tools|call_tool|function_calls|function_result", ee = RegExp(`<(${b})>([\\s\\S]*?)<\\/\\1>`, "g"), x = RegExp(`<(?:${b})>[\\s\\S]*$`), S = /<name>([\s\S]*?)<\/name>/, C = /<arguments>([\s\S]*?)<\/arguments>/, w = /<invoke\s+name="([^"]*)"\s*>([\s\S]*?)<\/invoke>/g, T = /<parameter\s+name="([^"]*)"\s*>([\s\S]*?)<\/parameter>/g;
|
|
10
|
+
function E(e) {
|
|
11
|
+
let t = S.exec(e)?.[1]?.trim() || "unknown_tool", n = C.exec(e)?.[1]?.trim();
|
|
12
12
|
return n ? {
|
|
13
13
|
name: t,
|
|
14
14
|
args: n
|
|
15
15
|
} : { name: t };
|
|
16
16
|
}
|
|
17
|
-
function
|
|
17
|
+
function D(e) {
|
|
18
18
|
let t = [];
|
|
19
|
-
|
|
19
|
+
w.lastIndex = 0;
|
|
20
20
|
let n;
|
|
21
|
-
for (; (n =
|
|
21
|
+
for (; (n = w.exec(e)) !== null;) {
|
|
22
22
|
let [, e, r] = n, i = {};
|
|
23
|
-
|
|
23
|
+
T.lastIndex = 0;
|
|
24
24
|
let a;
|
|
25
|
-
for (; (a =
|
|
25
|
+
for (; (a = T.exec(r)) !== null;) i[a[1]] = a[2].trim();
|
|
26
26
|
let o = e.trim() || "unknown_tool";
|
|
27
27
|
t.push(Object.keys(i).length > 0 ? {
|
|
28
28
|
name: o,
|
|
@@ -31,14 +31,14 @@ function O(e) {
|
|
|
31
31
|
}
|
|
32
32
|
return t;
|
|
33
33
|
}
|
|
34
|
-
function
|
|
35
|
-
let { hideOpenBlock: n = !0 } = t, r = [], i = e.replace(
|
|
34
|
+
function O(e, t = {}) {
|
|
35
|
+
let { hideOpenBlock: n = !0 } = t, r = [], i = e.replace(ee, (e, t, n) => (t === "call_tool" ? r.push(E(n)) : t === "search_tools" ? r.push({
|
|
36
36
|
name: "search_tools",
|
|
37
37
|
args: n.trim()
|
|
38
|
-
}) : t === "function_calls" ? r.push(...
|
|
38
|
+
}) : t === "function_calls" ? r.push(...D(n)) : r.push({
|
|
39
39
|
name: "function_result",
|
|
40
40
|
args: n.trim()
|
|
41
|
-
}), "")), a = n ? i.replace(
|
|
41
|
+
}), "")), a = n ? i.replace(x, "") : i;
|
|
42
42
|
return r.length === 0 && a === i ? {
|
|
43
43
|
cleanedText: i,
|
|
44
44
|
matches: r
|
|
@@ -49,7 +49,7 @@ function k(e, t = {}) {
|
|
|
49
49
|
}
|
|
50
50
|
//#endregion
|
|
51
51
|
//#region src/logic/sse.ts
|
|
52
|
-
function
|
|
52
|
+
function te(e) {
|
|
53
53
|
if (!e.startsWith("data: ")) return e;
|
|
54
54
|
let t = "";
|
|
55
55
|
for (let n of e.split("\n")) {
|
|
@@ -63,7 +63,7 @@ function ee(e) {
|
|
|
63
63
|
}
|
|
64
64
|
return t || null;
|
|
65
65
|
}
|
|
66
|
-
function
|
|
66
|
+
function k(e) {
|
|
67
67
|
let t = e.replace(/\r\n/g, "\n").split("\n\n"), n = t.pop() ?? "", r = [], i = !1;
|
|
68
68
|
for (let e of t) {
|
|
69
69
|
let t = e.split("\n").filter((e) => e.length > 0), n = "message", a = [];
|
|
@@ -88,7 +88,7 @@ function A(e) {
|
|
|
88
88
|
message: e
|
|
89
89
|
});
|
|
90
90
|
} else if (c?.type === "response.output_text.delta" && typeof c.delta == "string") {
|
|
91
|
-
let e =
|
|
91
|
+
let e = te(c.delta);
|
|
92
92
|
e && r.push({
|
|
93
93
|
type: "response.output_text.delta",
|
|
94
94
|
delta: e
|
|
@@ -106,27 +106,27 @@ function A(e) {
|
|
|
106
106
|
}
|
|
107
107
|
//#endregion
|
|
108
108
|
//#region src/utils/mapTranscript.ts
|
|
109
|
-
var
|
|
109
|
+
var A = {
|
|
110
110
|
inaccurate: !0,
|
|
111
111
|
unhelpful: !0,
|
|
112
112
|
unsafe: !0,
|
|
113
113
|
too_long: !0,
|
|
114
114
|
other: !0
|
|
115
|
-
},
|
|
116
|
-
function
|
|
115
|
+
}, j = (e) => Object.hasOwn(A, e) ? e : "other";
|
|
116
|
+
function M(e) {
|
|
117
117
|
if (!e || e.rating !== "up" && e.rating !== "down") return;
|
|
118
|
-
let t = (e.reasonCodes ?? []).map(
|
|
118
|
+
let t = (e.reasonCodes ?? []).map(j);
|
|
119
119
|
return {
|
|
120
120
|
rating: e.rating,
|
|
121
121
|
...t.length > 0 ? { reasonCodes: t } : {},
|
|
122
122
|
...e.comment ? { comment: e.comment } : {}
|
|
123
123
|
};
|
|
124
124
|
}
|
|
125
|
-
function
|
|
125
|
+
function N(e) {
|
|
126
126
|
let t = [];
|
|
127
127
|
return e.messages.forEach((e, n) => {
|
|
128
128
|
if (e.hidden || e.role !== "user" && e.role !== "assistant") return;
|
|
129
|
-
let r = Date.parse(e.createdAt), i = Number.isNaN(r) ? void 0 : r, a = e.messageId || `loaded-${n}-${e.role}-${i ?? 0}`, o = e.role === "assistant" ?
|
|
129
|
+
let r = Date.parse(e.createdAt), i = Number.isNaN(r) ? void 0 : r, a = e.messageId || `loaded-${n}-${e.role}-${i ?? 0}`, o = e.role === "assistant" ? M(e.feedback) : void 0;
|
|
130
130
|
t.push({
|
|
131
131
|
id: a,
|
|
132
132
|
role: e.role,
|
|
@@ -171,12 +171,12 @@ function F() {
|
|
|
171
171
|
}
|
|
172
172
|
//#endregion
|
|
173
173
|
//#region src/logic/useBaileyChat.ts
|
|
174
|
-
var
|
|
174
|
+
var oe = 200, se = 100, I = 15e4, L = () => typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : `bailey-${Date.now()}-${Math.random().toString(36).slice(2)}`, ce = (e, t, n) => {
|
|
175
175
|
if (e === 401 || e === 403) return "Bailey isn't reachable with your current login.";
|
|
176
176
|
let r = `Bailey request failed (status ${e ?? "network error"}).`, i = (n || t || "").trim();
|
|
177
|
-
return i ? `${r} ${i.length >
|
|
177
|
+
return i ? `${r} ${i.length > oe ? `${i.slice(0, oe)}…` : i}` : r;
|
|
178
178
|
};
|
|
179
|
-
function
|
|
179
|
+
function R(e, t, n) {
|
|
180
180
|
if (e) try {
|
|
181
181
|
return e.get(t) || void 0;
|
|
182
182
|
} catch (e) {
|
|
@@ -194,91 +194,91 @@ function ue(e, t, n, r) {
|
|
|
194
194
|
r(e, "write");
|
|
195
195
|
}
|
|
196
196
|
}
|
|
197
|
-
function
|
|
197
|
+
function de(e, t, n) {
|
|
198
198
|
try {
|
|
199
199
|
e?.remove(t);
|
|
200
200
|
} catch (e) {
|
|
201
201
|
n(e, "remove");
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
|
-
var
|
|
205
|
-
function
|
|
204
|
+
var z = (e, t) => t ? `${e}:${t}` : e;
|
|
205
|
+
function fe(e) {
|
|
206
206
|
let { seed: t, sub: n, storage: r, key: i, report: a } = e;
|
|
207
|
-
if (!n) return t ||
|
|
207
|
+
if (!n) return t || R(r, i, a);
|
|
208
208
|
if (t && re({
|
|
209
209
|
conversationId: t,
|
|
210
210
|
sub: n
|
|
211
211
|
})) return t;
|
|
212
|
-
let o =
|
|
212
|
+
let o = R(r, i, a);
|
|
213
213
|
if (o) {
|
|
214
214
|
if (re({
|
|
215
215
|
conversationId: o,
|
|
216
216
|
sub: n
|
|
217
217
|
})) return o;
|
|
218
|
-
|
|
218
|
+
de(r, i, a);
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
|
-
var
|
|
222
|
-
let [
|
|
221
|
+
var B = ({ transport: e, model: t, instructions: n, tools: r = [], toolChoice: i, firstUserMessagePrefix: o, onAssistantMessageComplete: c, idleTimeoutMs: l = I, client: p, conversationId: m, sub: h, storage: g, storageKey: _ = ie, sendFullTranscript: v = !1, onStorageError: y, onContextLoss: b }) => {
|
|
222
|
+
let [ee, x] = f([]), [S, C] = f([]), [w, T] = f(null), [E, D] = f("idle"), [te, A] = f(null), j = h !== void 0 && h.trim() === "", M = j ? void 0 : h?.trim() || void 0, P = u(() => ae(), []), F = j ? null : g === void 0 ? P : g || null, oe = d(y), R = d(b);
|
|
223
223
|
s(() => {
|
|
224
|
-
|
|
224
|
+
oe.current = y, R.current = b;
|
|
225
225
|
}, [y, b]);
|
|
226
|
-
let
|
|
226
|
+
let B = a((e, t) => {
|
|
227
227
|
try {
|
|
228
|
-
|
|
228
|
+
oe.current?.(e, t);
|
|
229
229
|
} catch {}
|
|
230
|
-
}, []),
|
|
230
|
+
}, []), V = (e) => fe({
|
|
231
231
|
seed: m,
|
|
232
|
-
sub:
|
|
232
|
+
sub: M,
|
|
233
233
|
storage: F,
|
|
234
|
-
key:
|
|
234
|
+
key: z(_, M),
|
|
235
235
|
report: e
|
|
236
|
-
}), [
|
|
236
|
+
}), [H] = f(() => {
|
|
237
237
|
let e = [];
|
|
238
238
|
return {
|
|
239
|
-
id:
|
|
239
|
+
id: V((t, n) => void e.push({
|
|
240
240
|
error: t,
|
|
241
241
|
operation: n
|
|
242
242
|
})),
|
|
243
243
|
errors: e
|
|
244
244
|
};
|
|
245
|
-
}), [
|
|
246
|
-
|
|
247
|
-
}, [
|
|
245
|
+
}), [U, pe] = f(H.id), [me, W] = f(H.errors.length > 0), G = a((e, t) => {
|
|
246
|
+
W(!0), B(e, t);
|
|
247
|
+
}, [B]);
|
|
248
248
|
s(() => {
|
|
249
|
-
|
|
250
|
-
}, [
|
|
251
|
-
|
|
252
|
-
}, [
|
|
253
|
-
let K = d(
|
|
249
|
+
H.errors.forEach(({ error: e, operation: t }) => B(e, t));
|
|
250
|
+
}, [H, B]), s(() => {
|
|
251
|
+
j && B(/* @__PURE__ */ Error("sub is blank"), "key");
|
|
252
|
+
}, [j, B]);
|
|
253
|
+
let K = d(U), q = d({
|
|
254
254
|
storage: F,
|
|
255
|
-
key:
|
|
256
|
-
sub:
|
|
255
|
+
key: z(_, M),
|
|
256
|
+
sub: M,
|
|
257
257
|
sendFullTranscript: v
|
|
258
258
|
});
|
|
259
259
|
s(() => {
|
|
260
260
|
q.current = {
|
|
261
261
|
storage: F,
|
|
262
|
-
key:
|
|
263
|
-
sub:
|
|
262
|
+
key: z(_, M),
|
|
263
|
+
sub: M,
|
|
264
264
|
sendFullTranscript: v
|
|
265
265
|
};
|
|
266
266
|
}, [
|
|
267
267
|
F,
|
|
268
268
|
_,
|
|
269
|
-
|
|
269
|
+
M,
|
|
270
270
|
v
|
|
271
271
|
]);
|
|
272
|
-
let he = g === !1 ? "off" :
|
|
273
|
-
|
|
272
|
+
let he = g === !1 ? "off" : me || j ? "degraded" : "ok", [ge, _e] = f(!1), [ve, J] = f("idle"), [ye, be] = f(!1), Y = d(0), xe = d(null), Se = d(null), X = d(!1), Z = a(() => {
|
|
273
|
+
Y.current += 1, xe.current?.abort(), xe.current = null, Se.current = null, X.current = !1, be(!1), J("idle");
|
|
274
274
|
}, []), Ce = d(p);
|
|
275
275
|
s(() => {
|
|
276
276
|
Ce.current = p;
|
|
277
|
-
}, [p]), s(() => () =>
|
|
277
|
+
}, [p]), s(() => () => xe.current?.abort(), []);
|
|
278
278
|
let we = d(null), Te = d(""), Ee = d(0), De = d([]);
|
|
279
279
|
s(() => {
|
|
280
|
-
De.current =
|
|
281
|
-
}, [
|
|
280
|
+
De.current = ee;
|
|
281
|
+
}, [ee]);
|
|
282
282
|
let Q = d([]), Oe = d(/* @__PURE__ */ new Map()), ke = d(/* @__PURE__ */ new Map()), Ae = d(null), je = a(() => {
|
|
283
283
|
Ae.current !== null && (clearTimeout(Ae.current), Ae.current = null);
|
|
284
284
|
}, []), Me = a((e) => {
|
|
@@ -299,10 +299,10 @@ var V = ({ transport: e, model: t, instructions: n, tools: r = [], toolChoice: i
|
|
|
299
299
|
r && !re({
|
|
300
300
|
conversationId: e,
|
|
301
301
|
sub: r
|
|
302
|
-
}) || (K.current = e,
|
|
302
|
+
}) || (K.current = e, pe(e), ue(i, a, e, G));
|
|
303
303
|
}, [G]), Ne = a((e, t, n, r) => {
|
|
304
304
|
let i = (e) => {
|
|
305
|
-
n.push(e),
|
|
305
|
+
n.push(e), C((t) => [...t, e]);
|
|
306
306
|
};
|
|
307
307
|
if (t.type === "response.output_text.delta") {
|
|
308
308
|
if (!t.delta) return !1;
|
|
@@ -311,8 +311,8 @@ var V = ({ transport: e, model: t, instructions: n, tools: r = [], toolChoice: i
|
|
|
311
311
|
emittedCount: 0
|
|
312
312
|
};
|
|
313
313
|
n.raw += t.delta;
|
|
314
|
-
let { cleanedText: r, matches: a } =
|
|
315
|
-
if (n.emittedCount = a.length, Oe.current.set(e, n), ke.current.set(e, o),
|
|
314
|
+
let { cleanedText: r, matches: a } = O(n.raw), o = r.trim(), s = a.slice(n.emittedCount);
|
|
315
|
+
if (n.emittedCount = a.length, Oe.current.set(e, n), ke.current.set(e, o), x((t) => t.map((t) => t.id === e ? {
|
|
316
316
|
...t,
|
|
317
317
|
content: o
|
|
318
318
|
} : t)), s.length > 0) {
|
|
@@ -329,7 +329,7 @@ var V = ({ transport: e, model: t, instructions: n, tools: r = [], toolChoice: i
|
|
|
329
329
|
}
|
|
330
330
|
if (t.type === "response.output_item.added" || t.type === "response.output_item.done") {
|
|
331
331
|
let n = t.item;
|
|
332
|
-
if (n.type === "output_image") return n.image_url &&
|
|
332
|
+
if (n.type === "output_image") return n.image_url && x((t) => t.map((t) => t.id === e ? {
|
|
333
333
|
...t,
|
|
334
334
|
parts: [...t.parts ?? [], {
|
|
335
335
|
type: "image",
|
|
@@ -396,14 +396,14 @@ var V = ({ transport: e, model: t, instructions: n, tools: r = [], toolChoice: i
|
|
|
396
396
|
turn: r
|
|
397
397
|
}), le(t.response?.conversation?.history_status, r);
|
|
398
398
|
let n = typeof t.message_id == "string" && t.message_id ? t.message_id : void 0;
|
|
399
|
-
n &&
|
|
399
|
+
n && x((t) => t.map((t) => t.id === e ? {
|
|
400
400
|
...t,
|
|
401
401
|
serverMessageId: n
|
|
402
402
|
} : t));
|
|
403
403
|
let i = Oe.current.get(e);
|
|
404
404
|
if (i) {
|
|
405
|
-
let { cleanedText: t } =
|
|
406
|
-
n !== ke.current.get(e) && (ke.current.set(e, n),
|
|
405
|
+
let { cleanedText: t } = O(i.raw, { hideOpenBlock: !1 }), n = t.trim();
|
|
406
|
+
n !== ke.current.get(e) && (ke.current.set(e, n), x((t) => t.map((t) => t.id === e ? {
|
|
407
407
|
...t,
|
|
408
408
|
content: n
|
|
409
409
|
} : t)));
|
|
@@ -426,7 +426,7 @@ var V = ({ transport: e, model: t, instructions: n, tools: r = [], toolChoice: i
|
|
|
426
426
|
turnSentAt: Ee.current
|
|
427
427
|
}), !0;
|
|
428
428
|
let { html: r, title: a, csp: o, permissions: s, prefersBorder: c, displayMode: l } = t;
|
|
429
|
-
return
|
|
429
|
+
return x((t) => t.map((t) => t.id === e ? {
|
|
430
430
|
...t,
|
|
431
431
|
parts: [...t.parts ?? [], {
|
|
432
432
|
type: "mcp_app",
|
|
@@ -448,17 +448,17 @@ var V = ({ transport: e, model: t, instructions: n, tools: r = [], toolChoice: i
|
|
|
448
448
|
turnSentAt: Ee.current
|
|
449
449
|
}), !0;
|
|
450
450
|
}, [$]), Pe = a(async (a) => {
|
|
451
|
-
|
|
451
|
+
D("streaming"), A(null), _e(!1);
|
|
452
452
|
let s = Date.now();
|
|
453
453
|
Ee.current = s;
|
|
454
|
-
let l =
|
|
454
|
+
let l = L(), u = {
|
|
455
455
|
id: l,
|
|
456
456
|
role: "assistant",
|
|
457
457
|
content: "",
|
|
458
458
|
streaming: !0,
|
|
459
459
|
createdAt: s
|
|
460
460
|
};
|
|
461
|
-
|
|
461
|
+
x((e) => [...e, u]), Q.current = [...a, u];
|
|
462
462
|
let d = a.findIndex((e) => e.role === "user" && !e.hidden), f = a.map((e, t) => t === d && o ? {
|
|
463
463
|
role: e.role,
|
|
464
464
|
content: `${o}${e.content}`,
|
|
@@ -470,7 +470,7 @@ var V = ({ transport: e, model: t, instructions: n, tools: r = [], toolChoice: i
|
|
|
470
470
|
hidden: e.hidden,
|
|
471
471
|
titleHint: e.titleHint
|
|
472
472
|
}), { sendFullTranscript: p } = q.current, m = p ? void 0 : K.current, h = m ? f.slice(-1) : f;
|
|
473
|
-
|
|
473
|
+
T({
|
|
474
474
|
model: t,
|
|
475
475
|
systemPrompt: n,
|
|
476
476
|
messages: h,
|
|
@@ -489,8 +489,8 @@ var V = ({ transport: e, model: t, instructions: n, tools: r = [], toolChoice: i
|
|
|
489
489
|
let _ = {
|
|
490
490
|
signal: g.signal,
|
|
491
491
|
heldId: m
|
|
492
|
-
}, v = "", y = null, b = !1,
|
|
493
|
-
|
|
492
|
+
}, v = "", y = null, b = !1, ee = !1, S = !1, w = [], E = (e, t) => {
|
|
493
|
+
D("error"), A(e);
|
|
494
494
|
let n = {
|
|
495
495
|
kind: "error",
|
|
496
496
|
message: e,
|
|
@@ -498,8 +498,8 @@ var V = ({ transport: e, model: t, instructions: n, tools: r = [], toolChoice: i
|
|
|
498
498
|
turnSentAt: s,
|
|
499
499
|
...t
|
|
500
500
|
};
|
|
501
|
-
|
|
502
|
-
},
|
|
501
|
+
w.push(n), C((e) => [...e, n]);
|
|
502
|
+
}, O = (e, t) => {
|
|
503
503
|
e.forEach((e) => {
|
|
504
504
|
if (e.type === "error") {
|
|
505
505
|
y = e.message;
|
|
@@ -509,11 +509,11 @@ var V = ({ transport: e, model: t, instructions: n, tools: r = [], toolChoice: i
|
|
|
509
509
|
at: Date.now(),
|
|
510
510
|
turnSentAt: s
|
|
511
511
|
};
|
|
512
|
-
|
|
512
|
+
w.push(t), C((e) => [...e, t]);
|
|
513
513
|
return;
|
|
514
514
|
}
|
|
515
|
-
e.type === "response.output_text.delta" && e.delta && (
|
|
516
|
-
}), t && (b = !0,
|
|
515
|
+
e.type === "response.output_text.delta" && e.delta && (S = !0), Ne(l, e, w, _) && (ee = !0);
|
|
516
|
+
}), t && (b = !0, x((e) => e.map((e) => e.id === l ? {
|
|
517
517
|
...e,
|
|
518
518
|
streaming: !1
|
|
519
519
|
} : e)));
|
|
@@ -534,10 +534,10 @@ var V = ({ transport: e, model: t, instructions: n, tools: r = [], toolChoice: i
|
|
|
534
534
|
signal: g.signal,
|
|
535
535
|
onChunk: (e) => {
|
|
536
536
|
Me(g), v += e;
|
|
537
|
-
let { events: t, remainder: n, done: r } =
|
|
538
|
-
v = n,
|
|
537
|
+
let { events: t, remainder: n, done: r } = k(v);
|
|
538
|
+
v = n, O(t, r);
|
|
539
539
|
let i = Date.now();
|
|
540
|
-
|
|
540
|
+
T((e) => e && e.sentAt === s ? {
|
|
541
541
|
...e,
|
|
542
542
|
streamStats: {
|
|
543
543
|
chunkCount: e.streamStats.chunkCount + 1,
|
|
@@ -547,88 +547,88 @@ var V = ({ transport: e, model: t, instructions: n, tools: r = [], toolChoice: i
|
|
|
547
547
|
} : e);
|
|
548
548
|
},
|
|
549
549
|
onRequestId: (e) => {
|
|
550
|
-
|
|
550
|
+
T((t) => t && t.sentAt === s ? {
|
|
551
551
|
...t,
|
|
552
552
|
requestId: e
|
|
553
553
|
} : t);
|
|
554
554
|
},
|
|
555
555
|
onMessageId: (e) => {
|
|
556
|
-
typeof e == "string" && e &&
|
|
556
|
+
typeof e == "string" && e && x((t) => t.map((t) => t.id === l ? {
|
|
557
557
|
...t,
|
|
558
558
|
serverMessageId: e
|
|
559
559
|
} : t));
|
|
560
560
|
}
|
|
561
561
|
});
|
|
562
562
|
if (v.trim()) {
|
|
563
|
-
let { events: e, done: t } =
|
|
564
|
-
v = "",
|
|
563
|
+
let { events: e, done: t } = k(`${v}\n\n`);
|
|
564
|
+
v = "", O(e, t);
|
|
565
565
|
}
|
|
566
566
|
if (y) {
|
|
567
|
-
|
|
567
|
+
D("error"), A(y);
|
|
568
568
|
return;
|
|
569
569
|
}
|
|
570
570
|
if (d === "timeout" && !b) {
|
|
571
|
-
|
|
571
|
+
E(u || "The assistant took too long to respond. Please try again.", { source: "client-timeout" });
|
|
572
572
|
return;
|
|
573
573
|
}
|
|
574
574
|
if (f && !b) {
|
|
575
|
-
|
|
575
|
+
E("The connection was interrupted before the answer finished. Try again.");
|
|
576
576
|
return;
|
|
577
577
|
}
|
|
578
578
|
if (a === void 0 || a >= 400) {
|
|
579
|
-
|
|
579
|
+
E(ce(a, o, u), {
|
|
580
580
|
httpStatus: a,
|
|
581
581
|
rawBody: o || void 0
|
|
582
582
|
});
|
|
583
583
|
return;
|
|
584
584
|
}
|
|
585
|
-
let p = _.reportedId,
|
|
586
|
-
if (m && !_.signal.aborted && (
|
|
587
|
-
K.current = void 0,
|
|
585
|
+
let p = _.reportedId, C = p !== m, te = _.historyStatus === "failed" || _.historyStatus === "empty";
|
|
586
|
+
if (m && !_.signal.aborted && (C || te)) {
|
|
587
|
+
K.current = void 0, pe(void 0), de(q.current.storage, q.current.key, G), Z(), _e(!0);
|
|
588
588
|
try {
|
|
589
|
-
|
|
589
|
+
R.current?.({
|
|
590
590
|
sentId: m,
|
|
591
591
|
...p ? { reportedId: p } : {},
|
|
592
|
-
reason:
|
|
592
|
+
reason: C ? "id" : "history"
|
|
593
593
|
});
|
|
594
594
|
} catch {}
|
|
595
595
|
}
|
|
596
|
-
if (!
|
|
597
|
-
|
|
596
|
+
if (!ee) {
|
|
597
|
+
E("Bailey returned an empty response.");
|
|
598
598
|
return;
|
|
599
599
|
}
|
|
600
|
-
if (!
|
|
601
|
-
|
|
600
|
+
if (!S) {
|
|
601
|
+
E("Bailey ran some tools but didn't return an answer. Try asking again.");
|
|
602
602
|
return;
|
|
603
603
|
}
|
|
604
|
-
|
|
605
|
-
let
|
|
606
|
-
|
|
604
|
+
D("idle");
|
|
605
|
+
let j = ke.current.get(l) ?? "";
|
|
606
|
+
T((e) => e && e.sentAt === s ? {
|
|
607
607
|
...e,
|
|
608
|
-
response: { content:
|
|
608
|
+
response: { content: j }
|
|
609
609
|
} : e), c && await c({
|
|
610
610
|
id: l,
|
|
611
611
|
role: "assistant",
|
|
612
|
-
content:
|
|
612
|
+
content: j,
|
|
613
613
|
streaming: !1
|
|
614
|
-
},
|
|
614
|
+
}, w);
|
|
615
615
|
} catch (e) {
|
|
616
616
|
let t = e;
|
|
617
617
|
if (t?.name === "TimeoutError") {
|
|
618
|
-
|
|
618
|
+
E(t.message, { source: "client-timeout" });
|
|
619
619
|
return;
|
|
620
620
|
}
|
|
621
621
|
if (t?.name === "AbortError") {
|
|
622
|
-
|
|
622
|
+
D("idle");
|
|
623
623
|
return;
|
|
624
624
|
}
|
|
625
|
-
|
|
625
|
+
E(t?.message || "Bailey request failed.");
|
|
626
626
|
} finally {
|
|
627
627
|
je();
|
|
628
628
|
let e = ke.current.get(l) ?? "";
|
|
629
629
|
Oe.current.delete(l), ke.current.delete(l);
|
|
630
|
-
let t =
|
|
631
|
-
|
|
630
|
+
let t = w.some((e) => e.kind === "tool_start" || e.kind === "tool_end");
|
|
631
|
+
x((e) => e.flatMap((e) => e.id === l ? e.content || t ? [{
|
|
632
632
|
...e,
|
|
633
633
|
streaming: !1
|
|
634
634
|
}] : [] : [e])), Q.current = Q.current.flatMap((t) => t.id === l ? e ? [{
|
|
@@ -652,25 +652,25 @@ var V = ({ transport: e, model: t, instructions: n, tools: r = [], toolChoice: i
|
|
|
652
652
|
G,
|
|
653
653
|
Z
|
|
654
654
|
]), Fe = a((e) => {
|
|
655
|
-
De.current = e,
|
|
655
|
+
De.current = e, x(e);
|
|
656
656
|
}, []), Ie = a((e) => {
|
|
657
657
|
let t = e.trim();
|
|
658
658
|
if (!t) return;
|
|
659
659
|
Te.current = t;
|
|
660
660
|
let n = {
|
|
661
|
-
id:
|
|
661
|
+
id: L(),
|
|
662
662
|
role: "user",
|
|
663
663
|
content: t,
|
|
664
664
|
createdAt: Date.now()
|
|
665
665
|
}, r = [...Q.current, n];
|
|
666
666
|
Q.current = r, Fe([...De.current, n]), Pe(r);
|
|
667
667
|
}, [Pe, Fe]), Le = a((e, t) => {
|
|
668
|
-
if (
|
|
668
|
+
if (E === "streaming") return;
|
|
669
669
|
let n = e.trim();
|
|
670
670
|
if (!n) return;
|
|
671
671
|
Te.current = n;
|
|
672
672
|
let r = t?.trim(), i = {
|
|
673
|
-
id:
|
|
673
|
+
id: L(),
|
|
674
674
|
role: "user",
|
|
675
675
|
content: n,
|
|
676
676
|
createdAt: Date.now(),
|
|
@@ -678,10 +678,10 @@ var V = ({ transport: e, model: t, instructions: n, tools: r = [], toolChoice: i
|
|
|
678
678
|
...r ? { titleHint: r } : {}
|
|
679
679
|
}, a = [...Q.current, i];
|
|
680
680
|
Q.current = a, Pe(a);
|
|
681
|
-
}, [Pe,
|
|
681
|
+
}, [Pe, E]), Re = a(() => {
|
|
682
682
|
we.current?.abort();
|
|
683
683
|
}, []), ze = a(() => {
|
|
684
|
-
if (
|
|
684
|
+
if (E === "streaming" || !Te.current) return;
|
|
685
685
|
let e = De.current, t = e[e.length - 1], n = t && t.role === "assistant" ? e.slice(0, -1) : e;
|
|
686
686
|
Fe(n);
|
|
687
687
|
let r = Q.current, i = r[r.length - 1], a = i && i.role === "assistant" ? r.slice(0, -1) : r;
|
|
@@ -689,45 +689,45 @@ var V = ({ transport: e, model: t, instructions: n, tools: r = [], toolChoice: i
|
|
|
689
689
|
}, [
|
|
690
690
|
Pe,
|
|
691
691
|
Fe,
|
|
692
|
-
|
|
693
|
-
]), Be = a(() =>
|
|
694
|
-
|
|
692
|
+
E
|
|
693
|
+
]), Be = a(() => C([]), []), Ve = a(() => {
|
|
694
|
+
A(null), D((e) => e === "error" ? "idle" : e);
|
|
695
695
|
}, []), He = a(() => {
|
|
696
|
-
we.current?.abort(), Z(), _e(!1), Fe([]), Q.current = [],
|
|
696
|
+
we.current?.abort(), Z(), _e(!1), Fe([]), Q.current = [], C([]), T(null), D("idle"), A(null), Te.current = "";
|
|
697
697
|
}, [Z, Fe]), Ue = a(() => {
|
|
698
|
-
He(), K.current = void 0,
|
|
699
|
-
}, [He, G]), We = d(
|
|
698
|
+
He(), K.current = void 0, pe(void 0), de(q.current.storage, q.current.key, G);
|
|
699
|
+
}, [He, G]), We = d(M);
|
|
700
700
|
s(() => {
|
|
701
701
|
let e = We.current;
|
|
702
|
-
if (e ===
|
|
703
|
-
We.current =
|
|
704
|
-
let t =
|
|
705
|
-
K.current = t,
|
|
706
|
-
}, [
|
|
702
|
+
if (e === M) return;
|
|
703
|
+
We.current = M, e !== void 0 && He();
|
|
704
|
+
let t = V(G);
|
|
705
|
+
K.current = t, pe(t);
|
|
706
|
+
}, [M]);
|
|
707
707
|
let Ge = a((e) => {
|
|
708
708
|
we.current?.abort();
|
|
709
709
|
let t = e.filter((e) => e.role === "user" || e.role === "assistant").map((e) => ({
|
|
710
710
|
...e,
|
|
711
711
|
streaming: !1
|
|
712
712
|
}));
|
|
713
|
-
Fe(t.filter((e) => !e.hidden)), Q.current = t,
|
|
713
|
+
Fe(t.filter((e) => !e.hidden)), Q.current = t, C([]), T(null), D("idle"), A(null), Te.current = "";
|
|
714
714
|
}, [Fe]), Ke = a((e) => {
|
|
715
715
|
Z(), Ge(e);
|
|
716
716
|
}, [Z, Ge]), qe = a((e) => {
|
|
717
|
-
K.current = e,
|
|
717
|
+
K.current = e, pe(e), ue(q.current.storage, q.current.key, e, G), _e(!1);
|
|
718
718
|
}, [G]), Je = a((e) => {
|
|
719
719
|
let t = e.hasMoreBefore && e.nextBeforeAbsoluteIndex !== null;
|
|
720
|
-
|
|
720
|
+
Se.current = t ? e.nextBeforeAbsoluteIndex : null, be(t);
|
|
721
721
|
}, []);
|
|
722
722
|
return {
|
|
723
|
-
conversationId:
|
|
723
|
+
conversationId: U,
|
|
724
724
|
persistence: he,
|
|
725
725
|
contextLost: ge,
|
|
726
|
-
messages:
|
|
727
|
-
traceEvents:
|
|
728
|
-
lastRequest:
|
|
729
|
-
status:
|
|
730
|
-
error:
|
|
726
|
+
messages: ee,
|
|
727
|
+
traceEvents: S,
|
|
728
|
+
lastRequest: w,
|
|
729
|
+
status: E,
|
|
730
|
+
error: te,
|
|
731
731
|
send: Ie,
|
|
732
732
|
sendHidden: Le,
|
|
733
733
|
stop: Re,
|
|
@@ -743,18 +743,18 @@ var V = ({ transport: e, model: t, instructions: n, tools: r = [], toolChoice: i
|
|
|
743
743
|
}));
|
|
744
744
|
if (!t || !r) throw J("error"), Error(t ? "invalid conversation id" : "no client");
|
|
745
745
|
we.current?.abort(), Z();
|
|
746
|
-
let i =
|
|
747
|
-
|
|
746
|
+
let i = Y.current, a = new AbortController();
|
|
747
|
+
xe.current = a, J("loading");
|
|
748
748
|
try {
|
|
749
749
|
let n = await t.getConversation({
|
|
750
750
|
conversationId: e,
|
|
751
|
-
limit:
|
|
751
|
+
limit: se,
|
|
752
752
|
signal: a.signal
|
|
753
753
|
});
|
|
754
|
-
if (i !==
|
|
755
|
-
Ge(
|
|
754
|
+
if (i !== Y.current) return;
|
|
755
|
+
Ge(N({ messages: n.messages })), qe(e), Je(n), J("idle");
|
|
756
756
|
} catch (e) {
|
|
757
|
-
if (i !==
|
|
757
|
+
if (i !== Y.current) return;
|
|
758
758
|
throw J("error"), e;
|
|
759
759
|
}
|
|
760
760
|
}, [
|
|
@@ -764,23 +764,23 @@ var V = ({ transport: e, model: t, instructions: n, tools: r = [], toolChoice: i
|
|
|
764
764
|
Ge
|
|
765
765
|
]),
|
|
766
766
|
loadEarlier: a(async () => {
|
|
767
|
-
let e = Ce.current, t = K.current, n =
|
|
768
|
-
if (!e || !t || n === null ||
|
|
769
|
-
let r =
|
|
770
|
-
|
|
767
|
+
let e = Ce.current, t = K.current, n = Se.current;
|
|
768
|
+
if (!e || !t || n === null || X.current) return;
|
|
769
|
+
let r = Y.current, i = new AbortController();
|
|
770
|
+
xe.current = i, X.current = !0, J("loading");
|
|
771
771
|
try {
|
|
772
772
|
let a = await e.getConversation({
|
|
773
773
|
conversationId: t,
|
|
774
|
-
limit:
|
|
774
|
+
limit: se,
|
|
775
775
|
beforeAbsoluteIndex: n,
|
|
776
776
|
signal: i.signal
|
|
777
777
|
});
|
|
778
|
-
if (r !==
|
|
779
|
-
let o =
|
|
778
|
+
if (r !== Y.current) return;
|
|
779
|
+
let o = N({ messages: a.messages });
|
|
780
780
|
Q.current = ne({
|
|
781
781
|
current: Q.current,
|
|
782
782
|
earlier: o
|
|
783
|
-
}),
|
|
783
|
+
}), x((e) => {
|
|
784
784
|
let t = ne({
|
|
785
785
|
current: e,
|
|
786
786
|
earlier: o
|
|
@@ -788,23 +788,23 @@ var V = ({ transport: e, model: t, instructions: n, tools: r = [], toolChoice: i
|
|
|
788
788
|
return De.current = t, t;
|
|
789
789
|
}), Je(a), J("idle");
|
|
790
790
|
} catch (e) {
|
|
791
|
-
if (r !==
|
|
791
|
+
if (r !== Y.current) return;
|
|
792
792
|
throw J("error"), e;
|
|
793
793
|
} finally {
|
|
794
|
-
r ===
|
|
794
|
+
r === Y.current && (X.current = !1);
|
|
795
795
|
}
|
|
796
796
|
}, [Je]),
|
|
797
797
|
hasEarlier: ye,
|
|
798
798
|
historyStatus: ve
|
|
799
799
|
};
|
|
800
|
-
},
|
|
800
|
+
}, V = class extends Error {
|
|
801
801
|
status;
|
|
802
802
|
kind;
|
|
803
803
|
constructor(e) {
|
|
804
|
-
super(e.message ??
|
|
804
|
+
super(e.message ?? H(e), e.cause === void 0 ? void 0 : { cause: e.cause }), this.name = "BaileyApiError", this.status = e.status, this.kind = e.kind;
|
|
805
805
|
}
|
|
806
806
|
};
|
|
807
|
-
function
|
|
807
|
+
function H(e) {
|
|
808
808
|
switch (e.kind) {
|
|
809
809
|
case "http": return `Bailey request failed (status ${e.status})`;
|
|
810
810
|
case "timeout": return "Bailey request timed out";
|
|
@@ -813,16 +813,16 @@ function U(e) {
|
|
|
813
813
|
default: return "Bailey request failed (network error)";
|
|
814
814
|
}
|
|
815
815
|
}
|
|
816
|
-
var
|
|
816
|
+
var U = class extends Error {
|
|
817
817
|
operation;
|
|
818
818
|
constructor(e) {
|
|
819
819
|
super(`Bailey cleanup failed (${e.operation})`), this.name = "BaileyCleanupError", this.operation = e.operation;
|
|
820
820
|
}
|
|
821
|
-
},
|
|
821
|
+
}, pe = (e) => e instanceof V ? e : new V({
|
|
822
822
|
status: 0,
|
|
823
823
|
kind: "network"
|
|
824
824
|
});
|
|
825
|
-
function
|
|
825
|
+
function me(e) {
|
|
826
826
|
let { pageSize: t, enabled: n = !0 } = e, [r, i] = f([]), [o, c] = f(n ? "loading" : "idle"), [l, u] = f(null), [p, m] = f(null), h = d(e.client), g = d([]);
|
|
827
827
|
s(() => {
|
|
828
828
|
h.current = e.client, g.current = r;
|
|
@@ -845,15 +845,15 @@ function pe(e) {
|
|
|
845
845
|
}), _.current = r.nextCursor, m(r.nextCursor), u(null), c("idle");
|
|
846
846
|
} catch (e) {
|
|
847
847
|
if (n.signal.aborted) return;
|
|
848
|
-
u(
|
|
848
|
+
u(pe(e)), c("error");
|
|
849
849
|
}
|
|
850
850
|
}, [t]);
|
|
851
851
|
s(() => {
|
|
852
852
|
if (n) return y("replace"), () => v.current?.abort();
|
|
853
853
|
}, [n, y]);
|
|
854
|
-
let b = a(() => y("replace"), [y]),
|
|
854
|
+
let b = a(() => y("replace"), [y]), ee = a(async () => {
|
|
855
855
|
_.current !== null && await y("append");
|
|
856
|
-
}, [y]),
|
|
856
|
+
}, [y]), x = a(async ({ conversationId: e }) => {
|
|
857
857
|
let t = g.current.findIndex((t) => t.conversationId === e), n = t === -1 ? void 0 : {
|
|
858
858
|
row: g.current[t],
|
|
859
859
|
index: t
|
|
@@ -877,13 +877,13 @@ function pe(e) {
|
|
|
877
877
|
error: l,
|
|
878
878
|
hasMore: p !== null,
|
|
879
879
|
refresh: b,
|
|
880
|
-
loadMore:
|
|
881
|
-
remove:
|
|
880
|
+
loadMore: ee,
|
|
881
|
+
remove: x
|
|
882
882
|
};
|
|
883
883
|
}
|
|
884
884
|
//#endregion
|
|
885
885
|
//#region src/client/routes.ts
|
|
886
|
-
function
|
|
886
|
+
function W(e) {
|
|
887
887
|
return e.replace(/\/+$/, "");
|
|
888
888
|
}
|
|
889
889
|
function G(e, t) {
|
|
@@ -894,22 +894,22 @@ function G(e, t) {
|
|
|
894
894
|
}
|
|
895
895
|
var K = {
|
|
896
896
|
responses(e) {
|
|
897
|
-
return `${
|
|
897
|
+
return `${W(e)}/responses`;
|
|
898
898
|
},
|
|
899
899
|
conversations(e, t) {
|
|
900
|
-
return G(`${
|
|
900
|
+
return G(`${W(e)}/conversations`, {
|
|
901
901
|
limit: t.limit,
|
|
902
902
|
cursor: t.cursor
|
|
903
903
|
});
|
|
904
904
|
},
|
|
905
905
|
conversation(e, t, n) {
|
|
906
|
-
return G(`${
|
|
906
|
+
return G(`${W(e)}/conversations/${encodeURIComponent(t)}`, {
|
|
907
907
|
limit: n.limit,
|
|
908
908
|
before_absolute_index: n.beforeAbsoluteIndex
|
|
909
909
|
});
|
|
910
910
|
},
|
|
911
911
|
feedback(e, t, n) {
|
|
912
|
-
return `${
|
|
912
|
+
return `${W(e)}/conversations/${encodeURIComponent(t)}/messages/${encodeURIComponent(n)}/feedback`;
|
|
913
913
|
}
|
|
914
914
|
};
|
|
915
915
|
//#endregion
|
|
@@ -934,9 +934,9 @@ function ge(e) {
|
|
|
934
934
|
...e.status === void 0 ? {} : { interrupted: !0 }
|
|
935
935
|
};
|
|
936
936
|
}
|
|
937
|
-
var _e = 3e4, ve = 155e3, J = "x-chat-id", ye = "header",
|
|
937
|
+
var _e = 3e4, ve = 155e3, J = "x-chat-id", ye = "header", be = "body", Y = "x-request-id", xe = "x-conversation-id", Se = "x-message-id", X = (e) => e && typeof e == "object" ? e : {}, Z = (e, t = "") => typeof e == "string" ? e : t, Ce = (e, t = 0) => typeof e == "number" ? e : t;
|
|
938
938
|
function we(e) {
|
|
939
|
-
let t =
|
|
939
|
+
let t = X(e);
|
|
940
940
|
return {
|
|
941
941
|
conversationId: Z(t.conversation_id),
|
|
942
942
|
title: typeof t.title == "string" ? t.title : null,
|
|
@@ -948,7 +948,7 @@ function we(e) {
|
|
|
948
948
|
}
|
|
949
949
|
function Te(e) {
|
|
950
950
|
if (!e || typeof e != "object") return null;
|
|
951
|
-
let t =
|
|
951
|
+
let t = X(e);
|
|
952
952
|
return {
|
|
953
953
|
rating: Z(t.rating),
|
|
954
954
|
reasonCodes: Array.isArray(t.reason_codes) ? t.reason_codes.filter((e) => typeof e == "string") : [],
|
|
@@ -957,7 +957,7 @@ function Te(e) {
|
|
|
957
957
|
};
|
|
958
958
|
}
|
|
959
959
|
function Ee(e) {
|
|
960
|
-
let t =
|
|
960
|
+
let t = X(e);
|
|
961
961
|
return {
|
|
962
962
|
messageId: Z(t.message_id),
|
|
963
963
|
role: Z(t.role),
|
|
@@ -980,22 +980,22 @@ function De(e) {
|
|
|
980
980
|
};
|
|
981
981
|
}
|
|
982
982
|
function Q(e) {
|
|
983
|
-
return e.timedOut() ? new
|
|
983
|
+
return e.timedOut() ? new V({
|
|
984
984
|
status: 0,
|
|
985
985
|
kind: "timeout",
|
|
986
986
|
cause: e.signal.reason
|
|
987
|
-
}) : new
|
|
987
|
+
}) : new V({
|
|
988
988
|
status: 0,
|
|
989
989
|
kind: "aborted"
|
|
990
990
|
});
|
|
991
991
|
}
|
|
992
992
|
function Oe(e) {
|
|
993
993
|
let { baseUrl: t, getHeaders: n, onAuthError: r } = e, i = e.requestTimeoutMs ?? _e, a = e.idleTimeoutMs ?? ve, o = e.conversationVia ?? ye;
|
|
994
|
-
if (o !== ye && o !==
|
|
994
|
+
if (o !== ye && o !== be) throw TypeError("createBaileyClient: conversationVia must be 'header' or 'body'");
|
|
995
995
|
let s = e.fetch ?? ((e, t) => globalThis.fetch(e, t));
|
|
996
996
|
function c(t) {
|
|
997
997
|
try {
|
|
998
|
-
e.onCleanupError?.(new
|
|
998
|
+
e.onCleanupError?.(new U({ operation: t }));
|
|
999
999
|
} catch {}
|
|
1000
1000
|
}
|
|
1001
1001
|
function l(e) {
|
|
@@ -1014,7 +1014,7 @@ function Oe(e) {
|
|
|
1014
1014
|
...await n()
|
|
1015
1015
|
};
|
|
1016
1016
|
} catch {
|
|
1017
|
-
throw new
|
|
1017
|
+
throw new V({
|
|
1018
1018
|
status: 0,
|
|
1019
1019
|
kind: "network"
|
|
1020
1020
|
});
|
|
@@ -1030,18 +1030,18 @@ function Oe(e) {
|
|
|
1030
1030
|
signal: t.signal
|
|
1031
1031
|
});
|
|
1032
1032
|
} catch (e) {
|
|
1033
|
-
throw t.signal.aborted ? Q(t) : new
|
|
1033
|
+
throw t.signal.aborted ? Q(t) : new V({
|
|
1034
1034
|
status: 0,
|
|
1035
1035
|
kind: "network",
|
|
1036
1036
|
cause: e
|
|
1037
1037
|
});
|
|
1038
1038
|
}
|
|
1039
|
-
if (!i.ok) throw i.body?.cancel().catch(() => c("cancel-response-body")), new
|
|
1039
|
+
if (!i.ok) throw i.body?.cancel().catch(() => c("cancel-response-body")), new V({
|
|
1040
1040
|
status: i.status,
|
|
1041
1041
|
kind: "http"
|
|
1042
1042
|
});
|
|
1043
1043
|
if (i.status === 204) {
|
|
1044
|
-
if (e.requireJsonBody) throw new
|
|
1044
|
+
if (e.requireJsonBody) throw new V({
|
|
1045
1045
|
status: 204,
|
|
1046
1046
|
kind: "invalid-response"
|
|
1047
1047
|
});
|
|
@@ -1049,22 +1049,22 @@ function Oe(e) {
|
|
|
1049
1049
|
}
|
|
1050
1050
|
try {
|
|
1051
1051
|
let t = await i.json();
|
|
1052
|
-
if (e.requireJsonBody && (typeof t != "object" || !t || Array.isArray(t))) throw new
|
|
1052
|
+
if (e.requireJsonBody && (typeof t != "object" || !t || Array.isArray(t))) throw new V({
|
|
1053
1053
|
status: i.status,
|
|
1054
1054
|
kind: "invalid-response"
|
|
1055
1055
|
});
|
|
1056
1056
|
return t;
|
|
1057
1057
|
} catch (n) {
|
|
1058
|
-
if (n instanceof
|
|
1058
|
+
if (n instanceof V) throw n;
|
|
1059
1059
|
if (t.timedOut() || t.signal.aborted) throw Q(t);
|
|
1060
|
-
if (e.requireJsonBody) throw new
|
|
1060
|
+
if (e.requireJsonBody) throw new V({
|
|
1061
1061
|
status: i.status,
|
|
1062
1062
|
kind: "invalid-response"
|
|
1063
1063
|
});
|
|
1064
1064
|
return;
|
|
1065
1065
|
}
|
|
1066
1066
|
} catch (e) {
|
|
1067
|
-
throw e instanceof
|
|
1067
|
+
throw e instanceof V && l(e), e;
|
|
1068
1068
|
} finally {
|
|
1069
1069
|
t.dispose();
|
|
1070
1070
|
}
|
|
@@ -1110,7 +1110,7 @@ function Oe(e) {
|
|
|
1110
1110
|
stream: !0,
|
|
1111
1111
|
...Object.keys(u).length > 0 ? { metadata: u } : {}
|
|
1112
1112
|
};
|
|
1113
|
-
e.conversationId && o ===
|
|
1113
|
+
e.conversationId && o === be && (d.conversation = e.conversationId), e.tools.length > 0 && (d.tools = e.tools), e.toolChoice && (d.tool_choice = e.toolChoice);
|
|
1114
1114
|
let m;
|
|
1115
1115
|
try {
|
|
1116
1116
|
m = await s(K.responses(t), {
|
|
@@ -1122,11 +1122,11 @@ function Oe(e) {
|
|
|
1122
1122
|
} catch (e) {
|
|
1123
1123
|
return r.signal.aborted ? p() : q({ cause: e });
|
|
1124
1124
|
}
|
|
1125
|
-
let h = m.headers.get(
|
|
1125
|
+
let h = m.headers.get(Y);
|
|
1126
1126
|
h && e.onRequestId?.(h);
|
|
1127
|
-
let g = m.headers.get(
|
|
1127
|
+
let g = m.headers.get(Se);
|
|
1128
1128
|
if (g && e.onMessageId?.(g), !m.ok) {
|
|
1129
|
-
l(new
|
|
1129
|
+
l(new V({
|
|
1130
1130
|
status: m.status,
|
|
1131
1131
|
kind: "http"
|
|
1132
1132
|
}));
|
|
@@ -1136,7 +1136,7 @@ function Oe(e) {
|
|
|
1136
1136
|
text: e
|
|
1137
1137
|
};
|
|
1138
1138
|
}
|
|
1139
|
-
let _ = m.headers.get(
|
|
1139
|
+
let _ = m.headers.get(xe);
|
|
1140
1140
|
if (_ && e.onConversationId?.(_), !m.body) return {
|
|
1141
1141
|
status: m.status,
|
|
1142
1142
|
text: ""
|
|
@@ -1173,7 +1173,7 @@ function Oe(e) {
|
|
|
1173
1173
|
}
|
|
1174
1174
|
},
|
|
1175
1175
|
async listConversations(e = {}) {
|
|
1176
|
-
let n =
|
|
1176
|
+
let n = X(await u({
|
|
1177
1177
|
method: "GET",
|
|
1178
1178
|
url: K.conversations(t, e),
|
|
1179
1179
|
signal: e.signal,
|
|
@@ -1185,13 +1185,13 @@ function Oe(e) {
|
|
|
1185
1185
|
};
|
|
1186
1186
|
},
|
|
1187
1187
|
async getConversation(e) {
|
|
1188
|
-
let n =
|
|
1188
|
+
let n = X(await u({
|
|
1189
1189
|
method: "GET",
|
|
1190
1190
|
url: K.conversation(t, e.conversationId, e),
|
|
1191
1191
|
signal: e.signal,
|
|
1192
1192
|
requireJsonBody: !0
|
|
1193
1193
|
}));
|
|
1194
|
-
if (!n.conversation || typeof n.conversation != "object") throw new
|
|
1194
|
+
if (!n.conversation || typeof n.conversation != "object") throw new V({
|
|
1195
1195
|
status: 200,
|
|
1196
1196
|
kind: "invalid-response"
|
|
1197
1197
|
});
|
|
@@ -2171,7 +2171,7 @@ function _n(e) {
|
|
|
2171
2171
|
//#endregion
|
|
2172
2172
|
//#region src/ui/BaileyHistoryDrawer.tsx
|
|
2173
2173
|
function vn({ client: e, pageSize: t, chat: n, labels: r, locale: i, onClose: o }) {
|
|
2174
|
-
let s =
|
|
2174
|
+
let s = me({
|
|
2175
2175
|
client: e,
|
|
2176
2176
|
pageSize: t
|
|
2177
2177
|
}), { loadConversation: c, newChat: l } = n, u = a((e) => c ? c(e) : Promise.reject(/* @__PURE__ */ Error("no loadConversation")), [c]), d = a(() => {
|
|
@@ -2191,17 +2191,17 @@ function vn({ client: e, pageSize: t, chat: n, labels: r, locale: i, onClose: o
|
|
|
2191
2191
|
}
|
|
2192
2192
|
var yn = (e, t) => Object.entries(t).reduce((e, [t, n]) => e.split(`{${t}}`).join(String(n)), e), bn = (e) => !e || e.kind !== "http" ? !1 : e.status === 401 || e.status === 403;
|
|
2193
2193
|
function xn({ conversations: e, activeConversationId: t, selectStatus: n, onSelect: r, onActiveDeleted: i, onNewChat: a, onClose: o, labels: l, locale: u, now: p }) {
|
|
2194
|
-
let { conversations: m, status: h, error: g, hasMore: b, refresh:
|
|
2194
|
+
let { conversations: m, status: h, error: g, hasMore: b, refresh: ee, loadMore: x, remove: S } = e, C = c(), w = c(), T = d(null), E = d(null), D = d(null), O = d(/* @__PURE__ */ new Map()), te = d(/* @__PURE__ */ new Map()), k = d(null), A = d(null), [j, M] = f(null), [N, P] = f(null), [ne, re] = f(0), [ie, ae] = f(!1), [F, oe] = f(!1), [se, I] = f(!1), L = u ?? (typeof navigator < "u" ? navigator.language : void 0);
|
|
2195
2195
|
s(() => {
|
|
2196
|
-
|
|
2196
|
+
T.current?.focus();
|
|
2197
2197
|
}, []), s(() => {
|
|
2198
|
-
let e =
|
|
2198
|
+
let e = k.current;
|
|
2199
2199
|
if (!e) return;
|
|
2200
|
-
let t = e.kind === "select" ?
|
|
2201
|
-
t && (t.focus(),
|
|
2200
|
+
let t = e.kind === "select" ? O.current.get(e.id) : e.kind === "delete" ? te.current.get(e.id) : e.kind === "cancel" ? D.current : E.current;
|
|
2201
|
+
t && (t.focus(), k.current = null);
|
|
2202
2202
|
}), s(() => {
|
|
2203
|
-
let e =
|
|
2204
|
-
e !== null && h !== "loading" && (
|
|
2203
|
+
let e = A.current;
|
|
2204
|
+
e !== null && h !== "loading" && (A.current = null, !b && m.length > e && (k.current = {
|
|
2205
2205
|
kind: "select",
|
|
2206
2206
|
id: m[e].conversationId
|
|
2207
2207
|
}));
|
|
@@ -2210,57 +2210,57 @@ function xn({ conversations: e, activeConversationId: t, selectStatus: n, onSele
|
|
|
2210
2210
|
b,
|
|
2211
2211
|
m
|
|
2212
2212
|
]);
|
|
2213
|
-
let
|
|
2214
|
-
|
|
2215
|
-
},
|
|
2216
|
-
|
|
2213
|
+
let ce = () => {
|
|
2214
|
+
A.current = m.length, x();
|
|
2215
|
+
}, R = (e) => {
|
|
2216
|
+
k.current = {
|
|
2217
2217
|
kind: "delete",
|
|
2218
2218
|
id: e
|
|
2219
|
-
},
|
|
2219
|
+
}, M(null);
|
|
2220
2220
|
}, le = (e) => {
|
|
2221
2221
|
if (e.key === "Escape") {
|
|
2222
|
-
if (e.stopPropagation(),
|
|
2223
|
-
|
|
2222
|
+
if (e.stopPropagation(), j) {
|
|
2223
|
+
R(j);
|
|
2224
2224
|
return;
|
|
2225
2225
|
}
|
|
2226
2226
|
o({ restoreFocusTo: "menu" });
|
|
2227
2227
|
}
|
|
2228
2228
|
}, ue = async (e) => {
|
|
2229
|
-
if (
|
|
2229
|
+
if (I(!1), e === t) {
|
|
2230
2230
|
o({ restoreFocusTo: "input" });
|
|
2231
2231
|
return;
|
|
2232
2232
|
}
|
|
2233
|
-
|
|
2233
|
+
oe(!0);
|
|
2234
2234
|
try {
|
|
2235
2235
|
await r({ conversationId: e });
|
|
2236
2236
|
} catch {
|
|
2237
|
-
|
|
2237
|
+
k.current = {
|
|
2238
2238
|
kind: "select",
|
|
2239
2239
|
id: e
|
|
2240
|
-
},
|
|
2240
|
+
}, I(!0), oe(!1);
|
|
2241
2241
|
return;
|
|
2242
2242
|
}
|
|
2243
|
-
|
|
2244
|
-
},
|
|
2243
|
+
oe(!1), o({ restoreFocusTo: "input" });
|
|
2244
|
+
}, de = async (e) => {
|
|
2245
2245
|
let n = m.findIndex((t) => t.conversationId === e), r = m[n + 1] ?? m[n - 1];
|
|
2246
|
-
|
|
2246
|
+
k.current = r ? {
|
|
2247
2247
|
kind: "select",
|
|
2248
2248
|
id: r.conversationId
|
|
2249
|
-
} : { kind: "newChat" },
|
|
2249
|
+
} : { kind: "newChat" }, M(null), P(null), ae(!1), re((e) => e + 1);
|
|
2250
2250
|
try {
|
|
2251
|
-
await
|
|
2251
|
+
await S({ conversationId: e }), ae(!0), e === t && i?.();
|
|
2252
2252
|
} catch {
|
|
2253
|
-
|
|
2253
|
+
k.current = {
|
|
2254
2254
|
kind: "delete",
|
|
2255
2255
|
id: e
|
|
2256
2256
|
}, P(e);
|
|
2257
2257
|
} finally {
|
|
2258
2258
|
re((e) => e - 1);
|
|
2259
2259
|
}
|
|
2260
|
-
},
|
|
2260
|
+
}, z = h === "loading" && m.length === 0, fe = h === "error" && m.length === 0, B = h === "error" && m.length > 0 && b, V = h === "loading" && m.length > 0, H = F || n === "loading", U = z ? l.historyLoadingText : ne > 0 ? l.historyDeletingText : ie ? l.historyDeletedText : m.length > 0 ? yn(m.length === 1 ? l.historyCountTextOne : l.historyCountTextMany, { count: m.length }) : "", pe = z || ne > 0;
|
|
2261
2261
|
return /* @__PURE__ */ y("section", {
|
|
2262
2262
|
role: "region",
|
|
2263
|
-
"aria-labelledby":
|
|
2263
|
+
"aria-labelledby": C,
|
|
2264
2264
|
className: "bailey-history-drawer",
|
|
2265
2265
|
onKeyDown: le,
|
|
2266
2266
|
children: [
|
|
@@ -2275,18 +2275,18 @@ function xn({ conversations: e, activeConversationId: t, selectStatus: n, onSele
|
|
|
2275
2275
|
children: /* @__PURE__ */ v(zt, { className: "bailey-history-icon" })
|
|
2276
2276
|
}),
|
|
2277
2277
|
/* @__PURE__ */ v("h3", {
|
|
2278
|
-
id:
|
|
2279
|
-
ref:
|
|
2278
|
+
id: C,
|
|
2279
|
+
ref: T,
|
|
2280
2280
|
tabIndex: -1,
|
|
2281
2281
|
className: "bailey-history-heading",
|
|
2282
2282
|
children: l.historyTitle
|
|
2283
2283
|
}),
|
|
2284
2284
|
/* @__PURE__ */ y("button", {
|
|
2285
|
-
ref:
|
|
2285
|
+
ref: E,
|
|
2286
2286
|
type: "button",
|
|
2287
2287
|
className: "bailey-history-button bailey-history-new-chat",
|
|
2288
2288
|
"aria-label": l.newChatButtonText,
|
|
2289
|
-
disabled:
|
|
2289
|
+
disabled: z,
|
|
2290
2290
|
onClick: a,
|
|
2291
2291
|
children: [/* @__PURE__ */ v(Pt, { className: "bailey-history-icon-small" }), /* @__PURE__ */ v("span", {
|
|
2292
2292
|
className: "bailey-history-new-chat-text",
|
|
@@ -2297,9 +2297,9 @@ function xn({ conversations: e, activeConversationId: t, selectStatus: n, onSele
|
|
|
2297
2297
|
}),
|
|
2298
2298
|
/* @__PURE__ */ y("div", {
|
|
2299
2299
|
className: "bailey-history-body",
|
|
2300
|
-
"aria-busy":
|
|
2300
|
+
"aria-busy": z || void 0,
|
|
2301
2301
|
children: [
|
|
2302
|
-
|
|
2302
|
+
z && /* @__PURE__ */ y("div", {
|
|
2303
2303
|
"aria-hidden": "true",
|
|
2304
2304
|
children: [
|
|
2305
2305
|
/* @__PURE__ */ v("div", { className: "bailey-history-skeleton" }),
|
|
@@ -2308,7 +2308,7 @@ function xn({ conversations: e, activeConversationId: t, selectStatus: n, onSele
|
|
|
2308
2308
|
/* @__PURE__ */ v("div", { className: "bailey-history-skeleton" })
|
|
2309
2309
|
]
|
|
2310
2310
|
}),
|
|
2311
|
-
|
|
2311
|
+
fe && /* @__PURE__ */ y("div", {
|
|
2312
2312
|
role: "alert",
|
|
2313
2313
|
className: "bailey-history-state bailey-history-state-error",
|
|
2314
2314
|
children: [
|
|
@@ -2318,12 +2318,12 @@ function xn({ conversations: e, activeConversationId: t, selectStatus: n, onSele
|
|
|
2318
2318
|
/* @__PURE__ */ v("button", {
|
|
2319
2319
|
type: "button",
|
|
2320
2320
|
className: "bailey-history-button bailey-history-button-primary",
|
|
2321
|
-
onClick: () => void
|
|
2321
|
+
onClick: () => void ee(),
|
|
2322
2322
|
children: l.retryButtonText
|
|
2323
2323
|
})
|
|
2324
2324
|
]
|
|
2325
2325
|
}),
|
|
2326
|
-
!
|
|
2326
|
+
!z && !fe && m.length === 0 && /* @__PURE__ */ y("div", {
|
|
2327
2327
|
className: "bailey-history-state",
|
|
2328
2328
|
children: [
|
|
2329
2329
|
/* @__PURE__ */ v(jt, { className: "bailey-history-state-icon" }),
|
|
@@ -2341,15 +2341,15 @@ function xn({ conversations: e, activeConversationId: t, selectStatus: n, onSele
|
|
|
2341
2341
|
className: "bailey-history-list",
|
|
2342
2342
|
children: m.map((e) => {
|
|
2343
2343
|
let n = e.conversationId, r = e.title?.trim() ? e.title : l.historyUntitledText, i = n === t;
|
|
2344
|
-
if (
|
|
2344
|
+
if (j === n) return /* @__PURE__ */ v("li", {
|
|
2345
2345
|
className: "bailey-history-row bailey-history-row-confirming",
|
|
2346
2346
|
children: /* @__PURE__ */ y("div", {
|
|
2347
2347
|
role: "group",
|
|
2348
|
-
"aria-labelledby":
|
|
2348
|
+
"aria-labelledby": w,
|
|
2349
2349
|
className: "bailey-history-confirm",
|
|
2350
2350
|
children: [
|
|
2351
2351
|
/* @__PURE__ */ v("span", {
|
|
2352
|
-
id:
|
|
2352
|
+
id: w,
|
|
2353
2353
|
className: "bailey-history-confirm-question",
|
|
2354
2354
|
children: l.historyDeleteConfirmQuestion
|
|
2355
2355
|
}),
|
|
@@ -2360,14 +2360,14 @@ function xn({ conversations: e, activeConversationId: t, selectStatus: n, onSele
|
|
|
2360
2360
|
/* @__PURE__ */ v("button", {
|
|
2361
2361
|
type: "button",
|
|
2362
2362
|
className: "bailey-history-button bailey-history-button-danger",
|
|
2363
|
-
onClick: () => void
|
|
2363
|
+
onClick: () => void de(n),
|
|
2364
2364
|
children: l.historyDeleteConfirmText
|
|
2365
2365
|
}),
|
|
2366
2366
|
/* @__PURE__ */ v("button", {
|
|
2367
|
-
ref:
|
|
2367
|
+
ref: D,
|
|
2368
2368
|
type: "button",
|
|
2369
2369
|
className: "bailey-history-button",
|
|
2370
|
-
onClick: () =>
|
|
2370
|
+
onClick: () => R(n),
|
|
2371
2371
|
children: l.historyDeleteCancelText
|
|
2372
2372
|
})
|
|
2373
2373
|
]
|
|
@@ -2375,23 +2375,23 @@ function xn({ conversations: e, activeConversationId: t, selectStatus: n, onSele
|
|
|
2375
2375
|
}, n);
|
|
2376
2376
|
let a = _n({
|
|
2377
2377
|
iso: e.updatedAt,
|
|
2378
|
-
locale:
|
|
2378
|
+
locale: L,
|
|
2379
2379
|
now: p?.(),
|
|
2380
2380
|
justNowText: l.historyJustNowText
|
|
2381
|
-
}), o = yn(e.messageCount === 1 ? l.historyMessageCountOne : l.historyMessageCountMany, { count: e.messageCount }), s =
|
|
2381
|
+
}), o = yn(e.messageCount === 1 ? l.historyMessageCountOne : l.historyMessageCountMany, { count: e.messageCount }), s = N === n;
|
|
2382
2382
|
return /* @__PURE__ */ y("li", {
|
|
2383
2383
|
className: `bailey-history-row${i ? " bailey-history-row-active" : ""}${s ? " bailey-history-row-failed" : ""}`,
|
|
2384
2384
|
children: [
|
|
2385
2385
|
/* @__PURE__ */ y("button", {
|
|
2386
2386
|
type: "button",
|
|
2387
2387
|
ref: (e) => {
|
|
2388
|
-
e ?
|
|
2388
|
+
e ? O.current.set(n, e) : O.current.delete(n);
|
|
2389
2389
|
},
|
|
2390
2390
|
className: "bailey-history-select",
|
|
2391
2391
|
"aria-current": i ? "true" : void 0,
|
|
2392
|
-
"aria-disabled":
|
|
2392
|
+
"aria-disabled": H || void 0,
|
|
2393
2393
|
onClick: () => {
|
|
2394
|
-
|
|
2394
|
+
H || ue(n);
|
|
2395
2395
|
},
|
|
2396
2396
|
children: [/* @__PURE__ */ v("span", {
|
|
2397
2397
|
className: "bailey-history-row-title",
|
|
@@ -2417,12 +2417,12 @@ function xn({ conversations: e, activeConversationId: t, selectStatus: n, onSele
|
|
|
2417
2417
|
/* @__PURE__ */ v("button", {
|
|
2418
2418
|
type: "button",
|
|
2419
2419
|
ref: (e) => {
|
|
2420
|
-
e ?
|
|
2420
|
+
e ? te.current.set(n, e) : te.current.delete(n);
|
|
2421
2421
|
},
|
|
2422
2422
|
className: "bailey-history-icon-button bailey-history-delete",
|
|
2423
2423
|
"aria-label": yn(l.historyDeleteAriaLabel, { title: r }),
|
|
2424
2424
|
onClick: () => {
|
|
2425
|
-
P(null), ae(!1),
|
|
2425
|
+
P(null), ae(!1), k.current = { kind: "cancel" }, M(n);
|
|
2426
2426
|
},
|
|
2427
2427
|
children: /* @__PURE__ */ v(Bt, { className: "bailey-history-icon" })
|
|
2428
2428
|
}),
|
|
@@ -2435,7 +2435,7 @@ function xn({ conversations: e, activeConversationId: t, selectStatus: n, onSele
|
|
|
2435
2435
|
/* @__PURE__ */ v("button", {
|
|
2436
2436
|
type: "button",
|
|
2437
2437
|
className: "bailey-history-button bailey-history-button-small",
|
|
2438
|
-
onClick: () => void
|
|
2438
|
+
onClick: () => void de(n),
|
|
2439
2439
|
children: l.historyDeleteRetryText
|
|
2440
2440
|
}),
|
|
2441
2441
|
/* @__PURE__ */ v("button", {
|
|
@@ -2450,31 +2450,31 @@ function xn({ conversations: e, activeConversationId: t, selectStatus: n, onSele
|
|
|
2450
2450
|
}, n);
|
|
2451
2451
|
})
|
|
2452
2452
|
}),
|
|
2453
|
-
|
|
2453
|
+
se && /* @__PURE__ */ v("div", {
|
|
2454
2454
|
role: "alert",
|
|
2455
2455
|
className: "bailey-history-inline-error",
|
|
2456
2456
|
children: l.historySelectErrorText
|
|
2457
2457
|
}),
|
|
2458
2458
|
b && m.length > 0 && /* @__PURE__ */ v("div", {
|
|
2459
2459
|
className: "bailey-history-more",
|
|
2460
|
-
children:
|
|
2460
|
+
children: B ? /* @__PURE__ */ y("div", {
|
|
2461
2461
|
role: "alert",
|
|
2462
2462
|
className: "bailey-history-inline-error",
|
|
2463
2463
|
children: [/* @__PURE__ */ v("span", { children: l.historyLoadMoreErrorText }), /* @__PURE__ */ v("button", {
|
|
2464
2464
|
type: "button",
|
|
2465
2465
|
className: "bailey-history-button",
|
|
2466
|
-
onClick:
|
|
2466
|
+
onClick: ce,
|
|
2467
2467
|
children: l.retryButtonText
|
|
2468
2468
|
})]
|
|
2469
2469
|
}) : /* @__PURE__ */ y("button", {
|
|
2470
2470
|
type: "button",
|
|
2471
2471
|
className: "bailey-history-button",
|
|
2472
|
-
disabled:
|
|
2473
|
-
onClick:
|
|
2474
|
-
children: [
|
|
2472
|
+
disabled: V,
|
|
2473
|
+
onClick: ce,
|
|
2474
|
+
children: [V && /* @__PURE__ */ v("span", {
|
|
2475
2475
|
className: "bailey-history-spinner",
|
|
2476
2476
|
"aria-hidden": "true"
|
|
2477
|
-
}),
|
|
2477
|
+
}), V ? l.historyLoadingMoreText : l.historyLoadMoreText]
|
|
2478
2478
|
})
|
|
2479
2479
|
})
|
|
2480
2480
|
]
|
|
@@ -2483,10 +2483,10 @@ function xn({ conversations: e, activeConversationId: t, selectStatus: n, onSele
|
|
|
2483
2483
|
role: "status",
|
|
2484
2484
|
"aria-live": "polite",
|
|
2485
2485
|
className: "bailey-history-status",
|
|
2486
|
-
children: [
|
|
2486
|
+
children: [pe && /* @__PURE__ */ v("span", {
|
|
2487
2487
|
className: "bailey-history-spinner",
|
|
2488
2488
|
"aria-hidden": "true"
|
|
2489
|
-
}),
|
|
2489
|
+
}), U]
|
|
2490
2490
|
})
|
|
2491
2491
|
]
|
|
2492
2492
|
});
|
|
@@ -2582,63 +2582,63 @@ function jn(e) {
|
|
|
2582
2582
|
});
|
|
2583
2583
|
return n ? `Today ${r}` : `${t.toLocaleDateString()} ${r}`;
|
|
2584
2584
|
}
|
|
2585
|
-
function Mn({ chat: e, placeholder: t, replyPlaceholder: r = wn, emptyPlaceholder: i, suggestions: o, onHistoryClick: c, history: l, locale: m, privacyNote: _, resolveActivityIcon: b, className: x, height: S, width: C, hideDeveloperDetails: w = !1, renderMessageActions: T, renderTable: E, renderChart: D, renderMcpApp: O, labels:
|
|
2586
|
-
let { messages: A, traceEvents: j, lastRequest: M, status: N, error:
|
|
2585
|
+
function Mn({ chat: e, placeholder: t, replyPlaceholder: r = wn, emptyPlaceholder: i, suggestions: o, onHistoryClick: c, history: l, locale: m, privacyNote: _, resolveActivityIcon: b, sendIcon: ee, className: x, height: S, width: C, hideDeveloperDetails: w = !1, renderMessageActions: T, renderTable: E, renderChart: D, renderMcpApp: O, labels: te, formatMessageTime: k }) {
|
|
2586
|
+
let { messages: A, traceEvents: j, lastRequest: M, status: N, error: P, send: ne, stop: re, retryLast: ie, clearTrace: ae, clearError: F, newChat: oe } = e, [se, I] = f(""), L = {
|
|
2587
2587
|
...Tn,
|
|
2588
|
-
...
|
|
2589
|
-
},
|
|
2588
|
+
...te
|
|
2589
|
+
}, ce = k ?? jn, R = d(null), le = d(null), ue = d(null), de = d(null), [z, fe] = f(!1), B = d(null), V = d(!1), H = !!c || !!l, U = Ct(R), pe = d(null), me = d(null), W = d(!0), G = u(() => Tt({
|
|
2590
2590
|
renderTable: E,
|
|
2591
2591
|
renderChart: D
|
|
2592
|
-
}), [E, D]),
|
|
2592
|
+
}), [E, D]), K = u(() => kn(N, j, M), [
|
|
2593
2593
|
N,
|
|
2594
2594
|
j,
|
|
2595
2595
|
M
|
|
2596
|
-
]),
|
|
2597
|
-
|
|
2598
|
-
at:
|
|
2599
|
-
length:
|
|
2600
|
-
},
|
|
2601
|
-
let
|
|
2596
|
+
]), q = An(K), he = K?.kind === "tool_end" ? K.at : void 0, ge = A[A.length - 1]?.content.length ?? 0, [_e, ve] = f(null), J = _e;
|
|
2597
|
+
he !== void 0 && _e?.at !== he && (J = {
|
|
2598
|
+
at: he,
|
|
2599
|
+
length: ge
|
|
2600
|
+
}, ve(J));
|
|
2601
|
+
let ye = he !== void 0 && J?.at === he && ge <= J.length, be = q ?? (ye ? L.thinkingHint : void 0), Y = A.length === 0, xe = t ?? (Y ? i ?? Cn : r);
|
|
2602
2602
|
s(() => {
|
|
2603
|
-
let e =
|
|
2603
|
+
let e = me.current;
|
|
2604
2604
|
if (!e) return;
|
|
2605
2605
|
let t = () => {
|
|
2606
2606
|
let t = e.scrollHeight - e.scrollTop - e.clientHeight;
|
|
2607
|
-
|
|
2607
|
+
W.current = t < 60;
|
|
2608
2608
|
};
|
|
2609
2609
|
return e.addEventListener("scroll", t, { passive: !0 }), () => e.removeEventListener("scroll", t);
|
|
2610
2610
|
}, []), s(() => {
|
|
2611
|
-
|
|
2611
|
+
W.current && pe.current?.scrollIntoView({
|
|
2612
2612
|
behavior: N === "streaming" ? "auto" : "smooth",
|
|
2613
2613
|
block: "nearest"
|
|
2614
2614
|
});
|
|
2615
2615
|
}, [A, N]);
|
|
2616
|
-
let
|
|
2617
|
-
|
|
2618
|
-
},
|
|
2619
|
-
let t =
|
|
2620
|
-
|
|
2616
|
+
let Se = (e) => {
|
|
2617
|
+
W.current = !0, ne(e);
|
|
2618
|
+
}, X = d(null), Z = () => {
|
|
2619
|
+
let t = me.current;
|
|
2620
|
+
W.current = !1, X.current = t ? {
|
|
2621
2621
|
height: t.scrollHeight,
|
|
2622
2622
|
top: t.scrollTop
|
|
2623
2623
|
} : null, e.loadEarlier?.().catch(() => {
|
|
2624
|
-
|
|
2624
|
+
X.current = null;
|
|
2625
2625
|
});
|
|
2626
2626
|
};
|
|
2627
2627
|
s(() => {
|
|
2628
|
-
let e =
|
|
2629
|
-
!e || !t || t.scrollHeight === e.height || (t.scrollTop = e.top + (t.scrollHeight - e.height),
|
|
2628
|
+
let e = X.current, t = me.current;
|
|
2629
|
+
!e || !t || t.scrollHeight === e.height || (t.scrollTop = e.top + (t.scrollHeight - e.height), X.current = null);
|
|
2630
2630
|
}, [A]), s(() => {
|
|
2631
|
-
|
|
2631
|
+
le.current?.toggleAttribute("inert", z);
|
|
2632
2632
|
}, [z]), s(() => {
|
|
2633
|
-
z || !
|
|
2633
|
+
z || !B.current || ((B.current === "input" ? ue.current : de.current)?.focus(), B.current = null);
|
|
2634
2634
|
}, [z]);
|
|
2635
|
-
let
|
|
2636
|
-
|
|
2635
|
+
let Ce = a((e) => {
|
|
2636
|
+
B.current = e.restoreFocusTo, fe(!1);
|
|
2637
2637
|
}, []);
|
|
2638
2638
|
return /* @__PURE__ */ v(pt.Provider, {
|
|
2639
2639
|
value: U,
|
|
2640
2640
|
children: /* @__PURE__ */ y("div", {
|
|
2641
|
-
ref:
|
|
2641
|
+
ref: R,
|
|
2642
2642
|
className: `bailey-chat-panel${x ? ` ${x}` : ""}`,
|
|
2643
2643
|
style: S !== void 0 || C !== void 0 ? {
|
|
2644
2644
|
height: S,
|
|
@@ -2646,11 +2646,11 @@ function Mn({ chat: e, placeholder: t, replyPlaceholder: r = wn, emptyPlaceholde
|
|
|
2646
2646
|
} : void 0,
|
|
2647
2647
|
children: [/* @__PURE__ */ y("div", {
|
|
2648
2648
|
className: "bailey-chat-panel-inner",
|
|
2649
|
-
ref:
|
|
2649
|
+
ref: le,
|
|
2650
2650
|
children: [
|
|
2651
2651
|
/* @__PURE__ */ y("div", {
|
|
2652
2652
|
className: "bailey-chat-transcript",
|
|
2653
|
-
ref:
|
|
2653
|
+
ref: me,
|
|
2654
2654
|
children: [
|
|
2655
2655
|
e.hasEarlier && e.loadEarlier && /* @__PURE__ */ y("div", {
|
|
2656
2656
|
className: "bailey-load-earlier",
|
|
@@ -2658,7 +2658,7 @@ function Mn({ chat: e, placeholder: t, replyPlaceholder: r = wn, emptyPlaceholde
|
|
|
2658
2658
|
type: "button",
|
|
2659
2659
|
className: "bailey-load-earlier-button",
|
|
2660
2660
|
disabled: e.historyStatus === "loading",
|
|
2661
|
-
onClick:
|
|
2661
|
+
onClick: Z,
|
|
2662
2662
|
children: L.loadEarlierButtonText
|
|
2663
2663
|
}), e.historyStatus === "error" && /* @__PURE__ */ v("div", {
|
|
2664
2664
|
role: "alert",
|
|
@@ -2673,7 +2673,7 @@ function Mn({ chat: e, placeholder: t, replyPlaceholder: r = wn, emptyPlaceholde
|
|
|
2673
2673
|
children: L.suggestionsTitle
|
|
2674
2674
|
}), o.map((e, t) => /* @__PURE__ */ y("button", {
|
|
2675
2675
|
type: "button",
|
|
2676
|
-
onClick: () =>
|
|
2676
|
+
onClick: () => Se(e.value ?? e.label),
|
|
2677
2677
|
className: "bailey-suggestion-card",
|
|
2678
2678
|
children: [/* @__PURE__ */ v("span", { children: e.label }), /* @__PURE__ */ v(Ot, { className: "bailey-suggestion-icon" })]
|
|
2679
2679
|
}, `${e.label}-${t}`))]
|
|
@@ -2692,7 +2692,7 @@ function Mn({ chat: e, placeholder: t, replyPlaceholder: r = wn, emptyPlaceholde
|
|
|
2692
2692
|
children: [/* @__PURE__ */ v("span", {
|
|
2693
2693
|
className: "bailey-message-meta-name",
|
|
2694
2694
|
children: L.youLabel
|
|
2695
|
-
}), e.createdAt !== void 0 && /* @__PURE__ */ v("span", { children:
|
|
2695
|
+
}), e.createdAt !== void 0 && /* @__PURE__ */ v("span", { children: ce(e.createdAt) })]
|
|
2696
2696
|
}), /* @__PURE__ */ v("div", {
|
|
2697
2697
|
className: "bailey-user-bubble",
|
|
2698
2698
|
children: e.content
|
|
@@ -2702,7 +2702,7 @@ function Mn({ chat: e, placeholder: t, replyPlaceholder: r = wn, emptyPlaceholde
|
|
|
2702
2702
|
resolveActivityIcon: b
|
|
2703
2703
|
}) : /* @__PURE__ */ v("div", {
|
|
2704
2704
|
className: "bailey-thinking-hint",
|
|
2705
|
-
children:
|
|
2705
|
+
children: q ?? L.thinkingHint
|
|
2706
2706
|
}) : /* @__PURE__ */ y("div", {
|
|
2707
2707
|
className: "bailey-assistant-message",
|
|
2708
2708
|
children: [
|
|
@@ -2713,7 +2713,7 @@ function Mn({ chat: e, placeholder: t, replyPlaceholder: r = wn, emptyPlaceholde
|
|
|
2713
2713
|
}),
|
|
2714
2714
|
/* @__PURE__ */ v(On, {
|
|
2715
2715
|
content: e.content,
|
|
2716
|
-
components:
|
|
2716
|
+
components: G
|
|
2717
2717
|
}),
|
|
2718
2718
|
e.parts?.map((e, t) => e.type === "image" ? /* @__PURE__ */ v($t, {
|
|
2719
2719
|
src: e.src,
|
|
@@ -2726,9 +2726,9 @@ function Mn({ chat: e, placeholder: t, replyPlaceholder: r = wn, emptyPlaceholde
|
|
|
2726
2726
|
steps: a,
|
|
2727
2727
|
resolveActivityIcon: b
|
|
2728
2728
|
}),
|
|
2729
|
-
e.streaming &&
|
|
2729
|
+
e.streaming && be && !o && /* @__PURE__ */ v("div", {
|
|
2730
2730
|
className: "bailey-streaming-hint",
|
|
2731
|
-
children:
|
|
2731
|
+
children: be
|
|
2732
2732
|
}),
|
|
2733
2733
|
!e.streaming && /* @__PURE__ */ y("div", {
|
|
2734
2734
|
className: "bailey-message-actions",
|
|
@@ -2743,22 +2743,22 @@ function Mn({ chat: e, placeholder: t, replyPlaceholder: r = wn, emptyPlaceholde
|
|
|
2743
2743
|
})
|
|
2744
2744
|
}, e.id);
|
|
2745
2745
|
}),
|
|
2746
|
-
/* @__PURE__ */ v("div", { ref:
|
|
2746
|
+
/* @__PURE__ */ v("div", { ref: pe })
|
|
2747
2747
|
]
|
|
2748
2748
|
}),
|
|
2749
|
-
|
|
2749
|
+
P && /* @__PURE__ */ y("div", {
|
|
2750
2750
|
className: "bailey-error-banner",
|
|
2751
2751
|
role: "alert",
|
|
2752
|
-
children: [/* @__PURE__ */ v("span", { children:
|
|
2752
|
+
children: [/* @__PURE__ */ v("span", { children: P }), /* @__PURE__ */ y("div", {
|
|
2753
2753
|
className: "bailey-error-actions",
|
|
2754
2754
|
children: [/* @__PURE__ */ v("button", {
|
|
2755
2755
|
type: "button",
|
|
2756
|
-
onClick:
|
|
2756
|
+
onClick: ie,
|
|
2757
2757
|
className: "bailey-retry-button",
|
|
2758
2758
|
children: L.retryButtonText
|
|
2759
2759
|
}), /* @__PURE__ */ v("button", {
|
|
2760
2760
|
type: "button",
|
|
2761
|
-
onClick:
|
|
2761
|
+
onClick: F,
|
|
2762
2762
|
"aria-label": L.dismissErrorAriaLabel,
|
|
2763
2763
|
className: "bailey-dismiss-button",
|
|
2764
2764
|
children: "✕"
|
|
@@ -2768,22 +2768,22 @@ function Mn({ chat: e, placeholder: t, replyPlaceholder: r = wn, emptyPlaceholde
|
|
|
2768
2768
|
!w && /* @__PURE__ */ v(Qt, {
|
|
2769
2769
|
events: j,
|
|
2770
2770
|
lastRequest: M,
|
|
2771
|
-
onClear:
|
|
2771
|
+
onClear: ae
|
|
2772
2772
|
}),
|
|
2773
2773
|
/* @__PURE__ */ y("div", {
|
|
2774
2774
|
className: "bailey-input-area",
|
|
2775
2775
|
children: [/* @__PURE__ */ y("form", {
|
|
2776
2776
|
onSubmit: (e) => {
|
|
2777
|
-
e.preventDefault(), !(!
|
|
2777
|
+
e.preventDefault(), !(!se.trim() || N === "streaming") && (Se(se), I(""));
|
|
2778
2778
|
},
|
|
2779
2779
|
className: "bailey-input-row",
|
|
2780
2780
|
children: [/* @__PURE__ */ v("input", {
|
|
2781
|
-
ref:
|
|
2781
|
+
ref: ue,
|
|
2782
2782
|
type: "text",
|
|
2783
|
-
placeholder:
|
|
2784
|
-
"aria-label":
|
|
2785
|
-
value:
|
|
2786
|
-
onChange: (e) =>
|
|
2783
|
+
placeholder: xe,
|
|
2784
|
+
"aria-label": xe,
|
|
2785
|
+
value: se,
|
|
2786
|
+
onChange: (e) => I(e.target.value),
|
|
2787
2787
|
disabled: N === "streaming",
|
|
2788
2788
|
className: "bailey-input"
|
|
2789
2789
|
}), N === "streaming" ? /* @__PURE__ */ v(g.Provider, {
|
|
@@ -2792,7 +2792,7 @@ function Mn({ chat: e, placeholder: t, replyPlaceholder: r = wn, emptyPlaceholde
|
|
|
2792
2792
|
asChild: !0,
|
|
2793
2793
|
children: /* @__PURE__ */ v("button", {
|
|
2794
2794
|
type: "button",
|
|
2795
|
-
onClick:
|
|
2795
|
+
onClick: re,
|
|
2796
2796
|
"aria-label": L.stopAriaLabel,
|
|
2797
2797
|
className: "bailey-stop-button",
|
|
2798
2798
|
children: /* @__PURE__ */ v(Dt, { className: "bailey-stop-icon" })
|
|
@@ -2808,15 +2808,15 @@ function Mn({ chat: e, placeholder: t, replyPlaceholder: r = wn, emptyPlaceholde
|
|
|
2808
2808
|
}) : /* @__PURE__ */ v("button", {
|
|
2809
2809
|
type: "submit",
|
|
2810
2810
|
"aria-label": L.sendAriaLabel,
|
|
2811
|
-
disabled: !
|
|
2811
|
+
disabled: !se.trim(),
|
|
2812
2812
|
className: "bailey-send-button",
|
|
2813
|
-
children: /* @__PURE__ */ v(Et, { className: "bailey-send-icon" })
|
|
2813
|
+
children: ee ?? /* @__PURE__ */ v(Et, { className: "bailey-send-icon" })
|
|
2814
2814
|
})]
|
|
2815
2815
|
}), (!Y || H) && /* @__PURE__ */ y(h.Root, { children: [/* @__PURE__ */ v(h.Trigger, {
|
|
2816
2816
|
asChild: !0,
|
|
2817
2817
|
children: /* @__PURE__ */ v("button", {
|
|
2818
2818
|
type: "button",
|
|
2819
|
-
ref:
|
|
2819
|
+
ref: de,
|
|
2820
2820
|
"aria-label": L.menuAriaLabel,
|
|
2821
2821
|
className: "bailey-menu-button",
|
|
2822
2822
|
children: /* @__PURE__ */ v(Nt, { className: "bailey-menu-icon" })
|
|
@@ -2832,7 +2832,7 @@ function Mn({ chat: e, placeholder: t, replyPlaceholder: r = wn, emptyPlaceholde
|
|
|
2832
2832
|
V.current &&= (e.preventDefault(), !1);
|
|
2833
2833
|
},
|
|
2834
2834
|
children: [!Y && /* @__PURE__ */ y(h.Item, {
|
|
2835
|
-
onSelect: () =>
|
|
2835
|
+
onSelect: () => oe(),
|
|
2836
2836
|
className: "bailey-menu-item",
|
|
2837
2837
|
children: [/* @__PURE__ */ v(Pt, { className: "bailey-menu-item-icon" }), L.newChatButtonText]
|
|
2838
2838
|
}), H && /* @__PURE__ */ y(h.Item, {
|
|
@@ -2841,7 +2841,7 @@ function Mn({ chat: e, placeholder: t, replyPlaceholder: r = wn, emptyPlaceholde
|
|
|
2841
2841
|
c();
|
|
2842
2842
|
return;
|
|
2843
2843
|
}
|
|
2844
|
-
V.current = !0,
|
|
2844
|
+
V.current = !0, fe(!0);
|
|
2845
2845
|
},
|
|
2846
2846
|
className: "bailey-menu-item",
|
|
2847
2847
|
children: [/* @__PURE__ */ v(jt, { className: "bailey-menu-item-icon" }), L.historyMenuItemText]
|
|
@@ -2865,7 +2865,7 @@ function Mn({ chat: e, placeholder: t, replyPlaceholder: r = wn, emptyPlaceholde
|
|
|
2865
2865
|
chat: e,
|
|
2866
2866
|
labels: L,
|
|
2867
2867
|
locale: m,
|
|
2868
|
-
onClose:
|
|
2868
|
+
onClose: Ce
|
|
2869
2869
|
})]
|
|
2870
2870
|
})
|
|
2871
2871
|
});
|
|
@@ -2924,17 +2924,17 @@ function Hn({ messageId: e, onSubmit: t, onClear: n, initialRating: r, reasonOpt
|
|
|
2924
2924
|
let u = {
|
|
2925
2925
|
...Nn,
|
|
2926
2926
|
...o
|
|
2927
|
-
}, p = Rn(i), m = zn(a), h = r ? { rating: r } : null, [b,
|
|
2928
|
-
s(() => (
|
|
2929
|
-
|
|
2927
|
+
}, p = Rn(i), m = zn(a), h = r ? { rating: r } : null, [b, ee] = f(h), [x, S] = f(r ?? null), [C, w] = f(!1), [T, E] = f("down"), [D, O] = f([]), [te, k] = f(""), [A, j] = f(!1), [M, N] = f(!1), [P, ne] = f(!1), [re, ie] = f(!1), ae = d(h), F = d(null), oe = d(0), se = d(!1), I = d(!0), L = d(null), ce = d(null), R = d(null), le = d(null), ue = d(null), de = wt(ce), z = c(), fe = `${z}-comment`, B = `${z}-counter`, V = `${z}-privacy`;
|
|
2928
|
+
s(() => (I.current = !0, () => {
|
|
2929
|
+
I.current = !1;
|
|
2930
2930
|
}), []), s(() => {
|
|
2931
|
-
|
|
2932
|
-
}, [
|
|
2933
|
-
|
|
2931
|
+
C && ue.current?.focus();
|
|
2932
|
+
}, [C]), s(() => {
|
|
2933
|
+
L.current && !P && !C && ((L.current === "up" ? R : le).current?.focus(), L.current = null);
|
|
2934
2934
|
});
|
|
2935
|
-
let
|
|
2936
|
-
|
|
2937
|
-
},
|
|
2935
|
+
let H = () => {
|
|
2936
|
+
O([]), k("");
|
|
2937
|
+
}, U = async (r) => {
|
|
2938
2938
|
try {
|
|
2939
2939
|
return r.kind === "clear" ? await n({ messageId: e }) : await t({
|
|
2940
2940
|
messageId: e,
|
|
@@ -2943,70 +2943,70 @@ function Hn({ messageId: e, onSubmit: t, onClear: n, initialRating: r, reasonOpt
|
|
|
2943
2943
|
} catch {
|
|
2944
2944
|
return !1;
|
|
2945
2945
|
}
|
|
2946
|
-
},
|
|
2947
|
-
if (!
|
|
2948
|
-
|
|
2946
|
+
}, pe = async () => {
|
|
2947
|
+
if (!se.current) {
|
|
2948
|
+
se.current = !0, N(!0);
|
|
2949
2949
|
try {
|
|
2950
|
-
for (; F.current &&
|
|
2951
|
-
let e = F.current, t = e.kind === "clear" ? null : e.snapshot, n = !(e.kind === "submit" && e.formSubmit) && Bn(t, ae.current) || await
|
|
2952
|
-
if (!
|
|
2950
|
+
for (; F.current && I.current;) {
|
|
2951
|
+
let e = F.current, t = e.kind === "clear" ? null : e.snapshot, n = !(e.kind === "submit" && e.formSubmit) && Bn(t, ae.current) || await U(e);
|
|
2952
|
+
if (!I.current) return;
|
|
2953
2953
|
let r = F.current?.version !== e.version;
|
|
2954
|
-
!n && r || (n ? (ae.current = t,
|
|
2954
|
+
!n && r || (n ? (ae.current = t, ee(t)) : (S(ae.current?.rating ?? null), ie(!0)), r || (F.current = null, ne(!1), n && e.kind === "submit" && e.formSubmit && (w(!1), j(!0), L.current = e.snapshot.rating)));
|
|
2955
2955
|
}
|
|
2956
2956
|
} finally {
|
|
2957
|
-
|
|
2957
|
+
se.current = !1, I.current && N(!1);
|
|
2958
2958
|
}
|
|
2959
2959
|
}
|
|
2960
|
-
},
|
|
2961
|
-
|
|
2960
|
+
}, me = (e) => {
|
|
2961
|
+
oe.current += 1, F.current = {
|
|
2962
2962
|
...e,
|
|
2963
|
-
version:
|
|
2964
|
-
}, ie(!1),
|
|
2965
|
-
},
|
|
2966
|
-
|
|
2963
|
+
version: oe.current
|
|
2964
|
+
}, ie(!1), pe();
|
|
2965
|
+
}, W = () => {
|
|
2966
|
+
S(null), w(!1), j(!1), H(), me({ kind: "clear" });
|
|
2967
2967
|
}, G = (e) => {
|
|
2968
2968
|
if (!P) {
|
|
2969
|
-
if (
|
|
2970
|
-
|
|
2969
|
+
if (x === e) {
|
|
2970
|
+
W();
|
|
2971
2971
|
return;
|
|
2972
2972
|
}
|
|
2973
|
-
|
|
2973
|
+
S(e), j(!1), H(), e === "down" ? (E("down"), w(!0)) : w(!1), me({
|
|
2974
2974
|
kind: "submit",
|
|
2975
2975
|
snapshot: { rating: e },
|
|
2976
2976
|
formSubmit: !1
|
|
2977
2977
|
});
|
|
2978
2978
|
}
|
|
2979
2979
|
}, K = (e) => {
|
|
2980
|
-
|
|
2980
|
+
x !== null && (E(x), O((e?.reasonCodes ?? []).map(Ln)), k(e?.comment ?? ""), ie(!1), w(!0));
|
|
2981
2981
|
}, q = () => {
|
|
2982
|
-
P || (
|
|
2982
|
+
P || (w(!1), ie(!1), H(), L.current = T);
|
|
2983
2983
|
}, he = () => {
|
|
2984
2984
|
if (P) return;
|
|
2985
|
-
let e =
|
|
2986
|
-
rating:
|
|
2985
|
+
let e = te.trim(), t = p.filter((e) => D.includes(e)), n = {
|
|
2986
|
+
rating: T,
|
|
2987
2987
|
...t.length > 0 ? { reasonCodes: t } : {},
|
|
2988
2988
|
...e ? { comment: e } : {}
|
|
2989
2989
|
};
|
|
2990
|
-
ne(!0),
|
|
2990
|
+
ne(!0), S(T), me({
|
|
2991
2991
|
kind: "submit",
|
|
2992
2992
|
snapshot: n,
|
|
2993
2993
|
formSubmit: !0
|
|
2994
2994
|
});
|
|
2995
2995
|
}, ge = (e) => {
|
|
2996
|
-
|
|
2996
|
+
O((t) => t.includes(e) ? t.filter((t) => t !== e) : [...t, e]);
|
|
2997
2997
|
}, _e = (e) => {
|
|
2998
2998
|
e.key === "Escape" && (e.stopPropagation(), q());
|
|
2999
|
-
}, ve =
|
|
3000
|
-
let t =
|
|
2999
|
+
}, ve = x !== null && b?.rating === x && !M && !C, J = !!b && (!!b.comment || (b.reasonCodes?.length ?? 0) > 0), ye = M ? u.feedbackSavingText : ve ? u.feedbackThanksText : "", be = (e) => {
|
|
3000
|
+
let t = x === e, n = e === "up" ? u.feedbackThumbsUpAriaLabel : u.feedbackThumbsDownAriaLabel, r = e === "up" ? Lt : Rt;
|
|
3001
3001
|
return /* @__PURE__ */ y(g.Root, { children: [/* @__PURE__ */ v(g.Trigger, {
|
|
3002
3002
|
asChild: !0,
|
|
3003
3003
|
children: /* @__PURE__ */ v("button", {
|
|
3004
|
-
ref: e === "up" ?
|
|
3004
|
+
ref: e === "up" ? R : le,
|
|
3005
3005
|
type: "button",
|
|
3006
3006
|
className: "bailey-feedback-thumb",
|
|
3007
3007
|
"aria-pressed": t,
|
|
3008
3008
|
"aria-label": n,
|
|
3009
|
-
"aria-busy": t &&
|
|
3009
|
+
"aria-busy": t && M ? !0 : void 0,
|
|
3010
3010
|
disabled: P,
|
|
3011
3011
|
onClick: () => G(e),
|
|
3012
3012
|
children: /* @__PURE__ */ v(r, {
|
|
@@ -3015,7 +3015,7 @@ function Hn({ messageId: e, onSubmit: t, onClear: n, initialRating: r, reasonOpt
|
|
|
3015
3015
|
})
|
|
3016
3016
|
})
|
|
3017
3017
|
}), /* @__PURE__ */ v(g.Portal, {
|
|
3018
|
-
container:
|
|
3018
|
+
container: de instanceof ShadowRoot ? de : void 0,
|
|
3019
3019
|
children: /* @__PURE__ */ y(g.Content, {
|
|
3020
3020
|
side: "top",
|
|
3021
3021
|
className: "bailey-tooltip-content",
|
|
@@ -3024,7 +3024,7 @@ function Hn({ messageId: e, onSubmit: t, onClear: n, initialRating: r, reasonOpt
|
|
|
3024
3024
|
})] });
|
|
3025
3025
|
};
|
|
3026
3026
|
return /* @__PURE__ */ y("div", {
|
|
3027
|
-
ref:
|
|
3027
|
+
ref: ce,
|
|
3028
3028
|
className: `bailey-feedback${l ? ` ${l}` : ""}`,
|
|
3029
3029
|
children: [
|
|
3030
3030
|
/* @__PURE__ */ v(g.Provider, {
|
|
@@ -3032,15 +3032,15 @@ function Hn({ messageId: e, onSubmit: t, onClear: n, initialRating: r, reasonOpt
|
|
|
3032
3032
|
children: /* @__PURE__ */ y("div", {
|
|
3033
3033
|
role: "group",
|
|
3034
3034
|
"aria-label": u.feedbackGroupLabel,
|
|
3035
|
-
"aria-busy":
|
|
3035
|
+
"aria-busy": M ? !0 : void 0,
|
|
3036
3036
|
className: "bailey-feedback-thumbs",
|
|
3037
|
-
children: [
|
|
3037
|
+
children: [be("up"), be("down")]
|
|
3038
3038
|
})
|
|
3039
3039
|
}),
|
|
3040
3040
|
/* @__PURE__ */ y("span", {
|
|
3041
3041
|
role: "status",
|
|
3042
3042
|
className: "bailey-feedback-status",
|
|
3043
|
-
children: [
|
|
3043
|
+
children: [M && /* @__PURE__ */ v("span", {
|
|
3044
3044
|
className: "bailey-feedback-spinner",
|
|
3045
3045
|
"aria-hidden": "true"
|
|
3046
3046
|
}), ye]
|
|
@@ -3049,11 +3049,11 @@ function Hn({ messageId: e, onSubmit: t, onClear: n, initialRating: r, reasonOpt
|
|
|
3049
3049
|
type: "button",
|
|
3050
3050
|
className: "bailey-feedback-link",
|
|
3051
3051
|
onClick: () => K(b),
|
|
3052
|
-
children:
|
|
3052
|
+
children: A || J ? u.feedbackEditText : u.feedbackAddCommentText
|
|
3053
3053
|
}), /* @__PURE__ */ v("button", {
|
|
3054
3054
|
type: "button",
|
|
3055
3055
|
className: "bailey-feedback-link",
|
|
3056
|
-
onClick:
|
|
3056
|
+
onClick: W,
|
|
3057
3057
|
children: u.feedbackUndoText
|
|
3058
3058
|
})] }),
|
|
3059
3059
|
re && /* @__PURE__ */ v("span", {
|
|
@@ -3061,7 +3061,7 @@ function Hn({ messageId: e, onSubmit: t, onClear: n, initialRating: r, reasonOpt
|
|
|
3061
3061
|
className: "bailey-feedback-error",
|
|
3062
3062
|
children: u.feedbackErrorText
|
|
3063
3063
|
}),
|
|
3064
|
-
|
|
3064
|
+
C && /* @__PURE__ */ y("div", {
|
|
3065
3065
|
className: "bailey-feedback-form",
|
|
3066
3066
|
onKeyDown: _e,
|
|
3067
3067
|
children: [
|
|
@@ -3078,7 +3078,7 @@ function Hn({ messageId: e, onSubmit: t, onClear: n, initialRating: r, reasonOpt
|
|
|
3078
3078
|
} : void 0,
|
|
3079
3079
|
type: "button",
|
|
3080
3080
|
className: "bailey-feedback-chip",
|
|
3081
|
-
"aria-pressed":
|
|
3081
|
+
"aria-pressed": D.includes(e),
|
|
3082
3082
|
disabled: P,
|
|
3083
3083
|
onClick: () => ge(e),
|
|
3084
3084
|
children: u[In[e]]
|
|
@@ -3086,33 +3086,33 @@ function Hn({ messageId: e, onSubmit: t, onClear: n, initialRating: r, reasonOpt
|
|
|
3086
3086
|
})]
|
|
3087
3087
|
}),
|
|
3088
3088
|
/* @__PURE__ */ v("label", {
|
|
3089
|
-
htmlFor:
|
|
3089
|
+
htmlFor: fe,
|
|
3090
3090
|
className: "bailey-feedback-legend",
|
|
3091
3091
|
children: u.feedbackCommentLabel
|
|
3092
3092
|
}),
|
|
3093
3093
|
/* @__PURE__ */ v("textarea", {
|
|
3094
|
-
id:
|
|
3094
|
+
id: fe,
|
|
3095
3095
|
ref: p.length === 0 ? (e) => {
|
|
3096
3096
|
ue.current = e;
|
|
3097
3097
|
} : void 0,
|
|
3098
3098
|
className: "bailey-feedback-textarea",
|
|
3099
|
-
value:
|
|
3099
|
+
value: te,
|
|
3100
3100
|
maxLength: m,
|
|
3101
3101
|
placeholder: u.feedbackCommentPlaceholder,
|
|
3102
|
-
"aria-describedby": `${
|
|
3102
|
+
"aria-describedby": `${B} ${V}`,
|
|
3103
3103
|
disabled: P,
|
|
3104
|
-
onChange: (e) =>
|
|
3104
|
+
onChange: (e) => k(e.target.value.slice(0, m))
|
|
3105
3105
|
}),
|
|
3106
3106
|
/* @__PURE__ */ y("div", {
|
|
3107
3107
|
className: "bailey-feedback-meta",
|
|
3108
3108
|
children: [/* @__PURE__ */ v("span", {
|
|
3109
|
-
id:
|
|
3109
|
+
id: V,
|
|
3110
3110
|
className: "bailey-feedback-privacy",
|
|
3111
3111
|
children: u.feedbackPrivacyNote
|
|
3112
3112
|
}), /* @__PURE__ */ v("span", {
|
|
3113
|
-
id:
|
|
3113
|
+
id: B,
|
|
3114
3114
|
className: "bailey-feedback-counter",
|
|
3115
|
-
children: `${
|
|
3115
|
+
children: `${te.length} / ${m}`
|
|
3116
3116
|
})]
|
|
3117
3117
|
}),
|
|
3118
3118
|
/* @__PURE__ */ y("div", {
|
|
@@ -3140,4 +3140,4 @@ function Hn({ messageId: e, onSubmit: t, onClear: n, initialRating: r, reasonOpt
|
|
|
3140
3140
|
//#region src/index.ts
|
|
3141
3141
|
var Un = "0.3.1-pre.2";
|
|
3142
3142
|
//#endregion
|
|
3143
|
-
export { Mt as ActivityIcon, Ot as ArrowUpRightIcon, Un as BAILEYAI_CHAT_UI_VERSION, Ve as BAILEY_CHART_PROMPT_FRAGMENT, Ne as BAILEY_TABLE_GRID_ROW_THRESHOLD,
|
|
3143
|
+
export { Mt as ActivityIcon, Ot as ArrowUpRightIcon, Un as BAILEYAI_CHAT_UI_VERSION, Ve as BAILEY_CHART_PROMPT_FRAGMENT, Ne as BAILEY_TABLE_GRID_ROW_THRESHOLD, V as BaileyApiError, Mn as BaileyChatPanel, U as BaileyCleanupError, Vn as BaileyFeedbackButtons, vn as BaileyHistoryDrawer, Qt as BaileyTracePanel, Ut as CopyMarkdownButton, ie as DEFAULT_CONVERSATION_STORAGE_KEY, Et as HeartIcon, Ye as TRACE_KIND_LABEL, Rt as ThumbDownIcon, Lt as ThumbUpIcon, Oe as createBaileyClient, ke as createBaileyFeedbackHandlers, Tt as createBaileyMarkdownComponents, F as createMemoryConversationStorage, ae as createSessionConversationStorage, O as extractPseudoToolCalls, ze as extractTableData, _n as formatRelativeTime, at as formatTraceGap, it as formatTraceTime, lt as hasTraceFailure, re as isConversationIdForSub, e as isSafeMarkdownUrl, Ae as joinInstructions, N as mapTranscript, ne as mergeEarlierPage, Je as parseBaileyChartSpec, k as parseSseFrames, $ as resolveToolCall, Be as shouldUseGrid, ut as toActivityLines, dt as toToolSteps, ot as toTraceRows, ct as toTraceSegments, $e as traceEventArgsDetail, rt as traceEventHint, et as traceEventOutputDetail, nt as traceEventRawDetail, Qe as traceEventSummary, Ze as traceEventToolName, st as traceSummaryLine, B as useBaileyChat, me as useBaileyConversations };
|