@pluno/product-agent-web 0.1.135 → 0.1.136

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,13 +1,13 @@
1
- const Ge = "pluno-product-agent-attachments";
1
+ const Xe = "pluno-product-agent-attachments";
2
2
  const _t = "files";
3
- async function Xe(e) {
4
- const t = await xt();
5
- await Ve(t, "readwrite", (s) => s.put(e));
6
- }
7
- async function Ke(e, t) {
8
- const s = await xt();
9
- await Nt(s, "readwrite", async (n) => {
10
- const r = await Ot(
3
+ async function Ke(e) {
4
+ const t = await Lt();
5
+ await Ye(t, "readwrite", (s) => s.put(e));
6
+ }
7
+ async function Je(e, t) {
8
+ const s = await Lt();
9
+ await Bt(s, "readwrite", async (n) => {
10
+ const r = await qt(
11
11
  n.get(e)
12
12
  );
13
13
  r && n.put({
@@ -16,26 +16,26 @@ async function Ke(e, t) {
16
16
  });
17
17
  });
18
18
  }
19
- async function Je(e = 864e5) {
20
- const t = await xt(), s = Date.now() - e;
21
- await Nt(t, "readwrite", async (n) => {
19
+ async function Ve(e = 864e5) {
20
+ const t = await Lt(), s = Date.now() - e;
21
+ await Bt(t, "readwrite", async (n) => {
22
22
  const r = n.index("lastUsedAt");
23
- (await Ot(r.getAllKeys(IDBKeyRange.upperBound(s)))).forEach((o) => n.delete(o));
23
+ (await qt(r.getAllKeys(IDBKeyRange.upperBound(s)))).forEach((o) => n.delete(o));
24
24
  });
25
25
  }
26
- function xt() {
26
+ function Lt() {
27
27
  return typeof indexedDB > "u" ? Promise.reject(new Error("Product Agent attachment storage is unavailable")) : new Promise((e, t) => {
28
- const s = indexedDB.open(Ge, 1);
28
+ const s = indexedDB.open(Xe, 1);
29
29
  s.onupgradeneeded = () => {
30
30
  const r = s.result.createObjectStore(_t, { keyPath: "attachmentId" });
31
31
  r.createIndex("lastUsedAt", "lastUsedAt", { unique: !1 }), r.createIndex("sessionId", "sessionId", { unique: !1 }), r.createIndex("origin", "origin", { unique: !1 });
32
32
  }, s.onsuccess = () => e(s.result), s.onerror = () => t(s.error ?? new Error("Failed to open Product Agent attachment storage"));
33
33
  });
34
34
  }
35
- async function Ve(e, t, s) {
36
- return await Nt(e, t, async (n) => await Ot(s(n)));
35
+ async function Ye(e, t, s) {
36
+ return await Bt(e, t, async (n) => await qt(s(n)));
37
37
  }
38
- function Nt(e, t, s) {
38
+ function Bt(e, t, s) {
39
39
  return new Promise((n, r) => {
40
40
  const i = e.transaction(_t, t), o = i.objectStore(_t);
41
41
  let a, c = !1;
@@ -57,16 +57,16 @@ function Nt(e, t, s) {
57
57
  };
58
58
  });
59
59
  }
60
- function Ot(e) {
60
+ function qt(e) {
61
61
  return new Promise((t, s) => {
62
62
  e.onsuccess = () => t(e.result), e.onerror = () => s(e.error ?? new Error("Product Agent attachment storage request failed"));
63
63
  });
64
64
  }
65
- function Ye(e) {
65
+ function Ze(e) {
66
66
  return e !== null && (typeof e == "object" || typeof e == "function");
67
67
  }
68
- function Ie(e, t, s) {
69
- const n = Reflect.get(e, "pluno"), r = Ye(n) ? n : {};
68
+ function Ae(e, t, s) {
69
+ const n = Reflect.get(e, "pluno"), r = Ze(n) ? n : {};
70
70
  if (r !== n && !Reflect.set(e, "pluno", r))
71
71
  return null;
72
72
  const i = Object.getOwnPropertyDescriptor(r, t);
@@ -80,18 +80,18 @@ function Ie(e, t, s) {
80
80
  }
81
81
  };
82
82
  }
83
- const Ze = /(\]\()(\/api\/product-agent\/attachments\/download\?[^)\s]+)(\))/g;
84
- function Qe(e, t) {
83
+ const Qe = /(\]\()(\/api\/product-agent\/attachments\/download\?[^)\s]+)(\))/g;
84
+ function ts(e, t) {
85
85
  return t ? e.replace(
86
- Ze,
86
+ Qe,
87
87
  (s, n, r, i) => `${n}${new URL(r, t).toString()}${i}`
88
88
  ) : e;
89
89
  }
90
- const It = "pluno.productAgent.transportId", ts = "pluno.productAgent.transportIdentity", wt = "pluno.productAgent.transportIdentity.event", es = 50, ss = globalThis.setTimeout.bind(globalThis);
90
+ const wt = "pluno.productAgent.transportId", es = "pluno.productAgent.transportIdentity", At = "pluno.productAgent.transportIdentity.event", ss = 50, ns = globalThis.setTimeout.bind(globalThis);
91
91
  let W = null;
92
- const tt = /* @__PURE__ */ new Set(), At = /* @__PURE__ */ new Map();
93
- async function ns(e = we()) {
94
- const t = e.randomUUID(), s = e.storage.getItem(It);
92
+ const tt = /* @__PURE__ */ new Set(), St = /* @__PURE__ */ new Map();
93
+ async function rs(e = Se()) {
94
+ const t = e.randomUUID(), s = e.storage.getItem(wt);
95
95
  let n = s ?? e.randomUUID(), r = !1, i = !1;
96
96
  const o = e.channel.subscribe((c) => {
97
97
  if (!(c.senderId === t || c.transportId !== n)) {
@@ -109,14 +109,14 @@ async function ns(e = we()) {
109
109
  }
110
110
  });
111
111
  if (!s)
112
- e.storage.setItem(It, n), r = !0;
112
+ e.storage.setItem(wt, n), r = !0;
113
113
  else
114
114
  for (; ; ) {
115
115
  if (i = !1, e.channel.postMessage({ type: "probe", transportId: n, senderId: t }), await e.settle(), !i) {
116
116
  r = !0;
117
117
  break;
118
118
  }
119
- n = e.randomUUID(), e.storage.setItem(It, n);
119
+ n = e.randomUUID(), e.storage.setItem(wt, n);
120
120
  }
121
121
  let a = !1;
122
122
  return {
@@ -126,14 +126,14 @@ async function ns(e = we()) {
126
126
  }
127
127
  };
128
128
  }
129
- async function rs() {
130
- W || (W = ns(we()), W.then((n) => {
129
+ async function is() {
130
+ W || (W = rs(Se()), W.then((n) => {
131
131
  const r = (i) => {
132
132
  i.persisted || (n.release(), W = null, tt.clear(), window.removeEventListener("pagehide", r));
133
133
  };
134
134
  window.addEventListener("pagehide", r);
135
135
  }));
136
- const e = await W, t = is();
136
+ const e = await W, t = os();
137
137
  tt.add(t);
138
138
  let s = !1;
139
139
  return {
@@ -144,31 +144,31 @@ async function rs() {
144
144
  }
145
145
  };
146
146
  }
147
- function is() {
147
+ function os() {
148
148
  let e = 0;
149
149
  for (; tt.has(e); )
150
150
  e += 1;
151
151
  return e;
152
152
  }
153
- function we() {
153
+ function Se() {
154
154
  return {
155
- storage: os(),
156
- channel: as(),
155
+ storage: as(),
156
+ channel: cs(),
157
157
  randomUUID: () => crypto.randomUUID(),
158
- settle: () => new Promise((e) => ss(e, es))
158
+ settle: () => new Promise((e) => ns(e, ss))
159
159
  };
160
160
  }
161
- function os() {
161
+ function as() {
162
162
  return {
163
163
  getItem: (e) => {
164
164
  try {
165
- return window.sessionStorage?.getItem(e) ?? At.get(e) ?? null;
165
+ return window.sessionStorage?.getItem(e) ?? St.get(e) ?? null;
166
166
  } catch {
167
- return At.get(e) ?? null;
167
+ return St.get(e) ?? null;
168
168
  }
169
169
  },
170
170
  setItem: (e, t) => {
171
- At.set(e, t);
171
+ St.set(e, t);
172
172
  try {
173
173
  window.sessionStorage?.setItem(e, t);
174
174
  } catch {
@@ -176,9 +176,9 @@ function os() {
176
176
  }
177
177
  };
178
178
  }
179
- function as() {
179
+ function cs() {
180
180
  if (typeof BroadcastChannel < "u") {
181
- const e = new BroadcastChannel(ts);
181
+ const e = new BroadcastChannel(es);
182
182
  return {
183
183
  postMessage: (t) => e.postMessage(t),
184
184
  subscribe: (t) => {
@@ -188,11 +188,11 @@ function as() {
188
188
  close: () => e.close()
189
189
  };
190
190
  }
191
- return cs();
191
+ return ls();
192
192
  }
193
- function cs() {
193
+ function ls() {
194
194
  const e = /* @__PURE__ */ new Set(), t = (s) => {
195
- if (s.key !== wt || !s.newValue)
195
+ if (s.key !== At || !s.newValue)
196
196
  return;
197
197
  const n = JSON.parse(s.newValue);
198
198
  for (const r of e)
@@ -201,9 +201,9 @@ function cs() {
201
201
  return window.addEventListener("storage", t), {
202
202
  postMessage: (s) => {
203
203
  window.localStorage.setItem(
204
- wt,
204
+ At,
205
205
  JSON.stringify({ ...s, eventId: crypto.randomUUID() })
206
- ), window.localStorage.removeItem(wt);
206
+ ), window.localStorage.removeItem(At);
207
207
  },
208
208
  subscribe: (s) => (e.add(s), () => e.delete(s)),
209
209
  close: () => {
@@ -211,18 +211,18 @@ function cs() {
211
211
  }
212
212
  };
213
213
  }
214
- const ls = globalThis.fetch.bind(globalThis), Mt = '.pluno-pa-widget-host[data-pluno-product-agent-ui="widget"]', us = '.pluno-pa-widget[data-pluno-product-agent-ui-root="widget"]', ds = ".pluno-pa-widget__panel", hs = ".pluno-pa-widget__timeline", te = `${Mt}[data-pluno-sdk-preview-channel]`, ps = "https://app.pluno.ai", fs = "gpt-5.6-terra", gs = 2e4, ms = 1e4, ys = 1e4, Ts = 1e4, Is = 1e4, ws = 1e3, ee = 3e4, se = 0.2, ne = 6e4, As = 15e3, J = 8, Ss = 15e3, Es = 2e3, bs = 1e3, ks = 100, Rs = 8e3, re = 3, _s = [300, 1e3], Lt = 64e3, St = 4e3, Bt = 30, Ms = 2e3, Cs = 1e3, Ae = "Image is too large for model vision input.", Ps = 100, Se = "pluno.productAgent.state.", Ct = "pluno.productAgent.pendingEvents.", it = "pluno.productAgent.activeToolCalls.", Us = 100;
214
+ const us = globalThis.fetch.bind(globalThis), Ct = '.pluno-pa-widget-host[data-pluno-product-agent-ui="widget"]', ds = '.pluno-pa-widget[data-pluno-product-agent-ui-root="widget"]', hs = ".pluno-pa-widget__panel", ps = ".pluno-pa-widget__timeline", se = `${Ct}[data-pluno-sdk-preview-channel]`, fs = "https://app.pluno.ai", gs = "gpt-5.6-terra", ms = 2e4, ys = 1e4, Is = 1e4, Ts = 1e4, ws = 1e4, As = 1e3, ne = 3e4, re = 0.2, ie = 6e4, Ss = 15e3, J = 8, Es = 15e3, bs = 2e3, ks = 1e3, Rs = 100, Ms = 8e3, oe = 3, _s = [300, 1e3], Ht = 64e3, Et = 4e3, Ft = 30, Cs = 2e3, Us = 1e3, Ee = "Image is too large for model vision input.", Ps = 100, be = "pluno.productAgent.state.", Ut = "pluno.productAgent.pendingEvents.", it = "pluno.productAgent.activeToolCalls.", Ds = 100;
215
215
  function V(e, t = 0) {
216
216
  const s = e === 0 ? 0 : Math.min(3e4, 1e3 * 2 ** (e - 1));
217
217
  return Math.max(t, s);
218
218
  }
219
219
  const et = /* @__PURE__ */ new Set();
220
220
  let Y = null;
221
- function Ds(e, t = Math.random) {
222
- const s = Math.min(ee, ws * 2 ** e), n = 1 - se + t() * se * 2;
223
- return Math.min(ee, Math.round(s * n));
221
+ function vs(e, t = Math.random) {
222
+ const s = Math.min(ne, As * 2 ** e), n = 1 - re + t() * re * 2;
223
+ return Math.min(ne, Math.round(s * n));
224
224
  }
225
- function vs(e, t, s) {
225
+ function xs(e, t, s) {
226
226
  return new Promise((n, r) => {
227
227
  const i = setTimeout(() => r(new Error(s)), t);
228
228
  e.then(
@@ -235,13 +235,13 @@ function vs(e, t, s) {
235
235
  );
236
236
  });
237
237
  }
238
- class Ee {
238
+ class ke {
239
239
  constructor(t, s) {
240
240
  this.options = t, this.transportIdentity = s, this.state = {
241
241
  ...this.state,
242
- starterPrompts: fn(t.initialStarterPrompts)
242
+ starterPrompts: gn(t.initialStarterPrompts)
243
243
  };
244
- const n = t.restorePersistedState === !1 ? null : Zn(t.clientId, t.expectedPersistedSessionId);
244
+ const n = t.restorePersistedState === !1 ? null : sr(t.clientId, t.expectedPersistedSessionId);
245
245
  n && (this.state = {
246
246
  ...this.state,
247
247
  ...n,
@@ -254,9 +254,9 @@ class Ee {
254
254
  assistantDraftRunId: null,
255
255
  isThinking: !1,
256
256
  lastError: null
257
- }), this.queuedClientEvents = ir(
258
- tr(t.clientId),
259
- sr(t.clientId)
257
+ }), this.queuedClientEvents = lr(
258
+ rr(t.clientId),
259
+ or(t.clientId)
260
260
  ), $(t.clientId, this.queuedClientEvents);
261
261
  }
262
262
  options;
@@ -325,15 +325,15 @@ class Ee {
325
325
  lastErrorSecuritySettingsUrl: null
326
326
  };
327
327
  static async init(t) {
328
- const s = await rs(), n = new Ee({
328
+ const s = await is(), n = new ke({
329
329
  ...t,
330
- backendUrl: Zs(t.backendUrl ?? ps),
331
- clientId: t.clientId ?? In(),
332
- model: t.model ?? fs,
333
- entrySurface: Qs(t.entrySurface)
330
+ backendUrl: Qs(t.backendUrl ?? fs),
331
+ clientId: t.clientId ?? wn(),
332
+ model: t.model ?? gs,
333
+ entrySurface: tn(t.entrySurface)
334
334
  }, s);
335
335
  try {
336
- Je().catch((r) => {
336
+ Ve().catch((r) => {
337
337
  A("web-sdk.attachments", "Failed to delete stale Product Agent attachments", {
338
338
  message: r instanceof Error ? r.message : String(r)
339
339
  });
@@ -365,11 +365,11 @@ class Ee {
365
365
  lastError: null
366
366
  });
367
367
  try {
368
- if (this.token = this.options.token ?? (this.options.tokenProvider ? await vs(this.options.tokenProvider(), ys, "Pluno token provider timed out") : null), t !== this.connectionAttemptId || this.state.status === "closed")
368
+ if (this.token = this.options.token ?? (this.options.tokenProvider ? await xs(this.options.tokenProvider(), Is, "Pluno token provider timed out") : null), t !== this.connectionAttemptId || this.state.status === "closed")
369
369
  return;
370
370
  if (!this.token && !this.options.webSocketFactory)
371
371
  throw new Error("Pluno requires a token or tokenProvider");
372
- const s = sn(this.options.backendUrl), n = this.options.webSocketFactory?.(s) ?? new WebSocket(s);
372
+ const s = nn(this.options.backendUrl), n = this.options.webSocketFactory?.(s) ?? new WebSocket(s);
373
373
  this.socket = n, this.socketConnectTimer = window.setTimeout(() => {
374
374
  this.socket === n && n.readyState === WebSocket.CONNECTING && (A("web-sdk.agent", "Pluno socket opening timed out; reconnecting"), this.replaceTimedOutSocket(n));
375
375
  }, Ts), n.addEventListener("open", () => {
@@ -384,9 +384,9 @@ class Ee {
384
384
  pageUrl: location.href
385
385
  }) : !0)) || (this.socketAuthTimer = window.setTimeout(() => {
386
386
  this.socket === n && (A("web-sdk.agent", "Pluno socket authentication timed out; reconnecting"), this.replaceTimedOutSocket(n));
387
- }, Is));
387
+ }, ws));
388
388
  }), n.addEventListener("message", (r) => {
389
- this.socket === n && this.handleServerEvent(pn(r.data));
389
+ this.socket === n && this.handleServerEvent(fn(r.data));
390
390
  }), n.addEventListener("close", (r) => {
391
391
  this.socket === n && (this.clearSocketPhaseTimers(), this.stopHeartbeat(), this.socket = null, this.state.status !== "closed" && (A("web-sdk.agent", "Pluno socket closed; scheduling reconnect", {
392
392
  code: typeof r?.code == "number" ? r.code : null,
@@ -419,7 +419,7 @@ class Ee {
419
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.pendingWarmupEvent = null, this.socket?.close(), this.socket = null;
420
420
  }
421
421
  destroy() {
422
- this.disconnect(), this.locationChangeCleanup?.(), this.locationChangeCleanup = null, this.cleanupSessionUserFilesApi(), this.pageLifecycleCleanup?.(), this.pageLifecycleCleanup = null, this.activeBrowserToolCalls.clear(), or(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(), ur(this.options.clientId), this.transportIdentity.release(), this.networkCaptureCleanup?.(), this.networkCaptureCleanup = null, this.networkBatchTimer !== null && (window.clearTimeout(this.networkBatchTimer), this.networkBatchTimer = null), this.queuedNetworkEvents = [];
423
423
  for (const t of Object.values(this.listeners))
424
424
  t?.clear();
425
425
  }
@@ -434,16 +434,16 @@ class Ee {
434
434
  }
435
435
  async sendMessage(t, s = {}) {
436
436
  const n = t.trim(), r = s.attachments ?? [];
437
- let i = r.map($t);
437
+ let i = r.map(zt);
438
438
  if (!n && i.length === 0)
439
439
  return null;
440
- const o = k(), a = s.clientMessageId ?? kt(), c = {
440
+ const o = k(), a = s.clientMessageId ?? Rt(), c = {
441
441
  id: `local-${a}`,
442
442
  role: "user",
443
443
  content: n,
444
444
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
445
445
  ...r.length > 0 ? { attachments: r } : {}
446
- }, l = this.state.messages.some((u) => u.id === c.id || u.clientMessageId === a), d = this.state.isThinking, p = {
446
+ }, l = this.state.messages.some((h) => h.id === c.id || h.clientMessageId === a), u = this.state.isThinking, p = this.state.messages, I = l ? this.state.messages : [...this.state.messages, c], m = {
447
447
  assistantDraft: this.state.assistantDraft,
448
448
  assistantDraftItemId: this.state.assistantDraftItemId,
449
449
  assistantDraftPhase: this.state.assistantDraftPhase,
@@ -452,8 +452,8 @@ class Ee {
452
452
  lastError: this.state.lastError
453
453
  };
454
454
  this.setState({
455
- ...l ? {} : { messages: [...this.state.messages, c] },
456
- ...d ? {} : {
455
+ messages: I,
456
+ ...u ? {} : {
457
457
  assistantDraft: "",
458
458
  assistantDraftItemId: null,
459
459
  assistantDraftPhase: null,
@@ -464,55 +464,55 @@ class Ee {
464
464
  lastError: null
465
465
  }), l || this.emit("message", c);
466
466
  try {
467
- const u = [];
468
- for (const h of i) {
469
- const f = h.id ? this.attachmentFiles.get(h.id) : void 0;
470
- if (h.sandboxPath) {
471
- u.push(h);
467
+ const h = [];
468
+ for (const y of i) {
469
+ const M = y.id ? this.attachmentFiles.get(y.id) : void 0;
470
+ if (y.sandboxPath) {
471
+ h.push(y);
472
472
  continue;
473
473
  }
474
- if (!f)
475
- throw new Error(`Attachment bytes are unavailable for ${h.name}`);
476
- u.push(await this.uploadAttachmentForMessage({ file: f, attachment: h }));
474
+ if (!M)
475
+ throw new Error(`Attachment bytes are unavailable for ${y.name}`);
476
+ h.push(await this.uploadAttachmentForMessage({ file: M, attachment: y }));
477
477
  }
478
- i = u;
479
- } catch (u) {
478
+ i = h;
479
+ } catch (h) {
480
480
  throw this.setState({
481
- ...l ? {} : { messages: this.state.messages.filter((h) => h.id !== c.id) },
482
- ...d ? {} : { ...p, isThinking: !1 }
483
- }), u;
481
+ ...l ? {} : { messages: p },
482
+ ...u ? {} : { ...m, isThinking: !1 }
483
+ }), h;
484
484
  }
485
485
  this.retryableClientMessageId = null;
486
- const y = !s.initiatedBy && this.options.capturePageContent !== !1 && this.lastUserMessagePageUrl !== o.url, m = {
486
+ const d = !s.initiatedBy && this.options.capturePageContent !== !1 && this.lastUserMessagePageUrl !== o.url, f = {
487
487
  type: "chat.user_message",
488
488
  sessionId: this.state.sessionId ?? void 0,
489
489
  clientMessageId: a,
490
490
  initiatedBy: s.initiatedBy,
491
- invocation: tn(s.invocation ?? s.initiatedBy),
491
+ invocation: en(s.invocation ?? s.initiatedBy),
492
492
  entrySurface: this.options.entrySurface,
493
493
  content: n,
494
- pageContent: y && qt() || void 0,
494
+ pageContent: d && Wt() || void 0,
495
495
  attachments: i.length > 0 ? i : void 0,
496
496
  page: o,
497
497
  model: this.options.model,
498
- metadata: ie(this.options.metadata)
498
+ metadata: ae(this.options.metadata)
499
499
  };
500
- return s.initiatedBy || (this.lastUserMessagePageUrl = o.url), this.activeClientMessageId = a, this.activeUserMessageEvent = m, this.markThinkingProgress(), this.send(m), a;
500
+ return s.initiatedBy || (this.lastUserMessagePageUrl = o.url), this.activeClientMessageId = a, this.activeUserMessageEvent = f, this.markThinkingProgress(), this.send(f), a;
501
501
  }
502
502
  retryLastMessage() {
503
503
  const t = this.state.sessionId, s = this.retryableClientMessageId;
504
504
  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);
505
505
  }
506
506
  createLocalAttachment(t) {
507
- const s = kt(), n = {
507
+ const s = Rt(), n = {
508
508
  id: s,
509
509
  name: t.name || "attachment",
510
- mimeType: me(t),
510
+ mimeType: Ie(t),
511
511
  sizeBytes: t.size
512
512
  };
513
513
  this.attachmentFiles.set(s, t), this.attachmentBlobCache.set(s, t);
514
514
  const r = Date.now();
515
- return Xe({
515
+ return Ke({
516
516
  attachmentId: s,
517
517
  name: n.name,
518
518
  mimeType: n.mimeType,
@@ -541,7 +541,7 @@ class Ee {
541
541
  file: t,
542
542
  attachment: s
543
543
  }) {
544
- const n = this.state.sessionId, r = me(t), i = {
544
+ const n = this.state.sessionId, r = Ie(t), i = {
545
545
  sessionId: n ?? void 0,
546
546
  attachmentId: s.id,
547
547
  clientId: this.options.clientId,
@@ -551,7 +551,7 @@ class Ee {
551
551
  sizeBytes: t.size,
552
552
  page: k(),
553
553
  model: this.options.model,
554
- metadata: ie(this.options.metadata),
554
+ metadata: ae(this.options.metadata),
555
555
  entrySurface: this.options.entrySurface
556
556
  };
557
557
  let o;
@@ -577,8 +577,8 @@ class Ee {
577
577
  }, "Failed to upload attachment"), o = c;
578
578
  }
579
579
  this.setState({ sessionId: o.sessionId });
580
- const a = Ne(o.attachment, this.options.backendUrl);
581
- return this.updateAttachmentInState(s.id, a), s.id && Ke(s.id, {
580
+ const a = Oe(o.attachment, this.options.backendUrl);
581
+ return this.updateAttachmentInState(s.id, a), s.id && Je(s.id, {
582
582
  sessionId: o.sessionId,
583
583
  fileUrl: a.fileUrl,
584
584
  sandboxPath: a.sandboxPath,
@@ -608,7 +608,7 @@ class Ee {
608
608
  const n = await this.fetchEmbedAttachmentUpload(t);
609
609
  if (n.ok)
610
610
  return await n.json();
611
- if (Sr(n.status) && this.options.tokenProvider && !s) {
611
+ if (Rr(n.status) && this.options.tokenProvider && !s) {
612
612
  s = !0;
613
613
  const r = await this.fetchEmbedAttachmentUpload(t);
614
614
  if (r.ok)
@@ -652,10 +652,10 @@ class Ee {
652
652
  });
653
653
  }
654
654
  listSessions(t = {}) {
655
- const s = kt(), n = new Promise((i, o) => {
655
+ const s = Rt(), n = new Promise((i, o) => {
656
656
  const a = window.setTimeout(() => {
657
657
  this.pendingSessionHistoryRequests.delete(s), o(new Error("Session history did not respond in time"));
658
- }, Rs);
658
+ }, Ms);
659
659
  this.pendingSessionHistoryRequests.set(s, { resolve: i, reject: o, timeout: a });
660
660
  }), r = {
661
661
  type: "sessions.list",
@@ -714,7 +714,7 @@ class Ee {
714
714
  if (this.state.starterPromptsLoading || this.transientStarterPromptsRequestInFlight || this.transientStarterPromptsRequestAttempted)
715
715
  return;
716
716
  this.transientStarterPromptsRequestInFlight = !0, this.transientStarterPromptsRequestAttempted = !0, this.setState({ starterPromptsLoading: !0 });
717
- const t = nn();
717
+ const t = rn();
718
718
  this.sendNow(
719
719
  R({
720
720
  type: "starter_prompts.page_context",
@@ -725,13 +725,13 @@ class Ee {
725
725
  ) || (this.transientStarterPromptsRequestInFlight = !1, this.transientStarterPromptsRequestAttempted = !1, this.setState({ starterPromptsLoading: !1 }));
726
726
  }
727
727
  startStarterPromptUrlWatcher() {
728
- this.locationChangeCleanup || (this.locationChangeCleanup = rn(() => this.handleStarterPromptUrlChange()));
728
+ this.locationChangeCleanup || (this.locationChangeCleanup = on(() => this.handleStarterPromptUrlChange()));
729
729
  }
730
730
  handleStarterPromptUrlChange() {
731
731
  const t = location.href;
732
732
  t !== this.lastStarterPromptPageUrl && (this.lastStarterPromptPageUrl = t, this.clearStarterPromptUrlRefreshTimer(), this.starterPromptUrlRefreshTimer = window.setTimeout(() => {
733
733
  this.starterPromptUrlRefreshTimer = null, this.refreshStarterPromptsForCurrentUrl();
734
- }, Us));
734
+ }, Ds));
735
735
  }
736
736
  refreshStarterPromptsForCurrentUrl() {
737
737
  this.socket?.readyState !== WebSocket.OPEN || this.state.status === "closed" || (this.setState({ starterPromptsLoading: this.state.messages.length === 0 }), this.sendNow({
@@ -760,6 +760,10 @@ class Ee {
760
760
  !this.pendingWarmupEvent || !this.sendNow(this.pendingWarmupEvent) || (this.pendingWarmupEvent = null);
761
761
  }
762
762
  handleServerEvent(t) {
763
+ if (t.type === "run.steered") {
764
+ this.handleRunSteered(t);
765
+ return;
766
+ }
763
767
  if (t.type === "run.ack") {
764
768
  this.handleRunAck(t);
765
769
  return;
@@ -768,19 +772,19 @@ class Ee {
768
772
  this.clearHeartbeatAckTimer();
769
773
  return;
770
774
  }
771
- if (Os(t) && this.markThinkingProgress(), t.type === "auth.ok") {
775
+ if (Ls(t) && this.markThinkingProgress(), t.type === "auth.ok") {
772
776
  this.clearSocketAuthTimer(), this.reconnectAttempts = 0, this.flushQueuedClientEvents(), this.flushPendingWarmupEvent(), this.startHeartbeat();
773
- const s = gn(t), n = Object.prototype.hasOwnProperty.call(t, "appearance");
777
+ const s = mn(t), n = Object.prototype.hasOwnProperty.call(t, "appearance");
774
778
  A("web-sdk.agent", "Received auth.ok appearance", {
775
779
  hasAppearance: n,
776
780
  rawAppearance: t.appearance,
777
781
  normalizedAppearance: s
778
- }), this.runtimeHelperJavascript = mn(t.runtimeHelpers)?.javascript ?? null;
779
- const r = ce(t, "starterPrompts"), i = Object.prototype.hasOwnProperty.call(t, "starterPrompts"), o = t.starterPromptsLoading === !0, a = {
780
- user: wn(t.user),
782
+ }), this.runtimeHelperJavascript = yn(t.runtimeHelpers)?.javascript ?? null;
783
+ const r = ue(t, "starterPrompts"), i = Object.prototype.hasOwnProperty.call(t, "starterPrompts"), o = t.starterPromptsLoading === !0, a = {
784
+ user: An(t.user),
781
785
  status: "connected"
782
786
  };
783
- (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 && !an() && this.requestTransientStarterPrompts(), this.state.sessionId && this.send({
787
+ (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 && !cn() && this.requestTransientStarterPrompts(), this.state.sessionId && this.send({
784
788
  type: "page.upsert",
785
789
  sessionId: this.state.sessionId,
786
790
  page: k(),
@@ -790,44 +794,44 @@ class Ee {
790
794
  }
791
795
  if (t.type === "starterPrompts.updated") {
792
796
  this.transientStarterPromptsRequestInFlight = !1, this.transientStarterPromptsRequestAttempted = !0, this.setState({
793
- starterPrompts: ce(t, "starterPrompts"),
797
+ starterPrompts: ue(t, "starterPrompts"),
794
798
  starterPromptsLoading: !1
795
799
  });
796
800
  return;
797
801
  }
798
802
  if (t.type === "conversation.state") {
799
- const s = Array.isArray(t.items) ? t.items : [], n = Mn(
803
+ const s = Array.isArray(t.items) ? t.items : [], n = Cn(
800
804
  t.assistantDraft
801
805
  ), r = n !== void 0;
802
806
  this.rememberUserMessageClientMessageIds(s);
803
- const i = Wn(s);
807
+ const i = jn(s);
804
808
  if (i) {
805
- const f = $n(s, i);
809
+ const h = zn(s, i);
806
810
  this.retryAttemptsByClientMessageId[i] = Math.max(
807
811
  this.retryAttemptsByClientMessageId[i] ?? 0,
808
- f
812
+ h
809
813
  );
810
814
  }
811
- const o = s.filter((f) => {
812
- const T = L(f);
813
- return !he(T) && (!i || !Pt(T));
814
- }), a = xn(
815
+ const o = s.filter((h) => {
816
+ const y = B(h);
817
+ return !pe(y) && (!i || !xt(y));
818
+ }), a = Ln(
815
819
  this.state.messages,
816
- An(o, this.options.backendUrl)
817
- ), c = de(a), l = !r && s.some(
818
- (f) => fe(
819
- L(f),
820
+ Sn(o, this.options.backendUrl)
821
+ ), c = he(a), l = !r && s.some(
822
+ (h) => ge(
823
+ B(h),
820
824
  this.state.assistantDraft,
821
825
  this.state.assistantDraftItemId,
822
826
  this.state.assistantDraftRespondsToUserMessageId,
823
827
  this.state.assistantDraftRunId
824
828
  )
825
- ), d = r ? n?.content ?? "" : this.state.assistantDraft, p = !!n?.content, y = c && (!d || l), m = Bn(a), u = y && m;
826
- if (!c && Fn(this.state.messages, s))
829
+ ), u = r ? n?.content ?? "" : this.state.assistantDraft, p = !!n?.content, I = c && (!u || l), m = Fn(a), d = I && m;
830
+ if (!c && $n(this.state.messages, s))
827
831
  return;
828
- this.lastUserMessagePageUrl = Hn(s);
829
- const h = y ? null : Ut(s);
830
- if (this.latestRecoverableClientMessageId = h, m && this.clearRetryTimers(), this.setState({
832
+ this.lastUserMessagePageUrl = Wn(s);
833
+ const f = I ? null : Nt(s);
834
+ if (this.latestRecoverableClientMessageId = f, m && this.clearRetryTimers(), this.setState({
831
835
  sessionId: E(t.session, "id") ?? this.state.sessionId,
832
836
  messages: a,
833
837
  ...r ? {
@@ -846,28 +850,28 @@ class Ee {
846
850
  ...p ? {
847
851
  isThinking: !0,
848
852
  lastError: null
849
- } : y ? {
853
+ } : I ? {
850
854
  isThinking: !1,
851
- ...u ? {
855
+ ...d ? {
852
856
  status: "connected",
853
857
  lastError: null,
854
858
  lastErrorCode: null,
855
859
  lastErrorSecuritySettingsUrl: null
856
860
  } : {}
857
- } : h ? {
861
+ } : f ? {
858
862
  isThinking: !0,
859
863
  lastError: null
860
864
  } : {}
861
- }), y ? (this.retryableClientMessageId = null, this.clearThinkingWatchdog()) : (p || h) && (h && (this.activeClientMessageId = h), this.markThinkingProgress()), i) {
862
- const f = E(t.session, "id") ?? this.state.sessionId;
863
- f && this.retryAfterInterruptedRun(f, i);
865
+ }), I ? (this.retryableClientMessageId = null, this.clearThinkingWatchdog()) : (p || f) && (f && (this.activeClientMessageId = f), this.markThinkingProgress()), i) {
866
+ const h = E(t.session, "id") ?? this.state.sessionId;
867
+ h && this.retryAfterInterruptedRun(h, i);
864
868
  }
865
869
  return;
866
870
  }
867
871
  if (t.type === "sessions.page") {
868
872
  const s = typeof t.requestId == "string" ? t.requestId : null, n = s ? this.pendingSessionHistoryRequests.get(s) : null;
869
873
  s && n && (window.clearTimeout(n.timeout), this.pendingSessionHistoryRequests.delete(s), n.resolve({
870
- sessions: Sn(t.sessions),
874
+ sessions: En(t.sessions),
871
875
  nextCursor: typeof t.nextCursor == "string" ? t.nextCursor : null
872
876
  }));
873
877
  return;
@@ -878,10 +882,10 @@ class Ee {
878
882
  }
879
883
  if (t.type === "session.item") {
880
884
  this.rememberUserMessageClientMessageIds([t.item]);
881
- const s = L(t.item);
882
- if (Pt(s)) {
885
+ const s = B(t.item);
886
+ if (xt(s)) {
883
887
  typeof s?.runId == "string" && this.retryableFailureRunIdsAwaitingDone.add(s.runId);
884
- const r = E(t.item, "sessionId") ?? this.state.sessionId, i = s ? x(s) : null, o = i ? this.clientMessageIdsByUserMessageItemId.get(i) : null, a = typeof s?.clientMessageId == "string" ? s.clientMessageId : o ?? (i ? null : this.activeClientMessageId ?? this.latestRecoverableClientMessageId);
888
+ const r = E(t.item, "sessionId") ?? this.state.sessionId, i = s ? N(s) : null, o = i ? this.clientMessageIdsByUserMessageItemId.get(i) : null, a = typeof s?.clientMessageId == "string" ? s.clientMessageId : o ?? (i ? null : this.activeClientMessageId ?? this.latestRecoverableClientMessageId);
885
889
  if (r && a) {
886
890
  this.retryAfterInterruptedRun(r, a);
887
891
  return;
@@ -891,21 +895,21 @@ class Ee {
891
895
  return;
892
896
  }
893
897
  }
894
- if (he(s))
898
+ if (pe(s))
895
899
  return;
896
- const n = Me(t.item, this.options.backendUrl);
900
+ const n = Ue(t.item, this.options.backendUrl);
897
901
  if (n) {
898
902
  const r = n.callId ? this.pendingToolLoadingByCallId.get(n.callId) : void 0;
899
- n.callId && r !== void 0 && (n.loading = r, this.pendingToolLoadingByCallId.delete(n.callId)), q(n) && (this.retryableClientMessageId = null, this.clearRetryTimers(), this.clearRunAckResyncRetryTimer());
903
+ n.callId && r !== void 0 && (n.loading = r, this.pendingToolLoadingByCallId.delete(n.callId)), x(n) && (this.retryableClientMessageId = null, this.clearRetryTimers(), this.clearRunAckResyncRetryTimer());
900
904
  const i = t.item.data;
901
- zn(i) && this.clearRunAckResyncRetryTimer();
902
- const o = Ce(this.state.messages, n), a = de(o), c = fe(
905
+ Xn(i) && this.clearRunAckResyncRetryTimer();
906
+ const o = Pt(this.state.messages, n), a = he(o), c = ge(
903
907
  i,
904
908
  this.state.assistantDraft,
905
909
  this.state.assistantDraftItemId,
906
910
  this.state.assistantDraftRespondsToUserMessageId,
907
911
  this.state.assistantDraftRunId
908
- ), l = a && (!this.state.assistantDraft || c), d = l && q(n);
912
+ ), l = a && (!this.state.assistantDraft || c), u = l && x(n);
909
913
  this.setState({
910
914
  messages: o,
911
915
  ...c ? {
@@ -918,7 +922,7 @@ class Ee {
918
922
  ...l ? {
919
923
  isThinking: !1
920
924
  } : {},
921
- ...d ? {
925
+ ...u ? {
922
926
  status: "connected",
923
927
  lastError: null,
924
928
  lastErrorCode: null,
@@ -930,13 +934,23 @@ class Ee {
930
934
  }
931
935
  if (t.type === "chat.assistant_delta") {
932
936
  this.clearRunAckResyncRetryTimer();
933
- const s = typeof t.delta == "string" ? t.delta : "", n = typeof t.itemId == "string" ? t.itemId : null, r = n !== null && this.state.assistantDraftItemId !== n;
937
+ const s = typeof t.delta == "string" ? t.delta : "", n = typeof t.itemId == "string" ? t.itemId : null, r = n !== null && this.state.assistantDraftItemId !== n, i = `${r ? "" : this.state.assistantDraft}${s}`, o = n ?? this.state.assistantDraftItemId ?? "assistant-draft", a = this.state.messages.find((p) => p.id === o), c = t.phase === "commentary" || t.phase === "final_answer" ? t.phase : r ? null : this.state.assistantDraftPhase, l = typeof t.respondsToUserMessageId == "string" ? t.respondsToUserMessageId : this.state.assistantDraftRespondsToUserMessageId, u = typeof t.runId == "string" ? t.runId : this.state.assistantDraftRunId;
934
938
  this.setState({
935
- assistantDraft: `${r ? "" : this.state.assistantDraft}${s}`,
939
+ messages: Pt(this.state.messages, {
940
+ id: o,
941
+ role: "assistant",
942
+ content: i,
943
+ createdAt: a?.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
944
+ dataType: "assistant_draft",
945
+ ...c ? { phase: c } : {},
946
+ ...l ? { respondsToUserMessageId: l } : {},
947
+ ...u ? { runId: u } : {}
948
+ }),
949
+ assistantDraft: i,
936
950
  assistantDraftItemId: n ?? this.state.assistantDraftItemId,
937
- assistantDraftPhase: t.phase === "commentary" || t.phase === "final_answer" ? t.phase : r ? null : this.state.assistantDraftPhase,
938
- assistantDraftRespondsToUserMessageId: typeof t.respondsToUserMessageId == "string" ? t.respondsToUserMessageId : this.state.assistantDraftRespondsToUserMessageId,
939
- assistantDraftRunId: typeof t.runId == "string" ? t.runId : this.state.assistantDraftRunId,
951
+ assistantDraftPhase: c,
952
+ assistantDraftRespondsToUserMessageId: l,
953
+ assistantDraftRunId: u,
940
954
  isThinking: !0
941
955
  }), this.markThinkingProgress(), this.emit("delta", s);
942
956
  return;
@@ -945,23 +959,33 @@ class Ee {
945
959
  if (typeof t.runId == "string" && this.retryableFailureRunIdsAwaitingDone.delete(t.runId))
946
960
  return;
947
961
  this.retryableClientMessageId = null;
948
- const s = typeof t.sessionId == "string" ? t.sessionId : this.state.sessionId;
962
+ const s = typeof t.sessionId == "string" ? t.sessionId : this.state.sessionId, n = typeof t.respondsToUserMessageId == "string" ? t.respondsToUserMessageId : null, r = typeof t.runId == "string" ? t.runId : null;
963
+ if (!(n && this.state.assistantDraftRespondsToUserMessageId ? n === this.state.assistantDraftRespondsToUserMessageId : !r || !this.state.assistantDraftRunId || r === this.state.assistantDraftRunId))
964
+ return;
965
+ const o = [...this.state.messages].reverse().find((c) => c.role === "user")?.id, a = !n || !o || n === o;
949
966
  this.setState({
950
967
  sessionId: s,
968
+ messages: this.state.messages.filter(
969
+ (c) => c.dataType !== "assistant_draft" || !Dn(
970
+ c,
971
+ n,
972
+ r
973
+ )
974
+ ),
951
975
  assistantDraft: "",
952
976
  assistantDraftItemId: null,
953
977
  assistantDraftPhase: null,
954
978
  assistantDraftRespondsToUserMessageId: null,
955
979
  assistantDraftRunId: null,
956
- isThinking: !1
957
- }), this.clearThinkingWatchdog();
980
+ isThinking: a ? !1 : this.state.isThinking
981
+ }), a && this.clearThinkingWatchdog();
958
982
  return;
959
983
  }
960
984
  if (t.type === "tool.call") {
961
985
  this.clearRunAckResyncRetryTimer();
962
- const s = Dn(t);
986
+ const s = Nn(t);
963
987
  if (s) {
964
- const n = Pn(
988
+ const n = vn(
965
989
  this.state.messages,
966
990
  s
967
991
  );
@@ -1002,7 +1026,7 @@ class Ee {
1002
1026
  return;
1003
1027
  }
1004
1028
  o && r && i && (this.retryableClientMessageId = i);
1005
- const a = new Error(typeof t.message == "string" ? t.message.replace(/Product Agent/g, "Pluno") : "Pluno error"), c = en(a.message);
1029
+ const a = new Error(typeof t.message == "string" ? t.message.replace(/Product Agent/g, "Pluno") : "Pluno error"), c = sn(a.message);
1006
1030
  c && console.error(c), this.setState({
1007
1031
  status: "error",
1008
1032
  isThinking: !1,
@@ -1067,7 +1091,7 @@ class Ee {
1067
1091
  }
1068
1092
  rememberUserMessageClientMessageIds(t) {
1069
1093
  for (const s of t) {
1070
- const n = E(s, "id"), r = L(s);
1094
+ const n = E(s, "id"), r = B(s);
1071
1095
  n && r?.type === "message" && r.role === "user" && typeof r.clientMessageId == "string" && this.clientMessageIdsByUserMessageItemId.set(n, r.clientMessageId);
1072
1096
  }
1073
1097
  }
@@ -1077,7 +1101,7 @@ class Ee {
1077
1101
  this.pendingSessionHistoryRequests.clear();
1078
1102
  }
1079
1103
  markThinkingProgress() {
1080
- !this.state.isThinking || this.state.status === "closed" || (this.scheduleThinkingWatchdog(ne), this.activeClientMessageId && this.scheduleRunAckWatchdog(this.activeClientMessageId));
1104
+ !this.state.isThinking || this.state.status === "closed" || (this.scheduleThinkingWatchdog(ie), this.activeClientMessageId && this.scheduleRunAckWatchdog(this.activeClientMessageId));
1081
1105
  }
1082
1106
  scheduleThinkingWatchdog(t) {
1083
1107
  this.thinkingWatchdogTimer !== null && window.clearTimeout(this.thinkingWatchdogTimer), this.thinkingWatchdogTimer = window.setTimeout(() => {
@@ -1094,10 +1118,19 @@ class Ee {
1094
1118
  sessionId: typeof t.sessionId == "string" ? t.sessionId : this.state.sessionId
1095
1119
  }), !(!this.state.isThinking || !s || s !== this.activeClientMessageId) && (this.clearRunAckResyncRetryTimer(), this.scheduleRunAckWatchdog(s));
1096
1120
  }
1121
+ handleRunSteered(t) {
1122
+ const s = typeof t.respondsToUserMessageId == "string" ? t.respondsToUserMessageId : null;
1123
+ !this.state.isThinking || !s || this.setState({
1124
+ messages: Jn(
1125
+ this.state.messages,
1126
+ s
1127
+ )
1128
+ });
1129
+ }
1097
1130
  scheduleRunAckWatchdog(t) {
1098
1131
  this.runAckWatchdogTimer !== null && window.clearTimeout(this.runAckWatchdogTimer), this.runAckWatchdogTimer = window.setTimeout(() => {
1099
1132
  this.runAckWatchdogTimer = null, this.recoverMissedRunAck(t);
1100
- }, Ss);
1133
+ }, Es);
1101
1134
  }
1102
1135
  recoverMissedRunAck(t) {
1103
1136
  !this.state.isThinking || this.state.status === "closed" || this.activeClientMessageId !== t || (A("web-sdk.agent", "Pluno run ack missed; resyncing session", {
@@ -1121,8 +1154,8 @@ class Ee {
1121
1154
  sessionId: this.state.sessionId,
1122
1155
  clientMessageId: t,
1123
1156
  automatic: !0
1124
- }) : this.activeUserMessageEvent && this.send(this.activeUserMessageEvent), this.scheduleThinkingWatchdog(ne)));
1125
- }, V(s, Es)));
1157
+ }) : this.activeUserMessageEvent && this.send(this.activeUserMessageEvent), this.scheduleThinkingWatchdog(ie)));
1158
+ }, V(s, bs)));
1126
1159
  }
1127
1160
  clearRunAckResyncRetryTimer() {
1128
1161
  this.runAckResyncRetryTimer !== null && (window.clearTimeout(this.runAckResyncRetryTimer), this.runAckResyncRetryTimer = null);
@@ -1161,7 +1194,7 @@ class Ee {
1161
1194
  sessionId: this.state.sessionId,
1162
1195
  clientMessageId: t,
1163
1196
  resyncAttempts: s + 1
1164
- }), this.resyncThinkingSession(), this.scheduleThinkingWatchdog(As);
1197
+ }), this.resyncThinkingSession(), this.scheduleThinkingWatchdog(Ss);
1165
1198
  return;
1166
1199
  }
1167
1200
  this.setState({
@@ -1190,13 +1223,13 @@ class Ee {
1190
1223
  }) : (!this.socket || this.socket.readyState !== WebSocket.OPEN) && (this.setState({ status: "reconnecting", lastError: null }), this.scheduleReconnect());
1191
1224
  }
1192
1225
  async executeToolCall(t) {
1193
- 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 = O(
1226
+ 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(
1194
1227
  typeof t.summary == "string" ? t.summary : "Running browser tool"
1195
1228
  ), o = t.rawInput;
1196
1229
  if (!s || !n || !r)
1197
1230
  return;
1198
1231
  const a = r === "execute_code_in_browser_tab" && o !== null && typeof o == "object" && o.tabId === "local:current";
1199
- if (r !== "execute_code" && !a || !ur(o)) {
1232
+ if (r !== "execute_code" && !a || !fr(o)) {
1200
1233
  this.setToolMessageLoading(n, !1), this.send({
1201
1234
  type: "tool.result",
1202
1235
  sessionId: s,
@@ -1228,7 +1261,7 @@ class Ee {
1228
1261
  });
1229
1262
  return;
1230
1263
  }
1231
- const c = qs(this.state.messages);
1264
+ const c = Hs(this.state.messages);
1232
1265
  this.activeBrowserToolCalls.set(n, {
1233
1266
  event: {
1234
1267
  type: "tool.result",
@@ -1243,10 +1276,10 @@ class Ee {
1243
1276
  startedAtUrl: location.href,
1244
1277
  startedAtOrigin: location.origin
1245
1278
  }), this.installSessionUserFilesApi(c);
1246
- let l = null, d;
1247
- l = await this.executeRuntimeHelper(), d = await oe(
1279
+ let l = null, u;
1280
+ l = await this.executeRuntimeHelper(), u = await ce(
1248
1281
  o,
1249
- Vs(t.runtimeContext, this.options.backendUrl)
1282
+ Ys(t.runtimeContext, this.options.backendUrl)
1250
1283
  ).catch((p) => ({
1251
1284
  ok: !1,
1252
1285
  exception: {
@@ -1259,11 +1292,11 @@ class Ee {
1259
1292
  toolName: r,
1260
1293
  summary: o.summary,
1261
1294
  rawInput: R(o),
1262
- rawOutput: R(yn(d, l))
1263
- }), er(this.options.clientId, this.activeBrowserToolCalls.values());
1295
+ rawOutput: R(In(u, l))
1296
+ }), ir(this.options.clientId, this.activeBrowserToolCalls.values());
1264
1297
  }
1265
1298
  setToolMessageLoading(t, s) {
1266
- const n = Un(
1299
+ const n = xn(
1267
1300
  this.state.messages,
1268
1301
  t,
1269
1302
  s
@@ -1274,33 +1307,33 @@ class Ee {
1274
1307
  if (this.pageLifecycleCleanup)
1275
1308
  return;
1276
1309
  const t = () => {
1277
- ve(this.options.clientId, this.activeBrowserToolCalls.values());
1310
+ xe(this.options.clientId, this.activeBrowserToolCalls.values());
1278
1311
  };
1279
1312
  window.addEventListener("pagehide", t), window.addEventListener("beforeunload", t), this.pageLifecycleCleanup = () => {
1280
1313
  window.removeEventListener("pagehide", t), window.removeEventListener("beforeunload", t);
1281
1314
  };
1282
1315
  }
1283
1316
  installSessionUserFilesApi(t) {
1284
- this.cleanupSessionUserFilesApi(), this.sessionUserFilesApiCleanup = Hs(t, this.attachmentFiles, this.attachmentBlobCache);
1317
+ this.cleanupSessionUserFilesApi(), this.sessionUserFilesApiCleanup = Fs(t, this.attachmentFiles, this.attachmentBlobCache);
1285
1318
  }
1286
1319
  cleanupSessionUserFilesApi() {
1287
- this.sessionUserFilesApiCleanup && (Ks(this.sessionUserFilesApiCleanup), this.sessionUserFilesApiCleanup = null);
1320
+ this.sessionUserFilesApiCleanup && (Js(this.sessionUserFilesApiCleanup), this.sessionUserFilesApiCleanup = null);
1288
1321
  }
1289
1322
  async executeRuntimeHelper() {
1290
1323
  if (!this.runtimeHelperJavascript?.trim())
1291
1324
  return null;
1292
- const t = await oe({
1325
+ const t = await ce({
1293
1326
  javascript: this.runtimeHelperJavascript
1294
1327
  });
1295
1328
  return t.ok === !1 ? Tn(t) : null;
1296
1329
  }
1297
1330
  enableNetworkCapture() {
1298
- this.networkCaptureCleanup || (this.networkCaptureCleanup = xs((t) => {
1299
- mr(t.url, this.options.backendUrl) || this.enqueueNetworkEvent(t);
1331
+ this.networkCaptureCleanup || (this.networkCaptureCleanup = Ns((t) => {
1332
+ wr(t.url, this.options.backendUrl) || this.enqueueNetworkEvent(t);
1300
1333
  }));
1301
1334
  }
1302
1335
  enqueueNetworkEvent(t) {
1303
- this.queuedNetworkEvents.length >= ks || (this.queuedNetworkEvents.push(gr(t)), this.networkBatchTimer === null && (this.networkBatchTimer = window.setTimeout(() => {
1336
+ this.queuedNetworkEvents.length >= Rs || (this.queuedNetworkEvents.push(Tr(t)), this.networkBatchTimer === null && (this.networkBatchTimer = window.setTimeout(() => {
1304
1337
  this.networkBatchTimer = null;
1305
1338
  const s = this.queuedNetworkEvents.splice(0, this.queuedNetworkEvents.length);
1306
1339
  s.length === 0 || this.socket?.readyState !== WebSocket.OPEN || this.sendNow({
@@ -1309,12 +1342,12 @@ class Ee {
1309
1342
  page: k(),
1310
1343
  events: s
1311
1344
  });
1312
- }, bs)));
1345
+ }, ks)));
1313
1346
  }
1314
1347
  scheduleReconnect() {
1315
1348
  if (this.reconnectTimer !== null || this.state.status === "closed")
1316
1349
  return;
1317
- const t = Ds(this.reconnectAttempts);
1350
+ const t = vs(this.reconnectAttempts);
1318
1351
  this.reconnectAttempts += 1, this.reconnectTimer = window.setTimeout(() => {
1319
1352
  this.reconnectTimer = null, this.connect().catch((s) => {
1320
1353
  A("web-sdk.agent", "Pluno reconnect failed; retrying", {
@@ -1330,8 +1363,8 @@ class Ee {
1330
1363
  const t = this.socket;
1331
1364
  !t || !this.sendNow({ type: "runtime.ping" }) || (this.clearHeartbeatAckTimer(), this.heartbeatAckTimer = window.setTimeout(() => {
1332
1365
  this.socket === t && (A("web-sdk.agent", "Pluno heartbeat acknowledgement timed out; reconnecting"), this.replaceTimedOutSocket(t));
1333
- }, ms));
1334
- }, gs);
1366
+ }, ys));
1367
+ }, ms);
1335
1368
  }
1336
1369
  stopHeartbeat() {
1337
1370
  this.heartbeatTimer !== null && (window.clearInterval(this.heartbeatTimer), this.heartbeatTimer = null), this.clearHeartbeatAckTimer();
@@ -1357,105 +1390,105 @@ class Ee {
1357
1390
  ...t,
1358
1391
  ...t.lastError === null && t.lastErrorCode === void 0 ? { lastErrorCode: null } : {},
1359
1392
  ...t.lastError !== void 0 && t.lastErrorSecuritySettingsUrl === void 0 ? { lastErrorSecuritySettingsUrl: null } : {}
1360
- }, Qn(this.options.clientId, this.state), this.emit("state", this.getState());
1393
+ }, nr(this.options.clientId, this.state), this.emit("state", this.getState());
1361
1394
  }
1362
1395
  emit(t, s) {
1363
1396
  this.listeners[t]?.forEach((r) => r(s));
1364
1397
  }
1365
1398
  }
1366
- const Et = /* @__PURE__ */ new WeakMap();
1367
- function xs(e) {
1368
- const t = window.__plunoProductAgentNetworkCapture ?? Ns();
1399
+ const bt = /* @__PURE__ */ new WeakMap();
1400
+ function Ns(e) {
1401
+ const t = window.__plunoProductAgentNetworkCapture ?? Os();
1369
1402
  return t.subscribers.add(e), () => {
1370
1403
  t.subscribers.delete(e), !(t.subscribers.size > 0) && (t.destroy(), window.__plunoProductAgentNetworkCapture === t && delete window.__plunoProductAgentNetworkCapture);
1371
1404
  };
1372
1405
  }
1373
- function Ns() {
1374
- const e = /* @__PURE__ */ new Set(), t = (y) => {
1406
+ function Os() {
1407
+ const e = /* @__PURE__ */ new Set(), t = (I) => {
1375
1408
  e.forEach((m) => {
1376
1409
  try {
1377
- m(y);
1410
+ m(I);
1378
1411
  } catch {
1379
1412
  }
1380
1413
  });
1381
- }, s = window.fetch, n = XMLHttpRequest.prototype.open, r = XMLHttpRequest.prototype.setRequestHeader, i = XMLHttpRequest.prototype.send, o = function(m, u) {
1382
- const h = Date.now();
1383
- let f;
1414
+ }, s = window.fetch, n = XMLHttpRequest.prototype.open, r = XMLHttpRequest.prototype.setRequestHeader, i = XMLHttpRequest.prototype.send, o = function(m, d) {
1415
+ const f = Date.now();
1416
+ let h;
1384
1417
  try {
1385
- f = s.call(this, m, u);
1386
- } catch (T) {
1387
- throw T;
1418
+ h = s.call(this, m, d);
1419
+ } catch (y) {
1420
+ throw y;
1388
1421
  }
1389
1422
  try {
1390
- const T = m instanceof Request ? m : null, v = dr(m, T), I = Oe(u?.headers ?? T?.headers);
1391
- if (!N(v, I, u?.body)) {
1423
+ const y = m instanceof Request ? m : null, M = gr(m, y), T = Le(d?.headers ?? y?.headers);
1424
+ if (!O(M, T, d?.body)) {
1392
1425
  const H = {
1393
- requestId: Rt("fetch"),
1394
- url: C(v, St),
1395
- method: (u?.method ?? T?.method ?? "GET").toUpperCase(),
1396
- requestHeaders: I,
1397
- requestBody: ye(u?.body),
1426
+ requestId: Mt("fetch"),
1427
+ url: U(M, Et),
1428
+ method: (d?.method ?? y?.method ?? "GET").toUpperCase(),
1429
+ requestHeaders: T,
1430
+ requestBody: Te(d?.body),
1398
1431
  resourceType: "fetch",
1399
- startedAt: new Date(h).toISOString()
1432
+ startedAt: new Date(f).toISOString()
1400
1433
  };
1401
- f.then(
1434
+ h.then(
1402
1435
  (_) => {
1403
- hr(_, H, h, t).catch(() => {
1436
+ mr(_, H, f, t).catch(() => {
1404
1437
  t({
1405
1438
  ...H,
1406
1439
  responseStatus: _.status,
1407
- durationMs: Date.now() - h
1440
+ durationMs: Date.now() - f
1408
1441
  });
1409
1442
  });
1410
1443
  },
1411
1444
  (_) => {
1412
1445
  t({
1413
1446
  ...H,
1414
- errorText: C(_ instanceof Error ? _.message : String(_)),
1415
- durationMs: Date.now() - h
1447
+ errorText: U(_ instanceof Error ? _.message : String(_)),
1448
+ durationMs: Date.now() - f
1416
1449
  });
1417
1450
  }
1418
1451
  );
1419
1452
  }
1420
1453
  } catch {
1421
1454
  }
1422
- return f;
1423
- }, a = function(m, u, h, f, T) {
1424
- const v = n.call(this, m, u, h ?? !0, f ?? void 0, T ?? void 0), I = typeof u == "string" ? u : u.toString();
1425
- return Et.set(this, {
1426
- requestId: Rt("xhr"),
1455
+ return h;
1456
+ }, a = function(m, d, f, h, y) {
1457
+ const M = n.call(this, m, d, f ?? !0, h ?? void 0, y ?? void 0), T = typeof d == "string" ? d : d.toString();
1458
+ return bt.set(this, {
1459
+ requestId: Mt("xhr"),
1427
1460
  method: String(m ?? "GET").toUpperCase(),
1428
- url: C(I, St),
1461
+ url: U(T, Et),
1429
1462
  requestHeaders: {},
1430
1463
  startedAtMs: Date.now(),
1431
1464
  startedAt: (/* @__PURE__ */ new Date()).toISOString(),
1432
- excluded: N(I)
1433
- }), v;
1434
- }, c = function(m, u) {
1435
- const h = r.call(this, m, u), f = Et.get(this);
1436
- return f && Object.keys(f.requestHeaders).length < Bt && (f.requestHeaders[m] = jt(m, u), f.excluded = f.excluded || N(f.url, f.requestHeaders)), h;
1465
+ excluded: O(T)
1466
+ }), M;
1467
+ }, c = function(m, d) {
1468
+ const f = r.call(this, m, d), h = bt.get(this);
1469
+ return h && Object.keys(h.requestHeaders).length < Ft && (h.requestHeaders[m] = Gt(m, d), h.excluded = h.excluded || O(h.url, h.requestHeaders)), f;
1437
1470
  }, l = function(m) {
1438
1471
  try {
1439
- const u = Et.get(this);
1440
- u && (u.excluded = u.excluded || N(u.url, u.requestHeaders, m), u.requestBody = ye(m), u.excluded || this.addEventListener(
1472
+ const d = bt.get(this);
1473
+ d && (d.excluded = d.excluded || O(d.url, d.requestHeaders, m), d.requestBody = Te(m), d.excluded || this.addEventListener(
1441
1474
  "loadend",
1442
1475
  () => {
1443
1476
  queueMicrotask(() => {
1444
1477
  try {
1445
- const h = Tr(this.getAllResponseHeaders());
1478
+ const f = Sr(this.getAllResponseHeaders());
1446
1479
  t({
1447
- requestId: u.requestId,
1448
- url: u.url,
1449
- method: u.method,
1450
- requestHeaders: u.requestHeaders,
1451
- requestBody: u.requestBody,
1480
+ requestId: d.requestId,
1481
+ url: d.url,
1482
+ method: d.method,
1483
+ requestHeaders: d.requestHeaders,
1484
+ requestBody: d.requestBody,
1452
1485
  resourceType: "xhr",
1453
1486
  responseStatus: this.status,
1454
- responseHeaders: h,
1455
- responseBody: fr(this, h),
1487
+ responseHeaders: f,
1488
+ responseBody: Ir(this, f),
1456
1489
  errorText: this.status === 0 ? "XHR request failed or was aborted" : void 0,
1457
- startedAt: u.startedAt,
1458
- durationMs: Date.now() - u.startedAtMs
1490
+ startedAt: d.startedAt,
1491
+ durationMs: Date.now() - d.startedAtMs
1459
1492
  });
1460
1493
  } catch {
1461
1494
  return;
@@ -1484,35 +1517,35 @@ function Ns() {
1484
1517
  XMLHttpRequest.prototype.send = l;
1485
1518
  } catch {
1486
1519
  }
1487
- let d = null;
1520
+ let u = null;
1488
1521
  if (typeof PerformanceObserver < "u") {
1489
- d = new PerformanceObserver((y) => {
1490
- for (const m of y.getEntries()) {
1491
- const u = m;
1492
- if (u.initiatorType === "fetch" || u.initiatorType === "xmlhttprequest" || N(u.name))
1522
+ u = new PerformanceObserver((I) => {
1523
+ for (const m of I.getEntries()) {
1524
+ const d = m;
1525
+ if (d.initiatorType === "fetch" || d.initiatorType === "xmlhttprequest" || O(d.name))
1493
1526
  continue;
1494
- const h = performance.timeOrigin + u.startTime;
1527
+ const f = performance.timeOrigin + d.startTime;
1495
1528
  t({
1496
- requestId: Rt("resource"),
1497
- url: C(u.name, St),
1529
+ requestId: Mt("resource"),
1530
+ url: U(d.name, Et),
1498
1531
  method: "GET",
1499
1532
  resourceType: "resource",
1500
- responseStatus: u.responseStatus,
1501
- startedAt: new Date(h).toISOString(),
1502
- durationMs: u.duration
1533
+ responseStatus: d.responseStatus,
1534
+ startedAt: new Date(f).toISOString(),
1535
+ durationMs: d.duration
1503
1536
  });
1504
1537
  }
1505
1538
  });
1506
1539
  try {
1507
- d.observe({ type: "resource", buffered: !0 });
1540
+ u.observe({ type: "resource", buffered: !0 });
1508
1541
  } catch {
1509
- d.disconnect(), d = null;
1542
+ u.disconnect(), u = null;
1510
1543
  }
1511
1544
  }
1512
1545
  const p = {
1513
1546
  subscribers: e,
1514
1547
  destroy: () => {
1515
- d?.disconnect();
1548
+ u?.disconnect();
1516
1549
  try {
1517
1550
  window.fetch === o && (window.fetch = s);
1518
1551
  } catch {
@@ -1544,15 +1577,15 @@ function A(e, t, s) {
1544
1577
  }, i = n.__plunoProductAgentDiagnostics__ ?? [];
1545
1578
  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 }));
1546
1579
  }
1547
- function ie(e) {
1580
+ function ae(e) {
1548
1581
  const t = typeof e == "function" ? e() : e;
1549
1582
  return t && Object.keys(t).length > 0 ? t : void 0;
1550
1583
  }
1551
- function Os(e) {
1584
+ function Ls(e) {
1552
1585
  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";
1553
1586
  }
1554
- const Ls = 5e3, Bs = 12e4;
1555
- function qs(e) {
1587
+ const Bs = 5e3, qs = 12e4;
1588
+ function Hs(e) {
1556
1589
  const t = [];
1557
1590
  for (const s of e)
1558
1591
  s.role !== "user" || !s.attachments?.length || s.attachments.forEach((n, r) => {
@@ -1563,30 +1596,30 @@ function qs(e) {
1563
1596
  });
1564
1597
  return t;
1565
1598
  }
1566
- function Hs(e, t = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map()) {
1599
+ function Fs(e, t = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map()) {
1567
1600
  const n = [
1568
- Ws(),
1569
- Fs()
1601
+ $s(),
1602
+ Ws()
1570
1603
  ].filter((r) => typeof r == "function");
1571
1604
  return () => {
1572
1605
  for (const r of n.reverse())
1573
1606
  r();
1574
1607
  };
1575
1608
  }
1576
- function Fs() {
1577
- return Ie(globalThis, "getPageSnapshot", async () => qt());
1578
- }
1579
1609
  function Ws() {
1580
- return Ie(globalThis, "pageImages", {
1581
- inspectImage: async (t, s) => await $s(t, s)
1610
+ return Ae(globalThis, "getPageSnapshot", async () => Wt());
1611
+ }
1612
+ function $s() {
1613
+ return Ae(globalThis, "pageImages", {
1614
+ inspectImage: async (t, s) => await js(t, s)
1582
1615
  });
1583
1616
  }
1584
- async function $s(e, t = {}) {
1585
- const s = Xs(t.name), n = await js(e);
1617
+ async function js(e, t = {}) {
1618
+ const s = Ks(t.name), n = await zs(e);
1586
1619
  return n.ok ? n.sizeBytes > 8 * 1024 * 1024 ? {
1587
1620
  type: "pluno.pageImages.inspectImage",
1588
1621
  imageAttached: !1,
1589
- imageAttachmentError: Ae
1622
+ imageAttachmentError: Ee
1590
1623
  } : {
1591
1624
  type: "pluno.pageImages.inspectImage",
1592
1625
  imageAttached: !0,
@@ -1600,15 +1633,15 @@ async function $s(e, t = {}) {
1600
1633
  imageAttachmentError: n.error
1601
1634
  };
1602
1635
  }
1603
- async function js(e) {
1604
- 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: Ae } : {
1636
+ async function zs(e) {
1637
+ 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: Ee } : {
1605
1638
  ok: !0,
1606
1639
  mimeType: e.type,
1607
1640
  sizeBytes: e.size,
1608
- dataUrl: await Js(e)
1609
- } : { 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." } : zs(e);
1641
+ dataUrl: await Vs(e)
1642
+ } : { 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." } : Gs(e);
1610
1643
  }
1611
- function zs(e) {
1644
+ function Gs(e) {
1612
1645
  if (!e.startsWith("data:") || !e.includes(","))
1613
1646
  return { ok: !1, error: "Page image must be a complete data:image/* URL, not bare base64." };
1614
1647
  const [t, s] = e.slice(5).split(",", 2), n = t.split(";").map((a) => a.trim()).filter(Boolean), r = n[0] ?? "";
@@ -1619,7 +1652,7 @@ function zs(e) {
1619
1652
  const i = s.replace(/[ \t\r\n\f]+/g, "");
1620
1653
  if (!/^[A-Za-z0-9+/]*={0,2}$/.test(i))
1621
1654
  return { ok: !1, error: "Page image data URL has invalid base64." };
1622
- const o = Gs(i);
1655
+ const o = Xs(i);
1623
1656
  return o === null ? { ok: !1, error: "Page image data URL has invalid base64." } : o === 0 ? { ok: !1, error: "Page image is empty." } : {
1624
1657
  ok: !0,
1625
1658
  mimeType: r,
@@ -1627,22 +1660,22 @@ function zs(e) {
1627
1660
  dataUrl: `data:${r};base64,${i}`
1628
1661
  };
1629
1662
  }
1630
- function Gs(e) {
1663
+ function Xs(e) {
1631
1664
  if (e.length === 0 || e.length % 4 !== 0)
1632
1665
  return null;
1633
1666
  const t = e.length - e.replace(/=+$/, "").length;
1634
1667
  return t > 2 ? null : e.length / 4 * 3 - t;
1635
1668
  }
1636
- function Xs(e) {
1669
+ function Ks(e) {
1637
1670
  return (typeof e == "string" ? e.trim() : "") || "Page image";
1638
1671
  }
1639
- function Ks(e) {
1672
+ function Js(e) {
1640
1673
  try {
1641
1674
  e();
1642
1675
  } catch {
1643
1676
  }
1644
1677
  }
1645
- function Js(e) {
1678
+ function Vs(e) {
1646
1679
  return new Promise((t, s) => {
1647
1680
  const n = new FileReader();
1648
1681
  n.onload = () => {
@@ -1654,29 +1687,29 @@ function Js(e) {
1654
1687
  }, n.onerror = () => s(n.error ?? new Error("Failed to read Pluno user file")), n.readAsDataURL(e);
1655
1688
  });
1656
1689
  }
1657
- async function oe(e, t) {
1690
+ async function ce(e, t) {
1658
1691
  const s = Object.getPrototypeOf(async function() {
1659
- }).constructor, n = e.timeoutMs ?? Ls, r = Date.now(), i = [];
1692
+ }).constructor, n = e.timeoutMs ?? Bs, r = Date.now(), i = [];
1660
1693
  let o;
1661
1694
  const a = {
1662
1695
  log: console.log,
1663
1696
  info: console.info,
1664
1697
  warn: console.warn,
1665
1698
  error: console.error
1666
- }, c = (l) => (...d) => {
1667
- i.push({ level: l, args: d }), a[l](...d);
1699
+ }, c = (l) => (...u) => {
1700
+ i.push({ level: l, args: u }), a[l](...u);
1668
1701
  };
1669
1702
  console.log = c("log"), console.info = c("info"), console.warn = c("warn"), console.error = c("error");
1670
1703
  try {
1671
- const l = /* @__PURE__ */ Symbol("execute_code_timeout"), d = await Promise.race([
1704
+ const l = /* @__PURE__ */ Symbol("execute_code_timeout"), u = await Promise.race([
1672
1705
  new s("sandboxFiles", e.javascript)(t?.value),
1673
1706
  new Promise((p) => {
1674
1707
  o = window.setTimeout(() => p(l), n);
1675
1708
  })
1676
1709
  ]);
1677
- return d === l ? Ys(n) : {
1710
+ return u === l ? Zs(n) : {
1678
1711
  ok: !0,
1679
- result: d,
1712
+ result: u,
1680
1713
  console: i,
1681
1714
  metadata: {
1682
1715
  durationMs: Date.now() - r,
@@ -1703,7 +1736,7 @@ async function oe(e, t) {
1703
1736
  t?.deactivate(), o !== void 0 && window.clearTimeout(o), console.log = a.log, console.info = a.info, console.warn = a.warn, console.error = a.error;
1704
1737
  }
1705
1738
  }
1706
- function Vs(e, t) {
1739
+ function Ys(e, t) {
1707
1740
  if (!e || typeof e != "object")
1708
1741
  return;
1709
1742
  const s = e.sandboxFilesToken;
@@ -1713,20 +1746,20 @@ function Vs(e, t) {
1713
1746
  const r = () => {
1714
1747
  if (!n)
1715
1748
  throw new Error("sandboxFiles is only available during browser-code execution");
1716
- }, i = async (a, c) => await ls(`${t.replace(/\/$/, "")}${a}`, c);
1749
+ }, i = async (a, c) => await us(`${t.replace(/\/$/, "")}${a}`, c);
1717
1750
  return {
1718
1751
  value: Object.freeze({
1719
1752
  upload: async (a) => {
1720
1753
  if (r(), !(a instanceof Blob))
1721
1754
  throw new TypeError("sandboxFiles.upload expects a File or Blob");
1722
- const c = a instanceof File && a.name ? a.name : "file", l = `?name=${encodeURIComponent(c)}&size_bytes=${a.size}`, d = await i(`/api/product-agent/attachments/sandbox-files${l}`, {
1755
+ const c = a instanceof File && a.name ? a.name : "file", l = `?name=${encodeURIComponent(c)}&size_bytes=${a.size}`, u = await i(`/api/product-agent/attachments/sandbox-files${l}`, {
1723
1756
  method: "PUT",
1724
1757
  headers: { Authorization: `Bearer ${s}` },
1725
1758
  body: a
1726
1759
  });
1727
- if (!d.ok)
1728
- throw new Error(`sandboxFiles.upload failed (${d.status})`);
1729
- return String((await d.json()).path);
1760
+ if (!u.ok)
1761
+ throw new Error(`sandboxFiles.upload failed (${u.status})`);
1762
+ return String((await u.json()).path);
1730
1763
  },
1731
1764
  download: async (a) => {
1732
1765
  r();
@@ -1747,7 +1780,7 @@ function Vs(e, t) {
1747
1780
  }
1748
1781
  };
1749
1782
  }
1750
- function Ys(e) {
1783
+ function Zs(e) {
1751
1784
  return {
1752
1785
  ok: !1,
1753
1786
  exception: {
@@ -1761,10 +1794,10 @@ function Ys(e) {
1761
1794
  }
1762
1795
  };
1763
1796
  }
1764
- function Zs(e) {
1797
+ function Qs(e) {
1765
1798
  return e.replace(/\/+$/, "");
1766
1799
  }
1767
- function Qs(e) {
1800
+ function tn(e) {
1768
1801
  const t = {
1769
1802
  sidepanel: "extension_sidepanel",
1770
1803
  browser_extension_page_ui: "extension_widget",
@@ -1776,18 +1809,18 @@ function Qs(e) {
1776
1809
  };
1777
1810
  return e && e in t ? t[e] : e ?? "embedded_custom_ui";
1778
1811
  }
1779
- function tn(e) {
1812
+ function en(e) {
1780
1813
  return e === "pluno" ? "scheduled_continuation" : e ?? "user";
1781
1814
  }
1782
- function en(e, t = location.origin) {
1815
+ function sn(e, t = location.origin) {
1783
1816
  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;
1784
1817
  }
1785
- function sn(e) {
1818
+ function nn(e) {
1786
1819
  const t = new URL("/api/product-agent/embed/ws", e);
1787
1820
  return t.protocol = t.protocol === "https:" ? "wss:" : "ws:", t.toString();
1788
1821
  }
1789
1822
  function k() {
1790
- const e = _e();
1823
+ const e = Ce();
1791
1824
  return {
1792
1825
  url: location.href,
1793
1826
  title: document.title,
@@ -1795,19 +1828,19 @@ function k() {
1795
1828
  ...e ? { plunoProductAgentUi: e } : {}
1796
1829
  };
1797
1830
  }
1798
- function nn() {
1831
+ function rn() {
1799
1832
  return {
1800
1833
  pageUrl: location.href,
1801
1834
  pageTitle: document.title,
1802
- htmlContent: qt()
1835
+ htmlContent: Wt()
1803
1836
  };
1804
1837
  }
1805
- function rn(e) {
1806
- return et.add(e), Y || (Y = on()), () => {
1838
+ function on(e) {
1839
+ return et.add(e), Y || (Y = an()), () => {
1807
1840
  et.delete(e), et.size === 0 && (Y?.(), Y = null);
1808
1841
  };
1809
1842
  }
1810
- function on() {
1843
+ function an() {
1811
1844
  const e = () => {
1812
1845
  for (const i of Array.from(et))
1813
1846
  i();
@@ -1822,38 +1855,38 @@ function on() {
1822
1855
  window.history.pushState === n && (window.history.pushState = t), window.history.replaceState === r && (window.history.replaceState = s), window.removeEventListener("popstate", e), window.removeEventListener("hashchange", e);
1823
1856
  };
1824
1857
  }
1825
- function an() {
1826
- return _e()?.surface === "browser_extension_sdk_preview";
1858
+ function cn() {
1859
+ return Ce()?.surface === "browser_extension_sdk_preview";
1827
1860
  }
1828
- function qt() {
1861
+ function Wt() {
1829
1862
  if (!document.body)
1830
1863
  return "";
1831
- const e = [], t = [], s = (h, f) => {
1832
- const T = B(f);
1833
- !T || t.includes(T) || (e.push([h, T]), t.push(T));
1864
+ const e = [], t = [], s = (f, h) => {
1865
+ const y = q(h);
1866
+ !y || t.includes(y) || (e.push([f, y]), t.push(y));
1834
1867
  };
1835
1868
  s("Selected text", window.getSelection()?.toString() ?? "");
1836
1869
  const n = "[role='dialog'], [role='alertdialog'], dialog[open], [aria-modal='true']", r = Array.from(document.querySelectorAll(n)).filter(
1837
- (h) => be(h) && !h.parentElement?.closest(n)
1870
+ (f) => Re(f) && !f.parentElement?.closest(n)
1838
1871
  );
1839
- for (const h of r.slice(0, 3))
1840
- s("Active overlay", bt(j(h), t));
1841
- const i = cn(), o = i ? bt(j(i), t) : "";
1842
- s("Main page content", o), s("Additional visible page text", bt(j(document.body), t));
1843
- const a = e.map(([h, f]) => `${h}:
1844
- ${f}`).join(`
1872
+ for (const f of r.slice(0, 3))
1873
+ s("Active overlay", kt(j(f), t));
1874
+ const i = ln(), o = i ? kt(j(i), t) : "";
1875
+ s("Main page content", o), s("Additional visible page text", kt(j(document.body), t));
1876
+ const a = e.map(([f, h]) => `${f}:
1877
+ ${h}`).join(`
1845
1878
 
1846
- `).trim().slice(0, 12e3), c = ln(r, i).trim(), l = `Simplified DOM outline:
1847
- `, d = `
1879
+ `).trim().slice(0, 12e3), c = un(r, i).trim(), l = `Simplified DOM outline:
1880
+ `, u = `
1848
1881
 
1849
1882
  Visible page text:
1850
- `, p = 12e3 - l.length - d.length, y = Math.min(a.length, 7900), m = c.slice(0, p - y), u = a.slice(0, p - m.length);
1851
- return `${l}${m}${d}${u}`;
1883
+ `, p = 12e3 - l.length - u.length, I = Math.min(a.length, 7900), m = c.slice(0, p - I), d = a.slice(0, p - m.length);
1884
+ return `${l}${m}${u}${d}`;
1852
1885
  }
1853
1886
  function j(e) {
1854
1887
  return e.innerText ?? e.textContent ?? "";
1855
1888
  }
1856
- function B(e) {
1889
+ function q(e) {
1857
1890
  return (e ?? "").replace(/\u00a0/g, " ").replace(/\r\n?/g, `
1858
1891
  `).split(`
1859
1892
  `).map((t) => t.replace(/[ \t]+/g, " ").trim()).join(`
@@ -1861,20 +1894,20 @@ function B(e) {
1861
1894
 
1862
1895
  `).trim();
1863
1896
  }
1864
- function bt(e, t) {
1865
- let s = B(e);
1897
+ function kt(e, t) {
1898
+ let s = q(e);
1866
1899
  for (const n of t)
1867
1900
  s = s.replace(n, "");
1868
- return B(s);
1901
+ return q(s);
1869
1902
  }
1870
- function be(e) {
1903
+ function Re(e) {
1871
1904
  const t = window.getComputedStyle(e);
1872
1905
  return t.display !== "none" && t.visibility !== "hidden" && e.getClientRects().length > 0;
1873
1906
  }
1874
- function cn() {
1875
- return Array.from(document.querySelectorAll("main, [role='main'], article")).filter(be).sort((e, t) => j(t).length - j(e).length)[0] ?? null;
1907
+ function ln() {
1908
+ return Array.from(document.querySelectorAll("main, [role='main'], article")).filter(Re).sort((e, t) => j(t).length - j(e).length)[0] ?? null;
1876
1909
  }
1877
- function ln(e, t) {
1910
+ function un(e, t) {
1878
1911
  const s = /* @__PURE__ */ new Set([
1879
1912
  "main",
1880
1913
  "nav",
@@ -1954,92 +1987,92 @@ function ln(e, t) {
1954
1987
  "data-test",
1955
1988
  "data-qa",
1956
1989
  "data-cy"
1957
- ], l = ["aria-label", "placeholder", "data-testid", "data-test", "data-qa", "data-cy"], { priorityElements: d, priorityTargets: p } = un(), y = new Set(e);
1958
- t && y.add(t);
1990
+ ], l = ["aria-label", "placeholder", "data-testid", "data-test", "data-qa", "data-cy"], { priorityElements: u, priorityTargets: p } = dn(), I = new Set(e);
1991
+ t && I.add(t);
1959
1992
  let m = 0;
1960
- const u = (I) => {
1961
- const U = I.getAttribute("role");
1962
- return U && !o.has(U) ? U : "";
1963
- }, h = (I) => {
1964
- const U = I.getAttribute("data-testid") || I.getAttribute("data-test") || I.getAttribute("data-qa") || I.getAttribute("data-cy") || "";
1965
- return `${I.tagName.toLowerCase()}|${u(I)}|${U}`;
1966
- }, f = (I, U, H) => {
1967
- const _ = (S, lt) => {
1968
- const b = S.tagName.toLowerCase(), ut = window.getComputedStyle(S), z = d.has(S);
1969
- if (m >= 1e3 && !z || H.has(S) || i.has(b) || S.matches(".pluno-pa-widget-host, [data-pluno-product-agent-widget]") || ut.display === "none" || ut.visibility === "hidden")
1993
+ const d = (T) => {
1994
+ const D = T.getAttribute("role");
1995
+ return D && !o.has(D) ? D : "";
1996
+ }, f = (T) => {
1997
+ const D = T.getAttribute("data-testid") || T.getAttribute("data-test") || T.getAttribute("data-qa") || T.getAttribute("data-cy") || "";
1998
+ return `${T.tagName.toLowerCase()}|${d(T)}|${D}`;
1999
+ }, h = (T, D, H) => {
2000
+ const _ = (S, ut) => {
2001
+ const b = S.tagName.toLowerCase(), dt = window.getComputedStyle(S), z = u.has(S);
2002
+ if (m >= 1e3 && !z || H.has(S) || i.has(b) || S.matches(".pluno-pa-widget-host, [data-pluno-product-agent-widget]") || dt.display === "none" || dt.visibility === "hidden")
1970
2003
  return { lines: [], hasUsefulContent: !1, textPreview: "", containsTextElement: !1 };
1971
2004
  m += 1;
1972
- const zt = u(S), G = Re(S), je = a.has(zt) || ["button", "input", "textarea", "select", "iframe", "canvas"].includes(b) || b === "a" && S.hasAttribute("href"), dt = Array.from(S.children).filter((g) => g instanceof HTMLElement), X = /* @__PURE__ */ new Map();
1973
- for (const g of dt) {
1974
- const w = h(g);
2005
+ const Xt = d(S), G = _e(S), ze = a.has(Xt) || ["button", "input", "textarea", "select", "iframe", "canvas"].includes(b) || b === "a" && S.hasAttribute("href"), ht = Array.from(S.children).filter((g) => g instanceof HTMLElement), X = /* @__PURE__ */ new Map();
2006
+ for (const g of ht) {
2007
+ const w = f(g);
1975
2008
  X.set(w, (X.get(w) ?? 0) + 1);
1976
2009
  }
1977
- const ht = /* @__PURE__ */ new Map(), Gt = /* @__PURE__ */ new Map();
1978
- for (const g of dt) {
1979
- const w = h(g), D = Gt.get(w) ?? 0;
1980
- Gt.set(w, D + 1), (X.get(w) ?? 0) > 8 && D >= 6 && !d.has(g) && ht.set(w, (ht.get(w) ?? 0) + 1);
2010
+ const pt = /* @__PURE__ */ new Map(), Kt = /* @__PURE__ */ new Map();
2011
+ for (const g of ht) {
2012
+ const w = f(g), v = Kt.get(w) ?? 0;
2013
+ Kt.set(w, v + 1), (X.get(w) ?? 0) > 8 && v >= 6 && !u.has(g) && pt.set(w, (pt.get(w) ?? 0) + 1);
1981
2014
  }
1982
- const Xt = /* @__PURE__ */ new Map(), Kt = /* @__PURE__ */ new Set(), pt = [], Jt = [];
1983
- for (const g of dt) {
1984
- const w = h(g), D = X.get(w) ?? 0, Zt = Xt.get(w) ?? 0;
1985
- if (Xt.set(w, Zt + 1), D > 8 && Zt >= 6 && !d.has(g)) {
1986
- Kt.has(w) || (pt.push([`… ${ht.get(w) ?? 0} similar siblings omitted`]), Kt.add(w));
2015
+ const Jt = /* @__PURE__ */ new Map(), Vt = /* @__PURE__ */ new Set(), ft = [], Yt = [];
2016
+ for (const g of ht) {
2017
+ const w = f(g), v = X.get(w) ?? 0, te = Jt.get(w) ?? 0;
2018
+ if (Jt.set(w, te + 1), v > 8 && te >= 6 && !u.has(g)) {
2019
+ Vt.has(w) || (ft.push([`… ${pt.get(w) ?? 0} similar siblings omitted`]), Vt.add(w));
1987
2020
  continue;
1988
2021
  }
1989
- const Qt = _(g, lt);
1990
- Jt.push(Qt), pt.push(Qt.lines);
2022
+ const ee = _(g, ut);
2023
+ Yt.push(ee), ft.push(ee.lines);
1991
2024
  }
1992
- const ft = [];
2025
+ const gt = [];
1993
2026
  if (S.shadowRoot)
1994
2027
  for (const g of Array.from(S.shadowRoot.children))
1995
- g instanceof HTMLElement && ft.push(_(g, lt + 1));
1996
- const K = [...Jt, ...ft], gt = G.length > 0 || je || K.some((g) => g.hasUsefulContent), Vt = B(
2028
+ g instanceof HTMLElement && gt.push(_(g, ut + 1));
2029
+ const K = [...Yt, ...gt], mt = G.length > 0 || ze || K.some((g) => g.hasUsefulContent), Zt = q(
1997
2030
  [G, ...K.map((g) => g.textPreview)].filter(Boolean).join(" ")
1998
- ).slice(0, 180), ze = S.hasAttribute("contenteditable") && (G.length > 0 || !S.querySelector("[contenteditable]")), Yt = l.some((g) => S.hasAttribute(g)) || !!zt || ze, mt = (S.getClientRects().length > 0 || ut.display === "contents") && (s.has(b) || Yt || z) && (gt || z) && (!r.has(b) || gt || Yt || z), yt = mt ? 1 : 0, F = [];
1999
- if (mt) {
2000
- const g = K.some((D) => D.containsTextElement), w = n.has(b) && !g ? Vt : G;
2001
- F.push(ke(S, c, o, w.slice(0, 180)));
2031
+ ).slice(0, 180), Ge = S.hasAttribute("contenteditable") && (G.length > 0 || !S.querySelector("[contenteditable]")), Qt = l.some((g) => S.hasAttribute(g)) || !!Xt || Ge, yt = (S.getClientRects().length > 0 || dt.display === "contents") && (s.has(b) || Qt || z) && (mt || z) && (!r.has(b) || mt || Qt || z), It = yt ? 1 : 0, F = [];
2032
+ if (yt) {
2033
+ const g = K.some((v) => v.containsTextElement), w = n.has(b) && !g ? Zt : G;
2034
+ F.push(Me(S, c, o, w.slice(0, 180)));
2002
2035
  }
2003
- for (const g of pt)
2004
- F.push(...Z(g, yt));
2005
- const Tt = ft.flatMap((g) => g.lines);
2036
+ for (const g of ft)
2037
+ F.push(...Z(g, It));
2038
+ const Tt = gt.flatMap((g) => g.lines);
2006
2039
  if (Tt.length > 0) {
2007
2040
  const g = Tt.slice(0, 20);
2008
2041
  Tt.length > g.length && g.push("… shadow DOM omitted");
2009
2042
  const w = b.includes("tooltip") || b.includes("popper") || b.includes("loader");
2010
- if (lt < 2 && !w) {
2011
- const D = mt ? "#shadow-root" : `${b} #shadow-root`;
2012
- F.push(...Z([D, ...Z(g, 1)], yt));
2043
+ if (ut < 2 && !w) {
2044
+ const v = yt ? "#shadow-root" : `${b} #shadow-root`;
2045
+ F.push(...Z([v, ...Z(g, 1)], It));
2013
2046
  } else
2014
- F.push(...Z(g, yt));
2047
+ F.push(...Z(g, It));
2015
2048
  }
2016
2049
  return {
2017
2050
  lines: F,
2018
- hasUsefulContent: gt,
2019
- textPreview: Vt,
2051
+ hasUsefulContent: mt,
2052
+ textPreview: Zt,
2020
2053
  containsTextElement: n.has(b) || K.some((g) => g.containsTextElement)
2021
2054
  };
2022
2055
  };
2023
- return [`--- ${U} ---`, ..._(I, 0).lines].join(`
2056
+ return [`--- ${D} ---`, ..._(T, 0).lines].join(`
2024
2057
  `);
2025
- }, T = [], v = B(window.getSelection()?.toString() ?? "");
2026
- v && T.push(`--- selected text ---
2027
- ${JSON.stringify(v)}`), p.length > 0 && T.push(dn(p, s, c, o));
2028
- for (const I of e.slice(0, 3))
2029
- T.push(f(I, "active overlay DOM", /* @__PURE__ */ new Set()));
2030
- if (t && T.push(f(t, "main DOM", /* @__PURE__ */ new Set())), document.body) {
2031
- const I = t || e.length ? "other visible DOM" : "visible DOM";
2032
- T.push(f(document.body, I, y));
2033
- }
2034
- return T.join(`
2058
+ }, y = [], M = q(window.getSelection()?.toString() ?? "");
2059
+ M && y.push(`--- selected text ---
2060
+ ${JSON.stringify(M)}`), p.length > 0 && y.push(hn(p, s, c, o));
2061
+ for (const T of e.slice(0, 3))
2062
+ y.push(h(T, "active overlay DOM", /* @__PURE__ */ new Set()));
2063
+ if (t && y.push(h(t, "main DOM", /* @__PURE__ */ new Set())), document.body) {
2064
+ const T = t || e.length ? "other visible DOM" : "visible DOM";
2065
+ y.push(h(document.body, T, I));
2066
+ }
2067
+ return y.join(`
2035
2068
 
2036
2069
  `);
2037
2070
  }
2038
- function ke(e, t, s, n) {
2071
+ function Me(e, t, s, n) {
2039
2072
  const r = e.tagName.toLowerCase();
2040
2073
  let i = r;
2041
2074
  const o = e.getAttribute("id");
2042
- o && hn(o) && (i += `#${o}`);
2075
+ o && pn(o) && (i += `#${o}`);
2043
2076
  for (const a of t) {
2044
2077
  const c = e.getAttribute(a);
2045
2078
  c && c.length <= 160 && (a !== "role" || !s.has(c)) && (i += `[${a}=${JSON.stringify(c)}]`);
@@ -2052,20 +2085,20 @@ function ke(e, t, s, n) {
2052
2085
  e.hasAttribute(a) && (i += `[${a}]`);
2053
2086
  return `${i}${n ? ` ${JSON.stringify(n)}` : ""}`;
2054
2087
  }
2055
- function un() {
2088
+ function dn() {
2056
2089
  const e = /* @__PURE__ */ new Set(), t = /* @__PURE__ */ new Map(), s = (a, c) => {
2057
2090
  if (!a)
2058
2091
  return;
2059
2092
  const l = window.getComputedStyle(a);
2060
2093
  if (l.display === "none" || l.visibility === "hidden")
2061
2094
  return;
2062
- const d = t.get(a) ?? /* @__PURE__ */ new Set();
2063
- d.add(c), t.set(a, d);
2095
+ const u = t.get(a) ?? /* @__PURE__ */ new Set();
2096
+ u.add(c), t.set(a, u);
2064
2097
  let p = a;
2065
2098
  for (; p; ) {
2066
2099
  e.add(p);
2067
- const y = p.getRootNode();
2068
- p = p.parentElement ?? (y instanceof ShadowRoot && y.host instanceof HTMLElement ? y.host : null);
2100
+ const I = p.getRootNode();
2101
+ p = p.parentElement ?? (I instanceof ShadowRoot && I.host instanceof HTMLElement ? I.host : null);
2069
2102
  }
2070
2103
  };
2071
2104
  let n = document.activeElement instanceof HTMLElement ? document.activeElement : null;
@@ -2073,7 +2106,7 @@ function un() {
2073
2106
  n = n.shadowRoot.activeElement;
2074
2107
  n !== document.body && n !== document.documentElement && s(n, "focused");
2075
2108
  const r = window.getSelection();
2076
- r && !r.isCollapsed && (s(ae(r.anchorNode), "selected text"), s(ae(r.focusNode), "selected text"));
2109
+ r && !r.isCollapsed && (s(le(r.anchorNode), "selected text"), s(le(r.focusNode), "selected text"));
2077
2110
  const i = [
2078
2111
  ["[aria-selected='true']", "selected"],
2079
2112
  ["[aria-current]:not([aria-current='false'])", "current"],
@@ -2084,9 +2117,9 @@ function un() {
2084
2117
  ], o = [document];
2085
2118
  for (let a = 0; a < o.length; a += 1) {
2086
2119
  const c = o[a];
2087
- for (const [l, d] of i)
2120
+ for (const [l, u] of i)
2088
2121
  for (const p of Array.from(c.querySelectorAll(l)))
2089
- s(p, d);
2122
+ s(p, u);
2090
2123
  for (const l of Array.from(c.querySelectorAll("*")))
2091
2124
  l.shadowRoot && o.push(l.shadowRoot);
2092
2125
  }
@@ -2095,29 +2128,29 @@ function un() {
2095
2128
  priorityTargets: Array.from(t, ([a, c]) => ({ element: a, labels: Array.from(c) }))
2096
2129
  };
2097
2130
  }
2098
- function dn(e, t, s, n) {
2131
+ function hn(e, t, s, n) {
2099
2132
  const r = ["--- active/current elements ---"];
2100
2133
  for (const i of e) {
2101
2134
  const o = [];
2102
2135
  let a = i.element;
2103
2136
  for (; a; ) {
2104
- const d = a.tagName.toLowerCase();
2105
- (a === i.element || t.has(d) || a.hasAttribute("id") || a.hasAttribute("role") || a.hasAttribute("aria-label")) && o.unshift(a);
2137
+ const u = a.tagName.toLowerCase();
2138
+ (a === i.element || t.has(u) || a.hasAttribute("id") || a.hasAttribute("role") || a.hasAttribute("aria-label")) && o.unshift(a);
2106
2139
  const p = a.getRootNode();
2107
2140
  a = a.parentElement ?? (p instanceof ShadowRoot && p.host instanceof HTMLElement ? p.host : null);
2108
2141
  }
2109
- const c = o.length > 6 ? [o[0], ...o.slice(-5)] : o, l = c.map((d, p) => ke(
2110
- d,
2142
+ const c = o.length > 6 ? [o[0], ...o.slice(-5)] : o, l = c.map((u, p) => Me(
2143
+ u,
2111
2144
  s,
2112
2145
  n,
2113
- p === c.length - 1 ? Re(d).slice(0, 180) : ""
2146
+ p === c.length - 1 ? _e(u).slice(0, 180) : ""
2114
2147
  ));
2115
2148
  o.length > c.length && l.splice(1, 0, "…"), r.push(`${i.labels.join(", ")}: ${l.join(" > ")}`);
2116
2149
  }
2117
2150
  return r.join(`
2118
2151
  `);
2119
2152
  }
2120
- function ae(e) {
2153
+ function le(e) {
2121
2154
  return e instanceof HTMLElement ? e : e?.parentElement instanceof HTMLElement ? e.parentElement : null;
2122
2155
  }
2123
2156
  function Z(e, t) {
@@ -2126,17 +2159,17 @@ function Z(e, t) {
2126
2159
  const s = " ".repeat(t);
2127
2160
  return e.map((n) => `${s}${n}`);
2128
2161
  }
2129
- function Re(e) {
2130
- return B(
2162
+ function _e(e) {
2163
+ return q(
2131
2164
  Array.from(e.childNodes).filter((t) => t.nodeType === Node.TEXT_NODE).map((t) => t.textContent ?? "").join(" ")
2132
2165
  );
2133
2166
  }
2134
- function hn(e) {
2167
+ function pn(e) {
2135
2168
  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);
2136
2169
  }
2137
- function _e() {
2138
- const e = document.querySelector(te);
2139
- if (!(e ?? document.querySelector(Mt)))
2170
+ function Ce() {
2171
+ const e = document.querySelector(se);
2172
+ if (!(e ?? document.querySelector(Ct)))
2140
2173
  return;
2141
2174
  const s = e ? "browser_extension_sdk_preview" : "embedded_widget";
2142
2175
  return {
@@ -2145,28 +2178,28 @@ function _e() {
2145
2178
  selectors: [
2146
2179
  {
2147
2180
  name: "widget_host",
2148
- selector: s === "browser_extension_sdk_preview" ? te : Mt,
2181
+ selector: s === "browser_extension_sdk_preview" ? se : Ct,
2149
2182
  description: "Finds Pluno's shadow-host element in the host page DOM."
2150
2183
  },
2151
2184
  {
2152
2185
  name: "widget_root",
2153
- selector: us,
2186
+ selector: ds,
2154
2187
  description: "Finds Pluno's widget root inside the widget host shadow root."
2155
2188
  },
2156
2189
  {
2157
2190
  name: "widget_panel",
2158
- selector: ds,
2191
+ selector: hs,
2159
2192
  description: "Finds Pluno's open chat panel inside the widget host shadow root."
2160
2193
  },
2161
2194
  {
2162
2195
  name: "widget_timeline",
2163
- selector: hs,
2196
+ selector: ps,
2164
2197
  description: "Finds Pluno's chat timeline inside the widget host shadow root."
2165
2198
  }
2166
2199
  ]
2167
2200
  };
2168
2201
  }
2169
- function pn(e) {
2202
+ function fn(e) {
2170
2203
  try {
2171
2204
  const t = JSON.parse(e);
2172
2205
  return t && typeof t == "object" ? t : { type: "error", message: "Invalid server event" };
@@ -2174,16 +2207,16 @@ function pn(e) {
2174
2207
  return { type: "error", message: "Invalid server event" };
2175
2208
  }
2176
2209
  }
2177
- function ce(e, t) {
2210
+ function ue(e, t) {
2178
2211
  if (!e || typeof e != "object")
2179
2212
  return [];
2180
2213
  const s = e[t];
2181
2214
  return Array.isArray(s) ? s.filter((n) => typeof n == "string" && n.trim().length > 0) : [];
2182
2215
  }
2183
- function fn(e) {
2216
+ function gn(e) {
2184
2217
  return Array.isArray(e) ? e.filter((t) => typeof t == "string" && t.trim().length > 0) : [];
2185
2218
  }
2186
- function gn(e) {
2219
+ function mn(e) {
2187
2220
  if (!e || typeof e != "object")
2188
2221
  return null;
2189
2222
  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;
@@ -2194,13 +2227,13 @@ function gn(e) {
2194
2227
  ...a !== null ? { scribbleStyle: a } : {}
2195
2228
  };
2196
2229
  }
2197
- function mn(e) {
2230
+ function yn(e) {
2198
2231
  if (!e || typeof e != "object")
2199
2232
  return null;
2200
2233
  const t = e.javascript;
2201
2234
  return typeof t != "string" || !t.trim() ? null : { javascript: t };
2202
2235
  }
2203
- function yn(e, t) {
2236
+ function In(e, t) {
2204
2237
  return t ? e && typeof e == "object" ? {
2205
2238
  ...e,
2206
2239
  helperError: t
@@ -2216,17 +2249,17 @@ function Tn(e) {
2216
2249
  const t = e;
2217
2250
  return typeof t.exception?.message == "string" ? t.exception.message : typeof t.error == "string" ? t.error : e;
2218
2251
  }
2219
- function In() {
2252
+ function wn() {
2220
2253
  const e = "pluno.productAgent.clientId", t = window.localStorage.getItem(e);
2221
2254
  if (t)
2222
2255
  return t;
2223
2256
  const s = crypto.randomUUID();
2224
2257
  return window.localStorage.setItem(e, s), s;
2225
2258
  }
2226
- function kt() {
2259
+ function Rt() {
2227
2260
  return crypto.randomUUID();
2228
2261
  }
2229
- function wn(e) {
2262
+ function An(e) {
2230
2263
  if (!e || typeof e != "object")
2231
2264
  return null;
2232
2265
  const t = e, s = typeof t.id == "string" ? t.id : null;
@@ -2237,14 +2270,12 @@ function wn(e) {
2237
2270
  avatarUrl: typeof t.avatarUrl == "string" ? t.avatarUrl : null
2238
2271
  } : null;
2239
2272
  }
2240
- function An(e, t) {
2241
- return Array.isArray(e) ? Dt(
2242
- vt(
2243
- e.map((s) => Me(s, t)).filter((s) => s !== null)
2244
- )
2273
+ function Sn(e, t) {
2274
+ return Array.isArray(e) ? Ot(
2275
+ e.map((s) => Ue(s, t)).filter((s) => s !== null)
2245
2276
  ) : [];
2246
2277
  }
2247
- function Sn(e) {
2278
+ function En(e) {
2248
2279
  return Array.isArray(e) ? e.flatMap((t) => {
2249
2280
  if (!t || typeof t != "object")
2250
2281
  return [];
@@ -2263,7 +2294,7 @@ function Sn(e) {
2263
2294
  ];
2264
2295
  }) : [];
2265
2296
  }
2266
- function Me(e, t) {
2297
+ function Ue(e, t) {
2267
2298
  if (!e || typeof e != "object")
2268
2299
  return null;
2269
2300
  const s = e, n = s.data;
@@ -2279,14 +2310,14 @@ function Me(e, t) {
2279
2310
  id: String(s.id ?? crypto.randomUUID()),
2280
2311
  role: i,
2281
2312
  ...r.phase === "commentary" || r.phase === "final_answer" ? { phase: r.phase } : {},
2282
- content: Qe(
2283
- Cn(r.content),
2313
+ content: ts(
2314
+ Un(r.content),
2284
2315
  t
2285
2316
  ),
2286
2317
  createdAt: typeof s.createdAt == "string" ? s.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
2287
- respondsToUserMessageId: x(r) ?? void 0,
2288
- ...M(r) ? { runId: M(r) } : {},
2289
- attachments: xe(r.attachments, t)
2318
+ respondsToUserMessageId: N(r) ?? void 0,
2319
+ ...C(r) ? { runId: C(r) } : {},
2320
+ attachments: Ne(r.attachments, t)
2290
2321
  };
2291
2322
  return i === "assistant" && typeof r.id == "string" && Object.defineProperty(o, "assistantDraftItemId", {
2292
2323
  value: r.id,
@@ -2297,49 +2328,50 @@ function Me(e, t) {
2297
2328
  }), o;
2298
2329
  }
2299
2330
  if (r.type === "function_call_output") {
2300
- const i = bn(r.output);
2331
+ const i = kn(r.output);
2301
2332
  return i ? {
2302
2333
  id: String(s.id ?? crypto.randomUUID()),
2303
2334
  role: "tool",
2304
2335
  content: `Connect ${i.appName} to continue`,
2305
2336
  createdAt: typeof s.createdAt == "string" ? s.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
2306
- respondsToUserMessageId: x(r) ?? void 0,
2307
- ...M(r) ? { runId: M(r) } : {},
2337
+ respondsToUserMessageId: N(r) ?? void 0,
2338
+ ...C(r) ? { runId: C(r) } : {},
2308
2339
  dataType: "function_call_output",
2309
2340
  toolName: "authenticate_pipedream_app",
2310
- callId: le(r) ?? void 0,
2341
+ callId: de(r) ?? void 0,
2311
2342
  integrationAuthRequest: i
2312
2343
  } : null;
2313
2344
  }
2314
2345
  return r.type === "function_call" || r.type === "tool_call" || r.type === "web_search_call" || r.type === "mcp_call" || r.type === "tab_lifecycle_decision" ? {
2315
2346
  id: String(s.id ?? crypto.randomUUID()),
2316
2347
  role: "tool",
2317
- content: r.type === "mcp_call" ? En(r) : Rn(r),
2348
+ content: r.type === "mcp_call" ? bn(r) : Mn(r),
2318
2349
  createdAt: typeof s.createdAt == "string" ? s.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
2319
- respondsToUserMessageId: x(r) ?? void 0,
2320
- ...M(r) ? { runId: M(r) } : {},
2350
+ respondsToUserMessageId: N(r) ?? void 0,
2351
+ ...C(r) ? { runId: C(r) } : {},
2321
2352
  dataType: String(r.type),
2322
2353
  toolName: r.type === "tab_lifecycle_decision" ? "tab_lifecycle_decision" : typeof r.name == "string" ? r.name : void 0,
2323
- callId: le(r) ?? void 0,
2354
+ callId: de(r) ?? void 0,
2324
2355
  loading: r.localExecutionStatus === "queued" || r.localExecutionStatus === "running" ? !0 : typeof r.localExecutionStatus == "string" ? !1 : void 0
2325
2356
  } : r.type === "run_status" || r.type === "run_error" ? r.type === "run_error" && r.stage === "tool_execution" ? null : {
2326
2357
  id: String(s.id ?? crypto.randomUUID()),
2327
2358
  role: "system",
2328
- content: kn(r),
2359
+ content: Rn(r),
2329
2360
  createdAt: typeof s.createdAt == "string" ? s.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
2330
- respondsToUserMessageId: x(r) ?? void 0,
2331
- ...M(r) ? { runId: M(r) } : {},
2361
+ respondsToUserMessageId: N(r) ?? void 0,
2362
+ ...C(r) ? { runId: C(r) } : {},
2332
2363
  dataType: String(r.type),
2333
2364
  loading: r.type === "run_status" && (r.status === "running" || r.status === "retrying"),
2365
+ ...r.type === "run_status" && r.status === "steered" ? { steered: !0 } : {},
2334
2366
  ...typeof r.retryable == "boolean" ? { retryable: r.retryable } : {},
2335
2367
  ...typeof r.securitySettingsUrl == "string" ? { securitySettingsUrl: r.securitySettingsUrl } : {}
2336
2368
  } : null;
2337
2369
  }
2338
- function En(e) {
2370
+ function bn(e) {
2339
2371
  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(" ");
2340
2372
  return s ? `🔌 Using ${s}` : "🔌 Using connected integration";
2341
2373
  }
2342
- function bn(e) {
2374
+ function kn(e) {
2343
2375
  if (typeof e != "string")
2344
2376
  return null;
2345
2377
  try {
@@ -2356,10 +2388,10 @@ function bn(e) {
2356
2388
  return null;
2357
2389
  }
2358
2390
  }
2359
- function kn(e) {
2360
- 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.";
2361
- }
2362
2391
  function Rn(e) {
2392
+ return e.type === "run_status" && e.status === "stopped" ? "Run stopped by user" : e.type === "run_status" && e.status === "steered" ? "Steered" : 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.";
2393
+ }
2394
+ function Mn(e) {
2363
2395
  if (e.type === "web_search_call") {
2364
2396
  const t = e.action;
2365
2397
  if (t && typeof t == "object") {
@@ -2375,22 +2407,22 @@ function Rn(e) {
2375
2407
  }
2376
2408
  function _n(e) {
2377
2409
  if (typeof e.summary == "string" && e.summary.trim().length > 0)
2378
- return O(e.summary);
2410
+ return L(e.summary);
2379
2411
  if (typeof e.arguments == "string")
2380
2412
  try {
2381
2413
  const t = JSON.parse(e.arguments);
2382
2414
  if (typeof t.summary == "string" && t.summary.trim().length > 0)
2383
- return O(t.summary);
2415
+ return L(t.summary);
2384
2416
  } catch {
2385
- return typeof e.name == "string" && e.name.trim().length > 0 ? O(e.name) : "🛠️ Run tool";
2417
+ return typeof e.name == "string" && e.name.trim().length > 0 ? L(e.name) : "🛠️ Run tool";
2386
2418
  }
2387
- return typeof e.name == "string" && e.name.trim().length > 0 ? O(e.name) : "🛠️ Run tool";
2419
+ return typeof e.name == "string" && e.name.trim().length > 0 ? L(e.name) : "🛠️ Run tool";
2388
2420
  }
2389
- function O(e) {
2421
+ function L(e) {
2390
2422
  const t = e.trim() || "Run tool", s = t.codePointAt(0) ?? 0;
2391
2423
  return s >= 126976 && s <= 129791 || s >= 9728 && s <= 10175 || s >= 127462 && s <= 127487 ? t : `🛠️ ${t}`;
2392
2424
  }
2393
- function Mn(e) {
2425
+ function Cn(e) {
2394
2426
  if (e == null)
2395
2427
  return e;
2396
2428
  if (typeof e != "object")
@@ -2405,11 +2437,11 @@ function Mn(e) {
2405
2437
  runId: typeof t.runId == "string" ? t.runId : null
2406
2438
  };
2407
2439
  }
2408
- function le(e) {
2440
+ function de(e) {
2409
2441
  const t = e.callId ?? e.call_id;
2410
2442
  return typeof t == "string" && t ? t : null;
2411
2443
  }
2412
- function Cn(e) {
2444
+ function Un(e) {
2413
2445
  return typeof e == "string" ? e : Array.isArray(e) ? e.map((t) => {
2414
2446
  if (!t || typeof t != "object")
2415
2447
  return "";
@@ -2417,42 +2449,58 @@ function Cn(e) {
2417
2449
  return typeof s.text == "string" ? s.text : typeof s.content == "string" ? s.content : "";
2418
2450
  }).filter(Boolean).join("") : "";
2419
2451
  }
2420
- function Ce(e, t) {
2421
- const s = Pe(e, t), n = vn(
2422
- Ln(e, t),
2452
+ function Pt(e, t) {
2453
+ const s = Pe(e, t), n = On(
2454
+ Pn(
2455
+ Hn(e, t),
2456
+ s
2457
+ ),
2423
2458
  s
2424
2459
  ), r = n.findIndex((o) => o.id === s.id);
2425
2460
  if (r === -1)
2426
- return Dt(
2427
- vt([...n, s])
2461
+ return Ot(
2462
+ [...n, s]
2428
2463
  );
2429
2464
  const i = [...n];
2430
- return i[r] = s, Dt(vt(i));
2465
+ return i[r] = s, Ot(i);
2431
2466
  }
2432
2467
  function Pn(e, t) {
2468
+ const s = t.assistantDraftItemId;
2469
+ return s ? e.map(
2470
+ (n) => n.dataType === "assistant_draft" && n.id === s ? t : n
2471
+ ) : e;
2472
+ }
2473
+ function Dn(e, t, s) {
2474
+ return t !== null ? e.respondsToUserMessageId === t : s !== null && e.runId === s;
2475
+ }
2476
+ function vn(e, t) {
2433
2477
  const s = e.findIndex(
2434
2478
  (r) => !r.id.startsWith("transient-activity:") && r.callId === t.callId
2435
2479
  );
2436
2480
  if (s === -1)
2437
- return Ce(e, t);
2481
+ return Pt(e, t);
2438
2482
  const n = [...e];
2439
2483
  return n[s] = {
2440
2484
  ...n[s],
2441
2485
  content: t.content,
2442
- loading: !0
2486
+ loading: !0,
2487
+ ...n[s].respondsToUserMessageId ? {} : {
2488
+ respondsToUserMessageId: t.respondsToUserMessageId
2489
+ },
2490
+ ...n[s].runId ? {} : { runId: t.runId }
2443
2491
  }, n;
2444
2492
  }
2445
- function Un(e, t, s) {
2493
+ function xn(e, t, s) {
2446
2494
  let n = !1;
2447
2495
  const r = e.map((i) => i.callId !== t || i.loading === s ? i : (n = !0, { ...i, loading: s }));
2448
2496
  return n ? r : e;
2449
2497
  }
2450
- function Dn(e) {
2498
+ function Nn(e) {
2451
2499
  const t = typeof e.callId == "string" ? e.callId : null, s = typeof e.toolName == "string" ? e.toolName : null;
2452
2500
  return !t || !s ? null : {
2453
2501
  id: `transient-activity:${t}`,
2454
2502
  role: "tool",
2455
- content: O(
2503
+ content: L(
2456
2504
  typeof e.summary == "string" ? e.summary : "Running browser tool"
2457
2505
  ),
2458
2506
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
@@ -2464,60 +2512,86 @@ function Dn(e) {
2464
2512
  loading: !0
2465
2513
  };
2466
2514
  }
2467
- function vn(e, t) {
2515
+ function On(e, t) {
2468
2516
  if (t.id.startsWith("transient-activity:"))
2469
2517
  return e;
2470
2518
  const s = t.toolName === "tab_lifecycle";
2471
2519
  return !t.callId && !s ? e : e.filter(
2472
- (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)
2520
+ (n) => !(n.id === `transient-activity:${t.callId}` && n.callId === t.callId || s && n.id.startsWith("transient-activity:") && n.toolName === "browser_tabs" && n.runId && n.runId === t.runId)
2473
2521
  );
2474
2522
  }
2475
- function xn(e, t) {
2523
+ function Ln(e, t) {
2476
2524
  const s = t.map(
2477
- (n) => Pe(e, n)
2478
- );
2479
- return t.length > 0 ? s : e.filter(Ht);
2525
+ (c) => Pe(e, c)
2526
+ ), n = new Map(s.map((c) => [c.id, c])), r = new Map(
2527
+ s.flatMap((c) => {
2528
+ const l = c.clientMessageId;
2529
+ return l ? [[l, c]] : [];
2530
+ })
2531
+ ), i = new Map(
2532
+ s.flatMap((c) => {
2533
+ const l = c.assistantDraftItemId;
2534
+ return l ? [[l, c]] : [];
2535
+ })
2536
+ ), o = /* @__PURE__ */ new Set(), a = [];
2537
+ for (const c of e) {
2538
+ let l = n.get(c.id);
2539
+ if ($t(c)) {
2540
+ const u = Dt(c);
2541
+ if (l = u ? r.get(u) : void 0, !l) {
2542
+ a.push(c);
2543
+ continue;
2544
+ }
2545
+ } else if (c.dataType === "assistant_draft" && (l = i.get(c.id), !l)) {
2546
+ a.push(c);
2547
+ continue;
2548
+ }
2549
+ l && !o.has(l) && (a.push(l), o.add(l));
2550
+ }
2551
+ for (const c of s)
2552
+ o.has(c) || a.push(c);
2553
+ return a;
2480
2554
  }
2481
2555
  function Pe(e, t) {
2482
2556
  if (t.role !== "user" || !t.attachments?.length)
2483
2557
  return t;
2484
2558
  const s = e.find(
2485
- (r) => r.role === "user" && (r.id === t.id || Ht(r) && Ue(r, t))
2559
+ (r) => r.role === "user" && (r.id === t.id || $t(r) && De(r, t))
2486
2560
  );
2487
2561
  if (!s?.attachments?.length)
2488
2562
  return t;
2489
2563
  const n = t.attachments.map((r) => {
2490
- const i = Nn(s.attachments ?? [], r);
2491
- return i ? On(r, i) : r;
2564
+ const i = Bn(s.attachments ?? [], r);
2565
+ return i ? qn(r, i) : r;
2492
2566
  });
2493
2567
  return { ...t, attachments: n };
2494
2568
  }
2495
- function Nn(e, t) {
2569
+ function Bn(e, t) {
2496
2570
  return t.id ? e.find((s) => s.id === t.id) ?? null : null;
2497
2571
  }
2498
- function On(e, t) {
2572
+ function qn(e, t) {
2499
2573
  const { previewUrl: s } = t;
2500
2574
  return s ? { ...e, previewUrl: s } : e;
2501
2575
  }
2502
- function Ln(e, t) {
2576
+ function Hn(e, t) {
2503
2577
  if (t.role !== "user")
2504
2578
  return e;
2505
2579
  const s = e.findIndex(
2506
- (r) => Ht(r) && Ue(r, t)
2580
+ (r) => $t(r) && De(r, t)
2507
2581
  );
2508
2582
  if (s === -1)
2509
2583
  return e;
2510
2584
  const n = [...e];
2511
2585
  return n.splice(s, 1), n;
2512
2586
  }
2513
- function Ue(e, t) {
2514
- const s = ue(e), n = ue(t);
2587
+ function De(e, t) {
2588
+ const s = Dt(e), n = Dt(t);
2515
2589
  return s && n ? s === n : e.content === t.content;
2516
2590
  }
2517
- function Ht(e) {
2591
+ function $t(e) {
2518
2592
  return e.role === "user" && (e.id.startsWith("local-") || e.id.startsWith("optimistic-user-message:"));
2519
2593
  }
2520
- function ue(e) {
2594
+ function Dt(e) {
2521
2595
  const t = e.clientMessageId;
2522
2596
  if (t)
2523
2597
  return t;
@@ -2526,35 +2600,45 @@ function ue(e) {
2526
2600
  );
2527
2601
  return n ? e.id.slice(n.length) : null;
2528
2602
  }
2529
- function de(e) {
2530
- const t = De(e);
2603
+ function he(e) {
2604
+ const t = ve(e);
2531
2605
  if (t === null)
2532
2606
  return !1;
2533
- for (let s = e.length - 1; s > t; s -= 1) {
2534
- const n = e[s];
2535
- if (q(n))
2607
+ const s = e[t].id, n = e.some(
2608
+ (r) => r.respondsToUserMessageId === s && vt(r)
2609
+ );
2610
+ if (e.some((r) => r.respondsToUserMessageId === s))
2611
+ return n;
2612
+ for (let r = e.length - 1; r > t; r -= 1) {
2613
+ const i = e[r];
2614
+ if (x(i))
2536
2615
  return !0;
2537
- if (n.role === "system") {
2538
- if (n.dataType === "run_error")
2616
+ if (i.role === "system") {
2617
+ if (i.dataType === "run_error")
2539
2618
  return !0;
2540
- if (n.dataType === "run_status")
2541
- return n.loading !== !0;
2619
+ if (i.dataType === "run_status")
2620
+ return i.loading !== !0;
2542
2621
  }
2543
2622
  }
2544
2623
  return !1;
2545
2624
  }
2546
- function Bn(e) {
2547
- const t = De(e);
2548
- return t === null ? e.some(q) : e.slice(t + 1).some(q);
2625
+ function Fn(e) {
2626
+ const t = ve(e);
2627
+ if (t === null)
2628
+ return e.some(x);
2629
+ const s = e[t].id;
2630
+ return e.some((n) => n.respondsToUserMessageId === s) ? e.some(
2631
+ (n) => n.respondsToUserMessageId === s && x(n)
2632
+ ) : e.slice(t + 1).some(x);
2549
2633
  }
2550
- function De(e) {
2634
+ function ve(e) {
2551
2635
  for (let t = e.length - 1; t >= 0; t -= 1)
2552
2636
  if (e[t].role === "user")
2553
2637
  return t;
2554
2638
  return null;
2555
2639
  }
2556
- function qn(e) {
2557
- return q(e) ? !0 : e.role !== "system" ? !1 : e.dataType === "run_error" ? !0 : e.dataType === "run_status" && e.loading !== !0;
2640
+ function vt(e) {
2641
+ return x(e) ? !0 : e.role !== "system" ? !1 : e.dataType === "run_error" ? !0 : e.dataType === "run_status" && e.loading !== !0;
2558
2642
  }
2559
2643
  function ot(e) {
2560
2644
  for (let t = e.length - 1; t >= 0; t -= 1) {
@@ -2570,29 +2654,29 @@ function ot(e) {
2570
2654
  }
2571
2655
  return null;
2572
2656
  }
2573
- function Hn(e) {
2657
+ function Wn(e) {
2574
2658
  const t = ot(e);
2575
2659
  if (t === null)
2576
2660
  return null;
2577
- const n = L(e[t])?.page;
2661
+ const n = B(e[t])?.page;
2578
2662
  if (!n || typeof n != "object")
2579
2663
  return null;
2580
2664
  const r = n.url;
2581
2665
  return typeof r == "string" ? r : null;
2582
2666
  }
2583
- function L(e) {
2667
+ function B(e) {
2584
2668
  if (!e || typeof e != "object")
2585
2669
  return null;
2586
2670
  const t = e.data;
2587
2671
  return t && typeof t == "object" ? t : null;
2588
2672
  }
2589
- function Pt(e) {
2673
+ function xt(e) {
2590
2674
  return e?.retryable !== !0 ? !1 : e.type === "run_error" ? !0 : e.type === "run_status" && e.status === "interrupted";
2591
2675
  }
2592
- function he(e) {
2676
+ function pe(e) {
2593
2677
  return e?.type === "run_status" && e.status === "interrupted" && e.reason === "backend_restart";
2594
2678
  }
2595
- function Fn(e, t) {
2679
+ function $n(e, t) {
2596
2680
  const s = ot(t);
2597
2681
  if (s === null)
2598
2682
  return !1;
@@ -2600,9 +2684,11 @@ function Fn(e, t) {
2600
2684
  if (typeof r != "string" || !r)
2601
2685
  return !1;
2602
2686
  const i = e.findIndex((o) => o.role === "user" && o.id === r);
2603
- return i === -1 ? !1 : e.slice(i + 1).some(qn);
2687
+ return i === -1 ? !1 : e.some((o) => o.respondsToUserMessageId === r) ? e.some(
2688
+ (o) => o.respondsToUserMessageId === r && vt(o)
2689
+ ) : e.slice(i + 1).some(vt);
2604
2690
  }
2605
- function Ut(e) {
2691
+ function Nt(e) {
2606
2692
  const t = ot(e);
2607
2693
  if (t === null)
2608
2694
  return null;
@@ -2615,7 +2701,7 @@ function Ut(e) {
2615
2701
  const r = n.clientMessageId;
2616
2702
  return typeof r == "string" ? r : null;
2617
2703
  }
2618
- function Wn(e) {
2704
+ function jn(e) {
2619
2705
  const t = ot(e);
2620
2706
  if (t === null)
2621
2707
  return null;
@@ -2630,22 +2716,22 @@ function Wn(e) {
2630
2716
  if (i.type === "message" && i.role === "assistant")
2631
2717
  return null;
2632
2718
  if (i.type === "run_error")
2633
- return i.retryable !== !0 ? null : pe(e, i) ?? Ut(e);
2719
+ return i.retryable !== !0 ? null : fe(e, i) ?? Nt(e);
2634
2720
  if (i.type === "run_status")
2635
- return i.status === "interrupted" && i.retryable === !0 ? pe(e, i) ?? Ut(e) : null;
2721
+ return i.status === "interrupted" && i.retryable === !0 ? fe(e, i) ?? Nt(e) : null;
2636
2722
  }
2637
2723
  return null;
2638
2724
  }
2639
- function pe(e, t) {
2725
+ function fe(e, t) {
2640
2726
  if (typeof t.clientMessageId == "string")
2641
2727
  return t.clientMessageId;
2642
- const s = x(t);
2728
+ const s = N(t);
2643
2729
  if (!s)
2644
2730
  return null;
2645
- const n = e.find((i) => E(i, "id") === s), r = L(n);
2731
+ const n = e.find((i) => E(i, "id") === s), r = B(n);
2646
2732
  return r?.type === "message" && r.role === "user" && typeof r.clientMessageId == "string" ? r.clientMessageId : null;
2647
2733
  }
2648
- function $n(e, t) {
2734
+ function zn(e, t) {
2649
2735
  let s = 0;
2650
2736
  for (const n of e) {
2651
2737
  if (!n || typeof n != "object")
@@ -2658,64 +2744,65 @@ function $n(e, t) {
2658
2744
  }
2659
2745
  return s;
2660
2746
  }
2661
- function fe(e, t, s, n, r) {
2662
- if (!t || !jn(e))
2747
+ function ge(e, t, s, n, r) {
2748
+ if (!t || !Gn(e))
2663
2749
  return !1;
2664
2750
  const i = e;
2665
- return !(Pt(i) || s !== null && typeof i.id == "string" && i.id !== s || n !== null && x(i) !== n || r !== null && M(i) !== r);
2751
+ return !(xt(i) || s !== null && typeof i.id == "string" && i.id !== s || (n !== null ? N(i) !== n : r !== null && C(i) !== r));
2666
2752
  }
2667
- function jn(e) {
2753
+ function Gn(e) {
2668
2754
  if (!e || typeof e != "object")
2669
2755
  return !1;
2670
2756
  const t = e;
2671
- 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");
2757
+ 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" || t.status === "failed");
2672
2758
  }
2673
- function q(e) {
2759
+ function x(e) {
2674
2760
  return e.role === "assistant" && e.phase !== "commentary";
2675
2761
  }
2676
- function zn(e) {
2762
+ function Xn(e) {
2677
2763
  if (!e || typeof e != "object")
2678
2764
  return !1;
2679
2765
  const t = e;
2680
2766
  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";
2681
2767
  }
2682
- function Dt(e) {
2683
- return e.filter((t, s) => Ft(t) ? !Yn(e, s) && !Jn(e, s) && !Vn(e, s) : Gn(t) ? t.retryable === !0 && Kn(e, s) ? !1 : !Xn(e, s) : !0);
2768
+ function Ot(e) {
2769
+ return e.filter((t, s) => at(t) ? !er(e, s) && !Qn(e, s) && !tr(e, s) : Kn(t) ? t.retryable === !0 && Zn(e, s) ? !1 : !Yn(e, s) : !0);
2684
2770
  }
2685
- function Gn(e) {
2686
- return e.role === "system" && (e.dataType === "run_status" || e.dataType === "run_error");
2771
+ function Kn(e) {
2772
+ return e.role === "system" && (e.dataType === "run_error" || e.dataType === "run_status" && e.steered !== !0);
2687
2773
  }
2688
- function Ft(e) {
2774
+ function at(e) {
2689
2775
  return e.role === "system" && e.dataType === "run_status" && e.loading === !0;
2690
2776
  }
2691
- function vt(e) {
2692
- const t = new Set(e.filter((i) => i.role === "user").map((i) => i.id)), s = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set();
2693
- for (const i of e) {
2694
- if (i.role === "user" || !i.respondsToUserMessageId || !t.has(i.respondsToUserMessageId))
2695
- continue;
2696
- n.add(i.id);
2697
- const o = s.get(i.respondsToUserMessageId) ?? [];
2698
- o.push(i), s.set(i.respondsToUserMessageId, o);
2699
- }
2700
- if (n.size === 0)
2701
- return e;
2702
- const r = [];
2703
- for (const i of e)
2704
- n.has(i.id) || (r.push(i), i.role === "user" && r.push(...s.get(i.id) ?? []));
2705
- return r;
2777
+ function Jn(e, t) {
2778
+ const s = [...e].reverse().find(
2779
+ (n) => n.respondsToUserMessageId !== void 0 && n.respondsToUserMessageId !== t && me(n) && !Vn(
2780
+ e,
2781
+ n.respondsToUserMessageId
2782
+ )
2783
+ )?.respondsToUserMessageId;
2784
+ return s ? e.map(
2785
+ (n) => n.respondsToUserMessageId === s && me(n) ? { ...n, steered: !0 } : n
2786
+ ) : e;
2706
2787
  }
2707
- function Xn(e, t) {
2788
+ function me(e) {
2789
+ return e.role === "tool" || at(e) ? !0 : e.role === "assistant" && e.phase === "commentary";
2790
+ }
2791
+ function Vn(e, t) {
2792
+ return e.some(
2793
+ (s) => s.respondsToUserMessageId === t && (x(s) || s.role === "system" && (s.dataType === "run_error" || s.dataType === "run_status" && s.loading !== !0))
2794
+ );
2795
+ }
2796
+ function Yn(e, t) {
2708
2797
  const s = e[t];
2709
2798
  for (let n = t + 1; n < e.length; n += 1) {
2710
2799
  const r = e[n];
2711
- if (r.role === "user")
2712
- return !1;
2713
- if (r.role === "assistant" && at(s, r))
2800
+ if (r.role === "assistant" && ct(s, r))
2714
2801
  return !0;
2715
2802
  }
2716
2803
  return !1;
2717
2804
  }
2718
- function Kn(e, t) {
2805
+ function Zn(e, t) {
2719
2806
  const s = e[t];
2720
2807
  if (!s.respondsToUserMessageId)
2721
2808
  return !1;
@@ -2723,47 +2810,45 @@ function Kn(e, t) {
2723
2810
  const r = e[n];
2724
2811
  if (r.role === "user")
2725
2812
  return !1;
2726
- if (r.respondsToUserMessageId === s.respondsToUserMessageId && (r.role === "assistant" || r.role === "tool" || Ft(r)))
2813
+ if (r.respondsToUserMessageId === s.respondsToUserMessageId && (r.role === "assistant" || r.role === "tool" || at(r)))
2727
2814
  return !0;
2728
2815
  }
2729
2816
  return !1;
2730
2817
  }
2731
- function Jn(e, t) {
2818
+ function Qn(e, t) {
2732
2819
  const s = e[t];
2733
- for (let n = t + 1; n < e.length; n += 1)
2734
- if (e[n].role === "assistant" && at(s, e[n]))
2735
- return !0;
2736
- return !1;
2820
+ return e.some(
2821
+ (n, r) => r !== t && n.role === "assistant" && ct(s, n)
2822
+ );
2737
2823
  }
2738
- function Vn(e, t) {
2824
+ function tr(e, t) {
2739
2825
  const s = e[t];
2740
- for (let n = t + 1; n < e.length; n += 1)
2741
- if (e[n].role === "tool" && at(s, e[n]))
2742
- return !0;
2743
- return !1;
2826
+ return e.some(
2827
+ (n, r) => r !== t && n.role === "tool" && ct(s, n)
2828
+ );
2744
2829
  }
2745
- function Yn(e, t) {
2830
+ function er(e, t) {
2746
2831
  const s = e[t];
2747
2832
  for (let n = t + 1; n < e.length; n += 1)
2748
- if (Ft(e[n]) && at(s, e[n]))
2833
+ if (at(e[n]) && ct(s, e[n]))
2749
2834
  return !0;
2750
2835
  return !1;
2751
2836
  }
2752
- function at(e, t) {
2753
- return !e.runId || !t.runId ? !0 : e.runId === t.runId;
2837
+ function ct(e, t) {
2838
+ return !!(e.respondsToUserMessageId && e.respondsToUserMessageId === t.respondsToUserMessageId);
2754
2839
  }
2755
2840
  function E(e, t) {
2756
2841
  return e && typeof e == "object" && typeof e[t] == "string" ? e[t] : null;
2757
2842
  }
2758
- function Zn(e, t) {
2843
+ function sr(e, t) {
2759
2844
  try {
2760
- const s = window.localStorage.getItem(`${Se}${e}`);
2845
+ const s = window.localStorage.getItem(`${be}${e}`);
2761
2846
  if (!s)
2762
2847
  return null;
2763
2848
  const n = JSON.parse(s), r = typeof n.sessionId == "string" ? n.sessionId : null;
2764
2849
  if (t !== void 0 && r !== t)
2765
2850
  return null;
2766
- const i = Array.isArray(n.messages) ? n.messages.map(cr).filter((o) => !!o) : [];
2851
+ const i = Array.isArray(n.messages) ? n.messages.map(hr).filter((o) => !!o) : [];
2767
2852
  return {
2768
2853
  sessionId: r,
2769
2854
  messages: i
@@ -2772,46 +2857,46 @@ function Zn(e, t) {
2772
2857
  return null;
2773
2858
  }
2774
2859
  }
2775
- function Qn(e, t) {
2860
+ function nr(e, t) {
2776
2861
  try {
2777
2862
  window.localStorage.setItem(
2778
- `${Se}${e}`,
2863
+ `${be}${e}`,
2779
2864
  JSON.stringify({
2780
2865
  sessionId: t.sessionId,
2781
- messages: t.messages.slice(-Ps).map(lr)
2866
+ messages: t.messages.slice(-Ps).map(pr)
2782
2867
  })
2783
2868
  );
2784
2869
  } catch {
2785
2870
  return;
2786
2871
  }
2787
2872
  }
2788
- function tr(e) {
2873
+ function rr(e) {
2789
2874
  try {
2790
- const t = window.localStorage.getItem(`${Ct}${e}`);
2875
+ const t = window.localStorage.getItem(`${Ut}${e}`);
2791
2876
  if (!t)
2792
2877
  return [];
2793
2878
  const s = JSON.parse(t);
2794
- return Array.isArray(s) ? s.filter(Wt) : [];
2879
+ return Array.isArray(s) ? s.filter(jt) : [];
2795
2880
  } catch {
2796
2881
  return [];
2797
2882
  }
2798
2883
  }
2799
2884
  function $(e, t) {
2800
2885
  try {
2801
- const s = t.filter(Wt);
2886
+ const s = t.filter(jt);
2802
2887
  if (s.length === 0) {
2803
- window.localStorage.removeItem(`${Ct}${e}`);
2888
+ window.localStorage.removeItem(`${Ut}${e}`);
2804
2889
  return;
2805
2890
  }
2806
2891
  window.localStorage.setItem(
2807
- `${Ct}${e}`,
2892
+ `${Ut}${e}`,
2808
2893
  JSON.stringify(s.slice(-25))
2809
2894
  );
2810
2895
  } catch {
2811
2896
  return;
2812
2897
  }
2813
2898
  }
2814
- function ve(e, t) {
2899
+ function xe(e, t) {
2815
2900
  try {
2816
2901
  const s = `${it}${e}`, n = location.href, r = location.origin, i = Array.from(t, (o) => ({
2817
2902
  ...o,
@@ -2827,28 +2912,28 @@ function ve(e, t) {
2827
2912
  } catch {
2828
2913
  }
2829
2914
  }
2830
- function er(e, t) {
2915
+ function ir(e, t) {
2831
2916
  try {
2832
2917
  if (window.sessionStorage.getItem(`${it}${e}`) === null)
2833
2918
  return;
2834
2919
  } catch {
2835
2920
  return;
2836
2921
  }
2837
- ve(e, t);
2922
+ xe(e, t);
2838
2923
  }
2839
- function sr(e) {
2924
+ function or(e) {
2840
2925
  try {
2841
2926
  const t = `${it}${e}`, s = window.sessionStorage.getItem(t);
2842
2927
  if (window.sessionStorage.removeItem(t), !s)
2843
2928
  return [];
2844
2929
  const n = JSON.parse(s);
2845
- return Array.isArray(n) ? n.flatMap((r) => rr(r) ? [{
2930
+ return Array.isArray(n) ? n.flatMap((r) => cr(r) ? [{
2846
2931
  ...r.event,
2847
2932
  page: k(),
2848
2933
  rawOutput: {
2849
2934
  pageContextRestarted: !0,
2850
2935
  outcome: "unknown",
2851
- message: nr(location.href),
2936
+ message: ar(location.href),
2852
2937
  currentUrl: location.href,
2853
2938
  console: [],
2854
2939
  metadata: {
@@ -2865,17 +2950,17 @@ function sr(e) {
2865
2950
  return [];
2866
2951
  }
2867
2952
  }
2868
- function nr(e) {
2953
+ function ar(e) {
2869
2954
  return `The page context restarted. This is expected when the action included page navigation. Otherwise, it's unknown whether the action completed.
2870
2955
  Current URL: ${e}`;
2871
2956
  }
2872
- function rr(e) {
2957
+ function cr(e) {
2873
2958
  if (!e || typeof e != "object")
2874
2959
  return !1;
2875
2960
  const t = e, s = t.event;
2876
- return typeof t.startedAtMs == "number" && typeof t.startedAtUrl == "string" && t.startedAtOrigin === location.origin && t.unloadOrigin === location.origin && typeof t.unloadUrl == "string" && Wt(s) && s.type === "tool.result";
2961
+ return typeof t.startedAtMs == "number" && typeof t.startedAtUrl == "string" && t.startedAtOrigin === location.origin && t.unloadOrigin === location.origin && typeof t.unloadUrl == "string" && jt(s) && s.type === "tool.result";
2877
2962
  }
2878
- function ir(e, t) {
2963
+ function lr(e, t) {
2879
2964
  const s = new Set(
2880
2965
  e.flatMap((n) => n.type === "tool.result" ? [n.callId] : [])
2881
2966
  );
@@ -2884,26 +2969,26 @@ function ir(e, t) {
2884
2969
  ...t.filter((n) => !s.has(n.callId))
2885
2970
  ];
2886
2971
  }
2887
- function or(e) {
2972
+ function ur(e) {
2888
2973
  try {
2889
2974
  window.sessionStorage.removeItem(`${it}${e}`);
2890
2975
  } catch {
2891
2976
  return;
2892
2977
  }
2893
2978
  }
2894
- function Wt(e) {
2979
+ function jt(e) {
2895
2980
  if (!e || typeof e != "object")
2896
2981
  return !1;
2897
2982
  const t = e;
2898
- return t.type === "chat.user_message" ? typeof t.content == "string" && ge(t.page) : t.type === "page.upsert" || t.type === "session.reset" || t.type === "network.batch" ? ge(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;
2983
+ return t.type === "chat.user_message" ? typeof t.content == "string" && ye(t.page) : t.type === "page.upsert" || t.type === "session.reset" || t.type === "network.batch" ? ye(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;
2899
2984
  }
2900
- function ge(e) {
2985
+ function ye(e) {
2901
2986
  if (!e || typeof e != "object")
2902
2987
  return !1;
2903
2988
  const t = e;
2904
2989
  return typeof t.url == "string" && typeof t.title == "string" && typeof t.origin == "string";
2905
2990
  }
2906
- function xe(e, t) {
2991
+ function Ne(e, t) {
2907
2992
  if (!Array.isArray(e))
2908
2993
  return;
2909
2994
  const s = e.filter((r) => {
@@ -2911,23 +2996,23 @@ function xe(e, t) {
2911
2996
  return !1;
2912
2997
  const i = r;
2913
2998
  return typeof i.name == "string" && typeof i.mimeType == "string" && typeof i.sizeBytes == "number";
2914
- }), n = t ? s.map((r) => Ne(r, t)) : s;
2999
+ }), n = t ? s.map((r) => Oe(r, t)) : s;
2915
3000
  return n.length > 0 ? n : void 0;
2916
3001
  }
2917
- function Ne(e, t) {
3002
+ function Oe(e, t) {
2918
3003
  return e.fileUrl?.startsWith("/") ? {
2919
3004
  ...e,
2920
3005
  fileUrl: new URL(e.fileUrl, t).toString()
2921
3006
  } : e;
2922
3007
  }
2923
- function me(e) {
2924
- return e.type || ar(e.name) || "application/octet-stream";
3008
+ function Ie(e) {
3009
+ return e.type || dr(e.name) || "application/octet-stream";
2925
3010
  }
2926
- function ar(e) {
3011
+ function dr(e) {
2927
3012
  const t = e.toLowerCase();
2928
3013
  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;
2929
3014
  }
2930
- function cr(e) {
3015
+ function hr(e) {
2931
3016
  if (!e || typeof e != "object")
2932
3017
  return null;
2933
3018
  const t = e;
@@ -2940,17 +3025,17 @@ function cr(e) {
2940
3025
  ...typeof t.runId == "string" ? { runId: t.runId } : {},
2941
3026
  dataType: typeof t.dataType == "string" ? t.dataType : void 0,
2942
3027
  securitySettingsUrl: typeof t.securitySettingsUrl == "string" ? t.securitySettingsUrl : void 0,
2943
- attachments: xe(t.attachments)?.map($t),
3028
+ attachments: Ne(t.attachments)?.map(zt),
2944
3029
  loading: typeof t.loading == "boolean" ? t.loading : void 0
2945
3030
  };
2946
3031
  }
2947
- function lr(e) {
3032
+ function pr(e) {
2948
3033
  return e.attachments?.length ? {
2949
3034
  ...e,
2950
- attachments: e.attachments.map($t)
3035
+ attachments: e.attachments.map(zt)
2951
3036
  } : e;
2952
3037
  }
2953
- function $t(e) {
3038
+ function zt(e) {
2954
3039
  const {
2955
3040
  dataUrl: t,
2956
3041
  objectUrl: s,
@@ -2959,47 +3044,47 @@ function $t(e) {
2959
3044
  } = e;
2960
3045
  return r;
2961
3046
  }
2962
- function x(e) {
3047
+ function N(e) {
2963
3048
  const t = e.respondsToUserMessageId;
2964
3049
  return typeof t == "string" && t ? t : null;
2965
3050
  }
2966
- function M(e) {
3051
+ function C(e) {
2967
3052
  const t = e.runId;
2968
3053
  return typeof t == "string" && t ? t : null;
2969
3054
  }
2970
- function ur(e) {
3055
+ function fr(e) {
2971
3056
  const t = e?.timeoutMs;
2972
- 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 <= Bs);
3057
+ 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);
2973
3058
  }
2974
- function Oe(e) {
3059
+ function Le(e) {
2975
3060
  const t = {};
2976
3061
  try {
2977
3062
  new Headers(e).forEach((s, n) => {
2978
- Object.keys(t).length < Bt && (t[n] = jt(n, s));
3063
+ Object.keys(t).length < Ft && (t[n] = Gt(n, s));
2979
3064
  });
2980
3065
  } catch {
2981
3066
  return {};
2982
3067
  }
2983
3068
  return t;
2984
3069
  }
2985
- function jt(e, t) {
2986
- return We(e) ? ct : C(rt(t), Ms);
3070
+ function Gt(e, t) {
3071
+ return $e(e) ? lt : U(rt(t), Cs);
2987
3072
  }
2988
- function dr(e, t) {
3073
+ function gr(e, t) {
2989
3074
  return typeof e == "string" ? e : e instanceof URL ? e.toString() : t?.url ?? "";
2990
3075
  }
2991
- async function hr(e, t, s, n) {
2992
- const r = Oe(e.headers);
3076
+ async function mr(e, t, s, n) {
3077
+ const r = Le(e.headers);
2993
3078
  n({
2994
3079
  ...t,
2995
3080
  responseStatus: e.status,
2996
3081
  responseHeaders: r,
2997
- responseBody: await pr(e),
3082
+ responseBody: await yr(e),
2998
3083
  durationMs: Date.now() - s
2999
3084
  });
3000
3085
  }
3001
- async function pr(e) {
3002
- if (!Le(e.headers))
3086
+ async function yr(e) {
3087
+ if (!Be(e.headers))
3003
3088
  return;
3004
3089
  let t = null, s = null;
3005
3090
  try {
@@ -3008,7 +3093,7 @@ async function pr(e) {
3008
3093
  const n = new Promise((a) => {
3009
3094
  s = window.setTimeout(() => {
3010
3095
  t?.cancel(), a("timeout");
3011
- }, Cs);
3096
+ }, Us);
3012
3097
  }), r = new TextDecoder();
3013
3098
  let i = "", o = 0;
3014
3099
  for (; ; ) {
@@ -3017,10 +3102,10 @@ async function pr(e) {
3017
3102
  return;
3018
3103
  const { done: c, value: l } = a;
3019
3104
  if (c)
3020
- return C(i + r.decode());
3021
- const d = Lt - o;
3022
- if (l.byteLength > d)
3023
- return i += r.decode(l.subarray(0, Math.max(d, 0)), { stream: !0 }), t.cancel(), `${C(i)}... [truncated]`;
3105
+ return U(i + r.decode());
3106
+ const u = Ht - o;
3107
+ if (l.byteLength > u)
3108
+ return i += r.decode(l.subarray(0, Math.max(u, 0)), { stream: !0 }), t.cancel(), `${U(i)}... [truncated]`;
3024
3109
  o += l.byteLength, i += r.decode(l, { stream: !0 });
3025
3110
  }
3026
3111
  } catch {
@@ -3030,26 +3115,26 @@ async function pr(e) {
3030
3115
  s !== null && window.clearTimeout(s);
3031
3116
  }
3032
3117
  }
3033
- function fr(e, t) {
3034
- if (Le(new Headers(t)))
3118
+ function Ir(e, t) {
3119
+ if (Be(new Headers(t)))
3035
3120
  try {
3036
- return e.responseType === "" || e.responseType === "text" ? C(e.responseText ?? "") : void 0;
3121
+ return e.responseType === "" || e.responseType === "text" ? U(e.responseText ?? "") : void 0;
3037
3122
  } catch {
3038
3123
  return;
3039
3124
  }
3040
3125
  }
3041
- function ye(e) {
3126
+ function Te(e) {
3042
3127
  if (typeof e == "string")
3043
- return C(e);
3128
+ return U(e);
3044
3129
  }
3045
- function gr(e) {
3130
+ function Tr(e) {
3046
3131
  return R({
3047
3132
  ...e,
3048
- requestBody: Te(e.requestBody),
3049
- responseBody: Te(e.responseBody)
3133
+ requestBody: we(e.requestBody),
3134
+ responseBody: we(e.responseBody)
3050
3135
  });
3051
3136
  }
3052
- function Te(e) {
3137
+ function we(e) {
3053
3138
  if (typeof e != "string")
3054
3139
  return e;
3055
3140
  const t = e.trim();
@@ -3061,14 +3146,14 @@ function Te(e) {
3061
3146
  return rt(e);
3062
3147
  }
3063
3148
  }
3064
- function Le(e) {
3149
+ function Be(e) {
3065
3150
  if (!e)
3066
3151
  return !1;
3067
3152
  const t = e.get("content-type")?.toLowerCase() ?? "", s = e.get("content-length"), n = Number(s);
3068
- return s !== null && Number.isInteger(n) && n >= 0 && n <= Lt && (t.startsWith("text/") || t.includes("json") || t.includes("javascript"));
3153
+ return s !== null && Number.isInteger(n) && n >= 0 && n <= Ht && (t.startsWith("text/") || t.includes("json") || t.includes("javascript"));
3069
3154
  }
3070
- function N(e, t = {}, s) {
3071
- if (yr(s))
3155
+ function O(e, t = {}, s) {
3156
+ if (Ar(s))
3072
3157
  return !0;
3073
3158
  const n = Object.entries(t).find(([r]) => r.toLowerCase() === "content-type")?.[1]?.toLowerCase();
3074
3159
  if (n?.includes("multipart/form-data") || n?.includes("application/octet-stream"))
@@ -3083,8 +3168,8 @@ function N(e, t = {}, s) {
3083
3168
  return !0;
3084
3169
  }
3085
3170
  }
3086
- function mr(e, t) {
3087
- if (N(e))
3171
+ function wr(e, t) {
3172
+ if (O(e))
3088
3173
  return !0;
3089
3174
  try {
3090
3175
  const s = new URL(e, location.href), n = new URL(t);
@@ -3093,26 +3178,26 @@ function mr(e, t) {
3093
3178
  return !0;
3094
3179
  }
3095
3180
  }
3096
- function yr(e) {
3181
+ function Ar(e) {
3097
3182
  return e instanceof FormData || e instanceof Blob || e instanceof ArrayBuffer || ArrayBuffer.isView(e) || typeof ReadableStream < "u" && e instanceof ReadableStream;
3098
3183
  }
3099
- function Tr(e) {
3184
+ function Sr(e) {
3100
3185
  const t = {};
3101
3186
  for (const s of e.trim().split(/[\r\n]+/)) {
3102
3187
  const n = s.indexOf(":");
3103
3188
  if (n <= 0)
3104
3189
  continue;
3105
- if (Object.keys(t).length >= Bt)
3190
+ if (Object.keys(t).length >= Ft)
3106
3191
  break;
3107
3192
  const r = s.slice(0, n).trim();
3108
- t[r] = jt(r, s.slice(n + 1).trim());
3193
+ t[r] = Gt(r, s.slice(n + 1).trim());
3109
3194
  }
3110
3195
  return t;
3111
3196
  }
3112
- function C(e, t = Lt) {
3197
+ function U(e, t = Ht) {
3113
3198
  return e.length <= t ? e : `${e.slice(0, t)}... [truncated ${e.length - t} chars]`;
3114
3199
  }
3115
- function Rt(e) {
3200
+ function Mt(e) {
3116
3201
  return `${e}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
3117
3202
  }
3118
3203
  class st extends Error {
@@ -3123,31 +3208,31 @@ class st extends Error {
3123
3208
  }
3124
3209
  async function Q(e, t) {
3125
3210
  let s = null;
3126
- for (let n = 0; n < re; n += 1)
3211
+ for (let n = 0; n < oe; n += 1)
3127
3212
  try {
3128
3213
  return await e();
3129
3214
  } catch (r) {
3130
- if (s = r, n >= re - 1 || !wr(r))
3215
+ if (s = r, n >= oe - 1 || !br(r))
3131
3216
  throw r;
3132
- await Ir(n);
3217
+ await Er(n);
3133
3218
  }
3134
3219
  throw s instanceof Error ? s : new Error(t);
3135
3220
  }
3136
- function Ir(e) {
3221
+ function Er(e) {
3137
3222
  return new Promise((t) => {
3138
3223
  window.setTimeout(t, _s[e] ?? 0);
3139
3224
  });
3140
3225
  }
3141
- function wr(e) {
3142
- return e instanceof st ? Ar(e.status) : e instanceof TypeError;
3226
+ function br(e) {
3227
+ return e instanceof st ? kr(e.status) : e instanceof TypeError;
3143
3228
  }
3144
- function Ar(e) {
3229
+ function kr(e) {
3145
3230
  return e === 408 || e === 409 || e === 429 || e >= 500;
3146
3231
  }
3147
- function Sr(e) {
3232
+ function Rr(e) {
3148
3233
  return e === 401 || e === 403;
3149
3234
  }
3150
- const ct = "[REDACTED_SECRET]", P = "[REDACTED_TOKEN]", Er = "[REDACTED_SIGNED_URL]", br = 20, kr = /^(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, Be = /\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi, qe = /\bBasic\s+[A-Za-z0-9+/=-]{12,}/gi, He = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g, Fe = /\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, Rr = /\bhttps?:\/\/[^\s"'<>]+(?:X-Amz-Signature|X-Goog-Signature|Signature|sig=)[^\s"'<>]*/gi, _r = /\bhttps?:\/\/[^\s"'<>]+/gi, Mr = /[),.;\]]+$/;
3235
+ const lt = "[REDACTED_SECRET]", P = "[REDACTED_TOKEN]", Mr = "[REDACTED_SIGNED_URL]", _r = 20, Cr = /^(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, qe = /\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi, He = /\bBasic\s+[A-Za-z0-9+/=-]{12,}/gi, Fe = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g, We = /\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, Ur = /\bhttps?:\/\/[^\s"'<>]+(?:X-Amz-Signature|X-Goog-Signature|Signature|sig=)[^\s"'<>]*/gi, Pr = /\bhttps?:\/\/[^\s"'<>]+/gi, Dr = /[),.;\]]+$/;
3151
3236
  function R(e) {
3152
3237
  return nt(e, 0, /* @__PURE__ */ new WeakSet());
3153
3238
  }
@@ -3156,7 +3241,7 @@ function nt(e, t, s) {
3156
3241
  return e.startsWith("data:image/") || e.startsWith("data:application/pdf;") ? e : rt(e);
3157
3242
  if (e === null || typeof e != "object")
3158
3243
  return e;
3159
- if (t >= br)
3244
+ if (t >= _r)
3160
3245
  return "[REDACTED_MAX_DEPTH]";
3161
3246
  if (s.has(e))
3162
3247
  return "[REDACTED_CIRCULAR]";
@@ -3164,44 +3249,44 @@ function nt(e, t, s) {
3164
3249
  return e.map((r) => nt(r, t + 1, s));
3165
3250
  const n = {};
3166
3251
  for (const [r, i] of Object.entries(e))
3167
- r === "pageContent" ? n[r] = i : We(r) ? n[r] = ct : n[r] = r.toLowerCase() === "url" ? Cr(i) : nt(i, t + 1, s);
3252
+ r === "pageContent" ? n[r] = i : $e(r) ? n[r] = lt : n[r] = r.toLowerCase() === "url" ? vr(i) : nt(i, t + 1, s);
3168
3253
  return n;
3169
3254
  }
3170
- function We(e) {
3255
+ function $e(e) {
3171
3256
  const t = e.replace(/[^a-z0-9]/gi, "").toLowerCase();
3172
3257
  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");
3173
3258
  }
3174
- function Cr(e) {
3175
- return typeof e == "string" ? $e(e) : nt(e, 0, /* @__PURE__ */ new WeakSet());
3259
+ function vr(e) {
3260
+ return typeof e == "string" ? je(e) : nt(e, 0, /* @__PURE__ */ new WeakSet());
3176
3261
  }
3177
- function $e(e) {
3262
+ function je(e) {
3178
3263
  try {
3179
3264
  const t = new URL(e, location.href);
3180
3265
  for (const s of Array.from(t.searchParams.keys()))
3181
- kr.test(s) && t.searchParams.set(s, P);
3266
+ Cr.test(s) && t.searchParams.set(s, P);
3182
3267
  return t.username && (t.username = P), t.password && (t.password = P), t.toString();
3183
3268
  } catch {
3184
- return Pr(e);
3269
+ return xr(e);
3185
3270
  }
3186
3271
  }
3187
3272
  function rt(e) {
3188
- return e.replace(Rr, Er).replace(_r, Ur).replace(Be, `Bearer ${P}`).replace(qe, `Basic ${P}`).replace(He, P).replace(Fe, (t, s) => `${s}: ${ct}`);
3273
+ return e.replace(Ur, Mr).replace(Pr, Nr).replace(qe, `Bearer ${P}`).replace(He, `Basic ${P}`).replace(Fe, P).replace(We, (t, s) => `${s}: ${lt}`);
3189
3274
  }
3190
- function Pr(e) {
3191
- return e.replace(Be, `Bearer ${P}`).replace(qe, `Basic ${P}`).replace(He, P).replace(Fe, (t, s) => `${s}: ${ct}`);
3275
+ function xr(e) {
3276
+ return e.replace(qe, `Bearer ${P}`).replace(He, `Basic ${P}`).replace(Fe, P).replace(We, (t, s) => `${s}: ${lt}`);
3192
3277
  }
3193
- function Ur(e) {
3194
- const t = e.match(Mr)?.[0] ?? "", s = t ? e.slice(0, -t.length) : e;
3195
- return `${$e(s)}${t}`;
3278
+ function Nr(e) {
3279
+ const t = e.match(Dr)?.[0] ?? "", s = t ? e.slice(0, -t.length) : e;
3280
+ return `${je(s)}${t}`;
3196
3281
  }
3197
3282
  export {
3198
- te as PLUNO_PRODUCT_AGENT_SDK_PREVIEW_HOST_SELECTOR,
3199
- Mt as PLUNO_PRODUCT_AGENT_WIDGET_HOST_SELECTOR,
3200
- ds as PLUNO_PRODUCT_AGENT_WIDGET_PANEL_SELECTOR,
3201
- us as PLUNO_PRODUCT_AGENT_WIDGET_ROOT_SELECTOR,
3202
- hs as PLUNO_PRODUCT_AGENT_WIDGET_TIMELINE_SELECTOR,
3203
- Ee as PlunoProductAgent,
3204
- Ds as calculateReconnectDelay,
3205
- Ee as default,
3206
- en as getProductAgentOriginAccessErrorMessage
3283
+ se as PLUNO_PRODUCT_AGENT_SDK_PREVIEW_HOST_SELECTOR,
3284
+ Ct as PLUNO_PRODUCT_AGENT_WIDGET_HOST_SELECTOR,
3285
+ hs as PLUNO_PRODUCT_AGENT_WIDGET_PANEL_SELECTOR,
3286
+ ds as PLUNO_PRODUCT_AGENT_WIDGET_ROOT_SELECTOR,
3287
+ ps as PLUNO_PRODUCT_AGENT_WIDGET_TIMELINE_SELECTOR,
3288
+ ke as PlunoProductAgent,
3289
+ vs as calculateReconnectDelay,
3290
+ ke as default,
3291
+ sn as getProductAgentOriginAccessErrorMessage
3207
3292
  };