@pluno/product-agent-web 0.1.60 → 0.1.61

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,11 +1,11 @@
1
- const _t = "pluno-product-agent-attachments";
2
- const H = "files";
3
- async function it(e) {
4
- const t = await U();
5
- await at(t, "readwrite", (s) => s.put(e));
6
- }
7
- async function Pt(e) {
8
- const t = await U(), s = await at(
1
+ const Ut = "pluno-product-agent-attachments";
2
+ const W = "files";
3
+ async function at(e) {
4
+ const t = await D();
5
+ await lt(t, "readwrite", (s) => s.put(e));
6
+ }
7
+ async function Ct(e) {
8
+ const t = await D(), s = await lt(
9
9
  t,
10
10
  "readonly",
11
11
  (r) => r.get(e)
@@ -13,12 +13,12 @@ async function Pt(e) {
13
13
  if (!s)
14
14
  return null;
15
15
  const n = Date.now();
16
- return await ot(e, { lastUsedAt: n }), { ...s, lastUsedAt: n };
16
+ return await ct(e, { lastUsedAt: n }), { ...s, lastUsedAt: n };
17
17
  }
18
- async function ot(e, t) {
19
- const s = await U();
20
- await v(s, "readwrite", async (n) => {
21
- const r = await j(
18
+ async function ct(e, t) {
19
+ const s = await D();
20
+ await $(s, "readwrite", async (n) => {
21
+ const r = await z(
22
22
  n.get(e)
23
23
  );
24
24
  r && n.put({
@@ -28,27 +28,27 @@ async function ot(e, t) {
28
28
  });
29
29
  }
30
30
  async function Mt(e = 864e5) {
31
- const t = await U(), s = Date.now() - e;
32
- await v(t, "readwrite", async (n) => {
31
+ const t = await D(), s = Date.now() - e;
32
+ await $(t, "readwrite", async (n) => {
33
33
  const r = n.index("lastUsedAt");
34
- (await j(r.getAllKeys(IDBKeyRange.upperBound(s)))).forEach((o) => n.delete(o));
34
+ (await z(r.getAllKeys(IDBKeyRange.upperBound(s)))).forEach((o) => n.delete(o));
35
35
  });
36
36
  }
37
- function U() {
37
+ function D() {
38
38
  return typeof indexedDB > "u" ? Promise.reject(new Error("Product Agent attachment storage is unavailable")) : new Promise((e, t) => {
39
- const s = indexedDB.open(_t, 1);
39
+ const s = indexedDB.open(Ut, 1);
40
40
  s.onupgradeneeded = () => {
41
- const r = s.result.createObjectStore(H, { keyPath: "attachmentId" });
41
+ const r = s.result.createObjectStore(W, { keyPath: "attachmentId" });
42
42
  r.createIndex("lastUsedAt", "lastUsedAt", { unique: !1 }), r.createIndex("sessionId", "sessionId", { unique: !1 }), r.createIndex("origin", "origin", { unique: !1 });
43
43
  }, s.onsuccess = () => e(s.result), s.onerror = () => t(s.error ?? new Error("Failed to open Product Agent attachment storage"));
44
44
  });
45
45
  }
46
- async function at(e, t, s) {
47
- return await v(e, t, async (n) => await j(s(n)));
46
+ async function lt(e, t, s) {
47
+ return await $(e, t, async (n) => await z(s(n)));
48
48
  }
49
- function v(e, t, s) {
49
+ function $(e, t, s) {
50
50
  return new Promise((n, r) => {
51
- const i = e.transaction(H, t), o = i.objectStore(H);
51
+ const i = e.transaction(W, t), o = i.objectStore(W);
52
52
  let c, a = !1;
53
53
  s(o).then((d) => {
54
54
  c = d;
@@ -68,19 +68,20 @@ function v(e, t, s) {
68
68
  };
69
69
  });
70
70
  }
71
- function j(e) {
71
+ function z(e) {
72
72
  return new Promise((t, s) => {
73
73
  e.onsuccess = () => t(e.result), e.onerror = () => s(e.error ?? new Error("Product Agent attachment storage request failed"));
74
74
  });
75
75
  }
76
- const B = '.pluno-pa-widget-host[data-pluno-product-agent-ui="widget"]', bt = '.pluno-pa-widget[data-pluno-product-agent-ui-root="widget"]', Ut = ".pluno-pa-widget__panel", Ct = ".pluno-pa-widget__timeline", X = `${B}[data-pluno-sdk-preview-channel]`, Dt = "https://app.pluno.ai", Nt = "gpt-5.4", qt = 2e4, Ot = 2e3, E = 6e4, Ft = 15e3, K = 2, Ht = 15e3, Bt = 5e3, Lt = 1e3, Wt = 8e3, xt = 15e3, J = 3, vt = [300, 1e3], q = 1e5, jt = 200 * 1024 * 1024, $t = "Image is too large for model vision input.", zt = 100, ct = "pluno.productAgent.state.", L = "pluno.productAgent.pendingEvents.", V = "pluno.productAgent.transportId";
77
- class ut {
76
+ const B = '.pluno-pa-widget-host[data-pluno-product-agent-ui="widget"]', bt = '.pluno-pa-widget[data-pluno-product-agent-ui-root="widget"]', Dt = ".pluno-pa-widget__panel", Nt = ".pluno-pa-widget__timeline", J = `${B}[data-pluno-sdk-preview-channel]`, qt = "https://app.pluno.ai", Ot = "gpt-5.4", Ft = 2e4, Lt = 2e3, E = 6e4, Ht = 15e3, V = 2, Wt = 15e3, Bt = 5e3, vt = 1e3, xt = 8e3, jt = 15e3, Y = 3, $t = [300, 1e3], F = 1e5, zt = 200 * 1024 * 1024, Gt = "Image is too large for model vision input.", Xt = 100, ut = "pluno.productAgent.state.", v = "pluno.productAgent.pendingEvents.", Z = "pluno.productAgent.transportId", Kt = 100, C = /* @__PURE__ */ new Set();
77
+ let R = null;
78
+ class dt {
78
79
  constructor(t) {
79
- this.options = t, this.transportId = de(), this.state = {
80
+ this.options = t, this.transportId = me(), this.state = {
80
81
  ...this.state,
81
- starterPrompts: ie(t.initialStarterPrompts)
82
+ starterPrompts: ue(t.initialStarterPrompts)
82
83
  };
83
- const s = t.restorePersistedState === !1 ? null : qe(t.clientId, t.expectedPersistedSessionId);
84
+ const s = t.restorePersistedState === !1 ? null : We(t.clientId, t.expectedPersistedSessionId);
84
85
  s && (this.state = {
85
86
  ...this.state,
86
87
  ...s,
@@ -91,7 +92,7 @@ class ut {
91
92
  assistantDraftRunId: null,
92
93
  isThinking: !1,
93
94
  lastError: null
94
- }), this.queuedClientEvents = Fe(t.clientId);
95
+ }), this.queuedClientEvents = ve(t.clientId);
95
96
  }
96
97
  options;
97
98
  listeners = {};
@@ -122,6 +123,9 @@ class ut {
122
123
  sessionUserFilesApiCleanup = null;
123
124
  transientStarterPromptsRequestInFlight = !1;
124
125
  transientStarterPromptsRequestAttempted = !1;
126
+ locationChangeCleanup = null;
127
+ starterPromptUrlRefreshTimer = null;
128
+ lastStarterPromptPageUrl = location.href;
125
129
  state = {
126
130
  status: "idle",
127
131
  user: null,
@@ -138,18 +142,18 @@ class ut {
138
142
  lastErrorCode: null
139
143
  };
140
144
  static async init(t) {
141
- const s = new ut({
145
+ const s = new dt({
142
146
  ...t,
143
- backendUrl: Qt(t.backendUrl ?? Dt),
144
- clientId: t.clientId ?? le(),
145
- model: t.model ?? Nt
147
+ backendUrl: se(t.backendUrl ?? qt),
148
+ clientId: t.clientId ?? fe(),
149
+ model: t.model ?? Ot
146
150
  });
147
151
  try {
148
152
  Mt().catch((n) => {
149
153
  g("web-sdk.attachments", "Failed to delete stale Product Agent attachments", {
150
154
  message: n instanceof Error ? n.message : String(n)
151
155
  });
152
- }), s.enableNetworkCapture(), t.autoConnect !== !1 && await s.connect();
156
+ }), s.enableNetworkCapture(), s.startStarterPromptUrlWatcher(), t.autoConnect !== !1 && await s.connect();
153
157
  } catch (n) {
154
158
  throw s.destroy(), n;
155
159
  }
@@ -172,7 +176,7 @@ class ut {
172
176
  return;
173
177
  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)
174
178
  throw new Error("Pluno requires a token or tokenProvider");
175
- const t = te(this.options.backendUrl), s = this.options.webSocketFactory?.(t) ?? new WebSocket(t);
179
+ const t = ne(this.options.backendUrl), s = this.options.webSocketFactory?.(t) ?? new WebSocket(t);
176
180
  this.socket = s, s.addEventListener("open", () => {
177
181
  this.socket === s && (g("web-sdk.agent", "Pluno socket opened", {
178
182
  queuedClientEventCount: this.queuedClientEvents.length,
@@ -181,10 +185,11 @@ class ut {
181
185
  type: "auth.session",
182
186
  token: this.token,
183
187
  clientId: this.options.clientId,
184
- transportId: this.transportId
188
+ transportId: this.transportId,
189
+ pageUrl: location.href
185
190
  }), this.flushQueuedClientEvents(), this.startHeartbeat(), this.setState({ status: "connected", lastError: null }));
186
191
  }), s.addEventListener("message", (n) => {
187
- this.socket === s && this.handleServerEvent(re(n.data));
192
+ this.socket === s && this.handleServerEvent(le(n.data));
188
193
  }), s.addEventListener("close", (n) => {
189
194
  this.socket === s && (this.stopHeartbeat(), this.socket = null, this.state.status !== "closed" && (g("web-sdk.agent", "Pluno socket closed; scheduling reconnect", {
190
195
  code: typeof n?.code == "number" ? n.code : null,
@@ -201,18 +206,18 @@ class ut {
201
206
  });
202
207
  }
203
208
  disconnect() {
204
- this.setState({ status: "closed", isThinking: !1 }), this.stopHeartbeat(), this.clearRetryTimers(), this.clearThinkingWatchdog(), this.rejectPendingSessionHistoryRequests("Pluno disconnected."), this.reconnectTimer !== null && (window.clearTimeout(this.reconnectTimer), this.reconnectTimer = null), this.queuedClientEvents = [], this.socket?.close(), this.socket = null;
209
+ this.setState({ status: "closed", isThinking: !1 }), this.stopHeartbeat(), this.clearStarterPromptUrlRefreshTimer(), this.clearRetryTimers(), this.clearThinkingWatchdog(), this.rejectPendingSessionHistoryRequests("Pluno disconnected."), this.reconnectTimer !== null && (window.clearTimeout(this.reconnectTimer), this.reconnectTimer = null), this.queuedClientEvents = [], this.socket?.close(), this.socket = null;
205
210
  }
206
211
  destroy() {
207
- this.disconnect(), this.cleanupSessionUserFilesApi(), this.networkCaptureCleanup?.(), this.networkCaptureCleanup = null;
212
+ this.disconnect(), this.locationChangeCleanup?.(), this.locationChangeCleanup = null, this.cleanupSessionUserFilesApi(), this.networkCaptureCleanup?.(), this.networkCaptureCleanup = null;
208
213
  for (const t of Object.values(this.listeners))
209
214
  t?.clear();
210
215
  }
211
216
  sendMessage(t, s = {}) {
212
- const n = t.trim(), r = s.attachments ?? [], i = r.map($);
217
+ const n = t.trim(), r = s.attachments ?? [], i = r.map(G);
213
218
  if (!n && i.length === 0)
214
219
  return null;
215
- const o = y(), c = R(), a = {
220
+ const o = y(), c = _(), a = {
216
221
  id: `local-${c}`,
217
222
  role: "user",
218
223
  content: n,
@@ -237,20 +242,20 @@ class ut {
237
242
  attachments: i.length > 0 ? i : void 0,
238
243
  page: o,
239
244
  model: this.options.model,
240
- metadata: Y(this.options.metadata)
245
+ metadata: Q(this.options.metadata)
241
246
  };
242
247
  return this.activeClientMessageId = c, this.activeUserMessageEvent = d, this.markThinkingProgress(), this.send(d), this.startBackgroundAttachmentUploads(c, i), c;
243
248
  }
244
249
  createLocalAttachment(t) {
245
- const s = R(), n = {
250
+ const s = _(), n = {
246
251
  id: s,
247
252
  name: t.name || "attachment",
248
- mimeType: nt(t),
253
+ mimeType: it(t),
249
254
  sizeBytes: t.size
250
255
  };
251
256
  this.attachmentFiles.set(s, t), this.attachmentBlobCache.set(s, t);
252
257
  const r = Date.now();
253
- return it({
258
+ return at({
254
259
  attachmentId: s,
255
260
  name: n.name,
256
261
  mimeType: n.mimeType,
@@ -273,7 +278,7 @@ class ut {
273
278
  return await this.uploadAttachmentForMessage({
274
279
  file: t,
275
280
  attachment: s,
276
- clientMessageId: R(),
281
+ clientMessageId: _(),
277
282
  waitForSession: !1,
278
283
  notifyCompletion: !1
279
284
  });
@@ -305,7 +310,7 @@ class ut {
305
310
  waitForSession: r,
306
311
  notifyCompletion: i
307
312
  }) {
308
- const o = r ? await this.waitForSessionId() : this.state.sessionId, c = nt(t), a = {
313
+ const o = r ? await this.waitForSessionId() : this.state.sessionId, c = it(t), a = {
309
314
  sessionId: o ?? void 0,
310
315
  attachmentId: s.id,
311
316
  clientId: this.options.clientId,
@@ -315,32 +320,32 @@ class ut {
315
320
  sizeBytes: t.size,
316
321
  page: y(),
317
322
  model: this.options.model,
318
- metadata: Y(this.options.metadata)
319
- }, d = this.options.prepareAttachmentUpload ? await F(
323
+ metadata: Q(this.options.metadata)
324
+ }, d = this.options.prepareAttachmentUpload ? await H(
320
325
  () => this.options.prepareAttachmentUpload(a),
321
326
  "Failed to prepare attachment upload"
322
327
  ) : await this.prepareEmbedAttachmentUpload(a);
323
- await F(async () => {
324
- const u = await fetch(d.uploadUrl, {
328
+ await H(async () => {
329
+ const l = await fetch(d.uploadUrl, {
325
330
  method: d.uploadMethod,
326
331
  headers: d.uploadHeaders,
327
332
  body: t
328
333
  });
329
- if (!u.ok)
330
- throw new M("Failed to upload attachment", u.status);
331
- return u;
334
+ if (!l.ok)
335
+ throw new M("Failed to upload attachment", l.status);
336
+ return l;
332
337
  }, "Failed to upload attachment"), this.setState({ sessionId: d.sessionId });
333
- const h = wt(d.attachment, this.options.backendUrl);
334
- return this.updateAttachmentInState(s.id, h), s.id && ot(s.id, {
338
+ const h = At(d.attachment, this.options.backendUrl);
339
+ return this.updateAttachmentInState(s.id, h), s.id && ct(s.id, {
335
340
  sessionId: d.sessionId,
336
341
  fileUrl: h.fileUrl,
337
342
  gcsPath: h.gcsPath,
338
343
  lastUsedAt: Date.now()
339
- }).catch((u) => {
344
+ }).catch((l) => {
340
345
  g("web-sdk.attachments", "Failed to update persisted Product Agent attachment", {
341
346
  attachmentId: s.id,
342
347
  name: h.name,
343
- message: u instanceof Error ? u.message : String(u)
348
+ message: l instanceof Error ? l.message : String(l)
344
349
  });
345
350
  }), i && h.gcsPath && this.send({
346
351
  type: "attachment.upload_completed",
@@ -353,7 +358,7 @@ class ut {
353
358
  return this.state.sessionId ? Promise.resolve(this.state.sessionId) : new Promise((t, s) => {
354
359
  const n = window.setTimeout(() => {
355
360
  r(), s(new Error("Timed out waiting for Pluno session before persisting attachment"));
356
- }, xt), r = this.on("state", (i) => {
361
+ }, jt), r = this.on("state", (i) => {
357
362
  i.sessionId && (window.clearTimeout(n), r(), t(i.sessionId));
358
363
  });
359
364
  });
@@ -371,11 +376,11 @@ class ut {
371
376
  }
372
377
  async prepareEmbedAttachmentUpload(t) {
373
378
  let s = !1;
374
- return await F(async () => {
379
+ return await H(async () => {
375
380
  const n = await this.fetchEmbedAttachmentUpload(t);
376
381
  if (n.ok)
377
382
  return await n.json();
378
- if (Ve(n.status) && this.options.tokenProvider && !s) {
383
+ if (es(n.status) && this.options.tokenProvider && !s) {
379
384
  s = !0;
380
385
  const r = await this.fetchEmbedAttachmentUpload(t);
381
386
  if (r.ok)
@@ -416,10 +421,10 @@ class ut {
416
421
  });
417
422
  }
418
423
  listSessions(t = {}) {
419
- const s = R(), n = new Promise((i, o) => {
424
+ const s = _(), n = new Promise((i, o) => {
420
425
  const c = window.setTimeout(() => {
421
426
  this.pendingSessionHistoryRequests.delete(s), o(new Error("Session history did not respond in time"));
422
- }, Wt);
427
+ }, xt);
423
428
  this.pendingSessionHistoryRequests.set(s, { resolve: i, reject: o, timeout: c });
424
429
  }), r = {
425
430
  type: "sessions.list",
@@ -450,7 +455,7 @@ class ut {
450
455
  });
451
456
  }
452
457
  send(t) {
453
- this.sendNow(w(t)) || (this.queuedClientEvents.push(t), _(this.options.clientId, this.queuedClientEvents), this.setState({ status: "reconnecting" }), this.scheduleReconnect());
458
+ this.sendNow(T(t)) || (this.queuedClientEvents.push(t), P(this.options.clientId, this.queuedClientEvents), this.setState({ status: "reconnecting" }), this.scheduleReconnect());
454
459
  }
455
460
  async getUploadToken() {
456
461
  const t = this.options.token ?? await this.options.tokenProvider?.() ?? this.token ?? null;
@@ -476,9 +481,9 @@ class ut {
476
481
  if (this.state.starterPromptsLoading || this.transientStarterPromptsRequestInFlight || this.transientStarterPromptsRequestAttempted)
477
482
  return;
478
483
  this.transientStarterPromptsRequestInFlight = !0, this.transientStarterPromptsRequestAttempted = !0, this.setState({ starterPromptsLoading: !0 });
479
- const t = ee();
484
+ const t = re();
480
485
  this.sendNow(
481
- w({
486
+ T({
482
487
  type: "starter_prompts.page_context",
483
488
  pageUrl: t.pageUrl,
484
489
  pageTitle: t.pageTitle,
@@ -486,18 +491,36 @@ class ut {
486
491
  })
487
492
  ) || (this.transientStarterPromptsRequestInFlight = !1, this.transientStarterPromptsRequestAttempted = !1, this.setState({ starterPromptsLoading: !1 }));
488
493
  }
494
+ startStarterPromptUrlWatcher() {
495
+ this.locationChangeCleanup || (this.locationChangeCleanup = ie(() => this.handleStarterPromptUrlChange()));
496
+ }
497
+ handleStarterPromptUrlChange() {
498
+ const t = location.href;
499
+ t !== this.lastStarterPromptPageUrl && (this.lastStarterPromptPageUrl = t, this.clearStarterPromptUrlRefreshTimer(), this.starterPromptUrlRefreshTimer = window.setTimeout(() => {
500
+ this.starterPromptUrlRefreshTimer = null, this.refreshStarterPromptsForCurrentUrl();
501
+ }, Kt));
502
+ }
503
+ refreshStarterPromptsForCurrentUrl() {
504
+ this.socket?.readyState !== WebSocket.OPEN || this.state.status === "closed" || (this.setState({ starterPromptsLoading: this.state.messages.length === 0 }), this.sendNow({
505
+ type: "starter_prompts.page_url",
506
+ pageUrl: location.href
507
+ }));
508
+ }
509
+ clearStarterPromptUrlRefreshTimer() {
510
+ this.starterPromptUrlRefreshTimer !== null && (window.clearTimeout(this.starterPromptUrlRefreshTimer), this.starterPromptUrlRefreshTimer = null);
511
+ }
489
512
  flushQueuedClientEvents() {
490
513
  if (this.socket?.readyState !== WebSocket.OPEN || this.queuedClientEvents.length === 0)
491
514
  return;
492
515
  const t = this.queuedClientEvents.splice(0, this.queuedClientEvents.length);
493
- _(this.options.clientId, this.queuedClientEvents);
516
+ P(this.options.clientId, this.queuedClientEvents);
494
517
  for (let s = 0; s < t.length; s += 1) {
495
518
  const n = t[s];
496
- if (!this.sendNow(w(n))) {
497
- this.queuedClientEvents.unshift(n, ...t.slice(s + 1)), _(this.options.clientId, this.queuedClientEvents);
519
+ if (!this.sendNow(T(n))) {
520
+ this.queuedClientEvents.unshift(n, ...t.slice(s + 1)), P(this.options.clientId, this.queuedClientEvents);
498
521
  return;
499
522
  }
500
- _(this.options.clientId, this.queuedClientEvents);
523
+ P(this.options.clientId, this.queuedClientEvents);
501
524
  }
502
525
  }
503
526
  handleServerEvent(t) {
@@ -505,18 +528,18 @@ class ut {
505
528
  this.handleRunAck(t);
506
529
  return;
507
530
  }
508
- if (Gt(t) && this.markThinkingProgress(), t.type === "auth.ok") {
509
- const s = oe(t), n = Object.prototype.hasOwnProperty.call(t, "appearance");
531
+ if (Jt(t) && this.markThinkingProgress(), t.type === "auth.ok") {
532
+ const s = de(t), n = Object.prototype.hasOwnProperty.call(t, "appearance");
510
533
  g("web-sdk.agent", "Received auth.ok appearance", {
511
534
  hasAppearance: n,
512
535
  rawAppearance: t.appearance,
513
536
  normalizedAppearance: s
514
- }), this.runtimeHelperJavascript = ae(t.runtimeHelpers)?.javascript ?? null;
515
- const r = tt(t, "starterPrompts"), i = Object.prototype.hasOwnProperty.call(t, "starterPrompts"), o = t.starterPromptsLoading === !0, c = {
516
- user: he(t.user),
537
+ }), this.runtimeHelperJavascript = he(t.runtimeHelpers)?.javascript ?? null;
538
+ const r = st(t, "starterPrompts"), i = Object.prototype.hasOwnProperty.call(t, "starterPrompts"), o = t.starterPromptsLoading === !0, c = {
539
+ user: ye(t.user),
517
540
  status: "connected"
518
541
  };
519
- (i || this.state.starterPrompts.length === 0) && (c.starterPrompts = r, c.starterPromptsLoading = r.length > 0 ? !1 : o), i && r.length > 0 && (this.transientStarterPromptsRequestInFlight = !1, this.transientStarterPromptsRequestAttempted = !0), (n || s) && (c.appearance = s), this.setState(c), i && r.length === 0 && !o && !se() && this.requestTransientStarterPrompts(), this.state.sessionId && this.send({
542
+ (i || this.state.starterPrompts.length === 0) && (c.starterPrompts = r, c.starterPromptsLoading = r.length > 0 ? !1 : o), i && r.length > 0 && (this.transientStarterPromptsRequestInFlight = !1, this.transientStarterPromptsRequestAttempted = !0), (n || s) && (c.appearance = s), this.setState(c), i && r.length === 0 && !o && !ae() && this.requestTransientStarterPrompts(), this.state.sessionId && this.send({
520
543
  type: "page.upsert",
521
544
  sessionId: this.state.sessionId,
522
545
  page: y(),
@@ -526,20 +549,20 @@ class ut {
526
549
  }
527
550
  if (t.type === "starterPrompts.updated") {
528
551
  this.transientStarterPromptsRequestInFlight = !1, this.transientStarterPromptsRequestAttempted = !0, this.setState({
529
- starterPrompts: tt(t, "starterPrompts"),
552
+ starterPrompts: st(t, "starterPrompts"),
530
553
  starterPromptsLoading: !1
531
554
  });
532
555
  return;
533
556
  }
534
557
  if (t.type === "conversation.state") {
535
- const s = Array.isArray(t.items) ? t.items : [], n = Ae(
558
+ const s = Array.isArray(t.items) ? t.items : [], n = _e(
536
559
  this.state.messages,
537
- pe(s, this.options.backendUrl)
538
- ), r = et(n);
539
- if (!r && _e(this.state.messages, s))
560
+ we(s, this.options.backendUrl)
561
+ ), r = nt(n);
562
+ if (!r && be(this.state.messages, s))
540
563
  return;
541
- const i = r ? null : Pe(s);
542
- this.latestRecoverableClientMessageId = i, Re(n) && this.clearRetryTimers(), this.setState({
564
+ const i = r ? null : De(s);
565
+ this.latestRecoverableClientMessageId = i, Me(n) && this.clearRetryTimers(), this.setState({
543
566
  sessionId: I(t.session, "id") ?? this.state.sessionId,
544
567
  messages: n,
545
568
  ...r ? { assistantDraft: "", assistantDraftRespondsToUserMessageId: null, assistantDraftRunId: null, isThinking: !1 } : i ? {
@@ -555,7 +578,7 @@ class ut {
555
578
  if (t.type === "sessions.page") {
556
579
  const s = typeof t.requestId == "string" ? t.requestId : null, n = s ? this.pendingSessionHistoryRequests.get(s) : null;
557
580
  s && n && (window.clearTimeout(n.timeout), this.pendingSessionHistoryRequests.delete(s), n.resolve({
558
- sessions: ge(t.sessions),
581
+ sessions: Te(t.sessions),
559
582
  nextCursor: typeof t.nextCursor == "string" ? t.nextCursor : null
560
583
  }));
561
584
  return;
@@ -565,12 +588,12 @@ class ut {
565
588
  return;
566
589
  }
567
590
  if (t.type === "session.item") {
568
- const s = dt(t.item, this.options.backendUrl);
591
+ const s = pt(t.item, this.options.backendUrl);
569
592
  if (s) {
570
593
  s.role === "assistant" && (this.clearRetryTimers(), this.clearRunAckResyncRetryTimer());
571
594
  const n = t.item.data;
572
- Me(n) && this.clearRunAckResyncRetryTimer();
573
- const r = Ie(this.state.messages, s), i = et(r);
595
+ Ne(n) && this.clearRunAckResyncRetryTimer();
596
+ const r = Re(this.state.messages, s), i = nt(r);
574
597
  this.setState({
575
598
  messages: r,
576
599
  assistantDraft: s.role === "assistant" ? "" : this.state.assistantDraft,
@@ -669,7 +692,7 @@ class ut {
669
692
  scheduleRunAckWatchdog(t) {
670
693
  this.runAckWatchdogTimer !== null && window.clearTimeout(this.runAckWatchdogTimer), this.runAckWatchdogTimer = window.setTimeout(() => {
671
694
  this.runAckWatchdogTimer = null, this.recoverMissedRunAck(t);
672
- }, Ht);
695
+ }, Wt);
673
696
  }
674
697
  recoverMissedRunAck(t) {
675
698
  !this.state.isThinking || this.state.status === "closed" || this.activeClientMessageId !== t || (g("web-sdk.agent", "Pluno run ack missed; resyncing session", {
@@ -679,7 +702,7 @@ class ut {
679
702
  }
680
703
  scheduleRunAckResyncRetry(t) {
681
704
  this.clearRunAckResyncRetryTimer(), this.runAckResyncRetryTimer = window.setTimeout(() => {
682
- this.runAckResyncRetryTimer = null, !((this.runAckRecoveryRetryAttemptsByClientMessageId[t] ?? 0) >= 1) && (!this.state.isThinking || this.state.status === "closed" || this.activeClientMessageId !== t || this.latestRecoverableClientMessageId !== t || (this.runAckRecoveryRetryAttemptsByClientMessageId[t] = 1, this.thinkingWatchdogRetryAttemptsByClientMessageId[t] = K, this.setState({
705
+ this.runAckResyncRetryTimer = null, !((this.runAckRecoveryRetryAttemptsByClientMessageId[t] ?? 0) >= 1) && (!this.state.isThinking || this.state.status === "closed" || this.activeClientMessageId !== t || this.latestRecoverableClientMessageId !== t || (this.runAckRecoveryRetryAttemptsByClientMessageId[t] = 1, this.thinkingWatchdogRetryAttemptsByClientMessageId[t] = V, this.setState({
683
706
  status: this.state.status === "reconnecting" ? "reconnecting" : "connected",
684
707
  isThinking: !0,
685
708
  lastError: null
@@ -715,10 +738,10 @@ class ut {
715
738
  sessionId: this.state.sessionId,
716
739
  clientMessageId: t,
717
740
  resyncAttempts: s + 1
718
- }), this.resyncThinkingSession(), this.scheduleThinkingWatchdog(Ft);
741
+ }), this.resyncThinkingSession(), this.scheduleThinkingWatchdog(Ht);
719
742
  return;
720
743
  }
721
- if (n >= K) {
744
+ if (n >= V) {
722
745
  g("web-sdk.agent", "Pluno thinking watchdog retry limit reached; continuing resync", {
723
746
  sessionId: this.state.sessionId,
724
747
  clientMessageId: t,
@@ -752,15 +775,15 @@ class ut {
752
775
  const s = typeof t.sessionId == "string" ? t.sessionId : null, n = typeof t.callId == "string" ? t.callId : null, r = typeof t.toolName == "string" ? t.toolName : null, i = typeof t.summary == "string" ? t.summary : "Running browser tool", o = t.rawInput;
753
776
  if (!s || !n || !r)
754
777
  return;
755
- if (r !== "execute_code" || !ve(o)) {
778
+ if (r !== "execute_code" || !Xe(o)) {
756
779
  this.send({
757
780
  type: "tool.result",
758
781
  sessionId: s,
759
782
  callId: n,
760
783
  toolName: r,
761
784
  summary: i,
762
- rawInput: w(o),
763
- rawOutput: w({
785
+ rawInput: T(o),
786
+ rawOutput: T({
764
787
  ok: !1,
765
788
  toolName: r,
766
789
  error: `Unsupported browser tool: ${r}`
@@ -768,10 +791,10 @@ class ut {
768
791
  });
769
792
  return;
770
793
  }
771
- const c = Kt(this.state.messages);
794
+ const c = Yt(this.state.messages);
772
795
  this.installSessionUserFilesApi(c);
773
796
  let a = null, d;
774
- a = await this.executeRuntimeHelper(), d = await Q(o).catch((h) => ({
797
+ a = await this.executeRuntimeHelper(), d = await et(o).catch((h) => ({
775
798
  ok: !1,
776
799
  exception: {
777
800
  message: h instanceof Error ? h.message : String(h)
@@ -782,51 +805,51 @@ class ut {
782
805
  callId: n,
783
806
  toolName: r,
784
807
  summary: o.summary,
785
- rawInput: w(o),
786
- rawOutput: w(ce(d, a))
808
+ rawInput: T(o),
809
+ rawOutput: T(pe(d, a))
787
810
  });
788
811
  }
789
812
  installSessionUserFilesApi(t) {
790
- this.cleanupSessionUserFilesApi(), this.sessionUserFilesApiCleanup = Jt(t, this.attachmentFiles, this.attachmentBlobCache);
813
+ this.cleanupSessionUserFilesApi(), this.sessionUserFilesApiCleanup = Zt(t, this.attachmentFiles, this.attachmentBlobCache);
791
814
  }
792
815
  cleanupSessionUserFilesApi() {
793
- this.sessionUserFilesApiCleanup && (Vt(this.sessionUserFilesApiCleanup), this.sessionUserFilesApiCleanup = null);
816
+ this.sessionUserFilesApiCleanup && (Qt(this.sessionUserFilesApiCleanup), this.sessionUserFilesApiCleanup = null);
794
817
  }
795
818
  async executeRuntimeHelper() {
796
819
  if (!this.runtimeHelperJavascript?.trim())
797
820
  return null;
798
- const t = await Q({
821
+ const t = await et({
799
822
  javascript: this.runtimeHelperJavascript
800
823
  });
801
- return t.ok === !1 ? ue(t) : null;
824
+ return t.ok === !1 ? ge(t) : null;
802
825
  }
803
826
  enableNetworkCapture() {
804
827
  if (this.networkCaptureCleanup)
805
828
  return;
806
829
  const t = window.fetch.bind(window), s = XMLHttpRequest.prototype.open, n = XMLHttpRequest.prototype.setRequestHeader, r = XMLHttpRequest.prototype.send;
807
830
  window.fetch = async (i, o) => {
808
- const c = Date.now(), a = new Date(c).toISOString(), d = i instanceof Request ? i : null, h = typeof i == "string" ? i : i instanceof URL ? i.toString() : d?.url ?? "", u = (o?.method ?? d?.method ?? "GET").toUpperCase(), l = rt(new Headers(o?.headers ?? d?.headers ?? void 0)), f = await je(d, o);
831
+ const c = Date.now(), a = new Date(c).toISOString(), d = i instanceof Request ? i : null, h = typeof i == "string" ? i : i instanceof URL ? i.toString() : d?.url ?? "", l = (o?.method ?? d?.method ?? "GET").toUpperCase(), u = ot(new Headers(o?.headers ?? d?.headers ?? void 0)), f = await Ke(d, o);
809
832
  try {
810
833
  const p = await t(i, o);
811
834
  return this.enqueueNetworkEvent({
812
- requestId: P("fetch"),
835
+ requestId: U("fetch"),
813
836
  url: h,
814
- method: u,
815
- requestHeaders: l,
837
+ method: l,
838
+ requestHeaders: u,
816
839
  requestBody: f,
817
840
  resourceType: "fetch",
818
841
  responseStatus: p.status,
819
- responseHeaders: rt(p.headers),
820
- responseBody: await $e(p),
842
+ responseHeaders: ot(p.headers),
843
+ responseBody: await Je(p),
821
844
  startedAt: a,
822
845
  durationMs: Date.now() - c
823
846
  }), p;
824
847
  } catch (p) {
825
848
  throw this.enqueueNetworkEvent({
826
- requestId: P("fetch"),
849
+ requestId: U("fetch"),
827
850
  url: h,
828
- method: u,
829
- requestHeaders: l,
851
+ method: l,
852
+ requestHeaders: u,
830
853
  requestBody: f,
831
854
  resourceType: "fetch",
832
855
  errorText: p instanceof Error ? p.message : String(p),
@@ -836,7 +859,7 @@ class ut {
836
859
  }
837
860
  }, XMLHttpRequest.prototype.open = function(o, c, a, d, h) {
838
861
  return this.__plunoMeta = {
839
- requestId: P("xhr"),
862
+ requestId: U("xhr"),
840
863
  method: String(o ?? "GET").toUpperCase(),
841
864
  url: typeof c == "string" ? c : c.toString(),
842
865
  requestHeaders: {},
@@ -852,14 +875,14 @@ class ut {
852
875
  return n.call(this, o, c);
853
876
  }, XMLHttpRequest.prototype.send = function(o) {
854
877
  const c = window.__plunoProductAgentInstance, a = this.__plunoMeta ?? {
855
- requestId: P("xhr"),
878
+ requestId: U("xhr"),
856
879
  method: "GET",
857
880
  url: "",
858
881
  requestHeaders: {},
859
882
  startedAtMs: Date.now(),
860
883
  startedAt: (/* @__PURE__ */ new Date()).toISOString()
861
884
  };
862
- return a.requestBody = It(o), this.__plunoMeta = a, this.addEventListener(
885
+ return a.requestBody = St(o), this.__plunoMeta = a, this.addEventListener(
863
886
  "loadend",
864
887
  function() {
865
888
  !c || !this.__plunoMeta || c.enqueueNetworkEvent({
@@ -870,8 +893,8 @@ class ut {
870
893
  requestBody: typeof this.__plunoMeta.requestBody == "string" ? this.__plunoMeta.requestBody : void 0,
871
894
  resourceType: "xhr",
872
895
  responseStatus: this.status,
873
- responseHeaders: Ge(this.getAllResponseHeaders()),
874
- responseBody: ze(this),
896
+ responseHeaders: Ye(this.getAllResponseHeaders()),
897
+ responseBody: Ve(this),
875
898
  errorText: this.status === 0 ? "XHR request failed or was aborted" : void 0,
876
899
  startedAt: String(this.__plunoMeta.startedAt),
877
900
  durationMs: Date.now() - Number(this.__plunoMeta.startedAtMs ?? Date.now())
@@ -884,7 +907,7 @@ class ut {
884
907
  };
885
908
  }
886
909
  enqueueNetworkEvent(t) {
887
- this.queuedNetworkEvents.push(w(t)), this.networkBatchTimer === null && (this.networkBatchTimer = window.setTimeout(() => {
910
+ this.queuedNetworkEvents.push(T(t)), this.networkBatchTimer === null && (this.networkBatchTimer = window.setTimeout(() => {
888
911
  this.networkBatchTimer = null;
889
912
  const s = this.queuedNetworkEvents.splice(0, this.queuedNetworkEvents.length);
890
913
  s.length === 0 || this.socket?.readyState !== WebSocket.OPEN || this.sendNow({
@@ -893,7 +916,7 @@ class ut {
893
916
  page: y(),
894
917
  events: s
895
918
  });
896
- }, Lt));
919
+ }, vt));
897
920
  }
898
921
  scheduleReconnect() {
899
922
  this.reconnectTimer !== null || this.state.status === "closed" || (this.reconnectTimer = window.setTimeout(() => {
@@ -904,12 +927,12 @@ class ut {
904
927
  isThinking: this.state.isThinking
905
928
  }), this.setState({ status: "reconnecting", lastError: null }), this.scheduleReconnect();
906
929
  });
907
- }, Ot));
930
+ }, Lt));
908
931
  }
909
932
  startHeartbeat() {
910
933
  this.stopHeartbeat(), this.heartbeatTimer = window.setInterval(() => {
911
934
  this.sendNow({ type: "runtime.ping" });
912
- }, qt);
935
+ }, Ft);
913
936
  }
914
937
  stopHeartbeat() {
915
938
  this.heartbeatTimer !== null && (window.clearInterval(this.heartbeatTimer), this.heartbeatTimer = null);
@@ -919,7 +942,7 @@ class ut {
919
942
  ...this.state,
920
943
  ...t,
921
944
  ...t.lastError === null && t.lastErrorCode === void 0 ? { lastErrorCode: null } : {}
922
- }, Oe(this.options.clientId, this.state), this.emit("state", this.getState());
945
+ }, Be(this.options.clientId, this.state), this.emit("state", this.getState());
923
946
  }
924
947
  emit(t, s) {
925
948
  this.listeners[t]?.forEach((r) => r(s));
@@ -936,15 +959,15 @@ function g(e, t, s) {
936
959
  }, i = n.__plunoProductAgentDiagnostics__ ?? [];
937
960
  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 }));
938
961
  }
939
- function Y(e) {
962
+ function Q(e) {
940
963
  const t = typeof e == "function" ? e() : e;
941
964
  return t && Object.keys(t).length > 0 ? t : void 0;
942
965
  }
943
- function Gt(e) {
966
+ function Jt(e) {
944
967
  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";
945
968
  }
946
- const Xt = 5e3;
947
- function Kt(e) {
969
+ const Vt = 5e3;
970
+ function Yt(e) {
948
971
  const t = [];
949
972
  for (const s of e)
950
973
  s.role !== "user" || !s.attachments?.length || s.attachments.forEach((n, r) => {
@@ -955,118 +978,118 @@ function Kt(e) {
955
978
  });
956
979
  return t;
957
980
  }
958
- function Jt(e, t = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map()) {
959
- const n = new Map(e.map((u) => [u.id, u])), r = (u) => ({
960
- id: u.id,
961
- name: u.name,
962
- mimeType: u.mimeType,
963
- sizeBytes: u.sizeBytes,
964
- type: u.mimeType,
965
- size: u.sizeBytes
966
- }), i = (u) => {
967
- const l = n.get(u);
968
- if (!l)
969
- throw new Error(`Unknown Pluno user file: ${u}`);
970
- return l;
971
- }, o = async (u) => {
972
- const l = i(u), f = t.get(l.id);
981
+ function Zt(e, t = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map()) {
982
+ const n = new Map(e.map((l) => [l.id, l])), r = (l) => ({
983
+ id: l.id,
984
+ name: l.name,
985
+ mimeType: l.mimeType,
986
+ sizeBytes: l.sizeBytes,
987
+ type: l.mimeType,
988
+ size: l.sizeBytes
989
+ }), i = (l) => {
990
+ const u = n.get(l);
991
+ if (!u)
992
+ throw new Error(`Unknown Pluno user file: ${l}`);
993
+ return u;
994
+ }, o = async (l) => {
995
+ const u = i(l), f = t.get(u.id);
973
996
  if (f)
974
997
  return f;
975
- const p = s.get(l.id);
998
+ const p = s.get(u.id);
976
999
  if (p)
977
1000
  return p;
978
- const S = await Pt(l.id).then((m) => m?.blob ?? null).catch((m) => (g("web-sdk.attachments", "Failed to load Product Agent attachment from IndexedDB", {
979
- attachmentId: l.id,
980
- name: l.name,
1001
+ const S = await Ct(u.id).then((m) => m?.blob ?? null).catch((m) => (g("web-sdk.attachments", "Failed to load Product Agent attachment from IndexedDB", {
1002
+ attachmentId: u.id,
1003
+ name: u.name,
981
1004
  message: m instanceof Error ? m.message : String(m)
982
1005
  }), null));
983
1006
  if (S)
984
- return s.set(l.id, S), S;
985
- if (!l.fileUrl)
986
- throw new Error(`Pluno user file is missing content: ${u}`);
987
- const D = await fetch(l.fileUrl, He(l.fileUrl));
988
- if (!D.ok)
989
- throw new Error(`Failed to load Pluno user file: ${u}`);
990
- const N = await D.blob();
991
- s.set(l.id, N);
992
- const G = Date.now();
993
- return it({
994
- attachmentId: l.id,
995
- name: l.name,
996
- mimeType: l.mimeType,
997
- sizeBytes: l.sizeBytes,
998
- blob: N,
999
- fileUrl: l.fileUrl,
1000
- gcsPath: l.gcsPath,
1001
- createdAt: G,
1002
- lastUsedAt: G
1007
+ return s.set(u.id, S), S;
1008
+ if (!u.fileUrl)
1009
+ throw new Error(`Pluno user file is missing content: ${l}`);
1010
+ const q = await fetch(u.fileUrl, xe(u.fileUrl));
1011
+ if (!q.ok)
1012
+ throw new Error(`Failed to load Pluno user file: ${l}`);
1013
+ const O = await q.blob();
1014
+ s.set(u.id, O);
1015
+ const K = Date.now();
1016
+ return at({
1017
+ attachmentId: u.id,
1018
+ name: u.name,
1019
+ mimeType: u.mimeType,
1020
+ sizeBytes: u.sizeBytes,
1021
+ blob: O,
1022
+ fileUrl: u.fileUrl,
1023
+ gcsPath: u.gcsPath,
1024
+ createdAt: K,
1025
+ lastUsedAt: K
1003
1026
  }).catch((m) => {
1004
1027
  g("web-sdk.attachments", "Failed to cache Product Agent attachment from fileUrl", {
1005
- attachmentId: l.id,
1006
- name: l.name,
1028
+ attachmentId: u.id,
1029
+ name: u.name,
1007
1030
  message: m instanceof Error ? m.message : String(m)
1008
1031
  });
1009
- }), N;
1010
- }, c = async (u) => {
1011
- const l = i(u), f = await o(u), p = l.mimeType.startsWith("image/") ? l.mimeType : f.type || l.mimeType;
1032
+ }), O;
1033
+ }, c = async (l) => {
1034
+ const u = i(l), f = await o(l), p = u.mimeType.startsWith("image/") ? u.mimeType : f.type || u.mimeType;
1012
1035
  if (!p.startsWith("image/"))
1013
- throw new Error(`Pluno user file is not an image: ${u}`);
1036
+ throw new Error(`Pluno user file is not an image: ${l}`);
1014
1037
  const S = f.type === p ? f : new Blob([f], { type: p });
1015
- return Yt(p, S.size) > jt ? {
1038
+ return te(p, S.size) > zt ? {
1016
1039
  type: "pluno.userFiles.inspectImage",
1017
- id: l.id,
1018
- name: l.name,
1040
+ id: u.id,
1041
+ name: u.name,
1019
1042
  mimeType: p,
1020
- sizeBytes: l.sizeBytes,
1043
+ sizeBytes: u.sizeBytes,
1021
1044
  imageAttached: !1,
1022
- imageAttachmentError: $t
1045
+ imageAttachmentError: Gt
1023
1046
  } : {
1024
1047
  type: "pluno.userFiles.inspectImage",
1025
- id: l.id,
1026
- name: l.name,
1048
+ id: u.id,
1049
+ name: u.name,
1027
1050
  mimeType: p,
1028
- sizeBytes: l.sizeBytes,
1051
+ sizeBytes: u.sizeBytes,
1029
1052
  imageAttached: !0,
1030
- dataUrl: await Z(S)
1053
+ dataUrl: await tt(S)
1031
1054
  };
1032
1055
  }, a = globalThis, d = a.pluno?.userFiles, h = Object.prototype.hasOwnProperty.call(a.pluno ?? {}, "userFiles");
1033
1056
  return a.pluno = {
1034
1057
  ...a.pluno ?? {},
1035
1058
  userFiles: {
1036
1059
  list: () => e.map(r),
1037
- get: (u) => {
1038
- const l = n.get(u);
1039
- return l ? r(l) : null;
1060
+ get: (l) => {
1061
+ const u = n.get(l);
1062
+ return u ? r(u) : null;
1040
1063
  },
1041
1064
  inspectImage: c,
1042
- getDataUrl: async (u) => (i(u), await Z(await o(u))),
1065
+ getDataUrl: async (l) => (i(l), await tt(await o(l))),
1043
1066
  getBlob: o,
1044
- getArrayBuffer: async (u) => await (await o(u)).arrayBuffer(),
1045
- getFile: async (u) => {
1046
- const l = i(u);
1047
- return new File([await o(u)], l.name, { type: l.mimeType });
1067
+ getArrayBuffer: async (l) => await (await o(l)).arrayBuffer(),
1068
+ getFile: async (l) => {
1069
+ const u = i(l);
1070
+ return new File([await o(l)], u.name, { type: u.mimeType });
1048
1071
  }
1049
1072
  }
1050
1073
  }, () => {
1051
- const u = a.pluno ?? {};
1074
+ const l = a.pluno ?? {};
1052
1075
  if (h) {
1053
1076
  a.pluno = {
1054
- ...u,
1077
+ ...l,
1055
1078
  userFiles: d
1056
1079
  };
1057
1080
  return;
1058
1081
  }
1059
- const { userFiles: l, ...f } = u;
1082
+ const { userFiles: u, ...f } = l;
1060
1083
  a.pluno = f;
1061
1084
  };
1062
1085
  }
1063
- function Vt(e) {
1086
+ function Qt(e) {
1064
1087
  try {
1065
1088
  e();
1066
1089
  } catch {
1067
1090
  }
1068
1091
  }
1069
- function Z(e) {
1092
+ function tt(e) {
1070
1093
  return new Promise((t, s) => {
1071
1094
  const n = new FileReader();
1072
1095
  n.onload = () => {
@@ -1078,12 +1101,12 @@ function Z(e) {
1078
1101
  }, n.onerror = () => s(n.error ?? new Error("Failed to read Pluno user file")), n.readAsDataURL(e);
1079
1102
  });
1080
1103
  }
1081
- function Yt(e, t) {
1104
+ function te(e, t) {
1082
1105
  return `data:${e};base64,`.length + Math.ceil(t / 3) * 4;
1083
1106
  }
1084
- async function Q(e) {
1107
+ async function et(e) {
1085
1108
  const t = Object.getPrototypeOf(async function() {
1086
- }).constructor, s = e.timeoutMs ?? Xt, n = Date.now(), r = [];
1109
+ }).constructor, s = e.timeoutMs ?? Vt, n = Date.now(), r = [];
1087
1110
  let i;
1088
1111
  const o = {
1089
1112
  log: console.log,
@@ -1101,7 +1124,7 @@ async function Q(e) {
1101
1124
  i = window.setTimeout(() => h(a), s);
1102
1125
  })
1103
1126
  ]);
1104
- return d === a ? Zt(s) : {
1127
+ return d === a ? ee(s) : {
1105
1128
  ok: !0,
1106
1129
  result: d,
1107
1130
  console: r,
@@ -1130,7 +1153,7 @@ async function Q(e) {
1130
1153
  i !== void 0 && window.clearTimeout(i), console.log = o.log, console.info = o.info, console.warn = o.warn, console.error = o.error;
1131
1154
  }
1132
1155
  }
1133
- function Zt(e) {
1156
+ function ee(e) {
1134
1157
  return {
1135
1158
  ok: !1,
1136
1159
  exception: {
@@ -1144,15 +1167,15 @@ function Zt(e) {
1144
1167
  }
1145
1168
  };
1146
1169
  }
1147
- function Qt(e) {
1170
+ function se(e) {
1148
1171
  return e.replace(/\/+$/, "");
1149
1172
  }
1150
- function te(e) {
1173
+ function ne(e) {
1151
1174
  const t = new URL("/api/product-agent/embed/ws", e);
1152
1175
  return t.protocol = t.protocol === "https:" ? "wss:" : "ws:", t.toString();
1153
1176
  }
1154
1177
  function y() {
1155
- const e = lt();
1178
+ const e = ht();
1156
1179
  return {
1157
1180
  url: location.href,
1158
1181
  title: document.title,
@@ -1160,17 +1183,37 @@ function y() {
1160
1183
  ...e ? { plunoProductAgentUi: e } : {}
1161
1184
  };
1162
1185
  }
1163
- function ee() {
1186
+ function re() {
1164
1187
  return {
1165
1188
  pageUrl: location.href,
1166
1189
  pageTitle: document.title,
1167
- htmlContent: ne()
1190
+ htmlContent: ce()
1168
1191
  };
1169
1192
  }
1170
- function se() {
1171
- return lt()?.surface === "browser_extension_sdk_preview";
1193
+ function ie(e) {
1194
+ return C.add(e), R || (R = oe()), () => {
1195
+ C.delete(e), C.size === 0 && (R?.(), R = null);
1196
+ };
1197
+ }
1198
+ function oe() {
1199
+ const e = () => {
1200
+ for (const i of Array.from(C))
1201
+ i();
1202
+ }, t = window.history.pushState.bind(window.history), s = window.history.replaceState.bind(window.history), n = ((...i) => {
1203
+ const o = t(...i);
1204
+ return e(), o;
1205
+ }), r = ((...i) => {
1206
+ const o = s(...i);
1207
+ return e(), o;
1208
+ });
1209
+ return window.history.pushState = n, window.history.replaceState = r, window.addEventListener("popstate", e), window.addEventListener("hashchange", e), () => {
1210
+ window.history.pushState === n && (window.history.pushState = t), window.history.replaceState === r && (window.history.replaceState = s), window.removeEventListener("popstate", e), window.removeEventListener("hashchange", e);
1211
+ };
1212
+ }
1213
+ function ae() {
1214
+ return ht()?.surface === "browser_extension_sdk_preview";
1172
1215
  }
1173
- function ne() {
1216
+ function ce() {
1174
1217
  const e = document.body?.cloneNode(!0);
1175
1218
  return e instanceof HTMLElement ? (e.querySelectorAll(
1176
1219
  [
@@ -1194,8 +1237,8 @@ function ne() {
1194
1237
  s.name === "href" || s.name === "aria-label" || s.name === "role" || t.removeAttribute(s.name);
1195
1238
  }), e.textContent?.replace(/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}/gi, "[email]").replace(/\b(?:\d[ -]*?){13,19}\b/g, "[number]").replace(/\b(?:sk|pk|tok|key|secret|token)_[A-Za-z0-9_-]{8,}\b/gi, "[secret]").replace(/\s+/g, " ").trim().slice(0, 12e3) ?? "") : "";
1196
1239
  }
1197
- function lt() {
1198
- const e = document.querySelector(X);
1240
+ function ht() {
1241
+ const e = document.querySelector(J);
1199
1242
  if (!(e ?? document.querySelector(B)))
1200
1243
  return;
1201
1244
  const s = e ? "browser_extension_sdk_preview" : "embedded_widget";
@@ -1205,7 +1248,7 @@ function lt() {
1205
1248
  selectors: [
1206
1249
  {
1207
1250
  name: "widget_host",
1208
- selector: s === "browser_extension_sdk_preview" ? X : B,
1251
+ selector: s === "browser_extension_sdk_preview" ? J : B,
1209
1252
  description: "Finds Pluno's shadow-host element in the host page DOM."
1210
1253
  },
1211
1254
  {
@@ -1215,18 +1258,18 @@ function lt() {
1215
1258
  },
1216
1259
  {
1217
1260
  name: "widget_panel",
1218
- selector: Ut,
1261
+ selector: Dt,
1219
1262
  description: "Finds Pluno's open chat panel inside the widget host shadow root."
1220
1263
  },
1221
1264
  {
1222
1265
  name: "widget_timeline",
1223
- selector: Ct,
1266
+ selector: Nt,
1224
1267
  description: "Finds Pluno's chat timeline inside the widget host shadow root."
1225
1268
  }
1226
1269
  ]
1227
1270
  };
1228
1271
  }
1229
- function re(e) {
1272
+ function le(e) {
1230
1273
  try {
1231
1274
  const t = JSON.parse(e);
1232
1275
  return t && typeof t == "object" ? t : { type: "error", message: "Invalid server event" };
@@ -1234,16 +1277,16 @@ function re(e) {
1234
1277
  return { type: "error", message: "Invalid server event" };
1235
1278
  }
1236
1279
  }
1237
- function tt(e, t) {
1280
+ function st(e, t) {
1238
1281
  if (!e || typeof e != "object")
1239
1282
  return [];
1240
1283
  const s = e[t];
1241
1284
  return Array.isArray(s) ? s.filter((n) => typeof n == "string" && n.trim().length > 0) : [];
1242
1285
  }
1243
- function ie(e) {
1286
+ function ue(e) {
1244
1287
  return Array.isArray(e) ? e.filter((t) => typeof t == "string" && t.trim().length > 0) : [];
1245
1288
  }
1246
- function oe(e) {
1289
+ function de(e) {
1247
1290
  if (!e || typeof e != "object")
1248
1291
  return null;
1249
1292
  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, o = typeof n.fontFamily == "string" && n.fontFamily.trim() ? n.fontFamily : null, c = typeof n.scribbleStyle == "boolean" ? n.scribbleStyle : null;
@@ -1254,13 +1297,13 @@ function oe(e) {
1254
1297
  ...c !== null ? { scribbleStyle: c } : {}
1255
1298
  };
1256
1299
  }
1257
- function ae(e) {
1300
+ function he(e) {
1258
1301
  if (!e || typeof e != "object")
1259
1302
  return null;
1260
1303
  const t = e.javascript;
1261
1304
  return typeof t != "string" || !t.trim() ? null : { javascript: t };
1262
1305
  }
1263
- function ce(e, t) {
1306
+ function pe(e, t) {
1264
1307
  return t ? e && typeof e == "object" ? {
1265
1308
  ...e,
1266
1309
  helperError: t
@@ -1270,30 +1313,30 @@ function ce(e, t) {
1270
1313
  helperError: t
1271
1314
  } : e;
1272
1315
  }
1273
- function ue(e) {
1316
+ function ge(e) {
1274
1317
  if (!e || typeof e != "object")
1275
1318
  return e;
1276
1319
  const t = e;
1277
1320
  return typeof t.exception?.message == "string" ? t.exception.message : typeof t.error == "string" ? t.error : e;
1278
1321
  }
1279
- function le() {
1322
+ function fe() {
1280
1323
  const e = "pluno.productAgent.clientId", t = window.localStorage.getItem(e);
1281
1324
  if (t)
1282
1325
  return t;
1283
1326
  const s = crypto.randomUUID();
1284
1327
  return window.localStorage.setItem(e, s), s;
1285
1328
  }
1286
- function de() {
1287
- const e = window.sessionStorage.getItem(V);
1329
+ function me() {
1330
+ const e = window.sessionStorage.getItem(Z);
1288
1331
  if (e)
1289
1332
  return e;
1290
1333
  const t = crypto.randomUUID();
1291
- return window.sessionStorage.setItem(V, t), t;
1334
+ return window.sessionStorage.setItem(Z, t), t;
1292
1335
  }
1293
- function R() {
1336
+ function _() {
1294
1337
  return crypto.randomUUID();
1295
1338
  }
1296
- function he(e) {
1339
+ function ye(e) {
1297
1340
  if (!e || typeof e != "object")
1298
1341
  return null;
1299
1342
  const t = e, s = typeof t.id == "string" ? t.id : null;
@@ -1304,14 +1347,14 @@ function he(e) {
1304
1347
  avatarUrl: typeof t.avatarUrl == "string" ? t.avatarUrl : null
1305
1348
  } : null;
1306
1349
  }
1307
- function pe(e, t) {
1308
- return Array.isArray(e) ? W(
1309
- x(
1310
- e.map((s) => dt(s, t)).filter((s) => s !== null)
1350
+ function we(e, t) {
1351
+ return Array.isArray(e) ? x(
1352
+ j(
1353
+ e.map((s) => pt(s, t)).filter((s) => s !== null)
1311
1354
  )
1312
1355
  ) : [];
1313
1356
  }
1314
- function ge(e) {
1357
+ function Te(e) {
1315
1358
  return Array.isArray(e) ? e.flatMap((t) => {
1316
1359
  if (!t || typeof t != "object")
1317
1360
  return [];
@@ -1329,7 +1372,7 @@ function ge(e) {
1329
1372
  ];
1330
1373
  }) : [];
1331
1374
  }
1332
- function dt(e, t) {
1375
+ function pt(e, t) {
1333
1376
  if (!e || typeof e != "object")
1334
1377
  return null;
1335
1378
  const s = e, n = s.data;
@@ -1341,39 +1384,39 @@ function dt(e, t) {
1341
1384
  return {
1342
1385
  id: String(s.id ?? crypto.randomUUID()),
1343
1386
  role: i,
1344
- content: we(r.content),
1387
+ content: Ee(r.content),
1345
1388
  createdAt: typeof s.createdAt == "string" ? s.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
1346
- respondsToUserMessageId: O(r) ?? void 0,
1389
+ respondsToUserMessageId: L(r) ?? void 0,
1347
1390
  ...k(r) ? { runId: k(r) } : {},
1348
- attachments: Tt(r.attachments, t)
1391
+ attachments: It(r.attachments, t)
1349
1392
  };
1350
1393
  }
1351
1394
  return r.type === "function_call" || r.type === "tool_call" || r.type === "web_search_call" ? {
1352
1395
  id: String(s.id ?? crypto.randomUUID()),
1353
1396
  role: "tool",
1354
- content: me(r),
1397
+ content: Ae(r),
1355
1398
  createdAt: typeof s.createdAt == "string" ? s.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
1356
- respondsToUserMessageId: O(r) ?? void 0,
1399
+ respondsToUserMessageId: L(r) ?? void 0,
1357
1400
  ...k(r) ? { runId: k(r) } : {},
1358
1401
  dataType: String(r.type),
1359
1402
  toolName: typeof r.name == "string" ? r.name : void 0,
1360
- callId: Te(r) ?? void 0,
1403
+ callId: ke(r) ?? void 0,
1361
1404
  loading: r.localExecutionStatus === "running"
1362
1405
  } : r.type === "run_status" || r.type === "run_error" ? r.type === "run_error" && r.stage === "tool_execution" ? null : {
1363
1406
  id: String(s.id ?? crypto.randomUUID()),
1364
1407
  role: "system",
1365
- content: fe(r),
1408
+ content: Ie(r),
1366
1409
  createdAt: typeof s.createdAt == "string" ? s.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
1367
- respondsToUserMessageId: O(r) ?? void 0,
1410
+ respondsToUserMessageId: L(r) ?? void 0,
1368
1411
  ...k(r) ? { runId: k(r) } : {},
1369
1412
  dataType: String(r.type),
1370
1413
  loading: r.type === "run_status" && (r.status === "running" || r.status === "retrying")
1371
1414
  } : null;
1372
1415
  }
1373
- function fe(e) {
1416
+ function Ie(e) {
1374
1417
  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.";
1375
1418
  }
1376
- function me(e) {
1419
+ function Ae(e) {
1377
1420
  if (e.type === "web_search_call") {
1378
1421
  const t = e.action;
1379
1422
  if (t && typeof t == "object") {
@@ -1385,9 +1428,9 @@ function me(e) {
1385
1428
  }
1386
1429
  return "Searching the web";
1387
1430
  }
1388
- return ye(e);
1431
+ return Se(e);
1389
1432
  }
1390
- function ye(e) {
1433
+ function Se(e) {
1391
1434
  if (typeof e.summary == "string" && e.summary.trim().length > 0)
1392
1435
  return e.summary;
1393
1436
  if (typeof e.arguments == "string")
@@ -1400,11 +1443,11 @@ function ye(e) {
1400
1443
  }
1401
1444
  return typeof e.name == "string" && e.name.trim().length > 0 ? e.name : "Run tool";
1402
1445
  }
1403
- function Te(e) {
1446
+ function ke(e) {
1404
1447
  const t = e.callId ?? e.call_id;
1405
1448
  return typeof t == "string" && t ? t : null;
1406
1449
  }
1407
- function we(e) {
1450
+ function Ee(e) {
1408
1451
  return typeof e == "string" ? e : Array.isArray(e) ? e.map((t) => {
1409
1452
  if (!t || typeof t != "object")
1410
1453
  return "";
@@ -1412,19 +1455,19 @@ function we(e) {
1412
1455
  return typeof s.text == "string" ? s.text : typeof s.content == "string" ? s.content : "";
1413
1456
  }).filter(Boolean).join("") : "";
1414
1457
  }
1415
- function Ie(e, t) {
1416
- const s = ht(e, t), n = Ee(e, t), r = n.findIndex((o) => o.id === s.id);
1458
+ function Re(e, t) {
1459
+ const s = gt(e, t), n = Ce(e, t), r = n.findIndex((o) => o.id === s.id);
1417
1460
  if (r === -1)
1418
- return W(
1419
- x([...n, s])
1461
+ return x(
1462
+ j([...n, s])
1420
1463
  );
1421
1464
  const i = [...n];
1422
- return i[r] = s, W(x(i));
1465
+ return i[r] = s, x(j(i));
1423
1466
  }
1424
- function Ae(e, t) {
1425
- return t.map((s) => ht(e, s));
1467
+ function _e(e, t) {
1468
+ return t.map((s) => gt(e, s));
1426
1469
  }
1427
- function ht(e, t) {
1470
+ function gt(e, t) {
1428
1471
  if (t.role !== "user" || !t.attachments?.length)
1429
1472
  return t;
1430
1473
  const s = e.find(
@@ -1433,19 +1476,19 @@ function ht(e, t) {
1433
1476
  if (!s?.attachments?.length)
1434
1477
  return t;
1435
1478
  const n = t.attachments.map((r) => {
1436
- const i = Se(s.attachments ?? [], r);
1437
- return i ? ke(r, i) : r;
1479
+ const i = Pe(s.attachments ?? [], r);
1480
+ return i ? Ue(r, i) : r;
1438
1481
  });
1439
1482
  return { ...t, attachments: n };
1440
1483
  }
1441
- function Se(e, t) {
1484
+ function Pe(e, t) {
1442
1485
  return t.id ? e.find((s) => s.id === t.id) ?? null : null;
1443
1486
  }
1444
- function ke(e, t) {
1487
+ function Ue(e, t) {
1445
1488
  const { previewUrl: s } = t;
1446
1489
  return s ? { ...e, previewUrl: s } : e;
1447
1490
  }
1448
- function Ee(e, t) {
1491
+ function Ce(e, t) {
1449
1492
  if (t.role !== "user")
1450
1493
  return e;
1451
1494
  const s = e.findIndex(
@@ -1456,24 +1499,24 @@ function Ee(e, t) {
1456
1499
  const n = [...e];
1457
1500
  return n.splice(s, 1), n;
1458
1501
  }
1459
- function et(e) {
1460
- const t = pt(e);
1461
- return t === null ? !1 : e.slice(t + 1).some(gt);
1502
+ function nt(e) {
1503
+ const t = ft(e);
1504
+ return t === null ? !1 : e.slice(t + 1).some(mt);
1462
1505
  }
1463
- function Re(e) {
1464
- const t = pt(e);
1506
+ function Me(e) {
1507
+ const t = ft(e);
1465
1508
  return t === null ? e.some((s) => s.role === "assistant") : e.slice(t + 1).some((s) => s.role === "assistant");
1466
1509
  }
1467
- function pt(e) {
1510
+ function ft(e) {
1468
1511
  for (let t = e.length - 1; t >= 0; t -= 1)
1469
1512
  if (e[t].role === "user")
1470
1513
  return t;
1471
1514
  return null;
1472
1515
  }
1473
- function gt(e) {
1516
+ function mt(e) {
1474
1517
  return e.role === "assistant" ? !0 : e.role !== "system" ? !1 : e.dataType === "run_error" ? !0 : e.dataType === "run_status" && e.loading !== !0;
1475
1518
  }
1476
- function ft(e) {
1519
+ function yt(e) {
1477
1520
  for (let t = e.length - 1; t >= 0; t -= 1) {
1478
1521
  const s = e[t];
1479
1522
  if (!s || typeof s != "object")
@@ -1487,18 +1530,18 @@ function ft(e) {
1487
1530
  }
1488
1531
  return null;
1489
1532
  }
1490
- function _e(e, t) {
1491
- const s = ft(t);
1533
+ function be(e, t) {
1534
+ const s = yt(t);
1492
1535
  if (s === null)
1493
1536
  return !1;
1494
1537
  const n = t[s], r = n && typeof n == "object" ? n.id : null;
1495
1538
  if (typeof r != "string" || !r)
1496
1539
  return !1;
1497
1540
  const i = e.findIndex((o) => o.role === "user" && o.id === r);
1498
- return i === -1 ? !1 : e.slice(i + 1).some(gt);
1541
+ return i === -1 ? !1 : e.slice(i + 1).some(mt);
1499
1542
  }
1500
- function Pe(e) {
1501
- const t = ft(e);
1543
+ function De(e) {
1544
+ const t = yt(e);
1502
1545
  if (t === null)
1503
1546
  return null;
1504
1547
  const s = e[t];
@@ -1510,22 +1553,22 @@ function Pe(e) {
1510
1553
  const r = n.clientMessageId;
1511
1554
  return typeof r == "string" ? r : null;
1512
1555
  }
1513
- function Me(e) {
1556
+ function Ne(e) {
1514
1557
  if (!e || typeof e != "object")
1515
1558
  return !1;
1516
1559
  const t = e;
1517
1560
  return t.type === "message" && t.role === "user" ? !1 : t.type === "message" || t.type === "function_call" || t.type === "function_call_output" || t.type === "run_error" || t.type === "run_status";
1518
1561
  }
1519
- function W(e) {
1520
- return e.filter((t, s) => mt(t) ? !Ne(e, s) && !Ce(e, s) && !De(e, s) : be(t) ? !Ue(e, s) : !0);
1562
+ function x(e) {
1563
+ return e.filter((t, s) => wt(t) ? !He(e, s) && !Fe(e, s) && !Le(e, s) : qe(t) ? !Oe(e, s) : !0);
1521
1564
  }
1522
- function be(e) {
1565
+ function qe(e) {
1523
1566
  return e.role === "system" && (e.dataType === "run_status" || e.dataType === "run_error");
1524
1567
  }
1525
- function mt(e) {
1568
+ function wt(e) {
1526
1569
  return e.role === "system" && e.dataType === "run_status" && e.loading === !0;
1527
1570
  }
1528
- function x(e) {
1571
+ function j(e) {
1529
1572
  const t = new Set(e.filter((i) => i.role === "user").map((i) => i.id)), s = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set();
1530
1573
  for (const i of e) {
1531
1574
  if (i.role === "user" || !i.respondsToUserMessageId || !t.has(i.respondsToUserMessageId))
@@ -1541,53 +1584,53 @@ function x(e) {
1541
1584
  n.has(i.id) || (r.push(i), i.role === "user" && r.push(...s.get(i.id) ?? []));
1542
1585
  return r;
1543
1586
  }
1544
- function Ue(e, t) {
1587
+ function Oe(e, t) {
1545
1588
  const s = e[t];
1546
1589
  for (let n = t + 1; n < e.length; n += 1) {
1547
1590
  const r = e[n];
1548
1591
  if (r.role === "user")
1549
1592
  return !1;
1550
- if (r.role === "assistant" && C(s, r))
1593
+ if (r.role === "assistant" && N(s, r))
1551
1594
  return !0;
1552
1595
  }
1553
1596
  return !1;
1554
1597
  }
1555
- function Ce(e, t) {
1598
+ function Fe(e, t) {
1556
1599
  const s = e[t];
1557
1600
  for (let n = t + 1; n < e.length; n += 1)
1558
- if (e[n].role === "assistant" && C(s, e[n]))
1601
+ if (e[n].role === "assistant" && N(s, e[n]))
1559
1602
  return !0;
1560
1603
  return !1;
1561
1604
  }
1562
- function De(e, t) {
1605
+ function Le(e, t) {
1563
1606
  const s = e[t];
1564
1607
  for (let n = t + 1; n < e.length; n += 1)
1565
- if (e[n].role === "tool" && C(s, e[n]))
1608
+ if (e[n].role === "tool" && N(s, e[n]))
1566
1609
  return !0;
1567
1610
  return !1;
1568
1611
  }
1569
- function Ne(e, t) {
1612
+ function He(e, t) {
1570
1613
  const s = e[t];
1571
1614
  for (let n = t + 1; n < e.length; n += 1)
1572
- if (mt(e[n]) && C(s, e[n]))
1615
+ if (wt(e[n]) && N(s, e[n]))
1573
1616
  return !0;
1574
1617
  return !1;
1575
1618
  }
1576
- function C(e, t) {
1619
+ function N(e, t) {
1577
1620
  return !e.runId || !t.runId ? !0 : e.runId === t.runId;
1578
1621
  }
1579
1622
  function I(e, t) {
1580
1623
  return e && typeof e == "object" && typeof e[t] == "string" ? e[t] : null;
1581
1624
  }
1582
- function qe(e, t) {
1625
+ function We(e, t) {
1583
1626
  try {
1584
- const s = window.localStorage.getItem(`${ct}${e}`);
1627
+ const s = window.localStorage.getItem(`${ut}${e}`);
1585
1628
  if (!s)
1586
1629
  return null;
1587
1630
  const n = JSON.parse(s), r = typeof n.sessionId == "string" ? n.sessionId : null;
1588
1631
  if (t !== void 0 && r !== t)
1589
1632
  return null;
1590
- const i = Array.isArray(n.messages) ? n.messages.map(We).filter((o) => !!o) : [];
1633
+ const i = Array.isArray(n.messages) ? n.messages.map(ze).filter((o) => !!o) : [];
1591
1634
  return {
1592
1635
  sessionId: r,
1593
1636
  messages: i
@@ -1596,58 +1639,58 @@ function qe(e, t) {
1596
1639
  return null;
1597
1640
  }
1598
1641
  }
1599
- function Oe(e, t) {
1642
+ function Be(e, t) {
1600
1643
  try {
1601
1644
  window.localStorage.setItem(
1602
- `${ct}${e}`,
1645
+ `${ut}${e}`,
1603
1646
  JSON.stringify({
1604
1647
  sessionId: t.sessionId,
1605
- messages: t.messages.slice(-zt).map(xe)
1648
+ messages: t.messages.slice(-Xt).map(Ge)
1606
1649
  })
1607
1650
  );
1608
1651
  } catch {
1609
1652
  return;
1610
1653
  }
1611
1654
  }
1612
- function Fe(e) {
1655
+ function ve(e) {
1613
1656
  try {
1614
- const t = window.localStorage.getItem(`${L}${e}`);
1657
+ const t = window.localStorage.getItem(`${v}${e}`);
1615
1658
  if (!t)
1616
1659
  return [];
1617
1660
  const s = JSON.parse(t);
1618
- return Array.isArray(s) ? s.filter(yt) : [];
1661
+ return Array.isArray(s) ? s.filter(Tt) : [];
1619
1662
  } catch {
1620
1663
  return [];
1621
1664
  }
1622
1665
  }
1623
- function _(e, t) {
1666
+ function P(e, t) {
1624
1667
  try {
1625
- const s = t.filter(yt);
1668
+ const s = t.filter(Tt);
1626
1669
  if (s.length === 0) {
1627
- window.localStorage.removeItem(`${L}${e}`);
1670
+ window.localStorage.removeItem(`${v}${e}`);
1628
1671
  return;
1629
1672
  }
1630
1673
  window.localStorage.setItem(
1631
- `${L}${e}`,
1674
+ `${v}${e}`,
1632
1675
  JSON.stringify(s.slice(-25))
1633
1676
  );
1634
1677
  } catch {
1635
1678
  return;
1636
1679
  }
1637
1680
  }
1638
- function yt(e) {
1681
+ function Tt(e) {
1639
1682
  if (!e || typeof e != "object")
1640
1683
  return !1;
1641
1684
  const t = e;
1642
- return t.type === "chat.user_message" ? typeof t.content == "string" && st(t.page) : t.type === "page.upsert" || t.type === "session.reset" || t.type === "network.batch" ? st(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;
1685
+ return t.type === "chat.user_message" ? typeof t.content == "string" && rt(t.page) : t.type === "page.upsert" || t.type === "session.reset" || t.type === "network.batch" ? rt(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;
1643
1686
  }
1644
- function st(e) {
1687
+ function rt(e) {
1645
1688
  if (!e || typeof e != "object")
1646
1689
  return !1;
1647
1690
  const t = e;
1648
1691
  return typeof t.url == "string" && typeof t.title == "string" && typeof t.origin == "string";
1649
1692
  }
1650
- function Tt(e, t) {
1693
+ function It(e, t) {
1651
1694
  if (!Array.isArray(e))
1652
1695
  return;
1653
1696
  const s = e.filter((r) => {
@@ -1655,24 +1698,24 @@ function Tt(e, t) {
1655
1698
  return !1;
1656
1699
  const i = r;
1657
1700
  return typeof i.name == "string" && typeof i.mimeType == "string" && typeof i.sizeBytes == "number";
1658
- }), n = t ? s.map((r) => wt(r, t)) : s;
1701
+ }), n = t ? s.map((r) => At(r, t)) : s;
1659
1702
  return n.length > 0 ? n : void 0;
1660
1703
  }
1661
- function wt(e, t) {
1704
+ function At(e, t) {
1662
1705
  return e.fileUrl?.startsWith("/") ? {
1663
1706
  ...e,
1664
1707
  fileUrl: new URL(e.fileUrl, t).toString()
1665
1708
  } : e;
1666
1709
  }
1667
- function He(e) {
1668
- if (Be(e))
1710
+ function xe(e) {
1711
+ if (je(e))
1669
1712
  return {
1670
1713
  headers: {
1671
1714
  "ngrok-skip-browser-warning": "true"
1672
1715
  }
1673
1716
  };
1674
1717
  }
1675
- function Be(e) {
1718
+ function je(e) {
1676
1719
  try {
1677
1720
  const t = new URL(e).hostname;
1678
1721
  return t.endsWith(".ngrok-free.dev") || t.endsWith(".ngrok-free.app") || t.endsWith(".ngrok.app") || t.endsWith(".ngrok.io");
@@ -1680,14 +1723,14 @@ function Be(e) {
1680
1723
  return !1;
1681
1724
  }
1682
1725
  }
1683
- function nt(e) {
1684
- return e.type || Le(e.name) || "application/octet-stream";
1726
+ function it(e) {
1727
+ return e.type || $e(e.name) || "application/octet-stream";
1685
1728
  }
1686
- function Le(e) {
1729
+ function $e(e) {
1687
1730
  const t = e.toLowerCase();
1688
1731
  return t.endsWith(".png") ? "image/png" : t.endsWith(".jpg") || t.endsWith(".jpeg") ? "image/jpeg" : t.endsWith(".webp") ? "image/webp" : t.endsWith(".gif") ? "image/gif" : t.endsWith(".pdf") ? "application/pdf" : null;
1689
1732
  }
1690
- function We(e) {
1733
+ function ze(e) {
1691
1734
  if (!e || typeof e != "object")
1692
1735
  return null;
1693
1736
  const t = e;
@@ -1699,17 +1742,17 @@ function We(e) {
1699
1742
  respondsToUserMessageId: typeof t.respondsToUserMessageId == "string" ? t.respondsToUserMessageId : void 0,
1700
1743
  ...typeof t.runId == "string" ? { runId: t.runId } : {},
1701
1744
  dataType: typeof t.dataType == "string" ? t.dataType : void 0,
1702
- attachments: Tt(t.attachments)?.map($),
1745
+ attachments: It(t.attachments)?.map(G),
1703
1746
  loading: typeof t.loading == "boolean" ? t.loading : void 0
1704
1747
  };
1705
1748
  }
1706
- function xe(e) {
1749
+ function Ge(e) {
1707
1750
  return e.attachments?.length ? {
1708
1751
  ...e,
1709
- attachments: e.attachments.map($)
1752
+ attachments: e.attachments.map(G)
1710
1753
  } : e;
1711
1754
  }
1712
- function $(e) {
1755
+ function G(e) {
1713
1756
  const {
1714
1757
  dataUrl: t,
1715
1758
  objectUrl: s,
@@ -1718,7 +1761,7 @@ function $(e) {
1718
1761
  } = e;
1719
1762
  return r;
1720
1763
  }
1721
- function O(e) {
1764
+ function L(e) {
1722
1765
  const t = e.respondsToUserMessageId;
1723
1766
  return typeof t == "string" && t ? t : null;
1724
1767
  }
@@ -1726,18 +1769,18 @@ function k(e) {
1726
1769
  const t = e.runId;
1727
1770
  return typeof t == "string" && t ? t : null;
1728
1771
  }
1729
- function ve(e) {
1772
+ function Xe(e) {
1730
1773
  return !!e && typeof e == "object" && typeof e.summary == "string" && typeof e.javascript == "string";
1731
1774
  }
1732
- function rt(e) {
1775
+ function ot(e) {
1733
1776
  const t = {};
1734
1777
  return e?.forEach((s, n) => {
1735
1778
  t[n] = s;
1736
1779
  }), t;
1737
1780
  }
1738
- async function je(e, t) {
1781
+ async function Ke(e, t) {
1739
1782
  if (typeof t?.body < "u")
1740
- return It(t.body);
1783
+ return St(t.body);
1741
1784
  if (e)
1742
1785
  try {
1743
1786
  return A(await e.clone().text());
@@ -1745,21 +1788,21 @@ async function je(e, t) {
1745
1788
  return;
1746
1789
  }
1747
1790
  }
1748
- async function $e(e) {
1791
+ async function Je(e) {
1749
1792
  try {
1750
1793
  return A(await e.clone().text());
1751
1794
  } catch (t) {
1752
1795
  return { error: t instanceof Error ? t.message : "unavailable" };
1753
1796
  }
1754
1797
  }
1755
- function ze(e) {
1798
+ function Ve(e) {
1756
1799
  try {
1757
1800
  return e.responseType === "" || e.responseType === "text" ? A(e.responseText ?? "") : e.responseType === "json" ? A(JSON.stringify(e.response)) : `[unsupported xhr responseType: ${e.responseType || "unknown"}]`;
1758
1801
  } catch (t) {
1759
1802
  return { error: t instanceof Error ? t.message : "unavailable" };
1760
1803
  }
1761
1804
  }
1762
- function It(e) {
1805
+ function St(e) {
1763
1806
  if (!(e === null || typeof e > "u")) {
1764
1807
  if (typeof e == "string")
1765
1808
  return A(e);
@@ -1778,7 +1821,7 @@ function It(e) {
1778
1821
  }
1779
1822
  }
1780
1823
  }
1781
- function Ge(e) {
1824
+ function Ye(e) {
1782
1825
  const t = {};
1783
1826
  for (const s of e.trim().split(/[\r\n]+/)) {
1784
1827
  const n = s.indexOf(":");
@@ -1787,9 +1830,9 @@ function Ge(e) {
1787
1830
  return t;
1788
1831
  }
1789
1832
  function A(e) {
1790
- return e.length <= q ? e : `${e.slice(0, q)}... [truncated ${e.length - q} chars]`;
1833
+ return e.length <= F ? e : `${e.slice(0, F)}... [truncated ${e.length - F} chars]`;
1791
1834
  }
1792
- function P(e) {
1835
+ function U(e) {
1793
1836
  return `${e}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
1794
1837
  }
1795
1838
  class M extends Error {
@@ -1798,42 +1841,42 @@ class M extends Error {
1798
1841
  }
1799
1842
  status;
1800
1843
  }
1801
- async function F(e, t) {
1844
+ async function H(e, t) {
1802
1845
  let s = null;
1803
- for (let n = 0; n < J; n += 1)
1846
+ for (let n = 0; n < Y; n += 1)
1804
1847
  try {
1805
1848
  return await e();
1806
1849
  } catch (r) {
1807
- if (s = r, n >= J - 1 || !Ke(r))
1850
+ if (s = r, n >= Y - 1 || !Qe(r))
1808
1851
  throw r;
1809
- await Xe(n);
1852
+ await Ze(n);
1810
1853
  }
1811
1854
  throw s instanceof Error ? s : new Error(t);
1812
1855
  }
1813
- function Xe(e) {
1856
+ function Ze(e) {
1814
1857
  return new Promise((t) => {
1815
- window.setTimeout(t, vt[e] ?? 0);
1858
+ window.setTimeout(t, $t[e] ?? 0);
1816
1859
  });
1817
1860
  }
1818
- function Ke(e) {
1819
- return e instanceof M ? Je(e.status) : e instanceof TypeError;
1861
+ function Qe(e) {
1862
+ return e instanceof M ? ts(e.status) : e instanceof TypeError;
1820
1863
  }
1821
- function Je(e) {
1864
+ function ts(e) {
1822
1865
  return e === 408 || e === 409 || e === 429 || e >= 500;
1823
1866
  }
1824
- function Ve(e) {
1867
+ function es(e) {
1825
1868
  return e === 401 || e === 403;
1826
1869
  }
1827
- const z = "[REDACTED_SECRET]", T = "[REDACTED_TOKEN]", Ye = "[REDACTED_SIGNED_URL]", Ze = 20, Qe = /^(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, At = /\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi, St = /\bBasic\s+[A-Za-z0-9+/=-]{12,}/gi, kt = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g, Et = /\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, ts = /\bhttps?:\/\/[^\s"'<>]+(?:X-Amz-Signature|X-Goog-Signature|Signature|sig=)[^\s"'<>]*/gi, es = /\bhttps?:\/\/[^\s"'<>]+/gi, ss = /[),.;\]]+$/;
1828
- function w(e) {
1870
+ const X = "[REDACTED_SECRET]", w = "[REDACTED_TOKEN]", ss = "[REDACTED_SIGNED_URL]", ns = 20, rs = /^(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, kt = /\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi, Et = /\bBasic\s+[A-Za-z0-9+/=-]{12,}/gi, Rt = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g, _t = /\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, is = /\bhttps?:\/\/[^\s"'<>]+(?:X-Amz-Signature|X-Goog-Signature|Signature|sig=)[^\s"'<>]*/gi, os = /\bhttps?:\/\/[^\s"'<>]+/gi, as = /[),.;\]]+$/;
1871
+ function T(e) {
1829
1872
  return b(e, 0, /* @__PURE__ */ new WeakSet());
1830
1873
  }
1831
1874
  function b(e, t, s) {
1832
1875
  if (typeof e == "string")
1833
- return e.startsWith("data:image/") || e.startsWith("data:application/pdf;") ? e : is(e);
1876
+ return e.startsWith("data:image/") || e.startsWith("data:application/pdf;") ? e : us(e);
1834
1877
  if (e === null || typeof e != "object")
1835
1878
  return e;
1836
- if (t >= Ze)
1879
+ if (t >= ns)
1837
1880
  return "[REDACTED_MAX_DEPTH]";
1838
1881
  if (s.has(e))
1839
1882
  return "[REDACTED_CIRCULAR]";
@@ -1841,42 +1884,42 @@ function b(e, t, s) {
1841
1884
  return e.map((r) => b(r, t + 1, s));
1842
1885
  const n = {};
1843
1886
  for (const [r, i] of Object.entries(e))
1844
- ns(r) ? n[r] = z : n[r] = r.toLowerCase() === "url" ? rs(i) : b(i, t + 1, s);
1887
+ cs(r) ? n[r] = X : n[r] = r.toLowerCase() === "url" ? ls(i) : b(i, t + 1, s);
1845
1888
  return n;
1846
1889
  }
1847
- function ns(e) {
1890
+ function cs(e) {
1848
1891
  const t = e.replace(/[^a-z0-9]/gi, "").toLowerCase();
1849
1892
  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");
1850
1893
  }
1851
- function rs(e) {
1852
- return typeof e == "string" ? Rt(e) : b(e, 0, /* @__PURE__ */ new WeakSet());
1894
+ function ls(e) {
1895
+ return typeof e == "string" ? Pt(e) : b(e, 0, /* @__PURE__ */ new WeakSet());
1853
1896
  }
1854
- function Rt(e) {
1897
+ function Pt(e) {
1855
1898
  try {
1856
1899
  const t = new URL(e, location.href);
1857
1900
  for (const s of Array.from(t.searchParams.keys()))
1858
- Qe.test(s) && t.searchParams.set(s, T);
1859
- return t.username && (t.username = T), t.password && (t.password = T), t.toString();
1901
+ rs.test(s) && t.searchParams.set(s, w);
1902
+ return t.username && (t.username = w), t.password && (t.password = w), t.toString();
1860
1903
  } catch {
1861
- return os(e);
1904
+ return ds(e);
1862
1905
  }
1863
1906
  }
1864
- function is(e) {
1865
- return e.replace(ts, Ye).replace(es, as).replace(At, `Bearer ${T}`).replace(St, `Basic ${T}`).replace(kt, T).replace(Et, (t, s) => `${s}: ${z}`);
1907
+ function us(e) {
1908
+ return e.replace(is, ss).replace(os, hs).replace(kt, `Bearer ${w}`).replace(Et, `Basic ${w}`).replace(Rt, w).replace(_t, (t, s) => `${s}: ${X}`);
1866
1909
  }
1867
- function os(e) {
1868
- return e.replace(At, `Bearer ${T}`).replace(St, `Basic ${T}`).replace(kt, T).replace(Et, (t, s) => `${s}: ${z}`);
1910
+ function ds(e) {
1911
+ return e.replace(kt, `Bearer ${w}`).replace(Et, `Basic ${w}`).replace(Rt, w).replace(_t, (t, s) => `${s}: ${X}`);
1869
1912
  }
1870
- function as(e) {
1871
- const t = e.match(ss)?.[0] ?? "", s = t ? e.slice(0, -t.length) : e;
1872
- return `${Rt(s)}${t}`;
1913
+ function hs(e) {
1914
+ const t = e.match(as)?.[0] ?? "", s = t ? e.slice(0, -t.length) : e;
1915
+ return `${Pt(s)}${t}`;
1873
1916
  }
1874
1917
  export {
1875
- X as PLUNO_PRODUCT_AGENT_SDK_PREVIEW_HOST_SELECTOR,
1918
+ J as PLUNO_PRODUCT_AGENT_SDK_PREVIEW_HOST_SELECTOR,
1876
1919
  B as PLUNO_PRODUCT_AGENT_WIDGET_HOST_SELECTOR,
1877
- Ut as PLUNO_PRODUCT_AGENT_WIDGET_PANEL_SELECTOR,
1920
+ Dt as PLUNO_PRODUCT_AGENT_WIDGET_PANEL_SELECTOR,
1878
1921
  bt as PLUNO_PRODUCT_AGENT_WIDGET_ROOT_SELECTOR,
1879
- Ct as PLUNO_PRODUCT_AGENT_WIDGET_TIMELINE_SELECTOR,
1880
- ut as PlunoProductAgent,
1881
- ut as default
1922
+ Nt as PLUNO_PRODUCT_AGENT_WIDGET_TIMELINE_SELECTOR,
1923
+ dt as PlunoProductAgent,
1924
+ dt as default
1882
1925
  };