@icanbwell/baileyai-chat-ui 0.3.1-pre.0 → 0.3.1-pre.2
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.css +1 -1
- package/dist/baileyai-chat-ui.js +250 -236
- package/dist/chart.cjs +1 -0
- package/dist/chart.d.ts +36 -0
- package/dist/chart.js +67 -0
- package/dist/index.d.ts +3 -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,14 +322,16 @@ var y = 200, b = 15e4, x = (e, t, n) => {
|
|
|
321
322
|
F,
|
|
322
323
|
P,
|
|
323
324
|
N
|
|
324
|
-
])
|
|
325
|
+
]), L = n((e) => {
|
|
326
|
+
k.current = e, p(e);
|
|
327
|
+
}, []);
|
|
325
328
|
return {
|
|
326
329
|
messages: f,
|
|
327
330
|
traceEvents: m,
|
|
328
|
-
lastRequest:
|
|
329
|
-
status:
|
|
331
|
+
lastRequest: g,
|
|
332
|
+
status: b,
|
|
330
333
|
error: w,
|
|
331
|
-
send:
|
|
334
|
+
send: n((e) => {
|
|
332
335
|
let t = e.trim();
|
|
333
336
|
if (!t) return;
|
|
334
337
|
D.current = t;
|
|
@@ -337,33 +340,36 @@ var y = 200, b = 15e4, x = (e, t, n) => {
|
|
|
337
340
|
role: "user",
|
|
338
341
|
content: t
|
|
339
342
|
}];
|
|
340
|
-
|
|
341
|
-
}, [I]),
|
|
342
|
-
stop:
|
|
343
|
+
L(n), I(n);
|
|
344
|
+
}, [I, L]),
|
|
345
|
+
stop: n(() => {
|
|
343
346
|
E.current?.abort();
|
|
344
347
|
}, []),
|
|
345
|
-
retryLast:
|
|
348
|
+
retryLast: n(() => {
|
|
346
349
|
if (!D.current) return;
|
|
347
350
|
let e = k.current, t = e[e.length - 1], n = t && t.role === "assistant" ? e.slice(0, -1) : e;
|
|
348
|
-
|
|
349
|
-
}, [I]),
|
|
350
|
-
clearTrace:
|
|
351
|
-
clearError:
|
|
351
|
+
L(n), I(n);
|
|
352
|
+
}, [I, L]),
|
|
353
|
+
clearTrace: n(() => h([]), []),
|
|
354
|
+
clearError: n(() => {
|
|
352
355
|
T(null), C((e) => e === "error" ? "idle" : e);
|
|
353
|
-
}, [])
|
|
356
|
+
}, []),
|
|
357
|
+
newChat: n(() => {
|
|
358
|
+
E.current?.abort(), L([]), h([]), v(null), C("idle"), T(null), D.current = "";
|
|
359
|
+
}, [L])
|
|
354
360
|
};
|
|
355
361
|
};
|
|
356
362
|
//#endregion
|
|
357
363
|
//#region src/utils/prompt.ts
|
|
358
|
-
function
|
|
364
|
+
function w(...e) {
|
|
359
365
|
return e.filter((e) => !!(e && e.trim())).join("\n\n");
|
|
360
366
|
}
|
|
361
367
|
//#endregion
|
|
362
368
|
//#region src/utils/toolCalls.ts
|
|
363
|
-
var
|
|
364
|
-
function
|
|
369
|
+
var T = "call_tool", E = "a tool";
|
|
370
|
+
function D(e, t) {
|
|
365
371
|
let n = {
|
|
366
|
-
name: e ===
|
|
372
|
+
name: e === T ? E : e,
|
|
367
373
|
args: null,
|
|
368
374
|
viaCallTool: !1
|
|
369
375
|
};
|
|
@@ -376,7 +382,7 @@ function E(e, t) {
|
|
|
376
382
|
}
|
|
377
383
|
if (typeof r != "object" || !r) return n;
|
|
378
384
|
let i = r;
|
|
379
|
-
if (e ===
|
|
385
|
+
if (e === T) {
|
|
380
386
|
let e = typeof i.name == "string" ? i.name : void 0;
|
|
381
387
|
if (!e) return n;
|
|
382
388
|
let t = i.arguments;
|
|
@@ -393,36 +399,33 @@ function E(e, t) {
|
|
|
393
399
|
};
|
|
394
400
|
}
|
|
395
401
|
//#endregion
|
|
396
|
-
//#region src/utils/
|
|
397
|
-
var
|
|
398
|
-
let t = O(e);
|
|
399
|
-
return !/^[a-z][a-z0-9+.-]*:/i.test(t) || D.test(t);
|
|
400
|
-
}, 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) => {
|
|
401
404
|
if (e.tagName === "a" && e.properties?.href) return e.properties.href;
|
|
402
405
|
for (let t of e.children ?? []) {
|
|
403
|
-
let e =
|
|
406
|
+
let e = A(t);
|
|
404
407
|
if (e) return e;
|
|
405
408
|
}
|
|
406
|
-
},
|
|
407
|
-
let t =
|
|
409
|
+
}, j = (e, t) => (e.children ?? []).find((e) => e.tagName === t), M = (e) => {
|
|
410
|
+
let t = k(e), n = A(e);
|
|
408
411
|
return n ? {
|
|
409
412
|
text: t,
|
|
410
413
|
href: n
|
|
411
414
|
} : { text: t };
|
|
412
|
-
},
|
|
415
|
+
}, N = (e) => (e.children ?? []).filter((e) => e.type === "element").map(M), P = (e) => {
|
|
413
416
|
if (e.tagName !== "table") return null;
|
|
414
|
-
let t =
|
|
417
|
+
let t = j(e, "thead"), n = t && j(t, "tr");
|
|
415
418
|
return {
|
|
416
|
-
headers: n ?
|
|
417
|
-
rows: (
|
|
419
|
+
headers: n ? N(n).map((e) => e.text) : [],
|
|
420
|
+
rows: (j(e, "tbody")?.children ?? []).filter((e) => e.tagName === "tr").map(N)
|
|
418
421
|
};
|
|
419
|
-
},
|
|
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 = [
|
|
420
423
|
"bar",
|
|
421
424
|
"line",
|
|
422
425
|
"pie",
|
|
423
426
|
"doughnut",
|
|
424
427
|
"scatter"
|
|
425
|
-
],
|
|
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) => {
|
|
426
429
|
let t;
|
|
427
430
|
try {
|
|
428
431
|
t = JSON.parse(e);
|
|
@@ -431,17 +434,17 @@ var D = /^(https?|mailto):/i, O = (e) => e.replace(/[\t\n\r]/g, "").trim(), k =
|
|
|
431
434
|
}
|
|
432
435
|
if (typeof t != "object" || !t) return null;
|
|
433
436
|
let n = t;
|
|
434
|
-
if (typeof n.type != "string" || !
|
|
437
|
+
if (typeof n.type != "string" || !L.includes(n.type)) return null;
|
|
435
438
|
let r = n.type;
|
|
436
439
|
if (n.title !== void 0 && typeof n.title != "string") return null;
|
|
437
440
|
let i = n.title;
|
|
438
441
|
if (typeof n.data != "object" || n.data === null) return null;
|
|
439
442
|
let a = n.data;
|
|
440
|
-
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;
|
|
441
444
|
for (let e of a.datasets) if (typeof e != "object" || !e || typeof e.label != "string" || !Array.isArray(e.data)) return null;
|
|
442
445
|
let o = a.datasets;
|
|
443
446
|
if (r === "scatter") {
|
|
444
|
-
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;
|
|
445
448
|
return {
|
|
446
449
|
type: r,
|
|
447
450
|
title: i,
|
|
@@ -449,7 +452,7 @@ var D = /^(https?|mailto):/i, O = (e) => e.replace(/[\t\n\r]/g, "").trim(), k =
|
|
|
449
452
|
};
|
|
450
453
|
}
|
|
451
454
|
if (!Array.isArray(a.labels) || !a.labels.every((e) => typeof e == "string")) return null;
|
|
452
|
-
let s = a.labels, c = r === "pie" || r === "doughnut" ?
|
|
455
|
+
let s = a.labels, c = r === "pie" || r === "doughnut" ? ne : te;
|
|
453
456
|
if (s.length < 1 || s.length > c) return null;
|
|
454
457
|
for (let e of o) if (e.data.length !== s.length || !e.data.every((e) => typeof e == "number")) return null;
|
|
455
458
|
return {
|
|
@@ -470,7 +473,7 @@ var D = /^(https?|mailto):/i, O = (e) => e.replace(/[\t\n\r]/g, "").trim(), k =
|
|
|
470
473
|
raw: "Raw event"
|
|
471
474
|
};
|
|
472
475
|
function B(e) {
|
|
473
|
-
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);
|
|
474
477
|
}
|
|
475
478
|
function V(e, t = B(e)) {
|
|
476
479
|
return e.kind === "pseudo_tool_call" ? e.name : t?.name ?? null;
|
|
@@ -497,9 +500,9 @@ function G(e) {
|
|
|
497
500
|
}
|
|
498
501
|
function K(e) {
|
|
499
502
|
switch (e.kind) {
|
|
500
|
-
case "tool_start": return `Calling ${
|
|
503
|
+
case "tool_start": return `Calling ${D(e.name, e.args).name}...`;
|
|
501
504
|
case "tool_end": {
|
|
502
|
-
let t =
|
|
505
|
+
let t = D(e.name, e.args).name;
|
|
503
506
|
return e.isError ? `${t} failed` : `${t} returned`;
|
|
504
507
|
}
|
|
505
508
|
case "pseudo_tool_call": return `${e.name} (written as text, not called)`;
|
|
@@ -544,7 +547,7 @@ function X(e) {
|
|
|
544
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 = [];
|
|
545
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(" · ");
|
|
546
549
|
}
|
|
547
|
-
function
|
|
550
|
+
function ae(e) {
|
|
548
551
|
let t = [];
|
|
549
552
|
for (let n of e) {
|
|
550
553
|
let e = t[t.length - 1];
|
|
@@ -563,90 +566,90 @@ function Z(e) {
|
|
|
563
566
|
}
|
|
564
567
|
return t;
|
|
565
568
|
}
|
|
566
|
-
function
|
|
569
|
+
function oe(e) {
|
|
567
570
|
return e.some((e) => e.kind === "tool_end" && e.isError || e.kind === "error");
|
|
568
571
|
}
|
|
569
572
|
//#endregion
|
|
570
573
|
//#region src/ui/markdown.tsx
|
|
571
|
-
function
|
|
574
|
+
function se({ renderTable: t, renderChart: n } = {}) {
|
|
572
575
|
return {
|
|
573
|
-
a: ({ href:
|
|
574
|
-
href:
|
|
576
|
+
a: ({ href: t, children: n }) => !t || !e(t) ? /* @__PURE__ */ u(l, { children: n }) : /* @__PURE__ */ u("a", {
|
|
577
|
+
href: t,
|
|
575
578
|
target: "_blank",
|
|
576
579
|
rel: "noopener noreferrer",
|
|
577
|
-
children:
|
|
580
|
+
children: n
|
|
578
581
|
}),
|
|
579
|
-
table: ({ node:
|
|
580
|
-
let
|
|
581
|
-
if (
|
|
582
|
-
let
|
|
583
|
-
return /* @__PURE__ */ l
|
|
584
|
-
headers:
|
|
585
|
-
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
|
|
586
589
|
}) });
|
|
587
590
|
}
|
|
588
|
-
return /* @__PURE__ */
|
|
591
|
+
return /* @__PURE__ */ u("table", { children: r });
|
|
589
592
|
},
|
|
590
593
|
pre: ({ children: e }) => {
|
|
591
|
-
let
|
|
592
|
-
if ((
|
|
593
|
-
let e =
|
|
594
|
-
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) });
|
|
595
598
|
}
|
|
596
|
-
return /* @__PURE__ */
|
|
599
|
+
return /* @__PURE__ */ u("pre", { children: e });
|
|
597
600
|
}
|
|
598
601
|
};
|
|
599
602
|
}
|
|
600
603
|
//#endregion
|
|
601
604
|
//#region src/ui/CopyMarkdownButton.tsx
|
|
602
|
-
var
|
|
603
|
-
function
|
|
604
|
-
let [
|
|
605
|
-
return
|
|
606
|
-
|
|
607
|
-
}, []), /* @__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, {
|
|
608
611
|
delayDuration: 200,
|
|
609
|
-
children: /* @__PURE__ */
|
|
610
|
-
open:
|
|
612
|
+
children: /* @__PURE__ */ d(f.Root, {
|
|
613
|
+
open: n || s,
|
|
611
614
|
onOpenChange: c,
|
|
612
|
-
children: [/* @__PURE__ */
|
|
615
|
+
children: [/* @__PURE__ */ u(f.Trigger, {
|
|
613
616
|
asChild: !0,
|
|
614
|
-
children: /* @__PURE__ */
|
|
617
|
+
children: /* @__PURE__ */ u("button", {
|
|
615
618
|
type: "button",
|
|
616
619
|
onClick: async () => {
|
|
617
620
|
try {
|
|
618
621
|
await navigator.clipboard.writeText(e);
|
|
619
622
|
} catch {}
|
|
620
|
-
|
|
623
|
+
i(!0), l.current !== null && clearTimeout(l.current), l.current = setTimeout(() => i(!1), ce);
|
|
621
624
|
},
|
|
622
625
|
"aria-label": "copy response as markdown",
|
|
623
626
|
className: `bailey-copy-button${t ? ` ${t}` : ""}`,
|
|
624
|
-
children:
|
|
627
|
+
children: n ? "✓" : "⧉"
|
|
625
628
|
})
|
|
626
|
-
}), /* @__PURE__ */
|
|
629
|
+
}), /* @__PURE__ */ u(f.Portal, { children: /* @__PURE__ */ d(f.Content, {
|
|
627
630
|
side: "top",
|
|
628
631
|
className: "bailey-tooltip-content",
|
|
629
|
-
children: [
|
|
632
|
+
children: [n ? "Copied!" : "Copy as markdown", /* @__PURE__ */ u(f.Arrow, { className: "bailey-tooltip-arrow" })]
|
|
630
633
|
}) })]
|
|
631
634
|
})
|
|
632
635
|
});
|
|
633
636
|
}
|
|
634
637
|
//#endregion
|
|
635
638
|
//#region src/ui/BaileyTracePanel.tsx
|
|
636
|
-
async function
|
|
639
|
+
async function ue(e) {
|
|
637
640
|
try {
|
|
638
641
|
await navigator.clipboard.writeText(e);
|
|
639
642
|
} catch {}
|
|
640
643
|
}
|
|
641
|
-
function
|
|
642
|
-
return /* @__PURE__ */
|
|
644
|
+
function de({ text: e, label: t = "Copy" }) {
|
|
645
|
+
return /* @__PURE__ */ u("button", {
|
|
643
646
|
type: "button",
|
|
644
|
-
onClick: () =>
|
|
647
|
+
onClick: () => ue(e),
|
|
645
648
|
className: "bailey-trace-copy-button",
|
|
646
649
|
children: t
|
|
647
650
|
});
|
|
648
651
|
}
|
|
649
|
-
function
|
|
652
|
+
function fe(e) {
|
|
650
653
|
if (e.failed || e.kind === "error") return "bailey-trace-chip bailey-trace-chip-error";
|
|
651
654
|
switch (e.kind) {
|
|
652
655
|
case "tool_start": return "bailey-trace-chip bailey-trace-chip-info";
|
|
@@ -655,74 +658,74 @@ function pe(e) {
|
|
|
655
658
|
default: return "bailey-trace-chip bailey-trace-chip-default";
|
|
656
659
|
}
|
|
657
660
|
}
|
|
658
|
-
function
|
|
659
|
-
return /* @__PURE__ */
|
|
661
|
+
function Z({ label: e, content: t, copyable: n }) {
|
|
662
|
+
return /* @__PURE__ */ d("details", {
|
|
660
663
|
className: "bailey-trace-disclosure",
|
|
661
664
|
children: [
|
|
662
|
-
/* @__PURE__ */
|
|
665
|
+
/* @__PURE__ */ u("summary", {
|
|
663
666
|
className: "bailey-trace-disclosure-summary",
|
|
664
667
|
children: e
|
|
665
668
|
}),
|
|
666
|
-
n && /* @__PURE__ */
|
|
669
|
+
n && /* @__PURE__ */ u("div", {
|
|
667
670
|
className: "bailey-trace-disclosure-actions",
|
|
668
|
-
children: /* @__PURE__ */
|
|
671
|
+
children: /* @__PURE__ */ u(de, { text: t })
|
|
669
672
|
}),
|
|
670
|
-
/* @__PURE__ */
|
|
673
|
+
/* @__PURE__ */ u("pre", {
|
|
671
674
|
className: "bailey-trace-disclosure-content",
|
|
672
675
|
children: t
|
|
673
676
|
})
|
|
674
677
|
]
|
|
675
678
|
});
|
|
676
679
|
}
|
|
677
|
-
function
|
|
678
|
-
return /* @__PURE__ */
|
|
680
|
+
function Q({ row: e }) {
|
|
681
|
+
return /* @__PURE__ */ d("div", {
|
|
679
682
|
className: "bailey-trace-row",
|
|
680
683
|
children: [
|
|
681
|
-
/* @__PURE__ */
|
|
684
|
+
/* @__PURE__ */ d("div", {
|
|
682
685
|
className: "bailey-trace-row-header",
|
|
683
686
|
children: [
|
|
684
|
-
/* @__PURE__ */
|
|
687
|
+
/* @__PURE__ */ u("span", {
|
|
685
688
|
className: "bailey-trace-row-time",
|
|
686
689
|
children: e.time
|
|
687
690
|
}),
|
|
688
|
-
/* @__PURE__ */
|
|
691
|
+
/* @__PURE__ */ u("span", {
|
|
689
692
|
className: "bailey-trace-row-gap",
|
|
690
693
|
title: "Time since the previous event",
|
|
691
694
|
children: J(e.gapMs)
|
|
692
695
|
}),
|
|
693
|
-
/* @__PURE__ */
|
|
694
|
-
className:
|
|
696
|
+
/* @__PURE__ */ u("span", {
|
|
697
|
+
className: fe(e),
|
|
695
698
|
children: e.label
|
|
696
699
|
}),
|
|
697
|
-
/* @__PURE__ */
|
|
700
|
+
/* @__PURE__ */ u("span", {
|
|
698
701
|
className: "bailey-trace-row-summary",
|
|
699
702
|
children: e.summary
|
|
700
703
|
})
|
|
701
704
|
]
|
|
702
705
|
}),
|
|
703
|
-
e.argsDetail && /* @__PURE__ */
|
|
706
|
+
e.argsDetail && /* @__PURE__ */ u(Z, {
|
|
704
707
|
label: "args",
|
|
705
708
|
content: e.argsDetail
|
|
706
709
|
}),
|
|
707
|
-
e.outputDetail && /* @__PURE__ */
|
|
710
|
+
e.outputDetail && /* @__PURE__ */ u(Z, {
|
|
708
711
|
label: "output",
|
|
709
712
|
content: e.outputDetail
|
|
710
713
|
}),
|
|
711
|
-
e.rawDetail && /* @__PURE__ */
|
|
714
|
+
e.rawDetail && /* @__PURE__ */ u(Z, {
|
|
712
715
|
label: "raw",
|
|
713
716
|
content: e.rawDetail
|
|
714
717
|
})
|
|
715
718
|
]
|
|
716
719
|
});
|
|
717
720
|
}
|
|
718
|
-
function
|
|
721
|
+
function pe(e, t) {
|
|
719
722
|
if (e.chunkCount === 0) return "Streamed: no chunks received";
|
|
720
723
|
if (e.chunkCount === 1 || e.firstChunkAt === null) return "Streamed: 1 chunk (not incremental)";
|
|
721
724
|
let n = e.firstChunkAt - t, r = (e.lastChunkAt ?? e.firstChunkAt) - e.firstChunkAt;
|
|
722
725
|
return `Streamed: ${e.chunkCount} chunks · first chunk after ${n}ms · spread over ${(r / 1e3).toFixed(1)}s`;
|
|
723
726
|
}
|
|
724
|
-
function
|
|
725
|
-
let t =
|
|
727
|
+
function me({ request: e }) {
|
|
728
|
+
let t = i(() => JSON.stringify({
|
|
726
729
|
model: e.model,
|
|
727
730
|
instructions: e.systemPrompt,
|
|
728
731
|
input: e.messages,
|
|
@@ -730,10 +733,10 @@ function he({ request: e }) {
|
|
|
730
733
|
tools: e.tools,
|
|
731
734
|
toolChoice: e.toolChoice
|
|
732
735
|
}, null, 2), [e]);
|
|
733
|
-
return /* @__PURE__ */
|
|
736
|
+
return /* @__PURE__ */ d("div", {
|
|
734
737
|
className: "bailey-trace-request-details",
|
|
735
738
|
children: [
|
|
736
|
-
/* @__PURE__ */
|
|
739
|
+
/* @__PURE__ */ d("span", {
|
|
737
740
|
className: "bailey-trace-request-meta",
|
|
738
741
|
children: [
|
|
739
742
|
"Last request — ",
|
|
@@ -743,26 +746,26 @@ function he({ request: e }) {
|
|
|
743
746
|
e.requestId ? ` · ${e.requestId}` : ""
|
|
744
747
|
]
|
|
745
748
|
}),
|
|
746
|
-
/* @__PURE__ */
|
|
749
|
+
/* @__PURE__ */ u("span", {
|
|
747
750
|
className: "bailey-trace-request-meta",
|
|
748
|
-
children:
|
|
751
|
+
children: pe(e.streamStats, e.sentAt)
|
|
749
752
|
}),
|
|
750
|
-
/* @__PURE__ */
|
|
753
|
+
/* @__PURE__ */ u(Z, {
|
|
751
754
|
label: `System prompt (${e.systemPrompt.length.toLocaleString()} chars)`,
|
|
752
755
|
content: e.systemPrompt,
|
|
753
756
|
copyable: !0
|
|
754
757
|
}),
|
|
755
|
-
/* @__PURE__ */
|
|
758
|
+
/* @__PURE__ */ u(Z, {
|
|
756
759
|
label: `Messages (${e.messages.length})`,
|
|
757
760
|
content: JSON.stringify(e.messages, null, 2),
|
|
758
761
|
copyable: !0
|
|
759
762
|
}),
|
|
760
|
-
e.response && /* @__PURE__ */
|
|
763
|
+
e.response && /* @__PURE__ */ u(Z, {
|
|
761
764
|
label: `Response (${e.response.content.length.toLocaleString()} chars)`,
|
|
762
765
|
content: e.response.content,
|
|
763
766
|
copyable: !0
|
|
764
767
|
}),
|
|
765
|
-
/* @__PURE__ */
|
|
768
|
+
/* @__PURE__ */ u(Z, {
|
|
766
769
|
label: "Full payload (JSON)",
|
|
767
770
|
content: t,
|
|
768
771
|
copyable: !0
|
|
@@ -770,43 +773,43 @@ function he({ request: e }) {
|
|
|
770
773
|
]
|
|
771
774
|
});
|
|
772
775
|
}
|
|
773
|
-
function
|
|
774
|
-
let
|
|
775
|
-
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", {
|
|
776
779
|
className: "bailey-trace-body",
|
|
777
780
|
children: [
|
|
778
|
-
/* @__PURE__ */
|
|
781
|
+
/* @__PURE__ */ d("div", {
|
|
779
782
|
className: "bailey-trace-actions-row",
|
|
780
|
-
children: [e.length > 0 && /* @__PURE__ */
|
|
783
|
+
children: [e.length > 0 && /* @__PURE__ */ u(de, {
|
|
781
784
|
text: o,
|
|
782
785
|
label: "Copy trace as JSON"
|
|
783
|
-
}), /* @__PURE__ */
|
|
786
|
+
}), /* @__PURE__ */ u("button", {
|
|
784
787
|
type: "button",
|
|
785
788
|
onClick: n,
|
|
786
789
|
className: "bailey-trace-copy-button",
|
|
787
790
|
children: "Clear"
|
|
788
791
|
})]
|
|
789
792
|
}),
|
|
790
|
-
t && /* @__PURE__ */
|
|
791
|
-
/* @__PURE__ */
|
|
793
|
+
t && /* @__PURE__ */ u(me, { request: t }),
|
|
794
|
+
/* @__PURE__ */ u("div", {
|
|
792
795
|
className: "bailey-trace-rows",
|
|
793
796
|
children: a.map((e, t) => {
|
|
794
|
-
if (e.type === "single") return /* @__PURE__ */
|
|
797
|
+
if (e.type === "single") return /* @__PURE__ */ u(Q, { row: e.row }, e.row.key);
|
|
795
798
|
let n = e.rows.filter((e) => e.isToolStart).length;
|
|
796
|
-
if (n <= 1) return /* @__PURE__ */
|
|
799
|
+
if (n <= 1) return /* @__PURE__ */ u("div", {
|
|
797
800
|
className: "bailey-trace-rows",
|
|
798
|
-
children: e.rows.map((e) => /* @__PURE__ */
|
|
801
|
+
children: e.rows.map((e) => /* @__PURE__ */ u(Q, { row: e }, e.key))
|
|
799
802
|
}, `group-${t}`);
|
|
800
803
|
let r = e.rows.filter((e) => e.failed).length;
|
|
801
|
-
return /* @__PURE__ */
|
|
804
|
+
return /* @__PURE__ */ d("details", {
|
|
802
805
|
className: "bailey-trace-group",
|
|
803
|
-
children: [/* @__PURE__ */
|
|
806
|
+
children: [/* @__PURE__ */ d("summary", {
|
|
804
807
|
className: "bailey-trace-group-summary",
|
|
805
808
|
children: [
|
|
806
|
-
/* @__PURE__ */
|
|
809
|
+
/* @__PURE__ */ u("strong", { children: e.toolName }),
|
|
807
810
|
" × ",
|
|
808
811
|
n,
|
|
809
|
-
r > 0 && /* @__PURE__ */
|
|
812
|
+
r > 0 && /* @__PURE__ */ d("span", {
|
|
810
813
|
className: "bailey-trace-group-failed",
|
|
811
814
|
children: [
|
|
812
815
|
" ",
|
|
@@ -815,9 +818,9 @@ function ge({ events: e, lastRequest: t, onClear: n }) {
|
|
|
815
818
|
]
|
|
816
819
|
})
|
|
817
820
|
]
|
|
818
|
-
}), /* @__PURE__ */
|
|
821
|
+
}), /* @__PURE__ */ u("div", {
|
|
819
822
|
className: "bailey-trace-rows",
|
|
820
|
-
children: e.rows.map((e) => /* @__PURE__ */
|
|
823
|
+
children: e.rows.map((e) => /* @__PURE__ */ u(Q, { row: e }, e.key))
|
|
821
824
|
})]
|
|
822
825
|
}, `group-${t}`);
|
|
823
826
|
})
|
|
@@ -825,29 +828,29 @@ function ge({ events: e, lastRequest: t, onClear: n }) {
|
|
|
825
828
|
]
|
|
826
829
|
});
|
|
827
830
|
}
|
|
828
|
-
function
|
|
829
|
-
let [
|
|
830
|
-
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", {
|
|
831
834
|
className: "bailey-trace-panel",
|
|
832
|
-
children: [/* @__PURE__ */
|
|
835
|
+
children: [/* @__PURE__ */ d("div", {
|
|
833
836
|
className: "bailey-trace-toggle-row",
|
|
834
|
-
children: [/* @__PURE__ */
|
|
837
|
+
children: [/* @__PURE__ */ d("button", {
|
|
835
838
|
type: "button",
|
|
836
|
-
onClick: () =>
|
|
837
|
-
"aria-expanded":
|
|
839
|
+
onClick: () => a((e) => !e),
|
|
840
|
+
"aria-expanded": r,
|
|
838
841
|
className: s ? "bailey-trace-toggle bailey-trace-toggle-error" : "bailey-trace-toggle",
|
|
839
842
|
children: [
|
|
840
|
-
s && !
|
|
841
|
-
|
|
843
|
+
s && !r ? "⚠ " : "",
|
|
844
|
+
r ? "Hide details" : "Show details",
|
|
842
845
|
" (",
|
|
843
846
|
e.length,
|
|
844
847
|
")"
|
|
845
848
|
]
|
|
846
|
-
}), c && /* @__PURE__ */
|
|
849
|
+
}), c && /* @__PURE__ */ u("span", {
|
|
847
850
|
className: s ? "bailey-trace-summary bailey-trace-summary-error" : "bailey-trace-summary",
|
|
848
851
|
children: c
|
|
849
852
|
})]
|
|
850
|
-
}),
|
|
853
|
+
}), r && /* @__PURE__ */ u(he, {
|
|
851
854
|
events: e,
|
|
852
855
|
lastRequest: t,
|
|
853
856
|
onClear: n
|
|
@@ -856,88 +859,99 @@ function _e({ events: e, lastRequest: t, onClear: n }) {
|
|
|
856
859
|
}
|
|
857
860
|
//#endregion
|
|
858
861
|
//#region src/ui/BaileyChatPanel.tsx
|
|
859
|
-
var
|
|
860
|
-
return /* @__PURE__ */
|
|
862
|
+
var ge = [c], _e = t(function({ content: e, components: t }) {
|
|
863
|
+
return /* @__PURE__ */ u("div", {
|
|
861
864
|
className: "bailey-markdown-content",
|
|
862
|
-
children: /* @__PURE__ */
|
|
863
|
-
remarkPlugins:
|
|
865
|
+
children: /* @__PURE__ */ u(s, {
|
|
866
|
+
remarkPlugins: ge,
|
|
864
867
|
components: t,
|
|
865
868
|
children: e
|
|
866
869
|
})
|
|
867
870
|
});
|
|
868
871
|
});
|
|
869
|
-
function
|
|
872
|
+
function ve(e, t, n) {
|
|
870
873
|
if (e !== "streaming") return;
|
|
871
874
|
let r = t.filter((e) => e.turnSentAt === n?.sentAt);
|
|
872
875
|
if (r.length !== 0) return K(r[r.length - 1]);
|
|
873
876
|
}
|
|
874
|
-
function
|
|
875
|
-
let { messages: f, traceEvents: p, lastRequest: m, status: h, error: g, send: _, stop: v, retryLast: y, clearTrace: b, clearError: x } = e, [
|
|
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({
|
|
876
879
|
renderTable: c,
|
|
877
|
-
renderChart:
|
|
878
|
-
}), [c,
|
|
880
|
+
renderChart: l
|
|
881
|
+
}), [c, l]), D = i(() => ve(h, p, m), [
|
|
879
882
|
h,
|
|
880
883
|
p,
|
|
881
884
|
m
|
|
882
885
|
]);
|
|
883
|
-
return
|
|
884
|
-
|
|
886
|
+
return r(() => {
|
|
887
|
+
T.current?.scrollIntoView({
|
|
885
888
|
behavior: "smooth",
|
|
886
889
|
block: "nearest"
|
|
887
890
|
});
|
|
888
|
-
}, [f]), /* @__PURE__ */
|
|
889
|
-
className: `bailey-chat-panel${
|
|
891
|
+
}, [f]), /* @__PURE__ */ d("div", {
|
|
892
|
+
className: `bailey-chat-panel${n ? ` ${n}` : ""}`,
|
|
890
893
|
children: [
|
|
891
894
|
/* @__PURE__ */ u("div", {
|
|
895
|
+
className: "bailey-toolbar-row",
|
|
896
|
+
children: /* @__PURE__ */ u("button", {
|
|
897
|
+
type: "button",
|
|
898
|
+
onClick: S,
|
|
899
|
+
disabled: f.length === 0,
|
|
900
|
+
"aria-label": "new chat",
|
|
901
|
+
className: "bailey-new-chat-button",
|
|
902
|
+
children: "New chat"
|
|
903
|
+
})
|
|
904
|
+
}),
|
|
905
|
+
/* @__PURE__ */ d("div", {
|
|
892
906
|
className: "bailey-chat-transcript",
|
|
893
907
|
children: [
|
|
894
|
-
f.length === 0 && /* @__PURE__ */
|
|
908
|
+
f.length === 0 && /* @__PURE__ */ u("div", {
|
|
895
909
|
className: "bailey-empty-state",
|
|
896
910
|
children: "Ask Bailey a question to get started."
|
|
897
911
|
}),
|
|
898
912
|
f.map((e, t) => {
|
|
899
913
|
let n = e.role === "assistant" && t === f.length - 1, r = h === "streaming" && n && e.content === "";
|
|
900
|
-
return /* @__PURE__ */
|
|
914
|
+
return /* @__PURE__ */ u("div", {
|
|
901
915
|
className: e.role === "user" ? "bailey-message-row bailey-message-row-user" : "bailey-message-row",
|
|
902
|
-
children: e.role === "user" ? /* @__PURE__ */
|
|
916
|
+
children: e.role === "user" ? /* @__PURE__ */ u("div", {
|
|
903
917
|
className: "bailey-user-bubble",
|
|
904
918
|
children: e.content
|
|
905
|
-
}) : r ? /* @__PURE__ */
|
|
919
|
+
}) : r ? /* @__PURE__ */ u("div", {
|
|
906
920
|
className: "bailey-thinking-hint",
|
|
907
|
-
children:
|
|
908
|
-
}) : /* @__PURE__ */
|
|
921
|
+
children: D ?? "Thinking…"
|
|
922
|
+
}) : /* @__PURE__ */ d("div", {
|
|
909
923
|
className: "bailey-assistant-message",
|
|
910
924
|
children: [
|
|
911
|
-
/* @__PURE__ */
|
|
925
|
+
/* @__PURE__ */ u(_e, {
|
|
912
926
|
content: e.content,
|
|
913
|
-
components:
|
|
927
|
+
components: E
|
|
914
928
|
}),
|
|
915
|
-
e.streaming &&
|
|
929
|
+
e.streaming && D && /* @__PURE__ */ u("div", {
|
|
916
930
|
className: "bailey-streaming-hint",
|
|
917
|
-
children:
|
|
931
|
+
children: D
|
|
918
932
|
}),
|
|
919
|
-
!e.streaming && /* @__PURE__ */
|
|
933
|
+
!e.streaming && /* @__PURE__ */ d("div", {
|
|
920
934
|
className: "bailey-message-actions",
|
|
921
|
-
children: [/* @__PURE__ */
|
|
935
|
+
children: [/* @__PURE__ */ u(le, { markdown: e.content }), s?.(e)]
|
|
922
936
|
})
|
|
923
937
|
]
|
|
924
938
|
})
|
|
925
939
|
}, e.id);
|
|
926
940
|
}),
|
|
927
|
-
/* @__PURE__ */
|
|
941
|
+
/* @__PURE__ */ u("div", { ref: T })
|
|
928
942
|
]
|
|
929
943
|
}),
|
|
930
|
-
g && /* @__PURE__ */
|
|
944
|
+
g && /* @__PURE__ */ d("div", {
|
|
931
945
|
className: "bailey-error-banner",
|
|
932
946
|
role: "alert",
|
|
933
|
-
children: [/* @__PURE__ */
|
|
947
|
+
children: [/* @__PURE__ */ u("span", { children: g }), /* @__PURE__ */ d("div", {
|
|
934
948
|
className: "bailey-error-actions",
|
|
935
|
-
children: [/* @__PURE__ */
|
|
949
|
+
children: [/* @__PURE__ */ u("button", {
|
|
936
950
|
type: "button",
|
|
937
951
|
onClick: y,
|
|
938
952
|
className: "bailey-retry-button",
|
|
939
953
|
children: "Retry"
|
|
940
|
-
}), /* @__PURE__ */
|
|
954
|
+
}), /* @__PURE__ */ u("button", {
|
|
941
955
|
type: "button",
|
|
942
956
|
onClick: x,
|
|
943
957
|
"aria-label": "dismiss error",
|
|
@@ -946,34 +960,34 @@ function xe({ chat: e, placeholder: t = "Send a message…", className: o, rende
|
|
|
946
960
|
})]
|
|
947
961
|
})]
|
|
948
962
|
}),
|
|
949
|
-
/* @__PURE__ */
|
|
963
|
+
/* @__PURE__ */ u($, {
|
|
950
964
|
events: p,
|
|
951
965
|
lastRequest: m,
|
|
952
966
|
onClear: b
|
|
953
967
|
}),
|
|
954
|
-
/* @__PURE__ */
|
|
968
|
+
/* @__PURE__ */ d("form", {
|
|
955
969
|
onSubmit: (e) => {
|
|
956
|
-
e.preventDefault(), !(!
|
|
970
|
+
e.preventDefault(), !(!C.trim() || h === "streaming") && (_(C), w(""));
|
|
957
971
|
},
|
|
958
972
|
className: "bailey-input-row",
|
|
959
|
-
children: [/* @__PURE__ */
|
|
973
|
+
children: [/* @__PURE__ */ u("input", {
|
|
960
974
|
type: "text",
|
|
961
975
|
placeholder: t,
|
|
962
976
|
"aria-label": t,
|
|
963
|
-
value:
|
|
964
|
-
onChange: (e) =>
|
|
977
|
+
value: C,
|
|
978
|
+
onChange: (e) => w(e.target.value),
|
|
965
979
|
disabled: h === "streaming",
|
|
966
980
|
className: "bailey-input"
|
|
967
|
-
}), h === "streaming" ? /* @__PURE__ */
|
|
981
|
+
}), h === "streaming" ? /* @__PURE__ */ u("button", {
|
|
968
982
|
type: "button",
|
|
969
983
|
onClick: v,
|
|
970
984
|
"aria-label": "stop",
|
|
971
985
|
className: "bailey-stop-button",
|
|
972
986
|
children: "Stop"
|
|
973
|
-
}) : /* @__PURE__ */
|
|
987
|
+
}) : /* @__PURE__ */ u("button", {
|
|
974
988
|
type: "submit",
|
|
975
989
|
"aria-label": "send",
|
|
976
|
-
disabled: !
|
|
990
|
+
disabled: !C.trim(),
|
|
977
991
|
className: "bailey-send-button",
|
|
978
992
|
children: "Send"
|
|
979
993
|
})]
|
|
@@ -983,6 +997,6 @@ function xe({ chat: e, placeholder: t = "Send a message…", className: o, rende
|
|
|
983
997
|
}
|
|
984
998
|
//#endregion
|
|
985
999
|
//#region src/index.ts
|
|
986
|
-
var
|
|
1000
|
+
var be = "0.3.1-pre.1";
|
|
987
1001
|
//#endregion
|
|
988
|
-
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 };
|