@nonoun/native-chat 0.2.1 → 0.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-input-structured-element-CbDnI4zv.js → chat-input-structured-element-C80qP8yg.js} +265 -108
- package/dist/chat-panel-element.d.ts.map +1 -1
- package/dist/feed/chat-feed-element.d.ts +19 -0
- package/dist/feed/chat-feed-element.d.ts.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/message/chat-message-element.d.ts +14 -1
- package/dist/message/chat-message-element.d.ts.map +1 -1
- package/dist/native-chat.css +31 -1
- package/dist/native-chat.js +426 -2
- package/dist/register.js +3 -3
- package/dist/stream/classify.d.ts +19 -0
- package/dist/stream/classify.d.ts.map +1 -0
- package/dist/stream/create-transport.d.ts +19 -0
- package/dist/stream/create-transport.d.ts.map +1 -0
- package/dist/stream/index.d.ts +9 -0
- package/dist/stream/index.d.ts.map +1 -0
- package/dist/stream/parse-json.d.ts +9 -0
- package/dist/stream/parse-json.d.ts.map +1 -0
- package/dist/stream/parse-ndjson.d.ts +9 -0
- package/dist/stream/parse-ndjson.d.ts.map +1 -0
- package/dist/stream/parse-sse.d.ts +9 -0
- package/dist/stream/parse-sse.d.ts.map +1 -0
- package/dist/stream/types.d.ts +42 -0
- package/dist/stream/types.d.ts.map +1 -0
- package/dist/telemetry/emitter.d.ts +20 -0
- package/dist/telemetry/emitter.d.ts.map +1 -0
- package/dist/telemetry/events.d.ts +11 -0
- package/dist/telemetry/events.d.ts.map +1 -0
- package/dist/telemetry/index.d.ts +5 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/redactor.d.ts +17 -0
- package/dist/telemetry/redactor.d.ts.map +1 -0
- package/dist/telemetry/types.d.ts +27 -0
- package/dist/telemetry/types.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/{chat-input-structured-element-CbDnI4zv.js → chat-input-structured-element-C80qP8yg.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NativeElement as e,
|
|
1
|
+
import { NativeElement as e, VirtualScrollController as t, createDisabledEffect as n, signal as r } from "@nonoun/native-ui";
|
|
2
2
|
/**
|
|
3
3
|
* Chat message input with textarea, submit button, and Enter-to-send behavior.
|
|
4
4
|
* @attr {boolean} disabled - Disables interaction
|
|
@@ -10,11 +10,11 @@ import { NativeElement as e, createDisabledEffect as t, signal as n } from "@non
|
|
|
10
10
|
* @fires native:composer-focus - Fired when the composer textarea gains focus
|
|
11
11
|
* @fires native:composer-blur - Fired when the composer textarea loses focus
|
|
12
12
|
*/
|
|
13
|
-
var
|
|
13
|
+
var i = class extends e {
|
|
14
14
|
static observedAttributes = ["disabled", "busy"];
|
|
15
15
|
#e;
|
|
16
|
-
#t =
|
|
17
|
-
#n =
|
|
16
|
+
#t = r(!1);
|
|
17
|
+
#n = r(!1);
|
|
18
18
|
#r = null;
|
|
19
19
|
#i = null;
|
|
20
20
|
constructor() {
|
|
@@ -60,7 +60,7 @@ var r = class extends e {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
setup() {
|
|
63
|
-
super.setup(), this.addEffect(
|
|
63
|
+
super.setup(), this.addEffect(n(this, this.#t, this.#e)), this.deferChildren(() => {
|
|
64
64
|
this.#a(), this.addEffect(() => {
|
|
65
65
|
let e = this.#t.value;
|
|
66
66
|
this.#r && this.#r.toggleAttribute("disabled", e), this.#i && (e ? this.#i.setAttribute("disabled", "") : this.#s());
|
|
@@ -131,10 +131,10 @@ var r = class extends e {
|
|
|
131
131
|
})) && !this.hasAttribute("no-auto-clear") && (this.value = "", this.#i?.setAttribute("disabled", ""));
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
|
-
},
|
|
134
|
+
}, a = class extends e {
|
|
135
135
|
static observedAttributes = ["show-stop", "show-restart"];
|
|
136
|
-
#e =
|
|
137
|
-
#t =
|
|
136
|
+
#e = r(!1);
|
|
137
|
+
#t = r(!1);
|
|
138
138
|
#n = null;
|
|
139
139
|
#r = null;
|
|
140
140
|
#i = null;
|
|
@@ -177,7 +177,7 @@ var r = class extends e {
|
|
|
177
177
|
let i = document.createElement("n-body"), a = document.createElement("n-chat-content");
|
|
178
178
|
i.appendChild(a);
|
|
179
179
|
let o = document.createElement("n-footer");
|
|
180
|
-
o.setAttribute("dividers", ""),
|
|
180
|
+
o.setAttribute("dividers", ""), this.#n = o;
|
|
181
181
|
let s = document.createElement("n-chat-input");
|
|
182
182
|
s.setAttribute("variant", "plain");
|
|
183
183
|
let c = document.createElement("n-textarea");
|
|
@@ -229,12 +229,22 @@ var r = class extends e {
|
|
|
229
229
|
composed: !0
|
|
230
230
|
}));
|
|
231
231
|
};
|
|
232
|
-
},
|
|
233
|
-
static observedAttributes = [
|
|
232
|
+
}, o = 40, s = class extends e {
|
|
233
|
+
static observedAttributes = [
|
|
234
|
+
"auto-scroll",
|
|
235
|
+
"scrollable",
|
|
236
|
+
"virtual",
|
|
237
|
+
"virtual-item-height",
|
|
238
|
+
"virtual-overscan"
|
|
239
|
+
];
|
|
234
240
|
#e;
|
|
235
|
-
#t =
|
|
236
|
-
#n =
|
|
241
|
+
#t = r(!0);
|
|
242
|
+
#n = r(!0);
|
|
237
243
|
#r = null;
|
|
244
|
+
#i = null;
|
|
245
|
+
#a = null;
|
|
246
|
+
#o = r([]);
|
|
247
|
+
#s = null;
|
|
238
248
|
constructor() {
|
|
239
249
|
super(), this.#e = this.attachInternals();
|
|
240
250
|
}
|
|
@@ -248,20 +258,87 @@ var r = class extends e {
|
|
|
248
258
|
behavior: e ? "smooth" : "instant"
|
|
249
259
|
}), this.#n.value = !0;
|
|
250
260
|
}
|
|
261
|
+
/** Data items for virtual rendering. */
|
|
262
|
+
get items() {
|
|
263
|
+
return this.#o.value;
|
|
264
|
+
}
|
|
265
|
+
set items(e) {
|
|
266
|
+
this.#o.value = e, this.#i && this.#i.updateCount(e.length);
|
|
267
|
+
}
|
|
268
|
+
/** Callback that creates an HTMLElement from a data item. */
|
|
269
|
+
get itemRenderer() {
|
|
270
|
+
return this.#s;
|
|
271
|
+
}
|
|
272
|
+
set itemRenderer(e) {
|
|
273
|
+
this.#s = e;
|
|
274
|
+
}
|
|
251
275
|
attributeChangedCallback(e, t, n) {
|
|
252
|
-
|
|
276
|
+
if (t !== n) {
|
|
277
|
+
switch (e) {
|
|
278
|
+
case "auto-scroll":
|
|
279
|
+
this.#t.value = n !== null;
|
|
280
|
+
break;
|
|
281
|
+
case "virtual":
|
|
282
|
+
n === null ? this.#l() : this.#c();
|
|
283
|
+
break;
|
|
284
|
+
case "virtual-item-height":
|
|
285
|
+
this.#i && n && (this.#i.itemHeight = Number(n) || 80);
|
|
286
|
+
break;
|
|
287
|
+
case "virtual-overscan":
|
|
288
|
+
this.#i && n && (this.#i.overscan = Number(n) || 5);
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
super.attributeChangedCallback(e, t, n);
|
|
292
|
+
}
|
|
253
293
|
}
|
|
254
294
|
setup() {
|
|
255
|
-
super.setup(), this.#e.role = "log", this.setAttribute("aria-live", "polite"), this.setAttribute("aria-label", "Conversation"), this.hasAttribute("auto-scroll") || (this.#t.value = !0), this.addEventListener("scroll", this.#
|
|
295
|
+
super.setup(), this.#e.role = "log", this.setAttribute("aria-live", "polite"), this.setAttribute("aria-label", "Conversation"), this.hasAttribute("scrollable") || this.setAttribute("scrollable", ""), this.hasAttribute("auto-scroll") || (this.#t.value = !0), this.addEventListener("scroll", this.#f, { passive: !0 }), this.#r = new MutationObserver(this.#p), this.#r.observe(this, {
|
|
256
296
|
childList: !0,
|
|
257
297
|
subtree: !0
|
|
258
|
-
}), this.addEventListener("native:message-action", this.#
|
|
298
|
+
}), this.addEventListener("native:message-action", this.#m), this.hasAttribute("virtual") && this.#c();
|
|
259
299
|
}
|
|
260
300
|
teardown() {
|
|
261
|
-
this.removeEventListener("scroll", this.#
|
|
301
|
+
this.removeEventListener("scroll", this.#f), this.removeEventListener("native:message-action", this.#m), this.#r?.disconnect(), this.#r = null, this.#l(), super.teardown();
|
|
302
|
+
}
|
|
303
|
+
#c() {
|
|
304
|
+
if (this.#i) return;
|
|
305
|
+
let e = Number(this.getAttribute("virtual-item-height")) || 80, n = Number(this.getAttribute("virtual-overscan")) || 5;
|
|
306
|
+
for (this.#i = new t(this, {
|
|
307
|
+
itemHeight: e,
|
|
308
|
+
overscan: n
|
|
309
|
+
}), this.#a = document.createElement("div"), this.#a.className = "n-chat-feed-virtual-container"; this.firstChild;) this.#a.appendChild(this.firstChild);
|
|
310
|
+
this.appendChild(this.#a), this.#i.enable(this, this.#a, this.#o.value.length), this.addEventListener("native:virtual-change", this.#u);
|
|
311
|
+
}
|
|
312
|
+
#l() {
|
|
313
|
+
if (this.#i && (this.removeEventListener("native:virtual-change", this.#u), this.#i.destroy(), this.#i = null, this.#a)) {
|
|
314
|
+
for (; this.#a.firstChild;) this.insertBefore(this.#a.firstChild, this.#a);
|
|
315
|
+
this.#a.remove(), this.#a = null;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
#u = (e) => {
|
|
319
|
+
let { start: t, end: n, totalCount: r } = e.detail;
|
|
320
|
+
this.dispatchEvent(new CustomEvent("native:range-change", {
|
|
321
|
+
bubbles: !0,
|
|
322
|
+
composed: !0,
|
|
323
|
+
detail: {
|
|
324
|
+
start: t,
|
|
325
|
+
end: n,
|
|
326
|
+
total: r
|
|
327
|
+
}
|
|
328
|
+
})), this.#s && this.#a && this.#d(t, n);
|
|
329
|
+
};
|
|
330
|
+
#d(e, t) {
|
|
331
|
+
if (!this.#a || !this.#s) return;
|
|
332
|
+
let n = this.#o.value, r = Array.from(this.#a.children);
|
|
333
|
+
for (let e of r) !e.classList.contains("n-virtual-spacer-top") && !e.classList.contains("n-virtual-spacer-bottom") && e.remove();
|
|
334
|
+
let i = this.#a.querySelector(".n-virtual-spacer-bottom");
|
|
335
|
+
for (let r = e; r < t && r < n.length; r++) {
|
|
336
|
+
let e = this.#s(n[r], r);
|
|
337
|
+
i ? this.#a.insertBefore(e, i) : this.#a.appendChild(e);
|
|
338
|
+
}
|
|
262
339
|
}
|
|
263
|
-
#
|
|
264
|
-
let e = this.#n.value, t = this.scrollTop + this.clientHeight >= this.scrollHeight -
|
|
340
|
+
#f = () => {
|
|
341
|
+
let e = this.#n.value, t = this.scrollTop + this.clientHeight >= this.scrollHeight - o;
|
|
265
342
|
this.#n.value = t, t !== e && this.dispatchEvent(new CustomEvent("native:feed-scroll", {
|
|
266
343
|
bubbles: !0,
|
|
267
344
|
composed: !0,
|
|
@@ -271,7 +348,7 @@ var r = class extends e {
|
|
|
271
348
|
}
|
|
272
349
|
}));
|
|
273
350
|
};
|
|
274
|
-
#
|
|
351
|
+
#p = () => {
|
|
275
352
|
this.#t.value && this.#n.value && requestAnimationFrame(() => {
|
|
276
353
|
this.scrollTo({
|
|
277
354
|
top: this.scrollHeight,
|
|
@@ -279,16 +356,16 @@ var r = class extends e {
|
|
|
279
356
|
});
|
|
280
357
|
});
|
|
281
358
|
};
|
|
282
|
-
#
|
|
283
|
-
},
|
|
359
|
+
#m = (e) => {};
|
|
360
|
+
}, c = class extends e {
|
|
284
361
|
static observedAttributes = [
|
|
285
362
|
"src",
|
|
286
363
|
"name",
|
|
287
364
|
"icon"
|
|
288
365
|
];
|
|
289
|
-
#e =
|
|
290
|
-
#t =
|
|
291
|
-
#n =
|
|
366
|
+
#e = r("");
|
|
367
|
+
#t = r("");
|
|
368
|
+
#n = r("");
|
|
292
369
|
attributeChangedCallback(e, t, n) {
|
|
293
370
|
if (t !== n) {
|
|
294
371
|
switch (e) {
|
|
@@ -320,7 +397,7 @@ var r = class extends e {
|
|
|
320
397
|
}
|
|
321
398
|
if (n) {
|
|
322
399
|
let e = document.createElement("span");
|
|
323
|
-
e.className = "n-chat-avatar-initials", e.textContent =
|
|
400
|
+
e.className = "n-chat-avatar-initials", e.textContent = l(n), e.setAttribute("aria-hidden", "true"), this.appendChild(e);
|
|
324
401
|
return;
|
|
325
402
|
}
|
|
326
403
|
let r = document.createElement("n-icon");
|
|
@@ -331,10 +408,44 @@ var r = class extends e {
|
|
|
331
408
|
this.textContent = "", super.teardown();
|
|
332
409
|
}
|
|
333
410
|
};
|
|
334
|
-
function
|
|
411
|
+
function l(e) {
|
|
335
412
|
let t = e.trim().split(/\s+/);
|
|
336
413
|
return t.length === 0 ? "" : t.length === 1 ? t[0][0].toUpperCase() : (t[0][0] + t[t.length - 1][0]).toUpperCase();
|
|
337
414
|
}
|
|
415
|
+
const u = {
|
|
416
|
+
copy: {
|
|
417
|
+
label: "Copy",
|
|
418
|
+
icon: "copy"
|
|
419
|
+
},
|
|
420
|
+
retry: {
|
|
421
|
+
label: "Retry",
|
|
422
|
+
icon: "arrow-clockwise"
|
|
423
|
+
},
|
|
424
|
+
edit: {
|
|
425
|
+
label: "Edit",
|
|
426
|
+
icon: "pencil-simple"
|
|
427
|
+
},
|
|
428
|
+
"feedback-up": {
|
|
429
|
+
label: "Helpful",
|
|
430
|
+
icon: "thumbs-up"
|
|
431
|
+
},
|
|
432
|
+
"feedback-down": {
|
|
433
|
+
label: "Not helpful",
|
|
434
|
+
icon: "thumbs-down"
|
|
435
|
+
},
|
|
436
|
+
continue: {
|
|
437
|
+
label: "Continue",
|
|
438
|
+
icon: "arrow-right"
|
|
439
|
+
}
|
|
440
|
+
}, d = {
|
|
441
|
+
assistant: [
|
|
442
|
+
"copy",
|
|
443
|
+
"retry",
|
|
444
|
+
"feedback-up",
|
|
445
|
+
"feedback-down"
|
|
446
|
+
],
|
|
447
|
+
user: ["edit", "retry"]
|
|
448
|
+
};
|
|
338
449
|
/**
|
|
339
450
|
* Individual chat message bubble.
|
|
340
451
|
*
|
|
@@ -344,20 +455,27 @@ function c(e) {
|
|
|
344
455
|
* @attr {string} role - `user` | `assistant` | `system`
|
|
345
456
|
* @attr {string} message-id - Unique message identifier
|
|
346
457
|
* @attr {string} timestamp - Epoch milliseconds
|
|
347
|
-
* @attr {string} status - `sending` | `sent` | `error` | `streaming`
|
|
458
|
+
* @attr {string} status - `sending` | `sent` | `error` | `streaming` | `partial`
|
|
459
|
+
* @attr {string} actions - Comma-separated action list, or `"none"` to suppress
|
|
460
|
+
* @attr {string} actions-style - `"label"` (default) | `"icon"` | `"icon-label"`
|
|
348
461
|
* @fires native:message-action - Fired when an action button is clicked
|
|
462
|
+
* @fires native:continue-request - Fired when continue is requested for a partial message
|
|
349
463
|
*/
|
|
350
|
-
var
|
|
464
|
+
var f = class extends e {
|
|
351
465
|
static observedAttributes = [
|
|
352
466
|
"role",
|
|
353
467
|
"message-id",
|
|
354
468
|
"timestamp",
|
|
355
|
-
"status"
|
|
469
|
+
"status",
|
|
470
|
+
"actions",
|
|
471
|
+
"actions-style"
|
|
356
472
|
];
|
|
357
473
|
#e;
|
|
358
|
-
#t =
|
|
359
|
-
#n =
|
|
360
|
-
#r = null;
|
|
474
|
+
#t = r("assistant");
|
|
475
|
+
#n = r("sent");
|
|
476
|
+
#r = r(null);
|
|
477
|
+
#i = r("label");
|
|
478
|
+
#a = null;
|
|
361
479
|
constructor() {
|
|
362
480
|
super(), this.#e = this.attachInternals();
|
|
363
481
|
}
|
|
@@ -379,6 +497,18 @@ var l = class extends e {
|
|
|
379
497
|
set status(e) {
|
|
380
498
|
this.#n.value = e, this.setAttribute("status", e);
|
|
381
499
|
}
|
|
500
|
+
get actions() {
|
|
501
|
+
return this.#r.value;
|
|
502
|
+
}
|
|
503
|
+
set actions(e) {
|
|
504
|
+
this.#r.value = e, e === null ? this.removeAttribute("actions") : this.setAttribute("actions", e);
|
|
505
|
+
}
|
|
506
|
+
get actionsStyle() {
|
|
507
|
+
return this.#i.value;
|
|
508
|
+
}
|
|
509
|
+
set actionsStyle(e) {
|
|
510
|
+
this.#i.value = e, this.setAttribute("actions-style", e);
|
|
511
|
+
}
|
|
382
512
|
attributeChangedCallback(e, t, n) {
|
|
383
513
|
if (t !== n) {
|
|
384
514
|
switch (e) {
|
|
@@ -388,39 +518,66 @@ var l = class extends e {
|
|
|
388
518
|
case "status":
|
|
389
519
|
this.#n.value = n ?? "sent";
|
|
390
520
|
break;
|
|
521
|
+
case "actions":
|
|
522
|
+
this.#r.value = n;
|
|
523
|
+
break;
|
|
524
|
+
case "actions-style":
|
|
525
|
+
this.#i.value = n ?? "label";
|
|
526
|
+
break;
|
|
391
527
|
}
|
|
392
528
|
super.attributeChangedCallback(e, t, n);
|
|
393
529
|
}
|
|
394
530
|
}
|
|
395
531
|
setup() {
|
|
396
532
|
super.setup(), this.addEffect(() => {
|
|
397
|
-
let e = this.#t.value;
|
|
398
|
-
this.#
|
|
399
|
-
}), this.#e.role = "article", this.addEventListener("native:press", this.#
|
|
533
|
+
let e = this.#t.value, t = this.#r.value, n = this.#i.value, r = this.#n.value;
|
|
534
|
+
this.#o(e, t, n, r);
|
|
535
|
+
}), this.#e.role = "article", this.addEventListener("native:press", this.#s);
|
|
400
536
|
}
|
|
401
537
|
teardown() {
|
|
402
|
-
this.removeEventListener("native:press", this.#
|
|
403
|
-
}
|
|
404
|
-
#
|
|
405
|
-
this.#
|
|
406
|
-
let
|
|
407
|
-
|
|
538
|
+
this.removeEventListener("native:press", this.#s), this.#a = null, super.teardown();
|
|
539
|
+
}
|
|
540
|
+
#o(e, t, n, r) {
|
|
541
|
+
if (this.#a &&= (this.#a.remove(), null), t === "none" || this.querySelector("[slot=\"actions\"]")) return;
|
|
542
|
+
let i;
|
|
543
|
+
if (i = t ? t.split(",").map((e) => e.trim()).filter(Boolean) : d[e] ?? [], r === "partial" && !i.includes("continue") && (i = [...i, "continue"]), i.length === 0) return;
|
|
544
|
+
let a = document.createElement("n-toolbar");
|
|
545
|
+
a.className = "n-chat-message-actions", a.setAttribute("padding", "none"), a.setAttribute("aria-label", "Message actions"), n !== "label" && a.setAttribute("data-style", n);
|
|
546
|
+
for (let e of i) {
|
|
547
|
+
let t = u[e];
|
|
548
|
+
t && a.appendChild(p(e, t, n));
|
|
549
|
+
}
|
|
550
|
+
a.children.length > 0 && (this.appendChild(a), this.#a = a);
|
|
408
551
|
}
|
|
409
|
-
#
|
|
552
|
+
#s = (e) => {
|
|
410
553
|
let t = e.target, n = t?.getAttribute("data-action");
|
|
411
|
-
n && this.#
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
554
|
+
if (n && this.#a?.contains(t)) {
|
|
555
|
+
if (e.stopPropagation(), n === "continue") {
|
|
556
|
+
this.dispatchEvent(new CustomEvent("native:continue-request", {
|
|
557
|
+
bubbles: !0,
|
|
558
|
+
composed: !0,
|
|
559
|
+
detail: { messageId: this.messageId }
|
|
560
|
+
}));
|
|
561
|
+
return;
|
|
417
562
|
}
|
|
418
|
-
|
|
563
|
+
this.dispatchEvent(new CustomEvent("native:message-action", {
|
|
564
|
+
bubbles: !0,
|
|
565
|
+
composed: !0,
|
|
566
|
+
detail: {
|
|
567
|
+
action: n,
|
|
568
|
+
messageId: this.messageId
|
|
569
|
+
}
|
|
570
|
+
}));
|
|
571
|
+
}
|
|
419
572
|
};
|
|
420
573
|
};
|
|
421
|
-
function
|
|
422
|
-
let
|
|
423
|
-
|
|
574
|
+
function p(e, t, n) {
|
|
575
|
+
let r = document.createElement("n-button");
|
|
576
|
+
if (r.setAttribute("variant", "ghost"), r.setAttribute("size", "sm"), r.setAttribute("inline", ""), r.setAttribute("data-action", e), r.setAttribute("aria-label", t.label), n === "icon" || n === "icon-label") {
|
|
577
|
+
let e = document.createElement("n-icon");
|
|
578
|
+
e.setAttribute("name", t.icon), e.setAttribute("slot", "leading"), r.appendChild(e);
|
|
579
|
+
}
|
|
580
|
+
return (n === "label" || n === "icon-label") && r.appendChild(document.createTextNode(t.label)), r;
|
|
424
581
|
}
|
|
425
582
|
/**
|
|
426
583
|
* Message group — cluster of messages from the same sender.
|
|
@@ -440,7 +597,7 @@ function u(e, t) {
|
|
|
440
597
|
* @attr {string} role - `user` | `assistant` | `system`
|
|
441
598
|
* @attr {string} sender - Display name of the sender
|
|
442
599
|
*/
|
|
443
|
-
var
|
|
600
|
+
var m = class extends e {
|
|
444
601
|
static observedAttributes = ["role", "sender"];
|
|
445
602
|
#e;
|
|
446
603
|
constructor() {
|
|
@@ -457,10 +614,10 @@ var d = class extends e {
|
|
|
457
614
|
teardown() {
|
|
458
615
|
super.teardown();
|
|
459
616
|
}
|
|
460
|
-
},
|
|
617
|
+
}, h = class extends e {
|
|
461
618
|
static observedAttributes = ["format"];
|
|
462
|
-
#e =
|
|
463
|
-
#t =
|
|
619
|
+
#e = r("markdown");
|
|
620
|
+
#t = r("");
|
|
464
621
|
#n = null;
|
|
465
622
|
get content() {
|
|
466
623
|
return this.#t.value;
|
|
@@ -481,14 +638,14 @@ var d = class extends e {
|
|
|
481
638
|
super.setup(), this.deferChildren(() => {
|
|
482
639
|
!this.#t.value && this.textContent?.trim() && (this.#t.value = this.textContent.trim()), this.#n = document.createElement("div"), this.#n.className = "n-chat-prose", this.textContent = "", this.appendChild(this.#n), this.addEffect(() => {
|
|
483
640
|
let e = this.#t.value, t = this.#e.value;
|
|
484
|
-
this.#n && (t === "plain" ? this.#n.textContent = e : this.#n.innerHTML =
|
|
641
|
+
this.#n && (t === "plain" ? this.#n.textContent = e : this.#n.innerHTML = y(e));
|
|
485
642
|
});
|
|
486
643
|
});
|
|
487
644
|
}
|
|
488
645
|
teardown() {
|
|
489
646
|
this.#n = null, super.teardown();
|
|
490
647
|
}
|
|
491
|
-
},
|
|
648
|
+
}, g = new Set([
|
|
492
649
|
"p",
|
|
493
650
|
"br",
|
|
494
651
|
"strong",
|
|
@@ -508,14 +665,14 @@ var d = class extends e {
|
|
|
508
665
|
"blockquote",
|
|
509
666
|
"hr"
|
|
510
667
|
]);
|
|
511
|
-
function
|
|
668
|
+
function _(e) {
|
|
512
669
|
return e.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("\"", """).replaceAll("'", "'");
|
|
513
670
|
}
|
|
514
|
-
function
|
|
515
|
-
let t =
|
|
671
|
+
function v(e) {
|
|
672
|
+
let t = _(e);
|
|
516
673
|
return t = t.replace(/`([^`]+)`/g, "<code>$1</code>"), t = t.replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>"), t = t.replace(/__(.+?)__/g, "<strong>$1</strong>"), t = t.replace(/\*(.+?)\*/g, "<em>$1</em>"), t = t.replace(/(?<!\w)_(.+?)_(?!\w)/g, "<em>$1</em>"), t = t.replace(/\[([^\]]+)\]\((https?:\/\/[^)]+)\)/g, "<a href=\"$2\" rel=\"noopener noreferrer\" target=\"_blank\">$1</a>"), t;
|
|
517
674
|
}
|
|
518
|
-
function
|
|
675
|
+
function y(e) {
|
|
519
676
|
if (!e) return "";
|
|
520
677
|
let t = e.split("\n"), n = [], r = 0;
|
|
521
678
|
for (; r < t.length;) {
|
|
@@ -524,14 +681,14 @@ function g(e) {
|
|
|
524
681
|
let i = e.slice(3).trim(), a = [];
|
|
525
682
|
for (r += 1; r < t.length && !t[r].startsWith("```");) a.push(t[r]), r += 1;
|
|
526
683
|
r += 1;
|
|
527
|
-
let o = i ? ` data-lang="${
|
|
528
|
-
n.push(`<pre${o}><code>${
|
|
684
|
+
let o = i ? ` data-lang="${_(i)}"` : "";
|
|
685
|
+
n.push(`<pre${o}><code>${_(a.join("\n"))}</code></pre>`);
|
|
529
686
|
continue;
|
|
530
687
|
}
|
|
531
688
|
let i = e.match(/^(#{1,6})\s+(.+)/);
|
|
532
689
|
if (i) {
|
|
533
690
|
let e = i[1].length;
|
|
534
|
-
n.push(`<h${e}>${
|
|
691
|
+
n.push(`<h${e}>${v(i[2])}</h${e}>`), r += 1;
|
|
535
692
|
continue;
|
|
536
693
|
}
|
|
537
694
|
if (/^---+$/.test(e.trim()) || /^\*\*\*+$/.test(e.trim())) {
|
|
@@ -541,19 +698,19 @@ function g(e) {
|
|
|
541
698
|
if (e.startsWith("> ")) {
|
|
542
699
|
let e = [];
|
|
543
700
|
for (; r < t.length && t[r].startsWith("> ");) e.push(t[r].slice(2)), r += 1;
|
|
544
|
-
n.push(`<blockquote>${
|
|
701
|
+
n.push(`<blockquote>${y(e.join("\n"))}</blockquote>`);
|
|
545
702
|
continue;
|
|
546
703
|
}
|
|
547
704
|
if (/^[-*+]\s/.test(e)) {
|
|
548
705
|
let e = [];
|
|
549
706
|
for (; r < t.length && /^[-*+]\s/.test(t[r]);) e.push(t[r].replace(/^[-*+]\s/, "")), r += 1;
|
|
550
|
-
n.push("<ul>" + e.map((e) => `<li>${
|
|
707
|
+
n.push("<ul>" + e.map((e) => `<li>${v(e)}</li>`).join("") + "</ul>");
|
|
551
708
|
continue;
|
|
552
709
|
}
|
|
553
710
|
if (/^\d+\.\s/.test(e)) {
|
|
554
711
|
let e = [];
|
|
555
712
|
for (; r < t.length && /^\d+\.\s/.test(t[r]);) e.push(t[r].replace(/^\d+\.\s/, "")), r += 1;
|
|
556
|
-
n.push("<ol>" + e.map((e) => `<li>${
|
|
713
|
+
n.push("<ol>" + e.map((e) => `<li>${v(e)}</li>`).join("") + "</ol>");
|
|
557
714
|
continue;
|
|
558
715
|
}
|
|
559
716
|
if (!e.trim()) {
|
|
@@ -562,15 +719,15 @@ function g(e) {
|
|
|
562
719
|
}
|
|
563
720
|
let a = [];
|
|
564
721
|
for (; r < t.length && t[r].trim() && !t[r].startsWith("#") && !t[r].startsWith("```") && !t[r].startsWith("> ") && !/^[-*+]\s/.test(t[r]) && !/^\d+\.\s/.test(t[r]) && !/^---+$/.test(t[r].trim());) a.push(t[r]), r += 1;
|
|
565
|
-
a.length > 0 && n.push(`<p>${
|
|
722
|
+
a.length > 0 && n.push(`<p>${v(a.join("\n"))}</p>`);
|
|
566
723
|
}
|
|
567
724
|
return n.join("");
|
|
568
725
|
}
|
|
569
726
|
/** Sanitize rendered HTML — strip any tags not in allowlist. */
|
|
570
|
-
function
|
|
727
|
+
function b(e) {
|
|
571
728
|
return e.replace(/<\/?([a-zA-Z][a-zA-Z0-9]*)[^>]*>/g, (e, t) => {
|
|
572
729
|
let n = t.toLowerCase();
|
|
573
|
-
return
|
|
730
|
+
return g.has(n) ? e : "";
|
|
574
731
|
});
|
|
575
732
|
}
|
|
576
733
|
/**
|
|
@@ -591,7 +748,7 @@ function _(e) {
|
|
|
591
748
|
* @attr {boolean} expandable - Allow click to expand trace content
|
|
592
749
|
* @fires native:activity-toggle - Fired when trace is expanded/collapsed
|
|
593
750
|
*/
|
|
594
|
-
var
|
|
751
|
+
var x = class extends e {
|
|
595
752
|
static observedAttributes = [
|
|
596
753
|
"type",
|
|
597
754
|
"label",
|
|
@@ -599,11 +756,11 @@ var v = class extends e {
|
|
|
599
756
|
"expandable"
|
|
600
757
|
];
|
|
601
758
|
#e;
|
|
602
|
-
#t =
|
|
603
|
-
#n =
|
|
604
|
-
#r =
|
|
605
|
-
#i =
|
|
606
|
-
#a =
|
|
759
|
+
#t = r("typing");
|
|
760
|
+
#n = r("");
|
|
761
|
+
#r = r(!1);
|
|
762
|
+
#i = r(!1);
|
|
763
|
+
#a = r(!1);
|
|
607
764
|
#o = 0;
|
|
608
765
|
#s = 0;
|
|
609
766
|
#c = null;
|
|
@@ -649,7 +806,7 @@ var v = class extends e {
|
|
|
649
806
|
this.#r.value ? (this.#p(), this.#e.states.add("active")) : (this.#m(), this.#e.states.delete("active"));
|
|
650
807
|
}), this.addEffect(() => {
|
|
651
808
|
if (!this.#c) return;
|
|
652
|
-
let e = this.#n.value ||
|
|
809
|
+
let e = this.#n.value || S(this.#t.value);
|
|
653
810
|
this.#c.textContent = e;
|
|
654
811
|
}), this.addEffect(() => {
|
|
655
812
|
this.#u && (this.#u.hidden = !this.#r.value);
|
|
@@ -679,7 +836,7 @@ var v = class extends e {
|
|
|
679
836
|
#h = () => {
|
|
680
837
|
if (!this.#r.value || !this.#l) return;
|
|
681
838
|
let e = performance.now() - this.#o;
|
|
682
|
-
this.#l.textContent =
|
|
839
|
+
this.#l.textContent = C(e), this.#s = requestAnimationFrame(this.#h);
|
|
683
840
|
};
|
|
684
841
|
#g = () => {
|
|
685
842
|
this.#i.value && (this.#a.value = !this.#a.value, this.toggleAttribute("expanded", this.#a.value), this.dispatchEvent(new CustomEvent("native:activity-toggle", {
|
|
@@ -689,14 +846,14 @@ var v = class extends e {
|
|
|
689
846
|
})));
|
|
690
847
|
};
|
|
691
848
|
};
|
|
692
|
-
function
|
|
849
|
+
function S(e) {
|
|
693
850
|
switch (e) {
|
|
694
851
|
case "thinking": return "Thinking…";
|
|
695
852
|
case "tool-use": return "Using tools…";
|
|
696
853
|
default: return "Host is typing…";
|
|
697
854
|
}
|
|
698
855
|
}
|
|
699
|
-
function
|
|
856
|
+
function C(e) {
|
|
700
857
|
let t = Math.floor(e / 1e3);
|
|
701
858
|
if (t < 60) return `${t}s`;
|
|
702
859
|
let n = Math.floor(t / 60), r = t % 60;
|
|
@@ -716,11 +873,11 @@ function b(e) {
|
|
|
716
873
|
* @attr {boolean} disabled - Disables all chips
|
|
717
874
|
* @fires native:seed-select - Fired when a chip is clicked
|
|
718
875
|
*/
|
|
719
|
-
var
|
|
876
|
+
var w = class extends e {
|
|
720
877
|
static observedAttributes = ["options", "disabled"];
|
|
721
878
|
#e;
|
|
722
|
-
#t =
|
|
723
|
-
#n =
|
|
879
|
+
#t = r([]);
|
|
880
|
+
#n = r(!1);
|
|
724
881
|
constructor() {
|
|
725
882
|
super(), this.#e = this.attachInternals();
|
|
726
883
|
}
|
|
@@ -754,7 +911,7 @@ var x = class extends e {
|
|
|
754
911
|
}
|
|
755
912
|
}
|
|
756
913
|
setup() {
|
|
757
|
-
super.setup(), this.addEffect(
|
|
914
|
+
super.setup(), this.addEffect(n(this, this.#n, this.#e)), this.addEffect(() => {
|
|
758
915
|
let e = this.#t.value;
|
|
759
916
|
this.textContent = "";
|
|
760
917
|
for (let t of e) {
|
|
@@ -785,7 +942,7 @@ var x = class extends e {
|
|
|
785
942
|
}
|
|
786
943
|
}));
|
|
787
944
|
};
|
|
788
|
-
},
|
|
945
|
+
}, T = new Set([
|
|
789
946
|
"script",
|
|
790
947
|
"style",
|
|
791
948
|
"link",
|
|
@@ -802,12 +959,12 @@ var x = class extends e {
|
|
|
802
959
|
"frame",
|
|
803
960
|
"frameset",
|
|
804
961
|
"noscript"
|
|
805
|
-
]),
|
|
962
|
+
]), E = class extends e {
|
|
806
963
|
static observedAttributes = ["schema-type", "mode"];
|
|
807
964
|
#e;
|
|
808
|
-
#t =
|
|
809
|
-
#n =
|
|
810
|
-
#r =
|
|
965
|
+
#t = r("a2ui");
|
|
966
|
+
#n = r("inline");
|
|
967
|
+
#r = r(null);
|
|
811
968
|
#i = null;
|
|
812
969
|
constructor() {
|
|
813
970
|
super(), this.#e = this.attachInternals();
|
|
@@ -847,7 +1004,7 @@ var x = class extends e {
|
|
|
847
1004
|
super.setup(), this.#i = document.createElement("div"), this.#i.className = "n-chat-genui-container", this.appendChild(this.#i), this.addEffect(() => {
|
|
848
1005
|
let e = this.#r.value, t = this.#n.value;
|
|
849
1006
|
if (!this.#i || (this.#i.textContent = "", !e)) return;
|
|
850
|
-
let n =
|
|
1007
|
+
let n = D(e);
|
|
851
1008
|
if (n.length > 0) {
|
|
852
1009
|
this.#a(n), this.dispatchEvent(new CustomEvent("native:genui-error", {
|
|
853
1010
|
bubbles: !0,
|
|
@@ -858,7 +1015,7 @@ var x = class extends e {
|
|
|
858
1015
|
}
|
|
859
1016
|
if (t === "lightbox") this.#o(e);
|
|
860
1017
|
else {
|
|
861
|
-
let t =
|
|
1018
|
+
let t = O(e);
|
|
862
1019
|
t && this.#i.appendChild(t);
|
|
863
1020
|
}
|
|
864
1021
|
this.#e.states.add("rendered");
|
|
@@ -882,7 +1039,7 @@ var x = class extends e {
|
|
|
882
1039
|
r.setAttribute("variant", "outline"), r.setAttribute("size", "sm"), r.setAttribute("inline", ""), r.textContent = "Open", r.addEventListener("click", () => this.#s(e)), t.appendChild(r), this.#i.appendChild(t);
|
|
883
1040
|
}
|
|
884
1041
|
#s(e) {
|
|
885
|
-
let t = document.createElement("n-dialog"), n =
|
|
1042
|
+
let t = document.createElement("n-dialog"), n = O(e);
|
|
886
1043
|
n && t.appendChild(n), this.appendChild(t), requestAnimationFrame(() => {
|
|
887
1044
|
let e = t.querySelector("dialog");
|
|
888
1045
|
e && e.showModal();
|
|
@@ -902,20 +1059,20 @@ var x = class extends e {
|
|
|
902
1059
|
}));
|
|
903
1060
|
};
|
|
904
1061
|
};
|
|
905
|
-
function
|
|
1062
|
+
function D(e, t = 0) {
|
|
906
1063
|
let n = [];
|
|
907
1064
|
if (t > 20) return n.push("Maximum nesting depth (20) exceeded"), n;
|
|
908
1065
|
if (!e.tag || typeof e.tag != "string") return n.push("Node missing required \"tag\" property"), n;
|
|
909
|
-
if (
|
|
1066
|
+
if (T.has(e.tag.toLowerCase()) && n.push(`Forbidden tag: <${e.tag}>`), e.children) for (let r of e.children) n.push(...D(r, t + 1));
|
|
910
1067
|
return n;
|
|
911
1068
|
}
|
|
912
|
-
function
|
|
913
|
-
if (
|
|
1069
|
+
function O(e) {
|
|
1070
|
+
if (T.has(e.tag.toLowerCase())) return null;
|
|
914
1071
|
let t = document.createElement(e.tag);
|
|
915
1072
|
if (e.id && (t.id = e.id), e.slot && (t.slot = e.slot), e.attributes) for (let [n, r] of Object.entries(e.attributes)) t.setAttribute(n, r);
|
|
916
1073
|
if (e.properties) for (let [n, r] of Object.entries(e.properties)) t[n] = r;
|
|
917
1074
|
if (e.text && (t.textContent = e.text), e.children) for (let n of e.children) {
|
|
918
|
-
let e =
|
|
1075
|
+
let e = O(n);
|
|
919
1076
|
e && t.appendChild(e);
|
|
920
1077
|
}
|
|
921
1078
|
return t;
|
|
@@ -940,7 +1097,7 @@ function T(e) {
|
|
|
940
1097
|
* @fires native:structured-submit - Fired on submit with selections
|
|
941
1098
|
* @fires native:structured-cancel - Fired when dismissed without selecting
|
|
942
1099
|
*/
|
|
943
|
-
var
|
|
1100
|
+
var k = class extends e {
|
|
944
1101
|
static observedAttributes = [
|
|
945
1102
|
"question",
|
|
946
1103
|
"type",
|
|
@@ -949,12 +1106,12 @@ var E = class extends e {
|
|
|
949
1106
|
"disabled"
|
|
950
1107
|
];
|
|
951
1108
|
#e;
|
|
952
|
-
#t =
|
|
953
|
-
#n =
|
|
954
|
-
#r =
|
|
955
|
-
#i =
|
|
956
|
-
#a =
|
|
957
|
-
#o =
|
|
1109
|
+
#t = r("");
|
|
1110
|
+
#n = r("single");
|
|
1111
|
+
#r = r([]);
|
|
1112
|
+
#i = r(!1);
|
|
1113
|
+
#a = r(!1);
|
|
1114
|
+
#o = r(/* @__PURE__ */ new Set());
|
|
958
1115
|
constructor() {
|
|
959
1116
|
super(), this.#e = this.attachInternals();
|
|
960
1117
|
}
|
|
@@ -1007,7 +1164,7 @@ var E = class extends e {
|
|
|
1007
1164
|
}
|
|
1008
1165
|
}
|
|
1009
1166
|
setup() {
|
|
1010
|
-
super.setup(), this.addEffect(
|
|
1167
|
+
super.setup(), this.addEffect(n(this, this.#a, this.#e)), this.addEffect(() => {
|
|
1011
1168
|
this.#s();
|
|
1012
1169
|
}), this.addEventListener("native:press", this.#c);
|
|
1013
1170
|
}
|
|
@@ -1066,4 +1223,4 @@ var E = class extends e {
|
|
|
1066
1223
|
}));
|
|
1067
1224
|
};
|
|
1068
1225
|
};
|
|
1069
|
-
export {
|
|
1226
|
+
export { h as a, b as c, f as d, d as f, i as g, a as h, x as i, m as l, s as m, E as n, v as o, c as p, w as r, y as s, k as t, u };
|