@pagelines/sdk 1.0.429 → 1.0.431
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/index.js +373 -304
- package/dist/index.js.map +1 -1
- package/dist/sdkClient.js +244 -184
- package/dist/sdkClient.js.map +1 -1
- package/package.json +1 -1
package/dist/sdkClient.js
CHANGED
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
import { APP_PORT as
|
|
6
|
-
import { watch as
|
|
7
|
-
import { hc as
|
|
8
|
-
function
|
|
9
|
-
return
|
|
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
|
-
|
|
12
|
-
function
|
|
13
|
-
const t =
|
|
14
|
-
return
|
|
15
|
-
fetch: /* @__PURE__ */
|
|
16
|
-
const
|
|
17
|
-
...
|
|
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
|
-
...
|
|
19
|
+
...s?.headers,
|
|
20
20
|
"Content-Type": "application/json",
|
|
21
21
|
// Only include Authorization header if token exists
|
|
22
|
-
...
|
|
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
|
|
29
|
-
|
|
30
|
-
const c = await
|
|
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
|
|
34
|
+
return h;
|
|
35
35
|
}, "fetch")
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
let
|
|
40
|
-
const
|
|
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:
|
|
46
|
+
init: n,
|
|
47
47
|
lc: 0,
|
|
48
48
|
listen(r) {
|
|
49
49
|
return t.lc = e.push(r), () => {
|
|
50
|
-
for (let
|
|
51
|
-
d[
|
|
52
|
-
let
|
|
53
|
-
~
|
|
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,
|
|
57
|
-
let
|
|
58
|
-
for (let
|
|
59
|
-
d.push(
|
|
60
|
-
if (
|
|
61
|
-
for (f = 0; f < d.length; f +=
|
|
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
|
|
76
|
-
|
|
75
|
+
let o = t.value;
|
|
76
|
+
o !== r && (t.value = r, t.notify(o));
|
|
77
77
|
},
|
|
78
78
|
subscribe(r) {
|
|
79
|
-
let
|
|
80
|
-
return r(t.value),
|
|
79
|
+
let o = t.listen(r);
|
|
80
|
+
return r(t.value), o;
|
|
81
81
|
},
|
|
82
|
-
value:
|
|
82
|
+
value: n
|
|
83
83
|
};
|
|
84
|
-
return process.env.NODE_ENV !== "production" && (t[
|
|
84
|
+
return process.env.NODE_ENV !== "production" && (t[se] = () => {
|
|
85
85
|
e = [], t.lc = 0, t.off();
|
|
86
86
|
}), t;
|
|
87
|
-
}, "atom"), y = globalThis,
|
|
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
|
-
|
|
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 =
|
|
102
|
-
r && (e.value = r),
|
|
103
|
-
|
|
104
|
-
}, { immediate: !0 }),
|
|
105
|
-
U.set(
|
|
106
|
-
}, { immediate: !0 }),
|
|
107
|
-
|
|
108
|
-
}), U.subscribe((
|
|
109
|
-
|
|
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
|
|
122
|
-
|
|
123
|
-
} catch (
|
|
124
|
-
this.logger.error("Failed to load user from localStorage", { data:
|
|
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
|
-
|
|
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
|
-
|
|
176
|
+
l(F, "SDKStorage");
|
|
177
177
|
let B = F;
|
|
178
|
-
const
|
|
178
|
+
const H = [
|
|
179
179
|
"Deploying your server...",
|
|
180
180
|
"Setting up your workspace...",
|
|
181
181
|
"Installing tools...",
|
|
182
182
|
"Almost ready..."
|
|
183
|
-
],
|
|
183
|
+
], L = class L {
|
|
184
184
|
constructor(e) {
|
|
185
|
-
|
|
185
|
+
a(this, "ctx");
|
|
186
186
|
this.ctx = e;
|
|
187
187
|
}
|
|
188
188
|
async create(e) {
|
|
189
|
-
const t = e.orgId || this.resolveOrgId(), r =
|
|
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 (!
|
|
198
|
-
const
|
|
199
|
-
throw this.ctx.error.value =
|
|
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(
|
|
201
|
+
return this.ctx.processApiResponse(s), s.data[0];
|
|
202
202
|
}
|
|
203
203
|
async getStatus(e) {
|
|
204
|
-
const t =
|
|
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 !
|
|
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:
|
|
213
|
-
let
|
|
214
|
-
for (; Date.now() -
|
|
215
|
-
const
|
|
216
|
-
if (
|
|
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 (
|
|
221
|
-
throw new Error(
|
|
222
|
-
r &&
|
|
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 = `${
|
|
229
|
-
e.meta && (
|
|
230
|
-
const
|
|
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(
|
|
233
|
+
body: JSON.stringify(o)
|
|
234
234
|
});
|
|
235
|
-
if (!
|
|
236
|
-
const
|
|
237
|
-
throw new Error(`Webhook delivery failed (${
|
|
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
|
|
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
|
-
|
|
249
|
-
let D =
|
|
250
|
-
async function m(
|
|
251
|
-
|
|
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
|
-
|
|
255
|
+
n.loading.value = !1;
|
|
256
256
|
}
|
|
257
257
|
}
|
|
258
|
-
|
|
259
|
-
const
|
|
258
|
+
l(m, "withLoadingState");
|
|
259
|
+
const _ = class _ {
|
|
260
260
|
constructor(e) {
|
|
261
|
-
|
|
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
|
|
282
|
+
const o = await (await this.ctx.api.auth["verify-code"].$post({
|
|
283
283
|
json: { email: e, code: t }
|
|
284
284
|
})).json();
|
|
285
|
-
if (!
|
|
286
|
-
throw this.ctx.error.value =
|
|
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
|
|
290
|
-
throw this.ctx.error.value =
|
|
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 =
|
|
350
|
-
|
|
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=${
|
|
352
|
+
`width=${s},height=${i},left=${h},top=${p},popup=yes`
|
|
353
353
|
);
|
|
354
354
|
if (!c) {
|
|
355
|
-
const
|
|
356
|
-
this.ctx.error.value =
|
|
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__ */
|
|
359
|
+
const v = /* @__PURE__ */ l((u) => {
|
|
360
360
|
const S = new URL(t).origin;
|
|
361
|
-
if (
|
|
362
|
-
if (
|
|
361
|
+
if (u.origin === S) {
|
|
362
|
+
if (u.data?.type === "auth-success") {
|
|
363
363
|
window.removeEventListener("message", v);
|
|
364
|
-
const { token: w, user:
|
|
365
|
-
this.ctx.processApiResponse({ ok: !0, data: {}, token: w, user:
|
|
366
|
-
} else if (
|
|
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 =
|
|
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
|
-
|
|
380
|
-
let
|
|
381
|
-
const
|
|
379
|
+
l(_, "AuthClient");
|
|
380
|
+
let j = _;
|
|
381
|
+
const N = class N {
|
|
382
382
|
constructor(e) {
|
|
383
|
-
|
|
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 = `${
|
|
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 = `${
|
|
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
|
|
437
|
-
e.onError(
|
|
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
|
|
446
|
-
let
|
|
504
|
+
const o = new TextDecoder();
|
|
505
|
+
let s = "", i = e.conversationId || "";
|
|
447
506
|
for (; ; ) {
|
|
448
|
-
const { done:
|
|
449
|
-
if (
|
|
507
|
+
const { done: h, value: p } = await r.read();
|
|
508
|
+
if (h)
|
|
450
509
|
break;
|
|
451
|
-
|
|
452
|
-
const c =
|
|
510
|
+
s += o.decode(p, { stream: !0 });
|
|
511
|
+
const c = s.split(`
|
|
453
512
|
`);
|
|
454
|
-
|
|
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(
|
|
519
|
+
e.onDone(i);
|
|
461
520
|
return;
|
|
462
521
|
}
|
|
463
522
|
try {
|
|
464
|
-
const
|
|
465
|
-
if (
|
|
466
|
-
e.onStatus?.(
|
|
523
|
+
const u = JSON.parse(I);
|
|
524
|
+
if (u.pl_status) {
|
|
525
|
+
e.onStatus?.(u.pl_status);
|
|
467
526
|
continue;
|
|
468
527
|
}
|
|
469
|
-
|
|
470
|
-
const S =
|
|
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(
|
|
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 = `${
|
|
541
|
+
const r = `${g(this.ctx.apiBase, this.ctx.isDev)}/api/agent/public/${encodeURIComponent(e.handle)}/chat`;
|
|
483
542
|
try {
|
|
484
|
-
const
|
|
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 (!
|
|
495
|
-
this.ctx.logger.error("chatMessage failed", { error: !
|
|
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:
|
|
500
|
-
content:
|
|
558
|
+
conversationId: s.data.conversationId,
|
|
559
|
+
content: s.data.message.content
|
|
501
560
|
};
|
|
502
|
-
} catch (
|
|
503
|
-
this.ctx.logger.error("chatMessage error", { error:
|
|
561
|
+
} catch (o) {
|
|
562
|
+
this.ctx.logger.error("chatMessage error", { error: o });
|
|
504
563
|
return;
|
|
505
564
|
}
|
|
506
565
|
}
|
|
507
566
|
};
|
|
508
|
-
|
|
509
|
-
let
|
|
510
|
-
const
|
|
567
|
+
l(G, "ChatClient");
|
|
568
|
+
let C = G;
|
|
569
|
+
const M = class M {
|
|
511
570
|
constructor(e) {
|
|
512
|
-
|
|
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
|
-
|
|
570
|
-
let
|
|
571
|
-
const
|
|
628
|
+
l(M, "UserClient");
|
|
629
|
+
let O = M;
|
|
630
|
+
const W = class W {
|
|
572
631
|
constructor() {
|
|
573
|
-
|
|
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
|
-
|
|
587
|
-
let
|
|
588
|
-
const E = new
|
|
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
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
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
|
-
|
|
660
|
+
a(this, "storage", new B());
|
|
602
661
|
// Auto-managed session ID for usage tracking
|
|
603
|
-
|
|
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
|
-
|
|
665
|
+
a(this, "apiClient");
|
|
607
666
|
// Computed properties derived from activeUser (matches UserClient pattern)
|
|
608
|
-
|
|
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((
|
|
673
|
+
return t.agents.find((o) => o.agentId === r);
|
|
615
674
|
}));
|
|
616
|
-
|
|
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((
|
|
681
|
+
return r.orgs.find((o) => o.orgId === t.orgId);
|
|
623
682
|
}));
|
|
624
683
|
// Initialization state
|
|
625
|
-
|
|
626
|
-
|
|
684
|
+
a(this, "initialized");
|
|
685
|
+
a(this, "resolveUser");
|
|
627
686
|
// Sub-clients (new preferred API surface)
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
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
|
|
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(
|
|
651
|
-
this.resolveUser =
|
|
652
|
-
}), this.token.value && !this.activeUser.value ? this.getCurrentUser().then((
|
|
653
|
-
this.resolveUser && (this.resolveUser(
|
|
654
|
-
}).catch((
|
|
655
|
-
this.logger.error("Auto user fetch failed", { data:
|
|
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
|
-
|
|
732
|
-
let
|
|
791
|
+
l(T, "PageLinesSDK");
|
|
792
|
+
let Q = T;
|
|
733
793
|
export {
|
|
734
794
|
D as A,
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
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
|