@pagelines/sdk 1.0.573 → 1.0.574
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.map +1 -1
- package/dist/AgentWrap.vue_vue_type_script_setup_true_lang.js +892 -873
- package/dist/AgentWrap.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/agent/AgentController.d.ts +1 -0
- package/dist/agent/schema.d.ts +5 -0
- package/dist/clients/ChatClient.d.ts +2 -0
- package/dist/index.js +1 -1
- package/dist/sdkClient.js +61 -57
- package/dist/sdkClient.js.map +1 -1
- package/package.json +1 -1
package/dist/sdkClient.js
CHANGED
|
@@ -4,12 +4,12 @@ var u = (n, e) => oe(n, "name", { value: e, configurable: !0 });
|
|
|
4
4
|
var c = (n, e, t) => ve(n, typeof e != "symbol" ? e + "" : e, t);
|
|
5
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
6
|
import { watch as N, ref as R, computed as ae } from "vue";
|
|
7
|
-
function
|
|
7
|
+
function k(n, e) {
|
|
8
8
|
return n || (e ? `http://localhost:${pe}` : me);
|
|
9
9
|
}
|
|
10
|
-
u(
|
|
11
|
-
function
|
|
12
|
-
const r =
|
|
10
|
+
u(k, "resolveApiBase");
|
|
11
|
+
function ke(n, e, t) {
|
|
12
|
+
const r = k(n.apiBase, n.isDev), s = t ? ye({
|
|
13
13
|
fetch: globalThis.fetch.bind(globalThis),
|
|
14
14
|
getDeviceId: t.getDeviceId,
|
|
15
15
|
refreshUrl: `${r}/api/auth/refresh`,
|
|
@@ -17,8 +17,8 @@ function Ie(n, e, t) {
|
|
|
17
17
|
onTerminalFailure: t.onTerminalFailure
|
|
18
18
|
}) : globalThis.fetch.bind(globalThis);
|
|
19
19
|
return async (o, i) => {
|
|
20
|
-
const
|
|
21
|
-
a.has("Content-Type") || a.set("Content-Type", "application/json"),
|
|
20
|
+
const f = U.getAuthToken(), a = new Headers(i?.headers);
|
|
21
|
+
a.has("Content-Type") || a.set("Content-Type", "application/json"), f && !a.has("Authorization") && a.set("Authorization", `Bearer ${f}`);
|
|
22
22
|
const p = typeof o == "string" && o.startsWith("/") ? `${r}${o}` : o, g = await s(p, {
|
|
23
23
|
...i,
|
|
24
24
|
headers: a,
|
|
@@ -34,8 +34,8 @@ function Ie(n, e, t) {
|
|
|
34
34
|
return g;
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
|
-
u(
|
|
38
|
-
const
|
|
37
|
+
u(ke, "createApiFetch");
|
|
38
|
+
const Ie = /* @__PURE__ */ Symbol("clean");
|
|
39
39
|
let y = [], b = 0;
|
|
40
40
|
const P = 4, be = globalThis.nanostoresGlobal || (globalThis.nanostoresGlobal = { epoch: 0 }), H = /* @__PURE__ */ u(/* @__NO_SIDE_EFFECTS__ */ (n) => {
|
|
41
41
|
let e = [], t = {
|
|
@@ -82,10 +82,10 @@ const P = 4, be = globalThis.nanostoresGlobal || (globalThis.nanostoresGlobal =
|
|
|
82
82
|
},
|
|
83
83
|
value: n
|
|
84
84
|
};
|
|
85
|
-
return process.env.NODE_ENV !== "production" && (t[
|
|
85
|
+
return process.env.NODE_ENV !== "production" && (t[Ie] = () => {
|
|
86
86
|
e = [], t.lc = 0, t.off();
|
|
87
87
|
}), t;
|
|
88
|
-
}, "atom"),
|
|
88
|
+
}, "atom"), I = globalThis, D = I.__PL_AUTH_USER__ ?? (I.__PL_AUTH_USER__ = /* @__PURE__ */ H(void 0)), B = I.__PL_AUTH_TOKEN__ ?? (I.__PL_AUTH_TOKEN__ = /* @__PURE__ */ H(null)), _ = I.__PL_AUTH_DEVICE_ID__ ?? (I.__PL_AUTH_DEVICE_ID__ = /* @__PURE__ */ H(null)), V = class V {
|
|
89
89
|
constructor() {
|
|
90
90
|
c(this, "logger", we("SDKStorage"));
|
|
91
91
|
}
|
|
@@ -99,8 +99,8 @@ const P = 4, be = globalThis.nanostoresGlobal || (globalThis.nanostoresGlobal =
|
|
|
99
99
|
* Sync Vue reactive refs with global nanostores for cross-bundle persistence.
|
|
100
100
|
*/
|
|
101
101
|
syncWithGlobalStores(e) {
|
|
102
|
-
const { activeUser: t, token: r, deviceId: s } = e, o = D.get(), i = B.get(),
|
|
103
|
-
o && (t.value = o), i && (r.value = i),
|
|
102
|
+
const { activeUser: t, token: r, deviceId: s } = e, o = D.get(), i = B.get(), f = _.get();
|
|
103
|
+
o && (t.value = o), i && (r.value = i), f && (s.value = f), N(t, (a) => D.set(a), { immediate: !0 }), N(r, (a) => B.set(a), { immediate: !0 }), N(s, (a) => _.set(a), { immediate: !0 }), D.subscribe((a) => {
|
|
104
104
|
a !== t.value && (t.value = a);
|
|
105
105
|
}), B.subscribe((a) => {
|
|
106
106
|
a !== r.value && (r.value = a);
|
|
@@ -186,7 +186,7 @@ const Q = class Q {
|
|
|
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 = k(this.ctx.apiBase, this.ctx.isDev), o = await (await fetch(`${r}/api/agents`, {
|
|
190
190
|
method: "POST",
|
|
191
191
|
headers: {
|
|
192
192
|
"Content-Type": "application/json",
|
|
@@ -201,7 +201,7 @@ const Q = class Q {
|
|
|
201
201
|
return this.ctx.processApiResponse(o), o.data[0];
|
|
202
202
|
}
|
|
203
203
|
async getStatus(e) {
|
|
204
|
-
const t =
|
|
204
|
+
const t = k(this.ctx.apiBase, this.ctx.isDev), s = await (await fetch(`${t}/api/agents/${e.agentId}/status`, {
|
|
205
205
|
headers: {
|
|
206
206
|
...this.ctx.token.value && { Authorization: `Bearer ${this.ctx.token.value}` }
|
|
207
207
|
}
|
|
@@ -219,7 +219,7 @@ const Q = class Q {
|
|
|
219
219
|
*/
|
|
220
220
|
async waitUntilReady(e) {
|
|
221
221
|
const { agentId: t, onStatus: r, timeoutMs: s = 3e5, pollIntervalMs: o = 3e3 } = e, i = Date.now();
|
|
222
|
-
let
|
|
222
|
+
let f;
|
|
223
223
|
for (; Date.now() - i < s; ) {
|
|
224
224
|
const a = await this.getStatus({ agentId: t });
|
|
225
225
|
if (a.ready) {
|
|
@@ -228,13 +228,13 @@ const Q = class Q {
|
|
|
228
228
|
}
|
|
229
229
|
if (a.status === "error")
|
|
230
230
|
throw new Error(a.error || "Provisioning failed");
|
|
231
|
-
a.status !==
|
|
231
|
+
a.status !== f && (r?.(a.status), f = a.status), await new Promise((p) => setTimeout(p, o));
|
|
232
232
|
}
|
|
233
233
|
throw new Error("Agent provisioning timed out — please try again");
|
|
234
234
|
}
|
|
235
235
|
/** Send a typed webhook event to a bot agent. No auth required — the proxy is public. */
|
|
236
236
|
async webhook(e) {
|
|
237
|
-
const r = `${
|
|
237
|
+
const r = `${k(this.ctx.apiBase, this.ctx.isDev)}/api/bot-api/webhooks/agents/${e.agentId}`, s = { type: e.type, data: e.data };
|
|
238
238
|
e.meta && (s.meta = e.meta);
|
|
239
239
|
const o = await fetch(r, {
|
|
240
240
|
method: "POST",
|
|
@@ -361,10 +361,10 @@ const X = class X {
|
|
|
361
361
|
this.ctx.logger.error("loginWithGoogle: Only available in browser");
|
|
362
362
|
return;
|
|
363
363
|
}
|
|
364
|
-
const t =
|
|
364
|
+
const t = k(this.ctx.apiBase, this.ctx.isDev), r = window.location.origin, s = `${t}/auth/google-popup?origin=${encodeURIComponent(r)}`, o = 500, i = 600, f = window.screenX + (window.outerWidth - o) / 2, a = window.screenY + (window.outerHeight - i) / 2, p = window.open(
|
|
365
365
|
s,
|
|
366
366
|
"google-auth",
|
|
367
|
-
`width=${o},height=${i},left=${
|
|
367
|
+
`width=${o},height=${i},left=${f},top=${a},popup=yes`
|
|
368
368
|
);
|
|
369
369
|
if (!p) {
|
|
370
370
|
const l = "Popup was blocked. Please allow popups for this site.";
|
|
@@ -376,8 +376,8 @@ const X = class X {
|
|
|
376
376
|
if (l.origin === m) {
|
|
377
377
|
if (l.data?.type === "auth-success") {
|
|
378
378
|
window.removeEventListener("message", g);
|
|
379
|
-
const { token: x, user:
|
|
380
|
-
this.ctx.processApiResponse({ ok: !0, data: {}, token: x, user:
|
|
379
|
+
const { token: x, user: h } = l.data;
|
|
380
|
+
this.ctx.processApiResponse({ ok: !0, data: {}, token: x, user: h }), this.ctx.logger.info("Google login successful"), e?.onSuccess?.(h);
|
|
381
381
|
} else if (l.data?.type === "auth-error") {
|
|
382
382
|
window.removeEventListener("message", g);
|
|
383
383
|
const x = l.data.error || "Google authentication failed";
|
|
@@ -392,14 +392,14 @@ const X = class X {
|
|
|
392
392
|
}
|
|
393
393
|
};
|
|
394
394
|
u(X, "AuthClient");
|
|
395
|
-
let
|
|
395
|
+
let W = X;
|
|
396
396
|
const Y = class Y {
|
|
397
397
|
constructor(e) {
|
|
398
398
|
c(this, "ctx");
|
|
399
399
|
this.ctx = e;
|
|
400
400
|
}
|
|
401
401
|
async startTrial(e) {
|
|
402
|
-
const t = this.resolveOrgId(), r =
|
|
402
|
+
const t = this.resolveOrgId(), r = k(this.ctx.apiBase, this.ctx.isDev), o = await (await fetch(`${r}/api/billing/checkout/create`, {
|
|
403
403
|
method: "POST",
|
|
404
404
|
headers: {
|
|
405
405
|
"Content-Type": "application/json",
|
|
@@ -421,7 +421,7 @@ const Y = class Y {
|
|
|
421
421
|
return this.getStatus();
|
|
422
422
|
}
|
|
423
423
|
async getStatus() {
|
|
424
|
-
const e = this.resolveOrgId(), t =
|
|
424
|
+
const e = this.resolveOrgId(), t = k(this.ctx.apiBase, this.ctx.isDev), s = await (await fetch(`${t}/api/billing/details/${e}`, {
|
|
425
425
|
headers: {
|
|
426
426
|
...this.ctx.token.value && { Authorization: `Bearer ${this.ctx.token.value}` }
|
|
427
427
|
}
|
|
@@ -451,7 +451,7 @@ const Y = class Y {
|
|
|
451
451
|
}
|
|
452
452
|
};
|
|
453
453
|
u(Y, "BillingClient");
|
|
454
|
-
let
|
|
454
|
+
let q = Y;
|
|
455
455
|
const Te = /* @__PURE__ */ new Set(["status", "message", "message_delta", "working_state", "working_end", "error", "stream_end"]);
|
|
456
456
|
function ie(n) {
|
|
457
457
|
const e = n.split(`
|
|
@@ -499,8 +499,8 @@ const Z = class Z {
|
|
|
499
499
|
* which stores a stable ID in localStorage).
|
|
500
500
|
*/
|
|
501
501
|
async chatStreamPublic(e) {
|
|
502
|
-
const r = `${
|
|
503
|
-
let s = "", o = !1, i = !1,
|
|
502
|
+
const r = `${k(this.ctx.apiBase, this.ctx.isDev)}/api/agents/public/${encodeURIComponent(e.handle)}/chat/v2/stream`;
|
|
503
|
+
let s = "", o = !1, i = !1, f;
|
|
504
504
|
try {
|
|
505
505
|
const a = await fetch(r, {
|
|
506
506
|
method: "POST",
|
|
@@ -517,14 +517,14 @@ const Z = class Z {
|
|
|
517
517
|
e.onError(w.error || `HTTP ${a.status}`);
|
|
518
518
|
return;
|
|
519
519
|
}
|
|
520
|
-
if (s = a.headers.get("X-Conversation-Id") || "",
|
|
520
|
+
if (s = a.headers.get("X-Conversation-Id") || "", f = a.body?.getReader(), !f) {
|
|
521
521
|
e.onError("No response stream");
|
|
522
522
|
return;
|
|
523
523
|
}
|
|
524
524
|
const p = new TextDecoder();
|
|
525
525
|
let g = "";
|
|
526
526
|
e: for (; ; ) {
|
|
527
|
-
const { done: w, value: l } = await
|
|
527
|
+
const { done: w, value: l } = await f.read();
|
|
528
528
|
if (w)
|
|
529
529
|
break;
|
|
530
530
|
g += p.decode(l, { stream: !0 });
|
|
@@ -534,20 +534,22 @@ const Z = class Z {
|
|
|
534
534
|
for (; m !== -1; ) {
|
|
535
535
|
const x = g.slice(0, m);
|
|
536
536
|
g = g.slice(m + 2);
|
|
537
|
-
const
|
|
538
|
-
if (
|
|
539
|
-
if (
|
|
540
|
-
e.onStatus?.(
|
|
541
|
-
else if (
|
|
542
|
-
e.
|
|
543
|
-
else if (
|
|
544
|
-
|
|
537
|
+
const h = ie(x);
|
|
538
|
+
if (h) {
|
|
539
|
+
if (h.event === "working_state")
|
|
540
|
+
e.onStatus?.(h.data.description);
|
|
541
|
+
else if (h.event === "working_end")
|
|
542
|
+
e.onWorkingEnd?.();
|
|
543
|
+
else if (h.event === "message_delta")
|
|
544
|
+
e.onDelta(h.data.delta, h.data.role);
|
|
545
|
+
else if (h.event === "error") {
|
|
546
|
+
o = !0, e.onError(h.data.message);
|
|
545
547
|
break e;
|
|
546
|
-
} else if (
|
|
548
|
+
} else if (h.event === "message" && (h.data.message.role === "assistant" || h.data.message.role === "system")) {
|
|
547
549
|
i = !0;
|
|
548
|
-
const A = ne(
|
|
550
|
+
const A = ne(h.data.message);
|
|
549
551
|
A && e.onMessage?.(A);
|
|
550
|
-
} else if (
|
|
552
|
+
} else if (h.event === "stream_end")
|
|
551
553
|
break e;
|
|
552
554
|
}
|
|
553
555
|
m = g.indexOf(`
|
|
@@ -560,7 +562,7 @@ const Z = class Z {
|
|
|
560
562
|
e.onError(a instanceof Error ? a.message : "Stream failed");
|
|
561
563
|
} finally {
|
|
562
564
|
try {
|
|
563
|
-
await
|
|
565
|
+
await f?.cancel();
|
|
564
566
|
} catch {
|
|
565
567
|
}
|
|
566
568
|
}
|
|
@@ -574,7 +576,7 @@ const Z = class Z {
|
|
|
574
576
|
* Mirrors `src/modules/agent/client.ts → sendChatMessageStream`.
|
|
575
577
|
*/
|
|
576
578
|
async chatStreamAuthenticated(e) {
|
|
577
|
-
const t =
|
|
579
|
+
const t = k(this.ctx.apiBase, this.ctx.isDev), r = this.ctx.token.value ? { Authorization: `Bearer ${this.ctx.token.value}` } : {};
|
|
578
580
|
let s, o = null;
|
|
579
581
|
try {
|
|
580
582
|
const d = await fetch(`${t}/api/conversations`, {
|
|
@@ -591,19 +593,19 @@ const Z = class Z {
|
|
|
591
593
|
e.onError(d instanceof Error ? d.message : "Conversation failed");
|
|
592
594
|
return;
|
|
593
595
|
}
|
|
594
|
-
let i = !1,
|
|
596
|
+
let i = !1, f = !1, a = !1, p = !1, g = !1, w = !1, l;
|
|
595
597
|
const m = new AbortController();
|
|
596
|
-
let x = !1,
|
|
598
|
+
let x = !1, h, A = /* @__PURE__ */ u(() => {
|
|
597
599
|
}, "resolveStreamReady");
|
|
598
600
|
const le = new Promise((d) => {
|
|
599
601
|
A = d;
|
|
600
602
|
}), $ = /* @__PURE__ */ u((d) => {
|
|
601
|
-
x || (x = !0,
|
|
603
|
+
x || (x = !0, h && clearTimeout(h), A(d));
|
|
602
604
|
}, "settleStreamReady"), re = /* @__PURE__ */ u(() => {
|
|
603
605
|
l?.cancel().catch(() => {
|
|
604
606
|
});
|
|
605
607
|
}, "cancelReader"), de = o ? `${t}/api/conversations/${encodeURIComponent(s)}/stream?since=${encodeURIComponent(o)}` : `${t}/api/conversations/${encodeURIComponent(s)}/stream`;
|
|
606
|
-
|
|
608
|
+
h = setTimeout(() => {
|
|
607
609
|
w = !0, a = !0, e.onError("Timed out opening stream"), m.abort(), $("failed");
|
|
608
610
|
}, 1e4);
|
|
609
611
|
const O = (async () => {
|
|
@@ -638,6 +640,8 @@ const Z = class Z {
|
|
|
638
640
|
if (v) {
|
|
639
641
|
if (v.event === "working_state")
|
|
640
642
|
i && e.onStatus?.(v.data.description);
|
|
643
|
+
else if (v.event === "working_end")
|
|
644
|
+
i && e.onWorkingEnd?.();
|
|
641
645
|
else if (v.event === "message_delta")
|
|
642
646
|
i && e.onDelta(v.data.delta, v.data.role);
|
|
643
647
|
else if (v.event === "error") {
|
|
@@ -658,9 +662,9 @@ const Z = class Z {
|
|
|
658
662
|
`);
|
|
659
663
|
}
|
|
660
664
|
}
|
|
661
|
-
!a && p ? e.onDone(s) : !a && i && !
|
|
665
|
+
!a && p ? e.onDone(s) : !a && i && !f && e.onError("Stream ended before reply arrived");
|
|
662
666
|
} catch (d) {
|
|
663
|
-
!
|
|
667
|
+
!f && !w && (a = !0, $("failed"), e.onError(d instanceof Error ? d.message : "Stream failed"));
|
|
664
668
|
} finally {
|
|
665
669
|
g = !0;
|
|
666
670
|
try {
|
|
@@ -691,18 +695,18 @@ const Z = class Z {
|
|
|
691
695
|
})
|
|
692
696
|
}), S = await d.json();
|
|
693
697
|
if (!S.ok) {
|
|
694
|
-
|
|
698
|
+
f = !0, m.abort(), re(), e.onError(S.error || `Send failed: HTTP ${d.status}`), await O;
|
|
695
699
|
return;
|
|
696
700
|
}
|
|
697
701
|
} catch (d) {
|
|
698
|
-
|
|
702
|
+
f = !0, m.abort(), re(), e.onError(d instanceof Error ? d.message : "Send failed"), await O;
|
|
699
703
|
return;
|
|
700
704
|
}
|
|
701
705
|
await O;
|
|
702
706
|
}
|
|
703
707
|
};
|
|
704
708
|
u(Z, "ChatClient");
|
|
705
|
-
let
|
|
709
|
+
let z = Z;
|
|
706
710
|
const ee = class ee {
|
|
707
711
|
constructor(e) {
|
|
708
712
|
c(this, "ctx");
|
|
@@ -825,7 +829,7 @@ const j = new K(), L = class L extends Se {
|
|
|
825
829
|
c(this, "user");
|
|
826
830
|
j.set(this);
|
|
827
831
|
const o = {
|
|
828
|
-
apiFetch:
|
|
832
|
+
apiFetch: ke(
|
|
829
833
|
{ isDev: this.isDev, apiBase: this.apiBase },
|
|
830
834
|
this.processApiResponse.bind(this),
|
|
831
835
|
{
|
|
@@ -850,7 +854,7 @@ const j = new K(), L = class L extends Se {
|
|
|
850
854
|
logger: this.logger,
|
|
851
855
|
processApiResponse: this.processApiResponse.bind(this)
|
|
852
856
|
};
|
|
853
|
-
this.agent = new G(o), this.auth = new
|
|
857
|
+
this.agent = new G(o), this.auth = new W(o), this.billing = new q(o), this.chat = new z(o), this.user = new M(o), this.logger.info("PageLinesSDK initialized"), this.storage.loadFromStorage(this.authRefs()), this.storage.syncWithGlobalStores(this.authRefs()), this.initialized = new Promise((i) => {
|
|
854
858
|
this.resolveUser = i;
|
|
855
859
|
}), this.token.value && !this.activeUser.value ? this.auth.getCurrentUser().then((i) => {
|
|
856
860
|
this.resolveUser && (this.resolveUser(i), this.resolveUser = void 0);
|
|
@@ -900,11 +904,11 @@ u(L, "PageLinesSDK");
|
|
|
900
904
|
let ce = L;
|
|
901
905
|
export {
|
|
902
906
|
G as A,
|
|
903
|
-
|
|
904
|
-
|
|
907
|
+
q as B,
|
|
908
|
+
z as C,
|
|
905
909
|
ce as P,
|
|
906
910
|
M as U,
|
|
907
|
-
|
|
908
|
-
|
|
911
|
+
W as a,
|
|
912
|
+
k as r
|
|
909
913
|
};
|
|
910
914
|
//# sourceMappingURL=sdkClient.js.map
|