@icanbwell/baileyai-chat-ui 0.3.1-pre.1 → 0.3.3
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 +27 -0
- package/dist/baileyai-chat-ui.cjs +5 -5
- package/dist/baileyai-chat-ui.js +226 -228
- package/dist/chart.cjs +1 -0
- package/dist/chart.d.ts +36 -0
- package/dist/chart.js +67 -0
- package/dist/safeMarkdownUrl-DsMPGzpD.cjs +1 -0
- package/dist/safeMarkdownUrl-xI42YYzd.js +7 -0
- package/dist/table.cjs +1 -0
- package/dist/table.d.ts +20 -0
- package/dist/table.js +65 -0
- package/package.json +49 -2
package/dist/baileyai-chat-ui.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import o from "react
|
|
3
|
-
import s from "
|
|
4
|
-
import
|
|
5
|
-
import
|
|
1
|
+
import { t as e } from "./safeMarkdownUrl-xI42YYzd.js";
|
|
2
|
+
import { memo as t, useCallback as n, useEffect as r, useMemo as i, useRef as a, useState as o } from "react";
|
|
3
|
+
import s from "react-markdown";
|
|
4
|
+
import c from "remark-gfm";
|
|
5
|
+
import { Fragment as l, jsx as u, jsxs as d } from "react/jsx-runtime";
|
|
6
|
+
import * as f from "@radix-ui/react-tooltip";
|
|
6
7
|
//#region src/utils/pseudoToolCalls.ts
|
|
7
|
-
var
|
|
8
|
-
function
|
|
9
|
-
let t =
|
|
8
|
+
var p = /<(search_tools|call_tool)>([\s\S]*?)<\/\1>/g, m = /<name>([\s\S]*?)<\/name>/, h = /<arguments>([\s\S]*?)<\/arguments>/;
|
|
9
|
+
function g(e) {
|
|
10
|
+
let t = m.exec(e)?.[1]?.trim() || "unknown_tool", n = h.exec(e)?.[1]?.trim();
|
|
10
11
|
return n ? {
|
|
11
12
|
name: t,
|
|
12
13
|
args: n
|
|
13
14
|
} : { name: t };
|
|
14
15
|
}
|
|
15
|
-
function
|
|
16
|
-
let t = [], n = e.replace(
|
|
16
|
+
function _(e) {
|
|
17
|
+
let t = [], n = e.replace(p, (e, n, r) => (t.push(n === "call_tool" ? g(r) : {
|
|
17
18
|
name: "search_tools",
|
|
18
19
|
args: r.trim()
|
|
19
20
|
}), ""));
|
|
@@ -27,7 +28,7 @@ function g(e) {
|
|
|
27
28
|
}
|
|
28
29
|
//#endregion
|
|
29
30
|
//#region src/logic/sse.ts
|
|
30
|
-
function
|
|
31
|
+
function v(e) {
|
|
31
32
|
if (!e.startsWith("data: ")) return e;
|
|
32
33
|
let t = "";
|
|
33
34
|
for (let n of e.split("\n")) {
|
|
@@ -41,7 +42,7 @@ function _(e) {
|
|
|
41
42
|
}
|
|
42
43
|
return t || null;
|
|
43
44
|
}
|
|
44
|
-
function
|
|
45
|
+
function y(e) {
|
|
45
46
|
let t = e.replace(/\r\n/g, "\n").split("\n\n"), n = t.pop() ?? "", r = [], i = !1;
|
|
46
47
|
for (let e of t) {
|
|
47
48
|
let t = e.split("\n").filter((e) => e.length > 0), n = "message", a = [];
|
|
@@ -66,7 +67,7 @@ function v(e) {
|
|
|
66
67
|
message: e
|
|
67
68
|
});
|
|
68
69
|
} else if (c?.type === "response.output_text.delta" && typeof c.delta == "string") {
|
|
69
|
-
let e =
|
|
70
|
+
let e = v(c.delta);
|
|
70
71
|
e && r.push({
|
|
71
72
|
type: "response.output_text.delta",
|
|
72
73
|
delta: e
|
|
@@ -84,22 +85,22 @@ function v(e) {
|
|
|
84
85
|
}
|
|
85
86
|
//#endregion
|
|
86
87
|
//#region src/logic/useBaileyChat.ts
|
|
87
|
-
var
|
|
88
|
+
var b = 200, x = 15e4, S = (e, t, n) => {
|
|
88
89
|
if (e === 401 || e === 403) return "Bailey isn't reachable with your current login.";
|
|
89
90
|
let r = `Bailey request failed (status ${e ?? "network error"}).`, i = (n || t || "").trim();
|
|
90
|
-
return i ? `${r} ${i.length >
|
|
91
|
-
},
|
|
92
|
-
let [f, p] =
|
|
93
|
-
|
|
91
|
+
return i ? `${r} ${i.length > b ? `${i.slice(0, b)}…` : i}` : r;
|
|
92
|
+
}, C = ({ transport: e, model: t, instructions: i, tools: s = [], toolChoice: c, firstUserMessagePrefix: l, onAssistantMessageComplete: u, idleTimeoutMs: d = x }) => {
|
|
93
|
+
let [f, p] = o([]), [m, h] = o([]), [g, v] = o(null), [b, C] = o("idle"), [w, T] = o(null), E = a(null), D = a(""), O = a(0), k = a([]);
|
|
94
|
+
r(() => {
|
|
94
95
|
k.current = f;
|
|
95
96
|
}, [f]);
|
|
96
|
-
let A =
|
|
97
|
+
let A = a(/* @__PURE__ */ new Map()), j = a(/* @__PURE__ */ new Map()), M = a(null), N = n(() => {
|
|
97
98
|
M.current !== null && (clearTimeout(M.current), M.current = null);
|
|
98
|
-
}, []), P =
|
|
99
|
+
}, []), P = n((e) => {
|
|
99
100
|
N(), M.current = setTimeout(() => {
|
|
100
101
|
e.abort(new DOMException("The assistant took too long to respond. Please try again.", "TimeoutError"));
|
|
101
102
|
}, d);
|
|
102
|
-
}, [N, d]), F =
|
|
103
|
+
}, [N, d]), F = n((e, t, n) => {
|
|
103
104
|
let r = (e) => {
|
|
104
105
|
n.push(e), h((t) => [...t, e]);
|
|
105
106
|
};
|
|
@@ -110,7 +111,7 @@ var y = 200, b = 15e4, x = (e, t, n) => {
|
|
|
110
111
|
emittedCount: 0
|
|
111
112
|
};
|
|
112
113
|
n.raw += t.delta;
|
|
113
|
-
let { cleanedText: i, matches: a } =
|
|
114
|
+
let { cleanedText: i, matches: a } = _(n.raw), o = i.trim(), s = a.slice(n.emittedCount);
|
|
114
115
|
if (n.emittedCount = a.length, A.current.set(e, n), j.current.set(e, o), p((t) => t.map((t) => t.id === e ? {
|
|
115
116
|
...t,
|
|
116
117
|
content: o
|
|
@@ -167,32 +168,32 @@ var y = 200, b = 15e4, x = (e, t, n) => {
|
|
|
167
168
|
at: Date.now(),
|
|
168
169
|
turnSentAt: O.current
|
|
169
170
|
}), !0);
|
|
170
|
-
}, []), I =
|
|
171
|
+
}, []), I = n(async (n) => {
|
|
171
172
|
C("streaming"), T(null);
|
|
172
|
-
let
|
|
173
|
+
let r = crypto.randomUUID();
|
|
173
174
|
p((e) => [...e, {
|
|
174
|
-
id:
|
|
175
|
+
id: r,
|
|
175
176
|
role: "assistant",
|
|
176
177
|
content: "",
|
|
177
178
|
streaming: !0
|
|
178
179
|
}]);
|
|
179
|
-
let
|
|
180
|
-
O.current =
|
|
181
|
-
let
|
|
180
|
+
let a = Date.now();
|
|
181
|
+
O.current = a;
|
|
182
|
+
let o = n.map((e, t) => t === 0 && e.role === "user" && l ? {
|
|
182
183
|
role: e.role,
|
|
183
184
|
content: `${l}${e.content}`
|
|
184
185
|
} : {
|
|
185
186
|
role: e.role,
|
|
186
187
|
content: e.content
|
|
187
188
|
});
|
|
188
|
-
|
|
189
|
-
model:
|
|
190
|
-
systemPrompt:
|
|
191
|
-
messages:
|
|
189
|
+
v({
|
|
190
|
+
model: t,
|
|
191
|
+
systemPrompt: i,
|
|
192
|
+
messages: o,
|
|
192
193
|
tools: s,
|
|
193
194
|
toolChoice: c,
|
|
194
195
|
stream: !0,
|
|
195
|
-
sentAt:
|
|
196
|
+
sentAt: a,
|
|
196
197
|
streamStats: {
|
|
197
198
|
chunkCount: 0,
|
|
198
199
|
firstChunkAt: null,
|
|
@@ -201,13 +202,13 @@ var y = 200, b = 15e4, x = (e, t, n) => {
|
|
|
201
202
|
});
|
|
202
203
|
let d = new AbortController();
|
|
203
204
|
E.current = d, P(d);
|
|
204
|
-
let f = "", m = null, g = !1, _ = !1, b = [],
|
|
205
|
+
let f = "", m = null, g = !1, _ = !1, b = [], x = (e, t) => {
|
|
205
206
|
C("error"), T(e);
|
|
206
207
|
let n = {
|
|
207
208
|
kind: "error",
|
|
208
209
|
message: e,
|
|
209
210
|
at: Date.now(),
|
|
210
|
-
turnSentAt:
|
|
211
|
+
turnSentAt: a,
|
|
211
212
|
...t
|
|
212
213
|
};
|
|
213
214
|
b.push(n), h((e) => [...e, n]);
|
|
@@ -219,76 +220,76 @@ var y = 200, b = 15e4, x = (e, t, n) => {
|
|
|
219
220
|
kind: "error",
|
|
220
221
|
message: e.message,
|
|
221
222
|
at: Date.now(),
|
|
222
|
-
turnSentAt:
|
|
223
|
+
turnSentAt: a
|
|
223
224
|
};
|
|
224
225
|
b.push(t), h((e) => [...e, t]);
|
|
225
226
|
return;
|
|
226
227
|
}
|
|
227
|
-
e.type === "response.output_text.delta" && e.delta && (_ = !0), F(
|
|
228
|
-
}), t && p((e) => e.map((e) => e.id ===
|
|
228
|
+
e.type === "response.output_text.delta" && e.delta && (_ = !0), F(r, e, b) && (g = !0);
|
|
229
|
+
}), t && p((e) => e.map((e) => e.id === r ? {
|
|
229
230
|
...e,
|
|
230
231
|
streaming: !1
|
|
231
232
|
} : e));
|
|
232
233
|
};
|
|
233
234
|
try {
|
|
234
|
-
let { status:
|
|
235
|
-
model:
|
|
236
|
-
instructions:
|
|
237
|
-
input:
|
|
235
|
+
let { status: n, text: l, errorMessage: p } = await e.streamChat({
|
|
236
|
+
model: t,
|
|
237
|
+
instructions: i,
|
|
238
|
+
input: o,
|
|
238
239
|
tools: s,
|
|
239
240
|
toolChoice: c,
|
|
240
241
|
signal: d.signal,
|
|
241
242
|
onChunk: (e) => {
|
|
242
243
|
P(d), f += e;
|
|
243
|
-
let { events: t, remainder: n, done: r } =
|
|
244
|
+
let { events: t, remainder: n, done: r } = y(f);
|
|
244
245
|
f = n, w(t, r);
|
|
245
|
-
let
|
|
246
|
-
|
|
246
|
+
let i = Date.now();
|
|
247
|
+
v((e) => e && e.sentAt === a ? {
|
|
247
248
|
...e,
|
|
248
249
|
streamStats: {
|
|
249
250
|
chunkCount: e.streamStats.chunkCount + 1,
|
|
250
|
-
firstChunkAt: e.streamStats.firstChunkAt ??
|
|
251
|
-
lastChunkAt:
|
|
251
|
+
firstChunkAt: e.streamStats.firstChunkAt ?? i,
|
|
252
|
+
lastChunkAt: i
|
|
252
253
|
}
|
|
253
254
|
} : e);
|
|
254
255
|
},
|
|
255
256
|
onRequestId: (e) => {
|
|
256
|
-
|
|
257
|
+
v((t) => t && t.sentAt === a ? {
|
|
257
258
|
...t,
|
|
258
259
|
requestId: e
|
|
259
260
|
} : t);
|
|
260
261
|
}
|
|
261
262
|
});
|
|
262
263
|
if (f.trim()) {
|
|
263
|
-
let { events: e, done: t } =
|
|
264
|
+
let { events: e, done: t } = y(`${f}\n\n`);
|
|
264
265
|
f = "", w(e, t);
|
|
265
266
|
}
|
|
266
267
|
if (m) {
|
|
267
268
|
C("error"), T(m);
|
|
268
269
|
return;
|
|
269
270
|
}
|
|
270
|
-
if (
|
|
271
|
-
S(
|
|
272
|
-
httpStatus:
|
|
271
|
+
if (n === void 0 || n >= 400) {
|
|
272
|
+
x(S(n, l, p), {
|
|
273
|
+
httpStatus: n,
|
|
273
274
|
rawBody: l || void 0
|
|
274
275
|
});
|
|
275
276
|
return;
|
|
276
277
|
}
|
|
277
278
|
if (!g) {
|
|
278
|
-
|
|
279
|
+
x("Bailey returned an empty response.");
|
|
279
280
|
return;
|
|
280
281
|
}
|
|
281
282
|
if (!_) {
|
|
282
|
-
|
|
283
|
+
x("Bailey ran some tools but didn't return an answer. Try asking again.");
|
|
283
284
|
return;
|
|
284
285
|
}
|
|
285
286
|
C("idle");
|
|
286
|
-
let h = j.current.get(
|
|
287
|
-
|
|
287
|
+
let h = j.current.get(r) ?? "";
|
|
288
|
+
v((e) => e && e.sentAt === a ? {
|
|
288
289
|
...e,
|
|
289
290
|
response: { content: h }
|
|
290
291
|
} : e), u && await u({
|
|
291
|
-
id:
|
|
292
|
+
id: r,
|
|
292
293
|
role: "assistant",
|
|
293
294
|
content: h,
|
|
294
295
|
streaming: !1
|
|
@@ -296,24 +297,24 @@ var y = 200, b = 15e4, x = (e, t, n) => {
|
|
|
296
297
|
} catch (e) {
|
|
297
298
|
let t = e;
|
|
298
299
|
if (t?.name === "TimeoutError") {
|
|
299
|
-
|
|
300
|
+
x(t.message, { source: "client-timeout" });
|
|
300
301
|
return;
|
|
301
302
|
}
|
|
302
303
|
if (t?.name === "AbortError") {
|
|
303
304
|
C("idle");
|
|
304
305
|
return;
|
|
305
306
|
}
|
|
306
|
-
|
|
307
|
+
x(t?.message || "Bailey request failed.");
|
|
307
308
|
} finally {
|
|
308
|
-
N(), A.current.delete(
|
|
309
|
+
N(), A.current.delete(r), j.current.delete(r), p((e) => e.flatMap((e) => e.id === r ? e.content ? [{
|
|
309
310
|
...e,
|
|
310
311
|
streaming: !1
|
|
311
312
|
}] : [] : [e]));
|
|
312
313
|
}
|
|
313
314
|
}, [
|
|
314
315
|
e,
|
|
315
|
-
|
|
316
|
-
|
|
316
|
+
t,
|
|
317
|
+
i,
|
|
317
318
|
s,
|
|
318
319
|
c,
|
|
319
320
|
l,
|
|
@@ -321,16 +322,16 @@ var y = 200, b = 15e4, x = (e, t, n) => {
|
|
|
321
322
|
F,
|
|
322
323
|
P,
|
|
323
324
|
N
|
|
324
|
-
]), L =
|
|
325
|
+
]), L = n((e) => {
|
|
325
326
|
k.current = e, p(e);
|
|
326
327
|
}, []);
|
|
327
328
|
return {
|
|
328
329
|
messages: f,
|
|
329
330
|
traceEvents: m,
|
|
330
|
-
lastRequest:
|
|
331
|
-
status:
|
|
331
|
+
lastRequest: g,
|
|
332
|
+
status: b,
|
|
332
333
|
error: w,
|
|
333
|
-
send:
|
|
334
|
+
send: n((e) => {
|
|
334
335
|
let t = e.trim();
|
|
335
336
|
if (!t) return;
|
|
336
337
|
D.current = t;
|
|
@@ -341,34 +342,34 @@ var y = 200, b = 15e4, x = (e, t, n) => {
|
|
|
341
342
|
}];
|
|
342
343
|
L(n), I(n);
|
|
343
344
|
}, [I, L]),
|
|
344
|
-
stop:
|
|
345
|
+
stop: n(() => {
|
|
345
346
|
E.current?.abort();
|
|
346
347
|
}, []),
|
|
347
|
-
retryLast:
|
|
348
|
+
retryLast: n(() => {
|
|
348
349
|
if (!D.current) return;
|
|
349
350
|
let e = k.current, t = e[e.length - 1], n = t && t.role === "assistant" ? e.slice(0, -1) : e;
|
|
350
351
|
L(n), I(n);
|
|
351
352
|
}, [I, L]),
|
|
352
|
-
clearTrace:
|
|
353
|
-
clearError:
|
|
353
|
+
clearTrace: n(() => h([]), []),
|
|
354
|
+
clearError: n(() => {
|
|
354
355
|
T(null), C((e) => e === "error" ? "idle" : e);
|
|
355
356
|
}, []),
|
|
356
|
-
newChat:
|
|
357
|
-
E.current?.abort(), L([]), h([]),
|
|
357
|
+
newChat: n(() => {
|
|
358
|
+
E.current?.abort(), L([]), h([]), v(null), C("idle"), T(null), D.current = "";
|
|
358
359
|
}, [L])
|
|
359
360
|
};
|
|
360
361
|
};
|
|
361
362
|
//#endregion
|
|
362
363
|
//#region src/utils/prompt.ts
|
|
363
|
-
function
|
|
364
|
+
function w(...e) {
|
|
364
365
|
return e.filter((e) => !!(e && e.trim())).join("\n\n");
|
|
365
366
|
}
|
|
366
367
|
//#endregion
|
|
367
368
|
//#region src/utils/toolCalls.ts
|
|
368
|
-
var
|
|
369
|
-
function
|
|
369
|
+
var T = "call_tool", E = "a tool";
|
|
370
|
+
function D(e, t) {
|
|
370
371
|
let n = {
|
|
371
|
-
name: e ===
|
|
372
|
+
name: e === T ? E : e,
|
|
372
373
|
args: null,
|
|
373
374
|
viaCallTool: !1
|
|
374
375
|
};
|
|
@@ -381,7 +382,7 @@ function E(e, t) {
|
|
|
381
382
|
}
|
|
382
383
|
if (typeof r != "object" || !r) return n;
|
|
383
384
|
let i = r;
|
|
384
|
-
if (e ===
|
|
385
|
+
if (e === T) {
|
|
385
386
|
let e = typeof i.name == "string" ? i.name : void 0;
|
|
386
387
|
if (!e) return n;
|
|
387
388
|
let t = i.arguments;
|
|
@@ -398,36 +399,33 @@ function E(e, t) {
|
|
|
398
399
|
};
|
|
399
400
|
}
|
|
400
401
|
//#endregion
|
|
401
|
-
//#region src/utils/
|
|
402
|
-
var
|
|
403
|
-
let t = O(e);
|
|
404
|
-
return !/^[a-z][a-z0-9+.-]*:/i.test(t) || D.test(t);
|
|
405
|
-
}, A = 5, j = (e) => e.type === "text" ? e.value ?? "" : (e.children ?? []).map(j).join(""), M = (e) => {
|
|
402
|
+
//#region src/utils/table.ts
|
|
403
|
+
var O = 5, k = (e) => e.type === "text" ? e.value ?? "" : (e.children ?? []).map(k).join(""), A = (e) => {
|
|
406
404
|
if (e.tagName === "a" && e.properties?.href) return e.properties.href;
|
|
407
405
|
for (let t of e.children ?? []) {
|
|
408
|
-
let e =
|
|
406
|
+
let e = A(t);
|
|
409
407
|
if (e) return e;
|
|
410
408
|
}
|
|
411
|
-
},
|
|
412
|
-
let t =
|
|
409
|
+
}, j = (e, t) => (e.children ?? []).find((e) => e.tagName === t), M = (e) => {
|
|
410
|
+
let t = k(e), n = A(e);
|
|
413
411
|
return n ? {
|
|
414
412
|
text: t,
|
|
415
413
|
href: n
|
|
416
414
|
} : { text: t };
|
|
417
|
-
},
|
|
415
|
+
}, N = (e) => (e.children ?? []).filter((e) => e.type === "element").map(M), P = (e) => {
|
|
418
416
|
if (e.tagName !== "table") return null;
|
|
419
|
-
let t =
|
|
417
|
+
let t = j(e, "thead"), n = t && j(t, "tr");
|
|
420
418
|
return {
|
|
421
|
-
headers: n ?
|
|
422
|
-
rows: (
|
|
419
|
+
headers: n ? N(n).map((e) => e.text) : [],
|
|
420
|
+
rows: (j(e, "tbody")?.children ?? []).filter((e) => e.tagName === "tr").map(N)
|
|
423
421
|
};
|
|
424
|
-
},
|
|
422
|
+
}, F = (e) => e.length > 5, I = "When a chart would help answer a question (e.g. plotting a trend over time), include a fenced code block tagged `chartjs` containing a JSON object with this exact shape: {\"type\": \"bar\" | \"line\" | \"pie\" | \"doughnut\" | \"scatter\", \"title\"?: string, \"data\": {\"labels\": string[], \"datasets\": [{\"label\": string, \"data\": number[]}]}}. For \"scatter\" charts, omit \"labels\" and give each dataset \"data\" as an array of {\"x\": number, \"y\": number} points instead of a number array. \"pie\" and \"doughnut\" charts must have exactly one dataset. Do not include any other fields (no \"options\", no colors) — the app handles styling. Example:\n```chartjs\n{\"type\": \"line\", \"title\": \"BP readings\", \"data\": {\"labels\": [\"Jul 14\", \"Jul 21\", \"Jul 28\"], \"datasets\": [{\"label\": \"Systolic\", \"data\": [120, 118, 122]}]}}\n```", L = [
|
|
425
423
|
"bar",
|
|
426
424
|
"line",
|
|
427
425
|
"pie",
|
|
428
426
|
"doughnut",
|
|
429
427
|
"scatter"
|
|
430
|
-
],
|
|
428
|
+
], ee = 8, te = 50, ne = 8, re = 500, ie = (e) => typeof e == "object" && !!e && typeof e.x == "number" && typeof e.y == "number", R = (e) => {
|
|
431
429
|
let t;
|
|
432
430
|
try {
|
|
433
431
|
t = JSON.parse(e);
|
|
@@ -436,17 +434,17 @@ var D = /^(https?|mailto):/i, O = (e) => e.replace(/[\t\n\r]/g, "").trim(), k =
|
|
|
436
434
|
}
|
|
437
435
|
if (typeof t != "object" || !t) return null;
|
|
438
436
|
let n = t;
|
|
439
|
-
if (typeof n.type != "string" || !
|
|
437
|
+
if (typeof n.type != "string" || !L.includes(n.type)) return null;
|
|
440
438
|
let r = n.type;
|
|
441
439
|
if (n.title !== void 0 && typeof n.title != "string") return null;
|
|
442
440
|
let i = n.title;
|
|
443
441
|
if (typeof n.data != "object" || n.data === null) return null;
|
|
444
442
|
let a = n.data;
|
|
445
|
-
if (!Array.isArray(a.datasets) || a.datasets.length < 1 || a.datasets.length >
|
|
443
|
+
if (!Array.isArray(a.datasets) || a.datasets.length < 1 || a.datasets.length > ee || (r === "pie" || r === "doughnut") && a.datasets.length !== 1) return null;
|
|
446
444
|
for (let e of a.datasets) if (typeof e != "object" || !e || typeof e.label != "string" || !Array.isArray(e.data)) return null;
|
|
447
445
|
let o = a.datasets;
|
|
448
446
|
if (r === "scatter") {
|
|
449
|
-
for (let e of o) if (e.data.length < 1 || e.data.length >
|
|
447
|
+
for (let e of o) if (e.data.length < 1 || e.data.length > re || !e.data.every(ie)) return null;
|
|
450
448
|
return {
|
|
451
449
|
type: r,
|
|
452
450
|
title: i,
|
|
@@ -454,7 +452,7 @@ var D = /^(https?|mailto):/i, O = (e) => e.replace(/[\t\n\r]/g, "").trim(), k =
|
|
|
454
452
|
};
|
|
455
453
|
}
|
|
456
454
|
if (!Array.isArray(a.labels) || !a.labels.every((e) => typeof e == "string")) return null;
|
|
457
|
-
let s = a.labels, c = r === "pie" || r === "doughnut" ?
|
|
455
|
+
let s = a.labels, c = r === "pie" || r === "doughnut" ? ne : te;
|
|
458
456
|
if (s.length < 1 || s.length > c) return null;
|
|
459
457
|
for (let e of o) if (e.data.length !== s.length || !e.data.every((e) => typeof e == "number")) return null;
|
|
460
458
|
return {
|
|
@@ -475,7 +473,7 @@ var D = /^(https?|mailto):/i, O = (e) => e.replace(/[\t\n\r]/g, "").trim(), k =
|
|
|
475
473
|
raw: "Raw event"
|
|
476
474
|
};
|
|
477
475
|
function B(e) {
|
|
478
|
-
return e.kind !== "tool_start" && e.kind !== "tool_end" ? null :
|
|
476
|
+
return e.kind !== "tool_start" && e.kind !== "tool_end" ? null : D(e.name, e.args);
|
|
479
477
|
}
|
|
480
478
|
function V(e, t = B(e)) {
|
|
481
479
|
return e.kind === "pseudo_tool_call" ? e.name : t?.name ?? null;
|
|
@@ -502,9 +500,9 @@ function G(e) {
|
|
|
502
500
|
}
|
|
503
501
|
function K(e) {
|
|
504
502
|
switch (e.kind) {
|
|
505
|
-
case "tool_start": return `Calling ${
|
|
503
|
+
case "tool_start": return `Calling ${D(e.name, e.args).name}...`;
|
|
506
504
|
case "tool_end": {
|
|
507
|
-
let t =
|
|
505
|
+
let t = D(e.name, e.args).name;
|
|
508
506
|
return e.isError ? `${t} failed` : `${t} returned`;
|
|
509
507
|
}
|
|
510
508
|
case "pseudo_tool_call": return `${e.name} (written as text, not called)`;
|
|
@@ -549,7 +547,7 @@ function X(e) {
|
|
|
549
547
|
let t = e.filter((e) => e.kind === "tool_end"), n = t.filter((e) => e.kind === "tool_end" && e.isError), r = e.filter((e) => e.kind === "error"), i = [];
|
|
550
548
|
return t.length > 0 && i.push(`${t.length} tool call${t.length === 1 ? "" : "s"}` + (n.length > 0 ? `, ${n.length} failed` : "")), r.length > 0 && i.push(`${r.length} stream error${r.length === 1 ? "" : "s"}`), i.join(" · ");
|
|
551
549
|
}
|
|
552
|
-
function
|
|
550
|
+
function ae(e) {
|
|
553
551
|
let t = [];
|
|
554
552
|
for (let n of e) {
|
|
555
553
|
let e = t[t.length - 1];
|
|
@@ -568,90 +566,90 @@ function Z(e) {
|
|
|
568
566
|
}
|
|
569
567
|
return t;
|
|
570
568
|
}
|
|
571
|
-
function
|
|
569
|
+
function oe(e) {
|
|
572
570
|
return e.some((e) => e.kind === "tool_end" && e.isError || e.kind === "error");
|
|
573
571
|
}
|
|
574
572
|
//#endregion
|
|
575
573
|
//#region src/ui/markdown.tsx
|
|
576
|
-
function
|
|
574
|
+
function se({ renderTable: t, renderChart: n } = {}) {
|
|
577
575
|
return {
|
|
578
|
-
a: ({ href:
|
|
579
|
-
href:
|
|
576
|
+
a: ({ href: t, children: n }) => !t || !e(t) ? /* @__PURE__ */ u(l, { children: n }) : /* @__PURE__ */ u("a", {
|
|
577
|
+
href: t,
|
|
580
578
|
target: "_blank",
|
|
581
579
|
rel: "noopener noreferrer",
|
|
582
|
-
children:
|
|
580
|
+
children: n
|
|
583
581
|
}),
|
|
584
|
-
table: ({ node:
|
|
585
|
-
let
|
|
586
|
-
if (
|
|
587
|
-
let
|
|
588
|
-
return /* @__PURE__ */ l
|
|
589
|
-
headers:
|
|
590
|
-
rows:
|
|
582
|
+
table: ({ node: n, children: r }) => {
|
|
583
|
+
let i = n && P(n);
|
|
584
|
+
if (i && F(i.rows) && t) {
|
|
585
|
+
let n = i.rows.map((t) => t.map((t) => t.href && !e(t.href) ? { text: t.text } : t));
|
|
586
|
+
return /* @__PURE__ */ u(l, { children: t({
|
|
587
|
+
headers: i.headers,
|
|
588
|
+
rows: n
|
|
591
589
|
}) });
|
|
592
590
|
}
|
|
593
|
-
return /* @__PURE__ */
|
|
591
|
+
return /* @__PURE__ */ u("table", { children: r });
|
|
594
592
|
},
|
|
595
593
|
pre: ({ children: e }) => {
|
|
596
|
-
let
|
|
597
|
-
if ((
|
|
598
|
-
let e =
|
|
599
|
-
if (r) return /* @__PURE__ */ l
|
|
594
|
+
let t = (Array.isArray(e) ? e[0] : e)?.props;
|
|
595
|
+
if ((t?.className?.split(" ") ?? []).includes("language-chartjs") && n) {
|
|
596
|
+
let e = t?.children, r = R(Array.isArray(e) ? e.join("") : String(e ?? ""));
|
|
597
|
+
if (r) return /* @__PURE__ */ u(l, { children: n(r) });
|
|
600
598
|
}
|
|
601
|
-
return /* @__PURE__ */
|
|
599
|
+
return /* @__PURE__ */ u("pre", { children: e });
|
|
602
600
|
}
|
|
603
601
|
};
|
|
604
602
|
}
|
|
605
603
|
//#endregion
|
|
606
604
|
//#region src/ui/CopyMarkdownButton.tsx
|
|
607
|
-
var
|
|
608
|
-
function
|
|
609
|
-
let [
|
|
610
|
-
return
|
|
611
|
-
|
|
612
|
-
}, []), /* @__PURE__ */
|
|
605
|
+
var ce = 1500;
|
|
606
|
+
function le({ markdown: e, className: t }) {
|
|
607
|
+
let [n, i] = o(!1), [s, c] = o(!1), l = a(null);
|
|
608
|
+
return r(() => () => {
|
|
609
|
+
l.current !== null && clearTimeout(l.current);
|
|
610
|
+
}, []), /* @__PURE__ */ u(f.Provider, {
|
|
613
611
|
delayDuration: 200,
|
|
614
|
-
children: /* @__PURE__ */
|
|
615
|
-
open:
|
|
612
|
+
children: /* @__PURE__ */ d(f.Root, {
|
|
613
|
+
open: n || s,
|
|
616
614
|
onOpenChange: c,
|
|
617
|
-
children: [/* @__PURE__ */
|
|
615
|
+
children: [/* @__PURE__ */ u(f.Trigger, {
|
|
618
616
|
asChild: !0,
|
|
619
|
-
children: /* @__PURE__ */
|
|
617
|
+
children: /* @__PURE__ */ u("button", {
|
|
620
618
|
type: "button",
|
|
621
619
|
onClick: async () => {
|
|
622
620
|
try {
|
|
623
621
|
await navigator.clipboard.writeText(e);
|
|
624
622
|
} catch {}
|
|
625
|
-
|
|
623
|
+
i(!0), l.current !== null && clearTimeout(l.current), l.current = setTimeout(() => i(!1), ce);
|
|
626
624
|
},
|
|
627
625
|
"aria-label": "copy response as markdown",
|
|
628
626
|
className: `bailey-copy-button${t ? ` ${t}` : ""}`,
|
|
629
|
-
children:
|
|
627
|
+
children: n ? "✓" : "⧉"
|
|
630
628
|
})
|
|
631
|
-
}), /* @__PURE__ */
|
|
629
|
+
}), /* @__PURE__ */ u(f.Portal, { children: /* @__PURE__ */ d(f.Content, {
|
|
632
630
|
side: "top",
|
|
633
631
|
className: "bailey-tooltip-content",
|
|
634
|
-
children: [
|
|
632
|
+
children: [n ? "Copied!" : "Copy as markdown", /* @__PURE__ */ u(f.Arrow, { className: "bailey-tooltip-arrow" })]
|
|
635
633
|
}) })]
|
|
636
634
|
})
|
|
637
635
|
});
|
|
638
636
|
}
|
|
639
637
|
//#endregion
|
|
640
638
|
//#region src/ui/BaileyTracePanel.tsx
|
|
641
|
-
async function
|
|
639
|
+
async function ue(e) {
|
|
642
640
|
try {
|
|
643
641
|
await navigator.clipboard.writeText(e);
|
|
644
642
|
} catch {}
|
|
645
643
|
}
|
|
646
|
-
function
|
|
647
|
-
return /* @__PURE__ */
|
|
644
|
+
function de({ text: e, label: t = "Copy" }) {
|
|
645
|
+
return /* @__PURE__ */ u("button", {
|
|
648
646
|
type: "button",
|
|
649
|
-
onClick: () =>
|
|
647
|
+
onClick: () => ue(e),
|
|
650
648
|
className: "bailey-trace-copy-button",
|
|
651
649
|
children: t
|
|
652
650
|
});
|
|
653
651
|
}
|
|
654
|
-
function
|
|
652
|
+
function fe(e) {
|
|
655
653
|
if (e.failed || e.kind === "error") return "bailey-trace-chip bailey-trace-chip-error";
|
|
656
654
|
switch (e.kind) {
|
|
657
655
|
case "tool_start": return "bailey-trace-chip bailey-trace-chip-info";
|
|
@@ -660,74 +658,74 @@ function pe(e) {
|
|
|
660
658
|
default: return "bailey-trace-chip bailey-trace-chip-default";
|
|
661
659
|
}
|
|
662
660
|
}
|
|
663
|
-
function
|
|
664
|
-
return /* @__PURE__ */
|
|
661
|
+
function Z({ label: e, content: t, copyable: n }) {
|
|
662
|
+
return /* @__PURE__ */ d("details", {
|
|
665
663
|
className: "bailey-trace-disclosure",
|
|
666
664
|
children: [
|
|
667
|
-
/* @__PURE__ */
|
|
665
|
+
/* @__PURE__ */ u("summary", {
|
|
668
666
|
className: "bailey-trace-disclosure-summary",
|
|
669
667
|
children: e
|
|
670
668
|
}),
|
|
671
|
-
n && /* @__PURE__ */
|
|
669
|
+
n && /* @__PURE__ */ u("div", {
|
|
672
670
|
className: "bailey-trace-disclosure-actions",
|
|
673
|
-
children: /* @__PURE__ */
|
|
671
|
+
children: /* @__PURE__ */ u(de, { text: t })
|
|
674
672
|
}),
|
|
675
|
-
/* @__PURE__ */
|
|
673
|
+
/* @__PURE__ */ u("pre", {
|
|
676
674
|
className: "bailey-trace-disclosure-content",
|
|
677
675
|
children: t
|
|
678
676
|
})
|
|
679
677
|
]
|
|
680
678
|
});
|
|
681
679
|
}
|
|
682
|
-
function
|
|
683
|
-
return /* @__PURE__ */
|
|
680
|
+
function Q({ row: e }) {
|
|
681
|
+
return /* @__PURE__ */ d("div", {
|
|
684
682
|
className: "bailey-trace-row",
|
|
685
683
|
children: [
|
|
686
|
-
/* @__PURE__ */
|
|
684
|
+
/* @__PURE__ */ d("div", {
|
|
687
685
|
className: "bailey-trace-row-header",
|
|
688
686
|
children: [
|
|
689
|
-
/* @__PURE__ */
|
|
687
|
+
/* @__PURE__ */ u("span", {
|
|
690
688
|
className: "bailey-trace-row-time",
|
|
691
689
|
children: e.time
|
|
692
690
|
}),
|
|
693
|
-
/* @__PURE__ */
|
|
691
|
+
/* @__PURE__ */ u("span", {
|
|
694
692
|
className: "bailey-trace-row-gap",
|
|
695
693
|
title: "Time since the previous event",
|
|
696
694
|
children: J(e.gapMs)
|
|
697
695
|
}),
|
|
698
|
-
/* @__PURE__ */
|
|
699
|
-
className:
|
|
696
|
+
/* @__PURE__ */ u("span", {
|
|
697
|
+
className: fe(e),
|
|
700
698
|
children: e.label
|
|
701
699
|
}),
|
|
702
|
-
/* @__PURE__ */
|
|
700
|
+
/* @__PURE__ */ u("span", {
|
|
703
701
|
className: "bailey-trace-row-summary",
|
|
704
702
|
children: e.summary
|
|
705
703
|
})
|
|
706
704
|
]
|
|
707
705
|
}),
|
|
708
|
-
e.argsDetail && /* @__PURE__ */
|
|
706
|
+
e.argsDetail && /* @__PURE__ */ u(Z, {
|
|
709
707
|
label: "args",
|
|
710
708
|
content: e.argsDetail
|
|
711
709
|
}),
|
|
712
|
-
e.outputDetail && /* @__PURE__ */
|
|
710
|
+
e.outputDetail && /* @__PURE__ */ u(Z, {
|
|
713
711
|
label: "output",
|
|
714
712
|
content: e.outputDetail
|
|
715
713
|
}),
|
|
716
|
-
e.rawDetail && /* @__PURE__ */
|
|
714
|
+
e.rawDetail && /* @__PURE__ */ u(Z, {
|
|
717
715
|
label: "raw",
|
|
718
716
|
content: e.rawDetail
|
|
719
717
|
})
|
|
720
718
|
]
|
|
721
719
|
});
|
|
722
720
|
}
|
|
723
|
-
function
|
|
721
|
+
function pe(e, t) {
|
|
724
722
|
if (e.chunkCount === 0) return "Streamed: no chunks received";
|
|
725
723
|
if (e.chunkCount === 1 || e.firstChunkAt === null) return "Streamed: 1 chunk (not incremental)";
|
|
726
724
|
let n = e.firstChunkAt - t, r = (e.lastChunkAt ?? e.firstChunkAt) - e.firstChunkAt;
|
|
727
725
|
return `Streamed: ${e.chunkCount} chunks · first chunk after ${n}ms · spread over ${(r / 1e3).toFixed(1)}s`;
|
|
728
726
|
}
|
|
729
|
-
function
|
|
730
|
-
let t =
|
|
727
|
+
function me({ request: e }) {
|
|
728
|
+
let t = i(() => JSON.stringify({
|
|
731
729
|
model: e.model,
|
|
732
730
|
instructions: e.systemPrompt,
|
|
733
731
|
input: e.messages,
|
|
@@ -735,10 +733,10 @@ function he({ request: e }) {
|
|
|
735
733
|
tools: e.tools,
|
|
736
734
|
toolChoice: e.toolChoice
|
|
737
735
|
}, null, 2), [e]);
|
|
738
|
-
return /* @__PURE__ */
|
|
736
|
+
return /* @__PURE__ */ d("div", {
|
|
739
737
|
className: "bailey-trace-request-details",
|
|
740
738
|
children: [
|
|
741
|
-
/* @__PURE__ */
|
|
739
|
+
/* @__PURE__ */ d("span", {
|
|
742
740
|
className: "bailey-trace-request-meta",
|
|
743
741
|
children: [
|
|
744
742
|
"Last request — ",
|
|
@@ -748,26 +746,26 @@ function he({ request: e }) {
|
|
|
748
746
|
e.requestId ? ` · ${e.requestId}` : ""
|
|
749
747
|
]
|
|
750
748
|
}),
|
|
751
|
-
/* @__PURE__ */
|
|
749
|
+
/* @__PURE__ */ u("span", {
|
|
752
750
|
className: "bailey-trace-request-meta",
|
|
753
|
-
children:
|
|
751
|
+
children: pe(e.streamStats, e.sentAt)
|
|
754
752
|
}),
|
|
755
|
-
/* @__PURE__ */
|
|
753
|
+
/* @__PURE__ */ u(Z, {
|
|
756
754
|
label: `System prompt (${e.systemPrompt.length.toLocaleString()} chars)`,
|
|
757
755
|
content: e.systemPrompt,
|
|
758
756
|
copyable: !0
|
|
759
757
|
}),
|
|
760
|
-
/* @__PURE__ */
|
|
758
|
+
/* @__PURE__ */ u(Z, {
|
|
761
759
|
label: `Messages (${e.messages.length})`,
|
|
762
760
|
content: JSON.stringify(e.messages, null, 2),
|
|
763
761
|
copyable: !0
|
|
764
762
|
}),
|
|
765
|
-
e.response && /* @__PURE__ */
|
|
763
|
+
e.response && /* @__PURE__ */ u(Z, {
|
|
766
764
|
label: `Response (${e.response.content.length.toLocaleString()} chars)`,
|
|
767
765
|
content: e.response.content,
|
|
768
766
|
copyable: !0
|
|
769
767
|
}),
|
|
770
|
-
/* @__PURE__ */
|
|
768
|
+
/* @__PURE__ */ u(Z, {
|
|
771
769
|
label: "Full payload (JSON)",
|
|
772
770
|
content: t,
|
|
773
771
|
copyable: !0
|
|
@@ -775,43 +773,43 @@ function he({ request: e }) {
|
|
|
775
773
|
]
|
|
776
774
|
});
|
|
777
775
|
}
|
|
778
|
-
function
|
|
779
|
-
let
|
|
780
|
-
return /* @__PURE__ */
|
|
776
|
+
function he({ events: e, lastRequest: t, onClear: n }) {
|
|
777
|
+
let r = i(() => Y(e), [e]), a = i(() => ae(r), [r]), o = i(() => JSON.stringify(e, null, 2), [e]);
|
|
778
|
+
return /* @__PURE__ */ d("div", {
|
|
781
779
|
className: "bailey-trace-body",
|
|
782
780
|
children: [
|
|
783
|
-
/* @__PURE__ */
|
|
781
|
+
/* @__PURE__ */ d("div", {
|
|
784
782
|
className: "bailey-trace-actions-row",
|
|
785
|
-
children: [e.length > 0 && /* @__PURE__ */
|
|
783
|
+
children: [e.length > 0 && /* @__PURE__ */ u(de, {
|
|
786
784
|
text: o,
|
|
787
785
|
label: "Copy trace as JSON"
|
|
788
|
-
}), /* @__PURE__ */
|
|
786
|
+
}), /* @__PURE__ */ u("button", {
|
|
789
787
|
type: "button",
|
|
790
788
|
onClick: n,
|
|
791
789
|
className: "bailey-trace-copy-button",
|
|
792
790
|
children: "Clear"
|
|
793
791
|
})]
|
|
794
792
|
}),
|
|
795
|
-
t && /* @__PURE__ */
|
|
796
|
-
/* @__PURE__ */
|
|
793
|
+
t && /* @__PURE__ */ u(me, { request: t }),
|
|
794
|
+
/* @__PURE__ */ u("div", {
|
|
797
795
|
className: "bailey-trace-rows",
|
|
798
796
|
children: a.map((e, t) => {
|
|
799
|
-
if (e.type === "single") return /* @__PURE__ */
|
|
797
|
+
if (e.type === "single") return /* @__PURE__ */ u(Q, { row: e.row }, e.row.key);
|
|
800
798
|
let n = e.rows.filter((e) => e.isToolStart).length;
|
|
801
|
-
if (n <= 1) return /* @__PURE__ */
|
|
799
|
+
if (n <= 1) return /* @__PURE__ */ u("div", {
|
|
802
800
|
className: "bailey-trace-rows",
|
|
803
|
-
children: e.rows.map((e) => /* @__PURE__ */
|
|
801
|
+
children: e.rows.map((e) => /* @__PURE__ */ u(Q, { row: e }, e.key))
|
|
804
802
|
}, `group-${t}`);
|
|
805
803
|
let r = e.rows.filter((e) => e.failed).length;
|
|
806
|
-
return /* @__PURE__ */
|
|
804
|
+
return /* @__PURE__ */ d("details", {
|
|
807
805
|
className: "bailey-trace-group",
|
|
808
|
-
children: [/* @__PURE__ */
|
|
806
|
+
children: [/* @__PURE__ */ d("summary", {
|
|
809
807
|
className: "bailey-trace-group-summary",
|
|
810
808
|
children: [
|
|
811
|
-
/* @__PURE__ */
|
|
809
|
+
/* @__PURE__ */ u("strong", { children: e.toolName }),
|
|
812
810
|
" × ",
|
|
813
811
|
n,
|
|
814
|
-
r > 0 && /* @__PURE__ */
|
|
812
|
+
r > 0 && /* @__PURE__ */ d("span", {
|
|
815
813
|
className: "bailey-trace-group-failed",
|
|
816
814
|
children: [
|
|
817
815
|
" ",
|
|
@@ -820,9 +818,9 @@ function ge({ events: e, lastRequest: t, onClear: n }) {
|
|
|
820
818
|
]
|
|
821
819
|
})
|
|
822
820
|
]
|
|
823
|
-
}), /* @__PURE__ */
|
|
821
|
+
}), /* @__PURE__ */ u("div", {
|
|
824
822
|
className: "bailey-trace-rows",
|
|
825
|
-
children: e.rows.map((e) => /* @__PURE__ */
|
|
823
|
+
children: e.rows.map((e) => /* @__PURE__ */ u(Q, { row: e }, e.key))
|
|
826
824
|
})]
|
|
827
825
|
}, `group-${t}`);
|
|
828
826
|
})
|
|
@@ -830,29 +828,29 @@ function ge({ events: e, lastRequest: t, onClear: n }) {
|
|
|
830
828
|
]
|
|
831
829
|
});
|
|
832
830
|
}
|
|
833
|
-
function
|
|
834
|
-
let [
|
|
835
|
-
return e.length === 0 && !t ? null : /* @__PURE__ */
|
|
831
|
+
function $({ events: e, lastRequest: t, onClear: n }) {
|
|
832
|
+
let [r, a] = o(!1), s = i(() => oe(e), [e]), c = i(() => X(e), [e]);
|
|
833
|
+
return e.length === 0 && !t ? null : /* @__PURE__ */ d("div", {
|
|
836
834
|
className: "bailey-trace-panel",
|
|
837
|
-
children: [/* @__PURE__ */
|
|
835
|
+
children: [/* @__PURE__ */ d("div", {
|
|
838
836
|
className: "bailey-trace-toggle-row",
|
|
839
|
-
children: [/* @__PURE__ */
|
|
837
|
+
children: [/* @__PURE__ */ d("button", {
|
|
840
838
|
type: "button",
|
|
841
|
-
onClick: () =>
|
|
842
|
-
"aria-expanded":
|
|
839
|
+
onClick: () => a((e) => !e),
|
|
840
|
+
"aria-expanded": r,
|
|
843
841
|
className: s ? "bailey-trace-toggle bailey-trace-toggle-error" : "bailey-trace-toggle",
|
|
844
842
|
children: [
|
|
845
|
-
s && !
|
|
846
|
-
|
|
843
|
+
s && !r ? "⚠ " : "",
|
|
844
|
+
r ? "Hide details" : "Show details",
|
|
847
845
|
" (",
|
|
848
846
|
e.length,
|
|
849
847
|
")"
|
|
850
848
|
]
|
|
851
|
-
}), c && /* @__PURE__ */
|
|
849
|
+
}), c && /* @__PURE__ */ u("span", {
|
|
852
850
|
className: s ? "bailey-trace-summary bailey-trace-summary-error" : "bailey-trace-summary",
|
|
853
851
|
children: c
|
|
854
852
|
})]
|
|
855
|
-
}),
|
|
853
|
+
}), r && /* @__PURE__ */ u(he, {
|
|
856
854
|
events: e,
|
|
857
855
|
lastRequest: t,
|
|
858
856
|
onClear: n
|
|
@@ -861,41 +859,41 @@ function _e({ events: e, lastRequest: t, onClear: n }) {
|
|
|
861
859
|
}
|
|
862
860
|
//#endregion
|
|
863
861
|
//#region src/ui/BaileyChatPanel.tsx
|
|
864
|
-
var
|
|
865
|
-
return /* @__PURE__ */
|
|
862
|
+
var ge = [c], _e = t(function({ content: e, components: t }) {
|
|
863
|
+
return /* @__PURE__ */ u("div", {
|
|
866
864
|
className: "bailey-markdown-content",
|
|
867
|
-
children: /* @__PURE__ */
|
|
868
|
-
remarkPlugins:
|
|
865
|
+
children: /* @__PURE__ */ u(s, {
|
|
866
|
+
remarkPlugins: ge,
|
|
869
867
|
components: t,
|
|
870
868
|
children: e
|
|
871
869
|
})
|
|
872
870
|
});
|
|
873
871
|
});
|
|
874
|
-
function
|
|
872
|
+
function ve(e, t, n) {
|
|
875
873
|
if (e !== "streaming") return;
|
|
876
874
|
let r = t.filter((e) => e.turnSentAt === n?.sentAt);
|
|
877
875
|
if (r.length !== 0) return K(r[r.length - 1]);
|
|
878
876
|
}
|
|
879
|
-
function
|
|
880
|
-
let { messages: f, traceEvents: p, lastRequest: m, status: h, error: g, send: _, stop: v, retryLast: y, clearTrace: b, clearError: x, newChat: S } = e, [C, w] =
|
|
877
|
+
function ye({ chat: e, placeholder: t = "Send a message…", className: n, renderMessageActions: s, renderTable: c, renderChart: l }) {
|
|
878
|
+
let { messages: f, traceEvents: p, lastRequest: m, status: h, error: g, send: _, stop: v, retryLast: y, clearTrace: b, clearError: x, newChat: S } = e, [C, w] = o(""), T = a(null), E = i(() => se({
|
|
881
879
|
renderTable: c,
|
|
882
|
-
renderChart:
|
|
883
|
-
}), [c,
|
|
880
|
+
renderChart: l
|
|
881
|
+
}), [c, l]), D = i(() => ve(h, p, m), [
|
|
884
882
|
h,
|
|
885
883
|
p,
|
|
886
884
|
m
|
|
887
885
|
]);
|
|
888
|
-
return
|
|
886
|
+
return r(() => {
|
|
889
887
|
T.current?.scrollIntoView({
|
|
890
888
|
behavior: "smooth",
|
|
891
889
|
block: "nearest"
|
|
892
890
|
});
|
|
893
|
-
}, [f]), /* @__PURE__ */
|
|
894
|
-
className: `bailey-chat-panel${
|
|
891
|
+
}, [f]), /* @__PURE__ */ d("div", {
|
|
892
|
+
className: `bailey-chat-panel${n ? ` ${n}` : ""}`,
|
|
895
893
|
children: [
|
|
896
|
-
/* @__PURE__ */
|
|
894
|
+
/* @__PURE__ */ u("div", {
|
|
897
895
|
className: "bailey-toolbar-row",
|
|
898
|
-
children: /* @__PURE__ */
|
|
896
|
+
children: /* @__PURE__ */ u("button", {
|
|
899
897
|
type: "button",
|
|
900
898
|
onClick: S,
|
|
901
899
|
disabled: f.length === 0,
|
|
@@ -904,56 +902,56 @@ function xe({ chat: e, placeholder: t = "Send a message…", className: o, rende
|
|
|
904
902
|
children: "New chat"
|
|
905
903
|
})
|
|
906
904
|
}),
|
|
907
|
-
/* @__PURE__ */
|
|
905
|
+
/* @__PURE__ */ d("div", {
|
|
908
906
|
className: "bailey-chat-transcript",
|
|
909
907
|
children: [
|
|
910
|
-
f.length === 0 && /* @__PURE__ */
|
|
908
|
+
f.length === 0 && /* @__PURE__ */ u("div", {
|
|
911
909
|
className: "bailey-empty-state",
|
|
912
910
|
children: "Ask Bailey a question to get started."
|
|
913
911
|
}),
|
|
914
912
|
f.map((e, t) => {
|
|
915
913
|
let n = e.role === "assistant" && t === f.length - 1, r = h === "streaming" && n && e.content === "";
|
|
916
|
-
return /* @__PURE__ */
|
|
914
|
+
return /* @__PURE__ */ u("div", {
|
|
917
915
|
className: e.role === "user" ? "bailey-message-row bailey-message-row-user" : "bailey-message-row",
|
|
918
|
-
children: e.role === "user" ? /* @__PURE__ */
|
|
916
|
+
children: e.role === "user" ? /* @__PURE__ */ u("div", {
|
|
919
917
|
className: "bailey-user-bubble",
|
|
920
918
|
children: e.content
|
|
921
|
-
}) : r ? /* @__PURE__ */
|
|
919
|
+
}) : r ? /* @__PURE__ */ u("div", {
|
|
922
920
|
className: "bailey-thinking-hint",
|
|
923
921
|
children: D ?? "Thinking…"
|
|
924
|
-
}) : /* @__PURE__ */
|
|
922
|
+
}) : /* @__PURE__ */ d("div", {
|
|
925
923
|
className: "bailey-assistant-message",
|
|
926
924
|
children: [
|
|
927
|
-
/* @__PURE__ */
|
|
925
|
+
/* @__PURE__ */ u(_e, {
|
|
928
926
|
content: e.content,
|
|
929
927
|
components: E
|
|
930
928
|
}),
|
|
931
|
-
e.streaming && D && /* @__PURE__ */
|
|
929
|
+
e.streaming && D && /* @__PURE__ */ u("div", {
|
|
932
930
|
className: "bailey-streaming-hint",
|
|
933
931
|
children: D
|
|
934
932
|
}),
|
|
935
|
-
!e.streaming && /* @__PURE__ */
|
|
933
|
+
!e.streaming && /* @__PURE__ */ d("div", {
|
|
936
934
|
className: "bailey-message-actions",
|
|
937
|
-
children: [/* @__PURE__ */
|
|
935
|
+
children: [/* @__PURE__ */ u(le, { markdown: e.content }), s?.(e)]
|
|
938
936
|
})
|
|
939
937
|
]
|
|
940
938
|
})
|
|
941
939
|
}, e.id);
|
|
942
940
|
}),
|
|
943
|
-
/* @__PURE__ */
|
|
941
|
+
/* @__PURE__ */ u("div", { ref: T })
|
|
944
942
|
]
|
|
945
943
|
}),
|
|
946
|
-
g && /* @__PURE__ */
|
|
944
|
+
g && /* @__PURE__ */ d("div", {
|
|
947
945
|
className: "bailey-error-banner",
|
|
948
946
|
role: "alert",
|
|
949
|
-
children: [/* @__PURE__ */
|
|
947
|
+
children: [/* @__PURE__ */ u("span", { children: g }), /* @__PURE__ */ d("div", {
|
|
950
948
|
className: "bailey-error-actions",
|
|
951
|
-
children: [/* @__PURE__ */
|
|
949
|
+
children: [/* @__PURE__ */ u("button", {
|
|
952
950
|
type: "button",
|
|
953
951
|
onClick: y,
|
|
954
952
|
className: "bailey-retry-button",
|
|
955
953
|
children: "Retry"
|
|
956
|
-
}), /* @__PURE__ */
|
|
954
|
+
}), /* @__PURE__ */ u("button", {
|
|
957
955
|
type: "button",
|
|
958
956
|
onClick: x,
|
|
959
957
|
"aria-label": "dismiss error",
|
|
@@ -962,17 +960,17 @@ function xe({ chat: e, placeholder: t = "Send a message…", className: o, rende
|
|
|
962
960
|
})]
|
|
963
961
|
})]
|
|
964
962
|
}),
|
|
965
|
-
/* @__PURE__ */
|
|
963
|
+
/* @__PURE__ */ u($, {
|
|
966
964
|
events: p,
|
|
967
965
|
lastRequest: m,
|
|
968
966
|
onClear: b
|
|
969
967
|
}),
|
|
970
|
-
/* @__PURE__ */
|
|
968
|
+
/* @__PURE__ */ d("form", {
|
|
971
969
|
onSubmit: (e) => {
|
|
972
970
|
e.preventDefault(), !(!C.trim() || h === "streaming") && (_(C), w(""));
|
|
973
971
|
},
|
|
974
972
|
className: "bailey-input-row",
|
|
975
|
-
children: [/* @__PURE__ */
|
|
973
|
+
children: [/* @__PURE__ */ u("input", {
|
|
976
974
|
type: "text",
|
|
977
975
|
placeholder: t,
|
|
978
976
|
"aria-label": t,
|
|
@@ -980,13 +978,13 @@ function xe({ chat: e, placeholder: t = "Send a message…", className: o, rende
|
|
|
980
978
|
onChange: (e) => w(e.target.value),
|
|
981
979
|
disabled: h === "streaming",
|
|
982
980
|
className: "bailey-input"
|
|
983
|
-
}), h === "streaming" ? /* @__PURE__ */
|
|
981
|
+
}), h === "streaming" ? /* @__PURE__ */ u("button", {
|
|
984
982
|
type: "button",
|
|
985
983
|
onClick: v,
|
|
986
984
|
"aria-label": "stop",
|
|
987
985
|
className: "bailey-stop-button",
|
|
988
986
|
children: "Stop"
|
|
989
|
-
}) : /* @__PURE__ */
|
|
987
|
+
}) : /* @__PURE__ */ u("button", {
|
|
990
988
|
type: "submit",
|
|
991
989
|
"aria-label": "send",
|
|
992
990
|
disabled: !C.trim(),
|
|
@@ -999,6 +997,6 @@ function xe({ chat: e, placeholder: t = "Send a message…", className: o, rende
|
|
|
999
997
|
}
|
|
1000
998
|
//#endregion
|
|
1001
999
|
//#region src/index.ts
|
|
1002
|
-
var
|
|
1000
|
+
var be = "0.3.1-pre.1";
|
|
1003
1001
|
//#endregion
|
|
1004
|
-
export {
|
|
1002
|
+
export { be as BAILEYAI_CHAT_UI_VERSION, I as BAILEY_CHART_PROMPT_FRAGMENT, O as BAILEY_TABLE_GRID_ROW_THRESHOLD, ye as BaileyChatPanel, $ as BaileyTracePanel, le as CopyMarkdownButton, z as TRACE_KIND_LABEL, se as createBaileyMarkdownComponents, _ as extractPseudoToolCalls, P as extractTableData, J as formatTraceGap, q as formatTraceTime, oe as hasTraceFailure, e as isSafeMarkdownUrl, w as joinInstructions, R as parseBaileyChartSpec, y as parseSseFrames, D as resolveToolCall, F as shouldUseGrid, Y as toTraceRows, ae as toTraceSegments, U as traceEventArgsDetail, K as traceEventHint, W as traceEventOutputDetail, G as traceEventRawDetail, H as traceEventSummary, V as traceEventToolName, X as traceSummaryLine, C as useBaileyChat };
|