@pagelines/sdk 1.0.391 → 1.0.393
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/AgentWrap.vue_vue_type_script_setup_true_lang.js +409 -403
- package/dist/AgentWrap.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/agent/test/webhook.test.d.ts +1 -0
- package/dist/clients/AgentClient.d.ts +15 -0
- package/dist/index.js +1 -1
- package/dist/sdkClient.js +136 -121
- package/dist/sdkClient.js.map +1 -1
- package/package.json +1 -1
package/dist/sdkClient.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
var W = Object.defineProperty;
|
|
2
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
|
|
3
|
+
var u = (a, e) => W(a, "name", { value: e, configurable: !0 });
|
|
4
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
|
|
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
6
|
import { watch as q, ref as k, computed as z } from "vue";
|
|
7
7
|
import { hc as ee } from "hono/client";
|
|
8
|
-
function
|
|
8
|
+
function p(a, e) {
|
|
9
9
|
return a || (e ? `http://localhost:${V}` : X);
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
u(p, "resolveApiBase");
|
|
12
12
|
function te(a, e) {
|
|
13
|
-
const t =
|
|
13
|
+
const t = p(a.apiBase, a.isDev);
|
|
14
14
|
return ee(t, {
|
|
15
|
-
fetch: /* @__PURE__ */
|
|
16
|
-
const n = x.getAuthToken(), l = await fetch(
|
|
17
|
-
...
|
|
15
|
+
fetch: /* @__PURE__ */ u(async (s, o) => {
|
|
16
|
+
const n = x.getAuthToken(), l = await fetch(s, {
|
|
17
|
+
...o,
|
|
18
18
|
headers: {
|
|
19
|
-
...
|
|
19
|
+
...o?.headers,
|
|
20
20
|
"Content-Type": "application/json",
|
|
21
21
|
// Only include Authorization header if token exists
|
|
22
22
|
...n && { Authorization: `Bearer ${n}` }
|
|
@@ -35,9 +35,9 @@ function te(a, e) {
|
|
|
35
35
|
}, "fetch")
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
u(te, "createApiClient");
|
|
39
39
|
let re = /* @__PURE__ */ Symbol("clean"), d = [], f = 0;
|
|
40
|
-
const
|
|
40
|
+
const b = 4, K = /* @__PURE__ */ u(/* @__NO_SIDE_EFFECTS__ */ (a) => {
|
|
41
41
|
let e = [], t = {
|
|
42
42
|
get() {
|
|
43
43
|
return t.lc || t.listen(() => {
|
|
@@ -46,18 +46,18 @@ const A = 4, K = /* @__PURE__ */ h(/* @__NO_SIDE_EFFECTS__ */ (a) => {
|
|
|
46
46
|
lc: 0,
|
|
47
47
|
listen(r) {
|
|
48
48
|
return t.lc = e.push(r), () => {
|
|
49
|
-
for (let
|
|
50
|
-
d[
|
|
51
|
-
let
|
|
52
|
-
~
|
|
49
|
+
for (let o = f + b; o < d.length; )
|
|
50
|
+
d[o] === r ? d.splice(o, b) : o += b;
|
|
51
|
+
let s = e.indexOf(r);
|
|
52
|
+
~s && (e.splice(s, 1), --t.lc || t.off());
|
|
53
53
|
};
|
|
54
54
|
},
|
|
55
|
-
notify(r,
|
|
56
|
-
let
|
|
55
|
+
notify(r, s) {
|
|
56
|
+
let o = !d.length;
|
|
57
57
|
for (let n of e)
|
|
58
|
-
d.push(n, t.value, r,
|
|
59
|
-
if (
|
|
60
|
-
for (f = 0; f < d.length; f +=
|
|
58
|
+
d.push(n, t.value, r, s);
|
|
59
|
+
if (o) {
|
|
60
|
+
for (f = 0; f < d.length; f += b)
|
|
61
61
|
d[f](
|
|
62
62
|
d[f + 1],
|
|
63
63
|
d[f + 2],
|
|
@@ -71,19 +71,19 @@ const A = 4, K = /* @__PURE__ */ h(/* @__NO_SIDE_EFFECTS__ */ (a) => {
|
|
|
71
71
|
off() {
|
|
72
72
|
},
|
|
73
73
|
set(r) {
|
|
74
|
-
let
|
|
75
|
-
|
|
74
|
+
let s = t.value;
|
|
75
|
+
s !== r && (t.value = r, t.notify(s));
|
|
76
76
|
},
|
|
77
77
|
subscribe(r) {
|
|
78
|
-
let
|
|
79
|
-
return r(t.value),
|
|
78
|
+
let s = t.listen(r);
|
|
79
|
+
return r(t.value), s;
|
|
80
80
|
},
|
|
81
81
|
value: a
|
|
82
82
|
};
|
|
83
83
|
return process.env.NODE_ENV !== "production" && (t[re] = () => {
|
|
84
84
|
e = [], t.lc = 0, t.off();
|
|
85
85
|
}), t;
|
|
86
|
-
}, "atom"), y = globalThis,
|
|
86
|
+
}, "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
87
|
constructor() {
|
|
88
88
|
i(this, "logger", Y("SDKStorage"));
|
|
89
89
|
}
|
|
@@ -97,15 +97,15 @@ const A = 4, K = /* @__PURE__ */ h(/* @__NO_SIDE_EFFECTS__ */ (a) => {
|
|
|
97
97
|
* Sync Vue reactive refs with global nanostores for cross-page persistence
|
|
98
98
|
*/
|
|
99
99
|
syncWithGlobalStores(e, t) {
|
|
100
|
-
const r =
|
|
101
|
-
r && (e.value = r),
|
|
102
|
-
|
|
103
|
-
}, { immediate: !0 }), q(t, (
|
|
104
|
-
|
|
105
|
-
}, { immediate: !0 }),
|
|
106
|
-
|
|
107
|
-
}),
|
|
108
|
-
|
|
100
|
+
const r = A.get(), s = U.get();
|
|
101
|
+
r && (e.value = r), s && (t.value = s), q(e, (o) => {
|
|
102
|
+
A.set(o);
|
|
103
|
+
}, { immediate: !0 }), q(t, (o) => {
|
|
104
|
+
U.set(o);
|
|
105
|
+
}, { immediate: !0 }), A.subscribe((o) => {
|
|
106
|
+
o !== e.value && (e.value = o);
|
|
107
|
+
}), U.subscribe((o) => {
|
|
108
|
+
o !== t.value && (t.value = o);
|
|
109
109
|
});
|
|
110
110
|
}
|
|
111
111
|
/**
|
|
@@ -117,10 +117,10 @@ const A = 4, K = /* @__PURE__ */ h(/* @__NO_SIDE_EFFECTS__ */ (a) => {
|
|
|
117
117
|
const r = x.getAuthToken();
|
|
118
118
|
if (r && (t.value = r), this.isLocalStorageFunctional())
|
|
119
119
|
try {
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
} catch (
|
|
123
|
-
this.logger.error("Failed to load user from localStorage", { data:
|
|
120
|
+
const s = localStorage.getItem("pagelines-user");
|
|
121
|
+
s && (e.value = JSON.parse(s));
|
|
122
|
+
} catch (s) {
|
|
123
|
+
this.logger.error("Failed to load user from localStorage", { data: s });
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
/**
|
|
@@ -145,7 +145,7 @@ const A = 4, K = /* @__PURE__ */ h(/* @__NO_SIDE_EFFECTS__ */ (a) => {
|
|
|
145
145
|
} catch (e) {
|
|
146
146
|
this.logger.error("Failed to clear user from localStorage", { data: e });
|
|
147
147
|
}
|
|
148
|
-
|
|
148
|
+
A.set(void 0), U.set(null);
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
/**
|
|
@@ -172,19 +172,19 @@ const A = 4, K = /* @__PURE__ */ h(/* @__NO_SIDE_EFFECTS__ */ (a) => {
|
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
};
|
|
175
|
-
|
|
176
|
-
let
|
|
175
|
+
u(F, "SDKStorage");
|
|
176
|
+
let B = F;
|
|
177
177
|
const J = [
|
|
178
178
|
"Deploying your server...",
|
|
179
179
|
"Setting up your workspace...",
|
|
180
180
|
"Installing tools...",
|
|
181
181
|
"Almost ready..."
|
|
182
|
-
],
|
|
182
|
+
], O = class O {
|
|
183
183
|
constructor(e) {
|
|
184
184
|
this.ctx = e;
|
|
185
185
|
}
|
|
186
186
|
async create(e) {
|
|
187
|
-
const t = e.orgId || this.resolveOrgId(), r =
|
|
187
|
+
const t = e.orgId || this.resolveOrgId(), r = p(this.ctx.apiBase, this.ctx.isDev), o = await (await fetch(`${r}/api/agent`, {
|
|
188
188
|
method: "POST",
|
|
189
189
|
headers: {
|
|
190
190
|
"Content-Type": "application/json",
|
|
@@ -192,24 +192,24 @@ const J = [
|
|
|
192
192
|
},
|
|
193
193
|
body: JSON.stringify({ name: e.name, orgId: t })
|
|
194
194
|
})).json();
|
|
195
|
-
if (!
|
|
196
|
-
const n =
|
|
195
|
+
if (!o.ok || !o.data?.[0]) {
|
|
196
|
+
const n = o.error || "Failed to create agent";
|
|
197
197
|
throw this.ctx.error.value = n, new Error(n);
|
|
198
198
|
}
|
|
199
|
-
return this.ctx.processApiResponse(
|
|
199
|
+
return this.ctx.processApiResponse(o), o.data[0];
|
|
200
200
|
}
|
|
201
201
|
async getStatus(e) {
|
|
202
|
-
const t =
|
|
202
|
+
const t = p(this.ctx.apiBase, this.ctx.isDev), s = await (await fetch(`${t}/api/agent/${e.agentId}/status`, {
|
|
203
203
|
headers: {
|
|
204
204
|
...this.ctx.token.value && { Authorization: `Bearer ${this.ctx.token.value}` }
|
|
205
205
|
}
|
|
206
206
|
})).json();
|
|
207
|
-
return !
|
|
207
|
+
return !s.ok || !s.data ? { status: "unknown", ready: !1, error: "Failed to check status" } : s.data;
|
|
208
208
|
}
|
|
209
209
|
async waitUntilReady(e) {
|
|
210
|
-
const { agentId: t, onStatus: r, timeoutMs:
|
|
210
|
+
const { agentId: t, onStatus: r, timeoutMs: s = 3e5, pollIntervalMs: o = 3e3 } = e, n = Date.now();
|
|
211
211
|
let l = 0;
|
|
212
|
-
for (; Date.now() - n <
|
|
212
|
+
for (; Date.now() - n < s; ) {
|
|
213
213
|
const g = await this.getStatus({ agentId: t });
|
|
214
214
|
if (g.ready) {
|
|
215
215
|
r?.("Ready!");
|
|
@@ -217,10 +217,25 @@ const J = [
|
|
|
217
217
|
}
|
|
218
218
|
if (g.status === "error")
|
|
219
219
|
throw new Error(g.error || "Provisioning failed");
|
|
220
|
-
r && l < J.length && (r(J[l]), l++), await new Promise((c) => setTimeout(c,
|
|
220
|
+
r && l < J.length && (r(J[l]), l++), await new Promise((c) => setTimeout(c, o));
|
|
221
221
|
}
|
|
222
222
|
throw new Error("Agent provisioning timed out — please try again");
|
|
223
223
|
}
|
|
224
|
+
/** Send a typed webhook event to a bot agent. No auth required — the proxy is public. */
|
|
225
|
+
async webhook(e) {
|
|
226
|
+
const r = `${p(this.ctx.apiBase, this.ctx.isDev)}/api/bot-api/agents/${e.agentId}/webhook`, s = { type: e.type, data: e.data };
|
|
227
|
+
e.meta && (s.meta = e.meta);
|
|
228
|
+
const o = await fetch(r, {
|
|
229
|
+
method: "POST",
|
|
230
|
+
headers: { "Content-Type": "application/json" },
|
|
231
|
+
body: JSON.stringify(s)
|
|
232
|
+
});
|
|
233
|
+
if (!o.ok) {
|
|
234
|
+
const n = await o.text().catch(() => "Unknown error");
|
|
235
|
+
throw new Error(`Webhook delivery failed (${o.status}): ${n.slice(0, 200)}`);
|
|
236
|
+
}
|
|
237
|
+
return o.json();
|
|
238
|
+
}
|
|
224
239
|
resolveOrgId() {
|
|
225
240
|
const t = this.ctx.activeUser.value?.orgs?.[0]?.orgId;
|
|
226
241
|
if (!t)
|
|
@@ -228,8 +243,8 @@ const J = [
|
|
|
228
243
|
return t;
|
|
229
244
|
}
|
|
230
245
|
};
|
|
231
|
-
|
|
232
|
-
let
|
|
246
|
+
u(O, "AgentClient");
|
|
247
|
+
let D = O;
|
|
233
248
|
async function m(a, e) {
|
|
234
249
|
a.loading.value = !0, a.error.value = null;
|
|
235
250
|
try {
|
|
@@ -238,8 +253,8 @@ async function m(a, e) {
|
|
|
238
253
|
a.loading.value = !1;
|
|
239
254
|
}
|
|
240
255
|
}
|
|
241
|
-
|
|
242
|
-
const
|
|
256
|
+
u(m, "withLoadingState");
|
|
257
|
+
const R = class R {
|
|
243
258
|
constructor(e) {
|
|
244
259
|
this.ctx = e;
|
|
245
260
|
}
|
|
@@ -261,15 +276,15 @@ const _ = class _ {
|
|
|
261
276
|
async verifyCode(e, t) {
|
|
262
277
|
return m(this.ctx, async () => {
|
|
263
278
|
try {
|
|
264
|
-
const
|
|
279
|
+
const s = await (await this.ctx.api.auth["verify-code"].$post({
|
|
265
280
|
json: { email: e, code: t }
|
|
266
281
|
})).json();
|
|
267
|
-
if (!
|
|
268
|
-
throw this.ctx.error.value =
|
|
282
|
+
if (!s.ok)
|
|
283
|
+
throw this.ctx.error.value = s.error, new Error(s.error);
|
|
269
284
|
} catch (r) {
|
|
270
285
|
this.ctx.logger.error("Verify code error", { data: r });
|
|
271
|
-
const
|
|
272
|
-
throw this.ctx.error.value =
|
|
286
|
+
const s = r instanceof Error ? r.message : "Failed to verify code";
|
|
287
|
+
throw this.ctx.error.value = s, r;
|
|
273
288
|
}
|
|
274
289
|
});
|
|
275
290
|
}
|
|
@@ -328,44 +343,44 @@ const _ = class _ {
|
|
|
328
343
|
this.ctx.logger.error("loginWithGoogle: Only available in browser");
|
|
329
344
|
return;
|
|
330
345
|
}
|
|
331
|
-
const t =
|
|
332
|
-
|
|
346
|
+
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(
|
|
347
|
+
s,
|
|
333
348
|
"google-auth",
|
|
334
|
-
`width=${
|
|
349
|
+
`width=${o},height=${n},left=${l},top=${g},popup=yes`
|
|
335
350
|
);
|
|
336
351
|
if (!c) {
|
|
337
|
-
const
|
|
338
|
-
this.ctx.error.value =
|
|
352
|
+
const h = "Popup was blocked. Please allow popups for this site.";
|
|
353
|
+
this.ctx.error.value = h, e?.onError?.(h);
|
|
339
354
|
return;
|
|
340
355
|
}
|
|
341
|
-
const
|
|
356
|
+
const v = /* @__PURE__ */ u((h) => {
|
|
342
357
|
const S = new URL(t).origin;
|
|
343
|
-
if (
|
|
344
|
-
if (
|
|
345
|
-
window.removeEventListener("message",
|
|
346
|
-
const { token: w, user: M } =
|
|
358
|
+
if (h.origin === S) {
|
|
359
|
+
if (h.data?.type === "auth-success") {
|
|
360
|
+
window.removeEventListener("message", v);
|
|
361
|
+
const { token: w, user: M } = h.data;
|
|
347
362
|
this.ctx.processApiResponse({ ok: !0, data: {}, token: w, user: M }), this.ctx.logger.info("Google login successful"), e?.onSuccess?.(M);
|
|
348
|
-
} else if (
|
|
349
|
-
window.removeEventListener("message",
|
|
350
|
-
const w =
|
|
363
|
+
} else if (h.data?.type === "auth-error") {
|
|
364
|
+
window.removeEventListener("message", v);
|
|
365
|
+
const w = h.data.error || "Google authentication failed";
|
|
351
366
|
this.ctx.error.value = w, this.ctx.logger.error("Google login failed", { error: w }), e?.onError?.(w);
|
|
352
367
|
}
|
|
353
368
|
}
|
|
354
369
|
}, "handler");
|
|
355
|
-
window.addEventListener("message",
|
|
370
|
+
window.addEventListener("message", v);
|
|
356
371
|
const I = setInterval(() => {
|
|
357
|
-
c.closed && (clearInterval(I), window.removeEventListener("message",
|
|
372
|
+
c.closed && (clearInterval(I), window.removeEventListener("message", v));
|
|
358
373
|
}, 500);
|
|
359
374
|
}
|
|
360
375
|
};
|
|
361
|
-
|
|
362
|
-
let C =
|
|
363
|
-
const
|
|
376
|
+
u(R, "AuthClient");
|
|
377
|
+
let C = R;
|
|
378
|
+
const _ = class _ {
|
|
364
379
|
constructor(e) {
|
|
365
380
|
this.ctx = e;
|
|
366
381
|
}
|
|
367
382
|
async chatStream(e) {
|
|
368
|
-
const r = `${
|
|
383
|
+
const r = `${p(this.ctx.apiBase, this.ctx.isDev)}/api/agent/public/${encodeURIComponent(e.handle)}/chat/stream`;
|
|
369
384
|
return this._streamChat({
|
|
370
385
|
url: r,
|
|
371
386
|
headers: { "Content-Type": "application/json" },
|
|
@@ -385,7 +400,7 @@ const O = class O {
|
|
|
385
400
|
});
|
|
386
401
|
}
|
|
387
402
|
async chatStreamAuthenticated(e) {
|
|
388
|
-
const r = `${
|
|
403
|
+
const r = `${p(this.ctx.apiBase, this.ctx.isDev)}/api/agent/${encodeURIComponent(e.agentId)}/chat/stream`;
|
|
389
404
|
return this._streamChat({
|
|
390
405
|
url: r,
|
|
391
406
|
headers: {
|
|
@@ -423,32 +438,32 @@ const O = class O {
|
|
|
423
438
|
e.onError("No response stream");
|
|
424
439
|
return;
|
|
425
440
|
}
|
|
426
|
-
const
|
|
427
|
-
let
|
|
441
|
+
const s = new TextDecoder();
|
|
442
|
+
let o = "", n = e.conversationId || "";
|
|
428
443
|
for (; ; ) {
|
|
429
444
|
const { done: l, value: g } = await r.read();
|
|
430
445
|
if (l)
|
|
431
446
|
break;
|
|
432
|
-
|
|
433
|
-
const c =
|
|
447
|
+
o += s.decode(g, { stream: !0 });
|
|
448
|
+
const c = o.split(`
|
|
434
449
|
`);
|
|
435
|
-
|
|
436
|
-
for (const
|
|
437
|
-
if (!
|
|
450
|
+
o = c.pop() || "";
|
|
451
|
+
for (const v of c) {
|
|
452
|
+
if (!v.startsWith("data: "))
|
|
438
453
|
continue;
|
|
439
|
-
const I =
|
|
454
|
+
const I = v.slice(6).trim();
|
|
440
455
|
if (I === "[DONE]") {
|
|
441
456
|
e.onDone(n);
|
|
442
457
|
return;
|
|
443
458
|
}
|
|
444
459
|
try {
|
|
445
|
-
const
|
|
446
|
-
if (
|
|
447
|
-
e.onStatus?.(
|
|
460
|
+
const h = JSON.parse(I);
|
|
461
|
+
if (h.pl_status) {
|
|
462
|
+
e.onStatus?.(h.pl_status);
|
|
448
463
|
continue;
|
|
449
464
|
}
|
|
450
|
-
|
|
451
|
-
const S =
|
|
465
|
+
h.pl_metadata?.conversationId && (n = h.pl_metadata.conversationId);
|
|
466
|
+
const S = h.choices?.[0]?.delta;
|
|
452
467
|
S?.content && e.onDelta(S.content);
|
|
453
468
|
} catch {
|
|
454
469
|
}
|
|
@@ -460,9 +475,9 @@ const O = class O {
|
|
|
460
475
|
}
|
|
461
476
|
}
|
|
462
477
|
async chatMessage(e) {
|
|
463
|
-
const r = `${
|
|
478
|
+
const r = `${p(this.ctx.apiBase, this.ctx.isDev)}/api/agent/public/${encodeURIComponent(e.handle)}/chat`;
|
|
464
479
|
try {
|
|
465
|
-
const
|
|
480
|
+
const o = await (await fetch(r, {
|
|
466
481
|
method: "POST",
|
|
467
482
|
headers: { "Content-Type": "application/json" },
|
|
468
483
|
body: JSON.stringify({
|
|
@@ -472,22 +487,22 @@ const O = class O {
|
|
|
472
487
|
context: e.context
|
|
473
488
|
})
|
|
474
489
|
})).json();
|
|
475
|
-
if (!
|
|
476
|
-
this.ctx.logger.error("chatMessage failed", { error: !
|
|
490
|
+
if (!o.ok || !o.data) {
|
|
491
|
+
this.ctx.logger.error("chatMessage failed", { error: !o.ok && "error" in o ? o.error : "Unknown" });
|
|
477
492
|
return;
|
|
478
493
|
}
|
|
479
494
|
return {
|
|
480
|
-
conversationId:
|
|
481
|
-
content:
|
|
495
|
+
conversationId: o.data.conversationId,
|
|
496
|
+
content: o.data.message.content
|
|
482
497
|
};
|
|
483
|
-
} catch (
|
|
484
|
-
this.ctx.logger.error("chatMessage error", { error:
|
|
498
|
+
} catch (s) {
|
|
499
|
+
this.ctx.logger.error("chatMessage error", { error: s });
|
|
485
500
|
return;
|
|
486
501
|
}
|
|
487
502
|
}
|
|
488
503
|
};
|
|
489
|
-
|
|
490
|
-
let P =
|
|
504
|
+
u(_, "ChatClient");
|
|
505
|
+
let P = _;
|
|
491
506
|
const N = class N {
|
|
492
507
|
constructor(e) {
|
|
493
508
|
this.ctx = e;
|
|
@@ -531,7 +546,7 @@ const N = class N {
|
|
|
531
546
|
generateAnonId() {
|
|
532
547
|
const e = "pagelinesAnonId";
|
|
533
548
|
let t = this.ctx.storage.getItem(e);
|
|
534
|
-
return t || (t =
|
|
549
|
+
return t || (t = $({ prefix: "anon" }), this.ctx.storage.setItem(e, t)), t;
|
|
535
550
|
}
|
|
536
551
|
track(e) {
|
|
537
552
|
try {
|
|
@@ -546,7 +561,7 @@ const N = class N {
|
|
|
546
561
|
}
|
|
547
562
|
}
|
|
548
563
|
};
|
|
549
|
-
|
|
564
|
+
u(N, "UserClient");
|
|
550
565
|
let j = N;
|
|
551
566
|
const G = class G {
|
|
552
567
|
constructor() {
|
|
@@ -563,7 +578,7 @@ const G = class G {
|
|
|
563
578
|
typeof window < "u" && delete globalThis[this.key];
|
|
564
579
|
}
|
|
565
580
|
};
|
|
566
|
-
|
|
581
|
+
u(G, "SDKGlobal");
|
|
567
582
|
let L = G;
|
|
568
583
|
const E = new L(), T = class T extends Z {
|
|
569
584
|
constructor(t = {}) {
|
|
@@ -578,9 +593,9 @@ const E = new L(), T = class T extends Z {
|
|
|
578
593
|
i(this, "error", k(null));
|
|
579
594
|
i(this, "apiBase", this.settings.apiBase || void 0);
|
|
580
595
|
// Storage handler for persistence
|
|
581
|
-
i(this, "storage", new
|
|
596
|
+
i(this, "storage", new B());
|
|
582
597
|
// Auto-managed session ID for usage tracking
|
|
583
|
-
i(this, "sessionId",
|
|
598
|
+
i(this, "sessionId", $({ prefix: "ses" }));
|
|
584
599
|
// Typed Hono RPC client - uses SDKAppType (auth/self/usage routes only)
|
|
585
600
|
// Initialized in constructor (definite assignment via singleton pattern)
|
|
586
601
|
i(this, "apiClient");
|
|
@@ -591,7 +606,7 @@ const E = new L(), T = class T extends Z {
|
|
|
591
606
|
return;
|
|
592
607
|
const r = t.primaryAgentId || t.agents[0]?.agentId;
|
|
593
608
|
if (r)
|
|
594
|
-
return t.agents.find((
|
|
609
|
+
return t.agents.find((s) => s.agentId === r);
|
|
595
610
|
}));
|
|
596
611
|
i(this, "currentOrg", z(() => {
|
|
597
612
|
const t = this.currentAgent.value;
|
|
@@ -599,7 +614,7 @@ const E = new L(), T = class T extends Z {
|
|
|
599
614
|
return;
|
|
600
615
|
const r = this.activeUser.value;
|
|
601
616
|
if (r?.orgs)
|
|
602
|
-
return r.orgs.find((
|
|
617
|
+
return r.orgs.find((s) => s.orgId === t.orgId);
|
|
603
618
|
}));
|
|
604
619
|
// Initialization state
|
|
605
620
|
i(this, "initialized");
|
|
@@ -613,7 +628,7 @@ const E = new L(), T = class T extends Z {
|
|
|
613
628
|
{ isDev: this.isDev, apiBase: this.apiBase },
|
|
614
629
|
this.processApiResponse.bind(this)
|
|
615
630
|
);
|
|
616
|
-
const
|
|
631
|
+
const s = {
|
|
617
632
|
api: this.api,
|
|
618
633
|
apiBase: this.apiBase,
|
|
619
634
|
isDev: this.isDev,
|
|
@@ -627,12 +642,12 @@ const E = new L(), T = class T extends Z {
|
|
|
627
642
|
logger: this.logger,
|
|
628
643
|
processApiResponse: this.processApiResponse.bind(this)
|
|
629
644
|
};
|
|
630
|
-
this.agent = new
|
|
631
|
-
this.resolveUser =
|
|
632
|
-
}), this.token.value && !this.activeUser.value ? this.getCurrentUser().then((
|
|
633
|
-
this.resolveUser && (this.resolveUser(
|
|
634
|
-
}).catch((
|
|
635
|
-
this.logger.error("Auto user fetch failed", { data:
|
|
645
|
+
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) => {
|
|
646
|
+
this.resolveUser = o;
|
|
647
|
+
}), this.token.value && !this.activeUser.value ? this.getCurrentUser().then((o) => {
|
|
648
|
+
this.resolveUser && (this.resolveUser(o), this.resolveUser = void 0);
|
|
649
|
+
}).catch((o) => {
|
|
650
|
+
this.logger.error("Auto user fetch failed", { data: o }), this.resolveUser && (this.resolveUser(void 0), this.resolveUser = void 0);
|
|
636
651
|
}) : this.activeUser.value ? this.resolveUser?.(this.activeUser.value) : this.resolveUser?.(void 0);
|
|
637
652
|
}
|
|
638
653
|
/**
|
|
@@ -661,7 +676,7 @@ const E = new L(), T = class T extends Z {
|
|
|
661
676
|
}
|
|
662
677
|
// Full reset - clears session + state + destroys singleton
|
|
663
678
|
clear() {
|
|
664
|
-
this.logger.info("Clearing SDK completely"), this.clearSession(), this.loading.value = !1, this.sessionId =
|
|
679
|
+
this.logger.info("Clearing SDK completely"), this.clearSession(), this.loading.value = !1, this.sessionId = $({ prefix: "ses" }), E.delete();
|
|
665
680
|
}
|
|
666
681
|
// Backward-compatible delegates — these forward to sub-clients
|
|
667
682
|
// Can be removed in a future breaking change
|
|
@@ -708,14 +723,14 @@ const E = new L(), T = class T extends Z {
|
|
|
708
723
|
return this.user.track(t);
|
|
709
724
|
}
|
|
710
725
|
};
|
|
711
|
-
|
|
726
|
+
u(T, "PageLinesSDK");
|
|
712
727
|
let H = T;
|
|
713
728
|
export {
|
|
714
|
-
|
|
729
|
+
D as A,
|
|
715
730
|
P as C,
|
|
716
731
|
H as P,
|
|
717
732
|
j as U,
|
|
718
733
|
C as a,
|
|
719
|
-
|
|
734
|
+
p as r
|
|
720
735
|
};
|
|
721
736
|
//# sourceMappingURL=sdkClient.js.map
|