@pagelines/sdk 1.0.385 → 1.0.387

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/{AgentProvider.vue_vue_type_script_setup_true_lang-5V_TRBPP.js → AgentProvider.vue_vue_type_script_setup_true_lang.js} +889 -1027
  2. package/dist/AgentProvider.vue_vue_type_script_setup_true_lang.js.map +1 -0
  3. package/dist/{AgentWidgetInline-DOoug3lh.js → AgentWidgetInline.js} +3 -3
  4. package/dist/AgentWidgetInline.js.map +1 -0
  5. package/dist/{AgentWidgetModal-C-dDlu8w.js → AgentWidgetModal.js} +4 -4
  6. package/dist/AgentWidgetModal.js.map +1 -0
  7. package/dist/AgentWidgetOnboard.js +5 -0
  8. package/dist/AgentWidgetOnboard.js.map +1 -0
  9. package/dist/{AgentWrap.vue_vue_type_script_setup_true_lang-CHgCPDEe.js → AgentWrap.vue_vue_type_script_setup_true_lang.js} +878 -737
  10. package/dist/AgentWrap.vue_vue_type_script_setup_true_lang.js.map +1 -0
  11. package/dist/{FModal.vue_vue_type_script_setup_true_lang-DI6cyWhd.js → FModal.vue_vue_type_script_setup_true_lang.js} +1 -1
  12. package/dist/FModal.vue_vue_type_script_setup_true_lang.js.map +1 -0
  13. package/dist/agent/ui/ElAuthPanel.vue.d.ts +6 -0
  14. package/dist/agent/ui/ElCreateAgent.vue.d.ts +180 -0
  15. package/dist/agent/ui/ElProvisioningStatus.vue.d.ts +13 -0
  16. package/dist/agent.js +5 -5
  17. package/dist/clients/AgentClient.d.ts +24 -0
  18. package/dist/clients/ChatClient.d.ts +22 -0
  19. package/dist/demo/index.d.ts +2 -1
  20. package/dist/index.d.ts +1 -0
  21. package/dist/index.js +766 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/sdk.js +9 -8
  24. package/dist/sdkClient.d.ts +9 -3
  25. package/dist/sdkClient.js +721 -0
  26. package/dist/sdkClient.js.map +1 -0
  27. package/dist/{socialPlatforms-Ck-b3SnQ.js → socialPlatforms.js} +1 -1
  28. package/dist/socialPlatforms.js.map +1 -0
  29. package/dist/test/agent-client.test.d.ts +4 -0
  30. package/dist/test/chat-authenticated.test.d.ts +1 -0
  31. package/dist/test/derive-mode.test.d.ts +1 -0
  32. package/dist/widget/PLWidget.d.ts +1 -1
  33. package/dist/widget/composables/useWidgetState.d.ts +6 -3
  34. package/dist/widget/index.d.ts +1 -0
  35. package/dist/widget/ui/AgentWidgetOnboard.vue.d.ts +7 -0
  36. package/dist/widget.js +4 -3
  37. package/package.json +1 -1
  38. package/dist/AgentProvider.vue_vue_type_script_setup_true_lang-5V_TRBPP.js.map +0 -1
  39. package/dist/AgentWidgetInline-DOoug3lh.js.map +0 -1
  40. package/dist/AgentWidgetModal-C-dDlu8w.js.map +0 -1
  41. package/dist/AgentWrap.vue_vue_type_script_setup_true_lang-CHgCPDEe.js.map +0 -1
  42. package/dist/FModal.vue_vue_type_script_setup_true_lang-DI6cyWhd.js.map +0 -1
  43. package/dist/index-C9cSPVgs.js +0 -379
  44. package/dist/index-C9cSPVgs.js.map +0 -1
  45. package/dist/sdkClient-6j3pmwVP.js +0 -625
  46. package/dist/sdkClient-6j3pmwVP.js.map +0 -1
  47. package/dist/socialPlatforms-Ck-b3SnQ.js.map +0 -1
@@ -1,625 +0,0 @@
1
- var N = Object.defineProperty;
2
- var z = (i, t, e) => t in i ? N(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e;
3
- var c = (i, t) => N(i, "name", { value: t, configurable: !0 });
4
- var a = (i, t, e) => z(i, typeof t != "symbol" ? t + "" : t, e);
5
- import { APP_PORT as H, APP_PROD_URL as K, cookieUtil as x, createLogger as Q, objectId as $, SettingsObject as V } from "@pagelines/core";
6
- import { watch as W, ref as S, computed as M } from "vue";
7
- import { hc as X } from "hono/client";
8
- function T(i, t) {
9
- return i || (t ? `http://localhost:${H}` : K);
10
- }
11
- c(T, "resolveApiBase");
12
- function Y(i, t) {
13
- const e = T(i.apiBase, i.isDev);
14
- return X(e, {
15
- fetch: /* @__PURE__ */ c(async (o, s) => {
16
- const g = x.getAuthToken(), d = await fetch(o, {
17
- ...s,
18
- headers: {
19
- ...s?.headers,
20
- "Content-Type": "application/json",
21
- // Only include Authorization header if token exists
22
- ...g && { Authorization: `Bearer ${g}` }
23
- },
24
- // Use 'omit' for Bearer tokens (not cookies) to allow CORS wildcard origin
25
- credentials: "omit"
26
- });
27
- if (t) {
28
- const v = d.json.bind(d);
29
- d.json = async () => {
30
- const n = await v();
31
- return typeof n == "object" && n !== null && "ok" in n && ("user" in n || "token" in n) && t(n), n;
32
- };
33
- }
34
- return d;
35
- }, "fetch")
36
- });
37
- }
38
- c(Y, "createApiClient");
39
- let Z = /* @__PURE__ */ Symbol("clean"), h = [], f = 0;
40
- const U = 4, J = /* @__PURE__ */ c(/* @__NO_SIDE_EFFECTS__ */ (i) => {
41
- let t = [], e = {
42
- get() {
43
- return e.lc || e.listen(() => {
44
- })(), e.value;
45
- },
46
- lc: 0,
47
- listen(r) {
48
- return e.lc = t.push(r), () => {
49
- for (let s = f + U; s < h.length; )
50
- h[s] === r ? h.splice(s, U) : s += U;
51
- let o = t.indexOf(r);
52
- ~o && (t.splice(o, 1), --e.lc || e.off());
53
- };
54
- },
55
- notify(r, o) {
56
- let s = !h.length;
57
- for (let g of t)
58
- h.push(g, e.value, r, o);
59
- if (s) {
60
- for (f = 0; f < h.length; f += U)
61
- h[f](
62
- h[f + 1],
63
- h[f + 2],
64
- h[f + 3]
65
- );
66
- h.length = 0;
67
- }
68
- },
69
- /* It will be called on last listener unsubscribing.
70
- We will redefine it in onMount and onStop. */
71
- off() {
72
- },
73
- set(r) {
74
- let o = e.value;
75
- o !== r && (e.value = r, e.notify(o));
76
- },
77
- subscribe(r) {
78
- let o = e.listen(r);
79
- return r(e.value), o;
80
- },
81
- value: i
82
- };
83
- return process.env.NODE_ENV !== "production" && (e[Z] = () => {
84
- t = [], e.lc = 0, e.off();
85
- }), e;
86
- }, "atom"), y = globalThis, b = y.__PL_AUTH_USER__ ?? (y.__PL_AUTH_USER__ = /* @__PURE__ */ J(void 0)), A = y.__PL_AUTH_TOKEN__ ?? (y.__PL_AUTH_TOKEN__ = /* @__PURE__ */ J(null)), R = class R {
87
- constructor() {
88
- a(this, "logger", Q("SDKStorage"));
89
- }
90
- /**
91
- * Check if localStorage is fully functional (some test environments provide partial mocks)
92
- */
93
- isLocalStorageFunctional() {
94
- return typeof window < "u" && typeof localStorage?.getItem == "function" && typeof localStorage?.setItem == "function" && typeof localStorage?.removeItem == "function";
95
- }
96
- /**
97
- * Sync Vue reactive refs with global nanostores for cross-page persistence
98
- */
99
- syncWithGlobalStores(t, e) {
100
- const r = b.get(), o = A.get();
101
- r && (t.value = r), o && (e.value = o), W(t, (s) => {
102
- b.set(s);
103
- }, { immediate: !0 }), W(e, (s) => {
104
- A.set(s);
105
- }, { immediate: !0 }), b.subscribe((s) => {
106
- s !== t.value && (t.value = s);
107
- }), A.subscribe((s) => {
108
- s !== e.value && (e.value = s);
109
- });
110
- }
111
- /**
112
- * Load user and token from browser storage on initialization
113
- */
114
- loadFromStorage(t, e) {
115
- if (typeof window > "u")
116
- return;
117
- const r = x.getAuthToken();
118
- if (r && (e.value = r), this.isLocalStorageFunctional())
119
- try {
120
- const o = localStorage.getItem("pagelines-user");
121
- o && (t.value = JSON.parse(o));
122
- } catch (o) {
123
- this.logger.error("Failed to load user from localStorage", { data: o });
124
- }
125
- }
126
- /**
127
- * Save current user and token to browser storage
128
- */
129
- saveToStorage(t, e) {
130
- if (!(typeof window > "u") && (e.value ? x.setAuthToken(e.value) : x.removeAuthToken(), this.isLocalStorageFunctional()))
131
- try {
132
- t.value ? localStorage.setItem("pagelines-user", JSON.stringify(t.value)) : localStorage.removeItem("pagelines-user");
133
- } catch (r) {
134
- this.logger.error("Failed to save user to localStorage", { data: r });
135
- }
136
- }
137
- /**
138
- * Clear all stored user data and tokens
139
- */
140
- clearStorage() {
141
- if (!(typeof window > "u")) {
142
- if (x.removeAuthToken(), this.isLocalStorageFunctional())
143
- try {
144
- localStorage.removeItem("pagelines-user");
145
- } catch (t) {
146
- this.logger.error("Failed to clear user from localStorage", { data: t });
147
- }
148
- b.set(void 0), A.set(null);
149
- }
150
- }
151
- /**
152
- * Generic localStorage getter
153
- */
154
- getItem(t) {
155
- if (!this.isLocalStorageFunctional())
156
- return null;
157
- try {
158
- return localStorage.getItem(t);
159
- } catch (e) {
160
- return this.logger.error("Failed to get item from localStorage", { key: t, error: e }), null;
161
- }
162
- }
163
- /**
164
- * Generic localStorage setter
165
- */
166
- setItem(t, e) {
167
- if (this.isLocalStorageFunctional())
168
- try {
169
- localStorage.setItem(t, e);
170
- } catch (r) {
171
- this.logger.error("Failed to set item in localStorage", { key: t, error: r });
172
- }
173
- }
174
- };
175
- c(R, "SDKStorage");
176
- let C = R;
177
- async function m(i, t) {
178
- i.loading.value = !0, i.error.value = null;
179
- try {
180
- return await t();
181
- } finally {
182
- i.loading.value = !1;
183
- }
184
- }
185
- c(m, "withLoadingState");
186
- const _ = class _ {
187
- constructor(t) {
188
- this.ctx = t;
189
- }
190
- async sendCode(t) {
191
- return m(this.ctx, async () => {
192
- try {
193
- const r = await (await this.ctx.api.auth["check-email"].$post({
194
- json: { email: t }
195
- })).json();
196
- if (!r.ok)
197
- throw this.ctx.error.value = r.error, new Error(r.error);
198
- } catch (e) {
199
- this.ctx.logger.error("Send code error", { data: e });
200
- const r = e instanceof Error ? e.message : "Failed to send verification code";
201
- throw this.ctx.error.value = r, e;
202
- }
203
- });
204
- }
205
- async verifyCode(t, e) {
206
- return m(this.ctx, async () => {
207
- try {
208
- const o = await (await this.ctx.api.auth["verify-code"].$post({
209
- json: { email: t, code: e }
210
- })).json();
211
- if (!o.ok)
212
- throw this.ctx.error.value = o.error, new Error(o.error);
213
- } catch (r) {
214
- this.ctx.logger.error("Verify code error", { data: r });
215
- const o = r instanceof Error ? r.message : "Failed to verify code";
216
- throw this.ctx.error.value = o, r;
217
- }
218
- });
219
- }
220
- async logout() {
221
- return m(this.ctx, async () => {
222
- try {
223
- await this.ctx.api.auth.logout.$post();
224
- } catch (t) {
225
- this.ctx.logger.error("Logout error (user still logged out locally)", { data: t });
226
- }
227
- this.ctx.activeUser.value = void 0, this.ctx.token.value = null, this.ctx.storage.clearStorage();
228
- });
229
- }
230
- async getCurrentUser() {
231
- if (this.ctx.token.value)
232
- return m(this.ctx, async () => {
233
- try {
234
- const e = await (await this.ctx.api.auth.me.$get()).json();
235
- if (!e.ok) {
236
- this.ctx.error.value = e.error, e.error.includes("Authentication") && (this.ctx.activeUser.value = void 0, this.ctx.token.value = null, this.ctx.storage.clearStorage());
237
- return;
238
- }
239
- return e.user;
240
- } catch (t) {
241
- this.ctx.logger.error("Get current user error", { data: t }), this.ctx.error.value = t instanceof Error ? t.message : "Failed to get user info";
242
- return;
243
- }
244
- });
245
- }
246
- async requestAuthCode(t) {
247
- return m(this.ctx, async () => {
248
- try {
249
- const r = await (await this.ctx.api.auth["check-email"].$post({
250
- json: { email: t.email }
251
- })).json();
252
- return r.ok ? (this.ctx.logger.info("Auth code requested successfully", { email: t.email }), !0) : (this.ctx.error.value = r.error, this.ctx.logger.error("Failed to request auth code", { email: t.email, error: r.error }), !1);
253
- } catch (e) {
254
- return this.ctx.logger.error("Request auth code error", { email: t.email, error: e }), this.ctx.error.value = e instanceof Error ? e.message : "Failed to request auth code", !1;
255
- }
256
- });
257
- }
258
- async loginWithCode(t) {
259
- return m(this.ctx, async () => {
260
- try {
261
- const r = await (await this.ctx.api.auth["verify-code"].$post({
262
- json: { email: t.email, code: t.code }
263
- })).json();
264
- return r.ok ? (this.ctx.logger.info("Login successful", { email: t.email }), !0) : (this.ctx.error.value = r.error, this.ctx.logger.error("Login failed", { email: t.email, error: r.error }), !1);
265
- } catch (e) {
266
- return this.ctx.logger.error("Login with code error", { email: t.email, error: e }), this.ctx.error.value = e instanceof Error ? e.message : "Login failed", !1;
267
- }
268
- });
269
- }
270
- loginWithGoogle(t) {
271
- if (typeof window > "u") {
272
- this.ctx.logger.error("loginWithGoogle: Only available in browser");
273
- return;
274
- }
275
- const e = T(this.ctx.apiBase, this.ctx.isDev), r = window.location.origin, o = `${e}/auth/google-popup?origin=${encodeURIComponent(r)}`, s = 500, g = 600, d = window.screenX + (window.outerWidth - s) / 2, v = window.screenY + (window.outerHeight - g) / 2, n = window.open(
276
- o,
277
- "google-auth",
278
- `width=${s},height=${g},left=${d},top=${v},popup=yes`
279
- );
280
- if (!n) {
281
- const l = "Popup was blocked. Please allow popups for this site.";
282
- this.ctx.error.value = l, t?.onError?.(l);
283
- return;
284
- }
285
- const p = /* @__PURE__ */ c((l) => {
286
- const k = new URL(e).origin;
287
- if (l.origin === k) {
288
- if (l.data?.type === "auth-success") {
289
- window.removeEventListener("message", p);
290
- const { token: u, user: w } = l.data;
291
- this.ctx.processApiResponse({ ok: !0, data: {}, token: u, user: w }), this.ctx.logger.info("Google login successful"), t?.onSuccess?.(w);
292
- } else if (l.data?.type === "auth-error") {
293
- window.removeEventListener("message", p);
294
- const u = l.data.error || "Google authentication failed";
295
- this.ctx.error.value = u, this.ctx.logger.error("Google login failed", { error: u }), t?.onError?.(u);
296
- }
297
- }
298
- }, "handler");
299
- window.addEventListener("message", p);
300
- const I = setInterval(() => {
301
- n.closed && (clearInterval(I), window.removeEventListener("message", p));
302
- }, 500);
303
- }
304
- };
305
- c(_, "AuthClient");
306
- let P = _;
307
- const D = class D {
308
- constructor(t) {
309
- this.ctx = t;
310
- }
311
- async chatStream(t) {
312
- const r = `${T(this.ctx.apiBase, this.ctx.isDev)}/api/agent/public/${encodeURIComponent(t.handle)}/chat/stream`;
313
- try {
314
- const o = await fetch(r, {
315
- method: "POST",
316
- headers: { "Content-Type": "application/json" },
317
- body: JSON.stringify({
318
- message: t.message,
319
- conversationId: t.conversationId,
320
- history: t.history,
321
- visitorId: t.visitorId,
322
- context: t.context,
323
- attachments: t.attachments
324
- })
325
- });
326
- if (!o.ok) {
327
- const n = await o.json().catch(() => ({ error: "Request failed" }));
328
- t.onError(n.error || `HTTP ${o.status}`);
329
- return;
330
- }
331
- const s = o.body?.getReader();
332
- if (!s) {
333
- t.onError("No response stream");
334
- return;
335
- }
336
- const g = new TextDecoder();
337
- let d = "", v = t.conversationId || "";
338
- for (; ; ) {
339
- const { done: n, value: p } = await s.read();
340
- if (n)
341
- break;
342
- d += g.decode(p, { stream: !0 });
343
- const I = d.split(`
344
- `);
345
- d = I.pop() || "";
346
- for (const l of I) {
347
- if (!l.startsWith("data: "))
348
- continue;
349
- const k = l.slice(6).trim();
350
- if (k === "[DONE]") {
351
- t.onDone(v);
352
- return;
353
- }
354
- try {
355
- const u = JSON.parse(k);
356
- if (u.pl_status) {
357
- t.onStatus?.(u.pl_status);
358
- continue;
359
- }
360
- u.pl_metadata?.conversationId && (v = u.pl_metadata.conversationId);
361
- const w = u.choices?.[0]?.delta;
362
- w?.content && t.onDelta(w.content);
363
- } catch {
364
- }
365
- }
366
- }
367
- t.onDone(v);
368
- } catch (o) {
369
- t.onError(o instanceof Error ? o.message : "Stream failed");
370
- }
371
- }
372
- async chatMessage(t) {
373
- const r = `${T(this.ctx.apiBase, this.ctx.isDev)}/api/agent/public/${encodeURIComponent(t.handle)}/chat`;
374
- try {
375
- const s = await (await fetch(r, {
376
- method: "POST",
377
- headers: { "Content-Type": "application/json" },
378
- body: JSON.stringify({
379
- message: t.message,
380
- conversationId: t.conversationId,
381
- visitorId: t.visitorId,
382
- context: t.context
383
- })
384
- })).json();
385
- if (!s.ok || !s.data) {
386
- this.ctx.logger.error("chatMessage failed", { error: !s.ok && "error" in s ? s.error : "Unknown" });
387
- return;
388
- }
389
- return {
390
- conversationId: s.data.conversationId,
391
- content: s.data.message.content
392
- };
393
- } catch (o) {
394
- this.ctx.logger.error("chatMessage error", { error: o });
395
- return;
396
- }
397
- }
398
- };
399
- c(D, "ChatClient");
400
- let F = D;
401
- const O = class O {
402
- constructor(t) {
403
- this.ctx = t;
404
- }
405
- async getPublicAgent(t) {
406
- this.ctx.loading.value = !0, this.ctx.error.value = null;
407
- try {
408
- const r = await (await this.ctx.api.agent.public[":handle"].$get({
409
- param: { handle: t.handle }
410
- })).json();
411
- if (!r.ok) {
412
- this.ctx.error.value = r.error, this.ctx.logger.error("Failed to fetch public agent", { handle: t.handle, error: r.error });
413
- return;
414
- }
415
- return r.data;
416
- } catch (e) {
417
- this.ctx.logger.error("Get public agent error", { handle: t.handle, error: e }), this.ctx.error.value = e instanceof Error ? e.message : "Failed to fetch agent";
418
- return;
419
- } finally {
420
- this.ctx.loading.value = !1;
421
- }
422
- }
423
- async getAgentByEmail(t) {
424
- this.ctx.loading.value = !0, this.ctx.error.value = null;
425
- try {
426
- const r = await (await this.ctx.api.agent["by-email"][":email"].$get({
427
- param: { email: t.email }
428
- })).json();
429
- if (!r.ok) {
430
- this.ctx.error.value = r.error, this.ctx.logger.error("Failed to fetch agent by email", { email: t.email, error: r.error });
431
- return;
432
- }
433
- return r.data;
434
- } catch (e) {
435
- this.ctx.logger.error("Get agent by email error", { email: t.email, error: e }), this.ctx.error.value = e instanceof Error ? e.message : "Failed to fetch agent";
436
- return;
437
- } finally {
438
- this.ctx.loading.value = !1;
439
- }
440
- }
441
- generateAnonId() {
442
- const t = "pagelinesAnonId";
443
- let e = this.ctx.storage.getItem(t);
444
- return e || (e = $({ prefix: "anon" }), this.ctx.storage.setItem(t, e)), e;
445
- }
446
- track(t) {
447
- try {
448
- typeof window < "u" && window.parent !== window && window.parent.postMessage({
449
- type: "pagelines_track",
450
- event: t.event,
451
- agentId: t.agentId,
452
- properties: t.properties || {}
453
- }, "*"), this.ctx.logger.info("SDK event tracked", { event: t.event, agentId: t.agentId });
454
- } catch (e) {
455
- this.ctx.logger.error("Track event error", { error: e, args: t });
456
- }
457
- }
458
- };
459
- c(O, "UserClient");
460
- let j = O;
461
- const G = class G {
462
- constructor() {
463
- a(this, "key", "__PAGELINES_SDK__");
464
- }
465
- get() {
466
- if (!(typeof window > "u"))
467
- return globalThis[this.key];
468
- }
469
- set(t) {
470
- typeof window < "u" && (globalThis[this.key] = t);
471
- }
472
- delete() {
473
- typeof window < "u" && delete globalThis[this.key];
474
- }
475
- };
476
- c(G, "SDKGlobal");
477
- let B = G;
478
- const E = new B(), L = class L extends V {
479
- constructor(e = {}) {
480
- const r = E.get();
481
- if (r)
482
- return console.debug("[PageLinesSDK] Returning existing singleton instance"), r;
483
- super("PageLinesSDK", e);
484
- // Vue reactive state
485
- a(this, "activeUser", S());
486
- a(this, "token", S(null));
487
- a(this, "loading", S(!1));
488
- a(this, "error", S(null));
489
- a(this, "apiBase", this.settings.apiBase || void 0);
490
- // Storage handler for persistence
491
- a(this, "storage", new C());
492
- // Auto-managed session ID for usage tracking
493
- a(this, "sessionId", $({ prefix: "ses" }));
494
- // Typed Hono RPC client - uses SDKAppType (auth/self/usage routes only)
495
- // Initialized in constructor (definite assignment via singleton pattern)
496
- a(this, "apiClient");
497
- // Computed properties derived from activeUser (matches UserClient pattern)
498
- a(this, "currentAgent", M(() => {
499
- const e = this.activeUser.value;
500
- if (!e?.agents)
501
- return;
502
- const r = e.primaryAgentId || e.agents[0]?.agentId;
503
- if (r)
504
- return e.agents.find((o) => o.agentId === r);
505
- }));
506
- a(this, "currentOrg", M(() => {
507
- const e = this.currentAgent.value;
508
- if (!e?.orgId)
509
- return;
510
- const r = this.activeUser.value;
511
- if (r?.orgs)
512
- return r.orgs.find((o) => o.orgId === e.orgId);
513
- }));
514
- // Initialization state
515
- a(this, "initialized");
516
- a(this, "resolveUser");
517
- // Sub-clients (new preferred API surface)
518
- a(this, "auth");
519
- a(this, "chat");
520
- a(this, "user");
521
- E.set(this), this.apiClient = Y(
522
- { isDev: this.isDev, apiBase: this.apiBase },
523
- this.processApiResponse.bind(this)
524
- );
525
- const o = {
526
- api: this.api,
527
- apiBase: this.apiBase,
528
- isDev: this.isDev,
529
- activeUser: this.activeUser,
530
- token: this.token,
531
- loading: this.loading,
532
- error: this.error,
533
- currentAgent: this.currentAgent,
534
- storage: this.storage,
535
- sessionId: this.sessionId,
536
- logger: this.logger,
537
- processApiResponse: this.processApiResponse.bind(this)
538
- };
539
- this.auth = new P(o), this.chat = new F(o), this.user = new j(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) => {
540
- this.resolveUser = s;
541
- }), this.token.value && !this.activeUser.value ? this.getCurrentUser().then((s) => {
542
- this.resolveUser && (this.resolveUser(s), this.resolveUser = void 0);
543
- }).catch((s) => {
544
- this.logger.error("Auto user fetch failed", { data: s }), this.resolveUser && (this.resolveUser(void 0), this.resolveUser = void 0);
545
- }) : this.activeUser.value ? this.resolveUser?.(this.activeUser.value) : this.resolveUser?.(void 0);
546
- }
547
- /**
548
- * Get singleton instance in browser (creates if doesn't exist)
549
- * Node.js: Always creates new instance (no singleton)
550
- * Recommended: Use this instead of constructor for shared state
551
- */
552
- static getInstance(e = {}) {
553
- return E.get() || new L(e);
554
- }
555
- get isDev() {
556
- return this.settings.isDev ?? (typeof window < "u" ? window.location.hostname === "localhost" || window.location.hostname.includes("127.0.0.1") : !1);
557
- }
558
- // Bypass stub typing for route access (production builds use SDKAppType stub)
559
- // Runtime types are validated via Zod at API boundaries
560
- get api() {
561
- return this.apiClient.api;
562
- }
563
- // Process ApiResponse for automatic user/token updates - public for dependency injection
564
- processApiResponse(e) {
565
- e.ok && e.user && (this.activeUser.value = e.user, this.logger.info("User updated from API response", { data: e.user })), e.ok && e.token && (this.token.value = e.token, this.storage.saveToStorage(this.activeUser, this.token), this.logger.info("Token updated from API response")), this.resolveUser && e.ok && (this.resolveUser(e.user), this.resolveUser = void 0);
566
- }
567
- // Clear all user data and tokens
568
- clearSession() {
569
- this.logger.info("Clearing session"), this.activeUser.value = void 0, this.token.value = null, this.error.value = null, this.storage.clearStorage();
570
- }
571
- // Full reset - clears session + state + destroys singleton
572
- clear() {
573
- this.logger.info("Clearing SDK completely"), this.clearSession(), this.loading.value = !1, this.sessionId = $({ prefix: "ses" }), E.delete();
574
- }
575
- // Backward-compatible delegates — these forward to sub-clients
576
- // Can be removed in a future breaking change
577
- async sendCode(e) {
578
- return this.auth.sendCode(e);
579
- }
580
- async verifyCode(e, r) {
581
- return this.auth.verifyCode(e, r);
582
- }
583
- async logout() {
584
- return this.auth.logout();
585
- }
586
- async getCurrentUser() {
587
- return this.auth.getCurrentUser();
588
- }
589
- async requestAuthCode(e) {
590
- return this.auth.requestAuthCode(e);
591
- }
592
- async loginWithCode(e) {
593
- return this.auth.loginWithCode(e);
594
- }
595
- loginWithGoogle(e) {
596
- return this.auth.loginWithGoogle(e);
597
- }
598
- async chatStream(e) {
599
- return this.chat.chatStream(e);
600
- }
601
- async chatMessage(e) {
602
- return this.chat.chatMessage(e);
603
- }
604
- async getPublicAgent(e) {
605
- return this.user.getPublicAgent(e);
606
- }
607
- async getAgentByEmail(e) {
608
- return this.user.getAgentByEmail(e);
609
- }
610
- generateAnonId() {
611
- return this.user.generateAnonId();
612
- }
613
- track(e) {
614
- return this.user.track(e);
615
- }
616
- };
617
- c(L, "PageLinesSDK");
618
- let q = L;
619
- export {
620
- P as A,
621
- F as C,
622
- q as P,
623
- j as U
624
- };
625
- //# sourceMappingURL=sdkClient-6j3pmwVP.js.map