@pluno/product-agent-web 0.1.23 → 0.1.25

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,12 +1,11 @@
1
- const z = "https://app.pluno.ai", F = "gpt-5.4";
2
- const H = "pluno.productAgent.state.", k = "pluno.productAgent.pendingEvents.", R = "pluno.productAgent.transportId";
3
- class q {
1
+ const S = '.pluno-pa-widget-host[data-pluno-product-agent-ui="widget"]', V = '.pluno-pa-widget[data-pluno-product-agent-ui-root="widget"]', Y = ".pluno-pa-widget__panel", Z = ".pluno-pa-widget__timeline", M = `${S}[data-pluno-sdk-preview-channel]`, Q = "https://app.pluno.ai", tt = "gpt-5.4", et = 2e4, st = 2e3, m = 6e4, nt = 15e3, rt = 2, it = 1e3, _ = 1e5, ot = 100, L = "pluno.productAgent.state.", E = "pluno.productAgent.pendingEvents.", N = "pluno.productAgent.transportId";
2
+ class W {
4
3
  constructor(t) {
5
- this.options = t, this.transportId = at(), this.state = {
4
+ this.options = t, this.transportId = _t(), this.state = {
6
5
  ...this.state,
7
- starterPrompts: et(t.initialStarterPrompts)
6
+ starterPrompts: ft(t.initialStarterPrompts)
8
7
  };
9
- const s = t.restorePersistedState === !1 ? null : It(t.clientId, t.expectedPersistedSessionId);
8
+ const s = t.restorePersistedState === !1 ? null : qt(t.clientId, t.expectedPersistedSessionId);
10
9
  s && (this.state = {
11
10
  ...this.state,
12
11
  ...s,
@@ -15,7 +14,7 @@ class q {
15
14
  assistantDraft: "",
16
15
  isThinking: !1,
17
16
  lastError: null
18
- }), this.queuedClientEvents = _t(t.clientId);
17
+ }), this.queuedClientEvents = xt(t.clientId);
19
18
  }
20
19
  options;
21
20
  listeners = {};
@@ -49,11 +48,11 @@ class q {
49
48
  lastErrorCode: null
50
49
  };
51
50
  static async init(t) {
52
- const s = new q({
51
+ const s = new W({
53
52
  ...t,
54
- backendUrl: V(t.backendUrl ?? z),
55
- clientId: t.clientId ?? ot(),
56
- model: t.model ?? F
53
+ backendUrl: ut(t.backendUrl ?? Q),
54
+ clientId: t.clientId ?? kt(),
55
+ model: t.model ?? tt
57
56
  });
58
57
  try {
59
58
  s.enableNetworkCapture(), t.autoConnect !== !1 && await s.connect();
@@ -79,7 +78,7 @@ class q {
79
78
  return;
80
79
  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)
81
80
  throw new Error("Pluno requires a token or tokenProvider");
82
- const t = Z(this.options.backendUrl), s = this.options.webSocketFactory?.(t) ?? new WebSocket(t);
81
+ const t = dt(this.options.backendUrl), s = this.options.webSocketFactory?.(t) ?? new WebSocket(t);
83
82
  this.socket = s, s.addEventListener("open", () => {
84
83
  this.socket === s && (u("web-sdk.agent", "Pluno socket opened", {
85
84
  queuedClientEventCount: this.queuedClientEvents.length,
@@ -91,7 +90,7 @@ class q {
91
90
  transportId: this.transportId
92
91
  }), this.flushQueuedClientEvents(), this.startHeartbeat(), this.setState({ status: "connected", lastError: null }));
93
92
  }), s.addEventListener("message", (n) => {
94
- this.socket === s && this.handleServerEvent(Q(n.data));
93
+ this.socket === s && this.handleServerEvent(pt(n.data));
95
94
  }), s.addEventListener("close", (n) => {
96
95
  this.socket === s && (this.stopHeartbeat(), this.socket = null, this.state.status !== "closed" && (u("web-sdk.agent", "Pluno socket closed; scheduling reconnect", {
97
96
  code: typeof n?.code == "number" ? n.code : null,
@@ -119,7 +118,7 @@ class q {
119
118
  const n = t.trim(), r = s.attachments ?? [];
120
119
  if (!n && r.length === 0)
121
120
  return;
122
- const i = g(), a = ct(), o = {
121
+ const i = g(), a = St(), o = {
123
122
  id: `local-${a}`,
124
123
  role: "user",
125
124
  content: n,
@@ -140,7 +139,7 @@ class q {
140
139
  attachments: r.length > 0 ? r : void 0,
141
140
  page: i,
142
141
  model: this.options.model,
143
- metadata: K(this.options.metadata)
142
+ metadata: at(this.options.metadata)
144
143
  };
145
144
  this.activeClientMessageId = a, this.activeUserMessageEvent = c, this.markThinkingProgress(), this.send(c);
146
145
  }
@@ -162,7 +161,7 @@ class q {
162
161
  });
163
162
  }
164
163
  send(t) {
165
- this.sendNow(f(t)) || (this.queuedClientEvents.push(t), m(this.options.clientId, this.queuedClientEvents), this.setState({ status: "reconnecting" }), this.scheduleReconnect());
164
+ this.sendNow(f(t)) || (this.queuedClientEvents.push(t), T(this.options.clientId, this.queuedClientEvents), this.setState({ status: "reconnecting" }), this.scheduleReconnect());
166
165
  }
167
166
  sendNow(t) {
168
167
  if (!this.socket || this.socket.readyState !== WebSocket.OPEN)
@@ -182,26 +181,26 @@ class q {
182
181
  if (this.socket?.readyState !== WebSocket.OPEN || this.queuedClientEvents.length === 0)
183
182
  return;
184
183
  const t = this.queuedClientEvents.splice(0, this.queuedClientEvents.length);
185
- m(this.options.clientId, this.queuedClientEvents);
184
+ T(this.options.clientId, this.queuedClientEvents);
186
185
  for (let s = 0; s < t.length; s += 1) {
187
186
  const n = t[s];
188
187
  if (!this.sendNow(f(n))) {
189
- this.queuedClientEvents.unshift(n, ...t.slice(s + 1)), m(this.options.clientId, this.queuedClientEvents);
188
+ this.queuedClientEvents.unshift(n, ...t.slice(s + 1)), T(this.options.clientId, this.queuedClientEvents);
190
189
  return;
191
190
  }
192
- m(this.options.clientId, this.queuedClientEvents);
191
+ T(this.options.clientId, this.queuedClientEvents);
193
192
  }
194
193
  }
195
194
  handleServerEvent(t) {
196
- if (J(t) && this.markThinkingProgress(), t.type === "auth.ok") {
197
- const s = st(t), n = Object.prototype.hasOwnProperty.call(t, "appearance");
195
+ if (ct(t) && this.markThinkingProgress(), t.type === "auth.ok") {
196
+ const s = yt(t), n = Object.prototype.hasOwnProperty.call(t, "appearance");
198
197
  u("web-sdk.agent", "Received auth.ok appearance", {
199
198
  hasAppearance: n,
200
199
  rawAppearance: t.appearance,
201
200
  normalizedAppearance: s
202
- }), this.runtimeHelperJavascript = nt(t.runtimeHelpers)?.javascript ?? null;
203
- const r = tt(t, "starterPrompts"), i = Object.prototype.hasOwnProperty.call(t, "starterPrompts"), a = {
204
- user: lt(t.user),
201
+ }), this.runtimeHelperJavascript = mt(t.runtimeHelpers)?.javascript ?? null;
202
+ const r = gt(t, "starterPrompts"), i = Object.prototype.hasOwnProperty.call(t, "starterPrompts"), a = {
203
+ user: Et(t.user),
205
204
  status: "connected"
206
205
  };
207
206
  (i || this.state.starterPrompts.length === 0) && (a.starterPrompts = r), (n || s) && (a.appearance = s), this.setState(a), this.state.sessionId && this.send({
@@ -214,21 +213,21 @@ class q {
214
213
  }
215
214
  if (t.type === "conversation.state") {
216
215
  const s = Array.isArray(t.items) ? t.items : [];
217
- Tt(s) && this.clearRetryTimers(), this.setState({
218
- sessionId: P(t.session, "id") ?? this.state.sessionId,
219
- messages: ut(s),
220
- ...b(s) ? { assistantDraft: "", isThinking: !1 } : {}
221
- }), b(s) && this.clearThinkingWatchdog();
216
+ Dt(s) && this.clearRetryTimers(), this.setState({
217
+ sessionId: q(t.session, "id") ?? this.state.sessionId,
218
+ messages: It(s),
219
+ ...O(s) ? { assistantDraft: "", isThinking: !1 } : {}
220
+ }), O(s) && this.clearThinkingWatchdog();
222
221
  return;
223
222
  }
224
223
  if (t.type === "session.updated") {
225
- this.setState({ sessionId: P(t.session, "id") ?? this.state.sessionId });
224
+ this.setState({ sessionId: q(t.session, "id") ?? this.state.sessionId });
226
225
  return;
227
226
  }
228
227
  if (t.type === "session.item") {
229
- const s = U(t.item);
228
+ const s = B(t.item);
230
229
  s && (s.role === "assistant" && this.clearRetryTimers(), this.setState({
231
- messages: yt(this.state.messages, s),
230
+ messages: Mt(this.state.messages, s),
232
231
  assistantDraft: s.role === "assistant" ? "" : this.state.assistantDraft,
233
232
  ...I(t.item.data) ? { assistantDraft: "", isThinking: !1 } : {}
234
233
  }), I(t.item.data) && this.clearThinkingWatchdog(), this.emit("message", s));
@@ -283,7 +282,7 @@ class q {
283
282
  this.retryTimersByClientMessageId = {};
284
283
  }
285
284
  markThinkingProgress() {
286
- !this.state.isThinking || this.state.status === "closed" || this.scheduleThinkingWatchdog(6e4);
285
+ !this.state.isThinking || this.state.status === "closed" || this.scheduleThinkingWatchdog(m);
287
286
  }
288
287
  scheduleThinkingWatchdog(t) {
289
288
  this.thinkingWatchdogTimer !== null && window.clearTimeout(this.thinkingWatchdogTimer), this.thinkingWatchdogTimer = window.setTimeout(() => {
@@ -300,7 +299,7 @@ class q {
300
299
  if (!t) {
301
300
  u("web-sdk.agent", "Pluno thinking watchdog resyncing without active message id", {
302
301
  sessionId: this.state.sessionId
303
- }), this.resyncThinkingSession(), this.scheduleThinkingWatchdog(6e4);
302
+ }), this.resyncThinkingSession(), this.scheduleThinkingWatchdog(m);
304
303
  return;
305
304
  }
306
305
  const s = this.thinkingWatchdogResyncAttemptsByClientMessageId[t] ?? 0, n = this.thinkingWatchdogRetryAttemptsByClientMessageId[t] ?? 0;
@@ -309,15 +308,15 @@ class q {
309
308
  sessionId: this.state.sessionId,
310
309
  clientMessageId: t,
311
310
  resyncAttempts: s + 1
312
- }), this.resyncThinkingSession(), this.scheduleThinkingWatchdog(15e3);
311
+ }), this.resyncThinkingSession(), this.scheduleThinkingWatchdog(nt);
313
312
  return;
314
313
  }
315
- if (n >= 2) {
314
+ if (n >= rt) {
316
315
  u("web-sdk.agent", "Pluno thinking watchdog retry limit reached; continuing resync", {
317
316
  sessionId: this.state.sessionId,
318
317
  clientMessageId: t,
319
318
  retryAttempts: n
320
- }), this.resyncThinkingSession(), this.scheduleThinkingWatchdog(6e4);
319
+ }), this.resyncThinkingSession(), this.scheduleThinkingWatchdog(m);
321
320
  return;
322
321
  }
323
322
  this.thinkingWatchdogRetryAttemptsByClientMessageId[t] = n + 1, this.setState({
@@ -332,7 +331,7 @@ class q {
332
331
  type: "chat.retry_last_user_message",
333
332
  sessionId: this.state.sessionId,
334
333
  clientMessageId: t
335
- }) : this.activeUserMessageEvent && this.send(this.activeUserMessageEvent), this.scheduleThinkingWatchdog(6e4);
334
+ }) : this.activeUserMessageEvent && this.send(this.activeUserMessageEvent), this.scheduleThinkingWatchdog(m);
336
335
  }
337
336
  resyncThinkingSession() {
338
337
  this.state.sessionId ? this.send({
@@ -344,9 +343,9 @@ class q {
344
343
  }
345
344
  async executeToolCall(t) {
346
345
  const s = typeof t.sessionId == "string" ? t.sessionId : null, n = typeof t.callId == "string" ? t.callId : null, r = t.rawInput;
347
- if (!s || !n || !Ct(r))
346
+ if (!s || !n || !Bt(r))
348
347
  return;
349
- const i = await this.executeRuntimeHelper(), a = await M(r).catch((o) => ({
348
+ const i = await this.executeRuntimeHelper(), a = await D(r).catch((o) => ({
350
349
  ok: !1,
351
350
  exception: {
352
351
  message: o instanceof Error ? o.message : String(o)
@@ -359,45 +358,45 @@ class q {
359
358
  toolName: "execute_code",
360
359
  summary: r.summary,
361
360
  rawInput: f(r),
362
- rawOutput: f(rt(a, i))
361
+ rawOutput: f(Tt(a, i))
363
362
  });
364
363
  }
365
364
  async executeRuntimeHelper() {
366
365
  if (!this.runtimeHelperJavascript?.trim())
367
366
  return null;
368
- const t = await M({
367
+ const t = await D({
369
368
  javascript: this.runtimeHelperJavascript
370
369
  });
371
- return t.ok === !1 ? it(t) : null;
370
+ return t.ok === !1 ? wt(t) : null;
372
371
  }
373
372
  enableNetworkCapture() {
374
373
  if (this.networkCaptureCleanup)
375
374
  return;
376
375
  const t = window.fetch.bind(window), s = XMLHttpRequest.prototype.open, n = XMLHttpRequest.prototype.setRequestHeader, r = XMLHttpRequest.prototype.send;
377
376
  window.fetch = async (i, a) => {
378
- const o = Date.now(), c = new Date(o).toISOString(), l = i instanceof Request ? i : null, y = typeof i == "string" ? i : i instanceof URL ? i.toString() : l?.url ?? "", w = (a?.method ?? l?.method ?? "GET").toUpperCase(), A = O(new Headers(a?.headers ?? l?.headers ?? void 0)), C = await Rt(l, a);
377
+ const o = Date.now(), c = new Date(o).toISOString(), l = i instanceof Request ? i : null, y = typeof i == "string" ? i : i instanceof URL ? i.toString() : l?.url ?? "", R = (a?.method ?? l?.method ?? "GET").toUpperCase(), b = x(new Headers(a?.headers ?? l?.headers ?? void 0)), P = await jt(l, a);
379
378
  try {
380
379
  const d = await t(i, a);
381
380
  return this.enqueueNetworkEvent({
382
- requestId: T("fetch"),
381
+ requestId: w("fetch"),
383
382
  url: y,
384
- method: w,
385
- requestHeaders: A,
386
- requestBody: C,
383
+ method: R,
384
+ requestHeaders: b,
385
+ requestBody: P,
387
386
  resourceType: "fetch",
388
387
  responseStatus: d.status,
389
- responseHeaders: O(d.headers),
390
- responseBody: await Mt(d),
388
+ responseHeaders: x(d.headers),
389
+ responseBody: await vt(d),
391
390
  startedAt: c,
392
391
  durationMs: Date.now() - o
393
392
  }), d;
394
393
  } catch (d) {
395
394
  throw this.enqueueNetworkEvent({
396
- requestId: T("fetch"),
395
+ requestId: w("fetch"),
397
396
  url: y,
398
- method: w,
399
- requestHeaders: A,
400
- requestBody: C,
397
+ method: R,
398
+ requestHeaders: b,
399
+ requestBody: P,
401
400
  resourceType: "fetch",
402
401
  errorText: d instanceof Error ? d.message : String(d),
403
402
  startedAt: c,
@@ -406,7 +405,7 @@ class q {
406
405
  }
407
406
  }, XMLHttpRequest.prototype.open = function(a, o, c, l, y) {
408
407
  return this.__plunoMeta = {
409
- requestId: T("xhr"),
408
+ requestId: w("xhr"),
410
409
  method: String(a ?? "GET").toUpperCase(),
411
410
  url: typeof o == "string" ? o : o.toString(),
412
411
  requestHeaders: {},
@@ -422,14 +421,14 @@ class q {
422
421
  return n.call(this, a, o);
423
422
  }, XMLHttpRequest.prototype.send = function(a) {
424
423
  const o = window.__plunoProductAgentInstance, c = this.__plunoMeta ?? {
425
- requestId: T("xhr"),
424
+ requestId: w("xhr"),
426
425
  method: "GET",
427
426
  url: "",
428
427
  requestHeaders: {},
429
428
  startedAtMs: Date.now(),
430
429
  startedAt: (/* @__PURE__ */ new Date()).toISOString()
431
430
  };
432
- return c.requestBody = L(a), this.__plunoMeta = c, this.addEventListener(
431
+ return c.requestBody = G(a), this.__plunoMeta = c, this.addEventListener(
433
432
  "loadend",
434
433
  function() {
435
434
  !o || !this.__plunoMeta || o.enqueueNetworkEvent({
@@ -440,8 +439,8 @@ class q {
440
439
  requestBody: typeof this.__plunoMeta.requestBody == "string" ? this.__plunoMeta.requestBody : void 0,
441
440
  resourceType: "xhr",
442
441
  responseStatus: this.status,
443
- responseHeaders: Nt(this.getAllResponseHeaders()),
444
- responseBody: bt(this),
442
+ responseHeaders: Gt(this.getAllResponseHeaders()),
443
+ responseBody: $t(this),
445
444
  errorText: this.status === 0 ? "XHR request failed or was aborted" : void 0,
446
445
  startedAt: String(this.__plunoMeta.startedAt),
447
446
  durationMs: Date.now() - Number(this.__plunoMeta.startedAtMs ?? Date.now())
@@ -463,7 +462,7 @@ class q {
463
462
  page: g(),
464
463
  events: s
465
464
  });
466
- }, 1e3));
465
+ }, it));
467
466
  }
468
467
  scheduleReconnect() {
469
468
  this.reconnectTimer !== null || this.state.status === "closed" || (this.reconnectTimer = window.setTimeout(() => {
@@ -474,12 +473,12 @@ class q {
474
473
  isThinking: this.state.isThinking
475
474
  }), this.setState({ status: "reconnecting", lastError: null }), this.scheduleReconnect();
476
475
  });
477
- }, 2e3));
476
+ }, st));
478
477
  }
479
478
  startHeartbeat() {
480
479
  this.stopHeartbeat(), this.heartbeatTimer = window.setInterval(() => {
481
480
  this.sendNow({ type: "runtime.ping" });
482
- }, 2e4);
481
+ }, et);
483
482
  }
484
483
  stopHeartbeat() {
485
484
  this.heartbeatTimer !== null && (window.clearInterval(this.heartbeatTimer), this.heartbeatTimer = null);
@@ -489,7 +488,7 @@ class q {
489
488
  ...this.state,
490
489
  ...t,
491
490
  ...t.lastError === null && t.lastErrorCode === void 0 ? { lastErrorCode: null } : {}
492
- }, Et(this.options.clientId, this.state), this.emit("state", this.getState());
491
+ }, Ht(this.options.clientId, this.state), this.emit("state", this.getState());
493
492
  }
494
493
  emit(t, s) {
495
494
  this.listeners[t]?.forEach((r) => r(s));
@@ -506,17 +505,17 @@ function u(e, t, s) {
506
505
  }, i = n.__plunoProductAgentDiagnostics__ ?? [];
507
506
  i.push(r), i.length > 120 && i.splice(0, i.length - 120), n.__plunoProductAgentDiagnostics__ = i, n.__PLUNO_PRODUCT_AGENT_DIAGNOSTICS__ = () => [...i], window.dispatchEvent(new CustomEvent("product-agent:preview-diagnostic", { detail: r }));
508
507
  }
509
- function K(e) {
508
+ function at(e) {
510
509
  const t = typeof e == "function" ? e() : e;
511
510
  return t && Object.keys(t).length > 0 ? t : void 0;
512
511
  }
513
- function J(e) {
512
+ function ct(e) {
514
513
  return e.type === "conversation.state" || e.type === "session.updated" || e.type === "session.item" || e.type === "chat.assistant_delta" || e.type === "chat.assistant_done" || e.type === "tool.call";
515
514
  }
516
- const Y = 5e3;
517
- async function M(e) {
515
+ const lt = 5e3;
516
+ async function D(e) {
518
517
  const t = Object.getPrototypeOf(async function() {
519
- }).constructor, s = Y, n = Date.now(), r = [], i = {
518
+ }).constructor, s = lt, n = Date.now(), r = [], i = {
520
519
  log: console.log,
521
520
  info: console.info,
522
521
  warn: console.warn,
@@ -560,21 +559,55 @@ async function M(e) {
560
559
  console.log = i.log, console.info = i.info, console.warn = i.warn, console.error = i.error;
561
560
  }
562
561
  }
563
- function V(e) {
562
+ function ut(e) {
564
563
  return e.replace(/\/+$/, "");
565
564
  }
566
- function Z(e) {
565
+ function dt(e) {
567
566
  const t = new URL("/api/product-agent/embed/ws", e);
568
567
  return t.protocol = t.protocol === "https:" ? "wss:" : "ws:", t.toString();
569
568
  }
570
569
  function g() {
570
+ const e = ht();
571
571
  return {
572
572
  url: location.href,
573
573
  title: document.title,
574
- origin: location.origin
574
+ origin: location.origin,
575
+ ...e ? { plunoProductAgentUi: e } : {}
576
+ };
577
+ }
578
+ function ht() {
579
+ const e = document.querySelector(M);
580
+ if (!(e ?? document.querySelector(S)))
581
+ return;
582
+ const s = e ? "browser_extension_sdk_preview" : "embedded_widget";
583
+ return {
584
+ surface: s,
585
+ description: s === "browser_extension_sdk_preview" ? "Pluno browser-extension SDK preview widget embedded in the host page." : "Pluno Product Agent default widget embedded in the host page.",
586
+ selectors: [
587
+ {
588
+ name: "widget_host",
589
+ selector: s === "browser_extension_sdk_preview" ? M : S,
590
+ description: "Finds Pluno's shadow-host element in the host page DOM."
591
+ },
592
+ {
593
+ name: "widget_root",
594
+ selector: V,
595
+ description: "Finds Pluno's widget root inside the widget host shadow root."
596
+ },
597
+ {
598
+ name: "widget_panel",
599
+ selector: Y,
600
+ description: "Finds Pluno's open chat panel inside the widget host shadow root."
601
+ },
602
+ {
603
+ name: "widget_timeline",
604
+ selector: Z,
605
+ description: "Finds Pluno's chat timeline inside the widget host shadow root."
606
+ }
607
+ ]
575
608
  };
576
609
  }
577
- function Q(e) {
610
+ function pt(e) {
578
611
  try {
579
612
  const t = JSON.parse(e);
580
613
  return t && typeof t == "object" ? t : { type: "error", message: "Invalid server event" };
@@ -582,16 +615,16 @@ function Q(e) {
582
615
  return { type: "error", message: "Invalid server event" };
583
616
  }
584
617
  }
585
- function tt(e, t) {
618
+ function gt(e, t) {
586
619
  if (!e || typeof e != "object")
587
620
  return [];
588
621
  const s = e[t];
589
622
  return Array.isArray(s) ? s.filter((n) => typeof n == "string" && n.trim().length > 0) : [];
590
623
  }
591
- function et(e) {
624
+ function ft(e) {
592
625
  return Array.isArray(e) ? e.filter((t) => typeof t == "string" && t.trim().length > 0) : [];
593
626
  }
594
- function st(e) {
627
+ function yt(e) {
595
628
  if (!e || typeof e != "object")
596
629
  return null;
597
630
  const t = e, s = t.appearance, n = s && typeof s == "object" ? s : t, r = typeof n.accentColor == "string" ? n.accentColor : null, i = n.colorScheme === "dark" ? "dark" : n.colorScheme === "light" ? "light" : null, a = typeof n.fontFamily == "string" && n.fontFamily.trim() ? n.fontFamily : null, o = typeof n.scribbleStyle == "boolean" ? n.scribbleStyle : null;
@@ -602,13 +635,13 @@ function st(e) {
602
635
  ...o !== null ? { scribbleStyle: o } : {}
603
636
  };
604
637
  }
605
- function nt(e) {
638
+ function mt(e) {
606
639
  if (!e || typeof e != "object")
607
640
  return null;
608
641
  const t = e.javascript;
609
642
  return typeof t != "string" || !t.trim() ? null : { javascript: t };
610
643
  }
611
- function rt(e, t) {
644
+ function Tt(e, t) {
612
645
  return t ? e && typeof e == "object" ? {
613
646
  ...e,
614
647
  helperError: t
@@ -618,30 +651,30 @@ function rt(e, t) {
618
651
  helperError: t
619
652
  } : e;
620
653
  }
621
- function it(e) {
654
+ function wt(e) {
622
655
  if (!e || typeof e != "object")
623
656
  return e;
624
657
  const t = e;
625
658
  return typeof t.exception?.message == "string" ? t.exception.message : typeof t.error == "string" ? t.error : e;
626
659
  }
627
- function ot() {
660
+ function kt() {
628
661
  const e = "pluno.productAgent.clientId", t = window.localStorage.getItem(e);
629
662
  if (t)
630
663
  return t;
631
664
  const s = crypto.randomUUID();
632
665
  return window.localStorage.setItem(e, s), s;
633
666
  }
634
- function at() {
635
- const e = window.sessionStorage.getItem(R);
667
+ function _t() {
668
+ const e = window.sessionStorage.getItem(N);
636
669
  if (e)
637
670
  return e;
638
671
  const t = crypto.randomUUID();
639
- return window.sessionStorage.setItem(R, t), t;
672
+ return window.sessionStorage.setItem(N, t), t;
640
673
  }
641
- function ct() {
674
+ function St() {
642
675
  return crypto.randomUUID();
643
676
  }
644
- function lt(e) {
677
+ function Et(e) {
645
678
  if (!e || typeof e != "object")
646
679
  return null;
647
680
  const t = e, s = typeof t.id == "string" ? t.id : null;
@@ -652,12 +685,12 @@ function lt(e) {
652
685
  avatarUrl: typeof t.avatarUrl == "string" ? t.avatarUrl : null
653
686
  } : null;
654
687
  }
655
- function ut(e) {
656
- return Array.isArray(e) ? E(
657
- e.map(U).filter((t) => t !== null)
688
+ function It(e) {
689
+ return Array.isArray(e) ? A(
690
+ e.map(B).filter((t) => t !== null)
658
691
  ) : [];
659
692
  }
660
- function U(e) {
693
+ function B(e) {
661
694
  if (!e || typeof e != "object")
662
695
  return null;
663
696
  const t = e, s = t.data;
@@ -669,32 +702,32 @@ function U(e) {
669
702
  return {
670
703
  id: String(t.id ?? crypto.randomUUID()),
671
704
  role: r,
672
- content: ft(n.content),
705
+ content: Pt(n.content),
673
706
  createdAt: typeof t.createdAt == "string" ? t.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
674
- attachments: B(n.attachments)
707
+ attachments: $(n.attachments)
675
708
  };
676
709
  }
677
710
  return n.type === "function_call" || n.type === "tool_call" || n.type === "web_search_call" ? {
678
711
  id: String(t.id ?? crypto.randomUUID()),
679
712
  role: "tool",
680
- content: ht(n),
713
+ content: Ct(n),
681
714
  createdAt: typeof t.createdAt == "string" ? t.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
682
715
  dataType: String(n.type),
683
716
  toolName: typeof n.name == "string" ? n.name : void 0,
684
- callId: gt(n) ?? void 0,
717
+ callId: bt(n) ?? void 0,
685
718
  loading: n.localExecutionStatus === "running"
686
719
  } : n.type === "run_status" || n.type === "run_error" ? n.type === "run_status" && (n.status === "running" || n.status === "retrying") || n.type === "run_error" && n.stage === "tool_execution" ? null : {
687
720
  id: String(t.id ?? crypto.randomUUID()),
688
721
  role: "system",
689
- content: dt(n),
722
+ content: At(n),
690
723
  createdAt: typeof t.createdAt == "string" ? t.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
691
724
  dataType: String(n.type)
692
725
  } : null;
693
726
  }
694
- function dt(e) {
727
+ function At(e) {
695
728
  return typeof e.message == "string" && e.message.trim().length > 0 ? e.message.replace(/Product Agent/g, "Pluno") : e.type === "run_status" && e.status === "interrupted" ? "Pluno was interrupted before it could finish this message." : e.type === "run_status" && e.status === "stopped" ? "Pluno stopped." : "Pluno run status changed.";
696
729
  }
697
- function ht(e) {
730
+ function Ct(e) {
698
731
  if (e.type === "web_search_call") {
699
732
  const t = e.action;
700
733
  if (t && typeof t == "object") {
@@ -706,9 +739,9 @@ function ht(e) {
706
739
  }
707
740
  return "Searching the web";
708
741
  }
709
- return pt(e);
742
+ return Rt(e);
710
743
  }
711
- function pt(e) {
744
+ function Rt(e) {
712
745
  if (typeof e.summary == "string" && e.summary.trim().length > 0)
713
746
  return e.summary;
714
747
  if (typeof e.arguments == "string")
@@ -721,11 +754,11 @@ function pt(e) {
721
754
  }
722
755
  return typeof e.name == "string" && e.name.trim().length > 0 ? e.name : "Run tool";
723
756
  }
724
- function gt(e) {
757
+ function bt(e) {
725
758
  const t = e.callId ?? e.call_id;
726
759
  return typeof t == "string" && t ? t : null;
727
760
  }
728
- function ft(e) {
761
+ function Pt(e) {
729
762
  return typeof e == "string" ? e : Array.isArray(e) ? e.map((t) => {
730
763
  if (!t || typeof t != "object")
731
764
  return "";
@@ -733,14 +766,14 @@ function ft(e) {
733
766
  return typeof s.text == "string" ? s.text : typeof s.content == "string" ? s.content : "";
734
767
  }).filter(Boolean).join("") : "";
735
768
  }
736
- function yt(e, t) {
737
- const s = mt(e, t), n = s.findIndex((i) => i.id === t.id);
769
+ function Mt(e, t) {
770
+ const s = Nt(e, t), n = s.findIndex((i) => i.id === t.id);
738
771
  if (n === -1)
739
- return E([...s, t]);
772
+ return A([...s, t]);
740
773
  const r = [...s];
741
- return r[n] = t, E(r);
774
+ return r[n] = t, A(r);
742
775
  }
743
- function mt(e, t) {
776
+ function Nt(e, t) {
744
777
  if (t.role !== "user")
745
778
  return e;
746
779
  const s = e.findIndex(
@@ -751,15 +784,15 @@ function mt(e, t) {
751
784
  const n = [...e];
752
785
  return n.splice(s, 1), n;
753
786
  }
754
- function b(e) {
755
- const t = W(e);
787
+ function O(e) {
788
+ const t = j(e);
756
789
  return t === null ? !1 : e.slice(t + 1).some((s) => !s || typeof s != "object" ? !1 : I(s.data));
757
790
  }
758
- function Tt(e) {
759
- const t = W(e);
760
- return t === null ? e.some((s) => !s || typeof s != "object" ? !1 : N(s.data)) : e.slice(t + 1).some((s) => !s || typeof s != "object" ? !1 : N(s.data));
791
+ function Dt(e) {
792
+ const t = j(e);
793
+ return t === null ? e.some((s) => !s || typeof s != "object" ? !1 : U(s.data)) : e.slice(t + 1).some((s) => !s || typeof s != "object" ? !1 : U(s.data));
761
794
  }
762
- function W(e) {
795
+ function j(e) {
763
796
  for (let t = e.length - 1; t >= 0; t -= 1) {
764
797
  const s = e[t];
765
798
  if (!s || typeof s != "object")
@@ -773,7 +806,7 @@ function W(e) {
773
806
  }
774
807
  return null;
775
808
  }
776
- function N(e) {
809
+ function U(e) {
777
810
  if (!e || typeof e != "object")
778
811
  return !1;
779
812
  const t = e;
@@ -785,13 +818,13 @@ function I(e) {
785
818
  const t = e;
786
819
  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");
787
820
  }
788
- function E(e) {
789
- return e.filter((t, s) => St(t) ? !kt(e, s) : !0);
821
+ function A(e) {
822
+ return e.filter((t, s) => Ot(t) ? !Ut(e, s) : !0);
790
823
  }
791
- function St(e) {
824
+ function Ot(e) {
792
825
  return e.role === "system" && (e.dataType === "run_status" || e.dataType === "run_error");
793
826
  }
794
- function kt(e, t) {
827
+ function Ut(e, t) {
795
828
  for (let s = t + 1; s < e.length; s += 1) {
796
829
  const n = e[s];
797
830
  if (n.role === "user")
@@ -801,18 +834,18 @@ function kt(e, t) {
801
834
  }
802
835
  return !1;
803
836
  }
804
- function P(e, t) {
837
+ function q(e, t) {
805
838
  return e && typeof e == "object" && typeof e[t] == "string" ? e[t] : null;
806
839
  }
807
- function It(e, t) {
840
+ function qt(e, t) {
808
841
  try {
809
- const s = window.localStorage.getItem(`${H}${e}`);
842
+ const s = window.localStorage.getItem(`${L}${e}`);
810
843
  if (!s)
811
844
  return null;
812
845
  const n = JSON.parse(s), r = typeof n.sessionId == "string" ? n.sessionId : null;
813
846
  if (t !== void 0 && r !== t)
814
847
  return null;
815
- const i = Array.isArray(n.messages) ? n.messages.map(At).filter((a) => !!a) : [];
848
+ const i = Array.isArray(n.messages) ? n.messages.map(Wt).filter((a) => !!a) : [];
816
849
  return {
817
850
  sessionId: r,
818
851
  messages: i
@@ -821,72 +854,72 @@ function It(e, t) {
821
854
  return null;
822
855
  }
823
856
  }
824
- function Et(e, t) {
857
+ function Ht(e, t) {
825
858
  try {
826
859
  window.localStorage.setItem(
827
- `${H}${e}`,
860
+ `${L}${e}`,
828
861
  JSON.stringify({
829
862
  sessionId: t.sessionId,
830
- messages: t.messages.slice(-100)
863
+ messages: t.messages.slice(-ot)
831
864
  })
832
865
  );
833
866
  } catch {
834
867
  return;
835
868
  }
836
869
  }
837
- function _t(e) {
870
+ function xt(e) {
838
871
  try {
839
- const t = window.localStorage.getItem(`${k}${e}`);
872
+ const t = window.localStorage.getItem(`${E}${e}`);
840
873
  if (!t)
841
874
  return [];
842
875
  const s = JSON.parse(t);
843
- return Array.isArray(s) ? s.filter(x) : [];
876
+ return Array.isArray(s) ? s.filter(v) : [];
844
877
  } catch {
845
878
  return [];
846
879
  }
847
880
  }
848
- function m(e, t) {
881
+ function T(e, t) {
849
882
  try {
850
- const s = t.filter(x);
883
+ const s = t.filter(v);
851
884
  if (s.length === 0) {
852
- window.localStorage.removeItem(`${k}${e}`);
885
+ window.localStorage.removeItem(`${E}${e}`);
853
886
  return;
854
887
  }
855
888
  window.localStorage.setItem(
856
- `${k}${e}`,
889
+ `${E}${e}`,
857
890
  JSON.stringify(s.slice(-25))
858
891
  );
859
892
  } catch {
860
893
  return;
861
894
  }
862
895
  }
863
- function x(e) {
896
+ function v(e) {
864
897
  if (!e || typeof e != "object")
865
898
  return !1;
866
899
  const t = e;
867
- return t.type === "chat.user_message" ? typeof t.content == "string" && D(t.page) : t.type === "page.upsert" || t.type === "session.reset" || t.type === "network.batch" ? D(t.page) : t.type === "tool.result" ? typeof t.sessionId == "string" && typeof t.callId == "string" && t.toolName === "execute_code" : t.type === "chat.retry_last_user_message" ? typeof t.sessionId == "string" && typeof t.clientMessageId == "string" : t.type === "run.stop" ? typeof t.sessionId == "string" : !1;
900
+ return t.type === "chat.user_message" ? typeof t.content == "string" && H(t.page) : t.type === "page.upsert" || t.type === "session.reset" || t.type === "network.batch" ? H(t.page) : t.type === "tool.result" ? typeof t.sessionId == "string" && typeof t.callId == "string" && t.toolName === "execute_code" : t.type === "chat.retry_last_user_message" ? typeof t.sessionId == "string" && typeof t.clientMessageId == "string" : t.type === "run.stop" ? typeof t.sessionId == "string" : !1;
868
901
  }
869
- function D(e) {
902
+ function H(e) {
870
903
  if (!e || typeof e != "object")
871
904
  return !1;
872
905
  const t = e;
873
906
  return typeof t.url == "string" && typeof t.title == "string" && typeof t.origin == "string";
874
907
  }
875
- function B(e) {
908
+ function $(e) {
876
909
  if (!Array.isArray(e))
877
910
  return;
878
911
  const t = e.filter((s) => {
879
912
  if (!s || typeof s != "object")
880
913
  return !1;
881
914
  const n = s;
882
- return typeof n.name == "string" && wt(n.mimeType) && typeof n.sizeBytes == "number" && typeof n.dataUrl == "string";
915
+ return typeof n.name == "string" && Lt(n.mimeType) && typeof n.sizeBytes == "number" && typeof n.dataUrl == "string";
883
916
  });
884
917
  return t.length > 0 ? t : void 0;
885
918
  }
886
- function wt(e) {
919
+ function Lt(e) {
887
920
  return e === "image/png" || e === "image/jpeg" || e === "image/webp" || e === "image/gif" || e === "application/pdf";
888
921
  }
889
- function At(e) {
922
+ function Wt(e) {
890
923
  if (!e || typeof e != "object")
891
924
  return null;
892
925
  const t = e;
@@ -896,22 +929,22 @@ function At(e) {
896
929
  content: t.content,
897
930
  createdAt: t.createdAt,
898
931
  dataType: typeof t.dataType == "string" ? t.dataType : void 0,
899
- attachments: B(t.attachments),
932
+ attachments: $(t.attachments),
900
933
  loading: typeof t.loading == "boolean" ? t.loading : void 0
901
934
  };
902
935
  }
903
- function Ct(e) {
936
+ function Bt(e) {
904
937
  return !!e && typeof e == "object" && typeof e.summary == "string" && typeof e.javascript == "string";
905
938
  }
906
- function O(e) {
939
+ function x(e) {
907
940
  const t = {};
908
941
  return e?.forEach((s, n) => {
909
942
  t[n] = s;
910
943
  }), t;
911
944
  }
912
- async function Rt(e, t) {
945
+ async function jt(e, t) {
913
946
  if (typeof t?.body < "u")
914
- return L(t.body);
947
+ return G(t.body);
915
948
  if (e)
916
949
  try {
917
950
  return p(await e.clone().text());
@@ -919,21 +952,21 @@ async function Rt(e, t) {
919
952
  return;
920
953
  }
921
954
  }
922
- async function Mt(e) {
955
+ async function vt(e) {
923
956
  try {
924
957
  return p(await e.clone().text());
925
958
  } catch (t) {
926
959
  return { error: t instanceof Error ? t.message : "unavailable" };
927
960
  }
928
961
  }
929
- function bt(e) {
962
+ function $t(e) {
930
963
  try {
931
964
  return e.responseType === "" || e.responseType === "text" ? p(e.responseText ?? "") : e.responseType === "json" ? p(JSON.stringify(e.response)) : `[unsupported xhr responseType: ${e.responseType || "unknown"}]`;
932
965
  } catch (t) {
933
966
  return { error: t instanceof Error ? t.message : "unavailable" };
934
967
  }
935
968
  }
936
- function L(e) {
969
+ function G(e) {
937
970
  if (!(e === null || typeof e > "u")) {
938
971
  if (typeof e == "string")
939
972
  return p(e);
@@ -952,7 +985,7 @@ function L(e) {
952
985
  }
953
986
  }
954
987
  }
955
- function Nt(e) {
988
+ function Gt(e) {
956
989
  const t = {};
957
990
  for (const s of e.trim().split(/[\r\n]+/)) {
958
991
  const n = s.indexOf(":");
@@ -961,59 +994,64 @@ function Nt(e) {
961
994
  return t;
962
995
  }
963
996
  function p(e) {
964
- return e.length <= 1e5 ? e : `${e.slice(0, 1e5)}... [truncated ${e.length - 1e5} chars]`;
997
+ return e.length <= _ ? e : `${e.slice(0, _)}... [truncated ${e.length - _} chars]`;
965
998
  }
966
- function T(e) {
999
+ function w(e) {
967
1000
  return `${e}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
968
1001
  }
969
- const _ = "[REDACTED_SECRET]", h = "[REDACTED_TOKEN]", Pt = "[REDACTED_SIGNED_URL]", Dt = 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, j = /\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi, G = /\bBasic\s+[A-Za-z0-9+/=-]{12,}/gi, v = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g, $ = /\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, Ht = /\bhttps?:\/\/[^\s"'<>]+(?:X-Amz-Signature|X-Goog-Signature|Signature|sig=)[^\s"'<>]*/gi, qt = /\bhttps?:\/\/[^\s"'<>]+/gi, Ut = /[),.;\]]+$/;
1002
+ const C = "[REDACTED_SECRET]", h = "[REDACTED_TOKEN]", Ft = "[REDACTED_SIGNED_URL]", zt = 20, Xt = /^(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, F = /\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi, z = /\bBasic\s+[A-Za-z0-9+/=-]{12,}/gi, X = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g, J = /\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, Jt = /\bhttps?:\/\/[^\s"'<>]+(?:X-Amz-Signature|X-Goog-Signature|Signature|sig=)[^\s"'<>]*/gi, Kt = /\bhttps?:\/\/[^\s"'<>]+/gi, Vt = /[),.;\]]+$/;
970
1003
  function f(e) {
971
- return S(e, 0, /* @__PURE__ */ new WeakSet());
1004
+ return k(e, 0, /* @__PURE__ */ new WeakSet());
972
1005
  }
973
- function S(e, t, s) {
1006
+ function k(e, t, s) {
974
1007
  if (typeof e == "string")
975
- return e.startsWith("data:image/") || e.startsWith("data:application/pdf;") ? e : Bt(e);
1008
+ return e.startsWith("data:image/") || e.startsWith("data:application/pdf;") ? e : Qt(e);
976
1009
  if (e === null || typeof e != "object")
977
1010
  return e;
978
- if (t >= Dt)
1011
+ if (t >= zt)
979
1012
  return "[REDACTED_MAX_DEPTH]";
980
1013
  if (s.has(e))
981
1014
  return "[REDACTED_CIRCULAR]";
982
1015
  if (s.add(e), Array.isArray(e))
983
- return e.map((r) => S(r, t + 1, s));
1016
+ return e.map((r) => k(r, t + 1, s));
984
1017
  const n = {};
985
1018
  for (const [r, i] of Object.entries(e))
986
- Wt(r) ? n[r] = _ : n[r] = r.toLowerCase() === "url" ? xt(i) : S(i, t + 1, s);
1019
+ Yt(r) ? n[r] = C : n[r] = r.toLowerCase() === "url" ? Zt(i) : k(i, t + 1, s);
987
1020
  return n;
988
1021
  }
989
- function Wt(e) {
1022
+ function Yt(e) {
990
1023
  const t = e.replace(/[^a-z0-9]/gi, "").toLowerCase();
991
1024
  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");
992
1025
  }
993
- function xt(e) {
994
- return typeof e == "string" ? X(e) : S(e, 0, /* @__PURE__ */ new WeakSet());
1026
+ function Zt(e) {
1027
+ return typeof e == "string" ? K(e) : k(e, 0, /* @__PURE__ */ new WeakSet());
995
1028
  }
996
- function X(e) {
1029
+ function K(e) {
997
1030
  try {
998
1031
  const t = new URL(e, location.href);
999
1032
  for (const s of Array.from(t.searchParams.keys()))
1000
- Ot.test(s) && t.searchParams.set(s, h);
1033
+ Xt.test(s) && t.searchParams.set(s, h);
1001
1034
  return t.username && (t.username = h), t.password && (t.password = h), t.toString();
1002
1035
  } catch {
1003
- return Lt(e);
1036
+ return te(e);
1004
1037
  }
1005
1038
  }
1006
- function Bt(e) {
1007
- return e.replace(Ht, Pt).replace(qt, jt).replace(j, `Bearer ${h}`).replace(G, `Basic ${h}`).replace(v, h).replace($, (t, s) => `${s}: ${_}`);
1039
+ function Qt(e) {
1040
+ return e.replace(Jt, Ft).replace(Kt, ee).replace(F, `Bearer ${h}`).replace(z, `Basic ${h}`).replace(X, h).replace(J, (t, s) => `${s}: ${C}`);
1008
1041
  }
1009
- function Lt(e) {
1010
- return e.replace(j, `Bearer ${h}`).replace(G, `Basic ${h}`).replace(v, h).replace($, (t, s) => `${s}: ${_}`);
1042
+ function te(e) {
1043
+ return e.replace(F, `Bearer ${h}`).replace(z, `Basic ${h}`).replace(X, h).replace(J, (t, s) => `${s}: ${C}`);
1011
1044
  }
1012
- function jt(e) {
1013
- const t = e.match(Ut)?.[0] ?? "", s = t ? e.slice(0, -t.length) : e;
1014
- return `${X(s)}${t}`;
1045
+ function ee(e) {
1046
+ const t = e.match(Vt)?.[0] ?? "", s = t ? e.slice(0, -t.length) : e;
1047
+ return `${K(s)}${t}`;
1015
1048
  }
1016
1049
  export {
1017
- q as PlunoProductAgent,
1018
- q as default
1050
+ M as PLUNO_PRODUCT_AGENT_SDK_PREVIEW_HOST_SELECTOR,
1051
+ S as PLUNO_PRODUCT_AGENT_WIDGET_HOST_SELECTOR,
1052
+ Y as PLUNO_PRODUCT_AGENT_WIDGET_PANEL_SELECTOR,
1053
+ V as PLUNO_PRODUCT_AGENT_WIDGET_ROOT_SELECTOR,
1054
+ Z as PLUNO_PRODUCT_AGENT_WIDGET_TIMELINE_SELECTOR,
1055
+ W as PlunoProductAgent,
1056
+ W as default
1019
1057
  };