@webority/chat-react 0.30.0 → 0.31.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.
@@ -1,269 +1,82 @@
1
- import { AppActionIcon as e, AppAlert as t, AppButton as n, AppCard as r, AppConfirmDialog as i, AppDataTable as a, AppEmptyState as o, AppIcon as s, AppLink as c, AppSidebarMenu as l, AppSkeleton as u, AppSpinner as d, AppTextarea as f } from "@webority/ui-react";
2
- import { Fragment as p, useCallback as m, useEffect as h, useId as g, useRef as _, useState as v } from "react";
3
- import { Fragment as y, jsx as b, jsxs as x } from "react/jsx-runtime";
4
- //#region src/lib/sse.js
5
- function S(e) {
6
- let t = "";
7
- function n(t) {
8
- let n = "message", r = [];
9
- for (let e of t.split("\n")) {
10
- if (e === "" || e.startsWith(":")) continue;
11
- let t = e.indexOf(":"), i = t === -1 ? e : e.slice(0, t), a = t === -1 ? "" : e.slice(t + 1);
12
- a.startsWith(" ") && (a = a.slice(1)), i === "event" ? n = a : i === "data" && r.push(a);
13
- }
14
- if (r.length === 0) return;
15
- let i;
16
- try {
17
- i = JSON.parse(r.join("\n"));
18
- } catch {
19
- e({
20
- name: "error",
21
- data: {
22
- code: "invalid-response",
23
- message: null
24
- }
25
- });
26
- return;
27
- }
28
- e({
29
- name: n,
30
- data: i
31
- });
32
- }
33
- return {
34
- push(e) {
35
- if (!e) return;
36
- t = (t + e).replace(/\r\n/g, "\n").replace(/\r(?!$)/g, "\n");
37
- let r = t.split("\n\n");
38
- t = r.pop();
39
- for (let e of r) n(e);
40
- },
41
- end() {
42
- let e = t.replace(/\r$/, "");
43
- t = "", e.trim() && n(e);
44
- }
45
- };
46
- }
47
- //#endregion
48
- //#region src/client.js
49
- var C = "Something went wrong. Please try again.", w = class extends Error {
50
- constructor(e, t, n, r = null) {
51
- super(t), this.name = "ChatApiError", this.code = e, this.status = n, this.resetsAtUtc = r;
52
- }
53
- };
54
- function T(e) {
55
- if (typeof e == "string") try {
56
- return JSON.parse(e);
57
- } catch {
58
- return null;
59
- }
60
- return e ?? null;
61
- }
62
- function E(e, t) {
63
- return t?.aborted || e?.code === "ERR_CANCELED" || e?.name === "CanceledError" || e?.name === "AbortError";
64
- }
65
- function D(e, t) {
66
- if (e instanceof w) return e;
67
- if (E(e, t)) return new w("aborted", "The request was cancelled.");
68
- let n = e?.response;
69
- if (!n) return new w("network", C);
70
- let r = T(n.data), i = typeof r?.code == "string" && r.code ? r.code : "unknown", a = typeof r?.message == "string" && r.message ? r.message : C, o = typeof r?.resetsAtUtc == "string" ? r.resetsAtUtc : null;
71
- return new w(i, a, n.status, o);
72
- }
73
- async function O(e) {
74
- try {
75
- return (await e()).data;
76
- } catch (e) {
77
- throw D(e);
78
- }
79
- }
80
- function k(e) {
81
- let t = e?.event?.target;
82
- if (!(!t || typeof t.responseText != "string") && !(typeof t.status == "number" && (t.status < 200 || t.status >= 300))) return t.responseText;
83
- }
84
- function A(e, { base: t }) {
85
- if (typeof t != "string" || t.trim() === "") throw TypeError("createChatClient needs a base path, e.g. { base: \"/api/assistant\" }.");
86
- let n = t.replace(/\/+$/, ""), r = (e) => `${n}/conversations/${encodeURIComponent(e)}`;
87
- async function i({ message: t, conversationId: r, pageContext: i }, { signal: a, onEvent: o } = {}) {
88
- let s = null, c = null, l = S(({ name: e, data: t }) => {
89
- s || c || (e === "done" ? s = t : e === "error" ? c = t : (e === "delta" || e === "reset" || e === "actions") && o?.(e, t));
90
- }), u = 0, d = (e) => {
91
- typeof e != "string" || e.length <= u || (l.push(e.slice(u)), u = e.length);
92
- }, f = { message: t };
93
- r && (f.conversationId = r), i != null && (f.pageContext = i);
94
- let p;
95
- try {
96
- p = await e.post(`${n}/chat`, f, {
97
- responseType: "text",
98
- headers: { Accept: "text/event-stream" },
99
- signal: a,
100
- onDownloadProgress: (e) => d(k(e))
101
- });
102
- } catch (e) {
103
- throw D(e, a);
104
- }
105
- if (d(p.data), l.end(), c) throw new w(c.code || "unknown", c.message || C);
106
- if (!s) throw new w("invalid-response", C, p.status);
107
- return s;
108
- }
109
- return {
110
- sendMessage: i,
111
- getAllowance: () => O(() => e.get(`${n}/allowance`)),
112
- listConversations: ({ skip: t, take: r } = {}) => {
113
- let i = new URLSearchParams();
114
- t != null && i.append("skip", String(t)), r != null && i.append("take", String(r));
115
- let a = i.toString();
116
- return O(() => e.get(`${n}/conversations${a ? `?${a}` : ""}`));
117
- },
118
- getConversation: (t) => O(() => e.get(r(t))),
119
- deleteConversation: async (t) => {
120
- await O(() => e.delete(r(t)));
121
- },
122
- rateMessage: async (t, n, { rating: i, note: a }) => {
123
- let o = typeof a == "string" ? a.trim() : "";
124
- await O(() => e.put(`${r(t)}/messages/${encodeURIComponent(n)}/rating`, {
125
- rating: i,
126
- note: o || null
127
- }));
128
- }
129
- };
130
- }
131
- //#endregion
132
- //#region src/labels.js
133
- var j = Object.freeze({
134
- launcher: "Ask the assistant",
135
- panelTitle: "Assistant",
136
- newChat: "New chat",
137
- close: "Close",
138
- thread: "Conversation",
139
- you: "You",
140
- assistant: "Assistant",
141
- thinking: "Thinking",
142
- emptyTitle: "How can I help?",
143
- emptyText: "Ask a question about what you see on this page.",
144
- composer: "Your question",
145
- placeholder: "Ask a question",
146
- send: "Send",
147
- composerHint: "Press Enter to send, Shift and Enter for a new line.",
148
- allowance: (e) => e === 0 ? "You have no questions left today." : e === 1 ? "You have 1 question left today." : `You have ${e} questions left today.`,
149
- disclaimer: "Answers are written by AI and can be wrong. Check anything important.",
150
- loadingConversation: "Loading the conversation",
151
- rateUp: "Helpful",
152
- rateDown: "Not helpful",
153
- rated: "Thanks for the feedback.",
154
- ratingNote: "What was wrong with this answer?",
155
- ratingNoteHint: "Optional.",
156
- ratingNoteSend: "Send",
157
- ratingNoteSkip: "Skip",
158
- ratingFailed: "Your rating did not save. Please try again.",
159
- actionRaiseTicket: "New support ticket",
160
- actionReply: (e) => `Reply on ${e}`,
161
- actionReopen: (e) => `Reopen ${e}`,
162
- actionNote: "Nothing is sent until you confirm.",
163
- actionConfirm: "Confirm",
164
- actionDismiss: "Not now",
165
- actionDismissed: "Not sent.",
166
- actionExpired: "This request expired and was not sent. Ask again if you still need it.",
167
- actionFailed: "We could not send this. Please try again.",
168
- actionDoneRaiseTicket: (e) => `Ticket ${e} raised.`,
169
- actionDoneReply: (e) => `Your reply was added to ${e}.`,
170
- actionDoneReopen: (e) => `${e} is open again.`,
171
- viewTicket: "View ticket",
172
- conversations: "Past chats",
173
- conversationsEmptyTitle: "No past chats",
174
- conversationsEmptyText: "Your conversations with the assistant show here.",
175
- untitled: "Untitled chat",
176
- deleteConversation: "Delete chat",
177
- deleteConfirmTitle: "Delete this chat?",
178
- deleteConfirmMessage: "The conversation is removed for good.",
179
- deleteConfirm: "Delete",
180
- deleteFailed: "We could not delete this chat. Please try again.",
181
- cancel: "Cancel",
182
- loadMore: "Show more",
183
- loadFailed: "We could not load your chats. Please try again.",
184
- retry: "Try again"
185
- });
186
- function M(e) {
187
- return e ? {
188
- ...j,
189
- ...e
190
- } : j;
191
- }
192
- //#endregion
1
+ import { ChatApiError as e, DEFAULT_CHAT_LABELS as t, createChatClient as n, createSseParser as r, linkRoute as i, mergeLabels as a, parseBlocks as o, parseInline as s } from "@webority/ui-elements/chat-core";
2
+ import { AppActionIcon as c, AppAlert as l, AppButton as u, AppCard as d, AppConfirmDialog as f, AppDataTable as p, AppEmptyState as m, AppIcon as h, AppLink as g, AppSidebarMenu as _, AppSkeleton as v, AppSpinner as y, AppTextarea as b, useFloatingStack as x } from "@webority/ui-react";
3
+ import { Fragment as S, useCallback as C, useEffect as w, useId as T, useRef as E, useState as D } from "react";
4
+ import { Fragment as O, jsx as k, jsxs as A } from "react/jsx-runtime";
5
+ import { createPortal as j } from "react-dom";
193
6
  //#region src/components/ActionCard.jsx
194
- function N(e, t) {
7
+ function M(e, t) {
195
8
  return e.kind === "Reply" ? t.actionReply(e.ticketNumber) : e.kind === "Reopen" ? t.actionReopen(e.ticketNumber) : t.actionRaiseTicket;
196
9
  }
197
- function P(e, t, n) {
10
+ function N(e, t, n) {
198
11
  return e === "Reply" ? n.actionDoneReply(t) : e === "Reopen" ? n.actionDoneReopen(t) : n.actionDoneRaiseTicket(t);
199
12
  }
200
- function F({ action: e, confirmAction: i, onViewTicket: a, labels: o }) {
201
- let s = M(o), [c, l] = v("ready"), [u, d] = v(null), [f, p] = v("");
202
- if (c === "dismissed") return /* @__PURE__ */ b("p", {
13
+ function P({ action: e, confirmAction: t, onViewTicket: n, labels: r }) {
14
+ let i = a(r), [o, s] = D("ready"), [c, f] = D(null), [p, m] = D("");
15
+ if (o === "dismissed") return /* @__PURE__ */ k("p", {
203
16
  className: "wui-text-sm text-body-secondary mb-0",
204
- children: s.actionDismissed
17
+ children: i.actionDismissed
205
18
  });
206
- if (c === "done") return /* @__PURE__ */ b(t, {
19
+ if (o === "done") return /* @__PURE__ */ k(l, {
207
20
  variant: "success",
208
21
  role: "status",
209
22
  size: "sm",
210
- action: a ? /* @__PURE__ */ b(n, {
23
+ action: n ? /* @__PURE__ */ k(u, {
211
24
  size: "sm",
212
25
  variant: "ghost",
213
- onClick: () => a(u),
214
- children: s.viewTicket
26
+ onClick: () => n(c),
27
+ children: i.viewTicket
215
28
  }) : void 0,
216
- children: P(e.kind, u.number, s)
29
+ children: N(e.kind, c.number, i)
217
30
  });
218
- async function m() {
219
- l("sending"), p("");
31
+ async function h() {
32
+ s("sending"), m("");
220
33
  try {
221
- d(await i(e.token)), l("done");
34
+ f(await t(e.token)), s("done");
222
35
  } catch (e) {
223
- p(e?.message || s.actionFailed), l("ready");
36
+ m(e?.message || i.actionFailed), s("ready");
224
37
  }
225
38
  }
226
- let h = c === "sending", g = new Date(e.expiresDateTimeUtc).getTime() <= Date.now(), _ = e.kind === "RaiseTicket" ? [e.category, e.subject].filter(Boolean).join(" · ") : "";
227
- return /* @__PURE__ */ b(r, {
39
+ let g = o === "sending", _ = new Date(e.expiresDateTimeUtc).getTime() <= Date.now(), v = e.kind === "RaiseTicket" ? [e.category, e.subject].filter(Boolean).join(" · ") : "";
40
+ return /* @__PURE__ */ k(d, {
228
41
  padding: "sm",
229
42
  className: "border",
230
- title: N(e, s),
231
- subtitle: _ || void 0,
232
- children: /* @__PURE__ */ x("div", {
43
+ title: M(e, i),
44
+ subtitle: v || void 0,
45
+ children: /* @__PURE__ */ A("div", {
233
46
  className: "d-flex flex-column gap-2",
234
- children: [e.kind !== "Reopen" && e.body && /* @__PURE__ */ b("p", {
47
+ children: [e.kind !== "Reopen" && e.body && /* @__PURE__ */ k("p", {
235
48
  className: "wui-text-sm mb-0",
236
49
  style: {
237
50
  whiteSpace: "pre-wrap",
238
51
  overflowWrap: "anywhere"
239
52
  },
240
53
  children: e.body
241
- }), g ? /* @__PURE__ */ b("p", {
54
+ }), _ ? /* @__PURE__ */ k("p", {
242
55
  className: "wui-text-sm text-body-secondary mb-0",
243
- children: s.actionExpired
244
- }) : /* @__PURE__ */ x(y, { children: [
245
- /* @__PURE__ */ b("p", {
56
+ children: i.actionExpired
57
+ }) : /* @__PURE__ */ A(O, { children: [
58
+ /* @__PURE__ */ k("p", {
246
59
  className: "wui-text-xs text-body-secondary mb-0",
247
- children: s.actionNote
60
+ children: i.actionNote
248
61
  }),
249
- f && /* @__PURE__ */ b(t, {
62
+ p && /* @__PURE__ */ k(l, {
250
63
  size: "sm",
251
64
  variant: "danger",
252
- children: f
65
+ children: p
253
66
  }),
254
- /* @__PURE__ */ x("div", {
67
+ /* @__PURE__ */ A("div", {
255
68
  className: "d-flex flex-wrap gap-2",
256
- children: [/* @__PURE__ */ b(n, {
69
+ children: [/* @__PURE__ */ k(u, {
257
70
  size: "sm",
258
- loading: h,
259
- onClick: m,
260
- children: s.actionConfirm
261
- }), /* @__PURE__ */ b(n, {
71
+ loading: g,
72
+ onClick: h,
73
+ children: i.actionConfirm
74
+ }), /* @__PURE__ */ k(u, {
262
75
  size: "sm",
263
76
  variant: "secondary",
264
- disabled: h,
265
- onClick: () => l("dismissed"),
266
- children: s.actionDismiss
77
+ disabled: g,
78
+ onClick: () => s("dismissed"),
79
+ children: i.actionDismiss
267
80
  })]
268
81
  })
269
82
  ] })]
@@ -272,45 +85,45 @@ function F({ action: e, confirmAction: i, onViewTicket: a, labels: o }) {
272
85
  }
273
86
  //#endregion
274
87
  //#region src/components/ChatComposer.jsx
275
- function I({ onSubmit: e, busy: t = !1, disabled: r = !1, maxLength: i = 4e3, inputRef: a, labels: o }) {
276
- let s = M(o), c = g(), [l, u] = v(""), d = t || r || !l.trim();
88
+ function F({ onSubmit: e, busy: t = !1, disabled: n = !1, maxLength: r = 4e3, inputRef: i, labels: o }) {
89
+ let s = a(o), c = T(), [l, d] = D(""), f = t || n || !l.trim();
277
90
  function p() {
278
- d || (e(l.trim()), u(""));
91
+ f || (e(l.trim()), d(""));
279
92
  }
280
- return /* @__PURE__ */ x("form", {
93
+ return /* @__PURE__ */ A("form", {
281
94
  className: "d-flex align-items-end gap-2",
282
95
  "aria-label": s.composer,
283
96
  onSubmit: (e) => {
284
97
  e.preventDefault(), p();
285
98
  },
286
99
  children: [
287
- /* @__PURE__ */ b(f, {
100
+ /* @__PURE__ */ k(b, {
288
101
  id: `${c}-message`,
289
102
  "aria-label": s.composer,
290
103
  "aria-describedby": `${c}-hint`,
291
104
  placeholder: s.placeholder,
292
105
  rows: 1,
293
106
  autoGrow: !0,
294
- maxLength: i,
107
+ maxLength: r,
295
108
  value: l,
296
- disabled: r,
297
- ref: a,
109
+ disabled: n,
110
+ ref: i,
298
111
  fieldClassName: "flex-grow-1 mb-0",
299
- onChange: (e) => u(e.target.value),
112
+ onChange: (e) => d(e.target.value),
300
113
  onKeyDown: (e) => {
301
114
  e.key === "Enter" && !e.shiftKey && !e.nativeEvent.isComposing && (e.preventDefault(), p());
302
115
  }
303
116
  }),
304
- /* @__PURE__ */ b("span", {
117
+ /* @__PURE__ */ k("span", {
305
118
  id: `${c}-hint`,
306
119
  className: "visually-hidden",
307
120
  children: s.composerHint
308
121
  }),
309
- /* @__PURE__ */ b(n, {
122
+ /* @__PURE__ */ k(u, {
310
123
  type: "submit",
311
124
  leftIcon: "send",
312
- disabled: d,
313
- children: /* @__PURE__ */ b("span", {
125
+ disabled: f,
126
+ children: /* @__PURE__ */ k("span", {
314
127
  className: "visually-hidden",
315
128
  children: s.send
316
129
  })
@@ -320,7 +133,7 @@ function I({ onSubmit: e, busy: t = !1, disabled: r = !1, maxLength: i = 4e3, in
320
133
  }
321
134
  //#endregion
322
135
  //#region src/lib/format.js
323
- var ee = new Intl.DateTimeFormat("en-IN", {
136
+ var I = new Intl.DateTimeFormat("en-IN", {
324
137
  day: "2-digit",
325
138
  month: "numeric",
326
139
  year: "numeric",
@@ -328,7 +141,7 @@ var ee = new Intl.DateTimeFormat("en-IN", {
328
141
  minute: "2-digit",
329
142
  hour12: !0,
330
143
  timeZoneName: "short"
331
- }), te = [
144
+ }), L = [
332
145
  "Jan",
333
146
  "Feb",
334
147
  "Mar",
@@ -342,128 +155,128 @@ var ee = new Intl.DateTimeFormat("en-IN", {
342
155
  "Nov",
343
156
  "Dec"
344
157
  ];
345
- function ne(e) {
158
+ function R(e) {
346
159
  if (!e) return "-";
347
160
  let t = new Date(e);
348
161
  if (Number.isNaN(t.getTime())) return "-";
349
- let n = Object.fromEntries(ee.formatToParts(t).map((e) => [e.type, e.value]));
350
- return `${n.day} ${te[Number(n.month) - 1]} ${n.year}, ${n.hour}:${n.minute} ${n.dayPeriod.toLowerCase()} ${n.timeZoneName}`;
162
+ let n = Object.fromEntries(I.formatToParts(t).map((e) => [e.type, e.value]));
163
+ return `${n.day} ${L[Number(n.month) - 1]} ${n.year}, ${n.hour}:${n.minute} ${n.dayPeriod.toLowerCase()} ${n.timeZoneName}`;
351
164
  }
352
165
  //#endregion
353
166
  //#region src/components/ChatConversationList.jsx
354
- function re({ client: a, onOpen: s, onDeleted: c, pageSize: l = 20, labels: d }) {
355
- let f = M(d), [p, g] = v([]), [_, y] = v(!0), [S, C] = v(""), [w, T] = v(!1), [E, D] = v(0), [O, k] = v(null), [A, j] = v(!1), [N, P] = v(""), F = m(async (e) => {
356
- y(!0), C("");
167
+ function z({ client: e, onOpen: t, onDeleted: n, pageSize: r = 20, labels: i }) {
168
+ let o = a(i), [s, p] = D([]), [h, g] = D(!0), [_, y] = D(""), [b, x] = D(!1), [S, T] = D(0), [E, O] = D(null), [j, M] = D(!1), [N, P] = D(""), F = C(async (t) => {
169
+ g(!0), y("");
357
170
  try {
358
- let t = await a.listConversations({
359
- skip: e,
360
- take: l
171
+ let n = await e.listConversations({
172
+ skip: t,
173
+ take: r
361
174
  });
362
- g((n) => e === 0 ? t : [...n, ...t]), T(t.length === l);
175
+ p((e) => t === 0 ? n : [...e, ...n]), x(n.length === r);
363
176
  } catch (e) {
364
- C(e?.message || f.loadFailed);
177
+ y(e?.message || o.loadFailed);
365
178
  } finally {
366
- y(!1);
179
+ g(!1);
367
180
  }
368
181
  }, [
369
- a,
370
- l,
371
- f.loadFailed
182
+ e,
183
+ r,
184
+ o.loadFailed
372
185
  ]);
373
- h(() => {
186
+ w(() => {
374
187
  F(0);
375
- }, [F, E]);
188
+ }, [F, S]);
376
189
  async function I() {
377
- j(!0), P("");
190
+ M(!0), P("");
378
191
  try {
379
- await a.deleteConversation(O.publicId), g((e) => e.filter((e) => e.publicId !== O.publicId)), c?.(O.publicId), k(null);
192
+ await e.deleteConversation(E.publicId), p((e) => e.filter((e) => e.publicId !== E.publicId)), n?.(E.publicId), O(null);
380
193
  } catch (e) {
381
- P(e?.message || f.deleteFailed);
194
+ P(e?.message || o.deleteFailed);
382
195
  } finally {
383
- j(!1);
196
+ M(!1);
384
197
  }
385
198
  }
386
- return !_ && !S && p.length === 0 ? /* @__PURE__ */ b(o, {
199
+ return !h && !_ && s.length === 0 ? /* @__PURE__ */ k(m, {
387
200
  icon: "chat",
388
201
  size: "sm",
389
- title: f.conversationsEmptyTitle,
390
- text: f.conversationsEmptyText
391
- }) : /* @__PURE__ */ x("div", {
202
+ title: o.conversationsEmptyTitle,
203
+ text: o.conversationsEmptyText
204
+ }) : /* @__PURE__ */ A("div", {
392
205
  className: "d-flex flex-column gap-3",
393
206
  children: [
394
- S && /* @__PURE__ */ b(t, {
207
+ _ && /* @__PURE__ */ k(l, {
395
208
  variant: "danger",
396
- action: /* @__PURE__ */ b(n, {
209
+ action: /* @__PURE__ */ k(u, {
397
210
  size: "sm",
398
211
  variant: "secondary",
399
- onClick: () => D((e) => e + 1),
400
- children: f.retry
212
+ onClick: () => T((e) => e + 1),
213
+ children: o.retry
401
214
  }),
402
- children: S
215
+ children: _
403
216
  }),
404
- p.length > 0 && /* @__PURE__ */ b("ul", {
217
+ s.length > 0 && /* @__PURE__ */ k("ul", {
405
218
  className: "list-unstyled d-flex flex-column gap-2 mb-0",
406
- "aria-label": f.conversations,
407
- children: p.map((t) => /* @__PURE__ */ b("li", { children: /* @__PURE__ */ x(r, {
219
+ "aria-label": o.conversations,
220
+ children: s.map((e) => /* @__PURE__ */ k("li", { children: /* @__PURE__ */ A(d, {
408
221
  padding: "sm",
409
222
  className: "border",
410
223
  bodyClassName: "d-flex align-items-center gap-2",
411
- children: [/* @__PURE__ */ b(n, {
224
+ children: [/* @__PURE__ */ k(u, {
412
225
  variant: "ghost",
413
226
  className: "flex-grow-1 text-start",
414
227
  style: { minWidth: 0 },
415
- onClick: () => s(t),
416
- children: /* @__PURE__ */ x("span", {
228
+ onClick: () => t(e),
229
+ children: /* @__PURE__ */ A("span", {
417
230
  className: "d-flex flex-column",
418
231
  style: { minWidth: 0 },
419
- children: [/* @__PURE__ */ b("span", {
232
+ children: [/* @__PURE__ */ k("span", {
420
233
  className: "text-truncate fw-semibold",
421
- children: t.title || f.untitled
422
- }), /* @__PURE__ */ b("time", {
423
- dateTime: t.lastMessageDateTimeUtc,
234
+ children: e.title || o.untitled
235
+ }), /* @__PURE__ */ k("time", {
236
+ dateTime: e.lastMessageDateTimeUtc,
424
237
  className: "wui-text-xs text-body-secondary",
425
- children: ne(t.lastMessageDateTimeUtc)
238
+ children: R(e.lastMessageDateTimeUtc)
426
239
  })]
427
240
  })
428
- }), /* @__PURE__ */ b(e, {
241
+ }), /* @__PURE__ */ k(c, {
429
242
  icon: "trash-2",
430
243
  danger: !0,
431
- label: f.deleteConversation,
244
+ label: o.deleteConversation,
432
245
  onClick: () => {
433
- P(""), k(t);
246
+ P(""), O(e);
434
247
  }
435
248
  })]
436
- }) }, t.publicId))
249
+ }) }, e.publicId))
437
250
  }),
438
- _ && /* @__PURE__ */ x("div", {
251
+ h && /* @__PURE__ */ A("div", {
439
252
  className: "d-flex flex-column gap-2",
440
253
  "aria-hidden": "true",
441
254
  children: [
442
- /* @__PURE__ */ b(u, { height: 44 }),
443
- /* @__PURE__ */ b(u, { height: 44 }),
444
- /* @__PURE__ */ b(u, { height: 44 })
255
+ /* @__PURE__ */ k(v, { height: 44 }),
256
+ /* @__PURE__ */ k(v, { height: 44 }),
257
+ /* @__PURE__ */ k(v, { height: 44 })
445
258
  ]
446
259
  }),
447
- !_ && w && /* @__PURE__ */ b(n, {
260
+ !h && b && /* @__PURE__ */ k(u, {
448
261
  variant: "secondary",
449
262
  className: "align-self-center",
450
- onClick: () => F(p.length),
451
- children: f.loadMore
263
+ onClick: () => F(s.length),
264
+ children: o.loadMore
452
265
  }),
453
- /* @__PURE__ */ b(i, {
454
- open: O !== null,
455
- title: f.deleteConfirmTitle,
456
- message: N ? /* @__PURE__ */ b(t, {
266
+ /* @__PURE__ */ k(f, {
267
+ open: E !== null,
268
+ title: o.deleteConfirmTitle,
269
+ message: N ? /* @__PURE__ */ k(l, {
457
270
  variant: "danger",
458
271
  children: N
459
- }) : f.deleteConfirmMessage,
460
- confirmLabel: f.deleteConfirm,
461
- cancelLabel: f.cancel,
272
+ }) : o.deleteConfirmMessage,
273
+ confirmLabel: o.deleteConfirm,
274
+ cancelLabel: o.cancel,
462
275
  danger: !0,
463
- loading: A,
276
+ loading: j,
464
277
  onConfirm: I,
465
278
  onClose: () => {
466
- A || k(null);
279
+ j || O(null);
467
280
  }
468
281
  })
469
282
  ]
@@ -471,256 +284,129 @@ function re({ client: a, onOpen: s, onDeleted: c, pageSize: l = 20, labels: d })
471
284
  }
472
285
  //#endregion
473
286
  //#region src/components/ChatLauncher.jsx
474
- var ie = {
287
+ var B = {
475
288
  zIndex: "var(--wui-z-fixed)",
476
289
  bottom: 0
477
- }, ae = {
290
+ }, V = {
478
291
  end: { insetInlineEnd: 0 },
479
292
  start: { insetInlineStart: 0 }
480
293
  };
481
- function oe({ onClick: e, open: t = !1, position: r = "end", icon: i = "sparkles", className: a, style: o, labels: s }) {
482
- let c = M(s);
483
- return /* @__PURE__ */ b("span", {
294
+ function H({ onClick: e, open: t = !1, position: n = "end", icon: r = "sparkles", compact: i = !1, className: o, style: s, labels: c }) {
295
+ let l = a(c);
296
+ return i ? /* @__PURE__ */ k(U, {
297
+ onClick: e,
298
+ open: t,
299
+ position: n,
300
+ icon: r,
301
+ className: o,
302
+ style: s,
303
+ label: l.launcher
304
+ }) : /* @__PURE__ */ k("span", {
484
305
  "data-support-capture": "exclude",
485
- className: ["position-fixed m-3", a].filter(Boolean).join(" "),
306
+ className: ["position-fixed m-3", o].filter(Boolean).join(" "),
486
307
  style: {
487
- ...ie,
488
- ...ae[r],
489
- ...o
308
+ ...B,
309
+ ...V[n],
310
+ ...s
490
311
  },
491
- children: /* @__PURE__ */ b(n, {
492
- leftIcon: i,
312
+ children: /* @__PURE__ */ k(u, {
313
+ leftIcon: r,
493
314
  className: "rounded-pill",
494
315
  onClick: e,
495
316
  "aria-haspopup": "dialog",
496
317
  "aria-expanded": t,
497
- children: c.launcher
318
+ children: l.launcher
498
319
  })
499
320
  });
500
321
  }
322
+ function U({ onClick: e, open: t, position: n, icon: r, className: i, style: a, label: o }) {
323
+ let s = x(n);
324
+ return s ? j(/* @__PURE__ */ k("span", {
325
+ className: ["wui-floating-stack-item wui-floating-stack-item--primary", i].filter(Boolean).join(" "),
326
+ style: a,
327
+ children: /* @__PURE__ */ k(u, {
328
+ className: "wui-floating-btn",
329
+ onClick: e,
330
+ "aria-label": o,
331
+ "aria-haspopup": "dialog",
332
+ "aria-expanded": t,
333
+ tooltip: o,
334
+ tooltipPlacement: n === "start" ? "end" : "start",
335
+ children: /* @__PURE__ */ k(h, {
336
+ name: r,
337
+ size: 24
338
+ })
339
+ })
340
+ }), s) : null;
341
+ }
501
342
  //#endregion
502
343
  //#region src/markdown.jsx
503
- var se = /^[a-z][a-z0-9+.-]*:[a-z0-9_-]+\/[a-z0-9_.~-]+$/i, L = /^\s*```/, R = /^\s*[-*+]\s+(.*)$/, z = /^\s*(\d{1,9})[.)]\s+(.*)$/, B = /^\s{0,3}#{1,6}\s+(.*?)\s*#*\s*$/, V = /^\s*([-*_])(\s*\1){2,}\s*$/, ce = /^\s*\|?\s*:?-{3,}:?\s*(\|\s*:?-{3,}:?\s*)*\|?\s*$/, H = (e) => e.includes("|");
504
- function U(e) {
505
- let t = e.trim();
506
- return t.startsWith("|") && (t = t.slice(1)), t.endsWith("|") && (t = t.slice(0, -1)), t.split("|").map((e) => e.trim());
507
- }
508
- function W(e, t) {
509
- return H(e[t]) && t + 1 < e.length && ce.test(e[t + 1]);
510
- }
511
- function G(e, t) {
512
- let n = e[t];
513
- return L.test(n) || R.test(n) || z.test(n) || B.test(n) || V.test(n) || W(e, t);
514
- }
515
- function le(e) {
516
- let t = String(e ?? "").replace(/\r\n?/g, "\n").split("\n"), n = [], r = 0;
517
- for (; r < t.length;) {
518
- let e = t[r];
519
- if (!e.trim()) {
520
- r += 1;
521
- continue;
522
- }
523
- if (L.test(e)) {
524
- let e = [];
525
- for (r += 1; r < t.length && !L.test(t[r]);) e.push(t[r]), r += 1;
526
- r += 1, n.push({
527
- type: "code",
528
- text: e.join("\n")
529
- });
530
- continue;
531
- }
532
- if (W(t, r)) {
533
- let i = U(e), a = [];
534
- for (r += 2; r < t.length && t[r].trim() && H(t[r]);) a.push(U(t[r])), r += 1;
535
- n.push({
536
- type: "table",
537
- header: i,
538
- rows: a
539
- });
540
- continue;
541
- }
542
- if (V.test(e)) {
543
- n.push({ type: "rule" }), r += 1;
544
- continue;
545
- }
546
- let i = B.exec(e);
547
- if (i) {
548
- n.push({
549
- type: "heading",
550
- text: i[1]
551
- }), r += 1;
552
- continue;
553
- }
554
- let a = z.exec(e);
555
- if (a || R.test(e)) {
556
- let e = !!a, i = e ? z : R, o = [];
557
- for (; r < t.length && t[r].trim();) {
558
- let n = i.exec(t[r]);
559
- if (n) o.push(e ? n[2] : n[1]);
560
- else if (G(t, r)) break;
561
- else o[o.length - 1] += ` ${t[r].trim()}`;
562
- r += 1;
563
- }
564
- n.push({
565
- type: "list",
566
- ordered: e,
567
- start: e ? Number(a[1]) : 1,
568
- items: o
569
- });
570
- continue;
571
- }
572
- let o = [e];
573
- for (r += 1; r < t.length && t[r].trim() && !G(t, r);) o.push(t[r]), r += 1;
574
- n.push({
575
- type: "paragraph",
576
- lines: o
577
- });
578
- }
579
- return n.map((e, t) => ({
580
- ...e,
581
- key: t
582
- }));
583
- }
584
- var K = (e) => !!e && /[\p{L}\p{N}]/u.test(e);
585
- function q(e, t, n) {
586
- let r = e.indexOf(n, t);
587
- for (; r !== -1;) {
588
- let i = e.slice(t, r), a = n.length === 1 && (e[r + 1] === n || e[r - 1] === n), o = n[0] === "_" && K(e[r + n.length]);
589
- if (i.trim() && !/^\s/.test(i) && !/\s$/.test(i) && !a && !o) return r;
590
- r = e.indexOf(n, r + 1);
591
- }
592
- return -1;
593
- }
594
- function J(e) {
595
- let t = [], n = "", r = () => {
596
- n && t.push({
597
- type: "text",
598
- text: n
599
- }), n = "";
600
- }, i = 0;
601
- for (; i < e.length;) {
602
- let a = e[i];
603
- if (a === "`") {
604
- let n = e.indexOf("`", i + 1);
605
- if (n > i + 1) {
606
- r(), t.push({
607
- type: "code",
608
- text: e.slice(i + 1, n)
609
- }), i = n + 1;
610
- continue;
611
- }
612
- }
613
- if ((a === "*" || a === "_") && e[i + 1] === a) {
614
- let o = a + a, s = q(e, i + 2, o);
615
- if (s !== -1 && !(a === "_" && K(e[i - 1]))) {
616
- r(), t.push({
617
- type: "strong",
618
- children: J(e.slice(i + 2, s))
619
- }), i = s + 2;
620
- continue;
621
- }
622
- n += o, i += 2;
623
- continue;
624
- }
625
- if (a === "*" || a === "_") {
626
- let n = q(e, i + 1, a);
627
- if (n !== -1 && !(a === "_" && K(e[i - 1]))) {
628
- r(), t.push({
629
- type: "em",
630
- children: J(e.slice(i + 1, n))
631
- }), i = n + 1;
632
- continue;
633
- }
634
- }
635
- if (a === "[") {
636
- let n = /^\[([^\]\n]+)\]\(([^)\s]+)\)/.exec(e.slice(i));
637
- if (n) {
638
- r(), t.push({
639
- type: "link",
640
- href: n[2],
641
- children: J(n[1])
642
- }), i += n[0].length;
643
- continue;
644
- }
645
- }
646
- n += a, i += 1;
647
- }
648
- return r(), t.map((e, t) => ({
649
- ...e,
650
- key: t
651
- }));
652
- }
653
- function ue(e, t) {
654
- if (!t || !se.test(e)) return null;
655
- let n = t(e);
656
- return typeof n == "string" && n.startsWith("/") && !n.startsWith("//") ? n : null;
657
- }
658
- function Y({ tokens: e, resolveLink: t, linkComponent: n }) {
344
+ function W({ tokens: e, resolveLink: t, linkComponent: n }) {
659
345
  return e.map((e) => {
660
346
  switch (e.type) {
661
- case "code": return /* @__PURE__ */ b("code", { children: e.text }, e.key);
662
- case "strong": return /* @__PURE__ */ b("strong", { children: /* @__PURE__ */ b(Y, {
347
+ case "code": return /* @__PURE__ */ k("code", { children: e.text }, e.key);
348
+ case "strong": return /* @__PURE__ */ k("strong", { children: /* @__PURE__ */ k(W, {
663
349
  tokens: e.children,
664
350
  resolveLink: t,
665
351
  linkComponent: n
666
352
  }) }, e.key);
667
- case "em": return /* @__PURE__ */ b("em", { children: /* @__PURE__ */ b(Y, {
353
+ case "em": return /* @__PURE__ */ k("em", { children: /* @__PURE__ */ k(W, {
668
354
  tokens: e.children,
669
355
  resolveLink: t,
670
356
  linkComponent: n
671
357
  }) }, e.key);
672
358
  case "link": {
673
- let r = /* @__PURE__ */ b(Y, {
359
+ let r = /* @__PURE__ */ k(W, {
674
360
  tokens: e.children,
675
361
  resolveLink: t,
676
362
  linkComponent: n
677
- }), i = ue(e.href, t);
678
- return i ? /* @__PURE__ */ b(c, {
679
- href: i,
363
+ }), a = i(e.href, t);
364
+ return a ? /* @__PURE__ */ k(g, {
365
+ href: a,
680
366
  linkComponent: n,
681
367
  animation: "static",
682
368
  children: r
683
- }, e.key) : /* @__PURE__ */ b("span", { children: r }, e.key);
369
+ }, e.key) : /* @__PURE__ */ k("span", { children: r }, e.key);
684
370
  }
685
- default: return /* @__PURE__ */ b(p, { children: e.text }, e.key);
371
+ default: return /* @__PURE__ */ k(S, { children: e.text }, e.key);
686
372
  }
687
373
  });
688
374
  }
689
- function de({ text: e, resolveLink: t, linkComponent: n }) {
690
- return /* @__PURE__ */ b(Y, {
691
- tokens: J(e),
375
+ function G({ text: e, resolveLink: t, linkComponent: n }) {
376
+ return /* @__PURE__ */ k(W, {
377
+ tokens: s(e),
692
378
  resolveLink: t,
693
379
  linkComponent: n
694
380
  });
695
381
  }
696
- function fe({ block: e, resolveLink: t, linkComponent: n }) {
697
- let r = (e) => /* @__PURE__ */ b(de, {
382
+ function K({ block: e, resolveLink: t, linkComponent: n }) {
383
+ let r = (e) => /* @__PURE__ */ k(G, {
698
384
  text: e,
699
385
  resolveLink: t,
700
386
  linkComponent: n
701
387
  });
702
388
  switch (e.type) {
703
- case "heading": return /* @__PURE__ */ b("p", {
389
+ case "heading": return /* @__PURE__ */ k("p", {
704
390
  className: "fw-semibold mb-2",
705
391
  children: r(e.text)
706
392
  });
707
- case "rule": return /* @__PURE__ */ b("hr", { className: "my-2" });
708
- case "code": return /* @__PURE__ */ b("pre", {
393
+ case "rule": return /* @__PURE__ */ k("hr", { className: "my-2" });
394
+ case "code": return /* @__PURE__ */ k("pre", {
709
395
  className: "wui-text-sm mb-2",
710
- children: /* @__PURE__ */ b("code", { children: e.text })
396
+ children: /* @__PURE__ */ k("code", { children: e.text })
711
397
  });
712
398
  case "list": {
713
- let t = e.items.map((e, t) => /* @__PURE__ */ b("li", { children: r(e) }, t));
714
- return e.ordered ? /* @__PURE__ */ b("ol", {
399
+ let t = e.items.map((e, t) => /* @__PURE__ */ k("li", { children: r(e) }, t));
400
+ return e.ordered ? /* @__PURE__ */ k("ol", {
715
401
  className: "mb-2 ps-4",
716
402
  start: e.start === 1 ? void 0 : e.start,
717
403
  children: t
718
- }) : /* @__PURE__ */ b("ul", {
404
+ }) : /* @__PURE__ */ k("ul", {
719
405
  className: "mb-2 ps-4",
720
406
  children: t
721
407
  });
722
408
  }
723
- case "table": return /* @__PURE__ */ b(a, {
409
+ case "table": return /* @__PURE__ */ k(p, {
724
410
  columns: e.header.map((e, t) => ({
725
411
  key: `c${t}`,
726
412
  label: r(e),
@@ -734,17 +420,17 @@ function fe({ block: e, resolveLink: t, linkComponent: n }) {
734
420
  empty: null,
735
421
  wrapperClassName: "mb-2"
736
422
  });
737
- default: return /* @__PURE__ */ b("p", {
423
+ default: return /* @__PURE__ */ k("p", {
738
424
  className: "mb-2",
739
- children: e.lines.map((e, t) => /* @__PURE__ */ x("span", { children: [t > 0 && /* @__PURE__ */ b("br", {}), r(e)] }, t))
425
+ children: e.lines.map((e, t) => /* @__PURE__ */ A("span", { children: [t > 0 && /* @__PURE__ */ k("br", {}), r(e)] }, t))
740
426
  });
741
427
  }
742
428
  }
743
- function X({ text: e, resolveLink: t, linkComponent: n, className: r }) {
744
- let i = le(e);
745
- return /* @__PURE__ */ b("div", {
429
+ function q({ text: e, resolveLink: t, linkComponent: n, className: r }) {
430
+ let i = o(e);
431
+ return /* @__PURE__ */ k("div", {
746
432
  className: ["wui-text-sm text-break", r].filter(Boolean).join(" "),
747
- children: i.map((e) => /* @__PURE__ */ b(fe, {
433
+ children: i.map((e) => /* @__PURE__ */ k(K, {
748
434
  block: e,
749
435
  resolveLink: t,
750
436
  linkComponent: n
@@ -753,82 +439,82 @@ function X({ text: e, resolveLink: t, linkComponent: n, className: r }) {
753
439
  }
754
440
  //#endregion
755
441
  //#region src/components/ReplyRating.jsx
756
- function Z({ rating: e = null, onRate: r, noteMaxLength: i = 1e3, labels: a }) {
757
- let o = M(a), s = g(), [c, l] = v(!1), [u, d] = v(!1), [p, m] = v(""), [h, _] = v(""), [y, S] = v(!1);
758
- async function C(e, t) {
759
- l(!0), _("");
442
+ function J({ rating: e = null, onRate: t, noteMaxLength: n = 1e3, labels: r }) {
443
+ let i = a(r), o = T(), [s, c] = D(!1), [d, f] = D(!1), [p, m] = D(""), [h, g] = D(""), [_, v] = D(!1);
444
+ async function y(e, n) {
445
+ c(!0), g("");
760
446
  try {
761
- await r(e, t), d(e === "Down" && t === void 0), S(e === "Up" || t !== void 0), t !== void 0 && m("");
447
+ await t(e, n), f(e === "Down" && n === void 0), v(e === "Up" || n !== void 0), n !== void 0 && m("");
762
448
  } catch {
763
- _(o.ratingFailed);
449
+ g(i.ratingFailed);
764
450
  } finally {
765
- l(!1);
451
+ c(!1);
766
452
  }
767
453
  }
768
- return /* @__PURE__ */ x("div", {
454
+ return /* @__PURE__ */ A("div", {
769
455
  className: "d-flex flex-column gap-2",
770
456
  children: [
771
- /* @__PURE__ */ x("div", {
457
+ /* @__PURE__ */ A("div", {
772
458
  className: "d-flex flex-wrap align-items-center gap-1",
773
459
  children: [
774
- /* @__PURE__ */ b(n, {
460
+ /* @__PURE__ */ k(u, {
775
461
  size: "sm",
776
462
  variant: e === "Up" ? "subtle" : "ghost",
777
463
  leftIcon: "check",
778
464
  "aria-pressed": e === "Up",
779
- disabled: c,
780
- onClick: () => C("Up"),
781
- children: o.rateUp
465
+ disabled: s,
466
+ onClick: () => y("Up"),
467
+ children: i.rateUp
782
468
  }),
783
- /* @__PURE__ */ b(n, {
469
+ /* @__PURE__ */ k(u, {
784
470
  size: "sm",
785
471
  variant: e === "Down" ? "subtle" : "ghost",
786
472
  leftIcon: "x",
787
473
  "aria-pressed": e === "Down",
788
- disabled: c,
789
- onClick: () => C("Down"),
790
- children: o.rateDown
474
+ disabled: s,
475
+ onClick: () => y("Down"),
476
+ children: i.rateDown
791
477
  }),
792
- y && !u && /* @__PURE__ */ b("span", {
478
+ _ && !d && /* @__PURE__ */ k("span", {
793
479
  className: "wui-text-xs text-body-secondary",
794
480
  role: "status",
795
- children: o.rated
481
+ children: i.rated
796
482
  })
797
483
  ]
798
484
  }),
799
- h && /* @__PURE__ */ b(t, {
485
+ h && /* @__PURE__ */ k(l, {
800
486
  size: "sm",
801
487
  variant: "danger",
802
488
  children: h
803
489
  }),
804
- u && /* @__PURE__ */ x("form", {
490
+ d && /* @__PURE__ */ A("form", {
805
491
  className: "d-flex flex-column gap-2",
806
492
  onSubmit: (e) => {
807
- e.preventDefault(), C("Down", p);
493
+ e.preventDefault(), y("Down", p);
808
494
  },
809
- children: [/* @__PURE__ */ b(f, {
810
- id: `${s}-note`,
811
- label: o.ratingNote,
812
- hint: o.ratingNoteHint,
495
+ children: [/* @__PURE__ */ k(b, {
496
+ id: `${o}-note`,
497
+ label: i.ratingNote,
498
+ hint: i.ratingNoteHint,
813
499
  rows: 2,
814
- maxLength: i,
500
+ maxLength: n,
815
501
  value: p,
816
502
  onChange: (e) => m(e.target.value)
817
- }), /* @__PURE__ */ x("div", {
503
+ }), /* @__PURE__ */ A("div", {
818
504
  className: "d-flex gap-2",
819
- children: [/* @__PURE__ */ b(n, {
505
+ children: [/* @__PURE__ */ k(u, {
820
506
  type: "submit",
821
507
  size: "sm",
822
- loading: c,
823
- children: o.ratingNoteSend
824
- }), /* @__PURE__ */ b(n, {
508
+ loading: s,
509
+ children: i.ratingNoteSend
510
+ }), /* @__PURE__ */ k(u, {
825
511
  size: "sm",
826
512
  variant: "secondary",
827
- disabled: c,
513
+ disabled: s,
828
514
  onClick: () => {
829
- d(!1), S(!0);
515
+ f(!1), v(!0);
830
516
  },
831
- children: o.ratingNoteSkip
517
+ children: i.ratingNoteSkip
832
518
  })]
833
519
  })]
834
520
  })
@@ -837,68 +523,68 @@ function Z({ rating: e = null, onRate: r, noteMaxLength: i = 1e3, labels: a }) {
837
523
  }
838
524
  //#endregion
839
525
  //#region src/components/ChatMessage.jsx
840
- var pe = {
526
+ var Y = {
841
527
  maxWidth: "85%",
842
528
  whiteSpace: "pre-wrap",
843
529
  overflowWrap: "anywhere"
844
530
  };
845
- function Q({ turn: e, onRate: n, resolveLink: i, linkComponent: a, confirmAction: o, onViewTicket: s, renderReply: c, labels: l }) {
846
- let u = M(l), f = e.streaming && !e.answer;
847
- return /* @__PURE__ */ x("li", {
531
+ function X({ turn: e, onRate: t, resolveLink: n, linkComponent: r, confirmAction: i, onViewTicket: o, renderReply: s, labels: c }) {
532
+ let u = a(c), f = e.streaming && !e.answer;
533
+ return /* @__PURE__ */ A("li", {
848
534
  className: "d-flex flex-column gap-2",
849
- children: [e.question && /* @__PURE__ */ x("div", {
535
+ children: [e.question && /* @__PURE__ */ A("div", {
850
536
  className: "align-self-end",
851
- style: pe,
852
- children: [/* @__PURE__ */ x("span", {
537
+ style: Y,
538
+ children: [/* @__PURE__ */ A("span", {
853
539
  className: "visually-hidden",
854
540
  children: [u.you, ": "]
855
- }), /* @__PURE__ */ b(r, {
541
+ }), /* @__PURE__ */ k(d, {
856
542
  padding: "sm",
857
543
  variant: "muted",
858
544
  className: "wui-text-sm",
859
545
  children: e.question
860
546
  })]
861
- }), /* @__PURE__ */ x("div", {
547
+ }), /* @__PURE__ */ A("div", {
862
548
  className: "d-flex flex-column gap-2",
863
549
  style: { minWidth: 0 },
864
550
  children: [
865
- /* @__PURE__ */ x("span", {
551
+ /* @__PURE__ */ A("span", {
866
552
  className: "visually-hidden",
867
553
  children: [u.assistant, ": "]
868
554
  }),
869
- /* @__PURE__ */ b("div", {
555
+ /* @__PURE__ */ k("div", {
870
556
  "aria-live": "polite",
871
557
  "aria-busy": e.streaming,
872
- children: f ? /* @__PURE__ */ x("span", {
558
+ children: f ? /* @__PURE__ */ A("span", {
873
559
  className: "d-inline-flex align-items-center gap-2 wui-text-sm text-body-secondary",
874
- children: [/* @__PURE__ */ b(d, {
560
+ children: [/* @__PURE__ */ k(y, {
875
561
  size: "sm",
876
562
  label: u.thinking
877
- }), /* @__PURE__ */ b("span", {
563
+ }), /* @__PURE__ */ k("span", {
878
564
  "aria-hidden": "true",
879
565
  children: u.thinking
880
566
  })]
881
- }) : e.answer && (c ? c(e, { streaming: !!e.streaming }) : /* @__PURE__ */ b(X, {
567
+ }) : e.answer && (s ? s(e, { streaming: !!e.streaming }) : /* @__PURE__ */ k(q, {
882
568
  text: e.answer,
883
- resolveLink: i,
884
- linkComponent: a
569
+ resolveLink: n,
570
+ linkComponent: r
885
571
  }))
886
572
  }),
887
- e.error && /* @__PURE__ */ b(t, {
573
+ e.error && /* @__PURE__ */ k(l, {
888
574
  size: "sm",
889
575
  variant: "danger",
890
576
  children: e.error.message
891
577
  }),
892
- o && !e.streaming && e.actions.map((e) => /* @__PURE__ */ b(F, {
578
+ i && !e.streaming && e.actions.map((e) => /* @__PURE__ */ k(P, {
893
579
  action: e,
894
- confirmAction: o,
895
- onViewTicket: s,
896
- labels: l
580
+ confirmAction: i,
581
+ onViewTicket: o,
582
+ labels: c
897
583
  }, e.token)),
898
- n && e.messageId && !e.streaming && /* @__PURE__ */ b(Z, {
584
+ t && e.messageId && !e.streaming && /* @__PURE__ */ k(J, {
899
585
  rating: e.rating,
900
- onRate: (t, r) => n(e.id, t, r),
901
- labels: l
586
+ onRate: (n, r) => t(e.id, n, r),
587
+ labels: c
902
588
  })
903
589
  ]
904
590
  })]
@@ -906,135 +592,135 @@ function Q({ turn: e, onRate: n, resolveLink: i, linkComponent: a, confirmAction
906
592
  }
907
593
  //#endregion
908
594
  //#region src/components/ChatThread.jsx
909
- function $({ turns: e, empty: t, onRate: n, resolveLink: r, linkComponent: i, confirmAction: a, onViewTicket: s, renderReply: c, labels: l }) {
910
- let u = M(l), d = _(null), f = e[e.length - 1];
911
- return h(() => {
595
+ function Z({ turns: e, empty: t, onRate: n, resolveLink: r, linkComponent: i, confirmAction: o, onViewTicket: s, renderReply: c, labels: l }) {
596
+ let u = a(l), d = E(null), f = e[e.length - 1];
597
+ return w(() => {
912
598
  d.current?.scrollIntoView({ block: "end" });
913
599
  }, [
914
600
  e.length,
915
601
  f?.answer,
916
602
  f?.error,
917
603
  f?.actions
918
- ]), e.length === 0 ? t ?? /* @__PURE__ */ b(o, {
604
+ ]), e.length === 0 ? t ?? /* @__PURE__ */ k(m, {
919
605
  icon: "sparkles",
920
606
  size: "sm",
921
607
  title: u.emptyTitle,
922
608
  text: u.emptyText
923
- }) : /* @__PURE__ */ x(y, { children: [/* @__PURE__ */ b("ol", {
609
+ }) : /* @__PURE__ */ A(O, { children: [/* @__PURE__ */ k("ol", {
924
610
  className: "list-unstyled d-flex flex-column gap-3 mb-0",
925
611
  "aria-label": u.thread,
926
- children: e.map((e) => /* @__PURE__ */ b(Q, {
612
+ children: e.map((e) => /* @__PURE__ */ k(X, {
927
613
  turn: e,
928
614
  onRate: n,
929
615
  resolveLink: r,
930
616
  linkComponent: i,
931
- confirmAction: a,
617
+ confirmAction: o,
932
618
  onViewTicket: s,
933
619
  renderReply: c,
934
620
  labels: l
935
621
  }, e.id))
936
- }), /* @__PURE__ */ b("div", { ref: d })] });
622
+ }), /* @__PURE__ */ k("div", { ref: d })] });
937
623
  }
938
624
  //#endregion
939
625
  //#region src/components/ChatPanel.jsx
940
- function me({ chat: n, open: r, onClose: i, title: a, titleIcon: o = "sparkles", headerActions: c, empty: u, disclaimer: f, maxLength: p = 4e3, allowanceThreshold: m = 10, width: g = "440px", resolveLink: v, linkComponent: y, confirmAction: S, onViewTicket: C, rating: w = !0, renderReply: T, labels: E }) {
941
- let D = M(E), O = _(null), { refreshAllowance: k } = n;
942
- h(() => {
943
- r && k().catch(() => {});
944
- }, [r, k]);
945
- let A = n.messagesLeftToday, j = a ?? D.panelTitle;
946
- return /* @__PURE__ */ b(l, {
947
- show: r,
948
- onHide: i,
626
+ function Q({ chat: e, open: t, onClose: n, title: r, titleIcon: i = "sparkles", headerActions: o, empty: s, disclaimer: u, maxLength: d = 4e3, allowanceThreshold: f = 10, width: p = "440px", resolveLink: m, linkComponent: g, confirmAction: v, onViewTicket: b, rating: x = !0, renderReply: S, labels: C }) {
627
+ let T = a(C), D = E(null), { refreshAllowance: O } = e;
628
+ w(() => {
629
+ t && O().catch(() => {});
630
+ }, [t, O]);
631
+ let j = e.messagesLeftToday, M = r ?? T.panelTitle;
632
+ return /* @__PURE__ */ k(_, {
633
+ show: t,
634
+ onHide: n,
949
635
  side: "right",
950
- width: g,
951
- header: /* @__PURE__ */ x("div", {
636
+ width: p,
637
+ header: /* @__PURE__ */ A("div", {
952
638
  className: "drawer-header",
953
- children: [/* @__PURE__ */ x("div", {
639
+ children: [/* @__PURE__ */ A("div", {
954
640
  className: "drawer-title",
955
- children: [o && /* @__PURE__ */ b("span", {
641
+ children: [i && /* @__PURE__ */ k("span", {
956
642
  className: "drawer-title-ic",
957
- children: /* @__PURE__ */ b(s, {
958
- name: o,
643
+ children: /* @__PURE__ */ k(h, {
644
+ name: i,
959
645
  size: 18
960
646
  })
961
- }), j]
962
- }), /* @__PURE__ */ x("div", {
647
+ }), M]
648
+ }), /* @__PURE__ */ A("div", {
963
649
  className: "d-flex align-items-center gap-1",
964
650
  children: [
965
- c,
966
- /* @__PURE__ */ b(e, {
651
+ o,
652
+ /* @__PURE__ */ k(c, {
967
653
  icon: "plus",
968
- label: D.newChat,
969
- onClick: n.newConversation,
970
- disabled: n.turns.length === 0 && !n.loading
654
+ label: T.newChat,
655
+ onClick: e.newConversation,
656
+ disabled: e.turns.length === 0 && !e.loading
971
657
  }),
972
- /* @__PURE__ */ b(e, {
658
+ /* @__PURE__ */ k(c, {
973
659
  icon: "x",
974
- label: D.close,
975
- onClick: i
660
+ label: T.close,
661
+ onClick: n
976
662
  })
977
663
  ]
978
664
  })]
979
665
  }),
980
- footer: /* @__PURE__ */ x("div", {
666
+ footer: /* @__PURE__ */ A("div", {
981
667
  className: "d-flex flex-column gap-2",
982
668
  children: [
983
- A !== null && A <= m && /* @__PURE__ */ b("p", {
669
+ j !== null && j <= f && /* @__PURE__ */ k("p", {
984
670
  className: "wui-text-xs text-body-secondary mb-0",
985
671
  role: "status",
986
- children: D.allowance(A)
672
+ children: T.allowance(j)
987
673
  }),
988
- /* @__PURE__ */ b(I, {
989
- onSubmit: n.submit,
990
- busy: n.streaming || n.loading,
991
- disabled: A === 0,
992
- maxLength: p,
993
- inputRef: O,
994
- labels: E
674
+ /* @__PURE__ */ k(F, {
675
+ onSubmit: e.submit,
676
+ busy: e.streaming || e.loading,
677
+ disabled: j === 0,
678
+ maxLength: d,
679
+ inputRef: D,
680
+ labels: C
995
681
  }),
996
- /* @__PURE__ */ b("p", {
682
+ /* @__PURE__ */ k("p", {
997
683
  className: "wui-text-xs text-body-secondary mb-0",
998
- children: f ?? D.disclaimer
684
+ children: u ?? T.disclaimer
999
685
  })
1000
686
  ]
1001
687
  }),
1002
- ariaLabel: typeof j == "string" ? j : D.panelTitle,
1003
- onEntered: () => O.current?.focus(),
1004
- children: n.loading ? /* @__PURE__ */ b("div", {
688
+ ariaLabel: typeof M == "string" ? M : T.panelTitle,
689
+ onEntered: () => D.current?.focus(),
690
+ children: e.loading ? /* @__PURE__ */ k("div", {
1005
691
  className: "d-flex justify-content-center py-4",
1006
- children: /* @__PURE__ */ b(d, { label: D.loadingConversation })
1007
- }) : n.loadError ? /* @__PURE__ */ b(t, {
692
+ children: /* @__PURE__ */ k(y, { label: T.loadingConversation })
693
+ }) : e.loadError ? /* @__PURE__ */ k(l, {
1008
694
  variant: "danger",
1009
- children: n.loadError.message
1010
- }) : /* @__PURE__ */ b($, {
1011
- turns: n.turns,
1012
- empty: u,
1013
- onRate: w ? n.rate : void 0,
1014
- resolveLink: v,
1015
- linkComponent: y,
1016
- confirmAction: S,
1017
- onViewTicket: C,
1018
- renderReply: T,
1019
- labels: E
695
+ children: e.loadError.message
696
+ }) : /* @__PURE__ */ k(Z, {
697
+ turns: e.turns,
698
+ empty: s,
699
+ onRate: x ? e.rate : void 0,
700
+ resolveLink: m,
701
+ linkComponent: g,
702
+ confirmAction: v,
703
+ onViewTicket: b,
704
+ renderReply: S,
705
+ labels: C
1020
706
  })
1021
707
  });
1022
708
  }
1023
709
  //#endregion
1024
710
  //#region src/useChat.js
1025
- function he(e) {
711
+ function $(e) {
1026
712
  return {
1027
713
  code: e?.code || "unknown",
1028
714
  message: e?.message || "Something went wrong. Please try again.",
1029
715
  resetsAtUtc: e?.resetsAtUtc ?? null
1030
716
  };
1031
717
  }
1032
- function ge(e) {
718
+ function ee(e) {
1033
719
  if (!e) return [];
1034
720
  let t = JSON.parse(e);
1035
721
  return Array.isArray(t) ? t : [];
1036
722
  }
1037
- function _e(e) {
723
+ function te(e) {
1038
724
  let t = [];
1039
725
  for (let n of e ?? []) {
1040
726
  if (n.role === "User") {
@@ -1053,7 +739,7 @@ function _e(e) {
1053
739
  }
1054
740
  let e = t[t.length - 1], r = {
1055
741
  answer: n.content,
1056
- actions: ge(n.actionsJson),
742
+ actions: ee(n.actionsJson),
1057
743
  messageId: n.publicId,
1058
744
  rating: n.rating ?? null,
1059
745
  ratingNote: n.ratingNote ?? null
@@ -1068,28 +754,28 @@ function _e(e) {
1068
754
  }
1069
755
  return t;
1070
756
  }
1071
- function ve({ client: e, pageContext: t }) {
1072
- let [n, r] = v([]), [i, a] = v(null), [o, s] = v(null), [c, l] = v(!1), [u, d] = v(null), f = _(null), p = _(0), g = _(0), y = _(t);
1073
- y.current = t;
1074
- let b = _(null);
1075
- b.current = i;
1076
- let x = _(n);
1077
- x.current = n;
1078
- let S = m(() => {
757
+ function ne({ client: e, pageContext: t }) {
758
+ let [n, r] = D([]), [i, a] = D(null), [o, s] = D(null), [c, l] = D(!1), [u, d] = D(null), f = E(null), p = E(0), m = E(0), h = E(t);
759
+ h.current = t;
760
+ let g = E(null);
761
+ g.current = i;
762
+ let _ = E(n);
763
+ _.current = n;
764
+ let v = C(() => {
1079
765
  p.current += 1, f.current?.abort(), f.current = null;
1080
766
  }, []);
1081
- h(() => S, [S]);
1082
- let C = m((e, t) => {
767
+ w(() => v, [v]);
768
+ let y = C((e, t) => {
1083
769
  r((n) => n.map((n) => n.id === e ? {
1084
770
  ...n,
1085
771
  ...typeof t == "function" ? t(n) : t
1086
772
  } : n));
1087
- }, []), w = m(async (t) => {
773
+ }, []), b = C(async (t) => {
1088
774
  let n = typeof t == "string" ? t.trim() : "";
1089
775
  if (!n || f.current) return;
1090
776
  let i = p.current, o = new AbortController();
1091
- f.current = o, g.current += 1;
1092
- let c = `turn-${g.current}`;
777
+ f.current = o, m.current += 1;
778
+ let c = `turn-${m.current}`;
1093
779
  r((e) => [...e, {
1094
780
  id: c,
1095
781
  question: n,
@@ -1105,60 +791,60 @@ function ve({ client: e, pageContext: t }) {
1105
791
  try {
1106
792
  let t = await e.sendMessage({
1107
793
  message: n,
1108
- conversationId: b.current,
1109
- pageContext: y.current
794
+ conversationId: g.current,
795
+ pageContext: h.current
1110
796
  }, {
1111
797
  signal: o.signal,
1112
798
  onEvent: (e, t) => {
1113
- l() && (e === "delta" ? C(c, (e) => ({ answer: e.answer + (t?.text ?? "") })) : e === "reset" ? C(c, { answer: "" }) : e === "actions" && C(c, { actions: Array.isArray(t?.actions) ? t.actions : [] }));
799
+ l() && (e === "delta" ? y(c, (e) => ({ answer: e.answer + (t?.text ?? "") })) : e === "reset" ? y(c, { answer: "" }) : e === "actions" && y(c, { actions: Array.isArray(t?.actions) ? t.actions : [] }));
1114
800
  }
1115
801
  });
1116
802
  if (!l()) return;
1117
- C(c, {
803
+ y(c, {
1118
804
  answer: t.reply,
1119
805
  messageId: t.messageId ?? null,
1120
806
  streaming: !1
1121
- }), b.current = t.conversationId, a(t.conversationId), s(t.messagesLeftToday ?? null);
807
+ }), g.current = t.conversationId, a(t.conversationId), s(t.messagesLeftToday ?? null);
1122
808
  } catch (e) {
1123
809
  if (!l()) return;
1124
- C(c, {
810
+ y(c, {
1125
811
  answer: "",
1126
812
  actions: [],
1127
813
  streaming: !1,
1128
- error: he(e)
1129
- }), e?.code === "daily-limit" && s(0), e?.code === "conversation-not-found" && (b.current = null, a(null));
814
+ error: $(e)
815
+ }), e?.code === "daily-limit" && s(0), e?.code === "conversation-not-found" && (g.current = null, a(null));
1130
816
  } finally {
1131
817
  f.current === o && (f.current = null);
1132
818
  }
1133
- }, [e, C]), T = m(async (t) => {
1134
- S();
819
+ }, [e, y]), x = C(async (t) => {
820
+ v();
1135
821
  let n = p.current;
1136
822
  r([]), a(null), d(null), l(!0);
1137
823
  try {
1138
824
  let i = await e.getConversation(t);
1139
825
  if (n !== p.current) return;
1140
- r(_e(i.messages)), a(i.publicId);
826
+ r(te(i.messages)), a(i.publicId);
1141
827
  } catch (e) {
1142
828
  if (n !== p.current) return;
1143
- d(he(e));
829
+ d($(e));
1144
830
  } finally {
1145
831
  n === p.current && l(!1);
1146
832
  }
1147
- }, [S, e]), E = m(() => {
1148
- S(), r([]), a(null), d(null), l(!1);
1149
- }, [S]), D = m(() => {
1150
- S(), r([]), a(null), s(null), d(null), l(!1);
1151
- }, [S]), O = m(async () => {
833
+ }, [v, e]), S = C(() => {
834
+ v(), r([]), a(null), d(null), l(!1);
835
+ }, [v]), T = C(() => {
836
+ v(), r([]), a(null), s(null), d(null), l(!1);
837
+ }, [v]), O = C(async () => {
1152
838
  let t = p.current, n = await e.getAllowance();
1153
839
  t === p.current && s(n?.messagesLeftToday ?? null);
1154
- }, [e]), k = m(async (t, n, r) => {
1155
- let i = x.current.find((e) => e.id === t), a = b.current;
840
+ }, [e]), k = C(async (t, n, r) => {
841
+ let i = _.current.find((e) => e.id === t), a = g.current;
1156
842
  if (!i?.messageId || !a) throw Error("Only a stored reply can be rated.");
1157
843
  let o = {
1158
844
  rating: i.rating,
1159
845
  ratingNote: i.ratingNote
1160
846
  }, s = typeof r == "string" && r.trim() ? r.trim() : null;
1161
- C(t, {
847
+ y(t, {
1162
848
  rating: n,
1163
849
  ratingNote: s
1164
850
  });
@@ -1168,9 +854,9 @@ function ve({ client: e, pageContext: t }) {
1168
854
  note: s
1169
855
  });
1170
856
  } catch (e) {
1171
- throw C(t, o), e;
857
+ throw y(t, o), e;
1172
858
  }
1173
- }, [e, C]);
859
+ }, [e, y]);
1174
860
  return {
1175
861
  turns: n,
1176
862
  conversationId: i,
@@ -1178,13 +864,13 @@ function ve({ client: e, pageContext: t }) {
1178
864
  streaming: n.some((e) => e.streaming),
1179
865
  loading: c,
1180
866
  loadError: u,
1181
- submit: w,
1182
- openConversation: T,
1183
- newConversation: E,
867
+ submit: b,
868
+ openConversation: x,
869
+ newConversation: S,
1184
870
  rate: k,
1185
871
  refreshAllowance: O,
1186
- reset: D
872
+ reset: T
1187
873
  };
1188
874
  }
1189
875
  //#endregion
1190
- export { F as ActionCard, w as ChatApiError, I as ChatComposer, re as ChatConversationList, oe as ChatLauncher, X as ChatMarkdown, Q as ChatMessage, me as ChatPanel, $ as ChatThread, j as DEFAULT_CHAT_LABELS, Z as ReplyRating, A as createChatClient, S as createSseParser, ve as useChat };
876
+ export { P as ActionCard, e as ChatApiError, F as ChatComposer, z as ChatConversationList, H as ChatLauncher, q as ChatMarkdown, X as ChatMessage, Q as ChatPanel, Z as ChatThread, t as DEFAULT_CHAT_LABELS, J as ReplyRating, n as createChatClient, r as createSseParser, ne as useChat };