@pagelines/sdk 1.0.516 → 1.0.518

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,81 +1,71 @@
1
- var Q = Object.defineProperty;
2
- var te = (i, e, t) => e in i ? Q(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
- var u = (i, e) => Q(i, "name", { value: e, configurable: !0 });
4
- var c = (i, e, t) => te(i, typeof e != "symbol" ? e + "" : e, t);
5
- import { APP_PORT as re, APP_PROD_URL as se, createRefreshingFetch as oe, cookieUtil as b, createLogger as ae, shortId as ie, objectId as O, SettingsObject as ne } from "@pagelines/core";
6
- import { watch as R, ref as E, computed as X } from "vue";
7
- import { hc as ce } from "hono/client";
8
- function y(i, e) {
9
- return i || (e ? `http://localhost:${re}` : se);
1
+ var ae = Object.defineProperty;
2
+ var ve = (n, e, t) => e in n ? ae(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
+ var u = (n, e) => ae(n, "name", { value: e, configurable: !0 });
4
+ var c = (n, e, t) => ve(n, typeof e != "symbol" ? e + "" : e, t);
5
+ import { APP_PORT as pe, APP_PROD_URL as me, createRefreshingFetch as ye, cookieUtil as U, createLogger as we, shortId as xe, objectId as C, SettingsObject as Se } from "@pagelines/core";
6
+ import { watch as N, ref as R, computed as oe } from "vue";
7
+ function I(n, e) {
8
+ return n || (e ? `http://localhost:${pe}` : me);
10
9
  }
11
- u(y, "resolveApiBase");
12
- function le(i, e, t) {
13
- const r = y(i.apiBase, i.isDev), s = t ? oe({
10
+ u(I, "resolveApiBase");
11
+ function Ie(n, e, t) {
12
+ const r = I(n.apiBase, n.isDev), s = t ? ye({
14
13
  fetch: globalThis.fetch.bind(globalThis),
15
14
  getDeviceId: t.getDeviceId,
16
15
  refreshUrl: `${r}/api/auth/refresh`,
17
16
  onAccessTokenRefreshed: t.onAccessTokenRefreshed,
18
17
  onTerminalFailure: t.onTerminalFailure
19
18
  }) : globalThis.fetch.bind(globalThis);
20
- return ce(r, {
21
- fetch: /* @__PURE__ */ u(async (n, g) => {
22
- const a = b.getAuthToken(), l = await s(n, {
23
- ...g,
24
- headers: {
25
- ...g?.headers,
26
- "Content-Type": "application/json",
27
- // Only include Authorization header if token exists
28
- ...a && { Authorization: `Bearer ${a}` }
29
- },
30
- // 'include' so the browser attaches the HttpOnly pl-refresh-token
31
- // cookie when /refresh is hit. Server allows credentials per origin
32
- // (no CORS wildcard) so iOS/Android-WebView and same-origin web both
33
- // work; embeds on third-party sites must be on a CORS-allowed origin.
34
- credentials: "include"
35
- });
36
- if (e) {
37
- const h = l.json.bind(l);
38
- l.json = async () => {
39
- const d = await h();
40
- return typeof d == "object" && d !== null && "ok" in d && ("user" in d || "token" in d) && e(d), d;
41
- };
42
- }
43
- return l;
44
- }, "fetch")
45
- });
19
+ return async (a, i) => {
20
+ const h = U.getAuthToken(), o = new Headers(i?.headers);
21
+ o.has("Content-Type") || o.set("Content-Type", "application/json"), h && !o.has("Authorization") && o.set("Authorization", `Bearer ${h}`);
22
+ const p = typeof a == "string" && a.startsWith("/") ? `${r}${a}` : a, g = await s(p, {
23
+ ...i,
24
+ headers: o,
25
+ credentials: "include"
26
+ });
27
+ if (e) {
28
+ const w = g.json.bind(g);
29
+ g.json = async () => {
30
+ const l = await w();
31
+ return typeof l == "object" && l !== null && "ok" in l && ("user" in l || "token" in l) && e(l), l;
32
+ };
33
+ }
34
+ return g;
35
+ };
46
36
  }
47
- u(le, "createApiClient");
48
- const de = /* @__PURE__ */ Symbol("clean");
49
- let w = [], I = 0;
50
- const U = 4, ue = globalThis.nanostoresGlobal || (globalThis.nanostoresGlobal = { epoch: 0 }), G = /* @__PURE__ */ u(/* @__NO_SIDE_EFFECTS__ */ (i) => {
37
+ u(Ie, "createApiFetch");
38
+ const ke = /* @__PURE__ */ Symbol("clean");
39
+ let y = [], b = 0;
40
+ const P = 4, be = globalThis.nanostoresGlobal || (globalThis.nanostoresGlobal = { epoch: 0 }), H = /* @__PURE__ */ u(/* @__NO_SIDE_EFFECTS__ */ (n) => {
51
41
  let e = [], t = {
52
42
  get() {
53
43
  return t.lc || t.listen(() => {
54
44
  })(), t.value;
55
45
  },
56
- init: i,
46
+ init: n,
57
47
  lc: 0,
58
48
  listen(r) {
59
49
  return t.lc = e.push(r), () => {
60
- for (let o = I + U; o < w.length; )
61
- w[o] === r ? w.splice(o, U) : o += U;
50
+ for (let a = b + P; a < y.length; )
51
+ y[a] === r ? y.splice(a, P) : a += P;
62
52
  let s = e.indexOf(r);
63
53
  ~s && (e.splice(s, 1), --t.lc || t.off());
64
54
  };
65
55
  },
66
56
  notify(r, s) {
67
- ue.epoch++;
68
- let o = !w.length;
69
- for (let n of e)
70
- w.push(n, t.value, r, s);
71
- if (o) {
72
- for (I = 0; I < w.length; I += U)
73
- w[I](
74
- w[I + 1],
75
- w[I + 2],
76
- w[I + 3]
57
+ be.epoch++;
58
+ let a = !y.length;
59
+ for (let i of e)
60
+ y.push(i, t.value, r, s);
61
+ if (a) {
62
+ for (b = 0; b < y.length; b += P)
63
+ y[b](
64
+ y[b + 1],
65
+ y[b + 2],
66
+ y[b + 3]
77
67
  );
78
- w.length = 0;
68
+ y.length = 0;
79
69
  }
80
70
  },
81
71
  /* It will be called on last listener unsubscribing.
@@ -90,14 +80,14 @@ const U = 4, ue = globalThis.nanostoresGlobal || (globalThis.nanostoresGlobal =
90
80
  let s = t.listen(r);
91
81
  return r(t.value), s;
92
82
  },
93
- value: i
83
+ value: n
94
84
  };
95
- return process.env.NODE_ENV !== "production" && (t[de] = () => {
85
+ return process.env.NODE_ENV !== "production" && (t[ke] = () => {
96
86
  e = [], t.lc = 0, t.off();
97
87
  }), t;
98
- }, "atom"), x = globalThis, T = x.__PL_AUTH_USER__ ?? (x.__PL_AUTH_USER__ = /* @__PURE__ */ G(void 0)), A = x.__PL_AUTH_TOKEN__ ?? (x.__PL_AUTH_TOKEN__ = /* @__PURE__ */ G(null)), $ = x.__PL_AUTH_DEVICE_ID__ ?? (x.__PL_AUTH_DEVICE_ID__ = /* @__PURE__ */ G(null)), z = class z {
88
+ }, "atom"), k = globalThis, D = k.__PL_AUTH_USER__ ?? (k.__PL_AUTH_USER__ = /* @__PURE__ */ H(void 0)), B = k.__PL_AUTH_TOKEN__ ?? (k.__PL_AUTH_TOKEN__ = /* @__PURE__ */ H(null)), _ = k.__PL_AUTH_DEVICE_ID__ ?? (k.__PL_AUTH_DEVICE_ID__ = /* @__PURE__ */ H(null)), V = class V {
99
89
  constructor() {
100
- c(this, "logger", ae("SDKStorage"));
90
+ c(this, "logger", we("SDKStorage"));
101
91
  }
102
92
  /**
103
93
  * Check if localStorage is fully functional (some test environments provide partial mocks)
@@ -109,13 +99,13 @@ const U = 4, ue = globalThis.nanostoresGlobal || (globalThis.nanostoresGlobal =
109
99
  * Sync Vue reactive refs with global nanostores for cross-bundle persistence.
110
100
  */
111
101
  syncWithGlobalStores(e) {
112
- const { activeUser: t, token: r, deviceId: s } = e, o = T.get(), n = A.get(), g = $.get();
113
- o && (t.value = o), n && (r.value = n), g && (s.value = g), R(t, (a) => T.set(a), { immediate: !0 }), R(r, (a) => A.set(a), { immediate: !0 }), R(s, (a) => $.set(a), { immediate: !0 }), T.subscribe((a) => {
114
- a !== t.value && (t.value = a);
115
- }), A.subscribe((a) => {
116
- a !== r.value && (r.value = a);
117
- }), $.subscribe((a) => {
118
- a !== s.value && (s.value = a);
102
+ const { activeUser: t, token: r, deviceId: s } = e, a = D.get(), i = B.get(), h = _.get();
103
+ a && (t.value = a), i && (r.value = i), h && (s.value = h), N(t, (o) => D.set(o), { immediate: !0 }), N(r, (o) => B.set(o), { immediate: !0 }), N(s, (o) => _.set(o), { immediate: !0 }), D.subscribe((o) => {
104
+ o !== t.value && (t.value = o);
105
+ }), B.subscribe((o) => {
106
+ o !== r.value && (r.value = o);
107
+ }), _.subscribe((o) => {
108
+ o !== s.value && (s.value = o);
119
109
  });
120
110
  }
121
111
  /**
@@ -125,9 +115,9 @@ const U = 4, ue = globalThis.nanostoresGlobal || (globalThis.nanostoresGlobal =
125
115
  loadFromStorage(e) {
126
116
  if (typeof window > "u")
127
117
  return;
128
- const t = b.getAuthToken();
118
+ const t = U.getAuthToken();
129
119
  t && (e.token.value = t);
130
- const r = b.getDeviceId();
120
+ const r = U.getDeviceId();
131
121
  if (r && (e.deviceId.value = r), this.isLocalStorageFunctional())
132
122
  try {
133
123
  const s = localStorage.getItem("pagelines-user");
@@ -141,7 +131,7 @@ const U = 4, ue = globalThis.nanostoresGlobal || (globalThis.nanostoresGlobal =
141
131
  * deviceId is server-owned (Set-Cookie) — JS doesn't write it.
142
132
  */
143
133
  saveToStorage(e) {
144
- if (!(typeof window > "u") && (e.token.value ? b.setAuthToken(e.token.value) : b.removeAuthToken(), this.isLocalStorageFunctional()))
134
+ if (!(typeof window > "u") && (e.token.value ? U.setAuthToken(e.token.value) : U.removeAuthToken(), this.isLocalStorageFunctional()))
145
135
  try {
146
136
  e.activeUser.value ? localStorage.setItem("pagelines-user", JSON.stringify(e.activeUser.value)) : localStorage.removeItem("pagelines-user");
147
137
  } catch (t) {
@@ -155,13 +145,13 @@ const U = 4, ue = globalThis.nanostoresGlobal || (globalThis.nanostoresGlobal =
155
145
  */
156
146
  clearStorage() {
157
147
  if (!(typeof window > "u")) {
158
- if (b.removeAuthToken(), this.isLocalStorageFunctional())
148
+ if (U.removeAuthToken(), this.isLocalStorageFunctional())
159
149
  try {
160
150
  localStorage.removeItem("pagelines-user");
161
151
  } catch (e) {
162
152
  this.logger.error("Failed to clear user from localStorage", { data: e });
163
153
  }
164
- T.set(void 0), A.set(null), $.set(null);
154
+ D.set(void 0), B.set(null), _.set(null);
165
155
  }
166
156
  }
167
157
  /**
@@ -188,15 +178,15 @@ const U = 4, ue = globalThis.nanostoresGlobal || (globalThis.nanostoresGlobal =
188
178
  }
189
179
  }
190
180
  };
191
- u(z, "SDKStorage");
192
- let P = z;
193
- const M = class M {
181
+ u(V, "SDKStorage");
182
+ let J = V;
183
+ const Q = class Q {
194
184
  constructor(e) {
195
185
  c(this, "ctx");
196
186
  this.ctx = e;
197
187
  }
198
188
  async create(e) {
199
- const t = e.orgId || this.resolveOrgId(), r = y(this.ctx.apiBase, this.ctx.isDev), o = await (await fetch(`${r}/api/agents`, {
189
+ const t = e.orgId || this.resolveOrgId(), r = I(this.ctx.apiBase, this.ctx.isDev), a = await (await fetch(`${r}/api/agents`, {
200
190
  method: "POST",
201
191
  headers: {
202
192
  "Content-Type": "application/json",
@@ -204,14 +194,14 @@ const M = class M {
204
194
  },
205
195
  body: JSON.stringify({ name: e.name, orgId: t })
206
196
  })).json();
207
- if (!o.ok || !o.data?.[0]) {
208
- const n = o.error || "Failed to create agent";
209
- throw this.ctx.error.value = n, new Error(n);
197
+ if (!a.ok || !a.data?.[0]) {
198
+ const i = a.error || "Failed to create agent";
199
+ throw this.ctx.error.value = i, new Error(i);
210
200
  }
211
- return this.ctx.processApiResponse(o), o.data[0];
201
+ return this.ctx.processApiResponse(a), a.data[0];
212
202
  }
213
203
  async getStatus(e) {
214
- const t = y(this.ctx.apiBase, this.ctx.isDev), s = await (await fetch(`${t}/api/agents/${e.agentId}/status`, {
204
+ const t = I(this.ctx.apiBase, this.ctx.isDev), s = await (await fetch(`${t}/api/agents/${e.agentId}/status`, {
215
205
  headers: {
216
206
  ...this.ctx.token.value && { Authorization: `Bearer ${this.ctx.token.value}` }
217
207
  }
@@ -228,34 +218,34 @@ const M = class M {
228
218
  * names to user copy at the call site.
229
219
  */
230
220
  async waitUntilReady(e) {
231
- const { agentId: t, onStatus: r, timeoutMs: s = 3e5, pollIntervalMs: o = 3e3 } = e, n = Date.now();
232
- let g;
233
- for (; Date.now() - n < s; ) {
234
- const a = await this.getStatus({ agentId: t });
235
- if (a.ready) {
221
+ const { agentId: t, onStatus: r, timeoutMs: s = 3e5, pollIntervalMs: a = 3e3 } = e, i = Date.now();
222
+ let h;
223
+ for (; Date.now() - i < s; ) {
224
+ const o = await this.getStatus({ agentId: t });
225
+ if (o.ready) {
236
226
  r?.("running");
237
227
  return;
238
228
  }
239
- if (a.status === "error")
240
- throw new Error(a.error || "Provisioning failed");
241
- a.status !== g && (r?.(a.status), g = a.status), await new Promise((l) => setTimeout(l, o));
229
+ if (o.status === "error")
230
+ throw new Error(o.error || "Provisioning failed");
231
+ o.status !== h && (r?.(o.status), h = o.status), await new Promise((p) => setTimeout(p, a));
242
232
  }
243
233
  throw new Error("Agent provisioning timed out — please try again");
244
234
  }
245
235
  /** Send a typed webhook event to a bot agent. No auth required — the proxy is public. */
246
236
  async webhook(e) {
247
- const r = `${y(this.ctx.apiBase, this.ctx.isDev)}/api/bot-api/agents/${e.agentId}/webhook`, s = { type: e.type, data: e.data };
237
+ const r = `${I(this.ctx.apiBase, this.ctx.isDev)}/api/bot-api/webhooks/agents/${e.agentId}`, s = { type: e.type, data: e.data };
248
238
  e.meta && (s.meta = e.meta);
249
- const o = await fetch(r, {
239
+ const a = await fetch(r, {
250
240
  method: "POST",
251
241
  headers: { "Content-Type": "application/json" },
252
242
  body: JSON.stringify(s)
253
243
  });
254
- if (!o.ok) {
255
- const n = await o.text().catch(() => "Unknown error");
256
- throw new Error(`Webhook delivery failed (${o.status}): ${n.slice(0, 200)}`);
244
+ if (!a.ok) {
245
+ const i = await a.text().catch(() => "Unknown error");
246
+ throw new Error(`Webhook delivery failed (${a.status}): ${i.slice(0, 200)}`);
257
247
  }
258
- return o.json();
248
+ return a.json();
259
249
  }
260
250
  resolveOrgId() {
261
251
  const t = this.ctx.activeUser.value?.orgs?.[0]?.orgId;
@@ -264,27 +254,28 @@ const M = class M {
264
254
  return t;
265
255
  }
266
256
  };
267
- u(M, "AgentClient");
268
- let _ = M;
269
- async function S(i, e) {
270
- i.loading.value = !0, i.error.value = null;
257
+ u(Q, "AgentClient");
258
+ let G = Q;
259
+ async function E(n, e) {
260
+ n.loading.value = !0, n.error.value = null;
271
261
  try {
272
262
  return await e();
273
263
  } finally {
274
- i.loading.value = !1;
264
+ n.loading.value = !1;
275
265
  }
276
266
  }
277
- u(S, "withLoadingState");
278
- const W = class W {
267
+ u(E, "withLoadingState");
268
+ const X = class X {
279
269
  constructor(e) {
280
270
  c(this, "ctx");
281
271
  this.ctx = e;
282
272
  }
283
273
  async sendCode(e) {
284
- return S(this.ctx, async () => {
274
+ return E(this.ctx, async () => {
285
275
  try {
286
- const r = await (await this.ctx.api.auth["check-email"].$post({
287
- json: { email: e }
276
+ const r = await (await this.ctx.apiFetch("/api/auth/check-email", {
277
+ method: "POST",
278
+ body: JSON.stringify({ email: e })
288
279
  })).json();
289
280
  if (!r.ok)
290
281
  throw this.ctx.error.value = r.error, new Error(r.error);
@@ -296,10 +287,11 @@ const W = class W {
296
287
  });
297
288
  }
298
289
  async verifyCode(e, t) {
299
- return S(this.ctx, async () => {
290
+ return E(this.ctx, async () => {
300
291
  try {
301
- const s = await (await this.ctx.api.auth["verify-code"].$post({
302
- json: { email: e, code: t }
292
+ const s = await (await this.ctx.apiFetch("/api/auth/verify-code", {
293
+ method: "POST",
294
+ body: JSON.stringify({ email: e, code: t })
303
295
  })).json();
304
296
  if (!s.ok)
305
297
  throw this.ctx.error.value = s.error, new Error(s.error);
@@ -311,9 +303,9 @@ const W = class W {
311
303
  });
312
304
  }
313
305
  async logout() {
314
- return S(this.ctx, async () => {
306
+ return E(this.ctx, async () => {
315
307
  try {
316
- await this.ctx.api.auth.logout.$post();
308
+ await this.ctx.apiFetch("/api/auth/logout", { method: "POST" });
317
309
  } catch (e) {
318
310
  this.ctx.logger.error("Logout error (user still logged out locally)", { data: e });
319
311
  }
@@ -322,17 +314,16 @@ const W = class W {
322
314
  }
323
315
  async getCurrentUser() {
324
316
  if (this.ctx.token.value)
325
- return S(this.ctx, async () => {
317
+ return E(this.ctx, async () => {
326
318
  try {
327
- const e = y(this.ctx.apiBase, this.ctx.isDev), r = await (await fetch(`${e}/api/users/me`, {
328
- method: "GET",
329
- headers: { Authorization: `Bearer ${this.ctx.token.value}` }
319
+ const t = await (await this.ctx.apiFetch("/api/users/me", {
320
+ method: "GET"
330
321
  })).json();
331
- if (!r.ok) {
332
- this.ctx.error.value = r.error, r.error.includes("Authentication") && (this.ctx.activeUser.value = void 0, this.ctx.token.value = null, this.ctx.storage.clearStorage());
322
+ if (!t.ok) {
323
+ 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());
333
324
  return;
334
325
  }
335
- return this.ctx.token.value && (this.ctx.activeUser.value = r.data), r.data;
326
+ return this.ctx.token.value && (this.ctx.activeUser.value = t.data), t.data;
336
327
  } catch (e) {
337
328
  this.ctx.logger.error("Get current user error", { data: e }), this.ctx.error.value = e instanceof Error ? e.message : "Failed to get user info";
338
329
  return;
@@ -340,10 +331,11 @@ const W = class W {
340
331
  });
341
332
  }
342
333
  async requestAuthCode(e) {
343
- return S(this.ctx, async () => {
334
+ return E(this.ctx, async () => {
344
335
  try {
345
- const r = await (await this.ctx.api.auth["check-email"].$post({
346
- json: { email: e.email }
336
+ const r = await (await this.ctx.apiFetch("/api/auth/check-email", {
337
+ method: "POST",
338
+ body: JSON.stringify({ email: e.email })
347
339
  })).json();
348
340
  return r.ok ? (this.ctx.logger.info("Auth code requested successfully", { email: e.email }), !0) : (this.ctx.error.value = r.error, this.ctx.logger.error("Failed to request auth code", { email: e.email, error: r.error }), !1);
349
341
  } catch (t) {
@@ -352,10 +344,11 @@ const W = class W {
352
344
  });
353
345
  }
354
346
  async loginWithCode(e) {
355
- return S(this.ctx, async () => {
347
+ return E(this.ctx, async () => {
356
348
  try {
357
- const r = await (await this.ctx.api.auth["verify-code"].$post({
358
- json: { email: e.email, code: e.code }
349
+ const r = await (await this.ctx.apiFetch("/api/auth/verify-code", {
350
+ method: "POST",
351
+ body: JSON.stringify({ email: e.email, code: e.code })
359
352
  })).json();
360
353
  return r.ok ? (this.ctx.logger.info("Login successful", { email: e.email }), !0) : (this.ctx.error.value = r.error, this.ctx.logger.error("Login failed", { email: e.email, error: r.error }), !1);
361
354
  } catch (t) {
@@ -368,45 +361,45 @@ const W = class W {
368
361
  this.ctx.logger.error("loginWithGoogle: Only available in browser");
369
362
  return;
370
363
  }
371
- const t = y(this.ctx.apiBase, this.ctx.isDev), r = window.location.origin, s = `${t}/auth/google-popup?origin=${encodeURIComponent(r)}`, o = 500, n = 600, g = window.screenX + (window.outerWidth - o) / 2, a = window.screenY + (window.outerHeight - n) / 2, l = window.open(
364
+ const t = I(this.ctx.apiBase, this.ctx.isDev), r = window.location.origin, s = `${t}/auth/google-popup?origin=${encodeURIComponent(r)}`, a = 500, i = 600, h = window.screenX + (window.outerWidth - a) / 2, o = window.screenY + (window.outerHeight - i) / 2, p = window.open(
372
365
  s,
373
366
  "google-auth",
374
- `width=${o},height=${n},left=${g},top=${a},popup=yes`
367
+ `width=${a},height=${i},left=${h},top=${o},popup=yes`
375
368
  );
376
- if (!l) {
377
- const p = "Popup was blocked. Please allow popups for this site.";
378
- this.ctx.error.value = p, e?.onError?.(p);
369
+ if (!p) {
370
+ const l = "Popup was blocked. Please allow popups for this site.";
371
+ this.ctx.error.value = l, e?.onError?.(l);
379
372
  return;
380
373
  }
381
- const h = /* @__PURE__ */ u((p) => {
382
- const k = new URL(t).origin;
383
- if (p.origin === k) {
384
- if (p.data?.type === "auth-success") {
385
- window.removeEventListener("message", h);
386
- const { token: m, user: f } = p.data;
387
- this.ctx.processApiResponse({ ok: !0, data: {}, token: m, user: f }), this.ctx.logger.info("Google login successful"), e?.onSuccess?.(f);
388
- } else if (p.data?.type === "auth-error") {
389
- window.removeEventListener("message", h);
390
- const m = p.data.error || "Google authentication failed";
391
- this.ctx.error.value = m, this.ctx.logger.error("Google login failed", { error: m }), e?.onError?.(m);
374
+ const g = /* @__PURE__ */ u((l) => {
375
+ const m = new URL(t).origin;
376
+ if (l.origin === m) {
377
+ if (l.data?.type === "auth-success") {
378
+ window.removeEventListener("message", g);
379
+ const { token: x, user: f } = l.data;
380
+ this.ctx.processApiResponse({ ok: !0, data: {}, token: x, user: f }), this.ctx.logger.info("Google login successful"), e?.onSuccess?.(f);
381
+ } else if (l.data?.type === "auth-error") {
382
+ window.removeEventListener("message", g);
383
+ const x = l.data.error || "Google authentication failed";
384
+ this.ctx.error.value = x, this.ctx.logger.error("Google login failed", { error: x }), e?.onError?.(x);
392
385
  }
393
386
  }
394
387
  }, "handler");
395
- window.addEventListener("message", h);
396
- const d = setInterval(() => {
397
- l.closed && (clearInterval(d), window.removeEventListener("message", h));
388
+ window.addEventListener("message", g);
389
+ const w = setInterval(() => {
390
+ p.closed && (clearInterval(w), window.removeEventListener("message", g));
398
391
  }, 500);
399
392
  }
400
393
  };
401
- u(W, "AuthClient");
402
- let F = W;
403
- const J = class J {
394
+ u(X, "AuthClient");
395
+ let z = X;
396
+ const Y = class Y {
404
397
  constructor(e) {
405
398
  c(this, "ctx");
406
399
  this.ctx = e;
407
400
  }
408
401
  async startTrial(e) {
409
- const t = this.resolveOrgId(), r = y(this.ctx.apiBase, this.ctx.isDev), o = await (await fetch(`${r}/api/billing/checkout/create`, {
402
+ const t = this.resolveOrgId(), r = I(this.ctx.apiBase, this.ctx.isDev), a = await (await fetch(`${r}/api/billing/checkout/create`, {
410
403
  method: "POST",
411
404
  headers: {
412
405
  "Content-Type": "application/json",
@@ -418,17 +411,17 @@ const J = class J {
418
411
  ...e?.planKey && { planKey: e.planKey }
419
412
  })
420
413
  })).json();
421
- if (!o.ok || !o.data?.url) {
422
- const n = o.error || "Failed to create checkout session";
423
- throw this.ctx.error.value = n, new Error(n);
414
+ if (!a.ok || !a.data?.url) {
415
+ const i = a.error || "Failed to create checkout session";
416
+ throw this.ctx.error.value = i, new Error(i);
424
417
  }
425
- window.location.href = o.data.url;
418
+ window.location.href = a.data.url;
426
419
  }
427
420
  async confirmCheckout(e) {
428
421
  return this.getStatus();
429
422
  }
430
423
  async getStatus() {
431
- const e = this.resolveOrgId(), t = y(this.ctx.apiBase, this.ctx.isDev), s = await (await fetch(`${t}/api/billing/details/${e}`, {
424
+ const e = this.resolveOrgId(), t = I(this.ctx.apiBase, this.ctx.isDev), s = await (await fetch(`${t}/api/billing/details/${e}`, {
432
425
  headers: {
433
426
  ...this.ctx.token.value && { Authorization: `Bearer ${this.ctx.token.value}` }
434
427
  }
@@ -440,11 +433,11 @@ const J = class J {
440
433
  hasActiveBilling: !1,
441
434
  maxAgents: 0
442
435
  };
443
- const o = ["active", "trialing"];
436
+ const a = ["active", "trialing"];
444
437
  return {
445
438
  plan: s.data.plan,
446
439
  status: s.data.status,
447
- hasActiveBilling: o.includes(s.data.status),
440
+ hasActiveBilling: a.includes(s.data.status),
448
441
  maxAgents: s.data.maxAgents,
449
442
  ...s.data.trialEnd && { trialEnd: s.data.trialEnd },
450
443
  ...s.data.trialDaysRemaining !== void 0 && { trialDaysRemaining: s.data.trialDaysRemaining }
@@ -457,16 +450,16 @@ const J = class J {
457
450
  return t;
458
451
  }
459
452
  };
460
- u(J, "BillingClient");
461
- let j = J;
462
- const he = /* @__PURE__ */ new Set(["message", "message_delta", "working_state", "working_end", "error", "stream_end"]);
463
- function Y(i) {
464
- const e = i.split(`
453
+ u(Y, "BillingClient");
454
+ let W = Y;
455
+ const Te = /* @__PURE__ */ new Set(["status", "message", "message_delta", "working_state", "working_end", "error", "stream_end"]);
456
+ function ie(n) {
457
+ const e = n.split(`
465
458
  `).filter((s) => s.length > 0);
466
459
  let t, r;
467
460
  for (const s of e)
468
461
  s.startsWith("event:") ? t = s.slice(6).trim() : s.startsWith("data:") && (r = s.slice(5).trim());
469
- if (!t || r === void 0 || !he.has(t))
462
+ if (!t || r === void 0 || !Te.has(t))
470
463
  return null;
471
464
  try {
472
465
  return { event: t, data: JSON.parse(r) };
@@ -474,20 +467,20 @@ function Y(i) {
474
467
  return null;
475
468
  }
476
469
  }
477
- u(Y, "parseChatEvent");
478
- function Z(i) {
479
- if (!(i.role !== "assistant" && i.role !== "system"))
470
+ u(ie, "parseChatEvent");
471
+ function ne(n) {
472
+ if (!(n.role !== "assistant" && n.role !== "system"))
480
473
  return {
481
- id: i.messageId,
482
- text: i.content,
483
- sender: i.role === "system" ? "system" : "agent",
484
- timestamp: i.createdAt,
485
- ...i.metadata?.attachments?.length ? { attachments: i.metadata.attachments } : {},
486
- ...i.metadata?.issue ? { issue: i.metadata.issue } : {}
474
+ id: n.messageId,
475
+ text: n.content,
476
+ sender: n.role === "system" ? "system" : "agent",
477
+ timestamp: n.createdAt,
478
+ ...n.metadata?.attachments?.length ? { attachments: n.metadata.attachments } : {},
479
+ ...n.metadata?.issue ? { issue: n.metadata.issue } : {}
487
480
  };
488
481
  }
489
- u(Z, "toChatMessage");
490
- const q = class q {
482
+ u(ne, "toChatMessage");
483
+ const Z = class Z {
491
484
  constructor(e) {
492
485
  c(this, "ctx");
493
486
  this.ctx = e;
@@ -503,10 +496,10 @@ const q = class q {
503
496
  * which stores a stable ID in localStorage).
504
497
  */
505
498
  async chatStreamPublic(e) {
506
- const r = `${y(this.ctx.apiBase, this.ctx.isDev)}/api/agents/public/${encodeURIComponent(e.handle)}/chat/v2/stream`;
507
- let s = "", o = !1, n = !1, g;
499
+ const r = `${I(this.ctx.apiBase, this.ctx.isDev)}/api/agents/public/${encodeURIComponent(e.handle)}/chat/v2/stream`;
500
+ let s = "", a = !1, i = !1, h;
508
501
  try {
509
- const a = await fetch(r, {
502
+ const o = await fetch(r, {
510
503
  method: "POST",
511
504
  headers: { "Content-Type": "application/json" },
512
505
  body: JSON.stringify({
@@ -516,145 +509,198 @@ const q = class q {
516
509
  ...e.context ? { context: e.context } : {}
517
510
  })
518
511
  });
519
- if (!a.ok) {
520
- const d = await a.json().catch(() => ({ error: "Request failed" }));
521
- e.onError(d.error || `HTTP ${a.status}`);
512
+ if (!o.ok) {
513
+ const w = await o.json().catch(() => ({ error: "Request failed" }));
514
+ e.onError(w.error || `HTTP ${o.status}`);
522
515
  return;
523
516
  }
524
- if (s = a.headers.get("X-Conversation-Id") || "", g = a.body?.getReader(), !g) {
517
+ if (s = o.headers.get("X-Conversation-Id") || "", h = o.body?.getReader(), !h) {
525
518
  e.onError("No response stream");
526
519
  return;
527
520
  }
528
- const l = new TextDecoder();
529
- let h = "";
521
+ const p = new TextDecoder();
522
+ let g = "";
530
523
  e: for (; ; ) {
531
- const { done: d, value: p } = await g.read();
532
- if (d)
524
+ const { done: w, value: l } = await h.read();
525
+ if (w)
533
526
  break;
534
- h += l.decode(p, { stream: !0 });
535
- let k = h.indexOf(`
527
+ g += p.decode(l, { stream: !0 });
528
+ let m = g.indexOf(`
536
529
 
537
530
  `);
538
- for (; k !== -1; ) {
539
- const m = h.slice(0, k);
540
- h = h.slice(k + 2);
541
- const f = Y(m);
531
+ for (; m !== -1; ) {
532
+ const x = g.slice(0, m);
533
+ g = g.slice(m + 2);
534
+ const f = ie(x);
542
535
  if (f) {
543
536
  if (f.event === "working_state")
544
537
  e.onStatus?.(f.data.description);
545
538
  else if (f.event === "message_delta")
546
539
  e.onDelta(f.data.delta, f.data.role);
547
540
  else if (f.event === "error") {
548
- o = !0, e.onError(f.data.message);
541
+ a = !0, e.onError(f.data.message);
549
542
  break e;
550
543
  } else if (f.event === "message" && (f.data.message.role === "assistant" || f.data.message.role === "system")) {
551
- n = !0;
552
- const v = Z(f.data.message);
553
- v && e.onMessage?.(v);
544
+ i = !0;
545
+ const A = ne(f.data.message);
546
+ A && e.onMessage?.(A);
554
547
  } else if (f.event === "stream_end")
555
548
  break e;
556
549
  }
557
- k = h.indexOf(`
550
+ m = g.indexOf(`
558
551
 
559
552
  `);
560
553
  }
561
554
  }
562
- !o && n ? e.onDone(s) : o || e.onError("Stream ended before reply arrived");
563
- } catch (a) {
564
- e.onError(a instanceof Error ? a.message : "Stream failed");
555
+ !a && i ? e.onDone(s) : a || e.onError("Stream ended before reply arrived");
556
+ } catch (o) {
557
+ e.onError(o instanceof Error ? o.message : "Stream failed");
565
558
  } finally {
566
559
  try {
567
- await g?.cancel();
560
+ await h?.cancel();
568
561
  } catch {
569
562
  }
570
563
  }
571
564
  }
572
565
  /**
573
- * Authenticated chat — substrate-backed (POST /api/messages + SSE on
574
- * /api/chat/:agentId/stream). Same callback contract as the legacy
575
- * `chatStream` so callers don't need to know which transport runs underneath.
566
+ * Authenticated chat — substrate-backed:
567
+ * POST /api/conversations, open SSE from that conversation's latest
568
+ * sequence, then POST /api/messages. Opening the stream before send keeps
569
+ * fast working_state / message_delta frames from outrunning the subscriber.
570
+ * Same callback contract as `chatStream` so callers don't need transport details.
576
571
  * Mirrors `src/modules/agent/client.ts → sendChatMessageStream`.
577
572
  */
578
573
  async chatStreamAuthenticated(e) {
579
- const t = y(this.ctx.apiBase, this.ctx.isDev), r = this.ctx.token.value ? { Authorization: `Bearer ${this.ctx.token.value}` } : {}, s = `nonce_${ie(16)}`;
580
- let o;
574
+ const t = I(this.ctx.apiBase, this.ctx.isDev), r = this.ctx.token.value ? { Authorization: `Bearer ${this.ctx.token.value}` } : {};
575
+ let s, a = null;
581
576
  try {
582
- const l = await fetch(`${t}/api/messages`, {
577
+ const d = await fetch(`${t}/api/conversations`, {
583
578
  method: "POST",
584
579
  headers: { "Content-Type": "application/json", ...r },
585
- body: JSON.stringify({ agentId: e.agentId, content: e.message, clientNonce: s })
586
- }), h = await l.json();
587
- if (!h.ok) {
588
- e.onError(h.error || `Send failed: HTTP ${l.status}`);
580
+ body: JSON.stringify({ agentId: e.agentId })
581
+ }), S = await d.json();
582
+ if (!S.ok) {
583
+ e.onError(S.error || `Conversation failed: HTTP ${d.status}`);
589
584
  return;
590
585
  }
591
- o = h.data;
592
- } catch (l) {
593
- e.onError(l instanceof Error ? l.message : "Send failed");
586
+ s = S.data.conversationId, a = S.data.latestSequence ?? null;
587
+ } catch (d) {
588
+ e.onError(d instanceof Error ? d.message : "Conversation failed");
594
589
  return;
595
590
  }
596
- let n = !1, g = !1, a;
597
- try {
598
- const l = await fetch(`${t}/api/chat/${encodeURIComponent(e.agentId)}/stream?since=${encodeURIComponent(o.sequence)}`, {
599
- headers: r
591
+ let i = !1, h = !1, o = !1, p = !1, g = !1, w = !1, l;
592
+ const m = new AbortController();
593
+ let x = !1, f, A = /* @__PURE__ */ u(() => {
594
+ }, "resolveStreamReady");
595
+ const le = new Promise((d) => {
596
+ A = d;
597
+ }), $ = /* @__PURE__ */ u((d) => {
598
+ x || (x = !0, f && clearTimeout(f), A(d));
599
+ }, "settleStreamReady"), re = /* @__PURE__ */ u(() => {
600
+ l?.cancel().catch(() => {
600
601
  });
601
- if (!l.ok) {
602
- e.onError(`Stream failed: HTTP ${l.status}`);
603
- return;
604
- }
605
- if (a = l.body?.getReader(), !a) {
606
- e.onError("No response stream");
607
- return;
608
- }
609
- const h = new TextDecoder();
610
- let d = "";
611
- e: for (; ; ) {
612
- const { done: p, value: k } = await a.read();
613
- if (p)
614
- break;
615
- d += h.decode(k, { stream: !0 });
616
- let m = d.indexOf(`
602
+ }, "cancelReader"), de = a ? `${t}/api/conversations/${encodeURIComponent(s)}/stream?since=${encodeURIComponent(a)}` : `${t}/api/conversations/${encodeURIComponent(s)}/stream`;
603
+ f = setTimeout(() => {
604
+ w = !0, o = !0, e.onError("Timed out opening stream"), m.abort(), $("failed");
605
+ }, 1e4);
606
+ const O = (async () => {
607
+ try {
608
+ const d = await fetch(de, {
609
+ headers: r,
610
+ signal: m.signal
611
+ });
612
+ if (!d.ok) {
613
+ o = !0, $("failed"), e.onError(`Stream failed: HTTP ${d.status}`);
614
+ return;
615
+ }
616
+ if (l = d.body?.getReader(), !l) {
617
+ o = !0, $("failed"), e.onError("No response stream");
618
+ return;
619
+ }
620
+ $("ready");
621
+ const S = new TextDecoder();
622
+ let T = "";
623
+ e: for (; ; ) {
624
+ const { done: he, value: fe } = await l.read();
625
+ if (he)
626
+ break;
627
+ T += S.decode(fe, { stream: !0 });
628
+ let F = T.indexOf(`
617
629
 
618
630
  `);
619
- for (; m !== -1; ) {
620
- const f = d.slice(0, m);
621
- d = d.slice(m + 2);
622
- const v = Y(f);
623
- if (v) {
624
- if (v.event === "working_state")
625
- e.onStatus?.(v.data.description);
626
- else if (v.event === "message_delta")
627
- e.onDelta(v.data.delta, v.data.role);
628
- else if (v.event === "error") {
629
- n = !0, e.onError(v.data.message);
630
- break e;
631
- } else if (v.event === "message" && (v.data.message.role === "assistant" || v.data.message.role === "system")) {
632
- g = !0;
633
- const V = Z(v.data.message);
634
- V && e.onMessage?.(V);
635
- break e;
636
- } else if (v.event === "stream_end")
637
- break e;
638
- }
639
- m = d.indexOf(`
631
+ for (; F !== -1; ) {
632
+ const ge = T.slice(0, F);
633
+ T = T.slice(F + 2);
634
+ const v = ie(ge);
635
+ if (v) {
636
+ if (v.event === "working_state")
637
+ i && e.onStatus?.(v.data.description);
638
+ else if (v.event === "message_delta")
639
+ i && e.onDelta(v.data.delta, v.data.role);
640
+ else if (v.event === "error") {
641
+ o = !0, e.onError(v.data.message);
642
+ break e;
643
+ } else if (v.event === "message" && (v.data.message.role === "assistant" || v.data.message.role === "system")) {
644
+ if (!i)
645
+ continue;
646
+ p = !0;
647
+ const se = ne(v.data.message);
648
+ se && e.onMessage?.(se);
649
+ break e;
650
+ } else if (v.event === "stream_end")
651
+ break e;
652
+ }
653
+ F = T.indexOf(`
640
654
 
641
655
  `);
656
+ }
657
+ }
658
+ !o && p ? e.onDone(s) : !o && i && !h && e.onError("Stream ended before reply arrived");
659
+ } catch (d) {
660
+ !h && !w && (o = !0, $("failed"), e.onError(d instanceof Error ? d.message : "Stream failed"));
661
+ } finally {
662
+ g = !0;
663
+ try {
664
+ await l?.cancel();
665
+ } catch {
642
666
  }
643
667
  }
644
- !n && g ? e.onDone(o.conversationId) : n || e.onError("Stream ended before reply arrived");
645
- } catch (l) {
646
- e.onError(l instanceof Error ? l.message : "Stream failed");
647
- } finally {
648
- try {
649
- await a?.cancel();
650
- } catch {
668
+ })();
669
+ if (await le === "failed") {
670
+ await O;
671
+ return;
672
+ }
673
+ if (g) {
674
+ e.onError("Stream closed before send"), await O;
675
+ return;
676
+ }
677
+ const ue = `nonce_${xe(16)}`;
678
+ try {
679
+ i = !0;
680
+ const d = await fetch(`${t}/api/messages`, {
681
+ method: "POST",
682
+ headers: { "Content-Type": "application/json", ...r },
683
+ body: JSON.stringify({
684
+ conversationId: s,
685
+ content: e.message,
686
+ clientNonce: ue,
687
+ ...e.attachments && e.attachments.length > 0 ? { attachments: e.attachments } : {}
688
+ })
689
+ }), S = await d.json();
690
+ if (!S.ok) {
691
+ h = !0, m.abort(), re(), e.onError(S.error || `Send failed: HTTP ${d.status}`), await O;
692
+ return;
651
693
  }
694
+ } catch (d) {
695
+ h = !0, m.abort(), re(), e.onError(d instanceof Error ? d.message : "Send failed"), await O;
696
+ return;
652
697
  }
698
+ await O;
653
699
  }
654
700
  };
655
- u(q, "ChatClient");
656
- let L = q;
657
- const K = class K {
701
+ u(Z, "ChatClient");
702
+ let q = Z;
703
+ const ee = class ee {
658
704
  constructor(e) {
659
705
  c(this, "ctx");
660
706
  this.ctx = e;
@@ -662,9 +708,7 @@ const K = class K {
662
708
  async getPublicAgent(e) {
663
709
  this.ctx.loading.value = !0, this.ctx.error.value = null;
664
710
  try {
665
- const r = await (await this.ctx.api.agents.public[":handle"].$get({
666
- param: { handle: e.handle }
667
- })).json();
711
+ const r = await (await this.ctx.apiFetch(`/api/agents/public/${encodeURIComponent(e.handle)}`)).json();
668
712
  if (!r.ok) {
669
713
  this.ctx.error.value = r.error, this.ctx.logger.error("Failed to fetch public agent", { handle: e.handle, error: r.error });
670
714
  return;
@@ -680,9 +724,7 @@ const K = class K {
680
724
  async getAgentByEmail(e) {
681
725
  this.ctx.loading.value = !0, this.ctx.error.value = null;
682
726
  try {
683
- const r = await (await this.ctx.api.agents["by-email"][":email"].$get({
684
- param: { email: e.email }
685
- })).json();
727
+ const r = await (await this.ctx.apiFetch(`/api/agents/by-email/${encodeURIComponent(e.email)}`)).json();
686
728
  if (!r.ok) {
687
729
  this.ctx.error.value = r.error, this.ctx.logger.error("Failed to fetch agent by email", { email: e.email, error: r.error });
688
730
  return;
@@ -698,7 +740,7 @@ const K = class K {
698
740
  generateAnonId() {
699
741
  const e = "pagelinesAnonId";
700
742
  let t = this.ctx.storage.getItem(e);
701
- return t || (t = O({ prefix: "anon" }), this.ctx.storage.setItem(e, t)), t;
743
+ return t || (t = C({ prefix: "anon" }), this.ctx.storage.setItem(e, t)), t;
702
744
  }
703
745
  track(e) {
704
746
  try {
@@ -713,9 +755,9 @@ const K = class K {
713
755
  }
714
756
  }
715
757
  };
716
- u(K, "UserClient");
717
- let N = K;
718
- const H = class H {
758
+ u(ee, "UserClient");
759
+ let M = ee;
760
+ const te = class te {
719
761
  constructor() {
720
762
  c(this, "key", "__PAGELINES_SDK__");
721
763
  }
@@ -730,33 +772,30 @@ const H = class H {
730
772
  typeof window < "u" && delete globalThis[this.key];
731
773
  }
732
774
  };
733
- u(H, "SDKGlobal");
734
- let C = H;
735
- const D = new C(), B = class B extends ne {
775
+ u(te, "SDKGlobal");
776
+ let K = te;
777
+ const j = new K(), L = class L extends Se {
736
778
  constructor(t = {}) {
737
- const r = D.get();
779
+ const r = j.get();
738
780
  if (r)
739
781
  return console.debug("[PageLinesSDK] Returning existing singleton instance"), r;
740
782
  super("PageLinesSDK", t);
741
783
  // Vue reactive state
742
- c(this, "activeUser", E());
743
- c(this, "token", E(null));
784
+ c(this, "activeUser", R());
785
+ c(this, "token", R(null));
744
786
  // Refresh credential lives in HttpOnly pl-refresh-token cookie — JS never
745
787
  // holds it, so no reactive ref. /api/auth/refresh reads the cookie via the
746
788
  // browser's automatic credentials: 'include' attach.
747
- c(this, "deviceId", E(null));
748
- c(this, "loading", E(!1));
749
- c(this, "error", E(null));
789
+ c(this, "deviceId", R(null));
790
+ c(this, "loading", R(!1));
791
+ c(this, "error", R(null));
750
792
  c(this, "apiBase", this.settings.apiBase || void 0);
751
793
  // Storage handler for persistence
752
- c(this, "storage", new P());
794
+ c(this, "storage", new J());
753
795
  // Auto-managed session ID for usage tracking
754
- c(this, "sessionId", O({ prefix: "ses" }));
755
- // Typed Hono RPC client - uses SDKAppType (auth/self/usage routes only)
756
- // Initialized in constructor (definite assignment via singleton pattern)
757
- c(this, "apiClient");
796
+ c(this, "sessionId", C({ prefix: "ses" }));
758
797
  // Computed properties derived from activeUser (matches UserClient pattern)
759
- c(this, "currentAgent", X(() => {
798
+ c(this, "currentAgent", oe(() => {
760
799
  const t = this.activeUser.value;
761
800
  if (!t?.agents)
762
801
  return;
@@ -764,7 +803,7 @@ const D = new C(), B = class B extends ne {
764
803
  if (r)
765
804
  return t.agents.find((s) => s.agentId === r);
766
805
  }));
767
- c(this, "currentOrg", X(() => {
806
+ c(this, "currentOrg", oe(() => {
768
807
  const t = this.currentAgent.value;
769
808
  if (!t?.orgId)
770
809
  return;
@@ -781,21 +820,21 @@ const D = new C(), B = class B extends ne {
781
820
  c(this, "billing");
782
821
  c(this, "chat");
783
822
  c(this, "user");
784
- D.set(this), this.apiClient = le(
785
- { isDev: this.isDev, apiBase: this.apiBase },
786
- this.processApiResponse.bind(this),
787
- {
788
- getDeviceId: /* @__PURE__ */ u(() => this.deviceId.value, "getDeviceId"),
789
- onAccessTokenRefreshed: /* @__PURE__ */ u((o) => {
790
- this.token.value = o, this.persistAuth();
791
- }, "onAccessTokenRefreshed"),
792
- onTerminalFailure: /* @__PURE__ */ u(() => {
793
- this.clearSession();
794
- }, "onTerminalFailure")
795
- }
796
- );
797
- const s = {
798
- api: this.api,
823
+ j.set(this);
824
+ const a = {
825
+ apiFetch: Ie(
826
+ { isDev: this.isDev, apiBase: this.apiBase },
827
+ this.processApiResponse.bind(this),
828
+ {
829
+ getDeviceId: /* @__PURE__ */ u(() => this.deviceId.value, "getDeviceId"),
830
+ onAccessTokenRefreshed: /* @__PURE__ */ u((i) => {
831
+ this.token.value = i, this.persistAuth();
832
+ }, "onAccessTokenRefreshed"),
833
+ onTerminalFailure: /* @__PURE__ */ u(() => {
834
+ this.clearSession();
835
+ }, "onTerminalFailure")
836
+ }
837
+ ),
799
838
  apiBase: this.apiBase,
800
839
  isDev: this.isDev,
801
840
  activeUser: this.activeUser,
@@ -808,12 +847,12 @@ const D = new C(), B = class B extends ne {
808
847
  logger: this.logger,
809
848
  processApiResponse: this.processApiResponse.bind(this)
810
849
  };
811
- this.agent = new _(s), this.auth = new F(s), this.billing = new j(s), this.chat = new L(s), this.user = new N(s), this.logger.info("PageLinesSDK initialized"), this.storage.loadFromStorage(this.authRefs()), this.storage.syncWithGlobalStores(this.authRefs()), this.initialized = new Promise((o) => {
812
- this.resolveUser = o;
813
- }), this.token.value && !this.activeUser.value ? this.auth.getCurrentUser().then((o) => {
814
- this.resolveUser && (this.resolveUser(o), this.resolveUser = void 0);
815
- }).catch((o) => {
816
- this.logger.error("Auto user fetch failed", { data: o }), this.resolveUser && (this.resolveUser(void 0), this.resolveUser = void 0);
850
+ this.agent = new G(a), this.auth = new z(a), this.billing = new W(a), this.chat = new q(a), this.user = new M(a), this.logger.info("PageLinesSDK initialized"), this.storage.loadFromStorage(this.authRefs()), this.storage.syncWithGlobalStores(this.authRefs()), this.initialized = new Promise((i) => {
851
+ this.resolveUser = i;
852
+ }), this.token.value && !this.activeUser.value ? this.auth.getCurrentUser().then((i) => {
853
+ this.resolveUser && (this.resolveUser(i), this.resolveUser = void 0);
854
+ }).catch((i) => {
855
+ this.logger.error("Auto user fetch failed", { data: i }), this.resolveUser && (this.resolveUser(void 0), this.resolveUser = void 0);
817
856
  }) : this.activeUser.value ? this.resolveUser?.(this.activeUser.value) : this.resolveUser?.(void 0);
818
857
  }
819
858
  /**
@@ -822,17 +861,11 @@ const D = new C(), B = class B extends ne {
822
861
  * Recommended: Use this instead of constructor for shared state
823
862
  */
824
863
  static getInstance(t = {}) {
825
- return D.get() || new B(t);
864
+ return j.get() || new L(t);
826
865
  }
827
866
  get isDev() {
828
867
  return this.settings.isDev ?? (typeof window < "u" ? window.location.hostname === "localhost" || window.location.hostname.includes("127.0.0.1") : !1);
829
868
  }
830
- // The stub `Hono<any, any, any>` makes `hc<SDKAppType>` resolve to `any`
831
- // for prod-build speed; in dev the alias points at the real SDKAppType
832
- // and we get full route typing. Either way `.api` is a valid access.
833
- get api() {
834
- return this.apiClient.api;
835
- }
836
869
  // Process ApiResponse for automatic user/token updates - public for dependency injection
837
870
  processApiResponse(t) {
838
871
  if (!t.ok) return;
@@ -857,18 +890,18 @@ const D = new C(), B = class B extends ne {
857
890
  }
858
891
  // Full reset - clears session + state + destroys singleton
859
892
  clear() {
860
- this.logger.info("Clearing SDK completely"), this.clearSession(), this.loading.value = !1, this.sessionId = O({ prefix: "ses" }), D.delete();
893
+ this.logger.info("Clearing SDK completely"), this.clearSession(), this.loading.value = !1, this.sessionId = C({ prefix: "ses" }), j.delete();
861
894
  }
862
895
  };
863
- u(B, "PageLinesSDK");
864
- let ee = B;
896
+ u(L, "PageLinesSDK");
897
+ let ce = L;
865
898
  export {
866
- _ as A,
867
- j as B,
868
- L as C,
869
- ee as P,
870
- N as U,
871
- F as a,
872
- y as r
899
+ G as A,
900
+ W as B,
901
+ q as C,
902
+ ce as P,
903
+ M as U,
904
+ z as a,
905
+ I as r
873
906
  };
874
907
  //# sourceMappingURL=sdkClient.js.map