@webority/chat-react 0.30.0 → 0.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -6
- package/dist/chat-react.js +352 -666
- package/dist/types/components/ActionCard.d.ts +4 -4
- package/dist/types/components/ChatComposer.d.ts +2 -2
- package/dist/types/components/ChatConversationList.d.ts +6 -6
- package/dist/types/components/ChatLauncher.d.ts +11 -3
- package/dist/types/components/ChatMessage.d.ts +2 -2
- package/dist/types/components/ChatPanel.d.ts +2 -2
- package/dist/types/components/ChatThread.d.ts +2 -2
- package/dist/types/components/ReplyRating.d.ts +2 -2
- package/dist/types/index.d.ts +1 -3
- package/dist/types/markdown.d.ts +0 -77
- package/dist/types/useChat.d.ts +3 -3
- package/package.json +5 -3
- package/dist/types/client.d.ts +0 -208
- package/dist/types/labels.d.ts +0 -69
- package/dist/types/lib/sse.d.ts +0 -33
package/dist/chat-react.js
CHANGED
|
@@ -1,269 +1,82 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Fragment as
|
|
4
|
-
|
|
5
|
-
|
|
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
|
|
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
|
|
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
|
|
201
|
-
let
|
|
202
|
-
if (
|
|
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:
|
|
17
|
+
children: i.actionDismissed
|
|
205
18
|
});
|
|
206
|
-
if (
|
|
19
|
+
if (o === "done") return /* @__PURE__ */ k(l, {
|
|
207
20
|
variant: "success",
|
|
208
21
|
role: "status",
|
|
209
22
|
size: "sm",
|
|
210
|
-
action:
|
|
23
|
+
action: n ? /* @__PURE__ */ k(u, {
|
|
211
24
|
size: "sm",
|
|
212
25
|
variant: "ghost",
|
|
213
|
-
onClick: () =>
|
|
214
|
-
children:
|
|
26
|
+
onClick: () => n(c),
|
|
27
|
+
children: i.viewTicket
|
|
215
28
|
}) : void 0,
|
|
216
|
-
children:
|
|
29
|
+
children: N(e.kind, c.number, i)
|
|
217
30
|
});
|
|
218
|
-
async function
|
|
219
|
-
|
|
31
|
+
async function h() {
|
|
32
|
+
s("sending"), m("");
|
|
220
33
|
try {
|
|
221
|
-
|
|
34
|
+
f(await t(e.token)), s("done");
|
|
222
35
|
} catch (e) {
|
|
223
|
-
|
|
36
|
+
m(e?.message || i.actionFailed), s("ready");
|
|
224
37
|
}
|
|
225
38
|
}
|
|
226
|
-
let
|
|
227
|
-
return /* @__PURE__ */
|
|
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:
|
|
231
|
-
subtitle:
|
|
232
|
-
children: /* @__PURE__ */
|
|
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__ */
|
|
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
|
-
}),
|
|
54
|
+
}), _ ? /* @__PURE__ */ k("p", {
|
|
242
55
|
className: "wui-text-sm text-body-secondary mb-0",
|
|
243
|
-
children:
|
|
244
|
-
}) : /* @__PURE__ */
|
|
245
|
-
/* @__PURE__ */
|
|
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:
|
|
60
|
+
children: i.actionNote
|
|
248
61
|
}),
|
|
249
|
-
|
|
62
|
+
p && /* @__PURE__ */ k(l, {
|
|
250
63
|
size: "sm",
|
|
251
64
|
variant: "danger",
|
|
252
|
-
children:
|
|
65
|
+
children: p
|
|
253
66
|
}),
|
|
254
|
-
/* @__PURE__ */
|
|
67
|
+
/* @__PURE__ */ A("div", {
|
|
255
68
|
className: "d-flex flex-wrap gap-2",
|
|
256
|
-
children: [/* @__PURE__ */
|
|
69
|
+
children: [/* @__PURE__ */ k(u, {
|
|
257
70
|
size: "sm",
|
|
258
|
-
loading:
|
|
259
|
-
onClick:
|
|
260
|
-
children:
|
|
261
|
-
}), /* @__PURE__ */
|
|
71
|
+
loading: g,
|
|
72
|
+
onClick: h,
|
|
73
|
+
children: i.actionConfirm
|
|
74
|
+
}), /* @__PURE__ */ k(u, {
|
|
262
75
|
size: "sm",
|
|
263
76
|
variant: "secondary",
|
|
264
|
-
disabled:
|
|
265
|
-
onClick: () =>
|
|
266
|
-
children:
|
|
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
|
|
276
|
-
let s =
|
|
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
|
-
|
|
91
|
+
f || (e(l.trim()), d(""));
|
|
279
92
|
}
|
|
280
|
-
return /* @__PURE__ */
|
|
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
|
|
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:
|
|
107
|
+
maxLength: r,
|
|
295
108
|
value: l,
|
|
296
|
-
disabled:
|
|
297
|
-
ref:
|
|
109
|
+
disabled: n,
|
|
110
|
+
ref: i,
|
|
298
111
|
fieldClassName: "flex-grow-1 mb-0",
|
|
299
|
-
onChange: (e) =>
|
|
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__ */
|
|
117
|
+
/* @__PURE__ */ k("span", {
|
|
305
118
|
id: `${c}-hint`,
|
|
306
119
|
className: "visually-hidden",
|
|
307
120
|
children: s.composerHint
|
|
308
121
|
}),
|
|
309
|
-
/* @__PURE__ */
|
|
122
|
+
/* @__PURE__ */ k(u, {
|
|
310
123
|
type: "submit",
|
|
311
124
|
leftIcon: "send",
|
|
312
|
-
disabled:
|
|
313
|
-
children: /* @__PURE__ */
|
|
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
|
|
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
|
-
}),
|
|
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
|
|
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(
|
|
350
|
-
return `${n.day} ${
|
|
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
|
|
355
|
-
let
|
|
356
|
-
|
|
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
|
|
359
|
-
skip:
|
|
360
|
-
take:
|
|
171
|
+
let n = await e.listConversations({
|
|
172
|
+
skip: t,
|
|
173
|
+
take: r
|
|
361
174
|
});
|
|
362
|
-
|
|
175
|
+
p((e) => t === 0 ? n : [...e, ...n]), x(n.length === r);
|
|
363
176
|
} catch (e) {
|
|
364
|
-
|
|
177
|
+
y(e?.message || o.loadFailed);
|
|
365
178
|
} finally {
|
|
366
|
-
|
|
179
|
+
g(!1);
|
|
367
180
|
}
|
|
368
181
|
}, [
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
182
|
+
e,
|
|
183
|
+
r,
|
|
184
|
+
o.loadFailed
|
|
372
185
|
]);
|
|
373
|
-
|
|
186
|
+
w(() => {
|
|
374
187
|
F(0);
|
|
375
|
-
}, [F,
|
|
188
|
+
}, [F, S]);
|
|
376
189
|
async function I() {
|
|
377
|
-
|
|
190
|
+
M(!0), P("");
|
|
378
191
|
try {
|
|
379
|
-
await
|
|
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 ||
|
|
194
|
+
P(e?.message || o.deleteFailed);
|
|
382
195
|
} finally {
|
|
383
|
-
|
|
196
|
+
M(!1);
|
|
384
197
|
}
|
|
385
198
|
}
|
|
386
|
-
return !
|
|
199
|
+
return !h && !_ && s.length === 0 ? /* @__PURE__ */ k(m, {
|
|
387
200
|
icon: "chat",
|
|
388
201
|
size: "sm",
|
|
389
|
-
title:
|
|
390
|
-
text:
|
|
391
|
-
}) : /* @__PURE__ */
|
|
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
|
-
|
|
207
|
+
_ && /* @__PURE__ */ k(l, {
|
|
395
208
|
variant: "danger",
|
|
396
|
-
action: /* @__PURE__ */
|
|
209
|
+
action: /* @__PURE__ */ k(u, {
|
|
397
210
|
size: "sm",
|
|
398
211
|
variant: "secondary",
|
|
399
|
-
onClick: () =>
|
|
400
|
-
children:
|
|
212
|
+
onClick: () => T((e) => e + 1),
|
|
213
|
+
children: o.retry
|
|
401
214
|
}),
|
|
402
|
-
children:
|
|
215
|
+
children: _
|
|
403
216
|
}),
|
|
404
|
-
|
|
217
|
+
s.length > 0 && /* @__PURE__ */ k("ul", {
|
|
405
218
|
className: "list-unstyled d-flex flex-column gap-2 mb-0",
|
|
406
|
-
"aria-label":
|
|
407
|
-
children:
|
|
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__ */
|
|
224
|
+
children: [/* @__PURE__ */ k(u, {
|
|
412
225
|
variant: "ghost",
|
|
413
226
|
className: "flex-grow-1 text-start",
|
|
414
227
|
style: { minWidth: 0 },
|
|
415
|
-
onClick: () =>
|
|
416
|
-
children: /* @__PURE__ */
|
|
228
|
+
onClick: () => t(e),
|
|
229
|
+
children: /* @__PURE__ */ A("span", {
|
|
417
230
|
className: "d-flex flex-column",
|
|
418
231
|
style: { minWidth: 0 },
|
|
419
|
-
children: [/* @__PURE__ */
|
|
232
|
+
children: [/* @__PURE__ */ k("span", {
|
|
420
233
|
className: "text-truncate fw-semibold",
|
|
421
|
-
children:
|
|
422
|
-
}), /* @__PURE__ */
|
|
423
|
-
dateTime:
|
|
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:
|
|
238
|
+
children: R(e.lastMessageDateTimeUtc)
|
|
426
239
|
})]
|
|
427
240
|
})
|
|
428
|
-
}), /* @__PURE__ */
|
|
241
|
+
}), /* @__PURE__ */ k(c, {
|
|
429
242
|
icon: "trash-2",
|
|
430
243
|
danger: !0,
|
|
431
|
-
label:
|
|
244
|
+
label: o.deleteConversation,
|
|
432
245
|
onClick: () => {
|
|
433
|
-
P(""),
|
|
246
|
+
P(""), O(e);
|
|
434
247
|
}
|
|
435
248
|
})]
|
|
436
|
-
}) },
|
|
249
|
+
}) }, e.publicId))
|
|
437
250
|
}),
|
|
438
|
-
|
|
251
|
+
h && /* @__PURE__ */ A("div", {
|
|
439
252
|
className: "d-flex flex-column gap-2",
|
|
440
253
|
"aria-hidden": "true",
|
|
441
254
|
children: [
|
|
442
|
-
/* @__PURE__ */
|
|
443
|
-
/* @__PURE__ */
|
|
444
|
-
/* @__PURE__ */
|
|
255
|
+
/* @__PURE__ */ k(v, { height: 44 }),
|
|
256
|
+
/* @__PURE__ */ k(v, { height: 44 }),
|
|
257
|
+
/* @__PURE__ */ k(v, { height: 44 })
|
|
445
258
|
]
|
|
446
259
|
}),
|
|
447
|
-
!
|
|
260
|
+
!h && b && /* @__PURE__ */ k(u, {
|
|
448
261
|
variant: "secondary",
|
|
449
262
|
className: "align-self-center",
|
|
450
|
-
onClick: () => F(
|
|
451
|
-
children:
|
|
263
|
+
onClick: () => F(s.length),
|
|
264
|
+
children: o.loadMore
|
|
452
265
|
}),
|
|
453
|
-
/* @__PURE__ */
|
|
454
|
-
open:
|
|
455
|
-
title:
|
|
456
|
-
message: N ? /* @__PURE__ */
|
|
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
|
-
}) :
|
|
460
|
-
confirmLabel:
|
|
461
|
-
cancelLabel:
|
|
272
|
+
}) : o.deleteConfirmMessage,
|
|
273
|
+
confirmLabel: o.deleteConfirm,
|
|
274
|
+
cancelLabel: o.cancel,
|
|
462
275
|
danger: !0,
|
|
463
|
-
loading:
|
|
276
|
+
loading: j,
|
|
464
277
|
onConfirm: I,
|
|
465
278
|
onClose: () => {
|
|
466
|
-
|
|
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
|
|
287
|
+
var B = {
|
|
475
288
|
zIndex: "var(--wui-z-fixed)",
|
|
476
289
|
bottom: 0
|
|
477
|
-
},
|
|
290
|
+
}, V = {
|
|
478
291
|
end: { insetInlineEnd: 0 },
|
|
479
292
|
start: { insetInlineStart: 0 }
|
|
480
293
|
};
|
|
481
|
-
function
|
|
482
|
-
let
|
|
483
|
-
return /* @__PURE__ */
|
|
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",
|
|
306
|
+
className: ["position-fixed m-3", o].filter(Boolean).join(" "),
|
|
486
307
|
style: {
|
|
487
|
-
...
|
|
488
|
-
...
|
|
489
|
-
...
|
|
308
|
+
...B,
|
|
309
|
+
...V[n],
|
|
310
|
+
...s
|
|
490
311
|
},
|
|
491
|
-
children: /* @__PURE__ */
|
|
492
|
-
leftIcon:
|
|
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:
|
|
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
|
-
|
|
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__ */
|
|
662
|
-
case "strong": return /* @__PURE__ */
|
|
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__ */
|
|
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__ */
|
|
359
|
+
let r = /* @__PURE__ */ k(W, {
|
|
674
360
|
tokens: e.children,
|
|
675
361
|
resolveLink: t,
|
|
676
362
|
linkComponent: n
|
|
677
|
-
}),
|
|
678
|
-
return
|
|
679
|
-
href:
|
|
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__ */
|
|
369
|
+
}, e.key) : /* @__PURE__ */ k("span", { children: r }, e.key);
|
|
684
370
|
}
|
|
685
|
-
default: return /* @__PURE__ */
|
|
371
|
+
default: return /* @__PURE__ */ k(S, { children: e.text }, e.key);
|
|
686
372
|
}
|
|
687
373
|
});
|
|
688
374
|
}
|
|
689
|
-
function
|
|
690
|
-
return /* @__PURE__ */
|
|
691
|
-
tokens:
|
|
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
|
|
697
|
-
let r = (e) => /* @__PURE__ */
|
|
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__ */
|
|
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__ */
|
|
708
|
-
case "code": return /* @__PURE__ */
|
|
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__ */
|
|
396
|
+
children: /* @__PURE__ */ k("code", { children: e.text })
|
|
711
397
|
});
|
|
712
398
|
case "list": {
|
|
713
|
-
let t = e.items.map((e, t) => /* @__PURE__ */
|
|
714
|
-
return e.ordered ? /* @__PURE__ */
|
|
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__ */
|
|
404
|
+
}) : /* @__PURE__ */ k("ul", {
|
|
719
405
|
className: "mb-2 ps-4",
|
|
720
406
|
children: t
|
|
721
407
|
});
|
|
722
408
|
}
|
|
723
|
-
case "table": return /* @__PURE__ */
|
|
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__ */
|
|
423
|
+
default: return /* @__PURE__ */ k("p", {
|
|
738
424
|
className: "mb-2",
|
|
739
|
-
children: e.lines.map((e, t) => /* @__PURE__ */
|
|
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
|
|
744
|
-
let i =
|
|
745
|
-
return /* @__PURE__ */
|
|
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__ */
|
|
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
|
|
757
|
-
let
|
|
758
|
-
async function
|
|
759
|
-
|
|
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
|
|
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
|
-
|
|
449
|
+
g(i.ratingFailed);
|
|
764
450
|
} finally {
|
|
765
|
-
|
|
451
|
+
c(!1);
|
|
766
452
|
}
|
|
767
453
|
}
|
|
768
|
-
return /* @__PURE__ */
|
|
454
|
+
return /* @__PURE__ */ A("div", {
|
|
769
455
|
className: "d-flex flex-column gap-2",
|
|
770
456
|
children: [
|
|
771
|
-
/* @__PURE__ */
|
|
457
|
+
/* @__PURE__ */ A("div", {
|
|
772
458
|
className: "d-flex flex-wrap align-items-center gap-1",
|
|
773
459
|
children: [
|
|
774
|
-
/* @__PURE__ */
|
|
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:
|
|
780
|
-
onClick: () =>
|
|
781
|
-
children:
|
|
465
|
+
disabled: s,
|
|
466
|
+
onClick: () => y("Up"),
|
|
467
|
+
children: i.rateUp
|
|
782
468
|
}),
|
|
783
|
-
/* @__PURE__ */
|
|
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:
|
|
789
|
-
onClick: () =>
|
|
790
|
-
children:
|
|
474
|
+
disabled: s,
|
|
475
|
+
onClick: () => y("Down"),
|
|
476
|
+
children: i.rateDown
|
|
791
477
|
}),
|
|
792
|
-
|
|
478
|
+
_ && !d && /* @__PURE__ */ k("span", {
|
|
793
479
|
className: "wui-text-xs text-body-secondary",
|
|
794
480
|
role: "status",
|
|
795
|
-
children:
|
|
481
|
+
children: i.rated
|
|
796
482
|
})
|
|
797
483
|
]
|
|
798
484
|
}),
|
|
799
|
-
h && /* @__PURE__ */
|
|
485
|
+
h && /* @__PURE__ */ k(l, {
|
|
800
486
|
size: "sm",
|
|
801
487
|
variant: "danger",
|
|
802
488
|
children: h
|
|
803
489
|
}),
|
|
804
|
-
|
|
490
|
+
d && /* @__PURE__ */ A("form", {
|
|
805
491
|
className: "d-flex flex-column gap-2",
|
|
806
492
|
onSubmit: (e) => {
|
|
807
|
-
e.preventDefault(),
|
|
493
|
+
e.preventDefault(), y("Down", p);
|
|
808
494
|
},
|
|
809
|
-
children: [/* @__PURE__ */ b
|
|
810
|
-
id: `${
|
|
811
|
-
label:
|
|
812
|
-
hint:
|
|
495
|
+
children: [/* @__PURE__ */ k(b, {
|
|
496
|
+
id: `${o}-note`,
|
|
497
|
+
label: i.ratingNote,
|
|
498
|
+
hint: i.ratingNoteHint,
|
|
813
499
|
rows: 2,
|
|
814
|
-
maxLength:
|
|
500
|
+
maxLength: n,
|
|
815
501
|
value: p,
|
|
816
502
|
onChange: (e) => m(e.target.value)
|
|
817
|
-
}), /* @__PURE__ */
|
|
503
|
+
}), /* @__PURE__ */ A("div", {
|
|
818
504
|
className: "d-flex gap-2",
|
|
819
|
-
children: [/* @__PURE__ */
|
|
505
|
+
children: [/* @__PURE__ */ k(u, {
|
|
820
506
|
type: "submit",
|
|
821
507
|
size: "sm",
|
|
822
|
-
loading:
|
|
823
|
-
children:
|
|
824
|
-
}), /* @__PURE__ */
|
|
508
|
+
loading: s,
|
|
509
|
+
children: i.ratingNoteSend
|
|
510
|
+
}), /* @__PURE__ */ k(u, {
|
|
825
511
|
size: "sm",
|
|
826
512
|
variant: "secondary",
|
|
827
|
-
disabled:
|
|
513
|
+
disabled: s,
|
|
828
514
|
onClick: () => {
|
|
829
|
-
|
|
515
|
+
f(!1), v(!0);
|
|
830
516
|
},
|
|
831
|
-
children:
|
|
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
|
|
526
|
+
var Y = {
|
|
841
527
|
maxWidth: "85%",
|
|
842
528
|
whiteSpace: "pre-wrap",
|
|
843
529
|
overflowWrap: "anywhere"
|
|
844
530
|
};
|
|
845
|
-
function
|
|
846
|
-
let u =
|
|
847
|
-
return /* @__PURE__ */
|
|
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__ */
|
|
535
|
+
children: [e.question && /* @__PURE__ */ A("div", {
|
|
850
536
|
className: "align-self-end",
|
|
851
|
-
style:
|
|
852
|
-
children: [/* @__PURE__ */
|
|
537
|
+
style: Y,
|
|
538
|
+
children: [/* @__PURE__ */ A("span", {
|
|
853
539
|
className: "visually-hidden",
|
|
854
540
|
children: [u.you, ": "]
|
|
855
|
-
}), /* @__PURE__ */
|
|
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__ */
|
|
547
|
+
}), /* @__PURE__ */ A("div", {
|
|
862
548
|
className: "d-flex flex-column gap-2",
|
|
863
549
|
style: { minWidth: 0 },
|
|
864
550
|
children: [
|
|
865
|
-
/* @__PURE__ */
|
|
551
|
+
/* @__PURE__ */ A("span", {
|
|
866
552
|
className: "visually-hidden",
|
|
867
553
|
children: [u.assistant, ": "]
|
|
868
554
|
}),
|
|
869
|
-
/* @__PURE__ */
|
|
555
|
+
/* @__PURE__ */ k("div", {
|
|
870
556
|
"aria-live": "polite",
|
|
871
557
|
"aria-busy": e.streaming,
|
|
872
|
-
children: f ? /* @__PURE__ */
|
|
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__ */
|
|
560
|
+
children: [/* @__PURE__ */ k(y, {
|
|
875
561
|
size: "sm",
|
|
876
562
|
label: u.thinking
|
|
877
|
-
}), /* @__PURE__ */
|
|
563
|
+
}), /* @__PURE__ */ k("span", {
|
|
878
564
|
"aria-hidden": "true",
|
|
879
565
|
children: u.thinking
|
|
880
566
|
})]
|
|
881
|
-
}) : e.answer && (
|
|
567
|
+
}) : e.answer && (s ? s(e, { streaming: !!e.streaming }) : /* @__PURE__ */ k(q, {
|
|
882
568
|
text: e.answer,
|
|
883
|
-
resolveLink:
|
|
884
|
-
linkComponent:
|
|
569
|
+
resolveLink: n,
|
|
570
|
+
linkComponent: r
|
|
885
571
|
}))
|
|
886
572
|
}),
|
|
887
|
-
e.error && /* @__PURE__ */
|
|
573
|
+
e.error && /* @__PURE__ */ k(l, {
|
|
888
574
|
size: "sm",
|
|
889
575
|
variant: "danger",
|
|
890
576
|
children: e.error.message
|
|
891
577
|
}),
|
|
892
|
-
|
|
578
|
+
i && !e.streaming && e.actions.map((e) => /* @__PURE__ */ k(P, {
|
|
893
579
|
action: e,
|
|
894
|
-
confirmAction:
|
|
895
|
-
onViewTicket:
|
|
896
|
-
labels:
|
|
580
|
+
confirmAction: i,
|
|
581
|
+
onViewTicket: o,
|
|
582
|
+
labels: c
|
|
897
583
|
}, e.token)),
|
|
898
|
-
|
|
584
|
+
t && e.messageId && !e.streaming && /* @__PURE__ */ k(J, {
|
|
899
585
|
rating: e.rating,
|
|
900
|
-
onRate: (
|
|
901
|
-
labels:
|
|
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
|
|
910
|
-
let u =
|
|
911
|
-
return
|
|
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__ */
|
|
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__ */
|
|
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__ */
|
|
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:
|
|
617
|
+
confirmAction: o,
|
|
932
618
|
onViewTicket: s,
|
|
933
619
|
renderReply: c,
|
|
934
620
|
labels: l
|
|
935
621
|
}, e.id))
|
|
936
|
-
}), /* @__PURE__ */
|
|
622
|
+
}), /* @__PURE__ */ k("div", { ref: d })] });
|
|
937
623
|
}
|
|
938
624
|
//#endregion
|
|
939
625
|
//#region src/components/ChatPanel.jsx
|
|
940
|
-
function
|
|
941
|
-
let
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
}, [
|
|
945
|
-
let
|
|
946
|
-
return /* @__PURE__ */
|
|
947
|
-
show:
|
|
948
|
-
onHide:
|
|
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:
|
|
951
|
-
header: /* @__PURE__ */
|
|
636
|
+
width: p,
|
|
637
|
+
header: /* @__PURE__ */ A("div", {
|
|
952
638
|
className: "drawer-header",
|
|
953
|
-
children: [/* @__PURE__ */
|
|
639
|
+
children: [/* @__PURE__ */ A("div", {
|
|
954
640
|
className: "drawer-title",
|
|
955
|
-
children: [
|
|
641
|
+
children: [i && /* @__PURE__ */ k("span", {
|
|
956
642
|
className: "drawer-title-ic",
|
|
957
|
-
children: /* @__PURE__ */
|
|
958
|
-
name:
|
|
643
|
+
children: /* @__PURE__ */ k(h, {
|
|
644
|
+
name: i,
|
|
959
645
|
size: 18
|
|
960
646
|
})
|
|
961
|
-
}),
|
|
962
|
-
}), /* @__PURE__ */
|
|
647
|
+
}), M]
|
|
648
|
+
}), /* @__PURE__ */ A("div", {
|
|
963
649
|
className: "d-flex align-items-center gap-1",
|
|
964
650
|
children: [
|
|
965
|
-
|
|
966
|
-
/* @__PURE__ */
|
|
651
|
+
o,
|
|
652
|
+
/* @__PURE__ */ k(c, {
|
|
967
653
|
icon: "plus",
|
|
968
|
-
label:
|
|
969
|
-
onClick:
|
|
970
|
-
disabled:
|
|
654
|
+
label: T.newChat,
|
|
655
|
+
onClick: e.newConversation,
|
|
656
|
+
disabled: e.turns.length === 0 && !e.loading
|
|
971
657
|
}),
|
|
972
|
-
/* @__PURE__ */
|
|
658
|
+
/* @__PURE__ */ k(c, {
|
|
973
659
|
icon: "x",
|
|
974
|
-
label:
|
|
975
|
-
onClick:
|
|
660
|
+
label: T.close,
|
|
661
|
+
onClick: n
|
|
976
662
|
})
|
|
977
663
|
]
|
|
978
664
|
})]
|
|
979
665
|
}),
|
|
980
|
-
footer: /* @__PURE__ */
|
|
666
|
+
footer: /* @__PURE__ */ A("div", {
|
|
981
667
|
className: "d-flex flex-column gap-2",
|
|
982
668
|
children: [
|
|
983
|
-
|
|
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:
|
|
672
|
+
children: T.allowance(j)
|
|
987
673
|
}),
|
|
988
|
-
/* @__PURE__ */
|
|
989
|
-
onSubmit:
|
|
990
|
-
busy:
|
|
991
|
-
disabled:
|
|
992
|
-
maxLength:
|
|
993
|
-
inputRef:
|
|
994
|
-
labels:
|
|
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__ */
|
|
682
|
+
/* @__PURE__ */ k("p", {
|
|
997
683
|
className: "wui-text-xs text-body-secondary mb-0",
|
|
998
|
-
children:
|
|
684
|
+
children: u ?? T.disclaimer
|
|
999
685
|
})
|
|
1000
686
|
]
|
|
1001
687
|
}),
|
|
1002
|
-
ariaLabel: typeof
|
|
1003
|
-
onEntered: () =>
|
|
1004
|
-
children:
|
|
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__ */
|
|
1007
|
-
}) :
|
|
692
|
+
children: /* @__PURE__ */ k(y, { label: T.loadingConversation })
|
|
693
|
+
}) : e.loadError ? /* @__PURE__ */ k(l, {
|
|
1008
694
|
variant: "danger",
|
|
1009
|
-
children:
|
|
1010
|
-
}) : /* @__PURE__ */
|
|
1011
|
-
turns:
|
|
1012
|
-
empty:
|
|
1013
|
-
onRate:
|
|
1014
|
-
resolveLink:
|
|
1015
|
-
linkComponent:
|
|
1016
|
-
confirmAction:
|
|
1017
|
-
onViewTicket:
|
|
1018
|
-
renderReply:
|
|
1019
|
-
labels:
|
|
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
|
|
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
|
|
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
|
|
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:
|
|
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
|
|
1072
|
-
let [n, r] =
|
|
1073
|
-
|
|
1074
|
-
let
|
|
1075
|
-
|
|
1076
|
-
let
|
|
1077
|
-
|
|
1078
|
-
let
|
|
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
|
-
|
|
1082
|
-
let
|
|
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
|
-
}, []),
|
|
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,
|
|
1092
|
-
let c = `turn-${
|
|
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:
|
|
1109
|
-
pageContext:
|
|
794
|
+
conversationId: g.current,
|
|
795
|
+
pageContext: h.current
|
|
1110
796
|
}, {
|
|
1111
797
|
signal: o.signal,
|
|
1112
798
|
onEvent: (e, t) => {
|
|
1113
|
-
l() && (e === "delta" ?
|
|
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
|
-
|
|
803
|
+
y(c, {
|
|
1118
804
|
answer: t.reply,
|
|
1119
805
|
messageId: t.messageId ?? null,
|
|
1120
806
|
streaming: !1
|
|
1121
|
-
}),
|
|
807
|
+
}), g.current = t.conversationId, a(t.conversationId), s(t.messagesLeftToday ?? null);
|
|
1122
808
|
} catch (e) {
|
|
1123
809
|
if (!l()) return;
|
|
1124
|
-
|
|
810
|
+
y(c, {
|
|
1125
811
|
answer: "",
|
|
1126
812
|
actions: [],
|
|
1127
813
|
streaming: !1,
|
|
1128
|
-
error:
|
|
1129
|
-
}), e?.code === "daily-limit" && s(0), e?.code === "conversation-not-found" && (
|
|
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,
|
|
1134
|
-
|
|
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(
|
|
826
|
+
r(te(i.messages)), a(i.publicId);
|
|
1141
827
|
} catch (e) {
|
|
1142
828
|
if (n !== p.current) return;
|
|
1143
|
-
d(
|
|
829
|
+
d($(e));
|
|
1144
830
|
} finally {
|
|
1145
831
|
n === p.current && l(!1);
|
|
1146
832
|
}
|
|
1147
|
-
}, [
|
|
1148
|
-
|
|
1149
|
-
}, [
|
|
1150
|
-
|
|
1151
|
-
}, [
|
|
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 =
|
|
1155
|
-
let i =
|
|
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
|
-
|
|
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
|
|
857
|
+
throw y(t, o), e;
|
|
1172
858
|
}
|
|
1173
|
-
}, [e,
|
|
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:
|
|
1182
|
-
openConversation:
|
|
1183
|
-
newConversation:
|
|
867
|
+
submit: b,
|
|
868
|
+
openConversation: x,
|
|
869
|
+
newConversation: S,
|
|
1184
870
|
rate: k,
|
|
1185
871
|
refreshAllowance: O,
|
|
1186
|
-
reset:
|
|
872
|
+
reset: T
|
|
1187
873
|
};
|
|
1188
874
|
}
|
|
1189
875
|
//#endregion
|
|
1190
|
-
export {
|
|
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 };
|