@pluno/product-agent-web 0.1.163 → 0.1.165

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,13 @@
1
- const as = "pluno-product-agent-attachments";
2
- const xe = "files";
3
- async function ls(t) {
4
- const e = await Ke();
5
- await ds(e, "readwrite", (s) => s.put(t));
6
- }
7
- async function cs(t, e) {
8
- const s = await Ke();
9
- await Ge(s, "readwrite", async (n) => {
10
- const r = await Xe(
1
+ const us = "pluno-product-agent-attachments";
2
+ const Be = "files";
3
+ async function ds(t) {
4
+ const e = await Xe();
5
+ await gs(e, "readwrite", (s) => s.put(t));
6
+ }
7
+ async function ps(t, e) {
8
+ const s = await Xe();
9
+ await Ve(s, "readwrite", async (n) => {
10
+ const r = await Je(
11
11
  n.get(t)
12
12
  );
13
13
  r && n.put({
@@ -16,28 +16,28 @@ async function cs(t, e) {
16
16
  });
17
17
  });
18
18
  }
19
- async function us(t = 864e5) {
20
- const e = await Ke(), s = Date.now() - t;
21
- await Ge(e, "readwrite", async (n) => {
19
+ async function hs(t = 864e5) {
20
+ const e = await Xe(), s = Date.now() - t;
21
+ await Ve(e, "readwrite", async (n) => {
22
22
  const r = n.index("lastUsedAt");
23
- (await Xe(r.getAllKeys(IDBKeyRange.upperBound(s)))).forEach((o) => n.delete(o));
23
+ (await Je(r.getAllKeys(IDBKeyRange.upperBound(s)))).forEach((o) => n.delete(o));
24
24
  });
25
25
  }
26
- function Ke() {
26
+ function Xe() {
27
27
  return typeof indexedDB > "u" ? Promise.reject(new Error("Product Agent attachment storage is unavailable")) : new Promise((t, e) => {
28
- const s = indexedDB.open(as, 1);
28
+ const s = indexedDB.open(us, 1);
29
29
  s.onupgradeneeded = () => {
30
- const r = s.result.createObjectStore(xe, { keyPath: "attachmentId" });
30
+ const r = s.result.createObjectStore(Be, { keyPath: "attachmentId" });
31
31
  r.createIndex("lastUsedAt", "lastUsedAt", { unique: !1 }), r.createIndex("sessionId", "sessionId", { unique: !1 }), r.createIndex("origin", "origin", { unique: !1 });
32
32
  }, s.onsuccess = () => t(s.result), s.onerror = () => e(s.error ?? new Error("Failed to open Product Agent attachment storage"));
33
33
  });
34
34
  }
35
- async function ds(t, e, s) {
36
- return await Ge(t, e, async (n) => await Xe(s(n)));
35
+ async function gs(t, e, s) {
36
+ return await Ve(t, e, async (n) => await Je(s(n)));
37
37
  }
38
- function Ge(t, e, s) {
38
+ function Ve(t, e, s) {
39
39
  return new Promise((n, r) => {
40
- const i = t.transaction(xe, e), o = i.objectStore(xe);
40
+ const i = t.transaction(Be, e), o = i.objectStore(Be);
41
41
  let a, l = !1;
42
42
  s(o).then((c) => {
43
43
  a = c;
@@ -57,16 +57,16 @@ function Ge(t, e, s) {
57
57
  };
58
58
  });
59
59
  }
60
- function Xe(t) {
60
+ function Je(t) {
61
61
  return new Promise((e, s) => {
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 ps(t) {
65
+ function fs(t) {
66
66
  return t !== null && (typeof t == "object" || typeof t == "function");
67
67
  }
68
- function Pt(t, e, s) {
69
- const n = Reflect.get(t, "pluno"), r = ps(n) ? n : {};
68
+ function vt(t, e, s) {
69
+ const n = Reflect.get(t, "pluno"), r = fs(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,14 +80,18 @@ function Pt(t, e, s) {
80
80
  }
81
81
  };
82
82
  }
83
- const hs = /(\]\()(\/api\/product-agent\/attachments\/download\?[^)\s]+)(\))/g;
84
- function gs(t, e) {
83
+ const ms = /(\]\()(\/api\/product-agent\/attachments\/download\?[^)\s]+)(\))/g;
84
+ function ys(t, e) {
85
85
  return e ? t.replace(
86
- hs,
86
+ ms,
87
87
  (s, n, r, i) => `${n}${new URL(r, e).toString()}${i}`
88
88
  ) : t;
89
89
  }
90
- function fs(t, e, s) {
90
+ const Is = "save_runtime_captured_skill";
91
+ function Ts(t) {
92
+ return (t.type === "function_call" || t.type === "tool_call") && t.name === Is;
93
+ }
94
+ function ws(t, e, s) {
91
95
  const n = e.map((u) => ({ item: u, identity: s(u) })), r = new Set(
92
96
  n.flatMap(
93
97
  ({ identity: u }) => u.isActivity && !u.isTransient ? u.activityKeys ?? [] : []
@@ -104,38 +108,38 @@ function fs(t, e, s) {
104
108
  )
105
109
  ), c = /* @__PURE__ */ new Map();
106
110
  for (const { item: u, identity: d } of i)
107
- for (const g of d.activityKeys ?? []) {
108
- const m = c.get(g);
109
- (!m || s(m).isTransient) && c.set(g, u);
111
+ for (const f of d.activityKeys ?? []) {
112
+ const I = c.get(f);
113
+ (!I || s(I).isTransient) && c.set(f, u);
110
114
  }
111
- const p = new Set(i.map(({ identity: u }) => u.id)), h = new Set(
115
+ const p = new Set(i.map(({ identity: u }) => u.id)), g = new Set(
112
116
  i.flatMap(({ identity: u }) => u.runId ? [u.runId] : [])
113
- ), w = /* @__PURE__ */ new Set(), y = [];
117
+ ), T = /* @__PURE__ */ new Set(), h = [];
114
118
  for (const u of t) {
115
119
  const d = s(u);
116
- let g = o.get(d.id);
117
- if (d.isOptimistic && d.optimisticKey ? g = a.get(d.optimisticKey) : d.isAssistantDraft && d.assistantDraftKey ? g = l.get(d.assistantDraftKey) : d.isActivity && (g = d.activityKeys?.map((T) => c.get(T)).find((T) => T !== void 0) ?? g), g && !w.has(g)) {
118
- y.push(g), w.add(g);
120
+ let f = o.get(d.id);
121
+ if (d.isOptimistic && d.optimisticKey ? f = a.get(d.optimisticKey) : d.isAssistantDraft && d.assistantDraftKey ? f = l.get(d.assistantDraftKey) : d.isActivity && (f = d.activityKeys?.map((w) => c.get(w)).find((w) => w !== void 0) ?? f), f && !T.has(f)) {
122
+ h.push(f), T.add(f);
119
123
  continue;
120
124
  }
121
- const m = d.respondsToUserMessageId !== void 0 && p.has(d.respondsToUserMessageId) || d.runId !== void 0 && h.has(d.runId);
122
- (d.isOptimistic || (d.isAssistantDraft || d.isActivity) && m) && y.push(u);
125
+ const I = d.respondsToUserMessageId !== void 0 && p.has(d.respondsToUserMessageId) || d.runId !== void 0 && g.has(d.runId);
126
+ (d.isOptimistic || (d.isAssistantDraft || d.isActivity) && I) && h.push(u);
123
127
  }
124
128
  for (const { item: u } of i)
125
- w.has(u) || y.push(u);
126
- return y;
129
+ T.has(u) || h.push(u);
130
+ return h;
127
131
  }
128
- function ms(t, e, s, n) {
132
+ function Ss(t, e, s, n) {
129
133
  return t.filter((r) => {
130
134
  const i = n(r);
131
135
  return !i.isActivity || !i.isTransient ? !0 : e !== null && i.respondsToUserMessageId !== void 0 ? i.respondsToUserMessageId !== e : s === null || i.runId !== s;
132
136
  });
133
137
  }
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
- const le = /* @__PURE__ */ new Set(), _e = /* @__PURE__ */ new Map();
137
- async function ws(t = Ut()) {
138
- const e = t.randomUUID(), s = t.storage.getItem(Ce);
138
+ const be = "pluno.productAgent.transportId", Ms = "pluno.productAgent.transportIdentity", _e = "pluno.productAgent.transportIdentity.event", As = 50, Rs = globalThis.setTimeout.bind(globalThis);
139
+ let J = null;
140
+ const de = /* @__PURE__ */ new Set(), ke = /* @__PURE__ */ new Map();
141
+ async function Es(t = Nt()) {
142
+ const e = t.randomUUID(), s = t.storage.getItem(be);
139
143
  let n = s ?? t.randomUUID(), r = !1, i = !1;
140
144
  const o = t.channel.subscribe((l) => {
141
145
  if (!(l.senderId === e || l.transportId !== n)) {
@@ -153,14 +157,14 @@ async function ws(t = Ut()) {
153
157
  }
154
158
  });
155
159
  if (!s)
156
- t.storage.setItem(Ce, n), r = !0;
160
+ t.storage.setItem(be, n), r = !0;
157
161
  else
158
162
  for (; ; ) {
159
163
  if (i = !1, t.channel.postMessage({ type: "probe", transportId: n, senderId: e }), await t.settle(), !i) {
160
164
  r = !0;
161
165
  break;
162
166
  }
163
- n = t.randomUUID(), t.storage.setItem(Ce, n);
167
+ n = t.randomUUID(), t.storage.setItem(be, n);
164
168
  }
165
169
  let a = !1;
166
170
  return {
@@ -170,49 +174,49 @@ async function ws(t = Ut()) {
170
174
  }
171
175
  };
172
176
  }
173
- async function Ss() {
174
- K || (K = ws(Ut()), K.then((n) => {
177
+ async function Cs() {
178
+ J || (J = Es(Nt()), J.then((n) => {
175
179
  const r = (i) => {
176
- i.persisted || (n.release(), K = null, le.clear(), window.removeEventListener("pagehide", r));
180
+ i.persisted || (n.release(), J = null, de.clear(), window.removeEventListener("pagehide", r));
177
181
  };
178
182
  window.addEventListener("pagehide", r);
179
183
  }));
180
- const t = await K, e = Ms();
181
- le.add(e);
184
+ const t = await J, e = bs();
185
+ de.add(e);
182
186
  let s = !1;
183
187
  return {
184
188
  // A stable per-tab base keeps reload routing intact, while slots isolate multiple live SDK instances in one tab.
185
189
  transportId: e === 0 ? t.transportId : `${t.transportId}.${e}`,
186
190
  release: () => {
187
- s || (s = !0, le.delete(e));
191
+ s || (s = !0, de.delete(e));
188
192
  }
189
193
  };
190
194
  }
191
- function Ms() {
195
+ function bs() {
192
196
  let t = 0;
193
- for (; le.has(t); )
197
+ for (; de.has(t); )
194
198
  t += 1;
195
199
  return t;
196
200
  }
197
- function Ut() {
201
+ function Nt() {
198
202
  return {
199
- storage: As(),
200
- channel: Rs(),
203
+ storage: _s(),
204
+ channel: ks(),
201
205
  randomUUID: () => crypto.randomUUID(),
202
- settle: () => new Promise((t) => Ts(t, Is))
206
+ settle: () => new Promise((t) => Rs(t, As))
203
207
  };
204
208
  }
205
- function As() {
209
+ function _s() {
206
210
  return {
207
211
  getItem: (t) => {
208
212
  try {
209
- return window.sessionStorage?.getItem(t) ?? _e.get(t) ?? null;
213
+ return window.sessionStorage?.getItem(t) ?? ke.get(t) ?? null;
210
214
  } catch {
211
- return _e.get(t) ?? null;
215
+ return ke.get(t) ?? null;
212
216
  }
213
217
  },
214
218
  setItem: (t, e) => {
215
- _e.set(t, e);
219
+ ke.set(t, e);
216
220
  try {
217
221
  window.sessionStorage?.setItem(t, e);
218
222
  } catch {
@@ -220,9 +224,9 @@ function As() {
220
224
  }
221
225
  };
222
226
  }
223
- function Rs() {
227
+ function ks() {
224
228
  if (typeof BroadcastChannel < "u") {
225
- const t = new BroadcastChannel(ys);
229
+ const t = new BroadcastChannel(Ms);
226
230
  return {
227
231
  postMessage: (e) => t.postMessage(e),
228
232
  subscribe: (e) => {
@@ -232,11 +236,11 @@ function Rs() {
232
236
  close: () => t.close()
233
237
  };
234
238
  }
235
- return Es();
239
+ return Ps();
236
240
  }
237
- function Es() {
241
+ function Ps() {
238
242
  const t = /* @__PURE__ */ new Set(), e = (s) => {
239
- if (s.key !== be || !s.newValue)
243
+ if (s.key !== _e || !s.newValue)
240
244
  return;
241
245
  const n = JSON.parse(s.newValue);
242
246
  for (const r of t)
@@ -245,9 +249,9 @@ function Es() {
245
249
  return window.addEventListener("storage", e), {
246
250
  postMessage: (s) => {
247
251
  window.localStorage.setItem(
248
- be,
252
+ _e,
249
253
  JSON.stringify({ ...s, eventId: crypto.randomUUID() })
250
- ), window.localStorage.removeItem(be);
254
+ ), window.localStorage.removeItem(_e);
251
255
  },
252
256
  subscribe: (s) => (t.add(s), () => t.delete(s)),
253
257
  close: () => {
@@ -255,8 +259,8 @@ function Es() {
255
259
  }
256
260
  };
257
261
  }
258
- const Dt = "schedule_follow_up";
259
- function Cs(t) {
262
+ const Ot = "schedule_follow_up";
263
+ function Us(t) {
260
264
  let e = t;
261
265
  if (typeof e == "string")
262
266
  try {
@@ -267,11 +271,11 @@ function Cs(t) {
267
271
  if (!e || typeof e != "object")
268
272
  return null;
269
273
  const s = e;
270
- return s.ok !== !0 || s.toolName !== Dt || typeof s.dueAt != "string" || Number.isNaN(Date.parse(s.dueAt)) ? null : s.dueAt;
274
+ return s.ok !== !0 || s.toolName !== Ot || typeof s.dueAt != "string" || Number.isNaN(Date.parse(s.dueAt)) ? null : s.dueAt;
271
275
  }
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
- function dt(t) {
276
+ const Ds = globalThis.fetch.bind(globalThis), qe = '.pluno-pa-widget-host[data-pluno-product-agent-ui="widget"]', vs = '.pluno-pa-widget[data-pluno-product-agent-ui-root="widget"]', Ns = ".pluno-pa-widget__panel", Os = ".pluno-pa-widget__timeline", pt = `${qe}[data-pluno-sdk-preview-channel]`;
277
+ let xs = 0;
278
+ function ht(t) {
275
279
  const e = {};
276
280
  for (const o of [
277
281
  "type",
@@ -309,7 +313,7 @@ function dt(t) {
309
313
  }
310
314
  return e;
311
315
  }
312
- function ke(t, e, s) {
316
+ function Pe(t, e, s) {
313
317
  if (typeof window > "u")
314
318
  return;
315
319
  const n = window.__PLUNO_PRODUCT_AGENT_TRACE_ID__;
@@ -321,31 +325,31 @@ function ke(t, e, s) {
321
325
  source: "web_sdk",
322
326
  category: t,
323
327
  name: e,
324
- sequence: ++Us,
328
+ sequence: ++xs,
325
329
  wallTime: (/* @__PURE__ */ new Date()).toISOString(),
326
330
  monotonicMs: performance.now(),
327
331
  data: s
328
332
  };
329
333
  window.dispatchEvent(new CustomEvent("product-agent:trace", { detail: r }));
330
334
  }
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([
335
+ const Ls = "https://app.pluno.ai", Bs = "gpt-5.6-terra", qs = 2e4, Ws = 1e4, Hs = 1e4, $s = 1e4, js = 1e4, Fs = 3e3, zs = 3e4, Ks = 1e3, gt = 3e4, ft = 0.2, mt = 6e4, Gs = 15e3, Y = 8, Xs = "Pluno could not finish this message. Try it again.", Vs = "Browser connection was interrupted.", yt = 15e3, Js = "Pluno could not send this message. Try it again.", It = 2e3, Ys = 1e3, Qs = 100, Tt = 8e3, wt = 3, Zs = [300, 1e3], xt = 50 * 1024 * 1024, en = /* @__PURE__ */ new Set([
332
336
  ".jpeg:image/jpeg",
333
337
  ".jpg:image/jpeg",
334
338
  ".pdf:application/pdf",
335
339
  ".png:image/png",
336
340
  ".webp:image/webp"
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) {
341
+ ]), di = ".pdf,.png,.jpg,.jpeg,.webp", Ye = 64e3, Ue = 4e3, Qe = 30, tn = 2e3, sn = 1e3, Lt = "Image is too large for model vision input.", nn = 100, Bt = "pluno.productAgent.state.", We = "pluno.productAgent.pendingEvents.", me = "pluno.productAgent.activeToolCalls.", rn = 100;
342
+ function Q(t, e = 0) {
339
343
  const s = t === 0 ? 0 : Math.min(3e4, 1e3 * 2 ** (t - 1));
340
344
  return Math.max(e, s);
341
345
  }
342
- const ce = /* @__PURE__ */ new Set();
343
- let ne = null;
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
+ const pe = /* @__PURE__ */ new Set();
347
+ let ie = null;
348
+ function on(t, e = Math.random) {
349
+ const s = Math.min(gt, Ks * 2 ** t), n = 1 - ft + e() * ft * 2;
350
+ return Math.min(gt, Math.round(s * n));
347
351
  }
348
- function tn(t, e, s) {
352
+ function an(t, e, s) {
349
353
  return new Promise((n, r) => {
350
354
  const i = setTimeout(() => r(new Error(s)), e);
351
355
  t.then(
@@ -358,13 +362,13 @@ function tn(t, e, s) {
358
362
  );
359
363
  });
360
364
  }
361
- class xt {
365
+ class qt {
362
366
  constructor(e, s) {
363
367
  this.options = e, this.transportIdentity = s, this.state = {
364
368
  ...this.state,
365
- starterPrompts: xn(e.initialStarterPrompts)
369
+ starterPrompts: Hn(e.initialStarterPrompts)
366
370
  };
367
- const n = e.restorePersistedState === !1 ? null : Cr(e.clientId, e.expectedPersistedSessionId);
371
+ const n = e.restorePersistedState === !1 ? null : Pr(e.clientId, e.expectedPersistedSessionId);
368
372
  n && (this.state = {
369
373
  ...this.state,
370
374
  ...n,
@@ -376,17 +380,18 @@ class xt {
376
380
  assistantDraftRespondsToUserMessageId: null,
377
381
  assistantDraftRunId: null,
378
382
  pendingMessageStatus: null,
383
+ turnPhase: null,
379
384
  isThinking: !1,
380
385
  isRetrying: !1,
381
386
  lastError: null
382
- }), this.queuedClientEvents = vr(
383
- _r(e.clientId),
384
- Pr(e.clientId)
387
+ }), this.queuedClientEvents = xr(
388
+ Dr(e.clientId),
389
+ vr(e.clientId)
385
390
  );
386
391
  const r = [...this.queuedClientEvents].reverse().find(
387
392
  (i) => i.type === "chat.user_message" && typeof i.clientMessageId == "string"
388
393
  );
389
- r?.clientMessageId && (this.pendingClientMessageId = r.clientMessageId, this.pendingUserMessageEvent = r, this.state.pendingMessageStatus = "reconnecting"), q(e.clientId, this.queuedClientEvents);
394
+ r?.clientMessageId && (this.pendingClientMessageId = r.clientMessageId, this.pendingUserMessageEvent = r, this.state.pendingMessageStatus = "reconnecting", this.state.turnPhase = "sending"), $(e.clientId, this.queuedClientEvents);
390
395
  }
391
396
  options;
392
397
  listeners = {};
@@ -444,6 +449,7 @@ class xt {
444
449
  attachmentFiles = /* @__PURE__ */ new Map();
445
450
  sessionBrowserApisCleanup = null;
446
451
  activeBrowserToolCalls = /* @__PURE__ */ new Map();
452
+ stoppedTurns = [];
447
453
  pendingToolLoadingByCallId = /* @__PURE__ */ new Map();
448
454
  terminalToolCallIds = /* @__PURE__ */ new Set();
449
455
  nonTranscriptToolCallIds = /* @__PURE__ */ new Set();
@@ -467,6 +473,7 @@ class xt {
467
473
  assistantDraftRespondsToUserMessageId: null,
468
474
  assistantDraftRunId: null,
469
475
  pendingMessageStatus: null,
476
+ turnPhase: null,
470
477
  isThinking: !1,
471
478
  isRetrying: !1,
472
479
  lastError: null,
@@ -474,17 +481,17 @@ class xt {
474
481
  lastErrorSecuritySettingsUrl: null
475
482
  };
476
483
  static async init(e) {
477
- const s = await Ss(), n = new xt({
484
+ const s = await Cs(), n = new qt({
478
485
  ...e,
479
- backendUrl: Sn(e.backendUrl ?? Ds),
480
- clientId: e.clientId ?? Hn(),
481
- model: e.model ?? vs,
486
+ backendUrl: Cn(e.backendUrl ?? Ls),
487
+ clientId: e.clientId ?? Kn(),
488
+ model: e.model ?? Bs,
482
489
  productVariant: e.productVariant ?? "customer_embedded",
483
- entrySurface: Mn(e.entrySurface)
490
+ entrySurface: bn(e.entrySurface)
484
491
  }, s);
485
492
  try {
486
- us().catch((r) => {
487
- M("web-sdk.attachments", "Failed to delete stale Product Agent attachments", {
493
+ hs().catch((r) => {
494
+ R("web-sdk.attachments", "Failed to delete stale Product Agent attachments", {
488
495
  message: r instanceof Error ? r.message : String(r)
489
496
  });
490
497
  }), e.disableNetworkCapture || n.enableNetworkCapture(), n.startPageLifecycleRecovery(), n.startStarterPromptUrlWatcher(), e.autoConnect !== !1 && await n.connect();
@@ -514,15 +521,15 @@ class xt {
514
521
  this.state.status === "reconnecting" ? { status: "reconnecting" } : { status: "connecting", lastError: null }
515
522
  );
516
523
  try {
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")
524
+ if (this.token = this.options.token ?? (this.options.tokenProvider ? await an(this.options.tokenProvider(), Hs, "Pluno token provider timed out") : null), e !== this.connectionAttemptId || this.state.status === "closed")
518
525
  return;
519
526
  if (!this.token && !this.options.webSocketFactory)
520
527
  throw new Error("Pluno requires a token or tokenProvider");
521
- const s = En(this.options.backendUrl), n = this.options.webSocketFactory?.(s) ?? new WebSocket(s);
528
+ const s = Pn(this.options.backendUrl), n = this.options.webSocketFactory?.(s) ?? new WebSocket(s);
522
529
  this.socket = n, this.socketConnectTimer = window.setTimeout(() => {
523
- this.socket === n && n.readyState === WebSocket.CONNECTING && (M("web-sdk.agent", "Pluno socket opening timed out; reconnecting"), this.replaceTimedOutSocket(n));
524
- }, Ls), n.addEventListener("open", () => {
525
- this.socket !== n || (this.clearSocketConnectTimer(), M("web-sdk.agent", "Pluno socket opened", {
530
+ this.socket === n && n.readyState === WebSocket.CONNECTING && (R("web-sdk.agent", "Pluno socket opening timed out; reconnecting"), this.replaceTimedOutSocket(n));
531
+ }, $s), n.addEventListener("open", () => {
532
+ this.socket !== n || (this.clearSocketConnectTimer(), R("web-sdk.agent", "Pluno socket opened", {
526
533
  queuedClientEventCount: this.queuedClientEvents.length,
527
534
  isThinking: this.state.isThinking
528
535
  }), !(this.token ? this.sendNow({
@@ -532,19 +539,19 @@ class xt {
532
539
  transportId: this.transportIdentity.transportId,
533
540
  pageUrl: location.href
534
541
  }) : !0)) || (this.socketAuthTimer = window.setTimeout(() => {
535
- this.socket === n && (M("web-sdk.agent", "Pluno socket authentication timed out; reconnecting"), this.replaceTimedOutSocket(n));
536
- }, qs));
542
+ this.socket === n && (R("web-sdk.agent", "Pluno socket authentication timed out; reconnecting"), this.replaceTimedOutSocket(n));
543
+ }, js));
537
544
  }), n.addEventListener("message", (r) => {
538
- this.socket === n && this.handleServerEvent(Nn(r.data));
545
+ this.socket === n && this.handleServerEvent(qn(r.data));
539
546
  }), n.addEventListener("sendfailure", (r) => {
540
547
  if (this.socket !== n)
541
548
  return;
542
- const i = On(r?.detail?.data);
549
+ const i = Wn(r?.detail?.data);
543
550
  i?.type === "chat.user_message" && i.clientMessageId === this.pendingClientMessageId && !this.queuedClientEvents.some(
544
551
  (o) => o.type === "chat.user_message" && o.clientMessageId === i.clientMessageId
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();
552
+ ) && (this.queuedClientEvents.push(i), $(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();
546
553
  }), n.addEventListener("close", (r) => {
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", {
554
+ this.socket === n && (this.clearSocketPhaseTimers(), this.stopHeartbeat(), this.socket = null, this.state.status !== "closed" && (this.rememberBrowserConnectionInterruptionForActiveRun(), R("web-sdk.agent", "Pluno socket closed; scheduling reconnect", {
548
555
  code: typeof r?.code == "number" ? r.code : null,
549
556
  reason: typeof r?.reason == "string" ? r.reason : "",
550
557
  wasClean: typeof r?.wasClean == "boolean" ? r.wasClean : null,
@@ -552,7 +559,7 @@ class xt {
552
559
  isThinking: this.state.isThinking
553
560
  }), this.setReconnectingState(), this.scheduleReconnect()));
554
561
  }), n.addEventListener("error", () => {
555
- this.socket !== n || this.state.status === "closed" || (M("web-sdk.agent", "Pluno socket error; scheduling reconnect", {
562
+ this.socket !== n || this.state.status === "closed" || (R("web-sdk.agent", "Pluno socket error; scheduling reconnect", {
556
563
  queuedClientEventCount: this.queuedClientEvents.length,
557
564
  isThinking: this.state.isThinking
558
565
  }), this.clearSocketPhaseTimers(), this.stopHeartbeat(), this.socket = null, this.rememberBrowserConnectionInterruptionForActiveRun(), this.setReconnectingState(), this.scheduleReconnect(), n.readyState !== WebSocket.CLOSED && n.readyState !== WebSocket.CLOSING && n.close());
@@ -575,15 +582,15 @@ class xt {
575
582
  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;
576
583
  }
577
584
  destroy() {
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 = [];
585
+ this.disconnect(), this.locationChangeCleanup?.(), this.locationChangeCleanup = null, this.cleanupSessionBrowserApis(), this.pageLifecycleCleanup?.(), this.pageLifecycleCleanup = null, this.activeBrowserToolCalls.clear(), Lr(this.options.clientId), this.transportIdentity.release(), this.networkCaptureCleanup?.(), this.networkCaptureCleanup = null, this.networkBatchTimer !== null && (window.clearTimeout(this.networkBatchTimer), this.networkBatchTimer = null), this.queuedNetworkEvents = [];
579
586
  for (const e of Object.values(this.listeners))
580
587
  e?.clear();
581
588
  }
582
589
  warmup(e = "panel_open") {
583
- const s = C(), n = `${this.state.sessionId ?? "draft"}:${s.url}`, r = e === "composer_input" && this.pendingComposerWarmup?.scope === n ? this.pendingComposerWarmup : null, i = {
590
+ const s = k(), n = `${this.state.sessionId ?? "draft"}:${s.url}`, r = e === "composer_input" && this.pendingComposerWarmup?.scope === n ? this.pendingComposerWarmup : null, i = {
584
591
  type: "runtime.warmup",
585
592
  reason: e,
586
- ...e === "composer_input" ? { warmupId: r?.event.warmupId ?? L() } : {},
593
+ ...e === "composer_input" ? { warmupId: r?.event.warmupId ?? H() } : {},
587
594
  entrySurface: this.options.entrySurface,
588
595
  sessionId: this.state.sessionId ?? void 0,
589
596
  page: s
@@ -598,23 +605,23 @@ class xt {
598
605
  }
599
606
  async sendMessage(e, s = {}) {
600
607
  const n = e.trim(), r = s.attachments ?? [];
601
- if (this.options.productVariant === "customer_embedded" && (r.forEach(Jt), r.reduce(
602
- (T, f) => T + f.sizeBytes,
608
+ if (this.options.productVariant === "customer_embedded" && (r.forEach(Zt), r.reduce(
609
+ (m, b) => m + b.sizeBytes,
603
610
  0
604
- ) > vt))
611
+ ) > xt))
605
612
  throw new Error("Embedded attachments must total at most 50 MB per message");
606
- let i = r.map(Ze);
613
+ let i = r.map(tt);
607
614
  if (!n && i.length === 0)
608
615
  return null;
609
616
  if (this.pendingClientMessageId)
610
617
  throw new Error("Wait for the current message to finish sending before sending another.");
611
- const o = C(), a = s.clientMessageId ?? L(), l = {
618
+ const o = k(), a = s.clientMessageId ?? H(), l = {
612
619
  id: `local-${a}`,
613
620
  role: "user",
614
621
  content: n,
615
622
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
616
623
  ...r.length > 0 ? { attachments: r } : {}
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 = {
624
+ }, c = this.state.messages.some((w) => w.id === l.id || w.clientMessageId === a), p = this.state.isThinking, g = this.state.pendingMessageStatus, T = this.state.turnPhase, h = this.state.messages, u = c ? this.state.messages : [...this.state.messages, l], d = {
618
625
  assistantDraft: this.state.assistantDraft,
619
626
  assistantDraftItemId: this.state.assistantDraftItemId,
620
627
  assistantDraftPhase: this.state.assistantDraftPhase,
@@ -623,7 +630,7 @@ class xt {
623
630
  lastError: this.state.lastError
624
631
  };
625
632
  this.setState({
626
- messages: y,
633
+ messages: u,
627
634
  ...p ? {} : {
628
635
  assistantDraft: "",
629
636
  assistantDraftItemId: null,
@@ -632,46 +639,48 @@ class xt {
632
639
  assistantDraftRunId: null
633
640
  },
634
641
  pendingMessageStatus: "sending",
642
+ turnPhase: p ? T : "sending",
635
643
  isThinking: p,
636
644
  isRetrying: !1,
637
645
  lastError: null
638
646
  }), c || this.emit("message", l);
639
647
  try {
640
- const m = [];
641
- for (const T of i) {
642
- const f = T.id ? this.attachmentFiles.get(T.id) : void 0;
643
- if (T.sandboxPath || T.storageKey) {
644
- m.push(T);
648
+ const w = [];
649
+ for (const m of i) {
650
+ const b = m.id ? this.attachmentFiles.get(m.id) : void 0;
651
+ if (m.sandboxPath || m.storageKey) {
652
+ w.push(m);
645
653
  continue;
646
654
  }
647
- if (!f)
648
- throw new Error(`Attachment bytes are unavailable for ${T.name}`);
649
- m.push(await this.uploadAttachmentForMessage({ file: f, attachment: T }));
655
+ if (!b)
656
+ throw new Error(`Attachment bytes are unavailable for ${m.name}`);
657
+ w.push(await this.uploadAttachmentForMessage({ file: b, attachment: m }));
650
658
  }
651
- i = m;
652
- } catch (m) {
659
+ i = w;
660
+ } catch (w) {
653
661
  throw this.setState({
654
- ...c ? {} : { messages: w },
655
- ...p ? {} : { ...u, isThinking: !1 },
656
- pendingMessageStatus: h
657
- }), m;
662
+ ...c ? {} : { messages: h },
663
+ ...p ? {} : { ...d, isThinking: !1 },
664
+ pendingMessageStatus: g,
665
+ turnPhase: T
666
+ }), w;
658
667
  }
659
668
  this.retryableClientMessageId = null;
660
- const d = !s.initiatedBy && this.options.capturePageContent !== !1 && this.lastUserMessagePageUrl !== o.url, g = {
669
+ const f = !s.initiatedBy && this.options.capturePageContent !== !1 && this.lastUserMessagePageUrl !== o.url, I = {
661
670
  type: "chat.user_message",
662
671
  sessionId: this.state.sessionId ?? void 0,
663
672
  clientMessageId: a,
664
673
  initiatedBy: s.initiatedBy,
665
- invocation: An(s.invocation ?? s.initiatedBy),
674
+ invocation: _n(s.invocation ?? s.initiatedBy),
666
675
  entrySurface: this.options.entrySurface,
667
676
  content: n,
668
- pageContent: d && Ye() || void 0,
677
+ pageContent: f && Ze() || void 0,
669
678
  attachments: i.length > 0 ? i : void 0,
670
679
  page: o,
671
680
  model: this.options.model,
672
- metadata: Tt(this.options.metadata)
681
+ metadata: St(this.options.metadata)
673
682
  };
674
- return s.initiatedBy || (this.lastUserMessagePageUrl = o.url), this.pendingClientMessageId = a, this.pendingUserMessageEvent = g, this.browserConnectionInterruptedClientMessageIds.delete(a), this.send(g), this.schedulePendingDeliveryAck(a), a;
683
+ return s.initiatedBy || (this.lastUserMessagePageUrl = o.url), this.pendingClientMessageId = a, this.pendingUserMessageEvent = I, this.browserConnectionInterruptedClientMessageIds.delete(a), this.send(I), this.schedulePendingDeliveryAck(a), a;
675
684
  }
676
685
  retryLastMessage() {
677
686
  const e = this.state.sessionId, s = this.retryableClientMessageId;
@@ -689,27 +698,27 @@ class xt {
689
698
  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;
690
699
  }
691
700
  createLocalAttachment(e) {
692
- this.options.productVariant === "customer_embedded" && Or(e);
693
- const s = L(), n = {
701
+ this.options.productVariant === "customer_embedded" && Br(e);
702
+ const s = H(), n = {
694
703
  id: s,
695
704
  name: e.name || "attachment",
696
- mimeType: ze(e),
705
+ mimeType: Ge(e),
697
706
  sizeBytes: e.size
698
707
  };
699
708
  this.attachmentFiles.set(s, e);
700
709
  const r = Date.now();
701
- return ls({
710
+ return ds({
702
711
  attachmentId: s,
703
712
  name: n.name,
704
713
  mimeType: n.mimeType,
705
714
  sizeBytes: n.sizeBytes,
706
715
  blob: e,
707
- origin: C().origin,
716
+ origin: k().origin,
708
717
  sessionId: this.state.sessionId ?? void 0,
709
718
  createdAt: r,
710
719
  lastUsedAt: r
711
720
  }).catch((i) => {
712
- M("web-sdk.attachments", "Failed to store Product Agent attachment", {
721
+ R("web-sdk.attachments", "Failed to store Product Agent attachment", {
713
722
  attachmentId: s,
714
723
  name: n.name,
715
724
  message: i instanceof Error ? i.message : String(i)
@@ -727,7 +736,7 @@ class xt {
727
736
  file: e,
728
737
  attachment: s
729
738
  }) {
730
- const n = this.state.sessionId, r = ze(e), i = {
739
+ const n = this.state.sessionId, r = Ge(e), i = {
731
740
  sessionId: n ?? void 0,
732
741
  attachmentId: s.id,
733
742
  clientId: this.options.clientId,
@@ -735,43 +744,43 @@ class xt {
735
744
  name: e.name || "attachment",
736
745
  mimeType: r,
737
746
  sizeBytes: e.size,
738
- page: C(),
747
+ page: k(),
739
748
  model: this.options.model,
740
- metadata: Tt(this.options.metadata),
749
+ metadata: St(this.options.metadata),
741
750
  entrySurface: this.options.entrySurface
742
751
  };
743
752
  let o;
744
753
  if (this.options.persistAttachmentUpload)
745
- o = await ae(
754
+ o = await ue(
746
755
  () => this.options.persistAttachmentUpload(i, e),
747
756
  "Failed to upload attachment"
748
757
  );
749
758
  else {
750
- const l = this.options.prepareAttachmentUpload ? await ae(
759
+ const l = this.options.prepareAttachmentUpload ? await ue(
751
760
  () => this.options.prepareAttachmentUpload(i),
752
761
  "Failed to prepare attachment upload"
753
762
  ) : await this.prepareEmbedAttachmentUpload(i);
754
- await ae(async () => {
763
+ await ue(async () => {
755
764
  const c = await fetch(new URL(l.uploadUrl, this.options.backendUrl), {
756
765
  method: l.uploadMethod,
757
766
  headers: l.uploadHeaders,
758
767
  body: e
759
768
  });
760
769
  if (!c.ok)
761
- throw new ue("Failed to upload attachment", c.status);
770
+ throw new he("Failed to upload attachment", c.status);
762
771
  return c;
763
772
  }, "Failed to upload attachment"), o = l;
764
773
  }
765
774
  this.setState({ sessionId: o.sessionId });
766
- const a = Vt(o.attachment, this.options.backendUrl);
767
- return this.updateAttachmentInState(s.id, a), s.id && cs(s.id, {
775
+ const a = Qt(o.attachment, this.options.backendUrl);
776
+ return this.updateAttachmentInState(s.id, a), s.id && ps(s.id, {
768
777
  sessionId: o.sessionId,
769
778
  fileUrl: a.fileUrl,
770
779
  sandboxPath: a.sandboxPath,
771
780
  storageKey: a.storageKey,
772
781
  lastUsedAt: Date.now()
773
782
  }).catch((l) => {
774
- M("web-sdk.attachments", "Failed to update persisted Product Agent attachment", {
783
+ R("web-sdk.attachments", "Failed to update persisted Product Agent attachment", {
775
784
  attachmentId: s.id,
776
785
  name: a.name,
777
786
  message: l instanceof Error ? l.message : String(l)
@@ -791,18 +800,18 @@ class xt {
791
800
  }
792
801
  async prepareEmbedAttachmentUpload(e) {
793
802
  let s = !1;
794
- return await ae(async () => {
803
+ return await ue(async () => {
795
804
  const n = await this.fetchEmbedAttachmentUpload(e);
796
805
  if (n.ok)
797
806
  return await n.json();
798
- if (Qr(n.status) && this.options.tokenProvider && !s) {
807
+ if (ti(n.status) && this.options.tokenProvider && !s) {
799
808
  s = !0;
800
809
  const r = await this.fetchEmbedAttachmentUpload(e);
801
810
  if (r.ok)
802
811
  return await r.json();
803
- throw new ue("Failed to prepare attachment upload", r.status);
812
+ throw new he("Failed to prepare attachment upload", r.status);
804
813
  }
805
- throw new ue("Failed to prepare attachment upload", n.status);
814
+ throw new he("Failed to prepare attachment upload", n.status);
806
815
  }, "Failed to prepare attachment upload");
807
816
  }
808
817
  async fetchEmbedAttachmentUpload(e) {
@@ -820,21 +829,42 @@ class xt {
820
829
  if (!this.state.sessionId)
821
830
  return;
822
831
  this.send({ type: "run.stop", sessionId: this.state.sessionId, reason: "user_requested" });
823
- const e = yr(
832
+ const e = Sr(
824
833
  this.state.messages,
825
834
  this.state.assistantDraftRespondsToUserMessageId,
826
835
  this.state.assistantDraftRunId,
827
836
  this.activeClientMessageId
828
837
  );
829
- this.setState({
830
- messages: oe(
838
+ this.stoppedTurns.push({
839
+ sessionId: this.state.sessionId,
840
+ ...e,
841
+ stoppedAt: null,
842
+ stoppedCausalSequence: null,
843
+ toolCallIds: new Set(
844
+ this.state.messages.filter(
845
+ (s) => Oe(
846
+ s,
847
+ e.respondsToUserMessageId,
848
+ e.runId
849
+ )
850
+ ).map((s) => s.callId).filter((s) => typeof s == "string")
851
+ )
852
+ }), this.stoppedTurns.splice(0, Math.max(0, this.stoppedTurns.length - 20));
853
+ for (const [s, n] of this.activeBrowserToolCalls)
854
+ n.event.sessionId === this.state.sessionId && this.activeBrowserToolCalls.delete(s);
855
+ kt(this.options.clientId, this.activeBrowserToolCalls.values()), this.setState({
856
+ messages: ce(
831
857
  this.state.messages,
832
858
  e.clientMessageId,
833
859
  e.runId
834
860
  ),
861
+ pendingMessageStatus: null,
835
862
  isThinking: !1,
836
- isRetrying: !1
837
- }), this.clearThinkingWatchdog();
863
+ isRetrying: !1,
864
+ lastError: null,
865
+ lastErrorCode: null,
866
+ lastErrorSecuritySettingsUrl: null
867
+ }), this.clearPendingDeliveryTimers(), this.pendingClientMessageId = null, this.pendingUserMessageEvent = null, this.clearThinkingWatchdog();
838
868
  }
839
869
  startNewSession(e = {}) {
840
870
  const s = e.notifyTransport !== !1, n = this.activeComposerWarmupId;
@@ -842,7 +872,7 @@ class xt {
842
872
  type: "session.reset",
843
873
  sessionId: this.state.sessionId ?? void 0,
844
874
  warmupId: n ?? void 0,
845
- page: C()
875
+ page: k()
846
876
  }), this.setState({
847
877
  sessionId: null,
848
878
  starterPrompts: [...this.state.starterPrompts],
@@ -859,15 +889,15 @@ class xt {
859
889
  });
860
890
  }
861
891
  listSessions(e = {}) {
862
- const s = L(), n = new Promise((i, o) => {
892
+ const s = H(), n = new Promise((i, o) => {
863
893
  const a = window.setTimeout(() => {
864
894
  this.pendingSessionHistoryRequests.delete(s), o(new Error("Session history did not respond in time"));
865
- }, yt);
895
+ }, Tt);
866
896
  this.pendingSessionHistoryRequests.set(s, { resolve: i, reject: o, timeout: a });
867
897
  }), r = {
868
898
  type: "sessions.list",
869
899
  requestId: s,
870
- page: C(),
900
+ page: k(),
871
901
  ...e.cursor ? { cursor: e.cursor } : {},
872
902
  ...e.limit ? { limit: e.limit } : {},
873
903
  ...typeof e.pinned == "boolean" ? { pinned: e.pinned } : {}
@@ -881,14 +911,14 @@ class xt {
881
911
  setSessionPinned(e, s) {
882
912
  return this.sendSessionMutation(
883
913
  this.pendingSessionPinRequests,
884
- { type: "session.pin", requestId: L(), sessionId: e, pinned: s },
914
+ { type: "session.pin", requestId: H(), sessionId: e, pinned: s },
885
915
  "Session pin did not respond in time"
886
916
  );
887
917
  }
888
918
  renameSession(e, s) {
889
919
  return this.sendSessionMutation(
890
920
  this.pendingSessionRenameRequests,
891
- { type: "session.rename", requestId: L(), sessionId: e, title: s },
921
+ { type: "session.rename", requestId: H(), sessionId: e, title: s },
892
922
  "Session rename did not respond in time"
893
923
  );
894
924
  }
@@ -897,7 +927,7 @@ class xt {
897
927
  !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
928
  type: "session.reset",
899
929
  warmupId: s,
900
- page: C()
930
+ page: k()
901
931
  }), this.clearThinkingWatchdog(), this.clearPendingDeliveryTimers(), this.pendingClientMessageId = null, this.pendingUserMessageEvent = null, this.failedUserMessageEvent = null, this.lastUserMessagePageUrl = null, this.setState({
902
932
  sessionId: e,
903
933
  assistantDraft: "",
@@ -913,13 +943,13 @@ class xt {
913
943
  }), this.send({
914
944
  type: "session.load",
915
945
  sessionId: e,
916
- page: C()
946
+ page: k()
917
947
  });
918
948
  }
919
949
  send(e) {
920
- this.sendNow(k(e)) || (e.type === "chat.user_message" && typeof e.clientMessageId == "string" && this.queuedClientEvents.some(
950
+ this.sendNow(v(e)) || (e.type === "chat.user_message" && typeof e.clientMessageId == "string" && this.queuedClientEvents.some(
921
951
  (r) => r.type === "chat.user_message" && r.clientMessageId === e.clientMessageId
922
- ) || this.queuedClientEvents.push(e), q(this.options.clientId, this.queuedClientEvents), this.setState({
952
+ ) || this.queuedClientEvents.push(e), $(this.options.clientId, this.queuedClientEvents), this.setState({
923
953
  status: "reconnecting",
924
954
  ...e.type === "chat.user_message" && e.clientMessageId === this.pendingClientMessageId ? { pendingMessageStatus: "reconnecting" } : {}
925
955
  }), this.scheduleReconnect());
@@ -935,9 +965,9 @@ class xt {
935
965
  return !1;
936
966
  const s = this.socket;
937
967
  try {
938
- return s.send(JSON.stringify(e)), ke("client_event", e.type, dt(e)), !0;
968
+ return s.send(JSON.stringify(e)), Pe("client_event", e.type, ht(e)), !0;
939
969
  } catch (n) {
940
- return M("web-sdk.agent", "Pluno socket send failed; scheduling reconnect", {
970
+ return R("web-sdk.agent", "Pluno socket send failed; scheduling reconnect", {
941
971
  message: n instanceof Error ? n.message : String(n),
942
972
  queuedClientEventCount: this.queuedClientEvents.length,
943
973
  isThinking: this.state.isThinking
@@ -969,7 +999,7 @@ class xt {
969
999
  }
970
1000
  }));
971
1001
  } catch (r) {
972
- M("web-sdk.agent", "Pluno health signal send failed", {
1002
+ R("web-sdk.agent", "Pluno health signal send failed", {
973
1003
  name: e,
974
1004
  message: r instanceof Error ? r.message : String(r)
975
1005
  });
@@ -979,9 +1009,9 @@ class xt {
979
1009
  if (this.state.starterPromptsLoading || this.transientStarterPromptsRequestInFlight || this.transientStarterPromptsRequestAttempted)
980
1010
  return;
981
1011
  this.transientStarterPromptsRequestInFlight = !0, this.transientStarterPromptsRequestAttempted = !0, this.setState({ starterPromptsLoading: !0 });
982
- const e = Cn();
1012
+ const e = Un();
983
1013
  this.sendNow(
984
- k({
1014
+ v({
985
1015
  type: "starter_prompts.page_context",
986
1016
  pageUrl: e.pageUrl,
987
1017
  pageTitle: e.pageTitle,
@@ -990,13 +1020,13 @@ class xt {
990
1020
  ) || (this.transientStarterPromptsRequestInFlight = !1, this.transientStarterPromptsRequestAttempted = !1, this.setState({ starterPromptsLoading: !1 }));
991
1021
  }
992
1022
  startStarterPromptUrlWatcher() {
993
- this.locationChangeCleanup || (this.locationChangeCleanup = bn(() => this.handleStarterPromptUrlChange()));
1023
+ this.locationChangeCleanup || (this.locationChangeCleanup = Dn(() => this.handleStarterPromptUrlChange()));
994
1024
  }
995
1025
  handleStarterPromptUrlChange() {
996
1026
  const e = location.href;
997
1027
  e !== this.lastStarterPromptPageUrl && (this.activeComposerWarmupScope && !this.activeComposerWarmupScope.endsWith(`:${e}`) && this.clearPendingComposerWarmup(), this.lastStarterPromptPageUrl = e, this.clearStarterPromptUrlRefreshTimer(), this.starterPromptUrlRefreshTimer = window.setTimeout(() => {
998
1028
  this.starterPromptUrlRefreshTimer = null, this.refreshStarterPromptsForCurrentUrl();
999
- }, Zs));
1029
+ }, rn));
1000
1030
  }
1001
1031
  refreshStarterPromptsForCurrentUrl() {
1002
1032
  this.socket?.readyState !== WebSocket.OPEN || this.state.status === "closed" || (this.setState({ starterPromptsLoading: this.state.messages.length === 0 }), this.sendNow({
@@ -1011,14 +1041,14 @@ class xt {
1011
1041
  if (this.socket?.readyState !== WebSocket.OPEN || this.queuedClientEvents.length === 0)
1012
1042
  return;
1013
1043
  const e = this.queuedClientEvents.splice(0, this.queuedClientEvents.length);
1014
- q(this.options.clientId, this.queuedClientEvents);
1044
+ $(this.options.clientId, this.queuedClientEvents);
1015
1045
  for (let s = 0; s < e.length; s += 1) {
1016
1046
  const n = e[s];
1017
- if (!this.sendNow(k(n))) {
1018
- this.queuedClientEvents.unshift(n, ...e.slice(s + 1)), q(this.options.clientId, this.queuedClientEvents);
1047
+ if (!this.sendNow(v(n))) {
1048
+ this.queuedClientEvents.unshift(n, ...e.slice(s + 1)), $(this.options.clientId, this.queuedClientEvents);
1019
1049
  return;
1020
1050
  }
1021
- q(this.options.clientId, this.queuedClientEvents);
1051
+ $(this.options.clientId, this.queuedClientEvents);
1022
1052
  }
1023
1053
  }
1024
1054
  flushPendingPassiveWarmup() {
@@ -1030,32 +1060,92 @@ class xt {
1030
1060
  return;
1031
1061
  this.clearPendingWarmupAckTimer();
1032
1062
  const s = Math.min(
1033
- Bs * 2 ** e.retryAttempt,
1034
- Ws
1063
+ Fs * 2 ** e.retryAttempt,
1064
+ zs
1035
1065
  );
1036
1066
  e.retryAttempt += 1, this.pendingWarmupAckTimer = window.setTimeout(() => {
1037
1067
  this.pendingWarmupAckTimer = null, this.flushPendingComposerWarmup();
1038
1068
  }, s);
1039
1069
  }
1070
+ findStoppedTurn(e, s) {
1071
+ if (!e)
1072
+ return null;
1073
+ const n = typeof s.clientMessageId == "string" ? s.clientMessageId : null, r = typeof s.respondsToUserMessageId == "string" ? s.respondsToUserMessageId : null, i = typeof s.runId == "string" ? s.runId : null;
1074
+ return [...this.stoppedTurns].reverse().find((o) => o.sessionId !== e ? !1 : r && o.respondsToUserMessageId ? r === o.respondsToUserMessageId : n && o.clientMessageId ? n === o.clientMessageId : !!(i && o.runId && i === o.runId)) ?? null;
1075
+ }
1076
+ findStoppedTurnForEvent(e) {
1077
+ const s = e.type === "session.item" ? P(e.item) : null;
1078
+ return this.findStoppedTurn(
1079
+ oe(e) ?? this.state.sessionId,
1080
+ s ?? e
1081
+ );
1082
+ }
1083
+ rememberDurablyStoppedTurn(e, s, n) {
1084
+ if (!e || !s || !xe(s) || this.findStoppedTurn(e, s))
1085
+ return;
1086
+ const r = O(s), i = U(s), o = typeof s.clientMessageId == "string" ? s.clientMessageId : r ? this.clientMessageIdsByUserMessageItemId.get(r) ?? null : null;
1087
+ this.stoppedTurns.push({
1088
+ sessionId: e,
1089
+ clientMessageId: o,
1090
+ respondsToUserMessageId: r,
1091
+ runId: i,
1092
+ stoppedAt: n,
1093
+ stoppedCausalSequence: N(s),
1094
+ toolCallIds: new Set(
1095
+ this.state.messages.filter(
1096
+ (a) => Oe(a, r, i)
1097
+ ).map((a) => a.callId).filter((a) => typeof a == "string")
1098
+ )
1099
+ }), this.stoppedTurns.splice(0, Math.max(0, this.stoppedTurns.length - 20));
1100
+ }
1101
+ shouldIgnoreStoppedTurnEvent(e) {
1102
+ if (e.type === "tool.status") {
1103
+ const n = typeof e.callId == "string" ? e.callId : null;
1104
+ return !!(n && this.stoppedTurns.some((r) => r.toolCallIds.has(n)));
1105
+ }
1106
+ return this.findStoppedTurnForEvent(e) ? e.type === "session.item" ? !xe(P(e.item)) : e.type !== "conversation.state" : !1;
1107
+ }
1108
+ filterStoppedSnapshotItems(e, s) {
1109
+ return e.filter((n) => {
1110
+ const r = P(n), i = r ? this.findStoppedTurn(s, r) : null;
1111
+ if (!i || r?.type === "message" && r.role === "user" || xe(r))
1112
+ return !0;
1113
+ if (i.stoppedCausalSequence !== null) {
1114
+ const o = r ? N(r) : null;
1115
+ return o === null || o <= i.stoppedCausalSequence;
1116
+ }
1117
+ if (i.stoppedAt) {
1118
+ const o = S(n, "createdAt");
1119
+ return !!(o && Date.parse(o) <= Date.parse(i.stoppedAt));
1120
+ }
1121
+ return !1;
1122
+ });
1123
+ }
1040
1124
  handleServerEvent(e) {
1041
- if (ke("server_event", e.type, dt(e)), !(e.type === "session.updated" && typeof e.warmupId == "string" && e.warmupId !== this.activeComposerWarmupId)) {
1125
+ if (Pe("server_event", e.type, ht(e)), e.type === "session.item" && this.rememberDurablyStoppedTurn(
1126
+ S(e.item, "sessionId") ?? this.state.sessionId,
1127
+ P(e.item),
1128
+ S(e.item, "createdAt")
1129
+ ), !(e.type === "session.updated" && typeof e.warmupId == "string" && e.warmupId !== this.activeComposerWarmupId)) {
1042
1130
  if (e.type === "runtime.warmup_ack" && typeof e.warmupId == "string" && e.warmupId === this.pendingComposerWarmup?.event.warmupId) {
1043
1131
  this.clearPendingWarmupAckTimer(), this.pendingComposerWarmup.acknowledged = !0;
1044
1132
  return;
1045
1133
  }
1046
1134
  if (e.type === "run.ack") {
1047
- const s = De(e), n = typeof e.clientMessageId == "string" ? e.clientMessageId : null;
1135
+ if (this.shouldIgnoreStoppedTurnEvent(e))
1136
+ return;
1137
+ const s = oe(e), n = typeof e.clientMessageId == "string" ? e.clientMessageId : null;
1048
1138
  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);
1049
1139
  return;
1050
1140
  }
1051
1141
  if (e.type === "session.updated" && this.options.keepRunsActiveOnSessionNavigation && this.state.sessionId === null && this.backgroundClientMessageIds.size > 0) {
1052
- const s = De(e);
1142
+ const s = oe(e);
1053
1143
  if (s) {
1054
1144
  this.deferredSessionUpdatedSessionIds.add(s);
1055
1145
  return;
1056
1146
  }
1057
1147
  }
1058
- if (!this.shouldIgnoreBackgroundSessionEvent(e)) {
1148
+ if (!this.shouldIgnoreBackgroundSessionEvent(e) && !this.shouldIgnoreStoppedTurnEvent(e)) {
1059
1149
  if (e.type === "run.steered") {
1060
1150
  this.handleRunSteered(e);
1061
1151
  return;
@@ -1064,121 +1154,147 @@ class xt {
1064
1154
  this.clearHeartbeatAckTimer();
1065
1155
  return;
1066
1156
  }
1067
- if (rn(e) && this.markThinkingProgress(), e.type === "auth.ok") {
1157
+ if (e.type === "run.model_started") {
1158
+ const s = typeof e.runId == "string" ? e.runId : null;
1159
+ if (!this.state.isThinking || !s || this.activeResponseRunId && this.activeResponseRunId !== s)
1160
+ return;
1161
+ this.activeResponseRunId = s, this.setState({ turnPhase: "thinking", lastError: null }), this.markThinkingProgress();
1162
+ return;
1163
+ }
1164
+ if (un(e) && this.markThinkingProgress(), e.type === "auth.ok") {
1068
1165
  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", {
1166
+ const s = $n(e), n = Object.prototype.hasOwnProperty.call(e, "appearance");
1167
+ R("web-sdk.agent", "Received auth.ok appearance", {
1071
1168
  hasAppearance: n,
1072
1169
  rawAppearance: e.appearance,
1073
1170
  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),
1171
+ }), this.runtimeHelperJavascript = jn(e.runtimeHelpers)?.javascript ?? null;
1172
+ const r = Rt(e, "starterPrompts"), i = Object.prototype.hasOwnProperty.call(e, "starterPrompts"), o = e.starterPromptsLoading === !0, a = {
1173
+ user: Gn(e.user),
1077
1174
  status: "connected",
1078
1175
  ...this.state.lastErrorCode === "connection_failed" ? { lastError: null, lastErrorCode: null } : {}
1079
1176
  };
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({
1177
+ (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 && !ae() && this.requestTransientStarterPrompts(), this.state.sessionId && this.send({
1081
1178
  type: "page.upsert",
1082
1179
  sessionId: this.state.sessionId,
1083
- page: C(),
1180
+ page: k(),
1084
1181
  model: this.options.model
1085
1182
  });
1086
1183
  return;
1087
1184
  }
1088
1185
  if (e.type === "starterPrompts.updated") {
1089
1186
  this.transientStarterPromptsRequestInFlight = !1, this.transientStarterPromptsRequestAttempted = !0, this.setState({
1090
- starterPrompts: Mt(e, "starterPrompts"),
1187
+ starterPrompts: Rt(e, "starterPrompts"),
1091
1188
  starterPromptsLoading: !1
1092
1189
  });
1093
1190
  return;
1094
1191
  }
1095
1192
  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(
1193
+ const s = Array.isArray(e.items) ? e.items : [], n = S(e.session, "id") ?? this.state.sessionId;
1194
+ for (const E of s)
1195
+ this.rememberDurablyStoppedTurn(
1196
+ n,
1197
+ P(E),
1198
+ S(E, "createdAt")
1199
+ );
1200
+ const r = K(s), i = r === null ? null : s[r], o = P(i), a = this.findStoppedTurn(n, {
1201
+ clientMessageId: o?.clientMessageId,
1202
+ respondsToUserMessageId: S(i, "id"),
1203
+ runId: o?.runId
1204
+ }), l = this.filterStoppedSnapshotItems(s, n), c = e.pendingMessageStatus === "sending" ? "sending" : e.pendingMessageStatus === "queued" ? "reconnecting" : null, p = typeof e.pendingClientMessageId == "string" ? e.pendingClientMessageId : null, g = e.isRetrying === !0, T = e.turnPhase === "sending" || e.turnPhase === "starting" || e.turnPhase === "thinking" ? e.turnPhase : null;
1205
+ c && p && (this.pendingClientMessageId = p);
1206
+ let h = tr(
1099
1207
  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
1208
+ );
1209
+ h && this.findStoppedTurn(n, {
1210
+ respondsToUserMessageId: h.respondsToUserMessageId,
1211
+ runId: h.runId
1212
+ }) && (h = void 0);
1213
+ const u = h !== void 0;
1214
+ this.rememberUserMessageClientMessageIds(l);
1215
+ const d = mr(l);
1216
+ if (d) {
1217
+ const E = yr(l, d);
1218
+ this.retryAttemptsByClientMessageId[d] = Math.max(
1219
+ this.retryAttemptsByClientMessageId[d] ?? 0,
1220
+ E
1108
1221
  );
1109
1222
  }
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(
1223
+ const f = l.filter((E) => {
1224
+ const D = P(E);
1225
+ return Ct(D) ? !1 : !D || !d || !je(D) ? !0 : ze(l, D) !== d;
1226
+ }), I = cr(
1114
1227
  this.state.messages,
1115
- jn(c, this.options.backendUrl)
1116
- ), h = At(p), w = !a && s.some(
1117
- (f) => Et(
1118
- H(f),
1228
+ Xn(f, this.options.backendUrl)
1229
+ ), w = Et(I), m = !u && l.some(
1230
+ (E) => bt(
1231
+ P(E),
1119
1232
  this.state.assistantDraft,
1120
1233
  this.state.assistantDraftItemId,
1121
1234
  this.state.assistantDraftRespondsToUserMessageId,
1122
1235
  this.state.assistantDraftRunId
1123
1236
  )
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))
1237
+ ), b = u ? h?.content ?? "" : this.state.assistantDraft, B = !!h?.content, _ = w && (!b || m), M = hr(I), X = _ && M;
1238
+ if (!w && fr(this.state.messages, l))
1126
1239
  return;
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 ? {
1240
+ this.lastUserMessagePageUrl = gr(l);
1241
+ const C = _ || a ? null : Fe(l);
1242
+ if (this.latestRecoverableClientMessageId = C, M && this.clearRetryTimers(), this.setState({
1243
+ sessionId: S(e.session, "id") ?? this.state.sessionId,
1244
+ messages: I,
1245
+ ...c ? { pendingMessageStatus: c } : {},
1246
+ ...T ? { turnPhase: T } : {},
1247
+ isRetrying: g,
1248
+ ...u ? {
1249
+ assistantDraft: h?.content ?? "",
1250
+ assistantDraftItemId: h?.itemId ?? null,
1251
+ assistantDraftPhase: h?.phase ?? null,
1252
+ assistantDraftRespondsToUserMessageId: h?.respondsToUserMessageId ?? null,
1253
+ assistantDraftRunId: h?.runId ?? null
1254
+ } : m ? {
1141
1255
  assistantDraft: "",
1142
1256
  assistantDraftItemId: null,
1143
1257
  assistantDraftPhase: null,
1144
1258
  assistantDraftRespondsToUserMessageId: null,
1145
1259
  assistantDraftRunId: null
1146
1260
  } : {},
1147
- ...u ? {
1261
+ ...B ? {
1148
1262
  isThinking: !0,
1263
+ turnPhase: "thinking",
1149
1264
  lastError: null
1150
- } : d ? {
1265
+ } : _ ? {
1151
1266
  isThinking: !1,
1152
- ...m ? {
1267
+ ...X ? {
1153
1268
  status: "connected",
1154
1269
  lastError: null,
1155
1270
  lastErrorCode: null,
1156
1271
  lastErrorSecuritySettingsUrl: null
1157
1272
  } : {}
1158
- } : T ? {
1273
+ } : C ? {
1159
1274
  isThinking: !0,
1275
+ turnPhase: T ?? this.state.turnPhase ?? "starting",
1160
1276
  lastError: null
1161
1277
  } : {}
1162
- }), d)
1278
+ }), _)
1163
1279
  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");
1280
+ else if (!a && (B || C)) {
1281
+ if (C) {
1282
+ this.activeClientMessageId = C;
1283
+ const E = K(l), D = E === null ? null : l[E];
1284
+ this.activeResponseUserMessageId = S(D, "id");
1169
1285
  }
1170
1286
  this.markThinkingProgress();
1171
1287
  }
1172
- if (l) {
1173
- const f = E(e.session, "id") ?? this.state.sessionId;
1174
- f && this.retryAfterInterruptedRun(f, l);
1288
+ if (d) {
1289
+ const E = S(e.session, "id") ?? this.state.sessionId;
1290
+ E && this.retryAfterInterruptedRun(E, d);
1175
1291
  }
1176
1292
  return;
1177
1293
  }
1178
1294
  if (e.type === "sessions.page") {
1179
1295
  const s = typeof e.requestId == "string" ? e.requestId : null, n = s ? this.pendingSessionHistoryRequests.get(s) : null;
1180
1296
  s && n && (window.clearTimeout(n.timeout), this.pendingSessionHistoryRequests.delete(s), n.resolve({
1181
- sessions: Fn(e.sessions),
1297
+ sessions: Vn(e.sessions),
1182
1298
  nextCursor: typeof e.nextCursor == "string" ? e.nextCursor : null
1183
1299
  }));
1184
1300
  return;
@@ -1193,7 +1309,7 @@ class xt {
1193
1309
  }
1194
1310
  if (e.type === "session.updated") {
1195
1311
  this.clearRunAckResyncRetryTimer();
1196
- const s = E(e.session, "id");
1312
+ const s = S(e.session, "id");
1197
1313
  s && typeof e.warmupId == "string" && e.warmupId === this.pendingComposerWarmup?.event.warmupId && (this.pendingComposerWarmup.event = {
1198
1314
  ...this.pendingComposerWarmup.event,
1199
1315
  sessionId: s
@@ -1204,10 +1320,10 @@ class xt {
1204
1320
  }
1205
1321
  if (e.type === "session.item") {
1206
1322
  this.rememberUserMessageClientMessageIds([e.item]);
1207
- const s = H(e.item);
1208
- if (He(s)) {
1323
+ const s = P(e.item);
1324
+ if (je(s)) {
1209
1325
  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);
1326
+ const r = S(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
1327
  if (r && a) {
1212
1328
  this.retryAfterInterruptedRun(r, a);
1213
1329
  return;
@@ -1217,21 +1333,21 @@ class xt {
1217
1333
  return;
1218
1334
  }
1219
1335
  }
1220
- if (Rt(s))
1336
+ if (Ct(s))
1221
1337
  return;
1222
- const n = Ht(e.item, this.options.backendUrl);
1338
+ const n = Ft(e.item, this.options.backendUrl);
1223
1339
  if (n) {
1224
1340
  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());
1341
+ n.callId && r !== void 0 && (n.loading = r, this.pendingToolLoadingByCallId.delete(n.callId)), W(n) && (this.retryableClientMessageId = null, this.clearRetryTimers(), this.clearRunAckResyncRetryTimer());
1226
1342
  const i = e.item.data;
1227
- fr(i) && this.clearRunAckResyncRetryTimer();
1228
- const o = Be(this.state.messages, n), a = At(o), l = Et(
1343
+ Tr(i) && this.clearRunAckResyncRetryTimer();
1344
+ const o = He(this.state.messages, n), a = Et(o), l = bt(
1229
1345
  i,
1230
1346
  this.state.assistantDraft,
1231
1347
  this.state.assistantDraftItemId,
1232
1348
  this.state.assistantDraftRespondsToUserMessageId,
1233
1349
  this.state.assistantDraftRunId
1234
- ), c = a && (!this.state.assistantDraft || l), p = x(n) && (c || !this.state.isThinking && this.activeClientMessageId === null);
1350
+ ), c = a && (!this.state.assistantDraft || l), p = W(n) && (c || !this.state.isThinking && this.activeClientMessageId === null);
1235
1351
  this.setState({
1236
1352
  messages: o,
1237
1353
  ...l ? {
@@ -1257,9 +1373,9 @@ class xt {
1257
1373
  }
1258
1374
  if (e.type === "chat.assistant_delta") {
1259
1375
  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;
1376
+ 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((g) => g.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
1377
  this.activeClientMessageId && (this.activeResponseUserMessageId = c, this.activeResponseRunId = p), this.setState({
1262
- messages: Be(this.state.messages, {
1378
+ messages: He(this.state.messages, {
1263
1379
  id: o,
1264
1380
  role: "assistant",
1265
1381
  content: i,
@@ -1287,9 +1403,9 @@ class xt {
1287
1403
  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
1404
  if (!(n && this.state.assistantDraftRespondsToUserMessageId ? n === this.state.assistantDraftRespondsToUserMessageId : !r || !this.state.assistantDraftRunId || r === this.state.assistantDraftRunId))
1289
1405
  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(
1406
+ 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 = Ss(
1291
1407
  this.state.messages.filter(
1292
- (c) => c.dataType !== "assistant_draft" || !Zn(
1408
+ (c) => c.dataType !== "assistant_draft" || !Oe(
1293
1409
  c,
1294
1410
  n,
1295
1411
  r
@@ -1297,11 +1413,11 @@ class xt {
1297
1413
  ),
1298
1414
  n,
1299
1415
  r,
1300
- $t
1416
+ zt
1301
1417
  );
1302
1418
  this.setState({
1303
1419
  sessionId: s,
1304
- messages: er(
1420
+ messages: rr(
1305
1421
  l,
1306
1422
  typeof e.responseId == "string" ? e.responseId : null,
1307
1423
  n,
@@ -1323,9 +1439,9 @@ class xt {
1323
1439
  if (s)
1324
1440
  this.nonTranscriptToolCallIds.add(s);
1325
1441
  else {
1326
- const n = nr(e);
1442
+ const n = ar(e);
1327
1443
  if (n) {
1328
- const r = tr(
1444
+ const r = ir(
1329
1445
  this.state.messages,
1330
1446
  n
1331
1447
  );
@@ -1378,9 +1494,9 @@ class xt {
1378
1494
  return;
1379
1495
  }
1380
1496
  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);
1497
+ const a = new Error(typeof e.message == "string" ? e.message.replace(/Product Agent/g, "Pluno") : "Pluno error"), l = kn(a.message);
1382
1498
  l && console.error(l), this.setState({
1383
- messages: oe(
1499
+ messages: ce(
1384
1500
  this.state.messages,
1385
1501
  i ?? this.activeClientMessageId,
1386
1502
  typeof e.runId == "string" ? e.runId : null
@@ -1397,9 +1513,9 @@ class xt {
1397
1513
  }
1398
1514
  }
1399
1515
  shouldIgnoreBackgroundSessionEvent(e) {
1400
- if (!this.options.keepRunsActiveOnSessionNavigation || !on(e))
1516
+ if (!this.options.keepRunsActiveOnSessionNavigation || !dn(e))
1401
1517
  return !1;
1402
- const s = De(e);
1518
+ const s = oe(e);
1403
1519
  return s ? this.deferredSessionUpdatedSessionIds.has(s) ? !0 : this.state.sessionId ? s !== this.state.sessionId : this.backgroundSessionIds.has(s) : !1;
1404
1520
  }
1405
1521
  rememberCurrentRunAsBackground() {
@@ -1409,7 +1525,7 @@ class xt {
1409
1525
  const s = typeof e.sessionId == "string" ? e.sessionId : this.state.sessionId, n = typeof e.clientMessageId == "string" ? e.clientMessageId : null;
1410
1526
  if (!(e.retryable === !0 || e.code === "transient_model_error") || !s || !n || e.code === "run_recovery_exhausted")
1411
1527
  return !1;
1412
- if (re())
1528
+ if (ae())
1413
1529
  return this.retryableClientMessageId = n, this.activeClientMessageId = n, this.latestRecoverableClientMessageId = n, this.setState({ status: "connected", isThinking: !0, isRetrying: !0, lastError: null, lastErrorCode: null }), !0;
1414
1530
  if (e.code === "run_still_active") {
1415
1531
  if (this.retryableClientMessageId = n, this.activeClientMessageId = n, this.latestRecoverableClientMessageId = n, this.setState({ status: "connected", isThinking: !0, isRetrying: !0, lastError: null, lastErrorCode: null }), this.retryTimersByClientMessageId[n] === void 0) {
@@ -1423,10 +1539,10 @@ class xt {
1423
1539
  if (this.retryTimersByClientMessageId[n] !== void 0)
1424
1540
  return !0;
1425
1541
  const i = this.retryAttemptsByClientMessageId[n] ?? 0;
1426
- if (i >= G)
1542
+ if (i >= Y)
1427
1543
  return !1;
1428
1544
  this.retryAttemptsByClientMessageId[n] = i + 1;
1429
- const o = X(
1545
+ const o = Q(
1430
1546
  i,
1431
1547
  typeof e.retryAfterMs == "number" ? e.retryAfterMs : 0
1432
1548
  );
@@ -1440,20 +1556,20 @@ class xt {
1440
1556
  }, o), !0;
1441
1557
  }
1442
1558
  retryAfterInterruptedRun(e, s) {
1443
- if (re()) {
1559
+ if (ae()) {
1444
1560
  this.retryableClientMessageId = s, this.activeClientMessageId = s, this.latestRecoverableClientMessageId = s, this.setState({ status: "connected", isThinking: !0, isRetrying: !0, lastError: null, lastErrorCode: null });
1445
1561
  return;
1446
1562
  }
1447
1563
  if (this.retryTimersByClientMessageId[s] !== void 0)
1448
1564
  return;
1449
1565
  const n = this.retryAttemptsByClientMessageId[s] ?? 0;
1450
- if (n >= G) {
1566
+ if (n >= Y) {
1451
1567
  this.reportHealthSignal("run_recovery_exhausted", {
1452
1568
  clientMessageId: s,
1453
1569
  retryAttempts: n,
1454
1570
  reason: "retry_budget_exhausted"
1455
1571
  }), this.retryableClientMessageId = s, this.setState({
1456
- messages: oe(
1572
+ messages: ce(
1457
1573
  this.state.messages,
1458
1574
  s,
1459
1575
  null
@@ -1467,7 +1583,7 @@ class xt {
1467
1583
  }
1468
1584
  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(() => {
1469
1585
  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 });
1470
- }, X(n));
1586
+ }, Q(n));
1471
1587
  }
1472
1588
  clearRetryTimers() {
1473
1589
  for (const e of Object.values(this.retryTimersByClientMessageId))
@@ -1476,10 +1592,10 @@ class xt {
1476
1592
  }
1477
1593
  rememberUserMessageClientMessageIds(e) {
1478
1594
  for (const s of e) {
1479
- const n = E(s, "id"), r = H(s);
1595
+ const n = S(s, "id"), r = P(s);
1480
1596
  n && r?.type === "message" && r.role === "user" && r.optimistic !== !0 && !n.startsWith("optimistic-user-message:") && typeof r.clientMessageId == "string" && (this.clientMessageIdsByUserMessageItemId.set(n, r.clientMessageId), r.clientMessageId === this.pendingClientMessageId && this.promotePendingDelivery(
1481
1597
  r.clientMessageId,
1482
- E(s, "sessionId") ?? this.state.sessionId,
1598
+ S(s, "sessionId") ?? this.state.sessionId,
1483
1599
  n,
1484
1600
  null
1485
1601
  ), r.clientMessageId === this.activeClientMessageId && (this.activeResponseUserMessageId = n));
@@ -1494,7 +1610,7 @@ class xt {
1494
1610
  const r = new Promise((i, o) => {
1495
1611
  const a = window.setTimeout(() => {
1496
1612
  e.delete(s.requestId), o(new Error(n));
1497
- }, yt);
1613
+ }, Tt);
1498
1614
  e.set(s.requestId, { resolve: i, reject: o, timeout: a });
1499
1615
  });
1500
1616
  if (!this.sendNow(s)) {
@@ -1517,7 +1633,7 @@ class xt {
1517
1633
  e.clear();
1518
1634
  }
1519
1635
  markThinkingProgress() {
1520
- !this.state.isThinking || this.state.status === "closed" || (this.scheduleThinkingWatchdog(gt), this.activeClientMessageId && this.scheduleRunAckWatchdog(this.activeClientMessageId));
1636
+ !this.state.isThinking || this.state.status === "closed" || (this.scheduleThinkingWatchdog(mt), this.activeClientMessageId && this.scheduleRunAckWatchdog(this.activeClientMessageId));
1521
1637
  }
1522
1638
  scheduleThinkingWatchdog(e) {
1523
1639
  this.thinkingWatchdogTimer !== null && window.clearTimeout(this.thinkingWatchdogTimer), this.thinkingWatchdogTimer = window.setTimeout(() => {
@@ -1552,6 +1668,7 @@ class xt {
1552
1668
  this.clearPendingDeliveryTimers(), this.pendingClientMessageId = null, this.pendingUserMessageEvent = null, this.failedUserMessageEvent = null, this.activeClientMessageId = e, this.activeResponseUserMessageId = n, this.activeResponseRunId = r, this.activeUserMessageEvent = i, this.latestRecoverableClientMessageId = e, this.setState({
1553
1669
  sessionId: s ?? this.state.sessionId,
1554
1670
  pendingMessageStatus: null,
1671
+ turnPhase: "starting",
1555
1672
  status: "connected",
1556
1673
  isThinking: !0,
1557
1674
  isRetrying: !1,
@@ -1560,21 +1677,21 @@ class xt {
1560
1677
  }), this.markThinkingProgress();
1561
1678
  }
1562
1679
  schedulePendingDeliveryAck(e) {
1563
- this.clearPendingDeliveryTimers(), !re() && (this.pendingDeliveryAckTimer = window.setTimeout(() => {
1680
+ this.clearPendingDeliveryTimers(), !ae() && (this.pendingDeliveryAckTimer = window.setTimeout(() => {
1564
1681
  this.pendingDeliveryAckTimer = null, this.retryPendingDelivery(e);
1565
- }, ft));
1682
+ }, yt));
1566
1683
  }
1567
1684
  retryPendingDelivery(e) {
1568
1685
  if (this.state.status === "closed" || this.pendingClientMessageId !== e || !this.pendingUserMessageEvent)
1569
1686
  return;
1570
1687
  const s = this.retryAttemptsByClientMessageId[e] ?? 0;
1571
- if (s >= G) {
1688
+ if (s >= Y) {
1572
1689
  this.failPendingDelivery(e);
1573
1690
  return;
1574
1691
  }
1575
1692
  s === 0 && this.reportHealthSignal("run_ack_missed", { clientMessageId: e }), this.retryAttemptsByClientMessageId[e] = s + 1, this.setState({ pendingMessageStatus: "reconnecting" }), this.pendingDeliveryRetryTimer = window.setTimeout(() => {
1576
1693
  this.pendingDeliveryRetryTimer = null, !(this.pendingClientMessageId !== e || !this.pendingUserMessageEvent) && (this.send(this.pendingUserMessageEvent), this.setState({ pendingMessageStatus: "sending" }), this.schedulePendingDeliveryAck(e));
1577
- }, X(s, mt));
1694
+ }, Q(s, It));
1578
1695
  }
1579
1696
  failPendingDelivery(e) {
1580
1697
  if (this.pendingClientMessageId !== e)
@@ -1582,8 +1699,10 @@ class xt {
1582
1699
  const s = this.pendingUserMessageEvent;
1583
1700
  this.clearPendingDeliveryTimers(), this.pendingClientMessageId = null, this.pendingUserMessageEvent = null, this.failedUserMessageEvent = s, this.retryableClientMessageId = e, this.setState({
1584
1701
  pendingMessageStatus: null,
1702
+ // A failed follow-up delivery must not hide an older acknowledged response that is still active.
1703
+ ...this.state.isThinking ? {} : { turnPhase: null },
1585
1704
  isRetrying: !1,
1586
- lastError: zs,
1705
+ lastError: Js,
1587
1706
  lastErrorCode: "message_delivery_failed"
1588
1707
  });
1589
1708
  }
@@ -1598,7 +1717,7 @@ class xt {
1598
1717
  s,
1599
1718
  typeof e.runId == "string" ? e.runId : null
1600
1719
  ), !(!this.state.isThinking || !s) && this.setState({
1601
- messages: Tr(
1720
+ messages: Ar(
1602
1721
  this.state.messages,
1603
1722
  s
1604
1723
  )
@@ -1607,10 +1726,10 @@ class xt {
1607
1726
  scheduleRunAckWatchdog(e) {
1608
1727
  this.runAckWatchdogTimer !== null && window.clearTimeout(this.runAckWatchdogTimer), this.runAckWatchdogTimer = window.setTimeout(() => {
1609
1728
  this.runAckWatchdogTimer = null, this.recoverMissedRunAck(e);
1610
- }, ft);
1729
+ }, yt);
1611
1730
  }
1612
1731
  recoverMissedRunAck(e) {
1613
- !this.state.isThinking || this.state.status === "closed" || this.activeClientMessageId !== e || (M("web-sdk.agent", "Pluno run ack missed; resyncing session", {
1732
+ !this.state.isThinking || this.state.status === "closed" || this.activeClientMessageId !== e || (R("web-sdk.agent", "Pluno run ack missed; resyncing session", {
1614
1733
  sessionId: this.state.sessionId,
1615
1734
  clientMessageId: e
1616
1735
  }), this.reportHealthSignal("run_ack_missed", { clientMessageId: e }), this.resyncThinkingSession(), this.scheduleRunAckResyncRetry(e));
@@ -1618,12 +1737,12 @@ class xt {
1618
1737
  scheduleRunAckResyncRetry(e) {
1619
1738
  this.clearRunAckResyncRetryTimer();
1620
1739
  const s = this.retryAttemptsByClientMessageId[e] ?? 0;
1621
- s >= G || (this.runAckResyncRetryTimer = window.setTimeout(() => {
1740
+ s >= Y || (this.runAckResyncRetryTimer = window.setTimeout(() => {
1622
1741
  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({
1623
1742
  status: this.state.status === "reconnecting" ? "reconnecting" : "connected",
1624
1743
  isThinking: !0,
1625
1744
  lastError: null
1626
- }), M("web-sdk.agent", "Pluno run ack recovery retrying last user message", {
1745
+ }), R("web-sdk.agent", "Pluno run ack recovery retrying last user message", {
1627
1746
  sessionId: this.state.sessionId,
1628
1747
  clientMessageId: e
1629
1748
  }), this.state.sessionId ? this.send({
@@ -1631,8 +1750,8 @@ class xt {
1631
1750
  sessionId: this.state.sessionId,
1632
1751
  clientMessageId: e,
1633
1752
  automatic: !0
1634
- }) : this.activeUserMessageEvent && this.send(this.activeUserMessageEvent), this.scheduleThinkingWatchdog(gt)));
1635
- }, X(s, mt)));
1753
+ }) : this.activeUserMessageEvent && this.send(this.activeUserMessageEvent), this.scheduleThinkingWatchdog(mt)));
1754
+ }, Q(s, It)));
1636
1755
  }
1637
1756
  clearRunAckResyncRetryTimer() {
1638
1757
  this.runAckResyncRetryTimer !== null && (window.clearTimeout(this.runAckResyncRetryTimer), this.runAckResyncRetryTimer = null);
@@ -1645,7 +1764,7 @@ class xt {
1645
1764
  return;
1646
1765
  const e = this.activeClientMessageId;
1647
1766
  if (!e) {
1648
- M("web-sdk.agent", "Pluno thinking watchdog stopped without a recoverable message id", {
1767
+ R("web-sdk.agent", "Pluno thinking watchdog stopped without a recoverable message id", {
1649
1768
  sessionId: this.state.sessionId
1650
1769
  }), this.reportHealthSignal("run_recovery_exhausted", {
1651
1770
  reason: "missing_client_message_id"
@@ -1657,8 +1776,8 @@ class xt {
1657
1776
  return;
1658
1777
  }
1659
1778
  const s = this.thinkingWatchdogResyncAttemptsByClientMessageId[e] ?? 0, n = this.retryAttemptsByClientMessageId[e] ?? 0;
1660
- if (n >= G) {
1661
- M("web-sdk.agent", "Pluno run recovery retry exhausted", {
1779
+ if (n >= Y) {
1780
+ R("web-sdk.agent", "Pluno run recovery retry exhausted", {
1662
1781
  sessionId: this.state.sessionId,
1663
1782
  clientMessageId: e
1664
1783
  }), this.reportHealthSignal("run_recovery_exhausted", {
@@ -1666,7 +1785,7 @@ class xt {
1666
1785
  retryAttempts: n,
1667
1786
  reason: "retry_budget_exhausted"
1668
1787
  }), this.retryableClientMessageId = e, this.setState({
1669
- messages: oe(
1788
+ messages: ce(
1670
1789
  this.state.messages,
1671
1790
  e,
1672
1791
  null
@@ -1678,18 +1797,18 @@ class xt {
1678
1797
  return;
1679
1798
  }
1680
1799
  if (s < 1) {
1681
- this.thinkingWatchdogResyncAttemptsByClientMessageId[e] = s + 1, M("web-sdk.agent", "Pluno thinking watchdog resyncing session", {
1800
+ this.thinkingWatchdogResyncAttemptsByClientMessageId[e] = s + 1, R("web-sdk.agent", "Pluno thinking watchdog resyncing session", {
1682
1801
  sessionId: this.state.sessionId,
1683
1802
  clientMessageId: e,
1684
1803
  resyncAttempts: s + 1
1685
- }), this.resyncThinkingSession(), this.scheduleThinkingWatchdog($s);
1804
+ }), this.resyncThinkingSession(), this.scheduleThinkingWatchdog(Gs);
1686
1805
  return;
1687
1806
  }
1688
1807
  this.setState({
1689
1808
  status: this.state.status === "reconnecting" ? "reconnecting" : "connected",
1690
1809
  isThinking: !0,
1691
1810
  lastError: null
1692
- }), M("web-sdk.agent", "Pluno thinking watchdog scheduling retry for last user message", {
1811
+ }), R("web-sdk.agent", "Pluno thinking watchdog scheduling retry for last user message", {
1693
1812
  sessionId: this.state.sessionId,
1694
1813
  clientMessageId: e,
1695
1814
  retryAttempts: n + 1
@@ -1700,32 +1819,32 @@ class xt {
1700
1819
  clientMessageId: e,
1701
1820
  automatic: !0
1702
1821
  }) : this.activeUserMessageEvent && this.send(this.activeUserMessageEvent), this.markThinkingProgress();
1703
- }, X(n)));
1822
+ }, Q(n)));
1704
1823
  }
1705
1824
  resyncThinkingSession() {
1706
1825
  this.state.sessionId ? this.send({
1707
1826
  type: "page.upsert",
1708
1827
  sessionId: this.state.sessionId,
1709
- page: C(),
1828
+ page: k(),
1710
1829
  model: this.options.model
1711
1830
  }) : (!this.socket || this.socket.readyState !== WebSocket.OPEN) && (this.setReconnectingState(), this.scheduleReconnect());
1712
1831
  }
1713
1832
  async executeToolCall(e) {
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(
1833
+ 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 = F(
1715
1834
  typeof e.summary == "string" ? e.summary : "Running browser tool"
1716
1835
  ), o = e.rawInput;
1717
1836
  if (!s || !n || !r)
1718
1837
  return;
1719
1838
  const a = r === "execute_code", l = r === "execute_code_in_browser_tab" && o !== null && typeof o == "object" && o.tabId === "local:current";
1720
- if (!a && !l || !Wr(o)) {
1839
+ if (!a && !l || !jr(o)) {
1721
1840
  this.setToolMessageLoading(n, !1), this.send({
1722
1841
  type: "tool.result",
1723
1842
  sessionId: s,
1724
1843
  callId: n,
1725
1844
  toolName: r,
1726
1845
  summary: i,
1727
- rawInput: k(o),
1728
- rawOutput: k({
1846
+ rawInput: v(o),
1847
+ rawOutput: v({
1729
1848
  ok: !1,
1730
1849
  toolName: r,
1731
1850
  error: `Unsupported browser tool: ${r}`
@@ -1740,7 +1859,7 @@ class xt {
1740
1859
  callId: n,
1741
1860
  toolName: r,
1742
1861
  summary: i,
1743
- rawInput: k(o),
1862
+ rawInput: v(o),
1744
1863
  rawOutput: {
1745
1864
  ok: !1,
1746
1865
  toolName: r,
@@ -1756,7 +1875,7 @@ class xt {
1756
1875
  callId: n,
1757
1876
  toolName: r,
1758
1877
  summary: i,
1759
- rawInput: k(o),
1878
+ rawInput: v(o),
1760
1879
  rawOutput: null
1761
1880
  },
1762
1881
  startedAtMs: Date.now(),
@@ -1764,26 +1883,26 @@ class xt {
1764
1883
  startedAtOrigin: location.origin
1765
1884
  }), this.installSessionBrowserApis();
1766
1885
  let c = null, p;
1767
- c = await this.executeRuntimeHelper(), p = await wt(
1886
+ c = await this.executeRuntimeHelper(), p = await Mt(
1768
1887
  o,
1769
- Tn(e.runtimeContext, this.options.backendUrl)
1770
- ).catch((h) => ({
1888
+ Rn(e.runtimeContext, this.options.backendUrl)
1889
+ ).catch((g) => ({
1771
1890
  ok: !1,
1772
1891
  exception: {
1773
- message: h instanceof Error ? h.message : String(h)
1892
+ message: g instanceof Error ? g.message : String(g)
1774
1893
  }
1775
- })), this.activeBrowserToolCalls.delete(n), this.setToolMessageLoading(n, !1), this.send({
1894
+ })), this.activeBrowserToolCalls.has(n) && (this.activeBrowserToolCalls.delete(n), this.setToolMessageLoading(n, !1), this.send({
1776
1895
  type: "tool.result",
1777
1896
  sessionId: s,
1778
1897
  callId: n,
1779
1898
  toolName: r,
1780
1899
  summary: o.summary,
1781
- rawInput: k(o),
1782
- rawOutput: k(Bn(p, c))
1783
- }), kr(this.options.clientId, this.activeBrowserToolCalls.values());
1900
+ rawInput: v(o),
1901
+ rawOutput: v(Fn(p, c))
1902
+ }), kt(this.options.clientId, this.activeBrowserToolCalls.values()));
1784
1903
  }
1785
1904
  setToolMessageLoading(e, s) {
1786
- const n = sr(
1905
+ const n = or(
1787
1906
  this.state.messages,
1788
1907
  e,
1789
1908
  s
@@ -1794,50 +1913,50 @@ class xt {
1794
1913
  if (this.pageLifecycleCleanup)
1795
1914
  return;
1796
1915
  const e = () => {
1797
- Gt(this.options.clientId, this.activeBrowserToolCalls.values());
1916
+ Jt(this.options.clientId, this.activeBrowserToolCalls.values());
1798
1917
  };
1799
1918
  window.addEventListener("pagehide", e), window.addEventListener("beforeunload", e), this.pageLifecycleCleanup = () => {
1800
1919
  window.removeEventListener("pagehide", e), window.removeEventListener("beforeunload", e);
1801
1920
  };
1802
1921
  }
1803
1922
  installSessionBrowserApis() {
1804
- this.cleanupSessionBrowserApis(), this.sessionBrowserApisCleanup = cn();
1923
+ this.cleanupSessionBrowserApis(), this.sessionBrowserApisCleanup = gn();
1805
1924
  }
1806
1925
  cleanupSessionBrowserApis() {
1807
- this.sessionBrowserApisCleanup && (yn(this.sessionBrowserApisCleanup), this.sessionBrowserApisCleanup = null);
1926
+ this.sessionBrowserApisCleanup && (Mn(this.sessionBrowserApisCleanup), this.sessionBrowserApisCleanup = null);
1808
1927
  }
1809
1928
  async executeRuntimeHelper() {
1810
1929
  if (!this.runtimeHelperJavascript?.trim())
1811
1930
  return null;
1812
- const e = await wt({
1931
+ const e = await Mt({
1813
1932
  javascript: this.runtimeHelperJavascript
1814
1933
  });
1815
- return e.ok === !1 ? Wn(e) : null;
1934
+ return e.ok === !1 ? zn(e) : null;
1816
1935
  }
1817
1936
  enableNetworkCapture() {
1818
- this.networkCaptureCleanup || (this.networkCaptureCleanup = sn((e) => {
1819
- Kr(e.url, this.options.backendUrl) || this.enqueueNetworkEvent(e);
1937
+ this.networkCaptureCleanup || (this.networkCaptureCleanup = ln((e) => {
1938
+ Vr(e.url, this.options.backendUrl) || this.enqueueNetworkEvent(e);
1820
1939
  }));
1821
1940
  }
1822
1941
  enqueueNetworkEvent(e) {
1823
- this.queuedNetworkEvents.length >= Gs || (this.queuedNetworkEvents.push(zr(e)), this.networkBatchTimer === null && (this.networkBatchTimer = window.setTimeout(() => {
1942
+ this.queuedNetworkEvents.length >= Qs || (this.queuedNetworkEvents.push(Xr(e)), this.networkBatchTimer === null && (this.networkBatchTimer = window.setTimeout(() => {
1824
1943
  this.networkBatchTimer = null;
1825
1944
  const s = this.queuedNetworkEvents.splice(0, this.queuedNetworkEvents.length);
1826
1945
  s.length === 0 || this.socket?.readyState !== WebSocket.OPEN || this.sendNow({
1827
1946
  type: "network.batch",
1828
1947
  sessionId: this.state.sessionId ?? void 0,
1829
- page: C(),
1948
+ page: k(),
1830
1949
  events: s
1831
1950
  });
1832
- }, Ks)));
1951
+ }, Ys)));
1833
1952
  }
1834
1953
  scheduleReconnect() {
1835
1954
  if (this.reconnectTimer !== null || this.state.status === "closed")
1836
1955
  return;
1837
- const e = en(this.reconnectAttempts);
1956
+ const e = on(this.reconnectAttempts);
1838
1957
  this.reconnectAttempts += 1, this.reconnectTimer = window.setTimeout(() => {
1839
1958
  this.reconnectTimer = null, this.connect().catch((s) => {
1840
- M("web-sdk.agent", "Pluno reconnect failed; retrying", {
1959
+ R("web-sdk.agent", "Pluno reconnect failed; retrying", {
1841
1960
  message: s instanceof Error ? s.message : String(s),
1842
1961
  queuedClientEventCount: this.queuedClientEvents.length,
1843
1962
  isThinking: this.state.isThinking
@@ -1849,9 +1968,9 @@ class xt {
1849
1968
  this.stopHeartbeat(), this.heartbeatTimer = window.setInterval(() => {
1850
1969
  const e = this.socket;
1851
1970
  !e || !this.sendNow({ type: "runtime.ping" }) || (this.clearHeartbeatAckTimer(), this.heartbeatAckTimer = window.setTimeout(() => {
1852
- this.socket === e && (M("web-sdk.agent", "Pluno heartbeat acknowledgement timed out; reconnecting"), this.replaceTimedOutSocket(e));
1853
- }, Os));
1854
- }, Ns);
1971
+ this.socket === e && (R("web-sdk.agent", "Pluno heartbeat acknowledgement timed out; reconnecting"), this.replaceTimedOutSocket(e));
1972
+ }, Ws));
1973
+ }, qs);
1855
1974
  }
1856
1975
  stopHeartbeat() {
1857
1976
  this.heartbeatTimer !== null && (window.clearInterval(this.heartbeatTimer), this.heartbeatTimer = null), this.clearHeartbeatAckTimer();
@@ -1878,17 +1997,21 @@ class xt {
1878
1997
  this.socket !== e || this.state.status === "closed" || (this.clearSocketPhaseTimers(), this.stopHeartbeat(), this.socket = null, this.rememberBrowserConnectionInterruptionForActiveRun(), this.setReconnectingState(), this.scheduleReconnect(), e.readyState !== WebSocket.CLOSED && e.readyState !== WebSocket.CLOSING && e.close());
1879
1998
  }
1880
1999
  setState(e) {
1881
- this.state = {
2000
+ const s = e.isThinking ?? this.state.isThinking, n = e.pendingMessageStatus !== void 0 ? e.pendingMessageStatus : this.state.pendingMessageStatus;
2001
+ let r = e.turnPhase !== void 0 ? e.turnPhase : this.state.turnPhase;
2002
+ e.turnPhase === void 0 && (e.isThinking === !1 ? r = n ? "sending" : null : s && r === null ? r = "starting" : !s && n && r === null && (r = "sending")), this.state = {
1882
2003
  ...this.state,
1883
2004
  ...e,
2005
+ turnPhase: r,
1884
2006
  ...e.lastError === null && e.lastErrorCode === void 0 ? { lastErrorCode: null } : {},
1885
2007
  ...e.lastError !== void 0 && e.lastErrorSecuritySettingsUrl === void 0 ? { lastErrorSecuritySettingsUrl: null } : {}
1886
- }, br(this.options.clientId, this.state), this.emit("state", this.getState()), ke("state", this.state.status, {
2008
+ }, Ur(this.options.clientId, this.state), this.emit("state", this.getState()), Pe("state", this.state.status, {
1887
2009
  status: this.state.status,
1888
2010
  sessionId: this.state.sessionId,
1889
2011
  messageCount: this.state.messages.length,
1890
2012
  assistantDraftLength: this.state.assistantDraft.length,
1891
2013
  isThinking: this.state.isThinking,
2014
+ turnPhase: this.state.turnPhase,
1892
2015
  hasError: this.state.lastError !== null
1893
2016
  });
1894
2017
  }
@@ -1903,61 +2026,61 @@ class xt {
1903
2026
  this.state.isThinking && this.activeClientMessageId ? this.browserConnectionInterruptedClientMessageIds.add(this.activeClientMessageId) : this.pendingClientMessageId && this.browserConnectionInterruptedClientMessageIds.add(this.pendingClientMessageId);
1904
2027
  }
1905
2028
  getRunRecoveryExhaustedErrorMessage(e) {
1906
- return e && this.browserConnectionInterruptedClientMessageIds.has(e) ? Fs : js;
2029
+ return e && this.browserConnectionInterruptedClientMessageIds.has(e) ? Vs : Xs;
1907
2030
  }
1908
2031
  emit(e, s) {
1909
2032
  this.listeners[e]?.forEach((r) => r(s));
1910
2033
  }
1911
2034
  }
1912
- const Ue = /* @__PURE__ */ new WeakMap();
1913
- function sn(t) {
1914
- const e = window.__plunoProductAgentNetworkCapture ?? nn();
2035
+ const De = /* @__PURE__ */ new WeakMap();
2036
+ function ln(t) {
2037
+ const e = window.__plunoProductAgentNetworkCapture ?? cn();
1915
2038
  return e.subscribers.add(t), () => {
1916
2039
  e.subscribers.delete(t), !(e.subscribers.size > 0) && (e.destroy(), window.__plunoProductAgentNetworkCapture === e && delete window.__plunoProductAgentNetworkCapture);
1917
2040
  };
1918
2041
  }
1919
- function nn() {
1920
- const t = /* @__PURE__ */ new Set(), e = (w) => {
1921
- t.forEach((y) => {
2042
+ function cn() {
2043
+ const t = /* @__PURE__ */ new Set(), e = (T) => {
2044
+ t.forEach((h) => {
1922
2045
  try {
1923
- y(w);
2046
+ h(T);
1924
2047
  } catch {
1925
2048
  }
1926
2049
  });
1927
- }, s = window.fetch, n = XMLHttpRequest.prototype.open, r = XMLHttpRequest.prototype.setRequestHeader, i = XMLHttpRequest.prototype.send, o = function(y, u) {
2050
+ }, s = window.fetch, n = XMLHttpRequest.prototype.open, r = XMLHttpRequest.prototype.setRequestHeader, i = XMLHttpRequest.prototype.send, o = function(h, u) {
1928
2051
  const d = Date.now();
1929
- let g;
2052
+ let f;
1930
2053
  try {
1931
- g = s.call(this, y, u);
1932
- } catch (m) {
1933
- throw m;
2054
+ f = s.call(this, h, u);
2055
+ } catch (I) {
2056
+ throw I;
1934
2057
  }
1935
2058
  try {
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)) {
1938
- const F = {
1939
- requestId: Oe("fetch"),
1940
- url: U(T, Pe),
1941
- method: (u?.method ?? m?.method ?? "GET").toUpperCase(),
1942
- requestHeaders: f,
1943
- requestBody: _t(u?.body),
2059
+ const I = h instanceof Request ? h : null, w = Fr(h, I), m = es(u?.headers ?? I?.headers);
2060
+ if (!j(w, m, u?.body)) {
2061
+ const B = {
2062
+ requestId: Le("fetch"),
2063
+ url: x(w, Ue),
2064
+ method: (u?.method ?? I?.method ?? "GET").toUpperCase(),
2065
+ requestHeaders: m,
2066
+ requestBody: Ut(u?.body),
1944
2067
  resourceType: "fetch",
1945
2068
  startedAt: new Date(d).toISOString()
1946
2069
  };
1947
- g.then(
1948
- (P) => {
1949
- $r(P, F, d, e).catch(() => {
2070
+ f.then(
2071
+ (_) => {
2072
+ zr(_, B, d, e).catch(() => {
1950
2073
  e({
1951
- ...F,
1952
- responseStatus: P.status,
2074
+ ...B,
2075
+ responseStatus: _.status,
1953
2076
  durationMs: Date.now() - d
1954
2077
  });
1955
2078
  });
1956
2079
  },
1957
- (P) => {
2080
+ (_) => {
1958
2081
  e({
1959
- ...F,
1960
- errorText: U(P instanceof Error ? P.message : String(P)),
2082
+ ...B,
2083
+ errorText: x(_ instanceof Error ? _.message : String(_)),
1961
2084
  durationMs: Date.now() - d
1962
2085
  });
1963
2086
  }
@@ -1965,30 +2088,30 @@ function nn() {
1965
2088
  }
1966
2089
  } catch {
1967
2090
  }
1968
- return g;
1969
- }, a = function(y, u, d, g, m) {
1970
- const T = n.call(this, y, u, d ?? !0, g ?? void 0, m ?? void 0), f = typeof u == "string" ? u : u.toString();
1971
- return Ue.set(this, {
1972
- requestId: Oe("xhr"),
1973
- method: String(y ?? "GET").toUpperCase(),
1974
- url: U(f, Pe),
2091
+ return f;
2092
+ }, a = function(h, u, d, f, I) {
2093
+ const w = n.call(this, h, u, d ?? !0, f ?? void 0, I ?? void 0), m = typeof u == "string" ? u : u.toString();
2094
+ return De.set(this, {
2095
+ requestId: Le("xhr"),
2096
+ method: String(h ?? "GET").toUpperCase(),
2097
+ url: x(m, Ue),
1975
2098
  requestHeaders: {},
1976
2099
  startedAtMs: Date.now(),
1977
2100
  startedAt: (/* @__PURE__ */ new Date()).toISOString(),
1978
- excluded: B(f)
1979
- }), T;
1980
- }, l = function(y, u) {
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;
1983
- }, c = function(y) {
2101
+ excluded: j(m)
2102
+ }), w;
2103
+ }, l = function(h, u) {
2104
+ const d = r.call(this, h, u), f = De.get(this);
2105
+ return f && Object.keys(f.requestHeaders).length < Qe && (f.requestHeaders[h] = st(h, u), f.excluded = f.excluded || j(f.url, f.requestHeaders)), d;
2106
+ }, c = function(h) {
1984
2107
  try {
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(
2108
+ const u = De.get(this);
2109
+ u && (u.excluded = u.excluded || j(u.url, u.requestHeaders, h), u.requestBody = Ut(h), u.excluded || this.addEventListener(
1987
2110
  "loadend",
1988
2111
  () => {
1989
2112
  queueMicrotask(() => {
1990
2113
  try {
1991
- const d = Xr(this.getAllResponseHeaders());
2114
+ const d = Yr(this.getAllResponseHeaders());
1992
2115
  e({
1993
2116
  requestId: u.requestId,
1994
2117
  url: u.url,
@@ -1998,7 +2121,7 @@ function nn() {
1998
2121
  resourceType: "xhr",
1999
2122
  responseStatus: this.status,
2000
2123
  responseHeaders: d,
2001
- responseBody: Fr(this, d),
2124
+ responseBody: Gr(this, d),
2002
2125
  errorText: this.status === 0 ? "XHR request failed or was aborted" : void 0,
2003
2126
  startedAt: u.startedAt,
2004
2127
  durationMs: Date.now() - u.startedAtMs
@@ -2012,7 +2135,7 @@ function nn() {
2012
2135
  ));
2013
2136
  } catch {
2014
2137
  }
2015
- return i.call(this, y ?? null);
2138
+ return i.call(this, h ?? null);
2016
2139
  };
2017
2140
  try {
2018
2141
  window.fetch = o;
@@ -2032,15 +2155,15 @@ function nn() {
2032
2155
  }
2033
2156
  let p = null;
2034
2157
  if (typeof PerformanceObserver < "u") {
2035
- p = new PerformanceObserver((w) => {
2036
- for (const y of w.getEntries()) {
2037
- const u = y;
2038
- if (u.initiatorType === "fetch" || u.initiatorType === "xmlhttprequest" || B(u.name))
2158
+ p = new PerformanceObserver((T) => {
2159
+ for (const h of T.getEntries()) {
2160
+ const u = h;
2161
+ if (u.initiatorType === "fetch" || u.initiatorType === "xmlhttprequest" || j(u.name))
2039
2162
  continue;
2040
2163
  const d = performance.timeOrigin + u.startTime;
2041
2164
  e({
2042
- requestId: Oe("resource"),
2043
- url: U(u.name, Pe),
2165
+ requestId: Le("resource"),
2166
+ url: x(u.name, Ue),
2044
2167
  method: "GET",
2045
2168
  resourceType: "resource",
2046
2169
  responseStatus: u.responseStatus,
@@ -2055,7 +2178,7 @@ function nn() {
2055
2178
  p.disconnect(), p = null;
2056
2179
  }
2057
2180
  }
2058
- const h = {
2181
+ const g = {
2059
2182
  subscribers: t,
2060
2183
  destroy: () => {
2061
2184
  p?.disconnect();
@@ -2077,9 +2200,9 @@ function nn() {
2077
2200
  }
2078
2201
  }
2079
2202
  };
2080
- return window.__plunoProductAgentNetworkCapture = h, h;
2203
+ return window.__plunoProductAgentNetworkCapture = g, g;
2081
2204
  }
2082
- function M(t, e, s) {
2205
+ function R(t, e, s) {
2083
2206
  if (typeof window > "u")
2084
2207
  return;
2085
2208
  const n = window, r = {
@@ -2090,17 +2213,17 @@ function M(t, e, s) {
2090
2213
  }, i = n.__plunoProductAgentDiagnostics__ ?? [];
2091
2214
  i.push(r), i.length > 120 && i.splice(0, i.length - 120), n.__plunoProductAgentDiagnostics__ = i, n.__PLUNO_PRODUCT_AGENT_DIAGNOSTICS__ = () => [...i], window.dispatchEvent(new CustomEvent("product-agent:preview-diagnostic", { detail: r }));
2092
2215
  }
2093
- function Tt(t) {
2216
+ function St(t) {
2094
2217
  const e = typeof t == "function" ? t() : t;
2095
2218
  return e && Object.keys(e).length > 0 ? e : void 0;
2096
2219
  }
2097
- function rn(t) {
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";
2220
+ function un(t) {
2221
+ return t.type === "run.model_started" || 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";
2099
2222
  }
2100
- function on(t) {
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";
2223
+ function dn(t) {
2224
+ return t.type === "run.steered" || t.type === "run.ack" || t.type === "run.model_started" || 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";
2102
2225
  }
2103
- function De(t) {
2226
+ function oe(t) {
2104
2227
  if (typeof t.sessionId == "string")
2105
2228
  return t.sessionId;
2106
2229
  if (t.session && typeof t.session == "object") {
@@ -2115,31 +2238,31 @@ function De(t) {
2115
2238
  }
2116
2239
  return null;
2117
2240
  }
2118
- const an = 5e3, ln = 12e4;
2119
- function cn() {
2241
+ const pn = 5e3, hn = 12e4;
2242
+ function gn() {
2120
2243
  const t = [
2121
- dn(),
2122
- un()
2244
+ mn(),
2245
+ fn()
2123
2246
  ].filter((e) => typeof e == "function");
2124
2247
  return () => {
2125
2248
  for (const e of t.reverse())
2126
2249
  e();
2127
2250
  };
2128
2251
  }
2129
- function un() {
2130
- return Pt(globalThis, "getPageSnapshot", async () => Ye());
2252
+ function fn() {
2253
+ return vt(globalThis, "getPageSnapshot", async () => Ze());
2131
2254
  }
2132
- function dn() {
2133
- return Pt(globalThis, "pageImages", {
2134
- inspectImage: async (e, s) => await pn(e, s)
2255
+ function mn() {
2256
+ return vt(globalThis, "pageImages", {
2257
+ inspectImage: async (e, s) => await yn(e, s)
2135
2258
  });
2136
2259
  }
2137
- async function pn(t, e = {}) {
2138
- const s = mn(e.name), n = await hn(t);
2260
+ async function yn(t, e = {}) {
2261
+ const s = Sn(e.name), n = await In(t);
2139
2262
  return n.ok ? n.sizeBytes > 8 * 1024 * 1024 ? {
2140
2263
  type: "pluno.pageImages.inspectImage",
2141
2264
  imageAttached: !1,
2142
- imageAttachmentError: Nt
2265
+ imageAttachmentError: Lt
2143
2266
  } : {
2144
2267
  type: "pluno.pageImages.inspectImage",
2145
2268
  imageAttached: !0,
@@ -2153,15 +2276,15 @@ async function pn(t, e = {}) {
2153
2276
  imageAttachmentError: n.error
2154
2277
  };
2155
2278
  }
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 } : {
2279
+ async function In(t) {
2280
+ 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: Lt } : {
2158
2281
  ok: !0,
2159
2282
  mimeType: t.type,
2160
2283
  sizeBytes: t.size,
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);
2284
+ dataUrl: await An(t)
2285
+ } : { 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." } : Tn(t);
2163
2286
  }
2164
- function gn(t) {
2287
+ function Tn(t) {
2165
2288
  if (!t.startsWith("data:") || !t.includes(","))
2166
2289
  return { ok: !1, error: "Page image must be a complete data:image/* URL, not bare base64." };
2167
2290
  const [e, s] = t.slice(5).split(",", 2), n = e.split(";").map((a) => a.trim()).filter(Boolean), r = n[0] ?? "";
@@ -2172,7 +2295,7 @@ function gn(t) {
2172
2295
  const i = s.replace(/[ \t\r\n\f]+/g, "");
2173
2296
  if (!/^[A-Za-z0-9+/]*={0,2}$/.test(i))
2174
2297
  return { ok: !1, error: "Page image data URL has invalid base64." };
2175
- const o = fn(i);
2298
+ const o = wn(i);
2176
2299
  return o === null ? { ok: !1, error: "Page image data URL has invalid base64." } : o === 0 ? { ok: !1, error: "Page image is empty." } : {
2177
2300
  ok: !0,
2178
2301
  mimeType: r,
@@ -2180,22 +2303,22 @@ function gn(t) {
2180
2303
  dataUrl: `data:${r};base64,${i}`
2181
2304
  };
2182
2305
  }
2183
- function fn(t) {
2306
+ function wn(t) {
2184
2307
  if (t.length === 0 || t.length % 4 !== 0)
2185
2308
  return null;
2186
2309
  const e = t.length - t.replace(/=+$/, "").length;
2187
2310
  return e > 2 ? null : t.length / 4 * 3 - e;
2188
2311
  }
2189
- function mn(t) {
2312
+ function Sn(t) {
2190
2313
  return (typeof t == "string" ? t.trim() : "") || "Page image";
2191
2314
  }
2192
- function yn(t) {
2315
+ function Mn(t) {
2193
2316
  try {
2194
2317
  t();
2195
2318
  } catch {
2196
2319
  }
2197
2320
  }
2198
- function In(t) {
2321
+ function An(t) {
2199
2322
  return new Promise((e, s) => {
2200
2323
  const n = new FileReader();
2201
2324
  n.onload = () => {
@@ -2207,9 +2330,9 @@ function In(t) {
2207
2330
  }, n.onerror = () => s(n.error ?? new Error("Failed to read page image")), n.readAsDataURL(t);
2208
2331
  });
2209
2332
  }
2210
- async function wt(t, e) {
2333
+ async function Mt(t, e) {
2211
2334
  const s = Object.getPrototypeOf(async function() {
2212
- }).constructor, n = t.timeoutMs ?? an, r = Date.now(), i = [];
2335
+ }).constructor, n = t.timeoutMs ?? pn, r = Date.now(), i = [];
2213
2336
  let o;
2214
2337
  const a = {
2215
2338
  log: console.log,
@@ -2223,11 +2346,11 @@ async function wt(t, e) {
2223
2346
  try {
2224
2347
  const c = /* @__PURE__ */ Symbol("execute_code_timeout"), p = await Promise.race([
2225
2348
  new s("sandboxFiles", t.javascript)(e?.value),
2226
- new Promise((h) => {
2227
- o = window.setTimeout(() => h(c), n);
2349
+ new Promise((g) => {
2350
+ o = window.setTimeout(() => g(c), n);
2228
2351
  })
2229
2352
  ]);
2230
- return p === c ? wn(n) : {
2353
+ return p === c ? En(n) : {
2231
2354
  ok: !0,
2232
2355
  result: p,
2233
2356
  console: i,
@@ -2256,7 +2379,7 @@ async function wt(t, e) {
2256
2379
  e?.deactivate(), o !== void 0 && window.clearTimeout(o), console.log = a.log, console.info = a.info, console.warn = a.warn, console.error = a.error;
2257
2380
  }
2258
2381
  }
2259
- function Tn(t, e) {
2382
+ function Rn(t, e) {
2260
2383
  if (!t || typeof t != "object")
2261
2384
  return;
2262
2385
  const s = t.sandboxFilesToken;
@@ -2266,7 +2389,7 @@ function Tn(t, e) {
2266
2389
  const r = () => {
2267
2390
  if (!n)
2268
2391
  throw new Error("sandboxFiles is only available during browser-code execution");
2269
- }, i = async (a, l) => await bs(`${e.replace(/\/$/, "")}${a}`, l);
2392
+ }, i = async (a, l) => await Ds(`${e.replace(/\/$/, "")}${a}`, l);
2270
2393
  return {
2271
2394
  value: Object.freeze({
2272
2395
  upload: async (a) => {
@@ -2289,8 +2412,8 @@ function Tn(t, e) {
2289
2412
  );
2290
2413
  if (!l.ok)
2291
2414
  throw new Error(`sandboxFiles.download failed (${l.status})`);
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", {
2415
+ const c = await l.blob(), g = (l.headers.get("content-disposition") ?? "").match(/filename="([^"]+)"/i)?.[1];
2416
+ return new File([c], g || a.split("/").pop() || "file", {
2294
2417
  type: c.type
2295
2418
  });
2296
2419
  }
@@ -2300,7 +2423,7 @@ function Tn(t, e) {
2300
2423
  }
2301
2424
  };
2302
2425
  }
2303
- function wn(t) {
2426
+ function En(t) {
2304
2427
  return {
2305
2428
  ok: !1,
2306
2429
  exception: {
@@ -2314,10 +2437,10 @@ function wn(t) {
2314
2437
  }
2315
2438
  };
2316
2439
  }
2317
- function Sn(t) {
2440
+ function Cn(t) {
2318
2441
  return t.replace(/\/+$/, "");
2319
2442
  }
2320
- function Mn(t) {
2443
+ function bn(t) {
2321
2444
  const e = {
2322
2445
  sidepanel: "extension_sidepanel",
2323
2446
  browser_extension_page_ui: "extension_widget",
@@ -2329,18 +2452,18 @@ function Mn(t) {
2329
2452
  };
2330
2453
  return t && t in e ? e[t] : t ?? "embedded_custom_ui";
2331
2454
  }
2332
- function An(t) {
2455
+ function _n(t) {
2333
2456
  return t === "pluno" ? "scheduled_continuation" : t ?? "user";
2334
2457
  }
2335
- function Rn(t, e = location.origin) {
2458
+ function kn(t, e = location.origin) {
2336
2459
  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;
2337
2460
  }
2338
- function En(t) {
2461
+ function Pn(t) {
2339
2462
  const e = new URL("/api/product-agent/embed/ws", t);
2340
2463
  return e.protocol = e.protocol === "https:" ? "wss:" : "ws:", e.toString();
2341
2464
  }
2342
- function C() {
2343
- const t = Wt();
2465
+ function k() {
2466
+ const t = jt();
2344
2467
  return {
2345
2468
  url: location.href,
2346
2469
  title: document.title,
@@ -2348,21 +2471,21 @@ function C() {
2348
2471
  ...t ? { plunoProductAgentUi: t } : {}
2349
2472
  };
2350
2473
  }
2351
- function Cn() {
2474
+ function Un() {
2352
2475
  return {
2353
2476
  pageUrl: location.href,
2354
2477
  pageTitle: document.title,
2355
- htmlContent: Ye()
2478
+ htmlContent: Ze()
2356
2479
  };
2357
2480
  }
2358
- function bn(t) {
2359
- return ce.add(t), ne || (ne = _n()), () => {
2360
- ce.delete(t), ce.size === 0 && (ne?.(), ne = null);
2481
+ function Dn(t) {
2482
+ return pe.add(t), ie || (ie = vn()), () => {
2483
+ pe.delete(t), pe.size === 0 && (ie?.(), ie = null);
2361
2484
  };
2362
2485
  }
2363
- function _n() {
2486
+ function vn() {
2364
2487
  const t = () => {
2365
- for (const i of Array.from(ce))
2488
+ for (const i of Array.from(pe))
2366
2489
  i();
2367
2490
  }, e = window.history.pushState.bind(window.history), s = window.history.replaceState.bind(window.history), n = ((...i) => {
2368
2491
  const o = e(...i);
@@ -2375,38 +2498,38 @@ function _n() {
2375
2498
  window.history.pushState === n && (window.history.pushState = e), window.history.replaceState === r && (window.history.replaceState = s), window.removeEventListener("popstate", t), window.removeEventListener("hashchange", t);
2376
2499
  };
2377
2500
  }
2378
- function re() {
2379
- return Wt()?.surface === "browser_extension_sdk_preview";
2501
+ function ae() {
2502
+ return jt()?.surface === "browser_extension_sdk_preview";
2380
2503
  }
2381
- function Ye() {
2504
+ function Ze() {
2382
2505
  if (!document.body)
2383
2506
  return "";
2384
- const t = [], e = [], s = (d, g) => {
2385
- const m = $(g);
2386
- !m || e.includes(m) || (t.push([d, m]), e.push(m));
2507
+ const t = [], e = [], s = (d, f) => {
2508
+ const I = z(f);
2509
+ !I || e.includes(I) || (t.push([d, I]), e.push(I));
2387
2510
  };
2388
2511
  s("Selected text", window.getSelection()?.toString() ?? "");
2389
2512
  const n = "[role='dialog'], [role='alertdialog'], dialog[open], [aria-modal='true']", r = Array.from(document.querySelectorAll(n)).filter(
2390
- (d) => Lt(d) && !d.parentElement?.closest(n)
2513
+ (d) => Wt(d) && !d.parentElement?.closest(n)
2391
2514
  );
2392
2515
  for (const d of r.slice(0, 3))
2393
- s("Active overlay", ve(V(d), e));
2394
- const i = kn(), o = i ? ve(V(i), e) : "";
2395
- s("Main page content", o), s("Additional visible page text", ve(V(document.body), e));
2396
- const a = t.map(([d, g]) => `${d}:
2397
- ${g}`).join(`
2516
+ s("Active overlay", ve(Z(d), e));
2517
+ const i = Nn(), o = i ? ve(Z(i), e) : "";
2518
+ s("Main page content", o), s("Additional visible page text", ve(Z(document.body), e));
2519
+ const a = t.map(([d, f]) => `${d}:
2520
+ ${f}`).join(`
2398
2521
 
2399
- `).trim().slice(0, 12e3), l = Pn(r, i).trim(), c = `Simplified DOM outline:
2522
+ `).trim().slice(0, 12e3), l = On(r, i).trim(), c = `Simplified DOM outline:
2400
2523
  `, p = `
2401
2524
 
2402
2525
  Visible page text:
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}`;
2526
+ `, g = 12e3 - c.length - p.length, T = Math.min(a.length, 7900), h = l.slice(0, g - T), u = a.slice(0, g - h.length);
2527
+ return `${c}${h}${p}${u}`;
2405
2528
  }
2406
- function V(t) {
2529
+ function Z(t) {
2407
2530
  return t.innerText ?? t.textContent ?? "";
2408
2531
  }
2409
- function $(t) {
2532
+ function z(t) {
2410
2533
  return (t ?? "").replace(/\u00a0/g, " ").replace(/\r\n?/g, `
2411
2534
  `).split(`
2412
2535
  `).map((e) => e.replace(/[ \t]+/g, " ").trim()).join(`
@@ -2415,19 +2538,19 @@ function $(t) {
2415
2538
  `).trim();
2416
2539
  }
2417
2540
  function ve(t, e) {
2418
- let s = $(t);
2541
+ let s = z(t);
2419
2542
  for (const n of e)
2420
2543
  s = s.replace(n, "");
2421
- return $(s);
2544
+ return z(s);
2422
2545
  }
2423
- function Lt(t) {
2546
+ function Wt(t) {
2424
2547
  const e = window.getComputedStyle(t);
2425
2548
  return e.display !== "none" && e.visibility !== "hidden" && t.getClientRects().length > 0;
2426
2549
  }
2427
- function kn() {
2428
- return Array.from(document.querySelectorAll("main, [role='main'], article")).filter(Lt).sort((t, e) => V(e).length - V(t).length)[0] ?? null;
2550
+ function Nn() {
2551
+ return Array.from(document.querySelectorAll("main, [role='main'], article")).filter(Wt).sort((t, e) => Z(e).length - Z(t).length)[0] ?? null;
2429
2552
  }
2430
- function Pn(t, e) {
2553
+ function On(t, e) {
2431
2554
  const s = /* @__PURE__ */ new Set([
2432
2555
  "main",
2433
2556
  "nav",
@@ -2507,92 +2630,92 @@ function Pn(t, e) {
2507
2630
  "data-test",
2508
2631
  "data-qa",
2509
2632
  "data-cy"
2510
- ], c = ["aria-label", "placeholder", "data-testid", "data-test", "data-qa", "data-cy"], { priorityElements: p, priorityTargets: h } = Un(), w = new Set(t);
2511
- e && w.add(e);
2512
- let y = 0;
2513
- const u = (f) => {
2514
- const R = f.getAttribute("role");
2515
- return R && !o.has(R) ? R : "";
2516
- }, d = (f) => {
2517
- const R = f.getAttribute("data-testid") || f.getAttribute("data-test") || f.getAttribute("data-qa") || f.getAttribute("data-cy") || "";
2518
- return `${f.tagName.toLowerCase()}|${u(f)}|${R}`;
2519
- }, g = (f, R, F) => {
2520
- const P = (A, me) => {
2521
- const b = A.tagName.toLowerCase(), ye = window.getComputedStyle(A), Z = p.has(A);
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")
2633
+ ], c = ["aria-label", "placeholder", "data-testid", "data-test", "data-qa", "data-cy"], { priorityElements: p, priorityTargets: g } = xn(), T = new Set(t);
2634
+ e && T.add(e);
2635
+ let h = 0;
2636
+ const u = (m) => {
2637
+ const b = m.getAttribute("role");
2638
+ return b && !o.has(b) ? b : "";
2639
+ }, d = (m) => {
2640
+ const b = m.getAttribute("data-testid") || m.getAttribute("data-test") || m.getAttribute("data-qa") || m.getAttribute("data-cy") || "";
2641
+ return `${m.tagName.toLowerCase()}|${u(m)}|${b}`;
2642
+ }, f = (m, b, B) => {
2643
+ const _ = (M, X) => {
2644
+ const C = M.tagName.toLowerCase(), E = window.getComputedStyle(M), D = p.has(M);
2645
+ if (h >= 1e3 && !D || B.has(M) || i.has(C) || M.matches(".pluno-pa-widget-host, [data-pluno-product-agent-widget]") || E.display === "none" || E.visibility === "hidden")
2523
2646
  return { lines: [], hasUsefulContent: !1, textPreview: "", containsTextElement: !1 };
2524
- y += 1;
2525
- const tt = u(A), ee = Bt(A), is = a.has(tt) || ["button", "input", "textarea", "select", "iframe", "canvas"].includes(b) || b === "a" && A.hasAttribute("href"), Ie = Array.from(A.children).filter((I) => I instanceof HTMLElement), te = /* @__PURE__ */ new Map();
2526
- for (const I of Ie) {
2527
- const S = d(I);
2528
- te.set(S, (te.get(S) ?? 0) + 1);
2647
+ h += 1;
2648
+ const nt = u(M), se = $t(M), ls = a.has(nt) || ["button", "input", "textarea", "select", "iframe", "canvas"].includes(C) || C === "a" && M.hasAttribute("href"), Te = Array.from(M.children).filter((y) => y instanceof HTMLElement), ne = /* @__PURE__ */ new Map();
2649
+ for (const y of Te) {
2650
+ const A = d(y);
2651
+ ne.set(A, (ne.get(A) ?? 0) + 1);
2529
2652
  }
2530
- const Te = /* @__PURE__ */ new Map(), st = /* @__PURE__ */ new Map();
2531
- for (const I of Ie) {
2532
- const S = d(I), v = st.get(S) ?? 0;
2533
- st.set(S, v + 1), (te.get(S) ?? 0) > 8 && v >= 6 && !p.has(I) && Te.set(S, (Te.get(S) ?? 0) + 1);
2653
+ const we = /* @__PURE__ */ new Map(), rt = /* @__PURE__ */ new Map();
2654
+ for (const y of Te) {
2655
+ const A = d(y), q = rt.get(A) ?? 0;
2656
+ rt.set(A, q + 1), (ne.get(A) ?? 0) > 8 && q >= 6 && !p.has(y) && we.set(A, (we.get(A) ?? 0) + 1);
2534
2657
  }
2535
- const nt = /* @__PURE__ */ new Map(), rt = /* @__PURE__ */ new Set(), we = [], it = [];
2536
- for (const I of Ie) {
2537
- const S = d(I), v = te.get(S) ?? 0, lt = nt.get(S) ?? 0;
2538
- if (nt.set(S, lt + 1), v > 8 && lt >= 6 && !p.has(I)) {
2539
- rt.has(S) || (we.push([`… ${Te.get(S) ?? 0} similar siblings omitted`]), rt.add(S));
2658
+ const it = /* @__PURE__ */ new Map(), ot = /* @__PURE__ */ new Set(), Se = [], at = [];
2659
+ for (const y of Te) {
2660
+ const A = d(y), q = ne.get(A) ?? 0, ut = it.get(A) ?? 0;
2661
+ if (it.set(A, ut + 1), q > 8 && ut >= 6 && !p.has(y)) {
2662
+ ot.has(A) || (Se.push([`… ${we.get(A) ?? 0} similar siblings omitted`]), ot.add(A));
2540
2663
  continue;
2541
2664
  }
2542
- const ct = P(I, me);
2543
- it.push(ct), we.push(ct.lines);
2665
+ const dt = _(y, X);
2666
+ at.push(dt), Se.push(dt.lines);
2544
2667
  }
2545
- const Se = [];
2546
- if (A.shadowRoot)
2547
- for (const I of Array.from(A.shadowRoot.children))
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 = $(
2550
- [ee, ...se.map((I) => I.textPreview)].filter(Boolean).join(" ")
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 = [];
2552
- if (Ae) {
2553
- const I = se.some((v) => v.containsTextElement), S = n.has(b) && !I ? ot : ee;
2554
- z.push(qt(A, l, o, S.slice(0, 180)));
2668
+ const Me = [];
2669
+ if (M.shadowRoot)
2670
+ for (const y of Array.from(M.shadowRoot.children))
2671
+ y instanceof HTMLElement && Me.push(_(y, X + 1));
2672
+ const re = [...at, ...Me], Ae = se.length > 0 || ls || re.some((y) => y.hasUsefulContent), lt = z(
2673
+ [se, ...re.map((y) => y.textPreview)].filter(Boolean).join(" ")
2674
+ ).slice(0, 180), cs = M.hasAttribute("contenteditable") && (se.length > 0 || !M.querySelector("[contenteditable]")), ct = c.some((y) => M.hasAttribute(y)) || !!nt || cs, Re = (M.getClientRects().length > 0 || E.display === "contents") && (s.has(C) || ct || D) && (Ae || D) && (!r.has(C) || Ae || ct || D), Ee = Re ? 1 : 0, V = [];
2675
+ if (Re) {
2676
+ const y = re.some((q) => q.containsTextElement), A = n.has(C) && !y ? lt : se;
2677
+ V.push(Ht(M, l, o, A.slice(0, 180)));
2555
2678
  }
2556
- for (const I of we)
2557
- z.push(...ie(I, Re));
2558
- const Ee = Se.flatMap((I) => I.lines);
2559
- if (Ee.length > 0) {
2560
- const I = Ee.slice(0, 20);
2561
- Ee.length > I.length && I.push("… shadow DOM omitted");
2562
- const S = b.includes("tooltip") || b.includes("popper") || b.includes("loader");
2563
- if (me < 2 && !S) {
2564
- const v = Ae ? "#shadow-root" : `${b} #shadow-root`;
2565
- z.push(...ie([v, ...ie(I, 1)], Re));
2679
+ for (const y of Se)
2680
+ V.push(...le(y, Ee));
2681
+ const Ce = Me.flatMap((y) => y.lines);
2682
+ if (Ce.length > 0) {
2683
+ const y = Ce.slice(0, 20);
2684
+ Ce.length > y.length && y.push("… shadow DOM omitted");
2685
+ const A = C.includes("tooltip") || C.includes("popper") || C.includes("loader");
2686
+ if (X < 2 && !A) {
2687
+ const q = Re ? "#shadow-root" : `${C} #shadow-root`;
2688
+ V.push(...le([q, ...le(y, 1)], Ee));
2566
2689
  } else
2567
- z.push(...ie(I, Re));
2690
+ V.push(...le(y, Ee));
2568
2691
  }
2569
2692
  return {
2570
- lines: z,
2571
- hasUsefulContent: Me,
2572
- textPreview: ot,
2573
- containsTextElement: n.has(b) || se.some((I) => I.containsTextElement)
2693
+ lines: V,
2694
+ hasUsefulContent: Ae,
2695
+ textPreview: lt,
2696
+ containsTextElement: n.has(C) || re.some((y) => y.containsTextElement)
2574
2697
  };
2575
2698
  };
2576
- return [`--- ${R} ---`, ...P(f, 0).lines].join(`
2699
+ return [`--- ${b} ---`, ..._(m, 0).lines].join(`
2577
2700
  `);
2578
- }, m = [], T = $(window.getSelection()?.toString() ?? "");
2579
- T && m.push(`--- selected text ---
2580
- ${JSON.stringify(T)}`), h.length > 0 && m.push(Dn(h, s, l, o));
2581
- for (const f of t.slice(0, 3))
2582
- m.push(g(f, "active overlay DOM", /* @__PURE__ */ new Set()));
2583
- if (e && m.push(g(e, "main DOM", /* @__PURE__ */ new Set())), document.body) {
2584
- const f = e || t.length ? "other visible DOM" : "visible DOM";
2585
- m.push(g(document.body, f, w));
2586
- }
2587
- return m.join(`
2701
+ }, I = [], w = z(window.getSelection()?.toString() ?? "");
2702
+ w && I.push(`--- selected text ---
2703
+ ${JSON.stringify(w)}`), g.length > 0 && I.push(Ln(g, s, l, o));
2704
+ for (const m of t.slice(0, 3))
2705
+ I.push(f(m, "active overlay DOM", /* @__PURE__ */ new Set()));
2706
+ if (e && I.push(f(e, "main DOM", /* @__PURE__ */ new Set())), document.body) {
2707
+ const m = e || t.length ? "other visible DOM" : "visible DOM";
2708
+ I.push(f(document.body, m, T));
2709
+ }
2710
+ return I.join(`
2588
2711
 
2589
2712
  `);
2590
2713
  }
2591
- function qt(t, e, s, n) {
2714
+ function Ht(t, e, s, n) {
2592
2715
  const r = t.tagName.toLowerCase();
2593
2716
  let i = r;
2594
2717
  const o = t.getAttribute("id");
2595
- o && vn(o) && (i += `#${o}`);
2718
+ o && Bn(o) && (i += `#${o}`);
2596
2719
  for (const a of e) {
2597
2720
  const l = t.getAttribute(a);
2598
2721
  l && l.length <= 160 && (a !== "role" || !s.has(l)) && (i += `[${a}=${JSON.stringify(l)}]`);
@@ -2605,7 +2728,7 @@ function qt(t, e, s, n) {
2605
2728
  t.hasAttribute(a) && (i += `[${a}]`);
2606
2729
  return `${i}${n ? ` ${JSON.stringify(n)}` : ""}`;
2607
2730
  }
2608
- function Un() {
2731
+ function xn() {
2609
2732
  const t = /* @__PURE__ */ new Set(), e = /* @__PURE__ */ new Map(), s = (a, l) => {
2610
2733
  if (!a)
2611
2734
  return;
@@ -2614,11 +2737,11 @@ function Un() {
2614
2737
  return;
2615
2738
  const p = e.get(a) ?? /* @__PURE__ */ new Set();
2616
2739
  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);
2740
+ let g = a;
2741
+ for (; g; ) {
2742
+ t.add(g);
2743
+ const T = g.getRootNode();
2744
+ g = g.parentElement ?? (T instanceof ShadowRoot && T.host instanceof HTMLElement ? T.host : null);
2622
2745
  }
2623
2746
  };
2624
2747
  let n = document.activeElement instanceof HTMLElement ? document.activeElement : null;
@@ -2626,7 +2749,7 @@ function Un() {
2626
2749
  n = n.shadowRoot.activeElement;
2627
2750
  n !== document.body && n !== document.documentElement && s(n, "focused");
2628
2751
  const r = window.getSelection();
2629
- r && !r.isCollapsed && (s(St(r.anchorNode), "selected text"), s(St(r.focusNode), "selected text"));
2752
+ r && !r.isCollapsed && (s(At(r.anchorNode), "selected text"), s(At(r.focusNode), "selected text"));
2630
2753
  const i = [
2631
2754
  ["[aria-selected='true']", "selected"],
2632
2755
  ["[aria-current]:not([aria-current='false'])", "current"],
@@ -2638,8 +2761,8 @@ function Un() {
2638
2761
  for (let a = 0; a < o.length; a += 1) {
2639
2762
  const l = o[a];
2640
2763
  for (const [c, p] of i)
2641
- for (const h of Array.from(l.querySelectorAll(c)))
2642
- s(h, p);
2764
+ for (const g of Array.from(l.querySelectorAll(c)))
2765
+ s(g, p);
2643
2766
  for (const c of Array.from(l.querySelectorAll("*")))
2644
2767
  c.shadowRoot && o.push(c.shadowRoot);
2645
2768
  }
@@ -2648,7 +2771,7 @@ function Un() {
2648
2771
  priorityTargets: Array.from(e, ([a, l]) => ({ element: a, labels: Array.from(l) }))
2649
2772
  };
2650
2773
  }
2651
- function Dn(t, e, s, n) {
2774
+ function Ln(t, e, s, n) {
2652
2775
  const r = ["--- active/current elements ---"];
2653
2776
  for (const i of t) {
2654
2777
  const o = [];
@@ -2656,40 +2779,40 @@ function Dn(t, e, s, n) {
2656
2779
  for (; a; ) {
2657
2780
  const p = a.tagName.toLowerCase();
2658
2781
  (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);
2782
+ const g = a.getRootNode();
2783
+ a = a.parentElement ?? (g instanceof ShadowRoot && g.host instanceof HTMLElement ? g.host : null);
2661
2784
  }
2662
- const l = o.length > 6 ? [o[0], ...o.slice(-5)] : o, c = l.map((p, h) => qt(
2785
+ const l = o.length > 6 ? [o[0], ...o.slice(-5)] : o, c = l.map((p, g) => Ht(
2663
2786
  p,
2664
2787
  s,
2665
2788
  n,
2666
- h === l.length - 1 ? Bt(p).slice(0, 180) : ""
2789
+ g === l.length - 1 ? $t(p).slice(0, 180) : ""
2667
2790
  ));
2668
2791
  o.length > l.length && c.splice(1, 0, "…"), r.push(`${i.labels.join(", ")}: ${c.join(" > ")}`);
2669
2792
  }
2670
2793
  return r.join(`
2671
2794
  `);
2672
2795
  }
2673
- function St(t) {
2796
+ function At(t) {
2674
2797
  return t instanceof HTMLElement ? t : t?.parentElement instanceof HTMLElement ? t.parentElement : null;
2675
2798
  }
2676
- function ie(t, e) {
2799
+ function le(t, e) {
2677
2800
  if (e === 0)
2678
2801
  return t;
2679
2802
  const s = " ".repeat(e);
2680
2803
  return t.map((n) => `${s}${n}`);
2681
2804
  }
2682
- function Bt(t) {
2683
- return $(
2805
+ function $t(t) {
2806
+ return z(
2684
2807
  Array.from(t.childNodes).filter((e) => e.nodeType === Node.TEXT_NODE).map((e) => e.textContent ?? "").join(" ")
2685
2808
  );
2686
2809
  }
2687
- function vn(t) {
2810
+ function Bn(t) {
2688
2811
  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);
2689
2812
  }
2690
- function Wt() {
2691
- const t = document.querySelector(ut);
2692
- if (!(t ?? document.querySelector(Le)))
2813
+ function jt() {
2814
+ const t = document.querySelector(pt);
2815
+ if (!(t ?? document.querySelector(qe)))
2693
2816
  return;
2694
2817
  const s = t ? "browser_extension_sdk_preview" : "embedded_widget";
2695
2818
  return {
@@ -2698,28 +2821,28 @@ function Wt() {
2698
2821
  selectors: [
2699
2822
  {
2700
2823
  name: "widget_host",
2701
- selector: s === "browser_extension_sdk_preview" ? ut : Le,
2824
+ selector: s === "browser_extension_sdk_preview" ? pt : qe,
2702
2825
  description: "Finds Pluno's shadow-host element in the host page DOM."
2703
2826
  },
2704
2827
  {
2705
2828
  name: "widget_root",
2706
- selector: _s,
2829
+ selector: vs,
2707
2830
  description: "Finds Pluno's widget root inside the widget host shadow root."
2708
2831
  },
2709
2832
  {
2710
2833
  name: "widget_panel",
2711
- selector: ks,
2834
+ selector: Ns,
2712
2835
  description: "Finds Pluno's open chat panel inside the widget host shadow root."
2713
2836
  },
2714
2837
  {
2715
2838
  name: "widget_timeline",
2716
- selector: Ps,
2839
+ selector: Os,
2717
2840
  description: "Finds Pluno's chat timeline inside the widget host shadow root."
2718
2841
  }
2719
2842
  ]
2720
2843
  };
2721
2844
  }
2722
- function Nn(t) {
2845
+ function qn(t) {
2723
2846
  try {
2724
2847
  const e = JSON.parse(t);
2725
2848
  return e && typeof e == "object" ? e : { type: "error", message: "Invalid server event" };
@@ -2727,7 +2850,7 @@ function Nn(t) {
2727
2850
  return { type: "error", message: "Invalid server event" };
2728
2851
  }
2729
2852
  }
2730
- function On(t) {
2853
+ function Wn(t) {
2731
2854
  if (typeof t != "string")
2732
2855
  return null;
2733
2856
  try {
@@ -2737,16 +2860,16 @@ function On(t) {
2737
2860
  return null;
2738
2861
  }
2739
2862
  }
2740
- function Mt(t, e) {
2863
+ function Rt(t, e) {
2741
2864
  if (!t || typeof t != "object")
2742
2865
  return [];
2743
2866
  const s = t[e];
2744
2867
  return Array.isArray(s) ? s.filter((n) => typeof n == "string" && n.trim().length > 0) : [];
2745
2868
  }
2746
- function xn(t) {
2869
+ function Hn(t) {
2747
2870
  return Array.isArray(t) ? t.filter((e) => typeof e == "string" && e.trim().length > 0) : [];
2748
2871
  }
2749
- function Ln(t) {
2872
+ function $n(t) {
2750
2873
  if (!t || typeof t != "object")
2751
2874
  return null;
2752
2875
  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;
@@ -2757,13 +2880,13 @@ function Ln(t) {
2757
2880
  ...a !== null ? { scribbleStyle: a } : {}
2758
2881
  };
2759
2882
  }
2760
- function qn(t) {
2883
+ function jn(t) {
2761
2884
  if (!t || typeof t != "object")
2762
2885
  return null;
2763
2886
  const e = t.javascript;
2764
2887
  return typeof e != "string" || !e.trim() ? null : { javascript: e };
2765
2888
  }
2766
- function Bn(t, e) {
2889
+ function Fn(t, e) {
2767
2890
  return e ? t && typeof t == "object" ? {
2768
2891
  ...t,
2769
2892
  helperError: e
@@ -2773,23 +2896,23 @@ function Bn(t, e) {
2773
2896
  helperError: e
2774
2897
  } : t;
2775
2898
  }
2776
- function Wn(t) {
2899
+ function zn(t) {
2777
2900
  if (!t || typeof t != "object")
2778
2901
  return t;
2779
2902
  const e = t;
2780
2903
  return typeof e.exception?.message == "string" ? e.exception.message : typeof e.error == "string" ? e.error : t;
2781
2904
  }
2782
- function Hn() {
2905
+ function Kn() {
2783
2906
  const t = "pluno.productAgent.clientId", e = window.localStorage.getItem(t);
2784
2907
  if (e)
2785
2908
  return e;
2786
2909
  const s = crypto.randomUUID();
2787
2910
  return window.localStorage.setItem(t, s), s;
2788
2911
  }
2789
- function L() {
2912
+ function H() {
2790
2913
  return crypto.randomUUID();
2791
2914
  }
2792
- function $n(t) {
2915
+ function Gn(t) {
2793
2916
  if (!t || typeof t != "object")
2794
2917
  return null;
2795
2918
  const e = t, s = typeof e.id == "string" ? e.id : null;
@@ -2800,22 +2923,22 @@ function $n(t) {
2800
2923
  avatarUrl: typeof e.avatarUrl == "string" ? e.avatarUrl : null
2801
2924
  } : null;
2802
2925
  }
2803
- function jn(t, e) {
2804
- return Array.isArray(t) ? Fe(
2805
- t.map((s) => Ht(s, e)).filter((s) => s !== null)
2926
+ function Xn(t, e) {
2927
+ return Array.isArray(t) ? Ke(
2928
+ t.map((s) => Ft(s, e)).filter((s) => s !== null)
2806
2929
  ) : [];
2807
2930
  }
2808
- function Fn(t) {
2931
+ function Vn(t) {
2809
2932
  return Array.isArray(t) ? t.flatMap((e) => {
2810
2933
  if (!e || typeof e != "object")
2811
2934
  return [];
2812
- const s = e, n = E(s, "id"), r = E(s, "createdAt"), i = E(s, "updatedAt"), o = E(s, "lastActiveAt");
2935
+ const s = e, n = S(s, "id"), r = S(s, "createdAt"), i = S(s, "updatedAt"), o = S(s, "lastActiveAt");
2813
2936
  return !n || !r || !i || !o ? [] : [
2814
2937
  {
2815
2938
  id: n,
2816
- title: E(s, "title"),
2817
- customTitle: E(s, "customTitle"),
2818
- firstUserMessage: E(s, "firstUserMessage"),
2939
+ title: S(s, "title"),
2940
+ customTitle: S(s, "customTitle"),
2941
+ firstUserMessage: S(s, "firstUserMessage"),
2819
2942
  currentPage: s.currentPage ?? null,
2820
2943
  createdAt: r,
2821
2944
  updatedAt: i,
@@ -2826,29 +2949,29 @@ function Fn(t) {
2826
2949
  ];
2827
2950
  }) : [];
2828
2951
  }
2829
- function Ht(t, e) {
2952
+ function Ft(t, e) {
2830
2953
  if (!t || typeof t != "object")
2831
2954
  return null;
2832
2955
  const s = t, n = s.data;
2833
2956
  if (!n || typeof n != "object")
2834
2957
  return null;
2835
2958
  const r = n;
2836
- if (r.hiddenFromTranscript === !0 || r.type === "tab_lifecycle_decision" && r.decision === "keep")
2959
+ if (r.hiddenFromTranscript === !0 || Ts(r) || r.type === "tab_lifecycle_decision" && r.decision === "keep")
2837
2960
  return null;
2838
2961
  if (r.type === "message") {
2839
2962
  const i = r.role === "assistant" ? "assistant" : r.role === "user" ? "user" : "system", o = {
2840
2963
  id: String(s.id ?? crypto.randomUUID()),
2841
2964
  role: i,
2842
2965
  ...r.phase === "commentary" || r.phase === "final_answer" ? { phase: r.phase } : {},
2843
- content: gs(
2844
- Yn(r.content),
2966
+ content: ys(
2967
+ sr(r.content),
2845
2968
  e
2846
2969
  ),
2847
2970
  createdAt: typeof s.createdAt == "string" ? s.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
2848
2971
  ...N(r) !== null ? { causalSequence: N(r) } : {},
2849
2972
  respondsToUserMessageId: O(r) ?? void 0,
2850
- ..._(r) ? { runId: _(r) } : {},
2851
- attachments: Xt(r.attachments, e)
2973
+ ...U(r) ? { runId: U(r) } : {},
2974
+ attachments: Yt(r.attachments, e)
2852
2975
  };
2853
2976
  return i === "assistant" && typeof r.id == "string" && Object.defineProperty(o, "assistantDraftItemId", {
2854
2977
  value: r.id,
@@ -2859,7 +2982,7 @@ function Ht(t, e) {
2859
2982
  }), o;
2860
2983
  }
2861
2984
  if (r.type === "function_call_output") {
2862
- const i = Cs(r.output);
2985
+ const i = Us(r.output);
2863
2986
  if (i)
2864
2987
  return {
2865
2988
  id: String(s.id ?? crypto.randomUUID()),
@@ -2867,13 +2990,13 @@ function Ht(t, e) {
2867
2990
  content: "",
2868
2991
  createdAt: typeof s.createdAt == "string" ? s.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
2869
2992
  respondsToUserMessageId: O(r) ?? void 0,
2870
- ..._(r) ? { runId: _(r) } : {},
2993
+ ...U(r) ? { runId: U(r) } : {},
2871
2994
  dataType: "scheduled_check_in",
2872
- toolName: Dt,
2995
+ toolName: Ot,
2873
2996
  callId: Ne(r) ?? void 0,
2874
2997
  scheduledCheckInAt: i
2875
2998
  };
2876
- const o = Kn(r.output);
2999
+ const o = Yn(r.output);
2877
3000
  return o ? {
2878
3001
  id: String(s.id ?? crypto.randomUUID()),
2879
3002
  role: "tool",
@@ -2881,7 +3004,7 @@ function Ht(t, e) {
2881
3004
  createdAt: typeof s.createdAt == "string" ? s.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
2882
3005
  ...N(r) !== null ? { causalSequence: N(r) } : {},
2883
3006
  respondsToUserMessageId: O(r) ?? void 0,
2884
- ..._(r) ? { runId: _(r) } : {},
3007
+ ...U(r) ? { runId: U(r) } : {},
2885
3008
  dataType: "function_call_output",
2886
3009
  toolName: "authenticate_pipedream_app",
2887
3010
  callId: Ne(r) ?? void 0,
@@ -2891,11 +3014,11 @@ function Ht(t, e) {
2891
3014
  return r.type === "function_call" || r.type === "tool_call" || r.type === "web_search_call" || r.type === "mcp_call" || r.type === "tab_lifecycle_decision" ? {
2892
3015
  id: String(s.id ?? crypto.randomUUID()),
2893
3016
  role: "tool",
2894
- content: r.type === "mcp_call" ? zn(r) : Xn(r),
3017
+ content: r.type === "mcp_call" ? Jn(r) : Zn(r),
2895
3018
  createdAt: typeof s.createdAt == "string" ? s.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
2896
3019
  ...N(r) !== null ? { causalSequence: N(r) } : {},
2897
3020
  respondsToUserMessageId: O(r) ?? void 0,
2898
- ..._(r) ? { runId: _(r) } : {},
3021
+ ...U(r) ? { runId: U(r) } : {},
2899
3022
  dataType: String(r.type),
2900
3023
  toolName: r.type === "tab_lifecycle_decision" ? "tab_lifecycle_decision" : typeof r.name == "string" ? r.name : void 0,
2901
3024
  callId: Ne(r) ?? void 0,
@@ -2903,11 +3026,11 @@ function Ht(t, e) {
2903
3026
  } : r.type === "run_status" || r.type === "run_error" ? r.type === "run_error" && r.stage === "tool_execution" ? null : {
2904
3027
  id: String(s.id ?? crypto.randomUUID()),
2905
3028
  role: "system",
2906
- content: Gn(r),
3029
+ content: Qn(r),
2907
3030
  createdAt: typeof s.createdAt == "string" ? s.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
2908
3031
  ...N(r) !== null ? { causalSequence: N(r) } : {},
2909
3032
  respondsToUserMessageId: O(r) ?? void 0,
2910
- ..._(r) ? { runId: _(r) } : {},
3033
+ ...U(r) ? { runId: U(r) } : {},
2911
3034
  dataType: String(r.type),
2912
3035
  loading: r.type === "run_status" && (r.status === "running" || r.status === "retrying"),
2913
3036
  ...r.type === "run_status" && r.status === "steered" ? { steered: !0 } : {},
@@ -2915,11 +3038,11 @@ function Ht(t, e) {
2915
3038
  ...typeof r.securitySettingsUrl == "string" ? { securitySettingsUrl: r.securitySettingsUrl } : {}
2916
3039
  } : null;
2917
3040
  }
2918
- function zn(t) {
3041
+ function Jn(t) {
2919
3042
  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(" ");
2920
3043
  return s ? `🔌 Using ${s}` : "🔌 Using connected integration";
2921
3044
  }
2922
- function Kn(t) {
3045
+ function Yn(t) {
2923
3046
  if (typeof t != "string")
2924
3047
  return null;
2925
3048
  try {
@@ -2936,10 +3059,10 @@ function Kn(t) {
2936
3059
  return null;
2937
3060
  }
2938
3061
  }
2939
- function Gn(t) {
3062
+ function Qn(t) {
2940
3063
  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.";
2941
3064
  }
2942
- function Xn(t) {
3065
+ function Zn(t) {
2943
3066
  if (t.type === "web_search_call") {
2944
3067
  const e = t.action;
2945
3068
  if (e && typeof e == "object") {
@@ -2951,26 +3074,26 @@ function Xn(t) {
2951
3074
  }
2952
3075
  return "🔎 Searching the web";
2953
3076
  }
2954
- return Vn(t);
3077
+ return er(t);
2955
3078
  }
2956
- function Vn(t) {
3079
+ function er(t) {
2957
3080
  if (typeof t.summary == "string" && t.summary.trim().length > 0)
2958
- return W(t.summary);
3081
+ return F(t.summary);
2959
3082
  if (typeof t.arguments == "string")
2960
3083
  try {
2961
3084
  const e = JSON.parse(t.arguments);
2962
3085
  if (typeof e.summary == "string" && e.summary.trim().length > 0)
2963
- return W(e.summary);
3086
+ return F(e.summary);
2964
3087
  } catch {
2965
- return typeof t.name == "string" && t.name.trim().length > 0 ? W(t.name) : "🛠️ Run tool";
3088
+ return typeof t.name == "string" && t.name.trim().length > 0 ? F(t.name) : "🛠️ Run tool";
2966
3089
  }
2967
- return typeof t.name == "string" && t.name.trim().length > 0 ? W(t.name) : "🛠️ Run tool";
3090
+ return typeof t.name == "string" && t.name.trim().length > 0 ? F(t.name) : "🛠️ Run tool";
2968
3091
  }
2969
- function W(t) {
3092
+ function F(t) {
2970
3093
  const e = t.trim() || "Run tool", s = e.codePointAt(0) ?? 0;
2971
3094
  return s >= 126976 && s <= 129791 || s >= 9728 && s <= 10175 || s >= 127462 && s <= 127487 ? e : `🛠️ ${e}`;
2972
3095
  }
2973
- function Jn(t) {
3096
+ function tr(t) {
2974
3097
  if (t == null)
2975
3098
  return t;
2976
3099
  if (typeof t != "object")
@@ -2992,7 +3115,7 @@ function Ne(t) {
2992
3115
  function N(t) {
2993
3116
  return typeof t.causalSequence == "number" && Number.isSafeInteger(t.causalSequence) ? t.causalSequence : null;
2994
3117
  }
2995
- function Yn(t) {
3118
+ function sr(t) {
2996
3119
  return typeof t == "string" ? t : Array.isArray(t) ? t.map((e) => {
2997
3120
  if (!e || typeof e != "object")
2998
3121
  return "";
@@ -3000,31 +3123,31 @@ function Yn(t) {
3000
3123
  return typeof s.text == "string" ? s.text : typeof s.content == "string" ? s.content : "";
3001
3124
  }).filter(Boolean).join("") : "";
3002
3125
  }
3003
- function Be(t, e) {
3004
- const s = jt(t, e), n = rr(
3005
- Qn(
3006
- lr(t, e),
3126
+ function He(t, e) {
3127
+ const s = Kt(t, e), n = lr(
3128
+ nr(
3129
+ pr(t, e),
3007
3130
  s
3008
3131
  ),
3009
3132
  s
3010
3133
  ), r = n.findIndex((o) => o.id === s.id);
3011
3134
  if (r === -1)
3012
- return Fe(
3135
+ return Ke(
3013
3136
  [...n, s]
3014
3137
  );
3015
3138
  const i = [...n];
3016
- return i[r] = s, Fe(i);
3139
+ return i[r] = s, Ke(i);
3017
3140
  }
3018
- function Qn(t, e) {
3141
+ function nr(t, e) {
3019
3142
  const s = e.assistantDraftItemId;
3020
3143
  return s ? t.map(
3021
3144
  (n) => n.dataType === "assistant_draft" && n.id === s ? e : n
3022
3145
  ) : t;
3023
3146
  }
3024
- function Zn(t, e, s) {
3147
+ function Oe(t, e, s) {
3025
3148
  return e !== null ? t.respondsToUserMessageId === e : s !== null && t.runId === s;
3026
3149
  }
3027
- function er(t, e, s, n) {
3150
+ function rr(t, e, s, n) {
3028
3151
  if (s === null) return t;
3029
3152
  let r = -1;
3030
3153
  for (let o = t.length - 1; o >= 0; o -= 1) {
@@ -3041,12 +3164,12 @@ function er(t, e, s, n) {
3041
3164
  respondsToUserMessageId: s
3042
3165
  }, i;
3043
3166
  }
3044
- function tr(t, e) {
3167
+ function ir(t, e) {
3045
3168
  const s = t.findIndex(
3046
3169
  (r) => !r.id.startsWith("transient-activity:") && r.callId === e.callId
3047
3170
  );
3048
3171
  if (s === -1)
3049
- return Be(t, e);
3172
+ return He(t, e);
3050
3173
  const n = [...t];
3051
3174
  return n[s] = {
3052
3175
  ...n[s],
@@ -3058,19 +3181,19 @@ function tr(t, e) {
3058
3181
  ...n[s].runId ? {} : { runId: e.runId }
3059
3182
  }, n;
3060
3183
  }
3061
- function sr(t, e, s) {
3184
+ function or(t, e, s) {
3062
3185
  let n = !1;
3063
3186
  const r = t.map((i) => i.callId !== e || i.loading === s ? i : (n = !0, { ...i, loading: s }));
3064
3187
  return n ? r : t;
3065
3188
  }
3066
- function nr(t) {
3189
+ function ar(t) {
3067
3190
  if (t.hiddenFromTranscript === !0)
3068
3191
  return null;
3069
3192
  const e = typeof t.callId == "string" ? t.callId : null, s = typeof t.toolName == "string" ? t.toolName : null;
3070
3193
  return !e || !s ? null : {
3071
3194
  id: `transient-activity:${e}`,
3072
3195
  role: "tool",
3073
- content: W(
3196
+ content: F(
3074
3197
  typeof t.summary == "string" ? t.summary : "Running browser tool"
3075
3198
  ),
3076
3199
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
@@ -3083,7 +3206,7 @@ function nr(t) {
3083
3206
  loading: !0
3084
3207
  };
3085
3208
  }
3086
- function rr(t, e) {
3209
+ function lr(t, e) {
3087
3210
  if (e.id.startsWith("transient-activity:"))
3088
3211
  return t;
3089
3212
  const s = e.toolName === "tab_lifecycle";
@@ -3092,17 +3215,17 @@ function rr(t, e) {
3092
3215
  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);
3093
3216
  return r === -1 ? t : t.flatMap((i, o) => n(i) ? o === r ? [e] : [] : i.id === e.id ? [] : [i]);
3094
3217
  }
3095
- function ir(t, e) {
3096
- return fs(
3218
+ function cr(t, e) {
3219
+ return ws(
3097
3220
  t,
3098
3221
  e.map(
3099
- (s) => jt(t, s)
3222
+ (s) => Kt(t, s)
3100
3223
  ),
3101
- $t
3224
+ zt
3102
3225
  );
3103
3226
  }
3104
- function $t(t) {
3105
- const e = J(t) ?? void 0, s = t.assistantDraftItemId, n = [
3227
+ function zt(t) {
3228
+ const e = ee(t) ?? void 0, s = t.assistantDraftItemId, n = [
3106
3229
  ...t.callId ? [`call:${t.callId}`] : [],
3107
3230
  ...t.runId && (t.toolName === "browser_tabs" || t.toolName === "tab_lifecycle") ? [`tab-lifecycle:${t.runId}`] : []
3108
3231
  ];
@@ -3113,52 +3236,52 @@ function $t(t) {
3113
3236
  ...n.length > 0 ? { activityKeys: n } : {},
3114
3237
  ...t.respondsToUserMessageId ? { respondsToUserMessageId: t.respondsToUserMessageId } : {},
3115
3238
  ...t.runId ? { runId: t.runId } : {},
3116
- isOptimistic: ge(t),
3239
+ isOptimistic: ye(t),
3117
3240
  isAssistantDraft: t.dataType === "assistant_draft",
3118
3241
  isActivity: t.role === "tool" || t.phase === "commentary" || t.dataType === "assistant_draft",
3119
3242
  isTransient: t.id.startsWith("transient-activity:") || t.dataType === "assistant_draft"
3120
3243
  };
3121
3244
  }
3122
- function jt(t, e) {
3245
+ function Kt(t, e) {
3123
3246
  if (e.role !== "user" || !e.attachments?.length)
3124
3247
  return e;
3125
3248
  const s = t.find(
3126
- (r) => r.role === "user" && (r.id === e.id || ge(r) && Ft(r, e))
3249
+ (r) => r.role === "user" && (r.id === e.id || ye(r) && Gt(r, e))
3127
3250
  );
3128
3251
  if (!s?.attachments?.length)
3129
3252
  return e;
3130
3253
  const n = e.attachments.map((r) => {
3131
- const i = or(s.attachments ?? [], r);
3132
- return i ? ar(r, i) : r;
3254
+ const i = ur(s.attachments ?? [], r);
3255
+ return i ? dr(r, i) : r;
3133
3256
  });
3134
3257
  return { ...e, attachments: n };
3135
3258
  }
3136
- function or(t, e) {
3259
+ function ur(t, e) {
3137
3260
  return e.id ? t.find((s) => s.id === e.id) ?? null : null;
3138
3261
  }
3139
- function ar(t, e) {
3262
+ function dr(t, e) {
3140
3263
  const { previewUrl: s } = e;
3141
3264
  return s ? { ...t, previewUrl: s } : t;
3142
3265
  }
3143
- function lr(t, e) {
3266
+ function pr(t, e) {
3144
3267
  if (e.role !== "user")
3145
3268
  return t;
3146
3269
  const s = t.findIndex(
3147
- (r) => ge(r) && Ft(r, e)
3270
+ (r) => ye(r) && Gt(r, e)
3148
3271
  );
3149
3272
  if (s === -1)
3150
3273
  return t;
3151
3274
  const n = [...t];
3152
3275
  return n.splice(s, 1), n;
3153
3276
  }
3154
- function Ft(t, e) {
3155
- const s = J(t), n = J(e);
3277
+ function Gt(t, e) {
3278
+ const s = ee(t), n = ee(e);
3156
3279
  return s && n ? s === n : t.content === e.content;
3157
3280
  }
3158
- function ge(t) {
3281
+ function ye(t) {
3159
3282
  return t.role === "user" && (t.id.startsWith("local-") || t.id.startsWith("optimistic-user-message:"));
3160
3283
  }
3161
- function J(t) {
3284
+ function ee(t) {
3162
3285
  const e = t.clientMessageId;
3163
3286
  if (e)
3164
3287
  return e;
@@ -3167,18 +3290,18 @@ function J(t) {
3167
3290
  );
3168
3291
  return n ? t.id.slice(n.length) : null;
3169
3292
  }
3170
- function At(t) {
3171
- const e = zt(t);
3293
+ function Et(t) {
3294
+ const e = Xt(t);
3172
3295
  if (e === null)
3173
3296
  return !1;
3174
3297
  const s = t[e].id, n = t.some(
3175
- (r) => r.respondsToUserMessageId === s && We(r)
3298
+ (r) => r.respondsToUserMessageId === s && $e(r)
3176
3299
  );
3177
3300
  if (t.some((r) => r.respondsToUserMessageId === s))
3178
3301
  return n;
3179
3302
  for (let r = t.length - 1; r > e; r -= 1) {
3180
3303
  const i = t[r];
3181
- if (x(i))
3304
+ if (W(i))
3182
3305
  return !0;
3183
3306
  if (i.role === "system") {
3184
3307
  if (i.dataType === "run_error")
@@ -3189,25 +3312,25 @@ function At(t) {
3189
3312
  }
3190
3313
  return !1;
3191
3314
  }
3192
- function cr(t) {
3193
- const e = zt(t);
3315
+ function hr(t) {
3316
+ const e = Xt(t);
3194
3317
  if (e === null)
3195
- return t.some(x);
3318
+ return t.some(W);
3196
3319
  const s = t[e].id;
3197
3320
  return t.some((n) => n.respondsToUserMessageId === s) ? t.some(
3198
- (n) => n.respondsToUserMessageId === s && x(n)
3199
- ) : t.slice(e + 1).some(x);
3321
+ (n) => n.respondsToUserMessageId === s && W(n)
3322
+ ) : t.slice(e + 1).some(W);
3200
3323
  }
3201
- function zt(t) {
3324
+ function Xt(t) {
3202
3325
  for (let e = t.length - 1; e >= 0; e -= 1)
3203
- if (t[e].role === "user" && !ge(t[e]))
3326
+ if (t[e].role === "user" && !ye(t[e]))
3204
3327
  return e;
3205
3328
  return null;
3206
3329
  }
3207
- function We(t) {
3208
- return x(t) ? !0 : t.role !== "system" ? !1 : t.dataType === "run_error" ? !0 : t.dataType === "run_status" && t.loading !== !0;
3330
+ function $e(t) {
3331
+ return W(t) ? !0 : t.role !== "system" ? !1 : t.dataType === "run_error" ? !0 : t.dataType === "run_status" && t.loading !== !0;
3209
3332
  }
3210
- function Y(t) {
3333
+ function K(t) {
3211
3334
  for (let e = t.length - 1; e >= 0; e -= 1) {
3212
3335
  const s = t[e];
3213
3336
  if (!s || typeof s != "object")
@@ -3221,30 +3344,30 @@ function Y(t) {
3221
3344
  }
3222
3345
  return null;
3223
3346
  }
3224
- function ur(t) {
3225
- const e = Y(t);
3347
+ function gr(t) {
3348
+ const e = K(t);
3226
3349
  if (e === null)
3227
3350
  return null;
3228
- const n = H(t[e])?.page;
3351
+ const n = P(t[e])?.page;
3229
3352
  if (!n || typeof n != "object")
3230
3353
  return null;
3231
3354
  const r = n.url;
3232
3355
  return typeof r == "string" ? r : null;
3233
3356
  }
3234
- function H(t) {
3357
+ function P(t) {
3235
3358
  if (!t || typeof t != "object")
3236
3359
  return null;
3237
3360
  const e = t.data;
3238
3361
  return e && typeof e == "object" ? e : null;
3239
3362
  }
3240
- function He(t) {
3363
+ function je(t) {
3241
3364
  return t?.retryable !== !0 ? !1 : t.type === "run_error" ? !0 : t.type === "run_status" && t.status === "interrupted";
3242
3365
  }
3243
- function Rt(t) {
3366
+ function Ct(t) {
3244
3367
  return t?.type === "run_status" && t.status === "interrupted" && t.reason === "backend_restart";
3245
3368
  }
3246
- function dr(t, e) {
3247
- const s = Y(e);
3369
+ function fr(t, e) {
3370
+ const s = K(e);
3248
3371
  if (s === null)
3249
3372
  return !1;
3250
3373
  const n = e[s], r = n && typeof n == "object" ? n.id : null;
@@ -3252,11 +3375,11 @@ function dr(t, e) {
3252
3375
  return !1;
3253
3376
  const i = t.findIndex((o) => o.role === "user" && o.id === r);
3254
3377
  return i === -1 ? !1 : t.some((o) => o.respondsToUserMessageId === r) ? t.some(
3255
- (o) => o.respondsToUserMessageId === r && We(o)
3256
- ) : t.slice(i + 1).some(We);
3378
+ (o) => o.respondsToUserMessageId === r && $e(o)
3379
+ ) : t.slice(i + 1).some($e);
3257
3380
  }
3258
- function $e(t) {
3259
- const e = Y(t);
3381
+ function Fe(t) {
3382
+ const e = K(t);
3260
3383
  if (e === null)
3261
3384
  return null;
3262
3385
  const s = t[e];
@@ -3268,8 +3391,8 @@ function $e(t) {
3268
3391
  const r = n.clientMessageId;
3269
3392
  return typeof r == "string" ? r : null;
3270
3393
  }
3271
- function pr(t) {
3272
- const e = Y(t);
3394
+ function mr(t) {
3395
+ const e = K(t);
3273
3396
  if (e === null)
3274
3397
  return null;
3275
3398
  for (let s = t.length - 1; s > e; s -= 1) {
@@ -3283,22 +3406,22 @@ function pr(t) {
3283
3406
  if (i.type === "message" && i.role === "assistant")
3284
3407
  return null;
3285
3408
  if (i.type === "run_error")
3286
- return i.retryable !== !0 ? null : je(t, i) ?? $e(t);
3409
+ return i.retryable !== !0 ? null : ze(t, i) ?? Fe(t);
3287
3410
  if (i.type === "run_status")
3288
- return i.status === "interrupted" && i.retryable === !0 ? je(t, i) ?? $e(t) : null;
3411
+ return i.status === "interrupted" && i.retryable === !0 ? ze(t, i) ?? Fe(t) : null;
3289
3412
  }
3290
3413
  return null;
3291
3414
  }
3292
- function je(t, e) {
3415
+ function ze(t, e) {
3293
3416
  if (typeof e.clientMessageId == "string")
3294
3417
  return e.clientMessageId;
3295
3418
  const s = O(e);
3296
3419
  if (!s)
3297
3420
  return null;
3298
- const n = t.find((i) => E(i, "id") === s), r = H(n);
3421
+ const n = t.find((i) => S(i, "id") === s), r = P(n);
3299
3422
  return r?.type === "message" && r.role === "user" && typeof r.clientMessageId == "string" ? r.clientMessageId : null;
3300
3423
  }
3301
- function hr(t, e) {
3424
+ function yr(t, e) {
3302
3425
  let s = 0;
3303
3426
  for (const n of t) {
3304
3427
  if (!n || typeof n != "object")
@@ -3311,69 +3434,73 @@ function hr(t, e) {
3311
3434
  }
3312
3435
  return s;
3313
3436
  }
3314
- function Et(t, e, s, n, r) {
3315
- if (!e || !gr(t))
3437
+ function bt(t, e, s, n, r) {
3438
+ if (!e || !Ir(t))
3316
3439
  return !1;
3317
3440
  const i = t;
3318
- return !(He(i) || s !== null && typeof i.id == "string" && i.id !== s || (n !== null ? O(i) !== n : r !== null && _(i) !== r));
3441
+ return !(je(i) || s !== null && typeof i.id == "string" && i.id !== s || (n !== null ? O(i) !== n : r !== null && U(i) !== r));
3319
3442
  }
3320
- function gr(t) {
3443
+ function Ir(t) {
3321
3444
  if (!t || typeof t != "object")
3322
3445
  return !1;
3323
3446
  const e = t;
3324
3447
  return e.type === "message" && e.role === "assistant" ? !0 : e.type === "run_error" ? e.stage !== "tool_execution" : e.type === "run_status" && (e.status === "stopped" || e.status === "interrupted" || e.status === "failed");
3325
3448
  }
3326
- function x(t) {
3449
+ function W(t) {
3327
3450
  return t.role === "assistant" && t.phase !== "commentary";
3328
3451
  }
3329
- function fr(t) {
3452
+ function Tr(t) {
3330
3453
  if (!t || typeof t != "object")
3331
3454
  return !1;
3332
3455
  const e = t;
3333
3456
  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";
3334
3457
  }
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);
3458
+ function Ke(t) {
3459
+ return t.filter((e, s) => G(e) ? !kr(t, s) && !Vt(t, s) && !br(t, s) && !_r(t, s) : wr(e) ? e.retryable === !0 && Cr(t, s) ? !1 : !Er(t, s) : !0);
3337
3460
  }
3338
- function mr(t) {
3461
+ function wr(t) {
3339
3462
  return t.role === "system" && (t.dataType === "run_error" || t.dataType === "run_status" && t.steered !== !0);
3340
3463
  }
3341
- function j(t) {
3464
+ function G(t) {
3342
3465
  return t.role === "system" && t.dataType === "run_status" && t.loading === !0;
3343
3466
  }
3344
- function yr(t, e, s, n) {
3467
+ function Sr(t, e, s, n) {
3345
3468
  const r = t.findIndex(
3346
- (l, c) => j(l) && !Kt(t, c)
3469
+ (l, c) => G(l) && !Vt(t, c)
3347
3470
  ), i = r === -1 ? null : t[r], o = e ?? i?.respondsToUserMessageId ?? null, a = o ? t.find(
3348
3471
  (l) => l.role === "user" && l.id === o
3349
3472
  ) : null;
3350
3473
  return {
3351
- clientMessageId: a ? J(a) : o ? null : n,
3474
+ clientMessageId: a ? ee(a) : o ? null : n,
3475
+ respondsToUserMessageId: o,
3352
3476
  runId: s ?? i?.runId ?? null
3353
3477
  };
3354
3478
  }
3355
- function oe(t, e, s) {
3479
+ function xe(t) {
3480
+ return t?.type === "run_status" && t.status === "stopped";
3481
+ }
3482
+ function ce(t, e, s) {
3356
3483
  const n = new Set(
3357
3484
  t.filter(
3358
- (r) => r.role === "user" && e !== null && J(r) === e
3485
+ (r) => r.role === "user" && e !== null && ee(r) === e
3359
3486
  ).map((r) => r.id)
3360
3487
  );
3361
3488
  return t.filter(
3362
- (r) => !j(r) || (n.size > 0 ? !r.respondsToUserMessageId || !n.has(r.respondsToUserMessageId) : !s || r.runId !== s)
3489
+ (r) => !G(r) || (n.size > 0 ? !r.respondsToUserMessageId || !n.has(r.respondsToUserMessageId) : !s || r.runId !== s)
3363
3490
  );
3364
3491
  }
3365
- function Kt(t, e) {
3492
+ function Vt(t, e) {
3366
3493
  return t.some(
3367
- (s, n) => n !== e && s.role === "system" && (s.dataType === "run_error" || s.dataType === "run_status" && s.loading !== !0 && s.steered !== !0) && Ir(
3494
+ (s, n) => n !== e && s.role === "system" && (s.dataType === "run_error" || s.dataType === "run_status" && s.loading !== !0 && s.steered !== !0) && Mr(
3368
3495
  t,
3369
3496
  e,
3370
3497
  n
3371
3498
  )
3372
3499
  );
3373
3500
  }
3374
- function Ir(t, e, s) {
3501
+ function Mr(t, e, s) {
3375
3502
  const n = t[e], r = t[s];
3376
- if (Q(n, r))
3503
+ if (te(n, r))
3377
3504
  return !0;
3378
3505
  if (!n.respondsToUserMessageId || r.respondsToUserMessageId || !n.runId || n.runId !== r.runId)
3379
3506
  return !1;
@@ -3382,35 +3509,35 @@ function Ir(t, e, s) {
3382
3509
  return t[i].id === n.respondsToUserMessageId;
3383
3510
  return !1;
3384
3511
  }
3385
- function Tr(t, e) {
3512
+ function Ar(t, e) {
3386
3513
  const s = [...t].reverse().find(
3387
- (n) => n.respondsToUserMessageId !== void 0 && n.respondsToUserMessageId !== e && Ct(n) && !wr(
3514
+ (n) => n.respondsToUserMessageId !== void 0 && n.respondsToUserMessageId !== e && _t(n) && !Rr(
3388
3515
  t,
3389
3516
  n.respondsToUserMessageId
3390
3517
  )
3391
3518
  )?.respondsToUserMessageId;
3392
3519
  return s ? t.map(
3393
- (n) => n.respondsToUserMessageId === s && Ct(n) ? { ...n, steered: !0 } : n
3520
+ (n) => n.respondsToUserMessageId === s && _t(n) ? { ...n, steered: !0 } : n
3394
3521
  ) : t;
3395
3522
  }
3396
- function Ct(t) {
3397
- return t.role === "tool" || j(t) ? !0 : t.role === "assistant" && t.phase === "commentary";
3523
+ function _t(t) {
3524
+ return t.role === "tool" || G(t) ? !0 : t.role === "assistant" && t.phase === "commentary";
3398
3525
  }
3399
- function wr(t, e) {
3526
+ function Rr(t, e) {
3400
3527
  return t.some(
3401
- (s) => s.respondsToUserMessageId === e && (x(s) || s.role === "system" && (s.dataType === "run_error" || s.dataType === "run_status" && s.loading !== !0))
3528
+ (s) => s.respondsToUserMessageId === e && (W(s) || s.role === "system" && (s.dataType === "run_error" || s.dataType === "run_status" && s.loading !== !0))
3402
3529
  );
3403
3530
  }
3404
- function Sr(t, e) {
3531
+ function Er(t, e) {
3405
3532
  const s = t[e];
3406
3533
  for (let n = e + 1; n < t.length; n += 1) {
3407
3534
  const r = t[n];
3408
- if (r.role === "assistant" && Q(s, r))
3535
+ if (r.role === "assistant" && te(s, r))
3409
3536
  return !0;
3410
3537
  }
3411
3538
  return !1;
3412
3539
  }
3413
- function Mr(t, e) {
3540
+ function Cr(t, e) {
3414
3541
  const s = t[e];
3415
3542
  if (!s.respondsToUserMessageId)
3416
3543
  return !1;
@@ -3418,45 +3545,45 @@ function Mr(t, e) {
3418
3545
  const r = t[n];
3419
3546
  if (r.role === "user")
3420
3547
  return !1;
3421
- if (r.respondsToUserMessageId === s.respondsToUserMessageId && (r.role === "assistant" || r.role === "tool" || j(r)))
3548
+ if (r.respondsToUserMessageId === s.respondsToUserMessageId && (r.role === "assistant" || r.role === "tool" || G(r)))
3422
3549
  return !0;
3423
3550
  }
3424
3551
  return !1;
3425
3552
  }
3426
- function Ar(t, e) {
3553
+ function br(t, e) {
3427
3554
  const s = t[e];
3428
3555
  return t.some(
3429
- (n, r) => r !== e && n.role === "assistant" && Q(s, n)
3556
+ (n, r) => r !== e && n.role === "assistant" && te(s, n)
3430
3557
  );
3431
3558
  }
3432
- function Rr(t, e) {
3559
+ function _r(t, e) {
3433
3560
  const s = t[e];
3434
3561
  return t.some(
3435
- (n, r) => r !== e && n.role === "tool" && Q(s, n)
3562
+ (n, r) => r !== e && n.role === "tool" && te(s, n)
3436
3563
  );
3437
3564
  }
3438
- function Er(t, e) {
3565
+ function kr(t, e) {
3439
3566
  const s = t[e];
3440
3567
  for (let n = e + 1; n < t.length; n += 1)
3441
- if (j(t[n]) && Q(s, t[n]))
3568
+ if (G(t[n]) && te(s, t[n]))
3442
3569
  return !0;
3443
3570
  return !1;
3444
3571
  }
3445
- function Q(t, e) {
3572
+ function te(t, e) {
3446
3573
  return !!(t.respondsToUserMessageId && t.respondsToUserMessageId === e.respondsToUserMessageId);
3447
3574
  }
3448
- function E(t, e) {
3575
+ function S(t, e) {
3449
3576
  return t && typeof t == "object" && typeof t[e] == "string" ? t[e] : null;
3450
3577
  }
3451
- function Cr(t, e) {
3578
+ function Pr(t, e) {
3452
3579
  try {
3453
- const s = window.localStorage.getItem(`${Ot}${t}`);
3580
+ const s = window.localStorage.getItem(`${Bt}${t}`);
3454
3581
  if (!s)
3455
3582
  return null;
3456
3583
  const n = JSON.parse(s), r = typeof n.sessionId == "string" ? n.sessionId : null;
3457
3584
  if (e !== void 0 && r !== e)
3458
3585
  return null;
3459
- const i = Array.isArray(n.messages) ? n.messages.map(qr).filter((o) => !!o) : [];
3586
+ const i = Array.isArray(n.messages) ? n.messages.map(Hr).filter((o) => !!o) : [];
3460
3587
  return {
3461
3588
  sessionId: r,
3462
3589
  messages: i
@@ -3465,48 +3592,48 @@ function Cr(t, e) {
3465
3592
  return null;
3466
3593
  }
3467
3594
  }
3468
- function br(t, e) {
3595
+ function Ur(t, e) {
3469
3596
  try {
3470
3597
  window.localStorage.setItem(
3471
- `${Ot}${t}`,
3598
+ `${Bt}${t}`,
3472
3599
  JSON.stringify({
3473
3600
  sessionId: e.sessionId,
3474
- messages: e.messages.slice(-Qs).map(Br)
3601
+ messages: e.messages.slice(-nn).map($r)
3475
3602
  })
3476
3603
  );
3477
3604
  } catch {
3478
3605
  return;
3479
3606
  }
3480
3607
  }
3481
- function _r(t) {
3608
+ function Dr(t) {
3482
3609
  try {
3483
- const e = window.localStorage.getItem(`${qe}${t}`);
3610
+ const e = window.localStorage.getItem(`${We}${t}`);
3484
3611
  if (!e)
3485
3612
  return [];
3486
3613
  const s = JSON.parse(e);
3487
- return Array.isArray(s) ? s.filter(Qe) : [];
3614
+ return Array.isArray(s) ? s.filter(et) : [];
3488
3615
  } catch {
3489
3616
  return [];
3490
3617
  }
3491
3618
  }
3492
- function q(t, e) {
3619
+ function $(t, e) {
3493
3620
  try {
3494
- const s = e.filter(Qe);
3621
+ const s = e.filter(et);
3495
3622
  if (s.length === 0) {
3496
- window.localStorage.removeItem(`${qe}${t}`);
3623
+ window.localStorage.removeItem(`${We}${t}`);
3497
3624
  return;
3498
3625
  }
3499
3626
  window.localStorage.setItem(
3500
- `${qe}${t}`,
3627
+ `${We}${t}`,
3501
3628
  JSON.stringify(s.slice(-25))
3502
3629
  );
3503
3630
  } catch {
3504
3631
  return;
3505
3632
  }
3506
3633
  }
3507
- function Gt(t, e) {
3634
+ function Jt(t, e) {
3508
3635
  try {
3509
- const s = `${he}${t}`, n = location.href, r = location.origin, i = Array.from(e, (o) => ({
3636
+ const s = `${me}${t}`, n = location.href, r = location.origin, i = Array.from(e, (o) => ({
3510
3637
  ...o,
3511
3638
  storedAt: Date.now(),
3512
3639
  unloadUrl: n,
@@ -3520,28 +3647,28 @@ function Gt(t, e) {
3520
3647
  } catch {
3521
3648
  }
3522
3649
  }
3523
- function kr(t, e) {
3650
+ function kt(t, e) {
3524
3651
  try {
3525
- if (window.sessionStorage.getItem(`${he}${t}`) === null)
3652
+ if (window.sessionStorage.getItem(`${me}${t}`) === null)
3526
3653
  return;
3527
3654
  } catch {
3528
3655
  return;
3529
3656
  }
3530
- Gt(t, e);
3657
+ Jt(t, e);
3531
3658
  }
3532
- function Pr(t) {
3659
+ function vr(t) {
3533
3660
  try {
3534
- const e = `${he}${t}`, s = window.sessionStorage.getItem(e);
3661
+ const e = `${me}${t}`, s = window.sessionStorage.getItem(e);
3535
3662
  if (window.sessionStorage.removeItem(e), !s)
3536
3663
  return [];
3537
3664
  const n = JSON.parse(s);
3538
- return Array.isArray(n) ? n.flatMap((r) => Dr(r) ? [{
3665
+ return Array.isArray(n) ? n.flatMap((r) => Or(r) ? [{
3539
3666
  ...r.event,
3540
- page: C(),
3667
+ page: k(),
3541
3668
  rawOutput: {
3542
3669
  pageContextRestarted: !0,
3543
3670
  outcome: "unknown",
3544
- message: Ur(location.href),
3671
+ message: Nr(location.href),
3545
3672
  currentUrl: location.href,
3546
3673
  console: [],
3547
3674
  metadata: {
@@ -3558,17 +3685,17 @@ function Pr(t) {
3558
3685
  return [];
3559
3686
  }
3560
3687
  }
3561
- function Ur(t) {
3688
+ function Nr(t) {
3562
3689
  return `The page context restarted. This is expected when the action included page navigation. Otherwise, it's unknown whether the action completed.
3563
3690
  Current URL: ${t}`;
3564
3691
  }
3565
- function Dr(t) {
3692
+ function Or(t) {
3566
3693
  if (!t || typeof t != "object")
3567
3694
  return !1;
3568
3695
  const e = t, s = e.event;
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";
3696
+ return typeof e.startedAtMs == "number" && typeof e.startedAtUrl == "string" && e.startedAtOrigin === location.origin && e.unloadOrigin === location.origin && typeof e.unloadUrl == "string" && et(s) && s.type === "tool.result";
3570
3697
  }
3571
- function vr(t, e) {
3698
+ function xr(t, e) {
3572
3699
  const s = new Set(
3573
3700
  t.flatMap((n) => n.type === "tool.result" ? [n.callId] : [])
3574
3701
  );
@@ -3577,26 +3704,26 @@ function vr(t, e) {
3577
3704
  ...e.filter((n) => !s.has(n.callId))
3578
3705
  ];
3579
3706
  }
3580
- function Nr(t) {
3707
+ function Lr(t) {
3581
3708
  try {
3582
- window.sessionStorage.removeItem(`${he}${t}`);
3709
+ window.sessionStorage.removeItem(`${me}${t}`);
3583
3710
  } catch {
3584
3711
  return;
3585
3712
  }
3586
3713
  }
3587
- function Qe(t) {
3714
+ function et(t) {
3588
3715
  if (!t || typeof t != "object")
3589
3716
  return !1;
3590
3717
  const e = t;
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;
3718
+ return e.type === "chat.user_message" ? typeof e.content == "string" && Pt(e.page) : e.type === "page.upsert" || e.type === "session.reset" || e.type === "network.batch" ? Pt(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;
3592
3719
  }
3593
- function bt(t) {
3720
+ function Pt(t) {
3594
3721
  if (!t || typeof t != "object")
3595
3722
  return !1;
3596
3723
  const e = t;
3597
3724
  return typeof e.url == "string" && typeof e.title == "string" && typeof e.origin == "string";
3598
3725
  }
3599
- function Xt(t, e) {
3726
+ function Yt(t, e) {
3600
3727
  if (!Array.isArray(t))
3601
3728
  return;
3602
3729
  const s = t.filter((r) => {
@@ -3604,41 +3731,41 @@ function Xt(t, e) {
3604
3731
  return !1;
3605
3732
  const i = r;
3606
3733
  return typeof i.name == "string" && typeof i.mimeType == "string" && typeof i.sizeBytes == "number";
3607
- }), n = e ? s.map((r) => Vt(r, e)) : s;
3734
+ }), n = e ? s.map((r) => Qt(r, e)) : s;
3608
3735
  return n.length > 0 ? n : void 0;
3609
3736
  }
3610
- function Vt(t, e) {
3737
+ function Qt(t, e) {
3611
3738
  return t.fileUrl?.startsWith("/") ? {
3612
3739
  ...t,
3613
3740
  fileUrl: new URL(t.fileUrl, e).toString()
3614
3741
  } : t;
3615
3742
  }
3616
- function ze(t) {
3617
- return t.type || Lr(t.name) || "application/octet-stream";
3743
+ function Ge(t) {
3744
+ return t.type || Wr(t.name) || "application/octet-stream";
3618
3745
  }
3619
- function Or(t) {
3620
- Jt({
3746
+ function Br(t) {
3747
+ Zt({
3621
3748
  name: t.name,
3622
- mimeType: ze(t),
3749
+ mimeType: Ge(t),
3623
3750
  sizeBytes: t.size
3624
3751
  });
3625
3752
  }
3626
- function Jt(t) {
3627
- const e = xr(t.name), s = t.mimeType.trim().toLowerCase();
3628
- if (!Vs.has(`${e}:${s}`))
3753
+ function Zt(t) {
3754
+ const e = qr(t.name), s = t.mimeType.trim().toLowerCase();
3755
+ if (!en.has(`${e}:${s}`))
3629
3756
  throw new Error("This attachment type is not supported by the embedded model provider");
3630
- if (t.sizeBytes <= 0 || t.sizeBytes >= vt)
3757
+ if (t.sizeBytes <= 0 || t.sizeBytes >= xt)
3631
3758
  throw new Error("Embedded attachments must be between 1 byte and less than 50 MB");
3632
3759
  }
3633
- function xr(t) {
3760
+ function qr(t) {
3634
3761
  const e = t.trim().toLowerCase(), s = e.lastIndexOf(".");
3635
3762
  return s >= 0 ? e.slice(s) : "";
3636
3763
  }
3637
- function Lr(t) {
3764
+ function Wr(t) {
3638
3765
  const e = t.toLowerCase();
3639
3766
  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;
3640
3767
  }
3641
- function qr(t) {
3768
+ function Hr(t) {
3642
3769
  if (!t || typeof t != "object")
3643
3770
  return null;
3644
3771
  const e = t;
@@ -3655,17 +3782,17 @@ function qr(t) {
3655
3782
  dataType: typeof e.dataType == "string" ? e.dataType : void 0,
3656
3783
  scheduledCheckInAt: typeof e.scheduledCheckInAt == "string" ? e.scheduledCheckInAt : void 0,
3657
3784
  securitySettingsUrl: typeof e.securitySettingsUrl == "string" ? e.securitySettingsUrl : void 0,
3658
- attachments: Xt(e.attachments)?.map(Ze),
3785
+ attachments: Yt(e.attachments)?.map(tt),
3659
3786
  loading: typeof e.loading == "boolean" ? e.loading : void 0
3660
3787
  };
3661
3788
  }
3662
- function Br(t) {
3789
+ function $r(t) {
3663
3790
  return t.attachments?.length ? {
3664
3791
  ...t,
3665
- attachments: t.attachments.map(Ze)
3792
+ attachments: t.attachments.map(tt)
3666
3793
  } : t;
3667
3794
  }
3668
- function Ze(t) {
3795
+ function tt(t) {
3669
3796
  const {
3670
3797
  dataUrl: e,
3671
3798
  objectUrl: s,
@@ -3678,43 +3805,43 @@ function O(t) {
3678
3805
  const e = t.respondsToUserMessageId;
3679
3806
  return typeof e == "string" && e ? e : null;
3680
3807
  }
3681
- function _(t) {
3808
+ function U(t) {
3682
3809
  const e = t.runId;
3683
3810
  return typeof e == "string" && e ? e : null;
3684
3811
  }
3685
- function Wr(t) {
3812
+ function jr(t) {
3686
3813
  const e = t?.timeoutMs;
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);
3814
+ 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 <= hn);
3688
3815
  }
3689
- function Yt(t) {
3816
+ function es(t) {
3690
3817
  const e = {};
3691
3818
  try {
3692
3819
  new Headers(t).forEach((s, n) => {
3693
- Object.keys(e).length < Je && (e[n] = et(n, s));
3820
+ Object.keys(e).length < Qe && (e[n] = st(n, s));
3694
3821
  });
3695
3822
  } catch {
3696
3823
  return {};
3697
3824
  }
3698
3825
  return e;
3699
3826
  }
3700
- function et(t, e) {
3701
- return ns(t) ? fe : U(pe(e), Js);
3827
+ function st(t, e) {
3828
+ return os(t) ? Ie : x(fe(e), tn);
3702
3829
  }
3703
- function Hr(t, e) {
3830
+ function Fr(t, e) {
3704
3831
  return typeof t == "string" ? t : t instanceof URL ? t.toString() : e?.url ?? "";
3705
3832
  }
3706
- async function $r(t, e, s, n) {
3707
- const r = Yt(t.headers);
3833
+ async function zr(t, e, s, n) {
3834
+ const r = es(t.headers);
3708
3835
  n({
3709
3836
  ...e,
3710
3837
  responseStatus: t.status,
3711
3838
  responseHeaders: r,
3712
- responseBody: await jr(t),
3839
+ responseBody: await Kr(t),
3713
3840
  durationMs: Date.now() - s
3714
3841
  });
3715
3842
  }
3716
- async function jr(t) {
3717
- if (!Qt(t.headers))
3843
+ async function Kr(t) {
3844
+ if (!ts(t.headers))
3718
3845
  return;
3719
3846
  let e = null, s = null;
3720
3847
  try {
@@ -3723,7 +3850,7 @@ async function jr(t) {
3723
3850
  const n = new Promise((a) => {
3724
3851
  s = window.setTimeout(() => {
3725
3852
  e?.cancel(), a("timeout");
3726
- }, Ys);
3853
+ }, sn);
3727
3854
  }), r = new TextDecoder();
3728
3855
  let i = "", o = 0;
3729
3856
  for (; ; ) {
@@ -3732,10 +3859,10 @@ async function jr(t) {
3732
3859
  return;
3733
3860
  const { done: l, value: c } = a;
3734
3861
  if (l)
3735
- return U(i + r.decode());
3736
- const p = Ve - o;
3862
+ return x(i + r.decode());
3863
+ const p = Ye - o;
3737
3864
  if (c.byteLength > p)
3738
- return i += r.decode(c.subarray(0, Math.max(p, 0)), { stream: !0 }), e.cancel(), `${U(i)}... [truncated]`;
3865
+ return i += r.decode(c.subarray(0, Math.max(p, 0)), { stream: !0 }), e.cancel(), `${x(i)}... [truncated]`;
3739
3866
  o += c.byteLength, i += r.decode(c, { stream: !0 });
3740
3867
  }
3741
3868
  } catch {
@@ -3745,45 +3872,45 @@ async function jr(t) {
3745
3872
  s !== null && window.clearTimeout(s);
3746
3873
  }
3747
3874
  }
3748
- function Fr(t, e) {
3749
- if (Qt(new Headers(e)))
3875
+ function Gr(t, e) {
3876
+ if (ts(new Headers(e)))
3750
3877
  try {
3751
- return t.responseType === "" || t.responseType === "text" ? U(t.responseText ?? "") : void 0;
3878
+ return t.responseType === "" || t.responseType === "text" ? x(t.responseText ?? "") : void 0;
3752
3879
  } catch {
3753
3880
  return;
3754
3881
  }
3755
3882
  }
3756
- function _t(t) {
3883
+ function Ut(t) {
3757
3884
  if (typeof t == "string")
3758
- return U(t);
3885
+ return x(t);
3759
3886
  }
3760
- function zr(t) {
3761
- return k({
3887
+ function Xr(t) {
3888
+ return v({
3762
3889
  ...t,
3763
- requestBody: kt(t.requestBody),
3764
- responseBody: kt(t.responseBody)
3890
+ requestBody: Dt(t.requestBody),
3891
+ responseBody: Dt(t.responseBody)
3765
3892
  });
3766
3893
  }
3767
- function kt(t) {
3894
+ function Dt(t) {
3768
3895
  if (typeof t != "string")
3769
3896
  return t;
3770
3897
  const e = t.trim();
3771
3898
  if (!e.startsWith("{") && !e.startsWith("["))
3772
- return pe(t);
3899
+ return fe(t);
3773
3900
  try {
3774
- return JSON.stringify(k(JSON.parse(t)));
3901
+ return JSON.stringify(v(JSON.parse(t)));
3775
3902
  } catch {
3776
- return pe(t);
3903
+ return fe(t);
3777
3904
  }
3778
3905
  }
3779
- function Qt(t) {
3906
+ function ts(t) {
3780
3907
  if (!t)
3781
3908
  return !1;
3782
3909
  const e = t.get("content-type")?.toLowerCase() ?? "", s = t.get("content-length"), n = Number(s);
3783
- return s !== null && Number.isInteger(n) && n >= 0 && n <= Ve && (e.startsWith("text/") || e.includes("json") || e.includes("javascript"));
3910
+ return s !== null && Number.isInteger(n) && n >= 0 && n <= Ye && (e.startsWith("text/") || e.includes("json") || e.includes("javascript"));
3784
3911
  }
3785
- function B(t, e = {}, s) {
3786
- if (Gr(s))
3912
+ function j(t, e = {}, s) {
3913
+ if (Jr(s))
3787
3914
  return !0;
3788
3915
  const n = Object.entries(e).find(([r]) => r.toLowerCase() === "content-type")?.[1]?.toLowerCase();
3789
3916
  if (n?.includes("multipart/form-data") || n?.includes("application/octet-stream"))
@@ -3798,8 +3925,8 @@ function B(t, e = {}, s) {
3798
3925
  return !0;
3799
3926
  }
3800
3927
  }
3801
- function Kr(t, e) {
3802
- if (B(t))
3928
+ function Vr(t, e) {
3929
+ if (j(t))
3803
3930
  return !0;
3804
3931
  try {
3805
3932
  const s = new URL(t, location.href), n = new URL(e);
@@ -3808,117 +3935,117 @@ function Kr(t, e) {
3808
3935
  return !0;
3809
3936
  }
3810
3937
  }
3811
- function Gr(t) {
3938
+ function Jr(t) {
3812
3939
  return t instanceof FormData || t instanceof Blob || t instanceof ArrayBuffer || ArrayBuffer.isView(t) || typeof ReadableStream < "u" && t instanceof ReadableStream;
3813
3940
  }
3814
- function Xr(t) {
3941
+ function Yr(t) {
3815
3942
  const e = {};
3816
3943
  for (const s of t.trim().split(/[\r\n]+/)) {
3817
3944
  const n = s.indexOf(":");
3818
3945
  if (n <= 0)
3819
3946
  continue;
3820
- if (Object.keys(e).length >= Je)
3947
+ if (Object.keys(e).length >= Qe)
3821
3948
  break;
3822
3949
  const r = s.slice(0, n).trim();
3823
- e[r] = et(r, s.slice(n + 1).trim());
3950
+ e[r] = st(r, s.slice(n + 1).trim());
3824
3951
  }
3825
3952
  return e;
3826
3953
  }
3827
- function U(t, e = Ve) {
3954
+ function x(t, e = Ye) {
3828
3955
  return t.length <= e ? t : `${t.slice(0, e)}... [truncated ${t.length - e} chars]`;
3829
3956
  }
3830
- function Oe(t) {
3957
+ function Le(t) {
3831
3958
  return `${t}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
3832
3959
  }
3833
- class ue extends Error {
3960
+ class he extends Error {
3834
3961
  constructor(e, s) {
3835
3962
  super(`${e} (${s})`), this.status = s, this.name = "AttachmentUploadHttpError";
3836
3963
  }
3837
3964
  status;
3838
3965
  }
3839
- async function ae(t, e) {
3966
+ async function ue(t, e) {
3840
3967
  let s = null;
3841
- for (let n = 0; n < It; n += 1)
3968
+ for (let n = 0; n < wt; n += 1)
3842
3969
  try {
3843
3970
  return await t();
3844
3971
  } catch (r) {
3845
- if (s = r, n >= It - 1 || !Jr(r))
3972
+ if (s = r, n >= wt - 1 || !Zr(r))
3846
3973
  throw r;
3847
- await Vr(n);
3974
+ await Qr(n);
3848
3975
  }
3849
3976
  throw s instanceof Error ? s : new Error(e);
3850
3977
  }
3851
- function Vr(t) {
3978
+ function Qr(t) {
3852
3979
  return new Promise((e) => {
3853
- window.setTimeout(e, Xs[t] ?? 0);
3980
+ window.setTimeout(e, Zs[t] ?? 0);
3854
3981
  });
3855
3982
  }
3856
- function Jr(t) {
3857
- return t instanceof ue ? Yr(t.status) : t instanceof TypeError;
3983
+ function Zr(t) {
3984
+ return t instanceof he ? ei(t.status) : t instanceof TypeError;
3858
3985
  }
3859
- function Yr(t) {
3986
+ function ei(t) {
3860
3987
  return t === 408 || t === 409 || t === 429 || t >= 500;
3861
3988
  }
3862
- function Qr(t) {
3989
+ function ti(t) {
3863
3990
  return t === 401 || t === 403;
3864
3991
  }
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 = /[),.;\]]+$/;
3866
- function k(t) {
3867
- return de(t, 0, /* @__PURE__ */ new WeakSet());
3992
+ const Ie = "[REDACTED_SECRET]", L = "[REDACTED_TOKEN]", si = "[REDACTED_SIGNED_URL]", ni = 20, ri = /^(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, ss = /\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi, ns = /\bBasic\s+[A-Za-z0-9+/=-]{12,}/gi, rs = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g, is = /\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, ii = /\bhttps?:\/\/[^\s"'<>]+(?:X-Amz-Signature|X-Goog-Signature|Signature|sig=)[^\s"'<>]*/gi, oi = /\bhttps?:\/\/[^\s"'<>]+/gi, ai = /[),.;\]]+$/;
3993
+ function v(t) {
3994
+ return ge(t, 0, /* @__PURE__ */ new WeakSet());
3868
3995
  }
3869
- function de(t, e, s) {
3996
+ function ge(t, e, s) {
3870
3997
  if (typeof t == "string")
3871
- return t.startsWith("data:image/") || t.startsWith("data:application/pdf;") ? t : pe(t);
3998
+ return t.startsWith("data:image/") || t.startsWith("data:application/pdf;") ? t : fe(t);
3872
3999
  if (t === null || typeof t != "object")
3873
4000
  return t;
3874
- if (e >= ei)
4001
+ if (e >= ni)
3875
4002
  return "[REDACTED_MAX_DEPTH]";
3876
4003
  if (s.has(t))
3877
4004
  return "[REDACTED_CIRCULAR]";
3878
4005
  if (s.add(t), Array.isArray(t))
3879
- return t.map((r) => de(r, e + 1, s));
4006
+ return t.map((r) => ge(r, e + 1, s));
3880
4007
  const n = {};
3881
4008
  for (const [r, i] of Object.entries(t))
3882
- r === "pageContent" ? n[r] = i : ns(r) ? n[r] = fe : n[r] = r.toLowerCase() === "url" ? ii(i) : de(i, e + 1, s);
4009
+ r === "pageContent" ? n[r] = i : os(r) ? n[r] = Ie : n[r] = r.toLowerCase() === "url" ? li(i) : ge(i, e + 1, s);
3883
4010
  return n;
3884
4011
  }
3885
- function ns(t) {
4012
+ function os(t) {
3886
4013
  const e = t.replace(/[^a-z0-9]/gi, "").toLowerCase();
3887
4014
  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");
3888
4015
  }
3889
- function ii(t) {
3890
- return typeof t == "string" ? rs(t) : de(t, 0, /* @__PURE__ */ new WeakSet());
4016
+ function li(t) {
4017
+ return typeof t == "string" ? as(t) : ge(t, 0, /* @__PURE__ */ new WeakSet());
3891
4018
  }
3892
- function rs(t) {
4019
+ function as(t) {
3893
4020
  try {
3894
4021
  const e = new URL(t, location.href);
3895
4022
  for (const s of Array.from(e.searchParams.keys()))
3896
- ti.test(s) && e.searchParams.set(s, D);
3897
- return e.username && (e.username = D), e.password && (e.password = D), e.toString();
4023
+ ri.test(s) && e.searchParams.set(s, L);
4024
+ return e.username && (e.username = L), e.password && (e.password = L), e.toString();
3898
4025
  } catch {
3899
- return oi(t);
4026
+ return ci(t);
3900
4027
  }
3901
4028
  }
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}`);
4029
+ function fe(t) {
4030
+ return t.replace(ii, si).replace(oi, ui).replace(ss, `Bearer ${L}`).replace(ns, `Basic ${L}`).replace(rs, L).replace(is, (e, s) => `${s}: ${Ie}`);
3904
4031
  }
3905
- function oi(t) {
3906
- return t.replace(Zt, `Bearer ${D}`).replace(es, `Basic ${D}`).replace(ts, D).replace(ss, (e, s) => `${s}: ${fe}`);
4032
+ function ci(t) {
4033
+ return t.replace(ss, `Bearer ${L}`).replace(ns, `Basic ${L}`).replace(rs, L).replace(is, (e, s) => `${s}: ${Ie}`);
3907
4034
  }
3908
- function ai(t) {
3909
- const e = t.match(ri)?.[0] ?? "", s = e ? t.slice(0, -e.length) : t;
3910
- return `${rs(s)}${e}`;
4035
+ function ui(t) {
4036
+ const e = t.match(ai)?.[0] ?? "", s = e ? t.slice(0, -e.length) : t;
4037
+ return `${as(s)}${e}`;
3911
4038
  }
3912
4039
  export {
3913
- ut as PLUNO_PRODUCT_AGENT_SDK_PREVIEW_HOST_SELECTOR,
3914
- Le as PLUNO_PRODUCT_AGENT_WIDGET_HOST_SELECTOR,
3915
- ks as PLUNO_PRODUCT_AGENT_WIDGET_PANEL_SELECTOR,
3916
- _s as PLUNO_PRODUCT_AGENT_WIDGET_ROOT_SELECTOR,
3917
- Ps as PLUNO_PRODUCT_AGENT_WIDGET_TIMELINE_SELECTOR,
3918
- li as PRODUCT_AGENT_PROVIDER_INPUT_ATTACHMENT_ACCEPT,
3919
- xt as PlunoProductAgent,
3920
- en as calculateReconnectDelay,
3921
- xt as default,
3922
- Rn as getProductAgentOriginAccessErrorMessage,
3923
- Or as validateProductAgentProviderInputFile
4040
+ pt as PLUNO_PRODUCT_AGENT_SDK_PREVIEW_HOST_SELECTOR,
4041
+ qe as PLUNO_PRODUCT_AGENT_WIDGET_HOST_SELECTOR,
4042
+ Ns as PLUNO_PRODUCT_AGENT_WIDGET_PANEL_SELECTOR,
4043
+ vs as PLUNO_PRODUCT_AGENT_WIDGET_ROOT_SELECTOR,
4044
+ Os as PLUNO_PRODUCT_AGENT_WIDGET_TIMELINE_SELECTOR,
4045
+ di as PRODUCT_AGENT_PROVIDER_INPUT_ATTACHMENT_ACCEPT,
4046
+ qt as PlunoProductAgent,
4047
+ on as calculateReconnectDelay,
4048
+ qt as default,
4049
+ kn as getProductAgentOriginAccessErrorMessage,
4050
+ Br as validateProductAgentProviderInputFile
3924
4051
  };