@green-on-grey/ui-kit 1.5.0 → 1.7.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/ContextMeter.d.ts +4 -2
- package/dist/chat.js +197 -169
- package/dist/chat.js.map +1 -1
- package/dist/components/Icon.d.ts +2 -0
- package/dist/index.js +1 -1
- package/dist/locales/index.d.ts +5 -0
- package/dist/locales.js +10 -5
- package/dist/locales.js.map +1 -1
- package/dist/manifest.json +1 -1
- package/dist/styles.css +3 -2
- package/dist/{ui-ChXUXoIB.js → ui-DvmjcG-d.js} +4 -2
- package/dist/ui-DvmjcG-d.js.map +1 -0
- package/package.json +1 -1
- package/dist/ui-ChXUXoIB.js.map +0 -1
package/dist/chat.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as e, d as t, i as n, l as r, s as i } from "./ui-
|
|
1
|
+
import { c as e, d as t, i as n, l as r, s as i } from "./ui-DvmjcG-d.js";
|
|
2
2
|
import { n as a, t as o } from "./i18n-BJ8rsBp6.js";
|
|
3
3
|
import { Fragment as s, jsx as c, jsxs as l } from "react/jsx-runtime";
|
|
4
4
|
import { useCallback as u, useEffect as d, useLayoutEffect as f, useMemo as p, useRef as m, useState as h } from "react";
|
|
@@ -77,25 +77,25 @@ function b(e, t) {
|
|
|
77
77
|
maximumFractionDigits: 1
|
|
78
78
|
}).format(e);
|
|
79
79
|
}
|
|
80
|
-
function x({ context: e, onCompact:
|
|
81
|
-
let
|
|
80
|
+
function x({ context: e, onCompact: t, onReset: n, busy: r = !1 }) {
|
|
81
|
+
let u = a(), { i18n: d } = g(o), [f, p] = h(!1), m = i(f, () => p(!1)), _ = e.window > 0 ? Math.min(1, e.tokens / e.window) : 0, v = Math.round(_ * 100), y = _ >= .9 ? "full" : _ >= .7 ? "warn" : "", x = 2 * Math.PI * 7, C = d.language;
|
|
82
82
|
return /* @__PURE__ */ l("div", {
|
|
83
83
|
className: "ctxmeter",
|
|
84
|
-
ref:
|
|
84
|
+
ref: m,
|
|
85
85
|
children: [/* @__PURE__ */ c("button", {
|
|
86
86
|
type: "button",
|
|
87
|
-
className: `ctxring ${
|
|
88
|
-
"aria-expanded":
|
|
89
|
-
onClick: () =>
|
|
90
|
-
"aria-label":
|
|
91
|
-
used: b(e.tokens,
|
|
92
|
-
total: b(e.window,
|
|
93
|
-
pct:
|
|
87
|
+
className: `ctxring ${y}`,
|
|
88
|
+
"aria-expanded": f,
|
|
89
|
+
onClick: () => p((e) => !e),
|
|
90
|
+
"aria-label": u("chat.context.meter", {
|
|
91
|
+
used: b(e.tokens, C),
|
|
92
|
+
total: b(e.window, C),
|
|
93
|
+
pct: v
|
|
94
94
|
}),
|
|
95
|
-
title:
|
|
96
|
-
used: b(e.tokens,
|
|
97
|
-
total: b(e.window,
|
|
98
|
-
pct:
|
|
95
|
+
title: u("chat.context.meter", {
|
|
96
|
+
used: b(e.tokens, C),
|
|
97
|
+
total: b(e.window, C),
|
|
98
|
+
pct: v
|
|
99
99
|
}),
|
|
100
100
|
children: /* @__PURE__ */ l("svg", {
|
|
101
101
|
viewBox: "0 0 18 18",
|
|
@@ -110,81 +110,93 @@ function x({ context: e, onCompact: n, onReset: r }) {
|
|
|
110
110
|
cx: "9",
|
|
111
111
|
cy: "9",
|
|
112
112
|
r: 7,
|
|
113
|
-
strokeDasharray: `${(
|
|
113
|
+
strokeDasharray: `${(x * _).toFixed(1)} ${x.toFixed(1)}`,
|
|
114
114
|
transform: "rotate(-90 9 9)"
|
|
115
115
|
})]
|
|
116
116
|
})
|
|
117
|
-
}),
|
|
117
|
+
}), f && /* @__PURE__ */ l("div", {
|
|
118
118
|
className: "ctxtip",
|
|
119
119
|
role: "dialog",
|
|
120
120
|
children: [
|
|
121
|
-
/* @__PURE__ */ c("div", { children:
|
|
122
|
-
used: b(e.tokens,
|
|
123
|
-
total: b(e.window,
|
|
124
|
-
pct:
|
|
121
|
+
/* @__PURE__ */ c("div", { children: u("chat.context.meter", {
|
|
122
|
+
used: b(e.tokens, C),
|
|
123
|
+
total: b(e.window, C),
|
|
124
|
+
pct: v
|
|
125
125
|
}) }),
|
|
126
|
-
|
|
126
|
+
y === "full" && /* @__PURE__ */ c("div", {
|
|
127
127
|
className: "small muted",
|
|
128
128
|
style: { marginTop: 4 },
|
|
129
|
-
children:
|
|
129
|
+
children: u("chat.context.full")
|
|
130
130
|
}),
|
|
131
|
-
|
|
131
|
+
y === "full" && (t || n) && /* @__PURE__ */ l(s, { children: [/* @__PURE__ */ l("div", {
|
|
132
132
|
className: "row",
|
|
133
133
|
style: {
|
|
134
134
|
marginTop: 8,
|
|
135
135
|
gap: 6
|
|
136
136
|
},
|
|
137
|
-
children: [
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
f(!1), r();
|
|
152
|
-
},
|
|
153
|
-
children: [/* @__PURE__ */ c(t, {
|
|
154
|
-
name: "undo",
|
|
155
|
-
size: 14
|
|
156
|
-
}), s("chat.context.reset")]
|
|
137
|
+
children: [t && /* @__PURE__ */ c(S, {
|
|
138
|
+
icon: "compress",
|
|
139
|
+
label: u("chat.context.compact"),
|
|
140
|
+
busy: r,
|
|
141
|
+
run: () => {
|
|
142
|
+
p(!1), t();
|
|
143
|
+
}
|
|
144
|
+
}), n && /* @__PURE__ */ c(S, {
|
|
145
|
+
icon: "reset",
|
|
146
|
+
label: u("chat.context.reset"),
|
|
147
|
+
busy: r,
|
|
148
|
+
run: () => {
|
|
149
|
+
p(!1), n();
|
|
150
|
+
}
|
|
157
151
|
})]
|
|
158
|
-
})
|
|
152
|
+
}), r && /* @__PURE__ */ c("div", {
|
|
153
|
+
id: "ctx-wait",
|
|
154
|
+
className: "small muted",
|
|
155
|
+
style: { marginTop: 6 },
|
|
156
|
+
children: u("chat.context.waitTurn")
|
|
157
|
+
})] })
|
|
159
158
|
]
|
|
160
159
|
})]
|
|
161
160
|
});
|
|
162
161
|
}
|
|
162
|
+
function S({ icon: e, label: n, busy: r, run: i }) {
|
|
163
|
+
return /* @__PURE__ */ l("button", {
|
|
164
|
+
type: "button",
|
|
165
|
+
className: "btn sm",
|
|
166
|
+
disabled: r,
|
|
167
|
+
"aria-describedby": r ? "ctx-wait" : void 0,
|
|
168
|
+
onClick: i,
|
|
169
|
+
children: [/* @__PURE__ */ c(t, {
|
|
170
|
+
name: e,
|
|
171
|
+
size: 14
|
|
172
|
+
}), n]
|
|
173
|
+
});
|
|
174
|
+
}
|
|
163
175
|
//#endregion
|
|
164
176
|
//#region src/chat/Attachments.tsx
|
|
165
|
-
var
|
|
177
|
+
var C = /* @__PURE__ */ new Set([
|
|
166
178
|
"image/png",
|
|
167
179
|
"image/jpeg",
|
|
168
180
|
"image/gif",
|
|
169
181
|
"image/webp",
|
|
170
182
|
"image/svg+xml"
|
|
171
|
-
]),
|
|
172
|
-
function
|
|
183
|
+
]), w = /\.(png|jpe?g|gif|webp|svg)$/, T = /\.(txt|log|json|ya?ml|xml|ini|toml|sql|sh|py|go|js|ts|tsx|java|kt|rb|rs|c|cpp|h|css)$/;
|
|
184
|
+
function E(e) {
|
|
173
185
|
let t = (e.mimeType ?? "").toLowerCase().split(";")[0].trim(), n = e.fileName.toLowerCase();
|
|
174
|
-
return
|
|
186
|
+
return C.has(t) || (!t || t === "application/octet-stream") && w.test(n) ? "image" : t === "application/pdf" || n.endsWith(".pdf") ? "pdf" : t === "text/markdown" || /\.(md|markdown)$/.test(n) ? "markdown" : t === "text/csv" || t === "text/tab-separated-values" || /\.(csv|tsv)$/.test(n) ? "table" : t === "text/html" || /\.html?$/.test(n) ? "html" : t.startsWith("text/") || t === "application/json" || t === "application/xml" || T.test(n) ? "text" : null;
|
|
175
187
|
}
|
|
176
|
-
var
|
|
188
|
+
var D = {
|
|
177
189
|
image: "image",
|
|
178
190
|
pdf: "pdf",
|
|
179
191
|
markdown: "markdown",
|
|
180
192
|
table: "table",
|
|
181
193
|
html: "globe",
|
|
182
194
|
text: "source"
|
|
183
|
-
},
|
|
184
|
-
function
|
|
195
|
+
}, O = (e) => D[e];
|
|
196
|
+
function k(e, t) {
|
|
185
197
|
return t === "pdf" ? "PDF" : t === "markdown" ? "MD" : t === "html" ? "HTML" : /\.([a-z0-9]{1,5})$/i.exec(e.fileName)?.[1]?.toUpperCase() ?? (t ? "TXT" : "FILE");
|
|
186
198
|
}
|
|
187
|
-
function
|
|
199
|
+
function A(e, t) {
|
|
188
200
|
let n = [
|
|
189
201
|
"byte",
|
|
190
202
|
"kilobyte",
|
|
@@ -199,23 +211,23 @@ function k(e, t) {
|
|
|
199
211
|
maximumFractionDigits: i === 0 ? 0 : 1
|
|
200
212
|
}).format(r);
|
|
201
213
|
}
|
|
202
|
-
var
|
|
203
|
-
function
|
|
204
|
-
let t = `<meta http-equiv="Content-Security-Policy" content="${
|
|
214
|
+
var j = "default-src 'none'; img-src data:; media-src data:; font-src data:; style-src 'unsafe-inline' data:";
|
|
215
|
+
function ee(e) {
|
|
216
|
+
let t = `<meta http-equiv="Content-Security-Policy" content="${j}">`, n = /^\s*<!doctype[^>]*>/i.exec(e)?.[0] ?? "";
|
|
205
217
|
if (typeof DOMParser > "u") return n + t + e.slice(n.length);
|
|
206
218
|
let r = new DOMParser().parseFromString(e, "text/html");
|
|
207
219
|
r.querySelectorAll("script, noscript, iframe, frame, frameset, object, embed, applet, base, link, meta[http-equiv], portal").forEach((e) => e.remove()), r.querySelectorAll("*").forEach((e) => {
|
|
208
220
|
for (let t of Array.from(e.attributes)) {
|
|
209
221
|
let n = t.name.toLowerCase();
|
|
210
|
-
n.startsWith("on") ||
|
|
222
|
+
n.startsWith("on") || M.has(n) && !N.test(t.value) || n === "srcset" && t.value.split(",").some((e) => !N.test(e)) ? e.removeAttribute(t.name) : n === "style" && e.setAttribute("style", P(t.value));
|
|
211
223
|
}
|
|
212
224
|
}), r.querySelectorAll("style").forEach((e) => {
|
|
213
|
-
e.textContent =
|
|
225
|
+
e.textContent = P(e.textContent ?? "");
|
|
214
226
|
});
|
|
215
227
|
let i = r.createElement("meta");
|
|
216
|
-
return i.setAttribute("http-equiv", "Content-Security-Policy"), i.setAttribute("content",
|
|
228
|
+
return i.setAttribute("http-equiv", "Content-Security-Policy"), i.setAttribute("content", j), r.head.prepend(i), (n ? "<!doctype html>" : "") + r.documentElement.outerHTML;
|
|
217
229
|
}
|
|
218
|
-
var
|
|
230
|
+
var M = /* @__PURE__ */ new Set([
|
|
219
231
|
"src",
|
|
220
232
|
"href",
|
|
221
233
|
"xlink:href",
|
|
@@ -233,11 +245,11 @@ var ee = /* @__PURE__ */ new Set([
|
|
|
233
245
|
"codebase",
|
|
234
246
|
"archive",
|
|
235
247
|
"usemap"
|
|
236
|
-
]),
|
|
237
|
-
function
|
|
238
|
-
return e.replace(/@import[^;]*;?/gi, "").replace(/url\(\s*(['"]?)(.*?)\1\s*\)/gi, (e, t, n) =>
|
|
248
|
+
]), N = /^\s*(data:|#|$)/i;
|
|
249
|
+
function P(e) {
|
|
250
|
+
return e.replace(/@import[^;]*;?/gi, "").replace(/url\(\s*(['"]?)(.*?)\1\s*\)/gi, (e, t, n) => N.test(n) && n.trim() !== "" ? e : "none");
|
|
239
251
|
}
|
|
240
|
-
var
|
|
252
|
+
var F = {
|
|
241
253
|
png: "image/png",
|
|
242
254
|
jpg: "image/jpeg",
|
|
243
255
|
jpeg: "image/jpeg",
|
|
@@ -252,11 +264,11 @@ var P = {
|
|
|
252
264
|
html: "text/html",
|
|
253
265
|
htm: "text/html"
|
|
254
266
|
};
|
|
255
|
-
function
|
|
267
|
+
function I(e) {
|
|
256
268
|
let t = (e.mimeType ?? "").split(";")[0].trim().toLowerCase();
|
|
257
|
-
return t && t !== "application/octet-stream" ? t :
|
|
269
|
+
return t && t !== "application/octet-stream" ? t : F[/\.([a-z0-9]+)$/i.exec(e.fileName)?.[1]?.toLowerCase() ?? ""] ?? (t || void 0);
|
|
258
270
|
}
|
|
259
|
-
function
|
|
271
|
+
function L(e, t) {
|
|
260
272
|
if (t) return e.replace(/\r?\n$/, "").split(/\r?\n/).map((e) => e.split(" "));
|
|
261
273
|
let n = [], r = [], i = "", a = !1;
|
|
262
274
|
for (let t = 0; t < e.length; t++) {
|
|
@@ -265,7 +277,7 @@ function I(e, t) {
|
|
|
265
277
|
}
|
|
266
278
|
return (i !== "" || r.length > 0) && (r.push(i), n.push(r)), n;
|
|
267
279
|
}
|
|
268
|
-
function
|
|
280
|
+
function R(e, t, n = !0) {
|
|
269
281
|
let [r, i] = h({}), { id: a, href: o, fileName: s, mimeType: c, size: l } = e;
|
|
270
282
|
return d(() => {
|
|
271
283
|
if (!n) return;
|
|
@@ -278,7 +290,7 @@ function L(e, t, n = !0) {
|
|
|
278
290
|
size: l
|
|
279
291
|
}).then((t) => {
|
|
280
292
|
if (!r) return;
|
|
281
|
-
let n =
|
|
293
|
+
let n = I({
|
|
282
294
|
fileName: s,
|
|
283
295
|
mimeType: c
|
|
284
296
|
}), a = n && t.type !== n ? new Blob([t], { type: n }) : t;
|
|
@@ -299,9 +311,9 @@ function L(e, t, n = !0) {
|
|
|
299
311
|
l
|
|
300
312
|
]), r;
|
|
301
313
|
}
|
|
302
|
-
function
|
|
303
|
-
let r = a(), { url: i, failed: o } =
|
|
304
|
-
return o ? /* @__PURE__ */ c(
|
|
314
|
+
function z({ a: e, load: t, onOpen: n }) {
|
|
315
|
+
let r = a(), { url: i, failed: o } = R(e, t);
|
|
316
|
+
return o ? /* @__PURE__ */ c(B, {
|
|
305
317
|
a: e,
|
|
306
318
|
kind: "image",
|
|
307
319
|
onOpen: n
|
|
@@ -323,16 +335,16 @@ function R({ a: e, load: t, onOpen: n }) {
|
|
|
323
335
|
})]
|
|
324
336
|
});
|
|
325
337
|
}
|
|
326
|
-
function
|
|
338
|
+
function B({ a: e, kind: n, onOpen: r }) {
|
|
327
339
|
let i = a(), { i18n: u } = g(o), d = n !== null && r !== void 0, f = /* @__PURE__ */ l(s, { children: [
|
|
328
340
|
/* @__PURE__ */ l("span", {
|
|
329
341
|
className: "att-ic",
|
|
330
342
|
children: [/* @__PURE__ */ c(t, {
|
|
331
|
-
name: d && n ?
|
|
343
|
+
name: d && n ? D[n] : "download",
|
|
332
344
|
size: 24
|
|
333
345
|
}), /* @__PURE__ */ c("span", {
|
|
334
346
|
className: "att-kl",
|
|
335
|
-
children:
|
|
347
|
+
children: k(e, n)
|
|
336
348
|
})]
|
|
337
349
|
}),
|
|
338
350
|
/* @__PURE__ */ c("span", {
|
|
@@ -341,7 +353,7 @@ function z({ a: e, kind: n, onOpen: r }) {
|
|
|
341
353
|
}),
|
|
342
354
|
e.size != null && /* @__PURE__ */ c("span", {
|
|
343
355
|
className: "att-size",
|
|
344
|
-
children:
|
|
356
|
+
children: A(e.size, u.language)
|
|
345
357
|
})
|
|
346
358
|
] });
|
|
347
359
|
return d ? /* @__PURE__ */ c("button", {
|
|
@@ -360,16 +372,16 @@ function z({ a: e, kind: n, onOpen: r }) {
|
|
|
360
372
|
children: f
|
|
361
373
|
});
|
|
362
374
|
}
|
|
363
|
-
function
|
|
375
|
+
function V({ items: e, load: t, onOpen: n }) {
|
|
364
376
|
return /* @__PURE__ */ c("div", {
|
|
365
377
|
className: "atts",
|
|
366
378
|
children: e.map((e) => {
|
|
367
|
-
let r = t && n ? () => n(e) : void 0, i =
|
|
368
|
-
return t && r && i === "image" ? /* @__PURE__ */ c(
|
|
379
|
+
let r = t && n ? () => n(e) : void 0, i = E(e);
|
|
380
|
+
return t && r && i === "image" ? /* @__PURE__ */ c(z, {
|
|
369
381
|
a: e,
|
|
370
382
|
load: t,
|
|
371
383
|
onOpen: r
|
|
372
|
-
}, e.id) : /* @__PURE__ */ c(
|
|
384
|
+
}, e.id) : /* @__PURE__ */ c(B, {
|
|
373
385
|
a: e,
|
|
374
386
|
kind: i,
|
|
375
387
|
onOpen: r
|
|
@@ -377,8 +389,8 @@ function B({ items: e, load: t, onOpen: n }) {
|
|
|
377
389
|
})
|
|
378
390
|
});
|
|
379
391
|
}
|
|
380
|
-
function
|
|
381
|
-
let n = a(), [r, ...i] =
|
|
392
|
+
function H({ text: e, tab: t }) {
|
|
393
|
+
let n = a(), [r, ...i] = L(e, t), o = i.slice(0, 500);
|
|
382
394
|
return /* @__PURE__ */ l("div", {
|
|
383
395
|
className: "att-table",
|
|
384
396
|
children: [/* @__PURE__ */ l("table", { children: [r && /* @__PURE__ */ c("thead", { children: /* @__PURE__ */ c("tr", { children: r.map((e, t) => /* @__PURE__ */ c("th", { children: e }, t)) }) }), /* @__PURE__ */ c("tbody", { children: o.map((e, t) => /* @__PURE__ */ c("tr", { children: e.map((e, t) => /* @__PURE__ */ c("td", { children: e }, t)) }, t)) })] }), i.length > o.length && /* @__PURE__ */ c("div", {
|
|
@@ -390,52 +402,61 @@ function V({ text: e, tab: t }) {
|
|
|
390
402
|
})]
|
|
391
403
|
});
|
|
392
404
|
}
|
|
393
|
-
var
|
|
394
|
-
function
|
|
395
|
-
let n = m(null), [r, i] = h(
|
|
405
|
+
var U = 1280;
|
|
406
|
+
function W({ text: e, title: t }) {
|
|
407
|
+
let n = m(null), [r, i] = h(U), [a, o] = h(U);
|
|
396
408
|
d(() => {
|
|
397
409
|
let e = n.current;
|
|
398
410
|
if (!e) return;
|
|
399
|
-
let t = () => i(
|
|
411
|
+
let t = () => i(e.clientWidth);
|
|
400
412
|
if (t(), typeof ResizeObserver > "u") return;
|
|
401
413
|
let r = new ResizeObserver(t);
|
|
402
414
|
return r.observe(e), () => r.disconnect();
|
|
403
415
|
}, []);
|
|
404
|
-
let
|
|
416
|
+
let s = p(() => ee(e), [e]), [l, u] = h(s);
|
|
417
|
+
l !== s && (u(s), o(U));
|
|
418
|
+
let f = (e) => {
|
|
419
|
+
let t = e.currentTarget, n = () => {
|
|
420
|
+
let e = t.contentDocument?.documentElement;
|
|
421
|
+
e && o(Math.max(U, e.scrollWidth));
|
|
422
|
+
};
|
|
423
|
+
n(), t.contentDocument?.fonts?.ready.then(n);
|
|
424
|
+
}, g = Math.min(1, r / a);
|
|
405
425
|
return /* @__PURE__ */ c("div", {
|
|
406
426
|
className: "att-htmlbox",
|
|
407
427
|
ref: n,
|
|
408
428
|
children: /* @__PURE__ */ c("iframe", {
|
|
409
429
|
className: "att-html",
|
|
410
|
-
sandbox: "",
|
|
411
|
-
srcDoc:
|
|
430
|
+
sandbox: "allow-same-origin",
|
|
431
|
+
srcDoc: s,
|
|
412
432
|
title: t,
|
|
413
433
|
referrerPolicy: "no-referrer",
|
|
434
|
+
onLoad: f,
|
|
414
435
|
style: {
|
|
415
|
-
width:
|
|
416
|
-
height: `${100 /
|
|
417
|
-
transform: `scale(${
|
|
436
|
+
width: a,
|
|
437
|
+
height: `${100 / g}%`,
|
|
438
|
+
transform: `scale(${g})`
|
|
418
439
|
}
|
|
419
440
|
})
|
|
420
441
|
});
|
|
421
442
|
}
|
|
422
443
|
function te({ a: e, load: i, onClose: u }) {
|
|
423
|
-
let f = a(), { i18n: p } = g(o), m =
|
|
444
|
+
let f = a(), { i18n: p } = g(o), m = E(e), _ = m === "markdown" || m === "table" || m === "html" || m === "text", [v, y] = h(!1), b = _ && (e.size ?? 0) > 1048576, { url: x, blob: S, failed: C } = R(e, i, !b), [w, T] = h(null), D = b || _ && (S?.size ?? 0) > 1048576;
|
|
424
445
|
d(() => {
|
|
425
446
|
_ && S && !D && S.arrayBuffer().then((e) => {
|
|
426
447
|
try {
|
|
427
|
-
|
|
448
|
+
T({ text: new TextDecoder("utf-8", { fatal: !0 }).decode(e) });
|
|
428
449
|
} catch {
|
|
429
|
-
|
|
450
|
+
T({ text: null });
|
|
430
451
|
}
|
|
431
|
-
}, () =>
|
|
452
|
+
}, () => T({ text: null }));
|
|
432
453
|
}, [
|
|
433
454
|
_,
|
|
434
455
|
S,
|
|
435
456
|
D
|
|
436
457
|
]);
|
|
437
|
-
let O = w?.text,
|
|
438
|
-
return
|
|
458
|
+
let O = w?.text, k;
|
|
459
|
+
return k = C ? /* @__PURE__ */ c("div", {
|
|
439
460
|
className: "att-msg err-text",
|
|
440
461
|
children: f("chat.files.failed")
|
|
441
462
|
}) : D ? /* @__PURE__ */ c("div", {
|
|
@@ -470,10 +491,10 @@ function te({ a: e, load: i, onClose: u }) {
|
|
|
470
491
|
}) : m === "markdown" ? /* @__PURE__ */ c("div", {
|
|
471
492
|
className: "att-md",
|
|
472
493
|
children: /* @__PURE__ */ c(r, { text: O ?? "" })
|
|
473
|
-
}) : m === "table" ? /* @__PURE__ */ c(
|
|
494
|
+
}) : m === "table" ? /* @__PURE__ */ c(H, {
|
|
474
495
|
text: O ?? "",
|
|
475
496
|
tab: /\.tsv$/i.test(e.fileName) || e.mimeType === "text/tab-separated-values"
|
|
476
|
-
}) : m === "html" && !v ? /* @__PURE__ */ c(
|
|
497
|
+
}) : m === "html" && !v ? /* @__PURE__ */ c(W, {
|
|
477
498
|
text: O ?? "",
|
|
478
499
|
title: e.fileName
|
|
479
500
|
}) : /* @__PURE__ */ c("pre", {
|
|
@@ -489,7 +510,7 @@ function te({ a: e, load: i, onClose: u }) {
|
|
|
489
510
|
children: e.fileName
|
|
490
511
|
}), e.size != null && /* @__PURE__ */ c("span", {
|
|
491
512
|
className: "muted small",
|
|
492
|
-
children:
|
|
513
|
+
children: A(e.size, p.language)
|
|
493
514
|
})]
|
|
494
515
|
}),
|
|
495
516
|
footer: /* @__PURE__ */ l(s, { children: [
|
|
@@ -528,22 +549,22 @@ function te({ a: e, load: i, onClose: u }) {
|
|
|
528
549
|
] }),
|
|
529
550
|
children: /* @__PURE__ */ c("div", {
|
|
530
551
|
className: `att-view ${m ?? ""}`,
|
|
531
|
-
children:
|
|
552
|
+
children: k
|
|
532
553
|
})
|
|
533
554
|
});
|
|
534
555
|
}
|
|
535
556
|
//#endregion
|
|
536
557
|
//#region src/chat/MessageView.tsx
|
|
537
|
-
function
|
|
558
|
+
function G(e, t) {
|
|
538
559
|
return new Intl.DateTimeFormat(y(t), {
|
|
539
560
|
hour: "2-digit",
|
|
540
561
|
minute: "2-digit"
|
|
541
562
|
}).format(new Date(e));
|
|
542
563
|
}
|
|
543
|
-
function
|
|
564
|
+
function K(e, t) {
|
|
544
565
|
return t || e.length <= 3 ? e : e.slice(-2);
|
|
545
566
|
}
|
|
546
|
-
var
|
|
567
|
+
var q = {
|
|
547
568
|
done: {
|
|
548
569
|
icon: "check",
|
|
549
570
|
cls: "ok"
|
|
@@ -563,7 +584,7 @@ function ne({ m: e, busy: n, onRetry: i, loadAttachment: a, onOpenAttachment: u
|
|
|
563
584
|
className: "sysnote",
|
|
564
585
|
children: e.text
|
|
565
586
|
});
|
|
566
|
-
if (e.role === "event" && e.event) return /* @__PURE__ */ c(
|
|
587
|
+
if (e.role === "event" && e.event) return /* @__PURE__ */ c(J, { m: e });
|
|
567
588
|
let _ = e.mark && /* @__PURE__ */ l("div", {
|
|
568
589
|
className: "chan",
|
|
569
590
|
children: [
|
|
@@ -574,9 +595,9 @@ function ne({ m: e, busy: n, onRetry: i, loadAttachment: a, onOpenAttachment: u
|
|
|
574
595
|
" ",
|
|
575
596
|
e.mark.text,
|
|
576
597
|
" · ",
|
|
577
|
-
|
|
598
|
+
G(e.createdAt, f.language)
|
|
578
599
|
]
|
|
579
|
-
}), v = e.attachments && e.attachments.length > 0 && /* @__PURE__ */ c(
|
|
600
|
+
}), v = e.attachments && e.attachments.length > 0 && /* @__PURE__ */ c(V, {
|
|
580
601
|
items: e.attachments,
|
|
581
602
|
load: a,
|
|
582
603
|
onOpen: u
|
|
@@ -615,13 +636,13 @@ function ne({ m: e, busy: n, onRetry: i, loadAttachment: a, onOpenAttachment: u
|
|
|
615
636
|
"aria-expanded": p,
|
|
616
637
|
children: p ? d("chat.hideSteps") : d("chat.moreSteps", { count: y.length - 2 })
|
|
617
638
|
}),
|
|
618
|
-
|
|
639
|
+
K(y, p).map((e) => /* @__PURE__ */ l("div", {
|
|
619
640
|
className: "tool",
|
|
620
641
|
title: e.title,
|
|
621
642
|
children: [/* @__PURE__ */ c(t, {
|
|
622
|
-
name:
|
|
643
|
+
name: q[e.status].icon,
|
|
623
644
|
size: 14,
|
|
624
|
-
className:
|
|
645
|
+
className: q[e.status].cls
|
|
625
646
|
}), /* @__PURE__ */ c("span", {
|
|
626
647
|
className: "tx",
|
|
627
648
|
children: e.text
|
|
@@ -665,7 +686,7 @@ function ne({ m: e, busy: n, onRetry: i, loadAttachment: a, onOpenAttachment: u
|
|
|
665
686
|
]
|
|
666
687
|
});
|
|
667
688
|
}
|
|
668
|
-
function
|
|
689
|
+
function J({ m: e }) {
|
|
669
690
|
let { t: n, i18n: r } = g(o), [i, a] = h(!1), s = e.event;
|
|
670
691
|
return /* @__PURE__ */ l("div", {
|
|
671
692
|
className: "evdiv",
|
|
@@ -681,7 +702,7 @@ function q({ m: e }) {
|
|
|
681
702
|
}),
|
|
682
703
|
s.text,
|
|
683
704
|
" · ",
|
|
684
|
-
|
|
705
|
+
G(e.createdAt, r.language),
|
|
685
706
|
s.details && /* @__PURE__ */ l("button", {
|
|
686
707
|
type: "button",
|
|
687
708
|
className: "textbtn",
|
|
@@ -783,77 +804,77 @@ function ae(e) {
|
|
|
783
804
|
}
|
|
784
805
|
//#endregion
|
|
785
806
|
//#region src/chat/Chat.tsx
|
|
786
|
-
function
|
|
807
|
+
function Y(n) {
|
|
787
808
|
let r = a(), i = e(), [o, u] = h(""), [g, y] = h([]), [b, S] = h(!1), [C, w] = h(null), [T, E] = h(0), [D, O] = h(!1), [k, A] = h(null), [j, ee] = h(!1), [M, N] = h(null), P = m(n.loadAttachment);
|
|
788
809
|
d(() => {
|
|
789
810
|
P.current = n.loadAttachment;
|
|
790
811
|
});
|
|
791
|
-
let F = !!n.loadAttachment, I = p(() => F ? (e) => P.current ? P.current(e) : Promise.reject(/* @__PURE__ */ Error("no loader")) : void 0, [F]), L = m(!1), R = m(null), z = m(null), B = m(null), V = n.voiceMaxSeconds ?? 300, H = ie(V, () => void
|
|
792
|
-
d(() =>
|
|
793
|
-
let
|
|
812
|
+
let F = !!n.loadAttachment, I = p(() => F ? (e) => P.current ? P.current(e) : Promise.reject(/* @__PURE__ */ Error("no loader")) : void 0, [F]), L = m(!1), R = m(null), z = m(null), B = m(null), V = n.voiceMaxSeconds ?? 300, H = ie(V, () => void ve()), { messages: U, busy: W = !1 } = n, G = W || U.some((e) => e.status === "pending" || e.status === "streaming"), K = n.onPendingChange;
|
|
813
|
+
d(() => K?.(g), [g, K]);
|
|
814
|
+
let q = U[0]?.id, J = U[U.length - 1], Y = J?.id, ce = J?.text.length, de = J?.steps?.length, X = m({ height: 0 });
|
|
794
815
|
f(() => {
|
|
795
816
|
let e = R.current;
|
|
796
817
|
if (!e) return;
|
|
797
|
-
let t =
|
|
798
|
-
e.scrollTop = t.first !== void 0 &&
|
|
799
|
-
first:
|
|
800
|
-
last:
|
|
818
|
+
let t = X.current;
|
|
819
|
+
e.scrollTop = t.first !== void 0 && q !== t.first && Y === t.last ? e.scrollTop + (e.scrollHeight - t.height) : e.scrollHeight, X.current = {
|
|
820
|
+
first: q,
|
|
821
|
+
last: Y,
|
|
801
822
|
height: e.scrollHeight
|
|
802
823
|
};
|
|
803
824
|
}, [
|
|
804
825
|
U.length,
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
826
|
+
q,
|
|
827
|
+
Y,
|
|
828
|
+
ce,
|
|
829
|
+
de
|
|
809
830
|
]);
|
|
810
|
-
let
|
|
831
|
+
let Z = n.commands && !C && o.startsWith("/") && !/\s/.test(o) ? o.slice(1) : null, Q = Z === null ? [] : _(n.commands ?? [], Z), $ = Z !== null && !D, fe = () => {
|
|
811
832
|
u(""), y([]), w(null), A(null), L.current = !1;
|
|
812
|
-
},
|
|
833
|
+
}, pe = async (e, t) => {
|
|
813
834
|
if (n.onCommand) try {
|
|
814
|
-
await n.onCommand(e, t),
|
|
835
|
+
await n.onCommand(e, t), fe();
|
|
815
836
|
} catch {}
|
|
816
|
-
},
|
|
837
|
+
}, me = async (e, t = !1) => {
|
|
817
838
|
let r = e.trim();
|
|
818
839
|
if (!(!r && g.length === 0 && !C || W || n.readOnly)) {
|
|
819
840
|
if (!t && !C && n.commands && r.startsWith("/")) {
|
|
820
841
|
let [e, ...t] = r.slice(1).split(/\s+/), i = n.commands.find((t) => t.kind === "command" && t.name === e);
|
|
821
|
-
if (i) return
|
|
842
|
+
if (i) return pe(i.name, t.join(" "));
|
|
822
843
|
if (e && !r.includes("\n")) {
|
|
823
844
|
A("/" + e);
|
|
824
845
|
return;
|
|
825
846
|
}
|
|
826
847
|
}
|
|
827
848
|
try {
|
|
828
|
-
await n.onSend(r, g.map((e) => e.id), L.current, C ?? void 0),
|
|
849
|
+
await n.onSend(r, g.map((e) => e.id), L.current, C ?? void 0), fe();
|
|
829
850
|
} catch {}
|
|
830
851
|
}
|
|
831
|
-
},
|
|
832
|
-
E(0), e.kind === "skill" ? (w(e.name), u("")) : e.takesText ? u("/" + e.name + " ") :
|
|
833
|
-
},
|
|
834
|
-
if (
|
|
852
|
+
}, he = (e) => {
|
|
853
|
+
E(0), e.kind === "skill" ? (w(e.name), u("")) : e.takesText ? u("/" + e.name + " ") : pe(e.name, ""), B.current?.focus();
|
|
854
|
+
}, ge = (e) => {
|
|
855
|
+
if ($ && Q.length > 0) {
|
|
835
856
|
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
836
857
|
e.preventDefault();
|
|
837
858
|
let t = e.key === "ArrowDown" ? 1 : -1;
|
|
838
|
-
E((e) => (e + t +
|
|
859
|
+
E((e) => (e + t + Q.length) % Q.length);
|
|
839
860
|
return;
|
|
840
861
|
}
|
|
841
862
|
if (e.key === "Enter" && !e.shiftKey || e.key === "Tab") {
|
|
842
|
-
e.preventDefault(),
|
|
863
|
+
e.preventDefault(), he(Q[Math.min(T, Q.length - 1)]);
|
|
843
864
|
return;
|
|
844
865
|
}
|
|
845
866
|
}
|
|
846
|
-
|
|
867
|
+
$ && e.key === "Escape" ? (e.preventDefault(), O(!0)) : e.key === "Backspace" && C && o === "" ? w(null) : e.key === "Enter" && !e.shiftKey && !e.nativeEvent.isComposing && !se() && (e.preventDefault(), me(o));
|
|
847
868
|
};
|
|
848
|
-
f(() =>
|
|
869
|
+
f(() => le(R.current, () => ue(B.current)), [o]), d(() => {
|
|
849
870
|
let e = B.current;
|
|
850
871
|
if (!e || typeof ResizeObserver > "u") return;
|
|
851
872
|
let t = e.clientWidth, n = new ResizeObserver(() => {
|
|
852
|
-
e.clientWidth !== t && (t = e.clientWidth,
|
|
873
|
+
e.clientWidth !== t && (t = e.clientWidth, le(R.current, () => ue(e)));
|
|
853
874
|
});
|
|
854
875
|
return n.observe(e), () => n.disconnect();
|
|
855
876
|
}, [H.recording]);
|
|
856
|
-
let
|
|
877
|
+
let _e = async (e) => {
|
|
857
878
|
if (e?.length && n.onUpload) {
|
|
858
879
|
S(!0);
|
|
859
880
|
for (let t of Array.from(e)) {
|
|
@@ -871,7 +892,7 @@ function J(n) {
|
|
|
871
892
|
S(!1), z.current && (z.current.value = "");
|
|
872
893
|
}
|
|
873
894
|
};
|
|
874
|
-
async function
|
|
895
|
+
async function ve() {
|
|
875
896
|
let e = await H.stop();
|
|
876
897
|
e && n.onTranscribe && await re(e, n.onTranscribe, {
|
|
877
898
|
busy: ee,
|
|
@@ -893,9 +914,9 @@ function J(n) {
|
|
|
893
914
|
}
|
|
894
915
|
});
|
|
895
916
|
}
|
|
896
|
-
let
|
|
917
|
+
let ye = (e) => {
|
|
897
918
|
e.key === "Escape" && H.recording && (e.preventDefault(), H.cancel());
|
|
898
|
-
},
|
|
919
|
+
}, be = C ? r("chat.skillPlaceholder") : r("chat.placeholder", { name: n.agentName }), xe = V - H.seconds;
|
|
899
920
|
return /* @__PURE__ */ l("section", {
|
|
900
921
|
className: "nb-chat",
|
|
901
922
|
"aria-label": r("chat.title"),
|
|
@@ -975,10 +996,10 @@ function J(n) {
|
|
|
975
996
|
}) : /* @__PURE__ */ l("div", {
|
|
976
997
|
className: "composer-wrap",
|
|
977
998
|
children: [
|
|
978
|
-
|
|
979
|
-
items:
|
|
980
|
-
active: Math.min(T, Math.max(
|
|
981
|
-
onPick:
|
|
999
|
+
$ && /* @__PURE__ */ c(v, {
|
|
1000
|
+
items: Q,
|
|
1001
|
+
active: Math.min(T, Math.max(Q.length - 1, 0)),
|
|
1002
|
+
onPick: he,
|
|
982
1003
|
onHover: E
|
|
983
1004
|
}),
|
|
984
1005
|
n.aboveComposer,
|
|
@@ -1014,7 +1035,7 @@ function J(n) {
|
|
|
1014
1035
|
children: [r("chat.unknownCommand", { name: k }), /* @__PURE__ */ c("button", {
|
|
1015
1036
|
type: "button",
|
|
1016
1037
|
className: "textbtn",
|
|
1017
|
-
onClick: () => void
|
|
1038
|
+
onClick: () => void me(o, !0),
|
|
1018
1039
|
children: r("chat.sendAsText")
|
|
1019
1040
|
})]
|
|
1020
1041
|
}),
|
|
@@ -1033,10 +1054,10 @@ function J(n) {
|
|
|
1033
1054
|
multiple: !0,
|
|
1034
1055
|
hidden: !0,
|
|
1035
1056
|
accept: n.upload?.accept,
|
|
1036
|
-
onChange: (e) =>
|
|
1057
|
+
onChange: (e) => _e(e.target.files)
|
|
1037
1058
|
})] }),
|
|
1038
1059
|
H.recording ? /* @__PURE__ */ l("div", {
|
|
1039
|
-
className: `recbar${
|
|
1060
|
+
className: `recbar${xe <= 15 ? " ending" : ""}`,
|
|
1040
1061
|
role: "status",
|
|
1041
1062
|
"aria-label": r("chat.voice.recordingNow"),
|
|
1042
1063
|
children: [
|
|
@@ -1066,8 +1087,8 @@ function J(n) {
|
|
|
1066
1087
|
/* @__PURE__ */ c("button", {
|
|
1067
1088
|
type: "button",
|
|
1068
1089
|
className: "btn primary sm",
|
|
1069
|
-
onKeyDown:
|
|
1070
|
-
onClick: () => void
|
|
1090
|
+
onKeyDown: ye,
|
|
1091
|
+
onClick: () => void ve(),
|
|
1071
1092
|
children: r("chat.voice.done")
|
|
1072
1093
|
})
|
|
1073
1094
|
]
|
|
@@ -1100,21 +1121,22 @@ function J(n) {
|
|
|
1100
1121
|
ref: B,
|
|
1101
1122
|
rows: 1,
|
|
1102
1123
|
value: o,
|
|
1103
|
-
placeholder: j ? r("chat.voice.recognizing") :
|
|
1104
|
-
"aria-label":
|
|
1124
|
+
placeholder: j ? r("chat.voice.recognizing") : be,
|
|
1125
|
+
"aria-label": be,
|
|
1105
1126
|
disabled: j,
|
|
1106
|
-
"aria-expanded":
|
|
1127
|
+
"aria-expanded": $,
|
|
1107
1128
|
"aria-autocomplete": n.commands ? "list" : void 0,
|
|
1108
1129
|
onChange: (e) => {
|
|
1109
1130
|
u(e.target.value), O(!1), E(0), A(null);
|
|
1110
1131
|
},
|
|
1111
|
-
onKeyDown:
|
|
1132
|
+
onKeyDown: ge
|
|
1112
1133
|
})]
|
|
1113
1134
|
}),
|
|
1114
1135
|
n.context && !H.recording && /* @__PURE__ */ c(x, {
|
|
1115
1136
|
context: n.context,
|
|
1116
1137
|
onCompact: n.onCompact,
|
|
1117
|
-
onReset: n.onReset
|
|
1138
|
+
onReset: n.onReset,
|
|
1139
|
+
busy: G
|
|
1118
1140
|
}),
|
|
1119
1141
|
n.onTranscribe && !H.recording && /* @__PURE__ */ c(oe, {
|
|
1120
1142
|
supported: H.supported,
|
|
@@ -1130,7 +1152,7 @@ function J(n) {
|
|
|
1130
1152
|
className: "iconbtn fill",
|
|
1131
1153
|
"aria-label": r("chat.send"),
|
|
1132
1154
|
disabled: !o.trim() && g.length === 0 && !C || W || j,
|
|
1133
|
-
onClick: () =>
|
|
1155
|
+
onClick: () => me(o),
|
|
1134
1156
|
children: /* @__PURE__ */ c(t, { name: "send" })
|
|
1135
1157
|
}))
|
|
1136
1158
|
]
|
|
@@ -1176,14 +1198,20 @@ function oe({ supported: e, recognizing: n, onStart: r }) {
|
|
|
1176
1198
|
function se() {
|
|
1177
1199
|
return typeof window < "u" && !!window.matchMedia?.("(hover: none) and (pointer: coarse)").matches;
|
|
1178
1200
|
}
|
|
1179
|
-
|
|
1201
|
+
var ce = (e) => e.scrollHeight - e.scrollTop - e.clientHeight < 2;
|
|
1202
|
+
function le(e, t) {
|
|
1203
|
+
let n = !!e && ce(e);
|
|
1204
|
+
t(), e && n && (e.scrollTop = e.scrollHeight);
|
|
1205
|
+
}
|
|
1206
|
+
function ue(e) {
|
|
1180
1207
|
if (!e) return;
|
|
1181
|
-
|
|
1182
|
-
|
|
1208
|
+
e.style.overflowY = "hidden", e.style.height = "auto";
|
|
1209
|
+
let t = e.scrollHeight + e.offsetHeight - e.clientHeight;
|
|
1210
|
+
e.style.height = `${t}px`, e.style.overflowY = e.offsetHeight < t ? "auto" : "hidden";
|
|
1183
1211
|
}
|
|
1184
1212
|
//#endregion
|
|
1185
1213
|
//#region src/chat/ConversationList.tsx
|
|
1186
|
-
function
|
|
1214
|
+
function de({ conversations: e, currentId: n, open: r, onPick: i, onClose: o, onCreate: u }) {
|
|
1187
1215
|
let f = a(), [p, m] = h(!1);
|
|
1188
1216
|
d(() => {
|
|
1189
1217
|
if (!r) return;
|
|
@@ -1259,19 +1287,19 @@ function le({ conversations: e, currentId: n, open: r, onPick: i, onClose: o, on
|
|
|
1259
1287
|
"aria-label": f("close"),
|
|
1260
1288
|
onClick: o
|
|
1261
1289
|
}),
|
|
1262
|
-
p && u && /* @__PURE__ */ c(
|
|
1290
|
+
p && u && /* @__PURE__ */ c(Z, {
|
|
1263
1291
|
onClose: () => m(!1),
|
|
1264
1292
|
onCreate: u
|
|
1265
1293
|
})
|
|
1266
1294
|
] });
|
|
1267
1295
|
}
|
|
1268
|
-
function
|
|
1296
|
+
function X({ narrow: e, children: t }) {
|
|
1269
1297
|
return /* @__PURE__ */ c("div", {
|
|
1270
1298
|
className: `nb-app${e ? " narrow" : ""}`,
|
|
1271
1299
|
children: t
|
|
1272
1300
|
});
|
|
1273
1301
|
}
|
|
1274
|
-
function
|
|
1302
|
+
function Z({ onClose: e, onCreate: t }) {
|
|
1275
1303
|
let r = a(), [i, o] = h(""), [u, d] = h(!1), [f, p] = h(null), m = async () => {
|
|
1276
1304
|
if (i.trim() && !u) {
|
|
1277
1305
|
d(!0), p(null);
|
|
@@ -1323,7 +1351,7 @@ function Y({ onClose: e, onCreate: t }) {
|
|
|
1323
1351
|
}
|
|
1324
1352
|
//#endregion
|
|
1325
1353
|
//#region src/chat/AgentMenu.tsx
|
|
1326
|
-
function
|
|
1354
|
+
function Q({ icon: e, label: n, title: r, expanded: i, small: a, disabled: o, onClick: s }) {
|
|
1327
1355
|
return /* @__PURE__ */ c("button", {
|
|
1328
1356
|
type: "button",
|
|
1329
1357
|
className: `agentbtn${a ? " s" : ""}`,
|
|
@@ -1339,7 +1367,7 @@ function X({ icon: e, label: n, title: r, expanded: i, small: a, disabled: o, on
|
|
|
1339
1367
|
})
|
|
1340
1368
|
});
|
|
1341
1369
|
}
|
|
1342
|
-
function
|
|
1370
|
+
function $({ label: e, name: n, options: r, value: o, optionsLabel: u, hint: d, narrow: f, models: p, onRename: m, onPick: g, onClose: _ }) {
|
|
1343
1371
|
let v = a(), [y, b] = h(n), x = i(!0, _);
|
|
1344
1372
|
return /* @__PURE__ */ l("div", {
|
|
1345
1373
|
className: `agentmenu${f ? " narrow" : ""}`,
|
|
@@ -1450,6 +1478,6 @@ function Z({ label: e, name: n, options: r, value: o, optionsLabel: u, hint: d,
|
|
|
1450
1478
|
});
|
|
1451
1479
|
}
|
|
1452
1480
|
//#endregion
|
|
1453
|
-
export {
|
|
1481
|
+
export { Q as AgentButton, $ as AgentMenu, V as AttachmentList, te as AttachmentPreview, Y as Chat, X as ChatLayout, v as CommandPalette, x as ContextMeter, de as ConversationList, ne as MessageView, Z as NewTopicModal, oe as VoiceButton, A as fileSize, L as parseTable, O as previewIcon, E as previewKind, b as tokens, ie as useRecorder };
|
|
1454
1482
|
|
|
1455
1483
|
//# sourceMappingURL=chat.js.map
|