@pluno/product-agent-web 0.1.125 → 0.1.131

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,24 +1,13 @@
1
- const Ve = "pluno-product-agent-attachments";
2
- const Mt = "files";
3
- async function Se(e) {
4
- const t = await it();
5
- await ke(t, "readwrite", (s) => s.put(e));
6
- }
7
- async function Ye(e) {
8
- const t = await it(), s = await ke(
9
- t,
10
- "readonly",
11
- (r) => r.get(e)
12
- );
13
- if (!s)
14
- return null;
15
- const n = Date.now();
16
- return await Ee(e, { lastUsedAt: n }), { ...s, lastUsedAt: n };
17
- }
18
- async function Ee(e, t) {
19
- const s = await it();
20
- await Lt(s, "readwrite", async (n) => {
21
- const r = await xt(
1
+ const Ge = "pluno-product-agent-attachments";
2
+ const _t = "files";
3
+ async function Xe(e) {
4
+ const t = await vt();
5
+ await Ve(t, "readwrite", (s) => s.put(e));
6
+ }
7
+ async function Je(e, t) {
8
+ const s = await vt();
9
+ await Ot(s, "readwrite", async (n) => {
10
+ const r = await Nt(
22
11
  n.get(e)
23
12
  );
24
13
  r && n.put({
@@ -27,57 +16,57 @@ async function Ee(e, t) {
27
16
  });
28
17
  });
29
18
  }
30
- async function Ze(e = 864e5) {
31
- const t = await it(), s = Date.now() - e;
32
- await Lt(t, "readwrite", async (n) => {
19
+ async function Ke(e = 864e5) {
20
+ const t = await vt(), s = Date.now() - e;
21
+ await Ot(t, "readwrite", async (n) => {
33
22
  const r = n.index("lastUsedAt");
34
- (await xt(r.getAllKeys(IDBKeyRange.upperBound(s)))).forEach((o) => n.delete(o));
23
+ (await Nt(r.getAllKeys(IDBKeyRange.upperBound(s)))).forEach((o) => n.delete(o));
35
24
  });
36
25
  }
37
- function it() {
26
+ function vt() {
38
27
  return typeof indexedDB > "u" ? Promise.reject(new Error("Product Agent attachment storage is unavailable")) : new Promise((e, t) => {
39
- const s = indexedDB.open(Ve, 1);
28
+ const s = indexedDB.open(Ge, 1);
40
29
  s.onupgradeneeded = () => {
41
- const r = s.result.createObjectStore(Mt, { keyPath: "attachmentId" });
30
+ const r = s.result.createObjectStore(_t, { keyPath: "attachmentId" });
42
31
  r.createIndex("lastUsedAt", "lastUsedAt", { unique: !1 }), r.createIndex("sessionId", "sessionId", { unique: !1 }), r.createIndex("origin", "origin", { unique: !1 });
43
32
  }, s.onsuccess = () => e(s.result), s.onerror = () => t(s.error ?? new Error("Failed to open Product Agent attachment storage"));
44
33
  });
45
34
  }
46
- async function ke(e, t, s) {
47
- return await Lt(e, t, async (n) => await xt(s(n)));
35
+ async function Ve(e, t, s) {
36
+ return await Ot(e, t, async (n) => await Nt(s(n)));
48
37
  }
49
- function Lt(e, t, s) {
38
+ function Ot(e, t, s) {
50
39
  return new Promise((n, r) => {
51
- const i = e.transaction(Mt, t), o = i.objectStore(Mt);
52
- let a, u = !1;
53
- s(o).then((c) => {
54
- a = c;
55
- }).catch((c) => {
56
- u = !0;
40
+ const i = e.transaction(_t, t), o = i.objectStore(_t);
41
+ let a, c = !1;
42
+ s(o).then((l) => {
43
+ a = l;
44
+ }).catch((l) => {
45
+ c = !0;
57
46
  try {
58
47
  i.abort();
59
48
  } catch {
60
49
  }
61
- r(c);
50
+ r(l);
62
51
  }), i.oncomplete = () => {
63
- u || n(a);
52
+ c || n(a);
64
53
  }, i.onerror = () => {
65
- u || (u = !0, r(i.error ?? new Error("Product Agent attachment storage transaction failed")));
54
+ c || (c = !0, r(i.error ?? new Error("Product Agent attachment storage transaction failed")));
66
55
  }, i.onabort = () => {
67
- u || (u = !0, r(i.error ?? new Error("Product Agent attachment storage transaction aborted")));
56
+ c || (c = !0, r(i.error ?? new Error("Product Agent attachment storage transaction aborted")));
68
57
  };
69
58
  });
70
59
  }
71
- function xt(e) {
60
+ function Nt(e) {
72
61
  return new Promise((t, s) => {
73
62
  e.onsuccess = () => t(e.result), e.onerror = () => s(e.error ?? new Error("Product Agent attachment storage request failed"));
74
63
  });
75
64
  }
76
- function Qe(e) {
65
+ function Ye(e) {
77
66
  return e !== null && (typeof e == "object" || typeof e == "function");
78
67
  }
79
- function Bt(e, t, s) {
80
- const n = Reflect.get(e, "pluno"), r = Qe(n) ? n : {};
68
+ function Te(e, t, s) {
69
+ const n = Reflect.get(e, "pluno"), r = Ye(n) ? n : {};
81
70
  if (r !== n && !Reflect.set(e, "pluno", r))
82
71
  return null;
83
72
  const i = Object.getOwnPropertyDescriptor(r, t);
@@ -91,36 +80,36 @@ function Bt(e, t, s) {
91
80
  }
92
81
  };
93
82
  }
94
- const wt = "pluno.productAgent.transportId", ts = "pluno.productAgent.transportIdentity", At = "pluno.productAgent.transportIdentity.event", es = 50, ss = globalThis.setTimeout.bind(globalThis);
83
+ const It = "pluno.productAgent.transportId", Ze = "pluno.productAgent.transportIdentity", Tt = "pluno.productAgent.transportIdentity.event", Qe = 50, ts = globalThis.setTimeout.bind(globalThis);
95
84
  let F = null;
96
- const tt = /* @__PURE__ */ new Set(), St = /* @__PURE__ */ new Map();
97
- async function ns(e = be()) {
98
- const t = e.randomUUID(), s = e.storage.getItem(wt);
85
+ const Q = /* @__PURE__ */ new Set(), wt = /* @__PURE__ */ new Map();
86
+ async function es(e = we()) {
87
+ const t = e.randomUUID(), s = e.storage.getItem(It);
99
88
  let n = s ?? e.randomUUID(), r = !1, i = !1;
100
- const o = e.channel.subscribe((u) => {
101
- if (!(u.senderId === t || u.transportId !== n)) {
102
- if (u.type === "probe") {
89
+ const o = e.channel.subscribe((c) => {
90
+ if (!(c.senderId === t || c.transportId !== n)) {
91
+ if (c.type === "probe") {
103
92
  e.channel.postMessage({
104
93
  type: "contender",
105
94
  transportId: n,
106
95
  senderId: t,
107
- targetId: u.senderId,
96
+ targetId: c.senderId,
108
97
  established: r
109
- }), !r && t > u.senderId && (i = !0);
98
+ }), !r && t > c.senderId && (i = !0);
110
99
  return;
111
100
  }
112
- u.targetId === t && (u.established || t > u.senderId) && (i = !0);
101
+ c.targetId === t && (c.established || t > c.senderId) && (i = !0);
113
102
  }
114
103
  });
115
104
  if (!s)
116
- e.storage.setItem(wt, n), r = !0;
105
+ e.storage.setItem(It, n), r = !0;
117
106
  else
118
107
  for (; ; ) {
119
108
  if (i = !1, e.channel.postMessage({ type: "probe", transportId: n, senderId: t }), await e.settle(), !i) {
120
109
  r = !0;
121
110
  break;
122
111
  }
123
- n = e.randomUUID(), e.storage.setItem(wt, n);
112
+ n = e.randomUUID(), e.storage.setItem(It, n);
124
113
  }
125
114
  let a = !1;
126
115
  return {
@@ -130,49 +119,49 @@ async function ns(e = be()) {
130
119
  }
131
120
  };
132
121
  }
133
- async function rs() {
134
- F || (F = ns(be()), F.then((n) => {
122
+ async function ss() {
123
+ F || (F = es(we()), F.then((n) => {
135
124
  const r = (i) => {
136
- i.persisted || (n.release(), F = null, tt.clear(), window.removeEventListener("pagehide", r));
125
+ i.persisted || (n.release(), F = null, Q.clear(), window.removeEventListener("pagehide", r));
137
126
  };
138
127
  window.addEventListener("pagehide", r);
139
128
  }));
140
- const e = await F, t = is();
141
- tt.add(t);
129
+ const e = await F, t = ns();
130
+ Q.add(t);
142
131
  let s = !1;
143
132
  return {
144
133
  // A stable per-tab base keeps reload routing intact, while slots isolate multiple live SDK instances in one tab.
145
134
  transportId: t === 0 ? e.transportId : `${e.transportId}.${t}`,
146
135
  release: () => {
147
- s || (s = !0, tt.delete(t));
136
+ s || (s = !0, Q.delete(t));
148
137
  }
149
138
  };
150
139
  }
151
- function is() {
140
+ function ns() {
152
141
  let e = 0;
153
- for (; tt.has(e); )
142
+ for (; Q.has(e); )
154
143
  e += 1;
155
144
  return e;
156
145
  }
157
- function be() {
146
+ function we() {
158
147
  return {
159
- storage: os(),
160
- channel: as(),
148
+ storage: rs(),
149
+ channel: is(),
161
150
  randomUUID: () => crypto.randomUUID(),
162
- settle: () => new Promise((e) => ss(e, es))
151
+ settle: () => new Promise((e) => ts(e, Qe))
163
152
  };
164
153
  }
165
- function os() {
154
+ function rs() {
166
155
  return {
167
156
  getItem: (e) => {
168
157
  try {
169
- return window.sessionStorage?.getItem(e) ?? St.get(e) ?? null;
158
+ return window.sessionStorage?.getItem(e) ?? wt.get(e) ?? null;
170
159
  } catch {
171
- return St.get(e) ?? null;
160
+ return wt.get(e) ?? null;
172
161
  }
173
162
  },
174
163
  setItem: (e, t) => {
175
- St.set(e, t);
164
+ wt.set(e, t);
176
165
  try {
177
166
  window.sessionStorage?.setItem(e, t);
178
167
  } catch {
@@ -180,9 +169,9 @@ function os() {
180
169
  }
181
170
  };
182
171
  }
183
- function as() {
172
+ function is() {
184
173
  if (typeof BroadcastChannel < "u") {
185
- const e = new BroadcastChannel(ts);
174
+ const e = new BroadcastChannel(Ze);
186
175
  return {
187
176
  postMessage: (t) => e.postMessage(t),
188
177
  subscribe: (t) => {
@@ -192,11 +181,11 @@ function as() {
192
181
  close: () => e.close()
193
182
  };
194
183
  }
195
- return cs();
184
+ return os();
196
185
  }
197
- function cs() {
186
+ function os() {
198
187
  const e = /* @__PURE__ */ new Set(), t = (s) => {
199
- if (s.key !== At || !s.newValue)
188
+ if (s.key !== Tt || !s.newValue)
200
189
  return;
201
190
  const n = JSON.parse(s.newValue);
202
191
  for (const r of e)
@@ -205,9 +194,9 @@ function cs() {
205
194
  return window.addEventListener("storage", t), {
206
195
  postMessage: (s) => {
207
196
  window.localStorage.setItem(
208
- At,
197
+ Tt,
209
198
  JSON.stringify({ ...s, eventId: crypto.randomUUID() })
210
- ), window.localStorage.removeItem(At);
199
+ ), window.localStorage.removeItem(Tt);
211
200
  },
212
201
  subscribe: (s) => (e.add(s), () => e.delete(s)),
213
202
  close: () => {
@@ -215,18 +204,18 @@ function cs() {
215
204
  }
216
205
  };
217
206
  }
218
- const Ct = '.pluno-pa-widget-host[data-pluno-product-agent-ui="widget"]', ls = '.pluno-pa-widget[data-pluno-product-agent-ui-root="widget"]', us = ".pluno-pa-widget__panel", ds = ".pluno-pa-widget__timeline", ne = `${Ct}[data-pluno-sdk-preview-channel]`, hs = "https://app.pluno.ai", ps = "gpt-5.6-terra", fs = 2e4, gs = 1e4, ms = 1e4, ys = 1e4, Ts = 1e4, Is = 1e3, re = 3e4, ie = 0.2, oe = 6e4, ws = 15e3, K = 8, As = 15e3, Ss = 2e3, Es = 1e3, ks = 100, bs = 8e3, Rs = 15e3, ae = 3, _s = [300, 1e3], qt = 64e3, Et = 4e3, Ht = 30, Ms = 2e3, Cs = 1e3, Ps = 200 * 1024 * 1024, Ft = "Image is too large for model vision input.", Us = 100, Re = "pluno.productAgent.state.", Pt = "pluno.productAgent.pendingEvents.", ot = "pluno.productAgent.activeToolCalls.", Ds = 100;
207
+ const as = globalThis.fetch.bind(globalThis), Mt = '.pluno-pa-widget-host[data-pluno-product-agent-ui="widget"]', cs = '.pluno-pa-widget[data-pluno-product-agent-ui-root="widget"]', ls = ".pluno-pa-widget__panel", us = ".pluno-pa-widget__timeline", te = `${Mt}[data-pluno-sdk-preview-channel]`, ds = "https://app.pluno.ai", hs = "gpt-5.6-terra", ps = 2e4, fs = 1e4, gs = 1e4, ms = 1e4, ys = 1e4, Is = 1e3, ee = 3e4, se = 0.2, ne = 6e4, Ts = 15e3, K = 8, ws = 15e3, As = 2e3, Ss = 1e3, bs = 100, Es = 8e3, re = 3, ks = [300, 1e3], Lt = 64e3, At = 4e3, Bt = 30, Rs = 2e3, _s = 1e3, Ae = "Image is too large for model vision input.", Ms = 100, Se = "pluno.productAgent.state.", Ct = "pluno.productAgent.pendingEvents.", rt = "pluno.productAgent.activeToolCalls.", Cs = 100;
219
208
  function V(e, t = 0) {
220
209
  const s = e === 0 ? 0 : Math.min(3e4, 1e3 * 2 ** (e - 1));
221
210
  return Math.max(t, s);
222
211
  }
223
- const et = /* @__PURE__ */ new Set();
212
+ const tt = /* @__PURE__ */ new Set();
224
213
  let Y = null;
225
- function Ns(e, t = Math.random) {
226
- const s = Math.min(re, Is * 2 ** e), n = 1 - ie + t() * ie * 2;
227
- return Math.min(re, Math.round(s * n));
214
+ function Ps(e, t = Math.random) {
215
+ const s = Math.min(ee, Is * 2 ** e), n = 1 - se + t() * se * 2;
216
+ return Math.min(ee, Math.round(s * n));
228
217
  }
229
- function Os(e, t, s) {
218
+ function Us(e, t, s) {
230
219
  return new Promise((n, r) => {
231
220
  const i = setTimeout(() => r(new Error(s)), t);
232
221
  e.then(
@@ -239,13 +228,13 @@ function Os(e, t, s) {
239
228
  );
240
229
  });
241
230
  }
242
- class _e {
231
+ class be {
243
232
  constructor(t, s) {
244
233
  this.options = t, this.transportIdentity = s, this.state = {
245
234
  ...this.state,
246
- starterPrompts: pn(t.initialStarterPrompts)
235
+ starterPrompts: hn(t.initialStarterPrompts)
247
236
  };
248
- const n = t.restorePersistedState === !1 ? null : Yn(t.clientId, t.expectedPersistedSessionId);
237
+ const n = t.restorePersistedState === !1 ? null : Vn(t.clientId, t.expectedPersistedSessionId);
249
238
  n && (this.state = {
250
239
  ...this.state,
251
240
  ...n,
@@ -258,10 +247,10 @@ class _e {
258
247
  assistantDraftRunId: null,
259
248
  isThinking: !1,
260
249
  lastError: null
261
- }), this.queuedClientEvents = rr(
262
- Qn(t.clientId),
263
- er(t.clientId)
264
- ), W(t.clientId, this.queuedClientEvents);
250
+ }), this.queuedClientEvents = nr(
251
+ Zn(t.clientId),
252
+ tr(t.clientId)
253
+ ), $(t.clientId, this.queuedClientEvents);
265
254
  }
266
255
  options;
267
256
  listeners = {};
@@ -301,6 +290,8 @@ class _e {
301
290
  attachmentBlobCache = /* @__PURE__ */ new Map();
302
291
  sessionUserFilesApiCleanup = null;
303
292
  activeBrowserToolCalls = /* @__PURE__ */ new Map();
293
+ pendingToolLoadingByCallId = /* @__PURE__ */ new Map();
294
+ terminalToolCallIds = /* @__PURE__ */ new Set();
304
295
  pageLifecycleCleanup = null;
305
296
  transientStarterPromptsRequestInFlight = !1;
306
297
  transientStarterPromptsRequestAttempted = !1;
@@ -326,15 +317,16 @@ class _e {
326
317
  lastErrorSecuritySettingsUrl: null
327
318
  };
328
319
  static async init(t) {
329
- const s = await rs(), n = new _e({
320
+ const s = await ss(), n = new be({
330
321
  ...t,
331
- backendUrl: Qs(t.backendUrl ?? hs),
332
- clientId: t.clientId ?? Tn(),
333
- model: t.model ?? ps
322
+ backendUrl: Vs(t.backendUrl ?? ds),
323
+ clientId: t.clientId ?? yn(),
324
+ model: t.model ?? hs,
325
+ entrySurface: Ys(t.entrySurface)
334
326
  }, s);
335
327
  try {
336
- Ze().catch((r) => {
337
- I("web-sdk.attachments", "Failed to delete stale Product Agent attachments", {
328
+ Ke().catch((r) => {
329
+ A("web-sdk.attachments", "Failed to delete stale Product Agent attachments", {
338
330
  message: r instanceof Error ? r.message : String(r)
339
331
  });
340
332
  }), t.disableNetworkCapture || n.enableNetworkCapture(), n.startPageLifecycleRecovery(), n.startStarterPromptUrlWatcher(), t.autoConnect !== !1 && await n.connect();
@@ -365,15 +357,15 @@ class _e {
365
357
  lastError: null
366
358
  });
367
359
  try {
368
- if (this.token = this.options.token ?? (this.options.tokenProvider ? await Os(this.options.tokenProvider(), ms, "Pluno token provider timed out") : null), t !== this.connectionAttemptId || this.state.status === "closed")
360
+ if (this.token = this.options.token ?? (this.options.tokenProvider ? await Us(this.options.tokenProvider(), gs, "Pluno token provider timed out") : null), t !== this.connectionAttemptId || this.state.status === "closed")
369
361
  return;
370
362
  if (!this.token && !this.options.webSocketFactory)
371
363
  throw new Error("Pluno requires a token or tokenProvider");
372
- const s = en(this.options.backendUrl), n = this.options.webSocketFactory?.(s) ?? new WebSocket(s);
364
+ const s = tn(this.options.backendUrl), n = this.options.webSocketFactory?.(s) ?? new WebSocket(s);
373
365
  this.socket = n, this.socketConnectTimer = window.setTimeout(() => {
374
- this.socket === n && n.readyState === WebSocket.CONNECTING && (I("web-sdk.agent", "Pluno socket opening timed out; reconnecting"), this.replaceTimedOutSocket(n));
375
- }, ys), n.addEventListener("open", () => {
376
- this.socket !== n || (this.clearSocketConnectTimer(), I("web-sdk.agent", "Pluno socket opened", {
366
+ this.socket === n && n.readyState === WebSocket.CONNECTING && (A("web-sdk.agent", "Pluno socket opening timed out; reconnecting"), this.replaceTimedOutSocket(n));
367
+ }, ms), n.addEventListener("open", () => {
368
+ this.socket !== n || (this.clearSocketConnectTimer(), A("web-sdk.agent", "Pluno socket opened", {
377
369
  queuedClientEventCount: this.queuedClientEvents.length,
378
370
  isThinking: this.state.isThinking
379
371
  }), !(this.token ? this.sendNow({
@@ -383,12 +375,12 @@ class _e {
383
375
  transportId: this.transportIdentity.transportId,
384
376
  pageUrl: location.href
385
377
  }) : !0)) || (this.socketAuthTimer = window.setTimeout(() => {
386
- this.socket === n && (I("web-sdk.agent", "Pluno socket authentication timed out; reconnecting"), this.replaceTimedOutSocket(n));
387
- }, Ts));
378
+ this.socket === n && (A("web-sdk.agent", "Pluno socket authentication timed out; reconnecting"), this.replaceTimedOutSocket(n));
379
+ }, ys));
388
380
  }), n.addEventListener("message", (r) => {
389
- this.socket === n && this.handleServerEvent(hn(r.data));
381
+ this.socket === n && this.handleServerEvent(dn(r.data));
390
382
  }), n.addEventListener("close", (r) => {
391
- this.socket === n && (this.clearSocketPhaseTimers(), this.stopHeartbeat(), this.socket = null, this.state.status !== "closed" && (I("web-sdk.agent", "Pluno socket closed; scheduling reconnect", {
383
+ this.socket === n && (this.clearSocketPhaseTimers(), this.stopHeartbeat(), this.socket = null, this.state.status !== "closed" && (A("web-sdk.agent", "Pluno socket closed; scheduling reconnect", {
392
384
  code: typeof r?.code == "number" ? r.code : null,
393
385
  reason: typeof r?.reason == "string" ? r.reason : "",
394
386
  wasClean: typeof r?.wasClean == "boolean" ? r.wasClean : null,
@@ -396,7 +388,7 @@ class _e {
396
388
  isThinking: this.state.isThinking
397
389
  }), this.setState({ status: "reconnecting", lastError: null }), this.scheduleReconnect()));
398
390
  }), n.addEventListener("error", () => {
399
- this.socket !== n || this.state.status === "closed" || (I("web-sdk.agent", "Pluno socket error; scheduling reconnect", {
391
+ this.socket !== n || this.state.status === "closed" || (A("web-sdk.agent", "Pluno socket error; scheduling reconnect", {
400
392
  queuedClientEventCount: this.queuedClientEvents.length,
401
393
  isThinking: this.state.isThinking
402
394
  }), this.clearSocketPhaseTimers(), this.stopHeartbeat(), this.socket = null, this.setState({ status: "reconnecting", lastError: null }), this.scheduleReconnect(), n.readyState !== WebSocket.CLOSED && n.readyState !== WebSocket.CLOSING && n.close());
@@ -419,26 +411,32 @@ class _e {
419
411
  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;
420
412
  }
421
413
  destroy() {
422
- this.disconnect(), this.locationChangeCleanup?.(), this.locationChangeCleanup = null, this.cleanupSessionUserFilesApi(), this.pageLifecycleCleanup?.(), this.pageLifecycleCleanup = null, this.activeBrowserToolCalls.clear(), ir(this.options.clientId), this.transportIdentity.release(), this.networkCaptureCleanup?.(), this.networkCaptureCleanup = null, this.networkBatchTimer !== null && (window.clearTimeout(this.networkBatchTimer), this.networkBatchTimer = null), this.queuedNetworkEvents = [];
414
+ this.disconnect(), this.locationChangeCleanup?.(), this.locationChangeCleanup = null, this.cleanupSessionUserFilesApi(), this.pageLifecycleCleanup?.(), this.pageLifecycleCleanup = null, this.activeBrowserToolCalls.clear(), rr(this.options.clientId), this.transportIdentity.release(), this.networkCaptureCleanup?.(), this.networkCaptureCleanup = null, this.networkBatchTimer !== null && (window.clearTimeout(this.networkBatchTimer), this.networkBatchTimer = null), this.queuedNetworkEvents = [];
423
415
  for (const t of Object.values(this.listeners))
424
416
  t?.clear();
425
417
  }
426
- sendMessage(t, s = {}) {
427
- const n = t.trim(), r = s.attachments ?? [], i = r.map(Gt);
418
+ async sendMessage(t, s = {}) {
419
+ const n = t.trim(), r = s.attachments ?? [];
420
+ let i = r.map(Wt);
428
421
  if (!n && i.length === 0)
429
422
  return null;
430
- const o = R(), a = s.clientMessageId ?? Q();
431
- this.retryableClientMessageId = null;
432
- const u = {
423
+ const o = _(), a = s.clientMessageId ?? Et(), c = {
433
424
  id: `local-${a}`,
434
425
  role: "user",
435
426
  content: n,
436
427
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
437
428
  ...r.length > 0 ? { attachments: r } : {}
438
- }, c = this.state.messages.some((f) => f.id === u.id || f.clientMessageId === a);
429
+ }, l = this.state.messages.some((u) => u.id === c.id || u.clientMessageId === a), d = this.state.isThinking, p = {
430
+ assistantDraft: this.state.assistantDraft,
431
+ assistantDraftItemId: this.state.assistantDraftItemId,
432
+ assistantDraftPhase: this.state.assistantDraftPhase,
433
+ assistantDraftRespondsToUserMessageId: this.state.assistantDraftRespondsToUserMessageId,
434
+ assistantDraftRunId: this.state.assistantDraftRunId,
435
+ lastError: this.state.lastError
436
+ };
439
437
  this.setState({
440
- messages: c ? this.state.messages : [...this.state.messages, u],
441
- ...this.state.isThinking ? {} : {
438
+ ...l ? {} : { messages: [...this.state.messages, c] },
439
+ ...d ? {} : {
442
440
  assistantDraft: "",
443
441
  assistantDraftItemId: null,
444
442
  assistantDraftPhase: null,
@@ -447,46 +445,68 @@ class _e {
447
445
  },
448
446
  isThinking: !0,
449
447
  lastError: null
450
- }), c || this.emit("message", u);
451
- const l = !s.initiatedBy && this.options.capturePageContent !== !1 && this.lastUserMessagePageUrl !== o.url, h = {
448
+ }), l || this.emit("message", c);
449
+ try {
450
+ const u = [];
451
+ for (const h of i) {
452
+ const m = h.id ? this.attachmentFiles.get(h.id) : void 0;
453
+ if (h.sandboxPath) {
454
+ u.push(h);
455
+ continue;
456
+ }
457
+ if (!m)
458
+ throw new Error(`Attachment bytes are unavailable for ${h.name}`);
459
+ u.push(await this.uploadAttachmentForMessage({ file: m, attachment: h }));
460
+ }
461
+ i = u;
462
+ } catch (u) {
463
+ throw this.setState({
464
+ ...l ? {} : { messages: this.state.messages.filter((h) => h.id !== c.id) },
465
+ ...d ? {} : { ...p, isThinking: !1 }
466
+ }), u;
467
+ }
468
+ this.retryableClientMessageId = null;
469
+ const y = !s.initiatedBy && this.options.capturePageContent !== !1 && this.lastUserMessagePageUrl !== o.url, f = {
452
470
  type: "chat.user_message",
453
471
  sessionId: this.state.sessionId ?? void 0,
454
472
  clientMessageId: a,
455
473
  initiatedBy: s.initiatedBy,
474
+ invocation: Zs(s.invocation ?? s.initiatedBy),
475
+ entrySurface: this.options.entrySurface,
456
476
  content: n,
457
- pageContent: l && Wt() || void 0,
477
+ pageContent: y && qt() || void 0,
458
478
  attachments: i.length > 0 ? i : void 0,
459
479
  page: o,
460
480
  model: this.options.model,
461
- metadata: ce(this.options.metadata)
481
+ metadata: ie(this.options.metadata)
462
482
  };
463
- return s.initiatedBy || (this.lastUserMessagePageUrl = o.url), this.activeClientMessageId = a, this.activeUserMessageEvent = h, this.markThinkingProgress(), this.send(h), this.startBackgroundAttachmentUploads(a, i), a;
483
+ return s.initiatedBy || (this.lastUserMessagePageUrl = o.url), this.activeClientMessageId = a, this.activeUserMessageEvent = f, this.markThinkingProgress(), this.send(f), a;
464
484
  }
465
485
  retryLastMessage() {
466
486
  const t = this.state.sessionId, s = this.retryableClientMessageId;
467
487
  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);
468
488
  }
469
489
  createLocalAttachment(t) {
470
- const s = Q(), n = {
490
+ const s = Et(), n = {
471
491
  id: s,
472
492
  name: t.name || "attachment",
473
- mimeType: Ie(t),
493
+ mimeType: me(t),
474
494
  sizeBytes: t.size
475
495
  };
476
496
  this.attachmentFiles.set(s, t), this.attachmentBlobCache.set(s, t);
477
497
  const r = Date.now();
478
- return Se({
498
+ return Xe({
479
499
  attachmentId: s,
480
500
  name: n.name,
481
501
  mimeType: n.mimeType,
482
502
  sizeBytes: n.sizeBytes,
483
503
  blob: t,
484
- origin: R().origin,
504
+ origin: _().origin,
485
505
  sessionId: this.state.sessionId ?? void 0,
486
506
  createdAt: r,
487
507
  lastUsedAt: r
488
508
  }).catch((i) => {
489
- I("web-sdk.attachments", "Failed to store Product Agent attachment", {
509
+ A("web-sdk.attachments", "Failed to store Product Agent attachment", {
490
510
  attachmentId: s,
491
511
  name: n.name,
492
512
  message: i instanceof Error ? i.message : String(i)
@@ -497,91 +517,52 @@ class _e {
497
517
  const s = this.createLocalAttachment(t);
498
518
  return await this.uploadAttachmentForMessage({
499
519
  file: t,
500
- attachment: s,
501
- clientMessageId: Q(),
502
- waitForSession: !1,
503
- notifyCompletion: !1
520
+ attachment: s
504
521
  });
505
522
  }
506
- startBackgroundAttachmentUploads(t, s) {
507
- for (const n of s) {
508
- if (!n.id || n.gcsPath || !this.attachmentFiles.has(n.id))
509
- continue;
510
- const r = this.attachmentFiles.get(n.id);
511
- r && this.uploadAttachmentForMessage({
512
- file: r,
513
- attachment: n,
514
- clientMessageId: t,
515
- waitForSession: !0,
516
- notifyCompletion: !0
517
- }).catch((i) => {
518
- I("web-sdk.agent", "Attachment background upload failed", {
519
- attachmentId: n.id,
520
- name: n.name,
521
- message: i instanceof Error ? i.message : String(i)
522
- });
523
- });
524
- }
525
- }
526
523
  async uploadAttachmentForMessage({
527
524
  file: t,
528
- attachment: s,
529
- clientMessageId: n,
530
- waitForSession: r,
531
- notifyCompletion: i
525
+ attachment: s
532
526
  }) {
533
- const o = r ? await this.waitForSessionId() : this.state.sessionId, a = Ie(t), u = {
534
- sessionId: o ?? void 0,
527
+ const n = this.state.sessionId, r = me(t), i = {
528
+ sessionId: n ?? void 0,
535
529
  attachmentId: s.id,
536
530
  clientId: this.options.clientId,
537
531
  transportId: this.transportIdentity.transportId,
538
532
  name: t.name || "attachment",
539
- mimeType: a,
533
+ mimeType: r,
540
534
  sizeBytes: t.size,
541
- page: R(),
535
+ page: _(),
542
536
  model: this.options.model,
543
- metadata: ce(this.options.metadata)
544
- }, c = this.options.prepareAttachmentUpload ? await _t(
545
- () => this.options.prepareAttachmentUpload(u),
537
+ metadata: ie(this.options.metadata),
538
+ entrySurface: this.options.entrySurface
539
+ }, o = this.options.prepareAttachmentUpload ? await Rt(
540
+ () => this.options.prepareAttachmentUpload(i),
546
541
  "Failed to prepare attachment upload"
547
- ) : await this.prepareEmbedAttachmentUpload(u);
548
- await _t(async () => {
549
- const h = await fetch(c.uploadUrl, {
550
- method: c.uploadMethod,
551
- headers: c.uploadHeaders,
542
+ ) : await this.prepareEmbedAttachmentUpload(i);
543
+ await Rt(async () => {
544
+ const c = await fetch(new URL(o.uploadUrl, this.options.backendUrl), {
545
+ method: o.uploadMethod,
546
+ headers: o.uploadHeaders,
552
547
  body: t
553
548
  });
554
- if (!h.ok)
555
- throw new st("Failed to upload attachment", h.status);
556
- return h;
557
- }, "Failed to upload attachment"), this.setState({ sessionId: c.sessionId });
558
- const l = qe(c.attachment, this.options.backendUrl);
559
- return this.updateAttachmentInState(s.id, l), s.id && Ee(s.id, {
560
- sessionId: c.sessionId,
561
- fileUrl: l.fileUrl,
562
- gcsPath: l.gcsPath,
549
+ if (!c.ok)
550
+ throw new et("Failed to upload attachment", c.status);
551
+ return c;
552
+ }, "Failed to upload attachment"), this.setState({ sessionId: o.sessionId });
553
+ const a = Oe(o.attachment, this.options.backendUrl);
554
+ return this.updateAttachmentInState(s.id, a), s.id && Je(s.id, {
555
+ sessionId: o.sessionId,
556
+ fileUrl: a.fileUrl,
557
+ sandboxPath: a.sandboxPath,
563
558
  lastUsedAt: Date.now()
564
- }).catch((h) => {
565
- I("web-sdk.attachments", "Failed to update persisted Product Agent attachment", {
559
+ }).catch((c) => {
560
+ A("web-sdk.attachments", "Failed to update persisted Product Agent attachment", {
566
561
  attachmentId: s.id,
567
- name: l.name,
568
- message: h instanceof Error ? h.message : String(h)
569
- });
570
- }), i && l.gcsPath && this.send({
571
- type: "attachment.upload_completed",
572
- sessionId: c.sessionId,
573
- clientMessageId: n,
574
- attachment: l
575
- }), l;
576
- }
577
- waitForSessionId() {
578
- return this.state.sessionId ? Promise.resolve(this.state.sessionId) : new Promise((t, s) => {
579
- const n = window.setTimeout(() => {
580
- r(), s(new Error("Timed out waiting for Pluno session before persisting attachment"));
581
- }, Rs), r = this.on("state", (i) => {
582
- i.sessionId && (window.clearTimeout(n), r(), t(i.sessionId));
562
+ name: a.name,
563
+ message: c instanceof Error ? c.message : String(c)
583
564
  });
584
- });
565
+ }), a;
585
566
  }
586
567
  updateAttachmentInState(t, s) {
587
568
  if (!t)
@@ -596,18 +577,18 @@ class _e {
596
577
  }
597
578
  async prepareEmbedAttachmentUpload(t) {
598
579
  let s = !1;
599
- return await _t(async () => {
580
+ return await Rt(async () => {
600
581
  const n = await this.fetchEmbedAttachmentUpload(t);
601
582
  if (n.ok)
602
583
  return await n.json();
603
- if (Er(n.status) && this.options.tokenProvider && !s) {
584
+ if (wr(n.status) && this.options.tokenProvider && !s) {
604
585
  s = !0;
605
586
  const r = await this.fetchEmbedAttachmentUpload(t);
606
587
  if (r.ok)
607
588
  return await r.json();
608
- throw new st("Failed to prepare attachment upload", r.status);
589
+ throw new et("Failed to prepare attachment upload", r.status);
609
590
  }
610
- throw new st("Failed to prepare attachment upload", n.status);
591
+ throw new et("Failed to prepare attachment upload", n.status);
611
592
  }, "Failed to prepare attachment upload");
612
593
  }
613
594
  async fetchEmbedAttachmentUpload(t) {
@@ -629,7 +610,7 @@ class _e {
629
610
  !this.options.keepRunsActiveOnSessionNavigation && s && this.state.sessionId && this.state.isThinking && this.send({ type: "run.stop", sessionId: this.state.sessionId, reason: "new_chat" }), this.cleanupSessionUserFilesApi(), this.queuedClientEvents = this.queuedClientEvents.filter((n) => n.type !== "chat.user_message"), this.clearThinkingWatchdog(), this.retryableClientMessageId = null, this.lastUserMessagePageUrl = null, this.retryAttemptsByClientMessageId = {}, this.thinkingWatchdogResyncAttemptsByClientMessageId = {}, s && this.send({
630
611
  type: "session.reset",
631
612
  sessionId: this.state.sessionId ?? void 0,
632
- page: R()
613
+ page: _()
633
614
  }), this.setState({
634
615
  sessionId: null,
635
616
  starterPrompts: [...this.state.starterPrompts],
@@ -644,15 +625,15 @@ class _e {
644
625
  });
645
626
  }
646
627
  listSessions(t = {}) {
647
- const s = Q(), n = new Promise((i, o) => {
628
+ const s = Et(), n = new Promise((i, o) => {
648
629
  const a = window.setTimeout(() => {
649
630
  this.pendingSessionHistoryRequests.delete(s), o(new Error("Session history did not respond in time"));
650
- }, bs);
631
+ }, Es);
651
632
  this.pendingSessionHistoryRequests.set(s, { resolve: i, reject: o, timeout: a });
652
633
  }), r = {
653
634
  type: "sessions.list",
654
635
  requestId: s,
655
- page: R(),
636
+ page: _(),
656
637
  ...t.cursor ? { cursor: t.cursor } : {},
657
638
  ...t.limit ? { limit: t.limit } : {}
658
639
  };
@@ -676,11 +657,11 @@ class _e {
676
657
  }), this.send({
677
658
  type: "session.load",
678
659
  sessionId: t,
679
- page: R()
660
+ page: _()
680
661
  });
681
662
  }
682
663
  send(t) {
683
- this.sendNow(_(t)) || (this.queuedClientEvents.push(t), W(this.options.clientId, this.queuedClientEvents), this.setState({ status: "reconnecting" }), this.scheduleReconnect());
664
+ this.sendNow(k(t)) || (this.queuedClientEvents.push(t), $(this.options.clientId, this.queuedClientEvents), this.setState({ status: "reconnecting" }), this.scheduleReconnect());
684
665
  }
685
666
  async getUploadToken() {
686
667
  const t = this.options.token ?? await this.options.tokenProvider?.() ?? this.token ?? null;
@@ -695,7 +676,7 @@ class _e {
695
676
  try {
696
677
  return s.send(JSON.stringify(t)), !0;
697
678
  } catch (n) {
698
- return I("web-sdk.agent", "Pluno socket send failed; scheduling reconnect", {
679
+ return A("web-sdk.agent", "Pluno socket send failed; scheduling reconnect", {
699
680
  message: n instanceof Error ? n.message : String(n),
700
681
  queuedClientEventCount: this.queuedClientEvents.length,
701
682
  isThinking: this.state.isThinking
@@ -706,9 +687,9 @@ class _e {
706
687
  if (this.state.starterPromptsLoading || this.transientStarterPromptsRequestInFlight || this.transientStarterPromptsRequestAttempted)
707
688
  return;
708
689
  this.transientStarterPromptsRequestInFlight = !0, this.transientStarterPromptsRequestAttempted = !0, this.setState({ starterPromptsLoading: !0 });
709
- const t = sn();
690
+ const t = en();
710
691
  this.sendNow(
711
- _({
692
+ k({
712
693
  type: "starter_prompts.page_context",
713
694
  pageUrl: t.pageUrl,
714
695
  pageTitle: t.pageTitle,
@@ -717,13 +698,13 @@ class _e {
717
698
  ) || (this.transientStarterPromptsRequestInFlight = !1, this.transientStarterPromptsRequestAttempted = !1, this.setState({ starterPromptsLoading: !1 }));
718
699
  }
719
700
  startStarterPromptUrlWatcher() {
720
- this.locationChangeCleanup || (this.locationChangeCleanup = nn(() => this.handleStarterPromptUrlChange()));
701
+ this.locationChangeCleanup || (this.locationChangeCleanup = sn(() => this.handleStarterPromptUrlChange()));
721
702
  }
722
703
  handleStarterPromptUrlChange() {
723
704
  const t = location.href;
724
705
  t !== this.lastStarterPromptPageUrl && (this.lastStarterPromptPageUrl = t, this.clearStarterPromptUrlRefreshTimer(), this.starterPromptUrlRefreshTimer = window.setTimeout(() => {
725
706
  this.starterPromptUrlRefreshTimer = null, this.refreshStarterPromptsForCurrentUrl();
726
- }, Ds));
707
+ }, Cs));
727
708
  }
728
709
  refreshStarterPromptsForCurrentUrl() {
729
710
  this.socket?.readyState !== WebSocket.OPEN || this.state.status === "closed" || (this.setState({ starterPromptsLoading: this.state.messages.length === 0 }), this.sendNow({
@@ -738,14 +719,14 @@ class _e {
738
719
  if (this.socket?.readyState !== WebSocket.OPEN || this.queuedClientEvents.length === 0)
739
720
  return;
740
721
  const t = this.queuedClientEvents.splice(0, this.queuedClientEvents.length);
741
- W(this.options.clientId, this.queuedClientEvents);
722
+ $(this.options.clientId, this.queuedClientEvents);
742
723
  for (let s = 0; s < t.length; s += 1) {
743
724
  const n = t[s];
744
- if (!this.sendNow(_(n))) {
745
- this.queuedClientEvents.unshift(n, ...t.slice(s + 1)), W(this.options.clientId, this.queuedClientEvents);
725
+ if (!this.sendNow(k(n))) {
726
+ this.queuedClientEvents.unshift(n, ...t.slice(s + 1)), $(this.options.clientId, this.queuedClientEvents);
746
727
  return;
747
728
  }
748
- W(this.options.clientId, this.queuedClientEvents);
729
+ $(this.options.clientId, this.queuedClientEvents);
749
730
  }
750
731
  }
751
732
  handleServerEvent(t) {
@@ -757,67 +738,67 @@ class _e {
757
738
  this.clearHeartbeatAckTimer();
758
739
  return;
759
740
  }
760
- if (xs(t) && this.markThinkingProgress(), t.type === "auth.ok") {
741
+ if (vs(t) && this.markThinkingProgress(), t.type === "auth.ok") {
761
742
  this.clearSocketAuthTimer(), this.reconnectAttempts = 0, this.flushQueuedClientEvents(), this.startHeartbeat();
762
- const s = fn(t), n = Object.prototype.hasOwnProperty.call(t, "appearance");
763
- I("web-sdk.agent", "Received auth.ok appearance", {
743
+ const s = pn(t), n = Object.prototype.hasOwnProperty.call(t, "appearance");
744
+ A("web-sdk.agent", "Received auth.ok appearance", {
764
745
  hasAppearance: n,
765
746
  rawAppearance: t.appearance,
766
747
  normalizedAppearance: s
767
- }), this.runtimeHelperJavascript = gn(t.runtimeHelpers)?.javascript ?? null;
768
- const r = de(t, "starterPrompts"), i = Object.prototype.hasOwnProperty.call(t, "starterPrompts"), o = t.starterPromptsLoading === !0, a = {
748
+ }), this.runtimeHelperJavascript = fn(t.runtimeHelpers)?.javascript ?? null;
749
+ const r = ce(t, "starterPrompts"), i = Object.prototype.hasOwnProperty.call(t, "starterPrompts"), o = t.starterPromptsLoading === !0, a = {
769
750
  user: In(t.user),
770
751
  status: "connected"
771
752
  };
772
- (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 && !on() && this.requestTransientStarterPrompts(), this.state.sessionId && this.send({
753
+ (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 && !rn() && this.requestTransientStarterPrompts(), this.state.sessionId && this.send({
773
754
  type: "page.upsert",
774
755
  sessionId: this.state.sessionId,
775
- page: R(),
756
+ page: _(),
776
757
  model: this.options.model
777
758
  });
778
759
  return;
779
760
  }
780
761
  if (t.type === "starterPrompts.updated") {
781
762
  this.transientStarterPromptsRequestInFlight = !1, this.transientStarterPromptsRequestAttempted = !0, this.setState({
782
- starterPrompts: de(t, "starterPrompts"),
763
+ starterPrompts: ce(t, "starterPrompts"),
783
764
  starterPromptsLoading: !1
784
765
  });
785
766
  return;
786
767
  }
787
768
  if (t.type === "conversation.state") {
788
- const s = Array.isArray(t.items) ? t.items : [], n = _n(
769
+ const s = Array.isArray(t.items) ? t.items : [], n = Rn(
789
770
  t.assistantDraft
790
771
  ), r = n !== void 0;
791
772
  this.rememberUserMessageClientMessageIds(s);
792
- const i = Fn(s);
773
+ const i = Hn(s);
793
774
  if (i) {
794
- const d = Wn(s, i);
775
+ const u = Fn(s, i);
795
776
  this.retryAttemptsByClientMessageId[i] = Math.max(
796
777
  this.retryAttemptsByClientMessageId[i] ?? 0,
797
- d
778
+ u
798
779
  );
799
780
  }
800
- const o = s.filter((d) => {
801
- const g = x(d);
802
- return !ge(g) && (!i || !Dt(g));
803
- }), a = Nn(
781
+ const o = s.filter((u) => {
782
+ const h = L(u);
783
+ return !he(h) && (!i || !Pt(h));
784
+ }), a = Dn(
804
785
  this.state.messages,
805
- wn(o, this.options.backendUrl)
806
- ), u = fe(a), c = !r && s.some(
807
- (d) => ye(
808
- x(d),
786
+ Tn(o, this.options.backendUrl)
787
+ ), c = de(a), l = !r && s.some(
788
+ (u) => fe(
789
+ L(u),
809
790
  this.state.assistantDraft,
810
791
  this.state.assistantDraftItemId,
811
792
  this.state.assistantDraftRespondsToUserMessageId,
812
793
  this.state.assistantDraftRunId
813
794
  )
814
- ), l = r ? n?.content ?? "" : this.state.assistantDraft, h = !!n?.content, f = u && (!l || c);
815
- if (!u && Hn(this.state.messages, s))
795
+ ), d = r ? n?.content ?? "" : this.state.assistantDraft, p = !!n?.content, y = c && (!d || l);
796
+ if (!c && qn(this.state.messages, s))
816
797
  return;
817
- this.lastUserMessagePageUrl = qn(s);
818
- const p = f ? null : Nt(s);
819
- if (this.latestRecoverableClientMessageId = p, xn(a) && this.clearRetryTimers(), this.setState({
820
- sessionId: E(t.session, "id") ?? this.state.sessionId,
798
+ this.lastUserMessagePageUrl = Bn(s);
799
+ const f = y ? null : Ut(s);
800
+ if (this.latestRecoverableClientMessageId = f, Nn(a) && this.clearRetryTimers(), this.setState({
801
+ sessionId: b(t.session, "id") ?? this.state.sessionId,
821
802
  messages: a,
822
803
  ...r ? {
823
804
  assistantDraft: n?.content ?? "",
@@ -825,46 +806,46 @@ class _e {
825
806
  assistantDraftPhase: n?.phase ?? null,
826
807
  assistantDraftRespondsToUserMessageId: n?.respondsToUserMessageId ?? null,
827
808
  assistantDraftRunId: n?.runId ?? null
828
- } : c ? {
809
+ } : l ? {
829
810
  assistantDraft: "",
830
811
  assistantDraftItemId: null,
831
812
  assistantDraftPhase: null,
832
813
  assistantDraftRespondsToUserMessageId: null,
833
814
  assistantDraftRunId: null
834
815
  } : {},
835
- ...h ? {
816
+ ...p ? {
836
817
  isThinking: !0,
837
818
  lastError: null
838
- } : f ? {
819
+ } : y ? {
839
820
  isThinking: !1
840
- } : p ? {
821
+ } : f ? {
841
822
  isThinking: !0,
842
823
  lastError: null
843
824
  } : {}
844
- }), f ? (this.retryableClientMessageId = null, this.clearThinkingWatchdog()) : (h || p) && (p && (this.activeClientMessageId = p), this.markThinkingProgress()), i) {
845
- const d = E(t.session, "id") ?? this.state.sessionId;
846
- d && this.retryAfterInterruptedRun(d, i);
825
+ }), y ? (this.retryableClientMessageId = null, this.clearThinkingWatchdog()) : (p || f) && (f && (this.activeClientMessageId = f), this.markThinkingProgress()), i) {
826
+ const u = b(t.session, "id") ?? this.state.sessionId;
827
+ u && this.retryAfterInterruptedRun(u, i);
847
828
  }
848
829
  return;
849
830
  }
850
831
  if (t.type === "sessions.page") {
851
832
  const s = typeof t.requestId == "string" ? t.requestId : null, n = s ? this.pendingSessionHistoryRequests.get(s) : null;
852
833
  s && n && (window.clearTimeout(n.timeout), this.pendingSessionHistoryRequests.delete(s), n.resolve({
853
- sessions: An(t.sessions),
834
+ sessions: wn(t.sessions),
854
835
  nextCursor: typeof t.nextCursor == "string" ? t.nextCursor : null
855
836
  }));
856
837
  return;
857
838
  }
858
839
  if (t.type === "session.updated") {
859
- this.clearRunAckResyncRetryTimer(), this.setState({ sessionId: E(t.session, "id") ?? this.state.sessionId });
840
+ this.clearRunAckResyncRetryTimer(), this.setState({ sessionId: b(t.session, "id") ?? this.state.sessionId });
860
841
  return;
861
842
  }
862
843
  if (t.type === "session.item") {
863
844
  this.rememberUserMessageClientMessageIds([t.item]);
864
- const s = x(t.item);
865
- if (Dt(s)) {
845
+ const s = L(t.item);
846
+ if (Pt(s)) {
866
847
  typeof s?.runId == "string" && this.retryableFailureRunIdsAwaitingDone.add(s.runId);
867
- const r = E(t.item, "sessionId") ?? this.state.sessionId, i = s ? O(s) : null, o = i ? this.clientMessageIdsByUserMessageItemId.get(i) : null, a = typeof s?.clientMessageId == "string" ? s.clientMessageId : o ?? (i ? null : this.activeClientMessageId ?? this.latestRecoverableClientMessageId);
848
+ const r = b(t.item, "sessionId") ?? this.state.sessionId, i = s ? v(s) : null, o = i ? this.clientMessageIdsByUserMessageItemId.get(i) : null, a = typeof s?.clientMessageId == "string" ? s.clientMessageId : o ?? (i ? null : this.activeClientMessageId ?? this.latestRecoverableClientMessageId);
868
849
  if (r && a) {
869
850
  this.retryAfterInterruptedRun(r, a);
870
851
  return;
@@ -874,31 +855,32 @@ class _e {
874
855
  return;
875
856
  }
876
857
  }
877
- if (ge(s))
858
+ if (he(s))
878
859
  return;
879
- const n = De(t.item, this.options.backendUrl);
860
+ const n = Me(t.item, this.options.backendUrl);
880
861
  if (n) {
881
- j(n) && (this.retryableClientMessageId = null, this.clearRetryTimers(), this.clearRunAckResyncRetryTimer());
882
- const r = t.item.data;
883
- jn(r) && this.clearRunAckResyncRetryTimer();
884
- const i = Ne(this.state.messages, n), o = fe(i), a = ye(
885
- r,
862
+ const r = n.callId ? this.pendingToolLoadingByCallId.get(n.callId) : void 0;
863
+ n.callId && r !== void 0 && (n.loading = r, this.pendingToolLoadingByCallId.delete(n.callId)), j(n) && (this.retryableClientMessageId = null, this.clearRetryTimers(), this.clearRunAckResyncRetryTimer());
864
+ const i = t.item.data;
865
+ Wn(i) && this.clearRunAckResyncRetryTimer();
866
+ const o = Ce(this.state.messages, n), a = de(o), c = fe(
867
+ i,
886
868
  this.state.assistantDraft,
887
869
  this.state.assistantDraftItemId,
888
870
  this.state.assistantDraftRespondsToUserMessageId,
889
871
  this.state.assistantDraftRunId
890
- ), u = o && (!this.state.assistantDraft || a);
872
+ ), l = a && (!this.state.assistantDraft || c);
891
873
  this.setState({
892
- messages: i,
893
- ...a ? {
874
+ messages: o,
875
+ ...c ? {
894
876
  assistantDraft: "",
895
877
  assistantDraftItemId: null,
896
878
  assistantDraftPhase: null,
897
879
  assistantDraftRespondsToUserMessageId: null,
898
880
  assistantDraftRunId: null
899
881
  } : {},
900
- ...u ? { isThinking: !1 } : {}
901
- }), u && this.clearThinkingWatchdog(), this.emit("message", n);
882
+ ...l ? { isThinking: !1 } : {}
883
+ }), l && this.clearThinkingWatchdog(), this.emit("message", n);
902
884
  }
903
885
  return;
904
886
  }
@@ -933,9 +915,9 @@ class _e {
933
915
  }
934
916
  if (t.type === "tool.call") {
935
917
  this.clearRunAckResyncRetryTimer();
936
- const s = Un(t);
918
+ const s = Pn(t);
937
919
  if (s) {
938
- const n = Cn(
920
+ const n = Mn(
939
921
  this.state.messages,
940
922
  s
941
923
  );
@@ -952,6 +934,18 @@ class _e {
952
934
  this.executeToolCall(t);
953
935
  return;
954
936
  }
937
+ if (t.type === "tool.status") {
938
+ const s = typeof t.callId == "string" ? t.callId : null;
939
+ if (!s)
940
+ return;
941
+ const n = t.status === "queued" || t.status === "running";
942
+ if (n && this.terminalToolCallIds.has(s))
943
+ return;
944
+ n || this.terminalToolCallIds.add(s), this.state.messages.some(
945
+ (i) => i.callId === s
946
+ ) ? this.setToolMessageLoading(s, n) : this.pendingToolLoadingByCallId.set(s, n);
947
+ return;
948
+ }
955
949
  if (t.type === "error") {
956
950
  const s = typeof t.requestId == "string" ? t.requestId : null, n = s ? this.pendingSessionHistoryRequests.get(s) : null;
957
951
  if (s && n) {
@@ -964,8 +958,8 @@ class _e {
964
958
  return;
965
959
  }
966
960
  o && r && i && (this.retryableClientMessageId = i);
967
- const a = new Error(typeof t.message == "string" ? t.message.replace(/Product Agent/g, "Pluno") : "Pluno error"), u = tn(a.message);
968
- u && console.error(u), this.setState({
961
+ const a = new Error(typeof t.message == "string" ? t.message.replace(/Product Agent/g, "Pluno") : "Pluno error"), c = Qs(a.message);
962
+ c && console.error(c), this.setState({
969
963
  status: "error",
970
964
  isThinking: !1,
971
965
  lastError: a.message,
@@ -1029,7 +1023,7 @@ class _e {
1029
1023
  }
1030
1024
  rememberUserMessageClientMessageIds(t) {
1031
1025
  for (const s of t) {
1032
- const n = E(s, "id"), r = x(s);
1026
+ const n = b(s, "id"), r = L(s);
1033
1027
  n && r?.type === "message" && r.role === "user" && typeof r.clientMessageId == "string" && this.clientMessageIdsByUserMessageItemId.set(n, r.clientMessageId);
1034
1028
  }
1035
1029
  }
@@ -1039,7 +1033,7 @@ class _e {
1039
1033
  this.pendingSessionHistoryRequests.clear();
1040
1034
  }
1041
1035
  markThinkingProgress() {
1042
- !this.state.isThinking || this.state.status === "closed" || (this.scheduleThinkingWatchdog(oe), this.activeClientMessageId && this.scheduleRunAckWatchdog(this.activeClientMessageId));
1036
+ !this.state.isThinking || this.state.status === "closed" || (this.scheduleThinkingWatchdog(ne), this.activeClientMessageId && this.scheduleRunAckWatchdog(this.activeClientMessageId));
1043
1037
  }
1044
1038
  scheduleThinkingWatchdog(t) {
1045
1039
  this.thinkingWatchdogTimer !== null && window.clearTimeout(this.thinkingWatchdogTimer), this.thinkingWatchdogTimer = window.setTimeout(() => {
@@ -1059,10 +1053,10 @@ class _e {
1059
1053
  scheduleRunAckWatchdog(t) {
1060
1054
  this.runAckWatchdogTimer !== null && window.clearTimeout(this.runAckWatchdogTimer), this.runAckWatchdogTimer = window.setTimeout(() => {
1061
1055
  this.runAckWatchdogTimer = null, this.recoverMissedRunAck(t);
1062
- }, As);
1056
+ }, ws);
1063
1057
  }
1064
1058
  recoverMissedRunAck(t) {
1065
- !this.state.isThinking || this.state.status === "closed" || this.activeClientMessageId !== t || (I("web-sdk.agent", "Pluno run ack missed; resyncing session", {
1059
+ !this.state.isThinking || this.state.status === "closed" || this.activeClientMessageId !== t || (A("web-sdk.agent", "Pluno run ack missed; resyncing session", {
1066
1060
  sessionId: this.state.sessionId,
1067
1061
  clientMessageId: t
1068
1062
  }), this.resyncThinkingSession(), this.scheduleRunAckResyncRetry(t));
@@ -1075,7 +1069,7 @@ class _e {
1075
1069
  status: this.state.status === "reconnecting" ? "reconnecting" : "connected",
1076
1070
  isThinking: !0,
1077
1071
  lastError: null
1078
- }), I("web-sdk.agent", "Pluno run ack recovery retrying last user message", {
1072
+ }), A("web-sdk.agent", "Pluno run ack recovery retrying last user message", {
1079
1073
  sessionId: this.state.sessionId,
1080
1074
  clientMessageId: t
1081
1075
  }), this.state.sessionId ? this.send({
@@ -1083,8 +1077,8 @@ class _e {
1083
1077
  sessionId: this.state.sessionId,
1084
1078
  clientMessageId: t,
1085
1079
  automatic: !0
1086
- }) : this.activeUserMessageEvent && this.send(this.activeUserMessageEvent), this.scheduleThinkingWatchdog(oe)));
1087
- }, V(s, Ss)));
1080
+ }) : this.activeUserMessageEvent && this.send(this.activeUserMessageEvent), this.scheduleThinkingWatchdog(ne)));
1081
+ }, V(s, As)));
1088
1082
  }
1089
1083
  clearRunAckResyncRetryTimer() {
1090
1084
  this.runAckResyncRetryTimer !== null && (window.clearTimeout(this.runAckResyncRetryTimer), this.runAckResyncRetryTimer = null);
@@ -1097,7 +1091,7 @@ class _e {
1097
1091
  return;
1098
1092
  const t = this.activeClientMessageId;
1099
1093
  if (!t) {
1100
- I("web-sdk.agent", "Pluno thinking watchdog stopped without a recoverable message id", {
1094
+ A("web-sdk.agent", "Pluno thinking watchdog stopped without a recoverable message id", {
1101
1095
  sessionId: this.state.sessionId
1102
1096
  }), this.setState({
1103
1097
  isThinking: !1,
@@ -1108,7 +1102,7 @@ class _e {
1108
1102
  }
1109
1103
  const s = this.thinkingWatchdogResyncAttemptsByClientMessageId[t] ?? 0, n = this.retryAttemptsByClientMessageId[t] ?? 0;
1110
1104
  if (n >= K) {
1111
- I("web-sdk.agent", "Pluno run recovery retry exhausted", {
1105
+ A("web-sdk.agent", "Pluno run recovery retry exhausted", {
1112
1106
  sessionId: this.state.sessionId,
1113
1107
  clientMessageId: t
1114
1108
  }), this.retryableClientMessageId = t, this.setState({
@@ -1119,18 +1113,18 @@ class _e {
1119
1113
  return;
1120
1114
  }
1121
1115
  if (s < 1) {
1122
- this.thinkingWatchdogResyncAttemptsByClientMessageId[t] = s + 1, I("web-sdk.agent", "Pluno thinking watchdog resyncing session", {
1116
+ this.thinkingWatchdogResyncAttemptsByClientMessageId[t] = s + 1, A("web-sdk.agent", "Pluno thinking watchdog resyncing session", {
1123
1117
  sessionId: this.state.sessionId,
1124
1118
  clientMessageId: t,
1125
1119
  resyncAttempts: s + 1
1126
- }), this.resyncThinkingSession(), this.scheduleThinkingWatchdog(ws);
1120
+ }), this.resyncThinkingSession(), this.scheduleThinkingWatchdog(Ts);
1127
1121
  return;
1128
1122
  }
1129
1123
  this.setState({
1130
1124
  status: this.state.status === "reconnecting" ? "reconnecting" : "connected",
1131
1125
  isThinking: !0,
1132
1126
  lastError: null
1133
- }), I("web-sdk.agent", "Pluno thinking watchdog scheduling retry for last user message", {
1127
+ }), A("web-sdk.agent", "Pluno thinking watchdog scheduling retry for last user message", {
1134
1128
  sessionId: this.state.sessionId,
1135
1129
  clientMessageId: t,
1136
1130
  retryAttempts: n + 1
@@ -1147,26 +1141,26 @@ class _e {
1147
1141
  this.state.sessionId ? this.send({
1148
1142
  type: "page.upsert",
1149
1143
  sessionId: this.state.sessionId,
1150
- page: R(),
1144
+ page: _(),
1151
1145
  model: this.options.model
1152
1146
  }) : (!this.socket || this.socket.readyState !== WebSocket.OPEN) && (this.setState({ status: "reconnecting", lastError: null }), this.scheduleReconnect());
1153
1147
  }
1154
1148
  async executeToolCall(t) {
1155
- const s = typeof t.sessionId == "string" ? t.sessionId : null, n = typeof t.callId == "string" ? t.callId : null, r = typeof t.toolName == "string" ? t.toolName : null, i = L(
1149
+ 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 = N(
1156
1150
  typeof t.summary == "string" ? t.summary : "Running browser tool"
1157
1151
  ), o = t.rawInput;
1158
1152
  if (!s || !n || !r)
1159
1153
  return;
1160
1154
  const a = r === "execute_code_in_browser_tab" && o !== null && typeof o == "object" && o.tabId === "local:current";
1161
- if (r !== "execute_code" && !a || !dr(o)) {
1155
+ if (r !== "execute_code" && !a || !cr(o)) {
1162
1156
  this.setToolMessageLoading(n, !1), this.send({
1163
1157
  type: "tool.result",
1164
1158
  sessionId: s,
1165
1159
  callId: n,
1166
1160
  toolName: r,
1167
1161
  summary: i,
1168
- rawInput: _(o),
1169
- rawOutput: _({
1162
+ rawInput: k(o),
1163
+ rawOutput: k({
1170
1164
  ok: !1,
1171
1165
  toolName: r,
1172
1166
  error: `Unsupported browser tool: ${r}`
@@ -1174,7 +1168,23 @@ class _e {
1174
1168
  });
1175
1169
  return;
1176
1170
  }
1177
- const u = Hs(this.state.messages);
1171
+ if (typeof o.frameId == "string") {
1172
+ this.setToolMessageLoading(n, !1), this.send({
1173
+ type: "tool.result",
1174
+ sessionId: s,
1175
+ callId: n,
1176
+ toolName: r,
1177
+ summary: i,
1178
+ rawInput: k(o),
1179
+ rawOutput: {
1180
+ ok: !1,
1181
+ toolName: r,
1182
+ error: "Frame-targeted execution requires browser debugger access and is unavailable in embedded sessions."
1183
+ }
1184
+ });
1185
+ return;
1186
+ }
1187
+ const c = Ls(this.state.messages);
1178
1188
  this.activeBrowserToolCalls.set(n, {
1179
1189
  event: {
1180
1190
  type: "tool.result",
@@ -1182,18 +1192,21 @@ class _e {
1182
1192
  callId: n,
1183
1193
  toolName: r,
1184
1194
  summary: i,
1185
- rawInput: _(o),
1195
+ rawInput: k(o),
1186
1196
  rawOutput: null
1187
1197
  },
1188
1198
  startedAtMs: Date.now(),
1189
1199
  startedAtUrl: location.href,
1190
1200
  startedAtOrigin: location.origin
1191
- }), this.installSessionUserFilesApi(u);
1192
- let c = null, l;
1193
- c = await this.executeRuntimeHelper(), l = await le(o).catch((h) => ({
1201
+ }), this.installSessionUserFilesApi(c);
1202
+ let l = null, d;
1203
+ l = await this.executeRuntimeHelper(), d = await oe(
1204
+ o,
1205
+ Js(t.runtimeContext, this.options.backendUrl)
1206
+ ).catch((p) => ({
1194
1207
  ok: !1,
1195
1208
  exception: {
1196
- message: h instanceof Error ? h.message : String(h)
1209
+ message: p instanceof Error ? p.message : String(p)
1197
1210
  }
1198
1211
  })), this.activeBrowserToolCalls.delete(n), this.setToolMessageLoading(n, !1), this.send({
1199
1212
  type: "tool.result",
@@ -1201,12 +1214,12 @@ class _e {
1201
1214
  callId: n,
1202
1215
  toolName: r,
1203
1216
  summary: o.summary,
1204
- rawInput: _(o),
1205
- rawOutput: _(mn(l, c))
1206
- }), tr(this.options.clientId, this.activeBrowserToolCalls.values());
1217
+ rawInput: k(o),
1218
+ rawOutput: k(gn(d, l))
1219
+ }), Qn(this.options.clientId, this.activeBrowserToolCalls.values());
1207
1220
  }
1208
1221
  setToolMessageLoading(t, s) {
1209
- const n = Pn(
1222
+ const n = Cn(
1210
1223
  this.state.messages,
1211
1224
  t,
1212
1225
  s
@@ -1224,43 +1237,43 @@ class _e {
1224
1237
  };
1225
1238
  }
1226
1239
  installSessionUserFilesApi(t) {
1227
- this.cleanupSessionUserFilesApi(), this.sessionUserFilesApiCleanup = Fs(t, this.attachmentFiles, this.attachmentBlobCache);
1240
+ this.cleanupSessionUserFilesApi(), this.sessionUserFilesApiCleanup = Bs(t, this.attachmentFiles, this.attachmentBlobCache);
1228
1241
  }
1229
1242
  cleanupSessionUserFilesApi() {
1230
- this.sessionUserFilesApiCleanup && (Vs(this.sessionUserFilesApiCleanup), this.sessionUserFilesApiCleanup = null);
1243
+ this.sessionUserFilesApiCleanup && (Gs(this.sessionUserFilesApiCleanup), this.sessionUserFilesApiCleanup = null);
1231
1244
  }
1232
1245
  async executeRuntimeHelper() {
1233
1246
  if (!this.runtimeHelperJavascript?.trim())
1234
1247
  return null;
1235
- const t = await le({
1248
+ const t = await oe({
1236
1249
  javascript: this.runtimeHelperJavascript
1237
1250
  });
1238
- return t.ok === !1 ? yn(t) : null;
1251
+ return t.ok === !1 ? mn(t) : null;
1239
1252
  }
1240
1253
  enableNetworkCapture() {
1241
- this.networkCaptureCleanup || (this.networkCaptureCleanup = vs((t) => {
1242
- yr(t.url, this.options.backendUrl) || this.enqueueNetworkEvent(t);
1254
+ this.networkCaptureCleanup || (this.networkCaptureCleanup = Ds((t) => {
1255
+ fr(t.url, this.options.backendUrl) || this.enqueueNetworkEvent(t);
1243
1256
  }));
1244
1257
  }
1245
1258
  enqueueNetworkEvent(t) {
1246
- this.queuedNetworkEvents.length >= ks || (this.queuedNetworkEvents.push(mr(t)), this.networkBatchTimer === null && (this.networkBatchTimer = window.setTimeout(() => {
1259
+ this.queuedNetworkEvents.length >= bs || (this.queuedNetworkEvents.push(pr(t)), this.networkBatchTimer === null && (this.networkBatchTimer = window.setTimeout(() => {
1247
1260
  this.networkBatchTimer = null;
1248
1261
  const s = this.queuedNetworkEvents.splice(0, this.queuedNetworkEvents.length);
1249
1262
  s.length === 0 || this.socket?.readyState !== WebSocket.OPEN || this.sendNow({
1250
1263
  type: "network.batch",
1251
1264
  sessionId: this.state.sessionId ?? void 0,
1252
- page: R(),
1265
+ page: _(),
1253
1266
  events: s
1254
1267
  });
1255
- }, Es)));
1268
+ }, Ss)));
1256
1269
  }
1257
1270
  scheduleReconnect() {
1258
1271
  if (this.reconnectTimer !== null || this.state.status === "closed")
1259
1272
  return;
1260
- const t = Ns(this.reconnectAttempts);
1273
+ const t = Ps(this.reconnectAttempts);
1261
1274
  this.reconnectAttempts += 1, this.reconnectTimer = window.setTimeout(() => {
1262
1275
  this.reconnectTimer = null, this.connect().catch((s) => {
1263
- I("web-sdk.agent", "Pluno reconnect failed; retrying", {
1276
+ A("web-sdk.agent", "Pluno reconnect failed; retrying", {
1264
1277
  message: s instanceof Error ? s.message : String(s),
1265
1278
  queuedClientEventCount: this.queuedClientEvents.length,
1266
1279
  isThinking: this.state.isThinking
@@ -1272,9 +1285,9 @@ class _e {
1272
1285
  this.stopHeartbeat(), this.heartbeatTimer = window.setInterval(() => {
1273
1286
  const t = this.socket;
1274
1287
  !t || !this.sendNow({ type: "runtime.ping" }) || (this.clearHeartbeatAckTimer(), this.heartbeatAckTimer = window.setTimeout(() => {
1275
- this.socket === t && (I("web-sdk.agent", "Pluno heartbeat acknowledgement timed out; reconnecting"), this.replaceTimedOutSocket(t));
1276
- }, gs));
1277
- }, fs);
1288
+ this.socket === t && (A("web-sdk.agent", "Pluno heartbeat acknowledgement timed out; reconnecting"), this.replaceTimedOutSocket(t));
1289
+ }, fs));
1290
+ }, ps);
1278
1291
  }
1279
1292
  stopHeartbeat() {
1280
1293
  this.heartbeatTimer !== null && (window.clearInterval(this.heartbeatTimer), this.heartbeatTimer = null), this.clearHeartbeatAckTimer();
@@ -1300,105 +1313,105 @@ class _e {
1300
1313
  ...t,
1301
1314
  ...t.lastError === null && t.lastErrorCode === void 0 ? { lastErrorCode: null } : {},
1302
1315
  ...t.lastError !== void 0 && t.lastErrorSecuritySettingsUrl === void 0 ? { lastErrorSecuritySettingsUrl: null } : {}
1303
- }, Zn(this.options.clientId, this.state), this.emit("state", this.getState());
1316
+ }, Yn(this.options.clientId, this.state), this.emit("state", this.getState());
1304
1317
  }
1305
1318
  emit(t, s) {
1306
1319
  this.listeners[t]?.forEach((r) => r(s));
1307
1320
  }
1308
1321
  }
1309
- const kt = /* @__PURE__ */ new WeakMap();
1310
- function vs(e) {
1311
- const t = window.__plunoProductAgentNetworkCapture ?? Ls();
1322
+ const St = /* @__PURE__ */ new WeakMap();
1323
+ function Ds(e) {
1324
+ const t = window.__plunoProductAgentNetworkCapture ?? xs();
1312
1325
  return t.subscribers.add(e), () => {
1313
1326
  t.subscribers.delete(e), !(t.subscribers.size > 0) && (t.destroy(), window.__plunoProductAgentNetworkCapture === t && delete window.__plunoProductAgentNetworkCapture);
1314
1327
  };
1315
1328
  }
1316
- function Ls() {
1317
- const e = /* @__PURE__ */ new Set(), t = (f) => {
1318
- e.forEach((p) => {
1329
+ function xs() {
1330
+ const e = /* @__PURE__ */ new Set(), t = (y) => {
1331
+ e.forEach((f) => {
1319
1332
  try {
1320
- p(f);
1333
+ f(y);
1321
1334
  } catch {
1322
1335
  }
1323
1336
  });
1324
- }, s = window.fetch, n = XMLHttpRequest.prototype.open, r = XMLHttpRequest.prototype.setRequestHeader, i = XMLHttpRequest.prototype.send, o = function(p, d) {
1325
- const g = Date.now();
1326
- let T;
1337
+ }, s = window.fetch, n = XMLHttpRequest.prototype.open, r = XMLHttpRequest.prototype.setRequestHeader, i = XMLHttpRequest.prototype.send, o = function(f, u) {
1338
+ const h = Date.now();
1339
+ let m;
1327
1340
  try {
1328
- T = s.call(this, p, d);
1329
- } catch (y) {
1330
- throw y;
1341
+ m = s.call(this, f, u);
1342
+ } catch (T) {
1343
+ throw T;
1331
1344
  }
1332
1345
  try {
1333
- const y = p instanceof Request ? p : null, N = hr(p, y), w = He(d?.headers ?? y?.headers);
1334
- if (!v(N, w, d?.body)) {
1346
+ const T = f instanceof Request ? f : null, x = lr(f, T), I = Ne(u?.headers ?? T?.headers);
1347
+ if (!O(x, I, u?.body)) {
1335
1348
  const q = {
1336
- requestId: Rt("fetch"),
1337
- url: C(N, Et),
1338
- method: (d?.method ?? y?.method ?? "GET").toUpperCase(),
1339
- requestHeaders: w,
1340
- requestBody: we(d?.body),
1349
+ requestId: kt("fetch"),
1350
+ url: C(x, At),
1351
+ method: (u?.method ?? T?.method ?? "GET").toUpperCase(),
1352
+ requestHeaders: I,
1353
+ requestBody: ye(u?.body),
1341
1354
  resourceType: "fetch",
1342
- startedAt: new Date(g).toISOString()
1355
+ startedAt: new Date(h).toISOString()
1343
1356
  };
1344
- T.then(
1345
- (b) => {
1346
- pr(b, q, g, t).catch(() => {
1357
+ m.then(
1358
+ (R) => {
1359
+ ur(R, q, h, t).catch(() => {
1347
1360
  t({
1348
1361
  ...q,
1349
- responseStatus: b.status,
1350
- durationMs: Date.now() - g
1362
+ responseStatus: R.status,
1363
+ durationMs: Date.now() - h
1351
1364
  });
1352
1365
  });
1353
1366
  },
1354
- (b) => {
1367
+ (R) => {
1355
1368
  t({
1356
1369
  ...q,
1357
- errorText: C(b instanceof Error ? b.message : String(b)),
1358
- durationMs: Date.now() - g
1370
+ errorText: C(R instanceof Error ? R.message : String(R)),
1371
+ durationMs: Date.now() - h
1359
1372
  });
1360
1373
  }
1361
1374
  );
1362
1375
  }
1363
1376
  } catch {
1364
1377
  }
1365
- return T;
1366
- }, a = function(p, d, g, T, y) {
1367
- const N = n.call(this, p, d, g ?? !0, T ?? void 0, y ?? void 0), w = typeof d == "string" ? d : d.toString();
1368
- return kt.set(this, {
1369
- requestId: Rt("xhr"),
1370
- method: String(p ?? "GET").toUpperCase(),
1371
- url: C(w, Et),
1378
+ return m;
1379
+ }, a = function(f, u, h, m, T) {
1380
+ const x = n.call(this, f, u, h ?? !0, m ?? void 0, T ?? void 0), I = typeof u == "string" ? u : u.toString();
1381
+ return St.set(this, {
1382
+ requestId: kt("xhr"),
1383
+ method: String(f ?? "GET").toUpperCase(),
1384
+ url: C(I, At),
1372
1385
  requestHeaders: {},
1373
1386
  startedAtMs: Date.now(),
1374
1387
  startedAt: (/* @__PURE__ */ new Date()).toISOString(),
1375
- excluded: v(w)
1376
- }), N;
1377
- }, u = function(p, d) {
1378
- const g = r.call(this, p, d), T = kt.get(this);
1379
- return T && Object.keys(T.requestHeaders).length < Ht && (T.requestHeaders[p] = Xt(p, d), T.excluded = T.excluded || v(T.url, T.requestHeaders)), g;
1380
- }, c = function(p) {
1388
+ excluded: O(I)
1389
+ }), x;
1390
+ }, c = function(f, u) {
1391
+ const h = r.call(this, f, u), m = St.get(this);
1392
+ return m && Object.keys(m.requestHeaders).length < Bt && (m.requestHeaders[f] = jt(f, u), m.excluded = m.excluded || O(m.url, m.requestHeaders)), h;
1393
+ }, l = function(f) {
1381
1394
  try {
1382
- const d = kt.get(this);
1383
- d && (d.excluded = d.excluded || v(d.url, d.requestHeaders, p), d.requestBody = we(p), d.excluded || this.addEventListener(
1395
+ const u = St.get(this);
1396
+ u && (u.excluded = u.excluded || O(u.url, u.requestHeaders, f), u.requestBody = ye(f), u.excluded || this.addEventListener(
1384
1397
  "loadend",
1385
1398
  () => {
1386
1399
  queueMicrotask(() => {
1387
1400
  try {
1388
- const g = Ir(this.getAllResponseHeaders());
1401
+ const h = mr(this.getAllResponseHeaders());
1389
1402
  t({
1390
- requestId: d.requestId,
1391
- url: d.url,
1392
- method: d.method,
1393
- requestHeaders: d.requestHeaders,
1394
- requestBody: d.requestBody,
1403
+ requestId: u.requestId,
1404
+ url: u.url,
1405
+ method: u.method,
1406
+ requestHeaders: u.requestHeaders,
1407
+ requestBody: u.requestBody,
1395
1408
  resourceType: "xhr",
1396
1409
  responseStatus: this.status,
1397
- responseHeaders: g,
1398
- responseBody: gr(this, g),
1410
+ responseHeaders: h,
1411
+ responseBody: hr(this, h),
1399
1412
  errorText: this.status === 0 ? "XHR request failed or was aborted" : void 0,
1400
- startedAt: d.startedAt,
1401
- durationMs: Date.now() - d.startedAtMs
1413
+ startedAt: u.startedAt,
1414
+ durationMs: Date.now() - u.startedAtMs
1402
1415
  });
1403
1416
  } catch {
1404
1417
  return;
@@ -1409,7 +1422,7 @@ function Ls() {
1409
1422
  ));
1410
1423
  } catch {
1411
1424
  }
1412
- return i.call(this, p ?? null);
1425
+ return i.call(this, f ?? null);
1413
1426
  };
1414
1427
  try {
1415
1428
  window.fetch = o;
@@ -1420,42 +1433,42 @@ function Ls() {
1420
1433
  } catch {
1421
1434
  }
1422
1435
  try {
1423
- XMLHttpRequest.prototype.setRequestHeader = u;
1436
+ XMLHttpRequest.prototype.setRequestHeader = c;
1424
1437
  } catch {
1425
1438
  }
1426
1439
  try {
1427
- XMLHttpRequest.prototype.send = c;
1440
+ XMLHttpRequest.prototype.send = l;
1428
1441
  } catch {
1429
1442
  }
1430
- let l = null;
1443
+ let d = null;
1431
1444
  if (typeof PerformanceObserver < "u") {
1432
- l = new PerformanceObserver((f) => {
1433
- for (const p of f.getEntries()) {
1434
- const d = p;
1435
- if (d.initiatorType === "fetch" || d.initiatorType === "xmlhttprequest" || v(d.name))
1445
+ d = new PerformanceObserver((y) => {
1446
+ for (const f of y.getEntries()) {
1447
+ const u = f;
1448
+ if (u.initiatorType === "fetch" || u.initiatorType === "xmlhttprequest" || O(u.name))
1436
1449
  continue;
1437
- const g = performance.timeOrigin + d.startTime;
1450
+ const h = performance.timeOrigin + u.startTime;
1438
1451
  t({
1439
- requestId: Rt("resource"),
1440
- url: C(d.name, Et),
1452
+ requestId: kt("resource"),
1453
+ url: C(u.name, At),
1441
1454
  method: "GET",
1442
1455
  resourceType: "resource",
1443
- responseStatus: d.responseStatus,
1444
- startedAt: new Date(g).toISOString(),
1445
- durationMs: d.duration
1456
+ responseStatus: u.responseStatus,
1457
+ startedAt: new Date(h).toISOString(),
1458
+ durationMs: u.duration
1446
1459
  });
1447
1460
  }
1448
1461
  });
1449
1462
  try {
1450
- l.observe({ type: "resource", buffered: !0 });
1463
+ d.observe({ type: "resource", buffered: !0 });
1451
1464
  } catch {
1452
- l.disconnect(), l = null;
1465
+ d.disconnect(), d = null;
1453
1466
  }
1454
1467
  }
1455
- const h = {
1468
+ const p = {
1456
1469
  subscribers: e,
1457
1470
  destroy: () => {
1458
- l?.disconnect();
1471
+ d?.disconnect();
1459
1472
  try {
1460
1473
  window.fetch === o && (window.fetch = s);
1461
1474
  } catch {
@@ -1465,18 +1478,18 @@ function Ls() {
1465
1478
  } catch {
1466
1479
  }
1467
1480
  try {
1468
- XMLHttpRequest.prototype.setRequestHeader === u && (XMLHttpRequest.prototype.setRequestHeader = r);
1481
+ XMLHttpRequest.prototype.setRequestHeader === c && (XMLHttpRequest.prototype.setRequestHeader = r);
1469
1482
  } catch {
1470
1483
  }
1471
1484
  try {
1472
- XMLHttpRequest.prototype.send === c && (XMLHttpRequest.prototype.send = i);
1485
+ XMLHttpRequest.prototype.send === l && (XMLHttpRequest.prototype.send = i);
1473
1486
  } catch {
1474
1487
  }
1475
1488
  }
1476
1489
  };
1477
- return window.__plunoProductAgentNetworkCapture = h, h;
1490
+ return window.__plunoProductAgentNetworkCapture = p, p;
1478
1491
  }
1479
- function I(e, t, s) {
1492
+ function A(e, t, s) {
1480
1493
  if (typeof window > "u")
1481
1494
  return;
1482
1495
  const n = window, r = {
@@ -1487,15 +1500,15 @@ function I(e, t, s) {
1487
1500
  }, i = n.__plunoProductAgentDiagnostics__ ?? [];
1488
1501
  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 }));
1489
1502
  }
1490
- function ce(e) {
1503
+ function ie(e) {
1491
1504
  const t = typeof e == "function" ? e() : e;
1492
1505
  return t && Object.keys(t).length > 0 ? t : void 0;
1493
1506
  }
1494
- function xs(e) {
1507
+ function vs(e) {
1495
1508
  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";
1496
1509
  }
1497
- const Bs = 5e3, qs = 12e4;
1498
- function Hs(e) {
1510
+ const Os = 5e3, Ns = 12e4;
1511
+ function Ls(e) {
1499
1512
  const t = [];
1500
1513
  for (const s of e)
1501
1514
  s.role !== "user" || !s.attachments?.length || s.attachments.forEach((n, r) => {
@@ -1506,122 +1519,30 @@ function Hs(e) {
1506
1519
  });
1507
1520
  return t;
1508
1521
  }
1509
- function Fs(e, t = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map()) {
1522
+ function Bs(e, t = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map()) {
1510
1523
  const n = [
1511
- $s(e, t, s),
1512
- js(),
1513
- Ws()
1524
+ Hs(),
1525
+ qs()
1514
1526
  ].filter((r) => typeof r == "function");
1515
1527
  return () => {
1516
1528
  for (const r of n.reverse())
1517
1529
  r();
1518
1530
  };
1519
1531
  }
1520
- function Ws() {
1521
- return Bt(globalThis, "getPageSnapshot", async () => Wt());
1522
- }
1523
- function $s(e, t = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map()) {
1524
- const n = new Map(e.map((c) => [c.id, c])), r = (c) => ({
1525
- id: c.id,
1526
- name: c.name,
1527
- mimeType: c.mimeType,
1528
- sizeBytes: c.sizeBytes,
1529
- type: c.mimeType,
1530
- size: c.sizeBytes
1531
- }), i = (c) => {
1532
- const l = n.get(c);
1533
- if (!l)
1534
- throw new Error(`Unknown Pluno user file: ${c}`);
1535
- return l;
1536
- }, o = async (c) => {
1537
- const l = i(c), h = t.get(l.id);
1538
- if (h)
1539
- return h;
1540
- const f = s.get(l.id);
1541
- if (f)
1542
- return f;
1543
- const p = await Ye(l.id).then((y) => y?.blob ?? null).catch((y) => (I("web-sdk.attachments", "Failed to load Product Agent attachment from IndexedDB", {
1544
- attachmentId: l.id,
1545
- name: l.name,
1546
- message: y instanceof Error ? y.message : String(y)
1547
- }), null));
1548
- if (p)
1549
- return s.set(l.id, p), p;
1550
- if (!l.fileUrl)
1551
- throw new Error(`Pluno user file is missing content: ${c}`);
1552
- const d = await fetch(l.fileUrl, or(l.fileUrl));
1553
- if (!d.ok)
1554
- throw new Error(`Failed to load Pluno user file: ${c}`);
1555
- const g = await d.blob();
1556
- s.set(l.id, g);
1557
- const T = Date.now();
1558
- return Se({
1559
- attachmentId: l.id,
1560
- name: l.name,
1561
- mimeType: l.mimeType,
1562
- sizeBytes: l.sizeBytes,
1563
- blob: g,
1564
- fileUrl: l.fileUrl,
1565
- gcsPath: l.gcsPath,
1566
- createdAt: T,
1567
- lastUsedAt: T
1568
- }).catch((y) => {
1569
- I("web-sdk.attachments", "Failed to cache Product Agent attachment from fileUrl", {
1570
- attachmentId: l.id,
1571
- name: l.name,
1572
- message: y instanceof Error ? y.message : String(y)
1573
- });
1574
- }), g;
1575
- };
1576
- return Bt(globalThis, "userFiles", {
1577
- list: () => e.map(r),
1578
- get: (c) => {
1579
- const l = n.get(c);
1580
- return l ? r(l) : null;
1581
- },
1582
- inspectImage: async (c) => {
1583
- const l = i(c), h = await o(c), f = l.mimeType.startsWith("image/") ? l.mimeType : h.type || l.mimeType;
1584
- if (!f.startsWith("image/"))
1585
- throw new Error(`Pluno user file is not an image: ${c}`);
1586
- const p = h.type === f ? h : new Blob([h], { type: f });
1587
- return Ys(f, p.size) > Ps ? {
1588
- type: "pluno.userFiles.inspectImage",
1589
- id: l.id,
1590
- name: l.name,
1591
- mimeType: f,
1592
- sizeBytes: l.sizeBytes,
1593
- imageAttached: !1,
1594
- imageAttachmentError: Ft
1595
- } : {
1596
- type: "pluno.userFiles.inspectImage",
1597
- id: l.id,
1598
- name: l.name,
1599
- mimeType: f,
1600
- sizeBytes: l.sizeBytes,
1601
- imageAttached: !0,
1602
- dataUrl: await Ut(p)
1603
- };
1604
- },
1605
- getDataUrl: async (c) => (i(c), await Ut(await o(c))),
1606
- getBlob: o,
1607
- getArrayBuffer: async (c) => await (await o(c)).arrayBuffer(),
1608
- getFile: async (c) => {
1609
- const l = i(c);
1610
- return new File([await o(c)], l.name, { type: l.mimeType });
1611
- }
1612
- });
1532
+ function qs() {
1533
+ return Te(globalThis, "getPageSnapshot", async () => qt());
1613
1534
  }
1614
- function js() {
1615
- return Bt(globalThis, "pageImages", {
1616
- inspectImage: async (t, s) => await zs(t, s)
1535
+ function Hs() {
1536
+ return Te(globalThis, "pageImages", {
1537
+ inspectImage: async (t, s) => await Fs(t, s)
1617
1538
  });
1618
1539
  }
1619
- async function zs(e, t = {}) {
1620
- const s = Ks(t.name), n = await Gs(e);
1540
+ async function Fs(e, t = {}) {
1541
+ const s = zs(t.name), n = await $s(e);
1621
1542
  return n.ok ? n.sizeBytes > 8 * 1024 * 1024 ? {
1622
1543
  type: "pluno.pageImages.inspectImage",
1623
1544
  imageAttached: !1,
1624
- imageAttachmentError: Ft
1545
+ imageAttachmentError: Ae
1625
1546
  } : {
1626
1547
  type: "pluno.pageImages.inspectImage",
1627
1548
  imageAttached: !0,
@@ -1635,15 +1556,15 @@ async function zs(e, t = {}) {
1635
1556
  imageAttachmentError: n.error
1636
1557
  };
1637
1558
  }
1638
- async function Gs(e) {
1639
- 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: Ft } : {
1559
+ async function $s(e) {
1560
+ return e instanceof Blob ? e.type.startsWith("image/") ? e.size === 0 ? { ok: !1, error: "Page image is empty." } : e.size > 8 * 1024 * 1024 ? { ok: !1, error: Ae } : {
1640
1561
  ok: !0,
1641
1562
  mimeType: e.type,
1642
1563
  sizeBytes: e.size,
1643
- dataUrl: await Ut(e)
1644
- } : { 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." } : Xs(e);
1564
+ dataUrl: await Xs(e)
1565
+ } : { 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." } : Ws(e);
1645
1566
  }
1646
- function Xs(e) {
1567
+ function Ws(e) {
1647
1568
  if (!e.startsWith("data:") || !e.includes(","))
1648
1569
  return { ok: !1, error: "Page image must be a complete data:image/* URL, not bare base64." };
1649
1570
  const [t, s] = e.slice(5).split(",", 2), n = t.split(";").map((a) => a.trim()).filter(Boolean), r = n[0] ?? "";
@@ -1654,7 +1575,7 @@ function Xs(e) {
1654
1575
  const i = s.replace(/[ \t\r\n\f]+/g, "");
1655
1576
  if (!/^[A-Za-z0-9+/]*={0,2}$/.test(i))
1656
1577
  return { ok: !1, error: "Page image data URL has invalid base64." };
1657
- const o = Js(i);
1578
+ const o = js(i);
1658
1579
  return o === null ? { ok: !1, error: "Page image data URL has invalid base64." } : o === 0 ? { ok: !1, error: "Page image is empty." } : {
1659
1580
  ok: !0,
1660
1581
  mimeType: r,
@@ -1662,22 +1583,22 @@ function Xs(e) {
1662
1583
  dataUrl: `data:${r};base64,${i}`
1663
1584
  };
1664
1585
  }
1665
- function Js(e) {
1586
+ function js(e) {
1666
1587
  if (e.length === 0 || e.length % 4 !== 0)
1667
1588
  return null;
1668
1589
  const t = e.length - e.replace(/=+$/, "").length;
1669
1590
  return t > 2 ? null : e.length / 4 * 3 - t;
1670
1591
  }
1671
- function Ks(e) {
1592
+ function zs(e) {
1672
1593
  return (typeof e == "string" ? e.trim() : "") || "Page image";
1673
1594
  }
1674
- function Vs(e) {
1595
+ function Gs(e) {
1675
1596
  try {
1676
1597
  e();
1677
1598
  } catch {
1678
1599
  }
1679
1600
  }
1680
- function Ut(e) {
1601
+ function Xs(e) {
1681
1602
  return new Promise((t, s) => {
1682
1603
  const n = new FileReader();
1683
1604
  n.onload = () => {
@@ -1689,59 +1610,100 @@ function Ut(e) {
1689
1610
  }, n.onerror = () => s(n.error ?? new Error("Failed to read Pluno user file")), n.readAsDataURL(e);
1690
1611
  });
1691
1612
  }
1692
- function Ys(e, t) {
1693
- return `data:${e};base64,`.length + Math.ceil(t / 3) * 4;
1694
- }
1695
- async function le(e) {
1696
- const t = Object.getPrototypeOf(async function() {
1697
- }).constructor, s = e.timeoutMs ?? Bs, n = Date.now(), r = [];
1698
- let i;
1699
- const o = {
1613
+ async function oe(e, t) {
1614
+ const s = Object.getPrototypeOf(async function() {
1615
+ }).constructor, n = e.timeoutMs ?? Os, r = Date.now(), i = [];
1616
+ let o;
1617
+ const a = {
1700
1618
  log: console.log,
1701
1619
  info: console.info,
1702
1620
  warn: console.warn,
1703
1621
  error: console.error
1704
- }, a = (u) => (...c) => {
1705
- r.push({ level: u, args: c }), o[u](...c);
1622
+ }, c = (l) => (...d) => {
1623
+ i.push({ level: l, args: d }), a[l](...d);
1706
1624
  };
1707
- console.log = a("log"), console.info = a("info"), console.warn = a("warn"), console.error = a("error");
1625
+ console.log = c("log"), console.info = c("info"), console.warn = c("warn"), console.error = c("error");
1708
1626
  try {
1709
- const u = /* @__PURE__ */ Symbol("execute_code_timeout"), c = await Promise.race([
1710
- new t(e.javascript)(),
1711
- new Promise((l) => {
1712
- i = window.setTimeout(() => l(u), s);
1627
+ const l = /* @__PURE__ */ Symbol("execute_code_timeout"), d = await Promise.race([
1628
+ new s("sandboxFiles", e.javascript)(t?.value),
1629
+ new Promise((p) => {
1630
+ o = window.setTimeout(() => p(l), n);
1713
1631
  })
1714
1632
  ]);
1715
- return c === u ? Zs(s) : {
1633
+ return d === l ? Ks(n) : {
1716
1634
  ok: !0,
1717
- result: c,
1718
- console: r,
1635
+ result: d,
1636
+ console: i,
1719
1637
  metadata: {
1720
- durationMs: Date.now() - n,
1638
+ durationMs: Date.now() - r,
1721
1639
  url: location.href,
1722
1640
  origin: location.origin
1723
1641
  }
1724
1642
  };
1725
- } catch (u) {
1643
+ } catch (l) {
1726
1644
  return {
1727
1645
  ok: !1,
1728
- console: r,
1646
+ console: i,
1729
1647
  exception: {
1730
- name: u instanceof Error ? u.name : "Error",
1731
- message: u instanceof Error ? u.message : String(u),
1732
- stack: u instanceof Error ? u.stack : void 0
1648
+ name: l instanceof Error ? l.name : "Error",
1649
+ message: l instanceof Error ? l.message : String(l),
1650
+ stack: l instanceof Error ? l.stack : void 0
1733
1651
  },
1734
1652
  metadata: {
1735
- durationMs: Date.now() - n,
1653
+ durationMs: Date.now() - r,
1736
1654
  url: location.href,
1737
1655
  origin: location.origin
1738
1656
  }
1739
1657
  };
1740
1658
  } finally {
1741
- i !== void 0 && window.clearTimeout(i), console.log = o.log, console.info = o.info, console.warn = o.warn, console.error = o.error;
1659
+ t?.deactivate(), o !== void 0 && window.clearTimeout(o), console.log = a.log, console.info = a.info, console.warn = a.warn, console.error = a.error;
1742
1660
  }
1743
1661
  }
1744
- function Zs(e) {
1662
+ function Js(e, t) {
1663
+ if (!e || typeof e != "object")
1664
+ return;
1665
+ const s = e.sandboxFilesToken;
1666
+ if (typeof s != "string" || !s)
1667
+ return;
1668
+ let n = !0;
1669
+ const r = () => {
1670
+ if (!n)
1671
+ throw new Error("sandboxFiles is only available during browser-code execution");
1672
+ }, i = async (a, c) => await as(`${t.replace(/\/$/, "")}${a}`, c);
1673
+ return {
1674
+ value: Object.freeze({
1675
+ upload: async (a) => {
1676
+ if (r(), !(a instanceof Blob))
1677
+ throw new TypeError("sandboxFiles.upload expects a File or Blob");
1678
+ const c = a instanceof File && a.name ? a.name : "file", l = `?name=${encodeURIComponent(c)}&size_bytes=${a.size}`, d = await i(`/api/product-agent/attachments/sandbox-files${l}`, {
1679
+ method: "PUT",
1680
+ headers: { Authorization: `Bearer ${s}` },
1681
+ body: a
1682
+ });
1683
+ if (!d.ok)
1684
+ throw new Error(`sandboxFiles.upload failed (${d.status})`);
1685
+ return String((await d.json()).path);
1686
+ },
1687
+ download: async (a) => {
1688
+ r();
1689
+ const c = await i(
1690
+ `/api/product-agent/attachments/sandbox-files?path=${encodeURIComponent(a)}`,
1691
+ { headers: { Authorization: `Bearer ${s}` } }
1692
+ );
1693
+ if (!c.ok)
1694
+ throw new Error(`sandboxFiles.download failed (${c.status})`);
1695
+ const l = await c.blob(), p = (c.headers.get("content-disposition") ?? "").match(/filename="([^"]+)"/i)?.[1];
1696
+ return new File([l], p || a.split("/").pop() || "file", {
1697
+ type: l.type
1698
+ });
1699
+ }
1700
+ }),
1701
+ deactivate: () => {
1702
+ n = !1;
1703
+ }
1704
+ };
1705
+ }
1706
+ function Ks(e) {
1745
1707
  return {
1746
1708
  ok: !1,
1747
1709
  exception: {
@@ -1755,18 +1717,33 @@ function Zs(e) {
1755
1717
  }
1756
1718
  };
1757
1719
  }
1758
- function Qs(e) {
1720
+ function Vs(e) {
1759
1721
  return e.replace(/\/+$/, "");
1760
1722
  }
1761
- function tn(e, t = location.origin) {
1723
+ function Ys(e) {
1724
+ const t = {
1725
+ sidepanel: "extension_sidepanel",
1726
+ browser_extension_page_ui: "extension_widget",
1727
+ sdk_preview_widget: "extension_widget",
1728
+ browser_extension_sdk_preview: "extension_widget",
1729
+ "sdk-preview": "extension_widget",
1730
+ main_chat: "main_web_chat",
1731
+ automation_run: "automation"
1732
+ };
1733
+ return e && e in t ? t[e] : e ?? "embedded_custom_ui";
1734
+ }
1735
+ function Zs(e) {
1736
+ return e === "pluno" ? "scheduled_continuation" : e ?? "user";
1737
+ }
1738
+ function Qs(e, t = location.origin) {
1762
1739
  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;
1763
1740
  }
1764
- function en(e) {
1741
+ function tn(e) {
1765
1742
  const t = new URL("/api/product-agent/embed/ws", e);
1766
1743
  return t.protocol = t.protocol === "https:" ? "wss:" : "ws:", t.toString();
1767
1744
  }
1768
- function R() {
1769
- const e = Ue();
1745
+ function _() {
1746
+ const e = _e();
1770
1747
  return {
1771
1748
  url: location.href,
1772
1749
  title: document.title,
@@ -1774,21 +1751,21 @@ function R() {
1774
1751
  ...e ? { plunoProductAgentUi: e } : {}
1775
1752
  };
1776
1753
  }
1777
- function sn() {
1754
+ function en() {
1778
1755
  return {
1779
1756
  pageUrl: location.href,
1780
1757
  pageTitle: document.title,
1781
- htmlContent: Wt()
1758
+ htmlContent: qt()
1782
1759
  };
1783
1760
  }
1784
- function nn(e) {
1785
- return et.add(e), Y || (Y = rn()), () => {
1786
- et.delete(e), et.size === 0 && (Y?.(), Y = null);
1761
+ function sn(e) {
1762
+ return tt.add(e), Y || (Y = nn()), () => {
1763
+ tt.delete(e), tt.size === 0 && (Y?.(), Y = null);
1787
1764
  };
1788
1765
  }
1789
- function rn() {
1766
+ function nn() {
1790
1767
  const e = () => {
1791
- for (const i of Array.from(et))
1768
+ for (const i of Array.from(tt))
1792
1769
  i();
1793
1770
  }, t = window.history.pushState.bind(window.history), s = window.history.replaceState.bind(window.history), n = ((...i) => {
1794
1771
  const o = t(...i);
@@ -1801,35 +1778,35 @@ function rn() {
1801
1778
  window.history.pushState === n && (window.history.pushState = t), window.history.replaceState === r && (window.history.replaceState = s), window.removeEventListener("popstate", e), window.removeEventListener("hashchange", e);
1802
1779
  };
1803
1780
  }
1804
- function on() {
1805
- return Ue()?.surface === "browser_extension_sdk_preview";
1781
+ function rn() {
1782
+ return _e()?.surface === "browser_extension_sdk_preview";
1806
1783
  }
1807
- function Wt() {
1784
+ function qt() {
1808
1785
  if (!document.body)
1809
1786
  return "";
1810
- const e = [], t = [], s = (g, T) => {
1811
- const y = B(T);
1812
- !y || t.includes(y) || (e.push([g, y]), t.push(y));
1787
+ const e = [], t = [], s = (h, m) => {
1788
+ const T = B(m);
1789
+ !T || t.includes(T) || (e.push([h, T]), t.push(T));
1813
1790
  };
1814
1791
  s("Selected text", window.getSelection()?.toString() ?? "");
1815
1792
  const n = "[role='dialog'], [role='alertdialog'], dialog[open], [aria-modal='true']", r = Array.from(document.querySelectorAll(n)).filter(
1816
- (g) => Me(g) && !g.parentElement?.closest(n)
1793
+ (h) => Ee(h) && !h.parentElement?.closest(n)
1817
1794
  );
1818
- for (const g of r.slice(0, 3))
1819
- s("Active overlay", bt($(g), t));
1820
- const i = an(), o = i ? bt($(i), t) : "";
1821
- s("Main page content", o), s("Additional visible page text", bt($(document.body), t));
1822
- const a = e.map(([g, T]) => `${g}:
1823
- ${T}`).join(`
1795
+ for (const h of r.slice(0, 3))
1796
+ s("Active overlay", bt(W(h), t));
1797
+ const i = on(), o = i ? bt(W(i), t) : "";
1798
+ s("Main page content", o), s("Additional visible page text", bt(W(document.body), t));
1799
+ const a = e.map(([h, m]) => `${h}:
1800
+ ${m}`).join(`
1824
1801
 
1825
- `).trim().slice(0, 12e3), u = cn(r, i).trim(), c = `Simplified DOM outline:
1826
- `, l = `
1802
+ `).trim().slice(0, 12e3), c = an(r, i).trim(), l = `Simplified DOM outline:
1803
+ `, d = `
1827
1804
 
1828
1805
  Visible page text:
1829
- `, h = 12e3 - c.length - l.length, f = Math.min(a.length, 7900), p = u.slice(0, h - f), d = a.slice(0, h - p.length);
1830
- return `${c}${p}${l}${d}`;
1806
+ `, p = 12e3 - l.length - d.length, y = Math.min(a.length, 7900), f = c.slice(0, p - y), u = a.slice(0, p - f.length);
1807
+ return `${l}${f}${d}${u}`;
1831
1808
  }
1832
- function $(e) {
1809
+ function W(e) {
1833
1810
  return e.innerText ?? e.textContent ?? "";
1834
1811
  }
1835
1812
  function B(e) {
@@ -1846,14 +1823,14 @@ function bt(e, t) {
1846
1823
  s = s.replace(n, "");
1847
1824
  return B(s);
1848
1825
  }
1849
- function Me(e) {
1826
+ function Ee(e) {
1850
1827
  const t = window.getComputedStyle(e);
1851
1828
  return t.display !== "none" && t.visibility !== "hidden" && e.getClientRects().length > 0;
1852
1829
  }
1853
- function an() {
1854
- return Array.from(document.querySelectorAll("main, [role='main'], article")).filter(Me).sort((e, t) => $(t).length - $(e).length)[0] ?? null;
1830
+ function on() {
1831
+ return Array.from(document.querySelectorAll("main, [role='main'], article")).filter(Ee).sort((e, t) => W(t).length - W(e).length)[0] ?? null;
1855
1832
  }
1856
- function cn(e, t) {
1833
+ function an(e, t) {
1857
1834
  const s = /* @__PURE__ */ new Set([
1858
1835
  "main",
1859
1836
  "nav",
@@ -1917,7 +1894,7 @@ function cn(e, t) {
1917
1894
  "tab",
1918
1895
  "menuitem",
1919
1896
  "option"
1920
- ]), u = [
1897
+ ]), c = [
1921
1898
  "role",
1922
1899
  "aria-label",
1923
1900
  "aria-current",
@@ -1933,95 +1910,95 @@ function cn(e, t) {
1933
1910
  "data-test",
1934
1911
  "data-qa",
1935
1912
  "data-cy"
1936
- ], c = ["aria-label", "placeholder", "data-testid", "data-test", "data-qa", "data-cy"], { priorityElements: l, priorityTargets: h } = ln(), f = new Set(e);
1937
- t && f.add(t);
1938
- let p = 0;
1939
- const d = (w) => {
1940
- const U = w.getAttribute("role");
1913
+ ], l = ["aria-label", "placeholder", "data-testid", "data-test", "data-qa", "data-cy"], { priorityElements: d, priorityTargets: p } = cn(), y = new Set(e);
1914
+ t && y.add(t);
1915
+ let f = 0;
1916
+ const u = (I) => {
1917
+ const U = I.getAttribute("role");
1941
1918
  return U && !o.has(U) ? U : "";
1942
- }, g = (w) => {
1943
- const U = w.getAttribute("data-testid") || w.getAttribute("data-test") || w.getAttribute("data-qa") || w.getAttribute("data-cy") || "";
1944
- return `${w.tagName.toLowerCase()}|${d(w)}|${U}`;
1945
- }, T = (w, U, q) => {
1946
- const b = (S, ut) => {
1947
- const k = S.tagName.toLowerCase(), dt = window.getComputedStyle(S), z = l.has(S);
1948
- if (p >= 1e3 && !z || q.has(S) || i.has(k) || S.matches(".pluno-pa-widget-host, [data-pluno-product-agent-widget]") || dt.display === "none" || dt.visibility === "hidden")
1919
+ }, h = (I) => {
1920
+ const U = I.getAttribute("data-testid") || I.getAttribute("data-test") || I.getAttribute("data-qa") || I.getAttribute("data-cy") || "";
1921
+ return `${I.tagName.toLowerCase()}|${u(I)}|${U}`;
1922
+ }, m = (I, U, q) => {
1923
+ const R = (S, ct) => {
1924
+ const E = S.tagName.toLowerCase(), lt = window.getComputedStyle(S), z = d.has(S);
1925
+ if (f >= 1e3 && !z || q.has(S) || i.has(E) || S.matches(".pluno-pa-widget-host, [data-pluno-product-agent-widget]") || lt.display === "none" || lt.visibility === "hidden")
1949
1926
  return { lines: [], hasUsefulContent: !1, textPreview: "", containsTextElement: !1 };
1950
- p += 1;
1951
- const Jt = d(S), G = Pe(S), Je = a.has(Jt) || ["button", "input", "textarea", "select", "iframe", "canvas"].includes(k) || k === "a" && S.hasAttribute("href"), ht = Array.from(S.children).filter((m) => m instanceof HTMLElement), X = /* @__PURE__ */ new Map();
1952
- for (const m of ht) {
1953
- const A = g(m);
1954
- X.set(A, (X.get(A) ?? 0) + 1);
1927
+ f += 1;
1928
+ const zt = u(S), G = Re(S), je = a.has(zt) || ["button", "input", "textarea", "select", "iframe", "canvas"].includes(E) || E === "a" && S.hasAttribute("href"), ut = Array.from(S.children).filter((g) => g instanceof HTMLElement), X = /* @__PURE__ */ new Map();
1929
+ for (const g of ut) {
1930
+ const w = h(g);
1931
+ X.set(w, (X.get(w) ?? 0) + 1);
1955
1932
  }
1956
- const pt = /* @__PURE__ */ new Map(), Kt = /* @__PURE__ */ new Map();
1957
- for (const m of ht) {
1958
- const A = g(m), D = Kt.get(A) ?? 0;
1959
- Kt.set(A, D + 1), (X.get(A) ?? 0) > 8 && D >= 6 && !l.has(m) && pt.set(A, (pt.get(A) ?? 0) + 1);
1933
+ const dt = /* @__PURE__ */ new Map(), Gt = /* @__PURE__ */ new Map();
1934
+ for (const g of ut) {
1935
+ const w = h(g), D = Gt.get(w) ?? 0;
1936
+ Gt.set(w, D + 1), (X.get(w) ?? 0) > 8 && D >= 6 && !d.has(g) && dt.set(w, (dt.get(w) ?? 0) + 1);
1960
1937
  }
1961
- const Vt = /* @__PURE__ */ new Map(), Yt = /* @__PURE__ */ new Set(), ft = [], Zt = [];
1962
- for (const m of ht) {
1963
- const A = g(m), D = X.get(A) ?? 0, ee = Vt.get(A) ?? 0;
1964
- if (Vt.set(A, ee + 1), D > 8 && ee >= 6 && !l.has(m)) {
1965
- Yt.has(A) || (ft.push([`… ${pt.get(A) ?? 0} similar siblings omitted`]), Yt.add(A));
1938
+ const Xt = /* @__PURE__ */ new Map(), Jt = /* @__PURE__ */ new Set(), ht = [], Kt = [];
1939
+ for (const g of ut) {
1940
+ const w = h(g), D = X.get(w) ?? 0, Zt = Xt.get(w) ?? 0;
1941
+ if (Xt.set(w, Zt + 1), D > 8 && Zt >= 6 && !d.has(g)) {
1942
+ Jt.has(w) || (ht.push([`… ${dt.get(w) ?? 0} similar siblings omitted`]), Jt.add(w));
1966
1943
  continue;
1967
1944
  }
1968
- const se = b(m, ut);
1969
- Zt.push(se), ft.push(se.lines);
1945
+ const Qt = R(g, ct);
1946
+ Kt.push(Qt), ht.push(Qt.lines);
1970
1947
  }
1971
- const gt = [];
1948
+ const pt = [];
1972
1949
  if (S.shadowRoot)
1973
- for (const m of Array.from(S.shadowRoot.children))
1974
- m instanceof HTMLElement && gt.push(b(m, ut + 1));
1975
- const J = [...Zt, ...gt], mt = G.length > 0 || Je || J.some((m) => m.hasUsefulContent), Qt = B(
1976
- [G, ...J.map((m) => m.textPreview)].filter(Boolean).join(" ")
1977
- ).slice(0, 180), Ke = S.hasAttribute("contenteditable") && (G.length > 0 || !S.querySelector("[contenteditable]")), te = c.some((m) => S.hasAttribute(m)) || !!Jt || Ke, yt = (S.getClientRects().length > 0 || dt.display === "contents") && (s.has(k) || te || z) && (mt || z) && (!r.has(k) || mt || te || z), Tt = yt ? 1 : 0, H = [];
1978
- if (yt) {
1979
- const m = J.some((D) => D.containsTextElement), A = n.has(k) && !m ? Qt : G;
1980
- H.push(Ce(S, u, o, A.slice(0, 180)));
1950
+ for (const g of Array.from(S.shadowRoot.children))
1951
+ g instanceof HTMLElement && pt.push(R(g, ct + 1));
1952
+ const J = [...Kt, ...pt], ft = G.length > 0 || je || J.some((g) => g.hasUsefulContent), Vt = B(
1953
+ [G, ...J.map((g) => g.textPreview)].filter(Boolean).join(" ")
1954
+ ).slice(0, 180), ze = S.hasAttribute("contenteditable") && (G.length > 0 || !S.querySelector("[contenteditable]")), Yt = l.some((g) => S.hasAttribute(g)) || !!zt || ze, gt = (S.getClientRects().length > 0 || lt.display === "contents") && (s.has(E) || Yt || z) && (ft || z) && (!r.has(E) || ft || Yt || z), mt = gt ? 1 : 0, H = [];
1955
+ if (gt) {
1956
+ const g = J.some((D) => D.containsTextElement), w = n.has(E) && !g ? Vt : G;
1957
+ H.push(ke(S, c, o, w.slice(0, 180)));
1981
1958
  }
1982
- for (const m of ft)
1983
- H.push(...Z(m, Tt));
1984
- const It = gt.flatMap((m) => m.lines);
1985
- if (It.length > 0) {
1986
- const m = It.slice(0, 20);
1987
- It.length > m.length && m.push("… shadow DOM omitted");
1988
- const A = k.includes("tooltip") || k.includes("popper") || k.includes("loader");
1989
- if (ut < 2 && !A) {
1990
- const D = yt ? "#shadow-root" : `${k} #shadow-root`;
1991
- H.push(...Z([D, ...Z(m, 1)], Tt));
1959
+ for (const g of ht)
1960
+ H.push(...Z(g, mt));
1961
+ const yt = pt.flatMap((g) => g.lines);
1962
+ if (yt.length > 0) {
1963
+ const g = yt.slice(0, 20);
1964
+ yt.length > g.length && g.push("… shadow DOM omitted");
1965
+ const w = E.includes("tooltip") || E.includes("popper") || E.includes("loader");
1966
+ if (ct < 2 && !w) {
1967
+ const D = gt ? "#shadow-root" : `${E} #shadow-root`;
1968
+ H.push(...Z([D, ...Z(g, 1)], mt));
1992
1969
  } else
1993
- H.push(...Z(m, Tt));
1970
+ H.push(...Z(g, mt));
1994
1971
  }
1995
1972
  return {
1996
1973
  lines: H,
1997
- hasUsefulContent: mt,
1998
- textPreview: Qt,
1999
- containsTextElement: n.has(k) || J.some((m) => m.containsTextElement)
1974
+ hasUsefulContent: ft,
1975
+ textPreview: Vt,
1976
+ containsTextElement: n.has(E) || J.some((g) => g.containsTextElement)
2000
1977
  };
2001
1978
  };
2002
- return [`--- ${U} ---`, ...b(w, 0).lines].join(`
1979
+ return [`--- ${U} ---`, ...R(I, 0).lines].join(`
2003
1980
  `);
2004
- }, y = [], N = B(window.getSelection()?.toString() ?? "");
2005
- N && y.push(`--- selected text ---
2006
- ${JSON.stringify(N)}`), h.length > 0 && y.push(un(h, s, u, o));
2007
- for (const w of e.slice(0, 3))
2008
- y.push(T(w, "active overlay DOM", /* @__PURE__ */ new Set()));
2009
- if (t && y.push(T(t, "main DOM", /* @__PURE__ */ new Set())), document.body) {
2010
- const w = t || e.length ? "other visible DOM" : "visible DOM";
2011
- y.push(T(document.body, w, f));
2012
- }
2013
- return y.join(`
1981
+ }, T = [], x = B(window.getSelection()?.toString() ?? "");
1982
+ x && T.push(`--- selected text ---
1983
+ ${JSON.stringify(x)}`), p.length > 0 && T.push(ln(p, s, c, o));
1984
+ for (const I of e.slice(0, 3))
1985
+ T.push(m(I, "active overlay DOM", /* @__PURE__ */ new Set()));
1986
+ if (t && T.push(m(t, "main DOM", /* @__PURE__ */ new Set())), document.body) {
1987
+ const I = t || e.length ? "other visible DOM" : "visible DOM";
1988
+ T.push(m(document.body, I, y));
1989
+ }
1990
+ return T.join(`
2014
1991
 
2015
1992
  `);
2016
1993
  }
2017
- function Ce(e, t, s, n) {
1994
+ function ke(e, t, s, n) {
2018
1995
  const r = e.tagName.toLowerCase();
2019
1996
  let i = r;
2020
1997
  const o = e.getAttribute("id");
2021
- o && dn(o) && (i += `#${o}`);
1998
+ o && un(o) && (i += `#${o}`);
2022
1999
  for (const a of t) {
2023
- const u = e.getAttribute(a);
2024
- u && u.length <= 160 && (a !== "role" || !s.has(u)) && (i += `[${a}=${JSON.stringify(u)}]`);
2000
+ const c = e.getAttribute(a);
2001
+ c && c.length <= 160 && (a !== "role" || !s.has(c)) && (i += `[${a}=${JSON.stringify(c)}]`);
2025
2002
  }
2026
2003
  if (r === "a" || r === "iframe") {
2027
2004
  const a = e.getAttribute(r === "a" ? "href" : "src");
@@ -2031,20 +2008,20 @@ function Ce(e, t, s, n) {
2031
2008
  e.hasAttribute(a) && (i += `[${a}]`);
2032
2009
  return `${i}${n ? ` ${JSON.stringify(n)}` : ""}`;
2033
2010
  }
2034
- function ln() {
2035
- const e = /* @__PURE__ */ new Set(), t = /* @__PURE__ */ new Map(), s = (a, u) => {
2011
+ function cn() {
2012
+ const e = /* @__PURE__ */ new Set(), t = /* @__PURE__ */ new Map(), s = (a, c) => {
2036
2013
  if (!a)
2037
2014
  return;
2038
- const c = window.getComputedStyle(a);
2039
- if (c.display === "none" || c.visibility === "hidden")
2015
+ const l = window.getComputedStyle(a);
2016
+ if (l.display === "none" || l.visibility === "hidden")
2040
2017
  return;
2041
- const l = t.get(a) ?? /* @__PURE__ */ new Set();
2042
- l.add(u), t.set(a, l);
2043
- let h = a;
2044
- for (; h; ) {
2045
- e.add(h);
2046
- const f = h.getRootNode();
2047
- h = h.parentElement ?? (f instanceof ShadowRoot && f.host instanceof HTMLElement ? f.host : null);
2018
+ const d = t.get(a) ?? /* @__PURE__ */ new Set();
2019
+ d.add(c), t.set(a, d);
2020
+ let p = a;
2021
+ for (; p; ) {
2022
+ e.add(p);
2023
+ const y = p.getRootNode();
2024
+ p = p.parentElement ?? (y instanceof ShadowRoot && y.host instanceof HTMLElement ? y.host : null);
2048
2025
  }
2049
2026
  };
2050
2027
  let n = document.activeElement instanceof HTMLElement ? document.activeElement : null;
@@ -2052,7 +2029,7 @@ function ln() {
2052
2029
  n = n.shadowRoot.activeElement;
2053
2030
  n !== document.body && n !== document.documentElement && s(n, "focused");
2054
2031
  const r = window.getSelection();
2055
- r && !r.isCollapsed && (s(ue(r.anchorNode), "selected text"), s(ue(r.focusNode), "selected text"));
2032
+ r && !r.isCollapsed && (s(ae(r.anchorNode), "selected text"), s(ae(r.focusNode), "selected text"));
2056
2033
  const i = [
2057
2034
  ["[aria-selected='true']", "selected"],
2058
2035
  ["[aria-current]:not([aria-current='false'])", "current"],
@@ -2062,41 +2039,41 @@ function ln() {
2062
2039
  ["[open]", "open"]
2063
2040
  ], o = [document];
2064
2041
  for (let a = 0; a < o.length; a += 1) {
2065
- const u = o[a];
2066
- for (const [c, l] of i)
2067
- for (const h of Array.from(u.querySelectorAll(c)))
2068
- s(h, l);
2069
- for (const c of Array.from(u.querySelectorAll("*")))
2070
- c.shadowRoot && o.push(c.shadowRoot);
2042
+ const c = o[a];
2043
+ for (const [l, d] of i)
2044
+ for (const p of Array.from(c.querySelectorAll(l)))
2045
+ s(p, d);
2046
+ for (const l of Array.from(c.querySelectorAll("*")))
2047
+ l.shadowRoot && o.push(l.shadowRoot);
2071
2048
  }
2072
2049
  return {
2073
2050
  priorityElements: e,
2074
- priorityTargets: Array.from(t, ([a, u]) => ({ element: a, labels: Array.from(u) }))
2051
+ priorityTargets: Array.from(t, ([a, c]) => ({ element: a, labels: Array.from(c) }))
2075
2052
  };
2076
2053
  }
2077
- function un(e, t, s, n) {
2054
+ function ln(e, t, s, n) {
2078
2055
  const r = ["--- active/current elements ---"];
2079
2056
  for (const i of e) {
2080
2057
  const o = [];
2081
2058
  let a = i.element;
2082
2059
  for (; a; ) {
2083
- const l = a.tagName.toLowerCase();
2084
- (a === i.element || t.has(l) || a.hasAttribute("id") || a.hasAttribute("role") || a.hasAttribute("aria-label")) && o.unshift(a);
2085
- const h = a.getRootNode();
2086
- a = a.parentElement ?? (h instanceof ShadowRoot && h.host instanceof HTMLElement ? h.host : null);
2060
+ const d = a.tagName.toLowerCase();
2061
+ (a === i.element || t.has(d) || a.hasAttribute("id") || a.hasAttribute("role") || a.hasAttribute("aria-label")) && o.unshift(a);
2062
+ const p = a.getRootNode();
2063
+ a = a.parentElement ?? (p instanceof ShadowRoot && p.host instanceof HTMLElement ? p.host : null);
2087
2064
  }
2088
- const u = o.length > 6 ? [o[0], ...o.slice(-5)] : o, c = u.map((l, h) => Ce(
2089
- l,
2065
+ const c = o.length > 6 ? [o[0], ...o.slice(-5)] : o, l = c.map((d, p) => ke(
2066
+ d,
2090
2067
  s,
2091
2068
  n,
2092
- h === u.length - 1 ? Pe(l).slice(0, 180) : ""
2069
+ p === c.length - 1 ? Re(d).slice(0, 180) : ""
2093
2070
  ));
2094
- o.length > u.length && c.splice(1, 0, "…"), r.push(`${i.labels.join(", ")}: ${c.join(" > ")}`);
2071
+ o.length > c.length && l.splice(1, 0, "…"), r.push(`${i.labels.join(", ")}: ${l.join(" > ")}`);
2095
2072
  }
2096
2073
  return r.join(`
2097
2074
  `);
2098
2075
  }
2099
- function ue(e) {
2076
+ function ae(e) {
2100
2077
  return e instanceof HTMLElement ? e : e?.parentElement instanceof HTMLElement ? e.parentElement : null;
2101
2078
  }
2102
2079
  function Z(e, t) {
@@ -2105,17 +2082,17 @@ function Z(e, t) {
2105
2082
  const s = " ".repeat(t);
2106
2083
  return e.map((n) => `${s}${n}`);
2107
2084
  }
2108
- function Pe(e) {
2085
+ function Re(e) {
2109
2086
  return B(
2110
2087
  Array.from(e.childNodes).filter((t) => t.nodeType === Node.TEXT_NODE).map((t) => t.textContent ?? "").join(" ")
2111
2088
  );
2112
2089
  }
2113
- function dn(e) {
2090
+ function un(e) {
2114
2091
  return e.length <= 64 && /^[A-Za-z_][A-Za-z0-9_:.-]*$/.test(e) && !/[a-f0-9]{12,}/i.test(e) && !/:r[0-9a-z]+:/i.test(e);
2115
2092
  }
2116
- function Ue() {
2117
- const e = document.querySelector(ne);
2118
- if (!(e ?? document.querySelector(Ct)))
2093
+ function _e() {
2094
+ const e = document.querySelector(te);
2095
+ if (!(e ?? document.querySelector(Mt)))
2119
2096
  return;
2120
2097
  const s = e ? "browser_extension_sdk_preview" : "embedded_widget";
2121
2098
  return {
@@ -2124,28 +2101,28 @@ function Ue() {
2124
2101
  selectors: [
2125
2102
  {
2126
2103
  name: "widget_host",
2127
- selector: s === "browser_extension_sdk_preview" ? ne : Ct,
2104
+ selector: s === "browser_extension_sdk_preview" ? te : Mt,
2128
2105
  description: "Finds Pluno's shadow-host element in the host page DOM."
2129
2106
  },
2130
2107
  {
2131
2108
  name: "widget_root",
2132
- selector: ls,
2109
+ selector: cs,
2133
2110
  description: "Finds Pluno's widget root inside the widget host shadow root."
2134
2111
  },
2135
2112
  {
2136
2113
  name: "widget_panel",
2137
- selector: us,
2114
+ selector: ls,
2138
2115
  description: "Finds Pluno's open chat panel inside the widget host shadow root."
2139
2116
  },
2140
2117
  {
2141
2118
  name: "widget_timeline",
2142
- selector: ds,
2119
+ selector: us,
2143
2120
  description: "Finds Pluno's chat timeline inside the widget host shadow root."
2144
2121
  }
2145
2122
  ]
2146
2123
  };
2147
2124
  }
2148
- function hn(e) {
2125
+ function dn(e) {
2149
2126
  try {
2150
2127
  const t = JSON.parse(e);
2151
2128
  return t && typeof t == "object" ? t : { type: "error", message: "Invalid server event" };
@@ -2153,16 +2130,16 @@ function hn(e) {
2153
2130
  return { type: "error", message: "Invalid server event" };
2154
2131
  }
2155
2132
  }
2156
- function de(e, t) {
2133
+ function ce(e, t) {
2157
2134
  if (!e || typeof e != "object")
2158
2135
  return [];
2159
2136
  const s = e[t];
2160
2137
  return Array.isArray(s) ? s.filter((n) => typeof n == "string" && n.trim().length > 0) : [];
2161
2138
  }
2162
- function pn(e) {
2139
+ function hn(e) {
2163
2140
  return Array.isArray(e) ? e.filter((t) => typeof t == "string" && t.trim().length > 0) : [];
2164
2141
  }
2165
- function fn(e) {
2142
+ function pn(e) {
2166
2143
  if (!e || typeof e != "object")
2167
2144
  return null;
2168
2145
  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;
@@ -2173,13 +2150,13 @@ function fn(e) {
2173
2150
  ...a !== null ? { scribbleStyle: a } : {}
2174
2151
  };
2175
2152
  }
2176
- function gn(e) {
2153
+ function fn(e) {
2177
2154
  if (!e || typeof e != "object")
2178
2155
  return null;
2179
2156
  const t = e.javascript;
2180
2157
  return typeof t != "string" || !t.trim() ? null : { javascript: t };
2181
2158
  }
2182
- function mn(e, t) {
2159
+ function gn(e, t) {
2183
2160
  return t ? e && typeof e == "object" ? {
2184
2161
  ...e,
2185
2162
  helperError: t
@@ -2189,20 +2166,20 @@ function mn(e, t) {
2189
2166
  helperError: t
2190
2167
  } : e;
2191
2168
  }
2192
- function yn(e) {
2169
+ function mn(e) {
2193
2170
  if (!e || typeof e != "object")
2194
2171
  return e;
2195
2172
  const t = e;
2196
2173
  return typeof t.exception?.message == "string" ? t.exception.message : typeof t.error == "string" ? t.error : e;
2197
2174
  }
2198
- function Tn() {
2175
+ function yn() {
2199
2176
  const e = "pluno.productAgent.clientId", t = window.localStorage.getItem(e);
2200
2177
  if (t)
2201
2178
  return t;
2202
2179
  const s = crypto.randomUUID();
2203
2180
  return window.localStorage.setItem(e, s), s;
2204
2181
  }
2205
- function Q() {
2182
+ function Et() {
2206
2183
  return crypto.randomUUID();
2207
2184
  }
2208
2185
  function In(e) {
@@ -2216,23 +2193,23 @@ function In(e) {
2216
2193
  avatarUrl: typeof t.avatarUrl == "string" ? t.avatarUrl : null
2217
2194
  } : null;
2218
2195
  }
2219
- function wn(e, t) {
2220
- return Array.isArray(e) ? Ot(
2221
- vt(
2222
- e.map((s) => De(s, t)).filter((s) => s !== null)
2196
+ function Tn(e, t) {
2197
+ return Array.isArray(e) ? Dt(
2198
+ xt(
2199
+ e.map((s) => Me(s, t)).filter((s) => s !== null)
2223
2200
  )
2224
2201
  ) : [];
2225
2202
  }
2226
- function An(e) {
2203
+ function wn(e) {
2227
2204
  return Array.isArray(e) ? e.flatMap((t) => {
2228
2205
  if (!t || typeof t != "object")
2229
2206
  return [];
2230
- const s = t, n = E(s, "id"), r = E(s, "createdAt"), i = E(s, "updatedAt"), o = E(s, "lastActiveAt");
2207
+ const s = t, n = b(s, "id"), r = b(s, "createdAt"), i = b(s, "updatedAt"), o = b(s, "lastActiveAt");
2231
2208
  return !n || !r || !i || !o ? [] : [
2232
2209
  {
2233
2210
  id: n,
2234
- title: E(s, "title"),
2235
- firstUserMessage: E(s, "firstUserMessage"),
2211
+ title: b(s, "title"),
2212
+ firstUserMessage: b(s, "firstUserMessage"),
2236
2213
  currentPage: s.currentPage ?? null,
2237
2214
  createdAt: r,
2238
2215
  updatedAt: i,
@@ -2242,7 +2219,7 @@ function An(e) {
2242
2219
  ];
2243
2220
  }) : [];
2244
2221
  }
2245
- function De(e, t) {
2222
+ function Me(e, t) {
2246
2223
  if (!e || typeof e != "object")
2247
2224
  return null;
2248
2225
  const s = e, n = s.data;
@@ -2258,11 +2235,11 @@ function De(e, t) {
2258
2235
  id: String(s.id ?? crypto.randomUUID()),
2259
2236
  role: i,
2260
2237
  ...r.phase === "commentary" || r.phase === "final_answer" ? { phase: r.phase } : {},
2261
- content: Mn(r.content),
2238
+ content: _n(r.content),
2262
2239
  createdAt: typeof s.createdAt == "string" ? s.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
2263
- respondsToUserMessageId: O(r) ?? void 0,
2240
+ respondsToUserMessageId: v(r) ?? void 0,
2264
2241
  ...M(r) ? { runId: M(r) } : {},
2265
- attachments: Be(r.attachments, t)
2242
+ attachments: ve(r.attachments, t)
2266
2243
  };
2267
2244
  return i === "assistant" && typeof r.id == "string" && Object.defineProperty(o, "assistantDraftItemId", {
2268
2245
  value: r.id,
@@ -2273,37 +2250,37 @@ function De(e, t) {
2273
2250
  }), o;
2274
2251
  }
2275
2252
  if (r.type === "function_call_output") {
2276
- const i = En(r.output);
2253
+ const i = Sn(r.output);
2277
2254
  return i ? {
2278
2255
  id: String(s.id ?? crypto.randomUUID()),
2279
2256
  role: "tool",
2280
2257
  content: `Connect ${i.appName} to continue`,
2281
2258
  createdAt: typeof s.createdAt == "string" ? s.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
2282
- respondsToUserMessageId: O(r) ?? void 0,
2259
+ respondsToUserMessageId: v(r) ?? void 0,
2283
2260
  ...M(r) ? { runId: M(r) } : {},
2284
2261
  dataType: "function_call_output",
2285
2262
  toolName: "authenticate_pipedream_app",
2286
- callId: he(r) ?? void 0,
2263
+ callId: le(r) ?? void 0,
2287
2264
  integrationAuthRequest: i
2288
2265
  } : null;
2289
2266
  }
2290
2267
  return r.type === "function_call" || r.type === "tool_call" || r.type === "web_search_call" || r.type === "mcp_call" || r.type === "tab_lifecycle_decision" ? {
2291
2268
  id: String(s.id ?? crypto.randomUUID()),
2292
2269
  role: "tool",
2293
- content: r.type === "mcp_call" ? Sn(r) : bn(r),
2270
+ content: r.type === "mcp_call" ? An(r) : En(r),
2294
2271
  createdAt: typeof s.createdAt == "string" ? s.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
2295
- respondsToUserMessageId: O(r) ?? void 0,
2272
+ respondsToUserMessageId: v(r) ?? void 0,
2296
2273
  ...M(r) ? { runId: M(r) } : {},
2297
2274
  dataType: String(r.type),
2298
2275
  toolName: r.type === "tab_lifecycle_decision" ? "tab_lifecycle_decision" : typeof r.name == "string" ? r.name : void 0,
2299
- callId: he(r) ?? void 0,
2300
- loading: r.localExecutionStatus === "running"
2276
+ callId: le(r) ?? void 0,
2277
+ loading: r.localExecutionStatus === "queued" || r.localExecutionStatus === "running" ? !0 : typeof r.localExecutionStatus == "string" ? !1 : void 0
2301
2278
  } : r.type === "run_status" || r.type === "run_error" ? r.type === "run_error" && r.stage === "tool_execution" ? null : {
2302
2279
  id: String(s.id ?? crypto.randomUUID()),
2303
2280
  role: "system",
2304
- content: kn(r),
2281
+ content: bn(r),
2305
2282
  createdAt: typeof s.createdAt == "string" ? s.createdAt : (/* @__PURE__ */ new Date()).toISOString(),
2306
- respondsToUserMessageId: O(r) ?? void 0,
2283
+ respondsToUserMessageId: v(r) ?? void 0,
2307
2284
  ...M(r) ? { runId: M(r) } : {},
2308
2285
  dataType: String(r.type),
2309
2286
  loading: r.type === "run_status" && (r.status === "running" || r.status === "retrying"),
@@ -2311,11 +2288,11 @@ function De(e, t) {
2311
2288
  ...typeof r.securitySettingsUrl == "string" ? { securitySettingsUrl: r.securitySettingsUrl } : {}
2312
2289
  } : null;
2313
2290
  }
2314
- function Sn(e) {
2291
+ function An(e) {
2315
2292
  const s = (typeof e.server_label == "string" ? e.server_label : "").replace(/^pipedream_/, "").split(/[_-]+/).filter(Boolean).map((n) => `${n.charAt(0).toUpperCase()}${n.slice(1)}`).join(" ");
2316
2293
  return s ? `🔌 Using ${s}` : "🔌 Using connected integration";
2317
2294
  }
2318
- function En(e) {
2295
+ function Sn(e) {
2319
2296
  if (typeof e != "string")
2320
2297
  return null;
2321
2298
  try {
@@ -2332,10 +2309,10 @@ function En(e) {
2332
2309
  return null;
2333
2310
  }
2334
2311
  }
2335
- function kn(e) {
2312
+ function bn(e) {
2336
2313
  return e.type === "run_status" && e.status === "stopped" ? "Run stopped by user" : typeof e.message == "string" && e.message.trim().length > 0 ? e.message.replace(/Product Agent/g, "Pluno") : e.type === "run_status" && e.status === "interrupted" ? "Pluno was interrupted before it could finish this message." : "Pluno run status changed.";
2337
2314
  }
2338
- function bn(e) {
2315
+ function En(e) {
2339
2316
  if (e.type === "web_search_call") {
2340
2317
  const t = e.action;
2341
2318
  if (t && typeof t == "object") {
@@ -2347,26 +2324,26 @@ function bn(e) {
2347
2324
  }
2348
2325
  return "🔎 Searching the web";
2349
2326
  }
2350
- return Rn(e);
2327
+ return kn(e);
2351
2328
  }
2352
- function Rn(e) {
2329
+ function kn(e) {
2353
2330
  if (typeof e.summary == "string" && e.summary.trim().length > 0)
2354
- return L(e.summary);
2331
+ return N(e.summary);
2355
2332
  if (typeof e.arguments == "string")
2356
2333
  try {
2357
2334
  const t = JSON.parse(e.arguments);
2358
2335
  if (typeof t.summary == "string" && t.summary.trim().length > 0)
2359
- return L(t.summary);
2336
+ return N(t.summary);
2360
2337
  } catch {
2361
- return typeof e.name == "string" && e.name.trim().length > 0 ? L(e.name) : "🛠️ Run tool";
2338
+ return typeof e.name == "string" && e.name.trim().length > 0 ? N(e.name) : "🛠️ Run tool";
2362
2339
  }
2363
- return typeof e.name == "string" && e.name.trim().length > 0 ? L(e.name) : "🛠️ Run tool";
2340
+ return typeof e.name == "string" && e.name.trim().length > 0 ? N(e.name) : "🛠️ Run tool";
2364
2341
  }
2365
- function L(e) {
2342
+ function N(e) {
2366
2343
  const t = e.trim() || "Run tool", s = t.codePointAt(0) ?? 0;
2367
2344
  return s >= 126976 && s <= 129791 || s >= 9728 && s <= 10175 || s >= 127462 && s <= 127487 ? t : `🛠️ ${t}`;
2368
2345
  }
2369
- function _n(e) {
2346
+ function Rn(e) {
2370
2347
  if (e == null)
2371
2348
  return e;
2372
2349
  if (typeof e != "object")
@@ -2381,11 +2358,11 @@ function _n(e) {
2381
2358
  runId: typeof t.runId == "string" ? t.runId : null
2382
2359
  };
2383
2360
  }
2384
- function he(e) {
2361
+ function le(e) {
2385
2362
  const t = e.callId ?? e.call_id;
2386
2363
  return typeof t == "string" && t ? t : null;
2387
2364
  }
2388
- function Mn(e) {
2365
+ function _n(e) {
2389
2366
  return typeof e == "string" ? e : Array.isArray(e) ? e.map((t) => {
2390
2367
  if (!t || typeof t != "object")
2391
2368
  return "";
@@ -2393,24 +2370,24 @@ function Mn(e) {
2393
2370
  return typeof s.text == "string" ? s.text : typeof s.content == "string" ? s.content : "";
2394
2371
  }).filter(Boolean).join("") : "";
2395
2372
  }
2396
- function Ne(e, t) {
2397
- const s = Oe(e, t), n = Dn(
2398
- Ln(e, t),
2373
+ function Ce(e, t) {
2374
+ const s = Pe(e, t), n = Un(
2375
+ On(e, t),
2399
2376
  s
2400
2377
  ), r = n.findIndex((o) => o.id === s.id);
2401
2378
  if (r === -1)
2402
- return Ot(
2403
- vt([...n, s])
2379
+ return Dt(
2380
+ xt([...n, s])
2404
2381
  );
2405
2382
  const i = [...n];
2406
- return i[r] = s, Ot(vt(i));
2383
+ return i[r] = s, Dt(xt(i));
2407
2384
  }
2408
- function Cn(e, t) {
2385
+ function Mn(e, t) {
2409
2386
  const s = e.findIndex(
2410
2387
  (r) => !r.id.startsWith("transient-activity:") && r.callId === t.callId
2411
2388
  );
2412
2389
  if (s === -1)
2413
- return Ne(e, t);
2390
+ return Ce(e, t);
2414
2391
  const n = [...e];
2415
2392
  return n[s] = {
2416
2393
  ...n[s],
@@ -2418,17 +2395,17 @@ function Cn(e, t) {
2418
2395
  loading: !0
2419
2396
  }, n;
2420
2397
  }
2421
- function Pn(e, t, s) {
2398
+ function Cn(e, t, s) {
2422
2399
  let n = !1;
2423
2400
  const r = e.map((i) => i.callId !== t || i.loading === s ? i : (n = !0, { ...i, loading: s }));
2424
2401
  return n ? r : e;
2425
2402
  }
2426
- function Un(e) {
2403
+ function Pn(e) {
2427
2404
  const t = typeof e.callId == "string" ? e.callId : null, s = typeof e.toolName == "string" ? e.toolName : null;
2428
2405
  return !t || !s ? null : {
2429
2406
  id: `transient-activity:${t}`,
2430
2407
  role: "tool",
2431
- content: L(
2408
+ content: N(
2432
2409
  typeof e.summary == "string" ? e.summary : "Running browser tool"
2433
2410
  ),
2434
2411
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
@@ -2440,7 +2417,7 @@ function Un(e) {
2440
2417
  loading: !0
2441
2418
  };
2442
2419
  }
2443
- function Dn(e, t) {
2420
+ function Un(e, t) {
2444
2421
  if (t.id.startsWith("transient-activity:"))
2445
2422
  return e;
2446
2423
  const s = t.toolName === "tab_lifecycle";
@@ -2448,52 +2425,52 @@ function Dn(e, t) {
2448
2425
  (n) => !(n.id === `transient-activity:${t.callId}` && n.callId === t.callId || s && n.id.startsWith("transient-activity:") && n.toolName === "browser_tabs" && n.runId === t.runId && n.respondsToUserMessageId === t.respondsToUserMessageId)
2449
2426
  );
2450
2427
  }
2451
- function Nn(e, t) {
2428
+ function Dn(e, t) {
2452
2429
  const s = t.map(
2453
- (n) => Oe(e, n)
2430
+ (n) => Pe(e, n)
2454
2431
  );
2455
- return t.length > 0 ? s : e.filter($t);
2432
+ return t.length > 0 ? s : e.filter(Ht);
2456
2433
  }
2457
- function Oe(e, t) {
2434
+ function Pe(e, t) {
2458
2435
  if (t.role !== "user" || !t.attachments?.length)
2459
2436
  return t;
2460
2437
  const s = e.find(
2461
- (r) => r.role === "user" && (r.id === t.id || $t(r) && ve(r, t))
2438
+ (r) => r.role === "user" && (r.id === t.id || Ht(r) && Ue(r, t))
2462
2439
  );
2463
2440
  if (!s?.attachments?.length)
2464
2441
  return t;
2465
2442
  const n = t.attachments.map((r) => {
2466
- const i = On(s.attachments ?? [], r);
2443
+ const i = xn(s.attachments ?? [], r);
2467
2444
  return i ? vn(r, i) : r;
2468
2445
  });
2469
2446
  return { ...t, attachments: n };
2470
2447
  }
2471
- function On(e, t) {
2448
+ function xn(e, t) {
2472
2449
  return t.id ? e.find((s) => s.id === t.id) ?? null : null;
2473
2450
  }
2474
2451
  function vn(e, t) {
2475
2452
  const { previewUrl: s } = t;
2476
2453
  return s ? { ...e, previewUrl: s } : e;
2477
2454
  }
2478
- function Ln(e, t) {
2455
+ function On(e, t) {
2479
2456
  if (t.role !== "user")
2480
2457
  return e;
2481
2458
  const s = e.findIndex(
2482
- (r) => $t(r) && ve(r, t)
2459
+ (r) => Ht(r) && Ue(r, t)
2483
2460
  );
2484
2461
  if (s === -1)
2485
2462
  return e;
2486
2463
  const n = [...e];
2487
2464
  return n.splice(s, 1), n;
2488
2465
  }
2489
- function ve(e, t) {
2490
- const s = pe(e), n = pe(t);
2466
+ function Ue(e, t) {
2467
+ const s = ue(e), n = ue(t);
2491
2468
  return s && n ? s === n : e.content === t.content;
2492
2469
  }
2493
- function $t(e) {
2470
+ function Ht(e) {
2494
2471
  return e.role === "user" && (e.id.startsWith("local-") || e.id.startsWith("optimistic-user-message:"));
2495
2472
  }
2496
- function pe(e) {
2473
+ function ue(e) {
2497
2474
  const t = e.clientMessageId;
2498
2475
  if (t)
2499
2476
  return t;
@@ -2502,8 +2479,8 @@ function pe(e) {
2502
2479
  );
2503
2480
  return n ? e.id.slice(n.length) : null;
2504
2481
  }
2505
- function fe(e) {
2506
- const t = Le(e);
2482
+ function de(e) {
2483
+ const t = De(e);
2507
2484
  if (t === null)
2508
2485
  return !1;
2509
2486
  for (let s = e.length - 1; s > t; s -= 1) {
@@ -2519,20 +2496,20 @@ function fe(e) {
2519
2496
  }
2520
2497
  return !1;
2521
2498
  }
2522
- function xn(e) {
2523
- const t = Le(e);
2499
+ function Nn(e) {
2500
+ const t = De(e);
2524
2501
  return t === null ? e.some(j) : e.slice(t + 1).some(j);
2525
2502
  }
2526
- function Le(e) {
2503
+ function De(e) {
2527
2504
  for (let t = e.length - 1; t >= 0; t -= 1)
2528
2505
  if (e[t].role === "user")
2529
2506
  return t;
2530
2507
  return null;
2531
2508
  }
2532
- function Bn(e) {
2509
+ function Ln(e) {
2533
2510
  return j(e) ? !0 : e.role !== "system" ? !1 : e.dataType === "run_error" ? !0 : e.dataType === "run_status" && e.loading !== !0;
2534
2511
  }
2535
- function at(e) {
2512
+ function it(e) {
2536
2513
  for (let t = e.length - 1; t >= 0; t -= 1) {
2537
2514
  const s = e[t];
2538
2515
  if (!s || typeof s != "object")
@@ -2546,40 +2523,40 @@ function at(e) {
2546
2523
  }
2547
2524
  return null;
2548
2525
  }
2549
- function qn(e) {
2550
- const t = at(e);
2526
+ function Bn(e) {
2527
+ const t = it(e);
2551
2528
  if (t === null)
2552
2529
  return null;
2553
- const n = x(e[t])?.page;
2530
+ const n = L(e[t])?.page;
2554
2531
  if (!n || typeof n != "object")
2555
2532
  return null;
2556
2533
  const r = n.url;
2557
2534
  return typeof r == "string" ? r : null;
2558
2535
  }
2559
- function x(e) {
2536
+ function L(e) {
2560
2537
  if (!e || typeof e != "object")
2561
2538
  return null;
2562
2539
  const t = e.data;
2563
2540
  return t && typeof t == "object" ? t : null;
2564
2541
  }
2565
- function Dt(e) {
2542
+ function Pt(e) {
2566
2543
  return e?.retryable !== !0 ? !1 : e.type === "run_error" ? !0 : e.type === "run_status" && e.status === "interrupted";
2567
2544
  }
2568
- function ge(e) {
2545
+ function he(e) {
2569
2546
  return e?.type === "run_status" && e.status === "interrupted" && e.reason === "backend_restart";
2570
2547
  }
2571
- function Hn(e, t) {
2572
- const s = at(t);
2548
+ function qn(e, t) {
2549
+ const s = it(t);
2573
2550
  if (s === null)
2574
2551
  return !1;
2575
2552
  const n = t[s], r = n && typeof n == "object" ? n.id : null;
2576
2553
  if (typeof r != "string" || !r)
2577
2554
  return !1;
2578
2555
  const i = e.findIndex((o) => o.role === "user" && o.id === r);
2579
- return i === -1 ? !1 : e.slice(i + 1).some(Bn);
2556
+ return i === -1 ? !1 : e.slice(i + 1).some(Ln);
2580
2557
  }
2581
- function Nt(e) {
2582
- const t = at(e);
2558
+ function Ut(e) {
2559
+ const t = it(e);
2583
2560
  if (t === null)
2584
2561
  return null;
2585
2562
  const s = e[t];
@@ -2591,8 +2568,8 @@ function Nt(e) {
2591
2568
  const r = n.clientMessageId;
2592
2569
  return typeof r == "string" ? r : null;
2593
2570
  }
2594
- function Fn(e) {
2595
- const t = at(e);
2571
+ function Hn(e) {
2572
+ const t = it(e);
2596
2573
  if (t === null)
2597
2574
  return null;
2598
2575
  for (let s = e.length - 1; s > t; s -= 1) {
@@ -2606,22 +2583,22 @@ function Fn(e) {
2606
2583
  if (i.type === "message" && i.role === "assistant")
2607
2584
  return null;
2608
2585
  if (i.type === "run_error")
2609
- return i.retryable !== !0 ? null : me(e, i) ?? Nt(e);
2586
+ return i.retryable !== !0 ? null : pe(e, i) ?? Ut(e);
2610
2587
  if (i.type === "run_status")
2611
- return i.status === "interrupted" && i.retryable === !0 ? me(e, i) ?? Nt(e) : null;
2588
+ return i.status === "interrupted" && i.retryable === !0 ? pe(e, i) ?? Ut(e) : null;
2612
2589
  }
2613
2590
  return null;
2614
2591
  }
2615
- function me(e, t) {
2592
+ function pe(e, t) {
2616
2593
  if (typeof t.clientMessageId == "string")
2617
2594
  return t.clientMessageId;
2618
- const s = O(t);
2595
+ const s = v(t);
2619
2596
  if (!s)
2620
2597
  return null;
2621
- const n = e.find((i) => E(i, "id") === s), r = x(n);
2598
+ const n = e.find((i) => b(i, "id") === s), r = L(n);
2622
2599
  return r?.type === "message" && r.role === "user" && typeof r.clientMessageId == "string" ? r.clientMessageId : null;
2623
2600
  }
2624
- function Wn(e, t) {
2601
+ function Fn(e, t) {
2625
2602
  let s = 0;
2626
2603
  for (const n of e) {
2627
2604
  if (!n || typeof n != "object")
@@ -2634,11 +2611,11 @@ function Wn(e, t) {
2634
2611
  }
2635
2612
  return s;
2636
2613
  }
2637
- function ye(e, t, s, n, r) {
2614
+ function fe(e, t, s, n, r) {
2638
2615
  if (!t || !$n(e))
2639
2616
  return !1;
2640
2617
  const i = e;
2641
- return !(Dt(i) || s !== null && typeof i.id == "string" && i.id !== s || n !== null && O(i) !== n || r !== null && M(i) !== r);
2618
+ return !(Pt(i) || s !== null && typeof i.id == "string" && i.id !== s || n !== null && v(i) !== n || r !== null && M(i) !== r);
2642
2619
  }
2643
2620
  function $n(e) {
2644
2621
  if (!e || typeof e != "object")
@@ -2649,22 +2626,22 @@ function $n(e) {
2649
2626
  function j(e) {
2650
2627
  return e.role === "assistant" && e.phase !== "commentary";
2651
2628
  }
2652
- function jn(e) {
2629
+ function Wn(e) {
2653
2630
  if (!e || typeof e != "object")
2654
2631
  return !1;
2655
2632
  const t = e;
2656
2633
  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";
2657
2634
  }
2658
- function Ot(e) {
2659
- return e.filter((t, s) => jt(t) ? !Vn(e, s) && !Jn(e, s) && !Kn(e, s) : zn(t) ? t.retryable === !0 && Xn(e, s) ? !1 : !Gn(e, s) : !0);
2635
+ function Dt(e) {
2636
+ return e.filter((t, s) => Ft(t) ? !Kn(e, s) && !Xn(e, s) && !Jn(e, s) : jn(t) ? t.retryable === !0 && Gn(e, s) ? !1 : !zn(e, s) : !0);
2660
2637
  }
2661
- function zn(e) {
2638
+ function jn(e) {
2662
2639
  return e.role === "system" && (e.dataType === "run_status" || e.dataType === "run_error");
2663
2640
  }
2664
- function jt(e) {
2641
+ function Ft(e) {
2665
2642
  return e.role === "system" && e.dataType === "run_status" && e.loading === !0;
2666
2643
  }
2667
- function vt(e) {
2644
+ function xt(e) {
2668
2645
  const t = new Set(e.filter((i) => i.role === "user").map((i) => i.id)), s = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set();
2669
2646
  for (const i of e) {
2670
2647
  if (i.role === "user" || !i.respondsToUserMessageId || !t.has(i.respondsToUserMessageId))
@@ -2680,18 +2657,18 @@ function vt(e) {
2680
2657
  n.has(i.id) || (r.push(i), i.role === "user" && r.push(...s.get(i.id) ?? []));
2681
2658
  return r;
2682
2659
  }
2683
- function Gn(e, t) {
2660
+ function zn(e, t) {
2684
2661
  const s = e[t];
2685
2662
  for (let n = t + 1; n < e.length; n += 1) {
2686
2663
  const r = e[n];
2687
2664
  if (r.role === "user")
2688
2665
  return !1;
2689
- if (r.role === "assistant" && ct(s, r))
2666
+ if (r.role === "assistant" && ot(s, r))
2690
2667
  return !0;
2691
2668
  }
2692
2669
  return !1;
2693
2670
  }
2694
- function Xn(e, t) {
2671
+ function Gn(e, t) {
2695
2672
  const s = e[t];
2696
2673
  if (!s.respondsToUserMessageId)
2697
2674
  return !1;
@@ -2699,47 +2676,47 @@ function Xn(e, t) {
2699
2676
  const r = e[n];
2700
2677
  if (r.role === "user")
2701
2678
  return !1;
2702
- if (r.respondsToUserMessageId === s.respondsToUserMessageId && (r.role === "assistant" || r.role === "tool" || jt(r)))
2679
+ if (r.respondsToUserMessageId === s.respondsToUserMessageId && (r.role === "assistant" || r.role === "tool" || Ft(r)))
2703
2680
  return !0;
2704
2681
  }
2705
2682
  return !1;
2706
2683
  }
2707
- function Jn(e, t) {
2684
+ function Xn(e, t) {
2708
2685
  const s = e[t];
2709
2686
  for (let n = t + 1; n < e.length; n += 1)
2710
- if (e[n].role === "assistant" && ct(s, e[n]))
2687
+ if (e[n].role === "assistant" && ot(s, e[n]))
2711
2688
  return !0;
2712
2689
  return !1;
2713
2690
  }
2714
- function Kn(e, t) {
2691
+ function Jn(e, t) {
2715
2692
  const s = e[t];
2716
2693
  for (let n = t + 1; n < e.length; n += 1)
2717
- if (e[n].role === "tool" && ct(s, e[n]))
2694
+ if (e[n].role === "tool" && ot(s, e[n]))
2718
2695
  return !0;
2719
2696
  return !1;
2720
2697
  }
2721
- function Vn(e, t) {
2698
+ function Kn(e, t) {
2722
2699
  const s = e[t];
2723
2700
  for (let n = t + 1; n < e.length; n += 1)
2724
- if (jt(e[n]) && ct(s, e[n]))
2701
+ if (Ft(e[n]) && ot(s, e[n]))
2725
2702
  return !0;
2726
2703
  return !1;
2727
2704
  }
2728
- function ct(e, t) {
2705
+ function ot(e, t) {
2729
2706
  return !e.runId || !t.runId ? !0 : e.runId === t.runId;
2730
2707
  }
2731
- function E(e, t) {
2708
+ function b(e, t) {
2732
2709
  return e && typeof e == "object" && typeof e[t] == "string" ? e[t] : null;
2733
2710
  }
2734
- function Yn(e, t) {
2711
+ function Vn(e, t) {
2735
2712
  try {
2736
- const s = window.localStorage.getItem(`${Re}${e}`);
2713
+ const s = window.localStorage.getItem(`${Se}${e}`);
2737
2714
  if (!s)
2738
2715
  return null;
2739
2716
  const n = JSON.parse(s), r = typeof n.sessionId == "string" ? n.sessionId : null;
2740
2717
  if (t !== void 0 && r !== t)
2741
2718
  return null;
2742
- const i = Array.isArray(n.messages) ? n.messages.map(lr).filter((o) => !!o) : [];
2719
+ const i = Array.isArray(n.messages) ? n.messages.map(or).filter((o) => !!o) : [];
2743
2720
  return {
2744
2721
  sessionId: r,
2745
2722
  messages: i
@@ -2748,39 +2725,39 @@ function Yn(e, t) {
2748
2725
  return null;
2749
2726
  }
2750
2727
  }
2751
- function Zn(e, t) {
2728
+ function Yn(e, t) {
2752
2729
  try {
2753
2730
  window.localStorage.setItem(
2754
- `${Re}${e}`,
2731
+ `${Se}${e}`,
2755
2732
  JSON.stringify({
2756
2733
  sessionId: t.sessionId,
2757
- messages: t.messages.slice(-Us).map(ur)
2734
+ messages: t.messages.slice(-Ms).map(ar)
2758
2735
  })
2759
2736
  );
2760
2737
  } catch {
2761
2738
  return;
2762
2739
  }
2763
2740
  }
2764
- function Qn(e) {
2741
+ function Zn(e) {
2765
2742
  try {
2766
- const t = window.localStorage.getItem(`${Pt}${e}`);
2743
+ const t = window.localStorage.getItem(`${Ct}${e}`);
2767
2744
  if (!t)
2768
2745
  return [];
2769
2746
  const s = JSON.parse(t);
2770
- return Array.isArray(s) ? s.filter(zt) : [];
2747
+ return Array.isArray(s) ? s.filter($t) : [];
2771
2748
  } catch {
2772
2749
  return [];
2773
2750
  }
2774
2751
  }
2775
- function W(e, t) {
2752
+ function $(e, t) {
2776
2753
  try {
2777
- const s = t.filter(zt);
2754
+ const s = t.filter($t);
2778
2755
  if (s.length === 0) {
2779
- window.localStorage.removeItem(`${Pt}${e}`);
2756
+ window.localStorage.removeItem(`${Ct}${e}`);
2780
2757
  return;
2781
2758
  }
2782
2759
  window.localStorage.setItem(
2783
- `${Pt}${e}`,
2760
+ `${Ct}${e}`,
2784
2761
  JSON.stringify(s.slice(-25))
2785
2762
  );
2786
2763
  } catch {
@@ -2789,7 +2766,7 @@ function W(e, t) {
2789
2766
  }
2790
2767
  function xe(e, t) {
2791
2768
  try {
2792
- const s = `${ot}${e}`, n = location.href, r = location.origin, i = Array.from(t, (o) => ({
2769
+ const s = `${rt}${e}`, n = location.href, r = location.origin, i = Array.from(t, (o) => ({
2793
2770
  ...o,
2794
2771
  storedAt: Date.now(),
2795
2772
  unloadUrl: n,
@@ -2803,28 +2780,28 @@ function xe(e, t) {
2803
2780
  } catch {
2804
2781
  }
2805
2782
  }
2806
- function tr(e, t) {
2783
+ function Qn(e, t) {
2807
2784
  try {
2808
- if (window.sessionStorage.getItem(`${ot}${e}`) === null)
2785
+ if (window.sessionStorage.getItem(`${rt}${e}`) === null)
2809
2786
  return;
2810
2787
  } catch {
2811
2788
  return;
2812
2789
  }
2813
2790
  xe(e, t);
2814
2791
  }
2815
- function er(e) {
2792
+ function tr(e) {
2816
2793
  try {
2817
- const t = `${ot}${e}`, s = window.sessionStorage.getItem(t);
2794
+ const t = `${rt}${e}`, s = window.sessionStorage.getItem(t);
2818
2795
  if (window.sessionStorage.removeItem(t), !s)
2819
2796
  return [];
2820
2797
  const n = JSON.parse(s);
2821
- return Array.isArray(n) ? n.flatMap((r) => nr(r) ? [{
2798
+ return Array.isArray(n) ? n.flatMap((r) => sr(r) ? [{
2822
2799
  ...r.event,
2823
- page: R(),
2800
+ page: _(),
2824
2801
  rawOutput: {
2825
2802
  pageContextRestarted: !0,
2826
2803
  outcome: "unknown",
2827
- message: sr(location.href),
2804
+ message: er(location.href),
2828
2805
  currentUrl: location.href,
2829
2806
  console: [],
2830
2807
  metadata: {
@@ -2841,17 +2818,17 @@ function er(e) {
2841
2818
  return [];
2842
2819
  }
2843
2820
  }
2844
- function sr(e) {
2821
+ function er(e) {
2845
2822
  return `The page context restarted. This is expected when the action included page navigation. Otherwise, it's unknown whether the action completed.
2846
2823
  Current URL: ${e}`;
2847
2824
  }
2848
- function nr(e) {
2825
+ function sr(e) {
2849
2826
  if (!e || typeof e != "object")
2850
2827
  return !1;
2851
2828
  const t = e, s = t.event;
2852
- return typeof t.startedAtMs == "number" && typeof t.startedAtUrl == "string" && t.startedAtOrigin === location.origin && t.unloadOrigin === location.origin && typeof t.unloadUrl == "string" && zt(s) && s.type === "tool.result";
2829
+ return typeof t.startedAtMs == "number" && typeof t.startedAtUrl == "string" && t.startedAtOrigin === location.origin && t.unloadOrigin === location.origin && typeof t.unloadUrl == "string" && $t(s) && s.type === "tool.result";
2853
2830
  }
2854
- function rr(e, t) {
2831
+ function nr(e, t) {
2855
2832
  const s = new Set(
2856
2833
  e.flatMap((n) => n.type === "tool.result" ? [n.callId] : [])
2857
2834
  );
@@ -2860,26 +2837,26 @@ function rr(e, t) {
2860
2837
  ...t.filter((n) => !s.has(n.callId))
2861
2838
  ];
2862
2839
  }
2863
- function ir(e) {
2840
+ function rr(e) {
2864
2841
  try {
2865
- window.sessionStorage.removeItem(`${ot}${e}`);
2842
+ window.sessionStorage.removeItem(`${rt}${e}`);
2866
2843
  } catch {
2867
2844
  return;
2868
2845
  }
2869
2846
  }
2870
- function zt(e) {
2847
+ function $t(e) {
2871
2848
  if (!e || typeof e != "object")
2872
2849
  return !1;
2873
2850
  const t = e;
2874
- return t.type === "chat.user_message" ? typeof t.content == "string" && Te(t.page) : t.type === "page.upsert" || t.type === "session.reset" || t.type === "network.batch" ? Te(t.page) : t.type === "tool.result" ? typeof t.sessionId == "string" && typeof t.callId == "string" && (t.toolName === "execute_code" || t.toolName === "execute_code_in_browser_tab") : t.type === "chat.retry_last_user_message" ? typeof t.sessionId == "string" && typeof t.clientMessageId == "string" : t.type === "run.stop" ? typeof t.sessionId == "string" && (t.reason === "user_requested" || t.reason === "new_chat" || t.reason === "session_switch") : !1;
2851
+ return t.type === "chat.user_message" ? typeof t.content == "string" && ge(t.page) : t.type === "page.upsert" || t.type === "session.reset" || t.type === "network.batch" ? ge(t.page) : t.type === "tool.result" ? typeof t.sessionId == "string" && typeof t.callId == "string" && (t.toolName === "execute_code" || t.toolName === "execute_code_in_browser_tab") : t.type === "chat.retry_last_user_message" ? typeof t.sessionId == "string" && typeof t.clientMessageId == "string" : t.type === "run.stop" ? typeof t.sessionId == "string" && (t.reason === "user_requested" || t.reason === "new_chat" || t.reason === "session_switch") : !1;
2875
2852
  }
2876
- function Te(e) {
2853
+ function ge(e) {
2877
2854
  if (!e || typeof e != "object")
2878
2855
  return !1;
2879
2856
  const t = e;
2880
2857
  return typeof t.url == "string" && typeof t.title == "string" && typeof t.origin == "string";
2881
2858
  }
2882
- function Be(e, t) {
2859
+ function ve(e, t) {
2883
2860
  if (!Array.isArray(e))
2884
2861
  return;
2885
2862
  const s = e.filter((r) => {
@@ -2887,39 +2864,23 @@ function Be(e, t) {
2887
2864
  return !1;
2888
2865
  const i = r;
2889
2866
  return typeof i.name == "string" && typeof i.mimeType == "string" && typeof i.sizeBytes == "number";
2890
- }), n = t ? s.map((r) => qe(r, t)) : s;
2867
+ }), n = t ? s.map((r) => Oe(r, t)) : s;
2891
2868
  return n.length > 0 ? n : void 0;
2892
2869
  }
2893
- function qe(e, t) {
2870
+ function Oe(e, t) {
2894
2871
  return e.fileUrl?.startsWith("/") ? {
2895
2872
  ...e,
2896
2873
  fileUrl: new URL(e.fileUrl, t).toString()
2897
2874
  } : e;
2898
2875
  }
2899
- function or(e) {
2900
- if (ar(e))
2901
- return {
2902
- headers: {
2903
- "ngrok-skip-browser-warning": "true"
2904
- }
2905
- };
2906
- }
2907
- function ar(e) {
2908
- try {
2909
- const t = new URL(e).hostname;
2910
- return t.endsWith(".ngrok-free.dev") || t.endsWith(".ngrok-free.app") || t.endsWith(".ngrok.app") || t.endsWith(".ngrok.io");
2911
- } catch {
2912
- return !1;
2913
- }
2914
- }
2915
- function Ie(e) {
2916
- return e.type || cr(e.name) || "application/octet-stream";
2876
+ function me(e) {
2877
+ return e.type || ir(e.name) || "application/octet-stream";
2917
2878
  }
2918
- function cr(e) {
2879
+ function ir(e) {
2919
2880
  const t = e.toLowerCase();
2920
2881
  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;
2921
2882
  }
2922
- function lr(e) {
2883
+ function or(e) {
2923
2884
  if (!e || typeof e != "object")
2924
2885
  return null;
2925
2886
  const t = e;
@@ -2932,17 +2893,17 @@ function lr(e) {
2932
2893
  ...typeof t.runId == "string" ? { runId: t.runId } : {},
2933
2894
  dataType: typeof t.dataType == "string" ? t.dataType : void 0,
2934
2895
  securitySettingsUrl: typeof t.securitySettingsUrl == "string" ? t.securitySettingsUrl : void 0,
2935
- attachments: Be(t.attachments)?.map(Gt),
2896
+ attachments: ve(t.attachments)?.map(Wt),
2936
2897
  loading: typeof t.loading == "boolean" ? t.loading : void 0
2937
2898
  };
2938
2899
  }
2939
- function ur(e) {
2900
+ function ar(e) {
2940
2901
  return e.attachments?.length ? {
2941
2902
  ...e,
2942
- attachments: e.attachments.map(Gt)
2903
+ attachments: e.attachments.map(Wt)
2943
2904
  } : e;
2944
2905
  }
2945
- function Gt(e) {
2906
+ function Wt(e) {
2946
2907
  const {
2947
2908
  dataUrl: t,
2948
2909
  objectUrl: s,
@@ -2951,7 +2912,7 @@ function Gt(e) {
2951
2912
  } = e;
2952
2913
  return r;
2953
2914
  }
2954
- function O(e) {
2915
+ function v(e) {
2955
2916
  const t = e.respondsToUserMessageId;
2956
2917
  return typeof t == "string" && t ? t : null;
2957
2918
  }
@@ -2959,39 +2920,39 @@ function M(e) {
2959
2920
  const t = e.runId;
2960
2921
  return typeof t == "string" && t ? t : null;
2961
2922
  }
2962
- function dr(e) {
2923
+ function cr(e) {
2963
2924
  const t = e?.timeoutMs;
2964
- return !!e && typeof e == "object" && typeof e.summary == "string" && typeof e.javascript == "string" && (t === void 0 || typeof t == "number" && Number.isInteger(t) && t > 0 && t <= qs);
2925
+ 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 <= Ns);
2965
2926
  }
2966
- function He(e) {
2927
+ function Ne(e) {
2967
2928
  const t = {};
2968
2929
  try {
2969
2930
  new Headers(e).forEach((s, n) => {
2970
- Object.keys(t).length < Ht && (t[n] = Xt(n, s));
2931
+ Object.keys(t).length < Bt && (t[n] = jt(n, s));
2971
2932
  });
2972
2933
  } catch {
2973
2934
  return {};
2974
2935
  }
2975
2936
  return t;
2976
2937
  }
2977
- function Xt(e, t) {
2978
- return Ge(e) ? lt : C(rt(t), Ms);
2938
+ function jt(e, t) {
2939
+ return $e(e) ? at : C(nt(t), Rs);
2979
2940
  }
2980
- function hr(e, t) {
2941
+ function lr(e, t) {
2981
2942
  return typeof e == "string" ? e : e instanceof URL ? e.toString() : t?.url ?? "";
2982
2943
  }
2983
- async function pr(e, t, s, n) {
2984
- const r = He(e.headers);
2944
+ async function ur(e, t, s, n) {
2945
+ const r = Ne(e.headers);
2985
2946
  n({
2986
2947
  ...t,
2987
2948
  responseStatus: e.status,
2988
2949
  responseHeaders: r,
2989
- responseBody: await fr(e),
2950
+ responseBody: await dr(e),
2990
2951
  durationMs: Date.now() - s
2991
2952
  });
2992
2953
  }
2993
- async function fr(e) {
2994
- if (!Fe(e.headers))
2954
+ async function dr(e) {
2955
+ if (!Le(e.headers))
2995
2956
  return;
2996
2957
  let t = null, s = null;
2997
2958
  try {
@@ -3000,20 +2961,20 @@ async function fr(e) {
3000
2961
  const n = new Promise((a) => {
3001
2962
  s = window.setTimeout(() => {
3002
2963
  t?.cancel(), a("timeout");
3003
- }, Cs);
2964
+ }, _s);
3004
2965
  }), r = new TextDecoder();
3005
2966
  let i = "", o = 0;
3006
2967
  for (; ; ) {
3007
2968
  const a = await Promise.race([t.read(), n]);
3008
2969
  if (a === "timeout")
3009
2970
  return;
3010
- const { done: u, value: c } = a;
3011
- if (u)
2971
+ const { done: c, value: l } = a;
2972
+ if (c)
3012
2973
  return C(i + r.decode());
3013
- const l = qt - o;
3014
- if (c.byteLength > l)
3015
- return i += r.decode(c.subarray(0, Math.max(l, 0)), { stream: !0 }), t.cancel(), `${C(i)}... [truncated]`;
3016
- o += c.byteLength, i += r.decode(c, { stream: !0 });
2974
+ const d = Lt - o;
2975
+ if (l.byteLength > d)
2976
+ return i += r.decode(l.subarray(0, Math.max(d, 0)), { stream: !0 }), t.cancel(), `${C(i)}... [truncated]`;
2977
+ o += l.byteLength, i += r.decode(l, { stream: !0 });
3017
2978
  }
3018
2979
  } catch {
3019
2980
  t?.cancel();
@@ -3022,45 +2983,45 @@ async function fr(e) {
3022
2983
  s !== null && window.clearTimeout(s);
3023
2984
  }
3024
2985
  }
3025
- function gr(e, t) {
3026
- if (Fe(new Headers(t)))
2986
+ function hr(e, t) {
2987
+ if (Le(new Headers(t)))
3027
2988
  try {
3028
2989
  return e.responseType === "" || e.responseType === "text" ? C(e.responseText ?? "") : void 0;
3029
2990
  } catch {
3030
2991
  return;
3031
2992
  }
3032
2993
  }
3033
- function we(e) {
2994
+ function ye(e) {
3034
2995
  if (typeof e == "string")
3035
2996
  return C(e);
3036
2997
  }
3037
- function mr(e) {
3038
- return _({
2998
+ function pr(e) {
2999
+ return k({
3039
3000
  ...e,
3040
- requestBody: Ae(e.requestBody),
3041
- responseBody: Ae(e.responseBody)
3001
+ requestBody: Ie(e.requestBody),
3002
+ responseBody: Ie(e.responseBody)
3042
3003
  });
3043
3004
  }
3044
- function Ae(e) {
3005
+ function Ie(e) {
3045
3006
  if (typeof e != "string")
3046
3007
  return e;
3047
3008
  const t = e.trim();
3048
3009
  if (!t.startsWith("{") && !t.startsWith("["))
3049
- return rt(e);
3010
+ return nt(e);
3050
3011
  try {
3051
- return JSON.stringify(_(JSON.parse(e)));
3012
+ return JSON.stringify(k(JSON.parse(e)));
3052
3013
  } catch {
3053
- return rt(e);
3014
+ return nt(e);
3054
3015
  }
3055
3016
  }
3056
- function Fe(e) {
3017
+ function Le(e) {
3057
3018
  if (!e)
3058
3019
  return !1;
3059
3020
  const t = e.get("content-type")?.toLowerCase() ?? "", s = e.get("content-length"), n = Number(s);
3060
- return s !== null && Number.isInteger(n) && n >= 0 && n <= qt && (t.startsWith("text/") || t.includes("json") || t.includes("javascript"));
3021
+ return s !== null && Number.isInteger(n) && n >= 0 && n <= Lt && (t.startsWith("text/") || t.includes("json") || t.includes("javascript"));
3061
3022
  }
3062
- function v(e, t = {}, s) {
3063
- if (Tr(s))
3023
+ function O(e, t = {}, s) {
3024
+ if (gr(s))
3064
3025
  return !0;
3065
3026
  const n = Object.entries(t).find(([r]) => r.toLowerCase() === "content-type")?.[1]?.toLowerCase();
3066
3027
  if (n?.includes("multipart/form-data") || n?.includes("application/octet-stream"))
@@ -3075,8 +3036,8 @@ function v(e, t = {}, s) {
3075
3036
  return !0;
3076
3037
  }
3077
3038
  }
3078
- function yr(e, t) {
3079
- if (v(e))
3039
+ function fr(e, t) {
3040
+ if (O(e))
3080
3041
  return !0;
3081
3042
  try {
3082
3043
  const s = new URL(e, location.href), n = new URL(t);
@@ -3085,115 +3046,115 @@ function yr(e, t) {
3085
3046
  return !0;
3086
3047
  }
3087
3048
  }
3088
- function Tr(e) {
3049
+ function gr(e) {
3089
3050
  return e instanceof FormData || e instanceof Blob || e instanceof ArrayBuffer || ArrayBuffer.isView(e) || typeof ReadableStream < "u" && e instanceof ReadableStream;
3090
3051
  }
3091
- function Ir(e) {
3052
+ function mr(e) {
3092
3053
  const t = {};
3093
3054
  for (const s of e.trim().split(/[\r\n]+/)) {
3094
3055
  const n = s.indexOf(":");
3095
3056
  if (n <= 0)
3096
3057
  continue;
3097
- if (Object.keys(t).length >= Ht)
3058
+ if (Object.keys(t).length >= Bt)
3098
3059
  break;
3099
3060
  const r = s.slice(0, n).trim();
3100
- t[r] = Xt(r, s.slice(n + 1).trim());
3061
+ t[r] = jt(r, s.slice(n + 1).trim());
3101
3062
  }
3102
3063
  return t;
3103
3064
  }
3104
- function C(e, t = qt) {
3065
+ function C(e, t = Lt) {
3105
3066
  return e.length <= t ? e : `${e.slice(0, t)}... [truncated ${e.length - t} chars]`;
3106
3067
  }
3107
- function Rt(e) {
3068
+ function kt(e) {
3108
3069
  return `${e}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
3109
3070
  }
3110
- class st extends Error {
3071
+ class et extends Error {
3111
3072
  constructor(t, s) {
3112
3073
  super(`${t} (${s})`), this.status = s, this.name = "AttachmentUploadHttpError";
3113
3074
  }
3114
3075
  status;
3115
3076
  }
3116
- async function _t(e, t) {
3077
+ async function Rt(e, t) {
3117
3078
  let s = null;
3118
- for (let n = 0; n < ae; n += 1)
3079
+ for (let n = 0; n < re; n += 1)
3119
3080
  try {
3120
3081
  return await e();
3121
3082
  } catch (r) {
3122
- if (s = r, n >= ae - 1 || !Ar(r))
3083
+ if (s = r, n >= re - 1 || !Ir(r))
3123
3084
  throw r;
3124
- await wr(n);
3085
+ await yr(n);
3125
3086
  }
3126
3087
  throw s instanceof Error ? s : new Error(t);
3127
3088
  }
3128
- function wr(e) {
3089
+ function yr(e) {
3129
3090
  return new Promise((t) => {
3130
- window.setTimeout(t, _s[e] ?? 0);
3091
+ window.setTimeout(t, ks[e] ?? 0);
3131
3092
  });
3132
3093
  }
3133
- function Ar(e) {
3134
- return e instanceof st ? Sr(e.status) : e instanceof TypeError;
3094
+ function Ir(e) {
3095
+ return e instanceof et ? Tr(e.status) : e instanceof TypeError;
3135
3096
  }
3136
- function Sr(e) {
3097
+ function Tr(e) {
3137
3098
  return e === 408 || e === 409 || e === 429 || e >= 500;
3138
3099
  }
3139
- function Er(e) {
3100
+ function wr(e) {
3140
3101
  return e === 401 || e === 403;
3141
3102
  }
3142
- const lt = "[REDACTED_SECRET]", P = "[REDACTED_TOKEN]", kr = "[REDACTED_SIGNED_URL]", br = 20, Rr = /^(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, We = /\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi, $e = /\bBasic\s+[A-Za-z0-9+/=-]{12,}/gi, je = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g, ze = /\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, _r = /\bhttps?:\/\/[^\s"'<>]+(?:X-Amz-Signature|X-Goog-Signature|Signature|sig=)[^\s"'<>]*/gi, Mr = /\bhttps?:\/\/[^\s"'<>]+/gi, Cr = /[),.;\]]+$/;
3143
- function _(e) {
3144
- return nt(e, 0, /* @__PURE__ */ new WeakSet());
3103
+ const at = "[REDACTED_SECRET]", P = "[REDACTED_TOKEN]", Ar = "[REDACTED_SIGNED_URL]", Sr = 20, br = /^(access_token|accessToken|refresh_token|refreshToken|id_token|idToken|authToken|token|api_key|apiKey|apikey|key|secret|signature|sig|password|passwd|pwd|code|state|session|jwt|csrf|csrfToken|xsrf|xsrfToken)$/i, Be = /\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi, qe = /\bBasic\s+[A-Za-z0-9+/=-]{12,}/gi, He = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g, Fe = /\b(access_token|accessToken|refresh_token|refreshToken|id_token|idToken|authToken|api_key|apiKey|apikey|client_secret|clientSecret|password|secret|token|jwt|csrf|csrfToken|xsrf|xsrfToken)\b\s*[:=]\s*["']?[^"',&\s}]+/gi, Er = /\bhttps?:\/\/[^\s"'<>]+(?:X-Amz-Signature|X-Goog-Signature|Signature|sig=)[^\s"'<>]*/gi, kr = /\bhttps?:\/\/[^\s"'<>]+/gi, Rr = /[),.;\]]+$/;
3104
+ function k(e) {
3105
+ return st(e, 0, /* @__PURE__ */ new WeakSet());
3145
3106
  }
3146
- function nt(e, t, s) {
3107
+ function st(e, t, s) {
3147
3108
  if (typeof e == "string")
3148
- return e.startsWith("data:image/") || e.startsWith("data:application/pdf;") ? e : rt(e);
3109
+ return e.startsWith("data:image/") || e.startsWith("data:application/pdf;") ? e : nt(e);
3149
3110
  if (e === null || typeof e != "object")
3150
3111
  return e;
3151
- if (t >= br)
3112
+ if (t >= Sr)
3152
3113
  return "[REDACTED_MAX_DEPTH]";
3153
3114
  if (s.has(e))
3154
3115
  return "[REDACTED_CIRCULAR]";
3155
3116
  if (s.add(e), Array.isArray(e))
3156
- return e.map((r) => nt(r, t + 1, s));
3117
+ return e.map((r) => st(r, t + 1, s));
3157
3118
  const n = {};
3158
3119
  for (const [r, i] of Object.entries(e))
3159
- r === "pageContent" ? n[r] = i : Ge(r) ? n[r] = lt : n[r] = r.toLowerCase() === "url" ? Pr(i) : nt(i, t + 1, s);
3120
+ r === "pageContent" ? n[r] = i : $e(r) ? n[r] = at : n[r] = r.toLowerCase() === "url" ? _r(i) : st(i, t + 1, s);
3160
3121
  return n;
3161
3122
  }
3162
- function Ge(e) {
3123
+ function $e(e) {
3163
3124
  const t = e.replace(/[^a-z0-9]/gi, "").toLowerCase();
3164
3125
  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");
3165
3126
  }
3166
- function Pr(e) {
3167
- return typeof e == "string" ? Xe(e) : nt(e, 0, /* @__PURE__ */ new WeakSet());
3127
+ function _r(e) {
3128
+ return typeof e == "string" ? We(e) : st(e, 0, /* @__PURE__ */ new WeakSet());
3168
3129
  }
3169
- function Xe(e) {
3130
+ function We(e) {
3170
3131
  try {
3171
3132
  const t = new URL(e, location.href);
3172
3133
  for (const s of Array.from(t.searchParams.keys()))
3173
- Rr.test(s) && t.searchParams.set(s, P);
3134
+ br.test(s) && t.searchParams.set(s, P);
3174
3135
  return t.username && (t.username = P), t.password && (t.password = P), t.toString();
3175
3136
  } catch {
3176
- return Ur(e);
3137
+ return Mr(e);
3177
3138
  }
3178
3139
  }
3179
- function rt(e) {
3180
- return e.replace(_r, kr).replace(Mr, Dr).replace(We, `Bearer ${P}`).replace($e, `Basic ${P}`).replace(je, P).replace(ze, (t, s) => `${s}: ${lt}`);
3140
+ function nt(e) {
3141
+ return e.replace(Er, Ar).replace(kr, Cr).replace(Be, `Bearer ${P}`).replace(qe, `Basic ${P}`).replace(He, P).replace(Fe, (t, s) => `${s}: ${at}`);
3181
3142
  }
3182
- function Ur(e) {
3183
- return e.replace(We, `Bearer ${P}`).replace($e, `Basic ${P}`).replace(je, P).replace(ze, (t, s) => `${s}: ${lt}`);
3143
+ function Mr(e) {
3144
+ return e.replace(Be, `Bearer ${P}`).replace(qe, `Basic ${P}`).replace(He, P).replace(Fe, (t, s) => `${s}: ${at}`);
3184
3145
  }
3185
- function Dr(e) {
3186
- const t = e.match(Cr)?.[0] ?? "", s = t ? e.slice(0, -t.length) : e;
3187
- return `${Xe(s)}${t}`;
3146
+ function Cr(e) {
3147
+ const t = e.match(Rr)?.[0] ?? "", s = t ? e.slice(0, -t.length) : e;
3148
+ return `${We(s)}${t}`;
3188
3149
  }
3189
3150
  export {
3190
- ne as PLUNO_PRODUCT_AGENT_SDK_PREVIEW_HOST_SELECTOR,
3191
- Ct as PLUNO_PRODUCT_AGENT_WIDGET_HOST_SELECTOR,
3192
- us as PLUNO_PRODUCT_AGENT_WIDGET_PANEL_SELECTOR,
3193
- ls as PLUNO_PRODUCT_AGENT_WIDGET_ROOT_SELECTOR,
3194
- ds as PLUNO_PRODUCT_AGENT_WIDGET_TIMELINE_SELECTOR,
3195
- _e as PlunoProductAgent,
3196
- Ns as calculateReconnectDelay,
3197
- _e as default,
3198
- tn as getProductAgentOriginAccessErrorMessage
3151
+ te as PLUNO_PRODUCT_AGENT_SDK_PREVIEW_HOST_SELECTOR,
3152
+ Mt as PLUNO_PRODUCT_AGENT_WIDGET_HOST_SELECTOR,
3153
+ ls as PLUNO_PRODUCT_AGENT_WIDGET_PANEL_SELECTOR,
3154
+ cs as PLUNO_PRODUCT_AGENT_WIDGET_ROOT_SELECTOR,
3155
+ us as PLUNO_PRODUCT_AGENT_WIDGET_TIMELINE_SELECTOR,
3156
+ be as PlunoProductAgent,
3157
+ Ps as calculateReconnectDelay,
3158
+ be as default,
3159
+ Qs as getProductAgentOriginAccessErrorMessage
3199
3160
  };