@pluno/product-agent-web 0.1.161 → 0.1.163

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.
@@ -62,11 +62,11 @@ function Xe(t) {
62
62
  t.onsuccess = () => e(t.result), t.onerror = () => s(t.error ?? new Error("Product Agent attachment storage request failed"));
63
63
  });
64
64
  }
65
- function hs(t) {
65
+ function ps(t) {
66
66
  return t !== null && (typeof t == "object" || typeof t == "function");
67
67
  }
68
- function Ut(t, e, s) {
69
- const n = Reflect.get(t, "pluno"), r = hs(n) ? n : {};
68
+ function Pt(t, e, s) {
69
+ const n = Reflect.get(t, "pluno"), r = ps(n) ? n : {};
70
70
  if (r !== n && !Reflect.set(t, "pluno", r))
71
71
  return null;
72
72
  const i = Object.getOwnPropertyDescriptor(r, e);
@@ -80,10 +80,10 @@ function Ut(t, e, s) {
80
80
  }
81
81
  };
82
82
  }
83
- const ps = /(\]\()(\/api\/product-agent\/attachments\/download\?[^)\s]+)(\))/g;
83
+ const hs = /(\]\()(\/api\/product-agent\/attachments\/download\?[^)\s]+)(\))/g;
84
84
  function gs(t, e) {
85
85
  return e ? t.replace(
86
- ps,
86
+ hs,
87
87
  (s, n, r, i) => `${n}${new URL(r, e).toString()}${i}`
88
88
  ) : t;
89
89
  }
@@ -108,7 +108,7 @@ function fs(t, e, s) {
108
108
  const m = c.get(g);
109
109
  (!m || s(m).isTransient) && c.set(g, u);
110
110
  }
111
- const h = new Set(i.map(({ identity: u }) => u.id)), p = new Set(
111
+ const p = new Set(i.map(({ identity: u }) => u.id)), h = new Set(
112
112
  i.flatMap(({ identity: u }) => u.runId ? [u.runId] : [])
113
113
  ), w = /* @__PURE__ */ new Set(), y = [];
114
114
  for (const u of t) {
@@ -118,7 +118,7 @@ function fs(t, e, s) {
118
118
  y.push(g), w.add(g);
119
119
  continue;
120
120
  }
121
- const m = d.respondsToUserMessageId !== void 0 && h.has(d.respondsToUserMessageId) || d.runId !== void 0 && p.has(d.runId);
121
+ const m = d.respondsToUserMessageId !== void 0 && p.has(d.respondsToUserMessageId) || d.runId !== void 0 && h.has(d.runId);
122
122
  (d.isOptimistic || (d.isAssistantDraft || d.isActivity) && m) && y.push(u);
123
123
  }
124
124
  for (const { item: u } of i)
@@ -131,11 +131,11 @@ function ms(t, e, s, n) {
131
131
  return !i.isActivity || !i.isTransient ? !0 : e !== null && i.respondsToUserMessageId !== void 0 ? i.respondsToUserMessageId !== e : s === null || i.runId !== s;
132
132
  });
133
133
  }
134
- const be = "pluno.productAgent.transportId", ys = "pluno.productAgent.transportIdentity", Ce = "pluno.productAgent.transportIdentity.event", Is = 50, Ts = globalThis.setTimeout.bind(globalThis);
135
- let z = null;
134
+ const Ce = "pluno.productAgent.transportId", ys = "pluno.productAgent.transportIdentity", be = "pluno.productAgent.transportIdentity.event", Is = 50, Ts = globalThis.setTimeout.bind(globalThis);
135
+ let K = null;
136
136
  const le = /* @__PURE__ */ new Set(), _e = /* @__PURE__ */ new Map();
137
- async function ws(t = Pt()) {
138
- const e = t.randomUUID(), s = t.storage.getItem(be);
137
+ async function ws(t = Ut()) {
138
+ const e = t.randomUUID(), s = t.storage.getItem(Ce);
139
139
  let n = s ?? t.randomUUID(), r = !1, i = !1;
140
140
  const o = t.channel.subscribe((l) => {
141
141
  if (!(l.senderId === e || l.transportId !== n)) {
@@ -153,14 +153,14 @@ async function ws(t = Pt()) {
153
153
  }
154
154
  });
155
155
  if (!s)
156
- t.storage.setItem(be, n), r = !0;
156
+ t.storage.setItem(Ce, n), r = !0;
157
157
  else
158
158
  for (; ; ) {
159
159
  if (i = !1, t.channel.postMessage({ type: "probe", transportId: n, senderId: e }), await t.settle(), !i) {
160
160
  r = !0;
161
161
  break;
162
162
  }
163
- n = t.randomUUID(), t.storage.setItem(be, n);
163
+ n = t.randomUUID(), t.storage.setItem(Ce, n);
164
164
  }
165
165
  let a = !1;
166
166
  return {
@@ -171,13 +171,13 @@ async function ws(t = Pt()) {
171
171
  };
172
172
  }
173
173
  async function Ss() {
174
- z || (z = ws(Pt()), z.then((n) => {
174
+ K || (K = ws(Ut()), K.then((n) => {
175
175
  const r = (i) => {
176
- i.persisted || (n.release(), z = null, le.clear(), window.removeEventListener("pagehide", r));
176
+ i.persisted || (n.release(), K = null, le.clear(), window.removeEventListener("pagehide", r));
177
177
  };
178
178
  window.addEventListener("pagehide", r);
179
179
  }));
180
- const t = await z, e = Ms();
180
+ const t = await K, e = Ms();
181
181
  le.add(e);
182
182
  let s = !1;
183
183
  return {
@@ -194,7 +194,7 @@ function Ms() {
194
194
  t += 1;
195
195
  return t;
196
196
  }
197
- function Pt() {
197
+ function Ut() {
198
198
  return {
199
199
  storage: As(),
200
200
  channel: Rs(),
@@ -236,7 +236,7 @@ function Rs() {
236
236
  }
237
237
  function Es() {
238
238
  const t = /* @__PURE__ */ new Set(), e = (s) => {
239
- if (s.key !== Ce || !s.newValue)
239
+ if (s.key !== be || !s.newValue)
240
240
  return;
241
241
  const n = JSON.parse(s.newValue);
242
242
  for (const r of t)
@@ -245,9 +245,9 @@ function Es() {
245
245
  return window.addEventListener("storage", e), {
246
246
  postMessage: (s) => {
247
247
  window.localStorage.setItem(
248
- Ce,
248
+ be,
249
249
  JSON.stringify({ ...s, eventId: crypto.randomUUID() })
250
- ), window.localStorage.removeItem(Ce);
250
+ ), window.localStorage.removeItem(be);
251
251
  },
252
252
  subscribe: (s) => (t.add(s), () => t.delete(s)),
253
253
  close: () => {
@@ -256,7 +256,7 @@ function Es() {
256
256
  };
257
257
  }
258
258
  const Dt = "schedule_follow_up";
259
- function bs(t) {
259
+ function Cs(t) {
260
260
  let e = t;
261
261
  if (typeof e == "string")
262
262
  try {
@@ -269,8 +269,8 @@ function bs(t) {
269
269
  const s = e;
270
270
  return s.ok !== !0 || s.toolName !== Dt || typeof s.dueAt != "string" || Number.isNaN(Date.parse(s.dueAt)) ? null : s.dueAt;
271
271
  }
272
- const Cs = globalThis.fetch.bind(globalThis), Le = '.pluno-pa-widget-host[data-pluno-product-agent-ui="widget"]', _s = '.pluno-pa-widget[data-pluno-product-agent-ui-root="widget"]', ks = ".pluno-pa-widget__panel", Us = ".pluno-pa-widget__timeline", ut = `${Le}[data-pluno-sdk-preview-channel]`;
273
- let Ps = 0;
272
+ const bs = globalThis.fetch.bind(globalThis), Le = '.pluno-pa-widget-host[data-pluno-product-agent-ui="widget"]', _s = '.pluno-pa-widget[data-pluno-product-agent-ui-root="widget"]', ks = ".pluno-pa-widget__panel", Ps = ".pluno-pa-widget__timeline", ut = `${Le}[data-pluno-sdk-preview-channel]`;
273
+ let Us = 0;
274
274
  function dt(t) {
275
275
  const e = {};
276
276
  for (const o of [
@@ -278,6 +278,7 @@ function dt(t) {
278
278
  "requestId",
279
279
  "clientMessageId",
280
280
  "sessionId",
281
+ "warmupId",
281
282
  "runId",
282
283
  "itemId",
283
284
  "reason",
@@ -320,31 +321,31 @@ function ke(t, e, s) {
320
321
  source: "web_sdk",
321
322
  category: t,
322
323
  name: e,
323
- sequence: ++Ps,
324
+ sequence: ++Us,
324
325
  wallTime: (/* @__PURE__ */ new Date()).toISOString(),
325
326
  monotonicMs: performance.now(),
326
327
  data: s
327
328
  };
328
329
  window.dispatchEvent(new CustomEvent("product-agent:trace", { detail: r }));
329
330
  }
330
- const Ds = "https://app.pluno.ai", vs = "gpt-5.6-terra", Os = 2e4, Ns = 1e4, xs = 1e4, Ls = 1e4, qs = 1e4, Bs = 1e3, ht = 3e4, pt = 0.2, gt = 6e4, Hs = 15e3, K = 8, Ws = "Pluno could not finish this message. Try it again.", js = "Browser connection was interrupted.", ft = 15e3, Fs = "Pluno could not send this message. Try it again.", mt = 2e3, $s = 1e3, zs = 100, yt = 8e3, It = 3, Ks = [300, 1e3], vt = 50 * 1024 * 1024, Gs = /* @__PURE__ */ new Set([
331
+ const Ds = "https://app.pluno.ai", vs = "gpt-5.6-terra", Ns = 2e4, Os = 1e4, xs = 1e4, Ls = 1e4, qs = 1e4, Bs = 3e3, Ws = 3e4, Hs = 1e3, pt = 3e4, ht = 0.2, gt = 6e4, $s = 15e3, G = 8, js = "Pluno could not finish this message. Try it again.", Fs = "Browser connection was interrupted.", ft = 15e3, zs = "Pluno could not send this message. Try it again.", mt = 2e3, Ks = 1e3, Gs = 100, yt = 8e3, It = 3, Xs = [300, 1e3], vt = 50 * 1024 * 1024, Vs = /* @__PURE__ */ new Set([
331
332
  ".jpeg:image/jpeg",
332
333
  ".jpg:image/jpeg",
333
334
  ".pdf:application/pdf",
334
335
  ".png:image/png",
335
336
  ".webp:image/webp"
336
- ]), oi = ".pdf,.png,.jpg,.jpeg,.webp", Ve = 64e3, Ue = 4e3, Je = 30, Xs = 2e3, Vs = 1e3, Ot = "Image is too large for model vision input.", Js = 100, Nt = "pluno.productAgent.state.", qe = "pluno.productAgent.pendingEvents.", pe = "pluno.productAgent.activeToolCalls.", Ys = 100;
337
- function G(t, e = 0) {
337
+ ]), li = ".pdf,.png,.jpg,.jpeg,.webp", Ve = 64e3, Pe = 4e3, Je = 30, Js = 2e3, Ys = 1e3, Nt = "Image is too large for model vision input.", Qs = 100, Ot = "pluno.productAgent.state.", qe = "pluno.productAgent.pendingEvents.", he = "pluno.productAgent.activeToolCalls.", Zs = 100;
338
+ function X(t, e = 0) {
338
339
  const s = t === 0 ? 0 : Math.min(3e4, 1e3 * 2 ** (t - 1));
339
340
  return Math.max(e, s);
340
341
  }
341
342
  const ce = /* @__PURE__ */ new Set();
342
343
  let ne = null;
343
- function Qs(t, e = Math.random) {
344
- const s = Math.min(ht, Bs * 2 ** t), n = 1 - pt + e() * pt * 2;
345
- return Math.min(ht, Math.round(s * n));
344
+ function en(t, e = Math.random) {
345
+ const s = Math.min(pt, Hs * 2 ** t), n = 1 - ht + e() * ht * 2;
346
+ return Math.min(pt, Math.round(s * n));
346
347
  }
347
- function Zs(t, e, s) {
348
+ function tn(t, e, s) {
348
349
  return new Promise((n, r) => {
349
350
  const i = setTimeout(() => r(new Error(s)), e);
350
351
  t.then(
@@ -361,9 +362,9 @@ class xt {
361
362
  constructor(e, s) {
362
363
  this.options = e, this.transportIdentity = s, this.state = {
363
364
  ...this.state,
364
- starterPrompts: On(e.initialStarterPrompts)
365
+ starterPrompts: xn(e.initialStarterPrompts)
365
366
  };
366
- const n = e.restorePersistedState === !1 ? null : Rr(e.clientId, e.expectedPersistedSessionId);
367
+ const n = e.restorePersistedState === !1 ? null : Cr(e.clientId, e.expectedPersistedSessionId);
367
368
  n && (this.state = {
368
369
  ...this.state,
369
370
  ...n,
@@ -378,14 +379,14 @@ class xt {
378
379
  isThinking: !1,
379
380
  isRetrying: !1,
380
381
  lastError: null
381
- }), this.queuedClientEvents = Pr(
382
- br(e.clientId),
383
- _r(e.clientId)
382
+ }), this.queuedClientEvents = vr(
383
+ _r(e.clientId),
384
+ Pr(e.clientId)
384
385
  );
385
386
  const r = [...this.queuedClientEvents].reverse().find(
386
387
  (i) => i.type === "chat.user_message" && typeof i.clientMessageId == "string"
387
388
  );
388
- r?.clientMessageId && (this.pendingClientMessageId = r.clientMessageId, this.pendingUserMessageEvent = r, this.state.pendingMessageStatus = "reconnecting"), L(e.clientId, this.queuedClientEvents);
389
+ r?.clientMessageId && (this.pendingClientMessageId = r.clientMessageId, this.pendingUserMessageEvent = r, this.state.pendingMessageStatus = "reconnecting"), q(e.clientId, this.queuedClientEvents);
389
390
  }
390
391
  options;
391
392
  listeners = {};
@@ -403,13 +404,18 @@ class xt {
403
404
  networkBatchTimer = null;
404
405
  queuedNetworkEvents = [];
405
406
  queuedClientEvents = [];
406
- pendingWarmupEvent = null;
407
+ pendingPassiveWarmupEvent = null;
408
+ pendingComposerWarmup = null;
409
+ activeComposerWarmupId = null;
410
+ activeComposerWarmupScope = null;
411
+ pendingWarmupAckTimer = null;
407
412
  pendingSessionHistoryRequests = /* @__PURE__ */ new Map();
408
413
  pendingSessionPinRequests = /* @__PURE__ */ new Map();
409
414
  pendingSessionRenameRequests = /* @__PURE__ */ new Map();
410
415
  transportIdentity;
411
416
  retryAttemptsByClientMessageId = {};
412
417
  retryTimersByClientMessageId = {};
418
+ reportedHealthSignalKeys = /* @__PURE__ */ new Set();
413
419
  clientMessageIdsByUserMessageItemId = /* @__PURE__ */ new Map();
414
420
  backgroundSessionIds = /* @__PURE__ */ new Set();
415
421
  backgroundClientMessageIds = /* @__PURE__ */ new Set();
@@ -470,11 +476,11 @@ class xt {
470
476
  static async init(e) {
471
477
  const s = await Ss(), n = new xt({
472
478
  ...e,
473
- backendUrl: Tn(e.backendUrl ?? Ds),
474
- clientId: e.clientId ?? Bn(),
479
+ backendUrl: Sn(e.backendUrl ?? Ds),
480
+ clientId: e.clientId ?? Hn(),
475
481
  model: e.model ?? vs,
476
482
  productVariant: e.productVariant ?? "customer_embedded",
477
- entrySurface: wn(e.entrySurface)
483
+ entrySurface: Mn(e.entrySurface)
478
484
  }, s);
479
485
  try {
480
486
  us().catch((r) => {
@@ -508,11 +514,11 @@ class xt {
508
514
  this.state.status === "reconnecting" ? { status: "reconnecting" } : { status: "connecting", lastError: null }
509
515
  );
510
516
  try {
511
- if (this.token = this.options.token ?? (this.options.tokenProvider ? await Zs(this.options.tokenProvider(), xs, "Pluno token provider timed out") : null), e !== this.connectionAttemptId || this.state.status === "closed")
517
+ if (this.token = this.options.token ?? (this.options.tokenProvider ? await tn(this.options.tokenProvider(), xs, "Pluno token provider timed out") : null), e !== this.connectionAttemptId || this.state.status === "closed")
512
518
  return;
513
519
  if (!this.token && !this.options.webSocketFactory)
514
520
  throw new Error("Pluno requires a token or tokenProvider");
515
- const s = An(this.options.backendUrl), n = this.options.webSocketFactory?.(s) ?? new WebSocket(s);
521
+ const s = En(this.options.backendUrl), n = this.options.webSocketFactory?.(s) ?? new WebSocket(s);
516
522
  this.socket = n, this.socketConnectTimer = window.setTimeout(() => {
517
523
  this.socket === n && n.readyState === WebSocket.CONNECTING && (M("web-sdk.agent", "Pluno socket opening timed out; reconnecting"), this.replaceTimedOutSocket(n));
518
524
  }, Ls), n.addEventListener("open", () => {
@@ -529,14 +535,14 @@ class xt {
529
535
  this.socket === n && (M("web-sdk.agent", "Pluno socket authentication timed out; reconnecting"), this.replaceTimedOutSocket(n));
530
536
  }, qs));
531
537
  }), n.addEventListener("message", (r) => {
532
- this.socket === n && this.handleServerEvent(Dn(r.data));
538
+ this.socket === n && this.handleServerEvent(Nn(r.data));
533
539
  }), n.addEventListener("sendfailure", (r) => {
534
540
  if (this.socket !== n)
535
541
  return;
536
- const i = vn(r?.detail?.data);
542
+ const i = On(r?.detail?.data);
537
543
  i?.type === "chat.user_message" && i.clientMessageId === this.pendingClientMessageId && !this.queuedClientEvents.some(
538
544
  (o) => o.type === "chat.user_message" && o.clientMessageId === i.clientMessageId
539
- ) && (this.queuedClientEvents.push(i), L(this.options.clientId, this.queuedClientEvents), this.setState({ pendingMessageStatus: "reconnecting" })), this.clearSocketPhaseTimers(), this.stopHeartbeat(), this.socket = null, this.setReconnectingState(), this.scheduleReconnect(), n.readyState !== WebSocket.CLOSED && n.readyState !== WebSocket.CLOSING && n.close();
545
+ ) && (this.queuedClientEvents.push(i), q(this.options.clientId, this.queuedClientEvents), this.setState({ pendingMessageStatus: "reconnecting" })), this.clearSocketPhaseTimers(), this.stopHeartbeat(), this.socket = null, this.setReconnectingState(), this.scheduleReconnect(), n.readyState !== WebSocket.CLOSED && n.readyState !== WebSocket.CLOSING && n.close();
540
546
  }), n.addEventListener("close", (r) => {
541
547
  this.socket === n && (this.clearSocketPhaseTimers(), this.stopHeartbeat(), this.socket = null, this.state.status !== "closed" && (this.rememberBrowserConnectionInterruptionForActiveRun(), M("web-sdk.agent", "Pluno socket closed; scheduling reconnect", {
542
548
  code: typeof r?.code == "number" ? r.code : null,
@@ -566,22 +572,29 @@ class xt {
566
572
  }
567
573
  }
568
574
  disconnect() {
569
- this.connectionAttemptId += 1, this.setState({ status: "closed", pendingMessageStatus: null, isThinking: !1, isRetrying: !1 }), this.clearSocketPhaseTimers(), this.stopHeartbeat(), this.clearStarterPromptUrlRefreshTimer(), this.clearRetryTimers(), this.clearThinkingWatchdog(), this.clearPendingDeliveryTimers(), this.pendingClientMessageId = null, this.pendingUserMessageEvent = null, this.failedUserMessageEvent = null, this.rejectPendingSessionHistoryRequests("Pluno disconnected."), this.rejectPendingSessionMutationRequests(this.pendingSessionPinRequests, "Pluno disconnected."), this.rejectPendingSessionMutationRequests(this.pendingSessionRenameRequests, "Pluno disconnected."), this.reconnectTimer !== null && (window.clearTimeout(this.reconnectTimer), this.reconnectTimer = null), this.queuedClientEvents = [], this.pendingWarmupEvent = null, this.nonTranscriptToolCallIds.clear(), this.socket?.close(), this.socket = null;
575
+ this.connectionAttemptId += 1, this.setState({ status: "closed", pendingMessageStatus: null, isThinking: !1, isRetrying: !1 }), this.clearSocketPhaseTimers(), this.stopHeartbeat(), this.clearStarterPromptUrlRefreshTimer(), this.clearRetryTimers(), this.clearThinkingWatchdog(), this.clearPendingDeliveryTimers(), this.pendingClientMessageId = null, this.pendingUserMessageEvent = null, this.failedUserMessageEvent = null, this.rejectPendingSessionHistoryRequests("Pluno disconnected."), this.rejectPendingSessionMutationRequests(this.pendingSessionPinRequests, "Pluno disconnected."), this.rejectPendingSessionMutationRequests(this.pendingSessionRenameRequests, "Pluno disconnected."), this.reconnectTimer !== null && (window.clearTimeout(this.reconnectTimer), this.reconnectTimer = null), this.queuedClientEvents = [], this.clearPendingWarmupAckTimer(), this.pendingPassiveWarmupEvent = null, this.pendingComposerWarmup = null, this.activeComposerWarmupId = null, this.activeComposerWarmupScope = null, this.nonTranscriptToolCallIds.clear(), this.socket?.close(), this.socket = null;
570
576
  }
571
577
  destroy() {
572
- this.disconnect(), this.locationChangeCleanup?.(), this.locationChangeCleanup = null, this.cleanupSessionBrowserApis(), this.pageLifecycleCleanup?.(), this.pageLifecycleCleanup = null, this.activeBrowserToolCalls.clear(), Dr(this.options.clientId), this.transportIdentity.release(), this.networkCaptureCleanup?.(), this.networkCaptureCleanup = null, this.networkBatchTimer !== null && (window.clearTimeout(this.networkBatchTimer), this.networkBatchTimer = null), this.queuedNetworkEvents = [];
578
+ this.disconnect(), this.locationChangeCleanup?.(), this.locationChangeCleanup = null, this.cleanupSessionBrowserApis(), this.pageLifecycleCleanup?.(), this.pageLifecycleCleanup = null, this.activeBrowserToolCalls.clear(), Nr(this.options.clientId), this.transportIdentity.release(), this.networkCaptureCleanup?.(), this.networkCaptureCleanup = null, this.networkBatchTimer !== null && (window.clearTimeout(this.networkBatchTimer), this.networkBatchTimer = null), this.queuedNetworkEvents = [];
573
579
  for (const e of Object.values(this.listeners))
574
580
  e?.clear();
575
581
  }
576
582
  warmup(e = "panel_open") {
577
- const s = {
583
+ const s = C(), n = `${this.state.sessionId ?? "draft"}:${s.url}`, r = e === "composer_input" && this.pendingComposerWarmup?.scope === n ? this.pendingComposerWarmup : null, i = {
578
584
  type: "runtime.warmup",
579
585
  reason: e,
586
+ ...e === "composer_input" ? { warmupId: r?.event.warmupId ?? L() } : {},
580
587
  entrySurface: this.options.entrySurface,
581
588
  sessionId: this.state.sessionId ?? void 0,
582
- page: C()
589
+ page: s
583
590
  };
584
- this.sendNow(s) || (this.pendingWarmupEvent = s);
591
+ if (e === "composer_input") {
592
+ if (this.options.productVariant === "customer_embedded") {
593
+ this.sendNow(i) || (this.pendingPassiveWarmupEvent = i);
594
+ return;
595
+ }
596
+ r || (this.clearPendingComposerWarmup(), this.pendingComposerWarmup = { event: i, scope: n, retryAttempt: 0, acknowledged: !1 }, this.activeComposerWarmupId = i.warmupId ?? null, this.activeComposerWarmupScope = n), this.flushPendingComposerWarmup();
597
+ } else this.sendNow(i) || (this.pendingPassiveWarmupEvent = i);
585
598
  }
586
599
  async sendMessage(e, s = {}) {
587
600
  const n = e.trim(), r = s.attachments ?? [];
@@ -595,13 +608,13 @@ class xt {
595
608
  return null;
596
609
  if (this.pendingClientMessageId)
597
610
  throw new Error("Wait for the current message to finish sending before sending another.");
598
- const o = C(), a = s.clientMessageId ?? X(), l = {
611
+ const o = C(), a = s.clientMessageId ?? L(), l = {
599
612
  id: `local-${a}`,
600
613
  role: "user",
601
614
  content: n,
602
615
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
603
616
  ...r.length > 0 ? { attachments: r } : {}
604
- }, c = this.state.messages.some((m) => m.id === l.id || m.clientMessageId === a), h = this.state.isThinking, p = this.state.pendingMessageStatus, w = this.state.messages, y = c ? this.state.messages : [...this.state.messages, l], u = {
617
+ }, c = this.state.messages.some((m) => m.id === l.id || m.clientMessageId === a), p = this.state.isThinking, h = this.state.pendingMessageStatus, w = this.state.messages, y = c ? this.state.messages : [...this.state.messages, l], u = {
605
618
  assistantDraft: this.state.assistantDraft,
606
619
  assistantDraftItemId: this.state.assistantDraftItemId,
607
620
  assistantDraftPhase: this.state.assistantDraftPhase,
@@ -611,7 +624,7 @@ class xt {
611
624
  };
612
625
  this.setState({
613
626
  messages: y,
614
- ...h ? {} : {
627
+ ...p ? {} : {
615
628
  assistantDraft: "",
616
629
  assistantDraftItemId: null,
617
630
  assistantDraftPhase: null,
@@ -619,7 +632,7 @@ class xt {
619
632
  assistantDraftRunId: null
620
633
  },
621
634
  pendingMessageStatus: "sending",
622
- isThinking: h,
635
+ isThinking: p,
623
636
  isRetrying: !1,
624
637
  lastError: null
625
638
  }), c || this.emit("message", l);
@@ -639,8 +652,8 @@ class xt {
639
652
  } catch (m) {
640
653
  throw this.setState({
641
654
  ...c ? {} : { messages: w },
642
- ...h ? {} : { ...u, isThinking: !1 },
643
- pendingMessageStatus: p
655
+ ...p ? {} : { ...u, isThinking: !1 },
656
+ pendingMessageStatus: h
644
657
  }), m;
645
658
  }
646
659
  this.retryableClientMessageId = null;
@@ -649,7 +662,7 @@ class xt {
649
662
  sessionId: this.state.sessionId ?? void 0,
650
663
  clientMessageId: a,
651
664
  initiatedBy: s.initiatedBy,
652
- invocation: Sn(s.invocation ?? s.initiatedBy),
665
+ invocation: An(s.invocation ?? s.initiatedBy),
653
666
  entrySurface: this.options.entrySurface,
654
667
  content: n,
655
668
  pageContent: d && Ye() || void 0,
@@ -676,8 +689,8 @@ class xt {
676
689
  return e ? (this.retryAttemptsByClientMessageId[s] = 0, this.retryableClientMessageId = null, this.activeClientMessageId = s, this.browserConnectionInterruptedClientMessageIds.delete(s), this.latestRecoverableClientMessageId = s, this.setState({ status: "connected", isThinking: !0, isRetrying: !0, lastError: null, lastErrorCode: null }), this.markThinkingProgress(), this.send({ type: "chat.retry_last_user_message", sessionId: e, clientMessageId: s, automatic: !1 }), !0) : !1;
677
690
  }
678
691
  createLocalAttachment(e) {
679
- this.options.productVariant === "customer_embedded" && vr(e);
680
- const s = X(), n = {
692
+ this.options.productVariant === "customer_embedded" && Or(e);
693
+ const s = L(), n = {
681
694
  id: s,
682
695
  name: e.name || "attachment",
683
696
  mimeType: ze(e),
@@ -782,7 +795,7 @@ class xt {
782
795
  const n = await this.fetchEmbedAttachmentUpload(e);
783
796
  if (n.ok)
784
797
  return await n.json();
785
- if (Jr(n.status) && this.options.tokenProvider && !s) {
798
+ if (Qr(n.status) && this.options.tokenProvider && !s) {
786
799
  s = !0;
787
800
  const r = await this.fetchEmbedAttachmentUpload(e);
788
801
  if (r.ok)
@@ -807,7 +820,7 @@ class xt {
807
820
  if (!this.state.sessionId)
808
821
  return;
809
822
  this.send({ type: "run.stop", sessionId: this.state.sessionId, reason: "user_requested" });
810
- const e = fr(
823
+ const e = yr(
811
824
  this.state.messages,
812
825
  this.state.assistantDraftRespondsToUserMessageId,
813
826
  this.state.assistantDraftRunId,
@@ -824,10 +837,11 @@ class xt {
824
837
  }), this.clearThinkingWatchdog();
825
838
  }
826
839
  startNewSession(e = {}) {
827
- const s = e.notifyTransport !== !1;
828
- !this.options.keepRunsActiveOnSessionNavigation && s && this.state.sessionId && (this.state.isThinking || this.state.pendingMessageStatus !== null) && this.send({ type: "run.stop", sessionId: this.state.sessionId, reason: "new_chat" }), this.rememberCurrentRunAsBackground(), this.cleanupSessionBrowserApis(), this.queuedClientEvents = this.queuedClientEvents.filter((n) => n.type !== "chat.user_message"), this.clearThinkingWatchdog(), this.clearPendingDeliveryTimers(), this.pendingClientMessageId = null, this.pendingUserMessageEvent = null, this.failedUserMessageEvent = null, this.retryableClientMessageId = null, this.lastUserMessagePageUrl = null, this.retryAttemptsByClientMessageId = {}, this.thinkingWatchdogResyncAttemptsByClientMessageId = {}, this.nonTranscriptToolCallIds.clear(), s && this.send({
840
+ const s = e.notifyTransport !== !1, n = this.activeComposerWarmupId;
841
+ !this.options.keepRunsActiveOnSessionNavigation && s && this.state.sessionId && (this.state.isThinking || this.state.pendingMessageStatus !== null) && this.send({ type: "run.stop", sessionId: this.state.sessionId, reason: "new_chat" }), this.rememberCurrentRunAsBackground(), this.clearPendingComposerWarmup(), this.cleanupSessionBrowserApis(), this.queuedClientEvents = this.queuedClientEvents.filter((r) => r.type !== "chat.user_message"), this.clearThinkingWatchdog(), this.clearPendingDeliveryTimers(), this.pendingClientMessageId = null, this.pendingUserMessageEvent = null, this.failedUserMessageEvent = null, this.retryableClientMessageId = null, this.lastUserMessagePageUrl = null, this.retryAttemptsByClientMessageId = {}, this.thinkingWatchdogResyncAttemptsByClientMessageId = {}, this.nonTranscriptToolCallIds.clear(), s && this.send({
829
842
  type: "session.reset",
830
843
  sessionId: this.state.sessionId ?? void 0,
844
+ warmupId: n ?? void 0,
831
845
  page: C()
832
846
  }), this.setState({
833
847
  sessionId: null,
@@ -845,7 +859,7 @@ class xt {
845
859
  });
846
860
  }
847
861
  listSessions(e = {}) {
848
- const s = X(), n = new Promise((i, o) => {
862
+ const s = L(), n = new Promise((i, o) => {
849
863
  const a = window.setTimeout(() => {
850
864
  this.pendingSessionHistoryRequests.delete(s), o(new Error("Session history did not respond in time"));
851
865
  }, yt);
@@ -867,19 +881,24 @@ class xt {
867
881
  setSessionPinned(e, s) {
868
882
  return this.sendSessionMutation(
869
883
  this.pendingSessionPinRequests,
870
- { type: "session.pin", requestId: X(), sessionId: e, pinned: s },
884
+ { type: "session.pin", requestId: L(), sessionId: e, pinned: s },
871
885
  "Session pin did not respond in time"
872
886
  );
873
887
  }
874
888
  renameSession(e, s) {
875
889
  return this.sendSessionMutation(
876
890
  this.pendingSessionRenameRequests,
877
- { type: "session.rename", requestId: X(), sessionId: e, title: s },
891
+ { type: "session.rename", requestId: L(), sessionId: e, title: s },
878
892
  "Session rename did not respond in time"
879
893
  );
880
894
  }
881
895
  loadSession(e) {
882
- !this.options.keepRunsActiveOnSessionNavigation && this.state.sessionId && (this.state.isThinking || this.state.pendingMessageStatus !== null) && this.send({ type: "run.stop", sessionId: this.state.sessionId, reason: "session_switch" }), this.options.keepRunsActiveOnSessionNavigation && (this.rememberCurrentRunAsBackground(), this.backgroundSessionIds.delete(e), this.deferredSessionUpdatedSessionIds.delete(e)), this.clearThinkingWatchdog(), this.clearPendingDeliveryTimers(), this.pendingClientMessageId = null, this.pendingUserMessageEvent = null, this.failedUserMessageEvent = null, this.lastUserMessagePageUrl = null, this.setState({
896
+ const s = this.activeComposerWarmupId;
897
+ !this.options.keepRunsActiveOnSessionNavigation && this.state.sessionId && (this.state.isThinking || this.state.pendingMessageStatus !== null) && this.send({ type: "run.stop", sessionId: this.state.sessionId, reason: "session_switch" }), this.options.keepRunsActiveOnSessionNavigation && (this.rememberCurrentRunAsBackground(), this.backgroundSessionIds.delete(e), this.deferredSessionUpdatedSessionIds.delete(e)), this.clearPendingComposerWarmup(), s && this.send({
898
+ type: "session.reset",
899
+ warmupId: s,
900
+ page: C()
901
+ }), this.clearThinkingWatchdog(), this.clearPendingDeliveryTimers(), this.pendingClientMessageId = null, this.pendingUserMessageEvent = null, this.failedUserMessageEvent = null, this.lastUserMessagePageUrl = null, this.setState({
883
902
  sessionId: e,
884
903
  assistantDraft: "",
885
904
  assistantDraftItemId: null,
@@ -900,7 +919,7 @@ class xt {
900
919
  send(e) {
901
920
  this.sendNow(k(e)) || (e.type === "chat.user_message" && typeof e.clientMessageId == "string" && this.queuedClientEvents.some(
902
921
  (r) => r.type === "chat.user_message" && r.clientMessageId === e.clientMessageId
903
- ) || this.queuedClientEvents.push(e), L(this.options.clientId, this.queuedClientEvents), this.setState({
922
+ ) || this.queuedClientEvents.push(e), q(this.options.clientId, this.queuedClientEvents), this.setState({
904
923
  status: "reconnecting",
905
924
  ...e.type === "chat.user_message" && e.clientMessageId === this.pendingClientMessageId ? { pendingMessageStatus: "reconnecting" } : {}
906
925
  }), this.scheduleReconnect());
@@ -926,33 +945,41 @@ class xt {
926
945
  }
927
946
  }
928
947
  reportHealthSignal(e, s = {}) {
929
- if (!(!this.socket || this.socket.readyState !== WebSocket.OPEN))
930
- try {
931
- this.socket.send(JSON.stringify({
932
- type: "runtime.health",
933
- signal: {
934
- id: crypto.randomUUID(),
935
- name: e,
936
- occurredAt: (/* @__PURE__ */ new Date()).toISOString(),
937
- source: "web_sdk",
938
- entrySurface: this.options.entrySurface,
939
- ...this.state.sessionId ? { sessionId: this.state.sessionId } : {},
940
- ...this.activeResponseRunId ? { runId: this.activeResponseRunId } : {},
941
- ...s
942
- }
943
- }));
944
- } catch (n) {
945
- M("web-sdk.agent", "Pluno health signal send failed", {
948
+ if (!this.socket || this.socket.readyState !== WebSocket.OPEN)
949
+ return;
950
+ const n = s.clientMessageId ?? this.activeResponseRunId;
951
+ if (n) {
952
+ const r = `${e}:${n}`;
953
+ if (this.reportedHealthSignalKeys.has(r))
954
+ return;
955
+ this.reportedHealthSignalKeys.add(r);
956
+ }
957
+ try {
958
+ this.socket.send(JSON.stringify({
959
+ type: "runtime.health",
960
+ signal: {
961
+ id: crypto.randomUUID(),
946
962
  name: e,
947
- message: n instanceof Error ? n.message : String(n)
948
- });
949
- }
963
+ occurredAt: (/* @__PURE__ */ new Date()).toISOString(),
964
+ source: "web_sdk",
965
+ entrySurface: this.options.entrySurface,
966
+ ...this.state.sessionId ? { sessionId: this.state.sessionId } : {},
967
+ ...this.activeResponseRunId ? { runId: this.activeResponseRunId } : {},
968
+ ...s
969
+ }
970
+ }));
971
+ } catch (r) {
972
+ M("web-sdk.agent", "Pluno health signal send failed", {
973
+ name: e,
974
+ message: r instanceof Error ? r.message : String(r)
975
+ });
976
+ }
950
977
  }
951
978
  requestTransientStarterPrompts() {
952
979
  if (this.state.starterPromptsLoading || this.transientStarterPromptsRequestInFlight || this.transientStarterPromptsRequestAttempted)
953
980
  return;
954
981
  this.transientStarterPromptsRequestInFlight = !0, this.transientStarterPromptsRequestAttempted = !0, this.setState({ starterPromptsLoading: !0 });
955
- const e = Rn();
982
+ const e = Cn();
956
983
  this.sendNow(
957
984
  k({
958
985
  type: "starter_prompts.page_context",
@@ -963,13 +990,13 @@ class xt {
963
990
  ) || (this.transientStarterPromptsRequestInFlight = !1, this.transientStarterPromptsRequestAttempted = !1, this.setState({ starterPromptsLoading: !1 }));
964
991
  }
965
992
  startStarterPromptUrlWatcher() {
966
- this.locationChangeCleanup || (this.locationChangeCleanup = En(() => this.handleStarterPromptUrlChange()));
993
+ this.locationChangeCleanup || (this.locationChangeCleanup = bn(() => this.handleStarterPromptUrlChange()));
967
994
  }
968
995
  handleStarterPromptUrlChange() {
969
996
  const e = location.href;
970
- e !== this.lastStarterPromptPageUrl && (this.lastStarterPromptPageUrl = e, this.clearStarterPromptUrlRefreshTimer(), this.starterPromptUrlRefreshTimer = window.setTimeout(() => {
997
+ e !== this.lastStarterPromptPageUrl && (this.activeComposerWarmupScope && !this.activeComposerWarmupScope.endsWith(`:${e}`) && this.clearPendingComposerWarmup(), this.lastStarterPromptPageUrl = e, this.clearStarterPromptUrlRefreshTimer(), this.starterPromptUrlRefreshTimer = window.setTimeout(() => {
971
998
  this.starterPromptUrlRefreshTimer = null, this.refreshStarterPromptsForCurrentUrl();
972
- }, Ys));
999
+ }, Zs));
973
1000
  }
974
1001
  refreshStarterPromptsForCurrentUrl() {
975
1002
  this.socket?.readyState !== WebSocket.OPEN || this.state.status === "closed" || (this.setState({ starterPromptsLoading: this.state.messages.length === 0 }), this.sendNow({
@@ -984,367 +1011,393 @@ class xt {
984
1011
  if (this.socket?.readyState !== WebSocket.OPEN || this.queuedClientEvents.length === 0)
985
1012
  return;
986
1013
  const e = this.queuedClientEvents.splice(0, this.queuedClientEvents.length);
987
- L(this.options.clientId, this.queuedClientEvents);
1014
+ q(this.options.clientId, this.queuedClientEvents);
988
1015
  for (let s = 0; s < e.length; s += 1) {
989
1016
  const n = e[s];
990
1017
  if (!this.sendNow(k(n))) {
991
- this.queuedClientEvents.unshift(n, ...e.slice(s + 1)), L(this.options.clientId, this.queuedClientEvents);
1018
+ this.queuedClientEvents.unshift(n, ...e.slice(s + 1)), q(this.options.clientId, this.queuedClientEvents);
992
1019
  return;
993
1020
  }
994
- L(this.options.clientId, this.queuedClientEvents);
1021
+ q(this.options.clientId, this.queuedClientEvents);
995
1022
  }
996
1023
  }
997
- flushPendingWarmupEvent() {
998
- !this.pendingWarmupEvent || !this.sendNow(this.pendingWarmupEvent) || (this.pendingWarmupEvent = null);
1024
+ flushPendingPassiveWarmup() {
1025
+ !this.pendingPassiveWarmupEvent || !this.sendNow(this.pendingPassiveWarmupEvent) || (this.pendingPassiveWarmupEvent = null);
999
1026
  }
1000
- handleServerEvent(e) {
1001
- if (ke("server_event", e.type, dt(e)), e.type === "run.ack") {
1002
- const s = De(e), n = typeof e.clientMessageId == "string" ? e.clientMessageId : null;
1003
- s && n && this.backgroundClientMessageIds.delete(n) ? (this.backgroundSessionIds.add(s), this.deferredSessionUpdatedSessionIds.delete(s)) : s && (n === this.activeClientMessageId || n === this.pendingClientMessageId) && this.deferredSessionUpdatedSessionIds.delete(s) && this.state.sessionId === null && this.setState({ sessionId: s }), this.handleRunAck(e);
1027
+ flushPendingComposerWarmup() {
1028
+ const e = this.pendingComposerWarmup;
1029
+ if (!e || e.acknowledged || !this.sendNow(e.event))
1004
1030
  return;
1005
- }
1006
- if (e.type === "session.updated" && this.options.keepRunsActiveOnSessionNavigation && this.state.sessionId === null && this.backgroundClientMessageIds.size > 0) {
1007
- const s = De(e);
1008
- if (s) {
1009
- this.deferredSessionUpdatedSessionIds.add(s);
1010
- return;
1011
- }
1012
- }
1013
- if (!this.shouldIgnoreBackgroundSessionEvent(e)) {
1014
- if (e.type === "run.steered") {
1015
- this.handleRunSteered(e);
1016
- return;
1017
- }
1018
- if (e.type === "runtime.pong") {
1019
- this.clearHeartbeatAckTimer();
1031
+ this.clearPendingWarmupAckTimer();
1032
+ const s = Math.min(
1033
+ Bs * 2 ** e.retryAttempt,
1034
+ Ws
1035
+ );
1036
+ e.retryAttempt += 1, this.pendingWarmupAckTimer = window.setTimeout(() => {
1037
+ this.pendingWarmupAckTimer = null, this.flushPendingComposerWarmup();
1038
+ }, s);
1039
+ }
1040
+ handleServerEvent(e) {
1041
+ if (ke("server_event", e.type, dt(e)), !(e.type === "session.updated" && typeof e.warmupId == "string" && e.warmupId !== this.activeComposerWarmupId)) {
1042
+ if (e.type === "runtime.warmup_ack" && typeof e.warmupId == "string" && e.warmupId === this.pendingComposerWarmup?.event.warmupId) {
1043
+ this.clearPendingWarmupAckTimer(), this.pendingComposerWarmup.acknowledged = !0;
1020
1044
  return;
1021
1045
  }
1022
- if (sn(e) && this.markThinkingProgress(), e.type === "auth.ok") {
1023
- this.clearSocketAuthTimer(), this.reconnectAttempts = 0, this.flushQueuedClientEvents(), this.pendingClientMessageId && (this.setState({ pendingMessageStatus: "sending" }), this.schedulePendingDeliveryAck(this.pendingClientMessageId)), this.flushPendingWarmupEvent(), this.startHeartbeat();
1024
- const s = Nn(e), n = Object.prototype.hasOwnProperty.call(e, "appearance");
1025
- M("web-sdk.agent", "Received auth.ok appearance", {
1026
- hasAppearance: n,
1027
- rawAppearance: e.appearance,
1028
- normalizedAppearance: s
1029
- }), this.runtimeHelperJavascript = xn(e.runtimeHelpers)?.javascript ?? null;
1030
- const r = Mt(e, "starterPrompts"), i = Object.prototype.hasOwnProperty.call(e, "starterPrompts"), o = e.starterPromptsLoading === !0, a = {
1031
- user: Hn(e.user),
1032
- status: "connected",
1033
- ...this.state.lastErrorCode === "connection_failed" ? { lastError: null, lastErrorCode: null } : {}
1034
- };
1035
- (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 && !re() && this.requestTransientStarterPrompts(), this.state.sessionId && this.send({
1036
- type: "page.upsert",
1037
- sessionId: this.state.sessionId,
1038
- page: C(),
1039
- model: this.options.model
1040
- });
1046
+ if (e.type === "run.ack") {
1047
+ const s = De(e), n = typeof e.clientMessageId == "string" ? e.clientMessageId : null;
1048
+ s && n && this.backgroundClientMessageIds.delete(n) ? (this.backgroundSessionIds.add(s), this.deferredSessionUpdatedSessionIds.delete(s)) : s && (n === this.activeClientMessageId || n === this.pendingClientMessageId) && this.deferredSessionUpdatedSessionIds.delete(s) && this.state.sessionId === null && this.setState({ sessionId: s }), this.handleRunAck(e);
1041
1049
  return;
1042
1050
  }
1043
- if (e.type === "starterPrompts.updated") {
1044
- this.transientStarterPromptsRequestInFlight = !1, this.transientStarterPromptsRequestAttempted = !0, this.setState({
1045
- starterPrompts: Mt(e, "starterPrompts"),
1046
- starterPromptsLoading: !1
1047
- });
1048
- return;
1051
+ if (e.type === "session.updated" && this.options.keepRunsActiveOnSessionNavigation && this.state.sessionId === null && this.backgroundClientMessageIds.size > 0) {
1052
+ const s = De(e);
1053
+ if (s) {
1054
+ this.deferredSessionUpdatedSessionIds.add(s);
1055
+ return;
1056
+ }
1049
1057
  }
1050
- if (e.type === "conversation.state") {
1051
- const s = Array.isArray(e.items) ? e.items : [], n = e.pendingMessageStatus === "sending" ? "sending" : e.pendingMessageStatus === "queued" ? "reconnecting" : null, r = typeof e.pendingClientMessageId == "string" ? e.pendingClientMessageId : null, i = e.isRetrying === !0;
1052
- n && r && (this.pendingClientMessageId = r);
1053
- const o = Xn(
1054
- e.assistantDraft
1055
- ), a = o !== void 0;
1056
- this.rememberUserMessageClientMessageIds(s);
1057
- const l = ur(s);
1058
- if (l) {
1059
- const f = dr(s, l);
1060
- this.retryAttemptsByClientMessageId[l] = Math.max(
1061
- this.retryAttemptsByClientMessageId[l] ?? 0,
1062
- f
1063
- );
1058
+ if (!this.shouldIgnoreBackgroundSessionEvent(e)) {
1059
+ if (e.type === "run.steered") {
1060
+ this.handleRunSteered(e);
1061
+ return;
1064
1062
  }
1065
- const c = s.filter((f) => {
1066
- const R = H(f);
1067
- return Rt(R) ? !1 : !R || !l || !We(R) ? !0 : Fe(s, R) !== l;
1068
- }), h = nr(
1069
- this.state.messages,
1070
- Wn(c, this.options.backendUrl)
1071
- ), p = At(h), w = !a && s.some(
1072
- (f) => Et(
1073
- H(f),
1074
- this.state.assistantDraft,
1075
- this.state.assistantDraftItemId,
1076
- this.state.assistantDraftRespondsToUserMessageId,
1077
- this.state.assistantDraftRunId
1078
- )
1079
- ), y = a ? o?.content ?? "" : this.state.assistantDraft, u = !!o?.content, d = p && (!y || w), g = ar(h), m = d && g;
1080
- if (!p && cr(this.state.messages, s))
1063
+ if (e.type === "runtime.pong") {
1064
+ this.clearHeartbeatAckTimer();
1081
1065
  return;
1082
- this.lastUserMessagePageUrl = lr(s);
1083
- const T = d ? null : je(s);
1084
- if (this.latestRecoverableClientMessageId = T, g && this.clearRetryTimers(), this.setState({
1085
- sessionId: E(e.session, "id") ?? this.state.sessionId,
1086
- messages: h,
1087
- ...n ? { pendingMessageStatus: n } : {},
1088
- isRetrying: i,
1089
- ...a ? {
1090
- assistantDraft: o?.content ?? "",
1091
- assistantDraftItemId: o?.itemId ?? null,
1092
- assistantDraftPhase: o?.phase ?? null,
1093
- assistantDraftRespondsToUserMessageId: o?.respondsToUserMessageId ?? null,
1094
- assistantDraftRunId: o?.runId ?? null
1095
- } : w ? {
1096
- assistantDraft: "",
1097
- assistantDraftItemId: null,
1098
- assistantDraftPhase: null,
1099
- assistantDraftRespondsToUserMessageId: null,
1100
- assistantDraftRunId: null
1101
- } : {},
1102
- ...u ? {
1103
- isThinking: !0,
1104
- lastError: null
1105
- } : d ? {
1106
- isThinking: !1,
1107
- ...m ? {
1108
- status: "connected",
1109
- lastError: null,
1110
- lastErrorCode: null,
1111
- lastErrorSecuritySettingsUrl: null
1112
- } : {}
1113
- } : T ? {
1114
- isThinking: !0,
1115
- lastError: null
1116
- } : {}
1117
- }), d)
1118
- this.retryableClientMessageId = null, this.clearThinkingWatchdog();
1119
- else if (u || T) {
1120
- if (T) {
1121
- this.activeClientMessageId = T;
1122
- const f = Y(s), R = f === null ? null : s[f];
1123
- this.activeResponseUserMessageId = E(R, "id");
1124
- }
1125
- this.markThinkingProgress();
1126
1066
  }
1127
- if (l) {
1128
- const f = E(e.session, "id") ?? this.state.sessionId;
1129
- f && this.retryAfterInterruptedRun(f, l);
1067
+ if (rn(e) && this.markThinkingProgress(), e.type === "auth.ok") {
1068
+ this.clearSocketAuthTimer(), this.reconnectAttempts = 0, this.flushPendingComposerWarmup(), this.flushQueuedClientEvents(), this.pendingClientMessageId && (this.setState({ pendingMessageStatus: "sending" }), this.schedulePendingDeliveryAck(this.pendingClientMessageId)), this.flushPendingPassiveWarmup(), this.startHeartbeat();
1069
+ const s = Ln(e), n = Object.prototype.hasOwnProperty.call(e, "appearance");
1070
+ M("web-sdk.agent", "Received auth.ok appearance", {
1071
+ hasAppearance: n,
1072
+ rawAppearance: e.appearance,
1073
+ normalizedAppearance: s
1074
+ }), this.runtimeHelperJavascript = qn(e.runtimeHelpers)?.javascript ?? null;
1075
+ const r = Mt(e, "starterPrompts"), i = Object.prototype.hasOwnProperty.call(e, "starterPrompts"), o = e.starterPromptsLoading === !0, a = {
1076
+ user: $n(e.user),
1077
+ status: "connected",
1078
+ ...this.state.lastErrorCode === "connection_failed" ? { lastError: null, lastErrorCode: null } : {}
1079
+ };
1080
+ (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 && !re() && this.requestTransientStarterPrompts(), this.state.sessionId && this.send({
1081
+ type: "page.upsert",
1082
+ sessionId: this.state.sessionId,
1083
+ page: C(),
1084
+ model: this.options.model
1085
+ });
1086
+ return;
1130
1087
  }
1131
- return;
1132
- }
1133
- if (e.type === "sessions.page") {
1134
- const s = typeof e.requestId == "string" ? e.requestId : null, n = s ? this.pendingSessionHistoryRequests.get(s) : null;
1135
- s && n && (window.clearTimeout(n.timeout), this.pendingSessionHistoryRequests.delete(s), n.resolve({
1136
- sessions: jn(e.sessions),
1137
- nextCursor: typeof e.nextCursor == "string" ? e.nextCursor : null
1138
- }));
1139
- return;
1140
- }
1141
- if (e.type === "session.pin.updated") {
1142
- this.resolvePendingSessionMutation(this.pendingSessionPinRequests, e);
1143
- return;
1144
- }
1145
- if (e.type === "session.rename.updated") {
1146
- this.resolvePendingSessionMutation(this.pendingSessionRenameRequests, e);
1147
- return;
1148
- }
1149
- if (e.type === "session.updated") {
1150
- this.clearRunAckResyncRetryTimer(), this.setState({ sessionId: E(e.session, "id") ?? this.state.sessionId });
1151
- return;
1152
- }
1153
- if (e.type === "session.item") {
1154
- this.rememberUserMessageClientMessageIds([e.item]);
1155
- const s = H(e.item);
1156
- if (We(s)) {
1157
- typeof s?.runId == "string" && this.retryableFailureRunIdsAwaitingDone.add(s.runId);
1158
- const r = E(e.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);
1159
- if (r && a) {
1160
- this.retryAfterInterruptedRun(r, a);
1161
- return;
1088
+ if (e.type === "starterPrompts.updated") {
1089
+ this.transientStarterPromptsRequestInFlight = !1, this.transientStarterPromptsRequestAttempted = !0, this.setState({
1090
+ starterPrompts: Mt(e, "starterPrompts"),
1091
+ starterPromptsLoading: !1
1092
+ });
1093
+ return;
1094
+ }
1095
+ if (e.type === "conversation.state") {
1096
+ const s = Array.isArray(e.items) ? e.items : [], n = e.pendingMessageStatus === "sending" ? "sending" : e.pendingMessageStatus === "queued" ? "reconnecting" : null, r = typeof e.pendingClientMessageId == "string" ? e.pendingClientMessageId : null, i = e.isRetrying === !0;
1097
+ n && r && (this.pendingClientMessageId = r);
1098
+ const o = Jn(
1099
+ e.assistantDraft
1100
+ ), a = o !== void 0;
1101
+ this.rememberUserMessageClientMessageIds(s);
1102
+ const l = pr(s);
1103
+ if (l) {
1104
+ const f = hr(s, l);
1105
+ this.retryAttemptsByClientMessageId[l] = Math.max(
1106
+ this.retryAttemptsByClientMessageId[l] ?? 0,
1107
+ f
1108
+ );
1162
1109
  }
1163
- if (r && i) {
1164
- this.setState({ status: "connected", isThinking: !0, lastError: null, lastErrorCode: null }), this.resyncThinkingSession();
1110
+ const c = s.filter((f) => {
1111
+ const R = H(f);
1112
+ return Rt(R) ? !1 : !R || !l || !He(R) ? !0 : je(s, R) !== l;
1113
+ }), p = ir(
1114
+ this.state.messages,
1115
+ jn(c, this.options.backendUrl)
1116
+ ), h = At(p), w = !a && s.some(
1117
+ (f) => Et(
1118
+ H(f),
1119
+ this.state.assistantDraft,
1120
+ this.state.assistantDraftItemId,
1121
+ this.state.assistantDraftRespondsToUserMessageId,
1122
+ this.state.assistantDraftRunId
1123
+ )
1124
+ ), y = a ? o?.content ?? "" : this.state.assistantDraft, u = !!o?.content, d = h && (!y || w), g = cr(p), m = d && g;
1125
+ if (!h && dr(this.state.messages, s))
1165
1126
  return;
1166
- }
1167
- }
1168
- if (Rt(s))
1169
- return;
1170
- const n = Wt(e.item, this.options.backendUrl);
1171
- if (n) {
1172
- const r = n.callId ? this.pendingToolLoadingByCallId.get(n.callId) : void 0;
1173
- n.callId && r !== void 0 && (n.loading = r, this.pendingToolLoadingByCallId.delete(n.callId)), x(n) && (this.retryableClientMessageId = null, this.clearRetryTimers(), this.clearRunAckResyncRetryTimer());
1174
- const i = e.item.data;
1175
- pr(i) && this.clearRunAckResyncRetryTimer();
1176
- const o = Be(this.state.messages, n), a = At(o), l = Et(
1177
- i,
1178
- this.state.assistantDraft,
1179
- this.state.assistantDraftItemId,
1180
- this.state.assistantDraftRespondsToUserMessageId,
1181
- this.state.assistantDraftRunId
1182
- ), c = a && (!this.state.assistantDraft || l), h = x(n) && (c || !this.state.isThinking && this.activeClientMessageId === null);
1183
- this.setState({
1184
- messages: o,
1185
- ...l ? {
1127
+ this.lastUserMessagePageUrl = ur(s);
1128
+ const T = d ? null : $e(s);
1129
+ if (this.latestRecoverableClientMessageId = T, g && this.clearRetryTimers(), this.setState({
1130
+ sessionId: E(e.session, "id") ?? this.state.sessionId,
1131
+ messages: p,
1132
+ ...n ? { pendingMessageStatus: n } : {},
1133
+ isRetrying: i,
1134
+ ...a ? {
1135
+ assistantDraft: o?.content ?? "",
1136
+ assistantDraftItemId: o?.itemId ?? null,
1137
+ assistantDraftPhase: o?.phase ?? null,
1138
+ assistantDraftRespondsToUserMessageId: o?.respondsToUserMessageId ?? null,
1139
+ assistantDraftRunId: o?.runId ?? null
1140
+ } : w ? {
1186
1141
  assistantDraft: "",
1187
1142
  assistantDraftItemId: null,
1188
1143
  assistantDraftPhase: null,
1189
1144
  assistantDraftRespondsToUserMessageId: null,
1190
1145
  assistantDraftRunId: null
1191
1146
  } : {},
1192
- ...c ? {
1147
+ ...u ? {
1148
+ isThinking: !0,
1149
+ lastError: null
1150
+ } : d ? {
1193
1151
  isThinking: !1,
1194
- isRetrying: !1
1195
- } : {},
1196
- ...h ? {
1197
- status: "connected",
1198
- lastError: null,
1199
- lastErrorCode: null,
1200
- lastErrorSecuritySettingsUrl: null
1152
+ ...m ? {
1153
+ status: "connected",
1154
+ lastError: null,
1155
+ lastErrorCode: null,
1156
+ lastErrorSecuritySettingsUrl: null
1157
+ } : {}
1158
+ } : T ? {
1159
+ isThinking: !0,
1160
+ lastError: null
1201
1161
  } : {}
1202
- }), c && this.clearThinkingWatchdog(), this.emit("message", n);
1162
+ }), d)
1163
+ this.retryableClientMessageId = null, this.clearThinkingWatchdog();
1164
+ else if (u || T) {
1165
+ if (T) {
1166
+ this.activeClientMessageId = T;
1167
+ const f = Y(s), R = f === null ? null : s[f];
1168
+ this.activeResponseUserMessageId = E(R, "id");
1169
+ }
1170
+ this.markThinkingProgress();
1171
+ }
1172
+ if (l) {
1173
+ const f = E(e.session, "id") ?? this.state.sessionId;
1174
+ f && this.retryAfterInterruptedRun(f, l);
1175
+ }
1176
+ return;
1203
1177
  }
1204
- return;
1205
- }
1206
- if (e.type === "chat.assistant_delta") {
1207
- this.clearRunAckResyncRetryTimer();
1208
- const s = typeof e.delta == "string" ? e.delta : "", n = typeof e.itemId == "string" ? e.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), l = e.phase === "commentary" || e.phase === "final_answer" ? e.phase : r ? null : this.state.assistantDraftPhase, c = typeof e.respondsToUserMessageId == "string" ? e.respondsToUserMessageId : this.state.assistantDraftRespondsToUserMessageId, h = typeof e.runId == "string" ? e.runId : this.state.assistantDraftRunId;
1209
- this.activeClientMessageId && (this.activeResponseUserMessageId = c, this.activeResponseRunId = h), this.setState({
1210
- messages: Be(this.state.messages, {
1211
- id: o,
1212
- role: "assistant",
1213
- content: i,
1214
- createdAt: a?.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
1215
- ...typeof e.causalSequence == "number" ? { causalSequence: e.causalSequence } : {},
1216
- dataType: "assistant_draft",
1217
- ...l ? { phase: l } : {},
1218
- ...c ? { respondsToUserMessageId: c } : {},
1219
- ...h ? { runId: h } : {}
1220
- }),
1221
- assistantDraft: i,
1222
- assistantDraftItemId: n ?? this.state.assistantDraftItemId,
1223
- assistantDraftPhase: l,
1224
- assistantDraftRespondsToUserMessageId: c,
1225
- assistantDraftRunId: h,
1226
- isThinking: !0,
1227
- isRetrying: !1
1228
- }), this.markThinkingProgress(), this.emit("delta", s);
1229
- return;
1230
- }
1231
- if (e.type === "chat.assistant_done") {
1232
- if (typeof e.runId == "string" && this.retryableFailureRunIdsAwaitingDone.delete(e.runId))
1178
+ if (e.type === "sessions.page") {
1179
+ const s = typeof e.requestId == "string" ? e.requestId : null, n = s ? this.pendingSessionHistoryRequests.get(s) : null;
1180
+ s && n && (window.clearTimeout(n.timeout), this.pendingSessionHistoryRequests.delete(s), n.resolve({
1181
+ sessions: Fn(e.sessions),
1182
+ nextCursor: typeof e.nextCursor == "string" ? e.nextCursor : null
1183
+ }));
1233
1184
  return;
1234
- this.retryableClientMessageId = null;
1235
- const s = typeof e.sessionId == "string" ? e.sessionId : this.state.sessionId, n = typeof e.respondsToUserMessageId == "string" ? e.respondsToUserMessageId : null, r = typeof e.runId == "string" ? e.runId : null;
1236
- if (!(n && this.state.assistantDraftRespondsToUserMessageId ? n === this.state.assistantDraftRespondsToUserMessageId : !r || !this.state.assistantDraftRunId || r === this.state.assistantDraftRunId))
1185
+ }
1186
+ if (e.type === "session.pin.updated") {
1187
+ this.resolvePendingSessionMutation(this.pendingSessionPinRequests, e);
1237
1188
  return;
1238
- const o = n ? this.clientMessageIdsByUserMessageItemId.get(n) ?? null : null, a = !this.activeClientMessageId || (o ? o === this.activeClientMessageId : this.activeResponseUserMessageId ? !n || n === this.activeResponseUserMessageId : !this.activeResponseRunId || !r || r === this.activeResponseRunId), l = ms(
1239
- this.state.messages.filter(
1240
- (c) => c.dataType !== "assistant_draft" || !Yn(
1241
- c,
1242
- n,
1243
- r
1244
- )
1245
- ),
1246
- n,
1247
- r,
1248
- jt
1249
- );
1250
- this.setState({
1251
- sessionId: s,
1252
- messages: Qn(
1253
- l,
1254
- typeof e.responseId == "string" ? e.responseId : null,
1255
- n,
1256
- r
1257
- ),
1258
- assistantDraft: "",
1259
- assistantDraftItemId: null,
1260
- assistantDraftPhase: null,
1261
- assistantDraftRespondsToUserMessageId: null,
1262
- assistantDraftRunId: null,
1263
- isThinking: a ? !1 : this.state.isThinking,
1264
- isRetrying: a ? !1 : this.state.isRetrying
1265
- }), a && this.clearThinkingWatchdog();
1266
- return;
1267
- }
1268
- if (e.type === "tool.call") {
1269
- this.clearRunAckResyncRetryTimer();
1270
- const s = e.hiddenFromTranscript === !0 && typeof e.callId == "string" ? e.callId : null;
1271
- if (s)
1272
- this.nonTranscriptToolCallIds.add(s);
1273
- else {
1274
- const n = tr(e);
1189
+ }
1190
+ if (e.type === "session.rename.updated") {
1191
+ this.resolvePendingSessionMutation(this.pendingSessionRenameRequests, e);
1192
+ return;
1193
+ }
1194
+ if (e.type === "session.updated") {
1195
+ this.clearRunAckResyncRetryTimer();
1196
+ const s = E(e.session, "id");
1197
+ s && typeof e.warmupId == "string" && e.warmupId === this.pendingComposerWarmup?.event.warmupId && (this.pendingComposerWarmup.event = {
1198
+ ...this.pendingComposerWarmup.event,
1199
+ sessionId: s
1200
+ }, this.pendingComposerWarmup.scope = `${s}:${this.pendingComposerWarmup.event.page.url}`), this.setState({ sessionId: s ?? this.state.sessionId });
1201
+ const n = e.session && typeof e.session == "object" ? e.session.metadata : null;
1202
+ typeof e.warmupId == "string" && e.warmupId === this.activeComposerWarmupId && n && typeof n == "object" && n.composerPreload && this.clearPendingComposerWarmup();
1203
+ return;
1204
+ }
1205
+ if (e.type === "session.item") {
1206
+ this.rememberUserMessageClientMessageIds([e.item]);
1207
+ const s = H(e.item);
1208
+ if (He(s)) {
1209
+ typeof s?.runId == "string" && this.retryableFailureRunIdsAwaitingDone.add(s.runId);
1210
+ const r = E(e.item, "sessionId") ?? this.state.sessionId, i = s ? O(s) : null, o = i ? this.clientMessageIdsByUserMessageItemId.get(i) : null, a = typeof s?.clientMessageId == "string" ? s.clientMessageId : o ?? (i ? null : this.activeClientMessageId ?? this.latestRecoverableClientMessageId);
1211
+ if (r && a) {
1212
+ this.retryAfterInterruptedRun(r, a);
1213
+ return;
1214
+ }
1215
+ if (r && i) {
1216
+ this.setState({ status: "connected", isThinking: !0, lastError: null, lastErrorCode: null }), this.resyncThinkingSession();
1217
+ return;
1218
+ }
1219
+ }
1220
+ if (Rt(s))
1221
+ return;
1222
+ const n = Ht(e.item, this.options.backendUrl);
1275
1223
  if (n) {
1276
- const r = Zn(
1277
- this.state.messages,
1278
- n
1279
- );
1224
+ const r = n.callId ? this.pendingToolLoadingByCallId.get(n.callId) : void 0;
1225
+ n.callId && r !== void 0 && (n.loading = r, this.pendingToolLoadingByCallId.delete(n.callId)), x(n) && (this.retryableClientMessageId = null, this.clearRetryTimers(), this.clearRunAckResyncRetryTimer());
1226
+ const i = e.item.data;
1227
+ fr(i) && this.clearRunAckResyncRetryTimer();
1228
+ const o = Be(this.state.messages, n), a = At(o), l = Et(
1229
+ i,
1230
+ this.state.assistantDraft,
1231
+ this.state.assistantDraftItemId,
1232
+ this.state.assistantDraftRespondsToUserMessageId,
1233
+ this.state.assistantDraftRunId
1234
+ ), c = a && (!this.state.assistantDraft || l), p = x(n) && (c || !this.state.isThinking && this.activeClientMessageId === null);
1280
1235
  this.setState({
1281
- messages: r,
1282
- isThinking: !0
1283
- }), this.emit(
1284
- "message",
1285
- r.find(
1286
- (i) => i.callId === n.callId
1287
- ) ?? n
1288
- );
1236
+ messages: o,
1237
+ ...l ? {
1238
+ assistantDraft: "",
1239
+ assistantDraftItemId: null,
1240
+ assistantDraftPhase: null,
1241
+ assistantDraftRespondsToUserMessageId: null,
1242
+ assistantDraftRunId: null
1243
+ } : {},
1244
+ ...c ? {
1245
+ isThinking: !1,
1246
+ isRetrying: !1
1247
+ } : {},
1248
+ ...p ? {
1249
+ status: "connected",
1250
+ lastError: null,
1251
+ lastErrorCode: null,
1252
+ lastErrorSecuritySettingsUrl: null
1253
+ } : {}
1254
+ }), c && this.clearThinkingWatchdog(), this.emit("message", n);
1289
1255
  }
1290
- }
1291
- this.executeToolCall(e);
1292
- return;
1293
- }
1294
- if (e.type === "tool.status") {
1295
- const s = typeof e.callId == "string" ? e.callId : null;
1296
- if (!s)
1297
- return;
1298
- const n = e.status === "queued" || e.status === "running";
1299
- if (this.nonTranscriptToolCallIds.has(s) || n && this.terminalToolCallIds.has(s))
1300
1256
  return;
1301
- n || this.terminalToolCallIds.add(s), this.state.messages.some(
1302
- (i) => i.callId === s
1303
- ) ? this.setToolMessageLoading(s, n) : this.pendingToolLoadingByCallId.set(s, n);
1304
- return;
1305
- }
1306
- if (e.type === "error") {
1307
- const s = typeof e.requestId == "string" ? e.requestId : null, n = s ? this.pendingSessionHistoryRequests.get(s) : null;
1308
- if (s && n) {
1309
- window.clearTimeout(n.timeout), this.pendingSessionHistoryRequests.delete(s), n.reject(new Error(typeof e.message == "string" ? e.message : "Pluno error"));
1257
+ }
1258
+ if (e.type === "chat.assistant_delta") {
1259
+ this.clearRunAckResyncRetryTimer();
1260
+ const s = typeof e.delta == "string" ? e.delta : "", n = typeof e.itemId == "string" ? e.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((h) => h.id === o), l = e.phase === "commentary" || e.phase === "final_answer" ? e.phase : r ? null : this.state.assistantDraftPhase, c = typeof e.respondsToUserMessageId == "string" ? e.respondsToUserMessageId : this.state.assistantDraftRespondsToUserMessageId, p = typeof e.runId == "string" ? e.runId : this.state.assistantDraftRunId;
1261
+ this.activeClientMessageId && (this.activeResponseUserMessageId = c, this.activeResponseRunId = p), this.setState({
1262
+ messages: Be(this.state.messages, {
1263
+ id: o,
1264
+ role: "assistant",
1265
+ content: i,
1266
+ createdAt: a?.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
1267
+ ...typeof e.causalSequence == "number" ? { causalSequence: e.causalSequence } : {},
1268
+ dataType: "assistant_draft",
1269
+ ...l ? { phase: l } : {},
1270
+ ...c ? { respondsToUserMessageId: c } : {},
1271
+ ...p ? { runId: p } : {}
1272
+ }),
1273
+ assistantDraft: i,
1274
+ assistantDraftItemId: n ?? this.state.assistantDraftItemId,
1275
+ assistantDraftPhase: l,
1276
+ assistantDraftRespondsToUserMessageId: c,
1277
+ assistantDraftRunId: p,
1278
+ isThinking: !0,
1279
+ isRetrying: !1
1280
+ }), this.markThinkingProgress(), this.emit("delta", s);
1310
1281
  return;
1311
1282
  }
1312
- if (this.rejectPendingSessionMutation(this.pendingSessionPinRequests, e) || this.rejectPendingSessionMutation(this.pendingSessionRenameRequests, e))
1283
+ if (e.type === "chat.assistant_done") {
1284
+ if (typeof e.runId == "string" && this.retryableFailureRunIdsAwaitingDone.delete(e.runId))
1285
+ return;
1286
+ this.retryableClientMessageId = null;
1287
+ const s = typeof e.sessionId == "string" ? e.sessionId : this.state.sessionId, n = typeof e.respondsToUserMessageId == "string" ? e.respondsToUserMessageId : null, r = typeof e.runId == "string" ? e.runId : null;
1288
+ if (!(n && this.state.assistantDraftRespondsToUserMessageId ? n === this.state.assistantDraftRespondsToUserMessageId : !r || !this.state.assistantDraftRunId || r === this.state.assistantDraftRunId))
1289
+ return;
1290
+ const o = n ? this.clientMessageIdsByUserMessageItemId.get(n) ?? null : null, a = !this.activeClientMessageId || (o ? o === this.activeClientMessageId : this.activeResponseUserMessageId ? !n || n === this.activeResponseUserMessageId : !this.activeResponseRunId || !r || r === this.activeResponseRunId), l = ms(
1291
+ this.state.messages.filter(
1292
+ (c) => c.dataType !== "assistant_draft" || !Zn(
1293
+ c,
1294
+ n,
1295
+ r
1296
+ )
1297
+ ),
1298
+ n,
1299
+ r,
1300
+ $t
1301
+ );
1302
+ this.setState({
1303
+ sessionId: s,
1304
+ messages: er(
1305
+ l,
1306
+ typeof e.responseId == "string" ? e.responseId : null,
1307
+ n,
1308
+ r
1309
+ ),
1310
+ assistantDraft: "",
1311
+ assistantDraftItemId: null,
1312
+ assistantDraftPhase: null,
1313
+ assistantDraftRespondsToUserMessageId: null,
1314
+ assistantDraftRunId: null,
1315
+ isThinking: a ? !1 : this.state.isThinking,
1316
+ isRetrying: a ? !1 : this.state.isRetrying
1317
+ }), a && this.clearThinkingWatchdog();
1313
1318
  return;
1314
- const r = typeof e.sessionId == "string" ? e.sessionId : this.state.sessionId, i = typeof e.clientMessageId == "string" ? e.clientMessageId : null, o = e.retryable === !0 || e.code === "transient_model_error";
1315
- if (e.code === "message_delivery_failed" && i && i === this.pendingClientMessageId) {
1316
- this.failPendingDelivery(i);
1319
+ }
1320
+ if (e.type === "tool.call") {
1321
+ this.clearRunAckResyncRetryTimer();
1322
+ const s = e.hiddenFromTranscript === !0 && typeof e.callId == "string" ? e.callId : null;
1323
+ if (s)
1324
+ this.nonTranscriptToolCallIds.add(s);
1325
+ else {
1326
+ const n = nr(e);
1327
+ if (n) {
1328
+ const r = tr(
1329
+ this.state.messages,
1330
+ n
1331
+ );
1332
+ this.setState({
1333
+ messages: r,
1334
+ isThinking: !0
1335
+ }), this.emit(
1336
+ "message",
1337
+ r.find(
1338
+ (i) => i.callId === n.callId
1339
+ ) ?? n
1340
+ );
1341
+ }
1342
+ }
1343
+ this.executeToolCall(e);
1317
1344
  return;
1318
1345
  }
1319
- if (i && i === this.pendingClientMessageId && this.promotePendingDelivery(
1320
- i,
1321
- r,
1322
- typeof e.respondsToUserMessageId == "string" ? e.respondsToUserMessageId : null,
1323
- typeof e.runId == "string" ? e.runId : null
1324
- ), this.retryAfterRetryableError(e)) {
1325
- e.code !== "run_still_active" && typeof e.runId == "string" && this.retryableFailureRunIdsAwaitingDone.add(e.runId);
1346
+ if (e.type === "tool.status") {
1347
+ const s = typeof e.callId == "string" ? e.callId : null;
1348
+ if (!s)
1349
+ return;
1350
+ const n = e.status === "queued" || e.status === "running";
1351
+ if (this.nonTranscriptToolCallIds.has(s) || n && this.terminalToolCallIds.has(s))
1352
+ return;
1353
+ n || this.terminalToolCallIds.add(s), this.state.messages.some(
1354
+ (i) => i.callId === s
1355
+ ) ? this.setToolMessageLoading(s, n) : this.pendingToolLoadingByCallId.set(s, n);
1326
1356
  return;
1327
1357
  }
1328
- o && r && i && (this.retryableClientMessageId = i);
1329
- const a = new Error(typeof e.message == "string" ? e.message.replace(/Product Agent/g, "Pluno") : "Pluno error"), l = Mn(a.message);
1330
- l && console.error(l), this.setState({
1331
- messages: oe(
1332
- this.state.messages,
1333
- i ?? this.activeClientMessageId,
1358
+ if (e.type === "error") {
1359
+ const s = typeof e.requestId == "string" ? e.requestId : null, n = s ? this.pendingSessionHistoryRequests.get(s) : null;
1360
+ if (s && n) {
1361
+ window.clearTimeout(n.timeout), this.pendingSessionHistoryRequests.delete(s), n.reject(new Error(typeof e.message == "string" ? e.message : "Pluno error"));
1362
+ return;
1363
+ }
1364
+ if (this.rejectPendingSessionMutation(this.pendingSessionPinRequests, e) || this.rejectPendingSessionMutation(this.pendingSessionRenameRequests, e))
1365
+ return;
1366
+ const r = typeof e.sessionId == "string" ? e.sessionId : this.state.sessionId, i = typeof e.clientMessageId == "string" ? e.clientMessageId : null, o = e.retryable === !0 || e.code === "transient_model_error";
1367
+ if (e.code === "message_delivery_failed" && i && i === this.pendingClientMessageId) {
1368
+ this.failPendingDelivery(i);
1369
+ return;
1370
+ }
1371
+ if (i && i === this.pendingClientMessageId && this.promotePendingDelivery(
1372
+ i,
1373
+ r,
1374
+ typeof e.respondsToUserMessageId == "string" ? e.respondsToUserMessageId : null,
1334
1375
  typeof e.runId == "string" ? e.runId : null
1335
- ),
1336
- status: "error",
1337
- isThinking: !1,
1338
- isRetrying: !1,
1339
- lastError: a.message,
1340
- lastErrorCode: typeof e.code == "string" ? e.code : null,
1341
- lastErrorSecuritySettingsUrl: typeof e.securitySettingsUrl == "string" ? e.securitySettingsUrl : null
1342
- }), this.clearThinkingWatchdog(), this.emit("error", a);
1376
+ ), this.retryAfterRetryableError(e)) {
1377
+ e.code !== "run_still_active" && typeof e.runId == "string" && this.retryableFailureRunIdsAwaitingDone.add(e.runId);
1378
+ return;
1379
+ }
1380
+ o && r && i && (this.retryableClientMessageId = i);
1381
+ const a = new Error(typeof e.message == "string" ? e.message.replace(/Product Agent/g, "Pluno") : "Pluno error"), l = Rn(a.message);
1382
+ l && console.error(l), this.setState({
1383
+ messages: oe(
1384
+ this.state.messages,
1385
+ i ?? this.activeClientMessageId,
1386
+ typeof e.runId == "string" ? e.runId : null
1387
+ ),
1388
+ status: "error",
1389
+ isThinking: !1,
1390
+ isRetrying: !1,
1391
+ lastError: a.message,
1392
+ lastErrorCode: typeof e.code == "string" ? e.code : null,
1393
+ lastErrorSecuritySettingsUrl: typeof e.securitySettingsUrl == "string" ? e.securitySettingsUrl : null
1394
+ }), this.clearThinkingWatchdog(), this.emit("error", a);
1395
+ }
1343
1396
  }
1344
1397
  }
1345
1398
  }
1346
1399
  shouldIgnoreBackgroundSessionEvent(e) {
1347
- if (!this.options.keepRunsActiveOnSessionNavigation || !nn(e))
1400
+ if (!this.options.keepRunsActiveOnSessionNavigation || !on(e))
1348
1401
  return !1;
1349
1402
  const s = De(e);
1350
1403
  return s ? this.deferredSessionUpdatedSessionIds.has(s) ? !0 : this.state.sessionId ? s !== this.state.sessionId : this.backgroundSessionIds.has(s) : !1;
@@ -1370,10 +1423,10 @@ class xt {
1370
1423
  if (this.retryTimersByClientMessageId[n] !== void 0)
1371
1424
  return !0;
1372
1425
  const i = this.retryAttemptsByClientMessageId[n] ?? 0;
1373
- if (i >= K)
1426
+ if (i >= G)
1374
1427
  return !1;
1375
1428
  this.retryAttemptsByClientMessageId[n] = i + 1;
1376
- const o = G(
1429
+ const o = X(
1377
1430
  i,
1378
1431
  typeof e.retryAfterMs == "number" ? e.retryAfterMs : 0
1379
1432
  );
@@ -1394,7 +1447,7 @@ class xt {
1394
1447
  if (this.retryTimersByClientMessageId[s] !== void 0)
1395
1448
  return;
1396
1449
  const n = this.retryAttemptsByClientMessageId[s] ?? 0;
1397
- if (n >= K) {
1450
+ if (n >= G) {
1398
1451
  this.reportHealthSignal("run_recovery_exhausted", {
1399
1452
  clientMessageId: s,
1400
1453
  retryAttempts: n,
@@ -1414,7 +1467,7 @@ class xt {
1414
1467
  }
1415
1468
  this.retryAttemptsByClientMessageId[s] = n + 1, this.activeClientMessageId = s, this.latestRecoverableClientMessageId = s, this.setState({ status: "connected", isThinking: !0, isRetrying: !0, lastError: null, lastErrorCode: null }), this.retryTimersByClientMessageId[s] = window.setTimeout(() => {
1416
1469
  delete this.retryTimersByClientMessageId[s], this.setState({ status: "connected", isThinking: !0, isRetrying: !0, lastError: null, lastErrorCode: null }), this.markThinkingProgress(), this.send({ type: "chat.retry_last_user_message", sessionId: e, clientMessageId: s, automatic: !0 });
1417
- }, G(n));
1470
+ }, X(n));
1418
1471
  }
1419
1472
  clearRetryTimers() {
1420
1473
  for (const e of Object.values(this.retryTimersByClientMessageId))
@@ -1515,13 +1568,13 @@ class xt {
1515
1568
  if (this.state.status === "closed" || this.pendingClientMessageId !== e || !this.pendingUserMessageEvent)
1516
1569
  return;
1517
1570
  const s = this.retryAttemptsByClientMessageId[e] ?? 0;
1518
- if (s >= K) {
1571
+ if (s >= G) {
1519
1572
  this.failPendingDelivery(e);
1520
1573
  return;
1521
1574
  }
1522
1575
  s === 0 && this.reportHealthSignal("run_ack_missed", { clientMessageId: e }), this.retryAttemptsByClientMessageId[e] = s + 1, this.setState({ pendingMessageStatus: "reconnecting" }), this.pendingDeliveryRetryTimer = window.setTimeout(() => {
1523
1576
  this.pendingDeliveryRetryTimer = null, !(this.pendingClientMessageId !== e || !this.pendingUserMessageEvent) && (this.send(this.pendingUserMessageEvent), this.setState({ pendingMessageStatus: "sending" }), this.schedulePendingDeliveryAck(e));
1524
- }, G(s, mt));
1577
+ }, X(s, mt));
1525
1578
  }
1526
1579
  failPendingDelivery(e) {
1527
1580
  if (this.pendingClientMessageId !== e)
@@ -1530,7 +1583,7 @@ class xt {
1530
1583
  this.clearPendingDeliveryTimers(), this.pendingClientMessageId = null, this.pendingUserMessageEvent = null, this.failedUserMessageEvent = s, this.retryableClientMessageId = e, this.setState({
1531
1584
  pendingMessageStatus: null,
1532
1585
  isRetrying: !1,
1533
- lastError: Fs,
1586
+ lastError: zs,
1534
1587
  lastErrorCode: "message_delivery_failed"
1535
1588
  });
1536
1589
  }
@@ -1545,7 +1598,7 @@ class xt {
1545
1598
  s,
1546
1599
  typeof e.runId == "string" ? e.runId : null
1547
1600
  ), !(!this.state.isThinking || !s) && this.setState({
1548
- messages: yr(
1601
+ messages: Tr(
1549
1602
  this.state.messages,
1550
1603
  s
1551
1604
  )
@@ -1565,7 +1618,7 @@ class xt {
1565
1618
  scheduleRunAckResyncRetry(e) {
1566
1619
  this.clearRunAckResyncRetryTimer();
1567
1620
  const s = this.retryAttemptsByClientMessageId[e] ?? 0;
1568
- s >= K || (this.runAckResyncRetryTimer = window.setTimeout(() => {
1621
+ s >= G || (this.runAckResyncRetryTimer = window.setTimeout(() => {
1569
1622
  this.runAckResyncRetryTimer = null, (this.retryAttemptsByClientMessageId[e] ?? 0) === s && (!this.state.isThinking || this.state.status === "closed" || this.activeClientMessageId !== e || this.latestRecoverableClientMessageId !== e || (this.retryAttemptsByClientMessageId[e] = s + 1, this.setState({
1570
1623
  status: this.state.status === "reconnecting" ? "reconnecting" : "connected",
1571
1624
  isThinking: !0,
@@ -1579,7 +1632,7 @@ class xt {
1579
1632
  clientMessageId: e,
1580
1633
  automatic: !0
1581
1634
  }) : this.activeUserMessageEvent && this.send(this.activeUserMessageEvent), this.scheduleThinkingWatchdog(gt)));
1582
- }, G(s, mt)));
1635
+ }, X(s, mt)));
1583
1636
  }
1584
1637
  clearRunAckResyncRetryTimer() {
1585
1638
  this.runAckResyncRetryTimer !== null && (window.clearTimeout(this.runAckResyncRetryTimer), this.runAckResyncRetryTimer = null);
@@ -1604,7 +1657,7 @@ class xt {
1604
1657
  return;
1605
1658
  }
1606
1659
  const s = this.thinkingWatchdogResyncAttemptsByClientMessageId[e] ?? 0, n = this.retryAttemptsByClientMessageId[e] ?? 0;
1607
- if (n >= K) {
1660
+ if (n >= G) {
1608
1661
  M("web-sdk.agent", "Pluno run recovery retry exhausted", {
1609
1662
  sessionId: this.state.sessionId,
1610
1663
  clientMessageId: e
@@ -1629,7 +1682,7 @@ class xt {
1629
1682
  sessionId: this.state.sessionId,
1630
1683
  clientMessageId: e,
1631
1684
  resyncAttempts: s + 1
1632
- }), this.resyncThinkingSession(), this.scheduleThinkingWatchdog(Hs);
1685
+ }), this.resyncThinkingSession(), this.scheduleThinkingWatchdog($s);
1633
1686
  return;
1634
1687
  }
1635
1688
  this.setState({
@@ -1647,7 +1700,7 @@ class xt {
1647
1700
  clientMessageId: e,
1648
1701
  automatic: !0
1649
1702
  }) : this.activeUserMessageEvent && this.send(this.activeUserMessageEvent), this.markThinkingProgress();
1650
- }, G(n)));
1703
+ }, X(n)));
1651
1704
  }
1652
1705
  resyncThinkingSession() {
1653
1706
  this.state.sessionId ? this.send({
@@ -1658,13 +1711,13 @@ class xt {
1658
1711
  }) : (!this.socket || this.socket.readyState !== WebSocket.OPEN) && (this.setReconnectingState(), this.scheduleReconnect());
1659
1712
  }
1660
1713
  async executeToolCall(e) {
1661
- const s = typeof e.sessionId == "string" ? e.sessionId : null, n = typeof e.callId == "string" ? e.callId : null, r = typeof e.toolName == "string" ? e.toolName : null, i = B(
1714
+ const s = typeof e.sessionId == "string" ? e.sessionId : null, n = typeof e.callId == "string" ? e.callId : null, r = typeof e.toolName == "string" ? e.toolName : null, i = W(
1662
1715
  typeof e.summary == "string" ? e.summary : "Running browser tool"
1663
1716
  ), o = e.rawInput;
1664
1717
  if (!s || !n || !r)
1665
1718
  return;
1666
1719
  const a = r === "execute_code", l = r === "execute_code_in_browser_tab" && o !== null && typeof o == "object" && o.tabId === "local:current";
1667
- if (!a && !l || !qr(o)) {
1720
+ if (!a && !l || !Wr(o)) {
1668
1721
  this.setToolMessageLoading(n, !1), this.send({
1669
1722
  type: "tool.result",
1670
1723
  sessionId: s,
@@ -1710,14 +1763,14 @@ class xt {
1710
1763
  startedAtUrl: location.href,
1711
1764
  startedAtOrigin: location.origin
1712
1765
  }), this.installSessionBrowserApis();
1713
- let c = null, h;
1714
- c = await this.executeRuntimeHelper(), h = await wt(
1766
+ let c = null, p;
1767
+ c = await this.executeRuntimeHelper(), p = await wt(
1715
1768
  o,
1716
- yn(e.runtimeContext, this.options.backendUrl)
1717
- ).catch((p) => ({
1769
+ Tn(e.runtimeContext, this.options.backendUrl)
1770
+ ).catch((h) => ({
1718
1771
  ok: !1,
1719
1772
  exception: {
1720
- message: p instanceof Error ? p.message : String(p)
1773
+ message: h instanceof Error ? h.message : String(h)
1721
1774
  }
1722
1775
  })), this.activeBrowserToolCalls.delete(n), this.setToolMessageLoading(n, !1), this.send({
1723
1776
  type: "tool.result",
@@ -1726,11 +1779,11 @@ class xt {
1726
1779
  toolName: r,
1727
1780
  summary: o.summary,
1728
1781
  rawInput: k(o),
1729
- rawOutput: k(Ln(h, c))
1730
- }), Cr(this.options.clientId, this.activeBrowserToolCalls.values());
1782
+ rawOutput: k(Bn(p, c))
1783
+ }), kr(this.options.clientId, this.activeBrowserToolCalls.values());
1731
1784
  }
1732
1785
  setToolMessageLoading(e, s) {
1733
- const n = er(
1786
+ const n = sr(
1734
1787
  this.state.messages,
1735
1788
  e,
1736
1789
  s
@@ -1748,10 +1801,10 @@ class xt {
1748
1801
  };
1749
1802
  }
1750
1803
  installSessionBrowserApis() {
1751
- this.cleanupSessionBrowserApis(), this.sessionBrowserApisCleanup = an();
1804
+ this.cleanupSessionBrowserApis(), this.sessionBrowserApisCleanup = cn();
1752
1805
  }
1753
1806
  cleanupSessionBrowserApis() {
1754
- this.sessionBrowserApisCleanup && (fn(this.sessionBrowserApisCleanup), this.sessionBrowserApisCleanup = null);
1807
+ this.sessionBrowserApisCleanup && (yn(this.sessionBrowserApisCleanup), this.sessionBrowserApisCleanup = null);
1755
1808
  }
1756
1809
  async executeRuntimeHelper() {
1757
1810
  if (!this.runtimeHelperJavascript?.trim())
@@ -1759,15 +1812,15 @@ class xt {
1759
1812
  const e = await wt({
1760
1813
  javascript: this.runtimeHelperJavascript
1761
1814
  });
1762
- return e.ok === !1 ? qn(e) : null;
1815
+ return e.ok === !1 ? Wn(e) : null;
1763
1816
  }
1764
1817
  enableNetworkCapture() {
1765
- this.networkCaptureCleanup || (this.networkCaptureCleanup = en((e) => {
1766
- $r(e.url, this.options.backendUrl) || this.enqueueNetworkEvent(e);
1818
+ this.networkCaptureCleanup || (this.networkCaptureCleanup = sn((e) => {
1819
+ Kr(e.url, this.options.backendUrl) || this.enqueueNetworkEvent(e);
1767
1820
  }));
1768
1821
  }
1769
1822
  enqueueNetworkEvent(e) {
1770
- this.queuedNetworkEvents.length >= zs || (this.queuedNetworkEvents.push(Fr(e)), this.networkBatchTimer === null && (this.networkBatchTimer = window.setTimeout(() => {
1823
+ this.queuedNetworkEvents.length >= Gs || (this.queuedNetworkEvents.push(zr(e)), this.networkBatchTimer === null && (this.networkBatchTimer = window.setTimeout(() => {
1771
1824
  this.networkBatchTimer = null;
1772
1825
  const s = this.queuedNetworkEvents.splice(0, this.queuedNetworkEvents.length);
1773
1826
  s.length === 0 || this.socket?.readyState !== WebSocket.OPEN || this.sendNow({
@@ -1776,12 +1829,12 @@ class xt {
1776
1829
  page: C(),
1777
1830
  events: s
1778
1831
  });
1779
- }, $s)));
1832
+ }, Ks)));
1780
1833
  }
1781
1834
  scheduleReconnect() {
1782
1835
  if (this.reconnectTimer !== null || this.state.status === "closed")
1783
1836
  return;
1784
- const e = Qs(this.reconnectAttempts);
1837
+ const e = en(this.reconnectAttempts);
1785
1838
  this.reconnectAttempts += 1, this.reconnectTimer = window.setTimeout(() => {
1786
1839
  this.reconnectTimer = null, this.connect().catch((s) => {
1787
1840
  M("web-sdk.agent", "Pluno reconnect failed; retrying", {
@@ -1797,8 +1850,8 @@ class xt {
1797
1850
  const e = this.socket;
1798
1851
  !e || !this.sendNow({ type: "runtime.ping" }) || (this.clearHeartbeatAckTimer(), this.heartbeatAckTimer = window.setTimeout(() => {
1799
1852
  this.socket === e && (M("web-sdk.agent", "Pluno heartbeat acknowledgement timed out; reconnecting"), this.replaceTimedOutSocket(e));
1800
- }, Ns));
1801
- }, Os);
1853
+ }, Os));
1854
+ }, Ns);
1802
1855
  }
1803
1856
  stopHeartbeat() {
1804
1857
  this.heartbeatTimer !== null && (window.clearInterval(this.heartbeatTimer), this.heartbeatTimer = null), this.clearHeartbeatAckTimer();
@@ -1806,6 +1859,12 @@ class xt {
1806
1859
  clearHeartbeatAckTimer() {
1807
1860
  this.heartbeatAckTimer !== null && (window.clearTimeout(this.heartbeatAckTimer), this.heartbeatAckTimer = null);
1808
1861
  }
1862
+ clearPendingWarmupAckTimer() {
1863
+ this.pendingWarmupAckTimer !== null && (window.clearTimeout(this.pendingWarmupAckTimer), this.pendingWarmupAckTimer = null);
1864
+ }
1865
+ clearPendingComposerWarmup() {
1866
+ this.clearPendingWarmupAckTimer(), this.pendingComposerWarmup = null, this.activeComposerWarmupId = null, this.activeComposerWarmupScope = null;
1867
+ }
1809
1868
  clearSocketConnectTimer() {
1810
1869
  this.socketConnectTimer !== null && (window.clearTimeout(this.socketConnectTimer), this.socketConnectTimer = null);
1811
1870
  }
@@ -1824,7 +1883,7 @@ class xt {
1824
1883
  ...e,
1825
1884
  ...e.lastError === null && e.lastErrorCode === void 0 ? { lastErrorCode: null } : {},
1826
1885
  ...e.lastError !== void 0 && e.lastErrorSecuritySettingsUrl === void 0 ? { lastErrorSecuritySettingsUrl: null } : {}
1827
- }, Er(this.options.clientId, this.state), this.emit("state", this.getState()), ke("state", this.state.status, {
1886
+ }, br(this.options.clientId, this.state), this.emit("state", this.getState()), ke("state", this.state.status, {
1828
1887
  status: this.state.status,
1829
1888
  sessionId: this.state.sessionId,
1830
1889
  messageCount: this.state.messages.length,
@@ -1844,20 +1903,20 @@ class xt {
1844
1903
  this.state.isThinking && this.activeClientMessageId ? this.browserConnectionInterruptedClientMessageIds.add(this.activeClientMessageId) : this.pendingClientMessageId && this.browserConnectionInterruptedClientMessageIds.add(this.pendingClientMessageId);
1845
1904
  }
1846
1905
  getRunRecoveryExhaustedErrorMessage(e) {
1847
- return e && this.browserConnectionInterruptedClientMessageIds.has(e) ? js : Ws;
1906
+ return e && this.browserConnectionInterruptedClientMessageIds.has(e) ? Fs : js;
1848
1907
  }
1849
1908
  emit(e, s) {
1850
1909
  this.listeners[e]?.forEach((r) => r(s));
1851
1910
  }
1852
1911
  }
1853
- const Pe = /* @__PURE__ */ new WeakMap();
1854
- function en(t) {
1855
- const e = window.__plunoProductAgentNetworkCapture ?? tn();
1912
+ const Ue = /* @__PURE__ */ new WeakMap();
1913
+ function sn(t) {
1914
+ const e = window.__plunoProductAgentNetworkCapture ?? nn();
1856
1915
  return e.subscribers.add(t), () => {
1857
1916
  e.subscribers.delete(t), !(e.subscribers.size > 0) && (e.destroy(), window.__plunoProductAgentNetworkCapture === e && delete window.__plunoProductAgentNetworkCapture);
1858
1917
  };
1859
1918
  }
1860
- function tn() {
1919
+ function nn() {
1861
1920
  const t = /* @__PURE__ */ new Set(), e = (w) => {
1862
1921
  t.forEach((y) => {
1863
1922
  try {
@@ -1874,11 +1933,11 @@ function tn() {
1874
1933
  throw m;
1875
1934
  }
1876
1935
  try {
1877
- const m = y instanceof Request ? y : null, T = Br(y, m), f = Yt(u?.headers ?? m?.headers);
1878
- if (!q(T, f, u?.body)) {
1936
+ const m = y instanceof Request ? y : null, T = Hr(y, m), f = Yt(u?.headers ?? m?.headers);
1937
+ if (!B(T, f, u?.body)) {
1879
1938
  const F = {
1880
- requestId: Ne("fetch"),
1881
- url: P(T, Ue),
1939
+ requestId: Oe("fetch"),
1940
+ url: U(T, Pe),
1882
1941
  method: (u?.method ?? m?.method ?? "GET").toUpperCase(),
1883
1942
  requestHeaders: f,
1884
1943
  requestBody: _t(u?.body),
@@ -1886,19 +1945,19 @@ function tn() {
1886
1945
  startedAt: new Date(d).toISOString()
1887
1946
  };
1888
1947
  g.then(
1889
- (U) => {
1890
- Hr(U, F, d, e).catch(() => {
1948
+ (P) => {
1949
+ $r(P, F, d, e).catch(() => {
1891
1950
  e({
1892
1951
  ...F,
1893
- responseStatus: U.status,
1952
+ responseStatus: P.status,
1894
1953
  durationMs: Date.now() - d
1895
1954
  });
1896
1955
  });
1897
1956
  },
1898
- (U) => {
1957
+ (P) => {
1899
1958
  e({
1900
1959
  ...F,
1901
- errorText: P(U instanceof Error ? U.message : String(U)),
1960
+ errorText: U(P instanceof Error ? P.message : String(P)),
1902
1961
  durationMs: Date.now() - d
1903
1962
  });
1904
1963
  }
@@ -1909,27 +1968,27 @@ function tn() {
1909
1968
  return g;
1910
1969
  }, a = function(y, u, d, g, m) {
1911
1970
  const T = n.call(this, y, u, d ?? !0, g ?? void 0, m ?? void 0), f = typeof u == "string" ? u : u.toString();
1912
- return Pe.set(this, {
1913
- requestId: Ne("xhr"),
1971
+ return Ue.set(this, {
1972
+ requestId: Oe("xhr"),
1914
1973
  method: String(y ?? "GET").toUpperCase(),
1915
- url: P(f, Ue),
1974
+ url: U(f, Pe),
1916
1975
  requestHeaders: {},
1917
1976
  startedAtMs: Date.now(),
1918
1977
  startedAt: (/* @__PURE__ */ new Date()).toISOString(),
1919
- excluded: q(f)
1978
+ excluded: B(f)
1920
1979
  }), T;
1921
1980
  }, l = function(y, u) {
1922
- const d = r.call(this, y, u), g = Pe.get(this);
1923
- return g && Object.keys(g.requestHeaders).length < Je && (g.requestHeaders[y] = et(y, u), g.excluded = g.excluded || q(g.url, g.requestHeaders)), d;
1981
+ const d = r.call(this, y, u), g = Ue.get(this);
1982
+ return g && Object.keys(g.requestHeaders).length < Je && (g.requestHeaders[y] = et(y, u), g.excluded = g.excluded || B(g.url, g.requestHeaders)), d;
1924
1983
  }, c = function(y) {
1925
1984
  try {
1926
- const u = Pe.get(this);
1927
- u && (u.excluded = u.excluded || q(u.url, u.requestHeaders, y), u.requestBody = _t(y), u.excluded || this.addEventListener(
1985
+ const u = Ue.get(this);
1986
+ u && (u.excluded = u.excluded || B(u.url, u.requestHeaders, y), u.requestBody = _t(y), u.excluded || this.addEventListener(
1928
1987
  "loadend",
1929
1988
  () => {
1930
1989
  queueMicrotask(() => {
1931
1990
  try {
1932
- const d = Kr(this.getAllResponseHeaders());
1991
+ const d = Xr(this.getAllResponseHeaders());
1933
1992
  e({
1934
1993
  requestId: u.requestId,
1935
1994
  url: u.url,
@@ -1939,7 +1998,7 @@ function tn() {
1939
1998
  resourceType: "xhr",
1940
1999
  responseStatus: this.status,
1941
2000
  responseHeaders: d,
1942
- responseBody: jr(this, d),
2001
+ responseBody: Fr(this, d),
1943
2002
  errorText: this.status === 0 ? "XHR request failed or was aborted" : void 0,
1944
2003
  startedAt: u.startedAt,
1945
2004
  durationMs: Date.now() - u.startedAtMs
@@ -1971,17 +2030,17 @@ function tn() {
1971
2030
  XMLHttpRequest.prototype.send = c;
1972
2031
  } catch {
1973
2032
  }
1974
- let h = null;
2033
+ let p = null;
1975
2034
  if (typeof PerformanceObserver < "u") {
1976
- h = new PerformanceObserver((w) => {
2035
+ p = new PerformanceObserver((w) => {
1977
2036
  for (const y of w.getEntries()) {
1978
2037
  const u = y;
1979
- if (u.initiatorType === "fetch" || u.initiatorType === "xmlhttprequest" || q(u.name))
2038
+ if (u.initiatorType === "fetch" || u.initiatorType === "xmlhttprequest" || B(u.name))
1980
2039
  continue;
1981
2040
  const d = performance.timeOrigin + u.startTime;
1982
2041
  e({
1983
- requestId: Ne("resource"),
1984
- url: P(u.name, Ue),
2042
+ requestId: Oe("resource"),
2043
+ url: U(u.name, Pe),
1985
2044
  method: "GET",
1986
2045
  resourceType: "resource",
1987
2046
  responseStatus: u.responseStatus,
@@ -1991,15 +2050,15 @@ function tn() {
1991
2050
  }
1992
2051
  });
1993
2052
  try {
1994
- h.observe({ type: "resource", buffered: !0 });
2053
+ p.observe({ type: "resource", buffered: !0 });
1995
2054
  } catch {
1996
- h.disconnect(), h = null;
2055
+ p.disconnect(), p = null;
1997
2056
  }
1998
2057
  }
1999
- const p = {
2058
+ const h = {
2000
2059
  subscribers: t,
2001
2060
  destroy: () => {
2002
- h?.disconnect();
2061
+ p?.disconnect();
2003
2062
  try {
2004
2063
  window.fetch === o && (window.fetch = s);
2005
2064
  } catch {
@@ -2018,7 +2077,7 @@ function tn() {
2018
2077
  }
2019
2078
  }
2020
2079
  };
2021
- return window.__plunoProductAgentNetworkCapture = p, p;
2080
+ return window.__plunoProductAgentNetworkCapture = h, h;
2022
2081
  }
2023
2082
  function M(t, e, s) {
2024
2083
  if (typeof window > "u")
@@ -2035,10 +2094,10 @@ function Tt(t) {
2035
2094
  const e = typeof t == "function" ? t() : t;
2036
2095
  return e && Object.keys(e).length > 0 ? e : void 0;
2037
2096
  }
2038
- function sn(t) {
2097
+ function rn(t) {
2039
2098
  return t.type === "conversation.state" || t.type === "session.updated" || t.type === "session.item" || t.type === "chat.assistant_delta" || t.type === "chat.assistant_done" || t.type === "tool.call";
2040
2099
  }
2041
- function nn(t) {
2100
+ function on(t) {
2042
2101
  return t.type === "run.steered" || t.type === "run.ack" || t.type === "conversation.state" || t.type === "session.updated" || t.type === "session.item" || t.type === "chat.assistant_delta" || t.type === "chat.assistant_done" || t.type === "tool.call" || t.type === "tool.status" || t.type === "error" && typeof t.requestId != "string";
2043
2102
  }
2044
2103
  function De(t) {
@@ -2056,31 +2115,31 @@ function De(t) {
2056
2115
  }
2057
2116
  return null;
2058
2117
  }
2059
- const rn = 5e3, on = 12e4;
2060
- function an() {
2118
+ const an = 5e3, ln = 12e4;
2119
+ function cn() {
2061
2120
  const t = [
2062
- cn(),
2063
- ln()
2121
+ dn(),
2122
+ un()
2064
2123
  ].filter((e) => typeof e == "function");
2065
2124
  return () => {
2066
2125
  for (const e of t.reverse())
2067
2126
  e();
2068
2127
  };
2069
2128
  }
2070
- function ln() {
2071
- return Ut(globalThis, "getPageSnapshot", async () => Ye());
2129
+ function un() {
2130
+ return Pt(globalThis, "getPageSnapshot", async () => Ye());
2072
2131
  }
2073
- function cn() {
2074
- return Ut(globalThis, "pageImages", {
2075
- inspectImage: async (e, s) => await un(e, s)
2132
+ function dn() {
2133
+ return Pt(globalThis, "pageImages", {
2134
+ inspectImage: async (e, s) => await pn(e, s)
2076
2135
  });
2077
2136
  }
2078
- async function un(t, e = {}) {
2079
- const s = gn(e.name), n = await dn(t);
2137
+ async function pn(t, e = {}) {
2138
+ const s = mn(e.name), n = await hn(t);
2080
2139
  return n.ok ? n.sizeBytes > 8 * 1024 * 1024 ? {
2081
2140
  type: "pluno.pageImages.inspectImage",
2082
2141
  imageAttached: !1,
2083
- imageAttachmentError: Ot
2142
+ imageAttachmentError: Nt
2084
2143
  } : {
2085
2144
  type: "pluno.pageImages.inspectImage",
2086
2145
  imageAttached: !0,
@@ -2094,15 +2153,15 @@ async function un(t, e = {}) {
2094
2153
  imageAttachmentError: n.error
2095
2154
  };
2096
2155
  }
2097
- async function dn(t) {
2098
- return t instanceof Blob ? t.type.startsWith("image/") ? t.size === 0 ? { ok: !1, error: "Page image is empty." } : t.size > 8 * 1024 * 1024 ? { ok: !1, error: Ot } : {
2156
+ async function hn(t) {
2157
+ return t instanceof Blob ? t.type.startsWith("image/") ? t.size === 0 ? { ok: !1, error: "Page image is empty." } : t.size > 8 * 1024 * 1024 ? { ok: !1, error: Nt } : {
2099
2158
  ok: !0,
2100
2159
  mimeType: t.type,
2101
2160
  sizeBytes: t.size,
2102
- dataUrl: await mn(t)
2103
- } : { ok: !1, error: "Page image must be an image Blob or complete data:image/* URL." } : typeof t != "string" ? { ok: !1, error: "Page image must be an image Blob or complete data:image/* URL." } : hn(t);
2161
+ dataUrl: await In(t)
2162
+ } : { ok: !1, error: "Page image must be an image Blob or complete data:image/* URL." } : typeof t != "string" ? { ok: !1, error: "Page image must be an image Blob or complete data:image/* URL." } : gn(t);
2104
2163
  }
2105
- function hn(t) {
2164
+ function gn(t) {
2106
2165
  if (!t.startsWith("data:") || !t.includes(","))
2107
2166
  return { ok: !1, error: "Page image must be a complete data:image/* URL, not bare base64." };
2108
2167
  const [e, s] = t.slice(5).split(",", 2), n = e.split(";").map((a) => a.trim()).filter(Boolean), r = n[0] ?? "";
@@ -2113,7 +2172,7 @@ function hn(t) {
2113
2172
  const i = s.replace(/[ \t\r\n\f]+/g, "");
2114
2173
  if (!/^[A-Za-z0-9+/]*={0,2}$/.test(i))
2115
2174
  return { ok: !1, error: "Page image data URL has invalid base64." };
2116
- const o = pn(i);
2175
+ const o = fn(i);
2117
2176
  return o === null ? { ok: !1, error: "Page image data URL has invalid base64." } : o === 0 ? { ok: !1, error: "Page image is empty." } : {
2118
2177
  ok: !0,
2119
2178
  mimeType: r,
@@ -2121,22 +2180,22 @@ function hn(t) {
2121
2180
  dataUrl: `data:${r};base64,${i}`
2122
2181
  };
2123
2182
  }
2124
- function pn(t) {
2183
+ function fn(t) {
2125
2184
  if (t.length === 0 || t.length % 4 !== 0)
2126
2185
  return null;
2127
2186
  const e = t.length - t.replace(/=+$/, "").length;
2128
2187
  return e > 2 ? null : t.length / 4 * 3 - e;
2129
2188
  }
2130
- function gn(t) {
2189
+ function mn(t) {
2131
2190
  return (typeof t == "string" ? t.trim() : "") || "Page image";
2132
2191
  }
2133
- function fn(t) {
2192
+ function yn(t) {
2134
2193
  try {
2135
2194
  t();
2136
2195
  } catch {
2137
2196
  }
2138
2197
  }
2139
- function mn(t) {
2198
+ function In(t) {
2140
2199
  return new Promise((e, s) => {
2141
2200
  const n = new FileReader();
2142
2201
  n.onload = () => {
@@ -2150,27 +2209,27 @@ function mn(t) {
2150
2209
  }
2151
2210
  async function wt(t, e) {
2152
2211
  const s = Object.getPrototypeOf(async function() {
2153
- }).constructor, n = t.timeoutMs ?? rn, r = Date.now(), i = [];
2212
+ }).constructor, n = t.timeoutMs ?? an, r = Date.now(), i = [];
2154
2213
  let o;
2155
2214
  const a = {
2156
2215
  log: console.log,
2157
2216
  info: console.info,
2158
2217
  warn: console.warn,
2159
2218
  error: console.error
2160
- }, l = (c) => (...h) => {
2161
- i.push({ level: c, args: h }), a[c](...h);
2219
+ }, l = (c) => (...p) => {
2220
+ i.push({ level: c, args: p }), a[c](...p);
2162
2221
  };
2163
2222
  console.log = l("log"), console.info = l("info"), console.warn = l("warn"), console.error = l("error");
2164
2223
  try {
2165
- const c = /* @__PURE__ */ Symbol("execute_code_timeout"), h = await Promise.race([
2224
+ const c = /* @__PURE__ */ Symbol("execute_code_timeout"), p = await Promise.race([
2166
2225
  new s("sandboxFiles", t.javascript)(e?.value),
2167
- new Promise((p) => {
2168
- o = window.setTimeout(() => p(c), n);
2226
+ new Promise((h) => {
2227
+ o = window.setTimeout(() => h(c), n);
2169
2228
  })
2170
2229
  ]);
2171
- return h === c ? In(n) : {
2230
+ return p === c ? wn(n) : {
2172
2231
  ok: !0,
2173
- result: h,
2232
+ result: p,
2174
2233
  console: i,
2175
2234
  metadata: {
2176
2235
  durationMs: Date.now() - r,
@@ -2197,7 +2256,7 @@ async function wt(t, e) {
2197
2256
  e?.deactivate(), o !== void 0 && window.clearTimeout(o), console.log = a.log, console.info = a.info, console.warn = a.warn, console.error = a.error;
2198
2257
  }
2199
2258
  }
2200
- function yn(t, e) {
2259
+ function Tn(t, e) {
2201
2260
  if (!t || typeof t != "object")
2202
2261
  return;
2203
2262
  const s = t.sandboxFilesToken;
@@ -2207,20 +2266,20 @@ function yn(t, e) {
2207
2266
  const r = () => {
2208
2267
  if (!n)
2209
2268
  throw new Error("sandboxFiles is only available during browser-code execution");
2210
- }, i = async (a, l) => await Cs(`${e.replace(/\/$/, "")}${a}`, l);
2269
+ }, i = async (a, l) => await bs(`${e.replace(/\/$/, "")}${a}`, l);
2211
2270
  return {
2212
2271
  value: Object.freeze({
2213
2272
  upload: async (a) => {
2214
2273
  if (r(), !(a instanceof Blob))
2215
2274
  throw new TypeError("sandboxFiles.upload expects a File or Blob");
2216
- const l = a instanceof File && a.name ? a.name : "file", c = `?name=${encodeURIComponent(l)}&size_bytes=${a.size}`, h = await i(`/api/product-agent/attachments/sandbox-files${c}`, {
2275
+ const l = a instanceof File && a.name ? a.name : "file", c = `?name=${encodeURIComponent(l)}&size_bytes=${a.size}`, p = await i(`/api/product-agent/attachments/sandbox-files${c}`, {
2217
2276
  method: "PUT",
2218
2277
  headers: { Authorization: `Bearer ${s}` },
2219
2278
  body: a
2220
2279
  });
2221
- if (!h.ok)
2222
- throw new Error(`sandboxFiles.upload failed (${h.status})`);
2223
- return String((await h.json()).path);
2280
+ if (!p.ok)
2281
+ throw new Error(`sandboxFiles.upload failed (${p.status})`);
2282
+ return String((await p.json()).path);
2224
2283
  },
2225
2284
  download: async (a) => {
2226
2285
  r();
@@ -2230,8 +2289,8 @@ function yn(t, e) {
2230
2289
  );
2231
2290
  if (!l.ok)
2232
2291
  throw new Error(`sandboxFiles.download failed (${l.status})`);
2233
- const c = await l.blob(), p = (l.headers.get("content-disposition") ?? "").match(/filename="([^"]+)"/i)?.[1];
2234
- return new File([c], p || a.split("/").pop() || "file", {
2292
+ const c = await l.blob(), h = (l.headers.get("content-disposition") ?? "").match(/filename="([^"]+)"/i)?.[1];
2293
+ return new File([c], h || a.split("/").pop() || "file", {
2235
2294
  type: c.type
2236
2295
  });
2237
2296
  }
@@ -2241,7 +2300,7 @@ function yn(t, e) {
2241
2300
  }
2242
2301
  };
2243
2302
  }
2244
- function In(t) {
2303
+ function wn(t) {
2245
2304
  return {
2246
2305
  ok: !1,
2247
2306
  exception: {
@@ -2255,10 +2314,10 @@ function In(t) {
2255
2314
  }
2256
2315
  };
2257
2316
  }
2258
- function Tn(t) {
2317
+ function Sn(t) {
2259
2318
  return t.replace(/\/+$/, "");
2260
2319
  }
2261
- function wn(t) {
2320
+ function Mn(t) {
2262
2321
  const e = {
2263
2322
  sidepanel: "extension_sidepanel",
2264
2323
  browser_extension_page_ui: "extension_widget",
@@ -2270,18 +2329,18 @@ function wn(t) {
2270
2329
  };
2271
2330
  return t && t in e ? e[t] : t ?? "embedded_custom_ui";
2272
2331
  }
2273
- function Sn(t) {
2332
+ function An(t) {
2274
2333
  return t === "pluno" ? "scheduled_continuation" : t ?? "user";
2275
2334
  }
2276
- function Mn(t, e = location.origin) {
2335
+ function Rn(t, e = location.origin) {
2277
2336
  return /origin (?:is not allowed|does not match browser origin)/i.test(t) ? `Pluno widget blocked on ${e}: this domain is not allowed. Add ${e} in Pluno under Integration > Domains.` : null;
2278
2337
  }
2279
- function An(t) {
2338
+ function En(t) {
2280
2339
  const e = new URL("/api/product-agent/embed/ws", t);
2281
2340
  return e.protocol = e.protocol === "https:" ? "wss:" : "ws:", e.toString();
2282
2341
  }
2283
2342
  function C() {
2284
- const t = Ht();
2343
+ const t = Wt();
2285
2344
  return {
2286
2345
  url: location.href,
2287
2346
  title: document.title,
@@ -2289,19 +2348,19 @@ function C() {
2289
2348
  ...t ? { plunoProductAgentUi: t } : {}
2290
2349
  };
2291
2350
  }
2292
- function Rn() {
2351
+ function Cn() {
2293
2352
  return {
2294
2353
  pageUrl: location.href,
2295
2354
  pageTitle: document.title,
2296
2355
  htmlContent: Ye()
2297
2356
  };
2298
2357
  }
2299
- function En(t) {
2300
- return ce.add(t), ne || (ne = bn()), () => {
2358
+ function bn(t) {
2359
+ return ce.add(t), ne || (ne = _n()), () => {
2301
2360
  ce.delete(t), ce.size === 0 && (ne?.(), ne = null);
2302
2361
  };
2303
2362
  }
2304
- function bn() {
2363
+ function _n() {
2305
2364
  const t = () => {
2306
2365
  for (const i of Array.from(ce))
2307
2366
  i();
@@ -2317,13 +2376,13 @@ function bn() {
2317
2376
  };
2318
2377
  }
2319
2378
  function re() {
2320
- return Ht()?.surface === "browser_extension_sdk_preview";
2379
+ return Wt()?.surface === "browser_extension_sdk_preview";
2321
2380
  }
2322
2381
  function Ye() {
2323
2382
  if (!document.body)
2324
2383
  return "";
2325
2384
  const t = [], e = [], s = (d, g) => {
2326
- const m = W(g);
2385
+ const m = $(g);
2327
2386
  !m || e.includes(m) || (t.push([d, m]), e.push(m));
2328
2387
  };
2329
2388
  s("Selected text", window.getSelection()?.toString() ?? "");
@@ -2332,22 +2391,22 @@ function Ye() {
2332
2391
  );
2333
2392
  for (const d of r.slice(0, 3))
2334
2393
  s("Active overlay", ve(V(d), e));
2335
- const i = Cn(), o = i ? ve(V(i), e) : "";
2394
+ const i = kn(), o = i ? ve(V(i), e) : "";
2336
2395
  s("Main page content", o), s("Additional visible page text", ve(V(document.body), e));
2337
2396
  const a = t.map(([d, g]) => `${d}:
2338
2397
  ${g}`).join(`
2339
2398
 
2340
- `).trim().slice(0, 12e3), l = _n(r, i).trim(), c = `Simplified DOM outline:
2341
- `, h = `
2399
+ `).trim().slice(0, 12e3), l = Pn(r, i).trim(), c = `Simplified DOM outline:
2400
+ `, p = `
2342
2401
 
2343
2402
  Visible page text:
2344
- `, p = 12e3 - c.length - h.length, w = Math.min(a.length, 7900), y = l.slice(0, p - w), u = a.slice(0, p - y.length);
2345
- return `${c}${y}${h}${u}`;
2403
+ `, h = 12e3 - c.length - p.length, w = Math.min(a.length, 7900), y = l.slice(0, h - w), u = a.slice(0, h - y.length);
2404
+ return `${c}${y}${p}${u}`;
2346
2405
  }
2347
2406
  function V(t) {
2348
2407
  return t.innerText ?? t.textContent ?? "";
2349
2408
  }
2350
- function W(t) {
2409
+ function $(t) {
2351
2410
  return (t ?? "").replace(/\u00a0/g, " ").replace(/\r\n?/g, `
2352
2411
  `).split(`
2353
2412
  `).map((e) => e.replace(/[ \t]+/g, " ").trim()).join(`
@@ -2356,19 +2415,19 @@ function W(t) {
2356
2415
  `).trim();
2357
2416
  }
2358
2417
  function ve(t, e) {
2359
- let s = W(t);
2418
+ let s = $(t);
2360
2419
  for (const n of e)
2361
2420
  s = s.replace(n, "");
2362
- return W(s);
2421
+ return $(s);
2363
2422
  }
2364
2423
  function Lt(t) {
2365
2424
  const e = window.getComputedStyle(t);
2366
2425
  return e.display !== "none" && e.visibility !== "hidden" && t.getClientRects().length > 0;
2367
2426
  }
2368
- function Cn() {
2427
+ function kn() {
2369
2428
  return Array.from(document.querySelectorAll("main, [role='main'], article")).filter(Lt).sort((t, e) => V(e).length - V(t).length)[0] ?? null;
2370
2429
  }
2371
- function _n(t, e) {
2430
+ function Pn(t, e) {
2372
2431
  const s = /* @__PURE__ */ new Set([
2373
2432
  "main",
2374
2433
  "nav",
@@ -2448,7 +2507,7 @@ function _n(t, e) {
2448
2507
  "data-test",
2449
2508
  "data-qa",
2450
2509
  "data-cy"
2451
- ], c = ["aria-label", "placeholder", "data-testid", "data-test", "data-qa", "data-cy"], { priorityElements: h, priorityTargets: p } = kn(), w = new Set(t);
2510
+ ], c = ["aria-label", "placeholder", "data-testid", "data-test", "data-qa", "data-cy"], { priorityElements: p, priorityTargets: h } = Un(), w = new Set(t);
2452
2511
  e && w.add(e);
2453
2512
  let y = 0;
2454
2513
  const u = (f) => {
@@ -2458,8 +2517,8 @@ function _n(t, e) {
2458
2517
  const R = f.getAttribute("data-testid") || f.getAttribute("data-test") || f.getAttribute("data-qa") || f.getAttribute("data-cy") || "";
2459
2518
  return `${f.tagName.toLowerCase()}|${u(f)}|${R}`;
2460
2519
  }, g = (f, R, F) => {
2461
- const U = (A, me) => {
2462
- const b = A.tagName.toLowerCase(), ye = window.getComputedStyle(A), Z = h.has(A);
2520
+ const P = (A, me) => {
2521
+ const b = A.tagName.toLowerCase(), ye = window.getComputedStyle(A), Z = p.has(A);
2463
2522
  if (y >= 1e3 && !Z || F.has(A) || i.has(b) || A.matches(".pluno-pa-widget-host, [data-pluno-product-agent-widget]") || ye.display === "none" || ye.visibility === "hidden")
2464
2523
  return { lines: [], hasUsefulContent: !1, textPreview: "", containsTextElement: !1 };
2465
2524
  y += 1;
@@ -2471,31 +2530,31 @@ function _n(t, e) {
2471
2530
  const Te = /* @__PURE__ */ new Map(), st = /* @__PURE__ */ new Map();
2472
2531
  for (const I of Ie) {
2473
2532
  const S = d(I), v = st.get(S) ?? 0;
2474
- st.set(S, v + 1), (te.get(S) ?? 0) > 8 && v >= 6 && !h.has(I) && Te.set(S, (Te.get(S) ?? 0) + 1);
2533
+ st.set(S, v + 1), (te.get(S) ?? 0) > 8 && v >= 6 && !p.has(I) && Te.set(S, (Te.get(S) ?? 0) + 1);
2475
2534
  }
2476
2535
  const nt = /* @__PURE__ */ new Map(), rt = /* @__PURE__ */ new Set(), we = [], it = [];
2477
2536
  for (const I of Ie) {
2478
2537
  const S = d(I), v = te.get(S) ?? 0, lt = nt.get(S) ?? 0;
2479
- if (nt.set(S, lt + 1), v > 8 && lt >= 6 && !h.has(I)) {
2538
+ if (nt.set(S, lt + 1), v > 8 && lt >= 6 && !p.has(I)) {
2480
2539
  rt.has(S) || (we.push([`… ${Te.get(S) ?? 0} similar siblings omitted`]), rt.add(S));
2481
2540
  continue;
2482
2541
  }
2483
- const ct = U(I, me);
2542
+ const ct = P(I, me);
2484
2543
  it.push(ct), we.push(ct.lines);
2485
2544
  }
2486
2545
  const Se = [];
2487
2546
  if (A.shadowRoot)
2488
2547
  for (const I of Array.from(A.shadowRoot.children))
2489
- I instanceof HTMLElement && Se.push(U(I, me + 1));
2490
- const se = [...it, ...Se], Me = ee.length > 0 || is || se.some((I) => I.hasUsefulContent), ot = W(
2548
+ I instanceof HTMLElement && Se.push(P(I, me + 1));
2549
+ const se = [...it, ...Se], Me = ee.length > 0 || is || se.some((I) => I.hasUsefulContent), ot = $(
2491
2550
  [ee, ...se.map((I) => I.textPreview)].filter(Boolean).join(" ")
2492
- ).slice(0, 180), os = A.hasAttribute("contenteditable") && (ee.length > 0 || !A.querySelector("[contenteditable]")), at = c.some((I) => A.hasAttribute(I)) || !!tt || os, Ae = (A.getClientRects().length > 0 || ye.display === "contents") && (s.has(b) || at || Z) && (Me || Z) && (!r.has(b) || Me || at || Z), Re = Ae ? 1 : 0, $ = [];
2551
+ ).slice(0, 180), os = A.hasAttribute("contenteditable") && (ee.length > 0 || !A.querySelector("[contenteditable]")), at = c.some((I) => A.hasAttribute(I)) || !!tt || os, Ae = (A.getClientRects().length > 0 || ye.display === "contents") && (s.has(b) || at || Z) && (Me || Z) && (!r.has(b) || Me || at || Z), Re = Ae ? 1 : 0, z = [];
2493
2552
  if (Ae) {
2494
2553
  const I = se.some((v) => v.containsTextElement), S = n.has(b) && !I ? ot : ee;
2495
- $.push(qt(A, l, o, S.slice(0, 180)));
2554
+ z.push(qt(A, l, o, S.slice(0, 180)));
2496
2555
  }
2497
2556
  for (const I of we)
2498
- $.push(...ie(I, Re));
2557
+ z.push(...ie(I, Re));
2499
2558
  const Ee = Se.flatMap((I) => I.lines);
2500
2559
  if (Ee.length > 0) {
2501
2560
  const I = Ee.slice(0, 20);
@@ -2503,22 +2562,22 @@ function _n(t, e) {
2503
2562
  const S = b.includes("tooltip") || b.includes("popper") || b.includes("loader");
2504
2563
  if (me < 2 && !S) {
2505
2564
  const v = Ae ? "#shadow-root" : `${b} #shadow-root`;
2506
- $.push(...ie([v, ...ie(I, 1)], Re));
2565
+ z.push(...ie([v, ...ie(I, 1)], Re));
2507
2566
  } else
2508
- $.push(...ie(I, Re));
2567
+ z.push(...ie(I, Re));
2509
2568
  }
2510
2569
  return {
2511
- lines: $,
2570
+ lines: z,
2512
2571
  hasUsefulContent: Me,
2513
2572
  textPreview: ot,
2514
2573
  containsTextElement: n.has(b) || se.some((I) => I.containsTextElement)
2515
2574
  };
2516
2575
  };
2517
- return [`--- ${R} ---`, ...U(f, 0).lines].join(`
2576
+ return [`--- ${R} ---`, ...P(f, 0).lines].join(`
2518
2577
  `);
2519
- }, m = [], T = W(window.getSelection()?.toString() ?? "");
2578
+ }, m = [], T = $(window.getSelection()?.toString() ?? "");
2520
2579
  T && m.push(`--- selected text ---
2521
- ${JSON.stringify(T)}`), p.length > 0 && m.push(Un(p, s, l, o));
2580
+ ${JSON.stringify(T)}`), h.length > 0 && m.push(Dn(h, s, l, o));
2522
2581
  for (const f of t.slice(0, 3))
2523
2582
  m.push(g(f, "active overlay DOM", /* @__PURE__ */ new Set()));
2524
2583
  if (e && m.push(g(e, "main DOM", /* @__PURE__ */ new Set())), document.body) {
@@ -2533,7 +2592,7 @@ function qt(t, e, s, n) {
2533
2592
  const r = t.tagName.toLowerCase();
2534
2593
  let i = r;
2535
2594
  const o = t.getAttribute("id");
2536
- o && Pn(o) && (i += `#${o}`);
2595
+ o && vn(o) && (i += `#${o}`);
2537
2596
  for (const a of e) {
2538
2597
  const l = t.getAttribute(a);
2539
2598
  l && l.length <= 160 && (a !== "role" || !s.has(l)) && (i += `[${a}=${JSON.stringify(l)}]`);
@@ -2546,20 +2605,20 @@ function qt(t, e, s, n) {
2546
2605
  t.hasAttribute(a) && (i += `[${a}]`);
2547
2606
  return `${i}${n ? ` ${JSON.stringify(n)}` : ""}`;
2548
2607
  }
2549
- function kn() {
2608
+ function Un() {
2550
2609
  const t = /* @__PURE__ */ new Set(), e = /* @__PURE__ */ new Map(), s = (a, l) => {
2551
2610
  if (!a)
2552
2611
  return;
2553
2612
  const c = window.getComputedStyle(a);
2554
2613
  if (c.display === "none" || c.visibility === "hidden")
2555
2614
  return;
2556
- const h = e.get(a) ?? /* @__PURE__ */ new Set();
2557
- h.add(l), e.set(a, h);
2558
- let p = a;
2559
- for (; p; ) {
2560
- t.add(p);
2561
- const w = p.getRootNode();
2562
- p = p.parentElement ?? (w instanceof ShadowRoot && w.host instanceof HTMLElement ? w.host : null);
2615
+ const p = e.get(a) ?? /* @__PURE__ */ new Set();
2616
+ p.add(l), e.set(a, p);
2617
+ let h = a;
2618
+ for (; h; ) {
2619
+ t.add(h);
2620
+ const w = h.getRootNode();
2621
+ h = h.parentElement ?? (w instanceof ShadowRoot && w.host instanceof HTMLElement ? w.host : null);
2563
2622
  }
2564
2623
  };
2565
2624
  let n = document.activeElement instanceof HTMLElement ? document.activeElement : null;
@@ -2578,9 +2637,9 @@ function kn() {
2578
2637
  ], o = [document];
2579
2638
  for (let a = 0; a < o.length; a += 1) {
2580
2639
  const l = o[a];
2581
- for (const [c, h] of i)
2582
- for (const p of Array.from(l.querySelectorAll(c)))
2583
- s(p, h);
2640
+ for (const [c, p] of i)
2641
+ for (const h of Array.from(l.querySelectorAll(c)))
2642
+ s(h, p);
2584
2643
  for (const c of Array.from(l.querySelectorAll("*")))
2585
2644
  c.shadowRoot && o.push(c.shadowRoot);
2586
2645
  }
@@ -2589,22 +2648,22 @@ function kn() {
2589
2648
  priorityTargets: Array.from(e, ([a, l]) => ({ element: a, labels: Array.from(l) }))
2590
2649
  };
2591
2650
  }
2592
- function Un(t, e, s, n) {
2651
+ function Dn(t, e, s, n) {
2593
2652
  const r = ["--- active/current elements ---"];
2594
2653
  for (const i of t) {
2595
2654
  const o = [];
2596
2655
  let a = i.element;
2597
2656
  for (; a; ) {
2598
- const h = a.tagName.toLowerCase();
2599
- (a === i.element || e.has(h) || a.hasAttribute("id") || a.hasAttribute("role") || a.hasAttribute("aria-label")) && o.unshift(a);
2600
- const p = a.getRootNode();
2601
- a = a.parentElement ?? (p instanceof ShadowRoot && p.host instanceof HTMLElement ? p.host : null);
2657
+ const p = a.tagName.toLowerCase();
2658
+ (a === i.element || e.has(p) || a.hasAttribute("id") || a.hasAttribute("role") || a.hasAttribute("aria-label")) && o.unshift(a);
2659
+ const h = a.getRootNode();
2660
+ a = a.parentElement ?? (h instanceof ShadowRoot && h.host instanceof HTMLElement ? h.host : null);
2602
2661
  }
2603
- const l = o.length > 6 ? [o[0], ...o.slice(-5)] : o, c = l.map((h, p) => qt(
2604
- h,
2662
+ const l = o.length > 6 ? [o[0], ...o.slice(-5)] : o, c = l.map((p, h) => qt(
2663
+ p,
2605
2664
  s,
2606
2665
  n,
2607
- p === l.length - 1 ? Bt(h).slice(0, 180) : ""
2666
+ h === l.length - 1 ? Bt(p).slice(0, 180) : ""
2608
2667
  ));
2609
2668
  o.length > l.length && c.splice(1, 0, "…"), r.push(`${i.labels.join(", ")}: ${c.join(" > ")}`);
2610
2669
  }
@@ -2621,14 +2680,14 @@ function ie(t, e) {
2621
2680
  return t.map((n) => `${s}${n}`);
2622
2681
  }
2623
2682
  function Bt(t) {
2624
- return W(
2683
+ return $(
2625
2684
  Array.from(t.childNodes).filter((e) => e.nodeType === Node.TEXT_NODE).map((e) => e.textContent ?? "").join(" ")
2626
2685
  );
2627
2686
  }
2628
- function Pn(t) {
2687
+ function vn(t) {
2629
2688
  return t.length <= 64 && /^[A-Za-z_][A-Za-z0-9_:.-]*$/.test(t) && !/[a-f0-9]{12,}/i.test(t) && !/:r[0-9a-z]+:/i.test(t);
2630
2689
  }
2631
- function Ht() {
2690
+ function Wt() {
2632
2691
  const t = document.querySelector(ut);
2633
2692
  if (!(t ?? document.querySelector(Le)))
2634
2693
  return;
@@ -2654,13 +2713,13 @@ function Ht() {
2654
2713
  },
2655
2714
  {
2656
2715
  name: "widget_timeline",
2657
- selector: Us,
2716
+ selector: Ps,
2658
2717
  description: "Finds Pluno's chat timeline inside the widget host shadow root."
2659
2718
  }
2660
2719
  ]
2661
2720
  };
2662
2721
  }
2663
- function Dn(t) {
2722
+ function Nn(t) {
2664
2723
  try {
2665
2724
  const e = JSON.parse(t);
2666
2725
  return e && typeof e == "object" ? e : { type: "error", message: "Invalid server event" };
@@ -2668,7 +2727,7 @@ function Dn(t) {
2668
2727
  return { type: "error", message: "Invalid server event" };
2669
2728
  }
2670
2729
  }
2671
- function vn(t) {
2730
+ function On(t) {
2672
2731
  if (typeof t != "string")
2673
2732
  return null;
2674
2733
  try {
@@ -2684,10 +2743,10 @@ function Mt(t, e) {
2684
2743
  const s = t[e];
2685
2744
  return Array.isArray(s) ? s.filter((n) => typeof n == "string" && n.trim().length > 0) : [];
2686
2745
  }
2687
- function On(t) {
2746
+ function xn(t) {
2688
2747
  return Array.isArray(t) ? t.filter((e) => typeof e == "string" && e.trim().length > 0) : [];
2689
2748
  }
2690
- function Nn(t) {
2749
+ function Ln(t) {
2691
2750
  if (!t || typeof t != "object")
2692
2751
  return null;
2693
2752
  const e = t, s = e.appearance, n = s && typeof s == "object" ? s : e, 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;
@@ -2698,13 +2757,13 @@ function Nn(t) {
2698
2757
  ...a !== null ? { scribbleStyle: a } : {}
2699
2758
  };
2700
2759
  }
2701
- function xn(t) {
2760
+ function qn(t) {
2702
2761
  if (!t || typeof t != "object")
2703
2762
  return null;
2704
2763
  const e = t.javascript;
2705
2764
  return typeof e != "string" || !e.trim() ? null : { javascript: e };
2706
2765
  }
2707
- function Ln(t, e) {
2766
+ function Bn(t, e) {
2708
2767
  return e ? t && typeof t == "object" ? {
2709
2768
  ...t,
2710
2769
  helperError: e
@@ -2714,23 +2773,23 @@ function Ln(t, e) {
2714
2773
  helperError: e
2715
2774
  } : t;
2716
2775
  }
2717
- function qn(t) {
2776
+ function Wn(t) {
2718
2777
  if (!t || typeof t != "object")
2719
2778
  return t;
2720
2779
  const e = t;
2721
2780
  return typeof e.exception?.message == "string" ? e.exception.message : typeof e.error == "string" ? e.error : t;
2722
2781
  }
2723
- function Bn() {
2782
+ function Hn() {
2724
2783
  const t = "pluno.productAgent.clientId", e = window.localStorage.getItem(t);
2725
2784
  if (e)
2726
2785
  return e;
2727
2786
  const s = crypto.randomUUID();
2728
2787
  return window.localStorage.setItem(t, s), s;
2729
2788
  }
2730
- function X() {
2789
+ function L() {
2731
2790
  return crypto.randomUUID();
2732
2791
  }
2733
- function Hn(t) {
2792
+ function $n(t) {
2734
2793
  if (!t || typeof t != "object")
2735
2794
  return null;
2736
2795
  const e = t, s = typeof e.id == "string" ? e.id : null;
@@ -2741,12 +2800,12 @@ function Hn(t) {
2741
2800
  avatarUrl: typeof e.avatarUrl == "string" ? e.avatarUrl : null
2742
2801
  } : null;
2743
2802
  }
2744
- function Wn(t, e) {
2745
- return Array.isArray(t) ? $e(
2746
- t.map((s) => Wt(s, e)).filter((s) => s !== null)
2803
+ function jn(t, e) {
2804
+ return Array.isArray(t) ? Fe(
2805
+ t.map((s) => Ht(s, e)).filter((s) => s !== null)
2747
2806
  ) : [];
2748
2807
  }
2749
- function jn(t) {
2808
+ function Fn(t) {
2750
2809
  return Array.isArray(t) ? t.flatMap((e) => {
2751
2810
  if (!e || typeof e != "object")
2752
2811
  return [];
@@ -2767,7 +2826,7 @@ function jn(t) {
2767
2826
  ];
2768
2827
  }) : [];
2769
2828
  }
2770
- function Wt(t, e) {
2829
+ function Ht(t, e) {
2771
2830
  if (!t || typeof t != "object")
2772
2831
  return null;
2773
2832
  const s = t, n = s.data;
@@ -2782,12 +2841,12 @@ function Wt(t, e) {
2782
2841
  role: i,
2783
2842
  ...r.phase === "commentary" || r.phase === "final_answer" ? { phase: r.phase } : {},
2784
2843
  content: gs(
2785
- Vn(r.content),
2844
+ Yn(r.content),
2786
2845
  e
2787
2846
  ),
2788
2847
  createdAt: typeof s.createdAt == "string" ? s.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
2789
- ...O(r) !== null ? { causalSequence: O(r) } : {},
2790
- respondsToUserMessageId: N(r) ?? void 0,
2848
+ ...N(r) !== null ? { causalSequence: N(r) } : {},
2849
+ respondsToUserMessageId: O(r) ?? void 0,
2791
2850
  ..._(r) ? { runId: _(r) } : {},
2792
2851
  attachments: Xt(r.attachments, e)
2793
2852
  };
@@ -2800,54 +2859,54 @@ function Wt(t, e) {
2800
2859
  }), o;
2801
2860
  }
2802
2861
  if (r.type === "function_call_output") {
2803
- const i = bs(r.output);
2862
+ const i = Cs(r.output);
2804
2863
  if (i)
2805
2864
  return {
2806
2865
  id: String(s.id ?? crypto.randomUUID()),
2807
2866
  role: "tool",
2808
2867
  content: "",
2809
2868
  createdAt: typeof s.createdAt == "string" ? s.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
2810
- respondsToUserMessageId: N(r) ?? void 0,
2869
+ respondsToUserMessageId: O(r) ?? void 0,
2811
2870
  ..._(r) ? { runId: _(r) } : {},
2812
2871
  dataType: "scheduled_check_in",
2813
2872
  toolName: Dt,
2814
- callId: Oe(r) ?? void 0,
2873
+ callId: Ne(r) ?? void 0,
2815
2874
  scheduledCheckInAt: i
2816
2875
  };
2817
- const o = $n(r.output);
2876
+ const o = Kn(r.output);
2818
2877
  return o ? {
2819
2878
  id: String(s.id ?? crypto.randomUUID()),
2820
2879
  role: "tool",
2821
2880
  content: `Connect ${o.appName} to continue`,
2822
2881
  createdAt: typeof s.createdAt == "string" ? s.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
2823
- ...O(r) !== null ? { causalSequence: O(r) } : {},
2824
- respondsToUserMessageId: N(r) ?? void 0,
2882
+ ...N(r) !== null ? { causalSequence: N(r) } : {},
2883
+ respondsToUserMessageId: O(r) ?? void 0,
2825
2884
  ..._(r) ? { runId: _(r) } : {},
2826
2885
  dataType: "function_call_output",
2827
2886
  toolName: "authenticate_pipedream_app",
2828
- callId: Oe(r) ?? void 0,
2887
+ callId: Ne(r) ?? void 0,
2829
2888
  integrationAuthRequest: o
2830
2889
  } : null;
2831
2890
  }
2832
2891
  return r.type === "function_call" || r.type === "tool_call" || r.type === "web_search_call" || r.type === "mcp_call" || r.type === "tab_lifecycle_decision" ? {
2833
2892
  id: String(s.id ?? crypto.randomUUID()),
2834
2893
  role: "tool",
2835
- content: r.type === "mcp_call" ? Fn(r) : Kn(r),
2894
+ content: r.type === "mcp_call" ? zn(r) : Xn(r),
2836
2895
  createdAt: typeof s.createdAt == "string" ? s.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
2837
- ...O(r) !== null ? { causalSequence: O(r) } : {},
2838
- respondsToUserMessageId: N(r) ?? void 0,
2896
+ ...N(r) !== null ? { causalSequence: N(r) } : {},
2897
+ respondsToUserMessageId: O(r) ?? void 0,
2839
2898
  ..._(r) ? { runId: _(r) } : {},
2840
2899
  dataType: String(r.type),
2841
2900
  toolName: r.type === "tab_lifecycle_decision" ? "tab_lifecycle_decision" : typeof r.name == "string" ? r.name : void 0,
2842
- callId: Oe(r) ?? void 0,
2901
+ callId: Ne(r) ?? void 0,
2843
2902
  loading: r.localExecutionStatus === "queued" || r.localExecutionStatus === "running" ? !0 : typeof r.localExecutionStatus == "string" ? !1 : void 0
2844
2903
  } : r.type === "run_status" || r.type === "run_error" ? r.type === "run_error" && r.stage === "tool_execution" ? null : {
2845
2904
  id: String(s.id ?? crypto.randomUUID()),
2846
2905
  role: "system",
2847
- content: zn(r),
2906
+ content: Gn(r),
2848
2907
  createdAt: typeof s.createdAt == "string" ? s.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
2849
- ...O(r) !== null ? { causalSequence: O(r) } : {},
2850
- respondsToUserMessageId: N(r) ?? void 0,
2908
+ ...N(r) !== null ? { causalSequence: N(r) } : {},
2909
+ respondsToUserMessageId: O(r) ?? void 0,
2851
2910
  ..._(r) ? { runId: _(r) } : {},
2852
2911
  dataType: String(r.type),
2853
2912
  loading: r.type === "run_status" && (r.status === "running" || r.status === "retrying"),
@@ -2856,11 +2915,11 @@ function Wt(t, e) {
2856
2915
  ...typeof r.securitySettingsUrl == "string" ? { securitySettingsUrl: r.securitySettingsUrl } : {}
2857
2916
  } : null;
2858
2917
  }
2859
- function Fn(t) {
2918
+ function zn(t) {
2860
2919
  const s = (typeof t.server_label == "string" ? t.server_label : "").replace(/^pipedream_/, "").split(/[_-]+/).filter(Boolean).map((n) => `${n.charAt(0).toUpperCase()}${n.slice(1)}`).join(" ");
2861
2920
  return s ? `🔌 Using ${s}` : "🔌 Using connected integration";
2862
2921
  }
2863
- function $n(t) {
2922
+ function Kn(t) {
2864
2923
  if (typeof t != "string")
2865
2924
  return null;
2866
2925
  try {
@@ -2877,10 +2936,10 @@ function $n(t) {
2877
2936
  return null;
2878
2937
  }
2879
2938
  }
2880
- function zn(t) {
2939
+ function Gn(t) {
2881
2940
  return t.type === "run_status" && t.status === "stopped" ? "Run stopped by user" : t.type === "run_status" && t.status === "steered" ? "Steered" : typeof t.message == "string" && t.message.trim().length > 0 ? t.message.replace(/Product Agent/g, "Pluno") : t.type === "run_status" && t.status === "interrupted" ? "Pluno was interrupted before it could finish this message." : "Pluno run status changed.";
2882
2941
  }
2883
- function Kn(t) {
2942
+ function Xn(t) {
2884
2943
  if (t.type === "web_search_call") {
2885
2944
  const e = t.action;
2886
2945
  if (e && typeof e == "object") {
@@ -2892,26 +2951,26 @@ function Kn(t) {
2892
2951
  }
2893
2952
  return "🔎 Searching the web";
2894
2953
  }
2895
- return Gn(t);
2954
+ return Vn(t);
2896
2955
  }
2897
- function Gn(t) {
2956
+ function Vn(t) {
2898
2957
  if (typeof t.summary == "string" && t.summary.trim().length > 0)
2899
- return B(t.summary);
2958
+ return W(t.summary);
2900
2959
  if (typeof t.arguments == "string")
2901
2960
  try {
2902
2961
  const e = JSON.parse(t.arguments);
2903
2962
  if (typeof e.summary == "string" && e.summary.trim().length > 0)
2904
- return B(e.summary);
2963
+ return W(e.summary);
2905
2964
  } catch {
2906
- return typeof t.name == "string" && t.name.trim().length > 0 ? B(t.name) : "🛠️ Run tool";
2965
+ return typeof t.name == "string" && t.name.trim().length > 0 ? W(t.name) : "🛠️ Run tool";
2907
2966
  }
2908
- return typeof t.name == "string" && t.name.trim().length > 0 ? B(t.name) : "🛠️ Run tool";
2967
+ return typeof t.name == "string" && t.name.trim().length > 0 ? W(t.name) : "🛠️ Run tool";
2909
2968
  }
2910
- function B(t) {
2969
+ function W(t) {
2911
2970
  const e = t.trim() || "Run tool", s = e.codePointAt(0) ?? 0;
2912
2971
  return s >= 126976 && s <= 129791 || s >= 9728 && s <= 10175 || s >= 127462 && s <= 127487 ? e : `🛠️ ${e}`;
2913
2972
  }
2914
- function Xn(t) {
2973
+ function Jn(t) {
2915
2974
  if (t == null)
2916
2975
  return t;
2917
2976
  if (typeof t != "object")
@@ -2926,14 +2985,14 @@ function Xn(t) {
2926
2985
  runId: typeof e.runId == "string" ? e.runId : null
2927
2986
  };
2928
2987
  }
2929
- function Oe(t) {
2988
+ function Ne(t) {
2930
2989
  const e = t.callId ?? t.call_id;
2931
2990
  return typeof e == "string" && e ? e : null;
2932
2991
  }
2933
- function O(t) {
2992
+ function N(t) {
2934
2993
  return typeof t.causalSequence == "number" && Number.isSafeInteger(t.causalSequence) ? t.causalSequence : null;
2935
2994
  }
2936
- function Vn(t) {
2995
+ function Yn(t) {
2937
2996
  return typeof t == "string" ? t : Array.isArray(t) ? t.map((e) => {
2938
2997
  if (!e || typeof e != "object")
2939
2998
  return "";
@@ -2942,30 +3001,30 @@ function Vn(t) {
2942
3001
  }).filter(Boolean).join("") : "";
2943
3002
  }
2944
3003
  function Be(t, e) {
2945
- const s = Ft(t, e), n = sr(
2946
- Jn(
2947
- or(t, e),
3004
+ const s = jt(t, e), n = rr(
3005
+ Qn(
3006
+ lr(t, e),
2948
3007
  s
2949
3008
  ),
2950
3009
  s
2951
3010
  ), r = n.findIndex((o) => o.id === s.id);
2952
3011
  if (r === -1)
2953
- return $e(
3012
+ return Fe(
2954
3013
  [...n, s]
2955
3014
  );
2956
3015
  const i = [...n];
2957
- return i[r] = s, $e(i);
3016
+ return i[r] = s, Fe(i);
2958
3017
  }
2959
- function Jn(t, e) {
3018
+ function Qn(t, e) {
2960
3019
  const s = e.assistantDraftItemId;
2961
3020
  return s ? t.map(
2962
3021
  (n) => n.dataType === "assistant_draft" && n.id === s ? e : n
2963
3022
  ) : t;
2964
3023
  }
2965
- function Yn(t, e, s) {
3024
+ function Zn(t, e, s) {
2966
3025
  return e !== null ? t.respondsToUserMessageId === e : s !== null && t.runId === s;
2967
3026
  }
2968
- function Qn(t, e, s, n) {
3027
+ function er(t, e, s, n) {
2969
3028
  if (s === null) return t;
2970
3029
  let r = -1;
2971
3030
  for (let o = t.length - 1; o >= 0; o -= 1) {
@@ -2982,7 +3041,7 @@ function Qn(t, e, s, n) {
2982
3041
  respondsToUserMessageId: s
2983
3042
  }, i;
2984
3043
  }
2985
- function Zn(t, e) {
3044
+ function tr(t, e) {
2986
3045
  const s = t.findIndex(
2987
3046
  (r) => !r.id.startsWith("transient-activity:") && r.callId === e.callId
2988
3047
  );
@@ -2999,19 +3058,19 @@ function Zn(t, e) {
2999
3058
  ...n[s].runId ? {} : { runId: e.runId }
3000
3059
  }, n;
3001
3060
  }
3002
- function er(t, e, s) {
3061
+ function sr(t, e, s) {
3003
3062
  let n = !1;
3004
3063
  const r = t.map((i) => i.callId !== e || i.loading === s ? i : (n = !0, { ...i, loading: s }));
3005
3064
  return n ? r : t;
3006
3065
  }
3007
- function tr(t) {
3066
+ function nr(t) {
3008
3067
  if (t.hiddenFromTranscript === !0)
3009
3068
  return null;
3010
3069
  const e = typeof t.callId == "string" ? t.callId : null, s = typeof t.toolName == "string" ? t.toolName : null;
3011
3070
  return !e || !s ? null : {
3012
3071
  id: `transient-activity:${e}`,
3013
3072
  role: "tool",
3014
- content: B(
3073
+ content: W(
3015
3074
  typeof t.summary == "string" ? t.summary : "Running browser tool"
3016
3075
  ),
3017
3076
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
@@ -3024,7 +3083,7 @@ function tr(t) {
3024
3083
  loading: !0
3025
3084
  };
3026
3085
  }
3027
- function sr(t, e) {
3086
+ function rr(t, e) {
3028
3087
  if (e.id.startsWith("transient-activity:"))
3029
3088
  return t;
3030
3089
  const s = e.toolName === "tab_lifecycle";
@@ -3033,16 +3092,16 @@ function sr(t, e) {
3033
3092
  const n = (i) => i.id === `transient-activity:${e.callId}` && i.callId === e.callId || s && i.id.startsWith("transient-activity:") && i.toolName === "browser_tabs" && !!i.runId && i.runId === e.runId, r = t.findIndex(n);
3034
3093
  return r === -1 ? t : t.flatMap((i, o) => n(i) ? o === r ? [e] : [] : i.id === e.id ? [] : [i]);
3035
3094
  }
3036
- function nr(t, e) {
3095
+ function ir(t, e) {
3037
3096
  return fs(
3038
3097
  t,
3039
3098
  e.map(
3040
- (s) => Ft(t, s)
3099
+ (s) => jt(t, s)
3041
3100
  ),
3042
- jt
3101
+ $t
3043
3102
  );
3044
3103
  }
3045
- function jt(t) {
3104
+ function $t(t) {
3046
3105
  const e = J(t) ?? void 0, s = t.assistantDraftItemId, n = [
3047
3106
  ...t.callId ? [`call:${t.callId}`] : [],
3048
3107
  ...t.runId && (t.toolName === "browser_tabs" || t.toolName === "tab_lifecycle") ? [`tab-lifecycle:${t.runId}`] : []
@@ -3060,39 +3119,39 @@ function jt(t) {
3060
3119
  isTransient: t.id.startsWith("transient-activity:") || t.dataType === "assistant_draft"
3061
3120
  };
3062
3121
  }
3063
- function Ft(t, e) {
3122
+ function jt(t, e) {
3064
3123
  if (e.role !== "user" || !e.attachments?.length)
3065
3124
  return e;
3066
3125
  const s = t.find(
3067
- (r) => r.role === "user" && (r.id === e.id || ge(r) && $t(r, e))
3126
+ (r) => r.role === "user" && (r.id === e.id || ge(r) && Ft(r, e))
3068
3127
  );
3069
3128
  if (!s?.attachments?.length)
3070
3129
  return e;
3071
3130
  const n = e.attachments.map((r) => {
3072
- const i = rr(s.attachments ?? [], r);
3073
- return i ? ir(r, i) : r;
3131
+ const i = or(s.attachments ?? [], r);
3132
+ return i ? ar(r, i) : r;
3074
3133
  });
3075
3134
  return { ...e, attachments: n };
3076
3135
  }
3077
- function rr(t, e) {
3136
+ function or(t, e) {
3078
3137
  return e.id ? t.find((s) => s.id === e.id) ?? null : null;
3079
3138
  }
3080
- function ir(t, e) {
3139
+ function ar(t, e) {
3081
3140
  const { previewUrl: s } = e;
3082
3141
  return s ? { ...t, previewUrl: s } : t;
3083
3142
  }
3084
- function or(t, e) {
3143
+ function lr(t, e) {
3085
3144
  if (e.role !== "user")
3086
3145
  return t;
3087
3146
  const s = t.findIndex(
3088
- (r) => ge(r) && $t(r, e)
3147
+ (r) => ge(r) && Ft(r, e)
3089
3148
  );
3090
3149
  if (s === -1)
3091
3150
  return t;
3092
3151
  const n = [...t];
3093
3152
  return n.splice(s, 1), n;
3094
3153
  }
3095
- function $t(t, e) {
3154
+ function Ft(t, e) {
3096
3155
  const s = J(t), n = J(e);
3097
3156
  return s && n ? s === n : t.content === e.content;
3098
3157
  }
@@ -3113,7 +3172,7 @@ function At(t) {
3113
3172
  if (e === null)
3114
3173
  return !1;
3115
3174
  const s = t[e].id, n = t.some(
3116
- (r) => r.respondsToUserMessageId === s && He(r)
3175
+ (r) => r.respondsToUserMessageId === s && We(r)
3117
3176
  );
3118
3177
  if (t.some((r) => r.respondsToUserMessageId === s))
3119
3178
  return n;
@@ -3130,7 +3189,7 @@ function At(t) {
3130
3189
  }
3131
3190
  return !1;
3132
3191
  }
3133
- function ar(t) {
3192
+ function cr(t) {
3134
3193
  const e = zt(t);
3135
3194
  if (e === null)
3136
3195
  return t.some(x);
@@ -3145,7 +3204,7 @@ function zt(t) {
3145
3204
  return e;
3146
3205
  return null;
3147
3206
  }
3148
- function He(t) {
3207
+ function We(t) {
3149
3208
  return x(t) ? !0 : t.role !== "system" ? !1 : t.dataType === "run_error" ? !0 : t.dataType === "run_status" && t.loading !== !0;
3150
3209
  }
3151
3210
  function Y(t) {
@@ -3162,7 +3221,7 @@ function Y(t) {
3162
3221
  }
3163
3222
  return null;
3164
3223
  }
3165
- function lr(t) {
3224
+ function ur(t) {
3166
3225
  const e = Y(t);
3167
3226
  if (e === null)
3168
3227
  return null;
@@ -3178,13 +3237,13 @@ function H(t) {
3178
3237
  const e = t.data;
3179
3238
  return e && typeof e == "object" ? e : null;
3180
3239
  }
3181
- function We(t) {
3240
+ function He(t) {
3182
3241
  return t?.retryable !== !0 ? !1 : t.type === "run_error" ? !0 : t.type === "run_status" && t.status === "interrupted";
3183
3242
  }
3184
3243
  function Rt(t) {
3185
3244
  return t?.type === "run_status" && t.status === "interrupted" && t.reason === "backend_restart";
3186
3245
  }
3187
- function cr(t, e) {
3246
+ function dr(t, e) {
3188
3247
  const s = Y(e);
3189
3248
  if (s === null)
3190
3249
  return !1;
@@ -3193,10 +3252,10 @@ function cr(t, e) {
3193
3252
  return !1;
3194
3253
  const i = t.findIndex((o) => o.role === "user" && o.id === r);
3195
3254
  return i === -1 ? !1 : t.some((o) => o.respondsToUserMessageId === r) ? t.some(
3196
- (o) => o.respondsToUserMessageId === r && He(o)
3197
- ) : t.slice(i + 1).some(He);
3255
+ (o) => o.respondsToUserMessageId === r && We(o)
3256
+ ) : t.slice(i + 1).some(We);
3198
3257
  }
3199
- function je(t) {
3258
+ function $e(t) {
3200
3259
  const e = Y(t);
3201
3260
  if (e === null)
3202
3261
  return null;
@@ -3209,7 +3268,7 @@ function je(t) {
3209
3268
  const r = n.clientMessageId;
3210
3269
  return typeof r == "string" ? r : null;
3211
3270
  }
3212
- function ur(t) {
3271
+ function pr(t) {
3213
3272
  const e = Y(t);
3214
3273
  if (e === null)
3215
3274
  return null;
@@ -3224,22 +3283,22 @@ function ur(t) {
3224
3283
  if (i.type === "message" && i.role === "assistant")
3225
3284
  return null;
3226
3285
  if (i.type === "run_error")
3227
- return i.retryable !== !0 ? null : Fe(t, i) ?? je(t);
3286
+ return i.retryable !== !0 ? null : je(t, i) ?? $e(t);
3228
3287
  if (i.type === "run_status")
3229
- return i.status === "interrupted" && i.retryable === !0 ? Fe(t, i) ?? je(t) : null;
3288
+ return i.status === "interrupted" && i.retryable === !0 ? je(t, i) ?? $e(t) : null;
3230
3289
  }
3231
3290
  return null;
3232
3291
  }
3233
- function Fe(t, e) {
3292
+ function je(t, e) {
3234
3293
  if (typeof e.clientMessageId == "string")
3235
3294
  return e.clientMessageId;
3236
- const s = N(e);
3295
+ const s = O(e);
3237
3296
  if (!s)
3238
3297
  return null;
3239
3298
  const n = t.find((i) => E(i, "id") === s), r = H(n);
3240
3299
  return r?.type === "message" && r.role === "user" && typeof r.clientMessageId == "string" ? r.clientMessageId : null;
3241
3300
  }
3242
- function dr(t, e) {
3301
+ function hr(t, e) {
3243
3302
  let s = 0;
3244
3303
  for (const n of t) {
3245
3304
  if (!n || typeof n != "object")
@@ -3253,12 +3312,12 @@ function dr(t, e) {
3253
3312
  return s;
3254
3313
  }
3255
3314
  function Et(t, e, s, n, r) {
3256
- if (!e || !hr(t))
3315
+ if (!e || !gr(t))
3257
3316
  return !1;
3258
3317
  const i = t;
3259
- return !(We(i) || s !== null && typeof i.id == "string" && i.id !== s || (n !== null ? N(i) !== n : r !== null && _(i) !== r));
3318
+ return !(He(i) || s !== null && typeof i.id == "string" && i.id !== s || (n !== null ? O(i) !== n : r !== null && _(i) !== r));
3260
3319
  }
3261
- function hr(t) {
3320
+ function gr(t) {
3262
3321
  if (!t || typeof t != "object")
3263
3322
  return !1;
3264
3323
  const e = t;
@@ -3267,22 +3326,22 @@ function hr(t) {
3267
3326
  function x(t) {
3268
3327
  return t.role === "assistant" && t.phase !== "commentary";
3269
3328
  }
3270
- function pr(t) {
3329
+ function fr(t) {
3271
3330
  if (!t || typeof t != "object")
3272
3331
  return !1;
3273
3332
  const e = t;
3274
3333
  return e.type === "message" && e.role === "user" ? !1 : e.type === "message" || e.type === "function_call" || e.type === "function_call_output" || e.type === "run_error" || e.type === "run_status";
3275
3334
  }
3276
- function $e(t) {
3277
- return t.filter((e, s) => j(e) ? !Ar(t, s) && !Kt(t, s) && !Sr(t, s) && !Mr(t, s) : gr(e) ? e.retryable === !0 && wr(t, s) ? !1 : !Tr(t, s) : !0);
3335
+ function Fe(t) {
3336
+ return t.filter((e, s) => j(e) ? !Er(t, s) && !Kt(t, s) && !Ar(t, s) && !Rr(t, s) : mr(e) ? e.retryable === !0 && Mr(t, s) ? !1 : !Sr(t, s) : !0);
3278
3337
  }
3279
- function gr(t) {
3338
+ function mr(t) {
3280
3339
  return t.role === "system" && (t.dataType === "run_error" || t.dataType === "run_status" && t.steered !== !0);
3281
3340
  }
3282
3341
  function j(t) {
3283
3342
  return t.role === "system" && t.dataType === "run_status" && t.loading === !0;
3284
3343
  }
3285
- function fr(t, e, s, n) {
3344
+ function yr(t, e, s, n) {
3286
3345
  const r = t.findIndex(
3287
3346
  (l, c) => j(l) && !Kt(t, c)
3288
3347
  ), i = r === -1 ? null : t[r], o = e ?? i?.respondsToUserMessageId ?? null, a = o ? t.find(
@@ -3305,14 +3364,14 @@ function oe(t, e, s) {
3305
3364
  }
3306
3365
  function Kt(t, e) {
3307
3366
  return t.some(
3308
- (s, n) => n !== e && s.role === "system" && (s.dataType === "run_error" || s.dataType === "run_status" && s.loading !== !0 && s.steered !== !0) && mr(
3367
+ (s, n) => n !== e && s.role === "system" && (s.dataType === "run_error" || s.dataType === "run_status" && s.loading !== !0 && s.steered !== !0) && Ir(
3309
3368
  t,
3310
3369
  e,
3311
3370
  n
3312
3371
  )
3313
3372
  );
3314
3373
  }
3315
- function mr(t, e, s) {
3374
+ function Ir(t, e, s) {
3316
3375
  const n = t[e], r = t[s];
3317
3376
  if (Q(n, r))
3318
3377
  return !0;
@@ -3323,26 +3382,26 @@ function mr(t, e, s) {
3323
3382
  return t[i].id === n.respondsToUserMessageId;
3324
3383
  return !1;
3325
3384
  }
3326
- function yr(t, e) {
3385
+ function Tr(t, e) {
3327
3386
  const s = [...t].reverse().find(
3328
- (n) => n.respondsToUserMessageId !== void 0 && n.respondsToUserMessageId !== e && bt(n) && !Ir(
3387
+ (n) => n.respondsToUserMessageId !== void 0 && n.respondsToUserMessageId !== e && Ct(n) && !wr(
3329
3388
  t,
3330
3389
  n.respondsToUserMessageId
3331
3390
  )
3332
3391
  )?.respondsToUserMessageId;
3333
3392
  return s ? t.map(
3334
- (n) => n.respondsToUserMessageId === s && bt(n) ? { ...n, steered: !0 } : n
3393
+ (n) => n.respondsToUserMessageId === s && Ct(n) ? { ...n, steered: !0 } : n
3335
3394
  ) : t;
3336
3395
  }
3337
- function bt(t) {
3396
+ function Ct(t) {
3338
3397
  return t.role === "tool" || j(t) ? !0 : t.role === "assistant" && t.phase === "commentary";
3339
3398
  }
3340
- function Ir(t, e) {
3399
+ function wr(t, e) {
3341
3400
  return t.some(
3342
3401
  (s) => s.respondsToUserMessageId === e && (x(s) || s.role === "system" && (s.dataType === "run_error" || s.dataType === "run_status" && s.loading !== !0))
3343
3402
  );
3344
3403
  }
3345
- function Tr(t, e) {
3404
+ function Sr(t, e) {
3346
3405
  const s = t[e];
3347
3406
  for (let n = e + 1; n < t.length; n += 1) {
3348
3407
  const r = t[n];
@@ -3351,7 +3410,7 @@ function Tr(t, e) {
3351
3410
  }
3352
3411
  return !1;
3353
3412
  }
3354
- function wr(t, e) {
3413
+ function Mr(t, e) {
3355
3414
  const s = t[e];
3356
3415
  if (!s.respondsToUserMessageId)
3357
3416
  return !1;
@@ -3364,19 +3423,19 @@ function wr(t, e) {
3364
3423
  }
3365
3424
  return !1;
3366
3425
  }
3367
- function Sr(t, e) {
3426
+ function Ar(t, e) {
3368
3427
  const s = t[e];
3369
3428
  return t.some(
3370
3429
  (n, r) => r !== e && n.role === "assistant" && Q(s, n)
3371
3430
  );
3372
3431
  }
3373
- function Mr(t, e) {
3432
+ function Rr(t, e) {
3374
3433
  const s = t[e];
3375
3434
  return t.some(
3376
3435
  (n, r) => r !== e && n.role === "tool" && Q(s, n)
3377
3436
  );
3378
3437
  }
3379
- function Ar(t, e) {
3438
+ function Er(t, e) {
3380
3439
  const s = t[e];
3381
3440
  for (let n = e + 1; n < t.length; n += 1)
3382
3441
  if (j(t[n]) && Q(s, t[n]))
@@ -3389,15 +3448,15 @@ function Q(t, e) {
3389
3448
  function E(t, e) {
3390
3449
  return t && typeof t == "object" && typeof t[e] == "string" ? t[e] : null;
3391
3450
  }
3392
- function Rr(t, e) {
3451
+ function Cr(t, e) {
3393
3452
  try {
3394
- const s = window.localStorage.getItem(`${Nt}${t}`);
3453
+ const s = window.localStorage.getItem(`${Ot}${t}`);
3395
3454
  if (!s)
3396
3455
  return null;
3397
3456
  const n = JSON.parse(s), r = typeof n.sessionId == "string" ? n.sessionId : null;
3398
3457
  if (e !== void 0 && r !== e)
3399
3458
  return null;
3400
- const i = Array.isArray(n.messages) ? n.messages.map(xr).filter((o) => !!o) : [];
3459
+ const i = Array.isArray(n.messages) ? n.messages.map(qr).filter((o) => !!o) : [];
3401
3460
  return {
3402
3461
  sessionId: r,
3403
3462
  messages: i
@@ -3406,20 +3465,20 @@ function Rr(t, e) {
3406
3465
  return null;
3407
3466
  }
3408
3467
  }
3409
- function Er(t, e) {
3468
+ function br(t, e) {
3410
3469
  try {
3411
3470
  window.localStorage.setItem(
3412
- `${Nt}${t}`,
3471
+ `${Ot}${t}`,
3413
3472
  JSON.stringify({
3414
3473
  sessionId: e.sessionId,
3415
- messages: e.messages.slice(-Js).map(Lr)
3474
+ messages: e.messages.slice(-Qs).map(Br)
3416
3475
  })
3417
3476
  );
3418
3477
  } catch {
3419
3478
  return;
3420
3479
  }
3421
3480
  }
3422
- function br(t) {
3481
+ function _r(t) {
3423
3482
  try {
3424
3483
  const e = window.localStorage.getItem(`${qe}${t}`);
3425
3484
  if (!e)
@@ -3430,7 +3489,7 @@ function br(t) {
3430
3489
  return [];
3431
3490
  }
3432
3491
  }
3433
- function L(t, e) {
3492
+ function q(t, e) {
3434
3493
  try {
3435
3494
  const s = e.filter(Qe);
3436
3495
  if (s.length === 0) {
@@ -3447,7 +3506,7 @@ function L(t, e) {
3447
3506
  }
3448
3507
  function Gt(t, e) {
3449
3508
  try {
3450
- const s = `${pe}${t}`, n = location.href, r = location.origin, i = Array.from(e, (o) => ({
3509
+ const s = `${he}${t}`, n = location.href, r = location.origin, i = Array.from(e, (o) => ({
3451
3510
  ...o,
3452
3511
  storedAt: Date.now(),
3453
3512
  unloadUrl: n,
@@ -3461,28 +3520,28 @@ function Gt(t, e) {
3461
3520
  } catch {
3462
3521
  }
3463
3522
  }
3464
- function Cr(t, e) {
3523
+ function kr(t, e) {
3465
3524
  try {
3466
- if (window.sessionStorage.getItem(`${pe}${t}`) === null)
3525
+ if (window.sessionStorage.getItem(`${he}${t}`) === null)
3467
3526
  return;
3468
3527
  } catch {
3469
3528
  return;
3470
3529
  }
3471
3530
  Gt(t, e);
3472
3531
  }
3473
- function _r(t) {
3532
+ function Pr(t) {
3474
3533
  try {
3475
- const e = `${pe}${t}`, s = window.sessionStorage.getItem(e);
3534
+ const e = `${he}${t}`, s = window.sessionStorage.getItem(e);
3476
3535
  if (window.sessionStorage.removeItem(e), !s)
3477
3536
  return [];
3478
3537
  const n = JSON.parse(s);
3479
- return Array.isArray(n) ? n.flatMap((r) => Ur(r) ? [{
3538
+ return Array.isArray(n) ? n.flatMap((r) => Dr(r) ? [{
3480
3539
  ...r.event,
3481
3540
  page: C(),
3482
3541
  rawOutput: {
3483
3542
  pageContextRestarted: !0,
3484
3543
  outcome: "unknown",
3485
- message: kr(location.href),
3544
+ message: Ur(location.href),
3486
3545
  currentUrl: location.href,
3487
3546
  console: [],
3488
3547
  metadata: {
@@ -3499,17 +3558,17 @@ function _r(t) {
3499
3558
  return [];
3500
3559
  }
3501
3560
  }
3502
- function kr(t) {
3561
+ function Ur(t) {
3503
3562
  return `The page context restarted. This is expected when the action included page navigation. Otherwise, it's unknown whether the action completed.
3504
3563
  Current URL: ${t}`;
3505
3564
  }
3506
- function Ur(t) {
3565
+ function Dr(t) {
3507
3566
  if (!t || typeof t != "object")
3508
3567
  return !1;
3509
3568
  const e = t, s = e.event;
3510
3569
  return typeof e.startedAtMs == "number" && typeof e.startedAtUrl == "string" && e.startedAtOrigin === location.origin && e.unloadOrigin === location.origin && typeof e.unloadUrl == "string" && Qe(s) && s.type === "tool.result";
3511
3570
  }
3512
- function Pr(t, e) {
3571
+ function vr(t, e) {
3513
3572
  const s = new Set(
3514
3573
  t.flatMap((n) => n.type === "tool.result" ? [n.callId] : [])
3515
3574
  );
@@ -3518,9 +3577,9 @@ function Pr(t, e) {
3518
3577
  ...e.filter((n) => !s.has(n.callId))
3519
3578
  ];
3520
3579
  }
3521
- function Dr(t) {
3580
+ function Nr(t) {
3522
3581
  try {
3523
- window.sessionStorage.removeItem(`${pe}${t}`);
3582
+ window.sessionStorage.removeItem(`${he}${t}`);
3524
3583
  } catch {
3525
3584
  return;
3526
3585
  }
@@ -3529,9 +3588,9 @@ function Qe(t) {
3529
3588
  if (!t || typeof t != "object")
3530
3589
  return !1;
3531
3590
  const e = t;
3532
- return e.type === "chat.user_message" ? typeof e.content == "string" && Ct(e.page) : e.type === "page.upsert" || e.type === "session.reset" || e.type === "network.batch" ? Ct(e.page) : e.type === "tool.result" ? typeof e.sessionId == "string" && typeof e.callId == "string" && (e.toolName === "execute_code" || e.toolName === "execute_code_in_browser_tab") : e.type === "chat.retry_last_user_message" ? typeof e.sessionId == "string" && typeof e.clientMessageId == "string" : e.type === "run.stop" ? typeof e.sessionId == "string" && (e.reason === "user_requested" || e.reason === "new_chat" || e.reason === "session_switch") : !1;
3591
+ return e.type === "chat.user_message" ? typeof e.content == "string" && bt(e.page) : e.type === "page.upsert" || e.type === "session.reset" || e.type === "network.batch" ? bt(e.page) : e.type === "tool.result" ? typeof e.sessionId == "string" && typeof e.callId == "string" && (e.toolName === "execute_code" || e.toolName === "execute_code_in_browser_tab") : e.type === "chat.retry_last_user_message" ? typeof e.sessionId == "string" && typeof e.clientMessageId == "string" : e.type === "run.stop" ? typeof e.sessionId == "string" && (e.reason === "user_requested" || e.reason === "new_chat" || e.reason === "session_switch") : !1;
3533
3592
  }
3534
- function Ct(t) {
3593
+ function bt(t) {
3535
3594
  if (!t || typeof t != "object")
3536
3595
  return !1;
3537
3596
  const e = t;
@@ -3555,9 +3614,9 @@ function Vt(t, e) {
3555
3614
  } : t;
3556
3615
  }
3557
3616
  function ze(t) {
3558
- return t.type || Nr(t.name) || "application/octet-stream";
3617
+ return t.type || Lr(t.name) || "application/octet-stream";
3559
3618
  }
3560
- function vr(t) {
3619
+ function Or(t) {
3561
3620
  Jt({
3562
3621
  name: t.name,
3563
3622
  mimeType: ze(t),
@@ -3565,21 +3624,21 @@ function vr(t) {
3565
3624
  });
3566
3625
  }
3567
3626
  function Jt(t) {
3568
- const e = Or(t.name), s = t.mimeType.trim().toLowerCase();
3569
- if (!Gs.has(`${e}:${s}`))
3627
+ const e = xr(t.name), s = t.mimeType.trim().toLowerCase();
3628
+ if (!Vs.has(`${e}:${s}`))
3570
3629
  throw new Error("This attachment type is not supported by the embedded model provider");
3571
3630
  if (t.sizeBytes <= 0 || t.sizeBytes >= vt)
3572
3631
  throw new Error("Embedded attachments must be between 1 byte and less than 50 MB");
3573
3632
  }
3574
- function Or(t) {
3633
+ function xr(t) {
3575
3634
  const e = t.trim().toLowerCase(), s = e.lastIndexOf(".");
3576
3635
  return s >= 0 ? e.slice(s) : "";
3577
3636
  }
3578
- function Nr(t) {
3637
+ function Lr(t) {
3579
3638
  const e = t.toLowerCase();
3580
3639
  return e.endsWith(".png") ? "image/png" : e.endsWith(".jpg") || e.endsWith(".jpeg") ? "image/jpeg" : e.endsWith(".webp") ? "image/webp" : e.endsWith(".gif") ? "image/gif" : e.endsWith(".pdf") ? "application/pdf" : null;
3581
3640
  }
3582
- function xr(t) {
3641
+ function qr(t) {
3583
3642
  if (!t || typeof t != "object")
3584
3643
  return null;
3585
3644
  const e = t;
@@ -3600,7 +3659,7 @@ function xr(t) {
3600
3659
  loading: typeof e.loading == "boolean" ? e.loading : void 0
3601
3660
  };
3602
3661
  }
3603
- function Lr(t) {
3662
+ function Br(t) {
3604
3663
  return t.attachments?.length ? {
3605
3664
  ...t,
3606
3665
  attachments: t.attachments.map(Ze)
@@ -3615,7 +3674,7 @@ function Ze(t) {
3615
3674
  } = t;
3616
3675
  return r;
3617
3676
  }
3618
- function N(t) {
3677
+ function O(t) {
3619
3678
  const e = t.respondsToUserMessageId;
3620
3679
  return typeof e == "string" && e ? e : null;
3621
3680
  }
@@ -3623,9 +3682,9 @@ function _(t) {
3623
3682
  const e = t.runId;
3624
3683
  return typeof e == "string" && e ? e : null;
3625
3684
  }
3626
- function qr(t) {
3685
+ function Wr(t) {
3627
3686
  const e = t?.timeoutMs;
3628
- return !!t && typeof t == "object" && typeof t.summary == "string" && typeof t.javascript == "string" && (e === void 0 || typeof e == "number" && Number.isInteger(e) && e > 0 && e <= on);
3687
+ return !!t && typeof t == "object" && typeof t.summary == "string" && typeof t.javascript == "string" && (e === void 0 || typeof e == "number" && Number.isInteger(e) && e > 0 && e <= ln);
3629
3688
  }
3630
3689
  function Yt(t) {
3631
3690
  const e = {};
@@ -3639,22 +3698,22 @@ function Yt(t) {
3639
3698
  return e;
3640
3699
  }
3641
3700
  function et(t, e) {
3642
- return ns(t) ? fe : P(he(e), Xs);
3701
+ return ns(t) ? fe : U(pe(e), Js);
3643
3702
  }
3644
- function Br(t, e) {
3703
+ function Hr(t, e) {
3645
3704
  return typeof t == "string" ? t : t instanceof URL ? t.toString() : e?.url ?? "";
3646
3705
  }
3647
- async function Hr(t, e, s, n) {
3706
+ async function $r(t, e, s, n) {
3648
3707
  const r = Yt(t.headers);
3649
3708
  n({
3650
3709
  ...e,
3651
3710
  responseStatus: t.status,
3652
3711
  responseHeaders: r,
3653
- responseBody: await Wr(t),
3712
+ responseBody: await jr(t),
3654
3713
  durationMs: Date.now() - s
3655
3714
  });
3656
3715
  }
3657
- async function Wr(t) {
3716
+ async function jr(t) {
3658
3717
  if (!Qt(t.headers))
3659
3718
  return;
3660
3719
  let e = null, s = null;
@@ -3664,7 +3723,7 @@ async function Wr(t) {
3664
3723
  const n = new Promise((a) => {
3665
3724
  s = window.setTimeout(() => {
3666
3725
  e?.cancel(), a("timeout");
3667
- }, Vs);
3726
+ }, Ys);
3668
3727
  }), r = new TextDecoder();
3669
3728
  let i = "", o = 0;
3670
3729
  for (; ; ) {
@@ -3673,10 +3732,10 @@ async function Wr(t) {
3673
3732
  return;
3674
3733
  const { done: l, value: c } = a;
3675
3734
  if (l)
3676
- return P(i + r.decode());
3677
- const h = Ve - o;
3678
- if (c.byteLength > h)
3679
- return i += r.decode(c.subarray(0, Math.max(h, 0)), { stream: !0 }), e.cancel(), `${P(i)}... [truncated]`;
3735
+ return U(i + r.decode());
3736
+ const p = Ve - o;
3737
+ if (c.byteLength > p)
3738
+ return i += r.decode(c.subarray(0, Math.max(p, 0)), { stream: !0 }), e.cancel(), `${U(i)}... [truncated]`;
3680
3739
  o += c.byteLength, i += r.decode(c, { stream: !0 });
3681
3740
  }
3682
3741
  } catch {
@@ -3686,19 +3745,19 @@ async function Wr(t) {
3686
3745
  s !== null && window.clearTimeout(s);
3687
3746
  }
3688
3747
  }
3689
- function jr(t, e) {
3748
+ function Fr(t, e) {
3690
3749
  if (Qt(new Headers(e)))
3691
3750
  try {
3692
- return t.responseType === "" || t.responseType === "text" ? P(t.responseText ?? "") : void 0;
3751
+ return t.responseType === "" || t.responseType === "text" ? U(t.responseText ?? "") : void 0;
3693
3752
  } catch {
3694
3753
  return;
3695
3754
  }
3696
3755
  }
3697
3756
  function _t(t) {
3698
3757
  if (typeof t == "string")
3699
- return P(t);
3758
+ return U(t);
3700
3759
  }
3701
- function Fr(t) {
3760
+ function zr(t) {
3702
3761
  return k({
3703
3762
  ...t,
3704
3763
  requestBody: kt(t.requestBody),
@@ -3710,11 +3769,11 @@ function kt(t) {
3710
3769
  return t;
3711
3770
  const e = t.trim();
3712
3771
  if (!e.startsWith("{") && !e.startsWith("["))
3713
- return he(t);
3772
+ return pe(t);
3714
3773
  try {
3715
3774
  return JSON.stringify(k(JSON.parse(t)));
3716
3775
  } catch {
3717
- return he(t);
3776
+ return pe(t);
3718
3777
  }
3719
3778
  }
3720
3779
  function Qt(t) {
@@ -3723,8 +3782,8 @@ function Qt(t) {
3723
3782
  const e = t.get("content-type")?.toLowerCase() ?? "", s = t.get("content-length"), n = Number(s);
3724
3783
  return s !== null && Number.isInteger(n) && n >= 0 && n <= Ve && (e.startsWith("text/") || e.includes("json") || e.includes("javascript"));
3725
3784
  }
3726
- function q(t, e = {}, s) {
3727
- if (zr(s))
3785
+ function B(t, e = {}, s) {
3786
+ if (Gr(s))
3728
3787
  return !0;
3729
3788
  const n = Object.entries(e).find(([r]) => r.toLowerCase() === "content-type")?.[1]?.toLowerCase();
3730
3789
  if (n?.includes("multipart/form-data") || n?.includes("application/octet-stream"))
@@ -3739,8 +3798,8 @@ function q(t, e = {}, s) {
3739
3798
  return !0;
3740
3799
  }
3741
3800
  }
3742
- function $r(t, e) {
3743
- if (q(t))
3801
+ function Kr(t, e) {
3802
+ if (B(t))
3744
3803
  return !0;
3745
3804
  try {
3746
3805
  const s = new URL(t, location.href), n = new URL(e);
@@ -3749,10 +3808,10 @@ function $r(t, e) {
3749
3808
  return !0;
3750
3809
  }
3751
3810
  }
3752
- function zr(t) {
3811
+ function Gr(t) {
3753
3812
  return t instanceof FormData || t instanceof Blob || t instanceof ArrayBuffer || ArrayBuffer.isView(t) || typeof ReadableStream < "u" && t instanceof ReadableStream;
3754
3813
  }
3755
- function Kr(t) {
3814
+ function Xr(t) {
3756
3815
  const e = {};
3757
3816
  for (const s of t.trim().split(/[\r\n]+/)) {
3758
3817
  const n = s.indexOf(":");
@@ -3765,10 +3824,10 @@ function Kr(t) {
3765
3824
  }
3766
3825
  return e;
3767
3826
  }
3768
- function P(t, e = Ve) {
3827
+ function U(t, e = Ve) {
3769
3828
  return t.length <= e ? t : `${t.slice(0, e)}... [truncated ${t.length - e} chars]`;
3770
3829
  }
3771
- function Ne(t) {
3830
+ function Oe(t) {
3772
3831
  return `${t}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
3773
3832
  }
3774
3833
  class ue extends Error {
@@ -3783,36 +3842,36 @@ async function ae(t, e) {
3783
3842
  try {
3784
3843
  return await t();
3785
3844
  } catch (r) {
3786
- if (s = r, n >= It - 1 || !Xr(r))
3845
+ if (s = r, n >= It - 1 || !Jr(r))
3787
3846
  throw r;
3788
- await Gr(n);
3847
+ await Vr(n);
3789
3848
  }
3790
3849
  throw s instanceof Error ? s : new Error(e);
3791
3850
  }
3792
- function Gr(t) {
3851
+ function Vr(t) {
3793
3852
  return new Promise((e) => {
3794
- window.setTimeout(e, Ks[t] ?? 0);
3853
+ window.setTimeout(e, Xs[t] ?? 0);
3795
3854
  });
3796
3855
  }
3797
- function Xr(t) {
3798
- return t instanceof ue ? Vr(t.status) : t instanceof TypeError;
3856
+ function Jr(t) {
3857
+ return t instanceof ue ? Yr(t.status) : t instanceof TypeError;
3799
3858
  }
3800
- function Vr(t) {
3859
+ function Yr(t) {
3801
3860
  return t === 408 || t === 409 || t === 429 || t >= 500;
3802
3861
  }
3803
- function Jr(t) {
3862
+ function Qr(t) {
3804
3863
  return t === 401 || t === 403;
3805
3864
  }
3806
- const fe = "[REDACTED_SECRET]", D = "[REDACTED_TOKEN]", Yr = "[REDACTED_SIGNED_URL]", Qr = 20, Zr = /^(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, Zt = /\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi, es = /\bBasic\s+[A-Za-z0-9+/=-]{12,}/gi, ts = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g, ss = /\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, ei = /\bhttps?:\/\/[^\s"'<>]+(?:X-Amz-Signature|X-Goog-Signature|Signature|sig=)[^\s"'<>]*/gi, ti = /\bhttps?:\/\/[^\s"'<>]+/gi, si = /[),.;\]]+$/;
3865
+ const fe = "[REDACTED_SECRET]", D = "[REDACTED_TOKEN]", Zr = "[REDACTED_SIGNED_URL]", ei = 20, ti = /^(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, Zt = /\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi, es = /\bBasic\s+[A-Za-z0-9+/=-]{12,}/gi, ts = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g, ss = /\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, si = /\bhttps?:\/\/[^\s"'<>]+(?:X-Amz-Signature|X-Goog-Signature|Signature|sig=)[^\s"'<>]*/gi, ni = /\bhttps?:\/\/[^\s"'<>]+/gi, ri = /[),.;\]]+$/;
3807
3866
  function k(t) {
3808
3867
  return de(t, 0, /* @__PURE__ */ new WeakSet());
3809
3868
  }
3810
3869
  function de(t, e, s) {
3811
3870
  if (typeof t == "string")
3812
- return t.startsWith("data:image/") || t.startsWith("data:application/pdf;") ? t : he(t);
3871
+ return t.startsWith("data:image/") || t.startsWith("data:application/pdf;") ? t : pe(t);
3813
3872
  if (t === null || typeof t != "object")
3814
3873
  return t;
3815
- if (e >= Qr)
3874
+ if (e >= ei)
3816
3875
  return "[REDACTED_MAX_DEPTH]";
3817
3876
  if (s.has(t))
3818
3877
  return "[REDACTED_CIRCULAR]";
@@ -3820,34 +3879,34 @@ function de(t, e, s) {
3820
3879
  return t.map((r) => de(r, e + 1, s));
3821
3880
  const n = {};
3822
3881
  for (const [r, i] of Object.entries(t))
3823
- r === "pageContent" ? n[r] = i : ns(r) ? n[r] = fe : n[r] = r.toLowerCase() === "url" ? ni(i) : de(i, e + 1, s);
3882
+ r === "pageContent" ? n[r] = i : ns(r) ? n[r] = fe : n[r] = r.toLowerCase() === "url" ? ii(i) : de(i, e + 1, s);
3824
3883
  return n;
3825
3884
  }
3826
3885
  function ns(t) {
3827
3886
  const e = t.replace(/[^a-z0-9]/gi, "").toLowerCase();
3828
3887
  return e.includes("authorization") || e.includes("cookie") || e.includes("password") || e.includes("passwd") || e === "pwd" || e.includes("secret") || e === "token" || e.endsWith("token") || e.includes("apikey") || e.includes("csrf") || e.includes("xsrf") || e === "jwt" || e === "session" || e === "signature" || e.includes("privatekey");
3829
3888
  }
3830
- function ni(t) {
3889
+ function ii(t) {
3831
3890
  return typeof t == "string" ? rs(t) : de(t, 0, /* @__PURE__ */ new WeakSet());
3832
3891
  }
3833
3892
  function rs(t) {
3834
3893
  try {
3835
3894
  const e = new URL(t, location.href);
3836
3895
  for (const s of Array.from(e.searchParams.keys()))
3837
- Zr.test(s) && e.searchParams.set(s, D);
3896
+ ti.test(s) && e.searchParams.set(s, D);
3838
3897
  return e.username && (e.username = D), e.password && (e.password = D), e.toString();
3839
3898
  } catch {
3840
- return ri(t);
3899
+ return oi(t);
3841
3900
  }
3842
3901
  }
3843
- function he(t) {
3844
- return t.replace(ei, Yr).replace(ti, ii).replace(Zt, `Bearer ${D}`).replace(es, `Basic ${D}`).replace(ts, D).replace(ss, (e, s) => `${s}: ${fe}`);
3902
+ function pe(t) {
3903
+ return t.replace(si, Zr).replace(ni, ai).replace(Zt, `Bearer ${D}`).replace(es, `Basic ${D}`).replace(ts, D).replace(ss, (e, s) => `${s}: ${fe}`);
3845
3904
  }
3846
- function ri(t) {
3905
+ function oi(t) {
3847
3906
  return t.replace(Zt, `Bearer ${D}`).replace(es, `Basic ${D}`).replace(ts, D).replace(ss, (e, s) => `${s}: ${fe}`);
3848
3907
  }
3849
- function ii(t) {
3850
- const e = t.match(si)?.[0] ?? "", s = e ? t.slice(0, -e.length) : t;
3908
+ function ai(t) {
3909
+ const e = t.match(ri)?.[0] ?? "", s = e ? t.slice(0, -e.length) : t;
3851
3910
  return `${rs(s)}${e}`;
3852
3911
  }
3853
3912
  export {
@@ -3855,11 +3914,11 @@ export {
3855
3914
  Le as PLUNO_PRODUCT_AGENT_WIDGET_HOST_SELECTOR,
3856
3915
  ks as PLUNO_PRODUCT_AGENT_WIDGET_PANEL_SELECTOR,
3857
3916
  _s as PLUNO_PRODUCT_AGENT_WIDGET_ROOT_SELECTOR,
3858
- Us as PLUNO_PRODUCT_AGENT_WIDGET_TIMELINE_SELECTOR,
3859
- oi as PRODUCT_AGENT_PROVIDER_INPUT_ATTACHMENT_ACCEPT,
3917
+ Ps as PLUNO_PRODUCT_AGENT_WIDGET_TIMELINE_SELECTOR,
3918
+ li as PRODUCT_AGENT_PROVIDER_INPUT_ATTACHMENT_ACCEPT,
3860
3919
  xt as PlunoProductAgent,
3861
- Qs as calculateReconnectDelay,
3920
+ en as calculateReconnectDelay,
3862
3921
  xt as default,
3863
- Mn as getProductAgentOriginAccessErrorMessage,
3864
- vr as validateProductAgentProviderInputFile
3922
+ Rn as getProductAgentOriginAccessErrorMessage,
3923
+ Or as validateProductAgentProviderInputFile
3865
3924
  };