@ghuri/ai-widget 0.1.3 → 0.2.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/README.md +37 -2
- package/dist/core/client.d.ts +49 -1
- package/dist/core/index.d.ts +2 -1
- package/dist/core/prepare.d.ts +10 -0
- package/dist/core/types.d.ts +113 -3
- package/dist/{core-B5cGLmtw.js → core-HrvNVLh8.js} +380 -106
- package/dist/core-HrvNVLh8.js.map +1 -0
- package/dist/core.js +1 -1
- package/dist/index.js +3 -3
- package/dist/react.d.ts +1 -0
- package/dist/react.js +5 -1
- package/dist/react.js.map +1 -1
- package/dist/{src-BNRsAIH2.js → src-1wp0ThTf.js} +473 -171
- package/dist/src-1wp0ThTf.js.map +1 -0
- package/dist/ui/element.d.ts +16 -0
- package/dist/ui/labels.d.ts +8 -0
- package/package.json +1 -1
- package/dist/core-B5cGLmtw.js.map +0 -1
- package/dist/src-BNRsAIH2.js.map +0 -1
|
@@ -1,47 +1,48 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { LitElement as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { n as e, t } from "./core-HrvNVLh8.js";
|
|
2
|
+
import { LitElement as n, css as r, html as i, nothing as a, svg as o } from "lit";
|
|
3
|
+
import { styleMap as s } from "lit/directives/style-map.js";
|
|
4
|
+
import { unsafeSVG as c } from "lit/directives/unsafe-svg.js";
|
|
5
|
+
import { Lexer as l } from "marked";
|
|
5
6
|
// src/ui/format.ts
|
|
6
|
-
function
|
|
7
|
+
function u(e) {
|
|
7
8
|
let t = e.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_\-.]+/g, " ").trim().toLowerCase();
|
|
8
9
|
return t ? t[0].toUpperCase() + t.slice(1) : e;
|
|
9
10
|
}
|
|
10
|
-
function
|
|
11
|
-
return e == null ? "—" : typeof e == "string" ? e : typeof e == "number" || typeof e == "boolean" ? String(e) : Array.isArray(e) && e.every((e) => typeof e != "object" || !e) ? e.map(
|
|
11
|
+
function d(e) {
|
|
12
|
+
return e == null ? "—" : typeof e == "string" ? e : typeof e == "number" || typeof e == "boolean" ? String(e) : Array.isArray(e) && e.every((e) => typeof e != "object" || !e) ? e.map(d).join(", ") : JSON.stringify(e);
|
|
12
13
|
}
|
|
13
|
-
function
|
|
14
|
+
function f(e) {
|
|
14
15
|
return Array.isArray(e) && e.length > 0 && e.every((e) => e && typeof e == "object" && !Array.isArray(e));
|
|
15
16
|
}
|
|
16
|
-
function
|
|
17
|
+
function p(e) {
|
|
17
18
|
if (typeof e != "object" || !e || Array.isArray(e)) return e === void 0 ? [] : [{
|
|
18
19
|
label: "Value",
|
|
19
|
-
value:
|
|
20
|
+
value: d(e)
|
|
20
21
|
}];
|
|
21
22
|
let t = [];
|
|
22
|
-
for (let [n, r] of Object.entries(e)) if (
|
|
23
|
+
for (let [n, r] of Object.entries(e)) if (f(r)) r.forEach((e, r) => {
|
|
23
24
|
for (let [i, a] of Object.entries(e)) t.push({
|
|
24
|
-
label: `${
|
|
25
|
-
value:
|
|
25
|
+
label: `${u(n)} ${r + 1} · ${u(i)}`,
|
|
26
|
+
value: d(a)
|
|
26
27
|
});
|
|
27
28
|
});
|
|
28
29
|
else if (r && typeof r == "object" && !Array.isArray(r)) {
|
|
29
30
|
let e = Object.entries(r);
|
|
30
31
|
e.length || t.push({
|
|
31
|
-
label:
|
|
32
|
+
label: u(n),
|
|
32
33
|
value: "{}"
|
|
33
34
|
});
|
|
34
35
|
for (let [r, i] of e) t.push({
|
|
35
|
-
label: `${
|
|
36
|
-
value:
|
|
36
|
+
label: `${u(n)} · ${u(r)}`,
|
|
37
|
+
value: d(i)
|
|
37
38
|
});
|
|
38
39
|
} else t.push({
|
|
39
|
-
label:
|
|
40
|
-
value:
|
|
40
|
+
label: u(n),
|
|
41
|
+
value: d(r)
|
|
41
42
|
});
|
|
42
43
|
return t;
|
|
43
44
|
}
|
|
44
|
-
function
|
|
45
|
+
function m(e) {
|
|
45
46
|
if (!e || typeof e != "object") return null;
|
|
46
47
|
let t = e;
|
|
47
48
|
if (typeof t.count == "number") return t.count;
|
|
@@ -54,8 +55,8 @@ function f(e) {
|
|
|
54
55
|
return null;
|
|
55
56
|
}
|
|
56
57
|
// src/ui/icons.ts
|
|
57
|
-
function
|
|
58
|
-
return
|
|
58
|
+
function h(e = 20) {
|
|
59
|
+
return o`<svg class="kite" width=${e} height=${e} viewBox="0 0 28 28" aria-hidden="true" focusable="false">
|
|
59
60
|
<path transform="translate(15.13 20.17)" fill="var(--ghuri-kite-green, #0e8a5f)" d="M1.24 0.02C1.34 -0.02 1.44 0 1.51 0.06L6.18 3.97C6.26 4.03 6.29 4.13 6.27 4.23C6.26 4.32 6.19 4.4 6.1 4.44L0.36 6.52C0.27 6.55 0.17 6.54 0.1 6.47C0.02 6.41 -0.01 6.31 0 6.22L1.07 0.23C1.1 0.11 1.16 0.05 1.24 0.02Z"/>
|
|
60
61
|
<path transform="translate(3.47 6)" fill="var(--ghuri-kite-maroon, #8e1b2b)" d="M8.22 3.24L6.92 6.03L9.71 7.33L12.47 14.91L0 9.09C1.82 4.24 4.19 1.29 7.04 0L8.22 3.24Z"/>
|
|
61
62
|
<path transform="translate(6.28 1.66)" fill="var(--ghuri-kite-maroon, #8e1b2b)" d="M3.74 2.97C2.36 3.57 1.12 4.49 0 5.69L2.65 0L3.74 2.97Z"/>
|
|
@@ -63,7 +64,7 @@ function p(e = 20) {
|
|
|
63
64
|
<path transform="translate(10.17 1.21)" fill="var(--ghuri-kite-red, #f2492e)" d="M5.69 2.65C4.06 2.45 2.52 2.55 1.08 2.97L0 0L5.69 2.65Z"/>
|
|
64
65
|
</svg>`;
|
|
65
66
|
}
|
|
66
|
-
var
|
|
67
|
+
var g = {
|
|
67
68
|
history: "<path d=\"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8\"/><path d=\"M3 3v5h5\"/><path d=\"M12 7v5l4 2\"/>",
|
|
68
69
|
"square-pen": "<path d=\"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7\"/><path d=\"M18.38 2.62a2.12 2.12 0 1 1 3 3L12.36 14.64a2 2 0 0 1-.85.5l-2.87.84a.5.5 0 0 1-.62-.62l.84-2.87a2 2 0 0 1 .5-.85z\"/>",
|
|
69
70
|
x: "<path d=\"M18 6 6 18\"/><path d=\"m6 6 12 12\"/>",
|
|
@@ -80,14 +81,27 @@ var m = {
|
|
|
80
81
|
"wifi-off": "<path d=\"M12 20h.01\"/><path d=\"M8.5 16.43a5 5 0 0 1 7 0\"/><path d=\"M2 8.82a15 15 0 0 1 4.18-2.65\"/><path d=\"M19 12.86a10 10 0 0 0-2.55-1.86\"/><path d=\"M5 12.86a10 10 0 0 1 5.17-2.69\"/><path d=\"M22 8.82a15 15 0 0 0-11.29-3.76\"/><path d=\"m2 2 20 20\"/>",
|
|
81
82
|
"messages-square": "<path d=\"M14 9a2 2 0 0 1-2 2H6l-4 4V4a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2z\"/><path d=\"M18 9h2a2 2 0 0 1 2 2v11l-4-4h-6a2 2 0 0 1-2-2v-1\"/>",
|
|
82
83
|
"chevron-down": "<path d=\"m6 9 6 6 6-6\"/>",
|
|
83
|
-
ban: "<circle cx=\"12\" cy=\"12\" r=\"10\"/><path d=\"m4.9 4.9 14.2 14.2\"/>"
|
|
84
|
+
ban: "<circle cx=\"12\" cy=\"12\" r=\"10\"/><path d=\"m4.9 4.9 14.2 14.2\"/>",
|
|
85
|
+
"image-plus": "<path d=\"M16 5h6\"/><path d=\"M19 2v6\"/><path d=\"M21 11.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7.5\"/><path d=\"m21 15-3.09-3.09a2 2 0 0 0-2.82 0L6 21\"/><circle cx=\"9\" cy=\"9\" r=\"2\"/>",
|
|
86
|
+
"image-off": "<line x1=\"2\" x2=\"22\" y1=\"2\" y2=\"22\"/><path d=\"M10.41 10.41a2 2 0 1 1-2.83-2.83\"/><line x1=\"13.5\" x2=\"6\" y1=\"13.5\" y2=\"21\"/><line x1=\"18\" x2=\"21\" y1=\"12\" y2=\"15\"/><path d=\"M3.59 3.59A1.99 1.99 0 0 0 3 5v14a2 2 0 0 0 2 2h14c.55 0 1.052-.22 1.41-.59\"/><path d=\"M21 15V5a2 2 0 0 0-2-2H9\"/>"
|
|
84
87
|
};
|
|
85
|
-
function
|
|
86
|
-
return
|
|
87
|
-
stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">${
|
|
88
|
+
function _(e, t = 16) {
|
|
89
|
+
return o`<svg class="icon" width=${t} height=${t} viewBox="0 0 24 24" fill="none" stroke="currentColor"
|
|
90
|
+
stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">${c(g[e] ?? "")}</svg>`;
|
|
88
91
|
}
|
|
89
92
|
// src/ui/labels.ts
|
|
90
|
-
var
|
|
93
|
+
var v = {
|
|
94
|
+
attachPhoto: "Add photos",
|
|
95
|
+
removePhoto: "Remove photo",
|
|
96
|
+
retryPhoto: "Upload again",
|
|
97
|
+
photoProblem: {
|
|
98
|
+
type: "Not a photo",
|
|
99
|
+
size: "Too large",
|
|
100
|
+
count: "Too many",
|
|
101
|
+
upload: "Upload failed"
|
|
102
|
+
},
|
|
103
|
+
photosLimit: (e, t) => `Up to ${e} photos · ${t} MB each. Location data is removed.`,
|
|
104
|
+
dropPhotos: "Drop photos to add them",
|
|
91
105
|
placeholder: "Write in Bangla, Banglish or English…",
|
|
92
106
|
send: "Send",
|
|
93
107
|
stop: "Stop",
|
|
@@ -122,6 +136,7 @@ var g = {
|
|
|
122
136
|
reload: "Reload",
|
|
123
137
|
continue: "Continue",
|
|
124
138
|
continueMessage: "Continue",
|
|
139
|
+
continueSmallerMessage: "Your last reply was too long and got cut off. Continue, doing it in smaller steps.",
|
|
125
140
|
newConversation: "New conversation",
|
|
126
141
|
dismiss: "Dismiss",
|
|
127
142
|
problems: {
|
|
@@ -157,10 +172,26 @@ var g = {
|
|
|
157
172
|
title: "The assistant isn't available",
|
|
158
173
|
text: () => "Check your connection, then try again."
|
|
159
174
|
},
|
|
175
|
+
"answer-cut": {
|
|
176
|
+
title: "The answer was too long",
|
|
177
|
+
text: () => "It stopped before it finished. Continue to get the rest."
|
|
178
|
+
},
|
|
179
|
+
"step-limit": {
|
|
180
|
+
title: "Paused before finishing",
|
|
181
|
+
text: () => "The assistant took as many steps as one reply can and still has work to do. Continue to let it finish."
|
|
182
|
+
},
|
|
183
|
+
"too-long": {
|
|
184
|
+
title: "The reply was too long",
|
|
185
|
+
text: () => "It was cut off before its last step, so that step was not done. Continue to finish it in smaller steps."
|
|
186
|
+
},
|
|
160
187
|
"cut-off": {
|
|
161
188
|
title: "The reply was cut off",
|
|
162
189
|
text: () => "The connection dropped. Reload the conversation to see what finished."
|
|
163
190
|
},
|
|
191
|
+
"photos-refused": {
|
|
192
|
+
title: "Photos can't be sent here",
|
|
193
|
+
text: () => "Nothing was sent. Send your message without photos, or upload them in the dashboard."
|
|
194
|
+
},
|
|
164
195
|
failed: {
|
|
165
196
|
title: "Something went wrong",
|
|
166
197
|
text: () => "Please try again."
|
|
@@ -168,8 +199,19 @@ var g = {
|
|
|
168
199
|
},
|
|
169
200
|
noConversations: "No conversations yet.",
|
|
170
201
|
loading: "Loading…"
|
|
171
|
-
},
|
|
172
|
-
...
|
|
202
|
+
}, y = {
|
|
203
|
+
...v,
|
|
204
|
+
attachPhoto: "ছবি যোগ করুন",
|
|
205
|
+
removePhoto: "ছবি সরান",
|
|
206
|
+
retryPhoto: "আবার আপলোড করুন",
|
|
207
|
+
photoProblem: {
|
|
208
|
+
type: "ছবি নয়",
|
|
209
|
+
size: "খুব বড়",
|
|
210
|
+
count: "অনেক বেশি",
|
|
211
|
+
upload: "আপলোড হয়নি"
|
|
212
|
+
},
|
|
213
|
+
photosLimit: (e, t) => `সর্বোচ্চ ${e}টি ছবি · প্রতিটি ${t} MB। লোকেশনের তথ্য মুছে দেওয়া হয়।`,
|
|
214
|
+
dropPhotos: "ছবি এখানে ছেড়ে দিন",
|
|
173
215
|
placeholder: "বাংলা, Banglish বা English-এ লিখুন…",
|
|
174
216
|
send: "পাঠান",
|
|
175
217
|
stop: "থামান",
|
|
@@ -181,9 +223,9 @@ var g = {
|
|
|
181
223
|
emptyTitle: "কী সাহায্য করতে পারি?",
|
|
182
224
|
confirm: "নিশ্চিত করুন",
|
|
183
225
|
cancel: "বাতিল",
|
|
184
|
-
confirmN: (e) => `${
|
|
226
|
+
confirmN: (e) => `${x(e)}টি নিশ্চিত করুন`,
|
|
185
227
|
cancelAll: "সব বাতিল",
|
|
186
|
-
changes: (e) => `${
|
|
228
|
+
changes: (e) => `${x(e)}টি পরিবর্তন`,
|
|
187
229
|
needsOk: "আপনার অনুমতি দরকার",
|
|
188
230
|
exactValues: "ঠিক যা পাঠানো হবে",
|
|
189
231
|
unticked: "টিক না থাকলে বাতিল",
|
|
@@ -194,9 +236,9 @@ var g = {
|
|
|
194
236
|
outcomeUnknown: "ফলাফল জানা নেই",
|
|
195
237
|
stepFailed: "হয়নি",
|
|
196
238
|
now: "এখন",
|
|
197
|
-
lines: (e) => `${
|
|
239
|
+
lines: (e) => `${x(e)} লাইন`,
|
|
198
240
|
running: "কাজ চলছে…",
|
|
199
|
-
found: (e) => `${
|
|
241
|
+
found: (e) => `${x(e)}টি পাওয়া গেছে`,
|
|
200
242
|
footer: "যেকোনো পরিবর্তনের আগে আপনার অনুমতি নেওয়া হয়। AI ভুল করতে পারে।",
|
|
201
243
|
newMessageCancels: "নতুন মেসেজ পাঠালে অপেক্ষমাণ পরিবর্তন বাতিল হবে।",
|
|
202
244
|
leaveWarning: "উত্তর এখনো লেখা হচ্ছে। তবুও চলে যাবেন?",
|
|
@@ -204,6 +246,7 @@ var g = {
|
|
|
204
246
|
reload: "আবার লোড করুন",
|
|
205
247
|
continue: "চালিয়ে যান",
|
|
206
248
|
continueMessage: "চালিয়ে যাও",
|
|
249
|
+
continueSmallerMessage: "তোমার আগের উত্তর বেশি লম্বা হয়ে মাঝপথে কেটে গেছে। ছোট ছোট ধাপে চালিয়ে যাও।",
|
|
207
250
|
newConversation: "নতুন কথোপকথন",
|
|
208
251
|
dismiss: "ঠিক আছে",
|
|
209
252
|
problems: {
|
|
@@ -225,7 +268,7 @@ var g = {
|
|
|
225
268
|
},
|
|
226
269
|
throttled: {
|
|
227
270
|
title: "অনেক বেশি মেসেজ",
|
|
228
|
-
text: (e) => e ? `আরেকটি পাঠানোর আগে ${
|
|
271
|
+
text: (e) => e ? `আরেকটি পাঠানোর আগে ${x(e)} সেকেন্ড অপেক্ষা করুন।` : "আরেকটি পাঠানোর আগে একটু অপেক্ষা করুন।"
|
|
229
272
|
},
|
|
230
273
|
forbidden: {
|
|
231
274
|
title: "অনুমতি নেই",
|
|
@@ -239,10 +282,26 @@ var g = {
|
|
|
239
282
|
title: "অ্যাসিস্ট্যান্ট এখন পাওয়া যাচ্ছে না",
|
|
240
283
|
text: () => "ইন্টারনেট সংযোগ দেখে আবার চেষ্টা করুন।"
|
|
241
284
|
},
|
|
285
|
+
"answer-cut": {
|
|
286
|
+
title: "উত্তর বেশি লম্বা হয়ে গেছে",
|
|
287
|
+
text: () => "শেষ হওয়ার আগেই থেমে গেছে। বাকিটা পেতে চালিয়ে যান।"
|
|
288
|
+
},
|
|
289
|
+
"step-limit": {
|
|
290
|
+
title: "শেষ হওয়ার আগে থেমেছে",
|
|
291
|
+
text: () => "একটি উত্তরে যত ধাপ নেওয়া যায় তা শেষ, কিন্তু কাজ এখনো বাকি। শেষ করতে চালিয়ে যান।"
|
|
292
|
+
},
|
|
293
|
+
"too-long": {
|
|
294
|
+
title: "উত্তর বেশি লম্বা হয়ে গেছে",
|
|
295
|
+
text: () => "শেষ ধাপের আগেই উত্তর কেটে গেছে, তাই সেই ধাপটি করা হয়নি। ছোট ছোট ধাপে শেষ করতে চালিয়ে যান।"
|
|
296
|
+
},
|
|
242
297
|
"cut-off": {
|
|
243
298
|
title: "উত্তর মাঝপথে থেমে গেছে",
|
|
244
299
|
text: () => "সংযোগ বিচ্ছিন্ন হয়েছিল। কী শেষ হয়েছে দেখতে আবার লোড করুন।"
|
|
245
300
|
},
|
|
301
|
+
"photos-refused": {
|
|
302
|
+
title: "এখানে ছবি পাঠানো যাচ্ছে না",
|
|
303
|
+
text: () => "কিছুই পাঠানো হয়নি। ছবি ছাড়া মেসেজ পাঠান, বা ড্যাশবোর্ডে ছবি আপলোড করুন।"
|
|
304
|
+
},
|
|
246
305
|
failed: {
|
|
247
306
|
title: "কিছু একটা ভুল হয়েছে",
|
|
248
307
|
text: () => "আবার চেষ্টা করুন।"
|
|
@@ -250,12 +309,12 @@ var g = {
|
|
|
250
309
|
},
|
|
251
310
|
noConversations: "এখনো কোনো কথোপকথন নেই।",
|
|
252
311
|
loading: "লোড হচ্ছে…"
|
|
253
|
-
},
|
|
254
|
-
function
|
|
255
|
-
return String(e).replace(/\d/g, (e) =>
|
|
312
|
+
}, b = "০১২৩৪৫৬৭৮৯";
|
|
313
|
+
function x(e) {
|
|
314
|
+
return String(e).replace(/\d/g, (e) => b[Number(e)]);
|
|
256
315
|
}
|
|
257
|
-
function
|
|
258
|
-
let n = (e ?? "").toLowerCase().startsWith("bn") ?
|
|
316
|
+
function S(e, t = {}) {
|
|
317
|
+
let n = (e ?? "").toLowerCase().startsWith("bn") ? y : v;
|
|
259
318
|
return {
|
|
260
319
|
...n,
|
|
261
320
|
...t,
|
|
@@ -266,89 +325,89 @@ function b(e, t = {}) {
|
|
|
266
325
|
};
|
|
267
326
|
}
|
|
268
327
|
// src/ui/markdown.ts
|
|
269
|
-
var
|
|
270
|
-
function
|
|
328
|
+
var C = /^(https?:|mailto:)/i;
|
|
329
|
+
function w(e) {
|
|
271
330
|
let t = e.trim();
|
|
272
|
-
return
|
|
331
|
+
return C.test(t) ? t : null;
|
|
273
332
|
}
|
|
274
|
-
function
|
|
275
|
-
return (e ?? []).map((e) =>
|
|
333
|
+
function T(e) {
|
|
334
|
+
return (e ?? []).map((e) => E(e));
|
|
276
335
|
}
|
|
277
|
-
function
|
|
336
|
+
function E(e) {
|
|
278
337
|
switch (e.type) {
|
|
279
|
-
case "strong": return
|
|
280
|
-
case "em": return
|
|
281
|
-
case "del": return
|
|
282
|
-
case "codespan": return
|
|
283
|
-
case "br": return
|
|
338
|
+
case "strong": return i`<strong>${T(e.tokens)}</strong>`;
|
|
339
|
+
case "em": return i`<em>${T(e.tokens)}</em>`;
|
|
340
|
+
case "del": return i`<del>${T(e.tokens)}</del>`;
|
|
341
|
+
case "codespan": return i`<code>${e.text}</code>`;
|
|
342
|
+
case "br": return i`<br />`;
|
|
284
343
|
case "link": {
|
|
285
|
-
let t = e, n =
|
|
286
|
-
return n ?
|
|
344
|
+
let t = e, n = w(t.href);
|
|
345
|
+
return n ? i`<a href=${n} target="_blank" rel="noopener noreferrer nofollow">${T(t.tokens)}</a>` : i`${T(t.tokens)}`;
|
|
287
346
|
}
|
|
288
347
|
case "image": return e.text || "";
|
|
289
348
|
case "text": {
|
|
290
349
|
let t = e;
|
|
291
|
-
return t.tokens ?
|
|
350
|
+
return t.tokens ? i`${T(t.tokens)}` : D(t.text);
|
|
292
351
|
}
|
|
293
352
|
case "escape": return e.text;
|
|
294
353
|
case "html": return e.raw;
|
|
295
354
|
default: return "raw" in e ? String(e.raw) : "";
|
|
296
355
|
}
|
|
297
356
|
}
|
|
298
|
-
function
|
|
357
|
+
function D(e) {
|
|
299
358
|
return e.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, "\"").replace(/'/g, "'").replace(/&/g, "&");
|
|
300
359
|
}
|
|
301
|
-
function
|
|
360
|
+
function O(e) {
|
|
302
361
|
switch (e.type) {
|
|
303
|
-
case "paragraph": return
|
|
304
|
-
case "heading": return
|
|
362
|
+
case "paragraph": return i`<p>${T(e.tokens)}</p>`;
|
|
363
|
+
case "heading": return i`<p class="heading">${T(e.tokens)}</p>`;
|
|
305
364
|
case "list": {
|
|
306
|
-
let t = e, n = t.items.map((e) =>
|
|
307
|
-
return t.ordered ?
|
|
365
|
+
let t = e, n = t.items.map((e) => i`<li>${e.tokens.map(k)}</li>`);
|
|
366
|
+
return t.ordered ? i`<ol start=${typeof t.start == "number" ? t.start : 1}>${n}</ol>` : i`<ul>${n}</ul>`;
|
|
308
367
|
}
|
|
309
368
|
case "table": {
|
|
310
369
|
let t = e;
|
|
311
|
-
return
|
|
370
|
+
return i`<div class="table-wrap">
|
|
312
371
|
<table>
|
|
313
372
|
<thead>
|
|
314
373
|
<tr>
|
|
315
|
-
${t.header.map((e) =>
|
|
374
|
+
${t.header.map((e) => i`<th>${T(e.tokens)}</th>`)}
|
|
316
375
|
</tr>
|
|
317
376
|
</thead>
|
|
318
377
|
<tbody>
|
|
319
|
-
${t.rows.map((e) =>
|
|
378
|
+
${t.rows.map((e) => i`<tr>${e.map((e) => i`<td>${T(e.tokens)}</td>`)}</tr>`)}
|
|
320
379
|
</tbody>
|
|
321
380
|
</table>
|
|
322
381
|
</div>`;
|
|
323
382
|
}
|
|
324
|
-
case "code": return
|
|
325
|
-
case "blockquote": return
|
|
326
|
-
case "hr": return
|
|
327
|
-
case "html": return
|
|
383
|
+
case "code": return i`<pre><code>${e.text}</code></pre>`;
|
|
384
|
+
case "blockquote": return i`<blockquote>${e.tokens.map(O)}</blockquote>`;
|
|
385
|
+
case "hr": return i`<hr />`;
|
|
386
|
+
case "html": return i`<p>${e.raw}</p>`;
|
|
328
387
|
case "text": {
|
|
329
388
|
let t = e;
|
|
330
|
-
return
|
|
389
|
+
return i`<p>${t.tokens ? T(t.tokens) : D(t.text)}</p>`;
|
|
331
390
|
}
|
|
332
|
-
case "space": return
|
|
333
|
-
default: return "raw" in e ?
|
|
391
|
+
case "space": return a;
|
|
392
|
+
default: return "raw" in e ? i`<p>${String(e.raw)}</p>` : a;
|
|
334
393
|
}
|
|
335
394
|
}
|
|
336
|
-
function
|
|
395
|
+
function k(e) {
|
|
337
396
|
if (e.type === "text") {
|
|
338
397
|
let t = e;
|
|
339
|
-
return t.tokens ?
|
|
398
|
+
return t.tokens ? i`${T(t.tokens)}` : D(t.text);
|
|
340
399
|
}
|
|
341
|
-
return
|
|
400
|
+
return O(e);
|
|
342
401
|
}
|
|
343
|
-
function
|
|
344
|
-
let t =
|
|
402
|
+
function A(e) {
|
|
403
|
+
let t = l.lex(e, {
|
|
345
404
|
gfm: !0,
|
|
346
405
|
breaks: !0
|
|
347
406
|
});
|
|
348
|
-
return
|
|
407
|
+
return i`${t.map(O)}`;
|
|
349
408
|
}
|
|
350
409
|
// src/ui/styles.ts
|
|
351
|
-
var
|
|
410
|
+
var j = r`
|
|
352
411
|
:host {
|
|
353
412
|
--_accent: var(--ghuri-accent, #8e1b2b);
|
|
354
413
|
--_accent-text: var(--ghuri-accent-text, #ffffff);
|
|
@@ -962,6 +1021,149 @@ var k = n`
|
|
|
962
1021
|
background: var(--_accent);
|
|
963
1022
|
color: var(--_accent-text);
|
|
964
1023
|
}
|
|
1024
|
+
.attach {
|
|
1025
|
+
flex: none;
|
|
1026
|
+
display: grid;
|
|
1027
|
+
place-items: center;
|
|
1028
|
+
width: 32px;
|
|
1029
|
+
height: 32px;
|
|
1030
|
+
border-radius: var(--_radius-sm);
|
|
1031
|
+
color: var(--_muted);
|
|
1032
|
+
}
|
|
1033
|
+
.attach:hover:not(:disabled) {
|
|
1034
|
+
background: var(--_muted-surface);
|
|
1035
|
+
color: var(--_text);
|
|
1036
|
+
}
|
|
1037
|
+
.composer[data-dragging] .box {
|
|
1038
|
+
border-color: var(--_accent);
|
|
1039
|
+
border-style: dashed;
|
|
1040
|
+
}
|
|
1041
|
+
.drop-note,
|
|
1042
|
+
.chips-note {
|
|
1043
|
+
margin: 0 0 6px;
|
|
1044
|
+
font-size: 11px;
|
|
1045
|
+
color: var(--_muted);
|
|
1046
|
+
}
|
|
1047
|
+
.chips {
|
|
1048
|
+
display: flex;
|
|
1049
|
+
flex-wrap: wrap;
|
|
1050
|
+
gap: 8px;
|
|
1051
|
+
margin-bottom: 6px;
|
|
1052
|
+
}
|
|
1053
|
+
.chip {
|
|
1054
|
+
position: relative;
|
|
1055
|
+
display: grid;
|
|
1056
|
+
place-items: center;
|
|
1057
|
+
width: 64px;
|
|
1058
|
+
height: 64px;
|
|
1059
|
+
border-radius: var(--_radius-sm);
|
|
1060
|
+
background: var(--_muted-surface);
|
|
1061
|
+
overflow: hidden;
|
|
1062
|
+
}
|
|
1063
|
+
.chip img {
|
|
1064
|
+
width: 100%;
|
|
1065
|
+
height: 100%;
|
|
1066
|
+
object-fit: cover;
|
|
1067
|
+
}
|
|
1068
|
+
.chip[data-status='preparing'] img,
|
|
1069
|
+
.chip[data-status='uploading'] img {
|
|
1070
|
+
opacity: 0.6;
|
|
1071
|
+
}
|
|
1072
|
+
.chip[data-status='failed'] {
|
|
1073
|
+
background: var(--_danger-soft);
|
|
1074
|
+
color: var(--_danger);
|
|
1075
|
+
outline: 1px solid color-mix(in oklab, var(--_danger) 40%, transparent);
|
|
1076
|
+
}
|
|
1077
|
+
.chip[data-status='failed'] img {
|
|
1078
|
+
opacity: 0.35;
|
|
1079
|
+
}
|
|
1080
|
+
.chip-icon {
|
|
1081
|
+
display: grid;
|
|
1082
|
+
place-items: center;
|
|
1083
|
+
}
|
|
1084
|
+
.chip-progress {
|
|
1085
|
+
position: absolute;
|
|
1086
|
+
left: 6px;
|
|
1087
|
+
right: 6px;
|
|
1088
|
+
bottom: 6px;
|
|
1089
|
+
height: 4px;
|
|
1090
|
+
border-radius: 2px;
|
|
1091
|
+
background: rgb(255 255 255 / 0.7);
|
|
1092
|
+
}
|
|
1093
|
+
.chip-progress span {
|
|
1094
|
+
display: block;
|
|
1095
|
+
height: 100%;
|
|
1096
|
+
border-radius: 2px;
|
|
1097
|
+
background: var(--_text);
|
|
1098
|
+
transition: width 0.2s;
|
|
1099
|
+
}
|
|
1100
|
+
.chip-error {
|
|
1101
|
+
position: absolute;
|
|
1102
|
+
left: 0;
|
|
1103
|
+
right: 0;
|
|
1104
|
+
bottom: 4px;
|
|
1105
|
+
font-size: 10px;
|
|
1106
|
+
text-align: center;
|
|
1107
|
+
}
|
|
1108
|
+
.chip-remove,
|
|
1109
|
+
.chip-retry {
|
|
1110
|
+
position: absolute;
|
|
1111
|
+
top: 4px;
|
|
1112
|
+
display: grid;
|
|
1113
|
+
place-items: center;
|
|
1114
|
+
width: 18px;
|
|
1115
|
+
height: 18px;
|
|
1116
|
+
border-radius: 999px;
|
|
1117
|
+
background: rgb(24 24 27 / 0.8);
|
|
1118
|
+
color: #fff;
|
|
1119
|
+
}
|
|
1120
|
+
.chip-remove {
|
|
1121
|
+
right: 4px;
|
|
1122
|
+
}
|
|
1123
|
+
.chip-retry {
|
|
1124
|
+
left: 4px;
|
|
1125
|
+
}
|
|
1126
|
+
.photos {
|
|
1127
|
+
align-self: flex-end;
|
|
1128
|
+
display: flex;
|
|
1129
|
+
flex-wrap: wrap;
|
|
1130
|
+
justify-content: flex-end;
|
|
1131
|
+
gap: 6px;
|
|
1132
|
+
max-width: 85%;
|
|
1133
|
+
margin-bottom: -10px;
|
|
1134
|
+
}
|
|
1135
|
+
.photo {
|
|
1136
|
+
display: block;
|
|
1137
|
+
width: 96px;
|
|
1138
|
+
height: 120px;
|
|
1139
|
+
border-radius: var(--_radius);
|
|
1140
|
+
overflow: hidden;
|
|
1141
|
+
background: var(--_muted-surface);
|
|
1142
|
+
}
|
|
1143
|
+
.photo img {
|
|
1144
|
+
width: 100%;
|
|
1145
|
+
height: 100%;
|
|
1146
|
+
object-fit: cover;
|
|
1147
|
+
}
|
|
1148
|
+
.photo .photo-name {
|
|
1149
|
+
display: none;
|
|
1150
|
+
}
|
|
1151
|
+
.photo[data-broken] img {
|
|
1152
|
+
display: none;
|
|
1153
|
+
}
|
|
1154
|
+
.photo[data-broken] .photo-name {
|
|
1155
|
+
display: flex;
|
|
1156
|
+
flex-direction: column;
|
|
1157
|
+
align-items: center;
|
|
1158
|
+
justify-content: center;
|
|
1159
|
+
gap: 4px;
|
|
1160
|
+
height: 100%;
|
|
1161
|
+
padding: 6px;
|
|
1162
|
+
font-size: 11px;
|
|
1163
|
+
color: var(--_muted);
|
|
1164
|
+
text-align: center;
|
|
1165
|
+
overflow-wrap: anywhere;
|
|
1166
|
+
}
|
|
965
1167
|
.stop {
|
|
966
1168
|
flex: none;
|
|
967
1169
|
display: inline-flex;
|
|
@@ -1103,8 +1305,8 @@ var k = n`
|
|
|
1103
1305
|
font-weight: 500;
|
|
1104
1306
|
min-height: 48px;
|
|
1105
1307
|
}
|
|
1106
|
-
`,
|
|
1107
|
-
static styles =
|
|
1308
|
+
`, M = "result was not recorded", N = class extends n {
|
|
1309
|
+
static styles = j;
|
|
1108
1310
|
static properties = {
|
|
1109
1311
|
layout: {
|
|
1110
1312
|
type: String,
|
|
@@ -1122,7 +1324,8 @@ var k = n`
|
|
|
1122
1324
|
conversations: { state: !0 },
|
|
1123
1325
|
draft: { state: !0 },
|
|
1124
1326
|
expanded: { state: !0 },
|
|
1125
|
-
unticked: { state: !0 }
|
|
1327
|
+
unticked: { state: !0 },
|
|
1328
|
+
dragging: { state: !0 }
|
|
1126
1329
|
};
|
|
1127
1330
|
chat = null;
|
|
1128
1331
|
options = null;
|
|
@@ -1145,8 +1348,9 @@ var k = n`
|
|
|
1145
1348
|
}), ...[
|
|
1146
1349
|
"tool-result",
|
|
1147
1350
|
"approval-pending",
|
|
1148
|
-
"turn-end"
|
|
1149
|
-
|
|
1351
|
+
"turn-end",
|
|
1352
|
+
"attachment-error"
|
|
1353
|
+
].map((e) => n.on(e, (t) => this.fire(e, t)))], this.layout === "page" && this.loadConversations(), (this.open || this.layout === "page") && n.loadCapabilities();
|
|
1150
1354
|
}
|
|
1151
1355
|
setOptions(e) {
|
|
1152
1356
|
if (this.options) {
|
|
@@ -1162,7 +1366,7 @@ var k = n`
|
|
|
1162
1366
|
return this.chat;
|
|
1163
1367
|
}
|
|
1164
1368
|
show() {
|
|
1165
|
-
this.open || (this.open = !0, this.fire("open", {}), this.updateComplete.then(() => this.focusInput()));
|
|
1369
|
+
this.open || (this.open = !0, this.chat?.loadCapabilities(), this.fire("open", {}), this.updateComplete.then(() => this.focusInput()));
|
|
1166
1370
|
}
|
|
1167
1371
|
hide() {
|
|
1168
1372
|
this.open && (this.open = !1, this.fire("close", {}));
|
|
@@ -1192,7 +1396,7 @@ var k = n`
|
|
|
1192
1396
|
this.unsubscribe = [];
|
|
1193
1397
|
}
|
|
1194
1398
|
get labels() {
|
|
1195
|
-
return
|
|
1399
|
+
return S(this.locale || this.options?.locale || document.documentElement.lang || "en", this.options?.labels);
|
|
1196
1400
|
}
|
|
1197
1401
|
fire(e, t) {
|
|
1198
1402
|
this.dispatchEvent(new CustomEvent(`ghuri:${e}`, {
|
|
@@ -1229,10 +1433,14 @@ var k = n`
|
|
|
1229
1433
|
}
|
|
1230
1434
|
async submit() {
|
|
1231
1435
|
let e = this.draft.trim(), t = this.state?.status;
|
|
1232
|
-
if (!
|
|
1436
|
+
if (!this.canSend() || !this.chat || t === "sending" || t === "streaming") return;
|
|
1233
1437
|
this.draft = "", this.stickToBottom = !0;
|
|
1234
1438
|
let n = !this.state?.conversationId;
|
|
1235
|
-
await this.chat.send(e), n && this.layout === "page" && this.loadConversations();
|
|
1439
|
+
await this.chat.send(e), this.chat?.getState().problem?.code === "photos-refused" && !this.draft && (this.draft = e), n && this.layout === "page" && this.loadConversations();
|
|
1440
|
+
}
|
|
1441
|
+
canSend() {
|
|
1442
|
+
let e = this.state?.uploads ?? [];
|
|
1443
|
+
return e.some((e) => e.status === "preparing" || e.status === "uploading") || e.some((e) => e.status === "failed" && e.error === "upload") ? !1 : !!this.draft.trim() || e.some((e) => e.status === "ready");
|
|
1236
1444
|
}
|
|
1237
1445
|
onKeydown(e) {
|
|
1238
1446
|
e.key !== "Enter" || e.shiftKey || e.isComposing || e.keyCode === 229 || (e.preventDefault(), this.submit());
|
|
@@ -1261,16 +1469,16 @@ var k = n`
|
|
|
1261
1469
|
}
|
|
1262
1470
|
wanted = /* @__PURE__ */ new Map();
|
|
1263
1471
|
cardSlot(e, t, n) {
|
|
1264
|
-
let
|
|
1265
|
-
if (!
|
|
1472
|
+
let r = this.cards.get(e);
|
|
1473
|
+
if (!r) {
|
|
1266
1474
|
let t = document.createElement("div");
|
|
1267
|
-
t.slot = `ghuri-card-${++this.cardSeq}`, t.dataset.ghuriCard = e, this.appendChild(t),
|
|
1475
|
+
t.slot = `ghuri-card-${++this.cardSeq}`, t.dataset.ghuriCard = e, this.appendChild(t), r = { container: t }, this.cards.set(e, r);
|
|
1268
1476
|
}
|
|
1269
1477
|
return this.wanted.set(e, {
|
|
1270
|
-
slot:
|
|
1478
|
+
slot: r.container.slot,
|
|
1271
1479
|
ctx: t,
|
|
1272
1480
|
render: n
|
|
1273
|
-
}),
|
|
1481
|
+
}), i`<slot name=${r.container.slot}></slot>`;
|
|
1274
1482
|
}
|
|
1275
1483
|
mountCards() {
|
|
1276
1484
|
for (let [e, t] of this.cards) {
|
|
@@ -1287,7 +1495,7 @@ var k = n`
|
|
|
1287
1495
|
}
|
|
1288
1496
|
}
|
|
1289
1497
|
render() {
|
|
1290
|
-
return this.wanted = /* @__PURE__ */ new Map(), this.layout === "page" ?
|
|
1498
|
+
return this.wanted = /* @__PURE__ */ new Map(), this.layout === "page" ? i`<div class="page">
|
|
1291
1499
|
<aside class="sidebar" part="history">${this.renderSidebar()}</aside>
|
|
1292
1500
|
<section class="main">
|
|
1293
1501
|
<div class="page-head" part="header">
|
|
@@ -1296,8 +1504,8 @@ var k = n`
|
|
|
1296
1504
|
</div>
|
|
1297
1505
|
${this.renderScroll()} ${this.renderBottom()}
|
|
1298
1506
|
</section>
|
|
1299
|
-
</div>` :
|
|
1300
|
-
${this.view === "history" ? this.renderPanelHistory() :
|
|
1507
|
+
</div>` : i`${this.renderHeader()}
|
|
1508
|
+
${this.view === "history" ? this.renderPanelHistory() : i`${this.renderScroll()} ${this.renderBottom()}`}`;
|
|
1301
1509
|
}
|
|
1302
1510
|
currentTitle() {
|
|
1303
1511
|
let e = this.state?.conversationId;
|
|
@@ -1305,37 +1513,37 @@ var k = n`
|
|
|
1305
1513
|
}
|
|
1306
1514
|
renderHeader() {
|
|
1307
1515
|
let e = this.labels;
|
|
1308
|
-
return
|
|
1516
|
+
return i`<header class="header" part="header">
|
|
1309
1517
|
<div class="brand">
|
|
1310
|
-
<span class="avatar">${
|
|
1518
|
+
<span class="avatar">${h(20)}</span>
|
|
1311
1519
|
<span class="names">
|
|
1312
1520
|
<span class="title" part="title">${this.heading || "Ghuri AI"}</span>
|
|
1313
|
-
${this.subtitle ?
|
|
1521
|
+
${this.subtitle ? i`<span class="subtitle">${this.subtitle}</span>` : a}
|
|
1314
1522
|
</span>
|
|
1315
1523
|
</div>
|
|
1316
1524
|
<div class="tools">
|
|
1317
1525
|
<button class="icon-button" title=${e.history} aria-label=${e.history} @click=${() => this.showHistory()}>
|
|
1318
|
-
${
|
|
1526
|
+
${_("history")}
|
|
1319
1527
|
</button>
|
|
1320
1528
|
<button class="icon-button" title=${e.newChat} aria-label=${e.newChat} @click=${() => this.newConversation()}>
|
|
1321
|
-
${
|
|
1529
|
+
${_("square-pen")}
|
|
1322
1530
|
</button>
|
|
1323
1531
|
<button class="icon-button" title=${e.close} aria-label=${e.close} @click=${() => this.hide()}>
|
|
1324
|
-
${
|
|
1532
|
+
${_("x")}
|
|
1325
1533
|
</button>
|
|
1326
1534
|
</div>
|
|
1327
1535
|
</header>`;
|
|
1328
1536
|
}
|
|
1329
1537
|
renderConversationList() {
|
|
1330
1538
|
let e = this.labels;
|
|
1331
|
-
if (this.conversations === null) return
|
|
1332
|
-
if (!this.conversations.length) return
|
|
1539
|
+
if (this.conversations === null) return i`<div class="muted">${e.loading}</div>`;
|
|
1540
|
+
if (!this.conversations.length) return i`<div class="muted">${e.noConversations}</div>`;
|
|
1333
1541
|
let t = new Intl.DateTimeFormat(this.locale || void 0, {
|
|
1334
1542
|
dateStyle: "medium",
|
|
1335
1543
|
timeStyle: "short"
|
|
1336
1544
|
});
|
|
1337
|
-
return
|
|
1338
|
-
${this.conversations.map((e) =>
|
|
1545
|
+
return i`<nav class="history" aria-label=${e.conversations}>
|
|
1546
|
+
${this.conversations.map((e) => i`<button
|
|
1339
1547
|
class="conversation"
|
|
1340
1548
|
aria-current=${e.id === this.state?.conversationId ? "true" : "false"}
|
|
1341
1549
|
@click=${() => this.openConversation(e.id)}
|
|
@@ -1347,7 +1555,7 @@ var k = n`
|
|
|
1347
1555
|
}
|
|
1348
1556
|
renderPanelHistory() {
|
|
1349
1557
|
let e = this.labels;
|
|
1350
|
-
return
|
|
1558
|
+
return i`<div class="scroll">
|
|
1351
1559
|
<div class="history-head">
|
|
1352
1560
|
<span>${e.conversations}</span>
|
|
1353
1561
|
<button class="btn primary" @click=${() => this.newConversation()}>${e.newChat}</button>
|
|
@@ -1357,53 +1565,104 @@ var k = n`
|
|
|
1357
1565
|
}
|
|
1358
1566
|
renderSidebar() {
|
|
1359
1567
|
let e = this.labels;
|
|
1360
|
-
return
|
|
1361
|
-
<button class="new-chat" @click=${() => this.newConversation()}>${
|
|
1568
|
+
return i`<div class="side-brand">${h(24)}<span>${this.heading || "Ghuri AI"}</span></div>
|
|
1569
|
+
<button class="new-chat" @click=${() => this.newConversation()}>${_("square-pen", 15)} ${e.newChat}</button>
|
|
1362
1570
|
${this.renderConversationList()}`;
|
|
1363
1571
|
}
|
|
1364
1572
|
renderScroll() {
|
|
1365
|
-
let e = this.state, t = e?.messages ?? [], n = e?.status === "loading" ?
|
|
1573
|
+
let e = this.state, t = e?.messages ?? [], n = e?.status === "loading" ? i`<div class="muted">${this.labels.loading}</div>` : t.length ? i`${t.map((e, n) => this.renderMessage(e, n === t.length - 1))}
|
|
1366
1574
|
${this.renderPending()}` : this.renderEmpty();
|
|
1367
|
-
return
|
|
1575
|
+
return i`<div class="scroll">
|
|
1368
1576
|
<div class="messages column" role="log" aria-live="polite" aria-busy=${e?.status === "streaming"}>${n}</div>
|
|
1369
1577
|
</div>`;
|
|
1370
1578
|
}
|
|
1371
1579
|
renderEmpty() {
|
|
1372
1580
|
let e = this.labels, t = this.options?.starters ?? [];
|
|
1373
|
-
return
|
|
1374
|
-
<span class="avatar">${
|
|
1581
|
+
return i`<div class="empty" part="empty">
|
|
1582
|
+
<span class="avatar">${h(24)}</span>
|
|
1375
1583
|
<span class="heading">${e.emptyTitle}</span>
|
|
1376
|
-
${t.length ?
|
|
1377
|
-
${t.map((e) =>
|
|
1378
|
-
</div>` :
|
|
1584
|
+
${t.length ? i`<div class="starters">
|
|
1585
|
+
${t.map((e) => i`<button class="starter" part="starter" @click=${() => this.chat?.send(e)}>${e}</button>`)}
|
|
1586
|
+
</div>` : a}
|
|
1379
1587
|
</div>`;
|
|
1380
1588
|
}
|
|
1381
1589
|
renderMessage(e, t) {
|
|
1382
1590
|
if (e.role === "user") {
|
|
1383
|
-
let t = e.parts.map((e) => e.kind === "text" ? e.text : "").join("");
|
|
1384
|
-
return
|
|
1591
|
+
let t = e.parts.map((e) => e.kind === "text" ? e.text : "").join(""), n = e.parts.flatMap((e) => e.kind === "attachments" ? e.attachments : []);
|
|
1592
|
+
return i`${n.length ? i`<div class="photos" part="message-photos">${n.map((e) => this.renderPhoto(e))}</div>` : a}${t ? i`<div class="user" part="user-bubble">${t}</div>` : a}`;
|
|
1385
1593
|
}
|
|
1386
|
-
let n = t && this.state?.status === "streaming",
|
|
1594
|
+
let n = t && this.state?.status === "streaming", r = e.parts.map((t, r) => {
|
|
1387
1595
|
if (t.kind === "text") {
|
|
1388
|
-
if (!t.text) return
|
|
1389
|
-
let o = n &&
|
|
1390
|
-
return
|
|
1596
|
+
if (!t.text) return a;
|
|
1597
|
+
let o = n && r === e.parts.length - 1;
|
|
1598
|
+
return i`<div class="md" part="assistant">${A(t.text)}${o ? i`<span class="caret"></span>` : a}</div>`;
|
|
1391
1599
|
}
|
|
1392
|
-
return this.renderTool(t);
|
|
1393
|
-
}), o = n && !e.parts.length, s =
|
|
1394
|
-
${
|
|
1395
|
-
${o ?
|
|
1600
|
+
return t.kind === "tool" ? this.renderTool(t) : a;
|
|
1601
|
+
}), o = n && !e.parts.length, s = i`<div class="assistant">
|
|
1602
|
+
${r}
|
|
1603
|
+
${o ? i`<span class="step" part="tool-step">${_("loader", 13)}<span>${this.labels.running}</span></span>` : a}
|
|
1604
|
+
</div>`;
|
|
1605
|
+
return this.layout === "page" ? i`<div class="assistant-row"><span class="avatar">${h(18)}</span>${s}</div>` : s;
|
|
1606
|
+
}
|
|
1607
|
+
renderPhoto(e) {
|
|
1608
|
+
let t = P(e.thumbnailUrl), n = (e.previewUrl?.startsWith("blob:") ? e.previewUrl : void 0) ?? t, r = i`<span class="photo-name">${_("image-off", 14)}<span>${e.name}</span></span>`, o = n ? i`<img
|
|
1609
|
+
src=${n}
|
|
1610
|
+
alt=${e.name}
|
|
1611
|
+
loading="lazy"
|
|
1612
|
+
@error=${(e) => e.target.closest(".photo")?.setAttribute("data-broken", "")}
|
|
1613
|
+
/>${r}` : r;
|
|
1614
|
+
return t ? i`<a class="photo" href=${t} target="_blank" rel="noopener noreferrer" title=${e.name}>${o}</a>` : i`<span class="photo" data-broken=${n ? a : ""} title=${e.name}>${o}</span>`;
|
|
1615
|
+
}
|
|
1616
|
+
renderChip(e) {
|
|
1617
|
+
let t = this.labels, n = e.status === "preparing" || e.status === "uploading", r = e.status === "failed";
|
|
1618
|
+
return i`<div class="chip" part="attachment-chip" data-status=${e.status} title=${e.name}>
|
|
1619
|
+
${e.previewUrl && e.error !== "type" ? i`<img src=${e.previewUrl} alt=${e.name} />` : i`<span class="chip-icon">${_("image-off", 18)}</span>`}
|
|
1620
|
+
${n ? i`<span
|
|
1621
|
+
class="chip-progress"
|
|
1622
|
+
role="progressbar"
|
|
1623
|
+
aria-label=${e.name}
|
|
1624
|
+
aria-valuemin="0"
|
|
1625
|
+
aria-valuemax="100"
|
|
1626
|
+
aria-valuenow=${Math.round(e.progress * 100)}
|
|
1627
|
+
><span style=${s({ width: `${Math.max(8, Math.round(e.progress * 100))}%` })}></span
|
|
1628
|
+
></span>` : a}
|
|
1629
|
+
${r && e.error ? i`<span class="chip-error">${t.photoProblem[e.error]}</span>` : a}
|
|
1630
|
+
${r && e.error === "upload" ? i`<button class="chip-retry" aria-label=${t.retryPhoto} title=${t.retryPhoto} @click=${() => this.chat?.retryUpload(e.id)}>
|
|
1631
|
+
${_("refresh-cw", 12)}
|
|
1632
|
+
</button>` : a}
|
|
1633
|
+
<button class="chip-remove" aria-label=${t.removePhoto} title=${t.removePhoto} @click=${() => this.chat?.removeUpload(e.id)}>
|
|
1634
|
+
${_("x", 11)}
|
|
1635
|
+
</button>
|
|
1396
1636
|
</div>`;
|
|
1397
|
-
|
|
1637
|
+
}
|
|
1638
|
+
pickPhotos() {
|
|
1639
|
+
this.renderRoot.querySelector("input[type=file]")?.click();
|
|
1640
|
+
}
|
|
1641
|
+
onPicked(e) {
|
|
1642
|
+
let t = e.target;
|
|
1643
|
+
t.files?.length && this.chat?.addFiles(t.files), t.value = "";
|
|
1644
|
+
}
|
|
1645
|
+
onPaste(e) {
|
|
1646
|
+
if (!this.state?.canAttach) return;
|
|
1647
|
+
let t = Array.from(e.clipboardData?.files ?? []);
|
|
1648
|
+
t.length && (e.preventDefault(), this.chat?.addFiles(t));
|
|
1649
|
+
}
|
|
1650
|
+
onDrag(e, t) {
|
|
1651
|
+
this.state?.canAttach && e.dataTransfer?.types?.includes("Files") && (e.preventDefault(), this.dragging = t);
|
|
1652
|
+
}
|
|
1653
|
+
onDrop(e) {
|
|
1654
|
+
if (this.dragging = !1, !this.state?.canAttach) return;
|
|
1655
|
+
let t = Array.from(e.dataTransfer?.files ?? []);
|
|
1656
|
+
t.length && (e.preventDefault(), this.chat?.addFiles(t));
|
|
1398
1657
|
}
|
|
1399
1658
|
toolLabel(e) {
|
|
1400
|
-
return e.title ||
|
|
1659
|
+
return e.title || u(e.toolName);
|
|
1401
1660
|
}
|
|
1402
1661
|
renderTool(e) {
|
|
1403
1662
|
let t = this.labels;
|
|
1404
|
-
if (e.state === "awaiting-approval") return
|
|
1663
|
+
if (e.state === "awaiting-approval") return a;
|
|
1405
1664
|
if (e.approvalId) {
|
|
1406
|
-
let [n,
|
|
1665
|
+
let [n, r, a] = e.state === "done" ? [
|
|
1407
1666
|
"done",
|
|
1408
1667
|
"circle-check",
|
|
1409
1668
|
t.confirmed
|
|
@@ -1414,15 +1673,15 @@ var k = n`
|
|
|
1414
1673
|
] : e.state === "error" ? [
|
|
1415
1674
|
"error",
|
|
1416
1675
|
"circle-alert",
|
|
1417
|
-
e.errorText?.includes(
|
|
1676
|
+
e.errorText?.includes(M) ? t.outcomeUnknown : t.stepFailed
|
|
1418
1677
|
] : [
|
|
1419
1678
|
"denied",
|
|
1420
1679
|
"loader",
|
|
1421
1680
|
t.running
|
|
1422
1681
|
];
|
|
1423
|
-
return
|
|
1682
|
+
return i`<div class="decided" part="decided" title=${e.state === "error" ? e.errorText ?? "" : ""}>
|
|
1424
1683
|
<span class="what"
|
|
1425
|
-
><span class=${n}>${
|
|
1684
|
+
><span class=${n}>${_(r, 15)}</span>${this.toolLabel(e)}${e.preview ? ` · ${e.preview.summary}` : ""}</span
|
|
1426
1685
|
>
|
|
1427
1686
|
<span class=${n}>${a}</span>
|
|
1428
1687
|
</div>`;
|
|
@@ -1432,42 +1691,42 @@ var k = n`
|
|
|
1432
1691
|
part: e,
|
|
1433
1692
|
client: this.chat
|
|
1434
1693
|
}, n);
|
|
1435
|
-
if (this.options?.toolSteps === "hide") return
|
|
1436
|
-
let
|
|
1437
|
-
return
|
|
1438
|
-
${o}<span>${this.toolLabel(e)}${
|
|
1694
|
+
if (this.options?.toolSteps === "hide") return a;
|
|
1695
|
+
let r = e.state === "done" ? m(e.output) : null, o = e.state === "done" ? i`<span class="ok">${_("check", 13)}</span>` : e.state === "error" ? i`<span class="bad">${_("circle-alert", 13)}</span>` : e.state === "denied" ? _("ban", 13) : i`<span class="spin">${_("loader", 13)}</span>`;
|
|
1696
|
+
return i`<span class="step" part="tool-step" title=${e.state === "error" ? e.errorText ?? "" : ""}>
|
|
1697
|
+
${o}<span>${this.toolLabel(e)}${r === null ? "" : ` · ${t.found(r)}`}</span>
|
|
1439
1698
|
</span>`;
|
|
1440
1699
|
}
|
|
1441
1700
|
renderPreview(e) {
|
|
1442
|
-
if (!e) return
|
|
1701
|
+
if (!e) return a;
|
|
1443
1702
|
let t = this.labels;
|
|
1444
|
-
return
|
|
1703
|
+
return i`<div class="preview" part="preview">
|
|
1445
1704
|
<div class="preview-summary">${e.summary}</div>
|
|
1446
|
-
${e.changes.length ?
|
|
1447
|
-
${e.changes.map((e) =>
|
|
1705
|
+
${e.changes.length ? i`<ul class="preview-changes">
|
|
1706
|
+
${e.changes.map((e) => i`<li>
|
|
1448
1707
|
<span class="preview-label">${e.label}:</span>
|
|
1449
|
-
${e.current === void 0 ?
|
|
1708
|
+
${e.current === void 0 ? a : i`<span class="preview-now">${t.now} ${e.current}</span> → `}
|
|
1450
1709
|
<span class="preview-next">${e.next}</span>
|
|
1451
1710
|
</li>`)}
|
|
1452
|
-
</ul>` :
|
|
1711
|
+
</ul>` : a}
|
|
1453
1712
|
</div>`;
|
|
1454
1713
|
}
|
|
1455
1714
|
renderRows(e, t) {
|
|
1456
|
-
let n = this.labels,
|
|
1457
|
-
return
|
|
1458
|
-
${
|
|
1715
|
+
let n = this.labels, r = p(t), o = this.expanded.has(e), s = (e) => e.split("\n").length, c = (e) => s(e) > 1 ? `${e.split("\n")[0].slice(0, 160)}… (${n.lines(s(e))})` : e.length > 160 ? `${e.slice(0, 160)}…` : e, l = r.some((e) => e.value.length > 160 || s(e.value) > 1);
|
|
1716
|
+
return i`<div class="rows">
|
|
1717
|
+
${r.map((e) => i`<div class="row">
|
|
1459
1718
|
<span class="label">${e.label}</span>
|
|
1460
1719
|
<span class="value">${o ? e.value : c(e.value)}</span>
|
|
1461
1720
|
</div>`)}
|
|
1462
|
-
${l ?
|
|
1721
|
+
${l ? i`<button class="link" @click=${() => this.toggleRows(e)}>${o ? n.showLess : n.showMore}</button>` : a}
|
|
1463
1722
|
</div>`;
|
|
1464
1723
|
}
|
|
1465
1724
|
renderPending() {
|
|
1466
1725
|
let e = this.state?.pendingApprovals ?? [];
|
|
1467
|
-
if (!e.length || this.state?.status !== "awaiting-approval") return
|
|
1726
|
+
if (!e.length || this.state?.status !== "awaiting-approval") return a;
|
|
1468
1727
|
let t = this.labels;
|
|
1469
1728
|
if (e.length === 1) {
|
|
1470
|
-
let n = e[0],
|
|
1729
|
+
let n = e[0], r = this.options?.cards?.[n.toolName]?.confirm, o = {
|
|
1471
1730
|
kind: "tool",
|
|
1472
1731
|
toolCallId: n.toolCallId,
|
|
1473
1732
|
toolName: n.toolName,
|
|
@@ -1476,7 +1735,7 @@ var k = n`
|
|
|
1476
1735
|
state: "awaiting-approval",
|
|
1477
1736
|
approvalId: n.approvalId
|
|
1478
1737
|
};
|
|
1479
|
-
if (
|
|
1738
|
+
if (r && this.chat) {
|
|
1480
1739
|
let e = this.chat;
|
|
1481
1740
|
return this.cardSlot(`confirm:${n.approvalId}`, {
|
|
1482
1741
|
part: o,
|
|
@@ -1487,15 +1746,15 @@ var k = n`
|
|
|
1487
1746
|
approved: t,
|
|
1488
1747
|
...r ? { reason: r } : {}
|
|
1489
1748
|
}])
|
|
1490
|
-
},
|
|
1749
|
+
}, r);
|
|
1491
1750
|
}
|
|
1492
|
-
return
|
|
1751
|
+
return i`<div class="confirm" part="confirm-card" role="group" aria-label=${this.toolLabel(n)}>
|
|
1493
1752
|
<div class="confirm-head" part="confirm-header">
|
|
1494
|
-
<span class="what">${
|
|
1753
|
+
<span class="what">${_("pencil-line", 15)} ${this.toolLabel(n)}</span>
|
|
1495
1754
|
<span class="badge">${t.needsOk}</span>
|
|
1496
1755
|
</div>
|
|
1497
1756
|
${this.renderPreview(n.preview)}
|
|
1498
|
-
${n.preview ?
|
|
1757
|
+
${n.preview ? i`<div class="exact-head">${t.exactValues}</div>` : a}
|
|
1499
1758
|
${this.renderRows(n.approvalId, n.input)}
|
|
1500
1759
|
<div class="confirm-foot">
|
|
1501
1760
|
<span class="hint">${n.preview ? "" : t.exactValues}</span>
|
|
@@ -1507,12 +1766,12 @@ var k = n`
|
|
|
1507
1766
|
</div>`;
|
|
1508
1767
|
}
|
|
1509
1768
|
let n = e.filter((e) => !this.unticked.has(e.approvalId)).length;
|
|
1510
|
-
return
|
|
1769
|
+
return i`<div class="confirm" part="confirm-card" role="group" aria-label=${t.changes(e.length)}>
|
|
1511
1770
|
<div class="confirm-head" part="confirm-header">
|
|
1512
1771
|
<span class="what">${t.changes(e.length)}</span>
|
|
1513
1772
|
<span class="badge">${t.needsOk}</span>
|
|
1514
1773
|
</div>
|
|
1515
|
-
${e.map((e) =>
|
|
1774
|
+
${e.map((e) => i`<div class="item">
|
|
1516
1775
|
<input
|
|
1517
1776
|
type="checkbox"
|
|
1518
1777
|
aria-label=${this.toolLabel(e)}
|
|
@@ -1522,7 +1781,7 @@ var k = n`
|
|
|
1522
1781
|
<span class="body">
|
|
1523
1782
|
<span class="name">${this.toolLabel(e)}</span>
|
|
1524
1783
|
${this.renderPreview(e.preview)}
|
|
1525
|
-
${e.preview ?
|
|
1784
|
+
${e.preview ? i`<span class="exact-head">${t.exactValues}</span>` : a}
|
|
1526
1785
|
${this.renderRows(e.approvalId, e.input)}
|
|
1527
1786
|
</span>
|
|
1528
1787
|
</div>`)}
|
|
@@ -1538,7 +1797,7 @@ var k = n`
|
|
|
1538
1797
|
</div>`;
|
|
1539
1798
|
}
|
|
1540
1799
|
renderProblem(e) {
|
|
1541
|
-
let t = this.labels, n = t.problems[e.code],
|
|
1800
|
+
let t = this.labels, n = t.problems[e.code], r = this.chat, o = e.code === "reconnecting" || e.code === "in-progress" ? "" : e.code === "throttled" || e.code === "conversation-full" || e.code === "token-expired" || e.code === "too-long" || e.code === "answer-cut" || e.code === "step-limit" ? "warn" : "error", s = {
|
|
1542
1801
|
reconnecting: "refresh-cw",
|
|
1543
1802
|
"token-expired": "refresh-cw",
|
|
1544
1803
|
"in-progress": "clock",
|
|
@@ -1547,9 +1806,9 @@ var k = n`
|
|
|
1547
1806
|
"store-unreachable": "plug-zap",
|
|
1548
1807
|
"cut-off": "wifi-off",
|
|
1549
1808
|
unavailable: "wifi-off"
|
|
1550
|
-
}, c = e.code === "conversation-full" ?
|
|
1551
|
-
return
|
|
1552
|
-
<span class=${e.code === "reconnecting" ? "icon spin" : "icon"}>${
|
|
1809
|
+
}, c = e.code === "conversation-full" ? i`<button class="btn secondary" @click=${() => this.newConversation()}>${t.newConversation}</button>` : e.code === "cut-off" ? i`<button class="btn secondary" @click=${() => r?.reload()}>${t.reload}</button>` : e.code === "token-expired" || e.code === "answer-cut" || e.code === "step-limit" ? i`<button class="btn secondary" @click=${() => r?.send(t.continueMessage)}>${t.continue}</button>` : e.code === "too-long" ? i`<button class="btn secondary" @click=${() => r?.send(t.continueSmallerMessage)}>${t.continue}</button>` : e.code === "store-unreachable" || e.code === "unavailable" || e.code === "failed" || e.code === "in-progress" ? i`<button class="btn secondary" @click=${() => r?.retry()}>${t.tryAgain}</button>` : a, l = e.code === "reconnecting" ? a : i`<button class="btn secondary" @click=${() => r?.dismissProblem()}>${t.dismiss}</button>`;
|
|
1810
|
+
return i`<div class=${`problem ${o}`} part="problem" role="status">
|
|
1811
|
+
<span class=${e.code === "reconnecting" ? "icon spin" : "icon"}>${_(s[e.code] ?? "circle-alert", 16)}</span>
|
|
1553
1812
|
<span class="body">
|
|
1554
1813
|
<span class="head">${n.title}</span>
|
|
1555
1814
|
<span>${e.code === "failed" && e.message ? e.message : n.text(e.retryAfter)}</span>
|
|
@@ -1558,44 +1817,87 @@ var k = n`
|
|
|
1558
1817
|
</div>`;
|
|
1559
1818
|
}
|
|
1560
1819
|
renderBottom() {
|
|
1561
|
-
let e = this.labels,
|
|
1562
|
-
return
|
|
1563
|
-
<div
|
|
1820
|
+
let e = this.labels, n = this.state, r = n?.status === "sending" || n?.status === "streaming", o = n?.status === "awaiting-approval";
|
|
1821
|
+
return i`${n?.problem ? i`<div class="column">${this.renderProblem(n.problem)}</div>` : a}
|
|
1822
|
+
<div
|
|
1823
|
+
class="composer column"
|
|
1824
|
+
part="composer"
|
|
1825
|
+
?data-dragging=${this.dragging}
|
|
1826
|
+
@dragover=${(e) => this.onDrag(e, !0)}
|
|
1827
|
+
@dragleave=${(e) => this.onDrag(e, !1)}
|
|
1828
|
+
@drop=${this.onDrop}
|
|
1829
|
+
>
|
|
1830
|
+
${n?.uploads.length ? i`<div class="chips" part="attachment-chips">${n.uploads.map((e) => this.renderChip(e))}</div>
|
|
1831
|
+
<div class="chips-note">${e.photosLimit(this.photoCount(), this.photoMb())}</div>` : a}
|
|
1832
|
+
${this.dragging ? i`<div class="drop-note">${e.dropPhotos}</div>` : a}
|
|
1564
1833
|
<div class="box">
|
|
1834
|
+
${n?.canAttach ? i`<button
|
|
1835
|
+
class="attach"
|
|
1836
|
+
part="attach-button"
|
|
1837
|
+
aria-label=${e.attachPhoto}
|
|
1838
|
+
title=${e.attachPhoto}
|
|
1839
|
+
?disabled=${!this.chat}
|
|
1840
|
+
@click=${() => this.pickPhotos()}
|
|
1841
|
+
>
|
|
1842
|
+
${_("image-plus", 17)}
|
|
1843
|
+
</button>
|
|
1844
|
+
<input
|
|
1845
|
+
type="file"
|
|
1846
|
+
hidden
|
|
1847
|
+
multiple
|
|
1848
|
+
accept=${(this.chat?.attachmentLimits().accept ?? t.accept).join(",")}
|
|
1849
|
+
@change=${this.onPicked}
|
|
1850
|
+
/>` : a}
|
|
1565
1851
|
<label class="sr-only" for="input">${e.placeholder}</label>
|
|
1566
1852
|
<textarea
|
|
1567
1853
|
id="input"
|
|
1568
1854
|
part="input"
|
|
1569
1855
|
rows="1"
|
|
1570
|
-
lang=${this.locale ||
|
|
1856
|
+
lang=${this.locale || a}
|
|
1571
1857
|
placeholder=${e.placeholder}
|
|
1572
1858
|
.value=${this.draft}
|
|
1573
1859
|
?disabled=${!this.chat}
|
|
1574
1860
|
@input=${this.onInput}
|
|
1575
1861
|
@keydown=${this.onKeydown}
|
|
1862
|
+
@paste=${this.onPaste}
|
|
1576
1863
|
></textarea>
|
|
1577
|
-
${
|
|
1864
|
+
${r ? i`<button class="stop" part="stop" @click=${() => this.chat?.stop()}>
|
|
1578
1865
|
<span class="square"></span>${e.stop}
|
|
1579
|
-
</button>` :
|
|
1866
|
+
</button>` : i`<button
|
|
1580
1867
|
class="send"
|
|
1581
1868
|
part="send"
|
|
1582
1869
|
aria-label=${e.send}
|
|
1583
1870
|
title=${e.send}
|
|
1584
|
-
?disabled=${!this.
|
|
1871
|
+
?disabled=${!this.canSend() || !this.chat}
|
|
1585
1872
|
@click=${() => this.submit()}
|
|
1586
1873
|
>
|
|
1587
|
-
${
|
|
1874
|
+
${_("arrow-up", 17)}
|
|
1588
1875
|
</button>`}
|
|
1589
1876
|
</div>
|
|
1590
1877
|
<div class="footer">
|
|
1591
|
-
<span class="ghuri">${
|
|
1592
|
-
<span>· ${
|
|
1878
|
+
<span class="ghuri">${h(12)} Ghuri AI</span>
|
|
1879
|
+
<span>· ${o ? e.newMessageCancels : e.footer}</span>
|
|
1593
1880
|
</div>
|
|
1594
1881
|
</div>`;
|
|
1595
1882
|
}
|
|
1883
|
+
photoCount() {
|
|
1884
|
+
return this.chat?.attachmentLimits().maxCount ?? t.maxCount;
|
|
1885
|
+
}
|
|
1886
|
+
photoMb() {
|
|
1887
|
+
let e = this.chat?.attachmentLimits().maxBytes ?? t.maxBytes;
|
|
1888
|
+
return Math.round(e / 1048576 * 10) / 10;
|
|
1889
|
+
}
|
|
1596
1890
|
};
|
|
1891
|
+
function P(e) {
|
|
1892
|
+
if (typeof e == "string") try {
|
|
1893
|
+
let t = new URL(e);
|
|
1894
|
+
return t.protocol === "https:" ? t.toString() : void 0;
|
|
1895
|
+
} catch {
|
|
1896
|
+
return;
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1597
1899
|
// src/index.ts
|
|
1598
|
-
typeof customElements < "u" && !customElements.get("ghuri-chat") && customElements.define("ghuri-chat",
|
|
1599
|
-
export {
|
|
1900
|
+
typeof customElements < "u" && !customElements.get("ghuri-chat") && customElements.define("ghuri-chat", N);
|
|
1901
|
+
export { N as t };
|
|
1600
1902
|
|
|
1601
|
-
//# sourceMappingURL=src-
|
|
1903
|
+
//# sourceMappingURL=src-1wp0ThTf.js.map
|