@pagelines/sdk 1.0.511 → 1.0.512
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 +371 -394
- 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 +1104 -1076
- 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/ui/ElCreateAgent.vue.d.ts +8 -4
- package/dist/clients/ChatClient.d.ts +3 -0
- package/dist/contract/build.d.ts +3 -2
- package/dist/demo/index.d.ts +4 -2
- package/dist/index.js +21 -21
- package/dist/index.js.map +1 -1
- package/dist/sdkClient.d.ts +28 -14
- package/dist/sdkClient.js +187 -171
- package/dist/sdkClient.js.map +1 -1
- package/dist/widget/composables/useWidgetState.d.ts +12 -6
- package/package.json +1 -1
package/dist/sdkClient.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
import { APP_PORT as
|
|
6
|
-
import { watch as R, ref as E, computed as
|
|
7
|
-
import { hc as
|
|
8
|
-
function
|
|
9
|
-
return
|
|
1
|
+
var Q = Object.defineProperty;
|
|
2
|
+
var te = (i, e, t) => e in i ? Q(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
|
|
3
|
+
var u = (i, e) => Q(i, "name", { value: e, configurable: !0 });
|
|
4
|
+
var c = (i, e, t) => te(i, typeof e != "symbol" ? e + "" : e, t);
|
|
5
|
+
import { APP_PORT as re, APP_PROD_URL as se, createRefreshingFetch as oe, cookieUtil as b, createLogger as ae, shortId as ie, objectId as O, SettingsObject as ne } from "@pagelines/core";
|
|
6
|
+
import { watch as R, ref as E, computed as X } from "vue";
|
|
7
|
+
import { hc as ce } from "hono/client";
|
|
8
|
+
function y(i, e) {
|
|
9
|
+
return i || (e ? `http://localhost:${re}` : se);
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
function
|
|
13
|
-
const r =
|
|
11
|
+
u(y, "resolveApiBase");
|
|
12
|
+
function le(i, e, t) {
|
|
13
|
+
const r = y(i.apiBase, i.isDev), s = t ? oe({
|
|
14
14
|
fetch: globalThis.fetch.bind(globalThis),
|
|
15
15
|
getDeviceId: t.getDeviceId,
|
|
16
16
|
refreshUrl: `${r}/api/auth/refresh`,
|
|
17
17
|
onAccessTokenRefreshed: t.onAccessTokenRefreshed,
|
|
18
18
|
onTerminalFailure: t.onTerminalFailure
|
|
19
19
|
}) : globalThis.fetch.bind(globalThis);
|
|
20
|
-
return
|
|
21
|
-
fetch: /* @__PURE__ */
|
|
22
|
-
const a = b.getAuthToken(),
|
|
20
|
+
return ce(r, {
|
|
21
|
+
fetch: /* @__PURE__ */ u(async (n, g) => {
|
|
22
|
+
const a = b.getAuthToken(), l = await s(n, {
|
|
23
23
|
...g,
|
|
24
24
|
headers: {
|
|
25
25
|
...g?.headers,
|
|
@@ -34,26 +34,26 @@ function ne(l, e, t) {
|
|
|
34
34
|
credentials: "include"
|
|
35
35
|
});
|
|
36
36
|
if (e) {
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
const d = await
|
|
37
|
+
const h = l.json.bind(l);
|
|
38
|
+
l.json = async () => {
|
|
39
|
+
const d = await h();
|
|
40
40
|
return typeof d == "object" && d !== null && "ok" in d && ("user" in d || "token" in d) && e(d), d;
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
|
-
return
|
|
43
|
+
return l;
|
|
44
44
|
}, "fetch")
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
|
-
|
|
48
|
-
const
|
|
47
|
+
u(le, "createApiClient");
|
|
48
|
+
const de = /* @__PURE__ */ Symbol("clean");
|
|
49
49
|
let w = [], I = 0;
|
|
50
|
-
const U = 4,
|
|
50
|
+
const U = 4, ue = globalThis.nanostoresGlobal || (globalThis.nanostoresGlobal = { epoch: 0 }), G = /* @__PURE__ */ u(/* @__NO_SIDE_EFFECTS__ */ (i) => {
|
|
51
51
|
let e = [], t = {
|
|
52
52
|
get() {
|
|
53
53
|
return t.lc || t.listen(() => {
|
|
54
54
|
})(), t.value;
|
|
55
55
|
},
|
|
56
|
-
init:
|
|
56
|
+
init: i,
|
|
57
57
|
lc: 0,
|
|
58
58
|
listen(r) {
|
|
59
59
|
return t.lc = e.push(r), () => {
|
|
@@ -64,10 +64,10 @@ const U = 4, le = globalThis.nanostoresGlobal || (globalThis.nanostoresGlobal =
|
|
|
64
64
|
};
|
|
65
65
|
},
|
|
66
66
|
notify(r, s) {
|
|
67
|
-
|
|
67
|
+
ue.epoch++;
|
|
68
68
|
let o = !w.length;
|
|
69
|
-
for (let
|
|
70
|
-
w.push(
|
|
69
|
+
for (let n of e)
|
|
70
|
+
w.push(n, t.value, r, s);
|
|
71
71
|
if (o) {
|
|
72
72
|
for (I = 0; I < w.length; I += U)
|
|
73
73
|
w[I](
|
|
@@ -90,14 +90,14 @@ const U = 4, le = globalThis.nanostoresGlobal || (globalThis.nanostoresGlobal =
|
|
|
90
90
|
let s = t.listen(r);
|
|
91
91
|
return r(t.value), s;
|
|
92
92
|
},
|
|
93
|
-
value:
|
|
93
|
+
value: i
|
|
94
94
|
};
|
|
95
|
-
return process.env.NODE_ENV !== "production" && (t[
|
|
95
|
+
return process.env.NODE_ENV !== "production" && (t[de] = () => {
|
|
96
96
|
e = [], t.lc = 0, t.off();
|
|
97
97
|
}), t;
|
|
98
|
-
}, "atom"),
|
|
98
|
+
}, "atom"), x = globalThis, T = x.__PL_AUTH_USER__ ?? (x.__PL_AUTH_USER__ = /* @__PURE__ */ G(void 0)), A = x.__PL_AUTH_TOKEN__ ?? (x.__PL_AUTH_TOKEN__ = /* @__PURE__ */ G(null)), $ = x.__PL_AUTH_DEVICE_ID__ ?? (x.__PL_AUTH_DEVICE_ID__ = /* @__PURE__ */ G(null)), z = class z {
|
|
99
99
|
constructor() {
|
|
100
|
-
|
|
100
|
+
c(this, "logger", ae("SDKStorage"));
|
|
101
101
|
}
|
|
102
102
|
/**
|
|
103
103
|
* Check if localStorage is fully functional (some test environments provide partial mocks)
|
|
@@ -109,8 +109,8 @@ const U = 4, le = globalThis.nanostoresGlobal || (globalThis.nanostoresGlobal =
|
|
|
109
109
|
* Sync Vue reactive refs with global nanostores for cross-bundle persistence.
|
|
110
110
|
*/
|
|
111
111
|
syncWithGlobalStores(e) {
|
|
112
|
-
const { activeUser: t, token: r, deviceId: s } = e, o = T.get(),
|
|
113
|
-
o && (t.value = o),
|
|
112
|
+
const { activeUser: t, token: r, deviceId: s } = e, o = T.get(), n = A.get(), g = $.get();
|
|
113
|
+
o && (t.value = o), n && (r.value = n), g && (s.value = g), R(t, (a) => T.set(a), { immediate: !0 }), R(r, (a) => A.set(a), { immediate: !0 }), R(s, (a) => $.set(a), { immediate: !0 }), T.subscribe((a) => {
|
|
114
114
|
a !== t.value && (t.value = a);
|
|
115
115
|
}), A.subscribe((a) => {
|
|
116
116
|
a !== r.value && (r.value = a);
|
|
@@ -188,15 +188,15 @@ const U = 4, le = globalThis.nanostoresGlobal || (globalThis.nanostoresGlobal =
|
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
190
|
};
|
|
191
|
-
|
|
191
|
+
u(z, "SDKStorage");
|
|
192
192
|
let P = z;
|
|
193
|
-
const
|
|
193
|
+
const M = class M {
|
|
194
194
|
constructor(e) {
|
|
195
|
-
|
|
195
|
+
c(this, "ctx");
|
|
196
196
|
this.ctx = e;
|
|
197
197
|
}
|
|
198
198
|
async create(e) {
|
|
199
|
-
const t = e.orgId || this.resolveOrgId(), r =
|
|
199
|
+
const t = e.orgId || this.resolveOrgId(), r = y(this.ctx.apiBase, this.ctx.isDev), o = await (await fetch(`${r}/api/agents`, {
|
|
200
200
|
method: "POST",
|
|
201
201
|
headers: {
|
|
202
202
|
"Content-Type": "application/json",
|
|
@@ -205,13 +205,13 @@ const W = class W {
|
|
|
205
205
|
body: JSON.stringify({ name: e.name, orgId: t })
|
|
206
206
|
})).json();
|
|
207
207
|
if (!o.ok || !o.data?.[0]) {
|
|
208
|
-
const
|
|
209
|
-
throw this.ctx.error.value =
|
|
208
|
+
const n = o.error || "Failed to create agent";
|
|
209
|
+
throw this.ctx.error.value = n, new Error(n);
|
|
210
210
|
}
|
|
211
211
|
return this.ctx.processApiResponse(o), o.data[0];
|
|
212
212
|
}
|
|
213
213
|
async getStatus(e) {
|
|
214
|
-
const t =
|
|
214
|
+
const t = y(this.ctx.apiBase, this.ctx.isDev), s = await (await fetch(`${t}/api/agents/${e.agentId}/status`, {
|
|
215
215
|
headers: {
|
|
216
216
|
...this.ctx.token.value && { Authorization: `Bearer ${this.ctx.token.value}` }
|
|
217
217
|
}
|
|
@@ -228,9 +228,9 @@ const W = class W {
|
|
|
228
228
|
* names to user copy at the call site.
|
|
229
229
|
*/
|
|
230
230
|
async waitUntilReady(e) {
|
|
231
|
-
const { agentId: t, onStatus: r, timeoutMs: s = 3e5, pollIntervalMs: o = 3e3 } = e,
|
|
231
|
+
const { agentId: t, onStatus: r, timeoutMs: s = 3e5, pollIntervalMs: o = 3e3 } = e, n = Date.now();
|
|
232
232
|
let g;
|
|
233
|
-
for (; Date.now() -
|
|
233
|
+
for (; Date.now() - n < s; ) {
|
|
234
234
|
const a = await this.getStatus({ agentId: t });
|
|
235
235
|
if (a.ready) {
|
|
236
236
|
r?.("running");
|
|
@@ -238,13 +238,13 @@ const W = class W {
|
|
|
238
238
|
}
|
|
239
239
|
if (a.status === "error")
|
|
240
240
|
throw new Error(a.error || "Provisioning failed");
|
|
241
|
-
a.status !== g && (r?.(a.status), g = a.status), await new Promise((
|
|
241
|
+
a.status !== g && (r?.(a.status), g = a.status), await new Promise((l) => setTimeout(l, o));
|
|
242
242
|
}
|
|
243
243
|
throw new Error("Agent provisioning timed out — please try again");
|
|
244
244
|
}
|
|
245
245
|
/** Send a typed webhook event to a bot agent. No auth required — the proxy is public. */
|
|
246
246
|
async webhook(e) {
|
|
247
|
-
const r = `${
|
|
247
|
+
const r = `${y(this.ctx.apiBase, this.ctx.isDev)}/api/bot-api/agents/${e.agentId}/webhook`, s = { type: e.type, data: e.data };
|
|
248
248
|
e.meta && (s.meta = e.meta);
|
|
249
249
|
const o = await fetch(r, {
|
|
250
250
|
method: "POST",
|
|
@@ -252,8 +252,8 @@ const W = class W {
|
|
|
252
252
|
body: JSON.stringify(s)
|
|
253
253
|
});
|
|
254
254
|
if (!o.ok) {
|
|
255
|
-
const
|
|
256
|
-
throw new Error(`Webhook delivery failed (${o.status}): ${
|
|
255
|
+
const n = await o.text().catch(() => "Unknown error");
|
|
256
|
+
throw new Error(`Webhook delivery failed (${o.status}): ${n.slice(0, 200)}`);
|
|
257
257
|
}
|
|
258
258
|
return o.json();
|
|
259
259
|
}
|
|
@@ -264,20 +264,20 @@ const W = class W {
|
|
|
264
264
|
return t;
|
|
265
265
|
}
|
|
266
266
|
};
|
|
267
|
-
|
|
268
|
-
let _ =
|
|
269
|
-
async function S(
|
|
270
|
-
|
|
267
|
+
u(M, "AgentClient");
|
|
268
|
+
let _ = M;
|
|
269
|
+
async function S(i, e) {
|
|
270
|
+
i.loading.value = !0, i.error.value = null;
|
|
271
271
|
try {
|
|
272
272
|
return await e();
|
|
273
273
|
} finally {
|
|
274
|
-
|
|
274
|
+
i.loading.value = !1;
|
|
275
275
|
}
|
|
276
276
|
}
|
|
277
|
-
|
|
278
|
-
const
|
|
277
|
+
u(S, "withLoadingState");
|
|
278
|
+
const W = class W {
|
|
279
279
|
constructor(e) {
|
|
280
|
-
|
|
280
|
+
c(this, "ctx");
|
|
281
281
|
this.ctx = e;
|
|
282
282
|
}
|
|
283
283
|
async sendCode(e) {
|
|
@@ -324,7 +324,7 @@ const J = class J {
|
|
|
324
324
|
if (this.ctx.token.value)
|
|
325
325
|
return S(this.ctx, async () => {
|
|
326
326
|
try {
|
|
327
|
-
const e =
|
|
327
|
+
const e = y(this.ctx.apiBase, this.ctx.isDev), r = await (await fetch(`${e}/api/users/me`, {
|
|
328
328
|
method: "GET",
|
|
329
329
|
headers: { Authorization: `Bearer ${this.ctx.token.value}` }
|
|
330
330
|
})).json();
|
|
@@ -368,45 +368,45 @@ const J = class J {
|
|
|
368
368
|
this.ctx.logger.error("loginWithGoogle: Only available in browser");
|
|
369
369
|
return;
|
|
370
370
|
}
|
|
371
|
-
const t =
|
|
371
|
+
const t = y(this.ctx.apiBase, this.ctx.isDev), r = window.location.origin, s = `${t}/auth/google-popup?origin=${encodeURIComponent(r)}`, o = 500, n = 600, g = window.screenX + (window.outerWidth - o) / 2, a = window.screenY + (window.outerHeight - n) / 2, l = window.open(
|
|
372
372
|
s,
|
|
373
373
|
"google-auth",
|
|
374
|
-
`width=${o},height=${
|
|
374
|
+
`width=${o},height=${n},left=${g},top=${a},popup=yes`
|
|
375
375
|
);
|
|
376
|
-
if (!
|
|
377
|
-
const
|
|
378
|
-
this.ctx.error.value =
|
|
376
|
+
if (!l) {
|
|
377
|
+
const p = "Popup was blocked. Please allow popups for this site.";
|
|
378
|
+
this.ctx.error.value = p, e?.onError?.(p);
|
|
379
379
|
return;
|
|
380
380
|
}
|
|
381
|
-
const
|
|
381
|
+
const h = /* @__PURE__ */ u((p) => {
|
|
382
382
|
const k = new URL(t).origin;
|
|
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 =
|
|
383
|
+
if (p.origin === k) {
|
|
384
|
+
if (p.data?.type === "auth-success") {
|
|
385
|
+
window.removeEventListener("message", h);
|
|
386
|
+
const { token: m, user: f } = p.data;
|
|
387
|
+
this.ctx.processApiResponse({ ok: !0, data: {}, token: m, user: f }), this.ctx.logger.info("Google login successful"), e?.onSuccess?.(f);
|
|
388
|
+
} else if (p.data?.type === "auth-error") {
|
|
389
|
+
window.removeEventListener("message", h);
|
|
390
|
+
const m = p.data.error || "Google authentication failed";
|
|
391
|
+
this.ctx.error.value = m, this.ctx.logger.error("Google login failed", { error: m }), e?.onError?.(m);
|
|
392
392
|
}
|
|
393
393
|
}
|
|
394
394
|
}, "handler");
|
|
395
|
-
window.addEventListener("message",
|
|
395
|
+
window.addEventListener("message", h);
|
|
396
396
|
const d = setInterval(() => {
|
|
397
|
-
|
|
397
|
+
l.closed && (clearInterval(d), window.removeEventListener("message", h));
|
|
398
398
|
}, 500);
|
|
399
399
|
}
|
|
400
400
|
};
|
|
401
|
-
|
|
402
|
-
let F =
|
|
403
|
-
const
|
|
401
|
+
u(W, "AuthClient");
|
|
402
|
+
let F = W;
|
|
403
|
+
const J = class J {
|
|
404
404
|
constructor(e) {
|
|
405
|
-
|
|
405
|
+
c(this, "ctx");
|
|
406
406
|
this.ctx = e;
|
|
407
407
|
}
|
|
408
408
|
async startTrial(e) {
|
|
409
|
-
const t = this.resolveOrgId(), r =
|
|
409
|
+
const t = this.resolveOrgId(), r = y(this.ctx.apiBase, this.ctx.isDev), o = await (await fetch(`${r}/api/billing/checkout/create`, {
|
|
410
410
|
method: "POST",
|
|
411
411
|
headers: {
|
|
412
412
|
"Content-Type": "application/json",
|
|
@@ -419,8 +419,8 @@ const q = class q {
|
|
|
419
419
|
})
|
|
420
420
|
})).json();
|
|
421
421
|
if (!o.ok || !o.data?.url) {
|
|
422
|
-
const
|
|
423
|
-
throw this.ctx.error.value =
|
|
422
|
+
const n = o.error || "Failed to create checkout session";
|
|
423
|
+
throw this.ctx.error.value = n, new Error(n);
|
|
424
424
|
}
|
|
425
425
|
window.location.href = o.data.url;
|
|
426
426
|
}
|
|
@@ -428,7 +428,7 @@ const q = class q {
|
|
|
428
428
|
return this.getStatus();
|
|
429
429
|
}
|
|
430
430
|
async getStatus() {
|
|
431
|
-
const e = this.resolveOrgId(), t =
|
|
431
|
+
const e = this.resolveOrgId(), t = y(this.ctx.apiBase, this.ctx.isDev), s = await (await fetch(`${t}/api/billing/details/${e}`, {
|
|
432
432
|
headers: {
|
|
433
433
|
...this.ctx.token.value && { Authorization: `Bearer ${this.ctx.token.value}` }
|
|
434
434
|
}
|
|
@@ -457,16 +457,16 @@ const q = class q {
|
|
|
457
457
|
return t;
|
|
458
458
|
}
|
|
459
459
|
};
|
|
460
|
-
|
|
461
|
-
let j =
|
|
462
|
-
const
|
|
463
|
-
function
|
|
464
|
-
const e =
|
|
460
|
+
u(J, "BillingClient");
|
|
461
|
+
let j = J;
|
|
462
|
+
const he = /* @__PURE__ */ new Set(["message", "message_delta", "working_state", "working_end", "error", "stream_end"]);
|
|
463
|
+
function Y(i) {
|
|
464
|
+
const e = i.split(`
|
|
465
465
|
`).filter((s) => s.length > 0);
|
|
466
466
|
let t, r;
|
|
467
467
|
for (const s of e)
|
|
468
468
|
s.startsWith("event:") ? t = s.slice(6).trim() : s.startsWith("data:") && (r = s.slice(5).trim());
|
|
469
|
-
if (!t || r === void 0 || !
|
|
469
|
+
if (!t || r === void 0 || !he.has(t))
|
|
470
470
|
return null;
|
|
471
471
|
try {
|
|
472
472
|
return { event: t, data: JSON.parse(r) };
|
|
@@ -474,10 +474,22 @@ function X(l) {
|
|
|
474
474
|
return null;
|
|
475
475
|
}
|
|
476
476
|
}
|
|
477
|
-
|
|
478
|
-
|
|
477
|
+
u(Y, "parseChatEvent");
|
|
478
|
+
function Z(i) {
|
|
479
|
+
if (!(i.role !== "assistant" && i.role !== "system"))
|
|
480
|
+
return {
|
|
481
|
+
id: i.messageId,
|
|
482
|
+
text: i.content,
|
|
483
|
+
sender: i.role === "system" ? "system" : "agent",
|
|
484
|
+
timestamp: i.createdAt,
|
|
485
|
+
...i.metadata?.attachments?.length ? { attachments: i.metadata.attachments } : {},
|
|
486
|
+
...i.metadata?.issue ? { issue: i.metadata.issue } : {}
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
u(Z, "toChatMessage");
|
|
490
|
+
const q = class q {
|
|
479
491
|
constructor(e) {
|
|
480
|
-
|
|
492
|
+
c(this, "ctx");
|
|
481
493
|
this.ctx = e;
|
|
482
494
|
}
|
|
483
495
|
/**
|
|
@@ -491,8 +503,8 @@ const M = class M {
|
|
|
491
503
|
* which stores a stable ID in localStorage).
|
|
492
504
|
*/
|
|
493
505
|
async chatStreamPublic(e) {
|
|
494
|
-
const r = `${
|
|
495
|
-
let s = "", o = !1,
|
|
506
|
+
const r = `${y(this.ctx.apiBase, this.ctx.isDev)}/api/agents/public/${encodeURIComponent(e.handle)}/chat/v2/stream`;
|
|
507
|
+
let s = "", o = !1, n = !1, g;
|
|
496
508
|
try {
|
|
497
509
|
const a = await fetch(r, {
|
|
498
510
|
method: "POST",
|
|
@@ -513,20 +525,20 @@ const M = class M {
|
|
|
513
525
|
e.onError("No response stream");
|
|
514
526
|
return;
|
|
515
527
|
}
|
|
516
|
-
const
|
|
517
|
-
let
|
|
528
|
+
const l = new TextDecoder();
|
|
529
|
+
let h = "";
|
|
518
530
|
e: for (; ; ) {
|
|
519
|
-
const { done: d, value:
|
|
531
|
+
const { done: d, value: p } = await g.read();
|
|
520
532
|
if (d)
|
|
521
533
|
break;
|
|
522
|
-
|
|
523
|
-
let k =
|
|
534
|
+
h += l.decode(p, { stream: !0 });
|
|
535
|
+
let k = h.indexOf(`
|
|
524
536
|
|
|
525
537
|
`);
|
|
526
538
|
for (; k !== -1; ) {
|
|
527
|
-
const
|
|
528
|
-
|
|
529
|
-
const f =
|
|
539
|
+
const m = h.slice(0, k);
|
|
540
|
+
h = h.slice(k + 2);
|
|
541
|
+
const f = Y(m);
|
|
530
542
|
if (f) {
|
|
531
543
|
if (f.event === "working_state")
|
|
532
544
|
e.onStatus?.(f.data.description);
|
|
@@ -535,17 +547,19 @@ const M = class M {
|
|
|
535
547
|
else if (f.event === "error") {
|
|
536
548
|
o = !0, e.onError(f.data.message);
|
|
537
549
|
break e;
|
|
538
|
-
} else if (f.event === "message" && (f.data.message.role === "assistant" || f.data.message.role === "system"))
|
|
539
|
-
|
|
540
|
-
|
|
550
|
+
} else if (f.event === "message" && (f.data.message.role === "assistant" || f.data.message.role === "system")) {
|
|
551
|
+
n = !0;
|
|
552
|
+
const v = Z(f.data.message);
|
|
553
|
+
v && e.onMessage?.(v);
|
|
554
|
+
} else if (f.event === "stream_end")
|
|
541
555
|
break e;
|
|
542
556
|
}
|
|
543
|
-
k =
|
|
557
|
+
k = h.indexOf(`
|
|
544
558
|
|
|
545
559
|
`);
|
|
546
560
|
}
|
|
547
561
|
}
|
|
548
|
-
!o &&
|
|
562
|
+
!o && n ? e.onDone(s) : o || e.onError("Stream ended before reply arrived");
|
|
549
563
|
} catch (a) {
|
|
550
564
|
e.onError(a instanceof Error ? a.message : "Stream failed");
|
|
551
565
|
} finally {
|
|
@@ -562,72 +576,74 @@ const M = class M {
|
|
|
562
576
|
* Mirrors `src/modules/agent/client.ts → sendChatMessageStream`.
|
|
563
577
|
*/
|
|
564
578
|
async chatStreamAuthenticated(e) {
|
|
565
|
-
const t =
|
|
579
|
+
const t = y(this.ctx.apiBase, this.ctx.isDev), r = this.ctx.token.value ? { Authorization: `Bearer ${this.ctx.token.value}` } : {}, s = `nonce_${ie(16)}`;
|
|
566
580
|
let o;
|
|
567
581
|
try {
|
|
568
|
-
const
|
|
582
|
+
const l = await fetch(`${t}/api/messages`, {
|
|
569
583
|
method: "POST",
|
|
570
584
|
headers: { "Content-Type": "application/json", ...r },
|
|
571
585
|
body: JSON.stringify({ agentId: e.agentId, content: e.message, clientNonce: s })
|
|
572
|
-
}),
|
|
573
|
-
if (!
|
|
574
|
-
e.onError(
|
|
586
|
+
}), h = await l.json();
|
|
587
|
+
if (!h.ok) {
|
|
588
|
+
e.onError(h.error || `Send failed: HTTP ${l.status}`);
|
|
575
589
|
return;
|
|
576
590
|
}
|
|
577
|
-
o =
|
|
578
|
-
} catch (
|
|
579
|
-
e.onError(
|
|
591
|
+
o = h.data;
|
|
592
|
+
} catch (l) {
|
|
593
|
+
e.onError(l instanceof Error ? l.message : "Send failed");
|
|
580
594
|
return;
|
|
581
595
|
}
|
|
582
|
-
let
|
|
596
|
+
let n = !1, g = !1, a;
|
|
583
597
|
try {
|
|
584
|
-
const
|
|
598
|
+
const l = await fetch(`${t}/api/chat/${encodeURIComponent(e.agentId)}/stream?since=${encodeURIComponent(o.sequence)}`, {
|
|
585
599
|
headers: r
|
|
586
600
|
});
|
|
587
|
-
if (!
|
|
588
|
-
e.onError(`Stream failed: HTTP ${
|
|
601
|
+
if (!l.ok) {
|
|
602
|
+
e.onError(`Stream failed: HTTP ${l.status}`);
|
|
589
603
|
return;
|
|
590
604
|
}
|
|
591
|
-
if (a =
|
|
605
|
+
if (a = l.body?.getReader(), !a) {
|
|
592
606
|
e.onError("No response stream");
|
|
593
607
|
return;
|
|
594
608
|
}
|
|
595
|
-
const
|
|
609
|
+
const h = new TextDecoder();
|
|
596
610
|
let d = "";
|
|
597
611
|
e: for (; ; ) {
|
|
598
|
-
const { done:
|
|
599
|
-
if (
|
|
612
|
+
const { done: p, value: k } = await a.read();
|
|
613
|
+
if (p)
|
|
600
614
|
break;
|
|
601
|
-
d +=
|
|
602
|
-
let
|
|
615
|
+
d += h.decode(k, { stream: !0 });
|
|
616
|
+
let m = d.indexOf(`
|
|
603
617
|
|
|
604
618
|
`);
|
|
605
|
-
for (;
|
|
606
|
-
const f = d.slice(0,
|
|
607
|
-
d = d.slice(
|
|
608
|
-
const
|
|
609
|
-
if (
|
|
610
|
-
if (
|
|
611
|
-
e.onStatus?.(
|
|
612
|
-
else if (
|
|
613
|
-
e.onDelta(
|
|
614
|
-
else if (
|
|
615
|
-
|
|
619
|
+
for (; m !== -1; ) {
|
|
620
|
+
const f = d.slice(0, m);
|
|
621
|
+
d = d.slice(m + 2);
|
|
622
|
+
const v = Y(f);
|
|
623
|
+
if (v) {
|
|
624
|
+
if (v.event === "working_state")
|
|
625
|
+
e.onStatus?.(v.data.description);
|
|
626
|
+
else if (v.event === "message_delta")
|
|
627
|
+
e.onDelta(v.data.delta, v.data.role);
|
|
628
|
+
else if (v.event === "error") {
|
|
629
|
+
n = !0, e.onError(v.data.message);
|
|
616
630
|
break e;
|
|
617
|
-
} else if (
|
|
631
|
+
} else if (v.event === "message" && (v.data.message.role === "assistant" || v.data.message.role === "system")) {
|
|
618
632
|
g = !0;
|
|
633
|
+
const V = Z(v.data.message);
|
|
634
|
+
V && e.onMessage?.(V);
|
|
619
635
|
break e;
|
|
620
|
-
} else if (
|
|
636
|
+
} else if (v.event === "stream_end")
|
|
621
637
|
break e;
|
|
622
638
|
}
|
|
623
|
-
|
|
639
|
+
m = d.indexOf(`
|
|
624
640
|
|
|
625
641
|
`);
|
|
626
642
|
}
|
|
627
643
|
}
|
|
628
|
-
!
|
|
629
|
-
} catch (
|
|
630
|
-
e.onError(
|
|
644
|
+
!n && g ? e.onDone(o.conversationId) : n || e.onError("Stream ended before reply arrived");
|
|
645
|
+
} catch (l) {
|
|
646
|
+
e.onError(l instanceof Error ? l.message : "Stream failed");
|
|
631
647
|
} finally {
|
|
632
648
|
try {
|
|
633
649
|
await a?.cancel();
|
|
@@ -636,11 +652,11 @@ const M = class M {
|
|
|
636
652
|
}
|
|
637
653
|
}
|
|
638
654
|
};
|
|
639
|
-
|
|
640
|
-
let L =
|
|
655
|
+
u(q, "ChatClient");
|
|
656
|
+
let L = q;
|
|
641
657
|
const K = class K {
|
|
642
658
|
constructor(e) {
|
|
643
|
-
|
|
659
|
+
c(this, "ctx");
|
|
644
660
|
this.ctx = e;
|
|
645
661
|
}
|
|
646
662
|
async getPublicAgent(e) {
|
|
@@ -697,11 +713,11 @@ const K = class K {
|
|
|
697
713
|
}
|
|
698
714
|
}
|
|
699
715
|
};
|
|
700
|
-
|
|
716
|
+
u(K, "UserClient");
|
|
701
717
|
let N = K;
|
|
702
718
|
const H = class H {
|
|
703
719
|
constructor() {
|
|
704
|
-
|
|
720
|
+
c(this, "key", "__PAGELINES_SDK__");
|
|
705
721
|
}
|
|
706
722
|
get() {
|
|
707
723
|
if (!(typeof window > "u"))
|
|
@@ -714,33 +730,33 @@ const H = class H {
|
|
|
714
730
|
typeof window < "u" && delete globalThis[this.key];
|
|
715
731
|
}
|
|
716
732
|
};
|
|
717
|
-
|
|
733
|
+
u(H, "SDKGlobal");
|
|
718
734
|
let C = H;
|
|
719
|
-
const D = new C(), B = class B extends
|
|
735
|
+
const D = new C(), B = class B extends ne {
|
|
720
736
|
constructor(t = {}) {
|
|
721
737
|
const r = D.get();
|
|
722
738
|
if (r)
|
|
723
739
|
return console.debug("[PageLinesSDK] Returning existing singleton instance"), r;
|
|
724
740
|
super("PageLinesSDK", t);
|
|
725
741
|
// Vue reactive state
|
|
726
|
-
|
|
727
|
-
|
|
742
|
+
c(this, "activeUser", E());
|
|
743
|
+
c(this, "token", E(null));
|
|
728
744
|
// Refresh credential lives in HttpOnly pl-refresh-token cookie — JS never
|
|
729
745
|
// holds it, so no reactive ref. /api/auth/refresh reads the cookie via the
|
|
730
746
|
// browser's automatic credentials: 'include' attach.
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
747
|
+
c(this, "deviceId", E(null));
|
|
748
|
+
c(this, "loading", E(!1));
|
|
749
|
+
c(this, "error", E(null));
|
|
750
|
+
c(this, "apiBase", this.settings.apiBase || void 0);
|
|
735
751
|
// Storage handler for persistence
|
|
736
|
-
|
|
752
|
+
c(this, "storage", new P());
|
|
737
753
|
// Auto-managed session ID for usage tracking
|
|
738
|
-
|
|
754
|
+
c(this, "sessionId", O({ prefix: "ses" }));
|
|
739
755
|
// Typed Hono RPC client - uses SDKAppType (auth/self/usage routes only)
|
|
740
756
|
// Initialized in constructor (definite assignment via singleton pattern)
|
|
741
|
-
|
|
757
|
+
c(this, "apiClient");
|
|
742
758
|
// Computed properties derived from activeUser (matches UserClient pattern)
|
|
743
|
-
|
|
759
|
+
c(this, "currentAgent", X(() => {
|
|
744
760
|
const t = this.activeUser.value;
|
|
745
761
|
if (!t?.agents)
|
|
746
762
|
return;
|
|
@@ -748,7 +764,7 @@ const D = new C(), B = class B extends ae {
|
|
|
748
764
|
if (r)
|
|
749
765
|
return t.agents.find((s) => s.agentId === r);
|
|
750
766
|
}));
|
|
751
|
-
|
|
767
|
+
c(this, "currentOrg", X(() => {
|
|
752
768
|
const t = this.currentAgent.value;
|
|
753
769
|
if (!t?.orgId)
|
|
754
770
|
return;
|
|
@@ -757,23 +773,23 @@ const D = new C(), B = class B extends ae {
|
|
|
757
773
|
return r.orgs.find((s) => s.orgId === t.orgId);
|
|
758
774
|
}));
|
|
759
775
|
// Initialization state
|
|
760
|
-
|
|
761
|
-
|
|
776
|
+
c(this, "initialized");
|
|
777
|
+
c(this, "resolveUser");
|
|
762
778
|
// Sub-clients (new preferred API surface)
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
D.set(this), this.apiClient =
|
|
779
|
+
c(this, "agent");
|
|
780
|
+
c(this, "auth");
|
|
781
|
+
c(this, "billing");
|
|
782
|
+
c(this, "chat");
|
|
783
|
+
c(this, "user");
|
|
784
|
+
D.set(this), this.apiClient = le(
|
|
769
785
|
{ isDev: this.isDev, apiBase: this.apiBase },
|
|
770
786
|
this.processApiResponse.bind(this),
|
|
771
787
|
{
|
|
772
|
-
getDeviceId: /* @__PURE__ */
|
|
773
|
-
onAccessTokenRefreshed: /* @__PURE__ */
|
|
788
|
+
getDeviceId: /* @__PURE__ */ u(() => this.deviceId.value, "getDeviceId"),
|
|
789
|
+
onAccessTokenRefreshed: /* @__PURE__ */ u((o) => {
|
|
774
790
|
this.token.value = o, this.persistAuth();
|
|
775
791
|
}, "onAccessTokenRefreshed"),
|
|
776
|
-
onTerminalFailure: /* @__PURE__ */
|
|
792
|
+
onTerminalFailure: /* @__PURE__ */ u(() => {
|
|
777
793
|
this.clearSession();
|
|
778
794
|
}, "onTerminalFailure")
|
|
779
795
|
}
|
|
@@ -844,15 +860,15 @@ const D = new C(), B = class B extends ae {
|
|
|
844
860
|
this.logger.info("Clearing SDK completely"), this.clearSession(), this.loading.value = !1, this.sessionId = O({ prefix: "ses" }), D.delete();
|
|
845
861
|
}
|
|
846
862
|
};
|
|
847
|
-
|
|
848
|
-
let
|
|
863
|
+
u(B, "PageLinesSDK");
|
|
864
|
+
let ee = B;
|
|
849
865
|
export {
|
|
850
866
|
_ as A,
|
|
851
867
|
j as B,
|
|
852
868
|
L as C,
|
|
853
|
-
|
|
869
|
+
ee as P,
|
|
854
870
|
N as U,
|
|
855
871
|
F as a,
|
|
856
|
-
|
|
872
|
+
y as r
|
|
857
873
|
};
|
|
858
874
|
//# sourceMappingURL=sdkClient.js.map
|