@pluno/product-agent-web 0.1.4 → 0.1.6

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.
@@ -1,9 +1,9 @@
1
- const O = "https://app.pluno.ai";
2
- const k = "pluno.productAgent.state.";
3
- class I {
1
+ const P = "https://app.pluno.ai";
2
+ const I = "pluno.productAgent.state.";
3
+ class k {
4
4
  constructor(t) {
5
5
  this.options = t;
6
- const s = v(t.clientId);
6
+ const s = Q(t.clientId);
7
7
  s && (this.state = {
8
8
  ...this.state,
9
9
  ...s,
@@ -36,10 +36,10 @@ class I {
36
36
  lastError: null
37
37
  };
38
38
  static async init(t) {
39
- const s = new I({
39
+ const s = new k({
40
40
  ...t,
41
- backendUrl: U(t.backendUrl ?? O),
42
- clientId: t.clientId ?? $()
41
+ backendUrl: B(t.backendUrl ?? P),
42
+ clientId: t.clientId ?? j()
43
43
  });
44
44
  try {
45
45
  s.enableNetworkCapture(), t.autoConnect !== !1 && await s.connect();
@@ -64,10 +64,10 @@ class I {
64
64
  return;
65
65
  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)
66
66
  throw new Error("Product Agent requires a token or tokenProvider");
67
- const t = B(this.options.backendUrl);
67
+ const t = L(this.options.backendUrl);
68
68
  this.socket = this.options.webSocketFactory?.(t) ?? new WebSocket(t), this.socket.addEventListener("open", () => {
69
69
  this.token && this.sendNow({ type: "auth.session", token: this.token, clientId: this.options.clientId }), this.flushQueuedClientEvents(), this.startHeartbeat(), this.setState({ status: "connected", lastError: null });
70
- }), this.socket.addEventListener("message", (s) => this.handleServerEvent(L(s.data))), this.socket.addEventListener("close", () => {
70
+ }), this.socket.addEventListener("message", (s) => this.handleServerEvent(x(s.data))), this.socket.addEventListener("close", () => {
71
71
  this.stopHeartbeat(), this.socket = null, this.state.status !== "closed" && (this.setState({ status: "reconnecting" }), this.scheduleReconnect());
72
72
  }), this.socket.addEventListener("error", () => {
73
73
  this.setState({ status: "error", lastError: "Product Agent connection failed" });
@@ -85,7 +85,7 @@ class I {
85
85
  const s = t.trim();
86
86
  if (!s)
87
87
  return;
88
- const n = m(), r = j(), o = {
88
+ const n = g(), r = X(), o = {
89
89
  id: `local-${r}`,
90
90
  role: "user",
91
91
  content: s,
@@ -113,7 +113,7 @@ class I {
113
113
  this.state.sessionId && this.state.isThinking && this.sendNow({ type: "run.stop", sessionId: this.state.sessionId }), this.queuedClientEvents = this.queuedClientEvents.filter((t) => t.type !== "chat.user_message"), this.send({
114
114
  type: "session.reset",
115
115
  sessionId: this.state.sessionId ?? void 0,
116
- page: m()
116
+ page: g()
117
117
  }), this.setState({
118
118
  sessionId: null,
119
119
  starterPrompts: [...this.state.starterPrompts],
@@ -124,7 +124,7 @@ class I {
124
124
  });
125
125
  }
126
126
  send(t) {
127
- this.sendNow(h(t)) || (this.queuedClientEvents.push(t), this.setState({ status: "reconnecting" }), this.scheduleReconnect());
127
+ this.sendNow(f(t)) || (this.queuedClientEvents.push(t), this.setState({ status: "reconnecting" }), this.scheduleReconnect());
128
128
  }
129
129
  sendNow(t) {
130
130
  return !this.socket || this.socket.readyState !== WebSocket.OPEN ? !1 : (this.socket.send(JSON.stringify(t)), !0);
@@ -135,7 +135,7 @@ class I {
135
135
  const t = this.queuedClientEvents.splice(0, this.queuedClientEvents.length);
136
136
  for (let s = 0; s < t.length; s += 1) {
137
137
  const n = t[s];
138
- if (!this.sendNow(h(n))) {
138
+ if (!this.sendNow(f(n))) {
139
139
  this.queuedClientEvents.unshift(n, ...t.slice(s + 1));
140
140
  return;
141
141
  }
@@ -144,16 +144,23 @@ class I {
144
144
  handleServerEvent(t) {
145
145
  if (t.type === "auth.ok") {
146
146
  this.setState({
147
- user: X(t.user),
148
- starterPrompts: x(t, "starterPrompts"),
147
+ user: z(t.user),
148
+ starterPrompts: $(t, "starterPrompts"),
149
149
  status: "connected"
150
+ }), this.state.sessionId && this.send({
151
+ type: "page.upsert",
152
+ sessionId: this.state.sessionId,
153
+ page: g(),
154
+ model: this.options.model
150
155
  });
151
156
  return;
152
157
  }
153
158
  if (t.type === "conversation.state") {
159
+ const s = Array.isArray(t.items) ? t.items : [];
154
160
  this.setState({
155
161
  sessionId: _(t.session, "id") ?? this.state.sessionId,
156
- messages: z(t.items)
162
+ messages: F(s),
163
+ ...V(s) ? { assistantDraft: "", isThinking: !1 } : {}
157
164
  });
158
165
  return;
159
166
  }
@@ -164,8 +171,9 @@ class I {
164
171
  if (t.type === "session.item") {
165
172
  const s = R(t.item);
166
173
  s && (this.setState({
167
- messages: J(this.state.messages, s),
168
- assistantDraft: s.role === "assistant" ? "" : this.state.assistantDraft
174
+ messages: v(this.state.messages, s),
175
+ assistantDraft: s.role === "assistant" ? "" : this.state.assistantDraft,
176
+ ...C(t.item.data) ? { assistantDraft: "", isThinking: !1 } : {}
169
177
  }), this.emit("message", s));
170
178
  return;
171
179
  }
@@ -209,7 +217,7 @@ class I {
209
217
  }
210
218
  async executeToolCall(t) {
211
219
  const s = typeof t.sessionId == "string" ? t.sessionId : null, n = typeof t.callId == "string" ? t.callId : null, r = t.rawInput;
212
- if (!s || !n || !Z(r))
220
+ if (!s || !n || !st(r))
213
221
  return;
214
222
  const o = await H(r).catch((a) => ({
215
223
  ok: !1,
@@ -223,8 +231,8 @@ class I {
223
231
  callId: n,
224
232
  toolName: "execute_code",
225
233
  summary: r.summary,
226
- rawInput: h(r),
227
- rawOutput: h(o)
234
+ rawInput: f(r),
235
+ rawOutput: f(o)
228
236
  });
229
237
  }
230
238
  enableNetworkCapture() {
@@ -232,28 +240,28 @@ class I {
232
240
  return;
233
241
  const t = window.fetch.bind(window), s = XMLHttpRequest.prototype.open, n = XMLHttpRequest.prototype.setRequestHeader, r = XMLHttpRequest.prototype.send;
234
242
  window.fetch = async (o, a) => {
235
- const i = Date.now(), c = new Date(i).toISOString(), u = o instanceof Request ? o : null, f = typeof o == "string" ? o : o instanceof URL ? o.toString() : u?.url ?? "", E = (a?.method ?? u?.method ?? "GET").toUpperCase(), w = A(new Headers(a?.headers ?? u?.headers ?? void 0)), T = await Q(u, a);
243
+ const i = Date.now(), c = new Date(i).toISOString(), u = o instanceof Request ? o : null, h = typeof o == "string" ? o : o instanceof URL ? o.toString() : u?.url ?? "", w = (a?.method ?? u?.method ?? "GET").toUpperCase(), E = A(new Headers(a?.headers ?? u?.headers ?? void 0)), T = await nt(u, a);
236
244
  try {
237
245
  const l = await t(o, a);
238
246
  return this.enqueueNetworkEvent({
239
- requestId: g("fetch"),
240
- url: f,
241
- method: E,
242
- requestHeaders: w,
247
+ requestId: y("fetch"),
248
+ url: h,
249
+ method: w,
250
+ requestHeaders: E,
243
251
  requestBody: T,
244
252
  resourceType: "fetch",
245
253
  responseStatus: l.status,
246
254
  responseHeaders: A(l.headers),
247
- responseBody: await tt(l),
255
+ responseBody: await rt(l),
248
256
  startedAt: c,
249
257
  durationMs: Date.now() - i
250
258
  }), l;
251
259
  } catch (l) {
252
260
  throw this.enqueueNetworkEvent({
253
- requestId: g("fetch"),
254
- url: f,
255
- method: E,
256
- requestHeaders: w,
261
+ requestId: y("fetch"),
262
+ url: h,
263
+ method: w,
264
+ requestHeaders: E,
257
265
  requestBody: T,
258
266
  resourceType: "fetch",
259
267
  errorText: l instanceof Error ? l.message : String(l),
@@ -261,15 +269,15 @@ class I {
261
269
  durationMs: Date.now() - i
262
270
  }), l;
263
271
  }
264
- }, XMLHttpRequest.prototype.open = function(a, i, c, u, f) {
272
+ }, XMLHttpRequest.prototype.open = function(a, i, c, u, h) {
265
273
  return this.__plunoMeta = {
266
- requestId: g("xhr"),
274
+ requestId: y("xhr"),
267
275
  method: String(a ?? "GET").toUpperCase(),
268
276
  url: typeof i == "string" ? i : i.toString(),
269
277
  requestHeaders: {},
270
278
  startedAtMs: Date.now(),
271
279
  startedAt: (/* @__PURE__ */ new Date()).toISOString()
272
- }, s.call(this, a, i, c ?? !0, u ?? void 0, f ?? void 0);
280
+ }, s.call(this, a, i, c ?? !0, u ?? void 0, h ?? void 0);
273
281
  }, XMLHttpRequest.prototype.setRequestHeader = function(a, i) {
274
282
  const c = this.__plunoMeta;
275
283
  if (c) {
@@ -279,14 +287,14 @@ class I {
279
287
  return n.call(this, a, i);
280
288
  }, XMLHttpRequest.prototype.send = function(a) {
281
289
  const i = window.__plunoProductAgentInstance, c = this.__plunoMeta ?? {
282
- requestId: g("xhr"),
290
+ requestId: y("xhr"),
283
291
  method: "GET",
284
292
  url: "",
285
293
  requestHeaders: {},
286
294
  startedAtMs: Date.now(),
287
295
  startedAt: (/* @__PURE__ */ new Date()).toISOString()
288
296
  };
289
- return c.requestBody = C(a), this.__plunoMeta = c, this.addEventListener(
297
+ return c.requestBody = M(a), this.__plunoMeta = c, this.addEventListener(
290
298
  "loadend",
291
299
  function() {
292
300
  !i || !this.__plunoMeta || i.enqueueNetworkEvent({
@@ -297,8 +305,8 @@ class I {
297
305
  requestBody: typeof this.__plunoMeta.requestBody == "string" ? this.__plunoMeta.requestBody : void 0,
298
306
  resourceType: "xhr",
299
307
  responseStatus: this.status,
300
- responseHeaders: st(this.getAllResponseHeaders()),
301
- responseBody: et(this),
308
+ responseHeaders: it(this.getAllResponseHeaders()),
309
+ responseBody: ot(this),
302
310
  errorText: this.status === 0 ? "XHR request failed or was aborted" : void 0,
303
311
  startedAt: String(this.__plunoMeta.startedAt),
304
312
  durationMs: Date.now() - Number(this.__plunoMeta.startedAtMs ?? Date.now())
@@ -311,13 +319,13 @@ class I {
311
319
  };
312
320
  }
313
321
  enqueueNetworkEvent(t) {
314
- this.queuedNetworkEvents.push(h(t)), this.networkBatchTimer === null && (this.networkBatchTimer = window.setTimeout(() => {
322
+ this.queuedNetworkEvents.push(f(t)), this.networkBatchTimer === null && (this.networkBatchTimer = window.setTimeout(() => {
315
323
  this.networkBatchTimer = null;
316
324
  const s = this.queuedNetworkEvents.splice(0, this.queuedNetworkEvents.length);
317
325
  s.length === 0 || this.socket?.readyState !== WebSocket.OPEN || this.sendNow({
318
326
  type: "network.batch",
319
327
  sessionId: this.state.sessionId ?? void 0,
320
- page: m(),
328
+ page: g(),
321
329
  events: s
322
330
  });
323
331
  }, 1e3));
@@ -338,16 +346,16 @@ class I {
338
346
  this.heartbeatTimer !== null && (window.clearInterval(this.heartbeatTimer), this.heartbeatTimer = null);
339
347
  }
340
348
  setState(t) {
341
- this.state = { ...this.state, ...t }, Y(this.options.clientId, this.state), this.emit("state", this.getState());
349
+ this.state = { ...this.state, ...t }, tt(this.options.clientId, this.state), this.emit("state", this.getState());
342
350
  }
343
351
  emit(t, s) {
344
352
  this.listeners[t]?.forEach((r) => r(s));
345
353
  }
346
354
  }
347
- const P = 5e3;
355
+ const U = 5e3;
348
356
  async function H(e) {
349
357
  const t = Object.getPrototypeOf(async function() {
350
- }).constructor, s = P, n = Date.now(), r = [], o = {
358
+ }).constructor, s = U, n = Date.now(), r = [], o = {
351
359
  log: console.log,
352
360
  info: console.info,
353
361
  warn: console.warn,
@@ -391,21 +399,21 @@ async function H(e) {
391
399
  console.log = o.log, console.info = o.info, console.warn = o.warn, console.error = o.error;
392
400
  }
393
401
  }
394
- function U(e) {
402
+ function B(e) {
395
403
  return e.replace(/\/+$/, "");
396
404
  }
397
- function B(e) {
405
+ function L(e) {
398
406
  const t = new URL("/api/product-agent/embed/ws", e);
399
407
  return t.protocol = t.protocol === "https:" ? "wss:" : "ws:", t.toString();
400
408
  }
401
- function m() {
409
+ function g() {
402
410
  return {
403
411
  url: location.href,
404
412
  title: document.title,
405
413
  origin: location.origin
406
414
  };
407
415
  }
408
- function L(e) {
416
+ function x(e) {
409
417
  try {
410
418
  const t = JSON.parse(e);
411
419
  return t && typeof t == "object" ? t : { type: "error", message: "Invalid server event" };
@@ -413,23 +421,23 @@ function L(e) {
413
421
  return { type: "error", message: "Invalid server event" };
414
422
  }
415
423
  }
416
- function x(e, t) {
424
+ function $(e, t) {
417
425
  if (!e || typeof e != "object")
418
426
  return [];
419
427
  const s = e[t];
420
428
  return Array.isArray(s) ? s.filter((n) => typeof n == "string" && n.trim().length > 0) : [];
421
429
  }
422
- function $() {
430
+ function j() {
423
431
  const e = "pluno.productAgent.clientId", t = window.localStorage.getItem(e);
424
432
  if (t)
425
433
  return t;
426
434
  const s = crypto.randomUUID();
427
435
  return window.localStorage.setItem(e, s), s;
428
436
  }
429
- function j() {
437
+ function X() {
430
438
  return crypto.randomUUID();
431
439
  }
432
- function X(e) {
440
+ function z(e) {
433
441
  if (!e || typeof e != "object")
434
442
  return null;
435
443
  const t = e, s = typeof t.id == "string" ? t.id : null;
@@ -440,7 +448,7 @@ function X(e) {
440
448
  avatarUrl: typeof t.avatarUrl == "string" ? t.avatarUrl : null
441
449
  } : null;
442
450
  }
443
- function z(e) {
451
+ function F(e) {
444
452
  return Array.isArray(e) ? e.map(R).filter((t) => t !== null) : [];
445
453
  }
446
454
  function R(e) {
@@ -455,20 +463,29 @@ function R(e) {
455
463
  return {
456
464
  id: String(t.id ?? crypto.randomUUID()),
457
465
  role: r,
458
- content: W(n.content),
466
+ content: K(n.content),
459
467
  createdAt: typeof t.createdAt == "string" ? t.createdAt : (/* @__PURE__ */ new Date()).toISOString()
460
468
  };
461
469
  }
462
470
  return n.type === "function_call" || n.type === "tool_call" || n.type === "web_search_call" ? {
463
471
  id: String(t.id ?? crypto.randomUUID()),
464
472
  role: "tool",
465
- content: F(n),
473
+ content: W(n),
466
474
  createdAt: typeof t.createdAt == "string" ? t.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
467
475
  dataType: String(n.type),
468
476
  loading: n.localExecutionStatus === "running"
477
+ } : n.type === "run_status" || n.type === "run_error" ? n.type === "run_status" && (n.status === "running" || n.status === "retrying") ? null : {
478
+ id: String(t.id ?? crypto.randomUUID()),
479
+ role: "system",
480
+ content: G(n),
481
+ createdAt: typeof t.createdAt == "string" ? t.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
482
+ dataType: String(n.type)
469
483
  } : null;
470
484
  }
471
- function F(e) {
485
+ function G(e) {
486
+ 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.";
487
+ }
488
+ function W(e) {
472
489
  if (e.type === "web_search_call") {
473
490
  const t = e.action;
474
491
  if (t && typeof t == "object") {
@@ -480,9 +497,9 @@ function F(e) {
480
497
  }
481
498
  return "Searching the web";
482
499
  }
483
- return G(e);
500
+ return J(e);
484
501
  }
485
- function G(e) {
502
+ function J(e) {
486
503
  if (typeof e.summary == "string" && e.summary.trim().length > 0)
487
504
  return e.summary;
488
505
  if (typeof e.arguments == "string")
@@ -495,7 +512,7 @@ function G(e) {
495
512
  }
496
513
  return typeof e.name == "string" && e.name.trim().length > 0 ? e.name : "Run tool";
497
514
  }
498
- function W(e) {
515
+ function K(e) {
499
516
  return typeof e == "string" ? e : Array.isArray(e) ? e.map((t) => {
500
517
  if (!t || typeof t != "object")
501
518
  return "";
@@ -503,14 +520,14 @@ function W(e) {
503
520
  return typeof s.text == "string" ? s.text : typeof s.content == "string" ? s.content : "";
504
521
  }).filter(Boolean).join("") : "";
505
522
  }
506
- function J(e, t) {
507
- const s = K(e, t), n = s.findIndex((o) => o.id === t.id);
523
+ function v(e, t) {
524
+ const s = Y(e, t), n = s.findIndex((o) => o.id === t.id);
508
525
  if (n === -1)
509
526
  return [...s, t];
510
527
  const r = [...s];
511
528
  return r[n] = t, r;
512
529
  }
513
- function K(e, t) {
530
+ function Y(e, t) {
514
531
  if (t.role !== "user")
515
532
  return e;
516
533
  const s = e.findIndex(
@@ -521,15 +538,39 @@ function K(e, t) {
521
538
  const n = [...e];
522
539
  return n.splice(s, 1), n;
523
540
  }
541
+ function V(e) {
542
+ const t = Z(e);
543
+ return t === null ? !1 : e.slice(t + 1).some((s) => !s || typeof s != "object" ? !1 : C(s.data));
544
+ }
545
+ function Z(e) {
546
+ for (let t = e.length - 1; t >= 0; t -= 1) {
547
+ const s = e[t];
548
+ if (!s || typeof s != "object")
549
+ continue;
550
+ const n = s.data;
551
+ if (!n || typeof n != "object")
552
+ continue;
553
+ const r = n;
554
+ if (r.type === "message" && r.role === "user")
555
+ return t;
556
+ }
557
+ return null;
558
+ }
559
+ function C(e) {
560
+ if (!e || typeof e != "object")
561
+ return !1;
562
+ const t = e;
563
+ return t.type === "message" && t.role === "assistant" || t.type === "run_error" ? !0 : t.type === "run_status" && (t.status === "stopped" || t.status === "interrupted");
564
+ }
524
565
  function _(e, t) {
525
566
  return e && typeof e == "object" && typeof e[t] == "string" ? e[t] : null;
526
567
  }
527
- function v(e) {
568
+ function Q(e) {
528
569
  try {
529
- const t = window.localStorage.getItem(`${k}${e}`);
570
+ const t = window.localStorage.getItem(`${I}${e}`);
530
571
  if (!t)
531
572
  return null;
532
- const s = JSON.parse(t), n = Array.isArray(s.messages) ? s.messages.map(V).filter((r) => !!r) : [];
573
+ const s = JSON.parse(t), n = Array.isArray(s.messages) ? s.messages.map(et).filter((r) => !!r) : [];
533
574
  return {
534
575
  sessionId: typeof s.sessionId == "string" ? s.sessionId : null,
535
576
  messages: n
@@ -538,10 +579,10 @@ function v(e) {
538
579
  return null;
539
580
  }
540
581
  }
541
- function Y(e, t) {
582
+ function tt(e, t) {
542
583
  try {
543
584
  window.localStorage.setItem(
544
- `${k}${e}`,
585
+ `${I}${e}`,
545
586
  JSON.stringify({
546
587
  sessionId: t.sessionId,
547
588
  messages: t.messages.slice(-100)
@@ -551,7 +592,7 @@ function Y(e, t) {
551
592
  return;
552
593
  }
553
594
  }
554
- function V(e) {
595
+ function et(e) {
555
596
  if (!e || typeof e != "object")
556
597
  return null;
557
598
  const t = e;
@@ -564,7 +605,7 @@ function V(e) {
564
605
  loading: typeof t.loading == "boolean" ? t.loading : void 0
565
606
  };
566
607
  }
567
- function Z(e) {
608
+ function st(e) {
568
609
  return !!e && typeof e == "object" && typeof e.summary == "string" && typeof e.javascript == "string";
569
610
  }
570
611
  function A(e) {
@@ -573,9 +614,9 @@ function A(e) {
573
614
  t[n] = s;
574
615
  }), t;
575
616
  }
576
- async function Q(e, t) {
617
+ async function nt(e, t) {
577
618
  if (typeof t?.body < "u")
578
- return C(t.body);
619
+ return M(t.body);
579
620
  if (e)
580
621
  try {
581
622
  return p(await e.clone().text());
@@ -583,21 +624,21 @@ async function Q(e, t) {
583
624
  return;
584
625
  }
585
626
  }
586
- async function tt(e) {
627
+ async function rt(e) {
587
628
  try {
588
629
  return p(await e.clone().text());
589
630
  } catch (t) {
590
631
  return { error: t instanceof Error ? t.message : "unavailable" };
591
632
  }
592
633
  }
593
- function et(e) {
634
+ function ot(e) {
594
635
  try {
595
636
  return e.responseType === "" || e.responseType === "text" ? p(e.responseText ?? "") : e.responseType === "json" ? p(JSON.stringify(e.response)) : `[unsupported xhr responseType: ${e.responseType || "unknown"}]`;
596
637
  } catch (t) {
597
638
  return { error: t instanceof Error ? t.message : "unavailable" };
598
639
  }
599
640
  }
600
- function C(e) {
641
+ function M(e) {
601
642
  if (!(e === null || typeof e > "u")) {
602
643
  if (typeof e == "string")
603
644
  return p(e);
@@ -616,7 +657,7 @@ function C(e) {
616
657
  }
617
658
  }
618
659
  }
619
- function st(e) {
660
+ function it(e) {
620
661
  const t = {};
621
662
  for (const s of e.trim().split(/[\r\n]+/)) {
622
663
  const n = s.indexOf(":");
@@ -627,57 +668,57 @@ function st(e) {
627
668
  function p(e) {
628
669
  return e.length <= 1e5 ? e : `${e.slice(0, 1e5)}... [truncated ${e.length - 1e5} chars]`;
629
670
  }
630
- function g(e) {
671
+ function y(e) {
631
672
  return `${e}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
632
673
  }
633
- const S = "[REDACTED_SECRET]", d = "[REDACTED_TOKEN]", nt = "[REDACTED_SIGNED_URL]", rt = 20, ot = /^(access_token|accessToken|refresh_token|refreshToken|id_token|idToken|authToken|token|api_key|apiKey|apikey|key|secret|signature|sig|password|passwd|pwd|code|state|session|jwt|csrf|csrfToken|xsrf|xsrfToken)$/i, M = /\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi, N = /\bBasic\s+[A-Za-z0-9+/=-]{12,}/gi, D = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g, b = /\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, it = /\bhttps?:\/\/[^\s"'<>]+(?:X-Amz-Signature|X-Goog-Signature|Signature|sig=)[^\s"'<>]*/gi, at = /\bhttps?:\/\/[^\s"'<>]+/gi, ct = /[),.;\]]+$/;
634
- function h(e) {
635
- return y(e, 0, /* @__PURE__ */ new WeakSet());
674
+ const S = "[REDACTED_SECRET]", d = "[REDACTED_TOKEN]", at = "[REDACTED_SIGNED_URL]", ct = 20, ut = /^(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, D = /\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi, N = /\bBasic\s+[A-Za-z0-9+/=-]{12,}/gi, b = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g, q = /\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, lt = /\bhttps?:\/\/[^\s"'<>]+(?:X-Amz-Signature|X-Goog-Signature|Signature|sig=)[^\s"'<>]*/gi, dt = /\bhttps?:\/\/[^\s"'<>]+/gi, pt = /[),.;\]]+$/;
675
+ function f(e) {
676
+ return m(e, 0, /* @__PURE__ */ new WeakSet());
636
677
  }
637
- function y(e, t, s) {
678
+ function m(e, t, s) {
638
679
  if (typeof e == "string")
639
- return dt(e);
680
+ return gt(e);
640
681
  if (e === null || typeof e != "object")
641
682
  return e;
642
- if (t >= rt)
683
+ if (t >= ct)
643
684
  return "[REDACTED_MAX_DEPTH]";
644
685
  if (s.has(e))
645
686
  return "[REDACTED_CIRCULAR]";
646
687
  if (s.add(e), Array.isArray(e))
647
- return e.map((r) => y(r, t + 1, s));
688
+ return e.map((r) => m(r, t + 1, s));
648
689
  const n = {};
649
690
  for (const [r, o] of Object.entries(e))
650
- ut(r) ? n[r] = S : n[r] = r.toLowerCase() === "url" ? lt(o) : y(o, t + 1, s);
691
+ ft(r) ? n[r] = S : n[r] = r.toLowerCase() === "url" ? ht(o) : m(o, t + 1, s);
651
692
  return n;
652
693
  }
653
- function ut(e) {
694
+ function ft(e) {
654
695
  const t = e.replace(/[^a-z0-9]/gi, "").toLowerCase();
655
696
  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");
656
697
  }
657
- function lt(e) {
658
- return typeof e == "string" ? q(e) : y(e, 0, /* @__PURE__ */ new WeakSet());
698
+ function ht(e) {
699
+ return typeof e == "string" ? O(e) : m(e, 0, /* @__PURE__ */ new WeakSet());
659
700
  }
660
- function q(e) {
701
+ function O(e) {
661
702
  try {
662
703
  const t = new URL(e, location.href);
663
704
  for (const s of Array.from(t.searchParams.keys()))
664
- ot.test(s) && t.searchParams.set(s, d);
705
+ ut.test(s) && t.searchParams.set(s, d);
665
706
  return t.username && (t.username = d), t.password && (t.password = d), t.toString();
666
707
  } catch {
667
- return pt(e);
708
+ return yt(e);
668
709
  }
669
710
  }
670
- function dt(e) {
671
- return e.replace(it, nt).replace(at, ht).replace(M, `Bearer ${d}`).replace(N, `Basic ${d}`).replace(D, d).replace(b, (t, s) => `${s}: ${S}`);
711
+ function gt(e) {
712
+ return e.replace(lt, at).replace(dt, mt).replace(D, `Bearer ${d}`).replace(N, `Basic ${d}`).replace(b, d).replace(q, (t, s) => `${s}: ${S}`);
672
713
  }
673
- function pt(e) {
674
- return e.replace(M, `Bearer ${d}`).replace(N, `Basic ${d}`).replace(D, d).replace(b, (t, s) => `${s}: ${S}`);
714
+ function yt(e) {
715
+ return e.replace(D, `Bearer ${d}`).replace(N, `Basic ${d}`).replace(b, d).replace(q, (t, s) => `${s}: ${S}`);
675
716
  }
676
- function ht(e) {
677
- const t = e.match(ct)?.[0] ?? "", s = t ? e.slice(0, -t.length) : e;
678
- return `${q(s)}${t}`;
717
+ function mt(e) {
718
+ const t = e.match(pt)?.[0] ?? "", s = t ? e.slice(0, -t.length) : e;
719
+ return `${O(s)}${t}`;
679
720
  }
680
721
  export {
681
- I as PlunoProductAgent,
682
- I as default
722
+ k as PlunoProductAgent,
723
+ k as default
683
724
  };
@@ -705,7 +705,7 @@ function F(e, t) {
705
705
  left: 2px;
706
706
  }
707
707
  .pluno-pa-widget__message:hover .pluno-pa-widget__message-copy,
708
- .pluno-pa-widget__message:focus-within .pluno-pa-widget__message-copy {
708
+ .pluno-pa-widget__message-copy:focus-visible {
709
709
  opacity: 1;
710
710
  pointer-events: auto;
711
711
  transform: translateY(0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluno/product-agent-web",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Browser SDK and default widget for embedding Pluno Product Agent into customer web apps.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",