@ghuri/ai-widget 0.0.0-stage → 0.1.1

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.
@@ -0,0 +1,1529 @@
1
+ import { t as e } from "./core-CyN0xi9X.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";
5
+ // src/ui/format.ts
6
+ function c(e) {
7
+ let t = e.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_\-.]+/g, " ").trim().toLowerCase();
8
+ return t ? t[0].toUpperCase() + t.slice(1) : e;
9
+ }
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);
12
+ }
13
+ function u(e) {
14
+ if (typeof e != "object" || !e || Array.isArray(e)) return e === void 0 ? [] : [{
15
+ label: "Value",
16
+ value: l(e)
17
+ }];
18
+ let t = [];
19
+ for (let [n, r] of Object.entries(e)) if (r && typeof r == "object" && !Array.isArray(r)) {
20
+ let e = Object.entries(r);
21
+ e.length || t.push({
22
+ label: c(n),
23
+ value: "{}"
24
+ });
25
+ for (let [r, i] of e) t.push({
26
+ label: `${c(n)} · ${c(r)}`,
27
+ value: l(i)
28
+ });
29
+ } else t.push({
30
+ label: c(n),
31
+ value: l(r)
32
+ });
33
+ return t;
34
+ }
35
+ function d(e) {
36
+ if (!e || typeof e != "object") return null;
37
+ let t = e;
38
+ if (typeof t.count == "number") return t.count;
39
+ if (typeof t.total == "number") return t.total;
40
+ for (let e of [
41
+ "results",
42
+ "items",
43
+ "data"
44
+ ]) if (Array.isArray(t[e])) return t[e].length;
45
+ return null;
46
+ }
47
+ // 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">
50
+ <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
+ <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
+ <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"/>
53
+ <path transform="translate(11.75 5.21)" fill="var(--ghuri-kite-red, #f2492e)" d="M0 0.33C3.02 -0.51 6.72 0.22 11.19 2.75L5.43 15.24L2.67 7.66L3.97 4.88L1.18 3.58L0 0.33Z"/>
54
+ <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
+ </svg>`;
56
+ }
57
+ var p = {
58
+ 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
+ "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
+ x: "<path d=\"M18 6 6 18\"/><path d=\"m6 6 12 12\"/>",
61
+ check: "<path d=\"M20 6 9 17l-5-5\"/>",
62
+ loader: "<path d=\"M21 12a9 9 0 1 1-6.22-8.56\"/>",
63
+ "circle-check": "<circle cx=\"12\" cy=\"12\" r=\"10\"/><path d=\"m9 12 2 2 4-4\"/>",
64
+ "circle-x": "<circle cx=\"12\" cy=\"12\" r=\"10\"/><path d=\"m15 9-6 6\"/><path d=\"m9 9 6 6\"/>",
65
+ "circle-alert": "<circle cx=\"12\" cy=\"12\" r=\"10\"/><line x1=\"12\" x2=\"12\" y1=\"8\" y2=\"12\"/><line x1=\"12\" x2=\"12.01\" y1=\"16\" y2=\"16\"/>",
66
+ "arrow-up": "<path d=\"m5 12 7-7 7 7\"/><path d=\"M12 19V5\"/>",
67
+ "pencil-line": "<path d=\"M12 20h9\"/><path d=\"M16.38 3.62a1 1 0 0 1 3 3L7.37 18.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\"/>",
68
+ "refresh-cw": "<path d=\"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8\"/><path d=\"M21 3v5h-5\"/><path d=\"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16\"/><path d=\"M8 16H3v5\"/>",
69
+ clock: "<circle cx=\"12\" cy=\"12\" r=\"10\"/><path d=\"M12 6v6l4 2\"/>",
70
+ "plug-zap": "<path d=\"M6.3 20.3a2.4 2.4 0 0 0 3.4 0L12 18l-6-6-2.3 2.3a2.4 2.4 0 0 0 0 3.4Z\"/><path d=\"m2 22 3-3\"/><path d=\"M7.5 13.5 10 11\"/><path d=\"M10.5 16.5 13 14\"/><path d=\"m18 3-4 4h6l-4 4\"/>",
71
+ "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
+ "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
+ "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\"/>"
75
+ };
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>`;
79
+ }
80
+ // src/ui/labels.ts
81
+ var h = {
82
+ placeholder: "Write in Bangla, Banglish or English…",
83
+ send: "Send",
84
+ stop: "Stop",
85
+ close: "Close",
86
+ history: "Conversations",
87
+ newChat: "New chat",
88
+ conversations: "Conversations",
89
+ searchChats: "Search chats",
90
+ emptyTitle: "How can I help?",
91
+ confirm: "Confirm",
92
+ cancel: "Cancel",
93
+ confirmN: (e) => `Confirm ${e}`,
94
+ cancelAll: "Cancel all",
95
+ changes: (e) => `${e} changes`,
96
+ needsOk: "Needs your OK",
97
+ exactValues: "Exactly what will be sent",
98
+ unticked: "Unticked = cancelled",
99
+ showMore: "Show more",
100
+ showLess: "Show less",
101
+ confirmed: "Confirmed",
102
+ cancelled: "Cancelled",
103
+ outcomeUnknown: "Outcome unknown",
104
+ stepFailed: "Failed",
105
+ running: "Working…",
106
+ found: (e) => `${e} found`,
107
+ footer: "Changes always ask you first. AI can make mistakes.",
108
+ newMessageCancels: "Sending a new message cancels the waiting change.",
109
+ leaveWarning: "A reply is still being written. Leave anyway?",
110
+ tryAgain: "Try again",
111
+ reload: "Reload",
112
+ continue: "Continue",
113
+ continueMessage: "Continue",
114
+ newConversation: "New conversation",
115
+ dismiss: "Dismiss",
116
+ problems: {
117
+ reconnecting: {
118
+ title: "Reconnecting…",
119
+ text: () => "Getting a fresh connection to your store (no action needed)."
120
+ },
121
+ "token-expired": {
122
+ title: "Reconnected",
123
+ text: () => "The connection to your store expired during the reply. It is fixed: continue where it stopped."
124
+ },
125
+ "in-progress": {
126
+ title: "Still answering",
127
+ text: () => "The last reply is still being written. Try again in a moment."
128
+ },
129
+ "conversation-full": {
130
+ title: "This conversation is full",
131
+ text: () => "Start a new conversation to keep going. This one stays in your history."
132
+ },
133
+ throttled: {
134
+ title: "Too many messages",
135
+ text: (e) => e ? `Please wait ${e} seconds before sending another.` : "Please wait a little before sending another."
136
+ },
137
+ forbidden: {
138
+ title: "Not allowed",
139
+ text: () => "You don't have permission for that in this store."
140
+ },
141
+ "store-unreachable": {
142
+ title: "Couldn't reach your store",
143
+ text: () => "The store didn't answer. Nothing was changed."
144
+ },
145
+ unavailable: {
146
+ title: "The assistant isn't available",
147
+ text: () => "Check your connection, then try again."
148
+ },
149
+ "cut-off": {
150
+ title: "The reply was cut off",
151
+ text: () => "The connection dropped. Reload the conversation to see what finished."
152
+ },
153
+ failed: {
154
+ title: "Something went wrong",
155
+ text: () => "Please try again."
156
+ }
157
+ },
158
+ noConversations: "No conversations yet.",
159
+ loading: "Loading…"
160
+ }, g = {
161
+ ...h,
162
+ placeholder: "বাংলা, Banglish বা English-এ লিখুন…",
163
+ send: "পাঠান",
164
+ stop: "থামান",
165
+ close: "বন্ধ করুন",
166
+ history: "আগের কথোপকথন",
167
+ newChat: "নতুন চ্যাট",
168
+ conversations: "কথোপকথন",
169
+ searchChats: "খুঁজুন",
170
+ emptyTitle: "কী সাহায্য করতে পারি?",
171
+ confirm: "নিশ্চিত করুন",
172
+ cancel: "বাতিল",
173
+ confirmN: (e) => `${v(e)}টি নিশ্চিত করুন`,
174
+ cancelAll: "সব বাতিল",
175
+ changes: (e) => `${v(e)}টি পরিবর্তন`,
176
+ needsOk: "আপনার অনুমতি দরকার",
177
+ exactValues: "ঠিক যা পাঠানো হবে",
178
+ unticked: "টিক না থাকলে বাতিল",
179
+ showMore: "আরও দেখুন",
180
+ showLess: "কম দেখুন",
181
+ confirmed: "নিশ্চিত হয়েছে",
182
+ cancelled: "বাতিল হয়েছে",
183
+ outcomeUnknown: "ফলাফল জানা নেই",
184
+ stepFailed: "হয়নি",
185
+ running: "কাজ চলছে…",
186
+ found: (e) => `${v(e)}টি পাওয়া গেছে`,
187
+ footer: "যেকোনো পরিবর্তনের আগে আপনার অনুমতি নেওয়া হয়। AI ভুল করতে পারে।",
188
+ newMessageCancels: "নতুন মেসেজ পাঠালে অপেক্ষমাণ পরিবর্তন বাতিল হবে।",
189
+ leaveWarning: "উত্তর এখনো লেখা হচ্ছে। তবুও চলে যাবেন?",
190
+ tryAgain: "আবার চেষ্টা করুন",
191
+ reload: "আবার লোড করুন",
192
+ continue: "চালিয়ে যান",
193
+ continueMessage: "চালিয়ে যাও",
194
+ newConversation: "নতুন কথোপকথন",
195
+ dismiss: "ঠিক আছে",
196
+ problems: {
197
+ reconnecting: {
198
+ title: "আবার সংযোগ হচ্ছে…",
199
+ text: () => "আপনার স্টোরের সাথে নতুন সংযোগ নেওয়া হচ্ছে (কিছু করতে হবে না)।"
200
+ },
201
+ "token-expired": {
202
+ title: "আবার সংযুক্ত",
203
+ text: () => "উত্তরের মাঝে স্টোরের সংযোগ শেষ হয়েছিল। ঠিক করা হয়েছে, যেখানে থেমেছিল সেখান থেকে চালিয়ে যান।"
204
+ },
205
+ "in-progress": {
206
+ title: "এখনো উত্তর দিচ্ছে",
207
+ text: () => "আগের উত্তর এখনো লেখা হচ্ছে। একটু পরে আবার চেষ্টা করুন।"
208
+ },
209
+ "conversation-full": {
210
+ title: "এই কথোপকথন ভরে গেছে",
211
+ text: () => "চালিয়ে যেতে নতুন কথোপকথন শুরু করুন। এটি আপনার ইতিহাসে থাকবে।"
212
+ },
213
+ throttled: {
214
+ title: "অনেক বেশি মেসেজ",
215
+ text: (e) => e ? `আরেকটি পাঠানোর আগে ${v(e)} সেকেন্ড অপেক্ষা করুন।` : "আরেকটি পাঠানোর আগে একটু অপেক্ষা করুন।"
216
+ },
217
+ forbidden: {
218
+ title: "অনুমতি নেই",
219
+ text: () => "এই স্টোরে এটি করার অনুমতি আপনার নেই।"
220
+ },
221
+ "store-unreachable": {
222
+ title: "স্টোরে পৌঁছানো যায়নি",
223
+ text: () => "স্টোর সাড়া দেয়নি। কিছুই বদলানো হয়নি।"
224
+ },
225
+ unavailable: {
226
+ title: "অ্যাসিস্ট্যান্ট এখন পাওয়া যাচ্ছে না",
227
+ text: () => "ইন্টারনেট সংযোগ দেখে আবার চেষ্টা করুন।"
228
+ },
229
+ "cut-off": {
230
+ title: "উত্তর মাঝপথে থেমে গেছে",
231
+ text: () => "সংযোগ বিচ্ছিন্ন হয়েছিল। কী শেষ হয়েছে দেখতে আবার লোড করুন।"
232
+ },
233
+ failed: {
234
+ title: "কিছু একটা ভুল হয়েছে",
235
+ text: () => "আবার চেষ্টা করুন।"
236
+ }
237
+ },
238
+ noConversations: "এখনো কোনো কথোপকথন নেই।",
239
+ loading: "লোড হচ্ছে…"
240
+ }, _ = "০১২৩৪৫৬৭৮৯";
241
+ function v(e) {
242
+ return String(e).replace(/\d/g, (e) => _[Number(e)]);
243
+ }
244
+ function y(e, t = {}) {
245
+ let n = (e ?? "").toLowerCase().startsWith("bn") ? g : h;
246
+ return {
247
+ ...n,
248
+ ...t,
249
+ problems: {
250
+ ...n.problems,
251
+ ...t.problems ?? {}
252
+ }
253
+ };
254
+ }
255
+ // src/ui/markdown.ts
256
+ var b = /^(https?:|mailto:)/i;
257
+ function x(e) {
258
+ let t = e.trim();
259
+ return b.test(t) ? t : null;
260
+ }
261
+ function S(e) {
262
+ return (e ?? []).map((e) => C(e));
263
+ }
264
+ function C(e) {
265
+ switch (e.type) {
266
+ case "strong": return r`<strong>${S(e.tokens)}</strong>`;
267
+ case "em": return r`<em>${S(e.tokens)}</em>`;
268
+ case "del": return r`<del>${S(e.tokens)}</del>`;
269
+ case "codespan": return r`<code>${e.text}</code>`;
270
+ case "br": return r`<br />`;
271
+ case "link": {
272
+ let t = e, n = x(t.href);
273
+ return n ? r`<a href=${n} target="_blank" rel="noopener noreferrer nofollow">${S(t.tokens)}</a>` : r`${S(t.tokens)}`;
274
+ }
275
+ case "image": return e.text || "";
276
+ case "text": {
277
+ let t = e;
278
+ return t.tokens ? r`${S(t.tokens)}` : w(t.text);
279
+ }
280
+ case "escape": return e.text;
281
+ case "html": return e.raw;
282
+ default: return "raw" in e ? String(e.raw) : "";
283
+ }
284
+ }
285
+ function w(e) {
286
+ return e.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, "\"").replace(/&#39;/g, "'").replace(/&amp;/g, "&");
287
+ }
288
+ function T(e) {
289
+ switch (e.type) {
290
+ case "paragraph": return r`<p>${S(e.tokens)}</p>`;
291
+ case "heading": return r`<p class="heading">${S(e.tokens)}</p>`;
292
+ case "list": {
293
+ let t = e, n = t.items.map((e) => r`<li>${e.tokens.map(E)}</li>`);
294
+ return t.ordered ? r`<ol start=${typeof t.start == "number" ? t.start : 1}>${n}</ol>` : r`<ul>${n}</ul>`;
295
+ }
296
+ case "table": {
297
+ let t = e;
298
+ return r`<div class="table-wrap">
299
+ <table>
300
+ <thead>
301
+ <tr>
302
+ ${t.header.map((e) => r`<th>${S(e.tokens)}</th>`)}
303
+ </tr>
304
+ </thead>
305
+ <tbody>
306
+ ${t.rows.map((e) => r`<tr>${e.map((e) => r`<td>${S(e.tokens)}</td>`)}</tr>`)}
307
+ </tbody>
308
+ </table>
309
+ </div>`;
310
+ }
311
+ case "code": return r`<pre><code>${e.text}</code></pre>`;
312
+ case "blockquote": return r`<blockquote>${e.tokens.map(T)}</blockquote>`;
313
+ case "hr": return r`<hr />`;
314
+ case "html": return r`<p>${e.raw}</p>`;
315
+ case "text": {
316
+ let t = e;
317
+ return r`<p>${t.tokens ? S(t.tokens) : w(t.text)}</p>`;
318
+ }
319
+ case "space": return i;
320
+ default: return "raw" in e ? r`<p>${String(e.raw)}</p>` : i;
321
+ }
322
+ }
323
+ function E(e) {
324
+ if (e.type === "text") {
325
+ let t = e;
326
+ return t.tokens ? r`${S(t.tokens)}` : w(t.text);
327
+ }
328
+ return T(e);
329
+ }
330
+ function D(e) {
331
+ let t = s.lex(e, {
332
+ gfm: !0,
333
+ breaks: !0
334
+ });
335
+ return r`${t.map(T)}`;
336
+ }
337
+ // src/ui/styles.ts
338
+ var O = n`
339
+ :host {
340
+ --_accent: var(--ghuri-accent, #8e1b2b);
341
+ --_accent-text: var(--ghuri-accent-text, #ffffff);
342
+ --_accent-soft: var(--ghuri-accent-soft, #fbeef0);
343
+ --_accent-soft-text: var(--ghuri-accent-soft-text, var(--_accent));
344
+ --_accent-border: var(--ghuri-accent-border, #e8b4bc);
345
+ --_surface: var(--ghuri-surface, #ffffff);
346
+ --_background: var(--ghuri-background, #fafafa);
347
+ --_muted-surface: var(--ghuri-muted-surface, #f4f4f5);
348
+ --_text: var(--ghuri-text, #18181b);
349
+ --_muted: var(--ghuri-muted, #71717a);
350
+ --_border: var(--ghuri-border, #e4e4e7);
351
+ --_success: var(--ghuri-success, #15803d);
352
+ --_warning: var(--ghuri-warning, #b45309);
353
+ --_warning-soft: var(--ghuri-warning-soft, #fffbeb);
354
+ --_danger: var(--ghuri-danger, #dc2626);
355
+ --_danger-soft: var(--ghuri-danger-soft, #fef2f2);
356
+ --_radius: var(--ghuri-radius, 12px);
357
+ --_radius-sm: var(--ghuri-radius-sm, 8px);
358
+ --_bubble-radius: var(--ghuri-bubble-radius, 14px);
359
+ --_font: var(--ghuri-font, inherit);
360
+ --_font-size: var(--ghuri-font-size, 14px);
361
+ --_shadow: var(--ghuri-shadow, 0 1px 2px rgb(0 0 0 / 0.06));
362
+
363
+ display: flex;
364
+ flex-direction: column;
365
+ box-sizing: border-box;
366
+ height: 100%;
367
+ min-height: 0;
368
+ background: var(--_surface);
369
+ color: var(--_text);
370
+ font-family: var(--_font);
371
+ font-size: var(--_font-size);
372
+ line-height: 1.55;
373
+ }
374
+ :host([layout='panel']:not([open])) {
375
+ display: none;
376
+ }
377
+ *,
378
+ *::before,
379
+ *::after {
380
+ box-sizing: border-box;
381
+ }
382
+ button {
383
+ font: inherit;
384
+ color: inherit;
385
+ cursor: pointer;
386
+ border: 0;
387
+ background: none;
388
+ }
389
+ button:focus-visible,
390
+ a:focus-visible {
391
+ outline: 2px solid var(--_accent);
392
+ outline-offset: 2px;
393
+ }
394
+ button:disabled {
395
+ cursor: default;
396
+ opacity: 0.45;
397
+ }
398
+ .sr-only {
399
+ position: absolute;
400
+ width: 1px;
401
+ height: 1px;
402
+ overflow: hidden;
403
+ clip: rect(0 0 0 0);
404
+ white-space: nowrap;
405
+ }
406
+
407
+ /* --- layout --- */
408
+ .page {
409
+ display: grid;
410
+ grid-template-columns: 260px minmax(0, 1fr);
411
+ height: 100%;
412
+ min-height: 0;
413
+ }
414
+ .sidebar {
415
+ display: flex;
416
+ flex-direction: column;
417
+ gap: 12px;
418
+ padding: 12px;
419
+ background: var(--_background);
420
+ border-right: 1px solid var(--_border);
421
+ min-height: 0;
422
+ overflow-y: auto;
423
+ }
424
+ .main {
425
+ display: flex;
426
+ flex-direction: column;
427
+ min-height: 0;
428
+ min-width: 0;
429
+ }
430
+ .column {
431
+ width: 100%;
432
+ max-width: var(--ghuri-page-width, 760px);
433
+ margin: 0 auto;
434
+ }
435
+
436
+ /* --- header --- */
437
+ .header {
438
+ display: flex;
439
+ align-items: center;
440
+ justify-content: space-between;
441
+ gap: 8px;
442
+ padding: 12px 16px;
443
+ border-bottom: 1px solid var(--_border);
444
+ }
445
+ .brand {
446
+ display: flex;
447
+ align-items: center;
448
+ gap: 10px;
449
+ min-width: 0;
450
+ }
451
+ .avatar {
452
+ flex: none;
453
+ display: grid;
454
+ place-items: center;
455
+ width: 32px;
456
+ height: 32px;
457
+ border-radius: 999px;
458
+ background: var(--_accent-soft);
459
+ }
460
+ .names {
461
+ display: flex;
462
+ flex-direction: column;
463
+ min-width: 0;
464
+ }
465
+ .title {
466
+ font-weight: 600;
467
+ white-space: nowrap;
468
+ overflow: hidden;
469
+ text-overflow: ellipsis;
470
+ }
471
+ .subtitle {
472
+ font-size: 12px;
473
+ color: var(--_muted);
474
+ white-space: nowrap;
475
+ overflow: hidden;
476
+ text-overflow: ellipsis;
477
+ }
478
+ .tools {
479
+ display: flex;
480
+ gap: 2px;
481
+ }
482
+ .icon-button {
483
+ display: grid;
484
+ place-items: center;
485
+ width: 32px;
486
+ height: 32px;
487
+ border-radius: var(--_radius-sm);
488
+ color: var(--_muted);
489
+ }
490
+ .icon-button:hover {
491
+ background: var(--_muted-surface);
492
+ color: var(--_text);
493
+ }
494
+
495
+ /* --- messages --- */
496
+ .scroll {
497
+ flex: 1;
498
+ min-height: 0;
499
+ overflow-y: auto;
500
+ overscroll-behavior: contain;
501
+ }
502
+ .messages {
503
+ display: flex;
504
+ flex-direction: column;
505
+ gap: 14px;
506
+ padding: 16px;
507
+ }
508
+ .page .messages {
509
+ gap: 22px;
510
+ padding: 24px 16px;
511
+ }
512
+ .user {
513
+ align-self: flex-end;
514
+ max-width: 85%;
515
+ padding: 8px 12px;
516
+ border-radius: var(--_bubble-radius) var(--_bubble-radius) 4px var(--_bubble-radius);
517
+ background: var(--_muted-surface);
518
+ white-space: pre-wrap;
519
+ overflow-wrap: anywhere;
520
+ }
521
+ .assistant {
522
+ display: flex;
523
+ flex-direction: column;
524
+ gap: 10px;
525
+ min-width: 0;
526
+ }
527
+ .page .assistant-row {
528
+ display: flex;
529
+ gap: 14px;
530
+ align-items: flex-start;
531
+ }
532
+ .page .assistant-row > .avatar {
533
+ background: var(--_surface);
534
+ border: 1px solid var(--_border);
535
+ width: 30px;
536
+ height: 30px;
537
+ }
538
+ .page .assistant-row > .assistant {
539
+ flex: 1;
540
+ }
541
+ .md {
542
+ overflow-wrap: anywhere;
543
+ }
544
+ .md > :first-child {
545
+ margin-top: 0;
546
+ }
547
+ .md > :last-child {
548
+ margin-bottom: 0;
549
+ }
550
+ .md p,
551
+ .md ul,
552
+ .md ol,
553
+ .md pre,
554
+ .md blockquote,
555
+ .md .table-wrap {
556
+ margin: 0 0 8px;
557
+ }
558
+ .md ul,
559
+ .md ol {
560
+ padding-left: 22px;
561
+ }
562
+ .md .heading {
563
+ font-weight: 600;
564
+ }
565
+ .md a {
566
+ color: var(--_accent);
567
+ }
568
+ .md code {
569
+ font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
570
+ font-size: 0.9em;
571
+ background: var(--_muted-surface);
572
+ padding: 1px 4px;
573
+ border-radius: 4px;
574
+ }
575
+ .md pre {
576
+ background: var(--_muted-surface);
577
+ padding: 10px 12px;
578
+ border-radius: var(--_radius-sm);
579
+ overflow-x: auto;
580
+ }
581
+ .md pre code {
582
+ background: none;
583
+ padding: 0;
584
+ }
585
+ .md blockquote {
586
+ border-left: 3px solid var(--_border);
587
+ padding-left: 10px;
588
+ color: var(--_muted);
589
+ }
590
+ .table-wrap {
591
+ overflow-x: auto;
592
+ border: 1px solid var(--_border);
593
+ border-radius: var(--_radius-sm);
594
+ }
595
+ table {
596
+ width: 100%;
597
+ border-collapse: collapse;
598
+ font-size: 0.93em;
599
+ }
600
+ th {
601
+ text-align: left;
602
+ font-weight: 500;
603
+ color: var(--_muted);
604
+ background: var(--_background);
605
+ }
606
+ th,
607
+ td {
608
+ padding: 7px 12px;
609
+ border-top: 1px solid var(--_border);
610
+ }
611
+ thead th {
612
+ border-top: 0;
613
+ }
614
+ .caret {
615
+ display: inline-block;
616
+ width: 7px;
617
+ height: 1em;
618
+ margin-left: 2px;
619
+ vertical-align: text-bottom;
620
+ background: currentColor;
621
+ opacity: 0.55;
622
+ animation: blink 1s steps(2) infinite;
623
+ }
624
+ @keyframes blink {
625
+ 50% {
626
+ opacity: 0;
627
+ }
628
+ }
629
+
630
+ /* --- tool steps --- */
631
+ .step {
632
+ align-self: flex-start;
633
+ display: inline-flex;
634
+ align-items: center;
635
+ gap: 6px;
636
+ max-width: 100%;
637
+ padding: 3px 8px;
638
+ border: 1px solid var(--_border);
639
+ border-radius: 6px;
640
+ font-size: 12px;
641
+ color: var(--_muted);
642
+ }
643
+ .step .ok {
644
+ color: var(--_success);
645
+ }
646
+ .step .bad {
647
+ color: var(--_danger);
648
+ }
649
+ .spin {
650
+ animation: spin 0.9s linear infinite;
651
+ }
652
+ @keyframes spin {
653
+ to {
654
+ transform: rotate(360deg);
655
+ }
656
+ }
657
+ .decided {
658
+ display: flex;
659
+ align-items: center;
660
+ justify-content: space-between;
661
+ gap: 8px;
662
+ padding: 8px 12px;
663
+ border: 1px solid var(--_border);
664
+ border-radius: var(--_radius-sm);
665
+ background: var(--_background);
666
+ font-size: 13px;
667
+ }
668
+ .decided .what {
669
+ display: flex;
670
+ align-items: center;
671
+ gap: 8px;
672
+ font-weight: 500;
673
+ }
674
+ .decided .done {
675
+ color: var(--_success);
676
+ }
677
+ .decided .denied {
678
+ color: var(--_muted);
679
+ }
680
+ .decided .error {
681
+ color: var(--_warning);
682
+ }
683
+
684
+ /* --- confirm card --- */
685
+ .confirm {
686
+ border: 1px solid var(--_accent-border);
687
+ border-radius: var(--_radius);
688
+ background: var(--_surface);
689
+ box-shadow: var(--_shadow);
690
+ overflow: hidden;
691
+ }
692
+ .confirm-head {
693
+ display: flex;
694
+ align-items: center;
695
+ justify-content: space-between;
696
+ gap: 8px;
697
+ padding: 10px 14px;
698
+ background: var(--_accent-soft);
699
+ }
700
+ .confirm-head .what {
701
+ display: flex;
702
+ align-items: center;
703
+ gap: 8px;
704
+ font-weight: 600;
705
+ color: var(--_text);
706
+ }
707
+ .confirm-head .what .icon {
708
+ color: var(--_accent);
709
+ }
710
+ .badge {
711
+ font-size: 11px;
712
+ font-weight: 500;
713
+ color: var(--_accent-soft-text);
714
+ white-space: nowrap;
715
+ }
716
+ .rows {
717
+ padding: 6px 14px;
718
+ }
719
+ .row {
720
+ display: grid;
721
+ grid-template-columns: minmax(80px, 36%) 1fr;
722
+ gap: 10px;
723
+ padding: 6px 0;
724
+ font-size: 13px;
725
+ }
726
+ .row + .row {
727
+ border-top: 1px solid var(--_border);
728
+ }
729
+ .row .label {
730
+ color: var(--_muted);
731
+ overflow-wrap: anywhere;
732
+ }
733
+ .row .value {
734
+ font-weight: 500;
735
+ white-space: pre-wrap;
736
+ overflow-wrap: anywhere;
737
+ }
738
+ .link {
739
+ color: var(--_accent);
740
+ font-size: 12px;
741
+ padding: 0;
742
+ }
743
+ .confirm-foot {
744
+ display: flex;
745
+ align-items: center;
746
+ justify-content: space-between;
747
+ gap: 8px;
748
+ flex-wrap: wrap;
749
+ padding: 10px 14px;
750
+ border-top: 1px solid var(--_border);
751
+ }
752
+ .hint {
753
+ font-size: 12px;
754
+ color: var(--_muted);
755
+ }
756
+ .buttons {
757
+ display: flex;
758
+ gap: 8px;
759
+ margin-left: auto;
760
+ }
761
+ .btn {
762
+ padding: 7px 12px;
763
+ border-radius: var(--_radius-sm);
764
+ font-size: 13px;
765
+ font-weight: 500;
766
+ white-space: nowrap;
767
+ }
768
+ .btn.primary {
769
+ background: var(--_accent);
770
+ color: var(--_accent-text);
771
+ }
772
+ .btn.primary:hover:not(:disabled) {
773
+ filter: brightness(1.08);
774
+ }
775
+ .btn.secondary {
776
+ background: var(--_surface);
777
+ border: 1px solid var(--_border);
778
+ }
779
+ .btn.secondary:hover:not(:disabled) {
780
+ background: var(--_muted-surface);
781
+ }
782
+ .item {
783
+ display: flex;
784
+ gap: 10px;
785
+ padding: 10px 14px;
786
+ border-top: 1px solid var(--_border);
787
+ }
788
+ .item input {
789
+ margin-top: 3px;
790
+ accent-color: var(--_accent);
791
+ width: 16px;
792
+ height: 16px;
793
+ }
794
+ .item .body {
795
+ flex: 1;
796
+ min-width: 0;
797
+ display: flex;
798
+ flex-direction: column;
799
+ gap: 2px;
800
+ }
801
+ .item .rows {
802
+ padding: 2px 0 0;
803
+ }
804
+ .item .name {
805
+ font-weight: 600;
806
+ font-size: 13px;
807
+ }
808
+ .item .summary {
809
+ font-size: 12px;
810
+ color: var(--_muted);
811
+ overflow-wrap: anywhere;
812
+ }
813
+
814
+ /* --- problems --- */
815
+ .problem {
816
+ display: flex;
817
+ gap: 8px;
818
+ align-items: flex-start;
819
+ margin: 0 12px 8px;
820
+ padding: 10px 12px;
821
+ border: 1px solid var(--_border);
822
+ border-radius: var(--_radius-sm);
823
+ background: var(--_surface);
824
+ font-size: 13px;
825
+ }
826
+ .problem.warn {
827
+ background: var(--_warning-soft);
828
+ }
829
+ .problem.warn > .icon {
830
+ color: var(--_warning);
831
+ }
832
+ .problem.error {
833
+ background: var(--_danger-soft);
834
+ }
835
+ .problem.error > .icon {
836
+ color: var(--_danger);
837
+ }
838
+ .problem > .icon {
839
+ flex: none;
840
+ margin-top: 2px;
841
+ color: var(--_muted);
842
+ }
843
+ .problem .body {
844
+ flex: 1;
845
+ display: flex;
846
+ flex-direction: column;
847
+ gap: 2px;
848
+ }
849
+ .problem .head {
850
+ font-weight: 600;
851
+ }
852
+ .problem .actions {
853
+ display: flex;
854
+ gap: 8px;
855
+ margin-top: 6px;
856
+ }
857
+
858
+ /* --- composer --- */
859
+ .composer {
860
+ padding: 12px;
861
+ border-top: 1px solid var(--_border);
862
+ }
863
+ .page .composer {
864
+ border-top: 0;
865
+ padding: 0 16px 14px;
866
+ }
867
+ .box {
868
+ display: flex;
869
+ align-items: flex-end;
870
+ gap: 8px;
871
+ padding: 8px 8px 8px 12px;
872
+ border: 1px solid var(--_border);
873
+ border-radius: var(--_radius);
874
+ background: var(--_surface);
875
+ }
876
+ /* The text field has no ring of its own: the box around it shows focus. */
877
+ .box:focus-within {
878
+ border-color: var(--_accent);
879
+ box-shadow: 0 0 0 3px color-mix(in oklab, var(--_accent) 18%, transparent);
880
+ }
881
+ .page .box {
882
+ border-radius: 24px;
883
+ padding: 12px 10px 10px 18px;
884
+ box-shadow: 0 2px 12px rgb(0 0 0 / 0.06);
885
+ }
886
+ textarea {
887
+ flex: 1;
888
+ min-height: 24px;
889
+ max-height: 180px;
890
+ resize: none;
891
+ border: 0;
892
+ outline: none;
893
+ padding: 4px 0;
894
+ background: transparent;
895
+ color: inherit;
896
+ font: inherit;
897
+ line-height: 1.5;
898
+ }
899
+ textarea::placeholder {
900
+ color: var(--_muted);
901
+ opacity: 0.8;
902
+ }
903
+ .send {
904
+ flex: none;
905
+ display: grid;
906
+ place-items: center;
907
+ width: 32px;
908
+ height: 32px;
909
+ border-radius: 999px;
910
+ background: var(--_accent);
911
+ color: var(--_accent-text);
912
+ }
913
+ .stop {
914
+ flex: none;
915
+ display: inline-flex;
916
+ align-items: center;
917
+ gap: 6px;
918
+ height: 32px;
919
+ padding: 0 10px;
920
+ border-radius: var(--_radius-sm);
921
+ background: var(--_muted-surface);
922
+ font-size: 12px;
923
+ font-weight: 500;
924
+ }
925
+ .stop .square {
926
+ width: 9px;
927
+ height: 9px;
928
+ border-radius: 2px;
929
+ background: currentColor;
930
+ }
931
+ .footer {
932
+ display: flex;
933
+ align-items: center;
934
+ justify-content: center;
935
+ gap: 6px;
936
+ margin-top: 8px;
937
+ font-size: 11px;
938
+ color: var(--_muted);
939
+ text-align: center;
940
+ }
941
+ .footer .ghuri {
942
+ display: inline-flex;
943
+ align-items: center;
944
+ gap: 4px;
945
+ font-weight: 500;
946
+ white-space: nowrap;
947
+ }
948
+
949
+ /* --- empty state and history --- */
950
+ .empty {
951
+ display: flex;
952
+ flex-direction: column;
953
+ align-items: center;
954
+ gap: 10px;
955
+ padding: 32px 16px;
956
+ }
957
+ .empty .avatar {
958
+ width: 44px;
959
+ height: 44px;
960
+ border-radius: 12px;
961
+ }
962
+ .empty .heading {
963
+ font-size: 16px;
964
+ font-weight: 600;
965
+ }
966
+ .starters {
967
+ display: flex;
968
+ flex-direction: column;
969
+ gap: 8px;
970
+ width: 100%;
971
+ max-width: 420px;
972
+ }
973
+ .starter {
974
+ text-align: left;
975
+ padding: 9px 12px;
976
+ border: 1px solid var(--_border);
977
+ border-radius: var(--_radius-sm);
978
+ color: var(--_text);
979
+ font-size: 13px;
980
+ }
981
+ .starter:hover {
982
+ background: var(--_muted-surface);
983
+ }
984
+ .history {
985
+ display: flex;
986
+ flex-direction: column;
987
+ gap: 2px;
988
+ }
989
+ .history-head {
990
+ display: flex;
991
+ align-items: center;
992
+ justify-content: space-between;
993
+ padding: 12px 16px 6px;
994
+ font-weight: 600;
995
+ }
996
+ .conversation {
997
+ display: flex;
998
+ flex-direction: column;
999
+ gap: 1px;
1000
+ text-align: left;
1001
+ padding: 8px 10px;
1002
+ border-radius: var(--_radius-sm);
1003
+ min-width: 0;
1004
+ }
1005
+ .conversation:hover,
1006
+ .conversation[aria-current='true'] {
1007
+ background: var(--_muted-surface);
1008
+ }
1009
+ .conversation .name {
1010
+ font-size: 13px;
1011
+ white-space: nowrap;
1012
+ overflow: hidden;
1013
+ text-overflow: ellipsis;
1014
+ }
1015
+ .conversation .when {
1016
+ font-size: 11px;
1017
+ color: var(--_muted);
1018
+ }
1019
+ .panel-history {
1020
+ padding: 0 8px 12px;
1021
+ }
1022
+ .side-brand {
1023
+ display: flex;
1024
+ align-items: center;
1025
+ gap: 8px;
1026
+ padding: 6px;
1027
+ font-weight: 600;
1028
+ font-size: 15px;
1029
+ }
1030
+ .new-chat {
1031
+ display: flex;
1032
+ align-items: center;
1033
+ gap: 8px;
1034
+ padding: 9px 10px;
1035
+ border: 1px solid var(--_border);
1036
+ border-radius: var(--_radius-sm);
1037
+ background: var(--_surface);
1038
+ font-weight: 500;
1039
+ font-size: 13px;
1040
+ }
1041
+ .muted {
1042
+ color: var(--_muted);
1043
+ font-size: 13px;
1044
+ padding: 8px 10px;
1045
+ }
1046
+ .page-head {
1047
+ display: flex;
1048
+ align-items: center;
1049
+ justify-content: space-between;
1050
+ padding: 12px 20px;
1051
+ font-weight: 500;
1052
+ min-height: 48px;
1053
+ }
1054
+ `, k = "result was not recorded", A = class extends t {
1055
+ static styles = O;
1056
+ static properties = {
1057
+ layout: {
1058
+ type: String,
1059
+ reflect: !0
1060
+ },
1061
+ open: {
1062
+ type: Boolean,
1063
+ reflect: !0
1064
+ },
1065
+ locale: { type: String },
1066
+ heading: { type: String },
1067
+ subtitle: { type: String },
1068
+ state: { state: !0 },
1069
+ view: { state: !0 },
1070
+ conversations: { state: !0 },
1071
+ draft: { state: !0 },
1072
+ expanded: { state: !0 },
1073
+ unticked: { state: !0 }
1074
+ };
1075
+ chat = null;
1076
+ options = null;
1077
+ unsubscribe = [];
1078
+ cards = /* @__PURE__ */ new Map();
1079
+ cardSeq = 0;
1080
+ stickToBottom = !0;
1081
+ onBeforeUnload = (e) => {
1082
+ e.preventDefault(), e.returnValue = this.labels.leaveWarning;
1083
+ };
1084
+ guarding = !1;
1085
+ constructor() {
1086
+ super(), this.layout = "panel", this.open = !1, this.locale = "", this.heading = "", this.subtitle = "", this.state = null, this.view = "chat", this.conversations = null, this.draft = "", this.expanded = /* @__PURE__ */ new Set(), this.unticked = /* @__PURE__ */ new Set();
1087
+ }
1088
+ configure(t) {
1089
+ this.detach(), this.options = t, t.layout && (this.layout = t.layout), t.title !== void 0 && (this.heading = t.title), t.subtitle !== void 0 && (this.subtitle = t.subtitle), t.locale && (this.locale = t.locale);
1090
+ let n = new e(t);
1091
+ this.chat = n, this.state = n.getState(), this.unsubscribe = [n.subscribe((e) => {
1092
+ this.state = e, this.guardUnload(e.status === "sending" || e.status === "streaming");
1093
+ }), ...[
1094
+ "tool-result",
1095
+ "approval-pending",
1096
+ "turn-end"
1097
+ ].map((e) => n.on(e, (t) => this.fire(e, t)))], this.layout === "page" && this.loadConversations();
1098
+ }
1099
+ setOptions(e) {
1100
+ if (this.options) {
1101
+ this.options = {
1102
+ ...this.options,
1103
+ ...e
1104
+ }, e.layout && (this.layout = e.layout), e.title !== void 0 && (this.heading = e.title), e.subtitle !== void 0 && (this.subtitle = e.subtitle), e.locale && (this.locale = e.locale);
1105
+ for (let e of this.cards.values()) e.drawn = void 0;
1106
+ this.layout === "page" && this.conversations === null && this.loadConversations(), this.requestUpdate();
1107
+ }
1108
+ }
1109
+ get client() {
1110
+ return this.chat;
1111
+ }
1112
+ show() {
1113
+ this.open || (this.open = !0, this.fire("open", {}), this.updateComplete.then(() => this.focusInput()));
1114
+ }
1115
+ hide() {
1116
+ this.open && (this.open = !1, this.fire("close", {}));
1117
+ }
1118
+ toggle() {
1119
+ this.open ? this.hide() : this.show();
1120
+ }
1121
+ async ask(e, t = {}) {
1122
+ this.show(), this.view = "chat", t.send === !1 ? (this.draft = e, await this.updateComplete, this.focusInput()) : await this.chat?.send(e);
1123
+ }
1124
+ newConversation() {
1125
+ this.chat?.newConversation(), this.view = "chat", this.expanded = /* @__PURE__ */ new Set(), this.unticked = /* @__PURE__ */ new Set(), this.updateComplete.then(() => this.focusInput());
1126
+ }
1127
+ async openConversation(e) {
1128
+ this.view = "chat", await this.chat?.openConversation(e);
1129
+ }
1130
+ async end() {
1131
+ await this.chat?.end(), this.conversations = null;
1132
+ }
1133
+ disconnectedCallback() {
1134
+ super.disconnectedCallback(), this.guardUnload(!1);
1135
+ for (let e of this.cards.values()) e.cleanup?.(), e.container.remove();
1136
+ this.cards.clear();
1137
+ }
1138
+ detach() {
1139
+ for (let e of this.unsubscribe) e();
1140
+ this.unsubscribe = [];
1141
+ }
1142
+ get labels() {
1143
+ return y(this.locale || this.options?.locale || document.documentElement.lang || "en", this.options?.labels);
1144
+ }
1145
+ fire(e, t) {
1146
+ this.dispatchEvent(new CustomEvent(`ghuri:${e}`, {
1147
+ detail: t,
1148
+ bubbles: !0,
1149
+ composed: !0
1150
+ }));
1151
+ }
1152
+ guardUnload(e) {
1153
+ e !== this.guarding && (this.guarding = e, e ? window.addEventListener("beforeunload", this.onBeforeUnload) : window.removeEventListener("beforeunload", this.onBeforeUnload));
1154
+ }
1155
+ focusInput() {
1156
+ this.renderRoot.querySelector("textarea")?.focus();
1157
+ }
1158
+ willUpdate(e) {
1159
+ if (e.has("state")) {
1160
+ let e = this.renderRoot.querySelector(".scroll");
1161
+ this.stickToBottom = !e || e.scrollHeight - e.scrollTop - e.clientHeight < 80;
1162
+ }
1163
+ }
1164
+ updated() {
1165
+ if (this.stickToBottom) {
1166
+ let e = this.renderRoot.querySelector(".scroll");
1167
+ e && (e.scrollTop = e.scrollHeight);
1168
+ }
1169
+ this.mountCards();
1170
+ }
1171
+ async loadConversations() {
1172
+ if (this.chat) try {
1173
+ this.conversations = (await this.chat.listConversations({ limit: 50 })).results;
1174
+ } catch {
1175
+ this.conversations = [];
1176
+ }
1177
+ }
1178
+ async submit() {
1179
+ let e = this.draft.trim(), t = this.state?.status;
1180
+ if (!e || !this.chat || t === "sending" || t === "streaming") return;
1181
+ this.draft = "", this.stickToBottom = !0;
1182
+ let n = !this.state?.conversationId;
1183
+ await this.chat.send(e), n && this.layout === "page" && this.loadConversations();
1184
+ }
1185
+ onKeydown(e) {
1186
+ e.key !== "Enter" || e.shiftKey || e.isComposing || e.keyCode === 229 || (e.preventDefault(), this.submit());
1187
+ }
1188
+ onInput(e) {
1189
+ let t = e.target;
1190
+ this.draft = t.value, t.style.height = "auto", t.style.height = `${Math.min(t.scrollHeight, 180)}px`;
1191
+ }
1192
+ toggleRows(e) {
1193
+ let t = new Set(this.expanded);
1194
+ t.has(e) ? t.delete(e) : t.add(e), this.expanded = t;
1195
+ }
1196
+ tick(e, t) {
1197
+ let n = new Set(this.unticked);
1198
+ t ? n.delete(e) : n.add(e), this.unticked = n;
1199
+ }
1200
+ async decideAll(e) {
1201
+ let t = this.state?.pendingApprovals ?? [];
1202
+ this.chat && t.length && (await this.chat.decide(t.map((t) => ({
1203
+ approvalId: t.approvalId,
1204
+ approved: e && !this.unticked.has(t.approvalId)
1205
+ }))), this.unticked = /* @__PURE__ */ new Set());
1206
+ }
1207
+ async showHistory() {
1208
+ this.view = this.view === "history" ? "chat" : "history", this.view === "history" && await this.loadConversations();
1209
+ }
1210
+ wanted = /* @__PURE__ */ new Map();
1211
+ cardSlot(e, t, n) {
1212
+ let i = this.cards.get(e);
1213
+ if (!i) {
1214
+ let t = document.createElement("div");
1215
+ t.slot = `ghuri-card-${++this.cardSeq}`, t.dataset.ghuriCard = e, this.appendChild(t), i = { container: t }, this.cards.set(e, i);
1216
+ }
1217
+ return this.wanted.set(e, {
1218
+ slot: i.container.slot,
1219
+ ctx: t,
1220
+ render: n
1221
+ }), r`<slot name=${i.container.slot}></slot>`;
1222
+ }
1223
+ mountCards() {
1224
+ for (let [e, t] of this.cards) {
1225
+ let n = this.wanted.get(e);
1226
+ if (!n) {
1227
+ t.cleanup?.(), t.container.remove(), this.cards.delete(e);
1228
+ continue;
1229
+ }
1230
+ let r = n.ctx.part, i = `${r.state}|${r.approvalId ?? ""}|${n.ctx.approval ? "confirm" : "result"}`;
1231
+ if (t.drawn === i) continue;
1232
+ t.drawn = i;
1233
+ let a = n.render(t.container, n.ctx);
1234
+ typeof a == "function" && (t.cleanup = a);
1235
+ }
1236
+ }
1237
+ render() {
1238
+ return this.wanted = /* @__PURE__ */ new Map(), this.layout === "page" ? r`<div class="page">
1239
+ <aside class="sidebar" part="history">${this.renderSidebar()}</aside>
1240
+ <section class="main">
1241
+ <div class="page-head" part="header">
1242
+ <span class="title">${this.currentTitle()}</span>
1243
+ <span class="subtitle">${this.subtitle}</span>
1244
+ </div>
1245
+ ${this.renderScroll()} ${this.renderBottom()}
1246
+ </section>
1247
+ </div>` : r`${this.renderHeader()}
1248
+ ${this.view === "history" ? this.renderPanelHistory() : r`${this.renderScroll()} ${this.renderBottom()}`}`;
1249
+ }
1250
+ currentTitle() {
1251
+ let e = this.state?.conversationId;
1252
+ return this.conversations?.find((t) => t.id === e)?.title ?? "";
1253
+ }
1254
+ renderHeader() {
1255
+ let e = this.labels;
1256
+ return r`<header class="header" part="header">
1257
+ <div class="brand">
1258
+ <span class="avatar">${f(20)}</span>
1259
+ <span class="names">
1260
+ <span class="title" part="title">${this.heading || "Ghuri AI"}</span>
1261
+ ${this.subtitle ? r`<span class="subtitle">${this.subtitle}</span>` : i}
1262
+ </span>
1263
+ </div>
1264
+ <div class="tools">
1265
+ <button class="icon-button" title=${e.history} aria-label=${e.history} @click=${() => this.showHistory()}>
1266
+ ${m("history")}
1267
+ </button>
1268
+ <button class="icon-button" title=${e.newChat} aria-label=${e.newChat} @click=${() => this.newConversation()}>
1269
+ ${m("square-pen")}
1270
+ </button>
1271
+ <button class="icon-button" title=${e.close} aria-label=${e.close} @click=${() => this.hide()}>
1272
+ ${m("x")}
1273
+ </button>
1274
+ </div>
1275
+ </header>`;
1276
+ }
1277
+ renderConversationList() {
1278
+ let e = this.labels;
1279
+ if (this.conversations === null) return r`<div class="muted">${e.loading}</div>`;
1280
+ if (!this.conversations.length) return r`<div class="muted">${e.noConversations}</div>`;
1281
+ let t = new Intl.DateTimeFormat(this.locale || void 0, {
1282
+ dateStyle: "medium",
1283
+ timeStyle: "short"
1284
+ });
1285
+ return r`<nav class="history" aria-label=${e.conversations}>
1286
+ ${this.conversations.map((e) => r`<button
1287
+ class="conversation"
1288
+ aria-current=${e.id === this.state?.conversationId ? "true" : "false"}
1289
+ @click=${() => this.openConversation(e.id)}
1290
+ >
1291
+ <span class="name">${e.title || "—"}</span>
1292
+ <span class="when">${t.format(new Date(e.updatedAt))}</span>
1293
+ </button>`)}
1294
+ </nav>`;
1295
+ }
1296
+ renderPanelHistory() {
1297
+ let e = this.labels;
1298
+ return r`<div class="scroll">
1299
+ <div class="history-head">
1300
+ <span>${e.conversations}</span>
1301
+ <button class="btn primary" @click=${() => this.newConversation()}>${e.newChat}</button>
1302
+ </div>
1303
+ <div class="panel-history" part="history">${this.renderConversationList()}</div>
1304
+ </div>`;
1305
+ }
1306
+ renderSidebar() {
1307
+ let e = this.labels;
1308
+ return r`<div class="side-brand">${f(24)}<span>${this.heading || "Ghuri AI"}</span></div>
1309
+ <button class="new-chat" @click=${() => this.newConversation()}>${m("square-pen", 15)} ${e.newChat}</button>
1310
+ ${this.renderConversationList()}`;
1311
+ }
1312
+ renderScroll() {
1313
+ 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))}
1314
+ ${this.renderPending()}` : this.renderEmpty();
1315
+ return r`<div class="scroll">
1316
+ <div class="messages column" role="log" aria-live="polite" aria-busy=${e?.status === "streaming"}>${n}</div>
1317
+ </div>`;
1318
+ }
1319
+ renderEmpty() {
1320
+ let e = this.labels, t = this.options?.starters ?? [];
1321
+ return r`<div class="empty" part="empty">
1322
+ <span class="avatar">${f(24)}</span>
1323
+ <span class="heading">${e.emptyTitle}</span>
1324
+ ${t.length ? r`<div class="starters">
1325
+ ${t.map((e) => r`<button class="starter" part="starter" @click=${() => this.chat?.send(e)}>${e}</button>`)}
1326
+ </div>` : i}
1327
+ </div>`;
1328
+ }
1329
+ renderMessage(e, t) {
1330
+ if (e.role === "user") {
1331
+ let t = e.parts.map((e) => e.kind === "text" ? e.text : "").join("");
1332
+ return r`<div class="user" part="user-bubble">${t}</div>`;
1333
+ }
1334
+ let n = t && this.state?.status === "streaming", a = e.parts.map((t, a) => {
1335
+ if (t.kind === "text") {
1336
+ if (!t.text) return i;
1337
+ let o = n && a === e.parts.length - 1;
1338
+ return r`<div class="md" part="assistant">${D(t.text)}${o ? r`<span class="caret"></span>` : i}</div>`;
1339
+ }
1340
+ return this.renderTool(t);
1341
+ }), o = n && !e.parts.length, s = r`<div class="assistant">
1342
+ ${a}
1343
+ ${o ? r`<span class="step" part="tool-step">${m("loader", 13)}<span>${this.labels.running}</span></span>` : i}
1344
+ </div>`;
1345
+ return this.layout === "page" ? r`<div class="assistant-row"><span class="avatar">${f(18)}</span>${s}</div>` : s;
1346
+ }
1347
+ toolLabel(e) {
1348
+ return e.title || c(e.toolName);
1349
+ }
1350
+ renderTool(e) {
1351
+ let t = this.labels;
1352
+ if (e.state === "awaiting-approval") return i;
1353
+ if (e.approvalId) {
1354
+ let [n, i, a] = e.state === "done" ? [
1355
+ "done",
1356
+ "circle-check",
1357
+ t.confirmed
1358
+ ] : e.state === "denied" ? [
1359
+ "denied",
1360
+ "circle-x",
1361
+ t.cancelled
1362
+ ] : e.state === "error" ? [
1363
+ "error",
1364
+ "circle-alert",
1365
+ e.errorText?.includes(k) ? t.outcomeUnknown : t.stepFailed
1366
+ ] : [
1367
+ "denied",
1368
+ "loader",
1369
+ t.running
1370
+ ];
1371
+ return r`<div class="decided" part="decided" title=${e.state === "error" ? e.errorText ?? "" : ""}>
1372
+ <span class="what"><span class=${n}>${m(i, 15)}</span>${this.toolLabel(e)}</span>
1373
+ <span class=${n}>${a}</span>
1374
+ </div>`;
1375
+ }
1376
+ let n = this.options?.cards?.[e.toolName]?.result;
1377
+ if (n && e.state === "done" && this.chat) return this.cardSlot(`result:${e.toolCallId}`, {
1378
+ part: e,
1379
+ client: this.chat
1380
+ }, n);
1381
+ if (this.options?.toolSteps === "hide") return i;
1382
+ 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>`;
1383
+ return r`<span class="step" part="tool-step" title=${e.state === "error" ? e.errorText ?? "" : ""}>
1384
+ ${o}<span>${this.toolLabel(e)}${a === null ? "" : ` · ${t.found(a)}`}</span>
1385
+ </span>`;
1386
+ }
1387
+ renderRows(e, t) {
1388
+ let n = this.labels, a = u(t), o = this.expanded.has(e), s = a.some((e) => e.value.length > 160);
1389
+ return r`<div class="rows">
1390
+ ${a.map((e) => r`<div class="row">
1391
+ <span class="label">${e.label}</span>
1392
+ <span class="value">${!o && e.value.length > 160 ? `${e.value.slice(0, 160)}…` : e.value}</span>
1393
+ </div>`)}
1394
+ ${s ? r`<button class="link" @click=${() => this.toggleRows(e)}>${o ? n.showLess : n.showMore}</button>` : i}
1395
+ </div>`;
1396
+ }
1397
+ renderPending() {
1398
+ let e = this.state?.pendingApprovals ?? [];
1399
+ if (!e.length || this.state?.status !== "awaiting-approval") return i;
1400
+ let t = this.labels;
1401
+ if (e.length === 1) {
1402
+ let n = e[0], i = this.options?.cards?.[n.toolName]?.confirm, a = {
1403
+ kind: "tool",
1404
+ toolCallId: n.toolCallId,
1405
+ toolName: n.toolName,
1406
+ ...n.title ? { title: n.title } : {},
1407
+ input: n.input,
1408
+ state: "awaiting-approval",
1409
+ approvalId: n.approvalId
1410
+ };
1411
+ if (i && this.chat) {
1412
+ let e = this.chat;
1413
+ return this.cardSlot(`confirm:${n.approvalId}`, {
1414
+ part: a,
1415
+ approval: n,
1416
+ client: e,
1417
+ decide: (t, r) => e.decide([{
1418
+ approvalId: n.approvalId,
1419
+ approved: t,
1420
+ ...r ? { reason: r } : {}
1421
+ }])
1422
+ }, i);
1423
+ }
1424
+ return r`<div class="confirm" part="confirm-card" role="group" aria-label=${this.toolLabel(n)}>
1425
+ <div class="confirm-head" part="confirm-header">
1426
+ <span class="what">${m("pencil-line", 15)} ${this.toolLabel(n)}</span>
1427
+ <span class="badge">${t.needsOk}</span>
1428
+ </div>
1429
+ ${this.renderRows(n.approvalId, n.input)}
1430
+ <div class="confirm-foot">
1431
+ <span class="hint">${t.exactValues}</span>
1432
+ <span class="buttons">
1433
+ <button class="btn secondary" part="button-secondary" @click=${() => this.decideAll(!1)}>${t.cancel}</button>
1434
+ <button class="btn primary" part="button-primary" @click=${() => this.decideAll(!0)}>${t.confirm}</button>
1435
+ </span>
1436
+ </div>
1437
+ </div>`;
1438
+ }
1439
+ let n = e.filter((e) => !this.unticked.has(e.approvalId)).length;
1440
+ return r`<div class="confirm" part="confirm-card" role="group" aria-label=${t.changes(e.length)}>
1441
+ <div class="confirm-head" part="confirm-header">
1442
+ <span class="what">${t.changes(e.length)}</span>
1443
+ <span class="badge">${t.needsOk}</span>
1444
+ </div>
1445
+ ${e.map((e) => r`<div class="item">
1446
+ <input
1447
+ type="checkbox"
1448
+ aria-label=${this.toolLabel(e)}
1449
+ .checked=${!this.unticked.has(e.approvalId)}
1450
+ @change=${(t) => this.tick(e.approvalId, t.target.checked)}
1451
+ />
1452
+ <span class="body">
1453
+ <span class="name">${this.toolLabel(e)}</span>
1454
+ ${this.renderRows(e.approvalId, e.input)}
1455
+ </span>
1456
+ </div>`)}
1457
+ <div class="confirm-foot">
1458
+ <span class="hint">${t.unticked}</span>
1459
+ <span class="buttons">
1460
+ <button class="btn secondary" part="button-secondary" @click=${() => this.decideAll(!1)}>${t.cancelAll}</button>
1461
+ <button class="btn primary" part="button-primary" ?disabled=${!n} @click=${() => this.decideAll(!0)}>
1462
+ ${t.confirmN(n)}
1463
+ </button>
1464
+ </span>
1465
+ </div>
1466
+ </div>`;
1467
+ }
1468
+ renderProblem(e) {
1469
+ 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 = {
1470
+ reconnecting: "refresh-cw",
1471
+ "token-expired": "refresh-cw",
1472
+ "in-progress": "clock",
1473
+ throttled: "clock",
1474
+ "conversation-full": "messages-square",
1475
+ "store-unreachable": "plug-zap",
1476
+ "cut-off": "wifi-off",
1477
+ unavailable: "wifi-off"
1478
+ }, 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>`;
1479
+ return r`<div class=${`problem ${o}`} part="problem" role="status">
1480
+ <span class=${e.code === "reconnecting" ? "icon spin" : "icon"}>${m(s[e.code] ?? "circle-alert", 16)}</span>
1481
+ <span class="body">
1482
+ <span class="head">${n.title}</span>
1483
+ <span>${e.code === "failed" && e.message ? e.message : n.text(e.retryAfter)}</span>
1484
+ <span class="actions">${c}${l}</span>
1485
+ </span>
1486
+ </div>`;
1487
+ }
1488
+ renderBottom() {
1489
+ let e = this.labels, t = this.state, n = t?.status === "sending" || t?.status === "streaming", a = t?.status === "awaiting-approval";
1490
+ return r`${t?.problem ? r`<div class="column">${this.renderProblem(t.problem)}</div>` : i}
1491
+ <div class="composer column" part="composer">
1492
+ <div class="box">
1493
+ <label class="sr-only" for="input">${e.placeholder}</label>
1494
+ <textarea
1495
+ id="input"
1496
+ part="input"
1497
+ rows="1"
1498
+ lang=${this.locale || i}
1499
+ placeholder=${e.placeholder}
1500
+ .value=${this.draft}
1501
+ ?disabled=${!this.chat}
1502
+ @input=${this.onInput}
1503
+ @keydown=${this.onKeydown}
1504
+ ></textarea>
1505
+ ${n ? r`<button class="stop" part="stop" @click=${() => this.chat?.stop()}>
1506
+ <span class="square"></span>${e.stop}
1507
+ </button>` : r`<button
1508
+ class="send"
1509
+ part="send"
1510
+ aria-label=${e.send}
1511
+ title=${e.send}
1512
+ ?disabled=${!this.draft.trim() || !this.chat}
1513
+ @click=${() => this.submit()}
1514
+ >
1515
+ ${m("arrow-up", 17)}
1516
+ </button>`}
1517
+ </div>
1518
+ <div class="footer">
1519
+ <span class="ghuri">${f(12)} Ghuri AI</span>
1520
+ <span>· ${a ? e.newMessageCancels : e.footer}</span>
1521
+ </div>
1522
+ </div>`;
1523
+ }
1524
+ };
1525
+ // src/index.ts
1526
+ typeof customElements < "u" && !customElements.get("ghuri-chat") && customElements.define("ghuri-chat", A);
1527
+ export { A as t };
1528
+
1529
+ //# sourceMappingURL=src-BCZf85sn.js.map