@pagelines/sdk 1.0.643 → 1.0.644
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/README.md +1 -1
- package/dist/FModal.vue_vue_type_script_setup_true_lang.js +8 -8
- package/dist/FModal.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/agent/ui/ElCreateAgent.vue.d.ts +12 -0
- package/dist/api.d.ts +7 -6
- package/dist/demo/index.d.ts +6 -0
- package/dist/sdkClient.js +136 -150
- package/dist/sdkClient.js.map +1 -1
- package/dist/sdkStorage.d.ts +5 -5
- package/dist/test/sdk-token-capture.test.d.ts +3 -4
- package/dist/widget/composables/useWidgetState.d.ts +18 -0
- package/package.json +1 -1
package/dist/sdkClient.js
CHANGED
|
@@ -1,43 +1,38 @@
|
|
|
1
1
|
var Q = Object.defineProperty;
|
|
2
2
|
var ee = (i, e, t) => e in i ? Q(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
import { APP_PORT as te, APP_PROD_URL as re,
|
|
6
|
-
import { watch as
|
|
3
|
+
var l = (i, e) => Q(i, "name", { value: e, configurable: !0 });
|
|
4
|
+
var c = (i, e, t) => ee(i, typeof e != "symbol" ? e + "" : e, t);
|
|
5
|
+
import { APP_PORT as te, APP_PROD_URL as re, cookieUtil as S, createLogger as oe, shortId as se, runAuthenticatedChatTurnStream as ie, zChatEvent as ae, objectId as P, SettingsObject as ne } from "@pagelines/core";
|
|
6
|
+
import { watch as B, ref as b, computed as V } from "vue";
|
|
7
7
|
function p(i, e) {
|
|
8
8
|
return i || (e ? `http://localhost:${te}` : re);
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
function
|
|
12
|
-
const r = p(i.apiBase, i.isDev)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return async (s, n) => {
|
|
20
|
-
const d = S.getAuthToken(), a = new Headers(n?.headers);
|
|
21
|
-
a.has("Content-Type") || a.set("Content-Type", "application/json"), d && !a.has("Authorization") && a.set("Authorization", `Bearer ${d}`);
|
|
22
|
-
const g = typeof s == "string" && s.startsWith("/") ? `${r}${s}` : s, f = await o(g, {
|
|
23
|
-
...n,
|
|
24
|
-
headers: a,
|
|
10
|
+
l(p, "resolveApiBase");
|
|
11
|
+
function ce(i, e, t) {
|
|
12
|
+
const r = p(i.apiBase, i.isDev);
|
|
13
|
+
return async (o, s) => {
|
|
14
|
+
const n = S.getAuthToken(), d = new Headers(s?.headers);
|
|
15
|
+
d.has("Content-Type") || d.set("Content-Type", "application/json"), n && !d.has("Authorization") && d.set("Authorization", `Bearer ${n}`);
|
|
16
|
+
const a = typeof o == "string" && o.startsWith("/") ? `${r}${o}` : o, u = await fetch(a, {
|
|
17
|
+
...s,
|
|
18
|
+
headers: d,
|
|
25
19
|
credentials: "include"
|
|
26
20
|
});
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
21
|
+
if (t && u.status === 401 && (await u.clone().json().catch(() => {
|
|
22
|
+
}))?.code === "TOKEN_ERROR" && t(), e) {
|
|
23
|
+
const g = u.json.bind(u);
|
|
24
|
+
u.json = async () => {
|
|
25
|
+
const f = await g();
|
|
26
|
+
return typeof f == "object" && f !== null && "ok" in f && ("user" in f || "token" in f) && e(f), f;
|
|
32
27
|
};
|
|
33
28
|
}
|
|
34
|
-
return
|
|
29
|
+
return u;
|
|
35
30
|
};
|
|
36
31
|
}
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
let v = [],
|
|
40
|
-
const
|
|
32
|
+
l(ce, "createApiFetch");
|
|
33
|
+
const le = /* @__PURE__ */ Symbol("clean");
|
|
34
|
+
let v = [], w = 0;
|
|
35
|
+
const U = 4, ue = globalThis.nanostoresGlobal || (globalThis.nanostoresGlobal = { epoch: 0 }), N = /* @__PURE__ */ l(/* @__NO_SIDE_EFFECTS__ */ (i) => {
|
|
41
36
|
let e = [], t = {
|
|
42
37
|
get() {
|
|
43
38
|
return t.lc || t.listen(() => {
|
|
@@ -47,8 +42,8 @@ const T = 4, ue = globalThis.nanostoresGlobal || (globalThis.nanostoresGlobal =
|
|
|
47
42
|
lc: 0,
|
|
48
43
|
listen(r) {
|
|
49
44
|
return t.lc = e.push(r), () => {
|
|
50
|
-
for (let s =
|
|
51
|
-
v[s] === r ? v.splice(s,
|
|
45
|
+
for (let s = w + U; s < v.length; )
|
|
46
|
+
v[s] === r ? v.splice(s, U) : s += U;
|
|
52
47
|
let o = e.indexOf(r);
|
|
53
48
|
~o && (e.splice(o, 1), --t.lc || t.off());
|
|
54
49
|
};
|
|
@@ -59,11 +54,11 @@ const T = 4, ue = globalThis.nanostoresGlobal || (globalThis.nanostoresGlobal =
|
|
|
59
54
|
for (let n of e)
|
|
60
55
|
v.push(n, t.value, r, o);
|
|
61
56
|
if (s) {
|
|
62
|
-
for (
|
|
63
|
-
v[
|
|
64
|
-
v[
|
|
65
|
-
v[
|
|
66
|
-
v[
|
|
57
|
+
for (w = 0; w < v.length; w += U)
|
|
58
|
+
v[w](
|
|
59
|
+
v[w + 1],
|
|
60
|
+
v[w + 2],
|
|
61
|
+
v[w + 3]
|
|
67
62
|
);
|
|
68
63
|
v.length = 0;
|
|
69
64
|
}
|
|
@@ -82,12 +77,12 @@ const T = 4, ue = globalThis.nanostoresGlobal || (globalThis.nanostoresGlobal =
|
|
|
82
77
|
},
|
|
83
78
|
value: i
|
|
84
79
|
};
|
|
85
|
-
return process.env.NODE_ENV !== "production" && (t[
|
|
80
|
+
return process.env.NODE_ENV !== "production" && (t[le] = () => {
|
|
86
81
|
e = [], t.lc = 0, t.off();
|
|
87
82
|
}), t;
|
|
88
|
-
}, "atom"),
|
|
83
|
+
}, "atom"), y = globalThis, E = y.__PL_AUTH_USER__ ?? (y.__PL_AUTH_USER__ = /* @__PURE__ */ N(void 0)), T = y.__PL_AUTH_TOKEN__ ?? (y.__PL_AUTH_TOKEN__ = /* @__PURE__ */ N(null)), A = y.__PL_AUTH_DEVICE_ID__ ?? (y.__PL_AUTH_DEVICE_ID__ = /* @__PURE__ */ N(null)), z = class z {
|
|
89
84
|
constructor() {
|
|
90
|
-
|
|
85
|
+
c(this, "logger", oe("SDKStorage"));
|
|
91
86
|
}
|
|
92
87
|
/**
|
|
93
88
|
* Check if localStorage is fully functional (some test environments provide partial mocks)
|
|
@@ -99,10 +94,10 @@ const T = 4, ue = globalThis.nanostoresGlobal || (globalThis.nanostoresGlobal =
|
|
|
99
94
|
* Sync Vue reactive refs with global nanostores for cross-bundle persistence.
|
|
100
95
|
*/
|
|
101
96
|
syncWithGlobalStores(e) {
|
|
102
|
-
const { activeUser: t, token: r, deviceId: o } = e, s =
|
|
103
|
-
s && (t.value = s), n && (r.value = n), d && (o.value = d),
|
|
97
|
+
const { activeUser: t, token: r, deviceId: o } = e, s = E.get(), n = T.get(), d = A.get();
|
|
98
|
+
s && (t.value = s), n && (r.value = n), d && (o.value = d), B(t, (a) => E.set(a), { immediate: !0 }), B(r, (a) => T.set(a), { immediate: !0 }), B(o, (a) => A.set(a), { immediate: !0 }), E.subscribe((a) => {
|
|
104
99
|
a !== t.value && (t.value = a);
|
|
105
|
-
}),
|
|
100
|
+
}), T.subscribe((a) => {
|
|
106
101
|
a !== r.value && (r.value = a);
|
|
107
102
|
}), A.subscribe((a) => {
|
|
108
103
|
a !== o.value && (o.value = a);
|
|
@@ -127,7 +122,7 @@ const T = 4, ue = globalThis.nanostoresGlobal || (globalThis.nanostoresGlobal =
|
|
|
127
122
|
}
|
|
128
123
|
}
|
|
129
124
|
/**
|
|
130
|
-
* Save current user and
|
|
125
|
+
* Save current user and the transitional JS session-token mirror to browser storage.
|
|
131
126
|
* deviceId is server-owned (Set-Cookie) — JS doesn't write it.
|
|
132
127
|
*/
|
|
133
128
|
saveToStorage(e) {
|
|
@@ -140,7 +135,7 @@ const T = 4, ue = globalThis.nanostoresGlobal || (globalThis.nanostoresGlobal =
|
|
|
140
135
|
}
|
|
141
136
|
/**
|
|
142
137
|
* Clear local stored user data and JS-owned tokens. Server-owned cookies
|
|
143
|
-
* (pl-
|
|
138
|
+
* (pl-session, pl-device-id) are cleared by /api/auth/logout via
|
|
144
139
|
* Set-Cookie max-age=0 — JS can't touch them.
|
|
145
140
|
*/
|
|
146
141
|
clearStorage() {
|
|
@@ -151,7 +146,7 @@ const T = 4, ue = globalThis.nanostoresGlobal || (globalThis.nanostoresGlobal =
|
|
|
151
146
|
} catch (e) {
|
|
152
147
|
this.logger.error("Failed to clear user from localStorage", { data: e });
|
|
153
148
|
}
|
|
154
|
-
|
|
149
|
+
E.set(void 0), T.set(null), A.set(null);
|
|
155
150
|
}
|
|
156
151
|
}
|
|
157
152
|
/**
|
|
@@ -178,11 +173,11 @@ const T = 4, ue = globalThis.nanostoresGlobal || (globalThis.nanostoresGlobal =
|
|
|
178
173
|
}
|
|
179
174
|
}
|
|
180
175
|
};
|
|
181
|
-
|
|
182
|
-
let
|
|
176
|
+
l(z, "SDKStorage");
|
|
177
|
+
let D = z;
|
|
183
178
|
const J = class J {
|
|
184
179
|
constructor(e) {
|
|
185
|
-
|
|
180
|
+
c(this, "ctx");
|
|
186
181
|
this.ctx = e;
|
|
187
182
|
}
|
|
188
183
|
async create(e) {
|
|
@@ -240,7 +235,7 @@ const J = class J {
|
|
|
240
235
|
}
|
|
241
236
|
if (a.lifecycle === "error")
|
|
242
237
|
throw new Error(a.detail || "Your assistant hit a problem starting");
|
|
243
|
-
a.lifecycle !== d && (r?.(a.lifecycle), d = a.lifecycle), await new Promise((
|
|
238
|
+
a.lifecycle !== d && (r?.(a.lifecycle), d = a.lifecycle), await new Promise((u) => setTimeout(u, s));
|
|
244
239
|
}
|
|
245
240
|
throw new Error("Your assistant is taking longer than expected — please try again");
|
|
246
241
|
}
|
|
@@ -266,8 +261,8 @@ const J = class J {
|
|
|
266
261
|
return t;
|
|
267
262
|
}
|
|
268
263
|
};
|
|
269
|
-
|
|
270
|
-
let
|
|
264
|
+
l(J, "AgentClient");
|
|
265
|
+
let R = J;
|
|
271
266
|
async function k(i, e) {
|
|
272
267
|
i.loading.value = !0, i.error.value = null;
|
|
273
268
|
try {
|
|
@@ -276,10 +271,10 @@ async function k(i, e) {
|
|
|
276
271
|
i.loading.value = !1;
|
|
277
272
|
}
|
|
278
273
|
}
|
|
279
|
-
|
|
274
|
+
l(k, "withLoadingState");
|
|
280
275
|
const W = class W {
|
|
281
276
|
constructor(e) {
|
|
282
|
-
|
|
277
|
+
c(this, "ctx");
|
|
283
278
|
this.ctx = e;
|
|
284
279
|
}
|
|
285
280
|
async sendCode(e) {
|
|
@@ -373,41 +368,41 @@ const W = class W {
|
|
|
373
368
|
this.ctx.logger.error("loginWithGoogle: Only available in browser");
|
|
374
369
|
return;
|
|
375
370
|
}
|
|
376
|
-
const t = p(this.ctx.apiBase, this.ctx.isDev), r = window.location.origin, o = `${t}/auth/google-popup?origin=${encodeURIComponent(r)}`, s = 500, n = 600, d = window.screenX + (window.outerWidth - s) / 2, a = window.screenY + (window.outerHeight - n) / 2,
|
|
371
|
+
const t = p(this.ctx.apiBase, this.ctx.isDev), r = window.location.origin, o = `${t}/auth/google-popup?origin=${encodeURIComponent(r)}`, s = 500, n = 600, d = window.screenX + (window.outerWidth - s) / 2, a = window.screenY + (window.outerHeight - n) / 2, u = window.open(
|
|
377
372
|
o,
|
|
378
373
|
"google-auth",
|
|
379
374
|
`width=${s},height=${n},left=${d},top=${a},popup=yes`
|
|
380
375
|
);
|
|
381
|
-
if (!
|
|
382
|
-
const
|
|
383
|
-
this.ctx.error.value =
|
|
376
|
+
if (!u) {
|
|
377
|
+
const m = "Popup was blocked. Please allow popups for this site.";
|
|
378
|
+
this.ctx.error.value = m, e?.onError?.(m);
|
|
384
379
|
return;
|
|
385
380
|
}
|
|
386
|
-
const
|
|
381
|
+
const g = /* @__PURE__ */ l((m) => {
|
|
387
382
|
const I = new URL(t).origin;
|
|
388
|
-
if (
|
|
389
|
-
if (
|
|
390
|
-
window.removeEventListener("message",
|
|
391
|
-
const { token: x, user: h } =
|
|
383
|
+
if (m.origin === I) {
|
|
384
|
+
if (m.data?.type === "auth-success") {
|
|
385
|
+
window.removeEventListener("message", g);
|
|
386
|
+
const { token: x, user: h } = m.data;
|
|
392
387
|
this.ctx.processApiResponse({ ok: !0, data: {}, token: x, user: h }), this.ctx.logger.info("Google login successful"), e?.onSuccess?.(h);
|
|
393
|
-
} else if (
|
|
394
|
-
window.removeEventListener("message",
|
|
395
|
-
const x =
|
|
388
|
+
} else if (m.data?.type === "auth-error") {
|
|
389
|
+
window.removeEventListener("message", g);
|
|
390
|
+
const x = m.data.error || "Google authentication failed";
|
|
396
391
|
this.ctx.error.value = x, this.ctx.logger.error("Google login failed", { error: x }), e?.onError?.(x);
|
|
397
392
|
}
|
|
398
393
|
}
|
|
399
394
|
}, "handler");
|
|
400
|
-
window.addEventListener("message",
|
|
401
|
-
const
|
|
402
|
-
|
|
395
|
+
window.addEventListener("message", g);
|
|
396
|
+
const f = setInterval(() => {
|
|
397
|
+
u.closed && (clearInterval(f), window.removeEventListener("message", g));
|
|
403
398
|
}, 500);
|
|
404
399
|
}
|
|
405
400
|
};
|
|
406
|
-
|
|
407
|
-
let
|
|
401
|
+
l(W, "AuthClient");
|
|
402
|
+
let F = W;
|
|
408
403
|
const G = class G {
|
|
409
404
|
constructor(e) {
|
|
410
|
-
|
|
405
|
+
c(this, "ctx");
|
|
411
406
|
this.ctx = e;
|
|
412
407
|
}
|
|
413
408
|
async startTrial(e) {
|
|
@@ -475,7 +470,7 @@ const G = class G {
|
|
|
475
470
|
return t;
|
|
476
471
|
}
|
|
477
472
|
};
|
|
478
|
-
|
|
473
|
+
l(G, "BillingClient");
|
|
479
474
|
let L = G;
|
|
480
475
|
function de(i) {
|
|
481
476
|
const e = i.split(`
|
|
@@ -486,13 +481,13 @@ function de(i) {
|
|
|
486
481
|
if (!t || r === void 0)
|
|
487
482
|
return null;
|
|
488
483
|
try {
|
|
489
|
-
const o =
|
|
484
|
+
const o = ae.safeParse({ event: t, data: JSON.parse(r) });
|
|
490
485
|
return o.success ? o.data : null;
|
|
491
486
|
} catch {
|
|
492
487
|
return null;
|
|
493
488
|
}
|
|
494
489
|
}
|
|
495
|
-
|
|
490
|
+
l(de, "parseChatEvent");
|
|
496
491
|
function Y(i) {
|
|
497
492
|
return {
|
|
498
493
|
code: i.code,
|
|
@@ -503,11 +498,11 @@ function Y(i) {
|
|
|
503
498
|
...i.help ? { help: i.help } : {}
|
|
504
499
|
};
|
|
505
500
|
}
|
|
506
|
-
|
|
507
|
-
function
|
|
501
|
+
l(Y, "toChatStreamError");
|
|
502
|
+
function he(i) {
|
|
508
503
|
return i.stage === "stream-open" && i.message.startsWith("HTTP ") ? `Stream failed: ${i.message}` : i.message;
|
|
509
504
|
}
|
|
510
|
-
|
|
505
|
+
l(he, "toAuthenticatedTransportError");
|
|
511
506
|
function X(i) {
|
|
512
507
|
if (!(i.role !== "assistant" && i.role !== "system"))
|
|
513
508
|
return {
|
|
@@ -523,10 +518,10 @@ function X(i) {
|
|
|
523
518
|
...i.metadata?.issue ? { issue: i.metadata.issue } : {}
|
|
524
519
|
};
|
|
525
520
|
}
|
|
526
|
-
|
|
521
|
+
l(X, "toChatMessage");
|
|
527
522
|
const q = class q {
|
|
528
523
|
constructor(e) {
|
|
529
|
-
|
|
524
|
+
c(this, "ctx");
|
|
530
525
|
this.ctx = e;
|
|
531
526
|
}
|
|
532
527
|
async cancelConversationTurn(e) {
|
|
@@ -564,27 +559,27 @@ const q = class q {
|
|
|
564
559
|
})
|
|
565
560
|
});
|
|
566
561
|
if (!a.ok) {
|
|
567
|
-
const
|
|
568
|
-
e.onError(
|
|
562
|
+
const f = await a.json().catch(() => ({ error: "Request failed" }));
|
|
563
|
+
e.onError(f.error || `HTTP ${a.status}`);
|
|
569
564
|
return;
|
|
570
565
|
}
|
|
571
566
|
if (o = a.headers.get("X-Conversation-Id") || "", d = a.body?.getReader(), !d) {
|
|
572
567
|
e.onError("No response stream");
|
|
573
568
|
return;
|
|
574
569
|
}
|
|
575
|
-
const
|
|
576
|
-
let
|
|
570
|
+
const u = new TextDecoder();
|
|
571
|
+
let g = "";
|
|
577
572
|
e: for (; ; ) {
|
|
578
|
-
const { done:
|
|
579
|
-
if (
|
|
573
|
+
const { done: f, value: m } = await d.read();
|
|
574
|
+
if (f)
|
|
580
575
|
break;
|
|
581
|
-
|
|
582
|
-
let I =
|
|
576
|
+
g += u.decode(m, { stream: !0 });
|
|
577
|
+
let I = g.indexOf(`
|
|
583
578
|
|
|
584
579
|
`);
|
|
585
580
|
for (; I !== -1; ) {
|
|
586
|
-
const x =
|
|
587
|
-
|
|
581
|
+
const x = g.slice(0, I);
|
|
582
|
+
g = g.slice(I + 2);
|
|
588
583
|
const h = de(x);
|
|
589
584
|
if (h) {
|
|
590
585
|
if (h.event === "working_state")
|
|
@@ -605,7 +600,7 @@ const q = class q {
|
|
|
605
600
|
} else if (h.event === "stream_end")
|
|
606
601
|
break e;
|
|
607
602
|
}
|
|
608
|
-
I =
|
|
603
|
+
I = g.indexOf(`
|
|
609
604
|
|
|
610
605
|
`);
|
|
611
606
|
}
|
|
@@ -636,18 +631,18 @@ const q = class q {
|
|
|
636
631
|
method: "POST",
|
|
637
632
|
headers: { "Content-Type": "application/json", ...r },
|
|
638
633
|
body: JSON.stringify({ agentId: e.agentId })
|
|
639
|
-
}),
|
|
640
|
-
if (!
|
|
641
|
-
e.onError(
|
|
634
|
+
}), u = await a.json();
|
|
635
|
+
if (!u.ok) {
|
|
636
|
+
e.onError(u.error || `Conversation failed: HTTP ${a.status}`);
|
|
642
637
|
return;
|
|
643
638
|
}
|
|
644
|
-
o =
|
|
639
|
+
o = u.data.conversationId, s = u.data.latestSequence ?? null;
|
|
645
640
|
} catch (a) {
|
|
646
641
|
e.onError(a instanceof Error ? a.message : "Conversation failed");
|
|
647
642
|
return;
|
|
648
643
|
}
|
|
649
|
-
const n = s ? `${t}/api/conversations/${encodeURIComponent(o)}/stream?since=${encodeURIComponent(s)}` : `${t}/api/conversations/${encodeURIComponent(o)}/stream`, d = `nonce_${
|
|
650
|
-
await
|
|
644
|
+
const n = s ? `${t}/api/conversations/${encodeURIComponent(o)}/stream?since=${encodeURIComponent(s)}` : `${t}/api/conversations/${encodeURIComponent(o)}/stream`, d = `nonce_${se(16)}`;
|
|
645
|
+
await ie({
|
|
651
646
|
streamUrl: n,
|
|
652
647
|
sendUrl: `${t}/api/messages`,
|
|
653
648
|
headers: r,
|
|
@@ -661,21 +656,21 @@ const q = class q {
|
|
|
661
656
|
onDelta: e.onDelta,
|
|
662
657
|
onToolActivity: e.onToolActivity,
|
|
663
658
|
onWorkingEnd: e.onWorkingEnd,
|
|
664
|
-
onMessage: /* @__PURE__ */
|
|
665
|
-
const
|
|
666
|
-
|
|
659
|
+
onMessage: /* @__PURE__ */ l((a) => {
|
|
660
|
+
const u = X(a);
|
|
661
|
+
u && e.onMessage?.(u);
|
|
667
662
|
}, "onMessage"),
|
|
668
|
-
onDone: /* @__PURE__ */
|
|
669
|
-
onChatError: /* @__PURE__ */
|
|
670
|
-
onTransportError: /* @__PURE__ */
|
|
663
|
+
onDone: /* @__PURE__ */ l(() => e.onDone(o), "onDone"),
|
|
664
|
+
onChatError: /* @__PURE__ */ l((a) => e.onError(Y(a)), "onChatError"),
|
|
665
|
+
onTransportError: /* @__PURE__ */ l((a) => e.onError(he(a)), "onTransportError")
|
|
671
666
|
});
|
|
672
667
|
}
|
|
673
668
|
};
|
|
674
|
-
|
|
675
|
-
let
|
|
669
|
+
l(q, "ChatClient");
|
|
670
|
+
let j = q;
|
|
676
671
|
const M = class M {
|
|
677
672
|
constructor(e) {
|
|
678
|
-
|
|
673
|
+
c(this, "ctx");
|
|
679
674
|
this.ctx = e;
|
|
680
675
|
}
|
|
681
676
|
async getPublicAgent(e) {
|
|
@@ -713,7 +708,7 @@ const M = class M {
|
|
|
713
708
|
generateAnonId() {
|
|
714
709
|
const e = "pagelinesAnonId";
|
|
715
710
|
let t = this.ctx.storage.getItem(e);
|
|
716
|
-
return t || (t =
|
|
711
|
+
return t || (t = P({ prefix: "anon" }), this.ctx.storage.setItem(e, t)), t;
|
|
717
712
|
}
|
|
718
713
|
track(e) {
|
|
719
714
|
try {
|
|
@@ -728,11 +723,11 @@ const M = class M {
|
|
|
728
723
|
}
|
|
729
724
|
}
|
|
730
725
|
};
|
|
731
|
-
|
|
732
|
-
let
|
|
726
|
+
l(M, "UserClient");
|
|
727
|
+
let C = M;
|
|
733
728
|
const H = class H {
|
|
734
729
|
constructor() {
|
|
735
|
-
|
|
730
|
+
c(this, "key", "__PAGELINES_SDK__");
|
|
736
731
|
}
|
|
737
732
|
get() {
|
|
738
733
|
if (!(typeof window > "u"))
|
|
@@ -745,30 +740,29 @@ const H = class H {
|
|
|
745
740
|
typeof window < "u" && delete globalThis[this.key];
|
|
746
741
|
}
|
|
747
742
|
};
|
|
748
|
-
|
|
743
|
+
l(H, "SDKGlobal");
|
|
749
744
|
let _ = H;
|
|
750
|
-
const $ = new _(),
|
|
745
|
+
const $ = new _(), O = class O extends ne {
|
|
751
746
|
constructor(t = {}) {
|
|
752
747
|
const r = $.get();
|
|
753
748
|
if (r)
|
|
754
749
|
return console.debug("[PageLinesSDK] Returning existing singleton instance"), r;
|
|
755
750
|
super("PageLinesSDK", t);
|
|
756
751
|
// Vue reactive state
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
//
|
|
760
|
-
//
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
l(this, "apiBase", this.settings.apiBase || void 0);
|
|
752
|
+
c(this, "activeUser", b());
|
|
753
|
+
c(this, "token", b(null));
|
|
754
|
+
// Opaque session token for Bearer clients. Web may also have the same
|
|
755
|
+
// credential in the HttpOnly pl-session cookie, which JS cannot read.
|
|
756
|
+
c(this, "deviceId", b(null));
|
|
757
|
+
c(this, "loading", b(!1));
|
|
758
|
+
c(this, "error", b(null));
|
|
759
|
+
c(this, "apiBase", this.settings.apiBase || void 0);
|
|
766
760
|
// Storage handler for persistence
|
|
767
|
-
|
|
761
|
+
c(this, "storage", new D());
|
|
768
762
|
// Auto-managed session ID for usage tracking
|
|
769
|
-
|
|
763
|
+
c(this, "sessionId", P({ prefix: "ses" }));
|
|
770
764
|
// Computed properties derived from activeUser (matches UserClient pattern)
|
|
771
|
-
|
|
765
|
+
c(this, "currentAgent", V(() => {
|
|
772
766
|
const t = this.activeUser.value;
|
|
773
767
|
if (!t?.agents)
|
|
774
768
|
return;
|
|
@@ -776,7 +770,7 @@ const $ = new _(), B = class B extends ce {
|
|
|
776
770
|
if (r)
|
|
777
771
|
return t.agents.find((o) => o.agentId === r);
|
|
778
772
|
}));
|
|
779
|
-
|
|
773
|
+
c(this, "currentOrg", V(() => {
|
|
780
774
|
const t = this.currentAgent.value;
|
|
781
775
|
if (!t?.orgId)
|
|
782
776
|
return;
|
|
@@ -785,28 +779,20 @@ const $ = new _(), B = class B extends ce {
|
|
|
785
779
|
return r.orgs.find((o) => o.orgId === t.orgId);
|
|
786
780
|
}));
|
|
787
781
|
// Initialization state
|
|
788
|
-
|
|
789
|
-
|
|
782
|
+
c(this, "initialized");
|
|
783
|
+
c(this, "resolveUser");
|
|
790
784
|
// Sub-clients (new preferred API surface)
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
785
|
+
c(this, "agent");
|
|
786
|
+
c(this, "auth");
|
|
787
|
+
c(this, "billing");
|
|
788
|
+
c(this, "chat");
|
|
789
|
+
c(this, "user");
|
|
796
790
|
$.set(this);
|
|
797
791
|
const s = {
|
|
798
|
-
apiFetch:
|
|
792
|
+
apiFetch: ce(
|
|
799
793
|
{ isDev: this.isDev, apiBase: this.apiBase },
|
|
800
794
|
this.processApiResponse.bind(this),
|
|
801
|
-
|
|
802
|
-
getDeviceId: /* @__PURE__ */ c(() => this.deviceId.value, "getDeviceId"),
|
|
803
|
-
onAccessTokenRefreshed: /* @__PURE__ */ c((n) => {
|
|
804
|
-
this.token.value = n, this.persistAuth();
|
|
805
|
-
}, "onAccessTokenRefreshed"),
|
|
806
|
-
onTerminalFailure: /* @__PURE__ */ c(() => {
|
|
807
|
-
this.clearSession();
|
|
808
|
-
}, "onTerminalFailure")
|
|
809
|
-
}
|
|
795
|
+
() => this.clearSession()
|
|
810
796
|
),
|
|
811
797
|
apiBase: this.apiBase,
|
|
812
798
|
isDev: this.isDev,
|
|
@@ -820,7 +806,7 @@ const $ = new _(), B = class B extends ce {
|
|
|
820
806
|
logger: this.logger,
|
|
821
807
|
processApiResponse: this.processApiResponse.bind(this)
|
|
822
808
|
};
|
|
823
|
-
this.agent = new
|
|
809
|
+
this.agent = new R(s), this.auth = new F(s), this.billing = new L(s), this.chat = new j(s), this.user = new C(s), this.logger.info("PageLinesSDK initialized"), this.storage.loadFromStorage(this.authRefs()), this.storage.syncWithGlobalStores(this.authRefs()), this.initialized = new Promise((n) => {
|
|
824
810
|
this.resolveUser = n;
|
|
825
811
|
}), this.token.value && !this.activeUser.value ? this.auth.getCurrentUser().then((n) => {
|
|
826
812
|
this.resolveUser && (this.resolveUser(n), this.resolveUser = void 0);
|
|
@@ -834,7 +820,7 @@ const $ = new _(), B = class B extends ce {
|
|
|
834
820
|
* Recommended: Use this instead of constructor for shared state
|
|
835
821
|
*/
|
|
836
822
|
static getInstance(t = {}) {
|
|
837
|
-
return $.get() || new
|
|
823
|
+
return $.get() || new O(t);
|
|
838
824
|
}
|
|
839
825
|
get isDev() {
|
|
840
826
|
return this.settings.isDev ?? (typeof window < "u" ? window.location.hostname === "localhost" || window.location.hostname.includes("127.0.0.1") : !1);
|
|
@@ -863,18 +849,18 @@ const $ = new _(), B = class B extends ce {
|
|
|
863
849
|
}
|
|
864
850
|
// Full reset - clears session + state + destroys singleton
|
|
865
851
|
clear() {
|
|
866
|
-
this.logger.info("Clearing SDK completely"), this.clearSession(), this.loading.value = !1, this.sessionId =
|
|
852
|
+
this.logger.info("Clearing SDK completely"), this.clearSession(), this.loading.value = !1, this.sessionId = P({ prefix: "ses" }), $.delete();
|
|
867
853
|
}
|
|
868
854
|
};
|
|
869
|
-
|
|
870
|
-
let Z =
|
|
855
|
+
l(O, "PageLinesSDK");
|
|
856
|
+
let Z = O;
|
|
871
857
|
export {
|
|
872
|
-
|
|
858
|
+
R as A,
|
|
873
859
|
L as B,
|
|
874
|
-
C,
|
|
860
|
+
j as C,
|
|
875
861
|
Z as P,
|
|
876
|
-
|
|
877
|
-
|
|
862
|
+
C as U,
|
|
863
|
+
F as a,
|
|
878
864
|
p as r
|
|
879
865
|
};
|
|
880
866
|
//# sourceMappingURL=sdkClient.js.map
|