dsh-edge 0.18.0 → 0.19.0-alpha.2
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.i18n.yaml +2 -2
- package/README.md +8 -8
- package/README.zh.md +8 -8
- package/THIRD_PARTY_NOTICES.md +2011 -449
- package/dist/assets/fonts/Montserrat-OFL.txt +93 -0
- package/dist/assets/fonts/montserrat-light-Cvd2VjE_.woff2 +0 -0
- package/dist/assets/fonts/montserrat-medium-B4OyO9CN.woff2 +0 -0
- package/dist/assets/fonts/montserrat-regular-DYep38cA.woff2 +0 -0
- package/dist/assets/index-Cq6ljTv2.css +1 -0
- package/dist/assets/index-Dy0OhsZ5.js +127 -0
- package/dist/assets/langs/asciidoc-Ve4PFQV2.js +2 -0
- package/dist/assets/langs/bat-BkioyH1T.js +2 -0
- package/dist/assets/langs/bibtex-CHM0blh-.js +2 -0
- package/dist/assets/langs/clojure-P80f7IUj.js +2 -0
- package/dist/assets/langs/cmake-D1j8_8rp.js +2 -0
- package/dist/assets/langs/csv-fuZLfV_i.js +2 -0
- package/dist/assets/langs/dart-bE4Kk8sk.js +2 -0
- package/dist/assets/langs/diff-D97Zzqfu.js +2 -0
- package/dist/assets/langs/dotenv-Da5cRb03.js +2 -0
- package/dist/assets/langs/elixir-CvYZzuDY.js +2 -0
- package/dist/assets/langs/erlang-DsQrWhSR.js +2 -0
- package/dist/assets/langs/fish-BvzEVeQv.js +2 -0
- package/dist/assets/langs/fsharp-CXgrBDvD.js +2 -0
- package/dist/assets/langs/graphql-DujV8YkJ.js +2 -0
- package/dist/assets/langs/groovy-gcz8RCvz.js +2 -0
- package/dist/assets/langs/haskell-Df6bDoY_.js +2 -0
- package/dist/assets/langs/hcl-BWvSN4gD.js +2 -0
- package/dist/assets/langs/html-derivative-DOyKdj44.js +2 -0
- package/dist/assets/langs/html-fwsONPVS.js +2 -0
- package/dist/assets/langs/http-DcV90OkR.js +2 -0
- package/dist/assets/langs/javascript-DI5JR1nB.js +2 -0
- package/dist/assets/langs/julia-BpJ6DjL_.js +2 -0
- package/dist/assets/langs/latex-B4C7GdlO.js +2 -0
- package/dist/assets/langs/log-2UxHyX5q.js +2 -0
- package/dist/assets/langs/make-CHLpvVh8.js +2 -0
- package/dist/assets/langs/nix-CwoSXNpI.js +2 -0
- package/dist/assets/langs/perl-DsWkoyyU.js +2 -0
- package/dist/assets/langs/php-LEPfNACG.js +2 -0
- package/dist/assets/langs/powershell-Dpen1YoG.js +2 -0
- package/dist/assets/langs/proto-C7zT0LnQ.js +2 -0
- package/dist/assets/langs/r-Dspwwk_N.js +2 -0
- package/dist/assets/langs/rst-BbocfKWr.js +2 -0
- package/dist/assets/langs/ruby-R292Iif0.js +2 -0
- package/dist/assets/langs/scala-C151Ov-r.js +2 -0
- package/dist/assets/langs/svelte-DNMY6jOf.js +2 -0
- package/dist/assets/langs/system-verilog-CnnmHF94.js +2 -0
- package/dist/assets/langs/vb-D17OF-Vu.js +2 -0
- package/dist/assets/langs/verilog-BQ8w6xss.js +2 -0
- package/dist/assets/langs/vue-Dq2x6432.js +2 -0
- package/dist/favicon-dark.svg +3 -0
- package/dist/favicon.svg +0 -5
- package/dist/index.html +5 -4
- package/dist/manifest.webmanifest +3 -4
- package/dist/plugins/@deepseek-ai/dsh-api-gateway/client.js +353 -101
- package/dist/plugins/@deepseek-ai/dsh-api-job-controller/client.js +367 -0
- package/dist/plugins/@deepseek-ai/dsh-api-remotes/client.js +7223 -3584
- package/dist/plugins/@deepseek-ai/dsh-api-session-controller/client.js +1107 -991
- package/dist/plugins/@deepseek-ai/dsh-api-workspace-controller/client.js +119 -6
- package/dist/plugins/@deepseek-ai/dsh-api-workspace-files/client.js +41 -35
- package/dist/plugins/@deepseek-ai/dsh-client-connection/client.js +354 -5279
- package/dist/plugins/@deepseek-ai/dsh-client-file-upload/client.js +10 -23
- package/dist/plugins/@deepseek-ai/dsh-client-locale/client.js +234 -80
- package/dist/plugins/@deepseek-ai/dsh-client-modules/client.js +554 -46
- package/dist/plugins/@deepseek-ai/dsh-client-shortcuts/client.js +2006 -0
- package/dist/plugins/@deepseek-ai/dsh-client-ui-agent-preset/client.js +1090 -914
- package/dist/plugins/@deepseek-ai/dsh-client-ui-approval/client.js +79 -6
- package/dist/plugins/@deepseek-ai/dsh-client-ui-attachment/client.js +126 -155
- package/dist/plugins/@deepseek-ai/dsh-client-ui-chat/client.js +5776 -1593
- package/dist/plugins/@deepseek-ai/dsh-client-ui-commands/client.js +375 -121
- package/dist/plugins/@deepseek-ai/dsh-client-ui-conversation/client.js +3524 -1923
- package/dist/plugins/@deepseek-ai/dsh-client-ui-deliverables/client.js +1615 -258
- package/dist/plugins/@deepseek-ai/dsh-client-ui-directory-picker-browse/client.js +9 -9
- package/dist/plugins/@deepseek-ai/dsh-client-ui-goal/client.js +25 -10
- package/dist/plugins/@deepseek-ai/dsh-client-ui-input-trigger/client.js +169 -24
- package/dist/plugins/@deepseek-ai/dsh-client-ui-jobs/client.js +413 -63
- package/dist/plugins/@deepseek-ai/dsh-client-ui-layout/client.js +131 -14
- package/dist/plugins/@deepseek-ai/dsh-client-ui-message-feedback/client.js +24 -22
- package/dist/plugins/@deepseek-ai/dsh-client-ui-model-selection/client.js +281 -128
- package/dist/plugins/@deepseek-ai/dsh-client-ui-open-in-app/client.js +674 -223
- package/dist/plugins/@deepseek-ai/dsh-client-ui-plan/client.js +596 -18
- package/dist/plugins/@deepseek-ai/dsh-client-ui-reference/client.js +92 -9
- package/dist/plugins/@deepseek-ai/dsh-client-ui-renderer/client.js +467 -59
- package/dist/plugins/@deepseek-ai/dsh-client-ui-session/client.js +231 -72
- package/dist/plugins/@deepseek-ai/dsh-client-ui-settings/client.js +281 -117
- package/dist/plugins/@deepseek-ai/dsh-client-ui-settings-general/client.js +642 -122
- package/dist/plugins/@deepseek-ai/dsh-client-ui-settings-models/client.js +1565 -438
- package/dist/plugins/@deepseek-ai/dsh-client-ui-settings-plugin-inventory/client.js +201 -75
- package/dist/plugins/@deepseek-ai/dsh-client-ui-settings-plugins/client.js +30 -1628
- package/dist/plugins/@deepseek-ai/dsh-client-ui-shortcuts/client.js +1163 -0
- package/dist/plugins/@deepseek-ai/dsh-client-ui-sidebar/client.js +165 -39
- package/dist/plugins/@deepseek-ai/dsh-client-ui-sidebar-browser/client.js +1648 -0
- package/dist/plugins/@deepseek-ai/dsh-client-ui-sidebar-documentpreview/client.js +5515 -25622
- package/dist/plugins/@deepseek-ai/dsh-client-ui-sidebar-files/client.js +419 -118
- package/dist/plugins/@deepseek-ai/dsh-client-ui-sidebar-right/client.js +5692 -260
- package/dist/plugins/@deepseek-ai/dsh-client-ui-skill/client.js +156 -41
- package/dist/plugins/@deepseek-ai/dsh-client-ui-subagent/client.js +386 -263
- package/dist/plugins/@deepseek-ai/dsh-client-ui-theme/client.js +183 -73
- package/dist/plugins/@deepseek-ai/dsh-client-ui-tool/client.js +2367 -429
- package/dist/plugins/@deepseek-ai/dsh-client-ui-trajectory/client.js +788 -270
- package/dist/plugins/@deepseek-ai/dsh-client-ui-user-questions/client.js +87 -79
- package/dist/plugins/@deepseek-ai/dsh-client-ui-workflow-run/client.js +28 -14
- package/dist/plugins/@deepseek-ai/dsh-client-ui-workspace/client.js +2647 -1044
- package/dist/plugins/@deepseek-ai/dsh-typert-registry/client.js +22 -7
- package/dist/plugins/dsh-edge-client-ui/client.js +1 -10
- package/package.json +96 -86
- package/scripts/cli.mjs +16 -4
- package/scripts/install.d.mts +12 -2
- package/scripts/install.mjs +36 -9
- package/scripts/legal-files.mjs +15 -0
- package/worker/direct/index.js +2564 -1822
- package/worker/isolated/index.js +2144 -1402
- package/dist/assets/index-BKQ_L1z6.js +0 -117
- package/dist/assets/index-DPX2bQLO.css +0 -1
- package/dist/assets/langs/html-CfGypltT.js +0 -2
- package/dist/assets/langs/php-DJl5gRdb.js +0 -2
- package/dist/assets/langs/ruby-5eNB0pDK.js +0 -2
- package/dist/plugins/@deepseek-ai/dsh-client-ui-permission-presets/client.js +0 -505
- package/dist/plugins/@deepseek-ai/dsh-client-ui-schedule/client.js +0 -307
|
@@ -34,6 +34,27 @@ window.__ModuleLoader__.load({
|
|
|
34
34
|
this.name = "RemoteError";
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
+
/** Generic invocation-owned values returned by synchronous Client Context resolvers. */
|
|
38
|
+
/** Shared identity across independently bundled Context providers and Gateway. */
|
|
39
|
+
const TYPERT_OWNED_VALUE = Symbol.for("dsh.typert.owned-value");
|
|
40
|
+
/**
|
|
41
|
+
* Transfer cleanup ownership without adding another resource reference count.
|
|
42
|
+
* @param value - resolved payload passed to the invocation.
|
|
43
|
+
* @param release - non-throwing synchronous release, called at most once.
|
|
44
|
+
* @returns an owned payload disposed after invocation and reply settlement.
|
|
45
|
+
*/
|
|
46
|
+
function typertOwnedValue(value, release) {
|
|
47
|
+
let active = true;
|
|
48
|
+
return {
|
|
49
|
+
[TYPERT_OWNED_VALUE]: true,
|
|
50
|
+
value,
|
|
51
|
+
[Symbol.dispose]() {
|
|
52
|
+
if (!active) return;
|
|
53
|
+
active = false;
|
|
54
|
+
release();
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
37
58
|
//#endregion
|
|
38
59
|
//#region lib/types/client/sessions/history-records.js
|
|
39
60
|
/** Client range access and type narrowing for aligned Session history records. */
|
|
@@ -128,12 +149,14 @@ window.__ModuleLoader__.load({
|
|
|
128
149
|
"compaction/start",
|
|
129
150
|
"compaction/summary",
|
|
130
151
|
"deliverables/presented",
|
|
152
|
+
"developer/message",
|
|
131
153
|
"feedback/message-delete",
|
|
132
154
|
"feedback/message-put",
|
|
133
155
|
"feedback/record",
|
|
134
156
|
"goal/change",
|
|
135
157
|
"hook/invoked",
|
|
136
158
|
"hook/result",
|
|
159
|
+
"image/offload",
|
|
137
160
|
"llm/retry",
|
|
138
161
|
"llm/retry-started",
|
|
139
162
|
"model/selection",
|
|
@@ -169,13 +192,15 @@ window.__ModuleLoader__.load({
|
|
|
169
192
|
"turn/end",
|
|
170
193
|
"turn/start",
|
|
171
194
|
"user/message",
|
|
172
|
-
"web/deepseek-search-llm-request"
|
|
195
|
+
"web/deepseek-search-llm-request",
|
|
196
|
+
"workspace/changes"
|
|
173
197
|
]);
|
|
174
198
|
//#endregion
|
|
175
199
|
//#region ../../core/session/lib/types/surface.js
|
|
176
200
|
/** Runtime counterpart of the message-producing event union. */
|
|
177
201
|
const SURFACE_EVENT_TYPES = new Set([
|
|
178
202
|
"system/message",
|
|
203
|
+
"developer/message",
|
|
179
204
|
"user/message",
|
|
180
205
|
"assistant/message",
|
|
181
206
|
"tool/result"
|
|
@@ -183,7 +208,7 @@ window.__ModuleLoader__.load({
|
|
|
183
208
|
/**
|
|
184
209
|
* Whether an event type can join the model-visible surface.
|
|
185
210
|
* @param type - event type to test.
|
|
186
|
-
* @returns true for one of the
|
|
211
|
+
* @returns true for one of the message-producing event types.
|
|
187
212
|
*/
|
|
188
213
|
function isSurfaceEligibleType(type) {
|
|
189
214
|
return SURFACE_EVENT_TYPES.has(type);
|
|
@@ -193,14 +218,33 @@ window.__ModuleLoader__.load({
|
|
|
193
218
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
194
219
|
}
|
|
195
220
|
/**
|
|
196
|
-
* Reject noncanonical request-header fields and contradictory tool failure metadata.
|
|
221
|
+
* Reject noncanonical request-header fields, developer roles/content, and contradictory tool failure metadata.
|
|
197
222
|
* This does not validate complete event payloads or embedded provider streams.
|
|
198
223
|
* @param event - event whose locally related payload fields are inspected.
|
|
199
224
|
* @param subject - event location to include in validation errors.
|
|
200
|
-
* @throws when request
|
|
225
|
+
* @throws when request-header fields, developer roles/content, or tool failure metadata are invalid.
|
|
201
226
|
*/
|
|
202
227
|
function validateSessionEventData(event, subject) {
|
|
203
228
|
const data = event.data;
|
|
229
|
+
if (SURFACE_EVENT_TYPES.has(event.type) && isRecord(data)) {
|
|
230
|
+
const message = event.type === "user/message" ? data : data["message"];
|
|
231
|
+
if (isRecord(message)) {
|
|
232
|
+
if (event.type === "developer/message" !== (message["role"] === "developer")) throw new Error(`${subject} developer/message and developer role must occur together`);
|
|
233
|
+
if (message["role"] !== "developer" && Array.isArray(message["content"]) && message["content"].some((block) => isRecord(block) && (block["type"] === "tool-addition" || block["type"] === "tool-removal"))) throw new Error(`${subject} tool-change blocks require developer role`);
|
|
234
|
+
if (event.type === "developer/message" && Array.isArray(message["content"])) {
|
|
235
|
+
let hasAdditions = false;
|
|
236
|
+
for (const block of message["content"]) {
|
|
237
|
+
if (!isRecord(block) || block["type"] !== "tool-addition" && block["type"] !== "tool-removal") continue;
|
|
238
|
+
if (typeof block["toolName"] !== "string" || block["toolName"].length === 0) throw new Error(`${subject} ${block["type"]} requires a nonempty toolName`);
|
|
239
|
+
if (block["type"] === "tool-addition") {
|
|
240
|
+
hasAdditions = true;
|
|
241
|
+
if (Object.hasOwn(block, "tool")) throw new Error(`${subject} tool-addition must omit inline tool definitions`);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (hasAdditions ? !isEventSeq(data["headerSeq"]) : Object.hasOwn(data, "headerSeq")) throw new Error(`${subject} requires headerSeq exactly when tool additions are present`);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
204
248
|
if (event.type === "request/header") {
|
|
205
249
|
if (!isRecord(data)) throw new Error(`${subject} data must be an object`);
|
|
206
250
|
const header = data["header"];
|
|
@@ -213,9 +257,7 @@ window.__ModuleLoader__.load({
|
|
|
213
257
|
if (!isRecord(data)) throw new Error(`${subject} data must be an object`);
|
|
214
258
|
if (data["error"] === void 0) return;
|
|
215
259
|
const message = data["message"];
|
|
216
|
-
|
|
217
|
-
const block = Array.isArray(content) ? content[0] : void 0;
|
|
218
|
-
if (!isRecord(block) || block["isError"] !== true) throw new Error(`${subject} error requires message content[0].isError === true`);
|
|
260
|
+
if (!isRecord(message) || message["isError"] !== true) throw new Error(`${subject} error requires message.isError === true`);
|
|
219
261
|
}
|
|
220
262
|
}
|
|
221
263
|
/** Whether a runtime value is a non-negative safe event sequence. */
|
|
@@ -244,7 +286,7 @@ window.__ModuleLoader__.load({
|
|
|
244
286
|
return op;
|
|
245
287
|
}
|
|
246
288
|
/** Validate cited source-event seqs against prior log entries and the replacement range. */
|
|
247
|
-
function
|
|
289
|
+
function assertSourceEventReferences(event, shadowedSeqs) {
|
|
248
290
|
const raw = event.sourceEventSeqs;
|
|
249
291
|
if (event.type === "assistant/message" && raw !== void 0) throw new Error("assistant/message embeds its source stream and cannot carry sourceEventSeqs");
|
|
250
292
|
const sources = /* @__PURE__ */ new Set();
|
|
@@ -273,7 +315,7 @@ window.__ModuleLoader__.load({
|
|
|
273
315
|
function validateSurfaceMetadata(event) {
|
|
274
316
|
const op = surfaceOpOf(event);
|
|
275
317
|
if (op !== void 0 && op !== "append" && (op.startSeq >= event.seq || op.endSeq >= event.seq)) throw new Error(`surface replace at seq ${event.seq}: startSeq and endSeq must reference earlier events`);
|
|
276
|
-
if (op !== void 0)
|
|
318
|
+
if (op !== void 0) assertSourceEventReferences(event, []);
|
|
277
319
|
return op;
|
|
278
320
|
}
|
|
279
321
|
//#endregion
|
|
@@ -308,7 +350,6 @@ window.__ModuleLoader__.load({
|
|
|
308
350
|
}
|
|
309
351
|
//#endregion
|
|
310
352
|
//#region lib/types/types.js
|
|
311
|
-
/** Browser-safe request, result, and lifecycle vocabulary for the Session Remote service. */
|
|
312
353
|
/** Maximum number of Sessions returned by one search. */
|
|
313
354
|
const SESSION_SEARCH_RESULT_LIMIT = 20;
|
|
314
355
|
/** Maximum search snippet length in Unicode code points. */
|
|
@@ -387,7 +428,7 @@ window.__ModuleLoader__.load({
|
|
|
387
428
|
for await (const frame of this.remote.session.follow({
|
|
388
429
|
address: this.address,
|
|
389
430
|
assistantStream: true,
|
|
390
|
-
...
|
|
431
|
+
...this.repairRequest(request)
|
|
391
432
|
}, signal)) {
|
|
392
433
|
if (frame.type === "snapshot") {
|
|
393
434
|
for (const record of frame.records) assertSessionWireEvent(record.event);
|
|
@@ -435,7 +476,10 @@ window.__ModuleLoader__.load({
|
|
|
435
476
|
}
|
|
436
477
|
/** @inheritdoc */
|
|
437
478
|
repairRequest(request) {
|
|
438
|
-
return
|
|
479
|
+
return {
|
|
480
|
+
...request.maxMessages === void 0 ? {} : { maxMessages: request.maxMessages },
|
|
481
|
+
...request.turnWindow === void 0 ? {} : { turnWindow: request.turnWindow }
|
|
482
|
+
};
|
|
439
483
|
}
|
|
440
484
|
};
|
|
441
485
|
//#endregion
|
|
@@ -453,23 +497,7 @@ window.__ModuleLoader__.load({
|
|
|
453
497
|
}
|
|
454
498
|
//#endregion
|
|
455
499
|
//#region lib/types/client/scope.js
|
|
456
|
-
/**
|
|
457
|
-
* Client Agent-scope primitive: mint a Cordis context tagged with the owning
|
|
458
|
-
* Agent's identity. The mechanism mirrors the host `dsh-scope` architecture
|
|
459
|
-
* (no-op plugin fiber + context tag + `Context.filter` routing predicate);
|
|
460
|
-
* the shape deliberately diverges: the filter lives on the actx itself
|
|
461
|
-
* instead of a separate carrier object, so scoped dispatch is plain cordis —
|
|
462
|
-
* `actx.bail(actx, event, payload)` / `actx.emit(actx, ...)` — with no
|
|
463
|
-
* wrapper. The host needs a detached carrier because its dispatch subject is
|
|
464
|
-
* the business Agent object; client scope events carry only ids, so the
|
|
465
|
-
* actx is the natural subject. The second divergence stands: the scope key
|
|
466
|
-
* is the branded `SessionId` (value compared), not an object identity — the
|
|
467
|
-
* agent and its session share one id (1:1, same axis; no separate AgentId
|
|
468
|
-
* brand), and a client scope's identity IS that wire id. Third divergence,
|
|
469
|
-
* deliberate: the client scopes the Agent IDENTITY, not a live Agent object
|
|
470
|
-
* — a cold session's host Agent is already disposed while its client actx
|
|
471
|
-
* stays alive for history viewing.
|
|
472
|
-
*/
|
|
500
|
+
/** Client scope generations route local events independently of Host Agent residency. */
|
|
473
501
|
/** Context tag written by {@link createScope}. */
|
|
474
502
|
const kScope = Symbol("dsh.client.scope");
|
|
475
503
|
/** Shared no-op plugin backing each Agent scope fiber. */
|
|
@@ -477,21 +505,22 @@ window.__ModuleLoader__.load({
|
|
|
477
505
|
/**
|
|
478
506
|
* Mint an Agent scope under `ctx`: a no-op plugin fiber whose context
|
|
479
507
|
* carries the agent tag and the dispatch filter — untagged listeners are
|
|
480
|
-
* admitted globally, tagged listeners only for
|
|
508
|
+
* admitted globally, tagged listeners only for the same Client generation.
|
|
481
509
|
* Registrations through the returned ctx dispose with the fiber.
|
|
482
510
|
* @param ctx - client root context the scope fiber mounts under.
|
|
483
|
-
* @param key -
|
|
511
|
+
* @param key - durable Session identity carried by this generation.
|
|
484
512
|
* @returns the tagged context and its backing fiber.
|
|
485
513
|
*/
|
|
486
514
|
function createScope(ctx, key) {
|
|
487
515
|
const fiber = ctx.plugin(agentScope);
|
|
516
|
+
const identity = { sessionId: key };
|
|
488
517
|
return {
|
|
489
518
|
fiber,
|
|
490
519
|
ctx: fiber.ctx.extend({
|
|
491
|
-
[kScope]:
|
|
520
|
+
[kScope]: identity,
|
|
492
521
|
[_deepseek_ai_cordis.Context.filter](listenerCtx) {
|
|
493
|
-
const tag =
|
|
494
|
-
return tag === void 0 || tag ===
|
|
522
|
+
const tag = scopeIdentityOf(listenerCtx);
|
|
523
|
+
return tag === void 0 || tag === identity;
|
|
495
524
|
}
|
|
496
525
|
})
|
|
497
526
|
};
|
|
@@ -502,6 +531,14 @@ window.__ModuleLoader__.load({
|
|
|
502
531
|
* @returns its agent identity (the session id), or undefined for root contexts.
|
|
503
532
|
*/
|
|
504
533
|
function scopeOf(ctx) {
|
|
534
|
+
return scopeIdentityOf(ctx)?.sessionId;
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Read the exact generation identity inherited by a Client Context.
|
|
538
|
+
* @param ctx - scoped or root Client Context.
|
|
539
|
+
* @returns the generation identity, or undefined for an unscoped Context.
|
|
540
|
+
*/
|
|
541
|
+
function scopeIdentityOf(ctx) {
|
|
505
542
|
return ctx[kScope];
|
|
506
543
|
}
|
|
507
544
|
//#endregion
|
|
@@ -542,16 +579,219 @@ window.__ModuleLoader__.load({
|
|
|
542
579
|
return merged;
|
|
543
580
|
}
|
|
544
581
|
//#endregion
|
|
582
|
+
//#region ../../util/values/lib/index.js
|
|
583
|
+
/** Duplicate-install-safe JSON and immutable-value helpers. @module @deepseek-ai/dsh-util-values */
|
|
584
|
+
/**
|
|
585
|
+
* Mark an unreachable closed-union branch.
|
|
586
|
+
* @param value - impossible value; an unhandled typed variant fails at the call site.
|
|
587
|
+
* @param context - optional switch-site label included in the failure message.
|
|
588
|
+
* @returns never; a runtime value that escaped its type always throws.
|
|
589
|
+
*/
|
|
590
|
+
function assertNever(value, context) {
|
|
591
|
+
const rendered = JSON.stringify(value) ?? String(value);
|
|
592
|
+
throw new Error(`unreachable variant${context ? ` in ${context}` : ""}: ${rendered}`);
|
|
593
|
+
}
|
|
594
|
+
/** Whether a realm-owned intrinsic prototype has a native constructor matching this engine's representation. */
|
|
595
|
+
function hasIntrinsicConstructor(prototype, name) {
|
|
596
|
+
const constructor = Object.getOwnPropertyDescriptor(prototype, "constructor")?.value;
|
|
597
|
+
if (typeof constructor !== "function") return false;
|
|
598
|
+
try {
|
|
599
|
+
return constructor.name === name && constructor.prototype === prototype && Function.prototype.toString.call(constructor) === Function.prototype.toString.call(name === "Array" ? Array : Object);
|
|
600
|
+
} catch {
|
|
601
|
+
return false;
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
/** Whether a candidate is one realm's intrinsic `Object.prototype`. */
|
|
605
|
+
function isIntrinsicObjectPrototype(value) {
|
|
606
|
+
return Object.getPrototypeOf(value) === null && hasIntrinsicConstructor(value, "Object");
|
|
607
|
+
}
|
|
608
|
+
/** Whether an array uses one realm's intrinsic `Array.prototype`, not a subclass or forged prototype. */
|
|
609
|
+
function hasPlainArrayPrototype(value) {
|
|
610
|
+
const prototype = Object.getPrototypeOf(value);
|
|
611
|
+
if (!Array.isArray(prototype) || !hasIntrinsicConstructor(prototype, "Array")) return false;
|
|
612
|
+
const objectPrototype = Object.getPrototypeOf(prototype);
|
|
613
|
+
return typeof objectPrototype === "object" && objectPrototype !== null && isIntrinsicObjectPrototype(objectPrototype);
|
|
614
|
+
}
|
|
615
|
+
/** Whether an object is a plain or null-prototype record from any JavaScript realm. */
|
|
616
|
+
function hasPlainObjectPrototype(value) {
|
|
617
|
+
const prototype = Object.getPrototypeOf(value);
|
|
618
|
+
return prototype === null || typeof prototype === "object" && isIntrinsicObjectPrototype(prototype);
|
|
619
|
+
}
|
|
620
|
+
/** Return every JSON-visible object key, or reject own data JSON would discard. */
|
|
621
|
+
function enumerableStringKeys(value) {
|
|
622
|
+
const keys = Reflect.ownKeys(value);
|
|
623
|
+
if (keys.some((key) => typeof key !== "string" || !Object.prototype.propertyIsEnumerable.call(value, key))) return void 0;
|
|
624
|
+
return keys;
|
|
625
|
+
}
|
|
626
|
+
/** Validate lossless JSON iteratively, optionally materializing a detached snapshot. */
|
|
627
|
+
function walkJsonValue(value, detach) {
|
|
628
|
+
const ancestors = /* @__PURE__ */ new Set();
|
|
629
|
+
let root;
|
|
630
|
+
const assign = (destination, item) => {
|
|
631
|
+
if (destination === void 0) return;
|
|
632
|
+
if (destination.kind === "root") root = item;
|
|
633
|
+
else if (destination.kind === "array") destination.target[destination.index] = item;
|
|
634
|
+
else Object.defineProperty(destination.target, destination.key, {
|
|
635
|
+
value: item,
|
|
636
|
+
enumerable: true,
|
|
637
|
+
configurable: true,
|
|
638
|
+
writable: true
|
|
639
|
+
});
|
|
640
|
+
};
|
|
641
|
+
const tasks = [{
|
|
642
|
+
kind: "visit",
|
|
643
|
+
value,
|
|
644
|
+
...detach ? { destination: { kind: "root" } } : {}
|
|
645
|
+
}];
|
|
646
|
+
for (let task = tasks.pop(); task !== void 0; task = tasks.pop()) {
|
|
647
|
+
if (task.kind === "leave") {
|
|
648
|
+
ancestors.delete(task.source);
|
|
649
|
+
continue;
|
|
650
|
+
}
|
|
651
|
+
if (task.kind === "array-item") {
|
|
652
|
+
if (!Object.prototype.hasOwnProperty.call(task.source, task.index)) return void 0;
|
|
653
|
+
tasks.push({
|
|
654
|
+
kind: "visit",
|
|
655
|
+
value: task.source[task.index],
|
|
656
|
+
...task.target === void 0 ? {} : { destination: {
|
|
657
|
+
kind: "array",
|
|
658
|
+
target: task.target,
|
|
659
|
+
index: task.index
|
|
660
|
+
} }
|
|
661
|
+
});
|
|
662
|
+
continue;
|
|
663
|
+
}
|
|
664
|
+
if (task.kind === "object-property") {
|
|
665
|
+
tasks.push({
|
|
666
|
+
kind: "visit",
|
|
667
|
+
value: task.source[task.key],
|
|
668
|
+
...task.target === void 0 ? {} : { destination: {
|
|
669
|
+
kind: "object",
|
|
670
|
+
target: task.target,
|
|
671
|
+
key: task.key
|
|
672
|
+
} }
|
|
673
|
+
});
|
|
674
|
+
continue;
|
|
675
|
+
}
|
|
676
|
+
const current = task.value;
|
|
677
|
+
if (current === null) {
|
|
678
|
+
assign(task.destination, null);
|
|
679
|
+
continue;
|
|
680
|
+
}
|
|
681
|
+
if (typeof current === "boolean" || typeof current === "string") {
|
|
682
|
+
assign(task.destination, current);
|
|
683
|
+
continue;
|
|
684
|
+
}
|
|
685
|
+
if (typeof current === "number") {
|
|
686
|
+
if (!Number.isFinite(current) || Object.is(current, -0)) return void 0;
|
|
687
|
+
assign(task.destination, current);
|
|
688
|
+
continue;
|
|
689
|
+
}
|
|
690
|
+
if (typeof current !== "object") return void 0;
|
|
691
|
+
if (ancestors.has(current)) return void 0;
|
|
692
|
+
if (Array.isArray(current)) {
|
|
693
|
+
if (!hasPlainArrayPrototype(current)) return void 0;
|
|
694
|
+
const length = current.length;
|
|
695
|
+
if (Reflect.ownKeys(current).length !== length + 1) return void 0;
|
|
696
|
+
const target = detach ? [] : void 0;
|
|
697
|
+
if (target !== void 0) assign(task.destination, target);
|
|
698
|
+
ancestors.add(current);
|
|
699
|
+
tasks.push({
|
|
700
|
+
kind: "leave",
|
|
701
|
+
source: current
|
|
702
|
+
});
|
|
703
|
+
for (let index = length - 1; index >= 0; index--) tasks.push({
|
|
704
|
+
kind: "array-item",
|
|
705
|
+
source: current,
|
|
706
|
+
index,
|
|
707
|
+
...target === void 0 ? {} : { target }
|
|
708
|
+
});
|
|
709
|
+
continue;
|
|
710
|
+
}
|
|
711
|
+
if (!hasPlainObjectPrototype(current)) return void 0;
|
|
712
|
+
const keys = enumerableStringKeys(current);
|
|
713
|
+
if (keys === void 0) return void 0;
|
|
714
|
+
const target = detach ? {} : void 0;
|
|
715
|
+
if (target !== void 0) assign(task.destination, target);
|
|
716
|
+
ancestors.add(current);
|
|
717
|
+
tasks.push({
|
|
718
|
+
kind: "leave",
|
|
719
|
+
source: current
|
|
720
|
+
});
|
|
721
|
+
for (let index = keys.length - 1; index >= 0; index--) {
|
|
722
|
+
const key = keys[index];
|
|
723
|
+
/* v8 ignore next -- the loop is bounded by the captured key count. */
|
|
724
|
+
if (key === void 0) return void 0;
|
|
725
|
+
tasks.push({
|
|
726
|
+
kind: "object-property",
|
|
727
|
+
source: current,
|
|
728
|
+
key,
|
|
729
|
+
...target === void 0 ? {} : { target }
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
return detach ? root : true;
|
|
734
|
+
}
|
|
735
|
+
/**
|
|
736
|
+
* Validate and detach lossless JSON in one read per property.
|
|
737
|
+
* @param value - candidate value to validate and detach.
|
|
738
|
+
* @returns the detached snapshot, or `undefined` when the value is not losslessly JSON-serializable.
|
|
739
|
+
*/
|
|
740
|
+
function snapshotJsonValue(value) {
|
|
741
|
+
return walkJsonValue(value, true);
|
|
742
|
+
}
|
|
743
|
+
/**
|
|
744
|
+
* Deep-freeze an object graph in place while leaving live AbortSignal objects mutable.
|
|
745
|
+
* @param value - value to freeze.
|
|
746
|
+
* @returns the same value after every reachable enumerable child is frozen.
|
|
747
|
+
*/
|
|
748
|
+
function deepFreeze(value) {
|
|
749
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
750
|
+
const pending = [{
|
|
751
|
+
kind: "visit",
|
|
752
|
+
node: value
|
|
753
|
+
}];
|
|
754
|
+
while (pending.length > 0) {
|
|
755
|
+
const task = pending.pop();
|
|
756
|
+
/* v8 ignore next -- the loop condition guarantees one pending task. */
|
|
757
|
+
if (task === void 0) continue;
|
|
758
|
+
if (task.kind === "property") {
|
|
759
|
+
pending.push({
|
|
760
|
+
kind: "visit",
|
|
761
|
+
node: task.source[task.key]
|
|
762
|
+
});
|
|
763
|
+
continue;
|
|
764
|
+
}
|
|
765
|
+
const node = task.node;
|
|
766
|
+
if (node === null || typeof node !== "object") continue;
|
|
767
|
+
if (node instanceof AbortSignal) continue;
|
|
768
|
+
if (seen.has(node)) continue;
|
|
769
|
+
seen.add(node);
|
|
770
|
+
Object.freeze(node);
|
|
771
|
+
const keys = Object.keys(node);
|
|
772
|
+
for (let index = keys.length - 1; index >= 0; index--) {
|
|
773
|
+
const key = keys[index];
|
|
774
|
+
/* v8 ignore next -- the loop is bounded by the captured key count. */
|
|
775
|
+
if (key === void 0) continue;
|
|
776
|
+
pending.push({
|
|
777
|
+
kind: "property",
|
|
778
|
+
source: node,
|
|
779
|
+
key
|
|
780
|
+
});
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
return value;
|
|
784
|
+
}
|
|
785
|
+
//#endregion
|
|
545
786
|
//#region lib/types/client/sessions/lineage.js
|
|
546
787
|
/**
|
|
547
788
|
* Summaries -> flat list with lineage indentation. Root and sibling order
|
|
548
789
|
* follows the established input order; this projection never re-sorts a
|
|
549
790
|
* hydrated list from mutable timestamps.
|
|
550
791
|
* @param summaries - the host's session.list items.
|
|
551
|
-
* @param completed - sessions with a pending completion reminder (manager-owned live fact; absent = false).
|
|
552
792
|
* @returns display rows in render order.
|
|
553
793
|
*/
|
|
554
|
-
function flattenLineage(summaries
|
|
794
|
+
function flattenLineage(summaries) {
|
|
555
795
|
const byId = /* @__PURE__ */ new Map();
|
|
556
796
|
for (const s of summaries) byId.set(s.sessionId, s);
|
|
557
797
|
const children = /* @__PURE__ */ new Map();
|
|
@@ -569,9 +809,9 @@ window.__ModuleLoader__.load({
|
|
|
569
809
|
return;
|
|
570
810
|
}
|
|
571
811
|
visited.add(s.sessionId);
|
|
812
|
+
const { agentAvailable: _agentAvailable, ...row } = s;
|
|
572
813
|
out.push({
|
|
573
|
-
...
|
|
574
|
-
completed: completed?.has(s.sessionId) ?? false,
|
|
814
|
+
...row,
|
|
575
815
|
depth
|
|
576
816
|
});
|
|
577
817
|
const kids = children.get(s.sessionId);
|
|
@@ -674,10 +914,14 @@ window.__ModuleLoader__.load({
|
|
|
674
914
|
//#region lib/types/client/sessions/projection-store.js
|
|
675
915
|
/**
|
|
676
916
|
* One session's projection values. Framework semantics, uniform across every
|
|
677
|
-
* key
|
|
678
|
-
*
|
|
679
|
-
*
|
|
680
|
-
*
|
|
917
|
+
* key. Sequenced writes (a baseline seeds rows at its cut, a push frame
|
|
918
|
+
* updates one row) compare seqs among themselves: a lower-or-equal seq within
|
|
919
|
+
* the Host generation loses, so a replayed frame cannot regress a value and a
|
|
920
|
+
* stale baseline cannot overwrite a newer frame. Cached writes (the session
|
|
921
|
+
* list's zero-I/O block) only fill keys no sequenced row holds, and a baseline
|
|
922
|
+
* discards every cached row before it seeds, regardless of seq: the connected
|
|
923
|
+
* Session is the truth and a cached value never outranks it. A key the store
|
|
924
|
+
* has never seen reads `undefined` (capability absent). Faces are identity-stable
|
|
681
925
|
* per key (create-on-demand, cached) so the React side binds each exactly
|
|
682
926
|
* once; the store-level channel (`subscribeAny`) serves coarse consumers (the
|
|
683
927
|
* manager's list projection reads the `title` key).
|
|
@@ -708,6 +952,15 @@ window.__ModuleLoader__.load({
|
|
|
708
952
|
return this.rows.get(key)?.value;
|
|
709
953
|
}
|
|
710
954
|
/**
|
|
955
|
+
* Read the accepted Host watermark without subscribing or copying a value.
|
|
956
|
+
* @param key - projection key.
|
|
957
|
+
* @returns the current sequence, or undefined for absent and cached values.
|
|
958
|
+
*/
|
|
959
|
+
seqOf(key) {
|
|
960
|
+
const row = this.rows.get(key);
|
|
961
|
+
return row?.kind === "sequenced" ? row.seq : void 0;
|
|
962
|
+
}
|
|
963
|
+
/**
|
|
711
964
|
* Read every current projection value as one reference-stable snapshot.
|
|
712
965
|
* @returns The same frozen value map until a row changes.
|
|
713
966
|
*/
|
|
@@ -732,41 +985,60 @@ window.__ModuleLoader__.load({
|
|
|
732
985
|
*/
|
|
733
986
|
apply(key, value, seq) {
|
|
734
987
|
const row = this.rows.get(key);
|
|
735
|
-
if (row
|
|
988
|
+
if (row?.kind === "sequenced" && seq <= row.seq) return;
|
|
736
989
|
this.rows.set(key, {
|
|
990
|
+
kind: "sequenced",
|
|
737
991
|
value,
|
|
738
992
|
seq
|
|
739
993
|
});
|
|
740
994
|
this.changed(key);
|
|
741
995
|
}
|
|
742
996
|
/**
|
|
743
|
-
*
|
|
744
|
-
*
|
|
745
|
-
*
|
|
746
|
-
*
|
|
747
|
-
*
|
|
997
|
+
* Fill keys from a session-list block the Host labeled `cached`: a zero-I/O
|
|
998
|
+
* view of the persisted checkpoint. A cached value lands only where no
|
|
999
|
+
* sequenced row exists: a connected Session has already answered for such
|
|
1000
|
+
* a key, and the list's view of the persisted checkpoint cannot be newer
|
|
1001
|
+
* than it.
|
|
1002
|
+
* @param values - whole values by key viewed from the persisted checkpoint.
|
|
1003
|
+
*/
|
|
1004
|
+
applyCached(values) {
|
|
1005
|
+
for (const key of Object.keys(values)) {
|
|
1006
|
+
if (this.rows.get(key)?.kind === "sequenced") continue;
|
|
1007
|
+
this.rows.set(key, {
|
|
1008
|
+
kind: "cached",
|
|
1009
|
+
value: values[key]
|
|
1010
|
+
});
|
|
1011
|
+
this.changed(key);
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
/**
|
|
1015
|
+
* Seed from a history tail page's projections block. Every cached row is
|
|
1016
|
+
* discarded first, regardless of seq: the block comes from the connected
|
|
1017
|
+
* Session, and a value viewed from the persisted checkpoint never outranks
|
|
1018
|
+
* it. Then every carried key lands under the same seq rule as frames, and a
|
|
1019
|
+
* key the block omits is capability-absent as of the cut — its row clears
|
|
1020
|
+
* unless a newer frame already superseded the cut (a stale baseline can
|
|
1021
|
+
* neither overwrite nor clear newer sequenced values).
|
|
748
1022
|
* @param baseline - the response's projections block.
|
|
749
1023
|
*/
|
|
750
1024
|
seed(baseline) {
|
|
1025
|
+
for (const [key, row] of this.rows) {
|
|
1026
|
+
if (row.kind !== "cached") continue;
|
|
1027
|
+
this.rows.delete(key);
|
|
1028
|
+
this.changed(key);
|
|
1029
|
+
}
|
|
751
1030
|
const values = baseline.values;
|
|
752
1031
|
for (const key of Object.keys(values)) this.apply(key, values[key], baseline.asOfSeq);
|
|
753
1032
|
for (const [key, row] of this.rows) {
|
|
754
1033
|
if (Object.hasOwn(values, key)) continue;
|
|
755
|
-
if (row.seq > baseline.asOfSeq) continue;
|
|
1034
|
+
if (row.kind === "sequenced" && row.seq > baseline.asOfSeq) continue;
|
|
756
1035
|
this.rows.delete(key);
|
|
757
1036
|
this.changed(key);
|
|
758
1037
|
}
|
|
759
1038
|
}
|
|
760
|
-
/**
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
* outrank recomputed lower-seq values forever. The caller seeds the new
|
|
764
|
-
* baseline immediately afterward.
|
|
765
|
-
* @param lastSeq - highest durable sequence reflected by the baseline.
|
|
766
|
-
*/
|
|
767
|
-
truncate(lastSeq) {
|
|
768
|
-
for (const [key, row] of this.rows) {
|
|
769
|
-
if (row.seq <= lastSeq) continue;
|
|
1039
|
+
/** Discard one Host generation's values and watermarks while preserving subscribed faces. */
|
|
1040
|
+
clear() {
|
|
1041
|
+
for (const key of this.rows.keys()) {
|
|
770
1042
|
this.rows.delete(key);
|
|
771
1043
|
this.changed(key);
|
|
772
1044
|
}
|
|
@@ -903,298 +1175,51 @@ window.__ModuleLoader__.load({
|
|
|
903
1175
|
/**
|
|
904
1176
|
* Append one contiguous live entry.
|
|
905
1177
|
* @param entry - live tail entry.
|
|
906
|
-
*/
|
|
907
|
-
append(entry) {
|
|
908
|
-
const entries = [entry];
|
|
909
|
-
this.window = concat(this.window, leaf(entries));
|
|
910
|
-
this.publish(this.snapshot.hasMore, {
|
|
911
|
-
kind: "append",
|
|
912
|
-
entries
|
|
913
|
-
});
|
|
914
|
-
}
|
|
915
|
-
/**
|
|
916
|
-
* Replace one attempt's transient rows with its committed durable settlement.
|
|
917
|
-
* @param attemptId - process-local attempt whose live rows are now redundant.
|
|
918
|
-
* @param entry - durable settlement committed for that attempt.
|
|
919
|
-
*/
|
|
920
|
-
settleAssistant(attemptId, entry) {
|
|
921
|
-
const entries = materialize(this.window).filter((candidate) => candidate.type !== "transient" || candidate.event.data.attemptId !== attemptId);
|
|
922
|
-
if (entry !== void 0) {
|
|
923
|
-
const index = entries.findIndex((candidate) => candidate.event.seq > entry.event.seq);
|
|
924
|
-
if (index < 0) entries.push(entry);
|
|
925
|
-
else entries.splice(index, 0, entry);
|
|
926
|
-
}
|
|
927
|
-
this.window = leaf(entries);
|
|
928
|
-
this.publish(this.snapshot.hasMore, {
|
|
929
|
-
kind: "settle-assistant",
|
|
930
|
-
attemptId,
|
|
931
|
-
...entry === void 0 ? {} : { entry }
|
|
932
|
-
});
|
|
933
|
-
}
|
|
934
|
-
publish(hasMore, change) {
|
|
935
|
-
this.snapshot = windowSnapshot(this.window, hasMore, this.snapshot.revision + 1, change);
|
|
936
|
-
(0, _deepseek_ai_dsh_client_store.notifySubscribers)(this.listeners, "[session-controller] event feed");
|
|
937
|
-
}
|
|
938
|
-
};
|
|
939
|
-
//#endregion
|
|
940
|
-
//#region lib/types/client/time-zone.js
|
|
941
|
-
/** Browser-owned time-zone sampling for prompt RPC provenance. */
|
|
942
|
-
/**
|
|
943
|
-
* Resolve the current browser IANA zone for one outbound operation.
|
|
944
|
-
* @returns The browser-provided canonical zone.
|
|
945
|
-
* @throws when the runtime cannot provide a non-empty zone.
|
|
946
|
-
*/
|
|
947
|
-
function resolvedClientTimeZone() {
|
|
948
|
-
const timeZone = new Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
949
|
-
if (typeof timeZone !== "string" || timeZone.length === 0) throw new Error("browser time zone is unavailable");
|
|
950
|
-
return timeZone;
|
|
951
|
-
}
|
|
952
|
-
//#endregion
|
|
953
|
-
//#region lib/types/client/sessions/queue-mirror.js
|
|
954
|
-
const QUEUE_PREVIEW_CHARS = 200;
|
|
955
|
-
function previewOf(content) {
|
|
956
|
-
const flat = content.filter((block) => block.type !== "image" && block.type !== "file").map((block) => block.type === "text" ? block.text : `[${block.type}]`).join(" ").replace(/\s+/g, " ").trim();
|
|
957
|
-
const chars = Array.from(flat);
|
|
958
|
-
return chars.length > QUEUE_PREVIEW_CHARS ? `${chars.slice(0, QUEUE_PREVIEW_CHARS).join("")}…` : flat;
|
|
959
|
-
}
|
|
960
|
-
function textOf(content) {
|
|
961
|
-
if (!content.every((block) => block.type === "text")) return null;
|
|
962
|
-
return content.map((block) => block.text).join("");
|
|
963
|
-
}
|
|
964
|
-
/** Authoritative transient queue projection and durable steering handoff. */
|
|
965
|
-
var SessionQueueMirror = class {
|
|
966
|
-
current = [];
|
|
967
|
-
/**
|
|
968
|
-
* Return the current immutable queue projection.
|
|
969
|
-
* @returns current queue rows.
|
|
970
|
-
*/
|
|
971
|
-
snapshot() {
|
|
972
|
-
return this.current;
|
|
973
|
-
}
|
|
974
|
-
/**
|
|
975
|
-
* Replace from one authoritative stream queue frame.
|
|
976
|
-
* @param items - complete host queue snapshot.
|
|
977
|
-
*/
|
|
978
|
-
replace(items) {
|
|
979
|
-
this.current = items.map((item) => {
|
|
980
|
-
const content = item.message.content;
|
|
981
|
-
return {
|
|
982
|
-
id: item.id,
|
|
983
|
-
messageId: item.message.id,
|
|
984
|
-
placement: item.placement,
|
|
985
|
-
...item.rpcId === void 0 ? {} : { rpcId: item.rpcId },
|
|
986
|
-
content,
|
|
987
|
-
preview: previewOf(content),
|
|
988
|
-
text: textOf(content)
|
|
989
|
-
};
|
|
990
|
-
});
|
|
991
|
-
}
|
|
992
|
-
/**
|
|
993
|
-
* Retire a transient steering row once its durable message enters the log.
|
|
994
|
-
* @param event - newly contiguous durable Session event.
|
|
995
|
-
* @returns whether the projection changed.
|
|
996
|
-
*/
|
|
997
|
-
acceptDurable(event) {
|
|
998
|
-
if (event.type !== "user/message") return false;
|
|
999
|
-
const messageId = event.data.id;
|
|
1000
|
-
const index = this.current.findIndex((item) => item.placement === "steering" && item.messageId === messageId);
|
|
1001
|
-
if (index < 0) return false;
|
|
1002
|
-
this.current = this.current.filter((_item, candidate) => candidate !== index);
|
|
1003
|
-
return true;
|
|
1004
|
-
}
|
|
1005
|
-
};
|
|
1006
|
-
//#endregion
|
|
1007
|
-
//#region ../../util/values/lib/index.js
|
|
1008
|
-
/** Whether a realm-owned intrinsic prototype is backed by its native constructor. */
|
|
1009
|
-
function hasIntrinsicConstructor(prototype, name) {
|
|
1010
|
-
const constructor = Object.getOwnPropertyDescriptor(prototype, "constructor")?.value;
|
|
1011
|
-
if (typeof constructor !== "function") return false;
|
|
1012
|
-
try {
|
|
1013
|
-
return constructor.name === name && constructor.prototype === prototype && Function.prototype.toString.call(constructor) === `function ${name}() { [native code] }`;
|
|
1014
|
-
} catch {
|
|
1015
|
-
return false;
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
/** Whether a candidate is one realm's intrinsic `Object.prototype`. */
|
|
1019
|
-
function isIntrinsicObjectPrototype(value) {
|
|
1020
|
-
return Object.getPrototypeOf(value) === null && hasIntrinsicConstructor(value, "Object");
|
|
1021
|
-
}
|
|
1022
|
-
/** Whether an array uses one realm's intrinsic `Array.prototype`, not a subclass or forged prototype. */
|
|
1023
|
-
function hasPlainArrayPrototype(value) {
|
|
1024
|
-
const prototype = Object.getPrototypeOf(value);
|
|
1025
|
-
if (!Array.isArray(prototype) || !hasIntrinsicConstructor(prototype, "Array")) return false;
|
|
1026
|
-
const objectPrototype = Object.getPrototypeOf(prototype);
|
|
1027
|
-
return typeof objectPrototype === "object" && objectPrototype !== null && isIntrinsicObjectPrototype(objectPrototype);
|
|
1028
|
-
}
|
|
1029
|
-
/** Whether an object is a plain or null-prototype record from any JavaScript realm. */
|
|
1030
|
-
function hasPlainObjectPrototype(value) {
|
|
1031
|
-
const prototype = Object.getPrototypeOf(value);
|
|
1032
|
-
return prototype === null || typeof prototype === "object" && isIntrinsicObjectPrototype(prototype);
|
|
1033
|
-
}
|
|
1034
|
-
/** Return every JSON-visible object key, or reject own data JSON would discard. */
|
|
1035
|
-
function enumerableStringKeys(value) {
|
|
1036
|
-
const keys = Reflect.ownKeys(value);
|
|
1037
|
-
if (keys.some((key) => typeof key !== "string" || !Object.prototype.propertyIsEnumerable.call(value, key))) return void 0;
|
|
1038
|
-
return keys;
|
|
1039
|
-
}
|
|
1040
|
-
/** Validate lossless JSON iteratively, optionally materializing a detached snapshot. */
|
|
1041
|
-
function walkJsonValue(value, detach) {
|
|
1042
|
-
const ancestors = /* @__PURE__ */ new Set();
|
|
1043
|
-
let root;
|
|
1044
|
-
const assign = (destination, item) => {
|
|
1045
|
-
if (destination === void 0) return;
|
|
1046
|
-
if (destination.kind === "root") root = item;
|
|
1047
|
-
else if (destination.kind === "array") destination.target[destination.index] = item;
|
|
1048
|
-
else Object.defineProperty(destination.target, destination.key, {
|
|
1049
|
-
value: item,
|
|
1050
|
-
enumerable: true,
|
|
1051
|
-
configurable: true,
|
|
1052
|
-
writable: true
|
|
1053
|
-
});
|
|
1054
|
-
};
|
|
1055
|
-
const tasks = [{
|
|
1056
|
-
kind: "visit",
|
|
1057
|
-
value,
|
|
1058
|
-
...detach ? { destination: { kind: "root" } } : {}
|
|
1059
|
-
}];
|
|
1060
|
-
for (let task = tasks.pop(); task !== void 0; task = tasks.pop()) {
|
|
1061
|
-
if (task.kind === "leave") {
|
|
1062
|
-
ancestors.delete(task.source);
|
|
1063
|
-
continue;
|
|
1064
|
-
}
|
|
1065
|
-
if (task.kind === "array-item") {
|
|
1066
|
-
if (!Object.prototype.hasOwnProperty.call(task.source, task.index)) return void 0;
|
|
1067
|
-
tasks.push({
|
|
1068
|
-
kind: "visit",
|
|
1069
|
-
value: task.source[task.index],
|
|
1070
|
-
...task.target === void 0 ? {} : { destination: {
|
|
1071
|
-
kind: "array",
|
|
1072
|
-
target: task.target,
|
|
1073
|
-
index: task.index
|
|
1074
|
-
} }
|
|
1075
|
-
});
|
|
1076
|
-
continue;
|
|
1077
|
-
}
|
|
1078
|
-
if (task.kind === "object-property") {
|
|
1079
|
-
tasks.push({
|
|
1080
|
-
kind: "visit",
|
|
1081
|
-
value: task.source[task.key],
|
|
1082
|
-
...task.target === void 0 ? {} : { destination: {
|
|
1083
|
-
kind: "object",
|
|
1084
|
-
target: task.target,
|
|
1085
|
-
key: task.key
|
|
1086
|
-
} }
|
|
1087
|
-
});
|
|
1088
|
-
continue;
|
|
1089
|
-
}
|
|
1090
|
-
const current = task.value;
|
|
1091
|
-
if (current === null) {
|
|
1092
|
-
assign(task.destination, null);
|
|
1093
|
-
continue;
|
|
1094
|
-
}
|
|
1095
|
-
if (typeof current === "boolean" || typeof current === "string") {
|
|
1096
|
-
assign(task.destination, current);
|
|
1097
|
-
continue;
|
|
1098
|
-
}
|
|
1099
|
-
if (typeof current === "number") {
|
|
1100
|
-
if (!Number.isFinite(current) || Object.is(current, -0)) return void 0;
|
|
1101
|
-
assign(task.destination, current);
|
|
1102
|
-
continue;
|
|
1103
|
-
}
|
|
1104
|
-
if (typeof current !== "object") return void 0;
|
|
1105
|
-
if (ancestors.has(current)) return void 0;
|
|
1106
|
-
if (Array.isArray(current)) {
|
|
1107
|
-
if (!hasPlainArrayPrototype(current)) return void 0;
|
|
1108
|
-
const length = current.length;
|
|
1109
|
-
if (Reflect.ownKeys(current).length !== length + 1) return void 0;
|
|
1110
|
-
const target = detach ? [] : void 0;
|
|
1111
|
-
if (target !== void 0) assign(task.destination, target);
|
|
1112
|
-
ancestors.add(current);
|
|
1113
|
-
tasks.push({
|
|
1114
|
-
kind: "leave",
|
|
1115
|
-
source: current
|
|
1116
|
-
});
|
|
1117
|
-
for (let index = length - 1; index >= 0; index--) tasks.push({
|
|
1118
|
-
kind: "array-item",
|
|
1119
|
-
source: current,
|
|
1120
|
-
index,
|
|
1121
|
-
...target === void 0 ? {} : { target }
|
|
1122
|
-
});
|
|
1123
|
-
continue;
|
|
1124
|
-
}
|
|
1125
|
-
if (!hasPlainObjectPrototype(current)) return void 0;
|
|
1126
|
-
const keys = enumerableStringKeys(current);
|
|
1127
|
-
if (keys === void 0) return void 0;
|
|
1128
|
-
const target = detach ? {} : void 0;
|
|
1129
|
-
if (target !== void 0) assign(task.destination, target);
|
|
1130
|
-
ancestors.add(current);
|
|
1131
|
-
tasks.push({
|
|
1132
|
-
kind: "leave",
|
|
1133
|
-
source: current
|
|
1134
|
-
});
|
|
1135
|
-
for (let index = keys.length - 1; index >= 0; index--) {
|
|
1136
|
-
const key = keys[index];
|
|
1137
|
-
/* v8 ignore next -- the loop is bounded by the captured key count. */
|
|
1138
|
-
if (key === void 0) return void 0;
|
|
1139
|
-
tasks.push({
|
|
1140
|
-
kind: "object-property",
|
|
1141
|
-
source: current,
|
|
1142
|
-
key,
|
|
1143
|
-
...target === void 0 ? {} : { target }
|
|
1144
|
-
});
|
|
1145
|
-
}
|
|
1146
|
-
}
|
|
1147
|
-
return detach ? root : true;
|
|
1148
|
-
}
|
|
1149
|
-
/**
|
|
1150
|
-
* Validate and detach lossless JSON in one read per property.
|
|
1151
|
-
* @param value - candidate value to validate and detach.
|
|
1152
|
-
* @returns the detached snapshot, or `undefined` when the value is not losslessly JSON-serializable.
|
|
1153
|
-
*/
|
|
1154
|
-
function snapshotJsonValue(value) {
|
|
1155
|
-
return walkJsonValue(value, true);
|
|
1156
|
-
}
|
|
1157
|
-
/**
|
|
1158
|
-
* Deep-freeze an object graph in place while leaving live AbortSignal objects mutable.
|
|
1159
|
-
* @param value - value to freeze.
|
|
1160
|
-
* @returns the same value after every reachable enumerable child is frozen.
|
|
1161
|
-
*/
|
|
1162
|
-
function deepFreeze(value) {
|
|
1163
|
-
const seen = /* @__PURE__ */ new WeakSet();
|
|
1164
|
-
const pending = [{
|
|
1165
|
-
kind: "visit",
|
|
1166
|
-
node: value
|
|
1167
|
-
}];
|
|
1168
|
-
while (pending.length > 0) {
|
|
1169
|
-
const task = pending.pop();
|
|
1170
|
-
/* v8 ignore next -- the loop condition guarantees one pending task. */
|
|
1171
|
-
if (task === void 0) continue;
|
|
1172
|
-
if (task.kind === "property") {
|
|
1173
|
-
pending.push({
|
|
1174
|
-
kind: "visit",
|
|
1175
|
-
node: task.source[task.key]
|
|
1176
|
-
});
|
|
1177
|
-
continue;
|
|
1178
|
-
}
|
|
1179
|
-
const node = task.node;
|
|
1180
|
-
if (node === null || typeof node !== "object") continue;
|
|
1181
|
-
if (node instanceof AbortSignal) continue;
|
|
1182
|
-
if (seen.has(node)) continue;
|
|
1183
|
-
seen.add(node);
|
|
1184
|
-
Object.freeze(node);
|
|
1185
|
-
const keys = Object.keys(node);
|
|
1186
|
-
for (let index = keys.length - 1; index >= 0; index--) {
|
|
1187
|
-
const key = keys[index];
|
|
1188
|
-
/* v8 ignore next -- the loop is bounded by the captured key count. */
|
|
1189
|
-
if (key === void 0) continue;
|
|
1190
|
-
pending.push({
|
|
1191
|
-
kind: "property",
|
|
1192
|
-
source: node,
|
|
1193
|
-
key
|
|
1194
|
-
});
|
|
1178
|
+
*/
|
|
1179
|
+
append(entry) {
|
|
1180
|
+
const entries = [entry];
|
|
1181
|
+
this.window = concat(this.window, leaf(entries));
|
|
1182
|
+
this.publish(this.snapshot.hasMore, {
|
|
1183
|
+
kind: "append",
|
|
1184
|
+
entries
|
|
1185
|
+
});
|
|
1186
|
+
}
|
|
1187
|
+
/**
|
|
1188
|
+
* Replace one attempt's transient rows with its committed durable settlement.
|
|
1189
|
+
* @param attemptId - process-local attempt whose live rows are now redundant.
|
|
1190
|
+
* @param entry - durable settlement committed for that attempt.
|
|
1191
|
+
*/
|
|
1192
|
+
settleAssistant(attemptId, entry) {
|
|
1193
|
+
const entries = materialize(this.window).filter((candidate) => candidate.type !== "transient" || candidate.event.data.attemptId !== attemptId);
|
|
1194
|
+
if (entry !== void 0) {
|
|
1195
|
+
const index = entries.findIndex((candidate) => candidate.event.seq > entry.event.seq);
|
|
1196
|
+
if (index < 0) entries.push(entry);
|
|
1197
|
+
else entries.splice(index, 0, entry);
|
|
1195
1198
|
}
|
|
1199
|
+
this.window = leaf(entries);
|
|
1200
|
+
this.publish(this.snapshot.hasMore, {
|
|
1201
|
+
kind: "settle-assistant",
|
|
1202
|
+
attemptId,
|
|
1203
|
+
...entry === void 0 ? {} : { entry }
|
|
1204
|
+
});
|
|
1196
1205
|
}
|
|
1197
|
-
|
|
1206
|
+
publish(hasMore, change) {
|
|
1207
|
+
this.snapshot = windowSnapshot(this.window, hasMore, this.snapshot.revision + 1, change);
|
|
1208
|
+
(0, _deepseek_ai_dsh_client_store.notifySubscribers)(this.listeners, "[session-controller] event feed");
|
|
1209
|
+
}
|
|
1210
|
+
};
|
|
1211
|
+
//#endregion
|
|
1212
|
+
//#region lib/types/client/time-zone.js
|
|
1213
|
+
/** Browser-owned time-zone sampling for one prompt RPC. */
|
|
1214
|
+
/**
|
|
1215
|
+
* Resolve the current browser IANA zone for one outbound operation.
|
|
1216
|
+
* @returns The browser-provided canonical zone.
|
|
1217
|
+
* @throws when the runtime cannot provide a non-empty zone.
|
|
1218
|
+
*/
|
|
1219
|
+
function resolvedClientTimeZone() {
|
|
1220
|
+
const timeZone = new Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
1221
|
+
if (typeof timeZone !== "string" || timeZone.length === 0) throw new Error("browser time zone is unavailable");
|
|
1222
|
+
return timeZone;
|
|
1198
1223
|
}
|
|
1199
1224
|
//#endregion
|
|
1200
1225
|
//#region ../../llm/llm/lib/types/assistant-stream.js
|
|
@@ -1353,6 +1378,7 @@ window.__ModuleLoader__.load({
|
|
|
1353
1378
|
/** Keeps transient Assistant presentation behind one settlement-aware interface. */
|
|
1354
1379
|
var ClientAssistantStream = class {
|
|
1355
1380
|
activeAttempt;
|
|
1381
|
+
retainedAttempt;
|
|
1356
1382
|
pending = /* @__PURE__ */ new Map();
|
|
1357
1383
|
publishedSeqs = /* @__PURE__ */ new Set();
|
|
1358
1384
|
durableCursor = -1;
|
|
@@ -1367,6 +1393,7 @@ window.__ModuleLoader__.load({
|
|
|
1367
1393
|
this.pending.clear();
|
|
1368
1394
|
this.transientInGap = 0;
|
|
1369
1395
|
this.activeAttempt = void 0;
|
|
1396
|
+
this.retainedAttempt = void 0;
|
|
1370
1397
|
const opening = baseline?.activeAttempt;
|
|
1371
1398
|
if (opening !== void 0) this.activeAttempt = {
|
|
1372
1399
|
attemptId: opening.attemptId,
|
|
@@ -1417,13 +1444,15 @@ window.__ModuleLoader__.load({
|
|
|
1417
1444
|
}
|
|
1418
1445
|
/**
|
|
1419
1446
|
* Fold one dense transient frame and release its named durable settlement.
|
|
1447
|
+
* Successful messages retain their transient rows until the owning Step ends;
|
|
1448
|
+
* interrupted messages, failed attempts, and abandonment retire them immediately.
|
|
1420
1449
|
* @param frame - next Assistant stream frame received by the follow connection.
|
|
1421
1450
|
* @returns a transient, publication, or rebaseline decision, or `undefined` when no entry becomes visible.
|
|
1422
1451
|
*/
|
|
1423
1452
|
acceptFrame(frame) {
|
|
1424
1453
|
switch (frame.type) {
|
|
1425
1454
|
case "start":
|
|
1426
|
-
if (this.activeAttempt !== void 0 || this.pending.size > 0) return { type: "rebaseline" };
|
|
1455
|
+
if (this.activeAttempt !== void 0 || this.retainedAttempt !== void 0 || this.pending.size > 0) return { type: "rebaseline" };
|
|
1427
1456
|
this.pending.clear();
|
|
1428
1457
|
this.activeAttempt = {
|
|
1429
1458
|
attemptId: frame.attemptId,
|
|
@@ -1470,6 +1499,14 @@ window.__ModuleLoader__.load({
|
|
|
1470
1499
|
const entry = this.pending.get(frame.outcome.seq);
|
|
1471
1500
|
if (entry === void 0 || entry.event.type !== frame.outcome.eventType) return { type: "rebaseline" };
|
|
1472
1501
|
this.pending.delete(frame.outcome.seq);
|
|
1502
|
+
if (entry.event.type === "assistant/message" && entry.event.data.interrupted !== true) {
|
|
1503
|
+
this.retainedAttempt = {
|
|
1504
|
+
attemptId: attempt.attemptId,
|
|
1505
|
+
turn: attempt.turn,
|
|
1506
|
+
step: attempt.step
|
|
1507
|
+
};
|
|
1508
|
+
return this.publish(entry);
|
|
1509
|
+
}
|
|
1473
1510
|
this.publishedSeqs.add(entry.event.seq);
|
|
1474
1511
|
return {
|
|
1475
1512
|
type: "settlement",
|
|
@@ -1486,6 +1523,15 @@ window.__ModuleLoader__.load({
|
|
|
1486
1523
|
}
|
|
1487
1524
|
publish(entry) {
|
|
1488
1525
|
this.publishedSeqs.add(entry.event.seq);
|
|
1526
|
+
const retained = this.retainedAttempt;
|
|
1527
|
+
if (retained !== void 0 && entry.event.type === "step/end" && entry.event.data.turn === retained.turn && entry.event.data.step === retained.step) {
|
|
1528
|
+
this.retainedAttempt = void 0;
|
|
1529
|
+
return {
|
|
1530
|
+
type: "publish",
|
|
1531
|
+
entry,
|
|
1532
|
+
retireAttemptId: retained.attemptId
|
|
1533
|
+
};
|
|
1534
|
+
}
|
|
1489
1535
|
return {
|
|
1490
1536
|
type: "publish",
|
|
1491
1537
|
entry
|
|
@@ -1503,6 +1549,20 @@ window.__ModuleLoader__.load({
|
|
|
1503
1549
|
asOfSeq: value.asOfSeq === -1 ? -1 : SessionSeq(value.asOfSeq)
|
|
1504
1550
|
};
|
|
1505
1551
|
}
|
|
1552
|
+
const HISTORY_PAGE_OPTIONS = {
|
|
1553
|
+
maxMessages: 500,
|
|
1554
|
+
turnWindow: {
|
|
1555
|
+
minMessages: 50,
|
|
1556
|
+
minTurns: 2
|
|
1557
|
+
}
|
|
1558
|
+
};
|
|
1559
|
+
const JUMP_PAGE_OPTIONS = {
|
|
1560
|
+
...HISTORY_PAGE_OPTIONS,
|
|
1561
|
+
turnWindow: {
|
|
1562
|
+
...HISTORY_PAGE_OPTIONS.turnWindow,
|
|
1563
|
+
minMessages: 200
|
|
1564
|
+
}
|
|
1565
|
+
};
|
|
1506
1566
|
/**
|
|
1507
1567
|
* Owns a session's event window, lifecycle state, and observable
|
|
1508
1568
|
* snapshot. React bindings remain outside this data layer. Features see only
|
|
@@ -1526,8 +1586,8 @@ window.__ModuleLoader__.load({
|
|
|
1526
1586
|
jumpTargetSeq = null;
|
|
1527
1587
|
/** The running jump loop's completion, shared by retargeting callers. */
|
|
1528
1588
|
jumpPromise = null;
|
|
1529
|
-
|
|
1530
|
-
|
|
1589
|
+
pendingHistory = null;
|
|
1590
|
+
stopObservingInbox;
|
|
1531
1591
|
assistantStream = new ClientAssistantStream();
|
|
1532
1592
|
running = false;
|
|
1533
1593
|
address;
|
|
@@ -1540,7 +1600,7 @@ window.__ModuleLoader__.load({
|
|
|
1540
1600
|
promptAttempted = false;
|
|
1541
1601
|
/** A first accepted prompt stays in the engaging phase until its turn is observable. */
|
|
1542
1602
|
firstPromptPendingTurn = false;
|
|
1543
|
-
/**
|
|
1603
|
+
/** New Session display state; unknown bare sessions begin conservatively blank. */
|
|
1544
1604
|
blankBit = true;
|
|
1545
1605
|
removed = false;
|
|
1546
1606
|
promptError = null;
|
|
@@ -1548,7 +1608,7 @@ window.__ModuleLoader__.load({
|
|
|
1548
1608
|
/** Local submission echoes, insertion-ordered (see SessionSnapshot.pendingSubmissions). */
|
|
1549
1609
|
pendingSubmissions = [];
|
|
1550
1610
|
/** Per-echo settlement state; `retiring` latches the first observation so a
|
|
1551
|
-
*
|
|
1611
|
+
* Inbox projection and its durable event cannot both retire one echo. */
|
|
1552
1612
|
submissionSettlements = /* @__PURE__ */ new Map();
|
|
1553
1613
|
/** Owns the addressed page/follow lifecycle while this Session is open. */
|
|
1554
1614
|
events;
|
|
@@ -1556,8 +1616,9 @@ window.__ModuleLoader__.load({
|
|
|
1556
1616
|
* Per-session projection value store (push model; see the session-projection
|
|
1557
1617
|
* subsystem page, docs/subsystems/session-projection.md): finished whole
|
|
1558
1618
|
* values computed on the Host, seeded by the tail page's
|
|
1559
|
-
* projections block and updated by Session Controller control frames
|
|
1560
|
-
*
|
|
1619
|
+
* projections block and updated by Session Controller control frames;
|
|
1620
|
+
* Host-sequenced writes merge under higher-seq-wins and cached list blocks
|
|
1621
|
+
* yield to them (projection-store.ts). Keys are read via `projections.faceOf(key)`
|
|
1561
1622
|
* (the useProjection resolution face); the conversation snapshot never
|
|
1562
1623
|
* carries projection values, and no client-side domain folding exists.
|
|
1563
1624
|
* Manager-owned when constructed through SessionManager (frames route and
|
|
@@ -1593,6 +1654,9 @@ window.__ModuleLoader__.load({
|
|
|
1593
1654
|
this.snapshotCache = this.buildSnapshot();
|
|
1594
1655
|
});
|
|
1595
1656
|
this.snapshotCache = this.buildSnapshot();
|
|
1657
|
+
this.stopObservingInbox = this.projections.faceOf("inbox").subscribe(() => {
|
|
1658
|
+
this.observeSubmissionInbox();
|
|
1659
|
+
});
|
|
1596
1660
|
}
|
|
1597
1661
|
/**
|
|
1598
1662
|
* Bind the Agent-scoped context minted by ClientSessions (single write;
|
|
@@ -1619,14 +1683,16 @@ window.__ModuleLoader__.load({
|
|
|
1619
1683
|
*/
|
|
1620
1684
|
beginSubmission(input) {
|
|
1621
1685
|
const requestId = randomUUID();
|
|
1686
|
+
const placement = this.running ? input.mode === "steer" ? "steering" : "queued" : "transcript";
|
|
1622
1687
|
this.pendingSubmissions = [...this.pendingSubmissions, {
|
|
1623
1688
|
requestId,
|
|
1624
|
-
placement
|
|
1689
|
+
placement,
|
|
1625
1690
|
time: Date.now(),
|
|
1626
1691
|
text: input.text,
|
|
1627
1692
|
attachments: input.attachments
|
|
1628
1693
|
}];
|
|
1629
1694
|
this.submissionSettlements.set(requestId, {
|
|
1695
|
+
placement,
|
|
1630
1696
|
onRetire: input.onRetire,
|
|
1631
1697
|
retiring: false
|
|
1632
1698
|
});
|
|
@@ -1694,9 +1760,9 @@ window.__ModuleLoader__.load({
|
|
|
1694
1760
|
}
|
|
1695
1761
|
if (this.blankBit) {
|
|
1696
1762
|
this.blankBit = false;
|
|
1697
|
-
this.options.onEngaged?.(this);
|
|
1698
1763
|
this.notifier.markDirty();
|
|
1699
1764
|
}
|
|
1765
|
+
this.options.onEngaged?.(this);
|
|
1700
1766
|
return result;
|
|
1701
1767
|
}
|
|
1702
1768
|
/**
|
|
@@ -1797,7 +1863,7 @@ window.__ModuleLoader__.load({
|
|
|
1797
1863
|
this.openPromise = promise;
|
|
1798
1864
|
return promise;
|
|
1799
1865
|
}
|
|
1800
|
-
/**
|
|
1866
|
+
/** Prepend one Turn-aligned page: at least 50 messages and two Turn starts, capped at 500 messages. */
|
|
1801
1867
|
async loadOlder() {
|
|
1802
1868
|
if (this.openState !== "open" || !this.hasMore || this.loadingOlder) return;
|
|
1803
1869
|
const events = this.events;
|
|
@@ -1807,7 +1873,7 @@ window.__ModuleLoader__.load({
|
|
|
1807
1873
|
try {
|
|
1808
1874
|
await events.prepend({
|
|
1809
1875
|
beforeSeq: this.baseSeq,
|
|
1810
|
-
|
|
1876
|
+
...HISTORY_PAGE_OPTIONS
|
|
1811
1877
|
});
|
|
1812
1878
|
} catch (error) {
|
|
1813
1879
|
if (!(0, _deepseek_ai_dsh_api_gateway_client.isRemoteFailure)(error)) console.error("[session-controller] loadOlder failed:", error);
|
|
@@ -1824,36 +1890,44 @@ window.__ModuleLoader__.load({
|
|
|
1824
1890
|
return this.jumpPromise;
|
|
1825
1891
|
}
|
|
1826
1892
|
if (this.loadingOlder) return Promise.resolve();
|
|
1893
|
+
const events = this.events;
|
|
1894
|
+
if (events === void 0) return Promise.resolve();
|
|
1895
|
+
const pending = {
|
|
1896
|
+
beforeSeq: this.baseSeq,
|
|
1897
|
+
hasMore: this.hasMore,
|
|
1898
|
+
pages: []
|
|
1899
|
+
};
|
|
1900
|
+
this.pendingHistory = pending;
|
|
1827
1901
|
this.jumpTargetSeq = seq;
|
|
1828
1902
|
this.loadingOlder = true;
|
|
1829
1903
|
this.notifier.markDirty();
|
|
1830
1904
|
const generation = this.openGeneration;
|
|
1831
1905
|
this.jumpPromise = (async () => {
|
|
1832
1906
|
try {
|
|
1833
|
-
while (
|
|
1907
|
+
while (pending.hasMore && this.jumpTargetSeq !== null && pending.beforeSeq > this.jumpTargetSeq) {
|
|
1834
1908
|
if (generation !== this.openGeneration) return;
|
|
1835
|
-
const
|
|
1836
|
-
if (events === void 0) return;
|
|
1837
|
-
const before = this.baseSeq;
|
|
1909
|
+
const before = pending.beforeSeq;
|
|
1838
1910
|
await events.prepend({
|
|
1839
|
-
beforeSeq:
|
|
1840
|
-
|
|
1911
|
+
beforeSeq: before,
|
|
1912
|
+
...JUMP_PAGE_OPTIONS
|
|
1841
1913
|
});
|
|
1842
|
-
if (
|
|
1914
|
+
if (pending.beforeSeq >= before) return;
|
|
1843
1915
|
}
|
|
1844
1916
|
} catch (error) {
|
|
1845
1917
|
if (!(0, _deepseek_ai_dsh_api_gateway_client.isRemoteFailure)(error)) console.error("[session-controller] loadThrough failed:", error);
|
|
1846
1918
|
} finally {
|
|
1847
1919
|
this.jumpTargetSeq = null;
|
|
1848
1920
|
this.jumpPromise = null;
|
|
1921
|
+
this.pendingHistory = null;
|
|
1849
1922
|
this.loadingOlder = false;
|
|
1923
|
+
if (generation === this.openGeneration && pending.pages.length > 0) this.prependWindow(pending.pages.reverse().flat(), pending.hasMore);
|
|
1850
1924
|
this.notifier.markDirty();
|
|
1851
1925
|
}
|
|
1852
1926
|
})();
|
|
1853
1927
|
return this.jumpPromise;
|
|
1854
1928
|
}
|
|
1855
1929
|
/** Rebuild an opened history source after address replacement.
|
|
1856
|
-
* Invalidates any in-flight open first;
|
|
1930
|
+
* Invalidates any in-flight open first; projection state belongs to the independently
|
|
1857
1931
|
* reconnecting control stream and remains untouched. */
|
|
1858
1932
|
async resync() {
|
|
1859
1933
|
if (this.openState === "cold") return;
|
|
@@ -1885,24 +1959,6 @@ window.__ModuleLoader__.load({
|
|
|
1885
1959
|
return this.snapshotCache;
|
|
1886
1960
|
}
|
|
1887
1961
|
/**
|
|
1888
|
-
* Replace every transient control value for this Session from one stream baseline.
|
|
1889
|
-
* @param queue - complete pending queue for this Session.
|
|
1890
|
-
*/
|
|
1891
|
-
replaceControl(queue) {
|
|
1892
|
-
this.queueMirror.replace(queue);
|
|
1893
|
-
this.observeSubmissionQueue(queue);
|
|
1894
|
-
this.notifier.markDirty();
|
|
1895
|
-
}
|
|
1896
|
-
/**
|
|
1897
|
-
* Apply one Session-addressed live control update.
|
|
1898
|
-
* @param frame - queue replacement addressed to this Session.
|
|
1899
|
-
*/
|
|
1900
|
-
handleControlFrame(frame) {
|
|
1901
|
-
this.queueMirror.replace(frame.items);
|
|
1902
|
-
this.observeSubmissionQueue(frame.items);
|
|
1903
|
-
this.notifier.markDirty();
|
|
1904
|
-
}
|
|
1905
|
-
/**
|
|
1906
1962
|
* Running-bit relay from the host stream (list entry and snapshot stay consistent).
|
|
1907
1963
|
* @param running - the new running state.
|
|
1908
1964
|
*/
|
|
@@ -1939,13 +1995,15 @@ window.__ModuleLoader__.load({
|
|
|
1939
1995
|
this.notifier.markDirty();
|
|
1940
1996
|
}
|
|
1941
1997
|
/**
|
|
1942
|
-
*
|
|
1943
|
-
* `
|
|
1944
|
-
* running
|
|
1945
|
-
*
|
|
1946
|
-
*
|
|
1998
|
+
* Apply the Manager's effective display blank, further reconciled with the
|
|
1999
|
+
* current `sessionListMetadata` projection. Local send attempts and current
|
|
2000
|
+
* running state prevent re-blanking; an earlier false summary alone does not.
|
|
2001
|
+
* The Manager retains acceptance and earlier running observations across
|
|
2002
|
+
* Session-object replacement.
|
|
2003
|
+
* @param blank - New Session display state after Manager reconciliation.
|
|
1947
2004
|
*/
|
|
1948
2005
|
handleBlank(blank) {
|
|
2006
|
+
blank = blank && this.projections.values().sessionListMetadata?.blank !== false;
|
|
1949
2007
|
if (blank === this.blankBit) return;
|
|
1950
2008
|
if (blank && (this.promptAttempted || this.running)) return;
|
|
1951
2009
|
this.blankBit = blank;
|
|
@@ -1969,7 +2027,9 @@ window.__ModuleLoader__.load({
|
|
|
1969
2027
|
* @returns when the Remote iterator has completed teardown.
|
|
1970
2028
|
*/
|
|
1971
2029
|
async dispose() {
|
|
1972
|
-
|
|
2030
|
+
this.stopObservingInbox();
|
|
2031
|
+
for (const [requestId, settlement] of [...this.submissionSettlements]) if (settlement.admitted !== void 0) this.scheduleObservedRetirement(requestId, settlement.admitted);
|
|
2032
|
+
else this.retireFailedSubmission(requestId);
|
|
1973
2033
|
this.openGeneration++;
|
|
1974
2034
|
const events = this.events;
|
|
1975
2035
|
this.events = void 0;
|
|
@@ -1991,7 +2051,7 @@ window.__ModuleLoader__.load({
|
|
|
1991
2051
|
});
|
|
1992
2052
|
this.events = events;
|
|
1993
2053
|
try {
|
|
1994
|
-
await events.open(
|
|
2054
|
+
await events.open(HISTORY_PAGE_OPTIONS);
|
|
1995
2055
|
if (generation !== this.openGeneration || this.events !== events) return;
|
|
1996
2056
|
this.openState = "open";
|
|
1997
2057
|
} catch (error) {
|
|
@@ -2024,10 +2084,22 @@ window.__ModuleLoader__.load({
|
|
|
2024
2084
|
const visible = this.assistantStream.replace(entries, assistantStream);
|
|
2025
2085
|
this.baseSeq = SessionLogOffset(entries[0]?.event.seq ?? 0);
|
|
2026
2086
|
this.hasMore = hasMore;
|
|
2087
|
+
if (this.pendingHistory !== null) {
|
|
2088
|
+
this.pendingHistory.beforeSeq = this.baseSeq;
|
|
2089
|
+
this.pendingHistory.hasMore = hasMore;
|
|
2090
|
+
this.pendingHistory.pages.length = 0;
|
|
2091
|
+
}
|
|
2027
2092
|
if (visible.some((entry) => entry.event.type === "turn/start")) this.firstPromptPendingTurn = false;
|
|
2028
2093
|
if (projections !== void 0) this.projections.seed(projections);
|
|
2029
2094
|
this.eventSource.replace(visible, hasMore);
|
|
2095
|
+
if (projections !== void 0) {
|
|
2096
|
+
for (const [requestId, { receipt }] of this.submissionSettlements) if (receipt !== void 0 && receipt.seq <= projections.asOfSeq) this.scheduleObservedRetirement(requestId, receipt.attachments);
|
|
2097
|
+
}
|
|
2030
2098
|
for (const entry of visible) this.observeSubmissionEvent(entry.event);
|
|
2099
|
+
if (projections !== void 0) {
|
|
2100
|
+
const inbox = projections.values.inbox;
|
|
2101
|
+
for (const target of ["next-turn", "next-step"]) this.observeSubmissionInsertions(target, inbox?.[target] ?? [], 0, projections.asOfSeq);
|
|
2102
|
+
}
|
|
2031
2103
|
this.notifier.markDirty();
|
|
2032
2104
|
}
|
|
2033
2105
|
publishAssistantEntry(result) {
|
|
@@ -2049,14 +2121,24 @@ window.__ModuleLoader__.load({
|
|
|
2049
2121
|
this.notifier.markDirty();
|
|
2050
2122
|
return;
|
|
2051
2123
|
}
|
|
2052
|
-
if (result?.type === "publish"
|
|
2053
|
-
|
|
2124
|
+
if (result?.type === "publish") {
|
|
2125
|
+
const changed = this.appendLive(result.entry);
|
|
2126
|
+
if (result.retireAttemptId !== void 0) this.eventSource.settleAssistant(result.retireAttemptId);
|
|
2127
|
+
if (changed || result.retireAttemptId !== void 0) this.notifier.markDirty();
|
|
2128
|
+
} else if (result?.type === "transient") {
|
|
2054
2129
|
this.eventSource.append(result.entry);
|
|
2055
2130
|
this.notifier.markDirty();
|
|
2056
2131
|
}
|
|
2057
2132
|
}
|
|
2058
2133
|
/** Prepend one stream-validated history page. */
|
|
2059
2134
|
prependWindow(entries, hasMore) {
|
|
2135
|
+
if (this.pendingHistory !== null) {
|
|
2136
|
+
const pending = this.pendingHistory;
|
|
2137
|
+
pending.beforeSeq = entries[0] === void 0 ? pending.beforeSeq : SessionLogOffset(entries[0].event.seq);
|
|
2138
|
+
pending.hasMore = hasMore;
|
|
2139
|
+
pending.pages.push(entries);
|
|
2140
|
+
return;
|
|
2141
|
+
}
|
|
2060
2142
|
this.baseSeq = entries[0] === void 0 ? this.baseSeq : SessionLogOffset(entries[0].event.seq);
|
|
2061
2143
|
this.hasMore = hasMore;
|
|
2062
2144
|
this.eventSource.prepend(entries, hasMore);
|
|
@@ -2066,23 +2148,81 @@ window.__ModuleLoader__.load({
|
|
|
2066
2148
|
const event = entry.event;
|
|
2067
2149
|
const awaitingFirstTurn = this.firstPromptPendingTurn;
|
|
2068
2150
|
if (event.type === "turn/start") this.firstPromptPendingTurn = false;
|
|
2069
|
-
const queueChanged = this.queueMirror.acceptDurable(event);
|
|
2070
2151
|
this.eventSource.append(entry);
|
|
2071
2152
|
this.observeSubmissionEvent(event);
|
|
2072
|
-
return
|
|
2153
|
+
return awaitingFirstTurn !== this.firstPromptPendingTurn;
|
|
2073
2154
|
}
|
|
2074
|
-
/**
|
|
2155
|
+
/** Observe durable acceptance even when insertion and claim share one projection notification. */
|
|
2075
2156
|
observeSubmissionEvent(event) {
|
|
2076
|
-
if (this.submissionSettlements.size === 0 || event.type !== "user/message") return;
|
|
2077
|
-
const data = event.data;
|
|
2078
|
-
const source = data?.source;
|
|
2079
|
-
if (source?.kind !== "user" || typeof source.rpcId !== "string") return;
|
|
2080
|
-
this.scheduleObservedRetirement(source.rpcId, attachmentRefsIn(data?.content));
|
|
2081
|
-
}
|
|
2082
|
-
/** Retire echoes whose prompts landed in the host inbox instead of the log (running-turn submissions). */
|
|
2083
|
-
observeSubmissionQueue(items) {
|
|
2084
2157
|
if (this.submissionSettlements.size === 0) return;
|
|
2085
|
-
|
|
2158
|
+
if (event.type === "agent/inbox/spliced") {
|
|
2159
|
+
const { target, start, removedCount = 0, inserted, outcome } = event.data;
|
|
2160
|
+
for (const [requestId, settlement] of this.submissionSettlements) {
|
|
2161
|
+
const receipt = settlement.receipt;
|
|
2162
|
+
if (receipt?.target !== target || receipt.index === null || receipt.seq >= event.seq) continue;
|
|
2163
|
+
const removed = receipt.index >= start && receipt.index < start + removedCount;
|
|
2164
|
+
if (removed && outcome === "canceled") this.retireFailedSubmission(requestId);
|
|
2165
|
+
else settlement.receipt = {
|
|
2166
|
+
...receipt,
|
|
2167
|
+
seq: event.seq,
|
|
2168
|
+
index: removed ? null : receipt.index < start ? receipt.index : receipt.index + inserted.length - removedCount
|
|
2169
|
+
};
|
|
2170
|
+
}
|
|
2171
|
+
this.observeSubmissionInsertions(target, inserted, start, event.seq);
|
|
2172
|
+
for (const message of inserted) this.observeSubmissionMessage(message, false);
|
|
2173
|
+
return;
|
|
2174
|
+
}
|
|
2175
|
+
if (event.type === "request/context" || event.type === "turn/end") {
|
|
2176
|
+
for (const [requestId, settlement] of this.submissionSettlements) if (settlement.admitted === void 0 && settlement.receipt?.index === null && settlement.receipt.seq < event.seq) this.retireFailedSubmission(requestId);
|
|
2177
|
+
return;
|
|
2178
|
+
}
|
|
2179
|
+
if (event.type === "user/message") this.observeSubmissionMessage(event.data, true);
|
|
2180
|
+
}
|
|
2181
|
+
observeSubmissionInsertions(target, messages, start, seq) {
|
|
2182
|
+
for (const [index, message] of messages.entries()) {
|
|
2183
|
+
const source = message.source;
|
|
2184
|
+
if (source.kind !== "user" || !("rpcId" in source)) continue;
|
|
2185
|
+
const settlement = this.submissionSettlements.get(source.rpcId);
|
|
2186
|
+
if (settlement === void 0 || settlement.placement === "queued" || settlement.retiring || (settlement.receipt?.seq ?? -1) > seq) continue;
|
|
2187
|
+
settlement.receipt = {
|
|
2188
|
+
target,
|
|
2189
|
+
seq,
|
|
2190
|
+
index: start + index,
|
|
2191
|
+
attachments: attachmentRefsIn(message.content)
|
|
2192
|
+
};
|
|
2193
|
+
}
|
|
2194
|
+
}
|
|
2195
|
+
observeSubmissionMessage(message, admitted) {
|
|
2196
|
+
const source = message.source;
|
|
2197
|
+
if (source.kind !== "user" || !("rpcId" in source)) return;
|
|
2198
|
+
const settlement = this.submissionSettlements.get(source.rpcId);
|
|
2199
|
+
if (settlement === void 0 || settlement.retiring) return;
|
|
2200
|
+
if (!admitted) {
|
|
2201
|
+
if (settlement.placement === "queued") this.scheduleObservedRetirement(source.rpcId, attachmentRefsIn(message.content));
|
|
2202
|
+
return;
|
|
2203
|
+
}
|
|
2204
|
+
settlement.admitted = attachmentRefsIn(message.content);
|
|
2205
|
+
this.retireAdmittedSubmission(source.rpcId);
|
|
2206
|
+
}
|
|
2207
|
+
/** Retire admitted Chat identities only after stale Inbox rows can no longer reappear. */
|
|
2208
|
+
retireAdmittedSubmission(requestId) {
|
|
2209
|
+
const settlement = this.submissionSettlements.get(requestId);
|
|
2210
|
+
if (settlement?.admitted === void 0) return;
|
|
2211
|
+
const receipt = settlement.receipt;
|
|
2212
|
+
if (receipt?.index === null && (this.projections.seqOf("inbox") ?? -1) < receipt.seq) return;
|
|
2213
|
+
this.scheduleObservedRetirement(requestId, settlement.admitted);
|
|
2214
|
+
}
|
|
2215
|
+
/** Inbox acceptance retires queued echoes; its watermark completes admitted Chat handoffs. */
|
|
2216
|
+
observeSubmissionInbox() {
|
|
2217
|
+
if (this.submissionSettlements.size === 0) return;
|
|
2218
|
+
const inbox = this.projections.get("inbox");
|
|
2219
|
+
if (inbox === void 0) return;
|
|
2220
|
+
const seq = this.projections.seqOf("inbox");
|
|
2221
|
+
for (const target of ["next-turn", "next-step"]) {
|
|
2222
|
+
if (seq !== void 0) this.observeSubmissionInsertions(target, inbox[target], 0, seq);
|
|
2223
|
+
for (const message of inbox[target]) this.observeSubmissionMessage(message, false);
|
|
2224
|
+
}
|
|
2225
|
+
for (const requestId of this.submissionSettlements.keys()) this.retireAdmittedSubmission(requestId);
|
|
2086
2226
|
}
|
|
2087
2227
|
/**
|
|
2088
2228
|
* Latch one observed settlement and remove the echo an animation frame
|
|
@@ -2104,7 +2244,7 @@ window.__ModuleLoader__.load({
|
|
|
2104
2244
|
/** Remove one unsettled echo immediately (prompt rejection, abort, or disposal). */
|
|
2105
2245
|
retireFailedSubmission(requestId) {
|
|
2106
2246
|
const settlement = this.submissionSettlements.get(requestId);
|
|
2107
|
-
if (settlement === void 0 || settlement.retiring) return;
|
|
2247
|
+
if (settlement === void 0 || settlement.retiring || settlement.admitted !== void 0) return;
|
|
2108
2248
|
settlement.retiring = true;
|
|
2109
2249
|
this.finishSubmission(requestId, { reason: "failed" });
|
|
2110
2250
|
}
|
|
@@ -2131,13 +2271,16 @@ window.__ModuleLoader__.load({
|
|
|
2131
2271
|
this.notifier.markDirty();
|
|
2132
2272
|
}
|
|
2133
2273
|
buildSnapshot() {
|
|
2274
|
+
const identity = this.projections.values().subagent;
|
|
2134
2275
|
return {
|
|
2135
2276
|
sessionId: this.sessionId,
|
|
2136
|
-
queue: this.queueMirror.snapshot(),
|
|
2137
2277
|
pendingSubmissions: this.pendingSubmissions,
|
|
2138
2278
|
running: this.running,
|
|
2139
2279
|
subagent: this.address === void 0 ? null : {
|
|
2140
|
-
address: this.address
|
|
2280
|
+
address: this.address.mode === "unknown" && identity != null ? {
|
|
2281
|
+
...this.address,
|
|
2282
|
+
mode: identity.mode
|
|
2283
|
+
} : this.address,
|
|
2141
2284
|
...this.parentAvailable === void 0 ? {} : { parentAvailable: this.parentAvailable }
|
|
2142
2285
|
},
|
|
2143
2286
|
removed: this.removed,
|
|
@@ -2182,28 +2325,25 @@ window.__ModuleLoader__.load({
|
|
|
2182
2325
|
}
|
|
2183
2326
|
//#endregion
|
|
2184
2327
|
//#region lib/types/client/sessions/manager.js
|
|
2328
|
+
/** Host catalog, durable projection caches, and explicitly retained Client instances. */
|
|
2185
2329
|
function sessionSeqCursor(value) {
|
|
2186
2330
|
return value === -1 ? -1 : SessionSeq(value);
|
|
2187
2331
|
}
|
|
2188
|
-
function catalogAvailability(parentAvailable) {
|
|
2189
|
-
return parentAvailable === void 0 ? {} : { parentAvailable };
|
|
2190
|
-
}
|
|
2191
2332
|
/** Instance cluster + frame entry + the session list. */
|
|
2192
2333
|
var SessionManager = class {
|
|
2193
2334
|
remote;
|
|
2194
2335
|
sessions = /* @__PURE__ */ new Map();
|
|
2195
2336
|
/** In-flight Session disposals remain here after instances leave `sessions`, so manager disposal can await quiescence. */
|
|
2196
2337
|
sessionDisposals = /* @__PURE__ */ new Set();
|
|
2197
|
-
/** Latest transient queues, retained independently of Session object materialization. */
|
|
2198
|
-
queues = /* @__PURE__ */ new Map();
|
|
2199
2338
|
/**
|
|
2200
|
-
*
|
|
2201
|
-
*
|
|
2202
|
-
*
|
|
2339
|
+
* Accepted/running presentation must survive a later empty-history list
|
|
2340
|
+
* response. Host-asserted running is recorded even before a row, instance, or
|
|
2341
|
+
* address holds the identity — the listing that would hold it may not have
|
|
2342
|
+
* landed yet — while the client-local acceptance callback requires a current
|
|
2343
|
+
* holder, because it can arrive from a replaced or already-dropped Session.
|
|
2203
2344
|
*/
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
prevRunning = /* @__PURE__ */ new Map();
|
|
2345
|
+
engagedSessions = /* @__PURE__ */ new Set();
|
|
2346
|
+
disposed = false;
|
|
2207
2347
|
/** Per-session projection value stores, retained independently of instance arrival (the
|
|
2208
2348
|
* title-snapshot precedent, generalized): push frames land here whether or not the Session
|
|
2209
2349
|
* is instantiated (list rows read the 'title' key), and an instantiated Session adopts the
|
|
@@ -2215,22 +2355,11 @@ window.__ModuleLoader__.load({
|
|
|
2215
2355
|
listPhase = "pending";
|
|
2216
2356
|
listError = null;
|
|
2217
2357
|
listInflight = null;
|
|
2218
|
-
/**
|
|
2358
|
+
/** Active list request's mutation log; its identity also fences completion after reconnect. */
|
|
2219
2359
|
listMutations = null;
|
|
2220
2360
|
addresses = /* @__PURE__ */ new Map();
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
/** Catalog owners whose membership changed while a pull was in flight: one trailing refresh after it settles. */
|
|
2224
|
-
catalogStale = /* @__PURE__ */ new Set();
|
|
2225
|
-
openCatalogs = /* @__PURE__ */ new Set();
|
|
2226
|
-
catalogDebounce = /* @__PURE__ */ new Map();
|
|
2227
|
-
/**
|
|
2228
|
-
* Background jobs per session, last-wins from Session Controller's control
|
|
2229
|
-
* stream. An empty set is stored as an absent key, so absence and `[]` are
|
|
2230
|
-
* one representation.
|
|
2231
|
-
*/
|
|
2232
|
-
jobsBySession = /* @__PURE__ */ new Map();
|
|
2233
|
-
selected;
|
|
2361
|
+
projectionLoads = /* @__PURE__ */ new Map();
|
|
2362
|
+
projectionInflight = /* @__PURE__ */ new Map();
|
|
2234
2363
|
listSnapshotCache;
|
|
2235
2364
|
/** Entry-identity cache (reference stability): list rebuilds reuse the previous entry
|
|
2236
2365
|
* object when every field matches — wire refreshes mint all-new summary objects, so identity
|
|
@@ -2240,69 +2369,35 @@ window.__ModuleLoader__.load({
|
|
|
2240
2369
|
notifier = new Notifier(() => {
|
|
2241
2370
|
this.listSnapshotCache = this.buildListSnapshot();
|
|
2242
2371
|
});
|
|
2243
|
-
/**
|
|
2244
|
-
|
|
2245
|
-
* @param restoredSelection - persisted real-Session selection candidate.
|
|
2246
|
-
*/
|
|
2247
|
-
constructor(remote, restoredSelection, restoredAddress) {
|
|
2372
|
+
/** @param remote - generated Remote namespaces used by catalog and history readers. */
|
|
2373
|
+
constructor(remote) {
|
|
2248
2374
|
this.remote = remote;
|
|
2249
|
-
this.selected = restoredSelection;
|
|
2250
|
-
if (restoredAddress !== void 0) this.addresses.set(restoredAddress.childSessionId, restoredAddress);
|
|
2251
2375
|
this.listSnapshotCache = this.buildListSnapshot();
|
|
2252
2376
|
}
|
|
2253
2377
|
/**
|
|
2254
|
-
*
|
|
2255
|
-
* @param
|
|
2256
|
-
|
|
2257
|
-
select(sessionId) {
|
|
2258
|
-
const address = this.navigationAddress(sessionId);
|
|
2259
|
-
if (!this.summaries.some((summary) => summary.sessionId === sessionId) && address === void 0) throw new Error(`sessions.select: unknown session ${sessionId}`);
|
|
2260
|
-
if (address !== void 0) this.addresses.set(sessionId, address);
|
|
2261
|
-
this.sessions.get(sessionId)?.configureSubagent(address, address === void 0 ? void 0 : this.catalogs.get(address.parentSessionId)?.parentAvailable);
|
|
2262
|
-
this.selected = sessionId;
|
|
2263
|
-
this.completedNotifications.delete(sessionId);
|
|
2264
|
-
this.refreshSubagents(sessionId);
|
|
2265
|
-
this.notifier.notifyNow();
|
|
2266
|
-
}
|
|
2267
|
-
/**
|
|
2268
|
-
* Select a healthy child through its durable direct-parent address.
|
|
2269
|
-
* @param address - catalog-derived parent and child ids.
|
|
2270
|
-
*/
|
|
2271
|
-
selectSubagent(address) {
|
|
2272
|
-
const catalog = this.catalogs.get(address.parentSessionId);
|
|
2273
|
-
const entry = catalog?.entries.find((candidate) => candidate.id === address.childSessionId);
|
|
2274
|
-
if (entry === void 0 || entry.kind !== "child" || entry.mode !== address.mode) throw new Error(`sessions.selectSubagent: ${address.childSessionId} is not a healthy catalog child`);
|
|
2275
|
-
this.addresses.set(address.childSessionId, address);
|
|
2276
|
-
this.sessions.get(address.childSessionId)?.configureSubagent(address, catalog?.parentAvailable);
|
|
2277
|
-
this.selected = address.childSessionId;
|
|
2278
|
-
this.completedNotifications.delete(address.childSessionId);
|
|
2279
|
-
this.refreshSubagents(address.childSessionId);
|
|
2280
|
-
this.notifier.notifyNow();
|
|
2281
|
-
}
|
|
2282
|
-
/** Clear the selection (the layout falls to the no-session view state). */
|
|
2283
|
-
clearSelection() {
|
|
2284
|
-
this.selected = void 0;
|
|
2285
|
-
this.notifier.notifyNow();
|
|
2286
|
-
}
|
|
2287
|
-
/**
|
|
2288
|
-
* Return the durable catalog address retained for one child.
|
|
2289
|
-
* @param sessionId - possible addressed child id.
|
|
2290
|
-
* @returns The direct-parent address, when navigation discovered one.
|
|
2378
|
+
* Resolve an acquisition target without materializing a Session.
|
|
2379
|
+
* @param target - known identity or durable direct-parent address.
|
|
2380
|
+
* @returns the resolved identity with its explicit or catalog-derived history route installed.
|
|
2291
2381
|
*/
|
|
2292
|
-
|
|
2293
|
-
|
|
2382
|
+
resolveTarget(target) {
|
|
2383
|
+
const id = typeof target === "string" ? target : target.childSessionId;
|
|
2384
|
+
const address = typeof target === "string" ? this.subagentAddress(id) : target;
|
|
2385
|
+
if (typeof target === "string" && !this.sessions.has(id) && !this.summaries.some((summary) => summary.sessionId === id) && address === void 0) throw new Error(`sessions.retain: unknown session ${id}`);
|
|
2386
|
+
if (address !== void 0) this.addresses.set(id, address);
|
|
2387
|
+
this.sessions.get(id)?.configureSubagent(address, address === void 0 ? void 0 : this.agentAvailable(address.parentSessionId));
|
|
2388
|
+
return id;
|
|
2294
2389
|
}
|
|
2295
2390
|
/**
|
|
2296
2391
|
* Resolve an address for breadcrumb navigation without retaining transport authority.
|
|
2297
2392
|
* @param sessionId - possible child id in an already-loaded catalog.
|
|
2298
2393
|
* @returns A retained or catalog-derived direct-parent address.
|
|
2299
2394
|
*/
|
|
2300
|
-
|
|
2395
|
+
subagentAddress(sessionId) {
|
|
2301
2396
|
const retained = this.addresses.get(sessionId);
|
|
2302
2397
|
if (retained !== void 0) return retained;
|
|
2303
|
-
for (const
|
|
2304
|
-
const child =
|
|
2305
|
-
if (child
|
|
2398
|
+
for (const parentSessionId of this.projectionStores.keys()) {
|
|
2399
|
+
const child = this.projectionStores.get(parentSessionId)?.values().subagentCatalog?.find((entry) => entry.id === sessionId);
|
|
2400
|
+
if (child !== void 0) return {
|
|
2306
2401
|
parentSessionId,
|
|
2307
2402
|
childSessionId: sessionId,
|
|
2308
2403
|
mode: child.mode
|
|
@@ -2310,27 +2405,35 @@ window.__ModuleLoader__.load({
|
|
|
2310
2405
|
}
|
|
2311
2406
|
}
|
|
2312
2407
|
/**
|
|
2313
|
-
*
|
|
2314
|
-
*
|
|
2315
|
-
*
|
|
2316
|
-
* @
|
|
2408
|
+
* Withdraw an exact Client instance before running its teardown callbacks.
|
|
2409
|
+
* @param sessionId - identity to withdraw.
|
|
2410
|
+
* @param expected - instance being released; a replacement is left untouched.
|
|
2411
|
+
* @returns completion of the detached instance's stream teardown.
|
|
2317
2412
|
*/
|
|
2318
|
-
|
|
2413
|
+
drop(sessionId, expected) {
|
|
2319
2414
|
const session = this.sessions.get(sessionId);
|
|
2415
|
+
if (session !== expected) return Promise.resolve();
|
|
2320
2416
|
this.sessions.delete(sessionId);
|
|
2321
|
-
|
|
2417
|
+
this.addresses.delete(sessionId);
|
|
2418
|
+
this.pruneEngagement(sessionId, this.retainedIds(this.summaries));
|
|
2419
|
+
return this.startSessionDisposal(session);
|
|
2322
2420
|
}
|
|
2323
2421
|
/**
|
|
2324
|
-
* Stop
|
|
2325
|
-
* @returns
|
|
2422
|
+
* Stop catalog requests and dispose every resident Session.
|
|
2423
|
+
* @returns once catalog requests and every Session stream have stopped.
|
|
2326
2424
|
*/
|
|
2327
2425
|
async dispose() {
|
|
2328
|
-
|
|
2329
|
-
this.
|
|
2330
|
-
this.
|
|
2331
|
-
this.
|
|
2426
|
+
this.disposed = true;
|
|
2427
|
+
this.listMutations = null;
|
|
2428
|
+
this.listInflight = null;
|
|
2429
|
+
this.engagedSessions.clear();
|
|
2430
|
+
const reads = [...this.projectionInflight.values()];
|
|
2431
|
+
for (const { controller } of reads) controller.abort();
|
|
2432
|
+
this.projectionInflight.clear();
|
|
2433
|
+
await Promise.all(reads.map((read) => read.promise));
|
|
2332
2434
|
const sessions = [...this.sessions.values()];
|
|
2333
2435
|
this.sessions.clear();
|
|
2436
|
+
this.addresses.clear();
|
|
2334
2437
|
for (const session of sessions) this.startSessionDisposal(session);
|
|
2335
2438
|
await this.drainSessionDisposals();
|
|
2336
2439
|
}
|
|
@@ -2349,7 +2452,8 @@ window.__ModuleLoader__.load({
|
|
|
2349
2452
|
}
|
|
2350
2453
|
/**
|
|
2351
2454
|
* Lazy build: return the existing instance or construct one (no auto-open —
|
|
2352
|
-
*
|
|
2455
|
+
* the reference allocator opens history after binding the scope).
|
|
2456
|
+
* New instances reconcile retained metadata before returning.
|
|
2353
2457
|
* @param sessionId - the session to get.
|
|
2354
2458
|
* @returns the resident instance.
|
|
2355
2459
|
*/
|
|
@@ -2358,45 +2462,73 @@ window.__ModuleLoader__.load({
|
|
|
2358
2462
|
if (session === void 0) {
|
|
2359
2463
|
session = this.createSession(sessionId);
|
|
2360
2464
|
this.sessions.set(sessionId, session);
|
|
2361
|
-
session.replaceControl(this.queues.get(sessionId) ?? []);
|
|
2362
2465
|
const summary = this.summaries.find((s) => s.sessionId === sessionId);
|
|
2363
2466
|
if (summary !== void 0) {
|
|
2364
|
-
session.handleBlank(summary
|
|
2467
|
+
session.handleBlank(this.effectiveBlank(summary));
|
|
2365
2468
|
session.handleRunning(summary.running);
|
|
2366
2469
|
} else {
|
|
2367
2470
|
const address = this.addresses.get(sessionId);
|
|
2368
|
-
|
|
2369
|
-
if (child?.kind === "child") {
|
|
2471
|
+
if ((address === void 0 ? void 0 : this.projectionStores.get(address.parentSessionId)?.values().subagentCatalog?.find((entry) => entry.id === sessionId)) !== void 0) {
|
|
2370
2472
|
session.handleBlank(false);
|
|
2371
|
-
session.handleRunning(
|
|
2372
|
-
}
|
|
2473
|
+
session.handleRunning(false);
|
|
2474
|
+
} else session.handleBlank(true);
|
|
2373
2475
|
}
|
|
2374
2476
|
}
|
|
2375
2477
|
return session;
|
|
2376
2478
|
}
|
|
2377
2479
|
createSession(sessionId) {
|
|
2378
2480
|
const address = this.addresses.get(sessionId);
|
|
2379
|
-
const parentAvailable = address === void 0 ? void 0 : this.
|
|
2481
|
+
const parentAvailable = address === void 0 ? void 0 : this.agentAvailable(address.parentSessionId);
|
|
2380
2482
|
return new Session(sessionId, this.remote, {
|
|
2381
2483
|
...address === void 0 ? {} : {
|
|
2382
2484
|
address,
|
|
2383
|
-
...
|
|
2485
|
+
...parentAvailable === void 0 ? {} : { parentAvailable }
|
|
2384
2486
|
},
|
|
2385
2487
|
onEngaged: (engaged) => {
|
|
2386
|
-
this.
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2488
|
+
if (this.disposed || !this.retainedIds(this.summaries).has(engaged.sessionId)) return;
|
|
2489
|
+
if (!this.engagedSessions.has(engaged.sessionId)) {
|
|
2490
|
+
this.engagedSessions.add(engaged.sessionId);
|
|
2491
|
+
this.recordMutation({
|
|
2492
|
+
kind: "engaged",
|
|
2493
|
+
sessionId: engaged.sessionId
|
|
2494
|
+
});
|
|
2495
|
+
}
|
|
2496
|
+
this.sessions.get(engaged.sessionId)?.handleBlank(false);
|
|
2390
2497
|
},
|
|
2391
2498
|
projections: this.projectionStore(sessionId)
|
|
2392
2499
|
});
|
|
2393
2500
|
}
|
|
2501
|
+
effectiveBlank(summary) {
|
|
2502
|
+
return summary.blank && !this.engagedSessions.has(summary.sessionId);
|
|
2503
|
+
}
|
|
2504
|
+
/**
|
|
2505
|
+
* Identities an engagement may still belong to: the given list rows, resident
|
|
2506
|
+
* Session instances, and retained child addresses.
|
|
2507
|
+
* @param summaries - list rows of the caller's snapshot.
|
|
2508
|
+
* @returns the retained identity set.
|
|
2509
|
+
*/
|
|
2510
|
+
retainedIds(summaries) {
|
|
2511
|
+
const retained = new Set(summaries.map((summary) => summary.sessionId));
|
|
2512
|
+
for (const sessionId of this.sessions.keys()) retained.add(sessionId);
|
|
2513
|
+
for (const sessionId of this.addresses.keys()) retained.add(sessionId);
|
|
2514
|
+
return retained;
|
|
2515
|
+
}
|
|
2516
|
+
/**
|
|
2517
|
+
* Forget one engagement that no retained identity holds.
|
|
2518
|
+
* @param sessionId - identity whose engagement may be dropped.
|
|
2519
|
+
* @param retained - identities from {@link retainedIds} for the caller's snapshot.
|
|
2520
|
+
*/
|
|
2521
|
+
pruneEngagement(sessionId, retained) {
|
|
2522
|
+
if (!retained.has(sessionId)) this.engagedSessions.delete(sessionId);
|
|
2523
|
+
}
|
|
2394
2524
|
/** Resident per-session projection store (create-on-demand; outlives instantiation). */
|
|
2395
2525
|
projectionStore(sessionId) {
|
|
2396
2526
|
let store = this.projectionStores.get(sessionId);
|
|
2397
2527
|
if (store === void 0) {
|
|
2398
2528
|
store = new ProjectionValueStore();
|
|
2529
|
+
const projections = store;
|
|
2399
2530
|
store.subscribeAny(() => {
|
|
2531
|
+
if (projections.values().sessionListMetadata?.blank === false) this.sessions.get(sessionId)?.handleBlank(false);
|
|
2400
2532
|
this.notifier.markDirty();
|
|
2401
2533
|
});
|
|
2402
2534
|
this.projectionStores.set(sessionId, store);
|
|
@@ -2404,85 +2536,70 @@ window.__ModuleLoader__.load({
|
|
|
2404
2536
|
return store;
|
|
2405
2537
|
}
|
|
2406
2538
|
/**
|
|
2407
|
-
*
|
|
2408
|
-
* @param
|
|
2539
|
+
* Load a complete projection baseline once per connection; retry unsuccessful reads.
|
|
2540
|
+
* @param sessionId - Session to inspect without opening its conversation.
|
|
2541
|
+
* @returns completion of the current or newly started read.
|
|
2409
2542
|
*/
|
|
2410
|
-
|
|
2411
|
-
const existing = this.
|
|
2543
|
+
refreshProjections(sessionId) {
|
|
2544
|
+
const existing = this.projectionInflight.get(sessionId);
|
|
2412
2545
|
if (existing !== void 0) return existing.promise;
|
|
2413
|
-
|
|
2414
|
-
const
|
|
2415
|
-
const
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
...previous?.parentAvailable === void 0 ? {} : { parentAvailable: previous.parentAvailable },
|
|
2546
|
+
if (this.projectionLoads.get(sessionId)?.state === "ready") return Promise.resolve();
|
|
2547
|
+
const controller = new AbortController();
|
|
2548
|
+
const store = this.projectionStore(sessionId);
|
|
2549
|
+
const initialValues = store.values();
|
|
2550
|
+
this.projectionLoads.set(sessionId, {
|
|
2419
2551
|
state: "loading",
|
|
2420
2552
|
error: null
|
|
2421
2553
|
});
|
|
2422
2554
|
this.notifier.markDirty();
|
|
2423
2555
|
const operation = (async () => {
|
|
2424
2556
|
try {
|
|
2425
|
-
const result = await this.remote.
|
|
2557
|
+
const result = await this.remote.session.projections({ sessionId }, controller.signal);
|
|
2558
|
+
if (controller.signal.aborted) return;
|
|
2426
2559
|
if (result.ok) {
|
|
2427
|
-
|
|
2428
|
-
this.catalogs.set(parentSessionId, {
|
|
2560
|
+
if (result.value !== null) store.seed({
|
|
2429
2561
|
...result.value,
|
|
2430
|
-
|
|
2431
|
-
|
|
2562
|
+
asOfSeq: sessionSeqCursor(result.value.asOfSeq)
|
|
2563
|
+
});
|
|
2564
|
+
else if (store.values() === initialValues) store.clear();
|
|
2565
|
+
this.projectionLoads.set(sessionId, {
|
|
2432
2566
|
state: "ready",
|
|
2433
2567
|
error: null
|
|
2434
2568
|
});
|
|
2435
|
-
|
|
2436
|
-
if (address.parentSessionId !== parentSessionId) continue;
|
|
2437
|
-
this.sessions.get(childId)?.handleSubagentParentAvailable(parentAvailable);
|
|
2438
|
-
}
|
|
2439
|
-
} else this.catalogs.set(parentSessionId, {
|
|
2440
|
-
entries: this.withCatalogMutations(previous?.entries ?? [], expandableRows, activityRows),
|
|
2441
|
-
...catalogAvailability(this.catalogInflight.get(parentSessionId)?.parentAvailableOverride ?? previous?.parentAvailable),
|
|
2569
|
+
} else this.projectionLoads.set(sessionId, {
|
|
2442
2570
|
state: "error",
|
|
2443
2571
|
error: result.error
|
|
2444
2572
|
});
|
|
2445
2573
|
} catch (error) {
|
|
2574
|
+
if (controller.signal.aborted) return;
|
|
2446
2575
|
if (!(0, _deepseek_ai_dsh_api_gateway_client.isRemoteFailure)(error)) throw error;
|
|
2447
|
-
this.
|
|
2448
|
-
entries: this.withCatalogMutations(previous?.entries ?? [], expandableRows, activityRows),
|
|
2449
|
-
...catalogAvailability(this.catalogInflight.get(parentSessionId)?.parentAvailableOverride ?? previous?.parentAvailable),
|
|
2576
|
+
this.projectionLoads.set(sessionId, {
|
|
2450
2577
|
state: "error",
|
|
2451
2578
|
error
|
|
2452
2579
|
});
|
|
2453
2580
|
} finally {
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2581
|
+
if (!controller.signal.aborted) {
|
|
2582
|
+
this.projectionInflight.delete(sessionId);
|
|
2583
|
+
this.notifier.markDirty();
|
|
2584
|
+
}
|
|
2457
2585
|
}
|
|
2458
2586
|
})();
|
|
2459
|
-
this.
|
|
2587
|
+
this.projectionInflight.set(sessionId, {
|
|
2460
2588
|
promise: operation,
|
|
2461
|
-
|
|
2462
|
-
activityRows,
|
|
2463
|
-
parentAvailableOverride: void 0
|
|
2589
|
+
controller
|
|
2464
2590
|
});
|
|
2465
2591
|
return operation;
|
|
2466
2592
|
}
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
this.openCatalogs.add(parentSessionId);
|
|
2475
|
-
this.refreshSubagents(parentSessionId);
|
|
2476
|
-
} else {
|
|
2477
|
-
this.openCatalogs.delete(parentSessionId);
|
|
2478
|
-
const timer = this.catalogDebounce.get(parentSessionId);
|
|
2479
|
-
if (timer !== void 0) {
|
|
2480
|
-
clearTimeout(timer);
|
|
2481
|
-
this.catalogDebounce.delete(parentSessionId);
|
|
2482
|
-
}
|
|
2593
|
+
agentAvailable(sessionId) {
|
|
2594
|
+
return this.summaries.find((summary) => summary.sessionId === sessionId)?.agentAvailable ?? (this.listPhase === "ready" ? false : void 0);
|
|
2595
|
+
}
|
|
2596
|
+
updateParentAvailability() {
|
|
2597
|
+
for (const [childId, address] of this.addresses) {
|
|
2598
|
+
const available = this.agentAvailable(address.parentSessionId);
|
|
2599
|
+
if (available !== void 0) this.sessions.get(childId)?.handleSubagentParentAvailable(available);
|
|
2483
2600
|
}
|
|
2484
2601
|
}
|
|
2485
|
-
/** Full refresh via session.list (single-flight
|
|
2602
|
+
/** Full refresh via session.list (single-flight within one Host generation). */
|
|
2486
2603
|
refreshList() {
|
|
2487
2604
|
if (this.listInflight !== null) return this.listInflight;
|
|
2488
2605
|
this.listState = "loading";
|
|
@@ -2494,44 +2611,41 @@ window.__ModuleLoader__.load({
|
|
|
2494
2611
|
this.listInflight = (async () => {
|
|
2495
2612
|
try {
|
|
2496
2613
|
const result = await this.remote.session.list({});
|
|
2614
|
+
if (this.listMutations !== mutations) return;
|
|
2497
2615
|
if (result.ok) {
|
|
2498
2616
|
const baseline = this.listPhase === "pending" ? [...result.value.items] : mergeOrderedBaseline(established, result.value.items, (summary) => summary.sessionId);
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
for (const
|
|
2502
|
-
|
|
2503
|
-
this.summaries = summaries;
|
|
2504
|
-
this.syncCompletedNotifications();
|
|
2505
|
-
}
|
|
2617
|
+
const removedSincePull = /* @__PURE__ */ new Set();
|
|
2618
|
+
for (const mutation of mutations) if (mutation.kind === "remove") removedSincePull.add(mutation.sessionId);
|
|
2619
|
+
for (const s of baseline) if (s.running && !removedSincePull.has(s.sessionId)) this.engagedSessions.add(s.sessionId);
|
|
2620
|
+
const summaries = mutations.reduce(applyMutation, baseline);
|
|
2506
2621
|
this.summaries = summaries;
|
|
2622
|
+
const retained = this.retainedIds(summaries);
|
|
2623
|
+
for (const sessionId of this.engagedSessions) this.pruneEngagement(sessionId, retained);
|
|
2507
2624
|
this.listState = "idle";
|
|
2508
2625
|
this.listPhase = "ready";
|
|
2509
|
-
this.
|
|
2626
|
+
this.updateParentAvailability();
|
|
2510
2627
|
for (const s of this.summaries) {
|
|
2511
2628
|
const session = this.sessions.get(s.sessionId);
|
|
2512
2629
|
if (session === void 0) continue;
|
|
2513
|
-
session.handleBlank(s
|
|
2630
|
+
session.handleBlank(this.effectiveBlank(s));
|
|
2514
2631
|
session.handleRunning(s.running);
|
|
2515
2632
|
}
|
|
2516
|
-
for (const s of result.value.items)
|
|
2517
|
-
const block = s.projections;
|
|
2518
|
-
if (block === void 0) continue;
|
|
2519
|
-
const store = this.projectionStore(s.sessionId);
|
|
2520
|
-
const values = block.values;
|
|
2521
|
-
for (const key of Object.keys(values)) store.apply(key, values[key], sessionSeqCursor(block.asOfSeq));
|
|
2522
|
-
}
|
|
2633
|
+
for (const s of result.value.items) if (s.projections !== void 0) this.applyListBlock(s.sessionId, s.projections);
|
|
2523
2634
|
} else {
|
|
2524
2635
|
this.listState = "error";
|
|
2525
2636
|
this.listError = result.error;
|
|
2526
2637
|
}
|
|
2527
2638
|
} catch (error) {
|
|
2528
2639
|
if (!(0, _deepseek_ai_dsh_api_gateway_client.isRemoteFailure)(error)) throw error;
|
|
2640
|
+
if (this.listMutations !== mutations) return;
|
|
2529
2641
|
this.listState = "error";
|
|
2530
2642
|
this.listError = error;
|
|
2531
2643
|
} finally {
|
|
2532
|
-
this.listMutations
|
|
2533
|
-
|
|
2534
|
-
|
|
2644
|
+
if (this.listMutations === mutations) {
|
|
2645
|
+
this.listMutations = null;
|
|
2646
|
+
this.listInflight = null;
|
|
2647
|
+
this.notifier.markDirty();
|
|
2648
|
+
}
|
|
2535
2649
|
}
|
|
2536
2650
|
})();
|
|
2537
2651
|
return this.listInflight;
|
|
@@ -2572,8 +2686,9 @@ window.__ModuleLoader__.load({
|
|
|
2572
2686
|
};
|
|
2573
2687
|
const result = await this.remote.session.create(payload);
|
|
2574
2688
|
if (result.ok) this.recordMutation({
|
|
2575
|
-
kind: "
|
|
2689
|
+
kind: "placeholder",
|
|
2576
2690
|
summary: {
|
|
2691
|
+
agentAvailable: true,
|
|
2577
2692
|
sessionId: result.value.sessionId,
|
|
2578
2693
|
updatedAt: Date.now(),
|
|
2579
2694
|
running: false,
|
|
@@ -2584,8 +2699,9 @@ window.__ModuleLoader__.load({
|
|
|
2584
2699
|
else {
|
|
2585
2700
|
const publishedSessionId = workspaceAttachSessionId(result.error);
|
|
2586
2701
|
if (publishedSessionId !== void 0) this.recordMutation({
|
|
2587
|
-
kind: "
|
|
2702
|
+
kind: "placeholder",
|
|
2588
2703
|
summary: {
|
|
2704
|
+
agentAvailable: true,
|
|
2589
2705
|
sessionId: publishedSessionId,
|
|
2590
2706
|
updatedAt: Date.now(),
|
|
2591
2707
|
running: false,
|
|
@@ -2597,11 +2713,12 @@ window.__ModuleLoader__.load({
|
|
|
2597
2713
|
}
|
|
2598
2714
|
/**
|
|
2599
2715
|
* Contract session.fork; on success merge the child into summaries
|
|
2600
|
-
* immediately (same synchronous-addressability guarantee as create).
|
|
2601
|
-
*
|
|
2602
|
-
*
|
|
2603
|
-
*
|
|
2604
|
-
*
|
|
2716
|
+
* immediately (same synchronous-addressability guarantee as create).
|
|
2717
|
+
* Blankness starts provisionally true so the authoritative Host summary can
|
|
2718
|
+
* preserve it or lower it after an exact cut before the first `turn/start`;
|
|
2719
|
+
* lineage rides parentSessionId. A child published before Workspace
|
|
2720
|
+
* attachment fails is also reconciled into the list.
|
|
2721
|
+
* @param opts - source session and the optional exact inclusive boundary seq.
|
|
2605
2722
|
* @returns the fork result (the child session id).
|
|
2606
2723
|
*/
|
|
2607
2724
|
async fork(opts) {
|
|
@@ -2612,12 +2729,13 @@ window.__ModuleLoader__.load({
|
|
|
2612
2729
|
});
|
|
2613
2730
|
const childId = result.ok ? result.value.sessionId : workspaceAttachSessionId(result.error);
|
|
2614
2731
|
if (childId !== void 0) this.recordMutation({
|
|
2615
|
-
kind: "
|
|
2732
|
+
kind: "placeholder",
|
|
2616
2733
|
summary: {
|
|
2734
|
+
agentAvailable: true,
|
|
2617
2735
|
sessionId: childId,
|
|
2618
2736
|
updatedAt: Date.now(),
|
|
2619
2737
|
running: false,
|
|
2620
|
-
blank:
|
|
2738
|
+
blank: true,
|
|
2621
2739
|
parentSessionId: opts.sessionId,
|
|
2622
2740
|
...source?.cwd !== void 0 ? { cwd: source.cwd } : {}
|
|
2623
2741
|
}
|
|
@@ -2625,22 +2743,35 @@ window.__ModuleLoader__.load({
|
|
|
2625
2743
|
return result;
|
|
2626
2744
|
}
|
|
2627
2745
|
/**
|
|
2628
|
-
*
|
|
2629
|
-
*
|
|
2630
|
-
*
|
|
2631
|
-
*
|
|
2746
|
+
* Rename a Session and update its title projection without opening its history.
|
|
2747
|
+
* @param sessionId - Session to rename.
|
|
2748
|
+
* @param title - raw title text for Host normalization.
|
|
2749
|
+
* @returns the accepted title and event position, or the Remote failure.
|
|
2750
|
+
*/
|
|
2751
|
+
async rename(sessionId, title) {
|
|
2752
|
+
const result = await this.remote.session.rename({
|
|
2753
|
+
sessionId,
|
|
2754
|
+
title
|
|
2755
|
+
});
|
|
2756
|
+
if (result.ok) this.projectionStore(sessionId).apply("title", result.value.title, SessionSeq(result.value.seq));
|
|
2757
|
+
return result;
|
|
2758
|
+
}
|
|
2759
|
+
/**
|
|
2760
|
+
* Merge a Host summary, replacing live state and filling missing metadata.
|
|
2761
|
+
* Local create/fork placeholders only fill metadata on an existing row.
|
|
2632
2762
|
*/
|
|
2633
2763
|
mergeSummary(summary) {
|
|
2634
2764
|
this.recordMutation({
|
|
2635
2765
|
kind: "upsert",
|
|
2636
2766
|
summary
|
|
2637
2767
|
});
|
|
2768
|
+
this.updateParentAvailability();
|
|
2638
2769
|
}
|
|
2639
2770
|
/** Apply immediately and retain for replay when a list response is in flight. */
|
|
2640
2771
|
recordMutation(mutation) {
|
|
2772
|
+
if (this.disposed) return;
|
|
2641
2773
|
this.listMutations?.push(mutation);
|
|
2642
2774
|
this.summaries = applyMutation(this.summaries, mutation);
|
|
2643
|
-
this.syncCompletedNotifications();
|
|
2644
2775
|
this.notifier.markDirty();
|
|
2645
2776
|
}
|
|
2646
2777
|
/**
|
|
@@ -2660,6 +2791,14 @@ window.__ModuleLoader__.load({
|
|
|
2660
2791
|
return this.listSnapshotCache;
|
|
2661
2792
|
}
|
|
2662
2793
|
/**
|
|
2794
|
+
* Read cached projection values for a Session that may exist only in a loaded subagent catalog.
|
|
2795
|
+
* @param sessionId - Session whose control or history baseline supplied projections.
|
|
2796
|
+
* @returns current values, or undefined before any projection store exists.
|
|
2797
|
+
*/
|
|
2798
|
+
projectionValues(sessionId) {
|
|
2799
|
+
return this.projectionStores.get(sessionId)?.values();
|
|
2800
|
+
}
|
|
2801
|
+
/**
|
|
2663
2802
|
* Apply a complete control baseline or one later replacement frame.
|
|
2664
2803
|
* @param frame - baseline or live control replacement from Session Controller.
|
|
2665
2804
|
*/
|
|
@@ -2668,35 +2807,18 @@ window.__ModuleLoader__.load({
|
|
|
2668
2807
|
this.replaceControlBaseline(frame.value);
|
|
2669
2808
|
return;
|
|
2670
2809
|
}
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
this.notifier.markDirty();
|
|
2674
|
-
return;
|
|
2675
|
-
}
|
|
2676
|
-
if (frame.type === "jobs") {
|
|
2677
|
-
if (frame.jobs.length === 0) this.jobsBySession.delete(frame.sessionId);
|
|
2678
|
-
else this.jobsBySession.set(frame.sessionId, frame.jobs);
|
|
2679
|
-
this.notifier.markDirty();
|
|
2680
|
-
return;
|
|
2681
|
-
}
|
|
2682
|
-
this.queues.set(frame.sessionId, frame.items);
|
|
2683
|
-
this.sessions.get(frame.sessionId)?.handleControlFrame(frame);
|
|
2810
|
+
this.projectionStore(frame.sessionId).apply(frame.key, frame.value, SessionSeq(frame.seq));
|
|
2811
|
+
this.notifier.markDirty();
|
|
2684
2812
|
}
|
|
2685
2813
|
replaceControlBaseline(baseline) {
|
|
2686
|
-
this.queues.clear();
|
|
2687
|
-
for (const [sessionId, items] of Object.entries(baseline.queues)) this.queues.set(sessionId, items);
|
|
2688
|
-
this.jobsBySession.clear();
|
|
2689
|
-
for (const [sessionId, jobs] of Object.entries(baseline.jobs)) if (jobs.length > 0) this.jobsBySession.set(sessionId, jobs);
|
|
2690
2814
|
for (const [sessionId, block] of Object.entries(baseline.projections)) {
|
|
2691
2815
|
const store = this.projectionStore(sessionId);
|
|
2692
2816
|
const asOfSeq = sessionSeqCursor(block.asOfSeq);
|
|
2693
|
-
store.truncate(asOfSeq);
|
|
2694
2817
|
store.seed({
|
|
2695
2818
|
...block,
|
|
2696
2819
|
asOfSeq
|
|
2697
2820
|
});
|
|
2698
2821
|
}
|
|
2699
|
-
for (const [sessionId, session] of this.sessions) session.replaceControl(this.queues.get(sessionId) ?? []);
|
|
2700
2822
|
this.notifier.markDirty();
|
|
2701
2823
|
}
|
|
2702
2824
|
/**
|
|
@@ -2705,45 +2827,55 @@ window.__ModuleLoader__.load({
|
|
|
2705
2827
|
*/
|
|
2706
2828
|
handleSessionAdded(summary) {
|
|
2707
2829
|
this.mergeSummary(summary);
|
|
2708
|
-
this.
|
|
2709
|
-
|
|
2710
|
-
if (projections !== void 0)
|
|
2711
|
-
|
|
2712
|
-
|
|
2830
|
+
if (!this.disposed && summary.running) this.engagedSessions.add(summary.sessionId);
|
|
2831
|
+
this.sessions.get(summary.sessionId)?.handleBlank(this.effectiveBlank(summary));
|
|
2832
|
+
if (summary.projections !== void 0) this.applyListBlock(summary.sessionId, summary.projections);
|
|
2833
|
+
}
|
|
2834
|
+
/**
|
|
2835
|
+
* Merge one list-surface projection block by the sequence space it declares.
|
|
2836
|
+
* A `sequenced` block came from the Host's live registry for an attached
|
|
2837
|
+
* Session, so each key lands under higher-seq-wins against that Session's
|
|
2838
|
+
* baselines and frames. A `cached` block was viewed from the persisted
|
|
2839
|
+
* checkpoint by a header-only listing: its watermark is not comparable with
|
|
2840
|
+
* this connection's seqs, so it only fills keys no sequenced row holds.
|
|
2841
|
+
*/
|
|
2842
|
+
applyListBlock(sessionId, block) {
|
|
2843
|
+
const store = this.projectionStore(sessionId);
|
|
2844
|
+
switch (block.kind) {
|
|
2845
|
+
case "sequenced": {
|
|
2846
|
+
const seq = sessionSeqCursor(block.asOfSeq);
|
|
2847
|
+
for (const [key, value] of Object.entries(block.values)) store.apply(key, value, seq);
|
|
2848
|
+
return;
|
|
2849
|
+
}
|
|
2850
|
+
case "cached":
|
|
2851
|
+
store.applyCached(block.values);
|
|
2852
|
+
return;
|
|
2853
|
+
default: assertNever(block.kind, "session list projection block kind");
|
|
2713
2854
|
}
|
|
2714
|
-
if (summary.origin === "subagent" && summary.parentSessionId !== void 0) this.markCatalogParentExpandable(summary.parentSessionId);
|
|
2715
|
-
if (summary.parentSessionId !== void 0 && (this.selected === summary.parentSessionId || this.openCatalogs.has(summary.parentSessionId))) this.scheduleCatalogRefresh(summary.parentSessionId);
|
|
2716
2855
|
}
|
|
2717
2856
|
/**
|
|
2718
2857
|
* Apply one Session removal forwarded through `ctx.remote.$on`.
|
|
2719
2858
|
* @param sessionId - removed Session identity.
|
|
2720
2859
|
*/
|
|
2721
2860
|
handleSessionRemoved(sessionId) {
|
|
2722
|
-
const durableSubagent = this.summaries.
|
|
2861
|
+
const durableSubagent = this.subagentAddress(sessionId) !== void 0 || this.summaries.some((summary) => summary.sessionId === sessionId && summary.origin === "subagent");
|
|
2723
2862
|
this.recordMutation(durableSubagent ? {
|
|
2724
2863
|
kind: "status",
|
|
2725
2864
|
sessionId,
|
|
2726
|
-
running: false
|
|
2865
|
+
running: false,
|
|
2866
|
+
agentAvailable: false
|
|
2727
2867
|
} : {
|
|
2728
2868
|
kind: "remove",
|
|
2729
2869
|
sessionId
|
|
2730
2870
|
});
|
|
2731
|
-
this.updateCatalogActivity(sessionId, false);
|
|
2732
2871
|
if (durableSubagent) this.sessions.get(sessionId)?.handleRunning(false);
|
|
2733
2872
|
else this.sessions.get(sessionId)?.handleRemoved();
|
|
2734
|
-
this.
|
|
2735
|
-
this.
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
this.catalogStale.add(sessionId);
|
|
2741
|
-
}
|
|
2742
|
-
const ownedCatalog = this.catalogs.get(sessionId);
|
|
2743
|
-
if (ownedCatalog !== void 0 && ownedCatalog.parentAvailable) this.catalogs.set(sessionId, {
|
|
2744
|
-
...ownedCatalog,
|
|
2745
|
-
parentAvailable: false
|
|
2746
|
-
});
|
|
2873
|
+
const catalog = this.projectionStores.get(sessionId)?.values().subagentCatalog;
|
|
2874
|
+
if (!durableSubagent && (catalog === void 0 || catalog.length === 0)) this.projectionStores.delete(sessionId);
|
|
2875
|
+
this.pruneEngagement(sessionId, this.retainedIds(this.summaries));
|
|
2876
|
+
this.projectionInflight.get(sessionId)?.controller.abort();
|
|
2877
|
+
this.projectionInflight.delete(sessionId);
|
|
2878
|
+
this.projectionLoads.delete(sessionId);
|
|
2747
2879
|
for (const [childId, address] of this.addresses) if (address.parentSessionId === sessionId) this.sessions.get(childId)?.handleSubagentParentAvailable(false);
|
|
2748
2880
|
}
|
|
2749
2881
|
/**
|
|
@@ -2752,13 +2884,15 @@ window.__ModuleLoader__.load({
|
|
|
2752
2884
|
* @param running - current Agent running state.
|
|
2753
2885
|
*/
|
|
2754
2886
|
handleSessionStatus(sessionId, running) {
|
|
2887
|
+
if (!this.disposed && running) this.engagedSessions.add(sessionId);
|
|
2755
2888
|
this.recordMutation({
|
|
2756
2889
|
kind: "status",
|
|
2757
2890
|
sessionId,
|
|
2758
|
-
running
|
|
2891
|
+
running,
|
|
2892
|
+
agentAvailable: true
|
|
2759
2893
|
});
|
|
2894
|
+
this.updateParentAvailability();
|
|
2760
2895
|
this.sessions.get(sessionId)?.handleRunning(running);
|
|
2761
|
-
this.updateCatalogActivity(sessionId, running);
|
|
2762
2896
|
}
|
|
2763
2897
|
/**
|
|
2764
2898
|
* Advance Session-list activity from one user-authored durable message.
|
|
@@ -2782,165 +2916,87 @@ window.__ModuleLoader__.load({
|
|
|
2782
2916
|
}
|
|
2783
2917
|
/**
|
|
2784
2918
|
* Repair one re-established Host-event generation with queryable baselines.
|
|
2919
|
+
* Discard old projection cuts before new queries, including cold Sessions
|
|
2920
|
+
* absent from the process-local control baseline.
|
|
2785
2921
|
* Opened Session follow streams resume independently through API Gateway.
|
|
2786
2922
|
*/
|
|
2787
2923
|
handleConnected() {
|
|
2924
|
+
for (const store of this.projectionStores.values()) store.clear();
|
|
2925
|
+
this.listMutations = null;
|
|
2926
|
+
this.listInflight = null;
|
|
2788
2927
|
this.refreshList();
|
|
2789
|
-
const
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
}
|
|
2794
|
-
/** Debounce membership refetches while one parent catalog is selected or open. */
|
|
2795
|
-
scheduleCatalogRefresh(parentSessionId) {
|
|
2796
|
-
if (this.catalogDebounce.has(parentSessionId)) return;
|
|
2797
|
-
const timer = setTimeout(() => {
|
|
2798
|
-
this.catalogDebounce.delete(parentSessionId);
|
|
2799
|
-
if (this.catalogInflight.has(parentSessionId)) {
|
|
2800
|
-
this.catalogStale.add(parentSessionId);
|
|
2801
|
-
return;
|
|
2802
|
-
}
|
|
2803
|
-
this.refreshSubagents(parentSessionId);
|
|
2804
|
-
}, 50);
|
|
2805
|
-
this.catalogDebounce.set(parentSessionId, timer);
|
|
2806
|
-
}
|
|
2807
|
-
/** Apply one Agent-driver transition to loaded and in-flight catalogs. */
|
|
2808
|
-
updateCatalogActivity(childSessionId, running) {
|
|
2809
|
-
const activity = running ? "running" : "inactive";
|
|
2810
|
-
for (const inflight of this.catalogInflight.values()) inflight.activityRows.set(childSessionId, activity);
|
|
2811
|
-
let changed = false;
|
|
2812
|
-
for (const [parentSessionId, catalog] of this.catalogs) {
|
|
2813
|
-
if (!catalog.entries.some((entry) => entry.kind === "child" && entry.id === childSessionId && entry.activity !== activity)) continue;
|
|
2814
|
-
const entries = catalog.entries.map((entry) => {
|
|
2815
|
-
if (entry.kind !== "child" || entry.id !== childSessionId) return entry;
|
|
2816
|
-
return {
|
|
2817
|
-
...entry,
|
|
2818
|
-
activity
|
|
2819
|
-
};
|
|
2820
|
-
});
|
|
2821
|
-
changed = true;
|
|
2822
|
-
this.catalogs.set(parentSessionId, {
|
|
2823
|
-
...catalog,
|
|
2824
|
-
entries
|
|
2825
|
-
});
|
|
2826
|
-
}
|
|
2827
|
-
if (changed) this.notifier.markDirty();
|
|
2828
|
-
}
|
|
2829
|
-
/** Preserve and project a positive expandability hint after one direct subagent publishes. */
|
|
2830
|
-
markCatalogParentExpandable(parentSessionId) {
|
|
2831
|
-
this.applyCatalogParentExpandable(parentSessionId);
|
|
2832
|
-
for (const inflight of this.catalogInflight.values()) inflight.expandableRows.add(parentSessionId);
|
|
2833
|
-
}
|
|
2834
|
-
/** Apply one positive expandability hint to every loaded catalog containing that unique row id. */
|
|
2835
|
-
applyCatalogParentExpandable(parentSessionId) {
|
|
2836
|
-
let changed = false;
|
|
2837
|
-
for (const [catalogParentId, catalog] of this.catalogs) {
|
|
2838
|
-
if (!catalog.entries.some((entry) => entry.kind === "child" && entry.id === parentSessionId && !entry.hasChildren)) continue;
|
|
2839
|
-
const entries = catalog.entries.map((entry) => {
|
|
2840
|
-
if (entry.kind !== "child" || entry.id !== parentSessionId || entry.hasChildren) return entry;
|
|
2841
|
-
return {
|
|
2842
|
-
...entry,
|
|
2843
|
-
hasChildren: true
|
|
2844
|
-
};
|
|
2845
|
-
});
|
|
2846
|
-
changed = true;
|
|
2847
|
-
this.catalogs.set(catalogParentId, {
|
|
2848
|
-
...catalog,
|
|
2849
|
-
entries
|
|
2850
|
-
});
|
|
2851
|
-
}
|
|
2852
|
-
if (changed) this.notifier.markDirty();
|
|
2853
|
-
}
|
|
2854
|
-
/** Fold request-local row mutations into one catalog result before publication. */
|
|
2855
|
-
withCatalogMutations(entries, expandableRows, activityRows) {
|
|
2856
|
-
return entries.map((entry) => {
|
|
2857
|
-
if (entry.kind !== "child") return entry;
|
|
2858
|
-
const activity = activityRows.get(entry.id);
|
|
2859
|
-
if (!expandableRows.has(entry.id) && activity === void 0) return entry;
|
|
2860
|
-
return {
|
|
2861
|
-
...entry,
|
|
2862
|
-
...expandableRows.has(entry.id) ? { hasChildren: true } : {},
|
|
2863
|
-
...activity === void 0 ? {} : { activity }
|
|
2864
|
-
};
|
|
2865
|
-
});
|
|
2866
|
-
}
|
|
2867
|
-
/**
|
|
2868
|
-
* Reconcile completion reminders against the latest summaries, eagerly after
|
|
2869
|
-
* every mutation and pull (a snapshot-build-time pass would collapse
|
|
2870
|
-
* consecutive status frames into one observation). A running→idle edge of a
|
|
2871
|
-
* non-selected session arms its reminder; running disarms it; removal drops
|
|
2872
|
-
* it. First observation only records the running bit — sessions already
|
|
2873
|
-
* idle at load get no reminder.
|
|
2874
|
-
*/
|
|
2875
|
-
syncCompletedNotifications() {
|
|
2876
|
-
const seen = /* @__PURE__ */ new Set();
|
|
2877
|
-
for (const s of this.summaries) {
|
|
2878
|
-
seen.add(s.sessionId);
|
|
2879
|
-
const prev = this.prevRunning.get(s.sessionId);
|
|
2880
|
-
if (prev === void 0) {
|
|
2881
|
-
this.prevRunning.set(s.sessionId, s.running);
|
|
2882
|
-
continue;
|
|
2883
|
-
}
|
|
2884
|
-
if (prev && !s.running) {
|
|
2885
|
-
if (s.sessionId !== this.selected) this.completedNotifications.add(s.sessionId);
|
|
2886
|
-
} else if (s.running) this.completedNotifications.delete(s.sessionId);
|
|
2887
|
-
this.prevRunning.set(s.sessionId, s.running);
|
|
2928
|
+
const parents = new Set(this.projectionLoads.keys());
|
|
2929
|
+
for (const id of this.sessions.keys()) {
|
|
2930
|
+
const address = this.addresses.get(id);
|
|
2931
|
+
if (address !== void 0) parents.add(address.parentSessionId);
|
|
2888
2932
|
}
|
|
2889
|
-
for (const
|
|
2890
|
-
|
|
2933
|
+
for (const { controller } of this.projectionInflight.values()) controller.abort();
|
|
2934
|
+
this.projectionInflight.clear();
|
|
2935
|
+
this.projectionLoads.clear();
|
|
2936
|
+
for (const parentSessionId of parents) this.refreshProjections(parentSessionId);
|
|
2891
2937
|
}
|
|
2892
2938
|
buildListSnapshot() {
|
|
2893
2939
|
const items = flattenLineage(this.summaries.map((summary) => {
|
|
2894
2940
|
const projectionStore = this.projectionStores.get(summary.sessionId);
|
|
2895
2941
|
const title = projectionStore?.get("title");
|
|
2896
2942
|
const projectionValues = projectionStore?.values();
|
|
2943
|
+
const metadata = projectionValues?.sessionListMetadata;
|
|
2897
2944
|
return {
|
|
2898
2945
|
...summary,
|
|
2946
|
+
blank: this.effectiveBlank(summary) && metadata?.blank !== false,
|
|
2947
|
+
updatedAt: Math.max(summary.updatedAt, metadata?.lastPromptAt ?? 0),
|
|
2899
2948
|
...typeof title === "string" && title !== "" ? { title } : {},
|
|
2900
2949
|
...projectionValues === void 0 ? {} : { projectionValues }
|
|
2901
2950
|
};
|
|
2902
|
-
})
|
|
2951
|
+
})).map((entry) => {
|
|
2903
2952
|
const prev = this.entryCache.get(entry.sessionId);
|
|
2904
|
-
if (prev !== void 0 && prev.updatedAt === entry.updatedAt && prev.running === entry.running && prev.blank === entry.blank && prev.parentSessionId === entry.parentSessionId && prev.cwd === entry.cwd && prev.origin === entry.origin && prev.title === entry.title && prev.depth === entry.depth && prev.projectionValues === entry.projectionValues
|
|
2953
|
+
if (prev !== void 0 && prev.updatedAt === entry.updatedAt && prev.running === entry.running && prev.blank === entry.blank && prev.parentSessionId === entry.parentSessionId && prev.cwd === entry.cwd && prev.origin === entry.origin && prev.title === entry.title && prev.depth === entry.depth && prev.projectionValues === entry.projectionValues) return prev;
|
|
2905
2954
|
this.entryCache.set(entry.sessionId, entry);
|
|
2906
2955
|
return entry;
|
|
2907
2956
|
});
|
|
2908
|
-
|
|
2957
|
+
const itemIds = new Set(items.map((entry) => entry.sessionId));
|
|
2958
|
+
for (const id of this.entryCache.keys()) if (!itemIds.has(id)) this.entryCache.delete(id);
|
|
2909
2959
|
if (!(items.length === this.itemsCache.length && items.every((e, i) => e === this.itemsCache[i]))) this.itemsCache = items;
|
|
2910
|
-
const selected = this.selected;
|
|
2911
|
-
const current = selected !== void 0 && (items.some((item) => item.sessionId === selected) || this.addresses.has(selected)) ? selected : void 0;
|
|
2912
2960
|
return {
|
|
2913
2961
|
items: this.itemsCache,
|
|
2914
|
-
current,
|
|
2915
2962
|
state: this.listState,
|
|
2916
2963
|
phase: this.listPhase,
|
|
2917
2964
|
error: this.listError,
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2965
|
+
projectionsBySession: Object.fromEntries([...this.projectionStores].map(([sessionId, store]) => [sessionId, {
|
|
2966
|
+
values: store.values(),
|
|
2967
|
+
state: "idle",
|
|
2968
|
+
error: null,
|
|
2969
|
+
...this.projectionLoads.get(sessionId)
|
|
2970
|
+
}]))
|
|
2921
2971
|
};
|
|
2922
2972
|
}
|
|
2923
2973
|
};
|
|
2924
2974
|
/** Apply one list mutation without deriving display order. */
|
|
2925
2975
|
function applyMutation(summaries, mutation) {
|
|
2926
2976
|
switch (mutation.kind) {
|
|
2927
|
-
case "upsert":
|
|
2977
|
+
case "upsert":
|
|
2978
|
+
case "placeholder": {
|
|
2928
2979
|
const existing = summaries.find((summary) => summary.sessionId === mutation.summary.sessionId);
|
|
2929
2980
|
if (existing === void 0) return [mutation.summary, ...summaries];
|
|
2930
2981
|
const filled = {
|
|
2931
2982
|
...existing,
|
|
2932
2983
|
blank: existing.blank && mutation.summary.blank,
|
|
2984
|
+
...mutation.kind === "upsert" ? {
|
|
2985
|
+
agentAvailable: mutation.summary.agentAvailable,
|
|
2986
|
+
running: mutation.summary.running
|
|
2987
|
+
} : {},
|
|
2933
2988
|
...existing.cwd === void 0 && mutation.summary.cwd !== void 0 ? { cwd: mutation.summary.cwd } : {},
|
|
2934
2989
|
...existing.parentSessionId === void 0 && mutation.summary.parentSessionId !== void 0 ? { parentSessionId: mutation.summary.parentSessionId } : {},
|
|
2935
2990
|
...existing.origin === void 0 && mutation.summary.origin !== void 0 ? { origin: mutation.summary.origin } : {}
|
|
2936
2991
|
};
|
|
2937
|
-
if (filled.cwd === existing.cwd && filled.parentSessionId === existing.parentSessionId && filled.origin === existing.origin && filled.blank === existing.blank) return [...summaries];
|
|
2992
|
+
if (filled.cwd === existing.cwd && filled.parentSessionId === existing.parentSessionId && filled.origin === existing.origin && filled.blank === existing.blank && filled.agentAvailable === existing.agentAvailable && filled.running === existing.running) return [...summaries];
|
|
2938
2993
|
return summaries.map((summary) => summary.sessionId === mutation.summary.sessionId ? filled : summary);
|
|
2939
2994
|
}
|
|
2940
2995
|
case "remove": return summaries.filter((summary) => summary.sessionId !== mutation.sessionId);
|
|
2941
|
-
case "status": return summaries.map((summary) => summary.sessionId === mutation.sessionId && (summary.running !== mutation.running || mutation.running && summary.blank) ? {
|
|
2996
|
+
case "status": return summaries.map((summary) => summary.sessionId === mutation.sessionId && (summary.running !== mutation.running || summary.agentAvailable !== mutation.agentAvailable || mutation.running && summary.blank) ? {
|
|
2942
2997
|
...summary,
|
|
2943
2998
|
running: mutation.running,
|
|
2999
|
+
agentAvailable: mutation.agentAvailable,
|
|
2944
3000
|
blank: summary.blank && !mutation.running
|
|
2945
3001
|
} : summary);
|
|
2946
3002
|
case "activity": return summaries.map((summary) => summary.sessionId === mutation.sessionId && mutation.updatedAt > summary.updatedAt ? {
|
|
@@ -3014,7 +3070,74 @@ window.__ModuleLoader__.load({
|
|
|
3014
3070
|
if (fullWidth?.[1] !== void 0 && fullWidth[2] !== void 0) return `${fullWidth[1]}(${BigInt(fullWidth[2]) + 1n})`;
|
|
3015
3071
|
return `${title} (1)`;
|
|
3016
3072
|
}
|
|
3017
|
-
/**
|
|
3073
|
+
/** Source labels are dictionary keys, including names also present on Object.prototype. */
|
|
3074
|
+
function freezeRetainedBy(counts) {
|
|
3075
|
+
Object.setPrototypeOf(counts, null);
|
|
3076
|
+
return Object.freeze(counts);
|
|
3077
|
+
}
|
|
3078
|
+
const EMPTY_RETAIN_INFO = Object.freeze({
|
|
3079
|
+
referenceCount: 0,
|
|
3080
|
+
retainedBy: freezeRetainedBy({})
|
|
3081
|
+
});
|
|
3082
|
+
/** A cancelled waiter releases only its own reference, not the shared opening. */
|
|
3083
|
+
async function waitForOpen(opening, signal) {
|
|
3084
|
+
if (signal === void 0) return opening;
|
|
3085
|
+
const aborted = Promise.withResolvers();
|
|
3086
|
+
const onAbort = () => {
|
|
3087
|
+
aborted.reject(signal.reason);
|
|
3088
|
+
};
|
|
3089
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
3090
|
+
try {
|
|
3091
|
+
if (signal.aborted) onAbort();
|
|
3092
|
+
await Promise.race([opening, aborted.promise]);
|
|
3093
|
+
} finally {
|
|
3094
|
+
signal.removeEventListener("abort", onAbort);
|
|
3095
|
+
}
|
|
3096
|
+
}
|
|
3097
|
+
var ClientSessionReference = class {
|
|
3098
|
+
sessionId;
|
|
3099
|
+
record;
|
|
3100
|
+
releaseReference;
|
|
3101
|
+
released = new AbortController();
|
|
3102
|
+
readiness = Promise.withResolvers();
|
|
3103
|
+
ready = this.readiness.promise;
|
|
3104
|
+
constructor(sessionId, record, releaseReference) {
|
|
3105
|
+
this.sessionId = sessionId;
|
|
3106
|
+
this.record = record;
|
|
3107
|
+
this.releaseReference = releaseReference;
|
|
3108
|
+
this.ready.catch(() => {});
|
|
3109
|
+
}
|
|
3110
|
+
get binding() {
|
|
3111
|
+
if (this.record === void 0 || !this.record.live) throw new Error(`Session reference "${this.sessionId}" is released`);
|
|
3112
|
+
return this.record.binding;
|
|
3113
|
+
}
|
|
3114
|
+
attachOpening(opening, signal) {
|
|
3115
|
+
const waitSignal = signal === void 0 ? this.released.signal : AbortSignal.any([this.released.signal, signal]);
|
|
3116
|
+
waitForOpen(opening, waitSignal).then(() => {
|
|
3117
|
+
try {
|
|
3118
|
+
waitSignal.throwIfAborted();
|
|
3119
|
+
this.readiness.resolve(this.binding);
|
|
3120
|
+
} catch (error) {
|
|
3121
|
+
this.readiness.reject(error);
|
|
3122
|
+
}
|
|
3123
|
+
}, (error) => {
|
|
3124
|
+
this.readiness.reject(error);
|
|
3125
|
+
});
|
|
3126
|
+
}
|
|
3127
|
+
release() {
|
|
3128
|
+
const reason = /* @__PURE__ */ new Error(`Session reference "${this.sessionId}" is released`);
|
|
3129
|
+
const release = this.releaseReference;
|
|
3130
|
+
this.released.abort(reason);
|
|
3131
|
+
this.readiness.reject(reason);
|
|
3132
|
+
this.record = void 0;
|
|
3133
|
+
this.releaseReference = void 0;
|
|
3134
|
+
release?.();
|
|
3135
|
+
}
|
|
3136
|
+
[Symbol.dispose]() {
|
|
3137
|
+
this.release();
|
|
3138
|
+
}
|
|
3139
|
+
};
|
|
3140
|
+
/** Host catalog and local reference allocator; view selection remains outside the Controller. */
|
|
3018
3141
|
var ClientSessions = class {
|
|
3019
3142
|
rootCtx;
|
|
3020
3143
|
/**
|
|
@@ -3024,115 +3147,109 @@ window.__ModuleLoader__.load({
|
|
|
3024
3147
|
* reports the same number.
|
|
3025
3148
|
*/
|
|
3026
3149
|
searchResultLimit = 20;
|
|
3027
|
-
/**
|
|
3150
|
+
/** Catalog metadata and local reference-source projection. */
|
|
3028
3151
|
list;
|
|
3029
3152
|
/** The object-layer instance cluster and frame dispatch entry. */
|
|
3030
3153
|
manager;
|
|
3031
|
-
/**
|
|
3032
|
-
* Persisted selection cell (the durable half of `list.current`). Private on
|
|
3033
|
-
* purpose: reads go through the list snapshot; writes through {@link
|
|
3034
|
-
* ClientSessions.open} / {@link ClientSessions.clear}. Projection
|
|
3035
|
-
* validates it against the live list instead of destructively pruning, so a
|
|
3036
|
-
* selection survives transient list states (reconnect re-pull) and
|
|
3037
|
-
* resurfaces when its session returns.
|
|
3038
|
-
*/
|
|
3039
|
-
selection;
|
|
3040
3154
|
scopes = /* @__PURE__ */ new Map();
|
|
3041
|
-
/**
|
|
3155
|
+
/** Stable per-id sources retained for the Client root lifetime, including across generation replacement. */
|
|
3156
|
+
retainObservers = /* @__PURE__ */ new Map();
|
|
3042
3157
|
scopeDrops = /* @__PURE__ */ new Set();
|
|
3043
|
-
|
|
3044
|
-
* The staged session id — follows `list.current` exactly, holding its last
|
|
3045
|
-
* defined value across masked gaps (a transiently absent selection blanks
|
|
3046
|
-
* `current` without moving the stage, so reconnect re-pulls and removals
|
|
3047
|
-
* keep the staged scope's frozen view alive until the stage moves on).
|
|
3048
|
-
*/
|
|
3049
|
-
watched;
|
|
3050
|
-
/** Removed-while-staged sessions whose teardown waits for the stage to move away. */
|
|
3051
|
-
deferredRemovals = /* @__PURE__ */ new Set();
|
|
3158
|
+
closed = false;
|
|
3052
3159
|
/**
|
|
3053
3160
|
* @param ctx - client root context (scope fibers mount under it).
|
|
3054
3161
|
* @param remote - generated Remote namespaces shared with every Session.
|
|
3055
3162
|
*/
|
|
3056
3163
|
constructor(rootCtx, remote) {
|
|
3057
3164
|
this.rootCtx = rootCtx;
|
|
3058
|
-
this.
|
|
3059
|
-
const restored = this.selection.getSnapshot();
|
|
3060
|
-
this.manager = new SessionManager(remote, restored.sessionId, restored.subagentAddress);
|
|
3165
|
+
this.manager = new SessionManager(remote);
|
|
3061
3166
|
this.list = (0, _deepseek_ai_dsh_client_store.createSnapshotStore)({
|
|
3062
3167
|
ids: [],
|
|
3063
3168
|
byId: {},
|
|
3064
|
-
current: void 0,
|
|
3065
3169
|
phase: "pending",
|
|
3066
|
-
|
|
3067
|
-
jobsBySession: {},
|
|
3068
|
-
currentAddress: void 0
|
|
3170
|
+
projectionsBySession: {}
|
|
3069
3171
|
});
|
|
3070
3172
|
const disposeManagerProjection = this.manager.subscribe(() => {
|
|
3071
3173
|
this.projectList();
|
|
3072
3174
|
});
|
|
3073
|
-
const disposeStageFollower = this.list.subscribe(() => {
|
|
3074
|
-
this.followCurrent();
|
|
3075
|
-
});
|
|
3076
3175
|
rootCtx.effect(() => async () => {
|
|
3077
|
-
|
|
3176
|
+
this.closed = true;
|
|
3078
3177
|
disposeManagerProjection();
|
|
3079
3178
|
const scopes = [...this.scopes];
|
|
3080
3179
|
this.scopes.clear();
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3180
|
+
for (const [, record] of scopes) {
|
|
3181
|
+
record.live = false;
|
|
3182
|
+
record.session.unbindScope();
|
|
3183
|
+
}
|
|
3184
|
+
const managerDisposal = this.manager.dispose();
|
|
3185
|
+
for (const [id, record] of scopes) {
|
|
3186
|
+
this.startScopeDrop(id, record);
|
|
3187
|
+
this.publishRetention(id);
|
|
3188
|
+
}
|
|
3084
3189
|
await this.drainScopeDrops();
|
|
3085
|
-
await
|
|
3190
|
+
await managerDisposal;
|
|
3086
3191
|
}, "session-controller.client.sessions");
|
|
3087
3192
|
rootCtx.reflect.provide("sessions", this, void 0);
|
|
3088
3193
|
}
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
this.
|
|
3194
|
+
retain(target, options) {
|
|
3195
|
+
const { source, signal } = options;
|
|
3196
|
+
signal?.throwIfAborted();
|
|
3197
|
+
if (this.closed) throw new Error("Session Controller is disposed");
|
|
3198
|
+
const id = this.manager.resolveTarget(target);
|
|
3199
|
+
const reference = this.retainScope(id, source);
|
|
3200
|
+
try {
|
|
3201
|
+
reference.attachOpening(this.manager.get(id).open(), signal);
|
|
3202
|
+
return reference;
|
|
3203
|
+
} catch (error) {
|
|
3204
|
+
reference.release();
|
|
3205
|
+
throw error;
|
|
3206
|
+
}
|
|
3095
3207
|
}
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3208
|
+
async using(target, options, operation) {
|
|
3209
|
+
const reference = this.retain(target, options);
|
|
3210
|
+
try {
|
|
3211
|
+
await reference.ready;
|
|
3212
|
+
return await operation(reference);
|
|
3213
|
+
} finally {
|
|
3214
|
+
reference.release();
|
|
3215
|
+
}
|
|
3216
|
+
}
|
|
3217
|
+
retainInfo(id) {
|
|
3218
|
+
let observer = this.retainObservers.get(id);
|
|
3219
|
+
if (observer === void 0) {
|
|
3220
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
3221
|
+
observer = {
|
|
3222
|
+
listeners,
|
|
3223
|
+
published: this.retentionSnapshot(id),
|
|
3224
|
+
source: {
|
|
3225
|
+
getSnapshot: () => this.retentionSnapshot(id),
|
|
3226
|
+
subscribe: (listener) => {
|
|
3227
|
+
listeners.add(listener);
|
|
3228
|
+
return () => {
|
|
3229
|
+
listeners.delete(listener);
|
|
3230
|
+
};
|
|
3231
|
+
}
|
|
3232
|
+
}
|
|
3233
|
+
};
|
|
3234
|
+
this.retainObservers.set(id, observer);
|
|
3235
|
+
}
|
|
3236
|
+
return observer.source;
|
|
3102
3237
|
}
|
|
3103
3238
|
/**
|
|
3104
3239
|
* Resolve an already discovered direct-parent address without opening it.
|
|
3105
3240
|
* Feature plugins use this to avoid Agent-bound RPCs in persisted child views.
|
|
3106
3241
|
* @param id - possible addressed child id.
|
|
3107
|
-
* @returns
|
|
3242
|
+
* @returns A retained or loaded-catalog address, without retaining a new selection or scope.
|
|
3108
3243
|
*/
|
|
3109
3244
|
subagentAddress(id) {
|
|
3110
3245
|
return this.manager.subagentAddress(id);
|
|
3111
3246
|
}
|
|
3112
3247
|
/**
|
|
3113
|
-
*
|
|
3114
|
-
* @param
|
|
3115
|
-
* @param open - menu state.
|
|
3116
|
-
*/
|
|
3117
|
-
setSubagentCatalogOpen(parentSessionId, open) {
|
|
3118
|
-
this.manager.setSubagentCatalogOpen(parentSessionId, open);
|
|
3119
|
-
}
|
|
3120
|
-
/**
|
|
3121
|
-
* Refresh one direct-child catalog.
|
|
3122
|
-
* @param parentSessionId - catalog owner.
|
|
3123
|
-
*/
|
|
3124
|
-
refreshSubagents(parentSessionId) {
|
|
3125
|
-
return this.manager.refreshSubagents(parentSessionId);
|
|
3126
|
-
}
|
|
3127
|
-
/**
|
|
3128
|
-
* Clear the current selection so the layout shows the no-session empty
|
|
3129
|
-
* state (new-session affordance and the workspace preselection flow).
|
|
3130
|
-
* Wipes the persisted selection too — a reload stays on empty until the
|
|
3131
|
-
* user opens or starts a session. The staged scope keeps its frozen view
|
|
3132
|
-
* per the masked-gap contract until the next open() moves the stage.
|
|
3248
|
+
* Load all Session projections once per connection; retry an unsuccessful initial read.
|
|
3249
|
+
* @param sessionId - Session to inspect without opening its conversation.
|
|
3133
3250
|
*/
|
|
3134
|
-
|
|
3135
|
-
this.manager.
|
|
3251
|
+
refreshProjections(sessionId) {
|
|
3252
|
+
return this.manager.refreshProjections(sessionId);
|
|
3136
3253
|
}
|
|
3137
3254
|
/**
|
|
3138
3255
|
* Refresh the real Session baseline, reusing an in-flight pull.
|
|
@@ -3198,12 +3315,8 @@ window.__ModuleLoader__.load({
|
|
|
3198
3315
|
this.manager.handleConnected();
|
|
3199
3316
|
}
|
|
3200
3317
|
/**
|
|
3201
|
-
* Create a
|
|
3202
|
-
*
|
|
3203
|
-
* {@link ClientSessions.binding} resolves it — callers (New Session
|
|
3204
|
-
* draft hand-off) may address the scope synchronously, without waiting a
|
|
3205
|
-
* notifier flush. The synchronous projection below makes this structural
|
|
3206
|
-
* rather than an accident of microtask ordering.
|
|
3318
|
+
* Create a Host Session and publish its catalog row before resolving.
|
|
3319
|
+
* Callers retain the returned identity before borrowing its binding.
|
|
3207
3320
|
* @param opts - target workspace or directory and an optional preallocated id.
|
|
3208
3321
|
* @returns the new session id.
|
|
3209
3322
|
* @throws {SessionCreateError} with the requested id.
|
|
@@ -3215,16 +3328,14 @@ window.__ModuleLoader__.load({
|
|
|
3215
3328
|
return result.value.sessionId;
|
|
3216
3329
|
}
|
|
3217
3330
|
/**
|
|
3218
|
-
* Fork a session from
|
|
3331
|
+
* Fork a session from an exact inclusive prefix of the source (same
|
|
3219
3332
|
* synchronous-addressability guarantee as {@link ClientSessions.create}:
|
|
3220
|
-
* on resolution the child is
|
|
3221
|
-
* @param opts - source session id, the optional
|
|
3222
|
-
*
|
|
3223
|
-
*
|
|
3224
|
-
* and whether to increment an
|
|
3225
|
-
*
|
|
3226
|
-
* interrupted turn carry flow-ordering seqs between two events, and the
|
|
3227
|
-
* wire takes integers only.
|
|
3333
|
+
* on resolution the child is catalogued and may be explicitly retained).
|
|
3334
|
+
* @param opts - source session id, the optional exact inclusive boundary
|
|
3335
|
+
* seq (a real event seq the caller already knows; a cut inside an open
|
|
3336
|
+
* turn is balanced Host-side with synthetic closers, and omission selects
|
|
3337
|
+
* the latest completed-turn prefix), and whether to increment an
|
|
3338
|
+
* inherited durable title before resolving.
|
|
3228
3339
|
* @returns the child session id.
|
|
3229
3340
|
* @throws {SessionForkError} with the source id.
|
|
3230
3341
|
* @throws {Error} when a requested child-title rename fails after creation.
|
|
@@ -3233,37 +3344,34 @@ window.__ModuleLoader__.load({
|
|
|
3233
3344
|
const sourceTitle = opts.increaseTitle ? this.list.getSnapshot().byId[opts.sessionId]?.title : void 0;
|
|
3234
3345
|
const result = await this.manager.fork({
|
|
3235
3346
|
sessionId: opts.sessionId,
|
|
3236
|
-
...opts.atSeq === void 0 ? {} : { atSeq: SessionSeq(
|
|
3347
|
+
...opts.atSeq === void 0 ? {} : { atSeq: SessionSeq(opts.atSeq) }
|
|
3237
3348
|
});
|
|
3238
3349
|
if (!result.ok) throw new SessionForkError(result.error, opts.sessionId);
|
|
3239
3350
|
this.projectList();
|
|
3240
3351
|
const childId = result.value.sessionId;
|
|
3352
|
+
opts.onCreated?.(childId);
|
|
3241
3353
|
if (sourceTitle !== void 0) {
|
|
3242
|
-
const
|
|
3243
|
-
if (child === void 0) throw new Error(`fork child "${childId}" is not locally addressable`);
|
|
3244
|
-
const renamed = await child.rename(increasedForkTitle(sourceTitle));
|
|
3354
|
+
const renamed = await this.manager.rename(childId, increasedForkTitle(sourceTitle));
|
|
3245
3355
|
if (!renamed.ok) throw new Error(`fork child rename failed: ${renamed.error.code}: ${renamed.error.message}`);
|
|
3246
3356
|
}
|
|
3247
3357
|
return childId;
|
|
3248
3358
|
}
|
|
3249
3359
|
/**
|
|
3250
|
-
*
|
|
3360
|
+
* Borrow an already-retained Agent-scoped Context.
|
|
3251
3361
|
* @param id - session id (the agent identity — 1:1 same axis).
|
|
3252
|
-
* @returns scoped
|
|
3362
|
+
* @returns the scoped Context, or undefined without a retained generation.
|
|
3253
3363
|
*/
|
|
3254
3364
|
scope(id) {
|
|
3255
|
-
return this.
|
|
3365
|
+
return this.scopes.get(id)?.ctx;
|
|
3256
3366
|
}
|
|
3257
3367
|
/**
|
|
3258
|
-
*
|
|
3259
|
-
*
|
|
3260
|
-
*
|
|
3261
|
-
* arrival order.
|
|
3262
|
-
* @param id - Host-projected Agent identity (the matching Session id).
|
|
3263
|
-
* @returns the identity-stable Agent Context.
|
|
3368
|
+
* Retain a validated Gateway identity synchronously, without history or catalog I/O.
|
|
3369
|
+
* @param id - Host-projected Session identity, possibly not yet catalogued.
|
|
3370
|
+
* @returns a Gateway-source reference owned by the invocation.
|
|
3264
3371
|
*/
|
|
3265
|
-
|
|
3266
|
-
|
|
3372
|
+
retainAgentScope(id) {
|
|
3373
|
+
if (this.closed) throw new Error("Session Controller is disposed");
|
|
3374
|
+
return this.retainScope(id, "gateway");
|
|
3267
3375
|
}
|
|
3268
3376
|
/**
|
|
3269
3377
|
* Read the Agent scope tag off a context. Service-method boundary: fetch
|
|
@@ -3283,55 +3391,83 @@ window.__ModuleLoader__.load({
|
|
|
3283
3391
|
* `agent.session`). Same service-method boundary as
|
|
3284
3392
|
* {@link ClientSessions.scopeOf}.
|
|
3285
3393
|
* @param ctx - an Agent-scoped context.
|
|
3286
|
-
* @returns the
|
|
3394
|
+
* @returns the matching live Session, or undefined for an untagged or ended generation.
|
|
3287
3395
|
*/
|
|
3288
3396
|
sessionOf(ctx) {
|
|
3289
3397
|
const id = scopeOf(ctx);
|
|
3290
3398
|
if (id === void 0) return void 0;
|
|
3291
|
-
|
|
3399
|
+
const record = this.scopes.get(id);
|
|
3400
|
+
return record !== void 0 && scopeIdentityOf(record.ctx) === scopeIdentityOf(ctx) ? record.binding.session : void 0;
|
|
3292
3401
|
}
|
|
3293
3402
|
/**
|
|
3294
|
-
*
|
|
3295
|
-
*
|
|
3296
|
-
* @
|
|
3297
|
-
* @returns binding, or undefined for a session neither listed nor already scoped.
|
|
3403
|
+
* Borrow an already-retained binding without extending its lifetime.
|
|
3404
|
+
* @param id - Session identity.
|
|
3405
|
+
* @returns the live binding, or undefined without a retained generation.
|
|
3298
3406
|
*/
|
|
3299
3407
|
binding(id) {
|
|
3300
|
-
return this.
|
|
3301
|
-
}
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
record.
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3408
|
+
return this.scopes.get(id)?.binding;
|
|
3409
|
+
}
|
|
3410
|
+
retainScope(id, source) {
|
|
3411
|
+
const record = this.scopes.get(id) ?? this.materializeScope(id);
|
|
3412
|
+
const previous = record.retention;
|
|
3413
|
+
record.retention = Object.freeze({
|
|
3414
|
+
referenceCount: previous.referenceCount + 1,
|
|
3415
|
+
retainedBy: freezeRetainedBy({
|
|
3416
|
+
...previous.retainedBy,
|
|
3417
|
+
[source]: (previous.retainedBy[source] ?? 0) + 1
|
|
3418
|
+
})
|
|
3419
|
+
});
|
|
3420
|
+
const reference = new ClientSessionReference(id, record, () => {
|
|
3421
|
+
if (!record.live) return;
|
|
3422
|
+
const count = record.retention.referenceCount - 1;
|
|
3423
|
+
const { [source]: sourceCount = 0, ...otherSources } = record.retention.retainedBy;
|
|
3424
|
+
const retainedBy = sourceCount > 1 ? {
|
|
3425
|
+
...otherSources,
|
|
3426
|
+
[source]: sourceCount - 1
|
|
3427
|
+
} : otherSources;
|
|
3428
|
+
record.retention = count === 0 ? EMPTY_RETAIN_INFO : Object.freeze({
|
|
3429
|
+
referenceCount: count,
|
|
3430
|
+
retainedBy: freezeRetainedBy(retainedBy)
|
|
3431
|
+
});
|
|
3432
|
+
if (count === 0) this.retireScope(id, record);
|
|
3433
|
+
else this.publishRetention(id);
|
|
3434
|
+
});
|
|
3435
|
+
if (this.list.getSnapshot().byId[id] === void 0 && this.manager.subagentAddress(id) !== void 0) this.projectList();
|
|
3436
|
+
this.publishRetention(id);
|
|
3437
|
+
return reference;
|
|
3438
|
+
}
|
|
3439
|
+
retentionSnapshot(id) {
|
|
3440
|
+
return this.scopes.get(id)?.retention ?? EMPTY_RETAIN_INFO;
|
|
3441
|
+
}
|
|
3442
|
+
publishRetention(id) {
|
|
3443
|
+
const state = this.list.getSnapshot();
|
|
3444
|
+
const row = state.byId[id];
|
|
3445
|
+
const retainedBy = this.retentionSnapshot(id).retainedBy;
|
|
3446
|
+
if (row !== void 0 && row.retainedBy !== retainedBy) this.list.set({
|
|
3447
|
+
...state,
|
|
3448
|
+
byId: {
|
|
3449
|
+
...state.byId,
|
|
3450
|
+
[id]: {
|
|
3451
|
+
...row,
|
|
3452
|
+
retainedBy
|
|
3453
|
+
}
|
|
3454
|
+
}
|
|
3455
|
+
});
|
|
3456
|
+
const observer = this.retainObservers.get(id);
|
|
3457
|
+
const snapshot = this.retentionSnapshot(id);
|
|
3458
|
+
if (observer === void 0 || observer.published === snapshot) return;
|
|
3459
|
+
observer.published = snapshot;
|
|
3460
|
+
(0, _deepseek_ai_dsh_client_store.notifySubscribers)(observer.listeners, "[session-controller] reference sources");
|
|
3461
|
+
}
|
|
3462
|
+
retireScope(id, record, disposeFiber = true) {
|
|
3463
|
+
if (!record.live) return;
|
|
3464
|
+
record.live = false;
|
|
3465
|
+
if (this.scopes.get(id) === record) this.scopes.delete(id);
|
|
3466
|
+
record.session.unbindScope();
|
|
3467
|
+
const sessionDisposal = this.manager.drop(id, record.session);
|
|
3468
|
+
this.projectList();
|
|
3469
|
+
this.publishRetention(id);
|
|
3470
|
+
this.startScopeDrop(id, record, disposeFiber, sessionDisposal);
|
|
3335
3471
|
}
|
|
3336
3472
|
/** Materialize one scope after its caller establishes that the id may be addressed. */
|
|
3337
3473
|
materializeScope(id) {
|
|
@@ -3347,19 +3483,20 @@ window.__ModuleLoader__.load({
|
|
|
3347
3483
|
eventSource: session.eventSource,
|
|
3348
3484
|
ctx
|
|
3349
3485
|
},
|
|
3350
|
-
session
|
|
3486
|
+
session,
|
|
3487
|
+
retention: EMPTY_RETAIN_INFO,
|
|
3488
|
+
live: true
|
|
3351
3489
|
};
|
|
3352
3490
|
this.scopes.set(id, record);
|
|
3491
|
+
ctx.effect(() => () => {
|
|
3492
|
+
this.retireScope(id, record, false);
|
|
3493
|
+
}, "session-controller: exact generation");
|
|
3353
3494
|
return record;
|
|
3354
3495
|
}
|
|
3355
|
-
/** The one aliveness predicate shared by scope mint and prune: host-listed or currently addressed. */
|
|
3356
|
-
eligible(id) {
|
|
3357
|
-
const { ids, current } = this.list.getSnapshot();
|
|
3358
|
-
return current === id || ids.includes(id);
|
|
3359
|
-
}
|
|
3360
3496
|
/** Project the manager's list snapshot into the store (title derivation is display-only). */
|
|
3361
3497
|
projectList() {
|
|
3362
|
-
const
|
|
3498
|
+
const previousById = this.list.getSnapshot().byId;
|
|
3499
|
+
const { items, phase, projectionsBySession } = this.manager.getListSnapshot();
|
|
3363
3500
|
const ids = [];
|
|
3364
3501
|
const byId = {};
|
|
3365
3502
|
for (const entry of items) {
|
|
@@ -3368,7 +3505,7 @@ window.__ModuleLoader__.load({
|
|
|
3368
3505
|
id: entry.sessionId,
|
|
3369
3506
|
displayTitle: displayTitleOf(entry.title, entry.cwd, entry.sessionId),
|
|
3370
3507
|
running: entry.running,
|
|
3371
|
-
|
|
3508
|
+
retainedBy: this.retentionSnapshot(entry.sessionId).retainedBy,
|
|
3372
3509
|
blank: entry.blank,
|
|
3373
3510
|
updatedAt: entry.updatedAt,
|
|
3374
3511
|
...entry.projectionValues === void 0 ? {} : { projectionValues: entry.projectionValues },
|
|
@@ -3378,68 +3515,67 @@ window.__ModuleLoader__.load({
|
|
|
3378
3515
|
...entry.origin !== void 0 ? { origin: entry.origin } : {}
|
|
3379
3516
|
};
|
|
3380
3517
|
}
|
|
3381
|
-
|
|
3382
|
-
const
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3518
|
+
for (const [parentId, projection] of Object.entries(projectionsBySession)) for (const child of projection.values.subagentCatalog ?? []) {
|
|
3519
|
+
const childId = child.id;
|
|
3520
|
+
const summary = byId[childId];
|
|
3521
|
+
const projectionValues = summary?.projectionValues ?? this.manager.projectionValues(childId);
|
|
3522
|
+
const projectedTitle = projectionValues?.title;
|
|
3523
|
+
const title = typeof projectedTitle === "string" && projectedTitle !== "" ? projectedTitle : void 0;
|
|
3524
|
+
const displayTitle = title ?? child.label ?? childId;
|
|
3525
|
+
if (summary === void 0) byId[childId] = {
|
|
3526
|
+
id: childId,
|
|
3527
|
+
displayTitle,
|
|
3528
|
+
parentId,
|
|
3529
|
+
origin: "subagent",
|
|
3530
|
+
running: this.scopes.get(childId)?.session.getSnapshot().running ?? false,
|
|
3531
|
+
blank: false,
|
|
3532
|
+
updatedAt: 0,
|
|
3533
|
+
retainedBy: this.retentionSnapshot(childId).retainedBy,
|
|
3534
|
+
...projectionValues === void 0 ? {} : { projectionValues },
|
|
3535
|
+
...title === void 0 ? {} : { title }
|
|
3536
|
+
};
|
|
3537
|
+
else if (summary.displayTitle !== displayTitle || summary.projectionValues !== projectionValues) byId[childId] = {
|
|
3538
|
+
...summary,
|
|
3539
|
+
displayTitle,
|
|
3540
|
+
...projectionValues === void 0 ? {} : { projectionValues }
|
|
3541
|
+
};
|
|
3542
|
+
}
|
|
3543
|
+
for (const [id, record] of this.scopes) {
|
|
3544
|
+
if (byId[id] !== void 0) continue;
|
|
3545
|
+
const address = this.manager.subagentAddress(id);
|
|
3546
|
+
if (address === void 0) continue;
|
|
3547
|
+
const previous = previousById[id];
|
|
3548
|
+
const snapshot = record.session.getSnapshot();
|
|
3549
|
+
const projectionValues = this.manager.projectionValues(id);
|
|
3550
|
+
const projectedTitle = projectionValues?.title;
|
|
3551
|
+
const title = typeof projectedTitle === "string" && projectedTitle !== "" ? projectedTitle : previous?.title;
|
|
3552
|
+
byId[id] = {
|
|
3553
|
+
...previous ?? {
|
|
3554
|
+
id,
|
|
3555
|
+
displayTitle: id,
|
|
3398
3556
|
updatedAt: 0
|
|
3399
|
-
}
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3557
|
+
},
|
|
3558
|
+
running: snapshot.running,
|
|
3559
|
+
retainedBy: record.retention.retainedBy,
|
|
3560
|
+
blank: snapshot.blank,
|
|
3561
|
+
parentId: address.parentSessionId,
|
|
3562
|
+
origin: "subagent",
|
|
3563
|
+
...projectionValues === void 0 ? {} : { projectionValues },
|
|
3564
|
+
...title === void 0 ? {} : {
|
|
3565
|
+
title,
|
|
3566
|
+
displayTitle: title
|
|
3567
|
+
}
|
|
3568
|
+
};
|
|
3408
3569
|
}
|
|
3409
|
-
const persisted = this.selection.getSnapshot().sessionId;
|
|
3410
|
-
if (current === void 0) {
|
|
3411
|
-
if (persisted !== void 0) this.selection.set({});
|
|
3412
|
-
} else if (byId[current] !== void 0 && (persisted !== current || this.selection.getSnapshot().subagentAddress?.childSessionId !== currentAddress?.childSessionId || this.selection.getSnapshot().subagentAddress?.parentSessionId !== currentAddress?.parentSessionId || this.selection.getSnapshot().subagentAddress?.mode !== currentAddress?.mode)) this.selection.set({
|
|
3413
|
-
sessionId: current,
|
|
3414
|
-
...currentAddress === void 0 ? {} : { subagentAddress: currentAddress }
|
|
3415
|
-
});
|
|
3416
3570
|
this.list.set({
|
|
3417
3571
|
ids,
|
|
3418
3572
|
byId,
|
|
3419
|
-
current,
|
|
3420
3573
|
phase,
|
|
3421
|
-
|
|
3422
|
-
jobsBySession,
|
|
3423
|
-
currentAddress
|
|
3574
|
+
projectionsBySession
|
|
3424
3575
|
});
|
|
3425
|
-
this.pruneScopes();
|
|
3426
|
-
}
|
|
3427
|
-
/** Tear down scope + instance for no-longer-eligible sessions off stage; the staged one defers until the stage moves. */
|
|
3428
|
-
pruneScopes() {
|
|
3429
|
-
if (this.list.getSnapshot().phase === "pending") return;
|
|
3430
|
-
for (const [id, record] of this.scopes) {
|
|
3431
|
-
if (this.eligible(id)) continue;
|
|
3432
|
-
if (id === this.watched) {
|
|
3433
|
-
this.deferredRemovals.add(id);
|
|
3434
|
-
continue;
|
|
3435
|
-
}
|
|
3436
|
-
this.scopes.delete(id);
|
|
3437
|
-
this.deferredRemovals.delete(id);
|
|
3438
|
-
this.startScopeDrop(id, record);
|
|
3439
|
-
}
|
|
3440
3576
|
}
|
|
3441
|
-
startScopeDrop(id, record) {
|
|
3442
|
-
const drop = this.dropScope(
|
|
3577
|
+
startScopeDrop(id, record, disposeFiber = true, sessionDisposal = this.manager.drop(id, record.session)) {
|
|
3578
|
+
const drop = this.dropScope(record, disposeFiber, sessionDisposal);
|
|
3443
3579
|
this.scopeDrops.add(drop);
|
|
3444
3580
|
drop.then(() => {
|
|
3445
3581
|
this.scopeDrops.delete(drop);
|
|
@@ -3450,38 +3586,9 @@ window.__ModuleLoader__.load({
|
|
|
3450
3586
|
async drainScopeDrops() {
|
|
3451
3587
|
while (this.scopeDrops.size > 0) await Promise.allSettled([...this.scopeDrops]);
|
|
3452
3588
|
}
|
|
3453
|
-
/**
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
* controller, popup, plugin stores, listeners), the session-keyed slot
|
|
3457
|
-
* registrations and the Session instance itself — the host session log is the
|
|
3458
|
-
* durable truth, a reopen lazily rebuilds and backfills via open().
|
|
3459
|
-
*/
|
|
3460
|
-
async dropScope(id, record) {
|
|
3461
|
-
record.session.unbindScope();
|
|
3462
|
-
await Promise.allSettled([record.fiber.dispose(), this.manager.drop(id)]);
|
|
3463
|
-
}
|
|
3464
|
-
/** Run deferred teardowns whose session is no longer staged (called when the stage moves). */
|
|
3465
|
-
sweepDeferred() {
|
|
3466
|
-
for (const id of [...this.deferredRemovals]) {
|
|
3467
|
-
/* v8 ignore next -- defensive: only the staged id ever defers, and every
|
|
3468
|
-
* stage move sweeps first, so the set cannot contain the id the stage just
|
|
3469
|
-
* moved to; kept as a guard against future extra sweep call sites. */
|
|
3470
|
-
if (id === this.watched) continue;
|
|
3471
|
-
if (this.eligible(id)) {
|
|
3472
|
-
this.deferredRemovals.delete(id);
|
|
3473
|
-
continue;
|
|
3474
|
-
}
|
|
3475
|
-
const record = this.scopes.get(id);
|
|
3476
|
-
this.deferredRemovals.delete(id);
|
|
3477
|
-
/* v8 ignore next -- defensive: prune deletes a scope and its deferral
|
|
3478
|
-
* together, so a deferred id always still owns its record; kept so a
|
|
3479
|
-
* future teardown path cannot double-dispose. */
|
|
3480
|
-
if (record !== void 0) {
|
|
3481
|
-
this.scopes.delete(id);
|
|
3482
|
-
this.startScopeDrop(id, record);
|
|
3483
|
-
}
|
|
3484
|
-
}
|
|
3589
|
+
/** Await the already-withdrawn Session and scoped cleanup to quiescence. */
|
|
3590
|
+
async dropScope(record, disposeFiber, sessionDisposal) {
|
|
3591
|
+
await Promise.allSettled([sessionDisposal, ...disposeFiber ? [record.fiber.dispose()] : []]);
|
|
3485
3592
|
}
|
|
3486
3593
|
};
|
|
3487
3594
|
//#endregion
|
|
@@ -3503,6 +3610,7 @@ window.__ModuleLoader__.load({
|
|
|
3503
3610
|
*/
|
|
3504
3611
|
function apply(ctx) {
|
|
3505
3612
|
const remotes = ctx.remote;
|
|
3613
|
+
const connection = ctx.get("connection");
|
|
3506
3614
|
const sessions = new ClientSessions(ctx, remotes);
|
|
3507
3615
|
ctx.remote.$on("api-session/added", (summary) => {
|
|
3508
3616
|
sessions.handleSessionAdded(summary);
|
|
@@ -3527,14 +3635,22 @@ window.__ModuleLoader__.load({
|
|
|
3527
3635
|
console.error("[session-controller] control stream failed:", error);
|
|
3528
3636
|
}
|
|
3529
3637
|
});
|
|
3530
|
-
|
|
3531
|
-
|
|
3638
|
+
const connected = () => {
|
|
3639
|
+
if (connection.generation.getSnapshot() === void 0) return;
|
|
3532
3640
|
sessions.handleConnected();
|
|
3533
|
-
|
|
3534
|
-
|
|
3641
|
+
control.restart();
|
|
3642
|
+
control.start();
|
|
3643
|
+
};
|
|
3644
|
+
ctx.effect(() => connection.generation.subscribe(connected), "session-controller.client.generation");
|
|
3645
|
+
connected();
|
|
3535
3646
|
ctx.typert.contexts.registerClient("agent", {
|
|
3536
|
-
identity: (candidate) => sessions.
|
|
3537
|
-
resolve: (sessionId) =>
|
|
3647
|
+
identity: (candidate) => sessions.sessionOf(candidate)?.sessionId,
|
|
3648
|
+
resolve: (sessionId) => {
|
|
3649
|
+
const reference = sessions.retainAgentScope(sessionId);
|
|
3650
|
+
return typertOwnedValue(reference.binding.ctx, () => {
|
|
3651
|
+
reference.release();
|
|
3652
|
+
});
|
|
3653
|
+
}
|
|
3538
3654
|
});
|
|
3539
3655
|
ctx.effect(() => async () => {
|
|
3540
3656
|
await control.dispose();
|