@ourguide-ai/client 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,86 +1,87 @@
1
- function K(e) {
2
- return new Promise((t, s) => {
3
- const n = new FileReader();
4
- n.onload = () => {
5
- const o = n.result;
6
- t(o.split(",")[1]);
7
- }, n.onerror = () => s(new Error("Failed to read file")), n.readAsDataURL(e);
1
+ function Y(e) {
2
+ return new Promise((t, n) => {
3
+ const s = new FileReader();
4
+ s.onload = () => {
5
+ const r = s.result;
6
+ t(r.split(",")[1]);
7
+ }, s.onerror = () => n(new Error("Failed to read file")), s.readAsDataURL(e);
8
8
  });
9
9
  }
10
- async function Y(e, t) {
11
- const s = `${e}/api/products/${t}/config`;
12
- console.log("[Ourguide] fetchConfig HTTP GET", s);
10
+ async function Q(e, t) {
11
+ const n = `${e}/api/products/${t}/config`;
12
+ console.log("[Ourguide] fetchConfig HTTP GET", n);
13
13
  try {
14
- const n = await fetch(s, {
14
+ const s = await fetch(n, {
15
15
  headers: { "ngrok-skip-browser-warning": "true" }
16
16
  });
17
- if (console.log("[Ourguide] fetchConfig HTTP status:", n.status, n.statusText), !n.ok)
17
+ if (console.log("[Ourguide] fetchConfig HTTP status:", s.status, s.statusText), !s.ok)
18
18
  return console.warn("[Ourguide] fetchConfig non-OK response, returning {}"), {};
19
- const o = await n.json();
20
- return console.log("[Ourguide] fetchConfig raw JSON:", JSON.stringify(o, null, 2)), o;
21
- } catch (n) {
22
- return console.error("[Ourguide] fetchConfig threw:", n), {};
19
+ const r = await s.json();
20
+ return console.log("[Ourguide] fetchConfig raw JSON:", JSON.stringify(r, null, 2)), r;
21
+ } catch (s) {
22
+ return console.error("[Ourguide] fetchConfig threw:", s), {};
23
23
  }
24
24
  }
25
- async function H(e, t, s, n, o, r) {
26
- const i = { productId: t, messages: s, endUserSessionId: n };
27
- o && (i.conversationId = o), r && r.length > 0 && (i.attachments = r);
28
- const l = await fetch(`${e}/api/chat`, {
25
+ async function B(e, t, n, s, r, o, i) {
26
+ const l = { productId: t, messages: n, endUserSessionId: s };
27
+ r && (l.conversationId = r), o && o.length > 0 && (l.attachments = o);
28
+ const a = await fetch(`${e}/api/chat`, {
29
29
  method: "POST",
30
30
  headers: {
31
31
  "Content-Type": "application/json",
32
32
  "ngrok-skip-browser-warning": "true"
33
33
  },
34
- body: JSON.stringify(i)
34
+ body: JSON.stringify(l),
35
+ signal: i
35
36
  });
36
- if (!l.ok) {
37
- const a = await l.json().catch(() => ({ error: "Request failed" }));
38
- throw new Error(a.error || `HTTP ${l.status}`);
37
+ if (!a.ok) {
38
+ const S = await a.json().catch(() => ({ error: "Request failed" }));
39
+ throw new Error(S.error || `HTTP ${a.status}`);
39
40
  }
40
- if (!l.body)
41
+ if (!a.body)
41
42
  throw new Error("No response stream available");
42
43
  return {
43
- stream: l.body,
44
- conversationId: l.headers.get("X-Conversation-Id")
44
+ stream: a.body,
45
+ conversationId: a.headers.get("X-Conversation-Id")
45
46
  };
46
47
  }
47
- async function Q(e, t, s, n, o) {
48
- const r = await fetch(`${e}/api/widget/identify`, {
48
+ async function Z(e, t, n, s, r) {
49
+ const o = await fetch(`${e}/api/widget/identify`, {
49
50
  method: "POST",
50
51
  headers: {
51
52
  "Content-Type": "application/json",
52
53
  "ngrok-skip-browser-warning": "true"
53
54
  },
54
- body: JSON.stringify({ productId: t, endUserSessionId: s, token: n, name: o })
55
- }), i = await r.json().catch(() => ({}));
56
- if (!r.ok)
57
- throw new Error(i.error || `HTTP ${r.status}`);
55
+ body: JSON.stringify({ productId: t, endUserSessionId: n, token: s, name: r })
56
+ }), i = await o.json().catch(() => ({}));
57
+ if (!o.ok)
58
+ throw new Error(i.error || `HTTP ${o.status}`);
58
59
  return i;
59
60
  }
60
- async function Z(e, t, s) {
61
- const n = await fetch(`${e}/api/widget/reset-user`, {
61
+ async function tt(e, t, n) {
62
+ const s = await fetch(`${e}/api/widget/reset-user`, {
62
63
  method: "POST",
63
64
  headers: {
64
65
  "Content-Type": "application/json",
65
66
  "ngrok-skip-browser-warning": "true"
66
67
  },
67
- body: JSON.stringify({ productId: t, endUserSessionId: s })
68
- }), o = await n.json().catch(() => ({}));
69
- if (!n.ok)
70
- throw new Error(o.error || `HTTP ${n.status}`);
71
- return o;
68
+ body: JSON.stringify({ productId: t, endUserSessionId: n })
69
+ }), r = await s.json().catch(() => ({}));
70
+ if (!s.ok)
71
+ throw new Error(r.error || `HTTP ${s.status}`);
72
+ return r;
72
73
  }
73
- const tt = {
74
+ const et = {
74
75
  isOpen: !1,
75
76
  messages: [],
76
77
  isStreaming: !1,
77
78
  error: null
78
79
  };
79
- function j() {
80
+ function G() {
80
81
  return Date.now().toString(36) + Math.random().toString(36).slice(2, 7);
81
82
  }
82
- function et(e, t) {
83
- var s;
83
+ function nt(e, t) {
84
+ var n;
84
85
  switch (t.type) {
85
86
  case "OPEN":
86
87
  return { ...e, isOpen: !0, error: null };
@@ -108,34 +109,34 @@ function et(e, t) {
108
109
  ]
109
110
  };
110
111
  case "APPEND_TEXT": {
111
- const n = [...e.messages], o = n[n.length - 1];
112
- return o && o.role === "assistant" && o.isStreaming && (n[n.length - 1] = { ...o, content: o.content + t.text }), { ...e, messages: n };
112
+ const s = [...e.messages], r = s[s.length - 1];
113
+ return r && r.role === "assistant" && r.isStreaming && (s[s.length - 1] = { ...r, content: r.content + t.text }), { ...e, messages: s };
113
114
  }
114
115
  case "ADD_TOOL_CALL": {
115
- const n = [...e.messages], o = n[n.length - 1];
116
- if (o && o.role === "assistant") {
117
- const r = [...o.toolCalls ?? [], t.toolCall];
118
- n[n.length - 1] = { ...o, toolCalls: r };
116
+ const s = [...e.messages], r = s[s.length - 1];
117
+ if (r && r.role === "assistant") {
118
+ const o = [...r.toolCalls ?? [], t.toolCall];
119
+ s[s.length - 1] = { ...r, toolCalls: o };
119
120
  }
120
- return { ...e, messages: n };
121
+ return { ...e, messages: s };
121
122
  }
122
123
  case "SET_TOOL_RESULT": {
123
- const n = [...e.messages], o = n[n.length - 1];
124
- if (o && o.role === "assistant" && o.toolCalls) {
125
- const r = o.toolCalls.map(
124
+ const s = [...e.messages], r = s[s.length - 1];
125
+ if (r && r.role === "assistant" && r.toolCalls) {
126
+ const o = r.toolCalls.map(
126
127
  (i) => i.id === t.toolCallId ? { ...i, result: t.result, status: "done" } : i
127
128
  );
128
- n[n.length - 1] = { ...o, toolCalls: r };
129
+ s[s.length - 1] = { ...r, toolCalls: o };
129
130
  }
130
- return { ...e, messages: n };
131
+ return { ...e, messages: s };
131
132
  }
132
133
  case "FINISH_STREAMING": {
133
- const n = [...e.messages], o = n[n.length - 1];
134
- return o && o.role === "assistant" && o.isStreaming && (!o.content && ((s = o.toolCalls) != null && s.length) ? n.pop() : n[n.length - 1] = { ...o, isStreaming: !1 }), { ...e, isStreaming: !1, messages: n };
134
+ const s = [...e.messages], r = s[s.length - 1];
135
+ return r && r.role === "assistant" && r.isStreaming && (!r.content && ((n = r.toolCalls) != null && n.length) ? s.pop() : s[s.length - 1] = { ...r, isStreaming: !1 }), { ...e, isStreaming: !1, messages: s };
135
136
  }
136
137
  case "SET_ERROR": {
137
- const n = [...e.messages], o = n[n.length - 1];
138
- return o && o.role === "assistant" && o.isStreaming && (n[n.length - 1] = { ...o, isStreaming: !1 }), { ...e, isStreaming: !1, error: t.error, messages: n };
138
+ const s = [...e.messages], r = s[s.length - 1];
139
+ return r && r.role === "assistant" && r.isStreaming && (s[s.length - 1] = { ...r, isStreaming: !1 }), { ...e, isStreaming: !1, error: t.error, messages: s };
139
140
  }
140
141
  case "CLEAR_MESSAGES":
141
142
  return { ...e, messages: [], error: null, isStreaming: !1 };
@@ -143,70 +144,70 @@ function et(e, t) {
143
144
  return e;
144
145
  }
145
146
  }
146
- async function B(e, t) {
147
- const s = e.getReader(), n = new TextDecoder();
148
- let o = "";
147
+ async function F(e, t) {
148
+ const n = e.getReader(), s = new TextDecoder();
149
+ let r = "";
149
150
  try {
150
151
  for (; ; ) {
151
- const { done: r, value: i } = await s.read();
152
- if (o += r ? n.decode() : n.decode(i, { stream: !0 }), r) break;
153
- const l = o.split(`
152
+ const { done: o, value: i } = await n.read();
153
+ if (r += o ? s.decode() : s.decode(i, { stream: !0 }), o) break;
154
+ const l = r.split(`
154
155
 
155
156
  `);
156
- o = l.pop() ?? "";
157
+ r = l.pop() ?? "";
157
158
  for (const a of l)
158
- G(a.trim(), t);
159
+ z(a.trim(), t);
159
160
  }
160
- o.trim() && G(o.trim(), t), t.onFinish();
161
- } catch (r) {
162
- const i = r instanceof Error ? r.message : "Stream read failed";
161
+ r.trim() && z(r.trim(), t), t.onFinish();
162
+ } catch (o) {
163
+ const i = o instanceof Error ? o.message : "Stream read failed";
163
164
  t.onError(i);
164
165
  } finally {
165
- s.releaseLock();
166
+ n.releaseLock();
166
167
  }
167
168
  }
168
- function G(e, t) {
169
- const s = e.split(`
169
+ function z(e, t) {
170
+ const n = e.split(`
170
171
  `);
171
- for (const n of s) {
172
- if (!n.startsWith("data: ")) continue;
173
- const o = n.slice(6);
174
- if (o === "[DONE]") return;
172
+ for (const s of n) {
173
+ if (!s.startsWith("data: ")) continue;
174
+ const r = s.slice(6);
175
+ if (r === "[DONE]") return;
175
176
  try {
176
- const r = JSON.parse(o);
177
- switch (r.type) {
177
+ const o = JSON.parse(r);
178
+ switch (o.type) {
178
179
  case "text-delta":
179
- r.delta && t.onTextDelta(r.delta);
180
+ o.delta && t.onTextDelta(o.delta);
180
181
  break;
181
182
  // AI SDK v6: tool-input-available fires when tool input is fully parsed
182
183
  case "tool-input-available":
183
- r.toolCallId && r.toolName && t.onToolCall(
184
- r.toolCallId,
185
- r.toolName,
186
- r.input ?? {},
187
- r.providerMetadata
184
+ o.toolCallId && o.toolName && t.onToolCall(
185
+ o.toolCallId,
186
+ o.toolName,
187
+ o.input ?? {},
188
+ o.providerMetadata
188
189
  );
189
190
  break;
190
191
  // AI SDK v6: tool-output-available fires when tool execution completes
191
192
  case "tool-output-available":
192
- r.toolCallId && t.onToolResult(r.toolCallId, r.output);
193
+ o.toolCallId && t.onToolResult(o.toolCallId, o.output);
193
194
  break;
194
195
  // Legacy event names (AI SDK v5 compat)
195
196
  case "tool-call":
196
- r.toolCallId && r.toolName && t.onToolCall(
197
- r.toolCallId,
198
- r.toolName,
199
- r.input ?? {}
197
+ o.toolCallId && o.toolName && t.onToolCall(
198
+ o.toolCallId,
199
+ o.toolName,
200
+ o.input ?? {}
200
201
  );
201
202
  break;
202
203
  case "tool-result":
203
- r.toolCallId && t.onToolResult(r.toolCallId, r.output);
204
+ o.toolCallId && t.onToolResult(o.toolCallId, o.output);
204
205
  break;
205
206
  case "error":
206
- t.onError(r.errorText ?? r.reason ?? "Unknown error");
207
+ t.onError(o.errorText ?? o.reason ?? "Unknown error");
207
208
  break;
208
209
  case "abort":
209
- t.onError(r.reason ?? "Response aborted");
210
+ t.onError(o.reason ?? "Response aborted");
210
211
  break;
211
212
  // Ignore: start, finish, text-start, text-end, start-step, finish-step,
212
213
  // tool-input-start, tool-input-delta
@@ -217,53 +218,137 @@ function G(e, t) {
217
218
  }
218
219
  }
219
220
  }
220
- const M = {};
221
- function F(e) {
221
+ const st = 10, rt = 30, R = 500, ot = "og2-widget-root", it = /* @__PURE__ */ new Set(["SCRIPT", "STYLE", "NOSCRIPT", "SVG", "NAV", "HEADER", "FOOTER"]), at = "a[href], button, input, select, textarea";
222
+ function N(e) {
223
+ if (!(e instanceof HTMLElement)) return !1;
224
+ if (typeof e.checkVisibility == "function")
225
+ return e.checkVisibility({ checkOpacity: !1, checkVisibilityCSS: !0 });
226
+ let t = e;
227
+ for (; t; ) {
228
+ if (t.hidden || t.getAttribute("aria-hidden") === "true") return !1;
229
+ const n = getComputedStyle(t);
230
+ if (n.display === "none" || n.visibility === "hidden") return !1;
231
+ t = t.parentElement;
232
+ }
233
+ return !0;
234
+ }
235
+ function x(e) {
236
+ return !!e.closest(`#${ot}`);
237
+ }
238
+ function ct(e) {
239
+ var n, s;
240
+ if (e instanceof HTMLInputElement || e instanceof HTMLSelectElement || e instanceof HTMLTextAreaElement) {
241
+ if (e.id) {
242
+ const r = document.querySelector(`label[for="${CSS.escape(e.id)}"]`);
243
+ if ((n = r == null ? void 0 : r.textContent) != null && n.trim()) return r.textContent.trim();
244
+ }
245
+ return e.getAttribute("aria-label") || e.placeholder || e.getAttribute("name") || "";
246
+ }
247
+ const t = (s = e.innerText) == null ? void 0 : s.trim();
248
+ return t || e.getAttribute("aria-label") || e.getAttribute("title") || "";
249
+ }
250
+ function X(e, t) {
251
+ return e.length <= t ? e : e.slice(0, t - 3) + "...";
252
+ }
253
+ function lt() {
254
+ var b;
255
+ const e = window.location.pathname + window.location.search, t = document.title || "", n = document.querySelectorAll("h1, h2, h3"), s = [];
256
+ for (const c of n) {
257
+ if (s.length >= st) break;
258
+ if (x(c) || !N(c)) continue;
259
+ const d = (b = c.innerText) == null ? void 0 : b.trim();
260
+ d && !s.includes(d) && s.push(d);
261
+ }
262
+ const r = document.querySelectorAll(at), o = [], i = /* @__PURE__ */ new Set();
263
+ for (const c of r) {
264
+ if (o.length >= rt) break;
265
+ if (x(c) || !N(c)) continue;
266
+ const d = ct(c);
267
+ if (!d) continue;
268
+ const T = `${c.tagName}:${d}`;
269
+ if (i.has(T)) continue;
270
+ i.add(T);
271
+ const m = {
272
+ tag: c.tagName.toLowerCase(),
273
+ text: X(d, 80)
274
+ };
275
+ if (c instanceof HTMLInputElement && (m.type = c.type), c instanceof HTMLAnchorElement && c.href)
276
+ try {
277
+ const C = new URL(c.href);
278
+ m.href = C.pathname + C.search;
279
+ } catch {
280
+ m.href = c.getAttribute("href") || void 0;
281
+ }
282
+ o.push(m);
283
+ }
284
+ const l = document.querySelector("main") || document.body;
285
+ let a = "";
286
+ function S(c) {
287
+ var T;
288
+ if (a.length >= R) return;
289
+ if (c.nodeType === Node.TEXT_NODE) {
290
+ const m = (T = c.textContent) == null ? void 0 : T.trim();
291
+ m && (a += (a ? " " : "") + m);
292
+ return;
293
+ }
294
+ if (c.nodeType !== Node.ELEMENT_NODE) return;
295
+ const d = c;
296
+ if (!it.has(d.tagName) && !x(d) && N(d)) {
297
+ for (const m of d.childNodes)
298
+ if (S(m), a.length >= R) return;
299
+ }
300
+ }
301
+ return S(l), a = X(a.replace(/\s+/g, " ").trim(), R), { url: e, title: t, headings: s, interactiveElements: o, visibleText: a };
302
+ }
303
+ const M = {
304
+ capture_screen: async () => lt()
305
+ };
306
+ function ut(e) {
222
307
  Object.assign(M, e);
223
308
  }
224
- function nt(e) {
309
+ function dt(e) {
225
310
  return M[e];
226
311
  }
227
- function st(e) {
312
+ function gt(e) {
228
313
  return Object.hasOwn(M, e);
229
314
  }
230
- const ot = "og2-chat-", rt = "og2-enduser-session-", L = "og2-conv-";
315
+ const ht = "og2-chat-", ft = "og2-enduser-session-", L = "og2-conv-";
231
316
  function D(e) {
232
- return `${ot}${e}`;
317
+ return `${ht}${e}`;
233
318
  }
234
- function q(e) {
235
- return `${rt}${e}`;
319
+ function W(e) {
320
+ return `${ft}${e}`;
236
321
  }
237
- function z() {
238
- var t, s;
239
- const e = (s = (t = globalThis.crypto) == null ? void 0 : t.randomUUID) == null ? void 0 : s.call(t);
322
+ function V() {
323
+ var t, n;
324
+ const e = (n = (t = globalThis.crypto) == null ? void 0 : t.randomUUID) == null ? void 0 : n.call(t);
240
325
  return e || `${Date.now()}-${Math.random().toString(16).slice(2)}`;
241
326
  }
242
- function R(e) {
243
- const t = q(e);
327
+ function A(e) {
328
+ const t = W(e);
244
329
  try {
245
- const s = localStorage.getItem(t);
246
- if (s && s.trim()) return s;
247
- const n = `sess_${z()}`;
248
- return localStorage.setItem(t, n), n;
330
+ const n = localStorage.getItem(t);
331
+ if (n && n.trim()) return n;
332
+ const s = `sess_${V()}`;
333
+ return localStorage.setItem(t, s), s;
249
334
  } catch {
250
- return `sess_${z()}`;
335
+ return `sess_${V()}`;
251
336
  }
252
337
  }
253
- function it(e) {
338
+ function pt(e) {
254
339
  try {
255
- localStorage.removeItem(q(e));
340
+ localStorage.removeItem(W(e));
256
341
  } catch {
257
342
  }
258
343
  }
259
- function at(e, t) {
344
+ function mt(e, t) {
260
345
  try {
261
- const s = t.map(({ isStreaming: n, ...o }) => o);
262
- sessionStorage.setItem(D(e), JSON.stringify(s));
346
+ const n = t.map(({ isStreaming: s, ...r }) => r);
347
+ sessionStorage.setItem(D(e), JSON.stringify(n));
263
348
  } catch {
264
349
  }
265
350
  }
266
- function ct(e) {
351
+ function St(e) {
267
352
  try {
268
353
  const t = sessionStorage.getItem(D(e));
269
354
  return t ? JSON.parse(t) : [];
@@ -271,160 +356,84 @@ function ct(e) {
271
356
  return [];
272
357
  }
273
358
  }
274
- function X(e) {
359
+ function J(e) {
275
360
  try {
276
361
  sessionStorage.removeItem(D(e)), sessionStorage.removeItem(`${L}${e}`);
277
362
  } catch {
278
363
  }
279
364
  }
280
- function lt(e, t) {
365
+ function yt(e, t) {
281
366
  try {
282
367
  sessionStorage.setItem(`${L}${e}`, t);
283
368
  } catch {
284
369
  }
285
370
  }
286
- function ut(e) {
371
+ function Et(e) {
287
372
  try {
288
373
  return sessionStorage.getItem(`${L}${e}`);
289
374
  } catch {
290
375
  return null;
291
376
  }
292
377
  }
293
- const dt = 10, gt = 30, x = 500, ht = "og2-widget-root", ft = /* @__PURE__ */ new Set(["SCRIPT", "STYLE", "NOSCRIPT", "SVG", "NAV", "HEADER", "FOOTER"]), pt = "a[href], button, input, select, textarea";
294
- function N(e) {
295
- if (!(e instanceof HTMLElement)) return !1;
296
- if (typeof e.checkVisibility == "function")
297
- return e.checkVisibility({ checkOpacity: !1, checkVisibilityCSS: !0 });
298
- let t = e;
299
- for (; t; ) {
300
- if (t.hidden || t.getAttribute("aria-hidden") === "true") return !1;
301
- const s = getComputedStyle(t);
302
- if (s.display === "none" || s.visibility === "hidden") return !1;
303
- t = t.parentElement;
304
- }
305
- return !0;
306
- }
307
- function A(e) {
308
- return !!e.closest(`#${ht}`);
309
- }
310
- function mt(e) {
311
- var s, n;
312
- if (e instanceof HTMLInputElement || e instanceof HTMLSelectElement || e instanceof HTMLTextAreaElement) {
313
- if (e.id) {
314
- const o = document.querySelector(`label[for="${CSS.escape(e.id)}"]`);
315
- if ((s = o == null ? void 0 : o.textContent) != null && s.trim()) return o.textContent.trim();
316
- }
317
- return e.getAttribute("aria-label") || e.placeholder || e.getAttribute("name") || "";
318
- }
319
- const t = (n = e.innerText) == null ? void 0 : n.trim();
320
- return t || e.getAttribute("aria-label") || e.getAttribute("title") || "";
321
- }
322
- function V(e, t) {
323
- return e.length <= t ? e : e.slice(0, t - 3) + "...";
324
- }
325
- function St() {
326
- var w;
327
- const e = window.location.pathname + window.location.search, t = document.title || "", s = document.querySelectorAll("h1, h2, h3"), n = [];
328
- for (const c of s) {
329
- if (n.length >= dt) break;
330
- if (A(c) || !N(c)) continue;
331
- const g = (w = c.innerText) == null ? void 0 : w.trim();
332
- g && !n.includes(g) && n.push(g);
333
- }
334
- const o = document.querySelectorAll(pt), r = [], i = /* @__PURE__ */ new Set();
335
- for (const c of o) {
336
- if (r.length >= gt) break;
337
- if (A(c) || !N(c)) continue;
338
- const g = mt(c);
339
- if (!g) continue;
340
- const E = `${c.tagName}:${g}`;
341
- if (i.has(E)) continue;
342
- i.add(E);
343
- const m = {
344
- tag: c.tagName.toLowerCase(),
345
- text: V(g, 80)
346
- };
347
- if (c instanceof HTMLInputElement && (m.type = c.type), c instanceof HTMLAnchorElement && c.href)
348
- try {
349
- const C = new URL(c.href);
350
- m.href = C.pathname + C.search;
351
- } catch {
352
- m.href = c.getAttribute("href") || void 0;
353
- }
354
- r.push(m);
355
- }
356
- const l = document.querySelector("main") || document.body;
357
- let a = "";
358
- function T(c) {
359
- var E;
360
- if (a.length >= x) return;
361
- if (c.nodeType === Node.TEXT_NODE) {
362
- const m = (E = c.textContent) == null ? void 0 : E.trim();
363
- m && (a += (a ? " " : "") + m);
364
- return;
365
- }
366
- if (c.nodeType !== Node.ELEMENT_NODE) return;
367
- const g = c;
368
- if (!ft.has(g.tagName) && !A(g) && N(g)) {
369
- for (const m of g.childNodes)
370
- if (T(m), a.length >= x) return;
371
- }
372
- }
373
- return T(l), a = V(a.replace(/\s+/g, " ").trim(), x), { url: e, title: t, headings: n, interactiveElements: r, visibleText: a };
374
- }
375
- function yt(e, t) {
378
+ function bt(e, t) {
376
379
  if (!t) return e;
377
- let s = e;
378
- for (const [n, o] of Object.entries(t)) {
379
- const r = n.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
380
- s = s.replace(new RegExp(`:${r}(?!\\w)`, "g"), encodeURIComponent(o));
380
+ let n = e;
381
+ for (const [s, r] of Object.entries(t)) {
382
+ const o = s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
383
+ n = n.replace(new RegExp(`:${o}(?!\\w)`, "g"), encodeURIComponent(r));
381
384
  }
382
- return s;
385
+ return n;
383
386
  }
384
- function Et(e) {
385
- var n;
386
- const t = e.replace(/\/$/, "") || "/", s = document.querySelectorAll("a[href]");
387
- for (const o of s) {
388
- const r = o, i = ((n = r.pathname) == null ? void 0 : n.replace(/\/$/, "")) || "/";
389
- if (r.origin === window.location.origin && i === t)
390
- return r.click(), console.log(`[Ourguide] Navigated via anchor click: ${e}`), !0;
387
+ function Tt(e) {
388
+ var s;
389
+ const t = e.replace(/\/$/, "") || "/", n = document.querySelectorAll("a[href]");
390
+ for (const r of n) {
391
+ const o = r, i = ((s = o.pathname) == null ? void 0 : s.replace(/\/$/, "")) || "/";
392
+ if (o.origin === window.location.origin && i === t)
393
+ return o.click(), console.log(`[Ourguide] Navigated via anchor click: ${e}`), !0;
391
394
  }
392
395
  return !1;
393
396
  }
394
397
  function It(e) {
395
- var o, r;
396
- const t = window, s = t.next;
397
- if ((o = s == null ? void 0 : s.router) != null && o.push)
398
- return s.router.push(e), console.log(`[Ourguide] Navigated via Next.js router: ${e}`), !0;
398
+ var r, o;
399
+ const t = window, n = t.next;
400
+ if ((r = n == null ? void 0 : n.router) != null && r.push)
401
+ return n.router.push(e), console.log(`[Ourguide] Navigated via Next.js router: ${e}`), !0;
399
402
  if (t.__NUXT__) {
400
403
  const i = t.$nuxt;
401
- if ((r = i == null ? void 0 : i.$router) != null && r.push)
404
+ if ((o = i == null ? void 0 : i.$router) != null && o.push)
402
405
  return i.$router.push(e), console.log(`[Ourguide] Navigated via Vue/Nuxt router: ${e}`), !0;
403
406
  }
404
407
  return !1;
405
408
  }
406
- function Tt(e) {
409
+ function wt(e) {
407
410
  try {
408
411
  return window.history.pushState({}, "", e), window.dispatchEvent(new PopStateEvent("popstate", { state: {} })), console.log(`[Ourguide] Navigated via pushState: ${e}`), !0;
409
412
  } catch {
410
413
  return !1;
411
414
  }
412
415
  }
413
- async function bt(e, t, s) {
414
- const n = yt(e, t);
415
- return s ? (s(n), console.log(`[Ourguide] Navigated via navigate prop: ${n}`), !0) : (Et(n) || It(n) || Tt(n) || (console.log(`[Ourguide] Navigated via hard navigation: ${n}`), window.location.href = n), !0);
416
+ async function $t(e, t, n) {
417
+ const s = bt(e, t);
418
+ return n ? (n(s), console.log(`[Ourguide] Navigated via navigate prop: ${s}`), !0) : (Tt(s) || It(s) || wt(s) || (console.log(`[Ourguide] Navigated via hard navigation: ${s}`), window.location.href = s), !0);
416
419
  }
417
- class xt {
420
+ class At {
418
421
  constructor(t) {
419
- this.state = tt, this.conversationId = null, this.callbacks = {}, this.productId = t.productId, this.apiUrl = t.apiUrl, this.conversationId = ut(this.productId);
420
- const s = ct(this.productId);
421
- s.length > 0 && this.dispatch({ type: "LOAD_MESSAGES", messages: s }), F({
422
- capture_screen: async () => St()
423
- });
422
+ this.state = et, this.conversationId = null, this.callbacks = {}, this.listeners = /* @__PURE__ */ new Set(), this.abortController = null, this.destroyed = !1, this.productId = t.productId, this.apiUrl = t.apiUrl, this.conversationId = Et(this.productId);
423
+ const n = St(this.productId);
424
+ n.length > 0 && this.dispatch({ type: "LOAD_MESSAGES", messages: n });
424
425
  }
425
426
  on(t) {
426
427
  this.callbacks = { ...this.callbacks, ...t };
427
428
  }
429
+ subscribe(t) {
430
+ return this.listeners.add(t), () => {
431
+ this.listeners.delete(t);
432
+ };
433
+ }
434
+ getSnapshot() {
435
+ return this.state;
436
+ }
428
437
  getState() {
429
438
  return this.state;
430
439
  }
@@ -432,8 +441,11 @@ class xt {
432
441
  return this.state.messages;
433
442
  }
434
443
  dispatch(t) {
435
- var s, n;
436
- this.state = et(this.state, t), (n = (s = this.callbacks).onStateChange) == null || n.call(s, this.state);
444
+ var n, s;
445
+ if (!this.destroyed) {
446
+ this.state = nt(this.state, t), (s = (n = this.callbacks).onStateChange) == null || s.call(n, this.state);
447
+ for (const r of this.listeners) r(this.state);
448
+ }
437
449
  }
438
450
  open() {
439
451
  this.dispatch({ type: "OPEN" });
@@ -442,256 +454,275 @@ class xt {
442
454
  this.dispatch({ type: "CLOSE" });
443
455
  }
444
456
  registerTools(t) {
445
- F(t);
457
+ ut(t);
446
458
  }
447
459
  async loadConfig() {
448
- var s, n;
449
- const t = await Y(this.apiUrl, this.productId);
450
- return (n = (s = this.callbacks).onConfigLoaded) == null || n.call(s, t), t;
460
+ var n, s;
461
+ const t = await Q(this.apiUrl, this.productId);
462
+ return (s = (n = this.callbacks).onConfigLoaded) == null || s.call(n, t), t;
451
463
  }
452
- async identify(t, s) {
453
- const n = R(this.productId);
454
- await Q(this.apiUrl, this.productId, n, t, s);
464
+ async identify(t, n) {
465
+ const s = A(this.productId);
466
+ await Z(this.apiUrl, this.productId, s, t, n);
455
467
  }
456
468
  resetUser() {
457
- const t = R(this.productId);
458
- Z(this.apiUrl, this.productId, t).catch(() => {
459
- }), it(this.productId), X(this.productId), this.conversationId = null, this.dispatch({ type: "FINISH_STREAMING" }), this.dispatch({ type: "CLEAR_MESSAGES" });
469
+ const t = A(this.productId);
470
+ tt(this.apiUrl, this.productId, t).catch(() => {
471
+ }), pt(this.productId), J(this.productId), this.conversationId = null, this.dispatch({ type: "FINISH_STREAMING" }), this.dispatch({ type: "CLEAR_MESSAGES" });
472
+ }
473
+ destroy() {
474
+ var t;
475
+ this.destroyed = !0, (t = this.abortController) == null || t.abort(), this.abortController = null, this.listeners.clear(), this.callbacks = {};
476
+ }
477
+ revive() {
478
+ this.destroyed = !1;
460
479
  }
461
480
  newConversation() {
462
481
  const t = this.state.messages;
463
- let s = null;
482
+ let n = null;
464
483
  if (t.length > 0) {
465
- const n = t.find((o) => o.role === "user");
466
- s = {
467
- title: n ? n.content.slice(0, 30) : "Conversation",
484
+ const s = t.find((r) => r.role === "user");
485
+ n = {
486
+ title: s ? s.content.slice(0, 30) : "Conversation",
468
487
  preview: t[t.length - 1].content.slice(0, 50),
469
488
  messages: [...t]
470
489
  };
471
490
  }
472
- return X(this.productId), this.conversationId = null, this.dispatch({ type: "CLEAR_MESSAGES" }), s;
473
- }
474
- async sendMessage(t, s, n) {
475
- var E, m, C, P;
476
- const o = t.trim(), r = s ? [...s] : [];
477
- if (!o && r.length === 0 || this.state.isStreaming) return;
478
- const i = r.length > 0 ? r.map((h) => `[${h.name}]`).join(" ") : "", l = [o, i].filter(Boolean).join(" ");
479
- this.dispatch({ type: "ADD_USER_MESSAGE", id: j(), content: l });
491
+ return J(this.productId), this.conversationId = null, this.dispatch({ type: "CLEAR_MESSAGES" }), n;
492
+ }
493
+ async sendMessage(t, n, s) {
494
+ var m, C, P, U, H;
495
+ const r = t.trim(), o = n ? [...n] : [];
496
+ if (!r && o.length === 0 || this.state.isStreaming) return;
497
+ const i = o.length > 0 ? o.map((h) => `[${h.name}]`).join(" ") : "", l = [r, i].filter(Boolean).join(" ");
498
+ this.dispatch({ type: "ADD_USER_MESSAGE", id: G(), content: l });
480
499
  let a = [];
481
- if (r.length > 0)
500
+ if (o.length > 0)
482
501
  try {
483
- a = await Promise.all(r.map(async (h) => ({ name: h.name, type: h.type, data: await K(h) })));
502
+ a = await Promise.all(o.map(async (h) => ({ name: h.name, type: h.type, data: await Y(h) })));
484
503
  } catch {
485
504
  this.dispatch({ type: "SET_ERROR", error: "Failed to read attached files" });
486
505
  return;
487
506
  }
488
- const T = [
489
- ...this.state.messages.map((h) => ({ role: h.role, content: h.content })),
490
- { role: "user", content: o || "Please review the attached file(s)." }
507
+ const S = [
508
+ ...this.state.messages.slice(0, -1).map((h) => ({ role: h.role, content: h.content })),
509
+ { role: "user", content: r || "Please review the attached file(s)." }
491
510
  ];
492
- this.dispatch({ type: "START_STREAMING", id: j() });
493
- const w = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), g = (h) => ({
494
- onTextDelta: (d) => this.dispatch({ type: "APPEND_TEXT", text: d }),
495
- onToolCall: (d, p, f, S) => {
496
- var y, u;
497
- const I = { id: d, name: p, args: f, status: "calling", providerMetadata: S };
498
- w.set(d, I), this.dispatch({ type: "ADD_TOOL_CALL", toolCall: I }), (u = (y = this.callbacks).onToolCall) == null || u.call(y, I), h && st(p) && c.set(d, { name: p, args: f, providerMetadata: S });
511
+ this.dispatch({ type: "START_STREAMING", id: G() }), (m = this.abortController) == null || m.abort();
512
+ const b = new AbortController();
513
+ this.abortController = b;
514
+ const c = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map(), T = (h) => ({
515
+ onTextDelta: (g) => this.dispatch({ type: "APPEND_TEXT", text: g }),
516
+ onToolCall: (g, p, f, y) => {
517
+ var E, u;
518
+ const I = { id: g, name: p, args: f, status: "calling", providerMetadata: y };
519
+ c.set(g, I), this.dispatch({ type: "ADD_TOOL_CALL", toolCall: I }), (u = (E = this.callbacks).onToolCall) == null || u.call(E, I), h && gt(p) && d.set(g, { name: p, args: f, providerMetadata: y });
499
520
  },
500
- onToolResult: (d, p) => {
501
- var S, I;
502
- this.dispatch({ type: "SET_TOOL_RESULT", toolCallId: d, result: p });
503
- const f = w.get(d);
504
- if (f && ((I = (S = this.callbacks).onToolResult) == null || I.call(S, f.name, p)), (f == null ? void 0 : f.name) === "navigate_to_page") {
505
- const y = p;
506
- y.route && (y.confidence ?? 0) >= 0.5 && bt(y.route, y.params, n);
521
+ onToolResult: (g, p) => {
522
+ var y, I;
523
+ this.dispatch({ type: "SET_TOOL_RESULT", toolCallId: g, result: p });
524
+ const f = c.get(g);
525
+ if (f && ((I = (y = this.callbacks).onToolResult) == null || I.call(y, f.name, p)), (f == null ? void 0 : f.name) === "navigate_to_page") {
526
+ const E = p;
527
+ E.route && (E.confidence ?? 0) >= 0.5 && $t(E.route, E.params, s);
507
528
  }
508
529
  },
509
- onError: (d) => {
530
+ onError: (g) => {
510
531
  var p, f;
511
- this.dispatch({ type: "SET_ERROR", error: d }), (f = (p = this.callbacks).onError) == null || f.call(p, d);
532
+ this.dispatch({ type: "SET_ERROR", error: g }), (f = (p = this.callbacks).onError) == null || f.call(p, g);
512
533
  }
513
534
  });
514
535
  try {
515
- const h = R(this.productId), { stream: d, conversationId: p } = await H(this.apiUrl, this.productId, T, h, this.conversationId || void 0, a);
516
- p && !this.conversationId && (this.conversationId = p, lt(this.productId, p));
536
+ const h = A(this.productId), { stream: g, conversationId: p } = await B(this.apiUrl, this.productId, S, h, this.conversationId || void 0, a, b.signal);
537
+ p && !this.conversationId && (this.conversationId = p, yt(this.productId, p));
517
538
  let f = !1;
518
- if (await B(d, { ...g(!0), onError: (u) => {
519
- var $, _;
520
- f = !0, this.dispatch({ type: "SET_ERROR", error: u }), (_ = ($ = this.callbacks).onError) == null || _.call($, u);
539
+ if (await F(g, { ...T(!0), onError: (u) => {
540
+ var $, v;
541
+ f = !0, this.dispatch({ type: "SET_ERROR", error: u }), (v = ($ = this.callbacks).onError) == null || v.call($, u);
521
542
  }, onFinish: () => {
522
- } }), f || c.size === 0) {
543
+ } }), f || d.size === 0) {
523
544
  f || this.dispatch({ type: "FINISH_STREAMING" }), this.persistMessages();
524
545
  return;
525
546
  }
526
- const S = [];
527
- for (const [u, { name: $, args: _, providerMetadata: W }] of c) {
528
- let v;
547
+ const y = [];
548
+ for (const [u, { name: $, args: v, providerMetadata: K }] of d) {
549
+ let _;
529
550
  try {
530
- v = await nt($)(_);
531
- } catch (U) {
532
- v = { status: "error", error: U instanceof Error ? U.message : "Handler failed" };
551
+ _ = await dt($)(v);
552
+ } catch (j) {
553
+ _ = { status: "error", error: j instanceof Error ? j.message : "Handler failed" };
533
554
  }
534
- this.dispatch({ type: "SET_TOOL_RESULT", toolCallId: u, result: v }), (m = (E = this.callbacks).onToolResult) == null || m.call(E, $, v), S.push({ toolCallId: u, toolName: $, args: _, result: v, providerMetadata: W });
555
+ this.dispatch({ type: "SET_TOOL_RESULT", toolCallId: u, result: _ }), (P = (C = this.callbacks).onToolResult) == null || P.call(C, $, _), y.push({ toolCallId: u, toolName: $, args: v, result: _, providerMetadata: K });
535
556
  }
536
557
  const I = [
537
- ...T,
538
- { role: "assistant", content: S.map((u) => ({ type: "tool-call", toolCallId: u.toolCallId, toolName: u.toolName, input: u.args, ...u.providerMetadata ? { providerOptions: u.providerMetadata } : {} })) },
539
- { role: "tool", content: S.map((u) => ({ type: "tool-result", toolCallId: u.toolCallId, toolName: u.toolName, output: { type: "json", value: u.result } })) }
540
- ], { stream: y } = await H(this.apiUrl, this.productId, I, void 0, this.conversationId || void 0);
541
- await B(y, { ...g(!1), onFinish: () => this.dispatch({ type: "FINISH_STREAMING" }) });
558
+ ...S,
559
+ { role: "assistant", content: y.map((u) => ({ type: "tool-call", toolCallId: u.toolCallId, toolName: u.toolName, input: u.args, ...u.providerMetadata ? { providerOptions: u.providerMetadata } : {} })) },
560
+ { role: "tool", content: y.map((u) => ({ type: "tool-result", toolCallId: u.toolCallId, toolName: u.toolName, output: { type: "json", value: u.result } })) }
561
+ ], { stream: E } = await B(this.apiUrl, this.productId, I, void 0, this.conversationId || void 0, void 0, b.signal);
562
+ await F(E, { ...T(!1), onFinish: () => this.dispatch({ type: "FINISH_STREAMING" }) });
542
563
  } catch (h) {
564
+ if (this.destroyed || b.signal.aborted) return;
543
565
  this.dispatch({ type: "FINISH_STREAMING" });
544
- const d = h instanceof Error ? h.message : "Something went wrong";
545
- this.dispatch({ type: "SET_ERROR", error: d }), (P = (C = this.callbacks).onError) == null || P.call(C, d);
566
+ const g = h instanceof Error ? h.message : "Something went wrong";
567
+ this.dispatch({ type: "SET_ERROR", error: g }), (H = (U = this.callbacks).onError) == null || H.call(U, g);
546
568
  }
547
569
  this.persistMessages();
548
570
  }
549
571
  persistMessages() {
550
- !this.state.isStreaming && this.state.messages.length > 0 && at(this.productId, this.state.messages);
572
+ !this.state.isStreaming && this.state.messages.length > 0 && mt(this.productId, this.state.messages);
573
+ }
574
+ }
575
+ function kt(e, t) {
576
+ if (e.name === "navigate_to_page") {
577
+ if (e.status === "calling") return "Finding the right page...";
578
+ const n = e.result;
579
+ return n != null && n.route ? `Navigated to ${n.route}` : "No matching page found";
551
580
  }
581
+ return e.name === "capture_screen" ? e.status === "calling" || t ? "Looking at your screen..." : "Screen captured" : e.name;
552
582
  }
553
583
  function k(e) {
554
584
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
555
585
  }
556
- function b(e) {
586
+ function w(e) {
557
587
  let t = e;
558
588
  return t = t.replace(/`([^`\n]+)`/g, '<code class="og2-md-inline-code">$1</code>'), t = t.replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>"), t = t.replace(/__(.+?)__/g, "<strong>$1</strong>"), t = t.replace(/\*(.+?)\*/g, "<em>$1</em>"), t = t.replace(new RegExp("(?<!\\w)_(.+?)_(?!\\w)", "g"), "<em>$1</em>"), t = t.replace(
559
589
  /\[([^\]]+)\]\(([^)]+)\)/g,
560
- (s, n, o) => {
561
- const r = o.trim();
562
- return /^(https?:\/\/|mailto:|\/|#)/i.test(r) ? `<a class="og2-md-link" href="${r}" target="_blank" rel="noopener noreferrer">${n}</a>` : n;
590
+ (n, s, r) => {
591
+ const o = r.trim();
592
+ return /^(https?:\/\/|mailto:|\/|#)/i.test(o) ? `<a class="og2-md-link" href="${o}" target="_blank" rel="noopener noreferrer">${s}</a>` : s;
563
593
  }
564
594
  ), t;
565
595
  }
566
- function Nt(e) {
596
+ function Mt(e) {
567
597
  if (!e) return "";
568
598
  const t = [];
569
- let s = e.replace(/```(\w*)\n([\s\S]*?)```/g, (n, o, r) => {
570
- const i = t.length, l = k(r.replace(/\n$/, "")), a = o ? ` data-lang="${k(o)}"` : "";
599
+ let n = e.replace(/```(\w*)\n([\s\S]*?)```/g, (s, r, o) => {
600
+ const i = t.length, l = k(o.replace(/\n$/, "")), a = r ? ` data-lang="${k(r)}"` : "";
571
601
  return t.push(
572
602
  `<pre class="og2-md-pre"${a}><code class="og2-md-code">${l}</code></pre>`
573
603
  ), `\0CB${i}\0`;
574
604
  });
575
- return s = k(s), s = Rt(s), s = s.replace(/\x00CB(\d+)\x00/g, (n, o) => t[parseInt(o)]), s;
605
+ return n = k(n), n = xt(n), n = n.replace(/\x00CB(\d+)\x00/g, (s, r) => t[parseInt(r)]), n;
576
606
  }
577
- function wt(e) {
607
+ function Ct(e) {
578
608
  return /^[\s]*[-*]\s/.test(e) ? "ul" : /^[\s]*\d+\.\s/.test(e) ? "ol" : /^#{1,4}\s+/.test(e) ? "heading" : /^\s*\|/.test(e) ? "table" : "text";
579
609
  }
580
- function $t(e) {
610
+ function vt(e) {
581
611
  const t = [];
582
- let s = null;
583
- for (const n of e) {
584
- const o = wt(n);
585
- s && s.type === o ? s.lines.push(n) : (s && t.push(s), s = { type: o, lines: [n] });
612
+ let n = null;
613
+ for (const s of e) {
614
+ const r = Ct(s);
615
+ n && n.type === r ? n.lines.push(s) : (n && t.push(n), n = { type: r, lines: [s] });
586
616
  }
587
- return s && t.push(s), t;
617
+ return n && t.push(n), t;
588
618
  }
589
- function Ct(e) {
619
+ function _t(e) {
590
620
  var t;
591
621
  switch (e.type) {
592
622
  case "ul":
593
- return `<ul class="og2-md-list">${e.lines.map((n) => `<li>${b(n.replace(/^[\s]*[-*]\s/, ""))}</li>`).join("")}</ul>`;
623
+ return `<ul class="og2-md-list">${e.lines.map((s) => `<li>${w(s.replace(/^[\s]*[-*]\s/, ""))}</li>`).join("")}</ul>`;
594
624
  case "ol": {
595
- const s = e.lines.map((r) => `<li>${b(r.replace(/^[\s]*\d+\.\s/, ""))}</li>`).join(""), n = ((t = e.lines[0].match(/^[\s]*(\d+)\./)) == null ? void 0 : t[1]) ?? "1";
596
- return `<ol class="og2-md-list"${n !== "1" ? ` start="${n}"` : ""}>${s}</ol>`;
625
+ const n = e.lines.map((o) => `<li>${w(o.replace(/^[\s]*\d+\.\s/, ""))}</li>`).join(""), s = ((t = e.lines[0].match(/^[\s]*(\d+)\./)) == null ? void 0 : t[1]) ?? "1";
626
+ return `<ol class="og2-md-list"${s !== "1" ? ` start="${s}"` : ""}>${n}</ol>`;
597
627
  }
598
628
  case "heading":
599
- return e.lines.map((s) => {
600
- const n = s.match(/^(#{1,4})\s+(.+)$/), o = n[1].length;
601
- return `<h${o + 2} class="og2-md-heading">${b(n[2])}</h${o + 2}>`;
629
+ return e.lines.map((n) => {
630
+ const s = n.match(/^(#{1,4})\s+(.+)$/), r = s[1].length;
631
+ return `<h${r + 2} class="og2-md-heading">${w(s[2])}</h${r + 2}>`;
602
632
  }).join("");
603
633
  case "table":
604
- return Ot(e.lines);
634
+ return Nt(e.lines);
605
635
  case "text":
606
- return `<p>${e.lines.map((s) => b(s)).join("<br>")}</p>`;
636
+ return `<p>${e.lines.map((n) => w(n)).join("<br>")}</p>`;
607
637
  }
608
638
  }
609
639
  function O(e) {
610
- return e.trim().replace(/^\|/, "").replace(/\|$/, "").split("|").map((n) => n.trim());
640
+ return e.trim().replace(/^\|/, "").replace(/\|$/, "").split("|").map((s) => s.trim());
611
641
  }
612
- function _t(e) {
613
- const t = e.trim(), s = t.startsWith(":"), n = t.endsWith(":");
614
- return s && n ? "center" : n ? "right" : "left";
642
+ function Ot(e) {
643
+ const t = e.trim(), n = t.startsWith(":"), s = t.endsWith(":");
644
+ return n && s ? "center" : s ? "right" : "left";
615
645
  }
616
- function vt(e) {
646
+ function Rt(e) {
617
647
  const t = O(e);
618
- return t.length > 0 && t.every((s) => /^:?-{1,}:?$/.test(s.trim()));
648
+ return t.length > 0 && t.every((n) => /^:?-{1,}:?$/.test(n.trim()));
619
649
  }
620
- function Ot(e) {
621
- if (e.length < 2 || !vt(e[1]))
622
- return `<p>${e.map((l) => b(l)).join("<br>")}</p>`;
623
- const t = O(e[0]), s = O(e[1]).map(_t), n = e.slice(2), o = (l) => {
624
- const a = s[l];
650
+ function Nt(e) {
651
+ if (e.length < 2 || !Rt(e[1]))
652
+ return `<p>${e.map((l) => w(l)).join("<br>")}</p>`;
653
+ const t = O(e[0]), n = O(e[1]).map(Ot), s = e.slice(2), r = (l) => {
654
+ const a = n[l];
625
655
  return a && a !== "left" ? ` style="text-align:${a}"` : "";
626
- }, r = "<thead><tr>" + t.map((l, a) => `<th${o(a)}>${b(l)}</th>`).join("") + "</tr></thead>";
656
+ }, o = "<thead><tr>" + t.map((l, a) => `<th${r(a)}>${w(l)}</th>`).join("") + "</tr></thead>";
627
657
  let i = "";
628
- return n.length > 0 && (i = `<tbody>${n.map((a) => {
629
- const T = O(a);
630
- return "<tr>" + t.map((w, c) => `<td${o(c)}>${b(T[c] ?? "")}</td>`).join("") + "</tr>";
631
- }).join("")}</tbody>`), `<table class="og2-md-table">${r}${i}</table>`;
632
- }
633
- function Rt(e) {
634
- const t = e.split(/\n{2,}/), s = [];
635
- for (const n of t) {
636
- const o = n.trim();
637
- if (!o) continue;
638
- if (/^\x00CB\d+\x00$/.test(o)) {
639
- s.push(o);
658
+ return s.length > 0 && (i = `<tbody>${s.map((a) => {
659
+ const S = O(a);
660
+ return "<tr>" + t.map((b, c) => `<td${r(c)}>${w(S[c] ?? "")}</td>`).join("") + "</tr>";
661
+ }).join("")}</tbody>`), `<table class="og2-md-table">${o}${i}</table>`;
662
+ }
663
+ function xt(e) {
664
+ const t = e.split(/\n{2,}/), n = [];
665
+ for (const s of t) {
666
+ const r = s.trim();
667
+ if (!r) continue;
668
+ if (/^\x00CB\d+\x00$/.test(r)) {
669
+ n.push(r);
640
670
  continue;
641
671
  }
642
- const r = o.split(`
643
- `), i = $t(r);
672
+ const o = r.split(`
673
+ `), i = vt(o);
644
674
  for (const l of i)
645
- s.push(Ct(l));
675
+ n.push(_t(l));
646
676
  }
647
- return s.join("");
677
+ return n.join("");
648
678
  }
649
- const J = {
679
+ const q = {
650
680
  none: "none",
651
681
  soft: "0 2px 8px rgba(0,0,0,0.08)",
652
682
  medium: "0 4px 16px rgba(0,0,0,0.12)",
653
683
  strong: "0 8px 32px rgba(0,0,0,0.18)",
654
684
  "extra-strong": "0 16px 48px rgba(0,0,0,0.28)"
655
685
  };
656
- function At(e, t) {
686
+ function Lt(e, t) {
657
687
  if (!e || !t) return;
658
- const s = (l, a) => {
688
+ const n = (l, a) => {
659
689
  a != null && a !== "" && e.style.setProperty(l, String(a));
660
- }, { colors: n, typography: o, dimensions: r, shadow: i } = t;
661
- n && (s("--og2-bg", n.background), s("--og2-border", n.border), s("--og2-text", n.text), s("--og2-messages-bg", n.messagesBackground), s("--og2-agent-bubble", n.agentBubble), s("--og2-agent-bubble-text", n.agentBubbleText), s("--og2-user-bubble", n.userBubble), s("--og2-user-bubble-text", n.userBubbleText), s("--og2-user-bubble-border", n.userBubbleBorder), s("--og2-send-bg", n.sendButtonBackground), s("--og2-send-icon", n.sendButtonIcon), s("--og2-send-inactive-bg", n.sendButtonInactiveBackground)), o && (s("--og2-font", o.fontFamily), s("--og2-font-weight", o.fontWeight), s("--og2-line-height", o.lineHeight), typeof o.fontSize == "number" && s("--og2-font-size", `${o.fontSize}px`), typeof o.headerSize == "number" && s("--og2-header-size", `${o.headerSize}px`), typeof o.letterSpacing == "number" && s("--og2-letter-spacing", `${o.letterSpacing}px`)), r && (r.width !== void 0 && s("--og2-width", `${r.width}px`), r.maxHeight !== void 0 && s("--og2-height", `${r.maxHeight}px`), r.borderRadius !== void 0 && s("--og2-radius", `${r.borderRadius}px`), r.padding !== void 0 && s("--og2-padding", `${r.padding}px`)), i && J[i] && s("--og2-shadow", J[i]);
690
+ }, { colors: s, typography: r, dimensions: o, shadow: i } = t;
691
+ s && (n("--og2-bg", s.background), n("--og2-border", s.border), n("--og2-text", s.text), n("--og2-messages-bg", s.messagesBackground), n("--og2-agent-bubble", s.agentBubble), n("--og2-agent-bubble-text", s.agentBubbleText), n("--og2-user-bubble", s.userBubble), n("--og2-user-bubble-text", s.userBubbleText), n("--og2-user-bubble-border", s.userBubbleBorder), n("--og2-send-bg", s.sendButtonBackground), n("--og2-send-icon", s.sendButtonIcon), n("--og2-send-inactive-bg", s.sendButtonInactiveBackground)), r && (n("--og2-font", r.fontFamily), n("--og2-font-weight", r.fontWeight), n("--og2-line-height", r.lineHeight), typeof r.fontSize == "number" && n("--og2-font-size", `${r.fontSize}px`), typeof r.headerSize == "number" && n("--og2-header-size", `${r.headerSize}px`), typeof r.letterSpacing == "number" && n("--og2-letter-spacing", `${r.letterSpacing}px`)), o && (o.width !== void 0 && n("--og2-width", `${o.width}px`), o.maxHeight !== void 0 && n("--og2-height", `${o.maxHeight}px`), o.borderRadius !== void 0 && n("--og2-radius", `${o.borderRadius}px`), o.padding !== void 0 && n("--og2-padding", `${o.padding}px`)), i && q[i] && n("--og2-shadow", q[i]);
662
692
  }
663
- function kt(e, t) {
693
+ function Dt(e, t) {
664
694
  if (!e || !t) return;
665
- const s = (n, o) => {
666
- o != null && o !== "" && e.style.setProperty(n, String(o));
695
+ const n = (s, r) => {
696
+ r != null && r !== "" && e.style.setProperty(s, String(r));
667
697
  };
668
- t.background && s("--og2-bubble-bg", t.background), t.border && s("--og2-bubble-border", t.border), t.icon && s("--og2-bubble-icon", t.icon), t.buttonSize && s("--og2-bubble-size", `${t.buttonSize}px`), t.iconSize && s("--og2-bubble-icon-size", `${t.iconSize}px`), t.right !== void 0 && s("--og2-bubble-right", `${t.right}px`), t.bottom !== void 0 && s("--og2-bubble-bottom", `${t.bottom}px`);
698
+ t.background && n("--og2-bubble-bg", t.background), t.border && n("--og2-bubble-border", t.border), t.icon && n("--og2-bubble-icon", t.icon), t.buttonSize && n("--og2-bubble-size", `${t.buttonSize}px`), t.iconSize && n("--og2-bubble-icon-size", `${t.iconSize}px`), t.right !== void 0 && n("--og2-bubble-right", `${t.right}px`), t.bottom !== void 0 && n("--og2-bubble-bottom", `${t.bottom}px`);
669
699
  }
670
700
  export {
671
- xt as OurguideClient,
672
- At as applyAppearance,
673
- kt as applyBubble,
674
- St as captureDOM,
675
- it as clearEndUserSessionId,
676
- X as clearMessages,
677
- Y as fetchConfig,
678
- K as fileToBase64,
679
- j as generateId,
680
- nt as getHandler,
681
- R as getOrCreateEndUserSessionId,
682
- st as hasHandler,
683
- Q as identifyEndUser,
684
- tt as initialState,
685
- ut as loadConversationId,
686
- ct as loadMessages,
687
- bt as navigateTo,
688
- B as parseDataStream,
689
- F as registerTools,
690
- Nt as renderMarkdown,
691
- Z as resetEndUser,
692
- lt as saveConversationId,
693
- at as saveMessages,
694
- H as sendMessage,
695
- et as widgetReducer
701
+ At as OurguideClient,
702
+ Lt as applyAppearance,
703
+ Dt as applyBubble,
704
+ lt as captureDOM,
705
+ pt as clearEndUserSessionId,
706
+ J as clearMessages,
707
+ Q as fetchConfig,
708
+ Y as fileToBase64,
709
+ kt as formatToolCall,
710
+ G as generateId,
711
+ dt as getHandler,
712
+ A as getOrCreateEndUserSessionId,
713
+ gt as hasHandler,
714
+ Z as identifyEndUser,
715
+ et as initialState,
716
+ Et as loadConversationId,
717
+ St as loadMessages,
718
+ $t as navigateTo,
719
+ F as parseDataStream,
720
+ ut as registerTools,
721
+ Mt as renderMarkdown,
722
+ tt as resetEndUser,
723
+ yt as saveConversationId,
724
+ mt as saveMessages,
725
+ B as sendMessage,
726
+ nt as widgetReducer
696
727
  };
697
728
  //# sourceMappingURL=index.js.map