@ghuri/ai-widget 0.0.0-stage → 0.1.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.
@@ -0,0 +1,1532 @@
1
+ import { t as e } from "./core-BqhB9RhK.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 .name {
802
+ font-weight: 600;
803
+ font-size: 13px;
804
+ }
805
+ .item .summary {
806
+ font-size: 12px;
807
+ color: var(--_muted);
808
+ overflow-wrap: anywhere;
809
+ }
810
+
811
+ /* --- problems --- */
812
+ .problem {
813
+ display: flex;
814
+ gap: 8px;
815
+ align-items: flex-start;
816
+ margin: 0 12px 8px;
817
+ padding: 10px 12px;
818
+ border: 1px solid var(--_border);
819
+ border-radius: var(--_radius-sm);
820
+ background: var(--_surface);
821
+ font-size: 13px;
822
+ }
823
+ .problem.warn {
824
+ background: var(--_warning-soft);
825
+ }
826
+ .problem.warn > .icon {
827
+ color: var(--_warning);
828
+ }
829
+ .problem.error {
830
+ background: var(--_danger-soft);
831
+ }
832
+ .problem.error > .icon {
833
+ color: var(--_danger);
834
+ }
835
+ .problem > .icon {
836
+ flex: none;
837
+ margin-top: 2px;
838
+ color: var(--_muted);
839
+ }
840
+ .problem .body {
841
+ flex: 1;
842
+ display: flex;
843
+ flex-direction: column;
844
+ gap: 2px;
845
+ }
846
+ .problem .head {
847
+ font-weight: 600;
848
+ }
849
+ .problem .actions {
850
+ display: flex;
851
+ gap: 8px;
852
+ margin-top: 6px;
853
+ }
854
+
855
+ /* --- composer --- */
856
+ .composer {
857
+ padding: 12px;
858
+ border-top: 1px solid var(--_border);
859
+ }
860
+ .page .composer {
861
+ border-top: 0;
862
+ padding: 0 16px 14px;
863
+ }
864
+ .box {
865
+ display: flex;
866
+ align-items: flex-end;
867
+ gap: 8px;
868
+ padding: 8px 8px 8px 12px;
869
+ border: 1px solid var(--_border);
870
+ border-radius: var(--_radius);
871
+ background: var(--_surface);
872
+ }
873
+ /* The text field has no ring of its own: the box around it shows focus. */
874
+ .box:focus-within {
875
+ border-color: var(--_accent);
876
+ box-shadow: 0 0 0 3px color-mix(in oklab, var(--_accent) 18%, transparent);
877
+ }
878
+ .page .box {
879
+ border-radius: 24px;
880
+ padding: 12px 10px 10px 18px;
881
+ box-shadow: 0 2px 12px rgb(0 0 0 / 0.06);
882
+ }
883
+ textarea {
884
+ flex: 1;
885
+ min-height: 24px;
886
+ max-height: 180px;
887
+ resize: none;
888
+ border: 0;
889
+ outline: none;
890
+ padding: 4px 0;
891
+ background: transparent;
892
+ color: inherit;
893
+ font: inherit;
894
+ line-height: 1.5;
895
+ }
896
+ textarea::placeholder {
897
+ color: var(--_muted);
898
+ opacity: 0.8;
899
+ }
900
+ .send {
901
+ flex: none;
902
+ display: grid;
903
+ place-items: center;
904
+ width: 32px;
905
+ height: 32px;
906
+ border-radius: 999px;
907
+ background: var(--_accent);
908
+ color: var(--_accent-text);
909
+ }
910
+ .stop {
911
+ flex: none;
912
+ display: inline-flex;
913
+ align-items: center;
914
+ gap: 6px;
915
+ height: 32px;
916
+ padding: 0 10px;
917
+ border-radius: var(--_radius-sm);
918
+ background: var(--_muted-surface);
919
+ font-size: 12px;
920
+ font-weight: 500;
921
+ }
922
+ .stop .square {
923
+ width: 9px;
924
+ height: 9px;
925
+ border-radius: 2px;
926
+ background: currentColor;
927
+ }
928
+ .footer {
929
+ display: flex;
930
+ align-items: center;
931
+ justify-content: center;
932
+ gap: 6px;
933
+ margin-top: 8px;
934
+ font-size: 11px;
935
+ color: var(--_muted);
936
+ text-align: center;
937
+ }
938
+ .footer .ghuri {
939
+ display: inline-flex;
940
+ align-items: center;
941
+ gap: 4px;
942
+ font-weight: 500;
943
+ white-space: nowrap;
944
+ }
945
+
946
+ /* --- empty state and history --- */
947
+ .empty {
948
+ display: flex;
949
+ flex-direction: column;
950
+ align-items: center;
951
+ gap: 10px;
952
+ padding: 32px 16px;
953
+ }
954
+ .empty .avatar {
955
+ width: 44px;
956
+ height: 44px;
957
+ border-radius: 12px;
958
+ }
959
+ .empty .heading {
960
+ font-size: 16px;
961
+ font-weight: 600;
962
+ }
963
+ .starters {
964
+ display: flex;
965
+ flex-direction: column;
966
+ gap: 8px;
967
+ width: 100%;
968
+ max-width: 420px;
969
+ }
970
+ .starter {
971
+ text-align: left;
972
+ padding: 9px 12px;
973
+ border: 1px solid var(--_border);
974
+ border-radius: var(--_radius-sm);
975
+ color: var(--_text);
976
+ font-size: 13px;
977
+ }
978
+ .starter:hover {
979
+ background: var(--_muted-surface);
980
+ }
981
+ .history {
982
+ display: flex;
983
+ flex-direction: column;
984
+ gap: 2px;
985
+ }
986
+ .history-head {
987
+ display: flex;
988
+ align-items: center;
989
+ justify-content: space-between;
990
+ padding: 12px 16px 6px;
991
+ font-weight: 600;
992
+ }
993
+ .conversation {
994
+ display: flex;
995
+ flex-direction: column;
996
+ gap: 1px;
997
+ text-align: left;
998
+ padding: 8px 10px;
999
+ border-radius: var(--_radius-sm);
1000
+ min-width: 0;
1001
+ }
1002
+ .conversation:hover,
1003
+ .conversation[aria-current='true'] {
1004
+ background: var(--_muted-surface);
1005
+ }
1006
+ .conversation .name {
1007
+ font-size: 13px;
1008
+ white-space: nowrap;
1009
+ overflow: hidden;
1010
+ text-overflow: ellipsis;
1011
+ }
1012
+ .conversation .when {
1013
+ font-size: 11px;
1014
+ color: var(--_muted);
1015
+ }
1016
+ .panel-history {
1017
+ padding: 0 8px 12px;
1018
+ }
1019
+ .side-brand {
1020
+ display: flex;
1021
+ align-items: center;
1022
+ gap: 8px;
1023
+ padding: 6px;
1024
+ font-weight: 600;
1025
+ font-size: 15px;
1026
+ }
1027
+ .new-chat {
1028
+ display: flex;
1029
+ align-items: center;
1030
+ gap: 8px;
1031
+ padding: 9px 10px;
1032
+ border: 1px solid var(--_border);
1033
+ border-radius: var(--_radius-sm);
1034
+ background: var(--_surface);
1035
+ font-weight: 500;
1036
+ font-size: 13px;
1037
+ }
1038
+ .muted {
1039
+ color: var(--_muted);
1040
+ font-size: 13px;
1041
+ padding: 8px 10px;
1042
+ }
1043
+ .page-head {
1044
+ display: flex;
1045
+ align-items: center;
1046
+ justify-content: space-between;
1047
+ padding: 12px 20px;
1048
+ font-weight: 500;
1049
+ min-height: 48px;
1050
+ }
1051
+ `, k = "result was not recorded", A = class extends t {
1052
+ static styles = O;
1053
+ static properties = {
1054
+ layout: {
1055
+ type: String,
1056
+ reflect: !0
1057
+ },
1058
+ open: {
1059
+ type: Boolean,
1060
+ reflect: !0
1061
+ },
1062
+ locale: { type: String },
1063
+ heading: { type: String },
1064
+ subtitle: { type: String },
1065
+ state: { state: !0 },
1066
+ view: { state: !0 },
1067
+ conversations: { state: !0 },
1068
+ draft: { state: !0 },
1069
+ expanded: { state: !0 },
1070
+ unticked: { state: !0 }
1071
+ };
1072
+ chat = null;
1073
+ options = null;
1074
+ unsubscribe = [];
1075
+ cards = /* @__PURE__ */ new Map();
1076
+ cardSeq = 0;
1077
+ stickToBottom = !0;
1078
+ onBeforeUnload = (e) => {
1079
+ e.preventDefault(), e.returnValue = this.labels.leaveWarning;
1080
+ };
1081
+ guarding = !1;
1082
+ constructor() {
1083
+ 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();
1084
+ }
1085
+ configure(t) {
1086
+ 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);
1087
+ let n = new e(t);
1088
+ this.chat = n, this.state = n.getState(), this.unsubscribe = [n.subscribe((e) => {
1089
+ this.state = e, this.guardUnload(e.status === "sending" || e.status === "streaming");
1090
+ }), ...[
1091
+ "tool-result",
1092
+ "approval-pending",
1093
+ "turn-end"
1094
+ ].map((e) => n.on(e, (t) => this.fire(e, t)))], this.layout === "page" && this.loadConversations();
1095
+ }
1096
+ setOptions(e) {
1097
+ if (this.options) {
1098
+ this.options = {
1099
+ ...this.options,
1100
+ ...e
1101
+ }, 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);
1102
+ for (let e of this.cards.values()) e.drawn = void 0;
1103
+ this.layout === "page" && this.conversations === null && this.loadConversations(), this.requestUpdate();
1104
+ }
1105
+ }
1106
+ get client() {
1107
+ return this.chat;
1108
+ }
1109
+ show() {
1110
+ this.open || (this.open = !0, this.fire("open", {}), this.updateComplete.then(() => this.focusInput()));
1111
+ }
1112
+ hide() {
1113
+ this.open && (this.open = !1, this.fire("close", {}));
1114
+ }
1115
+ toggle() {
1116
+ this.open ? this.hide() : this.show();
1117
+ }
1118
+ async ask(e, t = {}) {
1119
+ this.show(), this.view = "chat", t.send === !1 ? (this.draft = e, await this.updateComplete, this.focusInput()) : await this.chat?.send(e);
1120
+ }
1121
+ newConversation() {
1122
+ this.chat?.newConversation(), this.view = "chat", this.expanded = /* @__PURE__ */ new Set(), this.unticked = /* @__PURE__ */ new Set(), this.updateComplete.then(() => this.focusInput());
1123
+ }
1124
+ async openConversation(e) {
1125
+ this.view = "chat", await this.chat?.openConversation(e);
1126
+ }
1127
+ async end() {
1128
+ await this.chat?.end(), this.conversations = null;
1129
+ }
1130
+ disconnectedCallback() {
1131
+ super.disconnectedCallback(), this.guardUnload(!1);
1132
+ for (let e of this.cards.values()) e.cleanup?.(), e.container.remove();
1133
+ this.cards.clear();
1134
+ }
1135
+ detach() {
1136
+ for (let e of this.unsubscribe) e();
1137
+ this.unsubscribe = [];
1138
+ }
1139
+ get labels() {
1140
+ return y(this.locale || this.options?.locale || document.documentElement.lang || "en", this.options?.labels);
1141
+ }
1142
+ fire(e, t) {
1143
+ this.dispatchEvent(new CustomEvent(`ghuri:${e}`, {
1144
+ detail: t,
1145
+ bubbles: !0,
1146
+ composed: !0
1147
+ }));
1148
+ }
1149
+ guardUnload(e) {
1150
+ e !== this.guarding && (this.guarding = e, e ? window.addEventListener("beforeunload", this.onBeforeUnload) : window.removeEventListener("beforeunload", this.onBeforeUnload));
1151
+ }
1152
+ focusInput() {
1153
+ this.renderRoot.querySelector("textarea")?.focus();
1154
+ }
1155
+ willUpdate(e) {
1156
+ if (e.has("state")) {
1157
+ let e = this.renderRoot.querySelector(".scroll");
1158
+ this.stickToBottom = !e || e.scrollHeight - e.scrollTop - e.clientHeight < 80;
1159
+ }
1160
+ }
1161
+ updated() {
1162
+ if (this.stickToBottom) {
1163
+ let e = this.renderRoot.querySelector(".scroll");
1164
+ e && (e.scrollTop = e.scrollHeight);
1165
+ }
1166
+ this.mountCards();
1167
+ }
1168
+ async loadConversations() {
1169
+ if (this.chat) try {
1170
+ this.conversations = (await this.chat.listConversations({ limit: 50 })).results;
1171
+ } catch {
1172
+ this.conversations = [];
1173
+ }
1174
+ }
1175
+ async submit() {
1176
+ let e = this.draft.trim(), t = this.state?.status;
1177
+ if (!e || !this.chat || t === "sending" || t === "streaming") return;
1178
+ this.draft = "", this.stickToBottom = !0;
1179
+ let n = !this.state?.conversationId;
1180
+ await this.chat.send(e), n && this.layout === "page" && this.loadConversations();
1181
+ }
1182
+ onKeydown(e) {
1183
+ e.key !== "Enter" || e.shiftKey || e.isComposing || e.keyCode === 229 || (e.preventDefault(), this.submit());
1184
+ }
1185
+ onInput(e) {
1186
+ let t = e.target;
1187
+ this.draft = t.value, t.style.height = "auto", t.style.height = `${Math.min(t.scrollHeight, 180)}px`;
1188
+ }
1189
+ toggleRows(e) {
1190
+ let t = new Set(this.expanded);
1191
+ t.has(e) ? t.delete(e) : t.add(e), this.expanded = t;
1192
+ }
1193
+ tick(e, t) {
1194
+ let n = new Set(this.unticked);
1195
+ t ? n.delete(e) : n.add(e), this.unticked = n;
1196
+ }
1197
+ async decideAll(e) {
1198
+ let t = this.state?.pendingApprovals ?? [];
1199
+ this.chat && t.length && (await this.chat.decide(t.map((t) => ({
1200
+ approvalId: t.approvalId,
1201
+ approved: e && !this.unticked.has(t.approvalId)
1202
+ }))), this.unticked = /* @__PURE__ */ new Set());
1203
+ }
1204
+ async showHistory() {
1205
+ this.view = this.view === "history" ? "chat" : "history", this.view === "history" && await this.loadConversations();
1206
+ }
1207
+ wanted = /* @__PURE__ */ new Map();
1208
+ cardSlot(e, t, n) {
1209
+ let i = this.cards.get(e);
1210
+ if (!i) {
1211
+ let t = document.createElement("div");
1212
+ t.slot = `ghuri-card-${++this.cardSeq}`, t.dataset.ghuriCard = e, this.appendChild(t), i = { container: t }, this.cards.set(e, i);
1213
+ }
1214
+ return this.wanted.set(e, {
1215
+ slot: i.container.slot,
1216
+ ctx: t,
1217
+ render: n
1218
+ }), r`<slot name=${i.container.slot}></slot>`;
1219
+ }
1220
+ mountCards() {
1221
+ for (let [e, t] of this.cards) {
1222
+ let n = this.wanted.get(e);
1223
+ if (!n) {
1224
+ t.cleanup?.(), t.container.remove(), this.cards.delete(e);
1225
+ continue;
1226
+ }
1227
+ let r = n.ctx.part, i = `${r.state}|${r.approvalId ?? ""}|${n.ctx.approval ? "confirm" : "result"}`;
1228
+ if (t.drawn === i) continue;
1229
+ t.drawn = i;
1230
+ let a = n.render(t.container, n.ctx);
1231
+ typeof a == "function" && (t.cleanup = a);
1232
+ }
1233
+ }
1234
+ render() {
1235
+ return this.wanted = /* @__PURE__ */ new Map(), this.layout === "page" ? r`<div class="page">
1236
+ <aside class="sidebar" part="history">${this.renderSidebar()}</aside>
1237
+ <section class="main">
1238
+ <div class="page-head" part="header">
1239
+ <span class="title">${this.currentTitle()}</span>
1240
+ <span class="subtitle">${this.subtitle}</span>
1241
+ </div>
1242
+ ${this.renderScroll()} ${this.renderBottom()}
1243
+ </section>
1244
+ </div>` : r`${this.renderHeader()}
1245
+ ${this.view === "history" ? this.renderPanelHistory() : r`${this.renderScroll()} ${this.renderBottom()}`}`;
1246
+ }
1247
+ currentTitle() {
1248
+ let e = this.state?.conversationId;
1249
+ return this.conversations?.find((t) => t.id === e)?.title ?? "";
1250
+ }
1251
+ renderHeader() {
1252
+ let e = this.labels;
1253
+ return r`<header class="header" part="header">
1254
+ <div class="brand">
1255
+ <span class="avatar">${f(20)}</span>
1256
+ <span class="names">
1257
+ <span class="title" part="title">${this.heading || "Ghuri AI"}</span>
1258
+ ${this.subtitle ? r`<span class="subtitle">${this.subtitle}</span>` : i}
1259
+ </span>
1260
+ </div>
1261
+ <div class="tools">
1262
+ <button class="icon-button" title=${e.history} aria-label=${e.history} @click=${() => this.showHistory()}>
1263
+ ${m("history")}
1264
+ </button>
1265
+ <button class="icon-button" title=${e.newChat} aria-label=${e.newChat} @click=${() => this.newConversation()}>
1266
+ ${m("square-pen")}
1267
+ </button>
1268
+ <button class="icon-button" title=${e.close} aria-label=${e.close} @click=${() => this.hide()}>
1269
+ ${m("x")}
1270
+ </button>
1271
+ </div>
1272
+ </header>`;
1273
+ }
1274
+ renderConversationList() {
1275
+ let e = this.labels;
1276
+ if (this.conversations === null) return r`<div class="muted">${e.loading}</div>`;
1277
+ if (!this.conversations.length) return r`<div class="muted">${e.noConversations}</div>`;
1278
+ let t = new Intl.DateTimeFormat(this.locale || void 0, {
1279
+ dateStyle: "medium",
1280
+ timeStyle: "short"
1281
+ });
1282
+ return r`<nav class="history" aria-label=${e.conversations}>
1283
+ ${this.conversations.map((e) => r`<button
1284
+ class="conversation"
1285
+ aria-current=${e.id === this.state?.conversationId ? "true" : "false"}
1286
+ @click=${() => this.openConversation(e.id)}
1287
+ >
1288
+ <span class="name">${e.title || "—"}</span>
1289
+ <span class="when">${t.format(new Date(e.updatedAt))}</span>
1290
+ </button>`)}
1291
+ </nav>`;
1292
+ }
1293
+ renderPanelHistory() {
1294
+ let e = this.labels;
1295
+ return r`<div class="scroll">
1296
+ <div class="history-head">
1297
+ <span>${e.conversations}</span>
1298
+ <button class="btn primary" @click=${() => this.newConversation()}>${e.newChat}</button>
1299
+ </div>
1300
+ <div class="panel-history" part="history">${this.renderConversationList()}</div>
1301
+ </div>`;
1302
+ }
1303
+ renderSidebar() {
1304
+ let e = this.labels;
1305
+ return r`<div class="side-brand">${f(24)}<span>${this.heading || "Ghuri AI"}</span></div>
1306
+ <button class="new-chat" @click=${() => this.newConversation()}>${m("square-pen", 15)} ${e.newChat}</button>
1307
+ ${this.renderConversationList()}`;
1308
+ }
1309
+ renderScroll() {
1310
+ 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))}
1311
+ ${this.renderPending()}` : this.renderEmpty();
1312
+ return r`<div class="scroll">
1313
+ <div class="messages column" role="log" aria-live="polite" aria-busy=${e?.status === "streaming"}>${n}</div>
1314
+ </div>`;
1315
+ }
1316
+ renderEmpty() {
1317
+ let e = this.labels, t = this.options?.starters ?? [];
1318
+ return r`<div class="empty" part="empty">
1319
+ <span class="avatar">${f(24)}</span>
1320
+ <span class="heading">${e.emptyTitle}</span>
1321
+ ${t.length ? r`<div class="starters">
1322
+ ${t.map((e) => r`<button class="starter" part="starter" @click=${() => this.chat?.send(e)}>${e}</button>`)}
1323
+ </div>` : i}
1324
+ </div>`;
1325
+ }
1326
+ renderMessage(e, t) {
1327
+ if (e.role === "user") {
1328
+ let t = e.parts.map((e) => e.kind === "text" ? e.text : "").join("");
1329
+ return r`<div class="user" part="user-bubble">${t}</div>`;
1330
+ }
1331
+ let n = t && this.state?.status === "streaming", a = e.parts.map((t, a) => {
1332
+ if (t.kind === "text") {
1333
+ if (!t.text) return i;
1334
+ let o = n && a === e.parts.length - 1;
1335
+ return r`<div class="md" part="assistant">${D(t.text)}${o ? r`<span class="caret"></span>` : i}</div>`;
1336
+ }
1337
+ return this.renderTool(t);
1338
+ }), o = n && !e.parts.length, s = r`<div class="assistant">
1339
+ ${a}
1340
+ ${o ? r`<span class="step" part="tool-step">${m("loader", 13)}<span>${this.labels.running}</span></span>` : i}
1341
+ </div>`;
1342
+ return this.layout === "page" ? r`<div class="assistant-row"><span class="avatar">${f(18)}</span>${s}</div>` : s;
1343
+ }
1344
+ toolLabel(e) {
1345
+ return e.title || c(e.toolName);
1346
+ }
1347
+ renderTool(e) {
1348
+ let t = this.labels;
1349
+ if (e.state === "awaiting-approval") return i;
1350
+ if (e.approvalId) {
1351
+ let [n, i, a] = e.state === "done" ? [
1352
+ "done",
1353
+ "circle-check",
1354
+ t.confirmed
1355
+ ] : e.state === "denied" ? [
1356
+ "denied",
1357
+ "circle-x",
1358
+ t.cancelled
1359
+ ] : e.state === "error" ? [
1360
+ "error",
1361
+ "circle-alert",
1362
+ e.errorText?.includes(k) ? t.outcomeUnknown : t.stepFailed
1363
+ ] : [
1364
+ "denied",
1365
+ "loader",
1366
+ t.running
1367
+ ];
1368
+ return r`<div class="decided" part="decided" title=${e.state === "error" ? e.errorText ?? "" : ""}>
1369
+ <span class="what"><span class=${n}>${m(i, 15)}</span>${this.toolLabel(e)}</span>
1370
+ <span class=${n}>${a}</span>
1371
+ </div>`;
1372
+ }
1373
+ let n = this.options?.cards?.[e.toolName]?.result;
1374
+ if (n && e.state === "done" && this.chat) return this.cardSlot(`result:${e.toolCallId}`, {
1375
+ part: e,
1376
+ client: this.chat
1377
+ }, n);
1378
+ if (this.options?.toolSteps === "hide") return i;
1379
+ 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>`;
1380
+ return r`<span class="step" part="tool-step" title=${e.state === "error" ? e.errorText ?? "" : ""}>
1381
+ ${o}<span>${this.toolLabel(e)}${a === null ? "" : ` · ${t.found(a)}`}</span>
1382
+ </span>`;
1383
+ }
1384
+ renderRows(e, t) {
1385
+ let n = this.labels, a = u(t), o = this.expanded.has(e), s = a.some((e) => e.value.length > 160);
1386
+ return r`<div class="rows">
1387
+ ${a.map((e) => r`<div class="row">
1388
+ <span class="label">${e.label}</span>
1389
+ <span class="value">${!o && e.value.length > 160 ? `${e.value.slice(0, 160)}…` : e.value}</span>
1390
+ </div>`)}
1391
+ ${s ? r`<button class="link" @click=${() => this.toggleRows(e)}>${o ? n.showLess : n.showMore}</button>` : i}
1392
+ </div>`;
1393
+ }
1394
+ renderPending() {
1395
+ let e = this.state?.pendingApprovals ?? [];
1396
+ if (!e.length || this.state?.status !== "awaiting-approval") return i;
1397
+ let t = this.labels;
1398
+ if (e.length === 1) {
1399
+ let n = e[0], i = this.options?.cards?.[n.toolName]?.confirm, a = {
1400
+ kind: "tool",
1401
+ toolCallId: n.toolCallId,
1402
+ toolName: n.toolName,
1403
+ ...n.title ? { title: n.title } : {},
1404
+ input: n.input,
1405
+ state: "awaiting-approval",
1406
+ approvalId: n.approvalId
1407
+ };
1408
+ if (i && this.chat) {
1409
+ let e = this.chat;
1410
+ return this.cardSlot(`confirm:${n.approvalId}`, {
1411
+ part: a,
1412
+ approval: n,
1413
+ client: e,
1414
+ decide: (t, r) => e.decide([{
1415
+ approvalId: n.approvalId,
1416
+ approved: t,
1417
+ ...r ? { reason: r } : {}
1418
+ }])
1419
+ }, i);
1420
+ }
1421
+ return r`<div class="confirm" part="confirm-card" role="group" aria-label=${this.toolLabel(n)}>
1422
+ <div class="confirm-head" part="confirm-header">
1423
+ <span class="what">${m("pencil-line", 15)} ${this.toolLabel(n)}</span>
1424
+ <span class="badge">${t.needsOk}</span>
1425
+ </div>
1426
+ ${this.renderRows(n.approvalId, n.input)}
1427
+ <div class="confirm-foot">
1428
+ <span class="hint">${t.exactValues}</span>
1429
+ <span class="buttons">
1430
+ <button class="btn secondary" part="button-secondary" @click=${() => this.decideAll(!1)}>${t.cancel}</button>
1431
+ <button class="btn primary" part="button-primary" @click=${() => this.decideAll(!0)}>${t.confirm}</button>
1432
+ </span>
1433
+ </div>
1434
+ </div>`;
1435
+ }
1436
+ let n = e.filter((e) => !this.unticked.has(e.approvalId)).length;
1437
+ return r`<div class="confirm" part="confirm-card" role="group" aria-label=${t.changes(e.length)}>
1438
+ <div class="confirm-head" part="confirm-header">
1439
+ <span class="what">${t.changes(e.length)}</span>
1440
+ <span class="badge">${t.needsOk}</span>
1441
+ </div>
1442
+ ${e.map((e) => {
1443
+ let n = u(e.input), i = this.expanded.has(e.approvalId);
1444
+ return r`<div class="item">
1445
+ <input
1446
+ type="checkbox"
1447
+ aria-label=${this.toolLabel(e)}
1448
+ .checked=${!this.unticked.has(e.approvalId)}
1449
+ @change=${(t) => this.tick(e.approvalId, t.target.checked)}
1450
+ />
1451
+ <span class="body">
1452
+ <span class="name">${this.toolLabel(e)}</span>
1453
+ ${i ? this.renderRows(`${e.approvalId}:all`, e.input) : r`<span class="summary">${n.slice(0, 2).map((e) => `${e.label} ${e.value}`).join(" · ")}</span>`}
1454
+ <button class="link" style="align-self:flex-start" @click=${() => this.toggleRows(e.approvalId)}>
1455
+ ${i ? t.showLess : t.showMore}
1456
+ </button>
1457
+ </span>
1458
+ </div>`;
1459
+ })}
1460
+ <div class="confirm-foot">
1461
+ <span class="hint">${t.unticked}</span>
1462
+ <span class="buttons">
1463
+ <button class="btn secondary" part="button-secondary" @click=${() => this.decideAll(!1)}>${t.cancelAll}</button>
1464
+ <button class="btn primary" part="button-primary" ?disabled=${!n} @click=${() => this.decideAll(!0)}>
1465
+ ${t.confirmN(n)}
1466
+ </button>
1467
+ </span>
1468
+ </div>
1469
+ </div>`;
1470
+ }
1471
+ renderProblem(e) {
1472
+ 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 = {
1473
+ reconnecting: "refresh-cw",
1474
+ "token-expired": "refresh-cw",
1475
+ "in-progress": "clock",
1476
+ throttled: "clock",
1477
+ "conversation-full": "messages-square",
1478
+ "store-unreachable": "plug-zap",
1479
+ "cut-off": "wifi-off",
1480
+ unavailable: "wifi-off"
1481
+ }, 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>`;
1482
+ return r`<div class=${`problem ${o}`} part="problem" role="status">
1483
+ <span class=${e.code === "reconnecting" ? "icon spin" : "icon"}>${m(s[e.code] ?? "circle-alert", 16)}</span>
1484
+ <span class="body">
1485
+ <span class="head">${n.title}</span>
1486
+ <span>${e.code === "failed" && e.message ? e.message : n.text(e.retryAfter)}</span>
1487
+ <span class="actions">${c}${l}</span>
1488
+ </span>
1489
+ </div>`;
1490
+ }
1491
+ renderBottom() {
1492
+ let e = this.labels, t = this.state, n = t?.status === "sending" || t?.status === "streaming", a = t?.status === "awaiting-approval";
1493
+ return r`${t?.problem ? r`<div class="column">${this.renderProblem(t.problem)}</div>` : i}
1494
+ <div class="composer column" part="composer">
1495
+ <div class="box">
1496
+ <label class="sr-only" for="input">${e.placeholder}</label>
1497
+ <textarea
1498
+ id="input"
1499
+ part="input"
1500
+ rows="1"
1501
+ lang=${this.locale || i}
1502
+ placeholder=${e.placeholder}
1503
+ .value=${this.draft}
1504
+ ?disabled=${!this.chat}
1505
+ @input=${this.onInput}
1506
+ @keydown=${this.onKeydown}
1507
+ ></textarea>
1508
+ ${n ? r`<button class="stop" part="stop" @click=${() => this.chat?.stop()}>
1509
+ <span class="square"></span>${e.stop}
1510
+ </button>` : r`<button
1511
+ class="send"
1512
+ part="send"
1513
+ aria-label=${e.send}
1514
+ title=${e.send}
1515
+ ?disabled=${!this.draft.trim() || !this.chat}
1516
+ @click=${() => this.submit()}
1517
+ >
1518
+ ${m("arrow-up", 17)}
1519
+ </button>`}
1520
+ </div>
1521
+ <div class="footer">
1522
+ <span class="ghuri">${f(12)} Ghuri AI</span>
1523
+ <span>· ${a ? e.newMessageCancels : e.footer}</span>
1524
+ </div>
1525
+ </div>`;
1526
+ }
1527
+ };
1528
+ // src/index.ts
1529
+ typeof customElements < "u" && !customElements.get("ghuri-chat") && customElements.define("ghuri-chat", A);
1530
+ export { A as t };
1531
+
1532
+ //# sourceMappingURL=src-DcFnX61O.js.map