@pluno/product-agent-web 0.1.7 → 0.1.9
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/dist/product-agent-widget.js +151 -127
- 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
|
};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { PlunoProductAgent as
|
|
2
|
-
const
|
|
1
|
+
import { PlunoProductAgent as I } from "./product-agent-sdk.js";
|
|
2
|
+
const S = {
|
|
3
3
|
launcherLabel: "Ask for anything...",
|
|
4
4
|
accentColor: "#18181b",
|
|
5
5
|
colorScheme: "light",
|
|
6
6
|
position: "bottom-right"
|
|
7
7
|
};
|
|
8
|
-
async function
|
|
8
|
+
async function K(e = {}) {
|
|
9
9
|
const t = {
|
|
10
|
-
launcherLabel: e.launcherLabel ??
|
|
11
|
-
accentColor: e.accentColor ??
|
|
12
|
-
colorScheme: e.colorScheme ??
|
|
13
|
-
position: e.position ??
|
|
10
|
+
launcherLabel: e.launcherLabel ?? S.launcherLabel,
|
|
11
|
+
accentColor: e.accentColor ?? S.accentColor,
|
|
12
|
+
colorScheme: e.colorScheme ?? S.colorScheme,
|
|
13
|
+
position: e.position ?? S.position,
|
|
14
14
|
token: e.token,
|
|
15
15
|
tokenProvider: e.tokenProvider,
|
|
16
16
|
tokenEndpoint: e.tokenEndpoint,
|
|
@@ -21,7 +21,7 @@ async function G(e = {}) {
|
|
|
21
21
|
const n = o.attachShadow({ mode: "open" }), a = document.createElement("div");
|
|
22
22
|
a.className = `pluno-pa-widget pluno-pa-widget--${t.position}`, a.innerHTML = `
|
|
23
23
|
<form class="pluno-pa-widget__launcher">
|
|
24
|
-
<input class="pluno-pa-widget__launcher-input" type="text" placeholder="${
|
|
24
|
+
<input class="pluno-pa-widget__launcher-input" type="text" placeholder="${B(t.launcherLabel)}" aria-label="${B(t.launcherLabel)}" />
|
|
25
25
|
</form>
|
|
26
26
|
<button type="button" class="pluno-pa-widget__close" aria-label="Close" hidden>
|
|
27
27
|
<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
|
@@ -53,12 +53,12 @@ async function G(e = {}) {
|
|
|
53
53
|
</form>
|
|
54
54
|
</section>
|
|
55
55
|
`, n.appendChild(a);
|
|
56
|
-
const w = await
|
|
57
|
-
w.appendChild(o), a.classList.add(`pluno-pa-widget--${t.colorScheme}`),
|
|
58
|
-
const l = a.querySelector(".pluno-pa-widget__launcher"), d = a.querySelector(".pluno-pa-widget__launcher-input"),
|
|
59
|
-
if (!l || !d || !
|
|
56
|
+
const w = await J(), s = w.ownerDocument;
|
|
57
|
+
w.appendChild(o), a.classList.add(`pluno-pa-widget--${t.colorScheme}`), U(n, t.accentColor);
|
|
58
|
+
const l = a.querySelector(".pluno-pa-widget__launcher"), d = a.querySelector(".pluno-pa-widget__launcher-input"), i = a.querySelector(".pluno-pa-widget__panel"), u = a.querySelector(".pluno-pa-widget__close"), h = a.querySelector(".pluno-pa-widget__composer"), r = a.querySelector(".pluno-pa-widget__input"), p = a.querySelector(".pluno-pa-widget__send"), g = a.querySelector(".pluno-pa-widget__new-chat"), f = a.querySelector(".pluno-pa-widget__timeline");
|
|
59
|
+
if (!l || !d || !i || !u || !h || !r || !p || !g || !f)
|
|
60
60
|
throw new Error("Failed to mount Product Agent widget");
|
|
61
|
-
const
|
|
61
|
+
const _ = t.token || t.webSocketFactory ? void 0 : t.tokenProvider ?? (async () => {
|
|
62
62
|
if (!t.tokenEndpoint)
|
|
63
63
|
throw new Error("Product Agent widget requires token or tokenEndpoint");
|
|
64
64
|
const c = await fetch(t.tokenEndpoint, {
|
|
@@ -69,99 +69,99 @@ async function G(e = {}) {
|
|
|
69
69
|
});
|
|
70
70
|
if (!c.ok)
|
|
71
71
|
throw new Error("Failed to load Product Agent token");
|
|
72
|
-
const
|
|
73
|
-
if (!
|
|
72
|
+
const v = await c.json();
|
|
73
|
+
if (!v.token)
|
|
74
74
|
throw new Error("Product Agent token endpoint did not return a token");
|
|
75
|
-
return
|
|
76
|
-
}), m = await
|
|
75
|
+
return v.token;
|
|
76
|
+
}), m = await I.init({
|
|
77
77
|
token: t.token,
|
|
78
|
-
tokenProvider:
|
|
78
|
+
tokenProvider: _,
|
|
79
79
|
backendUrl: t.backendUrl,
|
|
80
80
|
webSocketFactory: t.webSocketFactory
|
|
81
|
-
}),
|
|
82
|
-
let
|
|
81
|
+
}), C = Z(t), E = new Set(C.openToolGroupKeys);
|
|
82
|
+
let b = null, z = !1;
|
|
83
83
|
const q = () => {
|
|
84
|
-
|
|
85
|
-
},
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
|
|
84
|
+
z || typeof document > "u" || (U(n, t.accentColor), o.isConnected || s.body?.appendChild(o));
|
|
85
|
+
}, M = new MutationObserver(q);
|
|
86
|
+
M.observe(s.documentElement, { childList: !0, subtree: !0 });
|
|
87
|
+
const x = () => {
|
|
88
|
+
Q(t, {
|
|
89
89
|
isOpen: a.classList.contains("pluno-pa-widget--open"),
|
|
90
|
-
composerValue:
|
|
91
|
-
openToolGroupKeys: [...
|
|
90
|
+
composerValue: r.value,
|
|
91
|
+
openToolGroupKeys: [...E]
|
|
92
92
|
});
|
|
93
|
-
},
|
|
94
|
-
if (
|
|
95
|
-
a.classList.add("pluno-pa-widget--open"), l.hidden = !0, c && (
|
|
93
|
+
}, y = (c = "", v = !0) => {
|
|
94
|
+
if (b !== null && (window.clearTimeout(b), b = null), i.hidden = !1, u.hidden = !1, a.classList.remove("pluno-pa-widget--closing"), !v) {
|
|
95
|
+
a.classList.add("pluno-pa-widget--open"), l.hidden = !0, c && (r.value = c, k(r)), r.focus(), r.setSelectionRange(r.value.length, r.value.length), x();
|
|
96
96
|
return;
|
|
97
97
|
}
|
|
98
98
|
window.requestAnimationFrame(() => {
|
|
99
|
-
a.classList.add("pluno-pa-widget--open"), c && (
|
|
99
|
+
a.classList.add("pluno-pa-widget--open"), c && (r.value = c, k(r)), r.focus(), r.setSelectionRange(r.value.length, r.value.length), x(), b = window.setTimeout(() => {
|
|
100
100
|
l.hidden = !0;
|
|
101
101
|
}, 220);
|
|
102
102
|
});
|
|
103
|
-
},
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
}, N = () => {
|
|
104
|
+
b !== null && (window.clearTimeout(b), b = null), l.hidden = !1, a.classList.add("pluno-pa-widget--closing"), a.classList.remove("pluno-pa-widget--open"), x(), b = window.setTimeout(() => {
|
|
105
|
+
i.hidden = !0, u.hidden = !0, a.classList.remove("pluno-pa-widget--closing");
|
|
106
106
|
}, 220);
|
|
107
107
|
};
|
|
108
108
|
l.addEventListener("submit", (c) => {
|
|
109
|
-
c.preventDefault(),
|
|
109
|
+
c.preventDefault(), y(d.value), d.value = "";
|
|
110
110
|
}), d.addEventListener("focus", () => {
|
|
111
|
-
|
|
111
|
+
y(d.value), d.value = "";
|
|
112
112
|
}), d.addEventListener("input", () => {
|
|
113
113
|
if (!d.value)
|
|
114
114
|
return;
|
|
115
115
|
const c = d.value;
|
|
116
|
-
|
|
117
|
-
}), u.addEventListener("click",
|
|
118
|
-
const
|
|
116
|
+
y(c), d.value = "";
|
|
117
|
+
}), u.addEventListener("click", N);
|
|
118
|
+
const P = (c) => {
|
|
119
119
|
if (!(!c.metaKey || c.key.toLowerCase() !== "k")) {
|
|
120
|
-
if (c.preventDefault(),
|
|
121
|
-
|
|
120
|
+
if (c.preventDefault(), i.hidden || !a.classList.contains("pluno-pa-widget--open")) {
|
|
121
|
+
y();
|
|
122
122
|
return;
|
|
123
123
|
}
|
|
124
|
-
|
|
124
|
+
N();
|
|
125
125
|
}
|
|
126
126
|
};
|
|
127
|
-
return s.addEventListener("keydown",
|
|
128
|
-
c.preventDefault(),
|
|
127
|
+
return s.addEventListener("keydown", P), h.addEventListener("submit", (c) => {
|
|
128
|
+
c.preventDefault(), T(m, r);
|
|
129
129
|
}), p.addEventListener("click", () => {
|
|
130
130
|
if (m.getState().isThinking) {
|
|
131
131
|
m.stop();
|
|
132
132
|
return;
|
|
133
133
|
}
|
|
134
|
-
|
|
134
|
+
T(m, r);
|
|
135
135
|
}), g.addEventListener("click", () => {
|
|
136
|
-
m.startNewSession(),
|
|
137
|
-
}),
|
|
138
|
-
|
|
139
|
-
}),
|
|
140
|
-
c.key !== "Enter" || c.shiftKey || (c.preventDefault(),
|
|
141
|
-
}),
|
|
136
|
+
m.startNewSession(), E.clear(), r.value = "", k(r), x(), r.focus();
|
|
137
|
+
}), r.addEventListener("input", () => {
|
|
138
|
+
k(r), x();
|
|
139
|
+
}), r.addEventListener("keydown", (c) => {
|
|
140
|
+
c.key !== "Enter" || c.shiftKey || (c.preventDefault(), T(m, r));
|
|
141
|
+
}), C.composerValue && (r.value = C.composerValue, k(r)), C.isOpen && y(r.value, !1), m.on(
|
|
142
142
|
"state",
|
|
143
|
-
(c) =>
|
|
144
|
-
m.sendMessage(
|
|
143
|
+
(c) => A(f, p, g, c, E, x, (v) => {
|
|
144
|
+
m.sendMessage(v);
|
|
145
145
|
})
|
|
146
|
-
),
|
|
146
|
+
), A(f, p, g, m.getState(), E, x, (c) => {
|
|
147
147
|
m.sendMessage(c);
|
|
148
148
|
}), {
|
|
149
149
|
agent: m,
|
|
150
150
|
destroy: () => {
|
|
151
|
-
|
|
151
|
+
z = !0, M.disconnect(), m.destroy(), s.removeEventListener("keydown", P), o.remove();
|
|
152
152
|
}
|
|
153
153
|
};
|
|
154
154
|
}
|
|
155
|
-
function
|
|
155
|
+
function T(e, t) {
|
|
156
156
|
const o = t.value.trim();
|
|
157
157
|
o && (t.value = "", t.style.height = "22px", t.style.overflowY = "hidden", e.sendMessage(o), t.dispatchEvent(new Event("input", { bubbles: !0 })));
|
|
158
158
|
}
|
|
159
|
-
function
|
|
159
|
+
function k(e) {
|
|
160
160
|
e.style.height = "0px";
|
|
161
161
|
const t = Math.max(22, Math.min(e.scrollHeight, 140));
|
|
162
162
|
e.style.height = `${t}px`, e.style.overflowY = e.scrollHeight > 140 ? "auto" : "hidden";
|
|
163
163
|
}
|
|
164
|
-
function
|
|
164
|
+
function A(e, t, o, n, a, w, s) {
|
|
165
165
|
const l = [...n.messages];
|
|
166
166
|
e.innerHTML = "", V(t, n.isThinking);
|
|
167
167
|
const d = l.length > 0 || !!n.assistantDraft;
|
|
@@ -170,25 +170,25 @@ function $(e, t, o, n, a, w, s) {
|
|
|
170
170
|
p.className = n.starterPrompts.length > 0 ? "pluno-pa-widget__empty-state pluno-pa-widget__empty-state--starter" : "pluno-pa-widget__empty-state";
|
|
171
171
|
const g = document.createElement("div");
|
|
172
172
|
if (g.className = "pluno-pa-widget__empty", g.textContent = "What do you want to do today?", p.appendChild(g), n.starterPrompts.length > 0) {
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
for (const
|
|
173
|
+
const f = document.createElement("div");
|
|
174
|
+
f.className = "pluno-pa-widget__starter-prompts";
|
|
175
|
+
for (const _ of n.starterPrompts) {
|
|
176
176
|
const m = document.createElement("button");
|
|
177
|
-
m.type = "button", m.className = "pluno-pa-widget__starter-prompt", m.textContent = `"${
|
|
178
|
-
s(
|
|
179
|
-
}),
|
|
177
|
+
m.type = "button", m.className = "pluno-pa-widget__starter-prompt", m.textContent = `"${_}"`, m.addEventListener("click", () => {
|
|
178
|
+
s(_);
|
|
179
|
+
}), f.appendChild(m);
|
|
180
180
|
}
|
|
181
|
-
p.appendChild(
|
|
181
|
+
p.appendChild(f);
|
|
182
182
|
}
|
|
183
183
|
e.appendChild(p);
|
|
184
184
|
return;
|
|
185
185
|
}
|
|
186
|
-
let
|
|
187
|
-
const
|
|
186
|
+
let i = null, u = null, h = [];
|
|
187
|
+
const r = () => {
|
|
188
188
|
if (h.length === 0)
|
|
189
189
|
return;
|
|
190
|
-
const p =
|
|
191
|
-
e.appendChild(p),
|
|
190
|
+
const p = R(h, a, w);
|
|
191
|
+
e.appendChild(p), i = null, u = p, h = [];
|
|
192
192
|
};
|
|
193
193
|
for (let p = 0; p < l.length; p += 1) {
|
|
194
194
|
const g = l[p];
|
|
@@ -198,67 +198,67 @@ function $(e, t, o, n, a, w, s) {
|
|
|
198
198
|
}
|
|
199
199
|
if (g.role === "system")
|
|
200
200
|
continue;
|
|
201
|
-
|
|
202
|
-
const
|
|
203
|
-
|
|
201
|
+
r();
|
|
202
|
+
const f = D(g.content), _ = document.createElement("div");
|
|
203
|
+
_.className = `pluno-pa-widget__message pluno-pa-widget__message--${g.role}`, g.role === "assistant" ? j(_, f) : _.textContent = f, _.appendChild($(f)), e.appendChild(_), i = _, u = null;
|
|
204
204
|
}
|
|
205
|
-
if (
|
|
206
|
-
const p =
|
|
207
|
-
g.className = "pluno-pa-widget__message pluno-pa-widget__message--assistant",
|
|
205
|
+
if (r(), n.assistantDraft) {
|
|
206
|
+
const p = D(n.assistantDraft), g = document.createElement("div");
|
|
207
|
+
g.className = "pluno-pa-widget__message pluno-pa-widget__message--assistant", j(g, p), g.appendChild($(p)), e.appendChild(g), i = g, u = null;
|
|
208
208
|
}
|
|
209
209
|
if (n.isThinking && !n.assistantDraft) {
|
|
210
210
|
const p = document.createElement("div");
|
|
211
|
-
p.className = "pluno-pa-widget__status", p.textContent = "Thinking...", e.appendChild(p),
|
|
211
|
+
p.className = "pluno-pa-widget__status", p.textContent = "Thinking...", e.appendChild(p), i = null, u = p;
|
|
212
212
|
}
|
|
213
213
|
if (n.lastError) {
|
|
214
214
|
const p = document.createElement("div");
|
|
215
|
-
p.className = "pluno-pa-widget__error", p.textContent = n.lastError, e.appendChild(p),
|
|
215
|
+
p.className = "pluno-pa-widget__error", p.textContent = n.lastError, e.appendChild(p), i = p, u = null;
|
|
216
216
|
}
|
|
217
|
-
|
|
217
|
+
i?.classList.add("pluno-pa-widget__message--bottom-reserve"), u?.classList.add("pluno-pa-widget__bottom-reserve-compact"), e.scrollTop = e.scrollHeight;
|
|
218
218
|
}
|
|
219
|
-
function
|
|
219
|
+
function $(e) {
|
|
220
220
|
const t = document.createElement("button");
|
|
221
221
|
return t.type = "button", t.className = "pluno-pa-widget__message-copy", t.setAttribute("aria-label", "Copy message"), t.title = "Copy message", t.innerHTML = '<svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"></rect><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"></path></svg>', t.addEventListener("click", (o) => {
|
|
222
222
|
o.preventDefault(), o.stopPropagation(), navigator.clipboard.writeText(e);
|
|
223
223
|
}), t;
|
|
224
224
|
}
|
|
225
|
-
function
|
|
225
|
+
function D(e) {
|
|
226
226
|
return e.replace(/\uE200[^\uE201]*(?:\uE201|$)/g, "");
|
|
227
227
|
}
|
|
228
|
-
function
|
|
228
|
+
function R(e, t, o) {
|
|
229
229
|
const n = document.createElement("article");
|
|
230
230
|
n.className = "pluno-pa-widget__tool-group", n.title = new Date(e[e.length - 1].createdAt).toLocaleString();
|
|
231
|
-
const a = document.createElement("details"), w =
|
|
231
|
+
const a = document.createElement("details"), w = G(e);
|
|
232
232
|
a.open = t.has(w), a.addEventListener("toggle", () => {
|
|
233
233
|
a.open ? t.add(w) : t.delete(w), o();
|
|
234
234
|
});
|
|
235
235
|
const s = document.createElement("summary");
|
|
236
|
-
s.className = "pluno-pa-widget__tool-summary", e.some((
|
|
236
|
+
s.className = "pluno-pa-widget__tool-summary", e.some((i) => i.loading) && s.appendChild(O());
|
|
237
237
|
const d = document.createElement("span");
|
|
238
238
|
if (d.textContent = e[e.length - 1].content || "Run tool", s.appendChild(d), a.appendChild(s), e.length > 0) {
|
|
239
|
-
const
|
|
240
|
-
|
|
239
|
+
const i = document.createElement("div");
|
|
240
|
+
i.className = "pluno-pa-widget__tool-lines";
|
|
241
241
|
for (const u of e) {
|
|
242
242
|
const h = document.createElement("div");
|
|
243
|
-
h.className = "pluno-pa-widget__tool-line", u.loading && h.appendChild(
|
|
244
|
-
const
|
|
245
|
-
|
|
243
|
+
h.className = "pluno-pa-widget__tool-line", u.loading && h.appendChild(O());
|
|
244
|
+
const r = document.createElement("span");
|
|
245
|
+
r.textContent = u.content || "Run tool", h.appendChild(r), i.appendChild(h);
|
|
246
246
|
}
|
|
247
|
-
a.appendChild(
|
|
247
|
+
a.appendChild(i);
|
|
248
248
|
}
|
|
249
249
|
return n.appendChild(a), n;
|
|
250
250
|
}
|
|
251
|
-
function
|
|
251
|
+
function G(e) {
|
|
252
252
|
return `tools:${e.map((t) => t.id).join("|")}`;
|
|
253
253
|
}
|
|
254
|
-
function
|
|
254
|
+
function O() {
|
|
255
255
|
const e = document.createElement("span");
|
|
256
256
|
return e.className = "pluno-pa-widget__spinner", e.setAttribute("aria-hidden", "true"), e;
|
|
257
257
|
}
|
|
258
258
|
function V(e, t) {
|
|
259
259
|
e.setAttribute("aria-label", t ? "Stop" : "Send"), e.classList.toggle("pluno-pa-widget__send--stop", t), e.innerHTML = t ? '<svg viewBox="0 0 24 24" width="18" height="18" fill="currentColor" aria-hidden="true"><rect x="6" y="6" width="12" height="12" rx="2" /></svg>' : '<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><line x1="12" y1="19" x2="12" y2="5" /><polyline points="5 12 12 5 19 12" /></svg>';
|
|
260
260
|
}
|
|
261
|
-
function
|
|
261
|
+
function j(e, t) {
|
|
262
262
|
const o = t.replace(/\r\n/g, `
|
|
263
263
|
`).split(`
|
|
264
264
|
`);
|
|
@@ -270,49 +270,49 @@ function B(e, t) {
|
|
|
270
270
|
continue;
|
|
271
271
|
}
|
|
272
272
|
if (a.match(/^```(\w+)?\s*$/)) {
|
|
273
|
-
const
|
|
273
|
+
const i = [];
|
|
274
274
|
for (n += 1; n < o.length && !/^```\s*$/.test(o[n]); )
|
|
275
|
-
|
|
275
|
+
i.push(o[n]), n += 1;
|
|
276
276
|
n += n < o.length ? 1 : 0;
|
|
277
277
|
const u = document.createElement("pre"), h = document.createElement("code");
|
|
278
|
-
h.textContent =
|
|
278
|
+
h.textContent = i.join(`
|
|
279
279
|
`), u.appendChild(h), e.appendChild(u);
|
|
280
280
|
continue;
|
|
281
281
|
}
|
|
282
282
|
const s = a.match(/^(#{1,3})\s+(.+)$/);
|
|
283
283
|
if (s) {
|
|
284
|
-
const
|
|
285
|
-
|
|
284
|
+
const i = document.createElement(`h${s[1].length + 2}`);
|
|
285
|
+
L(i, s[2]), e.appendChild(i), n += 1;
|
|
286
286
|
continue;
|
|
287
287
|
}
|
|
288
288
|
if (/^\s*[-*+]\s+/.test(a)) {
|
|
289
|
-
const
|
|
289
|
+
const i = document.createElement("ul");
|
|
290
290
|
for (; n < o.length && /^\s*[-*+]\s+/.test(o[n]); ) {
|
|
291
291
|
const u = document.createElement("li");
|
|
292
|
-
|
|
292
|
+
L(u, o[n].replace(/^\s*[-*+]\s+/, "")), i.appendChild(u), n += 1;
|
|
293
293
|
}
|
|
294
|
-
e.appendChild(
|
|
294
|
+
e.appendChild(i);
|
|
295
295
|
continue;
|
|
296
296
|
}
|
|
297
297
|
if (/^\s*\d+\.\s+/.test(a)) {
|
|
298
|
-
const
|
|
298
|
+
const i = document.createElement("ol");
|
|
299
299
|
for (; n < o.length && /^\s*\d+\.\s+/.test(o[n]); ) {
|
|
300
300
|
const u = document.createElement("li");
|
|
301
|
-
|
|
301
|
+
L(u, o[n].replace(/^\s*\d+\.\s+/, "")), i.appendChild(u), n += 1;
|
|
302
302
|
}
|
|
303
|
-
e.appendChild(
|
|
303
|
+
e.appendChild(i);
|
|
304
304
|
continue;
|
|
305
305
|
}
|
|
306
306
|
const l = [a];
|
|
307
307
|
for (n += 1; n < o.length && o[n].trim() && !/^```/.test(o[n]) && !/^(#{1,3})\s+/.test(o[n]) && !/^\s*[-*+]\s+/.test(o[n]) && !/^\s*\d+\.\s+/.test(o[n]); )
|
|
308
308
|
l.push(o[n]), n += 1;
|
|
309
309
|
const d = document.createElement("p");
|
|
310
|
-
l.forEach((
|
|
311
|
-
u > 0 && d.appendChild(document.createElement("br")),
|
|
310
|
+
l.forEach((i, u) => {
|
|
311
|
+
u > 0 && d.appendChild(document.createElement("br")), L(d, i);
|
|
312
312
|
}), e.appendChild(d);
|
|
313
313
|
}
|
|
314
314
|
}
|
|
315
|
-
function
|
|
315
|
+
function L(e, t) {
|
|
316
316
|
const o = /(`[^`]+`|\*\*[^*]+\*\*|\*[^*]+\*|\[[^\]]+\]\(([^)\s]+)\))/g;
|
|
317
317
|
let n = 0;
|
|
318
318
|
for (const a of t.matchAll(o)) {
|
|
@@ -350,7 +350,7 @@ function Y(e) {
|
|
|
350
350
|
return !1;
|
|
351
351
|
}
|
|
352
352
|
}
|
|
353
|
-
function
|
|
353
|
+
function U(e, t) {
|
|
354
354
|
if (e.getElementById("pluno-pa-widget-styles"))
|
|
355
355
|
return;
|
|
356
356
|
const o = e.ownerDocument.createElement("style");
|
|
@@ -1023,7 +1023,7 @@ function F(e, t) {
|
|
|
1023
1023
|
}
|
|
1024
1024
|
`, e.appendChild(o);
|
|
1025
1025
|
}
|
|
1026
|
-
async function
|
|
1026
|
+
async function J() {
|
|
1027
1027
|
return document.body ? document.body : await new Promise((e) => {
|
|
1028
1028
|
const t = new MutationObserver(() => {
|
|
1029
1029
|
document.body && (t.disconnect(), e(document.body));
|
|
@@ -1031,16 +1031,16 @@ async function R() {
|
|
|
1031
1031
|
t.observe(document.documentElement, { childList: !0 });
|
|
1032
1032
|
});
|
|
1033
1033
|
}
|
|
1034
|
-
function
|
|
1034
|
+
function B(e) {
|
|
1035
1035
|
const t = document.createElement("span");
|
|
1036
1036
|
return t.textContent = e, t.innerHTML;
|
|
1037
1037
|
}
|
|
1038
|
-
function
|
|
1038
|
+
function F(e) {
|
|
1039
1039
|
return `pluno.productAgent.widgetState.${location.origin}.${e.backendUrl ?? ""}.${e.tokenEndpoint ?? ""}.${e.position ?? ""}`;
|
|
1040
1040
|
}
|
|
1041
|
-
function
|
|
1041
|
+
function Z(e) {
|
|
1042
1042
|
try {
|
|
1043
|
-
const t = window.localStorage.getItem(
|
|
1043
|
+
const t = window.localStorage.getItem(F(e));
|
|
1044
1044
|
if (!t)
|
|
1045
1045
|
return { isOpen: !1, composerValue: "", openToolGroupKeys: [] };
|
|
1046
1046
|
const o = JSON.parse(t);
|
|
@@ -1053,25 +1053,49 @@ function J(e) {
|
|
|
1053
1053
|
return { isOpen: !1, composerValue: "", openToolGroupKeys: [] };
|
|
1054
1054
|
}
|
|
1055
1055
|
}
|
|
1056
|
-
function
|
|
1056
|
+
function Q(e, t) {
|
|
1057
1057
|
try {
|
|
1058
|
-
window.localStorage.setItem(
|
|
1058
|
+
window.localStorage.setItem(F(e), JSON.stringify(t));
|
|
1059
1059
|
} catch {
|
|
1060
1060
|
return;
|
|
1061
1061
|
}
|
|
1062
1062
|
}
|
|
1063
|
-
const
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
}
|
|
1063
|
+
const W = /* @__PURE__ */ new WeakSet();
|
|
1064
|
+
function X(e) {
|
|
1065
|
+
return Object.keys(e.dataset).some((t) => t.startsWith("pluno"));
|
|
1066
|
+
}
|
|
1067
|
+
function H(e) {
|
|
1068
|
+
const t = e.pathname.split("/");
|
|
1069
|
+
return t[t.length - 1] ?? "";
|
|
1070
|
+
}
|
|
1071
|
+
function ee(e, t) {
|
|
1072
|
+
const o = new URL(e.src, document.baseURI);
|
|
1073
|
+
return o.href === t.href || o.pathname === t.pathname ? !0 : H(o) === H(t);
|
|
1074
|
+
}
|
|
1075
|
+
function te(e) {
|
|
1076
|
+
const t = document.currentScript;
|
|
1077
|
+
if (t instanceof HTMLScriptElement)
|
|
1078
|
+
return [t];
|
|
1079
|
+
const o = new URL(e, document.baseURI).href, n = new URL(o);
|
|
1080
|
+
return [...document.querySelectorAll("script[type='module'][src]")].filter(
|
|
1081
|
+
(a) => a instanceof HTMLScriptElement && X(a) && ee(a, n)
|
|
1082
|
+
);
|
|
1083
|
+
}
|
|
1084
|
+
function ne(e) {
|
|
1085
|
+
for (const t of te(e))
|
|
1086
|
+
W.has(t) || t.dataset.plunoAutoMount === "false" || (W.add(t), K({
|
|
1087
|
+
token: t.dataset.plunoToken,
|
|
1088
|
+
tokenEndpoint: t.dataset.plunoTokenEndpoint,
|
|
1089
|
+
backendUrl: t.dataset.plunoBackendUrl,
|
|
1090
|
+
launcherLabel: t.dataset.plunoLauncherLabel,
|
|
1091
|
+
accentColor: t.dataset.plunoAccentColor,
|
|
1092
|
+
colorScheme: t.dataset.plunoColorScheme === "dark" ? "dark" : "light",
|
|
1093
|
+
position: t.dataset.plunoPosition === "bottom-left" ? "bottom-left" : "bottom-right"
|
|
1094
|
+
}).catch((o) => {
|
|
1095
|
+
console.error("Failed to mount Pluno Product Agent widget", o);
|
|
1096
|
+
}));
|
|
1097
|
+
}
|
|
1098
|
+
ne(import.meta.url);
|
|
1075
1099
|
export {
|
|
1076
|
-
|
|
1100
|
+
K as mountPlunoProductAgentWidget
|
|
1077
1101
|
};
|
package/package.json
CHANGED