@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.
@@ -1,47 +1,48 @@
1
- import { t as e } from "./core-B5cGLmtw.js";
2
- import { LitElement as t, css as n, html as r, nothing as i, svg as a } from "lit";
3
- import { unsafeSVG as o } from "lit/directives/unsafe-svg.js";
4
- import { Lexer as s } from "marked";
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 c(e) {
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 l(e) {
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(l).join(", ") : JSON.stringify(e);
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 u(e) {
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 d(e) {
17
+ function p(e) {
17
18
  if (typeof e != "object" || !e || Array.isArray(e)) return e === void 0 ? [] : [{
18
19
  label: "Value",
19
- value: l(e)
20
+ value: d(e)
20
21
  }];
21
22
  let t = [];
22
- for (let [n, r] of Object.entries(e)) if (u(r)) r.forEach((e, r) => {
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: `${c(n)} ${r + 1} · ${c(i)}`,
25
- value: l(a)
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: c(n),
32
+ label: u(n),
32
33
  value: "{}"
33
34
  });
34
35
  for (let [r, i] of e) t.push({
35
- label: `${c(n)} · ${c(r)}`,
36
- value: l(i)
36
+ label: `${u(n)} · ${u(r)}`,
37
+ value: d(i)
37
38
  });
38
39
  } else t.push({
39
- label: c(n),
40
- value: l(r)
40
+ label: u(n),
41
+ value: d(r)
41
42
  });
42
43
  return t;
43
44
  }
44
- function f(e) {
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 p(e = 20) {
58
- return a`<svg class="kite" width=${e} height=${e} viewBox="0 0 28 28" aria-hidden="true" focusable="false">
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 m = {
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 h(e, t = 16) {
86
- return a`<svg class="icon" width=${t} height=${t} viewBox="0 0 24 24" fill="none" stroke="currentColor"
87
- stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">${o(m[e] ?? "")}</svg>`;
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 g = {
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
- ...g,
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) => `${y(e)}টি নিশ্চিত করুন`,
226
+ confirmN: (e) => `${x(e)}টি নিশ্চিত করুন`,
185
227
  cancelAll: "সব বাতিল",
186
- changes: (e) => `${y(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) => `${y(e)} লাইন`,
239
+ lines: (e) => `${x(e)} লাইন`,
198
240
  running: "কাজ চলছে…",
199
- found: (e) => `${y(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 ? `আরেকটি পাঠানোর আগে ${y(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
- }, v = "০১২৩৪৫৬৭৮৯";
254
- function y(e) {
255
- return String(e).replace(/\d/g, (e) => v[Number(e)]);
312
+ }, b = "০১২৩৪৫৬৭৮৯";
313
+ function x(e) {
314
+ return String(e).replace(/\d/g, (e) => b[Number(e)]);
256
315
  }
257
- function b(e, t = {}) {
258
- let n = (e ?? "").toLowerCase().startsWith("bn") ? _ : g;
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 x = /^(https?:|mailto:)/i;
270
- function S(e) {
328
+ var C = /^(https?:|mailto:)/i;
329
+ function w(e) {
271
330
  let t = e.trim();
272
- return x.test(t) ? t : null;
331
+ return C.test(t) ? t : null;
273
332
  }
274
- function C(e) {
275
- return (e ?? []).map((e) => w(e));
333
+ function T(e) {
334
+ return (e ?? []).map((e) => E(e));
276
335
  }
277
- function w(e) {
336
+ function E(e) {
278
337
  switch (e.type) {
279
- case "strong": return r`<strong>${C(e.tokens)}</strong>`;
280
- case "em": return r`<em>${C(e.tokens)}</em>`;
281
- case "del": return r`<del>${C(e.tokens)}</del>`;
282
- case "codespan": return r`<code>${e.text}</code>`;
283
- case "br": return r`<br />`;
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 = S(t.href);
286
- return n ? r`<a href=${n} target="_blank" rel="noopener noreferrer nofollow">${C(t.tokens)}</a>` : r`${C(t.tokens)}`;
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 ? r`${C(t.tokens)}` : T(t.text);
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 T(e) {
357
+ function D(e) {
299
358
  return e.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, "\"").replace(/&#39;/g, "'").replace(/&amp;/g, "&");
300
359
  }
301
- function E(e) {
360
+ function O(e) {
302
361
  switch (e.type) {
303
- case "paragraph": return r`<p>${C(e.tokens)}</p>`;
304
- case "heading": return r`<p class="heading">${C(e.tokens)}</p>`;
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) => r`<li>${e.tokens.map(D)}</li>`);
307
- return t.ordered ? r`<ol start=${typeof t.start == "number" ? t.start : 1}>${n}</ol>` : r`<ul>${n}</ul>`;
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 r`<div class="table-wrap">
370
+ return i`<div class="table-wrap">
312
371
  <table>
313
372
  <thead>
314
373
  <tr>
315
- ${t.header.map((e) => r`<th>${C(e.tokens)}</th>`)}
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) => r`<tr>${e.map((e) => r`<td>${C(e.tokens)}</td>`)}</tr>`)}
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 r`<pre><code>${e.text}</code></pre>`;
325
- case "blockquote": return r`<blockquote>${e.tokens.map(E)}</blockquote>`;
326
- case "hr": return r`<hr />`;
327
- case "html": return r`<p>${e.raw}</p>`;
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 r`<p>${t.tokens ? C(t.tokens) : T(t.text)}</p>`;
389
+ return i`<p>${t.tokens ? T(t.tokens) : D(t.text)}</p>`;
331
390
  }
332
- case "space": return i;
333
- default: return "raw" in e ? r`<p>${String(e.raw)}</p>` : i;
391
+ case "space": return a;
392
+ default: return "raw" in e ? i`<p>${String(e.raw)}</p>` : a;
334
393
  }
335
394
  }
336
- function D(e) {
395
+ function k(e) {
337
396
  if (e.type === "text") {
338
397
  let t = e;
339
- return t.tokens ? r`${C(t.tokens)}` : T(t.text);
398
+ return t.tokens ? i`${T(t.tokens)}` : D(t.text);
340
399
  }
341
- return E(e);
400
+ return O(e);
342
401
  }
343
- function O(e) {
344
- let t = s.lex(e, {
402
+ function A(e) {
403
+ let t = l.lex(e, {
345
404
  gfm: !0,
346
405
  breaks: !0
347
406
  });
348
- return r`${t.map(E)}`;
407
+ return i`${t.map(O)}`;
349
408
  }
350
409
  // src/ui/styles.ts
351
- var k = n`
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
- `, A = "result was not recorded", j = class extends t {
1107
- static styles = k;
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
- ].map((e) => n.on(e, (t) => this.fire(e, t)))], this.layout === "page" && this.loadConversations();
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 b(this.locale || this.options?.locale || document.documentElement.lang || "en", this.options?.labels);
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 (!e || !this.chat || t === "sending" || t === "streaming") return;
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 i = this.cards.get(e);
1265
- if (!i) {
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), i = { container: t }, this.cards.set(e, i);
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: i.container.slot,
1478
+ slot: r.container.slot,
1271
1479
  ctx: t,
1272
1480
  render: n
1273
- }), r`<slot name=${i.container.slot}></slot>`;
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" ? r`<div class="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>` : r`${this.renderHeader()}
1300
- ${this.view === "history" ? this.renderPanelHistory() : r`${this.renderScroll()} ${this.renderBottom()}`}`;
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 r`<header class="header" part="header">
1516
+ return i`<header class="header" part="header">
1309
1517
  <div class="brand">
1310
- <span class="avatar">${p(20)}</span>
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 ? r`<span class="subtitle">${this.subtitle}</span>` : i}
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
- ${h("history")}
1526
+ ${_("history")}
1319
1527
  </button>
1320
1528
  <button class="icon-button" title=${e.newChat} aria-label=${e.newChat} @click=${() => this.newConversation()}>
1321
- ${h("square-pen")}
1529
+ ${_("square-pen")}
1322
1530
  </button>
1323
1531
  <button class="icon-button" title=${e.close} aria-label=${e.close} @click=${() => this.hide()}>
1324
- ${h("x")}
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 r`<div class="muted">${e.loading}</div>`;
1332
- if (!this.conversations.length) return r`<div class="muted">${e.noConversations}</div>`;
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 r`<nav class="history" aria-label=${e.conversations}>
1338
- ${this.conversations.map((e) => r`<button
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 r`<div class="scroll">
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 r`<div class="side-brand">${p(24)}<span>${this.heading || "Ghuri AI"}</span></div>
1361
- <button class="new-chat" @click=${() => this.newConversation()}>${h("square-pen", 15)} ${e.newChat}</button>
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" ? r`<div class="muted">${this.labels.loading}</div>` : t.length ? r`${t.map((e, n) => this.renderMessage(e, n === t.length - 1))}
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 r`<div class="scroll">
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 r`<div class="empty" part="empty">
1374
- <span class="avatar">${p(24)}</span>
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 ? r`<div class="starters">
1377
- ${t.map((e) => r`<button class="starter" part="starter" @click=${() => this.chat?.send(e)}>${e}</button>`)}
1378
- </div>` : i}
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 r`<div class="user" part="user-bubble">${t}</div>`;
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", a = e.parts.map((t, a) => {
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 i;
1389
- let o = n && a === e.parts.length - 1;
1390
- return r`<div class="md" part="assistant">${O(t.text)}${o ? r`<span class="caret"></span>` : i}</div>`;
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 = r`<div class="assistant">
1394
- ${a}
1395
- ${o ? r`<span class="step" part="tool-step">${h("loader", 13)}<span>${this.labels.running}</span></span>` : i}
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
- return this.layout === "page" ? r`<div class="assistant-row"><span class="avatar">${p(18)}</span>${s}</div>` : s;
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 || c(e.toolName);
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 i;
1663
+ if (e.state === "awaiting-approval") return a;
1405
1664
  if (e.approvalId) {
1406
- let [n, i, a] = e.state === "done" ? [
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(A) ? t.outcomeUnknown : t.stepFailed
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 r`<div class="decided" part="decided" title=${e.state === "error" ? e.errorText ?? "" : ""}>
1682
+ return i`<div class="decided" part="decided" title=${e.state === "error" ? e.errorText ?? "" : ""}>
1424
1683
  <span class="what"
1425
- ><span class=${n}>${h(i, 15)}</span>${this.toolLabel(e)}${e.preview ? ` · ${e.preview.summary}` : ""}</span
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 i;
1436
- let a = e.state === "done" ? f(e.output) : null, o = e.state === "done" ? r`<span class="ok">${h("check", 13)}</span>` : e.state === "error" ? r`<span class="bad">${h("circle-alert", 13)}</span>` : e.state === "denied" ? h("ban", 13) : r`<span class="spin">${h("loader", 13)}</span>`;
1437
- return r`<span class="step" part="tool-step" title=${e.state === "error" ? e.errorText ?? "" : ""}>
1438
- ${o}<span>${this.toolLabel(e)}${a === null ? "" : ` · ${t.found(a)}`}</span>
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 i;
1701
+ if (!e) return a;
1443
1702
  let t = this.labels;
1444
- return r`<div class="preview" part="preview">
1703
+ return i`<div class="preview" part="preview">
1445
1704
  <div class="preview-summary">${e.summary}</div>
1446
- ${e.changes.length ? r`<ul class="preview-changes">
1447
- ${e.changes.map((e) => r`<li>
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 ? i : r`<span class="preview-now">${t.now} ${e.current}</span> → `}
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>` : i}
1711
+ </ul>` : a}
1453
1712
  </div>`;
1454
1713
  }
1455
1714
  renderRows(e, t) {
1456
- let n = this.labels, a = d(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 = a.some((e) => e.value.length > 160 || s(e.value) > 1);
1457
- return r`<div class="rows">
1458
- ${a.map((e) => r`<div class="row">
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 ? r`<button class="link" @click=${() => this.toggleRows(e)}>${o ? n.showLess : n.showMore}</button>` : i}
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 i;
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], a = this.options?.cards?.[n.toolName]?.confirm, o = {
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 (a && this.chat) {
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
- }, a);
1749
+ }, r);
1491
1750
  }
1492
- return r`<div class="confirm" part="confirm-card" role="group" aria-label=${this.toolLabel(n)}>
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">${h("pencil-line", 15)} ${this.toolLabel(n)}</span>
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 ? r`<div class="exact-head">${t.exactValues}</div>` : i}
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 r`<div class="confirm" part="confirm-card" role="group" aria-label=${t.changes(e.length)}>
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) => r`<div class="item">
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 ? r`<span class="exact-head">${t.exactValues}</span>` : i}
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], a = this.chat, o = e.code === "reconnecting" || e.code === "in-progress" ? "" : e.code === "throttled" || e.code === "conversation-full" || e.code === "token-expired" ? "warn" : "error", s = {
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" ? r`<button class="btn secondary" @click=${() => this.newConversation()}>${t.newConversation}</button>` : e.code === "cut-off" ? r`<button class="btn secondary" @click=${() => a?.reload()}>${t.reload}</button>` : e.code === "token-expired" ? r`<button class="btn secondary" @click=${() => a?.send(t.continueMessage)}>${t.continue}</button>` : e.code === "store-unreachable" || e.code === "unavailable" || e.code === "failed" || e.code === "in-progress" ? r`<button class="btn secondary" @click=${() => a?.retry()}>${t.tryAgain}</button>` : i, l = e.code === "reconnecting" ? i : r`<button class="btn secondary" @click=${() => a?.dismissProblem()}>${t.dismiss}</button>`;
1551
- return r`<div class=${`problem ${o}`} part="problem" role="status">
1552
- <span class=${e.code === "reconnecting" ? "icon spin" : "icon"}>${h(s[e.code] ?? "circle-alert", 16)}</span>
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, t = this.state, n = t?.status === "sending" || t?.status === "streaming", a = t?.status === "awaiting-approval";
1562
- return r`${t?.problem ? r`<div class="column">${this.renderProblem(t.problem)}</div>` : i}
1563
- <div class="composer column" part="composer">
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 || i}
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
- ${n ? r`<button class="stop" part="stop" @click=${() => this.chat?.stop()}>
1864
+ ${r ? i`<button class="stop" part="stop" @click=${() => this.chat?.stop()}>
1578
1865
  <span class="square"></span>${e.stop}
1579
- </button>` : r`<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.draft.trim() || !this.chat}
1871
+ ?disabled=${!this.canSend() || !this.chat}
1585
1872
  @click=${() => this.submit()}
1586
1873
  >
1587
- ${h("arrow-up", 17)}
1874
+ ${_("arrow-up", 17)}
1588
1875
  </button>`}
1589
1876
  </div>
1590
1877
  <div class="footer">
1591
- <span class="ghuri">${p(12)} Ghuri AI</span>
1592
- <span>· ${a ? e.newMessageCancels : e.footer}</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", j);
1599
- export { j as t };
1900
+ typeof customElements < "u" && !customElements.get("ghuri-chat") && customElements.define("ghuri-chat", N);
1901
+ export { N as t };
1600
1902
 
1601
- //# sourceMappingURL=src-BNRsAIH2.js.map
1903
+ //# sourceMappingURL=src-1wp0ThTf.js.map