@pluno/product-agent-web 0.1.220 → 0.1.223
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/README.md +8 -0
- package/dist/activeUsersCounter.d.ts +0 -7
- package/dist/adapters/web/activeUsers.d.ts +4 -0
- package/dist/adapters/web/backendHttp.d.ts +12 -0
- package/dist/adapters/web/backendTransport.d.ts +55 -0
- package/dist/adapters/web/directoryAdapters.d.ts +85 -0
- package/dist/adapters/web/directoryScope.d.ts +42 -0
- package/dist/adapters/web/modelScope.d.ts +3 -0
- package/dist/adapters/web/socketIOTransport.d.ts +74 -0
- package/dist/chatPresentation.d.ts +2 -0
- package/dist/core/active-users/reducer.d.ts +47 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/model-selection/commands.d.ts +22 -0
- package/dist/core/model-selection/contracts.d.ts +3 -1
- package/dist/core/model-selection/events.d.ts +15 -0
- package/dist/core/model-selection/reducer.d.ts +4 -0
- package/dist/core/model-selection/selectors.d.ts +10 -0
- package/dist/core/model-selection/state.d.ts +22 -0
- package/dist/core/protocol/modelRouting.d.ts +2 -0
- package/dist/core/session-directory/contracts.d.ts +202 -0
- package/dist/core/session-directory/membership.d.ts +4 -0
- package/dist/core/session-directory/reducer.d.ts +4 -0
- package/dist/core/session-directory/selectors.d.ts +2 -0
- package/dist/core/session-directory/state.d.ts +6 -0
- package/dist/index.d.ts +29 -16
- package/dist/interruptState.d.ts +2 -0
- package/dist/product-agent-runtime.cjs +1 -1
- package/dist/product-agent-runtime.js +384 -315
- package/dist/product-agent-sdk.js +7643 -3448
- package/dist/product-agent-widget.js +8818 -4752
- package/dist/public/operationRoutes.d.ts +1 -0
- package/dist/runtime/composition.d.ts +27 -7
- package/dist/runtime/modelSelection.d.ts +14 -0
- package/dist/runtimeClient.d.ts +10 -0
- package/dist/sessionRecoveryPolling.d.ts +3 -0
- package/dist/timelineReconciliation.d.ts +1 -0
- package/dist/uiInvariants.d.ts +6 -0
- package/dist/widget.d.ts +1 -0
- package/package.json +4 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
function
|
|
1
|
+
function f(i) {
|
|
2
2
|
return {
|
|
3
|
-
key:
|
|
3
|
+
key: i,
|
|
4
4
|
status: "not_requested",
|
|
5
5
|
data: null,
|
|
6
6
|
error: null,
|
|
@@ -8,9 +8,9 @@ function h(s) {
|
|
|
8
8
|
updatedAt: null
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
|
-
class
|
|
12
|
-
constructor(e, t,
|
|
13
|
-
this.loader = t, this.merge =
|
|
11
|
+
class w {
|
|
12
|
+
constructor(e, t, s = (n, a) => a) {
|
|
13
|
+
this.loader = t, this.merge = s, this.state = f(e);
|
|
14
14
|
}
|
|
15
15
|
loader;
|
|
16
16
|
merge;
|
|
@@ -25,10 +25,10 @@ class A {
|
|
|
25
25
|
return this.listeners.add(e), e(this.state), () => this.listeners.delete(e);
|
|
26
26
|
}
|
|
27
27
|
setKey(e) {
|
|
28
|
-
e !== this.state.key && (this.state =
|
|
28
|
+
e !== this.state.key && (this.state = f(e), this.trailingLoad = null, this.publish());
|
|
29
29
|
}
|
|
30
30
|
reset() {
|
|
31
|
-
this.state =
|
|
31
|
+
this.state = f(this.state.key), this.trailingLoad = null, this.publish();
|
|
32
32
|
}
|
|
33
33
|
invalidate() {
|
|
34
34
|
this.state = {
|
|
@@ -52,16 +52,16 @@ class A {
|
|
|
52
52
|
for (; this.trailingLoad; ) {
|
|
53
53
|
const e = this.trailingLoad;
|
|
54
54
|
this.trailingLoad = null;
|
|
55
|
-
const t = this.state.key,
|
|
55
|
+
const t = this.state.key, s = 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:
|
|
60
|
+
requestId: s
|
|
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 ||
|
|
64
|
+
if (t !== this.state.key || s !== this.state.requestId) continue;
|
|
65
65
|
this.state = {
|
|
66
66
|
...this.state,
|
|
67
67
|
status: "ready",
|
|
@@ -70,7 +70,7 @@ class A {
|
|
|
70
70
|
updatedAt: Date.now()
|
|
71
71
|
}, this.publish();
|
|
72
72
|
} catch (n) {
|
|
73
|
-
if (t !== this.state.key ||
|
|
73
|
+
if (t !== this.state.key || s !== this.state.requestId) continue;
|
|
74
74
|
this.state = {
|
|
75
75
|
...this.state,
|
|
76
76
|
status: "error",
|
|
@@ -83,64 +83,64 @@ class A {
|
|
|
83
83
|
for (const e of this.listeners) e(this.state);
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
|
-
function
|
|
86
|
+
function m(i) {
|
|
87
87
|
const e = {}, t = [];
|
|
88
|
-
for (const
|
|
89
|
-
e[
|
|
88
|
+
for (const s of i.entities)
|
|
89
|
+
e[s.id] || t.push(s.id), e[s.id] = s;
|
|
90
90
|
return {
|
|
91
91
|
entitiesById: e,
|
|
92
92
|
ids: t,
|
|
93
|
-
nextCursor:
|
|
93
|
+
nextCursor: i.nextCursor
|
|
94
94
|
};
|
|
95
95
|
}
|
|
96
|
-
function
|
|
97
|
-
if (t === "replace" ||
|
|
98
|
-
const
|
|
99
|
-
for (const
|
|
100
|
-
|
|
101
|
-
return { entitiesById:
|
|
96
|
+
function O(i, e, t) {
|
|
97
|
+
if (t === "replace" || i === null) return e;
|
|
98
|
+
const s = { ...i.entitiesById, ...e.entitiesById }, n = [...i.ids];
|
|
99
|
+
for (const a of e.ids)
|
|
100
|
+
i.entitiesById[a] || n.push(a);
|
|
101
|
+
return { entitiesById: s, ids: n, nextCursor: e.nextCursor };
|
|
102
102
|
}
|
|
103
|
-
function
|
|
104
|
-
return
|
|
103
|
+
function k(i) {
|
|
104
|
+
return i ? i.ids.map((e) => i.entitiesById[e]).filter((e) => !!e) : [];
|
|
105
105
|
}
|
|
106
|
-
function
|
|
107
|
-
return
|
|
106
|
+
function N(i) {
|
|
107
|
+
return i.visible ? i.minimized ? { state: "minimized" } : { state: i.open ? "visible_open" : "visible_closed" } : { state: "hidden" };
|
|
108
108
|
}
|
|
109
|
-
function
|
|
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"] } :
|
|
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: [] };
|
|
111
111
|
}
|
|
112
|
-
function
|
|
113
|
-
if (!
|
|
114
|
-
const e =
|
|
112
|
+
function j(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 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" };
|
|
119
119
|
}
|
|
120
|
-
function
|
|
121
|
-
const e =
|
|
122
|
-
return
|
|
120
|
+
function z(i) {
|
|
121
|
+
const e = i.hasDraftMessage || i.hasPreSubmittedAttachment;
|
|
122
|
+
return i.hasRunningAssistantTurn && !i.hasDraftMessage ? {
|
|
123
123
|
action: "stop",
|
|
124
|
-
disabled: !
|
|
124
|
+
disabled: !i.canStopRunningTurn
|
|
125
125
|
} : {
|
|
126
126
|
action: "send",
|
|
127
|
-
disabled: !e || !
|
|
127
|
+
disabled: !e || !i.canSubmitMessage
|
|
128
128
|
};
|
|
129
129
|
}
|
|
130
|
-
class
|
|
131
|
-
constructor(e, t,
|
|
132
|
-
this.loadPage = t, this.limit =
|
|
130
|
+
class H {
|
|
131
|
+
constructor(e, t, s = 20) {
|
|
132
|
+
this.loadPage = t, this.limit = s, this.recentQuery = new w(
|
|
133
133
|
`${e}:recent`,
|
|
134
|
-
async ({ cursor: n }) =>
|
|
135
|
-
await this.loadPage({ cursor: n, limit: this.limit, pinned: !1 }).then((
|
|
136
|
-
entities:
|
|
137
|
-
nextCursor:
|
|
134
|
+
async ({ cursor: n }) => m(
|
|
135
|
+
await this.loadPage({ cursor: n, limit: this.limit, pinned: !1 }).then((a) => ({
|
|
136
|
+
entities: a.sessions,
|
|
137
|
+
nextCursor: a.nextCursor
|
|
138
138
|
}))
|
|
139
139
|
),
|
|
140
|
-
|
|
141
|
-
), this.pinnedQuery = new
|
|
140
|
+
O
|
|
141
|
+
), this.pinnedQuery = new w(
|
|
142
142
|
`${e}:pinned`,
|
|
143
|
-
async () =>
|
|
143
|
+
async () => m({
|
|
144
144
|
entities: await this.loadAllPinned(),
|
|
145
145
|
nextCursor: null
|
|
146
146
|
})
|
|
@@ -159,19 +159,19 @@ class F {
|
|
|
159
159
|
completedRefreshSequence = 0;
|
|
160
160
|
activityReconciliationScheduled = !1;
|
|
161
161
|
getState() {
|
|
162
|
-
const e = this.recentQuery.getState(), t = this.pinnedQuery.getState(),
|
|
163
|
-
...
|
|
164
|
-
...
|
|
165
|
-
], n = new Map(
|
|
162
|
+
const e = this.recentQuery.getState(), t = this.pinnedQuery.getState(), s = [
|
|
163
|
+
...g(t.data),
|
|
164
|
+
...g(e.data)
|
|
165
|
+
], n = new Map(s.map((o) => [o.id, o])), a = Array.from(n.values()).map(
|
|
166
166
|
(o) => this.applyOverrides(o, this.completedRefreshSequence)
|
|
167
|
-
),
|
|
168
|
-
entities: [...
|
|
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],
|
|
169
169
|
nextCursor: e.data?.nextCursor ?? null
|
|
170
170
|
}) : null;
|
|
171
171
|
return {
|
|
172
172
|
key: e.key.slice(0, -7),
|
|
173
|
-
status:
|
|
174
|
-
data:
|
|
173
|
+
status: R(e, t),
|
|
174
|
+
data: r,
|
|
175
175
|
error: e.error ?? t.error,
|
|
176
176
|
requestId: Math.max(e.requestId, t.requestId),
|
|
177
177
|
updatedAt: Math.max(e.updatedAt ?? 0, t.updatedAt ?? 0) || null
|
|
@@ -216,56 +216,56 @@ class F {
|
|
|
216
216
|
isActive: t,
|
|
217
217
|
confirmAfterRefresh: this.completedRefreshSequence + 1,
|
|
218
218
|
releaseAfterRefresh: this.completedRefreshSequence + 2
|
|
219
|
-
}), this.updateEntity(e, (
|
|
219
|
+
}), this.updateEntity(e, (s) => ({ ...s, isActive: t }));
|
|
220
220
|
}
|
|
221
221
|
setPinned(e, t) {
|
|
222
|
-
const
|
|
223
|
-
return this.pinnedOverrides.set(e,
|
|
222
|
+
const s = { pinned: t, confirmAfterRefresh: Number.POSITIVE_INFINITY };
|
|
223
|
+
return this.pinnedOverrides.set(e, s), this.updateEntity(e, (n) => ({ ...n, isPinned: t })), s;
|
|
224
224
|
}
|
|
225
225
|
confirmPinned(e, t) {
|
|
226
226
|
this.pinnedOverrides.get(e) === t && (t.confirmAfterRefresh = this.completedRefreshSequence + 1);
|
|
227
227
|
}
|
|
228
|
-
rollbackPinned(e, t,
|
|
229
|
-
this.pinnedOverrides.get(e) === t && (this.pinnedOverrides.delete(e), this.updateEntity(e, (n) => ({ ...n, isPinned:
|
|
228
|
+
rollbackPinned(e, t, s) {
|
|
229
|
+
this.pinnedOverrides.get(e) === t && (this.pinnedOverrides.delete(e), this.updateEntity(e, (n) => ({ ...n, isPinned: s })));
|
|
230
230
|
}
|
|
231
231
|
setTitle(e, t) {
|
|
232
|
-
this.titleOverrides.set(e, t), this.updateEntity(e, (
|
|
232
|
+
this.titleOverrides.set(e, t), this.updateEntity(e, (s) => ({ ...s, customTitle: t }));
|
|
233
233
|
}
|
|
234
234
|
confirmTitle(e) {
|
|
235
235
|
this.titleOverrides.delete(e);
|
|
236
236
|
}
|
|
237
237
|
reconcileDurableEntities() {
|
|
238
238
|
const e = [
|
|
239
|
-
...
|
|
240
|
-
...
|
|
241
|
-
], t = new Set(e.map((
|
|
242
|
-
for (const
|
|
243
|
-
t.has(
|
|
244
|
-
for (const
|
|
239
|
+
...g(this.pinnedQuery.getState().data),
|
|
240
|
+
...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);
|
|
245
245
|
this.publish();
|
|
246
246
|
}
|
|
247
247
|
async loadAllPinned() {
|
|
248
248
|
const e = [];
|
|
249
249
|
let t = null;
|
|
250
250
|
do {
|
|
251
|
-
const
|
|
252
|
-
e.push(...
|
|
251
|
+
const s = await this.loadPage({ cursor: t, limit: this.limit, pinned: !0 });
|
|
252
|
+
e.push(...s.sessions), t = s.nextCursor;
|
|
253
253
|
} while (t);
|
|
254
254
|
return e;
|
|
255
255
|
}
|
|
256
256
|
applyOverrides(e, t) {
|
|
257
|
-
let
|
|
257
|
+
let s = e;
|
|
258
258
|
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) :
|
|
260
|
-
const
|
|
261
|
-
return
|
|
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 });
|
|
260
|
+
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;
|
|
262
262
|
}
|
|
263
263
|
updateProjection() {
|
|
264
264
|
this.publish();
|
|
265
265
|
}
|
|
266
266
|
updateEntity(e, t) {
|
|
267
|
-
const
|
|
268
|
-
|
|
267
|
+
const s = this.optimisticEntities.get(e);
|
|
268
|
+
s && this.optimisticEntities.set(e, t(s)), this.publish();
|
|
269
269
|
}
|
|
270
270
|
hasUnconfirmedActivityOverride() {
|
|
271
271
|
return Array.from(this.activityOverrides.values()).some(
|
|
@@ -276,16 +276,16 @@ class F {
|
|
|
276
276
|
for (const e of this.listeners) e(this.getState());
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
|
-
function
|
|
280
|
-
return
|
|
279
|
+
function g(i) {
|
|
280
|
+
return i ? i.ids.map((e) => i.entitiesById[e]).filter((e) => !!e) : [];
|
|
281
281
|
}
|
|
282
|
-
function
|
|
283
|
-
return
|
|
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";
|
|
284
284
|
}
|
|
285
|
-
class
|
|
285
|
+
class G {
|
|
286
286
|
constructor(e, t = null) {
|
|
287
287
|
this.storage = e, t && (this.decisions = new Map(
|
|
288
|
-
t.filter(
|
|
288
|
+
t.filter(I).map((s) => [this.getDecisionKey(s), s])
|
|
289
289
|
), this.initialized = !0);
|
|
290
290
|
}
|
|
291
291
|
storage;
|
|
@@ -297,113 +297,113 @@ class U {
|
|
|
297
297
|
if (this.initialized) return;
|
|
298
298
|
const e = await this.storage.load();
|
|
299
299
|
this.decisions = new Map(
|
|
300
|
-
e.filter(
|
|
300
|
+
e.filter(I).map((t) => [this.getDecisionKey(t), t])
|
|
301
301
|
), this.initialized = !0;
|
|
302
302
|
}
|
|
303
303
|
isEligible(e, t = Date.now()) {
|
|
304
|
-
const
|
|
305
|
-
return
|
|
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);
|
|
306
306
|
}
|
|
307
307
|
getDecision(e) {
|
|
308
308
|
return this.decisions.get(this.getExactKey(e)) ?? this.decisions.get(this.getCategoryKey(e)) ?? null;
|
|
309
309
|
}
|
|
310
310
|
getStatus(e, t = Date.now()) {
|
|
311
|
-
const
|
|
312
|
-
if (
|
|
311
|
+
const s = this.scheduledEligibility.get(this.getExactKey(e));
|
|
312
|
+
if (s !== void 0 && s > t) return "scheduled";
|
|
313
313
|
const n = this.getDecision(e);
|
|
314
314
|
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
315
|
}
|
|
316
316
|
scheduleEligibility(e, t) {
|
|
317
|
-
const
|
|
318
|
-
return n !== void 0 ? n : (this.scheduledEligibility.set(
|
|
317
|
+
const s = this.getExactKey(e), n = this.scheduledEligibility.get(s);
|
|
318
|
+
return n !== void 0 ? n : (this.scheduledEligibility.set(s, t), t);
|
|
319
319
|
}
|
|
320
320
|
getNextEligibilityAt(e = Date.now()) {
|
|
321
321
|
const t = [
|
|
322
|
-
...Array.from(this.scheduledEligibility.values()).filter((
|
|
323
|
-
...Array.from(this.decisions.values()).map((
|
|
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)
|
|
324
324
|
];
|
|
325
325
|
return t.length > 0 ? Math.min(...t) : null;
|
|
326
326
|
}
|
|
327
|
-
act(e, t,
|
|
328
|
-
const n = this.actionQueue.then(() => this.applyAction(e, t,
|
|
327
|
+
act(e, t, s = {}) {
|
|
328
|
+
const n = this.actionQueue.then(() => this.applyAction(e, t, s));
|
|
329
329
|
return this.actionQueue = n.then(() => {
|
|
330
330
|
}, () => {
|
|
331
331
|
}), n;
|
|
332
332
|
}
|
|
333
|
-
async applyAction(e, t,
|
|
333
|
+
async applyAction(e, t, s) {
|
|
334
334
|
if (!e.allowedActions.includes(t))
|
|
335
335
|
throw new Error(`Interaction ${e.key} does not allow ${t}.`);
|
|
336
|
-
if (!
|
|
336
|
+
if (!D(t))
|
|
337
337
|
throw new Error(`Interaction action ${t} is not a persistence decision.`);
|
|
338
|
-
const n =
|
|
338
|
+
const n = s.now ?? /* @__PURE__ */ new Date(), a = {
|
|
339
339
|
promptKey: e.key,
|
|
340
340
|
category: e.category,
|
|
341
341
|
action: t,
|
|
342
342
|
scope: e.scope,
|
|
343
343
|
decidedAt: n.toISOString(),
|
|
344
|
-
nextEligibleAt: this.getNextEligibleAt(e, t, n,
|
|
345
|
-
},
|
|
346
|
-
return
|
|
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;
|
|
347
347
|
}
|
|
348
348
|
isDecisionEligible(e, t) {
|
|
349
349
|
return e ? e.action === "dismiss" || e.action === "never" || e.action === "dont_show_again" ? !1 : !e.nextEligibleAt || Date.parse(e.nextEligibleAt) <= t : !0;
|
|
350
350
|
}
|
|
351
|
-
getNextEligibleAt(e, t,
|
|
351
|
+
getNextEligibleAt(e, t, s, n) {
|
|
352
352
|
if (t === "later")
|
|
353
|
-
return new Date(
|
|
353
|
+
return new Date(s.getTime() + (e.laterDelayMs ?? 3600 * 1e3)).toISOString();
|
|
354
354
|
if (t === "snooze") {
|
|
355
|
-
if (!n || n.getTime() <=
|
|
355
|
+
if (!n || n.getTime() <= s.getTime())
|
|
356
356
|
throw new Error("Snooze requires a future next-eligible time.");
|
|
357
357
|
return n.toISOString();
|
|
358
358
|
}
|
|
359
359
|
return null;
|
|
360
360
|
}
|
|
361
361
|
getDecisionKey(e) {
|
|
362
|
-
const t =
|
|
362
|
+
const t = b(e.scope);
|
|
363
363
|
return e.action === "dont_show_again" ? `${t}:category:${e.category}` : `${t}:interaction:${e.promptKey}`;
|
|
364
364
|
}
|
|
365
365
|
getExactKey(e) {
|
|
366
|
-
return `${
|
|
366
|
+
return `${b(e.scope)}:interaction:${e.key}`;
|
|
367
367
|
}
|
|
368
368
|
getCategoryKey(e) {
|
|
369
|
-
return `${
|
|
369
|
+
return `${b(e.scope)}:category:${e.category}`;
|
|
370
370
|
}
|
|
371
371
|
}
|
|
372
|
-
function
|
|
372
|
+
function V(i, e) {
|
|
373
373
|
return {
|
|
374
|
-
load: async () =>
|
|
375
|
-
save: async (t) =>
|
|
374
|
+
load: async () => x(i, e),
|
|
375
|
+
save: async (t) => i.setItem(e, JSON.stringify(t))
|
|
376
376
|
};
|
|
377
377
|
}
|
|
378
|
-
function
|
|
379
|
-
const t =
|
|
378
|
+
function x(i, e) {
|
|
379
|
+
const t = i.getItem(e);
|
|
380
380
|
if (!t) return [];
|
|
381
|
-
const
|
|
382
|
-
return Array.isArray(
|
|
381
|
+
const s = JSON.parse(t);
|
|
382
|
+
return Array.isArray(s) ? s.filter(I) : [];
|
|
383
383
|
}
|
|
384
|
-
function
|
|
385
|
-
return `${
|
|
384
|
+
function b(i) {
|
|
385
|
+
return `${i.level}:${i.key}`;
|
|
386
386
|
}
|
|
387
|
-
function
|
|
388
|
-
return
|
|
387
|
+
function D(i) {
|
|
388
|
+
return i === "dismiss" || i === "later" || i === "snooze" || i === "never" || i === "dont_show_again";
|
|
389
389
|
}
|
|
390
|
-
function
|
|
391
|
-
if (!
|
|
392
|
-
const e =
|
|
393
|
-
return typeof e.promptKey == "string" && typeof e.category == "string" && typeof e.decidedAt == "string" && (e.nextEligibleAt === null || typeof e.nextEligibleAt == "string") &&
|
|
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");
|
|
394
394
|
}
|
|
395
|
-
const
|
|
395
|
+
const C = {
|
|
396
396
|
working: "⏳",
|
|
397
397
|
completed: "✅",
|
|
398
398
|
failed: "❗",
|
|
399
399
|
stopped: "⏹️"
|
|
400
|
-
},
|
|
401
|
-
function
|
|
402
|
-
if (!e) return
|
|
403
|
-
const t =
|
|
404
|
-
return t ? `${
|
|
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;
|
|
405
405
|
}
|
|
406
|
-
class
|
|
406
|
+
class Z {
|
|
407
407
|
constructor(e) {
|
|
408
408
|
this.titleDocument = e;
|
|
409
409
|
}
|
|
@@ -420,16 +420,16 @@ class H {
|
|
|
420
420
|
this.liveStatusVersion += 1, this.applyClear();
|
|
421
421
|
}
|
|
422
422
|
async syncStatus(e) {
|
|
423
|
-
const t = this.liveStatusVersion,
|
|
424
|
-
|
|
423
|
+
const t = this.liveStatusVersion, s = await e();
|
|
424
|
+
s === void 0 || t !== this.liveStatusVersion || (s ? this.applyStatus(s) : this.applyClear());
|
|
425
425
|
}
|
|
426
426
|
applyStatus(e) {
|
|
427
427
|
const t = this.titleDocument.getTitle();
|
|
428
|
-
t !== this.lastAppliedTitle && (this.baseTitle =
|
|
428
|
+
t !== this.lastAppliedTitle && (this.baseTitle = y(t)), this.status = e, this.stopObserving || (this.stopObserving = this.titleDocument.observeTitle(() => this.handleTitleChanged())), this.applyTitle();
|
|
429
429
|
}
|
|
430
430
|
applyClear() {
|
|
431
|
-
const e = this.titleDocument.getTitle(), t = this.lastAppliedTitle !== null && e === this.lastAppliedTitle,
|
|
432
|
-
this.status = null, this.lastAppliedTitle = null, this.stopObserving?.(), this.stopObserving = null, t ? this.titleDocument.setTitle(this.baseTitle) :
|
|
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);
|
|
433
433
|
}
|
|
434
434
|
handleTitleChanged() {
|
|
435
435
|
!this.status || this.titleDocument.getTitle() === this.lastAppliedTitle || this.applyTitle();
|
|
@@ -437,19 +437,19 @@ class H {
|
|
|
437
437
|
applyTitle() {
|
|
438
438
|
if (!this.status)
|
|
439
439
|
return;
|
|
440
|
-
const e =
|
|
440
|
+
const e = q(this.baseTitle, this.status);
|
|
441
441
|
this.lastAppliedTitle = e, this.titleDocument.getTitle() !== e && this.titleDocument.setTitle(e);
|
|
442
442
|
}
|
|
443
443
|
}
|
|
444
|
-
function
|
|
444
|
+
function J(i) {
|
|
445
445
|
return {
|
|
446
|
-
getTitle: () =>
|
|
446
|
+
getTitle: () => i.title,
|
|
447
447
|
setTitle: (e) => {
|
|
448
|
-
|
|
448
|
+
i.title = e;
|
|
449
449
|
},
|
|
450
450
|
observeTitle: (e) => {
|
|
451
451
|
const t = new MutationObserver(e);
|
|
452
|
-
return t.observe(
|
|
452
|
+
return t.observe(i.head, {
|
|
453
453
|
childList: !0,
|
|
454
454
|
subtree: !0,
|
|
455
455
|
characterData: !0
|
|
@@ -457,21 +457,43 @@ function j(s) {
|
|
|
457
457
|
}
|
|
458
458
|
};
|
|
459
459
|
}
|
|
460
|
-
function
|
|
461
|
-
return
|
|
460
|
+
function y(i) {
|
|
461
|
+
return i.replace(L, "");
|
|
462
|
+
}
|
|
463
|
+
function _(i, e) {
|
|
464
|
+
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);
|
|
469
|
+
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 });
|
|
471
|
+
return {
|
|
472
|
+
...i,
|
|
473
|
+
messages: s,
|
|
474
|
+
isThinking: !1,
|
|
475
|
+
isRetrying: !1,
|
|
476
|
+
pendingMessageStatus: null,
|
|
477
|
+
turnPhase: null,
|
|
478
|
+
taskStatus: "stopped",
|
|
479
|
+
lastError: null,
|
|
480
|
+
lastErrorCode: null
|
|
481
|
+
};
|
|
462
482
|
}
|
|
463
|
-
const
|
|
464
|
-
function
|
|
465
|
-
if (!
|
|
466
|
-
const e =
|
|
467
|
-
return typeof e.observedAt == "string" && e.observedAt.length <= 40 && Number.isFinite(Date.parse(e.observedAt)) &&
|
|
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;
|
|
487
|
+
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";
|
|
468
488
|
}
|
|
469
|
-
const
|
|
470
|
-
function
|
|
471
|
-
const e =
|
|
472
|
-
return e.length >
|
|
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;
|
|
473
493
|
}
|
|
474
|
-
const
|
|
494
|
+
const $ = {
|
|
495
|
+
"in-progress-stop-unavailable": "An in-progress response has no visible enabled interrupt control.",
|
|
496
|
+
"stop-did-not-interrupt": "The stopped response remained in progress after an interrupt click.",
|
|
475
497
|
"duplicate-message-item": "A canonical message rendered more than once.",
|
|
476
498
|
"duplicate-canonical-item": "A canonical session item rendered more than once.",
|
|
477
499
|
"duplicate-tool-call": "A tool call rendered more than once.",
|
|
@@ -484,43 +506,45 @@ const C = {
|
|
|
484
506
|
"thinking-groups-without-user-message": "Multiple thinking groups appeared without a user message between them.",
|
|
485
507
|
"thinking-without-progress": "Thinking remained visible without progress for five minutes."
|
|
486
508
|
};
|
|
487
|
-
function
|
|
488
|
-
return typeof
|
|
509
|
+
function K(i) {
|
|
510
|
+
return typeof i == "string" && i.startsWith("ui_invariant:") && Object.prototype.hasOwnProperty.call($, i.slice(13));
|
|
489
511
|
}
|
|
490
|
-
function
|
|
512
|
+
function P(i) {
|
|
491
513
|
return {
|
|
492
|
-
...
|
|
493
|
-
name:
|
|
494
|
-
mimeType:
|
|
495
|
-
sizeBytes:
|
|
496
|
-
...
|
|
497
|
-
...
|
|
498
|
-
...
|
|
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 }
|
|
499
521
|
};
|
|
500
522
|
}
|
|
501
|
-
function
|
|
502
|
-
if (!
|
|
503
|
-
const e =
|
|
523
|
+
function Y(i) {
|
|
524
|
+
if (!i || typeof i != "object" || !("type" in i)) return !1;
|
|
525
|
+
const e = i;
|
|
504
526
|
switch (e.type) {
|
|
505
527
|
case "runtime.connect":
|
|
506
528
|
case "session.new":
|
|
507
|
-
case "run.stop":
|
|
508
529
|
case "run.retry":
|
|
509
530
|
return !0;
|
|
531
|
+
case "run.stop":
|
|
532
|
+
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);
|
|
510
533
|
case "runtime.report_response_visibility":
|
|
511
|
-
return
|
|
534
|
+
return Q(e.observation);
|
|
512
535
|
case "runtime.warmup":
|
|
513
536
|
return e.reason === "panel_open" || e.reason === "extension_install" || e.reason === "composer_input";
|
|
514
537
|
case "runtime.report_displayed_error":
|
|
515
538
|
return (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);
|
|
516
539
|
case "runtime.report_invalid_state_transition":
|
|
517
|
-
return (e.reason === "submitted_turn_returned_to_welcome_without_new_chat" || e.reason === "new_messages_button_without_user_scroll" ||
|
|
540
|
+
return (e.reason === "submitted_turn_returned_to_welcome_without_new_chat" || e.reason === "new_messages_button_without_user_scroll" || K(e.reason)) && (e.clientMessageId === void 0 || typeof e.clientMessageId == "string");
|
|
518
541
|
case "runtime.widget_lifecycle":
|
|
519
542
|
return (e.action === "opened" || e.action === "closed" || e.action === "minimized") && typeof e.trigger == "string";
|
|
520
543
|
case "session.load":
|
|
521
544
|
return typeof e.sessionId == "string" && e.sessionId.length > 0;
|
|
522
545
|
case "session.list":
|
|
523
546
|
return (e.cursor === void 0 || e.cursor === null || typeof e.cursor == "string") && (e.limit === void 0 || typeof e.limit == "number") && (e.pinned === void 0 || typeof e.pinned == "boolean");
|
|
547
|
+
case "composer.select_model":
|
|
524
548
|
case "session.set_model":
|
|
525
549
|
return typeof e.model == "string";
|
|
526
550
|
case "session.pin":
|
|
@@ -532,18 +556,18 @@ function V(s) {
|
|
|
532
556
|
case "conversation.stage_proactive_suggestion":
|
|
533
557
|
return typeof e.question == "string" && typeof e.clientMessageId == "string";
|
|
534
558
|
case "conversation.stage":
|
|
535
|
-
return typeof e.content == "string" && typeof e.clientMessageId == "string" && (e.submittedAt === void 0 || typeof e.submittedAt == "number") && (e.attachments === void 0 || Array.isArray(e.attachments));
|
|
559
|
+
return typeof e.content == "string" && typeof e.clientMessageId == "string" && (e.submittedAt === void 0 || typeof e.submittedAt == "number") && (e.requestedModel === void 0 || typeof e.requestedModel == "string") && (e.attachments === void 0 || Array.isArray(e.attachments));
|
|
536
560
|
case "conversation.fail_staged":
|
|
537
561
|
return typeof e.clientMessageId == "string" && typeof e.message == "string";
|
|
538
562
|
case "conversation.send":
|
|
539
|
-
return typeof e.content == "string" && typeof e.clientMessageId == "string" && (e.automationOnboarding === void 0 || typeof e.automationOnboarding == "boolean") && (e.attachments === void 0 || Array.isArray(e.attachments));
|
|
563
|
+
return typeof e.content == "string" && typeof e.clientMessageId == "string" && (e.requestedModel === void 0 || typeof e.requestedModel == "string") && (e.automationOnboarding === void 0 || typeof e.automationOnboarding == "boolean") && (e.attachments === void 0 || Array.isArray(e.attachments));
|
|
540
564
|
default:
|
|
541
565
|
return !1;
|
|
542
566
|
}
|
|
543
567
|
}
|
|
544
|
-
class
|
|
545
|
-
constructor(e, t,
|
|
546
|
-
this.adapter = t, this.state =
|
|
568
|
+
class W {
|
|
569
|
+
constructor(e, t, s) {
|
|
570
|
+
this.adapter = t, this.state = A(e), this.model = s;
|
|
547
571
|
}
|
|
548
572
|
adapter;
|
|
549
573
|
listeners = {};
|
|
@@ -552,56 +576,80 @@ class Z {
|
|
|
552
576
|
interactionListeners = /* @__PURE__ */ new Set();
|
|
553
577
|
accountListeners = /* @__PURE__ */ new Set();
|
|
554
578
|
state;
|
|
555
|
-
sessionHistoryState =
|
|
579
|
+
sessionHistoryState = f("unavailable");
|
|
556
580
|
model;
|
|
557
581
|
interactions = [];
|
|
558
582
|
account = null;
|
|
559
583
|
stagedProactiveSuggestionClientMessageId = null;
|
|
560
584
|
unacknowledgedSubmissions = /* @__PURE__ */ new Map();
|
|
585
|
+
submissionGeneration = 0;
|
|
586
|
+
stoppedProjection = null;
|
|
561
587
|
operationQueue = Promise.resolve();
|
|
562
588
|
destroyed = !1;
|
|
563
589
|
on(e, t) {
|
|
564
|
-
const
|
|
565
|
-
return
|
|
590
|
+
const s = this.listeners[e] ?? /* @__PURE__ */ new Set();
|
|
591
|
+
return s.add(t), this.listeners[e] = s, () => s.delete(t);
|
|
566
592
|
}
|
|
567
593
|
getState() {
|
|
568
|
-
return
|
|
569
|
-
}
|
|
570
|
-
updateProjection(e, t,
|
|
571
|
-
if (
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
const o = this.state.messages.find(
|
|
579
|
-
(c) => c.clientMessageId === a
|
|
580
|
-
);
|
|
581
|
-
if (o) {
|
|
582
|
-
o.attachments = q(
|
|
583
|
-
l.message.attachments,
|
|
584
|
-
o.attachments
|
|
585
|
-
), this.unacknowledgedSubmissions.delete(a);
|
|
586
|
-
continue;
|
|
587
|
-
}
|
|
588
|
-
l.sessionId ??= e.sessionId, this.state.messages.push(l.message), this.state.pendingMessageStatus = "sending", this.state.turnPhase ??= "sending", this.state.taskStatus ??= "working";
|
|
594
|
+
return A(this.state);
|
|
595
|
+
}
|
|
596
|
+
updateProjection(e, t, s, n, a) {
|
|
597
|
+
if (this.destroyed) return;
|
|
598
|
+
const l = this.state;
|
|
599
|
+
if (this.state = A(e), l.user?.id === e.user?.id)
|
|
600
|
+
for (const r of this.state.messages) {
|
|
601
|
+
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));
|
|
589
604
|
}
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
605
|
+
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)
|
|
608
|
+
this.stoppedProjection = null;
|
|
609
|
+
else {
|
|
610
|
+
const d = [
|
|
611
|
+
r.activeResponseUserMessageId,
|
|
612
|
+
r.assistantDraftRespondsToUserMessageId,
|
|
613
|
+
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 : {
|
|
616
|
+
...this.state,
|
|
617
|
+
messages: r.messages,
|
|
618
|
+
assistantDraft: r.assistantDraft
|
|
619
|
+
}, (/* @__PURE__ */ new Date()).toISOString()), this.stoppedProjection = this.getState();
|
|
594
620
|
}
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
621
|
+
}
|
|
622
|
+
for (const [r, o] of this.unacknowledgedSubmissions) {
|
|
623
|
+
if (e.user?.id !== o.userId || o.sessionId !== null && e.sessionId !== o.sessionId) {
|
|
624
|
+
this.unacknowledgedSubmissions.delete(r);
|
|
625
|
+
continue;
|
|
598
626
|
}
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
627
|
+
const c = this.state.messages.find(
|
|
628
|
+
(u) => u.clientMessageId === r
|
|
629
|
+
);
|
|
630
|
+
if (c) {
|
|
631
|
+
c.attachments = T(
|
|
632
|
+
o.message.attachments,
|
|
633
|
+
c.attachments
|
|
634
|
+
), this.unacknowledgedSubmissions.delete(r);
|
|
635
|
+
continue;
|
|
602
636
|
}
|
|
603
|
-
this.
|
|
637
|
+
o.sessionId ??= e.sessionId, this.state.messages.push(o.message), this.state.pendingMessageStatus = "sending", this.state.turnPhase ??= "sending", this.state.taskStatus ??= "working";
|
|
638
|
+
}
|
|
639
|
+
if (t !== void 0 && (this.model = t), s && JSON.stringify(s) !== JSON.stringify(this.sessionHistoryState)) {
|
|
640
|
+
this.sessionHistoryState = E(s);
|
|
641
|
+
for (const r of this.sessionHistoryListeners)
|
|
642
|
+
r(this.getSessionHistoryState());
|
|
643
|
+
}
|
|
644
|
+
if (n && JSON.stringify(n) !== JSON.stringify(this.interactions)) {
|
|
645
|
+
this.interactions = n.map((r) => ({ ...r }));
|
|
646
|
+
for (const r of this.interactionListeners) r(this.getInteractions());
|
|
647
|
+
}
|
|
648
|
+
if (a !== void 0 && JSON.stringify(a) !== JSON.stringify(this.account)) {
|
|
649
|
+
this.account = a ? { ...a } : null;
|
|
650
|
+
for (const r of this.accountListeners) r(this.getAccount());
|
|
604
651
|
}
|
|
652
|
+
this.emit("state", this.getState());
|
|
605
653
|
}
|
|
606
654
|
async connect() {
|
|
607
655
|
await this.dispatch({ type: "runtime.connect" });
|
|
@@ -632,99 +680,106 @@ class Z {
|
|
|
632
680
|
}).catch(() => {
|
|
633
681
|
});
|
|
634
682
|
}
|
|
635
|
-
reportDisplayedError(e, t,
|
|
683
|
+
reportDisplayedError(e, t, s) {
|
|
636
684
|
this.adapter.dispatch({
|
|
637
685
|
type: "runtime.report_displayed_error",
|
|
638
686
|
reason: e,
|
|
639
687
|
errorFingerprint: t,
|
|
640
|
-
...
|
|
688
|
+
...s ? { displayedMessage: U(s) } : {}
|
|
641
689
|
}).catch(() => {
|
|
642
690
|
});
|
|
643
691
|
}
|
|
644
692
|
sendMessage(e, t = {}) {
|
|
645
|
-
const
|
|
646
|
-
if (!
|
|
647
|
-
const
|
|
648
|
-
id: `local-${
|
|
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 = {
|
|
696
|
+
id: `local-${a}`,
|
|
649
697
|
role: "user",
|
|
650
|
-
content:
|
|
698
|
+
content: s,
|
|
651
699
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
652
700
|
...n.length > 0 ? { attachments: n } : {},
|
|
653
|
-
clientMessageId:
|
|
701
|
+
clientMessageId: a
|
|
654
702
|
};
|
|
655
|
-
|
|
656
|
-
message: { ...
|
|
657
|
-
sessionId:
|
|
658
|
-
userId:
|
|
703
|
+
this.unacknowledgedSubmissions.set(a, {
|
|
704
|
+
message: { ...c, attachments: c.attachments?.map((d) => ({ ...d })) },
|
|
705
|
+
sessionId: r.sessionId,
|
|
706
|
+
userId: r.user?.id
|
|
659
707
|
}), this.state = {
|
|
660
708
|
...this.state,
|
|
661
|
-
messages: [...this.state.messages,
|
|
709
|
+
messages: [...this.state.messages, c],
|
|
662
710
|
pendingMessageStatus: "sending",
|
|
663
711
|
turnPhase: this.state.isThinking ? this.state.turnPhase : "sending",
|
|
664
712
|
taskStatus: "working",
|
|
665
713
|
isRetrying: !1,
|
|
666
714
|
lastError: null
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
l
|
|
715
|
+
};
|
|
716
|
+
const u = this.enqueueOperation(() => this.sendMessageNow(
|
|
717
|
+
s,
|
|
718
|
+
{ ...t, clientMessageId: a, submittedAt: l },
|
|
719
|
+
r,
|
|
720
|
+
o
|
|
671
721
|
));
|
|
722
|
+
return this.emit("state", this.getState()), u;
|
|
672
723
|
}
|
|
673
|
-
async sendMessageNow(e, t,
|
|
674
|
-
const
|
|
675
|
-
let
|
|
724
|
+
async sendMessageNow(e, t, s, n) {
|
|
725
|
+
const a = e, l = t.clientMessageId;
|
|
726
|
+
let r = t.attachments ?? [], o = !1;
|
|
727
|
+
if (n !== this.submissionGeneration) return null;
|
|
676
728
|
try {
|
|
677
729
|
if (await this.adapter.dispatch({
|
|
678
730
|
type: "conversation.stage",
|
|
679
|
-
content:
|
|
680
|
-
clientMessageId:
|
|
731
|
+
content: a,
|
|
732
|
+
clientMessageId: l,
|
|
681
733
|
proactiveSuggestionQuestion: t.proactiveSuggestionQuestion,
|
|
682
734
|
// Preview URLs belong to the renderer's optimistic snapshot and are not valid runtime-command metadata.
|
|
683
|
-
attachments:
|
|
735
|
+
attachments: r.length > 0 ? r.map(P) : void 0,
|
|
684
736
|
submittedAt: t.submittedAt
|
|
685
|
-
}),
|
|
737
|
+
}), n !== this.submissionGeneration) return null;
|
|
738
|
+
if (o = !0, r.length > 0) {
|
|
686
739
|
if (!this.adapter.uploadAttachment)
|
|
687
740
|
throw new Error("The runtime does not support attachments.");
|
|
688
|
-
const
|
|
689
|
-
for (const d of
|
|
741
|
+
const u = [];
|
|
742
|
+
for (const d of r) {
|
|
690
743
|
if (d.sandboxPath || d.storageKey) {
|
|
691
|
-
|
|
744
|
+
u.push(d);
|
|
692
745
|
continue;
|
|
693
746
|
}
|
|
694
|
-
const
|
|
695
|
-
if (!
|
|
696
|
-
|
|
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;
|
|
697
750
|
}
|
|
698
|
-
|
|
751
|
+
r = u;
|
|
699
752
|
}
|
|
700
|
-
const
|
|
753
|
+
const c = await this.adapter.dispatch({
|
|
701
754
|
type: "conversation.send",
|
|
702
|
-
content:
|
|
703
|
-
clientMessageId:
|
|
755
|
+
content: a,
|
|
756
|
+
clientMessageId: l,
|
|
704
757
|
initiatedBy: t.initiatedBy,
|
|
705
758
|
invocation: t.invocation,
|
|
706
759
|
proactiveSuggestionQuestion: t.proactiveSuggestionQuestion,
|
|
707
760
|
...t.automationOnboarding ? { automationOnboarding: !0 } : {},
|
|
708
|
-
attachments:
|
|
761
|
+
attachments: r.length > 0 ? r.map(P) : void 0
|
|
709
762
|
});
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
763
|
+
if (n !== this.submissionGeneration) return null;
|
|
764
|
+
for (const u of t.attachments ?? [])
|
|
765
|
+
u.id && this.attachmentFiles.delete(u.id);
|
|
766
|
+
return l === this.stagedProactiveSuggestionClientMessageId && (this.stagedProactiveSuggestionClientMessageId = null), c?.clientMessageId ?? l;
|
|
767
|
+
} catch (c) {
|
|
768
|
+
if (n !== this.submissionGeneration) return null;
|
|
769
|
+
throw this.unacknowledgedSubmissions.delete(l), this.state = {
|
|
715
770
|
...this.state,
|
|
716
771
|
messages: this.state.messages.filter(
|
|
717
|
-
(
|
|
772
|
+
(u) => u.id !== `local-${l}` && u.id !== `optimistic-user-message:${l}`
|
|
718
773
|
),
|
|
719
|
-
pendingMessageStatus:
|
|
720
|
-
turnPhase:
|
|
721
|
-
isThinking:
|
|
722
|
-
taskStatus:
|
|
723
|
-
}, this.emit("state", this.getState()),
|
|
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({
|
|
724
779
|
type: "conversation.fail_staged",
|
|
725
|
-
clientMessageId:
|
|
726
|
-
message:
|
|
727
|
-
}),
|
|
780
|
+
clientMessageId: l,
|
|
781
|
+
message: c instanceof Error ? c.message : String(c)
|
|
782
|
+
}), c;
|
|
728
783
|
}
|
|
729
784
|
}
|
|
730
785
|
getModel() {
|
|
@@ -735,7 +790,7 @@ class Z {
|
|
|
735
790
|
});
|
|
736
791
|
}
|
|
737
792
|
retryLastMessage() {
|
|
738
|
-
return this.dispatch({ type: "run.retry" }), !0;
|
|
793
|
+
return this.stoppedProjection = null, this.dispatch({ type: "run.retry" }), !0;
|
|
739
794
|
}
|
|
740
795
|
createLocalAttachment(e) {
|
|
741
796
|
const t = crypto.randomUUID();
|
|
@@ -747,23 +802,37 @@ class Z {
|
|
|
747
802
|
};
|
|
748
803
|
}
|
|
749
804
|
stop() {
|
|
750
|
-
|
|
805
|
+
const e = this.cancelPendingSubmissions();
|
|
806
|
+
this.state = _(this.state, (/* @__PURE__ */ new Date()).toISOString()), this.stoppedProjection = this.getState(), this.emit("state", this.getState());
|
|
807
|
+
const t = this.adapter.dispatch({ type: "run.stop", ...e.length ? { clientMessageIds: e } : {} });
|
|
808
|
+
return this.operationQueue = t.then(() => {
|
|
809
|
+
}, () => {
|
|
810
|
+
}), t.then(() => {
|
|
751
811
|
});
|
|
752
812
|
}
|
|
813
|
+
cancelPendingSubmissions() {
|
|
814
|
+
const e = [...this.unacknowledgedSubmissions.keys()];
|
|
815
|
+
this.submissionGeneration++;
|
|
816
|
+
for (const t of this.unacknowledgedSubmissions.values())
|
|
817
|
+
for (const s of t.message.attachments ?? [])
|
|
818
|
+
s.id && this.attachmentFiles.delete(s.id);
|
|
819
|
+
return this.unacknowledgedSubmissions.clear(), this.operationQueue = Promise.resolve(), e;
|
|
820
|
+
}
|
|
753
821
|
startNewSession(e = {}) {
|
|
754
|
-
return this.
|
|
822
|
+
return this.cancelPendingSubmissions(), this.stoppedProjection = null, e.notifyTransport === !1 ? Promise.resolve() : this.dispatch({ type: "session.new" }).then(() => {
|
|
755
823
|
});
|
|
756
824
|
}
|
|
757
825
|
async listSessions(e = {}) {
|
|
758
|
-
await this.dispatch({ type: "session.list", ...e });
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
sessions:
|
|
762
|
-
|
|
763
|
-
|
|
826
|
+
const t = await this.dispatch({ type: "session.list", ...e });
|
|
827
|
+
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 };
|
|
830
|
+
}
|
|
831
|
+
if (!t?.sessionHistoryPage) throw new Error("Session list command did not return a page.");
|
|
832
|
+
return t.sessionHistoryPage;
|
|
764
833
|
}
|
|
765
834
|
getSessionHistoryState() {
|
|
766
|
-
return
|
|
835
|
+
return E(this.sessionHistoryState);
|
|
767
836
|
}
|
|
768
837
|
subscribeSessionHistory(e) {
|
|
769
838
|
return this.sessionHistoryListeners.add(e), e(this.getSessionHistoryState()), () => this.sessionHistoryListeners.delete(e);
|
|
@@ -774,7 +843,7 @@ class Z {
|
|
|
774
843
|
}
|
|
775
844
|
loadMoreSessionHistory() {
|
|
776
845
|
const e = this.sessionHistoryState.data?.nextCursor ?? null;
|
|
777
|
-
return e ? this.dispatch({ type: "session.list", cursor: e
|
|
846
|
+
return e ? this.dispatch({ type: "session.list", cursor: e }).then(() => {
|
|
778
847
|
}) : Promise.resolve();
|
|
779
848
|
}
|
|
780
849
|
setSessionPinned(e, t) {
|
|
@@ -791,12 +860,12 @@ class Z {
|
|
|
791
860
|
subscribeInteractions(e) {
|
|
792
861
|
return this.interactionListeners.add(e), e(this.getInteractions()), () => this.interactionListeners.delete(e);
|
|
793
862
|
}
|
|
794
|
-
actOnInteraction(e, t,
|
|
863
|
+
actOnInteraction(e, t, s, n = {}) {
|
|
795
864
|
return this.dispatch({
|
|
796
865
|
type: "interaction.act",
|
|
797
866
|
interactionId: e,
|
|
798
867
|
action: t,
|
|
799
|
-
expectedRevision:
|
|
868
|
+
expectedRevision: s,
|
|
800
869
|
...n
|
|
801
870
|
}).then(() => {
|
|
802
871
|
});
|
|
@@ -817,11 +886,11 @@ class Z {
|
|
|
817
886
|
stageProactiveSuggestionQuestion(e) {
|
|
818
887
|
const t = e.trim();
|
|
819
888
|
if (!t) return Promise.resolve();
|
|
820
|
-
const
|
|
821
|
-
return this.stagedProactiveSuggestionClientMessageId =
|
|
889
|
+
const s = this.stagedProactiveSuggestionClientMessageId ?? crypto.randomUUID();
|
|
890
|
+
return this.stagedProactiveSuggestionClientMessageId = s, this.dispatch({
|
|
822
891
|
type: "conversation.stage_proactive_suggestion",
|
|
823
892
|
question: t,
|
|
824
|
-
clientMessageId:
|
|
893
|
+
clientMessageId: s
|
|
825
894
|
}).then(() => {
|
|
826
895
|
});
|
|
827
896
|
}
|
|
@@ -838,73 +907,73 @@ class Z {
|
|
|
838
907
|
), t;
|
|
839
908
|
}
|
|
840
909
|
emit(e, t) {
|
|
841
|
-
const
|
|
842
|
-
for (const n of
|
|
910
|
+
const s = this.listeners[e];
|
|
911
|
+
for (const n of s ?? []) n(t);
|
|
843
912
|
}
|
|
844
913
|
}
|
|
845
|
-
function
|
|
846
|
-
if (!e || !
|
|
914
|
+
function T(i, e) {
|
|
915
|
+
if (!e || !i) return e;
|
|
847
916
|
const t = /* @__PURE__ */ new Map();
|
|
848
|
-
for (const
|
|
849
|
-
const n =
|
|
850
|
-
|
|
917
|
+
for (const s of i) {
|
|
918
|
+
const n = s.previewUrl;
|
|
919
|
+
s.id && n && t.set(s.id, n);
|
|
851
920
|
}
|
|
852
|
-
return e.map((
|
|
853
|
-
const n =
|
|
854
|
-
return n ? { ...
|
|
921
|
+
return e.map((s) => {
|
|
922
|
+
const n = s.id ? t.get(s.id) : void 0;
|
|
923
|
+
return n ? { ...s, previewUrl: n } : s;
|
|
855
924
|
});
|
|
856
925
|
}
|
|
857
|
-
function
|
|
926
|
+
function A(i) {
|
|
858
927
|
return {
|
|
859
|
-
...
|
|
860
|
-
starterPrompts: [...
|
|
861
|
-
appearance:
|
|
862
|
-
messages:
|
|
928
|
+
...i,
|
|
929
|
+
starterPrompts: [...i.starterPrompts],
|
|
930
|
+
appearance: i.appearance ? { ...i.appearance } : null,
|
|
931
|
+
messages: i.messages.map((e) => {
|
|
863
932
|
const t = {
|
|
864
933
|
...e,
|
|
865
|
-
attachments: e.attachments?.map((
|
|
866
|
-
},
|
|
867
|
-
return
|
|
868
|
-
value:
|
|
934
|
+
attachments: e.attachments?.map((l) => ({ ...l }))
|
|
935
|
+
}, s = e.assistantDraftItemId, n = e.clientMessageId, a = e.proactiveSuggestionClientMessageId;
|
|
936
|
+
return a && Object.defineProperty(t, "proactiveSuggestionClientMessageId", {
|
|
937
|
+
value: a,
|
|
869
938
|
enumerable: !1
|
|
870
|
-
}),
|
|
871
|
-
value:
|
|
939
|
+
}), s && Object.defineProperty(t, "assistantDraftItemId", {
|
|
940
|
+
value: s,
|
|
872
941
|
enumerable: !1
|
|
873
942
|
}), n && Object.defineProperty(t, "clientMessageId", {
|
|
874
943
|
value: n,
|
|
875
944
|
enumerable: !1
|
|
876
945
|
}), t;
|
|
877
946
|
}),
|
|
878
|
-
activeScheduledFollowUps:
|
|
947
|
+
activeScheduledFollowUps: i.activeScheduledFollowUps?.map((e) => ({ ...e })) ?? null
|
|
879
948
|
};
|
|
880
949
|
}
|
|
881
|
-
function
|
|
950
|
+
function E(i) {
|
|
882
951
|
return {
|
|
883
|
-
...
|
|
884
|
-
data:
|
|
885
|
-
entities:
|
|
886
|
-
nextCursor:
|
|
952
|
+
...i,
|
|
953
|
+
data: i.data ? m({
|
|
954
|
+
entities: k(i.data).map((e) => ({ ...e })),
|
|
955
|
+
nextCursor: i.data.nextCursor
|
|
887
956
|
}) : null
|
|
888
957
|
};
|
|
889
958
|
}
|
|
890
959
|
export {
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
960
|
+
G as ProductAgentInteractionManager,
|
|
961
|
+
w as ProductAgentQueryController,
|
|
962
|
+
W as ProductAgentRemoteRuntimeClient,
|
|
963
|
+
H as ProductAgentSessionHistoryManager,
|
|
964
|
+
Z as ProductAgentTaskPageTitleController,
|
|
965
|
+
V as createLocalStorageInteractionDecisionStorage,
|
|
966
|
+
f as createProductAgentQueryState,
|
|
967
|
+
J as createProductAgentTaskPageTitleDocument,
|
|
968
|
+
q as formatProductAgentTaskPageTitle,
|
|
969
|
+
j as hasProductAgentPaidCreditFallback,
|
|
970
|
+
Y as isProductAgentRuntimeCommand,
|
|
971
|
+
O as mergeProductAgentEntityPages,
|
|
972
|
+
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
|
|
910
979
|
};
|