@pagelines/sdk 1.0.217 → 1.0.219

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.
Files changed (68) hide show
  1. package/dist/{AgentProvider.vue_vue_type_script_setup_true_lang-J2dPA8gh.js → AgentProvider.vue_vue_type_script_setup_true_lang-CsNF0TwT.js} +2 -2
  2. package/dist/AgentProvider.vue_vue_type_script_setup_true_lang-CsNF0TwT.js.map +1 -0
  3. package/dist/AgentWidgetInline-DG-ZuBMI.js +33 -0
  4. package/dist/AgentWidgetInline-DG-ZuBMI.js.map +1 -0
  5. package/dist/AgentWidgetModal-D-7lR3Yy.js +65 -0
  6. package/dist/AgentWidgetModal-D-7lR3Yy.js.map +1 -0
  7. package/dist/AgentWidgetPopup-C7vent2i.js +119 -0
  8. package/dist/AgentWidgetPopup-C7vent2i.js.map +1 -0
  9. package/dist/{AgentWrap.vue_vue_type_script_setup_true_lang-Cc3E_MFR.js → AgentWrap.vue_vue_type_script_setup_true_lang-TeMIjtid.js} +2102 -2664
  10. package/dist/AgentWrap.vue_vue_type_script_setup_true_lang-TeMIjtid.js.map +1 -0
  11. package/dist/agent/AgentController.d.ts +12 -43
  12. package/dist/agent/index.d.ts +1 -4
  13. package/dist/agent/schema.d.ts +2 -15
  14. package/dist/agent/ui/AgentChat.vue.d.ts +2 -2
  15. package/dist/agent/ui/AgentModal.vue.d.ts +2 -2
  16. package/dist/agent/ui/AgentProvider.vue.d.ts +3 -3
  17. package/dist/agent/ui/AgentWrap.vue.d.ts +21 -97
  18. package/dist/agent/ui/ElAgentAbout.vue.d.ts +1 -1
  19. package/dist/agent/ui/ElAgentChat.vue.d.ts +3 -3
  20. package/dist/agent/ui/ElAgentHeader.vue.d.ts +1 -1
  21. package/dist/agent/ui/ElAgentModeSidebar.vue.d.ts +2 -2
  22. package/dist/agent/ui/ElModeHeader.vue.d.ts +1 -1
  23. package/dist/agent/ui/ElSidebar.vue.d.ts +1 -1
  24. package/dist/agent/utils.d.ts +4 -3
  25. package/dist/agent.js +46 -57
  26. package/dist/agent.js.map +1 -1
  27. package/dist/clients/AuthClient.d.ts +1 -1
  28. package/dist/clients/UserClient.d.ts +3 -3
  29. package/dist/clients/types.d.ts +2 -3
  30. package/dist/constants/socialPlatforms.d.ts +1 -1
  31. package/dist/demo/index.d.ts +37 -37
  32. package/dist/demo.js.map +1 -1
  33. package/dist/index.d.ts +2 -2
  34. package/dist/sdk.css +1 -1
  35. package/dist/sdk.js +2 -2
  36. package/dist/sdkClient-IfuVpXGX.js +637 -0
  37. package/dist/sdkClient-IfuVpXGX.js.map +1 -0
  38. package/dist/sdkClient.d.ts +24 -25
  39. package/dist/sdkStorage.d.ts +1 -1
  40. package/dist/socialPlatforms-Ck-b3SnQ.js.map +1 -1
  41. package/dist/useWidgetState-BGtx6NKD.js +15 -0
  42. package/dist/useWidgetState-BGtx6NKD.js.map +1 -0
  43. package/dist/widget/PLWidget.d.ts +3 -3
  44. package/dist/widget/composables/usePLWidget.d.ts +2 -2
  45. package/dist/widget/composables/useWidgetState.d.ts +277 -0
  46. package/dist/widget/ui/AgentWidgetInline.vue.d.ts +5 -6
  47. package/dist/widget/ui/AgentWidgetModal.vue.d.ts +4 -5
  48. package/dist/widget/ui/AgentWidgetPopup.vue.d.ts +4 -5
  49. package/dist/widget.js +12 -11
  50. package/dist/widget.js.map +1 -1
  51. package/package.json +2 -2
  52. package/dist/AgentProvider.vue_vue_type_script_setup_true_lang-J2dPA8gh.js.map +0 -1
  53. package/dist/AgentWidgetInline-a7B42aCD.js +0 -37
  54. package/dist/AgentWidgetInline-a7B42aCD.js.map +0 -1
  55. package/dist/AgentWidgetModal-DmiBPAeW.js +0 -68
  56. package/dist/AgentWidgetModal-DmiBPAeW.js.map +0 -1
  57. package/dist/AgentWidgetPopup-kDs-plgY.js +0 -122
  58. package/dist/AgentWidgetPopup-kDs-plgY.js.map +0 -1
  59. package/dist/AgentWrap.vue_vue_type_script_setup_true_lang-Cc3E_MFR.js.map +0 -1
  60. package/dist/agent/ClientAudio.d.ts +0 -102
  61. package/dist/agent/constants.d.ts +0 -16
  62. package/dist/sdkClient-B3EKDRYb.js +0 -1094
  63. package/dist/sdkClient-B3EKDRYb.js.map +0 -1
  64. package/dist/utils/base.d.ts +0 -14
  65. package/dist/utils/color.d.ts +0 -12
  66. package/dist/utils/cookies.d.ts +0 -47
  67. package/dist/utils/id.d.ts +0 -27
  68. package/dist/utils/logger.d.ts +0 -49
@@ -1,1094 +0,0 @@
1
- var ie = Object.defineProperty;
2
- var he = (d, e, t) => e in d ? ie(d, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : d[e] = t;
3
- var s = (d, e) => ie(d, "name", { value: e, configurable: !0 });
4
- var a = (d, e, t) => he(d, typeof e != "symbol" ? e + "" : e, t);
5
- import { watch as ne, ref as T, computed as se } from "vue";
6
- import { APP_PORT as M, APP_PROD_URL as R } from "@pagelines/types";
7
- import { hc as de } from "hono/client";
8
- function ae(d = {}) {
9
- const { prefix: e = "id_" } = d, 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
- for (let i = 0; i < 16; i++)
12
- r += Math.floor(Math.random() * 16).toString(16);
13
- return t + o + r;
14
- }
15
- s(ae, "objectId$1");
16
- const $ = globalThis.process, y = typeof window < "u", G = typeof $ < "u" && !y, E = y ? typeof window < "u" && window.location && !window.location.hostname.includes("localhost") : G && typeof $ < "u" && $.env?.NODE_ENV === "production", ge = !E, D = {
17
- error: { priority: 50, color: "#FF0000", nodeColor: "\x1B[31m" },
18
- warn: { priority: 40, color: "#FFA500", nodeColor: "\x1B[33m" },
19
- info: { priority: 30, color: "#00ABFF", nodeColor: "\x1B[36m" },
20
- debug: { priority: 20, color: "#00BD0C", nodeColor: "\x1B[32m" },
21
- trace: { priority: 10, color: "#5233FF", nodeColor: "\x1B[35m" }
22
- }, fe = ["password", "token", "secret", "apikey", "api_key", "authorization", "cookie"];
23
- var m;
24
- let ce = (m = class {
25
- constructor(e = {}, t) {
26
- a(this, "settings");
27
- a(this, "enabledInBrowser", !1);
28
- a(this, "context");
29
- this.context = t, this.settings = {
30
- enabled: e.enabled ?? !0,
31
- minLevel: e.minLevel ?? this.getDefaultLevel(),
32
- timestamps: e.timestamps ?? !0
33
- }, y && this.initBrowserLogging();
34
- }
35
- getDefaultLevel() {
36
- if (G && typeof $ < "u" && $.env?.LOG_LEVEL)
37
- return $.env.LOG_LEVEL;
38
- if (y && typeof localStorage < "u" && typeof localStorage.getItem == "function") {
39
- const e = localStorage.getItem("PAGELINES_LOG_LEVEL");
40
- if (e)
41
- return e;
42
- }
43
- return "info";
44
- }
45
- initBrowserLogging() {
46
- if (!y)
47
- return;
48
- const t = typeof localStorage?.getItem == "function" && localStorage.getItem("PAGELINES_LOG") === "true", o = window.location?.hostname || "";
49
- this.enabledInBrowser = ge || t || o === "localhost" || o.includes("127.0.0.1"), E && !t && !m.hasShownHelp && (console.log(
50
- "%cPageLines Logger (disabled in production)",
51
- "color: #888; font-size: 12px"
52
- ), console.log(
53
- '%cTo enable: localStorage.setItem("PAGELINES_LOG", "true")',
54
- "color: #888; font-size: 11px"
55
- ), m.hasShownHelp = !0);
56
- }
57
- shouldLog(e) {
58
- if (!this.settings.enabled || y && !this.enabledInBrowser)
59
- return !1;
60
- const t = D[e].priority, o = D[this.settings.minLevel].priority;
61
- return t >= o;
62
- }
63
- formatTimestamp() {
64
- return (/* @__PURE__ */ new Date()).toLocaleTimeString("en-GB", {
65
- hour12: !1,
66
- hour: "2-digit",
67
- minute: "2-digit",
68
- second: "2-digit"
69
- });
70
- }
71
- formatISOTimestamp() {
72
- return (/* @__PURE__ */ new Date()).toISOString();
73
- }
74
- redactSensitive(e) {
75
- if (typeof e != "object" || e === null)
76
- return e;
77
- if (Array.isArray(e))
78
- return e.map((o) => this.redactSensitive(o));
79
- const t = {};
80
- for (const [o, r] of Object.entries(e)) {
81
- const i = o.toLowerCase();
82
- fe.some((n) => i.includes(n)) ? t[o] = "[REDACTED]" : typeof r == "object" && r !== null ? t[o] = this.redactSensitive(r) : t[o] = r;
83
- }
84
- return t;
85
- }
86
- formatData(e, t = 3, o = 0) {
87
- if (o >= t)
88
- return "[Max Depth]";
89
- if (e == null)
90
- return e;
91
- if (e instanceof Error)
92
- return {
93
- name: e.name,
94
- message: e.message,
95
- stack: E ? e.stack?.split(`
96
- `).slice(0, 3).join(`
97
- `) : e.stack,
98
- ...e
99
- // Include any additional error properties
100
- };
101
- if (e instanceof Date)
102
- return e.toISOString();
103
- if (typeof e != "object")
104
- return e;
105
- if (Array.isArray(e))
106
- return e.length > 20 && E ? `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));
107
- try {
108
- const r = {}, i = Object.entries(e), n = E ? 50 : 200;
109
- for (const [u, c] of i.slice(0, n))
110
- r[u] = this.formatData(c, t, o + 1);
111
- return i.length > n && (r["..."] = `${i.length - n} more properties`), this.redactSensitive(r);
112
- } catch {
113
- return "[Unserializable]";
114
- }
115
- }
116
- logToBrowser(e) {
117
- if (!y || !this.shouldLog(e.level))
118
- return;
119
- const { level: t, description: o, context: r, data: i, error: n } = e, u = D[t], l = `[${r || this.context || "www"}] ${t.toUpperCase()}:`, h = `color: ${u.color}; font-weight: bold;`;
120
- i !== void 0 ? console[t](`%c${l}`, h, o, this.formatData(i)) : console[t](`%c${l}`, h, o), n && (n instanceof Error ? console.error(n) : console.error("Error details:", n));
121
- }
122
- logToNode(e) {
123
- if (!G || !this.shouldLog(e.level))
124
- return;
125
- const { level: t, description: o, context: r, data: i, error: n } = e, u = r || this.context || "www";
126
- if (E) {
127
- const c = {
128
- timestamp: this.formatISOTimestamp(),
129
- level: t.toUpperCase()
130
- };
131
- i && (c.data = this.formatData(i)), n && (c.error = this.formatData(n)), console[t](`${c.timestamp} ${c.level} [${u}] ${o}`, i || n ? JSON.stringify({ data: i, error: n }) : "");
132
- } else {
133
- const c = D[t], l = this.formatTimestamp(), h = "\x1B[0m", S = "\x1B[2m", g = c.nodeColor || "", k = `${S}${l}${h} ${g}${t.toUpperCase()} (${u}):${h} ${o}`;
134
- console[t](k), i !== void 0 && console.log(JSON.stringify(this.formatData(i), null, 2)), n && (n instanceof Error ? (console.error(`\x1B[31mError:${h}`, n.message), n.stack && console.error(`\x1B[90m${n.stack}${h}`)) : console.error("Error:", n));
135
- }
136
- }
137
- log(e) {
138
- y ? this.logToBrowser(e) : G && this.logToNode(e);
139
- }
140
- error(e, t) {
141
- this.log({ level: "error", description: e, data: t, context: this.context });
142
- }
143
- warn(e, t) {
144
- this.log({ level: "warn", description: e, data: t, context: this.context });
145
- }
146
- info(e, t) {
147
- this.log({ level: "info", description: e, data: t, context: this.context });
148
- }
149
- debug(e, t) {
150
- this.log({ level: "debug", description: e, data: t, context: this.context });
151
- }
152
- trace(e, t) {
153
- this.log({ level: "trace", description: e, data: t, context: this.context });
154
- }
155
- isEnabled() {
156
- return y ? this.enabledInBrowser : !0;
157
- }
158
- setLevel(e) {
159
- this.settings.minLevel = e;
160
- }
161
- createContextLogger(e) {
162
- const t = new m(this.settings, e);
163
- return {
164
- error: /* @__PURE__ */ s((o, r) => t.error(o, r), "error"),
165
- warn: /* @__PURE__ */ s((o, r) => t.warn(o, r), "warn"),
166
- info: /* @__PURE__ */ s((o, r) => t.info(o, r), "info"),
167
- debug: /* @__PURE__ */ s((o, r) => t.debug(o, r), "debug"),
168
- trace: /* @__PURE__ */ s((o, r) => t.trace(o, r), "trace"),
169
- isEnabled: /* @__PURE__ */ s(() => t.isEnabled(), "isEnabled"),
170
- setLevel: /* @__PURE__ */ s((o) => t.setLevel(o), "setLevel")
171
- };
172
- }
173
- }, s(m, "Logger"), a(m, "hasShownHelp", !1), m);
174
- function pe(d) {
175
- return new ce({}, d);
176
- }
177
- s(pe, "createLogger$1");
178
- const v = new ce();
179
- v.error.bind(v);
180
- v.warn.bind(v);
181
- v.info.bind(v);
182
- v.debug.bind(v);
183
- v.trace.bind(v);
184
- const Y = class Y {
185
- constructor(e, t) {
186
- a(this, "name");
187
- a(this, "settings");
188
- a(this, "logger");
189
- this.name = e, this.settings = t, this.logger = pe(e);
190
- }
191
- };
192
- s(Y, "SettingsObject");
193
- let V = Y;
194
- const X = class X {
195
- constructor() {
196
- // Configuration properties
197
- a(this, "tokenName", "auth-token");
198
- a(this, "tokenMaxAge", 3600 * 24 * 7);
199
- // 7 days
200
- a(this, "fallbackStorageKey", "token");
201
- // For localStorage migration
202
- a(this, "productionDomain", ".pagelines.com");
203
- }
204
- /**
205
- * Get cookie value by name
206
- */
207
- getCookie(e) {
208
- if (typeof document > "u")
209
- return null;
210
- const t = document.cookie.split(";");
211
- for (const o of t) {
212
- const [r, i] = o.trim().split("=");
213
- if (r === e)
214
- return decodeURIComponent(i || "");
215
- }
216
- return null;
217
- }
218
- /**
219
- * Set cookie with secure defaults
220
- */
221
- setCookie(e, t, o = {}) {
222
- if (typeof document > "u")
223
- return;
224
- const {
225
- secure: r = !0,
226
- sameSite: i = "lax",
227
- maxAge: n = 3600 * 24 * 7,
228
- // 7 days default
229
- domain: u,
230
- path: c = "/"
231
- } = o;
232
- let l = `${e}=${encodeURIComponent(t)}`;
233
- l += `; Path=${c}`, l += `; Max-Age=${n}`, l += `; SameSite=${i}`, r && (l += "; Secure"), u && (l += `; Domain=${u}`), document.cookie = l;
234
- }
235
- /**
236
- * Remove cookie by setting expired date
237
- */
238
- removeCookie(e, t = {}) {
239
- this.setCookie(e, "", { ...t, maxAge: 0 });
240
- }
241
- /**
242
- * Check if localStorage is fully functional (some test environments provide partial mocks)
243
- */
244
- isLocalStorageFunctional() {
245
- return typeof window < "u" && typeof window.localStorage?.getItem == "function" && typeof window.localStorage?.setItem == "function" && typeof window.localStorage?.removeItem == "function";
246
- }
247
- /**
248
- * Get auth token with fallback to localStorage for migration
249
- */
250
- getAuthToken() {
251
- const e = this.getCookie(this.tokenName);
252
- if (e)
253
- return e;
254
- if (this.isLocalStorageFunctional()) {
255
- const t = window.localStorage.getItem(this.fallbackStorageKey);
256
- if (t)
257
- return this.setAuthToken(t), window.localStorage.removeItem(this.fallbackStorageKey), t;
258
- }
259
- return null;
260
- }
261
- /**
262
- * Set auth token in cookie with production-ready settings
263
- */
264
- setAuthToken(e) {
265
- const t = typeof window < "u" && window.location.hostname !== "localhost";
266
- this.setCookie(this.tokenName, e, {
267
- secure: t,
268
- sameSite: "lax",
269
- maxAge: this.tokenMaxAge,
270
- domain: t ? this.productionDomain : void 0,
271
- path: "/"
272
- });
273
- }
274
- /**
275
- * Remove auth token
276
- */
277
- removeAuthToken() {
278
- const e = typeof window < "u" && window.location.hostname !== "localhost";
279
- this.removeCookie(this.tokenName, {
280
- domain: e ? this.productionDomain : void 0,
281
- path: "/"
282
- }), this.isLocalStorageFunctional() && window.localStorage.removeItem(this.fallbackStorageKey);
283
- }
284
- };
285
- s(X, "CookieUtil");
286
- let z = X;
287
- const C = new z();
288
- function me(d, e) {
289
- const t = d.apiBase || (d.isDev ? `http://localhost:${M}` : R);
290
- return de(t, {
291
- fetch: /* @__PURE__ */ s(async (r, i) => {
292
- const n = C.getAuthToken(), u = await fetch(r, {
293
- ...i,
294
- headers: {
295
- ...i?.headers,
296
- "Content-Type": "application/json",
297
- // Only include Authorization header if token exists
298
- ...n && { Authorization: `Bearer ${n}` }
299
- },
300
- // Use 'omit' for Bearer tokens (not cookies) to allow CORS wildcard origin
301
- credentials: "omit"
302
- });
303
- if (e) {
304
- const c = u.json.bind(u);
305
- u.json = async () => {
306
- const l = await c();
307
- return typeof l == "object" && l !== null && "ok" in l && ("user" in l || "token" in l) && e(l), l;
308
- };
309
- }
310
- return u;
311
- }, "fetch")
312
- });
313
- }
314
- s(me, "createApiClient");
315
- let ve = /* @__PURE__ */ Symbol("clean"), p = [], I = 0;
316
- const U = 4, ue = /* @__PURE__ */ s(/* @__NO_SIDE_EFFECTS__ */ (d) => {
317
- let e = [], t = {
318
- get() {
319
- return t.lc || t.listen(() => {
320
- })(), t.value;
321
- },
322
- lc: 0,
323
- listen(o) {
324
- return t.lc = e.push(o), () => {
325
- for (let i = I + U; i < p.length; )
326
- p[i] === o ? p.splice(i, U) : i += U;
327
- let r = e.indexOf(o);
328
- ~r && (e.splice(r, 1), --t.lc || t.off());
329
- };
330
- },
331
- notify(o, r) {
332
- let i = !p.length;
333
- for (let n of e)
334
- p.push(n, t.value, o, r);
335
- if (i) {
336
- for (I = 0; I < p.length; I += U)
337
- p[I](
338
- p[I + 1],
339
- p[I + 2],
340
- p[I + 3]
341
- );
342
- p.length = 0;
343
- }
344
- },
345
- /* It will be called on last listener unsubscribing.
346
- We will redefine it in onMount and onStop. */
347
- off() {
348
- },
349
- set(o) {
350
- let r = t.value;
351
- r !== o && (t.value = o, t.notify(r));
352
- },
353
- subscribe(o) {
354
- let r = t.listen(o);
355
- return o(t.value), r;
356
- },
357
- value: d
358
- };
359
- return process.env.NODE_ENV !== "production" && (t[ve] = () => {
360
- e = [], t.lc = 0, t.off();
361
- }), t;
362
- }, "atom"), A = globalThis.process, x = typeof window < "u", j = typeof A < "u" && !x, b = x ? typeof window < "u" && window.location && !window.location.hostname.includes("localhost") : j && typeof A < "u" && A.env?.NODE_ENV === "production", we = !b, P = {
363
- error: { priority: 50, color: "#FF0000", nodeColor: "\x1B[31m" },
364
- warn: { priority: 40, color: "#FFA500", nodeColor: "\x1B[33m" },
365
- info: { priority: 30, color: "#00ABFF", nodeColor: "\x1B[36m" },
366
- debug: { priority: 20, color: "#00BD0C", nodeColor: "\x1B[32m" },
367
- trace: { priority: 10, color: "#5233FF", nodeColor: "\x1B[35m" }
368
- }, ye = ["password", "token", "secret", "apikey", "api_key", "authorization", "cookie"], L = class L {
369
- constructor(e = {}, t) {
370
- a(this, "settings");
371
- a(this, "enabledInBrowser", !1);
372
- a(this, "context");
373
- this.context = t, this.settings = {
374
- enabled: e.enabled ?? !0,
375
- minLevel: e.minLevel ?? this.getDefaultLevel(),
376
- timestamps: e.timestamps ?? !0
377
- }, x && this.initBrowserLogging();
378
- }
379
- getDefaultLevel() {
380
- if (j && typeof A < "u" && A.env?.LOG_LEVEL)
381
- return A.env.LOG_LEVEL;
382
- if (x && typeof localStorage < "u" && typeof localStorage.getItem == "function") {
383
- const e = localStorage.getItem("PAGELINES_LOG_LEVEL");
384
- if (e)
385
- return e;
386
- }
387
- return b ? "info" : "debug";
388
- }
389
- initBrowserLogging() {
390
- if (!x)
391
- return;
392
- const t = typeof localStorage?.getItem == "function" && localStorage.getItem("PAGELINES_LOG") === "true", o = window.location?.hostname || "";
393
- this.enabledInBrowser = we || t || o === "localhost" || o.includes("127.0.0.1"), b && !t && !L.hasShownHelp && (console.log(
394
- "%cPageLines Logger (disabled in production)",
395
- "color: #888; font-size: 12px"
396
- ), console.log(
397
- '%cTo enable: localStorage.setItem("PAGELINES_LOG", "true")',
398
- "color: #888; font-size: 11px"
399
- ), L.hasShownHelp = !0);
400
- }
401
- shouldLog(e) {
402
- if (!this.settings.enabled || x && !this.enabledInBrowser)
403
- return !1;
404
- const t = P[e].priority, o = P[this.settings.minLevel].priority;
405
- return t >= o;
406
- }
407
- formatTimestamp() {
408
- return (/* @__PURE__ */ new Date()).toLocaleTimeString("en-GB", {
409
- hour12: !1,
410
- hour: "2-digit",
411
- minute: "2-digit",
412
- second: "2-digit"
413
- });
414
- }
415
- formatISOTimestamp() {
416
- return (/* @__PURE__ */ new Date()).toISOString();
417
- }
418
- redactSensitive(e) {
419
- if (typeof e != "object" || e === null)
420
- return e;
421
- if (Array.isArray(e))
422
- return e.map((o) => this.redactSensitive(o));
423
- const t = {};
424
- for (const [o, r] of Object.entries(e)) {
425
- const i = o.toLowerCase();
426
- ye.some((n) => i.includes(n)) ? t[o] = "[REDACTED]" : typeof r == "object" && r !== null ? t[o] = this.redactSensitive(r) : t[o] = r;
427
- }
428
- return t;
429
- }
430
- formatData(e, t = 3, o = 0) {
431
- if (o >= t)
432
- return "[Max Depth]";
433
- if (e == null)
434
- return e;
435
- if (e instanceof Error)
436
- return {
437
- name: e.name,
438
- message: e.message,
439
- stack: b ? e.stack?.split(`
440
- `).slice(0, 3).join(`
441
- `) : e.stack,
442
- ...e
443
- // Include any additional error properties
444
- };
445
- if (e instanceof Date)
446
- return e.toISOString();
447
- if (typeof e != "object")
448
- return e;
449
- if (Array.isArray(e))
450
- return e.length > 20 && b ? `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));
451
- try {
452
- const r = {}, i = Object.entries(e), n = b ? 50 : 200;
453
- for (const [u, c] of i.slice(0, n))
454
- r[u] = this.formatData(c, t, o + 1);
455
- return i.length > n && (r["..."] = `${i.length - n} more properties`), this.redactSensitive(r);
456
- } catch {
457
- return "[Unserializable]";
458
- }
459
- }
460
- logToBrowser(e) {
461
- if (!x || !this.shouldLog(e.level))
462
- return;
463
- const { level: t, description: o, context: r, data: i, error: n } = e, u = P[t], l = `[${r || this.context || "www"}] ${t.toUpperCase()}:`, h = `color: ${u.color}; font-weight: bold;`;
464
- i !== void 0 ? console[t](`%c${l}`, h, o, this.formatData(i)) : console[t](`%c${l}`, h, o), n && (n instanceof Error ? console.error(n) : console.error("Error details:", n));
465
- }
466
- logToNode(e) {
467
- if (!j || !this.shouldLog(e.level))
468
- return;
469
- const { level: t, description: o, context: r, data: i, error: n } = e, u = r || this.context || "www";
470
- if (b) {
471
- const c = {
472
- timestamp: this.formatISOTimestamp(),
473
- level: t.toUpperCase()
474
- };
475
- i && (c.data = this.formatData(i)), n && (c.error = this.formatData(n)), console[t](`${c.timestamp} ${c.level} [${u}] ${o}`, i || n ? JSON.stringify({ data: i, error: n }) : "");
476
- } else {
477
- const c = P[t], l = this.formatTimestamp(), h = "\x1B[0m", S = "\x1B[2m", g = c.nodeColor || "", k = `${S}${l}${h} ${g}${t.toUpperCase()} (${u}):${h} ${o}`;
478
- console[t](k), i !== void 0 && console.log(JSON.stringify(this.formatData(i), null, 2)), n && (n instanceof Error ? (console.error(`\x1B[31mError:${h}`, n.message), n.stack && console.error(`\x1B[90m${n.stack}${h}`)) : console.error("Error:", n));
479
- }
480
- }
481
- log(e) {
482
- x ? this.logToBrowser(e) : j && this.logToNode(e);
483
- }
484
- error(e, t) {
485
- this.log({ level: "error", description: e, data: t, context: this.context });
486
- }
487
- warn(e, t) {
488
- this.log({ level: "warn", description: e, data: t, context: this.context });
489
- }
490
- info(e, t) {
491
- this.log({ level: "info", description: e, data: t, context: this.context });
492
- }
493
- debug(e, t) {
494
- this.log({ level: "debug", description: e, data: t, context: this.context });
495
- }
496
- trace(e, t) {
497
- this.log({ level: "trace", description: e, data: t, context: this.context });
498
- }
499
- isEnabled() {
500
- return x ? this.enabledInBrowser : !0;
501
- }
502
- setLevel(e) {
503
- this.settings.minLevel = e;
504
- }
505
- createContextLogger(e) {
506
- const t = new L(this.settings, e);
507
- return {
508
- error: /* @__PURE__ */ s((o, r) => t.error(o, r), "error"),
509
- warn: /* @__PURE__ */ s((o, r) => t.warn(o, r), "warn"),
510
- info: /* @__PURE__ */ s((o, r) => t.info(o, r), "info"),
511
- debug: /* @__PURE__ */ s((o, r) => t.debug(o, r), "debug"),
512
- trace: /* @__PURE__ */ s((o, r) => t.trace(o, r), "trace"),
513
- isEnabled: /* @__PURE__ */ s(() => t.isEnabled(), "isEnabled"),
514
- setLevel: /* @__PURE__ */ s((o) => t.setLevel(o), "setLevel")
515
- };
516
- }
517
- };
518
- s(L, "Logger"), a(L, "hasShownHelp", !1);
519
- let _ = L;
520
- function xe(d) {
521
- return new _({}, d);
522
- }
523
- s(xe, "createLogger");
524
- const w = new _();
525
- w.error.bind(w);
526
- w.warn.bind(w);
527
- w.info.bind(w);
528
- w.debug.bind(w);
529
- w.trace.bind(w);
530
- const F = /* @__PURE__ */ ue(void 0), O = /* @__PURE__ */ ue(null), Z = class Z {
531
- constructor() {
532
- a(this, "logger", xe("SDKStorage"));
533
- }
534
- /**
535
- * Check if localStorage is fully functional (some test environments provide partial mocks)
536
- */
537
- isLocalStorageFunctional() {
538
- return typeof window < "u" && typeof localStorage?.getItem == "function" && typeof localStorage?.setItem == "function" && typeof localStorage?.removeItem == "function";
539
- }
540
- /**
541
- * Sync Vue reactive refs with global nanostores for cross-page persistence
542
- */
543
- syncWithGlobalStores(e, t) {
544
- const o = F.get(), r = O.get();
545
- o && (e.value = o), r && (t.value = r), ne(e, (i) => {
546
- F.set(i);
547
- }, { immediate: !0 }), ne(t, (i) => {
548
- O.set(i);
549
- }, { immediate: !0 }), F.subscribe((i) => {
550
- i !== e.value && (e.value = i);
551
- }), O.subscribe((i) => {
552
- i !== t.value && (t.value = i);
553
- });
554
- }
555
- /**
556
- * Load user and token from browser storage on initialization
557
- */
558
- loadFromStorage(e, t) {
559
- if (typeof window > "u")
560
- return;
561
- const o = C.getAuthToken();
562
- if (o && (t.value = o), this.isLocalStorageFunctional())
563
- try {
564
- const r = localStorage.getItem("pagelines-user");
565
- r && (e.value = JSON.parse(r));
566
- } catch (r) {
567
- this.logger.error("Failed to load user from localStorage", { data: r });
568
- }
569
- }
570
- /**
571
- * Save current user and token to browser storage
572
- */
573
- saveToStorage(e, t) {
574
- if (!(typeof window > "u") && (t.value ? C.setAuthToken(t.value) : C.removeAuthToken(), this.isLocalStorageFunctional()))
575
- try {
576
- e.value ? localStorage.setItem("pagelines-user", JSON.stringify(e.value)) : localStorage.removeItem("pagelines-user");
577
- } catch (o) {
578
- this.logger.error("Failed to save user to localStorage", { data: o });
579
- }
580
- }
581
- /**
582
- * Clear all stored user data and tokens
583
- */
584
- clearStorage() {
585
- if (!(typeof window > "u")) {
586
- if (C.removeAuthToken(), this.isLocalStorageFunctional())
587
- try {
588
- localStorage.removeItem("pagelines-user");
589
- } catch (e) {
590
- this.logger.error("Failed to clear user from localStorage", { data: e });
591
- }
592
- F.set(void 0), O.set(null);
593
- }
594
- }
595
- /**
596
- * Generic localStorage getter
597
- */
598
- getItem(e) {
599
- if (!this.isLocalStorageFunctional())
600
- return null;
601
- try {
602
- return localStorage.getItem(e);
603
- } catch (t) {
604
- return this.logger.error("Failed to get item from localStorage", { key: e, error: t }), null;
605
- }
606
- }
607
- /**
608
- * Generic localStorage setter
609
- */
610
- setItem(e, t) {
611
- if (this.isLocalStorageFunctional())
612
- try {
613
- localStorage.setItem(e, t);
614
- } catch (o) {
615
- this.logger.error("Failed to set item in localStorage", { key: e, error: o });
616
- }
617
- }
618
- };
619
- s(Z, "SDKStorage");
620
- let W = Z;
621
- const ee = class ee {
622
- constructor(e) {
623
- this.ctx = e;
624
- }
625
- async sendCode(e) {
626
- this.ctx.loading.value = !0, this.ctx.error.value = null;
627
- try {
628
- const o = await (await this.ctx.api.auth["check-email"].$post({
629
- json: { email: e }
630
- })).json();
631
- if (!o.ok)
632
- throw this.ctx.error.value = o.error, new Error(o.error);
633
- } catch (t) {
634
- this.ctx.logger.error("Send code error", { data: t });
635
- const o = t instanceof Error ? t.message : "Failed to send verification code";
636
- throw this.ctx.error.value = o, t;
637
- } finally {
638
- this.ctx.loading.value = !1;
639
- }
640
- }
641
- async verifyCode(e, t) {
642
- this.ctx.loading.value = !0, this.ctx.error.value = null;
643
- try {
644
- const r = await (await this.ctx.api.auth["verify-code"].$post({
645
- json: { email: e, code: t }
646
- })).json();
647
- if (!r.ok)
648
- throw this.ctx.error.value = r.error, new Error(r.error);
649
- } catch (o) {
650
- this.ctx.logger.error("Verify code error", { data: o });
651
- const r = o instanceof Error ? o.message : "Failed to verify code";
652
- throw this.ctx.error.value = r, o;
653
- } finally {
654
- this.ctx.loading.value = !1;
655
- }
656
- }
657
- async login(e, t) {
658
- this.ctx.loading.value = !0, this.ctx.error.value = null;
659
- try {
660
- const r = await (await this.ctx.api.auth.login.$post({
661
- json: { email: e, password: t }
662
- })).json();
663
- if (!r.ok)
664
- throw this.ctx.error.value = r.error, new Error(r.error);
665
- } catch (o) {
666
- this.ctx.logger.error("Login error", { data: o });
667
- const r = o instanceof Error ? o.message : "Login failed";
668
- throw this.ctx.error.value = r, o;
669
- } finally {
670
- this.ctx.loading.value = !1;
671
- }
672
- }
673
- async logout() {
674
- this.ctx.loading.value = !0, this.ctx.error.value = null;
675
- try {
676
- await this.ctx.api.auth.logout.$post(), this.ctx.activeUser.value = void 0, this.ctx.token.value = null, this.ctx.storage.clearStorage();
677
- } catch (e) {
678
- this.ctx.logger.error("Logout error (user still logged out locally)", { data: e }), this.ctx.activeUser.value = void 0, this.ctx.token.value = null, this.ctx.storage.clearStorage();
679
- } finally {
680
- this.ctx.loading.value = !1;
681
- }
682
- }
683
- async getCurrentUser() {
684
- if (this.ctx.token.value) {
685
- this.ctx.loading.value = !0;
686
- try {
687
- const t = await (await this.ctx.api.auth.me.$get()).json();
688
- if (!t.ok) {
689
- this.ctx.error.value = t.error, t.error.includes("Authentication") && (this.ctx.activeUser.value = void 0, this.ctx.token.value = null, this.ctx.storage.clearStorage());
690
- return;
691
- }
692
- return t.user;
693
- } catch (e) {
694
- this.ctx.logger.error("Get current user error", { data: e }), this.ctx.error.value = e instanceof Error ? e.message : "Failed to get user info";
695
- return;
696
- } finally {
697
- this.ctx.loading.value = !1;
698
- }
699
- }
700
- }
701
- async requestAuthCode(e) {
702
- this.ctx.loading.value = !0, this.ctx.error.value = null;
703
- try {
704
- const o = await (await this.ctx.api.auth["check-email"].$post({
705
- json: { email: e.email }
706
- })).json();
707
- 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);
708
- } catch (t) {
709
- 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;
710
- } finally {
711
- this.ctx.loading.value = !1;
712
- }
713
- }
714
- async loginWithCode(e) {
715
- this.ctx.loading.value = !0, this.ctx.error.value = null;
716
- try {
717
- const o = await (await this.ctx.api.auth["verify-code"].$post({
718
- json: { email: e.email, code: e.code }
719
- })).json();
720
- 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);
721
- } catch (t) {
722
- 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;
723
- } finally {
724
- this.ctx.loading.value = !1;
725
- }
726
- }
727
- loginWithGoogle(e) {
728
- if (typeof window > "u") {
729
- this.ctx.logger.error("loginWithGoogle: Only available in browser");
730
- return;
731
- }
732
- const t = this.ctx.apiBase || (this.ctx.isDev ? `http://localhost:${M}` : R), o = window.location.origin, r = `${t}/auth/google-popup?origin=${encodeURIComponent(o)}`, i = 500, n = 600, u = window.screenX + (window.outerWidth - i) / 2, c = window.screenY + (window.outerHeight - n) / 2, l = window.open(
733
- r,
734
- "google-auth",
735
- `width=${i},height=${n},left=${u},top=${c},popup=yes`
736
- );
737
- if (!l) {
738
- const g = "Popup was blocked. Please allow popups for this site.";
739
- this.ctx.error.value = g, e?.onError?.(g);
740
- return;
741
- }
742
- const h = /* @__PURE__ */ s((g) => {
743
- const k = new URL(t).origin;
744
- if (g.origin === k) {
745
- if (g.data?.type === "auth-success") {
746
- window.removeEventListener("message", h);
747
- const { token: f, user: B } = g.data;
748
- this.ctx.processApiResponse({ ok: !0, data: {}, token: f, user: B }), this.ctx.logger.info("Google login successful"), e?.onSuccess?.(B);
749
- } else if (g.data?.type === "auth-error") {
750
- window.removeEventListener("message", h);
751
- const f = g.data.error || "Google authentication failed";
752
- this.ctx.error.value = f, this.ctx.logger.error("Google login failed", { error: f }), e?.onError?.(f);
753
- }
754
- }
755
- }, "handler");
756
- window.addEventListener("message", h);
757
- const S = setInterval(() => {
758
- l.closed && (clearInterval(S), window.removeEventListener("message", h));
759
- }, 500);
760
- }
761
- };
762
- s(ee, "AuthClient");
763
- let J = ee;
764
- const te = class te {
765
- constructor(e) {
766
- this.ctx = e;
767
- }
768
- async chatStream(e) {
769
- const o = `${this.ctx.apiBase || (this.ctx.isDev ? `http://localhost:${M}` : R)}/api/agent/public/${encodeURIComponent(e.handle)}/chat/stream`;
770
- try {
771
- const r = await fetch(o, {
772
- method: "POST",
773
- headers: { "Content-Type": "application/json" },
774
- body: JSON.stringify({
775
- message: e.message,
776
- conversationId: e.conversationId,
777
- history: e.history,
778
- visitorId: e.visitorId,
779
- context: e.context,
780
- attachments: e.attachments
781
- })
782
- });
783
- if (!r.ok) {
784
- const l = await r.json().catch(() => ({ error: "Request failed" }));
785
- e.onError(l.error || `HTTP ${r.status}`);
786
- return;
787
- }
788
- const i = r.body?.getReader();
789
- if (!i) {
790
- e.onError("No response stream");
791
- return;
792
- }
793
- const n = new TextDecoder();
794
- let u = "", c = e.conversationId || "";
795
- for (; ; ) {
796
- const { done: l, value: h } = await i.read();
797
- if (l)
798
- break;
799
- u += n.decode(h, { stream: !0 });
800
- const S = u.split(`
801
- `);
802
- u = S.pop() || "";
803
- for (const g of S) {
804
- if (!g.startsWith("data: "))
805
- continue;
806
- const k = g.slice(6).trim();
807
- if (k === "[DONE]") {
808
- e.onDone(c);
809
- return;
810
- }
811
- try {
812
- const f = JSON.parse(k);
813
- if (f.pl_status) {
814
- e.onStatus?.(f.pl_status);
815
- continue;
816
- }
817
- f.pl_metadata?.conversationId && (c = f.pl_metadata.conversationId);
818
- const B = f.choices?.[0]?.delta;
819
- B?.content && e.onDelta(B.content);
820
- } catch {
821
- }
822
- }
823
- }
824
- e.onDone(c);
825
- } catch (r) {
826
- e.onError(r instanceof Error ? r.message : "Stream failed");
827
- }
828
- }
829
- async chatMessage(e) {
830
- const o = `${this.ctx.apiBase || (this.ctx.isDev ? `http://localhost:${M}` : R)}/api/agent/public/${encodeURIComponent(e.handle)}/chat`;
831
- try {
832
- const i = await (await fetch(o, {
833
- method: "POST",
834
- headers: { "Content-Type": "application/json" },
835
- body: JSON.stringify({
836
- message: e.message,
837
- conversationId: e.conversationId,
838
- visitorId: e.visitorId,
839
- context: e.context
840
- })
841
- })).json();
842
- if (!i.ok || !i.data) {
843
- this.ctx.logger.error("chatMessage failed", { error: !i.ok && "error" in i ? i.error : "Unknown" });
844
- return;
845
- }
846
- return {
847
- conversationId: i.data.conversationId,
848
- content: i.data.message.content
849
- };
850
- } catch (r) {
851
- this.ctx.logger.error("chatMessage error", { error: r });
852
- return;
853
- }
854
- }
855
- };
856
- s(te, "ChatClient");
857
- let q = te;
858
- function Se(d = {}) {
859
- const { prefix: e = "id_" } = d, t = e.length >= 3 ? e.substring(0, 3) : e.padEnd(3, "_"), o = Math.floor(Date.now() / 1e3).toString(16).padStart(8, "0");
860
- let r = "";
861
- for (let i = 0; i < 16; i++)
862
- r += Math.floor(Math.random() * 16).toString(16);
863
- return t + o + r;
864
- }
865
- s(Se, "objectId");
866
- const oe = class oe {
867
- constructor(e) {
868
- this.ctx = e;
869
- }
870
- async getPublicAgent(e) {
871
- this.ctx.loading.value = !0, this.ctx.error.value = null;
872
- try {
873
- const o = await (await this.ctx.api.agent.public[":handle"].$get({
874
- param: { handle: e.handle }
875
- })).json();
876
- if (!o.ok) {
877
- this.ctx.error.value = o.error, this.ctx.logger.error("Failed to fetch public agent", { handle: e.handle, error: o.error });
878
- return;
879
- }
880
- return o.data;
881
- } catch (t) {
882
- 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";
883
- return;
884
- } finally {
885
- this.ctx.loading.value = !1;
886
- }
887
- }
888
- async getAgentByEmail(e) {
889
- this.ctx.loading.value = !0, this.ctx.error.value = null;
890
- try {
891
- const o = await (await this.ctx.api.agent["by-email"][":email"].$get({
892
- param: { email: e.email }
893
- })).json();
894
- if (!o.ok) {
895
- this.ctx.error.value = o.error, this.ctx.logger.error("Failed to fetch agent by email", { email: e.email, error: o.error });
896
- return;
897
- }
898
- return o.data;
899
- } catch (t) {
900
- 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";
901
- return;
902
- } finally {
903
- this.ctx.loading.value = !1;
904
- }
905
- }
906
- generateAnonId() {
907
- const e = "pagelinesAnonId";
908
- let t = this.ctx.storage.getItem(e);
909
- return t || (t = Se({ prefix: "anon" }), this.ctx.storage.setItem(e, t)), t;
910
- }
911
- track(e) {
912
- try {
913
- typeof window < "u" && window.parent !== window && window.parent.postMessage({
914
- type: "pagelines_track",
915
- event: e.event,
916
- agentId: e.agentId,
917
- properties: e.properties || {}
918
- }, "*"), this.ctx.logger.info("SDK event tracked", { event: e.event, agentId: e.agentId });
919
- } catch (t) {
920
- this.ctx.logger.error("Track event error", { error: t, args: e });
921
- }
922
- }
923
- };
924
- s(oe, "UserClient");
925
- let H = oe;
926
- const re = class re {
927
- constructor() {
928
- a(this, "key", "__PAGELINES_SDK__");
929
- }
930
- get() {
931
- if (!(typeof window > "u"))
932
- return globalThis[this.key];
933
- }
934
- set(e) {
935
- typeof window < "u" && (globalThis[this.key] = e);
936
- }
937
- delete() {
938
- typeof window < "u" && delete globalThis[this.key];
939
- }
940
- };
941
- s(re, "SDKGlobal");
942
- let Q = re;
943
- const N = new Q(), K = class K extends V {
944
- constructor(t = {}) {
945
- const o = N.get();
946
- if (o)
947
- return console.debug("[PageLinesSDK] Returning existing singleton instance"), o;
948
- super("PageLinesSDK", t);
949
- // Vue reactive state
950
- a(this, "activeUser", T());
951
- a(this, "token", T(null));
952
- a(this, "loading", T(!1));
953
- a(this, "error", T(null));
954
- a(this, "apiBase", this.settings.apiBase || void 0);
955
- // Storage handler for persistence
956
- a(this, "storage", new W());
957
- // Auto-managed session ID for usage tracking
958
- a(this, "sessionId", ae({ prefix: "ses" }));
959
- // Typed Hono RPC client - uses SDKAppType (auth/self/usage routes only)
960
- // Initialized in constructor (definite assignment via singleton pattern)
961
- a(this, "apiClient");
962
- // Computed properties derived from activeUser (matches UserClient pattern)
963
- a(this, "currentAgent", se(() => {
964
- const t = this.activeUser.value;
965
- if (!t?.agents)
966
- return;
967
- const o = t.primaryAgentId || t.agents[0]?.agentId;
968
- if (o)
969
- return t.agents.find((r) => r.agentId === o);
970
- }));
971
- a(this, "currentOrg", se(() => {
972
- const t = this.currentAgent.value;
973
- if (!t?.orgId)
974
- return;
975
- const o = this.activeUser.value;
976
- if (o?.orgs)
977
- return o.orgs.find((r) => r.orgId === t.orgId);
978
- }));
979
- // Initialization state
980
- a(this, "initialized");
981
- a(this, "resolveUser");
982
- // Sub-clients (new preferred API surface)
983
- a(this, "auth");
984
- a(this, "chat");
985
- a(this, "user");
986
- N.set(this), this.apiClient = me(
987
- { isDev: this.isDev, apiBase: this.apiBase },
988
- this.processApiResponse.bind(this)
989
- );
990
- const r = {
991
- api: this.api,
992
- apiBase: this.apiBase,
993
- isDev: this.isDev,
994
- activeUser: this.activeUser,
995
- token: this.token,
996
- loading: this.loading,
997
- error: this.error,
998
- currentAgent: this.currentAgent,
999
- storage: this.storage,
1000
- sessionId: this.sessionId,
1001
- logger: this.logger,
1002
- processApiResponse: this.processApiResponse.bind(this)
1003
- };
1004
- this.auth = new J(r), this.chat = new q(r), this.user = new H(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) => {
1005
- this.resolveUser = i;
1006
- }), this.token.value && !this.activeUser.value ? this.getCurrentUser().then((i) => {
1007
- this.resolveUser && (this.resolveUser(i), this.resolveUser = void 0);
1008
- }).catch((i) => {
1009
- this.logger.error("Auto user fetch failed", { data: i }), this.resolveUser && (this.resolveUser(void 0), this.resolveUser = void 0);
1010
- }) : this.activeUser.value ? this.resolveUser?.(this.activeUser.value) : this.resolveUser?.(void 0);
1011
- }
1012
- /**
1013
- * Get singleton instance in browser (creates if doesn't exist)
1014
- * Node.js: Always creates new instance (no singleton)
1015
- * Recommended: Use this instead of constructor for shared state
1016
- */
1017
- static getInstance(t = {}) {
1018
- return N.get() || new K(t);
1019
- }
1020
- get isDev() {
1021
- return this.settings.isDev ?? (typeof window < "u" ? window.location.hostname === "localhost" || window.location.hostname.includes("127.0.0.1") : !1);
1022
- }
1023
- // Bypass stub typing for route access (production builds use SDKAppType stub)
1024
- // Runtime types are validated via Zod at API boundaries
1025
- get api() {
1026
- return this.apiClient.api;
1027
- }
1028
- // Process ApiResponse for automatic user/token updates - public for dependency injection
1029
- processApiResponse(t) {
1030
- t.ok && t.user && (this.activeUser.value = t.user, this.logger.info("User updated from API response", { data: t.user })), t.ok && t.token && (this.token.value = t.token, this.storage.saveToStorage(this.activeUser, this.token), this.logger.info("Token updated from API response")), this.resolveUser && t.ok && (this.resolveUser(t.user), this.resolveUser = void 0);
1031
- }
1032
- // Clear all user data and tokens
1033
- clearSession() {
1034
- this.logger.info("Clearing session"), this.activeUser.value = void 0, this.token.value = null, this.error.value = null, this.storage.clearStorage();
1035
- }
1036
- // Full reset - clears session + state + destroys singleton
1037
- clear() {
1038
- this.logger.info("Clearing SDK completely"), this.clearSession(), this.loading.value = !1, this.sessionId = ae({ prefix: "ses" }), N.delete();
1039
- }
1040
- // Backward-compatible delegates — these forward to sub-clients
1041
- // Can be removed in a future breaking change
1042
- async sendCode(t) {
1043
- return this.auth.sendCode(t);
1044
- }
1045
- async verifyCode(t, o) {
1046
- return this.auth.verifyCode(t, o);
1047
- }
1048
- async login(t, o) {
1049
- return this.auth.login(t, o);
1050
- }
1051
- async logout() {
1052
- return this.auth.logout();
1053
- }
1054
- async getCurrentUser() {
1055
- return this.auth.getCurrentUser();
1056
- }
1057
- async requestAuthCode(t) {
1058
- return this.auth.requestAuthCode(t);
1059
- }
1060
- async loginWithCode(t) {
1061
- return this.auth.loginWithCode(t);
1062
- }
1063
- loginWithGoogle(t) {
1064
- return this.auth.loginWithGoogle(t);
1065
- }
1066
- async chatStream(t) {
1067
- return this.chat.chatStream(t);
1068
- }
1069
- async chatMessage(t) {
1070
- return this.chat.chatMessage(t);
1071
- }
1072
- async getPublicAgent(t) {
1073
- return this.user.getPublicAgent(t);
1074
- }
1075
- async getAgentByEmail(t) {
1076
- return this.user.getAgentByEmail(t);
1077
- }
1078
- generateAnonId() {
1079
- return this.user.generateAnonId();
1080
- }
1081
- track(t) {
1082
- return this.user.track(t);
1083
- }
1084
- };
1085
- s(K, "PageLinesSDK");
1086
- let le = K;
1087
- export {
1088
- J as A,
1089
- q as C,
1090
- le as P,
1091
- H as U,
1092
- xe as c
1093
- };
1094
- //# sourceMappingURL=sdkClient-B3EKDRYb.js.map