@ghuri/ai-widget 0.1.2 → 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,38 +1,48 @@
1
- import { t as e } from "./core-BekZ5K2i.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);
13
+ }
14
+ function f(e) {
15
+ return Array.isArray(e) && e.length > 0 && e.every((e) => e && typeof e == "object" && !Array.isArray(e));
12
16
  }
13
- function u(e) {
17
+ function p(e) {
14
18
  if (typeof e != "object" || !e || Array.isArray(e)) return e === void 0 ? [] : [{
15
19
  label: "Value",
16
- value: l(e)
20
+ value: d(e)
17
21
  }];
18
22
  let t = [];
19
- for (let [n, r] of Object.entries(e)) if (r && typeof r == "object" && !Array.isArray(r)) {
23
+ for (let [n, r] of Object.entries(e)) if (f(r)) r.forEach((e, r) => {
24
+ for (let [i, a] of Object.entries(e)) t.push({
25
+ label: `${u(n)} ${r + 1} · ${u(i)}`,
26
+ value: d(a)
27
+ });
28
+ });
29
+ else if (r && typeof r == "object" && !Array.isArray(r)) {
20
30
  let e = Object.entries(r);
21
31
  e.length || t.push({
22
- label: c(n),
32
+ label: u(n),
23
33
  value: "{}"
24
34
  });
25
35
  for (let [r, i] of e) t.push({
26
- label: `${c(n)} · ${c(r)}`,
27
- value: l(i)
36
+ label: `${u(n)} · ${u(r)}`,
37
+ value: d(i)
28
38
  });
29
39
  } else t.push({
30
- label: c(n),
31
- value: l(r)
40
+ label: u(n),
41
+ value: d(r)
32
42
  });
33
43
  return t;
34
44
  }
35
- function d(e) {
45
+ function m(e) {
36
46
  if (!e || typeof e != "object") return null;
37
47
  let t = e;
38
48
  if (typeof t.count == "number") return t.count;
@@ -45,8 +55,8 @@ function d(e) {
45
55
  return null;
46
56
  }
47
57
  // src/ui/icons.ts
48
- function f(e = 20) {
49
- 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">
50
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"/>
51
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"/>
52
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"/>
@@ -54,7 +64,7 @@ function f(e = 20) {
54
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"/>
55
65
  </svg>`;
56
66
  }
57
- var p = {
67
+ var g = {
58
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\"/>",
59
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\"/>",
60
70
  x: "<path d=\"M18 6 6 18\"/><path d=\"m6 6 12 12\"/>",
@@ -71,14 +81,27 @@ var p = {
71
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\"/>",
72
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\"/>",
73
83
  "chevron-down": "<path d=\"m6 9 6 6 6-6\"/>",
74
- 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\"/>"
75
87
  };
76
- function m(e, t = 16) {
77
- return a`<svg class="icon" width=${t} height=${t} viewBox="0 0 24 24" fill="none" stroke="currentColor"
78
- stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">${o(p[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>`;
79
91
  }
80
92
  // src/ui/labels.ts
81
- var h = {
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",
82
105
  placeholder: "Write in Bangla, Banglish or English…",
83
106
  send: "Send",
84
107
  stop: "Stop",
@@ -103,6 +126,7 @@ var h = {
103
126
  outcomeUnknown: "Outcome unknown",
104
127
  stepFailed: "Failed",
105
128
  now: "now",
129
+ lines: (e) => `${e} lines`,
106
130
  running: "Working…",
107
131
  found: (e) => `${e} found`,
108
132
  footer: "Changes always ask you first. AI can make mistakes.",
@@ -112,6 +136,7 @@ var h = {
112
136
  reload: "Reload",
113
137
  continue: "Continue",
114
138
  continueMessage: "Continue",
139
+ continueSmallerMessage: "Your last reply was too long and got cut off. Continue, doing it in smaller steps.",
115
140
  newConversation: "New conversation",
116
141
  dismiss: "Dismiss",
117
142
  problems: {
@@ -147,10 +172,26 @@ var h = {
147
172
  title: "The assistant isn't available",
148
173
  text: () => "Check your connection, then try again."
149
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
+ },
150
187
  "cut-off": {
151
188
  title: "The reply was cut off",
152
189
  text: () => "The connection dropped. Reload the conversation to see what finished."
153
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
+ },
154
195
  failed: {
155
196
  title: "Something went wrong",
156
197
  text: () => "Please try again."
@@ -158,8 +199,19 @@ var h = {
158
199
  },
159
200
  noConversations: "No conversations yet.",
160
201
  loading: "Loading…"
161
- }, g = {
162
- ...h,
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: "ছবি এখানে ছেড়ে দিন",
163
215
  placeholder: "বাংলা, Banglish বা English-এ লিখুন…",
164
216
  send: "পাঠান",
165
217
  stop: "থামান",
@@ -171,9 +223,9 @@ var h = {
171
223
  emptyTitle: "কী সাহায্য করতে পারি?",
172
224
  confirm: "নিশ্চিত করুন",
173
225
  cancel: "বাতিল",
174
- confirmN: (e) => `${v(e)}টি নিশ্চিত করুন`,
226
+ confirmN: (e) => `${x(e)}টি নিশ্চিত করুন`,
175
227
  cancelAll: "সব বাতিল",
176
- changes: (e) => `${v(e)}টি পরিবর্তন`,
228
+ changes: (e) => `${x(e)}টি পরিবর্তন`,
177
229
  needsOk: "আপনার অনুমতি দরকার",
178
230
  exactValues: "ঠিক যা পাঠানো হবে",
179
231
  unticked: "টিক না থাকলে বাতিল",
@@ -184,8 +236,9 @@ var h = {
184
236
  outcomeUnknown: "ফলাফল জানা নেই",
185
237
  stepFailed: "হয়নি",
186
238
  now: "এখন",
239
+ lines: (e) => `${x(e)} লাইন`,
187
240
  running: "কাজ চলছে…",
188
- found: (e) => `${v(e)}টি পাওয়া গেছে`,
241
+ found: (e) => `${x(e)}টি পাওয়া গেছে`,
189
242
  footer: "যেকোনো পরিবর্তনের আগে আপনার অনুমতি নেওয়া হয়। AI ভুল করতে পারে।",
190
243
  newMessageCancels: "নতুন মেসেজ পাঠালে অপেক্ষমাণ পরিবর্তন বাতিল হবে।",
191
244
  leaveWarning: "উত্তর এখনো লেখা হচ্ছে। তবুও চলে যাবেন?",
@@ -193,6 +246,7 @@ var h = {
193
246
  reload: "আবার লোড করুন",
194
247
  continue: "চালিয়ে যান",
195
248
  continueMessage: "চালিয়ে যাও",
249
+ continueSmallerMessage: "তোমার আগের উত্তর বেশি লম্বা হয়ে মাঝপথে কেটে গেছে। ছোট ছোট ধাপে চালিয়ে যাও।",
196
250
  newConversation: "নতুন কথোপকথন",
197
251
  dismiss: "ঠিক আছে",
198
252
  problems: {
@@ -214,7 +268,7 @@ var h = {
214
268
  },
215
269
  throttled: {
216
270
  title: "অনেক বেশি মেসেজ",
217
- text: (e) => e ? `আরেকটি পাঠানোর আগে ${v(e)} সেকেন্ড অপেক্ষা করুন।` : "আরেকটি পাঠানোর আগে একটু অপেক্ষা করুন।"
271
+ text: (e) => e ? `আরেকটি পাঠানোর আগে ${x(e)} সেকেন্ড অপেক্ষা করুন।` : "আরেকটি পাঠানোর আগে একটু অপেক্ষা করুন।"
218
272
  },
219
273
  forbidden: {
220
274
  title: "অনুমতি নেই",
@@ -228,10 +282,26 @@ var h = {
228
282
  title: "অ্যাসিস্ট্যান্ট এখন পাওয়া যাচ্ছে না",
229
283
  text: () => "ইন্টারনেট সংযোগ দেখে আবার চেষ্টা করুন।"
230
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
+ },
231
297
  "cut-off": {
232
298
  title: "উত্তর মাঝপথে থেমে গেছে",
233
299
  text: () => "সংযোগ বিচ্ছিন্ন হয়েছিল। কী শেষ হয়েছে দেখতে আবার লোড করুন।"
234
300
  },
301
+ "photos-refused": {
302
+ title: "এখানে ছবি পাঠানো যাচ্ছে না",
303
+ text: () => "কিছুই পাঠানো হয়নি। ছবি ছাড়া মেসেজ পাঠান, বা ড্যাশবোর্ডে ছবি আপলোড করুন।"
304
+ },
235
305
  failed: {
236
306
  title: "কিছু একটা ভুল হয়েছে",
237
307
  text: () => "আবার চেষ্টা করুন।"
@@ -239,12 +309,12 @@ var h = {
239
309
  },
240
310
  noConversations: "এখনো কোনো কথোপকথন নেই।",
241
311
  loading: "লোড হচ্ছে…"
242
- }, _ = "০১২৩৪৫৬৭৮৯";
243
- function v(e) {
244
- return String(e).replace(/\d/g, (e) => _[Number(e)]);
312
+ }, b = "০১২৩৪৫৬৭৮৯";
313
+ function x(e) {
314
+ return String(e).replace(/\d/g, (e) => b[Number(e)]);
245
315
  }
246
- function y(e, t = {}) {
247
- let n = (e ?? "").toLowerCase().startsWith("bn") ? g : h;
316
+ function S(e, t = {}) {
317
+ let n = (e ?? "").toLowerCase().startsWith("bn") ? y : v;
248
318
  return {
249
319
  ...n,
250
320
  ...t,
@@ -255,89 +325,89 @@ function y(e, t = {}) {
255
325
  };
256
326
  }
257
327
  // src/ui/markdown.ts
258
- var b = /^(https?:|mailto:)/i;
259
- function x(e) {
328
+ var C = /^(https?:|mailto:)/i;
329
+ function w(e) {
260
330
  let t = e.trim();
261
- return b.test(t) ? t : null;
331
+ return C.test(t) ? t : null;
262
332
  }
263
- function S(e) {
264
- return (e ?? []).map((e) => C(e));
333
+ function T(e) {
334
+ return (e ?? []).map((e) => E(e));
265
335
  }
266
- function C(e) {
336
+ function E(e) {
267
337
  switch (e.type) {
268
- case "strong": return r`<strong>${S(e.tokens)}</strong>`;
269
- case "em": return r`<em>${S(e.tokens)}</em>`;
270
- case "del": return r`<del>${S(e.tokens)}</del>`;
271
- case "codespan": return r`<code>${e.text}</code>`;
272
- 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 />`;
273
343
  case "link": {
274
- let t = e, n = x(t.href);
275
- return n ? r`<a href=${n} target="_blank" rel="noopener noreferrer nofollow">${S(t.tokens)}</a>` : r`${S(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)}`;
276
346
  }
277
347
  case "image": return e.text || "";
278
348
  case "text": {
279
349
  let t = e;
280
- return t.tokens ? r`${S(t.tokens)}` : w(t.text);
350
+ return t.tokens ? i`${T(t.tokens)}` : D(t.text);
281
351
  }
282
352
  case "escape": return e.text;
283
353
  case "html": return e.raw;
284
354
  default: return "raw" in e ? String(e.raw) : "";
285
355
  }
286
356
  }
287
- function w(e) {
357
+ function D(e) {
288
358
  return e.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, "\"").replace(/&#39;/g, "'").replace(/&amp;/g, "&");
289
359
  }
290
- function T(e) {
360
+ function O(e) {
291
361
  switch (e.type) {
292
- case "paragraph": return r`<p>${S(e.tokens)}</p>`;
293
- case "heading": return r`<p class="heading">${S(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>`;
294
364
  case "list": {
295
- let t = e, n = t.items.map((e) => r`<li>${e.tokens.map(E)}</li>`);
296
- 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>`;
297
367
  }
298
368
  case "table": {
299
369
  let t = e;
300
- return r`<div class="table-wrap">
370
+ return i`<div class="table-wrap">
301
371
  <table>
302
372
  <thead>
303
373
  <tr>
304
- ${t.header.map((e) => r`<th>${S(e.tokens)}</th>`)}
374
+ ${t.header.map((e) => i`<th>${T(e.tokens)}</th>`)}
305
375
  </tr>
306
376
  </thead>
307
377
  <tbody>
308
- ${t.rows.map((e) => r`<tr>${e.map((e) => r`<td>${S(e.tokens)}</td>`)}</tr>`)}
378
+ ${t.rows.map((e) => i`<tr>${e.map((e) => i`<td>${T(e.tokens)}</td>`)}</tr>`)}
309
379
  </tbody>
310
380
  </table>
311
381
  </div>`;
312
382
  }
313
- case "code": return r`<pre><code>${e.text}</code></pre>`;
314
- case "blockquote": return r`<blockquote>${e.tokens.map(T)}</blockquote>`;
315
- case "hr": return r`<hr />`;
316
- 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>`;
317
387
  case "text": {
318
388
  let t = e;
319
- return r`<p>${t.tokens ? S(t.tokens) : w(t.text)}</p>`;
389
+ return i`<p>${t.tokens ? T(t.tokens) : D(t.text)}</p>`;
320
390
  }
321
- case "space": return i;
322
- 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;
323
393
  }
324
394
  }
325
- function E(e) {
395
+ function k(e) {
326
396
  if (e.type === "text") {
327
397
  let t = e;
328
- return t.tokens ? r`${S(t.tokens)}` : w(t.text);
398
+ return t.tokens ? i`${T(t.tokens)}` : D(t.text);
329
399
  }
330
- return T(e);
400
+ return O(e);
331
401
  }
332
- function D(e) {
333
- let t = s.lex(e, {
402
+ function A(e) {
403
+ let t = l.lex(e, {
334
404
  gfm: !0,
335
405
  breaks: !0
336
406
  });
337
- return r`${t.map(T)}`;
407
+ return i`${t.map(O)}`;
338
408
  }
339
409
  // src/ui/styles.ts
340
- var O = n`
410
+ var j = r`
341
411
  :host {
342
412
  --_accent: var(--ghuri-accent, #8e1b2b);
343
413
  --_accent-text: var(--ghuri-accent-text, #ffffff);
@@ -951,6 +1021,149 @@ var O = n`
951
1021
  background: var(--_accent);
952
1022
  color: var(--_accent-text);
953
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
+ }
954
1167
  .stop {
955
1168
  flex: none;
956
1169
  display: inline-flex;
@@ -1092,8 +1305,8 @@ var O = n`
1092
1305
  font-weight: 500;
1093
1306
  min-height: 48px;
1094
1307
  }
1095
- `, k = "result was not recorded", A = class extends t {
1096
- static styles = O;
1308
+ `, M = "result was not recorded", N = class extends n {
1309
+ static styles = j;
1097
1310
  static properties = {
1098
1311
  layout: {
1099
1312
  type: String,
@@ -1111,7 +1324,8 @@ var O = n`
1111
1324
  conversations: { state: !0 },
1112
1325
  draft: { state: !0 },
1113
1326
  expanded: { state: !0 },
1114
- unticked: { state: !0 }
1327
+ unticked: { state: !0 },
1328
+ dragging: { state: !0 }
1115
1329
  };
1116
1330
  chat = null;
1117
1331
  options = null;
@@ -1134,8 +1348,9 @@ var O = n`
1134
1348
  }), ...[
1135
1349
  "tool-result",
1136
1350
  "approval-pending",
1137
- "turn-end"
1138
- ].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();
1139
1354
  }
1140
1355
  setOptions(e) {
1141
1356
  if (this.options) {
@@ -1151,7 +1366,7 @@ var O = n`
1151
1366
  return this.chat;
1152
1367
  }
1153
1368
  show() {
1154
- 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()));
1155
1370
  }
1156
1371
  hide() {
1157
1372
  this.open && (this.open = !1, this.fire("close", {}));
@@ -1181,7 +1396,7 @@ var O = n`
1181
1396
  this.unsubscribe = [];
1182
1397
  }
1183
1398
  get labels() {
1184
- return y(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);
1185
1400
  }
1186
1401
  fire(e, t) {
1187
1402
  this.dispatchEvent(new CustomEvent(`ghuri:${e}`, {
@@ -1218,10 +1433,14 @@ var O = n`
1218
1433
  }
1219
1434
  async submit() {
1220
1435
  let e = this.draft.trim(), t = this.state?.status;
1221
- if (!e || !this.chat || t === "sending" || t === "streaming") return;
1436
+ if (!this.canSend() || !this.chat || t === "sending" || t === "streaming") return;
1222
1437
  this.draft = "", this.stickToBottom = !0;
1223
1438
  let n = !this.state?.conversationId;
1224
- 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");
1225
1444
  }
1226
1445
  onKeydown(e) {
1227
1446
  e.key !== "Enter" || e.shiftKey || e.isComposing || e.keyCode === 229 || (e.preventDefault(), this.submit());
@@ -1250,16 +1469,16 @@ var O = n`
1250
1469
  }
1251
1470
  wanted = /* @__PURE__ */ new Map();
1252
1471
  cardSlot(e, t, n) {
1253
- let i = this.cards.get(e);
1254
- if (!i) {
1472
+ let r = this.cards.get(e);
1473
+ if (!r) {
1255
1474
  let t = document.createElement("div");
1256
- 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);
1257
1476
  }
1258
1477
  return this.wanted.set(e, {
1259
- slot: i.container.slot,
1478
+ slot: r.container.slot,
1260
1479
  ctx: t,
1261
1480
  render: n
1262
- }), r`<slot name=${i.container.slot}></slot>`;
1481
+ }), i`<slot name=${r.container.slot}></slot>`;
1263
1482
  }
1264
1483
  mountCards() {
1265
1484
  for (let [e, t] of this.cards) {
@@ -1276,7 +1495,7 @@ var O = n`
1276
1495
  }
1277
1496
  }
1278
1497
  render() {
1279
- 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">
1280
1499
  <aside class="sidebar" part="history">${this.renderSidebar()}</aside>
1281
1500
  <section class="main">
1282
1501
  <div class="page-head" part="header">
@@ -1285,8 +1504,8 @@ var O = n`
1285
1504
  </div>
1286
1505
  ${this.renderScroll()} ${this.renderBottom()}
1287
1506
  </section>
1288
- </div>` : r`${this.renderHeader()}
1289
- ${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()}`}`;
1290
1509
  }
1291
1510
  currentTitle() {
1292
1511
  let e = this.state?.conversationId;
@@ -1294,37 +1513,37 @@ var O = n`
1294
1513
  }
1295
1514
  renderHeader() {
1296
1515
  let e = this.labels;
1297
- return r`<header class="header" part="header">
1516
+ return i`<header class="header" part="header">
1298
1517
  <div class="brand">
1299
- <span class="avatar">${f(20)}</span>
1518
+ <span class="avatar">${h(20)}</span>
1300
1519
  <span class="names">
1301
1520
  <span class="title" part="title">${this.heading || "Ghuri AI"}</span>
1302
- ${this.subtitle ? r`<span class="subtitle">${this.subtitle}</span>` : i}
1521
+ ${this.subtitle ? i`<span class="subtitle">${this.subtitle}</span>` : a}
1303
1522
  </span>
1304
1523
  </div>
1305
1524
  <div class="tools">
1306
1525
  <button class="icon-button" title=${e.history} aria-label=${e.history} @click=${() => this.showHistory()}>
1307
- ${m("history")}
1526
+ ${_("history")}
1308
1527
  </button>
1309
1528
  <button class="icon-button" title=${e.newChat} aria-label=${e.newChat} @click=${() => this.newConversation()}>
1310
- ${m("square-pen")}
1529
+ ${_("square-pen")}
1311
1530
  </button>
1312
1531
  <button class="icon-button" title=${e.close} aria-label=${e.close} @click=${() => this.hide()}>
1313
- ${m("x")}
1532
+ ${_("x")}
1314
1533
  </button>
1315
1534
  </div>
1316
1535
  </header>`;
1317
1536
  }
1318
1537
  renderConversationList() {
1319
1538
  let e = this.labels;
1320
- if (this.conversations === null) return r`<div class="muted">${e.loading}</div>`;
1321
- 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>`;
1322
1541
  let t = new Intl.DateTimeFormat(this.locale || void 0, {
1323
1542
  dateStyle: "medium",
1324
1543
  timeStyle: "short"
1325
1544
  });
1326
- return r`<nav class="history" aria-label=${e.conversations}>
1327
- ${this.conversations.map((e) => r`<button
1545
+ return i`<nav class="history" aria-label=${e.conversations}>
1546
+ ${this.conversations.map((e) => i`<button
1328
1547
  class="conversation"
1329
1548
  aria-current=${e.id === this.state?.conversationId ? "true" : "false"}
1330
1549
  @click=${() => this.openConversation(e.id)}
@@ -1336,7 +1555,7 @@ var O = n`
1336
1555
  }
1337
1556
  renderPanelHistory() {
1338
1557
  let e = this.labels;
1339
- return r`<div class="scroll">
1558
+ return i`<div class="scroll">
1340
1559
  <div class="history-head">
1341
1560
  <span>${e.conversations}</span>
1342
1561
  <button class="btn primary" @click=${() => this.newConversation()}>${e.newChat}</button>
@@ -1346,53 +1565,104 @@ var O = n`
1346
1565
  }
1347
1566
  renderSidebar() {
1348
1567
  let e = this.labels;
1349
- return r`<div class="side-brand">${f(24)}<span>${this.heading || "Ghuri AI"}</span></div>
1350
- <button class="new-chat" @click=${() => this.newConversation()}>${m("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>
1351
1570
  ${this.renderConversationList()}`;
1352
1571
  }
1353
1572
  renderScroll() {
1354
- 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))}
1355
1574
  ${this.renderPending()}` : this.renderEmpty();
1356
- return r`<div class="scroll">
1575
+ return i`<div class="scroll">
1357
1576
  <div class="messages column" role="log" aria-live="polite" aria-busy=${e?.status === "streaming"}>${n}</div>
1358
1577
  </div>`;
1359
1578
  }
1360
1579
  renderEmpty() {
1361
1580
  let e = this.labels, t = this.options?.starters ?? [];
1362
- return r`<div class="empty" part="empty">
1363
- <span class="avatar">${f(24)}</span>
1581
+ return i`<div class="empty" part="empty">
1582
+ <span class="avatar">${h(24)}</span>
1364
1583
  <span class="heading">${e.emptyTitle}</span>
1365
- ${t.length ? r`<div class="starters">
1366
- ${t.map((e) => r`<button class="starter" part="starter" @click=${() => this.chat?.send(e)}>${e}</button>`)}
1367
- </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}
1368
1587
  </div>`;
1369
1588
  }
1370
1589
  renderMessage(e, t) {
1371
1590
  if (e.role === "user") {
1372
- let t = e.parts.map((e) => e.kind === "text" ? e.text : "").join("");
1373
- 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}`;
1374
1593
  }
1375
- 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) => {
1376
1595
  if (t.kind === "text") {
1377
- if (!t.text) return i;
1378
- let o = n && a === e.parts.length - 1;
1379
- return r`<div class="md" part="assistant">${D(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>`;
1380
1599
  }
1381
- return this.renderTool(t);
1382
- }), o = n && !e.parts.length, s = r`<div class="assistant">
1383
- ${a}
1384
- ${o ? r`<span class="step" part="tool-step">${m("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>
1385
1636
  </div>`;
1386
- return this.layout === "page" ? r`<div class="assistant-row"><span class="avatar">${f(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));
1387
1657
  }
1388
1658
  toolLabel(e) {
1389
- return e.title || c(e.toolName);
1659
+ return e.title || u(e.toolName);
1390
1660
  }
1391
1661
  renderTool(e) {
1392
1662
  let t = this.labels;
1393
- if (e.state === "awaiting-approval") return i;
1663
+ if (e.state === "awaiting-approval") return a;
1394
1664
  if (e.approvalId) {
1395
- let [n, i, a] = e.state === "done" ? [
1665
+ let [n, r, a] = e.state === "done" ? [
1396
1666
  "done",
1397
1667
  "circle-check",
1398
1668
  t.confirmed
@@ -1403,15 +1673,15 @@ var O = n`
1403
1673
  ] : e.state === "error" ? [
1404
1674
  "error",
1405
1675
  "circle-alert",
1406
- e.errorText?.includes(k) ? t.outcomeUnknown : t.stepFailed
1676
+ e.errorText?.includes(M) ? t.outcomeUnknown : t.stepFailed
1407
1677
  ] : [
1408
1678
  "denied",
1409
1679
  "loader",
1410
1680
  t.running
1411
1681
  ];
1412
- 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 ?? "" : ""}>
1413
1683
  <span class="what"
1414
- ><span class=${n}>${m(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
1415
1685
  >
1416
1686
  <span class=${n}>${a}</span>
1417
1687
  </div>`;
@@ -1421,42 +1691,42 @@ var O = n`
1421
1691
  part: e,
1422
1692
  client: this.chat
1423
1693
  }, n);
1424
- if (this.options?.toolSteps === "hide") return i;
1425
- let a = e.state === "done" ? d(e.output) : null, o = e.state === "done" ? r`<span class="ok">${m("check", 13)}</span>` : e.state === "error" ? r`<span class="bad">${m("circle-alert", 13)}</span>` : e.state === "denied" ? m("ban", 13) : r`<span class="spin">${m("loader", 13)}</span>`;
1426
- return r`<span class="step" part="tool-step" title=${e.state === "error" ? e.errorText ?? "" : ""}>
1427
- ${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>
1428
1698
  </span>`;
1429
1699
  }
1430
1700
  renderPreview(e) {
1431
- if (!e) return i;
1701
+ if (!e) return a;
1432
1702
  let t = this.labels;
1433
- return r`<div class="preview" part="preview">
1703
+ return i`<div class="preview" part="preview">
1434
1704
  <div class="preview-summary">${e.summary}</div>
1435
- ${e.changes.length ? r`<ul class="preview-changes">
1436
- ${e.changes.map((e) => r`<li>
1705
+ ${e.changes.length ? i`<ul class="preview-changes">
1706
+ ${e.changes.map((e) => i`<li>
1437
1707
  <span class="preview-label">${e.label}:</span>
1438
- ${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> → `}
1439
1709
  <span class="preview-next">${e.next}</span>
1440
1710
  </li>`)}
1441
- </ul>` : i}
1711
+ </ul>` : a}
1442
1712
  </div>`;
1443
1713
  }
1444
1714
  renderRows(e, t) {
1445
- let n = this.labels, a = u(t), o = this.expanded.has(e), s = a.some((e) => e.value.length > 160);
1446
- return r`<div class="rows">
1447
- ${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">
1448
1718
  <span class="label">${e.label}</span>
1449
- <span class="value">${!o && e.value.length > 160 ? `${e.value.slice(0, 160)}…` : e.value}</span>
1719
+ <span class="value">${o ? e.value : c(e.value)}</span>
1450
1720
  </div>`)}
1451
- ${s ? 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}
1452
1722
  </div>`;
1453
1723
  }
1454
1724
  renderPending() {
1455
1725
  let e = this.state?.pendingApprovals ?? [];
1456
- if (!e.length || this.state?.status !== "awaiting-approval") return i;
1726
+ if (!e.length || this.state?.status !== "awaiting-approval") return a;
1457
1727
  let t = this.labels;
1458
1728
  if (e.length === 1) {
1459
- 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 = {
1460
1730
  kind: "tool",
1461
1731
  toolCallId: n.toolCallId,
1462
1732
  toolName: n.toolName,
@@ -1465,7 +1735,7 @@ var O = n`
1465
1735
  state: "awaiting-approval",
1466
1736
  approvalId: n.approvalId
1467
1737
  };
1468
- if (a && this.chat) {
1738
+ if (r && this.chat) {
1469
1739
  let e = this.chat;
1470
1740
  return this.cardSlot(`confirm:${n.approvalId}`, {
1471
1741
  part: o,
@@ -1476,15 +1746,15 @@ var O = n`
1476
1746
  approved: t,
1477
1747
  ...r ? { reason: r } : {}
1478
1748
  }])
1479
- }, a);
1749
+ }, r);
1480
1750
  }
1481
- 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)}>
1482
1752
  <div class="confirm-head" part="confirm-header">
1483
- <span class="what">${m("pencil-line", 15)} ${this.toolLabel(n)}</span>
1753
+ <span class="what">${_("pencil-line", 15)} ${this.toolLabel(n)}</span>
1484
1754
  <span class="badge">${t.needsOk}</span>
1485
1755
  </div>
1486
1756
  ${this.renderPreview(n.preview)}
1487
- ${n.preview ? r`<div class="exact-head">${t.exactValues}</div>` : i}
1757
+ ${n.preview ? i`<div class="exact-head">${t.exactValues}</div>` : a}
1488
1758
  ${this.renderRows(n.approvalId, n.input)}
1489
1759
  <div class="confirm-foot">
1490
1760
  <span class="hint">${n.preview ? "" : t.exactValues}</span>
@@ -1496,12 +1766,12 @@ var O = n`
1496
1766
  </div>`;
1497
1767
  }
1498
1768
  let n = e.filter((e) => !this.unticked.has(e.approvalId)).length;
1499
- 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)}>
1500
1770
  <div class="confirm-head" part="confirm-header">
1501
1771
  <span class="what">${t.changes(e.length)}</span>
1502
1772
  <span class="badge">${t.needsOk}</span>
1503
1773
  </div>
1504
- ${e.map((e) => r`<div class="item">
1774
+ ${e.map((e) => i`<div class="item">
1505
1775
  <input
1506
1776
  type="checkbox"
1507
1777
  aria-label=${this.toolLabel(e)}
@@ -1511,7 +1781,7 @@ var O = n`
1511
1781
  <span class="body">
1512
1782
  <span class="name">${this.toolLabel(e)}</span>
1513
1783
  ${this.renderPreview(e.preview)}
1514
- ${e.preview ? r`<span class="exact-head">${t.exactValues}</span>` : i}
1784
+ ${e.preview ? i`<span class="exact-head">${t.exactValues}</span>` : a}
1515
1785
  ${this.renderRows(e.approvalId, e.input)}
1516
1786
  </span>
1517
1787
  </div>`)}
@@ -1527,7 +1797,7 @@ var O = n`
1527
1797
  </div>`;
1528
1798
  }
1529
1799
  renderProblem(e) {
1530
- 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 = {
1531
1801
  reconnecting: "refresh-cw",
1532
1802
  "token-expired": "refresh-cw",
1533
1803
  "in-progress": "clock",
@@ -1536,9 +1806,9 @@ var O = n`
1536
1806
  "store-unreachable": "plug-zap",
1537
1807
  "cut-off": "wifi-off",
1538
1808
  unavailable: "wifi-off"
1539
- }, 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>`;
1540
- return r`<div class=${`problem ${o}`} part="problem" role="status">
1541
- <span class=${e.code === "reconnecting" ? "icon spin" : "icon"}>${m(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>
1542
1812
  <span class="body">
1543
1813
  <span class="head">${n.title}</span>
1544
1814
  <span>${e.code === "failed" && e.message ? e.message : n.text(e.retryAfter)}</span>
@@ -1547,44 +1817,87 @@ var O = n`
1547
1817
  </div>`;
1548
1818
  }
1549
1819
  renderBottom() {
1550
- let e = this.labels, t = this.state, n = t?.status === "sending" || t?.status === "streaming", a = t?.status === "awaiting-approval";
1551
- return r`${t?.problem ? r`<div class="column">${this.renderProblem(t.problem)}</div>` : i}
1552
- <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}
1553
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}
1554
1851
  <label class="sr-only" for="input">${e.placeholder}</label>
1555
1852
  <textarea
1556
1853
  id="input"
1557
1854
  part="input"
1558
1855
  rows="1"
1559
- lang=${this.locale || i}
1856
+ lang=${this.locale || a}
1560
1857
  placeholder=${e.placeholder}
1561
1858
  .value=${this.draft}
1562
1859
  ?disabled=${!this.chat}
1563
1860
  @input=${this.onInput}
1564
1861
  @keydown=${this.onKeydown}
1862
+ @paste=${this.onPaste}
1565
1863
  ></textarea>
1566
- ${n ? r`<button class="stop" part="stop" @click=${() => this.chat?.stop()}>
1864
+ ${r ? i`<button class="stop" part="stop" @click=${() => this.chat?.stop()}>
1567
1865
  <span class="square"></span>${e.stop}
1568
- </button>` : r`<button
1866
+ </button>` : i`<button
1569
1867
  class="send"
1570
1868
  part="send"
1571
1869
  aria-label=${e.send}
1572
1870
  title=${e.send}
1573
- ?disabled=${!this.draft.trim() || !this.chat}
1871
+ ?disabled=${!this.canSend() || !this.chat}
1574
1872
  @click=${() => this.submit()}
1575
1873
  >
1576
- ${m("arrow-up", 17)}
1874
+ ${_("arrow-up", 17)}
1577
1875
  </button>`}
1578
1876
  </div>
1579
1877
  <div class="footer">
1580
- <span class="ghuri">${f(12)} Ghuri AI</span>
1581
- <span>· ${a ? e.newMessageCancels : e.footer}</span>
1878
+ <span class="ghuri">${h(12)} Ghuri AI</span>
1879
+ <span>· ${o ? e.newMessageCancels : e.footer}</span>
1582
1880
  </div>
1583
1881
  </div>`;
1584
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
+ }
1585
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
+ }
1586
1899
  // src/index.ts
1587
- typeof customElements < "u" && !customElements.get("ghuri-chat") && customElements.define("ghuri-chat", A);
1588
- export { A as t };
1900
+ typeof customElements < "u" && !customElements.get("ghuri-chat") && customElements.define("ghuri-chat", N);
1901
+ export { N as t };
1589
1902
 
1590
- //# sourceMappingURL=src-I1h_3l4Z.js.map
1903
+ //# sourceMappingURL=src-1wp0ThTf.js.map