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