@pluno/product-agent-web 0.1.229 → 0.1.230

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,6 +1,6 @@
1
- function f(i) {
1
+ function f(s) {
2
2
  return {
3
- key: i,
3
+ key: s,
4
4
  status: "not_requested",
5
5
  data: null,
6
6
  error: null,
@@ -9,8 +9,8 @@ function f(i) {
9
9
  };
10
10
  }
11
11
  class w {
12
- constructor(e, t, s = (n, a) => a) {
13
- this.loader = t, this.merge = s, this.state = f(e);
12
+ constructor(e, t, i = (n, a) => a) {
13
+ this.loader = t, this.merge = i, this.state = f(e);
14
14
  }
15
15
  loader;
16
16
  merge;
@@ -52,16 +52,16 @@ class w {
52
52
  for (; this.trailingLoad; ) {
53
53
  const e = this.trailingLoad;
54
54
  this.trailingLoad = null;
55
- const t = this.state.key, s = this.state.requestId + 1;
55
+ const t = this.state.key, i = this.state.requestId + 1;
56
56
  this.state = {
57
57
  ...this.state,
58
58
  status: e.mode === "append" ? "loading_more" : this.state.data === null ? "loading" : "refreshing",
59
59
  error: null,
60
- requestId: s
60
+ requestId: i
61
61
  }, this.publish();
62
62
  try {
63
63
  const n = await this.loader({ key: t, cursor: e.cursor });
64
- if (t !== this.state.key || s !== this.state.requestId) continue;
64
+ if (t !== this.state.key || i !== this.state.requestId) continue;
65
65
  this.state = {
66
66
  ...this.state,
67
67
  status: "ready",
@@ -70,7 +70,7 @@ class w {
70
70
  updatedAt: Date.now()
71
71
  }, this.publish();
72
72
  } catch (n) {
73
- if (t !== this.state.key || s !== this.state.requestId) continue;
73
+ if (t !== this.state.key || i !== this.state.requestId) continue;
74
74
  this.state = {
75
75
  ...this.state,
76
76
  status: "error",
@@ -83,53 +83,60 @@ class w {
83
83
  for (const e of this.listeners) e(this.state);
84
84
  }
85
85
  }
86
- function m(i) {
86
+ function m(s) {
87
87
  const e = {}, t = [];
88
- for (const s of i.entities)
89
- e[s.id] || t.push(s.id), e[s.id] = s;
88
+ for (const i of s.entities)
89
+ e[i.id] || t.push(i.id), e[i.id] = i;
90
90
  return {
91
91
  entitiesById: e,
92
92
  ids: t,
93
- nextCursor: i.nextCursor
93
+ nextCursor: s.nextCursor
94
94
  };
95
95
  }
96
- function O(i, e, t) {
97
- if (t === "replace" || i === null) return e;
98
- const s = { ...i.entitiesById, ...e.entitiesById }, n = [...i.ids];
96
+ function D(s, e, t) {
97
+ if (t === "replace" || s === null) return e;
98
+ const i = { ...s.entitiesById, ...e.entitiesById }, n = [...s.ids];
99
99
  for (const a of e.ids)
100
- i.entitiesById[a] || n.push(a);
101
- return { entitiesById: s, ids: n, nextCursor: e.nextCursor };
100
+ s.entitiesById[a] || n.push(a);
101
+ return { entitiesById: i, ids: n, nextCursor: e.nextCursor };
102
102
  }
103
- function k(i) {
104
- return i ? i.ids.map((e) => i.entitiesById[e]).filter((e) => !!e) : [];
103
+ function R(s) {
104
+ return s ? s.ids.map((e) => s.entitiesById[e]).filter((e) => !!e) : [];
105
105
  }
106
- function N(i) {
107
- return i.visible ? i.minimized ? { state: "minimized" } : { state: i.open ? "visible_open" : "visible_closed" } : { state: "hidden" };
106
+ function F(s) {
107
+ return s.visible ? s.minimized ? { state: "minimized" } : { state: s.open ? "visible_open" : "visible_closed" } : { state: "hidden" };
108
108
  }
109
- function B(i, e) {
110
- 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"] } : i ?? { allowed: !0, reason: "allowed", actions: [] };
109
+ function j(s, e) {
110
+ 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: [] };
111
111
  }
112
- function j(i) {
113
- if (!i || typeof i != "object") return !1;
114
- const e = i.paidCreditFallbackModel;
112
+ function z(s) {
113
+ if (!s || typeof s != "object") return !1;
114
+ const e = s.paidCreditFallbackModel;
115
115
  return typeof e == "string" && e.length > 0;
116
116
  }
117
- function F(i) {
118
- return i ? i.submissionGate?.allowed === !1 ? { state: "action_required", reason: i.submissionGate.reason } : i.usingPaidCreditFallback === !0 ? { state: "paid_credit_fallback" } : i.creditLimit !== null && i.creditLimit > 0 && i.creditsRemaining !== null && i.creditsRemaining > 0 && i.creditsRemaining / i.creditLimit <= 0.2 ? { state: "low_credits" } : i.creditsUsed !== null ? { state: "usage" } : { state: "hidden" } : { state: "hidden" };
117
+ function H(s) {
118
+ return s ? s.submissionGate?.allowed === !1 ? { state: "action_required", reason: s.submissionGate.reason } : 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
- function z(i) {
121
- const e = i.hasDraftMessage || i.hasPreSubmittedAttachment;
122
- return i.hasRunningAssistantTurn && !i.hasDraftMessage ? {
120
+ function G(s) {
121
+ return s.submissionAllowed && s.isAuthenticated && s.hasWorkspace && !s.isWebsiteBlocked && s.isCurrentPageResolved && !s.isSubmitting && !s.hasPendingMessage;
122
+ }
123
+ function V(s) {
124
+ const e = s.hasDraftMessage || s.hasPreSubmittedAttachment;
125
+ return s.hasRunningAssistantTurn && !e ? {
123
126
  action: "stop",
124
- disabled: !i.canStopRunningTurn
127
+ disabled: !s.canStopRunningTurn
125
128
  } : {
126
129
  action: "send",
127
- disabled: !e || !i.canSubmitMessage
130
+ disabled: !e || !s.canSubmitMessage
128
131
  };
129
132
  }
130
- class H {
131
- constructor(e, t, s = 20) {
132
- this.loadPage = t, this.limit = s, this.recentQuery = new w(
133
+ const k = "Pluno is reconnecting. Try again in a moment.";
134
+ function C(s) {
135
+ return (s instanceof Error ? s.message : s) === k;
136
+ }
137
+ class Z {
138
+ constructor(e, t, i = 20) {
139
+ this.loadPage = t, this.limit = i, this.recentQuery = new w(
133
140
  `${e}:recent`,
134
141
  async ({ cursor: n }) => m(
135
142
  await this.loadPage({ cursor: n, limit: this.limit, pinned: !1 }).then((a) => ({
@@ -137,7 +144,7 @@ class H {
137
144
  nextCursor: a.nextCursor
138
145
  }))
139
146
  ),
140
- O
147
+ D
141
148
  ), this.pinnedQuery = new w(
142
149
  `${e}:pinned`,
143
150
  async () => m({
@@ -159,18 +166,18 @@ class H {
159
166
  completedRefreshSequence = 0;
160
167
  activityReconciliationScheduled = !1;
161
168
  getState() {
162
- const e = this.recentQuery.getState(), t = this.pinnedQuery.getState(), s = [
169
+ const e = this.recentQuery.getState(), t = this.pinnedQuery.getState(), i = [
163
170
  ...g(t.data),
164
171
  ...g(e.data)
165
- ], n = new Map(s.map((o) => [o.id, o])), a = Array.from(n.values()).map(
166
- (o) => this.applyOverrides(o, this.completedRefreshSequence)
167
- ), l = Array.from(this.optimisticEntities.values()).filter((o) => !n.has(o.id)).reverse(), r = e.data || t.data || l.length > 0 ? m({
168
- entities: [...l, ...a],
172
+ ], n = new Map(i.map((l) => [l.id, l])), a = Array.from(n.values()).map(
173
+ (l) => this.applyOverrides(l, this.completedRefreshSequence)
174
+ ), c = Array.from(this.optimisticEntities.values()).filter((l) => !n.has(l.id)).reverse(), r = e.data || t.data || c.length > 0 ? m({
175
+ entities: [...c, ...a],
169
176
  nextCursor: e.data?.nextCursor ?? null
170
177
  }) : null;
171
178
  return {
172
179
  key: e.key.slice(0, -7),
173
- status: R(e, t),
180
+ status: x(e, t),
174
181
  data: r,
175
182
  error: e.error ?? t.error,
176
183
  requestId: Math.max(e.requestId, t.requestId),
@@ -216,20 +223,20 @@ class H {
216
223
  isActive: t,
217
224
  confirmAfterRefresh: this.completedRefreshSequence + 1,
218
225
  releaseAfterRefresh: this.completedRefreshSequence + 2
219
- }), this.updateEntity(e, (s) => ({ ...s, isActive: t }));
226
+ }), this.updateEntity(e, (i) => ({ ...i, isActive: t }));
220
227
  }
221
228
  setPinned(e, t) {
222
- const s = { pinned: t, confirmAfterRefresh: Number.POSITIVE_INFINITY };
223
- return this.pinnedOverrides.set(e, s), this.updateEntity(e, (n) => ({ ...n, isPinned: t })), s;
229
+ const i = { pinned: t, confirmAfterRefresh: Number.POSITIVE_INFINITY };
230
+ return this.pinnedOverrides.set(e, i), this.updateEntity(e, (n) => ({ ...n, isPinned: t })), i;
224
231
  }
225
232
  confirmPinned(e, t) {
226
233
  this.pinnedOverrides.get(e) === t && (t.confirmAfterRefresh = this.completedRefreshSequence + 1);
227
234
  }
228
- rollbackPinned(e, t, s) {
229
- this.pinnedOverrides.get(e) === t && (this.pinnedOverrides.delete(e), this.updateEntity(e, (n) => ({ ...n, isPinned: s })));
235
+ rollbackPinned(e, t, i) {
236
+ this.pinnedOverrides.get(e) === t && (this.pinnedOverrides.delete(e), this.updateEntity(e, (n) => ({ ...n, isPinned: i })));
230
237
  }
231
238
  setTitle(e, t) {
232
- this.titleOverrides.set(e, t), this.updateEntity(e, (s) => ({ ...s, customTitle: t }));
239
+ this.titleOverrides.set(e, t), this.updateEntity(e, (i) => ({ ...i, customTitle: t }));
233
240
  }
234
241
  confirmTitle(e) {
235
242
  this.titleOverrides.delete(e);
@@ -238,34 +245,34 @@ class H {
238
245
  const e = [
239
246
  ...g(this.pinnedQuery.getState().data),
240
247
  ...g(this.recentQuery.getState().data)
241
- ], t = new Set(e.map((s) => s.id));
242
- for (const s of this.optimisticEntities.keys())
243
- t.has(s) && this.optimisticEntities.delete(s);
244
- for (const s of e) this.applyOverrides(s, this.completedRefreshSequence);
248
+ ], t = new Set(e.map((i) => i.id));
249
+ for (const i of this.optimisticEntities.keys())
250
+ t.has(i) && this.optimisticEntities.delete(i);
251
+ for (const i of e) this.applyOverrides(i, this.completedRefreshSequence);
245
252
  this.publish();
246
253
  }
247
254
  async loadAllPinned() {
248
255
  const e = [];
249
256
  let t = null;
250
257
  do {
251
- const s = await this.loadPage({ cursor: t, limit: this.limit, pinned: !0 });
252
- e.push(...s.sessions), t = s.nextCursor;
258
+ const i = await this.loadPage({ cursor: t, limit: this.limit, pinned: !0 });
259
+ e.push(...i.sessions), t = i.nextCursor;
253
260
  } while (t);
254
261
  return e;
255
262
  }
256
263
  applyOverrides(e, t) {
257
- let s = e;
264
+ let i = e;
258
265
  const n = this.activityOverrides.get(e.id);
259
- n && (t >= n.confirmAfterRefresh && e.isActive === n.isActive ? this.activityOverrides.delete(e.id) : t >= n.releaseAfterRefresh ? this.activityOverrides.delete(e.id) : s = { ...s, isActive: n.isActive });
266
+ n && (t >= n.confirmAfterRefresh && e.isActive === n.isActive ? this.activityOverrides.delete(e.id) : t >= n.releaseAfterRefresh ? this.activityOverrides.delete(e.id) : i = { ...i, isActive: n.isActive });
260
267
  const a = this.pinnedOverrides.get(e.id);
261
- return a && (t >= a.confirmAfterRefresh && e.isPinned === !0 === a.pinned ? this.pinnedOverrides.delete(e.id) : s = { ...s, isPinned: a.pinned }), this.titleOverrides.has(e.id) && (s = { ...s, customTitle: this.titleOverrides.get(e.id) ?? null }), s;
268
+ return a && (t >= a.confirmAfterRefresh && e.isPinned === !0 === a.pinned ? this.pinnedOverrides.delete(e.id) : i = { ...i, isPinned: a.pinned }), this.titleOverrides.has(e.id) && (i = { ...i, customTitle: this.titleOverrides.get(e.id) ?? null }), i;
262
269
  }
263
270
  updateProjection() {
264
271
  this.publish();
265
272
  }
266
273
  updateEntity(e, t) {
267
- const s = this.optimisticEntities.get(e);
268
- s && this.optimisticEntities.set(e, t(s)), this.publish();
274
+ const i = this.optimisticEntities.get(e);
275
+ i && this.optimisticEntities.set(e, t(i)), this.publish();
269
276
  }
270
277
  hasUnconfirmedActivityOverride() {
271
278
  return Array.from(this.activityOverrides.values()).some(
@@ -276,16 +283,16 @@ class H {
276
283
  for (const e of this.listeners) e(this.getState());
277
284
  }
278
285
  }
279
- function g(i) {
280
- return i ? i.ids.map((e) => i.entitiesById[e]).filter((e) => !!e) : [];
286
+ function g(s) {
287
+ return s ? s.ids.map((e) => s.entitiesById[e]).filter((e) => !!e) : [];
281
288
  }
282
- function R(i, e) {
283
- return i.status === "error" || e.status === "error" ? "error" : i.status === "loading" || e.status === "loading" ? "loading" : i.status === "refreshing" || e.status === "refreshing" ? "refreshing" : i.status === "loading_more" ? "loading_more" : i.status === "ready" || e.status === "ready" ? "ready" : "not_requested";
289
+ function x(s, e) {
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";
284
291
  }
285
- class G {
292
+ class J {
286
293
  constructor(e, t = null) {
287
294
  this.storage = e, t && (this.decisions = new Map(
288
- t.filter(I).map((s) => [this.getDecisionKey(s), s])
295
+ t.filter(I).map((i) => [this.getDecisionKey(i), i])
289
296
  ), this.initialized = !0);
290
297
  }
291
298
  storage;
@@ -301,58 +308,58 @@ class G {
301
308
  ), this.initialized = !0;
302
309
  }
303
310
  isEligible(e, t = Date.now()) {
304
- const s = this.scheduledEligibility.get(this.getExactKey(e));
305
- return s !== void 0 && s > t ? !1 : this.isDecisionEligible(this.decisions.get(this.getExactKey(e)), t) && this.isDecisionEligible(this.decisions.get(this.getCategoryKey(e)), t);
311
+ const i = this.scheduledEligibility.get(this.getExactKey(e));
312
+ return i !== void 0 && i > t ? !1 : this.isDecisionEligible(this.decisions.get(this.getExactKey(e)), t) && this.isDecisionEligible(this.decisions.get(this.getCategoryKey(e)), t);
306
313
  }
307
314
  getDecision(e) {
308
315
  return this.decisions.get(this.getExactKey(e)) ?? this.decisions.get(this.getCategoryKey(e)) ?? null;
309
316
  }
310
317
  getStatus(e, t = Date.now()) {
311
- const s = this.scheduledEligibility.get(this.getExactKey(e));
312
- if (s !== void 0 && s > t) return "scheduled";
318
+ const i = this.scheduledEligibility.get(this.getExactKey(e));
319
+ if (i !== void 0 && i > t) return "scheduled";
313
320
  const n = this.getDecision(e);
314
321
  return n ? n.action === "never" || n.action === "dont_show_again" ? "suppressed" : n.action === "dismiss" ? "resolved" : n.nextEligibleAt && Date.parse(n.nextEligibleAt) > t ? "snoozed" : "presentable" : "presentable";
315
322
  }
316
323
  scheduleEligibility(e, t) {
317
- const s = this.getExactKey(e), n = this.scheduledEligibility.get(s);
318
- return n !== void 0 ? n : (this.scheduledEligibility.set(s, t), t);
324
+ const i = this.getExactKey(e), n = this.scheduledEligibility.get(i);
325
+ return n !== void 0 ? n : (this.scheduledEligibility.set(i, t), t);
319
326
  }
320
327
  getNextEligibilityAt(e = Date.now()) {
321
328
  const t = [
322
- ...Array.from(this.scheduledEligibility.values()).filter((s) => s > e),
323
- ...Array.from(this.decisions.values()).map((s) => s.nextEligibleAt ? Date.parse(s.nextEligibleAt) : Number.NaN).filter((s) => Number.isFinite(s) && s > e)
329
+ ...Array.from(this.scheduledEligibility.values()).filter((i) => i > e),
330
+ ...Array.from(this.decisions.values()).map((i) => i.nextEligibleAt ? Date.parse(i.nextEligibleAt) : Number.NaN).filter((i) => Number.isFinite(i) && i > e)
324
331
  ];
325
332
  return t.length > 0 ? Math.min(...t) : null;
326
333
  }
327
- act(e, t, s = {}) {
328
- const n = this.actionQueue.then(() => this.applyAction(e, t, s));
334
+ act(e, t, i = {}) {
335
+ const n = this.actionQueue.then(() => this.applyAction(e, t, i));
329
336
  return this.actionQueue = n.then(() => {
330
337
  }, () => {
331
338
  }), n;
332
339
  }
333
- async applyAction(e, t, s) {
340
+ async applyAction(e, t, i) {
334
341
  if (!e.allowedActions.includes(t))
335
342
  throw new Error(`Interaction ${e.key} does not allow ${t}.`);
336
- if (!D(t))
343
+ if (!O(t))
337
344
  throw new Error(`Interaction action ${t} is not a persistence decision.`);
338
- const n = s.now ?? /* @__PURE__ */ new Date(), a = {
345
+ const n = i.now ?? /* @__PURE__ */ new Date(), a = {
339
346
  promptKey: e.key,
340
347
  category: e.category,
341
348
  action: t,
342
349
  scope: e.scope,
343
350
  decidedAt: n.toISOString(),
344
- nextEligibleAt: this.getNextEligibleAt(e, t, n, s.snoozeUntil)
345
- }, l = t === "dont_show_again" ? this.getCategoryKey(e) : this.getExactKey(e), r = new Map(this.decisions);
346
- return r.set(l, a), await this.storage.save([...r.values()]), this.decisions = r, a;
351
+ nextEligibleAt: this.getNextEligibleAt(e, t, n, i.snoozeUntil)
352
+ }, c = t === "dont_show_again" ? this.getCategoryKey(e) : this.getExactKey(e), r = new Map(this.decisions);
353
+ return r.set(c, a), await this.storage.save([...r.values()]), this.decisions = r, a;
347
354
  }
348
355
  isDecisionEligible(e, t) {
349
356
  return e ? e.action === "dismiss" || e.action === "never" || e.action === "dont_show_again" ? !1 : !e.nextEligibleAt || Date.parse(e.nextEligibleAt) <= t : !0;
350
357
  }
351
- getNextEligibleAt(e, t, s, n) {
358
+ getNextEligibleAt(e, t, i, n) {
352
359
  if (t === "later")
353
- return new Date(s.getTime() + (e.laterDelayMs ?? 3600 * 1e3)).toISOString();
360
+ return new Date(i.getTime() + (e.laterDelayMs ?? 3600 * 1e3)).toISOString();
354
361
  if (t === "snooze") {
355
- if (!n || n.getTime() <= s.getTime())
362
+ if (!n || n.getTime() <= i.getTime())
356
363
  throw new Error("Snooze requires a future next-eligible time.");
357
364
  return n.toISOString();
358
365
  }
@@ -369,41 +376,41 @@ class G {
369
376
  return `${b(e.scope)}:category:${e.category}`;
370
377
  }
371
378
  }
372
- function V(i, e) {
379
+ function W(s, e) {
373
380
  return {
374
- load: async () => x(i, e),
375
- save: async (t) => i.setItem(e, JSON.stringify(t))
381
+ load: async () => L(s, e),
382
+ save: async (t) => s.setItem(e, JSON.stringify(t))
376
383
  };
377
384
  }
378
- function x(i, e) {
379
- const t = i.getItem(e);
385
+ function L(s, e) {
386
+ const t = s.getItem(e);
380
387
  if (!t) return [];
381
- const s = JSON.parse(t);
382
- return Array.isArray(s) ? s.filter(I) : [];
388
+ const i = JSON.parse(t);
389
+ return Array.isArray(i) ? i.filter(I) : [];
383
390
  }
384
- function b(i) {
385
- return `${i.level}:${i.key}`;
391
+ function b(s) {
392
+ return `${s.level}:${s.key}`;
386
393
  }
387
- function D(i) {
388
- return i === "dismiss" || i === "later" || i === "snooze" || i === "never" || i === "dont_show_again";
394
+ function O(s) {
395
+ return s === "dismiss" || s === "later" || s === "snooze" || s === "never" || s === "dont_show_again";
389
396
  }
390
- function I(i) {
391
- if (!i || typeof i != "object") return !1;
392
- const e = i;
393
- return typeof e.promptKey == "string" && typeof e.category == "string" && typeof e.decidedAt == "string" && (e.nextEligibleAt === null || typeof e.nextEligibleAt == "string") && D(e.action) && !!(e.scope && typeof e.scope == "object" && typeof e.scope.level == "string" && typeof e.scope.key == "string");
397
+ function I(s) {
398
+ if (!s || typeof s != "object") return !1;
399
+ const e = s;
400
+ return typeof e.promptKey == "string" && typeof e.category == "string" && typeof e.decidedAt == "string" && (e.nextEligibleAt === null || typeof e.nextEligibleAt == "string") && O(e.action) && !!(e.scope && typeof e.scope == "object" && typeof e.scope.level == "string" && typeof e.scope.key == "string");
394
401
  }
395
- const C = {
402
+ const q = {
396
403
  working: "⏳",
397
404
  completed: "✅",
398
405
  failed: "❗",
399
406
  stopped: "⏹️"
400
- }, L = /^(?:⌛|⏳|✅|❗|⏹️) Pluno(?:: )?/;
401
- function q(i, e) {
402
- if (!e) return y(i);
403
- const t = y(i), s = `${C[e]} Pluno`;
404
- return t ? `${s}: ${t}` : s;
407
+ }, U = /^(?:⌛|⏳|✅|❗|⏹️) Pluno(?:: )?/;
408
+ function Q(s, e) {
409
+ if (!e) return y(s);
410
+ const t = y(s), i = `${q[e]} Pluno`;
411
+ return t ? `${i}: ${t}` : i;
405
412
  }
406
- class Z {
413
+ class Y {
407
414
  constructor(e) {
408
415
  this.titleDocument = e;
409
416
  }
@@ -420,16 +427,16 @@ class Z {
420
427
  this.liveStatusVersion += 1, this.applyClear();
421
428
  }
422
429
  async syncStatus(e) {
423
- const t = this.liveStatusVersion, s = await e();
424
- s === void 0 || t !== this.liveStatusVersion || (s ? this.applyStatus(s) : this.applyClear());
430
+ const t = this.liveStatusVersion, i = await e();
431
+ i === void 0 || t !== this.liveStatusVersion || (i ? this.applyStatus(i) : this.applyClear());
425
432
  }
426
433
  applyStatus(e) {
427
434
  const t = this.titleDocument.getTitle();
428
435
  t !== this.lastAppliedTitle && (this.baseTitle = y(t)), this.status = e, this.stopObserving || (this.stopObserving = this.titleDocument.observeTitle(() => this.handleTitleChanged())), this.applyTitle();
429
436
  }
430
437
  applyClear() {
431
- const e = this.titleDocument.getTitle(), t = this.lastAppliedTitle !== null && e === this.lastAppliedTitle, s = this.lastAppliedTitle === null ? y(e) : e;
432
- this.status = null, this.lastAppliedTitle = null, this.stopObserving?.(), this.stopObserving = null, t ? this.titleDocument.setTitle(this.baseTitle) : s !== e && this.titleDocument.setTitle(s);
438
+ const e = this.titleDocument.getTitle(), t = this.lastAppliedTitle !== null && e === this.lastAppliedTitle, i = this.lastAppliedTitle === null ? y(e) : e;
439
+ this.status = null, this.lastAppliedTitle = null, this.stopObserving?.(), this.stopObserving = null, t ? this.titleDocument.setTitle(this.baseTitle) : i !== e && this.titleDocument.setTitle(i);
433
440
  }
434
441
  handleTitleChanged() {
435
442
  !this.status || this.titleDocument.getTitle() === this.lastAppliedTitle || this.applyTitle();
@@ -437,19 +444,19 @@ class Z {
437
444
  applyTitle() {
438
445
  if (!this.status)
439
446
  return;
440
- const e = q(this.baseTitle, this.status);
447
+ const e = Q(this.baseTitle, this.status);
441
448
  this.lastAppliedTitle = e, this.titleDocument.getTitle() !== e && this.titleDocument.setTitle(e);
442
449
  }
443
450
  }
444
- function J(i) {
451
+ function X(s) {
445
452
  return {
446
- getTitle: () => i.title,
453
+ getTitle: () => s.title,
447
454
  setTitle: (e) => {
448
- i.title = e;
455
+ s.title = e;
449
456
  },
450
457
  observeTitle: (e) => {
451
458
  const t = new MutationObserver(e);
452
- return t.observe(i.head, {
459
+ return t.observe(s.head, {
453
460
  childList: !0,
454
461
  subtree: !0,
455
462
  characterData: !0
@@ -457,20 +464,20 @@ function J(i) {
457
464
  }
458
465
  };
459
466
  }
460
- function y(i) {
461
- return i.replace(L, "");
467
+ function y(s) {
468
+ return s.replace(U, "");
462
469
  }
463
- function _(i, e) {
470
+ function P(s, e) {
464
471
  const t = new Set([
465
- i.assistantDraftRespondsToUserMessageId,
466
- i.activeResponseUserMessageId,
467
- i.messages.filter((n) => n.role === "user").slice(-1)[0]?.id
468
- ].filter((n) => !!n)), s = i.messages.filter((n) => !(n.dataType === "run_status" && n.loading && t.has(n.respondsToUserMessageId ?? ""))).map((n) => t.has(n.respondsToUserMessageId ?? "") ? { ...n, loading: !1 } : n);
472
+ s.assistantDraftRespondsToUserMessageId,
473
+ s.activeResponseUserMessageId,
474
+ s.messages.filter((n) => n.role === "user").slice(-1)[0]?.id
475
+ ].filter((n) => !!n)), i = s.messages.filter((n) => !(n.dataType === "run_status" && n.loading && t.has(n.respondsToUserMessageId ?? ""))).map((n) => t.has(n.respondsToUserMessageId ?? "") ? { ...n, loading: !1 } : n);
469
476
  for (const n of t)
470
- s.some((a) => a.respondsToUserMessageId === n && (a.dataType === "run_status" || a.dataType === "run_error" || a.role === "assistant" && a.phase !== "commentary")) || s.push({ id: `local-interrupted:${n}`, role: "system", dataType: "run_status", content: "Run stopped by user.", createdAt: e, respondsToUserMessageId: n });
477
+ i.some((a) => a.respondsToUserMessageId === n && (a.dataType === "run_status" || a.dataType === "run_error" || a.role === "assistant" && a.phase !== "commentary")) || i.push({ id: `local-interrupted:${n}`, role: "system", dataType: "run_status", content: "Run stopped by user.", createdAt: e, respondsToUserMessageId: n });
471
478
  return {
472
- ...i,
473
- messages: s,
479
+ ...s,
480
+ messages: i,
474
481
  isThinking: !1,
475
482
  isRetrying: !1,
476
483
  pendingMessageStatus: null,
@@ -480,18 +487,18 @@ function _(i, e) {
480
487
  lastErrorCode: null
481
488
  };
482
489
  }
483
- const S = (i) => i === null || typeof i == "string" && /^[a-zA-Z0-9:_-]{1,160}$/.test(i);
484
- function Q(i) {
485
- if (!i || typeof i != "object") return !1;
486
- const e = i;
490
+ const S = (s) => s === null || typeof s == "string" && /^[a-zA-Z0-9:_-]{1,160}$/.test(s);
491
+ function N(s) {
492
+ if (!s || typeof s != "object") return !1;
493
+ const e = s;
487
494
  return typeof e.observedAt == "string" && e.observedAt.length <= 40 && Number.isFinite(Date.parse(e.observedAt)) && S(e.sessionId) && S(e.responseItemId) && S(e.respondsToUserMessageId) && typeof e.panelVisible == "boolean" && typeof e.documentVisible == "boolean" && typeof e.loading == "boolean";
488
495
  }
489
- const M = 500;
490
- function U(i) {
491
- const e = i.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();
492
- return e.length > M ? `${e.slice(0, M - 1)}…` : e;
496
+ const _ = 500;
497
+ function $(s) {
498
+ 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();
499
+ return e.length > _ ? `${e.slice(0, _ - 1)}…` : e;
493
500
  }
494
- const $ = {
501
+ const B = {
495
502
  "in-progress-stop-unavailable": "An in-progress response has no visible enabled interrupt control.",
496
503
  "stop-did-not-interrupt": "The stopped response remained in progress after an interrupt click.",
497
504
  "duplicate-message-item": "A canonical message rendered more than once.",
@@ -506,23 +513,23 @@ const $ = {
506
513
  "thinking-groups-without-user-message": "Multiple thinking groups appeared without a user message between them.",
507
514
  "thinking-without-progress": "Thinking remained visible without progress for five minutes."
508
515
  };
509
- function K(i) {
510
- return typeof i == "string" && i.startsWith("ui_invariant:") && Object.prototype.hasOwnProperty.call($, i.slice(13));
516
+ function K(s) {
517
+ return typeof s == "string" && s.startsWith("ui_invariant:") && Object.prototype.hasOwnProperty.call(B, s.slice(13));
511
518
  }
512
- function P(i) {
519
+ function E(s) {
513
520
  return {
514
- ...i.id === void 0 ? {} : { id: i.id },
515
- name: i.name,
516
- mimeType: i.mimeType,
517
- sizeBytes: i.sizeBytes,
518
- ...i.sandboxPath === void 0 ? {} : { sandboxPath: i.sandboxPath },
519
- ...i.storageKey === void 0 ? {} : { storageKey: i.storageKey },
520
- ...i.fileUrl === void 0 ? {} : { fileUrl: i.fileUrl }
521
+ ...s.id === void 0 ? {} : { id: s.id },
522
+ name: s.name,
523
+ mimeType: s.mimeType,
524
+ sizeBytes: s.sizeBytes,
525
+ ...s.sandboxPath === void 0 ? {} : { sandboxPath: s.sandboxPath },
526
+ ...s.storageKey === void 0 ? {} : { storageKey: s.storageKey },
527
+ ...s.fileUrl === void 0 ? {} : { fileUrl: s.fileUrl }
521
528
  };
522
529
  }
523
- function Y(i) {
524
- if (!i || typeof i != "object" || !("type" in i)) return !1;
525
- const e = i;
530
+ function ee(s) {
531
+ if (!s || typeof s != "object" || !("type" in s)) return !1;
532
+ const e = s;
526
533
  switch (e.type) {
527
534
  case "runtime.connect":
528
535
  case "session.new":
@@ -531,7 +538,7 @@ function Y(i) {
531
538
  case "run.stop":
532
539
  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);
533
540
  case "runtime.report_response_visibility":
534
- return Q(e.observation);
541
+ return N(e.observation);
535
542
  case "runtime.warmup":
536
543
  return e.reason === "panel_open" || e.reason === "extension_install" || e.reason === "composer_input";
537
544
  case "runtime.report_displayed_error":
@@ -565,9 +572,9 @@ function Y(i) {
565
572
  return !1;
566
573
  }
567
574
  }
568
- class W {
569
- constructor(e, t, s) {
570
- this.adapter = t, this.state = A(e), this.model = s;
575
+ class te {
576
+ constructor(e, t, i) {
577
+ this.adapter = t, this.state = A(e), this.model = i;
571
578
  }
572
579
  adapter;
573
580
  listeners = {};
@@ -587,57 +594,57 @@ class W {
587
594
  operationQueue = Promise.resolve();
588
595
  destroyed = !1;
589
596
  on(e, t) {
590
- const s = this.listeners[e] ?? /* @__PURE__ */ new Set();
591
- return s.add(t), this.listeners[e] = s, () => s.delete(t);
597
+ const i = this.listeners[e] ?? /* @__PURE__ */ new Set();
598
+ return i.add(t), this.listeners[e] = i, () => i.delete(t);
592
599
  }
593
600
  getState() {
594
601
  return A(this.state);
595
602
  }
596
- updateProjection(e, t, s, n, a) {
603
+ updateProjection(e, t, i, n, a) {
597
604
  if (this.destroyed) return;
598
- const l = this.state;
599
- if (this.state = A(e), l.user?.id === e.user?.id)
605
+ const c = this.state;
606
+ if (this.state = A(e), c.user?.id === e.user?.id)
600
607
  for (const r of this.state.messages) {
601
608
  if (r.role !== "user" || !r.attachments?.length) continue;
602
- const o = r.clientMessageId, c = l.messages.find((u) => u.role === "user" && (u.id === r.id || o && u.clientMessageId === o));
603
- l.sessionId !== e.sessionId && !(l.sessionId === null && o && c?.clientMessageId === o) || (r.attachments = T(c?.attachments, r.attachments));
609
+ const l = r.clientMessageId, d = c.messages.find((u) => u.role === "user" && (u.id === r.id || l && u.clientMessageId === l));
610
+ c.sessionId !== e.sessionId && !(c.sessionId === null && l && d?.clientMessageId === l) || (r.attachments = M(d?.attachments, r.attachments));
604
611
  }
605
612
  if (this.stoppedProjection) {
606
- const r = this.stoppedProjection, o = new Set(r.messages.filter((d) => d.role === "user").map((d) => d.id)), c = e.sessionId === r.sessionId && e.user?.id === r.user?.id, u = e.messages.some((d) => d.role === "user" && !o.has(d.id) && !r.messages.some((h) => h.clientMessageId && h.clientMessageId === d.clientMessageId));
607
- if (!c || u)
613
+ const r = this.stoppedProjection, l = new Set(r.messages.filter((o) => o.role === "user").map((o) => o.id)), d = e.sessionId === r.sessionId && e.user?.id === r.user?.id, u = e.messages.some((o) => o.role === "user" && !l.has(o.id) && !r.messages.some((h) => h.clientMessageId && h.clientMessageId === o.clientMessageId));
614
+ if (!d || u)
608
615
  this.stoppedProjection = null;
609
616
  else {
610
- const d = [
617
+ const o = [
611
618
  r.activeResponseUserMessageId,
612
619
  r.assistantDraftRespondsToUserMessageId,
613
620
  r.messages.filter((v) => v.role === "user").slice(-1)[0]?.id
614
- ].filter(Boolean), h = d.length > 0 && d.every((v) => e.messages.some((p) => p.respondsToUserMessageId === v && !p.loading && (p.dataType === "run_status" || p.dataType === "run_error" || p.role === "assistant" && p.phase !== "commentary")));
615
- this.state = _(h ? this.state : {
621
+ ].filter(Boolean), h = o.length > 0 && o.every((v) => e.messages.some((p) => p.respondsToUserMessageId === v && !p.loading && (p.dataType === "run_status" || p.dataType === "run_error" || p.role === "assistant" && p.phase !== "commentary")));
622
+ this.state = P(h ? this.state : {
616
623
  ...this.state,
617
624
  messages: r.messages,
618
625
  assistantDraft: r.assistantDraft
619
626
  }, (/* @__PURE__ */ new Date()).toISOString()), this.stoppedProjection = this.getState();
620
627
  }
621
628
  }
622
- for (const [r, o] of this.unacknowledgedSubmissions) {
623
- if (e.user?.id !== o.userId || o.sessionId !== null && e.sessionId !== o.sessionId) {
629
+ for (const [r, l] of this.unacknowledgedSubmissions) {
630
+ if (e.user?.id !== l.userId || l.sessionId !== null && e.sessionId !== l.sessionId) {
624
631
  this.unacknowledgedSubmissions.delete(r);
625
632
  continue;
626
633
  }
627
- const c = this.state.messages.find(
634
+ const d = this.state.messages.find(
628
635
  (u) => u.clientMessageId === r
629
636
  );
630
- if (c) {
631
- c.attachments = T(
632
- o.message.attachments,
633
- c.attachments
637
+ if (d) {
638
+ d.attachments = M(
639
+ l.message.attachments,
640
+ d.attachments
634
641
  ), this.unacknowledgedSubmissions.delete(r);
635
642
  continue;
636
643
  }
637
- o.sessionId ??= e.sessionId, this.state.messages.push(o.message), this.state.pendingMessageStatus = "sending", this.state.turnPhase ??= "sending", this.state.taskStatus ??= "working";
644
+ l.sessionId ??= e.sessionId, this.state.messages.push(l.message), this.state.pendingMessageStatus = "sending", this.state.turnPhase ??= "sending", this.state.taskStatus ??= "working";
638
645
  }
639
- if (t !== void 0 && (this.model = t), s && JSON.stringify(s) !== JSON.stringify(this.sessionHistoryState)) {
640
- this.sessionHistoryState = E(s);
646
+ if (t !== void 0 && (this.model = t), i && JSON.stringify(i) !== JSON.stringify(this.sessionHistoryState)) {
647
+ this.sessionHistoryState = T(i);
641
648
  for (const r of this.sessionHistoryListeners)
642
649
  r(this.getSessionHistoryState());
643
650
  }
@@ -680,33 +687,33 @@ class W {
680
687
  }).catch(() => {
681
688
  });
682
689
  }
683
- reportDisplayedError(e, t, s) {
690
+ reportDisplayedError(e, t, i) {
684
691
  this.adapter.dispatch({
685
692
  type: "runtime.report_displayed_error",
686
693
  reason: e,
687
694
  errorFingerprint: t,
688
- ...s ? { displayedMessage: U(s) } : {}
695
+ ...i ? { displayedMessage: $(i) } : {}
689
696
  }).catch(() => {
690
697
  });
691
698
  }
692
699
  sendMessage(e, t = {}) {
693
- const s = e.trim(), n = t.attachments ?? [];
694
- if (!s && n.length === 0) return Promise.resolve(null);
695
- const a = t.clientMessageId ?? (t.proactiveSuggestionQuestion && this.stagedProactiveSuggestionClientMessageId ? this.stagedProactiveSuggestionClientMessageId : crypto.randomUUID()), l = t.submittedAt ?? Date.now(), r = this.state, o = this.submissionGeneration, c = {
700
+ const i = e.trim(), n = t.attachments ?? [];
701
+ if (!i && n.length === 0) return Promise.resolve(null);
702
+ const a = t.clientMessageId ?? (t.proactiveSuggestionQuestion && this.stagedProactiveSuggestionClientMessageId ? this.stagedProactiveSuggestionClientMessageId : crypto.randomUUID()), c = t.submittedAt ?? Date.now(), r = this.state, l = this.submissionGeneration, d = {
696
703
  id: `local-${a}`,
697
704
  role: "user",
698
- content: s,
705
+ content: i,
699
706
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
700
707
  ...n.length > 0 ? { attachments: n } : {},
701
708
  clientMessageId: a
702
709
  };
703
710
  this.unacknowledgedSubmissions.set(a, {
704
- message: { ...c, attachments: c.attachments?.map((d) => ({ ...d })) },
711
+ message: { ...d, attachments: d.attachments?.map((o) => ({ ...o })) },
705
712
  sessionId: r.sessionId,
706
713
  userId: r.user?.id
707
714
  }), this.state = {
708
715
  ...this.state,
709
- messages: [...this.state.messages, c],
716
+ messages: [...this.state.messages, d],
710
717
  pendingMessageStatus: "sending",
711
718
  turnPhase: this.state.isThinking ? this.state.turnPhase : "sending",
712
719
  taskStatus: "working",
@@ -714,72 +721,77 @@ class W {
714
721
  lastError: null
715
722
  };
716
723
  const u = this.enqueueOperation(() => this.sendMessageNow(
717
- s,
718
- { ...t, clientMessageId: a, submittedAt: l },
724
+ i,
725
+ { ...t, clientMessageId: a, submittedAt: c },
719
726
  r,
720
- o
727
+ l
721
728
  ));
722
729
  return this.emit("state", this.getState()), u;
723
730
  }
724
- async sendMessageNow(e, t, s, n) {
725
- const a = e, l = t.clientMessageId;
726
- let r = t.attachments ?? [], o = !1;
731
+ async sendMessageNow(e, t, i, n) {
732
+ const a = e, c = t.clientMessageId;
733
+ let r = t.attachments ?? [], l = !1;
727
734
  if (n !== this.submissionGeneration) return null;
728
735
  try {
729
736
  if (await this.adapter.dispatch({
730
737
  type: "conversation.stage",
731
738
  content: a,
732
- clientMessageId: l,
739
+ clientMessageId: c,
733
740
  proactiveSuggestionQuestion: t.proactiveSuggestionQuestion,
734
741
  // Preview URLs belong to the renderer's optimistic snapshot and are not valid runtime-command metadata.
735
- attachments: r.length > 0 ? r.map(P) : void 0,
742
+ attachments: r.length > 0 ? r.map(E) : void 0,
736
743
  submittedAt: t.submittedAt
737
744
  }), n !== this.submissionGeneration) return null;
738
- if (o = !0, r.length > 0) {
745
+ if (l = !0, r.length > 0) {
739
746
  if (!this.adapter.uploadAttachment)
740
747
  throw new Error("The runtime does not support attachments.");
741
748
  const u = [];
742
- for (const d of r) {
743
- if (d.sandboxPath || d.storageKey) {
744
- u.push(d);
749
+ for (const o of r) {
750
+ if (o.sandboxPath || o.storageKey) {
751
+ u.push(o);
745
752
  continue;
746
753
  }
747
- const h = d.id ? this.attachmentFiles.get(d.id) : void 0;
748
- if (!h) throw new Error(`Attachment bytes are unavailable for ${d.name}`);
749
- if (u.push(await this.adapter.uploadAttachment(h, d, { clientMessageId: l })), n !== this.submissionGeneration) return null;
754
+ const h = o.id ? this.attachmentFiles.get(o.id) : void 0;
755
+ if (!h) throw new Error(`Attachment bytes are unavailable for ${o.name}`);
756
+ if (u.push(await this.adapter.uploadAttachment(h, o, { clientMessageId: c })), n !== this.submissionGeneration) return null;
750
757
  }
751
758
  r = u;
752
759
  }
753
- const c = await this.adapter.dispatch({
760
+ const d = await this.adapter.dispatch({
754
761
  type: "conversation.send",
755
762
  content: a,
756
- clientMessageId: l,
763
+ clientMessageId: c,
757
764
  initiatedBy: t.initiatedBy,
758
765
  invocation: t.invocation,
759
766
  proactiveSuggestionQuestion: t.proactiveSuggestionQuestion,
760
767
  ...t.automationOnboarding ? { automationOnboarding: !0 } : {},
761
- attachments: r.length > 0 ? r.map(P) : void 0
768
+ attachments: r.length > 0 ? r.map(E) : void 0
762
769
  });
763
770
  if (n !== this.submissionGeneration) return null;
764
771
  for (const u of t.attachments ?? [])
765
772
  u.id && this.attachmentFiles.delete(u.id);
766
- return l === this.stagedProactiveSuggestionClientMessageId && (this.stagedProactiveSuggestionClientMessageId = null), c?.clientMessageId ?? l;
767
- } catch (c) {
773
+ return c === this.stagedProactiveSuggestionClientMessageId && (this.stagedProactiveSuggestionClientMessageId = null), d?.clientMessageId ?? c;
774
+ } catch (d) {
768
775
  if (n !== this.submissionGeneration) return null;
769
- throw this.unacknowledgedSubmissions.delete(l), this.state = {
776
+ const u = C(d);
777
+ if (u)
778
+ for (const o of t.attachments ?? [])
779
+ o.id && this.attachmentFiles.delete(o.id);
780
+ throw this.unacknowledgedSubmissions.delete(c), this.state = {
770
781
  ...this.state,
771
- messages: this.state.messages.filter(
772
- (u) => u.id !== `local-${l}` && u.id !== `optimistic-user-message:${l}`
782
+ messages: u ? this.state.messages : this.state.messages.filter(
783
+ (o) => o.id !== `local-${c}` && o.id !== `optimistic-user-message:${c}`
773
784
  ),
774
- pendingMessageStatus: s.pendingMessageStatus,
775
- turnPhase: s.turnPhase,
776
- isThinking: s.isThinking,
777
- taskStatus: s.taskStatus
778
- }, this.emit("state", this.getState()), o && await this.adapter.dispatch({
785
+ pendingMessageStatus: i.pendingMessageStatus,
786
+ turnPhase: i.turnPhase,
787
+ isThinking: i.isThinking,
788
+ taskStatus: u ? "failed" : i.taskStatus,
789
+ ...u ? { lastError: d instanceof Error ? d.message : String(d), lastErrorCode: "auth_reconnecting" } : {}
790
+ }, this.emit("state", this.getState()), l && await this.adapter.dispatch({
779
791
  type: "conversation.fail_staged",
780
- clientMessageId: l,
781
- message: c instanceof Error ? c.message : String(c)
782
- }), c;
792
+ clientMessageId: c,
793
+ message: d instanceof Error ? d.message : String(d)
794
+ }), d;
783
795
  }
784
796
  }
785
797
  getModel() {
@@ -803,7 +815,7 @@ class W {
803
815
  }
804
816
  stop() {
805
817
  const e = this.cancelPendingSubmissions();
806
- this.state = _(this.state, (/* @__PURE__ */ new Date()).toISOString()), this.stoppedProjection = this.getState(), this.emit("state", this.getState());
818
+ this.state = P(this.state, (/* @__PURE__ */ new Date()).toISOString()), this.stoppedProjection = this.getState(), this.emit("state", this.getState());
807
819
  const t = this.adapter.dispatch({ type: "run.stop", ...e.length ? { clientMessageIds: e } : {} });
808
820
  return this.operationQueue = t.then(() => {
809
821
  }, () => {
@@ -814,8 +826,8 @@ class W {
814
826
  const e = [...this.unacknowledgedSubmissions.keys()];
815
827
  this.submissionGeneration++;
816
828
  for (const t of this.unacknowledgedSubmissions.values())
817
- for (const s of t.message.attachments ?? [])
818
- s.id && this.attachmentFiles.delete(s.id);
829
+ for (const i of t.message.attachments ?? [])
830
+ i.id && this.attachmentFiles.delete(i.id);
819
831
  return this.unacknowledgedSubmissions.clear(), this.operationQueue = Promise.resolve(), e;
820
832
  }
821
833
  startNewSession(e = {}) {
@@ -825,14 +837,14 @@ class W {
825
837
  async listSessions(e = {}) {
826
838
  const t = await this.dispatch({ type: "session.list", ...e });
827
839
  if (t === void 0) {
828
- const s = this.getSessionHistoryState().data;
829
- return { sessions: s ? s.ids.map((n) => s.entitiesById[n]) : [], nextCursor: s?.nextCursor ?? null };
840
+ const i = this.getSessionHistoryState().data;
841
+ return { sessions: i ? i.ids.map((n) => i.entitiesById[n]) : [], nextCursor: i?.nextCursor ?? null };
830
842
  }
831
843
  if (!t?.sessionHistoryPage) throw new Error("Session list command did not return a page.");
832
844
  return t.sessionHistoryPage;
833
845
  }
834
846
  getSessionHistoryState() {
835
- return E(this.sessionHistoryState);
847
+ return T(this.sessionHistoryState);
836
848
  }
837
849
  subscribeSessionHistory(e) {
838
850
  return this.sessionHistoryListeners.add(e), e(this.getSessionHistoryState()), () => this.sessionHistoryListeners.delete(e);
@@ -860,12 +872,12 @@ class W {
860
872
  subscribeInteractions(e) {
861
873
  return this.interactionListeners.add(e), e(this.getInteractions()), () => this.interactionListeners.delete(e);
862
874
  }
863
- actOnInteraction(e, t, s, n = {}) {
875
+ actOnInteraction(e, t, i, n = {}) {
864
876
  return this.dispatch({
865
877
  type: "interaction.act",
866
878
  interactionId: e,
867
879
  action: t,
868
- expectedRevision: s,
880
+ expectedRevision: i,
869
881
  ...n
870
882
  }).then(() => {
871
883
  });
@@ -886,11 +898,11 @@ class W {
886
898
  stageProactiveSuggestionQuestion(e) {
887
899
  const t = e.trim();
888
900
  if (!t) return Promise.resolve();
889
- const s = this.stagedProactiveSuggestionClientMessageId ?? crypto.randomUUID();
890
- return this.stagedProactiveSuggestionClientMessageId = s, this.dispatch({
901
+ const i = this.stagedProactiveSuggestionClientMessageId ?? crypto.randomUUID();
902
+ return this.stagedProactiveSuggestionClientMessageId = i, this.dispatch({
891
903
  type: "conversation.stage_proactive_suggestion",
892
904
  question: t,
893
- clientMessageId: s
905
+ clientMessageId: i
894
906
  }).then(() => {
895
907
  });
896
908
  }
@@ -907,73 +919,76 @@ class W {
907
919
  ), t;
908
920
  }
909
921
  emit(e, t) {
910
- const s = this.listeners[e];
911
- for (const n of s ?? []) n(t);
922
+ const i = this.listeners[e];
923
+ for (const n of i ?? []) n(t);
912
924
  }
913
925
  }
914
- function T(i, e) {
915
- if (!e || !i) return e;
926
+ function M(s, e) {
927
+ if (!e || !s) return e;
916
928
  const t = /* @__PURE__ */ new Map();
917
- for (const s of i) {
918
- const n = s.previewUrl;
919
- s.id && n && t.set(s.id, n);
929
+ for (const i of s) {
930
+ const n = i.previewUrl;
931
+ i.id && n && t.set(i.id, n);
920
932
  }
921
- return e.map((s) => {
922
- const n = s.id ? t.get(s.id) : void 0;
923
- return n ? { ...s, previewUrl: n } : s;
933
+ return e.map((i) => {
934
+ const n = i.id ? t.get(i.id) : void 0;
935
+ return n ? { ...i, previewUrl: n } : i;
924
936
  });
925
937
  }
926
- function A(i) {
938
+ function A(s) {
927
939
  return {
928
- ...i,
929
- starterPrompts: [...i.starterPrompts],
930
- appearance: i.appearance ? { ...i.appearance } : null,
931
- messages: i.messages.map((e) => {
940
+ ...s,
941
+ starterPrompts: [...s.starterPrompts],
942
+ appearance: s.appearance ? { ...s.appearance } : null,
943
+ messages: s.messages.map((e) => {
932
944
  const t = {
933
945
  ...e,
934
- attachments: e.attachments?.map((l) => ({ ...l }))
935
- }, s = e.assistantDraftItemId, n = e.clientMessageId, a = e.proactiveSuggestionClientMessageId;
946
+ attachments: e.attachments?.map((c) => ({ ...c }))
947
+ }, i = e.assistantDraftItemId, n = e.clientMessageId, a = e.proactiveSuggestionClientMessageId;
936
948
  return a && Object.defineProperty(t, "proactiveSuggestionClientMessageId", {
937
949
  value: a,
938
950
  enumerable: !1
939
- }), s && Object.defineProperty(t, "assistantDraftItemId", {
940
- value: s,
951
+ }), i && Object.defineProperty(t, "assistantDraftItemId", {
952
+ value: i,
941
953
  enumerable: !1
942
954
  }), n && Object.defineProperty(t, "clientMessageId", {
943
955
  value: n,
944
956
  enumerable: !1
945
957
  }), t;
946
958
  }),
947
- activeScheduledFollowUps: i.activeScheduledFollowUps?.map((e) => ({ ...e })) ?? null
959
+ activeScheduledFollowUps: s.activeScheduledFollowUps?.map((e) => ({ ...e })) ?? null
948
960
  };
949
961
  }
950
- function E(i) {
962
+ function T(s) {
951
963
  return {
952
- ...i,
953
- data: i.data ? m({
954
- entities: k(i.data).map((e) => ({ ...e })),
955
- nextCursor: i.data.nextCursor
964
+ ...s,
965
+ data: s.data ? m({
966
+ entities: R(s.data).map((e) => ({ ...e })),
967
+ nextCursor: s.data.nextCursor
956
968
  }) : null
957
969
  };
958
970
  }
959
971
  export {
960
- G as ProductAgentInteractionManager,
972
+ k as PRODUCT_AGENT_AUTH_RECONNECTING_ERROR_MESSAGE,
973
+ J as ProductAgentInteractionManager,
961
974
  w as ProductAgentQueryController,
962
- W as ProductAgentRemoteRuntimeClient,
963
- H as ProductAgentSessionHistoryManager,
964
- Z as ProductAgentTaskPageTitleController,
965
- V as createLocalStorageInteractionDecisionStorage,
975
+ te as ProductAgentRemoteRuntimeClient,
976
+ Z as ProductAgentSessionHistoryManager,
977
+ Y as ProductAgentTaskPageTitleController,
978
+ G as canSubmitPersonalProductAgentMessage,
979
+ W as createLocalStorageInteractionDecisionStorage,
966
980
  f as createProductAgentQueryState,
967
- J as createProductAgentTaskPageTitleDocument,
968
- q as formatProductAgentTaskPageTitle,
969
- j as hasProductAgentPaidCreditFallback,
970
- Y as isProductAgentRuntimeCommand,
971
- O as mergeProductAgentEntityPages,
981
+ X as createProductAgentTaskPageTitleDocument,
982
+ Q as formatProductAgentTaskPageTitle,
983
+ z as hasProductAgentPaidCreditFallback,
984
+ C as isProductAgentAuthReconnectError,
985
+ ee as isProductAgentRuntimeCommand,
986
+ D as mergeProductAgentEntityPages,
972
987
  m as normalizeProductAgentEntityPage,
973
- x as readLocalStorageInteractionDecisions,
974
- B as reconcileProductAgentSubmissionGate,
975
- F as resolveProductAgentBillingPresentation,
976
- z as resolveProductAgentComposerAction,
977
- N as resolveProductAgentWidgetPresentation,
978
- k as selectProductAgentQueryEntities
988
+ L as readLocalStorageInteractionDecisions,
989
+ j as reconcileProductAgentSubmissionGate,
990
+ H as resolveProductAgentBillingPresentation,
991
+ V as resolveProductAgentComposerAction,
992
+ F as resolveProductAgentWidgetPresentation,
993
+ R as selectProductAgentQueryEntities
979
994
  };