@pluno/product-agent-web 0.1.277 → 0.1.278

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
- function Se(s, e) {
1
+ function Ie(s, e) {
2
2
  return e === "limit_exceeded" ? { allowed: !1, reason: "credits_exhausted", actions: ["upgrade", "earn_credits"] } : e === "subscription_required" || e === "subscription_inactive" || e === "payment_issue" || e === "subscription_invalid" || e === "payment_required" ? { allowed: !1, reason: "payment_issue", actions: ["upgrade"] } : s ?? { allowed: !0, reason: "allowed", actions: [] };
3
3
  }
4
- function b(s) {
4
+ function v(s) {
5
5
  return {
6
6
  key: s,
7
7
  status: "not_requested",
@@ -11,9 +11,9 @@ function b(s) {
11
11
  updatedAt: null
12
12
  };
13
13
  }
14
- class O {
14
+ class q {
15
15
  constructor(e, t, i = (n, r) => r) {
16
- this.loader = t, this.merge = i, this.state = b(e);
16
+ this.loader = t, this.merge = i, this.state = v(e);
17
17
  }
18
18
  loader;
19
19
  merge;
@@ -28,10 +28,10 @@ class O {
28
28
  return this.listeners.add(e), e(this.state), () => this.listeners.delete(e);
29
29
  }
30
30
  setKey(e) {
31
- e !== this.state.key && (this.state = b(e), this.trailingLoad = null, this.publish());
31
+ e !== this.state.key && (this.state = v(e), this.trailingLoad = null, this.publish());
32
32
  }
33
33
  reset() {
34
- this.state = b(this.state.key), this.trailingLoad = null, this.publish();
34
+ this.state = v(this.state.key), this.trailingLoad = null, this.publish();
35
35
  }
36
36
  invalidate() {
37
37
  this.state = {
@@ -86,7 +86,7 @@ class O {
86
86
  for (const e of this.listeners) e(this.state);
87
87
  }
88
88
  }
89
- function v(s) {
89
+ function _(s) {
90
90
  const e = {}, t = [];
91
91
  for (const i of s.entities)
92
92
  e[i.id] || t.push(i.id), e[i.id] = i;
@@ -106,21 +106,21 @@ function V(s, e, t) {
106
106
  function Z(s) {
107
107
  return s ? s.ids.map((e) => s.entitiesById[e]).filter((e) => !!e) : [];
108
108
  }
109
- function we(s) {
109
+ function Se(s) {
110
110
  return s.visible ? s.minimized ? { state: "minimized" } : { state: s.open ? "visible_open" : "visible_closed" } : { state: "hidden" };
111
111
  }
112
- function Ae(s) {
112
+ function we(s) {
113
113
  if (!s || typeof s != "object") return !1;
114
114
  const e = s.paidCreditFallbackModel;
115
115
  return typeof e == "string" && e.length > 0;
116
116
  }
117
- function Ee(s) {
117
+ function Ae(s) {
118
118
  return s ? s.submissionGate?.allowed === !1 ? ["credits_exhausted", "payment_issue", "onboarding_required"].includes(s.submissionGate.reason) ? { state: "action_required", reason: s.submissionGate.reason } : { state: "hidden" } : s.usingPaidCreditFallback === !0 ? { state: "paid_credit_fallback" } : s.creditLimit !== null && s.creditLimit > 0 && s.creditsRemaining !== null && s.creditsRemaining > 0 && s.creditsRemaining / s.creditLimit <= 0.2 ? { state: "low_credits" } : s.creditsUsed !== null ? { state: "usage" } : { state: "hidden" } : { state: "hidden" };
119
119
  }
120
120
  function Me(s) {
121
121
  return s.submissionAllowed && s.isAuthenticated && s.hasWorkspace && !s.isWebsiteBlocked && s.isCurrentPageResolved && !s.isSubmitting && !s.hasPendingMessage;
122
122
  }
123
- function Te(s) {
123
+ function Ee(s) {
124
124
  const e = s.hasDraftMessage || s.hasPreSubmittedAttachment;
125
125
  return s.hasRunningAssistantTurn && !e ? {
126
126
  action: "stop",
@@ -131,23 +131,23 @@ function Te(s) {
131
131
  };
132
132
  }
133
133
  const J = "Pluno is reconnecting. Try again in a moment.";
134
- function W(s) {
134
+ function O(s) {
135
135
  return (s instanceof Error ? s.message : s) === J;
136
136
  }
137
- class Pe {
137
+ class Te {
138
138
  constructor(e, t, i = 20) {
139
- this.loadPage = t, this.limit = i, this.recentQuery = new O(
139
+ this.loadPage = t, this.limit = i, this.recentQuery = new q(
140
140
  `${e}:recent`,
141
- async ({ cursor: n }) => v(
141
+ async ({ cursor: n }) => _(
142
142
  await this.loadPage({ cursor: n, limit: this.limit, pinned: !1 }).then((r) => ({
143
143
  entities: r.sessions,
144
144
  nextCursor: r.nextCursor
145
145
  }))
146
146
  ),
147
147
  V
148
- ), this.pinnedQuery = new O(
148
+ ), this.pinnedQuery = new q(
149
149
  `${e}:pinned`,
150
- async () => v({
150
+ async () => _({
151
151
  entities: await this.loadAllPinned(),
152
152
  nextCursor: null
153
153
  })
@@ -167,18 +167,18 @@ class Pe {
167
167
  activityReconciliationScheduled = !1;
168
168
  getState() {
169
169
  const e = this.recentQuery.getState(), t = this.pinnedQuery.getState(), i = [
170
- ...y(t.data),
171
- ...y(e.data)
170
+ ...b(t.data),
171
+ ...b(e.data)
172
172
  ], n = new Map(i.map((d) => [d.id, d])), r = Array.from(n.values()).map(
173
173
  (d) => this.applyOverrides(d, this.completedRefreshSequence)
174
- ), o = Array.from(this.optimisticEntities.values()).filter((d) => !n.has(d.id)).reverse(), a = e.data || t.data || o.length > 0 ? v({
175
- entities: [...o, ...r],
174
+ ), a = Array.from(this.optimisticEntities.values()).filter((d) => !n.has(d.id)).reverse(), o = e.data || t.data || a.length > 0 ? _({
175
+ entities: [...a, ...r],
176
176
  nextCursor: e.data?.nextCursor ?? null
177
177
  }) : null;
178
178
  return {
179
179
  key: e.key.slice(0, -7),
180
- status: Y(e, t),
181
- data: a,
180
+ status: W(e, t),
181
+ data: o,
182
182
  error: e.error ?? t.error,
183
183
  requestId: Math.max(e.requestId, t.requestId),
184
184
  updatedAt: Math.max(e.updatedAt ?? 0, t.updatedAt ?? 0) || null
@@ -243,8 +243,8 @@ class Pe {
243
243
  }
244
244
  reconcileDurableEntities() {
245
245
  const e = [
246
- ...y(this.pinnedQuery.getState().data),
247
- ...y(this.recentQuery.getState().data)
246
+ ...b(this.pinnedQuery.getState().data),
247
+ ...b(this.recentQuery.getState().data)
248
248
  ], t = new Set(e.map((i) => i.id));
249
249
  for (const i of this.optimisticEntities.keys())
250
250
  t.has(i) && this.optimisticEntities.delete(i);
@@ -283,10 +283,10 @@ class Pe {
283
283
  for (const e of this.listeners) e(this.getState());
284
284
  }
285
285
  }
286
- function y(s) {
286
+ function b(s) {
287
287
  return s ? s.ids.map((e) => s.entitiesById[e]).filter((e) => !!e) : [];
288
288
  }
289
- function Y(s, e) {
289
+ function W(s, e) {
290
290
  return s.status === "error" || e.status === "error" ? "error" : s.status === "loading" || e.status === "loading" ? "loading" : s.status === "refreshing" || e.status === "refreshing" ? "refreshing" : s.status === "loading_more" ? "loading_more" : s.status === "ready" || e.status === "ready" ? "ready" : "not_requested";
291
291
  }
292
292
  function R(s) {
@@ -294,33 +294,33 @@ function R(s) {
294
294
  if (!e) throw new Error("Display timestamps must retain the backend UTC precision.");
295
295
  return `${e[1]}.${(e[2] ?? "").padEnd(6, "0")}`;
296
296
  }
297
- function _(s) {
297
+ function I(s) {
298
298
  if (s === null || typeof s == "string" || typeof s == "boolean") return !0;
299
299
  if (typeof s == "number") return Number.isFinite(s);
300
- if (Array.isArray(s)) return s.every(_);
300
+ if (Array.isArray(s)) return s.every(I);
301
301
  if (typeof s != "object") return !1;
302
302
  const e = Object.getPrototypeOf(s);
303
- return e !== Object.prototype && e !== null ? !1 : Object.values(s).every(_);
303
+ return e !== Object.prototype && e !== null ? !1 : Object.values(s).every(I);
304
304
  }
305
- function $(s) {
306
- return s !== null && typeof s == "object" && !Object.isFrozen(s) && (Object.values(s).forEach($), Object.freeze(s)), s;
305
+ function z(s) {
306
+ return s !== null && typeof s == "object" && !Object.isFrozen(s) && (Object.values(s).forEach(z), Object.freeze(s)), s;
307
307
  }
308
- function X(s) {
309
- if (!_(s)) throw new Error("Conversation inputs must be JSON-safe values.");
308
+ function Y(s) {
309
+ if (!I(s)) throw new Error("Conversation inputs must be JSON-safe values.");
310
310
  return JSON.parse(JSON.stringify(s));
311
311
  }
312
- function ee(s, e) {
312
+ function X(s, e) {
313
313
  if (!e) return !1;
314
314
  const t = s.executionByUserMessage[e];
315
315
  if (t) return ["completed", "stopped", "failed"].includes(t.phase);
316
- const i = Object.values(s.items).sort((r, o) => R(r.created_at).localeCompare(R(o.created_at)) || r.id.localeCompare(o.id));
316
+ const i = Object.values(s.items).sort((r, a) => R(r.created_at).localeCompare(R(a.created_at)) || r.id.localeCompare(a.id));
317
317
  let n = !1;
318
318
  for (const r of i)
319
319
  if (r.type === "user_message" && (n = r.id === e), !!n && (r.type === "stopped" || r.type === "error" || r.type === "final_response" && s.streams[r.id]?.state === "finished" && s.streams[r.id].revision >= r.data.revision))
320
320
  return !0;
321
321
  return !1;
322
322
  }
323
- class ke {
323
+ class Pe {
324
324
  constructor(e, t = null) {
325
325
  this.storage = e, t && (this.decisions = new Map(
326
326
  t.filter(E).map((i) => [this.getDecisionKey(i), i])
@@ -344,8 +344,8 @@ class ke {
344
344
  const i = JSON.stringify([t.conversation_id, t.id]), n = this.sources.get(i);
345
345
  if (n && n.version >= t.version) continue;
346
346
  if (n && n.payload.kind !== t.payload.kind) throw new Error("Interaction kind changed.");
347
- const r = n?.payload.kind === "personal_channel" && n.lifecycle === "completed" ? "completed" : t.lifecycle, o = n?.payload.kind === "sharing" && t.payload.kind === "sharing" ? { ...t.payload, variant: n.payload.variant } : t.payload;
348
- this.sources.set(i, $(X({ ...t, lifecycle: r, payload: o }))), t.payload.kind === "integration_auth" && this.invalidateAuth(t.payload.request_id);
347
+ const r = n?.payload.kind === "personal_channel" && n.lifecycle === "completed" ? "completed" : t.lifecycle, a = n?.payload.kind === "sharing" && t.payload.kind === "sharing" ? { ...t.payload, variant: n.payload.variant } : t.payload;
348
+ this.sources.set(i, z(Y({ ...t, lifecycle: r, payload: a }))), t.payload.kind === "integration_auth" && this.invalidateAuth(t.payload.request_id);
349
349
  }
350
350
  }
351
351
  /** @internal */
@@ -357,38 +357,38 @@ class ke {
357
357
  if (!this.conversationReader) return;
358
358
  const t = { share: null, integrations: [], channel: null }, i = e ? this.conversationReader(e) : null;
359
359
  if (!i) return t;
360
- const n = [...this.sources.values()].filter((r) => r.conversation_id === e).sort((r, o) => r.version - o.version || r.id.localeCompare(o.id));
360
+ const n = [...this.sources.values()].filter((r) => r.conversation_id === e).sort((r, a) => r.version - a.version || r.id.localeCompare(a.id));
361
361
  for (const r of n) {
362
- const o = r.payload;
363
- if (o.kind === "sharing") {
364
- if (t.share = null, !o.eligible || r.lifecycle !== "pending" || r.invocation !== "user" || !["main_web_chat", "automation", "extension_sidepanel", "extension_widget"].includes(r.entry_surface ?? "")) continue;
365
- const a = r.user_message_id ? i.items[r.user_message_id] : null;
362
+ const a = r.payload;
363
+ if (a.kind === "sharing") {
364
+ if (t.share = null, !a.eligible || r.lifecycle !== "pending" || r.invocation !== "user" || !["main_web_chat", "automation", "extension_sidepanel", "extension_widget"].includes(r.entry_surface ?? "")) continue;
365
+ const o = r.user_message_id ? i.items[r.user_message_id] : null;
366
366
  t.share = {
367
367
  revision: r.version,
368
368
  candidate: {
369
369
  id: r.id,
370
- variant: o.variant,
371
- userPrompt: a?.type === "user_message" ? a.data.content : "",
370
+ variant: a.variant,
371
+ userPrompt: o?.type === "user_message" ? o.data.content : "",
372
372
  assistantAnswer: ""
373
373
  },
374
- terminal: !o.wait_for_terminal || ee(i, r.user_message_id)
374
+ terminal: !a.wait_for_terminal || X(i, r.user_message_id)
375
375
  };
376
- } else o.kind === "integration_auth" ? t.integrations.push({
376
+ } else a.kind === "integration_auth" ? t.integrations.push({
377
377
  revision: r.version,
378
378
  request: {
379
379
  type: "pipedream_auth_required",
380
- authRequestId: o.request_id,
381
- appSlug: o.app_slug,
382
- appName: o.app_name,
383
- appLogo: o.app_logo ?? void 0,
384
- expiresAt: o.expires_at
380
+ authRequestId: a.request_id,
381
+ appSlug: a.app_slug,
382
+ appName: a.app_name,
383
+ appLogo: a.app_logo ?? void 0,
384
+ expiresAt: a.expires_at
385
385
  },
386
- lifecycle: r.lifecycle === "pending" && Date.parse(o.expires_at) <= Date.now() ? "expired" : r.lifecycle
386
+ lifecycle: r.lifecycle === "pending" && Date.parse(a.expires_at) <= Date.now() ? "expired" : r.lifecycle
387
387
  }) : t.channel = { revision: r.version, request: {
388
388
  type: "personal_channel_connection_required",
389
- requestId: o.request_id,
390
- channel: o.channel,
391
- managementUrl: o.management_url
389
+ requestId: a.request_id,
390
+ channel: a.channel,
391
+ managementUrl: a.management_url
392
392
  }, lifecycle: r.lifecycle };
393
393
  }
394
394
  return t;
@@ -437,7 +437,7 @@ class ke {
437
437
  async applyAction(e, t, i) {
438
438
  if (!e.allowedActions.includes(t))
439
439
  throw new Error(`Interaction ${e.key} does not allow ${t}.`);
440
- if (!K(t))
440
+ if (!$(t))
441
441
  throw new Error(`Interaction action ${t} is not a persistence decision.`);
442
442
  const n = i.now ?? /* @__PURE__ */ new Date(), r = {
443
443
  promptKey: e.key,
@@ -446,8 +446,8 @@ class ke {
446
446
  scope: e.scope,
447
447
  decidedAt: n.toISOString(),
448
448
  nextEligibleAt: this.getNextEligibleAt(e, t, n, i.snoozeUntil)
449
- }, o = t === "dont_show_again" ? this.getCategoryKey(e) : this.getExactKey(e), a = new Map(this.decisions);
450
- return a.set(o, r), await this.storage.save([...a.values()]), this.decisions = a, r;
449
+ }, a = t === "dont_show_again" ? this.getCategoryKey(e) : this.getExactKey(e), o = new Map(this.decisions);
450
+ return o.set(a, r), await this.storage.save([...o.values()]), this.decisions = o, r;
451
451
  }
452
452
  isDecisionEligible(e, t) {
453
453
  return e ? e.action === "dismiss" || e.action === "never" || e.action === "dont_show_again" ? !1 : !e.nextEligibleAt || Date.parse(e.nextEligibleAt) <= t : !0;
@@ -463,51 +463,51 @@ class ke {
463
463
  return null;
464
464
  }
465
465
  getDecisionKey(e) {
466
- const t = S(e.scope);
466
+ const t = w(e.scope);
467
467
  return e.action === "dont_show_again" ? `${t}:category:${e.category}` : `${t}:interaction:${e.promptKey}`;
468
468
  }
469
469
  getExactKey(e) {
470
- return `${S(e.scope)}:interaction:${e.key}`;
470
+ return `${w(e.scope)}:interaction:${e.key}`;
471
471
  }
472
472
  getCategoryKey(e) {
473
- return `${S(e.scope)}:category:${e.category}`;
473
+ return `${w(e.scope)}:category:${e.category}`;
474
474
  }
475
475
  }
476
- function qe(s, e) {
476
+ function ke(s, e) {
477
477
  return {
478
- load: async () => te(s, e),
478
+ load: async () => ee(s, e),
479
479
  save: async (t) => s.setItem(e, JSON.stringify(t))
480
480
  };
481
481
  }
482
- function te(s, e) {
482
+ function ee(s, e) {
483
483
  const t = s.getItem(e);
484
484
  if (!t) return [];
485
485
  const i = JSON.parse(t);
486
486
  return Array.isArray(i) ? i.filter(E) : [];
487
487
  }
488
- function S(s) {
488
+ function w(s) {
489
489
  return `${s.level}:${s.key}`;
490
490
  }
491
- function K(s) {
491
+ function $(s) {
492
492
  return s === "dismiss" || s === "later" || s === "snooze" || s === "never" || s === "dont_show_again";
493
493
  }
494
494
  function E(s) {
495
495
  if (!s || typeof s != "object") return !1;
496
496
  const e = s;
497
- return typeof e.promptKey == "string" && typeof e.category == "string" && typeof e.decidedAt == "string" && (e.nextEligibleAt === null || typeof e.nextEligibleAt == "string") && K(e.action) && !!(e.scope && typeof e.scope == "object" && typeof e.scope.level == "string" && typeof e.scope.key == "string");
497
+ return typeof e.promptKey == "string" && typeof e.category == "string" && typeof e.decidedAt == "string" && (e.nextEligibleAt === null || typeof e.nextEligibleAt == "string") && $(e.action) && !!(e.scope && typeof e.scope == "object" && typeof e.scope.level == "string" && typeof e.scope.key == "string");
498
498
  }
499
- const se = {
499
+ const te = {
500
500
  working: "⏳",
501
501
  completed: "✅",
502
502
  failed: "❗",
503
503
  stopped: "⏹️"
504
- }, ie = /^(?:⌛|⏳|✅|❗|⏹️) Pluno(?:: )?/;
505
- function ne(s, e) {
506
- if (!e) return I(s);
507
- const t = I(s), i = `${se[e]} Pluno`;
504
+ }, se = /^(?:⌛|⏳|✅|❗|⏹️) Pluno(?:: )?/;
505
+ function ie(s, e) {
506
+ if (!e) return S(s);
507
+ const t = S(s), i = `${te[e]} Pluno`;
508
508
  return t ? `${i}: ${t}` : i;
509
509
  }
510
- class Oe {
510
+ class qe {
511
511
  constructor(e) {
512
512
  this.titleDocument = e;
513
513
  }
@@ -529,10 +529,10 @@ class Oe {
529
529
  }
530
530
  applyStatus(e) {
531
531
  const t = this.titleDocument.getTitle();
532
- t !== this.lastAppliedTitle && (this.baseTitle = I(t)), this.status = e, this.stopObserving || (this.stopObserving = this.titleDocument.observeTitle(() => this.handleTitleChanged())), this.applyTitle();
532
+ t !== this.lastAppliedTitle && (this.baseTitle = S(t)), this.status = e, this.stopObserving || (this.stopObserving = this.titleDocument.observeTitle(() => this.handleTitleChanged())), this.applyTitle();
533
533
  }
534
534
  applyClear() {
535
- const e = this.titleDocument.getTitle(), t = this.lastAppliedTitle !== null && e === this.lastAppliedTitle, i = this.lastAppliedTitle === null ? I(e) : e;
535
+ const e = this.titleDocument.getTitle(), t = this.lastAppliedTitle !== null && e === this.lastAppliedTitle, i = this.lastAppliedTitle === null ? S(e) : e;
536
536
  this.status = null, this.lastAppliedTitle = null, this.stopObserving?.(), this.stopObserving = null, t ? this.titleDocument.setTitle(this.baseTitle) : i !== e && this.titleDocument.setTitle(i);
537
537
  }
538
538
  handleTitleChanged() {
@@ -541,11 +541,11 @@ class Oe {
541
541
  applyTitle() {
542
542
  if (!this.status)
543
543
  return;
544
- const e = ne(this.baseTitle, this.status);
544
+ const e = ie(this.baseTitle, this.status);
545
545
  this.lastAppliedTitle = e, this.titleDocument.getTitle() !== e && this.titleDocument.setTitle(e);
546
546
  }
547
547
  }
548
- function Re(s) {
548
+ function Oe(s) {
549
549
  return {
550
550
  getTitle: () => s.title,
551
551
  setTitle: (e) => {
@@ -561,13 +561,13 @@ function Re(s) {
561
561
  }
562
562
  };
563
563
  }
564
- function I(s) {
565
- return s.replace(ie, "");
564
+ function S(s) {
565
+ return s.replace(se, "");
566
566
  }
567
- const re = "0.1.277", oe = {
568
- version: re
567
+ const ne = "0.1.278", re = {
568
+ version: ne
569
569
  }, p = (s) => typeof s == "string" && /^[a-zA-Z0-9:_.-]{1,160}$/.test(s) ? s : null;
570
- function ae(s) {
570
+ function oe(s) {
571
571
  if (!s || typeof s != "object") return !1;
572
572
  const e = s, t = (n) => Number.isSafeInteger(n) && n >= 0, i = (n) => n && typeof n == "object" && Object.keys(n).every((r) => ["sequence", "at", "type", "changed", "generation", "sessionId", "scopeId", "requestId", "effectId", "clientScopeId", "reason", "effectKind", "eventType", "itemCount", "removedCount", "projectionReady"].includes(r)) && t(n.sequence) && t(n.at) && p(n.type) !== null && typeof n.changed == "boolean" && [n.generation, n.itemCount, n.removedCount].every((r) => r === null || t(r)) && [n.sessionId, n.scopeId, n.requestId, n.effectId, n.clientScopeId, n.reason, n.effectKind, n.eventType].every((r) => r === null || p(r) !== null) && (n.projectionReady === null || typeof n.projectionReady == "boolean");
573
573
  return Object.keys(e).every((n) => ["ownerId", "revision", "dropped", "lastIntent", "lastSelection", "transitions"].includes(n)) && p(e.ownerId) !== null && t(e.revision) && t(e.dropped) && (e.lastIntent == null || i(e.lastIntent)) && (e.lastSelection === null || i(e.lastSelection)) && Array.isArray(e.transitions) && e.transitions.length <= 16 && e.transitions.every(i);
@@ -577,23 +577,23 @@ function U(s) {
577
577
  const e = s;
578
578
  return Object.keys(e).every((t) => ["sessionId", "episodeId", "consecutiveFailures", "transportCode", "requestId", "durationMs"].includes(t)) && typeof e.sessionId == "string" && /^[a-zA-Z0-9:_-]{1,160}$/.test(e.sessionId) && typeof e.episodeId == "string" && /^[a-zA-Z0-9:_-]{1,500}$/.test(e.episodeId) && (e.transportCode === void 0 || typeof e.transportCode == "string" && /^[a-z0-9_]{1,80}$/.test(e.transportCode)) && (e.requestId === void 0 || typeof e.requestId == "string" && /^[a-zA-Z0-9_-]{1,160}$/.test(e.requestId)) && (e.durationMs === void 0 || typeof e.durationMs == "number" && Number.isFinite(e.durationMs) && e.durationMs >= 0) && Number.isSafeInteger(e.consecutiveFailures) && e.consecutiveFailures >= 1;
579
579
  }
580
- const C = ["messageKeys", "canonicalItemKeys", "terminalResponseKeys", "toolCallKeys", "activeResponseKeys"], M = (s) => typeof s == "string" && /^[a-zA-Z0-9:_-]{1,160}$/.test(s), h = (s) => s === null || M(s), de = (s) => typeof s == "string" && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,6})?(?:Z|\+00:00)$/.test(s) && Number.isFinite(Date.parse(s));
580
+ const C = ["messageKeys", "canonicalItemKeys", "terminalResponseKeys", "toolCallKeys", "activeResponseKeys"], T = (s) => typeof s == "string" && /^[a-zA-Z0-9:_-]{1,160}$/.test(s), f = (s) => s === null || T(s), ae = (s) => typeof s == "string" && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,6})?(?:Z|\+00:00)$/.test(s) && Number.isFinite(Date.parse(s));
581
581
  function L(s) {
582
582
  if (!s || typeof s != "object") return !1;
583
583
  const e = s;
584
- return Object.keys(s).every((t) => ["sessionId", "itemId", "userMessageId", "createdAt", "runId", "retryable"].includes(t)) && h(e.sessionId) && M(e.itemId) && h(e.userMessageId) && (e.retryable === void 0 || typeof e.retryable == "boolean") && h(e.runId) && (e.createdAt === null || de(e.createdAt));
584
+ return Object.keys(s).every((t) => ["sessionId", "itemId", "userMessageId", "createdAt", "runId", "retryable"].includes(t)) && f(e.sessionId) && T(e.itemId) && f(e.userMessageId) && (e.retryable === void 0 || typeof e.retryable == "boolean") && f(e.runId) && (e.createdAt === null || ae(e.createdAt));
585
585
  }
586
586
  function ce(s) {
587
587
  if (!s || typeof s != "object") return !1;
588
588
  const e = s, t = (i) => Number.isSafeInteger(i) && i >= 0;
589
- return Object.keys(e).every((i) => ["capturedAt", "selectionKey", "userId", "loading", "draft", "thinking", "connected", "hasError", "phase", "queryStatus", "queryRequestId", "queryUpdatedAt", "renderSource", "selectionFencePending", "guardCreatedAt", "owner", "sdkVersion", "presentationGate", "firstObservedAt", "confirmationMs"].includes(i)) && t(e.capturedAt) && [e.queryUpdatedAt, e.guardCreatedAt].every((i) => i === null || t(i)) && [e.selectionKey, e.userId, e.phase, e.queryStatus, e.queryRequestId].every((i) => i === null || p(i) !== null) && [e.loading, e.draft, e.thinking, e.connected, e.hasError, e.selectionFencePending].every((i) => typeof i == "boolean") && ["state", "account", "interactions", "local", "sidepanel_layout", "observer"].includes(e.renderSource) && (e.owner === void 0 || ae(e.owner)) && (e.sdkVersion === void 0 || typeof e.sdkVersion == "string" && e.sdkVersion.length <= 32 && /^\d+\.\d+\.\d+(?:[-+][a-zA-Z0-9.-]+)?$/.test(e.sdkVersion)) && (e.presentationGate === void 0 || ["none", "authentication", "signup"].includes(e.presentationGate)) && [e.firstObservedAt, e.confirmationMs].every((i) => i === void 0 || t(i));
589
+ return Object.keys(e).every((i) => ["capturedAt", "selectionKey", "userId", "loading", "draft", "thinking", "connected", "hasError", "phase", "queryStatus", "queryRequestId", "queryUpdatedAt", "renderSource", "selectionFencePending", "guardCreatedAt", "owner", "sdkVersion", "presentationGate", "firstObservedAt", "confirmationMs"].includes(i)) && t(e.capturedAt) && [e.queryUpdatedAt, e.guardCreatedAt].every((i) => i === null || t(i)) && [e.selectionKey, e.userId, e.phase, e.queryStatus, e.queryRequestId].every((i) => i === null || p(i) !== null) && [e.loading, e.draft, e.thinking, e.connected, e.hasError, e.selectionFencePending].every((i) => typeof i == "boolean") && ["state", "account", "interactions", "local", "sidepanel_layout", "observer"].includes(e.renderSource) && (e.owner === void 0 || oe(e.owner)) && (e.sdkVersion === void 0 || typeof e.sdkVersion == "string" && e.sdkVersion.length <= 32 && /^\d+\.\d+\.\d+(?:[-+][a-zA-Z0-9.-]+)?$/.test(e.sdkVersion)) && (e.presentationGate === void 0 || ["none", "authentication", "signup"].includes(e.presentationGate)) && [e.firstObservedAt, e.confirmationMs].every((i) => i === void 0 || t(i));
590
590
  }
591
591
  function F(s) {
592
592
  if (!s || typeof s != "object" || Object.keys(s).some((i) => i !== "before" && i !== "current")) return !1;
593
593
  const e = (i) => {
594
594
  if (!i || typeof i != "object") return !1;
595
595
  const n = i;
596
- return Object.keys(i).every((r) => [...C, "sessionId", "runtimeItemCount", "welcome", "truncated", "thinkingSequence", "context", "duplicateToolCalls"].includes(r)) && (n.duplicateToolCalls === void 0 || Array.isArray(n.duplicateToolCalls) && n.duplicateToolCalls.length <= 5 && n.duplicateToolCalls.every((r) => r && Object.keys(r).every((o) => ["key", "count", "rows", "truncated"].includes(o)) && h(r.key) && Number.isSafeInteger(r.count) && r.count >= 2 && typeof r.truncated == "boolean" && Array.isArray(r.rows) && r.rows.length >= 1 && r.rows.length <= 5 && r.rows.length <= r.count && r.rows.every((o) => o && Object.keys(o).every((a) => ["itemId", "groupId"].includes(a)) && h(o.itemId) && h(o.groupId)))) && (n.context === void 0 || ce(n.context)) && (n.thinkingSequence === void 0 || Array.isArray(n.thinkingSequence) && n.thinkingSequence.length <= 20 && n.thinkingSequence.every((r) => r === "user" || r === "thinking")) && h(n.sessionId) && Number.isSafeInteger(n.runtimeItemCount) && n.runtimeItemCount >= 0 && typeof n.welcome == "boolean" && typeof n.truncated == "boolean" && C.every((r) => Array.isArray(n[r]) && n[r].length <= 20 && n[r].every(M));
596
+ return Object.keys(i).every((r) => [...C, "sessionId", "runtimeItemCount", "welcome", "truncated", "thinkingSequence", "context", "duplicateToolCalls"].includes(r)) && (n.duplicateToolCalls === void 0 || Array.isArray(n.duplicateToolCalls) && n.duplicateToolCalls.length <= 5 && n.duplicateToolCalls.every((r) => r && Object.keys(r).every((a) => ["key", "count", "rows", "truncated"].includes(a)) && f(r.key) && Number.isSafeInteger(r.count) && r.count >= 2 && typeof r.truncated == "boolean" && Array.isArray(r.rows) && r.rows.length >= 1 && r.rows.length <= 5 && r.rows.length <= r.count && r.rows.every((a) => a && Object.keys(a).every((o) => ["itemId", "groupId"].includes(o)) && f(a.itemId) && f(a.groupId)))) && (n.context === void 0 || ce(n.context)) && (n.thinkingSequence === void 0 || Array.isArray(n.thinkingSequence) && n.thinkingSequence.length <= 20 && n.thinkingSequence.every((r) => r === "user" || r === "thinking")) && f(n.sessionId) && Number.isSafeInteger(n.runtimeItemCount) && n.runtimeItemCount >= 0 && typeof n.welcome == "boolean" && typeof n.truncated == "boolean" && C.every((r) => Array.isArray(n[r]) && n[r].length <= 20 && n[r].every(T));
597
597
  }, t = s;
598
598
  return (t.before === null || e(t.before)) && e(t.current);
599
599
  }
@@ -602,35 +602,35 @@ function G(s) {
602
602
  const e = s.replace(/\n\s*at\s[\s\S]*$/, "").replace(/-----BEGIN [^-]*PRIVATE KEY-----[\s\S]*?(?:-----END [^-]*PRIVATE KEY-----|$)/g, "[REDACTED]").replace(/\b(?:set-cookie|cookie)\s*[:=]\s*[^\n]+/gi, "cookie=[REDACTED]").replace(/\bdata:[^\s<>"']+/gi, "[DATA]").replace(/\b(?:https?:\/\/|www\.)[^\s<>"']+/gi, "[URL]").replace(/\b(?:Bearer|Basic)\s+[^\s,;"']+/gi, "[REDACTED]").replace(/\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+)?/g, "[REDACTED]").replace(/\b(?:sk|pk|ghp|gho|github_pat|xoxb|xoxp)[-_][A-Za-z0-9_-]{8,}/g, "[REDACTED]").replace(/\b((?:access|refresh|id|auth)[_-]?token|api[_-]?key|client[_-]?secret|password|passwd|pwd|secret|token|jwt|authorization|cookie|set-cookie)\b["']?\s*[:=]\s*(?:"[^"]*"|'[^']*'|[^\s,;}&]+)/gi, "$1=[REDACTED]").replace(/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}/gi, "[EMAIL]").replace(/(?:[A-Z]:[\\/]|\\\\|(?:~|\.\.?)?\/|[\w.-]+[\\/])[^\s<>"']+/gi, "[FILE]").replace(new RegExp("(?<![\\w.])(?:[\\w.-]+\\.[A-Z][A-Z0-9]{0,15}|\\.[A-Z][\\w.-]*)\\b", "gi"), "[FILE]").replace(/\s+/g, " ").trim();
603
603
  return e.length > x ? `${e.slice(0, x - 1)}…` : e;
604
604
  }
605
- function le(s) {
605
+ function de(s) {
606
606
  let e = 2166136261;
607
607
  for (let t = 0; t < s.length; t += 1)
608
608
  e ^= s.charCodeAt(t), e = Math.imul(e, 16777619);
609
609
  return `fnv1a-${(e >>> 0).toString(16).padStart(8, "0")}`;
610
610
  }
611
- function T(s) {
611
+ function P(s) {
612
612
  if (!s || typeof s != "object") return !1;
613
613
  const e = s;
614
614
  return Object.keys(s).every((t) => ["boundary", "category", "messageKind"].includes(t)) && ["runtime", "web_transport", "extension_ipc"].includes(e.boundary) && ["error", "object", "null", "array", "string", "undefined", "number", "boolean", "bigint", "symbol", "function"].includes(e.category) && ["object_coercion", "text", "blank", "non_text"].includes(e.messageKind);
615
615
  }
616
- function ue(s) {
616
+ function le(s) {
617
617
  if (!s || typeof s != "object") return !1;
618
618
  const e = s;
619
- return Object.keys(e).every((t) => ["sessionId", "requestId", "code", "normalization", "builds", "clientMessageId"].includes(t)) && (e.clientMessageId === void 0 || p(e.clientMessageId) !== null) && [e.sessionId, e.requestId, e.code].every((t) => t === null || p(t) !== null) && (e.normalization === void 0 || T(e.normalization)) && !!e.builds && typeof e.builds == "object" && typeof e.builds.sdk == "string" && Object.entries(e.builds).every(([t, i]) => ["sdk", "rendererExtension", "contentExtension", "backgroundExtension"].includes(t) && typeof i == "string" && /^\d{1,5}\.\d{1,5}\.\d{1,5}$/.test(i));
619
+ return Object.keys(e).every((t) => ["sessionId", "requestId", "code", "normalization", "builds", "clientMessageId"].includes(t)) && (e.clientMessageId === void 0 || p(e.clientMessageId) !== null) && [e.sessionId, e.requestId, e.code].every((t) => t === null || p(t) !== null) && (e.normalization === void 0 || P(e.normalization)) && !!e.builds && typeof e.builds == "object" && typeof e.builds.sdk == "string" && Object.entries(e.builds).every(([t, i]) => ["sdk", "rendererExtension", "contentExtension", "backgroundExtension"].includes(t) && typeof i == "string" && /^\d{1,5}\.\d{1,5}\.\d{1,5}$/.test(i));
620
620
  }
621
- function pe(s, e, t, i, n = {}) {
622
- const r = !i && e === "conversation_error" && t !== void 0 && s.conversationDiagnostics?.errorMessageFingerprint === le(G(t)) ? s.conversationDiagnostics : void 0;
621
+ function ue(s, e, t, i, n = {}) {
622
+ const r = !i && e === "conversation_error" && t !== void 0 && s.conversationDiagnostics?.errorMessageFingerprint === de(G(t)) ? s.conversationDiagnostics : void 0;
623
623
  return {
624
624
  sessionId: p(s.sessionId),
625
625
  requestId: p(r?.httpRequest?.requestId ?? r?.errorRequestId ?? r?.queryRequestId),
626
626
  ...p(r?.failedClientMessageId) ? { clientMessageId: r.failedClientMessageId } : {},
627
627
  code: r ? p(s.lastErrorCode) : null,
628
- ...T(r?.errorNormalization) ? { normalization: r.errorNormalization } : {},
629
- builds: { sdk: oe.version, ...n }
628
+ ...P(r?.errorNormalization) ? { normalization: r.errorNormalization } : {},
629
+ builds: { sdk: re.version, ...n }
630
630
  };
631
631
  }
632
- function he(s) {
633
- if (s.details !== void 0 && !_(s.details))
632
+ function pe(s) {
633
+ if (s.details !== void 0 && !I(s.details))
634
634
  throw new TypeError("Product Agent transported error details must be JSON-safe.");
635
635
  return {
636
636
  code: s.code,
@@ -639,24 +639,24 @@ function he(s) {
639
639
  ...s.details === void 0 ? {} : { details: s.details }
640
640
  };
641
641
  }
642
- function g(s, e = "runtime_error", t = "runtime") {
643
- const i = s !== null && typeof s == "object" ? s : null, n = typeof s == "string" ? s : i && "message" in i && typeof i.message == "string" ? i.message : "", r = i && "code" in i && typeof i.code == "string" && i.code.trim() ? i.code : e, o = i && "details" in i ? i.details : null, a = o && typeof o == "object" ? o : {}, d = {
644
- ...typeof a.httpStatus == "number" && Number.isInteger(a.httpStatus) && a.httpStatus >= 100 && a.httpStatus <= 599 ? { httpStatus: a.httpStatus } : {},
642
+ function m(s, e = "runtime_error", t = "runtime") {
643
+ const i = s !== null && typeof s == "object" ? s : null, n = typeof s == "string" ? s : i && "message" in i && typeof i.message == "string" ? i.message : "", r = i && "code" in i && typeof i.code == "string" && i.code.trim() ? i.code : e, a = i && "details" in i ? i.details : null, o = a && typeof a == "object" ? a : {}, d = {
644
+ ...typeof o.httpStatus == "number" && Number.isInteger(o.httpStatus) && o.httpStatus >= 100 && o.httpStatus <= 599 ? { httpStatus: o.httpStatus } : {},
645
645
  // Preserve the first boundary's shape after normalization replaces the original message/prototype.
646
- errorNormalization: T(a.errorNormalization) ? a.errorNormalization : {
646
+ errorNormalization: P(o.errorNormalization) ? o.errorNormalization : {
647
647
  boundary: t,
648
648
  category: s instanceof Error ? "error" : s === null ? "null" : Array.isArray(s) ? "array" : typeof s,
649
649
  messageKind: n.trim() === "[object Object]" ? "object_coercion" : n.trim() ? "text" : typeof s == "string" || i && "message" in i && typeof i.message == "string" ? "blank" : "non_text"
650
650
  },
651
- ...a.allocation === "unissued" ? { allocation: "unissued" } : {},
652
- ...["unissued", "rejected"].includes(String(a.acceptance)) ? { acceptance: String(a.acceptance) } : {},
653
- ...typeof a.securitySettingsUrl == "string" ? { securitySettingsUrl: a.securitySettingsUrl } : {},
654
- ...typeof a.transportCode == "string" && /^[a-z0-9_]{1,80}$/.test(a.transportCode) ? { transportCode: a.transportCode } : {},
655
- ...typeof a.requestId == "string" && /^[a-zA-Z0-9_-]{1,160}$/.test(a.requestId) ? { requestId: a.requestId } : {},
656
- ...typeof a.durationMs == "number" && Number.isFinite(a.durationMs) && a.durationMs >= 0 ? { durationMs: a.durationMs } : {},
657
- ...typeof a.successfulRequests == "number" && Number.isSafeInteger(a.successfulRequests) && a.successfulRequests >= 0 ? { successfulRequests: a.successfulRequests } : {}
651
+ ...o.allocation === "unissued" ? { allocation: "unissued" } : {},
652
+ ...["unissued", "rejected"].includes(String(o.acceptance)) ? { acceptance: String(o.acceptance) } : {},
653
+ ...typeof o.securitySettingsUrl == "string" ? { securitySettingsUrl: o.securitySettingsUrl } : {},
654
+ ...typeof o.transportCode == "string" && /^[a-z0-9_]{1,80}$/.test(o.transportCode) ? { transportCode: o.transportCode } : {},
655
+ ...typeof o.requestId == "string" && /^[a-zA-Z0-9_-]{1,160}$/.test(o.requestId) ? { requestId: o.requestId } : {},
656
+ ...typeof o.durationMs == "number" && Number.isFinite(o.durationMs) && o.durationMs >= 0 ? { durationMs: o.durationMs } : {},
657
+ ...typeof o.successfulRequests == "number" && Number.isSafeInteger(o.successfulRequests) && o.successfulRequests >= 0 ? { successfulRequests: o.successfulRequests } : {}
658
658
  };
659
- return he({
659
+ return pe({
660
660
  code: r,
661
661
  message: n.trim() && n.trim() !== "[object Object]" ? n : "The Product Agent operation failed. Try again.",
662
662
  retryable: !!(i && "retryable" in i && i.retryable === !0),
@@ -687,7 +687,7 @@ function B(s) {
687
687
  "upstreamTraceId"
688
688
  ].includes(i)) && p(e.requestId) !== null && ["GET", "POST", "PUT", "PATCH", "DELETE"].includes(e.method) && ["/api/product-agent/conversations/:sessionId/snapshot", "/api/product-agent/:namespace/commands", "/api/product-agent/:namespace/:operation"].includes(e.route) && (e.status === null || t(e.status) && e.status >= 100 && e.status <= 599) && (e.abortTrigger === null || ["deadline", "transport_disposed", "owner_disposed", "authority_retired", "observation_released", "request_replaced", "caller_cancelled", "unexpected_abort"].includes(e.abortTrigger)) && ["http_deadline", "http_transport", "conversation_query", "browser", "http_response"].includes(e.owner) && (e.category === void 0 || /^[a-z0-9_]{1,80}$/.test(e.category)) && [e.responseHeadersMs, e.responseBodyMs].every((i) => i == null || t(i)) && t(e.elapsedMs) && t(e.attempt) && e.attempt >= 1 && e.attempt <= 10 && [e.queryRequestId, e.ownerId, e.sessionId].every((i) => i === null || p(i) !== null) && (e.authorityGeneration === null || t(e.authorityGeneration)) && typeof e.release == "string" && /^[a-zA-Z0-9._-]{1,80}$/.test(e.release) && [e.upstreamRequestId, e.upstreamTraceId].every((i) => i === null || typeof i == "string" && /^[a-zA-Z0-9_:;=./-]{1,160}$/.test(i));
689
689
  }
690
- const ge = [
690
+ const he = [
691
691
  "submit",
692
692
  "stop",
693
693
  "staging_ipc",
@@ -766,17 +766,17 @@ const ge = [
766
766
  "backend_refusal",
767
767
  "unknown"
768
768
  ];
769
- function fe(s) {
769
+ function ge(s) {
770
770
  const e = s, t = e?.code;
771
771
  return e?.backendRefusal === !0 ? "backend_refusal" : typeof t == "string" && t !== "backend_refusal" && Q.includes(t) ? t : e?.name === "AbortError" ? "aborted" : e?.name === "TypeError" ? "type_error" : "unknown";
772
772
  }
773
773
  const H = Math.random().toString(36).slice(2);
774
- let me = 0;
775
- const D = () => `timing:${H}:${++me}`, m = (s) => typeof s == "string" && /^[a-zA-Z0-9:_-]{1,160}$/.test(s);
776
- function P(s) {
774
+ let fe = 0;
775
+ const D = () => `timing:${H}:${++fe}`, y = (s) => typeof s == "string" && /^[a-zA-Z0-9:_-]{1,160}$/.test(s);
776
+ function k(s) {
777
777
  if (!s || typeof s != "object") return !1;
778
778
  const e = s;
779
- return Object.keys(e).every((t) => ["entrySurface", "operation", "layer", "stage", "status", "spanId", "requestId", "clientMessageId", "sessionId", "occurredAt", "durationMs", "failureCategory", "tabId", "queueDepth", "workerId"].includes(t)) && (e.tabId === void 0 || Number.isSafeInteger(e.tabId) && e.tabId >= 0) && (e.queueDepth === void 0 || Number.isSafeInteger(e.queueDepth) && e.queueDepth >= 0) && (e.workerId === void 0 || m(e.workerId)) && (e.failureCategory === void 0 || e.status === "failed" && Q.includes(e.failureCategory)) && (e.entrySurface === void 0 || ["extension_sidepanel", "extension_widget", "main_web_chat", "embedded_widget", "embedded_custom_ui", "automation", "mcp", "whatsapp", "email"].includes(e.entrySurface)) && ["send", "stop"].includes(e.operation) && ["renderer", "sdk", "extension", "http"].includes(e.layer) && ge.includes(e.stage) && ["started", "completed", "failed", "observed"].includes(e.status) && m(e.spanId) && m(e.requestId) && (e.clientMessageId === null || m(e.clientMessageId)) && (e.sessionId === null || m(e.sessionId)) && typeof e.occurredAt == "string" && e.occurredAt.length <= 40 && Number.isFinite(Date.parse(e.occurredAt)) && Number.isSafeInteger(e.durationMs) && e.durationMs >= 0;
779
+ return Object.keys(e).every((t) => ["entrySurface", "operation", "layer", "stage", "status", "spanId", "requestId", "clientMessageId", "sessionId", "occurredAt", "durationMs", "failureCategory", "tabId", "queueDepth", "workerId"].includes(t)) && (e.tabId === void 0 || Number.isSafeInteger(e.tabId) && e.tabId >= 0) && (e.queueDepth === void 0 || Number.isSafeInteger(e.queueDepth) && e.queueDepth >= 0) && (e.workerId === void 0 || y(e.workerId)) && (e.failureCategory === void 0 || e.status === "failed" && Q.includes(e.failureCategory)) && (e.entrySurface === void 0 || ["extension_sidepanel", "extension_widget", "main_web_chat", "embedded_widget", "embedded_custom_ui", "automation", "mcp", "whatsapp", "email"].includes(e.entrySurface)) && ["send", "stop"].includes(e.operation) && ["renderer", "sdk", "extension", "http"].includes(e.layer) && he.includes(e.stage) && ["started", "completed", "failed", "observed"].includes(e.status) && y(e.spanId) && y(e.requestId) && (e.clientMessageId === null || y(e.clientMessageId)) && (e.sessionId === null || y(e.sessionId)) && typeof e.occurredAt == "string" && e.occurredAt.length <= 40 && Number.isFinite(Date.parse(e.occurredAt)) && Number.isSafeInteger(e.durationMs) && e.durationMs >= 0;
780
780
  }
781
781
  function j(s, e) {
782
782
  if (e = { workerId: H, ...e }, !s) return {
@@ -785,67 +785,67 @@ function j(s, e) {
785
785
  },
786
786
  measure: (n, r) => r()
787
787
  };
788
- const t = performance.now(), i = (n, r, o, a, d) => {
788
+ const t = performance.now(), i = (n, r, a, o, d) => {
789
789
  const c = {
790
790
  ...e,
791
791
  stage: n,
792
792
  status: r,
793
- spanId: a,
793
+ spanId: o,
794
794
  occurredAt: (/* @__PURE__ */ new Date()).toISOString(),
795
- durationMs: Math.max(0, Math.round(performance.now() - o)),
796
- ...r === "failed" ? { failureCategory: fe(d) } : {}
795
+ durationMs: Math.max(0, Math.round(performance.now() - a)),
796
+ ...r === "failed" ? { failureCategory: ge(d) } : {}
797
797
  };
798
- s && P(c) && Promise.resolve().then(() => s(c)).catch(() => {
798
+ s && k(c) && Promise.resolve().then(() => s(c)).catch(() => {
799
799
  });
800
800
  };
801
801
  return {
802
802
  identity: e,
803
803
  mark: (n) => i(n, "observed", t, D()),
804
804
  measure(n, r) {
805
- const o = performance.now(), a = D();
806
- return i(n, "started", o, a), r().then(
807
- (d) => (i(n, "completed", o, a), d),
805
+ const a = performance.now(), o = D();
806
+ return i(n, "started", a, o), r().then(
807
+ (d) => (i(n, "completed", a, o), d),
808
808
  (d) => {
809
- throw i(n, "failed", o, a, d), d;
809
+ throw i(n, "failed", a, o, d), d;
810
810
  }
811
811
  );
812
812
  }
813
813
  };
814
814
  }
815
- const w = (s) => s === null || typeof s == "string" && /^[a-zA-Z0-9:_-]{1,160}$/.test(s);
816
- function ye(s) {
815
+ const A = (s) => s === null || typeof s == "string" && /^[a-zA-Z0-9:_-]{1,160}$/.test(s);
816
+ function me(s) {
817
817
  if (!s || typeof s != "object") return !1;
818
818
  const e = s;
819
- return typeof e.observedAt == "string" && e.observedAt.length <= 40 && Number.isFinite(Date.parse(e.observedAt)) && w(e.sessionId) && w(e.responseItemId) && w(e.respondsToUserMessageId) && typeof e.panelVisible == "boolean" && typeof e.documentVisible == "boolean" && typeof e.loading == "boolean";
819
+ return typeof e.observedAt == "string" && e.observedAt.length <= 40 && Number.isFinite(Date.parse(e.observedAt)) && A(e.sessionId) && A(e.responseItemId) && A(e.respondsToUserMessageId) && typeof e.panelVisible == "boolean" && typeof e.documentVisible == "boolean" && typeof e.loading == "boolean";
820
820
  }
821
- function be(s, e, t = "stopped", i, n = "Run stopped by user.") {
821
+ function ye(s, e, t = "stopped", i, n = "Run stopped by user.") {
822
822
  const r = new Set(i ?? [
823
823
  s.assistantDraftRespondsToUserMessageId,
824
824
  s.activeResponseUserMessageId,
825
825
  s.messages.filter((d) => d.role === "user").slice(-1)[0]?.id
826
- ].filter((d) => !!d)), o = s.messages.filter((d) => !(d.dataType === "run_status" && d.loading && r.has(d.respondsToUserMessageId ?? ""))).map((d) => r.has(d.respondsToUserMessageId ?? "") ? { ...d, loading: !1 } : d);
826
+ ].filter((d) => !!d)), a = s.messages.filter((d) => !(d.dataType === "run_status" && d.loading && r.has(d.respondsToUserMessageId ?? ""))).map((d) => r.has(d.respondsToUserMessageId ?? "") ? { ...d, loading: !1 } : d);
827
827
  for (const d of r)
828
- o.some((c) => c.respondsToUserMessageId === d && (c.dataType === "run_status" || c.dataType === "run_error" || c.role === "assistant" && c.phase !== "commentary")) || o.some((c) => c.role === "user" && c.id === d) && o.push({ id: `local-interrupted:${d}`, role: "system", dataType: "run_status", provisional: t === "stopping", content: t === "stopping" ? "Stopping…" : n, createdAt: e, respondsToUserMessageId: d });
829
- const a = s.segments?.map((d) => ({ ...d, outcomeIds: [
828
+ a.some((c) => c.respondsToUserMessageId === d && (c.dataType === "run_status" || c.dataType === "run_error" || c.role === "assistant" && c.phase !== "commentary")) || a.some((c) => c.role === "user" && c.id === d) && a.push({ id: `local-interrupted:${d}`, role: "system", dataType: "run_status", provisional: t === "stopping", content: t === "stopping" ? "Stopping…" : n, createdAt: e, respondsToUserMessageId: d });
829
+ const o = s.segments?.map((d) => ({ ...d, outcomeIds: [
830
830
  ...d.outcomeIds,
831
- ...o.filter((c) => c.id === `local-interrupted:${d.userMessageId}` && !d.outcomeIds.includes(c.id)).map((c) => c.id)
831
+ ...a.filter((c) => c.id === `local-interrupted:${d.userMessageId}` && !d.outcomeIds.includes(c.id)).map((c) => c.id)
832
832
  ] }));
833
833
  return {
834
834
  ...s,
835
- messages: o,
835
+ messages: a,
836
836
  isThinking: !1,
837
837
  isRetrying: !1,
838
838
  pendingMessageStatus: null,
839
839
  turnPhase: null,
840
- segments: a,
840
+ segments: o,
841
841
  activity: { phase: t, activeItemId: null },
842
- isLoadingSession: s.isLoadingSession && o.length === 0,
842
+ isLoadingSession: s.isLoadingSession && a.length === 0,
843
843
  taskStatus: t === "stopped" ? "stopped" : null,
844
844
  lastError: null,
845
845
  lastErrorCode: null
846
846
  };
847
847
  }
848
- const ve = {
848
+ const be = {
849
849
  "stop-without-rendered-message": "Stop is enabled while no message is rendered or the welcome screen is still visible.",
850
850
  "in-progress-stop-unavailable": "An in-progress response has no visible enabled interrupt control.",
851
851
  "stop-did-not-interrupt": "The stopped response remained in progress after an interrupt click.",
@@ -861,8 +861,8 @@ const ve = {
861
861
  "thinking-groups-without-user-message": "Multiple thinking groups appeared without a user message between them.",
862
862
  "thinking-without-progress": "Thinking remained visible without progress for five minutes."
863
863
  };
864
- function _e(s) {
865
- return typeof s == "string" && s.startsWith("ui_invariant:") && Object.prototype.hasOwnProperty.call(ve, s.slice(13));
864
+ function ve(s) {
865
+ return typeof s == "string" && s.startsWith("ui_invariant:") && Object.prototype.hasOwnProperty.call(be, s.slice(13));
866
866
  }
867
867
  function N(s) {
868
868
  return {
@@ -875,7 +875,7 @@ function N(s) {
875
875
  ...s.fileUrl === void 0 ? {} : { fileUrl: s.fileUrl }
876
876
  };
877
877
  }
878
- function Ce(s) {
878
+ function Re(s) {
879
879
  if (!s || typeof s != "object" || !("type" in s)) return !1;
880
880
  const e = s;
881
881
  switch (e.type) {
@@ -887,15 +887,15 @@ function Ce(s) {
887
887
  case "run.stop":
888
888
  return e.clientMessageIds === void 0 || Array.isArray(e.clientMessageIds) && e.clientMessageIds.length <= 100 && e.clientMessageIds.every((t) => typeof t == "string" && t.length > 0 && t.length <= 160);
889
889
  case "runtime.report_response_visibility":
890
- return ye(e.observation);
890
+ return me(e.observation);
891
891
  case "runtime.warmup":
892
892
  return e.reason === "panel_open" || e.reason === "extension_install" || e.reason === "composer_input";
893
893
  case "runtime.report_operation_timing":
894
- return P(e.timing);
894
+ return k(e.timing);
895
895
  case "runtime.report_displayed_error":
896
- return (e.errorDiagnostic === void 0 || ue(e.errorDiagnostic)) && (e.httpRequest === void 0 || B(e.httpRequest)) && (e.historyRefreshFailure === void 0 || U(e.historyRefreshFailure)) && (e.renderedError === void 0 || L(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);
896
+ return (e.errorDiagnostic === void 0 || le(e.errorDiagnostic)) && (e.httpRequest === void 0 || B(e.httpRequest)) && (e.historyRefreshFailure === void 0 || U(e.historyRefreshFailure)) && (e.renderedError === void 0 || L(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);
897
897
  case "runtime.report_invalid_state_transition":
898
- return (e.uiInvariant === void 0 || F(e.uiInvariant)) && (e.reason === "submitted_turn_returned_to_welcome_without_new_chat" || e.reason === "new_messages_button_without_user_scroll" || _e(e.reason)) && (e.clientMessageId === void 0 || typeof e.clientMessageId == "string");
898
+ return (e.uiInvariant === void 0 || F(e.uiInvariant)) && (e.reason === "submitted_turn_returned_to_welcome_without_new_chat" || e.reason === "new_messages_button_without_user_scroll" || ve(e.reason)) && (e.clientMessageId === void 0 || typeof e.clientMessageId == "string");
899
899
  case "runtime.prompt_presented":
900
900
  return (e.feature === "notifications" || e.feature === "tab_grouping") && typeof e.openingGeneration == "number" && Number.isSafeInteger(e.openingGeneration) && e.openingGeneration > 0;
901
901
  case "runtime.widget_lifecycle":
@@ -916,7 +916,7 @@ function Ce(s) {
916
916
  case "conversation.stage_proactive_suggestion":
917
917
  return typeof e.question == "string" && typeof e.clientMessageId == "string";
918
918
  case "conversation.stage":
919
- return typeof e.content == "string" && typeof e.clientMessageId == "string" && (e.submittedAt === void 0 || typeof e.submittedAt == "number") && (e.requestedModel === void 0 || typeof e.requestedModel == "string") && (e.attachments === void 0 || Array.isArray(e.attachments));
919
+ return (e.reconcileAcceptance === void 0 || typeof e.reconcileAcceptance == "boolean") && (e.selectionKey === void 0 || typeof e.selectionKey == "string") && (e.reconcileAcceptance !== !0 || typeof e.selectionKey == "string" && e.selectionKey.length > 0) && typeof e.content == "string" && typeof e.clientMessageId == "string" && (e.submittedAt === void 0 || typeof e.submittedAt == "number") && (e.requestedModel === void 0 || typeof e.requestedModel == "string") && (e.attachments === void 0 || Array.isArray(e.attachments));
920
920
  case "conversation.fail_staged":
921
921
  return typeof e.clientMessageId == "string" && typeof e.message == "string";
922
922
  case "conversation.send":
@@ -925,9 +925,9 @@ function Ce(s) {
925
925
  return !1;
926
926
  }
927
927
  }
928
- class xe {
928
+ class Ce {
929
929
  constructor(e, t, i) {
930
- this.adapter = t, this.state = A(e), this.model = i;
930
+ this.adapter = t, this.state = M(e), this.model = i;
931
931
  }
932
932
  adapter;
933
933
  listeners = {};
@@ -936,7 +936,7 @@ class xe {
936
936
  interactionListeners = /* @__PURE__ */ new Set();
937
937
  accountListeners = /* @__PURE__ */ new Set();
938
938
  state;
939
- sessionHistoryState = b("unavailable");
939
+ sessionHistoryState = v("unavailable");
940
940
  model;
941
941
  interactions = [];
942
942
  account = null;
@@ -944,6 +944,8 @@ class xe {
944
944
  pendingTransfers = /* @__PURE__ */ new Map();
945
945
  // Presentation of commands in transit only; the background remains the submission/delivery owner.
946
946
  submissionPreviews = /* @__PURE__ */ new Map();
947
+ // Durable metadata can retire the preview before receipt reconciliation permits byte transfer.
948
+ submissionRetries = /* @__PURE__ */ new Map();
947
949
  submissionGeneration = 0;
948
950
  pendingStop = null;
949
951
  stopError = null;
@@ -956,44 +958,44 @@ class xe {
956
958
  return i.add(t), this.listeners[e] = i, () => i.delete(t);
957
959
  }
958
960
  getState() {
959
- const e = A(this.state);
961
+ const e = M(this.state);
960
962
  for (const [n, r] of this.submissionPreviews)
961
- e.messages.some((o) => o.id === n) || (e.messages.push({ ...r.message, attachments: r.message.attachments?.map((o) => ({ ...o })) }), e.segments && (e.segments = [...e.segments, { id: n, userMessageId: n, activityIds: [], outcomeIds: [], collapsed: !1 }]), e.isLoadingSession = !1, r.pending && (e.activeResponseUserMessageId = n, e.pendingMessageStatus = "sending", e.turnPhase = "sending", e.activity = { phase: "submitting", activeItemId: null }), r.error && (e.lastError = r.error.message, e.lastErrorCode = ["unauthorized", "401", "auth_reconnecting", "submission_not_available", "submission_checkpoint_pending"].includes(r.error.code) ? r.error.code : "message_delivery_failed"));
963
+ e.messages.some((a) => a.id === n) || (e.messages.push({ ...r.message, attachments: r.message.attachments?.map((a) => ({ ...a })) }), e.segments && (e.segments = [...e.segments, { id: n, userMessageId: n, activityIds: [], outcomeIds: [], collapsed: !1 }]), e.isLoadingSession = !1, r.pending && (e.activeResponseUserMessageId = n, e.pendingMessageStatus = "sending", e.turnPhase = "sending", e.activity = { phase: "submitting", activeItemId: null }), r.error && (e.lastError = r.error.message, e.lastErrorCode = ["unauthorized", "401", "auth_reconnecting", "submission_not_available", "submission_checkpoint_pending"].includes(r.error.code) ? r.error.code : "message_delivery_failed"));
962
964
  this.stopError && (e.lastError = this.stopError, e.lastErrorCode = "stop_failed");
963
965
  const t = [...this.stopPreviews.keys()];
964
966
  if (!t.length) return e;
965
- const i = be(e, "", "stopping", t);
967
+ const i = ye(e, "", "stopping", t);
966
968
  return e.activeResponseUserMessageId && !this.stopPreviews.has(e.activeResponseUserMessageId) ? { ...e, messages: i.messages, segments: i.segments } : i;
967
969
  }
968
970
  updateProjection(e, t, i, n, r) {
969
971
  if (this.destroyed) return;
970
- const o = this.getState();
971
- (o.user?.id !== e.user?.id || o.selectionKey !== void 0 && o.selectionKey !== e.selectionKey || o.selectionKey === void 0 && o.sessionId !== null && o.sessionId !== e.sessionId) && (this.cancelPendingSubmissions(), this.submissionPreviews.clear());
972
- for (const a of e.messages)
973
- a.role === "user" && e.receipts?.find((d) => d.userMessageId === a.id)?.durable !== !1 && this.submissionPreviews.delete(a.id);
974
- this.state = A(e);
975
- for (const [a, d] of this.stopPreviews) {
972
+ const a = this.getState();
973
+ (a.user?.id !== e.user?.id || a.selectionKey !== void 0 && a.selectionKey !== e.selectionKey || a.selectionKey === void 0 && a.sessionId !== null && a.sessionId !== e.sessionId) && (this.cancelPendingSubmissions(), this.submissionPreviews.clear());
974
+ for (const o of e.messages)
975
+ o.role === "user" && e.receipts?.find((d) => d.userMessageId === o.id)?.durable !== !1 && this.submissionPreviews.delete(o.id);
976
+ this.state = M(e);
977
+ for (const [o, d] of this.stopPreviews) {
976
978
  const c = e.activity?.executionKey;
977
- (d !== void 0 && d !== "[]" && c !== void 0 && c !== "[]" && (c !== d || ["completed", "failed", "stopped"].includes(e.activity.phase)) || (d === void 0 || d === "[]") && e.messages.some((l) => l.respondsToUserMessageId === a && !l.provisional && l.loading !== !0 && (l.dataType === "run_status" || l.dataType === "run_error" || l.role === "assistant" && l.phase !== "commentary" && (l.streamState === void 0 || ["finished", "stopped", "failed"].includes(l.streamState))))) && this.stopPreviews.delete(a);
979
+ (d !== void 0 && d !== "[]" && c !== void 0 && c !== "[]" && (c !== d || ["completed", "failed", "stopped"].includes(e.activity.phase)) || (d === void 0 || d === "[]") && e.messages.some((l) => l.respondsToUserMessageId === o && !l.provisional && l.loading !== !0 && (l.dataType === "run_status" || l.dataType === "run_error" || l.role === "assistant" && l.phase !== "commentary" && (l.streamState === void 0 || ["finished", "stopped", "failed"].includes(l.streamState))))) && this.stopPreviews.delete(o);
978
980
  }
979
- if (this.pendingStop?.userMessageIds.every((a) => !this.stopPreviews.has(a)) && (this.pendingStop = null), o.user?.id === e.user?.id)
980
- for (const a of this.state.messages) {
981
- if (a.role !== "user" || !a.attachments?.length) continue;
982
- const d = o.messages.find((c) => c.role === "user" && c.id === a.id);
983
- o.sessionId !== e.sessionId && !(o.sessionId === null && d) || (a.attachments = Ie(d?.attachments, a.attachments));
981
+ if (this.pendingStop?.userMessageIds.every((o) => !this.stopPreviews.has(o)) && (this.pendingStop = null), a.user?.id === e.user?.id)
982
+ for (const o of this.state.messages) {
983
+ if (o.role !== "user" || !o.attachments?.length) continue;
984
+ const d = a.messages.find((c) => c.role === "user" && c.id === o.id);
985
+ a.sessionId !== e.sessionId && !(a.sessionId === null && d) || (o.attachments = _e(d?.attachments, o.attachments));
984
986
  }
985
987
  if (t !== void 0 && (this.model = t), i && JSON.stringify(i) !== JSON.stringify(this.sessionHistoryState)) {
986
- this.sessionHistoryState = z(i);
987
- for (const a of this.sessionHistoryListeners)
988
- a(this.getSessionHistoryState());
988
+ this.sessionHistoryState = K(i);
989
+ for (const o of this.sessionHistoryListeners)
990
+ o(this.getSessionHistoryState());
989
991
  }
990
992
  if (n && JSON.stringify(n) !== JSON.stringify(this.interactions)) {
991
- this.interactions = n.map((a) => ({ ...a }));
992
- for (const a of this.interactionListeners) a(this.getInteractions());
993
+ this.interactions = n.map((o) => ({ ...o }));
994
+ for (const o of this.interactionListeners) o(this.getInteractions());
993
995
  }
994
996
  if (r !== void 0 && JSON.stringify(r) !== JSON.stringify(this.account)) {
995
997
  this.account = r ? { ...r } : null;
996
- for (const a of this.accountListeners) a(this.getAccount());
998
+ for (const o of this.accountListeners) o(this.getAccount());
997
999
  }
998
1000
  this.emit("state", this.getState());
999
1001
  }
@@ -1004,7 +1006,7 @@ class xe {
1004
1006
  if (!this.destroyed) {
1005
1007
  this.destroyed = !0;
1006
1008
  for (const e of this.durabilityWaiters) e();
1007
- this.pendingStop = null, this.stopPreviews.clear(), this.pendingTransfers.clear(), this.submissionPreviews.clear(), this.attachmentFiles.clear(), this.sessionHistoryListeners.clear(), this.interactionListeners.clear(), this.accountListeners.clear();
1009
+ this.pendingStop = null, this.stopPreviews.clear(), this.pendingTransfers.clear(), this.submissionRetries.clear(), this.submissionPreviews.clear(), this.attachmentFiles.clear(), this.sessionHistoryListeners.clear(), this.interactionListeners.clear(), this.accountListeners.clear();
1008
1010
  for (const e of Object.values(this.listeners)) e?.clear();
1009
1011
  this.adapter.onDisconnect?.();
1010
1012
  }
@@ -1020,7 +1022,7 @@ class xe {
1020
1022
  this.dispatch({ type: "runtime.widget_lifecycle", action: e, trigger: t });
1021
1023
  }
1022
1024
  reportOperationTiming(e) {
1023
- !this.destroyed && P(e) && this.adapter.dispatch({ type: "runtime.report_operation_timing", timing: e }).catch(() => {
1025
+ !this.destroyed && k(e) && this.adapter.dispatch({ type: "runtime.report_operation_timing", timing: e }).catch(() => {
1024
1026
  });
1025
1027
  }
1026
1028
  reportResponseVisibility(e) {
@@ -1037,18 +1039,18 @@ class xe {
1037
1039
  });
1038
1040
  }
1039
1041
  reportDisplayedError(e, t, i, n, r) {
1040
- const o = e === "conversation_error" && !n ? this.getState().conversationDiagnostics?.httpRequest : void 0;
1042
+ const a = e === "conversation_error" && !n ? this.getState().conversationDiagnostics?.httpRequest : void 0;
1041
1043
  if (n !== void 0 && !L(n) || r !== void 0 && !U(r)) return;
1042
- const a = pe(this.getState(), e, i, !!n, this.adapter.diagnosticBuilds);
1044
+ const o = ue(this.getState(), e, i, !!n, this.adapter.diagnosticBuilds);
1043
1045
  this.adapter.dispatch({
1044
1046
  type: "runtime.report_displayed_error",
1045
- errorDiagnostic: a,
1046
- ...a.clientMessageId ? { clientMessageId: a.clientMessageId } : {},
1047
+ errorDiagnostic: o,
1048
+ ...o.clientMessageId ? { clientMessageId: o.clientMessageId } : {},
1047
1049
  reason: e,
1048
1050
  errorFingerprint: t,
1049
1051
  ...n ? { renderedError: n } : {},
1050
1052
  ...r ? { historyRefreshFailure: r } : {},
1051
- ...B(o) ? { httpRequest: o } : {},
1053
+ ...B(a) ? { httpRequest: a } : {},
1052
1054
  ...i ? { displayedMessage: G(i) } : {}
1053
1055
  }).catch(() => {
1054
1056
  });
@@ -1059,7 +1061,7 @@ class xe {
1059
1061
  const n = t.attachments ?? [];
1060
1062
  if (!i && n.length === 0) return Promise.resolve(null);
1061
1063
  this.pendingStop = null, this.stopError = null;
1062
- const r = t.clientMessageId ?? (t.proactiveSuggestionQuestion && this.stagedProactiveSuggestionClientMessageId ? this.stagedProactiveSuggestionClientMessageId : crypto.randomUUID()), o = t.submittedAt ?? Date.now(), a = this.submissionGeneration;
1064
+ const r = t.clientMessageId ?? (t.proactiveSuggestionQuestion && this.stagedProactiveSuggestionClientMessageId ? this.stagedProactiveSuggestionClientMessageId : crypto.randomUUID()), a = t.submittedAt ?? Date.now(), o = this.submissionGeneration;
1063
1065
  this.pendingTransfers.set(r, n.flatMap((c) => c.id ? [c.id] : [])), this.submissionPreviews.set(r, { pending: !0, message: {
1064
1066
  id: r,
1065
1067
  role: "user",
@@ -1067,13 +1069,13 @@ class xe {
1067
1069
  createdAt: "",
1068
1070
  attachments: n.map((c) => ({ ...c }))
1069
1071
  } });
1070
- const d = this.sendMessageNow(i, { ...t, clientMessageId: r, submittedAt: o }, a);
1072
+ const d = this.sendMessageNow(i, { ...t, clientMessageId: r, submittedAt: a, selectionKey: this.state.selectionKey }, o);
1071
1073
  return this.emit("state", this.getState()), d.finally(() => {
1072
1074
  this.pendingTransfers.delete(r);
1073
1075
  });
1074
1076
  }
1075
1077
  async sendMessageNow(e, t, i) {
1076
- const n = e, r = t.clientMessageId, o = j((c) => {
1078
+ const n = e, r = t.clientMessageId, a = j((c) => {
1077
1079
  i === this.submissionGeneration && this.reportOperationTiming(c);
1078
1080
  }, {
1079
1081
  operation: "send",
@@ -1082,13 +1084,14 @@ class xe {
1082
1084
  clientMessageId: r,
1083
1085
  sessionId: this.state.sessionId
1084
1086
  });
1085
- o.mark("submit");
1086
- let a = t.attachments ?? [], d = !1;
1087
+ a.mark("submit");
1088
+ let o = t.attachments ?? [], d = !1;
1087
1089
  if (i !== this.submissionGeneration) return null;
1088
1090
  try {
1089
- if (!await o.measure("staging_ipc", async () => {
1091
+ const c = await a.measure("staging_ipc", async () => {
1090
1092
  const u = await this.enqueueOperation(async () => this.destroyed || i !== this.submissionGeneration ? null : { result: this.adapter.dispatch({
1091
1093
  type: "conversation.stage",
1094
+ ...t.reconcileAcceptance ? { reconcileAcceptance: !0, selectionKey: t.selectionKey } : {},
1092
1095
  initiatedBy: t.initiatedBy,
1093
1096
  invocation: t.invocation,
1094
1097
  automationOnboarding: t.automationOnboarding,
@@ -1096,30 +1099,37 @@ class xe {
1096
1099
  clientMessageId: r,
1097
1100
  proactiveSuggestionQuestion: t.proactiveSuggestionQuestion,
1098
1101
  // Preview URLs belong to the renderer's optimistic snapshot and are not valid runtime-command metadata.
1099
- attachments: a.length > 0 ? a.map(N) : void 0,
1102
+ attachments: o.length > 0 ? o.map(N) : void 0,
1100
1103
  submittedAt: t.submittedAt
1101
1104
  }) });
1102
- return u && await u.result.then(() => !0, (f) => {
1103
- const k = g(f);
1104
- if (k.code !== "submission_checkpoint_pending") throw f;
1105
- const q = this.submissionPreviews.get(r);
1106
- return q && (q.error = k), this.emit("state", this.getState()), this.waitForSubmissionDurability(r, i);
1107
- }) ? u : null;
1108
- }) || i !== this.submissionGeneration) return null;
1109
- if (d = !0, a.length > 0) {
1105
+ return u ? u.result.then((l) => ({ result: l }), async (l) => {
1106
+ const h = m(l);
1107
+ if (h.code !== "submission_checkpoint_pending") throw l;
1108
+ const g = this.submissionPreviews.get(r);
1109
+ return g && (g.error = h), this.emit("state", this.getState()), await this.waitForSubmissionDurability(r, i) ? { result: void 0 } : null;
1110
+ }) : null;
1111
+ });
1112
+ if (!c || i !== this.submissionGeneration) return null;
1113
+ if (d = !0, this.submissionRetries.delete(r), c.result?.submissionAccepted) {
1114
+ r === this.stagedProactiveSuggestionClientMessageId && (this.stagedProactiveSuggestionClientMessageId = null);
1115
+ for (const u of t.attachments ?? [])
1116
+ u.id && this.attachmentFiles.delete(u.id);
1117
+ return r;
1118
+ }
1119
+ if (o.length > 0) {
1110
1120
  if (!this.adapter.uploadAttachment)
1111
1121
  throw new Error("The runtime does not support attachments.");
1112
1122
  const u = [];
1113
- for (const l of a) {
1123
+ for (const l of o) {
1114
1124
  if (l.sandboxPath || l.storageKey) {
1115
1125
  u.push(l);
1116
1126
  continue;
1117
1127
  }
1118
- const f = l.id ? this.attachmentFiles.get(l.id) : void 0;
1119
- if (!f) throw new Error(`Attachment bytes are unavailable for ${l.name}`);
1120
- if (u.push(await o.measure("attachment_transfer", () => this.adapter.uploadAttachment(f, l, { clientMessageId: r }))), i !== this.submissionGeneration) return null;
1128
+ const h = l.id ? this.attachmentFiles.get(l.id) : void 0;
1129
+ if (!h) throw new Error(`Attachment bytes are unavailable for ${l.name}`);
1130
+ if (u.push(await a.measure("attachment_transfer", () => this.adapter.uploadAttachment(h, l, { clientMessageId: r }))), i !== this.submissionGeneration) return null;
1121
1131
  }
1122
- a = u;
1132
+ o = u;
1123
1133
  }
1124
1134
  if (i !== this.submissionGeneration || (await this.adapter.dispatch({
1125
1135
  type: "conversation.send",
@@ -1129,21 +1139,26 @@ class xe {
1129
1139
  invocation: t.invocation,
1130
1140
  automationOnboarding: t.automationOnboarding,
1131
1141
  proactiveSuggestionQuestion: t.proactiveSuggestionQuestion,
1132
- attachments: a.length > 0 ? a.map(N) : void 0
1142
+ attachments: o.length > 0 ? o.map(N) : void 0
1133
1143
  }), i !== this.submissionGeneration)) return null;
1134
1144
  for (const u of t.attachments ?? [])
1135
1145
  u.id && this.attachmentFiles.delete(u.id);
1136
1146
  return r === this.stagedProactiveSuggestionClientMessageId && (this.stagedProactiveSuggestionClientMessageId = null), r;
1137
1147
  } catch (c) {
1138
1148
  if (i !== this.submissionGeneration) return null;
1139
- if (W(c))
1140
- for (const l of t.attachments ?? [])
1141
- l.id && this.attachmentFiles.delete(l.id);
1142
- const u = this.submissionPreviews.get(r);
1143
- throw u && (u.pending = !1, u.error = g(c), u.retry = !d && g(c).code === "command_not_received" ? () => this.sendMessageNow(e, t, i) : void 0, this.emit("state", this.getState())), d && await this.adapter.dispatch({
1149
+ if (O(c))
1150
+ for (const g of t.attachments ?? [])
1151
+ g.id && this.attachmentFiles.delete(g.id);
1152
+ const l = m(c).code === "command_not_received";
1153
+ !d && !O(c) && (l || t.selectionKey !== void 0) && this.submissionRetries.set(r, {
1154
+ retry: () => this.sendMessageNow(e, { ...t, reconcileAcceptance: !l }, i),
1155
+ attachmentIds: (t.attachments ?? []).flatMap((g) => g.id ? [g.id] : [])
1156
+ });
1157
+ const h = this.submissionPreviews.get(r);
1158
+ throw h && (h.pending = !1, h.error = m(c), this.emit("state", this.getState())), d && await this.adapter.dispatch({
1144
1159
  type: "conversation.fail_staged",
1145
1160
  clientMessageId: r,
1146
- message: g(c).message
1161
+ message: m(c).message
1147
1162
  }), c;
1148
1163
  }
1149
1164
  }
@@ -1158,15 +1173,15 @@ class xe {
1158
1173
  const t = e ?? [...this.submissionPreviews].reverse().find(([, o]) => o.error)?.[0] ?? this.state.messages.filter((o) => o.role === "user").slice(-1)[0]?.id;
1159
1174
  if (!t || this.destroyed) return !1;
1160
1175
  const i = this.submissionPreviews.get(t);
1161
- if (i?.pending) return !1;
1162
- const n = i?.retry, r = this.submissionGeneration;
1176
+ if (i?.pending || this.pendingTransfers.has(t)) return !1;
1177
+ const n = this.submissionRetries.get(t), r = n?.retry, a = this.submissionGeneration;
1163
1178
  try {
1164
- return i && n ? (i.pending = !0, i.error = void 0, i.retry = void 0, this.pendingTransfers.set(t, (i.message.attachments ?? []).flatMap((o) => o.id ? [o.id] : [])), this.emit("state", this.getState()), await n()) : await this.dispatch({ type: "run.retry", clientMessageId: t }), !0;
1179
+ return n && r ? (i && (i.pending = !0, i.error = void 0), this.submissionRetries.delete(t), this.pendingTransfers.set(t, n.attachmentIds), this.emit("state", this.getState()), await r()) : await this.dispatch({ type: "run.retry", clientMessageId: t }), !0;
1165
1180
  } catch (o) {
1166
- if (!i) throw o;
1167
- return r === this.submissionGeneration && this.submissionPreviews.get(t) === i && (i.error = g(o), this.emit("state", this.getState())), !1;
1181
+ if (!i && !r) throw o;
1182
+ return i && a === this.submissionGeneration && this.submissionPreviews.get(t) === i && (i.error = m(o), this.emit("state", this.getState())), !1;
1168
1183
  } finally {
1169
- n && this.pendingTransfers.delete(t), i && r === this.submissionGeneration && this.submissionPreviews.get(t) === i && (i.pending = !1, this.emit("state", this.getState()));
1184
+ r && this.pendingTransfers.delete(t), i && a === this.submissionGeneration && this.submissionPreviews.get(t) === i && (i.pending = !1, this.emit("state", this.getState()));
1170
1185
  }
1171
1186
  }
1172
1187
  createLocalAttachment(e) {
@@ -1194,18 +1209,18 @@ class xe {
1194
1209
  n.mark("stop");
1195
1210
  const r = { userMessageIds: i, promise: Promise.resolve() };
1196
1211
  this.pendingStop = r;
1197
- const o = !e.pendingMessageStatus && ["thinking", "steering", "queued", "stopping"].includes(this.state.activity?.phase ?? "") ? this.state.activity?.executionKey : void 0;
1212
+ const a = !e.pendingMessageStatus && ["thinking", "steering", "queued", "stopping"].includes(this.state.activity?.phase ?? "") ? this.state.activity?.executionKey : void 0;
1198
1213
  for (const c of i)
1199
- this.stopPreviews.set(c, t.includes(c) ? void 0 : o);
1200
- const a = this.submissionGeneration;
1214
+ this.stopPreviews.set(c, t.includes(c) ? void 0 : a);
1215
+ const o = this.submissionGeneration;
1201
1216
  r.promise = n.measure("stop_ipc", () => this.adapter.dispatch({ type: "run.stop", ...t.length ? { clientMessageIds: t } : {} })).then(() => {
1202
1217
  }, (c) => {
1203
- if (!(a !== this.submissionGeneration || i.every((u) => !this.stopPreviews.has(u)))) {
1218
+ if (!(o !== this.submissionGeneration || i.every((u) => !this.stopPreviews.has(u)))) {
1204
1219
  for (const u of i) this.stopPreviews.delete(u);
1205
- this.stopError = g(c).message;
1220
+ this.stopError = m(c).message;
1206
1221
  }
1207
1222
  }).finally(() => {
1208
- this.destroyed || a !== this.submissionGeneration || (this.pendingStop === r && (this.pendingStop = null), this.emit("state", this.getState()));
1223
+ this.destroyed || o !== this.submissionGeneration || (this.pendingStop === r && (this.pendingStop = null), this.emit("state", this.getState()));
1209
1224
  }), this.emit("state", this.getState());
1210
1225
  const d = r.promise;
1211
1226
  return this.operationQueue = d.then(() => {
@@ -1217,27 +1232,27 @@ class xe {
1217
1232
  let i = () => {
1218
1233
  }, n = () => {
1219
1234
  };
1220
- return new Promise((r, o) => {
1235
+ return new Promise((r, a) => {
1221
1236
  n = () => {
1222
1237
  if (this.destroyed || t !== this.submissionGeneration) {
1223
1238
  r(!1);
1224
1239
  return;
1225
1240
  }
1226
- const a = this.state;
1227
- if (a.messages.some((c) => c.respondsToUserMessageId === e && c.dataType === "run_status" && !c.provisional)) {
1241
+ const o = this.state;
1242
+ if (o.messages.some((c) => c.respondsToUserMessageId === e && c.dataType === "run_status" && !c.provisional)) {
1228
1243
  r(!1);
1229
1244
  return;
1230
1245
  }
1231
- if (a.conversationDiagnostics?.failedClientMessageId === e && a.lastError && a.lastErrorCode !== "submission_checkpoint_pending") {
1232
- o(Object.assign(new Error(a.lastError), { code: a.lastErrorCode }));
1246
+ if (o.conversationDiagnostics?.failedClientMessageId === e && o.lastError && o.lastErrorCode !== "submission_checkpoint_pending") {
1247
+ a(Object.assign(new Error(o.lastError), { code: o.lastErrorCode }));
1233
1248
  return;
1234
1249
  }
1235
- const d = a.messages.find((c) => c.id === `submission-error:${e}` && c.dataType === "run_error");
1250
+ const d = o.messages.find((c) => c.id === `submission-error:${e}` && c.dataType === "run_error");
1236
1251
  if (d) {
1237
- o(new Error(d.content));
1252
+ a(new Error(d.content));
1238
1253
  return;
1239
1254
  }
1240
- a.receipts?.some((c) => c.userMessageId === e && c.durable) && r(!0);
1255
+ o.receipts?.some((c) => c.userMessageId === e && c.durable) && r(!0);
1241
1256
  }, this.durabilityWaiters.add(n), i = this.on("state", n), n();
1242
1257
  }).finally(() => {
1243
1258
  i(), this.durabilityWaiters.delete(n);
@@ -1245,14 +1260,17 @@ class xe {
1245
1260
  }
1246
1261
  cancelPendingSubmissions(e = !0) {
1247
1262
  this.pendingStop = null, e && this.stopPreviews.clear(), this.stopError = null;
1248
- const t = [...this.pendingTransfers.keys()];
1263
+ const t = [.../* @__PURE__ */ new Set([...this.pendingTransfers.keys(), ...this.submissionRetries.keys()])];
1249
1264
  this.submissionGeneration++;
1250
1265
  for (const i of this.durabilityWaiters) i();
1251
1266
  for (const i of this.pendingTransfers.values())
1252
1267
  for (const n of i) this.attachmentFiles.delete(n);
1253
1268
  this.pendingTransfers.clear();
1269
+ for (const i of this.submissionRetries.values())
1270
+ for (const n of i.attachmentIds) this.attachmentFiles.delete(n);
1271
+ this.submissionRetries.clear();
1254
1272
  for (const i of this.submissionPreviews.values()) {
1255
- i.pending = !1, i.retry = void 0, i.error?.code === "submission_checkpoint_pending" && (i.error = void 0);
1273
+ i.pending = !1, i.error?.code === "submission_checkpoint_pending" && (i.error = void 0);
1256
1274
  for (const n of i.message.attachments ?? [])
1257
1275
  n.id && this.attachmentFiles.delete(n.id);
1258
1276
  }
@@ -1272,7 +1290,7 @@ class xe {
1272
1290
  return t.sessionHistoryPage;
1273
1291
  }
1274
1292
  getSessionHistoryState() {
1275
- return z(this.sessionHistoryState);
1293
+ return K(this.sessionHistoryState);
1276
1294
  }
1277
1295
  subscribeSessionHistory(e) {
1278
1296
  return this.sessionHistoryListeners.add(e), e(this.getSessionHistoryState()), () => this.sessionHistoryListeners.delete(e);
@@ -1301,7 +1319,7 @@ class xe {
1301
1319
  return this.interactionListeners.add(e), e(this.getInteractions()), () => this.interactionListeners.delete(e);
1302
1320
  }
1303
1321
  actOnInteraction(e, t, i, n = {}) {
1304
- const r = n.expectedSourceVersion === void 0 ? this.getInteractions().find((o) => o.id === e)?.sourceVersion ?? null : n.expectedSourceVersion;
1322
+ const r = n.expectedSourceVersion === void 0 ? this.getInteractions().find((a) => a.id === e)?.sourceVersion ?? null : n.expectedSourceVersion;
1305
1323
  return this.dispatch({
1306
1324
  type: "interaction.act",
1307
1325
  interactionId: e,
@@ -1354,7 +1372,7 @@ class xe {
1354
1372
  for (const n of i ?? []) n(t);
1355
1373
  }
1356
1374
  }
1357
- function Ie(s, e) {
1375
+ function _e(s, e) {
1358
1376
  if (!e || !s) return e;
1359
1377
  const t = /* @__PURE__ */ new Map();
1360
1378
  for (const i of s) {
@@ -1366,7 +1384,7 @@ function Ie(s, e) {
1366
1384
  return n ? { ...i, previewUrl: n } : i;
1367
1385
  });
1368
1386
  }
1369
- function A(s) {
1387
+ function M(s) {
1370
1388
  return {
1371
1389
  ...s,
1372
1390
  starterPrompts: [...s.starterPrompts],
@@ -1374,7 +1392,7 @@ function A(s) {
1374
1392
  messages: s.messages.map((e) => {
1375
1393
  const t = {
1376
1394
  ...e,
1377
- attachments: e.attachments?.map((o) => ({ ...o }))
1395
+ attachments: e.attachments?.map((a) => ({ ...a }))
1378
1396
  }, i = e.assistantDraftItemId, n = e.clientMessageId, r = e.proactiveSuggestionClientMessageId;
1379
1397
  return r && Object.defineProperty(t, "proactiveSuggestionClientMessageId", {
1380
1398
  value: r,
@@ -1390,10 +1408,10 @@ function A(s) {
1390
1408
  activeScheduledFollowUps: s.activeScheduledFollowUps?.map((e) => ({ ...e })) ?? null
1391
1409
  };
1392
1410
  }
1393
- function z(s) {
1411
+ function K(s) {
1394
1412
  return {
1395
1413
  ...s,
1396
- data: s.data ? v({
1414
+ data: s.data ? _({
1397
1415
  entities: Z(s.data).map((e) => ({ ...e })),
1398
1416
  nextCursor: s.data.nextCursor
1399
1417
  }) : null
@@ -1401,25 +1419,25 @@ function z(s) {
1401
1419
  }
1402
1420
  export {
1403
1421
  J as PRODUCT_AGENT_AUTH_RECONNECTING_ERROR_MESSAGE,
1404
- ke as ProductAgentInteractionManager,
1405
- O as ProductAgentQueryController,
1406
- xe as ProductAgentRemoteRuntimeClient,
1407
- Pe as ProductAgentSessionHistoryManager,
1408
- Oe as ProductAgentTaskPageTitleController,
1422
+ Pe as ProductAgentInteractionManager,
1423
+ q as ProductAgentQueryController,
1424
+ Ce as ProductAgentRemoteRuntimeClient,
1425
+ Te as ProductAgentSessionHistoryManager,
1426
+ qe as ProductAgentTaskPageTitleController,
1409
1427
  Me as canSubmitPersonalProductAgentMessage,
1410
- qe as createLocalStorageInteractionDecisionStorage,
1411
- b as createProductAgentQueryState,
1412
- Re as createProductAgentTaskPageTitleDocument,
1413
- ne as formatProductAgentTaskPageTitle,
1414
- Ae as hasProductAgentPaidCreditFallback,
1415
- W as isProductAgentAuthReconnectError,
1416
- Ce as isProductAgentRuntimeCommand,
1428
+ ke as createLocalStorageInteractionDecisionStorage,
1429
+ v as createProductAgentQueryState,
1430
+ Oe as createProductAgentTaskPageTitleDocument,
1431
+ ie as formatProductAgentTaskPageTitle,
1432
+ we as hasProductAgentPaidCreditFallback,
1433
+ O as isProductAgentAuthReconnectError,
1434
+ Re as isProductAgentRuntimeCommand,
1417
1435
  V as mergeProductAgentEntityPages,
1418
- v as normalizeProductAgentEntityPage,
1419
- te as readLocalStorageInteractionDecisions,
1420
- Se as reconcileProductAgentSubmissionGate,
1421
- Ee as resolveProductAgentBillingPresentation,
1422
- Te as resolveProductAgentComposerAction,
1423
- we as resolveProductAgentWidgetPresentation,
1436
+ _ as normalizeProductAgentEntityPage,
1437
+ ee as readLocalStorageInteractionDecisions,
1438
+ Ie as reconcileProductAgentSubmissionGate,
1439
+ Ae as resolveProductAgentBillingPresentation,
1440
+ Ee as resolveProductAgentComposerAction,
1441
+ Se as resolveProductAgentWidgetPresentation,
1424
1442
  Z as selectProductAgentQueryEntities
1425
1443
  };