@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/AgentProvider.vue_vue_type_script_setup_true_lang.js +706 -635
- package/dist/AgentProvider.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/AgentWrap.vue_vue_type_script_setup_true_lang.js +985 -1023
- package/dist/AgentWrap.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/agent/AgentController.d.ts +0 -10
- package/dist/agent/schema.d.ts +3 -3
- package/dist/agent/ui/ElCreateAgent.vue.d.ts +26 -12
- package/dist/api.d.ts +2 -18
- package/dist/clients/ChatClient.d.ts +5 -3
- package/dist/clients/types.d.ts +1 -5
- package/dist/contract/test/conversation-wire-shapes.unit.test.d.ts +14 -0
- package/dist/demo/index.d.ts +13 -6
- package/dist/index.js +291 -289
- package/dist/index.js.map +1 -1
- package/dist/sdkClient.d.ts +33 -40
- package/dist/sdkClient.js +357 -324
- package/dist/sdkClient.js.map +1 -1
- package/dist/widget/PLWidget.d.ts +1 -0
- package/dist/widget/composables/useWidgetState.d.ts +39 -18
- package/package.json +6 -7
- package/dist/types/SDKAppType.stub.d.ts +0 -6
package/dist/sdkClient.js
CHANGED
|
@@ -1,81 +1,71 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var u = (
|
|
4
|
-
var c = (
|
|
5
|
-
import { APP_PORT as
|
|
6
|
-
import { watch as
|
|
7
|
-
|
|
8
|
-
|
|
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(
|
|
12
|
-
function
|
|
13
|
-
const r =
|
|
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
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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(
|
|
48
|
-
const
|
|
49
|
-
let
|
|
50
|
-
const
|
|
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:
|
|
46
|
+
init: n,
|
|
57
47
|
lc: 0,
|
|
58
48
|
listen(r) {
|
|
59
49
|
return t.lc = e.push(r), () => {
|
|
60
|
-
for (let
|
|
61
|
-
|
|
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
|
-
|
|
68
|
-
let
|
|
69
|
-
for (let
|
|
70
|
-
|
|
71
|
-
if (
|
|
72
|
-
for (
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
-
|
|
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:
|
|
83
|
+
value: n
|
|
94
84
|
};
|
|
95
|
-
return process.env.NODE_ENV !== "production" && (t[
|
|
85
|
+
return process.env.NODE_ENV !== "production" && (t[ke] = () => {
|
|
96
86
|
e = [], t.lc = 0, t.off();
|
|
97
87
|
}), t;
|
|
98
|
-
}, "atom"),
|
|
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",
|
|
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,
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}),
|
|
116
|
-
|
|
117
|
-
}),
|
|
118
|
-
|
|
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 =
|
|
118
|
+
const t = U.getAuthToken();
|
|
129
119
|
t && (e.token.value = t);
|
|
130
|
-
const r =
|
|
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 ?
|
|
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 (
|
|
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
|
-
|
|
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(
|
|
192
|
-
let
|
|
193
|
-
const
|
|
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 =
|
|
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 (!
|
|
208
|
-
const
|
|
209
|
-
throw this.ctx.error.value =
|
|
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(
|
|
201
|
+
return this.ctx.processApiResponse(a), a.data[0];
|
|
212
202
|
}
|
|
213
203
|
async getStatus(e) {
|
|
214
|
-
const t =
|
|
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:
|
|
232
|
-
let
|
|
233
|
-
for (; Date.now() -
|
|
234
|
-
const
|
|
235
|
-
if (
|
|
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 (
|
|
240
|
-
throw new Error(
|
|
241
|
-
|
|
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 = `${
|
|
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
|
|
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 (!
|
|
255
|
-
const
|
|
256
|
-
throw new Error(`Webhook delivery failed (${
|
|
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
|
|
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(
|
|
268
|
-
let
|
|
269
|
-
async function
|
|
270
|
-
|
|
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
|
-
|
|
264
|
+
n.loading.value = !1;
|
|
275
265
|
}
|
|
276
266
|
}
|
|
277
|
-
u(
|
|
278
|
-
const
|
|
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
|
|
274
|
+
return E(this.ctx, async () => {
|
|
285
275
|
try {
|
|
286
|
-
const r = await (await this.ctx.api
|
|
287
|
-
|
|
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
|
|
290
|
+
return E(this.ctx, async () => {
|
|
300
291
|
try {
|
|
301
|
-
const s = await (await this.ctx.api
|
|
302
|
-
|
|
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
|
|
306
|
+
return E(this.ctx, async () => {
|
|
315
307
|
try {
|
|
316
|
-
await this.ctx.api
|
|
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
|
|
317
|
+
return E(this.ctx, async () => {
|
|
326
318
|
try {
|
|
327
|
-
const
|
|
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 (!
|
|
332
|
-
this.ctx.error.value =
|
|
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 =
|
|
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
|
|
334
|
+
return E(this.ctx, async () => {
|
|
344
335
|
try {
|
|
345
|
-
const r = await (await this.ctx.api
|
|
346
|
-
|
|
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
|
|
347
|
+
return E(this.ctx, async () => {
|
|
356
348
|
try {
|
|
357
|
-
const r = await (await this.ctx.api
|
|
358
|
-
|
|
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 =
|
|
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=${
|
|
367
|
+
`width=${a},height=${i},left=${h},top=${o},popup=yes`
|
|
375
368
|
);
|
|
376
|
-
if (!
|
|
377
|
-
const
|
|
378
|
-
this.ctx.error.value =
|
|
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
|
|
382
|
-
const
|
|
383
|
-
if (
|
|
384
|
-
if (
|
|
385
|
-
window.removeEventListener("message",
|
|
386
|
-
const { token:
|
|
387
|
-
this.ctx.processApiResponse({ ok: !0, data: {}, token:
|
|
388
|
-
} else if (
|
|
389
|
-
window.removeEventListener("message",
|
|
390
|
-
const
|
|
391
|
-
this.ctx.error.value =
|
|
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",
|
|
396
|
-
const
|
|
397
|
-
|
|
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(
|
|
402
|
-
let
|
|
403
|
-
const
|
|
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 =
|
|
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 (!
|
|
422
|
-
const
|
|
423
|
-
throw this.ctx.error.value =
|
|
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 =
|
|
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 =
|
|
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
|
|
436
|
+
const a = ["active", "trialing"];
|
|
444
437
|
return {
|
|
445
438
|
plan: s.data.plan,
|
|
446
439
|
status: s.data.status,
|
|
447
|
-
hasActiveBilling:
|
|
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(
|
|
461
|
-
let
|
|
462
|
-
const
|
|
463
|
-
function
|
|
464
|
-
const e =
|
|
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 || !
|
|
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(
|
|
478
|
-
function
|
|
479
|
-
if (!(
|
|
470
|
+
u(ie, "parseChatEvent");
|
|
471
|
+
function ne(n) {
|
|
472
|
+
if (!(n.role !== "assistant" && n.role !== "system"))
|
|
480
473
|
return {
|
|
481
|
-
id:
|
|
482
|
-
text:
|
|
483
|
-
sender:
|
|
484
|
-
timestamp:
|
|
485
|
-
...
|
|
486
|
-
...
|
|
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(
|
|
490
|
-
const
|
|
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 = `${
|
|
507
|
-
let s = "",
|
|
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
|
|
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 (!
|
|
520
|
-
const
|
|
521
|
-
e.onError(
|
|
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 =
|
|
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
|
|
529
|
-
let
|
|
521
|
+
const p = new TextDecoder();
|
|
522
|
+
let g = "";
|
|
530
523
|
e: for (; ; ) {
|
|
531
|
-
const { done:
|
|
532
|
-
if (
|
|
524
|
+
const { done: w, value: l } = await h.read();
|
|
525
|
+
if (w)
|
|
533
526
|
break;
|
|
534
|
-
|
|
535
|
-
let
|
|
527
|
+
g += p.decode(l, { stream: !0 });
|
|
528
|
+
let m = g.indexOf(`
|
|
536
529
|
|
|
537
530
|
`);
|
|
538
|
-
for (;
|
|
539
|
-
const
|
|
540
|
-
|
|
541
|
-
const f =
|
|
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
|
-
|
|
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
|
-
|
|
552
|
-
const
|
|
553
|
-
|
|
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
|
-
|
|
550
|
+
m = g.indexOf(`
|
|
558
551
|
|
|
559
552
|
`);
|
|
560
553
|
}
|
|
561
554
|
}
|
|
562
|
-
!
|
|
563
|
-
} catch (
|
|
564
|
-
e.onError(
|
|
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
|
|
560
|
+
await h?.cancel();
|
|
568
561
|
} catch {
|
|
569
562
|
}
|
|
570
563
|
}
|
|
571
564
|
}
|
|
572
565
|
/**
|
|
573
|
-
* Authenticated chat — substrate-backed
|
|
574
|
-
* /api/
|
|
575
|
-
*
|
|
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 =
|
|
580
|
-
let
|
|
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
|
|
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
|
|
586
|
-
}),
|
|
587
|
-
if (!
|
|
588
|
-
e.onError(
|
|
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
|
-
|
|
592
|
-
} catch (
|
|
593
|
-
e.onError(
|
|
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
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
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
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
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
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
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
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
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(
|
|
656
|
-
let
|
|
657
|
-
const
|
|
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
|
|
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
|
|
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 =
|
|
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(
|
|
717
|
-
let
|
|
718
|
-
const
|
|
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(
|
|
734
|
-
let
|
|
735
|
-
const
|
|
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 =
|
|
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",
|
|
743
|
-
c(this, "token",
|
|
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",
|
|
748
|
-
c(this, "loading",
|
|
749
|
-
c(this, "error",
|
|
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
|
|
794
|
+
c(this, "storage", new J());
|
|
753
795
|
// Auto-managed session ID for usage tracking
|
|
754
|
-
c(this, "sessionId",
|
|
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",
|
|
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",
|
|
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
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
this.
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
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
|
|
812
|
-
this.resolveUser =
|
|
813
|
-
}), this.token.value && !this.activeUser.value ? this.auth.getCurrentUser().then((
|
|
814
|
-
this.resolveUser && (this.resolveUser(
|
|
815
|
-
}).catch((
|
|
816
|
-
this.logger.error("Auto user fetch failed", { data:
|
|
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
|
|
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 =
|
|
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(
|
|
864
|
-
let
|
|
896
|
+
u(L, "PageLinesSDK");
|
|
897
|
+
let ce = L;
|
|
865
898
|
export {
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
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
|