@pagelines/sdk 1.0.642 → 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/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 c = (i, e) => Q(i, "name", { value: e, configurable: !0 });
4
- var l = (i, e, t) => ee(i, typeof e != "symbol" ? e + "" : e, t);
5
- import { APP_PORT as te, APP_PROD_URL as re, createRefreshingFetch as oe, cookieUtil as S, createLogger as se, shortId as ie, runAuthenticatedChatTurnStream as ae, zChatEvent as ne, objectId as O, SettingsObject as ce } from "@pagelines/core";
6
- import { watch as D, ref as b, computed as V } from "vue";
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
- c(p, "resolveApiBase");
11
- function le(i, e, t) {
12
- const r = p(i.apiBase, i.isDev), o = t ? oe({
13
- fetch: globalThis.fetch.bind(globalThis),
14
- getDeviceId: t.getDeviceId,
15
- refreshUrl: `${r}/api/auth/refresh`,
16
- onAccessTokenRefreshed: t.onAccessTokenRefreshed,
17
- onTerminalFailure: t.onTerminalFailure
18
- }) : globalThis.fetch.bind(globalThis);
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 (e) {
28
- const w = f.json.bind(f);
29
- f.json = async () => {
30
- const u = await w();
31
- return typeof u == "object" && u !== null && "ok" in u && ("user" in u || "token" in u) && e(u), u;
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 f;
29
+ return u;
35
30
  };
36
31
  }
37
- c(le, "createApiFetch");
38
- const he = /* @__PURE__ */ Symbol("clean");
39
- let v = [], y = 0;
40
- const T = 4, ue = globalThis.nanostoresGlobal || (globalThis.nanostoresGlobal = { epoch: 0 }), N = /* @__PURE__ */ c(/* @__NO_SIDE_EFFECTS__ */ (i) => {
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 = y + T; s < v.length; )
51
- v[s] === r ? v.splice(s, T) : s += T;
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 (y = 0; y < v.length; y += T)
63
- v[y](
64
- v[y + 1],
65
- v[y + 2],
66
- v[y + 3]
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[he] = () => {
80
+ return process.env.NODE_ENV !== "production" && (t[le] = () => {
86
81
  e = [], t.lc = 0, t.off();
87
82
  }), t;
88
- }, "atom"), m = globalThis, U = m.__PL_AUTH_USER__ ?? (m.__PL_AUTH_USER__ = /* @__PURE__ */ N(void 0)), E = m.__PL_AUTH_TOKEN__ ?? (m.__PL_AUTH_TOKEN__ = /* @__PURE__ */ N(null)), A = m.__PL_AUTH_DEVICE_ID__ ?? (m.__PL_AUTH_DEVICE_ID__ = /* @__PURE__ */ N(null)), z = class z {
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
- l(this, "logger", se("SDKStorage"));
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 = U.get(), n = E.get(), d = A.get();
103
- s && (t.value = s), n && (r.value = n), d && (o.value = d), D(t, (a) => U.set(a), { immediate: !0 }), D(r, (a) => E.set(a), { immediate: !0 }), D(o, (a) => A.set(a), { immediate: !0 }), U.subscribe((a) => {
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
- }), E.subscribe((a) => {
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 access token to browser storage.
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-refresh-token, pl-device-id) are cleared by /api/auth/logout via
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
- U.set(void 0), E.set(null), A.set(null);
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
- c(z, "SDKStorage");
182
- let F = z;
176
+ l(z, "SDKStorage");
177
+ let D = z;
183
178
  const J = class J {
184
179
  constructor(e) {
185
- l(this, "ctx");
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((g) => setTimeout(g, s));
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
- c(J, "AgentClient");
270
- let P = J;
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
- c(k, "withLoadingState");
274
+ l(k, "withLoadingState");
280
275
  const W = class W {
281
276
  constructor(e) {
282
- l(this, "ctx");
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, g = window.open(
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 (!g) {
382
- const u = "Popup was blocked. Please allow popups for this site.";
383
- this.ctx.error.value = u, e?.onError?.(u);
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 f = /* @__PURE__ */ c((u) => {
381
+ const g = /* @__PURE__ */ l((m) => {
387
382
  const I = new URL(t).origin;
388
- if (u.origin === I) {
389
- if (u.data?.type === "auth-success") {
390
- window.removeEventListener("message", f);
391
- const { token: x, user: h } = u.data;
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 (u.data?.type === "auth-error") {
394
- window.removeEventListener("message", f);
395
- const x = u.data.error || "Google authentication failed";
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", f);
401
- const w = setInterval(() => {
402
- g.closed && (clearInterval(w), window.removeEventListener("message", f));
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
- c(W, "AuthClient");
407
- let R = W;
401
+ l(W, "AuthClient");
402
+ let F = W;
408
403
  const G = class G {
409
404
  constructor(e) {
410
- l(this, "ctx");
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
- c(G, "BillingClient");
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 = ne.safeParse({ event: t, data: JSON.parse(r) });
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
- c(de, "parseChatEvent");
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
- c(Y, "toChatStreamError");
507
- function ge(i) {
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
- c(ge, "toAuthenticatedTransportError");
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
- c(X, "toChatMessage");
521
+ l(X, "toChatMessage");
527
522
  const q = class q {
528
523
  constructor(e) {
529
- l(this, "ctx");
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 w = await a.json().catch(() => ({ error: "Request failed" }));
568
- e.onError(w.error || `HTTP ${a.status}`);
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 g = new TextDecoder();
576
- let f = "";
570
+ const u = new TextDecoder();
571
+ let g = "";
577
572
  e: for (; ; ) {
578
- const { done: w, value: u } = await d.read();
579
- if (w)
573
+ const { done: f, value: m } = await d.read();
574
+ if (f)
580
575
  break;
581
- f += g.decode(u, { stream: !0 });
582
- let I = f.indexOf(`
576
+ g += u.decode(m, { stream: !0 });
577
+ let I = g.indexOf(`
583
578
 
584
579
  `);
585
580
  for (; I !== -1; ) {
586
- const x = f.slice(0, I);
587
- f = f.slice(I + 2);
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 = f.indexOf(`
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
- }), g = await a.json();
640
- if (!g.ok) {
641
- e.onError(g.error || `Conversation failed: HTTP ${a.status}`);
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 = g.data.conversationId, s = g.data.latestSequence ?? null;
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_${ie(16)}`;
650
- await ae({
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__ */ c((a) => {
665
- const g = X(a);
666
- g && e.onMessage?.(g);
659
+ onMessage: /* @__PURE__ */ l((a) => {
660
+ const u = X(a);
661
+ u && e.onMessage?.(u);
667
662
  }, "onMessage"),
668
- onDone: /* @__PURE__ */ c(() => e.onDone(o), "onDone"),
669
- onChatError: /* @__PURE__ */ c((a) => e.onError(Y(a)), "onChatError"),
670
- onTransportError: /* @__PURE__ */ c((a) => e.onError(ge(a)), "onTransportError")
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
- c(q, "ChatClient");
675
- let C = q;
669
+ l(q, "ChatClient");
670
+ let j = q;
676
671
  const M = class M {
677
672
  constructor(e) {
678
- l(this, "ctx");
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 = O({ prefix: "anon" }), this.ctx.storage.setItem(e, 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
- c(M, "UserClient");
732
- let j = M;
726
+ l(M, "UserClient");
727
+ let C = M;
733
728
  const H = class H {
734
729
  constructor() {
735
- l(this, "key", "__PAGELINES_SDK__");
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
- c(H, "SDKGlobal");
743
+ l(H, "SDKGlobal");
749
744
  let _ = H;
750
- const $ = new _(), B = class B extends ce {
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
- l(this, "activeUser", b());
758
- l(this, "token", b(null));
759
- // Refresh credential lives in HttpOnly pl-refresh-token cookie JS never
760
- // holds it, so no reactive ref. /api/auth/refresh reads the cookie via the
761
- // browser's automatic credentials: 'include' attach.
762
- l(this, "deviceId", b(null));
763
- l(this, "loading", b(!1));
764
- l(this, "error", b(null));
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
- l(this, "storage", new F());
761
+ c(this, "storage", new D());
768
762
  // Auto-managed session ID for usage tracking
769
- l(this, "sessionId", O({ prefix: "ses" }));
763
+ c(this, "sessionId", P({ prefix: "ses" }));
770
764
  // Computed properties derived from activeUser (matches UserClient pattern)
771
- l(this, "currentAgent", V(() => {
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
- l(this, "currentOrg", V(() => {
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
- l(this, "initialized");
789
- l(this, "resolveUser");
782
+ c(this, "initialized");
783
+ c(this, "resolveUser");
790
784
  // Sub-clients (new preferred API surface)
791
- l(this, "agent");
792
- l(this, "auth");
793
- l(this, "billing");
794
- l(this, "chat");
795
- l(this, "user");
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: le(
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 P(s), this.auth = new R(s), this.billing = new L(s), this.chat = new C(s), this.user = new j(s), this.logger.info("PageLinesSDK initialized"), this.storage.loadFromStorage(this.authRefs()), this.storage.syncWithGlobalStores(this.authRefs()), this.initialized = new Promise((n) => {
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 B(t);
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 = O({ prefix: "ses" }), $.delete();
852
+ this.logger.info("Clearing SDK completely"), this.clearSession(), this.loading.value = !1, this.sessionId = P({ prefix: "ses" }), $.delete();
867
853
  }
868
854
  };
869
- c(B, "PageLinesSDK");
870
- let Z = B;
855
+ l(O, "PageLinesSDK");
856
+ let Z = O;
871
857
  export {
872
- P as A,
858
+ R as A,
873
859
  L as B,
874
- C,
860
+ j as C,
875
861
  Z as P,
876
- j as U,
877
- R as a,
862
+ C as U,
863
+ F as a,
878
864
  p as r
879
865
  };
880
866
  //# sourceMappingURL=sdkClient.js.map