@pluno/product-agent-web 0.1.166 → 0.1.167

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.
@@ -135,11 +135,11 @@ function Ms(t, e, s, n) {
135
135
  return !i.isActivity || !i.isTransient ? !0 : e !== null && i.respondsToUserMessageId !== void 0 ? i.respondsToUserMessageId !== e : s === null || i.runId !== s;
136
136
  });
137
137
  }
138
- const _e = "pluno.productAgent.transportId", As = "pluno.productAgent.transportIdentity", ke = "pluno.productAgent.transportIdentity.event", Rs = 50, Es = globalThis.setTimeout.bind(globalThis);
138
+ const ke = "pluno.productAgent.transportId", As = "pluno.productAgent.transportIdentity", _e = "pluno.productAgent.transportIdentity.event", Rs = 50, Es = globalThis.setTimeout.bind(globalThis);
139
139
  let Q = null;
140
140
  const he = /* @__PURE__ */ new Set(), Pe = /* @__PURE__ */ new Map();
141
141
  async function Cs(t = Lt()) {
142
- const e = t.randomUUID(), s = t.storage.getItem(_e);
142
+ const e = t.randomUUID(), s = t.storage.getItem(ke);
143
143
  let n = s ?? t.randomUUID(), r = !1, i = !1;
144
144
  const o = t.channel.subscribe((l) => {
145
145
  if (!(l.senderId === e || l.transportId !== n)) {
@@ -157,14 +157,14 @@ async function Cs(t = Lt()) {
157
157
  }
158
158
  });
159
159
  if (!s)
160
- t.storage.setItem(_e, n), r = !0;
160
+ t.storage.setItem(ke, n), r = !0;
161
161
  else
162
162
  for (; ; ) {
163
163
  if (i = !1, t.channel.postMessage({ type: "probe", transportId: n, senderId: e }), await t.settle(), !i) {
164
164
  r = !0;
165
165
  break;
166
166
  }
167
- n = t.randomUUID(), t.storage.setItem(_e, n);
167
+ n = t.randomUUID(), t.storage.setItem(ke, n);
168
168
  }
169
169
  let a = !1;
170
170
  return {
@@ -181,7 +181,7 @@ async function bs() {
181
181
  };
182
182
  window.addEventListener("pagehide", r);
183
183
  }));
184
- const t = await Q, e = _s();
184
+ const t = await Q, e = ks();
185
185
  he.add(e);
186
186
  let s = !1;
187
187
  return {
@@ -192,7 +192,7 @@ async function bs() {
192
192
  }
193
193
  };
194
194
  }
195
- function _s() {
195
+ function ks() {
196
196
  let t = 0;
197
197
  for (; he.has(t); )
198
198
  t += 1;
@@ -200,13 +200,13 @@ function _s() {
200
200
  }
201
201
  function Lt() {
202
202
  return {
203
- storage: ks(),
203
+ storage: _s(),
204
204
  channel: Ps(),
205
205
  randomUUID: () => crypto.randomUUID(),
206
206
  settle: () => new Promise((t) => Es(t, Rs))
207
207
  };
208
208
  }
209
- function ks() {
209
+ function _s() {
210
210
  return {
211
211
  getItem: (t) => {
212
212
  try {
@@ -240,7 +240,7 @@ function Ps() {
240
240
  }
241
241
  function Us() {
242
242
  const t = /* @__PURE__ */ new Set(), e = (s) => {
243
- if (s.key !== ke || !s.newValue)
243
+ if (s.key !== _e || !s.newValue)
244
244
  return;
245
245
  const n = JSON.parse(s.newValue);
246
246
  for (const r of t)
@@ -249,9 +249,9 @@ function Us() {
249
249
  return window.addEventListener("storage", e), {
250
250
  postMessage: (s) => {
251
251
  window.localStorage.setItem(
252
- ke,
252
+ _e,
253
253
  JSON.stringify({ ...s, eventId: crypto.randomUUID() })
254
- ), window.localStorage.removeItem(ke);
254
+ ), window.localStorage.removeItem(_e);
255
255
  },
256
256
  subscribe: (s) => (t.add(s), () => t.delete(s)),
257
257
  close: () => {
@@ -332,7 +332,7 @@ function Ue(t, e, s) {
332
332
  };
333
333
  window.dispatchEvent(new CustomEvent("product-agent:trace", { detail: r }));
334
334
  }
335
- const xs = "https://app.pluno.ai", Bs = "gpt-5.6-terra", Ws = 2e4, Hs = 1e4, $s = 1e4, js = 1e4, Fs = 1e4, zs = 3e3, Ks = 3e4, Gs = 1e3, gt = 3e4, ft = 0.2, mt = 6e4, Xs = 15e3, Z = 8, Vs = "Pluno could not finish this message. Try it again.", Js = "Browser connection was interrupted.", yt = 15e3, Ys = "Pluno could not send this message. Try it again.", It = 2e3, Qs = 1e3, Zs = 100, Tt = 8e3, en = 8e3, St = 3, tn = [300, 1e3], qt = 50 * 1024 * 1024, sn = /* @__PURE__ */ new Set([
335
+ const xs = "https://app.pluno.ai", Bs = "gpt-5.6-terra", Ws = 2e4, Hs = 1e4, $s = 1e4, Fs = 1e4, js = 1e4, zs = 3e3, Ks = 3e4, Gs = 1e3, gt = 3e4, ft = 0.2, mt = 6e4, Xs = 15e3, Z = 8, Vs = "Pluno could not finish this message. Try it again.", Js = "Browser connection was interrupted.", yt = 15e3, Ys = "Pluno could not send this message. Try it again.", It = 2e3, Qs = 1e3, Zs = 100, Tt = 8e3, en = 8e3, St = 3, tn = [300, 1e3], qt = 50 * 1024 * 1024, sn = /* @__PURE__ */ new Set([
336
336
  ".jpeg:image/jpeg",
337
337
  ".jpg:image/jpeg",
338
338
  ".pdf:application/pdf",
@@ -366,7 +366,7 @@ class Wt {
366
366
  constructor(e, s) {
367
367
  this.options = e, this.transportIdentity = s, this.state = {
368
368
  ...this.state,
369
- starterPrompts: jn(e.initialStarterPrompts)
369
+ starterPrompts: Fn(e.initialStarterPrompts)
370
370
  };
371
371
  const n = e.restorePersistedState === !1 ? null : Dr(e.clientId, e.expectedPersistedSessionId);
372
372
  n && (this.state = {
@@ -391,7 +391,7 @@ class Wt {
391
391
  const r = [...this.queuedClientEvents].reverse().find(
392
392
  (i) => i.type === "chat.user_message" && typeof i.clientMessageId == "string"
393
393
  );
394
- r?.clientMessageId && (this.pendingClientMessageId = r.clientMessageId, this.pendingUserMessageEvent = r, this.state.pendingMessageStatus = "reconnecting", this.state.turnPhase = "sending"), F(e.clientId, this.queuedClientEvents);
394
+ r?.clientMessageId && (this.pendingClientMessageId = r.clientMessageId, this.pendingUserMessageEvent = r, this.state.pendingMessageStatus = "reconnecting", this.state.turnPhase = "sending"), j(e.clientId, this.queuedClientEvents);
395
395
  }
396
396
  options;
397
397
  listeners = {};
@@ -405,6 +405,8 @@ class Wt {
405
405
  connectionAttemptId = 0;
406
406
  connectionInProgress = !1;
407
407
  token = null;
408
+ authenticatedUserId = null;
409
+ authenticatedSocket = null;
408
410
  networkCaptureCleanup = null;
409
411
  networkBatchTimer = null;
410
412
  queuedNetworkEvents = [];
@@ -492,11 +494,11 @@ class Wt {
492
494
  static async init(e) {
493
495
  const s = await bs(), n = new Wt({
494
496
  ...e,
495
- backendUrl: _n(e.backendUrl ?? xs),
497
+ backendUrl: kn(e.backendUrl ?? xs),
496
498
  clientId: e.clientId ?? Xn(),
497
499
  model: e.model ?? Bs,
498
500
  productVariant: e.productVariant ?? "customer_embedded",
499
- entrySurface: kn(e.entrySurface)
501
+ entrySurface: _n(e.entrySurface)
500
502
  }, s);
501
503
  try {
502
504
  gs().catch((r) => {
@@ -537,7 +539,7 @@ class Wt {
537
539
  const s = Dn(this.options.backendUrl), n = this.options.webSocketFactory?.(s) ?? new WebSocket(s);
538
540
  this.socket = n, this.socketConnectTimer = window.setTimeout(() => {
539
541
  this.socket === n && n.readyState === WebSocket.CONNECTING && (R("web-sdk.agent", "Pluno socket opening timed out; reconnecting"), this.replaceTimedOutSocket(n));
540
- }, js), n.addEventListener("open", () => {
542
+ }, Fs), n.addEventListener("open", () => {
541
543
  this.socket !== n || (this.clearSocketConnectTimer(), R("web-sdk.agent", "Pluno socket opened", {
542
544
  queuedClientEventCount: this.queuedClientEvents.length,
543
545
  isThinking: this.state.isThinking
@@ -549,7 +551,7 @@ class Wt {
549
551
  pageUrl: location.href
550
552
  }) : !0)) || (this.socketAuthTimer = window.setTimeout(() => {
551
553
  this.socket === n && (R("web-sdk.agent", "Pluno socket authentication timed out; reconnecting"), this.replaceTimedOutSocket(n));
552
- }, Fs));
554
+ }, js));
553
555
  }), n.addEventListener("message", (r) => {
554
556
  this.socket === n && this.handleServerEvent(Hn(r.data));
555
557
  }), n.addEventListener("sendfailure", (r) => {
@@ -558,7 +560,7 @@ class Wt {
558
560
  const i = $n(r?.detail?.data);
559
561
  i?.type === "chat.user_message" && i.clientMessageId === this.pendingClientMessageId && !this.queuedClientEvents.some(
560
562
  (o) => o.type === "chat.user_message" && o.clientMessageId === i.clientMessageId
561
- ) && (this.queuedClientEvents.push(i), F(this.options.clientId, this.queuedClientEvents), this.setState({ pendingMessageStatus: "reconnecting" })), this.clearSocketPhaseTimers(), this.stopHeartbeat(), this.socket = null, this.setReconnectingState(), this.scheduleReconnect(), n.readyState !== WebSocket.CLOSED && n.readyState !== WebSocket.CLOSING && n.close();
563
+ ) && (this.queuedClientEvents.push(i), j(this.options.clientId, this.queuedClientEvents), this.setState({ pendingMessageStatus: "reconnecting" })), this.clearSocketPhaseTimers(), this.stopHeartbeat(), this.socket = null, this.setReconnectingState(), this.scheduleReconnect(), n.readyState !== WebSocket.CLOSED && n.readyState !== WebSocket.CLOSING && n.close();
562
564
  }), n.addEventListener("close", (r) => {
563
565
  this.socket === n && (this.clearSocketPhaseTimers(), this.stopHeartbeat(), this.socket = null, this.state.status !== "closed" && (this.rememberBrowserConnectionInterruptionForActiveRun(), R("web-sdk.agent", "Pluno socket closed; scheduling reconnect", {
564
566
  code: typeof r?.code == "number" ? r.code : null,
@@ -596,7 +598,7 @@ class Wt {
596
598
  e?.clear();
597
599
  }
598
600
  warmup(e = "panel_open") {
599
- const s = _(), n = `${this.state.sessionId ?? "draft"}:${s.url}`, r = e === "composer_input" && this.pendingComposerWarmup?.scope === n ? this.pendingComposerWarmup : null, i = {
601
+ const s = k(), n = `${this.state.sessionId ?? "draft"}:${s.url}`, r = e === "composer_input" && this.pendingComposerWarmup?.scope === n ? this.pendingComposerWarmup : null, i = {
600
602
  type: "runtime.warmup",
601
603
  reason: e,
602
604
  ...e === "composer_input" ? { warmupId: r?.event.warmupId ?? $() } : {},
@@ -624,7 +626,7 @@ class Wt {
624
626
  return null;
625
627
  if (this.pendingClientMessageId)
626
628
  throw new Error("Wait for the current message to finish sending before sending another.");
627
- const o = _(), a = s.clientMessageId ?? $(), l = {
629
+ const o = k(), a = s.clientMessageId ?? $(), l = {
628
630
  id: `local-${a}`,
629
631
  role: "user",
630
632
  content: n,
@@ -722,7 +724,7 @@ class Wt {
722
724
  mimeType: n.mimeType,
723
725
  sizeBytes: n.sizeBytes,
724
726
  blob: e,
725
- origin: _().origin,
727
+ origin: k().origin,
726
728
  sessionId: this.state.sessionId ?? void 0,
727
729
  createdAt: r,
728
730
  lastUsedAt: r
@@ -753,7 +755,7 @@ class Wt {
753
755
  name: e.name || "attachment",
754
756
  mimeType: r,
755
757
  sizeBytes: e.size,
756
- page: _(),
758
+ page: k(),
757
759
  model: this.options.model,
758
760
  metadata: wt(this.options.metadata),
759
761
  entrySurface: this.options.entrySurface
@@ -881,7 +883,7 @@ class Wt {
881
883
  type: "session.reset",
882
884
  sessionId: this.state.sessionId ?? void 0,
883
885
  warmupId: n ?? void 0,
884
- page: _()
886
+ page: k()
885
887
  }), this.setState({
886
888
  sessionId: null,
887
889
  starterPrompts: [...this.state.starterPrompts],
@@ -909,7 +911,7 @@ class Wt {
909
911
  }), r = {
910
912
  type: "sessions.list",
911
913
  requestId: s,
912
- page: _(),
914
+ page: k(),
913
915
  ...e.cursor ? { cursor: e.cursor } : {},
914
916
  ...e.limit ? { limit: e.limit } : {},
915
917
  ...typeof e.pinned == "boolean" ? { pinned: e.pinned } : {}
@@ -939,7 +941,7 @@ class Wt {
939
941
  !this.options.keepRunsActiveOnSessionNavigation && this.state.sessionId && (this.state.isThinking || this.state.pendingMessageStatus !== null) && this.send({ type: "run.stop", sessionId: this.state.sessionId, reason: "session_switch" }), this.options.keepRunsActiveOnSessionNavigation && (this.rememberCurrentRunAsBackground(), this.backgroundSessionIds.delete(e), this.deferredSessionUpdatedSessionIds.delete(e)), this.clearPendingComposerWarmup(), n && this.send({
940
942
  type: "session.reset",
941
943
  warmupId: n,
942
- page: _()
944
+ page: k()
943
945
  }), this.clearThinkingWatchdog(), this.clearPendingDeliveryTimers(), this.pendingClientMessageId = null, this.pendingUserMessageEvent = null, this.failedUserMessageEvent = null, this.lastUserMessagePageUrl = null, this.clearSessionLoadRequest(), this.sessionLoadRequestId = s, this.sessionLoadRequestTimer = window.setTimeout(() => {
944
946
  this.sessionLoadRequestId === s && (this.clearSessionLoadRequest(), this.setState({
945
947
  isLoadingSession: !1,
@@ -965,7 +967,7 @@ class Wt {
965
967
  type: "session.load",
966
968
  requestId: s,
967
969
  sessionId: e,
968
- page: _()
970
+ page: k()
969
971
  });
970
972
  }
971
973
  loadOlderMessages() {
@@ -978,13 +980,13 @@ class Wt {
978
980
  sessionId: this.state.sessionId,
979
981
  cursor: this.sessionItemsCursor,
980
982
  limit: 50,
981
- page: _()
983
+ page: k()
982
984
  });
983
985
  }
984
986
  send(e) {
985
987
  this.sendNow(v(e)) || (e.type === "chat.user_message" && typeof e.clientMessageId == "string" && this.queuedClientEvents.some(
986
988
  (r) => r.type === "chat.user_message" && r.clientMessageId === e.clientMessageId
987
- ) || this.queuedClientEvents.push(e), F(this.options.clientId, this.queuedClientEvents), this.setState({
989
+ ) || this.queuedClientEvents.push(e), j(this.options.clientId, this.queuedClientEvents), this.setState({
988
990
  status: "reconnecting",
989
991
  ...e.type === "chat.user_message" && e.clientMessageId === this.pendingClientMessageId ? { pendingMessageStatus: "reconnecting" } : {}
990
992
  }), this.scheduleReconnect());
@@ -1076,16 +1078,19 @@ class Wt {
1076
1078
  if (this.socket?.readyState !== WebSocket.OPEN || this.queuedClientEvents.length === 0)
1077
1079
  return;
1078
1080
  const e = this.queuedClientEvents.splice(0, this.queuedClientEvents.length);
1079
- F(this.options.clientId, this.queuedClientEvents);
1081
+ j(this.options.clientId, this.queuedClientEvents);
1080
1082
  for (let s = 0; s < e.length; s += 1) {
1081
1083
  const n = e[s];
1082
1084
  if (!this.sendNow(v(n))) {
1083
- this.queuedClientEvents.unshift(n, ...e.slice(s + 1)), F(this.options.clientId, this.queuedClientEvents);
1085
+ this.queuedClientEvents.unshift(n, ...e.slice(s + 1)), j(this.options.clientId, this.queuedClientEvents);
1084
1086
  return;
1085
1087
  }
1086
- F(this.options.clientId, this.queuedClientEvents);
1088
+ j(this.options.clientId, this.queuedClientEvents);
1087
1089
  }
1088
1090
  }
1091
+ resetForAuthenticationScopeChange() {
1092
+ this.startNewSession({ notifyTransport: !1 }), this.queuedClientEvents = [], j(this.options.clientId, this.queuedClientEvents), this.backgroundSessionIds.clear(), this.backgroundClientMessageIds.clear(), this.deferredSessionUpdatedSessionIds.clear();
1093
+ }
1089
1094
  flushPendingPassiveWarmup() {
1090
1095
  !this.pendingPassiveWarmupEvent || !this.sendNow(this.pendingPassiveWarmupEvent) || (this.pendingPassiveWarmupEvent = null);
1091
1096
  }
@@ -1197,22 +1202,24 @@ class Wt {
1197
1202
  return;
1198
1203
  }
1199
1204
  if (hn(e) && this.markThinkingProgress(), e.type === "auth.ok") {
1200
- this.clearSocketAuthTimer(), this.reconnectAttempts = 0, this.flushPendingComposerWarmup(), this.flushQueuedClientEvents(), this.pendingClientMessageId && (this.setState({ pendingMessageStatus: "sending" }), this.schedulePendingDeliveryAck(this.pendingClientMessageId)), this.flushPendingPassiveWarmup(), this.startHeartbeat();
1201
- const s = Fn(e), n = Object.prototype.hasOwnProperty.call(e, "appearance");
1205
+ this.clearSocketAuthTimer(), this.reconnectAttempts = 0;
1206
+ const s = Vn(e.user);
1207
+ this.authenticatedSocket !== this.socket && this.authenticatedUserId && s && s.id !== this.authenticatedUserId && this.resetForAuthenticationScopeChange(), this.authenticatedUserId = s?.id ?? null, this.authenticatedSocket = this.socket, this.flushPendingComposerWarmup(), this.flushQueuedClientEvents(), this.pendingClientMessageId && (this.setState({ pendingMessageStatus: "sending" }), this.schedulePendingDeliveryAck(this.pendingClientMessageId)), this.flushPendingPassiveWarmup(), this.startHeartbeat();
1208
+ const n = jn(e), r = Object.prototype.hasOwnProperty.call(e, "appearance");
1202
1209
  R("web-sdk.agent", "Received auth.ok appearance", {
1203
- hasAppearance: n,
1210
+ hasAppearance: r,
1204
1211
  rawAppearance: e.appearance,
1205
- normalizedAppearance: s
1212
+ normalizedAppearance: n
1206
1213
  }), this.runtimeHelperJavascript = zn(e.runtimeHelpers)?.javascript ?? null;
1207
- const r = Rt(e, "starterPrompts"), i = Object.prototype.hasOwnProperty.call(e, "starterPrompts"), o = e.starterPromptsLoading === !0, a = {
1208
- user: Vn(e.user),
1214
+ const i = Rt(e, "starterPrompts"), o = Object.prototype.hasOwnProperty.call(e, "starterPrompts"), a = e.starterPromptsLoading === !0, l = {
1215
+ user: s,
1209
1216
  status: "connected",
1210
1217
  ...this.state.lastErrorCode === "connection_failed" ? { lastError: null, lastErrorCode: null } : {}
1211
1218
  };
1212
- (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 && !le() && this.requestTransientStarterPrompts(), this.state.sessionId && this.send({
1219
+ (o || this.state.starterPrompts.length === 0) && (l.starterPrompts = i, l.starterPromptsLoading = i.length > 0 ? !1 : a), o && i.length > 0 && (this.transientStarterPromptsRequestInFlight = !1, this.transientStarterPromptsRequestAttempted = !0), (r || n) && (l.appearance = n), this.setState(l), o && i.length === 0 && !a && !le() && this.requestTransientStarterPrompts(), this.state.sessionId && this.send({
1213
1220
  type: "page.upsert",
1214
1221
  sessionId: this.state.sessionId,
1215
- page: _(),
1222
+ page: k(),
1216
1223
  model: this.options.model
1217
1224
  });
1218
1225
  return;
@@ -1260,7 +1267,7 @@ class Wt {
1260
1267
  }
1261
1268
  const I = c.filter((E) => {
1262
1269
  const D = P(E);
1263
- return bt(D) ? !1 : !D || !p || !Fe(D) ? !0 : Ke(c, D) !== p;
1270
+ return bt(D) ? !1 : !D || !p || !je(D) ? !0 : Ke(c, D) !== p;
1264
1271
  }), S = ur(
1265
1272
  this.state.messages,
1266
1273
  Et(I, this.options.backendUrl)
@@ -1269,14 +1276,14 @@ class Wt {
1269
1276
  S,
1270
1277
  this.loadedOlderSessionItemIds
1271
1278
  ) : S, C = Ct(m), B = !d && c.some(
1272
- (E) => _t(
1279
+ (E) => kt(
1273
1280
  P(E),
1274
1281
  this.state.assistantDraft,
1275
1282
  this.state.assistantDraftItemId,
1276
1283
  this.state.assistantDraftRespondsToUserMessageId,
1277
1284
  this.state.assistantDraftRunId
1278
1285
  )
1279
- ), k = d ? u?.content ?? "" : this.state.assistantDraft, M = !!u?.content, W = C && (!k || B), b = fr(m), J = W && b;
1286
+ ), _ = d ? u?.content ?? "" : this.state.assistantDraft, M = !!u?.content, W = C && (!_ || B), b = fr(m), J = W && b;
1280
1287
  if (!C && yr(this.state.messages, c))
1281
1288
  return;
1282
1289
  this.lastUserMessagePageUrl = mr(c);
@@ -1383,7 +1390,7 @@ class Wt {
1383
1390
  if (e.type === "session.item") {
1384
1391
  this.rememberUserMessageClientMessageIds([e.item]);
1385
1392
  const s = P(e.item);
1386
- if (Fe(s)) {
1393
+ if (je(s)) {
1387
1394
  typeof s?.runId == "string" && this.retryableFailureRunIdsAwaitingDone.add(s.runId);
1388
1395
  const r = w(e.item, "sessionId") ?? this.state.sessionId, i = s ? N(s) : null, o = i ? this.clientMessageIdsByUserMessageItemId.get(i) : null, a = typeof s?.clientMessageId == "string" ? s.clientMessageId : o ?? (i ? null : this.activeClientMessageId ?? this.latestRecoverableClientMessageId);
1389
1396
  if (r && a) {
@@ -1400,16 +1407,16 @@ class Wt {
1400
1407
  const n = zt(e.item, this.options.backendUrl);
1401
1408
  if (n) {
1402
1409
  const r = n.callId ? this.pendingToolLoadingByCallId.get(n.callId) : void 0;
1403
- n.callId && r !== void 0 && (n.loading = r, this.pendingToolLoadingByCallId.delete(n.callId)), j(n) && (this.retryableClientMessageId = null, this.clearRetryTimers(), this.clearRunAckResyncRetryTimer());
1410
+ n.callId && r !== void 0 && (n.loading = r, this.pendingToolLoadingByCallId.delete(n.callId)), F(n) && (this.retryableClientMessageId = null, this.clearRetryTimers(), this.clearRunAckResyncRetryTimer());
1404
1411
  const i = e.item.data;
1405
1412
  wr(i) && this.clearRunAckResyncRetryTimer();
1406
- const o = $e(this.state.messages, n), a = Ct(o), l = _t(
1413
+ const o = $e(this.state.messages, n), a = Ct(o), l = kt(
1407
1414
  i,
1408
1415
  this.state.assistantDraft,
1409
1416
  this.state.assistantDraftItemId,
1410
1417
  this.state.assistantDraftRespondsToUserMessageId,
1411
1418
  this.state.assistantDraftRunId
1412
- ), c = a && (!this.state.assistantDraft || l), h = j(n) && (c || !this.state.isThinking && this.activeClientMessageId === null);
1419
+ ), c = a && (!this.state.assistantDraft || l), h = F(n) && (c || !this.state.isThinking && this.activeClientMessageId === null);
1413
1420
  this.setState({
1414
1421
  messages: o,
1415
1422
  ...l ? {
@@ -1905,7 +1912,7 @@ class Wt {
1905
1912
  this.state.sessionId ? this.send({
1906
1913
  type: "page.upsert",
1907
1914
  sessionId: this.state.sessionId,
1908
- page: _(),
1915
+ page: k(),
1909
1916
  model: this.options.model
1910
1917
  }) : (!this.socket || this.socket.readyState !== WebSocket.OPEN) && (this.setReconnectingState(), this.scheduleReconnect());
1911
1918
  }
@@ -2025,7 +2032,7 @@ class Wt {
2025
2032
  s.length === 0 || this.socket?.readyState !== WebSocket.OPEN || this.sendNow({
2026
2033
  type: "network.batch",
2027
2034
  sessionId: this.state.sessionId ?? void 0,
2028
- page: _(),
2035
+ page: k(),
2029
2036
  events: s
2030
2037
  });
2031
2038
  }, Qs)));
@@ -2148,19 +2155,19 @@ function dn() {
2148
2155
  startedAt: new Date(d).toISOString()
2149
2156
  };
2150
2157
  p.then(
2151
- (k) => {
2152
- Gr(k, B, d, e).catch(() => {
2158
+ (_) => {
2159
+ Gr(_, B, d, e).catch(() => {
2153
2160
  e({
2154
2161
  ...B,
2155
- responseStatus: k.status,
2162
+ responseStatus: _.status,
2156
2163
  durationMs: Date.now() - d
2157
2164
  });
2158
2165
  });
2159
2166
  },
2160
- (k) => {
2167
+ (_) => {
2161
2168
  e({
2162
2169
  ...B,
2163
- errorText: q(k instanceof Error ? k.message : String(k)),
2170
+ errorText: q(_ instanceof Error ? _.message : String(_)),
2164
2171
  durationMs: Date.now() - d
2165
2172
  });
2166
2173
  }
@@ -2517,10 +2524,10 @@ function bn(t) {
2517
2524
  }
2518
2525
  };
2519
2526
  }
2520
- function _n(t) {
2527
+ function kn(t) {
2521
2528
  return t.replace(/\/+$/, "");
2522
2529
  }
2523
- function kn(t) {
2530
+ function _n(t) {
2524
2531
  const e = {
2525
2532
  sidepanel: "extension_sidepanel",
2526
2533
  browser_extension_page_ui: "extension_widget",
@@ -2542,8 +2549,8 @@ function Dn(t) {
2542
2549
  const e = new URL("/api/product-agent/embed/ws", t);
2543
2550
  return e.protocol = e.protocol === "https:" ? "wss:" : "ws:", e.toString();
2544
2551
  }
2545
- function _() {
2546
- const t = Ft();
2552
+ function k() {
2553
+ const t = jt();
2547
2554
  return {
2548
2555
  url: location.href,
2549
2556
  title: document.title,
@@ -2579,7 +2586,7 @@ function Ln() {
2579
2586
  };
2580
2587
  }
2581
2588
  function le() {
2582
- return Ft()?.surface === "browser_extension_sdk_preview";
2589
+ return jt()?.surface === "browser_extension_sdk_preview";
2583
2590
  }
2584
2591
  function et() {
2585
2592
  if (!document.body)
@@ -2720,12 +2727,12 @@ function qn(t, e) {
2720
2727
  const C = m.getAttribute("data-testid") || m.getAttribute("data-test") || m.getAttribute("data-qa") || m.getAttribute("data-cy") || "";
2721
2728
  return `${m.tagName.toLowerCase()}|${u(m)}|${C}`;
2722
2729
  }, p = (m, C, B) => {
2723
- const k = (M, W) => {
2730
+ const _ = (M, W) => {
2724
2731
  const b = M.tagName.toLowerCase(), J = window.getComputedStyle(M), O = h.has(M);
2725
2732
  if (f >= 1e3 && !O || B.has(M) || i.has(b) || M.matches(".pluno-pa-widget-host, [data-pluno-product-agent-widget]") || J.display === "none" || J.visibility === "hidden")
2726
2733
  return { lines: [], hasUsefulContent: !1, textPreview: "", containsTextElement: !1 };
2727
2734
  f += 1;
2728
- const E = u(M), D = jt(M), cs = a.has(E) || ["button", "input", "textarea", "select", "iframe", "canvas"].includes(b) || b === "a" && M.hasAttribute("href"), Se = Array.from(M.children).filter((y) => y instanceof HTMLElement), re = /* @__PURE__ */ new Map();
2735
+ const E = u(M), D = Ft(M), cs = a.has(E) || ["button", "input", "textarea", "select", "iframe", "canvas"].includes(b) || b === "a" && M.hasAttribute("href"), Se = Array.from(M.children).filter((y) => y instanceof HTMLElement), re = /* @__PURE__ */ new Map();
2729
2736
  for (const y of Se) {
2730
2737
  const A = d(y);
2731
2738
  re.set(A, (re.get(A) ?? 0) + 1);
@@ -2742,13 +2749,13 @@ function qn(t, e) {
2742
2749
  ot.has(A) || (Me.push([`… ${we.get(A) ?? 0} similar siblings omitted`]), ot.add(A));
2743
2750
  continue;
2744
2751
  }
2745
- const dt = k(y, W);
2752
+ const dt = _(y, W);
2746
2753
  at.push(dt), Me.push(dt.lines);
2747
2754
  }
2748
2755
  const Ae = [];
2749
2756
  if (M.shadowRoot)
2750
2757
  for (const y of Array.from(M.shadowRoot.children))
2751
- y instanceof HTMLElement && Ae.push(k(y, W + 1));
2758
+ y instanceof HTMLElement && Ae.push(_(y, W + 1));
2752
2759
  const ie = [...at, ...Ae], Re = D.length > 0 || cs || ie.some((y) => y.hasUsefulContent), lt = G(
2753
2760
  [D, ...ie.map((y) => y.textPreview)].filter(Boolean).join(" ")
2754
2761
  ).slice(0, 180), us = M.hasAttribute("contenteditable") && (D.length > 0 || !M.querySelector("[contenteditable]")), ct = c.some((y) => M.hasAttribute(y)) || !!E || us, Ee = (M.getClientRects().length > 0 || J.display === "contents") && (s.has(b) || ct || O) && (Re || O) && (!r.has(b) || Re || ct || O), Ce = Ee ? 1 : 0, Y = [];
@@ -2776,7 +2783,7 @@ function qn(t, e) {
2776
2783
  containsTextElement: n.has(b) || ie.some((y) => y.containsTextElement)
2777
2784
  };
2778
2785
  };
2779
- return [`--- ${C} ---`, ...k(m, 0).lines].join(`
2786
+ return [`--- ${C} ---`, ..._(m, 0).lines].join(`
2780
2787
  `);
2781
2788
  }, I = [], S = G(window.getSelection()?.toString() ?? "");
2782
2789
  S && I.push(`--- selected text ---
@@ -2866,7 +2873,7 @@ function Bn(t, e, s, n) {
2866
2873
  h,
2867
2874
  s,
2868
2875
  n,
2869
- g === l.length - 1 ? jt(h).slice(0, 180) : ""
2876
+ g === l.length - 1 ? Ft(h).slice(0, 180) : ""
2870
2877
  ));
2871
2878
  o.length > l.length && c.splice(1, 0, "…"), r.push(`${i.labels.join(", ")}: ${c.join(" > ")}`);
2872
2879
  }
@@ -2882,7 +2889,7 @@ function ce(t, e) {
2882
2889
  const s = " ".repeat(e);
2883
2890
  return t.map((n) => `${s}${n}`);
2884
2891
  }
2885
- function jt(t) {
2892
+ function Ft(t) {
2886
2893
  return G(
2887
2894
  Array.from(t.childNodes).filter((e) => e.nodeType === Node.TEXT_NODE).map((e) => e.textContent ?? "").join(" ")
2888
2895
  );
@@ -2890,7 +2897,7 @@ function jt(t) {
2890
2897
  function Wn(t) {
2891
2898
  return t.length <= 64 && /^[A-Za-z_][A-Za-z0-9_:.-]*$/.test(t) && !/[a-f0-9]{12,}/i.test(t) && !/:r[0-9a-z]+:/i.test(t);
2892
2899
  }
2893
- function Ft() {
2900
+ function jt() {
2894
2901
  const t = document.querySelector(ht);
2895
2902
  if (!(t ?? document.querySelector(We)))
2896
2903
  return;
@@ -2946,10 +2953,10 @@ function Rt(t, e) {
2946
2953
  const s = t[e];
2947
2954
  return Array.isArray(s) ? s.filter((n) => typeof n == "string" && n.trim().length > 0) : [];
2948
2955
  }
2949
- function jn(t) {
2956
+ function Fn(t) {
2950
2957
  return Array.isArray(t) ? t.filter((e) => typeof e == "string" && e.trim().length > 0) : [];
2951
2958
  }
2952
- function Fn(t) {
2959
+ function jn(t) {
2953
2960
  if (!t || typeof t != "object")
2954
2961
  return null;
2955
2962
  const e = t, s = e.appearance, n = s && typeof s == "object" ? s : e, r = typeof n.accentColor == "string" ? n.accentColor : null, i = n.colorScheme === "dark" ? "dark" : n.colorScheme === "light" ? "light" : null, o = typeof n.fontFamily == "string" && n.fontFamily.trim() ? n.fontFamily : null, a = typeof n.scribbleStyle == "boolean" ? n.scribbleStyle : null;
@@ -3382,13 +3389,13 @@ function Ct(t) {
3382
3389
  if (e === null)
3383
3390
  return !1;
3384
3391
  const s = t[e].id, n = t.some(
3385
- (r) => r.respondsToUserMessageId === s && je(r)
3392
+ (r) => r.respondsToUserMessageId === s && Fe(r)
3386
3393
  );
3387
3394
  if (t.some((r) => r.respondsToUserMessageId === s))
3388
3395
  return n;
3389
3396
  for (let r = t.length - 1; r > e; r -= 1) {
3390
3397
  const i = t[r];
3391
- if (j(i))
3398
+ if (F(i))
3392
3399
  return !0;
3393
3400
  if (i.role === "system") {
3394
3401
  if (i.dataType === "run_error")
@@ -3402,11 +3409,11 @@ function Ct(t) {
3402
3409
  function fr(t) {
3403
3410
  const e = Vt(t);
3404
3411
  if (e === null)
3405
- return t.some(j);
3412
+ return t.some(F);
3406
3413
  const s = t[e].id;
3407
3414
  return t.some((n) => n.respondsToUserMessageId === s) ? t.some(
3408
- (n) => n.respondsToUserMessageId === s && j(n)
3409
- ) : t.slice(e + 1).some(j);
3415
+ (n) => n.respondsToUserMessageId === s && F(n)
3416
+ ) : t.slice(e + 1).some(F);
3410
3417
  }
3411
3418
  function Vt(t) {
3412
3419
  for (let e = t.length - 1; e >= 0; e -= 1)
@@ -3414,8 +3421,8 @@ function Vt(t) {
3414
3421
  return e;
3415
3422
  return null;
3416
3423
  }
3417
- function je(t) {
3418
- return j(t) ? !0 : t.role !== "system" ? !1 : t.dataType === "run_error" ? !0 : t.dataType === "run_status" && t.loading !== !0;
3424
+ function Fe(t) {
3425
+ return F(t) ? !0 : t.role !== "system" ? !1 : t.dataType === "run_error" ? !0 : t.dataType === "run_status" && t.loading !== !0;
3419
3426
  }
3420
3427
  function X(t) {
3421
3428
  for (let e = t.length - 1; e >= 0; e -= 1) {
@@ -3447,7 +3454,7 @@ function P(t) {
3447
3454
  const e = t.data;
3448
3455
  return e && typeof e == "object" ? e : null;
3449
3456
  }
3450
- function Fe(t) {
3457
+ function je(t) {
3451
3458
  return t?.retryable !== !0 ? !1 : t.type === "run_error" ? !0 : t.type === "run_status" && t.status === "interrupted";
3452
3459
  }
3453
3460
  function bt(t) {
@@ -3462,8 +3469,8 @@ function yr(t, e) {
3462
3469
  return !1;
3463
3470
  const i = t.findIndex((o) => o.role === "user" && o.id === r);
3464
3471
  return i === -1 ? !1 : t.some((o) => o.respondsToUserMessageId === r) ? t.some(
3465
- (o) => o.respondsToUserMessageId === r && je(o)
3466
- ) : t.slice(i + 1).some(je);
3472
+ (o) => o.respondsToUserMessageId === r && Fe(o)
3473
+ ) : t.slice(i + 1).some(Fe);
3467
3474
  }
3468
3475
  function ze(t) {
3469
3476
  const e = X(t);
@@ -3521,11 +3528,11 @@ function Tr(t, e) {
3521
3528
  }
3522
3529
  return s;
3523
3530
  }
3524
- function _t(t, e, s, n, r) {
3531
+ function kt(t, e, s, n, r) {
3525
3532
  if (!e || !Sr(t))
3526
3533
  return !1;
3527
3534
  const i = t;
3528
- return !(Fe(i) || s !== null && typeof i.id == "string" && i.id !== s || (n !== null ? N(i) !== n : r !== null && U(i) !== r));
3535
+ return !(je(i) || s !== null && typeof i.id == "string" && i.id !== s || (n !== null ? N(i) !== n : r !== null && U(i) !== r));
3529
3536
  }
3530
3537
  function Sr(t) {
3531
3538
  if (!t || typeof t != "object")
@@ -3533,7 +3540,7 @@ function Sr(t) {
3533
3540
  const e = t;
3534
3541
  return e.type === "message" && e.role === "assistant" ? !0 : e.type === "run_error" ? e.stage !== "tool_execution" : e.type === "run_status" && (e.status === "stopped" || e.status === "interrupted" || e.status === "failed");
3535
3542
  }
3536
- function j(t) {
3543
+ function F(t) {
3537
3544
  return t.role === "assistant" && t.phase !== "commentary";
3538
3545
  }
3539
3546
  function wr(t) {
@@ -3543,7 +3550,7 @@ function wr(t) {
3543
3550
  return e.type === "message" && e.role === "user" ? !1 : e.type === "message" || e.type === "function_call" || e.type === "function_call_output" || e.type === "run_error" || e.type === "run_status";
3544
3551
  }
3545
3552
  function Ge(t) {
3546
- return t.filter((e, s) => V(e) ? !Ur(t, s) && !Jt(t, s) && !kr(t, s) && !Pr(t, s) : Mr(e) ? e.retryable === !0 && _r(t, s) ? !1 : !br(t, s) : !0);
3553
+ return t.filter((e, s) => V(e) ? !Ur(t, s) && !Jt(t, s) && !_r(t, s) && !Pr(t, s) : Mr(e) ? e.retryable === !0 && kr(t, s) ? !1 : !br(t, s) : !0);
3547
3554
  }
3548
3555
  function Mr(t) {
3549
3556
  return t.role === "system" && (t.dataType === "run_error" || t.dataType === "run_status" && t.steered !== !0);
@@ -3598,21 +3605,21 @@ function Rr(t, e, s) {
3598
3605
  }
3599
3606
  function Er(t, e) {
3600
3607
  const s = [...t].reverse().find(
3601
- (n) => n.respondsToUserMessageId !== void 0 && n.respondsToUserMessageId !== e && kt(n) && !Cr(
3608
+ (n) => n.respondsToUserMessageId !== void 0 && n.respondsToUserMessageId !== e && _t(n) && !Cr(
3602
3609
  t,
3603
3610
  n.respondsToUserMessageId
3604
3611
  )
3605
3612
  )?.respondsToUserMessageId;
3606
3613
  return s ? t.map(
3607
- (n) => n.respondsToUserMessageId === s && kt(n) ? { ...n, steered: !0 } : n
3614
+ (n) => n.respondsToUserMessageId === s && _t(n) ? { ...n, steered: !0 } : n
3608
3615
  ) : t;
3609
3616
  }
3610
- function kt(t) {
3617
+ function _t(t) {
3611
3618
  return t.role === "tool" || V(t) ? !0 : t.role === "assistant" && t.phase === "commentary";
3612
3619
  }
3613
3620
  function Cr(t, e) {
3614
3621
  return t.some(
3615
- (s) => s.respondsToUserMessageId === e && (j(s) || s.role === "system" && (s.dataType === "run_error" || s.dataType === "run_status" && s.loading !== !0))
3622
+ (s) => s.respondsToUserMessageId === e && (F(s) || s.role === "system" && (s.dataType === "run_error" || s.dataType === "run_status" && s.loading !== !0))
3616
3623
  );
3617
3624
  }
3618
3625
  function br(t, e) {
@@ -3624,7 +3631,7 @@ function br(t, e) {
3624
3631
  }
3625
3632
  return !1;
3626
3633
  }
3627
- function _r(t, e) {
3634
+ function kr(t, e) {
3628
3635
  const s = t[e];
3629
3636
  if (!s.respondsToUserMessageId)
3630
3637
  return !1;
@@ -3637,7 +3644,7 @@ function _r(t, e) {
3637
3644
  }
3638
3645
  return !1;
3639
3646
  }
3640
- function kr(t, e) {
3647
+ function _r(t, e) {
3641
3648
  const s = t[e];
3642
3649
  return t.some(
3643
3650
  (n, r) => r !== e && n.role === "assistant" && ne(s, n)
@@ -3670,7 +3677,7 @@ function Dr(t, e) {
3670
3677
  const n = JSON.parse(s), r = typeof n.sessionId == "string" ? n.sessionId : null;
3671
3678
  if (e !== void 0 && r !== e)
3672
3679
  return null;
3673
- const i = Array.isArray(n.messages) ? n.messages.map(jr).filter((o) => !!o) : [];
3680
+ const i = Array.isArray(n.messages) ? n.messages.map(Fr).filter((o) => !!o) : [];
3674
3681
  return {
3675
3682
  sessionId: r,
3676
3683
  messages: i
@@ -3685,7 +3692,7 @@ function vr(t, e) {
3685
3692
  `${Bt}${t}`,
3686
3693
  JSON.stringify({
3687
3694
  sessionId: e.sessionId,
3688
- messages: e.messages.slice(-on).map(Fr)
3695
+ messages: e.messages.slice(-on).map(jr)
3689
3696
  })
3690
3697
  );
3691
3698
  } catch {
@@ -3703,7 +3710,7 @@ function Or(t) {
3703
3710
  return [];
3704
3711
  }
3705
3712
  }
3706
- function F(t, e) {
3713
+ function j(t, e) {
3707
3714
  try {
3708
3715
  const s = e.filter(tt);
3709
3716
  if (s.length === 0) {
@@ -3751,7 +3758,7 @@ function Lr(t) {
3751
3758
  const n = JSON.parse(s);
3752
3759
  return Array.isArray(n) ? n.flatMap((r) => qr(r) ? [{
3753
3760
  ...r.event,
3754
- page: _(),
3761
+ page: k(),
3755
3762
  rawOutput: {
3756
3763
  pageContextRestarted: !0,
3757
3764
  outcome: "unknown",
@@ -3852,7 +3859,7 @@ function $r(t) {
3852
3859
  const e = t.toLowerCase();
3853
3860
  return e.endsWith(".png") ? "image/png" : e.endsWith(".jpg") || e.endsWith(".jpeg") ? "image/jpeg" : e.endsWith(".webp") ? "image/webp" : e.endsWith(".gif") ? "image/gif" : e.endsWith(".pdf") ? "application/pdf" : null;
3854
3861
  }
3855
- function jr(t) {
3862
+ function Fr(t) {
3856
3863
  if (!t || typeof t != "object")
3857
3864
  return null;
3858
3865
  const e = t;
@@ -3873,7 +3880,7 @@ function jr(t) {
3873
3880
  loading: typeof e.loading == "boolean" ? e.loading : void 0
3874
3881
  };
3875
3882
  }
3876
- function Fr(t) {
3883
+ function jr(t) {
3877
3884
  return t.attachments?.length ? {
3878
3885
  ...t,
3879
3886
  attachments: t.attachments.map(st)