@pluno/product-agent-web 0.1.282 → 0.1.284
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/web/conversationPresentation.d.ts +1 -1
- package/dist/core/conversation/contracts.d.ts +1 -0
- package/dist/core/conversation/selectors.d.ts +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/product-agent-runtime.cjs +1 -1
- package/dist/product-agent-runtime.js +550 -516
- package/dist/product-agent-sdk.js +106 -70
- package/dist/product-agent-widget.js +4 -2
- package/dist/runtimeClient.d.ts +3 -0
- package/package.json +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
function
|
|
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"] } :
|
|
1
|
+
function Se(i, e) {
|
|
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"] } : i ?? { allowed: !0, reason: "allowed", actions: [] };
|
|
3
3
|
}
|
|
4
|
-
function
|
|
4
|
+
function _(i) {
|
|
5
5
|
return {
|
|
6
|
-
key:
|
|
6
|
+
key: i,
|
|
7
7
|
status: "not_requested",
|
|
8
8
|
data: null,
|
|
9
9
|
error: null,
|
|
@@ -12,8 +12,8 @@ function v(s) {
|
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
14
|
class q {
|
|
15
|
-
constructor(e, t,
|
|
16
|
-
this.loader = t, this.merge =
|
|
15
|
+
constructor(e, t, s = (n, r) => r) {
|
|
16
|
+
this.loader = t, this.merge = s, this.state = _(e);
|
|
17
17
|
}
|
|
18
18
|
loader;
|
|
19
19
|
merge;
|
|
@@ -28,10 +28,10 @@ class q {
|
|
|
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 =
|
|
31
|
+
e !== this.state.key && (this.state = _(e), this.trailingLoad = null, this.publish());
|
|
32
32
|
}
|
|
33
33
|
reset() {
|
|
34
|
-
this.state =
|
|
34
|
+
this.state = _(this.state.key), this.trailingLoad = null, this.publish();
|
|
35
35
|
}
|
|
36
36
|
invalidate() {
|
|
37
37
|
this.state = {
|
|
@@ -55,16 +55,16 @@ class q {
|
|
|
55
55
|
for (; this.trailingLoad; ) {
|
|
56
56
|
const e = this.trailingLoad;
|
|
57
57
|
this.trailingLoad = null;
|
|
58
|
-
const t = this.state.key,
|
|
58
|
+
const t = this.state.key, s = this.state.requestId + 1;
|
|
59
59
|
this.state = {
|
|
60
60
|
...this.state,
|
|
61
61
|
status: e.mode === "append" ? "loading_more" : this.state.data === null ? "loading" : "refreshing",
|
|
62
62
|
error: null,
|
|
63
|
-
requestId:
|
|
63
|
+
requestId: s
|
|
64
64
|
}, this.publish();
|
|
65
65
|
try {
|
|
66
66
|
const n = await this.loader({ key: t, cursor: e.cursor });
|
|
67
|
-
if (t !== this.state.key ||
|
|
67
|
+
if (t !== this.state.key || s !== this.state.requestId) continue;
|
|
68
68
|
this.state = {
|
|
69
69
|
...this.state,
|
|
70
70
|
status: "ready",
|
|
@@ -73,7 +73,7 @@ class q {
|
|
|
73
73
|
updatedAt: Date.now()
|
|
74
74
|
}, this.publish();
|
|
75
75
|
} catch (n) {
|
|
76
|
-
if (t !== this.state.key ||
|
|
76
|
+
if (t !== this.state.key || s !== this.state.requestId) continue;
|
|
77
77
|
this.state = {
|
|
78
78
|
...this.state,
|
|
79
79
|
status: "error",
|
|
@@ -86,68 +86,68 @@ class q {
|
|
|
86
86
|
for (const e of this.listeners) e(this.state);
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
-
function
|
|
89
|
+
function I(i) {
|
|
90
90
|
const e = {}, t = [];
|
|
91
|
-
for (const
|
|
92
|
-
e[
|
|
91
|
+
for (const s of i.entities)
|
|
92
|
+
e[s.id] || t.push(s.id), e[s.id] = s;
|
|
93
93
|
return {
|
|
94
94
|
entitiesById: e,
|
|
95
95
|
ids: t,
|
|
96
|
-
nextCursor:
|
|
96
|
+
nextCursor: i.nextCursor
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
|
-
function
|
|
100
|
-
if (t === "replace" ||
|
|
101
|
-
const
|
|
99
|
+
function Z(i, e, t) {
|
|
100
|
+
if (t === "replace" || i === null) return e;
|
|
101
|
+
const s = { ...i.entitiesById, ...e.entitiesById }, n = [...i.ids];
|
|
102
102
|
for (const r of e.ids)
|
|
103
|
-
|
|
104
|
-
return { entitiesById:
|
|
103
|
+
i.entitiesById[r] || n.push(r);
|
|
104
|
+
return { entitiesById: s, ids: n, nextCursor: e.nextCursor };
|
|
105
105
|
}
|
|
106
|
-
function
|
|
107
|
-
return
|
|
106
|
+
function J(i) {
|
|
107
|
+
return i ? i.ids.map((e) => i.entitiesById[e]).filter((e) => !!e) : [];
|
|
108
108
|
}
|
|
109
|
-
function
|
|
110
|
-
return
|
|
109
|
+
function we(i) {
|
|
110
|
+
return i.visible ? i.minimized ? { state: "minimized" } : { state: i.open ? "visible_open" : "visible_closed" } : { state: "hidden" };
|
|
111
111
|
}
|
|
112
|
-
function
|
|
113
|
-
if (!
|
|
114
|
-
const e =
|
|
112
|
+
function Ae(i) {
|
|
113
|
+
if (!i || typeof i != "object") return !1;
|
|
114
|
+
const e = i.paidCreditFallbackModel;
|
|
115
115
|
return typeof e == "string" && e.length > 0;
|
|
116
116
|
}
|
|
117
|
-
function
|
|
118
|
-
return
|
|
117
|
+
function Ee(i) {
|
|
118
|
+
return i ? i.submissionGate?.allowed === !1 ? ["credits_exhausted", "payment_issue", "onboarding_required"].includes(i.submissionGate.reason) ? { state: "action_required", reason: i.submissionGate.reason } : { state: "hidden" } : 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" };
|
|
119
119
|
}
|
|
120
|
-
function
|
|
121
|
-
return
|
|
120
|
+
function Pe(i) {
|
|
121
|
+
return i.submissionAllowed && i.isAuthenticated && i.hasWorkspace && !i.isWebsiteBlocked && i.isCurrentPageResolved && !i.isSubmitting && !i.hasPendingMessage;
|
|
122
122
|
}
|
|
123
|
-
function
|
|
124
|
-
const e =
|
|
125
|
-
return
|
|
123
|
+
function Me(i) {
|
|
124
|
+
const e = i.hasDraftMessage || i.hasPreSubmittedAttachment;
|
|
125
|
+
return i.hasRunningAssistantTurn && !e ? {
|
|
126
126
|
action: "stop",
|
|
127
|
-
disabled: !
|
|
127
|
+
disabled: !i.canStopRunningTurn
|
|
128
128
|
} : {
|
|
129
129
|
action: "send",
|
|
130
|
-
disabled: !e || !
|
|
130
|
+
disabled: !e || !i.canSubmitMessage
|
|
131
131
|
};
|
|
132
132
|
}
|
|
133
|
-
const
|
|
134
|
-
function O(
|
|
135
|
-
return (
|
|
133
|
+
const W = "Pluno is reconnecting. Try again in a moment.";
|
|
134
|
+
function O(i) {
|
|
135
|
+
return (i instanceof Error ? i.message : i) === W;
|
|
136
136
|
}
|
|
137
137
|
class Te {
|
|
138
|
-
constructor(e, t,
|
|
139
|
-
this.loadPage = t, this.limit =
|
|
138
|
+
constructor(e, t, s = 20) {
|
|
139
|
+
this.loadPage = t, this.limit = s, this.recentQuery = new q(
|
|
140
140
|
`${e}:recent`,
|
|
141
|
-
async ({ cursor: n }) =>
|
|
141
|
+
async ({ cursor: n }) => I(
|
|
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
|
+
Z
|
|
148
148
|
), this.pinnedQuery = new q(
|
|
149
149
|
`${e}:pinned`,
|
|
150
|
-
async () =>
|
|
150
|
+
async () => I({
|
|
151
151
|
entities: await this.loadAllPinned(),
|
|
152
152
|
nextCursor: null
|
|
153
153
|
})
|
|
@@ -166,19 +166,19 @@ class Te {
|
|
|
166
166
|
completedRefreshSequence = 0;
|
|
167
167
|
activityReconciliationScheduled = !1;
|
|
168
168
|
getState() {
|
|
169
|
-
const e = this.recentQuery.getState(), t = this.pinnedQuery.getState(),
|
|
170
|
-
...
|
|
171
|
-
...
|
|
172
|
-
], n = new Map(
|
|
173
|
-
(
|
|
174
|
-
),
|
|
175
|
-
entities: [...
|
|
169
|
+
const e = this.recentQuery.getState(), t = this.pinnedQuery.getState(), s = [
|
|
170
|
+
...v(t.data),
|
|
171
|
+
...v(e.data)
|
|
172
|
+
], n = new Map(s.map((c) => [c.id, c])), r = Array.from(n.values()).map(
|
|
173
|
+
(c) => this.applyOverrides(c, this.completedRefreshSequence)
|
|
174
|
+
), o = Array.from(this.optimisticEntities.values()).filter((c) => !n.has(c.id)).reverse(), a = e.data || t.data || o.length > 0 ? I({
|
|
175
|
+
entities: [...o, ...r],
|
|
176
176
|
nextCursor: e.data?.nextCursor ?? null
|
|
177
177
|
}) : null;
|
|
178
178
|
return {
|
|
179
179
|
key: e.key.slice(0, -7),
|
|
180
|
-
status:
|
|
181
|
-
data:
|
|
180
|
+
status: Y(e, t),
|
|
181
|
+
data: a,
|
|
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
|
|
@@ -223,56 +223,56 @@ class Te {
|
|
|
223
223
|
isActive: t,
|
|
224
224
|
confirmAfterRefresh: this.completedRefreshSequence + 1,
|
|
225
225
|
releaseAfterRefresh: this.completedRefreshSequence + 2
|
|
226
|
-
}), this.updateEntity(e, (
|
|
226
|
+
}), this.updateEntity(e, (s) => ({ ...s, isActive: t }));
|
|
227
227
|
}
|
|
228
228
|
setPinned(e, t) {
|
|
229
|
-
const
|
|
230
|
-
return this.pinnedOverrides.set(e,
|
|
229
|
+
const s = { pinned: t, confirmAfterRefresh: Number.POSITIVE_INFINITY };
|
|
230
|
+
return this.pinnedOverrides.set(e, s), this.updateEntity(e, (n) => ({ ...n, isPinned: t })), s;
|
|
231
231
|
}
|
|
232
232
|
confirmPinned(e, t) {
|
|
233
233
|
this.pinnedOverrides.get(e) === t && (t.confirmAfterRefresh = this.completedRefreshSequence + 1);
|
|
234
234
|
}
|
|
235
|
-
rollbackPinned(e, t,
|
|
236
|
-
this.pinnedOverrides.get(e) === t && (this.pinnedOverrides.delete(e), this.updateEntity(e, (n) => ({ ...n, isPinned:
|
|
235
|
+
rollbackPinned(e, t, s) {
|
|
236
|
+
this.pinnedOverrides.get(e) === t && (this.pinnedOverrides.delete(e), this.updateEntity(e, (n) => ({ ...n, isPinned: s })));
|
|
237
237
|
}
|
|
238
238
|
setTitle(e, t) {
|
|
239
|
-
this.titleOverrides.set(e, t), this.updateEntity(e, (
|
|
239
|
+
this.titleOverrides.set(e, t), this.updateEntity(e, (s) => ({ ...s, customTitle: t }));
|
|
240
240
|
}
|
|
241
241
|
confirmTitle(e) {
|
|
242
242
|
this.titleOverrides.delete(e);
|
|
243
243
|
}
|
|
244
244
|
reconcileDurableEntities() {
|
|
245
245
|
const e = [
|
|
246
|
-
...
|
|
247
|
-
...
|
|
248
|
-
], t = new Set(e.map((
|
|
249
|
-
for (const
|
|
250
|
-
t.has(
|
|
251
|
-
for (const
|
|
246
|
+
...v(this.pinnedQuery.getState().data),
|
|
247
|
+
...v(this.recentQuery.getState().data)
|
|
248
|
+
], t = new Set(e.map((s) => s.id));
|
|
249
|
+
for (const s of this.optimisticEntities.keys())
|
|
250
|
+
t.has(s) && this.optimisticEntities.delete(s);
|
|
251
|
+
for (const s of e) this.applyOverrides(s, this.completedRefreshSequence);
|
|
252
252
|
this.publish();
|
|
253
253
|
}
|
|
254
254
|
async loadAllPinned() {
|
|
255
255
|
const e = [];
|
|
256
256
|
let t = null;
|
|
257
257
|
do {
|
|
258
|
-
const
|
|
259
|
-
e.push(...
|
|
258
|
+
const s = await this.loadPage({ cursor: t, limit: this.limit, pinned: !0 });
|
|
259
|
+
e.push(...s.sessions), t = s.nextCursor;
|
|
260
260
|
} while (t);
|
|
261
261
|
return e;
|
|
262
262
|
}
|
|
263
263
|
applyOverrides(e, t) {
|
|
264
|
-
let
|
|
264
|
+
let s = e;
|
|
265
265
|
const n = this.activityOverrides.get(e.id);
|
|
266
|
-
n && (t >= n.confirmAfterRefresh && e.isActive === n.isActive ? this.activityOverrides.delete(e.id) : t >= n.releaseAfterRefresh ? this.activityOverrides.delete(e.id) :
|
|
266
|
+
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 });
|
|
267
267
|
const r = this.pinnedOverrides.get(e.id);
|
|
268
|
-
return r && (t >= r.confirmAfterRefresh && e.isPinned === !0 === r.pinned ? this.pinnedOverrides.delete(e.id) :
|
|
268
|
+
return r && (t >= r.confirmAfterRefresh && e.isPinned === !0 === r.pinned ? this.pinnedOverrides.delete(e.id) : s = { ...s, isPinned: r.pinned }), this.titleOverrides.has(e.id) && (s = { ...s, customTitle: this.titleOverrides.get(e.id) ?? null }), s;
|
|
269
269
|
}
|
|
270
270
|
updateProjection() {
|
|
271
271
|
this.publish();
|
|
272
272
|
}
|
|
273
273
|
updateEntity(e, t) {
|
|
274
|
-
const
|
|
275
|
-
|
|
274
|
+
const s = this.optimisticEntities.get(e);
|
|
275
|
+
s && this.optimisticEntities.set(e, t(s)), this.publish();
|
|
276
276
|
}
|
|
277
277
|
hasUnconfirmedActivityOverride() {
|
|
278
278
|
return Array.from(this.activityOverrides.values()).some(
|
|
@@ -283,47 +283,47 @@ class Te {
|
|
|
283
283
|
for (const e of this.listeners) e(this.getState());
|
|
284
284
|
}
|
|
285
285
|
}
|
|
286
|
-
function
|
|
287
|
-
return
|
|
286
|
+
function v(i) {
|
|
287
|
+
return i ? i.ids.map((e) => i.entitiesById[e]).filter((e) => !!e) : [];
|
|
288
288
|
}
|
|
289
|
-
function
|
|
290
|
-
return
|
|
289
|
+
function Y(i, e) {
|
|
290
|
+
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";
|
|
291
291
|
}
|
|
292
|
-
function
|
|
293
|
-
const e = /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})(?:\.(\d{1,6}))?(?:Z|\+00:00)$/.exec(
|
|
292
|
+
function C(i) {
|
|
293
|
+
const e = /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})(?:\.(\d{1,6}))?(?:Z|\+00:00)$/.exec(i);
|
|
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
|
|
298
|
-
if (
|
|
299
|
-
if (typeof
|
|
300
|
-
if (Array.isArray(
|
|
301
|
-
if (typeof
|
|
302
|
-
const e = Object.getPrototypeOf(
|
|
303
|
-
return e !== Object.prototype && e !== null ? !1 : Object.values(
|
|
297
|
+
function S(i) {
|
|
298
|
+
if (i === null || typeof i == "string" || typeof i == "boolean") return !0;
|
|
299
|
+
if (typeof i == "number") return Number.isFinite(i);
|
|
300
|
+
if (Array.isArray(i)) return i.every(S);
|
|
301
|
+
if (typeof i != "object") return !1;
|
|
302
|
+
const e = Object.getPrototypeOf(i);
|
|
303
|
+
return e !== Object.prototype && e !== null ? !1 : Object.values(i).every(S);
|
|
304
304
|
}
|
|
305
|
-
function
|
|
306
|
-
return
|
|
305
|
+
function $(i) {
|
|
306
|
+
return i !== null && typeof i == "object" && !Object.isFrozen(i) && (Object.values(i).forEach($), Object.freeze(i)), i;
|
|
307
307
|
}
|
|
308
|
-
function
|
|
309
|
-
if (!
|
|
310
|
-
return JSON.parse(JSON.stringify(
|
|
308
|
+
function X(i) {
|
|
309
|
+
if (!S(i)) throw new Error("Conversation inputs must be JSON-safe values.");
|
|
310
|
+
return JSON.parse(JSON.stringify(i));
|
|
311
311
|
}
|
|
312
|
-
function
|
|
312
|
+
function ee(i, e) {
|
|
313
313
|
if (!e) return !1;
|
|
314
|
-
const t =
|
|
314
|
+
const t = i.executionByUserMessage[e];
|
|
315
315
|
if (t) return ["completed", "stopped", "failed"].includes(t.phase);
|
|
316
|
-
const
|
|
316
|
+
const s = Object.values(i.items).sort((r, o) => C(r.created_at).localeCompare(C(o.created_at)) || r.id.localeCompare(o.id));
|
|
317
317
|
let n = !1;
|
|
318
|
-
for (const r of
|
|
319
|
-
if (r.type === "user_message" && (n = r.id === e), !!n && (r.type === "stopped" || r.type === "error" || r.type === "final_response" &&
|
|
318
|
+
for (const r of s)
|
|
319
|
+
if (r.type === "user_message" && (n = r.id === e), !!n && (r.type === "stopped" || r.type === "error" || r.type === "final_response" && i.streams[r.id]?.state === "finished" && i.streams[r.id].revision >= r.data.revision))
|
|
320
320
|
return !0;
|
|
321
321
|
return !1;
|
|
322
322
|
}
|
|
323
|
-
class
|
|
323
|
+
class ke {
|
|
324
324
|
constructor(e, t = null) {
|
|
325
325
|
this.storage = e, t && (this.decisions = new Map(
|
|
326
|
-
t.filter(
|
|
326
|
+
t.filter(M).map((s) => [this.getDecisionKey(s), s])
|
|
327
327
|
), this.initialized = !0);
|
|
328
328
|
}
|
|
329
329
|
storage;
|
|
@@ -341,11 +341,11 @@ class Pe {
|
|
|
341
341
|
receiveConversationSources(e) {
|
|
342
342
|
for (const t of e) {
|
|
343
343
|
if (!Number.isSafeInteger(t.version) || t.version < 0) throw new Error("Invalid interaction source version.");
|
|
344
|
-
const
|
|
344
|
+
const s = JSON.stringify([t.conversation_id, t.id]), n = this.sources.get(s);
|
|
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,
|
|
348
|
-
this.sources.set(
|
|
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(s, $(X({ ...t, lifecycle: r, payload: o }))), t.payload.kind === "integration_auth" && this.invalidateAuth(t.payload.request_id);
|
|
349
349
|
}
|
|
350
350
|
}
|
|
351
351
|
/** @internal */
|
|
@@ -355,40 +355,40 @@ class Pe {
|
|
|
355
355
|
/** @internal */
|
|
356
356
|
getConversationInputs(e) {
|
|
357
357
|
if (!this.conversationReader) return;
|
|
358
|
-
const t = { share: null, integrations: [], channel: null },
|
|
359
|
-
if (!
|
|
360
|
-
const n = [...this.sources.values()].filter((r) => r.conversation_id === e).sort((r,
|
|
358
|
+
const t = { share: null, integrations: [], channel: null }, s = e ? this.conversationReader(e) : null;
|
|
359
|
+
if (!s) 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));
|
|
361
361
|
for (const r of n) {
|
|
362
|
-
const
|
|
363
|
-
if (
|
|
364
|
-
if (t.share = null, !
|
|
365
|
-
const
|
|
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 ? s.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:
|
|
371
|
-
userPrompt:
|
|
370
|
+
variant: o.variant,
|
|
371
|
+
userPrompt: a?.type === "user_message" ? a.data.content : "",
|
|
372
372
|
assistantAnswer: ""
|
|
373
373
|
},
|
|
374
|
-
terminal: !
|
|
374
|
+
terminal: !o.wait_for_terminal || ee(s, r.user_message_id)
|
|
375
375
|
};
|
|
376
|
-
} else
|
|
376
|
+
} else o.kind === "integration_auth" ? t.integrations.push({
|
|
377
377
|
revision: r.version,
|
|
378
378
|
request: {
|
|
379
379
|
type: "pipedream_auth_required",
|
|
380
|
-
authRequestId:
|
|
381
|
-
appSlug:
|
|
382
|
-
appName:
|
|
383
|
-
appLogo:
|
|
384
|
-
expiresAt:
|
|
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
|
|
385
385
|
},
|
|
386
|
-
lifecycle: r.lifecycle === "pending" && Date.parse(
|
|
386
|
+
lifecycle: r.lifecycle === "pending" && Date.parse(o.expires_at) <= Date.now() ? "expired" : r.lifecycle
|
|
387
387
|
}) : t.channel = { revision: r.version, request: {
|
|
388
388
|
type: "personal_channel_connection_required",
|
|
389
|
-
requestId:
|
|
390
|
-
channel:
|
|
391
|
-
managementUrl:
|
|
389
|
+
requestId: o.request_id,
|
|
390
|
+
channel: o.channel,
|
|
391
|
+
managementUrl: o.management_url
|
|
392
392
|
}, lifecycle: r.lifecycle };
|
|
393
393
|
}
|
|
394
394
|
return t;
|
|
@@ -401,111 +401,111 @@ class Pe {
|
|
|
401
401
|
if (this.initialized) return;
|
|
402
402
|
const e = await this.storage.load();
|
|
403
403
|
this.decisions = new Map(
|
|
404
|
-
e.filter(
|
|
404
|
+
e.filter(M).map((t) => [this.getDecisionKey(t), t])
|
|
405
405
|
), this.initialized = !0;
|
|
406
406
|
}
|
|
407
407
|
isEligible(e, t = Date.now()) {
|
|
408
|
-
const
|
|
409
|
-
return
|
|
408
|
+
const s = this.scheduledEligibility.get(this.getExactKey(e));
|
|
409
|
+
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);
|
|
410
410
|
}
|
|
411
411
|
getDecision(e) {
|
|
412
412
|
return this.decisions.get(this.getExactKey(e)) ?? this.decisions.get(this.getCategoryKey(e)) ?? null;
|
|
413
413
|
}
|
|
414
414
|
getStatus(e, t = Date.now()) {
|
|
415
|
-
const
|
|
416
|
-
if (
|
|
415
|
+
const s = this.scheduledEligibility.get(this.getExactKey(e));
|
|
416
|
+
if (s !== void 0 && s > t) return "scheduled";
|
|
417
417
|
const n = this.getDecision(e);
|
|
418
418
|
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";
|
|
419
419
|
}
|
|
420
420
|
scheduleEligibility(e, t) {
|
|
421
|
-
const
|
|
422
|
-
return n !== void 0 ? n : (this.scheduledEligibility.set(
|
|
421
|
+
const s = this.getExactKey(e), n = this.scheduledEligibility.get(s);
|
|
422
|
+
return n !== void 0 ? n : (this.scheduledEligibility.set(s, t), t);
|
|
423
423
|
}
|
|
424
424
|
getNextEligibilityAt(e = Date.now()) {
|
|
425
425
|
const t = [
|
|
426
|
-
...Array.from(this.scheduledEligibility.values()).filter((
|
|
427
|
-
...Array.from(this.decisions.values()).map((
|
|
426
|
+
...Array.from(this.scheduledEligibility.values()).filter((s) => s > e),
|
|
427
|
+
...Array.from(this.decisions.values()).map((s) => s.nextEligibleAt ? Date.parse(s.nextEligibleAt) : Number.NaN).filter((s) => Number.isFinite(s) && s > e)
|
|
428
428
|
];
|
|
429
429
|
return t.length > 0 ? Math.min(...t) : null;
|
|
430
430
|
}
|
|
431
|
-
act(e, t,
|
|
432
|
-
const n = this.actionQueue.then(() => this.applyAction(e, t,
|
|
431
|
+
act(e, t, s = {}) {
|
|
432
|
+
const n = this.actionQueue.then(() => this.applyAction(e, t, s));
|
|
433
433
|
return this.actionQueue = n.then(() => {
|
|
434
434
|
}, () => {
|
|
435
435
|
}), n;
|
|
436
436
|
}
|
|
437
|
-
async applyAction(e, t,
|
|
437
|
+
async applyAction(e, t, s) {
|
|
438
438
|
if (!e.allowedActions.includes(t))
|
|
439
439
|
throw new Error(`Interaction ${e.key} does not allow ${t}.`);
|
|
440
|
-
if (
|
|
440
|
+
if (!U(t))
|
|
441
441
|
throw new Error(`Interaction action ${t} is not a persistence decision.`);
|
|
442
|
-
const n =
|
|
442
|
+
const n = s.now ?? /* @__PURE__ */ new Date(), r = {
|
|
443
443
|
promptKey: e.key,
|
|
444
444
|
category: e.category,
|
|
445
445
|
action: t,
|
|
446
446
|
scope: e.scope,
|
|
447
447
|
decidedAt: n.toISOString(),
|
|
448
|
-
nextEligibleAt: this.getNextEligibleAt(e, t, n,
|
|
449
|
-
},
|
|
450
|
-
return
|
|
448
|
+
nextEligibleAt: this.getNextEligibleAt(e, t, n, s.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;
|
|
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;
|
|
454
454
|
}
|
|
455
|
-
getNextEligibleAt(e, t,
|
|
455
|
+
getNextEligibleAt(e, t, s, n) {
|
|
456
456
|
if (t === "later")
|
|
457
|
-
return new Date(
|
|
457
|
+
return new Date(s.getTime() + (e.laterDelayMs ?? 3600 * 1e3)).toISOString();
|
|
458
458
|
if (t === "snooze") {
|
|
459
|
-
if (!n || n.getTime() <=
|
|
459
|
+
if (!n || n.getTime() <= s.getTime())
|
|
460
460
|
throw new Error("Snooze requires a future next-eligible time.");
|
|
461
461
|
return n.toISOString();
|
|
462
462
|
}
|
|
463
463
|
return null;
|
|
464
464
|
}
|
|
465
465
|
getDecisionKey(e) {
|
|
466
|
-
const t =
|
|
466
|
+
const t = A(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 `${
|
|
470
|
+
return `${A(e.scope)}:interaction:${e.key}`;
|
|
471
471
|
}
|
|
472
472
|
getCategoryKey(e) {
|
|
473
|
-
return `${
|
|
473
|
+
return `${A(e.scope)}:category:${e.category}`;
|
|
474
474
|
}
|
|
475
475
|
}
|
|
476
|
-
function
|
|
476
|
+
function Re(i, e) {
|
|
477
477
|
return {
|
|
478
|
-
load: async () =>
|
|
479
|
-
save: async (t) =>
|
|
478
|
+
load: async () => te(i, e),
|
|
479
|
+
save: async (t) => i.setItem(e, JSON.stringify(t))
|
|
480
480
|
};
|
|
481
481
|
}
|
|
482
|
-
function
|
|
483
|
-
const t =
|
|
482
|
+
function te(i, e) {
|
|
483
|
+
const t = i.getItem(e);
|
|
484
484
|
if (!t) return [];
|
|
485
|
-
const
|
|
486
|
-
return Array.isArray(
|
|
485
|
+
const s = JSON.parse(t);
|
|
486
|
+
return Array.isArray(s) ? s.filter(M) : [];
|
|
487
487
|
}
|
|
488
|
-
function
|
|
489
|
-
return `${
|
|
488
|
+
function A(i) {
|
|
489
|
+
return `${i.level}:${i.key}`;
|
|
490
490
|
}
|
|
491
|
-
function
|
|
492
|
-
return
|
|
491
|
+
function U(i) {
|
|
492
|
+
return i === "dismiss" || i === "later" || i === "snooze" || i === "never" || i === "dont_show_again";
|
|
493
493
|
}
|
|
494
|
-
function
|
|
495
|
-
if (!
|
|
496
|
-
const e =
|
|
497
|
-
return typeof e.promptKey == "string" && typeof e.category == "string" && typeof e.decidedAt == "string" && (e.nextEligibleAt === null || typeof e.nextEligibleAt == "string") &&
|
|
494
|
+
function M(i) {
|
|
495
|
+
if (!i || typeof i != "object") return !1;
|
|
496
|
+
const e = i;
|
|
497
|
+
return typeof e.promptKey == "string" && typeof e.category == "string" && typeof e.decidedAt == "string" && (e.nextEligibleAt === null || typeof e.nextEligibleAt == "string") && U(e.action) && !!(e.scope && typeof e.scope == "object" && typeof e.scope.level == "string" && typeof e.scope.key == "string");
|
|
498
498
|
}
|
|
499
|
-
const
|
|
499
|
+
const se = {
|
|
500
500
|
working: "⏳",
|
|
501
501
|
completed: "✅",
|
|
502
502
|
failed: "❗",
|
|
503
503
|
stopped: "⏹️"
|
|
504
|
-
},
|
|
505
|
-
function
|
|
506
|
-
if (!e) return
|
|
507
|
-
const t =
|
|
508
|
-
return t ? `${
|
|
504
|
+
}, ie = /^(?:⌛|⏳|✅|❗|⏹️) Pluno(?:: )?/;
|
|
505
|
+
function ne(i, e) {
|
|
506
|
+
if (!e) return w(i);
|
|
507
|
+
const t = w(i), s = `${se[e]} Pluno`;
|
|
508
|
+
return t ? `${s}: ${t}` : s;
|
|
509
509
|
}
|
|
510
510
|
class qe {
|
|
511
511
|
constructor(e) {
|
|
@@ -524,16 +524,16 @@ class qe {
|
|
|
524
524
|
this.liveStatusVersion += 1, this.applyClear();
|
|
525
525
|
}
|
|
526
526
|
async syncStatus(e) {
|
|
527
|
-
const t = this.liveStatusVersion,
|
|
528
|
-
|
|
527
|
+
const t = this.liveStatusVersion, s = await e();
|
|
528
|
+
s === void 0 || t !== this.liveStatusVersion || (s ? this.applyStatus(s) : this.applyClear());
|
|
529
529
|
}
|
|
530
530
|
applyStatus(e) {
|
|
531
531
|
const t = this.titleDocument.getTitle();
|
|
532
|
-
t !== this.lastAppliedTitle && (this.baseTitle =
|
|
532
|
+
t !== this.lastAppliedTitle && (this.baseTitle = w(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,
|
|
536
|
-
this.status = null, this.lastAppliedTitle = null, this.stopObserving?.(), this.stopObserving = null, t ? this.titleDocument.setTitle(this.baseTitle) :
|
|
535
|
+
const e = this.titleDocument.getTitle(), t = this.lastAppliedTitle !== null && e === this.lastAppliedTitle, s = this.lastAppliedTitle === null ? w(e) : e;
|
|
536
|
+
this.status = null, this.lastAppliedTitle = null, this.stopObserving?.(), this.stopObserving = null, t ? this.titleDocument.setTitle(this.baseTitle) : s !== e && this.titleDocument.setTitle(s);
|
|
537
537
|
}
|
|
538
538
|
handleTitleChanged() {
|
|
539
539
|
!this.status || this.titleDocument.getTitle() === this.lastAppliedTitle || this.applyTitle();
|
|
@@ -541,19 +541,19 @@ class qe {
|
|
|
541
541
|
applyTitle() {
|
|
542
542
|
if (!this.status)
|
|
543
543
|
return;
|
|
544
|
-
const e =
|
|
544
|
+
const e = ne(this.baseTitle, this.status);
|
|
545
545
|
this.lastAppliedTitle = e, this.titleDocument.getTitle() !== e && this.titleDocument.setTitle(e);
|
|
546
546
|
}
|
|
547
547
|
}
|
|
548
|
-
function Oe(
|
|
548
|
+
function Oe(i) {
|
|
549
549
|
return {
|
|
550
|
-
getTitle: () =>
|
|
550
|
+
getTitle: () => i.title,
|
|
551
551
|
setTitle: (e) => {
|
|
552
|
-
|
|
552
|
+
i.title = e;
|
|
553
553
|
},
|
|
554
554
|
observeTitle: (e) => {
|
|
555
555
|
const t = new MutationObserver(e);
|
|
556
|
-
return t.observe(
|
|
556
|
+
return t.observe(i.head, {
|
|
557
557
|
childList: !0,
|
|
558
558
|
subtree: !0,
|
|
559
559
|
characterData: !0
|
|
@@ -561,112 +561,112 @@ function Oe(s) {
|
|
|
561
561
|
}
|
|
562
562
|
};
|
|
563
563
|
}
|
|
564
|
-
function
|
|
565
|
-
return
|
|
564
|
+
function w(i) {
|
|
565
|
+
return i.replace(ie, "");
|
|
566
566
|
}
|
|
567
|
-
const
|
|
568
|
-
version:
|
|
569
|
-
},
|
|
570
|
-
function
|
|
571
|
-
if (!
|
|
572
|
-
const e =
|
|
573
|
-
return Object.keys(e).every((n) => ["ownerId", "revision", "dropped", "lastIntent", "lastSelection", "transitions"].includes(n)) &&
|
|
567
|
+
const re = "0.1.284", oe = {
|
|
568
|
+
version: re
|
|
569
|
+
}, g = (i) => typeof i == "string" && /^[a-zA-Z0-9:_.-]{1,160}$/.test(i) ? i : null;
|
|
570
|
+
function ae(i) {
|
|
571
|
+
if (!i || typeof i != "object") return !1;
|
|
572
|
+
const e = i, t = (n) => Number.isSafeInteger(n) && n >= 0, s = (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) && g(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 || g(r) !== null) && (n.projectionReady === null || typeof n.projectionReady == "boolean");
|
|
573
|
+
return Object.keys(e).every((n) => ["ownerId", "revision", "dropped", "lastIntent", "lastSelection", "transitions"].includes(n)) && g(e.ownerId) !== null && t(e.revision) && t(e.dropped) && (e.lastIntent == null || s(e.lastIntent)) && (e.lastSelection === null || s(e.lastSelection)) && Array.isArray(e.transitions) && e.transitions.length <= 16 && e.transitions.every(s);
|
|
574
574
|
}
|
|
575
|
-
function
|
|
576
|
-
if (!
|
|
577
|
-
const e =
|
|
575
|
+
function F(i) {
|
|
576
|
+
if (!i || typeof i != "object") return !1;
|
|
577
|
+
const e = i;
|
|
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
|
|
581
|
-
function L(
|
|
582
|
-
if (!
|
|
583
|
-
const e =
|
|
584
|
-
return Object.keys(
|
|
580
|
+
const x = ["messageKeys", "canonicalItemKeys", "terminalResponseKeys", "toolCallKeys", "activeResponseKeys"], T = (i) => typeof i == "string" && /^[a-zA-Z0-9:_-]{1,160}$/.test(i), y = (i) => i === null || T(i), de = (i) => typeof i == "string" && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,6})?(?:Z|\+00:00)$/.test(i) && Number.isFinite(Date.parse(i));
|
|
581
|
+
function L(i) {
|
|
582
|
+
if (!i || typeof i != "object") return !1;
|
|
583
|
+
const e = i;
|
|
584
|
+
return Object.keys(i).every((t) => ["sessionId", "itemId", "userMessageId", "createdAt", "runId", "retryable"].includes(t)) && y(e.sessionId) && T(e.itemId) && y(e.userMessageId) && (e.retryable === void 0 || typeof e.retryable == "boolean") && y(e.runId) && (e.createdAt === null || de(e.createdAt));
|
|
585
585
|
}
|
|
586
|
-
function ce(
|
|
587
|
-
if (!
|
|
588
|
-
const e =
|
|
589
|
-
return Object.keys(e).every((
|
|
586
|
+
function ce(i) {
|
|
587
|
+
if (!i || typeof i != "object") return !1;
|
|
588
|
+
const e = i, t = (s) => Number.isSafeInteger(s) && s >= 0;
|
|
589
|
+
return Object.keys(e).every((s) => ["capturedAt", "selectionKey", "userId", "loading", "draft", "thinking", "connected", "hasError", "phase", "queryStatus", "queryRequestId", "queryUpdatedAt", "renderSource", "selectionFencePending", "guardCreatedAt", "owner", "sdkVersion", "presentationGate", "firstObservedAt", "confirmationMs"].includes(s)) && t(e.capturedAt) && [e.queryUpdatedAt, e.guardCreatedAt].every((s) => s === null || t(s)) && [e.selectionKey, e.userId, e.phase, e.queryStatus, e.queryRequestId].every((s) => s === null || g(s) !== null) && [e.loading, e.draft, e.thinking, e.connected, e.hasError, e.selectionFencePending].every((s) => typeof s == "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((s) => s === void 0 || t(s));
|
|
590
590
|
}
|
|
591
|
-
function
|
|
592
|
-
if (!
|
|
593
|
-
const e = (
|
|
594
|
-
if (!
|
|
595
|
-
const n =
|
|
596
|
-
return Object.keys(
|
|
597
|
-
}, t =
|
|
591
|
+
function G(i) {
|
|
592
|
+
if (!i || typeof i != "object" || Object.keys(i).some((s) => s !== "before" && s !== "current")) return !1;
|
|
593
|
+
const e = (s) => {
|
|
594
|
+
if (!s || typeof s != "object") return !1;
|
|
595
|
+
const n = s;
|
|
596
|
+
return Object.keys(s).every((r) => [...x, "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)) && y(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)) && y(o.itemId) && y(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")) && y(n.sessionId) && Number.isSafeInteger(n.runtimeItemCount) && n.runtimeItemCount >= 0 && typeof n.welcome == "boolean" && typeof n.truncated == "boolean" && x.every((r) => Array.isArray(n[r]) && n[r].length <= 20 && n[r].every(T));
|
|
597
|
+
}, t = i;
|
|
598
598
|
return (t.before === null || e(t.before)) && e(t.current);
|
|
599
599
|
}
|
|
600
|
-
const
|
|
601
|
-
function
|
|
602
|
-
const e =
|
|
603
|
-
return e.length >
|
|
600
|
+
const D = 500;
|
|
601
|
+
function B(i) {
|
|
602
|
+
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();
|
|
603
|
+
return e.length > D ? `${e.slice(0, D - 1)}…` : e;
|
|
604
604
|
}
|
|
605
|
-
function
|
|
605
|
+
function le(i) {
|
|
606
606
|
let e = 2166136261;
|
|
607
|
-
for (let t = 0; t <
|
|
608
|
-
e ^=
|
|
607
|
+
for (let t = 0; t < i.length; t += 1)
|
|
608
|
+
e ^= i.charCodeAt(t), e = Math.imul(e, 16777619);
|
|
609
609
|
return `fnv1a-${(e >>> 0).toString(16).padStart(8, "0")}`;
|
|
610
610
|
}
|
|
611
|
-
function
|
|
612
|
-
if (!
|
|
613
|
-
const e =
|
|
614
|
-
return Object.keys(
|
|
611
|
+
function k(i) {
|
|
612
|
+
if (!i || typeof i != "object") return !1;
|
|
613
|
+
const e = i;
|
|
614
|
+
return Object.keys(i).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
|
|
617
|
-
if (!
|
|
618
|
-
const e =
|
|
619
|
-
return Object.keys(e).every((t) => ["sessionId", "requestId", "code", "normalization", "builds", "clientMessageId"].includes(t)) && (e.clientMessageId === void 0 ||
|
|
616
|
+
function ue(i) {
|
|
617
|
+
if (!i || typeof i != "object") return !1;
|
|
618
|
+
const e = i;
|
|
619
|
+
return Object.keys(e).every((t) => ["sessionId", "requestId", "code", "normalization", "builds", "clientMessageId"].includes(t)) && (e.clientMessageId === void 0 || g(e.clientMessageId) !== null) && [e.sessionId, e.requestId, e.code].every((t) => t === null || g(t) !== null) && (e.normalization === void 0 || k(e.normalization)) && !!e.builds && typeof e.builds == "object" && typeof e.builds.sdk == "string" && Object.entries(e.builds).every(([t, s]) => ["sdk", "rendererExtension", "contentExtension", "backgroundExtension"].includes(t) && typeof s == "string" && /^\d{1,5}\.\d{1,5}\.\d{1,5}$/.test(s));
|
|
620
620
|
}
|
|
621
|
-
function
|
|
622
|
-
const r = !
|
|
621
|
+
function pe(i, e, t, s, n = {}) {
|
|
622
|
+
const r = !s && e === "conversation_error" && t !== void 0 && i.conversationDiagnostics?.errorMessageFingerprint === le(B(t)) ? i.conversationDiagnostics : void 0;
|
|
623
623
|
return {
|
|
624
|
-
sessionId:
|
|
625
|
-
requestId:
|
|
626
|
-
...
|
|
627
|
-
code: r ?
|
|
628
|
-
...
|
|
629
|
-
builds: { sdk:
|
|
624
|
+
sessionId: g(i.sessionId),
|
|
625
|
+
requestId: g(r?.httpRequest?.requestId ?? r?.errorRequestId ?? r?.queryRequestId),
|
|
626
|
+
...g(r?.failedClientMessageId) ? { clientMessageId: r.failedClientMessageId } : {},
|
|
627
|
+
code: r ? g(i.lastErrorCode) : null,
|
|
628
|
+
...k(r?.errorNormalization) ? { normalization: r.errorNormalization } : {},
|
|
629
|
+
builds: { sdk: oe.version, ...n }
|
|
630
630
|
};
|
|
631
631
|
}
|
|
632
|
-
function
|
|
633
|
-
if (
|
|
632
|
+
function he(i) {
|
|
633
|
+
if (i.details !== void 0 && !S(i.details))
|
|
634
634
|
throw new TypeError("Product Agent transported error details must be JSON-safe.");
|
|
635
635
|
return {
|
|
636
|
-
code:
|
|
637
|
-
message:
|
|
638
|
-
retryable:
|
|
639
|
-
...
|
|
636
|
+
code: i.code,
|
|
637
|
+
message: i.message,
|
|
638
|
+
retryable: i.retryable,
|
|
639
|
+
...i.details === void 0 ? {} : { details: i.details }
|
|
640
640
|
};
|
|
641
641
|
}
|
|
642
|
-
function m(
|
|
643
|
-
const
|
|
644
|
-
...typeof
|
|
642
|
+
function m(i, e = "runtime_error", t = "runtime") {
|
|
643
|
+
const s = i !== null && typeof i == "object" ? i : null, n = typeof i == "string" ? i : s && "message" in s && typeof s.message == "string" ? s.message : "", r = s && "code" in s && typeof s.code == "string" && s.code.trim() ? s.code : e, o = s && "details" in s ? s.details : null, a = o && typeof o == "object" ? o : {}, c = {
|
|
644
|
+
...typeof a.httpStatus == "number" && Number.isInteger(a.httpStatus) && a.httpStatus >= 100 && a.httpStatus <= 599 ? { httpStatus: a.httpStatus } : {},
|
|
645
645
|
// Preserve the first boundary's shape after normalization replaces the original message/prototype.
|
|
646
|
-
errorNormalization:
|
|
646
|
+
errorNormalization: k(a.errorNormalization) ? a.errorNormalization : {
|
|
647
647
|
boundary: t,
|
|
648
|
-
category:
|
|
649
|
-
messageKind: n.trim() === "[object Object]" ? "object_coercion" : n.trim() ? "text" : typeof
|
|
648
|
+
category: i instanceof Error ? "error" : i === null ? "null" : Array.isArray(i) ? "array" : typeof i,
|
|
649
|
+
messageKind: n.trim() === "[object Object]" ? "object_coercion" : n.trim() ? "text" : typeof i == "string" || s && "message" in s && typeof s.message == "string" ? "blank" : "non_text"
|
|
650
650
|
},
|
|
651
|
-
...
|
|
652
|
-
...["unissued", "rejected"].includes(String(
|
|
653
|
-
...typeof
|
|
654
|
-
...typeof
|
|
655
|
-
...typeof
|
|
656
|
-
...typeof
|
|
657
|
-
...typeof
|
|
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 } : {}
|
|
658
658
|
};
|
|
659
|
-
return
|
|
659
|
+
return he({
|
|
660
660
|
code: r,
|
|
661
661
|
message: n.trim() && n.trim() !== "[object Object]" ? n : "The Product Agent operation failed. Try again.",
|
|
662
|
-
retryable: !!(
|
|
663
|
-
...Object.keys(
|
|
662
|
+
retryable: !!(s && "retryable" in s && s.retryable === !0),
|
|
663
|
+
...Object.keys(c).length ? { details: c } : {}
|
|
664
664
|
});
|
|
665
665
|
}
|
|
666
|
-
function
|
|
667
|
-
if (!
|
|
668
|
-
const e =
|
|
669
|
-
return Object.keys(e).every((
|
|
666
|
+
function Q(i) {
|
|
667
|
+
if (!i || typeof i != "object") return !1;
|
|
668
|
+
const e = i, t = (s) => Number.isSafeInteger(s) && s >= 0;
|
|
669
|
+
return Object.keys(e).every((s) => [
|
|
670
670
|
"requestId",
|
|
671
671
|
"method",
|
|
672
672
|
"route",
|
|
@@ -685,9 +685,9 @@ function B(s) {
|
|
|
685
685
|
"release",
|
|
686
686
|
"upstreamRequestId",
|
|
687
687
|
"upstreamTraceId"
|
|
688
|
-
].includes(
|
|
688
|
+
].includes(s)) && g(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((s) => s == null || t(s)) && t(e.elapsedMs) && t(e.attempt) && e.attempt >= 1 && e.attempt <= 10 && [e.queryRequestId, e.ownerId, e.sessionId].every((s) => s === null || g(s) !== 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((s) => s === null || typeof s == "string" && /^[a-zA-Z0-9_:;=./-]{1,160}$/.test(s));
|
|
689
689
|
}
|
|
690
|
-
const
|
|
690
|
+
const ge = [
|
|
691
691
|
"submit",
|
|
692
692
|
"stop",
|
|
693
693
|
"staging_ipc",
|
|
@@ -750,7 +750,7 @@ const he = [
|
|
|
750
750
|
"acceptance_applied",
|
|
751
751
|
"cancellation_queue",
|
|
752
752
|
"cancellation_write"
|
|
753
|
-
],
|
|
753
|
+
], H = [
|
|
754
754
|
"request_timed_out",
|
|
755
755
|
"delivery_unknown",
|
|
756
756
|
"invalid_ack",
|
|
@@ -766,86 +766,86 @@ const he = [
|
|
|
766
766
|
"backend_refusal",
|
|
767
767
|
"unknown"
|
|
768
768
|
];
|
|
769
|
-
function
|
|
770
|
-
const e =
|
|
771
|
-
return e?.backendRefusal === !0 ? "backend_refusal" : typeof t == "string" && t !== "backend_refusal" &&
|
|
769
|
+
function fe(i) {
|
|
770
|
+
const e = i, t = e?.code;
|
|
771
|
+
return e?.backendRefusal === !0 ? "backend_refusal" : typeof t == "string" && t !== "backend_refusal" && H.includes(t) ? t : e?.name === "AbortError" ? "aborted" : e?.name === "TypeError" ? "type_error" : "unknown";
|
|
772
772
|
}
|
|
773
|
-
const
|
|
774
|
-
let
|
|
775
|
-
const
|
|
776
|
-
function
|
|
777
|
-
if (!
|
|
778
|
-
const e =
|
|
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 ||
|
|
773
|
+
const V = Math.random().toString(36).slice(2);
|
|
774
|
+
let ye = 0;
|
|
775
|
+
const j = () => `timing:${V}:${++ye}`, b = (i) => typeof i == "string" && /^[a-zA-Z0-9:_-]{1,160}$/.test(i);
|
|
776
|
+
function R(i) {
|
|
777
|
+
if (!i || typeof i != "object") return !1;
|
|
778
|
+
const e = i;
|
|
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 || b(e.workerId)) && (e.failureCategory === void 0 || e.status === "failed" && H.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) && b(e.spanId) && b(e.requestId) && (e.clientMessageId === null || b(e.clientMessageId)) && (e.sessionId === null || b(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
|
-
function
|
|
782
|
-
if (e = { workerId:
|
|
781
|
+
function N(i, e) {
|
|
782
|
+
if (e = { workerId: V, ...e }, !i) return {
|
|
783
783
|
identity: e,
|
|
784
784
|
mark: (n) => {
|
|
785
785
|
},
|
|
786
786
|
measure: (n, r) => r()
|
|
787
787
|
};
|
|
788
|
-
const t = performance.now(),
|
|
789
|
-
const
|
|
788
|
+
const t = performance.now(), s = (n, r, o, a, c) => {
|
|
789
|
+
const d = {
|
|
790
790
|
...e,
|
|
791
791
|
stage: n,
|
|
792
792
|
status: r,
|
|
793
|
-
spanId:
|
|
793
|
+
spanId: a,
|
|
794
794
|
occurredAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
795
|
-
durationMs: Math.max(0, Math.round(performance.now() -
|
|
796
|
-
...r === "failed" ? { failureCategory:
|
|
795
|
+
durationMs: Math.max(0, Math.round(performance.now() - o)),
|
|
796
|
+
...r === "failed" ? { failureCategory: fe(c) } : {}
|
|
797
797
|
};
|
|
798
|
-
|
|
798
|
+
i && R(d) && Promise.resolve().then(() => i(d)).catch(() => {
|
|
799
799
|
});
|
|
800
800
|
};
|
|
801
801
|
return {
|
|
802
802
|
identity: e,
|
|
803
|
-
mark: (n) =>
|
|
803
|
+
mark: (n) => s(n, "observed", t, j()),
|
|
804
804
|
measure(n, r) {
|
|
805
|
-
const
|
|
806
|
-
return
|
|
807
|
-
(
|
|
808
|
-
(
|
|
809
|
-
throw
|
|
805
|
+
const o = performance.now(), a = j();
|
|
806
|
+
return s(n, "started", o, a), r().then(
|
|
807
|
+
(c) => (s(n, "completed", o, a), c),
|
|
808
|
+
(c) => {
|
|
809
|
+
throw s(n, "failed", o, a, c), c;
|
|
810
810
|
}
|
|
811
811
|
);
|
|
812
812
|
}
|
|
813
813
|
};
|
|
814
814
|
}
|
|
815
|
-
const
|
|
816
|
-
function me(
|
|
817
|
-
if (!
|
|
818
|
-
const e =
|
|
819
|
-
return typeof e.observedAt == "string" && e.observedAt.length <= 40 && Number.isFinite(Date.parse(e.observedAt)) &&
|
|
815
|
+
const E = (i) => i === null || typeof i == "string" && /^[a-zA-Z0-9:_-]{1,160}$/.test(i);
|
|
816
|
+
function me(i) {
|
|
817
|
+
if (!i || typeof i != "object") return !1;
|
|
818
|
+
const e = i;
|
|
819
|
+
return typeof e.observedAt == "string" && e.observedAt.length <= 40 && Number.isFinite(Date.parse(e.observedAt)) && E(e.sessionId) && E(e.responseItemId) && E(e.respondsToUserMessageId) && typeof e.panelVisible == "boolean" && typeof e.documentVisible == "boolean" && typeof e.loading == "boolean";
|
|
820
820
|
}
|
|
821
|
-
function
|
|
822
|
-
const r = new Set(
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
].filter((
|
|
827
|
-
for (const
|
|
828
|
-
|
|
829
|
-
const
|
|
830
|
-
...
|
|
831
|
-
...
|
|
821
|
+
function be(i, e, t = "stopped", s, n = "Run stopped by user.") {
|
|
822
|
+
const r = new Set(s ?? [
|
|
823
|
+
i.assistantDraftRespondsToUserMessageId,
|
|
824
|
+
i.activeResponseUserMessageId,
|
|
825
|
+
i.messages.filter((c) => c.role === "user").slice(-1)[0]?.id
|
|
826
|
+
].filter((c) => !!c)), o = i.messages.filter((c) => !(c.dataType === "run_status" && c.loading && r.has(c.respondsToUserMessageId ?? ""))).map((c) => r.has(c.respondsToUserMessageId ?? "") ? { ...c, loading: !1 } : c);
|
|
827
|
+
for (const c of r)
|
|
828
|
+
o.some((d) => d.respondsToUserMessageId === c && (d.dataType === "run_status" || d.dataType === "run_error" || d.role === "assistant" && d.phase !== "commentary")) || o.some((d) => d.role === "user" && d.id === c) && o.push({ id: `local-interrupted:${c}`, role: "system", dataType: "run_status", provisional: t === "stopping", content: t === "stopping" ? "Stopping…" : n, createdAt: e, respondsToUserMessageId: c });
|
|
829
|
+
const a = i.segments?.map((c) => ({ ...c, outcomeIds: [
|
|
830
|
+
...c.outcomeIds,
|
|
831
|
+
...o.filter((d) => d.id === `local-interrupted:${c.userMessageId}` && !c.outcomeIds.includes(d.id)).map((d) => d.id)
|
|
832
832
|
] }));
|
|
833
833
|
return {
|
|
834
|
-
...
|
|
835
|
-
messages:
|
|
834
|
+
...i,
|
|
835
|
+
messages: o,
|
|
836
836
|
isThinking: !1,
|
|
837
837
|
isRetrying: !1,
|
|
838
838
|
pendingMessageStatus: null,
|
|
839
839
|
turnPhase: null,
|
|
840
|
-
segments:
|
|
840
|
+
segments: a,
|
|
841
841
|
activity: { phase: t, activeItemId: null },
|
|
842
|
-
isLoadingSession:
|
|
842
|
+
isLoadingSession: i.isLoadingSession && o.length === 0,
|
|
843
843
|
taskStatus: t === "stopped" ? "stopped" : null,
|
|
844
844
|
lastError: null,
|
|
845
845
|
lastErrorCode: null
|
|
846
846
|
};
|
|
847
847
|
}
|
|
848
|
-
const
|
|
848
|
+
const ve = {
|
|
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,23 +861,23 @@ const be = {
|
|
|
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
|
|
865
|
-
return typeof
|
|
864
|
+
function _e(i) {
|
|
865
|
+
return typeof i == "string" && i.startsWith("ui_invariant:") && Object.prototype.hasOwnProperty.call(ve, i.slice(13));
|
|
866
866
|
}
|
|
867
|
-
function
|
|
867
|
+
function K(i) {
|
|
868
868
|
return {
|
|
869
|
-
...
|
|
870
|
-
name:
|
|
871
|
-
mimeType:
|
|
872
|
-
sizeBytes:
|
|
873
|
-
...
|
|
874
|
-
...
|
|
875
|
-
...
|
|
869
|
+
...i.id === void 0 ? {} : { id: i.id },
|
|
870
|
+
name: i.name,
|
|
871
|
+
mimeType: i.mimeType,
|
|
872
|
+
sizeBytes: i.sizeBytes,
|
|
873
|
+
...i.sandboxPath === void 0 ? {} : { sandboxPath: i.sandboxPath },
|
|
874
|
+
...i.storageKey === void 0 ? {} : { storageKey: i.storageKey },
|
|
875
|
+
...i.fileUrl === void 0 ? {} : { fileUrl: i.fileUrl }
|
|
876
876
|
};
|
|
877
877
|
}
|
|
878
|
-
function
|
|
879
|
-
if (!
|
|
880
|
-
const e =
|
|
878
|
+
function Ce(i) {
|
|
879
|
+
if (!i || typeof i != "object" || !("type" in i)) return !1;
|
|
880
|
+
const e = i;
|
|
881
881
|
switch (e.type) {
|
|
882
882
|
case "runtime.connect":
|
|
883
883
|
case "session.new":
|
|
@@ -891,11 +891,11 @@ function Re(s) {
|
|
|
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
|
|
894
|
+
return R(e.timing);
|
|
895
895
|
case "runtime.report_displayed_error":
|
|
896
|
-
return (e.errorDiagnostic === void 0 ||
|
|
896
|
+
return (e.errorDiagnostic === void 0 || ue(e.errorDiagnostic)) && (e.httpRequest === void 0 || Q(e.httpRequest)) && (e.historyRefreshFailure === void 0 || F(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 ||
|
|
898
|
+
return (e.uiInvariant === void 0 || G(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");
|
|
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":
|
|
@@ -925,9 +925,9 @@ function Re(s) {
|
|
|
925
925
|
return !1;
|
|
926
926
|
}
|
|
927
927
|
}
|
|
928
|
-
class
|
|
929
|
-
constructor(e, t,
|
|
930
|
-
this.adapter = t, this.state =
|
|
928
|
+
class xe {
|
|
929
|
+
constructor(e, t, s) {
|
|
930
|
+
this.adapter = t, this.state = P(e), this.hasBeenReady = e.status === "connected" && e.submissionReady !== !1, this.model = s;
|
|
931
931
|
}
|
|
932
932
|
adapter;
|
|
933
933
|
listeners = {};
|
|
@@ -936,11 +936,12 @@ class Ce {
|
|
|
936
936
|
interactionListeners = /* @__PURE__ */ new Set();
|
|
937
937
|
accountListeners = /* @__PURE__ */ new Set();
|
|
938
938
|
state;
|
|
939
|
-
sessionHistoryState =
|
|
939
|
+
sessionHistoryState = _("unavailable");
|
|
940
940
|
model;
|
|
941
941
|
interactions = [];
|
|
942
942
|
account = null;
|
|
943
943
|
stagedProactiveSuggestionClientMessageId = null;
|
|
944
|
+
readinessPendingSubmissions = /* @__PURE__ */ new Set();
|
|
944
945
|
pendingTransfers = /* @__PURE__ */ new Map();
|
|
945
946
|
// Presentation of commands in transit only; the background remains the submission/delivery owner.
|
|
946
947
|
submissionPreviews = /* @__PURE__ */ new Map();
|
|
@@ -953,49 +954,50 @@ class Ce {
|
|
|
953
954
|
durabilityWaiters = /* @__PURE__ */ new Set();
|
|
954
955
|
operationQueue = Promise.resolve();
|
|
955
956
|
destroyed = !1;
|
|
957
|
+
hasBeenReady;
|
|
956
958
|
on(e, t) {
|
|
957
|
-
const
|
|
958
|
-
return
|
|
959
|
+
const s = this.listeners[e] ?? /* @__PURE__ */ new Set();
|
|
960
|
+
return s.add(t), this.listeners[e] = s, () => s.delete(t);
|
|
959
961
|
}
|
|
960
962
|
getState() {
|
|
961
|
-
const e =
|
|
963
|
+
const e = P(this.state);
|
|
962
964
|
for (const [n, r] of this.submissionPreviews)
|
|
963
|
-
e.messages.some((
|
|
965
|
+
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"));
|
|
964
966
|
this.stopError && (e.lastError = this.stopError, e.lastErrorCode = "stop_failed");
|
|
965
967
|
const t = [...this.stopPreviews.keys()];
|
|
966
968
|
if (!t.length) return e;
|
|
967
|
-
const
|
|
968
|
-
return e.activeResponseUserMessageId && !this.stopPreviews.has(e.activeResponseUserMessageId) ? { ...e, messages:
|
|
969
|
+
const s = be(e, "", "stopping", t);
|
|
970
|
+
return e.activeResponseUserMessageId && !this.stopPreviews.has(e.activeResponseUserMessageId) ? { ...e, messages: s.messages, segments: s.segments } : s;
|
|
969
971
|
}
|
|
970
|
-
updateProjection(e, t,
|
|
972
|
+
updateProjection(e, t, s, n, r) {
|
|
971
973
|
if (this.destroyed) return;
|
|
972
|
-
const
|
|
973
|
-
(
|
|
974
|
-
for (const
|
|
975
|
-
|
|
976
|
-
this.state =
|
|
977
|
-
for (const [
|
|
978
|
-
const
|
|
979
|
-
(
|
|
974
|
+
const o = this.getState(), a = !this.hasBeenReady && (!o.user || o.user.id === e.user?.id), c = o.stableSelectionKey !== void 0 && o.stableSelectionKey === e.stableSelectionKey && o.user?.id === e.user?.id && o.sessionId === e.sessionId && this.pendingTransfers.size > 0 && this.submissionRetries.size === 0 && [...this.pendingTransfers.keys()].every((d) => this.readinessPendingSubmissions.has(d));
|
|
975
|
+
!a && !c && (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());
|
|
976
|
+
for (const d of e.messages)
|
|
977
|
+
d.role === "user" && e.receipts?.find((l) => l.userMessageId === d.id)?.durable !== !1 && this.submissionPreviews.delete(d.id);
|
|
978
|
+
this.state = P(e), e.status === "connected" && e.submissionReady !== !1 && (this.hasBeenReady = !0);
|
|
979
|
+
for (const [d, l] of this.stopPreviews) {
|
|
980
|
+
const u = e.activity?.executionKey;
|
|
981
|
+
(l !== void 0 && l !== "[]" && u !== void 0 && u !== "[]" && (u !== l || ["completed", "failed", "stopped"].includes(e.activity.phase)) || (l === void 0 || l === "[]") && e.messages.some((p) => p.respondsToUserMessageId === d && !p.provisional && p.loading !== !0 && (p.dataType === "run_status" || p.dataType === "run_error" || p.role === "assistant" && p.phase !== "commentary" && (p.streamState === void 0 || ["finished", "stopped", "failed"].includes(p.streamState))))) && this.stopPreviews.delete(d);
|
|
980
982
|
}
|
|
981
|
-
if (this.pendingStop?.userMessageIds.every((
|
|
982
|
-
for (const
|
|
983
|
-
if (
|
|
984
|
-
const
|
|
985
|
-
|
|
983
|
+
if (this.pendingStop?.userMessageIds.every((d) => !this.stopPreviews.has(d)) && (this.pendingStop = null), o.user?.id === e.user?.id)
|
|
984
|
+
for (const d of this.state.messages) {
|
|
985
|
+
if (d.role !== "user" || !d.attachments?.length) continue;
|
|
986
|
+
const l = o.messages.find((u) => u.role === "user" && u.id === d.id);
|
|
987
|
+
o.sessionId !== e.sessionId && !(o.sessionId === null && l) || (d.attachments = Ie(l?.attachments, d.attachments));
|
|
986
988
|
}
|
|
987
|
-
if (t !== void 0 && (this.model = t),
|
|
988
|
-
this.sessionHistoryState =
|
|
989
|
-
for (const
|
|
990
|
-
|
|
989
|
+
if (t !== void 0 && (this.model = t), s && JSON.stringify(s) !== JSON.stringify(this.sessionHistoryState)) {
|
|
990
|
+
this.sessionHistoryState = z(s);
|
|
991
|
+
for (const d of this.sessionHistoryListeners)
|
|
992
|
+
d(this.getSessionHistoryState());
|
|
991
993
|
}
|
|
992
994
|
if (n && JSON.stringify(n) !== JSON.stringify(this.interactions)) {
|
|
993
|
-
this.interactions = n.map((
|
|
994
|
-
for (const
|
|
995
|
+
this.interactions = n.map((d) => ({ ...d }));
|
|
996
|
+
for (const d of this.interactionListeners) d(this.getInteractions());
|
|
995
997
|
}
|
|
996
998
|
if (r !== void 0 && JSON.stringify(r) !== JSON.stringify(this.account)) {
|
|
997
999
|
this.account = r ? { ...r } : null;
|
|
998
|
-
for (const
|
|
1000
|
+
for (const d of this.accountListeners) d(this.getAccount());
|
|
999
1001
|
}
|
|
1000
1002
|
this.emit("state", this.getState());
|
|
1001
1003
|
}
|
|
@@ -1022,61 +1024,61 @@ class Ce {
|
|
|
1022
1024
|
this.dispatch({ type: "runtime.widget_lifecycle", action: e, trigger: t });
|
|
1023
1025
|
}
|
|
1024
1026
|
reportOperationTiming(e) {
|
|
1025
|
-
!this.destroyed &&
|
|
1027
|
+
!this.destroyed && R(e) && this.adapter.dispatch({ type: "runtime.report_operation_timing", timing: e }).catch(() => {
|
|
1026
1028
|
});
|
|
1027
1029
|
}
|
|
1028
1030
|
reportResponseVisibility(e) {
|
|
1029
1031
|
this.adapter.dispatch({ type: "runtime.report_response_visibility", observation: e }).catch(() => {
|
|
1030
1032
|
});
|
|
1031
1033
|
}
|
|
1032
|
-
reportInvalidStateTransition(e, t,
|
|
1033
|
-
|
|
1034
|
+
reportInvalidStateTransition(e, t, s) {
|
|
1035
|
+
s !== void 0 && !G(s) || this.adapter.dispatch({
|
|
1034
1036
|
type: "runtime.report_invalid_state_transition",
|
|
1035
1037
|
reason: e,
|
|
1036
1038
|
clientMessageId: t,
|
|
1037
|
-
...
|
|
1039
|
+
...s ? { uiInvariant: s } : {}
|
|
1038
1040
|
}).catch(() => {
|
|
1039
1041
|
});
|
|
1040
1042
|
}
|
|
1041
|
-
reportDisplayedError(e, t,
|
|
1042
|
-
const
|
|
1043
|
-
if (n !== void 0 && !L(n) || r !== void 0 && !
|
|
1044
|
-
const
|
|
1043
|
+
reportDisplayedError(e, t, s, n, r) {
|
|
1044
|
+
const o = e === "conversation_error" && !n ? this.getState().conversationDiagnostics?.httpRequest : void 0;
|
|
1045
|
+
if (n !== void 0 && !L(n) || r !== void 0 && !F(r)) return;
|
|
1046
|
+
const a = pe(this.getState(), e, s, !!n, this.adapter.diagnosticBuilds);
|
|
1045
1047
|
this.adapter.dispatch({
|
|
1046
1048
|
type: "runtime.report_displayed_error",
|
|
1047
|
-
errorDiagnostic:
|
|
1048
|
-
...
|
|
1049
|
+
errorDiagnostic: a,
|
|
1050
|
+
...a.clientMessageId ? { clientMessageId: a.clientMessageId } : {},
|
|
1049
1051
|
reason: e,
|
|
1050
1052
|
errorFingerprint: t,
|
|
1051
1053
|
...n ? { renderedError: n } : {},
|
|
1052
1054
|
...r ? { historyRefreshFailure: r } : {},
|
|
1053
|
-
...
|
|
1054
|
-
...
|
|
1055
|
+
...Q(o) ? { httpRequest: o } : {},
|
|
1056
|
+
...s ? { displayedMessage: B(s) } : {}
|
|
1055
1057
|
}).catch(() => {
|
|
1056
1058
|
});
|
|
1057
1059
|
}
|
|
1058
1060
|
sendMessage(e, t = {}) {
|
|
1059
|
-
const
|
|
1060
|
-
t = { ...t, attachments: t.attachments?.map((
|
|
1061
|
+
const s = e.trim();
|
|
1062
|
+
t = { ...t, attachments: t.attachments?.map((d) => ({ ...d })) };
|
|
1061
1063
|
const n = t.attachments ?? [];
|
|
1062
|
-
if (!
|
|
1064
|
+
if (!s && n.length === 0) return Promise.resolve(null);
|
|
1063
1065
|
this.pendingStop = null, this.stopError = null;
|
|
1064
|
-
const r = t.clientMessageId ?? (t.proactiveSuggestionQuestion && this.stagedProactiveSuggestionClientMessageId ? this.stagedProactiveSuggestionClientMessageId : crypto.randomUUID()),
|
|
1065
|
-
this.pendingTransfers.set(r, n.flatMap((
|
|
1066
|
+
const r = t.clientMessageId ?? (t.proactiveSuggestionQuestion && this.stagedProactiveSuggestionClientMessageId ? this.stagedProactiveSuggestionClientMessageId : crypto.randomUUID()), o = t.submittedAt ?? Date.now(), a = this.submissionGeneration;
|
|
1067
|
+
this.pendingTransfers.set(r, n.flatMap((d) => d.id ? [d.id] : [])), this.submissionPreviews.set(r, { pending: !0, message: {
|
|
1066
1068
|
id: r,
|
|
1067
1069
|
role: "user",
|
|
1068
|
-
content:
|
|
1070
|
+
content: s,
|
|
1069
1071
|
createdAt: "",
|
|
1070
|
-
attachments: n.map((
|
|
1072
|
+
attachments: n.map((d) => ({ ...d }))
|
|
1071
1073
|
} });
|
|
1072
|
-
const
|
|
1073
|
-
return this.emit("state", this.getState()),
|
|
1074
|
+
const c = this.sendMessageNow(s, { ...t, clientMessageId: r, submittedAt: o, selectionKey: this.state.selectionKey }, a);
|
|
1075
|
+
return this.emit("state", this.getState()), c.finally(() => {
|
|
1074
1076
|
this.pendingTransfers.delete(r);
|
|
1075
1077
|
});
|
|
1076
1078
|
}
|
|
1077
|
-
async sendMessageNow(e, t,
|
|
1078
|
-
const n = e, r = t.clientMessageId,
|
|
1079
|
-
|
|
1079
|
+
async sendMessageNow(e, t, s) {
|
|
1080
|
+
const n = e, r = t.clientMessageId, o = N((l) => {
|
|
1081
|
+
s === this.submissionGeneration && this.reportOperationTiming(l);
|
|
1080
1082
|
}, {
|
|
1081
1083
|
operation: "send",
|
|
1082
1084
|
layer: "renderer",
|
|
@@ -1084,54 +1086,61 @@ class Ce {
|
|
|
1084
1086
|
clientMessageId: r,
|
|
1085
1087
|
sessionId: this.state.sessionId
|
|
1086
1088
|
});
|
|
1087
|
-
|
|
1088
|
-
let
|
|
1089
|
-
if (
|
|
1089
|
+
o.mark("submit");
|
|
1090
|
+
let a = t.attachments ?? [], c = !1, d = !this.hasBeenReady || this.state.submissionReady === !1;
|
|
1091
|
+
if (s !== this.submissionGeneration) return null;
|
|
1092
|
+
d && this.readinessPendingSubmissions.add(r);
|
|
1090
1093
|
try {
|
|
1091
|
-
const
|
|
1092
|
-
const u = await this.enqueueOperation(async () =>
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1094
|
+
const l = await o.measure("staging_ipc", async () => {
|
|
1095
|
+
const u = await this.enqueueOperation(async () => {
|
|
1096
|
+
if (d) {
|
|
1097
|
+
if (!await o.measure("authentication", () => this.waitForSubmissionReadiness(s))) return null;
|
|
1098
|
+
this.readinessPendingSubmissions.delete(r), d = !1, t = { ...t, selectionKey: this.state.selectionKey };
|
|
1099
|
+
}
|
|
1100
|
+
return this.destroyed || s !== this.submissionGeneration ? null : { result: this.adapter.dispatch({
|
|
1101
|
+
type: "conversation.stage",
|
|
1102
|
+
...t.reconcileAcceptance ? { reconcileAcceptance: !0, selectionKey: t.selectionKey } : {},
|
|
1103
|
+
initiatedBy: t.initiatedBy,
|
|
1104
|
+
invocation: t.invocation,
|
|
1105
|
+
automationOnboarding: t.automationOnboarding,
|
|
1106
|
+
content: n,
|
|
1107
|
+
clientMessageId: r,
|
|
1108
|
+
proactiveSuggestionQuestion: t.proactiveSuggestionQuestion,
|
|
1109
|
+
// Preview URLs belong to the renderer's optimistic snapshot and are not valid runtime-command metadata.
|
|
1110
|
+
attachments: a.length > 0 ? a.map(K) : void 0,
|
|
1111
|
+
submittedAt: t.submittedAt
|
|
1112
|
+
}) };
|
|
1113
|
+
});
|
|
1114
|
+
return u ? u.result.then((h) => ({ result: h }), async (h) => {
|
|
1115
|
+
const p = m(h);
|
|
1116
|
+
if (p.code !== "submission_checkpoint_pending") throw h;
|
|
1117
|
+
const f = this.submissionPreviews.get(r);
|
|
1118
|
+
return f && (f.error = p), this.emit("state", this.getState()), await this.waitForSubmissionDurability(r, s) ? { result: void 0 } : null;
|
|
1110
1119
|
}) : null;
|
|
1111
1120
|
});
|
|
1112
|
-
if (!
|
|
1113
|
-
if (
|
|
1121
|
+
if (!l || s !== this.submissionGeneration) return null;
|
|
1122
|
+
if (c = !0, this.submissionRetries.delete(r), l.result?.submissionAccepted) {
|
|
1114
1123
|
r === this.stagedProactiveSuggestionClientMessageId && (this.stagedProactiveSuggestionClientMessageId = null);
|
|
1115
1124
|
for (const u of t.attachments ?? [])
|
|
1116
1125
|
u.id && this.attachmentFiles.delete(u.id);
|
|
1117
1126
|
return r;
|
|
1118
1127
|
}
|
|
1119
|
-
if (
|
|
1128
|
+
if (a.length > 0) {
|
|
1120
1129
|
if (!this.adapter.uploadAttachment)
|
|
1121
1130
|
throw new Error("The runtime does not support attachments.");
|
|
1122
1131
|
const u = [];
|
|
1123
|
-
for (const
|
|
1124
|
-
if (
|
|
1125
|
-
u.push(
|
|
1132
|
+
for (const h of a) {
|
|
1133
|
+
if (h.sandboxPath || h.storageKey) {
|
|
1134
|
+
u.push(h);
|
|
1126
1135
|
continue;
|
|
1127
1136
|
}
|
|
1128
|
-
const
|
|
1129
|
-
if (!
|
|
1130
|
-
if (u.push(await
|
|
1137
|
+
const p = h.id ? this.attachmentFiles.get(h.id) : void 0;
|
|
1138
|
+
if (!p) throw new Error(`Attachment bytes are unavailable for ${h.name}`);
|
|
1139
|
+
if (u.push(await o.measure("attachment_transfer", () => this.adapter.uploadAttachment(p, h, { clientMessageId: r }))), s !== this.submissionGeneration) return null;
|
|
1131
1140
|
}
|
|
1132
|
-
|
|
1141
|
+
a = u;
|
|
1133
1142
|
}
|
|
1134
|
-
if (
|
|
1143
|
+
if (s !== this.submissionGeneration || (await this.adapter.dispatch({
|
|
1135
1144
|
type: "conversation.send",
|
|
1136
1145
|
content: n,
|
|
1137
1146
|
clientMessageId: r,
|
|
@@ -1139,27 +1148,29 @@ class Ce {
|
|
|
1139
1148
|
invocation: t.invocation,
|
|
1140
1149
|
automationOnboarding: t.automationOnboarding,
|
|
1141
1150
|
proactiveSuggestionQuestion: t.proactiveSuggestionQuestion,
|
|
1142
|
-
attachments:
|
|
1143
|
-
}),
|
|
1151
|
+
attachments: a.length > 0 ? a.map(K) : void 0
|
|
1152
|
+
}), s !== this.submissionGeneration)) return null;
|
|
1144
1153
|
for (const u of t.attachments ?? [])
|
|
1145
1154
|
u.id && this.attachmentFiles.delete(u.id);
|
|
1146
1155
|
return r === this.stagedProactiveSuggestionClientMessageId && (this.stagedProactiveSuggestionClientMessageId = null), r;
|
|
1147
|
-
} catch (
|
|
1148
|
-
if (
|
|
1149
|
-
if (O(
|
|
1150
|
-
for (const
|
|
1151
|
-
|
|
1152
|
-
const
|
|
1153
|
-
!
|
|
1154
|
-
retry: () => this.sendMessageNow(e, { ...t, reconcileAcceptance: !
|
|
1155
|
-
attachmentIds: (t.attachments ?? []).flatMap((
|
|
1156
|
+
} catch (l) {
|
|
1157
|
+
if (s !== this.submissionGeneration) return null;
|
|
1158
|
+
if (O(l))
|
|
1159
|
+
for (const f of t.attachments ?? [])
|
|
1160
|
+
f.id && this.attachmentFiles.delete(f.id);
|
|
1161
|
+
const h = m(l).code === "command_not_received";
|
|
1162
|
+
!c && !O(l) && (d || h || t.selectionKey !== void 0) && this.submissionRetries.set(r, {
|
|
1163
|
+
retry: async () => (d && await this.connect(), this.sendMessageNow(e, { ...t, reconcileAcceptance: !d && !h }, s)),
|
|
1164
|
+
attachmentIds: (t.attachments ?? []).flatMap((f) => f.id ? [f.id] : [])
|
|
1156
1165
|
});
|
|
1157
|
-
const
|
|
1158
|
-
throw
|
|
1166
|
+
const p = this.submissionPreviews.get(r);
|
|
1167
|
+
throw p && (p.pending = !1, p.error = m(l), this.emit("state", this.getState())), c && await this.adapter.dispatch({
|
|
1159
1168
|
type: "conversation.fail_staged",
|
|
1160
1169
|
clientMessageId: r,
|
|
1161
|
-
message: m(
|
|
1162
|
-
}),
|
|
1170
|
+
message: m(l).message
|
|
1171
|
+
}), l;
|
|
1172
|
+
} finally {
|
|
1173
|
+
this.readinessPendingSubmissions.delete(r);
|
|
1163
1174
|
}
|
|
1164
1175
|
}
|
|
1165
1176
|
getModel() {
|
|
@@ -1170,18 +1181,18 @@ class Ce {
|
|
|
1170
1181
|
});
|
|
1171
1182
|
}
|
|
1172
1183
|
async retryLastMessage(e) {
|
|
1173
|
-
const t = e ?? [...this.submissionPreviews].reverse().find(([,
|
|
1184
|
+
const t = e ?? [...this.submissionPreviews].reverse().find(([, a]) => a.error)?.[0] ?? this.state.messages.filter((a) => a.role === "user").slice(-1)[0]?.id;
|
|
1174
1185
|
if (!t || this.destroyed) return !1;
|
|
1175
|
-
const
|
|
1176
|
-
if (
|
|
1177
|
-
const n = this.submissionRetries.get(t), r = n?.retry,
|
|
1186
|
+
const s = this.submissionPreviews.get(t);
|
|
1187
|
+
if (s?.pending || this.pendingTransfers.has(t)) return !1;
|
|
1188
|
+
const n = this.submissionRetries.get(t), r = n?.retry, o = this.submissionGeneration;
|
|
1178
1189
|
try {
|
|
1179
|
-
return n && r ? (
|
|
1180
|
-
} catch (
|
|
1181
|
-
if (!
|
|
1182
|
-
return
|
|
1190
|
+
return n && r ? (s && (s.pending = !0, s.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;
|
|
1191
|
+
} catch (a) {
|
|
1192
|
+
if (!s && !r) throw a;
|
|
1193
|
+
return s && o === this.submissionGeneration && this.submissionPreviews.get(t) === s && (s.error = m(a), this.emit("state", this.getState())), !1;
|
|
1183
1194
|
} finally {
|
|
1184
|
-
r && this.pendingTransfers.delete(t),
|
|
1195
|
+
r && this.pendingTransfers.delete(t), s && o === this.submissionGeneration && this.submissionPreviews.get(t) === s && (s.pending = !1, this.emit("state", this.getState()));
|
|
1185
1196
|
}
|
|
1186
1197
|
}
|
|
1187
1198
|
createLocalAttachment(e) {
|
|
@@ -1195,83 +1206,106 @@ class Ce {
|
|
|
1195
1206
|
}
|
|
1196
1207
|
stop() {
|
|
1197
1208
|
if (this.pendingStop) return this.pendingStop.promise;
|
|
1198
|
-
const e = this.getState(), t = this.cancelPendingSubmissions(!1)
|
|
1209
|
+
const e = this.getState(), t = this.cancelPendingSubmissions(!1);
|
|
1210
|
+
if (!this.hasBeenReady && t.length > 0 && !this.state.isThinking && this.state.turnPhase === null && this.state.pendingMessageStatus === null)
|
|
1211
|
+
return this.emit("state", this.getState()), Promise.resolve();
|
|
1212
|
+
const s = [...new Set([
|
|
1199
1213
|
...t,
|
|
1200
1214
|
e.activeResponseUserMessageId,
|
|
1201
|
-
e.messages.filter((
|
|
1202
|
-
].filter((
|
|
1215
|
+
e.messages.filter((d) => d.role === "user").slice(-1)[0]?.id
|
|
1216
|
+
].filter((d) => !!d))], n = N((d) => this.reportOperationTiming(d), {
|
|
1203
1217
|
operation: "stop",
|
|
1204
1218
|
layer: "renderer",
|
|
1205
1219
|
requestId: crypto.randomUUID(),
|
|
1206
|
-
clientMessageId:
|
|
1220
|
+
clientMessageId: s[0] ?? null,
|
|
1207
1221
|
sessionId: e.sessionId
|
|
1208
1222
|
});
|
|
1209
1223
|
n.mark("stop");
|
|
1210
|
-
const r = { userMessageIds:
|
|
1224
|
+
const r = { userMessageIds: s, promise: Promise.resolve() };
|
|
1211
1225
|
this.pendingStop = r;
|
|
1212
|
-
const
|
|
1213
|
-
for (const
|
|
1214
|
-
this.stopPreviews.set(
|
|
1215
|
-
const
|
|
1226
|
+
const o = !e.pendingMessageStatus && ["thinking", "steering", "queued", "stopping"].includes(this.state.activity?.phase ?? "") ? this.state.activity?.executionKey : void 0;
|
|
1227
|
+
for (const d of s)
|
|
1228
|
+
this.stopPreviews.set(d, t.includes(d) ? void 0 : o);
|
|
1229
|
+
const a = this.submissionGeneration;
|
|
1216
1230
|
r.promise = n.measure("stop_ipc", () => this.adapter.dispatch({ type: "run.stop", ...t.length ? { clientMessageIds: t } : {} })).then(() => {
|
|
1217
|
-
}, (
|
|
1218
|
-
if (!(
|
|
1219
|
-
for (const
|
|
1220
|
-
this.stopError = m(
|
|
1231
|
+
}, (d) => {
|
|
1232
|
+
if (!(a !== this.submissionGeneration || s.every((l) => !this.stopPreviews.has(l)))) {
|
|
1233
|
+
for (const l of s) this.stopPreviews.delete(l);
|
|
1234
|
+
this.stopError = m(d).message;
|
|
1221
1235
|
}
|
|
1222
1236
|
}).finally(() => {
|
|
1223
|
-
this.destroyed ||
|
|
1237
|
+
this.destroyed || a !== this.submissionGeneration || (this.pendingStop === r && (this.pendingStop = null), this.emit("state", this.getState()));
|
|
1224
1238
|
}), this.emit("state", this.getState());
|
|
1225
|
-
const
|
|
1226
|
-
return this.operationQueue =
|
|
1239
|
+
const c = r.promise;
|
|
1240
|
+
return this.operationQueue = c.then(() => {
|
|
1227
1241
|
}, () => {
|
|
1228
|
-
}),
|
|
1242
|
+
}), c.then(() => {
|
|
1243
|
+
});
|
|
1244
|
+
}
|
|
1245
|
+
async waitForSubmissionReadiness(e) {
|
|
1246
|
+
let t = () => {
|
|
1247
|
+
}, s = () => {
|
|
1248
|
+
};
|
|
1249
|
+
return new Promise((n, r) => {
|
|
1250
|
+
s = () => {
|
|
1251
|
+
if (this.destroyed || e !== this.submissionGeneration) {
|
|
1252
|
+
n(!1);
|
|
1253
|
+
return;
|
|
1254
|
+
}
|
|
1255
|
+
if (this.state.lastError && ["connection_failed", "unauthorized", "update_required"].includes(this.state.lastErrorCode ?? "")) {
|
|
1256
|
+
r(Object.assign(new Error(this.state.lastError), { code: this.state.lastErrorCode }));
|
|
1257
|
+
return;
|
|
1258
|
+
}
|
|
1259
|
+
this.hasBeenReady && this.state.submissionReady !== !1 && n(!0);
|
|
1260
|
+
}, this.durabilityWaiters.add(s), t = this.on("state", s), s();
|
|
1261
|
+
}).finally(() => {
|
|
1262
|
+
t(), this.durabilityWaiters.delete(s);
|
|
1229
1263
|
});
|
|
1230
1264
|
}
|
|
1231
1265
|
async waitForSubmissionDurability(e, t) {
|
|
1232
|
-
let
|
|
1266
|
+
let s = () => {
|
|
1233
1267
|
}, n = () => {
|
|
1234
1268
|
};
|
|
1235
|
-
return new Promise((r,
|
|
1269
|
+
return new Promise((r, o) => {
|
|
1236
1270
|
n = () => {
|
|
1237
1271
|
if (this.destroyed || t !== this.submissionGeneration) {
|
|
1238
1272
|
r(!1);
|
|
1239
1273
|
return;
|
|
1240
1274
|
}
|
|
1241
|
-
const
|
|
1242
|
-
if (
|
|
1275
|
+
const a = this.state;
|
|
1276
|
+
if (a.messages.some((d) => d.respondsToUserMessageId === e && d.dataType === "run_status" && !d.provisional)) {
|
|
1243
1277
|
r(!1);
|
|
1244
1278
|
return;
|
|
1245
1279
|
}
|
|
1246
|
-
if (
|
|
1247
|
-
|
|
1280
|
+
if (a.conversationDiagnostics?.failedClientMessageId === e && a.lastError && a.lastErrorCode !== "submission_checkpoint_pending") {
|
|
1281
|
+
o(Object.assign(new Error(a.lastError), { code: a.lastErrorCode }));
|
|
1248
1282
|
return;
|
|
1249
1283
|
}
|
|
1250
|
-
const
|
|
1251
|
-
if (
|
|
1252
|
-
|
|
1284
|
+
const c = a.messages.find((d) => d.id === `submission-error:${e}` && d.dataType === "run_error");
|
|
1285
|
+
if (c) {
|
|
1286
|
+
o(new Error(c.content));
|
|
1253
1287
|
return;
|
|
1254
1288
|
}
|
|
1255
|
-
|
|
1256
|
-
}, this.durabilityWaiters.add(n),
|
|
1289
|
+
a.receipts?.some((d) => d.userMessageId === e && d.durable) && r(!0);
|
|
1290
|
+
}, this.durabilityWaiters.add(n), s = this.on("state", n), n();
|
|
1257
1291
|
}).finally(() => {
|
|
1258
|
-
|
|
1292
|
+
s(), this.durabilityWaiters.delete(n);
|
|
1259
1293
|
});
|
|
1260
1294
|
}
|
|
1261
1295
|
cancelPendingSubmissions(e = !0) {
|
|
1262
1296
|
this.pendingStop = null, e && this.stopPreviews.clear(), this.stopError = null;
|
|
1263
1297
|
const t = [.../* @__PURE__ */ new Set([...this.pendingTransfers.keys(), ...this.submissionRetries.keys()])];
|
|
1264
1298
|
this.submissionGeneration++;
|
|
1265
|
-
for (const
|
|
1266
|
-
for (const
|
|
1267
|
-
for (const n of
|
|
1299
|
+
for (const s of this.durabilityWaiters) s();
|
|
1300
|
+
for (const s of this.pendingTransfers.values())
|
|
1301
|
+
for (const n of s) this.attachmentFiles.delete(n);
|
|
1268
1302
|
this.pendingTransfers.clear();
|
|
1269
|
-
for (const
|
|
1270
|
-
for (const n of
|
|
1303
|
+
for (const s of this.submissionRetries.values())
|
|
1304
|
+
for (const n of s.attachmentIds) this.attachmentFiles.delete(n);
|
|
1271
1305
|
this.submissionRetries.clear();
|
|
1272
|
-
for (const
|
|
1273
|
-
|
|
1274
|
-
for (const n of
|
|
1306
|
+
for (const s of this.submissionPreviews.values()) {
|
|
1307
|
+
s.pending = !1, s.error?.code === "submission_checkpoint_pending" && (s.error = void 0);
|
|
1308
|
+
for (const n of s.message.attachments ?? [])
|
|
1275
1309
|
n.id && this.attachmentFiles.delete(n.id);
|
|
1276
1310
|
}
|
|
1277
1311
|
return this.operationQueue = Promise.resolve(), t;
|
|
@@ -1283,14 +1317,14 @@ class Ce {
|
|
|
1283
1317
|
async listSessions(e = {}) {
|
|
1284
1318
|
const t = await this.dispatch({ type: "session.list", ...e });
|
|
1285
1319
|
if (t === void 0) {
|
|
1286
|
-
const
|
|
1287
|
-
return { sessions:
|
|
1320
|
+
const s = this.getSessionHistoryState().data;
|
|
1321
|
+
return { sessions: s ? s.ids.map((n) => s.entitiesById[n]) : [], nextCursor: s?.nextCursor ?? null };
|
|
1288
1322
|
}
|
|
1289
1323
|
if (!t?.sessionHistoryPage) throw new Error("Session list command did not return a page.");
|
|
1290
1324
|
return t.sessionHistoryPage;
|
|
1291
1325
|
}
|
|
1292
1326
|
getSessionHistoryState() {
|
|
1293
|
-
return
|
|
1327
|
+
return z(this.sessionHistoryState);
|
|
1294
1328
|
}
|
|
1295
1329
|
subscribeSessionHistory(e) {
|
|
1296
1330
|
return this.sessionHistoryListeners.add(e), e(this.getSessionHistoryState()), () => this.sessionHistoryListeners.delete(e);
|
|
@@ -1318,13 +1352,13 @@ class Ce {
|
|
|
1318
1352
|
subscribeInteractions(e) {
|
|
1319
1353
|
return this.interactionListeners.add(e), e(this.getInteractions()), () => this.interactionListeners.delete(e);
|
|
1320
1354
|
}
|
|
1321
|
-
actOnInteraction(e, t,
|
|
1322
|
-
const r = n.expectedSourceVersion === void 0 ? this.getInteractions().find((
|
|
1355
|
+
actOnInteraction(e, t, s, n = {}) {
|
|
1356
|
+
const r = n.expectedSourceVersion === void 0 ? this.getInteractions().find((o) => o.id === e)?.sourceVersion ?? null : n.expectedSourceVersion;
|
|
1323
1357
|
return this.dispatch({
|
|
1324
1358
|
type: "interaction.act",
|
|
1325
1359
|
interactionId: e,
|
|
1326
1360
|
action: t,
|
|
1327
|
-
expectedRevision:
|
|
1361
|
+
expectedRevision: s,
|
|
1328
1362
|
...n,
|
|
1329
1363
|
expectedSourceVersion: r
|
|
1330
1364
|
}).then(() => {
|
|
@@ -1347,11 +1381,11 @@ class Ce {
|
|
|
1347
1381
|
stageProactiveSuggestionQuestion(e) {
|
|
1348
1382
|
const t = e.trim();
|
|
1349
1383
|
if (!t) return Promise.resolve();
|
|
1350
|
-
const
|
|
1351
|
-
return this.stagedProactiveSuggestionClientMessageId =
|
|
1384
|
+
const s = this.stagedProactiveSuggestionClientMessageId ?? crypto.randomUUID();
|
|
1385
|
+
return this.stagedProactiveSuggestionClientMessageId = s, this.dispatch({
|
|
1352
1386
|
type: "conversation.stage_proactive_suggestion",
|
|
1353
1387
|
question: t,
|
|
1354
|
-
clientMessageId:
|
|
1388
|
+
clientMessageId: s
|
|
1355
1389
|
}).then(() => {
|
|
1356
1390
|
});
|
|
1357
1391
|
}
|
|
@@ -1368,76 +1402,76 @@ class Ce {
|
|
|
1368
1402
|
), t;
|
|
1369
1403
|
}
|
|
1370
1404
|
emit(e, t) {
|
|
1371
|
-
const
|
|
1372
|
-
for (const n of
|
|
1405
|
+
const s = this.listeners[e];
|
|
1406
|
+
for (const n of s ?? []) n(t);
|
|
1373
1407
|
}
|
|
1374
1408
|
}
|
|
1375
|
-
function
|
|
1376
|
-
if (!e || !
|
|
1409
|
+
function Ie(i, e) {
|
|
1410
|
+
if (!e || !i) return e;
|
|
1377
1411
|
const t = /* @__PURE__ */ new Map();
|
|
1378
|
-
for (const
|
|
1379
|
-
const n =
|
|
1380
|
-
|
|
1412
|
+
for (const s of i) {
|
|
1413
|
+
const n = s.previewUrl;
|
|
1414
|
+
s.id && n && t.set(s.id, n);
|
|
1381
1415
|
}
|
|
1382
|
-
return e.map((
|
|
1383
|
-
const n =
|
|
1384
|
-
return n ? { ...
|
|
1416
|
+
return e.map((s) => {
|
|
1417
|
+
const n = s.id ? t.get(s.id) : void 0;
|
|
1418
|
+
return n ? { ...s, previewUrl: n } : s;
|
|
1385
1419
|
});
|
|
1386
1420
|
}
|
|
1387
|
-
function
|
|
1421
|
+
function P(i) {
|
|
1388
1422
|
return {
|
|
1389
|
-
...
|
|
1390
|
-
starterPrompts: [...
|
|
1391
|
-
appearance:
|
|
1392
|
-
messages:
|
|
1423
|
+
...i,
|
|
1424
|
+
starterPrompts: [...i.starterPrompts],
|
|
1425
|
+
appearance: i.appearance ? { ...i.appearance } : null,
|
|
1426
|
+
messages: i.messages.map((e) => {
|
|
1393
1427
|
const t = {
|
|
1394
1428
|
...e,
|
|
1395
|
-
attachments: e.attachments?.map((
|
|
1396
|
-
},
|
|
1429
|
+
attachments: e.attachments?.map((o) => ({ ...o }))
|
|
1430
|
+
}, s = e.assistantDraftItemId, n = e.clientMessageId, r = e.proactiveSuggestionClientMessageId;
|
|
1397
1431
|
return r && Object.defineProperty(t, "proactiveSuggestionClientMessageId", {
|
|
1398
1432
|
value: r,
|
|
1399
1433
|
enumerable: !1
|
|
1400
|
-
}),
|
|
1401
|
-
value:
|
|
1434
|
+
}), s && Object.defineProperty(t, "assistantDraftItemId", {
|
|
1435
|
+
value: s,
|
|
1402
1436
|
enumerable: !1
|
|
1403
1437
|
}), n && Object.defineProperty(t, "clientMessageId", {
|
|
1404
1438
|
value: n,
|
|
1405
1439
|
enumerable: !1
|
|
1406
1440
|
}), t;
|
|
1407
1441
|
}),
|
|
1408
|
-
activeScheduledFollowUps:
|
|
1442
|
+
activeScheduledFollowUps: i.activeScheduledFollowUps?.map((e) => ({ ...e })) ?? null
|
|
1409
1443
|
};
|
|
1410
1444
|
}
|
|
1411
|
-
function
|
|
1445
|
+
function z(i) {
|
|
1412
1446
|
return {
|
|
1413
|
-
...
|
|
1414
|
-
data:
|
|
1415
|
-
entities:
|
|
1416
|
-
nextCursor:
|
|
1447
|
+
...i,
|
|
1448
|
+
data: i.data ? I({
|
|
1449
|
+
entities: J(i.data).map((e) => ({ ...e })),
|
|
1450
|
+
nextCursor: i.data.nextCursor
|
|
1417
1451
|
}) : null
|
|
1418
1452
|
};
|
|
1419
1453
|
}
|
|
1420
1454
|
export {
|
|
1421
|
-
|
|
1422
|
-
|
|
1455
|
+
W as PRODUCT_AGENT_AUTH_RECONNECTING_ERROR_MESSAGE,
|
|
1456
|
+
ke as ProductAgentInteractionManager,
|
|
1423
1457
|
q as ProductAgentQueryController,
|
|
1424
|
-
|
|
1458
|
+
xe as ProductAgentRemoteRuntimeClient,
|
|
1425
1459
|
Te as ProductAgentSessionHistoryManager,
|
|
1426
1460
|
qe as ProductAgentTaskPageTitleController,
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1461
|
+
Pe as canSubmitPersonalProductAgentMessage,
|
|
1462
|
+
Re as createLocalStorageInteractionDecisionStorage,
|
|
1463
|
+
_ as createProductAgentQueryState,
|
|
1430
1464
|
Oe as createProductAgentTaskPageTitleDocument,
|
|
1431
|
-
|
|
1432
|
-
|
|
1465
|
+
ne as formatProductAgentTaskPageTitle,
|
|
1466
|
+
Ae as hasProductAgentPaidCreditFallback,
|
|
1433
1467
|
O as isProductAgentAuthReconnectError,
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1468
|
+
Ce as isProductAgentRuntimeCommand,
|
|
1469
|
+
Z as mergeProductAgentEntityPages,
|
|
1470
|
+
I as normalizeProductAgentEntityPage,
|
|
1471
|
+
te as readLocalStorageInteractionDecisions,
|
|
1472
|
+
Se as reconcileProductAgentSubmissionGate,
|
|
1473
|
+
Ee as resolveProductAgentBillingPresentation,
|
|
1474
|
+
Me as resolveProductAgentComposerAction,
|
|
1475
|
+
we as resolveProductAgentWidgetPresentation,
|
|
1476
|
+
J as selectProductAgentQueryEntities
|
|
1443
1477
|
};
|