@pluno/product-agent-web 0.1.7 → 0.1.8
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/product-agent-sdk.js +115 -97
- package/package.json +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
class
|
|
1
|
+
const x = "https://app.pluno.ai";
|
|
2
|
+
const R = "pluno.productAgent.state.";
|
|
3
|
+
class M {
|
|
4
4
|
constructor(t) {
|
|
5
5
|
this.options = t;
|
|
6
|
-
const s =
|
|
6
|
+
const s = ot(t.clientId);
|
|
7
7
|
s && (this.state = {
|
|
8
8
|
...this.state,
|
|
9
9
|
...s,
|
|
@@ -37,10 +37,10 @@ class R {
|
|
|
37
37
|
lastError: null
|
|
38
38
|
};
|
|
39
39
|
static async init(t) {
|
|
40
|
-
const s = new
|
|
40
|
+
const s = new M({
|
|
41
41
|
...t,
|
|
42
|
-
backendUrl:
|
|
43
|
-
clientId: t.clientId ??
|
|
42
|
+
backendUrl: B(t.backendUrl ?? x),
|
|
43
|
+
clientId: t.clientId ?? J()
|
|
44
44
|
});
|
|
45
45
|
try {
|
|
46
46
|
s.enableNetworkCapture(), t.autoConnect !== !1 && await s.connect();
|
|
@@ -65,10 +65,10 @@ class R {
|
|
|
65
65
|
return;
|
|
66
66
|
if (this.setState({ status: (this.state.status === "closed", "connecting"), lastError: null }), this.token = this.options.token ?? await this.options.tokenProvider?.() ?? null, !this.token && !this.options.webSocketFactory)
|
|
67
67
|
throw new Error("Product Agent requires a token or tokenProvider");
|
|
68
|
-
const t =
|
|
68
|
+
const t = L(this.options.backendUrl);
|
|
69
69
|
this.socket = this.options.webSocketFactory?.(t) ?? new WebSocket(t), this.socket.addEventListener("open", () => {
|
|
70
70
|
this.token && this.sendNow({ type: "auth.session", token: this.token, clientId: this.options.clientId }), this.flushQueuedClientEvents(), this.startHeartbeat(), this.setState({ status: "connected", lastError: null });
|
|
71
|
-
}), this.socket.addEventListener("message", (s) => this.handleServerEvent(
|
|
71
|
+
}), this.socket.addEventListener("message", (s) => this.handleServerEvent(j(s.data))), this.socket.addEventListener("close", () => {
|
|
72
72
|
this.stopHeartbeat(), this.socket = null, this.state.status !== "closed" && (this.setState({ status: "reconnecting" }), this.scheduleReconnect());
|
|
73
73
|
}), this.socket.addEventListener("error", () => {
|
|
74
74
|
this.setState({ status: "error", lastError: "Product Agent connection failed" });
|
|
@@ -86,7 +86,7 @@ class R {
|
|
|
86
86
|
const s = t.trim();
|
|
87
87
|
if (!s)
|
|
88
88
|
return;
|
|
89
|
-
const r = g(), n =
|
|
89
|
+
const r = g(), n = G(), i = {
|
|
90
90
|
id: `local-${n}`,
|
|
91
91
|
role: "user",
|
|
92
92
|
content: s,
|
|
@@ -144,9 +144,9 @@ class R {
|
|
|
144
144
|
}
|
|
145
145
|
handleServerEvent(t) {
|
|
146
146
|
if (t.type === "auth.ok") {
|
|
147
|
-
this.runtimeHelperJavascript =
|
|
148
|
-
user:
|
|
149
|
-
starterPrompts:
|
|
147
|
+
this.runtimeHelperJavascript = X(t.runtimeHelpers)?.javascript ?? null, this.setState({
|
|
148
|
+
user: W(t.user),
|
|
149
|
+
starterPrompts: $(t, "starterPrompts"),
|
|
150
150
|
status: "connected"
|
|
151
151
|
}), this.state.sessionId && this.send({
|
|
152
152
|
type: "page.upsert",
|
|
@@ -159,22 +159,22 @@ class R {
|
|
|
159
159
|
if (t.type === "conversation.state") {
|
|
160
160
|
const s = Array.isArray(t.items) ? t.items : [];
|
|
161
161
|
this.setState({
|
|
162
|
-
sessionId:
|
|
163
|
-
messages:
|
|
164
|
-
...
|
|
162
|
+
sessionId: I(t.session, "id") ?? this.state.sessionId,
|
|
163
|
+
messages: v(s),
|
|
164
|
+
...et(s) ? { assistantDraft: "", isThinking: !1 } : {}
|
|
165
165
|
});
|
|
166
166
|
return;
|
|
167
167
|
}
|
|
168
168
|
if (t.type === "session.updated") {
|
|
169
|
-
this.setState({ sessionId:
|
|
169
|
+
this.setState({ sessionId: I(t.session, "id") ?? this.state.sessionId });
|
|
170
170
|
return;
|
|
171
171
|
}
|
|
172
172
|
if (t.type === "session.item") {
|
|
173
173
|
const s = C(t.item);
|
|
174
174
|
s && (this.setState({
|
|
175
|
-
messages:
|
|
175
|
+
messages: Q(this.state.messages, s),
|
|
176
176
|
assistantDraft: s.role === "assistant" ? "" : this.state.assistantDraft,
|
|
177
|
-
...
|
|
177
|
+
...D(t.item.data) ? { assistantDraft: "", isThinking: !1 } : {}
|
|
178
178
|
}), this.emit("message", s));
|
|
179
179
|
return;
|
|
180
180
|
}
|
|
@@ -218,9 +218,9 @@ class R {
|
|
|
218
218
|
}
|
|
219
219
|
async executeToolCall(t) {
|
|
220
220
|
const s = typeof t.sessionId == "string" ? t.sessionId : null, r = typeof t.callId == "string" ? t.callId : null, n = t.rawInput;
|
|
221
|
-
if (!s || !r || !
|
|
221
|
+
if (!s || !r || !ct(n))
|
|
222
222
|
return;
|
|
223
|
-
const i = await this.executeRuntimeHelper(), a = await
|
|
223
|
+
const i = await this.executeRuntimeHelper(), a = await A(n).catch((o) => ({
|
|
224
224
|
ok: !1,
|
|
225
225
|
exception: {
|
|
226
226
|
message: o instanceof Error ? o.message : String(o)
|
|
@@ -233,35 +233,35 @@ class R {
|
|
|
233
233
|
toolName: "execute_code",
|
|
234
234
|
summary: n.summary,
|
|
235
235
|
rawInput: f(n),
|
|
236
|
-
rawOutput: f(
|
|
236
|
+
rawOutput: f(z(a, i))
|
|
237
237
|
});
|
|
238
238
|
}
|
|
239
239
|
async executeRuntimeHelper() {
|
|
240
240
|
if (!this.runtimeHelperJavascript?.trim())
|
|
241
241
|
return null;
|
|
242
|
-
const t = await
|
|
242
|
+
const t = await A({
|
|
243
243
|
javascript: this.runtimeHelperJavascript
|
|
244
244
|
});
|
|
245
|
-
return t.ok === !1 ?
|
|
245
|
+
return t.ok === !1 ? F(t) : null;
|
|
246
246
|
}
|
|
247
247
|
enableNetworkCapture() {
|
|
248
248
|
if (this.networkCaptureCleanup)
|
|
249
249
|
return;
|
|
250
250
|
const t = window.fetch.bind(window), s = XMLHttpRequest.prototype.open, r = XMLHttpRequest.prototype.setRequestHeader, n = XMLHttpRequest.prototype.send;
|
|
251
251
|
window.fetch = async (i, a) => {
|
|
252
|
-
const o = Date.now(), c = new Date(o).toISOString(), u = i instanceof Request ? i : null, h = typeof i == "string" ? i : i instanceof URL ? i.toString() : u?.url ?? "",
|
|
252
|
+
const o = Date.now(), c = new Date(o).toISOString(), u = i instanceof Request ? i : null, h = typeof i == "string" ? i : i instanceof URL ? i.toString() : u?.url ?? "", _ = (a?.method ?? u?.method ?? "GET").toUpperCase(), T = k(new Headers(a?.headers ?? u?.headers ?? void 0)), w = await ut(u, a);
|
|
253
253
|
try {
|
|
254
254
|
const l = await t(i, a);
|
|
255
255
|
return this.enqueueNetworkEvent({
|
|
256
256
|
requestId: y("fetch"),
|
|
257
257
|
url: h,
|
|
258
|
-
method:
|
|
258
|
+
method: _,
|
|
259
259
|
requestHeaders: T,
|
|
260
260
|
requestBody: w,
|
|
261
261
|
resourceType: "fetch",
|
|
262
262
|
responseStatus: l.status,
|
|
263
|
-
responseHeaders:
|
|
264
|
-
responseBody: await
|
|
263
|
+
responseHeaders: k(l.headers),
|
|
264
|
+
responseBody: await lt(l),
|
|
265
265
|
startedAt: c,
|
|
266
266
|
durationMs: Date.now() - o
|
|
267
267
|
}), l;
|
|
@@ -269,7 +269,7 @@ class R {
|
|
|
269
269
|
throw this.enqueueNetworkEvent({
|
|
270
270
|
requestId: y("fetch"),
|
|
271
271
|
url: h,
|
|
272
|
-
method:
|
|
272
|
+
method: _,
|
|
273
273
|
requestHeaders: T,
|
|
274
274
|
requestBody: w,
|
|
275
275
|
resourceType: "fetch",
|
|
@@ -303,7 +303,7 @@ class R {
|
|
|
303
303
|
startedAtMs: Date.now(),
|
|
304
304
|
startedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
305
305
|
};
|
|
306
|
-
return c.requestBody =
|
|
306
|
+
return c.requestBody = b(a), this.__plunoMeta = c, this.addEventListener(
|
|
307
307
|
"loadend",
|
|
308
308
|
function() {
|
|
309
309
|
!o || !this.__plunoMeta || o.enqueueNetworkEvent({
|
|
@@ -314,8 +314,8 @@ class R {
|
|
|
314
314
|
requestBody: typeof this.__plunoMeta.requestBody == "string" ? this.__plunoMeta.requestBody : void 0,
|
|
315
315
|
resourceType: "xhr",
|
|
316
316
|
responseStatus: this.status,
|
|
317
|
-
responseHeaders:
|
|
318
|
-
responseBody:
|
|
317
|
+
responseHeaders: pt(this.getAllResponseHeaders()),
|
|
318
|
+
responseBody: dt(this),
|
|
319
319
|
errorText: this.status === 0 ? "XHR request failed or was aborted" : void 0,
|
|
320
320
|
startedAt: String(this.__plunoMeta.startedAt),
|
|
321
321
|
durationMs: Date.now() - Number(this.__plunoMeta.startedAtMs ?? Date.now())
|
|
@@ -355,14 +355,14 @@ class R {
|
|
|
355
355
|
this.heartbeatTimer !== null && (window.clearInterval(this.heartbeatTimer), this.heartbeatTimer = null);
|
|
356
356
|
}
|
|
357
357
|
setState(t) {
|
|
358
|
-
this.state = { ...this.state, ...t },
|
|
358
|
+
this.state = { ...this.state, ...t }, it(this.options.clientId, this.state), this.emit("state", this.getState());
|
|
359
359
|
}
|
|
360
360
|
emit(t, s) {
|
|
361
361
|
this.listeners[t]?.forEach((n) => n(s));
|
|
362
362
|
}
|
|
363
363
|
}
|
|
364
364
|
const O = 5e3;
|
|
365
|
-
async function
|
|
365
|
+
async function A(e) {
|
|
366
366
|
const t = Object.getPrototypeOf(async function() {
|
|
367
367
|
}).constructor, s = O, r = Date.now(), n = [], i = {
|
|
368
368
|
log: console.log,
|
|
@@ -408,10 +408,10 @@ async function _(e) {
|
|
|
408
408
|
console.log = i.log, console.info = i.info, console.warn = i.warn, console.error = i.error;
|
|
409
409
|
}
|
|
410
410
|
}
|
|
411
|
-
function
|
|
411
|
+
function B(e) {
|
|
412
412
|
return e.replace(/\/+$/, "");
|
|
413
413
|
}
|
|
414
|
-
function
|
|
414
|
+
function L(e) {
|
|
415
415
|
const t = new URL("/api/product-agent/embed/ws", e);
|
|
416
416
|
return t.protocol = t.protocol === "https:" ? "wss:" : "ws:", t.toString();
|
|
417
417
|
}
|
|
@@ -422,7 +422,7 @@ function g() {
|
|
|
422
422
|
origin: location.origin
|
|
423
423
|
};
|
|
424
424
|
}
|
|
425
|
-
function
|
|
425
|
+
function j(e) {
|
|
426
426
|
try {
|
|
427
427
|
const t = JSON.parse(e);
|
|
428
428
|
return t && typeof t == "object" ? t : { type: "error", message: "Invalid server event" };
|
|
@@ -430,19 +430,19 @@ function L(e) {
|
|
|
430
430
|
return { type: "error", message: "Invalid server event" };
|
|
431
431
|
}
|
|
432
432
|
}
|
|
433
|
-
function
|
|
433
|
+
function $(e, t) {
|
|
434
434
|
if (!e || typeof e != "object")
|
|
435
435
|
return [];
|
|
436
436
|
const s = e[t];
|
|
437
437
|
return Array.isArray(s) ? s.filter((r) => typeof r == "string" && r.trim().length > 0) : [];
|
|
438
438
|
}
|
|
439
|
-
function
|
|
439
|
+
function X(e) {
|
|
440
440
|
if (!e || typeof e != "object")
|
|
441
441
|
return null;
|
|
442
442
|
const t = e.javascript;
|
|
443
443
|
return typeof t != "string" || !t.trim() ? null : { javascript: t };
|
|
444
444
|
}
|
|
445
|
-
function
|
|
445
|
+
function z(e, t) {
|
|
446
446
|
return t ? e && typeof e == "object" ? {
|
|
447
447
|
...e,
|
|
448
448
|
helperError: t
|
|
@@ -452,23 +452,23 @@ function X(e, t) {
|
|
|
452
452
|
helperError: t
|
|
453
453
|
} : e;
|
|
454
454
|
}
|
|
455
|
-
function
|
|
455
|
+
function F(e) {
|
|
456
456
|
if (!e || typeof e != "object")
|
|
457
457
|
return e;
|
|
458
458
|
const t = e;
|
|
459
459
|
return typeof t.exception?.message == "string" ? t.exception.message : typeof t.error == "string" ? t.error : e;
|
|
460
460
|
}
|
|
461
|
-
function
|
|
461
|
+
function J() {
|
|
462
462
|
const e = "pluno.productAgent.clientId", t = window.localStorage.getItem(e);
|
|
463
463
|
if (t)
|
|
464
464
|
return t;
|
|
465
465
|
const s = crypto.randomUUID();
|
|
466
466
|
return window.localStorage.setItem(e, s), s;
|
|
467
467
|
}
|
|
468
|
-
function
|
|
468
|
+
function G() {
|
|
469
469
|
return crypto.randomUUID();
|
|
470
470
|
}
|
|
471
|
-
function
|
|
471
|
+
function W(e) {
|
|
472
472
|
if (!e || typeof e != "object")
|
|
473
473
|
return null;
|
|
474
474
|
const t = e, s = typeof t.id == "string" ? t.id : null;
|
|
@@ -479,8 +479,10 @@ function G(e) {
|
|
|
479
479
|
avatarUrl: typeof t.avatarUrl == "string" ? t.avatarUrl : null
|
|
480
480
|
} : null;
|
|
481
481
|
}
|
|
482
|
-
function
|
|
483
|
-
return Array.isArray(e) ?
|
|
482
|
+
function v(e) {
|
|
483
|
+
return Array.isArray(e) ? S(
|
|
484
|
+
e.map(C).filter((t) => t !== null)
|
|
485
|
+
) : [];
|
|
484
486
|
}
|
|
485
487
|
function C(e) {
|
|
486
488
|
if (!e || typeof e != "object")
|
|
@@ -494,29 +496,29 @@ function C(e) {
|
|
|
494
496
|
return {
|
|
495
497
|
id: String(t.id ?? crypto.randomUUID()),
|
|
496
498
|
role: n,
|
|
497
|
-
content:
|
|
499
|
+
content: Z(r.content),
|
|
498
500
|
createdAt: typeof t.createdAt == "string" ? t.createdAt : (/* @__PURE__ */ new Date()).toISOString()
|
|
499
501
|
};
|
|
500
502
|
}
|
|
501
503
|
return r.type === "function_call" || r.type === "tool_call" || r.type === "web_search_call" ? {
|
|
502
504
|
id: String(t.id ?? crypto.randomUUID()),
|
|
503
505
|
role: "tool",
|
|
504
|
-
content:
|
|
506
|
+
content: Y(r),
|
|
505
507
|
createdAt: typeof t.createdAt == "string" ? t.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
|
|
506
508
|
dataType: String(r.type),
|
|
507
509
|
loading: r.localExecutionStatus === "running"
|
|
508
|
-
} : r.type === "run_status" || r.type === "run_error" ? r.type === "run_status" && (r.status === "running" || r.status === "retrying") ? null : {
|
|
510
|
+
} : r.type === "run_status" || r.type === "run_error" ? r.type === "run_status" && (r.status === "running" || r.status === "retrying") || r.type === "run_error" && r.stage === "tool_execution" ? null : {
|
|
509
511
|
id: String(t.id ?? crypto.randomUUID()),
|
|
510
512
|
role: "system",
|
|
511
|
-
content:
|
|
513
|
+
content: K(r),
|
|
512
514
|
createdAt: typeof t.createdAt == "string" ? t.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
|
|
513
515
|
dataType: String(r.type)
|
|
514
516
|
} : null;
|
|
515
517
|
}
|
|
516
|
-
function
|
|
518
|
+
function K(e) {
|
|
517
519
|
return typeof e.message == "string" && e.message.trim().length > 0 ? e.message : e.type === "run_status" && e.status === "interrupted" ? "Product Agent was interrupted before it could finish this message." : e.type === "run_status" && e.status === "stopped" ? "Product Agent stopped." : "Product Agent run status changed.";
|
|
518
520
|
}
|
|
519
|
-
function
|
|
521
|
+
function Y(e) {
|
|
520
522
|
if (e.type === "web_search_call") {
|
|
521
523
|
const t = e.action;
|
|
522
524
|
if (t && typeof t == "object") {
|
|
@@ -528,9 +530,9 @@ function K(e) {
|
|
|
528
530
|
}
|
|
529
531
|
return "Searching the web";
|
|
530
532
|
}
|
|
531
|
-
return
|
|
533
|
+
return V(e);
|
|
532
534
|
}
|
|
533
|
-
function
|
|
535
|
+
function V(e) {
|
|
534
536
|
if (typeof e.summary == "string" && e.summary.trim().length > 0)
|
|
535
537
|
return e.summary;
|
|
536
538
|
if (typeof e.arguments == "string")
|
|
@@ -543,7 +545,7 @@ function Y(e) {
|
|
|
543
545
|
}
|
|
544
546
|
return typeof e.name == "string" && e.name.trim().length > 0 ? e.name : "Run tool";
|
|
545
547
|
}
|
|
546
|
-
function
|
|
548
|
+
function Z(e) {
|
|
547
549
|
return typeof e == "string" ? e : Array.isArray(e) ? e.map((t) => {
|
|
548
550
|
if (!t || typeof t != "object")
|
|
549
551
|
return "";
|
|
@@ -551,14 +553,14 @@ function V(e) {
|
|
|
551
553
|
return typeof s.text == "string" ? s.text : typeof s.content == "string" ? s.content : "";
|
|
552
554
|
}).filter(Boolean).join("") : "";
|
|
553
555
|
}
|
|
554
|
-
function
|
|
555
|
-
const s =
|
|
556
|
+
function Q(e, t) {
|
|
557
|
+
const s = tt(e, t), r = s.findIndex((i) => i.id === t.id);
|
|
556
558
|
if (r === -1)
|
|
557
|
-
return [...s, t];
|
|
559
|
+
return S([...s, t]);
|
|
558
560
|
const n = [...s];
|
|
559
|
-
return n[r] = t, n;
|
|
561
|
+
return n[r] = t, S(n);
|
|
560
562
|
}
|
|
561
|
-
function
|
|
563
|
+
function tt(e, t) {
|
|
562
564
|
if (t.role !== "user")
|
|
563
565
|
return e;
|
|
564
566
|
const s = e.findIndex(
|
|
@@ -569,11 +571,11 @@ function Q(e, t) {
|
|
|
569
571
|
const r = [...e];
|
|
570
572
|
return r.splice(s, 1), r;
|
|
571
573
|
}
|
|
572
|
-
function tt(e) {
|
|
573
|
-
const t = et(e);
|
|
574
|
-
return t === null ? !1 : e.slice(t + 1).some((s) => !s || typeof s != "object" ? !1 : M(s.data));
|
|
575
|
-
}
|
|
576
574
|
function et(e) {
|
|
575
|
+
const t = st(e);
|
|
576
|
+
return t === null ? !1 : e.slice(t + 1).some((s) => !s || typeof s != "object" ? !1 : D(s.data));
|
|
577
|
+
}
|
|
578
|
+
function st(e) {
|
|
577
579
|
for (let t = e.length - 1; t >= 0; t -= 1) {
|
|
578
580
|
const s = e[t];
|
|
579
581
|
if (!s || typeof s != "object")
|
|
@@ -587,21 +589,37 @@ function et(e) {
|
|
|
587
589
|
}
|
|
588
590
|
return null;
|
|
589
591
|
}
|
|
590
|
-
function
|
|
592
|
+
function D(e) {
|
|
591
593
|
if (!e || typeof e != "object")
|
|
592
594
|
return !1;
|
|
593
595
|
const t = e;
|
|
594
|
-
return t.type === "message" && t.role === "assistant"
|
|
596
|
+
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");
|
|
597
|
+
}
|
|
598
|
+
function S(e) {
|
|
599
|
+
return e.filter((t, s) => rt(t) ? !nt(e, s) : !0);
|
|
595
600
|
}
|
|
596
|
-
function
|
|
601
|
+
function rt(e) {
|
|
602
|
+
return e.role === "system" && (e.dataType === "run_status" || e.dataType === "run_error");
|
|
603
|
+
}
|
|
604
|
+
function nt(e, t) {
|
|
605
|
+
for (let s = t + 1; s < e.length; s += 1) {
|
|
606
|
+
const r = e[s];
|
|
607
|
+
if (r.role === "user")
|
|
608
|
+
return !1;
|
|
609
|
+
if (r.role === "assistant")
|
|
610
|
+
return !0;
|
|
611
|
+
}
|
|
612
|
+
return !1;
|
|
613
|
+
}
|
|
614
|
+
function I(e, t) {
|
|
597
615
|
return e && typeof e == "object" && typeof e[t] == "string" ? e[t] : null;
|
|
598
616
|
}
|
|
599
|
-
function
|
|
617
|
+
function ot(e) {
|
|
600
618
|
try {
|
|
601
|
-
const t = window.localStorage.getItem(`${
|
|
619
|
+
const t = window.localStorage.getItem(`${R}${e}`);
|
|
602
620
|
if (!t)
|
|
603
621
|
return null;
|
|
604
|
-
const s = JSON.parse(t), r = Array.isArray(s.messages) ? s.messages.map(
|
|
622
|
+
const s = JSON.parse(t), r = Array.isArray(s.messages) ? s.messages.map(at).filter((n) => !!n) : [];
|
|
605
623
|
return {
|
|
606
624
|
sessionId: typeof s.sessionId == "string" ? s.sessionId : null,
|
|
607
625
|
messages: r
|
|
@@ -610,10 +628,10 @@ function st(e) {
|
|
|
610
628
|
return null;
|
|
611
629
|
}
|
|
612
630
|
}
|
|
613
|
-
function
|
|
631
|
+
function it(e, t) {
|
|
614
632
|
try {
|
|
615
633
|
window.localStorage.setItem(
|
|
616
|
-
`${
|
|
634
|
+
`${R}${e}`,
|
|
617
635
|
JSON.stringify({
|
|
618
636
|
sessionId: t.sessionId,
|
|
619
637
|
messages: t.messages.slice(-100)
|
|
@@ -623,7 +641,7 @@ function rt(e, t) {
|
|
|
623
641
|
return;
|
|
624
642
|
}
|
|
625
643
|
}
|
|
626
|
-
function
|
|
644
|
+
function at(e) {
|
|
627
645
|
if (!e || typeof e != "object")
|
|
628
646
|
return null;
|
|
629
647
|
const t = e;
|
|
@@ -636,18 +654,18 @@ function nt(e) {
|
|
|
636
654
|
loading: typeof t.loading == "boolean" ? t.loading : void 0
|
|
637
655
|
};
|
|
638
656
|
}
|
|
639
|
-
function
|
|
657
|
+
function ct(e) {
|
|
640
658
|
return !!e && typeof e == "object" && typeof e.summary == "string" && typeof e.javascript == "string";
|
|
641
659
|
}
|
|
642
|
-
function
|
|
660
|
+
function k(e) {
|
|
643
661
|
const t = {};
|
|
644
662
|
return e?.forEach((s, r) => {
|
|
645
663
|
t[r] = s;
|
|
646
664
|
}), t;
|
|
647
665
|
}
|
|
648
|
-
async function
|
|
666
|
+
async function ut(e, t) {
|
|
649
667
|
if (typeof t?.body < "u")
|
|
650
|
-
return
|
|
668
|
+
return b(t.body);
|
|
651
669
|
if (e)
|
|
652
670
|
try {
|
|
653
671
|
return p(await e.clone().text());
|
|
@@ -655,21 +673,21 @@ async function it(e, t) {
|
|
|
655
673
|
return;
|
|
656
674
|
}
|
|
657
675
|
}
|
|
658
|
-
async function
|
|
676
|
+
async function lt(e) {
|
|
659
677
|
try {
|
|
660
678
|
return p(await e.clone().text());
|
|
661
679
|
} catch (t) {
|
|
662
680
|
return { error: t instanceof Error ? t.message : "unavailable" };
|
|
663
681
|
}
|
|
664
682
|
}
|
|
665
|
-
function
|
|
683
|
+
function dt(e) {
|
|
666
684
|
try {
|
|
667
685
|
return e.responseType === "" || e.responseType === "text" ? p(e.responseText ?? "") : e.responseType === "json" ? p(JSON.stringify(e.response)) : `[unsupported xhr responseType: ${e.responseType || "unknown"}]`;
|
|
668
686
|
} catch (t) {
|
|
669
687
|
return { error: t instanceof Error ? t.message : "unavailable" };
|
|
670
688
|
}
|
|
671
689
|
}
|
|
672
|
-
function
|
|
690
|
+
function b(e) {
|
|
673
691
|
if (!(e === null || typeof e > "u")) {
|
|
674
692
|
if (typeof e == "string")
|
|
675
693
|
return p(e);
|
|
@@ -688,7 +706,7 @@ function D(e) {
|
|
|
688
706
|
}
|
|
689
707
|
}
|
|
690
708
|
}
|
|
691
|
-
function
|
|
709
|
+
function pt(e) {
|
|
692
710
|
const t = {};
|
|
693
711
|
for (const s of e.trim().split(/[\r\n]+/)) {
|
|
694
712
|
const r = s.indexOf(":");
|
|
@@ -702,16 +720,16 @@ function p(e) {
|
|
|
702
720
|
function y(e) {
|
|
703
721
|
return `${e}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
704
722
|
}
|
|
705
|
-
const
|
|
723
|
+
const E = "[REDACTED_SECRET]", d = "[REDACTED_TOKEN]", ft = "[REDACTED_SIGNED_URL]", ht = 20, gt = /^(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, N = /\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi, H = /\bBasic\s+[A-Za-z0-9+/=-]{12,}/gi, q = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g, U = /\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, yt = /\bhttps?:\/\/[^\s"'<>]+(?:X-Amz-Signature|X-Goog-Signature|Signature|sig=)[^\s"'<>]*/gi, mt = /\bhttps?:\/\/[^\s"'<>]+/gi, St = /[),.;\]]+$/;
|
|
706
724
|
function f(e) {
|
|
707
725
|
return m(e, 0, /* @__PURE__ */ new WeakSet());
|
|
708
726
|
}
|
|
709
727
|
function m(e, t, s) {
|
|
710
728
|
if (typeof e == "string")
|
|
711
|
-
return
|
|
729
|
+
return Tt(e);
|
|
712
730
|
if (e === null || typeof e != "object")
|
|
713
731
|
return e;
|
|
714
|
-
if (t >=
|
|
732
|
+
if (t >= ht)
|
|
715
733
|
return "[REDACTED_MAX_DEPTH]";
|
|
716
734
|
if (s.has(e))
|
|
717
735
|
return "[REDACTED_CIRCULAR]";
|
|
@@ -719,37 +737,37 @@ function m(e, t, s) {
|
|
|
719
737
|
return e.map((n) => m(n, t + 1, s));
|
|
720
738
|
const r = {};
|
|
721
739
|
for (const [n, i] of Object.entries(e))
|
|
722
|
-
|
|
740
|
+
Et(n) ? r[n] = E : r[n] = n.toLowerCase() === "url" ? _t(i) : m(i, t + 1, s);
|
|
723
741
|
return r;
|
|
724
742
|
}
|
|
725
|
-
function
|
|
743
|
+
function Et(e) {
|
|
726
744
|
const t = e.replace(/[^a-z0-9]/gi, "").toLowerCase();
|
|
727
745
|
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");
|
|
728
746
|
}
|
|
729
|
-
function
|
|
747
|
+
function _t(e) {
|
|
730
748
|
return typeof e == "string" ? P(e) : m(e, 0, /* @__PURE__ */ new WeakSet());
|
|
731
749
|
}
|
|
732
750
|
function P(e) {
|
|
733
751
|
try {
|
|
734
752
|
const t = new URL(e, location.href);
|
|
735
753
|
for (const s of Array.from(t.searchParams.keys()))
|
|
736
|
-
|
|
754
|
+
gt.test(s) && t.searchParams.set(s, d);
|
|
737
755
|
return t.username && (t.username = d), t.password && (t.password = d), t.toString();
|
|
738
756
|
} catch {
|
|
739
|
-
return
|
|
757
|
+
return wt(e);
|
|
740
758
|
}
|
|
741
759
|
}
|
|
742
|
-
function
|
|
743
|
-
return e.replace(
|
|
760
|
+
function Tt(e) {
|
|
761
|
+
return e.replace(yt, ft).replace(mt, At).replace(N, `Bearer ${d}`).replace(H, `Basic ${d}`).replace(q, d).replace(U, (t, s) => `${s}: ${E}`);
|
|
744
762
|
}
|
|
745
|
-
function
|
|
746
|
-
return e.replace(
|
|
763
|
+
function wt(e) {
|
|
764
|
+
return e.replace(N, `Bearer ${d}`).replace(H, `Basic ${d}`).replace(q, d).replace(U, (t, s) => `${s}: ${E}`);
|
|
747
765
|
}
|
|
748
|
-
function
|
|
749
|
-
const t = e.match(
|
|
766
|
+
function At(e) {
|
|
767
|
+
const t = e.match(St)?.[0] ?? "", s = t ? e.slice(0, -t.length) : e;
|
|
750
768
|
return `${P(s)}${t}`;
|
|
751
769
|
}
|
|
752
770
|
export {
|
|
753
|
-
|
|
754
|
-
|
|
771
|
+
M as PlunoProductAgent,
|
|
772
|
+
M as default
|
|
755
773
|
};
|
package/package.json
CHANGED