@pluno/product-agent-web 0.1.9 → 0.1.10

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 CHANGED
@@ -65,6 +65,7 @@ export declare class PlunoProductAgent {
65
65
  private queuedNetworkEvents;
66
66
  private queuedClientEvents;
67
67
  private retryAttemptsByClientMessageId;
68
+ private retryTimersByClientMessageId;
68
69
  private runtimeHelperJavascript;
69
70
  private state;
70
71
  private constructor();
@@ -82,6 +83,7 @@ export declare class PlunoProductAgent {
82
83
  private flushQueuedClientEvents;
83
84
  private handleServerEvent;
84
85
  private retryAfterRetryableError;
86
+ private clearRetryTimers;
85
87
  private executeToolCall;
86
88
  private executeRuntimeHelper;
87
89
  private enableNetworkCapture;
@@ -1,9 +1,9 @@
1
- const x = "https://app.pluno.ai";
2
- const R = "pluno.productAgent.state.";
3
- class M {
1
+ const O = "https://app.pluno.ai";
2
+ const M = "pluno.productAgent.state.";
3
+ class C {
4
4
  constructor(t) {
5
5
  this.options = t;
6
- const s = ot(t.clientId);
6
+ const s = at(t.clientId);
7
7
  s && (this.state = {
8
8
  ...this.state,
9
9
  ...s,
@@ -25,6 +25,7 @@ class M {
25
25
  queuedNetworkEvents = [];
26
26
  queuedClientEvents = [];
27
27
  retryAttemptsByClientMessageId = {};
28
+ retryTimersByClientMessageId = {};
28
29
  runtimeHelperJavascript = null;
29
30
  state = {
30
31
  status: "idle",
@@ -37,10 +38,10 @@ class M {
37
38
  lastError: null
38
39
  };
39
40
  static async init(t) {
40
- const s = new M({
41
+ const s = new C({
41
42
  ...t,
42
- backendUrl: B(t.backendUrl ?? x),
43
- clientId: t.clientId ?? J()
43
+ backendUrl: j(t.backendUrl ?? O),
44
+ clientId: t.clientId ?? G()
44
45
  });
45
46
  try {
46
47
  s.enableNetworkCapture(), t.autoConnect !== !1 && await s.connect();
@@ -65,17 +66,17 @@ class M {
65
66
  return;
66
67
  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
68
  throw new Error("Product Agent requires a token or tokenProvider");
68
- const t = L(this.options.backendUrl);
69
+ const t = $(this.options.backendUrl);
69
70
  this.socket = this.options.webSocketFactory?.(t) ?? new WebSocket(t), this.socket.addEventListener("open", () => {
70
71
  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(j(s.data))), this.socket.addEventListener("close", () => {
72
+ }), this.socket.addEventListener("message", (s) => this.handleServerEvent(X(s.data))), this.socket.addEventListener("close", () => {
72
73
  this.stopHeartbeat(), this.socket = null, this.state.status !== "closed" && (this.setState({ status: "reconnecting" }), this.scheduleReconnect());
73
74
  }), this.socket.addEventListener("error", () => {
74
75
  this.setState({ status: "error", lastError: "Product Agent connection failed" });
75
76
  });
76
77
  }
77
78
  disconnect() {
78
- this.setState({ status: "closed", isThinking: !1 }), this.stopHeartbeat(), this.reconnectTimer !== null && (window.clearTimeout(this.reconnectTimer), this.reconnectTimer = null), this.queuedClientEvents = [], this.socket?.close(), this.socket = null;
79
+ this.setState({ status: "closed", isThinking: !1 }), this.stopHeartbeat(), this.clearRetryTimers(), this.reconnectTimer !== null && (window.clearTimeout(this.reconnectTimer), this.reconnectTimer = null), this.queuedClientEvents = [], this.socket?.close(), this.socket = null;
79
80
  }
80
81
  destroy() {
81
82
  this.disconnect(), this.networkCaptureCleanup?.(), this.networkCaptureCleanup = null;
@@ -86,7 +87,7 @@ class M {
86
87
  const s = t.trim();
87
88
  if (!s)
88
89
  return;
89
- const r = g(), n = G(), i = {
90
+ const r = g(), n = W(), i = {
90
91
  id: `local-${n}`,
91
92
  role: "user",
92
93
  content: s,
@@ -125,7 +126,7 @@ class M {
125
126
  });
126
127
  }
127
128
  send(t) {
128
- this.sendNow(f(t)) || (this.queuedClientEvents.push(t), this.setState({ status: "reconnecting" }), this.scheduleReconnect());
129
+ this.sendNow(p(t)) || (this.queuedClientEvents.push(t), this.setState({ status: "reconnecting" }), this.scheduleReconnect());
129
130
  }
130
131
  sendNow(t) {
131
132
  return !this.socket || this.socket.readyState !== WebSocket.OPEN ? !1 : (this.socket.send(JSON.stringify(t)), !0);
@@ -136,7 +137,7 @@ class M {
136
137
  const t = this.queuedClientEvents.splice(0, this.queuedClientEvents.length);
137
138
  for (let s = 0; s < t.length; s += 1) {
138
139
  const r = t[s];
139
- if (!this.sendNow(f(r))) {
140
+ if (!this.sendNow(p(r))) {
140
141
  this.queuedClientEvents.unshift(r, ...t.slice(s + 1));
141
142
  return;
142
143
  }
@@ -144,9 +145,9 @@ class M {
144
145
  }
145
146
  handleServerEvent(t) {
146
147
  if (t.type === "auth.ok") {
147
- this.runtimeHelperJavascript = X(t.runtimeHelpers)?.javascript ?? null, this.setState({
148
- user: W(t.user),
149
- starterPrompts: $(t, "starterPrompts"),
148
+ this.runtimeHelperJavascript = F(t.runtimeHelpers)?.javascript ?? null, this.setState({
149
+ user: K(t.user),
150
+ starterPrompts: z(t, "starterPrompts"),
150
151
  status: "connected"
151
152
  }), this.state.sessionId && this.send({
152
153
  type: "page.upsert",
@@ -158,23 +159,23 @@ class M {
158
159
  }
159
160
  if (t.type === "conversation.state") {
160
161
  const s = Array.isArray(t.items) ? t.items : [];
161
- this.setState({
162
- sessionId: I(t.session, "id") ?? this.state.sessionId,
163
- messages: v(s),
164
- ...et(s) ? { assistantDraft: "", isThinking: !1 } : {}
162
+ nt(s) && this.clearRetryTimers(), this.setState({
163
+ sessionId: k(t.session, "id") ?? this.state.sessionId,
164
+ messages: Y(s),
165
+ ...rt(s) ? { assistantDraft: "", isThinking: !1 } : {}
165
166
  });
166
167
  return;
167
168
  }
168
169
  if (t.type === "session.updated") {
169
- this.setState({ sessionId: I(t.session, "id") ?? this.state.sessionId });
170
+ this.setState({ sessionId: k(t.session, "id") ?? this.state.sessionId });
170
171
  return;
171
172
  }
172
173
  if (t.type === "session.item") {
173
- const s = C(t.item);
174
- s && (this.setState({
175
- messages: Q(this.state.messages, s),
174
+ const s = b(t.item);
175
+ s && (s.role === "assistant" && this.clearRetryTimers(), this.setState({
176
+ messages: et(this.state.messages, s),
176
177
  assistantDraft: s.role === "assistant" ? "" : this.state.assistantDraft,
177
- ...D(t.item.data) ? { assistantDraft: "", isThinking: !1 } : {}
178
+ ...N(t.item.data) ? { assistantDraft: "", isThinking: !1 } : {}
178
179
  }), this.emit("message", s));
179
180
  return;
180
181
  }
@@ -208,17 +209,22 @@ class M {
208
209
  return !1;
209
210
  this.retryAttemptsByClientMessageId[r] = i + 1;
210
211
  const a = typeof t.retryAfterMs == "number" ? t.retryAfterMs : 2e3;
211
- return this.setState({ status: "reconnecting", isThinking: !0, lastError: null }), window.setTimeout(() => {
212
- this.setState({ status: "connected", isThinking: !0, lastError: null }), this.send({
212
+ return this.setState({ status: "reconnecting", isThinking: !0, lastError: null }), this.retryTimersByClientMessageId[r] = window.setTimeout(() => {
213
+ delete this.retryTimersByClientMessageId[r], this.setState({ status: "connected", isThinking: !0, lastError: null }), this.send({
213
214
  type: "chat.retry_last_user_message",
214
215
  sessionId: s,
215
216
  clientMessageId: r
216
217
  });
217
218
  }, a), !0;
218
219
  }
220
+ clearRetryTimers() {
221
+ for (const t of Object.values(this.retryTimersByClientMessageId))
222
+ window.clearTimeout(t);
223
+ this.retryTimersByClientMessageId = {};
224
+ }
219
225
  async executeToolCall(t) {
220
226
  const s = typeof t.sessionId == "string" ? t.sessionId : null, r = typeof t.callId == "string" ? t.callId : null, n = t.rawInput;
221
- if (!s || !r || !ct(n))
227
+ if (!s || !r || !lt(n))
222
228
  return;
223
229
  const i = await this.executeRuntimeHelper(), a = await A(n).catch((o) => ({
224
230
  ok: !1,
@@ -232,8 +238,8 @@ class M {
232
238
  callId: r,
233
239
  toolName: "execute_code",
234
240
  summary: n.summary,
235
- rawInput: f(n),
236
- rawOutput: f(z(a, i))
241
+ rawInput: p(n),
242
+ rawOutput: p(J(a, i))
237
243
  });
238
244
  }
239
245
  async executeRuntimeHelper() {
@@ -242,26 +248,26 @@ class M {
242
248
  const t = await A({
243
249
  javascript: this.runtimeHelperJavascript
244
250
  });
245
- return t.ok === !1 ? F(t) : null;
251
+ return t.ok === !1 ? v(t) : null;
246
252
  }
247
253
  enableNetworkCapture() {
248
254
  if (this.networkCaptureCleanup)
249
255
  return;
250
256
  const t = window.fetch.bind(window), s = XMLHttpRequest.prototype.open, r = XMLHttpRequest.prototype.setRequestHeader, n = XMLHttpRequest.prototype.send;
251
257
  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 ?? "", _ = (a?.method ?? u?.method ?? "GET").toUpperCase(), T = k(new Headers(a?.headers ?? u?.headers ?? void 0)), w = await ut(u, a);
258
+ 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 ?? "", E = (a?.method ?? u?.method ?? "GET").toUpperCase(), _ = R(new Headers(a?.headers ?? u?.headers ?? void 0)), w = await dt(u, a);
253
259
  try {
254
260
  const l = await t(i, a);
255
261
  return this.enqueueNetworkEvent({
256
262
  requestId: y("fetch"),
257
263
  url: h,
258
- method: _,
259
- requestHeaders: T,
264
+ method: E,
265
+ requestHeaders: _,
260
266
  requestBody: w,
261
267
  resourceType: "fetch",
262
268
  responseStatus: l.status,
263
- responseHeaders: k(l.headers),
264
- responseBody: await lt(l),
269
+ responseHeaders: R(l.headers),
270
+ responseBody: await ft(l),
265
271
  startedAt: c,
266
272
  durationMs: Date.now() - o
267
273
  }), l;
@@ -269,8 +275,8 @@ class M {
269
275
  throw this.enqueueNetworkEvent({
270
276
  requestId: y("fetch"),
271
277
  url: h,
272
- method: _,
273
- requestHeaders: T,
278
+ method: E,
279
+ requestHeaders: _,
274
280
  requestBody: w,
275
281
  resourceType: "fetch",
276
282
  errorText: l instanceof Error ? l.message : String(l),
@@ -303,7 +309,7 @@ class M {
303
309
  startedAtMs: Date.now(),
304
310
  startedAt: (/* @__PURE__ */ new Date()).toISOString()
305
311
  };
306
- return c.requestBody = b(a), this.__plunoMeta = c, this.addEventListener(
312
+ return c.requestBody = H(a), this.__plunoMeta = c, this.addEventListener(
307
313
  "loadend",
308
314
  function() {
309
315
  !o || !this.__plunoMeta || o.enqueueNetworkEvent({
@@ -314,8 +320,8 @@ class M {
314
320
  requestBody: typeof this.__plunoMeta.requestBody == "string" ? this.__plunoMeta.requestBody : void 0,
315
321
  resourceType: "xhr",
316
322
  responseStatus: this.status,
317
- responseHeaders: pt(this.getAllResponseHeaders()),
318
- responseBody: dt(this),
323
+ responseHeaders: ht(this.getAllResponseHeaders()),
324
+ responseBody: pt(this),
319
325
  errorText: this.status === 0 ? "XHR request failed or was aborted" : void 0,
320
326
  startedAt: String(this.__plunoMeta.startedAt),
321
327
  durationMs: Date.now() - Number(this.__plunoMeta.startedAtMs ?? Date.now())
@@ -328,7 +334,7 @@ class M {
328
334
  };
329
335
  }
330
336
  enqueueNetworkEvent(t) {
331
- this.queuedNetworkEvents.push(f(t)), this.networkBatchTimer === null && (this.networkBatchTimer = window.setTimeout(() => {
337
+ this.queuedNetworkEvents.push(p(t)), this.networkBatchTimer === null && (this.networkBatchTimer = window.setTimeout(() => {
332
338
  this.networkBatchTimer = null;
333
339
  const s = this.queuedNetworkEvents.splice(0, this.queuedNetworkEvents.length);
334
340
  s.length === 0 || this.socket?.readyState !== WebSocket.OPEN || this.sendNow({
@@ -355,16 +361,16 @@ class M {
355
361
  this.heartbeatTimer !== null && (window.clearInterval(this.heartbeatTimer), this.heartbeatTimer = null);
356
362
  }
357
363
  setState(t) {
358
- this.state = { ...this.state, ...t }, it(this.options.clientId, this.state), this.emit("state", this.getState());
364
+ this.state = { ...this.state, ...t }, ct(this.options.clientId, this.state), this.emit("state", this.getState());
359
365
  }
360
366
  emit(t, s) {
361
367
  this.listeners[t]?.forEach((n) => n(s));
362
368
  }
363
369
  }
364
- const O = 5e3;
370
+ const L = 5e3;
365
371
  async function A(e) {
366
372
  const t = Object.getPrototypeOf(async function() {
367
- }).constructor, s = O, r = Date.now(), n = [], i = {
373
+ }).constructor, s = L, r = Date.now(), n = [], i = {
368
374
  log: console.log,
369
375
  info: console.info,
370
376
  warn: console.warn,
@@ -408,10 +414,10 @@ async function A(e) {
408
414
  console.log = i.log, console.info = i.info, console.warn = i.warn, console.error = i.error;
409
415
  }
410
416
  }
411
- function B(e) {
417
+ function j(e) {
412
418
  return e.replace(/\/+$/, "");
413
419
  }
414
- function L(e) {
420
+ function $(e) {
415
421
  const t = new URL("/api/product-agent/embed/ws", e);
416
422
  return t.protocol = t.protocol === "https:" ? "wss:" : "ws:", t.toString();
417
423
  }
@@ -422,7 +428,7 @@ function g() {
422
428
  origin: location.origin
423
429
  };
424
430
  }
425
- function j(e) {
431
+ function X(e) {
426
432
  try {
427
433
  const t = JSON.parse(e);
428
434
  return t && typeof t == "object" ? t : { type: "error", message: "Invalid server event" };
@@ -430,19 +436,19 @@ function j(e) {
430
436
  return { type: "error", message: "Invalid server event" };
431
437
  }
432
438
  }
433
- function $(e, t) {
439
+ function z(e, t) {
434
440
  if (!e || typeof e != "object")
435
441
  return [];
436
442
  const s = e[t];
437
443
  return Array.isArray(s) ? s.filter((r) => typeof r == "string" && r.trim().length > 0) : [];
438
444
  }
439
- function X(e) {
445
+ function F(e) {
440
446
  if (!e || typeof e != "object")
441
447
  return null;
442
448
  const t = e.javascript;
443
449
  return typeof t != "string" || !t.trim() ? null : { javascript: t };
444
450
  }
445
- function z(e, t) {
451
+ function J(e, t) {
446
452
  return t ? e && typeof e == "object" ? {
447
453
  ...e,
448
454
  helperError: t
@@ -452,23 +458,23 @@ function z(e, t) {
452
458
  helperError: t
453
459
  } : e;
454
460
  }
455
- function F(e) {
461
+ function v(e) {
456
462
  if (!e || typeof e != "object")
457
463
  return e;
458
464
  const t = e;
459
465
  return typeof t.exception?.message == "string" ? t.exception.message : typeof t.error == "string" ? t.error : e;
460
466
  }
461
- function J() {
467
+ function G() {
462
468
  const e = "pluno.productAgent.clientId", t = window.localStorage.getItem(e);
463
469
  if (t)
464
470
  return t;
465
471
  const s = crypto.randomUUID();
466
472
  return window.localStorage.setItem(e, s), s;
467
473
  }
468
- function G() {
474
+ function W() {
469
475
  return crypto.randomUUID();
470
476
  }
471
- function W(e) {
477
+ function K(e) {
472
478
  if (!e || typeof e != "object")
473
479
  return null;
474
480
  const t = e, s = typeof t.id == "string" ? t.id : null;
@@ -479,12 +485,12 @@ function W(e) {
479
485
  avatarUrl: typeof t.avatarUrl == "string" ? t.avatarUrl : null
480
486
  } : null;
481
487
  }
482
- function v(e) {
488
+ function Y(e) {
483
489
  return Array.isArray(e) ? S(
484
- e.map(C).filter((t) => t !== null)
490
+ e.map(b).filter((t) => t !== null)
485
491
  ) : [];
486
492
  }
487
- function C(e) {
493
+ function b(e) {
488
494
  if (!e || typeof e != "object")
489
495
  return null;
490
496
  const t = e, s = t.data;
@@ -496,29 +502,29 @@ function C(e) {
496
502
  return {
497
503
  id: String(t.id ?? crypto.randomUUID()),
498
504
  role: n,
499
- content: Z(r.content),
505
+ content: tt(r.content),
500
506
  createdAt: typeof t.createdAt == "string" ? t.createdAt : (/* @__PURE__ */ new Date()).toISOString()
501
507
  };
502
508
  }
503
509
  return r.type === "function_call" || r.type === "tool_call" || r.type === "web_search_call" ? {
504
510
  id: String(t.id ?? crypto.randomUUID()),
505
511
  role: "tool",
506
- content: Y(r),
512
+ content: Z(r),
507
513
  createdAt: typeof t.createdAt == "string" ? t.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
508
514
  dataType: String(r.type),
509
515
  loading: r.localExecutionStatus === "running"
510
516
  } : 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 : {
511
517
  id: String(t.id ?? crypto.randomUUID()),
512
518
  role: "system",
513
- content: K(r),
519
+ content: V(r),
514
520
  createdAt: typeof t.createdAt == "string" ? t.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
515
521
  dataType: String(r.type)
516
522
  } : null;
517
523
  }
518
- function K(e) {
524
+ function V(e) {
519
525
  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.";
520
526
  }
521
- function Y(e) {
527
+ function Z(e) {
522
528
  if (e.type === "web_search_call") {
523
529
  const t = e.action;
524
530
  if (t && typeof t == "object") {
@@ -530,9 +536,9 @@ function Y(e) {
530
536
  }
531
537
  return "Searching the web";
532
538
  }
533
- return V(e);
539
+ return Q(e);
534
540
  }
535
- function V(e) {
541
+ function Q(e) {
536
542
  if (typeof e.summary == "string" && e.summary.trim().length > 0)
537
543
  return e.summary;
538
544
  if (typeof e.arguments == "string")
@@ -545,7 +551,7 @@ function V(e) {
545
551
  }
546
552
  return typeof e.name == "string" && e.name.trim().length > 0 ? e.name : "Run tool";
547
553
  }
548
- function Z(e) {
554
+ function tt(e) {
549
555
  return typeof e == "string" ? e : Array.isArray(e) ? e.map((t) => {
550
556
  if (!t || typeof t != "object")
551
557
  return "";
@@ -553,14 +559,14 @@ function Z(e) {
553
559
  return typeof s.text == "string" ? s.text : typeof s.content == "string" ? s.content : "";
554
560
  }).filter(Boolean).join("") : "";
555
561
  }
556
- function Q(e, t) {
557
- const s = tt(e, t), r = s.findIndex((i) => i.id === t.id);
562
+ function et(e, t) {
563
+ const s = st(e, t), r = s.findIndex((i) => i.id === t.id);
558
564
  if (r === -1)
559
565
  return S([...s, t]);
560
566
  const n = [...s];
561
567
  return n[r] = t, S(n);
562
568
  }
563
- function tt(e, t) {
569
+ function st(e, t) {
564
570
  if (t.role !== "user")
565
571
  return e;
566
572
  const s = e.findIndex(
@@ -571,11 +577,15 @@ function tt(e, t) {
571
577
  const r = [...e];
572
578
  return r.splice(s, 1), r;
573
579
  }
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));
580
+ function rt(e) {
581
+ const t = D(e);
582
+ return t === null ? !1 : e.slice(t + 1).some((s) => !s || typeof s != "object" ? !1 : N(s.data));
583
+ }
584
+ function nt(e) {
585
+ const t = D(e);
586
+ return t === null ? e.some((s) => !s || typeof s != "object" ? !1 : I(s.data)) : e.slice(t + 1).some((s) => !s || typeof s != "object" ? !1 : I(s.data));
577
587
  }
578
- function st(e) {
588
+ function D(e) {
579
589
  for (let t = e.length - 1; t >= 0; t -= 1) {
580
590
  const s = e[t];
581
591
  if (!s || typeof s != "object")
@@ -589,19 +599,25 @@ function st(e) {
589
599
  }
590
600
  return null;
591
601
  }
592
- function D(e) {
602
+ function I(e) {
603
+ if (!e || typeof e != "object")
604
+ return !1;
605
+ const t = e;
606
+ return t.type === "message" && t.role === "assistant";
607
+ }
608
+ function N(e) {
593
609
  if (!e || typeof e != "object")
594
610
  return !1;
595
611
  const t = e;
596
612
  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
613
  }
598
614
  function S(e) {
599
- return e.filter((t, s) => rt(t) ? !nt(e, s) : !0);
615
+ return e.filter((t, s) => ot(t) ? !it(e, s) : !0);
600
616
  }
601
- function rt(e) {
617
+ function ot(e) {
602
618
  return e.role === "system" && (e.dataType === "run_status" || e.dataType === "run_error");
603
619
  }
604
- function nt(e, t) {
620
+ function it(e, t) {
605
621
  for (let s = t + 1; s < e.length; s += 1) {
606
622
  const r = e[s];
607
623
  if (r.role === "user")
@@ -611,15 +627,15 @@ function nt(e, t) {
611
627
  }
612
628
  return !1;
613
629
  }
614
- function I(e, t) {
630
+ function k(e, t) {
615
631
  return e && typeof e == "object" && typeof e[t] == "string" ? e[t] : null;
616
632
  }
617
- function ot(e) {
633
+ function at(e) {
618
634
  try {
619
- const t = window.localStorage.getItem(`${R}${e}`);
635
+ const t = window.localStorage.getItem(`${M}${e}`);
620
636
  if (!t)
621
637
  return null;
622
- const s = JSON.parse(t), r = Array.isArray(s.messages) ? s.messages.map(at).filter((n) => !!n) : [];
638
+ const s = JSON.parse(t), r = Array.isArray(s.messages) ? s.messages.map(ut).filter((n) => !!n) : [];
623
639
  return {
624
640
  sessionId: typeof s.sessionId == "string" ? s.sessionId : null,
625
641
  messages: r
@@ -628,10 +644,10 @@ function ot(e) {
628
644
  return null;
629
645
  }
630
646
  }
631
- function it(e, t) {
647
+ function ct(e, t) {
632
648
  try {
633
649
  window.localStorage.setItem(
634
- `${R}${e}`,
650
+ `${M}${e}`,
635
651
  JSON.stringify({
636
652
  sessionId: t.sessionId,
637
653
  messages: t.messages.slice(-100)
@@ -641,7 +657,7 @@ function it(e, t) {
641
657
  return;
642
658
  }
643
659
  }
644
- function at(e) {
660
+ function ut(e) {
645
661
  if (!e || typeof e != "object")
646
662
  return null;
647
663
  const t = e;
@@ -654,59 +670,59 @@ function at(e) {
654
670
  loading: typeof t.loading == "boolean" ? t.loading : void 0
655
671
  };
656
672
  }
657
- function ct(e) {
673
+ function lt(e) {
658
674
  return !!e && typeof e == "object" && typeof e.summary == "string" && typeof e.javascript == "string";
659
675
  }
660
- function k(e) {
676
+ function R(e) {
661
677
  const t = {};
662
678
  return e?.forEach((s, r) => {
663
679
  t[r] = s;
664
680
  }), t;
665
681
  }
666
- async function ut(e, t) {
682
+ async function dt(e, t) {
667
683
  if (typeof t?.body < "u")
668
- return b(t.body);
684
+ return H(t.body);
669
685
  if (e)
670
686
  try {
671
- return p(await e.clone().text());
687
+ return f(await e.clone().text());
672
688
  } catch {
673
689
  return;
674
690
  }
675
691
  }
676
- async function lt(e) {
692
+ async function ft(e) {
677
693
  try {
678
- return p(await e.clone().text());
694
+ return f(await e.clone().text());
679
695
  } catch (t) {
680
696
  return { error: t instanceof Error ? t.message : "unavailable" };
681
697
  }
682
698
  }
683
- function dt(e) {
699
+ function pt(e) {
684
700
  try {
685
- return e.responseType === "" || e.responseType === "text" ? p(e.responseText ?? "") : e.responseType === "json" ? p(JSON.stringify(e.response)) : `[unsupported xhr responseType: ${e.responseType || "unknown"}]`;
701
+ return e.responseType === "" || e.responseType === "text" ? f(e.responseText ?? "") : e.responseType === "json" ? f(JSON.stringify(e.response)) : `[unsupported xhr responseType: ${e.responseType || "unknown"}]`;
686
702
  } catch (t) {
687
703
  return { error: t instanceof Error ? t.message : "unavailable" };
688
704
  }
689
705
  }
690
- function b(e) {
706
+ function H(e) {
691
707
  if (!(e === null || typeof e > "u")) {
692
708
  if (typeof e == "string")
693
- return p(e);
709
+ return f(e);
694
710
  if (e instanceof URLSearchParams)
695
- return p(e.toString());
711
+ return f(e.toString());
696
712
  if (e instanceof FormData) {
697
713
  const t = [];
698
- return e.forEach((s, r) => t.push([r, s instanceof File ? `[file:${s.name}]` : String(s)])), p(JSON.stringify(t));
714
+ return e.forEach((s, r) => t.push([r, s instanceof File ? `[file:${s.name}]` : String(s)])), f(JSON.stringify(t));
699
715
  }
700
716
  if (e instanceof Blob)
701
717
  return `[blob:${e.type || "application/octet-stream"}:${e.size}]`;
702
718
  try {
703
- return p(JSON.stringify(e));
719
+ return f(JSON.stringify(e));
704
720
  } catch {
705
721
  return `[unserializable body: ${Object.prototype.toString.call(e)}]`;
706
722
  }
707
723
  }
708
724
  }
709
- function pt(e) {
725
+ function ht(e) {
710
726
  const t = {};
711
727
  for (const s of e.trim().split(/[\r\n]+/)) {
712
728
  const r = s.indexOf(":");
@@ -714,22 +730,22 @@ function pt(e) {
714
730
  }
715
731
  return t;
716
732
  }
717
- function p(e) {
733
+ function f(e) {
718
734
  return e.length <= 1e5 ? e : `${e.slice(0, 1e5)}... [truncated ${e.length - 1e5} chars]`;
719
735
  }
720
736
  function y(e) {
721
737
  return `${e}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
722
738
  }
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 = /[),.;\]]+$/;
724
- function f(e) {
739
+ const T = "[REDACTED_SECRET]", d = "[REDACTED_TOKEN]", gt = "[REDACTED_SIGNED_URL]", yt = 20, mt = /^(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, U = /\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi, q = /\bBasic\s+[A-Za-z0-9+/=-]{12,}/gi, P = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g, x = /\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, St = /\bhttps?:\/\/[^\s"'<>]+(?:X-Amz-Signature|X-Goog-Signature|Signature|sig=)[^\s"'<>]*/gi, Tt = /\bhttps?:\/\/[^\s"'<>]+/gi, Et = /[),.;\]]+$/;
740
+ function p(e) {
725
741
  return m(e, 0, /* @__PURE__ */ new WeakSet());
726
742
  }
727
743
  function m(e, t, s) {
728
744
  if (typeof e == "string")
729
- return Tt(e);
745
+ return At(e);
730
746
  if (e === null || typeof e != "object")
731
747
  return e;
732
- if (t >= ht)
748
+ if (t >= yt)
733
749
  return "[REDACTED_MAX_DEPTH]";
734
750
  if (s.has(e))
735
751
  return "[REDACTED_CIRCULAR]";
@@ -737,37 +753,37 @@ function m(e, t, s) {
737
753
  return e.map((n) => m(n, t + 1, s));
738
754
  const r = {};
739
755
  for (const [n, i] of Object.entries(e))
740
- Et(n) ? r[n] = E : r[n] = n.toLowerCase() === "url" ? _t(i) : m(i, t + 1, s);
756
+ _t(n) ? r[n] = T : r[n] = n.toLowerCase() === "url" ? wt(i) : m(i, t + 1, s);
741
757
  return r;
742
758
  }
743
- function Et(e) {
759
+ function _t(e) {
744
760
  const t = e.replace(/[^a-z0-9]/gi, "").toLowerCase();
745
761
  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");
746
762
  }
747
- function _t(e) {
748
- return typeof e == "string" ? P(e) : m(e, 0, /* @__PURE__ */ new WeakSet());
763
+ function wt(e) {
764
+ return typeof e == "string" ? B(e) : m(e, 0, /* @__PURE__ */ new WeakSet());
749
765
  }
750
- function P(e) {
766
+ function B(e) {
751
767
  try {
752
768
  const t = new URL(e, location.href);
753
769
  for (const s of Array.from(t.searchParams.keys()))
754
- gt.test(s) && t.searchParams.set(s, d);
770
+ mt.test(s) && t.searchParams.set(s, d);
755
771
  return t.username && (t.username = d), t.password && (t.password = d), t.toString();
756
772
  } catch {
757
- return wt(e);
773
+ return It(e);
758
774
  }
759
775
  }
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}`);
776
+ function At(e) {
777
+ return e.replace(St, gt).replace(Tt, kt).replace(U, `Bearer ${d}`).replace(q, `Basic ${d}`).replace(P, d).replace(x, (t, s) => `${s}: ${T}`);
762
778
  }
763
- function wt(e) {
764
- return e.replace(N, `Bearer ${d}`).replace(H, `Basic ${d}`).replace(q, d).replace(U, (t, s) => `${s}: ${E}`);
779
+ function It(e) {
780
+ return e.replace(U, `Bearer ${d}`).replace(q, `Basic ${d}`).replace(P, d).replace(x, (t, s) => `${s}: ${T}`);
765
781
  }
766
- function At(e) {
767
- const t = e.match(St)?.[0] ?? "", s = t ? e.slice(0, -t.length) : e;
768
- return `${P(s)}${t}`;
782
+ function kt(e) {
783
+ const t = e.match(Et)?.[0] ?? "", s = t ? e.slice(0, -t.length) : e;
784
+ return `${B(s)}${t}`;
769
785
  }
770
786
  export {
771
- M as PlunoProductAgent,
772
- M as default
787
+ C as PlunoProductAgent,
788
+ C as default
773
789
  };
@@ -1077,7 +1077,7 @@ function te(e) {
1077
1077
  if (t instanceof HTMLScriptElement)
1078
1078
  return [t];
1079
1079
  const o = new URL(e, document.baseURI).href, n = new URL(o);
1080
- return [...document.querySelectorAll("script[type='module'][src]")].filter(
1080
+ return Array.from(document.querySelectorAll("script[type='module'][src]")).filter(
1081
1081
  (a) => a instanceof HTMLScriptElement && X(a) && ee(a, n)
1082
1082
  );
1083
1083
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluno/product-agent-web",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
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",