@pluno/product-agent-web 0.1.14 → 0.1.16
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 -1
- package/dist/product-agent-sdk.js +118 -113
- package/dist/product-agent-widget.js +283 -257
- package/dist/widget.d.ts +1 -0
- package/package.json +1 -1
|
@@ -2,11 +2,11 @@ const X = "https://app.pluno.ai";
|
|
|
2
2
|
const O = "pluno.productAgent.state.", k = "pluno.productAgent.pendingEvents.", R = "pluno.productAgent.transportId";
|
|
3
3
|
class q {
|
|
4
4
|
constructor(t) {
|
|
5
|
-
this.options = t, this.transportId =
|
|
5
|
+
this.options = t, this.transportId = it(), this.state = {
|
|
6
6
|
...this.state,
|
|
7
|
-
starterPrompts:
|
|
7
|
+
starterPrompts: Q(t.initialStarterPrompts)
|
|
8
8
|
};
|
|
9
|
-
const s =
|
|
9
|
+
const s = Tt(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 = kt(t.clientId);
|
|
19
19
|
}
|
|
20
20
|
options;
|
|
21
21
|
listeners = {};
|
|
@@ -50,8 +50,8 @@ class q {
|
|
|
50
50
|
static async init(t) {
|
|
51
51
|
const s = new q({
|
|
52
52
|
...t,
|
|
53
|
-
backendUrl:
|
|
54
|
-
clientId: t.clientId ??
|
|
53
|
+
backendUrl: J(t.backendUrl ?? X),
|
|
54
|
+
clientId: t.clientId ?? rt()
|
|
55
55
|
});
|
|
56
56
|
try {
|
|
57
57
|
s.enableNetworkCapture(), t.autoConnect !== !1 && await s.connect();
|
|
@@ -77,7 +77,7 @@ class q {
|
|
|
77
77
|
return;
|
|
78
78
|
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)
|
|
79
79
|
throw new Error("Product Agent requires a token or tokenProvider");
|
|
80
|
-
const t =
|
|
80
|
+
const t = Y(this.options.backendUrl), s = this.options.webSocketFactory?.(t) ?? new WebSocket(t);
|
|
81
81
|
this.socket = s, s.addEventListener("open", () => {
|
|
82
82
|
this.socket === s && (l("web-sdk.agent", "Product Agent socket opened", {
|
|
83
83
|
queuedClientEventCount: this.queuedClientEvents.length,
|
|
@@ -89,7 +89,7 @@ class q {
|
|
|
89
89
|
transportId: this.transportId
|
|
90
90
|
}), this.flushQueuedClientEvents(), this.startHeartbeat(), this.setState({ status: "connected", lastError: null }));
|
|
91
91
|
}), s.addEventListener("message", (n) => {
|
|
92
|
-
this.socket === s && this.handleServerEvent(
|
|
92
|
+
this.socket === s && this.handleServerEvent(V(n.data));
|
|
93
93
|
}), s.addEventListener("close", (n) => {
|
|
94
94
|
this.socket === s && (this.stopHeartbeat(), this.socket = null, this.state.status !== "closed" && (l("web-sdk.agent", "Product Agent socket closed; scheduling reconnect", {
|
|
95
95
|
code: typeof n?.code == "number" ? n.code : null,
|
|
@@ -117,7 +117,7 @@ class q {
|
|
|
117
117
|
const s = t.trim();
|
|
118
118
|
if (!s)
|
|
119
119
|
return;
|
|
120
|
-
const n = g(), r =
|
|
120
|
+
const n = g(), r = ot(), i = {
|
|
121
121
|
id: `local-${r}`,
|
|
122
122
|
role: "user",
|
|
123
123
|
content: s,
|
|
@@ -129,16 +129,16 @@ class q {
|
|
|
129
129
|
isThinking: !0,
|
|
130
130
|
lastError: null
|
|
131
131
|
}), this.emit("message", i);
|
|
132
|
-
const
|
|
132
|
+
const a = {
|
|
133
133
|
type: "chat.user_message",
|
|
134
134
|
sessionId: this.state.sessionId ?? void 0,
|
|
135
135
|
clientMessageId: r,
|
|
136
136
|
content: s,
|
|
137
137
|
page: n,
|
|
138
138
|
model: this.options.model,
|
|
139
|
-
metadata: this.options.metadata
|
|
139
|
+
metadata: F(this.options.metadata)
|
|
140
140
|
};
|
|
141
|
-
this.activeClientMessageId = r, this.activeUserMessageEvent =
|
|
141
|
+
this.activeClientMessageId = r, this.activeUserMessageEvent = a, this.markThinkingProgress(), this.send(a);
|
|
142
142
|
}
|
|
143
143
|
stop() {
|
|
144
144
|
this.state.sessionId && (this.send({ type: "run.stop", sessionId: this.state.sessionId }), this.setState({ isThinking: !1 }), this.clearThinkingWatchdog());
|
|
@@ -189,18 +189,18 @@ class q {
|
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
handleServerEvent(t) {
|
|
192
|
-
if (
|
|
193
|
-
const s =
|
|
192
|
+
if (z(t) && this.markThinkingProgress(), t.type === "auth.ok") {
|
|
193
|
+
const s = tt(t), n = Object.prototype.hasOwnProperty.call(t, "appearance");
|
|
194
194
|
l("web-sdk.agent", "Received auth.ok appearance", {
|
|
195
195
|
hasAppearance: n,
|
|
196
196
|
rawAppearance: t.appearance,
|
|
197
197
|
normalizedAppearance: s
|
|
198
|
-
}), this.runtimeHelperJavascript =
|
|
199
|
-
const r =
|
|
200
|
-
user:
|
|
198
|
+
}), this.runtimeHelperJavascript = et(t.runtimeHelpers)?.javascript ?? null;
|
|
199
|
+
const r = Z(t, "starterPrompts"), i = Object.prototype.hasOwnProperty.call(t, "starterPrompts"), a = {
|
|
200
|
+
user: at(t.user),
|
|
201
201
|
status: "connected"
|
|
202
202
|
};
|
|
203
|
-
(i || this.state.starterPrompts.length === 0) && (
|
|
203
|
+
(i || this.state.starterPrompts.length === 0) && (a.starterPrompts = r), (n || s) && (a.appearance = s), this.setState(a), this.state.sessionId && this.send({
|
|
204
204
|
type: "page.upsert",
|
|
205
205
|
sessionId: this.state.sessionId,
|
|
206
206
|
page: g(),
|
|
@@ -210,9 +210,9 @@ class q {
|
|
|
210
210
|
}
|
|
211
211
|
if (t.type === "conversation.state") {
|
|
212
212
|
const s = Array.isArray(t.items) ? t.items : [];
|
|
213
|
-
|
|
213
|
+
ft(s) && this.clearRetryTimers(), this.setState({
|
|
214
214
|
sessionId: P(t.session, "id") ?? this.state.sessionId,
|
|
215
|
-
messages:
|
|
215
|
+
messages: ct(s),
|
|
216
216
|
...b(s) ? { assistantDraft: "", isThinking: !1 } : {}
|
|
217
217
|
}), b(s) && this.clearThinkingWatchdog();
|
|
218
218
|
return;
|
|
@@ -224,7 +224,7 @@ class q {
|
|
|
224
224
|
if (t.type === "session.item") {
|
|
225
225
|
const s = U(t.item);
|
|
226
226
|
s && (s.role === "assistant" && this.clearRetryTimers(), this.setState({
|
|
227
|
-
messages:
|
|
227
|
+
messages: pt(this.state.messages, s),
|
|
228
228
|
assistantDraft: s.role === "assistant" ? "" : this.state.assistantDraft,
|
|
229
229
|
...I(t.item.data) ? { assistantDraft: "", isThinking: !1 } : {}
|
|
230
230
|
}), I(t.item.data) && this.clearThinkingWatchdog(), this.emit("message", s));
|
|
@@ -259,14 +259,14 @@ class q {
|
|
|
259
259
|
if (i >= 1)
|
|
260
260
|
return !1;
|
|
261
261
|
this.retryAttemptsByClientMessageId[n] = i + 1;
|
|
262
|
-
const
|
|
262
|
+
const a = typeof t.retryAfterMs == "number" ? t.retryAfterMs : 2e3;
|
|
263
263
|
return this.setState({ status: "reconnecting", isThinking: !0, lastError: null }), this.retryTimersByClientMessageId[n] = window.setTimeout(() => {
|
|
264
264
|
delete this.retryTimersByClientMessageId[n], this.setState({ status: "connected", isThinking: !0, lastError: null }), this.markThinkingProgress(), this.send({
|
|
265
265
|
type: "chat.retry_last_user_message",
|
|
266
266
|
sessionId: s,
|
|
267
267
|
clientMessageId: n
|
|
268
268
|
});
|
|
269
|
-
},
|
|
269
|
+
}, a), !0;
|
|
270
270
|
}
|
|
271
271
|
clearRetryTimers() {
|
|
272
272
|
for (const t of Object.values(this.retryTimersByClientMessageId))
|
|
@@ -335,12 +335,12 @@ class q {
|
|
|
335
335
|
}
|
|
336
336
|
async executeToolCall(t) {
|
|
337
337
|
const s = typeof t.sessionId == "string" ? t.sessionId : null, n = typeof t.callId == "string" ? t.callId : null, r = t.rawInput;
|
|
338
|
-
if (!s || !n || !
|
|
338
|
+
if (!s || !n || !_t(r))
|
|
339
339
|
return;
|
|
340
|
-
const i = await this.executeRuntimeHelper(),
|
|
340
|
+
const i = await this.executeRuntimeHelper(), a = await M(r).catch((o) => ({
|
|
341
341
|
ok: !1,
|
|
342
342
|
exception: {
|
|
343
|
-
message:
|
|
343
|
+
message: o instanceof Error ? o.message : String(o)
|
|
344
344
|
}
|
|
345
345
|
}));
|
|
346
346
|
this.send({
|
|
@@ -350,7 +350,7 @@ class q {
|
|
|
350
350
|
toolName: "execute_code",
|
|
351
351
|
summary: r.summary,
|
|
352
352
|
rawInput: f(r),
|
|
353
|
-
rawOutput: f(
|
|
353
|
+
rawOutput: f(st(a, i))
|
|
354
354
|
});
|
|
355
355
|
}
|
|
356
356
|
async executeRuntimeHelper() {
|
|
@@ -359,16 +359,16 @@ class q {
|
|
|
359
359
|
const t = await M({
|
|
360
360
|
javascript: this.runtimeHelperJavascript
|
|
361
361
|
});
|
|
362
|
-
return t.ok === !1 ?
|
|
362
|
+
return t.ok === !1 ? nt(t) : null;
|
|
363
363
|
}
|
|
364
364
|
enableNetworkCapture() {
|
|
365
365
|
if (this.networkCaptureCleanup)
|
|
366
366
|
return;
|
|
367
367
|
const t = window.fetch.bind(window), s = XMLHttpRequest.prototype.open, n = XMLHttpRequest.prototype.setRequestHeader, r = XMLHttpRequest.prototype.send;
|
|
368
|
-
window.fetch = async (i,
|
|
369
|
-
const
|
|
368
|
+
window.fetch = async (i, a) => {
|
|
369
|
+
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 = H(new Headers(a?.headers ?? u?.headers ?? void 0)), C = await Et(u, a);
|
|
370
370
|
try {
|
|
371
|
-
const d = await t(i,
|
|
371
|
+
const d = await t(i, a);
|
|
372
372
|
return this.enqueueNetworkEvent({
|
|
373
373
|
requestId: T("fetch"),
|
|
374
374
|
url: y,
|
|
@@ -378,9 +378,9 @@ class q {
|
|
|
378
378
|
resourceType: "fetch",
|
|
379
379
|
responseStatus: d.status,
|
|
380
380
|
responseHeaders: H(d.headers),
|
|
381
|
-
responseBody: await
|
|
381
|
+
responseBody: await wt(d),
|
|
382
382
|
startedAt: c,
|
|
383
|
-
durationMs: Date.now() -
|
|
383
|
+
durationMs: Date.now() - o
|
|
384
384
|
}), d;
|
|
385
385
|
} catch (d) {
|
|
386
386
|
throw this.enqueueNetworkEvent({
|
|
@@ -392,27 +392,27 @@ class q {
|
|
|
392
392
|
resourceType: "fetch",
|
|
393
393
|
errorText: d instanceof Error ? d.message : String(d),
|
|
394
394
|
startedAt: c,
|
|
395
|
-
durationMs: Date.now() -
|
|
395
|
+
durationMs: Date.now() - o
|
|
396
396
|
}), d;
|
|
397
397
|
}
|
|
398
|
-
}, XMLHttpRequest.prototype.open = function(
|
|
398
|
+
}, XMLHttpRequest.prototype.open = function(a, o, c, u, y) {
|
|
399
399
|
return this.__plunoMeta = {
|
|
400
400
|
requestId: T("xhr"),
|
|
401
|
-
method: String(
|
|
402
|
-
url: typeof
|
|
401
|
+
method: String(a ?? "GET").toUpperCase(),
|
|
402
|
+
url: typeof o == "string" ? o : o.toString(),
|
|
403
403
|
requestHeaders: {},
|
|
404
404
|
startedAtMs: Date.now(),
|
|
405
405
|
startedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
406
|
-
}, s.call(this,
|
|
407
|
-
}, XMLHttpRequest.prototype.setRequestHeader = function(
|
|
406
|
+
}, s.call(this, a, o, c ?? !0, u ?? void 0, y ?? void 0);
|
|
407
|
+
}, XMLHttpRequest.prototype.setRequestHeader = function(a, o) {
|
|
408
408
|
const c = this.__plunoMeta;
|
|
409
409
|
if (c) {
|
|
410
410
|
const u = c.requestHeaders ?? {};
|
|
411
|
-
u[
|
|
411
|
+
u[a] = o, c.requestHeaders = u;
|
|
412
412
|
}
|
|
413
|
-
return n.call(this,
|
|
414
|
-
}, XMLHttpRequest.prototype.send = function(
|
|
415
|
-
const
|
|
413
|
+
return n.call(this, a, o);
|
|
414
|
+
}, XMLHttpRequest.prototype.send = function(a) {
|
|
415
|
+
const o = window.__plunoProductAgentInstance, c = this.__plunoMeta ?? {
|
|
416
416
|
requestId: T("xhr"),
|
|
417
417
|
method: "GET",
|
|
418
418
|
url: "",
|
|
@@ -420,10 +420,10 @@ class q {
|
|
|
420
420
|
startedAtMs: Date.now(),
|
|
421
421
|
startedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
422
422
|
};
|
|
423
|
-
return c.requestBody = B(
|
|
423
|
+
return c.requestBody = B(a), this.__plunoMeta = c, this.addEventListener(
|
|
424
424
|
"loadend",
|
|
425
425
|
function() {
|
|
426
|
-
!
|
|
426
|
+
!o || !this.__plunoMeta || o.enqueueNetworkEvent({
|
|
427
427
|
requestId: String(this.__plunoMeta.requestId),
|
|
428
428
|
url: String(this.__plunoMeta.url ?? ""),
|
|
429
429
|
method: String(this.__plunoMeta.method ?? "GET"),
|
|
@@ -431,15 +431,15 @@ class q {
|
|
|
431
431
|
requestBody: typeof this.__plunoMeta.requestBody == "string" ? this.__plunoMeta.requestBody : void 0,
|
|
432
432
|
resourceType: "xhr",
|
|
433
433
|
responseStatus: this.status,
|
|
434
|
-
responseHeaders:
|
|
435
|
-
responseBody:
|
|
434
|
+
responseHeaders: Ct(this.getAllResponseHeaders()),
|
|
435
|
+
responseBody: At(this),
|
|
436
436
|
errorText: this.status === 0 ? "XHR request failed or was aborted" : void 0,
|
|
437
437
|
startedAt: String(this.__plunoMeta.startedAt),
|
|
438
438
|
durationMs: Date.now() - Number(this.__plunoMeta.startedAtMs ?? Date.now())
|
|
439
439
|
});
|
|
440
440
|
},
|
|
441
441
|
{ once: !0 }
|
|
442
|
-
), r.call(this,
|
|
442
|
+
), r.call(this, a ?? null);
|
|
443
443
|
}, window.__plunoProductAgentInstance = this, this.networkCaptureCleanup = () => {
|
|
444
444
|
window.fetch = t, XMLHttpRequest.prototype.open = s, XMLHttpRequest.prototype.setRequestHeader = n, XMLHttpRequest.prototype.send = r, window.__plunoProductAgentInstance === this && delete window.__plunoProductAgentInstance;
|
|
445
445
|
};
|
|
@@ -476,7 +476,7 @@ class q {
|
|
|
476
476
|
this.heartbeatTimer !== null && (window.clearInterval(this.heartbeatTimer), this.heartbeatTimer = null);
|
|
477
477
|
}
|
|
478
478
|
setState(t) {
|
|
479
|
-
this.state = { ...this.state, ...t },
|
|
479
|
+
this.state = { ...this.state, ...t }, St(this.options.clientId, this.state), this.emit("state", this.getState());
|
|
480
480
|
}
|
|
481
481
|
emit(t, s) {
|
|
482
482
|
this.listeners[t]?.forEach((r) => r(s));
|
|
@@ -494,20 +494,24 @@ function l(e, t, s) {
|
|
|
494
494
|
i.push(r), i.length > 120 && i.splice(0, i.length - 120), n.__plunoProductAgentDiagnostics__ = i, n.__PLUNO_PRODUCT_AGENT_DIAGNOSTICS__ = () => [...i], window.dispatchEvent(new CustomEvent("product-agent:preview-diagnostic", { detail: r }));
|
|
495
495
|
}
|
|
496
496
|
function F(e) {
|
|
497
|
+
const t = typeof e == "function" ? e() : e;
|
|
498
|
+
return t && Object.keys(t).length > 0 ? t : void 0;
|
|
499
|
+
}
|
|
500
|
+
function z(e) {
|
|
497
501
|
return e.type === "conversation.state" || e.type === "session.updated" || e.type === "session.item" || e.type === "chat.assistant_delta" || e.type === "chat.assistant_done" || e.type === "tool.call";
|
|
498
502
|
}
|
|
499
|
-
const
|
|
503
|
+
const K = 5e3;
|
|
500
504
|
async function M(e) {
|
|
501
505
|
const t = Object.getPrototypeOf(async function() {
|
|
502
|
-
}).constructor, s =
|
|
506
|
+
}).constructor, s = K, n = Date.now(), r = [], i = {
|
|
503
507
|
log: console.log,
|
|
504
508
|
info: console.info,
|
|
505
509
|
warn: console.warn,
|
|
506
510
|
error: console.error
|
|
507
|
-
},
|
|
508
|
-
r.push({ level:
|
|
511
|
+
}, a = (o) => (...c) => {
|
|
512
|
+
r.push({ level: o, args: c }), i[o](...c);
|
|
509
513
|
};
|
|
510
|
-
console.log =
|
|
514
|
+
console.log = a("log"), console.info = a("info"), console.warn = a("warn"), console.error = a("error");
|
|
511
515
|
try {
|
|
512
516
|
return {
|
|
513
517
|
ok: !0,
|
|
@@ -524,14 +528,14 @@ async function M(e) {
|
|
|
524
528
|
origin: location.origin
|
|
525
529
|
}
|
|
526
530
|
};
|
|
527
|
-
} catch (
|
|
531
|
+
} catch (o) {
|
|
528
532
|
return {
|
|
529
533
|
ok: !1,
|
|
530
534
|
console: r,
|
|
531
535
|
exception: {
|
|
532
|
-
name:
|
|
533
|
-
message:
|
|
534
|
-
stack:
|
|
536
|
+
name: o instanceof Error ? o.name : "Error",
|
|
537
|
+
message: o instanceof Error ? o.message : String(o),
|
|
538
|
+
stack: o instanceof Error ? o.stack : void 0
|
|
535
539
|
},
|
|
536
540
|
metadata: {
|
|
537
541
|
durationMs: Date.now() - n,
|
|
@@ -543,10 +547,10 @@ async function M(e) {
|
|
|
543
547
|
console.log = i.log, console.info = i.info, console.warn = i.warn, console.error = i.error;
|
|
544
548
|
}
|
|
545
549
|
}
|
|
546
|
-
function
|
|
550
|
+
function J(e) {
|
|
547
551
|
return e.replace(/\/+$/, "");
|
|
548
552
|
}
|
|
549
|
-
function
|
|
553
|
+
function Y(e) {
|
|
550
554
|
const t = new URL("/api/product-agent/embed/ws", e);
|
|
551
555
|
return t.protocol = t.protocol === "https:" ? "wss:" : "ws:", t.toString();
|
|
552
556
|
}
|
|
@@ -557,7 +561,7 @@ function g() {
|
|
|
557
561
|
origin: location.origin
|
|
558
562
|
};
|
|
559
563
|
}
|
|
560
|
-
function
|
|
564
|
+
function V(e) {
|
|
561
565
|
try {
|
|
562
566
|
const t = JSON.parse(e);
|
|
563
567
|
return t && typeof t == "object" ? t : { type: "error", message: "Invalid server event" };
|
|
@@ -565,32 +569,33 @@ function Y(e) {
|
|
|
565
569
|
return { type: "error", message: "Invalid server event" };
|
|
566
570
|
}
|
|
567
571
|
}
|
|
568
|
-
function
|
|
572
|
+
function Z(e, t) {
|
|
569
573
|
if (!e || typeof e != "object")
|
|
570
574
|
return [];
|
|
571
575
|
const s = e[t];
|
|
572
576
|
return Array.isArray(s) ? s.filter((n) => typeof n == "string" && n.trim().length > 0) : [];
|
|
573
577
|
}
|
|
574
|
-
function
|
|
578
|
+
function Q(e) {
|
|
575
579
|
return Array.isArray(e) ? e.filter((t) => typeof t == "string" && t.trim().length > 0) : [];
|
|
576
580
|
}
|
|
577
|
-
function
|
|
581
|
+
function tt(e) {
|
|
578
582
|
if (!e || typeof e != "object")
|
|
579
583
|
return null;
|
|
580
|
-
const t = e, s = t.appearance, n = s && typeof s == "object" ? s : t, r = typeof n.accentColor == "string" ? n.accentColor : null, i = n.colorScheme === "dark" ? "dark" : n.colorScheme === "light" ? "light" : null,
|
|
581
|
-
return !r && !i && !o ? null : {
|
|
584
|
+
const t = e, s = t.appearance, n = s && typeof s == "object" ? s : t, r = typeof n.accentColor == "string" ? n.accentColor : null, i = n.colorScheme === "dark" ? "dark" : n.colorScheme === "light" ? "light" : null, a = typeof n.fontFamily == "string" && n.fontFamily.trim() ? n.fontFamily : null, o = typeof n.scribbleStyle == "boolean" ? n.scribbleStyle : null;
|
|
585
|
+
return !r && !i && !a && o === null ? null : {
|
|
582
586
|
...r ? { accentColor: r } : {},
|
|
583
587
|
...i ? { colorScheme: i } : {},
|
|
584
|
-
...
|
|
588
|
+
...a ? { fontFamily: a } : {},
|
|
589
|
+
...o !== null ? { scribbleStyle: o } : {}
|
|
585
590
|
};
|
|
586
591
|
}
|
|
587
|
-
function
|
|
592
|
+
function et(e) {
|
|
588
593
|
if (!e || typeof e != "object")
|
|
589
594
|
return null;
|
|
590
595
|
const t = e.javascript;
|
|
591
596
|
return typeof t != "string" || !t.trim() ? null : { javascript: t };
|
|
592
597
|
}
|
|
593
|
-
function
|
|
598
|
+
function st(e, t) {
|
|
594
599
|
return t ? e && typeof e == "object" ? {
|
|
595
600
|
...e,
|
|
596
601
|
helperError: t
|
|
@@ -600,30 +605,30 @@ function et(e, t) {
|
|
|
600
605
|
helperError: t
|
|
601
606
|
} : e;
|
|
602
607
|
}
|
|
603
|
-
function
|
|
608
|
+
function nt(e) {
|
|
604
609
|
if (!e || typeof e != "object")
|
|
605
610
|
return e;
|
|
606
611
|
const t = e;
|
|
607
612
|
return typeof t.exception?.message == "string" ? t.exception.message : typeof t.error == "string" ? t.error : e;
|
|
608
613
|
}
|
|
609
|
-
function
|
|
614
|
+
function rt() {
|
|
610
615
|
const e = "pluno.productAgent.clientId", t = window.localStorage.getItem(e);
|
|
611
616
|
if (t)
|
|
612
617
|
return t;
|
|
613
618
|
const s = crypto.randomUUID();
|
|
614
619
|
return window.localStorage.setItem(e, s), s;
|
|
615
620
|
}
|
|
616
|
-
function
|
|
621
|
+
function it() {
|
|
617
622
|
const e = window.sessionStorage.getItem(R);
|
|
618
623
|
if (e)
|
|
619
624
|
return e;
|
|
620
625
|
const t = crypto.randomUUID();
|
|
621
626
|
return window.sessionStorage.setItem(R, t), t;
|
|
622
627
|
}
|
|
623
|
-
function
|
|
628
|
+
function ot() {
|
|
624
629
|
return crypto.randomUUID();
|
|
625
630
|
}
|
|
626
|
-
function
|
|
631
|
+
function at(e) {
|
|
627
632
|
if (!e || typeof e != "object")
|
|
628
633
|
return null;
|
|
629
634
|
const t = e, s = typeof t.id == "string" ? t.id : null;
|
|
@@ -634,7 +639,7 @@ function ot(e) {
|
|
|
634
639
|
avatarUrl: typeof t.avatarUrl == "string" ? t.avatarUrl : null
|
|
635
640
|
} : null;
|
|
636
641
|
}
|
|
637
|
-
function
|
|
642
|
+
function ct(e) {
|
|
638
643
|
return Array.isArray(e) ? _(
|
|
639
644
|
e.map(U).filter((t) => t !== null)
|
|
640
645
|
) : [];
|
|
@@ -651,29 +656,29 @@ function U(e) {
|
|
|
651
656
|
return {
|
|
652
657
|
id: String(t.id ?? crypto.randomUUID()),
|
|
653
658
|
role: r,
|
|
654
|
-
content:
|
|
659
|
+
content: ht(n.content),
|
|
655
660
|
createdAt: typeof t.createdAt == "string" ? t.createdAt : (/* @__PURE__ */ new Date()).toISOString()
|
|
656
661
|
};
|
|
657
662
|
}
|
|
658
663
|
return n.type === "function_call" || n.type === "tool_call" || n.type === "web_search_call" ? {
|
|
659
664
|
id: String(t.id ?? crypto.randomUUID()),
|
|
660
665
|
role: "tool",
|
|
661
|
-
content:
|
|
666
|
+
content: lt(n),
|
|
662
667
|
createdAt: typeof t.createdAt == "string" ? t.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
|
|
663
668
|
dataType: String(n.type),
|
|
664
669
|
loading: n.localExecutionStatus === "running"
|
|
665
670
|
} : 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 : {
|
|
666
671
|
id: String(t.id ?? crypto.randomUUID()),
|
|
667
672
|
role: "system",
|
|
668
|
-
content:
|
|
673
|
+
content: ut(n),
|
|
669
674
|
createdAt: typeof t.createdAt == "string" ? t.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
|
|
670
675
|
dataType: String(n.type)
|
|
671
676
|
} : null;
|
|
672
677
|
}
|
|
673
|
-
function
|
|
678
|
+
function ut(e) {
|
|
674
679
|
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.";
|
|
675
680
|
}
|
|
676
|
-
function
|
|
681
|
+
function lt(e) {
|
|
677
682
|
if (e.type === "web_search_call") {
|
|
678
683
|
const t = e.action;
|
|
679
684
|
if (t && typeof t == "object") {
|
|
@@ -685,9 +690,9 @@ function ut(e) {
|
|
|
685
690
|
}
|
|
686
691
|
return "Searching the web";
|
|
687
692
|
}
|
|
688
|
-
return
|
|
693
|
+
return dt(e);
|
|
689
694
|
}
|
|
690
|
-
function
|
|
695
|
+
function dt(e) {
|
|
691
696
|
if (typeof e.summary == "string" && e.summary.trim().length > 0)
|
|
692
697
|
return e.summary;
|
|
693
698
|
if (typeof e.arguments == "string")
|
|
@@ -700,7 +705,7 @@ function lt(e) {
|
|
|
700
705
|
}
|
|
701
706
|
return typeof e.name == "string" && e.name.trim().length > 0 ? e.name : "Run tool";
|
|
702
707
|
}
|
|
703
|
-
function
|
|
708
|
+
function ht(e) {
|
|
704
709
|
return typeof e == "string" ? e : Array.isArray(e) ? e.map((t) => {
|
|
705
710
|
if (!t || typeof t != "object")
|
|
706
711
|
return "";
|
|
@@ -708,14 +713,14 @@ function dt(e) {
|
|
|
708
713
|
return typeof s.text == "string" ? s.text : typeof s.content == "string" ? s.content : "";
|
|
709
714
|
}).filter(Boolean).join("") : "";
|
|
710
715
|
}
|
|
711
|
-
function
|
|
712
|
-
const s =
|
|
716
|
+
function pt(e, t) {
|
|
717
|
+
const s = gt(e, t), n = s.findIndex((i) => i.id === t.id);
|
|
713
718
|
if (n === -1)
|
|
714
719
|
return _([...s, t]);
|
|
715
720
|
const r = [...s];
|
|
716
721
|
return r[n] = t, _(r);
|
|
717
722
|
}
|
|
718
|
-
function
|
|
723
|
+
function gt(e, t) {
|
|
719
724
|
if (t.role !== "user")
|
|
720
725
|
return e;
|
|
721
726
|
const s = e.findIndex(
|
|
@@ -730,7 +735,7 @@ function b(e) {
|
|
|
730
735
|
const t = W(e);
|
|
731
736
|
return t === null ? !1 : e.slice(t + 1).some((s) => !s || typeof s != "object" ? !1 : I(s.data));
|
|
732
737
|
}
|
|
733
|
-
function
|
|
738
|
+
function ft(e) {
|
|
734
739
|
const t = W(e);
|
|
735
740
|
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));
|
|
736
741
|
}
|
|
@@ -761,12 +766,12 @@ function I(e) {
|
|
|
761
766
|
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");
|
|
762
767
|
}
|
|
763
768
|
function _(e) {
|
|
764
|
-
return e.filter((t, s) =>
|
|
769
|
+
return e.filter((t, s) => yt(t) ? !mt(e, s) : !0);
|
|
765
770
|
}
|
|
766
|
-
function
|
|
771
|
+
function yt(e) {
|
|
767
772
|
return e.role === "system" && (e.dataType === "run_status" || e.dataType === "run_error");
|
|
768
773
|
}
|
|
769
|
-
function
|
|
774
|
+
function mt(e, t) {
|
|
770
775
|
for (let s = t + 1; s < e.length; s += 1) {
|
|
771
776
|
const n = e[s];
|
|
772
777
|
if (n.role === "user")
|
|
@@ -779,12 +784,12 @@ function yt(e, t) {
|
|
|
779
784
|
function P(e, t) {
|
|
780
785
|
return e && typeof e == "object" && typeof e[t] == "string" ? e[t] : null;
|
|
781
786
|
}
|
|
782
|
-
function
|
|
787
|
+
function Tt(e) {
|
|
783
788
|
try {
|
|
784
789
|
const t = window.localStorage.getItem(`${O}${e}`);
|
|
785
790
|
if (!t)
|
|
786
791
|
return null;
|
|
787
|
-
const s = JSON.parse(t), n = Array.isArray(s.messages) ? s.messages.map(
|
|
792
|
+
const s = JSON.parse(t), n = Array.isArray(s.messages) ? s.messages.map(It).filter((r) => !!r) : [];
|
|
788
793
|
return {
|
|
789
794
|
sessionId: typeof s.sessionId == "string" ? s.sessionId : null,
|
|
790
795
|
messages: n
|
|
@@ -793,7 +798,7 @@ function mt(e) {
|
|
|
793
798
|
return null;
|
|
794
799
|
}
|
|
795
800
|
}
|
|
796
|
-
function
|
|
801
|
+
function St(e, t) {
|
|
797
802
|
try {
|
|
798
803
|
window.localStorage.setItem(
|
|
799
804
|
`${O}${e}`,
|
|
@@ -806,7 +811,7 @@ function Tt(e, t) {
|
|
|
806
811
|
return;
|
|
807
812
|
}
|
|
808
813
|
}
|
|
809
|
-
function
|
|
814
|
+
function kt(e) {
|
|
810
815
|
try {
|
|
811
816
|
const t = window.localStorage.getItem(`${k}${e}`);
|
|
812
817
|
if (!t)
|
|
@@ -844,7 +849,7 @@ function D(e) {
|
|
|
844
849
|
const t = e;
|
|
845
850
|
return typeof t.url == "string" && typeof t.title == "string" && typeof t.origin == "string";
|
|
846
851
|
}
|
|
847
|
-
function
|
|
852
|
+
function It(e) {
|
|
848
853
|
if (!e || typeof e != "object")
|
|
849
854
|
return null;
|
|
850
855
|
const t = e;
|
|
@@ -857,7 +862,7 @@ function kt(e) {
|
|
|
857
862
|
loading: typeof t.loading == "boolean" ? t.loading : void 0
|
|
858
863
|
};
|
|
859
864
|
}
|
|
860
|
-
function
|
|
865
|
+
function _t(e) {
|
|
861
866
|
return !!e && typeof e == "object" && typeof e.summary == "string" && typeof e.javascript == "string";
|
|
862
867
|
}
|
|
863
868
|
function H(e) {
|
|
@@ -866,7 +871,7 @@ function H(e) {
|
|
|
866
871
|
t[n] = s;
|
|
867
872
|
}), t;
|
|
868
873
|
}
|
|
869
|
-
async function
|
|
874
|
+
async function Et(e, t) {
|
|
870
875
|
if (typeof t?.body < "u")
|
|
871
876
|
return B(t.body);
|
|
872
877
|
if (e)
|
|
@@ -876,14 +881,14 @@ async function _t(e, t) {
|
|
|
876
881
|
return;
|
|
877
882
|
}
|
|
878
883
|
}
|
|
879
|
-
async function
|
|
884
|
+
async function wt(e) {
|
|
880
885
|
try {
|
|
881
886
|
return p(await e.clone().text());
|
|
882
887
|
} catch (t) {
|
|
883
888
|
return { error: t instanceof Error ? t.message : "unavailable" };
|
|
884
889
|
}
|
|
885
890
|
}
|
|
886
|
-
function
|
|
891
|
+
function At(e) {
|
|
887
892
|
try {
|
|
888
893
|
return e.responseType === "" || e.responseType === "text" ? p(e.responseText ?? "") : e.responseType === "json" ? p(JSON.stringify(e.response)) : `[unsupported xhr responseType: ${e.responseType || "unknown"}]`;
|
|
889
894
|
} catch (t) {
|
|
@@ -909,7 +914,7 @@ function B(e) {
|
|
|
909
914
|
}
|
|
910
915
|
}
|
|
911
916
|
}
|
|
912
|
-
function
|
|
917
|
+
function Ct(e) {
|
|
913
918
|
const t = {};
|
|
914
919
|
for (const s of e.trim().split(/[\r\n]+/)) {
|
|
915
920
|
const n = s.indexOf(":");
|
|
@@ -923,16 +928,16 @@ function p(e) {
|
|
|
923
928
|
function T(e) {
|
|
924
929
|
return `${e}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
925
930
|
}
|
|
926
|
-
const E = "[REDACTED_SECRET]", h = "[REDACTED_TOKEN]",
|
|
931
|
+
const E = "[REDACTED_SECRET]", h = "[REDACTED_TOKEN]", Rt = "[REDACTED_SIGNED_URL]", Mt = 20, bt = /^(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, L = /\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi, j = /\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, 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, Nt = /\bhttps?:\/\/[^\s"'<>]+(?:X-Amz-Signature|X-Goog-Signature|Signature|sig=)[^\s"'<>]*/gi, Pt = /\bhttps?:\/\/[^\s"'<>]+/gi, Dt = /[),.;\]]+$/;
|
|
927
932
|
function f(e) {
|
|
928
933
|
return S(e, 0, /* @__PURE__ */ new WeakSet());
|
|
929
934
|
}
|
|
930
935
|
function S(e, t, s) {
|
|
931
936
|
if (typeof e == "string")
|
|
932
|
-
return
|
|
937
|
+
return qt(e);
|
|
933
938
|
if (e === null || typeof e != "object")
|
|
934
939
|
return e;
|
|
935
|
-
if (t >=
|
|
940
|
+
if (t >= Mt)
|
|
936
941
|
return "[REDACTED_MAX_DEPTH]";
|
|
937
942
|
if (s.has(e))
|
|
938
943
|
return "[REDACTED_CIRCULAR]";
|
|
@@ -940,34 +945,34 @@ function S(e, t, s) {
|
|
|
940
945
|
return e.map((r) => S(r, t + 1, s));
|
|
941
946
|
const n = {};
|
|
942
947
|
for (const [r, i] of Object.entries(e))
|
|
943
|
-
|
|
948
|
+
Ht(r) ? n[r] = E : n[r] = r.toLowerCase() === "url" ? Ot(i) : S(i, t + 1, s);
|
|
944
949
|
return n;
|
|
945
950
|
}
|
|
946
|
-
function
|
|
951
|
+
function Ht(e) {
|
|
947
952
|
const t = e.replace(/[^a-z0-9]/gi, "").toLowerCase();
|
|
948
953
|
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");
|
|
949
954
|
}
|
|
950
|
-
function
|
|
955
|
+
function Ot(e) {
|
|
951
956
|
return typeof e == "string" ? $(e) : S(e, 0, /* @__PURE__ */ new WeakSet());
|
|
952
957
|
}
|
|
953
958
|
function $(e) {
|
|
954
959
|
try {
|
|
955
960
|
const t = new URL(e, location.href);
|
|
956
961
|
for (const s of Array.from(t.searchParams.keys()))
|
|
957
|
-
|
|
962
|
+
bt.test(s) && t.searchParams.set(s, h);
|
|
958
963
|
return t.username && (t.username = h), t.password && (t.password = h), t.toString();
|
|
959
964
|
} catch {
|
|
960
|
-
return
|
|
965
|
+
return Ut(e);
|
|
961
966
|
}
|
|
962
967
|
}
|
|
963
|
-
function Ot(e) {
|
|
964
|
-
return e.replace(bt, Ct).replace(Nt, Ut).replace(L, `Bearer ${h}`).replace(j, `Basic ${h}`).replace(G, h).replace(v, (t, s) => `${s}: ${E}`);
|
|
965
|
-
}
|
|
966
968
|
function qt(e) {
|
|
967
|
-
return e.replace(L, `Bearer ${h}`).replace(j, `Basic ${h}`).replace(
|
|
969
|
+
return e.replace(Nt, Rt).replace(Pt, Wt).replace(L, `Bearer ${h}`).replace(j, `Basic ${h}`).replace(v, h).replace(G, (t, s) => `${s}: ${E}`);
|
|
968
970
|
}
|
|
969
971
|
function Ut(e) {
|
|
970
|
-
|
|
972
|
+
return e.replace(L, `Bearer ${h}`).replace(j, `Basic ${h}`).replace(v, h).replace(G, (t, s) => `${s}: ${E}`);
|
|
973
|
+
}
|
|
974
|
+
function Wt(e) {
|
|
975
|
+
const t = e.match(Dt)?.[0] ?? "", s = t ? e.slice(0, -t.length) : e;
|
|
971
976
|
return `${$(s)}${t}`;
|
|
972
977
|
}
|
|
973
978
|
export {
|