@pagelines/sdk 1.0.153 → 1.0.155
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/{AgentProvider.vue_vue_type_script_setup_true_lang-B0TWM6dY.js → AgentProvider.vue_vue_type_script_setup_true_lang-vzGl9adQ.js} +16 -14
- package/dist/AgentProvider.vue_vue_type_script_setup_true_lang-vzGl9adQ.js.map +1 -0
- package/dist/AgentWidgetInline-xKwzOBQ7.js +37 -0
- package/dist/AgentWidgetInline-xKwzOBQ7.js.map +1 -0
- package/dist/{AgentWidgetModal-C4MD7yII.js → AgentWidgetModal-BesI4epW.js} +23 -21
- package/dist/AgentWidgetModal-BesI4epW.js.map +1 -0
- package/dist/{AgentWidgetPopup-DpR4jkw4.js → AgentWidgetPopup-KU7OGmSO.js} +48 -46
- package/dist/AgentWidgetPopup-KU7OGmSO.js.map +1 -0
- package/dist/{AgentWrap.vue_vue_type_script_setup_true_lang-Cr7I8qea.js → AgentWrap.vue_vue_type_script_setup_true_lang-Dnt1w4Uv.js} +1150 -1109
- package/dist/AgentWrap.vue_vue_type_script_setup_true_lang-Dnt1w4Uv.js.map +1 -0
- package/dist/agent/ui/AgentChat.vue.d.ts +1 -0
- package/dist/agent/ui/AgentProvider.vue.d.ts +1 -0
- package/dist/agent.js +3 -3
- package/dist/clients/ChatClient.d.ts +2 -0
- package/dist/sdk.css +1 -1
- package/dist/sdk.js +1 -1
- package/dist/{sdkClient-yg_rc4B7.js → sdkClient-DlvpHeVt.js} +163 -161
- package/dist/sdkClient-DlvpHeVt.js.map +1 -0
- package/dist/widget/PLWidget.d.ts +7 -0
- package/dist/widget/ui/AgentWidgetInline.vue.d.ts +1 -0
- package/dist/widget/ui/AgentWidgetModal.vue.d.ts +1 -0
- package/dist/widget/ui/AgentWidgetPopup.vue.d.ts +1 -0
- package/dist/widget.js +109 -81
- package/dist/widget.js.map +1 -1
- package/package.json +2 -2
- package/dist/AgentProvider.vue_vue_type_script_setup_true_lang-B0TWM6dY.js.map +0 -1
- package/dist/AgentWidgetInline-DAihjazO.js +0 -35
- package/dist/AgentWidgetInline-DAihjazO.js.map +0 -1
- package/dist/AgentWidgetModal-C4MD7yII.js.map +0 -1
- package/dist/AgentWidgetPopup-DpR4jkw4.js.map +0 -1
- package/dist/AgentWrap.vue_vue_type_script_setup_true_lang-Cr7I8qea.js.map +0 -1
- package/dist/sdkClient-yg_rc4B7.js.map +0 -1
|
@@ -6,14 +6,14 @@ import { watch as Z, ref as E, computed as ee } from "vue";
|
|
|
6
6
|
import { APP_PORT as F, APP_PROD_URL as D } from "@pagelines/types";
|
|
7
7
|
import { hc as ie } from "hono/client";
|
|
8
8
|
function N(h = {}) {
|
|
9
|
-
const { prefix: e = "id_" } = h, t = e.length >= 3 ? e.substring(0, 3) : e.padEnd(3, "_"),
|
|
10
|
-
let
|
|
9
|
+
const { prefix: e = "id_" } = h, t = e.length >= 3 ? e.substring(0, 3) : e.padEnd(3, "_"), o = Math.floor(Date.now() / 1e3).toString(16).padStart(8, "0");
|
|
10
|
+
let r = "";
|
|
11
11
|
for (let s = 0; s < 16; s++)
|
|
12
|
-
|
|
13
|
-
return t +
|
|
12
|
+
r += Math.floor(Math.random() * 16).toString(16);
|
|
13
|
+
return t + o + r;
|
|
14
14
|
}
|
|
15
15
|
c(N, "objectId");
|
|
16
|
-
const S = globalThis.process, m = typeof window < "u", B = typeof S < "u" && !m,
|
|
16
|
+
const S = globalThis.process, m = typeof window < "u", B = typeof S < "u" && !m, w = m ? typeof window < "u" && window.location && !window.location.hostname.includes("localhost") : B && typeof S < "u" && S.env?.NODE_ENV === "production", ne = !w, A = {
|
|
17
17
|
error: { priority: 50, color: "#FF0000", nodeColor: "\x1B[31m" },
|
|
18
18
|
warn: { priority: 40, color: "#FFA500", nodeColor: "\x1B[33m" },
|
|
19
19
|
info: { priority: 30, color: "#00ABFF", nodeColor: "\x1B[36m" },
|
|
@@ -38,13 +38,13 @@ const S = globalThis.process, m = typeof window < "u", B = typeof S < "u" && !m,
|
|
|
38
38
|
if (e)
|
|
39
39
|
return e;
|
|
40
40
|
}
|
|
41
|
-
return
|
|
41
|
+
return w ? "info" : "debug";
|
|
42
42
|
}
|
|
43
43
|
initBrowserLogging() {
|
|
44
44
|
if (!m)
|
|
45
45
|
return;
|
|
46
|
-
const t = typeof localStorage?.getItem == "function" && localStorage.getItem("PAGELINES_LOG") === "true",
|
|
47
|
-
this.enabledInBrowser = ne || t ||
|
|
46
|
+
const t = typeof localStorage?.getItem == "function" && localStorage.getItem("PAGELINES_LOG") === "true", o = window.location?.hostname || "";
|
|
47
|
+
this.enabledInBrowser = ne || t || o === "localhost" || o.includes("127.0.0.1"), w && !t && !y.hasShownHelp && (console.log(
|
|
48
48
|
"%cPageLines Logger (disabled in production)",
|
|
49
49
|
"color: #888; font-size: 12px"
|
|
50
50
|
), console.log(
|
|
@@ -55,8 +55,8 @@ const S = globalThis.process, m = typeof window < "u", B = typeof S < "u" && !m,
|
|
|
55
55
|
shouldLog(e) {
|
|
56
56
|
if (!this.settings.enabled || m && !this.enabledInBrowser)
|
|
57
57
|
return !1;
|
|
58
|
-
const t = A[e].priority,
|
|
59
|
-
return t >=
|
|
58
|
+
const t = A[e].priority, o = A[this.settings.minLevel].priority;
|
|
59
|
+
return t >= o;
|
|
60
60
|
}
|
|
61
61
|
formatTimestamp() {
|
|
62
62
|
return (/* @__PURE__ */ new Date()).toLocaleTimeString("en-GB", {
|
|
@@ -73,16 +73,16 @@ const S = globalThis.process, m = typeof window < "u", B = typeof S < "u" && !m,
|
|
|
73
73
|
if (typeof e != "object" || e === null)
|
|
74
74
|
return e;
|
|
75
75
|
if (Array.isArray(e))
|
|
76
|
-
return e.map((
|
|
76
|
+
return e.map((o) => this.redactSensitive(o));
|
|
77
77
|
const t = {};
|
|
78
|
-
for (const [
|
|
79
|
-
const s =
|
|
80
|
-
ae.some((i) => s.includes(i)) ? t[
|
|
78
|
+
for (const [o, r] of Object.entries(e)) {
|
|
79
|
+
const s = o.toLowerCase();
|
|
80
|
+
ae.some((i) => s.includes(i)) ? t[o] = "[REDACTED]" : typeof r == "object" && r !== null ? t[o] = this.redactSensitive(r) : t[o] = r;
|
|
81
81
|
}
|
|
82
82
|
return t;
|
|
83
83
|
}
|
|
84
|
-
formatData(e, t = 3,
|
|
85
|
-
if (
|
|
84
|
+
formatData(e, t = 3, o = 0) {
|
|
85
|
+
if (o >= t)
|
|
86
86
|
return "[Max Depth]";
|
|
87
87
|
if (e == null)
|
|
88
88
|
return e;
|
|
@@ -90,7 +90,7 @@ const S = globalThis.process, m = typeof window < "u", B = typeof S < "u" && !m,
|
|
|
90
90
|
return {
|
|
91
91
|
name: e.name,
|
|
92
92
|
message: e.message,
|
|
93
|
-
stack:
|
|
93
|
+
stack: w ? e.stack?.split(`
|
|
94
94
|
`).slice(0, 3).join(`
|
|
95
95
|
`) : e.stack,
|
|
96
96
|
...e
|
|
@@ -101,12 +101,12 @@ const S = globalThis.process, m = typeof window < "u", B = typeof S < "u" && !m,
|
|
|
101
101
|
if (typeof e != "object")
|
|
102
102
|
return e;
|
|
103
103
|
if (Array.isArray(e))
|
|
104
|
-
return e.length > 20 &&
|
|
104
|
+
return e.length > 20 && w ? `Array(${e.length}) [${e.slice(0, 3).map((r) => this.formatData(r, t, o + 1)).join(", ")}, ...]` : e.map((r) => this.formatData(r, t, o + 1));
|
|
105
105
|
try {
|
|
106
|
-
const
|
|
106
|
+
const r = {}, s = Object.entries(e), i = w ? 50 : 200;
|
|
107
107
|
for (const [l, u] of s.slice(0, i))
|
|
108
|
-
|
|
109
|
-
return s.length > i && (
|
|
108
|
+
r[l] = this.formatData(u, t, o + 1);
|
|
109
|
+
return s.length > i && (r["..."] = `${s.length - i} more properties`), this.redactSensitive(r);
|
|
110
110
|
} catch {
|
|
111
111
|
return "[Unserializable]";
|
|
112
112
|
}
|
|
@@ -114,21 +114,21 @@ const S = globalThis.process, m = typeof window < "u", B = typeof S < "u" && !m,
|
|
|
114
114
|
logToBrowser(e) {
|
|
115
115
|
if (!m || !this.shouldLog(e.level))
|
|
116
116
|
return;
|
|
117
|
-
const { level: t, description:
|
|
118
|
-
s !== void 0 ? console[t](`%c${a}`, d,
|
|
117
|
+
const { level: t, description: o, context: r, data: s, error: i } = e, l = A[t], a = `[${r || this.context || "www"}] ${t.toUpperCase()}:`, d = `color: ${l.color}; font-weight: bold;`;
|
|
118
|
+
s !== void 0 ? console[t](`%c${a}`, d, o, this.formatData(s)) : console[t](`%c${a}`, d, o), i && (i instanceof Error ? console.error(i) : console.error("Error details:", i));
|
|
119
119
|
}
|
|
120
120
|
logToNode(e) {
|
|
121
121
|
if (!B || !this.shouldLog(e.level))
|
|
122
122
|
return;
|
|
123
|
-
const { level: t, description:
|
|
124
|
-
if (
|
|
123
|
+
const { level: t, description: o, context: r, data: s, error: i } = e, l = r || this.context || "www";
|
|
124
|
+
if (w) {
|
|
125
125
|
const u = {
|
|
126
126
|
timestamp: this.formatISOTimestamp(),
|
|
127
127
|
level: t.toUpperCase()
|
|
128
128
|
};
|
|
129
|
-
s && (u.data = this.formatData(s)), i && (u.error = this.formatData(i)), console[t](`${u.timestamp} ${u.level} [${l}] ${
|
|
129
|
+
s && (u.data = this.formatData(s)), i && (u.error = this.formatData(i)), console[t](`${u.timestamp} ${u.level} [${l}] ${o}`, s || i ? JSON.stringify({ data: s, error: i }) : "");
|
|
130
130
|
} else {
|
|
131
|
-
const u = A[t], a = this.formatTimestamp(), d = "\x1B[0m", I = "\x1B[2m", g = u.nodeColor || "", k = `${I}${a}${d} ${g}${t.toUpperCase()} (${l}):${d} ${
|
|
131
|
+
const u = A[t], a = this.formatTimestamp(), d = "\x1B[0m", I = "\x1B[2m", g = u.nodeColor || "", k = `${I}${a}${d} ${g}${t.toUpperCase()} (${l}):${d} ${o}`;
|
|
132
132
|
console[t](k), s !== void 0 && console.log(JSON.stringify(this.formatData(s), null, 2)), i && (i instanceof Error ? (console.error(`\x1B[31mError:${d}`, i.message), i.stack && console.error(`\x1B[90m${i.stack}${d}`)) : console.error("Error:", i));
|
|
133
133
|
}
|
|
134
134
|
}
|
|
@@ -159,22 +159,22 @@ const S = globalThis.process, m = typeof window < "u", B = typeof S < "u" && !m,
|
|
|
159
159
|
createContextLogger(e) {
|
|
160
160
|
const t = new y(this.settings, e);
|
|
161
161
|
return {
|
|
162
|
-
error: /* @__PURE__ */ c((
|
|
163
|
-
warn: /* @__PURE__ */ c((
|
|
164
|
-
info: /* @__PURE__ */ c((
|
|
165
|
-
debug: /* @__PURE__ */ c((
|
|
166
|
-
trace: /* @__PURE__ */ c((
|
|
162
|
+
error: /* @__PURE__ */ c((o, r) => t.error(o, r), "error"),
|
|
163
|
+
warn: /* @__PURE__ */ c((o, r) => t.warn(o, r), "warn"),
|
|
164
|
+
info: /* @__PURE__ */ c((o, r) => t.info(o, r), "info"),
|
|
165
|
+
debug: /* @__PURE__ */ c((o, r) => t.debug(o, r), "debug"),
|
|
166
|
+
trace: /* @__PURE__ */ c((o, r) => t.trace(o, r), "trace"),
|
|
167
167
|
isEnabled: /* @__PURE__ */ c(() => t.isEnabled(), "isEnabled"),
|
|
168
|
-
setLevel: /* @__PURE__ */ c((
|
|
168
|
+
setLevel: /* @__PURE__ */ c((o) => t.setLevel(o), "setLevel")
|
|
169
169
|
};
|
|
170
170
|
}
|
|
171
171
|
};
|
|
172
172
|
c(y, "Logger"), n(y, "hasShownHelp", !1);
|
|
173
173
|
let P = y;
|
|
174
|
-
function
|
|
175
|
-
return new P({}, h)
|
|
174
|
+
function oe(h) {
|
|
175
|
+
return new P({}, h);
|
|
176
176
|
}
|
|
177
|
-
c(
|
|
177
|
+
c(oe, "createLogger");
|
|
178
178
|
const p = new P();
|
|
179
179
|
p.error.bind(p);
|
|
180
180
|
p.warn.bind(p);
|
|
@@ -186,7 +186,7 @@ const K = class K {
|
|
|
186
186
|
n(this, "name");
|
|
187
187
|
n(this, "settings");
|
|
188
188
|
n(this, "logger");
|
|
189
|
-
this.name = e, this.settings = t, this.logger =
|
|
189
|
+
this.name = e, this.settings = t, this.logger = oe(e);
|
|
190
190
|
}
|
|
191
191
|
};
|
|
192
192
|
c(K, "SettingsObject");
|
|
@@ -208,9 +208,9 @@ const z = class z {
|
|
|
208
208
|
if (typeof document > "u")
|
|
209
209
|
return null;
|
|
210
210
|
const t = document.cookie.split(";");
|
|
211
|
-
for (const
|
|
212
|
-
const [
|
|
213
|
-
if (
|
|
211
|
+
for (const o of t) {
|
|
212
|
+
const [r, s] = o.trim().split("=");
|
|
213
|
+
if (r === e)
|
|
214
214
|
return decodeURIComponent(s || "");
|
|
215
215
|
}
|
|
216
216
|
return null;
|
|
@@ -218,19 +218,19 @@ const z = class z {
|
|
|
218
218
|
/**
|
|
219
219
|
* Set cookie with secure defaults
|
|
220
220
|
*/
|
|
221
|
-
setCookie(e, t,
|
|
221
|
+
setCookie(e, t, o = {}) {
|
|
222
222
|
if (typeof document > "u")
|
|
223
223
|
return;
|
|
224
224
|
const {
|
|
225
|
-
secure:
|
|
225
|
+
secure: r = !0,
|
|
226
226
|
sameSite: s = "lax",
|
|
227
227
|
maxAge: i = 3600 * 24 * 7,
|
|
228
228
|
// 7 days default
|
|
229
229
|
domain: l,
|
|
230
230
|
path: u = "/"
|
|
231
|
-
} =
|
|
231
|
+
} = o;
|
|
232
232
|
let a = `${e}=${encodeURIComponent(t)}`;
|
|
233
|
-
a += `; Path=${u}`, a += `; Max-Age=${i}`, a += `; SameSite=${s}`,
|
|
233
|
+
a += `; Path=${u}`, a += `; Max-Age=${i}`, a += `; SameSite=${s}`, r && (a += "; Secure"), l && (a += `; Domain=${l}`), document.cookie = a;
|
|
234
234
|
}
|
|
235
235
|
/**
|
|
236
236
|
* Remove cookie by setting expired date
|
|
@@ -288,8 +288,8 @@ const C = new M();
|
|
|
288
288
|
function ce(h, e) {
|
|
289
289
|
const t = h.apiBase || (h.isDev ? `http://localhost:${F}` : D);
|
|
290
290
|
return ie(t, {
|
|
291
|
-
fetch: /* @__PURE__ */ c(async (
|
|
292
|
-
const i = C.getAuthToken(), l = await fetch(
|
|
291
|
+
fetch: /* @__PURE__ */ c(async (r, s) => {
|
|
292
|
+
const i = C.getAuthToken(), l = await fetch(r, {
|
|
293
293
|
...s,
|
|
294
294
|
headers: {
|
|
295
295
|
...s?.headers,
|
|
@@ -312,32 +312,32 @@ function ce(h, e) {
|
|
|
312
312
|
});
|
|
313
313
|
}
|
|
314
314
|
c(ce, "createApiClient");
|
|
315
|
-
let le = /* @__PURE__ */ Symbol("clean"), f = [],
|
|
316
|
-
const $ = 4,
|
|
315
|
+
let le = /* @__PURE__ */ Symbol("clean"), f = [], x = 0;
|
|
316
|
+
const $ = 4, re = /* @__PURE__ */ c(/* @__NO_SIDE_EFFECTS__ */ (h) => {
|
|
317
317
|
let e = [], t = {
|
|
318
318
|
get() {
|
|
319
319
|
return t.lc || t.listen(() => {
|
|
320
320
|
})(), t.value;
|
|
321
321
|
},
|
|
322
322
|
lc: 0,
|
|
323
|
-
listen(
|
|
324
|
-
return t.lc = e.push(
|
|
325
|
-
for (let s =
|
|
326
|
-
f[s] ===
|
|
327
|
-
let
|
|
328
|
-
~
|
|
323
|
+
listen(o) {
|
|
324
|
+
return t.lc = e.push(o), () => {
|
|
325
|
+
for (let s = x + $; s < f.length; )
|
|
326
|
+
f[s] === o ? f.splice(s, $) : s += $;
|
|
327
|
+
let r = e.indexOf(o);
|
|
328
|
+
~r && (e.splice(r, 1), --t.lc || t.off());
|
|
329
329
|
};
|
|
330
330
|
},
|
|
331
|
-
notify(
|
|
331
|
+
notify(o, r) {
|
|
332
332
|
let s = !f.length;
|
|
333
333
|
for (let i of e)
|
|
334
|
-
f.push(i, t.value,
|
|
334
|
+
f.push(i, t.value, o, r);
|
|
335
335
|
if (s) {
|
|
336
|
-
for (
|
|
337
|
-
f[
|
|
338
|
-
f[
|
|
339
|
-
f[
|
|
340
|
-
f[
|
|
336
|
+
for (x = 0; x < f.length; x += $)
|
|
337
|
+
f[x](
|
|
338
|
+
f[x + 1],
|
|
339
|
+
f[x + 2],
|
|
340
|
+
f[x + 3]
|
|
341
341
|
);
|
|
342
342
|
f.length = 0;
|
|
343
343
|
}
|
|
@@ -346,22 +346,22 @@ const $ = 4, oe = /* @__PURE__ */ c(/* @__NO_SIDE_EFFECTS__ */ (h) => {
|
|
|
346
346
|
We will redefine it in onMount and onStop. */
|
|
347
347
|
off() {
|
|
348
348
|
},
|
|
349
|
-
set(
|
|
350
|
-
let
|
|
351
|
-
|
|
349
|
+
set(o) {
|
|
350
|
+
let r = t.value;
|
|
351
|
+
r !== o && (t.value = o, t.notify(r));
|
|
352
352
|
},
|
|
353
|
-
subscribe(
|
|
354
|
-
let
|
|
355
|
-
return
|
|
353
|
+
subscribe(o) {
|
|
354
|
+
let r = t.listen(o);
|
|
355
|
+
return o(t.value), r;
|
|
356
356
|
},
|
|
357
357
|
value: h
|
|
358
358
|
};
|
|
359
359
|
return process.env.NODE_ENV !== "production" && (t[le] = () => {
|
|
360
360
|
e = [], t.lc = 0, t.off();
|
|
361
361
|
}), t;
|
|
362
|
-
}, "atom"), L = /* @__PURE__ */
|
|
362
|
+
}, "atom"), L = /* @__PURE__ */ re(void 0), U = /* @__PURE__ */ re(null), J = class J {
|
|
363
363
|
constructor() {
|
|
364
|
-
n(this, "logger",
|
|
364
|
+
n(this, "logger", oe("SDKStorage"));
|
|
365
365
|
}
|
|
366
366
|
/**
|
|
367
367
|
* Check if localStorage is fully functional (some test environments provide partial mocks)
|
|
@@ -373,8 +373,8 @@ const $ = 4, oe = /* @__PURE__ */ c(/* @__NO_SIDE_EFFECTS__ */ (h) => {
|
|
|
373
373
|
* Sync Vue reactive refs with global nanostores for cross-page persistence
|
|
374
374
|
*/
|
|
375
375
|
syncWithGlobalStores(e, t) {
|
|
376
|
-
const
|
|
377
|
-
|
|
376
|
+
const o = L.get(), r = U.get();
|
|
377
|
+
o && (e.value = o), r && (t.value = r), Z(e, (s) => {
|
|
378
378
|
L.set(s);
|
|
379
379
|
}, { immediate: !0 }), Z(t, (s) => {
|
|
380
380
|
U.set(s);
|
|
@@ -390,13 +390,13 @@ const $ = 4, oe = /* @__PURE__ */ c(/* @__NO_SIDE_EFFECTS__ */ (h) => {
|
|
|
390
390
|
loadFromStorage(e, t) {
|
|
391
391
|
if (typeof window > "u")
|
|
392
392
|
return;
|
|
393
|
-
const
|
|
394
|
-
if (
|
|
393
|
+
const o = C.getAuthToken();
|
|
394
|
+
if (o && (t.value = o), this.isLocalStorageFunctional())
|
|
395
395
|
try {
|
|
396
|
-
const
|
|
397
|
-
|
|
398
|
-
} catch (
|
|
399
|
-
this.logger.error("Failed to load user from localStorage", { data:
|
|
396
|
+
const r = localStorage.getItem("pagelines-user");
|
|
397
|
+
r && (e.value = JSON.parse(r));
|
|
398
|
+
} catch (r) {
|
|
399
|
+
this.logger.error("Failed to load user from localStorage", { data: r });
|
|
400
400
|
}
|
|
401
401
|
}
|
|
402
402
|
/**
|
|
@@ -406,8 +406,8 @@ const $ = 4, oe = /* @__PURE__ */ c(/* @__NO_SIDE_EFFECTS__ */ (h) => {
|
|
|
406
406
|
if (!(typeof window > "u") && (t.value ? C.setAuthToken(t.value) : C.removeAuthToken(), this.isLocalStorageFunctional()))
|
|
407
407
|
try {
|
|
408
408
|
e.value ? localStorage.setItem("pagelines-user", JSON.stringify(e.value)) : localStorage.removeItem("pagelines-user");
|
|
409
|
-
} catch (
|
|
410
|
-
this.logger.error("Failed to save user to localStorage", { data:
|
|
409
|
+
} catch (o) {
|
|
410
|
+
this.logger.error("Failed to save user to localStorage", { data: o });
|
|
411
411
|
}
|
|
412
412
|
}
|
|
413
413
|
/**
|
|
@@ -443,8 +443,8 @@ const $ = 4, oe = /* @__PURE__ */ c(/* @__NO_SIDE_EFFECTS__ */ (h) => {
|
|
|
443
443
|
if (this.isLocalStorageFunctional())
|
|
444
444
|
try {
|
|
445
445
|
localStorage.setItem(e, t);
|
|
446
|
-
} catch (
|
|
447
|
-
this.logger.error("Failed to set item in localStorage", { key: e, error:
|
|
446
|
+
} catch (o) {
|
|
447
|
+
this.logger.error("Failed to set item in localStorage", { key: e, error: o });
|
|
448
448
|
}
|
|
449
449
|
}
|
|
450
450
|
};
|
|
@@ -457,15 +457,15 @@ const V = class V {
|
|
|
457
457
|
async sendCode(e) {
|
|
458
458
|
this.ctx.loading.value = !0, this.ctx.error.value = null;
|
|
459
459
|
try {
|
|
460
|
-
const
|
|
460
|
+
const o = await (await this.ctx.api.auth["check-email"].$post({
|
|
461
461
|
json: { email: e }
|
|
462
462
|
})).json();
|
|
463
|
-
if (!
|
|
464
|
-
throw this.ctx.error.value =
|
|
463
|
+
if (!o.ok)
|
|
464
|
+
throw this.ctx.error.value = o.error, new Error(o.error);
|
|
465
465
|
} catch (t) {
|
|
466
466
|
this.ctx.logger.error("Send code error", { data: t });
|
|
467
|
-
const
|
|
468
|
-
throw this.ctx.error.value =
|
|
467
|
+
const o = t instanceof Error ? t.message : "Failed to send verification code";
|
|
468
|
+
throw this.ctx.error.value = o, t;
|
|
469
469
|
} finally {
|
|
470
470
|
this.ctx.loading.value = !1;
|
|
471
471
|
}
|
|
@@ -473,15 +473,15 @@ const V = class V {
|
|
|
473
473
|
async verifyCode(e, t) {
|
|
474
474
|
this.ctx.loading.value = !0, this.ctx.error.value = null;
|
|
475
475
|
try {
|
|
476
|
-
const
|
|
476
|
+
const r = await (await this.ctx.api.auth["verify-code"].$post({
|
|
477
477
|
json: { email: e, code: t }
|
|
478
478
|
})).json();
|
|
479
|
-
if (!
|
|
480
|
-
throw this.ctx.error.value =
|
|
481
|
-
} catch (
|
|
482
|
-
this.ctx.logger.error("Verify code error", { data:
|
|
483
|
-
const
|
|
484
|
-
throw this.ctx.error.value =
|
|
479
|
+
if (!r.ok)
|
|
480
|
+
throw this.ctx.error.value = r.error, new Error(r.error);
|
|
481
|
+
} catch (o) {
|
|
482
|
+
this.ctx.logger.error("Verify code error", { data: o });
|
|
483
|
+
const r = o instanceof Error ? o.message : "Failed to verify code";
|
|
484
|
+
throw this.ctx.error.value = r, o;
|
|
485
485
|
} finally {
|
|
486
486
|
this.ctx.loading.value = !1;
|
|
487
487
|
}
|
|
@@ -489,15 +489,15 @@ const V = class V {
|
|
|
489
489
|
async login(e, t) {
|
|
490
490
|
this.ctx.loading.value = !0, this.ctx.error.value = null;
|
|
491
491
|
try {
|
|
492
|
-
const
|
|
492
|
+
const r = await (await this.ctx.api.auth.login.$post({
|
|
493
493
|
json: { email: e, password: t }
|
|
494
494
|
})).json();
|
|
495
|
-
if (!
|
|
496
|
-
throw this.ctx.error.value =
|
|
497
|
-
} catch (
|
|
498
|
-
this.ctx.logger.error("Login error", { data:
|
|
499
|
-
const
|
|
500
|
-
throw this.ctx.error.value =
|
|
495
|
+
if (!r.ok)
|
|
496
|
+
throw this.ctx.error.value = r.error, new Error(r.error);
|
|
497
|
+
} catch (o) {
|
|
498
|
+
this.ctx.logger.error("Login error", { data: o });
|
|
499
|
+
const r = o instanceof Error ? o.message : "Login failed";
|
|
500
|
+
throw this.ctx.error.value = r, o;
|
|
501
501
|
} finally {
|
|
502
502
|
this.ctx.loading.value = !1;
|
|
503
503
|
}
|
|
@@ -533,10 +533,10 @@ const V = class V {
|
|
|
533
533
|
async requestAuthCode(e) {
|
|
534
534
|
this.ctx.loading.value = !0, this.ctx.error.value = null;
|
|
535
535
|
try {
|
|
536
|
-
const
|
|
536
|
+
const o = await (await this.ctx.api.auth["check-email"].$post({
|
|
537
537
|
json: { email: e.email }
|
|
538
538
|
})).json();
|
|
539
|
-
return
|
|
539
|
+
return o.ok ? (this.ctx.logger.info("Auth code requested successfully", { email: e.email }), !0) : (this.ctx.error.value = o.error, this.ctx.logger.error("Failed to request auth code", { email: e.email, error: o.error }), !1);
|
|
540
540
|
} catch (t) {
|
|
541
541
|
return this.ctx.logger.error("Request auth code error", { email: e.email, error: t }), this.ctx.error.value = t instanceof Error ? t.message : "Failed to request auth code", !1;
|
|
542
542
|
} finally {
|
|
@@ -546,17 +546,17 @@ const V = class V {
|
|
|
546
546
|
async loginWithCode(e) {
|
|
547
547
|
this.ctx.loading.value = !0, this.ctx.error.value = null;
|
|
548
548
|
try {
|
|
549
|
-
const
|
|
549
|
+
const o = await (await this.ctx.api.auth["verify-code"].$post({
|
|
550
550
|
json: { email: e.email, code: e.code }
|
|
551
551
|
})).json();
|
|
552
552
|
return this.ctx.logger.info("Login with code response", {
|
|
553
|
-
hasUser: !!
|
|
554
|
-
hasToken: !!
|
|
555
|
-
ok:
|
|
556
|
-
}),
|
|
553
|
+
hasUser: !!o.user,
|
|
554
|
+
hasToken: !!o.token,
|
|
555
|
+
ok: o.ok
|
|
556
|
+
}), o.ok ? (this.ctx.logger.info("Login successful", { email: e.email }), e.orgId && e.autoCreateContact !== !1 && this.ctx.activeUser.value?.userId && await this.autoCreateContact({
|
|
557
557
|
userId: this.ctx.activeUser.value.userId,
|
|
558
558
|
orgId: e.orgId
|
|
559
|
-
}), !0) : (this.ctx.error.value =
|
|
559
|
+
}), !0) : (this.ctx.error.value = o.error, this.ctx.logger.error("Login failed", { email: e.email, error: o.error }), !1);
|
|
560
560
|
} catch (t) {
|
|
561
561
|
return this.ctx.logger.error("Login with code error", { email: e.email, error: t }), this.ctx.error.value = t instanceof Error ? t.message : "Login failed", !1;
|
|
562
562
|
} finally {
|
|
@@ -565,10 +565,10 @@ const V = class V {
|
|
|
565
565
|
}
|
|
566
566
|
async autoCreateContact(e) {
|
|
567
567
|
try {
|
|
568
|
-
const
|
|
568
|
+
const o = await (await this.ctx.api.contact.resolve.$post({
|
|
569
569
|
json: { userId: e.userId, orgId: e.orgId }
|
|
570
570
|
})).json();
|
|
571
|
-
return
|
|
571
|
+
return o.ok ? (this.ctx.logger.info("Contact resolved", { userId: e.userId, orgId: e.orgId }), !0) : (this.ctx.logger.error("Failed to auto-create contact", { error: o.error, args: e }), !1);
|
|
572
572
|
} catch (t) {
|
|
573
573
|
return this.ctx.logger.error("Auto-create contact error", { error: t, args: e }), !1;
|
|
574
574
|
}
|
|
@@ -578,8 +578,8 @@ const V = class V {
|
|
|
578
578
|
this.ctx.logger.error("loginWithGoogle: Only available in browser");
|
|
579
579
|
return;
|
|
580
580
|
}
|
|
581
|
-
const t = this.ctx.apiBase || (this.ctx.isDev ? `http://localhost:${F}` : D),
|
|
582
|
-
|
|
581
|
+
const t = this.ctx.apiBase || (this.ctx.isDev ? `http://localhost:${F}` : D), o = window.location.origin, r = `${t}/auth/google-popup?origin=${encodeURIComponent(o)}`, s = 500, i = 600, l = window.screenX + (window.outerWidth - s) / 2, u = window.screenY + (window.outerHeight - i) / 2, a = window.open(
|
|
582
|
+
r,
|
|
583
583
|
"google-auth",
|
|
584
584
|
`width=${s},height=${i},left=${l},top=${u},popup=yes`
|
|
585
585
|
);
|
|
@@ -615,24 +615,25 @@ const H = class H {
|
|
|
615
615
|
this.ctx = e;
|
|
616
616
|
}
|
|
617
617
|
async chatStream(e) {
|
|
618
|
-
const
|
|
618
|
+
const o = `${this.ctx.apiBase || (this.ctx.isDev ? `http://localhost:${F}` : D)}/api/agent/public/${encodeURIComponent(e.handle)}/chat/stream`;
|
|
619
619
|
try {
|
|
620
|
-
const
|
|
620
|
+
const r = await fetch(o, {
|
|
621
621
|
method: "POST",
|
|
622
622
|
headers: { "Content-Type": "application/json" },
|
|
623
623
|
body: JSON.stringify({
|
|
624
624
|
message: e.message,
|
|
625
625
|
conversationId: e.conversationId,
|
|
626
626
|
history: e.history,
|
|
627
|
-
visitorId: e.visitorId
|
|
627
|
+
visitorId: e.visitorId,
|
|
628
|
+
context: e.context
|
|
628
629
|
})
|
|
629
630
|
});
|
|
630
|
-
if (!
|
|
631
|
-
const a = await
|
|
632
|
-
e.onError(a.error || `HTTP ${
|
|
631
|
+
if (!r.ok) {
|
|
632
|
+
const a = await r.json().catch(() => ({ error: "Request failed" }));
|
|
633
|
+
e.onError(a.error || `HTTP ${r.status}`);
|
|
633
634
|
return;
|
|
634
635
|
}
|
|
635
|
-
const s =
|
|
636
|
+
const s = r.body?.getReader();
|
|
636
637
|
if (!s) {
|
|
637
638
|
e.onError("No response stream");
|
|
638
639
|
return;
|
|
@@ -665,20 +666,21 @@ const H = class H {
|
|
|
665
666
|
}
|
|
666
667
|
}
|
|
667
668
|
e.onDone(u);
|
|
668
|
-
} catch (
|
|
669
|
-
e.onError(
|
|
669
|
+
} catch (r) {
|
|
670
|
+
e.onError(r instanceof Error ? r.message : "Stream failed");
|
|
670
671
|
}
|
|
671
672
|
}
|
|
672
673
|
async chatMessage(e) {
|
|
673
|
-
const
|
|
674
|
+
const o = `${this.ctx.apiBase || (this.ctx.isDev ? `http://localhost:${F}` : D)}/api/agent/public/${encodeURIComponent(e.handle)}/chat`;
|
|
674
675
|
try {
|
|
675
|
-
const s = await (await fetch(
|
|
676
|
+
const s = await (await fetch(o, {
|
|
676
677
|
method: "POST",
|
|
677
678
|
headers: { "Content-Type": "application/json" },
|
|
678
679
|
body: JSON.stringify({
|
|
679
680
|
message: e.message,
|
|
680
681
|
conversationId: e.conversationId,
|
|
681
|
-
visitorId: e.visitorId
|
|
682
|
+
visitorId: e.visitorId,
|
|
683
|
+
context: e.context
|
|
682
684
|
})
|
|
683
685
|
})).json();
|
|
684
686
|
if (!s.ok || !s.data) {
|
|
@@ -689,14 +691,14 @@ const H = class H {
|
|
|
689
691
|
conversationId: s.data.conversationId,
|
|
690
692
|
content: s.data.message.content
|
|
691
693
|
};
|
|
692
|
-
} catch (
|
|
693
|
-
this.ctx.logger.error("chatMessage error", { error:
|
|
694
|
+
} catch (r) {
|
|
695
|
+
this.ctx.logger.error("chatMessage error", { error: r });
|
|
694
696
|
return;
|
|
695
697
|
}
|
|
696
698
|
}
|
|
697
699
|
async saveMessage(e) {
|
|
698
700
|
try {
|
|
699
|
-
const
|
|
701
|
+
const o = await (await this.ctx.api.conversation.messages.$post({
|
|
700
702
|
json: {
|
|
701
703
|
sessionId: e.conversationId,
|
|
702
704
|
participantId: e.participantId,
|
|
@@ -704,7 +706,7 @@ const H = class H {
|
|
|
704
706
|
role: e.role
|
|
705
707
|
}
|
|
706
708
|
})).json();
|
|
707
|
-
return
|
|
709
|
+
return o.ok ? !0 : (this.ctx.logger.error("Failed to save message", { error: "error" in o ? o.error : "Unknown error", args: e }), !1);
|
|
708
710
|
} catch (t) {
|
|
709
711
|
return this.ctx.logger.error("Save message error", { error: t, args: e }), !1;
|
|
710
712
|
}
|
|
@@ -719,14 +721,14 @@ const Q = class Q {
|
|
|
719
721
|
async getPublicAgent(e) {
|
|
720
722
|
this.ctx.loading.value = !0, this.ctx.error.value = null;
|
|
721
723
|
try {
|
|
722
|
-
const
|
|
724
|
+
const o = await (await this.ctx.api.agent.public[":handle"].$get({
|
|
723
725
|
param: { handle: e.handle }
|
|
724
726
|
})).json();
|
|
725
|
-
if (!
|
|
726
|
-
this.ctx.error.value =
|
|
727
|
+
if (!o.ok) {
|
|
728
|
+
this.ctx.error.value = o.error, this.ctx.logger.error("Failed to fetch public agent", { handle: e.handle, error: o.error });
|
|
727
729
|
return;
|
|
728
730
|
}
|
|
729
|
-
return
|
|
731
|
+
return o.data;
|
|
730
732
|
} catch (t) {
|
|
731
733
|
this.ctx.logger.error("Get public agent error", { handle: e.handle, error: t }), this.ctx.error.value = t instanceof Error ? t.message : "Failed to fetch agent";
|
|
732
734
|
return;
|
|
@@ -737,14 +739,14 @@ const Q = class Q {
|
|
|
737
739
|
async getAgentByEmail(e) {
|
|
738
740
|
this.ctx.loading.value = !0, this.ctx.error.value = null;
|
|
739
741
|
try {
|
|
740
|
-
const
|
|
742
|
+
const o = await (await this.ctx.api.agent["by-email"][":email"].$get({
|
|
741
743
|
param: { email: e.email }
|
|
742
744
|
})).json();
|
|
743
|
-
if (!
|
|
744
|
-
this.ctx.error.value =
|
|
745
|
+
if (!o.ok) {
|
|
746
|
+
this.ctx.error.value = o.error, this.ctx.logger.error("Failed to fetch agent by email", { email: e.email, error: o.error });
|
|
745
747
|
return;
|
|
746
748
|
}
|
|
747
|
-
return
|
|
749
|
+
return o.data;
|
|
748
750
|
} catch (t) {
|
|
749
751
|
this.ctx.logger.error("Get agent by email error", { email: e.email, error: t }), this.ctx.error.value = t instanceof Error ? t.message : "Failed to fetch agent";
|
|
750
752
|
return;
|
|
@@ -757,7 +759,7 @@ const Q = class Q {
|
|
|
757
759
|
const t = this.ctx.currentAgent.value;
|
|
758
760
|
if (!t?.orgId)
|
|
759
761
|
return this.ctx.logger.error("Cannot track usage: no current agent with orgId", { args: e }), !1;
|
|
760
|
-
const
|
|
762
|
+
const r = await (await this.ctx.api.usage.record.$post({
|
|
761
763
|
json: {
|
|
762
764
|
orgId: t.orgId,
|
|
763
765
|
agentId: e.agentId,
|
|
@@ -769,7 +771,7 @@ const Q = class Q {
|
|
|
769
771
|
userId: e.participantId || this.ctx.activeUser.value?.userId || "anonymous"
|
|
770
772
|
}
|
|
771
773
|
})).json();
|
|
772
|
-
return
|
|
774
|
+
return r.ok ? !0 : (this.ctx.logger.error("Failed to track usage", { error: r.error, args: e }), !1);
|
|
773
775
|
} catch (t) {
|
|
774
776
|
return this.ctx.logger.error("Track usage error", { error: t, args: e }), !1;
|
|
775
777
|
}
|
|
@@ -781,7 +783,7 @@ const Q = class Q {
|
|
|
781
783
|
this.ctx.logger.error("Cannot start conversation: no current agent with orgId", { args: e });
|
|
782
784
|
return;
|
|
783
785
|
}
|
|
784
|
-
const
|
|
786
|
+
const r = await (await this.ctx.api.conversation.start.$post({
|
|
785
787
|
json: {
|
|
786
788
|
orgId: t.orgId,
|
|
787
789
|
agentId: e.agentId,
|
|
@@ -790,12 +792,12 @@ const Q = class Q {
|
|
|
790
792
|
channel: e.channel
|
|
791
793
|
}
|
|
792
794
|
})).json();
|
|
793
|
-
if (!
|
|
794
|
-
const s =
|
|
795
|
+
if (!r.ok || !r.data) {
|
|
796
|
+
const s = r.ok ? "No conversation data returned" : "error" in r ? r.error : "Unknown error";
|
|
795
797
|
this.ctx.logger.error("Failed to start conversation", { error: s, args: e });
|
|
796
798
|
return;
|
|
797
799
|
}
|
|
798
|
-
return this.ctx.logger.info("Conversation started", { conversationId:
|
|
800
|
+
return this.ctx.logger.info("Conversation started", { conversationId: r.data.conversationId }), r.data;
|
|
799
801
|
} catch (t) {
|
|
800
802
|
this.ctx.logger.error("Start conversation error", { error: t, args: e });
|
|
801
803
|
return;
|
|
@@ -803,10 +805,10 @@ const Q = class Q {
|
|
|
803
805
|
}
|
|
804
806
|
async autoCreateContact(e) {
|
|
805
807
|
try {
|
|
806
|
-
const
|
|
808
|
+
const o = await (await this.ctx.api.contact.resolve.$post({
|
|
807
809
|
json: { userId: e.userId, orgId: e.orgId }
|
|
808
810
|
})).json();
|
|
809
|
-
return
|
|
811
|
+
return o.ok ? (this.ctx.logger.info("Contact resolved", { userId: e.userId, orgId: e.orgId }), !0) : (this.ctx.logger.error("Failed to auto-create contact", { error: o.error, args: e }), !1);
|
|
810
812
|
} catch (t) {
|
|
811
813
|
return this.ctx.logger.error("Auto-create contact error", { error: t, args: e }), !1;
|
|
812
814
|
}
|
|
@@ -850,9 +852,9 @@ c(Y, "SDKGlobal");
|
|
|
850
852
|
let W = Y;
|
|
851
853
|
const T = new W(), j = class j extends O {
|
|
852
854
|
constructor(t = {}) {
|
|
853
|
-
const
|
|
854
|
-
if (
|
|
855
|
-
return console.debug("[PageLinesSDK] Returning existing singleton instance"),
|
|
855
|
+
const o = T.get();
|
|
856
|
+
if (o)
|
|
857
|
+
return console.debug("[PageLinesSDK] Returning existing singleton instance"), o;
|
|
856
858
|
super("PageLinesSDK", t);
|
|
857
859
|
// Vue reactive state
|
|
858
860
|
n(this, "activeUser", E());
|
|
@@ -872,17 +874,17 @@ const T = new W(), j = class j extends O {
|
|
|
872
874
|
const t = this.activeUser.value;
|
|
873
875
|
if (!t?.agents)
|
|
874
876
|
return;
|
|
875
|
-
const
|
|
876
|
-
if (
|
|
877
|
-
return t.agents.find((
|
|
877
|
+
const o = t.primaryAgentId || t.agents[0]?.agentId;
|
|
878
|
+
if (o)
|
|
879
|
+
return t.agents.find((r) => r.agentId === o);
|
|
878
880
|
}));
|
|
879
881
|
n(this, "currentOrg", ee(() => {
|
|
880
882
|
const t = this.currentAgent.value;
|
|
881
883
|
if (!t?.orgId)
|
|
882
884
|
return;
|
|
883
|
-
const
|
|
884
|
-
if (
|
|
885
|
-
return
|
|
885
|
+
const o = this.activeUser.value;
|
|
886
|
+
if (o?.orgs)
|
|
887
|
+
return o.orgs.find((r) => r.orgId === t.orgId);
|
|
886
888
|
}));
|
|
887
889
|
// Initialization state
|
|
888
890
|
n(this, "initialized");
|
|
@@ -895,7 +897,7 @@ const T = new W(), j = class j extends O {
|
|
|
895
897
|
{ isDev: this.isDev, apiBase: this.apiBase },
|
|
896
898
|
this.processApiResponse.bind(this)
|
|
897
899
|
);
|
|
898
|
-
const
|
|
900
|
+
const r = {
|
|
899
901
|
api: this.api,
|
|
900
902
|
apiBase: this.apiBase,
|
|
901
903
|
isDev: this.isDev,
|
|
@@ -909,7 +911,7 @@ const T = new W(), j = class j extends O {
|
|
|
909
911
|
logger: this.logger,
|
|
910
912
|
processApiResponse: this.processApiResponse.bind(this)
|
|
911
913
|
};
|
|
912
|
-
this.auth = new R(
|
|
914
|
+
this.auth = new R(r), this.chat = new _(r), this.user = new q(r), this.logger.info("PageLinesSDK initialized"), this.storage.loadFromStorage(this.activeUser, this.token), this.storage.syncWithGlobalStores(this.activeUser, this.token), this.initialized = new Promise((s) => {
|
|
913
915
|
this.resolveUser = s;
|
|
914
916
|
}), this.token.value && !this.activeUser.value ? this.getCurrentUser().then((s) => {
|
|
915
917
|
this.resolveUser && (this.resolveUser(s), this.resolveUser = void 0);
|
|
@@ -950,11 +952,11 @@ const T = new W(), j = class j extends O {
|
|
|
950
952
|
async sendCode(t) {
|
|
951
953
|
return this.auth.sendCode(t);
|
|
952
954
|
}
|
|
953
|
-
async verifyCode(t,
|
|
954
|
-
return this.auth.verifyCode(t,
|
|
955
|
+
async verifyCode(t, o) {
|
|
956
|
+
return this.auth.verifyCode(t, o);
|
|
955
957
|
}
|
|
956
|
-
async login(t,
|
|
957
|
-
return this.auth.login(t,
|
|
958
|
+
async login(t, o) {
|
|
959
|
+
return this.auth.login(t, o);
|
|
958
960
|
}
|
|
959
961
|
async logout() {
|
|
960
962
|
return this.auth.logout();
|
|
@@ -1010,6 +1012,6 @@ export {
|
|
|
1010
1012
|
te as P,
|
|
1011
1013
|
O as S,
|
|
1012
1014
|
q as U,
|
|
1013
|
-
|
|
1015
|
+
oe as c
|
|
1014
1016
|
};
|
|
1015
|
-
//# sourceMappingURL=sdkClient-
|
|
1017
|
+
//# sourceMappingURL=sdkClient-DlvpHeVt.js.map
|