@pluno/product-agent-web 0.1.133 → 0.1.134

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.
package/dist/index.d.ts CHANGED
@@ -133,6 +133,7 @@ export type ProductAgentInitOptions = {
133
133
  initialStarterPrompts?: string[];
134
134
  webSocketFactory?: ProductAgentWebSocketFactory;
135
135
  prepareAttachmentUpload?: (input: ProductAgentPrepareAttachmentUploadInput) => Promise<ProductAgentAttachmentUpload>;
136
+ persistAttachmentUpload?: (input: ProductAgentPrepareAttachmentUploadInput, file: File) => Promise<Pick<ProductAgentAttachmentUpload, "sessionId" | "attachment">>;
136
137
  restorePersistedState?: boolean;
137
138
  expectedPersistedSessionId?: string | null;
138
139
  keepRunsActiveOnSessionNavigation?: boolean;
@@ -87,11 +87,11 @@ function Qe(e, t) {
87
87
  (s, n, r, i) => `${n}${new URL(r, t).toString()}${i}`
88
88
  ) : e;
89
89
  }
90
- const Tt = "pluno.productAgent.transportId", ts = "pluno.productAgent.transportIdentity", It = "pluno.productAgent.transportIdentity.event", es = 50, ss = globalThis.setTimeout.bind(globalThis);
90
+ const It = "pluno.productAgent.transportId", ts = "pluno.productAgent.transportIdentity", wt = "pluno.productAgent.transportIdentity.event", es = 50, ss = globalThis.setTimeout.bind(globalThis);
91
91
  let $ = null;
92
- const Q = /* @__PURE__ */ new Set(), wt = /* @__PURE__ */ new Map();
92
+ const tt = /* @__PURE__ */ new Set(), At = /* @__PURE__ */ new Map();
93
93
  async function ns(e = we()) {
94
- const t = e.randomUUID(), s = e.storage.getItem(Tt);
94
+ const t = e.randomUUID(), s = e.storage.getItem(It);
95
95
  let n = s ?? e.randomUUID(), r = !1, i = !1;
96
96
  const o = e.channel.subscribe((c) => {
97
97
  if (!(c.senderId === t || c.transportId !== n)) {
@@ -109,14 +109,14 @@ async function ns(e = we()) {
109
109
  }
110
110
  });
111
111
  if (!s)
112
- e.storage.setItem(Tt, n), r = !0;
112
+ e.storage.setItem(It, n), r = !0;
113
113
  else
114
114
  for (; ; ) {
115
115
  if (i = !1, e.channel.postMessage({ type: "probe", transportId: n, senderId: t }), await e.settle(), !i) {
116
116
  r = !0;
117
117
  break;
118
118
  }
119
- n = e.randomUUID(), e.storage.setItem(Tt, n);
119
+ n = e.randomUUID(), e.storage.setItem(It, n);
120
120
  }
121
121
  let a = !1;
122
122
  return {
@@ -129,24 +129,24 @@ async function ns(e = we()) {
129
129
  async function rs() {
130
130
  $ || ($ = ns(we()), $.then((n) => {
131
131
  const r = (i) => {
132
- i.persisted || (n.release(), $ = null, Q.clear(), window.removeEventListener("pagehide", r));
132
+ i.persisted || (n.release(), $ = null, tt.clear(), window.removeEventListener("pagehide", r));
133
133
  };
134
134
  window.addEventListener("pagehide", r);
135
135
  }));
136
136
  const e = await $, t = is();
137
- Q.add(t);
137
+ tt.add(t);
138
138
  let s = !1;
139
139
  return {
140
140
  // A stable per-tab base keeps reload routing intact, while slots isolate multiple live SDK instances in one tab.
141
141
  transportId: t === 0 ? e.transportId : `${e.transportId}.${t}`,
142
142
  release: () => {
143
- s || (s = !0, Q.delete(t));
143
+ s || (s = !0, tt.delete(t));
144
144
  }
145
145
  };
146
146
  }
147
147
  function is() {
148
148
  let e = 0;
149
- for (; Q.has(e); )
149
+ for (; tt.has(e); )
150
150
  e += 1;
151
151
  return e;
152
152
  }
@@ -162,13 +162,13 @@ function os() {
162
162
  return {
163
163
  getItem: (e) => {
164
164
  try {
165
- return window.sessionStorage?.getItem(e) ?? wt.get(e) ?? null;
165
+ return window.sessionStorage?.getItem(e) ?? At.get(e) ?? null;
166
166
  } catch {
167
- return wt.get(e) ?? null;
167
+ return At.get(e) ?? null;
168
168
  }
169
169
  },
170
170
  setItem: (e, t) => {
171
- wt.set(e, t);
171
+ At.set(e, t);
172
172
  try {
173
173
  window.sessionStorage?.setItem(e, t);
174
174
  } catch {
@@ -192,7 +192,7 @@ function as() {
192
192
  }
193
193
  function cs() {
194
194
  const e = /* @__PURE__ */ new Set(), t = (s) => {
195
- if (s.key !== It || !s.newValue)
195
+ if (s.key !== wt || !s.newValue)
196
196
  return;
197
197
  const n = JSON.parse(s.newValue);
198
198
  for (const r of e)
@@ -201,9 +201,9 @@ function cs() {
201
201
  return window.addEventListener("storage", t), {
202
202
  postMessage: (s) => {
203
203
  window.localStorage.setItem(
204
- It,
204
+ wt,
205
205
  JSON.stringify({ ...s, eventId: crypto.randomUUID() })
206
- ), window.localStorage.removeItem(It);
206
+ ), window.localStorage.removeItem(wt);
207
207
  },
208
208
  subscribe: (s) => (e.add(s), () => e.delete(s)),
209
209
  close: () => {
@@ -211,12 +211,12 @@ function cs() {
211
211
  }
212
212
  };
213
213
  }
214
- const ls = globalThis.fetch.bind(globalThis), Mt = '.pluno-pa-widget-host[data-pluno-product-agent-ui="widget"]', us = '.pluno-pa-widget[data-pluno-product-agent-ui-root="widget"]', ds = ".pluno-pa-widget__panel", hs = ".pluno-pa-widget__timeline", te = `${Mt}[data-pluno-sdk-preview-channel]`, ps = "https://app.pluno.ai", fs = "gpt-5.6-terra", gs = 2e4, ms = 1e4, ys = 1e4, Ts = 1e4, Is = 1e4, ws = 1e3, ee = 3e4, se = 0.2, ne = 6e4, As = 15e3, J = 8, Ss = 15e3, Es = 2e3, bs = 1e3, ks = 100, Rs = 8e3, re = 3, _s = [300, 1e3], Lt = 64e3, At = 4e3, Bt = 30, Ms = 2e3, Cs = 1e3, Ae = "Image is too large for model vision input.", Ps = 100, Se = "pluno.productAgent.state.", Ct = "pluno.productAgent.pendingEvents.", rt = "pluno.productAgent.activeToolCalls.", Us = 100;
214
+ const ls = globalThis.fetch.bind(globalThis), Mt = '.pluno-pa-widget-host[data-pluno-product-agent-ui="widget"]', us = '.pluno-pa-widget[data-pluno-product-agent-ui-root="widget"]', ds = ".pluno-pa-widget__panel", hs = ".pluno-pa-widget__timeline", te = `${Mt}[data-pluno-sdk-preview-channel]`, ps = "https://app.pluno.ai", fs = "gpt-5.6-terra", gs = 2e4, ms = 1e4, ys = 1e4, Ts = 1e4, Is = 1e4, ws = 1e3, ee = 3e4, se = 0.2, ne = 6e4, As = 15e3, J = 8, Ss = 15e3, Es = 2e3, bs = 1e3, ks = 100, Rs = 8e3, re = 3, _s = [300, 1e3], Lt = 64e3, St = 4e3, Bt = 30, Ms = 2e3, Cs = 1e3, Ae = "Image is too large for model vision input.", Ps = 100, Se = "pluno.productAgent.state.", Ct = "pluno.productAgent.pendingEvents.", it = "pluno.productAgent.activeToolCalls.", Us = 100;
215
215
  function V(e, t = 0) {
216
216
  const s = e === 0 ? 0 : Math.min(3e4, 1e3 * 2 ** (e - 1));
217
217
  return Math.max(t, s);
218
218
  }
219
- const tt = /* @__PURE__ */ new Set();
219
+ const et = /* @__PURE__ */ new Set();
220
220
  let Y = null;
221
221
  function Ds(e, t = Math.random) {
222
222
  const s = Math.min(ee, ws * 2 ** e), n = 1 - se + t() * se * 2;
@@ -427,7 +427,7 @@ class Ee {
427
427
  let i = r.map(Wt);
428
428
  if (!n && i.length === 0)
429
429
  return null;
430
- const o = _(), a = s.clientMessageId ?? bt(), c = {
430
+ const o = _(), a = s.clientMessageId ?? kt(), c = {
431
431
  id: `local-${a}`,
432
432
  role: "user",
433
433
  content: n,
@@ -494,7 +494,7 @@ class Ee {
494
494
  return !t || !s ? !1 : (this.retryAttemptsByClientMessageId[s] = 0, this.retryableClientMessageId = null, this.activeClientMessageId = s, this.latestRecoverableClientMessageId = s, this.setState({ status: "connected", isThinking: !0, lastError: null, lastErrorCode: null }), this.markThinkingProgress(), this.send({ type: "chat.retry_last_user_message", sessionId: t, clientMessageId: s, automatic: !1 }), !0);
495
495
  }
496
496
  createLocalAttachment(t) {
497
- const s = bt(), n = {
497
+ const s = kt(), n = {
498
498
  id: s,
499
499
  name: t.name || "attachment",
500
500
  mimeType: me(t),
@@ -543,20 +543,30 @@ class Ee {
543
543
  model: this.options.model,
544
544
  metadata: ie(this.options.metadata),
545
545
  entrySurface: this.options.entrySurface
546
- }, o = this.options.prepareAttachmentUpload ? await Rt(
547
- () => this.options.prepareAttachmentUpload(i),
548
- "Failed to prepare attachment upload"
549
- ) : await this.prepareEmbedAttachmentUpload(i);
550
- await Rt(async () => {
551
- const c = await fetch(new URL(o.uploadUrl, this.options.backendUrl), {
552
- method: o.uploadMethod,
553
- headers: o.uploadHeaders,
554
- body: t
555
- });
556
- if (!c.ok)
557
- throw new et("Failed to upload attachment", c.status);
558
- return c;
559
- }, "Failed to upload attachment"), this.setState({ sessionId: o.sessionId });
546
+ };
547
+ let o;
548
+ if (this.options.persistAttachmentUpload)
549
+ o = await Q(
550
+ () => this.options.persistAttachmentUpload(i, t),
551
+ "Failed to upload attachment"
552
+ );
553
+ else {
554
+ const c = this.options.prepareAttachmentUpload ? await Q(
555
+ () => this.options.prepareAttachmentUpload(i),
556
+ "Failed to prepare attachment upload"
557
+ ) : await this.prepareEmbedAttachmentUpload(i);
558
+ await Q(async () => {
559
+ const l = await fetch(new URL(c.uploadUrl, this.options.backendUrl), {
560
+ method: c.uploadMethod,
561
+ headers: c.uploadHeaders,
562
+ body: t
563
+ });
564
+ if (!l.ok)
565
+ throw new st("Failed to upload attachment", l.status);
566
+ return l;
567
+ }, "Failed to upload attachment"), o = c;
568
+ }
569
+ this.setState({ sessionId: o.sessionId });
560
570
  const a = Ne(o.attachment, this.options.backendUrl);
561
571
  return this.updateAttachmentInState(s.id, a), s.id && Ke(s.id, {
562
572
  sessionId: o.sessionId,
@@ -584,7 +594,7 @@ class Ee {
584
594
  }
585
595
  async prepareEmbedAttachmentUpload(t) {
586
596
  let s = !1;
587
- return await Rt(async () => {
597
+ return await Q(async () => {
588
598
  const n = await this.fetchEmbedAttachmentUpload(t);
589
599
  if (n.ok)
590
600
  return await n.json();
@@ -593,9 +603,9 @@ class Ee {
593
603
  const r = await this.fetchEmbedAttachmentUpload(t);
594
604
  if (r.ok)
595
605
  return await r.json();
596
- throw new et("Failed to prepare attachment upload", r.status);
606
+ throw new st("Failed to prepare attachment upload", r.status);
597
607
  }
598
- throw new et("Failed to prepare attachment upload", n.status);
608
+ throw new st("Failed to prepare attachment upload", n.status);
599
609
  }, "Failed to prepare attachment upload");
600
610
  }
601
611
  async fetchEmbedAttachmentUpload(t) {
@@ -632,7 +642,7 @@ class Ee {
632
642
  });
633
643
  }
634
644
  listSessions(t = {}) {
635
- const s = bt(), n = new Promise((i, o) => {
645
+ const s = kt(), n = new Promise((i, o) => {
636
646
  const a = window.setTimeout(() => {
637
647
  this.pendingSessionHistoryRequests.delete(s), o(new Error("Session history did not respond in time"));
638
648
  }, Rs);
@@ -1340,7 +1350,7 @@ class Ee {
1340
1350
  this.listeners[t]?.forEach((r) => r(s));
1341
1351
  }
1342
1352
  }
1343
- const St = /* @__PURE__ */ new WeakMap();
1353
+ const Et = /* @__PURE__ */ new WeakMap();
1344
1354
  function vs(e) {
1345
1355
  const t = window.__plunoProductAgentNetworkCapture ?? Ns();
1346
1356
  return t.subscribers.add(e), () => {
@@ -1367,8 +1377,8 @@ function Ns() {
1367
1377
  const T = m instanceof Request ? m : null, x = dr(m, T), I = Oe(u?.headers ?? T?.headers);
1368
1378
  if (!N(x, I, u?.body)) {
1369
1379
  const H = {
1370
- requestId: kt("fetch"),
1371
- url: C(x, At),
1380
+ requestId: Rt("fetch"),
1381
+ url: C(x, St),
1372
1382
  method: (u?.method ?? T?.method ?? "GET").toUpperCase(),
1373
1383
  requestHeaders: I,
1374
1384
  requestBody: ye(u?.body),
@@ -1399,21 +1409,21 @@ function Ns() {
1399
1409
  return f;
1400
1410
  }, a = function(m, u, h, f, T) {
1401
1411
  const x = n.call(this, m, u, h ?? !0, f ?? void 0, T ?? void 0), I = typeof u == "string" ? u : u.toString();
1402
- return St.set(this, {
1403
- requestId: kt("xhr"),
1412
+ return Et.set(this, {
1413
+ requestId: Rt("xhr"),
1404
1414
  method: String(m ?? "GET").toUpperCase(),
1405
- url: C(I, At),
1415
+ url: C(I, St),
1406
1416
  requestHeaders: {},
1407
1417
  startedAtMs: Date.now(),
1408
1418
  startedAt: (/* @__PURE__ */ new Date()).toISOString(),
1409
1419
  excluded: N(I)
1410
1420
  }), x;
1411
1421
  }, c = function(m, u) {
1412
- const h = r.call(this, m, u), f = St.get(this);
1422
+ const h = r.call(this, m, u), f = Et.get(this);
1413
1423
  return f && Object.keys(f.requestHeaders).length < Bt && (f.requestHeaders[m] = jt(m, u), f.excluded = f.excluded || N(f.url, f.requestHeaders)), h;
1414
1424
  }, l = function(m) {
1415
1425
  try {
1416
- const u = St.get(this);
1426
+ const u = Et.get(this);
1417
1427
  u && (u.excluded = u.excluded || N(u.url, u.requestHeaders, m), u.requestBody = ye(m), u.excluded || this.addEventListener(
1418
1428
  "loadend",
1419
1429
  () => {
@@ -1470,8 +1480,8 @@ function Ns() {
1470
1480
  continue;
1471
1481
  const h = performance.timeOrigin + u.startTime;
1472
1482
  t({
1473
- requestId: kt("resource"),
1474
- url: C(u.name, At),
1483
+ requestId: Rt("resource"),
1484
+ url: C(u.name, St),
1475
1485
  method: "GET",
1476
1486
  resourceType: "resource",
1477
1487
  responseStatus: u.responseStatus,
@@ -1780,13 +1790,13 @@ function nn() {
1780
1790
  };
1781
1791
  }
1782
1792
  function rn(e) {
1783
- return tt.add(e), Y || (Y = on()), () => {
1784
- tt.delete(e), tt.size === 0 && (Y?.(), Y = null);
1793
+ return et.add(e), Y || (Y = on()), () => {
1794
+ et.delete(e), et.size === 0 && (Y?.(), Y = null);
1785
1795
  };
1786
1796
  }
1787
1797
  function on() {
1788
1798
  const e = () => {
1789
- for (const i of Array.from(tt))
1799
+ for (const i of Array.from(et))
1790
1800
  i();
1791
1801
  }, t = window.history.pushState.bind(window.history), s = window.history.replaceState.bind(window.history), n = ((...i) => {
1792
1802
  const o = t(...i);
@@ -1814,9 +1824,9 @@ function qt() {
1814
1824
  (h) => be(h) && !h.parentElement?.closest(n)
1815
1825
  );
1816
1826
  for (const h of r.slice(0, 3))
1817
- s("Active overlay", Et(j(h), t));
1818
- const i = cn(), o = i ? Et(j(i), t) : "";
1819
- s("Main page content", o), s("Additional visible page text", Et(j(document.body), t));
1827
+ s("Active overlay", bt(j(h), t));
1828
+ const i = cn(), o = i ? bt(j(i), t) : "";
1829
+ s("Main page content", o), s("Additional visible page text", bt(j(document.body), t));
1820
1830
  const a = e.map(([h, f]) => `${h}:
1821
1831
  ${f}`).join(`
1822
1832
 
@@ -1838,7 +1848,7 @@ function B(e) {
1838
1848
 
1839
1849
  `).trim();
1840
1850
  }
1841
- function Et(e, t) {
1851
+ function bt(e, t) {
1842
1852
  let s = B(e);
1843
1853
  for (const n of t)
1844
1854
  s = s.replace(n, "");
@@ -1941,58 +1951,58 @@ function ln(e, t) {
1941
1951
  const U = I.getAttribute("data-testid") || I.getAttribute("data-test") || I.getAttribute("data-qa") || I.getAttribute("data-cy") || "";
1942
1952
  return `${I.tagName.toLowerCase()}|${u(I)}|${U}`;
1943
1953
  }, f = (I, U, H) => {
1944
- const R = (S, ct) => {
1945
- const b = S.tagName.toLowerCase(), lt = window.getComputedStyle(S), z = d.has(S);
1946
- if (m >= 1e3 && !z || H.has(S) || i.has(b) || S.matches(".pluno-pa-widget-host, [data-pluno-product-agent-widget]") || lt.display === "none" || lt.visibility === "hidden")
1954
+ const R = (S, lt) => {
1955
+ const b = S.tagName.toLowerCase(), ut = window.getComputedStyle(S), z = d.has(S);
1956
+ if (m >= 1e3 && !z || H.has(S) || i.has(b) || S.matches(".pluno-pa-widget-host, [data-pluno-product-agent-widget]") || ut.display === "none" || ut.visibility === "hidden")
1947
1957
  return { lines: [], hasUsefulContent: !1, textPreview: "", containsTextElement: !1 };
1948
1958
  m += 1;
1949
- const zt = u(S), G = Re(S), je = a.has(zt) || ["button", "input", "textarea", "select", "iframe", "canvas"].includes(b) || b === "a" && S.hasAttribute("href"), ut = Array.from(S.children).filter((g) => g instanceof HTMLElement), X = /* @__PURE__ */ new Map();
1950
- for (const g of ut) {
1959
+ const zt = u(S), G = Re(S), je = a.has(zt) || ["button", "input", "textarea", "select", "iframe", "canvas"].includes(b) || b === "a" && S.hasAttribute("href"), dt = Array.from(S.children).filter((g) => g instanceof HTMLElement), X = /* @__PURE__ */ new Map();
1960
+ for (const g of dt) {
1951
1961
  const w = h(g);
1952
1962
  X.set(w, (X.get(w) ?? 0) + 1);
1953
1963
  }
1954
- const dt = /* @__PURE__ */ new Map(), Gt = /* @__PURE__ */ new Map();
1955
- for (const g of ut) {
1964
+ const ht = /* @__PURE__ */ new Map(), Gt = /* @__PURE__ */ new Map();
1965
+ for (const g of dt) {
1956
1966
  const w = h(g), D = Gt.get(w) ?? 0;
1957
- Gt.set(w, D + 1), (X.get(w) ?? 0) > 8 && D >= 6 && !d.has(g) && dt.set(w, (dt.get(w) ?? 0) + 1);
1967
+ Gt.set(w, D + 1), (X.get(w) ?? 0) > 8 && D >= 6 && !d.has(g) && ht.set(w, (ht.get(w) ?? 0) + 1);
1958
1968
  }
1959
- const Xt = /* @__PURE__ */ new Map(), Kt = /* @__PURE__ */ new Set(), ht = [], Jt = [];
1960
- for (const g of ut) {
1969
+ const Xt = /* @__PURE__ */ new Map(), Kt = /* @__PURE__ */ new Set(), pt = [], Jt = [];
1970
+ for (const g of dt) {
1961
1971
  const w = h(g), D = X.get(w) ?? 0, Zt = Xt.get(w) ?? 0;
1962
1972
  if (Xt.set(w, Zt + 1), D > 8 && Zt >= 6 && !d.has(g)) {
1963
- Kt.has(w) || (ht.push([`… ${dt.get(w) ?? 0} similar siblings omitted`]), Kt.add(w));
1973
+ Kt.has(w) || (pt.push([`… ${ht.get(w) ?? 0} similar siblings omitted`]), Kt.add(w));
1964
1974
  continue;
1965
1975
  }
1966
- const Qt = R(g, ct);
1967
- Jt.push(Qt), ht.push(Qt.lines);
1976
+ const Qt = R(g, lt);
1977
+ Jt.push(Qt), pt.push(Qt.lines);
1968
1978
  }
1969
- const pt = [];
1979
+ const ft = [];
1970
1980
  if (S.shadowRoot)
1971
1981
  for (const g of Array.from(S.shadowRoot.children))
1972
- g instanceof HTMLElement && pt.push(R(g, ct + 1));
1973
- const K = [...Jt, ...pt], ft = G.length > 0 || je || K.some((g) => g.hasUsefulContent), Vt = B(
1982
+ g instanceof HTMLElement && ft.push(R(g, lt + 1));
1983
+ const K = [...Jt, ...ft], gt = G.length > 0 || je || K.some((g) => g.hasUsefulContent), Vt = B(
1974
1984
  [G, ...K.map((g) => g.textPreview)].filter(Boolean).join(" ")
1975
- ).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(b) || Yt || z) && (ft || z) && (!r.has(b) || ft || Yt || z), mt = gt ? 1 : 0, F = [];
1976
- if (gt) {
1985
+ ).slice(0, 180), ze = S.hasAttribute("contenteditable") && (G.length > 0 || !S.querySelector("[contenteditable]")), Yt = l.some((g) => S.hasAttribute(g)) || !!zt || ze, mt = (S.getClientRects().length > 0 || ut.display === "contents") && (s.has(b) || Yt || z) && (gt || z) && (!r.has(b) || gt || Yt || z), yt = mt ? 1 : 0, F = [];
1986
+ if (mt) {
1977
1987
  const g = K.some((D) => D.containsTextElement), w = n.has(b) && !g ? Vt : G;
1978
1988
  F.push(ke(S, c, o, w.slice(0, 180)));
1979
1989
  }
1980
- for (const g of ht)
1981
- F.push(...Z(g, mt));
1982
- const yt = pt.flatMap((g) => g.lines);
1983
- if (yt.length > 0) {
1984
- const g = yt.slice(0, 20);
1985
- yt.length > g.length && g.push("… shadow DOM omitted");
1990
+ for (const g of pt)
1991
+ F.push(...Z(g, yt));
1992
+ const Tt = ft.flatMap((g) => g.lines);
1993
+ if (Tt.length > 0) {
1994
+ const g = Tt.slice(0, 20);
1995
+ Tt.length > g.length && g.push("… shadow DOM omitted");
1986
1996
  const w = b.includes("tooltip") || b.includes("popper") || b.includes("loader");
1987
- if (ct < 2 && !w) {
1988
- const D = gt ? "#shadow-root" : `${b} #shadow-root`;
1989
- F.push(...Z([D, ...Z(g, 1)], mt));
1997
+ if (lt < 2 && !w) {
1998
+ const D = mt ? "#shadow-root" : `${b} #shadow-root`;
1999
+ F.push(...Z([D, ...Z(g, 1)], yt));
1990
2000
  } else
1991
- F.push(...Z(g, mt));
2001
+ F.push(...Z(g, yt));
1992
2002
  }
1993
2003
  return {
1994
2004
  lines: F,
1995
- hasUsefulContent: ft,
2005
+ hasUsefulContent: gt,
1996
2006
  textPreview: Vt,
1997
2007
  containsTextElement: n.has(b) || K.some((g) => g.containsTextElement)
1998
2008
  };
@@ -2200,7 +2210,7 @@ function In() {
2200
2210
  const s = crypto.randomUUID();
2201
2211
  return window.localStorage.setItem(e, s), s;
2202
2212
  }
2203
- function bt() {
2213
+ function kt() {
2204
2214
  return crypto.randomUUID();
2205
2215
  }
2206
2216
  function wn(e) {
@@ -2533,7 +2543,7 @@ function De(e) {
2533
2543
  function qn(e) {
2534
2544
  return q(e) ? !0 : e.role !== "system" ? !1 : e.dataType === "run_error" ? !0 : e.dataType === "run_status" && e.loading !== !0;
2535
2545
  }
2536
- function it(e) {
2546
+ function ot(e) {
2537
2547
  for (let t = e.length - 1; t >= 0; t -= 1) {
2538
2548
  const s = e[t];
2539
2549
  if (!s || typeof s != "object")
@@ -2548,7 +2558,7 @@ function it(e) {
2548
2558
  return null;
2549
2559
  }
2550
2560
  function Hn(e) {
2551
- const t = it(e);
2561
+ const t = ot(e);
2552
2562
  if (t === null)
2553
2563
  return null;
2554
2564
  const n = L(e[t])?.page;
@@ -2570,7 +2580,7 @@ function he(e) {
2570
2580
  return e?.type === "run_status" && e.status === "interrupted" && e.reason === "backend_restart";
2571
2581
  }
2572
2582
  function Fn(e, t) {
2573
- const s = it(t);
2583
+ const s = ot(t);
2574
2584
  if (s === null)
2575
2585
  return !1;
2576
2586
  const n = t[s], r = n && typeof n == "object" ? n.id : null;
@@ -2580,7 +2590,7 @@ function Fn(e, t) {
2580
2590
  return i === -1 ? !1 : e.slice(i + 1).some(qn);
2581
2591
  }
2582
2592
  function Ut(e) {
2583
- const t = it(e);
2593
+ const t = ot(e);
2584
2594
  if (t === null)
2585
2595
  return null;
2586
2596
  const s = e[t];
@@ -2593,7 +2603,7 @@ function Ut(e) {
2593
2603
  return typeof r == "string" ? r : null;
2594
2604
  }
2595
2605
  function $n(e) {
2596
- const t = it(e);
2606
+ const t = ot(e);
2597
2607
  if (t === null)
2598
2608
  return null;
2599
2609
  for (let s = e.length - 1; s > t; s -= 1) {
@@ -2687,7 +2697,7 @@ function Xn(e, t) {
2687
2697
  const r = e[n];
2688
2698
  if (r.role === "user")
2689
2699
  return !1;
2690
- if (r.role === "assistant" && ot(s, r))
2700
+ if (r.role === "assistant" && at(s, r))
2691
2701
  return !0;
2692
2702
  }
2693
2703
  return !1;
@@ -2708,25 +2718,25 @@ function Kn(e, t) {
2708
2718
  function Jn(e, t) {
2709
2719
  const s = e[t];
2710
2720
  for (let n = t + 1; n < e.length; n += 1)
2711
- if (e[n].role === "assistant" && ot(s, e[n]))
2721
+ if (e[n].role === "assistant" && at(s, e[n]))
2712
2722
  return !0;
2713
2723
  return !1;
2714
2724
  }
2715
2725
  function Vn(e, t) {
2716
2726
  const s = e[t];
2717
2727
  for (let n = t + 1; n < e.length; n += 1)
2718
- if (e[n].role === "tool" && ot(s, e[n]))
2728
+ if (e[n].role === "tool" && at(s, e[n]))
2719
2729
  return !0;
2720
2730
  return !1;
2721
2731
  }
2722
2732
  function Yn(e, t) {
2723
2733
  const s = e[t];
2724
2734
  for (let n = t + 1; n < e.length; n += 1)
2725
- if (Ft(e[n]) && ot(s, e[n]))
2735
+ if (Ft(e[n]) && at(s, e[n]))
2726
2736
  return !0;
2727
2737
  return !1;
2728
2738
  }
2729
- function ot(e, t) {
2739
+ function at(e, t) {
2730
2740
  return !e.runId || !t.runId ? !0 : e.runId === t.runId;
2731
2741
  }
2732
2742
  function E(e, t) {
@@ -2790,7 +2800,7 @@ function W(e, t) {
2790
2800
  }
2791
2801
  function xe(e, t) {
2792
2802
  try {
2793
- const s = `${rt}${e}`, n = location.href, r = location.origin, i = Array.from(t, (o) => ({
2803
+ const s = `${it}${e}`, n = location.href, r = location.origin, i = Array.from(t, (o) => ({
2794
2804
  ...o,
2795
2805
  storedAt: Date.now(),
2796
2806
  unloadUrl: n,
@@ -2806,7 +2816,7 @@ function xe(e, t) {
2806
2816
  }
2807
2817
  function er(e, t) {
2808
2818
  try {
2809
- if (window.sessionStorage.getItem(`${rt}${e}`) === null)
2819
+ if (window.sessionStorage.getItem(`${it}${e}`) === null)
2810
2820
  return;
2811
2821
  } catch {
2812
2822
  return;
@@ -2815,7 +2825,7 @@ function er(e, t) {
2815
2825
  }
2816
2826
  function sr(e) {
2817
2827
  try {
2818
- const t = `${rt}${e}`, s = window.sessionStorage.getItem(t);
2828
+ const t = `${it}${e}`, s = window.sessionStorage.getItem(t);
2819
2829
  if (window.sessionStorage.removeItem(t), !s)
2820
2830
  return [];
2821
2831
  const n = JSON.parse(s);
@@ -2863,7 +2873,7 @@ function ir(e, t) {
2863
2873
  }
2864
2874
  function or(e) {
2865
2875
  try {
2866
- window.sessionStorage.removeItem(`${rt}${e}`);
2876
+ window.sessionStorage.removeItem(`${it}${e}`);
2867
2877
  } catch {
2868
2878
  return;
2869
2879
  }
@@ -2960,7 +2970,7 @@ function Oe(e) {
2960
2970
  return t;
2961
2971
  }
2962
2972
  function jt(e, t) {
2963
- return $e(e) ? at : C(nt(t), Ms);
2973
+ return $e(e) ? ct : C(rt(t), Ms);
2964
2974
  }
2965
2975
  function dr(e, t) {
2966
2976
  return typeof e == "string" ? e : e instanceof URL ? e.toString() : t?.url ?? "";
@@ -3031,11 +3041,11 @@ function Te(e) {
3031
3041
  return e;
3032
3042
  const t = e.trim();
3033
3043
  if (!t.startsWith("{") && !t.startsWith("["))
3034
- return nt(e);
3044
+ return rt(e);
3035
3045
  try {
3036
3046
  return JSON.stringify(k(JSON.parse(e)));
3037
3047
  } catch {
3038
- return nt(e);
3048
+ return rt(e);
3039
3049
  }
3040
3050
  }
3041
3051
  function Le(e) {
@@ -3089,16 +3099,16 @@ function Tr(e) {
3089
3099
  function C(e, t = Lt) {
3090
3100
  return e.length <= t ? e : `${e.slice(0, t)}... [truncated ${e.length - t} chars]`;
3091
3101
  }
3092
- function kt(e) {
3102
+ function Rt(e) {
3093
3103
  return `${e}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
3094
3104
  }
3095
- class et extends Error {
3105
+ class st extends Error {
3096
3106
  constructor(t, s) {
3097
3107
  super(`${t} (${s})`), this.status = s, this.name = "AttachmentUploadHttpError";
3098
3108
  }
3099
3109
  status;
3100
3110
  }
3101
- async function Rt(e, t) {
3111
+ async function Q(e, t) {
3102
3112
  let s = null;
3103
3113
  for (let n = 0; n < re; n += 1)
3104
3114
  try {
@@ -3116,7 +3126,7 @@ function Ir(e) {
3116
3126
  });
3117
3127
  }
3118
3128
  function wr(e) {
3119
- return e instanceof et ? Ar(e.status) : e instanceof TypeError;
3129
+ return e instanceof st ? Ar(e.status) : e instanceof TypeError;
3120
3130
  }
3121
3131
  function Ar(e) {
3122
3132
  return e === 408 || e === 409 || e === 429 || e >= 500;
@@ -3124,13 +3134,13 @@ function Ar(e) {
3124
3134
  function Sr(e) {
3125
3135
  return e === 401 || e === 403;
3126
3136
  }
3127
- const at = "[REDACTED_SECRET]", P = "[REDACTED_TOKEN]", Er = "[REDACTED_SIGNED_URL]", br = 20, kr = /^(access_token|accessToken|refresh_token|refreshToken|id_token|idToken|authToken|token|api_key|apiKey|apikey|key|secret|signature|sig|password|passwd|pwd|code|state|session|jwt|csrf|csrfToken|xsrf|xsrfToken)$/i, Be = /\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi, qe = /\bBasic\s+[A-Za-z0-9+/=-]{12,}/gi, He = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g, Fe = /\b(access_token|accessToken|refresh_token|refreshToken|id_token|idToken|authToken|api_key|apiKey|apikey|client_secret|clientSecret|password|secret|token|jwt|csrf|csrfToken|xsrf|xsrfToken)\b\s*[:=]\s*["']?[^"',&\s}]+/gi, Rr = /\bhttps?:\/\/[^\s"'<>]+(?:X-Amz-Signature|X-Goog-Signature|Signature|sig=)[^\s"'<>]*/gi, _r = /\bhttps?:\/\/[^\s"'<>]+/gi, Mr = /[),.;\]]+$/;
3137
+ const ct = "[REDACTED_SECRET]", P = "[REDACTED_TOKEN]", Er = "[REDACTED_SIGNED_URL]", br = 20, kr = /^(access_token|accessToken|refresh_token|refreshToken|id_token|idToken|authToken|token|api_key|apiKey|apikey|key|secret|signature|sig|password|passwd|pwd|code|state|session|jwt|csrf|csrfToken|xsrf|xsrfToken)$/i, Be = /\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi, qe = /\bBasic\s+[A-Za-z0-9+/=-]{12,}/gi, He = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g, Fe = /\b(access_token|accessToken|refresh_token|refreshToken|id_token|idToken|authToken|api_key|apiKey|apikey|client_secret|clientSecret|password|secret|token|jwt|csrf|csrfToken|xsrf|xsrfToken)\b\s*[:=]\s*["']?[^"',&\s}]+/gi, Rr = /\bhttps?:\/\/[^\s"'<>]+(?:X-Amz-Signature|X-Goog-Signature|Signature|sig=)[^\s"'<>]*/gi, _r = /\bhttps?:\/\/[^\s"'<>]+/gi, Mr = /[),.;\]]+$/;
3128
3138
  function k(e) {
3129
- return st(e, 0, /* @__PURE__ */ new WeakSet());
3139
+ return nt(e, 0, /* @__PURE__ */ new WeakSet());
3130
3140
  }
3131
- function st(e, t, s) {
3141
+ function nt(e, t, s) {
3132
3142
  if (typeof e == "string")
3133
- return e.startsWith("data:image/") || e.startsWith("data:application/pdf;") ? e : nt(e);
3143
+ return e.startsWith("data:image/") || e.startsWith("data:application/pdf;") ? e : rt(e);
3134
3144
  if (e === null || typeof e != "object")
3135
3145
  return e;
3136
3146
  if (t >= br)
@@ -3138,10 +3148,10 @@ function st(e, t, s) {
3138
3148
  if (s.has(e))
3139
3149
  return "[REDACTED_CIRCULAR]";
3140
3150
  if (s.add(e), Array.isArray(e))
3141
- return e.map((r) => st(r, t + 1, s));
3151
+ return e.map((r) => nt(r, t + 1, s));
3142
3152
  const n = {};
3143
3153
  for (const [r, i] of Object.entries(e))
3144
- r === "pageContent" ? n[r] = i : $e(r) ? n[r] = at : n[r] = r.toLowerCase() === "url" ? Cr(i) : st(i, t + 1, s);
3154
+ r === "pageContent" ? n[r] = i : $e(r) ? n[r] = ct : n[r] = r.toLowerCase() === "url" ? Cr(i) : nt(i, t + 1, s);
3145
3155
  return n;
3146
3156
  }
3147
3157
  function $e(e) {
@@ -3149,7 +3159,7 @@ function $e(e) {
3149
3159
  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");
3150
3160
  }
3151
3161
  function Cr(e) {
3152
- return typeof e == "string" ? We(e) : st(e, 0, /* @__PURE__ */ new WeakSet());
3162
+ return typeof e == "string" ? We(e) : nt(e, 0, /* @__PURE__ */ new WeakSet());
3153
3163
  }
3154
3164
  function We(e) {
3155
3165
  try {
@@ -3161,11 +3171,11 @@ function We(e) {
3161
3171
  return Pr(e);
3162
3172
  }
3163
3173
  }
3164
- function nt(e) {
3165
- return e.replace(Rr, Er).replace(_r, Ur).replace(Be, `Bearer ${P}`).replace(qe, `Basic ${P}`).replace(He, P).replace(Fe, (t, s) => `${s}: ${at}`);
3174
+ function rt(e) {
3175
+ return e.replace(Rr, Er).replace(_r, Ur).replace(Be, `Bearer ${P}`).replace(qe, `Basic ${P}`).replace(He, P).replace(Fe, (t, s) => `${s}: ${ct}`);
3166
3176
  }
3167
3177
  function Pr(e) {
3168
- return e.replace(Be, `Bearer ${P}`).replace(qe, `Basic ${P}`).replace(He, P).replace(Fe, (t, s) => `${s}: ${at}`);
3178
+ return e.replace(Be, `Bearer ${P}`).replace(qe, `Basic ${P}`).replace(He, P).replace(Fe, (t, s) => `${s}: ${ct}`);
3169
3179
  }
3170
3180
  function Ur(e) {
3171
3181
  const t = e.match(Mr)?.[0] ?? "", s = t ? e.slice(0, -t.length) : e;