@pagelines/sdk 1.0.172 → 1.0.174
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-DCanEQe2.js → AgentProvider.vue_vue_type_script_setup_true_lang-DfdOD9DB.js} +2 -2
- package/dist/{AgentProvider.vue_vue_type_script_setup_true_lang-DCanEQe2.js.map → AgentProvider.vue_vue_type_script_setup_true_lang-DfdOD9DB.js.map} +1 -1
- package/dist/{AgentWidgetInline-BW7Kg22N.js → AgentWidgetInline-DzMuLq-e.js} +2 -2
- package/dist/{AgentWidgetInline-BW7Kg22N.js.map → AgentWidgetInline-DzMuLq-e.js.map} +1 -1
- package/dist/{AgentWidgetModal-dH9xiLtO.js → AgentWidgetModal-Bo3I1Kvp.js} +2 -2
- package/dist/{AgentWidgetModal-dH9xiLtO.js.map → AgentWidgetModal-Bo3I1Kvp.js.map} +1 -1
- package/dist/{AgentWidgetPopup--EAvcTDh.js → AgentWidgetPopup-Vhq23tUI.js} +2 -2
- package/dist/{AgentWidgetPopup--EAvcTDh.js.map → AgentWidgetPopup-Vhq23tUI.js.map} +1 -1
- package/dist/AgentWrap.vue_vue_type_script_setup_true_lang-By0ndeW_.js +6972 -0
- package/dist/AgentWrap.vue_vue_type_script_setup_true_lang-By0ndeW_.js.map +1 -0
- package/dist/agent/AgentController.d.ts +14 -4
- package/dist/agent/ClientAudio.d.ts +1 -1
- package/dist/agent/index.d.ts +4 -1
- package/dist/agent/ui/AgentChat.vue.d.ts +1 -1
- package/dist/agent/ui/AgentWrap.vue.d.ts +0 -2
- package/dist/agent/ui/ElAgentChat.vue.d.ts +1 -0
- package/dist/agent.js +34 -32
- package/dist/clients/AuthClient.d.ts +0 -1
- package/dist/clients/ChatClient.d.ts +0 -6
- package/dist/clients/UserClient.d.ts +0 -20
- package/dist/clients/types.d.ts +2 -2
- package/dist/demo/index.d.ts +3 -5
- package/dist/sdk.css +1 -1
- package/dist/sdk.js +1 -1
- package/dist/{sdkClient-DlvpHeVt.js → sdkClient--jt-zUDx.js} +148 -251
- package/dist/sdkClient--jt-zUDx.js.map +1 -0
- package/dist/sdkClient.d.ts +1 -18
- package/dist/utils/base.d.ts +14 -0
- package/dist/utils/color.d.ts +12 -0
- package/dist/utils/cookies.d.ts +47 -0
- package/dist/utils/id.d.ts +27 -0
- package/dist/utils/logger.d.ts +49 -0
- package/dist/widget.js +5 -5
- package/dist/widget.js.map +1 -1
- package/package.json +2 -2
- package/dist/AgentWrap.vue_vue_type_script_setup_true_lang-DWBaKmcq.js +0 -5184
- package/dist/AgentWrap.vue_vue_type_script_setup_true_lang-DWBaKmcq.js.map +0 -1
- package/dist/sdkClient-DlvpHeVt.js.map +0 -1
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
var X = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var n = (h, e, t) =>
|
|
5
|
-
import { watch as Z, ref as
|
|
6
|
-
import { APP_PORT as
|
|
7
|
-
import { hc as
|
|
8
|
-
function
|
|
2
|
+
var ie = (h, e, t) => e in h ? X(h, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : h[e] = t;
|
|
3
|
+
var l = (h, e) => X(h, "name", { value: e, configurable: !0 });
|
|
4
|
+
var n = (h, e, t) => ie(h, typeof e != "symbol" ? e + "" : e, t);
|
|
5
|
+
import { watch as Z, ref as A, computed as ee } from "vue";
|
|
6
|
+
import { APP_PORT as D, APP_PROD_URL as P } from "@pagelines/types";
|
|
7
|
+
import { hc as se } from "hono/client";
|
|
8
|
+
function O(h = {}) {
|
|
9
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
10
|
let r = "";
|
|
11
|
-
for (let
|
|
11
|
+
for (let i = 0; i < 16; i++)
|
|
12
12
|
r += Math.floor(Math.random() * 16).toString(16);
|
|
13
13
|
return t + o + r;
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
const
|
|
15
|
+
l(O, "objectId");
|
|
16
|
+
const I = globalThis.process, m = typeof window < "u", B = typeof I < "u" && !m, x = m ? typeof window < "u" && window.location && !window.location.hostname.includes("localhost") : B && typeof I < "u" && I.env?.NODE_ENV === "production", ne = !x, L = {
|
|
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" },
|
|
@@ -31,20 +31,20 @@ const S = globalThis.process, m = typeof window < "u", B = typeof S < "u" && !m,
|
|
|
31
31
|
}, m && this.initBrowserLogging();
|
|
32
32
|
}
|
|
33
33
|
getDefaultLevel() {
|
|
34
|
-
if (B && typeof
|
|
35
|
-
return
|
|
34
|
+
if (B && typeof I < "u" && I.env?.LOG_LEVEL)
|
|
35
|
+
return I.env.LOG_LEVEL;
|
|
36
36
|
if (m && typeof localStorage < "u" && typeof localStorage.getItem == "function") {
|
|
37
37
|
const e = localStorage.getItem("PAGELINES_LOG_LEVEL");
|
|
38
38
|
if (e)
|
|
39
39
|
return e;
|
|
40
40
|
}
|
|
41
|
-
return
|
|
41
|
+
return x ? "info" : "debug";
|
|
42
42
|
}
|
|
43
43
|
initBrowserLogging() {
|
|
44
44
|
if (!m)
|
|
45
45
|
return;
|
|
46
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"),
|
|
47
|
+
this.enabledInBrowser = ne || t || o === "localhost" || o.includes("127.0.0.1"), x && !t && !y.hasShownHelp && (console.log(
|
|
48
48
|
"%cPageLines Logger (disabled in production)",
|
|
49
49
|
"color: #888; font-size: 12px"
|
|
50
50
|
), console.log(
|
|
@@ -55,7 +55,7 @@ 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 =
|
|
58
|
+
const t = L[e].priority, o = L[this.settings.minLevel].priority;
|
|
59
59
|
return t >= o;
|
|
60
60
|
}
|
|
61
61
|
formatTimestamp() {
|
|
@@ -76,8 +76,8 @@ const S = globalThis.process, m = typeof window < "u", B = typeof S < "u" && !m,
|
|
|
76
76
|
return e.map((o) => this.redactSensitive(o));
|
|
77
77
|
const t = {};
|
|
78
78
|
for (const [o, r] of Object.entries(e)) {
|
|
79
|
-
const
|
|
80
|
-
ae.some((
|
|
79
|
+
const i = o.toLowerCase();
|
|
80
|
+
ae.some((s) => i.includes(s)) ? t[o] = "[REDACTED]" : typeof r == "object" && r !== null ? t[o] = this.redactSensitive(r) : t[o] = r;
|
|
81
81
|
}
|
|
82
82
|
return t;
|
|
83
83
|
}
|
|
@@ -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: x ? 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 && x ? `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 r = {},
|
|
107
|
-
for (const [
|
|
108
|
-
r[
|
|
109
|
-
return
|
|
106
|
+
const r = {}, i = Object.entries(e), s = x ? 50 : 200;
|
|
107
|
+
for (const [c, u] of i.slice(0, s))
|
|
108
|
+
r[c] = this.formatData(u, t, o + 1);
|
|
109
|
+
return i.length > s && (r["..."] = `${i.length - s} more properties`), this.redactSensitive(r);
|
|
110
110
|
} catch {
|
|
111
111
|
return "[Unserializable]";
|
|
112
112
|
}
|
|
@@ -114,22 +114,22 @@ 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: o, context: r, data:
|
|
118
|
-
|
|
117
|
+
const { level: t, description: o, context: r, data: i, error: s } = e, c = L[t], a = `[${r || this.context || "www"}] ${t.toUpperCase()}:`, d = `color: ${c.color}; font-weight: bold;`;
|
|
118
|
+
i !== void 0 ? console[t](`%c${a}`, d, o, this.formatData(i)) : console[t](`%c${a}`, d, o), s && (s instanceof Error ? console.error(s) : console.error("Error details:", s));
|
|
119
119
|
}
|
|
120
120
|
logToNode(e) {
|
|
121
121
|
if (!B || !this.shouldLog(e.level))
|
|
122
122
|
return;
|
|
123
|
-
const { level: t, description: o, context: r, data:
|
|
124
|
-
if (
|
|
123
|
+
const { level: t, description: o, context: r, data: i, error: s } = e, c = r || this.context || "www";
|
|
124
|
+
if (x) {
|
|
125
125
|
const u = {
|
|
126
126
|
timestamp: this.formatISOTimestamp(),
|
|
127
127
|
level: t.toUpperCase()
|
|
128
128
|
};
|
|
129
|
-
|
|
129
|
+
i && (u.data = this.formatData(i)), s && (u.error = this.formatData(s)), console[t](`${u.timestamp} ${u.level} [${c}] ${o}`, i || s ? JSON.stringify({ data: i, error: s }) : "");
|
|
130
130
|
} else {
|
|
131
|
-
const u =
|
|
132
|
-
console[t](k),
|
|
131
|
+
const u = L[t], a = this.formatTimestamp(), d = "\x1B[0m", S = "\x1B[2m", g = u.nodeColor || "", k = `${S}${a}${d} ${g}${t.toUpperCase()} (${c}):${d} ${o}`;
|
|
132
|
+
console[t](k), i !== void 0 && console.log(JSON.stringify(this.formatData(i), null, 2)), s && (s instanceof Error ? (console.error(`\x1B[31mError:${d}`, s.message), s.stack && console.error(`\x1B[90m${s.stack}${d}`)) : console.error("Error:", s));
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
log(e) {
|
|
@@ -159,29 +159,29 @@ 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__ */
|
|
163
|
-
warn: /* @__PURE__ */
|
|
164
|
-
info: /* @__PURE__ */
|
|
165
|
-
debug: /* @__PURE__ */
|
|
166
|
-
trace: /* @__PURE__ */
|
|
167
|
-
isEnabled: /* @__PURE__ */
|
|
168
|
-
setLevel: /* @__PURE__ */
|
|
162
|
+
error: /* @__PURE__ */ l((o, r) => t.error(o, r), "error"),
|
|
163
|
+
warn: /* @__PURE__ */ l((o, r) => t.warn(o, r), "warn"),
|
|
164
|
+
info: /* @__PURE__ */ l((o, r) => t.info(o, r), "info"),
|
|
165
|
+
debug: /* @__PURE__ */ l((o, r) => t.debug(o, r), "debug"),
|
|
166
|
+
trace: /* @__PURE__ */ l((o, r) => t.trace(o, r), "trace"),
|
|
167
|
+
isEnabled: /* @__PURE__ */ l(() => t.isEnabled(), "isEnabled"),
|
|
168
|
+
setLevel: /* @__PURE__ */ l((o) => t.setLevel(o), "setLevel")
|
|
169
169
|
};
|
|
170
170
|
}
|
|
171
171
|
};
|
|
172
|
-
|
|
173
|
-
let
|
|
172
|
+
l(y, "Logger"), n(y, "hasShownHelp", !1);
|
|
173
|
+
let F = y;
|
|
174
174
|
function oe(h) {
|
|
175
|
-
return new
|
|
175
|
+
return new F({}, h);
|
|
176
176
|
}
|
|
177
|
-
|
|
178
|
-
const p = new
|
|
177
|
+
l(oe, "createLogger");
|
|
178
|
+
const p = new F();
|
|
179
179
|
p.error.bind(p);
|
|
180
180
|
p.warn.bind(p);
|
|
181
181
|
p.info.bind(p);
|
|
182
182
|
p.debug.bind(p);
|
|
183
183
|
p.trace.bind(p);
|
|
184
|
-
const
|
|
184
|
+
const q = class q {
|
|
185
185
|
constructor(e, t) {
|
|
186
186
|
n(this, "name");
|
|
187
187
|
n(this, "settings");
|
|
@@ -189,8 +189,8 @@ const K = class K {
|
|
|
189
189
|
this.name = e, this.settings = t, this.logger = oe(e);
|
|
190
190
|
}
|
|
191
191
|
};
|
|
192
|
-
|
|
193
|
-
let
|
|
192
|
+
l(q, "SettingsObject");
|
|
193
|
+
let j = q;
|
|
194
194
|
const z = class z {
|
|
195
195
|
constructor() {
|
|
196
196
|
// Configuration properties
|
|
@@ -209,9 +209,9 @@ const z = class z {
|
|
|
209
209
|
return null;
|
|
210
210
|
const t = document.cookie.split(";");
|
|
211
211
|
for (const o of t) {
|
|
212
|
-
const [r,
|
|
212
|
+
const [r, i] = o.trim().split("=");
|
|
213
213
|
if (r === e)
|
|
214
|
-
return decodeURIComponent(
|
|
214
|
+
return decodeURIComponent(i || "");
|
|
215
215
|
}
|
|
216
216
|
return null;
|
|
217
217
|
}
|
|
@@ -223,14 +223,14 @@ const z = class z {
|
|
|
223
223
|
return;
|
|
224
224
|
const {
|
|
225
225
|
secure: r = !0,
|
|
226
|
-
sameSite:
|
|
227
|
-
maxAge:
|
|
226
|
+
sameSite: i = "lax",
|
|
227
|
+
maxAge: s = 3600 * 24 * 7,
|
|
228
228
|
// 7 days default
|
|
229
|
-
domain:
|
|
229
|
+
domain: c,
|
|
230
230
|
path: u = "/"
|
|
231
231
|
} = o;
|
|
232
232
|
let a = `${e}=${encodeURIComponent(t)}`;
|
|
233
|
-
a += `; Path=${u}`, a += `; Max-Age=${
|
|
233
|
+
a += `; Path=${u}`, a += `; Max-Age=${s}`, a += `; SameSite=${i}`, r && (a += "; Secure"), c && (a += `; Domain=${c}`), document.cookie = a;
|
|
234
234
|
}
|
|
235
235
|
/**
|
|
236
236
|
* Remove cookie by setting expired date
|
|
@@ -282,38 +282,38 @@ const z = class z {
|
|
|
282
282
|
}), this.isLocalStorageFunctional() && window.localStorage.removeItem(this.fallbackStorageKey);
|
|
283
283
|
}
|
|
284
284
|
};
|
|
285
|
-
|
|
286
|
-
let
|
|
287
|
-
const
|
|
288
|
-
function
|
|
289
|
-
const t = h.apiBase || (h.isDev ? `http://localhost:${
|
|
290
|
-
return
|
|
291
|
-
fetch: /* @__PURE__ */
|
|
292
|
-
const
|
|
293
|
-
...
|
|
285
|
+
l(z, "CookieUtil");
|
|
286
|
+
let G = z;
|
|
287
|
+
const E = new G();
|
|
288
|
+
function le(h, e) {
|
|
289
|
+
const t = h.apiBase || (h.isDev ? `http://localhost:${D}` : P);
|
|
290
|
+
return se(t, {
|
|
291
|
+
fetch: /* @__PURE__ */ l(async (r, i) => {
|
|
292
|
+
const s = E.getAuthToken(), c = await fetch(r, {
|
|
293
|
+
...i,
|
|
294
294
|
headers: {
|
|
295
|
-
...
|
|
295
|
+
...i?.headers,
|
|
296
296
|
"Content-Type": "application/json",
|
|
297
297
|
// Only include Authorization header if token exists
|
|
298
|
-
...
|
|
298
|
+
...s && { Authorization: `Bearer ${s}` }
|
|
299
299
|
},
|
|
300
300
|
// Use 'omit' for Bearer tokens (not cookies) to allow CORS wildcard origin
|
|
301
301
|
credentials: "omit"
|
|
302
302
|
});
|
|
303
303
|
if (e) {
|
|
304
|
-
const u =
|
|
305
|
-
|
|
304
|
+
const u = c.json.bind(c);
|
|
305
|
+
c.json = async () => {
|
|
306
306
|
const a = await u();
|
|
307
307
|
return typeof a == "object" && a !== null && "ok" in a && ("user" in a || "token" in a) && e(a), a;
|
|
308
308
|
};
|
|
309
309
|
}
|
|
310
|
-
return
|
|
310
|
+
return c;
|
|
311
311
|
}, "fetch")
|
|
312
312
|
});
|
|
313
313
|
}
|
|
314
|
-
|
|
315
|
-
let
|
|
316
|
-
const $ = 4, re = /* @__PURE__ */
|
|
314
|
+
l(le, "createApiClient");
|
|
315
|
+
let ce = /* @__PURE__ */ Symbol("clean"), f = [], w = 0;
|
|
316
|
+
const $ = 4, re = /* @__PURE__ */ l(/* @__NO_SIDE_EFFECTS__ */ (h) => {
|
|
317
317
|
let e = [], t = {
|
|
318
318
|
get() {
|
|
319
319
|
return t.lc || t.listen(() => {
|
|
@@ -322,22 +322,22 @@ const $ = 4, re = /* @__PURE__ */ c(/* @__NO_SIDE_EFFECTS__ */ (h) => {
|
|
|
322
322
|
lc: 0,
|
|
323
323
|
listen(o) {
|
|
324
324
|
return t.lc = e.push(o), () => {
|
|
325
|
-
for (let
|
|
326
|
-
f[
|
|
325
|
+
for (let i = w + $; i < f.length; )
|
|
326
|
+
f[i] === o ? f.splice(i, $) : i += $;
|
|
327
327
|
let r = e.indexOf(o);
|
|
328
328
|
~r && (e.splice(r, 1), --t.lc || t.off());
|
|
329
329
|
};
|
|
330
330
|
},
|
|
331
331
|
notify(o, r) {
|
|
332
|
-
let
|
|
333
|
-
for (let
|
|
334
|
-
f.push(
|
|
335
|
-
if (
|
|
336
|
-
for (
|
|
337
|
-
f[
|
|
338
|
-
f[
|
|
339
|
-
f[
|
|
340
|
-
f[
|
|
332
|
+
let i = !f.length;
|
|
333
|
+
for (let s of e)
|
|
334
|
+
f.push(s, t.value, o, r);
|
|
335
|
+
if (i) {
|
|
336
|
+
for (w = 0; w < f.length; w += $)
|
|
337
|
+
f[w](
|
|
338
|
+
f[w + 1],
|
|
339
|
+
f[w + 2],
|
|
340
|
+
f[w + 3]
|
|
341
341
|
);
|
|
342
342
|
f.length = 0;
|
|
343
343
|
}
|
|
@@ -356,10 +356,10 @@ const $ = 4, re = /* @__PURE__ */ c(/* @__NO_SIDE_EFFECTS__ */ (h) => {
|
|
|
356
356
|
},
|
|
357
357
|
value: h
|
|
358
358
|
};
|
|
359
|
-
return process.env.NODE_ENV !== "production" && (t[
|
|
359
|
+
return process.env.NODE_ENV !== "production" && (t[ce] = () => {
|
|
360
360
|
e = [], t.lc = 0, t.off();
|
|
361
361
|
}), t;
|
|
362
|
-
}, "atom"),
|
|
362
|
+
}, "atom"), C = /* @__PURE__ */ re(void 0), U = /* @__PURE__ */ re(null), J = class J {
|
|
363
363
|
constructor() {
|
|
364
364
|
n(this, "logger", oe("SDKStorage"));
|
|
365
365
|
}
|
|
@@ -373,15 +373,15 @@ const $ = 4, re = /* @__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 o =
|
|
377
|
-
o && (e.value = o), r && (t.value = r), Z(e, (
|
|
378
|
-
|
|
379
|
-
}, { immediate: !0 }), Z(t, (
|
|
380
|
-
U.set(
|
|
381
|
-
}, { immediate: !0 }),
|
|
382
|
-
|
|
383
|
-
}), U.subscribe((
|
|
384
|
-
|
|
376
|
+
const o = C.get(), r = U.get();
|
|
377
|
+
o && (e.value = o), r && (t.value = r), Z(e, (i) => {
|
|
378
|
+
C.set(i);
|
|
379
|
+
}, { immediate: !0 }), Z(t, (i) => {
|
|
380
|
+
U.set(i);
|
|
381
|
+
}, { immediate: !0 }), C.subscribe((i) => {
|
|
382
|
+
i !== e.value && (e.value = i);
|
|
383
|
+
}), U.subscribe((i) => {
|
|
384
|
+
i !== t.value && (t.value = i);
|
|
385
385
|
});
|
|
386
386
|
}
|
|
387
387
|
/**
|
|
@@ -390,7 +390,7 @@ const $ = 4, re = /* @__PURE__ */ c(/* @__NO_SIDE_EFFECTS__ */ (h) => {
|
|
|
390
390
|
loadFromStorage(e, t) {
|
|
391
391
|
if (typeof window > "u")
|
|
392
392
|
return;
|
|
393
|
-
const o =
|
|
393
|
+
const o = E.getAuthToken();
|
|
394
394
|
if (o && (t.value = o), this.isLocalStorageFunctional())
|
|
395
395
|
try {
|
|
396
396
|
const r = localStorage.getItem("pagelines-user");
|
|
@@ -403,7 +403,7 @@ const $ = 4, re = /* @__PURE__ */ c(/* @__NO_SIDE_EFFECTS__ */ (h) => {
|
|
|
403
403
|
* Save current user and token to browser storage
|
|
404
404
|
*/
|
|
405
405
|
saveToStorage(e, t) {
|
|
406
|
-
if (!(typeof window > "u") && (t.value ?
|
|
406
|
+
if (!(typeof window > "u") && (t.value ? E.setAuthToken(t.value) : E.removeAuthToken(), this.isLocalStorageFunctional()))
|
|
407
407
|
try {
|
|
408
408
|
e.value ? localStorage.setItem("pagelines-user", JSON.stringify(e.value)) : localStorage.removeItem("pagelines-user");
|
|
409
409
|
} catch (o) {
|
|
@@ -415,13 +415,13 @@ const $ = 4, re = /* @__PURE__ */ c(/* @__NO_SIDE_EFFECTS__ */ (h) => {
|
|
|
415
415
|
*/
|
|
416
416
|
clearStorage() {
|
|
417
417
|
if (!(typeof window > "u")) {
|
|
418
|
-
if (
|
|
418
|
+
if (E.removeAuthToken(), this.isLocalStorageFunctional())
|
|
419
419
|
try {
|
|
420
420
|
localStorage.removeItem("pagelines-user");
|
|
421
421
|
} catch (e) {
|
|
422
422
|
this.logger.error("Failed to clear user from localStorage", { data: e });
|
|
423
423
|
}
|
|
424
|
-
|
|
424
|
+
C.set(void 0), U.set(null);
|
|
425
425
|
}
|
|
426
426
|
}
|
|
427
427
|
/**
|
|
@@ -448,8 +448,8 @@ const $ = 4, re = /* @__PURE__ */ c(/* @__NO_SIDE_EFFECTS__ */ (h) => {
|
|
|
448
448
|
}
|
|
449
449
|
}
|
|
450
450
|
};
|
|
451
|
-
|
|
452
|
-
let
|
|
451
|
+
l(J, "SDKStorage");
|
|
452
|
+
let R = J;
|
|
453
453
|
const V = class V {
|
|
454
454
|
constructor(e) {
|
|
455
455
|
this.ctx = e;
|
|
@@ -549,46 +549,29 @@ const V = class V {
|
|
|
549
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
|
-
return this.ctx.logger.info("Login
|
|
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
|
-
userId: this.ctx.activeUser.value.userId,
|
|
558
|
-
orgId: e.orgId
|
|
559
|
-
}), !0) : (this.ctx.error.value = o.error, this.ctx.logger.error("Login failed", { email: e.email, error: o.error }), !1);
|
|
552
|
+
return o.ok ? (this.ctx.logger.info("Login successful", { email: e.email }), !0) : (this.ctx.error.value = o.error, this.ctx.logger.error("Login failed", { email: e.email, error: o.error }), !1);
|
|
560
553
|
} catch (t) {
|
|
561
554
|
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
555
|
} finally {
|
|
563
556
|
this.ctx.loading.value = !1;
|
|
564
557
|
}
|
|
565
558
|
}
|
|
566
|
-
async autoCreateContact(e) {
|
|
567
|
-
try {
|
|
568
|
-
const o = await (await this.ctx.api.contact.resolve.$post({
|
|
569
|
-
json: { userId: e.userId, orgId: e.orgId }
|
|
570
|
-
})).json();
|
|
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
|
-
} catch (t) {
|
|
573
|
-
return this.ctx.logger.error("Auto-create contact error", { error: t, args: e }), !1;
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
559
|
loginWithGoogle(e) {
|
|
577
560
|
if (typeof window > "u") {
|
|
578
561
|
this.ctx.logger.error("loginWithGoogle: Only available in browser");
|
|
579
562
|
return;
|
|
580
563
|
}
|
|
581
|
-
const t = this.ctx.apiBase || (this.ctx.isDev ? `http://localhost:${
|
|
564
|
+
const t = this.ctx.apiBase || (this.ctx.isDev ? `http://localhost:${D}` : P), o = window.location.origin, r = `${t}/auth/google-popup?origin=${encodeURIComponent(o)}`, i = 500, s = 600, c = window.screenX + (window.outerWidth - i) / 2, u = window.screenY + (window.outerHeight - s) / 2, a = window.open(
|
|
582
565
|
r,
|
|
583
566
|
"google-auth",
|
|
584
|
-
`width=${
|
|
567
|
+
`width=${i},height=${s},left=${c},top=${u},popup=yes`
|
|
585
568
|
);
|
|
586
569
|
if (!a) {
|
|
587
570
|
const g = "Popup was blocked. Please allow popups for this site.";
|
|
588
571
|
this.ctx.error.value = g, e?.onError?.(g);
|
|
589
572
|
return;
|
|
590
573
|
}
|
|
591
|
-
const d = /* @__PURE__ */
|
|
574
|
+
const d = /* @__PURE__ */ l((g) => {
|
|
592
575
|
const k = new URL(t).origin;
|
|
593
576
|
if (g.origin === k) {
|
|
594
577
|
if (g.data?.type === "auth-success") {
|
|
@@ -603,19 +586,19 @@ const V = class V {
|
|
|
603
586
|
}
|
|
604
587
|
}, "handler");
|
|
605
588
|
window.addEventListener("message", d);
|
|
606
|
-
const
|
|
607
|
-
a.closed && (clearInterval(
|
|
589
|
+
const S = setInterval(() => {
|
|
590
|
+
a.closed && (clearInterval(S), window.removeEventListener("message", d));
|
|
608
591
|
}, 500);
|
|
609
592
|
}
|
|
610
593
|
};
|
|
611
|
-
|
|
612
|
-
let
|
|
594
|
+
l(V, "AuthClient");
|
|
595
|
+
let M = V;
|
|
613
596
|
const H = class H {
|
|
614
597
|
constructor(e) {
|
|
615
598
|
this.ctx = e;
|
|
616
599
|
}
|
|
617
600
|
async chatStream(e) {
|
|
618
|
-
const o = `${this.ctx.apiBase || (this.ctx.isDev ? `http://localhost:${
|
|
601
|
+
const o = `${this.ctx.apiBase || (this.ctx.isDev ? `http://localhost:${D}` : P)}/api/agent/public/${encodeURIComponent(e.handle)}/chat/stream`;
|
|
619
602
|
try {
|
|
620
603
|
const r = await fetch(o, {
|
|
621
604
|
method: "POST",
|
|
@@ -633,22 +616,22 @@ const H = class H {
|
|
|
633
616
|
e.onError(a.error || `HTTP ${r.status}`);
|
|
634
617
|
return;
|
|
635
618
|
}
|
|
636
|
-
const
|
|
637
|
-
if (!
|
|
619
|
+
const i = r.body?.getReader();
|
|
620
|
+
if (!i) {
|
|
638
621
|
e.onError("No response stream");
|
|
639
622
|
return;
|
|
640
623
|
}
|
|
641
|
-
const
|
|
642
|
-
let
|
|
624
|
+
const s = new TextDecoder();
|
|
625
|
+
let c = "", u = e.conversationId || "";
|
|
643
626
|
for (; ; ) {
|
|
644
|
-
const { done: a, value: d } = await
|
|
627
|
+
const { done: a, value: d } = await i.read();
|
|
645
628
|
if (a)
|
|
646
629
|
break;
|
|
647
|
-
|
|
648
|
-
const
|
|
630
|
+
c += s.decode(d, { stream: !0 });
|
|
631
|
+
const S = c.split(`
|
|
649
632
|
`);
|
|
650
|
-
|
|
651
|
-
for (const g of
|
|
633
|
+
c = S.pop() || "";
|
|
634
|
+
for (const g of S) {
|
|
652
635
|
if (!g.startsWith("data: "))
|
|
653
636
|
continue;
|
|
654
637
|
const k = g.slice(6).trim();
|
|
@@ -671,9 +654,9 @@ const H = class H {
|
|
|
671
654
|
}
|
|
672
655
|
}
|
|
673
656
|
async chatMessage(e) {
|
|
674
|
-
const o = `${this.ctx.apiBase || (this.ctx.isDev ? `http://localhost:${
|
|
657
|
+
const o = `${this.ctx.apiBase || (this.ctx.isDev ? `http://localhost:${D}` : P)}/api/agent/public/${encodeURIComponent(e.handle)}/chat`;
|
|
675
658
|
try {
|
|
676
|
-
const
|
|
659
|
+
const i = await (await fetch(o, {
|
|
677
660
|
method: "POST",
|
|
678
661
|
headers: { "Content-Type": "application/json" },
|
|
679
662
|
body: JSON.stringify({
|
|
@@ -683,36 +666,21 @@ const H = class H {
|
|
|
683
666
|
context: e.context
|
|
684
667
|
})
|
|
685
668
|
})).json();
|
|
686
|
-
if (!
|
|
687
|
-
this.ctx.logger.error("chatMessage failed", { error: !
|
|
669
|
+
if (!i.ok || !i.data) {
|
|
670
|
+
this.ctx.logger.error("chatMessage failed", { error: !i.ok && "error" in i ? i.error : "Unknown" });
|
|
688
671
|
return;
|
|
689
672
|
}
|
|
690
673
|
return {
|
|
691
|
-
conversationId:
|
|
692
|
-
content:
|
|
674
|
+
conversationId: i.data.conversationId,
|
|
675
|
+
content: i.data.message.content
|
|
693
676
|
};
|
|
694
677
|
} catch (r) {
|
|
695
678
|
this.ctx.logger.error("chatMessage error", { error: r });
|
|
696
679
|
return;
|
|
697
680
|
}
|
|
698
681
|
}
|
|
699
|
-
async saveMessage(e) {
|
|
700
|
-
try {
|
|
701
|
-
const o = await (await this.ctx.api.conversation.messages.$post({
|
|
702
|
-
json: {
|
|
703
|
-
sessionId: e.conversationId,
|
|
704
|
-
participantId: e.participantId,
|
|
705
|
-
content: e.content,
|
|
706
|
-
role: e.role
|
|
707
|
-
}
|
|
708
|
-
})).json();
|
|
709
|
-
return o.ok ? !0 : (this.ctx.logger.error("Failed to save message", { error: "error" in o ? o.error : "Unknown error", args: e }), !1);
|
|
710
|
-
} catch (t) {
|
|
711
|
-
return this.ctx.logger.error("Save message error", { error: t, args: e }), !1;
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
682
|
};
|
|
715
|
-
|
|
683
|
+
l(H, "ChatClient");
|
|
716
684
|
let _ = H;
|
|
717
685
|
const Q = class Q {
|
|
718
686
|
constructor(e) {
|
|
@@ -754,69 +722,10 @@ const Q = class Q {
|
|
|
754
722
|
this.ctx.loading.value = !1;
|
|
755
723
|
}
|
|
756
724
|
}
|
|
757
|
-
async trackUsage(e) {
|
|
758
|
-
try {
|
|
759
|
-
const t = this.ctx.currentAgent.value;
|
|
760
|
-
if (!t?.orgId)
|
|
761
|
-
return this.ctx.logger.error("Cannot track usage: no current agent with orgId", { args: e }), !1;
|
|
762
|
-
const r = await (await this.ctx.api.usage.record.$post({
|
|
763
|
-
json: {
|
|
764
|
-
orgId: t.orgId,
|
|
765
|
-
agentId: e.agentId,
|
|
766
|
-
sessionId: this.ctx.sessionId,
|
|
767
|
-
// Auto-managed by SDK
|
|
768
|
-
type: e.type,
|
|
769
|
-
quantity: e.quantity,
|
|
770
|
-
// Track the participant if provided, otherwise use current user or anonymous
|
|
771
|
-
userId: e.participantId || this.ctx.activeUser.value?.userId || "anonymous"
|
|
772
|
-
}
|
|
773
|
-
})).json();
|
|
774
|
-
return r.ok ? !0 : (this.ctx.logger.error("Failed to track usage", { error: r.error, args: e }), !1);
|
|
775
|
-
} catch (t) {
|
|
776
|
-
return this.ctx.logger.error("Track usage error", { error: t, args: e }), !1;
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
async startConversation(e) {
|
|
780
|
-
try {
|
|
781
|
-
const t = this.ctx.currentAgent.value;
|
|
782
|
-
if (!t?.orgId) {
|
|
783
|
-
this.ctx.logger.error("Cannot start conversation: no current agent with orgId", { args: e });
|
|
784
|
-
return;
|
|
785
|
-
}
|
|
786
|
-
const r = await (await this.ctx.api.conversation.start.$post({
|
|
787
|
-
json: {
|
|
788
|
-
orgId: t.orgId,
|
|
789
|
-
agentId: e.agentId,
|
|
790
|
-
userId: e.userId || this.ctx.activeUser.value?.userId,
|
|
791
|
-
anonId: e.anonId,
|
|
792
|
-
channel: e.channel
|
|
793
|
-
}
|
|
794
|
-
})).json();
|
|
795
|
-
if (!r.ok || !r.data) {
|
|
796
|
-
const s = r.ok ? "No conversation data returned" : "error" in r ? r.error : "Unknown error";
|
|
797
|
-
this.ctx.logger.error("Failed to start conversation", { error: s, args: e });
|
|
798
|
-
return;
|
|
799
|
-
}
|
|
800
|
-
return this.ctx.logger.info("Conversation started", { conversationId: r.data.conversationId }), r.data;
|
|
801
|
-
} catch (t) {
|
|
802
|
-
this.ctx.logger.error("Start conversation error", { error: t, args: e });
|
|
803
|
-
return;
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
async autoCreateContact(e) {
|
|
807
|
-
try {
|
|
808
|
-
const o = await (await this.ctx.api.contact.resolve.$post({
|
|
809
|
-
json: { userId: e.userId, orgId: e.orgId }
|
|
810
|
-
})).json();
|
|
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);
|
|
812
|
-
} catch (t) {
|
|
813
|
-
return this.ctx.logger.error("Auto-create contact error", { error: t, args: e }), !1;
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
725
|
generateAnonId() {
|
|
817
726
|
const e = "pagelinesAnonId";
|
|
818
727
|
let t = this.ctx.storage.getItem(e);
|
|
819
|
-
return t || (t =
|
|
728
|
+
return t || (t = O({ prefix: "anon" }), this.ctx.storage.setItem(e, t)), t;
|
|
820
729
|
}
|
|
821
730
|
track(e) {
|
|
822
731
|
try {
|
|
@@ -831,8 +740,8 @@ const Q = class Q {
|
|
|
831
740
|
}
|
|
832
741
|
}
|
|
833
742
|
};
|
|
834
|
-
|
|
835
|
-
let
|
|
743
|
+
l(Q, "UserClient");
|
|
744
|
+
let W = Q;
|
|
836
745
|
const Y = class Y {
|
|
837
746
|
constructor() {
|
|
838
747
|
n(this, "key", "__PAGELINES_SDK__");
|
|
@@ -848,24 +757,24 @@ const Y = class Y {
|
|
|
848
757
|
typeof window < "u" && delete globalThis[this.key];
|
|
849
758
|
}
|
|
850
759
|
};
|
|
851
|
-
|
|
852
|
-
let
|
|
853
|
-
const T = new
|
|
760
|
+
l(Y, "SDKGlobal");
|
|
761
|
+
let K = Y;
|
|
762
|
+
const T = new K(), N = class N extends j {
|
|
854
763
|
constructor(t = {}) {
|
|
855
764
|
const o = T.get();
|
|
856
765
|
if (o)
|
|
857
766
|
return console.debug("[PageLinesSDK] Returning existing singleton instance"), o;
|
|
858
767
|
super("PageLinesSDK", t);
|
|
859
768
|
// Vue reactive state
|
|
860
|
-
n(this, "activeUser",
|
|
861
|
-
n(this, "token",
|
|
862
|
-
n(this, "loading",
|
|
863
|
-
n(this, "error",
|
|
769
|
+
n(this, "activeUser", A());
|
|
770
|
+
n(this, "token", A(null));
|
|
771
|
+
n(this, "loading", A(!1));
|
|
772
|
+
n(this, "error", A(null));
|
|
864
773
|
n(this, "apiBase", this.settings.apiBase || void 0);
|
|
865
774
|
// Storage handler for persistence
|
|
866
|
-
n(this, "storage", new
|
|
775
|
+
n(this, "storage", new R());
|
|
867
776
|
// Auto-managed session ID for usage tracking
|
|
868
|
-
n(this, "sessionId",
|
|
777
|
+
n(this, "sessionId", O({ prefix: "ses" }));
|
|
869
778
|
// Typed Hono RPC client - uses SDKAppType (auth/self/usage routes only)
|
|
870
779
|
// Initialized in constructor (definite assignment via singleton pattern)
|
|
871
780
|
n(this, "apiClient");
|
|
@@ -893,7 +802,7 @@ const T = new W(), j = class j extends O {
|
|
|
893
802
|
n(this, "auth");
|
|
894
803
|
n(this, "chat");
|
|
895
804
|
n(this, "user");
|
|
896
|
-
T.set(this), this.apiClient =
|
|
805
|
+
T.set(this), this.apiClient = le(
|
|
897
806
|
{ isDev: this.isDev, apiBase: this.apiBase },
|
|
898
807
|
this.processApiResponse.bind(this)
|
|
899
808
|
);
|
|
@@ -911,12 +820,12 @@ const T = new W(), j = class j extends O {
|
|
|
911
820
|
logger: this.logger,
|
|
912
821
|
processApiResponse: this.processApiResponse.bind(this)
|
|
913
822
|
};
|
|
914
|
-
this.auth = new
|
|
915
|
-
this.resolveUser =
|
|
916
|
-
}), this.token.value && !this.activeUser.value ? this.getCurrentUser().then((
|
|
917
|
-
this.resolveUser && (this.resolveUser(
|
|
918
|
-
}).catch((
|
|
919
|
-
this.logger.error("Auto user fetch failed", { data:
|
|
823
|
+
this.auth = new M(r), this.chat = new _(r), this.user = new W(r), this.logger.info("PageLinesSDK initialized"), this.storage.loadFromStorage(this.activeUser, this.token), this.storage.syncWithGlobalStores(this.activeUser, this.token), this.initialized = new Promise((i) => {
|
|
824
|
+
this.resolveUser = i;
|
|
825
|
+
}), this.token.value && !this.activeUser.value ? this.getCurrentUser().then((i) => {
|
|
826
|
+
this.resolveUser && (this.resolveUser(i), this.resolveUser = void 0);
|
|
827
|
+
}).catch((i) => {
|
|
828
|
+
this.logger.error("Auto user fetch failed", { data: i }), this.resolveUser && (this.resolveUser(void 0), this.resolveUser = void 0);
|
|
920
829
|
}) : this.activeUser.value ? this.resolveUser?.(this.activeUser.value) : this.resolveUser?.(void 0);
|
|
921
830
|
}
|
|
922
831
|
/**
|
|
@@ -925,7 +834,7 @@ const T = new W(), j = class j extends O {
|
|
|
925
834
|
* Recommended: Use this instead of constructor for shared state
|
|
926
835
|
*/
|
|
927
836
|
static getInstance(t = {}) {
|
|
928
|
-
return T.get() || new
|
|
837
|
+
return T.get() || new N(t);
|
|
929
838
|
}
|
|
930
839
|
get isDev() {
|
|
931
840
|
return this.settings.isDev ?? (typeof window < "u" ? window.location.hostname === "localhost" || window.location.hostname.includes("127.0.0.1") : !1);
|
|
@@ -945,7 +854,7 @@ const T = new W(), j = class j extends O {
|
|
|
945
854
|
}
|
|
946
855
|
// Full reset - clears session + state + destroys singleton
|
|
947
856
|
clear() {
|
|
948
|
-
this.logger.info("Clearing SDK completely"), this.clearSession(), this.loading.value = !1, this.sessionId =
|
|
857
|
+
this.logger.info("Clearing SDK completely"), this.clearSession(), this.loading.value = !1, this.sessionId = O({ prefix: "ses" }), T.delete();
|
|
949
858
|
}
|
|
950
859
|
// Backward-compatible delegates -- these forward to sub-clients
|
|
951
860
|
// Can be removed in a future breaking change
|
|
@@ -979,24 +888,12 @@ const T = new W(), j = class j extends O {
|
|
|
979
888
|
async chatMessage(t) {
|
|
980
889
|
return this.chat.chatMessage(t);
|
|
981
890
|
}
|
|
982
|
-
async saveMessage(t) {
|
|
983
|
-
return this.chat.saveMessage(t);
|
|
984
|
-
}
|
|
985
891
|
async getPublicAgent(t) {
|
|
986
892
|
return this.user.getPublicAgent(t);
|
|
987
893
|
}
|
|
988
894
|
async getAgentByEmail(t) {
|
|
989
895
|
return this.user.getAgentByEmail(t);
|
|
990
896
|
}
|
|
991
|
-
async trackUsage(t) {
|
|
992
|
-
return this.user.trackUsage(t);
|
|
993
|
-
}
|
|
994
|
-
async startConversation(t) {
|
|
995
|
-
return this.user.startConversation(t);
|
|
996
|
-
}
|
|
997
|
-
async autoCreateContact(t) {
|
|
998
|
-
return this.user.autoCreateContact(t);
|
|
999
|
-
}
|
|
1000
897
|
generateAnonId() {
|
|
1001
898
|
return this.user.generateAnonId();
|
|
1002
899
|
}
|
|
@@ -1004,14 +901,14 @@ const T = new W(), j = class j extends O {
|
|
|
1004
901
|
return this.user.track(t);
|
|
1005
902
|
}
|
|
1006
903
|
};
|
|
1007
|
-
|
|
1008
|
-
let te =
|
|
904
|
+
l(N, "PageLinesSDK");
|
|
905
|
+
let te = N;
|
|
1009
906
|
export {
|
|
1010
|
-
|
|
907
|
+
M as A,
|
|
1011
908
|
_ as C,
|
|
1012
909
|
te as P,
|
|
1013
|
-
|
|
1014
|
-
|
|
910
|
+
j as S,
|
|
911
|
+
W as U,
|
|
1015
912
|
oe as c
|
|
1016
913
|
};
|
|
1017
|
-
//# sourceMappingURL=sdkClient-
|
|
914
|
+
//# sourceMappingURL=sdkClient--jt-zUDx.js.map
|