@pluno/product-agent-web 0.1.89 → 0.1.91

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,11 @@
1
- const ee = "pluno-product-agent-attachments";
2
- const et = "files";
3
- async function Ut(e) {
4
- const t = await W();
5
- await Dt(t, "readwrite", (s) => s.put(e));
6
- }
7
- async function se(e) {
8
- const t = await W(), s = await Dt(
1
+ const re = "pluno-product-agent-attachments";
2
+ const st = "files";
3
+ async function Nt(e) {
4
+ const t = await $();
5
+ await Bt(t, "readwrite", (s) => s.put(e));
6
+ }
7
+ async function ie(e) {
8
+ const t = await $(), s = await Bt(
9
9
  t,
10
10
  "readonly",
11
11
  (r) => r.get(e)
@@ -13,12 +13,12 @@ async function se(e) {
13
13
  if (!s)
14
14
  return null;
15
15
  const n = Date.now();
16
- return await vt(e, { lastUsedAt: n }), { ...s, lastUsedAt: n };
16
+ return await Ot(e, { lastUsedAt: n }), { ...s, lastUsedAt: n };
17
17
  }
18
- async function vt(e, t) {
19
- const s = await W();
20
- await lt(s, "readwrite", async (n) => {
21
- const r = await ut(
18
+ async function Ot(e, t) {
19
+ const s = await $();
20
+ await ut(s, "readwrite", async (n) => {
21
+ const r = await dt(
22
22
  n.get(e)
23
23
  );
24
24
  r && n.put({
@@ -27,28 +27,28 @@ async function vt(e, t) {
27
27
  });
28
28
  });
29
29
  }
30
- async function ne(e = 864e5) {
31
- const t = await W(), s = Date.now() - e;
32
- await lt(t, "readwrite", async (n) => {
30
+ async function oe(e = 864e5) {
31
+ const t = await $(), s = Date.now() - e;
32
+ await ut(t, "readwrite", async (n) => {
33
33
  const r = n.index("lastUsedAt");
34
- (await ut(r.getAllKeys(IDBKeyRange.upperBound(s)))).forEach((o) => n.delete(o));
34
+ (await dt(r.getAllKeys(IDBKeyRange.upperBound(s)))).forEach((o) => n.delete(o));
35
35
  });
36
36
  }
37
- function W() {
37
+ function $() {
38
38
  return typeof indexedDB > "u" ? Promise.reject(new Error("Product Agent attachment storage is unavailable")) : new Promise((e, t) => {
39
- const s = indexedDB.open(ee, 1);
39
+ const s = indexedDB.open(re, 1);
40
40
  s.onupgradeneeded = () => {
41
- const r = s.result.createObjectStore(et, { keyPath: "attachmentId" });
41
+ const r = s.result.createObjectStore(st, { keyPath: "attachmentId" });
42
42
  r.createIndex("lastUsedAt", "lastUsedAt", { unique: !1 }), r.createIndex("sessionId", "sessionId", { unique: !1 }), r.createIndex("origin", "origin", { unique: !1 });
43
43
  }, s.onsuccess = () => e(s.result), s.onerror = () => t(s.error ?? new Error("Failed to open Product Agent attachment storage"));
44
44
  });
45
45
  }
46
- async function Dt(e, t, s) {
47
- return await lt(e, t, async (n) => await ut(s(n)));
46
+ async function Bt(e, t, s) {
47
+ return await ut(e, t, async (n) => await dt(s(n)));
48
48
  }
49
- function lt(e, t, s) {
49
+ function ut(e, t, s) {
50
50
  return new Promise((n, r) => {
51
- const i = e.transaction(et, t), o = i.objectStore(et);
51
+ const i = e.transaction(st, t), o = i.objectStore(st);
52
52
  let a, u = !1;
53
53
  s(o).then((l) => {
54
54
  a = l;
@@ -68,16 +68,16 @@ function lt(e, t, s) {
68
68
  };
69
69
  });
70
70
  }
71
- function ut(e) {
71
+ function dt(e) {
72
72
  return new Promise((t, s) => {
73
73
  e.onsuccess = () => t(e.result), e.onerror = () => s(e.error ?? new Error("Product Agent attachment storage request failed"));
74
74
  });
75
75
  }
76
- function re(e) {
76
+ function ae(e) {
77
77
  return e !== null && (typeof e == "object" || typeof e == "function");
78
78
  }
79
- function Nt(e, t, s) {
80
- const n = Reflect.get(e, "pluno"), r = re(n) ? n : {};
79
+ function Lt(e, t, s) {
80
+ const n = Reflect.get(e, "pluno"), r = ae(n) ? n : {};
81
81
  if (r !== n && !Reflect.set(e, "pluno", r))
82
82
  return null;
83
83
  const i = Object.getOwnPropertyDescriptor(r, t);
@@ -91,19 +91,19 @@ function Nt(e, t, s) {
91
91
  }
92
92
  };
93
93
  }
94
- const x = "pluno.productAgent.scheduledChatContinuation.", st = "pluno:scheduled-chat-continuation-changed", Ot = 10080 * 6e4, ie = 5e3, oe = 15e3;
95
- function ae(e, {
94
+ const H = "pluno.productAgent.scheduledChatContinuation.", nt = "pluno:scheduled-chat-continuation-changed", qt = 10080 * 6e4, ce = 5e3, le = 15e3;
95
+ function ue(e, {
96
96
  clientId: t,
97
97
  sessionId: s,
98
98
  callId: n
99
99
  }) {
100
100
  return `const plunoScheduledContinuation = Object.freeze(${JSON.stringify({
101
- storageKeyPrefix: x,
102
- changedEvent: st,
101
+ storageKeyPrefix: H,
102
+ changedEvent: nt,
103
103
  clientId: t,
104
104
  sessionId: s,
105
105
  defaultTaskId: `scheduled-${n}`,
106
- expiresAfterDueMs: Ot
106
+ expiresAfterDueMs: qt
107
107
  })});
108
108
  const scheduleQuery = (query, delaySeconds) => {
109
109
  if (typeof query !== "string" || query.trim().length === 0) {
@@ -132,15 +132,15 @@ const scheduleQuery = (query, delaySeconds) => {
132
132
  };
133
133
  ${e}`;
134
134
  }
135
- function ce(e) {
136
- const t = e.storage === void 0 ? le() : e.storage;
135
+ function de(e) {
136
+ const t = e.storage === void 0 ? he() : e.storage;
137
137
  let s = null, n = !1, r = !1, i = !1, o = t !== null;
138
138
  const a = /* @__PURE__ */ new Map(), u = () => {
139
139
  s !== null && (clearTimeout(s), s = null);
140
140
  }, l = () => {
141
141
  u(), !(i || !o) && (s = setTimeout(() => {
142
142
  s = null, h();
143
- }, ie));
143
+ }, ce));
144
144
  }, c = () => {
145
145
  o = !1, u();
146
146
  }, h = async () => {
@@ -151,30 +151,30 @@ function ce(e) {
151
151
  }
152
152
  n = !0;
153
153
  try {
154
- const f = Date.now();
155
- for (const [g, I] of a)
156
- I <= f && a.delete(g);
154
+ const g = Date.now();
155
+ for (const [f, A] of a)
156
+ A <= g && a.delete(f);
157
157
  const w = await t.list(), m = [];
158
- for (const g of w) {
159
- if (!U(g)) {
160
- const I = g && typeof g == "object" ? g.id : null;
161
- typeof I == "string" && await t.remove(I);
158
+ for (const f of w) {
159
+ if (!U(f)) {
160
+ const A = f && typeof f == "object" ? f.id : null;
161
+ typeof A == "string" && await t.remove(A);
162
162
  continue;
163
163
  }
164
- if (g.expiresAt <= f) {
165
- await t.remove(g.id), a.delete(g.id);
164
+ if (f.expiresAt <= g) {
165
+ await t.remove(f.id), a.delete(f.id);
166
166
  continue;
167
167
  }
168
- m.push(g);
168
+ m.push(f);
169
169
  }
170
170
  e.onTasksChanged?.(m);
171
- for (const g of m)
172
- if (!(g.clientId !== e.clientId || g.dueAt > f || a.has(g.id) || !await e.canDeliver(g))) {
173
- a.set(g.id, f + oe);
171
+ for (const f of m)
172
+ if (!(f.clientId !== e.clientId || f.dueAt > g || a.has(f.id) || !await e.canDeliver(f))) {
173
+ a.set(f.id, g + le);
174
174
  try {
175
- await e.deliver(g);
175
+ await e.deliver(f);
176
176
  } catch {
177
- a.delete(g.id);
177
+ a.delete(f.id);
178
178
  }
179
179
  }
180
180
  } catch {
@@ -183,19 +183,19 @@ function ce(e) {
183
183
  n = !1, r ? (r = !1, h()) : l();
184
184
  }
185
185
  }
186
- }, T = async (f) => {
187
- if (i || !o || !t || !U(f))
186
+ }, T = async (g) => {
187
+ if (i || !o || !t || !U(g))
188
188
  return !1;
189
189
  try {
190
- return await t.set(f), e.onTasksChanged?.((await t.list()).filter(U)), await h(), !0;
190
+ return await t.set(g), e.onTasksChanged?.((await t.list()).filter(U)), await h(), !0;
191
191
  } catch {
192
192
  return c(), !1;
193
193
  }
194
- }, p = async (f) => {
195
- if (a.delete(f), i || !o || !t)
194
+ }, p = async (g) => {
195
+ if (a.delete(g), i || !o || !t)
196
196
  return !1;
197
197
  try {
198
- return await t.remove(f), e.onTasksChanged?.((await t.list()).filter(U)), !0;
198
+ return await t.remove(g), e.onTasksChanged?.((await t.list()).filter(U)), !0;
199
199
  } catch {
200
200
  return c(), !1;
201
201
  }
@@ -216,9 +216,9 @@ function U(e) {
216
216
  if (!e || typeof e != "object")
217
217
  return !1;
218
218
  const t = e;
219
- return typeof t.id == "string" && t.id.length > 0 && typeof t.clientId == "string" && t.clientId.length > 0 && typeof t.sessionId == "string" && t.sessionId.length > 0 && typeof t.prompt == "string" && t.prompt.trim().length > 0 && typeof t.dueAt == "number" && Number.isFinite(t.dueAt) && typeof t.expiresAt == "number" && Number.isFinite(t.expiresAt) && t.expiresAt === t.dueAt + Ot;
219
+ return typeof t.id == "string" && t.id.length > 0 && typeof t.clientId == "string" && t.clientId.length > 0 && typeof t.sessionId == "string" && t.sessionId.length > 0 && typeof t.prompt == "string" && t.prompt.trim().length > 0 && typeof t.dueAt == "number" && Number.isFinite(t.dueAt) && typeof t.expiresAt == "number" && Number.isFinite(t.expiresAt) && t.expiresAt === t.dueAt + qt;
220
220
  }
221
- function le() {
221
+ function he() {
222
222
  let e;
223
223
  try {
224
224
  e = window.localStorage, e.length;
@@ -230,13 +230,13 @@ function le() {
230
230
  const t = [];
231
231
  for (let s = 0; s < e.length; s += 1) {
232
232
  const n = e.key(s);
233
- if (!n?.startsWith(x))
233
+ if (!n?.startsWith(H))
234
234
  continue;
235
235
  const r = e.getItem(n);
236
236
  if (r)
237
237
  try {
238
238
  const i = JSON.parse(r);
239
- U(i) && n === X(i.id) ? t.push(i) : (e.removeItem(n), s -= 1);
239
+ U(i) && n === J(i.id) ? t.push(i) : (e.removeItem(n), s -= 1);
240
240
  } catch {
241
241
  e.removeItem(n), s -= 1;
242
242
  }
@@ -244,29 +244,29 @@ function le() {
244
244
  return t;
245
245
  },
246
246
  async set(t) {
247
- e.setItem(X(t.id), JSON.stringify(t));
247
+ e.setItem(J(t.id), JSON.stringify(t));
248
248
  },
249
249
  async remove(t) {
250
- e.removeItem(X(t));
250
+ e.removeItem(J(t));
251
251
  },
252
252
  subscribe(t) {
253
253
  const s = (r) => {
254
- r.key?.startsWith(x) && t();
254
+ r.key?.startsWith(H) && t();
255
255
  }, n = () => t();
256
- return window.addEventListener("storage", s), window.addEventListener(st, n), () => {
257
- window.removeEventListener("storage", s), window.removeEventListener(st, n);
256
+ return window.addEventListener("storage", s), window.addEventListener(nt, n), () => {
257
+ window.removeEventListener("storage", s), window.removeEventListener(nt, n);
258
258
  };
259
259
  }
260
260
  };
261
261
  }
262
- function X(e) {
263
- return `${x}${e}`;
262
+ function J(e) {
263
+ return `${H}${e}`;
264
264
  }
265
- const K = "pluno.productAgent.transportId", ue = "pluno.productAgent.transportIdentity", J = "pluno.productAgent.transportIdentity.event", de = 50, he = globalThis.setTimeout.bind(globalThis);
265
+ const V = "pluno.productAgent.transportId", pe = "pluno.productAgent.transportIdentity", Y = "pluno.productAgent.transportIdentity.event", ge = 50, fe = globalThis.setTimeout.bind(globalThis);
266
266
  let M = null;
267
267
  const L = /* @__PURE__ */ new Set();
268
- async function pe(e = Lt()) {
269
- const t = e.randomUUID(), s = e.storage.getItem(K);
268
+ async function me(e = xt()) {
269
+ const t = e.randomUUID(), s = e.storage.getItem(V);
270
270
  let n = s ?? e.randomUUID(), r = !1, i = !1;
271
271
  const o = e.channel.subscribe((u) => {
272
272
  if (!(u.senderId === t || u.transportId !== n)) {
@@ -284,14 +284,14 @@ async function pe(e = Lt()) {
284
284
  }
285
285
  });
286
286
  if (!s)
287
- e.storage.setItem(K, n), r = !0;
287
+ e.storage.setItem(V, n), r = !0;
288
288
  else
289
289
  for (; ; ) {
290
290
  if (i = !1, e.channel.postMessage({ type: "probe", transportId: n, senderId: t }), await e.settle(), !i) {
291
291
  r = !0;
292
292
  break;
293
293
  }
294
- n = e.randomUUID(), e.storage.setItem(K, n);
294
+ n = e.randomUUID(), e.storage.setItem(V, n);
295
295
  }
296
296
  let a = !1;
297
297
  return {
@@ -301,14 +301,14 @@ async function pe(e = Lt()) {
301
301
  }
302
302
  };
303
303
  }
304
- async function fe() {
305
- M || (M = pe(Lt()), M.then((n) => {
304
+ async function ye() {
305
+ M || (M = me(xt()), M.then((n) => {
306
306
  const r = (i) => {
307
307
  i.persisted || (n.release(), M = null, L.clear(), window.removeEventListener("pagehide", r));
308
308
  };
309
309
  window.addEventListener("pagehide", r);
310
310
  }));
311
- const e = await M, t = ge();
311
+ const e = await M, t = Te();
312
312
  L.add(t);
313
313
  let s = !1;
314
314
  return {
@@ -319,23 +319,23 @@ async function fe() {
319
319
  }
320
320
  };
321
321
  }
322
- function ge() {
322
+ function Te() {
323
323
  let e = 0;
324
324
  for (; L.has(e); )
325
325
  e += 1;
326
326
  return e;
327
327
  }
328
- function Lt() {
328
+ function xt() {
329
329
  return {
330
330
  storage: window.sessionStorage,
331
- channel: me(),
331
+ channel: we(),
332
332
  randomUUID: () => crypto.randomUUID(),
333
- settle: () => new Promise((e) => he(e, de))
333
+ settle: () => new Promise((e) => fe(e, ge))
334
334
  };
335
335
  }
336
- function me() {
336
+ function we() {
337
337
  if (typeof BroadcastChannel < "u") {
338
- const e = new BroadcastChannel(ue);
338
+ const e = new BroadcastChannel(pe);
339
339
  return {
340
340
  postMessage: (t) => e.postMessage(t),
341
341
  subscribe: (t) => {
@@ -345,11 +345,11 @@ function me() {
345
345
  close: () => e.close()
346
346
  };
347
347
  }
348
- return ye();
348
+ return Ie();
349
349
  }
350
- function ye() {
350
+ function Ie() {
351
351
  const e = /* @__PURE__ */ new Set(), t = (s) => {
352
- if (s.key !== J || !s.newValue)
352
+ if (s.key !== Y || !s.newValue)
353
353
  return;
354
354
  const n = JSON.parse(s.newValue);
355
355
  for (const r of e)
@@ -358,9 +358,9 @@ function ye() {
358
358
  return window.addEventListener("storage", t), {
359
359
  postMessage: (s) => {
360
360
  window.localStorage.setItem(
361
- J,
361
+ Y,
362
362
  JSON.stringify({ ...s, eventId: crypto.randomUUID() })
363
- ), window.localStorage.removeItem(J);
363
+ ), window.localStorage.removeItem(Y);
364
364
  },
365
365
  subscribe: (s) => (e.add(s), () => e.delete(s)),
366
366
  close: () => {
@@ -368,17 +368,17 @@ function ye() {
368
368
  }
369
369
  };
370
370
  }
371
- const nt = '.pluno-pa-widget-host[data-pluno-product-agent-ui="widget"]', Te = '.pluno-pa-widget[data-pluno-product-agent-ui-root="widget"]', we = ".pluno-pa-widget__panel", Ie = ".pluno-pa-widget__timeline", Tt = `${nt}[data-pluno-sdk-preview-channel]`, Ae = "https://app.pluno.ai", Se = "gpt-5.6-sol", ke = 2e4, Ee = 1e4, Re = 1e4, Ce = 1e4, _e = 1e4, be = 1e3, wt = 3e4, It = 0.2, At = 6e4, Me = 15e3, v = 3, Pe = 2e3, Ue = 15e3, ve = 1e3, De = 100, Ne = 8e3, Oe = 15e3, St = 3, Le = [300, 1e3], dt = 64e3, V = 4e3, ht = 30, Be = 2e3, qe = 1e3, xe = 200 * 1024 * 1024, pt = "Image is too large for model vision input.", He = 100, Bt = "pluno.productAgent.state.", rt = "pluno.productAgent.pendingEvents.", j = "pluno.productAgent.activeToolCalls.", Fe = 100;
372
- function D(e, t = 0) {
373
- return Math.max(t, Pe * 4 ** e);
371
+ const rt = '.pluno-pa-widget-host[data-pluno-product-agent-ui="widget"]', Ae = '.pluno-pa-widget[data-pluno-product-agent-ui-root="widget"]', Se = ".pluno-pa-widget__panel", ke = ".pluno-pa-widget__timeline", wt = `${rt}[data-pluno-sdk-preview-channel]`, Ee = "https://app.pluno.ai", Re = "gpt-5.6-sol", Ce = 2e4, _e = 1e4, be = 1e4, Me = 1e4, Pe = 1e4, Ue = 1e3, It = 3e4, At = 0.2, St = 6e4, De = 15e3, v = 3, ve = 2e3, Ne = 15e3, Oe = 1e3, Be = 100, Le = 8e3, qe = 15e3, kt = 3, xe = [300, 1e3], ht = 64e3, Z = 4e3, pt = 30, Fe = 2e3, He = 1e3, We = 200 * 1024 * 1024, gt = "Image is too large for model vision input.", je = 100, Ft = "pluno.productAgent.state.", it = "pluno.productAgent.pendingEvents.", z = "pluno.productAgent.activeToolCalls.", $e = 100;
372
+ function N(e, t = 0) {
373
+ return Math.max(t, ve * 4 ** e);
374
374
  }
375
- const B = /* @__PURE__ */ new Set();
376
- let N = null;
377
- function We(e, t = Math.random) {
378
- const s = Math.min(wt, be * 2 ** e), n = 1 - It + t() * It * 2;
379
- return Math.min(wt, Math.round(s * n));
375
+ const q = /* @__PURE__ */ new Set();
376
+ let O = null;
377
+ function ze(e, t = Math.random) {
378
+ const s = Math.min(It, Ue * 2 ** e), n = 1 - At + t() * At * 2;
379
+ return Math.min(It, Math.round(s * n));
380
380
  }
381
- function je(e, t, s) {
381
+ function Ge(e, t, s) {
382
382
  return new Promise((n, r) => {
383
383
  const i = setTimeout(() => r(new Error(s)), t);
384
384
  e.then(
@@ -391,13 +391,13 @@ function je(e, t, s) {
391
391
  );
392
392
  });
393
393
  }
394
- class qt {
394
+ class Ht {
395
395
  constructor(t, s) {
396
396
  this.options = t, this.transportIdentity = s, this.state = {
397
397
  ...this.state,
398
- starterPrompts: ms(t.initialStarterPrompts)
398
+ starterPrompts: ws(t.initialStarterPrompts)
399
399
  };
400
- const n = t.restorePersistedState === !1 ? null : Gs(t.clientId, t.expectedPersistedSessionId);
400
+ const n = t.restorePersistedState === !1 ? null : Js(t.clientId, t.expectedPersistedSessionId);
401
401
  n && (this.state = {
402
402
  ...this.state,
403
403
  ...n,
@@ -408,10 +408,10 @@ class qt {
408
408
  assistantDraftRunId: null,
409
409
  isThinking: !1,
410
410
  lastError: null
411
- }), this.queuedClientEvents = Qs(
412
- Ks(t.clientId),
413
- Vs(t.clientId)
414
- ), P(t.clientId, this.queuedClientEvents), this.scheduledChatContinuationScheduler = ce({
411
+ }), this.queuedClientEvents = sn(
412
+ Ys(t.clientId),
413
+ Qs(t.clientId)
414
+ ), P(t.clientId, this.queuedClientEvents), this.scheduledChatContinuationScheduler = de({
415
415
  clientId: t.clientId,
416
416
  canDeliver: (r) => r.sessionId === this.state.sessionId,
417
417
  deliver: async (r) => {
@@ -443,6 +443,10 @@ class qt {
443
443
  transportIdentity;
444
444
  retryAttemptsByClientMessageId = {};
445
445
  retryTimersByClientMessageId = {};
446
+ clientMessageIdsByUserMessageItemId = /* @__PURE__ */ new Map();
447
+ // The backend closes a retryable failed run with assistant_done; that paired event is recovery control flow,
448
+ // not successful completion of the user turn.
449
+ retryableFailureRunIdsAwaitingDone = /* @__PURE__ */ new Set();
446
450
  thinkingWatchdogTimer = null;
447
451
  runAckWatchdogTimer = null;
448
452
  runAckResyncRetryTimer = null;
@@ -479,14 +483,14 @@ class qt {
479
483
  lastErrorCode: null
480
484
  };
481
485
  static async init(t) {
482
- const s = await fe(), n = new qt({
486
+ const s = await ye(), n = new Ht({
483
487
  ...t,
484
- backendUrl: as(t.backendUrl ?? Ae),
485
- clientId: t.clientId ?? As(),
486
- model: t.model ?? Se
488
+ backendUrl: us(t.backendUrl ?? Ee),
489
+ clientId: t.clientId ?? Es(),
490
+ model: t.model ?? Re
487
491
  }, s);
488
492
  try {
489
- ne().catch((r) => {
493
+ oe().catch((r) => {
490
494
  y("web-sdk.attachments", "Failed to delete stale Product Agent attachments", {
491
495
  message: r instanceof Error ? r.message : String(r)
492
496
  });
@@ -518,14 +522,14 @@ class qt {
518
522
  lastError: null
519
523
  });
520
524
  try {
521
- if (this.token = this.options.token ?? (this.options.tokenProvider ? await je(this.options.tokenProvider(), Re, "Pluno token provider timed out") : null), t !== this.connectionAttemptId || this.state.status === "closed")
525
+ if (this.token = this.options.token ?? (this.options.tokenProvider ? await Ge(this.options.tokenProvider(), be, "Pluno token provider timed out") : null), t !== this.connectionAttemptId || this.state.status === "closed")
522
526
  return;
523
527
  if (!this.token && !this.options.webSocketFactory)
524
528
  throw new Error("Pluno requires a token or tokenProvider");
525
- const s = ls(this.options.backendUrl), n = this.options.webSocketFactory?.(s) ?? new WebSocket(s);
529
+ const s = hs(this.options.backendUrl), n = this.options.webSocketFactory?.(s) ?? new WebSocket(s);
526
530
  this.socket = n, this.socketConnectTimer = window.setTimeout(() => {
527
531
  this.socket === n && n.readyState === WebSocket.CONNECTING && (y("web-sdk.agent", "Pluno socket opening timed out; reconnecting"), this.replaceTimedOutSocket(n));
528
- }, Ce), n.addEventListener("open", () => {
532
+ }, Me), n.addEventListener("open", () => {
529
533
  this.socket !== n || (this.clearSocketConnectTimer(), y("web-sdk.agent", "Pluno socket opened", {
530
534
  queuedClientEventCount: this.queuedClientEvents.length,
531
535
  isThinking: this.state.isThinking
@@ -537,9 +541,9 @@ class qt {
537
541
  pageUrl: location.href
538
542
  }) : !0)) || (this.socketAuthTimer = window.setTimeout(() => {
539
543
  this.socket === n && (y("web-sdk.agent", "Pluno socket authentication timed out; reconnecting"), this.replaceTimedOutSocket(n));
540
- }, _e));
544
+ }, Pe));
541
545
  }), n.addEventListener("message", (r) => {
542
- this.socket === n && this.handleServerEvent(gs(r.data));
546
+ this.socket === n && this.handleServerEvent(Ts(r.data));
543
547
  }), n.addEventListener("close", (r) => {
544
548
  this.socket === n && (this.clearSocketPhaseTimers(), this.stopHeartbeat(), this.socket = null, this.state.status !== "closed" && (y("web-sdk.agent", "Pluno socket closed; scheduling reconnect", {
545
549
  code: typeof r?.code == "number" ? r.code : null,
@@ -572,15 +576,15 @@ class qt {
572
576
  this.connectionAttemptId += 1, this.setState({ status: "closed", isThinking: !1 }), this.clearSocketPhaseTimers(), this.stopHeartbeat(), this.clearStarterPromptUrlRefreshTimer(), this.clearRetryTimers(), this.clearThinkingWatchdog(), this.rejectPendingSessionHistoryRequests("Pluno disconnected."), this.reconnectTimer !== null && (window.clearTimeout(this.reconnectTimer), this.reconnectTimer = null), this.queuedClientEvents = [], this.socket?.close(), this.socket = null;
573
577
  }
574
578
  destroy() {
575
- this.disconnect(), this.locationChangeCleanup?.(), this.locationChangeCleanup = null, this.cleanupSessionUserFilesApi(), this.pageLifecycleCleanup?.(), this.pageLifecycleCleanup = null, this.activeBrowserToolCalls.clear(), this.scheduledChatContinuationScheduler.destroy(), tn(this.options.clientId), this.transportIdentity.release(), this.networkCaptureCleanup?.(), this.networkCaptureCleanup = null, this.networkBatchTimer !== null && (window.clearTimeout(this.networkBatchTimer), this.networkBatchTimer = null), this.queuedNetworkEvents = [];
579
+ this.disconnect(), this.locationChangeCleanup?.(), this.locationChangeCleanup = null, this.cleanupSessionUserFilesApi(), this.pageLifecycleCleanup?.(), this.pageLifecycleCleanup = null, this.activeBrowserToolCalls.clear(), this.scheduledChatContinuationScheduler.destroy(), nn(this.options.clientId), this.transportIdentity.release(), this.networkCaptureCleanup?.(), this.networkCaptureCleanup = null, this.networkBatchTimer !== null && (window.clearTimeout(this.networkBatchTimer), this.networkBatchTimer = null), this.queuedNetworkEvents = [];
576
580
  for (const t of Object.values(this.listeners))
577
581
  t?.clear();
578
582
  }
579
583
  sendMessage(t, s = {}) {
580
- const n = t.trim(), r = s.attachments ?? [], i = r.map(mt);
584
+ const n = t.trim(), r = s.attachments ?? [], i = r.map(yt);
581
585
  if (!n && i.length === 0)
582
586
  return null;
583
- const o = A(), a = s.clientMessageId ?? O();
587
+ const o = S(), a = s.clientMessageId ?? B();
584
588
  this.retryableClientMessageId = null;
585
589
  const u = {
586
590
  id: `local-${a}`,
@@ -608,7 +612,7 @@ class qt {
608
612
  attachments: i.length > 0 ? i : void 0,
609
613
  page: o,
610
614
  model: this.options.model,
611
- metadata: kt(this.options.metadata)
615
+ metadata: Et(this.options.metadata)
612
616
  };
613
617
  return this.activeClientMessageId = a, this.activeUserMessageEvent = c, this.markThinkingProgress(), this.send(c), this.startBackgroundAttachmentUploads(a, i), a;
614
618
  }
@@ -617,21 +621,21 @@ class qt {
617
621
  return !t || !s ? !1 : (this.retryAttemptsByClientMessageId[s] = 0, this.retryableClientMessageId = null, this.activeClientMessageId = s, this.latestRecoverableClientMessageId = s, this.setState({ status: "connected", isThinking: !0, lastError: null, lastErrorCode: null }), this.markThinkingProgress(), this.send({ type: "chat.retry_last_user_message", sessionId: t, clientMessageId: s, automatic: !1 }), !0);
618
622
  }
619
623
  createLocalAttachment(t) {
620
- const s = O(), n = {
624
+ const s = B(), n = {
621
625
  id: s,
622
626
  name: t.name || "attachment",
623
- mimeType: bt(t),
627
+ mimeType: Ut(t),
624
628
  sizeBytes: t.size
625
629
  };
626
630
  this.attachmentFiles.set(s, t), this.attachmentBlobCache.set(s, t);
627
631
  const r = Date.now();
628
- return Ut({
632
+ return Nt({
629
633
  attachmentId: s,
630
634
  name: n.name,
631
635
  mimeType: n.mimeType,
632
636
  sizeBytes: n.sizeBytes,
633
637
  blob: t,
634
- origin: A().origin,
638
+ origin: S().origin,
635
639
  sessionId: this.state.sessionId ?? void 0,
636
640
  createdAt: r,
637
641
  lastUsedAt: r
@@ -648,7 +652,7 @@ class qt {
648
652
  return await this.uploadAttachmentForMessage({
649
653
  file: t,
650
654
  attachment: s,
651
- clientMessageId: O(),
655
+ clientMessageId: B(),
652
656
  waitForSession: !1,
653
657
  notifyCompletion: !1
654
658
  });
@@ -680,7 +684,7 @@ class qt {
680
684
  waitForSession: r,
681
685
  notifyCompletion: i
682
686
  }) {
683
- const o = r ? await this.waitForSessionId() : this.state.sessionId, a = bt(t), u = {
687
+ const o = r ? await this.waitForSessionId() : this.state.sessionId, a = Ut(t), u = {
684
688
  sessionId: o ?? void 0,
685
689
  attachmentId: s.id,
686
690
  clientId: this.options.clientId,
@@ -688,25 +692,25 @@ class qt {
688
692
  name: t.name || "attachment",
689
693
  mimeType: a,
690
694
  sizeBytes: t.size,
691
- page: A(),
695
+ page: S(),
692
696
  model: this.options.model,
693
- metadata: kt(this.options.metadata)
694
- }, l = this.options.prepareAttachmentUpload ? await tt(
697
+ metadata: Et(this.options.metadata)
698
+ }, l = this.options.prepareAttachmentUpload ? await et(
695
699
  () => this.options.prepareAttachmentUpload(u),
696
700
  "Failed to prepare attachment upload"
697
701
  ) : await this.prepareEmbedAttachmentUpload(u);
698
- await tt(async () => {
702
+ await et(async () => {
699
703
  const h = await fetch(l.uploadUrl, {
700
704
  method: l.uploadMethod,
701
705
  headers: l.uploadHeaders,
702
706
  body: t
703
707
  });
704
708
  if (!h.ok)
705
- throw new q("Failed to upload attachment", h.status);
709
+ throw new F("Failed to upload attachment", h.status);
706
710
  return h;
707
711
  }, "Failed to upload attachment"), this.setState({ sessionId: l.sessionId });
708
- const c = Gt(l.attachment, this.options.backendUrl);
709
- return this.updateAttachmentInState(s.id, c), s.id && vt(s.id, {
712
+ const c = Jt(l.attachment, this.options.backendUrl);
713
+ return this.updateAttachmentInState(s.id, c), s.id && Ot(s.id, {
710
714
  sessionId: l.sessionId,
711
715
  fileUrl: c.fileUrl,
712
716
  gcsPath: c.gcsPath,
@@ -728,7 +732,7 @@ class qt {
728
732
  return this.state.sessionId ? Promise.resolve(this.state.sessionId) : new Promise((t, s) => {
729
733
  const n = window.setTimeout(() => {
730
734
  r(), s(new Error("Timed out waiting for Pluno session before persisting attachment"));
731
- }, Oe), r = this.on("state", (i) => {
735
+ }, qe), r = this.on("state", (i) => {
732
736
  i.sessionId && (window.clearTimeout(n), r(), t(i.sessionId));
733
737
  });
734
738
  });
@@ -746,18 +750,18 @@ class qt {
746
750
  }
747
751
  async prepareEmbedAttachmentUpload(t) {
748
752
  let s = !1;
749
- return await tt(async () => {
753
+ return await et(async () => {
750
754
  const n = await this.fetchEmbedAttachmentUpload(t);
751
755
  if (n.ok)
752
756
  return await n.json();
753
- if (wn(n.status) && this.options.tokenProvider && !s) {
757
+ if (Sn(n.status) && this.options.tokenProvider && !s) {
754
758
  s = !0;
755
759
  const r = await this.fetchEmbedAttachmentUpload(t);
756
760
  if (r.ok)
757
761
  return await r.json();
758
- throw new q("Failed to prepare attachment upload", r.status);
762
+ throw new F("Failed to prepare attachment upload", r.status);
759
763
  }
760
- throw new q("Failed to prepare attachment upload", n.status);
764
+ throw new F("Failed to prepare attachment upload", n.status);
761
765
  }, "Failed to prepare attachment upload");
762
766
  }
763
767
  async fetchEmbedAttachmentUpload(t) {
@@ -779,7 +783,7 @@ class qt {
779
783
  !this.options.keepRunsActiveOnSessionNavigation && s && this.state.sessionId && this.state.isThinking && this.send({ type: "run.stop", sessionId: this.state.sessionId, reason: "new_chat" }), this.cleanupSessionUserFilesApi(), this.queuedClientEvents = this.queuedClientEvents.filter((n) => n.type !== "chat.user_message"), this.clearThinkingWatchdog(), this.retryableClientMessageId = null, this.retryAttemptsByClientMessageId = {}, this.thinkingWatchdogResyncAttemptsByClientMessageId = {}, s && this.send({
780
784
  type: "session.reset",
781
785
  sessionId: this.state.sessionId ?? void 0,
782
- page: A()
786
+ page: S()
783
787
  }), this.setState({
784
788
  sessionId: null,
785
789
  starterPrompts: [...this.state.starterPrompts],
@@ -792,15 +796,15 @@ class qt {
792
796
  });
793
797
  }
794
798
  listSessions(t = {}) {
795
- const s = O(), n = new Promise((i, o) => {
799
+ const s = B(), n = new Promise((i, o) => {
796
800
  const a = window.setTimeout(() => {
797
801
  this.pendingSessionHistoryRequests.delete(s), o(new Error("Session history did not respond in time"));
798
- }, Ne);
802
+ }, Le);
799
803
  this.pendingSessionHistoryRequests.set(s, { resolve: i, reject: o, timeout: a });
800
804
  }), r = {
801
805
  type: "sessions.list",
802
806
  requestId: s,
803
- page: A(),
807
+ page: S(),
804
808
  ...t.cursor ? { cursor: t.cursor } : {},
805
809
  ...t.limit ? { limit: t.limit } : {}
806
810
  };
@@ -822,11 +826,11 @@ class qt {
822
826
  }), this.send({
823
827
  type: "session.load",
824
828
  sessionId: t,
825
- page: A()
829
+ page: S()
826
830
  });
827
831
  }
828
832
  send(t) {
829
- this.sendNow(S(t)) || (this.queuedClientEvents.push(t), P(this.options.clientId, this.queuedClientEvents), this.setState({ status: "reconnecting" }), this.scheduleReconnect());
833
+ this.sendNow(k(t)) || (this.queuedClientEvents.push(t), P(this.options.clientId, this.queuedClientEvents), this.setState({ status: "reconnecting" }), this.scheduleReconnect());
830
834
  }
831
835
  async getUploadToken() {
832
836
  const t = this.options.token ?? await this.options.tokenProvider?.() ?? this.token ?? null;
@@ -852,9 +856,9 @@ class qt {
852
856
  if (this.state.starterPromptsLoading || this.transientStarterPromptsRequestInFlight || this.transientStarterPromptsRequestAttempted)
853
857
  return;
854
858
  this.transientStarterPromptsRequestInFlight = !0, this.transientStarterPromptsRequestAttempted = !0, this.setState({ starterPromptsLoading: !0 });
855
- const t = us();
859
+ const t = ps();
856
860
  this.sendNow(
857
- S({
861
+ k({
858
862
  type: "starter_prompts.page_context",
859
863
  pageUrl: t.pageUrl,
860
864
  pageTitle: t.pageTitle,
@@ -863,13 +867,13 @@ class qt {
863
867
  ) || (this.transientStarterPromptsRequestInFlight = !1, this.transientStarterPromptsRequestAttempted = !1, this.setState({ starterPromptsLoading: !1 }));
864
868
  }
865
869
  startStarterPromptUrlWatcher() {
866
- this.locationChangeCleanup || (this.locationChangeCleanup = ds(() => this.handleStarterPromptUrlChange()));
870
+ this.locationChangeCleanup || (this.locationChangeCleanup = gs(() => this.handleStarterPromptUrlChange()));
867
871
  }
868
872
  handleStarterPromptUrlChange() {
869
873
  const t = location.href;
870
874
  t !== this.lastStarterPromptPageUrl && (this.lastStarterPromptPageUrl = t, this.clearStarterPromptUrlRefreshTimer(), this.starterPromptUrlRefreshTimer = window.setTimeout(() => {
871
875
  this.starterPromptUrlRefreshTimer = null, this.refreshStarterPromptsForCurrentUrl();
872
- }, Fe));
876
+ }, $e));
873
877
  }
874
878
  refreshStarterPromptsForCurrentUrl() {
875
879
  this.socket?.readyState !== WebSocket.OPEN || this.state.status === "closed" || (this.setState({ starterPromptsLoading: this.state.messages.length === 0 }), this.sendNow({
@@ -887,7 +891,7 @@ class qt {
887
891
  P(this.options.clientId, this.queuedClientEvents);
888
892
  for (let s = 0; s < t.length; s += 1) {
889
893
  const n = t[s];
890
- if (!this.sendNow(S(n))) {
894
+ if (!this.sendNow(k(n))) {
891
895
  this.queuedClientEvents.unshift(n, ...t.slice(s + 1)), P(this.options.clientId, this.queuedClientEvents);
892
896
  return;
893
897
  }
@@ -903,91 +907,107 @@ class qt {
903
907
  this.clearHeartbeatAckTimer();
904
908
  return;
905
909
  }
906
- if (Ge(t) && this.markThinkingProgress(), t.type === "auth.ok") {
910
+ if (Je(t) && this.markThinkingProgress(), t.type === "auth.ok") {
907
911
  this.clearSocketAuthTimer(), this.reconnectAttempts = 0, this.flushQueuedClientEvents(), this.startHeartbeat();
908
- const s = ys(t), n = Object.prototype.hasOwnProperty.call(t, "appearance");
912
+ const s = Is(t), n = Object.prototype.hasOwnProperty.call(t, "appearance");
909
913
  y("web-sdk.agent", "Received auth.ok appearance", {
910
914
  hasAppearance: n,
911
915
  rawAppearance: t.appearance,
912
916
  normalizedAppearance: s
913
- }), this.runtimeHelperJavascript = Ts(t.runtimeHelpers)?.javascript ?? null;
914
- const r = Rt(t, "starterPrompts"), i = Object.prototype.hasOwnProperty.call(t, "starterPrompts"), o = t.starterPromptsLoading === !0, a = {
915
- user: Ss(t.user),
917
+ }), this.runtimeHelperJavascript = As(t.runtimeHelpers)?.javascript ?? null;
918
+ const r = Ct(t, "starterPrompts"), i = Object.prototype.hasOwnProperty.call(t, "starterPrompts"), o = t.starterPromptsLoading === !0, a = {
919
+ user: Rs(t.user),
916
920
  status: "connected"
917
921
  };
918
- (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 && !ps() && this.requestTransientStarterPrompts(), this.state.sessionId && this.send({
922
+ (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 && !ms() && this.requestTransientStarterPrompts(), this.state.sessionId && this.send({
919
923
  type: "page.upsert",
920
924
  sessionId: this.state.sessionId,
921
- page: A(),
925
+ page: S(),
922
926
  model: this.options.model
923
927
  });
924
928
  return;
925
929
  }
926
930
  if (t.type === "starterPrompts.updated") {
927
931
  this.transientStarterPromptsRequestInFlight = !1, this.transientStarterPromptsRequestAttempted = !0, this.setState({
928
- starterPrompts: Rt(t, "starterPrompts"),
932
+ starterPrompts: Ct(t, "starterPrompts"),
929
933
  starterPromptsLoading: !1
930
934
  });
931
935
  return;
932
936
  }
933
937
  if (t.type === "conversation.state") {
934
- const s = Array.isArray(t.items) ? t.items : [], n = qs(s);
938
+ const s = Array.isArray(t.items) ? t.items : [];
939
+ this.rememberUserMessageClientMessageIds(s);
940
+ const n = Hs(s);
935
941
  if (n) {
936
- const a = xs(s, n);
942
+ const u = Ws(s, n);
937
943
  this.retryAttemptsByClientMessageId[n] = Math.max(
938
944
  this.retryAttemptsByClientMessageId[n] ?? 0,
939
- a
945
+ u
940
946
  );
941
947
  }
942
- const r = Us(
948
+ const r = n ? s.filter((u) => !bt(x(u))) : s, i = Ns(
943
949
  this.state.messages,
944
- ks(s, this.options.backendUrl)
945
- ), i = Ct(r);
946
- if (!i && Bs(this.state.messages, s))
950
+ Cs(r, this.options.backendUrl)
951
+ ), o = _t(i);
952
+ if (!o && Fs(this.state.messages, s))
947
953
  return;
948
- const o = i ? null : ot(s);
949
- if (this.latestRecoverableClientMessageId = o, Os(r) && this.clearRetryTimers(), this.setState({
950
- sessionId: k(t.session, "id") ?? this.state.sessionId,
951
- messages: r,
952
- ...i ? { assistantDraft: "", assistantDraftRespondsToUserMessageId: null, assistantDraftRunId: null, isThinking: !1 } : o ? {
954
+ const a = o ? null : at(s);
955
+ if (this.latestRecoverableClientMessageId = a, qs(i) && this.clearRetryTimers(), this.setState({
956
+ sessionId: I(t.session, "id") ?? this.state.sessionId,
957
+ messages: i,
958
+ ...o ? { assistantDraft: "", assistantDraftRespondsToUserMessageId: null, assistantDraftRunId: null, isThinking: !1 } : a ? {
953
959
  assistantDraft: "",
954
960
  assistantDraftRespondsToUserMessageId: null,
955
961
  assistantDraftRunId: null,
956
962
  isThinking: !0,
957
963
  lastError: null
958
964
  } : {}
959
- }), i ? (this.retryableClientMessageId = null, this.clearThinkingWatchdog()) : o && (this.activeClientMessageId = o, this.markThinkingProgress()), n) {
960
- const a = k(t.session, "id") ?? this.state.sessionId;
961
- a && this.retryAfterInterruptedRun(a, n);
965
+ }), o ? (this.retryableClientMessageId = null, this.clearThinkingWatchdog()) : a && (this.activeClientMessageId = a, this.markThinkingProgress()), n) {
966
+ const u = I(t.session, "id") ?? this.state.sessionId;
967
+ u && this.retryAfterInterruptedRun(u, n);
962
968
  }
963
969
  return;
964
970
  }
965
971
  if (t.type === "sessions.page") {
966
972
  const s = typeof t.requestId == "string" ? t.requestId : null, n = s ? this.pendingSessionHistoryRequests.get(s) : null;
967
973
  s && n && (window.clearTimeout(n.timeout), this.pendingSessionHistoryRequests.delete(s), n.resolve({
968
- sessions: Es(t.sessions),
974
+ sessions: _s(t.sessions),
969
975
  nextCursor: typeof t.nextCursor == "string" ? t.nextCursor : null
970
976
  }));
971
977
  return;
972
978
  }
973
979
  if (t.type === "session.updated") {
974
- this.clearRunAckResyncRetryTimer(), this.setState({ sessionId: k(t.session, "id") ?? this.state.sessionId });
980
+ this.clearRunAckResyncRetryTimer(), this.setState({ sessionId: I(t.session, "id") ?? this.state.sessionId });
975
981
  return;
976
982
  }
977
983
  if (t.type === "session.item") {
978
- const s = Ht(t.item, this.options.backendUrl);
979
- if (s) {
980
- s.role === "assistant" && (this.retryableClientMessageId = null, this.clearRetryTimers(), this.clearRunAckResyncRetryTimer());
981
- const n = t.item.data;
982
- Hs(n) && this.clearRunAckResyncRetryTimer();
983
- const r = Ps(this.state.messages, s), i = Ct(r);
984
+ this.rememberUserMessageClientMessageIds([t.item]);
985
+ const s = x(t.item);
986
+ if (bt(s)) {
987
+ typeof s?.runId == "string" && this.retryableFailureRunIdsAwaitingDone.add(s.runId);
988
+ const r = I(t.item, "sessionId") ?? this.state.sessionId, i = s ? D(s) : null, o = i ? this.clientMessageIdsByUserMessageItemId.get(i) : null, a = typeof s?.clientMessageId == "string" ? s.clientMessageId : o ?? (i ? null : this.activeClientMessageId ?? this.latestRecoverableClientMessageId);
989
+ if (r && a) {
990
+ this.retryAfterInterruptedRun(r, a);
991
+ return;
992
+ }
993
+ if (r && i) {
994
+ this.setState({ status: "connected", isThinking: !0, lastError: null, lastErrorCode: null }), this.resyncThinkingSession();
995
+ return;
996
+ }
997
+ }
998
+ const n = jt(t.item, this.options.backendUrl);
999
+ if (n) {
1000
+ n.role === "assistant" && (this.retryableClientMessageId = null, this.clearRetryTimers(), this.clearRunAckResyncRetryTimer());
1001
+ const r = t.item.data;
1002
+ js(r) && this.clearRunAckResyncRetryTimer();
1003
+ const i = vs(this.state.messages, n), o = _t(i);
984
1004
  this.setState({
985
- messages: r,
986
- assistantDraft: s.role === "assistant" ? "" : this.state.assistantDraft,
987
- assistantDraftRespondsToUserMessageId: s.role === "assistant" ? null : this.state.assistantDraftRespondsToUserMessageId,
988
- assistantDraftRunId: s.role === "assistant" ? null : this.state.assistantDraftRunId,
989
- ...i ? { assistantDraft: "", assistantDraftRespondsToUserMessageId: null, assistantDraftRunId: null, isThinking: !1 } : {}
990
- }), i && this.clearThinkingWatchdog(), this.emit("message", s);
1005
+ messages: i,
1006
+ assistantDraft: n.role === "assistant" ? "" : this.state.assistantDraft,
1007
+ assistantDraftRespondsToUserMessageId: n.role === "assistant" ? null : this.state.assistantDraftRespondsToUserMessageId,
1008
+ assistantDraftRunId: n.role === "assistant" ? null : this.state.assistantDraftRunId,
1009
+ ...o ? { assistantDraft: "", assistantDraftRespondsToUserMessageId: null, assistantDraftRunId: null, isThinking: !1 } : {}
1010
+ }), o && this.clearThinkingWatchdog(), this.emit("message", n);
991
1011
  }
992
1012
  return;
993
1013
  }
@@ -1003,6 +1023,8 @@ class qt {
1003
1023
  return;
1004
1024
  }
1005
1025
  if (t.type === "chat.assistant_done") {
1026
+ if (typeof t.runId == "string" && this.retryableFailureRunIdsAwaitingDone.delete(t.runId))
1027
+ return;
1006
1028
  this.retryableClientMessageId = null;
1007
1029
  const s = typeof t.sessionId == "string" ? t.sessionId : this.state.sessionId;
1008
1030
  this.setState({
@@ -1025,10 +1047,12 @@ class qt {
1025
1047
  return;
1026
1048
  }
1027
1049
  const r = typeof t.sessionId == "string" ? t.sessionId : this.state.sessionId, i = typeof t.clientMessageId == "string" ? t.clientMessageId : null, o = t.retryable === !0 || t.code === "transient_model_error";
1028
- if (this.retryAfterRetryableError(t))
1050
+ if (this.retryAfterRetryableError(t)) {
1051
+ t.code !== "run_still_active" && typeof t.runId == "string" && this.retryableFailureRunIdsAwaitingDone.add(t.runId);
1029
1052
  return;
1053
+ }
1030
1054
  o && r && i && (this.retryableClientMessageId = i);
1031
- const a = new Error(typeof t.message == "string" ? t.message.replace(/Product Agent/g, "Pluno") : "Pluno error"), u = cs(a.message);
1055
+ const a = new Error(typeof t.message == "string" ? t.message.replace(/Product Agent/g, "Pluno") : "Pluno error"), u = ds(a.message);
1032
1056
  u && console.error(u), this.setState({
1033
1057
  status: "error",
1034
1058
  isThinking: !1,
@@ -1050,15 +1074,17 @@ class qt {
1050
1074
  }
1051
1075
  return !0;
1052
1076
  }
1077
+ if (this.retryTimersByClientMessageId[n] !== void 0)
1078
+ return !0;
1053
1079
  const i = this.retryAttemptsByClientMessageId[n] ?? 0;
1054
1080
  if (i >= v)
1055
1081
  return !1;
1056
1082
  this.retryAttemptsByClientMessageId[n] = i + 1;
1057
- const o = D(
1083
+ const o = N(
1058
1084
  i,
1059
1085
  typeof t.retryAfterMs == "number" ? t.retryAfterMs : 0
1060
1086
  );
1061
- return this.setState({ status: "reconnecting", isThinking: !0, lastError: null }), this.retryTimersByClientMessageId[n] = window.setTimeout(() => {
1087
+ return this.setState({ status: "connected", isThinking: !0, lastError: null }), this.retryTimersByClientMessageId[n] = window.setTimeout(() => {
1062
1088
  delete this.retryTimersByClientMessageId[n], this.setState({ status: "connected", isThinking: !0, lastError: null }), this.markThinkingProgress(), this.send({
1063
1089
  type: "chat.retry_last_user_message",
1064
1090
  sessionId: s,
@@ -1079,14 +1105,20 @@ class qt {
1079
1105
  }), this.clearThinkingWatchdog();
1080
1106
  return;
1081
1107
  }
1082
- this.retryAttemptsByClientMessageId[s] = n + 1, this.activeClientMessageId = s, this.latestRecoverableClientMessageId = s, this.setState({ status: "reconnecting", isThinking: !0, lastError: null, lastErrorCode: null }), this.retryTimersByClientMessageId[s] = window.setTimeout(() => {
1108
+ this.retryAttemptsByClientMessageId[s] = n + 1, this.activeClientMessageId = s, this.latestRecoverableClientMessageId = s, this.setState({ status: "connected", isThinking: !0, lastError: null, lastErrorCode: null }), this.retryTimersByClientMessageId[s] = window.setTimeout(() => {
1083
1109
  delete this.retryTimersByClientMessageId[s], this.setState({ status: "connected", isThinking: !0, lastError: null, lastErrorCode: null }), this.markThinkingProgress(), this.send({ type: "chat.retry_last_user_message", sessionId: t, clientMessageId: s, automatic: !0 });
1084
- }, D(n));
1110
+ }, N(n));
1085
1111
  }
1086
1112
  clearRetryTimers() {
1087
1113
  for (const t of Object.values(this.retryTimersByClientMessageId))
1088
1114
  window.clearTimeout(t);
1089
- this.retryTimersByClientMessageId = {};
1115
+ this.retryTimersByClientMessageId = {}, this.retryableFailureRunIdsAwaitingDone.clear();
1116
+ }
1117
+ rememberUserMessageClientMessageIds(t) {
1118
+ for (const s of t) {
1119
+ const n = I(s, "id"), r = x(s);
1120
+ n && r?.type === "message" && r.role === "user" && typeof r.clientMessageId == "string" && this.clientMessageIdsByUserMessageItemId.set(n, r.clientMessageId);
1121
+ }
1090
1122
  }
1091
1123
  rejectPendingSessionHistoryRequests(t) {
1092
1124
  for (const s of this.pendingSessionHistoryRequests.values())
@@ -1094,7 +1126,7 @@ class qt {
1094
1126
  this.pendingSessionHistoryRequests.clear();
1095
1127
  }
1096
1128
  markThinkingProgress() {
1097
- !this.state.isThinking || this.state.status === "closed" || (this.scheduleThinkingWatchdog(At), this.activeClientMessageId && this.scheduleRunAckWatchdog(this.activeClientMessageId));
1129
+ !this.state.isThinking || this.state.status === "closed" || (this.scheduleThinkingWatchdog(St), this.activeClientMessageId && this.scheduleRunAckWatchdog(this.activeClientMessageId));
1098
1130
  }
1099
1131
  scheduleThinkingWatchdog(t) {
1100
1132
  this.thinkingWatchdogTimer !== null && window.clearTimeout(this.thinkingWatchdogTimer), this.thinkingWatchdogTimer = window.setTimeout(() => {
@@ -1114,7 +1146,7 @@ class qt {
1114
1146
  scheduleRunAckWatchdog(t) {
1115
1147
  this.runAckWatchdogTimer !== null && window.clearTimeout(this.runAckWatchdogTimer), this.runAckWatchdogTimer = window.setTimeout(() => {
1116
1148
  this.runAckWatchdogTimer = null, this.recoverMissedRunAck(t);
1117
- }, Ue);
1149
+ }, Ne);
1118
1150
  }
1119
1151
  recoverMissedRunAck(t) {
1120
1152
  !this.state.isThinking || this.state.status === "closed" || this.activeClientMessageId !== t || (y("web-sdk.agent", "Pluno run ack missed; resyncing session", {
@@ -1138,8 +1170,8 @@ class qt {
1138
1170
  sessionId: this.state.sessionId,
1139
1171
  clientMessageId: t,
1140
1172
  automatic: !0
1141
- }) : this.activeUserMessageEvent && this.send(this.activeUserMessageEvent), this.scheduleThinkingWatchdog(At)));
1142
- }, D(s)));
1173
+ }) : this.activeUserMessageEvent && this.send(this.activeUserMessageEvent), this.scheduleThinkingWatchdog(St)));
1174
+ }, N(s)));
1143
1175
  }
1144
1176
  clearRunAckResyncRetryTimer() {
1145
1177
  this.runAckResyncRetryTimer !== null && (window.clearTimeout(this.runAckResyncRetryTimer), this.runAckResyncRetryTimer = null);
@@ -1178,7 +1210,7 @@ class qt {
1178
1210
  sessionId: this.state.sessionId,
1179
1211
  clientMessageId: t,
1180
1212
  resyncAttempts: s + 1
1181
- }), this.resyncThinkingSession(), this.scheduleThinkingWatchdog(Me);
1213
+ }), this.resyncThinkingSession(), this.scheduleThinkingWatchdog(De);
1182
1214
  return;
1183
1215
  }
1184
1216
  this.setState({
@@ -1196,13 +1228,13 @@ class qt {
1196
1228
  clientMessageId: t,
1197
1229
  automatic: !0
1198
1230
  }) : this.activeUserMessageEvent && this.send(this.activeUserMessageEvent), this.markThinkingProgress();
1199
- }, D(n)));
1231
+ }, N(n)));
1200
1232
  }
1201
1233
  resyncThinkingSession() {
1202
1234
  this.state.sessionId ? this.send({
1203
1235
  type: "page.upsert",
1204
1236
  sessionId: this.state.sessionId,
1205
- page: A(),
1237
+ page: S(),
1206
1238
  model: this.options.model
1207
1239
  }) : (!this.socket || this.socket.readyState !== WebSocket.OPEN) && (this.setState({ status: "reconnecting", lastError: null }), this.scheduleReconnect());
1208
1240
  }
@@ -1210,15 +1242,15 @@ class qt {
1210
1242
  const s = typeof t.sessionId == "string" ? t.sessionId : null, n = typeof t.callId == "string" ? t.callId : null, r = typeof t.toolName == "string" ? t.toolName : null, i = typeof t.summary == "string" ? t.summary : "Running browser tool", o = t.rawInput;
1211
1243
  if (!s || !n || !r)
1212
1244
  return;
1213
- if (r !== "execute_code" || !an(o)) {
1245
+ if (r !== "execute_code" || !un(o)) {
1214
1246
  this.send({
1215
1247
  type: "tool.result",
1216
1248
  sessionId: s,
1217
1249
  callId: n,
1218
1250
  toolName: r,
1219
1251
  summary: i,
1220
- rawInput: S(o),
1221
- rawOutput: S({
1252
+ rawInput: k(o),
1253
+ rawOutput: k({
1222
1254
  ok: !1,
1223
1255
  toolName: r,
1224
1256
  error: `Unsupported browser tool: ${r}`
@@ -1226,7 +1258,7 @@ class qt {
1226
1258
  });
1227
1259
  return;
1228
1260
  }
1229
- const a = Je(this.state.messages);
1261
+ const a = Ze(this.state.messages);
1230
1262
  this.activeBrowserToolCalls.set(n, {
1231
1263
  event: {
1232
1264
  type: "tool.result",
@@ -1234,7 +1266,7 @@ class qt {
1234
1266
  callId: n,
1235
1267
  toolName: r,
1236
1268
  summary: o.summary,
1237
- rawInput: S(o),
1269
+ rawInput: k(o),
1238
1270
  rawOutput: null
1239
1271
  },
1240
1272
  startedAtMs: Date.now(),
@@ -1242,9 +1274,9 @@ class qt {
1242
1274
  startedAtOrigin: location.origin
1243
1275
  }), this.installSessionUserFilesApi(a);
1244
1276
  let u = null, l;
1245
- u = await this.executeRuntimeHelper(), l = await Et({
1277
+ u = await this.executeRuntimeHelper(), l = await Rt({
1246
1278
  ...o,
1247
- javascript: ae(o.javascript, {
1279
+ javascript: ue(o.javascript, {
1248
1280
  clientId: this.options.clientId,
1249
1281
  sessionId: s,
1250
1282
  callId: n
@@ -1260,55 +1292,55 @@ class qt {
1260
1292
  callId: n,
1261
1293
  toolName: r,
1262
1294
  summary: o.summary,
1263
- rawInput: S(o),
1264
- rawOutput: S(ws(l, u))
1265
- }), Js(this.options.clientId, this.activeBrowserToolCalls.values());
1295
+ rawInput: k(o),
1296
+ rawOutput: k(Ss(l, u))
1297
+ }), Zs(this.options.clientId, this.activeBrowserToolCalls.values());
1266
1298
  }
1267
1299
  startPageLifecycleRecovery() {
1268
1300
  if (this.pageLifecycleCleanup)
1269
1301
  return;
1270
1302
  const t = () => {
1271
- $t(this.options.clientId, this.activeBrowserToolCalls.values());
1303
+ Xt(this.options.clientId, this.activeBrowserToolCalls.values());
1272
1304
  };
1273
1305
  window.addEventListener("pagehide", t), window.addEventListener("beforeunload", t), this.pageLifecycleCleanup = () => {
1274
1306
  window.removeEventListener("pagehide", t), window.removeEventListener("beforeunload", t);
1275
1307
  };
1276
1308
  }
1277
1309
  installSessionUserFilesApi(t) {
1278
- this.cleanupSessionUserFilesApi(), this.sessionUserFilesApiCleanup = Ve(t, this.attachmentFiles, this.attachmentBlobCache);
1310
+ this.cleanupSessionUserFilesApi(), this.sessionUserFilesApiCleanup = Qe(t, this.attachmentFiles, this.attachmentBlobCache);
1279
1311
  }
1280
1312
  cleanupSessionUserFilesApi() {
1281
- this.sessionUserFilesApiCleanup && (rs(this.sessionUserFilesApiCleanup), this.sessionUserFilesApiCleanup = null);
1313
+ this.sessionUserFilesApiCleanup && (as(this.sessionUserFilesApiCleanup), this.sessionUserFilesApiCleanup = null);
1282
1314
  }
1283
1315
  async executeRuntimeHelper() {
1284
1316
  if (!this.runtimeHelperJavascript?.trim())
1285
1317
  return null;
1286
- const t = await Et({
1318
+ const t = await Rt({
1287
1319
  javascript: this.runtimeHelperJavascript
1288
1320
  });
1289
- return t.ok === !1 ? Is(t) : null;
1321
+ return t.ok === !1 ? ks(t) : null;
1290
1322
  }
1291
1323
  enableNetworkCapture() {
1292
- this.networkCaptureCleanup || (this.networkCaptureCleanup = $e((t) => {
1293
- pn(t.url, this.options.backendUrl) || this.enqueueNetworkEvent(t);
1324
+ this.networkCaptureCleanup || (this.networkCaptureCleanup = Xe((t) => {
1325
+ mn(t.url, this.options.backendUrl) || this.enqueueNetworkEvent(t);
1294
1326
  }));
1295
1327
  }
1296
1328
  enqueueNetworkEvent(t) {
1297
- this.queuedNetworkEvents.length >= De || (this.queuedNetworkEvents.push(hn(t)), this.networkBatchTimer === null && (this.networkBatchTimer = window.setTimeout(() => {
1329
+ this.queuedNetworkEvents.length >= Be || (this.queuedNetworkEvents.push(fn(t)), this.networkBatchTimer === null && (this.networkBatchTimer = window.setTimeout(() => {
1298
1330
  this.networkBatchTimer = null;
1299
1331
  const s = this.queuedNetworkEvents.splice(0, this.queuedNetworkEvents.length);
1300
1332
  s.length === 0 || this.socket?.readyState !== WebSocket.OPEN || this.sendNow({
1301
1333
  type: "network.batch",
1302
1334
  sessionId: this.state.sessionId ?? void 0,
1303
- page: A(),
1335
+ page: S(),
1304
1336
  events: s
1305
1337
  });
1306
- }, ve)));
1338
+ }, Oe)));
1307
1339
  }
1308
1340
  scheduleReconnect() {
1309
1341
  if (this.reconnectTimer !== null || this.state.status === "closed")
1310
1342
  return;
1311
- const t = We(this.reconnectAttempts);
1343
+ const t = ze(this.reconnectAttempts);
1312
1344
  this.reconnectAttempts += 1, this.reconnectTimer = window.setTimeout(() => {
1313
1345
  this.reconnectTimer = null, this.connect().catch((s) => {
1314
1346
  y("web-sdk.agent", "Pluno reconnect failed; retrying", {
@@ -1324,8 +1356,8 @@ class qt {
1324
1356
  const t = this.socket;
1325
1357
  !t || !this.sendNow({ type: "runtime.ping" }) || (this.clearHeartbeatAckTimer(), this.heartbeatAckTimer = window.setTimeout(() => {
1326
1358
  this.socket === t && (y("web-sdk.agent", "Pluno heartbeat acknowledgement timed out; reconnecting"), this.replaceTimedOutSocket(t));
1327
- }, Ee));
1328
- }, ke);
1359
+ }, _e));
1360
+ }, Ce);
1329
1361
  }
1330
1362
  stopHeartbeat() {
1331
1363
  this.heartbeatTimer !== null && (window.clearInterval(this.heartbeatTimer), this.heartbeatTimer = null), this.clearHeartbeatAckTimer();
@@ -1350,20 +1382,20 @@ class qt {
1350
1382
  ...this.state,
1351
1383
  ...t,
1352
1384
  ...t.lastError === null && t.lastErrorCode === void 0 ? { lastErrorCode: null } : {}
1353
- }, Xs(this.options.clientId, this.state), this.emit("state", this.getState());
1385
+ }, Vs(this.options.clientId, this.state), this.emit("state", this.getState());
1354
1386
  }
1355
1387
  emit(t, s) {
1356
1388
  this.listeners[t]?.forEach((r) => r(s));
1357
1389
  }
1358
1390
  }
1359
- const Y = /* @__PURE__ */ new WeakMap();
1360
- function $e(e) {
1361
- const t = window.__plunoProductAgentNetworkCapture ?? ze();
1391
+ const Q = /* @__PURE__ */ new WeakMap();
1392
+ function Xe(e) {
1393
+ const t = window.__plunoProductAgentNetworkCapture ?? Ke();
1362
1394
  return t.subscribers.add(e), () => {
1363
1395
  t.subscribers.delete(e), !(t.subscribers.size > 0) && (t.destroy(), window.__plunoProductAgentNetworkCapture === t && delete window.__plunoProductAgentNetworkCapture);
1364
1396
  };
1365
1397
  }
1366
- function ze() {
1398
+ function Ke() {
1367
1399
  const e = /* @__PURE__ */ new Set(), t = (T) => {
1368
1400
  e.forEach((p) => {
1369
1401
  try {
@@ -1372,7 +1404,7 @@ function ze() {
1372
1404
  }
1373
1405
  });
1374
1406
  }, s = window.fetch, n = XMLHttpRequest.prototype.open, r = XMLHttpRequest.prototype.setRequestHeader, i = XMLHttpRequest.prototype.send, o = function(p, d) {
1375
- const f = Date.now();
1407
+ const g = Date.now();
1376
1408
  let w;
1377
1409
  try {
1378
1410
  w = s.call(this, p, d);
@@ -1380,32 +1412,32 @@ function ze() {
1380
1412
  throw m;
1381
1413
  }
1382
1414
  try {
1383
- const m = p instanceof Request ? p : null, g = cn(p, m), I = Xt(d?.headers ?? m?.headers);
1384
- if (!b(g, I, d?.body)) {
1385
- const G = {
1386
- requestId: Q("fetch"),
1387
- url: E(g, V),
1415
+ const m = p instanceof Request ? p : null, f = dn(p, m), A = Vt(d?.headers ?? m?.headers);
1416
+ if (!b(f, A, d?.body)) {
1417
+ const K = {
1418
+ requestId: tt("fetch"),
1419
+ url: E(f, Z),
1388
1420
  method: (d?.method ?? m?.method ?? "GET").toUpperCase(),
1389
- requestHeaders: I,
1390
- requestBody: Mt(d?.body),
1421
+ requestHeaders: A,
1422
+ requestBody: Dt(d?.body),
1391
1423
  resourceType: "fetch",
1392
- startedAt: new Date(f).toISOString()
1424
+ startedAt: new Date(g).toISOString()
1393
1425
  };
1394
1426
  w.then(
1395
1427
  (C) => {
1396
- ln(C, G, f, t).catch(() => {
1428
+ hn(C, K, g, t).catch(() => {
1397
1429
  t({
1398
- ...G,
1430
+ ...K,
1399
1431
  responseStatus: C.status,
1400
- durationMs: Date.now() - f
1432
+ durationMs: Date.now() - g
1401
1433
  });
1402
1434
  });
1403
1435
  },
1404
1436
  (C) => {
1405
1437
  t({
1406
- ...G,
1438
+ ...K,
1407
1439
  errorText: E(C instanceof Error ? C.message : String(C)),
1408
- durationMs: Date.now() - f
1440
+ durationMs: Date.now() - g
1409
1441
  });
1410
1442
  }
1411
1443
  );
@@ -1413,29 +1445,29 @@ function ze() {
1413
1445
  } catch {
1414
1446
  }
1415
1447
  return w;
1416
- }, a = function(p, d, f, w, m) {
1417
- const g = n.call(this, p, d, f ?? !0, w ?? void 0, m ?? void 0), I = typeof d == "string" ? d : d.toString();
1418
- return Y.set(this, {
1419
- requestId: Q("xhr"),
1448
+ }, a = function(p, d, g, w, m) {
1449
+ const f = n.call(this, p, d, g ?? !0, w ?? void 0, m ?? void 0), A = typeof d == "string" ? d : d.toString();
1450
+ return Q.set(this, {
1451
+ requestId: tt("xhr"),
1420
1452
  method: String(p ?? "GET").toUpperCase(),
1421
- url: E(I, V),
1453
+ url: E(A, Z),
1422
1454
  requestHeaders: {},
1423
1455
  startedAtMs: Date.now(),
1424
1456
  startedAt: (/* @__PURE__ */ new Date()).toISOString(),
1425
- excluded: b(I)
1426
- }), g;
1457
+ excluded: b(A)
1458
+ }), f;
1427
1459
  }, u = function(p, d) {
1428
- const f = r.call(this, p, d), w = Y.get(this);
1429
- return w && Object.keys(w.requestHeaders).length < ht && (w.requestHeaders[p] = yt(p, d), w.excluded = w.excluded || b(w.url, w.requestHeaders)), f;
1460
+ const g = r.call(this, p, d), w = Q.get(this);
1461
+ return w && Object.keys(w.requestHeaders).length < pt && (w.requestHeaders[p] = Tt(p, d), w.excluded = w.excluded || b(w.url, w.requestHeaders)), g;
1430
1462
  }, l = function(p) {
1431
1463
  try {
1432
- const d = Y.get(this);
1433
- d && (d.excluded = d.excluded || b(d.url, d.requestHeaders, p), d.requestBody = Mt(p), d.excluded || this.addEventListener(
1464
+ const d = Q.get(this);
1465
+ d && (d.excluded = d.excluded || b(d.url, d.requestHeaders, p), d.requestBody = Dt(p), d.excluded || this.addEventListener(
1434
1466
  "loadend",
1435
1467
  () => {
1436
1468
  queueMicrotask(() => {
1437
1469
  try {
1438
- const f = gn(this.getAllResponseHeaders());
1470
+ const g = Tn(this.getAllResponseHeaders());
1439
1471
  t({
1440
1472
  requestId: d.requestId,
1441
1473
  url: d.url,
@@ -1444,8 +1476,8 @@ function ze() {
1444
1476
  requestBody: d.requestBody,
1445
1477
  resourceType: "xhr",
1446
1478
  responseStatus: this.status,
1447
- responseHeaders: f,
1448
- responseBody: dn(this, f),
1479
+ responseHeaders: g,
1480
+ responseBody: gn(this, g),
1449
1481
  errorText: this.status === 0 ? "XHR request failed or was aborted" : void 0,
1450
1482
  startedAt: d.startedAt,
1451
1483
  durationMs: Date.now() - d.startedAtMs
@@ -1484,14 +1516,14 @@ function ze() {
1484
1516
  const d = p;
1485
1517
  if (d.initiatorType === "fetch" || d.initiatorType === "xmlhttprequest" || b(d.name))
1486
1518
  continue;
1487
- const f = performance.timeOrigin + d.startTime;
1519
+ const g = performance.timeOrigin + d.startTime;
1488
1520
  t({
1489
- requestId: Q("resource"),
1490
- url: E(d.name, V),
1521
+ requestId: tt("resource"),
1522
+ url: E(d.name, Z),
1491
1523
  method: "GET",
1492
1524
  resourceType: "resource",
1493
1525
  responseStatus: d.responseStatus,
1494
- startedAt: new Date(f).toISOString(),
1526
+ startedAt: new Date(g).toISOString(),
1495
1527
  durationMs: d.duration
1496
1528
  });
1497
1529
  }
@@ -1537,15 +1569,15 @@ function y(e, t, s) {
1537
1569
  }, i = n.__plunoProductAgentDiagnostics__ ?? [];
1538
1570
  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 }));
1539
1571
  }
1540
- function kt(e) {
1572
+ function Et(e) {
1541
1573
  const t = typeof e == "function" ? e() : e;
1542
1574
  return t && Object.keys(t).length > 0 ? t : void 0;
1543
1575
  }
1544
- function Ge(e) {
1576
+ function Je(e) {
1545
1577
  return e.type === "conversation.state" || e.type === "session.updated" || e.type === "session.item" || e.type === "chat.assistant_delta" || e.type === "chat.assistant_done" || e.type === "tool.call";
1546
1578
  }
1547
- const Xe = 5e3, Ke = 12e4;
1548
- function Je(e) {
1579
+ const Ve = 5e3, Ye = 12e4;
1580
+ function Ze(e) {
1549
1581
  const t = [];
1550
1582
  for (const s of e)
1551
1583
  s.role !== "user" || !s.attachments?.length || s.attachments.forEach((n, r) => {
@@ -1556,17 +1588,17 @@ function Je(e) {
1556
1588
  });
1557
1589
  return t;
1558
1590
  }
1559
- function Ve(e, t = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map()) {
1591
+ function Qe(e, t = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map()) {
1560
1592
  const n = [
1561
- Ye(e, t, s),
1562
- Ze()
1593
+ ts(e, t, s),
1594
+ es()
1563
1595
  ].filter((r) => typeof r == "function");
1564
1596
  return () => {
1565
1597
  for (const r of n.reverse())
1566
1598
  r();
1567
1599
  };
1568
1600
  }
1569
- function Ye(e, t = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map()) {
1601
+ function ts(e, t = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map()) {
1570
1602
  const n = new Map(e.map((l) => [l.id, l])), r = (l) => ({
1571
1603
  id: l.id,
1572
1604
  name: l.name,
@@ -1586,7 +1618,7 @@ function Ye(e, t = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map()) {
1586
1618
  const T = s.get(c.id);
1587
1619
  if (T)
1588
1620
  return T;
1589
- const p = await se(c.id).then((m) => m?.blob ?? null).catch((m) => (y("web-sdk.attachments", "Failed to load Product Agent attachment from IndexedDB", {
1621
+ const p = await ie(c.id).then((m) => m?.blob ?? null).catch((m) => (y("web-sdk.attachments", "Failed to load Product Agent attachment from IndexedDB", {
1590
1622
  attachmentId: c.id,
1591
1623
  name: c.name,
1592
1624
  message: m instanceof Error ? m.message : String(m)
@@ -1595,18 +1627,18 @@ function Ye(e, t = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map()) {
1595
1627
  return s.set(c.id, p), p;
1596
1628
  if (!c.fileUrl)
1597
1629
  throw new Error(`Pluno user file is missing content: ${l}`);
1598
- const d = await fetch(c.fileUrl, en(c.fileUrl));
1630
+ const d = await fetch(c.fileUrl, rn(c.fileUrl));
1599
1631
  if (!d.ok)
1600
1632
  throw new Error(`Failed to load Pluno user file: ${l}`);
1601
- const f = await d.blob();
1602
- s.set(c.id, f);
1633
+ const g = await d.blob();
1634
+ s.set(c.id, g);
1603
1635
  const w = Date.now();
1604
- return Ut({
1636
+ return Nt({
1605
1637
  attachmentId: c.id,
1606
1638
  name: c.name,
1607
1639
  mimeType: c.mimeType,
1608
1640
  sizeBytes: c.sizeBytes,
1609
- blob: f,
1641
+ blob: g,
1610
1642
  fileUrl: c.fileUrl,
1611
1643
  gcsPath: c.gcsPath,
1612
1644
  createdAt: w,
@@ -1617,9 +1649,9 @@ function Ye(e, t = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map()) {
1617
1649
  name: c.name,
1618
1650
  message: m instanceof Error ? m.message : String(m)
1619
1651
  });
1620
- }), f;
1652
+ }), g;
1621
1653
  };
1622
- return Nt(globalThis, "userFiles", {
1654
+ return Lt(globalThis, "userFiles", {
1623
1655
  list: () => e.map(r),
1624
1656
  get: (l) => {
1625
1657
  const c = n.get(l);
@@ -1630,14 +1662,14 @@ function Ye(e, t = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map()) {
1630
1662
  if (!T.startsWith("image/"))
1631
1663
  throw new Error(`Pluno user file is not an image: ${l}`);
1632
1664
  const p = h.type === T ? h : new Blob([h], { type: T });
1633
- return is(T, p.size) > xe ? {
1665
+ return cs(T, p.size) > We ? {
1634
1666
  type: "pluno.userFiles.inspectImage",
1635
1667
  id: c.id,
1636
1668
  name: c.name,
1637
1669
  mimeType: T,
1638
1670
  sizeBytes: c.sizeBytes,
1639
1671
  imageAttached: !1,
1640
- imageAttachmentError: pt
1672
+ imageAttachmentError: gt
1641
1673
  } : {
1642
1674
  type: "pluno.userFiles.inspectImage",
1643
1675
  id: c.id,
@@ -1645,10 +1677,10 @@ function Ye(e, t = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map()) {
1645
1677
  mimeType: T,
1646
1678
  sizeBytes: c.sizeBytes,
1647
1679
  imageAttached: !0,
1648
- dataUrl: await it(p)
1680
+ dataUrl: await ot(p)
1649
1681
  };
1650
1682
  },
1651
- getDataUrl: async (l) => (i(l), await it(await o(l))),
1683
+ getDataUrl: async (l) => (i(l), await ot(await o(l))),
1652
1684
  getBlob: o,
1653
1685
  getArrayBuffer: async (l) => await (await o(l)).arrayBuffer(),
1654
1686
  getFile: async (l) => {
@@ -1657,17 +1689,17 @@ function Ye(e, t = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map()) {
1657
1689
  }
1658
1690
  });
1659
1691
  }
1660
- function Ze() {
1661
- return Nt(globalThis, "pageImages", {
1662
- inspectImage: async (t, s) => await Qe(t, s)
1692
+ function es() {
1693
+ return Lt(globalThis, "pageImages", {
1694
+ inspectImage: async (t, s) => await ss(t, s)
1663
1695
  });
1664
1696
  }
1665
- async function Qe(e, t = {}) {
1666
- const s = ns(t.name), n = await ts(e);
1697
+ async function ss(e, t = {}) {
1698
+ const s = os(t.name), n = await ns(e);
1667
1699
  return n.ok ? n.sizeBytes > 8 * 1024 * 1024 ? {
1668
1700
  type: "pluno.pageImages.inspectImage",
1669
1701
  imageAttached: !1,
1670
- imageAttachmentError: pt
1702
+ imageAttachmentError: gt
1671
1703
  } : {
1672
1704
  type: "pluno.pageImages.inspectImage",
1673
1705
  imageAttached: !0,
@@ -1681,15 +1713,15 @@ async function Qe(e, t = {}) {
1681
1713
  imageAttachmentError: n.error
1682
1714
  };
1683
1715
  }
1684
- async function ts(e) {
1685
- return e instanceof Blob ? e.type.startsWith("image/") ? e.size === 0 ? { ok: !1, error: "Page image is empty." } : e.size > 8 * 1024 * 1024 ? { ok: !1, error: pt } : {
1716
+ async function ns(e) {
1717
+ return e instanceof Blob ? e.type.startsWith("image/") ? e.size === 0 ? { ok: !1, error: "Page image is empty." } : e.size > 8 * 1024 * 1024 ? { ok: !1, error: gt } : {
1686
1718
  ok: !0,
1687
1719
  mimeType: e.type,
1688
1720
  sizeBytes: e.size,
1689
- dataUrl: await it(e)
1690
- } : { ok: !1, error: "Page image must be an image Blob or complete data:image/* URL." } : typeof e != "string" ? { ok: !1, error: "Page image must be an image Blob or complete data:image/* URL." } : es(e);
1721
+ dataUrl: await ot(e)
1722
+ } : { ok: !1, error: "Page image must be an image Blob or complete data:image/* URL." } : typeof e != "string" ? { ok: !1, error: "Page image must be an image Blob or complete data:image/* URL." } : rs(e);
1691
1723
  }
1692
- function es(e) {
1724
+ function rs(e) {
1693
1725
  if (!e.startsWith("data:") || !e.includes(","))
1694
1726
  return { ok: !1, error: "Page image must be a complete data:image/* URL, not bare base64." };
1695
1727
  const [t, s] = e.slice(5).split(",", 2), n = t.split(";").map((a) => a.trim()).filter(Boolean), r = n[0] ?? "";
@@ -1700,7 +1732,7 @@ function es(e) {
1700
1732
  const i = s.replace(/[ \t\r\n\f]+/g, "");
1701
1733
  if (!/^[A-Za-z0-9+/]*={0,2}$/.test(i))
1702
1734
  return { ok: !1, error: "Page image data URL has invalid base64." };
1703
- const o = ss(i);
1735
+ const o = is(i);
1704
1736
  return o === null ? { ok: !1, error: "Page image data URL has invalid base64." } : o === 0 ? { ok: !1, error: "Page image is empty." } : {
1705
1737
  ok: !0,
1706
1738
  mimeType: r,
@@ -1708,22 +1740,22 @@ function es(e) {
1708
1740
  dataUrl: `data:${r};base64,${i}`
1709
1741
  };
1710
1742
  }
1711
- function ss(e) {
1743
+ function is(e) {
1712
1744
  if (e.length === 0 || e.length % 4 !== 0)
1713
1745
  return null;
1714
1746
  const t = e.length - e.replace(/=+$/, "").length;
1715
1747
  return t > 2 ? null : e.length / 4 * 3 - t;
1716
1748
  }
1717
- function ns(e) {
1749
+ function os(e) {
1718
1750
  return (typeof e == "string" ? e.trim() : "") || "Page image";
1719
1751
  }
1720
- function rs(e) {
1752
+ function as(e) {
1721
1753
  try {
1722
1754
  e();
1723
1755
  } catch {
1724
1756
  }
1725
1757
  }
1726
- function it(e) {
1758
+ function ot(e) {
1727
1759
  return new Promise((t, s) => {
1728
1760
  const n = new FileReader();
1729
1761
  n.onload = () => {
@@ -1735,12 +1767,12 @@ function it(e) {
1735
1767
  }, n.onerror = () => s(n.error ?? new Error("Failed to read Pluno user file")), n.readAsDataURL(e);
1736
1768
  });
1737
1769
  }
1738
- function is(e, t) {
1770
+ function cs(e, t) {
1739
1771
  return `data:${e};base64,`.length + Math.ceil(t / 3) * 4;
1740
1772
  }
1741
- async function Et(e) {
1773
+ async function Rt(e) {
1742
1774
  const t = Object.getPrototypeOf(async function() {
1743
- }).constructor, s = e.timeoutMs ?? Xe, n = Date.now(), r = [];
1775
+ }).constructor, s = e.timeoutMs ?? Ve, n = Date.now(), r = [];
1744
1776
  let i;
1745
1777
  const o = {
1746
1778
  log: console.log,
@@ -1758,7 +1790,7 @@ async function Et(e) {
1758
1790
  i = window.setTimeout(() => c(u), s);
1759
1791
  })
1760
1792
  ]);
1761
- return l === u ? os(s) : {
1793
+ return l === u ? ls(s) : {
1762
1794
  ok: !0,
1763
1795
  result: l,
1764
1796
  console: r,
@@ -1787,7 +1819,7 @@ async function Et(e) {
1787
1819
  i !== void 0 && window.clearTimeout(i), console.log = o.log, console.info = o.info, console.warn = o.warn, console.error = o.error;
1788
1820
  }
1789
1821
  }
1790
- function os(e) {
1822
+ function ls(e) {
1791
1823
  return {
1792
1824
  ok: !1,
1793
1825
  exception: {
@@ -1801,18 +1833,18 @@ function os(e) {
1801
1833
  }
1802
1834
  };
1803
1835
  }
1804
- function as(e) {
1836
+ function us(e) {
1805
1837
  return e.replace(/\/+$/, "");
1806
1838
  }
1807
- function cs(e, t = location.origin) {
1839
+ function ds(e, t = location.origin) {
1808
1840
  return /origin (?:is not allowed|does not match browser origin)/i.test(e) ? `Pluno widget blocked on ${t}: this domain is not allowed. Add ${t} in Pluno under Integration > Domains.` : null;
1809
1841
  }
1810
- function ls(e) {
1842
+ function hs(e) {
1811
1843
  const t = new URL("/api/product-agent/embed/ws", e);
1812
1844
  return t.protocol = t.protocol === "https:" ? "wss:" : "ws:", t.toString();
1813
1845
  }
1814
- function A() {
1815
- const e = xt();
1846
+ function S() {
1847
+ const e = Wt();
1816
1848
  return {
1817
1849
  url: location.href,
1818
1850
  title: document.title,
@@ -1820,21 +1852,21 @@ function A() {
1820
1852
  ...e ? { plunoProductAgentUi: e } : {}
1821
1853
  };
1822
1854
  }
1823
- function us() {
1855
+ function ps() {
1824
1856
  return {
1825
1857
  pageUrl: location.href,
1826
1858
  pageTitle: document.title,
1827
- htmlContent: fs()
1859
+ htmlContent: ys()
1828
1860
  };
1829
1861
  }
1830
- function ds(e) {
1831
- return B.add(e), N || (N = hs()), () => {
1832
- B.delete(e), B.size === 0 && (N?.(), N = null);
1862
+ function gs(e) {
1863
+ return q.add(e), O || (O = fs()), () => {
1864
+ q.delete(e), q.size === 0 && (O?.(), O = null);
1833
1865
  };
1834
1866
  }
1835
- function hs() {
1867
+ function fs() {
1836
1868
  const e = () => {
1837
- for (const i of Array.from(B))
1869
+ for (const i of Array.from(q))
1838
1870
  i();
1839
1871
  }, t = window.history.pushState.bind(window.history), s = window.history.replaceState.bind(window.history), n = ((...i) => {
1840
1872
  const o = t(...i);
@@ -1847,10 +1879,10 @@ function hs() {
1847
1879
  window.history.pushState === n && (window.history.pushState = t), window.history.replaceState === r && (window.history.replaceState = s), window.removeEventListener("popstate", e), window.removeEventListener("hashchange", e);
1848
1880
  };
1849
1881
  }
1850
- function ps() {
1851
- return xt()?.surface === "browser_extension_sdk_preview";
1882
+ function ms() {
1883
+ return Wt()?.surface === "browser_extension_sdk_preview";
1852
1884
  }
1853
- function fs() {
1885
+ function ys() {
1854
1886
  const e = document.body?.cloneNode(!0);
1855
1887
  return e instanceof HTMLElement ? (e.querySelectorAll(
1856
1888
  [
@@ -1874,9 +1906,9 @@ function fs() {
1874
1906
  s.name === "href" || s.name === "aria-label" || s.name === "role" || t.removeAttribute(s.name);
1875
1907
  }), e.textContent?.replace(/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}/gi, "[email]").replace(/\b(?:\d[ -]*?){13,19}\b/g, "[number]").replace(/\b(?:sk|pk|tok|key|secret|token)_[A-Za-z0-9_-]{8,}\b/gi, "[secret]").replace(/\s+/g, " ").trim().slice(0, 12e3) ?? "") : "";
1876
1908
  }
1877
- function xt() {
1878
- const e = document.querySelector(Tt);
1879
- if (!(e ?? document.querySelector(nt)))
1909
+ function Wt() {
1910
+ const e = document.querySelector(wt);
1911
+ if (!(e ?? document.querySelector(rt)))
1880
1912
  return;
1881
1913
  const s = e ? "browser_extension_sdk_preview" : "embedded_widget";
1882
1914
  return {
@@ -1885,28 +1917,28 @@ function xt() {
1885
1917
  selectors: [
1886
1918
  {
1887
1919
  name: "widget_host",
1888
- selector: s === "browser_extension_sdk_preview" ? Tt : nt,
1920
+ selector: s === "browser_extension_sdk_preview" ? wt : rt,
1889
1921
  description: "Finds Pluno's shadow-host element in the host page DOM."
1890
1922
  },
1891
1923
  {
1892
1924
  name: "widget_root",
1893
- selector: Te,
1925
+ selector: Ae,
1894
1926
  description: "Finds Pluno's widget root inside the widget host shadow root."
1895
1927
  },
1896
1928
  {
1897
1929
  name: "widget_panel",
1898
- selector: we,
1930
+ selector: Se,
1899
1931
  description: "Finds Pluno's open chat panel inside the widget host shadow root."
1900
1932
  },
1901
1933
  {
1902
1934
  name: "widget_timeline",
1903
- selector: Ie,
1935
+ selector: ke,
1904
1936
  description: "Finds Pluno's chat timeline inside the widget host shadow root."
1905
1937
  }
1906
1938
  ]
1907
1939
  };
1908
1940
  }
1909
- function gs(e) {
1941
+ function Ts(e) {
1910
1942
  try {
1911
1943
  const t = JSON.parse(e);
1912
1944
  return t && typeof t == "object" ? t : { type: "error", message: "Invalid server event" };
@@ -1914,16 +1946,16 @@ function gs(e) {
1914
1946
  return { type: "error", message: "Invalid server event" };
1915
1947
  }
1916
1948
  }
1917
- function Rt(e, t) {
1949
+ function Ct(e, t) {
1918
1950
  if (!e || typeof e != "object")
1919
1951
  return [];
1920
1952
  const s = e[t];
1921
1953
  return Array.isArray(s) ? s.filter((n) => typeof n == "string" && n.trim().length > 0) : [];
1922
1954
  }
1923
- function ms(e) {
1955
+ function ws(e) {
1924
1956
  return Array.isArray(e) ? e.filter((t) => typeof t == "string" && t.trim().length > 0) : [];
1925
1957
  }
1926
- function ys(e) {
1958
+ function Is(e) {
1927
1959
  if (!e || typeof e != "object")
1928
1960
  return null;
1929
1961
  const t = e, s = t.appearance, n = s && typeof s == "object" ? s : t, r = typeof n.accentColor == "string" ? n.accentColor : null, i = n.colorScheme === "dark" ? "dark" : n.colorScheme === "light" ? "light" : null, o = typeof n.fontFamily == "string" && n.fontFamily.trim() ? n.fontFamily : null, a = typeof n.scribbleStyle == "boolean" ? n.scribbleStyle : null;
@@ -1934,13 +1966,13 @@ function ys(e) {
1934
1966
  ...a !== null ? { scribbleStyle: a } : {}
1935
1967
  };
1936
1968
  }
1937
- function Ts(e) {
1969
+ function As(e) {
1938
1970
  if (!e || typeof e != "object")
1939
1971
  return null;
1940
1972
  const t = e.javascript;
1941
1973
  return typeof t != "string" || !t.trim() ? null : { javascript: t };
1942
1974
  }
1943
- function ws(e, t) {
1975
+ function Ss(e, t) {
1944
1976
  return t ? e && typeof e == "object" ? {
1945
1977
  ...e,
1946
1978
  helperError: t
@@ -1950,23 +1982,23 @@ function ws(e, t) {
1950
1982
  helperError: t
1951
1983
  } : e;
1952
1984
  }
1953
- function Is(e) {
1985
+ function ks(e) {
1954
1986
  if (!e || typeof e != "object")
1955
1987
  return e;
1956
1988
  const t = e;
1957
1989
  return typeof t.exception?.message == "string" ? t.exception.message : typeof t.error == "string" ? t.error : e;
1958
1990
  }
1959
- function As() {
1991
+ function Es() {
1960
1992
  const e = "pluno.productAgent.clientId", t = window.localStorage.getItem(e);
1961
1993
  if (t)
1962
1994
  return t;
1963
1995
  const s = crypto.randomUUID();
1964
1996
  return window.localStorage.setItem(e, s), s;
1965
1997
  }
1966
- function O() {
1998
+ function B() {
1967
1999
  return crypto.randomUUID();
1968
2000
  }
1969
- function Ss(e) {
2001
+ function Rs(e) {
1970
2002
  if (!e || typeof e != "object")
1971
2003
  return null;
1972
2004
  const t = e, s = typeof t.id == "string" ? t.id : null;
@@ -1977,23 +2009,23 @@ function Ss(e) {
1977
2009
  avatarUrl: typeof t.avatarUrl == "string" ? t.avatarUrl : null
1978
2010
  } : null;
1979
2011
  }
1980
- function ks(e, t) {
1981
- return Array.isArray(e) ? at(
1982
- ct(
1983
- e.map((s) => Ht(s, t)).filter((s) => s !== null)
2012
+ function Cs(e, t) {
2013
+ return Array.isArray(e) ? ct(
2014
+ lt(
2015
+ e.map((s) => jt(s, t)).filter((s) => s !== null)
1984
2016
  )
1985
2017
  ) : [];
1986
2018
  }
1987
- function Es(e) {
2019
+ function _s(e) {
1988
2020
  return Array.isArray(e) ? e.flatMap((t) => {
1989
2021
  if (!t || typeof t != "object")
1990
2022
  return [];
1991
- const s = t, n = k(s, "id"), r = k(s, "createdAt"), i = k(s, "updatedAt"), o = k(s, "lastActiveAt");
2023
+ const s = t, n = I(s, "id"), r = I(s, "createdAt"), i = I(s, "updatedAt"), o = I(s, "lastActiveAt");
1992
2024
  return !n || !r || !i || !o ? [] : [
1993
2025
  {
1994
2026
  id: n,
1995
- title: k(s, "title"),
1996
- firstUserMessage: k(s, "firstUserMessage"),
2027
+ title: I(s, "title"),
2028
+ firstUserMessage: I(s, "firstUserMessage"),
1997
2029
  currentPage: s.currentPage ?? null,
1998
2030
  createdAt: r,
1999
2031
  updatedAt: i,
@@ -2003,7 +2035,7 @@ function Es(e) {
2003
2035
  ];
2004
2036
  }) : [];
2005
2037
  }
2006
- function Ht(e, t) {
2038
+ function jt(e, t) {
2007
2039
  if (!e || typeof e != "object")
2008
2040
  return null;
2009
2041
  const s = e, n = s.data;
@@ -2015,39 +2047,39 @@ function Ht(e, t) {
2015
2047
  return {
2016
2048
  id: String(s.id ?? crypto.randomUUID()),
2017
2049
  role: i,
2018
- content: Ms(r.content),
2050
+ content: Ds(r.content),
2019
2051
  createdAt: typeof s.createdAt == "string" ? s.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
2020
- respondsToUserMessageId: Z(r) ?? void 0,
2052
+ respondsToUserMessageId: D(r) ?? void 0,
2021
2053
  ..._(r) ? { runId: _(r) } : {},
2022
- attachments: zt(r.attachments, t)
2054
+ attachments: Kt(r.attachments, t)
2023
2055
  };
2024
2056
  }
2025
2057
  return r.type === "function_call" || r.type === "tool_call" || r.type === "web_search_call" ? {
2026
2058
  id: String(s.id ?? crypto.randomUUID()),
2027
2059
  role: "tool",
2028
- content: Cs(r),
2060
+ content: Ms(r),
2029
2061
  createdAt: typeof s.createdAt == "string" ? s.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
2030
- respondsToUserMessageId: Z(r) ?? void 0,
2062
+ respondsToUserMessageId: D(r) ?? void 0,
2031
2063
  ..._(r) ? { runId: _(r) } : {},
2032
2064
  dataType: String(r.type),
2033
2065
  toolName: typeof r.name == "string" ? r.name : void 0,
2034
- callId: bs(r) ?? void 0,
2066
+ callId: Us(r) ?? void 0,
2035
2067
  loading: r.localExecutionStatus === "running"
2036
2068
  } : r.type === "run_status" || r.type === "run_error" ? r.type === "run_error" && r.stage === "tool_execution" ? null : {
2037
2069
  id: String(s.id ?? crypto.randomUUID()),
2038
2070
  role: "system",
2039
- content: Rs(r),
2071
+ content: bs(r),
2040
2072
  createdAt: typeof s.createdAt == "string" ? s.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
2041
- respondsToUserMessageId: Z(r) ?? void 0,
2073
+ respondsToUserMessageId: D(r) ?? void 0,
2042
2074
  ..._(r) ? { runId: _(r) } : {},
2043
2075
  dataType: String(r.type),
2044
2076
  loading: r.type === "run_status" && (r.status === "running" || r.status === "retrying")
2045
2077
  } : null;
2046
2078
  }
2047
- function Rs(e) {
2079
+ function bs(e) {
2048
2080
  return typeof e.message == "string" && e.message.trim().length > 0 ? e.message.replace(/Product Agent/g, "Pluno") : e.type === "run_status" && e.status === "interrupted" ? "Pluno was interrupted before it could finish this message." : e.type === "run_status" && e.status === "stopped" ? "Pluno stopped." : "Pluno run status changed.";
2049
2081
  }
2050
- function Cs(e) {
2082
+ function Ms(e) {
2051
2083
  if (e.type === "web_search_call") {
2052
2084
  const t = e.action;
2053
2085
  if (t && typeof t == "object") {
@@ -2059,9 +2091,9 @@ function Cs(e) {
2059
2091
  }
2060
2092
  return "Searching the web";
2061
2093
  }
2062
- return _s(e);
2094
+ return Ps(e);
2063
2095
  }
2064
- function _s(e) {
2096
+ function Ps(e) {
2065
2097
  if (typeof e.summary == "string" && e.summary.trim().length > 0)
2066
2098
  return e.summary;
2067
2099
  if (typeof e.arguments == "string")
@@ -2074,11 +2106,11 @@ function _s(e) {
2074
2106
  }
2075
2107
  return typeof e.name == "string" && e.name.trim().length > 0 ? e.name : "Run tool";
2076
2108
  }
2077
- function bs(e) {
2109
+ function Us(e) {
2078
2110
  const t = e.callId ?? e.call_id;
2079
2111
  return typeof t == "string" && t ? t : null;
2080
2112
  }
2081
- function Ms(e) {
2113
+ function Ds(e) {
2082
2114
  return typeof e == "string" ? e : Array.isArray(e) ? e.map((t) => {
2083
2115
  if (!t || typeof t != "object")
2084
2116
  return "";
@@ -2086,24 +2118,24 @@ function Ms(e) {
2086
2118
  return typeof s.text == "string" ? s.text : typeof s.content == "string" ? s.content : "";
2087
2119
  }).filter(Boolean).join("") : "";
2088
2120
  }
2089
- function Ps(e, t) {
2090
- const s = Ft(e, t), n = Ns(e, t), r = n.findIndex((o) => o.id === s.id);
2121
+ function vs(e, t) {
2122
+ const s = $t(e, t), n = Ls(e, t), r = n.findIndex((o) => o.id === s.id);
2091
2123
  if (r === -1)
2092
- return at(
2093
- ct([...n, s])
2124
+ return ct(
2125
+ lt([...n, s])
2094
2126
  );
2095
2127
  const i = [...n];
2096
- return i[r] = s, at(ct(i));
2128
+ return i[r] = s, ct(lt(i));
2097
2129
  }
2098
- function Us(e, t) {
2130
+ function Ns(e, t) {
2099
2131
  const s = t.map(
2100
- (n) => Ft(e, n)
2132
+ (n) => $t(e, n)
2101
2133
  );
2102
2134
  return t.length > 0 ? s : e.filter(
2103
2135
  (n) => n.role === "user" && n.id.startsWith("local-")
2104
2136
  );
2105
2137
  }
2106
- function Ft(e, t) {
2138
+ function $t(e, t) {
2107
2139
  if (t.role !== "user" || !t.attachments?.length)
2108
2140
  return t;
2109
2141
  const s = e.find(
@@ -2112,19 +2144,19 @@ function Ft(e, t) {
2112
2144
  if (!s?.attachments?.length)
2113
2145
  return t;
2114
2146
  const n = t.attachments.map((r) => {
2115
- const i = vs(s.attachments ?? [], r);
2116
- return i ? Ds(r, i) : r;
2147
+ const i = Os(s.attachments ?? [], r);
2148
+ return i ? Bs(r, i) : r;
2117
2149
  });
2118
2150
  return { ...t, attachments: n };
2119
2151
  }
2120
- function vs(e, t) {
2152
+ function Os(e, t) {
2121
2153
  return t.id ? e.find((s) => s.id === t.id) ?? null : null;
2122
2154
  }
2123
- function Ds(e, t) {
2155
+ function Bs(e, t) {
2124
2156
  const { previewUrl: s } = t;
2125
2157
  return s ? { ...e, previewUrl: s } : e;
2126
2158
  }
2127
- function Ns(e, t) {
2159
+ function Ls(e, t) {
2128
2160
  if (t.role !== "user")
2129
2161
  return e;
2130
2162
  const s = e.findIndex(
@@ -2135,8 +2167,8 @@ function Ns(e, t) {
2135
2167
  const n = [...e];
2136
2168
  return n.splice(s, 1), n;
2137
2169
  }
2138
- function Ct(e) {
2139
- const t = Wt(e);
2170
+ function _t(e) {
2171
+ const t = zt(e);
2140
2172
  if (t === null)
2141
2173
  return !1;
2142
2174
  for (let s = e.length - 1; s > t; s -= 1) {
@@ -2152,17 +2184,17 @@ function Ct(e) {
2152
2184
  }
2153
2185
  return !1;
2154
2186
  }
2155
- function Os(e) {
2156
- const t = Wt(e);
2187
+ function qs(e) {
2188
+ const t = zt(e);
2157
2189
  return t === null ? e.some((s) => s.role === "assistant") : e.slice(t + 1).some((s) => s.role === "assistant");
2158
2190
  }
2159
- function Wt(e) {
2191
+ function zt(e) {
2160
2192
  for (let t = e.length - 1; t >= 0; t -= 1)
2161
2193
  if (e[t].role === "user")
2162
2194
  return t;
2163
2195
  return null;
2164
2196
  }
2165
- function Ls(e) {
2197
+ function xs(e) {
2166
2198
  return e.role === "assistant" ? !0 : e.role !== "system" ? !1 : e.dataType === "run_error" ? !0 : e.dataType === "run_status" && e.loading !== !0;
2167
2199
  }
2168
2200
  function ft(e) {
@@ -2179,7 +2211,16 @@ function ft(e) {
2179
2211
  }
2180
2212
  return null;
2181
2213
  }
2182
- function Bs(e, t) {
2214
+ function x(e) {
2215
+ if (!e || typeof e != "object")
2216
+ return null;
2217
+ const t = e.data;
2218
+ return t && typeof t == "object" ? t : null;
2219
+ }
2220
+ function bt(e) {
2221
+ return e?.retryable !== !0 ? !1 : e.type === "run_error" ? !0 : e.type === "run_status" && e.status === "interrupted";
2222
+ }
2223
+ function Fs(e, t) {
2183
2224
  const s = ft(t);
2184
2225
  if (s === null)
2185
2226
  return !1;
@@ -2187,9 +2228,9 @@ function Bs(e, t) {
2187
2228
  if (typeof r != "string" || !r)
2188
2229
  return !1;
2189
2230
  const i = e.findIndex((o) => o.role === "user" && o.id === r);
2190
- return i === -1 ? !1 : e.slice(i + 1).some(Ls);
2231
+ return i === -1 ? !1 : e.slice(i + 1).some(xs);
2191
2232
  }
2192
- function ot(e) {
2233
+ function at(e) {
2193
2234
  const t = ft(e);
2194
2235
  if (t === null)
2195
2236
  return null;
@@ -2202,7 +2243,7 @@ function ot(e) {
2202
2243
  const r = n.clientMessageId;
2203
2244
  return typeof r == "string" ? r : null;
2204
2245
  }
2205
- function qs(e) {
2246
+ function Hs(e) {
2206
2247
  const t = ft(e);
2207
2248
  if (t === null)
2208
2249
  return null;
@@ -2217,13 +2258,22 @@ function qs(e) {
2217
2258
  if (i.type === "message" && i.role === "assistant")
2218
2259
  return null;
2219
2260
  if (i.type === "run_error")
2220
- return i.retryable !== !0 ? null : typeof i.clientMessageId == "string" ? i.clientMessageId : ot(e);
2261
+ return i.retryable !== !0 ? null : Mt(e, i) ?? at(e);
2221
2262
  if (i.type === "run_status")
2222
- return i.status === "interrupted" && i.retryable === !0 ? ot(e) : null;
2263
+ return i.status === "interrupted" && i.retryable === !0 ? Mt(e, i) ?? at(e) : null;
2223
2264
  }
2224
2265
  return null;
2225
2266
  }
2226
- function xs(e, t) {
2267
+ function Mt(e, t) {
2268
+ if (typeof t.clientMessageId == "string")
2269
+ return t.clientMessageId;
2270
+ const s = D(t);
2271
+ if (!s)
2272
+ return null;
2273
+ const n = e.find((i) => I(i, "id") === s), r = x(n);
2274
+ return r?.type === "message" && r.role === "user" && typeof r.clientMessageId == "string" ? r.clientMessageId : null;
2275
+ }
2276
+ function Ws(e, t) {
2227
2277
  let s = 0;
2228
2278
  for (const n of e) {
2229
2279
  if (!n || typeof n != "object")
@@ -2236,22 +2286,22 @@ function xs(e, t) {
2236
2286
  }
2237
2287
  return s;
2238
2288
  }
2239
- function Hs(e) {
2289
+ function js(e) {
2240
2290
  if (!e || typeof e != "object")
2241
2291
  return !1;
2242
2292
  const t = e;
2243
2293
  return t.type === "message" && t.role === "user" ? !1 : t.type === "message" || t.type === "function_call" || t.type === "function_call_output" || t.type === "run_error" || t.type === "run_status";
2244
2294
  }
2245
- function at(e) {
2246
- return e.filter((t, s) => jt(t) ? !zs(e, s) && !js(e, s) && !$s(e, s) : Fs(t) ? !Ws(e, s) : !0);
2295
+ function ct(e) {
2296
+ return e.filter((t, s) => Gt(t) ? !Ks(e, s) && !Gs(e, s) && !Xs(e, s) : $s(t) ? !zs(e, s) : !0);
2247
2297
  }
2248
- function Fs(e) {
2298
+ function $s(e) {
2249
2299
  return e.role === "system" && (e.dataType === "run_status" || e.dataType === "run_error");
2250
2300
  }
2251
- function jt(e) {
2301
+ function Gt(e) {
2252
2302
  return e.role === "system" && e.dataType === "run_status" && e.loading === !0;
2253
2303
  }
2254
- function ct(e) {
2304
+ function lt(e) {
2255
2305
  const t = new Set(e.filter((i) => i.role === "user").map((i) => i.id)), s = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set();
2256
2306
  for (const i of e) {
2257
2307
  if (i.role === "user" || !i.respondsToUserMessageId || !t.has(i.respondsToUserMessageId))
@@ -2267,53 +2317,53 @@ function ct(e) {
2267
2317
  n.has(i.id) || (r.push(i), i.role === "user" && r.push(...s.get(i.id) ?? []));
2268
2318
  return r;
2269
2319
  }
2270
- function Ws(e, t) {
2320
+ function zs(e, t) {
2271
2321
  const s = e[t];
2272
2322
  for (let n = t + 1; n < e.length; n += 1) {
2273
2323
  const r = e[n];
2274
2324
  if (r.role === "user")
2275
2325
  return !1;
2276
- if (r.role === "assistant" && $(s, r))
2326
+ if (r.role === "assistant" && G(s, r))
2277
2327
  return !0;
2278
2328
  }
2279
2329
  return !1;
2280
2330
  }
2281
- function js(e, t) {
2331
+ function Gs(e, t) {
2282
2332
  const s = e[t];
2283
2333
  for (let n = t + 1; n < e.length; n += 1)
2284
- if (e[n].role === "assistant" && $(s, e[n]))
2334
+ if (e[n].role === "assistant" && G(s, e[n]))
2285
2335
  return !0;
2286
2336
  return !1;
2287
2337
  }
2288
- function $s(e, t) {
2338
+ function Xs(e, t) {
2289
2339
  const s = e[t];
2290
2340
  for (let n = t + 1; n < e.length; n += 1)
2291
- if (e[n].role === "tool" && $(s, e[n]))
2341
+ if (e[n].role === "tool" && G(s, e[n]))
2292
2342
  return !0;
2293
2343
  return !1;
2294
2344
  }
2295
- function zs(e, t) {
2345
+ function Ks(e, t) {
2296
2346
  const s = e[t];
2297
2347
  for (let n = t + 1; n < e.length; n += 1)
2298
- if (jt(e[n]) && $(s, e[n]))
2348
+ if (Gt(e[n]) && G(s, e[n]))
2299
2349
  return !0;
2300
2350
  return !1;
2301
2351
  }
2302
- function $(e, t) {
2352
+ function G(e, t) {
2303
2353
  return !e.runId || !t.runId ? !0 : e.runId === t.runId;
2304
2354
  }
2305
- function k(e, t) {
2355
+ function I(e, t) {
2306
2356
  return e && typeof e == "object" && typeof e[t] == "string" ? e[t] : null;
2307
2357
  }
2308
- function Gs(e, t) {
2358
+ function Js(e, t) {
2309
2359
  try {
2310
- const s = window.localStorage.getItem(`${Bt}${e}`);
2360
+ const s = window.localStorage.getItem(`${Ft}${e}`);
2311
2361
  if (!s)
2312
2362
  return null;
2313
2363
  const n = JSON.parse(s), r = typeof n.sessionId == "string" ? n.sessionId : null;
2314
2364
  if (t !== void 0 && r !== t)
2315
2365
  return null;
2316
- const i = Array.isArray(n.messages) ? n.messages.map(rn).filter((o) => !!o) : [];
2366
+ const i = Array.isArray(n.messages) ? n.messages.map(cn).filter((o) => !!o) : [];
2317
2367
  return {
2318
2368
  sessionId: r,
2319
2369
  messages: i
@@ -2322,48 +2372,48 @@ function Gs(e, t) {
2322
2372
  return null;
2323
2373
  }
2324
2374
  }
2325
- function Xs(e, t) {
2375
+ function Vs(e, t) {
2326
2376
  try {
2327
2377
  window.localStorage.setItem(
2328
- `${Bt}${e}`,
2378
+ `${Ft}${e}`,
2329
2379
  JSON.stringify({
2330
2380
  sessionId: t.sessionId,
2331
- messages: t.messages.slice(-He).map(on)
2381
+ messages: t.messages.slice(-je).map(ln)
2332
2382
  })
2333
2383
  );
2334
2384
  } catch {
2335
2385
  return;
2336
2386
  }
2337
2387
  }
2338
- function Ks(e) {
2388
+ function Ys(e) {
2339
2389
  try {
2340
- const t = window.localStorage.getItem(`${rt}${e}`);
2390
+ const t = window.localStorage.getItem(`${it}${e}`);
2341
2391
  if (!t)
2342
2392
  return [];
2343
2393
  const s = JSON.parse(t);
2344
- return Array.isArray(s) ? s.filter(gt) : [];
2394
+ return Array.isArray(s) ? s.filter(mt) : [];
2345
2395
  } catch {
2346
2396
  return [];
2347
2397
  }
2348
2398
  }
2349
2399
  function P(e, t) {
2350
2400
  try {
2351
- const s = t.filter(gt);
2401
+ const s = t.filter(mt);
2352
2402
  if (s.length === 0) {
2353
- window.localStorage.removeItem(`${rt}${e}`);
2403
+ window.localStorage.removeItem(`${it}${e}`);
2354
2404
  return;
2355
2405
  }
2356
2406
  window.localStorage.setItem(
2357
- `${rt}${e}`,
2407
+ `${it}${e}`,
2358
2408
  JSON.stringify(s.slice(-25))
2359
2409
  );
2360
2410
  } catch {
2361
2411
  return;
2362
2412
  }
2363
2413
  }
2364
- function $t(e, t) {
2414
+ function Xt(e, t) {
2365
2415
  try {
2366
- const s = `${j}${e}`, n = location.href, r = location.origin, i = Array.from(t, (o) => ({
2416
+ const s = `${z}${e}`, n = location.href, r = location.origin, i = Array.from(t, (o) => ({
2367
2417
  ...o,
2368
2418
  storedAt: Date.now(),
2369
2419
  unloadUrl: n,
@@ -2377,28 +2427,28 @@ function $t(e, t) {
2377
2427
  } catch {
2378
2428
  }
2379
2429
  }
2380
- function Js(e, t) {
2430
+ function Zs(e, t) {
2381
2431
  try {
2382
- if (window.sessionStorage.getItem(`${j}${e}`) === null)
2432
+ if (window.sessionStorage.getItem(`${z}${e}`) === null)
2383
2433
  return;
2384
2434
  } catch {
2385
2435
  return;
2386
2436
  }
2387
- $t(e, t);
2437
+ Xt(e, t);
2388
2438
  }
2389
- function Vs(e) {
2439
+ function Qs(e) {
2390
2440
  try {
2391
- const t = `${j}${e}`, s = window.sessionStorage.getItem(t);
2441
+ const t = `${z}${e}`, s = window.sessionStorage.getItem(t);
2392
2442
  if (window.sessionStorage.removeItem(t), !s)
2393
2443
  return [];
2394
2444
  const n = JSON.parse(s);
2395
- return Array.isArray(n) ? n.flatMap((r) => Zs(r) ? [{
2445
+ return Array.isArray(n) ? n.flatMap((r) => en(r) ? [{
2396
2446
  ...r.event,
2397
- page: A(),
2447
+ page: S(),
2398
2448
  rawOutput: {
2399
2449
  pageContextRestarted: !0,
2400
2450
  outcome: "unknown",
2401
- message: Ys(location.href),
2451
+ message: tn(location.href),
2402
2452
  currentUrl: location.href,
2403
2453
  console: [],
2404
2454
  metadata: {
@@ -2415,17 +2465,17 @@ function Vs(e) {
2415
2465
  return [];
2416
2466
  }
2417
2467
  }
2418
- function Ys(e) {
2468
+ function tn(e) {
2419
2469
  return `The page context restarted. This is expected when the action included page navigation. Otherwise, it's unknown whether the action completed.
2420
2470
  Current URL: ${e}`;
2421
2471
  }
2422
- function Zs(e) {
2472
+ function en(e) {
2423
2473
  if (!e || typeof e != "object")
2424
2474
  return !1;
2425
2475
  const t = e, s = t.event;
2426
- return typeof t.startedAtMs == "number" && typeof t.startedAtUrl == "string" && t.startedAtOrigin === location.origin && t.unloadOrigin === location.origin && typeof t.unloadUrl == "string" && gt(s) && s.type === "tool.result";
2476
+ return typeof t.startedAtMs == "number" && typeof t.startedAtUrl == "string" && t.startedAtOrigin === location.origin && t.unloadOrigin === location.origin && typeof t.unloadUrl == "string" && mt(s) && s.type === "tool.result";
2427
2477
  }
2428
- function Qs(e, t) {
2478
+ function sn(e, t) {
2429
2479
  const s = new Set(
2430
2480
  e.flatMap((n) => n.type === "tool.result" ? [n.callId] : [])
2431
2481
  );
@@ -2434,26 +2484,26 @@ function Qs(e, t) {
2434
2484
  ...t.filter((n) => !s.has(n.callId))
2435
2485
  ];
2436
2486
  }
2437
- function tn(e) {
2487
+ function nn(e) {
2438
2488
  try {
2439
- window.sessionStorage.removeItem(`${j}${e}`);
2489
+ window.sessionStorage.removeItem(`${z}${e}`);
2440
2490
  } catch {
2441
2491
  return;
2442
2492
  }
2443
2493
  }
2444
- function gt(e) {
2494
+ function mt(e) {
2445
2495
  if (!e || typeof e != "object")
2446
2496
  return !1;
2447
2497
  const t = e;
2448
- return t.type === "chat.user_message" ? typeof t.content == "string" && _t(t.page) : t.type === "page.upsert" || t.type === "session.reset" || t.type === "network.batch" ? _t(t.page) : t.type === "tool.result" ? typeof t.sessionId == "string" && typeof t.callId == "string" && t.toolName === "execute_code" : t.type === "chat.retry_last_user_message" ? typeof t.sessionId == "string" && typeof t.clientMessageId == "string" : t.type === "run.stop" ? typeof t.sessionId == "string" && (t.reason === "user_requested" || t.reason === "new_chat" || t.reason === "session_switch") : !1;
2498
+ return t.type === "chat.user_message" ? typeof t.content == "string" && Pt(t.page) : t.type === "page.upsert" || t.type === "session.reset" || t.type === "network.batch" ? Pt(t.page) : t.type === "tool.result" ? typeof t.sessionId == "string" && typeof t.callId == "string" && t.toolName === "execute_code" : t.type === "chat.retry_last_user_message" ? typeof t.sessionId == "string" && typeof t.clientMessageId == "string" : t.type === "run.stop" ? typeof t.sessionId == "string" && (t.reason === "user_requested" || t.reason === "new_chat" || t.reason === "session_switch") : !1;
2449
2499
  }
2450
- function _t(e) {
2500
+ function Pt(e) {
2451
2501
  if (!e || typeof e != "object")
2452
2502
  return !1;
2453
2503
  const t = e;
2454
2504
  return typeof t.url == "string" && typeof t.title == "string" && typeof t.origin == "string";
2455
2505
  }
2456
- function zt(e, t) {
2506
+ function Kt(e, t) {
2457
2507
  if (!Array.isArray(e))
2458
2508
  return;
2459
2509
  const s = e.filter((r) => {
@@ -2461,24 +2511,24 @@ function zt(e, t) {
2461
2511
  return !1;
2462
2512
  const i = r;
2463
2513
  return typeof i.name == "string" && typeof i.mimeType == "string" && typeof i.sizeBytes == "number";
2464
- }), n = t ? s.map((r) => Gt(r, t)) : s;
2514
+ }), n = t ? s.map((r) => Jt(r, t)) : s;
2465
2515
  return n.length > 0 ? n : void 0;
2466
2516
  }
2467
- function Gt(e, t) {
2517
+ function Jt(e, t) {
2468
2518
  return e.fileUrl?.startsWith("/") ? {
2469
2519
  ...e,
2470
2520
  fileUrl: new URL(e.fileUrl, t).toString()
2471
2521
  } : e;
2472
2522
  }
2473
- function en(e) {
2474
- if (sn(e))
2523
+ function rn(e) {
2524
+ if (on(e))
2475
2525
  return {
2476
2526
  headers: {
2477
2527
  "ngrok-skip-browser-warning": "true"
2478
2528
  }
2479
2529
  };
2480
2530
  }
2481
- function sn(e) {
2531
+ function on(e) {
2482
2532
  try {
2483
2533
  const t = new URL(e).hostname;
2484
2534
  return t.endsWith(".ngrok-free.dev") || t.endsWith(".ngrok-free.app") || t.endsWith(".ngrok.app") || t.endsWith(".ngrok.io");
@@ -2486,14 +2536,14 @@ function sn(e) {
2486
2536
  return !1;
2487
2537
  }
2488
2538
  }
2489
- function bt(e) {
2490
- return e.type || nn(e.name) || "application/octet-stream";
2539
+ function Ut(e) {
2540
+ return e.type || an(e.name) || "application/octet-stream";
2491
2541
  }
2492
- function nn(e) {
2542
+ function an(e) {
2493
2543
  const t = e.toLowerCase();
2494
2544
  return t.endsWith(".png") ? "image/png" : t.endsWith(".jpg") || t.endsWith(".jpeg") ? "image/jpeg" : t.endsWith(".webp") ? "image/webp" : t.endsWith(".gif") ? "image/gif" : t.endsWith(".pdf") ? "application/pdf" : null;
2495
2545
  }
2496
- function rn(e) {
2546
+ function cn(e) {
2497
2547
  if (!e || typeof e != "object")
2498
2548
  return null;
2499
2549
  const t = e;
@@ -2505,17 +2555,17 @@ function rn(e) {
2505
2555
  respondsToUserMessageId: typeof t.respondsToUserMessageId == "string" ? t.respondsToUserMessageId : void 0,
2506
2556
  ...typeof t.runId == "string" ? { runId: t.runId } : {},
2507
2557
  dataType: typeof t.dataType == "string" ? t.dataType : void 0,
2508
- attachments: zt(t.attachments)?.map(mt),
2558
+ attachments: Kt(t.attachments)?.map(yt),
2509
2559
  loading: typeof t.loading == "boolean" ? t.loading : void 0
2510
2560
  };
2511
2561
  }
2512
- function on(e) {
2562
+ function ln(e) {
2513
2563
  return e.attachments?.length ? {
2514
2564
  ...e,
2515
- attachments: e.attachments.map(mt)
2565
+ attachments: e.attachments.map(yt)
2516
2566
  } : e;
2517
2567
  }
2518
- function mt(e) {
2568
+ function yt(e) {
2519
2569
  const {
2520
2570
  dataUrl: t,
2521
2571
  objectUrl: s,
@@ -2524,7 +2574,7 @@ function mt(e) {
2524
2574
  } = e;
2525
2575
  return r;
2526
2576
  }
2527
- function Z(e) {
2577
+ function D(e) {
2528
2578
  const t = e.respondsToUserMessageId;
2529
2579
  return typeof t == "string" && t ? t : null;
2530
2580
  }
@@ -2532,39 +2582,39 @@ function _(e) {
2532
2582
  const t = e.runId;
2533
2583
  return typeof t == "string" && t ? t : null;
2534
2584
  }
2535
- function an(e) {
2585
+ function un(e) {
2536
2586
  const t = e?.timeoutMs;
2537
- return !!e && typeof e == "object" && typeof e.summary == "string" && typeof e.javascript == "string" && (t === void 0 || typeof t == "number" && Number.isInteger(t) && t > 0 && t <= Ke);
2587
+ return !!e && typeof e == "object" && typeof e.summary == "string" && typeof e.javascript == "string" && (t === void 0 || typeof t == "number" && Number.isInteger(t) && t > 0 && t <= Ye);
2538
2588
  }
2539
- function Xt(e) {
2589
+ function Vt(e) {
2540
2590
  const t = {};
2541
2591
  try {
2542
2592
  new Headers(e).forEach((s, n) => {
2543
- Object.keys(t).length < ht && (t[n] = yt(n, s));
2593
+ Object.keys(t).length < pt && (t[n] = Tt(n, s));
2544
2594
  });
2545
2595
  } catch {
2546
2596
  return {};
2547
2597
  }
2548
2598
  return t;
2549
2599
  }
2550
- function yt(e, t) {
2551
- return Qt(e) ? z : E(F(t), Be);
2600
+ function Tt(e, t) {
2601
+ return se(e) ? X : E(j(t), Fe);
2552
2602
  }
2553
- function cn(e, t) {
2603
+ function dn(e, t) {
2554
2604
  return typeof e == "string" ? e : e instanceof URL ? e.toString() : t?.url ?? "";
2555
2605
  }
2556
- async function ln(e, t, s, n) {
2557
- const r = Xt(e.headers);
2606
+ async function hn(e, t, s, n) {
2607
+ const r = Vt(e.headers);
2558
2608
  n({
2559
2609
  ...t,
2560
2610
  responseStatus: e.status,
2561
2611
  responseHeaders: r,
2562
- responseBody: await un(e),
2612
+ responseBody: await pn(e),
2563
2613
  durationMs: Date.now() - s
2564
2614
  });
2565
2615
  }
2566
- async function un(e) {
2567
- if (!Kt(e.headers))
2616
+ async function pn(e) {
2617
+ if (!Yt(e.headers))
2568
2618
  return;
2569
2619
  let t = null, s = null;
2570
2620
  try {
@@ -2573,7 +2623,7 @@ async function un(e) {
2573
2623
  const n = new Promise((a) => {
2574
2624
  s = window.setTimeout(() => {
2575
2625
  t?.cancel(), a("timeout");
2576
- }, qe);
2626
+ }, He);
2577
2627
  }), r = new TextDecoder();
2578
2628
  let i = "", o = 0;
2579
2629
  for (; ; ) {
@@ -2583,7 +2633,7 @@ async function un(e) {
2583
2633
  const { done: u, value: l } = a;
2584
2634
  if (u)
2585
2635
  return E(i + r.decode());
2586
- const c = dt - o;
2636
+ const c = ht - o;
2587
2637
  if (l.byteLength > c)
2588
2638
  return i += r.decode(l.subarray(0, Math.max(c, 0)), { stream: !0 }), t.cancel(), `${E(i)}... [truncated]`;
2589
2639
  o += l.byteLength, i += r.decode(l, { stream: !0 });
@@ -2595,45 +2645,45 @@ async function un(e) {
2595
2645
  s !== null && window.clearTimeout(s);
2596
2646
  }
2597
2647
  }
2598
- function dn(e, t) {
2599
- if (Kt(new Headers(t)))
2648
+ function gn(e, t) {
2649
+ if (Yt(new Headers(t)))
2600
2650
  try {
2601
2651
  return e.responseType === "" || e.responseType === "text" ? E(e.responseText ?? "") : void 0;
2602
2652
  } catch {
2603
2653
  return;
2604
2654
  }
2605
2655
  }
2606
- function Mt(e) {
2656
+ function Dt(e) {
2607
2657
  if (typeof e == "string")
2608
2658
  return E(e);
2609
2659
  }
2610
- function hn(e) {
2611
- return S({
2660
+ function fn(e) {
2661
+ return k({
2612
2662
  ...e,
2613
- requestBody: Pt(e.requestBody),
2614
- responseBody: Pt(e.responseBody)
2663
+ requestBody: vt(e.requestBody),
2664
+ responseBody: vt(e.responseBody)
2615
2665
  });
2616
2666
  }
2617
- function Pt(e) {
2667
+ function vt(e) {
2618
2668
  if (typeof e != "string")
2619
2669
  return e;
2620
2670
  const t = e.trim();
2621
2671
  if (!t.startsWith("{") && !t.startsWith("["))
2622
- return F(e);
2672
+ return j(e);
2623
2673
  try {
2624
- return JSON.stringify(S(JSON.parse(e)));
2674
+ return JSON.stringify(k(JSON.parse(e)));
2625
2675
  } catch {
2626
- return F(e);
2676
+ return j(e);
2627
2677
  }
2628
2678
  }
2629
- function Kt(e) {
2679
+ function Yt(e) {
2630
2680
  if (!e)
2631
2681
  return !1;
2632
2682
  const t = e.get("content-type")?.toLowerCase() ?? "", s = e.get("content-length"), n = Number(s);
2633
- return s !== null && Number.isInteger(n) && n >= 0 && n <= dt && (t.startsWith("text/") || t.includes("json") || t.includes("javascript"));
2683
+ return s !== null && Number.isInteger(n) && n >= 0 && n <= ht && (t.startsWith("text/") || t.includes("json") || t.includes("javascript"));
2634
2684
  }
2635
2685
  function b(e, t = {}, s) {
2636
- if (fn(s))
2686
+ if (yn(s))
2637
2687
  return !0;
2638
2688
  const n = Object.entries(t).find(([r]) => r.toLowerCase() === "content-type")?.[1]?.toLowerCase();
2639
2689
  if (n?.includes("multipart/form-data") || n?.includes("application/octet-stream"))
@@ -2648,7 +2698,7 @@ function b(e, t = {}, s) {
2648
2698
  return !0;
2649
2699
  }
2650
2700
  }
2651
- function pn(e, t) {
2701
+ function mn(e, t) {
2652
2702
  if (b(e))
2653
2703
  return !0;
2654
2704
  try {
@@ -2658,115 +2708,115 @@ function pn(e, t) {
2658
2708
  return !0;
2659
2709
  }
2660
2710
  }
2661
- function fn(e) {
2711
+ function yn(e) {
2662
2712
  return e instanceof FormData || e instanceof Blob || e instanceof ArrayBuffer || ArrayBuffer.isView(e) || typeof ReadableStream < "u" && e instanceof ReadableStream;
2663
2713
  }
2664
- function gn(e) {
2714
+ function Tn(e) {
2665
2715
  const t = {};
2666
2716
  for (const s of e.trim().split(/[\r\n]+/)) {
2667
2717
  const n = s.indexOf(":");
2668
2718
  if (n <= 0)
2669
2719
  continue;
2670
- if (Object.keys(t).length >= ht)
2720
+ if (Object.keys(t).length >= pt)
2671
2721
  break;
2672
2722
  const r = s.slice(0, n).trim();
2673
- t[r] = yt(r, s.slice(n + 1).trim());
2723
+ t[r] = Tt(r, s.slice(n + 1).trim());
2674
2724
  }
2675
2725
  return t;
2676
2726
  }
2677
- function E(e, t = dt) {
2727
+ function E(e, t = ht) {
2678
2728
  return e.length <= t ? e : `${e.slice(0, t)}... [truncated ${e.length - t} chars]`;
2679
2729
  }
2680
- function Q(e) {
2730
+ function tt(e) {
2681
2731
  return `${e}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
2682
2732
  }
2683
- class q extends Error {
2733
+ class F extends Error {
2684
2734
  constructor(t, s) {
2685
2735
  super(`${t} (${s})`), this.status = s, this.name = "AttachmentUploadHttpError";
2686
2736
  }
2687
2737
  status;
2688
2738
  }
2689
- async function tt(e, t) {
2739
+ async function et(e, t) {
2690
2740
  let s = null;
2691
- for (let n = 0; n < St; n += 1)
2741
+ for (let n = 0; n < kt; n += 1)
2692
2742
  try {
2693
2743
  return await e();
2694
2744
  } catch (r) {
2695
- if (s = r, n >= St - 1 || !yn(r))
2745
+ if (s = r, n >= kt - 1 || !In(r))
2696
2746
  throw r;
2697
- await mn(n);
2747
+ await wn(n);
2698
2748
  }
2699
2749
  throw s instanceof Error ? s : new Error(t);
2700
2750
  }
2701
- function mn(e) {
2751
+ function wn(e) {
2702
2752
  return new Promise((t) => {
2703
- window.setTimeout(t, Le[e] ?? 0);
2753
+ window.setTimeout(t, xe[e] ?? 0);
2704
2754
  });
2705
2755
  }
2706
- function yn(e) {
2707
- return e instanceof q ? Tn(e.status) : e instanceof TypeError;
2756
+ function In(e) {
2757
+ return e instanceof F ? An(e.status) : e instanceof TypeError;
2708
2758
  }
2709
- function Tn(e) {
2759
+ function An(e) {
2710
2760
  return e === 408 || e === 409 || e === 429 || e >= 500;
2711
2761
  }
2712
- function wn(e) {
2762
+ function Sn(e) {
2713
2763
  return e === 401 || e === 403;
2714
2764
  }
2715
- const z = "[REDACTED_SECRET]", R = "[REDACTED_TOKEN]", In = "[REDACTED_SIGNED_URL]", An = 20, Sn = /^(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, Jt = /\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi, Vt = /\bBasic\s+[A-Za-z0-9+/=-]{12,}/gi, Yt = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g, Zt = /\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, kn = /\bhttps?:\/\/[^\s"'<>]+(?:X-Amz-Signature|X-Goog-Signature|Signature|sig=)[^\s"'<>]*/gi, En = /\bhttps?:\/\/[^\s"'<>]+/gi, Rn = /[),.;\]]+$/;
2716
- function S(e) {
2717
- return H(e, 0, /* @__PURE__ */ new WeakSet());
2765
+ const X = "[REDACTED_SECRET]", R = "[REDACTED_TOKEN]", kn = "[REDACTED_SIGNED_URL]", En = 20, Rn = /^(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, Qt = /\bBasic\s+[A-Za-z0-9+/=-]{12,}/gi, te = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g, ee = /\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, Cn = /\bhttps?:\/\/[^\s"'<>]+(?:X-Amz-Signature|X-Goog-Signature|Signature|sig=)[^\s"'<>]*/gi, _n = /\bhttps?:\/\/[^\s"'<>]+/gi, bn = /[),.;\]]+$/;
2766
+ function k(e) {
2767
+ return W(e, 0, /* @__PURE__ */ new WeakSet());
2718
2768
  }
2719
- function H(e, t, s) {
2769
+ function W(e, t, s) {
2720
2770
  if (typeof e == "string")
2721
- return e.startsWith("data:image/") || e.startsWith("data:application/pdf;") ? e : F(e);
2771
+ return e.startsWith("data:image/") || e.startsWith("data:application/pdf;") ? e : j(e);
2722
2772
  if (e === null || typeof e != "object")
2723
2773
  return e;
2724
- if (t >= An)
2774
+ if (t >= En)
2725
2775
  return "[REDACTED_MAX_DEPTH]";
2726
2776
  if (s.has(e))
2727
2777
  return "[REDACTED_CIRCULAR]";
2728
2778
  if (s.add(e), Array.isArray(e))
2729
- return e.map((r) => H(r, t + 1, s));
2779
+ return e.map((r) => W(r, t + 1, s));
2730
2780
  const n = {};
2731
2781
  for (const [r, i] of Object.entries(e))
2732
- Qt(r) ? n[r] = z : n[r] = r.toLowerCase() === "url" ? Cn(i) : H(i, t + 1, s);
2782
+ se(r) ? n[r] = X : n[r] = r.toLowerCase() === "url" ? Mn(i) : W(i, t + 1, s);
2733
2783
  return n;
2734
2784
  }
2735
- function Qt(e) {
2785
+ function se(e) {
2736
2786
  const t = e.replace(/[^a-z0-9]/gi, "").toLowerCase();
2737
2787
  return t.includes("authorization") || t.includes("cookie") || t.includes("password") || t.includes("passwd") || t === "pwd" || t.includes("secret") || t === "token" || t.endsWith("token") || t.includes("apikey") || t.includes("csrf") || t.includes("xsrf") || t === "jwt" || t === "session" || t === "signature" || t.includes("privatekey");
2738
2788
  }
2739
- function Cn(e) {
2740
- return typeof e == "string" ? te(e) : H(e, 0, /* @__PURE__ */ new WeakSet());
2789
+ function Mn(e) {
2790
+ return typeof e == "string" ? ne(e) : W(e, 0, /* @__PURE__ */ new WeakSet());
2741
2791
  }
2742
- function te(e) {
2792
+ function ne(e) {
2743
2793
  try {
2744
2794
  const t = new URL(e, location.href);
2745
2795
  for (const s of Array.from(t.searchParams.keys()))
2746
- Sn.test(s) && t.searchParams.set(s, R);
2796
+ Rn.test(s) && t.searchParams.set(s, R);
2747
2797
  return t.username && (t.username = R), t.password && (t.password = R), t.toString();
2748
2798
  } catch {
2749
- return _n(e);
2799
+ return Pn(e);
2750
2800
  }
2751
2801
  }
2752
- function F(e) {
2753
- return e.replace(kn, In).replace(En, bn).replace(Jt, `Bearer ${R}`).replace(Vt, `Basic ${R}`).replace(Yt, R).replace(Zt, (t, s) => `${s}: ${z}`);
2802
+ function j(e) {
2803
+ return e.replace(Cn, kn).replace(_n, Un).replace(Zt, `Bearer ${R}`).replace(Qt, `Basic ${R}`).replace(te, R).replace(ee, (t, s) => `${s}: ${X}`);
2754
2804
  }
2755
- function _n(e) {
2756
- return e.replace(Jt, `Bearer ${R}`).replace(Vt, `Basic ${R}`).replace(Yt, R).replace(Zt, (t, s) => `${s}: ${z}`);
2805
+ function Pn(e) {
2806
+ return e.replace(Zt, `Bearer ${R}`).replace(Qt, `Basic ${R}`).replace(te, R).replace(ee, (t, s) => `${s}: ${X}`);
2757
2807
  }
2758
- function bn(e) {
2759
- const t = e.match(Rn)?.[0] ?? "", s = t ? e.slice(0, -t.length) : e;
2760
- return `${te(s)}${t}`;
2808
+ function Un(e) {
2809
+ const t = e.match(bn)?.[0] ?? "", s = t ? e.slice(0, -t.length) : e;
2810
+ return `${ne(s)}${t}`;
2761
2811
  }
2762
2812
  export {
2763
- Tt as PLUNO_PRODUCT_AGENT_SDK_PREVIEW_HOST_SELECTOR,
2764
- nt as PLUNO_PRODUCT_AGENT_WIDGET_HOST_SELECTOR,
2765
- we as PLUNO_PRODUCT_AGENT_WIDGET_PANEL_SELECTOR,
2766
- Te as PLUNO_PRODUCT_AGENT_WIDGET_ROOT_SELECTOR,
2767
- Ie as PLUNO_PRODUCT_AGENT_WIDGET_TIMELINE_SELECTOR,
2768
- qt as PlunoProductAgent,
2769
- We as calculateReconnectDelay,
2770
- qt as default,
2771
- cs as getProductAgentOriginAccessErrorMessage
2813
+ wt as PLUNO_PRODUCT_AGENT_SDK_PREVIEW_HOST_SELECTOR,
2814
+ rt as PLUNO_PRODUCT_AGENT_WIDGET_HOST_SELECTOR,
2815
+ Se as PLUNO_PRODUCT_AGENT_WIDGET_PANEL_SELECTOR,
2816
+ Ae as PLUNO_PRODUCT_AGENT_WIDGET_ROOT_SELECTOR,
2817
+ ke as PLUNO_PRODUCT_AGENT_WIDGET_TIMELINE_SELECTOR,
2818
+ Ht as PlunoProductAgent,
2819
+ ze as calculateReconnectDelay,
2820
+ Ht as default,
2821
+ ds as getProductAgentOriginAccessErrorMessage
2772
2822
  };