@green-on-grey/ui-kit 1.3.0 → 1.4.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/chat.js CHANGED
@@ -168,22 +168,23 @@ var S = /* @__PURE__ */ new Set([
168
168
  "image/gif",
169
169
  "image/webp",
170
170
  "image/svg+xml"
171
- ]), C = /\.(png|jpe?g|gif|webp|svg)$/, w = /\.(txt|log|json|ya?ml|xml|ini|toml|sql|sh|py|go|js|ts|tsx|java|kt|rb|rs|c|cpp|h|css|html?)$/;
171
+ ]), C = /\.(png|jpe?g|gif|webp|svg)$/, w = /\.(txt|log|json|ya?ml|xml|ini|toml|sql|sh|py|go|js|ts|tsx|java|kt|rb|rs|c|cpp|h|css)$/;
172
172
  function T(e) {
173
173
  let t = (e.mimeType ?? "").toLowerCase().split(";")[0].trim(), n = e.fileName.toLowerCase();
174
- return S.has(t) || (!t || t === "application/octet-stream") && C.test(n) ? "image" : t === "application/pdf" || n.endsWith(".pdf") ? "pdf" : t === "text/markdown" || /\.(md|markdown)$/.test(n) ? "markdown" : t === "text/csv" || t === "text/tab-separated-values" || /\.(csv|tsv)$/.test(n) ? "table" : t.startsWith("text/") || t === "application/json" || t === "application/xml" || w.test(n) ? "text" : null;
174
+ return S.has(t) || (!t || t === "application/octet-stream") && C.test(n) ? "image" : t === "application/pdf" || n.endsWith(".pdf") ? "pdf" : t === "text/markdown" || /\.(md|markdown)$/.test(n) ? "markdown" : t === "text/csv" || t === "text/tab-separated-values" || /\.(csv|tsv)$/.test(n) ? "table" : t === "text/html" || /\.html?$/.test(n) ? "html" : t.startsWith("text/") || t === "application/json" || t === "application/xml" || w.test(n) ? "text" : null;
175
175
  }
176
176
  var E = {
177
177
  image: "image",
178
178
  pdf: "pdf",
179
179
  markdown: "markdown",
180
180
  table: "table",
181
+ html: "globe",
181
182
  text: "source"
182
- };
183
- function D(e, t) {
184
- return t === "pdf" ? "PDF" : t === "markdown" ? "MD" : /\.([a-z0-9]{1,5})$/i.exec(e.fileName)?.[1]?.toUpperCase() ?? (t ? "TXT" : "FILE");
185
- }
183
+ }, D = (e) => E[e];
186
184
  function O(e, t) {
185
+ return t === "pdf" ? "PDF" : t === "markdown" ? "MD" : t === "html" ? "HTML" : /\.([a-z0-9]{1,5})$/i.exec(e.fileName)?.[1]?.toUpperCase() ?? (t ? "TXT" : "FILE");
186
+ }
187
+ function k(e, t) {
187
188
  let n = [
188
189
  "byte",
189
190
  "kilobyte",
@@ -198,7 +199,64 @@ function O(e, t) {
198
199
  maximumFractionDigits: i === 0 ? 0 : 1
199
200
  }).format(r);
200
201
  }
201
- function k(e, t) {
202
+ var A = "default-src 'none'; img-src data: blob:; media-src data: blob:; font-src data:; style-src 'unsafe-inline' data:";
203
+ function j(e) {
204
+ let t = `<meta http-equiv="Content-Security-Policy" content="${A}">`, n = /^\s*<!doctype[^>]*>/i.exec(e)?.[0] ?? "";
205
+ if (typeof DOMParser > "u") return n + t + e.slice(n.length);
206
+ let r = new DOMParser().parseFromString(e, "text/html");
207
+ r.querySelectorAll("script, noscript, iframe, frame, frameset, object, embed, applet, base, link, meta[http-equiv], portal").forEach((e) => e.remove()), r.querySelectorAll("*").forEach((e) => {
208
+ for (let t of Array.from(e.attributes)) {
209
+ let n = t.name.toLowerCase();
210
+ n.startsWith("on") || ee.has(n) && !M.test(t.value) || n === "srcset" && t.value.split(",").some((e) => !M.test(e)) ? e.removeAttribute(t.name) : n === "style" && e.setAttribute("style", N(t.value));
211
+ }
212
+ }), r.querySelectorAll("style").forEach((e) => {
213
+ e.textContent = N(e.textContent ?? "");
214
+ });
215
+ let i = r.createElement("meta");
216
+ return i.setAttribute("http-equiv", "Content-Security-Policy"), i.setAttribute("content", A), r.head.prepend(i), (n ? "<!doctype html>" : "") + r.documentElement.outerHTML;
217
+ }
218
+ var ee = /* @__PURE__ */ new Set([
219
+ "src",
220
+ "href",
221
+ "xlink:href",
222
+ "action",
223
+ "formaction",
224
+ "poster",
225
+ "background",
226
+ "data",
227
+ "ping",
228
+ "lowsrc",
229
+ "dynsrc",
230
+ "manifest",
231
+ "cite",
232
+ "longdesc",
233
+ "codebase",
234
+ "archive",
235
+ "usemap"
236
+ ]), M = /^\s*(data:|blob:|#|$)/i;
237
+ function N(e) {
238
+ return e.replace(/@import[^;]*;?/gi, "").replace(/url\(\s*(['"]?)(.*?)\1\s*\)/gi, (e, t, n) => M.test(n) && n.trim() !== "" ? e : "none");
239
+ }
240
+ var P = {
241
+ png: "image/png",
242
+ jpg: "image/jpeg",
243
+ jpeg: "image/jpeg",
244
+ gif: "image/gif",
245
+ webp: "image/webp",
246
+ svg: "image/svg+xml",
247
+ pdf: "application/pdf",
248
+ md: "text/markdown",
249
+ markdown: "text/markdown",
250
+ csv: "text/csv",
251
+ tsv: "text/tab-separated-values",
252
+ html: "text/html",
253
+ htm: "text/html"
254
+ };
255
+ function F(e) {
256
+ let t = (e.mimeType ?? "").split(";")[0].trim().toLowerCase();
257
+ return t && t !== "application/octet-stream" ? t : P[/\.([a-z0-9]+)$/i.exec(e.fileName)?.[1]?.toLowerCase() ?? ""] ?? (t || void 0);
258
+ }
259
+ function I(e, t) {
202
260
  if (t) return e.replace(/\r?\n$/, "").split(/\r?\n/).map((e) => e.split(" "));
203
261
  let n = [], r = [], i = "", a = !1;
204
262
  for (let t = 0; t < e.length; t++) {
@@ -207,7 +265,7 @@ function k(e, t) {
207
265
  }
208
266
  return (i !== "" || r.length > 0) && (r.push(i), n.push(r)), n;
209
267
  }
210
- function A(e, t, n = !0) {
268
+ function L(e, t, n = !0) {
211
269
  let [r, i] = h({}), { id: a, href: o, fileName: s, mimeType: c, size: l } = e;
212
270
  return d(() => {
213
271
  if (!n) return;
@@ -220,10 +278,13 @@ function A(e, t, n = !0) {
220
278
  size: l
221
279
  }).then((t) => {
222
280
  if (!r) return;
223
- let n = c && t.type !== c ? new Blob([t], { type: c }) : t;
224
- e = URL.createObjectURL(n), i({
281
+ let n = F({
282
+ fileName: s,
283
+ mimeType: c
284
+ }), a = n && t.type !== n ? new Blob([t], { type: n }) : t;
285
+ e = URL.createObjectURL(a), i({
225
286
  url: e,
226
- blob: n
287
+ blob: a
227
288
  });
228
289
  }, () => r && i({ failed: !0 })), () => {
229
290
  r = !1, e && URL.revokeObjectURL(e);
@@ -238,9 +299,9 @@ function A(e, t, n = !0) {
238
299
  l
239
300
  ]), r;
240
301
  }
241
- function j({ a: e, load: t, onOpen: n }) {
242
- let r = a(), { url: i, failed: o } = A(e, t);
243
- return o ? /* @__PURE__ */ c(M, {
302
+ function R({ a: e, load: t, onOpen: n }) {
303
+ let r = a(), { url: i, failed: o } = L(e, t);
304
+ return o ? /* @__PURE__ */ c(z, {
244
305
  a: e,
245
306
  kind: "image",
246
307
  onOpen: n
@@ -262,7 +323,7 @@ function j({ a: e, load: t, onOpen: n }) {
262
323
  })]
263
324
  });
264
325
  }
265
- function M({ a: e, kind: n, onOpen: r }) {
326
+ function z({ a: e, kind: n, onOpen: r }) {
266
327
  let i = a(), { i18n: u } = g(o), d = n !== null && r !== void 0, f = /* @__PURE__ */ l(s, { children: [
267
328
  /* @__PURE__ */ l("span", {
268
329
  className: "att-ic",
@@ -271,7 +332,7 @@ function M({ a: e, kind: n, onOpen: r }) {
271
332
  size: 24
272
333
  }), /* @__PURE__ */ c("span", {
273
334
  className: "att-kl",
274
- children: D(e, n)
335
+ children: O(e, n)
275
336
  })]
276
337
  }),
277
338
  /* @__PURE__ */ c("span", {
@@ -280,7 +341,7 @@ function M({ a: e, kind: n, onOpen: r }) {
280
341
  }),
281
342
  e.size != null && /* @__PURE__ */ c("span", {
282
343
  className: "att-size",
283
- children: O(e.size, u.language)
344
+ children: k(e.size, u.language)
284
345
  })
285
346
  ] });
286
347
  return d ? /* @__PURE__ */ c("button", {
@@ -299,16 +360,16 @@ function M({ a: e, kind: n, onOpen: r }) {
299
360
  children: f
300
361
  });
301
362
  }
302
- function N({ items: e, load: t, onOpen: n }) {
363
+ function B({ items: e, load: t, onOpen: n }) {
303
364
  return /* @__PURE__ */ c("div", {
304
365
  className: "atts",
305
366
  children: e.map((e) => {
306
367
  let r = t && n ? () => n(e) : void 0, i = T(e);
307
- return t && r && i === "image" ? /* @__PURE__ */ c(j, {
368
+ return t && r && i === "image" ? /* @__PURE__ */ c(R, {
308
369
  a: e,
309
370
  load: t,
310
371
  onOpen: r
311
- }, e.id) : /* @__PURE__ */ c(M, {
372
+ }, e.id) : /* @__PURE__ */ c(z, {
312
373
  a: e,
313
374
  kind: i,
314
375
  onOpen: r
@@ -316,8 +377,8 @@ function N({ items: e, load: t, onOpen: n }) {
316
377
  })
317
378
  });
318
379
  }
319
- function P({ text: e, tab: t }) {
320
- let n = a(), [r, ...i] = k(e, t), o = i.slice(0, 500);
380
+ function V({ text: e, tab: t }) {
381
+ let n = a(), [r, ...i] = I(e, t), o = i.slice(0, 500);
321
382
  return /* @__PURE__ */ l("div", {
322
383
  className: "att-table",
323
384
  children: [/* @__PURE__ */ l("table", { children: [r && /* @__PURE__ */ c("thead", { children: /* @__PURE__ */ c("tr", { children: r.map((e, t) => /* @__PURE__ */ c("th", { children: e }, t)) }) }), /* @__PURE__ */ c("tbody", { children: o.map((e, t) => /* @__PURE__ */ c("tr", { children: e.map((e, t) => /* @__PURE__ */ c("td", { children: e }, t)) }, t)) })] }), i.length > o.length && /* @__PURE__ */ c("div", {
@@ -329,32 +390,32 @@ function P({ text: e, tab: t }) {
329
390
  })]
330
391
  });
331
392
  }
332
- function ee({ a: e, load: i, onClose: u }) {
333
- let f = a(), { i18n: p } = g(o), m = T(e), _ = m === "markdown" || m === "table" || m === "text", v = _ && (e.size ?? 0) > 1048576, { url: y, blob: b, failed: x } = A(e, i, !v), [S, C] = h(null), w = v || _ && (b?.size ?? 0) > 1048576;
393
+ function te({ a: e, load: i, onClose: u }) {
394
+ let f = a(), { i18n: p } = g(o), m = T(e), _ = m === "markdown" || m === "table" || m === "html" || m === "text", [v, y] = h(!1), b = _ && (e.size ?? 0) > 1048576, { url: x, blob: S, failed: C } = L(e, i, !b), [w, E] = h(null), D = b || _ && (S?.size ?? 0) > 1048576;
334
395
  d(() => {
335
- _ && b && !w && b.arrayBuffer().then((e) => {
396
+ _ && S && !D && S.arrayBuffer().then((e) => {
336
397
  try {
337
- C({ text: new TextDecoder("utf-8", { fatal: !0 }).decode(e) });
398
+ E({ text: new TextDecoder("utf-8", { fatal: !0 }).decode(e) });
338
399
  } catch {
339
- C({ text: null });
400
+ E({ text: null });
340
401
  }
341
- }, () => C({ text: null }));
402
+ }, () => E({ text: null }));
342
403
  }, [
343
404
  _,
344
- b,
345
- w
405
+ S,
406
+ D
346
407
  ]);
347
- let E = S?.text, D;
348
- return D = x ? /* @__PURE__ */ c("div", {
408
+ let O = w?.text, A;
409
+ return A = C ? /* @__PURE__ */ c("div", {
349
410
  className: "att-msg err-text",
350
411
  children: f("chat.files.failed")
351
- }) : w ? /* @__PURE__ */ c("div", {
412
+ }) : D ? /* @__PURE__ */ c("div", {
352
413
  className: "att-msg",
353
414
  children: f("chat.files.tooLarge")
354
- }) : S && E === null ? /* @__PURE__ */ c("div", {
415
+ }) : w && O === null ? /* @__PURE__ */ c("div", {
355
416
  className: "att-msg",
356
417
  children: f("chat.files.notUtf8")
357
- }) : !y || _ && E == null ? /* @__PURE__ */ l("div", {
418
+ }) : !x || _ && O == null ? /* @__PURE__ */ l("div", {
358
419
  className: "att-msg",
359
420
  children: [
360
421
  /* @__PURE__ */ c("span", {
@@ -366,11 +427,11 @@ function ee({ a: e, load: i, onClose: u }) {
366
427
  ]
367
428
  }) : m === "image" ? /* @__PURE__ */ c("img", {
368
429
  className: "att-img",
369
- src: y,
430
+ src: x,
370
431
  alt: e.fileName
371
432
  }) : m === "pdf" ? /* @__PURE__ */ c("object", {
372
433
  className: "att-pdf",
373
- data: y,
434
+ data: x,
374
435
  type: "application/pdf",
375
436
  "aria-label": e.fileName,
376
437
  children: /* @__PURE__ */ c("div", {
@@ -379,13 +440,19 @@ function ee({ a: e, load: i, onClose: u }) {
379
440
  })
380
441
  }) : m === "markdown" ? /* @__PURE__ */ c("div", {
381
442
  className: "att-md",
382
- children: /* @__PURE__ */ c(r, { text: E ?? "" })
383
- }) : m === "table" ? /* @__PURE__ */ c(P, {
384
- text: E ?? "",
443
+ children: /* @__PURE__ */ c(r, { text: O ?? "" })
444
+ }) : m === "table" ? /* @__PURE__ */ c(V, {
445
+ text: O ?? "",
385
446
  tab: /\.tsv$/i.test(e.fileName) || e.mimeType === "text/tab-separated-values"
447
+ }) : m === "html" && !v ? /* @__PURE__ */ c("iframe", {
448
+ className: "att-html",
449
+ sandbox: "",
450
+ srcDoc: j(O ?? ""),
451
+ title: e.fileName,
452
+ referrerPolicy: "no-referrer"
386
453
  }) : /* @__PURE__ */ c("pre", {
387
454
  className: "att-text",
388
- children: E
455
+ children: O
389
456
  }), /* @__PURE__ */ c(n, {
390
457
  wide: !0,
391
458
  onClose: u,
@@ -396,45 +463,61 @@ function ee({ a: e, load: i, onClose: u }) {
396
463
  children: e.fileName
397
464
  }), e.size != null && /* @__PURE__ */ c("span", {
398
465
  className: "muted small",
399
- children: O(e.size, p.language)
466
+ children: k(e.size, p.language)
400
467
  })]
401
468
  }),
402
- footer: /* @__PURE__ */ l(s, { children: [/* @__PURE__ */ l("a", {
403
- className: "btn ghost",
404
- href: y ?? e.href,
405
- download: e.fileName,
406
- children: [
407
- /* @__PURE__ */ c(t, {
408
- name: "download",
409
- size: 14
410
- }),
411
- " ",
412
- f("chat.files.download")
413
- ]
414
- }), /* @__PURE__ */ c("button", {
415
- type: "button",
416
- className: "btn primary",
417
- onClick: u,
418
- children: f("close")
419
- })] }),
469
+ footer: /* @__PURE__ */ l(s, { children: [
470
+ m === "html" && /* @__PURE__ */ l("button", {
471
+ type: "button",
472
+ className: "btn ghost",
473
+ onClick: () => y((e) => !e),
474
+ children: [
475
+ /* @__PURE__ */ c(t, {
476
+ name: v ? "globe" : "code",
477
+ size: 14
478
+ }),
479
+ " ",
480
+ f(v ? "chat.files.page" : "chat.files.source")
481
+ ]
482
+ }),
483
+ /* @__PURE__ */ l("a", {
484
+ className: "btn ghost",
485
+ href: x ?? e.href,
486
+ download: e.fileName,
487
+ children: [
488
+ /* @__PURE__ */ c(t, {
489
+ name: "download",
490
+ size: 14
491
+ }),
492
+ " ",
493
+ f("chat.files.download")
494
+ ]
495
+ }),
496
+ /* @__PURE__ */ c("button", {
497
+ type: "button",
498
+ className: "btn primary",
499
+ onClick: u,
500
+ children: f("close")
501
+ })
502
+ ] }),
420
503
  children: /* @__PURE__ */ c("div", {
421
504
  className: `att-view ${m ?? ""}`,
422
- children: D
505
+ children: A
423
506
  })
424
507
  });
425
508
  }
426
509
  //#endregion
427
510
  //#region src/chat/MessageView.tsx
428
- function F(e, t) {
511
+ function H(e, t) {
429
512
  return new Intl.DateTimeFormat(y(t), {
430
513
  hour: "2-digit",
431
514
  minute: "2-digit"
432
515
  }).format(new Date(e));
433
516
  }
434
- function I(e, t) {
517
+ function U(e, t) {
435
518
  return t || e.length <= 3 ? e : e.slice(-2);
436
519
  }
437
- var L = {
520
+ var W = {
438
521
  done: {
439
522
  icon: "check",
440
523
  cls: "ok"
@@ -448,13 +531,13 @@ var L = {
448
531
  cls: "run"
449
532
  }
450
533
  };
451
- function R({ m: e, busy: n, onRetry: i, loadAttachment: a, onOpenAttachment: u }) {
534
+ function ne({ m: e, busy: n, onRetry: i, loadAttachment: a, onOpenAttachment: u }) {
452
535
  let { t: d, i18n: f } = g(o), [p, m] = h(!1);
453
536
  if (e.role === "note") return /* @__PURE__ */ c("div", {
454
537
  className: "sysnote",
455
538
  children: e.text
456
539
  });
457
- if (e.role === "event" && e.event) return /* @__PURE__ */ c(z, { m: e });
540
+ if (e.role === "event" && e.event) return /* @__PURE__ */ c(G, { m: e });
458
541
  let _ = e.mark && /* @__PURE__ */ l("div", {
459
542
  className: "chan",
460
543
  children: [
@@ -465,9 +548,9 @@ function R({ m: e, busy: n, onRetry: i, loadAttachment: a, onOpenAttachment: u }
465
548
  " ",
466
549
  e.mark.text,
467
550
  " · ",
468
- F(e.createdAt, f.language)
551
+ H(e.createdAt, f.language)
469
552
  ]
470
- }), v = e.attachments && e.attachments.length > 0 && /* @__PURE__ */ c(N, {
553
+ }), v = e.attachments && e.attachments.length > 0 && /* @__PURE__ */ c(B, {
471
554
  items: e.attachments,
472
555
  load: a,
473
556
  onOpen: u
@@ -506,13 +589,13 @@ function R({ m: e, busy: n, onRetry: i, loadAttachment: a, onOpenAttachment: u }
506
589
  "aria-expanded": p,
507
590
  children: p ? d("chat.hideSteps") : d("chat.moreSteps", { count: y.length - 2 })
508
591
  }),
509
- I(y, p).map((e) => /* @__PURE__ */ l("div", {
592
+ U(y, p).map((e) => /* @__PURE__ */ l("div", {
510
593
  className: "tool",
511
594
  title: e.title,
512
595
  children: [/* @__PURE__ */ c(t, {
513
- name: L[e.status].icon,
596
+ name: W[e.status].icon,
514
597
  size: 14,
515
- className: L[e.status].cls
598
+ className: W[e.status].cls
516
599
  }), /* @__PURE__ */ c("span", {
517
600
  className: "tx",
518
601
  children: e.text
@@ -556,7 +639,7 @@ function R({ m: e, busy: n, onRetry: i, loadAttachment: a, onOpenAttachment: u }
556
639
  ]
557
640
  });
558
641
  }
559
- function z({ m: e }) {
642
+ function G({ m: e }) {
560
643
  let { t: n, i18n: r } = g(o), [i, a] = h(!1), s = e.event;
561
644
  return /* @__PURE__ */ l("div", {
562
645
  className: "evdiv",
@@ -572,7 +655,7 @@ function z({ m: e }) {
572
655
  }),
573
656
  s.text,
574
657
  " · ",
575
- F(e.createdAt, r.language),
658
+ H(e.createdAt, r.language),
576
659
  s.details && /* @__PURE__ */ l("button", {
577
660
  type: "button",
578
661
  className: "textbtn",
@@ -594,20 +677,20 @@ function z({ m: e }) {
594
677
  }
595
678
  //#endregion
596
679
  //#region src/chat/transcription.ts
597
- async function te(e, t, n) {
680
+ async function re(e, t, n) {
598
681
  n.busy(!0);
599
682
  let r;
600
683
  try {
601
684
  r = await t(e);
602
685
  } catch (r) {
603
- n.busy(!1), n.failed(r instanceof Error && r.message ? r.message : void 0, () => void te(e, t, n));
686
+ n.busy(!1), n.failed(r instanceof Error && r.message ? r.message : void 0, () => void re(e, t, n));
604
687
  return;
605
688
  }
606
689
  n.busy(!1), r !== null && (r ? n.text(r) : n.empty());
607
690
  }
608
691
  //#endregion
609
692
  //#region src/chat/useRecorder.ts
610
- function ne(e = 300, t) {
693
+ function ie(e = 300, t) {
611
694
  let n = typeof window < "u" && "MediaRecorder" in window && !!navigator.mediaDevices?.getUserMedia, [r, i] = h(!1), [a, o] = h(0), [s, c] = h(0), [l, f] = h(!1), p = m(null), g = m([]), _ = m(void 0), v = m(null), y = m(null), b = m(!1), x = m(t);
612
695
  d(() => {
613
696
  x.current = t;
@@ -669,73 +752,82 @@ function ne(e = 300, t) {
669
752
  cancel: T
670
753
  };
671
754
  }
672
- function re(e) {
755
+ function ae(e) {
673
756
  return `${Math.floor(e / 60)}:${String(e % 60).padStart(2, "0")}`;
674
757
  }
675
758
  //#endregion
676
759
  //#region src/chat/Chat.tsx
677
- function B(n) {
678
- let r = a(), i = e(), [o, u] = h(""), [g, y] = h([]), [b, S] = h(!1), [C, w] = h(null), [T, E] = h(0), [D, O] = h(!1), [k, A] = h(null), [j, M] = h(!1), [N, P] = h(null), F = m(n.loadAttachment);
760
+ function K(n) {
761
+ let r = a(), i = e(), [o, u] = h(""), [g, y] = h([]), [b, S] = h(!1), [C, w] = h(null), [T, E] = h(0), [D, O] = h(!1), [k, A] = h(null), [j, ee] = h(!1), [M, N] = h(null), P = m(n.loadAttachment);
679
762
  d(() => {
680
- F.current = n.loadAttachment;
763
+ P.current = n.loadAttachment;
681
764
  });
682
- let I = !!n.loadAttachment, L = p(() => I ? (e) => F.current ? F.current(e) : Promise.reject(/* @__PURE__ */ Error("no loader")) : void 0, [I]), z = m(!1), B = m(null), V = m(null), H = m(null), U = n.voiceMaxSeconds ?? 300, W = ne(U, () => void me()), { messages: G, busy: K = !1 } = n, ae = n.onPendingChange;
683
- d(() => ae?.(g), [g, ae]);
684
- let q = G[0]?.id, J = G[G.length - 1], Y = J?.id, oe = J?.text.length, se = J?.steps?.length, ce = m({ height: 0 });
765
+ let F = !!n.loadAttachment, I = p(() => F ? (e) => P.current ? P.current(e) : Promise.reject(/* @__PURE__ */ Error("no loader")) : void 0, [F]), L = m(!1), R = m(null), z = m(null), B = m(null), V = n.voiceMaxSeconds ?? 300, H = ie(V, () => void ge()), { messages: U, busy: W = !1 } = n, G = n.onPendingChange;
766
+ d(() => G?.(g), [g, G]);
767
+ let K = U[0]?.id, q = U[U.length - 1], J = q?.id, Y = q?.text.length, le = q?.steps?.length, X = m({ height: 0 });
685
768
  f(() => {
686
- let e = B.current;
769
+ let e = R.current;
687
770
  if (!e) return;
688
- let t = ce.current;
689
- e.scrollTop = t.first !== void 0 && q !== t.first && Y === t.last ? e.scrollTop + (e.scrollHeight - t.height) : e.scrollHeight, ce.current = {
690
- first: q,
691
- last: Y,
771
+ let t = X.current;
772
+ e.scrollTop = t.first !== void 0 && K !== t.first && J === t.last ? e.scrollTop + (e.scrollHeight - t.height) : e.scrollHeight, X.current = {
773
+ first: K,
774
+ last: J,
692
775
  height: e.scrollHeight
693
776
  };
694
777
  }, [
695
- G.length,
696
- q,
778
+ U.length,
779
+ K,
780
+ J,
697
781
  Y,
698
- oe,
699
- se
782
+ le
700
783
  ]);
701
- let X = n.commands && !C && o.startsWith("/") && !/\s/.test(o) ? o.slice(1) : null, Z = X === null ? [] : _(n.commands ?? [], X), Q = X !== null && !D, le = () => {
702
- u(""), y([]), w(null), A(null), z.current = !1;
703
- }, ue = async (e, t) => {
784
+ let Z = n.commands && !C && o.startsWith("/") && !/\s/.test(o) ? o.slice(1) : null, Q = Z === null ? [] : _(n.commands ?? [], Z), $ = Z !== null && !D, ue = () => {
785
+ u(""), y([]), w(null), A(null), L.current = !1;
786
+ }, de = async (e, t) => {
704
787
  if (n.onCommand) try {
705
- await n.onCommand(e, t), le();
788
+ await n.onCommand(e, t), ue();
706
789
  } catch {}
707
- }, $ = async (e, t = !1) => {
790
+ }, fe = async (e, t = !1) => {
708
791
  let r = e.trim();
709
- if (!(!r && g.length === 0 && !C || K || n.readOnly)) {
792
+ if (!(!r && g.length === 0 && !C || W || n.readOnly)) {
710
793
  if (!t && !C && n.commands && r.startsWith("/")) {
711
794
  let [e, ...t] = r.slice(1).split(/\s+/), i = n.commands.find((t) => t.kind === "command" && t.name === e);
712
- if (i) return ue(i.name, t.join(" "));
795
+ if (i) return de(i.name, t.join(" "));
713
796
  if (e && !r.includes("\n")) {
714
797
  A("/" + e);
715
798
  return;
716
799
  }
717
800
  }
718
801
  try {
719
- await n.onSend(r, g.map((e) => e.id), z.current, C ?? void 0), le();
802
+ await n.onSend(r, g.map((e) => e.id), L.current, C ?? void 0), ue();
720
803
  } catch {}
721
804
  }
722
- }, de = (e) => {
723
- E(0), e.kind === "skill" ? (w(e.name), u("")) : e.takesText ? u("/" + e.name + " ") : ue(e.name, ""), H.current?.focus();
724
- }, fe = (e) => {
725
- if (Q && Z.length > 0) {
805
+ }, pe = (e) => {
806
+ E(0), e.kind === "skill" ? (w(e.name), u("")) : e.takesText ? u("/" + e.name + " ") : de(e.name, ""), B.current?.focus();
807
+ }, me = (e) => {
808
+ if ($ && Q.length > 0) {
726
809
  if (e.key === "ArrowDown" || e.key === "ArrowUp") {
727
810
  e.preventDefault();
728
811
  let t = e.key === "ArrowDown" ? 1 : -1;
729
- E((e) => (e + t + Z.length) % Z.length);
812
+ E((e) => (e + t + Q.length) % Q.length);
730
813
  return;
731
814
  }
732
815
  if (e.key === "Enter" && !e.shiftKey || e.key === "Tab") {
733
- e.preventDefault(), de(Z[Math.min(T, Z.length - 1)]);
816
+ e.preventDefault(), pe(Q[Math.min(T, Q.length - 1)]);
734
817
  return;
735
818
  }
736
819
  }
737
- Q && e.key === "Escape" ? (e.preventDefault(), O(!0)) : e.key === "Backspace" && C && o === "" ? w(null) : e.key === "Enter" && !e.shiftKey && !e.nativeEvent.isComposing && (e.preventDefault(), $(o));
738
- }, pe = async (e) => {
820
+ $ && e.key === "Escape" ? (e.preventDefault(), O(!0)) : e.key === "Backspace" && C && o === "" ? w(null) : e.key === "Enter" && !e.shiftKey && !e.nativeEvent.isComposing && !se() && (e.preventDefault(), fe(o));
821
+ };
822
+ f(() => ce(B.current), [o]), d(() => {
823
+ let e = B.current;
824
+ if (!e || typeof ResizeObserver > "u") return;
825
+ let t = e.clientWidth, n = new ResizeObserver(() => {
826
+ e.clientWidth !== t && (t = e.clientWidth, ce(e));
827
+ });
828
+ return n.observe(e), () => n.disconnect();
829
+ }, [H.recording]);
830
+ let he = async (e) => {
739
831
  if (e?.length && n.onUpload) {
740
832
  S(!0);
741
833
  for (let t of Array.from(e)) {
@@ -750,13 +842,13 @@ function B(n) {
750
842
  let e = await n.onUpload(t).catch(() => null);
751
843
  e && y((t) => [...t, e]);
752
844
  }
753
- S(!1), V.current && (V.current.value = "");
845
+ S(!1), z.current && (z.current.value = "");
754
846
  }
755
847
  };
756
- async function me() {
757
- let e = await W.stop();
758
- e && n.onTranscribe && await te(e, n.onTranscribe, {
759
- busy: M,
848
+ async function ge() {
849
+ let e = await H.stop();
850
+ e && n.onTranscribe && await re(e, n.onTranscribe, {
851
+ busy: ee,
760
852
  empty: () => i({
761
853
  kind: "error",
762
854
  title: r("chat.voice.notRecognized")
@@ -771,13 +863,13 @@ function B(n) {
771
863
  }]
772
864
  }),
773
865
  text: (e) => {
774
- z.current = !0, u((t) => t.trim() ? t.trimEnd() + " " + e : e), H.current?.focus();
866
+ L.current = !0, u((t) => t.trim() ? t.trimEnd() + " " + e : e), B.current?.focus();
775
867
  }
776
868
  });
777
869
  }
778
- let he = (e) => {
779
- e.key === "Escape" && W.recording && (e.preventDefault(), W.cancel());
780
- }, ge = C ? r("chat.skillPlaceholder") : r("chat.placeholder", { name: n.agentName }), _e = U - W.seconds;
870
+ let _e = (e) => {
871
+ e.key === "Escape" && H.recording && (e.preventDefault(), H.cancel());
872
+ }, ve = C ? r("chat.skillPlaceholder") : r("chat.placeholder", { name: n.agentName }), ye = V - H.seconds;
781
873
  return /* @__PURE__ */ l("section", {
782
874
  className: "nb-chat",
783
875
  "aria-label": r("chat.title"),
@@ -785,7 +877,7 @@ function B(n) {
785
877
  n.header,
786
878
  /* @__PURE__ */ l("div", {
787
879
  className: "msgs",
788
- ref: B,
880
+ ref: R,
789
881
  "aria-live": "polite",
790
882
  children: [
791
883
  n.hasOlder && n.onLoadOlder && /* @__PURE__ */ c("button", {
@@ -799,7 +891,7 @@ function B(n) {
799
891
  className: "err-text",
800
892
  children: n.historyError
801
893
  }),
802
- G.length === 0 && !n.loading && !n.historyError && /* @__PURE__ */ l("div", {
894
+ U.length === 0 && !n.loading && !n.historyError && /* @__PURE__ */ l("div", {
803
895
  className: "empty",
804
896
  children: [
805
897
  /* @__PURE__ */ c("div", {
@@ -810,12 +902,12 @@ function B(n) {
810
902
  n.emptyHint
811
903
  ]
812
904
  }),
813
- G.map((e) => /* @__PURE__ */ c(R, {
905
+ U.map((e) => /* @__PURE__ */ c(ne, {
814
906
  m: e,
815
- busy: K,
907
+ busy: W,
816
908
  onRetry: n.onRetry && (() => n.onRetry?.(e.id)),
817
- loadAttachment: L,
818
- onOpenAttachment: P
909
+ loadAttachment: I,
910
+ onOpenAttachment: N
819
911
  }, e.id)),
820
912
  n.onConfirm && (n.confirmations ?? []).map((e) => /* @__PURE__ */ l("div", {
821
913
  className: "confirm",
@@ -857,10 +949,10 @@ function B(n) {
857
949
  }) : /* @__PURE__ */ l("div", {
858
950
  className: "composer-wrap",
859
951
  children: [
860
- Q && /* @__PURE__ */ c(v, {
861
- items: Z,
862
- active: Math.min(T, Math.max(Z.length - 1, 0)),
863
- onPick: de,
952
+ $ && /* @__PURE__ */ c(v, {
953
+ items: Q,
954
+ active: Math.min(T, Math.max(Q.length - 1, 0)),
955
+ onPick: pe,
864
956
  onHover: E
865
957
  }),
866
958
  n.aboveComposer,
@@ -896,29 +988,29 @@ function B(n) {
896
988
  children: [r("chat.unknownCommand", { name: k }), /* @__PURE__ */ c("button", {
897
989
  type: "button",
898
990
  className: "textbtn",
899
- onClick: () => void $(o, !0),
991
+ onClick: () => void fe(o, !0),
900
992
  children: r("chat.sendAsText")
901
993
  })]
902
994
  }),
903
995
  /* @__PURE__ */ l("div", {
904
996
  className: "composer",
905
997
  children: [
906
- n.onUpload && !W.recording && /* @__PURE__ */ l(s, { children: [/* @__PURE__ */ c("button", {
998
+ n.onUpload && !H.recording && /* @__PURE__ */ l(s, { children: [/* @__PURE__ */ c("button", {
907
999
  className: "iconbtn",
908
1000
  "aria-label": r("chat.attach"),
909
1001
  disabled: b,
910
- onClick: () => V.current?.click(),
1002
+ onClick: () => z.current?.click(),
911
1003
  children: /* @__PURE__ */ c(t, { name: "clip" })
912
1004
  }), /* @__PURE__ */ c("input", {
913
- ref: V,
1005
+ ref: z,
914
1006
  type: "file",
915
1007
  multiple: !0,
916
1008
  hidden: !0,
917
1009
  accept: n.upload?.accept,
918
- onChange: (e) => pe(e.target.files)
1010
+ onChange: (e) => he(e.target.files)
919
1011
  })] }),
920
- W.recording ? /* @__PURE__ */ l("div", {
921
- className: `recbar${_e <= 15 ? " ending" : ""}`,
1012
+ H.recording ? /* @__PURE__ */ l("div", {
1013
+ className: `recbar${ye <= 15 ? " ending" : ""}`,
922
1014
  role: "status",
923
1015
  "aria-label": r("chat.voice.recordingNow"),
924
1016
  children: [
@@ -929,27 +1021,27 @@ function B(n) {
929
1021
  /* @__PURE__ */ l("span", {
930
1022
  className: "tm",
931
1023
  children: [
932
- re(W.seconds),
1024
+ ae(H.seconds),
933
1025
  " / ",
934
- re(U)
1026
+ ae(V)
935
1027
  ]
936
1028
  }),
937
1029
  /* @__PURE__ */ c("span", {
938
1030
  className: "lvl",
939
1031
  "aria-hidden": "true",
940
- children: /* @__PURE__ */ c("i", { style: { transform: `scaleX(${Math.max(.04, W.level)})` } })
1032
+ children: /* @__PURE__ */ c("i", { style: { transform: `scaleX(${Math.max(.04, H.level)})` } })
941
1033
  }),
942
1034
  /* @__PURE__ */ c("button", {
943
1035
  type: "button",
944
1036
  className: "btn ghost sm",
945
- onClick: W.cancel,
1037
+ onClick: H.cancel,
946
1038
  children: r("cancel")
947
1039
  }),
948
1040
  /* @__PURE__ */ c("button", {
949
1041
  type: "button",
950
1042
  className: "btn primary sm",
951
- onKeyDown: he,
952
- onClick: () => void me(),
1043
+ onKeyDown: _e,
1044
+ onClick: () => void ge(),
953
1045
  children: r("chat.voice.done")
954
1046
  })
955
1047
  ]
@@ -979,31 +1071,31 @@ function B(n) {
979
1071
  })
980
1072
  ]
981
1073
  }), /* @__PURE__ */ c("textarea", {
982
- ref: H,
1074
+ ref: B,
983
1075
  rows: 1,
984
1076
  value: o,
985
- placeholder: j ? r("chat.voice.recognizing") : ge,
986
- "aria-label": ge,
1077
+ placeholder: j ? r("chat.voice.recognizing") : ve,
1078
+ "aria-label": ve,
987
1079
  disabled: j,
988
- "aria-expanded": Q,
1080
+ "aria-expanded": $,
989
1081
  "aria-autocomplete": n.commands ? "list" : void 0,
990
1082
  onChange: (e) => {
991
1083
  u(e.target.value), O(!1), E(0), A(null);
992
1084
  },
993
- onKeyDown: fe
1085
+ onKeyDown: me
994
1086
  })]
995
1087
  }),
996
- n.context && !W.recording && /* @__PURE__ */ c(x, {
1088
+ n.context && !H.recording && /* @__PURE__ */ c(x, {
997
1089
  context: n.context,
998
1090
  onCompact: n.onCompact,
999
1091
  onReset: n.onReset
1000
1092
  }),
1001
- n.onTranscribe && !W.recording && /* @__PURE__ */ c(ie, {
1002
- supported: W.supported,
1093
+ n.onTranscribe && !H.recording && /* @__PURE__ */ c(oe, {
1094
+ supported: H.supported,
1003
1095
  recognizing: j,
1004
- onStart: () => void W.start()
1096
+ onStart: () => void H.start()
1005
1097
  }),
1006
- !W.recording && (n.onCancel && K ? /* @__PURE__ */ c("button", {
1098
+ !H.recording && (n.onCancel && W ? /* @__PURE__ */ c("button", {
1007
1099
  className: "iconbtn fill",
1008
1100
  "aria-label": r("chat.stop"),
1009
1101
  onClick: n.onCancel,
@@ -1011,28 +1103,28 @@ function B(n) {
1011
1103
  }) : /* @__PURE__ */ c("button", {
1012
1104
  className: "iconbtn fill",
1013
1105
  "aria-label": r("chat.send"),
1014
- disabled: !o.trim() && g.length === 0 && !C || K || j,
1015
- onClick: () => $(o),
1106
+ disabled: !o.trim() && g.length === 0 && !C || W || j,
1107
+ onClick: () => fe(o),
1016
1108
  children: /* @__PURE__ */ c(t, { name: "send" })
1017
1109
  }))
1018
1110
  ]
1019
1111
  }),
1020
- W.error && /* @__PURE__ */ c("div", {
1112
+ H.error && /* @__PURE__ */ c("div", {
1021
1113
  className: "err-text",
1022
1114
  style: { padding: "0 12px 8px" },
1023
1115
  children: r("chat.voice.micDenied")
1024
1116
  })
1025
1117
  ]
1026
1118
  }),
1027
- N && L && /* @__PURE__ */ c(ee, {
1028
- a: N,
1029
- load: L,
1030
- onClose: () => P(null)
1119
+ M && I && /* @__PURE__ */ c(te, {
1120
+ a: M,
1121
+ load: I,
1122
+ onClose: () => N(null)
1031
1123
  })
1032
1124
  ]
1033
1125
  });
1034
1126
  }
1035
- function ie({ supported: e, recognizing: n, onStart: r }) {
1127
+ function oe({ supported: e, recognizing: n, onStart: r }) {
1036
1128
  let i = a();
1037
1129
  return n ? /* @__PURE__ */ l("span", {
1038
1130
  className: "voicewait",
@@ -1055,9 +1147,15 @@ function ie({ supported: e, recognizing: n, onStart: r }) {
1055
1147
  children: /* @__PURE__ */ c(t, { name: "mic" })
1056
1148
  });
1057
1149
  }
1150
+ function se() {
1151
+ return typeof window < "u" && !!window.matchMedia?.("(hover: none) and (pointer: coarse)").matches;
1152
+ }
1153
+ function ce(e) {
1154
+ e && (e.style.height = "auto", e.style.height = `${e.scrollHeight + e.offsetHeight - e.clientHeight}px`);
1155
+ }
1058
1156
  //#endregion
1059
1157
  //#region src/chat/ConversationList.tsx
1060
- function V({ conversations: e, currentId: n, open: r, onPick: i, onClose: o, onCreate: u }) {
1158
+ function q({ conversations: e, currentId: n, open: r, onPick: i, onClose: o, onCreate: u }) {
1061
1159
  let f = a(), [p, m] = h(!1);
1062
1160
  d(() => {
1063
1161
  if (!r) return;
@@ -1133,19 +1231,19 @@ function V({ conversations: e, currentId: n, open: r, onPick: i, onClose: o, onC
1133
1231
  "aria-label": f("close"),
1134
1232
  onClick: o
1135
1233
  }),
1136
- p && u && /* @__PURE__ */ c(U, {
1234
+ p && u && /* @__PURE__ */ c(Y, {
1137
1235
  onClose: () => m(!1),
1138
1236
  onCreate: u
1139
1237
  })
1140
1238
  ] });
1141
1239
  }
1142
- function H({ narrow: e, children: t }) {
1240
+ function J({ narrow: e, children: t }) {
1143
1241
  return /* @__PURE__ */ c("div", {
1144
1242
  className: `nb-app${e ? " narrow" : ""}`,
1145
1243
  children: t
1146
1244
  });
1147
1245
  }
1148
- function U({ onClose: e, onCreate: t }) {
1246
+ function Y({ onClose: e, onCreate: t }) {
1149
1247
  let r = a(), [i, o] = h(""), [u, d] = h(!1), [f, p] = h(null), m = async () => {
1150
1248
  if (i.trim() && !u) {
1151
1249
  d(!0), p(null);
@@ -1197,7 +1295,7 @@ function U({ onClose: e, onCreate: t }) {
1197
1295
  }
1198
1296
  //#endregion
1199
1297
  //#region src/chat/AgentMenu.tsx
1200
- function W({ icon: e, label: n, title: r, expanded: i, small: a, disabled: o, onClick: s }) {
1298
+ function le({ icon: e, label: n, title: r, expanded: i, small: a, disabled: o, onClick: s }) {
1201
1299
  return /* @__PURE__ */ c("button", {
1202
1300
  type: "button",
1203
1301
  className: `agentbtn${a ? " s" : ""}`,
@@ -1213,7 +1311,7 @@ function W({ icon: e, label: n, title: r, expanded: i, small: a, disabled: o, on
1213
1311
  })
1214
1312
  });
1215
1313
  }
1216
- function G({ label: e, name: n, options: r, value: o, optionsLabel: u, hint: d, narrow: f, models: p, onRename: m, onPick: g, onClose: _ }) {
1314
+ function X({ label: e, name: n, options: r, value: o, optionsLabel: u, hint: d, narrow: f, models: p, onRename: m, onPick: g, onClose: _ }) {
1217
1315
  let v = a(), [y, b] = h(n), x = i(!0, _);
1218
1316
  return /* @__PURE__ */ l("div", {
1219
1317
  className: `agentmenu${f ? " narrow" : ""}`,
@@ -1324,6 +1422,6 @@ function G({ label: e, name: n, options: r, value: o, optionsLabel: u, hint: d,
1324
1422
  });
1325
1423
  }
1326
1424
  //#endregion
1327
- export { W as AgentButton, G as AgentMenu, N as AttachmentList, ee as AttachmentPreview, B as Chat, H as ChatLayout, v as CommandPalette, x as ContextMeter, V as ConversationList, R as MessageView, U as NewTopicModal, ie as VoiceButton, O as fileSize, k as parseTable, T as previewKind, b as tokens, ne as useRecorder };
1425
+ export { le as AgentButton, X as AgentMenu, B as AttachmentList, te as AttachmentPreview, K as Chat, J as ChatLayout, v as CommandPalette, x as ContextMeter, q as ConversationList, ne as MessageView, Y as NewTopicModal, oe as VoiceButton, k as fileSize, I as parseTable, D as previewIcon, T as previewKind, b as tokens, ie as useRecorder };
1328
1426
 
1329
1427
  //# sourceMappingURL=chat.js.map