@icanbwell/baileyai-chat-ui 0.3.4 → 0.4.1-pre.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/baileyai-chat-ui.cjs +5 -5
- package/dist/baileyai-chat-ui.css +1 -1
- package/dist/baileyai-chat-ui.js +434 -278
- package/dist/index.d.ts +64 -1
- package/package.json +1 -1
package/dist/baileyai-chat-ui.js
CHANGED
|
@@ -5,18 +5,38 @@ import c from "remark-gfm";
|
|
|
5
5
|
import { Fragment as l, jsx as u, jsxs as d } from "react/jsx-runtime";
|
|
6
6
|
import * as f from "@radix-ui/react-tooltip";
|
|
7
7
|
//#region src/utils/pseudoToolCalls.ts
|
|
8
|
-
var p = /<(search_tools|call_tool)>([\s\S]*?)<\/\1>/g, m = /<name>([\s\S]*?)<\/name>/, h = /<arguments>([\s\S]*?)<\/arguments
|
|
9
|
-
function
|
|
8
|
+
var p = /<(search_tools|call_tool|function_calls|function_result)>([\s\S]*?)<\/\1>/g, m = /<name>([\s\S]*?)<\/name>/, h = /<arguments>([\s\S]*?)<\/arguments>/, g = /<invoke\s+name="([^"]*)"\s*>([\s\S]*?)<\/invoke>/g, _ = /<parameter\s+name="([^"]*)"\s*>([\s\S]*?)<\/parameter>/g;
|
|
9
|
+
function v(e) {
|
|
10
10
|
let t = m.exec(e)?.[1]?.trim() || "unknown_tool", n = h.exec(e)?.[1]?.trim();
|
|
11
11
|
return n ? {
|
|
12
12
|
name: t,
|
|
13
13
|
args: n
|
|
14
14
|
} : { name: t };
|
|
15
15
|
}
|
|
16
|
-
function
|
|
17
|
-
let t = []
|
|
16
|
+
function y(e) {
|
|
17
|
+
let t = [];
|
|
18
|
+
g.lastIndex = 0;
|
|
19
|
+
let n;
|
|
20
|
+
for (; (n = g.exec(e)) !== null;) {
|
|
21
|
+
let [, e, r] = n, i = {};
|
|
22
|
+
_.lastIndex = 0;
|
|
23
|
+
let a;
|
|
24
|
+
for (; (a = _.exec(r)) !== null;) i[a[1]] = a[2].trim();
|
|
25
|
+
let o = e.trim() || "unknown_tool";
|
|
26
|
+
t.push(Object.keys(i).length > 0 ? {
|
|
27
|
+
name: o,
|
|
28
|
+
args: JSON.stringify(i, null, 2)
|
|
29
|
+
} : { name: o });
|
|
30
|
+
}
|
|
31
|
+
return t;
|
|
32
|
+
}
|
|
33
|
+
function b(e) {
|
|
34
|
+
let t = [], n = e.replace(p, (e, n, r) => (n === "call_tool" ? t.push(v(r)) : n === "search_tools" ? t.push({
|
|
18
35
|
name: "search_tools",
|
|
19
36
|
args: r.trim()
|
|
37
|
+
}) : n === "function_calls" ? t.push(...y(r)) : t.push({
|
|
38
|
+
name: "function_result",
|
|
39
|
+
args: r.trim()
|
|
20
40
|
}), ""));
|
|
21
41
|
return t.length === 0 ? {
|
|
22
42
|
cleanedText: n,
|
|
@@ -28,7 +48,7 @@ function _(e) {
|
|
|
28
48
|
}
|
|
29
49
|
//#endregion
|
|
30
50
|
//#region src/logic/sse.ts
|
|
31
|
-
function
|
|
51
|
+
function x(e) {
|
|
32
52
|
if (!e.startsWith("data: ")) return e;
|
|
33
53
|
let t = "";
|
|
34
54
|
for (let n of e.split("\n")) {
|
|
@@ -42,7 +62,7 @@ function v(e) {
|
|
|
42
62
|
}
|
|
43
63
|
return t || null;
|
|
44
64
|
}
|
|
45
|
-
function
|
|
65
|
+
function S(e) {
|
|
46
66
|
let t = e.replace(/\r\n/g, "\n").split("\n\n"), n = t.pop() ?? "", r = [], i = !1;
|
|
47
67
|
for (let e of t) {
|
|
48
68
|
let t = e.split("\n").filter((e) => e.length > 0), n = "message", a = [];
|
|
@@ -67,7 +87,7 @@ function y(e) {
|
|
|
67
87
|
message: e
|
|
68
88
|
});
|
|
69
89
|
} else if (c?.type === "response.output_text.delta" && typeof c.delta == "string") {
|
|
70
|
-
let e =
|
|
90
|
+
let e = x(c.delta);
|
|
71
91
|
e && r.push({
|
|
72
92
|
type: "response.output_text.delta",
|
|
73
93
|
delta: e
|
|
@@ -85,38 +105,38 @@ function y(e) {
|
|
|
85
105
|
}
|
|
86
106
|
//#endregion
|
|
87
107
|
//#region src/logic/useBaileyChat.ts
|
|
88
|
-
var
|
|
108
|
+
var C = 200, w = 15e4, ee = (e, t, n) => {
|
|
89
109
|
if (e === 401 || e === 403) return "Bailey isn't reachable with your current login.";
|
|
90
110
|
let r = `Bailey request failed (status ${e ?? "network error"}).`, i = (n || t || "").trim();
|
|
91
|
-
return i ? `${r} ${i.length >
|
|
92
|
-
},
|
|
93
|
-
let [f, p] = o([]), [m, h] = o([]), [g,
|
|
111
|
+
return i ? `${r} ${i.length > C ? `${i.slice(0, C)}…` : i}` : r;
|
|
112
|
+
}, T = ({ transport: e, model: t, instructions: i, tools: s = [], toolChoice: c, firstUserMessagePrefix: l, onAssistantMessageComplete: u, idleTimeoutMs: d = w }) => {
|
|
113
|
+
let [f, p] = o([]), [m, h] = o([]), [g, _] = o(null), [v, y] = o("idle"), [x, C] = o(null), T = a(null), E = a(""), D = a(0), O = a([]);
|
|
94
114
|
r(() => {
|
|
95
|
-
|
|
115
|
+
O.current = f;
|
|
96
116
|
}, [f]);
|
|
97
|
-
let
|
|
98
|
-
|
|
99
|
-
}, []),
|
|
100
|
-
|
|
117
|
+
let k = a(/* @__PURE__ */ new Map()), A = a(/* @__PURE__ */ new Map()), j = a(null), M = n(() => {
|
|
118
|
+
j.current !== null && (clearTimeout(j.current), j.current = null);
|
|
119
|
+
}, []), N = n((e) => {
|
|
120
|
+
M(), j.current = setTimeout(() => {
|
|
101
121
|
e.abort(new DOMException("The assistant took too long to respond. Please try again.", "TimeoutError"));
|
|
102
122
|
}, d);
|
|
103
|
-
}, [
|
|
123
|
+
}, [M, d]), P = n((e, t, n) => {
|
|
104
124
|
let r = (e) => {
|
|
105
125
|
n.push(e), h((t) => [...t, e]);
|
|
106
126
|
};
|
|
107
127
|
if (t.type === "response.output_text.delta") {
|
|
108
128
|
if (!t.delta) return !1;
|
|
109
|
-
let n =
|
|
129
|
+
let n = k.current.get(e) ?? {
|
|
110
130
|
raw: "",
|
|
111
131
|
emittedCount: 0
|
|
112
132
|
};
|
|
113
133
|
n.raw += t.delta;
|
|
114
|
-
let { cleanedText: i, matches: a } =
|
|
115
|
-
if (n.emittedCount = a.length,
|
|
134
|
+
let { cleanedText: i, matches: a } = b(n.raw), o = i.trim(), s = a.slice(n.emittedCount);
|
|
135
|
+
if (n.emittedCount = a.length, k.current.set(e, n), A.current.set(e, o), p((t) => t.map((t) => t.id === e ? {
|
|
116
136
|
...t,
|
|
117
137
|
content: o
|
|
118
138
|
} : t)), s.length > 0) {
|
|
119
|
-
let e = Date.now(), t =
|
|
139
|
+
let e = Date.now(), t = D.current;
|
|
120
140
|
s.forEach((n) => r({
|
|
121
141
|
kind: "pseudo_tool_call",
|
|
122
142
|
name: n.name,
|
|
@@ -130,7 +150,7 @@ var b = 200, x = 15e4, S = (e, t, n) => {
|
|
|
130
150
|
if (t.type === "response.output_item.added" || t.type === "response.output_item.done") {
|
|
131
151
|
let e = t.item;
|
|
132
152
|
if (e.type === "function_call" || e.type === "mcp_call") {
|
|
133
|
-
let n = Date.now(), i =
|
|
153
|
+
let n = Date.now(), i = D.current, a = e.name || "unknown_tool";
|
|
134
154
|
return r(t.type === "response.output_item.added" ? {
|
|
135
155
|
kind: "tool_start",
|
|
136
156
|
name: a,
|
|
@@ -155,30 +175,31 @@ var b = 200, x = 15e4, S = (e, t, n) => {
|
|
|
155
175
|
status: t.status,
|
|
156
176
|
message: t.message,
|
|
157
177
|
at: Date.now(),
|
|
158
|
-
turnSentAt:
|
|
178
|
+
turnSentAt: D.current
|
|
159
179
|
}), !0) : t.type === "response.output_text.done" || t.type === "response.created" || t.type === "response.completed" ? !1 : t.type === "info" ? (r({
|
|
160
180
|
kind: "info",
|
|
161
181
|
message: t.message,
|
|
162
182
|
at: Date.now(),
|
|
163
|
-
turnSentAt:
|
|
183
|
+
turnSentAt: D.current
|
|
164
184
|
}), !0) : (r({
|
|
165
185
|
kind: "raw",
|
|
166
186
|
eventType: t.type,
|
|
167
187
|
raw: JSON.stringify(t),
|
|
168
188
|
at: Date.now(),
|
|
169
|
-
turnSentAt:
|
|
189
|
+
turnSentAt: D.current
|
|
170
190
|
}), !0);
|
|
171
|
-
}, []),
|
|
172
|
-
|
|
173
|
-
let r =
|
|
191
|
+
}, []), F = n(async (n) => {
|
|
192
|
+
y("streaming"), C(null);
|
|
193
|
+
let r = Date.now();
|
|
194
|
+
D.current = r;
|
|
195
|
+
let a = crypto.randomUUID();
|
|
174
196
|
p((e) => [...e, {
|
|
175
|
-
id:
|
|
197
|
+
id: a,
|
|
176
198
|
role: "assistant",
|
|
177
199
|
content: "",
|
|
178
|
-
streaming: !0
|
|
200
|
+
streaming: !0,
|
|
201
|
+
createdAt: r
|
|
179
202
|
}]);
|
|
180
|
-
let a = Date.now();
|
|
181
|
-
O.current = a;
|
|
182
203
|
let o = n.map((e, t) => t === 0 && e.role === "user" && l ? {
|
|
183
204
|
role: e.role,
|
|
184
205
|
content: `${l}${e.content}`
|
|
@@ -186,14 +207,14 @@ var b = 200, x = 15e4, S = (e, t, n) => {
|
|
|
186
207
|
role: e.role,
|
|
187
208
|
content: e.content
|
|
188
209
|
});
|
|
189
|
-
|
|
210
|
+
_({
|
|
190
211
|
model: t,
|
|
191
212
|
systemPrompt: i,
|
|
192
213
|
messages: o,
|
|
193
214
|
tools: s,
|
|
194
215
|
toolChoice: c,
|
|
195
216
|
stream: !0,
|
|
196
|
-
sentAt:
|
|
217
|
+
sentAt: r,
|
|
197
218
|
streamStats: {
|
|
198
219
|
chunkCount: 0,
|
|
199
220
|
firstChunkAt: null,
|
|
@@ -201,14 +222,14 @@ var b = 200, x = 15e4, S = (e, t, n) => {
|
|
|
201
222
|
}
|
|
202
223
|
});
|
|
203
224
|
let d = new AbortController();
|
|
204
|
-
|
|
205
|
-
let f = "", m = null, g = !1,
|
|
206
|
-
|
|
225
|
+
T.current = d, N(d);
|
|
226
|
+
let f = "", m = null, g = !1, v = !1, b = [], x = (e, t) => {
|
|
227
|
+
y("error"), C(e);
|
|
207
228
|
let n = {
|
|
208
229
|
kind: "error",
|
|
209
230
|
message: e,
|
|
210
231
|
at: Date.now(),
|
|
211
|
-
turnSentAt:
|
|
232
|
+
turnSentAt: r,
|
|
212
233
|
...t
|
|
213
234
|
};
|
|
214
235
|
b.push(n), h((e) => [...e, n]);
|
|
@@ -220,13 +241,13 @@ var b = 200, x = 15e4, S = (e, t, n) => {
|
|
|
220
241
|
kind: "error",
|
|
221
242
|
message: e.message,
|
|
222
243
|
at: Date.now(),
|
|
223
|
-
turnSentAt:
|
|
244
|
+
turnSentAt: r
|
|
224
245
|
};
|
|
225
246
|
b.push(t), h((e) => [...e, t]);
|
|
226
247
|
return;
|
|
227
248
|
}
|
|
228
|
-
e.type === "response.output_text.delta" && e.delta && (
|
|
229
|
-
}), t && p((e) => e.map((e) => e.id ===
|
|
249
|
+
e.type === "response.output_text.delta" && e.delta && (v = !0), P(a, e, b) && (g = !0);
|
|
250
|
+
}), t && p((e) => e.map((e) => e.id === a ? {
|
|
230
251
|
...e,
|
|
231
252
|
streaming: !1
|
|
232
253
|
} : e));
|
|
@@ -240,36 +261,36 @@ var b = 200, x = 15e4, S = (e, t, n) => {
|
|
|
240
261
|
toolChoice: c,
|
|
241
262
|
signal: d.signal,
|
|
242
263
|
onChunk: (e) => {
|
|
243
|
-
|
|
244
|
-
let { events: t, remainder: n, done:
|
|
245
|
-
f = n, w(t,
|
|
246
|
-
let
|
|
247
|
-
|
|
264
|
+
N(d), f += e;
|
|
265
|
+
let { events: t, remainder: n, done: i } = S(f);
|
|
266
|
+
f = n, w(t, i);
|
|
267
|
+
let a = Date.now();
|
|
268
|
+
_((e) => e && e.sentAt === r ? {
|
|
248
269
|
...e,
|
|
249
270
|
streamStats: {
|
|
250
271
|
chunkCount: e.streamStats.chunkCount + 1,
|
|
251
|
-
firstChunkAt: e.streamStats.firstChunkAt ??
|
|
252
|
-
lastChunkAt:
|
|
272
|
+
firstChunkAt: e.streamStats.firstChunkAt ?? a,
|
|
273
|
+
lastChunkAt: a
|
|
253
274
|
}
|
|
254
275
|
} : e);
|
|
255
276
|
},
|
|
256
277
|
onRequestId: (e) => {
|
|
257
|
-
|
|
278
|
+
_((t) => t && t.sentAt === r ? {
|
|
258
279
|
...t,
|
|
259
280
|
requestId: e
|
|
260
281
|
} : t);
|
|
261
282
|
}
|
|
262
283
|
});
|
|
263
284
|
if (f.trim()) {
|
|
264
|
-
let { events: e, done: t } =
|
|
285
|
+
let { events: e, done: t } = S(`${f}\n\n`);
|
|
265
286
|
f = "", w(e, t);
|
|
266
287
|
}
|
|
267
288
|
if (m) {
|
|
268
|
-
|
|
289
|
+
y("error"), C(m);
|
|
269
290
|
return;
|
|
270
291
|
}
|
|
271
292
|
if (n === void 0 || n >= 400) {
|
|
272
|
-
x(
|
|
293
|
+
x(ee(n, l, p), {
|
|
273
294
|
httpStatus: n,
|
|
274
295
|
rawBody: l || void 0
|
|
275
296
|
});
|
|
@@ -279,17 +300,17 @@ var b = 200, x = 15e4, S = (e, t, n) => {
|
|
|
279
300
|
x("Bailey returned an empty response.");
|
|
280
301
|
return;
|
|
281
302
|
}
|
|
282
|
-
if (!
|
|
303
|
+
if (!v) {
|
|
283
304
|
x("Bailey ran some tools but didn't return an answer. Try asking again.");
|
|
284
305
|
return;
|
|
285
306
|
}
|
|
286
|
-
|
|
287
|
-
let h =
|
|
288
|
-
|
|
307
|
+
y("idle");
|
|
308
|
+
let h = A.current.get(a) ?? "";
|
|
309
|
+
_((e) => e && e.sentAt === r ? {
|
|
289
310
|
...e,
|
|
290
311
|
response: { content: h }
|
|
291
312
|
} : e), u && await u({
|
|
292
|
-
id:
|
|
313
|
+
id: a,
|
|
293
314
|
role: "assistant",
|
|
294
315
|
content: h,
|
|
295
316
|
streaming: !1
|
|
@@ -301,12 +322,12 @@ var b = 200, x = 15e4, S = (e, t, n) => {
|
|
|
301
322
|
return;
|
|
302
323
|
}
|
|
303
324
|
if (t?.name === "AbortError") {
|
|
304
|
-
|
|
325
|
+
y("idle");
|
|
305
326
|
return;
|
|
306
327
|
}
|
|
307
328
|
x(t?.message || "Bailey request failed.");
|
|
308
329
|
} finally {
|
|
309
|
-
|
|
330
|
+
M(), k.current.delete(a), A.current.delete(a), p((e) => e.flatMap((e) => e.id === a ? e.content ? [{
|
|
310
331
|
...e,
|
|
311
332
|
streaming: !1
|
|
312
333
|
}] : [] : [e]));
|
|
@@ -319,57 +340,58 @@ var b = 200, x = 15e4, S = (e, t, n) => {
|
|
|
319
340
|
c,
|
|
320
341
|
l,
|
|
321
342
|
u,
|
|
322
|
-
F,
|
|
323
343
|
P,
|
|
324
|
-
N
|
|
325
|
-
|
|
326
|
-
|
|
344
|
+
N,
|
|
345
|
+
M
|
|
346
|
+
]), I = n((e) => {
|
|
347
|
+
O.current = e, p(e);
|
|
327
348
|
}, []);
|
|
328
349
|
return {
|
|
329
350
|
messages: f,
|
|
330
351
|
traceEvents: m,
|
|
331
352
|
lastRequest: g,
|
|
332
|
-
status:
|
|
333
|
-
error:
|
|
353
|
+
status: v,
|
|
354
|
+
error: x,
|
|
334
355
|
send: n((e) => {
|
|
335
356
|
let t = e.trim();
|
|
336
357
|
if (!t) return;
|
|
337
|
-
|
|
338
|
-
let n = [...
|
|
358
|
+
E.current = t;
|
|
359
|
+
let n = [...O.current, {
|
|
339
360
|
id: crypto.randomUUID(),
|
|
340
361
|
role: "user",
|
|
341
|
-
content: t
|
|
362
|
+
content: t,
|
|
363
|
+
createdAt: Date.now()
|
|
342
364
|
}];
|
|
343
|
-
|
|
344
|
-
}, [
|
|
365
|
+
I(n), F(n);
|
|
366
|
+
}, [F, I]),
|
|
345
367
|
stop: n(() => {
|
|
346
|
-
|
|
368
|
+
T.current?.abort();
|
|
347
369
|
}, []),
|
|
348
370
|
retryLast: n(() => {
|
|
349
|
-
if (!
|
|
350
|
-
let e =
|
|
351
|
-
|
|
352
|
-
}, [
|
|
371
|
+
if (!E.current) return;
|
|
372
|
+
let e = O.current, t = e[e.length - 1], n = t && t.role === "assistant" ? e.slice(0, -1) : e;
|
|
373
|
+
I(n), F(n);
|
|
374
|
+
}, [F, I]),
|
|
353
375
|
clearTrace: n(() => h([]), []),
|
|
354
376
|
clearError: n(() => {
|
|
355
|
-
|
|
377
|
+
C(null), y((e) => e === "error" ? "idle" : e);
|
|
356
378
|
}, []),
|
|
357
379
|
newChat: n(() => {
|
|
358
|
-
|
|
359
|
-
}, [
|
|
380
|
+
T.current?.abort(), I([]), h([]), _(null), y("idle"), C(null), E.current = "";
|
|
381
|
+
}, [I])
|
|
360
382
|
};
|
|
361
383
|
};
|
|
362
384
|
//#endregion
|
|
363
385
|
//#region src/utils/prompt.ts
|
|
364
|
-
function
|
|
386
|
+
function E(...e) {
|
|
365
387
|
return e.filter((e) => !!(e && e.trim())).join("\n\n");
|
|
366
388
|
}
|
|
367
389
|
//#endregion
|
|
368
390
|
//#region src/utils/toolCalls.ts
|
|
369
|
-
var
|
|
370
|
-
function
|
|
391
|
+
var D = "call_tool", O = "a tool";
|
|
392
|
+
function k(e, t) {
|
|
371
393
|
let n = {
|
|
372
|
-
name: e ===
|
|
394
|
+
name: e === D ? O : e,
|
|
373
395
|
args: null,
|
|
374
396
|
viaCallTool: !1
|
|
375
397
|
};
|
|
@@ -382,7 +404,7 @@ function D(e, t) {
|
|
|
382
404
|
}
|
|
383
405
|
if (typeof r != "object" || !r) return n;
|
|
384
406
|
let i = r;
|
|
385
|
-
if (e ===
|
|
407
|
+
if (e === D) {
|
|
386
408
|
let e = typeof i.name == "string" ? i.name : void 0;
|
|
387
409
|
if (!e) return n;
|
|
388
410
|
let t = i.arguments;
|
|
@@ -400,32 +422,32 @@ function D(e, t) {
|
|
|
400
422
|
}
|
|
401
423
|
//#endregion
|
|
402
424
|
//#region src/utils/table.ts
|
|
403
|
-
var
|
|
425
|
+
var A = 5, j = (e) => e.type === "text" ? e.value ?? "" : (e.children ?? []).map(j).join(""), M = (e) => {
|
|
404
426
|
if (e.tagName === "a" && e.properties?.href) return e.properties.href;
|
|
405
427
|
for (let t of e.children ?? []) {
|
|
406
|
-
let e =
|
|
428
|
+
let e = M(t);
|
|
407
429
|
if (e) return e;
|
|
408
430
|
}
|
|
409
|
-
},
|
|
410
|
-
let t =
|
|
431
|
+
}, N = (e, t) => (e.children ?? []).find((e) => e.tagName === t), P = (e) => {
|
|
432
|
+
let t = j(e), n = M(e);
|
|
411
433
|
return n ? {
|
|
412
434
|
text: t,
|
|
413
435
|
href: n
|
|
414
436
|
} : { text: t };
|
|
415
|
-
},
|
|
437
|
+
}, F = (e) => (e.children ?? []).filter((e) => e.type === "element").map(P), I = (e) => {
|
|
416
438
|
if (e.tagName !== "table") return null;
|
|
417
|
-
let t =
|
|
439
|
+
let t = N(e, "thead"), n = t && N(t, "tr");
|
|
418
440
|
return {
|
|
419
|
-
headers: n ?
|
|
420
|
-
rows: (
|
|
441
|
+
headers: n ? F(n).map((e) => e.text) : [],
|
|
442
|
+
rows: (N(e, "tbody")?.children ?? []).filter((e) => e.tagName === "tr").map(F)
|
|
421
443
|
};
|
|
422
|
-
},
|
|
444
|
+
}, te = (e) => e.length > 5, ne = "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```", re = [
|
|
423
445
|
"bar",
|
|
424
446
|
"line",
|
|
425
447
|
"pie",
|
|
426
448
|
"doughnut",
|
|
427
449
|
"scatter"
|
|
428
|
-
],
|
|
450
|
+
], ie = 8, ae = 50, oe = 8, se = 500, ce = (e) => typeof e == "object" && !!e && typeof e.x == "number" && typeof e.y == "number", L = (e) => {
|
|
429
451
|
let t;
|
|
430
452
|
try {
|
|
431
453
|
t = JSON.parse(e);
|
|
@@ -434,17 +456,17 @@ var O = 5, k = (e) => e.type === "text" ? e.value ?? "" : (e.children ?? []).map
|
|
|
434
456
|
}
|
|
435
457
|
if (typeof t != "object" || !t) return null;
|
|
436
458
|
let n = t;
|
|
437
|
-
if (typeof n.type != "string" || !
|
|
459
|
+
if (typeof n.type != "string" || !re.includes(n.type)) return null;
|
|
438
460
|
let r = n.type;
|
|
439
461
|
if (n.title !== void 0 && typeof n.title != "string") return null;
|
|
440
462
|
let i = n.title;
|
|
441
463
|
if (typeof n.data != "object" || n.data === null) return null;
|
|
442
464
|
let a = n.data;
|
|
443
|
-
if (!Array.isArray(a.datasets) || a.datasets.length < 1 || a.datasets.length >
|
|
465
|
+
if (!Array.isArray(a.datasets) || a.datasets.length < 1 || a.datasets.length > ie || (r === "pie" || r === "doughnut") && a.datasets.length !== 1) return null;
|
|
444
466
|
for (let e of a.datasets) if (typeof e != "object" || !e || typeof e.label != "string" || !Array.isArray(e.data)) return null;
|
|
445
467
|
let o = a.datasets;
|
|
446
468
|
if (r === "scatter") {
|
|
447
|
-
for (let e of o) if (e.data.length < 1 || e.data.length >
|
|
469
|
+
for (let e of o) if (e.data.length < 1 || e.data.length > se || !e.data.every(ce)) return null;
|
|
448
470
|
return {
|
|
449
471
|
type: r,
|
|
450
472
|
title: i,
|
|
@@ -452,7 +474,7 @@ var O = 5, k = (e) => e.type === "text" ? e.value ?? "" : (e.children ?? []).map
|
|
|
452
474
|
};
|
|
453
475
|
}
|
|
454
476
|
if (!Array.isArray(a.labels) || !a.labels.every((e) => typeof e == "string")) return null;
|
|
455
|
-
let s = a.labels, c = r === "pie" || r === "doughnut" ?
|
|
477
|
+
let s = a.labels, c = r === "pie" || r === "doughnut" ? oe : ae;
|
|
456
478
|
if (s.length < 1 || s.length > c) return null;
|
|
457
479
|
for (let e of o) if (e.data.length !== s.length || !e.data.every((e) => typeof e == "number")) return null;
|
|
458
480
|
return {
|
|
@@ -463,7 +485,7 @@ var O = 5, k = (e) => e.type === "text" ? e.value ?? "" : (e.children ?? []).map
|
|
|
463
485
|
datasets: o
|
|
464
486
|
}
|
|
465
487
|
};
|
|
466
|
-
},
|
|
488
|
+
}, le = {
|
|
467
489
|
tool_start: "Tool start",
|
|
468
490
|
tool_end: "Tool end",
|
|
469
491
|
pseudo_tool_call: "Narrated tool call",
|
|
@@ -472,13 +494,13 @@ var O = 5, k = (e) => e.type === "text" ? e.value ?? "" : (e.children ?? []).map
|
|
|
472
494
|
error: "Error",
|
|
473
495
|
raw: "Raw event"
|
|
474
496
|
};
|
|
475
|
-
function
|
|
476
|
-
return e.kind !== "tool_start" && e.kind !== "tool_end" ? null :
|
|
497
|
+
function R(e) {
|
|
498
|
+
return e.kind !== "tool_start" && e.kind !== "tool_end" ? null : k(e.name, e.args);
|
|
477
499
|
}
|
|
478
|
-
function
|
|
500
|
+
function z(e, t = R(e)) {
|
|
479
501
|
return e.kind === "pseudo_tool_call" ? e.name : t?.name ?? null;
|
|
480
502
|
}
|
|
481
|
-
function
|
|
503
|
+
function ue(e, t = R(e)) {
|
|
482
504
|
switch (e.kind) {
|
|
483
505
|
case "tool_start": return t.viaCallTool ? `${t.name} (via call_tool)` : t.name;
|
|
484
506
|
case "tool_end": return `${t.viaCallTool ? `${t.name} (via call_tool)` : t.name}${e.runtimeSeconds === void 0 ? "" : ` — ${e.runtimeSeconds.toFixed(2)}s`}${e.isError ? " — failed" : ""}`;
|
|
@@ -489,20 +511,20 @@ function H(e, t = B(e)) {
|
|
|
489
511
|
case "raw": return `Unrecognized event: ${e.eventType}`;
|
|
490
512
|
}
|
|
491
513
|
}
|
|
492
|
-
function
|
|
514
|
+
function B(e, t = R(e)) {
|
|
493
515
|
return e.kind === "tool_start" || e.kind === "tool_end" ? t.args ? JSON.stringify(t.args, null, 2) : e.args ?? null : e.kind === "pseudo_tool_call" ? e.args ?? null : null;
|
|
494
516
|
}
|
|
495
|
-
function
|
|
517
|
+
function V(e) {
|
|
496
518
|
return e.kind === "tool_end" ? e.output ?? null : null;
|
|
497
519
|
}
|
|
498
|
-
function
|
|
520
|
+
function H(e) {
|
|
499
521
|
return e.kind === "raw" ? e.raw : e.kind === "error" ? e.rawBody ?? null : null;
|
|
500
522
|
}
|
|
501
|
-
function
|
|
523
|
+
function U(e) {
|
|
502
524
|
switch (e.kind) {
|
|
503
|
-
case "tool_start": return `Calling ${
|
|
525
|
+
case "tool_start": return `Calling ${k(e.name, e.args).name}...`;
|
|
504
526
|
case "tool_end": {
|
|
505
|
-
let t =
|
|
527
|
+
let t = k(e.name, e.args).name;
|
|
506
528
|
return e.isError ? `${t} failed` : `${t} returned`;
|
|
507
529
|
}
|
|
508
530
|
case "pseudo_tool_call": return `${e.name} (written as text, not called)`;
|
|
@@ -512,11 +534,11 @@ function K(e) {
|
|
|
512
534
|
case "raw": return `Unrecognized event: ${e.eventType}`;
|
|
513
535
|
}
|
|
514
536
|
}
|
|
515
|
-
function
|
|
537
|
+
function W(e) {
|
|
516
538
|
let t = new Date(e);
|
|
517
539
|
return `${String(t.getHours()).padStart(2, "0")}:${String(t.getMinutes()).padStart(2, "0")}:${String(t.getSeconds()).padStart(2, "0")}.${String(t.getMilliseconds()).padStart(3, "0")}`;
|
|
518
540
|
}
|
|
519
|
-
function
|
|
541
|
+
function G(e) {
|
|
520
542
|
if (e <= 0) return "+0ms";
|
|
521
543
|
if (e < 1e3) return `+${Math.round(e)}ms`;
|
|
522
544
|
let t = e / 1e3;
|
|
@@ -524,30 +546,30 @@ function J(e) {
|
|
|
524
546
|
let n = Math.floor(t / 60), r = Math.round(t % 60);
|
|
525
547
|
return `+${n}m${String(r).padStart(2, "0")}s`;
|
|
526
548
|
}
|
|
527
|
-
function
|
|
549
|
+
function K(e) {
|
|
528
550
|
return e.map((t, n) => {
|
|
529
|
-
let r =
|
|
551
|
+
let r = R(t), i = n === 0 ? t.turnSentAt : e[n - 1].at;
|
|
530
552
|
return {
|
|
531
553
|
key: `${t.at}-${n}`,
|
|
532
554
|
kind: t.kind,
|
|
533
|
-
toolName:
|
|
555
|
+
toolName: z(t, r),
|
|
534
556
|
isToolStart: t.kind === "tool_start",
|
|
535
557
|
failed: t.kind === "tool_end" && t.isError === !0,
|
|
536
|
-
time:
|
|
558
|
+
time: W(t.at),
|
|
537
559
|
gapMs: t.at - i,
|
|
538
|
-
label: t.kind === "tool_end" && t.isError === !0 ? "Tool failed" :
|
|
539
|
-
summary:
|
|
540
|
-
argsDetail:
|
|
541
|
-
outputDetail:
|
|
542
|
-
rawDetail:
|
|
560
|
+
label: t.kind === "tool_end" && t.isError === !0 ? "Tool failed" : le[t.kind],
|
|
561
|
+
summary: ue(t, r),
|
|
562
|
+
argsDetail: B(t, r),
|
|
563
|
+
outputDetail: V(t),
|
|
564
|
+
rawDetail: H(t)
|
|
543
565
|
};
|
|
544
566
|
});
|
|
545
567
|
}
|
|
546
|
-
function
|
|
568
|
+
function q(e) {
|
|
547
569
|
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 = [];
|
|
548
570
|
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(" · ");
|
|
549
571
|
}
|
|
550
|
-
function
|
|
572
|
+
function J(e) {
|
|
551
573
|
let t = [];
|
|
552
574
|
for (let n of e) {
|
|
553
575
|
let e = t[t.length - 1];
|
|
@@ -566,12 +588,19 @@ function ae(e) {
|
|
|
566
588
|
}
|
|
567
589
|
return t;
|
|
568
590
|
}
|
|
569
|
-
function
|
|
591
|
+
function Y(e) {
|
|
570
592
|
return e.some((e) => e.kind === "tool_end" && e.isError || e.kind === "error");
|
|
571
593
|
}
|
|
594
|
+
function X(e, t) {
|
|
595
|
+
return t === void 0 ? [] : e.filter((e) => e.turnSentAt === t && (e.kind === "tool_end" || e.kind === "pseudo_tool_call" || e.kind === "progress")).map((e, t) => ({
|
|
596
|
+
key: `${e.at}-${t}`,
|
|
597
|
+
text: U(e),
|
|
598
|
+
toolName: z(e)
|
|
599
|
+
}));
|
|
600
|
+
}
|
|
572
601
|
//#endregion
|
|
573
602
|
//#region src/ui/markdown.tsx
|
|
574
|
-
function
|
|
603
|
+
function de({ renderTable: t, renderChart: n } = {}) {
|
|
575
604
|
return {
|
|
576
605
|
a: ({ href: t, children: n }) => !t || !e(t) ? /* @__PURE__ */ u(l, { children: n }) : /* @__PURE__ */ u("a", {
|
|
577
606
|
href: t,
|
|
@@ -580,8 +609,8 @@ function se({ renderTable: t, renderChart: n } = {}) {
|
|
|
580
609
|
children: n
|
|
581
610
|
}),
|
|
582
611
|
table: ({ node: n, children: r }) => {
|
|
583
|
-
let i = n &&
|
|
584
|
-
if (i &&
|
|
612
|
+
let i = n && I(n);
|
|
613
|
+
if (i && te(i.rows) && t) {
|
|
585
614
|
let n = i.rows.map((t) => t.map((t) => t.href && !e(t.href) ? { text: t.text } : t));
|
|
586
615
|
return /* @__PURE__ */ u(l, { children: t({
|
|
587
616
|
headers: i.headers,
|
|
@@ -593,7 +622,7 @@ function se({ renderTable: t, renderChart: n } = {}) {
|
|
|
593
622
|
pre: ({ children: e }) => {
|
|
594
623
|
let t = (Array.isArray(e) ? e[0] : e)?.props;
|
|
595
624
|
if ((t?.className?.split(" ") ?? []).includes("language-chartjs") && n) {
|
|
596
|
-
let e = t?.children, r =
|
|
625
|
+
let e = t?.children, r = L(Array.isArray(e) ? e.join("") : String(e ?? ""));
|
|
597
626
|
if (r) return /* @__PURE__ */ u(l, { children: n(r) });
|
|
598
627
|
}
|
|
599
628
|
return /* @__PURE__ */ u("pre", { children: e });
|
|
@@ -601,9 +630,82 @@ function se({ renderTable: t, renderChart: n } = {}) {
|
|
|
601
630
|
};
|
|
602
631
|
}
|
|
603
632
|
//#endregion
|
|
633
|
+
//#region src/ui/icons.tsx
|
|
634
|
+
function fe({ className: e }) {
|
|
635
|
+
return /* @__PURE__ */ u("svg", {
|
|
636
|
+
viewBox: "0 0 24 24",
|
|
637
|
+
fill: "currentColor",
|
|
638
|
+
className: e,
|
|
639
|
+
"aria-hidden": "true",
|
|
640
|
+
children: /* @__PURE__ */ u("path", { d: "M12 20.3s-7.6-4.7-10-9.4C.4 7.7 1.7 4 5.2 3.1c2.2-.6 4.4.4 5.5 2.2 1.2-1.8 3.4-2.8 5.6-2.2 3.5.9 4.8 4.6 3.2 7.8-2.4 4.7-10 9.4-10 9.4z" })
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
function Z({ className: e }) {
|
|
644
|
+
return /* @__PURE__ */ d("svg", {
|
|
645
|
+
viewBox: "0 0 24 24",
|
|
646
|
+
fill: "none",
|
|
647
|
+
stroke: "currentColor",
|
|
648
|
+
strokeWidth: 2,
|
|
649
|
+
strokeLinecap: "round",
|
|
650
|
+
strokeLinejoin: "round",
|
|
651
|
+
className: e,
|
|
652
|
+
"aria-hidden": "true",
|
|
653
|
+
children: [/* @__PURE__ */ u("path", { d: "M7 17 17 7" }), /* @__PURE__ */ u("path", { d: "M9 7h8v8" })]
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
function pe({ className: e }) {
|
|
657
|
+
return /* @__PURE__ */ d("svg", {
|
|
658
|
+
viewBox: "0 0 24 24",
|
|
659
|
+
fill: "none",
|
|
660
|
+
stroke: "currentColor",
|
|
661
|
+
strokeWidth: 2,
|
|
662
|
+
strokeLinecap: "round",
|
|
663
|
+
strokeLinejoin: "round",
|
|
664
|
+
className: e,
|
|
665
|
+
"aria-hidden": "true",
|
|
666
|
+
children: [/* @__PURE__ */ u("rect", {
|
|
667
|
+
x: "8",
|
|
668
|
+
y: "8",
|
|
669
|
+
width: "12",
|
|
670
|
+
height: "12",
|
|
671
|
+
rx: "2"
|
|
672
|
+
}), /* @__PURE__ */ u("path", { d: "M16 8V6a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h2" })]
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
function me({ className: e }) {
|
|
676
|
+
return /* @__PURE__ */ u("svg", {
|
|
677
|
+
viewBox: "0 0 24 24",
|
|
678
|
+
fill: "none",
|
|
679
|
+
stroke: "currentColor",
|
|
680
|
+
strokeWidth: 2,
|
|
681
|
+
strokeLinecap: "round",
|
|
682
|
+
strokeLinejoin: "round",
|
|
683
|
+
className: e,
|
|
684
|
+
"aria-hidden": "true",
|
|
685
|
+
children: /* @__PURE__ */ u("path", { d: "M5 12.5 9.5 17 19 7" })
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
function he({ className: e }) {
|
|
689
|
+
return /* @__PURE__ */ d("svg", {
|
|
690
|
+
viewBox: "0 0 24 24",
|
|
691
|
+
fill: "none",
|
|
692
|
+
stroke: "currentColor",
|
|
693
|
+
strokeWidth: 2,
|
|
694
|
+
strokeLinecap: "round",
|
|
695
|
+
strokeLinejoin: "round",
|
|
696
|
+
className: e,
|
|
697
|
+
"aria-hidden": "true",
|
|
698
|
+
children: [/* @__PURE__ */ u("circle", {
|
|
699
|
+
cx: "12",
|
|
700
|
+
cy: "12",
|
|
701
|
+
r: "9"
|
|
702
|
+
}), /* @__PURE__ */ u("path", { d: "M8.5 12.5 11 15l4.5-5.5" })]
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
//#endregion
|
|
604
706
|
//#region src/ui/CopyMarkdownButton.tsx
|
|
605
|
-
var
|
|
606
|
-
function
|
|
707
|
+
var ge = 1500;
|
|
708
|
+
function _e({ markdown: e, className: t }) {
|
|
607
709
|
let [n, i] = o(!1), [s, c] = o(!1), l = a(null);
|
|
608
710
|
return r(() => () => {
|
|
609
711
|
l.current !== null && clearTimeout(l.current);
|
|
@@ -620,11 +722,11 @@ function le({ markdown: e, className: t }) {
|
|
|
620
722
|
try {
|
|
621
723
|
await navigator.clipboard.writeText(e);
|
|
622
724
|
} catch {}
|
|
623
|
-
i(!0), l.current !== null && clearTimeout(l.current), l.current = setTimeout(() => i(!1),
|
|
725
|
+
i(!0), l.current !== null && clearTimeout(l.current), l.current = setTimeout(() => i(!1), ge);
|
|
624
726
|
},
|
|
625
727
|
"aria-label": "copy response as markdown",
|
|
626
728
|
className: `bailey-copy-button${t ? ` ${t}` : ""}`,
|
|
627
|
-
children: n ?
|
|
729
|
+
children: u(n ? me : pe, { className: "bailey-copy-icon" })
|
|
628
730
|
})
|
|
629
731
|
}), /* @__PURE__ */ u(f.Portal, { children: /* @__PURE__ */ d(f.Content, {
|
|
630
732
|
side: "top",
|
|
@@ -636,20 +738,20 @@ function le({ markdown: e, className: t }) {
|
|
|
636
738
|
}
|
|
637
739
|
//#endregion
|
|
638
740
|
//#region src/ui/BaileyTracePanel.tsx
|
|
639
|
-
async function
|
|
741
|
+
async function ve(e) {
|
|
640
742
|
try {
|
|
641
743
|
await navigator.clipboard.writeText(e);
|
|
642
744
|
} catch {}
|
|
643
745
|
}
|
|
644
|
-
function
|
|
746
|
+
function ye({ text: e, label: t = "Copy" }) {
|
|
645
747
|
return /* @__PURE__ */ u("button", {
|
|
646
748
|
type: "button",
|
|
647
|
-
onClick: () =>
|
|
749
|
+
onClick: () => ve(e),
|
|
648
750
|
className: "bailey-trace-copy-button",
|
|
649
751
|
children: t
|
|
650
752
|
});
|
|
651
753
|
}
|
|
652
|
-
function
|
|
754
|
+
function be(e) {
|
|
653
755
|
if (e.failed || e.kind === "error") return "bailey-trace-chip bailey-trace-chip-error";
|
|
654
756
|
switch (e.kind) {
|
|
655
757
|
case "tool_start": return "bailey-trace-chip bailey-trace-chip-info";
|
|
@@ -658,7 +760,7 @@ function fe(e) {
|
|
|
658
760
|
default: return "bailey-trace-chip bailey-trace-chip-default";
|
|
659
761
|
}
|
|
660
762
|
}
|
|
661
|
-
function
|
|
763
|
+
function Q({ label: e, content: t, copyable: n }) {
|
|
662
764
|
return /* @__PURE__ */ d("details", {
|
|
663
765
|
className: "bailey-trace-disclosure",
|
|
664
766
|
children: [
|
|
@@ -668,7 +770,7 @@ function Z({ label: e, content: t, copyable: n }) {
|
|
|
668
770
|
}),
|
|
669
771
|
n && /* @__PURE__ */ u("div", {
|
|
670
772
|
className: "bailey-trace-disclosure-actions",
|
|
671
|
-
children: /* @__PURE__ */ u(
|
|
773
|
+
children: /* @__PURE__ */ u(ye, { text: t })
|
|
672
774
|
}),
|
|
673
775
|
/* @__PURE__ */ u("pre", {
|
|
674
776
|
className: "bailey-trace-disclosure-content",
|
|
@@ -677,7 +779,7 @@ function Z({ label: e, content: t, copyable: n }) {
|
|
|
677
779
|
]
|
|
678
780
|
});
|
|
679
781
|
}
|
|
680
|
-
function
|
|
782
|
+
function $({ row: e }) {
|
|
681
783
|
return /* @__PURE__ */ d("div", {
|
|
682
784
|
className: "bailey-trace-row",
|
|
683
785
|
children: [
|
|
@@ -691,10 +793,10 @@ function Q({ row: e }) {
|
|
|
691
793
|
/* @__PURE__ */ u("span", {
|
|
692
794
|
className: "bailey-trace-row-gap",
|
|
693
795
|
title: "Time since the previous event",
|
|
694
|
-
children:
|
|
796
|
+
children: G(e.gapMs)
|
|
695
797
|
}),
|
|
696
798
|
/* @__PURE__ */ u("span", {
|
|
697
|
-
className:
|
|
799
|
+
className: be(e),
|
|
698
800
|
children: e.label
|
|
699
801
|
}),
|
|
700
802
|
/* @__PURE__ */ u("span", {
|
|
@@ -703,28 +805,28 @@ function Q({ row: e }) {
|
|
|
703
805
|
})
|
|
704
806
|
]
|
|
705
807
|
}),
|
|
706
|
-
e.argsDetail && /* @__PURE__ */ u(
|
|
808
|
+
e.argsDetail && /* @__PURE__ */ u(Q, {
|
|
707
809
|
label: "args",
|
|
708
810
|
content: e.argsDetail
|
|
709
811
|
}),
|
|
710
|
-
e.outputDetail && /* @__PURE__ */ u(
|
|
812
|
+
e.outputDetail && /* @__PURE__ */ u(Q, {
|
|
711
813
|
label: "output",
|
|
712
814
|
content: e.outputDetail
|
|
713
815
|
}),
|
|
714
|
-
e.rawDetail && /* @__PURE__ */ u(
|
|
816
|
+
e.rawDetail && /* @__PURE__ */ u(Q, {
|
|
715
817
|
label: "raw",
|
|
716
818
|
content: e.rawDetail
|
|
717
819
|
})
|
|
718
820
|
]
|
|
719
821
|
});
|
|
720
822
|
}
|
|
721
|
-
function
|
|
823
|
+
function xe(e, t) {
|
|
722
824
|
if (e.chunkCount === 0) return "Streamed: no chunks received";
|
|
723
825
|
if (e.chunkCount === 1 || e.firstChunkAt === null) return "Streamed: 1 chunk (not incremental)";
|
|
724
826
|
let n = e.firstChunkAt - t, r = (e.lastChunkAt ?? e.firstChunkAt) - e.firstChunkAt;
|
|
725
827
|
return `Streamed: ${e.chunkCount} chunks · first chunk after ${n}ms · spread over ${(r / 1e3).toFixed(1)}s`;
|
|
726
828
|
}
|
|
727
|
-
function
|
|
829
|
+
function Se({ request: e }) {
|
|
728
830
|
let t = i(() => JSON.stringify({
|
|
729
831
|
model: e.model,
|
|
730
832
|
instructions: e.systemPrompt,
|
|
@@ -748,24 +850,24 @@ function me({ request: e }) {
|
|
|
748
850
|
}),
|
|
749
851
|
/* @__PURE__ */ u("span", {
|
|
750
852
|
className: "bailey-trace-request-meta",
|
|
751
|
-
children:
|
|
853
|
+
children: xe(e.streamStats, e.sentAt)
|
|
752
854
|
}),
|
|
753
|
-
/* @__PURE__ */ u(
|
|
855
|
+
/* @__PURE__ */ u(Q, {
|
|
754
856
|
label: `System prompt (${e.systemPrompt.length.toLocaleString()} chars)`,
|
|
755
857
|
content: e.systemPrompt,
|
|
756
858
|
copyable: !0
|
|
757
859
|
}),
|
|
758
|
-
/* @__PURE__ */ u(
|
|
860
|
+
/* @__PURE__ */ u(Q, {
|
|
759
861
|
label: `Messages (${e.messages.length})`,
|
|
760
862
|
content: JSON.stringify(e.messages, null, 2),
|
|
761
863
|
copyable: !0
|
|
762
864
|
}),
|
|
763
|
-
e.response && /* @__PURE__ */ u(
|
|
865
|
+
e.response && /* @__PURE__ */ u(Q, {
|
|
764
866
|
label: `Response (${e.response.content.length.toLocaleString()} chars)`,
|
|
765
867
|
content: e.response.content,
|
|
766
868
|
copyable: !0
|
|
767
869
|
}),
|
|
768
|
-
/* @__PURE__ */ u(
|
|
870
|
+
/* @__PURE__ */ u(Q, {
|
|
769
871
|
label: "Full payload (JSON)",
|
|
770
872
|
content: t,
|
|
771
873
|
copyable: !0
|
|
@@ -773,14 +875,14 @@ function me({ request: e }) {
|
|
|
773
875
|
]
|
|
774
876
|
});
|
|
775
877
|
}
|
|
776
|
-
function
|
|
777
|
-
let r = i(() =>
|
|
878
|
+
function Ce({ events: e, lastRequest: t, onClear: n }) {
|
|
879
|
+
let r = i(() => K(e), [e]), a = i(() => J(r), [r]), o = i(() => JSON.stringify(e, null, 2), [e]);
|
|
778
880
|
return /* @__PURE__ */ d("div", {
|
|
779
881
|
className: "bailey-trace-body",
|
|
780
882
|
children: [
|
|
781
883
|
/* @__PURE__ */ d("div", {
|
|
782
884
|
className: "bailey-trace-actions-row",
|
|
783
|
-
children: [e.length > 0 && /* @__PURE__ */ u(
|
|
885
|
+
children: [e.length > 0 && /* @__PURE__ */ u(ye, {
|
|
784
886
|
text: o,
|
|
785
887
|
label: "Copy trace as JSON"
|
|
786
888
|
}), /* @__PURE__ */ u("button", {
|
|
@@ -790,15 +892,15 @@ function he({ events: e, lastRequest: t, onClear: n }) {
|
|
|
790
892
|
children: "Clear"
|
|
791
893
|
})]
|
|
792
894
|
}),
|
|
793
|
-
t && /* @__PURE__ */ u(
|
|
895
|
+
t && /* @__PURE__ */ u(Se, { request: t }),
|
|
794
896
|
/* @__PURE__ */ u("div", {
|
|
795
897
|
className: "bailey-trace-rows",
|
|
796
898
|
children: a.map((e, t) => {
|
|
797
|
-
if (e.type === "single") return /* @__PURE__ */ u(
|
|
899
|
+
if (e.type === "single") return /* @__PURE__ */ u($, { row: e.row }, e.row.key);
|
|
798
900
|
let n = e.rows.filter((e) => e.isToolStart).length;
|
|
799
901
|
if (n <= 1) return /* @__PURE__ */ u("div", {
|
|
800
902
|
className: "bailey-trace-rows",
|
|
801
|
-
children: e.rows.map((e) => /* @__PURE__ */ u(
|
|
903
|
+
children: e.rows.map((e) => /* @__PURE__ */ u($, { row: e }, e.key))
|
|
802
904
|
}, `group-${t}`);
|
|
803
905
|
let r = e.rows.filter((e) => e.failed).length;
|
|
804
906
|
return /* @__PURE__ */ d("details", {
|
|
@@ -820,7 +922,7 @@ function he({ events: e, lastRequest: t, onClear: n }) {
|
|
|
820
922
|
]
|
|
821
923
|
}), /* @__PURE__ */ u("div", {
|
|
822
924
|
className: "bailey-trace-rows",
|
|
823
|
-
children: e.rows.map((e) => /* @__PURE__ */ u(
|
|
925
|
+
children: e.rows.map((e) => /* @__PURE__ */ u($, { row: e }, e.key))
|
|
824
926
|
})]
|
|
825
927
|
}, `group-${t}`);
|
|
826
928
|
})
|
|
@@ -828,8 +930,8 @@ function he({ events: e, lastRequest: t, onClear: n }) {
|
|
|
828
930
|
]
|
|
829
931
|
});
|
|
830
932
|
}
|
|
831
|
-
function
|
|
832
|
-
let [r, a] = o(!1), s = i(() =>
|
|
933
|
+
function we({ events: e, lastRequest: t, onClear: n }) {
|
|
934
|
+
let [r, a] = o(!1), s = i(() => Y(e), [e]), c = i(() => q(e), [e]);
|
|
833
935
|
return e.length === 0 && !t ? null : /* @__PURE__ */ d("div", {
|
|
834
936
|
className: "bailey-trace-panel",
|
|
835
937
|
children: [/* @__PURE__ */ d("div", {
|
|
@@ -850,7 +952,7 @@ function $({ events: e, lastRequest: t, onClear: n }) {
|
|
|
850
952
|
className: s ? "bailey-trace-summary bailey-trace-summary-error" : "bailey-trace-summary",
|
|
851
953
|
children: c
|
|
852
954
|
})]
|
|
853
|
-
}), r && /* @__PURE__ */ u(
|
|
955
|
+
}), r && /* @__PURE__ */ u(Ce, {
|
|
854
956
|
events: e,
|
|
855
957
|
lastRequest: t,
|
|
856
958
|
onClear: n
|
|
@@ -859,144 +961,198 @@ function $({ events: e, lastRequest: t, onClear: n }) {
|
|
|
859
961
|
}
|
|
860
962
|
//#endregion
|
|
861
963
|
//#region src/ui/BaileyChatPanel.tsx
|
|
862
|
-
var
|
|
964
|
+
var Te = "How can bailey AI help you today?", Ee = "Reply to bailey AI", De = [c], Oe = t(function({ content: e, components: t }) {
|
|
863
965
|
return /* @__PURE__ */ u("div", {
|
|
864
966
|
className: "bailey-markdown-content",
|
|
865
967
|
children: /* @__PURE__ */ u(s, {
|
|
866
|
-
remarkPlugins:
|
|
968
|
+
remarkPlugins: De,
|
|
867
969
|
components: t,
|
|
868
970
|
children: e
|
|
869
971
|
})
|
|
870
972
|
});
|
|
871
973
|
});
|
|
872
|
-
function
|
|
974
|
+
function ke(e, t, n) {
|
|
873
975
|
if (e !== "streaming") return;
|
|
874
976
|
let r = t.filter((e) => e.turnSentAt === n?.sentAt);
|
|
875
|
-
if (r.length !== 0) return
|
|
876
|
-
}
|
|
877
|
-
function
|
|
878
|
-
let
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
})
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
])
|
|
977
|
+
if (r.length !== 0) return U(r[r.length - 1]);
|
|
978
|
+
}
|
|
979
|
+
function Ae(e) {
|
|
980
|
+
let t = new Date(e), n = t.toDateString() === (/* @__PURE__ */ new Date()).toDateString(), r = t.toLocaleTimeString([], {
|
|
981
|
+
hour: "numeric",
|
|
982
|
+
minute: "2-digit"
|
|
983
|
+
});
|
|
984
|
+
return n ? `Today ${r}` : `${t.toLocaleDateString()} ${r}`;
|
|
985
|
+
}
|
|
986
|
+
function je({ chat: e, placeholder: t, replyPlaceholder: n = Ee, suggestions: s, privacyNote: c, resolveActivityIcon: l, className: f, height: p, width: m, hideDeveloperDetails: h = !1, renderMessageActions: g, renderTable: _, renderChart: v }) {
|
|
987
|
+
let { messages: y, traceEvents: b, lastRequest: x, status: S, error: C, send: w, stop: ee, retryLast: T, clearTrace: E, clearError: D, newChat: O } = e, [k, A] = o(""), j = a(null), M = i(() => de({
|
|
988
|
+
renderTable: _,
|
|
989
|
+
renderChart: v
|
|
990
|
+
}), [_, v]), N = i(() => ke(S, b, x), [
|
|
991
|
+
S,
|
|
992
|
+
b,
|
|
993
|
+
x
|
|
994
|
+
]), P = y.length === 0, F = t ?? (P ? Te : n);
|
|
886
995
|
return r(() => {
|
|
887
|
-
|
|
996
|
+
j.current?.scrollIntoView({
|
|
888
997
|
behavior: "smooth",
|
|
889
998
|
block: "nearest"
|
|
890
999
|
});
|
|
891
|
-
}, [
|
|
892
|
-
className: `bailey-chat-panel${
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
className: "bailey-
|
|
902
|
-
children: "
|
|
903
|
-
})
|
|
904
|
-
}),
|
|
905
|
-
/* @__PURE__ */ d("div", {
|
|
906
|
-
className: "bailey-chat-transcript",
|
|
907
|
-
children: [
|
|
908
|
-
f.length === 0 && /* @__PURE__ */ u("div", {
|
|
909
|
-
className: "bailey-empty-state",
|
|
910
|
-
children: "Ask Bailey a question to get started."
|
|
911
|
-
}),
|
|
912
|
-
f.map((e, t) => {
|
|
913
|
-
let n = e.role === "assistant" && t === f.length - 1, r = h === "streaming" && n && e.content === "";
|
|
914
|
-
return /* @__PURE__ */ u("div", {
|
|
915
|
-
className: e.role === "user" ? "bailey-message-row bailey-message-row-user" : "bailey-message-row",
|
|
916
|
-
children: e.role === "user" ? /* @__PURE__ */ u("div", {
|
|
917
|
-
className: "bailey-user-bubble",
|
|
918
|
-
children: e.content
|
|
919
|
-
}) : r ? /* @__PURE__ */ u("div", {
|
|
920
|
-
className: "bailey-thinking-hint",
|
|
921
|
-
children: D ?? "Thinking…"
|
|
922
|
-
}) : /* @__PURE__ */ d("div", {
|
|
923
|
-
className: "bailey-assistant-message",
|
|
924
|
-
children: [
|
|
925
|
-
/* @__PURE__ */ u(_e, {
|
|
926
|
-
content: e.content,
|
|
927
|
-
components: E
|
|
928
|
-
}),
|
|
929
|
-
e.streaming && D && /* @__PURE__ */ u("div", {
|
|
930
|
-
className: "bailey-streaming-hint",
|
|
931
|
-
children: D
|
|
932
|
-
}),
|
|
933
|
-
!e.streaming && /* @__PURE__ */ d("div", {
|
|
934
|
-
className: "bailey-message-actions",
|
|
935
|
-
children: [/* @__PURE__ */ u(le, { markdown: e.content }), s?.(e)]
|
|
936
|
-
})
|
|
937
|
-
]
|
|
938
|
-
})
|
|
939
|
-
}, e.id);
|
|
940
|
-
}),
|
|
941
|
-
/* @__PURE__ */ u("div", { ref: T })
|
|
942
|
-
]
|
|
943
|
-
}),
|
|
944
|
-
g && /* @__PURE__ */ d("div", {
|
|
945
|
-
className: "bailey-error-banner",
|
|
946
|
-
role: "alert",
|
|
947
|
-
children: [/* @__PURE__ */ u("span", { children: g }), /* @__PURE__ */ d("div", {
|
|
948
|
-
className: "bailey-error-actions",
|
|
949
|
-
children: [/* @__PURE__ */ u("button", {
|
|
1000
|
+
}, [y]), /* @__PURE__ */ u("div", {
|
|
1001
|
+
className: `bailey-chat-panel${f ? ` ${f}` : ""}`,
|
|
1002
|
+
style: p !== void 0 || m !== void 0 ? {
|
|
1003
|
+
height: p,
|
|
1004
|
+
width: m
|
|
1005
|
+
} : void 0,
|
|
1006
|
+
children: /* @__PURE__ */ d("div", {
|
|
1007
|
+
className: "bailey-chat-panel-inner",
|
|
1008
|
+
children: [
|
|
1009
|
+
/* @__PURE__ */ u("div", {
|
|
1010
|
+
className: "bailey-toolbar-row",
|
|
1011
|
+
children: /* @__PURE__ */ u("button", {
|
|
950
1012
|
type: "button",
|
|
951
|
-
onClick:
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
1013
|
+
onClick: O,
|
|
1014
|
+
disabled: y.length === 0,
|
|
1015
|
+
"aria-label": "new chat",
|
|
1016
|
+
className: "bailey-new-chat-button",
|
|
1017
|
+
children: "New chat"
|
|
1018
|
+
})
|
|
1019
|
+
}),
|
|
1020
|
+
/* @__PURE__ */ d("div", {
|
|
1021
|
+
className: "bailey-chat-transcript",
|
|
1022
|
+
children: [
|
|
1023
|
+
P && (s && s.length > 0 ? /* @__PURE__ */ d("div", {
|
|
1024
|
+
className: "bailey-suggestions",
|
|
1025
|
+
children: [/* @__PURE__ */ u("div", {
|
|
1026
|
+
className: "bailey-suggestions-title",
|
|
1027
|
+
children: "Suggested for you"
|
|
1028
|
+
}), s.map((e, t) => /* @__PURE__ */ d("button", {
|
|
1029
|
+
type: "button",
|
|
1030
|
+
onClick: () => w(e.value ?? e.label),
|
|
1031
|
+
className: "bailey-suggestion-card",
|
|
1032
|
+
children: [/* @__PURE__ */ u("span", { children: e.label }), /* @__PURE__ */ u(Z, { className: "bailey-suggestion-icon" })]
|
|
1033
|
+
}, `${e.label}-${t}`))]
|
|
1034
|
+
}) : /* @__PURE__ */ u("div", {
|
|
1035
|
+
className: "bailey-empty-state",
|
|
1036
|
+
children: "Ask Bailey a question to get started."
|
|
1037
|
+
})),
|
|
1038
|
+
y.map((e, t) => {
|
|
1039
|
+
let n = e.role === "assistant" && t === y.length - 1, r = S === "streaming" && n && e.content === "", i = e.role === "assistant" && !r ? X(b, e.createdAt) : [], a = i[i.length - 1];
|
|
1040
|
+
return /* @__PURE__ */ u("div", {
|
|
1041
|
+
className: e.role === "user" ? "bailey-message-row bailey-message-row-user" : "bailey-message-row",
|
|
1042
|
+
children: e.role === "user" ? /* @__PURE__ */ d("div", {
|
|
1043
|
+
className: "bailey-user-message",
|
|
1044
|
+
children: [/* @__PURE__ */ d("div", {
|
|
1045
|
+
className: "bailey-message-meta",
|
|
1046
|
+
children: [/* @__PURE__ */ u("span", {
|
|
1047
|
+
className: "bailey-message-meta-name",
|
|
1048
|
+
children: "You"
|
|
1049
|
+
}), e.createdAt !== void 0 && /* @__PURE__ */ u("span", { children: Ae(e.createdAt) })]
|
|
1050
|
+
}), /* @__PURE__ */ u("div", {
|
|
1051
|
+
className: "bailey-user-bubble",
|
|
1052
|
+
children: e.content
|
|
1053
|
+
})]
|
|
1054
|
+
}) : r ? /* @__PURE__ */ u("div", {
|
|
1055
|
+
className: "bailey-thinking-hint",
|
|
1056
|
+
children: N ?? "Thinking…"
|
|
1057
|
+
}) : /* @__PURE__ */ d("div", {
|
|
1058
|
+
className: "bailey-assistant-message",
|
|
1059
|
+
children: [
|
|
1060
|
+
a && /* @__PURE__ */ d("div", {
|
|
1061
|
+
className: "bailey-activity-line",
|
|
1062
|
+
children: [/* @__PURE__ */ u("span", {
|
|
1063
|
+
className: "bailey-activity-icon",
|
|
1064
|
+
children: l?.(a.toolName) ?? /* @__PURE__ */ u(he, {})
|
|
1065
|
+
}), /* @__PURE__ */ u("span", { children: a.text })]
|
|
1066
|
+
}),
|
|
1067
|
+
/* @__PURE__ */ u(Oe, {
|
|
1068
|
+
content: e.content,
|
|
1069
|
+
components: M
|
|
1070
|
+
}),
|
|
1071
|
+
e.streaming && N && /* @__PURE__ */ u("div", {
|
|
1072
|
+
className: "bailey-streaming-hint",
|
|
1073
|
+
children: N
|
|
1074
|
+
}),
|
|
1075
|
+
!e.streaming && /* @__PURE__ */ d("div", {
|
|
1076
|
+
className: "bailey-message-actions",
|
|
1077
|
+
children: [/* @__PURE__ */ u(_e, { markdown: e.content }), g?.(e)]
|
|
1078
|
+
})
|
|
1079
|
+
]
|
|
1080
|
+
})
|
|
1081
|
+
}, e.id);
|
|
1082
|
+
}),
|
|
1083
|
+
/* @__PURE__ */ u("div", { ref: j })
|
|
1084
|
+
]
|
|
1085
|
+
}),
|
|
1086
|
+
P && c && /* @__PURE__ */ d("div", {
|
|
1087
|
+
className: "bailey-privacy-note",
|
|
1088
|
+
children: [
|
|
1089
|
+
c.text,
|
|
1090
|
+
" ",
|
|
1091
|
+
/* @__PURE__ */ u("a", {
|
|
1092
|
+
href: c.linkHref,
|
|
1093
|
+
target: "_blank",
|
|
1094
|
+
rel: "noreferrer",
|
|
1095
|
+
children: c.linkLabel
|
|
1096
|
+
})
|
|
1097
|
+
]
|
|
1098
|
+
}),
|
|
1099
|
+
C && /* @__PURE__ */ d("div", {
|
|
1100
|
+
className: "bailey-error-banner",
|
|
1101
|
+
role: "alert",
|
|
1102
|
+
children: [/* @__PURE__ */ u("span", { children: C }), /* @__PURE__ */ d("div", {
|
|
1103
|
+
className: "bailey-error-actions",
|
|
1104
|
+
children: [/* @__PURE__ */ u("button", {
|
|
1105
|
+
type: "button",
|
|
1106
|
+
onClick: T,
|
|
1107
|
+
className: "bailey-retry-button",
|
|
1108
|
+
children: "Retry"
|
|
1109
|
+
}), /* @__PURE__ */ u("button", {
|
|
1110
|
+
type: "button",
|
|
1111
|
+
onClick: D,
|
|
1112
|
+
"aria-label": "dismiss error",
|
|
1113
|
+
className: "bailey-dismiss-button",
|
|
1114
|
+
children: "✕"
|
|
1115
|
+
})]
|
|
1116
|
+
})]
|
|
1117
|
+
}),
|
|
1118
|
+
!h && /* @__PURE__ */ u(we, {
|
|
1119
|
+
events: b,
|
|
1120
|
+
lastRequest: x,
|
|
1121
|
+
onClear: E
|
|
1122
|
+
}),
|
|
1123
|
+
/* @__PURE__ */ d("form", {
|
|
1124
|
+
onSubmit: (e) => {
|
|
1125
|
+
e.preventDefault(), !(!k.trim() || S === "streaming") && (w(k), A(""));
|
|
1126
|
+
},
|
|
1127
|
+
className: "bailey-input-row",
|
|
1128
|
+
children: [/* @__PURE__ */ u("input", {
|
|
1129
|
+
type: "text",
|
|
1130
|
+
placeholder: F,
|
|
1131
|
+
"aria-label": F,
|
|
1132
|
+
value: k,
|
|
1133
|
+
onChange: (e) => A(e.target.value),
|
|
1134
|
+
disabled: S === "streaming",
|
|
1135
|
+
className: "bailey-input"
|
|
1136
|
+
}), S === "streaming" ? /* @__PURE__ */ u("button", {
|
|
955
1137
|
type: "button",
|
|
956
|
-
onClick:
|
|
957
|
-
"aria-label": "
|
|
958
|
-
className: "bailey-
|
|
959
|
-
children: "
|
|
1138
|
+
onClick: ee,
|
|
1139
|
+
"aria-label": "stop",
|
|
1140
|
+
className: "bailey-stop-button",
|
|
1141
|
+
children: "Stop"
|
|
1142
|
+
}) : /* @__PURE__ */ u("button", {
|
|
1143
|
+
type: "submit",
|
|
1144
|
+
"aria-label": "send",
|
|
1145
|
+
disabled: !k.trim(),
|
|
1146
|
+
className: "bailey-send-button",
|
|
1147
|
+
children: /* @__PURE__ */ u(fe, { className: "bailey-send-icon" })
|
|
960
1148
|
})]
|
|
961
|
-
})
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
events: p,
|
|
965
|
-
lastRequest: m,
|
|
966
|
-
onClear: b
|
|
967
|
-
}),
|
|
968
|
-
/* @__PURE__ */ d("form", {
|
|
969
|
-
onSubmit: (e) => {
|
|
970
|
-
e.preventDefault(), !(!C.trim() || h === "streaming") && (_(C), w(""));
|
|
971
|
-
},
|
|
972
|
-
className: "bailey-input-row",
|
|
973
|
-
children: [/* @__PURE__ */ u("input", {
|
|
974
|
-
type: "text",
|
|
975
|
-
placeholder: t,
|
|
976
|
-
"aria-label": t,
|
|
977
|
-
value: C,
|
|
978
|
-
onChange: (e) => w(e.target.value),
|
|
979
|
-
disabled: h === "streaming",
|
|
980
|
-
className: "bailey-input"
|
|
981
|
-
}), h === "streaming" ? /* @__PURE__ */ u("button", {
|
|
982
|
-
type: "button",
|
|
983
|
-
onClick: v,
|
|
984
|
-
"aria-label": "stop",
|
|
985
|
-
className: "bailey-stop-button",
|
|
986
|
-
children: "Stop"
|
|
987
|
-
}) : /* @__PURE__ */ u("button", {
|
|
988
|
-
type: "submit",
|
|
989
|
-
"aria-label": "send",
|
|
990
|
-
disabled: !C.trim(),
|
|
991
|
-
className: "bailey-send-button",
|
|
992
|
-
children: "Send"
|
|
993
|
-
})]
|
|
994
|
-
})
|
|
995
|
-
]
|
|
1149
|
+
})
|
|
1150
|
+
]
|
|
1151
|
+
})
|
|
996
1152
|
});
|
|
997
1153
|
}
|
|
998
1154
|
//#endregion
|
|
999
1155
|
//#region src/index.ts
|
|
1000
|
-
var
|
|
1156
|
+
var Me = "0.3.1-pre.2";
|
|
1001
1157
|
//#endregion
|
|
1002
|
-
export {
|
|
1158
|
+
export { he as ActivityIcon, Z as ArrowUpRightIcon, Me as BAILEYAI_CHAT_UI_VERSION, ne as BAILEY_CHART_PROMPT_FRAGMENT, A as BAILEY_TABLE_GRID_ROW_THRESHOLD, je as BaileyChatPanel, we as BaileyTracePanel, _e as CopyMarkdownButton, fe as HeartIcon, le as TRACE_KIND_LABEL, de as createBaileyMarkdownComponents, b as extractPseudoToolCalls, I as extractTableData, G as formatTraceGap, W as formatTraceTime, Y as hasTraceFailure, e as isSafeMarkdownUrl, E as joinInstructions, L as parseBaileyChartSpec, S as parseSseFrames, k as resolveToolCall, te as shouldUseGrid, X as toActivityLines, K as toTraceRows, J as toTraceSegments, B as traceEventArgsDetail, U as traceEventHint, V as traceEventOutputDetail, H as traceEventRawDetail, ue as traceEventSummary, z as traceEventToolName, q as traceSummaryLine, T as useBaileyChat };
|