@pluno/product-agent-web 0.1.19 → 0.1.21
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.d.ts +2 -0
- package/dist/product-agent-sdk.js +49 -43
- package/dist/product-agent-widget.js +1038 -622
- package/dist/shareCard.d.ts +29 -0
- package/dist/widget.d.ts +8 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ class q {
|
|
|
6
6
|
...this.state,
|
|
7
7
|
starterPrompts: et(t.initialStarterPrompts)
|
|
8
8
|
};
|
|
9
|
-
const s =
|
|
9
|
+
const s = It(t.clientId);
|
|
10
10
|
s && (this.state = {
|
|
11
11
|
...this.state,
|
|
12
12
|
...s,
|
|
@@ -15,7 +15,7 @@ class q {
|
|
|
15
15
|
assistantDraft: "",
|
|
16
16
|
isThinking: !1,
|
|
17
17
|
lastError: null
|
|
18
|
-
}), this.queuedClientEvents =
|
|
18
|
+
}), this.queuedClientEvents = Et(t.clientId);
|
|
19
19
|
}
|
|
20
20
|
options;
|
|
21
21
|
listeners = {};
|
|
@@ -213,7 +213,7 @@ class q {
|
|
|
213
213
|
}
|
|
214
214
|
if (t.type === "conversation.state") {
|
|
215
215
|
const s = Array.isArray(t.items) ? t.items : [];
|
|
216
|
-
|
|
216
|
+
Tt(s) && this.clearRetryTimers(), this.setState({
|
|
217
217
|
sessionId: P(t.session, "id") ?? this.state.sessionId,
|
|
218
218
|
messages: lt(s),
|
|
219
219
|
...b(s) ? { assistantDraft: "", isThinking: !1 } : {}
|
|
@@ -227,7 +227,7 @@ class q {
|
|
|
227
227
|
if (t.type === "session.item") {
|
|
228
228
|
const s = U(t.item);
|
|
229
229
|
s && (s.role === "assistant" && this.clearRetryTimers(), this.setState({
|
|
230
|
-
messages:
|
|
230
|
+
messages: yt(this.state.messages, s),
|
|
231
231
|
assistantDraft: s.role === "assistant" ? "" : this.state.assistantDraft,
|
|
232
232
|
...I(t.item.data) ? { assistantDraft: "", isThinking: !1 } : {}
|
|
233
233
|
}), I(t.item.data) && this.clearThinkingWatchdog(), this.emit("message", s));
|
|
@@ -338,7 +338,7 @@ class q {
|
|
|
338
338
|
}
|
|
339
339
|
async executeToolCall(t) {
|
|
340
340
|
const s = typeof t.sessionId == "string" ? t.sessionId : null, n = typeof t.callId == "string" ? t.callId : null, r = t.rawInput;
|
|
341
|
-
if (!s || !n || !
|
|
341
|
+
if (!s || !n || !Ct(r))
|
|
342
342
|
return;
|
|
343
343
|
const i = await this.executeRuntimeHelper(), a = await M(r).catch((o) => ({
|
|
344
344
|
ok: !1,
|
|
@@ -369,7 +369,7 @@ class q {
|
|
|
369
369
|
return;
|
|
370
370
|
const t = window.fetch.bind(window), s = XMLHttpRequest.prototype.open, n = XMLHttpRequest.prototype.setRequestHeader, r = XMLHttpRequest.prototype.send;
|
|
371
371
|
window.fetch = async (i, a) => {
|
|
372
|
-
const o = Date.now(), c = new Date(o).toISOString(), u = i instanceof Request ? i : null, y = typeof i == "string" ? i : i instanceof URL ? i.toString() : u?.url ?? "", w = (a?.method ?? u?.method ?? "GET").toUpperCase(), A = O(new Headers(a?.headers ?? u?.headers ?? void 0)), C = await
|
|
372
|
+
const o = Date.now(), c = new Date(o).toISOString(), u = i instanceof Request ? i : null, y = typeof i == "string" ? i : i instanceof URL ? i.toString() : u?.url ?? "", w = (a?.method ?? u?.method ?? "GET").toUpperCase(), A = O(new Headers(a?.headers ?? u?.headers ?? void 0)), C = await Rt(u, a);
|
|
373
373
|
try {
|
|
374
374
|
const d = await t(i, a);
|
|
375
375
|
return this.enqueueNetworkEvent({
|
|
@@ -381,7 +381,7 @@ class q {
|
|
|
381
381
|
resourceType: "fetch",
|
|
382
382
|
responseStatus: d.status,
|
|
383
383
|
responseHeaders: O(d.headers),
|
|
384
|
-
responseBody: await
|
|
384
|
+
responseBody: await Mt(d),
|
|
385
385
|
startedAt: c,
|
|
386
386
|
durationMs: Date.now() - o
|
|
387
387
|
}), d;
|
|
@@ -434,8 +434,8 @@ class q {
|
|
|
434
434
|
requestBody: typeof this.__plunoMeta.requestBody == "string" ? this.__plunoMeta.requestBody : void 0,
|
|
435
435
|
resourceType: "xhr",
|
|
436
436
|
responseStatus: this.status,
|
|
437
|
-
responseHeaders:
|
|
438
|
-
responseBody:
|
|
437
|
+
responseHeaders: Nt(this.getAllResponseHeaders()),
|
|
438
|
+
responseBody: bt(this),
|
|
439
439
|
errorText: this.status === 0 ? "XHR request failed or was aborted" : void 0,
|
|
440
440
|
startedAt: String(this.__plunoMeta.startedAt),
|
|
441
441
|
durationMs: Date.now() - Number(this.__plunoMeta.startedAtMs ?? Date.now())
|
|
@@ -479,7 +479,7 @@ class q {
|
|
|
479
479
|
this.heartbeatTimer !== null && (window.clearInterval(this.heartbeatTimer), this.heartbeatTimer = null);
|
|
480
480
|
}
|
|
481
481
|
setState(t) {
|
|
482
|
-
this.state = { ...this.state, ...t },
|
|
482
|
+
this.state = { ...this.state, ...t }, _t(this.options.clientId, this.state), this.emit("state", this.getState());
|
|
483
483
|
}
|
|
484
484
|
emit(t, s) {
|
|
485
485
|
this.listeners[t]?.forEach((r) => r(s));
|
|
@@ -659,7 +659,7 @@ function U(e) {
|
|
|
659
659
|
return {
|
|
660
660
|
id: String(t.id ?? crypto.randomUUID()),
|
|
661
661
|
role: r,
|
|
662
|
-
content:
|
|
662
|
+
content: ft(n.content),
|
|
663
663
|
createdAt: typeof t.createdAt == "string" ? t.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
|
|
664
664
|
attachments: B(n.attachments)
|
|
665
665
|
};
|
|
@@ -670,6 +670,8 @@ function U(e) {
|
|
|
670
670
|
content: ht(n),
|
|
671
671
|
createdAt: typeof t.createdAt == "string" ? t.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
|
|
672
672
|
dataType: String(n.type),
|
|
673
|
+
toolName: typeof n.name == "string" ? n.name : void 0,
|
|
674
|
+
callId: gt(n) ?? void 0,
|
|
673
675
|
loading: n.localExecutionStatus === "running"
|
|
674
676
|
} : n.type === "run_status" || n.type === "run_error" ? n.type === "run_status" && (n.status === "running" || n.status === "retrying") || n.type === "run_error" && n.stage === "tool_execution" ? null : {
|
|
675
677
|
id: String(t.id ?? crypto.randomUUID()),
|
|
@@ -710,6 +712,10 @@ function pt(e) {
|
|
|
710
712
|
return typeof e.name == "string" && e.name.trim().length > 0 ? e.name : "Run tool";
|
|
711
713
|
}
|
|
712
714
|
function gt(e) {
|
|
715
|
+
const t = e.callId ?? e.call_id;
|
|
716
|
+
return typeof t == "string" && t ? t : null;
|
|
717
|
+
}
|
|
718
|
+
function ft(e) {
|
|
713
719
|
return typeof e == "string" ? e : Array.isArray(e) ? e.map((t) => {
|
|
714
720
|
if (!t || typeof t != "object")
|
|
715
721
|
return "";
|
|
@@ -717,14 +723,14 @@ function gt(e) {
|
|
|
717
723
|
return typeof s.text == "string" ? s.text : typeof s.content == "string" ? s.content : "";
|
|
718
724
|
}).filter(Boolean).join("") : "";
|
|
719
725
|
}
|
|
720
|
-
function
|
|
721
|
-
const s =
|
|
726
|
+
function yt(e, t) {
|
|
727
|
+
const s = mt(e, t), n = s.findIndex((i) => i.id === t.id);
|
|
722
728
|
if (n === -1)
|
|
723
729
|
return _([...s, t]);
|
|
724
730
|
const r = [...s];
|
|
725
731
|
return r[n] = t, _(r);
|
|
726
732
|
}
|
|
727
|
-
function
|
|
733
|
+
function mt(e, t) {
|
|
728
734
|
if (t.role !== "user")
|
|
729
735
|
return e;
|
|
730
736
|
const s = e.findIndex(
|
|
@@ -739,7 +745,7 @@ function b(e) {
|
|
|
739
745
|
const t = W(e);
|
|
740
746
|
return t === null ? !1 : e.slice(t + 1).some((s) => !s || typeof s != "object" ? !1 : I(s.data));
|
|
741
747
|
}
|
|
742
|
-
function
|
|
748
|
+
function Tt(e) {
|
|
743
749
|
const t = W(e);
|
|
744
750
|
return t === null ? e.some((s) => !s || typeof s != "object" ? !1 : N(s.data)) : e.slice(t + 1).some((s) => !s || typeof s != "object" ? !1 : N(s.data));
|
|
745
751
|
}
|
|
@@ -770,12 +776,12 @@ function I(e) {
|
|
|
770
776
|
return t.type === "message" && t.role === "assistant" ? !0 : t.type === "run_error" ? t.stage !== "tool_execution" : t.type === "run_status" && (t.status === "stopped" || t.status === "interrupted");
|
|
771
777
|
}
|
|
772
778
|
function _(e) {
|
|
773
|
-
return e.filter((t, s) =>
|
|
779
|
+
return e.filter((t, s) => St(t) ? !kt(e, s) : !0);
|
|
774
780
|
}
|
|
775
|
-
function
|
|
781
|
+
function St(e) {
|
|
776
782
|
return e.role === "system" && (e.dataType === "run_status" || e.dataType === "run_error");
|
|
777
783
|
}
|
|
778
|
-
function
|
|
784
|
+
function kt(e, t) {
|
|
779
785
|
for (let s = t + 1; s < e.length; s += 1) {
|
|
780
786
|
const n = e[s];
|
|
781
787
|
if (n.role === "user")
|
|
@@ -788,12 +794,12 @@ function St(e, t) {
|
|
|
788
794
|
function P(e, t) {
|
|
789
795
|
return e && typeof e == "object" && typeof e[t] == "string" ? e[t] : null;
|
|
790
796
|
}
|
|
791
|
-
function
|
|
797
|
+
function It(e) {
|
|
792
798
|
try {
|
|
793
799
|
const t = window.localStorage.getItem(`${H}${e}`);
|
|
794
800
|
if (!t)
|
|
795
801
|
return null;
|
|
796
|
-
const s = JSON.parse(t), n = Array.isArray(s.messages) ? s.messages.map(
|
|
802
|
+
const s = JSON.parse(t), n = Array.isArray(s.messages) ? s.messages.map(At).filter((r) => !!r) : [];
|
|
797
803
|
return {
|
|
798
804
|
sessionId: typeof s.sessionId == "string" ? s.sessionId : null,
|
|
799
805
|
messages: n
|
|
@@ -802,7 +808,7 @@ function kt(e) {
|
|
|
802
808
|
return null;
|
|
803
809
|
}
|
|
804
810
|
}
|
|
805
|
-
function
|
|
811
|
+
function _t(e, t) {
|
|
806
812
|
try {
|
|
807
813
|
window.localStorage.setItem(
|
|
808
814
|
`${H}${e}`,
|
|
@@ -815,7 +821,7 @@ function It(e, t) {
|
|
|
815
821
|
return;
|
|
816
822
|
}
|
|
817
823
|
}
|
|
818
|
-
function
|
|
824
|
+
function Et(e) {
|
|
819
825
|
try {
|
|
820
826
|
const t = window.localStorage.getItem(`${k}${e}`);
|
|
821
827
|
if (!t)
|
|
@@ -860,14 +866,14 @@ function B(e) {
|
|
|
860
866
|
if (!s || typeof s != "object")
|
|
861
867
|
return !1;
|
|
862
868
|
const n = s;
|
|
863
|
-
return typeof n.name == "string" &&
|
|
869
|
+
return typeof n.name == "string" && wt(n.mimeType) && typeof n.sizeBytes == "number" && typeof n.dataUrl == "string";
|
|
864
870
|
});
|
|
865
871
|
return t.length > 0 ? t : void 0;
|
|
866
872
|
}
|
|
867
|
-
function
|
|
873
|
+
function wt(e) {
|
|
868
874
|
return e === "image/png" || e === "image/jpeg" || e === "image/webp" || e === "image/gif" || e === "application/pdf";
|
|
869
875
|
}
|
|
870
|
-
function
|
|
876
|
+
function At(e) {
|
|
871
877
|
if (!e || typeof e != "object")
|
|
872
878
|
return null;
|
|
873
879
|
const t = e;
|
|
@@ -881,7 +887,7 @@ function wt(e) {
|
|
|
881
887
|
loading: typeof t.loading == "boolean" ? t.loading : void 0
|
|
882
888
|
};
|
|
883
889
|
}
|
|
884
|
-
function
|
|
890
|
+
function Ct(e) {
|
|
885
891
|
return !!e && typeof e == "object" && typeof e.summary == "string" && typeof e.javascript == "string";
|
|
886
892
|
}
|
|
887
893
|
function O(e) {
|
|
@@ -890,7 +896,7 @@ function O(e) {
|
|
|
890
896
|
t[n] = s;
|
|
891
897
|
}), t;
|
|
892
898
|
}
|
|
893
|
-
async function
|
|
899
|
+
async function Rt(e, t) {
|
|
894
900
|
if (typeof t?.body < "u")
|
|
895
901
|
return L(t.body);
|
|
896
902
|
if (e)
|
|
@@ -900,14 +906,14 @@ async function Ct(e, t) {
|
|
|
900
906
|
return;
|
|
901
907
|
}
|
|
902
908
|
}
|
|
903
|
-
async function
|
|
909
|
+
async function Mt(e) {
|
|
904
910
|
try {
|
|
905
911
|
return p(await e.clone().text());
|
|
906
912
|
} catch (t) {
|
|
907
913
|
return { error: t instanceof Error ? t.message : "unavailable" };
|
|
908
914
|
}
|
|
909
915
|
}
|
|
910
|
-
function
|
|
916
|
+
function bt(e) {
|
|
911
917
|
try {
|
|
912
918
|
return e.responseType === "" || e.responseType === "text" ? p(e.responseText ?? "") : e.responseType === "json" ? p(JSON.stringify(e.response)) : `[unsupported xhr responseType: ${e.responseType || "unknown"}]`;
|
|
913
919
|
} catch (t) {
|
|
@@ -933,7 +939,7 @@ function L(e) {
|
|
|
933
939
|
}
|
|
934
940
|
}
|
|
935
941
|
}
|
|
936
|
-
function
|
|
942
|
+
function Nt(e) {
|
|
937
943
|
const t = {};
|
|
938
944
|
for (const s of e.trim().split(/[\r\n]+/)) {
|
|
939
945
|
const n = s.indexOf(":");
|
|
@@ -947,16 +953,16 @@ function p(e) {
|
|
|
947
953
|
function T(e) {
|
|
948
954
|
return `${e}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
949
955
|
}
|
|
950
|
-
const E = "[REDACTED_SECRET]", h = "[REDACTED_TOKEN]",
|
|
956
|
+
const E = "[REDACTED_SECRET]", h = "[REDACTED_TOKEN]", Pt = "[REDACTED_SIGNED_URL]", Dt = 20, Ot = /^(access_token|accessToken|refresh_token|refreshToken|id_token|idToken|authToken|token|api_key|apiKey|apikey|key|secret|signature|sig|password|passwd|pwd|code|state|session|jwt|csrf|csrfToken|xsrf|xsrfToken)$/i, j = /\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi, G = /\bBasic\s+[A-Za-z0-9+/=-]{12,}/gi, v = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g, $ = /\b(access_token|accessToken|refresh_token|refreshToken|id_token|idToken|authToken|api_key|apiKey|apikey|client_secret|clientSecret|password|secret|token|jwt|csrf|csrfToken|xsrf|xsrfToken)\b\s*[:=]\s*["']?[^"',&\s}]+/gi, Ht = /\bhttps?:\/\/[^\s"'<>]+(?:X-Amz-Signature|X-Goog-Signature|Signature|sig=)[^\s"'<>]*/gi, qt = /\bhttps?:\/\/[^\s"'<>]+/gi, Ut = /[),.;\]]+$/;
|
|
951
957
|
function f(e) {
|
|
952
958
|
return S(e, 0, /* @__PURE__ */ new WeakSet());
|
|
953
959
|
}
|
|
954
960
|
function S(e, t, s) {
|
|
955
961
|
if (typeof e == "string")
|
|
956
|
-
return e.startsWith("data:image/") || e.startsWith("data:application/pdf;") ? e :
|
|
962
|
+
return e.startsWith("data:image/") || e.startsWith("data:application/pdf;") ? e : Bt(e);
|
|
957
963
|
if (e === null || typeof e != "object")
|
|
958
964
|
return e;
|
|
959
|
-
if (t >=
|
|
965
|
+
if (t >= Dt)
|
|
960
966
|
return "[REDACTED_MAX_DEPTH]";
|
|
961
967
|
if (s.has(e))
|
|
962
968
|
return "[REDACTED_CIRCULAR]";
|
|
@@ -964,34 +970,34 @@ function S(e, t, s) {
|
|
|
964
970
|
return e.map((r) => S(r, t + 1, s));
|
|
965
971
|
const n = {};
|
|
966
972
|
for (const [r, i] of Object.entries(e))
|
|
967
|
-
|
|
973
|
+
Wt(r) ? n[r] = E : n[r] = r.toLowerCase() === "url" ? xt(i) : S(i, t + 1, s);
|
|
968
974
|
return n;
|
|
969
975
|
}
|
|
970
|
-
function
|
|
976
|
+
function Wt(e) {
|
|
971
977
|
const t = e.replace(/[^a-z0-9]/gi, "").toLowerCase();
|
|
972
978
|
return t.includes("authorization") || t.includes("cookie") || t.includes("password") || t.includes("passwd") || t === "pwd" || t.includes("secret") || t === "token" || t.endsWith("token") || t.includes("apikey") || t.includes("csrf") || t.includes("xsrf") || t === "jwt" || t === "session" || t === "signature" || t.includes("privatekey");
|
|
973
979
|
}
|
|
974
|
-
function
|
|
980
|
+
function xt(e) {
|
|
975
981
|
return typeof e == "string" ? X(e) : S(e, 0, /* @__PURE__ */ new WeakSet());
|
|
976
982
|
}
|
|
977
983
|
function X(e) {
|
|
978
984
|
try {
|
|
979
985
|
const t = new URL(e, location.href);
|
|
980
986
|
for (const s of Array.from(t.searchParams.keys()))
|
|
981
|
-
|
|
987
|
+
Ot.test(s) && t.searchParams.set(s, h);
|
|
982
988
|
return t.username && (t.username = h), t.password && (t.password = h), t.toString();
|
|
983
989
|
} catch {
|
|
984
|
-
return
|
|
990
|
+
return Lt(e);
|
|
985
991
|
}
|
|
986
992
|
}
|
|
987
|
-
function xt(e) {
|
|
988
|
-
return e.replace(Ot, Nt).replace(Ht, Lt).replace(j, `Bearer ${h}`).replace(G, `Basic ${h}`).replace(v, h).replace($, (t, s) => `${s}: ${E}`);
|
|
989
|
-
}
|
|
990
993
|
function Bt(e) {
|
|
991
|
-
return e.replace(j, `Bearer ${h}`).replace(G, `Basic ${h}`).replace(v, h).replace($, (t, s) => `${s}: ${E}`);
|
|
994
|
+
return e.replace(Ht, Pt).replace(qt, jt).replace(j, `Bearer ${h}`).replace(G, `Basic ${h}`).replace(v, h).replace($, (t, s) => `${s}: ${E}`);
|
|
992
995
|
}
|
|
993
996
|
function Lt(e) {
|
|
994
|
-
|
|
997
|
+
return e.replace(j, `Bearer ${h}`).replace(G, `Basic ${h}`).replace(v, h).replace($, (t, s) => `${s}: ${E}`);
|
|
998
|
+
}
|
|
999
|
+
function jt(e) {
|
|
1000
|
+
const t = e.match(Ut)?.[0] ?? "", s = t ? e.slice(0, -t.length) : e;
|
|
995
1001
|
return `${X(s)}${t}`;
|
|
996
1002
|
}
|
|
997
1003
|
export {
|