@webority/ui-elements 0.37.0 → 0.38.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.
Files changed (116) hide show
  1. package/dist/WuiAutocomplete-Comrnbmf.js +13 -0
  2. package/dist/WuiCommandPalette-CKna1GlO.js +2 -0
  3. package/dist/WuiConsentBanner-CFll7vxN.js +201 -0
  4. package/dist/WuiContextMenu-CBy0O4HT.js +1 -0
  5. package/dist/WuiCountrySelect-oLBUHvMM.js +1 -0
  6. package/dist/WuiDatePicker-nB1B3eWW.js +31 -0
  7. package/dist/WuiDateRange-Di5YE9mg.js +25 -0
  8. package/dist/WuiDock-BD2HgMmP.js +1 -0
  9. package/dist/WuiImageCrop-Cr3D2iPo.js +17 -0
  10. package/dist/WuiMultiSelect-BUw-7apM.js +25 -0
  11. package/dist/WuiOtp-BbO_75RB.js +14 -0
  12. package/dist/WuiPhone-GJglNelp.js +15 -0
  13. package/dist/WuiSelect-DvtN4qC2.js +14 -0
  14. package/dist/WuiSlider-Br6V2amU.js +49 -0
  15. package/dist/WuiSortable-Bd7Fz5Ox.js +1 -0
  16. package/dist/WuiTagInput-DzEZooIn.js +6 -0
  17. package/dist/WuiTimePicker-Bolpp93P.js +9 -0
  18. package/dist/WuiTour-DiKZEWeb.js +15 -0
  19. package/dist/WuiTree-SA0QU9AF.js +1 -0
  20. package/dist/WuiWizardStep-DIHxrXn9.js +1 -0
  21. package/dist/anchorOverlay-WcDeH46q.js +1 -0
  22. package/dist/calendarMath-BC2wGCD-.js +1 -0
  23. package/dist/countries-CvmZ2xpG.js +1 -0
  24. package/dist/elementBase-BlsR4tqa.js +1 -0
  25. package/dist/elements/autocomplete.js +1 -6
  26. package/dist/elements/command-palette.js +1 -6
  27. package/dist/elements/consent-banner.js +1 -6
  28. package/dist/elements/context-menu.js +1 -6
  29. package/dist/elements/country-select.js +1 -6
  30. package/dist/elements/date-range.js +1 -6
  31. package/dist/elements/datepicker.js +1 -6
  32. package/dist/elements/dock.js +1 -6
  33. package/dist/elements/image-crop.js +1 -6
  34. package/dist/elements/kanban.js +1 -6
  35. package/dist/elements/multiselect.js +1 -6
  36. package/dist/elements/otp.js +1 -6
  37. package/dist/elements/phone.js +1 -6
  38. package/dist/elements/select.js +1 -6
  39. package/dist/elements/slider.js +1 -6
  40. package/dist/elements/sortable.js +1 -6
  41. package/dist/elements/status-icon.js +1 -6
  42. package/dist/elements/taginput.js +1 -6
  43. package/dist/elements/timepicker.js +1 -6
  44. package/dist/elements/tour.js +1 -6
  45. package/dist/elements/tree.js +1 -6
  46. package/dist/elements/wizard.js +1 -5
  47. package/dist/examples.mobile.json-GS1_MGh9.js +1 -0
  48. package/dist/fileViewerImage-Y9QBn2Rj.js +6 -0
  49. package/dist/fileViewerMedia-CaJaVnjE.js +1 -0
  50. package/dist/fileViewerPdf-BN0zuehw.js +19 -0
  51. package/dist/fileViewerUi-DasgDsU-.js +1 -0
  52. package/dist/focusOrigin-2imUSs-u.js +1 -0
  53. package/dist/formMirror-BgY7zkC3.js +1 -0
  54. package/dist/formatters-BAE__8ye.js +1 -0
  55. package/dist/helpers.js +1 -5
  56. package/dist/iconGlyphs.g-CUm_mfze.js +1 -0
  57. package/dist/kanban-CdELdS3U.js +1 -0
  58. package/dist/listboxKeyNav-DMIvs9d6.js +1 -0
  59. package/dist/max-CNrKnpEj.js +17 -0
  60. package/dist/optionLabel-DsX2fhWs.js +1 -0
  61. package/dist/statusIcons-2X4iGkKL.js +10 -0
  62. package/dist/textMatch-wdY7XLIc.js +1 -0
  63. package/dist/themeTransition-lkmQm8FR.js +1 -0
  64. package/dist/tokenCommit-BKckxgtg.js +2 -0
  65. package/dist/ui-calendar.global.js +1 -1
  66. package/dist/ui-calendar.js +1 -9905
  67. package/dist/ui-chart.js +21 -34563
  68. package/dist/ui-chat-core.js +10 -347
  69. package/dist/ui-chat.js +10 -1066
  70. package/dist/ui-elements.global.js +52 -53
  71. package/dist/ui-elements.js +1 -692
  72. package/dist/ui-file-viewer.js +1 -311
  73. package/dist/ui-rich-text.js +193 -16887
  74. package/dist/wuiHttp-BC8co934.js +1 -0
  75. package/package.json +5 -7
  76. package/dist/WuiAutocomplete-ByxnwJNQ.js +0 -283
  77. package/dist/WuiCommandPalette-CtZ04JxZ.js +0 -130
  78. package/dist/WuiConsentBanner-oVe-jxCO.js +0 -399
  79. package/dist/WuiContextMenu-Bx_U2X3t.js +0 -211
  80. package/dist/WuiCountrySelect-CUAwKnL9.js +0 -28
  81. package/dist/WuiDatePicker-DkNbc-z7.js +0 -325
  82. package/dist/WuiDateRange-BocnVO6L.js +0 -233
  83. package/dist/WuiDock-BSDY9g8Q.js +0 -57
  84. package/dist/WuiImageCrop-1yaAONTk.js +0 -462
  85. package/dist/WuiMultiSelect-BrCGRNCt.js +0 -416
  86. package/dist/WuiOtp-D8-4Pqil.js +0 -128
  87. package/dist/WuiPhone-BvbhiP2r.js +0 -731
  88. package/dist/WuiSelect-BXrpiuXG.js +0 -214
  89. package/dist/WuiSlider-BcU0psYf.js +0 -256
  90. package/dist/WuiSortable-JjJqstSU.js +0 -280
  91. package/dist/WuiTagInput-D1ay3OcL.js +0 -158
  92. package/dist/WuiTimePicker-C7n-VFGt.js +0 -370
  93. package/dist/WuiTour-R5O9l--J.js +0 -205
  94. package/dist/WuiTree-DXP7pGeI.js +0 -393
  95. package/dist/WuiWizardStep-BU5w9_Ds.js +0 -221
  96. package/dist/anchorOverlay-DluGZ8ef.js +0 -23
  97. package/dist/calendarMath-BAF2Jkg_.js +0 -42
  98. package/dist/countries-B-M_LTgS.js +0 -1234
  99. package/dist/elementBase-Bg1xpvup.js +0 -9
  100. package/dist/examples.mobile.json-BMXTGiGC.js +0 -250
  101. package/dist/fileViewerImage-Dky4nQZS.js +0 -185
  102. package/dist/fileViewerMedia-DPk_YcvC.js +0 -133
  103. package/dist/fileViewerPdf-BnIsj-J-.js +0 -15799
  104. package/dist/fileViewerUi-R6hlcShk.js +0 -272
  105. package/dist/formMirror-jGf5M4gk.js +0 -29
  106. package/dist/formatters-DusKbTyV.js +0 -138
  107. package/dist/iconGlyphs.g-Cpg1BUHm.js +0 -215
  108. package/dist/kanban-BIiEMkTK.js +0 -985
  109. package/dist/listboxKeyNav-zts_8d5e.js +0 -36
  110. package/dist/max-BDKx469G.js +0 -14478
  111. package/dist/optionLabel-Dn-I7zyp.js +0 -16
  112. package/dist/statusIcons-C3zjycpa.js +0 -37
  113. package/dist/textMatch-DEUjlkdy.js +0 -27
  114. package/dist/themeTransition-BpCuMnjk.js +0 -589
  115. package/dist/tokenCommit-VWz-2jEf.js +0 -20
  116. package/dist/wuiHttp-oeHs7X_c.js +0 -118
@@ -1,347 +1,10 @@
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 };
1
+ function e(e){let t=``;function n(t){let n=`message`,r=[];for(let e of t.split(`
2
+ `)){if(e===``||e.startsWith(`:`))continue;let t=e.indexOf(`:`),i=t===-1?e:e.slice(0,t),a=t===-1?``:e.slice(t+1);a.startsWith(` `)&&(a=a.slice(1)),i===`event`?n=a:i===`data`&&r.push(a)}if(r.length===0)return;let i;try{i=JSON.parse(r.join(`
3
+ `))}catch{e({name:`error`,data:{code:`invalid-response`,message:null}});return}e({name:n,data:i})}return{push(e){if(!e)return;t=(t+e).replace(/\r\n/g,`
4
+ `).replace(/\r(?!$)/g,`
5
+ `);let r=t.split(`
6
+
7
+ `);t=r.pop();for(let e of r)n(e)},end(){let e=t.replace(/\r$/,``);t=``,e.trim()&&n(e)}}}var t=`Something went wrong. Please try again.`,n=class extends Error{constructor(e,t,n,r=null){super(t),this.name=`ChatApiError`,this.code=e,this.status=n,this.resetsAtUtc=r}};function r(e){if(typeof e==`string`)try{return JSON.parse(e)}catch{return null}return e??null}function i(e,t){return t?.aborted||e?.code===`ERR_CANCELED`||e?.name===`CanceledError`||e?.name===`AbortError`}function a(e,a){if(e instanceof n)return e;if(i(e,a))return new n(`aborted`,`The request was cancelled.`);let o=e?.response;if(!o)return new n(`network`,t);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;return new n(c,l,o.status,u)}async function o(e){try{return(await e()).data}catch(e){throw a(e)}}function s(e){let t=e?.event?.target;if(!(!t||typeof t.responseText!=`string`)&&!(typeof t.status==`number`&&(t.status<200||t.status>=300)))return t.responseText}function c(r,{base:i}){if(typeof i!=`string`||i.trim()===``)throw TypeError(`createChatClient needs a base path, e.g. { base: "/api/assistant" }.`);let c=i.replace(/\/+$/,``),l=e=>`${c}/conversations/${encodeURIComponent(e)}`;async function u({message:i,conversationId:o,pageContext:l},{signal:u,onEvent:d}={}){let f=null,p=null,m=e(({name:e,data:t})=>{f||p||(e===`done`?f=t:e===`error`?p=t:(e===`delta`||e===`reset`||e===`actions`)&&d?.(e,t))}),h=0,g=e=>{typeof e!=`string`||e.length<=h||(m.push(e.slice(h)),h=e.length)},_={message:i};o&&(_.conversationId=o),l!=null&&(_.pageContext=l);let v;try{v=await r.post(`${c}/chat`,_,{responseType:`text`,headers:{Accept:`text/event-stream`},signal:u,onDownloadProgress:e=>g(s(e))})}catch(e){throw a(e,u)}if(g(v.data),m.end(),p)throw new n(p.code||`unknown`,p.message||t);if(!f)throw new n(`invalid-response`,t,v.status);return f}return{sendMessage:u,getAllowance:()=>o(()=>r.get(`${c}/allowance`)),listConversations:({skip:e,take:t}={})=>{let n=new URLSearchParams;e!=null&&n.append(`skip`,String(e)),t!=null&&n.append(`take`,String(t));let i=n.toString();return o(()=>r.get(`${c}/conversations${i?`?${i}`:``}`))},getConversation:e=>o(()=>r.get(l(e))),deleteConversation:async e=>{await o(()=>r.delete(l(e)))},rateMessage:async(e,t,{rating:n,note:i})=>{let a=typeof i==`string`?i.trim():``;await o(()=>r.put(`${l(e)}/messages/${encodeURIComponent(t)}/rating`,{rating:n,note:a||null}))}}}var l=Object.freeze({launcher:`Ask the assistant`,panelTitle:`Assistant`,newChat:`New chat`,close:`Close`,thread:`Conversation`,you:`You`,assistant:`Assistant`,thinking:`Thinking`,emptyTitle:`How can I help?`,emptyText:`Ask a question about what you see on this page.`,composer:`Your question`,placeholder:`Ask a question`,send:`Send`,composerHint:`Press Enter to send, Shift and Enter for a new line.`,allowance:e=>e===0?`You have no questions left today.`:e===1?`You have 1 question left today.`:`You have ${e} questions left today.`,disclaimer:`Answers are written by AI and can be wrong. Check anything important.`,loadingConversation:`Loading the conversation`,rateUp:`Helpful`,rateDown:`Not helpful`,rated:`Thanks for the feedback.`,ratingNote:`What was wrong with this answer?`,ratingNoteHint:`Optional.`,ratingNoteSend:`Send`,ratingNoteSkip:`Skip`,ratingFailed:`Your rating did not save. Please try again.`,actionRaiseTicket:`New support ticket`,actionReply:e=>`Reply on ${e}`,actionReopen:e=>`Reopen ${e}`,actionNote:`Nothing is sent until you confirm.`,actionConfirm:`Confirm`,actionDismiss:`Not now`,actionDismissed:`Not sent.`,actionExpired:`This request expired and was not sent. Ask again if you still need it.`,actionFailed:`We could not send this. Please try again.`,actionDoneRaiseTicket:e=>`Ticket ${e} raised.`,actionDoneReply:e=>`Your reply was added to ${e}.`,actionDoneReopen:e=>`${e} is open again.`,viewTicket:`View ticket`,conversations:`Past chats`,conversationsEmptyTitle:`No past chats`,conversationsEmptyText:`Your conversations with the assistant show here.`,untitled:`Untitled chat`,deleteConversation:`Delete chat`,deleteConfirmTitle:`Delete this chat?`,deleteConfirmMessage:`The conversation is removed for good.`,deleteConfirm:`Delete`,deleteFailed:`We could not delete this chat. Please try again.`,cancel:`Cancel`,loadMore:`Show more`,loadFailed:`We could not load your chats. Please try again.`,retry:`Try again`});function u(e){return e?{...l,...e}:l}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(`|`);function y(e){let t=e.trim();return t.startsWith(`|`)&&(t=t.slice(1)),t.endsWith(`|`)&&(t=t.slice(0,-1)),t.split(`|`).map(e=>e.trim())}function b(e,t){return v(e[t])&&t+1<e.length&&_.test(e[t+1])}function x(e,t){let n=e[t];return f.test(n)||p.test(n)||m.test(n)||h.test(n)||g.test(n)||b(e,t)}function S(e){let t=String(e??``).replace(/\r\n?/g,`
8
+ `).split(`
9
+ `),n=[],r=0;for(;r<t.length;){let e=t[r];if(!e.trim()){r+=1;continue}if(f.test(e)){let e=[];for(r+=1;r<t.length&&!f.test(t[r]);)e.push(t[r]),r+=1;r+=1,n.push({type:`code`,text:e.join(`
10
+ `)});continue}if(b(t,r)){let i=y(e),a=[];for(r+=2;r<t.length&&t[r].trim()&&v(t[r]);)a.push(y(t[r])),r+=1;n.push({type:`table`,header:i,rows:a});continue}if(g.test(e)){n.push({type:`rule`}),r+=1;continue}let i=h.exec(e);if(i){n.push({type:`heading`,text:i[1]}),r+=1;continue}let a=m.exec(e);if(a||p.test(e)){let e=!!a,i=e?m:p,o=[];for(;r<t.length&&t[r].trim();){let n=i.exec(t[r]);if(n)o.push(e?n[2]:n[1]);else if(x(t,r))break;else o[o.length-1]+=` ${t[r].trim()}`;r+=1}n.push({type:`list`,ordered:e,start:e?Number(a[1]):1,items:o});continue}let o=[e];for(r+=1;r<t.length&&t[r].trim()&&!x(t,r);)o.push(t[r]),r+=1;n.push({type:`paragraph`,lines:o})}return n.map((e,t)=>({...e,key:t}))}var C=e=>!!e&&/[\p{L}\p{N}]/u.test(e);function w(e,t,n){let r=e.indexOf(n,t);for(;r!==-1;){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]);if(i.trim()&&!/^\s/.test(i)&&!/\s$/.test(i)&&!a&&!o)return r;r=e.indexOf(n,r+1)}return-1}function T(e){let t=[],n=``,r=()=>{n&&t.push({type:`text`,text:n}),n=``},i=0;for(;i<e.length;){let a=e[i];if(a==="`"){let n=e.indexOf("`",i+1);if(n>i+1){r(),t.push({type:`code`,text:e.slice(i+1,n)}),i=n+1;continue}}if((a===`*`||a===`_`)&&e[i+1]===a){let o=a+a,s=w(e,i+2,o);if(s!==-1&&!(a===`_`&&C(e[i-1]))){r(),t.push({type:`strong`,children:T(e.slice(i+2,s))}),i=s+2;continue}n+=o,i+=2;continue}if(a===`*`||a===`_`){let n=w(e,i+1,a);if(n!==-1&&!(a===`_`&&C(e[i-1]))){r(),t.push({type:`em`,children:T(e.slice(i+1,n))}),i=n+1;continue}}if(a===`[`){let n=/^\[([^\]\n]+)\]\(([^)\s]+)\)/.exec(e.slice(i));if(n){r(),t.push({type:`link`,href:n[2],children:T(n[1])}),i+=n[0].length;continue}}n+=a,i+=1}return r(),t.map((e,t)=>({...e,key:t}))}function E(e,t){if(!t||!d.test(e))return null;let n=t(e);return typeof n==`string`&&n.startsWith(`/`)&&!n.startsWith(`//`)?n:null}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};