@icanbwell/baileyai-chat-ui 1.2.0 → 1.2.1
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 +5 -0
- package/dist/baileyai-chat-ui.cjs +2 -2
- package/dist/baileyai-chat-ui.js +412 -408
- package/dist/index.d.ts +13 -2
- package/package.json +1 -1
package/dist/baileyai-chat-ui.js
CHANGED
|
@@ -6,9 +6,9 @@ import * as h from "@radix-ui/react-dropdown-menu";
|
|
|
6
6
|
import * as g from "@radix-ui/react-tooltip";
|
|
7
7
|
import { Fragment as _, jsx as v, jsxs as y } from "react/jsx-runtime";
|
|
8
8
|
// src/utils/pseudoToolCalls.ts
|
|
9
|
-
var b = "search_tools|call_tool|function_calls|function_result", x = RegExp(`<(${b})>([\\s\\S]*?)<\\/\\1>`, "g"),
|
|
9
|
+
var b = "search_tools|call_tool|function_calls|function_result", x = RegExp(`<(${b})>([\\s\\S]*?)<\\/\\1>`, "g"), ee = RegExp(`<(?:${b})>[\\s\\S]*$`), S = /<name>([\s\S]*?)<\/name>/, C = /<arguments>([\s\S]*?)<\/arguments>/, w = /<invoke\s+name="([^"]*)"\s*>([\s\S]*?)<\/invoke>/g, T = /<parameter\s+name="([^"]*)"\s*>([\s\S]*?)<\/parameter>/g;
|
|
10
10
|
function E(e) {
|
|
11
|
-
let t =
|
|
11
|
+
let t = S.exec(e)?.[1]?.trim() || "unknown_tool", n = C.exec(e)?.[1]?.trim();
|
|
12
12
|
return n ? {
|
|
13
13
|
name: t,
|
|
14
14
|
args: n
|
|
@@ -38,7 +38,7 @@ function O(e, t = {}) {
|
|
|
38
38
|
}) : t === "function_calls" ? r.push(...D(n)) : r.push({
|
|
39
39
|
name: "function_result",
|
|
40
40
|
args: n.trim()
|
|
41
|
-
}), "")), a = n ? i.replace(
|
|
41
|
+
}), "")), a = n ? i.replace(ee, "") : i;
|
|
42
42
|
return r.length === 0 && a === i ? {
|
|
43
43
|
cleanedText: i,
|
|
44
44
|
matches: r
|
|
@@ -132,7 +132,7 @@ var ne = (e) => te(e), M = class extends Error {
|
|
|
132
132
|
too_long: !0,
|
|
133
133
|
other: !0
|
|
134
134
|
}, P = (e) => Object.hasOwn(N, e) ? e : "other";
|
|
135
|
-
function
|
|
135
|
+
function F(e) {
|
|
136
136
|
if (!e || e.rating !== "up" && e.rating !== "down") return;
|
|
137
137
|
let t = (e.reasonCodes ?? []).map(P);
|
|
138
138
|
return {
|
|
@@ -141,11 +141,11 @@ function re(e) {
|
|
|
141
141
|
...e.comment ? { comment: e.comment } : {}
|
|
142
142
|
};
|
|
143
143
|
}
|
|
144
|
-
function
|
|
144
|
+
function re(e) {
|
|
145
145
|
let t = [];
|
|
146
146
|
return e.messages.forEach((e, n) => {
|
|
147
147
|
if (e.hidden || e.role !== "user" && e.role !== "assistant") return;
|
|
148
|
-
let r = Date.parse(e.createdAt), i = Number.isNaN(r) ? void 0 : r, a = e.messageId || `loaded-${n}-${e.role}-${i ?? 0}`, o = e.role === "assistant" ?
|
|
148
|
+
let r = Date.parse(e.createdAt), i = Number.isNaN(r) ? void 0 : r, a = e.messageId || `loaded-${n}-${e.role}-${i ?? 0}`, o = e.role === "assistant" ? F(e.feedback) : void 0;
|
|
149
149
|
t.push({
|
|
150
150
|
id: a,
|
|
151
151
|
role: e.role,
|
|
@@ -158,19 +158,19 @@ function F(e) {
|
|
|
158
158
|
}), t;
|
|
159
159
|
}
|
|
160
160
|
var I = (e) => e.serverMessageId ?? e.id;
|
|
161
|
-
function
|
|
161
|
+
function L(e) {
|
|
162
162
|
let t = new Set(e.current.map(I)), n = e.earlier.filter((e) => !t.has(I(e)));
|
|
163
163
|
return n.length === 0 ? e.current : [...n, ...e.current];
|
|
164
164
|
}
|
|
165
165
|
// src/logic/conversationId.ts
|
|
166
|
-
function
|
|
166
|
+
function R(e) {
|
|
167
167
|
let t = e.sub.trim();
|
|
168
168
|
if (!t) return !1;
|
|
169
169
|
let n = `${t}:`;
|
|
170
170
|
return e.conversationId.startsWith(n) && e.conversationId.length > n.length;
|
|
171
171
|
}
|
|
172
172
|
// src/client/feedbackHandlers.ts
|
|
173
|
-
function
|
|
173
|
+
function ie(e) {
|
|
174
174
|
let { client: t, getConversationId: n } = e, r = () => {
|
|
175
175
|
let e = n();
|
|
176
176
|
if (!e) throw Error("no conversation id");
|
|
@@ -197,15 +197,15 @@ function ae(e) {
|
|
|
197
197
|
};
|
|
198
198
|
}
|
|
199
199
|
// src/logic/conversationStorage.ts
|
|
200
|
-
var
|
|
201
|
-
function
|
|
200
|
+
var ae = "baileyai-chat-ui:conversation";
|
|
201
|
+
function oe() {
|
|
202
202
|
return {
|
|
203
203
|
get: (e) => window.sessionStorage.getItem(e),
|
|
204
204
|
set: (e, t) => window.sessionStorage.setItem(e, t),
|
|
205
205
|
remove: (e) => window.sessionStorage.removeItem(e)
|
|
206
206
|
};
|
|
207
207
|
}
|
|
208
|
-
function
|
|
208
|
+
function se() {
|
|
209
209
|
let e = /* @__PURE__ */ new Map();
|
|
210
210
|
return {
|
|
211
211
|
get: (t) => e.get(t) ?? null,
|
|
@@ -214,12 +214,12 @@ function ce() {
|
|
|
214
214
|
};
|
|
215
215
|
}
|
|
216
216
|
// src/logic/useBaileyChat.ts
|
|
217
|
-
var
|
|
217
|
+
var ce = 200, le = 100, ue = [503, 405], de = 15e4, fe = "bailey", pe = () => typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : `bailey-${Date.now()}-${Math.random().toString(36).slice(2)}`, me = (e, t, n, r) => {
|
|
218
218
|
if (t === 401 || t === 403) return `${e} isn't reachable with your current login.`;
|
|
219
219
|
let i = `${e} request failed (status ${t ?? "network error"}).`, a = (r || n || "").trim();
|
|
220
|
-
return a ? `${i} ${a.length >
|
|
220
|
+
return a ? `${i} ${a.length > ce ? `${a.slice(0, ce)}…` : a}` : i;
|
|
221
221
|
};
|
|
222
|
-
function
|
|
222
|
+
function z(e, t, n) {
|
|
223
223
|
if (e) try {
|
|
224
224
|
return e.get(t) || void 0;
|
|
225
225
|
} catch (e) {
|
|
@@ -227,10 +227,10 @@ function B(e, t, n) {
|
|
|
227
227
|
return;
|
|
228
228
|
}
|
|
229
229
|
}
|
|
230
|
-
function
|
|
230
|
+
function he(e, t) {
|
|
231
231
|
t.signal.aborted || typeof e != "string" || (t.historyStatus = e);
|
|
232
232
|
}
|
|
233
|
-
function
|
|
233
|
+
function B(e, t, n, r) {
|
|
234
234
|
try {
|
|
235
235
|
e?.set(t, n);
|
|
236
236
|
} catch (e) {
|
|
@@ -247,28 +247,28 @@ function ge(e, t, n) {
|
|
|
247
247
|
var _e = (e, t) => t ? `${e}:${t}` : e;
|
|
248
248
|
function ve(e) {
|
|
249
249
|
let { seed: t, sub: n, storage: r, key: i, report: a } = e;
|
|
250
|
-
if (!n) return t ||
|
|
251
|
-
if (t &&
|
|
250
|
+
if (!n) return t || z(r, i, a);
|
|
251
|
+
if (t && R({
|
|
252
252
|
conversationId: t,
|
|
253
253
|
sub: n
|
|
254
254
|
})) return t;
|
|
255
|
-
let o =
|
|
255
|
+
let o = z(r, i, a);
|
|
256
256
|
if (o) {
|
|
257
|
-
if (
|
|
257
|
+
if (R({
|
|
258
258
|
conversationId: o,
|
|
259
259
|
sub: n
|
|
260
260
|
})) return o;
|
|
261
261
|
ge(r, i, a);
|
|
262
262
|
}
|
|
263
263
|
}
|
|
264
|
-
var ye = ({ transport: e, model: t, instructions: n, assistantName: r =
|
|
265
|
-
let [
|
|
264
|
+
var ye = ({ transport: e, model: t, instructions: n, assistantName: r = fe, tools: i = [], toolChoice: o, firstUserMessagePrefix: c, onAssistantMessageComplete: l, idleTimeoutMs: p = de, client: m, conversationId: h, sub: g, storage: _, storageKey: v = ae, sendFullTranscript: y = !1, onStorageError: b, onContextLoss: x }) => {
|
|
265
|
+
let [ee, S] = f([]), [C, w] = f([]), [T, E] = f(null), [D, k] = f("idle"), [ne, M] = f(null), N = g !== void 0 && g.trim() === "", P = N ? void 0 : g?.trim() || void 0, F = u(() => oe(), []), I = N ? null : _ === void 0 ? F : _ || null, se = d(b), ce = d(x);
|
|
266
266
|
s(() => {
|
|
267
|
-
|
|
267
|
+
se.current = b, ce.current = x;
|
|
268
268
|
}, [b, x]);
|
|
269
|
-
let
|
|
269
|
+
let z = a((e, t) => {
|
|
270
270
|
try {
|
|
271
|
-
|
|
271
|
+
se.current?.(e, t);
|
|
272
272
|
} catch {}
|
|
273
273
|
}, []), ye = (e) => ve({
|
|
274
274
|
seed: h,
|
|
@@ -285,22 +285,22 @@ var ye = ({ transport: e, model: t, instructions: n, assistantName: r = z, tools
|
|
|
285
285
|
})),
|
|
286
286
|
errors: e
|
|
287
287
|
};
|
|
288
|
-
}), [
|
|
289
|
-
|
|
290
|
-
}, [
|
|
288
|
+
}), [xe, V] = f(be.id), [Se, Ce] = f(be.errors.length > 0), H = a((e, t) => {
|
|
289
|
+
Ce(!0), z(e, t);
|
|
290
|
+
}, [z]);
|
|
291
291
|
s(() => {
|
|
292
|
-
be.errors.forEach(({ error: e, operation: t }) =>
|
|
293
|
-
}, [be,
|
|
294
|
-
N &&
|
|
295
|
-
}, [N,
|
|
296
|
-
let
|
|
292
|
+
be.errors.forEach(({ error: e, operation: t }) => z(e, t));
|
|
293
|
+
}, [be, z]), s(() => {
|
|
294
|
+
N && z(/* @__PURE__ */ Error("sub is blank"), "key");
|
|
295
|
+
}, [N, z]);
|
|
296
|
+
let U = d(xe), W = d({
|
|
297
297
|
storage: I,
|
|
298
298
|
key: _e(v, P),
|
|
299
299
|
sub: P,
|
|
300
300
|
sendFullTranscript: y
|
|
301
301
|
});
|
|
302
302
|
s(() => {
|
|
303
|
-
|
|
303
|
+
W.current = {
|
|
304
304
|
storage: I,
|
|
305
305
|
key: _e(v, P),
|
|
306
306
|
sub: P,
|
|
@@ -312,54 +312,54 @@ var ye = ({ transport: e, model: t, instructions: n, assistantName: r = z, tools
|
|
|
312
312
|
P,
|
|
313
313
|
y
|
|
314
314
|
]);
|
|
315
|
-
let
|
|
316
|
-
|
|
317
|
-
}, []),
|
|
315
|
+
let we = _ === !1 ? "off" : Se || N ? "degraded" : "ok", [Te, Ee] = f(!1), [De, Oe] = f("idle"), [ke, Ae] = f(!1), G = d(0), K = d(null), q = d(null), je = d(!1), J = a(() => {
|
|
316
|
+
G.current += 1, K.current?.abort(), K.current = null, q.current = null, je.current = !1, Ae(!1), Oe("idle");
|
|
317
|
+
}, []), Me = d(m);
|
|
318
318
|
s(() => {
|
|
319
|
-
|
|
320
|
-
}, [m]), s(() => () =>
|
|
321
|
-
let
|
|
319
|
+
Me.current = m;
|
|
320
|
+
}, [m]), s(() => () => K.current?.abort(), []);
|
|
321
|
+
let Ne = d(null), Y = d(""), X = d(0), Pe = d([]);
|
|
322
322
|
s(() => {
|
|
323
|
-
|
|
324
|
-
}, [
|
|
325
|
-
let
|
|
326
|
-
|
|
323
|
+
Pe.current = ee;
|
|
324
|
+
}, [ee]);
|
|
325
|
+
let Z = d([]), Fe = d(/* @__PURE__ */ new Map()), Q = d(/* @__PURE__ */ new Map()), $ = d(null), Ie = a(() => {
|
|
326
|
+
$.current !== null && (clearTimeout($.current), $.current = null);
|
|
327
327
|
}, []), Le = a((e) => {
|
|
328
|
-
Ie(),
|
|
328
|
+
Ie(), $.current = setTimeout(() => {
|
|
329
329
|
e.abort(new DOMException("The assistant took too long to respond. Please try again.", "TimeoutError"));
|
|
330
330
|
}, p);
|
|
331
331
|
}, [Ie, p]);
|
|
332
332
|
s(() => () => {
|
|
333
|
-
|
|
333
|
+
Ne.current?.abort(), Ie();
|
|
334
334
|
}, [Ie]);
|
|
335
335
|
let Re = a(({ reportedId: e, source: t, turn: n }) => {
|
|
336
336
|
if (n.signal.aborted || typeof e != "string" || !e) return;
|
|
337
337
|
if (t === "event") n.reportedId = e, n.reportedFromEvent = !0;
|
|
338
338
|
else if (!n.reportedFromEvent) n.reportedId = e;
|
|
339
339
|
else return;
|
|
340
|
-
if (n.heldId || e ===
|
|
341
|
-
let { sub: r, storage: i, key: a } =
|
|
342
|
-
(!r ||
|
|
340
|
+
if (n.heldId || e === U.current) return;
|
|
341
|
+
let { sub: r, storage: i, key: a } = W.current;
|
|
342
|
+
(!r || R({
|
|
343
343
|
conversationId: e,
|
|
344
344
|
sub: r
|
|
345
|
-
})) && (
|
|
346
|
-
}, [
|
|
345
|
+
})) && (U.current = e, V(e), B(i, a, e, H));
|
|
346
|
+
}, [H]), ze = a((e, t, n, r) => {
|
|
347
347
|
let i = (e) => {
|
|
348
348
|
n.push(e), w((t) => [...t, e]);
|
|
349
349
|
};
|
|
350
350
|
if (t.type === "response.output_text.delta") {
|
|
351
351
|
if (!t.delta) return !1;
|
|
352
|
-
let n =
|
|
352
|
+
let n = Fe.current.get(e) ?? {
|
|
353
353
|
raw: "",
|
|
354
354
|
emittedCount: 0
|
|
355
355
|
};
|
|
356
356
|
n.raw += t.delta;
|
|
357
357
|
let { cleanedText: r, matches: a } = O(n.raw), o = r.trim(), s = a.slice(n.emittedCount);
|
|
358
|
-
if (n.emittedCount = a.length,
|
|
358
|
+
if (n.emittedCount = a.length, Fe.current.set(e, n), Q.current.set(e, o), S((t) => t.map((t) => t.id === e ? {
|
|
359
359
|
...t,
|
|
360
360
|
content: o
|
|
361
361
|
} : t)), s.length > 0) {
|
|
362
|
-
let e = Date.now(), t =
|
|
362
|
+
let e = Date.now(), t = X.current;
|
|
363
363
|
s.forEach((n) => i({
|
|
364
364
|
kind: "pseudo_tool_call",
|
|
365
365
|
name: n.name,
|
|
@@ -372,7 +372,7 @@ var ye = ({ transport: e, model: t, instructions: n, assistantName: r = z, tools
|
|
|
372
372
|
}
|
|
373
373
|
if (t.type === "response.output_item.added" || t.type === "response.output_item.done") {
|
|
374
374
|
let n = t.item;
|
|
375
|
-
if (n.type === "output_image") return n.image_url &&
|
|
375
|
+
if (n.type === "output_image") return n.image_url && S((t) => t.map((t) => t.id === e ? {
|
|
376
376
|
...t,
|
|
377
377
|
parts: [...t.parts ?? [], {
|
|
378
378
|
type: "image",
|
|
@@ -380,7 +380,7 @@ var ye = ({ transport: e, model: t, instructions: n, assistantName: r = z, tools
|
|
|
380
380
|
}]
|
|
381
381
|
} : t)), !0;
|
|
382
382
|
if (n.type === "function_call" || n.type === "mcp_call") {
|
|
383
|
-
let e = Date.now(), r =
|
|
383
|
+
let e = Date.now(), r = X.current, a = n.name || "unknown_tool";
|
|
384
384
|
return i(t.type === "response.output_item.added" ? {
|
|
385
385
|
kind: "tool_start",
|
|
386
386
|
name: a,
|
|
@@ -404,7 +404,7 @@ var ye = ({ transport: e, model: t, instructions: n, assistantName: r = z, tools
|
|
|
404
404
|
}), !0;
|
|
405
405
|
}
|
|
406
406
|
if (n.type === "llm_call") {
|
|
407
|
-
let e = Date.now(), r =
|
|
407
|
+
let e = Date.now(), r = X.current;
|
|
408
408
|
return i(t.type === "response.output_item.added" ? {
|
|
409
409
|
kind: "llm_call_start",
|
|
410
410
|
request: n.request ?? [],
|
|
@@ -424,29 +424,29 @@ var ye = ({ transport: e, model: t, instructions: n, assistantName: r = z, tools
|
|
|
424
424
|
status: t.status,
|
|
425
425
|
message: t.message,
|
|
426
426
|
at: Date.now(),
|
|
427
|
-
turnSentAt:
|
|
427
|
+
turnSentAt: X.current
|
|
428
428
|
}), !0;
|
|
429
429
|
if (t.type === "response.output_text.done") return !1;
|
|
430
430
|
if (t.type === "response.created") return Re({
|
|
431
431
|
reportedId: t.response?.conversation?.id,
|
|
432
432
|
source: "event",
|
|
433
433
|
turn: r
|
|
434
|
-
}),
|
|
434
|
+
}), he(t.response?.conversation?.history_status, r), !1;
|
|
435
435
|
if (t.type === "response.completed") {
|
|
436
436
|
Re({
|
|
437
437
|
reportedId: t.response?.conversation?.id,
|
|
438
438
|
source: "event",
|
|
439
439
|
turn: r
|
|
440
|
-
}),
|
|
440
|
+
}), he(t.response?.conversation?.history_status, r);
|
|
441
441
|
let n = typeof t.message_id == "string" && t.message_id ? t.message_id : void 0;
|
|
442
|
-
n &&
|
|
442
|
+
n && S((t) => t.map((t) => t.id === e ? {
|
|
443
443
|
...t,
|
|
444
444
|
serverMessageId: n
|
|
445
445
|
} : t));
|
|
446
|
-
let i =
|
|
446
|
+
let i = Fe.current.get(e);
|
|
447
447
|
if (i) {
|
|
448
448
|
let { cleanedText: t } = O(i.raw, { hideOpenBlock: !1 }), n = t.trim();
|
|
449
|
-
n !==
|
|
449
|
+
n !== Q.current.get(e) && (Q.current.set(e, n), S((t) => t.map((t) => t.id === e ? {
|
|
450
450
|
...t,
|
|
451
451
|
content: n
|
|
452
452
|
} : t)));
|
|
@@ -457,7 +457,7 @@ var ye = ({ transport: e, model: t, instructions: n, assistantName: r = z, tools
|
|
|
457
457
|
kind: "info",
|
|
458
458
|
message: t.message,
|
|
459
459
|
at: Date.now(),
|
|
460
|
-
turnSentAt:
|
|
460
|
+
turnSentAt: X.current
|
|
461
461
|
}), !0;
|
|
462
462
|
if (t.type === "mcp_app") {
|
|
463
463
|
let n = t.resourceUri;
|
|
@@ -466,10 +466,10 @@ var ye = ({ transport: e, model: t, instructions: n, assistantName: r = z, tools
|
|
|
466
466
|
eventType: t.type,
|
|
467
467
|
raw: JSON.stringify(t),
|
|
468
468
|
at: Date.now(),
|
|
469
|
-
turnSentAt:
|
|
469
|
+
turnSentAt: X.current
|
|
470
470
|
}), !0;
|
|
471
471
|
let { html: r, title: a, csp: o, permissions: s, prefersBorder: c, displayMode: l } = t;
|
|
472
|
-
return
|
|
472
|
+
return S((t) => t.map((t) => t.id === e ? {
|
|
473
473
|
...t,
|
|
474
474
|
parts: [...t.parts ?? [], {
|
|
475
475
|
type: "mcp_app",
|
|
@@ -488,20 +488,20 @@ var ye = ({ transport: e, model: t, instructions: n, assistantName: r = z, tools
|
|
|
488
488
|
eventType: t.type,
|
|
489
489
|
raw: JSON.stringify(t),
|
|
490
490
|
at: Date.now(),
|
|
491
|
-
turnSentAt:
|
|
491
|
+
turnSentAt: X.current
|
|
492
492
|
}), !0;
|
|
493
493
|
}, [Re]), Be = a(async (a) => {
|
|
494
|
-
k("streaming"), M(null),
|
|
494
|
+
k("streaming"), M(null), Ee(!1);
|
|
495
495
|
let s = Date.now();
|
|
496
|
-
|
|
497
|
-
let u =
|
|
496
|
+
X.current = s;
|
|
497
|
+
let u = pe(), d = {
|
|
498
498
|
id: u,
|
|
499
499
|
role: "assistant",
|
|
500
500
|
content: "",
|
|
501
501
|
streaming: !0,
|
|
502
502
|
createdAt: s
|
|
503
503
|
};
|
|
504
|
-
|
|
504
|
+
S((e) => [...e, d]), Z.current = [...a, d];
|
|
505
505
|
let f = a.findIndex((e) => e.role === "user" && !e.hidden), p = a.map((e, t) => t === f && c ? {
|
|
506
506
|
role: e.role,
|
|
507
507
|
content: `${c}${e.content}`,
|
|
@@ -512,7 +512,7 @@ var ye = ({ transport: e, model: t, instructions: n, assistantName: r = z, tools
|
|
|
512
512
|
content: e.content,
|
|
513
513
|
hidden: e.hidden,
|
|
514
514
|
titleHint: e.titleHint
|
|
515
|
-
}), { sendFullTranscript: m } =
|
|
515
|
+
}), { sendFullTranscript: m } = W.current, h = m ? void 0 : U.current, g = h ? p.slice(-1) : p;
|
|
516
516
|
E({
|
|
517
517
|
model: t,
|
|
518
518
|
systemPrompt: n,
|
|
@@ -528,11 +528,11 @@ var ye = ({ transport: e, model: t, instructions: n, assistantName: r = z, tools
|
|
|
528
528
|
}
|
|
529
529
|
});
|
|
530
530
|
let _ = new AbortController();
|
|
531
|
-
|
|
531
|
+
Ne.current = _, Le(_);
|
|
532
532
|
let v = {
|
|
533
533
|
signal: _.signal,
|
|
534
534
|
heldId: h
|
|
535
|
-
}, y = "", b = null, x = !1,
|
|
535
|
+
}, y = "", b = null, x = !1, ee = !1, C = !1, T = [], D = (e, t) => {
|
|
536
536
|
k("error"), M(e);
|
|
537
537
|
let n = {
|
|
538
538
|
kind: "error",
|
|
@@ -553,8 +553,8 @@ var ye = ({ transport: e, model: t, instructions: n, assistantName: r = z, tools
|
|
|
553
553
|
turnSentAt: s
|
|
554
554
|
};
|
|
555
555
|
T.push(t), w((e) => [...e, t]);
|
|
556
|
-
} else e.type === "response.output_text.delta" && e.delta && (
|
|
557
|
-
}), t && (x = !0,
|
|
556
|
+
} else e.type === "response.output_text.delta" && e.delta && (C = !0), ze(u, e, T, v) && (ee = !0);
|
|
557
|
+
}), t && (x = !0, S((e) => e.map((e) => e.id === u ? {
|
|
558
558
|
...e,
|
|
559
559
|
streaming: !1
|
|
560
560
|
} : e)));
|
|
@@ -594,7 +594,7 @@ var ye = ({ transport: e, model: t, instructions: n, assistantName: r = z, tools
|
|
|
594
594
|
} : t);
|
|
595
595
|
},
|
|
596
596
|
onMessageId: (e) => {
|
|
597
|
-
typeof e == "string" && e &&
|
|
597
|
+
typeof e == "string" && e && S((t) => t.map((t) => t.id === u ? {
|
|
598
598
|
...t,
|
|
599
599
|
serverMessageId: e
|
|
600
600
|
} : t));
|
|
@@ -617,7 +617,7 @@ var ye = ({ transport: e, model: t, instructions: n, assistantName: r = z, tools
|
|
|
617
617
|
return;
|
|
618
618
|
}
|
|
619
619
|
if (a === void 0 || a >= 400) {
|
|
620
|
-
D(
|
|
620
|
+
D(me(r, a, c, d), {
|
|
621
621
|
httpStatus: a,
|
|
622
622
|
rawBody: c || void 0
|
|
623
623
|
});
|
|
@@ -625,25 +625,25 @@ var ye = ({ transport: e, model: t, instructions: n, assistantName: r = z, tools
|
|
|
625
625
|
}
|
|
626
626
|
let m = v.reportedId, w = m !== h, j = v.historyStatus === "failed" || v.historyStatus === "empty";
|
|
627
627
|
if (h && !v.signal.aborted && (w || j)) {
|
|
628
|
-
|
|
628
|
+
U.current = void 0, V(void 0), ge(W.current.storage, W.current.key, H), J(), Ee(!0);
|
|
629
629
|
try {
|
|
630
|
-
|
|
630
|
+
ce.current?.({
|
|
631
631
|
sentId: h,
|
|
632
632
|
...m ? { reportedId: m } : {},
|
|
633
633
|
reason: w ? "id" : "history"
|
|
634
634
|
});
|
|
635
635
|
} catch {}
|
|
636
636
|
}
|
|
637
|
-
if (!
|
|
637
|
+
if (!ee) {
|
|
638
638
|
D(`${r} returned an empty response.`);
|
|
639
639
|
return;
|
|
640
640
|
}
|
|
641
|
-
if (!
|
|
641
|
+
if (!C) {
|
|
642
642
|
D(`${r} ran some tools but didn't return an answer. Try asking again.`);
|
|
643
643
|
return;
|
|
644
644
|
}
|
|
645
645
|
k("idle");
|
|
646
|
-
let te =
|
|
646
|
+
let te = Q.current.get(u) ?? "";
|
|
647
647
|
E((e) => e && e.sentAt === s ? {
|
|
648
648
|
...e,
|
|
649
649
|
response: { content: te }
|
|
@@ -666,13 +666,13 @@ var ye = ({ transport: e, model: t, instructions: n, assistantName: r = z, tools
|
|
|
666
666
|
D(t instanceof j ? te(t, r) : t?.message || `${r} request failed.`);
|
|
667
667
|
} finally {
|
|
668
668
|
Ie();
|
|
669
|
-
let e =
|
|
670
|
-
|
|
669
|
+
let e = Q.current.get(u) ?? "";
|
|
670
|
+
Fe.current.delete(u), Q.current.delete(u);
|
|
671
671
|
let t = T.some((e) => e.kind === "tool_start" || e.kind === "tool_end");
|
|
672
|
-
|
|
672
|
+
S((e) => e.flatMap((e) => e.id === u ? e.content || t ? [{
|
|
673
673
|
...e,
|
|
674
674
|
streaming: !1
|
|
675
|
-
}] : [] : [e])),
|
|
675
|
+
}] : [] : [e])), Z.current = Z.current.flatMap((t) => t.id === u ? e ? [{
|
|
676
676
|
...t,
|
|
677
677
|
content: e,
|
|
678
678
|
streaming: !1
|
|
@@ -691,43 +691,43 @@ var ye = ({ transport: e, model: t, instructions: n, assistantName: r = z, tools
|
|
|
691
691
|
Re,
|
|
692
692
|
Le,
|
|
693
693
|
Ie,
|
|
694
|
-
|
|
695
|
-
|
|
694
|
+
H,
|
|
695
|
+
J
|
|
696
696
|
]), Ve = a((e) => {
|
|
697
|
-
|
|
697
|
+
Pe.current = e, S(e);
|
|
698
698
|
}, []), He = a((e) => {
|
|
699
699
|
let t = e.trim();
|
|
700
700
|
if (!t) return;
|
|
701
|
-
|
|
701
|
+
Y.current = t;
|
|
702
702
|
let n = {
|
|
703
|
-
id:
|
|
703
|
+
id: pe(),
|
|
704
704
|
role: "user",
|
|
705
705
|
content: t,
|
|
706
706
|
createdAt: Date.now()
|
|
707
|
-
}, r = [
|
|
708
|
-
|
|
707
|
+
}, r = [...Z.current, n];
|
|
708
|
+
Z.current = r, Ve([...Pe.current, n]), Be(r);
|
|
709
709
|
}, [Be, Ve]), Ue = a((e, t) => {
|
|
710
710
|
if (D === "streaming") return;
|
|
711
711
|
let n = e.trim();
|
|
712
712
|
if (!n) return;
|
|
713
|
-
|
|
713
|
+
Y.current = n;
|
|
714
714
|
let r = t?.trim(), i = {
|
|
715
|
-
id:
|
|
715
|
+
id: pe(),
|
|
716
716
|
role: "user",
|
|
717
717
|
content: n,
|
|
718
718
|
createdAt: Date.now(),
|
|
719
719
|
hidden: !0,
|
|
720
720
|
...r ? { titleHint: r } : {}
|
|
721
|
-
}, a = [
|
|
722
|
-
|
|
721
|
+
}, a = [...Z.current, i];
|
|
722
|
+
Z.current = a, Be(a);
|
|
723
723
|
}, [Be, D]), We = a(() => {
|
|
724
|
-
|
|
724
|
+
Ne.current?.abort();
|
|
725
725
|
}, []), Ge = a(() => {
|
|
726
|
-
if (D === "streaming" || !
|
|
727
|
-
let e =
|
|
726
|
+
if (D === "streaming" || !Y.current) return;
|
|
727
|
+
let e = Pe.current, t = e[e.length - 1], n = t && t.role === "assistant" ? e.slice(0, -1) : e;
|
|
728
728
|
Ve(n);
|
|
729
|
-
let r =
|
|
730
|
-
|
|
729
|
+
let r = Z.current, i = r[r.length - 1], a = i && i.role === "assistant" ? r.slice(0, -1) : r;
|
|
730
|
+
Z.current = a, Be(a);
|
|
731
731
|
}, [
|
|
732
732
|
Be,
|
|
733
733
|
Ve,
|
|
@@ -735,62 +735,62 @@ var ye = ({ transport: e, model: t, instructions: n, assistantName: r = z, tools
|
|
|
735
735
|
]), Ke = a(() => w([]), []), qe = a(() => {
|
|
736
736
|
M(null), k((e) => e === "error" ? "idle" : e);
|
|
737
737
|
}, []), Je = a(() => {
|
|
738
|
-
|
|
739
|
-
}, [
|
|
740
|
-
Je(),
|
|
741
|
-
}, [Je,
|
|
738
|
+
Ne.current?.abort(), J(), Ee(!1), Ve([]), Z.current = [], w([]), E(null), k("idle"), M(null), Y.current = "";
|
|
739
|
+
}, [J, Ve]), Ye = a(() => {
|
|
740
|
+
Je(), U.current = void 0, V(void 0), ge(W.current.storage, W.current.key, H);
|
|
741
|
+
}, [Je, H]), Xe = d(P);
|
|
742
742
|
s(() => {
|
|
743
743
|
let e = Xe.current;
|
|
744
744
|
if (e === P) return;
|
|
745
745
|
Xe.current = P, e !== void 0 && Je();
|
|
746
|
-
let t = ye(
|
|
747
|
-
|
|
746
|
+
let t = ye(H);
|
|
747
|
+
U.current = t, V(t);
|
|
748
748
|
}, [P]);
|
|
749
749
|
let Ze = a((e) => {
|
|
750
|
-
|
|
750
|
+
Ne.current?.abort();
|
|
751
751
|
let t = e.filter((e) => e.role === "user" || e.role === "assistant").map((e) => ({
|
|
752
752
|
...e,
|
|
753
753
|
streaming: !1
|
|
754
754
|
}));
|
|
755
|
-
Ve(t.filter((e) => !e.hidden)),
|
|
755
|
+
Ve(t.filter((e) => !e.hidden)), Z.current = t, w([]), E(null), k("idle"), M(null), Y.current = "";
|
|
756
756
|
}, [Ve]), Qe = a((e) => {
|
|
757
|
-
|
|
758
|
-
}, [
|
|
759
|
-
|
|
760
|
-
}, [
|
|
757
|
+
J(), Ze(e);
|
|
758
|
+
}, [J, Ze]), $e = a((e) => {
|
|
759
|
+
U.current = e, V(e), B(W.current.storage, W.current.key, e, H), Ee(!1);
|
|
760
|
+
}, [H]), et = a((e) => {
|
|
761
761
|
let t = e.hasMoreBefore && e.nextBeforeAbsoluteIndex !== null;
|
|
762
|
-
|
|
762
|
+
q.current = t ? e.nextBeforeAbsoluteIndex : null, Ae(t);
|
|
763
763
|
}, []), tt = a(async ({ conversationId: e }) => {
|
|
764
|
-
let t =
|
|
764
|
+
let t = Me.current, { sub: n } = W.current, r = !!e && (!n || R({
|
|
765
765
|
conversationId: e,
|
|
766
766
|
sub: n
|
|
767
767
|
}));
|
|
768
|
-
if (!t || !r) throw
|
|
769
|
-
|
|
770
|
-
let i =
|
|
771
|
-
|
|
768
|
+
if (!t || !r) throw Oe("error"), Error(t ? "invalid conversation id" : "no client");
|
|
769
|
+
Ne.current?.abort(), J();
|
|
770
|
+
let i = G.current, a = new AbortController();
|
|
771
|
+
K.current = a, Oe("loading");
|
|
772
772
|
try {
|
|
773
773
|
let n = await t.getConversation({
|
|
774
774
|
conversationId: e,
|
|
775
775
|
limit: le,
|
|
776
776
|
signal: a.signal
|
|
777
777
|
});
|
|
778
|
-
if (i !==
|
|
779
|
-
Ze(
|
|
778
|
+
if (i !== G.current) return;
|
|
779
|
+
Ze(re({ messages: n.messages })), $e(e), et(n), Oe("idle");
|
|
780
780
|
} catch (e) {
|
|
781
|
-
if (i !==
|
|
782
|
-
throw
|
|
781
|
+
if (i !== G.current) return;
|
|
782
|
+
throw Oe("error"), e;
|
|
783
783
|
}
|
|
784
784
|
}, [
|
|
785
785
|
et,
|
|
786
|
-
|
|
786
|
+
J,
|
|
787
787
|
$e,
|
|
788
788
|
Ze
|
|
789
789
|
]), nt = a(async () => {
|
|
790
|
-
let e =
|
|
791
|
-
if (!e || !t || n === null ||
|
|
792
|
-
let r =
|
|
793
|
-
|
|
790
|
+
let e = Me.current, t = U.current, n = q.current;
|
|
791
|
+
if (!e || !t || n === null || je.current) return;
|
|
792
|
+
let r = G.current, i = new AbortController();
|
|
793
|
+
K.current = i, je.current = !0, Oe("loading");
|
|
794
794
|
try {
|
|
795
795
|
let a = await e.getConversation({
|
|
796
796
|
conversationId: t,
|
|
@@ -798,31 +798,31 @@ var ye = ({ transport: e, model: t, instructions: n, assistantName: r = z, tools
|
|
|
798
798
|
beforeAbsoluteIndex: n,
|
|
799
799
|
signal: i.signal
|
|
800
800
|
});
|
|
801
|
-
if (r !==
|
|
802
|
-
let o =
|
|
803
|
-
|
|
804
|
-
current:
|
|
801
|
+
if (r !== G.current) return;
|
|
802
|
+
let o = re({ messages: a.messages });
|
|
803
|
+
Z.current = L({
|
|
804
|
+
current: Z.current,
|
|
805
805
|
earlier: o
|
|
806
|
-
}),
|
|
807
|
-
let t =
|
|
806
|
+
}), S((e) => {
|
|
807
|
+
let t = L({
|
|
808
808
|
current: e,
|
|
809
809
|
earlier: o
|
|
810
810
|
});
|
|
811
|
-
return
|
|
812
|
-
}), et(a),
|
|
811
|
+
return Pe.current = t, t;
|
|
812
|
+
}), et(a), Oe("idle");
|
|
813
813
|
} catch (e) {
|
|
814
|
-
if (r !==
|
|
815
|
-
throw
|
|
814
|
+
if (r !== G.current) return;
|
|
815
|
+
throw Oe("error"), e;
|
|
816
816
|
} finally {
|
|
817
|
-
r ===
|
|
817
|
+
r === G.current && (je.current = !1);
|
|
818
818
|
}
|
|
819
819
|
}, [et]), [rt, it] = f();
|
|
820
820
|
return {
|
|
821
|
-
conversationId:
|
|
822
|
-
persistence:
|
|
823
|
-
contextLost:
|
|
824
|
-
messages:
|
|
825
|
-
traceEvents:
|
|
821
|
+
conversationId: xe,
|
|
822
|
+
persistence: we,
|
|
823
|
+
contextLost: Te,
|
|
824
|
+
messages: ee,
|
|
825
|
+
traceEvents: C,
|
|
826
826
|
lastRequest: T,
|
|
827
827
|
status: D,
|
|
828
828
|
error: ne,
|
|
@@ -836,20 +836,20 @@ var ye = ({ transport: e, model: t, instructions: n, assistantName: r = z, tools
|
|
|
836
836
|
loadMessages: Qe,
|
|
837
837
|
loadConversation: tt,
|
|
838
838
|
loadEarlier: nt,
|
|
839
|
-
hasEarlier:
|
|
840
|
-
historyStatus:
|
|
839
|
+
hasEarlier: ke,
|
|
840
|
+
historyStatus: De,
|
|
841
841
|
feedback: u(() => {
|
|
842
842
|
if (!m || rt === m) return;
|
|
843
|
-
let e =
|
|
843
|
+
let e = ie({
|
|
844
844
|
client: m,
|
|
845
|
-
getConversationId: () =>
|
|
845
|
+
getConversationId: () => xe
|
|
846
846
|
}), t = async (e) => {
|
|
847
847
|
try {
|
|
848
848
|
await e();
|
|
849
849
|
} catch (e) {
|
|
850
850
|
throw e instanceof j && ue.includes(e.status) && it(m), e;
|
|
851
851
|
}
|
|
852
|
-
}, n = (e, t) =>
|
|
852
|
+
}, n = (e, t) => S((n) => n.map((n) => n.serverMessageId === e ? {
|
|
853
853
|
...n,
|
|
854
854
|
feedback: t
|
|
855
855
|
} : n));
|
|
@@ -869,7 +869,7 @@ var ye = ({ transport: e, model: t, instructions: n, assistantName: r = z, tools
|
|
|
869
869
|
};
|
|
870
870
|
}, [
|
|
871
871
|
m,
|
|
872
|
-
|
|
872
|
+
xe,
|
|
873
873
|
rt
|
|
874
874
|
])
|
|
875
875
|
};
|
|
@@ -877,7 +877,7 @@ var ye = ({ transport: e, model: t, instructions: n, assistantName: r = z, tools
|
|
|
877
877
|
status: 0,
|
|
878
878
|
kind: "network"
|
|
879
879
|
});
|
|
880
|
-
function
|
|
880
|
+
function xe(e) {
|
|
881
881
|
let { pageSize: t, enabled: n = !0 } = e, [r, i] = f([]), [o, c] = f(n ? "loading" : "idle"), [l, u] = f(null), [p, m] = f(null), h = d(e.client), g = d([]);
|
|
882
882
|
s(() => {
|
|
883
883
|
h.current = e.client, g.current = r;
|
|
@@ -908,7 +908,7 @@ function V(e) {
|
|
|
908
908
|
}, [n, y]);
|
|
909
909
|
let b = a(() => y("replace"), [y]), x = a(async () => {
|
|
910
910
|
_.current !== null && await y("append");
|
|
911
|
-
}, [y]),
|
|
911
|
+
}, [y]), ee = a(async ({ conversationId: e }) => {
|
|
912
912
|
let t = g.current.findIndex((t) => t.conversationId === e), n = t === -1 ? void 0 : {
|
|
913
913
|
row: g.current[t],
|
|
914
914
|
index: t
|
|
@@ -933,41 +933,41 @@ function V(e) {
|
|
|
933
933
|
hasMore: p !== null,
|
|
934
934
|
refresh: b,
|
|
935
935
|
loadMore: x,
|
|
936
|
-
remove:
|
|
936
|
+
remove: ee
|
|
937
937
|
};
|
|
938
938
|
}
|
|
939
939
|
// src/client/routes.ts
|
|
940
|
-
function
|
|
940
|
+
function V(e) {
|
|
941
941
|
return e.replace(/\/+$/, "");
|
|
942
942
|
}
|
|
943
|
-
function
|
|
943
|
+
function Se(e, t) {
|
|
944
944
|
let n = new URLSearchParams();
|
|
945
945
|
for (let [e, r] of Object.entries(t)) r !== void 0 && n.set(e, String(r));
|
|
946
946
|
let r = n.toString();
|
|
947
947
|
return r ? `${e}?${r}` : e;
|
|
948
948
|
}
|
|
949
|
-
var
|
|
949
|
+
var Ce = {
|
|
950
950
|
responses(e) {
|
|
951
|
-
return `${
|
|
951
|
+
return `${V(e)}/responses`;
|
|
952
952
|
},
|
|
953
953
|
conversations(e, t) {
|
|
954
|
-
return
|
|
954
|
+
return Se(`${V(e)}/conversations`, {
|
|
955
955
|
limit: t.limit,
|
|
956
956
|
cursor: t.cursor
|
|
957
957
|
});
|
|
958
958
|
},
|
|
959
959
|
conversation(e, t, n) {
|
|
960
|
-
return
|
|
960
|
+
return Se(`${V(e)}/conversations/${encodeURIComponent(t)}`, {
|
|
961
961
|
limit: n.limit,
|
|
962
962
|
before_absolute_index: n.beforeAbsoluteIndex
|
|
963
963
|
});
|
|
964
964
|
},
|
|
965
965
|
feedback(e, t, n) {
|
|
966
|
-
return `${
|
|
966
|
+
return `${V(e)}/conversations/${encodeURIComponent(t)}/messages/${encodeURIComponent(n)}/feedback`;
|
|
967
967
|
}
|
|
968
968
|
};
|
|
969
969
|
// src/client/createBaileyClient.ts
|
|
970
|
-
function
|
|
970
|
+
function H(e) {
|
|
971
971
|
return {
|
|
972
972
|
status: void 0,
|
|
973
973
|
text: "",
|
|
@@ -976,51 +976,51 @@ function W(e) {
|
|
|
976
976
|
...e ? { errorCause: e.cause } : {}
|
|
977
977
|
};
|
|
978
978
|
}
|
|
979
|
-
var
|
|
980
|
-
function
|
|
979
|
+
var U = "The assistant took too long to respond. Please try again.";
|
|
980
|
+
function W(e) {
|
|
981
981
|
return {
|
|
982
982
|
status: e.status,
|
|
983
983
|
text: "",
|
|
984
|
-
errorMessage:
|
|
984
|
+
errorMessage: U,
|
|
985
985
|
errorKind: "timeout",
|
|
986
986
|
errorCause: e.cause,
|
|
987
987
|
...e.status === void 0 ? {} : { interrupted: !0 }
|
|
988
988
|
};
|
|
989
989
|
}
|
|
990
|
-
var
|
|
991
|
-
function
|
|
992
|
-
let t =
|
|
990
|
+
var we = 3e4, Te = 155e3, Ee = "x-chat-id", De = "header", Oe = "body", ke = "x-request-id", Ae = "x-conversation-id", G = "x-message-id", K = (e) => e && typeof e == "object" ? e : {}, q = (e, t = "") => typeof e == "string" ? e : t, je = (e, t = 0) => typeof e == "number" ? e : t;
|
|
991
|
+
function J(e) {
|
|
992
|
+
let t = K(e);
|
|
993
993
|
return {
|
|
994
|
-
conversationId:
|
|
994
|
+
conversationId: q(t.conversation_id),
|
|
995
995
|
title: typeof t.title == "string" ? t.title : null,
|
|
996
|
-
status:
|
|
997
|
-
messageCount:
|
|
998
|
-
createdAt:
|
|
999
|
-
updatedAt:
|
|
996
|
+
status: q(t.status),
|
|
997
|
+
messageCount: je(t.message_count),
|
|
998
|
+
createdAt: q(t.created_at),
|
|
999
|
+
updatedAt: q(t.updated_at)
|
|
1000
1000
|
};
|
|
1001
1001
|
}
|
|
1002
|
-
function
|
|
1002
|
+
function Me(e) {
|
|
1003
1003
|
if (!e || typeof e != "object") return null;
|
|
1004
|
-
let t =
|
|
1004
|
+
let t = K(e);
|
|
1005
1005
|
return {
|
|
1006
|
-
rating:
|
|
1006
|
+
rating: q(t.rating),
|
|
1007
1007
|
reasonCodes: Array.isArray(t.reason_codes) ? t.reason_codes.filter((e) => typeof e == "string") : [],
|
|
1008
1008
|
comment: typeof t.comment == "string" ? t.comment : null,
|
|
1009
1009
|
...typeof t.updated_at == "string" ? { updatedAt: t.updated_at } : {}
|
|
1010
1010
|
};
|
|
1011
1011
|
}
|
|
1012
|
-
function
|
|
1013
|
-
let t =
|
|
1012
|
+
function Ne(e) {
|
|
1013
|
+
let t = K(e);
|
|
1014
1014
|
return {
|
|
1015
|
-
messageId:
|
|
1016
|
-
role:
|
|
1017
|
-
content:
|
|
1015
|
+
messageId: q(t.message_id),
|
|
1016
|
+
role: q(t.role),
|
|
1017
|
+
content: q(t.content),
|
|
1018
1018
|
hidden: t.hidden === !0,
|
|
1019
|
-
createdAt:
|
|
1020
|
-
feedback:
|
|
1019
|
+
createdAt: q(t.created_at),
|
|
1020
|
+
feedback: Me(t.feedback)
|
|
1021
1021
|
};
|
|
1022
1022
|
}
|
|
1023
|
-
function
|
|
1023
|
+
function Y(e) {
|
|
1024
1024
|
let t = new AbortController(), n = !1, r = setTimeout(() => {
|
|
1025
1025
|
n = !0, t.abort();
|
|
1026
1026
|
}, e.timeoutMs), i = () => t.abort(e.caller?.reason);
|
|
@@ -1032,7 +1032,7 @@ function je(e) {
|
|
|
1032
1032
|
}
|
|
1033
1033
|
};
|
|
1034
1034
|
}
|
|
1035
|
-
function
|
|
1035
|
+
function X(e) {
|
|
1036
1036
|
return e.timedOut() ? new j({
|
|
1037
1037
|
status: 0,
|
|
1038
1038
|
kind: "timeout",
|
|
@@ -1042,9 +1042,9 @@ function Q(e) {
|
|
|
1042
1042
|
kind: "aborted"
|
|
1043
1043
|
});
|
|
1044
1044
|
}
|
|
1045
|
-
function
|
|
1046
|
-
let { baseUrl: t, getHeaders: n, onAuthError: r, refreshAuth: i } = e, a = e.requestTimeoutMs ??
|
|
1047
|
-
if (s !==
|
|
1045
|
+
function Pe(e) {
|
|
1046
|
+
let { baseUrl: t, getHeaders: n, onAuthError: r, refreshAuth: i } = e, a = e.requestTimeoutMs ?? we, o = e.idleTimeoutMs ?? Te, s = e.conversationVia ?? De;
|
|
1047
|
+
if (s !== De && s !== Oe) throw TypeError("createBaileyClient: conversationVia must be 'header' or 'body'");
|
|
1048
1048
|
let c = e.fetch ?? ((e, t) => globalThis.fetch(e, t));
|
|
1049
1049
|
function l(t) {
|
|
1050
1050
|
try {
|
|
@@ -1064,7 +1064,7 @@ function Me(e) {
|
|
|
1064
1064
|
return e.body?.cancel().catch(() => l("cancel-response-body")), !0;
|
|
1065
1065
|
}
|
|
1066
1066
|
async function f(e) {
|
|
1067
|
-
let t =
|
|
1067
|
+
let t = Y({
|
|
1068
1068
|
caller: e.signal,
|
|
1069
1069
|
timeoutMs: a
|
|
1070
1070
|
});
|
|
@@ -1082,7 +1082,7 @@ function Me(e) {
|
|
|
1082
1082
|
kind: "network"
|
|
1083
1083
|
});
|
|
1084
1084
|
}
|
|
1085
|
-
if (t.signal.aborted) throw
|
|
1085
|
+
if (t.signal.aborted) throw X(t);
|
|
1086
1086
|
e.body !== void 0 && (r["Content-Type"] = "application/json");
|
|
1087
1087
|
try {
|
|
1088
1088
|
return await c(e.url, {
|
|
@@ -1092,7 +1092,7 @@ function Me(e) {
|
|
|
1092
1092
|
signal: t.signal
|
|
1093
1093
|
});
|
|
1094
1094
|
} catch (e) {
|
|
1095
|
-
throw t.signal.aborted ?
|
|
1095
|
+
throw t.signal.aborted ? X(t) : new j({
|
|
1096
1096
|
status: 0,
|
|
1097
1097
|
kind: "network",
|
|
1098
1098
|
cause: e
|
|
@@ -1119,7 +1119,7 @@ function Me(e) {
|
|
|
1119
1119
|
return t;
|
|
1120
1120
|
} catch (n) {
|
|
1121
1121
|
if (n instanceof j) throw n;
|
|
1122
|
-
if (t.timedOut() || t.signal.aborted) throw
|
|
1122
|
+
if (t.timedOut() || t.signal.aborted) throw X(t);
|
|
1123
1123
|
if (e.requireJsonBody) throw new j({
|
|
1124
1124
|
status: i.status,
|
|
1125
1125
|
kind: "invalid-response"
|
|
@@ -1138,10 +1138,10 @@ function Me(e) {
|
|
|
1138
1138
|
e.signal.aborted ? i() : e.signal.addEventListener("abort", i, { once: !0 });
|
|
1139
1139
|
let a, f, p = () => {
|
|
1140
1140
|
clearTimeout(a), a = setTimeout(() => {
|
|
1141
|
-
f = new DOMException(
|
|
1141
|
+
f = new DOMException(U, "TimeoutError"), r.abort(f);
|
|
1142
1142
|
}, o);
|
|
1143
1143
|
}, m = (t) => {
|
|
1144
|
-
if (f && !e.signal.aborted) return
|
|
1144
|
+
if (f && !e.signal.aborted) return W({
|
|
1145
1145
|
cause: f,
|
|
1146
1146
|
status: t
|
|
1147
1147
|
});
|
|
@@ -1162,7 +1162,7 @@ function Me(e) {
|
|
|
1162
1162
|
stream: !0,
|
|
1163
1163
|
...Object.keys(a).length > 0 ? { metadata: a } : {}
|
|
1164
1164
|
};
|
|
1165
|
-
e.conversationId && s ===
|
|
1165
|
+
e.conversationId && s === Oe && (o.conversation = e.conversationId), e.tools.length > 0 && (o.tools = e.tools), e.toolChoice && (o.tool_choice = e.toolChoice);
|
|
1166
1166
|
let f;
|
|
1167
1167
|
for (let i = !1;; i = !0) {
|
|
1168
1168
|
let a;
|
|
@@ -1172,25 +1172,25 @@ function Me(e) {
|
|
|
1172
1172
|
...await n()
|
|
1173
1173
|
};
|
|
1174
1174
|
} catch {
|
|
1175
|
-
return
|
|
1175
|
+
return H();
|
|
1176
1176
|
}
|
|
1177
1177
|
if (r.signal.aborted) return m();
|
|
1178
|
-
a["Content-Type"] = "application/json", e.conversationId && s ===
|
|
1178
|
+
a["Content-Type"] = "application/json", e.conversationId && s === De && (a[Ee] = e.conversationId);
|
|
1179
1179
|
try {
|
|
1180
|
-
f = await c(
|
|
1180
|
+
f = await c(Ce.responses(t), {
|
|
1181
1181
|
method: "POST",
|
|
1182
1182
|
headers: a,
|
|
1183
1183
|
body: JSON.stringify(o),
|
|
1184
1184
|
signal: r.signal
|
|
1185
1185
|
});
|
|
1186
1186
|
} catch (e) {
|
|
1187
|
-
return r.signal.aborted ? m() :
|
|
1187
|
+
return r.signal.aborted ? m() : H({ cause: e });
|
|
1188
1188
|
}
|
|
1189
1189
|
if (i || !await d(f)) break;
|
|
1190
1190
|
}
|
|
1191
|
-
let h = f.headers.get(
|
|
1191
|
+
let h = f.headers.get(ke);
|
|
1192
1192
|
h && e.onRequestId?.(h);
|
|
1193
|
-
let g = f.headers.get(
|
|
1193
|
+
let g = f.headers.get(G);
|
|
1194
1194
|
if (g && e.onMessageId?.(g), !f.ok) {
|
|
1195
1195
|
u(new j({
|
|
1196
1196
|
status: f.status,
|
|
@@ -1202,7 +1202,7 @@ function Me(e) {
|
|
|
1202
1202
|
text: e
|
|
1203
1203
|
};
|
|
1204
1204
|
}
|
|
1205
|
-
let _ = f.headers.get(
|
|
1205
|
+
let _ = f.headers.get(Ae);
|
|
1206
1206
|
if (_ && e.onConversationId?.(_), !f.body) return {
|
|
1207
1207
|
status: f.status,
|
|
1208
1208
|
text: ""
|
|
@@ -1239,21 +1239,21 @@ function Me(e) {
|
|
|
1239
1239
|
}
|
|
1240
1240
|
},
|
|
1241
1241
|
async listConversations(e = {}) {
|
|
1242
|
-
let n =
|
|
1242
|
+
let n = K(await f({
|
|
1243
1243
|
method: "GET",
|
|
1244
|
-
url:
|
|
1244
|
+
url: Ce.conversations(t, e),
|
|
1245
1245
|
signal: e.signal,
|
|
1246
1246
|
requireJsonBody: !0
|
|
1247
1247
|
}));
|
|
1248
1248
|
return {
|
|
1249
|
-
conversations: Array.isArray(n.conversations) ? n.conversations.map(
|
|
1249
|
+
conversations: Array.isArray(n.conversations) ? n.conversations.map(J).filter((e) => e.conversationId !== "") : [],
|
|
1250
1250
|
nextCursor: typeof n.next_cursor == "string" ? n.next_cursor : null
|
|
1251
1251
|
};
|
|
1252
1252
|
},
|
|
1253
1253
|
async getConversation(e) {
|
|
1254
|
-
let n =
|
|
1254
|
+
let n = K(await f({
|
|
1255
1255
|
method: "GET",
|
|
1256
|
-
url:
|
|
1256
|
+
url: Ce.conversation(t, e.conversationId, e),
|
|
1257
1257
|
signal: e.signal,
|
|
1258
1258
|
requireJsonBody: !0
|
|
1259
1259
|
}));
|
|
@@ -1262,8 +1262,8 @@ function Me(e) {
|
|
|
1262
1262
|
kind: "invalid-response"
|
|
1263
1263
|
});
|
|
1264
1264
|
return {
|
|
1265
|
-
conversation:
|
|
1266
|
-
messages: Array.isArray(n.messages) ? n.messages.map(
|
|
1265
|
+
conversation: J(n.conversation),
|
|
1266
|
+
messages: Array.isArray(n.messages) ? n.messages.map(Ne) : [],
|
|
1267
1267
|
hasMoreBefore: n.has_more_before === !0,
|
|
1268
1268
|
nextBeforeAbsoluteIndex: typeof n.next_before_absolute_index == "number" ? n.next_before_absolute_index : null
|
|
1269
1269
|
};
|
|
@@ -1271,14 +1271,14 @@ function Me(e) {
|
|
|
1271
1271
|
async deleteConversation(e) {
|
|
1272
1272
|
await f({
|
|
1273
1273
|
method: "DELETE",
|
|
1274
|
-
url:
|
|
1274
|
+
url: Ce.conversation(t, e.conversationId, {}),
|
|
1275
1275
|
signal: e.signal
|
|
1276
1276
|
});
|
|
1277
1277
|
},
|
|
1278
1278
|
async submitFeedback(e) {
|
|
1279
1279
|
await f({
|
|
1280
1280
|
method: "PUT",
|
|
1281
|
-
url:
|
|
1281
|
+
url: Ce.feedback(t, e.conversationId, e.messageId),
|
|
1282
1282
|
body: {
|
|
1283
1283
|
rating: e.rating,
|
|
1284
1284
|
...e.reasonCodes ? { reason_codes: e.reasonCodes } : {},
|
|
@@ -1290,21 +1290,21 @@ function Me(e) {
|
|
|
1290
1290
|
async clearFeedback(e) {
|
|
1291
1291
|
await f({
|
|
1292
1292
|
method: "DELETE",
|
|
1293
|
-
url:
|
|
1293
|
+
url: Ce.feedback(t, e.conversationId, e.messageId),
|
|
1294
1294
|
signal: e.signal
|
|
1295
1295
|
});
|
|
1296
1296
|
}
|
|
1297
1297
|
};
|
|
1298
1298
|
}
|
|
1299
1299
|
// src/utils/prompt.ts
|
|
1300
|
-
function
|
|
1300
|
+
function Z(...e) {
|
|
1301
1301
|
return e.filter((e) => !!(e && e.trim())).join("\n\n");
|
|
1302
1302
|
}
|
|
1303
1303
|
// src/utils/toolCalls.ts
|
|
1304
|
-
var
|
|
1305
|
-
function
|
|
1304
|
+
var Fe = "call_tool", Q = "a tool";
|
|
1305
|
+
function $(e, t) {
|
|
1306
1306
|
let n = {
|
|
1307
|
-
name: e ===
|
|
1307
|
+
name: e === Fe ? Q : e,
|
|
1308
1308
|
args: null,
|
|
1309
1309
|
viaCallTool: !1
|
|
1310
1310
|
};
|
|
@@ -1317,7 +1317,7 @@ function Fe(e, t) {
|
|
|
1317
1317
|
}
|
|
1318
1318
|
if (typeof r != "object" || !r) return n;
|
|
1319
1319
|
let i = r;
|
|
1320
|
-
if (e ===
|
|
1320
|
+
if (e === Fe) {
|
|
1321
1321
|
let e = typeof i.name == "string" ? i.name : void 0;
|
|
1322
1322
|
if (!e) return n;
|
|
1323
1323
|
let t = i.arguments;
|
|
@@ -1409,7 +1409,7 @@ var Ie = 5, Le = (e) => e.type === "text" ? e.value ?? "" : (e.children ?? []).m
|
|
|
1409
1409
|
raw: "Raw event"
|
|
1410
1410
|
};
|
|
1411
1411
|
function $e(e) {
|
|
1412
|
-
return e.kind !== "tool_start" && e.kind !== "tool_end" ? null :
|
|
1412
|
+
return e.kind !== "tool_start" && e.kind !== "tool_end" ? null : $(e.name, e.args);
|
|
1413
1413
|
}
|
|
1414
1414
|
function et(e, t = $e(e)) {
|
|
1415
1415
|
return e.kind === "pseudo_tool_call" ? e.name : t?.name ?? null;
|
|
@@ -1441,9 +1441,9 @@ function at(e) {
|
|
|
1441
1441
|
}
|
|
1442
1442
|
function ot(e) {
|
|
1443
1443
|
switch (e.kind) {
|
|
1444
|
-
case "tool_start": return `Calling ${
|
|
1444
|
+
case "tool_start": return `Calling ${$(e.name, e.args).name}...`;
|
|
1445
1445
|
case "tool_end": {
|
|
1446
|
-
let t =
|
|
1446
|
+
let t = $(e.name, e.args).name;
|
|
1447
1447
|
return e.isError ? `${t} failed` : `${t} returned`;
|
|
1448
1448
|
}
|
|
1449
1449
|
case "pseudo_tool_call": return `${e.name} (written as text, not called)`;
|
|
@@ -1521,7 +1521,7 @@ function mt(e, t) {
|
|
|
1521
1521
|
let n = [];
|
|
1522
1522
|
for (let r of e) if (r.turnSentAt === t) {
|
|
1523
1523
|
if (r.kind === "tool_start") {
|
|
1524
|
-
let e =
|
|
1524
|
+
let e = $(r.name, r.args).name;
|
|
1525
1525
|
n.push({
|
|
1526
1526
|
key: `step-${n.length}`,
|
|
1527
1527
|
callId: r.callId,
|
|
@@ -1531,7 +1531,7 @@ function mt(e, t) {
|
|
|
1531
1531
|
startOffsetMs: r.at - t
|
|
1532
1532
|
});
|
|
1533
1533
|
} else if (r.kind === "tool_end") {
|
|
1534
|
-
let e =
|
|
1534
|
+
let e = $(r.name, r.args).name, i = r.isError ? "failed" : "done", a = n.find((t) => t.status === "running" && t.callId === r.callId && t.toolName === e);
|
|
1535
1535
|
a ? (a.status = i, a.runtimeSeconds = r.runtimeSeconds, a.label = r.displayName || a.label) : n.push({
|
|
1536
1536
|
key: `step-${n.length}`,
|
|
1537
1537
|
callId: r.callId,
|
|
@@ -2214,7 +2214,7 @@ function Tn(e) {
|
|
|
2214
2214
|
}
|
|
2215
2215
|
// src/ui/BaileyHistoryDrawer.tsx
|
|
2216
2216
|
function En({ client: e, pageSize: t, chat: n, labels: r, locale: i, onClose: o }) {
|
|
2217
|
-
let s =
|
|
2217
|
+
let s = xe({
|
|
2218
2218
|
client: e,
|
|
2219
2219
|
pageSize: t
|
|
2220
2220
|
}), { loadConversation: c, newChat: l } = n, u = a((e) => c ? c(e) : Promise.reject(/* @__PURE__ */ Error("no loadConversation")), [c]), d = a(() => {
|
|
@@ -2234,7 +2234,7 @@ function En({ client: e, pageSize: t, chat: n, labels: r, locale: i, onClose: o
|
|
|
2234
2234
|
}
|
|
2235
2235
|
var Dn = (e, t) => Object.entries(t).reduce((e, [t, n]) => e.split(`{${t}}`).join(String(n)), e), On = (e) => !e || e.kind !== "http" ? !1 : e.status === 401 || e.status === 403;
|
|
2236
2236
|
function kn({ conversations: e, activeConversationId: t, selectStatus: n, onSelect: r, onActiveDeleted: i, onNewChat: a, onClose: o, labels: l, locale: u, now: p }) {
|
|
2237
|
-
let { conversations: m, status: h, error: g, hasMore: b, refresh: x, loadMore:
|
|
2237
|
+
let { conversations: m, status: h, error: g, hasMore: b, refresh: x, loadMore: ee, remove: S } = e, C = c(), w = c(), T = d(null), E = d(null), D = d(null), O = d(/* @__PURE__ */ new Map()), k = d(/* @__PURE__ */ new Map()), A = d(null), j = d(null), [te, ne] = f(null), [M, N] = f(null), [P, F] = f(0), [re, I] = f(!1), [L, R] = f(!1), [ie, ae] = f(!1), oe = u ?? (typeof navigator < "u" ? navigator.language : void 0);
|
|
2238
2238
|
s(() => {
|
|
2239
2239
|
T.current?.focus();
|
|
2240
2240
|
}, []), s(() => {
|
|
@@ -2253,50 +2253,50 @@ function kn({ conversations: e, activeConversationId: t, selectStatus: n, onSele
|
|
|
2253
2253
|
b,
|
|
2254
2254
|
m
|
|
2255
2255
|
]);
|
|
2256
|
-
let
|
|
2257
|
-
j.current = m.length,
|
|
2258
|
-
},
|
|
2256
|
+
let se = () => {
|
|
2257
|
+
j.current = m.length, ee();
|
|
2258
|
+
}, ce = (e) => {
|
|
2259
2259
|
A.current = {
|
|
2260
2260
|
kind: "delete",
|
|
2261
2261
|
id: e
|
|
2262
2262
|
}, ne(null);
|
|
2263
2263
|
}, le = (e) => {
|
|
2264
|
-
e.key === "Escape" && (e.stopPropagation(), te ?
|
|
2264
|
+
e.key === "Escape" && (e.stopPropagation(), te ? ce(te) : o({ restoreFocusTo: "menu" }));
|
|
2265
2265
|
}, ue = async (e) => {
|
|
2266
|
-
if (
|
|
2266
|
+
if (ae(!1), e === t) o({ restoreFocusTo: "input" });
|
|
2267
2267
|
else {
|
|
2268
|
-
|
|
2268
|
+
R(!0);
|
|
2269
2269
|
try {
|
|
2270
2270
|
await r({ conversationId: e });
|
|
2271
2271
|
} catch {
|
|
2272
2272
|
A.current = {
|
|
2273
2273
|
kind: "select",
|
|
2274
2274
|
id: e
|
|
2275
|
-
},
|
|
2275
|
+
}, ae(!0), R(!1);
|
|
2276
2276
|
return;
|
|
2277
2277
|
}
|
|
2278
|
-
|
|
2278
|
+
R(!1), o({ restoreFocusTo: "input" });
|
|
2279
2279
|
}
|
|
2280
2280
|
}, de = async (e) => {
|
|
2281
2281
|
let n = m.findIndex((t) => t.conversationId === e), r = m[n + 1] ?? m[n - 1];
|
|
2282
2282
|
A.current = r ? {
|
|
2283
2283
|
kind: "select",
|
|
2284
2284
|
id: r.conversationId
|
|
2285
|
-
} : { kind: "newChat" }, ne(null), N(null), I(!1),
|
|
2285
|
+
} : { kind: "newChat" }, ne(null), N(null), I(!1), F((e) => e + 1);
|
|
2286
2286
|
try {
|
|
2287
|
-
await
|
|
2287
|
+
await S({ conversationId: e }), I(!0), e === t && i?.();
|
|
2288
2288
|
} catch {
|
|
2289
2289
|
A.current = {
|
|
2290
2290
|
kind: "delete",
|
|
2291
2291
|
id: e
|
|
2292
2292
|
}, N(e);
|
|
2293
2293
|
} finally {
|
|
2294
|
-
|
|
2294
|
+
F((e) => e - 1);
|
|
2295
2295
|
}
|
|
2296
|
-
},
|
|
2296
|
+
}, fe = h === "loading" && m.length === 0, pe = h === "error" && m.length === 0, me = h === "error" && m.length > 0 && b, z = h === "loading" && m.length > 0, he = L || n === "loading", B = fe ? l.historyLoadingText : P > 0 ? l.historyDeletingText : re ? l.historyDeletedText : m.length > 0 ? Dn(m.length === 1 ? l.historyCountTextOne : l.historyCountTextMany, { count: m.length }) : "", ge = fe || P > 0;
|
|
2297
2297
|
return /* @__PURE__ */ y("section", {
|
|
2298
2298
|
role: "region",
|
|
2299
|
-
"aria-labelledby":
|
|
2299
|
+
"aria-labelledby": C,
|
|
2300
2300
|
className: "bailey-history-drawer",
|
|
2301
2301
|
onKeyDown: le,
|
|
2302
2302
|
children: [
|
|
@@ -2311,7 +2311,7 @@ function kn({ conversations: e, activeConversationId: t, selectStatus: n, onSele
|
|
|
2311
2311
|
children: /* @__PURE__ */ v(Kt, { className: "bailey-history-icon" })
|
|
2312
2312
|
}),
|
|
2313
2313
|
/* @__PURE__ */ v("h3", {
|
|
2314
|
-
id:
|
|
2314
|
+
id: C,
|
|
2315
2315
|
ref: T,
|
|
2316
2316
|
tabIndex: -1,
|
|
2317
2317
|
className: "bailey-history-heading",
|
|
@@ -2322,7 +2322,7 @@ function kn({ conversations: e, activeConversationId: t, selectStatus: n, onSele
|
|
|
2322
2322
|
type: "button",
|
|
2323
2323
|
className: "bailey-history-button bailey-history-new-chat",
|
|
2324
2324
|
"aria-label": l.newChatButtonText,
|
|
2325
|
-
disabled:
|
|
2325
|
+
disabled: fe,
|
|
2326
2326
|
onClick: a,
|
|
2327
2327
|
children: [/* @__PURE__ */ v(Vt, { className: "bailey-history-icon-small" }), /* @__PURE__ */ v("span", {
|
|
2328
2328
|
className: "bailey-history-new-chat-text",
|
|
@@ -2333,9 +2333,9 @@ function kn({ conversations: e, activeConversationId: t, selectStatus: n, onSele
|
|
|
2333
2333
|
}),
|
|
2334
2334
|
/* @__PURE__ */ y("div", {
|
|
2335
2335
|
className: "bailey-history-body",
|
|
2336
|
-
"aria-busy":
|
|
2336
|
+
"aria-busy": fe || void 0,
|
|
2337
2337
|
children: [
|
|
2338
|
-
|
|
2338
|
+
fe && /* @__PURE__ */ y("div", {
|
|
2339
2339
|
"aria-hidden": "true",
|
|
2340
2340
|
children: [
|
|
2341
2341
|
/* @__PURE__ */ v("div", { className: "bailey-history-skeleton" }),
|
|
@@ -2344,7 +2344,7 @@ function kn({ conversations: e, activeConversationId: t, selectStatus: n, onSele
|
|
|
2344
2344
|
/* @__PURE__ */ v("div", { className: "bailey-history-skeleton" })
|
|
2345
2345
|
]
|
|
2346
2346
|
}),
|
|
2347
|
-
|
|
2347
|
+
pe && /* @__PURE__ */ y("div", {
|
|
2348
2348
|
role: "alert",
|
|
2349
2349
|
className: "bailey-history-state bailey-history-state-error",
|
|
2350
2350
|
children: [
|
|
@@ -2359,7 +2359,7 @@ function kn({ conversations: e, activeConversationId: t, selectStatus: n, onSele
|
|
|
2359
2359
|
})
|
|
2360
2360
|
]
|
|
2361
2361
|
}),
|
|
2362
|
-
!
|
|
2362
|
+
!fe && !pe && m.length === 0 && /* @__PURE__ */ y("div", {
|
|
2363
2363
|
className: "bailey-history-state",
|
|
2364
2364
|
children: [
|
|
2365
2365
|
/* @__PURE__ */ v(Rt, { className: "bailey-history-state-icon" }),
|
|
@@ -2403,7 +2403,7 @@ function kn({ conversations: e, activeConversationId: t, selectStatus: n, onSele
|
|
|
2403
2403
|
ref: D,
|
|
2404
2404
|
type: "button",
|
|
2405
2405
|
className: "bailey-history-button",
|
|
2406
|
-
onClick: () =>
|
|
2406
|
+
onClick: () => ce(n),
|
|
2407
2407
|
children: l.historyDeleteCancelText
|
|
2408
2408
|
})
|
|
2409
2409
|
]
|
|
@@ -2411,7 +2411,7 @@ function kn({ conversations: e, activeConversationId: t, selectStatus: n, onSele
|
|
|
2411
2411
|
}, n);
|
|
2412
2412
|
let a = Tn({
|
|
2413
2413
|
iso: e.updatedAt,
|
|
2414
|
-
locale:
|
|
2414
|
+
locale: oe,
|
|
2415
2415
|
now: p?.(),
|
|
2416
2416
|
justNowText: l.historyJustNowText
|
|
2417
2417
|
}), o = Dn(e.messageCount === 1 ? l.historyMessageCountOne : l.historyMessageCountMany, { count: e.messageCount }), s = M === n;
|
|
@@ -2425,9 +2425,9 @@ function kn({ conversations: e, activeConversationId: t, selectStatus: n, onSele
|
|
|
2425
2425
|
},
|
|
2426
2426
|
className: "bailey-history-select",
|
|
2427
2427
|
"aria-current": i ? "true" : void 0,
|
|
2428
|
-
"aria-disabled":
|
|
2428
|
+
"aria-disabled": he || void 0,
|
|
2429
2429
|
onClick: () => {
|
|
2430
|
-
|
|
2430
|
+
he || ue(n);
|
|
2431
2431
|
},
|
|
2432
2432
|
children: [/* @__PURE__ */ v("span", {
|
|
2433
2433
|
className: "bailey-history-row-title",
|
|
@@ -2486,31 +2486,31 @@ function kn({ conversations: e, activeConversationId: t, selectStatus: n, onSele
|
|
|
2486
2486
|
}, n);
|
|
2487
2487
|
})
|
|
2488
2488
|
}),
|
|
2489
|
-
|
|
2489
|
+
ie && /* @__PURE__ */ v("div", {
|
|
2490
2490
|
role: "alert",
|
|
2491
2491
|
className: "bailey-history-inline-error",
|
|
2492
2492
|
children: l.historySelectErrorText
|
|
2493
2493
|
}),
|
|
2494
2494
|
b && m.length > 0 && /* @__PURE__ */ v("div", {
|
|
2495
2495
|
className: "bailey-history-more",
|
|
2496
|
-
children:
|
|
2496
|
+
children: me ? /* @__PURE__ */ y("div", {
|
|
2497
2497
|
role: "alert",
|
|
2498
2498
|
className: "bailey-history-inline-error",
|
|
2499
2499
|
children: [/* @__PURE__ */ v("span", { children: l.historyLoadMoreErrorText }), /* @__PURE__ */ v("button", {
|
|
2500
2500
|
type: "button",
|
|
2501
2501
|
className: "bailey-history-button",
|
|
2502
|
-
onClick:
|
|
2502
|
+
onClick: se,
|
|
2503
2503
|
children: l.retryButtonText
|
|
2504
2504
|
})]
|
|
2505
2505
|
}) : /* @__PURE__ */ y("button", {
|
|
2506
2506
|
type: "button",
|
|
2507
2507
|
className: "bailey-history-button",
|
|
2508
|
-
disabled:
|
|
2509
|
-
onClick:
|
|
2510
|
-
children: [
|
|
2508
|
+
disabled: z,
|
|
2509
|
+
onClick: se,
|
|
2510
|
+
children: [z && /* @__PURE__ */ v("span", {
|
|
2511
2511
|
className: "bailey-history-spinner",
|
|
2512
2512
|
"aria-hidden": "true"
|
|
2513
|
-
}),
|
|
2513
|
+
}), z ? l.historyLoadingMoreText : l.historyLoadMoreText]
|
|
2514
2514
|
})
|
|
2515
2515
|
})
|
|
2516
2516
|
]
|
|
@@ -2522,7 +2522,7 @@ function kn({ conversations: e, activeConversationId: t, selectStatus: n, onSele
|
|
|
2522
2522
|
children: [ge && /* @__PURE__ */ v("span", {
|
|
2523
2523
|
className: "bailey-history-spinner",
|
|
2524
2524
|
"aria-hidden": "true"
|
|
2525
|
-
}),
|
|
2525
|
+
}), B]
|
|
2526
2526
|
})
|
|
2527
2527
|
]
|
|
2528
2528
|
});
|
|
@@ -2614,15 +2614,15 @@ function Bn({ messageId: e, onSubmit: t, onClear: n, initialRating: r, reasonOpt
|
|
|
2614
2614
|
...jn,
|
|
2615
2615
|
feedbackCommentPlaceholder: `What should ${l} have said or done differently?`,
|
|
2616
2616
|
...o
|
|
2617
|
-
}, m = In(i), h = Ln(a), b = r ? { rating: r } : null, [x,
|
|
2618
|
-
s(() => (
|
|
2619
|
-
|
|
2617
|
+
}, m = In(i), h = Ln(a), b = r ? { rating: r } : null, [x, ee] = f(b), [S, C] = f(r ?? null), [w, T] = f(!1), [E, D] = f("down"), [O, k] = f([]), [A, j] = f(""), [te, ne] = f(!1), [M, N] = f(!1), [P, F] = f(!1), [re, I] = f(!1), L = d(b), R = d(null), ie = d(0), ae = d(!1), oe = d(!0), se = d(null), ce = d(null), le = d(null), ue = d(null), de = d(null), fe = At(ce), pe = c(), me = `${pe}-comment`, z = `${pe}-counter`, he = `${pe}-privacy`;
|
|
2618
|
+
s(() => (oe.current = !0, () => {
|
|
2619
|
+
oe.current = !1;
|
|
2620
2620
|
}), []), s(() => {
|
|
2621
2621
|
w && de.current?.focus();
|
|
2622
2622
|
}, [w]), s(() => {
|
|
2623
|
-
|
|
2623
|
+
se.current && !P && !w && ((se.current === "up" ? le : ue).current?.focus(), se.current = null);
|
|
2624
2624
|
});
|
|
2625
|
-
let
|
|
2625
|
+
let B = () => {
|
|
2626
2626
|
k([]), j("");
|
|
2627
2627
|
}, ge = async (r) => {
|
|
2628
2628
|
try {
|
|
@@ -2634,54 +2634,54 @@ function Bn({ messageId: e, onSubmit: t, onClear: n, initialRating: r, reasonOpt
|
|
|
2634
2634
|
return !1;
|
|
2635
2635
|
}
|
|
2636
2636
|
}, _e = async () => {
|
|
2637
|
-
if (!
|
|
2638
|
-
|
|
2637
|
+
if (!ae.current) {
|
|
2638
|
+
ae.current = !0, N(!0);
|
|
2639
2639
|
try {
|
|
2640
|
-
for (;
|
|
2641
|
-
let e =
|
|
2642
|
-
if (!
|
|
2643
|
-
let r =
|
|
2644
|
-
(n || !r) && (n ? (
|
|
2640
|
+
for (; R.current && oe.current;) {
|
|
2641
|
+
let e = R.current, t = e.kind === "clear" ? null : e.snapshot, n = !(e.kind === "submit" && e.formSubmit) && Rn(t, L.current) || await ge(e);
|
|
2642
|
+
if (!oe.current) return;
|
|
2643
|
+
let r = R.current?.version !== e.version;
|
|
2644
|
+
(n || !r) && (n ? (L.current = t, ee(t)) : (C(L.current?.rating ?? null), I(!0)), r || (R.current = null, F(!1), n && e.kind === "submit" && e.formSubmit && (T(!1), ne(!0), se.current = e.snapshot.rating)));
|
|
2645
2645
|
}
|
|
2646
2646
|
} finally {
|
|
2647
|
-
|
|
2647
|
+
ae.current = !1, oe.current && N(!1);
|
|
2648
2648
|
}
|
|
2649
2649
|
}
|
|
2650
2650
|
}, ve = (e) => {
|
|
2651
|
-
|
|
2651
|
+
ie.current += 1, R.current = {
|
|
2652
2652
|
...e,
|
|
2653
|
-
version:
|
|
2653
|
+
version: ie.current
|
|
2654
2654
|
}, I(!1), _e();
|
|
2655
2655
|
}, ye = () => {
|
|
2656
|
-
|
|
2656
|
+
C(null), T(!1), ne(!1), B(), ve({ kind: "clear" });
|
|
2657
2657
|
}, be = (e) => {
|
|
2658
|
-
P || (
|
|
2658
|
+
P || (S === e ? ye() : (C(e), ne(!1), B(), e === "down" ? (D("down"), T(!0)) : T(!1), ve({
|
|
2659
2659
|
kind: "submit",
|
|
2660
2660
|
snapshot: { rating: e },
|
|
2661
2661
|
formSubmit: !1
|
|
2662
2662
|
})));
|
|
2663
|
-
},
|
|
2664
|
-
|
|
2665
|
-
},
|
|
2666
|
-
P || (T(!1), I(!1),
|
|
2667
|
-
},
|
|
2663
|
+
}, xe = (e) => {
|
|
2664
|
+
S !== null && (D(S), k((e?.reasonCodes ?? []).map(Fn)), j(e?.comment ?? ""), I(!1), T(!0));
|
|
2665
|
+
}, V = () => {
|
|
2666
|
+
P || (T(!1), I(!1), B(), se.current = E);
|
|
2667
|
+
}, Se = () => {
|
|
2668
2668
|
if (P) return;
|
|
2669
2669
|
let e = A.trim(), t = m.filter((e) => O.includes(e)), n = {
|
|
2670
2670
|
rating: E,
|
|
2671
2671
|
...t.length > 0 ? { reasonCodes: t } : {},
|
|
2672
2672
|
...e ? { comment: e } : {}
|
|
2673
2673
|
};
|
|
2674
|
-
|
|
2674
|
+
F(!0), C(E), ve({
|
|
2675
2675
|
kind: "submit",
|
|
2676
2676
|
snapshot: n,
|
|
2677
2677
|
formSubmit: !0
|
|
2678
2678
|
});
|
|
2679
|
-
},
|
|
2679
|
+
}, Ce = (e) => {
|
|
2680
2680
|
k((t) => t.includes(e) ? t.filter((t) => t !== e) : [...t, e]);
|
|
2681
|
-
},
|
|
2682
|
-
e.key === "Escape" && (e.stopPropagation(),
|
|
2683
|
-
},
|
|
2684
|
-
let t =
|
|
2681
|
+
}, H = (e) => {
|
|
2682
|
+
e.key === "Escape" && (e.stopPropagation(), V());
|
|
2683
|
+
}, U = S !== null && x?.rating === S && !M && !w, W = !!x && (!!x.comment || (x.reasonCodes?.length ?? 0) > 0), we = M ? p.feedbackSavingText : U ? p.feedbackThanksText : "", Te = (e) => {
|
|
2684
|
+
let t = S === e, n = e === "up" ? p.feedbackThumbsUpAriaLabel : p.feedbackThumbsDownAriaLabel, r = e === "up" ? Wt : Gt;
|
|
2685
2685
|
return /* @__PURE__ */ y(g.Root, { children: [/* @__PURE__ */ v(g.Trigger, {
|
|
2686
2686
|
asChild: !0,
|
|
2687
2687
|
children: /* @__PURE__ */ v("button", {
|
|
@@ -2699,7 +2699,7 @@ function Bn({ messageId: e, onSubmit: t, onClear: n, initialRating: r, reasonOpt
|
|
|
2699
2699
|
})
|
|
2700
2700
|
})
|
|
2701
2701
|
}), /* @__PURE__ */ v(g.Portal, {
|
|
2702
|
-
container:
|
|
2702
|
+
container: fe instanceof ShadowRoot ? fe : void 0,
|
|
2703
2703
|
children: /* @__PURE__ */ y(g.Content, {
|
|
2704
2704
|
side: "top",
|
|
2705
2705
|
className: "bailey-tooltip-content",
|
|
@@ -2708,7 +2708,7 @@ function Bn({ messageId: e, onSubmit: t, onClear: n, initialRating: r, reasonOpt
|
|
|
2708
2708
|
})] });
|
|
2709
2709
|
};
|
|
2710
2710
|
return /* @__PURE__ */ y("div", {
|
|
2711
|
-
ref:
|
|
2711
|
+
ref: ce,
|
|
2712
2712
|
className: `bailey-feedback${u ? ` ${u}` : ""}`,
|
|
2713
2713
|
children: [
|
|
2714
2714
|
/* @__PURE__ */ v(g.Provider, {
|
|
@@ -2718,7 +2718,7 @@ function Bn({ messageId: e, onSubmit: t, onClear: n, initialRating: r, reasonOpt
|
|
|
2718
2718
|
"aria-label": p.feedbackGroupLabel,
|
|
2719
2719
|
"aria-busy": M ? !0 : void 0,
|
|
2720
2720
|
className: "bailey-feedback-thumbs",
|
|
2721
|
-
children: [
|
|
2721
|
+
children: [Te("up"), Te("down")]
|
|
2722
2722
|
})
|
|
2723
2723
|
}),
|
|
2724
2724
|
/* @__PURE__ */ y("span", {
|
|
@@ -2727,27 +2727,27 @@ function Bn({ messageId: e, onSubmit: t, onClear: n, initialRating: r, reasonOpt
|
|
|
2727
2727
|
children: [M && /* @__PURE__ */ v("span", {
|
|
2728
2728
|
className: "bailey-feedback-spinner",
|
|
2729
2729
|
"aria-hidden": "true"
|
|
2730
|
-
}),
|
|
2730
|
+
}), we]
|
|
2731
2731
|
}),
|
|
2732
|
-
|
|
2732
|
+
U && /* @__PURE__ */ y(_, { children: [/* @__PURE__ */ v("button", {
|
|
2733
2733
|
type: "button",
|
|
2734
2734
|
className: "bailey-feedback-link",
|
|
2735
|
-
onClick: () =>
|
|
2736
|
-
children: te ||
|
|
2735
|
+
onClick: () => xe(x),
|
|
2736
|
+
children: te || W ? p.feedbackEditText : p.feedbackAddCommentText
|
|
2737
2737
|
}), /* @__PURE__ */ v("button", {
|
|
2738
2738
|
type: "button",
|
|
2739
2739
|
className: "bailey-feedback-link",
|
|
2740
2740
|
onClick: ye,
|
|
2741
2741
|
children: p.feedbackUndoText
|
|
2742
2742
|
})] }),
|
|
2743
|
-
|
|
2743
|
+
re && /* @__PURE__ */ v("span", {
|
|
2744
2744
|
role: "alert",
|
|
2745
2745
|
className: "bailey-feedback-error",
|
|
2746
2746
|
children: p.feedbackErrorText
|
|
2747
2747
|
}),
|
|
2748
2748
|
w && /* @__PURE__ */ y("div", {
|
|
2749
2749
|
className: "bailey-feedback-form",
|
|
2750
|
-
onKeyDown:
|
|
2750
|
+
onKeyDown: H,
|
|
2751
2751
|
children: [
|
|
2752
2752
|
m.length > 0 && /* @__PURE__ */ y("fieldset", {
|
|
2753
2753
|
className: "bailey-feedback-reasons",
|
|
@@ -2764,18 +2764,18 @@ function Bn({ messageId: e, onSubmit: t, onClear: n, initialRating: r, reasonOpt
|
|
|
2764
2764
|
className: "bailey-feedback-chip",
|
|
2765
2765
|
"aria-pressed": O.includes(e),
|
|
2766
2766
|
disabled: P,
|
|
2767
|
-
onClick: () =>
|
|
2767
|
+
onClick: () => Ce(e),
|
|
2768
2768
|
children: p[Pn[e]]
|
|
2769
2769
|
}, e))
|
|
2770
2770
|
})]
|
|
2771
2771
|
}),
|
|
2772
2772
|
/* @__PURE__ */ v("label", {
|
|
2773
|
-
htmlFor:
|
|
2773
|
+
htmlFor: me,
|
|
2774
2774
|
className: "bailey-feedback-legend",
|
|
2775
2775
|
children: p.feedbackCommentLabel
|
|
2776
2776
|
}),
|
|
2777
2777
|
/* @__PURE__ */ v("textarea", {
|
|
2778
|
-
id:
|
|
2778
|
+
id: me,
|
|
2779
2779
|
ref: m.length === 0 ? (e) => {
|
|
2780
2780
|
de.current = e;
|
|
2781
2781
|
} : void 0,
|
|
@@ -2783,18 +2783,18 @@ function Bn({ messageId: e, onSubmit: t, onClear: n, initialRating: r, reasonOpt
|
|
|
2783
2783
|
value: A,
|
|
2784
2784
|
maxLength: h,
|
|
2785
2785
|
placeholder: p.feedbackCommentPlaceholder,
|
|
2786
|
-
"aria-describedby": `${
|
|
2786
|
+
"aria-describedby": `${z} ${he}`,
|
|
2787
2787
|
disabled: P,
|
|
2788
2788
|
onChange: (e) => j(e.target.value.slice(0, h))
|
|
2789
2789
|
}),
|
|
2790
2790
|
/* @__PURE__ */ y("div", {
|
|
2791
2791
|
className: "bailey-feedback-meta",
|
|
2792
2792
|
children: [/* @__PURE__ */ v("span", {
|
|
2793
|
-
id:
|
|
2793
|
+
id: he,
|
|
2794
2794
|
className: "bailey-feedback-privacy",
|
|
2795
2795
|
children: p.feedbackPrivacyNote
|
|
2796
2796
|
}), /* @__PURE__ */ v("span", {
|
|
2797
|
-
id:
|
|
2797
|
+
id: z,
|
|
2798
2798
|
className: "bailey-feedback-counter",
|
|
2799
2799
|
children: `${A.length} / ${h}`
|
|
2800
2800
|
})]
|
|
@@ -2805,13 +2805,13 @@ function Bn({ messageId: e, onSubmit: t, onClear: n, initialRating: r, reasonOpt
|
|
|
2805
2805
|
type: "button",
|
|
2806
2806
|
className: "bailey-feedback-button",
|
|
2807
2807
|
disabled: P,
|
|
2808
|
-
onClick:
|
|
2808
|
+
onClick: V,
|
|
2809
2809
|
children: p.feedbackCancelText
|
|
2810
2810
|
}), /* @__PURE__ */ v("button", {
|
|
2811
2811
|
type: "button",
|
|
2812
2812
|
className: "bailey-feedback-button bailey-feedback-button-primary",
|
|
2813
2813
|
disabled: P,
|
|
2814
|
-
onClick:
|
|
2814
|
+
onClick: Se,
|
|
2815
2815
|
children: P ? p.feedbackSavingText : p.feedbackSubmitText
|
|
2816
2816
|
})]
|
|
2817
2817
|
})
|
|
@@ -2877,91 +2877,95 @@ function Jn(e) {
|
|
|
2877
2877
|
});
|
|
2878
2878
|
return n ? `Today ${r}` : `${t.toLocaleDateString()} ${r}`;
|
|
2879
2879
|
}
|
|
2880
|
-
function Yn({ chat: e, placeholder: t, replyPlaceholder: r, emptyPlaceholder: i, assistantName: o = Vn, suggestions: c, suggestionsAlign: l = "start", hideMenuButton: m = !1, onHistoryClick: _, history: b,
|
|
2881
|
-
let { messages:
|
|
2882
|
-
let t = (t) =>
|
|
2880
|
+
function Yn({ chat: e, placeholder: t, replyPlaceholder: r, emptyPlaceholder: i, assistantName: o = Vn, suggestions: c, suggestionsAlign: l = "start", hideMenuButton: m = !1, onHistoryClick: _, history: b, historyOpen: x, onHistoryOpenChange: ee, locale: S, privacyNote: C, resolveActivityIcon: w, sendIcon: T, className: E, height: D, width: O, hideDeveloperDetails: k = !1, renderMessageActions: A, feedback: j, renderTable: te, renderChart: ne, renderMcpApp: M, labels: N, formatMessageTime: P }) {
|
|
2881
|
+
let { messages: F, traceEvents: re, lastRequest: I, status: L, error: R, send: ie, stop: ae, retryLast: oe, clearTrace: se, clearError: ce, newChat: le } = e, [ue, de] = f(""), [fe, pe] = f(/* @__PURE__ */ new Map()), me = a((e) => {
|
|
2882
|
+
let t = (t) => pe((n) => {
|
|
2883
2883
|
let r = new Map(n), i = (r.get(e) ?? 0) + t;
|
|
2884
2884
|
return i > 0 ? r.set(e, i) : r.delete(e), r;
|
|
2885
2885
|
});
|
|
2886
2886
|
return t(1), () => t(-1);
|
|
2887
|
-
}, []),
|
|
2887
|
+
}, []), z = u(() => ({
|
|
2888
2888
|
builtIn: !1,
|
|
2889
|
-
claim:
|
|
2890
|
-
}), [
|
|
2889
|
+
claim: me
|
|
2890
|
+
}), [me]), he = u(() => ({
|
|
2891
2891
|
builtIn: !0,
|
|
2892
|
-
claim:
|
|
2893
|
-
}), [
|
|
2892
|
+
claim: me
|
|
2893
|
+
}), [me]), B = {
|
|
2894
2894
|
...Hn,
|
|
2895
2895
|
emptyStateMessage: `Ask ${o} a question to get started.`,
|
|
2896
|
-
...
|
|
2897
|
-
},
|
|
2898
|
-
renderTable:
|
|
2899
|
-
renderChart:
|
|
2900
|
-
}), [
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
]),
|
|
2905
|
-
|
|
2906
|
-
at:
|
|
2907
|
-
length:
|
|
2908
|
-
},
|
|
2909
|
-
let
|
|
2896
|
+
...N
|
|
2897
|
+
}, ge = P ?? Jn, _e = d(null), ve = d(null), ye = d(null), be = d(null), [xe, V] = f(!1), Se = x !== void 0, Ce = x ?? xe, H = d(null), U = d(!1), W = !!_ || !!b, we = kt(_e), Te = d(null), Ee = d(null), De = d(!0), Oe = u(() => Mt({
|
|
2898
|
+
renderTable: te,
|
|
2899
|
+
renderChart: ne
|
|
2900
|
+
}), [te, ne]), ke = u(() => Kn(L, re, I), [
|
|
2901
|
+
L,
|
|
2902
|
+
re,
|
|
2903
|
+
I
|
|
2904
|
+
]), Ae = qn(ke), G = ke?.kind === "tool_end" ? ke.at : void 0, K = F[F.length - 1]?.content.length ?? 0, [q, je] = f(null), J = q;
|
|
2905
|
+
G !== void 0 && q?.at !== G && (J = {
|
|
2906
|
+
at: G,
|
|
2907
|
+
length: K
|
|
2908
|
+
}, je(J));
|
|
2909
|
+
let Me = G !== void 0 && J?.at === G && K <= J.length, Ne = Ae ?? (Me ? B.thinkingHint : void 0), Y = F.length === 0, X = t ?? (Y ? i ?? `How can ${o} AI help you today?` : r ?? `Reply to ${o} AI`);
|
|
2910
2910
|
s(() => {
|
|
2911
|
-
let e =
|
|
2911
|
+
let e = Ee.current;
|
|
2912
2912
|
if (!e) return;
|
|
2913
2913
|
let t = () => {
|
|
2914
2914
|
let t = e.scrollHeight - e.scrollTop - e.clientHeight;
|
|
2915
|
-
|
|
2915
|
+
De.current = t < 60;
|
|
2916
2916
|
};
|
|
2917
2917
|
return e.addEventListener("scroll", t, { passive: !0 }), () => e.removeEventListener("scroll", t);
|
|
2918
2918
|
}, []), s(() => {
|
|
2919
|
-
|
|
2920
|
-
behavior:
|
|
2919
|
+
De.current && Te.current?.scrollIntoView({
|
|
2920
|
+
behavior: L === "streaming" ? "auto" : "smooth",
|
|
2921
2921
|
block: "nearest"
|
|
2922
2922
|
});
|
|
2923
|
-
}, [
|
|
2924
|
-
let
|
|
2925
|
-
|
|
2926
|
-
},
|
|
2927
|
-
let t =
|
|
2928
|
-
|
|
2923
|
+
}, [F, L]);
|
|
2924
|
+
let Pe = (e) => {
|
|
2925
|
+
De.current = !0, ie(e);
|
|
2926
|
+
}, Z = d(null), Fe = () => {
|
|
2927
|
+
let t = Ee.current;
|
|
2928
|
+
De.current = !1, Z.current = t ? {
|
|
2929
2929
|
height: t.scrollHeight,
|
|
2930
2930
|
top: t.scrollTop
|
|
2931
2931
|
} : null, e.loadEarlier?.().catch(() => {
|
|
2932
|
-
|
|
2932
|
+
Z.current = null;
|
|
2933
2933
|
});
|
|
2934
2934
|
};
|
|
2935
2935
|
s(() => {
|
|
2936
|
-
let e =
|
|
2937
|
-
e && t && t.scrollHeight !== e.height && (t.scrollTop = e.top + (t.scrollHeight - e.height),
|
|
2938
|
-
}, [
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
}, [
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2936
|
+
let e = Z.current, t = Ee.current;
|
|
2937
|
+
e && t && t.scrollHeight !== e.height && (t.scrollTop = e.top + (t.scrollHeight - e.height), Z.current = null);
|
|
2938
|
+
}, [F]);
|
|
2939
|
+
let Q = Ce && !!b && !_;
|
|
2940
|
+
s(() => {
|
|
2941
|
+
ve.current?.toggleAttribute("inert", Q);
|
|
2942
|
+
}, [Q]), s(() => {
|
|
2943
|
+
!Q && H.current && (((H.current === "menu" ? be.current : null) ?? ye.current)?.focus(), H.current = null);
|
|
2944
|
+
}, [Q]);
|
|
2945
|
+
let $ = a((e) => {
|
|
2946
|
+
Se || V(e), ee?.(e);
|
|
2947
|
+
}, [Se, ee]), Ie = a((e) => {
|
|
2948
|
+
H.current = e.restoreFocusTo, $(!1);
|
|
2949
|
+
}, [$]);
|
|
2946
2950
|
return /* @__PURE__ */ v(gt.Provider, {
|
|
2947
|
-
value:
|
|
2951
|
+
value: we,
|
|
2948
2952
|
children: /* @__PURE__ */ v(jt.Provider, {
|
|
2949
|
-
value:
|
|
2953
|
+
value: z,
|
|
2950
2954
|
children: /* @__PURE__ */ y("div", {
|
|
2951
|
-
ref:
|
|
2952
|
-
className: `bailey-chat-panel${
|
|
2953
|
-
style:
|
|
2954
|
-
height:
|
|
2955
|
-
width:
|
|
2955
|
+
ref: _e,
|
|
2956
|
+
className: `bailey-chat-panel${E ? ` ${E}` : ""}`,
|
|
2957
|
+
style: D !== void 0 || O !== void 0 ? {
|
|
2958
|
+
height: D,
|
|
2959
|
+
width: O
|
|
2956
2960
|
} : void 0,
|
|
2957
2961
|
children: [/* @__PURE__ */ y("div", {
|
|
2958
2962
|
className: "bailey-chat-panel-inner",
|
|
2959
|
-
ref:
|
|
2963
|
+
ref: ve,
|
|
2960
2964
|
children: [
|
|
2961
2965
|
/* @__PURE__ */ y("div", {
|
|
2962
2966
|
className: "bailey-chat-transcript",
|
|
2963
|
-
ref:
|
|
2964
|
-
"data-suggestions-align":
|
|
2967
|
+
ref: Ee,
|
|
2968
|
+
"data-suggestions-align": Y && c && c.length > 0 ? l : void 0,
|
|
2965
2969
|
children: [
|
|
2966
2970
|
e.hasEarlier && e.loadEarlier && /* @__PURE__ */ y("div", {
|
|
2967
2971
|
className: "bailey-load-earlier",
|
|
@@ -2969,7 +2973,7 @@ function Yn({ chat: e, placeholder: t, replyPlaceholder: r, emptyPlaceholder: i,
|
|
|
2969
2973
|
type: "button",
|
|
2970
2974
|
className: "bailey-load-earlier-button",
|
|
2971
2975
|
disabled: e.historyStatus === "loading",
|
|
2972
|
-
onClick:
|
|
2976
|
+
onClick: Fe,
|
|
2973
2977
|
children: B.loadEarlierButtonText
|
|
2974
2978
|
}), e.historyStatus === "error" && /* @__PURE__ */ v("div", {
|
|
2975
2979
|
role: "alert",
|
|
@@ -2977,7 +2981,7 @@ function Yn({ chat: e, placeholder: t, replyPlaceholder: r, emptyPlaceholder: i,
|
|
|
2977
2981
|
children: B.loadEarlierErrorText
|
|
2978
2982
|
})]
|
|
2979
2983
|
}),
|
|
2980
|
-
|
|
2984
|
+
Y && (c && c.length > 0 ? /* @__PURE__ */ y("div", {
|
|
2981
2985
|
className: "bailey-suggestions",
|
|
2982
2986
|
"data-align": l,
|
|
2983
2987
|
children: [B.suggestionsTitle && /* @__PURE__ */ v("div", {
|
|
@@ -2985,7 +2989,7 @@ function Yn({ chat: e, placeholder: t, replyPlaceholder: r, emptyPlaceholder: i,
|
|
|
2985
2989
|
children: B.suggestionsTitle
|
|
2986
2990
|
}), c.map((e, t) => /* @__PURE__ */ y("button", {
|
|
2987
2991
|
type: "button",
|
|
2988
|
-
onClick: () =>
|
|
2992
|
+
onClick: () => Pe(e.value ?? e.label),
|
|
2989
2993
|
className: "bailey-suggestion-card",
|
|
2990
2994
|
children: [/* @__PURE__ */ v("span", { children: e.label }), e.icon ?? /* @__PURE__ */ v(Ft, { className: "bailey-suggestion-icon" })]
|
|
2991
2995
|
}, `${e.label}-${t}`))]
|
|
@@ -2993,8 +2997,8 @@ function Yn({ chat: e, placeholder: t, replyPlaceholder: r, emptyPlaceholder: i,
|
|
|
2993
2997
|
className: "bailey-empty-state",
|
|
2994
2998
|
children: B.emptyStateMessage
|
|
2995
2999
|
})),
|
|
2996
|
-
|
|
2997
|
-
let i = t.role === "assistant" && r ===
|
|
3000
|
+
F.map((t, r) => {
|
|
3001
|
+
let i = t.role === "assistant" && r === F.length - 1, a = L === "streaming" && i && t.content === "", s = t.role === "assistant" ? mt(re, t.createdAt) : [], c = s.some((e) => e.status === "running");
|
|
2998
3002
|
return /* @__PURE__ */ v("div", {
|
|
2999
3003
|
className: t.role === "user" ? "bailey-message-row bailey-message-row-user" : "bailey-message-row",
|
|
3000
3004
|
children: t.role === "user" ? /* @__PURE__ */ y("div", {
|
|
@@ -3004,17 +3008,17 @@ function Yn({ chat: e, placeholder: t, replyPlaceholder: r, emptyPlaceholder: i,
|
|
|
3004
3008
|
children: [/* @__PURE__ */ v("span", {
|
|
3005
3009
|
className: "bailey-message-meta-name",
|
|
3006
3010
|
children: B.youLabel
|
|
3007
|
-
}), t.createdAt !== void 0 && /* @__PURE__ */ v("span", { children:
|
|
3011
|
+
}), t.createdAt !== void 0 && /* @__PURE__ */ v("span", { children: ge(t.createdAt) })]
|
|
3008
3012
|
}), /* @__PURE__ */ v("div", {
|
|
3009
3013
|
className: "bailey-user-bubble",
|
|
3010
3014
|
children: t.content
|
|
3011
3015
|
})]
|
|
3012
3016
|
}) : a ? c ? /* @__PURE__ */ v(_n, {
|
|
3013
3017
|
steps: s,
|
|
3014
|
-
resolveActivityIcon:
|
|
3018
|
+
resolveActivityIcon: w
|
|
3015
3019
|
}) : /* @__PURE__ */ y("div", {
|
|
3016
3020
|
className: "bailey-thinking-hint",
|
|
3017
|
-
children: [/* @__PURE__ */ v("span", { children:
|
|
3021
|
+
children: [/* @__PURE__ */ v("span", { children: Ae ?? B.thinkingHint }), /* @__PURE__ */ v("span", {
|
|
3018
3022
|
className: "bailey-step-spinner",
|
|
3019
3023
|
"aria-hidden": "true"
|
|
3020
3024
|
})]
|
|
@@ -3024,26 +3028,26 @@ function Yn({ chat: e, placeholder: t, replyPlaceholder: r, emptyPlaceholder: i,
|
|
|
3024
3028
|
!t.streaming && /* @__PURE__ */ v(vn, {
|
|
3025
3029
|
steps: s,
|
|
3026
3030
|
labels: B,
|
|
3027
|
-
resolveActivityIcon:
|
|
3031
|
+
resolveActivityIcon: w
|
|
3028
3032
|
}),
|
|
3029
3033
|
/* @__PURE__ */ v(Gn, {
|
|
3030
3034
|
content: t.content,
|
|
3031
|
-
components:
|
|
3035
|
+
components: Oe
|
|
3032
3036
|
}),
|
|
3033
3037
|
t.parts?.map((e, t) => e.type === "image" ? /* @__PURE__ */ v(sn, {
|
|
3034
3038
|
src: e.src,
|
|
3035
3039
|
alt: e.alt
|
|
3036
|
-
}, t) : e.type === "mcp_app" ? /* @__PURE__ */ v(n, { children:
|
|
3040
|
+
}, t) : e.type === "mcp_app" ? /* @__PURE__ */ v(n, { children: M ? M(e) : /* @__PURE__ */ v(mn, {
|
|
3037
3041
|
...e,
|
|
3038
3042
|
title: e.title ?? B.mcpAppDefaultTitle
|
|
3039
3043
|
}) }, t) : null),
|
|
3040
3044
|
t.streaming && /* @__PURE__ */ v(_n, {
|
|
3041
3045
|
steps: s,
|
|
3042
|
-
resolveActivityIcon:
|
|
3046
|
+
resolveActivityIcon: w
|
|
3043
3047
|
}),
|
|
3044
|
-
t.streaming &&
|
|
3048
|
+
t.streaming && Ne && !c && /* @__PURE__ */ y("div", {
|
|
3045
3049
|
className: "bailey-streaming-hint",
|
|
3046
|
-
children: [/* @__PURE__ */ v("span", { children:
|
|
3050
|
+
children: [/* @__PURE__ */ v("span", { children: Ne }), /* @__PURE__ */ v("span", {
|
|
3047
3051
|
className: "bailey-step-spinner",
|
|
3048
3052
|
"aria-hidden": "true"
|
|
3049
3053
|
})]
|
|
@@ -3057,10 +3061,10 @@ function Yn({ chat: e, placeholder: t, replyPlaceholder: r, emptyPlaceholder: i,
|
|
|
3057
3061
|
tooltipDefaultText: B.copyButtonTooltipDefault,
|
|
3058
3062
|
tooltipCopiedText: B.copyButtonTooltipCopied
|
|
3059
3063
|
}),
|
|
3060
|
-
|
|
3061
|
-
value:
|
|
3064
|
+
j !== !1 && e.feedback && e.conversationId && t.serverMessageId && !fe.has(t.serverMessageId) && /* @__PURE__ */ v(jt.Provider, {
|
|
3065
|
+
value: he,
|
|
3062
3066
|
children: /* @__PURE__ */ v(zn, {
|
|
3063
|
-
...
|
|
3067
|
+
...j,
|
|
3064
3068
|
assistantName: o,
|
|
3065
3069
|
messageId: t.serverMessageId,
|
|
3066
3070
|
initialRating: t.feedback?.rating,
|
|
@@ -3068,69 +3072,69 @@ function Yn({ chat: e, placeholder: t, replyPlaceholder: r, emptyPlaceholder: i,
|
|
|
3068
3072
|
onClear: e.feedback.onClear
|
|
3069
3073
|
})
|
|
3070
3074
|
}),
|
|
3071
|
-
|
|
3075
|
+
A?.(t)
|
|
3072
3076
|
]
|
|
3073
3077
|
})
|
|
3074
3078
|
]
|
|
3075
3079
|
})
|
|
3076
3080
|
}, t.id);
|
|
3077
3081
|
}),
|
|
3078
|
-
/* @__PURE__ */ v("div", { ref:
|
|
3082
|
+
/* @__PURE__ */ v("div", { ref: Te })
|
|
3079
3083
|
]
|
|
3080
3084
|
}),
|
|
3081
|
-
|
|
3085
|
+
R && /* @__PURE__ */ y("div", {
|
|
3082
3086
|
className: "bailey-error-banner",
|
|
3083
3087
|
role: "alert",
|
|
3084
|
-
children: [/* @__PURE__ */ v("span", { children:
|
|
3088
|
+
children: [/* @__PURE__ */ v("span", { children: R }), /* @__PURE__ */ y("div", {
|
|
3085
3089
|
className: "bailey-error-actions",
|
|
3086
3090
|
children: [/* @__PURE__ */ v("button", {
|
|
3087
3091
|
type: "button",
|
|
3088
|
-
onClick:
|
|
3092
|
+
onClick: oe,
|
|
3089
3093
|
className: "bailey-retry-button",
|
|
3090
3094
|
children: B.retryButtonText
|
|
3091
3095
|
}), /* @__PURE__ */ v("button", {
|
|
3092
3096
|
type: "button",
|
|
3093
|
-
onClick:
|
|
3097
|
+
onClick: ce,
|
|
3094
3098
|
"aria-label": B.dismissErrorAriaLabel,
|
|
3095
3099
|
className: "bailey-dismiss-button",
|
|
3096
3100
|
children: "✕"
|
|
3097
3101
|
})]
|
|
3098
3102
|
})]
|
|
3099
3103
|
}),
|
|
3100
|
-
!
|
|
3101
|
-
events:
|
|
3102
|
-
lastRequest:
|
|
3103
|
-
onClear:
|
|
3104
|
+
!k && /* @__PURE__ */ v(on, {
|
|
3105
|
+
events: re,
|
|
3106
|
+
lastRequest: I,
|
|
3107
|
+
onClear: se
|
|
3104
3108
|
}),
|
|
3105
3109
|
/* @__PURE__ */ y("div", {
|
|
3106
3110
|
className: "bailey-input-area",
|
|
3107
3111
|
children: [/* @__PURE__ */ y("form", {
|
|
3108
3112
|
onSubmit: (e) => {
|
|
3109
|
-
e.preventDefault(),
|
|
3113
|
+
e.preventDefault(), ue.trim() && L !== "streaming" && (Pe(ue), de(""));
|
|
3110
3114
|
},
|
|
3111
3115
|
className: "bailey-input-row",
|
|
3112
3116
|
children: [/* @__PURE__ */ v("input", {
|
|
3113
|
-
ref:
|
|
3117
|
+
ref: ye,
|
|
3114
3118
|
type: "text",
|
|
3115
|
-
placeholder:
|
|
3116
|
-
"aria-label":
|
|
3117
|
-
value:
|
|
3118
|
-
onChange: (e) =>
|
|
3119
|
-
disabled:
|
|
3119
|
+
placeholder: X,
|
|
3120
|
+
"aria-label": X,
|
|
3121
|
+
value: ue,
|
|
3122
|
+
onChange: (e) => de(e.target.value),
|
|
3123
|
+
disabled: L === "streaming",
|
|
3120
3124
|
className: "bailey-input"
|
|
3121
|
-
}),
|
|
3125
|
+
}), L === "streaming" ? /* @__PURE__ */ v(g.Provider, {
|
|
3122
3126
|
delayDuration: 200,
|
|
3123
3127
|
children: /* @__PURE__ */ y(g.Root, { children: [/* @__PURE__ */ v(g.Trigger, {
|
|
3124
3128
|
asChild: !0,
|
|
3125
3129
|
children: /* @__PURE__ */ v("button", {
|
|
3126
3130
|
type: "button",
|
|
3127
|
-
onClick:
|
|
3131
|
+
onClick: ae,
|
|
3128
3132
|
"aria-label": B.stopAriaLabel,
|
|
3129
3133
|
className: "bailey-stop-button",
|
|
3130
3134
|
children: /* @__PURE__ */ v(Pt, { className: "bailey-stop-icon" })
|
|
3131
3135
|
})
|
|
3132
3136
|
}), /* @__PURE__ */ v(g.Portal, {
|
|
3133
|
-
container:
|
|
3137
|
+
container: we instanceof ShadowRoot ? we : void 0,
|
|
3134
3138
|
children: /* @__PURE__ */ y(g.Content, {
|
|
3135
3139
|
side: "top",
|
|
3136
3140
|
className: "bailey-tooltip-content",
|
|
@@ -3140,36 +3144,36 @@ function Yn({ chat: e, placeholder: t, replyPlaceholder: r, emptyPlaceholder: i,
|
|
|
3140
3144
|
}) : /* @__PURE__ */ v("button", {
|
|
3141
3145
|
type: "submit",
|
|
3142
3146
|
"aria-label": B.sendAriaLabel,
|
|
3143
|
-
disabled: !
|
|
3147
|
+
disabled: !ue.trim(),
|
|
3144
3148
|
className: "bailey-send-button",
|
|
3145
|
-
children:
|
|
3149
|
+
children: T ?? /* @__PURE__ */ v(Nt, { className: "bailey-send-icon" })
|
|
3146
3150
|
})]
|
|
3147
|
-
}), !m && (!
|
|
3151
|
+
}), !m && (!Y || W) && /* @__PURE__ */ y(h.Root, { children: [/* @__PURE__ */ v(h.Trigger, {
|
|
3148
3152
|
asChild: !0,
|
|
3149
3153
|
children: /* @__PURE__ */ v("button", {
|
|
3150
3154
|
type: "button",
|
|
3151
|
-
ref:
|
|
3155
|
+
ref: be,
|
|
3152
3156
|
"aria-label": B.menuAriaLabel,
|
|
3153
3157
|
className: "bailey-menu-button",
|
|
3154
3158
|
children: /* @__PURE__ */ v(Bt, { className: "bailey-menu-icon" })
|
|
3155
3159
|
})
|
|
3156
3160
|
}), /* @__PURE__ */ v(h.Portal, {
|
|
3157
|
-
container:
|
|
3161
|
+
container: we instanceof ShadowRoot ? we : void 0,
|
|
3158
3162
|
children: /* @__PURE__ */ y(h.Content, {
|
|
3159
3163
|
side: "top",
|
|
3160
3164
|
align: "end",
|
|
3161
3165
|
sideOffset: 8,
|
|
3162
3166
|
className: "bailey-menu-content",
|
|
3163
3167
|
onCloseAutoFocus: (e) => {
|
|
3164
|
-
|
|
3168
|
+
U.current &&= (e.preventDefault(), !1);
|
|
3165
3169
|
},
|
|
3166
|
-
children: [!
|
|
3167
|
-
onSelect: () =>
|
|
3170
|
+
children: [!Y && /* @__PURE__ */ y(h.Item, {
|
|
3171
|
+
onSelect: () => le(),
|
|
3168
3172
|
className: "bailey-menu-item",
|
|
3169
3173
|
children: [/* @__PURE__ */ v(Vt, { className: "bailey-menu-item-icon" }), B.newChatButtonText]
|
|
3170
|
-
}),
|
|
3174
|
+
}), W && /* @__PURE__ */ y(h.Item, {
|
|
3171
3175
|
onSelect: () => {
|
|
3172
|
-
_ ? _() : (
|
|
3176
|
+
_ ? _() : (U.current = !0, $(!0));
|
|
3173
3177
|
},
|
|
3174
3178
|
className: "bailey-menu-item",
|
|
3175
3179
|
children: [/* @__PURE__ */ v(Rt, { className: "bailey-menu-item-icon" }), B.historyMenuItemText]
|
|
@@ -3177,23 +3181,23 @@ function Yn({ chat: e, placeholder: t, replyPlaceholder: r, emptyPlaceholder: i,
|
|
|
3177
3181
|
})
|
|
3178
3182
|
})] })]
|
|
3179
3183
|
}),
|
|
3180
|
-
(
|
|
3184
|
+
(Y || C?.alwaysVisible) && C && /* @__PURE__ */ v("div", {
|
|
3181
3185
|
className: "bailey-privacy-note",
|
|
3182
3186
|
children: /* @__PURE__ */ v(p, {
|
|
3183
3187
|
remarkPlugins: Un,
|
|
3184
3188
|
components: Wn,
|
|
3185
3189
|
skipHtml: !0,
|
|
3186
|
-
children:
|
|
3190
|
+
children: C.markdown
|
|
3187
3191
|
})
|
|
3188
3192
|
})
|
|
3189
3193
|
]
|
|
3190
|
-
}),
|
|
3194
|
+
}), Q && /* @__PURE__ */ v(En, {
|
|
3191
3195
|
client: b.client,
|
|
3192
3196
|
pageSize: b.pageSize,
|
|
3193
3197
|
chat: e,
|
|
3194
3198
|
labels: B,
|
|
3195
|
-
locale:
|
|
3196
|
-
onClose:
|
|
3199
|
+
locale: S,
|
|
3200
|
+
onClose: Ie
|
|
3197
3201
|
})]
|
|
3198
3202
|
})
|
|
3199
3203
|
})
|
|
@@ -3201,4 +3205,4 @@ function Yn({ chat: e, placeholder: t, replyPlaceholder: r, emptyPlaceholder: i,
|
|
|
3201
3205
|
}
|
|
3202
3206
|
// src/index.ts
|
|
3203
3207
|
var Xn = "0.3.1-pre.2";
|
|
3204
|
-
export { zt as ActivityIcon, Ft as ArrowUpRightIcon, Xn as BAILEYAI_CHAT_UI_VERSION, We as BAILEY_CHART_PROMPT_FRAGMENT, Ie as BAILEY_TABLE_GRID_ROW_THRESHOLD, j as BaileyApiError, Yn as BaileyChatPanel, M as BaileyCleanupError, zn as BaileyFeedbackButtons, En as BaileyHistoryDrawer, on as BaileyTracePanel, Xt as CopyMarkdownButton,
|
|
3208
|
+
export { zt as ActivityIcon, Ft as ArrowUpRightIcon, Xn as BAILEYAI_CHAT_UI_VERSION, We as BAILEY_CHART_PROMPT_FRAGMENT, Ie as BAILEY_TABLE_GRID_ROW_THRESHOLD, j as BaileyApiError, Yn as BaileyChatPanel, M as BaileyCleanupError, zn as BaileyFeedbackButtons, En as BaileyHistoryDrawer, on as BaileyTracePanel, Xt as CopyMarkdownButton, ae as DEFAULT_CONVERSATION_STORAGE_KEY, Nt as HeartIcon, Qe as TRACE_KIND_LABEL, Gt as ThumbDownIcon, Wt as ThumbUpIcon, Pe as createBaileyClient, ie as createBaileyFeedbackHandlers, Mt as createBaileyMarkdownComponents, se as createMemoryConversationStorage, oe as createSessionConversationStorage, O as extractPseudoToolCalls, He as extractTableData, Tn as formatRelativeTime, ct as formatTraceGap, st as formatTraceTime, ft as hasTraceFailure, R as isConversationIdForSub, e as isSafeMarkdownUrl, Z as joinInstructions, re as mapTranscript, L as mergeEarlierPage, Ze as parseBaileyChartSpec, A as parseSseFrames, $ as resolveToolCall, Ue as shouldUseGrid, pt as toActivityLines, mt as toToolSteps, lt as toTraceRows, dt as toTraceSegments, nt as traceEventArgsDetail, ot as traceEventHint, rt as traceEventOutputDetail, at as traceEventRawDetail, tt as traceEventSummary, et as traceEventToolName, ut as traceSummaryLine, ye as useBaileyChat, xe as useBaileyConversations };
|