@webority/ui-elements 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/dist/{fileViewerPdf-C02nR-30.js → fileViewerPdf-BnIsj-J-.js} +57 -35
- package/dist/types/chatClient.d.ts +208 -0
- package/dist/types/chatCore.d.ts +4 -0
- package/dist/types/chatLabels.d.ts +69 -0
- package/dist/types/markdownParse.d.ts +77 -0
- package/dist/types/sse.d.ts +33 -0
- package/dist/ui-chat-core.js +347 -0
- package/dist/ui-chat.global.js +10 -0
- package/dist/ui-chat.js +1066 -0
- package/dist/ui-elements.global.js +80 -66
- package/dist/ui-elements.js +1283 -1019
- package/dist/ui-file-viewer.global.js +4 -4
- package/dist/ui-file-viewer.js +6 -2
- package/package.json +8 -2
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
//#region src/sse.js
|
|
2
|
+
function e(e) {
|
|
3
|
+
let t = "";
|
|
4
|
+
function n(t) {
|
|
5
|
+
let n = "message", r = [];
|
|
6
|
+
for (let e of t.split("\n")) {
|
|
7
|
+
if (e === "" || e.startsWith(":")) continue;
|
|
8
|
+
let t = e.indexOf(":"), i = t === -1 ? e : e.slice(0, t), a = t === -1 ? "" : e.slice(t + 1);
|
|
9
|
+
a.startsWith(" ") && (a = a.slice(1)), i === "event" ? n = a : i === "data" && r.push(a);
|
|
10
|
+
}
|
|
11
|
+
if (r.length === 0) return;
|
|
12
|
+
let i;
|
|
13
|
+
try {
|
|
14
|
+
i = JSON.parse(r.join("\n"));
|
|
15
|
+
} catch {
|
|
16
|
+
e({
|
|
17
|
+
name: "error",
|
|
18
|
+
data: {
|
|
19
|
+
code: "invalid-response",
|
|
20
|
+
message: null
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
e({
|
|
26
|
+
name: n,
|
|
27
|
+
data: i
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
push(e) {
|
|
32
|
+
if (!e) return;
|
|
33
|
+
t = (t + e).replace(/\r\n/g, "\n").replace(/\r(?!$)/g, "\n");
|
|
34
|
+
let r = t.split("\n\n");
|
|
35
|
+
t = r.pop();
|
|
36
|
+
for (let e of r) n(e);
|
|
37
|
+
},
|
|
38
|
+
end() {
|
|
39
|
+
let e = t.replace(/\r$/, "");
|
|
40
|
+
t = "", e.trim() && n(e);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/chatClient.js
|
|
46
|
+
var t = "Something went wrong. Please try again.", n = class extends Error {
|
|
47
|
+
constructor(e, t, n, r = null) {
|
|
48
|
+
super(t), this.name = "ChatApiError", this.code = e, this.status = n, this.resetsAtUtc = r;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
function r(e) {
|
|
52
|
+
if (typeof e == "string") try {
|
|
53
|
+
return JSON.parse(e);
|
|
54
|
+
} catch {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
return e ?? null;
|
|
58
|
+
}
|
|
59
|
+
function i(e, t) {
|
|
60
|
+
return t?.aborted || e?.code === "ERR_CANCELED" || e?.name === "CanceledError" || e?.name === "AbortError";
|
|
61
|
+
}
|
|
62
|
+
function a(e, a) {
|
|
63
|
+
if (e instanceof n) return e;
|
|
64
|
+
if (i(e, a)) return new n("aborted", "The request was cancelled.");
|
|
65
|
+
let o = e?.response;
|
|
66
|
+
if (!o) return new n("network", t);
|
|
67
|
+
let s = r(o.data), c = typeof s?.code == "string" && s.code ? s.code : "unknown", l = typeof s?.message == "string" && s.message ? s.message : t, u = typeof s?.resetsAtUtc == "string" ? s.resetsAtUtc : null;
|
|
68
|
+
return new n(c, l, o.status, u);
|
|
69
|
+
}
|
|
70
|
+
async function o(e) {
|
|
71
|
+
try {
|
|
72
|
+
return (await e()).data;
|
|
73
|
+
} catch (e) {
|
|
74
|
+
throw a(e);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function s(e) {
|
|
78
|
+
let t = e?.event?.target;
|
|
79
|
+
if (!(!t || typeof t.responseText != "string") && !(typeof t.status == "number" && (t.status < 200 || t.status >= 300))) return t.responseText;
|
|
80
|
+
}
|
|
81
|
+
function c(r, { base: i }) {
|
|
82
|
+
if (typeof i != "string" || i.trim() === "") throw TypeError("createChatClient needs a base path, e.g. { base: \"/api/assistant\" }.");
|
|
83
|
+
let c = i.replace(/\/+$/, ""), l = (e) => `${c}/conversations/${encodeURIComponent(e)}`;
|
|
84
|
+
async function u({ message: i, conversationId: o, pageContext: l }, { signal: u, onEvent: d } = {}) {
|
|
85
|
+
let f = null, p = null, m = e(({ name: e, data: t }) => {
|
|
86
|
+
f || p || (e === "done" ? f = t : e === "error" ? p = t : (e === "delta" || e === "reset" || e === "actions") && d?.(e, t));
|
|
87
|
+
}), h = 0, g = (e) => {
|
|
88
|
+
typeof e != "string" || e.length <= h || (m.push(e.slice(h)), h = e.length);
|
|
89
|
+
}, _ = { message: i };
|
|
90
|
+
o && (_.conversationId = o), l != null && (_.pageContext = l);
|
|
91
|
+
let v;
|
|
92
|
+
try {
|
|
93
|
+
v = await r.post(`${c}/chat`, _, {
|
|
94
|
+
responseType: "text",
|
|
95
|
+
headers: { Accept: "text/event-stream" },
|
|
96
|
+
signal: u,
|
|
97
|
+
onDownloadProgress: (e) => g(s(e))
|
|
98
|
+
});
|
|
99
|
+
} catch (e) {
|
|
100
|
+
throw a(e, u);
|
|
101
|
+
}
|
|
102
|
+
if (g(v.data), m.end(), p) throw new n(p.code || "unknown", p.message || t);
|
|
103
|
+
if (!f) throw new n("invalid-response", t, v.status);
|
|
104
|
+
return f;
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
sendMessage: u,
|
|
108
|
+
getAllowance: () => o(() => r.get(`${c}/allowance`)),
|
|
109
|
+
listConversations: ({ skip: e, take: t } = {}) => {
|
|
110
|
+
let n = new URLSearchParams();
|
|
111
|
+
e != null && n.append("skip", String(e)), t != null && n.append("take", String(t));
|
|
112
|
+
let i = n.toString();
|
|
113
|
+
return o(() => r.get(`${c}/conversations${i ? `?${i}` : ""}`));
|
|
114
|
+
},
|
|
115
|
+
getConversation: (e) => o(() => r.get(l(e))),
|
|
116
|
+
deleteConversation: async (e) => {
|
|
117
|
+
await o(() => r.delete(l(e)));
|
|
118
|
+
},
|
|
119
|
+
rateMessage: async (e, t, { rating: n, note: i }) => {
|
|
120
|
+
let a = typeof i == "string" ? i.trim() : "";
|
|
121
|
+
await o(() => r.put(`${l(e)}/messages/${encodeURIComponent(t)}/rating`, {
|
|
122
|
+
rating: n,
|
|
123
|
+
note: a || null
|
|
124
|
+
}));
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region src/chatLabels.js
|
|
130
|
+
var l = Object.freeze({
|
|
131
|
+
launcher: "Ask the assistant",
|
|
132
|
+
panelTitle: "Assistant",
|
|
133
|
+
newChat: "New chat",
|
|
134
|
+
close: "Close",
|
|
135
|
+
thread: "Conversation",
|
|
136
|
+
you: "You",
|
|
137
|
+
assistant: "Assistant",
|
|
138
|
+
thinking: "Thinking",
|
|
139
|
+
emptyTitle: "How can I help?",
|
|
140
|
+
emptyText: "Ask a question about what you see on this page.",
|
|
141
|
+
composer: "Your question",
|
|
142
|
+
placeholder: "Ask a question",
|
|
143
|
+
send: "Send",
|
|
144
|
+
composerHint: "Press Enter to send, Shift and Enter for a new line.",
|
|
145
|
+
allowance: (e) => e === 0 ? "You have no questions left today." : e === 1 ? "You have 1 question left today." : `You have ${e} questions left today.`,
|
|
146
|
+
disclaimer: "Answers are written by AI and can be wrong. Check anything important.",
|
|
147
|
+
loadingConversation: "Loading the conversation",
|
|
148
|
+
rateUp: "Helpful",
|
|
149
|
+
rateDown: "Not helpful",
|
|
150
|
+
rated: "Thanks for the feedback.",
|
|
151
|
+
ratingNote: "What was wrong with this answer?",
|
|
152
|
+
ratingNoteHint: "Optional.",
|
|
153
|
+
ratingNoteSend: "Send",
|
|
154
|
+
ratingNoteSkip: "Skip",
|
|
155
|
+
ratingFailed: "Your rating did not save. Please try again.",
|
|
156
|
+
actionRaiseTicket: "New support ticket",
|
|
157
|
+
actionReply: (e) => `Reply on ${e}`,
|
|
158
|
+
actionReopen: (e) => `Reopen ${e}`,
|
|
159
|
+
actionNote: "Nothing is sent until you confirm.",
|
|
160
|
+
actionConfirm: "Confirm",
|
|
161
|
+
actionDismiss: "Not now",
|
|
162
|
+
actionDismissed: "Not sent.",
|
|
163
|
+
actionExpired: "This request expired and was not sent. Ask again if you still need it.",
|
|
164
|
+
actionFailed: "We could not send this. Please try again.",
|
|
165
|
+
actionDoneRaiseTicket: (e) => `Ticket ${e} raised.`,
|
|
166
|
+
actionDoneReply: (e) => `Your reply was added to ${e}.`,
|
|
167
|
+
actionDoneReopen: (e) => `${e} is open again.`,
|
|
168
|
+
viewTicket: "View ticket",
|
|
169
|
+
conversations: "Past chats",
|
|
170
|
+
conversationsEmptyTitle: "No past chats",
|
|
171
|
+
conversationsEmptyText: "Your conversations with the assistant show here.",
|
|
172
|
+
untitled: "Untitled chat",
|
|
173
|
+
deleteConversation: "Delete chat",
|
|
174
|
+
deleteConfirmTitle: "Delete this chat?",
|
|
175
|
+
deleteConfirmMessage: "The conversation is removed for good.",
|
|
176
|
+
deleteConfirm: "Delete",
|
|
177
|
+
deleteFailed: "We could not delete this chat. Please try again.",
|
|
178
|
+
cancel: "Cancel",
|
|
179
|
+
loadMore: "Show more",
|
|
180
|
+
loadFailed: "We could not load your chats. Please try again.",
|
|
181
|
+
retry: "Try again"
|
|
182
|
+
});
|
|
183
|
+
function u(e) {
|
|
184
|
+
return e ? {
|
|
185
|
+
...l,
|
|
186
|
+
...e
|
|
187
|
+
} : l;
|
|
188
|
+
}
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region src/markdownParse.js
|
|
191
|
+
var d = /^[a-z][a-z0-9+.-]*:[a-z0-9_-]+\/[a-z0-9_.~-]+$/i, f = /^\s*```/, p = /^\s*[-*+]\s+(.*)$/, m = /^\s*(\d{1,9})[.)]\s+(.*)$/, h = /^\s{0,3}#{1,6}\s+(.*?)\s*#*\s*$/, g = /^\s*([-*_])(\s*\1){2,}\s*$/, _ = /^\s*\|?\s*:?-{3,}:?\s*(\|\s*:?-{3,}:?\s*)*\|?\s*$/, v = (e) => e.includes("|");
|
|
192
|
+
function y(e) {
|
|
193
|
+
let t = e.trim();
|
|
194
|
+
return t.startsWith("|") && (t = t.slice(1)), t.endsWith("|") && (t = t.slice(0, -1)), t.split("|").map((e) => e.trim());
|
|
195
|
+
}
|
|
196
|
+
function b(e, t) {
|
|
197
|
+
return v(e[t]) && t + 1 < e.length && _.test(e[t + 1]);
|
|
198
|
+
}
|
|
199
|
+
function x(e, t) {
|
|
200
|
+
let n = e[t];
|
|
201
|
+
return f.test(n) || p.test(n) || m.test(n) || h.test(n) || g.test(n) || b(e, t);
|
|
202
|
+
}
|
|
203
|
+
function S(e) {
|
|
204
|
+
let t = String(e ?? "").replace(/\r\n?/g, "\n").split("\n"), n = [], r = 0;
|
|
205
|
+
for (; r < t.length;) {
|
|
206
|
+
let e = t[r];
|
|
207
|
+
if (!e.trim()) {
|
|
208
|
+
r += 1;
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
if (f.test(e)) {
|
|
212
|
+
let e = [];
|
|
213
|
+
for (r += 1; r < t.length && !f.test(t[r]);) e.push(t[r]), r += 1;
|
|
214
|
+
r += 1, n.push({
|
|
215
|
+
type: "code",
|
|
216
|
+
text: e.join("\n")
|
|
217
|
+
});
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
if (b(t, r)) {
|
|
221
|
+
let i = y(e), a = [];
|
|
222
|
+
for (r += 2; r < t.length && t[r].trim() && v(t[r]);) a.push(y(t[r])), r += 1;
|
|
223
|
+
n.push({
|
|
224
|
+
type: "table",
|
|
225
|
+
header: i,
|
|
226
|
+
rows: a
|
|
227
|
+
});
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
if (g.test(e)) {
|
|
231
|
+
n.push({ type: "rule" }), r += 1;
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
let i = h.exec(e);
|
|
235
|
+
if (i) {
|
|
236
|
+
n.push({
|
|
237
|
+
type: "heading",
|
|
238
|
+
text: i[1]
|
|
239
|
+
}), r += 1;
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
let a = m.exec(e);
|
|
243
|
+
if (a || p.test(e)) {
|
|
244
|
+
let e = !!a, i = e ? m : p, o = [];
|
|
245
|
+
for (; r < t.length && t[r].trim();) {
|
|
246
|
+
let n = i.exec(t[r]);
|
|
247
|
+
if (n) o.push(e ? n[2] : n[1]);
|
|
248
|
+
else if (x(t, r)) break;
|
|
249
|
+
else o[o.length - 1] += ` ${t[r].trim()}`;
|
|
250
|
+
r += 1;
|
|
251
|
+
}
|
|
252
|
+
n.push({
|
|
253
|
+
type: "list",
|
|
254
|
+
ordered: e,
|
|
255
|
+
start: e ? Number(a[1]) : 1,
|
|
256
|
+
items: o
|
|
257
|
+
});
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
let o = [e];
|
|
261
|
+
for (r += 1; r < t.length && t[r].trim() && !x(t, r);) o.push(t[r]), r += 1;
|
|
262
|
+
n.push({
|
|
263
|
+
type: "paragraph",
|
|
264
|
+
lines: o
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
return n.map((e, t) => ({
|
|
268
|
+
...e,
|
|
269
|
+
key: t
|
|
270
|
+
}));
|
|
271
|
+
}
|
|
272
|
+
var C = (e) => !!e && /[\p{L}\p{N}]/u.test(e);
|
|
273
|
+
function w(e, t, n) {
|
|
274
|
+
let r = e.indexOf(n, t);
|
|
275
|
+
for (; r !== -1;) {
|
|
276
|
+
let i = e.slice(t, r), a = n.length === 1 && (e[r + 1] === n || e[r - 1] === n), o = n[0] === "_" && C(e[r + n.length]);
|
|
277
|
+
if (i.trim() && !/^\s/.test(i) && !/\s$/.test(i) && !a && !o) return r;
|
|
278
|
+
r = e.indexOf(n, r + 1);
|
|
279
|
+
}
|
|
280
|
+
return -1;
|
|
281
|
+
}
|
|
282
|
+
function T(e) {
|
|
283
|
+
let t = [], n = "", r = () => {
|
|
284
|
+
n && t.push({
|
|
285
|
+
type: "text",
|
|
286
|
+
text: n
|
|
287
|
+
}), n = "";
|
|
288
|
+
}, i = 0;
|
|
289
|
+
for (; i < e.length;) {
|
|
290
|
+
let a = e[i];
|
|
291
|
+
if (a === "`") {
|
|
292
|
+
let n = e.indexOf("`", i + 1);
|
|
293
|
+
if (n > i + 1) {
|
|
294
|
+
r(), t.push({
|
|
295
|
+
type: "code",
|
|
296
|
+
text: e.slice(i + 1, n)
|
|
297
|
+
}), i = n + 1;
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
if ((a === "*" || a === "_") && e[i + 1] === a) {
|
|
302
|
+
let o = a + a, s = w(e, i + 2, o);
|
|
303
|
+
if (s !== -1 && !(a === "_" && C(e[i - 1]))) {
|
|
304
|
+
r(), t.push({
|
|
305
|
+
type: "strong",
|
|
306
|
+
children: T(e.slice(i + 2, s))
|
|
307
|
+
}), i = s + 2;
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
n += o, i += 2;
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
if (a === "*" || a === "_") {
|
|
314
|
+
let n = w(e, i + 1, a);
|
|
315
|
+
if (n !== -1 && !(a === "_" && C(e[i - 1]))) {
|
|
316
|
+
r(), t.push({
|
|
317
|
+
type: "em",
|
|
318
|
+
children: T(e.slice(i + 1, n))
|
|
319
|
+
}), i = n + 1;
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
if (a === "[") {
|
|
324
|
+
let n = /^\[([^\]\n]+)\]\(([^)\s]+)\)/.exec(e.slice(i));
|
|
325
|
+
if (n) {
|
|
326
|
+
r(), t.push({
|
|
327
|
+
type: "link",
|
|
328
|
+
href: n[2],
|
|
329
|
+
children: T(n[1])
|
|
330
|
+
}), i += n[0].length;
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
n += a, i += 1;
|
|
335
|
+
}
|
|
336
|
+
return r(), t.map((e, t) => ({
|
|
337
|
+
...e,
|
|
338
|
+
key: t
|
|
339
|
+
}));
|
|
340
|
+
}
|
|
341
|
+
function E(e, t) {
|
|
342
|
+
if (!t || !d.test(e)) return null;
|
|
343
|
+
let n = t(e);
|
|
344
|
+
return typeof n == "string" && n.startsWith("/") && !n.startsWith("//") ? n : null;
|
|
345
|
+
}
|
|
346
|
+
//#endregion
|
|
347
|
+
export { n as ChatApiError, l as DEFAULT_CHAT_LABELS, c as createChatClient, e as createSseParser, E as linkRoute, u as mergeLabels, S as parseBlocks, T as parseInline };
|