@pluno/product-agent-web 0.1.265 → 0.1.267

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.
@@ -19,16 +19,16 @@ function Yt(t, e, s, n) {
19
19
  if (!o) continue;
20
20
  const c = o.sessionId ? e.sessions[o.sessionId] : void 0, l = c?.execution?.user_message_ids ?? [], d = ["queued", "thinking", "steering"].includes(c?.execution?.phase ?? "idle"), u = t.interactions.openings[a], p = u && (u.sessionId === o.sessionId || u.sessionId === null) ? { ...u, sessionId: o.sessionId } : { sessionId: o.sessionId, generation: ++r, openedAt: n, awaitingBaseline: o.sessionId !== null && !c?.execution, ignoredTurns: l, turns: {}, shown: {} };
21
21
  if (p.awaitingBaseline && c?.execution) {
22
- const m = l.filter((h) => {
23
- const v = e.submissions[h];
22
+ const m = l.filter((f) => {
23
+ const v = e.submissions[f];
24
24
  return v?.conversationScopeId === a && v.submittedAt >= p.openedAt;
25
25
  });
26
- p.awaitingBaseline = !1, p.ignoredTurns = l.filter((h) => !m.includes(h));
26
+ p.awaitingBaseline = !1, p.ignoredTurns = l.filter((f) => !m.includes(f));
27
27
  }
28
28
  const g = {};
29
- for (const [m, h] of Object.entries(p.turns)) {
30
- const v = d && l.includes(m), I = v && !h.active ? n : h.startedAt;
31
- g[m] = { ...h, startedAt: I, active: v, notifications: !h.notificationsSuppressed && (h.notifications || v && n - I >= 1e4) };
29
+ for (const [m, f] of Object.entries(p.turns)) {
30
+ const v = d && l.includes(m), I = v && !f.active ? n : f.startedAt;
31
+ g[m] = { ...f, startedAt: I, active: v, notifications: !f.notificationsSuppressed && (f.notifications || v && n - I >= 1e4) };
32
32
  }
33
33
  if (d)
34
34
  for (const m of l) !p.ignoredTurns.includes(m) && !g[m] && (g[m] = { startedAt: n, active: !0, notifications: !1, tab_grouping: (t.interactions.crossTabTurns[o.sessionId] ?? []).includes(m) });
@@ -215,10 +215,10 @@ function xi(t, e, s = null, n = !0) {
215
215
  }
216
216
  return i("allowed", "none");
217
217
  }
218
- function de(t) {
218
+ function le(t) {
219
219
  return t?.execution_message_ids ?? t?.user_message_ids ?? [];
220
220
  }
221
- function he(t) {
221
+ function fe(t) {
222
222
  const e = /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})(?:\.(\d{1,6}))?(?:Z|\+00:00)$/.exec(t);
223
223
  if (!e) throw new Error("Display timestamps must retain the backend UTC precision.");
224
224
  return `${e[1]}.${(e[2] ?? "").padEnd(6, "0")}`;
@@ -226,7 +226,7 @@ function he(t) {
226
226
  function xt(t) {
227
227
  return "revision" in t.data ? t.data.revision : null;
228
228
  }
229
- function me(t) {
229
+ function ye(t) {
230
230
  return {
231
231
  key: t,
232
232
  status: "not_requested",
@@ -292,7 +292,7 @@ function Ps(t) {
292
292
  executionByUserMessage: {},
293
293
  followUps: [],
294
294
  followUpsVersion: -1,
295
- queries: { current: me(`${t}:current`), history: me(`${t}:history`) }
295
+ queries: { current: ye(`${t}:current`), history: ye(`${t}:history`) }
296
296
  };
297
297
  }
298
298
  function Pi(t) {
@@ -304,7 +304,7 @@ function $r(t, e) {
304
304
  }
305
305
  function Ie(t, e, s) {
306
306
  const n = t.submissionOrder.map((k) => t.submissions[k]).filter((k) => k.conversationScopeId === s), i = e.selections[s]?.sessionId ?? n.find((k) => !k.cancelled && k.sessionId !== null)?.sessionId ?? null, r = i ? t.sessions[i] : void 0, a = t.submissionOrder.map((k) => t.submissions[k]).filter((k) => i ? k.sessionId === i || k.sessionId === null && k.conversationScopeId === s : k.conversationScopeId === s), o = Object.values(r?.items ?? {}).sort((k, x) => {
307
- const U = he(k.created_at), H = he(x.created_at);
307
+ const U = fe(k.created_at), H = fe(x.created_at);
308
308
  return U < H ? -1 : U > H ? 1 : k.id < x.id ? -1 : k.id > x.id ? 1 : 0;
309
309
  }), c = a.filter((k) => (!k.cancelled || k.conversationScopeId === s && (k.sessionId === null || k.sessionId === i || i === null && k === a[a.length - 1])) && !r?.items[k.userMessageId] && !r?.removedItems[k.userMessageId]), l = {};
310
310
  for (const k of o) {
@@ -335,14 +335,14 @@ function Ie(t, e, s) {
335
335
  collapsed: !1
336
336
  });
337
337
  }
338
- const u = r?.execution, p = a.filter((k) => !k.cancelled && k.delivery !== "failed"), g = p.filter((k) => k.delivery !== "accepted" && k.executionVersion === null), m = p.filter((k) => k.delivery === "accepted" && k.executionVersion === null), h = p[p.length - 1], v = g.length > 0, I = h !== void 0 && m.includes(h);
338
+ const u = r?.execution, p = a.filter((k) => !k.cancelled && k.delivery !== "failed"), g = p.filter((k) => k.delivery !== "accepted" && k.executionVersion === null), m = p.filter((k) => k.delivery === "accepted" && k.executionVersion === null), f = p[p.length - 1], v = g.length > 0, I = f !== void 0 && m.includes(f);
339
339
  let _ = v ? "submitting" : I ? "awaiting_execution" : u?.phase ?? "idle";
340
- const S = Object.entries(t.stops).filter(([k]) => k === s || i !== null && e.selections[k]?.sessionId === i).map(([, k]) => k).find((k) => (!a.length || k.userMessageIds.includes(a[a.length - 1].userMessageId) || !v && !I && de(u).some((x) => k.userMessageIds.includes(x))) && (!u || u.version <= k.executionVersion || ["thinking", "steering", "queued", "stopping"].includes(u.phase) || a.some((x) => x.cancelled && x.executionVersion === null && k.userMessageIds.includes(x.userMessageId)))), f = u && ["thinking", "steering", "queued", "stopping"].includes(u.phase) || a.some((k) => k.delivery === "accepted" && k.executionVersion === null && S?.userMessageIds.includes(k.userMessageId));
341
- S && f && !v && (!u || !["thinking", "steering", "queued", "stopping"].includes(u.phase) || de(u).every((k) => S.userMessageIds.includes(k))) && (_ = "stopping"), S && !f && !v && a.some((k) => k.cancelled && k.executionVersion === null && S.userMessageIds.includes(k.userMessageId)) && (_ = a.some((k) => S.userMessageIds.includes(k.userMessageId) && ["sending", "uncertain"].includes(k.delivery)) ? "stopping" : "stopped");
340
+ const S = Object.entries(t.stops).filter(([k]) => k === s || i !== null && e.selections[k]?.sessionId === i).map(([, k]) => k).find((k) => (!a.length || k.userMessageIds.includes(a[a.length - 1].userMessageId) || !v && !I && le(u).some((x) => k.userMessageIds.includes(x))) && (!u || u.version <= k.executionVersion || ["thinking", "steering", "queued", "stopping"].includes(u.phase) || a.some((x) => x.cancelled && x.executionVersion === null && k.userMessageIds.includes(x.userMessageId)))), h = u && ["thinking", "steering", "queued", "stopping"].includes(u.phase) || a.some((k) => k.delivery === "accepted" && k.executionVersion === null && S?.userMessageIds.includes(k.userMessageId));
341
+ S && h && !v && (!u || !["thinking", "steering", "queued", "stopping"].includes(u.phase) || le(u).every((k) => S.userMessageIds.includes(k))) && (_ = "stopping"), S && !h && !v && a.some((k) => k.cancelled && k.executionVersion === null && S.userMessageIds.includes(k.userMessageId)) && (_ = a.some((k) => S.userMessageIds.includes(k.userMessageId) && ["sending", "uncertain"].includes(k.delivery)) ? "stopping" : "stopped");
342
342
  const b = ["thinking", "steering", "queued"].includes(_), y = t.stops[s] ?? S, w = y?.userMessageIds.filter((k) => !["completed", "failed"].includes(r?.executionByUserMessage[k]?.phase ?? "")) ?? [], R = w.some((k) => {
343
343
  const x = a.find((H) => H.userMessageId === k);
344
- return !Object.values(t.operations).some((H) => H.command.type === "run.stop" && H.command.payload.expectedUserMessageId === k && H.phase === "done") && (x?.executionVersion === null && ["sending", "uncertain", "accepted"].includes(x.delivery) || !!(u && de(u).includes(k) && ["thinking", "steering", "queued", "stopping"].includes(u.phase)));
345
- }), T = u?.user_message_ids ?? [], C = v || I ? h?.userMessageId ?? null : T[T.length - 1] ?? null, E = d.find((k) => k.userMessageId === C), q = b ? [...E?.activityIds ?? []].reverse().find((k) => l[k] === "open") ?? null : null, O = i !== null && !!e.selections[s]?.provisionalId && o.length === 0 && a.length === 0 && // The first persisted idle snapshot already has a positive synchronization version.
344
+ return !Object.values(t.operations).some((H) => H.command.type === "run.stop" && H.command.payload.expectedUserMessageId === k && H.phase === "done") && (x?.executionVersion === null && ["sending", "uncertain", "accepted"].includes(x.delivery) || !!(u && le(u).includes(k) && ["thinking", "steering", "queued", "stopping"].includes(u.phase)));
345
+ }), T = u?.user_message_ids ?? [], C = v || I ? f?.userMessageId ?? null : T[T.length - 1] ?? null, E = d.find((k) => k.userMessageId === C), q = b ? [...E?.activityIds ?? []].reverse().find((k) => l[k] === "open") ?? null : null, O = i !== null && !!e.selections[s]?.provisionalId && o.length === 0 && a.length === 0 && // The first persisted idle snapshot already has a positive synchronization version.
346
346
  (!r?.execution || r.execution.phase === "idle" && r.execution.user_message_ids.length === 0) && Object.values(t.operations).some((k) => k.conversationScopeId === s && k.phase === "done" && ["runtime.warmup", "attachment.prepare"].includes(k.command.type) && !k.command.payload.sessionId && k.result?.sessionId === i);
347
347
  return G({
348
348
  historyRefreshFailure: r?.historyRefreshFailure ?? null,
@@ -361,7 +361,7 @@ function Ie(t, e, s) {
361
361
  preparation: r?.preparation ?? null,
362
362
  stop: y ? { ...y, userMessageIds: w, pending: R } : null,
363
363
  segments: d.map((k, x) => ({ ...k, collapsed: b ? k.userMessageId !== C : x < d.length - 1 || k.activityIds.length > 0 })),
364
- activity: { phase: _, activeItemId: q, userMessageId: C, executionKey: JSON.stringify([...de(u)].sort()) },
364
+ activity: { phase: _, activeItemId: q, userMessageId: C, executionKey: JSON.stringify([...le(u)].sort()) },
365
365
  // Staging transfers the immutable input to the core. Waiting for backend acceptance leaves
366
366
  // the same submitted text in the optimistic transcript and composer during delivery.
367
367
  receipts: n.filter((k) => !k.cancelled && e.clients[k.clientScopeId] === s).map((k) => ({ viewId: k.viewId, userMessageId: k.userMessageId, acceptedRendererRevision: k.rendererRevision }))
@@ -387,7 +387,7 @@ function Ui(t, e) {
387
387
  if (!e) return !1;
388
388
  const s = t.executionByUserMessage[e];
389
389
  if (s) return ["completed", "stopped", "failed"].includes(s.phase);
390
- const n = Object.values(t.items).sort((r, a) => he(r.created_at).localeCompare(he(a.created_at)) || r.id.localeCompare(a.id));
390
+ const n = Object.values(t.items).sort((r, a) => fe(r.created_at).localeCompare(fe(a.created_at)) || r.id.localeCompare(a.id));
391
391
  let i = !1;
392
392
  for (const r of n)
393
393
  if (r.type === "user_message" && (i = r.id === e), !!i && (r.type === "stopped" || r.type === "error" || r.type === "final_response" && t.streams[r.id]?.state === "finished" && t.streams[r.id].revision >= r.data.revision))
@@ -455,23 +455,23 @@ function Hr(t, e, s) {
455
455
  if (!J(n.profile, l)) continue;
456
456
  const d = s.conversationScopeId ? t.interactions.openings[s.conversationScopeId] : void 0;
457
457
  if (!s.sessionId || !d || d.sessionId !== s.sessionId || !Ci(t, s.conversationScopeId, c) || t.features.refreshRequired && !d.shown[c] || n.profile === "main_web_chat" && !t.interactions.bridgeReady && !d.shown[c]) continue;
458
- const u = Qe(t, c), p = t.interactions.preferencePrompts[c], g = t.interactions.deviceFacts[c], m = `preference:${c}`, h = u === null;
459
- if (u === !1 || t.features.desiredPreferences[c] === !1 || h && p.snoozedUntil && Date.parse(p.snoozedUntil) > a || !h && (g.permission !== "missing" || g.snoozedUntil && Date.parse(g.snoozedUntil) > a)) continue;
458
+ const u = Qe(t, c), p = t.interactions.preferencePrompts[c], g = t.interactions.deviceFacts[c], m = `preference:${c}`, f = u === null;
459
+ if (u === !1 || t.features.desiredPreferences[c] === !1 || f && p.snoozedUntil && Date.parse(p.snoozedUntil) > a || !f && (g.permission !== "missing" || g.snoozedUntil && Date.parse(g.snoozedUntil) > a)) continue;
460
460
  const v = Object.values(t.interactions.devicePending).some((S) => S.feature === c), I = o([m, `preferenceSnooze:${c}`, `preferenceAcknowledge:${c}`]), _ = I.error ?? t.interactions.deviceErrors[c] ?? (d.shown[c] && t.interactions.bridgeError ? { code: "connection_interrupted", message: t.interactions.bridgeError, retryable: !0 } : null);
461
461
  r.push({
462
462
  id: m,
463
- category: h ? "preference" : "permission",
463
+ category: f ? "preference" : "permission",
464
464
  placement: "bottom_overlay",
465
465
  sourceId: null,
466
466
  conversationId: null,
467
467
  userMessageId: null,
468
468
  sourceVersion: d.generation,
469
469
  decisionRevision: p.revision,
470
- actions: h ? ["enable", "not_now", "dont_enable"] : ["allow", "not_now"],
470
+ actions: f ? ["enable", "not_now", "dont_enable"] : ["allow", "not_now"],
471
471
  status: v ? "pending" : _ ? "error" : I.status,
472
472
  error: _,
473
473
  payload: { feature: c, openingGeneration: d.generation },
474
- nextEligibleAt: h ? p.snoozedUntil : g.snoozedUntil
474
+ nextEligibleAt: f ? p.snoozedUntil : g.snoozedUntil
475
475
  });
476
476
  }
477
477
  for (const c of Object.values(t.interactions.sources)) {
@@ -541,13 +541,13 @@ function Vr(t, e, s, n) {
541
541
  if (e.type === "stage7.act") {
542
542
  const d = i.interactions.actions[e.requestId];
543
543
  if (d) {
544
- const h = i.interactions.welcome[e.interactionId], v = h?.category === "morning_report" ? h.tasks[e.taskIndex ?? 0] : h?.text;
544
+ const f = i.interactions.welcome[e.interactionId], v = f?.category === "morning_report" ? f.tasks[e.taskIndex ?? 0] : f?.text;
545
545
  if (d.interactionId !== e.interactionId || d.action !== e.action || d.expectedRevision !== e.expectedRevision || d.sourceVersion !== (e.sourceVersion ?? null) || d.clientScopeId !== e.clientScopeId || d.taskIndex !== (e.taskIndex ?? null) || (d.operation.kind === "run" || d.operation.kind === "edit") && d.operation.text !== v) throw new Error("Action request changed.");
546
546
  return { state: i, effects: r, command: null };
547
547
  }
548
548
  if (e.action === "feedback") {
549
- const h = i.interactions.welcome[e.interactionId];
550
- if (!h || h.category !== "proactive_suggestion" || !e.feedback || h.clientScopeId && h.clientScopeId !== e.clientScopeId) throw new Error("Missing proactive feedback.");
549
+ const f = i.interactions.welcome[e.interactionId];
550
+ if (!f || f.category !== "proactive_suggestion" || !e.feedback || f.clientScopeId && f.clientScopeId !== e.clientScopeId) throw new Error("Missing proactive feedback.");
551
551
  return { state: i, effects: r, command: {
552
552
  type: "stage7.mutate",
553
553
  authority: a,
@@ -555,27 +555,27 @@ function Vr(t, e, s, n) {
555
555
  requestId: e.requestId,
556
556
  mutation: {
557
557
  kind: "proactiveFeedback",
558
- suggestionId: h.sourceSuggestionId ?? h.id,
559
- suggestedQuery: h.text,
558
+ suggestionId: f.sourceSuggestionId ?? f.id,
559
+ suggestedQuery: f.text,
560
560
  message: e.feedback.message,
561
561
  context: e.feedback.context
562
562
  }
563
563
  } };
564
564
  }
565
- const u = Bi(i, s, n, e.clientScopeId).find((h) => h.id === e.interactionId);
565
+ const u = Bi(i, s, n, e.clientScopeId).find((f) => f.id === e.interactionId);
566
566
  if (!u || !u.actions.includes(e.action) || u.decisionRevision !== e.expectedRevision || u.sourceVersion !== e.sourceVersion || u.status === "pending") throw new Error("Interaction changed or action is unavailable.");
567
567
  if (u.category === "preference" || u.category === "permission") {
568
- const h = u.payload.feature;
569
- if (h !== "notifications" && h !== "tab_grouping") throw new Error("Missing preference feature.");
570
- if (i = { ...i, interactions: { ...i.interactions, promptActions: { ...i.interactions.promptActions, [e.requestId]: { scope: n.clients[e.clientScopeId], openingGeneration: u.sourceVersion, expectedRevision: e.expectedRevision, feature: h, action: e.action } } } }, u.category === "permission") return { state: i, effects: r, command: { type: "stage7.permission", authority: a, now: e.now, requestId: e.requestId, feature: h, action: e.action, settings: !1 } };
571
- const v = e.action === "not_now" ? { kind: "preferenceSnooze", feature: h, expectedRevision: e.expectedRevision } : { kind: "preference", feature: h, enabled: e.action === "enable" };
568
+ const f = u.payload.feature;
569
+ if (f !== "notifications" && f !== "tab_grouping") throw new Error("Missing preference feature.");
570
+ if (i = { ...i, interactions: { ...i.interactions, promptActions: { ...i.interactions.promptActions, [e.requestId]: { scope: n.clients[e.clientScopeId], openingGeneration: u.sourceVersion, expectedRevision: e.expectedRevision, feature: f, action: e.action } } } }, u.category === "permission") return { state: i, effects: r, command: { type: "stage7.permission", authority: a, now: e.now, requestId: e.requestId, feature: f, action: e.action, settings: !1 } };
571
+ const v = e.action === "not_now" ? { kind: "preferenceSnooze", feature: f, expectedRevision: e.expectedRevision } : { kind: "preference", feature: f, enabled: e.action === "enable" };
572
572
  return { state: i, effects: r, command: { type: "stage7.mutate", authority: a, now: e.now, requestId: e.requestId, mutation: v } };
573
573
  }
574
574
  if (["not_now", "never", "snooze"].includes(e.action)) {
575
- const h = u.category === "morning_report" ? { kind: "decision", category: "morning_report", action: "snooze", promptKey: u.id, expectedRevision: e.expectedRevision } : { kind: "decision", category: "proactive_suggestion", action: e.action, promptKey: i.interactions.welcome[u.id].sourceSuggestionId ?? u.id, expectedRevision: e.expectedRevision };
576
- return { state: i, effects: r, command: { type: "stage7.mutate", authority: a, now: e.now, requestId: e.requestId, mutation: h } };
575
+ const f = u.category === "morning_report" ? { kind: "decision", category: "morning_report", action: "snooze", promptKey: u.id, expectedRevision: e.expectedRevision } : { kind: "decision", category: "proactive_suggestion", action: e.action, promptKey: i.interactions.welcome[u.id].sourceSuggestionId ?? u.id, expectedRevision: e.expectedRevision };
576
+ return { state: i, effects: r, command: { type: "stage7.mutate", authority: a, now: e.now, requestId: e.requestId, mutation: f } };
577
577
  }
578
- const p = Object.values(i.interactions.sources).find((h) => h.id === u.sourceId && h.conversation_id === u.conversationId);
578
+ const p = Object.values(i.interactions.sources).find((f) => f.id === u.sourceId && f.conversation_id === u.conversationId);
579
579
  let g;
580
580
  if (u.category === "device_hint")
581
581
  g = { kind: "saveHint", interactionId: u.id };
@@ -590,8 +590,8 @@ function Vr(t, e, s, n) {
590
590
  g = { kind: "saveSharing", interactionId: u.id, expectedRevision: e.expectedRevision };
591
591
  } else if (e.action === "copy" || e.action === "share") {
592
592
  if (p?.payload.kind !== "sharing") throw new Error("Missing sharing source.");
593
- const h = Object.values(i.interactions.actions).find((v) => v.interactionId === u.id && v.step === "perform" && v.status === "error" && (v.operation.kind === "copy" || v.operation.kind === "share"));
594
- if (h && h.error?.code !== "interaction_not_started") throw new Error("The previous sharing action has an uncertain outcome.");
593
+ const f = Object.values(i.interactions.actions).find((v) => v.interactionId === u.id && v.step === "perform" && v.status === "error" && (v.operation.kind === "copy" || v.operation.kind === "share"));
594
+ if (f && f.error?.code !== "interaction_not_started") throw new Error("The previous sharing action has an uncertain outcome.");
595
595
  g = { kind: e.action, interactionId: u.id, variant: p.payload.variant, ...e.sharePlatform ? { platform: e.sharePlatform } : {} };
596
596
  } else if (e.action === "connect") {
597
597
  if (p?.payload.kind !== "integration_auth") throw new Error("Missing integration request.");
@@ -600,8 +600,8 @@ function Vr(t, e, s, n) {
600
600
  if (p?.payload.kind !== "personal_channel") throw new Error("Missing channel request.");
601
601
  g = { kind: "pair", interactionId: u.id, requestId: p.payload.request_id, managementUrl: p.payload.management_url };
602
602
  } else {
603
- const h = ji(i, u.id, { clientScopeId: e.clientScopeId, conversationScopeId: n.clients[e.clientScopeId] });
604
- if (h?.status === "error" && h.error?.code !== "interaction_not_started") throw new Error("Reconcile the previous action before trying again.");
603
+ const f = ji(i, u.id, { clientScopeId: e.clientScopeId, conversationScopeId: n.clients[e.clientScopeId] });
604
+ if (f?.status === "error" && f.error?.code !== "interaction_not_started") throw new Error("Reconcile the previous action before trying again.");
605
605
  if (e.action !== "edit") {
606
606
  if (a.profile.startsWith("extension_") && !e.origin) throw new Error("Task submission requires the current page origin.");
607
607
  const _ = xi(i.account, "send_message", e.origin ?? null);
@@ -676,12 +676,12 @@ function Kr(t, e, s, n) {
676
676
  };
677
677
  if (s.type === "stage7.query" && s.query.kind === "appearance") {
678
678
  const u = { ...s.query, kind: "appearance" }, p = n(u);
679
- if (Object.values(i.pending).some((h) => h.mode === "query" && h.key === p)) return { state: i, effects: r };
679
+ if (Object.values(i.pending).some((f) => f.mode === "query" && f.key === p)) return { state: i, effects: r };
680
680
  const g = o("query", s.requestId, i.appearanceEpochs[u.origin] ?? 0), m = i.pending[g];
681
681
  if (m && m.fingerprint !== JSON.stringify(u)) throw new Error("Query request ID changed payload.");
682
682
  a({
683
683
  appearanceQueries: { ...i.appearanceQueries, [p]: u },
684
- queries: { ...i.queries, [p]: De(i.queries[p] ?? me(p), { key: p, requestId: re(s.requestId), mode: "replace" }) },
684
+ queries: { ...i.queries, [p]: De(i.queries[p] ?? ye(p), { key: p, requestId: re(s.requestId), mode: "replace" }) },
685
685
  pending: { ...i.pending, [g]: {
686
686
  requestId: s.requestId,
687
687
  effectId: g,
@@ -696,22 +696,22 @@ function Kr(t, e, s, n) {
696
696
  } }
697
697
  }), l(u.origin) || d(g);
698
698
  } else if (s.type === "stage7.mutate" && (s.mutation.kind === "sampleStyle" || s.mutation.kind === "saveStyle" || s.mutation.kind === "scribble" || s.mutation.kind === "deleteStyle")) {
699
- const u = s.mutation, p = u.origin, g = o("mutate", s.requestId), m = i.pending[g], h = JSON.stringify(u);
699
+ const u = s.mutation, p = u.origin, g = o("mutate", s.requestId), m = i.pending[g], f = JSON.stringify(u);
700
700
  if (m) {
701
- if (m.fingerprint !== h) throw new Error("Request ID was reused with a different payload.");
701
+ if (m.fingerprint !== f) throw new Error("Request ID was reused with a different payload.");
702
702
  return { state: i, effects: r };
703
703
  }
704
704
  const v = l(p), I = (i.appearanceEpochs[p] ?? 0) + 1, _ = { ...i.pending };
705
- for (const [S, f] of Object.entries(_)) {
706
- if (f.mode !== "query" || !c(f.operation, p)) continue;
705
+ for (const [S, h] of Object.entries(_)) {
706
+ if (h.mode !== "query" || !c(h.operation, p)) continue;
707
707
  delete _[S];
708
- const b = o("query", f.requestId, I);
709
- _[b] = { ...f, effectId: b, status: "queued" };
708
+ const b = o("query", h.requestId, I);
709
+ _[b] = { ...h, effectId: b, status: "queued" };
710
710
  }
711
711
  _[g] = {
712
712
  requestId: s.requestId,
713
713
  effectId: g,
714
- fingerprint: h,
714
+ fingerprint: f,
715
715
  key: `appearance:${p}`,
716
716
  generation: e.generation,
717
717
  operation: u,
@@ -728,18 +728,18 @@ function Kr(t, e, s, n) {
728
728
  if (s.effectKind !== "stage7.query" && s.effectKind !== "stage7.mutate") return { state: i, effects: r };
729
729
  const g = s.type === "effect.completed" ? s.output.data : null;
730
730
  if (g && (g.kind !== "appearance" || g.origin !== p)) throw new Error("Appearance response does not match its origin.");
731
- const m = { ...i.pending }, h = { ...i.queries };
731
+ const m = { ...i.pending }, f = { ...i.queries };
732
732
  if (u.mode === "query") {
733
733
  delete m[s.effectId];
734
- const v = h[u.key];
735
- v?.requestId === u.requestId && (h[u.key] = s.type === "effect.failed" ? { ...v, status: "error", error: s.error, requestId: null } : { ...v, status: "ready", data: g, error: null, requestId: null, updatedAt: s.output.completedAt });
734
+ const v = f[u.key];
735
+ v?.requestId === u.requestId && (f[u.key] = s.type === "effect.failed" ? { ...v, status: "error", error: s.error, requestId: null } : { ...v, status: "ready", data: g, error: null, requestId: null, updatedAt: s.output.completedAt });
736
736
  } else if (m[s.effectId] = { ...u, status: g ? "done" : "error", result: g, error: s.type === "effect.failed" ? s.error : null }, g && s.type === "effect.completed") {
737
737
  for (const [v, I] of Object.entries(i.appearanceQueries))
738
- I.origin === p && (h[v] = { ...h[v], status: "ready", data: g, requestId: null, error: null, updatedAt: s.output.completedAt });
738
+ I.origin === p && (f[v] = { ...f[v], status: "ready", data: g, requestId: null, error: null, updatedAt: s.output.completedAt });
739
739
  for (const [v, I] of Object.entries(m)) I.mode === "query" && c(I.operation, p) && delete m[v];
740
740
  } else if (s.type === "effect.failed")
741
741
  for (const [v, I] of Object.entries(m)) I.mode === "mutation" && I.status === "queued" && c(I.operation, p) && (m[v] = { ...I, status: "error", error: { code: "appearance_write_cancelled", message: "Refresh appearance before saving again.", retryable: !1 } });
742
- if (a({ pending: m, queries: h }), u.mode === "mutation") {
742
+ if (a({ pending: m, queries: f }), u.mode === "mutation") {
743
743
  const v = Object.values(i.pending).find((I) => I.mode === "mutation" && I.status === "queued" && c(I.operation, p));
744
744
  if (v && (v.operation.kind === "sampleStyle" || v.operation.kind === "saveStyle" || v.operation.kind === "scribble" || v.operation.kind === "deleteStyle"))
745
745
  a({ pending: { ...i.pending, [v.effectId]: { ...v, status: "pending" } } }), r.push({ kind: "stage7.mutate", id: v.effectId, input: { authority: e, requestId: v.requestId, mutation: v.operation } });
@@ -749,7 +749,7 @@ function Kr(t, e, s, n) {
749
749
  return { state: i, effects: r };
750
750
  }
751
751
  function Ds(t = null) {
752
- return { authority: t, refusal: null, paidFallbackBySession: {}, query: me("account"), preferences: null };
752
+ return { authority: t, refusal: null, paidFallbackBySession: {}, query: ye("account"), preferences: null };
753
753
  }
754
754
  function Wr(t, e) {
755
755
  return t.preferences && e.preferencesVersion <= t.preferences.preferencesVersion ? t : { ...t, preferences: e };
@@ -783,9 +783,9 @@ function Us() {
783
783
  };
784
784
  }
785
785
  function Ns(t = 0) {
786
- return { localScribbleStyle: null, originContextQueries: {}, contextObservers: {}, contextReads: {}, contextRunOrigins: {}, appearanceEpochs: {}, appearanceQueries: {}, polls: {}, queries: {}, pending: {}, queuedPreferences: {}, desiredPreferences: {}, refreshBatch: null, refreshQueuedRequestId: null, refreshAt: null, failures: 0, now: t, timerId: null, timerDeadline: null, timerRevision: 0, refreshRequired: !1, schedulerError: null, deepFlows: {} };
786
+ return { suggestionReadFailures: 0, localScribbleStyle: null, originContextQueries: {}, contextObservers: {}, contextReads: {}, contextRunOrigins: {}, appearanceEpochs: {}, appearanceQueries: {}, polls: {}, queries: {}, pending: {}, queuedPreferences: {}, desiredPreferences: {}, refreshBatch: null, refreshQueuedRequestId: null, refreshAt: null, failures: 0, now: t, timerId: null, timerDeadline: null, timerRevision: 0, refreshRequired: !1, schedulerError: null, deepFlows: {} };
787
787
  }
788
- function ue(t, e) {
788
+ function ae(t, e) {
789
789
  return e.kind === "originContext" ? JSON.stringify([t.authorityId, t.generation, t.communityId, e.kind, e.origin]) : JSON.stringify([
790
790
  t.authorityId,
791
791
  t.generation,
@@ -851,23 +851,23 @@ function Se(t, e, s) {
851
851
  }
852
852
  function js(t, e, s) {
853
853
  let n = t;
854
- const i = [], r = (f) => {
855
- n = { ...n, features: { ...n.features, ...f } };
856
- }, a = (f) => {
857
- n = { ...n, interactions: { ...n.interactions, ...f } };
854
+ const i = [], r = (h) => {
855
+ n = { ...n, features: { ...n.features, ...h } };
856
+ }, a = (h) => {
857
+ n = { ...n, interactions: { ...n.interactions, ...h } };
858
858
  };
859
859
  if (e.type === "stage7.initialize") {
860
- const f = n.account.authority;
861
- return f && JSON.stringify(f) === JSON.stringify(e.authority) ? { state: n, effects: i } : { state: { account: Ds(e.authority), features: Ns(e.now), interactions: Us() }, effects: i };
860
+ const h = n.account.authority;
861
+ return h && JSON.stringify(h) === JSON.stringify(e.authority) ? { state: n, effects: i } : { state: { account: Ds(e.authority), features: Ns(e.now), interactions: Us() }, effects: i };
862
862
  }
863
863
  const o = n.account.authority;
864
864
  if (!o) return { state: n, effects: i };
865
865
  if ("authority" in e && JSON.stringify(e.authority) !== JSON.stringify(o)) return { state: n, effects: i };
866
866
  if (e.type === "stage7.retire") return { state: { account: Ds(), features: Ns(e.now), interactions: Us() }, effects: i };
867
867
  "now" in e && r({ now: e.now });
868
- const c = (f, b) => {
869
- const y = { ...n.features.contextObservers }, w = y[f];
870
- if (b === null ? delete y[f] : y[f] = ue(o, { kind: "originContext", clientScopeId: f, origin: b, pageUrl: "" }), r({ contextObservers: y }), !w || Object.values(y).includes(w)) return;
868
+ const c = (h, b) => {
869
+ const y = { ...n.features.contextObservers }, w = y[h];
870
+ if (b === null ? delete y[h] : y[h] = ae(o, { kind: "originContext", clientScopeId: h, origin: b, pageUrl: "" }), r({ contextObservers: y }), !w || Object.values(y).includes(w)) return;
871
871
  const R = { ...n.features.queries }, T = { ...n.features.polls }, C = { ...n.features.contextReads }, E = { ...n.features.originContextQueries }, q = { ...n.features.pending }, O = E[w]?.origin, k = { ...n.features.contextRunOrigins };
872
872
  for (const [x, U] of Object.entries(k)) U === O && delete k[x];
873
873
  delete R[w], delete T[w], delete C[w], delete E[w];
@@ -881,83 +881,83 @@ function js(t, e, s) {
881
881
  const l = e.type === "stage7.query" ? e.query : e.type === "stage7.mutate" ? e.mutation : e.type === "effect.completed" || e.type === "effect.failed" ? n.features.pending[e.effectId]?.operation : null;
882
882
  if (l && Li(l)) {
883
883
  et(o, l);
884
- const f = Kr(n.features, o, e, (b) => ue(o, b));
885
- return { state: { ...n, features: f.state }, effects: f.effects };
884
+ const h = Kr(n.features, o, e, (b) => ae(o, b));
885
+ return { state: { ...n, features: h.state }, effects: h.effects };
886
886
  }
887
887
  if (e.type === "stage7.act" || e.type === "stage7.retry_action" || (e.type === "effect.completed" || e.type === "effect.failed") && e.effectKind === "stage7.platform") {
888
- const f = Vr(n, e, s.conversation, s.directory);
889
- if (!f.command) return { state: f.state, effects: f.effects };
890
- const b = js(f.state, f.command, s);
891
- return { state: b.state, effects: [...f.effects, ...b.effects] };
892
- }
893
- const d = (f, b, y) => {
894
- const w = f === "notifications" ? "canRequestNotificationPermission" : "canGroupSessionTabs";
895
- if (!J(o.profile, w) || Qe(n, f) !== !0 || n.features.desiredPreferences[f] === !1 || Object.values(n.interactions.devicePending).some((C) => C.feature === f && (b === "check" || C.action !== "check"))) return;
888
+ const h = Vr(n, e, s.conversation, s.directory);
889
+ if (!h.command) return { state: h.state, effects: h.effects };
890
+ const b = js(h.state, h.command, s);
891
+ return { state: b.state, effects: [...h.effects, ...b.effects] };
892
+ }
893
+ const d = (h, b, y) => {
894
+ const w = h === "notifications" ? "canRequestNotificationPermission" : "canGroupSessionTabs";
895
+ if (!J(o.profile, w) || Qe(n, h) !== !0 || n.features.desiredPreferences[h] === !1 || Object.values(n.interactions.devicePending).some((C) => C.feature === h && (b === "check" || C.action !== "check"))) return;
896
896
  const R = Se(o, "device", y), T = { ...n.interactions.deviceErrors };
897
- delete T[f], a({ deviceErrors: T, devicePending: { ...n.interactions.devicePending, [R]: { feature: f, requestId: y, generation: o.generation, desired: !0, action: b } } }), i.push({ kind: "stage7.device", id: R, input: { authority: o, requestId: y, feature: f, action: b, now: n.features.now } });
898
- }, u = (f, b) => {
897
+ delete T[h], a({ deviceErrors: T, devicePending: { ...n.interactions.devicePending, [R]: { feature: h, requestId: y, generation: o.generation, desired: !0, action: b } } }), i.push({ kind: "stage7.device", id: R, input: { authority: o, requestId: y, feature: h, action: b, now: n.features.now } });
898
+ }, u = (h, b) => {
899
899
  const y = b ? n.interactions.promptActions[b.replace(/:ack$/, "")] : void 0, w = { ...n.interactions.openings };
900
900
  for (const [R, T] of Object.entries(w)) {
901
901
  if (y?.scope === R && y.openingGeneration === T.generation && ["enable", "allow"].includes(y.action)) continue;
902
902
  const C = { ...T.shown };
903
- delete C[f], w[R] = {
903
+ delete C[h], w[R] = {
904
904
  ...T,
905
905
  shown: C,
906
- turns: Object.fromEntries(Object.entries(T.turns).map(([E, q]) => [E, { ...q, [f]: !1, [`${f}Suppressed`]: !0 }]))
906
+ turns: Object.fromEntries(Object.entries(T.turns).map(([E, q]) => [E, { ...q, [h]: !1, [`${h}Suppressed`]: !0 }]))
907
907
  };
908
908
  }
909
909
  a({ openings: w });
910
- }, p = (f, b = null) => {
911
- if (f.kind === "preferences" && n.account.preferences && f.value.preferencesVersion > n.account.preferences.preferencesVersion)
910
+ }, p = (h, b = null) => {
911
+ if (h.kind === "preferences" && n.account.preferences && h.value.preferencesVersion > n.account.preferences.preferencesVersion)
912
912
  for (const y of ["notifications", "tab_grouping"]) {
913
913
  const w = y === "notifications" ? "taskNotificationsEnabled" : "tabGroupingEnabled";
914
- f.value[w] !== n.account.preferences[w] && u(y, b);
914
+ h.value[w] !== n.account.preferences[w] && u(y, b);
915
915
  }
916
- if (f.kind === "preferencePrompts" || f.kind === "preferencePrompt")
916
+ if (h.kind === "preferencePrompts" || h.kind === "preferencePrompt")
917
917
  for (const y of ["notifications", "tab_grouping"]) {
918
- const w = f.kind === "preferencePrompts" ? f.value[y] : f.feature === y ? f.value : null;
918
+ const w = h.kind === "preferencePrompts" ? h.value[y] : h.feature === y ? h.value : null;
919
919
  w && w.revision > n.interactions.preferencePrompts[y].revision && u(y, w.requestId);
920
920
  }
921
- f.kind === "preferences" && (n = { ...n, account: Wr(n.account, f.value) }), f.kind === "preferencePrompts" && (n = { ...n, interactions: jn(n.interactions, f.value) }), f.kind === "preferencePrompt" && (n = { ...n, interactions: jn(n.interactions, { ...n.interactions.preferencePrompts, [f.feature]: f.value }) }), f.kind === "decisions" && (n = { ...n, interactions: es(n.interactions, f.decisions) }), f.kind === "decision" && (n = { ...n, interactions: es(n.interactions, [f.value]) });
922
- }, g = (f, b) => {
923
- const y = n.interactions.deviceFacts[f];
924
- b.revision <= y.revision || (Qe(n, f) === !0 && (b.permission === "granted" && y.permission !== "granted" || b.snoozedUntil && b.snoozedUntil !== y.snoozedUntil) && u(f, null), a({ deviceFacts: { ...n.interactions.deviceFacts, [f]: b } }));
925
- }, m = (f, b, y = !1) => {
926
- et(o, f);
927
- const w = ue(o, f), R = Se(o, "query", b);
928
- if (f.kind === "originContext") {
921
+ h.kind === "preferences" && (n = { ...n, account: Wr(n.account, h.value) }), h.kind === "preferencePrompts" && (n = { ...n, interactions: jn(n.interactions, h.value) }), h.kind === "preferencePrompt" && (n = { ...n, interactions: jn(n.interactions, { ...n.interactions.preferencePrompts, [h.feature]: h.value }) }), h.kind === "decisions" && (n = { ...n, interactions: es(n.interactions, h.decisions) }), h.kind === "decision" && (n = { ...n, interactions: es(n.interactions, [h.value]) });
922
+ }, g = (h, b) => {
923
+ const y = n.interactions.deviceFacts[h];
924
+ b.revision <= y.revision || (Qe(n, h) === !0 && (b.permission === "granted" && y.permission !== "granted" || b.snoozedUntil && b.snoozedUntil !== y.snoozedUntil) && u(h, null), a({ deviceFacts: { ...n.interactions.deviceFacts, [h]: b } }));
925
+ }, m = (h, b, y = !1) => {
926
+ et(o, h);
927
+ const w = ae(o, h), R = Se(o, "query", b);
928
+ if (h.kind === "originContext") {
929
929
  const q = n.features.queries[w], O = n.features.contextReads[w];
930
- if (r({ originContextQueries: { ...n.features.originContextQueries, [w]: f } }), !y && (q?.status === "ready" || q?.status === "error") && O && (n.features.now - O.settledAt < 3e4 || q.error && !q.error.retryable && q.error.code !== "runtime_error")) return;
930
+ if (r({ originContextQueries: { ...n.features.originContextQueries, [w]: h } }), !y && (q?.status === "ready" || q?.status === "error") && O && (n.features.now - O.settledAt < 3e4 || q.error && !q.error.retryable && q.error.code !== "runtime_error")) return;
931
931
  }
932
932
  const T = n.features.pending[R];
933
- if (T && T.fingerprint !== JSON.stringify(f)) throw new Error("Query request ID changed payload.");
933
+ if (T && T.fingerprint !== JSON.stringify(h)) throw new Error("Query request ID changed payload.");
934
934
  if (T?.status === "pending" || Object.values(n.features.pending).some((q) => q.mode === "query" && q.key === w && q.status === "pending")) return;
935
- const C = n.features.queries[w] ?? me(w), E = De(C, { key: w, requestId: re(b), mode: "replace" });
935
+ const C = n.features.queries[w] ?? ye(w), E = De(C, { key: w, requestId: re(b), mode: "replace" });
936
936
  r({ queries: { ...n.features.queries, [w]: E }, pending: { ...n.features.pending, [R]: {
937
937
  requestId: b,
938
938
  effectId: R,
939
- fingerprint: JSON.stringify(f),
939
+ fingerprint: JSON.stringify(h),
940
940
  key: w,
941
941
  generation: o.generation,
942
- operation: f,
942
+ operation: h,
943
943
  mode: "query",
944
944
  status: "pending",
945
945
  error: null,
946
946
  result: null
947
- } } }), f.kind === "account" && (n = { ...n, account: { ...n.account, query: De(n.account.query, { key: w, requestId: re(b), mode: "replace" }) } }), i.push({ kind: "stage7.query", id: R, input: { authority: o, requestId: b, query: f } });
948
- }, h = (f, b, y = !1) => {
949
- if (et(o, f), f.kind === "report" && !n.account.query.data?.user?.isSuperuser) throw new Error("Chat reporting requires superuser access.");
950
- const w = Se(o, "mutate", b), R = JSON.stringify(f), T = n.features.pending[w];
947
+ } } }), h.kind === "account" && (n = { ...n, account: { ...n.account, query: De(n.account.query, { key: w, requestId: re(b), mode: "replace" }) } }), i.push({ kind: "stage7.query", id: R, input: { authority: o, requestId: b, query: h } });
948
+ }, f = (h, b, y = !1) => {
949
+ if (et(o, h), h.kind === "report" && !n.account.query.data?.user?.isSuperuser) throw new Error("Chat reporting requires superuser access.");
950
+ const w = Se(o, "mutate", b), R = JSON.stringify(h), T = n.features.pending[w];
951
951
  if (T) {
952
952
  if (T.fingerprint !== R) throw new Error("Request ID was reused with a different payload.");
953
953
  if (!y || T.status !== "error") return;
954
- if (!["decision", "preferenceSnooze", "preferenceAcknowledge"].includes(f.kind)) throw new Error("This operation cannot be replayed automatically.");
954
+ if (!["decision", "preferenceSnooze", "preferenceAcknowledge"].includes(h.kind)) throw new Error("This operation cannot be replayed automatically.");
955
955
  if (["conflict", "409"].includes(T.error?.code ?? "")) throw new Error("Refresh the conflicting decision before making another choice.");
956
956
  }
957
- if (f.kind === "preference" && (r({ desiredPreferences: { ...n.features.desiredPreferences, [f.feature]: f.enabled } }), Object.values(n.features.pending).some((C) => C.status === "pending" && C.operation.kind === "preference" && C.operation.feature === f.feature))) {
958
- const C = n.features.queuedPreferences[f.feature];
957
+ if (h.kind === "preference" && (r({ desiredPreferences: { ...n.features.desiredPreferences, [h.feature]: h.enabled } }), Object.values(n.features.pending).some((C) => C.status === "pending" && C.operation.kind === "preference" && C.operation.feature === h.feature))) {
958
+ const C = n.features.queuedPreferences[h.feature];
959
959
  if (C && C.requestId !== b) {
960
- const E = Se(o, "mutate", C.requestId), q = { kind: "preference", feature: f.feature, enabled: C.enabled };
960
+ const E = Se(o, "mutate", C.requestId), q = { kind: "preference", feature: h.feature, enabled: C.enabled };
961
961
  r({ pending: { ...n.features.pending, [E]: {
962
962
  requestId: C.requestId,
963
963
  effectId: E,
@@ -971,26 +971,26 @@ function js(t, e, s) {
971
971
  error: { code: "preference_superseded", message: "A newer preference choice replaced this request.", retryable: !1 }
972
972
  } } });
973
973
  }
974
- r({ queuedPreferences: { ...n.features.queuedPreferences, [f.feature]: { requestId: b, enabled: f.enabled } } });
974
+ r({ queuedPreferences: { ...n.features.queuedPreferences, [h.feature]: { requestId: b, enabled: h.enabled } } });
975
975
  return;
976
976
  }
977
- if (f.kind === "generatePrompts") {
978
- const C = { kind: "starterPrompts", ...f.page, includeUserSuggestions: f.includeUserSuggestions ?? !1 }, E = ue(o, C), q = n.features.queries[E] ?? me(E);
977
+ if (h.kind === "generatePrompts") {
978
+ const C = { kind: "starterPrompts", ...h.page, includeUserSuggestions: h.includeUserSuggestions ?? !1 }, E = ae(o, C), q = n.features.queries[E] ?? ye(E);
979
979
  r({ queries: { ...n.features.queries, [E]: De(q, { key: E, requestId: re(b), mode: "replace" }) } });
980
980
  }
981
- r({ pending: { ...n.features.pending, [w]: { requestId: b, effectId: w, fingerprint: R, key: Ln(f), generation: o.generation, operation: f, mode: "mutation", status: "pending", error: null, result: null } } }), i.push({ kind: "stage7.mutate", id: w, input: { authority: o, requestId: b, mutation: f } });
982
- }, v = (f) => {
981
+ r({ pending: { ...n.features.pending, [w]: { requestId: b, effectId: w, fingerprint: R, key: Ln(h), generation: o.generation, operation: h, mode: "mutation", status: "pending", error: null, result: null } } }), i.push({ kind: "stage7.mutate", id: w, input: { authority: o, requestId: b, mutation: h } });
982
+ }, v = (h) => {
983
983
  if (!(!J(o.profile, "canManagePreferences") || n.features.refreshBatch)) {
984
984
  for (const b of Object.values(n.features.pending))
985
- b.mode === "mutation" && b.operation.kind === "preferenceAcknowledge" && b.status === "error" && !["conflict", "409"].includes(b.error?.code ?? "") && h(b.operation, b.requestId, !0);
985
+ b.mode === "mutation" && b.operation.kind === "preferenceAcknowledge" && b.status === "error" && !["conflict", "409"].includes(b.error?.code ?? "") && f(b.operation, b.requestId, !0);
986
986
  for (const b of ["account", "preferences", "preferencePrompts", "decisions"])
987
- Object.values(n.features.pending).some((y) => y.mode === "query" && y.status === "pending" && y.operation.kind === b) || m({ kind: b }, `${f}:${b}`);
987
+ Object.values(n.features.pending).some((y) => y.mode === "query" && y.status === "pending" && y.operation.kind === b) || m({ kind: b }, `${h}:${b}`);
988
988
  r({ refreshAt: null, refreshBatch: { pending: Object.values(n.features.pending).filter((b) => b.mode === "query" && b.status === "pending" && ["account", "preferences", "preferencePrompts", "decisions"].includes(b.operation.kind)).map((b) => b.effectId), failed: !1 } });
989
989
  }
990
- }, I = (f, b) => {
990
+ }, I = (h, b) => {
991
991
  const y = n.features.refreshBatch;
992
- if (y?.pending.includes(f)) {
993
- const w = y.pending.filter((T) => T !== f), R = y.failed || b;
992
+ if (y?.pending.includes(h)) {
993
+ const w = y.pending.filter((T) => T !== h), R = y.failed || b;
994
994
  if (w.length) r({ refreshBatch: { pending: w, failed: R } });
995
995
  else {
996
996
  const T = R ? n.features.failures + 1 : 0;
@@ -1002,8 +1002,8 @@ function js(t, e, s) {
1002
1002
  };
1003
1003
  switch (e.type) {
1004
1004
  case "stage7.account_refusal": {
1005
- const f = Ot(void 0, e.code);
1006
- if (f.allowed) return { state: n, effects: i };
1005
+ const h = Ot(void 0, e.code);
1006
+ if (h.allowed) return { state: n, effects: i };
1007
1007
  const b = { ...n.features.queries }, y = { ...n.features.pending }, w = [];
1008
1008
  for (const [R, T] of Object.entries(y)) {
1009
1009
  if (T.operation.kind !== "account" || T.status === "done" || T.status === "error") continue;
@@ -1014,7 +1014,7 @@ function js(t, e, s) {
1014
1014
  }
1015
1015
  n = { ...n, features: { ...n.features, pending: y, queries: b }, account: {
1016
1016
  ...n.account,
1017
- refusal: f,
1017
+ refusal: h,
1018
1018
  query: { ...n.account.query, requestId: null, status: n.account.query.data ? "ready" : "not_requested" }
1019
1019
  } };
1020
1020
  for (const R of w) I(R, !0);
@@ -1024,26 +1024,31 @@ function js(t, e, s) {
1024
1024
  c(e.clientScopeId, e.origin);
1025
1025
  break;
1026
1026
  case "stage7.query":
1027
+ if (e.query.kind === "userSuggestedTasks") {
1028
+ const h = ae(o, e.query);
1029
+ if (!e.force && (n.features.polls[h] || n.features.queries[h]?.status === "error")) break;
1030
+ e.force && r({ suggestionReadFailures: 0 });
1031
+ }
1027
1032
  if (e.query.kind === "originContext" && (c(e.query.clientScopeId, e.query.origin), e.force)) {
1028
- const f = ue(o, e.query), b = { ...n.features.contextReads };
1029
- delete b[f], r({ contextReads: b });
1033
+ const h = ae(o, e.query), b = { ...n.features.contextReads };
1034
+ delete b[h], r({ contextReads: b });
1030
1035
  }
1031
1036
  m(e.query, e.requestId, e.force);
1032
1037
  break;
1033
1038
  case "stage7.mutate":
1034
- h(e.mutation, e.requestId);
1039
+ f(e.mutation, e.requestId);
1035
1040
  break;
1036
1041
  case "stage7.retry": {
1037
- const f = n.features.pending[Se(o, "mutate", e.requestId)];
1038
- if (!f || f.mode !== "mutation") throw new Error("Unknown mutation request.");
1039
- h(f.operation, e.requestId, !0);
1042
+ const h = n.features.pending[Se(o, "mutate", e.requestId)];
1043
+ if (!h || h.mode !== "mutation") throw new Error("Unknown mutation request.");
1044
+ f(h.operation, e.requestId, !0);
1040
1045
  break;
1041
1046
  }
1042
1047
  case "stage7.reconcile":
1043
1048
  if (r({ schedulerError: null }), e.reason !== "periodic" || n.features.refreshAt === null || e.now >= n.features.refreshAt) {
1044
1049
  if (e.reason === "startup" && r({ refreshRequired: !0 }), e.reason === "wake" || e.reason === "reconnect") {
1045
- const f = Object.values(n.features.pending).some((b) => b.mode === "query" && b.status === "pending" && ["account", "preferences", "preferencePrompts", "decisions"].includes(b.operation.kind));
1046
- r({ refreshRequired: !0, refreshQueuedRequestId: f ? `after:${e.requestId}` : n.features.refreshQueuedRequestId });
1050
+ const h = Object.values(n.features.pending).some((b) => b.mode === "query" && b.status === "pending" && ["account", "preferences", "preferencePrompts", "decisions"].includes(b.operation.kind));
1051
+ r({ refreshRequired: !0, refreshQueuedRequestId: h ? `after:${e.requestId}` : n.features.refreshQueuedRequestId });
1047
1052
  }
1048
1053
  v(e.requestId);
1049
1054
  }
@@ -1056,38 +1061,38 @@ function js(t, e, s) {
1056
1061
  break;
1057
1062
  case "stage7.restore_prompt_openings": {
1058
1063
  if (!o.profile.startsWith("extension_")) throw new Error("Prompt restoration requires an extension opening checkpoint.");
1059
- const f = new Set(Object.values(s.directory.clients)), b = Object.fromEntries(Object.entries(e.checkpoint.openings).filter(([y, w]) => f.has(y) && s.directory.selections[y]?.sessionId === w.sessionId));
1064
+ const h = new Set(Object.values(s.directory.clients)), b = Object.fromEntries(Object.entries(e.checkpoint.openings).filter(([y, w]) => h.has(y) && s.directory.selections[y]?.sessionId === w.sessionId));
1060
1065
  a({ ...e.checkpoint, openings: b, openingGeneration: Math.max(n.interactions.openingGeneration, e.checkpoint.openingGeneration) });
1061
1066
  break;
1062
1067
  }
1063
1068
  case "stage7.prompt_view": {
1064
- const f = s.directory.clients[e.clientScopeId];
1065
- if (!f) break;
1069
+ const h = s.directory.clients[e.clientScopeId];
1070
+ if (!h) break;
1066
1071
  const b = { ...n.interactions.openings };
1067
- e.open || delete b[f], a({ openings: b, closedScopes: { ...n.interactions.closedScopes, [f]: !e.open } }), n = Yt(n, s.conversation, s.directory, e.now);
1072
+ e.open || delete b[h], a({ openings: b, closedScopes: { ...n.interactions.closedScopes, [h]: !e.open } }), n = Yt(n, s.conversation, s.directory, e.now);
1068
1073
  break;
1069
1074
  }
1070
1075
  case "stage7.prompt_shown": {
1071
- const f = s.directory.clients[e.clientScopeId], b = n.interactions.openings[f];
1076
+ const h = s.directory.clients[e.clientScopeId], b = n.interactions.openings[h];
1072
1077
  if (!b || b.generation !== e.openingGeneration) break;
1073
- const y = Ci(n, f, e.feature);
1074
- y && a({ openings: { ...n.interactions.openings, [f]: { ...b, shown: { ...b.shown, [e.feature]: y } } } });
1078
+ const y = Ci(n, h, e.feature);
1079
+ y && a({ openings: { ...n.interactions.openings, [h]: { ...b, shown: { ...b.shown, [e.feature]: y } } } });
1075
1080
  break;
1076
1081
  }
1077
1082
  case "stage7.cross_tab": {
1078
1083
  a({ crossTabTurns: { ...n.interactions.crossTabTurns, [e.sessionId]: [.../* @__PURE__ */ new Set([...n.interactions.crossTabTurns[e.sessionId] ?? [], e.userMessageId])] } });
1079
- const f = { ...n.interactions.openings };
1080
- for (const [b, y] of Object.entries(f)) {
1084
+ const h = { ...n.interactions.openings };
1085
+ for (const [b, y] of Object.entries(h)) {
1081
1086
  const w = y.turns[e.userMessageId];
1082
- y.sessionId === e.sessionId && w && !w.tab_groupingSuppressed && (f[b] = { ...y, turns: { ...y.turns, [e.userMessageId]: { ...w, tab_grouping: !0 } } });
1087
+ y.sessionId === e.sessionId && w && !w.tab_groupingSuppressed && (h[b] = { ...y, turns: { ...y.turns, [e.userMessageId]: { ...w, tab_grouping: !0 } } });
1083
1088
  }
1084
- a({ openings: f });
1089
+ a({ openings: h });
1085
1090
  break;
1086
1091
  }
1087
1092
  case "stage7.permission": {
1088
1093
  if (Qe(n, e.feature) !== !0) throw new Error("Permission setup requires a saved On preference.");
1089
- const f = n.interactions.deviceFacts[e.feature].snoozedUntil;
1090
- if (!e.settings && f && Date.parse(f) > e.now) break;
1094
+ const h = n.interactions.deviceFacts[e.feature].snoozedUntil;
1095
+ if (!e.settings && h && Date.parse(h) > e.now) break;
1091
1096
  d(e.feature, e.action, e.requestId);
1092
1097
  break;
1093
1098
  }
@@ -1095,38 +1100,38 @@ function js(t, e, s) {
1095
1100
  g(e.feature, e.fact);
1096
1101
  break;
1097
1102
  case "stage7.import_legacy_decisions":
1098
- if (!o.profile.startsWith("extension_") || e.decisions.some((f) => f.revision !== 0)) throw new Error("Invalid legacy decision import.");
1103
+ if (!o.profile.startsWith("extension_") || e.decisions.some((h) => h.revision !== 0)) throw new Error("Invalid legacy decision import.");
1099
1104
  n = { ...n, interactions: es(n.interactions, e.decisions) };
1100
1105
  break;
1101
1106
  case "stage7.device_hints": {
1102
1107
  if (o.profile !== "main_web_chat") throw new Error("Main-web hints unavailable.");
1103
- const f = { ...n.interactions.deviceHints };
1104
- for (const [b, y] of Object.entries(e.hints)) f[b] = f[b] === !0 || y;
1105
- a({ deviceHints: f });
1108
+ const h = { ...n.interactions.deviceHints };
1109
+ for (const [b, y] of Object.entries(e.hints)) h[b] = h[b] === !0 || y;
1110
+ a({ deviceHints: h });
1106
1111
  break;
1107
1112
  }
1108
1113
  case "stage7.local_sharing": {
1109
- const f = { ...n.interactions.localSharing };
1114
+ const h = { ...n.interactions.localSharing };
1110
1115
  for (const [b, y] of Object.entries(e.decisions))
1111
- (!f[b] || y.revision > f[b].revision) && (f[b] = y);
1112
- a({ localSharing: f, localSharingReady: !0 });
1116
+ (!h[b] || y.revision > h[b].revision) && (h[b] = y);
1117
+ a({ localSharing: h, localSharingReady: !0 });
1113
1118
  break;
1114
1119
  }
1115
1120
  case "stage7.sources": {
1116
- const f = { ...n.interactions.sources };
1121
+ const h = { ...n.interactions.sources };
1117
1122
  for (const b of e.sources) {
1118
1123
  if (!Number.isSafeInteger(b.version) || b.version < 0) throw new Error("Invalid source version.");
1119
- const y = JSON.stringify([b.conversation_id, b.id]), w = f[y];
1124
+ const y = JSON.stringify([b.conversation_id, b.id]), w = h[y];
1120
1125
  if (!(w && w.version >= b.version)) {
1121
1126
  if (w && w.payload.kind !== b.payload.kind) throw new Error("Interaction source changed category.");
1122
- f[y] = {
1127
+ h[y] = {
1123
1128
  ...b,
1124
1129
  lifecycle: w?.lifecycle === "completed" ? "completed" : b.lifecycle,
1125
1130
  payload: w?.payload.kind === "sharing" && b.payload.kind === "sharing" ? { ...b.payload, variant: w.payload.variant } : b.payload
1126
1131
  };
1127
1132
  }
1128
1133
  }
1129
- a({ sources: f });
1134
+ a({ sources: h });
1130
1135
  break;
1131
1136
  }
1132
1137
  case "stage7.local_style":
@@ -1139,7 +1144,7 @@ function js(t, e, s) {
1139
1144
  delete y[e.id], a({ welcome: y });
1140
1145
  break;
1141
1146
  }
1142
- const f = e.signupAgeDays, b = e.retained === !0 || e.localHour >= 5 && e.lastShownDate !== e.localDate && (f === 1 || f === 3 || f === 5 || f >= 7 && f % 7 === 0);
1147
+ const h = e.signupAgeDays, b = e.retained === !0 || e.localHour >= 5 && e.lastShownDate !== e.localDate && (h === 1 || h === 3 || h === 5 || h >= 7 && h % 7 === 0);
1143
1148
  a({ welcome: { ...n.interactions.welcome, [e.id]: { id: e.id, text: e.text, tasks: e.tasks, category: "morning_report", eligible: b } } });
1144
1149
  break;
1145
1150
  }
@@ -1148,8 +1153,8 @@ function js(t, e, s) {
1148
1153
  break;
1149
1154
  case "stage7.deep_flow": {
1150
1155
  if (!J(o.profile, "canStartDeepFlow")) throw new Error("Deep flow unavailable.");
1151
- const f = n.features.deepFlows[e.clientScopeId];
1152
- if ((f?.id ?? null) !== e.expectedId || f && e.flow && e.flow.id !== f.id || e.flow && f && f.status !== "running") break;
1156
+ const h = n.features.deepFlows[e.clientScopeId];
1157
+ if ((h?.id ?? null) !== e.expectedId || h && e.flow && e.flow.id !== h.id || e.flow && h && h.status !== "running") break;
1153
1158
  const b = { ...n.features.deepFlows };
1154
1159
  e.flow ? b[e.clientScopeId] = e.flow : delete b[e.clientScopeId], r({ deepFlows: b });
1155
1160
  break;
@@ -1177,7 +1182,7 @@ function js(t, e, s) {
1177
1182
  if (delete w[e.effectId], a({ devicePending: w }), e.type === "effect.completed") {
1178
1183
  if (y.action !== "check" && n.interactions.promptActions[y.requestId] && !n.features.pending[Se(o, "mutate", `${y.requestId}:ack`)]) {
1179
1184
  const R = n.interactions.promptActions[y.requestId];
1180
- u(R.feature, y.requestId), h({
1185
+ u(R.feature, y.requestId), f({
1181
1186
  kind: "preferenceAcknowledge",
1182
1187
  feature: R.feature,
1183
1188
  action: R.action,
@@ -1188,54 +1193,54 @@ function js(t, e, s) {
1188
1193
  } else Qe(n, y.feature) === !0 && n.features.desiredPreferences[y.feature] !== !1 && a({ deviceErrors: { ...n.interactions.deviceErrors, [y.feature]: e.error } });
1189
1194
  break;
1190
1195
  }
1191
- const f = n.features.pending[e.effectId];
1192
- if (!f || f.status !== "pending" || f.generation !== o.generation) break;
1196
+ const h = n.features.pending[e.effectId];
1197
+ if (!h || h.status !== "pending" || h.generation !== o.generation) break;
1193
1198
  const b = e.type === "effect.failed";
1194
- if (r({ pending: { ...n.features.pending, [e.effectId]: { ...f, status: b ? "error" : "done", error: b ? e.error : null, result: b ? null : e.output.data } } }), f.mode === "query") {
1199
+ if (r({ pending: { ...n.features.pending, [e.effectId]: { ...h, status: b ? "error" : "done", error: b ? e.error : null, result: b ? null : e.output.data } } }), h.mode === "query") {
1195
1200
  const y = { ...n.features.pending };
1196
1201
  delete y[e.effectId], r({ pending: y });
1197
- const w = n.features.queries[f.key];
1198
- if (!w || w.requestId !== f.requestId) break;
1199
- if (["originContext", "userContext", "contextRun"].includes(f.operation.kind)) {
1202
+ const w = n.features.queries[h.key];
1203
+ if (!w || w.requestId !== h.requestId) break;
1204
+ if (["originContext", "userContext", "contextRun"].includes(h.operation.kind)) {
1200
1205
  const R = { ...n.features.polls };
1201
- delete R[f.key], r({ polls: R, contextReads: { ...n.features.contextReads, [f.key]: {
1206
+ delete R[h.key], r({ polls: R, contextReads: { ...n.features.contextReads, [h.key]: {
1202
1207
  settledAt: b ? n.features.now : e.output.completedAt,
1203
- failures: b ? (n.features.contextReads[f.key]?.failures ?? 0) + 1 : 0
1208
+ failures: b ? (n.features.contextReads[h.key]?.failures ?? 0) + 1 : 0
1204
1209
  } } });
1205
1210
  }
1206
1211
  if (b)
1207
- r({ queries: { ...n.features.queries, [f.key]: ct(w, { key: f.key, requestId: re(f.requestId), error: e.error }) } }), f.operation.kind === "account" && (n = { ...n, account: { ...n.account, query: ct(n.account.query, { key: f.key, requestId: re(f.requestId), error: e.error }) } });
1212
+ r({ queries: { ...n.features.queries, [h.key]: ct(w, { key: h.key, requestId: re(h.requestId), error: e.error }) } }), h.operation.kind === "account" && (n = { ...n, account: { ...n.account, query: ct(n.account.query, { key: h.key, requestId: re(h.requestId), error: e.error }) } });
1208
1213
  else {
1209
- if (e.output.data.kind !== f.operation.kind) throw new Error("Feature response kind does not match the query.");
1210
- r({ now: e.output.completedAt, queries: { ...n.features.queries, [f.key]: Zt(w, { key: f.key, requestId: re(f.requestId), data: e.output.data, cursor: null, updatedAt: e.output.completedAt }) } }), p(e.output.data, f.requestId), e.output.data.kind === "account" && (n = { ...n, account: { ...n.account, refusal: null, query: Zt(n.account.query, { key: f.key, requestId: re(f.requestId), data: e.output.data.value, cursor: null, updatedAt: e.output.completedAt }) } });
1214
+ if (e.output.data.kind !== h.operation.kind) throw new Error("Feature response kind does not match the query.");
1215
+ r({ now: e.output.completedAt, queries: { ...n.features.queries, [h.key]: Zt(w, { key: h.key, requestId: re(h.requestId), data: e.output.data, cursor: null, updatedAt: e.output.completedAt }) } }), p(e.output.data, h.requestId), e.output.data.kind === "account" && (n = { ...n, account: { ...n.account, refusal: null, query: Zt(n.account.query, { key: h.key, requestId: re(h.requestId), data: e.output.data.value, cursor: null, updatedAt: e.output.completedAt }) } });
1211
1216
  }
1212
1217
  } else if (!b)
1213
- r({ now: e.output.completedAt }), p(e.output.data, f.requestId);
1218
+ r({ now: e.output.completedAt }), p(e.output.data, h.requestId);
1214
1219
  else if (["conflict", "409"].includes(e.error.code)) {
1215
- const y = f.operation.kind === "decision" ? "decisions" : f.operation.kind === "preferenceSnooze" || f.operation.kind === "preferenceAcknowledge" ? "preferencePrompts" : "preferences";
1216
- m({ kind: y }, `conflict:${f.requestId}`);
1220
+ const y = h.operation.kind === "decision" ? "decisions" : h.operation.kind === "preferenceSnooze" || h.operation.kind === "preferenceAcknowledge" ? "preferencePrompts" : "preferences";
1221
+ m({ kind: y }, `conflict:${h.requestId}`);
1217
1222
  }
1218
- if (f.mode === "mutation" && f.operation.kind === "decision") {
1223
+ if (h.mode === "mutation" && h.operation.kind === "decision") {
1219
1224
  const y = { ...n.interactions.actions };
1220
1225
  for (const [w, R] of Object.entries(y))
1221
- R.step === "persist" && f.requestId === `sharing:${w}` && (R.operation.kind === "copy" || R.operation.kind === "share") && (y[w] = { ...R, status: b ? "error" : "done", error: b ? e.error : null });
1226
+ R.step === "persist" && h.requestId === `sharing:${w}` && (R.operation.kind === "copy" || R.operation.kind === "share") && (y[w] = { ...R, status: b ? "error" : "done", error: b ? e.error : null });
1222
1227
  a({ actions: y });
1223
1228
  }
1224
- if (!b && f.mode === "mutation" && f.operation.kind === "preference" && n.interactions.promptActions[f.requestId]) {
1225
- const y = n.interactions.promptActions[f.requestId];
1226
- u(y.feature, f.requestId), h({
1229
+ if (!b && h.mode === "mutation" && h.operation.kind === "preference" && n.interactions.promptActions[h.requestId]) {
1230
+ const y = n.interactions.promptActions[h.requestId];
1231
+ u(y.feature, h.requestId), f({
1227
1232
  kind: "preferenceAcknowledge",
1228
1233
  feature: y.feature,
1229
1234
  action: y.action,
1230
1235
  expectedRevision: y.expectedRevision
1231
- }, `${f.requestId}:ack`);
1236
+ }, `${h.requestId}:ack`);
1232
1237
  }
1233
- if (I(e.effectId, b), f.operation.kind === "generatePrompts") {
1234
- const y = { kind: "starterPrompts", ...f.operation.page, includeUserSuggestions: f.operation.includeUserSuggestions ?? !1 }, w = ue(o, y), R = n.features.queries[w];
1235
- R?.requestId === f.requestId && r({ queries: { ...n.features.queries, [w]: b ? ct(R, { key: w, requestId: re(f.requestId), error: e.error }) : Zt(R, { key: w, requestId: re(f.requestId), data: e.output.data, cursor: null, updatedAt: e.output.completedAt }) } });
1238
+ if (I(e.effectId, b), h.operation.kind === "generatePrompts") {
1239
+ const y = { kind: "starterPrompts", ...h.operation.page, includeUserSuggestions: h.operation.includeUserSuggestions ?? !1 }, w = ae(o, y), R = n.features.queries[w];
1240
+ R?.requestId === h.requestId && r({ queries: { ...n.features.queries, [w]: b ? ct(R, { key: w, requestId: re(h.requestId), error: e.error }) : Zt(R, { key: w, requestId: re(h.requestId), data: e.output.data, cursor: null, updatedAt: e.output.completedAt }) } });
1236
1241
  }
1237
1242
  if (!b && e.output.data.kind === "originContext") {
1238
- const y = e.output.data, w = f.operation.kind === "originContext" || f.operation.kind === "refreshContext" ? f.operation.origin : null;
1243
+ const y = e.output.data, w = h.operation.kind === "originContext" || h.operation.kind === "refreshContext" ? h.operation.origin : null;
1239
1244
  if (w) {
1240
1245
  if (y.value.runId && ["queued", "pending", "running", "in_progress", "stopping", "cancel_requested"].includes(y.value.status))
1241
1246
  r({ contextRunOrigins: { ...n.features.contextRunOrigins, [y.value.runId]: w } });
@@ -1244,7 +1249,7 @@ function js(t, e, s) {
1244
1249
  for (const [T, C] of Object.entries(R)) C === w && delete R[T];
1245
1250
  r({ contextRunOrigins: R });
1246
1251
  }
1247
- if (f.mode === "mutation") {
1252
+ if (h.mode === "mutation") {
1248
1253
  const R = { ...n.features.queries }, T = { ...n.features.pending }, C = { ...n.features.contextReads }, E = { ...n.features.polls };
1249
1254
  for (const [q, O] of Object.entries(n.features.originContextQueries))
1250
1255
  if (O.origin === w) {
@@ -1265,66 +1270,70 @@ function js(t, e, s) {
1265
1270
  if (C.origin !== w) continue;
1266
1271
  const E = { ...n.features.pending };
1267
1272
  for (const [q, O] of Object.entries(E)) O.mode === "query" && O.key === T && delete E[q];
1268
- r({ pending: E }), m({ ...C, kind: "originContext" }, `context-final:${f.requestId}:${T}`, !0);
1273
+ r({ pending: E }), m({ ...C, kind: "originContext" }, `context-final:${h.requestId}:${T}`, !0);
1269
1274
  }
1270
1275
  }
1271
1276
  }
1272
1277
  if (!b && ["originContext", "userContext", "contextRun"].includes(e.output.data.kind)) {
1273
1278
  const y = e.output.data;
1274
1279
  if (y.kind === "originContext" || y.kind === "userContext" || y.kind === "contextRun") {
1275
- const w = y.kind === "originContext" ? f.mode === "query" && f.operation.kind === "originContext" && Object.values(n.features.contextObservers).includes(f.key) ? f.operation : null : y.kind === "userContext" ? { kind: "userContext" } : y.value.runId ? { kind: "contextRun", runId: y.value.runId } : null;
1280
+ const w = y.kind === "originContext" ? h.mode === "query" && h.operation.kind === "originContext" && Object.values(n.features.contextObservers).includes(h.key) ? h.operation : null : y.kind === "userContext" ? { kind: "userContext" } : y.value.runId ? { kind: "contextRun", runId: y.value.runId } : null;
1276
1281
  if (w && ["queued", "pending", "running", "in_progress", "stopping", "cancel_requested"].includes(y.value.status)) {
1277
- const R = ue(o, w);
1282
+ const R = ae(o, w);
1278
1283
  r({ polls: { ...n.features.polls, [R]: { query: w, deadline: n.features.now + 5e3 } } });
1279
1284
  }
1280
1285
  }
1281
1286
  }
1282
- if (!b && f.operation.kind === "stopContext")
1287
+ if (!b && h.operation.kind === "stopContext")
1283
1288
  for (const [y, w] of Object.entries(n.features.originContextQueries)) {
1284
1289
  const R = n.features.queries[y]?.data;
1285
- if (R?.kind === "originContext" && R.value.runId === f.operation.runId) {
1290
+ if (R?.kind === "originContext" && R.value.runId === h.operation.runId) {
1286
1291
  const T = { ...n.features.pending };
1287
1292
  for (const [C, E] of Object.entries(T)) E.mode === "query" && E.key === y && delete T[C];
1288
- r({ pending: T }), m({ ...w, kind: "originContext" }, `context-stop:${f.requestId}:${y}`, !0);
1293
+ r({ pending: T }), m({ ...w, kind: "originContext" }, `context-stop:${h.requestId}:${y}`, !0);
1289
1294
  }
1290
1295
  }
1291
- if (b && f.mode === "query" && ["originContext", "userContext", "contextRun"].includes(f.operation.kind) && e.error.retryable && (n.features.contextReads[f.key]?.failures ?? 0) <= 3) {
1292
- const y = f.operation, w = ue(o, y);
1293
- r({ polls: { ...n.features.polls, [w]: { query: y, deadline: n.features.now + 5e3 * (n.features.contextReads[f.key]?.failures ?? 1) } } });
1296
+ if (b && h.mode === "query" && ["originContext", "userContext", "contextRun"].includes(h.operation.kind) && e.error.retryable && (n.features.contextReads[h.key]?.failures ?? 0) <= 3) {
1297
+ const y = h.operation, w = ae(o, y);
1298
+ r({ polls: { ...n.features.polls, [w]: { query: y, deadline: n.features.now + 5e3 * (n.features.contextReads[h.key]?.failures ?? 1) } } });
1294
1299
  }
1295
- if (f.operation.kind === "preference") {
1296
- const y = f.operation.feature, w = n.features.queuedPreferences[y];
1300
+ if (h.mode === "query" && h.operation.kind === "userSuggestedTasks") {
1301
+ const y = b ? n.features.suggestionReadFailures + 1 : 0, w = { ...n.features.polls };
1302
+ delete w[h.key], b && y <= 3 && (e.error.retryable || ["connection_interrupted", "request_timed_out", "408", "425", "429", "500", "502", "503", "504"].includes(e.error.code)) && (w[h.key] = { query: h.operation, deadline: n.features.now + 1e3 * 2 ** (y - 1) }), r({ suggestionReadFailures: y, polls: w });
1303
+ }
1304
+ if (h.operation.kind === "preference") {
1305
+ const y = h.operation.feature, w = n.features.queuedPreferences[y];
1297
1306
  if (w) {
1298
1307
  const R = { ...n.features.queuedPreferences };
1299
- delete R[y], r({ queuedPreferences: R }), h({ kind: "preference", feature: y, enabled: w.enabled }, w.requestId);
1308
+ delete R[y], r({ queuedPreferences: R }), f({ kind: "preference", feature: y, enabled: w.enabled }, w.requestId);
1300
1309
  } else {
1301
1310
  const R = { ...n.features.desiredPreferences };
1302
1311
  delete R[y], r({ desiredPreferences: R });
1303
1312
  }
1304
1313
  }
1305
- if (!b && e.output.data.kind === "preferences") for (const y of ["notifications", "tab_grouping"]) d(y, "check", `preference:${f.requestId}:${y}`);
1314
+ if (!b && e.output.data.kind === "preferences") for (const y of ["notifications", "tab_grouping"]) d(y, "check", `preference:${h.requestId}:${y}`);
1306
1315
  n.features.refreshRequired && !n.features.refreshBatch && !n.features.refreshQueuedRequestId && ["account", "preferences", "preferencePrompts", "decisions"].every((y) => Object.values(n.features.queries).some((w) => w.data?.kind === y && w.status === "ready")) && r({ refreshRequired: !1 });
1307
1316
  break;
1308
1317
  }
1309
1318
  }
1310
1319
  const _ = [
1311
1320
  n.features.refreshAt,
1312
- ...Object.values(n.interactions.openings).flatMap((f) => Object.values(f.turns).filter((b) => b.active && !b.notifications && !b.notificationsSuppressed).map((b) => b.startedAt + 1e4)),
1313
- ...Object.values(n.interactions.welcome).map((f) => f.eligible ? f.expiresAt ?? null : null),
1314
- ...Object.values(n.interactions.sources).map((f) => f.lifecycle === "pending" && f.payload.kind === "integration_auth" ? Date.parse(f.payload.expires_at) : null),
1315
- ...Object.values(n.features.polls).map((f) => f.deadline),
1316
- ...Object.values(n.interactions.decisions).map((f) => f.nextEligibleAt ? Date.parse(f.nextEligibleAt) : null),
1317
- ...Object.values(n.interactions.preferencePrompts).map((f) => f.snoozedUntil ? Date.parse(f.snoozedUntil) : null),
1318
- ...Object.values(n.interactions.deviceFacts).map((f) => f.snoozedUntil ? Date.parse(f.snoozedUntil) : null)
1319
- ].filter((f) => f !== null && f > n.features.now), S = _.length ? Math.min(..._) : null;
1321
+ ...Object.values(n.interactions.openings).flatMap((h) => Object.values(h.turns).filter((b) => b.active && !b.notifications && !b.notificationsSuppressed).map((b) => b.startedAt + 1e4)),
1322
+ ...Object.values(n.interactions.welcome).map((h) => h.eligible ? h.expiresAt ?? null : null),
1323
+ ...Object.values(n.interactions.sources).map((h) => h.lifecycle === "pending" && h.payload.kind === "integration_auth" ? Date.parse(h.payload.expires_at) : null),
1324
+ ...Object.values(n.features.polls).map((h) => h.deadline),
1325
+ ...Object.values(n.interactions.decisions).map((h) => h.nextEligibleAt ? Date.parse(h.nextEligibleAt) : null),
1326
+ ...Object.values(n.interactions.preferencePrompts).map((h) => h.snoozedUntil ? Date.parse(h.snoozedUntil) : null),
1327
+ ...Object.values(n.interactions.deviceFacts).map((h) => h.snoozedUntil ? Date.parse(h.snoozedUntil) : null)
1328
+ ].filter((h) => h !== null && h > n.features.now), S = _.length ? Math.min(..._) : null;
1320
1329
  if (S !== n.features.timerDeadline && !n.features.schedulerError) {
1321
- const f = n.features.timerRevision + 1, b = S === null ? null : Se(o, "wait", `${f}:${S}`);
1322
- r({ timerId: b, timerDeadline: S, timerRevision: f }), S !== null && b && i.push({ kind: "stage7.wait", id: b, input: { authority: o, deadline: S } });
1330
+ const h = n.features.timerRevision + 1, b = S === null ? null : Se(o, "wait", `${h}:${S}`);
1331
+ r({ timerId: b, timerDeadline: S, timerRevision: h }), S !== null && b && i.push({ kind: "stage7.wait", id: b, input: { authority: o, deadline: S } });
1323
1332
  }
1324
1333
  return { state: n, effects: i };
1325
1334
  }
1326
1335
  function Bs(t, e) {
1327
- return t.account.authority ? t.features.queries[ue(t.account.authority, e)] ?? null : null;
1336
+ return t.account.authority ? t.features.queries[ae(t.account.authority, e)] ?? null : null;
1328
1337
  }
1329
1338
  function nt(t) {
1330
1339
  if (!t || typeof t != "object") return !1;
@@ -1373,7 +1382,7 @@ function P(t) {
1373
1382
  if (typeof t != "string") throw new Error("Invalid feature response string.");
1374
1383
  return t;
1375
1384
  }
1376
- function ce(t) {
1385
+ function de(t) {
1377
1386
  return t == null ? null : P(t);
1378
1387
  }
1379
1388
  function Oe(t) {
@@ -1392,7 +1401,7 @@ function bt(t) {
1392
1401
  return t.map(P);
1393
1402
  }
1394
1403
  function Mt(t) {
1395
- const e = ce(t);
1404
+ const e = de(t);
1396
1405
  if (e !== null && !Number.isFinite(Date.parse(e))) throw new Error("Invalid feature deadline.");
1397
1406
  return e;
1398
1407
  }
@@ -1404,13 +1413,13 @@ function ze(t) {
1404
1413
  preferencesVersion: Oe(e.preferencesVersion),
1405
1414
  scribbleStyleEnabled: ts(e.scribbleStyleEnabled),
1406
1415
  blockedOrigins: bt(e.blockedServiceOrigins),
1407
- personalInstructions: ce(e.personalInstructions),
1416
+ personalInstructions: de(e.personalInstructions),
1408
1417
  securityPolicyVersion: Oe(e.securityPolicyVersion)
1409
1418
  };
1410
1419
  }
1411
1420
  function Pt(t) {
1412
1421
  const e = N(t);
1413
- return { eligibleSince: Mt(e.eligibleSince), revision: Oe(e.revision), requestId: ce(e.requestId), snoozedUntil: Mt(e.snoozedUntil) };
1422
+ return { eligibleSince: Mt(e.eligibleSince), revision: Oe(e.revision), requestId: de(e.requestId), snoozedUntil: Mt(e.snoozedUntil) };
1414
1423
  }
1415
1424
  function Qr(t) {
1416
1425
  const e = N(t);
@@ -1465,14 +1474,14 @@ function Xr(t) {
1465
1474
  }
1466
1475
  function He(t, e) {
1467
1476
  const s = N(e);
1468
- if (t === "contextRun") return { kind: t, value: { status: P(s.status), runId: P(s.id), updatedAt: ce(s.completedAt ?? s.createdAt), hasContext: null } };
1469
- const n = s.latestRun === null || s.latestRun === void 0 ? null : N(s.latestRun), i = ce(s.activeRefreshRunId);
1477
+ if (t === "contextRun") return { kind: t, value: { status: P(s.status), runId: P(s.id), updatedAt: de(s.completedAt ?? s.createdAt), hasContext: null } };
1478
+ const n = s.latestRun === null || s.latestRun === void 0 ? null : N(s.latestRun), i = de(s.activeRefreshRunId);
1470
1479
  return { kind: t, value: {
1471
1480
  ...s.origin === void 0 ? {} : { origin: P(s.origin) },
1472
- ...n?.createdAt === void 0 ? {} : { latestRun: { id: P(n.id), status: P(n.status), createdAt: P(n.createdAt), completedAt: ce(n.completedAt), error: ce(n.error) } },
1481
+ ...n?.createdAt === void 0 ? {} : { latestRun: { id: P(n.id), status: P(n.status), createdAt: P(n.createdAt), completedAt: de(n.completedAt), error: de(n.error) } },
1473
1482
  status: i ? "running" : n ? P(n.status) : "idle",
1474
1483
  runId: i ?? (n ? P(n.id) : null),
1475
- updatedAt: ce(s.latestSnapshotUpdatedAt),
1484
+ updatedAt: de(s.latestSnapshotUpdatedAt),
1476
1485
  hasContext: je(s.hasContext)
1477
1486
  } };
1478
1487
  }
@@ -1487,7 +1496,7 @@ function dt(t, e) {
1487
1496
  }
1488
1497
  function lt(t) {
1489
1498
  const e = N(t);
1490
- if (!je(e.success)) throw new Error(ce(e.message) ?? "Failed to submit feedback");
1499
+ if (!je(e.success)) throw new Error(de(e.message) ?? "Failed to submit feedback");
1491
1500
  return { kind: "ack", success: !0 };
1492
1501
  }
1493
1502
  function ns(t) {
@@ -1541,16 +1550,16 @@ function Yr(t) {
1541
1550
  }
1542
1551
  case "starterPrompts": {
1543
1552
  const c = N(await a("/starter-prompts", r ? { page_url: n.pageUrl } : { origin: n.origin, page_url: n.pageUrl, include_user_suggestions: n.includeUserSuggestions }));
1544
- o = { kind: "starterPrompts", origin: n.origin, prompts: bt(c.starterPrompts), ...c.runtimeHelpers === void 0 ? {} : { runtimeHelpersJavascript: c.runtimeHelpers === null ? null : ce(N(c.runtimeHelpers).javascript) } };
1553
+ o = { kind: "starterPrompts", origin: n.origin, prompts: bt(c.starterPrompts), ...c.runtimeHelpers === void 0 ? {} : { runtimeHelpersJavascript: c.runtimeHelpers === null ? null : de(N(c.runtimeHelpers).javascript) } };
1545
1554
  break;
1546
1555
  }
1547
1556
  case "userSuggestedTasks": {
1548
- const c = N(await a("/user-suggested-tasks"));
1557
+ const c = N(await t.http.request("/user-suggested-tasks", {}, void 0, "GET", "runtime", { skipAuthentication: !0 }));
1549
1558
  if (!Array.isArray(c.proactiveSuggestions)) throw new Error("Invalid proactive suggestions.");
1550
1559
  o = {
1551
1560
  kind: "userSuggestedTasks",
1552
1561
  prompts: bt(c.starterPrompts),
1553
- morningReportOpening: ce(c.morningReportOpening),
1562
+ morningReportOpening: de(c.morningReportOpening),
1554
1563
  signupAt: P(c.signupAt),
1555
1564
  proactiveSuggestions: c.proactiveSuggestions.map(Xr)
1556
1565
  };
@@ -1712,8 +1721,8 @@ function Fi(t, e, s) {
1712
1721
  let c = !1, l = !1, d = () => {
1713
1722
  }, u = () => {
1714
1723
  };
1715
- const p = (m, h) => {
1716
- l || (l = !0, d(), u(), m ? o(m) : a(h));
1724
+ const p = (m, f) => {
1725
+ l || (l = !0, d(), u(), m ? o(m) : a(f));
1717
1726
  }, g = () => {
1718
1727
  if (!c) return;
1719
1728
  const m = t.engine.getState().slices;
@@ -1721,16 +1730,16 @@ function Fi(t, e, s) {
1721
1730
  p(new Error("Feature authority retired."));
1722
1731
  return;
1723
1732
  }
1724
- if (e.type === "stage7.query" && e.query.kind === "originContext" && m.features.contextObservers[e.query.clientScopeId] !== ue(n, e.query)) {
1733
+ if (e.type === "stage7.query" && e.query.kind === "originContext" && m.features.contextObservers[e.query.clientScopeId] !== ae(n, e.query)) {
1725
1734
  p(Object.assign(new Error("Context observation retired."), { code: "observation_released", retryable: !1 }));
1726
1735
  return;
1727
1736
  }
1728
- const h = Object.values(m.features.pending).find((v) => v.requestId === r);
1729
- if (!h && e.type === "stage7.query") {
1737
+ const f = Object.values(m.features.pending).find((v) => v.requestId === r);
1738
+ if (!f && e.type === "stage7.query") {
1730
1739
  const v = Bs(m, e.query);
1731
1740
  v?.status === "error" ? p(v.error) : v?.status === "ready" && v.data && p(null, v.data);
1732
1741
  }
1733
- h?.status === "error" ? p(h.error) : h?.status === "done" && p(null, h.result);
1742
+ f?.status === "error" ? p(f.error) : f?.status === "done" && p(null, f.result);
1734
1743
  };
1735
1744
  d = t.engine.subscribe(g), u = t.onDispose(() => p(new Error("Feature runtime disposed."))), t.engine.dispatch({ ...e, authority: n, requestId: r, now: Date.now() }).then(() => {
1736
1745
  c = !0, g();
@@ -1745,25 +1754,25 @@ async function no(t, e, s = crypto.randomUUID()) {
1745
1754
  let c = !1, l = !1, d = () => {
1746
1755
  }, u = () => {
1747
1756
  };
1748
- const p = (h) => {
1749
- l || (l = !0, d(), u(), h ? o(h) : a());
1757
+ const p = (f) => {
1758
+ l || (l = !0, d(), u(), f ? o(f) : a());
1750
1759
  }, g = () => {
1751
1760
  if (!c) return;
1752
- const h = t.engine.getState().slices;
1753
- if (JSON.stringify(h.account.authority) !== JSON.stringify(n)) return p(new Error("Feature authority retired."));
1754
- const v = h.interactions.actions[r];
1761
+ const f = t.engine.getState().slices;
1762
+ if (JSON.stringify(f.account.authority) !== JSON.stringify(n)) return p(new Error("Feature authority retired."));
1763
+ const v = f.interactions.actions[r];
1755
1764
  if (v) {
1756
1765
  v.status === "error" ? p(v.error) : v.status === "done" && p();
1757
1766
  return;
1758
1767
  }
1759
- const I = Object.values(h.features.pending).find((S) => S.requestId === r);
1768
+ const I = Object.values(f.features.pending).find((S) => S.requestId === r);
1760
1769
  if (I) {
1761
1770
  I.status === "error" ? p(I.error) : I.status === "done" && p();
1762
1771
  return;
1763
1772
  }
1764
- if (Object.values(h.interactions.devicePending).some((S) => S.requestId === r)) return;
1773
+ if (Object.values(f.interactions.devicePending).some((S) => S.requestId === r)) return;
1765
1774
  const _ = e.interactionId === "preference:notifications" ? "notifications" : e.interactionId === "preference:tab_grouping" ? "tab_grouping" : null;
1766
- p(_ ? h.interactions.deviceErrors[_] : void 0);
1775
+ p(_ ? f.interactions.deviceErrors[_] : void 0);
1767
1776
  };
1768
1777
  d = t.engine.subscribe(g), u = t.onDispose(() => p(new Error("Feature runtime disposed.")));
1769
1778
  const m = i ? { type: "stage7.retry_action", authority: n, now: Date.now(), requestId: r } : { type: "stage7.act", authority: n, now: Date.now(), requestId: r, ...e, sourceVersion: e.expectedSourceVersion ?? null };
@@ -1836,7 +1845,7 @@ function oo(t, e = null) {
1836
1845
  } : void 0);
1837
1846
  return { ...n, ...o ? { auth: o } : {}, submissionGate: a, usingPaidCreditFallback: e ? t.paidFallbackBySession[e] ?? !1 : !1 };
1838
1847
  }
1839
- const ao = "0.1.265", jt = {
1848
+ const ao = "0.1.267", jt = {
1840
1849
  version: ao
1841
1850
  }, dn = (t) => t.selectedModel ?? t.historyModel ?? t.defaultModel, co = (t, e) => t.scopes[e];
1842
1851
  function Bt(t) {
@@ -1845,19 +1854,19 @@ function Bt(t) {
1845
1854
  function Ls(t, e) {
1846
1855
  if (e.conversation_id !== t.sessionId) throw new Error("Display item belongs to another conversation.");
1847
1856
  if (t.removedItems[e.id]) return t;
1848
- const s = he(e.created_at);
1849
- he(e.updated_at);
1857
+ const s = fe(e.created_at);
1858
+ fe(e.updated_at);
1850
1859
  const n = xt(e);
1851
1860
  n !== null && Bt(n);
1852
1861
  const i = t.streams[e.id];
1853
1862
  if (n !== null && i && (i.state === "stopped" || i.state === "finished") && n > i.revision) return t;
1854
1863
  const r = t.items[e.id];
1855
1864
  if (r) {
1856
- if (he(r.created_at) !== s) throw new Error("Display shell timestamp changed.");
1865
+ if (fe(r.created_at) !== s) throw new Error("Display shell timestamp changed.");
1857
1866
  const a = xt(r);
1858
1867
  if (a !== null && n !== null) {
1859
1868
  if (n <= a) return t;
1860
- } else if (he(e.updated_at) <= he(r.updated_at)) return t;
1869
+ } else if (fe(e.updated_at) <= fe(r.updated_at)) return t;
1861
1870
  }
1862
1871
  return { ...t, items: { ...t.items, [e.id]: { ...e, created_at: r?.created_at ?? e.created_at } } };
1863
1872
  }
@@ -1870,7 +1879,7 @@ function Fs(t, e) {
1870
1879
  if (e.conversation_id !== t.sessionId) throw new Error("Execution belongs to another conversation.");
1871
1880
  if (Bt(e.version), t.execution && e.version <= t.execution.version) return t;
1872
1881
  const s = { ...t.executionByUserMessage };
1873
- for (const n of de(e)) s[n] = {
1882
+ for (const n of le(e)) s[n] = {
1874
1883
  version: e.version,
1875
1884
  phase: e.phase,
1876
1885
  responseMessageIds: e.response_message_groups?.find((i) => i.includes(n)) ?? [n]
@@ -1999,7 +2008,7 @@ function uo(t, e, s, n) {
1999
2008
  else {
2000
2009
  const m = X(e.output.snapshot);
2001
2010
  o.lane === "current" && (c = { ...c, preparation: null });
2002
- const h = c.queries.history, v = o.lane === "current" && (h.status === "not_requested" || m.next_cursor !== null && !c.items[m.next_cursor]);
2011
+ const f = c.queries.history, v = o.lane === "current" && (f.status === "not_requested" || m.next_cursor !== null && !c.items[m.next_cursor]);
2003
2012
  if (m.conversation_id !== o.sessionId) throw new Error("Snapshot belongs to another conversation.");
2004
2013
  for (const I of m.removed_items) c = rs(c, I);
2005
2014
  for (const I of m.items) c = Ls(c, I);
@@ -2029,7 +2038,7 @@ function uo(t, e, s, n) {
2029
2038
  } } }, v) {
2030
2039
  for (const [I, _] of Object.entries(p))
2031
2040
  _.sessionId === o.sessionId && _.lane === "history" && delete p[I];
2032
- c = { ...c, queries: { ...c.queries, history: { ...c.queries.current, key: h.key } } };
2041
+ c = { ...c, queries: { ...c.queries, history: { ...c.queries.current, key: f.key } } };
2033
2042
  }
2034
2043
  }
2035
2044
  i = { ...t, requests: p, submissions: g, sessions: { ...t.sessions, [c.sessionId]: c } };
@@ -2059,16 +2068,16 @@ function uo(t, e, s, n) {
2059
2068
  if (s.clients[e.clientScopeId] !== e.conversationScopeId) throw new Error("Submission selection has changed.");
2060
2069
  const { type: o, authorityId: c, generation: l, prepareContext: d, waitForAuthentication: u, ...p } = e, g = t.submissions[e.userMessageId];
2061
2070
  if (g) {
2062
- const { contextPreparation: S, requestedModel: f, sessionId: b, delivery: y, cancelled: w, cancellationReason: R, error: T, executionVersion: C, ...E } = g;
2071
+ const { contextPreparation: S, requestedModel: h, sessionId: b, delivery: y, cancelled: w, cancellationReason: R, error: T, executionVersion: C, ...E } = g;
2063
2072
  if (ut(E) !== ut(p)) throw new Error("User-message identity cannot be reused with different input.");
2064
2073
  return { state: t, effects: r };
2065
2074
  }
2066
- const m = s.selections[e.conversationScopeId], h = Object.values(t.submissions).find((S) => S.conversationScopeId === e.conversationScopeId && !S.cancelled && S.sessionId !== null), v = n.scopes[e.clientScopeId], I = {
2075
+ const m = s.selections[e.conversationScopeId], f = Object.values(t.submissions).find((S) => S.conversationScopeId === e.conversationScopeId && !S.cancelled && S.sessionId !== null), v = n.scopes[e.clientScopeId], I = {
2067
2076
  ...X(p),
2068
2077
  ...d ? { contextPreparation: null } : {},
2069
2078
  // Extension staging can await page context after the picker has already changed.
2070
2079
  requestedModel: v?.submissions[e.userMessageId] ? v.submissions[e.userMessageId].requestedModel ?? null : v ? dn(v) ?? null : null,
2071
- sessionId: m.sessionId ?? h?.sessionId ?? null,
2080
+ sessionId: m.sessionId ?? f?.sessionId ?? null,
2072
2081
  delivery: u ? "failed" : "staged",
2073
2082
  cancelled: !1,
2074
2083
  error: u ? { code: u, message: u === "unauthorized" ? "Open the Pluno login link, then return to Pluno." : "Pluno is reconnecting. Try again in a moment.", retryable: !1 } : null,
@@ -2091,11 +2100,11 @@ function uo(t, e, s, n) {
2091
2100
  }
2092
2101
  case "conversation.stop": {
2093
2102
  if (s.clients[e.clientScopeId] !== e.conversationScopeId) return { state: t, effects: r };
2094
- const o = s.selections[e.conversationScopeId].sessionId, c = o ? t.sessions[o]?.execution : null, l = Object.values(t.submissions).filter((h) => (o ? h.sessionId === o : h.conversationScopeId === e.conversationScopeId) && (!e.userMessageIds || e.userMessageIds.includes(h.userMessageId))), d = l.filter((h) => !h.cancelled && (h.delivery !== "failed" || t.deliveries[h.userMessageId]?.phase === "paused" || e.userMessageIds?.includes(h.userMessageId) && t.deliveries[h.userMessageId]?.acceptance === "unissued") && (h.delivery !== "accepted" || h.executionVersion === null)), u = d.length > 0, p = c && ["queued", "thinking", "steering", "stopping"].includes(c.phase) && (!e.userMessageIds || de(c).some((h) => e.userMessageIds.includes(h)));
2103
+ const o = s.selections[e.conversationScopeId].sessionId, c = o ? t.sessions[o]?.execution : null, l = Object.values(t.submissions).filter((f) => (o ? f.sessionId === o : f.conversationScopeId === e.conversationScopeId) && (!e.userMessageIds || e.userMessageIds.includes(f.userMessageId))), d = l.filter((f) => !f.cancelled && (f.delivery !== "failed" || t.deliveries[f.userMessageId]?.phase === "paused" || e.userMessageIds?.includes(f.userMessageId) && t.deliveries[f.userMessageId]?.acceptance === "unissued") && (f.delivery !== "accepted" || f.executionVersion === null)), u = d.length > 0, p = c && ["queued", "thinking", "steering", "stopping"].includes(c.phase) && (!e.userMessageIds || le(c).some((f) => e.userMessageIds.includes(f)));
2095
2104
  if (!u && !p && (c || !e.userMessageIds?.length)) return { state: t, effects: r };
2096
- const g = Array.from(new Set(e.userMessageIds ?? [...d.map((h) => h.userMessageId), ...p ? de(c) : []])), m = { ...t.submissions };
2097
- for (const h of l)
2098
- g.includes(h.userMessageId) && h.delivery !== "accepted" && (m[h.userMessageId] = { ...h, cancelled: !0, cancellationReason: e.reason ?? "user_requested" });
2105
+ const g = Array.from(new Set(e.userMessageIds ?? [...d.map((f) => f.userMessageId), ...p ? le(c) : []])), m = { ...t.submissions };
2106
+ for (const f of l)
2107
+ g.includes(f.userMessageId) && f.delivery !== "accepted" && (m[f.userMessageId] = { ...f, cancelled: !0, cancellationReason: e.reason ?? "user_requested" });
2099
2108
  i = { ...t, submissions: m, stops: { ...t.stops, [e.conversationScopeId]: {
2100
2109
  requestId: e.requestId,
2101
2110
  userMessageIds: g,
@@ -2127,7 +2136,7 @@ function uo(t, e, s, n) {
2127
2136
  const p = l[u.lane];
2128
2137
  l[u.lane] = { ...p, requestId: null, status: p.data === null ? "not_requested" : "ready" };
2129
2138
  }
2130
- l.history = me(l.history.key), i = { ...t, requests: c, sessions: { ...t.sessions, [e.sessionId]: { ...o, queries: l } } };
2139
+ l.history = ye(l.history.key), i = { ...t, requests: c, sessions: { ...t.sessions, [e.sessionId]: { ...o, queries: l } } };
2131
2140
  break;
2132
2141
  }
2133
2142
  case "conversation.snapshot": {
@@ -2260,7 +2269,7 @@ function Ws(t) {
2260
2269
  l = { ...l, uploads: [...l.uploads, g.uploaded] };
2261
2270
  continue;
2262
2271
  }
2263
- const m = Object.values(e.operations).find((h) => h.command.type === "attachment.prepare" && h.conversationScopeId === c.conversationScopeId && h.phase === "done" && h.command.payload.source.sourceId === g.sourceId && h.result?.sessionId === c.sessionId);
2272
+ const m = Object.values(e.operations).find((f) => f.command.type === "attachment.prepare" && f.conversationScopeId === c.conversationScopeId && f.phase === "done" && f.command.payload.source.sourceId === g.sourceId && f.result?.sessionId === c.sessionId);
2264
2273
  if (!m) break;
2265
2274
  l = { ...l, uploads: [...l.uploads, m.result.attachment] };
2266
2275
  }
@@ -2306,7 +2315,7 @@ function Ws(t) {
2306
2315
  };
2307
2316
  for (const [o, c] of Object.entries(e.stops))
2308
2317
  for (const l of c.userMessageIds) {
2309
- const d = e.submissions[l], u = d?.sessionId ?? Object.values(e.sessions).find((g) => de(g.execution).includes(l))?.sessionId, p = d?.delivery === "accepted" || u && de(e.sessions[u]?.execution).includes(l);
2318
+ const d = e.submissions[l], u = d?.sessionId ?? Object.values(e.sessions).find((g) => le(g.execution).includes(l))?.sessionId, p = d?.delivery === "accepted" || u && le(e.sessions[u]?.execution).includes(l);
2310
2319
  u && p && a(`stop:${o}:${c.requestId}:${l}`, u, l, c.reason);
2311
2320
  }
2312
2321
  for (const o of Object.values(e.submissions))
@@ -2350,8 +2359,8 @@ function ho(t, e, s, n) {
2350
2359
  const p = t.deliveries[d], g = t.submissions[d];
2351
2360
  let m = { ...p, phase: "waiting", effectId: null };
2352
2361
  if (e.type === "effect.failed") {
2353
- const h = e.error.details?.acceptance === "unissued" && p.acceptance !== "accepted" ? "unissued" : e.error.details?.acceptance === "rejected" ? "rejected" : p.acceptance, v = e.error.details?.allocation === "unissued" ? "unissued" : p.allocation, I = e.effectKind === "conversation.command" && p.step === "send" && h === "unissued" || e.effectKind === "conversation.upload" && e.error.details?.allocation === "unissued", _ = e.effectKind === "conversation.prepare" || I ? "failed" : h === "uncertain" || v === "uncertain" || e.error.retryable ? "uncertain" : "failed";
2354
- m = { ...m, phase: _, acceptance: h, allocation: v }, !g.cancelled && g.delivery !== "accepted" && (i = { ...i, submissions: {
2362
+ const f = e.error.details?.acceptance === "unissued" && p.acceptance !== "accepted" ? "unissued" : e.error.details?.acceptance === "rejected" ? "rejected" : p.acceptance, v = e.error.details?.allocation === "unissued" ? "unissued" : p.allocation, I = e.effectKind === "conversation.command" && p.step === "send" && f === "unissued" || e.effectKind === "conversation.upload" && e.error.details?.allocation === "unissued", _ = e.effectKind === "conversation.prepare" || I ? "failed" : f === "uncertain" || v === "uncertain" || e.error.retryable ? "uncertain" : "failed";
2363
+ m = { ...m, phase: _, acceptance: f, allocation: v }, !g.cancelled && g.delivery !== "accepted" && (i = { ...i, submissions: {
2355
2364
  ...i.submissions,
2356
2365
  [d]: { ...g, delivery: _, error: e.error }
2357
2366
  } });
@@ -2365,13 +2374,13 @@ function ho(t, e, s, n) {
2365
2374
  error: { code: "message_delivery_failed", message: "Pluno could not send this message. Try it again.", retryable: !0 }
2366
2375
  } } }));
2367
2376
  else if (e.effectKind === "conversation.upload") {
2368
- const h = X(e.output), v = g.attachments[p.uploads.length];
2369
- if (h.attachment.id !== v.sourceId || h.attachment.size_bytes !== v.sizeBytes || g.sessionId !== null && g.sessionId !== h.sessionId)
2377
+ const f = X(e.output), v = g.attachments[p.uploads.length];
2378
+ if (f.attachment.id !== v.sourceId || f.attachment.size_bytes !== v.sizeBytes || g.sessionId !== null && g.sessionId !== f.sessionId)
2370
2379
  throw new Error("Upload does not match the captured attachment or conversation.");
2371
- m = { ...m, allocation: "resolved", uploads: [...p.uploads, h.attachment] };
2380
+ m = { ...m, allocation: "resolved", uploads: [...p.uploads, f.attachment] };
2372
2381
  const I = Object.fromEntries(Object.entries(i.submissions).map(([_, S]) => [
2373
2382
  _,
2374
- S.conversationScopeId === g.conversationScopeId && (_ === d || !S.cancelled && !g.cancelled) ? { ...S, sessionId: h.sessionId } : S
2383
+ S.conversationScopeId === g.conversationScopeId && (_ === d || !S.cancelled && !g.cancelled) ? { ...S, sessionId: f.sessionId } : S
2375
2384
  ]));
2376
2385
  i = { ...i, submissions: I };
2377
2386
  } else if (e.effectKind === "conversation.receipt")
@@ -2382,25 +2391,25 @@ function ho(t, e, s, n) {
2382
2391
  error: { code: "message_acceptance_unconfirmed", message: "Pluno could not confirm whether this message was accepted. Try again.", retryable: !0 }
2383
2392
  } } });
2384
2393
  else {
2385
- const h = zn(e.output, d);
2394
+ const f = zn(e.output, d);
2386
2395
  m = { ...m, phase: "done", acceptance: "accepted" }, r = {
2387
2396
  type: "conversation.submission_accepted",
2388
2397
  authorityId: t.authorityId,
2389
2398
  generation: t.generation,
2390
2399
  userMessageId: d,
2391
- sessionId: h.sessionId
2400
+ sessionId: f.sessionId
2392
2401
  };
2393
2402
  }
2394
2403
  else if (e.effectKind === "conversation.command" && p.step === "complete")
2395
2404
  m = { ...m, completedUploads: p.completedUploads + 1, command: null };
2396
2405
  else if (e.effectKind === "conversation.command" && p.step === "send") {
2397
- const h = zn(e.output, d);
2406
+ const f = zn(e.output, d);
2398
2407
  m = { ...m, phase: "done", acceptance: "accepted" }, r = {
2399
2408
  type: "conversation.submission_accepted",
2400
2409
  authorityId: t.authorityId,
2401
2410
  generation: t.generation,
2402
2411
  userMessageId: d,
2403
- sessionId: h.sessionId
2412
+ sessionId: f.sessionId
2404
2413
  };
2405
2414
  }
2406
2415
  i = { ...i, deliveries: { ...i.deliveries, [d]: m } };
@@ -2437,36 +2446,36 @@ function ho(t, e, s, n) {
2437
2446
  if (d.schema !== 1 || d.authorityId !== t.authorityId || !u || Object.keys(t.operations).length)
2438
2447
  throw new Error("Delivery restoration requires an empty engine with the same authenticated authority.");
2439
2448
  const p = { ...t.submissions, ...d.submissions };
2440
- for (const [S, f] of Object.entries(t.submissions))
2441
- f.cancelled && (p[S] = { ...p[S], cancelled: !0, cancellationReason: f.cancellationReason });
2449
+ for (const [S, h] of Object.entries(t.submissions))
2450
+ h.cancelled && (p[S] = { ...p[S], cancelled: !0, cancellationReason: h.cancellationReason });
2442
2451
  const g = {
2443
2452
  ...d,
2444
2453
  submissions: p,
2445
2454
  stops: { ...d.stops, ...t.stops },
2446
2455
  deliveries: { ...t.deliveries, ...d.deliveries },
2447
2456
  submissionOrder: [.../* @__PURE__ */ new Set([...d.submissionOrder, ...t.submissionOrder])]
2448
- }, { schema: m, authorityId: h, ...v } = g, I = X(e.pendingRestoration ?? {}), _ = (S) => !s.clients[S.clientScopeId] && I[S.clientScopeId] === S.conversationScopeId;
2457
+ }, { schema: m, authorityId: f, ...v } = g, I = X(e.pendingRestoration ?? {}), _ = (S) => !s.clients[S.clientScopeId] && I[S.clientScopeId] === S.conversationScopeId;
2449
2458
  i = {
2450
2459
  ...t,
2451
2460
  ...v,
2452
2461
  pendingRestoration: I,
2453
2462
  requestSequence: Math.max(t.requestSequence, g.requestSequence),
2454
2463
  effectsEnabled: !0,
2455
- submissions: Object.fromEntries(Object.entries(g.submissions).map(([S, f]) => [S, {
2456
- ...f,
2464
+ submissions: Object.fromEntries(Object.entries(g.submissions).map(([S, h]) => [S, {
2465
+ ...h,
2457
2466
  executionVersion: null,
2458
- cancelled: f.cancelled || !_(f) && !zs(f, s),
2459
- ...!f.cancelled && !_(f) && !zs(f, s) ? { cancellationReason: "owner_lost" } : {},
2460
- delivery: (f.contextPreparation === null || !g.deliveries[S]) && !f.cancelled && f.delivery !== "accepted" ? "failed" : f.delivery === "sending" ? "uncertain" : f.delivery,
2461
- error: f.contextPreparation === null && !f.cancelled && !["unauthorized", "auth_reconnecting"].includes(f.error?.code ?? "") ? { code: "context_preparation_interrupted", message: "Page context preparation was interrupted. Please send this message again.", retryable: !1 } : !g.deliveries[S] && f.delivery !== "accepted" && !f.cancelled ? { code: "submission_interrupted", message: "Message preparation was interrupted. Retry this message.", retryable: !0 } : f.error
2467
+ cancelled: h.cancelled || !_(h) && !zs(h, s),
2468
+ ...!h.cancelled && !_(h) && !zs(h, s) ? { cancellationReason: "owner_lost" } : {},
2469
+ delivery: (h.contextPreparation === null || !g.deliveries[S]) && !h.cancelled && h.delivery !== "accepted" ? "failed" : h.delivery === "sending" ? "uncertain" : h.delivery,
2470
+ error: h.contextPreparation === null && !h.cancelled && !["unauthorized", "auth_reconnecting"].includes(h.error?.code ?? "") ? { code: "context_preparation_interrupted", message: "Page context preparation was interrupted. Please send this message again.", retryable: !1 } : !g.deliveries[S] && h.delivery !== "accepted" && !h.cancelled ? { code: "submission_interrupted", message: "Message preparation was interrupted. Retry this message.", retryable: !0 } : h.error
2462
2471
  }])),
2463
- deliveries: Object.fromEntries(Object.entries(g.submissions).map(([S, f], b) => {
2464
- const y = g.deliveries[S], w = f.contextPreparation === null, R = f.delivery === "accepted" ? "accepted" : y?.acceptance ?? (y && (y.step === "send" || y.step === "receipt") ? "uncertain" : "unissued");
2472
+ deliveries: Object.fromEntries(Object.entries(g.submissions).map(([S, h], b) => {
2473
+ const y = g.deliveries[S], w = h.contextPreparation === null, R = h.delivery === "accepted" ? "accepted" : y?.acceptance ?? (y && (y.step === "send" || y.step === "receipt") ? "uncertain" : "unissued");
2465
2474
  return [S, {
2466
- ...$n(f, b),
2475
+ ...$n(h, b),
2467
2476
  ...y,
2468
2477
  acceptance: R,
2469
- allocation: f.sessionId !== null ? "resolved" : y?.allocation ?? (y?.step === "upload" ? "uncertain" : "unissued"),
2478
+ allocation: h.sessionId !== null ? "resolved" : y?.allocation ?? (y?.step === "upload" ? "uncertain" : "unissued"),
2470
2479
  effectId: null,
2471
2480
  // Readiness is authority-local and must be re-established after restart. Captured input stays immutable.
2472
2481
  step: R === "uncertain" && y?.step === "send" && y.phase !== "done" ? "receipt" : y?.step ?? null,
@@ -2475,10 +2484,10 @@ function ho(t, e, s, n) {
2475
2484
  phase: R === "accepted" ? "done" : w || !y ? "failed" : ["running", "waiting"].includes(y.phase) ? "uncertain" : y.phase
2476
2485
  }];
2477
2486
  })),
2478
- operations: Object.fromEntries(Object.entries(g.operations).map(([S, f]) => [S, {
2479
- ...f,
2487
+ operations: Object.fromEntries(Object.entries(g.operations).map(([S, h]) => [S, {
2488
+ ...h,
2480
2489
  effectId: null,
2481
- phase: ["running", "waiting"].includes(f.phase) ? "uncertain" : f.phase
2490
+ phase: ["running", "waiting"].includes(h.phase) ? "uncertain" : h.phase
2482
2491
  }]))
2483
2492
  };
2484
2493
  }
@@ -2543,8 +2552,8 @@ function ho(t, e, s, n) {
2543
2552
  if (!u) {
2544
2553
  const p = d.type === "chat.retry_last_user_message" ? Object.fromEntries(Object.entries(t.stops).flatMap(([g, m]) => {
2545
2554
  if (s.selections[g]?.sessionId !== d.payload.sessionId) return [[g, m]];
2546
- const h = m.userMessageIds.filter((v) => v !== d.payload.clientMessageId);
2547
- return h.length ? [[g, { ...m, userMessageIds: h }]] : [];
2555
+ const f = m.userMessageIds.filter((v) => v !== d.payload.clientMessageId);
2556
+ return f.length ? [[g, { ...m, userMessageIds: f }]] : [];
2548
2557
  })) : t.stops;
2549
2558
  i = { ...t, stops: p, effectsEnabled: !0, operations: {
2550
2559
  ...t.operations,
@@ -2719,21 +2728,21 @@ function bo(t) {
2719
2728
  if (!o && s && a.requestSequence <= s.requestSequence) return;
2720
2729
  const m = await i();
2721
2730
  if (m && m.authorityId !== t.authorityId) throw new Error("Cancellation checkpoint authority mismatch.");
2722
- const h = { authorityId: t.authorityId, requestSequence: Math.max(a.requestSequence, m?.requestSequence ?? 0), cancelled: { ...m?.cancelled }, operations: { ...m?.operations }, stops: { ...m?.stops } };
2731
+ const f = { authorityId: t.authorityId, requestSequence: Math.max(a.requestSequence, m?.requestSequence ?? 0), cancelled: { ...m?.cancelled }, operations: { ...m?.operations }, stops: { ...m?.stops } };
2723
2732
  if (o) {
2724
- s = a, a.requestSequence >= (m?.requestSequence ?? 0) && (h.cancelled = {}, h.operations = {}, h.stops = {});
2725
- for (const [v] of l) delete h.cancelled[v];
2726
- for (const [v, I] of Object.entries(a.stops)) h.stops[v]?.requestId === I.requestId && delete h.stops[v];
2733
+ s = a, a.requestSequence >= (m?.requestSequence ?? 0) && (f.cancelled = {}, f.operations = {}, f.stops = {});
2734
+ for (const [v] of l) delete f.cancelled[v];
2735
+ for (const [v, I] of Object.entries(a.stops)) f.stops[v]?.requestId === I.requestId && delete f.stops[v];
2727
2736
  for (const [v, I] of c)
2728
- JSON.stringify(h.operations[v]?.command) === JSON.stringify(I.command) && delete h.operations[v];
2737
+ JSON.stringify(f.operations[v]?.command) === JSON.stringify(I.command) && delete f.operations[v];
2729
2738
  } else {
2730
- for (const [v, I] of l) s?.submissions[v]?.cancelled || (h.cancelled[v] = { ...I, context: {}, contextPreparation: { pageContent: "", sessionTabs: [] } });
2731
- for (const [v, I] of Object.entries(a.stops)) s?.stops[v]?.requestId !== I.requestId && (h.stops[v] = I);
2732
- for (const [v, I] of c) I.phase !== "done" && I.phase !== "failed" && JSON.stringify(s?.operations[v]?.command) !== JSON.stringify(I.command) && (h.operations[v] = { ...I, effectId: null, phase: "uncertain", result: null, error: null });
2739
+ for (const [v, I] of l) s?.submissions[v]?.cancelled || (f.cancelled[v] = { ...I, context: {}, contextPreparation: { pageContent: "", sessionTabs: [] } });
2740
+ for (const [v, I] of Object.entries(a.stops)) s?.stops[v]?.requestId !== I.requestId && (f.stops[v] = I);
2741
+ for (const [v, I] of c) I.phase !== "done" && I.phase !== "failed" && JSON.stringify(s?.operations[v]?.command) !== JSON.stringify(I.command) && (f.operations[v] = { ...I, effectId: null, phase: "uncertain", result: null, error: null });
2733
2742
  }
2734
- if (!(!m && !Object.keys(h.cancelled).length && !Object.keys(h.operations).length && !Object.keys(h.stops).length) && !(JSON.stringify(m?.cancelled ?? {}) === JSON.stringify(h.cancelled) && JSON.stringify(m?.operations ?? {}) === JSON.stringify(h.operations) && JSON.stringify(m?.stops ?? {}) === JSON.stringify(h.stops))) {
2743
+ if (!(!m && !Object.keys(f.cancelled).length && !Object.keys(f.operations).length && !Object.keys(f.stops).length) && !(JSON.stringify(m?.cancelled ?? {}) === JSON.stringify(f.cancelled) && JSON.stringify(m?.operations ?? {}) === JSON.stringify(f.operations) && JSON.stringify(m?.stops ?? {}) === JSON.stringify(f.stops))) {
2735
2744
  if (!t.isCurrent()) throw new Error("Cancellation authority was retired.");
2736
- await u.measure("cancellation_write", () => t.write(h)), n = Promise.resolve(h);
2745
+ await u.measure("cancellation_write", () => t.write(f)), n = Promise.resolve(f);
2737
2746
  }
2738
2747
  };
2739
2748
  return e = u.measure("cancellation_queue", () => p.then(() => {
@@ -2872,7 +2881,7 @@ frame `)) : void 0;
2872
2881
  ...n ? { stack: n } : {}
2873
2882
  };
2874
2883
  }
2875
- function ye(t) {
2884
+ function pe(t) {
2876
2885
  if (!t || typeof t != "object") return !1;
2877
2886
  const e = t, s = (n) => Number.isSafeInteger(n) && n >= 0;
2878
2887
  return Object.keys(e).every((n) => [
@@ -3057,7 +3066,7 @@ function Z(t, e) {
3057
3066
  throw Object.assign(new Error("Conversation authority was retired."), { code: "authority_retired", retryable: !0 });
3058
3067
  }
3059
3068
  function ke(t, e) {
3060
- const s = Y(t, "connection_interrupted", "web_transport"), { code: n, message: i } = s, r = t instanceof Error && "detail" in t ? t.detail : t instanceof Error && "details" in t ? t.details : void 0, a = r && typeof r == "object" && "httpRequest" in r ? r.httpRequest : r, o = a && typeof a == "object" ? a : {}, c = o.category ?? o.transportCode, l = o.elapsedMs ?? o.durationMs, d = r && typeof r == "object" && "successfulRequests" in r && typeof r.successfulRequests == "number" ? r.successfulRequests : 0, u = r && typeof r == "object" && "securitySettingsUrl" in r && typeof r.securitySettingsUrl == "string" ? r.securitySettingsUrl : void 0, p = r && typeof r == "object" && "httpRequest" in r && ye(r.httpRequest) ? r.httpRequest : void 0;
3069
+ const s = Y(t, "connection_interrupted", "web_transport"), { code: n, message: i } = s, r = t instanceof Error && "detail" in t ? t.detail : t instanceof Error && "details" in t ? t.details : void 0, a = r && typeof r == "object" && "httpRequest" in r ? r.httpRequest : r, o = a && typeof a == "object" ? a : {}, c = o.category ?? o.transportCode, l = o.elapsedMs ?? o.durationMs, d = r && typeof r == "object" && "successfulRequests" in r && typeof r.successfulRequests == "number" ? r.successfulRequests : 0, u = r && typeof r == "object" && "securitySettingsUrl" in r && typeof r.securitySettingsUrl == "string" ? r.securitySettingsUrl : void 0, p = r && typeof r == "object" && "httpRequest" in r && pe(r.httpRequest) ? r.httpRequest : void 0;
3061
3070
  return Object.assign(new Error(i), {
3062
3071
  code: n,
3063
3072
  // Keep the actionable public URL without copying arbitrary transport internals into durable errors.
@@ -3107,11 +3116,11 @@ function Mo(t) {
3107
3116
  }, p = () => {
3108
3117
  };
3109
3118
  d.measure("warmup_wait", () => new Promise((g, m) => {
3110
- const h = () => {
3119
+ const f = () => {
3111
3120
  const v = c.engine.getState().slices, I = v.conversation.submissions[o.submission.userMessageId], _ = v.conversation.operations[l.command.request_id];
3112
3121
  !Q(t) || !I || I.cancelled || v.directory.clients[I.clientScopeId] !== I.conversationScopeId ? m(new Error("Warmup wait was retired.")) : (I.sessionId !== null || !_ || !["waiting", "running", "uncertain"].includes(_.phase)) && g();
3113
3122
  };
3114
- u = c.engine.subscribe(h), p = c.onDispose(() => m(new Error("Warmup wait was retired."))), h();
3123
+ u = c.engine.subscribe(f), p = c.onDispose(() => m(new Error("Warmup wait was retired."))), f();
3115
3124
  })).catch(() => {
3116
3125
  }).finally(() => {
3117
3126
  u(), p();
@@ -3218,8 +3227,8 @@ function Mo(t) {
3218
3227
  }).measure("attachment_upload", () => Promise.resolve().then(async () => {
3219
3228
  const l = () => {
3220
3229
  if (Z(t, o), !o.preparationId) return r(o.submission.userMessageId);
3221
- const h = t.runtime().engine.getState().slices.directory;
3222
- if (!Object.values(h.clients).includes(o.submission.conversationScopeId))
3230
+ const f = t.runtime().engine.getState().slices.directory;
3231
+ if (!Object.values(f.clients).includes(o.submission.conversationScopeId))
3223
3232
  throw Object.assign(new Error("Attachment preparation was cancelled."), { code: "submission_cancelled", retryable: !1 });
3224
3233
  };
3225
3234
  l(), await s(), l();
@@ -3244,8 +3253,8 @@ function Mo(t) {
3244
3253
  if (l(), !p.sessionId || o.submission.sessionId && p.sessionId !== o.submission.sessionId || p.attachment.id !== o.source.sourceId || p.attachment.mimeType !== o.source.mimeType || p.attachment.sizeBytes !== o.source.sizeBytes)
3245
3254
  throw Object.assign(new Error("Attachment preparation identity mismatch."), { code: "attachment_identity_mismatch", retryable: !1 });
3246
3255
  if ("uploadUrl" in p) {
3247
- const h = await fetch(t.http.resolveUrl(p.uploadUrl), { method: p.uploadMethod, headers: p.uploadHeaders, body: d });
3248
- if (!h.ok) throw Object.assign(new Error("Attachment transfer failed."), { code: String(h.status) });
3256
+ const f = await fetch(t.http.resolveUrl(p.uploadUrl), { method: p.uploadMethod, headers: p.uploadHeaders, body: d });
3257
+ if (!f.ok) throw Object.assign(new Error("Attachment transfer failed."), { code: String(f.status) });
3249
3258
  }
3250
3259
  l();
3251
3260
  const g = p.attachment, m = {
@@ -3291,8 +3300,8 @@ function Mo(t) {
3291
3300
  } }
3292
3301
  ).catch((S) => {
3293
3302
  if (g.length === 0) throw S;
3294
- const f = ke(S);
3295
- throw Object.assign(f, { details: { ...f.details, successfulRequests: g.length } });
3303
+ const h = ke(S);
3304
+ throw Object.assign(h, { details: { ...h.details, successfulRequests: g.length } });
3296
3305
  });
3297
3306
  if (Z(t, o), _.conversation_id !== o.sessionId) throw new Error("Snapshot conversation identity mismatch.");
3298
3307
  if (g.push(_), !_.projection_ready) break;
@@ -3300,10 +3309,10 @@ function Mo(t) {
3300
3309
  const m = g[0];
3301
3310
  if (o.before !== null && m.next_cursor === o.before)
3302
3311
  throw Object.assign(new Error("Conversation history cursor did not advance."), { code: "invalid_history_cursor" });
3303
- const h = g.reduce((I, _) => _.execution.version > I.version ? _.execution : I, m.execution), v = g.reduce((I, _) => _.follow_ups_version > I.follow_ups_version ? _ : I, m);
3312
+ const f = g.reduce((I, _) => _.execution.version > I.version ? _.execution : I, m.execution), v = g.reduce((I, _) => _.follow_ups_version > I.follow_ups_version ? _ : I, m);
3304
3313
  return { snapshot: {
3305
3314
  ...m,
3306
- execution: h,
3315
+ execution: f,
3307
3316
  items: g.flatMap((I) => I.items),
3308
3317
  streams: g.flatMap((I) => I.streams),
3309
3318
  removed_items: g.flatMap((I) => I.removed_items),
@@ -3560,7 +3569,7 @@ function as(t, e, s, n) {
3560
3569
  createdAt: "",
3561
3570
  loading: !1
3562
3571
  });
3563
- const c = t.activity.phase, l = t.submissions.filter((y) => !y.cancelled && !["accepted", "failed"].includes(y.delivery)), d = t.submissions[t.submissions.length - 1], u = [...t.items].reverse().find((y) => y.type === "user_message"), p = ["queued", "thinking", "steering", "awaiting_execution"].includes(c), g = d?.delivery === "failed" && (p && t.activity.userMessageId != null && t.activity.userMessageId !== d.userMessageId || u !== void 0 && u.id !== d.userMessageId && Date.parse(u.created_at) > d.submittedAt), m = new Map(t.submissions.filter((y) => (y !== d || g) && !y.cancelled && y.delivery === "failed" && y.error).map((y) => [y.userMessageId, y])), h = a.flatMap((y) => {
3572
+ const c = t.activity.phase, l = t.submissions.filter((y) => !y.cancelled && !["accepted", "failed"].includes(y.delivery)), d = t.submissions[t.submissions.length - 1], u = [...t.items].reverse().find((y) => y.type === "user_message"), p = ["queued", "thinking", "steering", "awaiting_execution"].includes(c), g = d?.delivery === "failed" && (p && t.activity.userMessageId != null && t.activity.userMessageId !== d.userMessageId || u !== void 0 && u.id !== d.userMessageId && Date.parse(u.created_at) > d.submittedAt), m = new Map(t.submissions.filter((y) => (y !== d || g) && !y.cancelled && y.delivery === "failed" && y.error).map((y) => [y.userMessageId, y])), f = a.flatMap((y) => {
3564
3573
  const w = y.role === "user" ? m.get(y.id) : void 0;
3565
3574
  return w?.error ? [y, {
3566
3575
  id: `submission-error:${w.userMessageId}`,
@@ -3581,7 +3590,7 @@ function as(t, e, s, n) {
3581
3590
  ...typeof _?.details?.requestId == "string" ? { errorRequestId: _.details.requestId } : {},
3582
3591
  ...nt(_?.details?.errorNormalization) ? { errorNormalization: _.details.errorNormalization } : {},
3583
3592
  ...n ? { owner: n } : {},
3584
- ...ye(_?.details?.httpRequest) ? { httpRequest: _.details.httpRequest } : {},
3593
+ ...pe(_?.details?.httpRequest) ? { httpRequest: _.details.httpRequest } : {},
3585
3594
  queryStatus: e?.status ?? null,
3586
3595
  queryRequestId: e?.requestId ?? null,
3587
3596
  queryUpdatedAt: e?.updatedAt ?? null
@@ -3590,7 +3599,7 @@ function as(t, e, s, n) {
3590
3599
  selectionKey: t.selectionKey,
3591
3600
  isDraftSession: t.isDraftSession,
3592
3601
  sessionId: t.sessionId,
3593
- messages: h,
3602
+ messages: f,
3594
3603
  removedItems: o,
3595
3604
  activeResponseUserMessageId: t.activity.userMessageId ?? t.segments[t.segments.length - 1]?.userMessageId ?? d?.userMessageId ?? null,
3596
3605
  segments: t.segments,
@@ -3613,14 +3622,14 @@ function as(t, e, s, n) {
3613
3622
  lastErrorCode: _?.code ?? null,
3614
3623
  lastErrorSecuritySettingsUrl: typeof _?.details?.securitySettingsUrl == "string" ? _.details.securitySettingsUrl : null
3615
3624
  };
3616
- let f = S;
3625
+ let h = S;
3617
3626
  for (const y of t.optimistic.filter((w) => w.cancelled && !t.stop?.userMessageIds.includes(w.userMessageId))) {
3618
- const w = Gs(f, "", "stopped", [y.userMessageId], Gn(y.cancellationReason));
3619
- f = { ...f, messages: w.messages, segments: w.segments };
3627
+ const w = Gs(h, "", "stopped", [y.userMessageId], Gn(y.cancellationReason));
3628
+ h = { ...h, messages: w.messages, segments: w.segments };
3620
3629
  }
3621
- if (!t.stop) return f;
3630
+ if (!t.stop) return h;
3622
3631
  const b = Gs(
3623
- f,
3632
+ h,
3624
3633
  "",
3625
3634
  t.stop.pending ? "stopping" : "stopped",
3626
3635
  t.stop.userMessageIds,
@@ -3797,19 +3806,19 @@ const Fo = "Pluno is reconnecting. Try again in a moment.";
3797
3806
  function $o(t) {
3798
3807
  return (t instanceof Error ? t.message : t) === Fo;
3799
3808
  }
3800
- const pe = /* @__PURE__ */ Object.create(null);
3801
- pe.open = "0";
3802
- pe.close = "1";
3803
- pe.ping = "2";
3804
- pe.pong = "3";
3805
- pe.message = "4";
3806
- pe.upgrade = "5";
3807
- pe.noop = "6";
3809
+ const he = /* @__PURE__ */ Object.create(null);
3810
+ he.open = "0";
3811
+ he.close = "1";
3812
+ he.ping = "2";
3813
+ he.pong = "3";
3814
+ he.message = "4";
3815
+ he.upgrade = "5";
3816
+ he.noop = "6";
3808
3817
  const St = /* @__PURE__ */ Object.create(null);
3809
- Object.keys(pe).forEach((t) => {
3810
- St[pe[t]] = t;
3818
+ Object.keys(he).forEach((t) => {
3819
+ St[he[t]] = t;
3811
3820
  });
3812
- const Js = { type: "error", data: "parser error" }, Wi = typeof Blob == "function" || typeof Blob < "u" && Object.prototype.toString.call(Blob) === "[object BlobConstructor]", Gi = typeof ArrayBuffer == "function", Ji = (t) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(t) : t && t.buffer instanceof ArrayBuffer, gn = ({ type: t, data: e }, s, n) => Wi && e instanceof Blob ? s ? n(e) : Qn(e, n) : Gi && (e instanceof ArrayBuffer || Ji(e)) ? s ? n(e) : Qn(new Blob([e]), n) : n(pe[t] + (e || "")), Qn = (t, e) => {
3821
+ const Js = { type: "error", data: "parser error" }, Wi = typeof Blob == "function" || typeof Blob < "u" && Object.prototype.toString.call(Blob) === "[object BlobConstructor]", Gi = typeof ArrayBuffer == "function", Ji = (t) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(t) : t && t.buffer instanceof ArrayBuffer, gn = ({ type: t, data: e }, s, n) => Wi && e instanceof Blob ? s ? n(e) : Qn(e, n) : Gi && (e instanceof ArrayBuffer || Ji(e)) ? s ? n(e) : Qn(new Blob([e]), n) : n(he[t] + (e || "")), Qn = (t, e) => {
3813
3822
  const s = new FileReader();
3814
3823
  return s.onload = function() {
3815
3824
  const n = s.result.split(",")[1];
@@ -5215,7 +5224,7 @@ const Pa = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
5215
5224
  return M;
5216
5225
  }
5217
5226
  }, Symbol.toStringTag, { value: "Module" }));
5218
- function ae(t, e, s) {
5227
+ function ce(t, e, s) {
5219
5228
  return t.on(e, s), function() {
5220
5229
  t.off(e, s);
5221
5230
  };
@@ -5263,10 +5272,10 @@ class rr extends F {
5263
5272
  return;
5264
5273
  const e = this.io;
5265
5274
  this.subs = [
5266
- ae(e, "open", this.onopen.bind(this)),
5267
- ae(e, "packet", this.onpacket.bind(this)),
5268
- ae(e, "error", this.onerror.bind(this)),
5269
- ae(e, "close", this.onclose.bind(this))
5275
+ ce(e, "open", this.onopen.bind(this)),
5276
+ ce(e, "packet", this.onpacket.bind(this)),
5277
+ ce(e, "error", this.onerror.bind(this)),
5278
+ ce(e, "close", this.onclose.bind(this))
5270
5279
  ];
5271
5280
  }
5272
5281
  /**
@@ -5898,11 +5907,11 @@ class Zs extends F {
5898
5907
  this.engine = new _a(this.uri, this.opts);
5899
5908
  const s = this.engine, n = this;
5900
5909
  this._readyState = "opening", this.skipReconnect = !1;
5901
- const i = ae(s, "open", function() {
5910
+ const i = ce(s, "open", function() {
5902
5911
  n.onopen(), e && e();
5903
5912
  }), r = (o) => {
5904
5913
  this.cleanup(), this._readyState = "closed", this.emitReserved("error", o), e ? e(o) : this.maybeReconnectOnOpen();
5905
- }, a = ae(s, "error", r);
5914
+ }, a = ce(s, "error", r);
5906
5915
  if (this._timeout !== !1) {
5907
5916
  const o = this._timeout, c = this.setTimeoutFn(() => {
5908
5917
  i(), r(new Error("timeout")), s.close();
@@ -5931,12 +5940,12 @@ class Zs extends F {
5931
5940
  this.cleanup(), this._readyState = "open", this.emitReserved("open");
5932
5941
  const e = this.engine;
5933
5942
  this.subs.push(
5934
- ae(e, "ping", this.onping.bind(this)),
5935
- ae(e, "data", this.ondata.bind(this)),
5936
- ae(e, "error", this.onerror.bind(this)),
5937
- ae(e, "close", this.onclose.bind(this)),
5943
+ ce(e, "ping", this.onping.bind(this)),
5944
+ ce(e, "data", this.ondata.bind(this)),
5945
+ ce(e, "error", this.onerror.bind(this)),
5946
+ ce(e, "close", this.onclose.bind(this)),
5938
5947
  // @ts-ignore
5939
- ae(this.decoder, "decoded", this.ondecoded.bind(this))
5948
+ ce(this.decoder, "decoded", this.ondecoded.bind(this))
5940
5949
  );
5941
5950
  }
5942
5951
  /**
@@ -6471,21 +6480,21 @@ class or {
6471
6480
  const g = this.auth.token;
6472
6481
  let m = null;
6473
6482
  try {
6474
- let h = n;
6483
+ let f = n;
6475
6484
  if (r === "conversations" && e === "/commands" && this.auth.role !== "session_surface" && this.options.executorConnection) {
6476
6485
  if (m = this.options.executorConnection(), !m) throw new A("Reconnecting the browser before continuing.", "executor_not_ready");
6477
6486
  const _ = n;
6478
- h = { ..._, context: { ..._.context, connection_id: m } };
6487
+ f = { ..._, context: { ..._.context, connection_id: m } };
6479
6488
  }
6480
- const v = () => this.requestOnce(e, s, h, i, r, a.signal, a.diagnostic, ++d), I = await (a.timing ? a.timing.measure("http_request", v) : v());
6489
+ const v = () => this.requestOnce(e, s, f, i, r, a.signal, a.diagnostic, ++d), I = await (a.timing ? a.timing.measure("http_request", v) : v());
6481
6490
  return c(), I;
6482
- } catch (h) {
6483
- if (c(!1), this.requests.signal.aborted || a.signal?.aborted) throw h;
6484
- if (h instanceof A && h.code === "executor_not_ready" && m && u === 0 && this.options.restoreExecutor) {
6491
+ } catch (f) {
6492
+ if (c(!1), this.requests.signal.aborted || a.signal?.aborted) throw f;
6493
+ if (f instanceof A && f.code === "executor_not_ready" && m && u === 0 && this.options.restoreExecutor) {
6485
6494
  await this.options.restoreExecutor(m), u++, c();
6486
6495
  continue;
6487
6496
  }
6488
- if (!(h instanceof A) || !["unauthorized", "403"].includes(h.code) || !this.options.recoverAuthentication || !l || (await this.options.recoverAuthentication(g, h, l && u === 0), c(), !l || u !== 0)) throw h;
6497
+ if (!(f instanceof A) || !["unauthorized", "403"].includes(f.code) || !this.options.recoverAuthentication || !l || (await this.options.recoverAuthentication(g, f, l && u === 0), c(), !l || u !== 0)) throw f;
6489
6498
  u++;
6490
6499
  }
6491
6500
  }
@@ -6497,16 +6506,16 @@ class or {
6497
6506
  this.requests.signal.throwIfAborted(), a?.throwIfAborted();
6498
6507
  const p = new AbortController(), g = { trigger: null }, m = (E) => {
6499
6508
  p.signal.aborted || (g.trigger = E, p.abort());
6500
- }, h = () => m("transport_disposed"), v = () => m(["owner_disposed", "authority_retired", "observation_released", "request_replaced"].includes(a?.reason) ? a.reason : "caller_cancelled");
6501
- this.requests.signal.addEventListener("abort", h, { once: !0 }), a?.addEventListener("abort", v, { once: !0 });
6502
- const I = r === "conversations" && /^\/[^/]+\/snapshot$/.test(e) && i === "POST", _ = /^\/conversations(?:\/[^/]+)?$/.test(e) && (i ?? (n === void 0 ? "GET" : "POST")) === "GET", S = setTimeout(() => m("deadline"), _ ? 6e4 : I ? 3e4 : 15e3), f = Ba(), b = Date.now();
6509
+ }, f = () => m("transport_disposed"), v = () => m(["owner_disposed", "authority_retired", "observation_released", "request_replaced"].includes(a?.reason) ? a.reason : "caller_cancelled");
6510
+ this.requests.signal.addEventListener("abort", f, { once: !0 }), a?.addEventListener("abort", v, { once: !0 });
6511
+ const I = r === "conversations" && /^\/[^/]+\/snapshot$/.test(e) && i === "POST", _ = /^\/conversations(?:\/[^/]+)?$/.test(e) && (i ?? (n === void 0 ? "GET" : "POST")) === "GET", S = setTimeout(() => m("deadline"), _ ? 6e4 : I ? 3e4 : 15e3), h = Ba(), b = Date.now();
6503
6512
  let y = null, w = !1, R = null, T = null, C = null;
6504
6513
  try {
6505
6514
  const E = await Promise.resolve(fetch(d, {
6506
6515
  method: i ?? (n === void 0 ? "GET" : "POST"),
6507
6516
  cache: "no-store",
6508
6517
  signal: p.signal,
6509
- headers: { "x-product-agent-auth-request-id": f, authorization: l || r === "conversations" ? `Bearer ${this.auth.token}` : this.auth.token, "content-type": "application/json", ...I ? { "x-request-id": f } : {} },
6518
+ headers: { "x-product-agent-auth-request-id": h, authorization: l || r === "conversations" ? `Bearer ${this.auth.token}` : this.auth.token, "content-type": "application/json", ...I ? { "x-request-id": h } : {} },
6510
6519
  ...n === void 0 ? {} : { body: JSON.stringify(n) }
6511
6520
  })).catch((q) => {
6512
6521
  throw w = !0, q;
@@ -6526,13 +6535,13 @@ class or {
6526
6535
  ...typeof O.blockedOrigin == "string" ? { blockedOrigin: O.blockedOrigin } : {},
6527
6536
  ...typeof O.securitySettingsUrl == "string" ? { securitySettingsUrl: O.securitySettingsUrl } : {}
6528
6537
  }, r === "conversations" && e === "/commands");
6529
- const k = O === "Token expired" ? "token_expired" : O === "Invalid token" ? "invalid_token" : O?.reason, x = E.status === 401 && ["missing_token", "token_expired", "invalid_token", "user_not_found"].includes(k) ? { requestId: f, authTransport: "http", authEndpoint: `${r ?? (l ? "embed" : "runtime")}:${["snapshot", "me", "bootstrap", "commands", "activity", "session-history"].includes(e.split("/").pop()) ? e.split("/").pop() : "other"}`, reason: k, retryable: k === "token_expired" && (O === "Token expired" || O.retryable === !0) } : void 0;
6538
+ const k = O === "Token expired" ? "token_expired" : O === "Invalid token" ? "invalid_token" : O?.reason, x = E.status === 401 && ["missing_token", "token_expired", "invalid_token", "user_not_found"].includes(k) ? { requestId: h, authTransport: "http", authEndpoint: `${r ?? (l ? "embed" : "runtime")}:${["snapshot", "me", "bootstrap", "commands", "activity", "session-history"].includes(e.split("/").pop()) ? e.split("/").pop() : "other"}`, reason: k, retryable: k === "token_expired" && (O === "Token expired" || O.retryable === !0) } : void 0;
6530
6539
  throw new A(E.status === 401 ? "Your session expired or is invalid. Reconnect to continue." : E.status === 403 ? "You don't have access to this conversation. Check your access and reconnect." : `Product Agent request failed (${E.status})`, q, !1, x);
6531
6540
  }
6532
6541
  return await E.json();
6533
6542
  } catch (E) {
6534
6543
  const q = g.trigger ?? ((E instanceof Error || E instanceof DOMException) && E.name === "AbortError" ? "unexpected_abort" : null), O = {
6535
- requestId: f,
6544
+ requestId: h,
6536
6545
  method: i ?? (n === void 0 ? "GET" : "POST"),
6537
6546
  route: I ? "/api/product-agent/conversations/:sessionId/snapshot" : e === "/commands" ? "/api/product-agent/:namespace/commands" : "/api/product-agent/:namespace/:operation",
6538
6547
  status: R,
@@ -6551,9 +6560,9 @@ class or {
6551
6560
  upstreamRequestId: T,
6552
6561
  upstreamTraceId: C
6553
6562
  };
6554
- ye(O) && Promise.resolve().then(() => this.options.onRequestFailure ? this.options.onRequestFailure(O) : console.warn("Product Agent HTTP request failed", O)).catch(() => {
6563
+ pe(O) && Promise.resolve().then(() => this.options.onRequestFailure ? this.options.onRequestFailure(O) : console.warn("Product Agent HTTP request failed", O)).catch(() => {
6555
6564
  });
6556
- const k = ye(O) ? { httpRequest: O } : void 0;
6565
+ const k = pe(O) ? { httpRequest: O } : void 0;
6557
6566
  if (q !== null) {
6558
6567
  const x = q !== "deadline" && q !== "unexpected_abort";
6559
6568
  throw new A(
@@ -6570,7 +6579,7 @@ class or {
6570
6579
  k
6571
6580
  ) : E;
6572
6581
  } finally {
6573
- clearTimeout(S), this.requests.signal.removeEventListener("abort", h), a?.removeEventListener("abort", v);
6582
+ clearTimeout(S), this.requests.signal.removeEventListener("abort", f), a?.removeEventListener("abort", v);
6574
6583
  }
6575
6584
  }
6576
6585
  }
@@ -7072,7 +7081,6 @@ class L extends EventTarget {
7072
7081
  hydration = null;
7073
7082
  hydrations = Promise.resolve();
7074
7083
  bootstrapRequests = new AbortController();
7075
- suggestionTimer = null;
7076
7084
  diagnostics = [];
7077
7085
  diagnosticTimer = null;
7078
7086
  diagnosticFlush = !1;
@@ -7101,7 +7109,7 @@ class L extends EventTarget {
7101
7109
  }, 12e4));
7102
7110
  }
7103
7111
  resetBootstrap() {
7104
- this.bootstrapRequests.abort(), this.bootstrapRequests = new AbortController(), this.suggestionTimer !== null && clearTimeout(this.suggestionTimer), this.suggestionTimer = null;
7112
+ this.bootstrapRequests.abort(), this.bootstrapRequests = new AbortController();
7105
7113
  for (const [e, s] of this.contextRevisions) this.contextRevisions.set(e, s + 1);
7106
7114
  }
7107
7115
  queueDiagnostic(e, s = {}) {
@@ -7181,15 +7189,15 @@ class L extends EventTarget {
7181
7189
  return;
7182
7190
  }
7183
7191
  if (s.type === "auth.session") {
7184
- const o = a instanceof A ? a : new A("Chat setup failed", "request_failed");
7192
+ const o = a instanceof A ? a : new A("Chat setup failed", "request_failed"), c = this.isInvalidResponse(o);
7185
7193
  this.queueDiagnostic("auth_rejected", {
7186
7194
  stage: "bootstrap",
7187
7195
  failureKind: "permanent",
7188
7196
  httpStatus: /^[45][0-9]{2}$/.test(o.code) ? Number(o.code) : void 0
7189
7197
  }), this.fail(new A(
7190
7198
  o.message,
7191
- o.code,
7192
- o.outcomeUnknown,
7199
+ c ? "invalid_response" : o.code,
7200
+ c ? !1 : o.outcomeUnknown,
7193
7201
  { ...o.detail && typeof o.detail == "object" ? o.detail : {}, stage: "bootstrap" },
7194
7202
  o.backendRefusal
7195
7203
  ), s), this.pause();
@@ -7252,25 +7260,12 @@ class L extends EventTarget {
7252
7260
  http(e, s = {}, n, i) {
7253
7261
  return this.httpTransport.request(e, s, n, i);
7254
7262
  }
7255
- isRetryableRead(e) {
7256
- return e instanceof TypeError || e instanceof DOMException && e.name === "AbortError" || e instanceof A && ["request_timed_out", "408", "425", "429", "500", "502", "503", "504"].includes(e.code);
7263
+ isInvalidResponse(e) {
7264
+ const s = e instanceof A ? e.detail : void 0;
7265
+ return !!(s && typeof s == "object" && "httpRequest" in s && pe(s.httpRequest) && s.httpRequest.category === "invalid_response");
7257
7266
  }
7258
- async loadUserSuggestions(e, s = 0) {
7259
- const n = this.promptRevision, i = this.options.pageUrl();
7260
- this.receive({ type: "starterPrompts.updated", starterPromptsLoading: !0 });
7261
- try {
7262
- const r = await this.httpTransport.request("/user-suggested-tasks", {}, void 0, void 0, void 0, { signal: e });
7263
- !e.aborted && n === this.promptRevision && i === this.options.pageUrl() && this.receive({ ...r, type: "starterPrompts.updated" });
7264
- } catch (r) {
7265
- if (e.aborted) return;
7266
- if (!this.isRetryableRead(r)) {
7267
- n === this.promptRevision && i === this.options.pageUrl() && this.receive({ type: "starterPrompts.updated", starterPromptsLoading: !1 }), r instanceof A && ["unauthorized", "update_required"].includes(r.code) ? this.fail(r) : console.error("Product Agent optional suggestions could not be loaded", r);
7268
- return;
7269
- }
7270
- this.suggestionTimer = setTimeout(() => {
7271
- this.suggestionTimer = null, this.loadUserSuggestions(e, s + 1);
7272
- }, Math.min(3e4, 1e3 * 2 ** Math.min(s, 5)));
7273
- }
7267
+ isRetryableRead(e) {
7268
+ return this.isInvalidResponse(e) ? !1 : e instanceof TypeError || e instanceof DOMException && e.name === "AbortError" || e instanceof A && ["connection_interrupted", "request_timed_out", "408", "425", "429", "500", "502", "503", "504"].includes(e.code);
7274
7269
  }
7275
7270
  async dispatch(e, s) {
7276
7271
  const { type: n, ...i } = e, r = this.options.auth.client_kind === "embed", a = e.pageUrl ?? e.page?.url ?? this.options.pageUrl(), o = { page_url: a, origin: new URL(a).origin };
@@ -7288,7 +7283,7 @@ class L extends EventTarget {
7288
7283
  if (p.aborted || !this.isCurrent(s) || (this.credentialBootstrap = null, !this.options.auth.community_id && g.user?.runtimeCommunityId && (this.options.auth.community_id = g.user.runtimeCommunityId), this.receive({ type: "auth.ok", ...g }), p.aborted)) return;
7289
7284
  this.options.auth.client_kind === "extension" && this.receive({ type: "executor.registered", userId: g.user.id }), this.bootstrapped = !0;
7290
7285
  for (const m of this.beforeBootstrap.splice(0)) this.receive(m);
7291
- this.synchronizeReferences(), this.options.auth.client_kind === "web" && this.loadUserSuggestions(p);
7286
+ this.synchronizeReferences();
7292
7287
  return;
7293
7288
  }
7294
7289
  if (n === "runtime.auth_ack") {
@@ -7426,7 +7421,7 @@ function Qa(t, e, s, n, i, r, a, o, c = null, l = !1) {
7426
7421
  }
7427
7422
  const Xa = 1e4, Ya = 3e3;
7428
7423
  function lr() {
7429
- return { authenticated: !1, generation: 0, sequence: 0, displaySequence: 0, backendCount: null, query: me("activeUsers") };
7424
+ return { authenticated: !1, generation: 0, sequence: 0, displaySequence: 0, backendCount: null, query: ye("activeUsers") };
7430
7425
  }
7431
7426
  function Za(t, e) {
7432
7427
  if (e.type === "activeUsers.authenticate") {
@@ -7664,16 +7659,16 @@ function qe(t, e, s) {
7664
7659
  if (e.type === "effect.failed")
7665
7660
  n = { ...n, queries: { ...n.queries, [o]: { ...c, status: "error", error: { ...e.error }, requestId: null, consecutiveFailures: c.consecutiveFailures + 1 } } };
7666
7661
  else if (e.effectKind === "directory.query") {
7667
- for (const h of e.output.entries) n = ps(n, h, !0);
7668
- const l = e.output.entries.map((h) => h.conversation_id), d = { ...n.durableActivityBySessionId }, u = { ...n.activityBySessionId }, p = { ...n.activityRevisionBySessionId };
7669
- for (const h of e.output.entries) {
7670
- if (typeof h.is_active != "boolean") continue;
7671
- d[h.conversation_id] = h.is_active;
7672
- const v = c.startedAtActivityRevisionBySessionId[h.conversation_id];
7673
- v !== void 0 && p[h.conversation_id] === v && (delete u[h.conversation_id], delete p[h.conversation_id]);
7662
+ for (const f of e.output.entries) n = ps(n, f, !0);
7663
+ const l = e.output.entries.map((f) => f.conversation_id), d = { ...n.durableActivityBySessionId }, u = { ...n.activityBySessionId }, p = { ...n.activityRevisionBySessionId };
7664
+ for (const f of e.output.entries) {
7665
+ if (typeof f.is_active != "boolean") continue;
7666
+ d[f.conversation_id] = f.is_active;
7667
+ const v = c.startedAtActivityRevisionBySessionId[f.conversation_id];
7668
+ v !== void 0 && p[f.conversation_id] === v && (delete u[f.conversation_id], delete p[f.conversation_id]);
7674
7669
  }
7675
7670
  n = { ...n, durableActivityBySessionId: d, activityBySessionId: u, activityRevisionBySessionId: p };
7676
- const g = Object.fromEntries(Object.entries(n.optimisticEntries).filter(([, h]) => h.sessionId === null || !l.includes(h.sessionId)));
7671
+ const g = Object.fromEntries(Object.entries(n.optimisticEntries).filter(([, f]) => f.sessionId === null || !l.includes(f.sessionId)));
7677
7672
  n = { ...n, optimisticEntries: g };
7678
7673
  const m = [.../* @__PURE__ */ new Set([...c.mode === "append" ? c.data ?? [] : [], ...l])];
7679
7674
  n = { ...n, queries: { ...n.queries, [o]: {
@@ -7755,7 +7750,7 @@ function qe(t, e, s) {
7755
7750
  query: d,
7756
7751
  cursor: e.cursor !== void 0 ? e.cursor : e.mode === "append" ? l?.cursor ?? null : null
7757
7752
  } }, n = { ...t, queries: { ...t.queries, [c]: {
7758
- ...De(l ?? me(c), { key: c, requestId: e.requestId, mode: e.mode }),
7753
+ ...De(l ?? ye(c), { key: c, requestId: e.requestId, mode: e.mode }),
7759
7754
  query: d,
7760
7755
  requestSequence: t.requestSequence + 1,
7761
7756
  mode: e.mode,
@@ -8119,14 +8114,14 @@ class pc {
8119
8114
  let d = r.slices.directory;
8120
8115
  for (const [_, S] of Object.entries(l.state.operations)) {
8121
8116
  if (!["runtime.warmup", "attachment.prepare"].includes(S.command.type) || !S.conversationScopeId || S.phase !== "done" || r.slices.conversation.operations[_]?.phase === "done") continue;
8122
- const f = S.result, b = d.selections[S.conversationScopeId];
8123
- f?.sessionId && b?.provisionalId && b.sessionId === null && Object.values(d.clients).includes(S.conversationScopeId) && (d = qe(d, {
8117
+ const h = S.result, b = d.selections[S.conversationScopeId];
8118
+ h?.sessionId && b?.provisionalId && b.sessionId === null && Object.values(d.clients).includes(S.conversationScopeId) && (d = qe(d, {
8124
8119
  authorityId: l.state.authorityId,
8125
8120
  generation: l.state.generation,
8126
8121
  type: "directory.accepted",
8127
8122
  conversationScopeId: S.conversationScopeId,
8128
8123
  provisionalId: b.provisionalId,
8129
- sessionId: f.sessionId
8124
+ sessionId: h.sessionId
8130
8125
  }).state);
8131
8126
  }
8132
8127
  const u = Object.values(l.state.submissions).find((_) => _.delivery === "accepted" && r.slices.conversation.submissions[_.userMessageId]?.delivery !== "accepted");
@@ -8144,15 +8139,15 @@ class pc {
8144
8139
  d = pi(r.slices.conversation, l.state, d);
8145
8140
  const p = Ws(Hs(l.state, d)), g = Vs(l.state, p.state, d);
8146
8141
  let m = r.slices;
8147
- const h = [], v = l.interactionSources, I = m.account.authority;
8142
+ const f = [], v = l.interactionSources, I = m.account.authority;
8148
8143
  if (v && I && I.authorityId === v.authorityId && I.generation === v.generation) {
8149
8144
  const _ = js(m, { type: "stage7.sources", authority: I, now: m.features.now, sources: v.sources }, { conversation: g.state, directory: d });
8150
- m = G(X({ account: _.state.account, features: _.state.features, interactions: _.state.interactions })), h.push(..._.effects);
8145
+ m = G(X({ account: _.state.account, features: _.state.features, interactions: _.state.interactions })), f.push(..._.effects);
8151
8146
  }
8152
8147
  return { state: g.state === r.slices.conversation && d === r.slices.directory && m === r.slices ? r : Object.freeze({
8153
8148
  revision: r.revision + 1,
8154
8149
  slices: Object.freeze({ ...r.slices, account: m.account, features: m.features, interactions: m.interactions, directory: d, conversation: g.state })
8155
- }), effects: [...l.effects, ...h, ...g.effects, ...p.effects] };
8150
+ }), effects: [...l.effects, ...f, ...g.effects, ...p.effects] };
8156
8151
  }
8157
8152
  const c = tc(r.slices.modelSelection, o);
8158
8153
  return { state: c === r.slices.modelSelection ? r : Object.freeze({
@@ -8207,7 +8202,7 @@ class pc {
8207
8202
  },
8208
8203
  errorAdapter: (r) => {
8209
8204
  const a = Y(r), o = r !== null && typeof r == "object" ? "details" in r ? r.details : "detail" in r ? r.detail : void 0 : void 0, c = o && typeof o == "object" && "httpRequest" in o ? o.httpRequest : void 0;
8210
- return { ...a, ...ye(c) ? { details: { ...a.details, httpRequest: c } } : {} };
8205
+ return { ...a, ...pe(c) ? { details: { ...a.details, httpRequest: c } } : {} };
8211
8206
  }
8212
8207
  });
8213
8208
  }
@@ -9018,7 +9013,7 @@ function nu(t) {
9018
9013
  case "runtime.report_operation_timing":
9019
9014
  return it(e.timing);
9020
9015
  case "runtime.report_displayed_error":
9021
- return (e.errorDiagnostic === void 0 || Ro(e.errorDiagnostic)) && (e.httpRequest === void 0 || ye(e.httpRequest)) && (e.historyRefreshFailure === void 0 || un(e.historyRefreshFailure)) && (e.renderedError === void 0 || hn(e.renderedError)) && (e.reason === "conversation_error" || e.reason === "attachment_error" || e.reason === "history_error" || e.reason === "action_error") && typeof e.errorFingerprint == "string" && /^fnv1a-[0-9a-f]{8}$/.test(e.errorFingerprint) && (e.displayedMessage === void 0 || typeof e.displayedMessage == "string" && e.displayedMessage.length <= 500);
9016
+ return (e.errorDiagnostic === void 0 || Ro(e.errorDiagnostic)) && (e.httpRequest === void 0 || pe(e.httpRequest)) && (e.historyRefreshFailure === void 0 || un(e.historyRefreshFailure)) && (e.renderedError === void 0 || hn(e.renderedError)) && (e.reason === "conversation_error" || e.reason === "attachment_error" || e.reason === "history_error" || e.reason === "action_error") && typeof e.errorFingerprint == "string" && /^fnv1a-[0-9a-f]{8}$/.test(e.errorFingerprint) && (e.displayedMessage === void 0 || typeof e.displayedMessage == "string" && e.displayedMessage.length <= 500);
9022
9017
  case "runtime.report_invalid_state_transition":
9023
9018
  return (e.uiInvariant === void 0 || fn(e.uiInvariant)) && (e.reason === "submitted_turn_returned_to_welcome_without_new_chat" || e.reason === "new_messages_button_without_user_scroll" || Vc(e.reason)) && (e.clientMessageId === void 0 || typeof e.clientMessageId == "string");
9024
9019
  case "runtime.prompt_presented":
@@ -9170,7 +9165,7 @@ class iu {
9170
9165
  errorFingerprint: s,
9171
9166
  ...i ? { renderedError: i } : {},
9172
9167
  ...r ? { historyRefreshFailure: r } : {},
9173
- ...ye(a) ? { httpRequest: a } : {},
9168
+ ...pe(a) ? { httpRequest: a } : {},
9174
9169
  ...n ? { displayedMessage: Ce(n) } : {}
9175
9170
  }).catch(() => {
9176
9171
  });
@@ -9486,7 +9481,7 @@ function gi(t) {
9486
9481
  };
9487
9482
  }
9488
9483
  const Wc = globalThis.fetch.bind(globalThis), mi = '.pluno-pa-widget-host[data-pluno-product-agent-ui="widget"]', Gc = '.pluno-pa-widget[data-pluno-product-agent-ui-root="widget"]', Jc = ".pluno-pa-widget__panel", Qc = ".pluno-pa-widget__timeline", Xc = "__plunoExtensionWidgetOwner";
9489
- class le extends Error {
9484
+ class ue extends Error {
9490
9485
  constructor(e, s, n, i) {
9491
9486
  super(e), this.retryable = s, this.status = n, this.retryAfterMs = i, this.name = "ProductAgentTokenProviderError";
9492
9487
  }
@@ -9605,7 +9600,7 @@ function md(t) {
9605
9600
  }
9606
9601
  }
9607
9602
  function Rs(t) {
9608
- if (t instanceof le)
9603
+ if (t instanceof ue)
9609
9604
  return t.retryable;
9610
9605
  if (t && typeof t == "object") {
9611
9606
  const e = t instanceof A ? t.code : "", s = /^[45][0-9]{2}$/.test(e) ? Number(e) : t.status;
@@ -9848,8 +9843,8 @@ class Ht {
9848
9843
  const e = ++this.conversationAdapterGeneration;
9849
9844
  this.conversationObservation?.dispose(), this.conversationUnsubscribe?.();
9850
9845
  const s = this.directoryAuthority, n = () => e === this.conversationAdapterGeneration;
9851
- this.operationTimingReporter = vo((h) => {
9852
- n() && !this.clientRuntime.isDisposed && this.reportHealthSignal("operation_timing", { timings: h.map((v) => ({ ...v, entrySurface: this.options.entrySurface })) });
9846
+ this.operationTimingReporter = vo((f) => {
9847
+ n() && !this.clientRuntime.isDisposed && this.reportHealthSignal("operation_timing", { timings: f.map((v) => ({ ...v, entrySurface: this.options.entrySurface })) });
9853
9848
  });
9854
9849
  const i = `pa.conversation.delivery:${this.modelClientScopeId}:${s.authorityId}`, r = `${i}:cancellations`;
9855
9850
  this.authenticatedUserId && this.options.restorePersistedState === !1 && sessionStorage.removeItem(r);
@@ -9857,10 +9852,10 @@ class Ht {
9857
9852
  authorityId: s.authorityId,
9858
9853
  isCurrent: n,
9859
9854
  read: async () => a ? JSON.parse(a) : null,
9860
- write: async (h) => {
9861
- this.authenticatedUserId && sessionStorage.setItem(r, JSON.stringify(h));
9855
+ write: async (f) => {
9856
+ this.authenticatedUserId && sessionStorage.setItem(r, JSON.stringify(f));
9862
9857
  },
9863
- onTiming: (h) => this.reportOperationTiming(h)
9858
+ onTiming: (f) => this.reportOperationTiming(f)
9864
9859
  });
9865
9860
  this.clientRuntime.installConversationPorts({
9866
9861
  ...Mo({
@@ -9869,29 +9864,29 @@ class Ht {
9869
9864
  isCurrent: n,
9870
9865
  http: this.directoryHttp,
9871
9866
  now: () => Date.now(),
9872
- prepareSubmission: async ({ submission: h, sources: v }) => {
9867
+ prepareSubmission: async ({ submission: f, sources: v }) => {
9873
9868
  const I = te(this.operationTimingReporter, {
9874
9869
  operation: "send",
9875
9870
  layer: "sdk",
9876
- requestId: h.requestId,
9877
- clientMessageId: h.userMessageId,
9878
- sessionId: h.sessionId
9871
+ requestId: f.requestId,
9872
+ clientMessageId: f.userMessageId,
9873
+ sessionId: f.sessionId
9879
9874
  });
9880
- let _ = h.contextPreparation ?? { pageContent: "", sessionTabs: [] };
9881
- if (h.contextPreparation === null) {
9882
- await I.measure("first_frame", () => new Promise((f) => {
9875
+ let _ = f.contextPreparation ?? { pageContent: "", sessionTabs: [] };
9876
+ if (f.contextPreparation === null) {
9877
+ await I.measure("first_frame", () => new Promise((h) => {
9883
9878
  if (document.visibilityState !== "visible") {
9884
- setTimeout(f, 0);
9879
+ setTimeout(h, 0);
9885
9880
  return;
9886
9881
  }
9887
9882
  const b = () => {
9888
- cancelAnimationFrame(w), document.removeEventListener("visibilitychange", y), setTimeout(f, 0);
9883
+ cancelAnimationFrame(w), document.removeEventListener("visibilitychange", y), setTimeout(h, 0);
9889
9884
  }, y = () => {
9890
9885
  document.visibilityState !== "visible" && b();
9891
9886
  }, w = requestAnimationFrame(b);
9892
9887
  document.addEventListener("visibilitychange", y);
9893
9888
  }));
9894
- const S = h.context.page;
9889
+ const S = f.context.page;
9895
9890
  if (oe().url !== S.url) throw Object.assign(new Error("The page changed before preparation completed. Send this message again."), { code: "context_preparation_interrupted", retryable: !1 });
9896
9891
  _ = { pageContent: await I.measure("page_capture", async () => Rn()), sessionTabs: [] };
9897
9892
  }
@@ -9904,49 +9899,49 @@ class Ht {
9904
9899
  return I.mark("context_ready"), { ..._, now: Date.now() };
9905
9900
  },
9906
9901
  connectionId: () => this.socket instanceof L ? this.socket.connectionId : null,
9907
- prepareUpload: this.options.prepareAttachmentUpload ?? (this.options.productVariant === "customer_embedded" ? (h) => this.prepareEmbedAttachmentUpload(h, n) : void 0),
9908
- onUploaded: async (h, v, I) => {
9909
- await ur(h, {
9902
+ prepareUpload: this.options.prepareAttachmentUpload ?? (this.options.productVariant === "customer_embedded" ? (f) => this.prepareEmbedAttachmentUpload(f, n) : void 0),
9903
+ onUploaded: async (f, v, I) => {
9904
+ await ur(f, {
9910
9905
  sessionId: v,
9911
9906
  sandboxPath: I.sandbox_path ?? void 0,
9912
9907
  storageKey: I.storage_key ?? void 0,
9913
9908
  fileUrl: I.file_url ? new URL(I.file_url, this.options.backendUrl).toString() : void 0,
9914
9909
  lastUsedAt: Date.now()
9915
9910
  }).catch((_) => V("web-sdk.attachments", "Failed to update persisted Product Agent attachment", {
9916
- attachmentId: h,
9911
+ attachmentId: f,
9917
9912
  message: _ instanceof Error ? _.message : String(_)
9918
9913
  }));
9919
9914
  },
9920
9915
  persistUpload: this.options.persistAttachmentUpload,
9921
- readAttachment: async (h) => {
9922
- const v = (await hi(h))?.blob;
9916
+ readAttachment: async (f) => {
9917
+ const v = (await hi(f))?.blob;
9923
9918
  if (!v) throw Object.assign(new Error("Attachment files are unavailable. Attach the files again and send a new message."), { code: "attachment_source_unavailable", retryable: !1 });
9924
9919
  return v;
9925
9920
  },
9926
- saveCancellation: (h) => o.save(h),
9927
- saveDelivery: async (h) => {
9928
- this.authenticatedUserId && (sessionStorage.setItem(i, JSON.stringify(h)), await o.committed(h));
9921
+ saveCancellation: (f) => o.save(f),
9922
+ saveDelivery: async (f) => {
9923
+ this.authenticatedUserId && (sessionStorage.setItem(i, JSON.stringify(f)), await o.committed(f));
9929
9924
  },
9930
9925
  // HTTP now owns command delivery; keep opt-in operational traces at that actual handoff.
9931
- onTiming: (h) => {
9932
- n() && this.reportOperationTiming(h);
9926
+ onTiming: (f) => {
9927
+ n() && this.reportOperationTiming(f);
9933
9928
  },
9934
- onCommand: (h) => xe("client_event", h.type, ws({ ...h.payload, type: h.type })),
9935
- onError: (h, v) => {
9936
- if (this.options.productVariant === "customer_embedded" && v.operation === "conversation.snapshot" && h instanceof A && h.code === "conversation_access_denied") {
9929
+ onCommand: (f) => xe("client_event", f.type, ws({ ...f.payload, type: f.type })),
9930
+ onError: (f, v) => {
9931
+ if (this.options.productVariant === "customer_embedded" && v.operation === "conversation.snapshot" && f instanceof A && f.code === "conversation_access_denied") {
9937
9932
  v.sessionId === this.getState().sessionId && this.startNewSession({ notifyTransport: !1 });
9938
9933
  return;
9939
9934
  }
9940
- V("web-sdk.conversation", "Conversation operation failed", { ...v, ...Ao(h) }), h instanceof A && h.backendRefusal && v.operation.startsWith("chat.") ? this.applyAccountSubmissionError(h.code) : this.handleDirectoryTransportError(h);
9935
+ V("web-sdk.conversation", "Conversation operation failed", { ...v, ...Ao(f) }), f instanceof A && f.backendRefusal && v.operation.startsWith("chat.") ? this.applyAccountSubmissionError(f.code) : this.handleDirectoryTransportError(f);
9941
9936
  }
9942
9937
  })
9943
9938
  });
9944
9939
  const c = this.clientRuntime.engine.getState().slices.conversation, l = this.options.restorePersistedState === !1 || !this.authenticatedUserId ? null : os(i);
9945
9940
  if (this.authenticatedUserId && !c.submissionOrder.length && !Object.keys(c.operations).length) {
9946
- const h = this.queuedClientEvents.filter((_) => _.type === "chat.user_message"), v = l ? JSON.parse(l) : h.length ? Oo(c, h.map((_) => {
9947
- const { type: S, ...f } = _, b = this.clientRuntime.engine.getState().slices.directory, y = b.clients[this.modelClientScopeId];
9941
+ const f = this.queuedClientEvents.filter((_) => _.type === "chat.user_message"), v = l ? JSON.parse(l) : f.length ? Oo(c, f.map((_) => {
9942
+ const { type: S, ...h } = _, b = this.clientRuntime.engine.getState().slices.directory, y = b.clients[this.modelClientScopeId];
9948
9943
  return {
9949
- command: { type: S, request_id: _.clientMessageId, payload: JSON.parse(JSON.stringify(f)) },
9944
+ command: { type: S, request_id: _.clientMessageId, payload: JSON.parse(JSON.stringify(h)) },
9950
9945
  requestedModel: _.model ?? null,
9951
9946
  clientScopeId: this.modelClientScopeId,
9952
9947
  conversationScopeId: y,
@@ -9961,7 +9956,7 @@ class Ht {
9961
9956
  if (!n()) return;
9962
9957
  I && (v || Object.keys(I.operations).length || Object.keys(I.stops).length) && await this.clientRuntime.engine.dispatch({ ...s, type: "conversation.restore_delivery", checkpoint: I });
9963
9958
  }
9964
- if (this.authenticatedUserId && (this.queuedClientEvents = this.queuedClientEvents.filter((h) => !["chat.user_message", "chat.retry_last_user_message", "run.stop", "runtime.warmup", "session.reset", "attachment.upload_completed"].includes(h.type))), Re(this.options.clientId, this.queuedClientEvents), !n()) return;
9959
+ if (this.authenticatedUserId && (this.queuedClientEvents = this.queuedClientEvents.filter((f) => !["chat.user_message", "chat.retry_last_user_message", "run.stop", "runtime.warmup", "session.reset", "attachment.upload_completed"].includes(f.type))), Re(this.options.clientId, this.queuedClientEvents), !n()) return;
9965
9960
  this.conversationObservation = new Po({
9966
9961
  authority: s,
9967
9962
  now: () => Date.now(),
@@ -9969,15 +9964,15 @@ class Ht {
9969
9964
  isCurrent: n,
9970
9965
  enabled: () => !!this.token && !this.authenticationFailure && !this.refreshingDefaultCredentials && this.state.status !== "closed",
9971
9966
  socket: {
9972
- retain: async (h, v) => {
9967
+ retain: async (f, v) => {
9973
9968
  const I = this.socket;
9974
- I instanceof L && await I.directoryRooms.retain(h, v).catch((_) => {
9969
+ I instanceof L && await I.directoryRooms.retain(f, v).catch((_) => {
9975
9970
  if (this.socket === I) throw _;
9976
9971
  });
9977
9972
  },
9978
- release: async (h, v) => {
9973
+ release: async (f, v) => {
9979
9974
  const I = this.socket;
9980
- I instanceof L && await I.directoryRooms.release(h, v).catch((_) => {
9975
+ I instanceof L && await I.directoryRooms.release(f, v).catch((_) => {
9981
9976
  if (this.socket === I) throw _;
9982
9977
  });
9983
9978
  }
@@ -9986,13 +9981,13 @@ class Ht {
9986
9981
  wakeup: { start: () => {
9987
9982
  }, stop: () => {
9988
9983
  } },
9989
- onError: (h) => this.handleDirectoryTransportError(h)
9984
+ onError: (f) => this.handleDirectoryTransportError(f)
9990
9985
  });
9991
- const d = (h, v) => {
9986
+ const d = (f, v) => {
9992
9987
  if (this.firstResponseTimersByClientMessageId.size) {
9993
- for (const I of h)
9988
+ for (const I of f)
9994
9989
  (I.dataType === "run_status" || I.dataType === "run_error") && this.clearFirstResponseTimer(I.respondsToUserMessageId ?? null);
9995
- for (const I of h)
9990
+ for (const I of f)
9996
9991
  if (I.content.trim() && (I.role === "assistant" || I.dataType === "commentary_history" || I.dataType === "tool_summary")) {
9997
9992
  const _ = v ? this.clientRuntime.engine.getState().slices.conversation.sessions[v] : void 0;
9998
9993
  for (const S of I.respondsToUserMessageId ? $r(_, I.respondsToUserMessageId) : [])
@@ -10000,16 +9995,16 @@ class Ht {
10000
9995
  }
10001
9996
  }
10002
9997
  };
10003
- let u = new Map(this.getState().messages.map((h) => [h.id, h])), p = this.clientRuntime.engine.getState().slices.conversation, g = this.clientRuntime.engine.getState().slices.directory.selections, m = this.clientRuntime.engine.getState().slices.directory.clients[this.modelClientScopeId];
9998
+ let u = new Map(this.getState().messages.map((f) => [f.id, f])), p = this.clientRuntime.engine.getState().slices.conversation, g = this.clientRuntime.engine.getState().slices.directory.selections, m = this.clientRuntime.engine.getState().slices.directory.clients[this.modelClientScopeId];
10004
9999
  this.conversationUnsubscribe = this.clientRuntime.engine.subscribe(() => {
10005
- const h = this.clientRuntime.engine.getState().slices, v = p;
10006
- p = h.conversation, Io(v, h.conversation, this.operationTimingReporter, "sdk");
10007
- const I = m !== h.directory.clients[this.modelClientScopeId];
10008
- m = h.directory.clients[this.modelClientScopeId], g !== h.directory.selections && (g = h.directory.selections, this.directoryScope.persist());
10009
- for (const S of Object.values(h.conversation.submissions)) {
10000
+ const f = this.clientRuntime.engine.getState().slices, v = p;
10001
+ p = f.conversation, Io(v, f.conversation, this.operationTimingReporter, "sdk");
10002
+ const I = m !== f.directory.clients[this.modelClientScopeId];
10003
+ m = f.directory.clients[this.modelClientScopeId], g !== f.directory.selections && (g = f.directory.selections, this.directoryScope.persist());
10004
+ for (const S of Object.values(f.conversation.submissions)) {
10010
10005
  if (S.delivery === "accepted" && v.submissions[S.userMessageId]?.delivery !== "accepted") {
10011
- const f = this.firstResponseTimersByClientMessageId.get(S.userMessageId);
10012
- f && (f.sessionId = S.sessionId), this.emit("ack", { clientMessageId: S.userMessageId, sessionId: S.sessionId });
10006
+ const h = this.firstResponseTimersByClientMessageId.get(S.userMessageId);
10007
+ h && (h.sessionId = S.sessionId), this.emit("ack", { clientMessageId: S.userMessageId, sessionId: S.sessionId });
10013
10008
  const b = S.sessionId;
10014
10009
  b && this.getState().sessionId === b && this.directoryHttp.request(`/sessions/${encodeURIComponent(b)}/history`, { limit: 200 }).then((y) => {
10015
10010
  n() && this.getState().sessionId === b && this.state.status !== "closed" && vs(this.clientRuntime, this.modelClientScopeId, b, y.turns);
@@ -10019,19 +10014,19 @@ class Ht {
10019
10014
  }
10020
10015
  (S.cancelled || S.delivery === "failed") && this.clearFirstResponseTimer(S.userMessageId);
10021
10016
  }
10022
- for (const [S, f] of Object.entries(h.directory.clients)) {
10017
+ for (const [S, h] of Object.entries(f.directory.clients)) {
10023
10018
  if (!S.startsWith(`background:${this.modelClientScopeId}:`)) continue;
10024
- const b = Ie(h.conversation, h.directory, f), y = b.sessionId ? h.conversation.sessions[b.sessionId] : void 0;
10019
+ const b = Ie(f.conversation, f.directory, h), y = b.sessionId ? f.conversation.sessions[b.sessionId] : void 0;
10025
10020
  if (this.firstResponseTimersByClientMessageId.size && (d(as(b, y?.queries.current, this.options.backendUrl).messages, b.sessionId), ["failed", "stopped"].includes(b.activity.phase)))
10026
- for (const R of de(y?.execution)) this.clearFirstResponseTimer(R);
10027
- const w = b.activity.phase === "completed" && de(y?.execution).some((R) => this.firstResponseTimersByClientMessageId.has(R));
10021
+ for (const R of le(y?.execution)) this.clearFirstResponseTimer(R);
10022
+ const w = b.activity.phase === "completed" && le(y?.execution).some((R) => this.firstResponseTimersByClientMessageId.has(R));
10028
10023
  (I && b.sessionId === this.getState().sessionId || !w && ["completed", "failed", "stopped"].includes(b.activity.phase)) && this.directoryScope.detach(S);
10029
10024
  }
10030
10025
  const _ = this.getState();
10031
10026
  d(_.messages, _.sessionId);
10032
10027
  for (const S of _.messages) {
10033
- const f = u.get(S.id);
10034
- (!f || f.content !== S.content || f.loading !== S.loading) && this.emit("message", S), S.content.trim() && S.content !== f?.content && (S.role === "assistant" || S.dataType === "commentary_history") && S.content.startsWith(f?.content ?? "") && this.emit("delta", S.content.slice(f?.content.length ?? 0));
10028
+ const h = u.get(S.id);
10029
+ (!h || h.content !== S.content || h.loading !== S.loading) && this.emit("message", S), S.content.trim() && S.content !== h?.content && (S.role === "assistant" || S.dataType === "commentary_history") && S.content.startsWith(h?.content ?? "") && this.emit("delta", S.content.slice(h?.content.length ?? 0));
10035
10030
  }
10036
10031
  u = new Map(_.messages.map((S) => [S.id, S])), this.rebuildRuntimeInteractions(), this.emit("state", _);
10037
10032
  }), this.conversationObservation.wake();
@@ -10093,7 +10088,7 @@ class Ht {
10093
10088
  n.sessionId ? e.conversation.sessions[n.sessionId]?.queries.current : void 0,
10094
10089
  this.options.backendUrl,
10095
10090
  this.clientRuntime.engine.getDiagnostics({ clientScopeId: this.modelClientScopeId, scopeId: s, sessionId: n.sessionId })
10096
- ), r = { clientScopeId: this.modelClientScopeId, origin: location.origin, pageUrl: location.href }, a = Bs(e, { kind: "starterPrompts", ...r, includeUserSuggestions: !1 }), o = Bs(e, { kind: "appearance", ...r }), c = o?.data?.kind === "appearance" ? o.data.value : null;
10091
+ ), r = { clientScopeId: this.modelClientScopeId, origin: location.origin, pageUrl: location.href }, a = Bs(e, this.options.productVariant === "personal" ? { kind: "userSuggestedTasks" } : { kind: "starterPrompts", ...r, includeUserSuggestions: !1 }), o = Bs(e, { kind: "appearance", ...r }), c = o?.data?.kind === "appearance" ? o.data.value : null;
10097
10092
  return {
10098
10093
  ...this.platformState,
10099
10094
  ...i,
@@ -10105,7 +10100,7 @@ class Ht {
10105
10100
  lastError: i.lastError ?? this.platformState.lastError,
10106
10101
  lastErrorCode: i.lastErrorCode ?? this.platformState.lastErrorCode,
10107
10102
  lastErrorSecuritySettingsUrl: !i.lastErrorCode || i.lastErrorCode === this.platformState.lastErrorCode ? this.platformState.lastErrorSecuritySettingsUrl : null,
10108
- starterPrompts: a?.data?.kind === "starterPrompts" ? [...a.data.prompts] : Kd(this.options.initialStarterPrompts),
10103
+ starterPrompts: a?.data && (a.data.kind === "starterPrompts" || a.data.kind === "userSuggestedTasks") ? [...a.data.prompts] : Kd(this.options.initialStarterPrompts),
10109
10104
  starterPromptsLoading: a?.status === "loading" || a?.status === "refreshing",
10110
10105
  appearance: c ? { accentColor: c.accent, colorScheme: c.colorScheme, fontFamily: c.fontFamily, scribbleStyle: c.scribbleStyle } : null
10111
10106
  };
@@ -10139,7 +10134,7 @@ class Ht {
10139
10134
  let o = null;
10140
10135
  const c = new Promise((l, d) => {
10141
10136
  o = window.setTimeout(() => {
10142
- r.abort(), d(new le("Pluno token provider timed out", !0));
10137
+ r.abort(), d(new ue("Pluno token provider timed out", !0));
10143
10138
  }, sd);
10144
10139
  });
10145
10140
  try {
@@ -10148,9 +10143,9 @@ class Ht {
10148
10143
  c
10149
10144
  ]);
10150
10145
  if (r.signal.aborted || this.tokenAbortController !== r)
10151
- throw new le("Pluno token request was cancelled", !0);
10146
+ throw new ue("Pluno token request was cancelled", !0);
10152
10147
  if (typeof l != "string" || !l.trim())
10153
- throw new le("Chat setup did not return a session. Contact your app administrator, then try again.", !1);
10148
+ throw new ue("Chat setup did not return a session. Contact your app administrator, then try again.", !1);
10154
10149
  return this.token = l, this.tokenExpiresAtMs = md(l), l;
10155
10150
  } finally {
10156
10151
  o !== null && window.clearTimeout(o);
@@ -10196,7 +10191,7 @@ class Ht {
10196
10191
  if (this.lastRecoveryStage = "token_provider", this.token = await this.acquireToken("connect", { forceRefresh: e }), this.token && (this.directoryHttp.auth.token = this.token), n !== this.connectionAttemptId || this.state.status === "closed")
10197
10192
  return;
10198
10193
  if (this.lastRecoveryStage = "socket_admission", !this.token && !this.options.webSocketFactory)
10199
- throw new le("Pluno requires a token or tokenProvider", !1);
10194
+ throw new ue("Pluno requires a token or tokenProvider", !1);
10200
10195
  if (!this.options.webSocketFactory && this.rejectedTransportToken !== null && this.rejectedTransportToken === this.token) {
10201
10196
  this.clearEmbeddedRecoveryBudget(), this.setState({ status: "error", lastError: i });
10202
10197
  return;
@@ -10292,7 +10287,7 @@ class Ht {
10292
10287
  lastError: vi,
10293
10288
  lastErrorCode: "connection_failed"
10294
10289
  }), this.emit("error", a), this.scheduleReconnect(
10295
- r instanceof le ? r.retryAfterMs : void 0
10290
+ r instanceof ue ? r.retryAfterMs : void 0
10296
10291
  );
10297
10292
  return;
10298
10293
  }
@@ -10445,21 +10440,21 @@ class Ht {
10445
10440
  entrySurface: this.options.entrySurface,
10446
10441
  submittedAt: s.submittedAt ?? Date.now()
10447
10442
  });
10448
- const h = this.directoryAuthority;
10443
+ const f = this.directoryAuthority;
10449
10444
  return this.clientRuntime.isDisposed ? null : new Promise((v, I) => {
10450
10445
  let _ = null, S = null;
10451
- const f = () => {
10446
+ const h = () => {
10452
10447
  const b = this.clientRuntime.engine.getState().slices.conversation.submissions[r];
10453
10448
  if (!(b && !b.cancelled && b.delivery !== "accepted" && b.delivery !== "failed"))
10454
10449
  if (_?.(), S?.(), b?.delivery === "failed" && !b.cancelled) I(new Error(b.error?.message ?? "Message delivery failed."));
10455
10450
  else {
10456
10451
  const y = b?.invocation === "user" && b.contextPreparation?.pageContent ? b.context.page?.url : null;
10457
- b?.delivery === "accepted" && !b.cancelled && typeof y == "string" && c === this.submissionIntentRevision && h === this.directoryAuthority && this.clientRuntime.engine.getState().slices.directory.clients[this.modelClientScopeId] === m && (this.lastUserMessagePageUrl = y), v(b?.delivery === "accepted" && !b.cancelled ? r : null);
10452
+ b?.delivery === "accepted" && !b.cancelled && typeof y == "string" && c === this.submissionIntentRevision && f === this.directoryAuthority && this.clientRuntime.engine.getState().slices.directory.clients[this.modelClientScopeId] === m && (this.lastUserMessagePageUrl = y), v(b?.delivery === "accepted" && !b.cancelled ? r : null);
10458
10453
  }
10459
10454
  };
10460
- _ = this.clientRuntime.engine.subscribe(f), S = this.clientRuntime.onDispose(() => {
10455
+ _ = this.clientRuntime.engine.subscribe(h), S = this.clientRuntime.onDispose(() => {
10461
10456
  _?.(), v(null);
10462
- }), f();
10457
+ }), h();
10463
10458
  });
10464
10459
  }
10465
10460
  reportResponseVisibility(e) {
@@ -10483,7 +10478,7 @@ class Ht {
10483
10478
  errorFingerprint: s,
10484
10479
  ...i ? { renderedError: i } : {},
10485
10480
  ...r ? { historyRefreshFailure: r } : {},
10486
- ...ye(a) ? { httpRequest: a } : {},
10481
+ ...pe(a) ? { httpRequest: a } : {},
10487
10482
  ...n ? { displayedMessage: Ce(n) } : {}
10488
10483
  });
10489
10484
  }
@@ -10558,13 +10553,13 @@ class Ht {
10558
10553
  }), new Promise((l, d) => {
10559
10554
  let u, p;
10560
10555
  const g = () => {
10561
- const m = this.clientRuntime.engine.getState().slices, h = m.conversation.operations[c], v = m.directory.authorityId !== a.authorityId || m.directory.clients[this.modelClientScopeId] !== o;
10562
- if (!v && h && !["done", "failed"].includes(h.phase)) return;
10563
- if (u?.(), p?.(), v || !h || h.phase === "failed") {
10564
- d(new Error(h?.error?.message ?? "Attachment preparation was cancelled."));
10556
+ const m = this.clientRuntime.engine.getState().slices, f = m.conversation.operations[c], v = m.directory.authorityId !== a.authorityId || m.directory.clients[this.modelClientScopeId] !== o;
10557
+ if (!v && f && !["done", "failed"].includes(f.phase)) return;
10558
+ if (u?.(), p?.(), v || !f || f.phase === "failed") {
10559
+ d(new Error(f?.error?.message ?? "Attachment preparation was cancelled."));
10565
10560
  return;
10566
10561
  }
10567
- const _ = h.result.attachment;
10562
+ const _ = f.result.attachment;
10568
10563
  l(Ar({
10569
10564
  id: _.id,
10570
10565
  name: _.name,
@@ -10816,7 +10811,7 @@ class Ht {
10816
10811
  if (!this.clientRuntime.engine.getState().slices.account.authority) {
10817
10812
  const e = await this.acquireToken("connect", { preferCached: !0 });
10818
10813
  if (this.clientRuntime.isDisposed || this.state.status === "closed") return;
10819
- if (!e) throw new le("Pluno requires a token or tokenProvider", !1);
10814
+ if (!e) throw new ue("Pluno requires a token or tokenProvider", !1);
10820
10815
  this.directoryHttp.auth.token = e;
10821
10816
  const s = this.connectionAttemptId, n = () => !this.clientRuntime.isDisposed && this.state.status !== "closed" && this.connectionAttemptId === s && this.directoryHttp.auth.token === e, i = await this.directoryHttp.request(
10822
10817
  "/me",
@@ -10848,26 +10843,26 @@ class Ht {
10848
10843
  s = !0;
10849
10844
  const p = this.getState().sessionId, g = () => !this.clientRuntime.isDisposed && JSON.stringify(this.clientRuntime.engine.getState().slices.account.authority) === JSON.stringify(u) && this.getState().sessionId === p;
10850
10845
  Promise.all(["notifications", "tab_grouping"].map(async (m) => {
10851
- const h = await d.getState(m, p);
10846
+ const f = await d.getState(m, p);
10852
10847
  if (g()) {
10853
- if (!h.bridgeReady) return h;
10848
+ if (!f.bridgeReady) return f;
10854
10849
  if (await this.clientRuntime.engine.dispatch({
10855
10850
  type: "stage7.device_fact",
10856
10851
  authority: u,
10857
10852
  now: Date.now(),
10858
10853
  feature: m,
10859
- fact: { permission: h.permissionGranted ? "granted" : h.permissionNeeded ? "missing" : "unknown", revision: Math.max(Date.now(), this.clientRuntime.engine.getState().slices.interactions.deviceFacts[m].revision + 1), snoozedUntil: h.snoozedUntil ?? null }
10860
- }), m === "tab_grouping" && h.sessionId === p && p) for (const v of h.crossTabUserMessageIds ?? [])
10854
+ fact: { permission: f.permissionGranted ? "granted" : f.permissionNeeded ? "missing" : "unknown", revision: Math.max(Date.now(), this.clientRuntime.engine.getState().slices.interactions.deviceFacts[m].revision + 1), snoozedUntil: f.snoozedUntil ?? null }
10855
+ }), m === "tab_grouping" && f.sessionId === p && p) for (const v of f.crossTabUserMessageIds ?? [])
10861
10856
  await this.clientRuntime.engine.dispatch({ type: "stage7.cross_tab", authority: u, now: Date.now(), sessionId: p, userMessageId: v });
10862
- return h;
10857
+ return f;
10863
10858
  }
10864
10859
  })).then(async (m) => {
10865
10860
  g() && await this.clientRuntime.engine.dispatch({
10866
10861
  type: "stage7.bridge_ready",
10867
10862
  authority: u,
10868
10863
  now: Date.now(),
10869
- ready: m.every((h) => h?.bridgeReady),
10870
- error: m.find((h) => h?.error)?.error ?? null
10864
+ ready: m.every((f) => f?.bridgeReady),
10865
+ error: m.find((f) => f?.error)?.error ?? null
10871
10866
  });
10872
10867
  }).catch(async () => {
10873
10868
  g() && await this.clientRuntime.engine.dispatch({ type: "stage7.bridge_ready", authority: u, now: Date.now(), ready: !1, error: "The Pluno extension could not reconnect. Try again." });
@@ -10902,8 +10897,8 @@ class Ht {
10902
10897
  "stage7.device": async ({ feature: d, action: u, requestId: p }) => {
10903
10898
  const g = this.options.runtimeAdapters?.featurePermissions;
10904
10899
  if (!g) return { fact: { permission: "unsupported", revision: Date.now(), snoozedUntil: null }, completedAt: Date.now() };
10905
- const m = this.clientRuntime.engine.getState().slices.interactions, h = m.promptActions[p], v = h?.expectedRevision ?? m.preferencePrompts[d].revision;
10906
- u === "allow" && await g.enable(d, { requestId: p, expectedRevision: v, action: h?.action === "enable" ? "enable" : "allow" }), u === "not_now" && await g.dismiss(d, { requestId: p, expectedRevision: v, action: "not_now" });
10900
+ const m = this.clientRuntime.engine.getState().slices.interactions, f = m.promptActions[p], v = f?.expectedRevision ?? m.preferencePrompts[d].revision;
10901
+ u === "allow" && await g.enable(d, { requestId: p, expectedRevision: v, action: f?.action === "enable" ? "enable" : "allow" }), u === "not_now" && await g.dismiss(d, { requestId: p, expectedRevision: v, action: "not_now" });
10907
10902
  const I = await g.getState(d, this.getState().sessionId);
10908
10903
  if (!I.bridgeReady) throw new Error("The Pluno extension is reconnecting. Try again.");
10909
10904
  return { fact: {
@@ -10996,14 +10991,14 @@ class Ht {
10996
10991
  reportHealthSignal(e, s = {}) {
10997
10992
  let n = this.getState();
10998
10993
  if (e === "first_response_slow" && s.sessionId && s.sessionId !== n.sessionId) {
10999
- const { conversation: m, directory: h } = this.clientRuntime.engine.getState().slices, v = Object.values(h.clients).find((I) => h.selections[I]?.sessionId === s.sessionId);
10994
+ const { conversation: m, directory: f } = this.clientRuntime.engine.getState().slices, v = Object.values(f.clients).find((I) => f.selections[I]?.sessionId === s.sessionId);
11000
10995
  v && (n = { ...n, ...as(
11001
- Ie(m, h, v),
10996
+ Ie(m, f, v),
11002
10997
  m.sessions[s.sessionId]?.queries.current,
11003
10998
  this.options.backendUrl
11004
10999
  ) });
11005
11000
  }
11006
- if (s.httpRequest && (!ye(s.httpRequest) || s.httpRequest.sessionId !== null && s.httpRequest.sessionId !== n.sessionId) || s.historyRefreshFailure && (s.historyRefreshFailure.consecutiveFailures < 3 || s.historyRefreshFailure.sessionId !== n.sessionId) || s.renderedError && s.renderedError.sessionId !== n.sessionId || s.uiInvariant && s.uiInvariant.current.sessionId !== n.sessionId) return;
11001
+ if (s.httpRequest && (!pe(s.httpRequest) || s.httpRequest.sessionId !== null && s.httpRequest.sessionId !== n.sessionId) || s.historyRefreshFailure && (s.historyRefreshFailure.consecutiveFailures < 3 || s.historyRefreshFailure.sessionId !== n.sessionId) || s.renderedError && s.renderedError.sessionId !== n.sessionId || s.uiInvariant && s.uiInvariant.current.sessionId !== n.sessionId) return;
11007
11002
  const i = s.historyRefreshFailure?.episodeId ?? (s.renderedError ? `${s.errorFingerprint}:${s.renderedError.itemId}` : void 0) ?? s.errorFingerprint ?? s.clientMessageId ?? (s.previousPhase && s.nextPhase ? `${s.previousPhase}:${s.nextPhase}:${s.reason ?? "unknown"}` : null);
11008
11003
  if (i) {
11009
11004
  const m = `${e}:${i}:${e === "invalid_state_transition" ? s.reason ?? "unknown" : ""}`;
@@ -11233,7 +11228,7 @@ class Ht {
11233
11228
  const e = { clientScopeId: this.modelClientScopeId, origin: location.origin, pageUrl: location.href };
11234
11229
  return Promise.all([
11235
11230
  is(this.clientRuntime, { kind: "appearance", ...e }),
11236
- is(this.clientRuntime, { kind: "starterPrompts", ...e, includeUserSuggestions: !1 }).then(async (s) => {
11231
+ is(this.clientRuntime, this.options.productVariant === "personal" ? { kind: "userSuggestedTasks" } : { kind: "starterPrompts", ...e, includeUserSuggestions: !1 }).then(async (s) => {
11237
11232
  s.kind === "starterPrompts" && s.prompts.length === 0 && location.href === e.pageUrl && await this.requestTransientStarterPrompts();
11238
11233
  })
11239
11234
  ]).then(() => {
@@ -11289,7 +11284,7 @@ class Ht {
11289
11284
  if (p.type === "run.stop" && g.selections[m]?.sessionId === p.payload.sessionId) {
11290
11285
  if (u) continue;
11291
11286
  u = !0;
11292
- const h = o.filter((v) => v.type === "run.stop" && v.payload.sessionId === p.payload.sessionId).map((v) => String(v.payload.expectedUserMessageId));
11287
+ const f = o.filter((v) => v.type === "run.stop" && v.payload.sessionId === p.payload.sessionId).map((v) => String(v.payload.expectedUserMessageId));
11293
11288
  await this.clientRuntime.engine.dispatch({
11294
11289
  ...d,
11295
11290
  type: "conversation.stop",
@@ -11297,7 +11292,7 @@ class Ht {
11297
11292
  conversationScopeId: m,
11298
11293
  requestId: p.request_id,
11299
11294
  reason: p.payload.reason,
11300
- userMessageIds: h
11295
+ userMessageIds: f
11301
11296
  });
11302
11297
  } else (p.type === "run.stop" || p.type === "session.reset") && await this.clientRuntime.engine.dispatch({ ...d, type: "conversation.operation", command: p });
11303
11298
  }
@@ -11388,6 +11383,10 @@ class Ht {
11388
11383
  });
11389
11384
  return;
11390
11385
  }
11386
+ if (e.code === "invalid_response" && e.stage === "bootstrap") {
11387
+ this.stopAuthentication(new A(String(e.message), "connection_failed", !1, { stage: "bootstrap" }));
11388
+ return;
11389
+ }
11391
11390
  if (!this.options.webSocketFactory && (e.code === "unauthorized" || e.code === "401") && e.reason === "invalid_token" && (this.canRefreshInvalidCredential() || this.credentialRecovery !== null)) {
11392
11391
  const s = this.socket;
11393
11392
  if (s instanceof L) {
@@ -11592,7 +11591,7 @@ class Ht {
11592
11591
  this.embeddedRecoveryTimer !== null && window.clearTimeout(this.embeddedRecoveryTimer), this.embeddedRecoveryTimer = null;
11593
11592
  }
11594
11593
  connectionFailureDiagnostic(e, s) {
11595
- const n = e instanceof le ? e.status : e instanceof A && e.code === "unauthorized" ? 401 : e instanceof A && /^[45][0-9]{2}$/.test(e.code) ? Number(e.code) : void 0, i = n !== void 0 && Number.isInteger(n) && n >= 400 && n <= 599 ? n : void 0, a = !(e instanceof A && ["unauthorized", "403", "update_required", "executor_replaced"].includes(e.code)) && Rs(e) && i !== 401 && i !== 403;
11594
+ const n = e instanceof ue ? e.status : e instanceof A && e.code === "unauthorized" ? 401 : e instanceof A && /^[45][0-9]{2}$/.test(e.code) ? Number(e.code) : void 0, i = n !== void 0 && Number.isInteger(n) && n >= 400 && n <= 599 ? n : void 0, a = !(e instanceof A && ["unauthorized", "403", "update_required", "executor_replaced"].includes(e.code)) && Rs(e) && i !== 401 && i !== 403;
11596
11595
  return {
11597
11596
  stage: s,
11598
11597
  ...i !== void 0 ? { httpStatus: i } : {},
@@ -11700,13 +11699,13 @@ class Ht {
11700
11699
  const c = await this.acquireToken("connect", { forceRefresh: !0 });
11701
11700
  if (this.socket !== e || this.state.status === "closed" || this.clientRuntime.isDisposed)
11702
11701
  throw new A("Conversation authority was retired.", "authority_retired", !0);
11703
- if (!c) throw new le("Pluno token provider did not return a token", !1);
11702
+ if (!c) throw new ue("Pluno token provider did not return a token", !1);
11704
11703
  if (s && c === i) throw new A("Credential did not change.", "unauthorized", !1);
11705
11704
  this.directoryHttp.auth.token = c, a = "bootstrap", this.lastRecoveryStage = a, await this.replaceDefaultTransportCredentials(e), this.reportTransportDiagnostic("auth_refresh_validated", r);
11706
11705
  })().catch((c) => {
11707
11706
  if (this.socket !== e || this.state.status === "closed") throw c;
11708
11707
  if (this.reportTransportDiagnostic("auth_refresh_failed", { ...r, ...this.connectionFailureDiagnostic(c, a) }), this.credentialRecoveryFailure = Ge(c), c instanceof A && ["unauthorized", "403", "update_required"].includes(c.code) || !Rs(c)) {
11709
- const l = c instanceof A ? c : new A(c instanceof le ? c.message : "Your session could not be refreshed. Try again.", this.options.productVariant === "customer_embedded" ? "connection_failed" : "unauthorized", !1);
11708
+ const l = c instanceof A ? c : new A(c instanceof ue ? c.message : "Your session could not be refreshed. Try again.", this.options.productVariant === "customer_embedded" ? "connection_failed" : "unauthorized", !1);
11710
11709
  throw this.stopAuthentication(l), l;
11711
11710
  }
11712
11711
  throw this.options.productVariant === "customer_embedded" && this.setState({ status: "reconnecting", lastError: vi, lastErrorCode: "connection_failed" }), this.scheduleReconnect(), c;
@@ -11779,7 +11778,7 @@ function vd() {
11779
11778
  }
11780
11779
  });
11781
11780
  }, s = window.fetch, n = XMLHttpRequest.prototype.open, i = XMLHttpRequest.prototype.setRequestHeader, r = XMLHttpRequest.prototype.send, a = function(g, m) {
11782
- const h = Date.now();
11781
+ const f = Date.now();
11783
11782
  let v;
11784
11783
  try {
11785
11784
  v = s.call(this, g, m);
@@ -11791,28 +11790,28 @@ function vd() {
11791
11790
  if (!Me(_, S, m?.body)) {
11792
11791
  const b = {
11793
11792
  requestId: qs("fetch"),
11794
- url: fe(_, ks),
11793
+ url: ge(_, ks),
11795
11794
  method: (m?.method ?? I?.method ?? "GET").toUpperCase(),
11796
11795
  requestHeaders: S,
11797
11796
  requestBody: Ti(m?.body),
11798
11797
  resourceType: "fetch",
11799
- startedAt: new Date(h).toISOString()
11798
+ startedAt: new Date(f).toISOString()
11800
11799
  };
11801
11800
  v.then(
11802
11801
  (y) => {
11803
- El(y, b, h, e).catch(() => {
11802
+ El(y, b, f, e).catch(() => {
11804
11803
  e({
11805
11804
  ...b,
11806
11805
  responseStatus: y.status,
11807
- durationMs: Date.now() - h
11806
+ durationMs: Date.now() - f
11808
11807
  });
11809
11808
  });
11810
11809
  },
11811
11810
  (y) => {
11812
11811
  e({
11813
11812
  ...b,
11814
- errorText: fe(y instanceof Error ? y.message : String(y)),
11815
- durationMs: Date.now() - h
11813
+ errorText: ge(y instanceof Error ? y.message : String(y)),
11814
+ durationMs: Date.now() - f
11816
11815
  });
11817
11816
  }
11818
11817
  );
@@ -11820,20 +11819,20 @@ function vd() {
11820
11819
  } catch {
11821
11820
  }
11822
11821
  return v;
11823
- }, o = function(g, m, h, v, I) {
11824
- const _ = n.call(this, g, m, h ?? !0, v ?? void 0, I ?? void 0), S = typeof m == "string" ? m : m.toString();
11822
+ }, o = function(g, m, f, v, I) {
11823
+ const _ = n.call(this, g, m, f ?? !0, v ?? void 0, I ?? void 0), S = typeof m == "string" ? m : m.toString();
11825
11824
  return Es.set(this, {
11826
11825
  requestId: qs("xhr"),
11827
11826
  method: String(g ?? "GET").toUpperCase(),
11828
- url: fe(S, ks),
11827
+ url: ge(S, ks),
11829
11828
  requestHeaders: {},
11830
11829
  startedAtMs: Date.now(),
11831
11830
  startedAt: (/* @__PURE__ */ new Date()).toISOString(),
11832
11831
  excluded: Me(S)
11833
11832
  }), _;
11834
11833
  }, c = function(g, m) {
11835
- const h = i.call(this, g, m), v = Es.get(this);
11836
- return v && Object.keys(v.requestHeaders).length < kn && (v.requestHeaders[g] = Tn(g, m), v.excluded = v.excluded || Me(v.url, v.requestHeaders)), h;
11834
+ const f = i.call(this, g, m), v = Es.get(this);
11835
+ return v && Object.keys(v.requestHeaders).length < kn && (v.requestHeaders[g] = Tn(g, m), v.excluded = v.excluded || Me(v.url, v.requestHeaders)), f;
11837
11836
  }, l = function(g) {
11838
11837
  try {
11839
11838
  const m = Es.get(this);
@@ -11842,7 +11841,7 @@ function vd() {
11842
11841
  () => {
11843
11842
  queueMicrotask(() => {
11844
11843
  try {
11845
- const h = Ml(this.getAllResponseHeaders());
11844
+ const f = Ml(this.getAllResponseHeaders());
11846
11845
  e({
11847
11846
  requestId: m.requestId,
11848
11847
  url: m.url,
@@ -11851,8 +11850,8 @@ function vd() {
11851
11850
  requestBody: m.requestBody,
11852
11851
  resourceType: "xhr",
11853
11852
  responseStatus: this.status,
11854
- responseHeaders: h,
11855
- responseBody: ql(this, h),
11853
+ responseHeaders: f,
11854
+ responseBody: ql(this, f),
11856
11855
  errorText: this.status === 0 ? "XHR request failed or was aborted" : void 0,
11857
11856
  startedAt: m.startedAt,
11858
11857
  durationMs: Date.now() - m.startedAtMs
@@ -11891,14 +11890,14 @@ function vd() {
11891
11890
  const m = g;
11892
11891
  if (m.initiatorType === "fetch" || m.initiatorType === "xmlhttprequest" || Me(m.name))
11893
11892
  continue;
11894
- const h = performance.timeOrigin + m.startTime;
11893
+ const f = performance.timeOrigin + m.startTime;
11895
11894
  e({
11896
11895
  requestId: qs("resource"),
11897
- url: fe(m.name, ks),
11896
+ url: ge(m.name, ks),
11898
11897
  method: "GET",
11899
11898
  resourceType: "resource",
11900
11899
  responseStatus: m.responseStatus,
11901
- startedAt: new Date(h).toISOString(),
11900
+ startedAt: new Date(f).toISOString(),
11902
11901
  durationMs: m.duration
11903
11902
  });
11904
11903
  }
@@ -12199,19 +12198,19 @@ function jd() {
12199
12198
  function Rn() {
12200
12199
  if (!document.body)
12201
12200
  return "";
12202
- const t = [], e = [], s = (h, v) => {
12201
+ const t = [], e = [], s = (f, v) => {
12203
12202
  const I = Be(v);
12204
- !I || e.includes(I) || (t.push([h, I]), e.push(I));
12203
+ !I || e.includes(I) || (t.push([f, I]), e.push(I));
12205
12204
  };
12206
12205
  s("Selected text", window.getSelection()?.toString() ?? "");
12207
12206
  const n = "[role='dialog'], [role='alertdialog'], dialog[open], [aria-modal='true']", i = Array.from(document.querySelectorAll(n)).filter(
12208
- (h) => Ir(h) && !h.parentElement?.closest(n)
12207
+ (f) => Ir(f) && !f.parentElement?.closest(n)
12209
12208
  );
12210
- for (const h of i.slice(0, 3))
12211
- s("Active overlay", Ts(tt(h), e));
12209
+ for (const f of i.slice(0, 3))
12210
+ s("Active overlay", Ts(tt(f), e));
12212
12211
  const r = Bd(), a = r ? Ts(tt(r), e) : "";
12213
12212
  s("Main page content", a), s("Additional visible page text", Ts(tt(document.body), e));
12214
- const o = t.map(([h, v]) => `${h}:
12213
+ const o = t.map(([f, v]) => `${f}:
12215
12214
  ${v}`).join(`
12216
12215
 
12217
12216
  `).trim().slice(0, 12e3), c = Ld(i, r).trim(), l = `Simplified DOM outline:
@@ -12329,12 +12328,12 @@ function Ld(t, e) {
12329
12328
  e && p.add(e);
12330
12329
  let g = 0;
12331
12330
  const m = (S) => {
12332
- const f = S.getAttribute("role");
12333
- return f && !a.has(f) ? f : "";
12334
- }, h = (S) => {
12335
- const f = S.getAttribute("data-testid") || S.getAttribute("data-test") || S.getAttribute("data-qa") || S.getAttribute("data-cy") || "";
12336
- return `${S.tagName.toLowerCase()}|${m(S)}|${f}`;
12337
- }, v = (S, f, b) => {
12331
+ const h = S.getAttribute("role");
12332
+ return h && !a.has(h) ? h : "";
12333
+ }, f = (S) => {
12334
+ const h = S.getAttribute("data-testid") || S.getAttribute("data-test") || S.getAttribute("data-qa") || S.getAttribute("data-cy") || "";
12335
+ return `${S.tagName.toLowerCase()}|${m(S)}|${h}`;
12336
+ }, v = (S, h, b) => {
12338
12337
  const y = (w, R) => {
12339
12338
  const T = w.tagName.toLowerCase(), C = window.getComputedStyle(w), E = d.has(w);
12340
12339
  if (g >= 1e3 && !E || b.has(w) || r.has(T) || w.matches(".pluno-pa-widget-host, [data-pluno-product-agent-widget]") || C.display === "none" || C.visibility === "hidden")
@@ -12342,17 +12341,17 @@ function Ld(t, e) {
12342
12341
  g += 1;
12343
12342
  const q = m(w), O = _r(w), k = o.has(q) || ["button", "input", "textarea", "select", "iframe", "canvas"].includes(T) || T === "a" && w.hasAttribute("href"), x = Array.from(w.children).filter((D) => D instanceof HTMLElement), U = /* @__PURE__ */ new Map();
12344
12343
  for (const D of x) {
12345
- const $ = h(D);
12344
+ const $ = f(D);
12346
12345
  U.set($, (U.get($) ?? 0) + 1);
12347
12346
  }
12348
12347
  const H = /* @__PURE__ */ new Map(), Fe = /* @__PURE__ */ new Map();
12349
12348
  for (const D of x) {
12350
- const $ = h(D), ve = Fe.get($) ?? 0;
12349
+ const $ = f(D), ve = Fe.get($) ?? 0;
12351
12350
  Fe.set($, ve + 1), (U.get($) ?? 0) > 8 && ve >= 6 && !d.has(D) && H.set($, (H.get($) ?? 0) + 1);
12352
12351
  }
12353
12352
  const ot = /* @__PURE__ */ new Map(), qn = /* @__PURE__ */ new Set(), Kt = [], Cn = [];
12354
12353
  for (const D of x) {
12355
- const $ = h(D), ve = U.get($) ?? 0, Mn = ot.get($) ?? 0;
12354
+ const $ = f(D), ve = U.get($) ?? 0, Mn = ot.get($) ?? 0;
12356
12355
  if (ot.set($, Mn + 1), ve > 8 && Mn >= 6 && !d.has(D)) {
12357
12356
  qn.has($) || (Kt.push([`… ${H.get($) ?? 0} similar siblings omitted`]), qn.add($));
12358
12357
  continue;
@@ -12391,7 +12390,7 @@ function Ld(t, e) {
12391
12390
  containsTextElement: n.has(T) || at.some((D) => D.containsTextElement)
12392
12391
  };
12393
12392
  };
12394
- return [`--- ${f} ---`, ...y(S, 0).lines].join(`
12393
+ return [`--- ${h} ---`, ...y(S, 0).lines].join(`
12395
12394
  `);
12396
12395
  }, I = [], _ = Be(window.getSelection()?.toString() ?? "");
12397
12396
  _ && I.push(`--- selected text ---
@@ -13165,7 +13164,7 @@ function qr(t) {
13165
13164
  return e;
13166
13165
  }
13167
13166
  function Tn(t, e) {
13168
- return Ur(t) ? Vt : fe(Nt(e), ud);
13167
+ return Ur(t) ? Vt : ge(Nt(e), ud);
13169
13168
  }
13170
13169
  function Al(t, e) {
13171
13170
  return typeof t == "string" ? t : t instanceof URL ? t.toString() : e?.url ?? "";
@@ -13199,10 +13198,10 @@ async function Tl(t) {
13199
13198
  return;
13200
13199
  const { done: c, value: l } = o;
13201
13200
  if (c)
13202
- return fe(r + i.decode());
13201
+ return ge(r + i.decode());
13203
13202
  const d = Sn - a;
13204
13203
  if (l.byteLength > d)
13205
- return r += i.decode(l.subarray(0, Math.max(d, 0)), { stream: !0 }), e.cancel(), `${fe(r)}... [truncated]`;
13204
+ return r += i.decode(l.subarray(0, Math.max(d, 0)), { stream: !0 }), e.cancel(), `${ge(r)}... [truncated]`;
13206
13205
  a += l.byteLength, r += i.decode(l, { stream: !0 });
13207
13206
  }
13208
13207
  } catch {
@@ -13215,14 +13214,14 @@ async function Tl(t) {
13215
13214
  function ql(t, e) {
13216
13215
  if (Cr(new Headers(e)))
13217
13216
  try {
13218
- return t.responseType === "" || t.responseType === "text" ? fe(t.responseText ?? "") : void 0;
13217
+ return t.responseType === "" || t.responseType === "text" ? ge(t.responseText ?? "") : void 0;
13219
13218
  } catch {
13220
13219
  return;
13221
13220
  }
13222
13221
  }
13223
13222
  function Ti(t) {
13224
13223
  if (typeof t == "string")
13225
- return fe(t);
13224
+ return ge(t);
13226
13225
  }
13227
13226
  function Cl(t) {
13228
13227
  return ne({
@@ -13291,7 +13290,7 @@ function Ml(t) {
13291
13290
  }
13292
13291
  return e;
13293
13292
  }
13294
- function fe(t, e = Sn) {
13293
+ function ge(t, e = Sn) {
13295
13294
  return t.length <= e ? t : `${t.slice(0, e)}... [truncated ${t.length - e} chars]`;
13296
13295
  }
13297
13296
  function qs(t) {
@@ -13330,7 +13329,7 @@ function Nl(t) {
13330
13329
  function jl(t) {
13331
13330
  return t === 401 || t === 403;
13332
13331
  }
13333
- const Vt = "[REDACTED_SECRET]", ge = "[REDACTED_TOKEN]", Bl = "[REDACTED_SIGNED_URL]", Ll = 20, Fl = /^(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, xr = /\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi, Mr = /\bBasic\s+[A-Za-z0-9+/=-]{12,}/gi, Pr = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g, Dr = /\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, $l = /\bhttps?:\/\/[^\s"'<>]+(?:X-Amz-Signature|X-Goog-Signature|Signature|sig=)[^\s"'<>]*/gi, zl = /\bhttps?:\/\/[^\s"'<>]+/gi, Hl = /[),.;\]]+$/;
13332
+ const Vt = "[REDACTED_SECRET]", me = "[REDACTED_TOKEN]", Bl = "[REDACTED_SIGNED_URL]", Ll = 20, Fl = /^(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, xr = /\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi, Mr = /\bBasic\s+[A-Za-z0-9+/=-]{12,}/gi, Pr = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g, Dr = /\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, $l = /\bhttps?:\/\/[^\s"'<>]+(?:X-Amz-Signature|X-Goog-Signature|Signature|sig=)[^\s"'<>]*/gi, zl = /\bhttps?:\/\/[^\s"'<>]+/gi, Hl = /[),.;\]]+$/;
13334
13333
  function ne(t) {
13335
13334
  return Ut(t, 0, /* @__PURE__ */ new WeakSet());
13336
13335
  }
@@ -13361,17 +13360,17 @@ function Nr(t) {
13361
13360
  try {
13362
13361
  const e = new URL(t, location.href);
13363
13362
  for (const s of Array.from(e.searchParams.keys()))
13364
- Fl.test(s) && e.searchParams.set(s, ge);
13365
- return e.username && (e.username = ge), e.password && (e.password = ge), e.toString();
13363
+ Fl.test(s) && e.searchParams.set(s, me);
13364
+ return e.username && (e.username = me), e.password && (e.password = me), e.toString();
13366
13365
  } catch {
13367
13366
  return Kl(t);
13368
13367
  }
13369
13368
  }
13370
13369
  function Nt(t) {
13371
- return t.replace($l, Bl).replace(zl, Wl).replace(xr, `Bearer ${ge}`).replace(Mr, `Basic ${ge}`).replace(Pr, ge).replace(Dr, (e, s) => `${s}: ${Vt}`);
13370
+ return t.replace($l, Bl).replace(zl, Wl).replace(xr, `Bearer ${me}`).replace(Mr, `Basic ${me}`).replace(Pr, me).replace(Dr, (e, s) => `${s}: ${Vt}`);
13372
13371
  }
13373
13372
  function Kl(t) {
13374
- return t.replace(xr, `Bearer ${ge}`).replace(Mr, `Basic ${ge}`).replace(Pr, ge).replace(Dr, (e, s) => `${s}: ${Vt}`);
13373
+ return t.replace(xr, `Bearer ${me}`).replace(Mr, `Basic ${me}`).replace(Pr, me).replace(Dr, (e, s) => `${s}: ${Vt}`);
13375
13374
  }
13376
13375
  function Wl(t) {
13377
13376
  const e = t.match(Hl)?.[0] ?? "", s = e ? t.slice(0, -e.length) : t;
@@ -13397,7 +13396,7 @@ export {
13397
13396
  Ht as ProductAgentSessionEngine,
13398
13397
  Yl as ProductAgentSessionHistoryManager,
13399
13398
  tu as ProductAgentTaskPageTitleController,
13400
- le as ProductAgentTokenProviderError,
13399
+ ue as ProductAgentTokenProviderError,
13401
13400
  gd as calculateReconnectDelay,
13402
13401
  Jl as canSubmitPersonalProductAgentMessage,
13403
13402
  eu as createLocalStorageInteractionDecisionStorage,