@pagelines/sdk 1.0.428 → 1.0.430

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,64 +1,64 @@
1
- var W = Object.defineProperty;
2
- var Q = (a, e, t) => e in a ? W(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
3
- var u = (a, e) => W(a, "name", { value: e, configurable: !0 });
4
- var i = (a, e, t) => Q(a, typeof e != "symbol" ? e + "" : e, t);
5
- import { APP_PORT as V, APP_PROD_URL as X, cookieUtil as x, createLogger as Y, objectId as $, SettingsObject as Z } from "@pagelines/core";
6
- import { watch as q, ref as k, computed as z } from "vue";
7
- import { hc as ee } from "hono/client";
8
- function p(a, e) {
9
- return a || (e ? `http://localhost:${V}` : X);
1
+ var q = Object.defineProperty;
2
+ var X = (n, e, t) => e in n ? q(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
+ var l = (n, e) => q(n, "name", { value: e, configurable: !0 });
4
+ var a = (n, e, t) => X(n, typeof e != "symbol" ? e + "" : e, t);
5
+ import { APP_PORT as Y, APP_PROD_URL as Z, cookieUtil as x, createLogger as ee, objectId as $, SettingsObject as te } from "@pagelines/core";
6
+ import { watch as J, ref as k, computed as K } from "vue";
7
+ import { hc as re } from "hono/client";
8
+ function g(n, e) {
9
+ return n || (e ? `http://localhost:${Y}` : Z);
10
10
  }
11
- u(p, "resolveApiBase");
12
- function te(a, e) {
13
- const t = p(a.apiBase, a.isDev);
14
- return ee(t, {
15
- fetch: /* @__PURE__ */ u(async (s, o) => {
16
- const n = x.getAuthToken(), l = await fetch(s, {
17
- ...o,
11
+ l(g, "resolveApiBase");
12
+ function oe(n, e) {
13
+ const t = g(n.apiBase, n.isDev);
14
+ return re(t, {
15
+ fetch: /* @__PURE__ */ l(async (o, s) => {
16
+ const i = x.getAuthToken(), h = await fetch(o, {
17
+ ...s,
18
18
  headers: {
19
- ...o?.headers,
19
+ ...s?.headers,
20
20
  "Content-Type": "application/json",
21
21
  // Only include Authorization header if token exists
22
- ...n && { Authorization: `Bearer ${n}` }
22
+ ...i && { Authorization: `Bearer ${i}` }
23
23
  },
24
24
  // Use 'omit' for Bearer tokens (not cookies) to allow CORS wildcard origin
25
25
  credentials: "omit"
26
26
  });
27
27
  if (e) {
28
- const g = l.json.bind(l);
29
- l.json = async () => {
30
- const c = await g();
28
+ const p = h.json.bind(h);
29
+ h.json = async () => {
30
+ const c = await p();
31
31
  return typeof c == "object" && c !== null && "ok" in c && ("user" in c || "token" in c) && e(c), c;
32
32
  };
33
33
  }
34
- return l;
34
+ return h;
35
35
  }, "fetch")
36
36
  });
37
37
  }
38
- u(te, "createApiClient");
39
- let re = /* @__PURE__ */ Symbol("clean"), d = [], f = 0;
40
- const b = 4, K = /* @__PURE__ */ u(/* @__NO_SIDE_EFFECTS__ */ (a) => {
38
+ l(oe, "createApiClient");
39
+ let se = /* @__PURE__ */ Symbol("clean"), d = [], f = 0;
40
+ const A = 4, V = /* @__PURE__ */ l(/* @__NO_SIDE_EFFECTS__ */ (n) => {
41
41
  let e = [], t = {
42
42
  get() {
43
43
  return t.lc || t.listen(() => {
44
44
  })(), t.value;
45
45
  },
46
- init: a,
46
+ init: n,
47
47
  lc: 0,
48
48
  listen(r) {
49
49
  return t.lc = e.push(r), () => {
50
- for (let o = f + b; o < d.length; )
51
- d[o] === r ? d.splice(o, b) : o += b;
52
- let s = e.indexOf(r);
53
- ~s && (e.splice(s, 1), --t.lc || t.off());
50
+ for (let s = f + A; s < d.length; )
51
+ d[s] === r ? d.splice(s, A) : s += A;
52
+ let o = e.indexOf(r);
53
+ ~o && (e.splice(o, 1), --t.lc || t.off());
54
54
  };
55
55
  },
56
- notify(r, s) {
57
- let o = !d.length;
58
- for (let n of e)
59
- d.push(n, t.value, r, s);
60
- if (o) {
61
- for (f = 0; f < d.length; f += b)
56
+ notify(r, o) {
57
+ let s = !d.length;
58
+ for (let i of e)
59
+ d.push(i, t.value, r, o);
60
+ if (s) {
61
+ for (f = 0; f < d.length; f += A)
62
62
  d[f](
63
63
  d[f + 1],
64
64
  d[f + 2],
@@ -72,21 +72,21 @@ const b = 4, K = /* @__PURE__ */ u(/* @__NO_SIDE_EFFECTS__ */ (a) => {
72
72
  off() {
73
73
  },
74
74
  set(r) {
75
- let s = t.value;
76
- s !== r && (t.value = r, t.notify(s));
75
+ let o = t.value;
76
+ o !== r && (t.value = r, t.notify(o));
77
77
  },
78
78
  subscribe(r) {
79
- let s = t.listen(r);
80
- return r(t.value), s;
79
+ let o = t.listen(r);
80
+ return r(t.value), o;
81
81
  },
82
- value: a
82
+ value: n
83
83
  };
84
- return process.env.NODE_ENV !== "production" && (t[re] = () => {
84
+ return process.env.NODE_ENV !== "production" && (t[se] = () => {
85
85
  e = [], t.lc = 0, t.off();
86
86
  }), t;
87
- }, "atom"), y = globalThis, A = y.__PL_AUTH_USER__ ?? (y.__PL_AUTH_USER__ = /* @__PURE__ */ K(void 0)), U = y.__PL_AUTH_TOKEN__ ?? (y.__PL_AUTH_TOKEN__ = /* @__PURE__ */ K(null)), F = class F {
87
+ }, "atom"), y = globalThis, b = y.__PL_AUTH_USER__ ?? (y.__PL_AUTH_USER__ = /* @__PURE__ */ V(void 0)), U = y.__PL_AUTH_TOKEN__ ?? (y.__PL_AUTH_TOKEN__ = /* @__PURE__ */ V(null)), F = class F {
88
88
  constructor() {
89
- i(this, "logger", Y("SDKStorage"));
89
+ a(this, "logger", ee("SDKStorage"));
90
90
  }
91
91
  /**
92
92
  * Check if localStorage is fully functional (some test environments provide partial mocks)
@@ -98,15 +98,15 @@ const b = 4, K = /* @__PURE__ */ u(/* @__NO_SIDE_EFFECTS__ */ (a) => {
98
98
  * Sync Vue reactive refs with global nanostores for cross-page persistence
99
99
  */
100
100
  syncWithGlobalStores(e, t) {
101
- const r = A.get(), s = U.get();
102
- r && (e.value = r), s && (t.value = s), q(e, (o) => {
103
- A.set(o);
104
- }, { immediate: !0 }), q(t, (o) => {
105
- U.set(o);
106
- }, { immediate: !0 }), A.subscribe((o) => {
107
- o !== e.value && (e.value = o);
108
- }), U.subscribe((o) => {
109
- o !== t.value && (t.value = o);
101
+ const r = b.get(), o = U.get();
102
+ r && (e.value = r), o && (t.value = o), J(e, (s) => {
103
+ b.set(s);
104
+ }, { immediate: !0 }), J(t, (s) => {
105
+ U.set(s);
106
+ }, { immediate: !0 }), b.subscribe((s) => {
107
+ s !== e.value && (e.value = s);
108
+ }), U.subscribe((s) => {
109
+ s !== t.value && (t.value = s);
110
110
  });
111
111
  }
112
112
  /**
@@ -118,10 +118,10 @@ const b = 4, K = /* @__PURE__ */ u(/* @__NO_SIDE_EFFECTS__ */ (a) => {
118
118
  const r = x.getAuthToken();
119
119
  if (r && (t.value = r), this.isLocalStorageFunctional())
120
120
  try {
121
- const s = localStorage.getItem("pagelines-user");
122
- s && (e.value = JSON.parse(s));
123
- } catch (s) {
124
- this.logger.error("Failed to load user from localStorage", { data: s });
121
+ const o = localStorage.getItem("pagelines-user");
122
+ o && (e.value = JSON.parse(o));
123
+ } catch (o) {
124
+ this.logger.error("Failed to load user from localStorage", { data: o });
125
125
  }
126
126
  }
127
127
  /**
@@ -146,7 +146,7 @@ const b = 4, K = /* @__PURE__ */ u(/* @__NO_SIDE_EFFECTS__ */ (a) => {
146
146
  } catch (e) {
147
147
  this.logger.error("Failed to clear user from localStorage", { data: e });
148
148
  }
149
- A.set(void 0), U.set(null);
149
+ b.set(void 0), U.set(null);
150
150
  }
151
151
  }
152
152
  /**
@@ -173,20 +173,20 @@ const b = 4, K = /* @__PURE__ */ u(/* @__NO_SIDE_EFFECTS__ */ (a) => {
173
173
  }
174
174
  }
175
175
  };
176
- u(F, "SDKStorage");
176
+ l(F, "SDKStorage");
177
177
  let B = F;
178
- const J = [
178
+ const H = [
179
179
  "Deploying your server...",
180
180
  "Setting up your workspace...",
181
181
  "Installing tools...",
182
182
  "Almost ready..."
183
- ], O = class O {
183
+ ], L = class L {
184
184
  constructor(e) {
185
- i(this, "ctx");
185
+ a(this, "ctx");
186
186
  this.ctx = e;
187
187
  }
188
188
  async create(e) {
189
- const t = e.orgId || this.resolveOrgId(), r = p(this.ctx.apiBase, this.ctx.isDev), o = await (await fetch(`${r}/api/agent`, {
189
+ const t = e.orgId || this.resolveOrgId(), r = g(this.ctx.apiBase, this.ctx.isDev), s = await (await fetch(`${r}/api/agent`, {
190
190
  method: "POST",
191
191
  headers: {
192
192
  "Content-Type": "application/json",
@@ -194,49 +194,49 @@ const J = [
194
194
  },
195
195
  body: JSON.stringify({ name: e.name, orgId: t })
196
196
  })).json();
197
- if (!o.ok || !o.data?.[0]) {
198
- const n = o.error || "Failed to create agent";
199
- throw this.ctx.error.value = n, new Error(n);
197
+ if (!s.ok || !s.data?.[0]) {
198
+ const i = s.error || "Failed to create agent";
199
+ throw this.ctx.error.value = i, new Error(i);
200
200
  }
201
- return this.ctx.processApiResponse(o), o.data[0];
201
+ return this.ctx.processApiResponse(s), s.data[0];
202
202
  }
203
203
  async getStatus(e) {
204
- const t = p(this.ctx.apiBase, this.ctx.isDev), s = await (await fetch(`${t}/api/agent/${e.agentId}/status`, {
204
+ const t = g(this.ctx.apiBase, this.ctx.isDev), o = await (await fetch(`${t}/api/agent/${e.agentId}/status`, {
205
205
  headers: {
206
206
  ...this.ctx.token.value && { Authorization: `Bearer ${this.ctx.token.value}` }
207
207
  }
208
208
  })).json();
209
- return !s.ok || !s.data ? { status: "unknown", ready: !1, error: "Failed to check status" } : s.data;
209
+ return !o.ok || !o.data ? { status: "unknown", ready: !1, error: "Failed to check status" } : o.data;
210
210
  }
211
211
  async waitUntilReady(e) {
212
- const { agentId: t, onStatus: r, timeoutMs: s = 3e5, pollIntervalMs: o = 3e3 } = e, n = Date.now();
213
- let l = 0;
214
- for (; Date.now() - n < s; ) {
215
- const g = await this.getStatus({ agentId: t });
216
- if (g.ready) {
212
+ const { agentId: t, onStatus: r, timeoutMs: o = 3e5, pollIntervalMs: s = 3e3 } = e, i = Date.now();
213
+ let h = 0;
214
+ for (; Date.now() - i < o; ) {
215
+ const p = await this.getStatus({ agentId: t });
216
+ if (p.ready) {
217
217
  r?.("Ready!");
218
218
  return;
219
219
  }
220
- if (g.status === "error")
221
- throw new Error(g.error || "Provisioning failed");
222
- r && l < J.length && (r(J[l]), l++), await new Promise((c) => setTimeout(c, o));
220
+ if (p.status === "error")
221
+ throw new Error(p.error || "Provisioning failed");
222
+ r && h < H.length && (r(H[h]), h++), await new Promise((c) => setTimeout(c, s));
223
223
  }
224
224
  throw new Error("Agent provisioning timed out — please try again");
225
225
  }
226
226
  /** Send a typed webhook event to a bot agent. No auth required — the proxy is public. */
227
227
  async webhook(e) {
228
- const r = `${p(this.ctx.apiBase, this.ctx.isDev)}/api/bot-api/agents/${e.agentId}/webhook`, s = { type: e.type, data: e.data };
229
- e.meta && (s.meta = e.meta);
230
- const o = await fetch(r, {
228
+ const r = `${g(this.ctx.apiBase, this.ctx.isDev)}/api/bot-api/agents/${e.agentId}/webhook`, o = { type: e.type, data: e.data };
229
+ e.meta && (o.meta = e.meta);
230
+ const s = await fetch(r, {
231
231
  method: "POST",
232
232
  headers: { "Content-Type": "application/json" },
233
- body: JSON.stringify(s)
233
+ body: JSON.stringify(o)
234
234
  });
235
- if (!o.ok) {
236
- const n = await o.text().catch(() => "Unknown error");
237
- throw new Error(`Webhook delivery failed (${o.status}): ${n.slice(0, 200)}`);
235
+ if (!s.ok) {
236
+ const i = await s.text().catch(() => "Unknown error");
237
+ throw new Error(`Webhook delivery failed (${s.status}): ${i.slice(0, 200)}`);
238
238
  }
239
- return o.json();
239
+ return s.json();
240
240
  }
241
241
  resolveOrgId() {
242
242
  const t = this.ctx.activeUser.value?.orgs?.[0]?.orgId;
@@ -245,20 +245,20 @@ const J = [
245
245
  return t;
246
246
  }
247
247
  };
248
- u(O, "AgentClient");
249
- let D = O;
250
- async function m(a, e) {
251
- a.loading.value = !0, a.error.value = null;
248
+ l(L, "AgentClient");
249
+ let D = L;
250
+ async function m(n, e) {
251
+ n.loading.value = !0, n.error.value = null;
252
252
  try {
253
253
  return await e();
254
254
  } finally {
255
- a.loading.value = !1;
255
+ n.loading.value = !1;
256
256
  }
257
257
  }
258
- u(m, "withLoadingState");
259
- const R = class R {
258
+ l(m, "withLoadingState");
259
+ const _ = class _ {
260
260
  constructor(e) {
261
- i(this, "ctx");
261
+ a(this, "ctx");
262
262
  this.ctx = e;
263
263
  }
264
264
  async sendCode(e) {
@@ -279,15 +279,15 @@ const R = class R {
279
279
  async verifyCode(e, t) {
280
280
  return m(this.ctx, async () => {
281
281
  try {
282
- const s = await (await this.ctx.api.auth["verify-code"].$post({
282
+ const o = await (await this.ctx.api.auth["verify-code"].$post({
283
283
  json: { email: e, code: t }
284
284
  })).json();
285
- if (!s.ok)
286
- throw this.ctx.error.value = s.error, new Error(s.error);
285
+ if (!o.ok)
286
+ throw this.ctx.error.value = o.error, new Error(o.error);
287
287
  } catch (r) {
288
288
  this.ctx.logger.error("Verify code error", { data: r });
289
- const s = r instanceof Error ? r.message : "Failed to verify code";
290
- throw this.ctx.error.value = s, r;
289
+ const o = r instanceof Error ? r.message : "Failed to verify code";
290
+ throw this.ctx.error.value = o, r;
291
291
  }
292
292
  });
293
293
  }
@@ -346,26 +346,26 @@ const R = class R {
346
346
  this.ctx.logger.error("loginWithGoogle: Only available in browser");
347
347
  return;
348
348
  }
349
- const t = p(this.ctx.apiBase, this.ctx.isDev), r = window.location.origin, s = `${t}/auth/google-popup?origin=${encodeURIComponent(r)}`, o = 500, n = 600, l = window.screenX + (window.outerWidth - o) / 2, g = window.screenY + (window.outerHeight - n) / 2, c = window.open(
350
- s,
349
+ const t = g(this.ctx.apiBase, this.ctx.isDev), r = window.location.origin, o = `${t}/auth/google-popup?origin=${encodeURIComponent(r)}`, s = 500, i = 600, h = window.screenX + (window.outerWidth - s) / 2, p = window.screenY + (window.outerHeight - i) / 2, c = window.open(
350
+ o,
351
351
  "google-auth",
352
- `width=${o},height=${n},left=${l},top=${g},popup=yes`
352
+ `width=${s},height=${i},left=${h},top=${p},popup=yes`
353
353
  );
354
354
  if (!c) {
355
- const h = "Popup was blocked. Please allow popups for this site.";
356
- this.ctx.error.value = h, e?.onError?.(h);
355
+ const u = "Popup was blocked. Please allow popups for this site.";
356
+ this.ctx.error.value = u, e?.onError?.(u);
357
357
  return;
358
358
  }
359
- const v = /* @__PURE__ */ u((h) => {
359
+ const v = /* @__PURE__ */ l((u) => {
360
360
  const S = new URL(t).origin;
361
- if (h.origin === S) {
362
- if (h.data?.type === "auth-success") {
361
+ if (u.origin === S) {
362
+ if (u.data?.type === "auth-success") {
363
363
  window.removeEventListener("message", v);
364
- const { token: w, user: M } = h.data;
365
- this.ctx.processApiResponse({ ok: !0, data: {}, token: w, user: M }), this.ctx.logger.info("Google login successful"), e?.onSuccess?.(M);
366
- } else if (h.data?.type === "auth-error") {
364
+ const { token: w, user: z } = u.data;
365
+ this.ctx.processApiResponse({ ok: !0, data: {}, token: w, user: z }), this.ctx.logger.info("Google login successful"), e?.onSuccess?.(z);
366
+ } else if (u.data?.type === "auth-error") {
367
367
  window.removeEventListener("message", v);
368
- const w = h.data.error || "Google authentication failed";
368
+ const w = u.data.error || "Google authentication failed";
369
369
  this.ctx.error.value = w, this.ctx.logger.error("Google login failed", { error: w }), e?.onError?.(w);
370
370
  }
371
371
  }
@@ -376,15 +376,74 @@ const R = class R {
376
376
  }, 500);
377
377
  }
378
378
  };
379
- u(R, "AuthClient");
380
- let C = R;
381
- const _ = class _ {
379
+ l(_, "AuthClient");
380
+ let j = _;
381
+ const N = class N {
382
382
  constructor(e) {
383
- i(this, "ctx");
383
+ a(this, "ctx");
384
+ this.ctx = e;
385
+ }
386
+ async startTrial(e) {
387
+ const t = this.resolveOrgId(), r = g(this.ctx.apiBase, this.ctx.isDev), s = await (await fetch(`${r}/api/billing/checkout/create`, {
388
+ method: "POST",
389
+ headers: {
390
+ "Content-Type": "application/json",
391
+ ...this.ctx.token.value && { Authorization: `Bearer ${this.ctx.token.value}` }
392
+ },
393
+ body: JSON.stringify({
394
+ orgId: t,
395
+ ...e?.returnUrl && { returnUrl: e.returnUrl },
396
+ ...e?.planKey && { planKey: e.planKey }
397
+ })
398
+ })).json();
399
+ if (!s.ok || !s.data?.url) {
400
+ const i = s.error || "Failed to create checkout session";
401
+ throw this.ctx.error.value = i, new Error(i);
402
+ }
403
+ window.location.href = s.data.url;
404
+ }
405
+ async confirmCheckout(e) {
406
+ return this.getStatus();
407
+ }
408
+ async getStatus() {
409
+ const e = this.resolveOrgId(), t = g(this.ctx.apiBase, this.ctx.isDev), o = await (await fetch(`${t}/api/billing/details/${e}`, {
410
+ headers: {
411
+ ...this.ctx.token.value && { Authorization: `Bearer ${this.ctx.token.value}` }
412
+ }
413
+ })).json();
414
+ if (!o.ok || !o.data)
415
+ return {
416
+ plan: void 0,
417
+ status: "none",
418
+ hasActiveBilling: !1,
419
+ maxAgents: 0
420
+ };
421
+ const s = ["active", "trialing"];
422
+ return {
423
+ plan: o.data.plan,
424
+ status: o.data.status,
425
+ hasActiveBilling: s.includes(o.data.status),
426
+ maxAgents: o.data.maxAgents,
427
+ ...o.data.trialEnd && { trialEnd: o.data.trialEnd },
428
+ ...o.data.trialDaysRemaining !== void 0 && { trialDaysRemaining: o.data.trialDaysRemaining }
429
+ };
430
+ }
431
+ resolveOrgId() {
432
+ const t = this.ctx.activeUser.value?.orgs?.[0]?.orgId;
433
+ if (!t)
434
+ throw new Error("No organization found. Please sign in first.");
435
+ return t;
436
+ }
437
+ };
438
+ l(N, "BillingClient");
439
+ let P = N;
440
+ const G = class G {
441
+ constructor(e) {
442
+ a(this, "ctx");
384
443
  this.ctx = e;
385
444
  }
386
445
  async chatStream(e) {
387
- const r = `${p(this.ctx.apiBase, this.ctx.isDev)}/api/agent/public/${encodeURIComponent(e.handle)}/chat/stream`;
446
+ const r = `${g(this.ctx.apiBase, this.ctx.isDev)}/api/agent/public/${encodeURIComponent(e.handle)}/chat/stream`;
388
447
  return this._streamChat({
389
448
  url: r,
390
449
  headers: { "Content-Type": "application/json" },
@@ -404,7 +463,7 @@ const _ = class _ {
404
463
  });
405
464
  }
406
465
  async chatStreamAuthenticated(e) {
407
- const r = `${p(this.ctx.apiBase, this.ctx.isDev)}/api/agent/${encodeURIComponent(e.agentId)}/chat/stream`;
466
+ const r = `${g(this.ctx.apiBase, this.ctx.isDev)}/api/agent/${encodeURIComponent(e.agentId)}/chat/stream`;
408
467
  return this._streamChat({
409
468
  url: r,
410
469
  headers: {
@@ -433,8 +492,8 @@ const _ = class _ {
433
492
  body: JSON.stringify(e.body)
434
493
  });
435
494
  if (!t.ok) {
436
- const l = await t.json().catch(() => ({ error: "Request failed" }));
437
- e.onError(l.error || `HTTP ${t.status}`);
495
+ const h = await t.json().catch(() => ({ error: "Request failed" }));
496
+ e.onError(h.error || `HTTP ${t.status}`);
438
497
  return;
439
498
  }
440
499
  const r = t.body?.getReader();
@@ -442,46 +501,46 @@ const _ = class _ {
442
501
  e.onError("No response stream");
443
502
  return;
444
503
  }
445
- const s = new TextDecoder();
446
- let o = "", n = e.conversationId || "";
504
+ const o = new TextDecoder();
505
+ let s = "", i = e.conversationId || "";
447
506
  for (; ; ) {
448
- const { done: l, value: g } = await r.read();
449
- if (l)
507
+ const { done: h, value: p } = await r.read();
508
+ if (h)
450
509
  break;
451
- o += s.decode(g, { stream: !0 });
452
- const c = o.split(`
510
+ s += o.decode(p, { stream: !0 });
511
+ const c = s.split(`
453
512
  `);
454
- o = c.pop() || "";
513
+ s = c.pop() || "";
455
514
  for (const v of c) {
456
515
  if (!v.startsWith("data: "))
457
516
  continue;
458
517
  const I = v.slice(6).trim();
459
518
  if (I === "[DONE]") {
460
- e.onDone(n);
519
+ e.onDone(i);
461
520
  return;
462
521
  }
463
522
  try {
464
- const h = JSON.parse(I);
465
- if (h.pl_status) {
466
- e.onStatus?.(h.pl_status);
523
+ const u = JSON.parse(I);
524
+ if (u.pl_status) {
525
+ e.onStatus?.(u.pl_status);
467
526
  continue;
468
527
  }
469
- h.pl_metadata?.conversationId && (n = h.pl_metadata.conversationId);
470
- const S = h.choices?.[0]?.delta;
528
+ u.pl_metadata?.conversationId && (i = u.pl_metadata.conversationId);
529
+ const S = u.choices?.[0]?.delta;
471
530
  S?.content && e.onDelta(S.content);
472
531
  } catch {
473
532
  }
474
533
  }
475
534
  }
476
- e.onDone(n);
535
+ e.onDone(i);
477
536
  } catch (t) {
478
537
  e.onError(t instanceof Error ? t.message : "Stream failed");
479
538
  }
480
539
  }
481
540
  async chatMessage(e) {
482
- const r = `${p(this.ctx.apiBase, this.ctx.isDev)}/api/agent/public/${encodeURIComponent(e.handle)}/chat`;
541
+ const r = `${g(this.ctx.apiBase, this.ctx.isDev)}/api/agent/public/${encodeURIComponent(e.handle)}/chat`;
483
542
  try {
484
- const o = await (await fetch(r, {
543
+ const s = await (await fetch(r, {
485
544
  method: "POST",
486
545
  headers: { "Content-Type": "application/json" },
487
546
  body: JSON.stringify({
@@ -491,25 +550,25 @@ const _ = class _ {
491
550
  context: e.context
492
551
  })
493
552
  })).json();
494
- if (!o.ok || !o.data) {
495
- this.ctx.logger.error("chatMessage failed", { error: !o.ok && "error" in o ? o.error : "Unknown" });
553
+ if (!s.ok || !s.data) {
554
+ this.ctx.logger.error("chatMessage failed", { error: !s.ok && "error" in s ? s.error : "Unknown" });
496
555
  return;
497
556
  }
498
557
  return {
499
- conversationId: o.data.conversationId,
500
- content: o.data.message.content
558
+ conversationId: s.data.conversationId,
559
+ content: s.data.message.content
501
560
  };
502
- } catch (s) {
503
- this.ctx.logger.error("chatMessage error", { error: s });
561
+ } catch (o) {
562
+ this.ctx.logger.error("chatMessage error", { error: o });
504
563
  return;
505
564
  }
506
565
  }
507
566
  };
508
- u(_, "ChatClient");
509
- let P = _;
510
- const N = class N {
567
+ l(G, "ChatClient");
568
+ let C = G;
569
+ const M = class M {
511
570
  constructor(e) {
512
- i(this, "ctx");
571
+ a(this, "ctx");
513
572
  this.ctx = e;
514
573
  }
515
574
  async getPublicAgent(e) {
@@ -566,11 +625,11 @@ const N = class N {
566
625
  }
567
626
  }
568
627
  };
569
- u(N, "UserClient");
570
- let j = N;
571
- const G = class G {
628
+ l(M, "UserClient");
629
+ let O = M;
630
+ const W = class W {
572
631
  constructor() {
573
- i(this, "key", "__PAGELINES_SDK__");
632
+ a(this, "key", "__PAGELINES_SDK__");
574
633
  }
575
634
  get() {
576
635
  if (!(typeof window > "u"))
@@ -583,57 +642,58 @@ const G = class G {
583
642
  typeof window < "u" && delete globalThis[this.key];
584
643
  }
585
644
  };
586
- u(G, "SDKGlobal");
587
- let L = G;
588
- const E = new L(), T = class T extends Z {
645
+ l(W, "SDKGlobal");
646
+ let R = W;
647
+ const E = new R(), T = class T extends te {
589
648
  constructor(t = {}) {
590
649
  const r = E.get();
591
650
  if (r)
592
651
  return console.debug("[PageLinesSDK] Returning existing singleton instance"), r;
593
652
  super("PageLinesSDK", t);
594
653
  // Vue reactive state
595
- i(this, "activeUser", k());
596
- i(this, "token", k(null));
597
- i(this, "loading", k(!1));
598
- i(this, "error", k(null));
599
- i(this, "apiBase", this.settings.apiBase || void 0);
654
+ a(this, "activeUser", k());
655
+ a(this, "token", k(null));
656
+ a(this, "loading", k(!1));
657
+ a(this, "error", k(null));
658
+ a(this, "apiBase", this.settings.apiBase || void 0);
600
659
  // Storage handler for persistence
601
- i(this, "storage", new B());
660
+ a(this, "storage", new B());
602
661
  // Auto-managed session ID for usage tracking
603
- i(this, "sessionId", $({ prefix: "ses" }));
662
+ a(this, "sessionId", $({ prefix: "ses" }));
604
663
  // Typed Hono RPC client - uses SDKAppType (auth/self/usage routes only)
605
664
  // Initialized in constructor (definite assignment via singleton pattern)
606
- i(this, "apiClient");
665
+ a(this, "apiClient");
607
666
  // Computed properties derived from activeUser (matches UserClient pattern)
608
- i(this, "currentAgent", z(() => {
667
+ a(this, "currentAgent", K(() => {
609
668
  const t = this.activeUser.value;
610
669
  if (!t?.agents)
611
670
  return;
612
671
  const r = t.primaryAgentId || t.agents[0]?.agentId;
613
672
  if (r)
614
- return t.agents.find((s) => s.agentId === r);
673
+ return t.agents.find((o) => o.agentId === r);
615
674
  }));
616
- i(this, "currentOrg", z(() => {
675
+ a(this, "currentOrg", K(() => {
617
676
  const t = this.currentAgent.value;
618
677
  if (!t?.orgId)
619
678
  return;
620
679
  const r = this.activeUser.value;
621
680
  if (r?.orgs)
622
- return r.orgs.find((s) => s.orgId === t.orgId);
681
+ return r.orgs.find((o) => o.orgId === t.orgId);
623
682
  }));
624
683
  // Initialization state
625
- i(this, "initialized");
626
- i(this, "resolveUser");
684
+ a(this, "initialized");
685
+ a(this, "resolveUser");
627
686
  // Sub-clients (new preferred API surface)
628
- i(this, "agent");
629
- i(this, "auth");
630
- i(this, "chat");
631
- i(this, "user");
632
- E.set(this), this.apiClient = te(
687
+ a(this, "agent");
688
+ a(this, "auth");
689
+ a(this, "billing");
690
+ a(this, "chat");
691
+ a(this, "user");
692
+ E.set(this), this.apiClient = oe(
633
693
  { isDev: this.isDev, apiBase: this.apiBase },
634
694
  this.processApiResponse.bind(this)
635
695
  );
636
- const s = {
696
+ const o = {
637
697
  api: this.api,
638
698
  apiBase: this.apiBase,
639
699
  isDev: this.isDev,
@@ -647,12 +707,12 @@ const E = new L(), T = class T extends Z {
647
707
  logger: this.logger,
648
708
  processApiResponse: this.processApiResponse.bind(this)
649
709
  };
650
- this.agent = new D(s), this.auth = new C(s), this.chat = new P(s), this.user = new j(s), this.logger.info("PageLinesSDK initialized"), this.storage.loadFromStorage(this.activeUser, this.token), this.storage.syncWithGlobalStores(this.activeUser, this.token), this.initialized = new Promise((o) => {
651
- this.resolveUser = o;
652
- }), this.token.value && !this.activeUser.value ? this.getCurrentUser().then((o) => {
653
- this.resolveUser && (this.resolveUser(o), this.resolveUser = void 0);
654
- }).catch((o) => {
655
- this.logger.error("Auto user fetch failed", { data: o }), this.resolveUser && (this.resolveUser(void 0), this.resolveUser = void 0);
710
+ this.agent = new D(o), this.auth = new j(o), this.billing = new P(o), this.chat = new C(o), this.user = new O(o), this.logger.info("PageLinesSDK initialized"), this.storage.loadFromStorage(this.activeUser, this.token), this.storage.syncWithGlobalStores(this.activeUser, this.token), this.initialized = new Promise((s) => {
711
+ this.resolveUser = s;
712
+ }), this.token.value && !this.activeUser.value ? this.getCurrentUser().then((s) => {
713
+ this.resolveUser && (this.resolveUser(s), this.resolveUser = void 0);
714
+ }).catch((s) => {
715
+ this.logger.error("Auto user fetch failed", { data: s }), this.resolveUser && (this.resolveUser(void 0), this.resolveUser = void 0);
656
716
  }) : this.activeUser.value ? this.resolveUser?.(this.activeUser.value) : this.resolveUser?.(void 0);
657
717
  }
658
718
  /**
@@ -728,14 +788,14 @@ const E = new L(), T = class T extends Z {
728
788
  return this.user.track(t);
729
789
  }
730
790
  };
731
- u(T, "PageLinesSDK");
732
- let H = T;
791
+ l(T, "PageLinesSDK");
792
+ let Q = T;
733
793
  export {
734
794
  D as A,
735
- P as C,
736
- H as P,
737
- j as U,
738
- C as a,
739
- p as r
795
+ C,
796
+ Q as P,
797
+ O as U,
798
+ j as a,
799
+ g as r
740
800
  };
741
801
  //# sourceMappingURL=sdkClient.js.map