@pluno/product-agent-web 0.1.121 → 0.1.124

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 ce = "pluno-product-agent-attachments";
2
- const et = "files";
3
- async function qt(e) {
4
- const t = await $();
5
- await Ft(t, "readwrite", (s) => s.put(e));
6
- }
7
- async function le(e) {
8
- const t = await $(), s = await Ft(
1
+ const Ve = "pluno-product-agent-attachments";
2
+ const Mt = "files";
3
+ async function Se(e) {
4
+ const t = await it();
5
+ await ke(t, "readwrite", (s) => s.put(e));
6
+ }
7
+ async function Ye(e) {
8
+ const t = await it(), s = await ke(
9
9
  t,
10
10
  "readonly",
11
11
  (r) => r.get(e)
@@ -13,12 +13,12 @@ async function le(e) {
13
13
  if (!s)
14
14
  return null;
15
15
  const n = Date.now();
16
- return await xt(e, { lastUsedAt: n }), { ...s, lastUsedAt: n };
16
+ return await Ee(e, { lastUsedAt: n }), { ...s, lastUsedAt: n };
17
17
  }
18
- async function xt(e, t) {
19
- const s = await $();
20
- await lt(s, "readwrite", async (n) => {
21
- const r = await ut(
18
+ async function Ee(e, t) {
19
+ const s = await it();
20
+ await Lt(s, "readwrite", async (n) => {
21
+ const r = await xt(
22
22
  n.get(e)
23
23
  );
24
24
  r && n.put({
@@ -27,31 +27,31 @@ async function xt(e, t) {
27
27
  });
28
28
  });
29
29
  }
30
- async function ue(e = 864e5) {
31
- const t = await $(), s = Date.now() - e;
32
- await lt(t, "readwrite", async (n) => {
30
+ async function Ze(e = 864e5) {
31
+ const t = await it(), s = Date.now() - e;
32
+ await Lt(t, "readwrite", async (n) => {
33
33
  const r = n.index("lastUsedAt");
34
- (await ut(r.getAllKeys(IDBKeyRange.upperBound(s)))).forEach((o) => n.delete(o));
34
+ (await xt(r.getAllKeys(IDBKeyRange.upperBound(s)))).forEach((o) => n.delete(o));
35
35
  });
36
36
  }
37
- function $() {
37
+ function it() {
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(ce, 1);
39
+ const s = indexedDB.open(Ve, 1);
40
40
  s.onupgradeneeded = () => {
41
- const r = s.result.createObjectStore(et, { keyPath: "attachmentId" });
41
+ const r = s.result.createObjectStore(Mt, { 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 Ft(e, t, s) {
47
- return await lt(e, t, async (n) => await ut(s(n)));
46
+ async function ke(e, t, s) {
47
+ return await Lt(e, t, async (n) => await xt(s(n)));
48
48
  }
49
- function lt(e, t, s) {
49
+ function Lt(e, t, s) {
50
50
  return new Promise((n, r) => {
51
- const i = e.transaction(et, t), o = i.objectStore(et);
52
- let l, u = !1;
51
+ const i = e.transaction(Mt, t), o = i.objectStore(Mt);
52
+ let a, u = !1;
53
53
  s(o).then((c) => {
54
- l = c;
54
+ a = c;
55
55
  }).catch((c) => {
56
56
  u = !0;
57
57
  try {
@@ -60,7 +60,7 @@ function lt(e, t, s) {
60
60
  }
61
61
  r(c);
62
62
  }), i.oncomplete = () => {
63
- u || n(l);
63
+ u || n(a);
64
64
  }, i.onerror = () => {
65
65
  u || (u = !0, r(i.error ?? new Error("Product Agent attachment storage transaction failed")));
66
66
  }, i.onabort = () => {
@@ -68,16 +68,16 @@ function lt(e, t, s) {
68
68
  };
69
69
  });
70
70
  }
71
- function ut(e) {
71
+ function xt(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
- function de(e) {
76
+ function Qe(e) {
77
77
  return e !== null && (typeof e == "object" || typeof e == "function");
78
78
  }
79
- function Ht(e, t, s) {
80
- const n = Reflect.get(e, "pluno"), r = de(n) ? n : {};
79
+ function Bt(e, t, s) {
80
+ const n = Reflect.get(e, "pluno"), r = Qe(n) ? n : {};
81
81
  if (r !== n && !Reflect.set(e, "pluno", r))
82
82
  return null;
83
83
  const i = Object.getOwnPropertyDescriptor(r, t);
@@ -91,11 +91,11 @@ function Ht(e, t, s) {
91
91
  }
92
92
  };
93
93
  }
94
- const J = "pluno.productAgent.transportId", he = "pluno.productAgent.transportIdentity", V = "pluno.productAgent.transportIdentity.event", pe = 50, fe = globalThis.setTimeout.bind(globalThis);
95
- let P = null;
96
- const x = /* @__PURE__ */ new Set();
97
- async function ge(e = Wt()) {
98
- const t = e.randomUUID(), s = e.storage.getItem(J);
94
+ const wt = "pluno.productAgent.transportId", ts = "pluno.productAgent.transportIdentity", At = "pluno.productAgent.transportIdentity.event", es = 50, ss = globalThis.setTimeout.bind(globalThis);
95
+ let F = null;
96
+ const tt = /* @__PURE__ */ new Set(), St = /* @__PURE__ */ new Map();
97
+ async function ns(e = be()) {
98
+ const t = e.randomUUID(), s = e.storage.getItem(wt);
99
99
  let n = s ?? e.randomUUID(), r = !1, i = !1;
100
100
  const o = e.channel.subscribe((u) => {
101
101
  if (!(u.senderId === t || u.transportId !== n)) {
@@ -113,58 +113,76 @@ async function ge(e = Wt()) {
113
113
  }
114
114
  });
115
115
  if (!s)
116
- e.storage.setItem(J, n), r = !0;
116
+ e.storage.setItem(wt, n), r = !0;
117
117
  else
118
118
  for (; ; ) {
119
119
  if (i = !1, e.channel.postMessage({ type: "probe", transportId: n, senderId: t }), await e.settle(), !i) {
120
120
  r = !0;
121
121
  break;
122
122
  }
123
- n = e.randomUUID(), e.storage.setItem(J, n);
123
+ n = e.randomUUID(), e.storage.setItem(wt, n);
124
124
  }
125
- let l = !1;
125
+ let a = !1;
126
126
  return {
127
127
  transportId: n,
128
128
  release: () => {
129
- l || (l = !0, o(), e.channel.close());
129
+ a || (a = !0, o(), e.channel.close());
130
130
  }
131
131
  };
132
132
  }
133
- async function me() {
134
- P || (P = ge(Wt()), P.then((n) => {
133
+ async function rs() {
134
+ F || (F = ns(be()), F.then((n) => {
135
135
  const r = (i) => {
136
- i.persisted || (n.release(), P = null, x.clear(), window.removeEventListener("pagehide", r));
136
+ i.persisted || (n.release(), F = null, tt.clear(), window.removeEventListener("pagehide", r));
137
137
  };
138
138
  window.addEventListener("pagehide", r);
139
139
  }));
140
- const e = await P, t = ye();
141
- x.add(t);
140
+ const e = await F, t = is();
141
+ tt.add(t);
142
142
  let s = !1;
143
143
  return {
144
144
  // A stable per-tab base keeps reload routing intact, while slots isolate multiple live SDK instances in one tab.
145
145
  transportId: t === 0 ? e.transportId : `${e.transportId}.${t}`,
146
146
  release: () => {
147
- s || (s = !0, x.delete(t));
147
+ s || (s = !0, tt.delete(t));
148
148
  }
149
149
  };
150
150
  }
151
- function ye() {
151
+ function is() {
152
152
  let e = 0;
153
- for (; x.has(e); )
153
+ for (; tt.has(e); )
154
154
  e += 1;
155
155
  return e;
156
156
  }
157
- function Wt() {
157
+ function be() {
158
158
  return {
159
- storage: window.sessionStorage,
160
- channel: Ie(),
159
+ storage: os(),
160
+ channel: as(),
161
161
  randomUUID: () => crypto.randomUUID(),
162
- settle: () => new Promise((e) => fe(e, pe))
162
+ settle: () => new Promise((e) => ss(e, es))
163
163
  };
164
164
  }
165
- function Ie() {
165
+ function os() {
166
+ return {
167
+ getItem: (e) => {
168
+ try {
169
+ return window.sessionStorage?.getItem(e) ?? St.get(e) ?? null;
170
+ } catch {
171
+ return St.get(e) ?? null;
172
+ }
173
+ },
174
+ setItem: (e, t) => {
175
+ St.set(e, t);
176
+ try {
177
+ window.sessionStorage?.setItem(e, t);
178
+ } catch {
179
+ }
180
+ }
181
+ };
182
+ }
183
+ function as() {
166
184
  if (typeof BroadcastChannel < "u") {
167
- const e = new BroadcastChannel(he);
185
+ const e = new BroadcastChannel(ts);
168
186
  return {
169
187
  postMessage: (t) => e.postMessage(t),
170
188
  subscribe: (t) => {
@@ -174,11 +192,11 @@ function Ie() {
174
192
  close: () => e.close()
175
193
  };
176
194
  }
177
- return Te();
195
+ return cs();
178
196
  }
179
- function Te() {
197
+ function cs() {
180
198
  const e = /* @__PURE__ */ new Set(), t = (s) => {
181
- if (s.key !== V || !s.newValue)
199
+ if (s.key !== At || !s.newValue)
182
200
  return;
183
201
  const n = JSON.parse(s.newValue);
184
202
  for (const r of e)
@@ -187,9 +205,9 @@ function Te() {
187
205
  return window.addEventListener("storage", t), {
188
206
  postMessage: (s) => {
189
207
  window.localStorage.setItem(
190
- V,
208
+ At,
191
209
  JSON.stringify({ ...s, eventId: crypto.randomUUID() })
192
- ), window.localStorage.removeItem(V);
210
+ ), window.localStorage.removeItem(At);
193
211
  },
194
212
  subscribe: (s) => (e.add(s), () => e.delete(s)),
195
213
  close: () => {
@@ -197,18 +215,18 @@ function Te() {
197
215
  }
198
216
  };
199
217
  }
200
- const st = '.pluno-pa-widget-host[data-pluno-product-agent-ui="widget"]', we = '.pluno-pa-widget[data-pluno-product-agent-ui-root="widget"]', Ae = ".pluno-pa-widget__panel", Se = ".pluno-pa-widget__timeline", wt = `${st}[data-pluno-sdk-preview-channel]`, ke = "https://app.pluno.ai", Ee = "gpt-5.6-terra", Re = 2e4, _e = 1e4, be = 1e4, Me = 1e4, Ce = 1e4, Pe = 1e3, At = 3e4, St = 0.2, kt = 6e4, Ue = 15e3, L = 8, De = 15e3, Ne = 2e3, Oe = 1e3, Le = 100, Be = 8e3, ve = 15e3, Et = 3, qe = [300, 1e3], dt = 64e3, Y = 4e3, ht = 30, xe = 2e3, Fe = 1e3, He = 200 * 1024 * 1024, pt = "Image is too large for model vision input.", We = 100, jt = "pluno.productAgent.state.", nt = "pluno.productAgent.pendingEvents.", z = "pluno.productAgent.activeToolCalls.", je = 100;
201
- function B(e, t = 0) {
218
+ const Ct = '.pluno-pa-widget-host[data-pluno-product-agent-ui="widget"]', ls = '.pluno-pa-widget[data-pluno-product-agent-ui-root="widget"]', us = ".pluno-pa-widget__panel", ds = ".pluno-pa-widget__timeline", ne = `${Ct}[data-pluno-sdk-preview-channel]`, hs = "https://app.pluno.ai", ps = "gpt-5.6-terra", fs = 2e4, gs = 1e4, ms = 1e4, ys = 1e4, Ts = 1e4, Is = 1e3, re = 3e4, ie = 0.2, oe = 6e4, ws = 15e3, K = 8, As = 15e3, Ss = 2e3, Es = 1e3, ks = 100, bs = 8e3, Rs = 15e3, ae = 3, _s = [300, 1e3], qt = 64e3, Et = 4e3, Ht = 30, Ms = 2e3, Cs = 1e3, Ps = 200 * 1024 * 1024, Ft = "Image is too large for model vision input.", Us = 100, Re = "pluno.productAgent.state.", Pt = "pluno.productAgent.pendingEvents.", ot = "pluno.productAgent.activeToolCalls.", Ds = 100;
219
+ function V(e, t = 0) {
202
220
  const s = e === 0 ? 0 : Math.min(3e4, 1e3 * 2 ** (e - 1));
203
221
  return Math.max(t, s);
204
222
  }
205
- const F = /* @__PURE__ */ new Set();
206
- let v = null;
207
- function $e(e, t = Math.random) {
208
- const s = Math.min(At, Pe * 2 ** e), n = 1 - St + t() * St * 2;
209
- return Math.min(At, Math.round(s * n));
223
+ const et = /* @__PURE__ */ new Set();
224
+ let Y = null;
225
+ function Ns(e, t = Math.random) {
226
+ const s = Math.min(re, Is * 2 ** e), n = 1 - ie + t() * ie * 2;
227
+ return Math.min(re, Math.round(s * n));
210
228
  }
211
- function ze(e, t, s) {
229
+ function Os(e, t, s) {
212
230
  return new Promise((n, r) => {
213
231
  const i = setTimeout(() => r(new Error(s)), t);
214
232
  e.then(
@@ -221,13 +239,13 @@ function ze(e, t, s) {
221
239
  );
222
240
  });
223
241
  }
224
- class $t {
242
+ class _e {
225
243
  constructor(t, s) {
226
244
  this.options = t, this.transportIdentity = s, this.state = {
227
245
  ...this.state,
228
- starterPrompts: Is(t.initialStarterPrompts)
246
+ starterPrompts: pn(t.initialStarterPrompts)
229
247
  };
230
- const n = t.restorePersistedState === !1 ? null : tn(t.clientId, t.expectedPersistedSessionId);
248
+ const n = t.restorePersistedState === !1 ? null : Yn(t.clientId, t.expectedPersistedSessionId);
231
249
  n && (this.state = {
232
250
  ...this.state,
233
251
  ...n,
@@ -240,10 +258,10 @@ class $t {
240
258
  assistantDraftRunId: null,
241
259
  isThinking: !1,
242
260
  lastError: null
243
- }), this.queuedClientEvents = cn(
244
- sn(t.clientId),
245
- rn(t.clientId)
246
- ), U(t.clientId, this.queuedClientEvents);
261
+ }), this.queuedClientEvents = rr(
262
+ Qn(t.clientId),
263
+ er(t.clientId)
264
+ ), W(t.clientId, this.queuedClientEvents);
247
265
  }
248
266
  options;
249
267
  listeners = {};
@@ -275,6 +293,7 @@ class $t {
275
293
  activeClientMessageId = null;
276
294
  activeUserMessageEvent = null;
277
295
  latestRecoverableClientMessageId = null;
296
+ lastUserMessagePageUrl = null;
278
297
  thinkingWatchdogResyncAttemptsByClientMessageId = {};
279
298
  retryableClientMessageId = null;
280
299
  runtimeHelperJavascript = null;
@@ -307,15 +326,15 @@ class $t {
307
326
  lastErrorSecuritySettingsUrl: null
308
327
  };
309
328
  static async init(t) {
310
- const s = await me(), n = new $t({
329
+ const s = await rs(), n = new _e({
311
330
  ...t,
312
- backendUrl: ls(t.backendUrl ?? ke),
313
- clientId: t.clientId ?? ks(),
314
- model: t.model ?? Ee
331
+ backendUrl: Qs(t.backendUrl ?? hs),
332
+ clientId: t.clientId ?? Tn(),
333
+ model: t.model ?? ps
315
334
  }, s);
316
335
  try {
317
- ue().catch((r) => {
318
- f("web-sdk.attachments", "Failed to delete stale Product Agent attachments", {
336
+ Ze().catch((r) => {
337
+ I("web-sdk.attachments", "Failed to delete stale Product Agent attachments", {
319
338
  message: r instanceof Error ? r.message : String(r)
320
339
  });
321
340
  }), t.disableNetworkCapture || n.enableNetworkCapture(), n.startPageLifecycleRecovery(), n.startStarterPromptUrlWatcher(), t.autoConnect !== !1 && await n.connect();
@@ -346,15 +365,15 @@ class $t {
346
365
  lastError: null
347
366
  });
348
367
  try {
349
- if (this.token = this.options.token ?? (this.options.tokenProvider ? await ze(this.options.tokenProvider(), be, "Pluno token provider timed out") : null), t !== this.connectionAttemptId || this.state.status === "closed")
368
+ if (this.token = this.options.token ?? (this.options.tokenProvider ? await Os(this.options.tokenProvider(), ms, "Pluno token provider timed out") : null), t !== this.connectionAttemptId || this.state.status === "closed")
350
369
  return;
351
370
  if (!this.token && !this.options.webSocketFactory)
352
371
  throw new Error("Pluno requires a token or tokenProvider");
353
- const s = ds(this.options.backendUrl), n = this.options.webSocketFactory?.(s) ?? new WebSocket(s);
372
+ const s = en(this.options.backendUrl), n = this.options.webSocketFactory?.(s) ?? new WebSocket(s);
354
373
  this.socket = n, this.socketConnectTimer = window.setTimeout(() => {
355
- this.socket === n && n.readyState === WebSocket.CONNECTING && (f("web-sdk.agent", "Pluno socket opening timed out; reconnecting"), this.replaceTimedOutSocket(n));
356
- }, Me), n.addEventListener("open", () => {
357
- this.socket !== n || (this.clearSocketConnectTimer(), f("web-sdk.agent", "Pluno socket opened", {
374
+ this.socket === n && n.readyState === WebSocket.CONNECTING && (I("web-sdk.agent", "Pluno socket opening timed out; reconnecting"), this.replaceTimedOutSocket(n));
375
+ }, ys), n.addEventListener("open", () => {
376
+ this.socket !== n || (this.clearSocketConnectTimer(), I("web-sdk.agent", "Pluno socket opened", {
358
377
  queuedClientEventCount: this.queuedClientEvents.length,
359
378
  isThinking: this.state.isThinking
360
379
  }), !(this.token ? this.sendNow({
@@ -364,12 +383,12 @@ class $t {
364
383
  transportId: this.transportIdentity.transportId,
365
384
  pageUrl: location.href
366
385
  }) : !0)) || (this.socketAuthTimer = window.setTimeout(() => {
367
- this.socket === n && (f("web-sdk.agent", "Pluno socket authentication timed out; reconnecting"), this.replaceTimedOutSocket(n));
368
- }, Ce));
386
+ this.socket === n && (I("web-sdk.agent", "Pluno socket authentication timed out; reconnecting"), this.replaceTimedOutSocket(n));
387
+ }, Ts));
369
388
  }), n.addEventListener("message", (r) => {
370
- this.socket === n && this.handleServerEvent(ys(r.data));
389
+ this.socket === n && this.handleServerEvent(hn(r.data));
371
390
  }), n.addEventListener("close", (r) => {
372
- this.socket === n && (this.clearSocketPhaseTimers(), this.stopHeartbeat(), this.socket = null, this.state.status !== "closed" && (f("web-sdk.agent", "Pluno socket closed; scheduling reconnect", {
391
+ this.socket === n && (this.clearSocketPhaseTimers(), this.stopHeartbeat(), this.socket = null, this.state.status !== "closed" && (I("web-sdk.agent", "Pluno socket closed; scheduling reconnect", {
373
392
  code: typeof r?.code == "number" ? r.code : null,
374
393
  reason: typeof r?.reason == "string" ? r.reason : "",
375
394
  wasClean: typeof r?.wasClean == "boolean" ? r.wasClean : null,
@@ -377,7 +396,7 @@ class $t {
377
396
  isThinking: this.state.isThinking
378
397
  }), this.setState({ status: "reconnecting", lastError: null }), this.scheduleReconnect()));
379
398
  }), n.addEventListener("error", () => {
380
- this.socket !== n || this.state.status === "closed" || (f("web-sdk.agent", "Pluno socket error; scheduling reconnect", {
399
+ this.socket !== n || this.state.status === "closed" || (I("web-sdk.agent", "Pluno socket error; scheduling reconnect", {
381
400
  queuedClientEventCount: this.queuedClientEvents.length,
382
401
  isThinking: this.state.isThinking
383
402
  }), this.clearSocketPhaseTimers(), this.stopHeartbeat(), this.socket = null, this.setState({ status: "reconnecting", lastError: null }), this.scheduleReconnect(), n.readyState !== WebSocket.CLOSED && n.readyState !== WebSocket.CLOSING && n.close());
@@ -400,23 +419,23 @@ class $t {
400
419
  this.connectionAttemptId += 1, this.setState({ status: "closed", isThinking: !1 }), this.clearSocketPhaseTimers(), 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;
401
420
  }
402
421
  destroy() {
403
- this.disconnect(), this.locationChangeCleanup?.(), this.locationChangeCleanup = null, this.cleanupSessionUserFilesApi(), this.pageLifecycleCleanup?.(), this.pageLifecycleCleanup = null, this.activeBrowserToolCalls.clear(), ln(this.options.clientId), this.transportIdentity.release(), this.networkCaptureCleanup?.(), this.networkCaptureCleanup = null, this.networkBatchTimer !== null && (window.clearTimeout(this.networkBatchTimer), this.networkBatchTimer = null), this.queuedNetworkEvents = [];
422
+ this.disconnect(), this.locationChangeCleanup?.(), this.locationChangeCleanup = null, this.cleanupSessionUserFilesApi(), this.pageLifecycleCleanup?.(), this.pageLifecycleCleanup = null, this.activeBrowserToolCalls.clear(), ir(this.options.clientId), this.transportIdentity.release(), this.networkCaptureCleanup?.(), this.networkCaptureCleanup = null, this.networkBatchTimer !== null && (window.clearTimeout(this.networkBatchTimer), this.networkBatchTimer = null), this.queuedNetworkEvents = [];
404
423
  for (const t of Object.values(this.listeners))
405
424
  t?.clear();
406
425
  }
407
426
  sendMessage(t, s = {}) {
408
- const n = t.trim(), r = s.attachments ?? [], i = r.map(It);
427
+ const n = t.trim(), r = s.attachments ?? [], i = r.map(Gt);
409
428
  if (!n && i.length === 0)
410
429
  return null;
411
- const o = w(), l = s.clientMessageId ?? q();
430
+ const o = R(), a = s.clientMessageId ?? Q();
412
431
  this.retryableClientMessageId = null;
413
432
  const u = {
414
- id: `local-${l}`,
433
+ id: `local-${a}`,
415
434
  role: "user",
416
435
  content: n,
417
436
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
418
437
  ...r.length > 0 ? { attachments: r } : {}
419
- }, c = this.state.messages.some((h) => h.id === u.id || h.clientMessageId === l);
438
+ }, c = this.state.messages.some((f) => f.id === u.id || f.clientMessageId === a);
420
439
  this.setState({
421
440
  messages: c ? this.state.messages : [...this.state.messages, u],
422
441
  ...this.state.isThinking ? {} : {
@@ -429,44 +448,45 @@ class $t {
429
448
  isThinking: !0,
430
449
  lastError: null
431
450
  }), c || this.emit("message", u);
432
- const a = {
451
+ const l = !s.initiatedBy && this.options.capturePageContent !== !1 && this.lastUserMessagePageUrl !== o.url, h = {
433
452
  type: "chat.user_message",
434
453
  sessionId: this.state.sessionId ?? void 0,
435
- clientMessageId: l,
454
+ clientMessageId: a,
436
455
  initiatedBy: s.initiatedBy,
437
456
  content: n,
457
+ pageContent: l && Wt() || void 0,
438
458
  attachments: i.length > 0 ? i : void 0,
439
459
  page: o,
440
460
  model: this.options.model,
441
- metadata: Rt(this.options.metadata)
461
+ metadata: ce(this.options.metadata)
442
462
  };
443
- return this.activeClientMessageId = l, this.activeUserMessageEvent = a, this.markThinkingProgress(), this.send(a), this.startBackgroundAttachmentUploads(l, i), l;
463
+ return s.initiatedBy || (this.lastUserMessagePageUrl = o.url), this.activeClientMessageId = a, this.activeUserMessageEvent = h, this.markThinkingProgress(), this.send(h), this.startBackgroundAttachmentUploads(a, i), a;
444
464
  }
445
465
  retryLastMessage() {
446
466
  const t = this.state.sessionId, s = this.retryableClientMessageId;
447
467
  return !t || !s ? !1 : (this.retryAttemptsByClientMessageId[s] = 0, this.retryableClientMessageId = null, this.activeClientMessageId = s, this.latestRecoverableClientMessageId = s, this.setState({ status: "connected", isThinking: !0, lastError: null, lastErrorCode: null }), this.markThinkingProgress(), this.send({ type: "chat.retry_last_user_message", sessionId: t, clientMessageId: s, automatic: !1 }), !0);
448
468
  }
449
469
  createLocalAttachment(t) {
450
- const s = q(), n = {
470
+ const s = Q(), n = {
451
471
  id: s,
452
472
  name: t.name || "attachment",
453
- mimeType: Lt(t),
473
+ mimeType: Ie(t),
454
474
  sizeBytes: t.size
455
475
  };
456
476
  this.attachmentFiles.set(s, t), this.attachmentBlobCache.set(s, t);
457
477
  const r = Date.now();
458
- return qt({
478
+ return Se({
459
479
  attachmentId: s,
460
480
  name: n.name,
461
481
  mimeType: n.mimeType,
462
482
  sizeBytes: n.sizeBytes,
463
483
  blob: t,
464
- origin: w().origin,
484
+ origin: R().origin,
465
485
  sessionId: this.state.sessionId ?? void 0,
466
486
  createdAt: r,
467
487
  lastUsedAt: r
468
488
  }).catch((i) => {
469
- f("web-sdk.attachments", "Failed to store Product Agent attachment", {
489
+ I("web-sdk.attachments", "Failed to store Product Agent attachment", {
470
490
  attachmentId: s,
471
491
  name: n.name,
472
492
  message: i instanceof Error ? i.message : String(i)
@@ -478,7 +498,7 @@ class $t {
478
498
  return await this.uploadAttachmentForMessage({
479
499
  file: t,
480
500
  attachment: s,
481
- clientMessageId: q(),
501
+ clientMessageId: Q(),
482
502
  waitForSession: !1,
483
503
  notifyCompletion: !1
484
504
  });
@@ -495,7 +515,7 @@ class $t {
495
515
  waitForSession: !0,
496
516
  notifyCompletion: !0
497
517
  }).catch((i) => {
498
- f("web-sdk.agent", "Attachment background upload failed", {
518
+ I("web-sdk.agent", "Attachment background upload failed", {
499
519
  attachmentId: n.id,
500
520
  name: n.name,
501
521
  message: i instanceof Error ? i.message : String(i)
@@ -510,55 +530,55 @@ class $t {
510
530
  waitForSession: r,
511
531
  notifyCompletion: i
512
532
  }) {
513
- const o = r ? await this.waitForSessionId() : this.state.sessionId, l = Lt(t), u = {
533
+ const o = r ? await this.waitForSessionId() : this.state.sessionId, a = Ie(t), u = {
514
534
  sessionId: o ?? void 0,
515
535
  attachmentId: s.id,
516
536
  clientId: this.options.clientId,
517
537
  transportId: this.transportIdentity.transportId,
518
538
  name: t.name || "attachment",
519
- mimeType: l,
539
+ mimeType: a,
520
540
  sizeBytes: t.size,
521
- page: w(),
541
+ page: R(),
522
542
  model: this.options.model,
523
- metadata: Rt(this.options.metadata)
524
- }, c = this.options.prepareAttachmentUpload ? await tt(
543
+ metadata: ce(this.options.metadata)
544
+ }, c = this.options.prepareAttachmentUpload ? await _t(
525
545
  () => this.options.prepareAttachmentUpload(u),
526
546
  "Failed to prepare attachment upload"
527
547
  ) : await this.prepareEmbedAttachmentUpload(u);
528
- await tt(async () => {
548
+ await _t(async () => {
529
549
  const h = await fetch(c.uploadUrl, {
530
550
  method: c.uploadMethod,
531
551
  headers: c.uploadHeaders,
532
552
  body: t
533
553
  });
534
554
  if (!h.ok)
535
- throw new H("Failed to upload attachment", h.status);
555
+ throw new st("Failed to upload attachment", h.status);
536
556
  return h;
537
557
  }, "Failed to upload attachment"), this.setState({ sessionId: c.sessionId });
538
- const a = Qt(c.attachment, this.options.backendUrl);
539
- return this.updateAttachmentInState(s.id, a), s.id && xt(s.id, {
558
+ const l = qe(c.attachment, this.options.backendUrl);
559
+ return this.updateAttachmentInState(s.id, l), s.id && Ee(s.id, {
540
560
  sessionId: c.sessionId,
541
- fileUrl: a.fileUrl,
542
- gcsPath: a.gcsPath,
561
+ fileUrl: l.fileUrl,
562
+ gcsPath: l.gcsPath,
543
563
  lastUsedAt: Date.now()
544
564
  }).catch((h) => {
545
- f("web-sdk.attachments", "Failed to update persisted Product Agent attachment", {
565
+ I("web-sdk.attachments", "Failed to update persisted Product Agent attachment", {
546
566
  attachmentId: s.id,
547
- name: a.name,
567
+ name: l.name,
548
568
  message: h instanceof Error ? h.message : String(h)
549
569
  });
550
- }), i && a.gcsPath && this.send({
570
+ }), i && l.gcsPath && this.send({
551
571
  type: "attachment.upload_completed",
552
572
  sessionId: c.sessionId,
553
573
  clientMessageId: n,
554
- attachment: a
555
- }), a;
574
+ attachment: l
575
+ }), l;
556
576
  }
557
577
  waitForSessionId() {
558
578
  return this.state.sessionId ? Promise.resolve(this.state.sessionId) : new Promise((t, s) => {
559
579
  const n = window.setTimeout(() => {
560
580
  r(), s(new Error("Timed out waiting for Pluno session before persisting attachment"));
561
- }, ve), r = this.on("state", (i) => {
581
+ }, Rs), r = this.on("state", (i) => {
562
582
  i.sessionId && (window.clearTimeout(n), r(), t(i.sessionId));
563
583
  });
564
584
  });
@@ -576,18 +596,18 @@ class $t {
576
596
  }
577
597
  async prepareEmbedAttachmentUpload(t) {
578
598
  let s = !1;
579
- return await tt(async () => {
599
+ return await _t(async () => {
580
600
  const n = await this.fetchEmbedAttachmentUpload(t);
581
601
  if (n.ok)
582
602
  return await n.json();
583
- if (bn(n.status) && this.options.tokenProvider && !s) {
603
+ if (Er(n.status) && this.options.tokenProvider && !s) {
584
604
  s = !0;
585
605
  const r = await this.fetchEmbedAttachmentUpload(t);
586
606
  if (r.ok)
587
607
  return await r.json();
588
- throw new H("Failed to prepare attachment upload", r.status);
608
+ throw new st("Failed to prepare attachment upload", r.status);
589
609
  }
590
- throw new H("Failed to prepare attachment upload", n.status);
610
+ throw new st("Failed to prepare attachment upload", n.status);
591
611
  }, "Failed to prepare attachment upload");
592
612
  }
593
613
  async fetchEmbedAttachmentUpload(t) {
@@ -606,10 +626,10 @@ class $t {
606
626
  }
607
627
  startNewSession(t = {}) {
608
628
  const s = t.notifyTransport !== !1;
609
- !this.options.keepRunsActiveOnSessionNavigation && s && this.state.sessionId && this.state.isThinking && this.send({ type: "run.stop", sessionId: this.state.sessionId, reason: "new_chat" }), this.cleanupSessionUserFilesApi(), this.queuedClientEvents = this.queuedClientEvents.filter((n) => n.type !== "chat.user_message"), this.clearThinkingWatchdog(), this.retryableClientMessageId = null, this.retryAttemptsByClientMessageId = {}, this.thinkingWatchdogResyncAttemptsByClientMessageId = {}, s && this.send({
629
+ !this.options.keepRunsActiveOnSessionNavigation && s && this.state.sessionId && this.state.isThinking && this.send({ type: "run.stop", sessionId: this.state.sessionId, reason: "new_chat" }), this.cleanupSessionUserFilesApi(), this.queuedClientEvents = this.queuedClientEvents.filter((n) => n.type !== "chat.user_message"), this.clearThinkingWatchdog(), this.retryableClientMessageId = null, this.lastUserMessagePageUrl = null, this.retryAttemptsByClientMessageId = {}, this.thinkingWatchdogResyncAttemptsByClientMessageId = {}, s && this.send({
610
630
  type: "session.reset",
611
631
  sessionId: this.state.sessionId ?? void 0,
612
- page: w()
632
+ page: R()
613
633
  }), this.setState({
614
634
  sessionId: null,
615
635
  starterPrompts: [...this.state.starterPrompts],
@@ -624,15 +644,15 @@ class $t {
624
644
  });
625
645
  }
626
646
  listSessions(t = {}) {
627
- const s = q(), n = new Promise((i, o) => {
628
- const l = window.setTimeout(() => {
647
+ const s = Q(), n = new Promise((i, o) => {
648
+ const a = window.setTimeout(() => {
629
649
  this.pendingSessionHistoryRequests.delete(s), o(new Error("Session history did not respond in time"));
630
- }, Be);
631
- this.pendingSessionHistoryRequests.set(s, { resolve: i, reject: o, timeout: l });
650
+ }, bs);
651
+ this.pendingSessionHistoryRequests.set(s, { resolve: i, reject: o, timeout: a });
632
652
  }), r = {
633
653
  type: "sessions.list",
634
654
  requestId: s,
635
- page: w(),
655
+ page: R(),
636
656
  ...t.cursor ? { cursor: t.cursor } : {},
637
657
  ...t.limit ? { limit: t.limit } : {}
638
658
  };
@@ -643,7 +663,7 @@ class $t {
643
663
  return n;
644
664
  }
645
665
  loadSession(t) {
646
- !this.options.keepRunsActiveOnSessionNavigation && this.state.sessionId && this.state.isThinking && this.send({ type: "run.stop", sessionId: this.state.sessionId, reason: "session_switch" }), this.clearThinkingWatchdog(), this.setState({
666
+ !this.options.keepRunsActiveOnSessionNavigation && this.state.sessionId && this.state.isThinking && this.send({ type: "run.stop", sessionId: this.state.sessionId, reason: "session_switch" }), this.clearThinkingWatchdog(), this.lastUserMessagePageUrl = null, this.setState({
647
667
  sessionId: t,
648
668
  assistantDraft: "",
649
669
  assistantDraftItemId: null,
@@ -656,11 +676,11 @@ class $t {
656
676
  }), this.send({
657
677
  type: "session.load",
658
678
  sessionId: t,
659
- page: w()
679
+ page: R()
660
680
  });
661
681
  }
662
682
  send(t) {
663
- this.sendNow(A(t)) || (this.queuedClientEvents.push(t), U(this.options.clientId, this.queuedClientEvents), this.setState({ status: "reconnecting" }), this.scheduleReconnect());
683
+ this.sendNow(_(t)) || (this.queuedClientEvents.push(t), W(this.options.clientId, this.queuedClientEvents), this.setState({ status: "reconnecting" }), this.scheduleReconnect());
664
684
  }
665
685
  async getUploadToken() {
666
686
  const t = this.options.token ?? await this.options.tokenProvider?.() ?? this.token ?? null;
@@ -675,7 +695,7 @@ class $t {
675
695
  try {
676
696
  return s.send(JSON.stringify(t)), !0;
677
697
  } catch (n) {
678
- return f("web-sdk.agent", "Pluno socket send failed; scheduling reconnect", {
698
+ return I("web-sdk.agent", "Pluno socket send failed; scheduling reconnect", {
679
699
  message: n instanceof Error ? n.message : String(n),
680
700
  queuedClientEventCount: this.queuedClientEvents.length,
681
701
  isThinking: this.state.isThinking
@@ -686,9 +706,9 @@ class $t {
686
706
  if (this.state.starterPromptsLoading || this.transientStarterPromptsRequestInFlight || this.transientStarterPromptsRequestAttempted)
687
707
  return;
688
708
  this.transientStarterPromptsRequestInFlight = !0, this.transientStarterPromptsRequestAttempted = !0, this.setState({ starterPromptsLoading: !0 });
689
- const t = hs();
709
+ const t = sn();
690
710
  this.sendNow(
691
- A({
711
+ _({
692
712
  type: "starter_prompts.page_context",
693
713
  pageUrl: t.pageUrl,
694
714
  pageTitle: t.pageTitle,
@@ -697,13 +717,13 @@ class $t {
697
717
  ) || (this.transientStarterPromptsRequestInFlight = !1, this.transientStarterPromptsRequestAttempted = !1, this.setState({ starterPromptsLoading: !1 }));
698
718
  }
699
719
  startStarterPromptUrlWatcher() {
700
- this.locationChangeCleanup || (this.locationChangeCleanup = ps(() => this.handleStarterPromptUrlChange()));
720
+ this.locationChangeCleanup || (this.locationChangeCleanup = nn(() => this.handleStarterPromptUrlChange()));
701
721
  }
702
722
  handleStarterPromptUrlChange() {
703
723
  const t = location.href;
704
724
  t !== this.lastStarterPromptPageUrl && (this.lastStarterPromptPageUrl = t, this.clearStarterPromptUrlRefreshTimer(), this.starterPromptUrlRefreshTimer = window.setTimeout(() => {
705
725
  this.starterPromptUrlRefreshTimer = null, this.refreshStarterPromptsForCurrentUrl();
706
- }, je));
726
+ }, Ds));
707
727
  }
708
728
  refreshStarterPromptsForCurrentUrl() {
709
729
  this.socket?.readyState !== WebSocket.OPEN || this.state.status === "closed" || (this.setState({ starterPromptsLoading: this.state.messages.length === 0 }), this.sendNow({
@@ -718,14 +738,14 @@ class $t {
718
738
  if (this.socket?.readyState !== WebSocket.OPEN || this.queuedClientEvents.length === 0)
719
739
  return;
720
740
  const t = this.queuedClientEvents.splice(0, this.queuedClientEvents.length);
721
- U(this.options.clientId, this.queuedClientEvents);
741
+ W(this.options.clientId, this.queuedClientEvents);
722
742
  for (let s = 0; s < t.length; s += 1) {
723
743
  const n = t[s];
724
- if (!this.sendNow(A(n))) {
725
- this.queuedClientEvents.unshift(n, ...t.slice(s + 1)), U(this.options.clientId, this.queuedClientEvents);
744
+ if (!this.sendNow(_(n))) {
745
+ this.queuedClientEvents.unshift(n, ...t.slice(s + 1)), W(this.options.clientId, this.queuedClientEvents);
726
746
  return;
727
747
  }
728
- U(this.options.clientId, this.queuedClientEvents);
748
+ W(this.options.clientId, this.queuedClientEvents);
729
749
  }
730
750
  }
731
751
  handleServerEvent(t) {
@@ -737,104 +757,116 @@ class $t {
737
757
  this.clearHeartbeatAckTimer();
738
758
  return;
739
759
  }
740
- if (Ke(t) && this.markThinkingProgress(), t.type === "auth.ok") {
760
+ if (xs(t) && this.markThinkingProgress(), t.type === "auth.ok") {
741
761
  this.clearSocketAuthTimer(), this.reconnectAttempts = 0, this.flushQueuedClientEvents(), this.startHeartbeat();
742
- const s = Ts(t), n = Object.prototype.hasOwnProperty.call(t, "appearance");
743
- f("web-sdk.agent", "Received auth.ok appearance", {
762
+ const s = fn(t), n = Object.prototype.hasOwnProperty.call(t, "appearance");
763
+ I("web-sdk.agent", "Received auth.ok appearance", {
744
764
  hasAppearance: n,
745
765
  rawAppearance: t.appearance,
746
766
  normalizedAppearance: s
747
- }), this.runtimeHelperJavascript = ws(t.runtimeHelpers)?.javascript ?? null;
748
- const r = bt(t, "starterPrompts"), i = Object.prototype.hasOwnProperty.call(t, "starterPrompts"), o = t.starterPromptsLoading === !0, l = {
749
- user: Es(t.user),
767
+ }), this.runtimeHelperJavascript = gn(t.runtimeHelpers)?.javascript ?? null;
768
+ const r = de(t, "starterPrompts"), i = Object.prototype.hasOwnProperty.call(t, "starterPrompts"), o = t.starterPromptsLoading === !0, a = {
769
+ user: In(t.user),
750
770
  status: "connected"
751
771
  };
752
- (i || this.state.starterPrompts.length === 0) && (l.starterPrompts = r, l.starterPromptsLoading = r.length > 0 ? !1 : o), i && r.length > 0 && (this.transientStarterPromptsRequestInFlight = !1, this.transientStarterPromptsRequestAttempted = !0), (n || s) && (l.appearance = s), this.setState(l), i && r.length === 0 && !o && !gs() && this.requestTransientStarterPrompts(), this.state.sessionId && this.send({
772
+ (i || this.state.starterPrompts.length === 0) && (a.starterPrompts = r, a.starterPromptsLoading = r.length > 0 ? !1 : o), i && r.length > 0 && (this.transientStarterPromptsRequestInFlight = !1, this.transientStarterPromptsRequestAttempted = !0), (n || s) && (a.appearance = s), this.setState(a), i && r.length === 0 && !o && !on() && this.requestTransientStarterPrompts(), this.state.sessionId && this.send({
753
773
  type: "page.upsert",
754
774
  sessionId: this.state.sessionId,
755
- page: w(),
775
+ page: R(),
756
776
  model: this.options.model
757
777
  });
758
778
  return;
759
779
  }
760
780
  if (t.type === "starterPrompts.updated") {
761
781
  this.transientStarterPromptsRequestInFlight = !1, this.transientStarterPromptsRequestAttempted = !0, this.setState({
762
- starterPrompts: bt(t, "starterPrompts"),
782
+ starterPrompts: de(t, "starterPrompts"),
763
783
  starterPromptsLoading: !1
764
784
  });
765
785
  return;
766
786
  }
767
787
  if (t.type === "conversation.state") {
768
- const s = Array.isArray(t.items) ? t.items : [];
788
+ const s = Array.isArray(t.items) ? t.items : [], n = _n(
789
+ t.assistantDraft
790
+ ), r = n !== void 0;
769
791
  this.rememberUserMessageClientMessageIds(s);
770
- const n = $s(s);
771
- if (n) {
772
- const a = zs(s, n);
773
- this.retryAttemptsByClientMessageId[n] = Math.max(
774
- this.retryAttemptsByClientMessageId[n] ?? 0,
775
- a
792
+ const i = Fn(s);
793
+ if (i) {
794
+ const d = Wn(s, i);
795
+ this.retryAttemptsByClientMessageId[i] = Math.max(
796
+ this.retryAttemptsByClientMessageId[i] ?? 0,
797
+ d
776
798
  );
777
799
  }
778
- const r = s.filter((a) => {
779
- const h = D(a);
780
- return !Ut(h) && (!n || !it(h));
781
- }), i = vs(
800
+ const o = s.filter((d) => {
801
+ const g = x(d);
802
+ return !ge(g) && (!i || !Dt(g));
803
+ }), a = Nn(
782
804
  this.state.messages,
783
- Rs(r, this.options.backendUrl)
784
- ), o = Pt(i), l = s.some(
785
- (a) => Nt(
786
- D(a),
805
+ wn(o, this.options.backendUrl)
806
+ ), u = fe(a), c = !r && s.some(
807
+ (d) => ye(
808
+ x(d),
787
809
  this.state.assistantDraft,
788
810
  this.state.assistantDraftItemId,
789
811
  this.state.assistantDraftRespondsToUserMessageId,
790
812
  this.state.assistantDraftRunId
791
813
  )
792
- ), u = o && (!this.state.assistantDraft || l);
793
- if (!o && js(this.state.messages, s))
814
+ ), l = r ? n?.content ?? "" : this.state.assistantDraft, h = !!n?.content, f = u && (!l || c);
815
+ if (!u && Hn(this.state.messages, s))
794
816
  return;
795
- const c = u ? null : ot(s);
796
- if (this.latestRecoverableClientMessageId = c, Hs(i) && this.clearRetryTimers(), this.setState({
797
- sessionId: T(t.session, "id") ?? this.state.sessionId,
798
- messages: i,
799
- ...l ? {
817
+ this.lastUserMessagePageUrl = qn(s);
818
+ const p = f ? null : Nt(s);
819
+ if (this.latestRecoverableClientMessageId = p, xn(a) && this.clearRetryTimers(), this.setState({
820
+ sessionId: E(t.session, "id") ?? this.state.sessionId,
821
+ messages: a,
822
+ ...r ? {
823
+ assistantDraft: n?.content ?? "",
824
+ assistantDraftItemId: n?.itemId ?? null,
825
+ assistantDraftPhase: n?.phase ?? null,
826
+ assistantDraftRespondsToUserMessageId: n?.respondsToUserMessageId ?? null,
827
+ assistantDraftRunId: n?.runId ?? null
828
+ } : c ? {
800
829
  assistantDraft: "",
801
830
  assistantDraftItemId: null,
802
831
  assistantDraftPhase: null,
803
832
  assistantDraftRespondsToUserMessageId: null,
804
833
  assistantDraftRunId: null
805
834
  } : {},
806
- ...u ? {
835
+ ...h ? {
836
+ isThinking: !0,
837
+ lastError: null
838
+ } : f ? {
807
839
  isThinking: !1
808
- } : c ? {
840
+ } : p ? {
809
841
  isThinking: !0,
810
842
  lastError: null
811
843
  } : {}
812
- }), u ? (this.retryableClientMessageId = null, this.clearThinkingWatchdog()) : c && (this.activeClientMessageId = c, this.markThinkingProgress()), n) {
813
- const a = T(t.session, "id") ?? this.state.sessionId;
814
- a && this.retryAfterInterruptedRun(a, n);
844
+ }), f ? (this.retryableClientMessageId = null, this.clearThinkingWatchdog()) : (h || p) && (p && (this.activeClientMessageId = p), this.markThinkingProgress()), i) {
845
+ const d = E(t.session, "id") ?? this.state.sessionId;
846
+ d && this.retryAfterInterruptedRun(d, i);
815
847
  }
816
848
  return;
817
849
  }
818
850
  if (t.type === "sessions.page") {
819
851
  const s = typeof t.requestId == "string" ? t.requestId : null, n = s ? this.pendingSessionHistoryRequests.get(s) : null;
820
852
  s && n && (window.clearTimeout(n.timeout), this.pendingSessionHistoryRequests.delete(s), n.resolve({
821
- sessions: _s(t.sessions),
853
+ sessions: An(t.sessions),
822
854
  nextCursor: typeof t.nextCursor == "string" ? t.nextCursor : null
823
855
  }));
824
856
  return;
825
857
  }
826
858
  if (t.type === "session.updated") {
827
- this.clearRunAckResyncRetryTimer(), this.setState({ sessionId: T(t.session, "id") ?? this.state.sessionId });
859
+ this.clearRunAckResyncRetryTimer(), this.setState({ sessionId: E(t.session, "id") ?? this.state.sessionId });
828
860
  return;
829
861
  }
830
862
  if (t.type === "session.item") {
831
863
  this.rememberUserMessageClientMessageIds([t.item]);
832
- const s = D(t.item);
833
- if (it(s)) {
864
+ const s = x(t.item);
865
+ if (Dt(s)) {
834
866
  typeof s?.runId == "string" && this.retryableFailureRunIdsAwaitingDone.add(s.runId);
835
- const r = T(t.item, "sessionId") ?? this.state.sessionId, i = s ? R(s) : null, o = i ? this.clientMessageIdsByUserMessageItemId.get(i) : null, l = typeof s?.clientMessageId == "string" ? s.clientMessageId : o ?? (i ? null : this.activeClientMessageId ?? this.latestRecoverableClientMessageId);
836
- if (r && l) {
837
- this.retryAfterInterruptedRun(r, l);
867
+ const r = E(t.item, "sessionId") ?? this.state.sessionId, i = s ? O(s) : null, o = i ? this.clientMessageIdsByUserMessageItemId.get(i) : null, a = typeof s?.clientMessageId == "string" ? s.clientMessageId : o ?? (i ? null : this.activeClientMessageId ?? this.latestRecoverableClientMessageId);
868
+ if (r && a) {
869
+ this.retryAfterInterruptedRun(r, a);
838
870
  return;
839
871
  }
840
872
  if (r && i) {
@@ -842,23 +874,23 @@ class $t {
842
874
  return;
843
875
  }
844
876
  }
845
- if (Ut(s))
877
+ if (ge(s))
846
878
  return;
847
- const n = Gt(t.item, this.options.backendUrl);
879
+ const n = De(t.item, this.options.backendUrl);
848
880
  if (n) {
849
- N(n) && (this.retryableClientMessageId = null, this.clearRetryTimers(), this.clearRunAckResyncRetryTimer());
881
+ j(n) && (this.retryableClientMessageId = null, this.clearRetryTimers(), this.clearRunAckResyncRetryTimer());
850
882
  const r = t.item.data;
851
- Xs(r) && this.clearRunAckResyncRetryTimer();
852
- const i = Xt(this.state.messages, n), o = Pt(i), l = Nt(
883
+ jn(r) && this.clearRunAckResyncRetryTimer();
884
+ const i = Ne(this.state.messages, n), o = fe(i), a = ye(
853
885
  r,
854
886
  this.state.assistantDraft,
855
887
  this.state.assistantDraftItemId,
856
888
  this.state.assistantDraftRespondsToUserMessageId,
857
889
  this.state.assistantDraftRunId
858
- ), u = o && (!this.state.assistantDraft || l);
890
+ ), u = o && (!this.state.assistantDraft || a);
859
891
  this.setState({
860
892
  messages: i,
861
- ...l ? {
893
+ ...a ? {
862
894
  assistantDraft: "",
863
895
  assistantDraftItemId: null,
864
896
  assistantDraftPhase: null,
@@ -901,9 +933,9 @@ class $t {
901
933
  }
902
934
  if (t.type === "tool.call") {
903
935
  this.clearRunAckResyncRetryTimer();
904
- const s = Ls(t);
936
+ const s = Un(t);
905
937
  if (s) {
906
- const n = Ns(
938
+ const n = Cn(
907
939
  this.state.messages,
908
940
  s
909
941
  );
@@ -932,14 +964,14 @@ class $t {
932
964
  return;
933
965
  }
934
966
  o && r && i && (this.retryableClientMessageId = i);
935
- const l = new Error(typeof t.message == "string" ? t.message.replace(/Product Agent/g, "Pluno") : "Pluno error"), u = us(l.message);
967
+ const a = new Error(typeof t.message == "string" ? t.message.replace(/Product Agent/g, "Pluno") : "Pluno error"), u = tn(a.message);
936
968
  u && console.error(u), this.setState({
937
969
  status: "error",
938
970
  isThinking: !1,
939
- lastError: l.message,
971
+ lastError: a.message,
940
972
  lastErrorCode: typeof t.code == "string" ? t.code : null,
941
973
  lastErrorSecuritySettingsUrl: typeof t.securitySettingsUrl == "string" ? t.securitySettingsUrl : null
942
- }), this.clearThinkingWatchdog(), this.emit("error", l);
974
+ }), this.clearThinkingWatchdog(), this.emit("error", a);
943
975
  }
944
976
  }
945
977
  retryAfterRetryableError(t) {
@@ -948,20 +980,20 @@ class $t {
948
980
  return !1;
949
981
  if (t.code === "run_still_active") {
950
982
  if (this.retryableClientMessageId = n, this.activeClientMessageId = n, this.latestRecoverableClientMessageId = n, this.setState({ status: "connected", isThinking: !0, lastError: null, lastErrorCode: null }), this.retryTimersByClientMessageId[n] === void 0) {
951
- const l = typeof t.retryAfterMs == "number" ? t.retryAfterMs : 2e3;
983
+ const a = typeof t.retryAfterMs == "number" ? t.retryAfterMs : 2e3;
952
984
  this.retryTimersByClientMessageId[n] = window.setTimeout(() => {
953
985
  delete this.retryTimersByClientMessageId[n], this.resyncThinkingSession(), this.markThinkingProgress();
954
- }, l);
986
+ }, a);
955
987
  }
956
988
  return !0;
957
989
  }
958
990
  if (this.retryTimersByClientMessageId[n] !== void 0)
959
991
  return !0;
960
992
  const i = this.retryAttemptsByClientMessageId[n] ?? 0;
961
- if (i >= L)
993
+ if (i >= K)
962
994
  return !1;
963
995
  this.retryAttemptsByClientMessageId[n] = i + 1;
964
- const o = B(
996
+ const o = V(
965
997
  i,
966
998
  typeof t.retryAfterMs == "number" ? t.retryAfterMs : 0
967
999
  );
@@ -978,7 +1010,7 @@ class $t {
978
1010
  if (this.retryTimersByClientMessageId[s] !== void 0)
979
1011
  return;
980
1012
  const n = this.retryAttemptsByClientMessageId[s] ?? 0;
981
- if (n >= L) {
1013
+ if (n >= K) {
982
1014
  this.retryableClientMessageId = s, this.setState({
983
1015
  isThinking: !1,
984
1016
  lastError: "Pluno could not finish this message. Try it again.",
@@ -988,7 +1020,7 @@ class $t {
988
1020
  }
989
1021
  this.retryAttemptsByClientMessageId[s] = n + 1, this.activeClientMessageId = s, this.latestRecoverableClientMessageId = s, this.setState({ status: "connected", isThinking: !0, lastError: null, lastErrorCode: null }), this.retryTimersByClientMessageId[s] = window.setTimeout(() => {
990
1022
  delete this.retryTimersByClientMessageId[s], this.setState({ status: "connected", isThinking: !0, lastError: null, lastErrorCode: null }), this.markThinkingProgress(), this.send({ type: "chat.retry_last_user_message", sessionId: t, clientMessageId: s, automatic: !0 });
991
- }, B(n));
1023
+ }, V(n));
992
1024
  }
993
1025
  clearRetryTimers() {
994
1026
  for (const t of Object.values(this.retryTimersByClientMessageId))
@@ -997,7 +1029,7 @@ class $t {
997
1029
  }
998
1030
  rememberUserMessageClientMessageIds(t) {
999
1031
  for (const s of t) {
1000
- const n = T(s, "id"), r = D(s);
1032
+ const n = E(s, "id"), r = x(s);
1001
1033
  n && r?.type === "message" && r.role === "user" && typeof r.clientMessageId == "string" && this.clientMessageIdsByUserMessageItemId.set(n, r.clientMessageId);
1002
1034
  }
1003
1035
  }
@@ -1007,7 +1039,7 @@ class $t {
1007
1039
  this.pendingSessionHistoryRequests.clear();
1008
1040
  }
1009
1041
  markThinkingProgress() {
1010
- !this.state.isThinking || this.state.status === "closed" || (this.scheduleThinkingWatchdog(kt), this.activeClientMessageId && this.scheduleRunAckWatchdog(this.activeClientMessageId));
1042
+ !this.state.isThinking || this.state.status === "closed" || (this.scheduleThinkingWatchdog(oe), this.activeClientMessageId && this.scheduleRunAckWatchdog(this.activeClientMessageId));
1011
1043
  }
1012
1044
  scheduleThinkingWatchdog(t) {
1013
1045
  this.thinkingWatchdogTimer !== null && window.clearTimeout(this.thinkingWatchdogTimer), this.thinkingWatchdogTimer = window.setTimeout(() => {
@@ -1027,10 +1059,10 @@ class $t {
1027
1059
  scheduleRunAckWatchdog(t) {
1028
1060
  this.runAckWatchdogTimer !== null && window.clearTimeout(this.runAckWatchdogTimer), this.runAckWatchdogTimer = window.setTimeout(() => {
1029
1061
  this.runAckWatchdogTimer = null, this.recoverMissedRunAck(t);
1030
- }, De);
1062
+ }, As);
1031
1063
  }
1032
1064
  recoverMissedRunAck(t) {
1033
- !this.state.isThinking || this.state.status === "closed" || this.activeClientMessageId !== t || (f("web-sdk.agent", "Pluno run ack missed; resyncing session", {
1065
+ !this.state.isThinking || this.state.status === "closed" || this.activeClientMessageId !== t || (I("web-sdk.agent", "Pluno run ack missed; resyncing session", {
1034
1066
  sessionId: this.state.sessionId,
1035
1067
  clientMessageId: t
1036
1068
  }), this.resyncThinkingSession(), this.scheduleRunAckResyncRetry(t));
@@ -1038,12 +1070,12 @@ class $t {
1038
1070
  scheduleRunAckResyncRetry(t) {
1039
1071
  this.clearRunAckResyncRetryTimer();
1040
1072
  const s = this.retryAttemptsByClientMessageId[t] ?? 0;
1041
- s >= L || (this.runAckResyncRetryTimer = window.setTimeout(() => {
1073
+ s >= K || (this.runAckResyncRetryTimer = window.setTimeout(() => {
1042
1074
  this.runAckResyncRetryTimer = null, (this.retryAttemptsByClientMessageId[t] ?? 0) === s && (!this.state.isThinking || this.state.status === "closed" || this.activeClientMessageId !== t || this.latestRecoverableClientMessageId !== t || (this.retryAttemptsByClientMessageId[t] = s + 1, this.setState({
1043
1075
  status: this.state.status === "reconnecting" ? "reconnecting" : "connected",
1044
1076
  isThinking: !0,
1045
1077
  lastError: null
1046
- }), f("web-sdk.agent", "Pluno run ack recovery retrying last user message", {
1078
+ }), I("web-sdk.agent", "Pluno run ack recovery retrying last user message", {
1047
1079
  sessionId: this.state.sessionId,
1048
1080
  clientMessageId: t
1049
1081
  }), this.state.sessionId ? this.send({
@@ -1051,8 +1083,8 @@ class $t {
1051
1083
  sessionId: this.state.sessionId,
1052
1084
  clientMessageId: t,
1053
1085
  automatic: !0
1054
- }) : this.activeUserMessageEvent && this.send(this.activeUserMessageEvent), this.scheduleThinkingWatchdog(kt)));
1055
- }, B(s, Ne)));
1086
+ }) : this.activeUserMessageEvent && this.send(this.activeUserMessageEvent), this.scheduleThinkingWatchdog(oe)));
1087
+ }, V(s, Ss)));
1056
1088
  }
1057
1089
  clearRunAckResyncRetryTimer() {
1058
1090
  this.runAckResyncRetryTimer !== null && (window.clearTimeout(this.runAckResyncRetryTimer), this.runAckResyncRetryTimer = null);
@@ -1065,7 +1097,7 @@ class $t {
1065
1097
  return;
1066
1098
  const t = this.activeClientMessageId;
1067
1099
  if (!t) {
1068
- f("web-sdk.agent", "Pluno thinking watchdog stopped without a recoverable message id", {
1100
+ I("web-sdk.agent", "Pluno thinking watchdog stopped without a recoverable message id", {
1069
1101
  sessionId: this.state.sessionId
1070
1102
  }), this.setState({
1071
1103
  isThinking: !1,
@@ -1075,8 +1107,8 @@ class $t {
1075
1107
  return;
1076
1108
  }
1077
1109
  const s = this.thinkingWatchdogResyncAttemptsByClientMessageId[t] ?? 0, n = this.retryAttemptsByClientMessageId[t] ?? 0;
1078
- if (n >= L) {
1079
- f("web-sdk.agent", "Pluno run recovery retry exhausted", {
1110
+ if (n >= K) {
1111
+ I("web-sdk.agent", "Pluno run recovery retry exhausted", {
1080
1112
  sessionId: this.state.sessionId,
1081
1113
  clientMessageId: t
1082
1114
  }), this.retryableClientMessageId = t, this.setState({
@@ -1087,18 +1119,18 @@ class $t {
1087
1119
  return;
1088
1120
  }
1089
1121
  if (s < 1) {
1090
- this.thinkingWatchdogResyncAttemptsByClientMessageId[t] = s + 1, f("web-sdk.agent", "Pluno thinking watchdog resyncing session", {
1122
+ this.thinkingWatchdogResyncAttemptsByClientMessageId[t] = s + 1, I("web-sdk.agent", "Pluno thinking watchdog resyncing session", {
1091
1123
  sessionId: this.state.sessionId,
1092
1124
  clientMessageId: t,
1093
1125
  resyncAttempts: s + 1
1094
- }), this.resyncThinkingSession(), this.scheduleThinkingWatchdog(Ue);
1126
+ }), this.resyncThinkingSession(), this.scheduleThinkingWatchdog(ws);
1095
1127
  return;
1096
1128
  }
1097
1129
  this.setState({
1098
1130
  status: this.state.status === "reconnecting" ? "reconnecting" : "connected",
1099
1131
  isThinking: !0,
1100
1132
  lastError: null
1101
- }), f("web-sdk.agent", "Pluno thinking watchdog scheduling retry for last user message", {
1133
+ }), I("web-sdk.agent", "Pluno thinking watchdog scheduling retry for last user message", {
1102
1134
  sessionId: this.state.sessionId,
1103
1135
  clientMessageId: t,
1104
1136
  retryAttempts: n + 1
@@ -1109,32 +1141,32 @@ class $t {
1109
1141
  clientMessageId: t,
1110
1142
  automatic: !0
1111
1143
  }) : this.activeUserMessageEvent && this.send(this.activeUserMessageEvent), this.markThinkingProgress();
1112
- }, B(n)));
1144
+ }, V(n)));
1113
1145
  }
1114
1146
  resyncThinkingSession() {
1115
1147
  this.state.sessionId ? this.send({
1116
1148
  type: "page.upsert",
1117
1149
  sessionId: this.state.sessionId,
1118
- page: w(),
1150
+ page: R(),
1119
1151
  model: this.options.model
1120
1152
  }) : (!this.socket || this.socket.readyState !== WebSocket.OPEN) && (this.setState({ status: "reconnecting", lastError: null }), this.scheduleReconnect());
1121
1153
  }
1122
1154
  async executeToolCall(t) {
1123
- 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 = M(
1155
+ 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 = L(
1124
1156
  typeof t.summary == "string" ? t.summary : "Running browser tool"
1125
1157
  ), o = t.rawInput;
1126
1158
  if (!s || !n || !r)
1127
1159
  return;
1128
- const l = r === "execute_code_in_browser_tab" && o !== null && typeof o == "object" && o.tabId === "local:current";
1129
- if (r !== "execute_code" && !l || !gn(o)) {
1160
+ const a = r === "execute_code_in_browser_tab" && o !== null && typeof o == "object" && o.tabId === "local:current";
1161
+ if (r !== "execute_code" && !a || !dr(o)) {
1130
1162
  this.setToolMessageLoading(n, !1), this.send({
1131
1163
  type: "tool.result",
1132
1164
  sessionId: s,
1133
1165
  callId: n,
1134
1166
  toolName: r,
1135
1167
  summary: i,
1136
- rawInput: A(o),
1137
- rawOutput: A({
1168
+ rawInput: _(o),
1169
+ rawOutput: _({
1138
1170
  ok: !1,
1139
1171
  toolName: r,
1140
1172
  error: `Unsupported browser tool: ${r}`
@@ -1142,7 +1174,7 @@ class $t {
1142
1174
  });
1143
1175
  return;
1144
1176
  }
1145
- const u = Ye(this.state.messages);
1177
+ const u = Hs(this.state.messages);
1146
1178
  this.activeBrowserToolCalls.set(n, {
1147
1179
  event: {
1148
1180
  type: "tool.result",
@@ -1150,15 +1182,15 @@ class $t {
1150
1182
  callId: n,
1151
1183
  toolName: r,
1152
1184
  summary: i,
1153
- rawInput: A(o),
1185
+ rawInput: _(o),
1154
1186
  rawOutput: null
1155
1187
  },
1156
1188
  startedAtMs: Date.now(),
1157
1189
  startedAtUrl: location.href,
1158
1190
  startedAtOrigin: location.origin
1159
1191
  }), this.installSessionUserFilesApi(u);
1160
- let c = null, a;
1161
- c = await this.executeRuntimeHelper(), a = await _t(o).catch((h) => ({
1192
+ let c = null, l;
1193
+ c = await this.executeRuntimeHelper(), l = await le(o).catch((h) => ({
1162
1194
  ok: !1,
1163
1195
  exception: {
1164
1196
  message: h instanceof Error ? h.message : String(h)
@@ -1169,12 +1201,12 @@ class $t {
1169
1201
  callId: n,
1170
1202
  toolName: r,
1171
1203
  summary: o.summary,
1172
- rawInput: A(o),
1173
- rawOutput: A(As(a, c))
1174
- }), nn(this.options.clientId, this.activeBrowserToolCalls.values());
1204
+ rawInput: _(o),
1205
+ rawOutput: _(mn(l, c))
1206
+ }), tr(this.options.clientId, this.activeBrowserToolCalls.values());
1175
1207
  }
1176
1208
  setToolMessageLoading(t, s) {
1177
- const n = Os(
1209
+ const n = Pn(
1178
1210
  this.state.messages,
1179
1211
  t,
1180
1212
  s
@@ -1185,50 +1217,50 @@ class $t {
1185
1217
  if (this.pageLifecycleCleanup)
1186
1218
  return;
1187
1219
  const t = () => {
1188
- Yt(this.options.clientId, this.activeBrowserToolCalls.values());
1220
+ xe(this.options.clientId, this.activeBrowserToolCalls.values());
1189
1221
  };
1190
1222
  window.addEventListener("pagehide", t), window.addEventListener("beforeunload", t), this.pageLifecycleCleanup = () => {
1191
1223
  window.removeEventListener("pagehide", t), window.removeEventListener("beforeunload", t);
1192
1224
  };
1193
1225
  }
1194
1226
  installSessionUserFilesApi(t) {
1195
- this.cleanupSessionUserFilesApi(), this.sessionUserFilesApiCleanup = Ze(t, this.attachmentFiles, this.attachmentBlobCache);
1227
+ this.cleanupSessionUserFilesApi(), this.sessionUserFilesApiCleanup = Fs(t, this.attachmentFiles, this.attachmentBlobCache);
1196
1228
  }
1197
1229
  cleanupSessionUserFilesApi() {
1198
- this.sessionUserFilesApiCleanup && (os(this.sessionUserFilesApiCleanup), this.sessionUserFilesApiCleanup = null);
1230
+ this.sessionUserFilesApiCleanup && (Vs(this.sessionUserFilesApiCleanup), this.sessionUserFilesApiCleanup = null);
1199
1231
  }
1200
1232
  async executeRuntimeHelper() {
1201
1233
  if (!this.runtimeHelperJavascript?.trim())
1202
1234
  return null;
1203
- const t = await _t({
1235
+ const t = await le({
1204
1236
  javascript: this.runtimeHelperJavascript
1205
1237
  });
1206
- return t.ok === !1 ? Ss(t) : null;
1238
+ return t.ok === !1 ? yn(t) : null;
1207
1239
  }
1208
1240
  enableNetworkCapture() {
1209
- this.networkCaptureCleanup || (this.networkCaptureCleanup = Ge((t) => {
1210
- An(t.url, this.options.backendUrl) || this.enqueueNetworkEvent(t);
1241
+ this.networkCaptureCleanup || (this.networkCaptureCleanup = vs((t) => {
1242
+ yr(t.url, this.options.backendUrl) || this.enqueueNetworkEvent(t);
1211
1243
  }));
1212
1244
  }
1213
1245
  enqueueNetworkEvent(t) {
1214
- this.queuedNetworkEvents.length >= Le || (this.queuedNetworkEvents.push(wn(t)), this.networkBatchTimer === null && (this.networkBatchTimer = window.setTimeout(() => {
1246
+ this.queuedNetworkEvents.length >= ks || (this.queuedNetworkEvents.push(mr(t)), this.networkBatchTimer === null && (this.networkBatchTimer = window.setTimeout(() => {
1215
1247
  this.networkBatchTimer = null;
1216
1248
  const s = this.queuedNetworkEvents.splice(0, this.queuedNetworkEvents.length);
1217
1249
  s.length === 0 || this.socket?.readyState !== WebSocket.OPEN || this.sendNow({
1218
1250
  type: "network.batch",
1219
1251
  sessionId: this.state.sessionId ?? void 0,
1220
- page: w(),
1252
+ page: R(),
1221
1253
  events: s
1222
1254
  });
1223
- }, Oe)));
1255
+ }, Es)));
1224
1256
  }
1225
1257
  scheduleReconnect() {
1226
1258
  if (this.reconnectTimer !== null || this.state.status === "closed")
1227
1259
  return;
1228
- const t = $e(this.reconnectAttempts);
1260
+ const t = Ns(this.reconnectAttempts);
1229
1261
  this.reconnectAttempts += 1, this.reconnectTimer = window.setTimeout(() => {
1230
1262
  this.reconnectTimer = null, this.connect().catch((s) => {
1231
- f("web-sdk.agent", "Pluno reconnect failed; retrying", {
1263
+ I("web-sdk.agent", "Pluno reconnect failed; retrying", {
1232
1264
  message: s instanceof Error ? s.message : String(s),
1233
1265
  queuedClientEventCount: this.queuedClientEvents.length,
1234
1266
  isThinking: this.state.isThinking
@@ -1240,9 +1272,9 @@ class $t {
1240
1272
  this.stopHeartbeat(), this.heartbeatTimer = window.setInterval(() => {
1241
1273
  const t = this.socket;
1242
1274
  !t || !this.sendNow({ type: "runtime.ping" }) || (this.clearHeartbeatAckTimer(), this.heartbeatAckTimer = window.setTimeout(() => {
1243
- this.socket === t && (f("web-sdk.agent", "Pluno heartbeat acknowledgement timed out; reconnecting"), this.replaceTimedOutSocket(t));
1244
- }, _e));
1245
- }, Re);
1275
+ this.socket === t && (I("web-sdk.agent", "Pluno heartbeat acknowledgement timed out; reconnecting"), this.replaceTimedOutSocket(t));
1276
+ }, gs));
1277
+ }, fs);
1246
1278
  }
1247
1279
  stopHeartbeat() {
1248
1280
  this.heartbeatTimer !== null && (window.clearInterval(this.heartbeatTimer), this.heartbeatTimer = null), this.clearHeartbeatAckTimer();
@@ -1268,92 +1300,92 @@ class $t {
1268
1300
  ...t,
1269
1301
  ...t.lastError === null && t.lastErrorCode === void 0 ? { lastErrorCode: null } : {},
1270
1302
  ...t.lastError !== void 0 && t.lastErrorSecuritySettingsUrl === void 0 ? { lastErrorSecuritySettingsUrl: null } : {}
1271
- }, en(this.options.clientId, this.state), this.emit("state", this.getState());
1303
+ }, Zn(this.options.clientId, this.state), this.emit("state", this.getState());
1272
1304
  }
1273
1305
  emit(t, s) {
1274
1306
  this.listeners[t]?.forEach((r) => r(s));
1275
1307
  }
1276
1308
  }
1277
- const Z = /* @__PURE__ */ new WeakMap();
1278
- function Ge(e) {
1279
- const t = window.__plunoProductAgentNetworkCapture ?? Xe();
1309
+ const kt = /* @__PURE__ */ new WeakMap();
1310
+ function vs(e) {
1311
+ const t = window.__plunoProductAgentNetworkCapture ?? Ls();
1280
1312
  return t.subscribers.add(e), () => {
1281
1313
  t.subscribers.delete(e), !(t.subscribers.size > 0) && (t.destroy(), window.__plunoProductAgentNetworkCapture === t && delete window.__plunoProductAgentNetworkCapture);
1282
1314
  };
1283
1315
  }
1284
- function Xe() {
1285
- const e = /* @__PURE__ */ new Set(), t = (g) => {
1316
+ function Ls() {
1317
+ const e = /* @__PURE__ */ new Set(), t = (f) => {
1286
1318
  e.forEach((p) => {
1287
1319
  try {
1288
- p(g);
1320
+ p(f);
1289
1321
  } catch {
1290
1322
  }
1291
1323
  });
1292
1324
  }, s = window.fetch, n = XMLHttpRequest.prototype.open, r = XMLHttpRequest.prototype.setRequestHeader, i = XMLHttpRequest.prototype.send, o = function(p, d) {
1293
- const m = Date.now();
1294
- let I;
1325
+ const g = Date.now();
1326
+ let T;
1295
1327
  try {
1296
- I = s.call(this, p, d);
1328
+ T = s.call(this, p, d);
1297
1329
  } catch (y) {
1298
1330
  throw y;
1299
1331
  }
1300
1332
  try {
1301
- const y = p instanceof Request ? p : null, O = mn(p, y), C = te(d?.headers ?? y?.headers);
1302
- if (!b(O, C, d?.body)) {
1303
- const K = {
1304
- requestId: Q("fetch"),
1305
- url: k(O, Y),
1333
+ const y = p instanceof Request ? p : null, N = hr(p, y), w = He(d?.headers ?? y?.headers);
1334
+ if (!v(N, w, d?.body)) {
1335
+ const q = {
1336
+ requestId: Rt("fetch"),
1337
+ url: C(N, Et),
1306
1338
  method: (d?.method ?? y?.method ?? "GET").toUpperCase(),
1307
- requestHeaders: C,
1308
- requestBody: Bt(d?.body),
1339
+ requestHeaders: w,
1340
+ requestBody: we(d?.body),
1309
1341
  resourceType: "fetch",
1310
- startedAt: new Date(m).toISOString()
1342
+ startedAt: new Date(g).toISOString()
1311
1343
  };
1312
- I.then(
1313
- (_) => {
1314
- yn(_, K, m, t).catch(() => {
1344
+ T.then(
1345
+ (b) => {
1346
+ pr(b, q, g, t).catch(() => {
1315
1347
  t({
1316
- ...K,
1317
- responseStatus: _.status,
1318
- durationMs: Date.now() - m
1348
+ ...q,
1349
+ responseStatus: b.status,
1350
+ durationMs: Date.now() - g
1319
1351
  });
1320
1352
  });
1321
1353
  },
1322
- (_) => {
1354
+ (b) => {
1323
1355
  t({
1324
- ...K,
1325
- errorText: k(_ instanceof Error ? _.message : String(_)),
1326
- durationMs: Date.now() - m
1356
+ ...q,
1357
+ errorText: C(b instanceof Error ? b.message : String(b)),
1358
+ durationMs: Date.now() - g
1327
1359
  });
1328
1360
  }
1329
1361
  );
1330
1362
  }
1331
1363
  } catch {
1332
1364
  }
1333
- return I;
1334
- }, l = function(p, d, m, I, y) {
1335
- const O = n.call(this, p, d, m ?? !0, I ?? void 0, y ?? void 0), C = typeof d == "string" ? d : d.toString();
1336
- return Z.set(this, {
1337
- requestId: Q("xhr"),
1365
+ return T;
1366
+ }, a = function(p, d, g, T, y) {
1367
+ const N = n.call(this, p, d, g ?? !0, T ?? void 0, y ?? void 0), w = typeof d == "string" ? d : d.toString();
1368
+ return kt.set(this, {
1369
+ requestId: Rt("xhr"),
1338
1370
  method: String(p ?? "GET").toUpperCase(),
1339
- url: k(C, Y),
1371
+ url: C(w, Et),
1340
1372
  requestHeaders: {},
1341
1373
  startedAtMs: Date.now(),
1342
1374
  startedAt: (/* @__PURE__ */ new Date()).toISOString(),
1343
- excluded: b(C)
1344
- }), O;
1375
+ excluded: v(w)
1376
+ }), N;
1345
1377
  }, u = function(p, d) {
1346
- const m = r.call(this, p, d), I = Z.get(this);
1347
- return I && Object.keys(I.requestHeaders).length < ht && (I.requestHeaders[p] = Tt(p, d), I.excluded = I.excluded || b(I.url, I.requestHeaders)), m;
1378
+ const g = r.call(this, p, d), T = kt.get(this);
1379
+ return T && Object.keys(T.requestHeaders).length < Ht && (T.requestHeaders[p] = Xt(p, d), T.excluded = T.excluded || v(T.url, T.requestHeaders)), g;
1348
1380
  }, c = function(p) {
1349
1381
  try {
1350
- const d = Z.get(this);
1351
- d && (d.excluded = d.excluded || b(d.url, d.requestHeaders, p), d.requestBody = Bt(p), d.excluded || this.addEventListener(
1382
+ const d = kt.get(this);
1383
+ d && (d.excluded = d.excluded || v(d.url, d.requestHeaders, p), d.requestBody = we(p), d.excluded || this.addEventListener(
1352
1384
  "loadend",
1353
1385
  () => {
1354
1386
  queueMicrotask(() => {
1355
1387
  try {
1356
- const m = kn(this.getAllResponseHeaders());
1388
+ const g = Ir(this.getAllResponseHeaders());
1357
1389
  t({
1358
1390
  requestId: d.requestId,
1359
1391
  url: d.url,
@@ -1362,8 +1394,8 @@ function Xe() {
1362
1394
  requestBody: d.requestBody,
1363
1395
  resourceType: "xhr",
1364
1396
  responseStatus: this.status,
1365
- responseHeaders: m,
1366
- responseBody: Tn(this, m),
1397
+ responseHeaders: g,
1398
+ responseBody: gr(this, g),
1367
1399
  errorText: this.status === 0 ? "XHR request failed or was aborted" : void 0,
1368
1400
  startedAt: d.startedAt,
1369
1401
  durationMs: Date.now() - d.startedAtMs
@@ -1384,7 +1416,7 @@ function Xe() {
1384
1416
  } catch {
1385
1417
  }
1386
1418
  try {
1387
- XMLHttpRequest.prototype.open = l;
1419
+ XMLHttpRequest.prototype.open = a;
1388
1420
  } catch {
1389
1421
  }
1390
1422
  try {
@@ -1395,41 +1427,41 @@ function Xe() {
1395
1427
  XMLHttpRequest.prototype.send = c;
1396
1428
  } catch {
1397
1429
  }
1398
- let a = null;
1430
+ let l = null;
1399
1431
  if (typeof PerformanceObserver < "u") {
1400
- a = new PerformanceObserver((g) => {
1401
- for (const p of g.getEntries()) {
1432
+ l = new PerformanceObserver((f) => {
1433
+ for (const p of f.getEntries()) {
1402
1434
  const d = p;
1403
- if (d.initiatorType === "fetch" || d.initiatorType === "xmlhttprequest" || b(d.name))
1435
+ if (d.initiatorType === "fetch" || d.initiatorType === "xmlhttprequest" || v(d.name))
1404
1436
  continue;
1405
- const m = performance.timeOrigin + d.startTime;
1437
+ const g = performance.timeOrigin + d.startTime;
1406
1438
  t({
1407
- requestId: Q("resource"),
1408
- url: k(d.name, Y),
1439
+ requestId: Rt("resource"),
1440
+ url: C(d.name, Et),
1409
1441
  method: "GET",
1410
1442
  resourceType: "resource",
1411
1443
  responseStatus: d.responseStatus,
1412
- startedAt: new Date(m).toISOString(),
1444
+ startedAt: new Date(g).toISOString(),
1413
1445
  durationMs: d.duration
1414
1446
  });
1415
1447
  }
1416
1448
  });
1417
1449
  try {
1418
- a.observe({ type: "resource", buffered: !0 });
1450
+ l.observe({ type: "resource", buffered: !0 });
1419
1451
  } catch {
1420
- a.disconnect(), a = null;
1452
+ l.disconnect(), l = null;
1421
1453
  }
1422
1454
  }
1423
1455
  const h = {
1424
1456
  subscribers: e,
1425
1457
  destroy: () => {
1426
- a?.disconnect();
1458
+ l?.disconnect();
1427
1459
  try {
1428
1460
  window.fetch === o && (window.fetch = s);
1429
1461
  } catch {
1430
1462
  }
1431
1463
  try {
1432
- XMLHttpRequest.prototype.open === l && (XMLHttpRequest.prototype.open = n);
1464
+ XMLHttpRequest.prototype.open === a && (XMLHttpRequest.prototype.open = n);
1433
1465
  } catch {
1434
1466
  }
1435
1467
  try {
@@ -1444,7 +1476,7 @@ function Xe() {
1444
1476
  };
1445
1477
  return window.__plunoProductAgentNetworkCapture = h, h;
1446
1478
  }
1447
- function f(e, t, s) {
1479
+ function I(e, t, s) {
1448
1480
  if (typeof window > "u")
1449
1481
  return;
1450
1482
  const n = window, r = {
@@ -1455,15 +1487,15 @@ function f(e, t, s) {
1455
1487
  }, i = n.__plunoProductAgentDiagnostics__ ?? [];
1456
1488
  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 }));
1457
1489
  }
1458
- function Rt(e) {
1490
+ function ce(e) {
1459
1491
  const t = typeof e == "function" ? e() : e;
1460
1492
  return t && Object.keys(t).length > 0 ? t : void 0;
1461
1493
  }
1462
- function Ke(e) {
1494
+ function xs(e) {
1463
1495
  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";
1464
1496
  }
1465
- const Je = 5e3, Ve = 12e4;
1466
- function Ye(e) {
1497
+ const Bs = 5e3, qs = 12e4;
1498
+ function Hs(e) {
1467
1499
  const t = [];
1468
1500
  for (const s of e)
1469
1501
  s.role !== "user" || !s.attachments?.length || s.attachments.forEach((n, r) => {
@@ -1474,17 +1506,21 @@ function Ye(e) {
1474
1506
  });
1475
1507
  return t;
1476
1508
  }
1477
- function Ze(e, t = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map()) {
1509
+ function Fs(e, t = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map()) {
1478
1510
  const n = [
1479
- Qe(e, t, s),
1480
- ts()
1511
+ $s(e, t, s),
1512
+ js(),
1513
+ Ws()
1481
1514
  ].filter((r) => typeof r == "function");
1482
1515
  return () => {
1483
1516
  for (const r of n.reverse())
1484
1517
  r();
1485
1518
  };
1486
1519
  }
1487
- function Qe(e, t = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map()) {
1520
+ function Ws() {
1521
+ return Bt(globalThis, "getPageSnapshot", async () => Wt());
1522
+ }
1523
+ function $s(e, t = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map()) {
1488
1524
  const n = new Map(e.map((c) => [c.id, c])), r = (c) => ({
1489
1525
  id: c.id,
1490
1526
  name: c.name,
@@ -1493,99 +1529,99 @@ function Qe(e, t = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map()) {
1493
1529
  type: c.mimeType,
1494
1530
  size: c.sizeBytes
1495
1531
  }), i = (c) => {
1496
- const a = n.get(c);
1497
- if (!a)
1532
+ const l = n.get(c);
1533
+ if (!l)
1498
1534
  throw new Error(`Unknown Pluno user file: ${c}`);
1499
- return a;
1535
+ return l;
1500
1536
  }, o = async (c) => {
1501
- const a = i(c), h = t.get(a.id);
1537
+ const l = i(c), h = t.get(l.id);
1502
1538
  if (h)
1503
1539
  return h;
1504
- const g = s.get(a.id);
1505
- if (g)
1506
- return g;
1507
- const p = await le(a.id).then((y) => y?.blob ?? null).catch((y) => (f("web-sdk.attachments", "Failed to load Product Agent attachment from IndexedDB", {
1508
- attachmentId: a.id,
1509
- name: a.name,
1540
+ const f = s.get(l.id);
1541
+ if (f)
1542
+ return f;
1543
+ const p = await Ye(l.id).then((y) => y?.blob ?? null).catch((y) => (I("web-sdk.attachments", "Failed to load Product Agent attachment from IndexedDB", {
1544
+ attachmentId: l.id,
1545
+ name: l.name,
1510
1546
  message: y instanceof Error ? y.message : String(y)
1511
1547
  }), null));
1512
1548
  if (p)
1513
- return s.set(a.id, p), p;
1514
- if (!a.fileUrl)
1549
+ return s.set(l.id, p), p;
1550
+ if (!l.fileUrl)
1515
1551
  throw new Error(`Pluno user file is missing content: ${c}`);
1516
- const d = await fetch(a.fileUrl, un(a.fileUrl));
1552
+ const d = await fetch(l.fileUrl, or(l.fileUrl));
1517
1553
  if (!d.ok)
1518
1554
  throw new Error(`Failed to load Pluno user file: ${c}`);
1519
- const m = await d.blob();
1520
- s.set(a.id, m);
1521
- const I = Date.now();
1522
- return qt({
1523
- attachmentId: a.id,
1524
- name: a.name,
1525
- mimeType: a.mimeType,
1526
- sizeBytes: a.sizeBytes,
1527
- blob: m,
1528
- fileUrl: a.fileUrl,
1529
- gcsPath: a.gcsPath,
1530
- createdAt: I,
1531
- lastUsedAt: I
1555
+ const g = await d.blob();
1556
+ s.set(l.id, g);
1557
+ const T = Date.now();
1558
+ return Se({
1559
+ attachmentId: l.id,
1560
+ name: l.name,
1561
+ mimeType: l.mimeType,
1562
+ sizeBytes: l.sizeBytes,
1563
+ blob: g,
1564
+ fileUrl: l.fileUrl,
1565
+ gcsPath: l.gcsPath,
1566
+ createdAt: T,
1567
+ lastUsedAt: T
1532
1568
  }).catch((y) => {
1533
- f("web-sdk.attachments", "Failed to cache Product Agent attachment from fileUrl", {
1534
- attachmentId: a.id,
1535
- name: a.name,
1569
+ I("web-sdk.attachments", "Failed to cache Product Agent attachment from fileUrl", {
1570
+ attachmentId: l.id,
1571
+ name: l.name,
1536
1572
  message: y instanceof Error ? y.message : String(y)
1537
1573
  });
1538
- }), m;
1574
+ }), g;
1539
1575
  };
1540
- return Ht(globalThis, "userFiles", {
1576
+ return Bt(globalThis, "userFiles", {
1541
1577
  list: () => e.map(r),
1542
1578
  get: (c) => {
1543
- const a = n.get(c);
1544
- return a ? r(a) : null;
1579
+ const l = n.get(c);
1580
+ return l ? r(l) : null;
1545
1581
  },
1546
1582
  inspectImage: async (c) => {
1547
- const a = i(c), h = await o(c), g = a.mimeType.startsWith("image/") ? a.mimeType : h.type || a.mimeType;
1548
- if (!g.startsWith("image/"))
1583
+ const l = i(c), h = await o(c), f = l.mimeType.startsWith("image/") ? l.mimeType : h.type || l.mimeType;
1584
+ if (!f.startsWith("image/"))
1549
1585
  throw new Error(`Pluno user file is not an image: ${c}`);
1550
- const p = h.type === g ? h : new Blob([h], { type: g });
1551
- return as(g, p.size) > He ? {
1586
+ const p = h.type === f ? h : new Blob([h], { type: f });
1587
+ return Ys(f, p.size) > Ps ? {
1552
1588
  type: "pluno.userFiles.inspectImage",
1553
- id: a.id,
1554
- name: a.name,
1555
- mimeType: g,
1556
- sizeBytes: a.sizeBytes,
1589
+ id: l.id,
1590
+ name: l.name,
1591
+ mimeType: f,
1592
+ sizeBytes: l.sizeBytes,
1557
1593
  imageAttached: !1,
1558
- imageAttachmentError: pt
1594
+ imageAttachmentError: Ft
1559
1595
  } : {
1560
1596
  type: "pluno.userFiles.inspectImage",
1561
- id: a.id,
1562
- name: a.name,
1563
- mimeType: g,
1564
- sizeBytes: a.sizeBytes,
1597
+ id: l.id,
1598
+ name: l.name,
1599
+ mimeType: f,
1600
+ sizeBytes: l.sizeBytes,
1565
1601
  imageAttached: !0,
1566
- dataUrl: await rt(p)
1602
+ dataUrl: await Ut(p)
1567
1603
  };
1568
1604
  },
1569
- getDataUrl: async (c) => (i(c), await rt(await o(c))),
1605
+ getDataUrl: async (c) => (i(c), await Ut(await o(c))),
1570
1606
  getBlob: o,
1571
1607
  getArrayBuffer: async (c) => await (await o(c)).arrayBuffer(),
1572
1608
  getFile: async (c) => {
1573
- const a = i(c);
1574
- return new File([await o(c)], a.name, { type: a.mimeType });
1609
+ const l = i(c);
1610
+ return new File([await o(c)], l.name, { type: l.mimeType });
1575
1611
  }
1576
1612
  });
1577
1613
  }
1578
- function ts() {
1579
- return Ht(globalThis, "pageImages", {
1580
- inspectImage: async (t, s) => await es(t, s)
1614
+ function js() {
1615
+ return Bt(globalThis, "pageImages", {
1616
+ inspectImage: async (t, s) => await zs(t, s)
1581
1617
  });
1582
1618
  }
1583
- async function es(e, t = {}) {
1584
- const s = is(t.name), n = await ss(e);
1619
+ async function zs(e, t = {}) {
1620
+ const s = Ks(t.name), n = await Gs(e);
1585
1621
  return n.ok ? n.sizeBytes > 8 * 1024 * 1024 ? {
1586
1622
  type: "pluno.pageImages.inspectImage",
1587
1623
  imageAttached: !1,
1588
- imageAttachmentError: pt
1624
+ imageAttachmentError: Ft
1589
1625
  } : {
1590
1626
  type: "pluno.pageImages.inspectImage",
1591
1627
  imageAttached: !0,
@@ -1599,26 +1635,26 @@ async function es(e, t = {}) {
1599
1635
  imageAttachmentError: n.error
1600
1636
  };
1601
1637
  }
1602
- async function ss(e) {
1603
- return e instanceof Blob ? e.type.startsWith("image/") ? e.size === 0 ? { ok: !1, error: "Page image is empty." } : e.size > 8 * 1024 * 1024 ? { ok: !1, error: pt } : {
1638
+ async function Gs(e) {
1639
+ return e instanceof Blob ? e.type.startsWith("image/") ? e.size === 0 ? { ok: !1, error: "Page image is empty." } : e.size > 8 * 1024 * 1024 ? { ok: !1, error: Ft } : {
1604
1640
  ok: !0,
1605
1641
  mimeType: e.type,
1606
1642
  sizeBytes: e.size,
1607
- dataUrl: await rt(e)
1608
- } : { ok: !1, error: "Page image must be an image Blob or complete data:image/* URL." } : typeof e != "string" ? { ok: !1, error: "Page image must be an image Blob or complete data:image/* URL." } : ns(e);
1643
+ dataUrl: await Ut(e)
1644
+ } : { ok: !1, error: "Page image must be an image Blob or complete data:image/* URL." } : typeof e != "string" ? { ok: !1, error: "Page image must be an image Blob or complete data:image/* URL." } : Xs(e);
1609
1645
  }
1610
- function ns(e) {
1646
+ function Xs(e) {
1611
1647
  if (!e.startsWith("data:") || !e.includes(","))
1612
1648
  return { ok: !1, error: "Page image must be a complete data:image/* URL, not bare base64." };
1613
- const [t, s] = e.slice(5).split(",", 2), n = t.split(";").map((l) => l.trim()).filter(Boolean), r = n[0] ?? "";
1649
+ const [t, s] = e.slice(5).split(",", 2), n = t.split(";").map((a) => a.trim()).filter(Boolean), r = n[0] ?? "";
1614
1650
  if (!r.startsWith("image/"))
1615
1651
  return { ok: !1, error: "Page image MIME type must be image/*." };
1616
- if (!n.slice(1).some((l) => l.toLowerCase() === "base64"))
1652
+ if (!n.slice(1).some((a) => a.toLowerCase() === "base64"))
1617
1653
  return { ok: !1, error: "Page image data URL must be base64 encoded." };
1618
1654
  const i = s.replace(/[ \t\r\n\f]+/g, "");
1619
1655
  if (!/^[A-Za-z0-9+/]*={0,2}$/.test(i))
1620
1656
  return { ok: !1, error: "Page image data URL has invalid base64." };
1621
- const o = rs(i);
1657
+ const o = Js(i);
1622
1658
  return o === null ? { ok: !1, error: "Page image data URL has invalid base64." } : o === 0 ? { ok: !1, error: "Page image is empty." } : {
1623
1659
  ok: !0,
1624
1660
  mimeType: r,
@@ -1626,22 +1662,22 @@ function ns(e) {
1626
1662
  dataUrl: `data:${r};base64,${i}`
1627
1663
  };
1628
1664
  }
1629
- function rs(e) {
1665
+ function Js(e) {
1630
1666
  if (e.length === 0 || e.length % 4 !== 0)
1631
1667
  return null;
1632
1668
  const t = e.length - e.replace(/=+$/, "").length;
1633
1669
  return t > 2 ? null : e.length / 4 * 3 - t;
1634
1670
  }
1635
- function is(e) {
1671
+ function Ks(e) {
1636
1672
  return (typeof e == "string" ? e.trim() : "") || "Page image";
1637
1673
  }
1638
- function os(e) {
1674
+ function Vs(e) {
1639
1675
  try {
1640
1676
  e();
1641
1677
  } catch {
1642
1678
  }
1643
1679
  }
1644
- function rt(e) {
1680
+ function Ut(e) {
1645
1681
  return new Promise((t, s) => {
1646
1682
  const n = new FileReader();
1647
1683
  n.onload = () => {
@@ -1653,30 +1689,30 @@ function rt(e) {
1653
1689
  }, n.onerror = () => s(n.error ?? new Error("Failed to read Pluno user file")), n.readAsDataURL(e);
1654
1690
  });
1655
1691
  }
1656
- function as(e, t) {
1692
+ function Ys(e, t) {
1657
1693
  return `data:${e};base64,`.length + Math.ceil(t / 3) * 4;
1658
1694
  }
1659
- async function _t(e) {
1695
+ async function le(e) {
1660
1696
  const t = Object.getPrototypeOf(async function() {
1661
- }).constructor, s = e.timeoutMs ?? Je, n = Date.now(), r = [];
1697
+ }).constructor, s = e.timeoutMs ?? Bs, n = Date.now(), r = [];
1662
1698
  let i;
1663
1699
  const o = {
1664
1700
  log: console.log,
1665
1701
  info: console.info,
1666
1702
  warn: console.warn,
1667
1703
  error: console.error
1668
- }, l = (u) => (...c) => {
1704
+ }, a = (u) => (...c) => {
1669
1705
  r.push({ level: u, args: c }), o[u](...c);
1670
1706
  };
1671
- console.log = l("log"), console.info = l("info"), console.warn = l("warn"), console.error = l("error");
1707
+ console.log = a("log"), console.info = a("info"), console.warn = a("warn"), console.error = a("error");
1672
1708
  try {
1673
1709
  const u = /* @__PURE__ */ Symbol("execute_code_timeout"), c = await Promise.race([
1674
1710
  new t(e.javascript)(),
1675
- new Promise((a) => {
1676
- i = window.setTimeout(() => a(u), s);
1711
+ new Promise((l) => {
1712
+ i = window.setTimeout(() => l(u), s);
1677
1713
  })
1678
1714
  ]);
1679
- return c === u ? cs(s) : {
1715
+ return c === u ? Zs(s) : {
1680
1716
  ok: !0,
1681
1717
  result: c,
1682
1718
  console: r,
@@ -1705,7 +1741,7 @@ async function _t(e) {
1705
1741
  i !== void 0 && window.clearTimeout(i), console.log = o.log, console.info = o.info, console.warn = o.warn, console.error = o.error;
1706
1742
  }
1707
1743
  }
1708
- function cs(e) {
1744
+ function Zs(e) {
1709
1745
  return {
1710
1746
  ok: !1,
1711
1747
  exception: {
@@ -1719,18 +1755,18 @@ function cs(e) {
1719
1755
  }
1720
1756
  };
1721
1757
  }
1722
- function ls(e) {
1758
+ function Qs(e) {
1723
1759
  return e.replace(/\/+$/, "");
1724
1760
  }
1725
- function us(e, t = location.origin) {
1761
+ function tn(e, t = location.origin) {
1726
1762
  return /origin (?:is not allowed|does not match browser origin)/i.test(e) ? `Pluno widget blocked on ${t}: this domain is not allowed. Add ${t} in Pluno under Integration > Domains.` : null;
1727
1763
  }
1728
- function ds(e) {
1764
+ function en(e) {
1729
1765
  const t = new URL("/api/product-agent/embed/ws", e);
1730
1766
  return t.protocol = t.protocol === "https:" ? "wss:" : "ws:", t.toString();
1731
1767
  }
1732
- function w() {
1733
- const e = zt();
1768
+ function R() {
1769
+ const e = Ue();
1734
1770
  return {
1735
1771
  url: location.href,
1736
1772
  title: document.title,
@@ -1738,21 +1774,21 @@ function w() {
1738
1774
  ...e ? { plunoProductAgentUi: e } : {}
1739
1775
  };
1740
1776
  }
1741
- function hs() {
1777
+ function sn() {
1742
1778
  return {
1743
1779
  pageUrl: location.href,
1744
1780
  pageTitle: document.title,
1745
- htmlContent: ms()
1781
+ htmlContent: Wt()
1746
1782
  };
1747
1783
  }
1748
- function ps(e) {
1749
- return F.add(e), v || (v = fs()), () => {
1750
- F.delete(e), F.size === 0 && (v?.(), v = null);
1784
+ function nn(e) {
1785
+ return et.add(e), Y || (Y = rn()), () => {
1786
+ et.delete(e), et.size === 0 && (Y?.(), Y = null);
1751
1787
  };
1752
1788
  }
1753
- function fs() {
1789
+ function rn() {
1754
1790
  const e = () => {
1755
- for (const i of Array.from(F))
1791
+ for (const i of Array.from(et))
1756
1792
  i();
1757
1793
  }, t = window.history.pushState.bind(window.history), s = window.history.replaceState.bind(window.history), n = ((...i) => {
1758
1794
  const o = t(...i);
@@ -1765,36 +1801,321 @@ function fs() {
1765
1801
  window.history.pushState === n && (window.history.pushState = t), window.history.replaceState === r && (window.history.replaceState = s), window.removeEventListener("popstate", e), window.removeEventListener("hashchange", e);
1766
1802
  };
1767
1803
  }
1768
- function gs() {
1769
- return zt()?.surface === "browser_extension_sdk_preview";
1770
- }
1771
- function ms() {
1772
- const e = document.body?.cloneNode(!0);
1773
- return e instanceof HTMLElement ? (e.querySelectorAll(
1774
- [
1775
- "script",
1776
- "style",
1777
- "noscript",
1778
- "template",
1779
- "svg",
1780
- "canvas",
1781
- "iframe",
1782
- "input",
1783
- "textarea",
1784
- "select",
1785
- "option",
1786
- "[type='hidden']",
1787
- "[data-pluno-product-agent-widget]",
1788
- ".pluno-pa-widget"
1789
- ].join(",")
1790
- ).forEach((t) => t.remove()), e.querySelectorAll("*").forEach((t) => {
1791
- for (const s of Array.from(t.attributes))
1792
- s.name === "href" || s.name === "aria-label" || s.name === "role" || t.removeAttribute(s.name);
1793
- }), 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) ?? "") : "";
1794
- }
1795
- function zt() {
1796
- const e = document.querySelector(wt);
1797
- if (!(e ?? document.querySelector(st)))
1804
+ function on() {
1805
+ return Ue()?.surface === "browser_extension_sdk_preview";
1806
+ }
1807
+ function Wt() {
1808
+ if (!document.body)
1809
+ return "";
1810
+ const e = [], t = [], s = (g, T) => {
1811
+ const y = B(T);
1812
+ !y || t.includes(y) || (e.push([g, y]), t.push(y));
1813
+ };
1814
+ s("Selected text", window.getSelection()?.toString() ?? "");
1815
+ const n = "[role='dialog'], [role='alertdialog'], dialog[open], [aria-modal='true']", r = Array.from(document.querySelectorAll(n)).filter(
1816
+ (g) => Me(g) && !g.parentElement?.closest(n)
1817
+ );
1818
+ for (const g of r.slice(0, 3))
1819
+ s("Active overlay", bt($(g), t));
1820
+ const i = an(), o = i ? bt($(i), t) : "";
1821
+ s("Main page content", o), s("Additional visible page text", bt($(document.body), t));
1822
+ const a = e.map(([g, T]) => `${g}:
1823
+ ${T}`).join(`
1824
+
1825
+ `).trim().slice(0, 12e3), u = cn(r, i).trim(), c = `Simplified DOM outline:
1826
+ `, l = `
1827
+
1828
+ Visible page text:
1829
+ `, h = 12e3 - c.length - l.length, f = Math.min(a.length, 7900), p = u.slice(0, h - f), d = a.slice(0, h - p.length);
1830
+ return `${c}${p}${l}${d}`;
1831
+ }
1832
+ function $(e) {
1833
+ return e.innerText ?? e.textContent ?? "";
1834
+ }
1835
+ function B(e) {
1836
+ return (e ?? "").replace(/\u00a0/g, " ").replace(/\r\n?/g, `
1837
+ `).split(`
1838
+ `).map((t) => t.replace(/[ \t]+/g, " ").trim()).join(`
1839
+ `).replace(/\n{3,}/g, `
1840
+
1841
+ `).trim();
1842
+ }
1843
+ function bt(e, t) {
1844
+ let s = B(e);
1845
+ for (const n of t)
1846
+ s = s.replace(n, "");
1847
+ return B(s);
1848
+ }
1849
+ function Me(e) {
1850
+ const t = window.getComputedStyle(e);
1851
+ return t.display !== "none" && t.visibility !== "hidden" && e.getClientRects().length > 0;
1852
+ }
1853
+ function an() {
1854
+ return Array.from(document.querySelectorAll("main, [role='main'], article")).filter(Me).sort((e, t) => $(t).length - $(e).length)[0] ?? null;
1855
+ }
1856
+ function cn(e, t) {
1857
+ const s = /* @__PURE__ */ new Set([
1858
+ "main",
1859
+ "nav",
1860
+ "header",
1861
+ "footer",
1862
+ "section",
1863
+ "article",
1864
+ "aside",
1865
+ "form",
1866
+ "fieldset",
1867
+ "legend",
1868
+ "table",
1869
+ "tr",
1870
+ "th",
1871
+ "td",
1872
+ "ul",
1873
+ "ol",
1874
+ "li",
1875
+ "h1",
1876
+ "h2",
1877
+ "h3",
1878
+ "h4",
1879
+ "h5",
1880
+ "h6",
1881
+ "p",
1882
+ "a",
1883
+ "button",
1884
+ "label",
1885
+ "input",
1886
+ "textarea",
1887
+ "select",
1888
+ "option",
1889
+ "details",
1890
+ "summary",
1891
+ "dialog",
1892
+ "iframe",
1893
+ "canvas"
1894
+ ]), n = /* @__PURE__ */ new Set([
1895
+ "h1",
1896
+ "h2",
1897
+ "h3",
1898
+ "h4",
1899
+ "h5",
1900
+ "h6",
1901
+ "p",
1902
+ "a",
1903
+ "button",
1904
+ "label",
1905
+ "th",
1906
+ "td",
1907
+ "option",
1908
+ "summary"
1909
+ ]), r = /* @__PURE__ */ new Set(["tr", "th", "td", "li", "p", "label", "option", "a", "button"]), i = /* @__PURE__ */ new Set(["script", "style", "noscript", "template", "meta", "link", "svg", "path", "slot"]), o = /* @__PURE__ */ new Set(["none", "presentation", "tooltip", "status", "img"]), a = /* @__PURE__ */ new Set([
1910
+ "button",
1911
+ "link",
1912
+ "checkbox",
1913
+ "radio",
1914
+ "switch",
1915
+ "combobox",
1916
+ "textbox",
1917
+ "tab",
1918
+ "menuitem",
1919
+ "option"
1920
+ ]), u = [
1921
+ "role",
1922
+ "aria-label",
1923
+ "aria-current",
1924
+ "aria-selected",
1925
+ "aria-expanded",
1926
+ "aria-checked",
1927
+ "aria-pressed",
1928
+ "name",
1929
+ "type",
1930
+ "placeholder",
1931
+ "title",
1932
+ "data-testid",
1933
+ "data-test",
1934
+ "data-qa",
1935
+ "data-cy"
1936
+ ], c = ["aria-label", "placeholder", "data-testid", "data-test", "data-qa", "data-cy"], { priorityElements: l, priorityTargets: h } = ln(), f = new Set(e);
1937
+ t && f.add(t);
1938
+ let p = 0;
1939
+ const d = (w) => {
1940
+ const U = w.getAttribute("role");
1941
+ return U && !o.has(U) ? U : "";
1942
+ }, g = (w) => {
1943
+ const U = w.getAttribute("data-testid") || w.getAttribute("data-test") || w.getAttribute("data-qa") || w.getAttribute("data-cy") || "";
1944
+ return `${w.tagName.toLowerCase()}|${d(w)}|${U}`;
1945
+ }, T = (w, U, q) => {
1946
+ const b = (S, ut) => {
1947
+ const k = S.tagName.toLowerCase(), dt = window.getComputedStyle(S), z = l.has(S);
1948
+ if (p >= 1e3 && !z || q.has(S) || i.has(k) || S.matches(".pluno-pa-widget-host, [data-pluno-product-agent-widget]") || dt.display === "none" || dt.visibility === "hidden")
1949
+ return { lines: [], hasUsefulContent: !1, textPreview: "", containsTextElement: !1 };
1950
+ p += 1;
1951
+ const Jt = d(S), G = Pe(S), Je = a.has(Jt) || ["button", "input", "textarea", "select", "iframe", "canvas"].includes(k) || k === "a" && S.hasAttribute("href"), ht = Array.from(S.children).filter((m) => m instanceof HTMLElement), X = /* @__PURE__ */ new Map();
1952
+ for (const m of ht) {
1953
+ const A = g(m);
1954
+ X.set(A, (X.get(A) ?? 0) + 1);
1955
+ }
1956
+ const pt = /* @__PURE__ */ new Map(), Kt = /* @__PURE__ */ new Map();
1957
+ for (const m of ht) {
1958
+ const A = g(m), D = Kt.get(A) ?? 0;
1959
+ Kt.set(A, D + 1), (X.get(A) ?? 0) > 8 && D >= 6 && !l.has(m) && pt.set(A, (pt.get(A) ?? 0) + 1);
1960
+ }
1961
+ const Vt = /* @__PURE__ */ new Map(), Yt = /* @__PURE__ */ new Set(), ft = [], Zt = [];
1962
+ for (const m of ht) {
1963
+ const A = g(m), D = X.get(A) ?? 0, ee = Vt.get(A) ?? 0;
1964
+ if (Vt.set(A, ee + 1), D > 8 && ee >= 6 && !l.has(m)) {
1965
+ Yt.has(A) || (ft.push([`… ${pt.get(A) ?? 0} similar siblings omitted`]), Yt.add(A));
1966
+ continue;
1967
+ }
1968
+ const se = b(m, ut);
1969
+ Zt.push(se), ft.push(se.lines);
1970
+ }
1971
+ const gt = [];
1972
+ if (S.shadowRoot)
1973
+ for (const m of Array.from(S.shadowRoot.children))
1974
+ m instanceof HTMLElement && gt.push(b(m, ut + 1));
1975
+ const J = [...Zt, ...gt], mt = G.length > 0 || Je || J.some((m) => m.hasUsefulContent), Qt = B(
1976
+ [G, ...J.map((m) => m.textPreview)].filter(Boolean).join(" ")
1977
+ ).slice(0, 180), Ke = S.hasAttribute("contenteditable") && (G.length > 0 || !S.querySelector("[contenteditable]")), te = c.some((m) => S.hasAttribute(m)) || !!Jt || Ke, yt = (S.getClientRects().length > 0 || dt.display === "contents") && (s.has(k) || te || z) && (mt || z) && (!r.has(k) || mt || te || z), Tt = yt ? 1 : 0, H = [];
1978
+ if (yt) {
1979
+ const m = J.some((D) => D.containsTextElement), A = n.has(k) && !m ? Qt : G;
1980
+ H.push(Ce(S, u, o, A.slice(0, 180)));
1981
+ }
1982
+ for (const m of ft)
1983
+ H.push(...Z(m, Tt));
1984
+ const It = gt.flatMap((m) => m.lines);
1985
+ if (It.length > 0) {
1986
+ const m = It.slice(0, 20);
1987
+ It.length > m.length && m.push("… shadow DOM omitted");
1988
+ const A = k.includes("tooltip") || k.includes("popper") || k.includes("loader");
1989
+ if (ut < 2 && !A) {
1990
+ const D = yt ? "#shadow-root" : `${k} #shadow-root`;
1991
+ H.push(...Z([D, ...Z(m, 1)], Tt));
1992
+ } else
1993
+ H.push(...Z(m, Tt));
1994
+ }
1995
+ return {
1996
+ lines: H,
1997
+ hasUsefulContent: mt,
1998
+ textPreview: Qt,
1999
+ containsTextElement: n.has(k) || J.some((m) => m.containsTextElement)
2000
+ };
2001
+ };
2002
+ return [`--- ${U} ---`, ...b(w, 0).lines].join(`
2003
+ `);
2004
+ }, y = [], N = B(window.getSelection()?.toString() ?? "");
2005
+ N && y.push(`--- selected text ---
2006
+ ${JSON.stringify(N)}`), h.length > 0 && y.push(un(h, s, u, o));
2007
+ for (const w of e.slice(0, 3))
2008
+ y.push(T(w, "active overlay DOM", /* @__PURE__ */ new Set()));
2009
+ if (t && y.push(T(t, "main DOM", /* @__PURE__ */ new Set())), document.body) {
2010
+ const w = t || e.length ? "other visible DOM" : "visible DOM";
2011
+ y.push(T(document.body, w, f));
2012
+ }
2013
+ return y.join(`
2014
+
2015
+ `);
2016
+ }
2017
+ function Ce(e, t, s, n) {
2018
+ const r = e.tagName.toLowerCase();
2019
+ let i = r;
2020
+ const o = e.getAttribute("id");
2021
+ o && dn(o) && (i += `#${o}`);
2022
+ for (const a of t) {
2023
+ const u = e.getAttribute(a);
2024
+ u && u.length <= 160 && (a !== "role" || !s.has(u)) && (i += `[${a}=${JSON.stringify(u)}]`);
2025
+ }
2026
+ if (r === "a" || r === "iframe") {
2027
+ const a = e.getAttribute(r === "a" ? "href" : "src");
2028
+ a && (i += `[${r === "a" ? "href" : "src"}=${JSON.stringify(a.slice(0, 160))}]`);
2029
+ }
2030
+ for (const a of ["disabled", "checked", "selected", "open", "contenteditable"])
2031
+ e.hasAttribute(a) && (i += `[${a}]`);
2032
+ return `${i}${n ? ` ${JSON.stringify(n)}` : ""}`;
2033
+ }
2034
+ function ln() {
2035
+ const e = /* @__PURE__ */ new Set(), t = /* @__PURE__ */ new Map(), s = (a, u) => {
2036
+ if (!a)
2037
+ return;
2038
+ const c = window.getComputedStyle(a);
2039
+ if (c.display === "none" || c.visibility === "hidden")
2040
+ return;
2041
+ const l = t.get(a) ?? /* @__PURE__ */ new Set();
2042
+ l.add(u), t.set(a, l);
2043
+ let h = a;
2044
+ for (; h; ) {
2045
+ e.add(h);
2046
+ const f = h.getRootNode();
2047
+ h = h.parentElement ?? (f instanceof ShadowRoot && f.host instanceof HTMLElement ? f.host : null);
2048
+ }
2049
+ };
2050
+ let n = document.activeElement instanceof HTMLElement ? document.activeElement : null;
2051
+ for (; n?.shadowRoot?.activeElement instanceof HTMLElement; )
2052
+ n = n.shadowRoot.activeElement;
2053
+ n !== document.body && n !== document.documentElement && s(n, "focused");
2054
+ const r = window.getSelection();
2055
+ r && !r.isCollapsed && (s(ue(r.anchorNode), "selected text"), s(ue(r.focusNode), "selected text"));
2056
+ const i = [
2057
+ ["[aria-selected='true']", "selected"],
2058
+ ["[aria-current]:not([aria-current='false'])", "current"],
2059
+ ["[aria-expanded='true']", "expanded"],
2060
+ ["[aria-checked='true'], :checked", "checked"],
2061
+ ["[aria-pressed='true']", "pressed"],
2062
+ ["[open]", "open"]
2063
+ ], o = [document];
2064
+ for (let a = 0; a < o.length; a += 1) {
2065
+ const u = o[a];
2066
+ for (const [c, l] of i)
2067
+ for (const h of Array.from(u.querySelectorAll(c)))
2068
+ s(h, l);
2069
+ for (const c of Array.from(u.querySelectorAll("*")))
2070
+ c.shadowRoot && o.push(c.shadowRoot);
2071
+ }
2072
+ return {
2073
+ priorityElements: e,
2074
+ priorityTargets: Array.from(t, ([a, u]) => ({ element: a, labels: Array.from(u) }))
2075
+ };
2076
+ }
2077
+ function un(e, t, s, n) {
2078
+ const r = ["--- active/current elements ---"];
2079
+ for (const i of e) {
2080
+ const o = [];
2081
+ let a = i.element;
2082
+ for (; a; ) {
2083
+ const l = a.tagName.toLowerCase();
2084
+ (a === i.element || t.has(l) || a.hasAttribute("id") || a.hasAttribute("role") || a.hasAttribute("aria-label")) && o.unshift(a);
2085
+ const h = a.getRootNode();
2086
+ a = a.parentElement ?? (h instanceof ShadowRoot && h.host instanceof HTMLElement ? h.host : null);
2087
+ }
2088
+ const u = o.length > 6 ? [o[0], ...o.slice(-5)] : o, c = u.map((l, h) => Ce(
2089
+ l,
2090
+ s,
2091
+ n,
2092
+ h === u.length - 1 ? Pe(l).slice(0, 180) : ""
2093
+ ));
2094
+ o.length > u.length && c.splice(1, 0, "…"), r.push(`${i.labels.join(", ")}: ${c.join(" > ")}`);
2095
+ }
2096
+ return r.join(`
2097
+ `);
2098
+ }
2099
+ function ue(e) {
2100
+ return e instanceof HTMLElement ? e : e?.parentElement instanceof HTMLElement ? e.parentElement : null;
2101
+ }
2102
+ function Z(e, t) {
2103
+ if (t === 0)
2104
+ return e;
2105
+ const s = " ".repeat(t);
2106
+ return e.map((n) => `${s}${n}`);
2107
+ }
2108
+ function Pe(e) {
2109
+ return B(
2110
+ Array.from(e.childNodes).filter((t) => t.nodeType === Node.TEXT_NODE).map((t) => t.textContent ?? "").join(" ")
2111
+ );
2112
+ }
2113
+ function dn(e) {
2114
+ return e.length <= 64 && /^[A-Za-z_][A-Za-z0-9_:.-]*$/.test(e) && !/[a-f0-9]{12,}/i.test(e) && !/:r[0-9a-z]+:/i.test(e);
2115
+ }
2116
+ function Ue() {
2117
+ const e = document.querySelector(ne);
2118
+ if (!(e ?? document.querySelector(Ct)))
1798
2119
  return;
1799
2120
  const s = e ? "browser_extension_sdk_preview" : "embedded_widget";
1800
2121
  return {
@@ -1803,28 +2124,28 @@ function zt() {
1803
2124
  selectors: [
1804
2125
  {
1805
2126
  name: "widget_host",
1806
- selector: s === "browser_extension_sdk_preview" ? wt : st,
2127
+ selector: s === "browser_extension_sdk_preview" ? ne : Ct,
1807
2128
  description: "Finds Pluno's shadow-host element in the host page DOM."
1808
2129
  },
1809
2130
  {
1810
2131
  name: "widget_root",
1811
- selector: we,
2132
+ selector: ls,
1812
2133
  description: "Finds Pluno's widget root inside the widget host shadow root."
1813
2134
  },
1814
2135
  {
1815
2136
  name: "widget_panel",
1816
- selector: Ae,
2137
+ selector: us,
1817
2138
  description: "Finds Pluno's open chat panel inside the widget host shadow root."
1818
2139
  },
1819
2140
  {
1820
2141
  name: "widget_timeline",
1821
- selector: Se,
2142
+ selector: ds,
1822
2143
  description: "Finds Pluno's chat timeline inside the widget host shadow root."
1823
2144
  }
1824
2145
  ]
1825
2146
  };
1826
2147
  }
1827
- function ys(e) {
2148
+ function hn(e) {
1828
2149
  try {
1829
2150
  const t = JSON.parse(e);
1830
2151
  return t && typeof t == "object" ? t : { type: "error", message: "Invalid server event" };
@@ -1832,33 +2153,33 @@ function ys(e) {
1832
2153
  return { type: "error", message: "Invalid server event" };
1833
2154
  }
1834
2155
  }
1835
- function bt(e, t) {
2156
+ function de(e, t) {
1836
2157
  if (!e || typeof e != "object")
1837
2158
  return [];
1838
2159
  const s = e[t];
1839
2160
  return Array.isArray(s) ? s.filter((n) => typeof n == "string" && n.trim().length > 0) : [];
1840
2161
  }
1841
- function Is(e) {
2162
+ function pn(e) {
1842
2163
  return Array.isArray(e) ? e.filter((t) => typeof t == "string" && t.trim().length > 0) : [];
1843
2164
  }
1844
- function Ts(e) {
2165
+ function fn(e) {
1845
2166
  if (!e || typeof e != "object")
1846
2167
  return null;
1847
- 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, l = typeof n.scribbleStyle == "boolean" ? n.scribbleStyle : null;
1848
- return !r && !i && !o && l === null ? null : {
2168
+ 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, a = typeof n.scribbleStyle == "boolean" ? n.scribbleStyle : null;
2169
+ return !r && !i && !o && a === null ? null : {
1849
2170
  ...r ? { accentColor: r } : {},
1850
2171
  ...i ? { colorScheme: i } : {},
1851
2172
  ...o ? { fontFamily: o } : {},
1852
- ...l !== null ? { scribbleStyle: l } : {}
2173
+ ...a !== null ? { scribbleStyle: a } : {}
1853
2174
  };
1854
2175
  }
1855
- function ws(e) {
2176
+ function gn(e) {
1856
2177
  if (!e || typeof e != "object")
1857
2178
  return null;
1858
2179
  const t = e.javascript;
1859
2180
  return typeof t != "string" || !t.trim() ? null : { javascript: t };
1860
2181
  }
1861
- function As(e, t) {
2182
+ function mn(e, t) {
1862
2183
  return t ? e && typeof e == "object" ? {
1863
2184
  ...e,
1864
2185
  helperError: t
@@ -1868,23 +2189,23 @@ function As(e, t) {
1868
2189
  helperError: t
1869
2190
  } : e;
1870
2191
  }
1871
- function Ss(e) {
2192
+ function yn(e) {
1872
2193
  if (!e || typeof e != "object")
1873
2194
  return e;
1874
2195
  const t = e;
1875
2196
  return typeof t.exception?.message == "string" ? t.exception.message : typeof t.error == "string" ? t.error : e;
1876
2197
  }
1877
- function ks() {
2198
+ function Tn() {
1878
2199
  const e = "pluno.productAgent.clientId", t = window.localStorage.getItem(e);
1879
2200
  if (t)
1880
2201
  return t;
1881
2202
  const s = crypto.randomUUID();
1882
2203
  return window.localStorage.setItem(e, s), s;
1883
2204
  }
1884
- function q() {
2205
+ function Q() {
1885
2206
  return crypto.randomUUID();
1886
2207
  }
1887
- function Es(e) {
2208
+ function In(e) {
1888
2209
  if (!e || typeof e != "object")
1889
2210
  return null;
1890
2211
  const t = e, s = typeof t.id == "string" ? t.id : null;
@@ -1895,23 +2216,23 @@ function Es(e) {
1895
2216
  avatarUrl: typeof t.avatarUrl == "string" ? t.avatarUrl : null
1896
2217
  } : null;
1897
2218
  }
1898
- function Rs(e, t) {
1899
- return Array.isArray(e) ? at(
1900
- ct(
1901
- e.map((s) => Gt(s, t)).filter((s) => s !== null)
2219
+ function wn(e, t) {
2220
+ return Array.isArray(e) ? Ot(
2221
+ vt(
2222
+ e.map((s) => De(s, t)).filter((s) => s !== null)
1902
2223
  )
1903
2224
  ) : [];
1904
2225
  }
1905
- function _s(e) {
2226
+ function An(e) {
1906
2227
  return Array.isArray(e) ? e.flatMap((t) => {
1907
2228
  if (!t || typeof t != "object")
1908
2229
  return [];
1909
- const s = t, n = T(s, "id"), r = T(s, "createdAt"), i = T(s, "updatedAt"), o = T(s, "lastActiveAt");
2230
+ const s = t, n = E(s, "id"), r = E(s, "createdAt"), i = E(s, "updatedAt"), o = E(s, "lastActiveAt");
1910
2231
  return !n || !r || !i || !o ? [] : [
1911
2232
  {
1912
2233
  id: n,
1913
- title: T(s, "title"),
1914
- firstUserMessage: T(s, "firstUserMessage"),
2234
+ title: E(s, "title"),
2235
+ firstUserMessage: E(s, "firstUserMessage"),
1915
2236
  currentPage: s.currentPage ?? null,
1916
2237
  createdAt: r,
1917
2238
  updatedAt: i,
@@ -1921,7 +2242,7 @@ function _s(e) {
1921
2242
  ];
1922
2243
  }) : [];
1923
2244
  }
1924
- function Gt(e, t) {
2245
+ function De(e, t) {
1925
2246
  if (!e || typeof e != "object")
1926
2247
  return null;
1927
2248
  const s = e, n = s.data;
@@ -1937,61 +2258,64 @@ function Gt(e, t) {
1937
2258
  id: String(s.id ?? crypto.randomUUID()),
1938
2259
  role: i,
1939
2260
  ...r.phase === "commentary" || r.phase === "final_answer" ? { phase: r.phase } : {},
1940
- content: Ds(r.content),
2261
+ content: Mn(r.content),
1941
2262
  createdAt: typeof s.createdAt == "string" ? s.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
1942
- respondsToUserMessageId: R(r) ?? void 0,
1943
- ...S(r) ? { runId: S(r) } : {},
1944
- attachments: Zt(r.attachments, t)
2263
+ respondsToUserMessageId: O(r) ?? void 0,
2264
+ ...M(r) ? { runId: M(r) } : {},
2265
+ attachments: Be(r.attachments, t)
1945
2266
  };
1946
- return typeof r.clientMessageId == "string" && Object.defineProperty(o, "clientMessageId", {
2267
+ return i === "assistant" && typeof r.id == "string" && Object.defineProperty(o, "assistantDraftItemId", {
2268
+ value: r.id,
2269
+ enumerable: !1
2270
+ }), typeof r.clientMessageId == "string" && Object.defineProperty(o, "clientMessageId", {
1947
2271
  value: r.clientMessageId,
1948
2272
  enumerable: !1
1949
2273
  }), o;
1950
2274
  }
1951
2275
  if (r.type === "function_call_output") {
1952
- const i = Ms(r.output);
2276
+ const i = En(r.output);
1953
2277
  return i ? {
1954
2278
  id: String(s.id ?? crypto.randomUUID()),
1955
2279
  role: "tool",
1956
2280
  content: `Connect ${i.appName} to continue`,
1957
2281
  createdAt: typeof s.createdAt == "string" ? s.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
1958
- respondsToUserMessageId: R(r) ?? void 0,
1959
- ...S(r) ? { runId: S(r) } : {},
2282
+ respondsToUserMessageId: O(r) ?? void 0,
2283
+ ...M(r) ? { runId: M(r) } : {},
1960
2284
  dataType: "function_call_output",
1961
2285
  toolName: "authenticate_pipedream_app",
1962
- callId: Mt(r) ?? void 0,
2286
+ callId: he(r) ?? void 0,
1963
2287
  integrationAuthRequest: i
1964
2288
  } : null;
1965
2289
  }
1966
2290
  return r.type === "function_call" || r.type === "tool_call" || r.type === "web_search_call" || r.type === "mcp_call" || r.type === "tab_lifecycle_decision" ? {
1967
2291
  id: String(s.id ?? crypto.randomUUID()),
1968
2292
  role: "tool",
1969
- content: r.type === "mcp_call" ? bs(r) : Ps(r),
2293
+ content: r.type === "mcp_call" ? Sn(r) : bn(r),
1970
2294
  createdAt: typeof s.createdAt == "string" ? s.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
1971
- respondsToUserMessageId: R(r) ?? void 0,
1972
- ...S(r) ? { runId: S(r) } : {},
2295
+ respondsToUserMessageId: O(r) ?? void 0,
2296
+ ...M(r) ? { runId: M(r) } : {},
1973
2297
  dataType: String(r.type),
1974
2298
  toolName: r.type === "tab_lifecycle_decision" ? "tab_lifecycle_decision" : typeof r.name == "string" ? r.name : void 0,
1975
- callId: Mt(r) ?? void 0,
2299
+ callId: he(r) ?? void 0,
1976
2300
  loading: r.localExecutionStatus === "running"
1977
2301
  } : r.type === "run_status" || r.type === "run_error" ? r.type === "run_error" && r.stage === "tool_execution" ? null : {
1978
2302
  id: String(s.id ?? crypto.randomUUID()),
1979
2303
  role: "system",
1980
- content: Cs(r),
2304
+ content: kn(r),
1981
2305
  createdAt: typeof s.createdAt == "string" ? s.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
1982
- respondsToUserMessageId: R(r) ?? void 0,
1983
- ...S(r) ? { runId: S(r) } : {},
2306
+ respondsToUserMessageId: O(r) ?? void 0,
2307
+ ...M(r) ? { runId: M(r) } : {},
1984
2308
  dataType: String(r.type),
1985
2309
  loading: r.type === "run_status" && (r.status === "running" || r.status === "retrying"),
1986
2310
  ...typeof r.retryable == "boolean" ? { retryable: r.retryable } : {},
1987
2311
  ...typeof r.securitySettingsUrl == "string" ? { securitySettingsUrl: r.securitySettingsUrl } : {}
1988
2312
  } : null;
1989
2313
  }
1990
- function bs(e) {
2314
+ function Sn(e) {
1991
2315
  const s = (typeof e.server_label == "string" ? e.server_label : "").replace(/^pipedream_/, "").split(/[_-]+/).filter(Boolean).map((n) => `${n.charAt(0).toUpperCase()}${n.slice(1)}`).join(" ");
1992
2316
  return s ? `🔌 Using ${s}` : "🔌 Using connected integration";
1993
2317
  }
1994
- function Ms(e) {
2318
+ function En(e) {
1995
2319
  if (typeof e != "string")
1996
2320
  return null;
1997
2321
  try {
@@ -2008,10 +2332,10 @@ function Ms(e) {
2008
2332
  return null;
2009
2333
  }
2010
2334
  }
2011
- function Cs(e) {
2335
+ function kn(e) {
2012
2336
  return e.type === "run_status" && e.status === "stopped" ? "Run stopped by user" : 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." : "Pluno run status changed.";
2013
2337
  }
2014
- function Ps(e) {
2338
+ function bn(e) {
2015
2339
  if (e.type === "web_search_call") {
2016
2340
  const t = e.action;
2017
2341
  if (t && typeof t == "object") {
@@ -2023,30 +2347,45 @@ function Ps(e) {
2023
2347
  }
2024
2348
  return "🔎 Searching the web";
2025
2349
  }
2026
- return Us(e);
2350
+ return Rn(e);
2027
2351
  }
2028
- function Us(e) {
2352
+ function Rn(e) {
2029
2353
  if (typeof e.summary == "string" && e.summary.trim().length > 0)
2030
- return M(e.summary);
2354
+ return L(e.summary);
2031
2355
  if (typeof e.arguments == "string")
2032
2356
  try {
2033
2357
  const t = JSON.parse(e.arguments);
2034
2358
  if (typeof t.summary == "string" && t.summary.trim().length > 0)
2035
- return M(t.summary);
2359
+ return L(t.summary);
2036
2360
  } catch {
2037
- return typeof e.name == "string" && e.name.trim().length > 0 ? M(e.name) : "🛠️ Run tool";
2361
+ return typeof e.name == "string" && e.name.trim().length > 0 ? L(e.name) : "🛠️ Run tool";
2038
2362
  }
2039
- return typeof e.name == "string" && e.name.trim().length > 0 ? M(e.name) : "🛠️ Run tool";
2363
+ return typeof e.name == "string" && e.name.trim().length > 0 ? L(e.name) : "🛠️ Run tool";
2040
2364
  }
2041
- function M(e) {
2365
+ function L(e) {
2042
2366
  const t = e.trim() || "Run tool", s = t.codePointAt(0) ?? 0;
2043
2367
  return s >= 126976 && s <= 129791 || s >= 9728 && s <= 10175 || s >= 127462 && s <= 127487 ? t : `🛠️ ${t}`;
2044
2368
  }
2045
- function Mt(e) {
2369
+ function _n(e) {
2370
+ if (e == null)
2371
+ return e;
2372
+ if (typeof e != "object")
2373
+ return;
2374
+ const t = e;
2375
+ if (typeof t.content == "string")
2376
+ return {
2377
+ content: t.content,
2378
+ itemId: typeof t.itemId == "string" ? t.itemId : null,
2379
+ phase: t.phase === "commentary" || t.phase === "final_answer" ? t.phase : null,
2380
+ respondsToUserMessageId: typeof t.respondsToUserMessageId == "string" ? t.respondsToUserMessageId : null,
2381
+ runId: typeof t.runId == "string" ? t.runId : null
2382
+ };
2383
+ }
2384
+ function he(e) {
2046
2385
  const t = e.callId ?? e.call_id;
2047
2386
  return typeof t == "string" && t ? t : null;
2048
2387
  }
2049
- function Ds(e) {
2388
+ function Mn(e) {
2050
2389
  return typeof e == "string" ? e : Array.isArray(e) ? e.map((t) => {
2051
2390
  if (!t || typeof t != "object")
2052
2391
  return "";
@@ -2054,24 +2393,24 @@ function Ds(e) {
2054
2393
  return typeof s.text == "string" ? s.text : typeof s.content == "string" ? s.content : "";
2055
2394
  }).filter(Boolean).join("") : "";
2056
2395
  }
2057
- function Xt(e, t) {
2058
- const s = Kt(e, t), n = Bs(
2059
- Fs(e, t),
2396
+ function Ne(e, t) {
2397
+ const s = Oe(e, t), n = Dn(
2398
+ Ln(e, t),
2060
2399
  s
2061
2400
  ), r = n.findIndex((o) => o.id === s.id);
2062
2401
  if (r === -1)
2063
- return at(
2064
- ct([...n, s])
2402
+ return Ot(
2403
+ vt([...n, s])
2065
2404
  );
2066
2405
  const i = [...n];
2067
- return i[r] = s, at(ct(i));
2406
+ return i[r] = s, Ot(vt(i));
2068
2407
  }
2069
- function Ns(e, t) {
2408
+ function Cn(e, t) {
2070
2409
  const s = e.findIndex(
2071
2410
  (r) => !r.id.startsWith("transient-activity:") && r.callId === t.callId
2072
2411
  );
2073
2412
  if (s === -1)
2074
- return Xt(e, t);
2413
+ return Ne(e, t);
2075
2414
  const n = [...e];
2076
2415
  return n[s] = {
2077
2416
  ...n[s],
@@ -2079,17 +2418,17 @@ function Ns(e, t) {
2079
2418
  loading: !0
2080
2419
  }, n;
2081
2420
  }
2082
- function Os(e, t, s) {
2421
+ function Pn(e, t, s) {
2083
2422
  let n = !1;
2084
2423
  const r = e.map((i) => i.callId !== t || i.loading === s ? i : (n = !0, { ...i, loading: s }));
2085
2424
  return n ? r : e;
2086
2425
  }
2087
- function Ls(e) {
2426
+ function Un(e) {
2088
2427
  const t = typeof e.callId == "string" ? e.callId : null, s = typeof e.toolName == "string" ? e.toolName : null;
2089
2428
  return !t || !s ? null : {
2090
2429
  id: `transient-activity:${t}`,
2091
2430
  role: "tool",
2092
- content: M(
2431
+ content: L(
2093
2432
  typeof e.summary == "string" ? e.summary : "Running browser tool"
2094
2433
  ),
2095
2434
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
@@ -2101,7 +2440,7 @@ function Ls(e) {
2101
2440
  loading: !0
2102
2441
  };
2103
2442
  }
2104
- function Bs(e, t) {
2443
+ function Dn(e, t) {
2105
2444
  if (t.id.startsWith("transient-activity:"))
2106
2445
  return e;
2107
2446
  const s = t.toolName === "tab_lifecycle";
@@ -2109,52 +2448,52 @@ function Bs(e, t) {
2109
2448
  (n) => !(n.id === `transient-activity:${t.callId}` && n.callId === t.callId || s && n.id.startsWith("transient-activity:") && n.toolName === "browser_tabs" && n.runId === t.runId && n.respondsToUserMessageId === t.respondsToUserMessageId)
2110
2449
  );
2111
2450
  }
2112
- function vs(e, t) {
2451
+ function Nn(e, t) {
2113
2452
  const s = t.map(
2114
- (n) => Kt(e, n)
2453
+ (n) => Oe(e, n)
2115
2454
  );
2116
- return t.length > 0 ? s : e.filter(ft);
2455
+ return t.length > 0 ? s : e.filter($t);
2117
2456
  }
2118
- function Kt(e, t) {
2457
+ function Oe(e, t) {
2119
2458
  if (t.role !== "user" || !t.attachments?.length)
2120
2459
  return t;
2121
2460
  const s = e.find(
2122
- (r) => r.role === "user" && (r.id === t.id || ft(r) && Jt(r, t))
2461
+ (r) => r.role === "user" && (r.id === t.id || $t(r) && ve(r, t))
2123
2462
  );
2124
2463
  if (!s?.attachments?.length)
2125
2464
  return t;
2126
2465
  const n = t.attachments.map((r) => {
2127
- const i = qs(s.attachments ?? [], r);
2128
- return i ? xs(r, i) : r;
2466
+ const i = On(s.attachments ?? [], r);
2467
+ return i ? vn(r, i) : r;
2129
2468
  });
2130
2469
  return { ...t, attachments: n };
2131
2470
  }
2132
- function qs(e, t) {
2471
+ function On(e, t) {
2133
2472
  return t.id ? e.find((s) => s.id === t.id) ?? null : null;
2134
2473
  }
2135
- function xs(e, t) {
2474
+ function vn(e, t) {
2136
2475
  const { previewUrl: s } = t;
2137
2476
  return s ? { ...e, previewUrl: s } : e;
2138
2477
  }
2139
- function Fs(e, t) {
2478
+ function Ln(e, t) {
2140
2479
  if (t.role !== "user")
2141
2480
  return e;
2142
2481
  const s = e.findIndex(
2143
- (r) => ft(r) && Jt(r, t)
2482
+ (r) => $t(r) && ve(r, t)
2144
2483
  );
2145
2484
  if (s === -1)
2146
2485
  return e;
2147
2486
  const n = [...e];
2148
2487
  return n.splice(s, 1), n;
2149
2488
  }
2150
- function Jt(e, t) {
2151
- const s = Ct(e), n = Ct(t);
2489
+ function ve(e, t) {
2490
+ const s = pe(e), n = pe(t);
2152
2491
  return s && n ? s === n : e.content === t.content;
2153
2492
  }
2154
- function ft(e) {
2493
+ function $t(e) {
2155
2494
  return e.role === "user" && (e.id.startsWith("local-") || e.id.startsWith("optimistic-user-message:"));
2156
2495
  }
2157
- function Ct(e) {
2496
+ function pe(e) {
2158
2497
  const t = e.clientMessageId;
2159
2498
  if (t)
2160
2499
  return t;
@@ -2163,13 +2502,13 @@ function Ct(e) {
2163
2502
  );
2164
2503
  return n ? e.id.slice(n.length) : null;
2165
2504
  }
2166
- function Pt(e) {
2167
- const t = Vt(e);
2505
+ function fe(e) {
2506
+ const t = Le(e);
2168
2507
  if (t === null)
2169
2508
  return !1;
2170
2509
  for (let s = e.length - 1; s > t; s -= 1) {
2171
2510
  const n = e[s];
2172
- if (N(n))
2511
+ if (j(n))
2173
2512
  return !0;
2174
2513
  if (n.role === "system") {
2175
2514
  if (n.dataType === "run_error")
@@ -2180,20 +2519,20 @@ function Pt(e) {
2180
2519
  }
2181
2520
  return !1;
2182
2521
  }
2183
- function Hs(e) {
2184
- const t = Vt(e);
2185
- return t === null ? e.some(N) : e.slice(t + 1).some(N);
2522
+ function xn(e) {
2523
+ const t = Le(e);
2524
+ return t === null ? e.some(j) : e.slice(t + 1).some(j);
2186
2525
  }
2187
- function Vt(e) {
2526
+ function Le(e) {
2188
2527
  for (let t = e.length - 1; t >= 0; t -= 1)
2189
2528
  if (e[t].role === "user")
2190
2529
  return t;
2191
2530
  return null;
2192
2531
  }
2193
- function Ws(e) {
2194
- return N(e) ? !0 : e.role !== "system" ? !1 : e.dataType === "run_error" ? !0 : e.dataType === "run_status" && e.loading !== !0;
2532
+ function Bn(e) {
2533
+ return j(e) ? !0 : e.role !== "system" ? !1 : e.dataType === "run_error" ? !0 : e.dataType === "run_status" && e.loading !== !0;
2195
2534
  }
2196
- function gt(e) {
2535
+ function at(e) {
2197
2536
  for (let t = e.length - 1; t >= 0; t -= 1) {
2198
2537
  const s = e[t];
2199
2538
  if (!s || typeof s != "object")
@@ -2207,30 +2546,40 @@ function gt(e) {
2207
2546
  }
2208
2547
  return null;
2209
2548
  }
2210
- function D(e) {
2549
+ function qn(e) {
2550
+ const t = at(e);
2551
+ if (t === null)
2552
+ return null;
2553
+ const n = x(e[t])?.page;
2554
+ if (!n || typeof n != "object")
2555
+ return null;
2556
+ const r = n.url;
2557
+ return typeof r == "string" ? r : null;
2558
+ }
2559
+ function x(e) {
2211
2560
  if (!e || typeof e != "object")
2212
2561
  return null;
2213
2562
  const t = e.data;
2214
2563
  return t && typeof t == "object" ? t : null;
2215
2564
  }
2216
- function it(e) {
2565
+ function Dt(e) {
2217
2566
  return e?.retryable !== !0 ? !1 : e.type === "run_error" ? !0 : e.type === "run_status" && e.status === "interrupted";
2218
2567
  }
2219
- function Ut(e) {
2568
+ function ge(e) {
2220
2569
  return e?.type === "run_status" && e.status === "interrupted" && e.reason === "backend_restart";
2221
2570
  }
2222
- function js(e, t) {
2223
- const s = gt(t);
2571
+ function Hn(e, t) {
2572
+ const s = at(t);
2224
2573
  if (s === null)
2225
2574
  return !1;
2226
2575
  const n = t[s], r = n && typeof n == "object" ? n.id : null;
2227
2576
  if (typeof r != "string" || !r)
2228
2577
  return !1;
2229
2578
  const i = e.findIndex((o) => o.role === "user" && o.id === r);
2230
- return i === -1 ? !1 : e.slice(i + 1).some(Ws);
2579
+ return i === -1 ? !1 : e.slice(i + 1).some(Bn);
2231
2580
  }
2232
- function ot(e) {
2233
- const t = gt(e);
2581
+ function Nt(e) {
2582
+ const t = at(e);
2234
2583
  if (t === null)
2235
2584
  return null;
2236
2585
  const s = e[t];
@@ -2242,8 +2591,8 @@ function ot(e) {
2242
2591
  const r = n.clientMessageId;
2243
2592
  return typeof r == "string" ? r : null;
2244
2593
  }
2245
- function $s(e) {
2246
- const t = gt(e);
2594
+ function Fn(e) {
2595
+ const t = at(e);
2247
2596
  if (t === null)
2248
2597
  return null;
2249
2598
  for (let s = e.length - 1; s > t; s -= 1) {
@@ -2257,22 +2606,22 @@ function $s(e) {
2257
2606
  if (i.type === "message" && i.role === "assistant")
2258
2607
  return null;
2259
2608
  if (i.type === "run_error")
2260
- return i.retryable !== !0 ? null : Dt(e, i) ?? ot(e);
2609
+ return i.retryable !== !0 ? null : me(e, i) ?? Nt(e);
2261
2610
  if (i.type === "run_status")
2262
- return i.status === "interrupted" && i.retryable === !0 ? Dt(e, i) ?? ot(e) : null;
2611
+ return i.status === "interrupted" && i.retryable === !0 ? me(e, i) ?? Nt(e) : null;
2263
2612
  }
2264
2613
  return null;
2265
2614
  }
2266
- function Dt(e, t) {
2615
+ function me(e, t) {
2267
2616
  if (typeof t.clientMessageId == "string")
2268
2617
  return t.clientMessageId;
2269
- const s = R(t);
2618
+ const s = O(t);
2270
2619
  if (!s)
2271
2620
  return null;
2272
- const n = e.find((i) => T(i, "id") === s), r = D(n);
2621
+ const n = e.find((i) => E(i, "id") === s), r = x(n);
2273
2622
  return r?.type === "message" && r.role === "user" && typeof r.clientMessageId == "string" ? r.clientMessageId : null;
2274
2623
  }
2275
- function zs(e, t) {
2624
+ function Wn(e, t) {
2276
2625
  let s = 0;
2277
2626
  for (const n of e) {
2278
2627
  if (!n || typeof n != "object")
@@ -2285,37 +2634,37 @@ function zs(e, t) {
2285
2634
  }
2286
2635
  return s;
2287
2636
  }
2288
- function Nt(e, t, s, n, r) {
2289
- if (!t || !Gs(e))
2637
+ function ye(e, t, s, n, r) {
2638
+ if (!t || !$n(e))
2290
2639
  return !1;
2291
2640
  const i = e;
2292
- return !(it(i) || s !== null && typeof i.id == "string" && i.id !== s || n !== null && R(i) !== n || r !== null && S(i) !== r);
2641
+ return !(Dt(i) || s !== null && typeof i.id == "string" && i.id !== s || n !== null && O(i) !== n || r !== null && M(i) !== r);
2293
2642
  }
2294
- function Gs(e) {
2643
+ function $n(e) {
2295
2644
  if (!e || typeof e != "object")
2296
2645
  return !1;
2297
2646
  const t = e;
2298
2647
  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");
2299
2648
  }
2300
- function N(e) {
2649
+ function j(e) {
2301
2650
  return e.role === "assistant" && e.phase !== "commentary";
2302
2651
  }
2303
- function Xs(e) {
2652
+ function jn(e) {
2304
2653
  if (!e || typeof e != "object")
2305
2654
  return !1;
2306
2655
  const t = e;
2307
2656
  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";
2308
2657
  }
2309
- function at(e) {
2310
- return e.filter((t, s) => mt(t) ? !Qs(e, s) && !Ys(e, s) && !Zs(e, s) : Ks(t) ? t.retryable === !0 && Vs(e, s) ? !1 : !Js(e, s) : !0);
2658
+ function Ot(e) {
2659
+ return e.filter((t, s) => jt(t) ? !Vn(e, s) && !Jn(e, s) && !Kn(e, s) : zn(t) ? t.retryable === !0 && Xn(e, s) ? !1 : !Gn(e, s) : !0);
2311
2660
  }
2312
- function Ks(e) {
2661
+ function zn(e) {
2313
2662
  return e.role === "system" && (e.dataType === "run_status" || e.dataType === "run_error");
2314
2663
  }
2315
- function mt(e) {
2664
+ function jt(e) {
2316
2665
  return e.role === "system" && e.dataType === "run_status" && e.loading === !0;
2317
2666
  }
2318
- function ct(e) {
2667
+ function vt(e) {
2319
2668
  const t = new Set(e.filter((i) => i.role === "user").map((i) => i.id)), s = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set();
2320
2669
  for (const i of e) {
2321
2670
  if (i.role === "user" || !i.respondsToUserMessageId || !t.has(i.respondsToUserMessageId))
@@ -2331,18 +2680,18 @@ function ct(e) {
2331
2680
  n.has(i.id) || (r.push(i), i.role === "user" && r.push(...s.get(i.id) ?? []));
2332
2681
  return r;
2333
2682
  }
2334
- function Js(e, t) {
2683
+ function Gn(e, t) {
2335
2684
  const s = e[t];
2336
2685
  for (let n = t + 1; n < e.length; n += 1) {
2337
2686
  const r = e[n];
2338
2687
  if (r.role === "user")
2339
2688
  return !1;
2340
- if (r.role === "assistant" && G(s, r))
2689
+ if (r.role === "assistant" && ct(s, r))
2341
2690
  return !0;
2342
2691
  }
2343
2692
  return !1;
2344
2693
  }
2345
- function Vs(e, t) {
2694
+ function Xn(e, t) {
2346
2695
  const s = e[t];
2347
2696
  if (!s.respondsToUserMessageId)
2348
2697
  return !1;
@@ -2350,47 +2699,47 @@ function Vs(e, t) {
2350
2699
  const r = e[n];
2351
2700
  if (r.role === "user")
2352
2701
  return !1;
2353
- if (r.respondsToUserMessageId === s.respondsToUserMessageId && (r.role === "assistant" || r.role === "tool" || mt(r)))
2702
+ if (r.respondsToUserMessageId === s.respondsToUserMessageId && (r.role === "assistant" || r.role === "tool" || jt(r)))
2354
2703
  return !0;
2355
2704
  }
2356
2705
  return !1;
2357
2706
  }
2358
- function Ys(e, t) {
2707
+ function Jn(e, t) {
2359
2708
  const s = e[t];
2360
2709
  for (let n = t + 1; n < e.length; n += 1)
2361
- if (e[n].role === "assistant" && G(s, e[n]))
2710
+ if (e[n].role === "assistant" && ct(s, e[n]))
2362
2711
  return !0;
2363
2712
  return !1;
2364
2713
  }
2365
- function Zs(e, t) {
2714
+ function Kn(e, t) {
2366
2715
  const s = e[t];
2367
2716
  for (let n = t + 1; n < e.length; n += 1)
2368
- if (e[n].role === "tool" && G(s, e[n]))
2717
+ if (e[n].role === "tool" && ct(s, e[n]))
2369
2718
  return !0;
2370
2719
  return !1;
2371
2720
  }
2372
- function Qs(e, t) {
2721
+ function Vn(e, t) {
2373
2722
  const s = e[t];
2374
2723
  for (let n = t + 1; n < e.length; n += 1)
2375
- if (mt(e[n]) && G(s, e[n]))
2724
+ if (jt(e[n]) && ct(s, e[n]))
2376
2725
  return !0;
2377
2726
  return !1;
2378
2727
  }
2379
- function G(e, t) {
2728
+ function ct(e, t) {
2380
2729
  return !e.runId || !t.runId ? !0 : e.runId === t.runId;
2381
2730
  }
2382
- function T(e, t) {
2731
+ function E(e, t) {
2383
2732
  return e && typeof e == "object" && typeof e[t] == "string" ? e[t] : null;
2384
2733
  }
2385
- function tn(e, t) {
2734
+ function Yn(e, t) {
2386
2735
  try {
2387
- const s = window.localStorage.getItem(`${jt}${e}`);
2736
+ const s = window.localStorage.getItem(`${Re}${e}`);
2388
2737
  if (!s)
2389
2738
  return null;
2390
2739
  const n = JSON.parse(s), r = typeof n.sessionId == "string" ? n.sessionId : null;
2391
2740
  if (t !== void 0 && r !== t)
2392
2741
  return null;
2393
- const i = Array.isArray(n.messages) ? n.messages.map(pn).filter((o) => !!o) : [];
2742
+ const i = Array.isArray(n.messages) ? n.messages.map(lr).filter((o) => !!o) : [];
2394
2743
  return {
2395
2744
  sessionId: r,
2396
2745
  messages: i
@@ -2399,48 +2748,48 @@ function tn(e, t) {
2399
2748
  return null;
2400
2749
  }
2401
2750
  }
2402
- function en(e, t) {
2751
+ function Zn(e, t) {
2403
2752
  try {
2404
2753
  window.localStorage.setItem(
2405
- `${jt}${e}`,
2754
+ `${Re}${e}`,
2406
2755
  JSON.stringify({
2407
2756
  sessionId: t.sessionId,
2408
- messages: t.messages.slice(-We).map(fn)
2757
+ messages: t.messages.slice(-Us).map(ur)
2409
2758
  })
2410
2759
  );
2411
2760
  } catch {
2412
2761
  return;
2413
2762
  }
2414
2763
  }
2415
- function sn(e) {
2764
+ function Qn(e) {
2416
2765
  try {
2417
- const t = window.localStorage.getItem(`${nt}${e}`);
2766
+ const t = window.localStorage.getItem(`${Pt}${e}`);
2418
2767
  if (!t)
2419
2768
  return [];
2420
2769
  const s = JSON.parse(t);
2421
- return Array.isArray(s) ? s.filter(yt) : [];
2770
+ return Array.isArray(s) ? s.filter(zt) : [];
2422
2771
  } catch {
2423
2772
  return [];
2424
2773
  }
2425
2774
  }
2426
- function U(e, t) {
2775
+ function W(e, t) {
2427
2776
  try {
2428
- const s = t.filter(yt);
2777
+ const s = t.filter(zt);
2429
2778
  if (s.length === 0) {
2430
- window.localStorage.removeItem(`${nt}${e}`);
2779
+ window.localStorage.removeItem(`${Pt}${e}`);
2431
2780
  return;
2432
2781
  }
2433
2782
  window.localStorage.setItem(
2434
- `${nt}${e}`,
2783
+ `${Pt}${e}`,
2435
2784
  JSON.stringify(s.slice(-25))
2436
2785
  );
2437
2786
  } catch {
2438
2787
  return;
2439
2788
  }
2440
2789
  }
2441
- function Yt(e, t) {
2790
+ function xe(e, t) {
2442
2791
  try {
2443
- const s = `${z}${e}`, n = location.href, r = location.origin, i = Array.from(t, (o) => ({
2792
+ const s = `${ot}${e}`, n = location.href, r = location.origin, i = Array.from(t, (o) => ({
2444
2793
  ...o,
2445
2794
  storedAt: Date.now(),
2446
2795
  unloadUrl: n,
@@ -2454,28 +2803,28 @@ function Yt(e, t) {
2454
2803
  } catch {
2455
2804
  }
2456
2805
  }
2457
- function nn(e, t) {
2806
+ function tr(e, t) {
2458
2807
  try {
2459
- if (window.sessionStorage.getItem(`${z}${e}`) === null)
2808
+ if (window.sessionStorage.getItem(`${ot}${e}`) === null)
2460
2809
  return;
2461
2810
  } catch {
2462
2811
  return;
2463
2812
  }
2464
- Yt(e, t);
2813
+ xe(e, t);
2465
2814
  }
2466
- function rn(e) {
2815
+ function er(e) {
2467
2816
  try {
2468
- const t = `${z}${e}`, s = window.sessionStorage.getItem(t);
2817
+ const t = `${ot}${e}`, s = window.sessionStorage.getItem(t);
2469
2818
  if (window.sessionStorage.removeItem(t), !s)
2470
2819
  return [];
2471
2820
  const n = JSON.parse(s);
2472
- return Array.isArray(n) ? n.flatMap((r) => an(r) ? [{
2821
+ return Array.isArray(n) ? n.flatMap((r) => nr(r) ? [{
2473
2822
  ...r.event,
2474
- page: w(),
2823
+ page: R(),
2475
2824
  rawOutput: {
2476
2825
  pageContextRestarted: !0,
2477
2826
  outcome: "unknown",
2478
- message: on(location.href),
2827
+ message: sr(location.href),
2479
2828
  currentUrl: location.href,
2480
2829
  console: [],
2481
2830
  metadata: {
@@ -2492,17 +2841,17 @@ function rn(e) {
2492
2841
  return [];
2493
2842
  }
2494
2843
  }
2495
- function on(e) {
2844
+ function sr(e) {
2496
2845
  return `The page context restarted. This is expected when the action included page navigation. Otherwise, it's unknown whether the action completed.
2497
2846
  Current URL: ${e}`;
2498
2847
  }
2499
- function an(e) {
2848
+ function nr(e) {
2500
2849
  if (!e || typeof e != "object")
2501
2850
  return !1;
2502
2851
  const t = e, s = t.event;
2503
- return typeof t.startedAtMs == "number" && typeof t.startedAtUrl == "string" && t.startedAtOrigin === location.origin && t.unloadOrigin === location.origin && typeof t.unloadUrl == "string" && yt(s) && s.type === "tool.result";
2852
+ return typeof t.startedAtMs == "number" && typeof t.startedAtUrl == "string" && t.startedAtOrigin === location.origin && t.unloadOrigin === location.origin && typeof t.unloadUrl == "string" && zt(s) && s.type === "tool.result";
2504
2853
  }
2505
- function cn(e, t) {
2854
+ function rr(e, t) {
2506
2855
  const s = new Set(
2507
2856
  e.flatMap((n) => n.type === "tool.result" ? [n.callId] : [])
2508
2857
  );
@@ -2511,26 +2860,26 @@ function cn(e, t) {
2511
2860
  ...t.filter((n) => !s.has(n.callId))
2512
2861
  ];
2513
2862
  }
2514
- function ln(e) {
2863
+ function ir(e) {
2515
2864
  try {
2516
- window.sessionStorage.removeItem(`${z}${e}`);
2865
+ window.sessionStorage.removeItem(`${ot}${e}`);
2517
2866
  } catch {
2518
2867
  return;
2519
2868
  }
2520
2869
  }
2521
- function yt(e) {
2870
+ function zt(e) {
2522
2871
  if (!e || typeof e != "object")
2523
2872
  return !1;
2524
2873
  const t = e;
2525
- return t.type === "chat.user_message" ? typeof t.content == "string" && Ot(t.page) : t.type === "page.upsert" || t.type === "session.reset" || t.type === "network.batch" ? Ot(t.page) : t.type === "tool.result" ? typeof t.sessionId == "string" && typeof t.callId == "string" && (t.toolName === "execute_code" || t.toolName === "execute_code_in_browser_tab") : t.type === "chat.retry_last_user_message" ? typeof t.sessionId == "string" && typeof t.clientMessageId == "string" : t.type === "run.stop" ? typeof t.sessionId == "string" && (t.reason === "user_requested" || t.reason === "new_chat" || t.reason === "session_switch") : !1;
2874
+ return t.type === "chat.user_message" ? typeof t.content == "string" && Te(t.page) : t.type === "page.upsert" || t.type === "session.reset" || t.type === "network.batch" ? Te(t.page) : t.type === "tool.result" ? typeof t.sessionId == "string" && typeof t.callId == "string" && (t.toolName === "execute_code" || t.toolName === "execute_code_in_browser_tab") : t.type === "chat.retry_last_user_message" ? typeof t.sessionId == "string" && typeof t.clientMessageId == "string" : t.type === "run.stop" ? typeof t.sessionId == "string" && (t.reason === "user_requested" || t.reason === "new_chat" || t.reason === "session_switch") : !1;
2526
2875
  }
2527
- function Ot(e) {
2876
+ function Te(e) {
2528
2877
  if (!e || typeof e != "object")
2529
2878
  return !1;
2530
2879
  const t = e;
2531
2880
  return typeof t.url == "string" && typeof t.title == "string" && typeof t.origin == "string";
2532
2881
  }
2533
- function Zt(e, t) {
2882
+ function Be(e, t) {
2534
2883
  if (!Array.isArray(e))
2535
2884
  return;
2536
2885
  const s = e.filter((r) => {
@@ -2538,24 +2887,24 @@ function Zt(e, t) {
2538
2887
  return !1;
2539
2888
  const i = r;
2540
2889
  return typeof i.name == "string" && typeof i.mimeType == "string" && typeof i.sizeBytes == "number";
2541
- }), n = t ? s.map((r) => Qt(r, t)) : s;
2890
+ }), n = t ? s.map((r) => qe(r, t)) : s;
2542
2891
  return n.length > 0 ? n : void 0;
2543
2892
  }
2544
- function Qt(e, t) {
2893
+ function qe(e, t) {
2545
2894
  return e.fileUrl?.startsWith("/") ? {
2546
2895
  ...e,
2547
2896
  fileUrl: new URL(e.fileUrl, t).toString()
2548
2897
  } : e;
2549
2898
  }
2550
- function un(e) {
2551
- if (dn(e))
2899
+ function or(e) {
2900
+ if (ar(e))
2552
2901
  return {
2553
2902
  headers: {
2554
2903
  "ngrok-skip-browser-warning": "true"
2555
2904
  }
2556
2905
  };
2557
2906
  }
2558
- function dn(e) {
2907
+ function ar(e) {
2559
2908
  try {
2560
2909
  const t = new URL(e).hostname;
2561
2910
  return t.endsWith(".ngrok-free.dev") || t.endsWith(".ngrok-free.app") || t.endsWith(".ngrok.app") || t.endsWith(".ngrok.io");
@@ -2563,14 +2912,14 @@ function dn(e) {
2563
2912
  return !1;
2564
2913
  }
2565
2914
  }
2566
- function Lt(e) {
2567
- return e.type || hn(e.name) || "application/octet-stream";
2915
+ function Ie(e) {
2916
+ return e.type || cr(e.name) || "application/octet-stream";
2568
2917
  }
2569
- function hn(e) {
2918
+ function cr(e) {
2570
2919
  const t = e.toLowerCase();
2571
2920
  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;
2572
2921
  }
2573
- function pn(e) {
2922
+ function lr(e) {
2574
2923
  if (!e || typeof e != "object")
2575
2924
  return null;
2576
2925
  const t = e;
@@ -2583,17 +2932,17 @@ function pn(e) {
2583
2932
  ...typeof t.runId == "string" ? { runId: t.runId } : {},
2584
2933
  dataType: typeof t.dataType == "string" ? t.dataType : void 0,
2585
2934
  securitySettingsUrl: typeof t.securitySettingsUrl == "string" ? t.securitySettingsUrl : void 0,
2586
- attachments: Zt(t.attachments)?.map(It),
2935
+ attachments: Be(t.attachments)?.map(Gt),
2587
2936
  loading: typeof t.loading == "boolean" ? t.loading : void 0
2588
2937
  };
2589
2938
  }
2590
- function fn(e) {
2939
+ function ur(e) {
2591
2940
  return e.attachments?.length ? {
2592
2941
  ...e,
2593
- attachments: e.attachments.map(It)
2942
+ attachments: e.attachments.map(Gt)
2594
2943
  } : e;
2595
2944
  }
2596
- function It(e) {
2945
+ function Gt(e) {
2597
2946
  const {
2598
2947
  dataUrl: t,
2599
2948
  objectUrl: s,
@@ -2602,68 +2951,68 @@ function It(e) {
2602
2951
  } = e;
2603
2952
  return r;
2604
2953
  }
2605
- function R(e) {
2954
+ function O(e) {
2606
2955
  const t = e.respondsToUserMessageId;
2607
2956
  return typeof t == "string" && t ? t : null;
2608
2957
  }
2609
- function S(e) {
2958
+ function M(e) {
2610
2959
  const t = e.runId;
2611
2960
  return typeof t == "string" && t ? t : null;
2612
2961
  }
2613
- function gn(e) {
2962
+ function dr(e) {
2614
2963
  const t = e?.timeoutMs;
2615
- return !!e && typeof e == "object" && typeof e.summary == "string" && typeof e.javascript == "string" && (t === void 0 || typeof t == "number" && Number.isInteger(t) && t > 0 && t <= Ve);
2964
+ return !!e && typeof e == "object" && typeof e.summary == "string" && typeof e.javascript == "string" && (t === void 0 || typeof t == "number" && Number.isInteger(t) && t > 0 && t <= qs);
2616
2965
  }
2617
- function te(e) {
2966
+ function He(e) {
2618
2967
  const t = {};
2619
2968
  try {
2620
2969
  new Headers(e).forEach((s, n) => {
2621
- Object.keys(t).length < ht && (t[n] = Tt(n, s));
2970
+ Object.keys(t).length < Ht && (t[n] = Xt(n, s));
2622
2971
  });
2623
2972
  } catch {
2624
2973
  return {};
2625
2974
  }
2626
2975
  return t;
2627
2976
  }
2628
- function Tt(e, t) {
2629
- return oe(e) ? X : k(j(t), xe);
2977
+ function Xt(e, t) {
2978
+ return Ge(e) ? lt : C(rt(t), Ms);
2630
2979
  }
2631
- function mn(e, t) {
2980
+ function hr(e, t) {
2632
2981
  return typeof e == "string" ? e : e instanceof URL ? e.toString() : t?.url ?? "";
2633
2982
  }
2634
- async function yn(e, t, s, n) {
2635
- const r = te(e.headers);
2983
+ async function pr(e, t, s, n) {
2984
+ const r = He(e.headers);
2636
2985
  n({
2637
2986
  ...t,
2638
2987
  responseStatus: e.status,
2639
2988
  responseHeaders: r,
2640
- responseBody: await In(e),
2989
+ responseBody: await fr(e),
2641
2990
  durationMs: Date.now() - s
2642
2991
  });
2643
2992
  }
2644
- async function In(e) {
2645
- if (!ee(e.headers))
2993
+ async function fr(e) {
2994
+ if (!Fe(e.headers))
2646
2995
  return;
2647
2996
  let t = null, s = null;
2648
2997
  try {
2649
2998
  if (t = e.clone().body?.getReader() ?? null, !t)
2650
2999
  return;
2651
- const n = new Promise((l) => {
3000
+ const n = new Promise((a) => {
2652
3001
  s = window.setTimeout(() => {
2653
- t?.cancel(), l("timeout");
2654
- }, Fe);
3002
+ t?.cancel(), a("timeout");
3003
+ }, Cs);
2655
3004
  }), r = new TextDecoder();
2656
3005
  let i = "", o = 0;
2657
3006
  for (; ; ) {
2658
- const l = await Promise.race([t.read(), n]);
2659
- if (l === "timeout")
3007
+ const a = await Promise.race([t.read(), n]);
3008
+ if (a === "timeout")
2660
3009
  return;
2661
- const { done: u, value: c } = l;
3010
+ const { done: u, value: c } = a;
2662
3011
  if (u)
2663
- return k(i + r.decode());
2664
- const a = dt - o;
2665
- if (c.byteLength > a)
2666
- return i += r.decode(c.subarray(0, Math.max(a, 0)), { stream: !0 }), t.cancel(), `${k(i)}... [truncated]`;
3012
+ return C(i + r.decode());
3013
+ const l = qt - o;
3014
+ if (c.byteLength > l)
3015
+ return i += r.decode(c.subarray(0, Math.max(l, 0)), { stream: !0 }), t.cancel(), `${C(i)}... [truncated]`;
2667
3016
  o += c.byteLength, i += r.decode(c, { stream: !0 });
2668
3017
  }
2669
3018
  } catch {
@@ -2673,45 +3022,45 @@ async function In(e) {
2673
3022
  s !== null && window.clearTimeout(s);
2674
3023
  }
2675
3024
  }
2676
- function Tn(e, t) {
2677
- if (ee(new Headers(t)))
3025
+ function gr(e, t) {
3026
+ if (Fe(new Headers(t)))
2678
3027
  try {
2679
- return e.responseType === "" || e.responseType === "text" ? k(e.responseText ?? "") : void 0;
3028
+ return e.responseType === "" || e.responseType === "text" ? C(e.responseText ?? "") : void 0;
2680
3029
  } catch {
2681
3030
  return;
2682
3031
  }
2683
3032
  }
2684
- function Bt(e) {
3033
+ function we(e) {
2685
3034
  if (typeof e == "string")
2686
- return k(e);
3035
+ return C(e);
2687
3036
  }
2688
- function wn(e) {
2689
- return A({
3037
+ function mr(e) {
3038
+ return _({
2690
3039
  ...e,
2691
- requestBody: vt(e.requestBody),
2692
- responseBody: vt(e.responseBody)
3040
+ requestBody: Ae(e.requestBody),
3041
+ responseBody: Ae(e.responseBody)
2693
3042
  });
2694
3043
  }
2695
- function vt(e) {
3044
+ function Ae(e) {
2696
3045
  if (typeof e != "string")
2697
3046
  return e;
2698
3047
  const t = e.trim();
2699
3048
  if (!t.startsWith("{") && !t.startsWith("["))
2700
- return j(e);
3049
+ return rt(e);
2701
3050
  try {
2702
- return JSON.stringify(A(JSON.parse(e)));
3051
+ return JSON.stringify(_(JSON.parse(e)));
2703
3052
  } catch {
2704
- return j(e);
3053
+ return rt(e);
2705
3054
  }
2706
3055
  }
2707
- function ee(e) {
3056
+ function Fe(e) {
2708
3057
  if (!e)
2709
3058
  return !1;
2710
3059
  const t = e.get("content-type")?.toLowerCase() ?? "", s = e.get("content-length"), n = Number(s);
2711
- return s !== null && Number.isInteger(n) && n >= 0 && n <= dt && (t.startsWith("text/") || t.includes("json") || t.includes("javascript"));
3060
+ return s !== null && Number.isInteger(n) && n >= 0 && n <= qt && (t.startsWith("text/") || t.includes("json") || t.includes("javascript"));
2712
3061
  }
2713
- function b(e, t = {}, s) {
2714
- if (Sn(s))
3062
+ function v(e, t = {}, s) {
3063
+ if (Tr(s))
2715
3064
  return !0;
2716
3065
  const n = Object.entries(t).find(([r]) => r.toLowerCase() === "content-type")?.[1]?.toLowerCase();
2717
3066
  if (n?.includes("multipart/form-data") || n?.includes("application/octet-stream"))
@@ -2721,13 +3070,13 @@ function b(e, t = {}, s) {
2721
3070
  if (r.protocol !== "http:" && r.protocol !== "https:")
2722
3071
  return !0;
2723
3072
  const i = r.hostname.toLowerCase(), o = r.pathname.toLowerCase();
2724
- return i === "pluno.ai" || i.endsWith(".pluno.ai") || o === "/api/product-agent" || o.startsWith("/api/product-agent/") || /(^|\/)(auth|oauth|login|logout)(\/|$)/.test(o) || /(^|\/)[^/]*token[^/]*(\/|$)/.test(o) || /(^|\/)(upload|uploads|attachments)(\/|$)/.test(o) || [...r.searchParams.keys()].some((l) => /^(x-amz-signature|x-goog-signature|signature|sig)$/i.test(l));
3073
+ return i === "pluno.ai" || i.endsWith(".pluno.ai") || o === "/api/product-agent" || o.startsWith("/api/product-agent/") || /(^|\/)(auth|oauth|login|logout)(\/|$)/.test(o) || /(^|\/)[^/]*token[^/]*(\/|$)/.test(o) || /(^|\/)(upload|uploads|attachments)(\/|$)/.test(o) || [...r.searchParams.keys()].some((a) => /^(x-amz-signature|x-goog-signature|signature|sig)$/i.test(a));
2725
3074
  } catch {
2726
3075
  return !0;
2727
3076
  }
2728
3077
  }
2729
- function An(e, t) {
2730
- if (b(e))
3078
+ function yr(e, t) {
3079
+ if (v(e))
2731
3080
  return !0;
2732
3081
  try {
2733
3082
  const s = new URL(e, location.href), n = new URL(t);
@@ -2736,115 +3085,115 @@ function An(e, t) {
2736
3085
  return !0;
2737
3086
  }
2738
3087
  }
2739
- function Sn(e) {
3088
+ function Tr(e) {
2740
3089
  return e instanceof FormData || e instanceof Blob || e instanceof ArrayBuffer || ArrayBuffer.isView(e) || typeof ReadableStream < "u" && e instanceof ReadableStream;
2741
3090
  }
2742
- function kn(e) {
3091
+ function Ir(e) {
2743
3092
  const t = {};
2744
3093
  for (const s of e.trim().split(/[\r\n]+/)) {
2745
3094
  const n = s.indexOf(":");
2746
3095
  if (n <= 0)
2747
3096
  continue;
2748
- if (Object.keys(t).length >= ht)
3097
+ if (Object.keys(t).length >= Ht)
2749
3098
  break;
2750
3099
  const r = s.slice(0, n).trim();
2751
- t[r] = Tt(r, s.slice(n + 1).trim());
3100
+ t[r] = Xt(r, s.slice(n + 1).trim());
2752
3101
  }
2753
3102
  return t;
2754
3103
  }
2755
- function k(e, t = dt) {
3104
+ function C(e, t = qt) {
2756
3105
  return e.length <= t ? e : `${e.slice(0, t)}... [truncated ${e.length - t} chars]`;
2757
3106
  }
2758
- function Q(e) {
3107
+ function Rt(e) {
2759
3108
  return `${e}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
2760
3109
  }
2761
- class H extends Error {
3110
+ class st extends Error {
2762
3111
  constructor(t, s) {
2763
3112
  super(`${t} (${s})`), this.status = s, this.name = "AttachmentUploadHttpError";
2764
3113
  }
2765
3114
  status;
2766
3115
  }
2767
- async function tt(e, t) {
3116
+ async function _t(e, t) {
2768
3117
  let s = null;
2769
- for (let n = 0; n < Et; n += 1)
3118
+ for (let n = 0; n < ae; n += 1)
2770
3119
  try {
2771
3120
  return await e();
2772
3121
  } catch (r) {
2773
- if (s = r, n >= Et - 1 || !Rn(r))
3122
+ if (s = r, n >= ae - 1 || !Ar(r))
2774
3123
  throw r;
2775
- await En(n);
3124
+ await wr(n);
2776
3125
  }
2777
3126
  throw s instanceof Error ? s : new Error(t);
2778
3127
  }
2779
- function En(e) {
3128
+ function wr(e) {
2780
3129
  return new Promise((t) => {
2781
- window.setTimeout(t, qe[e] ?? 0);
3130
+ window.setTimeout(t, _s[e] ?? 0);
2782
3131
  });
2783
3132
  }
2784
- function Rn(e) {
2785
- return e instanceof H ? _n(e.status) : e instanceof TypeError;
3133
+ function Ar(e) {
3134
+ return e instanceof st ? Sr(e.status) : e instanceof TypeError;
2786
3135
  }
2787
- function _n(e) {
3136
+ function Sr(e) {
2788
3137
  return e === 408 || e === 409 || e === 429 || e >= 500;
2789
3138
  }
2790
- function bn(e) {
3139
+ function Er(e) {
2791
3140
  return e === 401 || e === 403;
2792
3141
  }
2793
- const X = "[REDACTED_SECRET]", E = "[REDACTED_TOKEN]", Mn = "[REDACTED_SIGNED_URL]", Cn = 20, Pn = /^(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, se = /\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi, ne = /\bBasic\s+[A-Za-z0-9+/=-]{12,}/gi, re = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g, ie = /\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, Un = /\bhttps?:\/\/[^\s"'<>]+(?:X-Amz-Signature|X-Goog-Signature|Signature|sig=)[^\s"'<>]*/gi, Dn = /\bhttps?:\/\/[^\s"'<>]+/gi, Nn = /[),.;\]]+$/;
2794
- function A(e) {
2795
- return W(e, 0, /* @__PURE__ */ new WeakSet());
3142
+ const lt = "[REDACTED_SECRET]", P = "[REDACTED_TOKEN]", kr = "[REDACTED_SIGNED_URL]", br = 20, Rr = /^(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, We = /\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi, $e = /\bBasic\s+[A-Za-z0-9+/=-]{12,}/gi, je = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g, ze = /\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, _r = /\bhttps?:\/\/[^\s"'<>]+(?:X-Amz-Signature|X-Goog-Signature|Signature|sig=)[^\s"'<>]*/gi, Mr = /\bhttps?:\/\/[^\s"'<>]+/gi, Cr = /[),.;\]]+$/;
3143
+ function _(e) {
3144
+ return nt(e, 0, /* @__PURE__ */ new WeakSet());
2796
3145
  }
2797
- function W(e, t, s) {
3146
+ function nt(e, t, s) {
2798
3147
  if (typeof e == "string")
2799
- return e.startsWith("data:image/") || e.startsWith("data:application/pdf;") ? e : j(e);
3148
+ return e.startsWith("data:image/") || e.startsWith("data:application/pdf;") ? e : rt(e);
2800
3149
  if (e === null || typeof e != "object")
2801
3150
  return e;
2802
- if (t >= Cn)
3151
+ if (t >= br)
2803
3152
  return "[REDACTED_MAX_DEPTH]";
2804
3153
  if (s.has(e))
2805
3154
  return "[REDACTED_CIRCULAR]";
2806
3155
  if (s.add(e), Array.isArray(e))
2807
- return e.map((r) => W(r, t + 1, s));
3156
+ return e.map((r) => nt(r, t + 1, s));
2808
3157
  const n = {};
2809
3158
  for (const [r, i] of Object.entries(e))
2810
- oe(r) ? n[r] = X : n[r] = r.toLowerCase() === "url" ? On(i) : W(i, t + 1, s);
3159
+ r === "pageContent" ? n[r] = i : Ge(r) ? n[r] = lt : n[r] = r.toLowerCase() === "url" ? Pr(i) : nt(i, t + 1, s);
2811
3160
  return n;
2812
3161
  }
2813
- function oe(e) {
3162
+ function Ge(e) {
2814
3163
  const t = e.replace(/[^a-z0-9]/gi, "").toLowerCase();
2815
3164
  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");
2816
3165
  }
2817
- function On(e) {
2818
- return typeof e == "string" ? ae(e) : W(e, 0, /* @__PURE__ */ new WeakSet());
3166
+ function Pr(e) {
3167
+ return typeof e == "string" ? Xe(e) : nt(e, 0, /* @__PURE__ */ new WeakSet());
2819
3168
  }
2820
- function ae(e) {
3169
+ function Xe(e) {
2821
3170
  try {
2822
3171
  const t = new URL(e, location.href);
2823
3172
  for (const s of Array.from(t.searchParams.keys()))
2824
- Pn.test(s) && t.searchParams.set(s, E);
2825
- return t.username && (t.username = E), t.password && (t.password = E), t.toString();
3173
+ Rr.test(s) && t.searchParams.set(s, P);
3174
+ return t.username && (t.username = P), t.password && (t.password = P), t.toString();
2826
3175
  } catch {
2827
- return Ln(e);
3176
+ return Ur(e);
2828
3177
  }
2829
3178
  }
2830
- function j(e) {
2831
- return e.replace(Un, Mn).replace(Dn, Bn).replace(se, `Bearer ${E}`).replace(ne, `Basic ${E}`).replace(re, E).replace(ie, (t, s) => `${s}: ${X}`);
3179
+ function rt(e) {
3180
+ return e.replace(_r, kr).replace(Mr, Dr).replace(We, `Bearer ${P}`).replace($e, `Basic ${P}`).replace(je, P).replace(ze, (t, s) => `${s}: ${lt}`);
2832
3181
  }
2833
- function Ln(e) {
2834
- return e.replace(se, `Bearer ${E}`).replace(ne, `Basic ${E}`).replace(re, E).replace(ie, (t, s) => `${s}: ${X}`);
3182
+ function Ur(e) {
3183
+ return e.replace(We, `Bearer ${P}`).replace($e, `Basic ${P}`).replace(je, P).replace(ze, (t, s) => `${s}: ${lt}`);
2835
3184
  }
2836
- function Bn(e) {
2837
- const t = e.match(Nn)?.[0] ?? "", s = t ? e.slice(0, -t.length) : e;
2838
- return `${ae(s)}${t}`;
3185
+ function Dr(e) {
3186
+ const t = e.match(Cr)?.[0] ?? "", s = t ? e.slice(0, -t.length) : e;
3187
+ return `${Xe(s)}${t}`;
2839
3188
  }
2840
3189
  export {
2841
- wt as PLUNO_PRODUCT_AGENT_SDK_PREVIEW_HOST_SELECTOR,
2842
- st as PLUNO_PRODUCT_AGENT_WIDGET_HOST_SELECTOR,
2843
- Ae as PLUNO_PRODUCT_AGENT_WIDGET_PANEL_SELECTOR,
2844
- we as PLUNO_PRODUCT_AGENT_WIDGET_ROOT_SELECTOR,
2845
- Se as PLUNO_PRODUCT_AGENT_WIDGET_TIMELINE_SELECTOR,
2846
- $t as PlunoProductAgent,
2847
- $e as calculateReconnectDelay,
2848
- $t as default,
2849
- us as getProductAgentOriginAccessErrorMessage
3190
+ ne as PLUNO_PRODUCT_AGENT_SDK_PREVIEW_HOST_SELECTOR,
3191
+ Ct as PLUNO_PRODUCT_AGENT_WIDGET_HOST_SELECTOR,
3192
+ us as PLUNO_PRODUCT_AGENT_WIDGET_PANEL_SELECTOR,
3193
+ ls as PLUNO_PRODUCT_AGENT_WIDGET_ROOT_SELECTOR,
3194
+ ds as PLUNO_PRODUCT_AGENT_WIDGET_TIMELINE_SELECTOR,
3195
+ _e as PlunoProductAgent,
3196
+ Ns as calculateReconnectDelay,
3197
+ _e as default,
3198
+ tn as getProductAgentOriginAccessErrorMessage
2850
3199
  };