@nonoun/native-chat 0.5.16 → 0.5.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -0
- package/dist/adapter-mock-DQ_CxuNu.js +845 -0
- package/dist/avatar/chat-avatar-element.d.ts +18 -0
- package/dist/avatar/chat-avatar-element.d.ts.map +1 -0
- package/dist/avatar/index.d.ts +2 -0
- package/dist/avatar/index.d.ts.map +1 -0
- package/dist/avatar/n-chat-avatar.d.ts +2 -0
- package/dist/avatar/n-chat-avatar.d.ts.map +1 -0
- package/dist/chat-input-element.d.ts +32 -0
- package/dist/chat-input-element.d.ts.map +1 -0
- package/dist/{chat-input-structured-element-C_5MDbpb.js → chat-input-structured-element-Xm4nCA2K.js} +508 -241
- package/dist/chat-panel-element.d.ts +100 -0
- package/dist/chat-panel-element.d.ts.map +1 -0
- package/dist/feed/chat-feed-element.d.ts +48 -0
- package/dist/feed/chat-feed-element.d.ts.map +1 -0
- package/dist/feed/index.d.ts +2 -0
- package/dist/feed/index.d.ts.map +1 -0
- package/dist/feed/n-chat-feed.d.ts +2 -0
- package/dist/feed/n-chat-feed.d.ts.map +1 -0
- package/dist/gateway/adapter-chatgpt.d.ts +67 -0
- package/dist/gateway/adapter-chatgpt.d.ts.map +1 -0
- package/dist/gateway/adapter-claude.d.ts +68 -0
- package/dist/gateway/adapter-claude.d.ts.map +1 -0
- package/dist/gateway/adapter-mock.d.ts +3 -0
- package/dist/gateway/adapter-mock.d.ts.map +1 -0
- package/dist/gateway/adapter.d.ts +71 -0
- package/dist/gateway/adapter.d.ts.map +1 -0
- package/dist/gateway/controller.d.ts +46 -0
- package/dist/gateway/controller.d.ts.map +1 -0
- package/dist/gateway/index.d.ts +10 -0
- package/dist/gateway/index.d.ts.map +1 -0
- package/dist/gateway/runtime.d.ts +53 -0
- package/dist/gateway/runtime.d.ts.map +1 -0
- package/dist/gateway/types.d.ts +73 -0
- package/dist/gateway/types.d.ts.map +1 -0
- package/dist/gateway.d.ts +2 -0
- package/dist/gateway.d.ts.map +1 -0
- package/dist/gateway.js +33 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/message/chat-input-structured-element.d.ts +43 -0
- package/dist/message/chat-input-structured-element.d.ts.map +1 -0
- package/dist/message/chat-message-activity-element.d.ts +32 -0
- package/dist/message/chat-message-activity-element.d.ts.map +1 -0
- package/dist/message/chat-message-element.d.ts +44 -0
- package/dist/message/chat-message-element.d.ts.map +1 -0
- package/dist/message/chat-message-genui-element.d.ts +45 -0
- package/dist/message/chat-message-genui-element.d.ts.map +1 -0
- package/dist/message/chat-message-seed-element.d.ts +33 -0
- package/dist/message/chat-message-seed-element.d.ts.map +1 -0
- package/dist/message/chat-message-text-element.d.ts +37 -0
- package/dist/message/chat-message-text-element.d.ts.map +1 -0
- package/dist/message/chat-messages-element.d.ts +39 -0
- package/dist/message/chat-messages-element.d.ts.map +1 -0
- package/dist/message/index.d.ts +8 -0
- package/dist/message/index.d.ts.map +1 -0
- package/dist/message/n-chat-message.d.ts +2 -0
- package/dist/message/n-chat-message.d.ts.map +1 -0
- package/dist/native-chat.css +116 -48
- package/dist/native-chat.js +1 -1
- package/dist/register.d.ts +13 -0
- package/dist/register.d.ts.map +1 -0
- 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 +5 -1
package/dist/{chat-input-structured-element-C_5MDbpb.js → chat-input-structured-element-Xm4nCA2K.js}
RENAMED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { f as e, o as t, r as n, t as r } from "./adapter-mock-DQ_CxuNu.js";
|
|
2
|
+
import { NativeElement as i, VirtualScrollController as a, createDisabledEffect as o, signal as s, uid as c } from "@nonoun/native-ui";
|
|
2
3
|
/**
|
|
3
4
|
* Chat message input with textarea, submit button, and Enter-to-send behavior.
|
|
4
5
|
* @attr {boolean} disabled - Disables interaction
|
|
6
|
+
* @attr {string} value - Initial textarea value
|
|
5
7
|
* @attr {boolean} busy - Disables submit but keeps textarea enabled
|
|
6
8
|
* @attr {boolean} no-enter-submit - Disables Enter key submission
|
|
7
9
|
* @attr {boolean} no-auto-clear - Prevents clearing the textarea after send
|
|
@@ -10,11 +12,15 @@ import { NativeElement as e, VirtualScrollController as t, createDisabledEffect
|
|
|
10
12
|
* @fires native:composer-focus - Fired when the composer textarea gains focus
|
|
11
13
|
* @fires native:composer-blur - Fired when the composer textarea loses focus
|
|
12
14
|
*/
|
|
13
|
-
var
|
|
14
|
-
static observedAttributes = [
|
|
15
|
+
var l = class extends i {
|
|
16
|
+
static observedAttributes = [
|
|
17
|
+
"disabled",
|
|
18
|
+
"busy",
|
|
19
|
+
"value"
|
|
20
|
+
];
|
|
15
21
|
#e;
|
|
16
|
-
#t =
|
|
17
|
-
#n =
|
|
22
|
+
#t = s(!1);
|
|
23
|
+
#n = s(!1);
|
|
18
24
|
#r = null;
|
|
19
25
|
#i = null;
|
|
20
26
|
constructor() {
|
|
@@ -55,13 +61,18 @@ var a = class extends e {
|
|
|
55
61
|
case "busy":
|
|
56
62
|
this.#n.value = n !== null;
|
|
57
63
|
break;
|
|
64
|
+
case "value":
|
|
65
|
+
this.#r && (this.#r.value = n ?? "");
|
|
66
|
+
break;
|
|
58
67
|
}
|
|
59
68
|
super.attributeChangedCallback(e, t, n);
|
|
60
69
|
}
|
|
61
70
|
}
|
|
62
71
|
setup() {
|
|
63
|
-
super.setup(), this.addEffect(
|
|
64
|
-
this.#a()
|
|
72
|
+
super.setup(), this.addEffect(o(this, this.#t, this.#e)), this.deferChildren(() => {
|
|
73
|
+
this.#a();
|
|
74
|
+
let e = this.getAttribute("value");
|
|
75
|
+
e && this.#r && (this.#r.value = e), this.addEffect(() => {
|
|
65
76
|
let e = this.#t.value;
|
|
66
77
|
this.#r && this.#r.toggleAttribute("disabled", e), this.#i && (e ? this.#i.setAttribute("disabled", "") : this.#s());
|
|
67
78
|
}), this.addEffect(() => {
|
|
@@ -131,27 +142,42 @@ var a = class extends e {
|
|
|
131
142
|
})) && !this.hasAttribute("no-auto-clear") && (this.value = "", this.#i?.setAttribute("disabled", ""));
|
|
132
143
|
}
|
|
133
144
|
}
|
|
134
|
-
},
|
|
145
|
+
}, u = class extends i {
|
|
146
|
+
static MAX_CONTEXT_MESSAGES = 50;
|
|
135
147
|
static observedAttributes = [
|
|
136
148
|
"show-stop",
|
|
137
149
|
"show-restart",
|
|
138
150
|
"auto-focus-policy",
|
|
139
151
|
"open",
|
|
140
|
-
"model"
|
|
152
|
+
"model",
|
|
153
|
+
"models",
|
|
154
|
+
"gateway",
|
|
155
|
+
"gateway-url",
|
|
156
|
+
"gateway-config",
|
|
157
|
+
"gateway-urls"
|
|
141
158
|
];
|
|
142
|
-
#e =
|
|
143
|
-
#t =
|
|
144
|
-
#n =
|
|
145
|
-
#r =
|
|
146
|
-
#i =
|
|
147
|
-
#a =
|
|
148
|
-
#o = null;
|
|
149
|
-
#s = null;
|
|
150
|
-
#c = null;
|
|
151
|
-
#l = null;
|
|
152
|
-
#u =
|
|
159
|
+
#e = s(!1);
|
|
160
|
+
#t = s(!1);
|
|
161
|
+
#n = s("open-request");
|
|
162
|
+
#r = s(!1);
|
|
163
|
+
#i = s([]);
|
|
164
|
+
#a = s(null);
|
|
165
|
+
#o = s(null);
|
|
166
|
+
#s = s(null);
|
|
167
|
+
#c = s(null);
|
|
168
|
+
#l = s(null);
|
|
169
|
+
#u = s(!1);
|
|
153
170
|
#d = null;
|
|
154
|
-
#f =
|
|
171
|
+
#f = [];
|
|
172
|
+
#p = null;
|
|
173
|
+
#m = null;
|
|
174
|
+
#h = null;
|
|
175
|
+
#g = null;
|
|
176
|
+
#_ = null;
|
|
177
|
+
#v = null;
|
|
178
|
+
#y = null;
|
|
179
|
+
#b = null;
|
|
180
|
+
#x = null;
|
|
155
181
|
attributeChangedCallback(e, t, n) {
|
|
156
182
|
if (t !== n) {
|
|
157
183
|
switch (e) {
|
|
@@ -166,12 +192,38 @@ var a = class extends e {
|
|
|
166
192
|
break;
|
|
167
193
|
case "open": {
|
|
168
194
|
let e = this.#r.value;
|
|
169
|
-
this.#r.value = n !== null, !e && n !== null ? this.#
|
|
195
|
+
this.#r.value = n !== null, !e && n !== null ? this.#E(void 0, !1) : e && n === null && this.#D(void 0);
|
|
170
196
|
break;
|
|
171
197
|
}
|
|
172
198
|
case "model":
|
|
173
199
|
this.#a.value = n;
|
|
174
200
|
break;
|
|
201
|
+
case "models":
|
|
202
|
+
n ? this.#i.value = n.split(",").map((e) => e.trim()).filter(Boolean).map((e) => ({
|
|
203
|
+
value: e,
|
|
204
|
+
label: e
|
|
205
|
+
})) : this.#i.value = [];
|
|
206
|
+
break;
|
|
207
|
+
case "gateway":
|
|
208
|
+
this.#o.value = n;
|
|
209
|
+
break;
|
|
210
|
+
case "gateway-url":
|
|
211
|
+
this.#s.value = n;
|
|
212
|
+
break;
|
|
213
|
+
case "gateway-config":
|
|
214
|
+
try {
|
|
215
|
+
this.#c.value = n ? JSON.parse(n) : null;
|
|
216
|
+
} catch {
|
|
217
|
+
this.#c.value = null;
|
|
218
|
+
}
|
|
219
|
+
break;
|
|
220
|
+
case "gateway-urls":
|
|
221
|
+
try {
|
|
222
|
+
this.#l.value = n ? JSON.parse(n) : null;
|
|
223
|
+
} catch {
|
|
224
|
+
this.#l.value = null;
|
|
225
|
+
}
|
|
226
|
+
break;
|
|
175
227
|
}
|
|
176
228
|
super.attributeChangedCallback(e, t, n);
|
|
177
229
|
}
|
|
@@ -199,7 +251,7 @@ var a = class extends e {
|
|
|
199
251
|
return this.#i.value;
|
|
200
252
|
}
|
|
201
253
|
set models(e) {
|
|
202
|
-
this.#i.value = e, e.length > 0 && this.#a.value === null && (this.#a.value = e[0].value, this.setAttribute("model", e[0].value));
|
|
254
|
+
this.#i.value = e, e.length > 0 ? this.setAttribute("models", e.map((e) => e.value).join(",")) : this.removeAttribute("models"), e.length > 0 && this.#a.value === null && (this.#a.value = e[0].value, this.setAttribute("model", e[0].value));
|
|
203
255
|
}
|
|
204
256
|
/** Currently selected model value. */
|
|
205
257
|
get model() {
|
|
@@ -208,120 +260,187 @@ var a = class extends e {
|
|
|
208
260
|
set model(e) {
|
|
209
261
|
this.#a.value = e, e === null ? this.removeAttribute("model") : this.setAttribute("model", e);
|
|
210
262
|
}
|
|
263
|
+
/** Gateway adapter type: 'openai' or 'claude'. When set, panel handles send/stream automatically. */
|
|
264
|
+
get gateway() {
|
|
265
|
+
return this.#o.value;
|
|
266
|
+
}
|
|
267
|
+
set gateway(e) {
|
|
268
|
+
this.#o.value = e, e ? this.setAttribute("gateway", e) : this.removeAttribute("gateway");
|
|
269
|
+
}
|
|
270
|
+
/** Base URL for the gateway API. */
|
|
271
|
+
get gatewayUrl() {
|
|
272
|
+
return this.#s.value;
|
|
273
|
+
}
|
|
274
|
+
set gatewayUrl(e) {
|
|
275
|
+
this.#s.value = e, e ? this.setAttribute("gateway-url", e) : this.removeAttribute("gateway-url");
|
|
276
|
+
}
|
|
277
|
+
/** Configuration for the gateway adapter (model, apiKey, system, etc.). */
|
|
278
|
+
get gatewayConfig() {
|
|
279
|
+
return this.#c.value;
|
|
280
|
+
}
|
|
281
|
+
set gatewayConfig(e) {
|
|
282
|
+
this.#c.value = e, e ? this.setAttribute("gateway-config", JSON.stringify(e)) : this.removeAttribute("gateway-config");
|
|
283
|
+
}
|
|
284
|
+
/** Map of provider prefixes to gateway URLs. Enables auto-switching gateway based on model prefix. */
|
|
285
|
+
get gatewayUrls() {
|
|
286
|
+
return this.#l.value;
|
|
287
|
+
}
|
|
288
|
+
set gatewayUrls(e) {
|
|
289
|
+
this.#l.value = e, e ? this.setAttribute("gateway-urls", JSON.stringify(e)) : this.removeAttribute("gateway-urls");
|
|
290
|
+
}
|
|
291
|
+
/** Whether the panel is currently streaming a response. Read-only. */
|
|
292
|
+
get streaming() {
|
|
293
|
+
return this.#u.value;
|
|
294
|
+
}
|
|
211
295
|
/** Open the panel. Optionally focus the composer. */
|
|
212
296
|
open(e) {
|
|
213
297
|
let t = this.#r.value;
|
|
214
298
|
this.#r.value = !0, this.toggleAttribute("open", !0);
|
|
215
299
|
let n = this.#n.value, r = e?.focusComposer ?? !1, i = n !== "never" && (n === "open-request" ? r : !1);
|
|
216
|
-
t || this.#
|
|
300
|
+
t || this.#E(e?.reason, i), i && this.focusComposer({ cursor: "end" }, "api");
|
|
217
301
|
}
|
|
218
302
|
/** Close the panel. */
|
|
219
303
|
close(e) {
|
|
220
304
|
let t = this.#r.value;
|
|
221
|
-
this.#r.value = !1, this.removeAttribute("open"), t && this.#
|
|
305
|
+
this.#r.value = !1, this.removeAttribute("open"), t && this.#D(e);
|
|
222
306
|
}
|
|
223
307
|
/** Focus the composer input. */
|
|
224
308
|
focusComposer(e, t = "api") {
|
|
225
|
-
this.#
|
|
309
|
+
this.#C(e ?? {}, t, 0);
|
|
226
310
|
}
|
|
227
311
|
setup() {
|
|
228
312
|
super.setup(), this.hasAttribute("open") && (this.#r.value = !0);
|
|
229
|
-
let
|
|
230
|
-
|
|
231
|
-
let
|
|
232
|
-
|
|
233
|
-
let
|
|
234
|
-
|
|
235
|
-
let
|
|
236
|
-
|
|
237
|
-
let
|
|
238
|
-
|
|
239
|
-
let
|
|
240
|
-
|
|
241
|
-
let
|
|
242
|
-
|
|
243
|
-
let
|
|
244
|
-
|
|
245
|
-
let
|
|
246
|
-
|
|
247
|
-
let
|
|
248
|
-
|
|
249
|
-
let
|
|
250
|
-
|
|
313
|
+
let i = document.createElement("n-header");
|
|
314
|
+
i.setAttribute("dividers", "");
|
|
315
|
+
let a = document.createElement("n-icon");
|
|
316
|
+
a.setAttribute("name", "chat-dots"), a.setAttribute("slot", "leading"), i.appendChild(a);
|
|
317
|
+
let o = document.createElement("span");
|
|
318
|
+
o.setAttribute("slot", "label"), o.textContent = "Assistant", i.appendChild(o);
|
|
319
|
+
let s = document.createElement("span");
|
|
320
|
+
s.setAttribute("slot", "trailing"), s.className = "n-chat-panel-header-trailing", i.appendChild(s), this.#v = s;
|
|
321
|
+
let c = document.createElement("n-body"), l = document.createElement("n-chat-content"), u = document.createElement("n-chat-feed");
|
|
322
|
+
u.setAttribute("auto-scroll", ""), l.appendChild(u), this.#h = u, c.appendChild(l);
|
|
323
|
+
let d = document.createElement("n-footer");
|
|
324
|
+
d.setAttribute("dividers", ""), this.#m = d;
|
|
325
|
+
let f = document.createElement("n-chat-input"), p = document.createElement("n-textarea");
|
|
326
|
+
p.setAttribute("placeholder", "Ask anything"), p.setAttribute("autogrow", ""), p.setAttribute("rows", "3"), f.appendChild(p);
|
|
327
|
+
let m = document.createElement("n-chat-input-actions");
|
|
328
|
+
this.#y = m;
|
|
329
|
+
let h = document.createElement("n-button");
|
|
330
|
+
h.setAttribute("variant", "ghost"), h.setAttribute("inline", "");
|
|
331
|
+
let g = document.createElement("n-icon");
|
|
332
|
+
g.setAttribute("name", "plus"), h.appendChild(g), m.appendChild(h);
|
|
333
|
+
let _ = document.createElement("n-button");
|
|
334
|
+
_.setAttribute("variant", "ghost"), _.setAttribute("inline", "");
|
|
335
|
+
let v = document.createElement("n-icon");
|
|
336
|
+
v.setAttribute("name", "microphone"), _.appendChild(v), m.appendChild(_);
|
|
337
|
+
let y = document.createElement("n-button");
|
|
338
|
+
y.setAttribute("variant", "primary"), y.setAttribute("intent", "accent"), y.setAttribute("radius", "round"), y.setAttribute("inline", ""), y.setAttribute("disabled", ""), y.dataset.submit = "", y.dataset.role = "submit";
|
|
339
|
+
let b = document.createElement("n-icon");
|
|
340
|
+
b.setAttribute("name", "arrow-up"), y.appendChild(b), m.appendChild(y), f.appendChild(m), d.appendChild(f), this.append(i, c, d), this.addEffect(() => {
|
|
251
341
|
let e = this.#e.value;
|
|
252
|
-
if (e && !this.#
|
|
342
|
+
if (e && !this.#g) {
|
|
253
343
|
let e = document.createElement("n-button");
|
|
254
|
-
e.setAttribute("variant", "ghost"), e.setAttribute("inline", ""), e.setAttribute("aria-label", "Stop")
|
|
255
|
-
|
|
344
|
+
e.setAttribute("variant", "ghost"), e.setAttribute("inline", ""), e.setAttribute("aria-label", "Stop");
|
|
345
|
+
let t = document.createElement("n-icon");
|
|
346
|
+
t.setAttribute("name", "stop"), e.appendChild(t), e.addEventListener("native:press", this.#k), this.#g = e, this.#v?.prepend(e);
|
|
347
|
+
} else !e && this.#g && (this.#g.removeEventListener("native:press", this.#k), this.#g.remove(), this.#g = null);
|
|
256
348
|
}), this.addEffect(() => {
|
|
257
349
|
let e = this.#t.value;
|
|
258
|
-
if (e && !this.#
|
|
350
|
+
if (e && !this.#_) {
|
|
259
351
|
let e = document.createElement("n-button");
|
|
260
|
-
e.setAttribute("variant", "ghost"), e.setAttribute("inline", ""), e.setAttribute("aria-label", "Restart")
|
|
261
|
-
let t =
|
|
262
|
-
|
|
263
|
-
|
|
352
|
+
e.setAttribute("variant", "ghost"), e.setAttribute("inline", ""), e.setAttribute("aria-label", "Restart");
|
|
353
|
+
let t = document.createElement("n-icon");
|
|
354
|
+
t.setAttribute("name", "arrow-counter-clockwise"), e.appendChild(t), e.addEventListener("native:press", this.#A), this.#_ = e;
|
|
355
|
+
let n = this.#g?.nextSibling ?? this.#v?.firstChild ?? null;
|
|
356
|
+
this.#v?.insertBefore(e, n);
|
|
357
|
+
} else !e && this.#_ && (this.#_.removeEventListener("native:press", this.#A), this.#_.remove(), this.#_ = null);
|
|
264
358
|
}), this.addEffect(() => {
|
|
265
359
|
let e = this.#i.value;
|
|
266
|
-
if (e.length > 0 && !this.#
|
|
267
|
-
let e = document.createElement("n-
|
|
268
|
-
e.setAttribute("
|
|
269
|
-
let t = document.createElement("n-
|
|
270
|
-
t.setAttribute("
|
|
271
|
-
|
|
360
|
+
if (e.length > 0 && !this.#b) {
|
|
361
|
+
let e = document.createElement("n-select");
|
|
362
|
+
e.setAttribute("aria-label", "Select model"), e.setAttribute("data-role", "model-picker"), e.addEventListener("native:change", this.#M);
|
|
363
|
+
let t = document.createElement("n-button");
|
|
364
|
+
t.setAttribute("variant", "ghost"), t.setAttribute("inline", "");
|
|
365
|
+
let n = document.createElement("n-icon");
|
|
366
|
+
n.setAttribute("name", "dots-three-outline-fill"), t.appendChild(n);
|
|
367
|
+
let r = document.createElement("n-listbox");
|
|
368
|
+
r.setAttribute("popover", "manual"), e.append(t, r), this.#b = e, this.#x = r;
|
|
369
|
+
let i = this.#y?.querySelector("[data-submit]");
|
|
370
|
+
i ? this.#y?.insertBefore(e, i) : this.#y?.appendChild(e);
|
|
371
|
+
} else e.length === 0 && this.#b && this.#B();
|
|
272
372
|
}), this.addEffect(() => {
|
|
273
|
-
let e = this.#i.value, t = this.#a.value, n = this.#
|
|
373
|
+
let e = this.#i.value, t = this.#a.value, n = this.#b, r = this.#x;
|
|
274
374
|
if (!n || !r || e.length === 0) return;
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
375
|
+
let i = t ?? e[0]?.value ?? null;
|
|
376
|
+
if (i !== null) {
|
|
377
|
+
r.innerHTML = "";
|
|
378
|
+
for (let [t, n] of this.#z(e)) {
|
|
379
|
+
let e = document.createElement("n-option-group"), a = document.createElement("n-option-group-header");
|
|
380
|
+
a.textContent = t, e.appendChild(a);
|
|
381
|
+
for (let t of n) {
|
|
382
|
+
let n = document.createElement("n-option"), r = t.value === i;
|
|
383
|
+
n.setAttribute("value", t.value), n.setAttribute("aria-selected", String(r)), n.textContent = t.label ?? t.value, e.appendChild(n);
|
|
384
|
+
}
|
|
385
|
+
r.appendChild(e);
|
|
386
|
+
}
|
|
387
|
+
t === null && (this.#a.value = i, this.setAttribute("model", i)), n.value = i;
|
|
279
388
|
}
|
|
280
|
-
|
|
281
|
-
let
|
|
282
|
-
if (
|
|
283
|
-
|
|
284
|
-
|
|
389
|
+
}), this.addEffect(() => {
|
|
390
|
+
let e = this.#l.value, t = this.#a.value;
|
|
391
|
+
if (!e || !t) return;
|
|
392
|
+
let n = this.#o.value, r = this.#s.value;
|
|
393
|
+
if (n && r) return;
|
|
394
|
+
let i = this.#j(t);
|
|
395
|
+
i && (this.#o.value = i.gateway, this.setAttribute("gateway", i.gateway), this.#s.value = i.url, this.setAttribute("gateway-url", i.url));
|
|
396
|
+
}), this.addEffect(() => {
|
|
397
|
+
let i = this.#o.value, a = this.#s.value, o = this.#c.value;
|
|
398
|
+
if (!i || !a) {
|
|
399
|
+
this.#d = null;
|
|
400
|
+
return;
|
|
285
401
|
}
|
|
402
|
+
let s = {
|
|
403
|
+
clientId: e(),
|
|
404
|
+
baseUrl: a,
|
|
405
|
+
gatewayConfig: o ?? {}
|
|
406
|
+
}, c = null;
|
|
407
|
+
i === "openai" ? c = t(s) : i === "claude" ? c = n(s) : i === "mock" && (c = r(s)), this.#d = c, c && c.bootstrapSession().catch(() => {});
|
|
286
408
|
}), this.addEffect(() => {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
} catch {}
|
|
291
|
-
}), this.deferChildren(() => {
|
|
292
|
-
this.#p();
|
|
409
|
+
this.#o.value && (this.#e.value = this.#u.value);
|
|
410
|
+
}), this.addEventListener("native:send", this.#N), this.addEventListener("native:chat-stop", this.#L), this.addEventListener("native:chat-restart", this.#R), this.deferChildren(() => {
|
|
411
|
+
this.#S();
|
|
293
412
|
}), this.#n.value === "ready" && queueMicrotask(() => {
|
|
294
413
|
this.isConnected && this.focusComposer({ cursor: "end" }, "policy");
|
|
295
414
|
});
|
|
296
415
|
}
|
|
297
416
|
teardown() {
|
|
298
|
-
this.#
|
|
417
|
+
this.#p?.abort(), this.removeEventListener("native:send", this.#N), this.removeEventListener("native:chat-stop", this.#L), this.removeEventListener("native:chat-restart", this.#R), this.#g && this.#g.removeEventListener("native:press", this.#k), this.#_ && this.#_.removeEventListener("native:press", this.#A), this.#B(), this.#d = null, this.#f = [], this.#p = null, this.#m = null, this.#h = null, this.#g = null, this.#_ = null, this.#v = null, this.#y = null, this.#x = null, this.innerHTML = "", super.teardown();
|
|
299
418
|
}
|
|
300
|
-
#
|
|
419
|
+
#S() {
|
|
301
420
|
let e = this.querySelector(":scope > [slot=\"header-trailing\"]");
|
|
302
|
-
e && this.#
|
|
421
|
+
e && this.#v && this.#v.appendChild(e);
|
|
303
422
|
let t = this.querySelector(":scope > [slot=\"footer-leading\"]");
|
|
304
|
-
if (t && this.#
|
|
305
|
-
let e = this.#
|
|
306
|
-
this.#
|
|
423
|
+
if (t && this.#m) {
|
|
424
|
+
let e = this.#m.querySelector(":scope > n-chat-input");
|
|
425
|
+
this.#m.insertBefore(t, e);
|
|
307
426
|
}
|
|
308
427
|
}
|
|
309
|
-
#
|
|
310
|
-
let r = this.#
|
|
428
|
+
#C(e, t, n) {
|
|
429
|
+
let r = this.#w();
|
|
311
430
|
if (!r) {
|
|
312
431
|
if (n < 2) {
|
|
313
|
-
queueMicrotask(() => this.#
|
|
432
|
+
queueMicrotask(() => this.#C(e, t, n + 1));
|
|
314
433
|
return;
|
|
315
434
|
}
|
|
316
|
-
this.#
|
|
435
|
+
this.#O("composer-unavailable", 3);
|
|
317
436
|
return;
|
|
318
437
|
}
|
|
319
438
|
if (r.disabled) {
|
|
320
439
|
if (n < 2) {
|
|
321
|
-
queueMicrotask(() => this.#
|
|
440
|
+
queueMicrotask(() => this.#C(e, t, n + 1));
|
|
322
441
|
return;
|
|
323
442
|
}
|
|
324
|
-
this.#
|
|
443
|
+
this.#O("disabled", 3);
|
|
325
444
|
return;
|
|
326
445
|
}
|
|
327
446
|
let i = r.querySelector("n-textarea"), a = i ?? r;
|
|
@@ -329,22 +448,22 @@ var a = class extends e {
|
|
|
329
448
|
a.focus();
|
|
330
449
|
} catch {
|
|
331
450
|
if (n < 2) {
|
|
332
|
-
queueMicrotask(() => this.#
|
|
451
|
+
queueMicrotask(() => this.#C(e, t, n + 1));
|
|
333
452
|
return;
|
|
334
453
|
}
|
|
335
|
-
this.#
|
|
454
|
+
this.#O("blocked", 3);
|
|
336
455
|
return;
|
|
337
456
|
}
|
|
338
|
-
e.cursor && e.cursor !== "preserve" && i && this.#
|
|
457
|
+
e.cursor && e.cursor !== "preserve" && i && this.#T(i, e.cursor), this.dispatchEvent(new CustomEvent("native:composer-focused", {
|
|
339
458
|
bubbles: !0,
|
|
340
459
|
composed: !0,
|
|
341
460
|
detail: { by: t }
|
|
342
461
|
}));
|
|
343
462
|
}
|
|
344
|
-
#
|
|
463
|
+
#w() {
|
|
345
464
|
return this.querySelector("n-chat-input");
|
|
346
465
|
}
|
|
347
|
-
#
|
|
466
|
+
#T(e, t) {
|
|
348
467
|
let n = e.ownerDocument.getSelection?.();
|
|
349
468
|
if (!n) return;
|
|
350
469
|
let r = e.firstChild ?? e, i = t === "end" ? r.textContent?.length ?? 0 : 0;
|
|
@@ -353,7 +472,7 @@ var a = class extends e {
|
|
|
353
472
|
e.setStart(r, i), e.collapse(!0), n.removeAllRanges(), n.addRange(e);
|
|
354
473
|
} catch {}
|
|
355
474
|
}
|
|
356
|
-
#
|
|
475
|
+
#E(e, t) {
|
|
357
476
|
this.dispatchEvent(new CustomEvent("native:chat-opened", {
|
|
358
477
|
bubbles: !0,
|
|
359
478
|
composed: !0,
|
|
@@ -363,14 +482,14 @@ var a = class extends e {
|
|
|
363
482
|
}
|
|
364
483
|
}));
|
|
365
484
|
}
|
|
366
|
-
#
|
|
485
|
+
#D(e) {
|
|
367
486
|
this.dispatchEvent(new CustomEvent("native:chat-closed", {
|
|
368
487
|
bubbles: !0,
|
|
369
488
|
composed: !0,
|
|
370
489
|
detail: { reason: e }
|
|
371
490
|
}));
|
|
372
491
|
}
|
|
373
|
-
#
|
|
492
|
+
#O(e, t) {
|
|
374
493
|
this.dispatchEvent(new CustomEvent("native:composer-focus-failed", {
|
|
375
494
|
bubbles: !0,
|
|
376
495
|
composed: !0,
|
|
@@ -380,30 +499,51 @@ var a = class extends e {
|
|
|
380
499
|
}
|
|
381
500
|
}));
|
|
382
501
|
}
|
|
383
|
-
#
|
|
502
|
+
#k = () => {
|
|
384
503
|
this.dispatchEvent(new CustomEvent("native:chat-stop", {
|
|
385
504
|
bubbles: !0,
|
|
386
505
|
composed: !0
|
|
387
506
|
}));
|
|
388
507
|
};
|
|
389
|
-
#
|
|
508
|
+
#A = () => {
|
|
390
509
|
this.dispatchEvent(new CustomEvent("native:chat-restart", {
|
|
391
510
|
bubbles: !0,
|
|
392
511
|
composed: !0
|
|
393
512
|
}));
|
|
394
513
|
};
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
514
|
+
/** Resolve gateway + URL from model prefix using the gateway-urls map. */
|
|
515
|
+
#j(e) {
|
|
516
|
+
let t = this.#l.value;
|
|
517
|
+
if (!t) return null;
|
|
518
|
+
let n = e.toLowerCase();
|
|
519
|
+
if (n.startsWith("claude") || n.startsWith("anthropic")) {
|
|
520
|
+
let e = t.claude;
|
|
521
|
+
if (e) return {
|
|
522
|
+
gateway: "claude",
|
|
523
|
+
url: e
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
if (n.startsWith("gpt") || n.startsWith("chatgpt") || n.startsWith("openai")) {
|
|
527
|
+
let e = t.openai;
|
|
528
|
+
if (e) return {
|
|
529
|
+
gateway: "openai",
|
|
530
|
+
url: e
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
for (let e of Object.keys(t)) if (n.startsWith(e.toLowerCase())) return {
|
|
534
|
+
gateway: e,
|
|
535
|
+
url: t[e]
|
|
536
|
+
};
|
|
537
|
+
return null;
|
|
538
|
+
}
|
|
539
|
+
#M = (e) => {
|
|
399
540
|
let t = e.detail?.value ?? null;
|
|
400
541
|
if (t === null) return;
|
|
401
542
|
let n = this.#a.value;
|
|
402
|
-
if (t === n)
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
this.#a.value = t, this.setAttribute("model", t), this.#f.value = !1, this.dispatchEvent(new CustomEvent("native:model-change", {
|
|
543
|
+
if (t === n) return;
|
|
544
|
+
this.#a.value = t, this.setAttribute("model", t);
|
|
545
|
+
let r = this.#j(t);
|
|
546
|
+
r && (this.#o.value = r.gateway, this.setAttribute("gateway", r.gateway), this.#s.value = r.url, this.setAttribute("gateway-url", r.url)), this.dispatchEvent(new CustomEvent("native:model-change", {
|
|
407
547
|
bubbles: !0,
|
|
408
548
|
composed: !0,
|
|
409
549
|
detail: {
|
|
@@ -412,10 +552,116 @@ var a = class extends e {
|
|
|
412
552
|
}
|
|
413
553
|
}));
|
|
414
554
|
};
|
|
415
|
-
#
|
|
416
|
-
|
|
555
|
+
#N = (e) => {
|
|
556
|
+
if (!this.#d) return;
|
|
557
|
+
let t = e.detail?.value;
|
|
558
|
+
t?.trim() && (e.stopImmediatePropagation(), this.#P(t));
|
|
559
|
+
};
|
|
560
|
+
async #P(t) {
|
|
561
|
+
let n = this.#d;
|
|
562
|
+
if (!n || this.#u.value) return;
|
|
563
|
+
this.#p?.abort();
|
|
564
|
+
let r = new AbortController();
|
|
565
|
+
this.#p = r;
|
|
566
|
+
let i = {
|
|
567
|
+
role: "user",
|
|
568
|
+
message: t,
|
|
569
|
+
datetime: Date.now()
|
|
570
|
+
};
|
|
571
|
+
this.#f.push(i);
|
|
572
|
+
let a = this.constructor.MAX_CONTEXT_MESSAGES;
|
|
573
|
+
this.#f.length > a && (this.#f = this.#f.slice(-a)), this.#F(i);
|
|
574
|
+
let o = `msg-${e()}`, s = this.#I(o), c = s?.querySelector("n-chat-message-text");
|
|
575
|
+
s?.setAttribute("status", "typing"), this.#u.value = !0;
|
|
576
|
+
let l = this.#w();
|
|
577
|
+
l && (l.busy = !0);
|
|
578
|
+
try {
|
|
579
|
+
let i = await n.sendMessageStream({
|
|
580
|
+
id: e(),
|
|
581
|
+
messages: this.#f,
|
|
582
|
+
query: t,
|
|
583
|
+
model: this.#a.value ?? void 0,
|
|
584
|
+
signal: r.signal,
|
|
585
|
+
onChunk: (e) => {
|
|
586
|
+
s?.getAttribute("status") === "typing" && s.setAttribute("status", "streaming"), c && (c.content = e.fullMessage), e.done && s?.setAttribute("status", e.partial ? "partial" : "sent");
|
|
587
|
+
}
|
|
588
|
+
});
|
|
589
|
+
this.#f.push({
|
|
590
|
+
role: "assistant",
|
|
591
|
+
message: i.message,
|
|
592
|
+
datetime: i.datetime ?? Date.now(),
|
|
593
|
+
partial: i.partial
|
|
594
|
+
});
|
|
595
|
+
} catch (e) {
|
|
596
|
+
if (e.name === "AbortError") {
|
|
597
|
+
s?.setAttribute("status", "partial");
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
600
|
+
s?.setAttribute("status", "error");
|
|
601
|
+
let t = c ? c.content : "";
|
|
602
|
+
c && (t.trim() ? c.content = t + `\n\n---\n*Error: ${e.message}*` : c.content = `Error: ${e.message}`);
|
|
603
|
+
} finally {
|
|
604
|
+
this.#u.value = !1, this.#p = null;
|
|
605
|
+
let e = this.#w();
|
|
606
|
+
e && (e.busy = !1);
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
#F(t) {
|
|
610
|
+
let n = this.#h;
|
|
611
|
+
if (!n) return;
|
|
612
|
+
let r = document.createElement("n-chat-messages");
|
|
613
|
+
r.setAttribute("data-role", t.role), r.setAttribute("sender", t.role === "user" ? "You" : "Assistant");
|
|
614
|
+
let i = document.createElement("n-chat-message");
|
|
615
|
+
i.setAttribute("data-role", t.role), i.setAttribute("message-id", `msg-${e()}`), i.setAttribute("status", "sent");
|
|
616
|
+
let a = document.createElement("n-chat-message-text");
|
|
617
|
+
a.content = t.message, i.appendChild(a), r.appendChild(i), n.appendChild(r);
|
|
618
|
+
}
|
|
619
|
+
#I(e) {
|
|
620
|
+
let t = this.#h;
|
|
621
|
+
if (!t) return null;
|
|
622
|
+
let n = document.createElement("n-chat-messages");
|
|
623
|
+
n.setAttribute("data-role", "assistant"), n.setAttribute("sender", "Assistant");
|
|
624
|
+
let r = document.createElement("n-chat-message");
|
|
625
|
+
r.setAttribute("data-role", "assistant"), r.setAttribute("message-id", e), r.setAttribute("status", "streaming");
|
|
626
|
+
let i = document.createElement("n-chat-message-text");
|
|
627
|
+
return r.appendChild(i), n.appendChild(r), t.appendChild(n), r;
|
|
628
|
+
}
|
|
629
|
+
#L = () => {
|
|
630
|
+
if (!this.#d) return;
|
|
631
|
+
this.#p?.abort(), this.#u.value = !1;
|
|
632
|
+
let e = this.#w();
|
|
633
|
+
e && (e.busy = !1);
|
|
634
|
+
};
|
|
635
|
+
#R = () => {
|
|
636
|
+
if (!this.#d) return;
|
|
637
|
+
this.#p?.abort(), this.#u.value = !1;
|
|
638
|
+
let e = this.#w();
|
|
639
|
+
e && (e.busy = !1), this.#f = [], this.#h && (this.#h.innerHTML = "");
|
|
640
|
+
};
|
|
641
|
+
#z(e) {
|
|
642
|
+
let t = /* @__PURE__ */ new Map(), n = (e) => {
|
|
643
|
+
let t = `${e.label ?? ""} ${e.value}`.toLowerCase();
|
|
644
|
+
return t.includes("claude") ? "Claude" : t.includes("gpt") || t.includes("openai") ? "ChatGPT" : t.includes("gemini") ? "Gemini" : "Models";
|
|
645
|
+
};
|
|
646
|
+
for (let r of e) {
|
|
647
|
+
let e = n(r);
|
|
648
|
+
t.has(e) || t.set(e, []), t.get(e).push(r);
|
|
649
|
+
}
|
|
650
|
+
let r = [
|
|
651
|
+
"Claude",
|
|
652
|
+
"ChatGPT",
|
|
653
|
+
"Gemini",
|
|
654
|
+
"Models"
|
|
655
|
+
];
|
|
656
|
+
return Array.from(t.entries()).sort((e, t) => {
|
|
657
|
+
let n = r.indexOf(e[0]), i = r.indexOf(t[0]);
|
|
658
|
+
return (n === -1 ? 999 : n) - (i === -1 ? 999 : i);
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
#B() {
|
|
662
|
+
this.#b &&= (this.#b.removeEventListener("native:change", this.#M), this.#b.remove(), null), this.#x = null;
|
|
417
663
|
}
|
|
418
|
-
},
|
|
664
|
+
}, d = 40, f = class extends i {
|
|
419
665
|
static observedAttributes = [
|
|
420
666
|
"auto-scroll",
|
|
421
667
|
"scrollable",
|
|
@@ -424,12 +670,12 @@ var a = class extends e {
|
|
|
424
670
|
"virtual-overscan"
|
|
425
671
|
];
|
|
426
672
|
#e;
|
|
427
|
-
#t =
|
|
428
|
-
#n =
|
|
673
|
+
#t = s(!0);
|
|
674
|
+
#n = s(!0);
|
|
429
675
|
#r = null;
|
|
430
676
|
#i = null;
|
|
431
677
|
#a = null;
|
|
432
|
-
#o =
|
|
678
|
+
#o = s([]);
|
|
433
679
|
#s = null;
|
|
434
680
|
constructor() {
|
|
435
681
|
super(), this.#e = this.attachInternals();
|
|
@@ -481,17 +727,17 @@ var a = class extends e {
|
|
|
481
727
|
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, {
|
|
482
728
|
childList: !0,
|
|
483
729
|
subtree: !0
|
|
484
|
-
}), this.
|
|
730
|
+
}), this.hasAttribute("virtual") && this.#c();
|
|
485
731
|
}
|
|
486
732
|
teardown() {
|
|
487
|
-
this.removeEventListener("scroll", this.#f), this
|
|
733
|
+
this.removeEventListener("scroll", this.#f), this.#r?.disconnect(), this.#r = null, this.#l(), super.teardown();
|
|
488
734
|
}
|
|
489
735
|
#c() {
|
|
490
736
|
if (this.#i) return;
|
|
491
|
-
let e = Number(this.getAttribute("virtual-item-height")) || 80,
|
|
492
|
-
for (this.#i = new
|
|
737
|
+
let e = Number(this.getAttribute("virtual-item-height")) || 80, t = Number(this.getAttribute("virtual-overscan")) || 5;
|
|
738
|
+
for (this.#i = new a(this, {
|
|
493
739
|
itemHeight: e,
|
|
494
|
-
overscan:
|
|
740
|
+
overscan: t
|
|
495
741
|
}), this.#a = document.createElement("div"), this.#a.className = "n-chat-feed-virtual-container"; this.firstChild;) this.#a.appendChild(this.firstChild);
|
|
496
742
|
this.appendChild(this.#a), this.#i.enable(this, this.#a, this.#o.value.length), this.addEventListener("native:virtual-change", this.#u);
|
|
497
743
|
}
|
|
@@ -524,7 +770,7 @@ var a = class extends e {
|
|
|
524
770
|
}
|
|
525
771
|
}
|
|
526
772
|
#f = () => {
|
|
527
|
-
let e = this.#n.value, t = this.scrollTop + this.clientHeight >= this.scrollHeight -
|
|
773
|
+
let e = this.#n.value, t = this.scrollTop + this.clientHeight >= this.scrollHeight - d;
|
|
528
774
|
this.#n.value = t, t !== e && this.dispatchEvent(new CustomEvent("native:feed-scroll", {
|
|
529
775
|
bubbles: !0,
|
|
530
776
|
composed: !0,
|
|
@@ -542,16 +788,15 @@ var a = class extends e {
|
|
|
542
788
|
});
|
|
543
789
|
});
|
|
544
790
|
};
|
|
545
|
-
|
|
546
|
-
}, l = class extends e {
|
|
791
|
+
}, p = class extends i {
|
|
547
792
|
static observedAttributes = [
|
|
548
793
|
"src",
|
|
549
794
|
"name",
|
|
550
795
|
"icon"
|
|
551
796
|
];
|
|
552
|
-
#e =
|
|
553
|
-
#t =
|
|
554
|
-
#n =
|
|
797
|
+
#e = s("");
|
|
798
|
+
#t = s("");
|
|
799
|
+
#n = s("");
|
|
555
800
|
attributeChangedCallback(e, t, n) {
|
|
556
801
|
if (t !== n) {
|
|
557
802
|
switch (e) {
|
|
@@ -583,7 +828,7 @@ var a = class extends e {
|
|
|
583
828
|
}
|
|
584
829
|
if (n) {
|
|
585
830
|
let e = document.createElement("span");
|
|
586
|
-
e.className = "n-chat-avatar-initials", e.textContent =
|
|
831
|
+
e.className = "n-chat-avatar-initials", e.textContent = m(n), e.setAttribute("aria-hidden", "true"), this.appendChild(e);
|
|
587
832
|
return;
|
|
588
833
|
}
|
|
589
834
|
let r = document.createElement("n-icon");
|
|
@@ -594,11 +839,11 @@ var a = class extends e {
|
|
|
594
839
|
this.textContent = "", super.teardown();
|
|
595
840
|
}
|
|
596
841
|
};
|
|
597
|
-
function
|
|
842
|
+
function m(e) {
|
|
598
843
|
let t = e.trim().split(/\s+/);
|
|
599
844
|
return t.length === 0 ? "" : t.length === 1 ? t[0][0].toUpperCase() : (t[0][0] + t[t.length - 1][0]).toUpperCase();
|
|
600
845
|
}
|
|
601
|
-
const
|
|
846
|
+
const h = {
|
|
602
847
|
copy: {
|
|
603
848
|
label: "Copy",
|
|
604
849
|
icon: "copy"
|
|
@@ -623,7 +868,7 @@ const d = {
|
|
|
623
868
|
label: "Continue",
|
|
624
869
|
icon: "arrow-right"
|
|
625
870
|
}
|
|
626
|
-
},
|
|
871
|
+
}, g = {
|
|
627
872
|
assistant: [
|
|
628
873
|
"copy",
|
|
629
874
|
"retry",
|
|
@@ -648,9 +893,9 @@ const d = {
|
|
|
648
893
|
* @fires native:message-action - Fired when an action button is clicked
|
|
649
894
|
* @fires native:continue-request - Fired when continue is requested for a partial message
|
|
650
895
|
*/
|
|
651
|
-
var
|
|
896
|
+
var _ = class extends i {
|
|
652
897
|
static observedAttributes = [
|
|
653
|
-
"role",
|
|
898
|
+
"data-role",
|
|
654
899
|
"message-id",
|
|
655
900
|
"timestamp",
|
|
656
901
|
"status",
|
|
@@ -659,11 +904,11 @@ var p = class extends e {
|
|
|
659
904
|
"actions-position"
|
|
660
905
|
];
|
|
661
906
|
#e;
|
|
662
|
-
#t =
|
|
663
|
-
#n =
|
|
664
|
-
#r =
|
|
665
|
-
#i =
|
|
666
|
-
#a =
|
|
907
|
+
#t = s("assistant");
|
|
908
|
+
#n = s("sent");
|
|
909
|
+
#r = s(null);
|
|
910
|
+
#i = s("icon");
|
|
911
|
+
#a = s("below");
|
|
667
912
|
#o = null;
|
|
668
913
|
#s = !1;
|
|
669
914
|
#c = 0;
|
|
@@ -675,7 +920,7 @@ var p = class extends e {
|
|
|
675
920
|
return this.#t.value;
|
|
676
921
|
}
|
|
677
922
|
set role(e) {
|
|
678
|
-
this.#t.value = e, this.setAttribute("role", e);
|
|
923
|
+
this.#t.value = e, this.setAttribute("data-role", e);
|
|
679
924
|
}
|
|
680
925
|
get messageId() {
|
|
681
926
|
return this.getAttribute("message-id") ?? "";
|
|
@@ -710,7 +955,7 @@ var p = class extends e {
|
|
|
710
955
|
attributeChangedCallback(e, t, n) {
|
|
711
956
|
if (t !== n) {
|
|
712
957
|
switch (e) {
|
|
713
|
-
case "role":
|
|
958
|
+
case "data-role":
|
|
714
959
|
this.#t.value = n ?? "assistant";
|
|
715
960
|
break;
|
|
716
961
|
case "status":
|
|
@@ -764,23 +1009,23 @@ var p = class extends e {
|
|
|
764
1009
|
this.#o.removeEventListener("native:press", this.#m), this.#o.remove();
|
|
765
1010
|
}
|
|
766
1011
|
}
|
|
767
|
-
#p(e, t, n, r,
|
|
1012
|
+
#p(e, t, n, r, i) {
|
|
768
1013
|
if (this.#o &&= (this.#f(), null), clearTimeout(this.#l), t === "none" || this.querySelector("[slot=\"actions\"]")) return;
|
|
769
|
-
let
|
|
770
|
-
if (
|
|
771
|
-
let
|
|
772
|
-
|
|
773
|
-
for (let e of
|
|
774
|
-
let t =
|
|
775
|
-
t &&
|
|
1014
|
+
let a;
|
|
1015
|
+
if (a = t ? t.split(",").map((e) => e.trim()).filter(Boolean) : g[e] ?? [], i === "partial" && !a.includes("continue") && (a = [...a, "continue"]), a.length === 0) return;
|
|
1016
|
+
let o = document.createElement("n-toolbar");
|
|
1017
|
+
o.dataset.role = "actions", o.setAttribute("padding", "tight"), o.setAttribute("aria-label", "Message actions"), n !== "label" && o.setAttribute("data-style", n);
|
|
1018
|
+
for (let e of a) {
|
|
1019
|
+
let t = h[e];
|
|
1020
|
+
t && o.appendChild(v(e, t, n));
|
|
776
1021
|
}
|
|
777
|
-
if (
|
|
778
|
-
if (
|
|
779
|
-
|
|
780
|
-
let e =
|
|
781
|
-
this.style.setProperty("anchor-name", `--${e}`),
|
|
782
|
-
} else this.appendChild(
|
|
783
|
-
this.#o =
|
|
1022
|
+
if (o.children.length !== 0) {
|
|
1023
|
+
if (o.addEventListener("native:press", this.#m), r === "below") {
|
|
1024
|
+
o.setAttribute("popover", "manual");
|
|
1025
|
+
let e = c("msg");
|
|
1026
|
+
this.style.setProperty("anchor-name", `--${e}`), o.style.setProperty("position-anchor", `--${e}`), this.appendChild(o), this.#s = !0, o.addEventListener("pointerenter", this.#u), o.addEventListener("pointerleave", this.#d), o.addEventListener("focusin", this.#u), o.addEventListener("focusout", this.#d), i === "partial" && o.showPopover();
|
|
1027
|
+
} else this.appendChild(o);
|
|
1028
|
+
this.#o = o;
|
|
784
1029
|
}
|
|
785
1030
|
}
|
|
786
1031
|
#m = (e) => {
|
|
@@ -805,7 +1050,7 @@ var p = class extends e {
|
|
|
805
1050
|
}
|
|
806
1051
|
};
|
|
807
1052
|
};
|
|
808
|
-
function
|
|
1053
|
+
function v(e, t, n) {
|
|
809
1054
|
let r = document.createElement("n-button");
|
|
810
1055
|
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") {
|
|
811
1056
|
let e = document.createElement("n-icon");
|
|
@@ -842,9 +1087,9 @@ function m(e, t, n) {
|
|
|
842
1087
|
* @attr {string} sender - Display name of the sender
|
|
843
1088
|
* @attr {string} avatar-align - `"top"` | `"center"` | `"bottom"` (default) — avatar vertical alignment
|
|
844
1089
|
*/
|
|
845
|
-
var
|
|
1090
|
+
var y = class extends i {
|
|
846
1091
|
static observedAttributes = [
|
|
847
|
-
"role",
|
|
1092
|
+
"data-role",
|
|
848
1093
|
"sender",
|
|
849
1094
|
"avatar-align"
|
|
850
1095
|
];
|
|
@@ -861,7 +1106,7 @@ var h = class extends e {
|
|
|
861
1106
|
setup() {
|
|
862
1107
|
super.setup(), this.#e.role = "group";
|
|
863
1108
|
let e = this.getAttribute("sender");
|
|
864
|
-
e &&
|
|
1109
|
+
e && this.setAttribute("aria-label", `Messages from ${e}`), this.#i(), this.#r = new MutationObserver((e) => {
|
|
865
1110
|
for (let t of e) for (let e of t.addedNodes) e instanceof Element && e.localName !== "n-chat-avatar" && (e === this.#t || e === this.#n || (e.localName === "n-chat-message" ? this.#n?.appendChild(e) : this.#t?.appendChild(e)));
|
|
866
1111
|
}), this.#r.observe(this, { childList: !0 });
|
|
867
1112
|
}
|
|
@@ -885,11 +1130,12 @@ var h = class extends e {
|
|
|
885
1130
|
for (let r of n) r instanceof Element && r.localName === "n-chat-avatar" || (r instanceof Element && r.localName === "n-chat-message" ? t.appendChild(r) : e.appendChild(r));
|
|
886
1131
|
this.appendChild(e), this.appendChild(t), this.#t = e, this.#n = t;
|
|
887
1132
|
}
|
|
888
|
-
},
|
|
1133
|
+
}, b = class extends i {
|
|
889
1134
|
static observedAttributes = ["format"];
|
|
890
|
-
#e =
|
|
891
|
-
#t =
|
|
1135
|
+
#e = s("markdown");
|
|
1136
|
+
#t = s("");
|
|
892
1137
|
#n = null;
|
|
1138
|
+
#r = 0;
|
|
893
1139
|
get content() {
|
|
894
1140
|
return this.#t.value;
|
|
895
1141
|
}
|
|
@@ -909,14 +1155,16 @@ var h = class extends e {
|
|
|
909
1155
|
super.setup(), this.deferChildren(() => {
|
|
910
1156
|
!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(() => {
|
|
911
1157
|
let e = this.#t.value, t = this.#e.value;
|
|
912
|
-
this.#n && (t === "plain" ? this.#n.textContent = e : this.#
|
|
1158
|
+
this.#n && (t === "plain" ? this.#n.textContent = e : (cancelAnimationFrame(this.#r), this.#r = requestAnimationFrame(() => {
|
|
1159
|
+
this.#n && (this.#n.innerHTML = T(w(e)));
|
|
1160
|
+
})));
|
|
913
1161
|
});
|
|
914
1162
|
});
|
|
915
1163
|
}
|
|
916
1164
|
teardown() {
|
|
917
|
-
this.#n = null, super.teardown();
|
|
1165
|
+
cancelAnimationFrame(this.#r), this.#n = null, super.teardown();
|
|
918
1166
|
}
|
|
919
|
-
},
|
|
1167
|
+
}, x = new Set([
|
|
920
1168
|
"p",
|
|
921
1169
|
"br",
|
|
922
1170
|
"strong",
|
|
@@ -936,14 +1184,14 @@ var h = class extends e {
|
|
|
936
1184
|
"blockquote",
|
|
937
1185
|
"hr"
|
|
938
1186
|
]);
|
|
939
|
-
function
|
|
1187
|
+
function S(e) {
|
|
940
1188
|
return e.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("\"", """).replaceAll("'", "'");
|
|
941
1189
|
}
|
|
942
|
-
function
|
|
943
|
-
let t =
|
|
1190
|
+
function C(e) {
|
|
1191
|
+
let t = S(e);
|
|
944
1192
|
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;
|
|
945
1193
|
}
|
|
946
|
-
function
|
|
1194
|
+
function w(e) {
|
|
947
1195
|
if (!e) return "";
|
|
948
1196
|
let t = e.split("\n"), n = [], r = 0;
|
|
949
1197
|
for (; r < t.length;) {
|
|
@@ -952,14 +1200,14 @@ function b(e) {
|
|
|
952
1200
|
let i = e.slice(3).trim(), a = [];
|
|
953
1201
|
for (r += 1; r < t.length && !t[r].startsWith("```");) a.push(t[r]), r += 1;
|
|
954
1202
|
r += 1;
|
|
955
|
-
let o = i ? ` data-lang="${
|
|
956
|
-
n.push(`<pre${o}><code>${
|
|
1203
|
+
let o = i ? ` data-lang="${S(i)}"` : "";
|
|
1204
|
+
n.push(`<pre${o}><code>${S(a.join("\n"))}</code></pre>`);
|
|
957
1205
|
continue;
|
|
958
1206
|
}
|
|
959
1207
|
let i = e.match(/^(#{1,6})\s+(.+)/);
|
|
960
1208
|
if (i) {
|
|
961
1209
|
let e = i[1].length;
|
|
962
|
-
n.push(`<h${e}>${
|
|
1210
|
+
n.push(`<h${e}>${C(i[2])}</h${e}>`), r += 1;
|
|
963
1211
|
continue;
|
|
964
1212
|
}
|
|
965
1213
|
if (/^---+$/.test(e.trim()) || /^\*\*\*+$/.test(e.trim())) {
|
|
@@ -969,19 +1217,19 @@ function b(e) {
|
|
|
969
1217
|
if (e.startsWith("> ")) {
|
|
970
1218
|
let e = [];
|
|
971
1219
|
for (; r < t.length && t[r].startsWith("> ");) e.push(t[r].slice(2)), r += 1;
|
|
972
|
-
n.push(`<blockquote>${
|
|
1220
|
+
n.push(`<blockquote>${w(e.join("\n"))}</blockquote>`);
|
|
973
1221
|
continue;
|
|
974
1222
|
}
|
|
975
1223
|
if (/^[-*+]\s/.test(e)) {
|
|
976
1224
|
let e = [];
|
|
977
1225
|
for (; r < t.length && /^[-*+]\s/.test(t[r]);) e.push(t[r].replace(/^[-*+]\s/, "")), r += 1;
|
|
978
|
-
n.push("<ul>" + e.map((e) => `<li>${
|
|
1226
|
+
n.push("<ul>" + e.map((e) => `<li>${C(e)}</li>`).join("") + "</ul>");
|
|
979
1227
|
continue;
|
|
980
1228
|
}
|
|
981
1229
|
if (/^\d+\.\s/.test(e)) {
|
|
982
1230
|
let e = [];
|
|
983
1231
|
for (; r < t.length && /^\d+\.\s/.test(t[r]);) e.push(t[r].replace(/^\d+\.\s/, "")), r += 1;
|
|
984
|
-
n.push("<ol>" + e.map((e) => `<li>${
|
|
1232
|
+
n.push("<ol>" + e.map((e) => `<li>${C(e)}</li>`).join("") + "</ol>");
|
|
985
1233
|
continue;
|
|
986
1234
|
}
|
|
987
1235
|
if (!e.trim()) {
|
|
@@ -990,15 +1238,15 @@ function b(e) {
|
|
|
990
1238
|
}
|
|
991
1239
|
let a = [];
|
|
992
1240
|
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;
|
|
993
|
-
a.length > 0 && n.push(`<p>${
|
|
1241
|
+
a.length > 0 && n.push(`<p>${C(a.join("\n"))}</p>`);
|
|
994
1242
|
}
|
|
995
1243
|
return n.join("");
|
|
996
1244
|
}
|
|
997
1245
|
/** Sanitize rendered HTML — strip any tags not in allowlist. */
|
|
998
|
-
function
|
|
1246
|
+
function T(e) {
|
|
999
1247
|
return e.replace(/<\/?([a-zA-Z][a-zA-Z0-9]*)[^>]*>/g, (e, t) => {
|
|
1000
1248
|
let n = t.toLowerCase();
|
|
1001
|
-
return
|
|
1249
|
+
return x.has(n) ? e : "";
|
|
1002
1250
|
});
|
|
1003
1251
|
}
|
|
1004
1252
|
/**
|
|
@@ -1019,7 +1267,7 @@ function x(e) {
|
|
|
1019
1267
|
* @attr {boolean} expandable - Allow click to expand trace content
|
|
1020
1268
|
* @fires native:activity-toggle - Fired when trace is expanded/collapsed
|
|
1021
1269
|
*/
|
|
1022
|
-
var
|
|
1270
|
+
var E = class extends i {
|
|
1023
1271
|
static observedAttributes = [
|
|
1024
1272
|
"type",
|
|
1025
1273
|
"label",
|
|
@@ -1027,11 +1275,11 @@ var S = class extends e {
|
|
|
1027
1275
|
"expandable"
|
|
1028
1276
|
];
|
|
1029
1277
|
#e;
|
|
1030
|
-
#t =
|
|
1031
|
-
#n =
|
|
1032
|
-
#r =
|
|
1033
|
-
#i =
|
|
1034
|
-
#a =
|
|
1278
|
+
#t = s("typing");
|
|
1279
|
+
#n = s("");
|
|
1280
|
+
#r = s(!1);
|
|
1281
|
+
#i = s(!1);
|
|
1282
|
+
#a = s(!1);
|
|
1035
1283
|
#o = 0;
|
|
1036
1284
|
#s = 0;
|
|
1037
1285
|
#c = null;
|
|
@@ -1077,7 +1325,7 @@ var S = class extends e {
|
|
|
1077
1325
|
this.#r.value ? (this.#p(), this.#e.states.add("active")) : (this.#m(), this.#e.states.delete("active"));
|
|
1078
1326
|
}), this.addEffect(() => {
|
|
1079
1327
|
if (!this.#c) return;
|
|
1080
|
-
let e = this.#n.value ||
|
|
1328
|
+
let e = this.#n.value || D(this.#t.value);
|
|
1081
1329
|
this.#c.textContent = e;
|
|
1082
1330
|
}), this.addEffect(() => {
|
|
1083
1331
|
this.#u && (this.#u.hidden = !this.#r.value);
|
|
@@ -1099,7 +1347,7 @@ var S = class extends e {
|
|
|
1099
1347
|
n.className = "n-chat-activity-sep", n.textContent = "|", n.setAttribute("aria-hidden", "true"), this.#c = document.createElement("span"), this.#c.className = "n-chat-activity-label", this.#u = document.createElement("span"), this.#u.className = "n-chat-activity-dots", this.#u.setAttribute("aria-hidden", "true"), this.#u.innerHTML = "<i></i><i></i><i></i>", t.append(this.#l, n, this.#c, this.#u), this.#d = document.createElement("div"), this.#d.className = "n-chat-activity-content", this.#d.hidden = !0, this.#d.appendChild(e), this.append(t, this.#d);
|
|
1100
1348
|
}
|
|
1101
1349
|
#p() {
|
|
1102
|
-
this.#o = performance.now(), this.#h();
|
|
1350
|
+
this.#m(), this.#o = performance.now(), this.#h();
|
|
1103
1351
|
}
|
|
1104
1352
|
#m() {
|
|
1105
1353
|
this.#s &&= (cancelAnimationFrame(this.#s), 0);
|
|
@@ -1107,7 +1355,7 @@ var S = class extends e {
|
|
|
1107
1355
|
#h = () => {
|
|
1108
1356
|
if (!this.#r.value || !this.#l) return;
|
|
1109
1357
|
let e = performance.now() - this.#o;
|
|
1110
|
-
this.#l.textContent =
|
|
1358
|
+
this.#l.textContent = O(e), this.#s = requestAnimationFrame(this.#h);
|
|
1111
1359
|
};
|
|
1112
1360
|
#g = () => {
|
|
1113
1361
|
this.#i.value && (this.#a.value = !this.#a.value, this.toggleAttribute("expanded", this.#a.value), this.dispatchEvent(new CustomEvent("native:activity-toggle", {
|
|
@@ -1117,14 +1365,14 @@ var S = class extends e {
|
|
|
1117
1365
|
})));
|
|
1118
1366
|
};
|
|
1119
1367
|
};
|
|
1120
|
-
function
|
|
1368
|
+
function D(e) {
|
|
1121
1369
|
switch (e) {
|
|
1122
1370
|
case "thinking": return "Thinking…";
|
|
1123
1371
|
case "tool-use": return "Using tools…";
|
|
1124
1372
|
default: return "Host is typing…";
|
|
1125
1373
|
}
|
|
1126
1374
|
}
|
|
1127
|
-
function
|
|
1375
|
+
function O(e) {
|
|
1128
1376
|
let t = Math.floor(e / 1e3);
|
|
1129
1377
|
if (t < 60) return `${t}s`;
|
|
1130
1378
|
let n = Math.floor(t / 60), r = t % 60;
|
|
@@ -1144,11 +1392,11 @@ function w(e) {
|
|
|
1144
1392
|
* @attr {boolean} disabled - Disables all chips
|
|
1145
1393
|
* @fires native:seed-select - Fired when a chip is clicked
|
|
1146
1394
|
*/
|
|
1147
|
-
var
|
|
1395
|
+
var k = class extends i {
|
|
1148
1396
|
static observedAttributes = ["options", "disabled"];
|
|
1149
1397
|
#e;
|
|
1150
|
-
#t =
|
|
1151
|
-
#n =
|
|
1398
|
+
#t = s([]);
|
|
1399
|
+
#n = s(!1);
|
|
1152
1400
|
constructor() {
|
|
1153
1401
|
super(), this.#e = this.attachInternals();
|
|
1154
1402
|
}
|
|
@@ -1182,11 +1430,11 @@ var T = class extends e {
|
|
|
1182
1430
|
}
|
|
1183
1431
|
}
|
|
1184
1432
|
setup() {
|
|
1185
|
-
super.setup(), this.addEffect(
|
|
1433
|
+
super.setup(), this.addEffect(o(this, this.#n, this.#e)), this.addEffect(() => {
|
|
1186
1434
|
let e = this.#t.value;
|
|
1187
1435
|
this.textContent = "";
|
|
1188
1436
|
let t = document.createElement("n-stack");
|
|
1189
|
-
t.setAttribute("direction", "row"), t.setAttribute("wrap", "")
|
|
1437
|
+
t.setAttribute("direction", "row"), t.setAttribute("wrap", "");
|
|
1190
1438
|
for (let n of e) {
|
|
1191
1439
|
let e = document.createElement("n-button");
|
|
1192
1440
|
if (e.setAttribute("variant", "outline"), e.setAttribute("size", "sm"), e.setAttribute("inline", ""), e.setAttribute("data-value", n.value), n.icon) {
|
|
@@ -1216,7 +1464,7 @@ var T = class extends e {
|
|
|
1216
1464
|
}
|
|
1217
1465
|
}));
|
|
1218
1466
|
};
|
|
1219
|
-
},
|
|
1467
|
+
}, A = new Set([
|
|
1220
1468
|
"script",
|
|
1221
1469
|
"style",
|
|
1222
1470
|
"link",
|
|
@@ -1233,13 +1481,14 @@ var T = class extends e {
|
|
|
1233
1481
|
"frame",
|
|
1234
1482
|
"frameset",
|
|
1235
1483
|
"noscript"
|
|
1236
|
-
]),
|
|
1484
|
+
]), j = class extends i {
|
|
1237
1485
|
static observedAttributes = ["schema-type", "mode"];
|
|
1238
1486
|
#e;
|
|
1239
|
-
#t =
|
|
1240
|
-
#n =
|
|
1241
|
-
#r =
|
|
1487
|
+
#t = s("a2ui");
|
|
1488
|
+
#n = s("inline");
|
|
1489
|
+
#r = s(null);
|
|
1242
1490
|
#i = null;
|
|
1491
|
+
#a = null;
|
|
1243
1492
|
constructor() {
|
|
1244
1493
|
super(), this.#e = this.attachInternals();
|
|
1245
1494
|
}
|
|
@@ -1278,50 +1527,59 @@ var T = class extends e {
|
|
|
1278
1527
|
super.setup(), this.#i = document.createElement("div"), this.#i.className = "n-chat-genui-container", this.appendChild(this.#i), this.addEffect(() => {
|
|
1279
1528
|
let e = this.#r.value, t = this.#n.value;
|
|
1280
1529
|
if (!this.#i || (this.#i.textContent = "", !e)) return;
|
|
1281
|
-
let n =
|
|
1530
|
+
let n = M(e);
|
|
1282
1531
|
if (n.length > 0) {
|
|
1283
|
-
this.#
|
|
1532
|
+
this.#o(n), this.dispatchEvent(new CustomEvent("native:genui-error", {
|
|
1284
1533
|
bubbles: !0,
|
|
1285
1534
|
composed: !0,
|
|
1286
1535
|
detail: { errors: n }
|
|
1287
1536
|
}));
|
|
1288
1537
|
return;
|
|
1289
1538
|
}
|
|
1290
|
-
if (t === "lightbox") this.#
|
|
1539
|
+
if (t === "lightbox") this.#s(e);
|
|
1291
1540
|
else {
|
|
1292
|
-
let t =
|
|
1541
|
+
let t = N(e);
|
|
1293
1542
|
t && this.#i.appendChild(t);
|
|
1294
1543
|
}
|
|
1295
1544
|
this.#e.states.add("rendered");
|
|
1296
|
-
}), this.addEventListener("native:press", this.#
|
|
1545
|
+
}), this.addEventListener("native:press", this.#u);
|
|
1297
1546
|
}
|
|
1298
1547
|
teardown() {
|
|
1299
|
-
this.removeEventListener("native:press", this.#
|
|
1548
|
+
this.removeEventListener("native:press", this.#u), this.#l(), this.#i = null, super.teardown();
|
|
1300
1549
|
}
|
|
1301
|
-
#
|
|
1550
|
+
#o(e) {
|
|
1302
1551
|
if (!this.#i) return;
|
|
1303
1552
|
let t = document.createElement("div");
|
|
1304
1553
|
t.className = "n-chat-genui-error", t.textContent = `Schema validation failed: ${e.join(", ")}`, this.#i.appendChild(t);
|
|
1305
1554
|
}
|
|
1306
|
-
#
|
|
1555
|
+
#s(e) {
|
|
1307
1556
|
if (!this.#i) return;
|
|
1308
1557
|
let t = document.createElement("n-card");
|
|
1309
1558
|
t.dataset.role = "preview";
|
|
1310
1559
|
let n = document.createElement("span");
|
|
1311
1560
|
n.textContent = `Interactive UI (${e.tag})`, t.appendChild(n);
|
|
1312
1561
|
let r = document.createElement("n-button");
|
|
1313
|
-
r.setAttribute("variant", "outline"), r.setAttribute("size", "sm"), r.setAttribute("inline", ""), r.textContent = "Open", r.addEventListener("click", () => this.#
|
|
1562
|
+
r.setAttribute("variant", "outline"), r.setAttribute("size", "sm"), r.setAttribute("inline", ""), r.textContent = "Open", r.addEventListener("click", () => this.#c(e)), t.appendChild(r), this.#i.appendChild(t);
|
|
1314
1563
|
}
|
|
1315
|
-
#
|
|
1316
|
-
|
|
1317
|
-
|
|
1564
|
+
#c(e) {
|
|
1565
|
+
this.#l();
|
|
1566
|
+
let t = document.createElement("n-dialog"), n = N(e);
|
|
1567
|
+
n && t.appendChild(n), this.appendChild(t), this.#a = t, requestAnimationFrame(() => {
|
|
1318
1568
|
let e = t.querySelector("dialog");
|
|
1319
1569
|
e && e.showModal();
|
|
1320
1570
|
}), t.addEventListener("close", () => {
|
|
1321
|
-
t.remove();
|
|
1571
|
+
t.remove(), this.#a === t && (this.#a = null);
|
|
1322
1572
|
});
|
|
1323
1573
|
}
|
|
1324
|
-
#
|
|
1574
|
+
#l() {
|
|
1575
|
+
if (!this.#a) return;
|
|
1576
|
+
let e = this.#a.querySelector("dialog");
|
|
1577
|
+
if (e?.open) try {
|
|
1578
|
+
e.close();
|
|
1579
|
+
} catch {}
|
|
1580
|
+
this.#a.remove(), this.#a = null;
|
|
1581
|
+
}
|
|
1582
|
+
#u = (e) => {
|
|
1325
1583
|
this.#i?.contains(e.target) && this.dispatchEvent(new CustomEvent("native:genui-action", {
|
|
1326
1584
|
bubbles: !0,
|
|
1327
1585
|
composed: !0,
|
|
@@ -1333,20 +1591,20 @@ var T = class extends e {
|
|
|
1333
1591
|
}));
|
|
1334
1592
|
};
|
|
1335
1593
|
};
|
|
1336
|
-
function
|
|
1594
|
+
function M(e, t = 0) {
|
|
1337
1595
|
let n = [];
|
|
1338
1596
|
if (t > 20) return n.push("Maximum nesting depth (20) exceeded"), n;
|
|
1339
1597
|
if (!e.tag || typeof e.tag != "string") return n.push("Node missing required \"tag\" property"), n;
|
|
1340
|
-
if (
|
|
1598
|
+
if (A.has(e.tag.toLowerCase()) && n.push(`Forbidden tag: <${e.tag}>`), e.children) for (let r of e.children) n.push(...M(r, t + 1));
|
|
1341
1599
|
return n;
|
|
1342
1600
|
}
|
|
1343
|
-
function
|
|
1344
|
-
if (
|
|
1601
|
+
function N(e) {
|
|
1602
|
+
if (A.has(e.tag.toLowerCase())) return null;
|
|
1345
1603
|
let t = document.createElement(e.tag);
|
|
1346
1604
|
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);
|
|
1347
1605
|
if (e.properties) for (let [n, r] of Object.entries(e.properties)) t[n] = r;
|
|
1348
1606
|
if (e.text && (t.textContent = e.text), e.children) for (let n of e.children) {
|
|
1349
|
-
let e =
|
|
1607
|
+
let e = N(n);
|
|
1350
1608
|
e && t.appendChild(e);
|
|
1351
1609
|
}
|
|
1352
1610
|
return t;
|
|
@@ -1371,7 +1629,7 @@ function k(e) {
|
|
|
1371
1629
|
* @fires native:structured-submit - Fired on submit with selections
|
|
1372
1630
|
* @fires native:structured-cancel - Fired when dismissed without selecting
|
|
1373
1631
|
*/
|
|
1374
|
-
var
|
|
1632
|
+
var P = class extends i {
|
|
1375
1633
|
static observedAttributes = [
|
|
1376
1634
|
"question",
|
|
1377
1635
|
"type",
|
|
@@ -1380,12 +1638,12 @@ var A = class extends e {
|
|
|
1380
1638
|
"disabled"
|
|
1381
1639
|
];
|
|
1382
1640
|
#e;
|
|
1383
|
-
#t =
|
|
1384
|
-
#n =
|
|
1385
|
-
#r =
|
|
1386
|
-
#i =
|
|
1387
|
-
#a =
|
|
1388
|
-
#o =
|
|
1641
|
+
#t = s("");
|
|
1642
|
+
#n = s("single");
|
|
1643
|
+
#r = s([]);
|
|
1644
|
+
#i = s(!1);
|
|
1645
|
+
#a = s(!1);
|
|
1646
|
+
#o = s(/* @__PURE__ */ new Set());
|
|
1389
1647
|
constructor() {
|
|
1390
1648
|
super(), this.#e = this.attachInternals();
|
|
1391
1649
|
}
|
|
@@ -1438,37 +1696,46 @@ var A = class extends e {
|
|
|
1438
1696
|
}
|
|
1439
1697
|
}
|
|
1440
1698
|
setup() {
|
|
1441
|
-
super.setup(), this.addEffect(
|
|
1442
|
-
this.#s();
|
|
1699
|
+
super.setup(), this.addEffect(o(this, this.#a, this.#e)), this.addEffect(() => {
|
|
1700
|
+
this.#t.value, this.#r.value, this.#n.value, this.#s();
|
|
1701
|
+
}), this.addEffect(() => {
|
|
1702
|
+
let e = this.#o.value, t = this.querySelectorAll("[data-value]");
|
|
1703
|
+
for (let n of t) {
|
|
1704
|
+
let t = n.getAttribute("data-value") ?? "", r = e.has(t);
|
|
1705
|
+
n.setAttribute("variant", r ? "primary" : "outline"), n.setAttribute("aria-pressed", String(r));
|
|
1706
|
+
}
|
|
1707
|
+
let n = this.querySelector("[data-action=\"submit\"]");
|
|
1708
|
+
n && this.#i.value && n.toggleAttribute("disabled", e.size === 0);
|
|
1443
1709
|
}), this.addEventListener("native:press", this.#c);
|
|
1444
1710
|
}
|
|
1445
1711
|
teardown() {
|
|
1446
1712
|
this.removeEventListener("native:press", this.#c), super.teardown();
|
|
1447
1713
|
}
|
|
1448
1714
|
#s() {
|
|
1449
|
-
let e = this.#t.value, t = this.#r.value, n = this.#
|
|
1450
|
-
if (this.textContent = "",
|
|
1715
|
+
let e = this.#t.value, t = this.#r.value, n = this.#n.value;
|
|
1716
|
+
if (this.textContent = "", t.length === 0) return;
|
|
1717
|
+
if (e) {
|
|
1451
1718
|
let t = document.createElement("div");
|
|
1452
1719
|
t.className = "n-chat-structured-question", t.textContent = e, this.appendChild(t);
|
|
1453
1720
|
}
|
|
1454
|
-
let
|
|
1455
|
-
|
|
1721
|
+
let r = document.createElement("n-stack");
|
|
1722
|
+
r.setAttribute("direction", "row"), r.setAttribute("wrap", ""), r.setAttribute("role", n === "multi" ? "group" : "radiogroup");
|
|
1456
1723
|
for (let e of t) {
|
|
1457
|
-
let t = document.createElement("n-button")
|
|
1458
|
-
if (t.setAttribute("variant",
|
|
1724
|
+
let t = document.createElement("n-button");
|
|
1725
|
+
if (t.setAttribute("variant", "outline"), t.setAttribute("data-value", e.value), t.setAttribute("aria-pressed", "false"), e.icon) {
|
|
1459
1726
|
let n = document.createElement("n-icon");
|
|
1460
1727
|
n.setAttribute("name", e.icon), n.setAttribute("slot", "leading"), t.appendChild(n);
|
|
1461
1728
|
}
|
|
1462
|
-
let
|
|
1463
|
-
|
|
1729
|
+
let n = document.createElement("span");
|
|
1730
|
+
n.setAttribute("slot", "label"), n.textContent = e.label, t.appendChild(n), r.appendChild(t);
|
|
1464
1731
|
}
|
|
1465
|
-
this.appendChild(
|
|
1466
|
-
let
|
|
1467
|
-
|
|
1732
|
+
this.appendChild(r);
|
|
1733
|
+
let i = document.createElement("div");
|
|
1734
|
+
i.className = "n-chat-structured-actions";
|
|
1735
|
+
let a = document.createElement("n-button");
|
|
1736
|
+
a.setAttribute("variant", "ghost"), a.setAttribute("size", "sm"), a.setAttribute("inline", ""), a.setAttribute("data-action", "cancel"), a.textContent = "Skip", i.appendChild(a);
|
|
1468
1737
|
let o = document.createElement("n-button");
|
|
1469
|
-
o.setAttribute("variant", "
|
|
1470
|
-
let s = document.createElement("n-button");
|
|
1471
|
-
s.setAttribute("variant", "primary"), s.setAttribute("size", "sm"), s.setAttribute("inline", ""), s.setAttribute("data-action", "submit"), s.textContent = "Submit", this.#i.value && n.size === 0 && s.setAttribute("disabled", ""), a.appendChild(s), this.appendChild(a);
|
|
1738
|
+
o.setAttribute("variant", "primary"), o.setAttribute("size", "sm"), o.setAttribute("inline", ""), o.setAttribute("data-action", "submit"), o.textContent = "Submit", this.#i.value && o.setAttribute("disabled", ""), i.appendChild(o), this.appendChild(i);
|
|
1472
1739
|
}
|
|
1473
1740
|
#c = (e) => {
|
|
1474
1741
|
if (this.#a.value) return;
|
|
@@ -1497,4 +1764,4 @@ var A = class extends e {
|
|
|
1497
1764
|
}));
|
|
1498
1765
|
};
|
|
1499
1766
|
};
|
|
1500
|
-
export {
|
|
1767
|
+
export { b as a, T as c, _ as d, g as f, l as g, u as h, E as i, y as l, f as m, j as n, C as o, p, k as r, w as s, P as t, h as u };
|