@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.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +414 -383
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,86 +1,87 @@
|
|
|
1
|
-
function
|
|
2
|
-
return new Promise((t,
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
t(
|
|
7
|
-
},
|
|
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
|
|
11
|
-
const
|
|
12
|
-
console.log("[Ourguide] fetchConfig HTTP GET",
|
|
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
|
|
14
|
+
const s = await fetch(n, {
|
|
15
15
|
headers: { "ngrok-skip-browser-warning": "true" }
|
|
16
16
|
});
|
|
17
|
-
if (console.log("[Ourguide] fetchConfig HTTP status:",
|
|
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
|
|
20
|
-
return console.log("[Ourguide] fetchConfig raw JSON:", JSON.stringify(
|
|
21
|
-
} catch (
|
|
22
|
-
return console.error("[Ourguide] fetchConfig threw:",
|
|
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
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
const
|
|
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(
|
|
34
|
+
body: JSON.stringify(l),
|
|
35
|
+
signal: i
|
|
35
36
|
});
|
|
36
|
-
if (!
|
|
37
|
-
const
|
|
38
|
-
throw new Error(
|
|
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 (!
|
|
41
|
+
if (!a.body)
|
|
41
42
|
throw new Error("No response stream available");
|
|
42
43
|
return {
|
|
43
|
-
stream:
|
|
44
|
-
conversationId:
|
|
44
|
+
stream: a.body,
|
|
45
|
+
conversationId: a.headers.get("X-Conversation-Id")
|
|
45
46
|
};
|
|
46
47
|
}
|
|
47
|
-
async function
|
|
48
|
-
const
|
|
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:
|
|
55
|
-
}), i = await
|
|
56
|
-
if (!
|
|
57
|
-
throw new Error(i.error || `HTTP ${
|
|
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
|
|
61
|
-
const
|
|
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:
|
|
68
|
-
}),
|
|
69
|
-
if (!
|
|
70
|
-
throw new Error(
|
|
71
|
-
return
|
|
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
|
|
74
|
+
const et = {
|
|
74
75
|
isOpen: !1,
|
|
75
76
|
messages: [],
|
|
76
77
|
isStreaming: !1,
|
|
77
78
|
error: null
|
|
78
79
|
};
|
|
79
|
-
function
|
|
80
|
+
function G() {
|
|
80
81
|
return Date.now().toString(36) + Math.random().toString(36).slice(2, 7);
|
|
81
82
|
}
|
|
82
|
-
function
|
|
83
|
-
var
|
|
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
|
|
112
|
-
return
|
|
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
|
|
116
|
-
if (
|
|
117
|
-
const
|
|
118
|
-
|
|
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:
|
|
121
|
+
return { ...e, messages: s };
|
|
121
122
|
}
|
|
122
123
|
case "SET_TOOL_RESULT": {
|
|
123
|
-
const
|
|
124
|
-
if (
|
|
125
|
-
const
|
|
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
|
-
|
|
129
|
+
s[s.length - 1] = { ...r, toolCalls: o };
|
|
129
130
|
}
|
|
130
|
-
return { ...e, messages:
|
|
131
|
+
return { ...e, messages: s };
|
|
131
132
|
}
|
|
132
133
|
case "FINISH_STREAMING": {
|
|
133
|
-
const
|
|
134
|
-
return
|
|
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
|
|
138
|
-
return
|
|
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
|
|
147
|
-
const
|
|
148
|
-
let
|
|
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:
|
|
152
|
-
if (
|
|
153
|
-
const l =
|
|
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
|
-
|
|
157
|
+
r = l.pop() ?? "";
|
|
157
158
|
for (const a of l)
|
|
158
|
-
|
|
159
|
+
z(a.trim(), t);
|
|
159
160
|
}
|
|
160
|
-
|
|
161
|
-
} catch (
|
|
162
|
-
const i =
|
|
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
|
-
|
|
166
|
+
n.releaseLock();
|
|
166
167
|
}
|
|
167
168
|
}
|
|
168
|
-
function
|
|
169
|
-
const
|
|
169
|
+
function z(e, t) {
|
|
170
|
+
const n = e.split(`
|
|
170
171
|
`);
|
|
171
|
-
for (const
|
|
172
|
-
if (!
|
|
173
|
-
const
|
|
174
|
-
if (
|
|
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
|
|
177
|
-
switch (
|
|
177
|
+
const o = JSON.parse(r);
|
|
178
|
+
switch (o.type) {
|
|
178
179
|
case "text-delta":
|
|
179
|
-
|
|
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
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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
|
-
|
|
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
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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
|
-
|
|
204
|
+
o.toolCallId && t.onToolResult(o.toolCallId, o.output);
|
|
204
205
|
break;
|
|
205
206
|
case "error":
|
|
206
|
-
t.onError(
|
|
207
|
+
t.onError(o.errorText ?? o.reason ?? "Unknown error");
|
|
207
208
|
break;
|
|
208
209
|
case "abort":
|
|
209
|
-
t.onError(
|
|
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
|
|
221
|
-
function
|
|
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
|
|
309
|
+
function dt(e) {
|
|
225
310
|
return M[e];
|
|
226
311
|
}
|
|
227
|
-
function
|
|
312
|
+
function gt(e) {
|
|
228
313
|
return Object.hasOwn(M, e);
|
|
229
314
|
}
|
|
230
|
-
const
|
|
315
|
+
const ht = "og2-chat-", ft = "og2-enduser-session-", L = "og2-conv-";
|
|
231
316
|
function D(e) {
|
|
232
|
-
return `${
|
|
317
|
+
return `${ht}${e}`;
|
|
233
318
|
}
|
|
234
|
-
function
|
|
235
|
-
return `${
|
|
319
|
+
function W(e) {
|
|
320
|
+
return `${ft}${e}`;
|
|
236
321
|
}
|
|
237
|
-
function
|
|
238
|
-
var t,
|
|
239
|
-
const e = (
|
|
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
|
|
243
|
-
const t =
|
|
327
|
+
function A(e) {
|
|
328
|
+
const t = W(e);
|
|
244
329
|
try {
|
|
245
|
-
const
|
|
246
|
-
if (
|
|
247
|
-
const
|
|
248
|
-
return localStorage.setItem(t,
|
|
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_${
|
|
335
|
+
return `sess_${V()}`;
|
|
251
336
|
}
|
|
252
337
|
}
|
|
253
|
-
function
|
|
338
|
+
function pt(e) {
|
|
254
339
|
try {
|
|
255
|
-
localStorage.removeItem(
|
|
340
|
+
localStorage.removeItem(W(e));
|
|
256
341
|
} catch {
|
|
257
342
|
}
|
|
258
343
|
}
|
|
259
|
-
function
|
|
344
|
+
function mt(e, t) {
|
|
260
345
|
try {
|
|
261
|
-
const
|
|
262
|
-
sessionStorage.setItem(D(e), JSON.stringify(
|
|
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
|
|
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
|
|
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
|
|
365
|
+
function yt(e, t) {
|
|
281
366
|
try {
|
|
282
367
|
sessionStorage.setItem(`${L}${e}`, t);
|
|
283
368
|
} catch {
|
|
284
369
|
}
|
|
285
370
|
}
|
|
286
|
-
function
|
|
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
|
-
|
|
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
|
|
378
|
-
for (const [
|
|
379
|
-
const
|
|
380
|
-
|
|
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
|
|
385
|
+
return n;
|
|
383
386
|
}
|
|
384
|
-
function
|
|
385
|
-
var
|
|
386
|
-
const t = e.replace(/\/$/, "") || "/",
|
|
387
|
-
for (const
|
|
388
|
-
const
|
|
389
|
-
if (
|
|
390
|
-
return
|
|
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
|
|
396
|
-
const t = window,
|
|
397
|
-
if ((
|
|
398
|
-
return
|
|
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 ((
|
|
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
|
|
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
|
|
414
|
-
const
|
|
415
|
-
return
|
|
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
|
|
420
|
+
class At {
|
|
418
421
|
constructor(t) {
|
|
419
|
-
this.state =
|
|
420
|
-
const
|
|
421
|
-
|
|
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
|
|
436
|
-
|
|
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
|
-
|
|
457
|
+
ut(t);
|
|
446
458
|
}
|
|
447
459
|
async loadConfig() {
|
|
448
|
-
var
|
|
449
|
-
const t = await
|
|
450
|
-
return (
|
|
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,
|
|
453
|
-
const
|
|
454
|
-
await
|
|
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 =
|
|
458
|
-
|
|
459
|
-
}),
|
|
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
|
|
482
|
+
let n = null;
|
|
464
483
|
if (t.length > 0) {
|
|
465
|
-
const
|
|
466
|
-
|
|
467
|
-
title:
|
|
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
|
|
473
|
-
}
|
|
474
|
-
async sendMessage(t,
|
|
475
|
-
var
|
|
476
|
-
const
|
|
477
|
-
if (!
|
|
478
|
-
const i =
|
|
479
|
-
this.dispatch({ type: "ADD_USER_MESSAGE", id:
|
|
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 (
|
|
500
|
+
if (o.length > 0)
|
|
482
501
|
try {
|
|
483
|
-
a = await Promise.all(
|
|
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
|
|
489
|
-
...this.state.messages.map((h) => ({ role: h.role, content: h.content })),
|
|
490
|
-
{ role: "user", content:
|
|
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:
|
|
493
|
-
const
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
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: (
|
|
501
|
-
var
|
|
502
|
-
this.dispatch({ type: "SET_TOOL_RESULT", toolCallId:
|
|
503
|
-
const f =
|
|
504
|
-
if (f && ((I = (
|
|
505
|
-
const
|
|
506
|
-
|
|
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: (
|
|
530
|
+
onError: (g) => {
|
|
510
531
|
var p, f;
|
|
511
|
-
this.dispatch({ type: "SET_ERROR", error:
|
|
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 =
|
|
516
|
-
p && !this.conversationId && (this.conversationId = 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
|
|
519
|
-
var $,
|
|
520
|
-
f = !0, this.dispatch({ type: "SET_ERROR", error: 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 ||
|
|
543
|
+
} }), f || d.size === 0) {
|
|
523
544
|
f || this.dispatch({ type: "FINISH_STREAMING" }), this.persistMessages();
|
|
524
545
|
return;
|
|
525
546
|
}
|
|
526
|
-
const
|
|
527
|
-
for (const [u, { name: $, args:
|
|
528
|
-
let
|
|
547
|
+
const y = [];
|
|
548
|
+
for (const [u, { name: $, args: v, providerMetadata: K }] of d) {
|
|
549
|
+
let _;
|
|
529
550
|
try {
|
|
530
|
-
|
|
531
|
-
} catch (
|
|
532
|
-
|
|
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:
|
|
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
|
-
...
|
|
538
|
-
{ role: "assistant", content:
|
|
539
|
-
{ role: "tool", content:
|
|
540
|
-
], { stream:
|
|
541
|
-
await
|
|
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
|
|
545
|
-
this.dispatch({ type: "SET_ERROR", error:
|
|
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 &&
|
|
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, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
555
585
|
}
|
|
556
|
-
function
|
|
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
|
-
(
|
|
561
|
-
const
|
|
562
|
-
return /^(https?:\/\/|mailto:|\/|#)/i.test(
|
|
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
|
|
596
|
+
function Mt(e) {
|
|
567
597
|
if (!e) return "";
|
|
568
598
|
const t = [];
|
|
569
|
-
let
|
|
570
|
-
const i = t.length, l = k(
|
|
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
|
|
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
|
|
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
|
|
610
|
+
function vt(e) {
|
|
581
611
|
const t = [];
|
|
582
|
-
let
|
|
583
|
-
for (const
|
|
584
|
-
const
|
|
585
|
-
|
|
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
|
|
617
|
+
return n && t.push(n), t;
|
|
588
618
|
}
|
|
589
|
-
function
|
|
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((
|
|
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
|
|
596
|
-
return `<ol class="og2-md-list"${
|
|
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((
|
|
600
|
-
const
|
|
601
|
-
return `<h${
|
|
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
|
|
634
|
+
return Nt(e.lines);
|
|
605
635
|
case "text":
|
|
606
|
-
return `<p>${e.lines.map((
|
|
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((
|
|
640
|
+
return e.trim().replace(/^\|/, "").replace(/\|$/, "").split("|").map((s) => s.trim());
|
|
611
641
|
}
|
|
612
|
-
function
|
|
613
|
-
const t = e.trim(),
|
|
614
|
-
return
|
|
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
|
|
646
|
+
function Rt(e) {
|
|
617
647
|
const t = O(e);
|
|
618
|
-
return t.length > 0 && t.every((
|
|
648
|
+
return t.length > 0 && t.every((n) => /^:?-{1,}:?$/.test(n.trim()));
|
|
619
649
|
}
|
|
620
|
-
function
|
|
621
|
-
if (e.length < 2 || !
|
|
622
|
-
return `<p>${e.map((l) =>
|
|
623
|
-
const t = O(e[0]),
|
|
624
|
-
const a =
|
|
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
|
-
},
|
|
656
|
+
}, o = "<thead><tr>" + t.map((l, a) => `<th${r(a)}>${w(l)}</th>`).join("") + "</tr></thead>";
|
|
627
657
|
let i = "";
|
|
628
|
-
return
|
|
629
|
-
const
|
|
630
|
-
return "<tr>" + t.map((
|
|
631
|
-
}).join("")}</tbody>`), `<table class="og2-md-table">${
|
|
632
|
-
}
|
|
633
|
-
function
|
|
634
|
-
const t = e.split(/\n{2,}/),
|
|
635
|
-
for (const
|
|
636
|
-
const
|
|
637
|
-
if (!
|
|
638
|
-
if (/^\x00CB\d+\x00$/.test(
|
|
639
|
-
|
|
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
|
|
643
|
-
`), i =
|
|
672
|
+
const o = r.split(`
|
|
673
|
+
`), i = vt(o);
|
|
644
674
|
for (const l of i)
|
|
645
|
-
|
|
675
|
+
n.push(_t(l));
|
|
646
676
|
}
|
|
647
|
-
return
|
|
677
|
+
return n.join("");
|
|
648
678
|
}
|
|
649
|
-
const
|
|
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
|
|
686
|
+
function Lt(e, t) {
|
|
657
687
|
if (!e || !t) return;
|
|
658
|
-
const
|
|
688
|
+
const n = (l, a) => {
|
|
659
689
|
a != null && a !== "" && e.style.setProperty(l, String(a));
|
|
660
|
-
}, { colors:
|
|
661
|
-
|
|
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
|
|
693
|
+
function Dt(e, t) {
|
|
664
694
|
if (!e || !t) return;
|
|
665
|
-
const
|
|
666
|
-
|
|
695
|
+
const n = (s, r) => {
|
|
696
|
+
r != null && r !== "" && e.style.setProperty(s, String(r));
|
|
667
697
|
};
|
|
668
|
-
t.background &&
|
|
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
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
F as
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
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
|