@pagelines/sdk 1.0.223 → 1.0.225
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-Bm-bqBBB.js → AgentProvider.vue_vue_type_script_setup_true_lang-Cg6HUUjN.js} +2 -2
- package/dist/{AgentProvider.vue_vue_type_script_setup_true_lang-Bm-bqBBB.js.map → AgentProvider.vue_vue_type_script_setup_true_lang-Cg6HUUjN.js.map} +1 -1
- package/dist/{AgentWidgetInline-DGcgpmVf.js → AgentWidgetInline-N6Cgvc9j.js} +2 -2
- package/dist/{AgentWidgetInline-DGcgpmVf.js.map → AgentWidgetInline-N6Cgvc9j.js.map} +1 -1
- package/dist/{AgentWidgetModal-DyWuWxx0.js → AgentWidgetModal-aqLGO-tR.js} +2 -2
- package/dist/{AgentWidgetModal-DyWuWxx0.js.map → AgentWidgetModal-aqLGO-tR.js.map} +1 -1
- package/dist/{AgentWidgetPopup-BNAOA4oM.js → AgentWidgetPopup-BYOIr_SE.js} +2 -2
- package/dist/{AgentWidgetPopup-BNAOA4oM.js.map → AgentWidgetPopup-BYOIr_SE.js.map} +1 -1
- package/dist/{AgentWrap.vue_vue_type_script_setup_true_lang-Bv9-HnDD.js → AgentWrap.vue_vue_type_script_setup_true_lang-BThCK162.js} +2 -2
- package/dist/{AgentWrap.vue_vue_type_script_setup_true_lang-Bv9-HnDD.js.map → AgentWrap.vue_vue_type_script_setup_true_lang-BThCK162.js.map} +1 -1
- package/dist/agent.js +3 -3
- package/dist/api.d.ts +5 -0
- package/dist/sdk.js +1 -1
- package/dist/{sdkClient-IfuVpXGX.js → sdkClient-Cxrx9Fsc.js} +195 -189
- package/dist/sdkClient-Cxrx9Fsc.js.map +1 -0
- package/dist/widget.js +4 -4
- package/package.json +1 -1
- package/dist/sdkClient-IfuVpXGX.js.map +0 -1
package/dist/agent.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
var A = Object.defineProperty;
|
|
2
2
|
var c = (e, r) => A(e, "name", { value: r, configurable: !0 });
|
|
3
|
-
import { _ as C, a as M } from "./AgentWrap.vue_vue_type_script_setup_true_lang-
|
|
4
|
-
import { b as K, A as L, A as Q, E as R } from "./AgentWrap.vue_vue_type_script_setup_true_lang-
|
|
3
|
+
import { _ as C, a as M } from "./AgentWrap.vue_vue_type_script_setup_true_lang-BThCK162.js";
|
|
4
|
+
import { b as K, A as L, A as Q, E as R } from "./AgentWrap.vue_vue_type_script_setup_true_lang-BThCK162.js";
|
|
5
5
|
import { defineComponent as x, createBlock as g, openBlock as l, withCtx as b, createElementVNode as o, createVNode as $, ref as h, watch as z, nextTick as E, createElementBlock as f, createCommentVNode as u, normalizeClass as p, normalizeStyle as N } from "vue";
|
|
6
6
|
import { _ as B } from "./FModal.vue_vue_type_script_setup_true_lang-cL0BFEkZ.js";
|
|
7
|
-
import { _ } from "./AgentProvider.vue_vue_type_script_setup_true_lang-
|
|
7
|
+
import { _ } from "./AgentProvider.vue_vue_type_script_setup_true_lang-Cg6HUUjN.js";
|
|
8
8
|
import { Agent as Y } from "@pagelines/core";
|
|
9
9
|
const T = { class: "relative w-full h-[80vh] md:h-[600px]" }, F = /* @__PURE__ */ x({
|
|
10
10
|
name: "AgentModal",
|
package/dist/api.d.ts
CHANGED
|
@@ -5,6 +5,11 @@ export interface ApiClientSettings {
|
|
|
5
5
|
apiBase?: string;
|
|
6
6
|
[key: string]: unknown;
|
|
7
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* Resolve API base URL from settings.
|
|
10
|
+
* Centralizes the isDev/apiBase/production URL logic used across SDK clients.
|
|
11
|
+
*/
|
|
12
|
+
export declare function resolveApiBase(apiBase?: string, isDev?: boolean): string;
|
|
8
13
|
/**
|
|
9
14
|
* Create fully typed Hono RPC client for PageLines SDK
|
|
10
15
|
*
|
package/dist/sdk.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as t, C as r, P as s, U as o } from "./sdkClient-
|
|
1
|
+
import { A as t, C as r, P as s, U as o } from "./sdkClient-Cxrx9Fsc.js";
|
|
2
2
|
import { MediaSchema as i } from "@pagelines/core";
|
|
3
3
|
import { S as m } from "./socialPlatforms-Ck-b3SnQ.js";
|
|
4
4
|
export {
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
import {
|
|
6
|
-
import { watch as
|
|
7
|
-
import { hc as
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
var N = Object.defineProperty;
|
|
2
|
+
var z = (i, t, e) => t in i ? N(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e;
|
|
3
|
+
var c = (i, t) => N(i, "name", { value: t, configurable: !0 });
|
|
4
|
+
var a = (i, t, e) => z(i, typeof t != "symbol" ? t + "" : t, e);
|
|
5
|
+
import { cookieUtil as x, APP_PORT as H, APP_PROD_URL as K, createLogger as Q, objectId as $, SettingsObject as V } from "@pagelines/core";
|
|
6
|
+
import { watch as M, ref as S, computed as W } from "vue";
|
|
7
|
+
import { hc as X } from "hono/client";
|
|
8
|
+
function T(i, t) {
|
|
9
|
+
return i || (t ? `http://localhost:${H}` : K);
|
|
10
|
+
}
|
|
11
|
+
c(T, "resolveApiBase");
|
|
12
|
+
function Y(i, t) {
|
|
13
|
+
const e = T(i.apiBase, i.isDev);
|
|
14
|
+
return X(e, {
|
|
15
|
+
fetch: /* @__PURE__ */ c(async (o, s) => {
|
|
12
16
|
const g = x.getAuthToken(), d = await fetch(o, {
|
|
13
17
|
...s,
|
|
14
18
|
headers: {
|
|
@@ -23,17 +27,17 @@ function V(n, t) {
|
|
|
23
27
|
if (t) {
|
|
24
28
|
const v = d.json.bind(d);
|
|
25
29
|
d.json = async () => {
|
|
26
|
-
const
|
|
27
|
-
return typeof
|
|
30
|
+
const n = await v();
|
|
31
|
+
return typeof n == "object" && n !== null && "ok" in n && ("user" in n || "token" in n) && t(n), n;
|
|
28
32
|
};
|
|
29
33
|
}
|
|
30
34
|
return d;
|
|
31
35
|
}, "fetch")
|
|
32
36
|
});
|
|
33
37
|
}
|
|
34
|
-
|
|
35
|
-
let
|
|
36
|
-
const
|
|
38
|
+
c(Y, "createApiClient");
|
|
39
|
+
let Z = /* @__PURE__ */ Symbol("clean"), h = [], f = 0;
|
|
40
|
+
const U = 4, J = /* @__PURE__ */ c(/* @__NO_SIDE_EFFECTS__ */ (i) => {
|
|
37
41
|
let t = [], e = {
|
|
38
42
|
get() {
|
|
39
43
|
return e.lc || e.listen(() => {
|
|
@@ -42,8 +46,8 @@ const k = 4, q = /* @__PURE__ */ u(/* @__NO_SIDE_EFFECTS__ */ (n) => {
|
|
|
42
46
|
lc: 0,
|
|
43
47
|
listen(r) {
|
|
44
48
|
return e.lc = t.push(r), () => {
|
|
45
|
-
for (let s = f +
|
|
46
|
-
h[s] === r ? h.splice(s,
|
|
49
|
+
for (let s = f + U; s < h.length; )
|
|
50
|
+
h[s] === r ? h.splice(s, U) : s += U;
|
|
47
51
|
let o = t.indexOf(r);
|
|
48
52
|
~o && (t.splice(o, 1), --e.lc || e.off());
|
|
49
53
|
};
|
|
@@ -53,7 +57,7 @@ const k = 4, q = /* @__PURE__ */ u(/* @__NO_SIDE_EFFECTS__ */ (n) => {
|
|
|
53
57
|
for (let g of t)
|
|
54
58
|
h.push(g, e.value, r, o);
|
|
55
59
|
if (s) {
|
|
56
|
-
for (f = 0; f < h.length; f +=
|
|
60
|
+
for (f = 0; f < h.length; f += U)
|
|
57
61
|
h[f](
|
|
58
62
|
h[f + 1],
|
|
59
63
|
h[f + 2],
|
|
@@ -74,14 +78,14 @@ const k = 4, q = /* @__PURE__ */ u(/* @__NO_SIDE_EFFECTS__ */ (n) => {
|
|
|
74
78
|
let o = e.listen(r);
|
|
75
79
|
return r(e.value), o;
|
|
76
80
|
},
|
|
77
|
-
value:
|
|
81
|
+
value: i
|
|
78
82
|
};
|
|
79
|
-
return process.env.NODE_ENV !== "production" && (e[
|
|
83
|
+
return process.env.NODE_ENV !== "production" && (e[Z] = () => {
|
|
80
84
|
t = [], e.lc = 0, e.off();
|
|
81
85
|
}), e;
|
|
82
|
-
}, "atom"),
|
|
86
|
+
}, "atom"), y = globalThis, b = y.__PL_AUTH_USER__ ?? (y.__PL_AUTH_USER__ = /* @__PURE__ */ J(void 0)), A = y.__PL_AUTH_TOKEN__ ?? (y.__PL_AUTH_TOKEN__ = /* @__PURE__ */ J(null)), R = class R {
|
|
83
87
|
constructor() {
|
|
84
|
-
|
|
88
|
+
a(this, "logger", Q("SDKStorage"));
|
|
85
89
|
}
|
|
86
90
|
/**
|
|
87
91
|
* Check if localStorage is fully functional (some test environments provide partial mocks)
|
|
@@ -93,14 +97,14 @@ const k = 4, q = /* @__PURE__ */ u(/* @__NO_SIDE_EFFECTS__ */ (n) => {
|
|
|
93
97
|
* Sync Vue reactive refs with global nanostores for cross-page persistence
|
|
94
98
|
*/
|
|
95
99
|
syncWithGlobalStores(t, e) {
|
|
96
|
-
const r =
|
|
97
|
-
r && (t.value = r), o && (e.value = o),
|
|
98
|
-
|
|
99
|
-
}, { immediate: !0 }),
|
|
100
|
-
|
|
101
|
-
}, { immediate: !0 }),
|
|
100
|
+
const r = b.get(), o = A.get();
|
|
101
|
+
r && (t.value = r), o && (e.value = o), M(t, (s) => {
|
|
102
|
+
b.set(s);
|
|
103
|
+
}, { immediate: !0 }), M(e, (s) => {
|
|
104
|
+
A.set(s);
|
|
105
|
+
}, { immediate: !0 }), b.subscribe((s) => {
|
|
102
106
|
s !== t.value && (t.value = s);
|
|
103
|
-
}),
|
|
107
|
+
}), A.subscribe((s) => {
|
|
104
108
|
s !== e.value && (e.value = s);
|
|
105
109
|
});
|
|
106
110
|
}
|
|
@@ -141,7 +145,7 @@ const k = 4, q = /* @__PURE__ */ u(/* @__NO_SIDE_EFFECTS__ */ (n) => {
|
|
|
141
145
|
} catch (t) {
|
|
142
146
|
this.logger.error("Failed to clear user from localStorage", { data: t });
|
|
143
147
|
}
|
|
144
|
-
|
|
148
|
+
b.set(void 0), A.set(null);
|
|
145
149
|
}
|
|
146
150
|
}
|
|
147
151
|
/**
|
|
@@ -168,157 +172,159 @@ const k = 4, q = /* @__PURE__ */ u(/* @__NO_SIDE_EFFECTS__ */ (n) => {
|
|
|
168
172
|
}
|
|
169
173
|
}
|
|
170
174
|
};
|
|
171
|
-
|
|
172
|
-
let
|
|
173
|
-
|
|
175
|
+
c(R, "SDKStorage");
|
|
176
|
+
let j = R;
|
|
177
|
+
async function p(i, t) {
|
|
178
|
+
i.loading.value = !0, i.error.value = null;
|
|
179
|
+
try {
|
|
180
|
+
return await t();
|
|
181
|
+
} finally {
|
|
182
|
+
i.loading.value = !1;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
c(p, "withLoadingState");
|
|
186
|
+
const _ = class _ {
|
|
174
187
|
constructor(t) {
|
|
175
188
|
this.ctx = t;
|
|
176
189
|
}
|
|
177
190
|
async sendCode(t) {
|
|
178
|
-
this.ctx
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
191
|
+
return p(this.ctx, async () => {
|
|
192
|
+
try {
|
|
193
|
+
const r = await (await this.ctx.api.auth["check-email"].$post({
|
|
194
|
+
json: { email: t }
|
|
195
|
+
})).json();
|
|
196
|
+
if (!r.ok)
|
|
197
|
+
throw this.ctx.error.value = r.error, new Error(r.error);
|
|
198
|
+
} catch (e) {
|
|
199
|
+
this.ctx.logger.error("Send code error", { data: e });
|
|
200
|
+
const r = e instanceof Error ? e.message : "Failed to send verification code";
|
|
201
|
+
throw this.ctx.error.value = r, e;
|
|
202
|
+
}
|
|
203
|
+
});
|
|
192
204
|
}
|
|
193
205
|
async verifyCode(t, e) {
|
|
194
|
-
this.ctx
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
206
|
+
return p(this.ctx, async () => {
|
|
207
|
+
try {
|
|
208
|
+
const o = await (await this.ctx.api.auth["verify-code"].$post({
|
|
209
|
+
json: { email: t, code: e }
|
|
210
|
+
})).json();
|
|
211
|
+
if (!o.ok)
|
|
212
|
+
throw this.ctx.error.value = o.error, new Error(o.error);
|
|
213
|
+
} catch (r) {
|
|
214
|
+
this.ctx.logger.error("Verify code error", { data: r });
|
|
215
|
+
const o = r instanceof Error ? r.message : "Failed to verify code";
|
|
216
|
+
throw this.ctx.error.value = o, r;
|
|
217
|
+
}
|
|
218
|
+
});
|
|
208
219
|
}
|
|
209
220
|
async login(t, e) {
|
|
210
|
-
this.ctx
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
221
|
+
return p(this.ctx, async () => {
|
|
222
|
+
try {
|
|
223
|
+
const o = await (await this.ctx.api.auth.login.$post({
|
|
224
|
+
json: { email: t, password: e }
|
|
225
|
+
})).json();
|
|
226
|
+
if (!o.ok)
|
|
227
|
+
throw this.ctx.error.value = o.error, new Error(o.error);
|
|
228
|
+
} catch (r) {
|
|
229
|
+
this.ctx.logger.error("Login error", { data: r });
|
|
230
|
+
const o = r instanceof Error ? r.message : "Login failed";
|
|
231
|
+
throw this.ctx.error.value = o, r;
|
|
232
|
+
}
|
|
233
|
+
});
|
|
224
234
|
}
|
|
225
235
|
async logout() {
|
|
226
|
-
this.ctx
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
this.ctx.
|
|
233
|
-
}
|
|
236
|
+
return p(this.ctx, async () => {
|
|
237
|
+
try {
|
|
238
|
+
await this.ctx.api.auth.logout.$post();
|
|
239
|
+
} catch (t) {
|
|
240
|
+
this.ctx.logger.error("Logout error (user still logged out locally)", { data: t });
|
|
241
|
+
}
|
|
242
|
+
this.ctx.activeUser.value = void 0, this.ctx.token.value = null, this.ctx.storage.clearStorage();
|
|
243
|
+
});
|
|
234
244
|
}
|
|
235
245
|
async getCurrentUser() {
|
|
236
|
-
if (this.ctx.token.value)
|
|
237
|
-
this.ctx
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
246
|
+
if (this.ctx.token.value)
|
|
247
|
+
return p(this.ctx, async () => {
|
|
248
|
+
try {
|
|
249
|
+
const e = await (await this.ctx.api.auth.me.$get()).json();
|
|
250
|
+
if (!e.ok) {
|
|
251
|
+
this.ctx.error.value = e.error, e.error.includes("Authentication") && (this.ctx.activeUser.value = void 0, this.ctx.token.value = null, this.ctx.storage.clearStorage());
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
return e.user;
|
|
255
|
+
} catch (t) {
|
|
256
|
+
this.ctx.logger.error("Get current user error", { data: t }), this.ctx.error.value = t instanceof Error ? t.message : "Failed to get user info";
|
|
242
257
|
return;
|
|
243
258
|
}
|
|
244
|
-
|
|
245
|
-
} catch (t) {
|
|
246
|
-
this.ctx.logger.error("Get current user error", { data: t }), this.ctx.error.value = t instanceof Error ? t.message : "Failed to get user info";
|
|
247
|
-
return;
|
|
248
|
-
} finally {
|
|
249
|
-
this.ctx.loading.value = !1;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
259
|
+
});
|
|
252
260
|
}
|
|
253
261
|
async requestAuthCode(t) {
|
|
254
|
-
this.ctx
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
}
|
|
262
|
+
return p(this.ctx, async () => {
|
|
263
|
+
try {
|
|
264
|
+
const r = await (await this.ctx.api.auth["check-email"].$post({
|
|
265
|
+
json: { email: t.email }
|
|
266
|
+
})).json();
|
|
267
|
+
return r.ok ? (this.ctx.logger.info("Auth code requested successfully", { email: t.email }), !0) : (this.ctx.error.value = r.error, this.ctx.logger.error("Failed to request auth code", { email: t.email, error: r.error }), !1);
|
|
268
|
+
} catch (e) {
|
|
269
|
+
return this.ctx.logger.error("Request auth code error", { email: t.email, error: e }), this.ctx.error.value = e instanceof Error ? e.message : "Failed to request auth code", !1;
|
|
270
|
+
}
|
|
271
|
+
});
|
|
265
272
|
}
|
|
266
273
|
async loginWithCode(t) {
|
|
267
|
-
this.ctx
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
}
|
|
274
|
+
return p(this.ctx, async () => {
|
|
275
|
+
try {
|
|
276
|
+
const r = await (await this.ctx.api.auth["verify-code"].$post({
|
|
277
|
+
json: { email: t.email, code: t.code }
|
|
278
|
+
})).json();
|
|
279
|
+
return r.ok ? (this.ctx.logger.info("Login successful", { email: t.email }), !0) : (this.ctx.error.value = r.error, this.ctx.logger.error("Login failed", { email: t.email, error: r.error }), !1);
|
|
280
|
+
} catch (e) {
|
|
281
|
+
return this.ctx.logger.error("Login with code error", { email: t.email, error: e }), this.ctx.error.value = e instanceof Error ? e.message : "Login failed", !1;
|
|
282
|
+
}
|
|
283
|
+
});
|
|
278
284
|
}
|
|
279
285
|
loginWithGoogle(t) {
|
|
280
286
|
if (typeof window > "u") {
|
|
281
287
|
this.ctx.logger.error("loginWithGoogle: Only available in browser");
|
|
282
288
|
return;
|
|
283
289
|
}
|
|
284
|
-
const e = this.ctx.apiBase
|
|
290
|
+
const e = T(this.ctx.apiBase, this.ctx.isDev), r = window.location.origin, o = `${e}/auth/google-popup?origin=${encodeURIComponent(r)}`, s = 500, g = 600, d = window.screenX + (window.outerWidth - s) / 2, v = window.screenY + (window.outerHeight - g) / 2, n = window.open(
|
|
285
291
|
o,
|
|
286
292
|
"google-auth",
|
|
287
293
|
`width=${s},height=${g},left=${d},top=${v},popup=yes`
|
|
288
294
|
);
|
|
289
|
-
if (!
|
|
295
|
+
if (!n) {
|
|
290
296
|
const l = "Popup was blocked. Please allow popups for this site.";
|
|
291
297
|
this.ctx.error.value = l, t?.onError?.(l);
|
|
292
298
|
return;
|
|
293
299
|
}
|
|
294
|
-
const
|
|
295
|
-
const
|
|
296
|
-
if (l.origin ===
|
|
300
|
+
const m = /* @__PURE__ */ c((l) => {
|
|
301
|
+
const k = new URL(e).origin;
|
|
302
|
+
if (l.origin === k) {
|
|
297
303
|
if (l.data?.type === "auth-success") {
|
|
298
|
-
window.removeEventListener("message",
|
|
299
|
-
const { token:
|
|
300
|
-
this.ctx.processApiResponse({ ok: !0, data: {}, token:
|
|
304
|
+
window.removeEventListener("message", m);
|
|
305
|
+
const { token: u, user: w } = l.data;
|
|
306
|
+
this.ctx.processApiResponse({ ok: !0, data: {}, token: u, user: w }), this.ctx.logger.info("Google login successful"), t?.onSuccess?.(w);
|
|
301
307
|
} else if (l.data?.type === "auth-error") {
|
|
302
|
-
window.removeEventListener("message",
|
|
303
|
-
const
|
|
304
|
-
this.ctx.error.value =
|
|
308
|
+
window.removeEventListener("message", m);
|
|
309
|
+
const u = l.data.error || "Google authentication failed";
|
|
310
|
+
this.ctx.error.value = u, this.ctx.logger.error("Google login failed", { error: u }), t?.onError?.(u);
|
|
305
311
|
}
|
|
306
312
|
}
|
|
307
313
|
}, "handler");
|
|
308
|
-
window.addEventListener("message",
|
|
309
|
-
const
|
|
310
|
-
|
|
314
|
+
window.addEventListener("message", m);
|
|
315
|
+
const I = setInterval(() => {
|
|
316
|
+
n.closed && (clearInterval(I), window.removeEventListener("message", m));
|
|
311
317
|
}, 500);
|
|
312
318
|
}
|
|
313
319
|
};
|
|
314
|
-
|
|
315
|
-
let
|
|
316
|
-
const
|
|
320
|
+
c(_, "AuthClient");
|
|
321
|
+
let C = _;
|
|
322
|
+
const D = class D {
|
|
317
323
|
constructor(t) {
|
|
318
324
|
this.ctx = t;
|
|
319
325
|
}
|
|
320
326
|
async chatStream(t) {
|
|
321
|
-
const r = `${this.ctx.apiBase
|
|
327
|
+
const r = `${T(this.ctx.apiBase, this.ctx.isDev)}/api/agent/public/${encodeURIComponent(t.handle)}/chat/stream`;
|
|
322
328
|
try {
|
|
323
329
|
const o = await fetch(r, {
|
|
324
330
|
method: "POST",
|
|
@@ -333,8 +339,8 @@ const R = class R {
|
|
|
333
339
|
})
|
|
334
340
|
});
|
|
335
341
|
if (!o.ok) {
|
|
336
|
-
const
|
|
337
|
-
t.onError(
|
|
342
|
+
const n = await o.json().catch(() => ({ error: "Request failed" }));
|
|
343
|
+
t.onError(n.error || `HTTP ${o.status}`);
|
|
338
344
|
return;
|
|
339
345
|
}
|
|
340
346
|
const s = o.body?.getReader();
|
|
@@ -345,30 +351,30 @@ const R = class R {
|
|
|
345
351
|
const g = new TextDecoder();
|
|
346
352
|
let d = "", v = t.conversationId || "";
|
|
347
353
|
for (; ; ) {
|
|
348
|
-
const { done:
|
|
349
|
-
if (
|
|
354
|
+
const { done: n, value: m } = await s.read();
|
|
355
|
+
if (n)
|
|
350
356
|
break;
|
|
351
|
-
d += g.decode(
|
|
352
|
-
const
|
|
357
|
+
d += g.decode(m, { stream: !0 });
|
|
358
|
+
const I = d.split(`
|
|
353
359
|
`);
|
|
354
|
-
d =
|
|
355
|
-
for (const l of
|
|
360
|
+
d = I.pop() || "";
|
|
361
|
+
for (const l of I) {
|
|
356
362
|
if (!l.startsWith("data: "))
|
|
357
363
|
continue;
|
|
358
|
-
const
|
|
359
|
-
if (
|
|
364
|
+
const k = l.slice(6).trim();
|
|
365
|
+
if (k === "[DONE]") {
|
|
360
366
|
t.onDone(v);
|
|
361
367
|
return;
|
|
362
368
|
}
|
|
363
369
|
try {
|
|
364
|
-
const
|
|
365
|
-
if (
|
|
366
|
-
t.onStatus?.(
|
|
370
|
+
const u = JSON.parse(k);
|
|
371
|
+
if (u.pl_status) {
|
|
372
|
+
t.onStatus?.(u.pl_status);
|
|
367
373
|
continue;
|
|
368
374
|
}
|
|
369
|
-
|
|
370
|
-
const
|
|
371
|
-
|
|
375
|
+
u.pl_metadata?.conversationId && (v = u.pl_metadata.conversationId);
|
|
376
|
+
const w = u.choices?.[0]?.delta;
|
|
377
|
+
w?.content && t.onDelta(w.content);
|
|
372
378
|
} catch {
|
|
373
379
|
}
|
|
374
380
|
}
|
|
@@ -379,7 +385,7 @@ const R = class R {
|
|
|
379
385
|
}
|
|
380
386
|
}
|
|
381
387
|
async chatMessage(t) {
|
|
382
|
-
const r = `${this.ctx.apiBase
|
|
388
|
+
const r = `${T(this.ctx.apiBase, this.ctx.isDev)}/api/agent/public/${encodeURIComponent(t.handle)}/chat`;
|
|
383
389
|
try {
|
|
384
390
|
const s = await (await fetch(r, {
|
|
385
391
|
method: "POST",
|
|
@@ -405,8 +411,8 @@ const R = class R {
|
|
|
405
411
|
}
|
|
406
412
|
}
|
|
407
413
|
};
|
|
408
|
-
|
|
409
|
-
let
|
|
414
|
+
c(D, "ChatClient");
|
|
415
|
+
let P = D;
|
|
410
416
|
const O = class O {
|
|
411
417
|
constructor(t) {
|
|
412
418
|
this.ctx = t;
|
|
@@ -450,7 +456,7 @@ const O = class O {
|
|
|
450
456
|
generateAnonId() {
|
|
451
457
|
const t = "pagelinesAnonId";
|
|
452
458
|
let e = this.ctx.storage.getItem(t);
|
|
453
|
-
return e || (e =
|
|
459
|
+
return e || (e = $({ prefix: "anon" }), this.ctx.storage.setItem(t, e)), e;
|
|
454
460
|
}
|
|
455
461
|
track(t) {
|
|
456
462
|
try {
|
|
@@ -465,11 +471,11 @@ const O = class O {
|
|
|
465
471
|
}
|
|
466
472
|
}
|
|
467
473
|
};
|
|
468
|
-
|
|
474
|
+
c(O, "UserClient");
|
|
469
475
|
let F = O;
|
|
470
476
|
const G = class G {
|
|
471
477
|
constructor() {
|
|
472
|
-
|
|
478
|
+
a(this, "key", "__PAGELINES_SDK__");
|
|
473
479
|
}
|
|
474
480
|
get() {
|
|
475
481
|
if (!(typeof window > "u"))
|
|
@@ -482,29 +488,29 @@ const G = class G {
|
|
|
482
488
|
typeof window < "u" && delete globalThis[this.key];
|
|
483
489
|
}
|
|
484
490
|
};
|
|
485
|
-
|
|
486
|
-
let
|
|
487
|
-
const
|
|
491
|
+
c(G, "SDKGlobal");
|
|
492
|
+
let B = G;
|
|
493
|
+
const E = new B(), L = class L extends V {
|
|
488
494
|
constructor(e = {}) {
|
|
489
|
-
const r =
|
|
495
|
+
const r = E.get();
|
|
490
496
|
if (r)
|
|
491
497
|
return console.debug("[PageLinesSDK] Returning existing singleton instance"), r;
|
|
492
498
|
super("PageLinesSDK", e);
|
|
493
499
|
// Vue reactive state
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
500
|
+
a(this, "activeUser", S());
|
|
501
|
+
a(this, "token", S(null));
|
|
502
|
+
a(this, "loading", S(!1));
|
|
503
|
+
a(this, "error", S(null));
|
|
504
|
+
a(this, "apiBase", this.settings.apiBase || void 0);
|
|
499
505
|
// Storage handler for persistence
|
|
500
|
-
|
|
506
|
+
a(this, "storage", new j());
|
|
501
507
|
// Auto-managed session ID for usage tracking
|
|
502
|
-
|
|
508
|
+
a(this, "sessionId", $({ prefix: "ses" }));
|
|
503
509
|
// Typed Hono RPC client - uses SDKAppType (auth/self/usage routes only)
|
|
504
510
|
// Initialized in constructor (definite assignment via singleton pattern)
|
|
505
|
-
|
|
511
|
+
a(this, "apiClient");
|
|
506
512
|
// Computed properties derived from activeUser (matches UserClient pattern)
|
|
507
|
-
|
|
513
|
+
a(this, "currentAgent", W(() => {
|
|
508
514
|
const e = this.activeUser.value;
|
|
509
515
|
if (!e?.agents)
|
|
510
516
|
return;
|
|
@@ -512,7 +518,7 @@ const b = new P(), $ = class $ extends Q {
|
|
|
512
518
|
if (r)
|
|
513
519
|
return e.agents.find((o) => o.agentId === r);
|
|
514
520
|
}));
|
|
515
|
-
|
|
521
|
+
a(this, "currentOrg", W(() => {
|
|
516
522
|
const e = this.currentAgent.value;
|
|
517
523
|
if (!e?.orgId)
|
|
518
524
|
return;
|
|
@@ -521,13 +527,13 @@ const b = new P(), $ = class $ extends Q {
|
|
|
521
527
|
return r.orgs.find((o) => o.orgId === e.orgId);
|
|
522
528
|
}));
|
|
523
529
|
// Initialization state
|
|
524
|
-
|
|
525
|
-
|
|
530
|
+
a(this, "initialized");
|
|
531
|
+
a(this, "resolveUser");
|
|
526
532
|
// Sub-clients (new preferred API surface)
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
533
|
+
a(this, "auth");
|
|
534
|
+
a(this, "chat");
|
|
535
|
+
a(this, "user");
|
|
536
|
+
E.set(this), this.apiClient = Y(
|
|
531
537
|
{ isDev: this.isDev, apiBase: this.apiBase },
|
|
532
538
|
this.processApiResponse.bind(this)
|
|
533
539
|
);
|
|
@@ -545,7 +551,7 @@ const b = new P(), $ = class $ extends Q {
|
|
|
545
551
|
logger: this.logger,
|
|
546
552
|
processApiResponse: this.processApiResponse.bind(this)
|
|
547
553
|
};
|
|
548
|
-
this.auth = new
|
|
554
|
+
this.auth = new C(o), this.chat = new P(o), this.user = new F(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) => {
|
|
549
555
|
this.resolveUser = s;
|
|
550
556
|
}), this.token.value && !this.activeUser.value ? this.getCurrentUser().then((s) => {
|
|
551
557
|
this.resolveUser && (this.resolveUser(s), this.resolveUser = void 0);
|
|
@@ -559,7 +565,7 @@ const b = new P(), $ = class $ extends Q {
|
|
|
559
565
|
* Recommended: Use this instead of constructor for shared state
|
|
560
566
|
*/
|
|
561
567
|
static getInstance(e = {}) {
|
|
562
|
-
return
|
|
568
|
+
return E.get() || new L(e);
|
|
563
569
|
}
|
|
564
570
|
get isDev() {
|
|
565
571
|
return this.settings.isDev ?? (typeof window < "u" ? window.location.hostname === "localhost" || window.location.hostname.includes("127.0.0.1") : !1);
|
|
@@ -579,7 +585,7 @@ const b = new P(), $ = class $ extends Q {
|
|
|
579
585
|
}
|
|
580
586
|
// Full reset - clears session + state + destroys singleton
|
|
581
587
|
clear() {
|
|
582
|
-
this.logger.info("Clearing SDK completely"), this.clearSession(), this.loading.value = !1, this.sessionId =
|
|
588
|
+
this.logger.info("Clearing SDK completely"), this.clearSession(), this.loading.value = !1, this.sessionId = $({ prefix: "ses" }), E.delete();
|
|
583
589
|
}
|
|
584
590
|
// Backward-compatible delegates — these forward to sub-clients
|
|
585
591
|
// Can be removed in a future breaking change
|
|
@@ -626,12 +632,12 @@ const b = new P(), $ = class $ extends Q {
|
|
|
626
632
|
return this.user.track(e);
|
|
627
633
|
}
|
|
628
634
|
};
|
|
629
|
-
|
|
630
|
-
let
|
|
635
|
+
c(L, "PageLinesSDK");
|
|
636
|
+
let q = L;
|
|
631
637
|
export {
|
|
632
|
-
|
|
633
|
-
C,
|
|
634
|
-
|
|
638
|
+
C as A,
|
|
639
|
+
P as C,
|
|
640
|
+
q as P,
|
|
635
641
|
F as U
|
|
636
642
|
};
|
|
637
|
-
//# sourceMappingURL=sdkClient-
|
|
643
|
+
//# sourceMappingURL=sdkClient-Cxrx9Fsc.js.map
|