@xmoon76/dsh-pi-tui 0.5.3 → 0.5.5
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.en.md +195 -150
- package/README.md +137 -103
- package/cordis.patch.yml +54 -2
- package/dist/application-runtime-CbBO4bY-.mjs +6860 -0
- package/dist/bootstrap-DLOydLLj.mjs +108410 -0
- package/dist/builtins.mjs +2 -3
- package/dist/client-bootstrap-DwSFzcTW.mjs +872 -0
- package/dist/context-summary-Bz0AGXa1.mjs +12027 -0
- package/dist/context-summary-D9mhxPXL.mjs +10015 -0
- package/dist/custom-items-CKrOBCox.mjs +655 -0
- package/dist/disposal-BYBbEpVY.mjs +54 -0
- package/dist/dispose-cause-BzcXo4hu.mjs +123 -0
- package/dist/dispose-cause-CNFuUnjR.mjs +24 -0
- package/dist/dist-C7QMk0ws.mjs +15431 -0
- package/dist/entry-control-DnduyDiw.mjs +92 -0
- package/dist/extension/advanced.d.mts +1 -1
- package/dist/extension/unstable.d.mts +1 -1
- package/dist/{extensions-DzpBiiYb.d.mts → extensions-Bte3XOt5.d.mts} +1 -1
- package/dist/{extensions-a-rxanjw.mjs → extensions-pcFiH7Qe.mjs} +1498 -410
- package/dist/extensions.d.mts +2 -2
- package/dist/extensions.mjs +1 -1
- package/dist/host-bootstrap-CKdfLkNS.mjs +188 -0
- package/dist/host-foundation-probe-CYHsbAw6.mjs +143 -0
- package/dist/host-prerequisites-9JBTtVNu.mjs +36 -0
- package/dist/host-runtime.d.mts +26 -0
- package/dist/host-runtime.mjs +450 -0
- package/dist/index.d.mts +9 -2
- package/dist/index.mjs +45779 -24480
- package/dist/local-client.mjs +1816 -0
- package/dist/local-discovery-CXnLT4GF.mjs +755 -0
- package/dist/local-discovery-DVFFpfBG.mjs +2 -0
- package/dist/local-host.mjs +1025 -0
- package/dist/local-transport-C9aonplC.mjs +513 -0
- package/dist/performance-host.d.mts +2 -2
- package/dist/performance-host.mjs +258 -1
- package/dist/{performance-view-jvvd8Jn7.mjs → performance-view-CfGvLZyD.mjs} +1 -1
- package/dist/pi-tui-remote-contribution-DRk6Tl3J.mjs +78 -0
- package/dist/pi-tui-terminal-progress-contract-CdBH9j78.mjs +70 -0
- package/dist/pi-tui-terminal-progress-contract-XTQKj-WW.mjs +905 -0
- package/dist/{public-types-gZi3iFNh.d.mts → public-types-Dgf1bDke.d.mts} +3 -3
- package/dist/{runtime-BtPH-UUb.mjs → runtime-Bh5OsftD.mjs} +1311 -1024
- package/dist/runtime-C5ROZqFj.mjs +2 -0
- package/dist/runtime-status-0lp9CM0V.mjs +1923 -0
- package/dist/session-4keoXjk0.mjs +10869 -0
- package/dist/session-B2zqv4wr.mjs +10869 -0
- package/dist/{startup-D5Xu8diR.mjs → startup-Ct2UUjUL.mjs} +55 -13
- package/dist/startup.d.mts +2 -1
- package/dist/startup.mjs +1 -1
- package/dist/terminal-progress-source-BhufrZ74.mjs +6000 -0
- package/dist/terminal-progress-source-CsBinCJ_.mjs +965 -0
- package/dist/visual-tools.d.mts +62 -0
- package/dist/visual-tools.mjs +556 -0
- package/generated/dsh-presets/README.md +1 -1
- package/package.json +145 -117
- package/dist/context-summary-CxUpNkA9.mjs +0 -2951
- package/dist/performance-host-BJT6scGF.mjs +0 -266
- package/dist/rolldown-runtime-8H4AJuhK.mjs +0 -14
- package/dist/session-BZLxhrPQ.mjs +0 -5697
- package/dist/terminal-progress-source-BlmksrSD.mjs +0 -2200
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import { n as
|
|
2
|
-
import { n as
|
|
3
|
-
import {
|
|
4
|
-
import { a as
|
|
1
|
+
import { a as PI_TUI_EXTENSIONS_SERVICE, n as extensions_exports } from "./extensions-pcFiH7Qe.mjs";
|
|
2
|
+
import { n as TUI_STARTUP_SERVICE } from "./startup-Ct2UUjUL.mjs";
|
|
3
|
+
import { C as safeErrorMessage, d as parseFooterCustomItems, g as resolveUserLayerFooterMode, h as resolveUserCommandItemFallbackActivationIds, m as resolveUserCommandItemActivationIds, p as resolveTrustedFooterCommand, v as cancellationError, y as isCancellation } from "./custom-items-CKrOBCox.mjs";
|
|
4
|
+
import { C as deliveredFileReadErrorFrom, F as providerOptionsFor, I as providerProfileProjectionOf, L as SupersededReadError, P as getPath, R as contextPressureOccupancy, S as DeliveredFileReadError, T as clientOwnerOf, a as detachInspection, c as detachPluginManagerSnapshot, f as QuestionAnswerError, g as classifySubagentPromptSettlement, h as detachedTurnOutline, i as detachChange, l as pluginInstallRequestId, m as detachedSessionStatus, n as createRemoteTerminalProgressSource, o as detachLog, r as PluginManagerStaleResultError, s as detachPhase, v as GATEWAY_PRE_INVOCATION_CODES, x as REMOTE_IMPLEMENTED_CAPABILITIES, y as isRemoteBusinessRefusalCode } from "./terminal-progress-source-CsBinCJ_.mjs";
|
|
5
5
|
import { t as builtins_exports } from "./builtins.mjs";
|
|
6
|
-
import {
|
|
6
|
+
import { n as PI_TUI_CLIENT_CONTRIBUTION, t as mergeCause } from "./dispose-cause-BzcXo4hu.mjs";
|
|
7
7
|
import { createRequire } from "node:module";
|
|
8
|
+
import { realpathSync } from "node:fs";
|
|
8
9
|
import { randomUUID } from "node:crypto";
|
|
10
|
+
import { pathToFileURL } from "node:url";
|
|
9
11
|
import { Context } from "@deepseek-ai/cordis";
|
|
10
12
|
import * as sessionLogExport from "@deepseek-ai/dsh-session-log-export";
|
|
13
|
+
import * as clientStore from "@deepseek-ai/dsh-client-store";
|
|
11
14
|
import commandsRemote from "@deepseek-ai/dsh-commands/remote";
|
|
12
15
|
import subagentsRemote from "@deepseek-ai/dsh-subagent/remote";
|
|
13
16
|
import agentPresetsRemote from "@deepseek-ai/dsh-agent-preset-registry/remote";
|
|
@@ -19,6 +22,7 @@ import jobRemote from "@deepseek-ai/dsh-api-job-controller/remote";
|
|
|
19
22
|
import settingsRemote from "@deepseek-ai/dsh-api-settings-controller/remote";
|
|
20
23
|
import userQuestionsRemote from "@deepseek-ai/dsh-user-questions/remote";
|
|
21
24
|
import fileUploadsRemote from "@deepseek-ai/dsh-client-file-upload/remote";
|
|
25
|
+
import workspaceFilesRemote from "@deepseek-ai/dsh-api-workspace-files/remote";
|
|
22
26
|
import SessionController from "@deepseek-ai/dsh-api-session-controller";
|
|
23
27
|
import { apply, inject } from "@deepseek-ai/dsh-api-remotes";
|
|
24
28
|
import SettingsController from "@deepseek-ai/dsh-api-settings-controller";
|
|
@@ -26,7 +30,6 @@ import { HostConnectionService } from "@deepseek-ai/dsh-client-connection";
|
|
|
26
30
|
import FileUploads from "@deepseek-ai/dsh-client-file-upload";
|
|
27
31
|
import * as sessionStats from "@deepseek-ai/dsh-session-stats";
|
|
28
32
|
import * as sessionTurnOutline from "@deepseek-ai/dsh-session-turn-outline";
|
|
29
|
-
import { TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
|
|
30
33
|
//#region src/runtime/remote/write-failure.ts
|
|
31
34
|
/**
|
|
32
35
|
* Remote write settlement classification (D2.2): map one official Client
|
|
@@ -171,7 +174,7 @@ function remoteNotDispatched() {
|
|
|
171
174
|
* semantic contract as `src/runtime/direct/config-direct.ts`; no Remote-only
|
|
172
175
|
* Config semantics and no Direct fallback exist.
|
|
173
176
|
*
|
|
174
|
-
* Published mapping (see docs/client
|
|
177
|
+
* Published mapping (see docs/architecture/host-client.md):
|
|
175
178
|
*
|
|
176
179
|
* ```text
|
|
177
180
|
* TUI settings / footer trust / custom items / providers / permissions /
|
|
@@ -213,6 +216,7 @@ const PROVIDER_SETTINGS_NS = "llm-pi-ai";
|
|
|
213
216
|
const PERMISSION_SETTINGS_NS = "permission";
|
|
214
217
|
const PRESET_REGISTRY_NS = "agent-preset-registry";
|
|
215
218
|
const SUBAGENT_SETTINGS_NS = "subagent-model-selection-settings";
|
|
219
|
+
const VISUAL_TOOLS_NS = "pi-tui-visual-tools";
|
|
216
220
|
/** The provider route grammar the adapter-owned profile-slot rule enforces
|
|
217
221
|
* (same rule the Direct adapter applies). */
|
|
218
222
|
const PROVIDER_ROUTE_PATTERN = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
@@ -252,20 +256,6 @@ function detachedValue(value) {
|
|
|
252
256
|
return;
|
|
253
257
|
}
|
|
254
258
|
}
|
|
255
|
-
/** Read the `llm-pi-ai` section's `providers` dict detached (the settings-only
|
|
256
|
-
* fallback the Direct adapter applies when the directory is unavailable). */
|
|
257
|
-
function piAiProvidersOf(section) {
|
|
258
|
-
const record = plainRecord(section);
|
|
259
|
-
if (record === void 0) return void 0;
|
|
260
|
-
const providers = plainRecord(record.providers);
|
|
261
|
-
if (providers === void 0) return void 0;
|
|
262
|
-
const out = {};
|
|
263
|
-
for (const [route, profile] of Object.entries(providers)) {
|
|
264
|
-
const entry = plainRecord(profile);
|
|
265
|
-
out[route] = entry === void 0 ? profile : { ...typeof entry.apiKeyEnv === "string" ? { apiKeyEnv: entry.apiKeyEnv } : {} };
|
|
266
|
-
}
|
|
267
|
-
return out;
|
|
268
|
-
}
|
|
269
259
|
/** Bounded re-describe attempts when an invalidation races a read. 5 is
|
|
270
260
|
* enough for a document/adapter/catalog event burst; a persistent storm
|
|
271
261
|
* fails loudly (SupersededReadError) instead of committing a stale result. */
|
|
@@ -300,7 +290,33 @@ function copyProviderEntry(entry) {
|
|
|
300
290
|
* Invalidations only bump the counter (the snapshot stays readable as the
|
|
301
291
|
* last-known display value); no unowned background promise is started.
|
|
302
292
|
*/
|
|
293
|
+
/**
|
|
294
|
+
* The ONE accepted-write lifetime counter of the Remote configuration port.
|
|
295
|
+
* Every write sink (the settings mirror's `mutate` and the credential
|
|
296
|
+
* reference writes) brackets its accepted work; the Client reload safety gate
|
|
297
|
+
* reads the count so it can never retire the Client while a persisted
|
|
298
|
+
* configuration write is still in flight. Read-only calls never register.
|
|
299
|
+
*/
|
|
300
|
+
var RemoteConfigWriteLifetime = class {
|
|
301
|
+
pending = 0;
|
|
302
|
+
/** Register one accepted write; the returned release is idempotent. */
|
|
303
|
+
begin() {
|
|
304
|
+
this.pending += 1;
|
|
305
|
+
let released = false;
|
|
306
|
+
return () => {
|
|
307
|
+
if (released) return;
|
|
308
|
+
released = true;
|
|
309
|
+
this.pending -= 1;
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
hasUnsettledWrites() {
|
|
313
|
+
return this.pending > 0;
|
|
314
|
+
}
|
|
315
|
+
};
|
|
303
316
|
var RemoteConfigMirror = class {
|
|
317
|
+
/** The accepted-write lifetime owner (the serialized chain below is
|
|
318
|
+
* `writes`, its internal queue). */
|
|
319
|
+
writeLifetime;
|
|
304
320
|
settings;
|
|
305
321
|
llm;
|
|
306
322
|
permissionPresets;
|
|
@@ -323,7 +339,8 @@ var RemoteConfigMirror = class {
|
|
|
323
339
|
* synchronously-notified generation subscription cannot start a read
|
|
324
340
|
* before construction finishes. */
|
|
325
341
|
constructed = false;
|
|
326
|
-
constructor(source, on) {
|
|
342
|
+
constructor(source, on, writeLifetime) {
|
|
343
|
+
this.writeLifetime = writeLifetime;
|
|
327
344
|
this.settings = source.remote.settings;
|
|
328
345
|
this.llm = source.remote.llm;
|
|
329
346
|
this.permissionPresets = source.remote.permissionPresets;
|
|
@@ -405,6 +422,11 @@ var RemoteConfigMirror = class {
|
|
|
405
422
|
providers() {
|
|
406
423
|
return this.snapshot?.providers;
|
|
407
424
|
}
|
|
425
|
+
/** The provider-directory read failure of the last committed snapshot, if
|
|
426
|
+
* the directory read failed. */
|
|
427
|
+
providersFailure() {
|
|
428
|
+
return this.snapshot?.providersFailure;
|
|
429
|
+
}
|
|
408
430
|
permissionPresetNames() {
|
|
409
431
|
return this.snapshot?.permissionPresetNames ?? [];
|
|
410
432
|
}
|
|
@@ -486,7 +508,8 @@ var RemoteConfigMirror = class {
|
|
|
486
508
|
invalidation,
|
|
487
509
|
namespaces,
|
|
488
510
|
settingsFailure,
|
|
489
|
-
providers: providersResult.ok && Array.isArray(providersResult.value) ? providersResult.value.map(copyProviderEntry) :
|
|
511
|
+
providers: providersResult.ok && Array.isArray(providersResult.value) ? providersResult.value.map(copyProviderEntry) : this.snapshot?.providers,
|
|
512
|
+
providersFailure: providersResult.ok ? void 0 : remoteFailureMessage(providersResult.error),
|
|
490
513
|
permissionPresetNames: catalogResult.ok && Array.isArray(catalogResult.value?.options) ? catalogResult.value.options.flatMap((option) => typeof option?.value === "string" ? [option.value] : []) : [],
|
|
491
514
|
permissionDefaultPreset: catalogResult.ok && typeof catalogResult.value?.defaultPreset === "string" ? catalogResult.value.defaultPreset : void 0,
|
|
492
515
|
presetRosterDefault: presetsResult.ok && Array.isArray(presetsResult.value?.presets) ? presetsResult.value.presets.find((preset) => preset.isDefault === true)?.id : void 0
|
|
@@ -525,36 +548,41 @@ var RemoteConfigMirror = class {
|
|
|
525
548
|
* authority itself and reports accepted-but-unverified instead of a refusal.
|
|
526
549
|
*/
|
|
527
550
|
async mutate(ns, ops, baseRevision, refreshFailure = "reject") {
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
this.
|
|
551
|
+
const endWrite = this.writeLifetime.begin();
|
|
552
|
+
try {
|
|
553
|
+
await this.enqueueWrite(async () => {
|
|
554
|
+
await this.ensureCurrent();
|
|
555
|
+
const snapshot = this.lastKnown();
|
|
556
|
+
if (snapshot === void 0 || !this.isCurrent()) {
|
|
557
|
+
if (snapshot?.settingsFailure instanceof Error) throw new Error(`settings.describe failed: ${snapshot.settingsFailure.message}`);
|
|
558
|
+
throw new Error(this.generation.getSnapshot() === void 0 ? "the Remote configuration is unavailable on this connection; the change was not saved" : snapshot === void 0 ? "the Remote configuration has not been read yet; the change was not saved" : "the Remote configuration is not current; the change was not saved");
|
|
559
|
+
}
|
|
560
|
+
if (ops.length === 0) return;
|
|
561
|
+
const descriptor = snapshot.namespaces?.get(ns);
|
|
562
|
+
if (descriptor === void 0) throw new Error(`settings namespace "${ns}" is not available in this deployment`);
|
|
563
|
+
const result = await settledResult(this.settings.mutate(ns, [...ops], baseRevision ?? descriptor.revision));
|
|
564
|
+
if (!result.ok) {
|
|
565
|
+
this.invalidate();
|
|
566
|
+
try {
|
|
567
|
+
await this.describe();
|
|
568
|
+
} catch (error) {
|
|
569
|
+
this.recordFailure(error);
|
|
570
|
+
}
|
|
571
|
+
throw new Error(`settings.mutate(${ns}) failed: ${remoteFailureMessage(result.error)}`);
|
|
572
|
+
}
|
|
573
|
+
if (refreshFailure === "reject") {
|
|
574
|
+
await this.describe();
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
541
577
|
try {
|
|
542
578
|
await this.describe();
|
|
543
579
|
} catch (error) {
|
|
544
580
|
this.recordFailure(error);
|
|
545
581
|
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
return;
|
|
551
|
-
}
|
|
552
|
-
try {
|
|
553
|
-
await this.describe();
|
|
554
|
-
} catch (error) {
|
|
555
|
-
this.recordFailure(error);
|
|
556
|
-
}
|
|
557
|
-
});
|
|
582
|
+
});
|
|
583
|
+
} finally {
|
|
584
|
+
endWrite();
|
|
585
|
+
}
|
|
558
586
|
}
|
|
559
587
|
/** Drop the cached snapshot (and any in-flight read's publication right). */
|
|
560
588
|
disposeCache() {
|
|
@@ -805,28 +833,122 @@ var RemoteProviderProfileConfig = class {
|
|
|
805
833
|
* over its per-entry sections when present, the settings-only fallback
|
|
806
834
|
* otherwise (the same merge the Direct adapter wires). */
|
|
807
835
|
listCredentialOptions() {
|
|
836
|
+
if (this.mirror.providersFailure() !== void 0 || this.mirror.readiness() !== "ready") return providerOptionsFor([], () => void 0).map((option) => remoteCredentialOptionOf(option));
|
|
808
837
|
const directory = this.mirror.providers();
|
|
809
|
-
if (directory !== void 0) return providerOptionsFor(directory, (
|
|
810
|
-
return
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
838
|
+
if (directory !== void 0) return providerOptionsFor(directory, (entry) => providerProfileProjectionOf(this.remoteProfileOf(entry))).map((option) => remoteCredentialOptionOf(option));
|
|
839
|
+
return this.settingsOnlyCatalog().options;
|
|
840
|
+
}
|
|
841
|
+
/**
|
|
842
|
+
* The ONE provider snapshot the Models page reads. The Remote mirror is
|
|
843
|
+
* already ONE committed snapshot (one settings describe + one directory
|
|
844
|
+
* read per generation), so the projection reads the mirror and never
|
|
845
|
+
* dispatches a second wire fetch. A directory the mirror could not read
|
|
846
|
+
* degrades to the settings-only fallback (the same fail-soft rule the
|
|
847
|
+
* Direct adapter applies).
|
|
848
|
+
*/
|
|
849
|
+
readCatalog() {
|
|
850
|
+
const directory = this.mirror.providers();
|
|
851
|
+
const failure = this.mirror.providersFailure();
|
|
852
|
+
if (failure !== void 0) return {
|
|
853
|
+
options: [],
|
|
854
|
+
profiles: [],
|
|
855
|
+
failure: `the provider directory could not be read: ${failure}`
|
|
856
|
+
};
|
|
857
|
+
if (directory === void 0) return this.settingsOnlyCatalog();
|
|
858
|
+
const rawProfiles = /* @__PURE__ */ new Map();
|
|
859
|
+
for (const entry of directory) {
|
|
860
|
+
if (entry.provider.length === 0 || entry.settingsNs.length === 0) continue;
|
|
861
|
+
rawProfiles.set(entry.provider, this.remoteProfileOf(entry));
|
|
862
|
+
}
|
|
863
|
+
const options = providerOptionsFor(directory, (entry) => providerProfileProjectionOf(this.remoteProfileOf(entry))).map((option) => remoteCredentialOptionOf(option));
|
|
864
|
+
const profiles = options.map((option) => {
|
|
865
|
+
const raw = rawProfiles.get(option.route);
|
|
866
|
+
if (option.route === "deepseek-official" && raw === void 0) return {
|
|
867
|
+
route: option.route,
|
|
815
868
|
configured: true,
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
group: "configured",
|
|
819
|
-
canProvisionProfile: canProvisionKeylessProfile(PROVIDER_SETTINGS_NS, ["providers", route], route)
|
|
869
|
+
displayName: option.label,
|
|
870
|
+
models: []
|
|
820
871
|
};
|
|
872
|
+
return remoteProviderFactsOf(option.route, option.label, raw);
|
|
821
873
|
});
|
|
874
|
+
const readiness = this.mirror.readiness();
|
|
875
|
+
if (readiness === "unavailable") return {
|
|
876
|
+
options: [],
|
|
877
|
+
profiles: [],
|
|
878
|
+
failure: "the configuration mirror is unavailable"
|
|
879
|
+
};
|
|
880
|
+
if (readiness === "stale") return {
|
|
881
|
+
options,
|
|
882
|
+
profiles,
|
|
883
|
+
stale: true
|
|
884
|
+
};
|
|
885
|
+
return {
|
|
886
|
+
options,
|
|
887
|
+
profiles
|
|
888
|
+
};
|
|
889
|
+
}
|
|
890
|
+
/**
|
|
891
|
+
* The settings-only fallback (no mirrored directory): the conventional
|
|
892
|
+
* llm-pi-ai `providers` slot is the only profile location. Every profile
|
|
893
|
+
* route stays a provider — a keyless profile is still a CONFIGURED
|
|
894
|
+
* provider; the presence of a key is not the membership authority.
|
|
895
|
+
*/
|
|
896
|
+
settingsOnlyCatalog() {
|
|
897
|
+
const section = this.mirror.namespace(PROVIDER_SETTINGS_NS)?.value;
|
|
898
|
+
const declared = plainRecord(plainRecord(section)?.providers);
|
|
899
|
+
const entries = declared === void 0 ? [] : Object.keys(declared).map((route) => ({
|
|
900
|
+
provider: route,
|
|
901
|
+
displayName: route,
|
|
902
|
+
settingsNs: PROVIDER_SETTINGS_NS,
|
|
903
|
+
settingsPath: ["providers", route]
|
|
904
|
+
}));
|
|
905
|
+
const options = providerOptionsFor(entries, (entry) => providerProfileProjectionOf(declared?.[entry.provider])).map((option) => remoteCredentialOptionOf(option));
|
|
906
|
+
return {
|
|
907
|
+
options,
|
|
908
|
+
profiles: options.map((option) => {
|
|
909
|
+
const raw = declared?.[option.route];
|
|
910
|
+
if (option.route === "deepseek-official" && raw === void 0) return {
|
|
911
|
+
route: option.route,
|
|
912
|
+
configured: true,
|
|
913
|
+
displayName: option.label,
|
|
914
|
+
models: []
|
|
915
|
+
};
|
|
916
|
+
return remoteProviderFactsOf(option.route, option.label, raw);
|
|
917
|
+
})
|
|
918
|
+
};
|
|
919
|
+
}
|
|
920
|
+
/** One directory entry's profile value, read from the mirror's ONE
|
|
921
|
+
* committed snapshot (no wire dispatch). */
|
|
922
|
+
remoteProfileOf(entry) {
|
|
923
|
+
const section = this.mirror.namespace(entry.settingsNs)?.value;
|
|
924
|
+
return entry.settingsPath.length === 0 ? section : getPath(section, entry.settingsPath);
|
|
925
|
+
}
|
|
926
|
+
readProfile(route) {
|
|
927
|
+
const directory = this.mirror.providers();
|
|
928
|
+
if (directory !== void 0) {
|
|
929
|
+
const entry = directory.find((candidate) => candidate.provider === route);
|
|
930
|
+
if (entry !== void 0) {
|
|
931
|
+
const section = this.mirror.namespace(entry.settingsNs)?.value;
|
|
932
|
+
const profile = entry.settingsPath.length === 0 ? section : getPath(section, entry.settingsPath);
|
|
933
|
+
return remoteProviderFactsOf(route, entry.displayName, profile);
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
const section = this.mirror.namespace(PROVIDER_SETTINGS_NS)?.value;
|
|
937
|
+
return remoteProviderFactsOf(route, route, section?.providers?.[route]);
|
|
938
|
+
}
|
|
939
|
+
configGuide() {
|
|
940
|
+
return {};
|
|
822
941
|
}
|
|
823
942
|
async writeProfile(route, profile) {
|
|
824
943
|
if (!canProvisionKeylessProfile(PROVIDER_SETTINGS_NS, ["providers", route], route)) throw new Error("invalid provider route");
|
|
944
|
+
await this.mirror.ensureCurrent();
|
|
945
|
+
const descriptor = this.mirror.namespace(PROVIDER_SETTINGS_NS);
|
|
946
|
+
if (getPath(descriptor?.value, ["providers", route]) !== void 0) throw new Error(`provider route "${route}" already exists`);
|
|
825
947
|
await this.mirror.mutate(PROVIDER_SETTINGS_NS, [{
|
|
826
948
|
op: "set",
|
|
827
949
|
path: ["providers", route],
|
|
828
950
|
value: profile
|
|
829
|
-
}]);
|
|
951
|
+
}], descriptor?.revision);
|
|
830
952
|
}
|
|
831
953
|
async writeKeylessProfile(route) {
|
|
832
954
|
if (route === "deepseek-official") return {
|
|
@@ -837,11 +959,16 @@ var RemoteProviderProfileConfig = class {
|
|
|
837
959
|
await this.mirror.ensureCurrent();
|
|
838
960
|
const directory = this.mirror.providers();
|
|
839
961
|
if (directory === void 0) {
|
|
962
|
+
const descriptor = this.mirror.namespace(PROVIDER_SETTINGS_NS);
|
|
963
|
+
if (getPath(descriptor?.value, ["providers", route]) !== void 0) return {
|
|
964
|
+
kind: "skipped",
|
|
965
|
+
reason: `provider route "${route}" already has a profile`
|
|
966
|
+
};
|
|
840
967
|
await this.mirror.mutate(PROVIDER_SETTINGS_NS, [{
|
|
841
968
|
op: "set",
|
|
842
969
|
path: ["providers", route],
|
|
843
970
|
value: {}
|
|
844
|
-
}]);
|
|
971
|
+
}], descriptor?.revision);
|
|
845
972
|
return { kind: "written" };
|
|
846
973
|
}
|
|
847
974
|
const entry = directory.find((candidate) => candidate.provider === route);
|
|
@@ -854,11 +981,16 @@ var RemoteProviderProfileConfig = class {
|
|
|
854
981
|
kind: "skipped",
|
|
855
982
|
reason: `hostile or malformed directory entry for ${route}`
|
|
856
983
|
};
|
|
984
|
+
const descriptor = this.mirror.namespace(entry.settingsNs);
|
|
985
|
+
if (getPath(descriptor?.value, path) !== void 0) return {
|
|
986
|
+
kind: "skipped",
|
|
987
|
+
reason: `provider route "${route}" already has a profile`
|
|
988
|
+
};
|
|
857
989
|
await this.mirror.mutate(entry.settingsNs, [{
|
|
858
990
|
op: "set",
|
|
859
991
|
path,
|
|
860
992
|
value: {}
|
|
861
|
-
}]);
|
|
993
|
+
}], descriptor?.revision);
|
|
862
994
|
return { kind: "written" };
|
|
863
995
|
}
|
|
864
996
|
};
|
|
@@ -866,12 +998,14 @@ var RemoteCredentialConfig = class {
|
|
|
866
998
|
credentials;
|
|
867
999
|
generation;
|
|
868
1000
|
on;
|
|
1001
|
+
writeLifetime;
|
|
869
1002
|
/** Every active listener subscription, so dispose() releases them once. */
|
|
870
1003
|
active = /* @__PURE__ */ new Set();
|
|
871
|
-
constructor(credentials, on, generation) {
|
|
1004
|
+
constructor(credentials, on, generation, writeLifetime) {
|
|
872
1005
|
this.credentials = credentials;
|
|
873
1006
|
this.on = on;
|
|
874
1007
|
this.generation = generation;
|
|
1008
|
+
this.writeLifetime = writeLifetime;
|
|
875
1009
|
}
|
|
876
1010
|
available() {
|
|
877
1011
|
return this.generation.getSnapshot() !== void 0;
|
|
@@ -901,13 +1035,23 @@ var RemoteCredentialConfig = class {
|
|
|
901
1035
|
}
|
|
902
1036
|
async setReference(ref, secret) {
|
|
903
1037
|
this.requireDispatchableGeneration();
|
|
904
|
-
const
|
|
905
|
-
|
|
1038
|
+
const endWrite = this.writeLifetime.begin();
|
|
1039
|
+
try {
|
|
1040
|
+
const result = await settledResult(this.credentials.set(ref, secret));
|
|
1041
|
+
if (!result.ok) throw new Error(`credentials.set(${ref}) failed: ${remoteFailureMessage(result.error)}`);
|
|
1042
|
+
} finally {
|
|
1043
|
+
endWrite();
|
|
1044
|
+
}
|
|
906
1045
|
}
|
|
907
1046
|
async unsetReference(ref) {
|
|
908
1047
|
this.requireDispatchableGeneration();
|
|
909
|
-
const
|
|
910
|
-
|
|
1048
|
+
const endWrite = this.writeLifetime.begin();
|
|
1049
|
+
try {
|
|
1050
|
+
const result = await settledResult(this.credentials.unset(ref));
|
|
1051
|
+
if (!result.ok) throw new Error(`credentials.unset(${ref}) failed: ${remoteFailureMessage(result.error)}`);
|
|
1052
|
+
} finally {
|
|
1053
|
+
endWrite();
|
|
1054
|
+
}
|
|
911
1055
|
}
|
|
912
1056
|
async describeReference(ref) {
|
|
913
1057
|
const captured = this.generation.getSnapshot();
|
|
@@ -1107,6 +1251,46 @@ function assertOfficialSubagentRoutes(routes) {
|
|
|
1107
1251
|
}
|
|
1108
1252
|
}
|
|
1109
1253
|
/**
|
|
1254
|
+
* The Remote visual-tools switch: the mirrored `pi-tui-visual-tools` form
|
|
1255
|
+
* section over the official generated settings remote. The write is a
|
|
1256
|
+
* revision-checked path mutation and the mirror's post-settlement refresh is
|
|
1257
|
+
* the only new authority — the mutate reply is never trusted as the new value.
|
|
1258
|
+
*
|
|
1259
|
+
* The Host registry itself is not observable on the wire, so `applied` stays
|
|
1260
|
+
* `undefined`: the UI may present the committed configuration but must not
|
|
1261
|
+
* claim the runtime registration took effect.
|
|
1262
|
+
*/
|
|
1263
|
+
var RemoteVisualToolsConfig = class {
|
|
1264
|
+
mirror;
|
|
1265
|
+
constructor(mirror) {
|
|
1266
|
+
this.mirror = mirror;
|
|
1267
|
+
}
|
|
1268
|
+
read() {
|
|
1269
|
+
const view = this.mirror.namespace(VISUAL_TOOLS_NS);
|
|
1270
|
+
if (view === void 0) return void 0;
|
|
1271
|
+
const enabled = plainRecord(view.value)?.enabled;
|
|
1272
|
+
if (typeof enabled !== "boolean") return void 0;
|
|
1273
|
+
const revision = view.revision;
|
|
1274
|
+
if (typeof revision !== "number") return void 0;
|
|
1275
|
+
return {
|
|
1276
|
+
enabled,
|
|
1277
|
+
revision,
|
|
1278
|
+
userOverridden: plainRecord(view.user)?.enabled !== void 0,
|
|
1279
|
+
applied: void 0
|
|
1280
|
+
};
|
|
1281
|
+
}
|
|
1282
|
+
async setEnabled(enabled, expectedRevision) {
|
|
1283
|
+
const view = this.mirror.namespace(VISUAL_TOOLS_NS);
|
|
1284
|
+
if (view === void 0) throw new Error(`settings namespace "${VISUAL_TOOLS_NS}" is not available in this deployment`);
|
|
1285
|
+
if (view.value === void 0) throw new Error(`settings namespace "${VISUAL_TOOLS_NS}" exposes no form projection`);
|
|
1286
|
+
await this.mirror.mutate(VISUAL_TOOLS_NS, [{
|
|
1287
|
+
op: "set",
|
|
1288
|
+
path: ["enabled"],
|
|
1289
|
+
value: enabled
|
|
1290
|
+
}], expectedRevision, "record");
|
|
1291
|
+
}
|
|
1292
|
+
};
|
|
1293
|
+
/**
|
|
1110
1294
|
* The Remote config port over ONE Client runtime source. The mirror is
|
|
1111
1295
|
* created first (its invalidation listeners are installed in its
|
|
1112
1296
|
* constructor, before the first describe), then every sub-domain projects
|
|
@@ -1116,15 +1300,19 @@ var RemoteConfigPort = class {
|
|
|
1116
1300
|
mirror;
|
|
1117
1301
|
tuiSettingsWrapper;
|
|
1118
1302
|
credentialConfig;
|
|
1303
|
+
/** The ONE accepted-write lifetime of this port (settings + credentials). */
|
|
1304
|
+
writes = new RemoteConfigWriteLifetime();
|
|
1119
1305
|
footerCommandTrust;
|
|
1120
1306
|
footerCustomItems;
|
|
1121
1307
|
providers;
|
|
1122
1308
|
credentials;
|
|
1123
1309
|
authorization;
|
|
1310
|
+
account;
|
|
1124
1311
|
permissions;
|
|
1125
1312
|
presetDefault;
|
|
1126
1313
|
subagentModelSelection;
|
|
1127
1314
|
web;
|
|
1315
|
+
visualTools;
|
|
1128
1316
|
/** `undefined` while the `tui-app` namespace is absent from the mirror
|
|
1129
1317
|
* (the port's documented absence contract). */
|
|
1130
1318
|
get tuiSettings() {
|
|
@@ -1136,17 +1324,19 @@ var RemoteConfigPort = class {
|
|
|
1136
1324
|
remote: source.remote,
|
|
1137
1325
|
connection: source.connection
|
|
1138
1326
|
};
|
|
1139
|
-
this.mirror = new RemoteConfigMirror(bound, on);
|
|
1327
|
+
this.mirror = new RemoteConfigMirror(bound, on, this.writes);
|
|
1140
1328
|
this.tuiSettingsWrapper = new RemoteTuiSettingsConfig(this.mirror);
|
|
1141
1329
|
this.footerCommandTrust = new RemoteFooterCommandTrust(this.mirror);
|
|
1142
1330
|
this.footerCustomItems = new RemoteFooterCustomItems(this.mirror);
|
|
1143
1331
|
this.providers = new RemoteProviderProfileConfig(this.mirror);
|
|
1144
|
-
this.credentialConfig = new RemoteCredentialConfig(bound.remote.credentials, on, source.connection.generation);
|
|
1332
|
+
this.credentialConfig = new RemoteCredentialConfig(bound.remote.credentials, on, source.connection.generation, this.writes);
|
|
1145
1333
|
this.credentials = this.credentialConfig;
|
|
1146
1334
|
this.authorization = new RemoteAuthorizationConfig();
|
|
1335
|
+
this.account = new RemoteUnsupportedAccountConfig();
|
|
1147
1336
|
this.permissions = new RemotePermissionConfig(this.mirror, source.remote.commands);
|
|
1148
1337
|
this.presetDefault = new RemotePresetDefaultConfig(this.mirror);
|
|
1149
1338
|
this.subagentModelSelection = new RemoteSubagentModelSelectionConfig(this.mirror);
|
|
1339
|
+
this.visualTools = new RemoteVisualToolsConfig(this.mirror);
|
|
1150
1340
|
this.web = new RemoteUnsupportedWebProviderConfig();
|
|
1151
1341
|
}
|
|
1152
1342
|
/** Commit one fresh mirror snapshot (or leave the last-known value). A
|
|
@@ -1166,6 +1356,10 @@ var RemoteConfigPort = class {
|
|
|
1166
1356
|
readiness() {
|
|
1167
1357
|
return this.mirror.readiness();
|
|
1168
1358
|
}
|
|
1359
|
+
/** Whether an accepted persisted configuration write is still unsettled. */
|
|
1360
|
+
hasUnsettledWrites() {
|
|
1361
|
+
return this.writes.hasUnsettledWrites();
|
|
1362
|
+
}
|
|
1169
1363
|
/** The semantic currentness signal (§9.1): the UI marks last-known values
|
|
1170
1364
|
* non-current and refuses writes while this is not `ready`. */
|
|
1171
1365
|
configReadiness() {
|
|
@@ -1220,6 +1414,72 @@ var RemoteUnsupportedWebProviderConfig = class {
|
|
|
1220
1414
|
this.refuse();
|
|
1221
1415
|
}
|
|
1222
1416
|
};
|
|
1417
|
+
/** Detached provider facts for the Remote Models detail (the same semantic
|
|
1418
|
+
* projection as Direct's adapter). */
|
|
1419
|
+
function remoteProviderFactsOf(route, fallbackLabel, profile) {
|
|
1420
|
+
if (typeof profile !== "object" || profile === null || Array.isArray(profile)) return {
|
|
1421
|
+
route,
|
|
1422
|
+
configured: profile !== void 0,
|
|
1423
|
+
displayName: fallbackLabel,
|
|
1424
|
+
models: []
|
|
1425
|
+
};
|
|
1426
|
+
const record = profile;
|
|
1427
|
+
const models = Array.isArray(record.models) ? record.models.flatMap((entry) => {
|
|
1428
|
+
if (typeof entry === "string") return [entry];
|
|
1429
|
+
if (typeof entry === "object" && entry !== null && typeof entry.id === "string") return [entry.id];
|
|
1430
|
+
return [];
|
|
1431
|
+
}) : [];
|
|
1432
|
+
return {
|
|
1433
|
+
route,
|
|
1434
|
+
configured: true,
|
|
1435
|
+
...typeof record.api === "string" && record.api !== "" ? { api: record.api } : {},
|
|
1436
|
+
...typeof record.baseURL === "string" && record.baseURL !== "" ? { baseURL: record.baseURL } : {},
|
|
1437
|
+
displayName: typeof record.displayName === "string" && record.displayName !== "" ? record.displayName : fallbackLabel,
|
|
1438
|
+
models,
|
|
1439
|
+
...typeof record.apiKeyEnv === "string" && record.apiKeyEnv !== "" ? { apiKeyEnv: record.apiKeyEnv } : {}
|
|
1440
|
+
};
|
|
1441
|
+
}
|
|
1442
|
+
/**
|
|
1443
|
+
* The Remote backend's DeepSeek Account sub-domain: INTENTIONALLY unsupported
|
|
1444
|
+
* for this stage. The rc.2 wire publishes no account state/attempt/profile/
|
|
1445
|
+
* balance/sign-out RPC, and the browser callback origin is a Host listener
|
|
1446
|
+
* fact that must never be synthesized by a Client. Every operation fails
|
|
1447
|
+
* closed; the Account page states the backend limitation instead of faking a
|
|
1448
|
+
* sign-in or a signed-out state.
|
|
1449
|
+
*/
|
|
1450
|
+
var RemoteUnsupportedAccountConfig = class {
|
|
1451
|
+
available() {
|
|
1452
|
+
return false;
|
|
1453
|
+
}
|
|
1454
|
+
refuse() {
|
|
1455
|
+
throw new Error("DeepSeek Account is not supported on this backend");
|
|
1456
|
+
}
|
|
1457
|
+
async getState() {
|
|
1458
|
+
this.refuse();
|
|
1459
|
+
}
|
|
1460
|
+
async getProfile(_client) {
|
|
1461
|
+
this.refuse();
|
|
1462
|
+
}
|
|
1463
|
+
async getBalance(_client) {
|
|
1464
|
+
this.refuse();
|
|
1465
|
+
}
|
|
1466
|
+
watch(_signal) {
|
|
1467
|
+
return (async function* empty() {})();
|
|
1468
|
+
}
|
|
1469
|
+
getCallbackOrigin() {}
|
|
1470
|
+
async startSignIn(_client) {
|
|
1471
|
+
this.refuse();
|
|
1472
|
+
}
|
|
1473
|
+
async cancelSignIn(_id) {
|
|
1474
|
+
this.refuse();
|
|
1475
|
+
}
|
|
1476
|
+
async signOut(_client) {
|
|
1477
|
+
this.refuse();
|
|
1478
|
+
}
|
|
1479
|
+
hasRunningAccountTasks() {
|
|
1480
|
+
return false;
|
|
1481
|
+
}
|
|
1482
|
+
};
|
|
1223
1483
|
//#endregion
|
|
1224
1484
|
//#region src/runtime/remote/session-archive-remote.ts
|
|
1225
1485
|
/** The official absolute export path (`dsh-session-log-export` routes). */
|
|
@@ -1284,777 +1544,138 @@ function createRemoteBackend(parts) {
|
|
|
1284
1544
|
};
|
|
1285
1545
|
}
|
|
1286
1546
|
//#endregion
|
|
1287
|
-
//#region src/
|
|
1288
|
-
/** The wire namespace (and Host Cordis service key) of the augmentation. */
|
|
1289
|
-
const PI_TUI_FILE_REFERENCES_NAMESPACE = "piTuiFileReferences";
|
|
1290
|
-
/** The private method's stable endpoint identity. */
|
|
1291
|
-
const PI_TUI_FILE_REFERENCES_LIST_ENDPOINT = "@xmoon76/dsh-pi-tui#piTuiFileReferences/list";
|
|
1292
|
-
/** One strict JSON codec that validates a wire string. */
|
|
1293
|
-
function stringCodec(typeSymbol) {
|
|
1294
|
-
return {
|
|
1295
|
-
mode: "strict",
|
|
1296
|
-
typeSymbol,
|
|
1297
|
-
create: () => ({ parse: (value) => {
|
|
1298
|
-
if (typeof value !== "string") throw new TypeError(`${typeSymbol}: the wire value must be a string`);
|
|
1299
|
-
return value;
|
|
1300
|
-
} })
|
|
1301
|
-
};
|
|
1302
|
-
}
|
|
1303
|
-
/**
|
|
1304
|
-
* Validate and detach one wire `HostFileListResult`. The result is produced by
|
|
1305
|
-
* this package's own Host router, but it is still a wire boundary on the Client
|
|
1306
|
-
* and the ONLY place the shape crosses.
|
|
1307
|
-
*/
|
|
1308
|
-
function decodeHostFileListResult(value) {
|
|
1309
|
-
if (typeof value !== "object" || value === null) throw new TypeError("piTuiFileReferences/list: the result must be an object");
|
|
1310
|
-
const record = value;
|
|
1311
|
-
if (record.kind === "unavailable") {
|
|
1312
|
-
if (typeof record.reason !== "string") throw new TypeError("piTuiFileReferences/list: an unavailable result needs a reason");
|
|
1313
|
-
return {
|
|
1314
|
-
kind: "unavailable",
|
|
1315
|
-
reason: record.reason
|
|
1316
|
-
};
|
|
1317
|
-
}
|
|
1318
|
-
if (record.kind !== "ok" || !Array.isArray(record.items)) throw new TypeError("piTuiFileReferences/list: the result must be ok(items) or unavailable(reason)");
|
|
1319
|
-
return {
|
|
1320
|
-
kind: "ok",
|
|
1321
|
-
items: record.items.map((entry) => {
|
|
1322
|
-
if (typeof entry !== "object" || entry === null) throw new TypeError("piTuiFileReferences/list: every candidate must be an object");
|
|
1323
|
-
const candidate = entry;
|
|
1324
|
-
if (typeof candidate.path !== "string" || candidate.kind !== "file" && candidate.kind !== "directory") throw new TypeError("piTuiFileReferences/list: every candidate needs a string path and a file/directory kind");
|
|
1325
|
-
return {
|
|
1326
|
-
path: candidate.path,
|
|
1327
|
-
kind: candidate.kind
|
|
1328
|
-
};
|
|
1329
|
-
})
|
|
1330
|
-
};
|
|
1331
|
-
}
|
|
1332
|
-
const HOST_FILE_LIST_RESULT_CODEC = {
|
|
1333
|
-
mode: "strict",
|
|
1334
|
-
typeSymbol: "@xmoon76/dsh-pi-tui#piTuiFileReferences/list:result",
|
|
1335
|
-
create: () => ({ parse: decodeHostFileListResult }),
|
|
1336
|
-
decode: decodeHostFileListResult
|
|
1337
|
-
};
|
|
1338
|
-
/**
|
|
1339
|
-
* The ONE shared invocation descriptor both contributions derive from. The
|
|
1340
|
-
* Host registers this exact object; the Client mounts this exact object.
|
|
1341
|
-
*/
|
|
1342
|
-
const PI_TUI_FILE_REFERENCES_LIST = {
|
|
1343
|
-
id: PI_TUI_FILE_REFERENCES_LIST_ENDPOINT,
|
|
1344
|
-
service: PI_TUI_FILE_REFERENCES_NAMESPACE,
|
|
1345
|
-
namespace: PI_TUI_FILE_REFERENCES_NAMESPACE,
|
|
1346
|
-
method: "list",
|
|
1347
|
-
invocation: { kind: "direct" },
|
|
1348
|
-
parameters: [{
|
|
1349
|
-
name: "sessionId",
|
|
1350
|
-
wire: "sessionId",
|
|
1351
|
-
source: "json",
|
|
1352
|
-
codec: stringCodec("@xmoon76/dsh-pi-tui#piTuiFileReferences/list:sessionId")
|
|
1353
|
-
}, {
|
|
1354
|
-
name: "query",
|
|
1355
|
-
wire: "query",
|
|
1356
|
-
source: "json",
|
|
1357
|
-
codec: stringCodec("@xmoon76/dsh-pi-tui#piTuiFileReferences/list:query")
|
|
1358
|
-
}],
|
|
1359
|
-
cancellation: { parameter: "signal" },
|
|
1360
|
-
result: HOST_FILE_LIST_RESULT_CODEC
|
|
1361
|
-
};
|
|
1362
|
-
//#endregion
|
|
1363
|
-
//#region src/runtime/remote/pi-tui-remote-contribution.ts
|
|
1364
|
-
/** The npm package that owns every private Remote invocation here. A test
|
|
1365
|
-
* guards that it equals each contract module's own package constant. */
|
|
1366
|
-
const PI_TUI_REMOTE_PACKAGE = "@xmoon76/dsh-pi-tui";
|
|
1367
|
-
/** The explicit Host contribution registered once with `ctx.typert.register`. */
|
|
1368
|
-
const PI_TUI_HOST_CONTRIBUTION = {
|
|
1369
|
-
package: PI_TUI_REMOTE_PACKAGE,
|
|
1370
|
-
face: "host",
|
|
1371
|
-
schemas: [],
|
|
1372
|
-
model: {
|
|
1373
|
-
services: [],
|
|
1374
|
-
events: [],
|
|
1375
|
-
objects: []
|
|
1376
|
-
},
|
|
1377
|
-
invocations: [PI_TUI_FILE_REFERENCES_LIST, PI_TUI_TERMINAL_PROGRESS_WATCH]
|
|
1378
|
-
};
|
|
1379
|
-
/** The explicit Client contribution mounted once with `ctx.remote.$mount`. */
|
|
1380
|
-
const PI_TUI_CLIENT_CONTRIBUTION = {
|
|
1381
|
-
package: PI_TUI_REMOTE_PACKAGE,
|
|
1382
|
-
descriptors: [PI_TUI_FILE_REFERENCES_LIST, PI_TUI_TERMINAL_PROGRESS_WATCH]
|
|
1383
|
-
};
|
|
1384
|
-
//#endregion
|
|
1385
|
-
//#region src/runtime/remote/pi-tui-file-reference-host-bridge.ts
|
|
1547
|
+
//#region src/app/remote/client-runtime.ts
|
|
1386
1548
|
/**
|
|
1387
|
-
*
|
|
1388
|
-
*
|
|
1389
|
-
*
|
|
1390
|
-
*
|
|
1391
|
-
*
|
|
1549
|
+
* Experimental official Client runtime composition (M3-1).
|
|
1550
|
+
*
|
|
1551
|
+
* Owns the official Client bundle capture, the Client `Context`, the exact
|
|
1552
|
+
* plugin mount order, the explicit `/remote` contributions, initial
|
|
1553
|
+
* readiness, and reverse disposal.
|
|
1554
|
+
* It does not assemble the TUI semantic `Backend`.
|
|
1392
1555
|
*
|
|
1393
|
-
*
|
|
1394
|
-
*
|
|
1395
|
-
*
|
|
1396
|
-
*
|
|
1397
|
-
*
|
|
1398
|
-
*
|
|
1556
|
+
* rc.2 publishes the six required Client plugin entries as Web
|
|
1557
|
+
* module-loader bundles: each bundle registers through
|
|
1558
|
+
* `window.__ModuleLoader__.load(...)`, which plain Node dynamic imports
|
|
1559
|
+
* cannot consume directly. The scoped loader below is therefore a packaging
|
|
1560
|
+
* adapter only: it is installed around exactly the six dynamic imports,
|
|
1561
|
+
* rejects unknown/duplicate/missing registrations, and restores the previous
|
|
1562
|
+
* process state before any Client plugin runs.
|
|
1399
1563
|
*
|
|
1400
|
-
*
|
|
1401
|
-
*
|
|
1564
|
+
* Because ESM evaluates each bundle at most once per process, the capture is
|
|
1565
|
+
* a process-wide single-flight: the captured package module exports are
|
|
1566
|
+
* reused for every Client `Context`, while each Context still gets its own
|
|
1567
|
+
* independent Connection, Gateway, Remote namespaces, Sessions, Jobs,
|
|
1568
|
+
* subscriptions, and lifetimes. Captured bundle factories are never re-run.
|
|
1402
1569
|
*
|
|
1403
|
-
* @module
|
|
1570
|
+
* @module app/remote/client-runtime
|
|
1404
1571
|
*/
|
|
1405
1572
|
/**
|
|
1406
|
-
*
|
|
1407
|
-
*
|
|
1408
|
-
* PATH pin; a later PATH change is not a Host completion fact).
|
|
1573
|
+
* The exact allowlist: dynamic import specifier paired with its expected
|
|
1574
|
+
* `__ModuleLoader__` registration id (§9.1). Kept distinct by design.
|
|
1409
1575
|
*/
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
}
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1576
|
+
const OFFICIAL_CLIENT_BUNDLES = [
|
|
1577
|
+
{
|
|
1578
|
+
specifier: "@deepseek-ai/dsh-typert-registry/client",
|
|
1579
|
+
id: "@deepseek-ai/dsh-typert-registry"
|
|
1580
|
+
},
|
|
1581
|
+
{
|
|
1582
|
+
specifier: "@deepseek-ai/dsh-client-connection/client",
|
|
1583
|
+
id: "@deepseek-ai/dsh-client-connection"
|
|
1584
|
+
},
|
|
1585
|
+
{
|
|
1586
|
+
specifier: "@deepseek-ai/dsh-api-gateway/client",
|
|
1587
|
+
id: "@deepseek-ai/dsh-api-gateway"
|
|
1588
|
+
},
|
|
1589
|
+
{
|
|
1590
|
+
specifier: "@deepseek-ai/dsh-client-file-upload/client",
|
|
1591
|
+
id: "@deepseek-ai/dsh-client-file-upload"
|
|
1592
|
+
},
|
|
1593
|
+
{
|
|
1594
|
+
specifier: "@deepseek-ai/dsh-api-session-controller/client",
|
|
1595
|
+
id: "@deepseek-ai/dsh-api-session-controller"
|
|
1596
|
+
},
|
|
1597
|
+
{
|
|
1598
|
+
specifier: "@deepseek-ai/dsh-api-job-controller/client",
|
|
1599
|
+
id: "@deepseek-ai/dsh-api-job-controller"
|
|
1600
|
+
}
|
|
1601
|
+
];
|
|
1602
|
+
/** Expected registration ids, in dependency order. */
|
|
1603
|
+
const EXPECTED_REGISTRATION_IDS = OFFICIAL_CLIENT_BUNDLES.map((bundle) => bundle.id);
|
|
1430
1604
|
/**
|
|
1431
|
-
* The
|
|
1432
|
-
*
|
|
1605
|
+
* The official web shell's platform static modules, which the browser-form
|
|
1606
|
+
* `/client` bundles resolve through the Loader's `require` (the published web
|
|
1607
|
+
* seed shares exactly these singletons). The Node Client shell is that shell:
|
|
1608
|
+
* it supplies the installed Harness-family `@deepseek-ai/dsh-client-store`
|
|
1609
|
+
* instance instead of relying on a transitive resolution from a bundle's own
|
|
1610
|
+
* package graph. `@deepseek-ai/cordis` is imported directly by this module and
|
|
1611
|
+
* therefore already resolves normally.
|
|
1433
1612
|
*/
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
constructor(ctx, deps) {
|
|
1443
|
-
super(ctx, PI_TUI_FILE_REFERENCES_NAMESPACE);
|
|
1444
|
-
this.runtime = createPiTuiHostFileReferenceRuntime({
|
|
1445
|
-
...deps,
|
|
1446
|
-
workingDirectory: () => ctx.get("workingDirectory")
|
|
1447
|
-
});
|
|
1448
|
-
}
|
|
1449
|
-
/**
|
|
1450
|
-
* The private Remote method (`piTuiFileReferences/list`, see
|
|
1451
|
-
* `pi-tui-file-reference-contract.ts`). Cancellation outranks every outcome.
|
|
1452
|
-
*/
|
|
1453
|
-
list(sessionId, query, signal) {
|
|
1454
|
-
return this.runtime.list(sessionId, query, signal);
|
|
1455
|
-
}
|
|
1456
|
-
};
|
|
1457
|
-
//#endregion
|
|
1458
|
-
//#region src/app/remote/terminal-progress-host.ts
|
|
1459
|
-
/** The structural `turn/start` / `turn/end` payload read (never a guessed shape). */
|
|
1460
|
-
function turnOf(data) {
|
|
1461
|
-
const turn = data?.turn;
|
|
1462
|
-
return typeof turn === "number" ? turn : void 0;
|
|
1613
|
+
const CLIENT_PLATFORM_MODULES = { "@deepseek-ai/dsh-client-store": clientStore };
|
|
1614
|
+
/** The loader's bare-dependency resolver: platform statics first, then the
|
|
1615
|
+
* CALLER's installation resolver. The real Client passes the DSH anchor
|
|
1616
|
+
* resolver so every non-platform dependency of a browser-form bundle also
|
|
1617
|
+
* resolves from the anchored installation, never from an unrelated source
|
|
1618
|
+
* tree. */
|
|
1619
|
+
function createPlatformRequire(fallback) {
|
|
1620
|
+
return (specifier) => Object.hasOwn(CLIENT_PLATFORM_MODULES, specifier) ? CLIENT_PLATFORM_MODULES[specifier] : fallback(specifier);
|
|
1463
1621
|
}
|
|
1464
|
-
/**
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1622
|
+
/** Process-wide single-flight capture; module code evaluates once per process. */
|
|
1623
|
+
let officialClientModulesPromise;
|
|
1624
|
+
/**
|
|
1625
|
+
* Load the six official Client bundles once per process and freeze their
|
|
1626
|
+
* captured module exports. Concurrent callers share the same promise.
|
|
1627
|
+
*
|
|
1628
|
+
* DSH 0.2.1-rc.1 and later select the `./client` entry by condition: `@deepseek-ai/dsh-typert-registry`,
|
|
1629
|
+
* `@deepseek-ai/dsh-client-connection` and `@deepseek-ai/dsh-api-gateway` publish
|
|
1630
|
+
* a standalone Node ESM variant (which never touches `window.__ModuleLoader__`),
|
|
1631
|
+
* while the remaining three publish the browser loader factory. Both channels
|
|
1632
|
+
* feed one table, so the registration order below still holds for every
|
|
1633
|
+
* `/client` dependency.
|
|
1634
|
+
*
|
|
1635
|
+
* Failure semantics: a rejected capture stays cached (fail fast, no silent
|
|
1636
|
+
* retry). ESM evaluates each bundle at most once per process, so bundles
|
|
1637
|
+
* already imported during a failed capture can never re-register — a retry
|
|
1638
|
+
* would deterministically fail the completeness check anyway.
|
|
1639
|
+
*/
|
|
1640
|
+
function loadOfficialClientModulesOnce() {
|
|
1641
|
+
officialClientModulesPromise ??= captureOfficialClientModules();
|
|
1642
|
+
return officialClientModulesPromise;
|
|
1468
1643
|
}
|
|
1469
1644
|
/**
|
|
1470
|
-
*
|
|
1471
|
-
*
|
|
1472
|
-
*
|
|
1645
|
+
* Exact scoped loader capture: install a temporary `window.__ModuleLoader__`,
|
|
1646
|
+
* dynamic-import the six bundles in dependency order, admit each bundle from
|
|
1647
|
+
* exactly the channel the published `./client` entry selected (loader
|
|
1648
|
+
* registration or standalone Node module — see {@link captureOfficialClientModules}),
|
|
1649
|
+
* freeze the module-export table, and restore the previous process state in
|
|
1650
|
+
* `finally` — before any Client Context exists.
|
|
1473
1651
|
*/
|
|
1474
|
-
const SUBSCRIBER_QUEUE_LIMIT = 64;
|
|
1475
1652
|
/**
|
|
1476
|
-
*
|
|
1477
|
-
*
|
|
1478
|
-
*
|
|
1479
|
-
*
|
|
1480
|
-
*
|
|
1481
|
-
* let a stream report a settlement whose running edge it lost (plan §6.5).
|
|
1653
|
+
* The exact scoped loader admission rules (module-internal seam, exercised by
|
|
1654
|
+
* the L5 loader-exactness test): reject an unknown registration id, a
|
|
1655
|
+
* duplicate id, a non-function factory, and a `/client` dependency requested
|
|
1656
|
+
* before its dependency-order capture; admit a directly imported Node bundle
|
|
1657
|
+
* for an id the loader did not register; report missing expected ids.
|
|
1482
1658
|
*/
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
this.frames.length = 0;
|
|
1494
|
-
const wake = this.wake;
|
|
1495
|
-
this.wake = void 0;
|
|
1496
|
-
wake?.();
|
|
1497
|
-
return;
|
|
1659
|
+
function createScopedClientModuleLoader(expectedIds, requireFrom = createRequire(import.meta.url)) {
|
|
1660
|
+
const nodeRequire = requireFrom;
|
|
1661
|
+
const registrations = /* @__PURE__ */ new Map();
|
|
1662
|
+
const captured = /* @__PURE__ */ new Map();
|
|
1663
|
+
const requireModule = (specifier) => {
|
|
1664
|
+
if (specifier.endsWith("/client")) {
|
|
1665
|
+
const id = specifier.slice(0, -7);
|
|
1666
|
+
const module = captured.get(id);
|
|
1667
|
+
if (module === void 0) throw new Error(`official Client module ${specifier} was requested before ${id} was captured`);
|
|
1668
|
+
return module;
|
|
1498
1669
|
}
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
*/
|
|
1509
|
-
close() {
|
|
1510
|
-
if (this.closed) return;
|
|
1511
|
-
this.closed = true;
|
|
1512
|
-
const wake = this.wake;
|
|
1513
|
-
this.wake = void 0;
|
|
1514
|
-
wake?.();
|
|
1515
|
-
}
|
|
1516
|
-
async next() {
|
|
1517
|
-
for (;;) {
|
|
1518
|
-
const frame = this.frames.shift();
|
|
1519
|
-
if (frame !== void 0) return {
|
|
1520
|
-
value: frame,
|
|
1521
|
-
done: false
|
|
1522
|
-
};
|
|
1523
|
-
if (this.failure !== void 0) throw this.failure;
|
|
1524
|
-
if (this.closed) return {
|
|
1525
|
-
value: void 0,
|
|
1526
|
-
done: true
|
|
1527
|
-
};
|
|
1528
|
-
await new Promise((resolve) => {
|
|
1529
|
-
this.wake = resolve;
|
|
1530
|
-
});
|
|
1531
|
-
}
|
|
1532
|
-
}
|
|
1533
|
-
};
|
|
1534
|
-
/**
|
|
1535
|
-
* The Host endpoint of the private stream. One instance per Remote Host
|
|
1536
|
-
* composition; the descriptors and the subscriptions leave with the fiber.
|
|
1537
|
-
*/
|
|
1538
|
-
var PiTuiTerminalProgressHostService = class extends TypertRemoteService {
|
|
1539
|
-
/** The Typert registry owns the explicit invocation definition. */
|
|
1540
|
-
static inject = ["typert"];
|
|
1541
|
-
/** The narrow Host facts the composition resolved (explicit field: the
|
|
1542
|
-
* strip-only TS loader rejects parameter properties). */
|
|
1543
|
-
deps;
|
|
1544
|
-
/** One opaque identity per Host plugin instance: a Host restart, a new
|
|
1545
|
-
* composition or a re-mounted fiber all invalidate older frames. */
|
|
1546
|
-
hostEpoch = `host-${randomEpoch()}`;
|
|
1547
|
-
records = /* @__PURE__ */ new Map();
|
|
1548
|
-
/** Monotonic Agent-lifetime counter: a replacement ALWAYS outranks every
|
|
1549
|
-
* earlier lifetime of the same session, even after its record was dropped. */
|
|
1550
|
-
epochCounter = 0;
|
|
1551
|
-
disposed = false;
|
|
1552
|
-
/**
|
|
1553
|
-
* @param ctx - the Host context this row is mounted in.
|
|
1554
|
-
* @param deps - the narrow Host facts the composition resolved.
|
|
1555
|
-
*/
|
|
1556
|
-
constructor(ctx, deps) {
|
|
1557
|
-
super(ctx, PI_TUI_TERMINAL_PROGRESS_NAMESPACE);
|
|
1558
|
-
this.deps = deps;
|
|
1559
|
-
ctx.on("agent/status", ({ agent, status }) => {
|
|
1560
|
-
this.onAgentStatus(agent, status);
|
|
1561
|
-
}, { global: true });
|
|
1562
|
-
ctx.on("session/event", (session, event) => {
|
|
1563
|
-
this.onSessionEvent(session, event.type, event.data);
|
|
1564
|
-
}, { global: true });
|
|
1565
|
-
ctx.on("agent/disposed", ({ agent }) => {
|
|
1566
|
-
this.onAgentDisposed(agent);
|
|
1567
|
-
}, { global: true });
|
|
1568
|
-
ctx.effect(() => () => {
|
|
1569
|
-
this.closeAll();
|
|
1570
|
-
}, "pi-tui-terminal-progress-watchers");
|
|
1571
|
-
}
|
|
1572
|
-
/**
|
|
1573
|
-
* The private Remote method (`piTuiTerminalProgress/watch`): the ONE
|
|
1574
|
-
* per-session ordered stream, opening with the authoritative snapshot of the
|
|
1575
|
-
* instant it subscribes and then every real Host-side change (plan §6.5).
|
|
1576
|
-
*
|
|
1577
|
-
* The subscriber is registered and the cut (revision + current state) is
|
|
1578
|
-
* captured in the SAME synchronous block before the first `yield`, so an
|
|
1579
|
-
* update can neither be lost between the snapshot and the subscription nor be
|
|
1580
|
-
* replayed twice.
|
|
1581
|
-
*/
|
|
1582
|
-
async *watch(sessionId, signal) {
|
|
1583
|
-
const record = this.recordFor(sessionId);
|
|
1584
|
-
const queue = new FrameQueue();
|
|
1585
|
-
const cut = record.revision;
|
|
1586
|
-
const snapshot = {
|
|
1587
|
-
kind: "snapshot",
|
|
1588
|
-
sessionId,
|
|
1589
|
-
hostEpoch: this.hostEpoch,
|
|
1590
|
-
agentEpoch: record.agentEpoch,
|
|
1591
|
-
revision: cut,
|
|
1592
|
-
running: record.running,
|
|
1593
|
-
outcome: record.outcome
|
|
1594
|
-
};
|
|
1595
|
-
record.subscribers.add(queue);
|
|
1596
|
-
const onAbort = () => {
|
|
1597
|
-
queue.close();
|
|
1598
|
-
};
|
|
1599
|
-
if (signal.aborted) queue.close();
|
|
1600
|
-
else signal.addEventListener("abort", onAbort, { once: true });
|
|
1601
|
-
try {
|
|
1602
|
-
yield snapshot;
|
|
1603
|
-
for (;;) {
|
|
1604
|
-
const next = await queue.next();
|
|
1605
|
-
if (next.done === true) return;
|
|
1606
|
-
yield next.value;
|
|
1607
|
-
}
|
|
1608
|
-
} finally {
|
|
1609
|
-
signal.removeEventListener("abort", onAbort);
|
|
1610
|
-
record.subscribers.delete(queue);
|
|
1611
|
-
this.reclaim(record);
|
|
1612
|
-
}
|
|
1613
|
-
}
|
|
1614
|
-
/**
|
|
1615
|
-
* Drop a record nobody watches and no Agent owns. A watch of a session that
|
|
1616
|
-
* has no live Agent must not leave an empty record behind for the rest of the
|
|
1617
|
-
* Host's life: it is observable by nothing, and the next Agent lifetime starts
|
|
1618
|
-
* a FRESH record carrying a HIGHER `agentEpoch` (the epoch counter never
|
|
1619
|
-
* rewinds), so no Client provenance can be resurrected across the gap.
|
|
1620
|
-
*/
|
|
1621
|
-
reclaim(record) {
|
|
1622
|
-
if (record.subscribers.size > 0 || record.agent !== void 0) return;
|
|
1623
|
-
if (this.records.get(record.sessionId) === record) this.records.delete(record.sessionId);
|
|
1624
|
-
}
|
|
1625
|
-
/** The live `agent/status` transition of one Agent (plan §6.4). */
|
|
1626
|
-
onAgentStatus(agent, status) {
|
|
1627
|
-
if (this.deps.agentFor(agent.session.id) !== agent) return;
|
|
1628
|
-
const record = this.recordFor(agent.session.id);
|
|
1629
|
-
if (record.agent !== agent) return;
|
|
1630
|
-
this.publish(record, record.fold.status(status === "running"));
|
|
1631
|
-
}
|
|
1632
|
-
/** One durable Session event (plan §6.4): evidence only, never an interim commit. */
|
|
1633
|
-
onSessionEvent(session, type, data) {
|
|
1634
|
-
const record = this.records.get(session.id);
|
|
1635
|
-
if (record === void 0 || record.agent === void 0) return;
|
|
1636
|
-
if (record.session !== session) return;
|
|
1637
|
-
if (type === "turn/start") {
|
|
1638
|
-
const turn = turnOf(data);
|
|
1639
|
-
if (turn !== void 0) record.fold.turnStart(turn);
|
|
1640
|
-
return;
|
|
1641
|
-
}
|
|
1642
|
-
if (type === "turn/end") {
|
|
1643
|
-
const turn = turnOf(data);
|
|
1644
|
-
const kind = reasonKindOf(data);
|
|
1645
|
-
if (turn !== void 0 && kind !== void 0) record.fold.turnEnd(turn, kind);
|
|
1646
|
-
}
|
|
1647
|
-
}
|
|
1648
|
-
/** The Agent lifetime ended (plan §6.4): retire honestly, end the watchers. */
|
|
1649
|
-
onAgentDisposed(agent) {
|
|
1650
|
-
const record = this.records.get(agent.session.id);
|
|
1651
|
-
if (record === void 0 || record.agent !== agent) return;
|
|
1652
|
-
const retired = record.fold.retire();
|
|
1653
|
-
if (retired !== void 0) this.publish(record, retired);
|
|
1654
|
-
this.records.delete(agent.session.id);
|
|
1655
|
-
for (const subscriber of record.subscribers) subscriber.close();
|
|
1656
|
-
}
|
|
1657
|
-
/**
|
|
1658
|
-
* The record of one session, bound to the live Agent the authoritative Host
|
|
1659
|
-
* registry currently holds. Creation AND a replaced Agent lifetime consume a
|
|
1660
|
-
* new `agentEpoch` and reset the interval: a new Agent can never inherit the
|
|
1661
|
-
* previous lifetime's evidence (plan §6.3/§6.4).
|
|
1662
|
-
*/
|
|
1663
|
-
recordFor(sessionId) {
|
|
1664
|
-
let record = this.records.get(sessionId);
|
|
1665
|
-
if (record === void 0) {
|
|
1666
|
-
record = {
|
|
1667
|
-
sessionId,
|
|
1668
|
-
agent: void 0,
|
|
1669
|
-
session: void 0,
|
|
1670
|
-
agentEpoch: 0,
|
|
1671
|
-
fold: createTerminalProgressInterval((kind) => {
|
|
1672
|
-
this.deps.onUnknownReason(kind);
|
|
1673
|
-
}),
|
|
1674
|
-
revision: 0,
|
|
1675
|
-
running: false,
|
|
1676
|
-
outcome: "idle",
|
|
1677
|
-
subscribers: /* @__PURE__ */ new Set()
|
|
1678
|
-
};
|
|
1679
|
-
this.records.set(sessionId, record);
|
|
1680
|
-
}
|
|
1681
|
-
const live = this.deps.agentFor(sessionId);
|
|
1682
|
-
if (live !== void 0 && live !== record.agent) this.rebind(record, live);
|
|
1683
|
-
return record;
|
|
1684
|
-
}
|
|
1685
|
-
/**
|
|
1686
|
-
* Bind one Agent lifetime: the running truth is read from the Agent's OWN
|
|
1687
|
-
* current status (a plugin mounted mid-run may therefore report `working`),
|
|
1688
|
-
* but the outcome starts at `idle` — an unobserved start can never prove a
|
|
1689
|
-
* settlement. The rebind is ALWAYS published, because the epoch change is
|
|
1690
|
-
* itself a fact the Client must fence on.
|
|
1691
|
-
*/
|
|
1692
|
-
rebind(record, agent) {
|
|
1693
|
-
record.agent = agent;
|
|
1694
|
-
record.session = agent.session;
|
|
1695
|
-
record.agentEpoch = ++this.epochCounter;
|
|
1696
|
-
const running = agent.status === "running";
|
|
1697
|
-
record.fold.apply({
|
|
1698
|
-
active: running,
|
|
1699
|
-
outcome: "idle"
|
|
1700
|
-
});
|
|
1701
|
-
record.running = running;
|
|
1702
|
-
record.outcome = "idle";
|
|
1703
|
-
record.revision += 1;
|
|
1704
|
-
this.broadcast(record, "update");
|
|
1705
|
-
}
|
|
1706
|
-
/** Commit one fold transition: mutate the record FIRST, then broadcast. */
|
|
1707
|
-
publish(record, next) {
|
|
1708
|
-
if (next === void 0) return;
|
|
1709
|
-
if (next.active === record.running && next.outcome === record.outcome) return;
|
|
1710
|
-
record.running = next.active;
|
|
1711
|
-
record.outcome = next.outcome;
|
|
1712
|
-
record.revision += 1;
|
|
1713
|
-
this.broadcast(record, "update");
|
|
1714
|
-
}
|
|
1715
|
-
broadcast(record, kind) {
|
|
1716
|
-
const frame = {
|
|
1717
|
-
kind,
|
|
1718
|
-
sessionId: record.sessionId,
|
|
1719
|
-
hostEpoch: this.hostEpoch,
|
|
1720
|
-
agentEpoch: record.agentEpoch,
|
|
1721
|
-
revision: record.revision,
|
|
1722
|
-
running: record.running,
|
|
1723
|
-
outcome: record.outcome
|
|
1724
|
-
};
|
|
1725
|
-
for (const subscriber of record.subscribers) subscriber.push(frame);
|
|
1726
|
-
}
|
|
1727
|
-
/** End every watcher (the row's fiber is going away). */
|
|
1728
|
-
closeAll() {
|
|
1729
|
-
if (this.disposed) return;
|
|
1730
|
-
this.disposed = true;
|
|
1731
|
-
for (const record of this.records.values()) for (const subscriber of record.subscribers) subscriber.close();
|
|
1732
|
-
}
|
|
1733
|
-
};
|
|
1734
|
-
/** An opaque, process-unique Host-plugin identity (the wire sees only a string). */
|
|
1735
|
-
function randomEpoch() {
|
|
1736
|
-
return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
|
|
1737
|
-
}
|
|
1738
|
-
//#endregion
|
|
1739
|
-
//#region src/app/remote/host-runtime.ts
|
|
1740
|
-
/**
|
|
1741
|
-
* Host services the ordinary Host Context must already expose before any M3
|
|
1742
|
-
* row mounts. The check fails fast with
|
|
1743
|
-
* the missing service named instead of parking the runtime.
|
|
1744
|
-
*/
|
|
1745
|
-
const HOST_PREREQUISITE_SERVICES = [
|
|
1746
|
-
"credentials",
|
|
1747
|
-
"userQuestions",
|
|
1748
|
-
"typert",
|
|
1749
|
-
"typertGateway",
|
|
1750
|
-
"agents",
|
|
1751
|
-
"agentDefaultModel",
|
|
1752
|
-
"attachments",
|
|
1753
|
-
"commands",
|
|
1754
|
-
"fileReferences",
|
|
1755
|
-
"fs",
|
|
1756
|
-
"workingDirectory",
|
|
1757
|
-
"llm",
|
|
1758
|
-
"sessions",
|
|
1759
|
-
"sessionProjections",
|
|
1760
|
-
"sessionQuery",
|
|
1761
|
-
"workspaceRegistry",
|
|
1762
|
-
"jobController"
|
|
1763
|
-
];
|
|
1764
|
-
/**
|
|
1765
|
-
* Fixed private base URL used only to construct valid `Request` objects for
|
|
1766
|
-
* the shared Fetch handler. It is not a global location, a server URL, a TCP
|
|
1767
|
-
* listener, or an authentication surface.
|
|
1768
|
-
*/
|
|
1769
|
-
const IN_PROCESS_BASE_URL = "http://dsh-pi-tui-remote.in-process/";
|
|
1770
|
-
async function* emptyUplink() {}
|
|
1771
|
-
/**
|
|
1772
|
-
* Attach one secondary failure to `failure`'s cause chain without losing an
|
|
1773
|
-
* existing cause: when the failure already carries a cause, both aggregate
|
|
1774
|
-
* into a single `AggregateError`. Shared by the three composition owners so
|
|
1775
|
-
* cleanup failures never mask the original construction/readiness error.
|
|
1776
|
-
* A `undefined` secondary is a no-op (nothing to attach).
|
|
1777
|
-
*/
|
|
1778
|
-
function mergeCause(failure, secondary) {
|
|
1779
|
-
if (secondary === void 0) return failure;
|
|
1780
|
-
const existingCause = failure.cause;
|
|
1781
|
-
failure.cause = existingCause === void 0 ? secondary : new AggregateError([existingCause, secondary], "remote composition: aggregated failure causes");
|
|
1782
|
-
return failure;
|
|
1783
|
-
}
|
|
1784
|
-
/**
|
|
1785
|
-
* Fail fast when the ordinary Host lacks one of the required base services.
|
|
1786
|
-
* Reads via the reflect store so the diagnostic can name the missing key
|
|
1787
|
-
* without depending on any one service's shape.
|
|
1788
|
-
*/
|
|
1789
|
-
function assertHostPrerequisites(hostContext) {
|
|
1790
|
-
for (const service of HOST_PREREQUISITE_SERVICES) if (hostContext.reflect.get(service) === void 0) throw new Error(`remote host runtime: the Host Context is missing the required "${service}" service`);
|
|
1791
|
-
}
|
|
1792
|
-
/** Build the in-process carrier over the Host connection + gateway seams.
|
|
1793
|
-
*
|
|
1794
|
-
* The carrier speaks for the Host Connection's OWN owner Peer
|
|
1795
|
-
* (`HostConnectionService.browserPeer`, created inside the service constructor
|
|
1796
|
-
* with `principal: { kind: 'owner' }` and disposed by the Connection plugin
|
|
1797
|
-
* fiber). The SAME reference is passed to the shared Fetch handler and to
|
|
1798
|
-
* `wireStream.open`, so one identity — and one lifetime — covers both the
|
|
1799
|
-
* unary and the streaming path; the carrier never creates, caches, or disposes
|
|
1800
|
-
* a Peer of its own. */
|
|
1801
|
-
function createInProcessCarrier(hostContext) {
|
|
1802
|
-
const connection = hostContext.connection;
|
|
1803
|
-
const peer = connection.browserPeer;
|
|
1804
|
-
const shared = connection.createSharedFetchHandler("/api");
|
|
1805
|
-
const gateway = hostContext.typertGateway;
|
|
1806
|
-
return {
|
|
1807
|
-
ownsHost: true,
|
|
1808
|
-
fetch(input, init) {
|
|
1809
|
-
const request = input instanceof Request ? new Request(input, init) : new Request(new URL(String(input), IN_PROCESS_BASE_URL), init);
|
|
1810
|
-
return shared.fetch(request, peer);
|
|
1811
|
-
},
|
|
1812
|
-
openStream(endpoint, payload, signal, uplink) {
|
|
1813
|
-
return (async function* () {
|
|
1814
|
-
yield* await gateway.wireStream.open(endpoint, payload, uplink ?? emptyUplink(), peer, signal);
|
|
1815
|
-
})();
|
|
1816
|
-
}
|
|
1817
|
-
};
|
|
1818
|
-
}
|
|
1819
|
-
/**
|
|
1820
|
-
* Mount the exact additive official Host closure (§2.4.1) onto the existing
|
|
1821
|
-
* Host Context and await every fiber. The existing `jobController` service is
|
|
1822
|
-
* asserted before and after construction and never re-mounted.
|
|
1823
|
-
*
|
|
1824
|
-
* On a partial construction failure the already-mounted fibers unwind in
|
|
1825
|
-
* reverse order before the original error rethrows.
|
|
1826
|
-
*/
|
|
1827
|
-
async function createRemoteHostRuntime(hostContext, options = {}) {
|
|
1828
|
-
assertHostPrerequisites(hostContext);
|
|
1829
|
-
const diag = options.diag ?? { warn: (message, fields) => {
|
|
1830
|
-
hostContext.logger("remote-host").warn(message, fields);
|
|
1831
|
-
} };
|
|
1832
|
-
/** The live Agent of one session, read PER CALL through the authoritative
|
|
1833
|
-
* Host registry (never a composition-time snapshot). */
|
|
1834
|
-
const liveAgentFor = (sessionId) => hostContext.reflect.get("agents")?.get(sessionId);
|
|
1835
|
-
const jobControllerBefore = hostContext.reflect.get("jobController");
|
|
1836
|
-
const userQuestionsBefore = hostContext.reflect.get("userQuestions");
|
|
1837
|
-
const fibers = [];
|
|
1838
|
-
let carrier;
|
|
1839
|
-
let disposed = false;
|
|
1840
|
-
/**
|
|
1841
|
-
* Reverse-dispose every mounted fiber. Per-step error isolation: one
|
|
1842
|
-
* rejecting disposer cannot truncate the remaining cleanup. Returns the
|
|
1843
|
-
* collected disposal errors instead of throwing, so the construction
|
|
1844
|
-
* failure path can rethrow the ORIGINAL error with the cleanup failures
|
|
1845
|
-
* attached as its `cause`.
|
|
1846
|
-
*/
|
|
1847
|
-
const collectUnwind = async () => {
|
|
1848
|
-
const errors = [];
|
|
1849
|
-
for (let index = fibers.length - 1; index >= 0; index -= 1) try {
|
|
1850
|
-
await fibers[index].dispose();
|
|
1851
|
-
} catch (error) {
|
|
1852
|
-
errors.push(error);
|
|
1853
|
-
}
|
|
1854
|
-
fibers.length = 0;
|
|
1855
|
-
return errors;
|
|
1856
|
-
};
|
|
1857
|
-
try {
|
|
1858
|
-
const contributionFiber = hostContext.inject(["typert"], (contributionCtx) => {
|
|
1859
|
-
contributionCtx.effect(() => contributionCtx.typert.register(PI_TUI_HOST_CONTRIBUTION), "pi-tui-private-remote-host");
|
|
1860
|
-
});
|
|
1861
|
-
fibers.push(contributionFiber);
|
|
1862
|
-
await contributionFiber;
|
|
1863
|
-
const fileReferenceFiber = hostContext.inject(PiTuiFileReferenceHostService.inject, (pluginCtx) => {
|
|
1864
|
-
new PiTuiFileReferenceHostService(pluginCtx, {
|
|
1865
|
-
agentFor: (sessionId) => liveAgentFor(sessionId),
|
|
1866
|
-
official: () => hostContext.reflect.get("fileReferences")
|
|
1867
|
-
});
|
|
1868
|
-
});
|
|
1869
|
-
fibers.push(fileReferenceFiber);
|
|
1870
|
-
await fileReferenceFiber;
|
|
1871
|
-
const terminalProgressFiber = hostContext.inject(PiTuiTerminalProgressHostService.inject, (pluginCtx) => {
|
|
1872
|
-
new PiTuiTerminalProgressHostService(pluginCtx, {
|
|
1873
|
-
agentFor: (sessionId) => liveAgentFor(sessionId),
|
|
1874
|
-
onUnknownReason: (kind) => {
|
|
1875
|
-
diag.warn("terminal progress: unknown turn/end reason", { kind });
|
|
1876
|
-
}
|
|
1877
|
-
});
|
|
1878
|
-
});
|
|
1879
|
-
fibers.push(terminalProgressFiber);
|
|
1880
|
-
await terminalProgressFiber;
|
|
1881
|
-
const connFiber = hostContext.plugin((connectionContext) => {
|
|
1882
|
-
new HostConnectionService(connectionContext, [], {});
|
|
1883
|
-
});
|
|
1884
|
-
fibers.push(connFiber);
|
|
1885
|
-
await connFiber;
|
|
1886
|
-
const uploadFiber = hostContext.plugin(FileUploads);
|
|
1887
|
-
fibers.push(uploadFiber);
|
|
1888
|
-
await uploadFiber;
|
|
1889
|
-
const statsFiber = hostContext.plugin(sessionStats);
|
|
1890
|
-
fibers.push(statsFiber);
|
|
1891
|
-
await statsFiber;
|
|
1892
|
-
const performanceFiber = hostContext.plugin(performance_host_exports);
|
|
1893
|
-
fibers.push(performanceFiber);
|
|
1894
|
-
await performanceFiber;
|
|
1895
|
-
const outlineFiber = hostContext.plugin(sessionTurnOutline);
|
|
1896
|
-
fibers.push(outlineFiber);
|
|
1897
|
-
await outlineFiber;
|
|
1898
|
-
const sessionCtrlFiber = hostContext.inject(SessionController.inject, (controllerContext) => {
|
|
1899
|
-
new SessionController(controllerContext, { nativeOpen: false });
|
|
1900
|
-
});
|
|
1901
|
-
fibers.push(sessionCtrlFiber);
|
|
1902
|
-
await sessionCtrlFiber;
|
|
1903
|
-
const settingsFiber = hostContext.plugin(SettingsController);
|
|
1904
|
-
fibers.push(settingsFiber);
|
|
1905
|
-
await settingsFiber;
|
|
1906
|
-
const remotesFiber = hostContext.plugin({
|
|
1907
|
-
inject,
|
|
1908
|
-
apply
|
|
1909
|
-
});
|
|
1910
|
-
fibers.push(remotesFiber);
|
|
1911
|
-
await remotesFiber;
|
|
1912
|
-
const exportFiber = hostContext.plugin(sessionLogExport);
|
|
1913
|
-
fibers.push(exportFiber);
|
|
1914
|
-
await exportFiber;
|
|
1915
|
-
const jobControllerAfter = hostContext.reflect.get("jobController");
|
|
1916
|
-
if (jobControllerAfter === void 0 || jobControllerAfter.typertRemote === void 0 || jobControllerAfter.typertRemote !== jobControllerBefore.typertRemote) throw new Error("remote host runtime: the existing jobController service was replaced by the M3 composition");
|
|
1917
|
-
const userQuestionsAfter = hostContext.reflect.get("userQuestions");
|
|
1918
|
-
if (userQuestionsAfter === void 0 || userQuestionsAfter.typertRemote === void 0 || userQuestionsAfter.typertRemote !== userQuestionsBefore?.typertRemote) throw new Error("remote host runtime: the existing userQuestions service was replaced by the M3 composition");
|
|
1919
|
-
carrier = createInProcessCarrier(hostContext);
|
|
1920
|
-
} catch (error) {
|
|
1921
|
-
const disposeErrors = await collectUnwind();
|
|
1922
|
-
if (disposeErrors.length > 0) {
|
|
1923
|
-
const secondary = disposeErrors.length === 1 ? disposeErrors[0] : new AggregateError(disposeErrors, "remote host runtime: unwind disposal failures");
|
|
1924
|
-
throw mergeCause(error instanceof Error ? error : new Error(String(error)), secondary);
|
|
1925
|
-
}
|
|
1926
|
-
throw error;
|
|
1927
|
-
}
|
|
1928
|
-
return {
|
|
1929
|
-
hostContext,
|
|
1930
|
-
carrier,
|
|
1931
|
-
async dispose() {
|
|
1932
|
-
if (disposed) return;
|
|
1933
|
-
disposed = true;
|
|
1934
|
-
const disposeErrors = await collectUnwind();
|
|
1935
|
-
if (disposeErrors.length > 0) {
|
|
1936
|
-
const failure = disposeErrors[0] instanceof Error ? disposeErrors[0] : new Error(String(disposeErrors[0]));
|
|
1937
|
-
if (disposeErrors.length > 1) mergeCause(failure, new AggregateError(disposeErrors.slice(1), "remote host runtime: remaining disposal failures"));
|
|
1938
|
-
throw failure;
|
|
1939
|
-
}
|
|
1940
|
-
}
|
|
1941
|
-
};
|
|
1942
|
-
}
|
|
1943
|
-
//#endregion
|
|
1944
|
-
//#region src/app/remote/client-runtime.ts
|
|
1945
|
-
/**
|
|
1946
|
-
* Experimental official Client runtime composition (M3-1).
|
|
1947
|
-
*
|
|
1948
|
-
* Owns the official Client bundle capture, the Client `Context`, the exact
|
|
1949
|
-
* plugin mount order, the explicit `/remote` contributions, initial
|
|
1950
|
-
* readiness, and reverse disposal.
|
|
1951
|
-
* It does not assemble the TUI semantic `Backend`.
|
|
1952
|
-
*
|
|
1953
|
-
* rc.2 publishes the six required Client plugin entries as Web
|
|
1954
|
-
* module-loader bundles: each bundle registers through
|
|
1955
|
-
* `window.__ModuleLoader__.load(...)`, which plain Node dynamic imports
|
|
1956
|
-
* cannot consume directly. The scoped loader below is therefore a packaging
|
|
1957
|
-
* adapter only: it is installed around exactly the six dynamic imports,
|
|
1958
|
-
* rejects unknown/duplicate/missing registrations, and restores the previous
|
|
1959
|
-
* process state before any Client plugin runs.
|
|
1960
|
-
*
|
|
1961
|
-
* Because ESM evaluates each bundle at most once per process, the capture is
|
|
1962
|
-
* a process-wide single-flight: the captured package module exports are
|
|
1963
|
-
* reused for every Client `Context`, while each Context still gets its own
|
|
1964
|
-
* independent Connection, Gateway, Remote namespaces, Sessions, Jobs,
|
|
1965
|
-
* subscriptions, and lifetimes. Captured bundle factories are never re-run.
|
|
1966
|
-
*
|
|
1967
|
-
* @module app/remote/client-runtime
|
|
1968
|
-
*/
|
|
1969
|
-
/**
|
|
1970
|
-
* The exact allowlist: dynamic import specifier paired with its expected
|
|
1971
|
-
* `__ModuleLoader__` registration id (§9.1). Kept distinct by design.
|
|
1972
|
-
*/
|
|
1973
|
-
const OFFICIAL_CLIENT_BUNDLES = [
|
|
1974
|
-
{
|
|
1975
|
-
specifier: "@deepseek-ai/dsh-typert-registry/client",
|
|
1976
|
-
id: "@deepseek-ai/dsh-typert-registry"
|
|
1977
|
-
},
|
|
1978
|
-
{
|
|
1979
|
-
specifier: "@deepseek-ai/dsh-client-connection/client",
|
|
1980
|
-
id: "@deepseek-ai/dsh-client-connection"
|
|
1981
|
-
},
|
|
1982
|
-
{
|
|
1983
|
-
specifier: "@deepseek-ai/dsh-api-gateway/client",
|
|
1984
|
-
id: "@deepseek-ai/dsh-api-gateway"
|
|
1985
|
-
},
|
|
1986
|
-
{
|
|
1987
|
-
specifier: "@deepseek-ai/dsh-client-file-upload/client",
|
|
1988
|
-
id: "@deepseek-ai/dsh-client-file-upload"
|
|
1989
|
-
},
|
|
1990
|
-
{
|
|
1991
|
-
specifier: "@deepseek-ai/dsh-api-session-controller/client",
|
|
1992
|
-
id: "@deepseek-ai/dsh-api-session-controller"
|
|
1993
|
-
},
|
|
1994
|
-
{
|
|
1995
|
-
specifier: "@deepseek-ai/dsh-api-job-controller/client",
|
|
1996
|
-
id: "@deepseek-ai/dsh-api-job-controller"
|
|
1997
|
-
}
|
|
1998
|
-
];
|
|
1999
|
-
/** Expected registration ids, in dependency order. */
|
|
2000
|
-
const EXPECTED_REGISTRATION_IDS = OFFICIAL_CLIENT_BUNDLES.map((bundle) => bundle.id);
|
|
2001
|
-
/** Process-wide single-flight capture; module code evaluates once per process. */
|
|
2002
|
-
let officialClientModulesPromise;
|
|
2003
|
-
/**
|
|
2004
|
-
* Load the six official Client bundles once per process and freeze their
|
|
2005
|
-
* captured module exports. Concurrent callers share the same promise.
|
|
2006
|
-
*
|
|
2007
|
-
* DSH 0.2.1-rc.1 and later select the `./client` entry by condition: `@deepseek-ai/dsh-typert-registry`,
|
|
2008
|
-
* `@deepseek-ai/dsh-client-connection` and `@deepseek-ai/dsh-api-gateway` publish
|
|
2009
|
-
* a standalone Node ESM variant (which never touches `window.__ModuleLoader__`),
|
|
2010
|
-
* while the remaining three publish the browser loader factory. Both channels
|
|
2011
|
-
* feed one table, so the registration order below still holds for every
|
|
2012
|
-
* `/client` dependency.
|
|
2013
|
-
*
|
|
2014
|
-
* Failure semantics: a rejected capture stays cached (fail fast, no silent
|
|
2015
|
-
* retry). ESM evaluates each bundle at most once per process, so bundles
|
|
2016
|
-
* already imported during a failed capture can never re-register — a retry
|
|
2017
|
-
* would deterministically fail the completeness check anyway.
|
|
2018
|
-
*/
|
|
2019
|
-
function loadOfficialClientModulesOnce() {
|
|
2020
|
-
officialClientModulesPromise ??= captureOfficialClientModules();
|
|
2021
|
-
return officialClientModulesPromise;
|
|
2022
|
-
}
|
|
2023
|
-
/**
|
|
2024
|
-
* Exact scoped loader capture: install a temporary `window.__ModuleLoader__`,
|
|
2025
|
-
* dynamic-import the six bundles in dependency order, admit each bundle from
|
|
2026
|
-
* exactly the channel the published `./client` entry selected (loader
|
|
2027
|
-
* registration or standalone Node module — see {@link captureOfficialClientModules}),
|
|
2028
|
-
* freeze the module-export table, and restore the previous process state in
|
|
2029
|
-
* `finally` — before any Client Context exists.
|
|
2030
|
-
*/
|
|
2031
|
-
/**
|
|
2032
|
-
* The exact scoped loader admission rules (module-internal seam, exercised by
|
|
2033
|
-
* the L5 loader-exactness test): reject an unknown registration id, a
|
|
2034
|
-
* duplicate id, a non-function factory, and a `/client` dependency requested
|
|
2035
|
-
* before its dependency-order capture; admit a directly imported Node bundle
|
|
2036
|
-
* for an id the loader did not register; report missing expected ids.
|
|
2037
|
-
*/
|
|
2038
|
-
function createScopedClientModuleLoader(expectedIds) {
|
|
2039
|
-
const nodeRequire = createRequire(import.meta.url);
|
|
2040
|
-
const registrations = /* @__PURE__ */ new Map();
|
|
2041
|
-
const captured = /* @__PURE__ */ new Map();
|
|
2042
|
-
const requireModule = (specifier) => {
|
|
2043
|
-
if (specifier.endsWith("/client")) {
|
|
2044
|
-
const id = specifier.slice(0, -7);
|
|
2045
|
-
const module = captured.get(id);
|
|
2046
|
-
if (module === void 0) throw new Error(`official Client module ${specifier} was requested before ${id} was captured`);
|
|
2047
|
-
return module;
|
|
2048
|
-
}
|
|
2049
|
-
return nodeRequire(specifier);
|
|
2050
|
-
};
|
|
2051
|
-
const load = ({ id, factory }) => {
|
|
2052
|
-
if (!expectedIds.includes(id)) throw new Error(`official Client bundle loader received an unexpected registration id: ${String(id)}`);
|
|
2053
|
-
if (registrations.has(id)) throw new Error(`official Client bundle ${id} registered twice`);
|
|
2054
|
-
if (typeof factory !== "function") throw new Error(`official Client bundle ${id} registered a non-function factory`);
|
|
2055
|
-
registrations.set(id, factory);
|
|
2056
|
-
captured.set(id, factory(requireModule));
|
|
2057
|
-
};
|
|
1670
|
+
return nodeRequire(specifier);
|
|
1671
|
+
};
|
|
1672
|
+
const load = ({ id, factory }) => {
|
|
1673
|
+
if (!expectedIds.includes(id)) throw new Error(`official Client bundle loader received an unexpected registration id: ${String(id)}`);
|
|
1674
|
+
if (registrations.has(id)) throw new Error(`official Client bundle ${id} registered twice`);
|
|
1675
|
+
if (typeof factory !== "function") throw new Error(`official Client bundle ${id} registered a non-function factory`);
|
|
1676
|
+
registrations.set(id, factory);
|
|
1677
|
+
captured.set(id, factory(requireModule));
|
|
1678
|
+
};
|
|
2058
1679
|
/**
|
|
2059
1680
|
* Admit one directly imported bundle whose `./client` entry did not register
|
|
2060
1681
|
* through the loader shim (the standalone Node variant). The module joins the
|
|
@@ -2127,7 +1748,7 @@ function installScopedModuleLoaderShim(load) {
|
|
|
2127
1748
|
return restore;
|
|
2128
1749
|
}
|
|
2129
1750
|
async function captureOfficialClientModules() {
|
|
2130
|
-
const loader = createScopedClientModuleLoader(EXPECTED_REGISTRATION_IDS);
|
|
1751
|
+
const loader = createScopedClientModuleLoader(EXPECTED_REGISTRATION_IDS, createPlatformRequire(createRequire(import.meta.url)));
|
|
2131
1752
|
const restoreShim = installScopedModuleLoaderShim(loader.load);
|
|
2132
1753
|
try {
|
|
2133
1754
|
for (const bundle of OFFICIAL_CLIENT_BUNDLES) loader.acceptImported(bundle.id, await import(bundle.specifier));
|
|
@@ -2163,8 +1784,79 @@ const REMOTE_CONTRIBUTIONS = [
|
|
|
2163
1784
|
permissionPresetsRemote,
|
|
2164
1785
|
llmRemote,
|
|
2165
1786
|
fileUploadsRemote,
|
|
2166
|
-
userQuestionsRemote
|
|
1787
|
+
userQuestionsRemote,
|
|
1788
|
+
workspaceFilesRemote
|
|
1789
|
+
];
|
|
1790
|
+
/**
|
|
1791
|
+
* The exact generated `/remote` contribution specifiers in the SAME frozen
|
|
1792
|
+
* order as {@link REMOTE_CONTRIBUTIONS}. A real installed Client process
|
|
1793
|
+
* resolves THESE from its DSH installation anchor instead of consuming the
|
|
1794
|
+
* statically imported source-tree copy; both channels produce the one table
|
|
1795
|
+
* `mountRemoteClientDomains` mounts.
|
|
1796
|
+
*/
|
|
1797
|
+
const REMOTE_CONTRIBUTION_SPECIFIERS = [
|
|
1798
|
+
"@deepseek-ai/dsh-api-session-controller/remote",
|
|
1799
|
+
"@deepseek-ai/dsh-api-job-controller/remote",
|
|
1800
|
+
"@deepseek-ai/dsh-commands/remote",
|
|
1801
|
+
"@deepseek-ai/dsh-subagent/remote",
|
|
1802
|
+
"@deepseek-ai/dsh-agent-preset-registry/remote",
|
|
1803
|
+
"@deepseek-ai/dsh-plugin-manager/remote",
|
|
1804
|
+
"@deepseek-ai/dsh-api-settings-controller/remote",
|
|
1805
|
+
"@deepseek-ai/dsh-permission-presets/remote",
|
|
1806
|
+
"@deepseek-ai/dsh-llm/remote",
|
|
1807
|
+
"@deepseek-ai/dsh-client-file-upload/remote",
|
|
1808
|
+
"@deepseek-ai/dsh-user-questions/remote",
|
|
1809
|
+
"@deepseek-ai/dsh-api-workspace-files/remote"
|
|
2167
1810
|
];
|
|
1811
|
+
/** Per-installation single-flight captures, keyed by the real anchor path. */
|
|
1812
|
+
const installedClientDomainModules = /* @__PURE__ */ new Map();
|
|
1813
|
+
/** Capture the six official `/client` bundles through the installation anchor. */
|
|
1814
|
+
async function captureInstalledOfficialClientModules(requireFromAnchor) {
|
|
1815
|
+
const loader = createScopedClientModuleLoader(EXPECTED_REGISTRATION_IDS, createPlatformRequire(requireFromAnchor));
|
|
1816
|
+
const restoreShim = installScopedModuleLoaderShim(loader.load);
|
|
1817
|
+
try {
|
|
1818
|
+
for (const bundle of OFFICIAL_CLIENT_BUNDLES) {
|
|
1819
|
+
const resolved = requireFromAnchor.resolve(bundle.specifier);
|
|
1820
|
+
loader.acceptImported(bundle.id, await import(pathToFileURL(resolved).href));
|
|
1821
|
+
}
|
|
1822
|
+
loader.assertComplete();
|
|
1823
|
+
} finally {
|
|
1824
|
+
restoreShim();
|
|
1825
|
+
}
|
|
1826
|
+
const captured = /* @__PURE__ */ new Map();
|
|
1827
|
+
for (const id of EXPECTED_REGISTRATION_IDS) captured.set(id, loader.requireModule(`${id}/client`));
|
|
1828
|
+
return freezeOfficialClientModules(captured);
|
|
1829
|
+
}
|
|
1830
|
+
/**
|
|
1831
|
+
* Capture ONE installed DSH generation's whole Client domain composition: the
|
|
1832
|
+
* six official `/client` bundles and the generated `/remote` contributions,
|
|
1833
|
+
* every specifier resolved from `dshAnchor`. A rejection stays cached (fail
|
|
1834
|
+
* fast; a retry cannot succeed because ESM evaluates the bundles once).
|
|
1835
|
+
*/
|
|
1836
|
+
async function captureInstalledClientDomainModules(anchor) {
|
|
1837
|
+
const requireFromAnchor = createRequire(anchor);
|
|
1838
|
+
const modules = await captureInstalledOfficialClientModules(requireFromAnchor);
|
|
1839
|
+
const contributions = [];
|
|
1840
|
+
for (const specifier of REMOTE_CONTRIBUTION_SPECIFIERS) {
|
|
1841
|
+
const contribution = (await import(pathToFileURL(requireFromAnchor.resolve(specifier)).href)).default;
|
|
1842
|
+
if (typeof contribution !== "object" || contribution === null || !Array.isArray(contribution.descriptors)) throw new Error(`remote client domains: installed ${specifier} is not a generated Remote contribution`);
|
|
1843
|
+
contributions.push(contribution);
|
|
1844
|
+
}
|
|
1845
|
+
return {
|
|
1846
|
+
modules,
|
|
1847
|
+
contributions
|
|
1848
|
+
};
|
|
1849
|
+
}
|
|
1850
|
+
/** Load the Client domain composition from one installed DSH anchor (single-flight). */
|
|
1851
|
+
function loadInstalledClientDomainModules(dshAnchor) {
|
|
1852
|
+
const anchor = realpathSync(dshAnchor);
|
|
1853
|
+
let pending = installedClientDomainModules.get(anchor);
|
|
1854
|
+
if (pending === void 0) {
|
|
1855
|
+
pending = captureInstalledClientDomainModules(anchor);
|
|
1856
|
+
installedClientDomainModules.set(anchor, pending);
|
|
1857
|
+
}
|
|
1858
|
+
return pending;
|
|
1859
|
+
}
|
|
2168
1860
|
/**
|
|
2169
1861
|
* Reverse-dispose the recorded `/remote` contribution disposers. Per-step
|
|
2170
1862
|
* error isolation: one rejecting disposer cannot truncate the remaining
|
|
@@ -2183,13 +1875,133 @@ async function disposeRemoteContributions(disposers) {
|
|
|
2183
1875
|
}
|
|
2184
1876
|
return errors;
|
|
2185
1877
|
}
|
|
1878
|
+
/** Reverse-order Domain teardown. Contribution failures are isolated. */
|
|
1879
|
+
async function shutdownDomainState(state) {
|
|
1880
|
+
if (state.disposed) return [];
|
|
1881
|
+
state.disposed = true;
|
|
1882
|
+
for (const fiber of [
|
|
1883
|
+
state.jobsFiber,
|
|
1884
|
+
state.sessionFiber,
|
|
1885
|
+
state.fileUploadFiber
|
|
1886
|
+
]) await fiber?.dispose();
|
|
1887
|
+
state.jobsFiber = void 0;
|
|
1888
|
+
state.sessionFiber = void 0;
|
|
1889
|
+
state.fileUploadFiber = void 0;
|
|
1890
|
+
const contributionErrors = await disposeRemoteContributions(state.contributionDisposers);
|
|
1891
|
+
state.contributionDisposers.length = 0;
|
|
1892
|
+
return contributionErrors;
|
|
1893
|
+
}
|
|
1894
|
+
/**
|
|
1895
|
+
* Mount the official Client Domain prerequisites on the caller's
|
|
1896
|
+
* ALREADY-AUTHENTICATED Client `Context`: the twelve generated `/remote`
|
|
1897
|
+
* contributions, the private pi-tui contribution, the official fileUpload
|
|
1898
|
+
* Client, then the official Session Client (which registers the `agent`
|
|
1899
|
+
* `typert.contexts` resolver). It deliberately does NOT wait for a Connection
|
|
1900
|
+
* generation: the split Client must mount the Session resolver and its root
|
|
1901
|
+
* interaction listeners before the official Gateway starts its event pump.
|
|
1902
|
+
*
|
|
1903
|
+
* Failure semantics: a construction failure unwinds exactly what this stage
|
|
1904
|
+
* created, in reverse order; the original error stays primary and any cleanup
|
|
1905
|
+
* failures ride its cause chain.
|
|
1906
|
+
*/
|
|
1907
|
+
async function mountRemoteClientDomainPrerequisites(options) {
|
|
1908
|
+
const { context } = options;
|
|
1909
|
+
const connection = context.get("connection");
|
|
1910
|
+
const remote = context.get("remote");
|
|
1911
|
+
if (context.get("typert") === void 0 || connection === void 0 || remote === void 0) throw new Error("remote client domains: the caller must install typert, the authenticated connection and the API gateway first");
|
|
1912
|
+
const source = options.dshAnchor === void 0 ? {
|
|
1913
|
+
modules: await loadOfficialClientModulesOnce(),
|
|
1914
|
+
contributions: REMOTE_CONTRIBUTIONS
|
|
1915
|
+
} : await loadInstalledClientDomainModules(options.dshAnchor);
|
|
1916
|
+
const state = {
|
|
1917
|
+
context,
|
|
1918
|
+
connection,
|
|
1919
|
+
remote,
|
|
1920
|
+
sessions: void 0,
|
|
1921
|
+
contributionDisposers: [],
|
|
1922
|
+
disposed: false
|
|
1923
|
+
};
|
|
1924
|
+
const unwind = async (error) => {
|
|
1925
|
+
const cleanupErrors = await shutdownDomainState(state);
|
|
1926
|
+
const failure = error instanceof Error ? error : new Error(String(error));
|
|
1927
|
+
if (cleanupErrors.length > 0) {
|
|
1928
|
+
const secondary = cleanupErrors.length === 1 ? cleanupErrors[0] : new AggregateError(cleanupErrors, "remote client domains: unwind disposal failures");
|
|
1929
|
+
mergeCause(failure, secondary);
|
|
1930
|
+
}
|
|
1931
|
+
throw failure;
|
|
1932
|
+
};
|
|
1933
|
+
try {
|
|
1934
|
+
for (const contribution of source.contributions) state.contributionDisposers.push(await remote.$mount(contribution));
|
|
1935
|
+
state.contributionDisposers.push(await remote.$mount(PI_TUI_CLIENT_CONTRIBUTION));
|
|
1936
|
+
state.fileUploadFiber = context.plugin(source.modules.fileUpload);
|
|
1937
|
+
await state.fileUploadFiber;
|
|
1938
|
+
state.sessionFiber = context.plugin(source.modules.session);
|
|
1939
|
+
await state.sessionFiber;
|
|
1940
|
+
state.sessions = context.get("sessions");
|
|
1941
|
+
if (state.sessions === void 0) throw new Error("remote client domains: the official Session Client did not install");
|
|
1942
|
+
} catch (error) {
|
|
1943
|
+
return await unwind(error);
|
|
1944
|
+
}
|
|
1945
|
+
return {
|
|
1946
|
+
context,
|
|
1947
|
+
connection,
|
|
1948
|
+
remote,
|
|
1949
|
+
sessions: state.sessions,
|
|
1950
|
+
async complete(completeOptions = {}) {
|
|
1951
|
+
if (state.disposed) throw new Error("remote client domains: the prerequisites were already disposed");
|
|
1952
|
+
state.completion ??= (async () => {
|
|
1953
|
+
try {
|
|
1954
|
+
state.jobsFiber = context.plugin(source.modules.jobs);
|
|
1955
|
+
await state.jobsFiber;
|
|
1956
|
+
await waitForInitialReadiness(connection, state.sessions, completeOptions.signal);
|
|
1957
|
+
const jobs = context.get("jobs");
|
|
1958
|
+
if (jobs === void 0) throw new Error("remote client domains: the official Jobs Client did not install");
|
|
1959
|
+
return {
|
|
1960
|
+
context,
|
|
1961
|
+
connection,
|
|
1962
|
+
sessions: state.sessions,
|
|
1963
|
+
jobs,
|
|
1964
|
+
remote,
|
|
1965
|
+
async dispose() {
|
|
1966
|
+
const cleanupErrors = await shutdownDomainState(state);
|
|
1967
|
+
if (cleanupErrors.length === 0) return;
|
|
1968
|
+
const failure = cleanupErrors[0] instanceof Error ? cleanupErrors[0] : new Error(String(cleanupErrors[0]));
|
|
1969
|
+
if (cleanupErrors.length > 1) mergeCause(failure, new AggregateError(cleanupErrors.slice(1), "remote client domains: remaining disposal failures"));
|
|
1970
|
+
throw failure;
|
|
1971
|
+
}
|
|
1972
|
+
};
|
|
1973
|
+
} catch (error) {
|
|
1974
|
+
return await unwind(error);
|
|
1975
|
+
}
|
|
1976
|
+
})();
|
|
1977
|
+
return await state.completion;
|
|
1978
|
+
},
|
|
1979
|
+
async dispose() {
|
|
1980
|
+
const cleanupErrors = await shutdownDomainState(state);
|
|
1981
|
+
if (cleanupErrors.length === 0) return;
|
|
1982
|
+
const failure = cleanupErrors[0] instanceof Error ? cleanupErrors[0] : new Error(String(cleanupErrors[0]));
|
|
1983
|
+
if (cleanupErrors.length > 1) mergeCause(failure, new AggregateError(cleanupErrors.slice(1), "remote client domains: remaining disposal failures"));
|
|
1984
|
+
throw failure;
|
|
1985
|
+
}
|
|
1986
|
+
};
|
|
1987
|
+
}
|
|
1988
|
+
/**
|
|
1989
|
+
* Mount the official Client data plane on the caller's ALREADY-AUTHENTICATED
|
|
1990
|
+
* Client `Context`: the full staged domain graph (prerequisites + Jobs) and
|
|
1991
|
+
* the initial-readiness wait. This wrapper preserves the M3 in-process
|
|
1992
|
+
* composition contract; the split Client uses the staged functions directly
|
|
1993
|
+
* so its interaction owner exists before the Gateway starts.
|
|
1994
|
+
*/
|
|
1995
|
+
async function mountRemoteClientDomains(options) {
|
|
1996
|
+
return await (await mountRemoteClientDomainPrerequisites(options)).complete(options.signal === void 0 ? {} : { signal: options.signal });
|
|
1997
|
+
}
|
|
2186
1998
|
/**
|
|
2187
|
-
* Compose one fresh official Client `Context` over the
|
|
2188
|
-
* typert -> Connection (explicit transport) -> Gateway -> the
|
|
2189
|
-
*
|
|
2190
|
-
* fileUpload -> Sessions -> Jobs
|
|
2191
|
-
* construction failure the partial composition unwinds
|
|
2192
|
-
* loader shim is never active during plugin execution.
|
|
1999
|
+
* Compose one fresh official Client `Context` over the M3 in-process carrier:
|
|
2000
|
+
* typert -> Connection (explicit transport) -> Gateway -> the shared Domain
|
|
2001
|
+
* mount ({@link mountRemoteClientDomains}, which owns the `/remote`
|
|
2002
|
+
* contributions and the fileUpload -> Sessions -> Jobs plugins) -> initial
|
|
2003
|
+
* readiness. On construction failure the partial composition unwinds
|
|
2004
|
+
* immediately; the loader shim is never active during plugin execution.
|
|
2193
2005
|
*/
|
|
2194
2006
|
async function createRemoteClientRuntime(options) {
|
|
2195
2007
|
const modules = await loadOfficialClientModulesOnce();
|
|
@@ -2198,42 +2010,35 @@ async function createRemoteClientRuntime(options) {
|
|
|
2198
2010
|
let typertFiber;
|
|
2199
2011
|
let connectionFiber;
|
|
2200
2012
|
let gatewayFiber;
|
|
2201
|
-
let
|
|
2202
|
-
let sessionFiber;
|
|
2203
|
-
let jobsFiber;
|
|
2204
|
-
let services;
|
|
2205
|
-
const contributionDisposers = [];
|
|
2013
|
+
let domains;
|
|
2206
2014
|
let disposed = false;
|
|
2207
2015
|
/**
|
|
2208
|
-
* The frozen §16 shutdown sequence:
|
|
2209
|
-
* `/remote` contributions
|
|
2210
|
-
* then the Client root. Unwinding a partial composition
|
|
2211
|
-
* order over whatever subset exists
|
|
2212
|
-
* already assigned, so it unwinds at its own position; only stages that
|
|
2213
|
-
* were never reached are skipped.
|
|
2016
|
+
* The frozen §16 shutdown sequence: the shared Domain mount (Jobs -> Sessions
|
|
2017
|
+
* -> fileUpload -> `/remote` contributions reverse), Gateway/Connection/
|
|
2018
|
+
* Typert (reverse), then the Client root. Unwinding a partial composition
|
|
2019
|
+
* runs the SAME order over whatever subset exists.
|
|
2214
2020
|
*
|
|
2215
|
-
*
|
|
2216
|
-
*
|
|
2217
|
-
*
|
|
2218
|
-
*
|
|
2021
|
+
* A Domain teardown failure is collected (never allowed to truncate the
|
|
2022
|
+
* remaining cleanup). Cordis contains unload-disposer failures inside
|
|
2023
|
+
* `fiber.dispose()` (they are logged there, never propagated), so the
|
|
2024
|
+
* remaining fiber steps cannot reject.
|
|
2219
2025
|
*
|
|
2220
|
-
* @returns the collected
|
|
2026
|
+
* @returns the collected cleanup errors.
|
|
2221
2027
|
*/
|
|
2222
2028
|
const shutdown = async () => {
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
contributionDisposers.length = 0;
|
|
2029
|
+
const errors = [];
|
|
2030
|
+
try {
|
|
2031
|
+
await domains?.dispose();
|
|
2032
|
+
} catch (error) {
|
|
2033
|
+
errors.push(error);
|
|
2034
|
+
}
|
|
2230
2035
|
for (const fiber of [
|
|
2231
2036
|
gatewayFiber,
|
|
2232
2037
|
connectionFiber,
|
|
2233
2038
|
typertFiber
|
|
2234
2039
|
]) await fiber?.dispose();
|
|
2235
2040
|
await context.fiber.dispose();
|
|
2236
|
-
return
|
|
2041
|
+
return errors;
|
|
2237
2042
|
};
|
|
2238
2043
|
const unwind = async () => {
|
|
2239
2044
|
disposed = true;
|
|
@@ -2255,33 +2060,26 @@ async function createRemoteClientRuntime(options) {
|
|
|
2255
2060
|
await connectionFiber;
|
|
2256
2061
|
gatewayFiber = context.plugin(modules.gateway);
|
|
2257
2062
|
await gatewayFiber;
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
sessionFiber = context.plugin(modules.session);
|
|
2263
|
-
await sessionFiber;
|
|
2264
|
-
jobsFiber = context.plugin(modules.jobs);
|
|
2265
|
-
await jobsFiber;
|
|
2266
|
-
services = {
|
|
2267
|
-
connection: context.get("connection"),
|
|
2268
|
-
sessions: context.get("sessions"),
|
|
2269
|
-
jobs: context.get("jobs")
|
|
2270
|
-
};
|
|
2271
|
-
await waitForInitialReadiness(services.connection, services.sessions, options.signal);
|
|
2063
|
+
domains = await mountRemoteClientDomains({
|
|
2064
|
+
context,
|
|
2065
|
+
...options.signal === void 0 ? {} : { signal: options.signal }
|
|
2066
|
+
});
|
|
2272
2067
|
} catch (error) {
|
|
2273
2068
|
const cleanupErrors = await unwind();
|
|
2274
2069
|
const failure = error instanceof Error ? error : new Error(String(error));
|
|
2275
|
-
if (cleanupErrors.length > 0)
|
|
2070
|
+
if (cleanupErrors.length > 0) {
|
|
2071
|
+
const secondary = cleanupErrors.length === 1 ? cleanupErrors[0] : new AggregateError(cleanupErrors, "remote client runtime: unwind disposal failures");
|
|
2072
|
+
mergeCause(failure, secondary);
|
|
2073
|
+
}
|
|
2276
2074
|
throw failure;
|
|
2277
2075
|
}
|
|
2278
|
-
const
|
|
2076
|
+
const mounted = domains;
|
|
2279
2077
|
return {
|
|
2280
2078
|
context,
|
|
2281
|
-
connection,
|
|
2282
|
-
sessions,
|
|
2283
|
-
jobs,
|
|
2284
|
-
remote:
|
|
2079
|
+
connection: mounted.connection,
|
|
2080
|
+
sessions: mounted.sessions,
|
|
2081
|
+
jobs: mounted.jobs,
|
|
2082
|
+
remote: mounted.remote,
|
|
2285
2083
|
async dispose() {
|
|
2286
2084
|
if (disposed) return;
|
|
2287
2085
|
disposed = true;
|
|
@@ -2436,85 +2234,259 @@ var RemotePromptSerializerProduction = class RemotePromptSerializerProduction {
|
|
|
2436
2234
|
}
|
|
2437
2235
|
}
|
|
2438
2236
|
}
|
|
2439
|
-
return {
|
|
2440
|
-
kind: "ok",
|
|
2441
|
-
echo: {
|
|
2442
|
-
text: prompt.segments.map((segment) => segment.type === "text" ? segment.text : segment.type === "image" ? "[image]" : "[file]").join(""),
|
|
2443
|
-
attachments: prompt.segments.filter((segment) => segment.type === "image").map((segment) => previewOf(segment.image))
|
|
2444
|
-
}
|
|
2445
|
-
};
|
|
2237
|
+
return {
|
|
2238
|
+
kind: "ok",
|
|
2239
|
+
echo: {
|
|
2240
|
+
text: prompt.segments.map((segment) => segment.type === "text" ? segment.text : segment.type === "image" ? "[image]" : "[file]").join(""),
|
|
2241
|
+
attachments: prompt.segments.filter((segment) => segment.type === "image").map((segment) => previewOf(segment.image))
|
|
2242
|
+
}
|
|
2243
|
+
};
|
|
2244
|
+
}
|
|
2245
|
+
async serialize(prepared, signal) {
|
|
2246
|
+
const prompt = prepared;
|
|
2247
|
+
if (prompt === void 0 || prompt === null || typeof prompt !== "object" || !Array.isArray(prompt.segments)) return {
|
|
2248
|
+
kind: "unsupported",
|
|
2249
|
+
reason: "the submission carries no prepared prompt snapshot"
|
|
2250
|
+
};
|
|
2251
|
+
if (prompt.hasFiles) return {
|
|
2252
|
+
kind: "unsupported",
|
|
2253
|
+
reason: "generic file attachments require an upload receipt this Remote composition does not provide"
|
|
2254
|
+
};
|
|
2255
|
+
const parts = [];
|
|
2256
|
+
for (const segment of prompt.segments) {
|
|
2257
|
+
signal?.throwIfAborted();
|
|
2258
|
+
if (segment.type === "text") {
|
|
2259
|
+
if (segment.text !== "") parts.push({
|
|
2260
|
+
type: "text",
|
|
2261
|
+
text: segment.text
|
|
2262
|
+
});
|
|
2263
|
+
continue;
|
|
2264
|
+
}
|
|
2265
|
+
if (segment.type === "image") {
|
|
2266
|
+
const image = segment.image;
|
|
2267
|
+
if (image.recalledRef !== void 0) {
|
|
2268
|
+
const read = await this.attachments.readAttachment(prompt.sessionId, image.recalledRef.attachmentId);
|
|
2269
|
+
signal?.throwIfAborted();
|
|
2270
|
+
if (!read.ok) return {
|
|
2271
|
+
kind: "unsupported",
|
|
2272
|
+
reason: `the durable image bytes could not be read for re-send (${String(read.error)})`
|
|
2273
|
+
};
|
|
2274
|
+
parts.push({
|
|
2275
|
+
type: "image",
|
|
2276
|
+
mediaType: image.mediaType,
|
|
2277
|
+
data: base64Of(read.data),
|
|
2278
|
+
...image.name !== void 0 ? { name: image.name } : {}
|
|
2279
|
+
});
|
|
2280
|
+
continue;
|
|
2281
|
+
}
|
|
2282
|
+
parts.push({
|
|
2283
|
+
type: "image",
|
|
2284
|
+
mediaType: image.mediaType,
|
|
2285
|
+
data: base64Of(image.bytes),
|
|
2286
|
+
...image.name !== void 0 ? { name: image.name } : {}
|
|
2287
|
+
});
|
|
2288
|
+
}
|
|
2289
|
+
}
|
|
2290
|
+
return {
|
|
2291
|
+
kind: "ok",
|
|
2292
|
+
content: Object.freeze(parts)
|
|
2293
|
+
};
|
|
2294
|
+
}
|
|
2295
|
+
};
|
|
2296
|
+
//#endregion
|
|
2297
|
+
//#region src/runtime/remote/host-user-shell-remote.ts
|
|
2298
|
+
/** The one truthful message every Remote admission returns. */
|
|
2299
|
+
const CARRIER_GAP_MESSAGE = "Host user-shell execution is unavailable in this Remote composition — nothing was executed";
|
|
2300
|
+
/** The Remote backend's Host user-shell port: truthful, inert, fail-closed. */
|
|
2301
|
+
var RemoteHostUserShellPort = class {
|
|
2302
|
+
availability = {
|
|
2303
|
+
supported: false,
|
|
2304
|
+
policies: []
|
|
2305
|
+
};
|
|
2306
|
+
async execute(_request) {
|
|
2307
|
+
return {
|
|
2308
|
+
kind: "unavailable",
|
|
2309
|
+
reason: {
|
|
2310
|
+
reason: "carrier-gap",
|
|
2311
|
+
message: CARRIER_GAP_MESSAGE
|
|
2312
|
+
}
|
|
2313
|
+
};
|
|
2314
|
+
}
|
|
2315
|
+
};
|
|
2316
|
+
//#endregion
|
|
2317
|
+
//#region src/app/remote/host-prerequisites.ts
|
|
2318
|
+
/**
|
|
2319
|
+
* Host services the ordinary Host Context must already expose before any
|
|
2320
|
+
* Remote Host row mounts. The check fails fast with the missing service named
|
|
2321
|
+
* instead of parking the runtime.
|
|
2322
|
+
*/
|
|
2323
|
+
const REMOTE_HOST_PREREQUISITE_SERVICES = [
|
|
2324
|
+
"credentials",
|
|
2325
|
+
"userQuestions",
|
|
2326
|
+
"typert",
|
|
2327
|
+
"typertGateway",
|
|
2328
|
+
"agents",
|
|
2329
|
+
"agentDefaultModel",
|
|
2330
|
+
"attachments",
|
|
2331
|
+
"commands",
|
|
2332
|
+
"fileReferences",
|
|
2333
|
+
"fs",
|
|
2334
|
+
"workingDirectory",
|
|
2335
|
+
"llm",
|
|
2336
|
+
"sessions",
|
|
2337
|
+
"sessionProjections",
|
|
2338
|
+
"sessionQuery",
|
|
2339
|
+
"workspaceRegistry",
|
|
2340
|
+
"jobController",
|
|
2341
|
+
"workspaceFiles"
|
|
2342
|
+
];
|
|
2343
|
+
/**
|
|
2344
|
+
* Fail fast when the ordinary Host lacks one of the required base services.
|
|
2345
|
+
* Reads via the reflect store so the diagnostic can name the missing key
|
|
2346
|
+
* without depending on any one service's shape.
|
|
2347
|
+
*/
|
|
2348
|
+
function assertRemoteHostPrerequisites(hostContext) {
|
|
2349
|
+
for (const service of REMOTE_HOST_PREREQUISITE_SERVICES) if (hostContext.reflect.get(service) === void 0) throw new Error(`remote host runtime: the Host Context is missing the required "${service}" service`);
|
|
2350
|
+
}
|
|
2351
|
+
//#endregion
|
|
2352
|
+
//#region src/app/remote/host-runtime.ts
|
|
2353
|
+
/**
|
|
2354
|
+
* Fixed private base URL used only to construct valid `Request` objects for
|
|
2355
|
+
* the shared Fetch handler. It is not a global location, a server URL, a TCP
|
|
2356
|
+
* listener, or an authentication surface.
|
|
2357
|
+
*/
|
|
2358
|
+
const IN_PROCESS_BASE_URL = "http://dsh-pi-tui-remote.in-process/";
|
|
2359
|
+
async function* emptyUplink() {}
|
|
2360
|
+
/** Build the in-process carrier over the Host connection + gateway seams.
|
|
2361
|
+
*
|
|
2362
|
+
* The carrier speaks for the Host Connection's OWN owner Peer
|
|
2363
|
+
* (`HostConnectionService.browserPeer`, created inside the service constructor
|
|
2364
|
+
* with `principal: { kind: 'owner' }` and disposed by the Connection plugin
|
|
2365
|
+
* fiber). The SAME reference is passed to the shared Fetch handler and to
|
|
2366
|
+
* `wireStream.open`, so one identity — and one lifetime — covers both the
|
|
2367
|
+
* unary and the streaming path; the carrier never creates, caches, or disposes
|
|
2368
|
+
* a Peer of its own. */
|
|
2369
|
+
function createInProcessCarrier(hostContext) {
|
|
2370
|
+
const connection = hostContext.connection;
|
|
2371
|
+
const peer = connection.browserPeer;
|
|
2372
|
+
const shared = connection.createSharedFetchHandler("/api");
|
|
2373
|
+
const gateway = hostContext.typertGateway;
|
|
2374
|
+
return {
|
|
2375
|
+
ownsHost: true,
|
|
2376
|
+
fetch(input, init) {
|
|
2377
|
+
const request = input instanceof Request ? new Request(input, init) : new Request(new URL(String(input), IN_PROCESS_BASE_URL), init);
|
|
2378
|
+
return shared.fetch(request, peer);
|
|
2379
|
+
},
|
|
2380
|
+
openStream(endpoint, payload, signal, uplink) {
|
|
2381
|
+
return (async function* () {
|
|
2382
|
+
yield* await gateway.wireStream.open(endpoint, payload, uplink ?? emptyUplink(), peer, signal);
|
|
2383
|
+
})();
|
|
2384
|
+
}
|
|
2385
|
+
};
|
|
2386
|
+
}
|
|
2387
|
+
/**
|
|
2388
|
+
* Mount the exact M3-only additive official Host closure onto the existing Host
|
|
2389
|
+
* Context and await every fiber. The caller must already have mounted the
|
|
2390
|
+
* built-in PiTui Host Runtime (private services + readiness) and the
|
|
2391
|
+
* Performance projection row exactly once; this function verifies both
|
|
2392
|
+
* readiness gates and then mounts only the M3-only official additive fibers.
|
|
2393
|
+
*
|
|
2394
|
+
* The existing `jobController`/`userQuestions` services are asserted before and
|
|
2395
|
+
* after construction and never re-mounted.
|
|
2396
|
+
*
|
|
2397
|
+
* On a partial construction failure the already-mounted fibers unwind in
|
|
2398
|
+
* reverse order before the original error rethrows.
|
|
2399
|
+
*/
|
|
2400
|
+
async function createRemoteHostRuntime(hostContext) {
|
|
2401
|
+
assertRemoteHostPrerequisites(hostContext);
|
|
2402
|
+
for (const service of [
|
|
2403
|
+
"piTuiHostReady",
|
|
2404
|
+
"piTuiFileReferences",
|
|
2405
|
+
"piTuiTerminalProgress",
|
|
2406
|
+
"piTuiPerformanceReady"
|
|
2407
|
+
]) if (hostContext.reflect.get(service) === void 0) throw new Error(`remote host runtime: the M3 composition requires the mounted PiTui Host Runtime and Performance row; missing "${service}"`);
|
|
2408
|
+
const jobControllerBefore = hostContext.reflect.get("jobController");
|
|
2409
|
+
const userQuestionsBefore = hostContext.reflect.get("userQuestions");
|
|
2410
|
+
const fibers = [];
|
|
2411
|
+
let carrier;
|
|
2412
|
+
let disposed = false;
|
|
2413
|
+
/**
|
|
2414
|
+
* Reverse-dispose every mounted fiber. Per-step error isolation: one
|
|
2415
|
+
* rejecting disposer cannot truncate the remaining cleanup. Returns the
|
|
2416
|
+
* collected disposal errors instead of throwing, so the construction
|
|
2417
|
+
* failure path can rethrow the ORIGINAL error with the cleanup failures
|
|
2418
|
+
* attached as its `cause`.
|
|
2419
|
+
*/
|
|
2420
|
+
const collectUnwind = async () => {
|
|
2421
|
+
const errors = [];
|
|
2422
|
+
for (let index = fibers.length - 1; index >= 0; index -= 1) try {
|
|
2423
|
+
await fibers[index].dispose();
|
|
2424
|
+
} catch (error) {
|
|
2425
|
+
errors.push(error);
|
|
2426
|
+
}
|
|
2427
|
+
fibers.length = 0;
|
|
2428
|
+
return errors;
|
|
2429
|
+
};
|
|
2430
|
+
try {
|
|
2431
|
+
const connFiber = hostContext.plugin((connectionContext) => {
|
|
2432
|
+
new HostConnectionService(connectionContext, [], {});
|
|
2433
|
+
});
|
|
2434
|
+
fibers.push(connFiber);
|
|
2435
|
+
await connFiber;
|
|
2436
|
+
const uploadFiber = hostContext.plugin(FileUploads);
|
|
2437
|
+
fibers.push(uploadFiber);
|
|
2438
|
+
await uploadFiber;
|
|
2439
|
+
const statsFiber = hostContext.plugin(sessionStats);
|
|
2440
|
+
fibers.push(statsFiber);
|
|
2441
|
+
await statsFiber;
|
|
2442
|
+
const outlineFiber = hostContext.plugin(sessionTurnOutline);
|
|
2443
|
+
fibers.push(outlineFiber);
|
|
2444
|
+
await outlineFiber;
|
|
2445
|
+
const sessionCtrlFiber = hostContext.inject(SessionController.inject, (controllerContext) => {
|
|
2446
|
+
new SessionController(controllerContext, { nativeOpen: false });
|
|
2447
|
+
});
|
|
2448
|
+
fibers.push(sessionCtrlFiber);
|
|
2449
|
+
await sessionCtrlFiber;
|
|
2450
|
+
const settingsFiber = hostContext.plugin(SettingsController);
|
|
2451
|
+
fibers.push(settingsFiber);
|
|
2452
|
+
await settingsFiber;
|
|
2453
|
+
const remotesFiber = hostContext.plugin({
|
|
2454
|
+
inject,
|
|
2455
|
+
apply
|
|
2456
|
+
});
|
|
2457
|
+
fibers.push(remotesFiber);
|
|
2458
|
+
await remotesFiber;
|
|
2459
|
+
const exportFiber = hostContext.plugin(sessionLogExport);
|
|
2460
|
+
fibers.push(exportFiber);
|
|
2461
|
+
await exportFiber;
|
|
2462
|
+
const jobControllerAfter = hostContext.reflect.get("jobController");
|
|
2463
|
+
if (jobControllerAfter === void 0 || jobControllerAfter.typertRemote === void 0 || jobControllerAfter.typertRemote !== jobControllerBefore.typertRemote) throw new Error("remote host runtime: the existing jobController service was replaced by the M3 composition");
|
|
2464
|
+
const userQuestionsAfter = hostContext.reflect.get("userQuestions");
|
|
2465
|
+
if (userQuestionsAfter === void 0 || userQuestionsAfter.typertRemote === void 0 || userQuestionsAfter.typertRemote !== userQuestionsBefore?.typertRemote) throw new Error("remote host runtime: the existing userQuestions service was replaced by the M3 composition");
|
|
2466
|
+
carrier = createInProcessCarrier(hostContext);
|
|
2467
|
+
} catch (error) {
|
|
2468
|
+
const disposeErrors = await collectUnwind();
|
|
2469
|
+
if (disposeErrors.length > 0) {
|
|
2470
|
+
const secondary = disposeErrors.length === 1 ? disposeErrors[0] : new AggregateError(disposeErrors, "remote host runtime: unwind disposal failures");
|
|
2471
|
+
throw mergeCause(error instanceof Error ? error : new Error(String(error)), secondary);
|
|
2472
|
+
}
|
|
2473
|
+
throw error;
|
|
2446
2474
|
}
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
for (const segment of prompt.segments) {
|
|
2459
|
-
signal?.throwIfAborted();
|
|
2460
|
-
if (segment.type === "text") {
|
|
2461
|
-
if (segment.text !== "") parts.push({
|
|
2462
|
-
type: "text",
|
|
2463
|
-
text: segment.text
|
|
2464
|
-
});
|
|
2465
|
-
continue;
|
|
2466
|
-
}
|
|
2467
|
-
if (segment.type === "image") {
|
|
2468
|
-
const image = segment.image;
|
|
2469
|
-
if (image.recalledRef !== void 0) {
|
|
2470
|
-
const read = await this.attachments.readAttachment(prompt.sessionId, image.recalledRef.attachmentId);
|
|
2471
|
-
signal?.throwIfAborted();
|
|
2472
|
-
if (!read.ok) return {
|
|
2473
|
-
kind: "unsupported",
|
|
2474
|
-
reason: `the durable image bytes could not be read for re-send (${String(read.error)})`
|
|
2475
|
-
};
|
|
2476
|
-
parts.push({
|
|
2477
|
-
type: "image",
|
|
2478
|
-
mediaType: image.mediaType,
|
|
2479
|
-
data: base64Of(read.data),
|
|
2480
|
-
...image.name !== void 0 ? { name: image.name } : {}
|
|
2481
|
-
});
|
|
2482
|
-
continue;
|
|
2483
|
-
}
|
|
2484
|
-
parts.push({
|
|
2485
|
-
type: "image",
|
|
2486
|
-
mediaType: image.mediaType,
|
|
2487
|
-
data: base64Of(image.bytes),
|
|
2488
|
-
...image.name !== void 0 ? { name: image.name } : {}
|
|
2489
|
-
});
|
|
2475
|
+
return {
|
|
2476
|
+
hostContext,
|
|
2477
|
+
carrier,
|
|
2478
|
+
async dispose() {
|
|
2479
|
+
if (disposed) return;
|
|
2480
|
+
disposed = true;
|
|
2481
|
+
const disposeErrors = await collectUnwind();
|
|
2482
|
+
if (disposeErrors.length > 0) {
|
|
2483
|
+
const failure = disposeErrors[0] instanceof Error ? disposeErrors[0] : new Error(String(disposeErrors[0]));
|
|
2484
|
+
if (disposeErrors.length > 1) mergeCause(failure, new AggregateError(disposeErrors.slice(1), "remote host runtime: remaining disposal failures"));
|
|
2485
|
+
throw failure;
|
|
2490
2486
|
}
|
|
2491
2487
|
}
|
|
2492
|
-
return {
|
|
2493
|
-
kind: "ok",
|
|
2494
|
-
content: Object.freeze(parts)
|
|
2495
|
-
};
|
|
2496
|
-
}
|
|
2497
|
-
};
|
|
2498
|
-
//#endregion
|
|
2499
|
-
//#region src/runtime/remote/host-user-shell-remote.ts
|
|
2500
|
-
/** The one truthful message every Remote admission returns. */
|
|
2501
|
-
const CARRIER_GAP_MESSAGE = "Host user-shell execution is unavailable in this Remote composition — nothing was executed";
|
|
2502
|
-
/** The Remote backend's Host user-shell port: truthful, inert, fail-closed. */
|
|
2503
|
-
var RemoteHostUserShellPort = class {
|
|
2504
|
-
availability = {
|
|
2505
|
-
supported: false,
|
|
2506
|
-
policies: []
|
|
2507
2488
|
};
|
|
2508
|
-
|
|
2509
|
-
return {
|
|
2510
|
-
kind: "unavailable",
|
|
2511
|
-
reason: {
|
|
2512
|
-
reason: "carrier-gap",
|
|
2513
|
-
message: CARRIER_GAP_MESSAGE
|
|
2514
|
-
}
|
|
2515
|
-
};
|
|
2516
|
-
}
|
|
2517
|
-
};
|
|
2489
|
+
}
|
|
2518
2490
|
//#endregion
|
|
2519
2491
|
//#region src/runtime/remote/interaction-remote.ts
|
|
2520
2492
|
const USER_QUESTIONS_PROJECTION_KEY = "userQuestions";
|
|
@@ -2580,14 +2552,19 @@ var RemoteQuestionInteractionPort = class {
|
|
|
2580
2552
|
sessions;
|
|
2581
2553
|
remote;
|
|
2582
2554
|
generation;
|
|
2555
|
+
onQualification;
|
|
2583
2556
|
/** Every subscription this adapter owns, released exactly once. */
|
|
2584
2557
|
owned = [];
|
|
2585
|
-
|
|
2558
|
+
registerDelivery;
|
|
2559
|
+
constructor(source, registerDelivery) {
|
|
2586
2560
|
this.sessions = source.sessions;
|
|
2587
2561
|
this.remote = source.remote;
|
|
2588
2562
|
this.generation = source.connection.generation;
|
|
2563
|
+
this.onQualification = source.onQualification;
|
|
2564
|
+
this.registerDelivery = registerDelivery;
|
|
2589
2565
|
}
|
|
2590
2566
|
onRequest(provider) {
|
|
2567
|
+
if (this.registerDelivery !== void 0) return this.registerDelivery(provider);
|
|
2591
2568
|
const sessions = this.sessions;
|
|
2592
2569
|
this.owned.push(this.remote.$on("user-questions/request", function(request, next) {
|
|
2593
2570
|
const sessionId = sessions.scopeOf(this);
|
|
@@ -2714,6 +2691,12 @@ var RemoteQuestionInteractionPort = class {
|
|
|
2714
2691
|
async answerContinued(sessionId, callId, answer) {
|
|
2715
2692
|
if (this.generation.getSnapshot() === void 0) throw new SupersededReadError("the question answer was not dispatched: no current Connection generation");
|
|
2716
2693
|
const result = await this.remote.userQuestions.answer(sessionId, callId, answer);
|
|
2694
|
+
const classification = result.ok ? result.value ? "queued" : "not-continued" : "error";
|
|
2695
|
+
this.onQualification?.({
|
|
2696
|
+
op: "question-answer-continued",
|
|
2697
|
+
callId,
|
|
2698
|
+
result: classification
|
|
2699
|
+
});
|
|
2717
2700
|
if (!result.ok) throw new QuestionAnswerError(remoteFailureCode(result.error) ?? "question/answer-failed", remoteFailureMessage(result.error));
|
|
2718
2701
|
return result.value ? "queued" : "not-continued";
|
|
2719
2702
|
}
|
|
@@ -2725,15 +2708,51 @@ var RemoteInteractionPort = class {
|
|
|
2725
2708
|
/** Every subscription this port owns, released exactly once. */
|
|
2726
2709
|
owned = [];
|
|
2727
2710
|
questionsPort;
|
|
2711
|
+
delivery;
|
|
2712
|
+
surfaceRevision;
|
|
2713
|
+
/** The split-delivery providers supplied by the CURRENT surface revision. */
|
|
2714
|
+
pendingQuestion;
|
|
2715
|
+
pendingApproval;
|
|
2716
|
+
deliveryDisposer;
|
|
2728
2717
|
constructor(source) {
|
|
2729
2718
|
this.remote = source.remote;
|
|
2730
|
-
this.
|
|
2719
|
+
this.delivery = source.delivery;
|
|
2720
|
+
this.surfaceRevision = source.surfaceRevision ?? 0;
|
|
2721
|
+
this.questionsPort = new RemoteQuestionInteractionPort(source, this.delivery === void 0 ? void 0 : (provider) => this.registerQuestion(provider));
|
|
2731
2722
|
this.questions = this.questionsPort;
|
|
2732
2723
|
}
|
|
2724
|
+
registerQuestion(provider) {
|
|
2725
|
+
this.pendingQuestion = provider;
|
|
2726
|
+
this.attachDeliveryWhenComplete();
|
|
2727
|
+
return true;
|
|
2728
|
+
}
|
|
2729
|
+
attachDeliveryWhenComplete() {
|
|
2730
|
+
if (this.delivery === void 0 || this.deliveryDisposer !== void 0) return;
|
|
2731
|
+
if (this.pendingQuestion === void 0 || this.pendingApproval === void 0) return;
|
|
2732
|
+
this.deliveryDisposer = this.delivery.attachSurface(this.surfaceRevision, {
|
|
2733
|
+
onQuestion: this.pendingQuestion,
|
|
2734
|
+
onApproval: this.pendingApproval
|
|
2735
|
+
});
|
|
2736
|
+
}
|
|
2733
2737
|
onApprovalRequest(listener) {
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2738
|
+
if (this.delivery === void 0) {
|
|
2739
|
+
this.owned.push(this.remote.$on("approval/request", function(request, next) {
|
|
2740
|
+
return listener(request, next);
|
|
2741
|
+
}));
|
|
2742
|
+
return;
|
|
2743
|
+
}
|
|
2744
|
+
this.pendingApproval = listener;
|
|
2745
|
+
this.attachDeliveryWhenComplete();
|
|
2746
|
+
}
|
|
2747
|
+
/**
|
|
2748
|
+
* Revoke the current surface's presentation token BEFORE the surface owner
|
|
2749
|
+
* withdraws its modal promises. A local teardown result must never be
|
|
2750
|
+
* forwarded as a Host decision; the root delivery then holds the official
|
|
2751
|
+
* invocation for a replacement surface (or the request lifetime).
|
|
2752
|
+
*/
|
|
2753
|
+
detachSurface() {
|
|
2754
|
+
this.deliveryDisposer?.();
|
|
2755
|
+
this.deliveryDisposer = void 0;
|
|
2737
2756
|
}
|
|
2738
2757
|
/**
|
|
2739
2758
|
* Release every subscription this adapter owns. The assembly runs it BEFORE
|
|
@@ -2741,6 +2760,7 @@ var RemoteInteractionPort = class {
|
|
|
2741
2760
|
* forwarded-event listener never outlives its owner.
|
|
2742
2761
|
*/
|
|
2743
2762
|
dispose() {
|
|
2763
|
+
this.detachSurface();
|
|
2744
2764
|
this.questionsPort.dispose();
|
|
2745
2765
|
for (const off of this.owned.splice(0)) off();
|
|
2746
2766
|
}
|
|
@@ -2890,6 +2910,90 @@ var RemotePluginManagerPort = class {
|
|
|
2890
2910
|
}
|
|
2891
2911
|
};
|
|
2892
2912
|
//#endregion
|
|
2913
|
+
//#region src/runtime/remote/deliverables-remote.ts
|
|
2914
|
+
/**
|
|
2915
|
+
* The experimental Remote delivered-file read adapter (Delivered files PR2 /
|
|
2916
|
+
* M11): the semantic {@link DeliveredFileReadPort} over the OFFICIAL generated
|
|
2917
|
+
* `workspaceFiles` Remote namespace.
|
|
2918
|
+
*
|
|
2919
|
+
* The Host remains the only authority for the Session's workspace scope, the
|
|
2920
|
+
* byte/line caps and the refusal taxonomy; this adapter owns no workspace
|
|
2921
|
+
* truth and never falls back to a Direct read or the Client filesystem.
|
|
2922
|
+
*
|
|
2923
|
+
* CURRENTNESS: the Connection generation is captured BEFORE dispatch and
|
|
2924
|
+
* compared after it — a reply (success OR refusal) carried by a superseded
|
|
2925
|
+
* generation is stale, so it becomes the repository's existing
|
|
2926
|
+
* `SupersededReadError` instead of the new generation's definite outcome. An
|
|
2927
|
+
* unchanged generation preserves the official refusal (mapped to the port's
|
|
2928
|
+
* vocabulary) and the caller's own cancellation.
|
|
2929
|
+
*
|
|
2930
|
+
* Full contract: docs/architecture/host-client.md.
|
|
2931
|
+
* @module @xmoon76/dsh-pi-tui/runtime/remote/deliverables-remote
|
|
2932
|
+
*/
|
|
2933
|
+
function statOf(value) {
|
|
2934
|
+
return value.bytes === void 0 ? { version: value.version } : {
|
|
2935
|
+
version: value.version,
|
|
2936
|
+
bytes: value.bytes
|
|
2937
|
+
};
|
|
2938
|
+
}
|
|
2939
|
+
/** One official result's business value, or its refusal thrown. */
|
|
2940
|
+
function unwrap(result) {
|
|
2941
|
+
if (!result.ok) throw result.error;
|
|
2942
|
+
return result.value;
|
|
2943
|
+
}
|
|
2944
|
+
/** Remote delivered-file reads over the generated `workspaceFiles` namespace. */
|
|
2945
|
+
var RemoteDeliveredFileReadPort = class {
|
|
2946
|
+
namespace;
|
|
2947
|
+
generation;
|
|
2948
|
+
constructor(namespace, generation) {
|
|
2949
|
+
this.namespace = namespace;
|
|
2950
|
+
this.generation = generation;
|
|
2951
|
+
}
|
|
2952
|
+
async stat(sessionId, path, signal) {
|
|
2953
|
+
return statOf(await this.fenced("stat", signal, (namespace) => namespace.stat(sessionId, path, signal)));
|
|
2954
|
+
}
|
|
2955
|
+
async read(sessionId, path, offset, signal) {
|
|
2956
|
+
const limit = 120;
|
|
2957
|
+
const page = await this.fenced("read", signal, (namespace) => namespace.read(sessionId, path, {
|
|
2958
|
+
offset,
|
|
2959
|
+
limit
|
|
2960
|
+
}, signal));
|
|
2961
|
+
return {
|
|
2962
|
+
stat: statOf(page),
|
|
2963
|
+
offset,
|
|
2964
|
+
limit,
|
|
2965
|
+
text: page.text,
|
|
2966
|
+
lines: page.lines,
|
|
2967
|
+
eof: page.eof
|
|
2968
|
+
};
|
|
2969
|
+
}
|
|
2970
|
+
/**
|
|
2971
|
+
* One Remote read fenced to the Connection generation captured BEFORE
|
|
2972
|
+
* dispatch. `operation` names the intent in the stale diagnostic.
|
|
2973
|
+
*/
|
|
2974
|
+
async fenced(operation, signal, call) {
|
|
2975
|
+
const namespace = this.namespace;
|
|
2976
|
+
if (namespace === void 0) throw new DeliveredFileReadError("service-unavailable", "the workspaceFiles Remote namespace is not mounted");
|
|
2977
|
+
if (signal.aborted) throw abortReason(signal);
|
|
2978
|
+
const captured = this.generation.getSnapshot();
|
|
2979
|
+
const stillCurrent = () => Object.is(captured, this.generation.getSnapshot());
|
|
2980
|
+
let value;
|
|
2981
|
+
try {
|
|
2982
|
+
value = unwrap(await call(namespace));
|
|
2983
|
+
} catch (error) {
|
|
2984
|
+
if (signal.aborted) throw abortReason(signal);
|
|
2985
|
+
if (!stillCurrent()) throw new SupersededReadError(`delivered file ${operation} superseded`);
|
|
2986
|
+
throw deliveredFileReadErrorFrom(error);
|
|
2987
|
+
}
|
|
2988
|
+
if (!stillCurrent()) throw new SupersededReadError(`delivered file ${operation} superseded`);
|
|
2989
|
+
return value;
|
|
2990
|
+
}
|
|
2991
|
+
};
|
|
2992
|
+
/** The caller's cancellation reason (an `Error` for every standard abort). */
|
|
2993
|
+
function abortReason(signal) {
|
|
2994
|
+
return signal.reason instanceof Error ? signal.reason : /* @__PURE__ */ new Error("delivered file read aborted");
|
|
2995
|
+
}
|
|
2996
|
+
//#endregion
|
|
2893
2997
|
//#region src/runtime/remote/job-observation-remote.ts
|
|
2894
2998
|
/**
|
|
2895
2999
|
* The Job-Stop operation-specific settlement table.
|
|
@@ -3876,8 +3980,16 @@ var RemoteSessionLifecycle = class {
|
|
|
3876
3980
|
}
|
|
3877
3981
|
};
|
|
3878
3982
|
}
|
|
3879
|
-
if (!Object.is(captured, this.generation.getSnapshot())
|
|
3983
|
+
if (isAborted(request.signal) || !Object.is(captured, this.generation.getSnapshot())) {
|
|
3984
|
+
const stateAtLoss = owner.openState();
|
|
3880
3985
|
owner.release();
|
|
3986
|
+
if (stateAtLoss.openState === "open") return {
|
|
3987
|
+
ownership: "superseded",
|
|
3988
|
+
outcome: {
|
|
3989
|
+
kind: "opened",
|
|
3990
|
+
handle: { session: { id: request.sessionId } }
|
|
3991
|
+
}
|
|
3992
|
+
};
|
|
3881
3993
|
return {
|
|
3882
3994
|
ownership: "superseded",
|
|
3883
3995
|
outcome: { kind: "cancelled" }
|
|
@@ -4957,7 +5069,10 @@ function createRemoteM3ASemantics(runtime, options) {
|
|
|
4957
5069
|
userQuestions: remote.userQuestions,
|
|
4958
5070
|
$on: forwardedEvents
|
|
4959
5071
|
},
|
|
4960
|
-
connection: { generation }
|
|
5072
|
+
connection: { generation },
|
|
5073
|
+
...options.delivery === void 0 ? {} : { delivery: options.delivery },
|
|
5074
|
+
...options.surfaceRevision === void 0 ? {} : { surfaceRevision: options.surfaceRevision },
|
|
5075
|
+
...options.onQualification === void 0 ? {} : { onQualification: options.onQualification }
|
|
4961
5076
|
});
|
|
4962
5077
|
const presetCatalog = new RemotePresetCatalog(remote.agentPresets, generation);
|
|
4963
5078
|
let disposed = false;
|
|
@@ -4981,6 +5096,7 @@ function createRemoteM3ASemantics(runtime, options) {
|
|
|
4981
5096
|
$on: forwardedEvents
|
|
4982
5097
|
}, generation),
|
|
4983
5098
|
jobObservation: new RemoteJobObservationPort(runtime.jobs),
|
|
5099
|
+
deliveredFileRead: new RemoteDeliveredFileReadPort(remote.workspaceFiles, generation),
|
|
4984
5100
|
dispose() {
|
|
4985
5101
|
if (disposed) return;
|
|
4986
5102
|
disposed = true;
|
|
@@ -4993,10 +5109,10 @@ function createRemoteM3ASemantics(runtime, options) {
|
|
|
4993
5109
|
//#endregion
|
|
4994
5110
|
//#region src/app/remote/session-owners.ts
|
|
4995
5111
|
/**
|
|
4996
|
-
*
|
|
5112
|
+
* Remote Session owner services: the exact-`SessionBinding` provider of
|
|
4997
5113
|
* the consumer-owned `SessionOwnerAccess` / `SessionOwnerRetirement` seams.
|
|
4998
5114
|
*
|
|
4999
|
-
* Identity authority (
|
|
5115
|
+
* Identity authority (see `docs/architecture/host-client.md`): the exact
|
|
5000
5116
|
* `SessionReference.binding` OBJECT a retained `ClientSessionOwner` carries is
|
|
5001
5117
|
* the generation token —
|
|
5002
5118
|
*
|
|
@@ -5016,19 +5132,32 @@ function createRemoteM3ASemantics(runtime, options) {
|
|
|
5016
5132
|
* owner, so `flush`/`preCancel` are deliberate no-ops, `retire` releases the
|
|
5017
5133
|
* exact Client reference exactly once, and `whenIdleOrAbort` observes the
|
|
5018
5134
|
* official `SessionSnapshot.running` without ever cancelling the Host session.
|
|
5135
|
+
* The ONE Host mutation here is `cancel`: the explicit user Stop addresses the
|
|
5136
|
+
* EXACT captured binding generation through the official `SessionFace.cancel`
|
|
5137
|
+
* verb; it never substitutes a same-id replacement and never releases the
|
|
5138
|
+
* Client reference. The Connection generation is captured before dispatch and
|
|
5139
|
+
* re-checked with the exact binding after the reply, so a superseded reply is
|
|
5140
|
+
* `indeterminate`, never the current generation's definite result. The same
|
|
5141
|
+
* one-shot verb serves the navigation audience through `cancelForNavigation`,
|
|
5142
|
+
* which resolves the dispatch PHASE (a dispatched reply whose classification is
|
|
5143
|
+
* a caller/carrier `cancelled` is dispatched-unproven there) without changing
|
|
5144
|
+
* the control `cancel` taxonomy; only `committed` lets navigation proceed.
|
|
5019
5145
|
*
|
|
5020
|
-
*
|
|
5021
|
-
*
|
|
5022
|
-
*
|
|
5146
|
+
* Composition note: the Remote application runtime constructs this provider
|
|
5147
|
+
* ONCE over the official Client's sessions and Connection generation source.
|
|
5148
|
+
* Tests may construct it directly over a fake binding/generation source.
|
|
5023
5149
|
*
|
|
5024
5150
|
* @module @xmoon76/dsh-pi-tui/app/remote/session-owners
|
|
5025
5151
|
*/
|
|
5026
5152
|
/**
|
|
5027
|
-
* Build the Remote Session owner services over one binding borrow source
|
|
5028
|
-
* `owners` and `retirement` share the SAME
|
|
5029
|
-
* independent mappings would create a second
|
|
5153
|
+
* Build the Remote Session owner services over one binding borrow source and
|
|
5154
|
+
* the Connection generation source. `owners` and `retirement` share the SAME
|
|
5155
|
+
* registry state; constructing two independent mappings would create a second
|
|
5156
|
+
* owner truth. The generation source is the SAME official pre-dispatch fence
|
|
5157
|
+
* the Remote session writer uses: an owner mutation's reply is only a definite
|
|
5158
|
+
* outcome for the generation it was dispatched on.
|
|
5030
5159
|
*/
|
|
5031
|
-
function createRemoteSessionOwnerServices(source) {
|
|
5160
|
+
function createRemoteSessionOwnerServices(source, generation) {
|
|
5032
5161
|
const byBinding = /* @__PURE__ */ new WeakMap();
|
|
5033
5162
|
const byOwner = /* @__PURE__ */ new WeakMap();
|
|
5034
5163
|
const releasedWrappers = /* @__PURE__ */ new WeakSet();
|
|
@@ -5065,26 +5194,123 @@ function createRemoteSessionOwnerServices(source) {
|
|
|
5065
5194
|
return existing;
|
|
5066
5195
|
};
|
|
5067
5196
|
const sessionId = (owner) => recordOf(owner).sessionId;
|
|
5068
|
-
|
|
5197
|
+
/**
|
|
5198
|
+
* The ONE exact-owner cancel body. `dispatched` records whether the official
|
|
5199
|
+
* `SessionFace.cancel()` was actually invoked: a local fence can prove it was
|
|
5200
|
+
* not; every reply (including a cancelled/superseded one) is about a call
|
|
5201
|
+
* that WAS made. The control audience projects only `outcome` (PR-A's
|
|
5202
|
+
* taxonomy is unchanged); the navigation audience resolves the phase.
|
|
5203
|
+
*/
|
|
5204
|
+
const cancelExactOwner = async (owner) => {
|
|
5205
|
+
const notDispatched = (outcome) => ({
|
|
5206
|
+
outcome,
|
|
5207
|
+
dispatched: false
|
|
5208
|
+
});
|
|
5209
|
+
const record = recordOf(owner);
|
|
5210
|
+
if (record.currentWrapper === void 0) return notDispatched({ kind: "cancelled" });
|
|
5211
|
+
const capturedGeneration = generation.getSnapshot();
|
|
5212
|
+
if (capturedGeneration === void 0) return notDispatched({ kind: "cancelled" });
|
|
5213
|
+
const borrowed = source.binding(record.sessionId);
|
|
5214
|
+
if (borrowed === void 0 || !Object.is(borrowed, record.bindingIdentity)) return notDispatched({ kind: "cancelled" });
|
|
5215
|
+
if (!Object.is(capturedGeneration, generation.getSnapshot())) return notDispatched({ kind: "cancelled" });
|
|
5216
|
+
const result = await borrowed.session.cancel();
|
|
5217
|
+
const currentGeneration = generation.getSnapshot();
|
|
5218
|
+
if (currentGeneration === void 0 || !Object.is(capturedGeneration, currentGeneration) || record.currentWrapper === void 0 || !Object.is(source.binding(record.sessionId), record.bindingIdentity)) return {
|
|
5219
|
+
outcome: {
|
|
5220
|
+
kind: "indeterminate",
|
|
5221
|
+
error: {
|
|
5222
|
+
code: "session/cancel-superseded",
|
|
5223
|
+
message: "the session owner or connection generation changed while the cancel was in flight"
|
|
5224
|
+
}
|
|
5225
|
+
},
|
|
5226
|
+
dispatched: true
|
|
5227
|
+
};
|
|
5228
|
+
if (result.ok) return {
|
|
5229
|
+
outcome: {
|
|
5230
|
+
kind: "committed",
|
|
5231
|
+
value: void 0
|
|
5232
|
+
},
|
|
5233
|
+
dispatched: true,
|
|
5234
|
+
receipt: { token: capturedGeneration }
|
|
5235
|
+
};
|
|
5236
|
+
return {
|
|
5237
|
+
outcome: classifyRemoteWriteFailure(result.error),
|
|
5238
|
+
dispatched: true
|
|
5239
|
+
};
|
|
5240
|
+
};
|
|
5241
|
+
/** The control (Busy Esc / Stop) audience: PR-A's shared write taxonomy. */
|
|
5242
|
+
const cancel = async (owner) => (await cancelExactOwner(owner)).outcome;
|
|
5243
|
+
/**
|
|
5244
|
+
* The navigation audience. The phase is resolved HERE, without changing
|
|
5245
|
+
* `cancel`:
|
|
5246
|
+
* - a pre-dispatch local fence is `cancelled` (the request was not addressed;
|
|
5247
|
+
* never permission to switch);
|
|
5248
|
+
* - a DISPATCHED reply classified as a caller/carrier cancellation is
|
|
5249
|
+
* `indeterminate` (the Host may have executed it) — the control audience
|
|
5250
|
+
* still sees PR-A's `cancelled`;
|
|
5251
|
+
* - a dispatched superseded reply is already `indeterminate`;
|
|
5252
|
+
* - a proven business refusal is `rejected`, success `committed`.
|
|
5253
|
+
*/
|
|
5254
|
+
const cancelForNavigation = async (owner) => {
|
|
5255
|
+
const { outcome, dispatched, receipt } = await cancelExactOwner(owner);
|
|
5256
|
+
switch (outcome.kind) {
|
|
5257
|
+
case "committed": return {
|
|
5258
|
+
kind: "committed",
|
|
5259
|
+
...receipt === void 0 ? {} : { receipt }
|
|
5260
|
+
};
|
|
5261
|
+
case "rejected": return {
|
|
5262
|
+
kind: "rejected",
|
|
5263
|
+
detail: outcome.error.message
|
|
5264
|
+
};
|
|
5265
|
+
case "unsupported": return {
|
|
5266
|
+
kind: "rejected",
|
|
5267
|
+
detail: outcome.reason
|
|
5268
|
+
};
|
|
5269
|
+
case "cancelled": return dispatched ? {
|
|
5270
|
+
kind: "indeterminate",
|
|
5271
|
+
detail: "the Host session cancel was dispatched but its reply was a caller/carrier cancellation"
|
|
5272
|
+
} : { kind: "cancelled" };
|
|
5273
|
+
case "indeterminate": return {
|
|
5274
|
+
kind: "indeterminate",
|
|
5275
|
+
detail: outcome.error.message
|
|
5276
|
+
};
|
|
5277
|
+
}
|
|
5278
|
+
};
|
|
5279
|
+
const whenIdleOrAbort = (owner, signal, receipt) => {
|
|
5069
5280
|
const record = recordOf(owner);
|
|
5281
|
+
const capturedGeneration = receipt === void 0 ? generation.getSnapshot() : receipt.token;
|
|
5282
|
+
if (capturedGeneration === void 0) return Promise.resolve("unobservable");
|
|
5283
|
+
if (!Object.is(generation.getSnapshot(), capturedGeneration)) return Promise.resolve("unobservable");
|
|
5070
5284
|
const borrowed = source.binding(record.sessionId);
|
|
5071
|
-
if (borrowed === void 0 || !Object.is(borrowed, record.bindingIdentity)) return Promise.resolve(
|
|
5285
|
+
if (borrowed === void 0 || !Object.is(borrowed, record.bindingIdentity)) return Promise.resolve("unobservable");
|
|
5286
|
+
const exactBindingCurrent = () => Object.is(source.binding(record.sessionId), record.bindingIdentity) && Object.is(generation.getSnapshot(), capturedGeneration);
|
|
5072
5287
|
const face = borrowed.session;
|
|
5073
|
-
if (!face.getSnapshot().running) return Promise.resolve(false);
|
|
5288
|
+
if (!face.getSnapshot().running) return Promise.resolve(exactBindingCurrent() ? false : "unobservable");
|
|
5074
5289
|
if (signal.aborted) return Promise.resolve(true);
|
|
5075
5290
|
return new Promise((resolve) => {
|
|
5076
5291
|
let settled = false;
|
|
5077
5292
|
let unsubscribe;
|
|
5078
5293
|
let offAbort;
|
|
5079
|
-
|
|
5294
|
+
let offGeneration;
|
|
5295
|
+
let offRetain;
|
|
5296
|
+
const retainInfo = source.retainInfo?.(record.sessionId);
|
|
5297
|
+
const settle = (result) => {
|
|
5080
5298
|
if (settled) return;
|
|
5081
5299
|
settled = true;
|
|
5082
5300
|
unsubscribe?.();
|
|
5083
5301
|
offAbort?.();
|
|
5084
|
-
|
|
5302
|
+
offGeneration?.();
|
|
5303
|
+
offRetain?.();
|
|
5304
|
+
resolve(result);
|
|
5305
|
+
};
|
|
5306
|
+
const onGeneration = () => {
|
|
5307
|
+
if (!Object.is(generation.getSnapshot(), capturedGeneration)) settle("unobservable");
|
|
5308
|
+
};
|
|
5309
|
+
const onRetain = () => {
|
|
5310
|
+
if (!exactBindingCurrent()) settle("unobservable");
|
|
5085
5311
|
};
|
|
5086
5312
|
const onSnapshot = () => {
|
|
5087
|
-
if (!face.getSnapshot().running) settle(false);
|
|
5313
|
+
if (!face.getSnapshot().running) settle(exactBindingCurrent() ? false : "unobservable");
|
|
5088
5314
|
};
|
|
5089
5315
|
const onAbort = () => {
|
|
5090
5316
|
settle(true);
|
|
@@ -5093,9 +5319,13 @@ function createRemoteSessionOwnerServices(source) {
|
|
|
5093
5319
|
offAbort = () => {
|
|
5094
5320
|
signal.removeEventListener("abort", onAbort);
|
|
5095
5321
|
};
|
|
5322
|
+
offGeneration = generation.subscribe(onGeneration);
|
|
5323
|
+
if (settled) offGeneration();
|
|
5324
|
+
offRetain = retainInfo?.subscribe(onRetain);
|
|
5325
|
+
if (settled) offRetain?.();
|
|
5096
5326
|
unsubscribe = face.subscribe(onSnapshot);
|
|
5097
5327
|
if (settled) unsubscribe();
|
|
5098
|
-
if (!face.getSnapshot().running) settle(false);
|
|
5328
|
+
if (!face.getSnapshot().running) settle(exactBindingCurrent() ? false : "unobservable");
|
|
5099
5329
|
if (signal.aborted) settle(true);
|
|
5100
5330
|
});
|
|
5101
5331
|
};
|
|
@@ -5150,6 +5380,8 @@ function createRemoteSessionOwnerServices(source) {
|
|
|
5150
5380
|
},
|
|
5151
5381
|
retirement: {
|
|
5152
5382
|
whenIdleOrAbort,
|
|
5383
|
+
cancel,
|
|
5384
|
+
cancelForNavigation,
|
|
5153
5385
|
flush: async () => {},
|
|
5154
5386
|
preCancel: () => {},
|
|
5155
5387
|
retire,
|
|
@@ -6077,9 +6309,10 @@ function detachedPlan(value) {
|
|
|
6077
6309
|
};
|
|
6078
6310
|
}
|
|
6079
6311
|
/**
|
|
6080
|
-
* Assemble the Remote application presentation source from the ONE
|
|
6081
|
-
*
|
|
6082
|
-
*
|
|
6312
|
+
* Assemble the Remote application presentation source from the ONE shared
|
|
6313
|
+
* Client runtime source (the M3-1 Client runtime or the real split Client's
|
|
6314
|
+
* mounted official Domains). Every member reuses a face that source already
|
|
6315
|
+
* owns: `semantics.presentationReader` by identity, its
|
|
6083
6316
|
* `sessions`/`connection.generation` for the official projection/echo reads,
|
|
6084
6317
|
* and the eventSource borrow for the live ingress. Constructing this bundle
|
|
6085
6318
|
* installs exactly ONE watch — the ingress factory's process-lifetime
|
|
@@ -6089,23 +6322,23 @@ function detachedPlan(value) {
|
|
|
6089
6322
|
* ingress subscription is created lazily by the bootstrap and disposed through
|
|
6090
6323
|
* its own handle.
|
|
6091
6324
|
*/
|
|
6092
|
-
function createRemotePresentationSource(
|
|
6093
|
-
const sessions =
|
|
6094
|
-
const generation =
|
|
6325
|
+
function createRemotePresentationSource(client, backendRuntime) {
|
|
6326
|
+
const sessions = client.sessions;
|
|
6327
|
+
const generation = client.connection.generation;
|
|
6095
6328
|
const sessionReader = backendRuntime.semantics.sessionReader;
|
|
6096
6329
|
const planSource = sessions;
|
|
6097
6330
|
const liveIngress = createRemoteLiveIngress(sessions, generation, CURRENT_STATUS_PROJECTION_KEYS);
|
|
6098
|
-
const taskReader = new RemoteTaskReader(sessions,
|
|
6331
|
+
const taskReader = new RemoteTaskReader(sessions, client.jobs, generation);
|
|
6099
6332
|
return {
|
|
6100
6333
|
presentationReader: backendRuntime.semantics.presentationReader,
|
|
6101
6334
|
commandSource: createRemoteCommandSource({
|
|
6102
|
-
authority:
|
|
6335
|
+
authority: client.remote,
|
|
6103
6336
|
generation,
|
|
6104
6337
|
bindings: sessions
|
|
6105
6338
|
}),
|
|
6106
6339
|
submissionPresentation: new RemoteSubmissionPresentation(sessions, generation),
|
|
6107
6340
|
terminalProgress: createRemoteTerminalProgressSource({
|
|
6108
|
-
remote:
|
|
6341
|
+
remote: client.remote,
|
|
6109
6342
|
generation,
|
|
6110
6343
|
binding: (sessionId) => sessions.binding(sessionId)
|
|
6111
6344
|
}),
|
|
@@ -6158,12 +6391,12 @@ function createRemotePresentationSource(wire, backendRuntime) {
|
|
|
6158
6391
|
},
|
|
6159
6392
|
task: {
|
|
6160
6393
|
readDescendants: (parentSessionId, signal) => taskReader.readDescendants(parentSessionId, signal),
|
|
6161
|
-
jobs: (sessionId) =>
|
|
6394
|
+
jobs: (sessionId) => client.jobs.state.getSnapshot().rows[sessionId] ?? [],
|
|
6162
6395
|
activityOf: (childSessionId) => {
|
|
6163
6396
|
const entry = sessions.list.getSnapshot().byId[childSessionId];
|
|
6164
6397
|
return entry === void 0 ? void 0 : entry.running ? "running" : "inactive";
|
|
6165
6398
|
},
|
|
6166
|
-
subscribeJobs: (listener) =>
|
|
6399
|
+
subscribeJobs: (listener) => client.jobs.state.subscribe(listener),
|
|
6167
6400
|
subscribeSessions: (listener) => sessions.list.subscribe(listener),
|
|
6168
6401
|
dispose: () => taskReader.dispose()
|
|
6169
6402
|
},
|
|
@@ -6264,7 +6497,10 @@ async function createRemoteClientUiRuntime(options) {
|
|
|
6264
6497
|
} catch (error) {
|
|
6265
6498
|
const cleanupErrors = await unwind();
|
|
6266
6499
|
const failure = error instanceof Error ? error : new Error(String(error));
|
|
6267
|
-
if (cleanupErrors.length > 0)
|
|
6500
|
+
if (cleanupErrors.length > 0) {
|
|
6501
|
+
const secondary = cleanupErrors.length === 1 ? cleanupErrors[0] : new AggregateError(cleanupErrors, "remote client UI runtime: unwind disposal failures");
|
|
6502
|
+
mergeCause(failure, secondary);
|
|
6503
|
+
}
|
|
6268
6504
|
throw failure;
|
|
6269
6505
|
}
|
|
6270
6506
|
}
|
|
@@ -6287,21 +6523,21 @@ function throwAggregated(errors, label) {
|
|
|
6287
6523
|
throw failure;
|
|
6288
6524
|
}
|
|
6289
6525
|
/**
|
|
6290
|
-
*
|
|
6291
|
-
*
|
|
6292
|
-
*
|
|
6293
|
-
*
|
|
6294
|
-
*
|
|
6295
|
-
*
|
|
6526
|
+
* The ONE Remote semantic composition stage shared by both public
|
|
6527
|
+
* application-runtime constructors. It composes the Backend, the ONE owner
|
|
6528
|
+
* registry and the presentation bundle over the supplied Client runtime
|
|
6529
|
+
* source. It owns no Context/Connection/Gateway/UI: the caller owns those and
|
|
6530
|
+
* disposes them around this stage.
|
|
6531
|
+
*
|
|
6532
|
+
* Failure semantics: a backend construction failure unwinds inside
|
|
6533
|
+
* `createRemoteBackendRuntime`; a LATER owner/presentation failure disposes the
|
|
6534
|
+
* constructed presentation task/backend before rethrowing, with the original
|
|
6535
|
+
* error primary.
|
|
6296
6536
|
*/
|
|
6297
|
-
async function
|
|
6298
|
-
const wire = await createExperimentalRemoteRuntime({
|
|
6299
|
-
hostContext: options.hostContext,
|
|
6300
|
-
waitForHostPrerequisites: options.waitForHostPrerequisites,
|
|
6301
|
-
signal: options.signal
|
|
6302
|
-
});
|
|
6537
|
+
async function composeRemoteApplicationStage(input) {
|
|
6303
6538
|
let backendRuntime;
|
|
6304
6539
|
let ownerServices;
|
|
6540
|
+
let presentation;
|
|
6305
6541
|
/**
|
|
6306
6542
|
* The composition-owned pre-dispatch write admission: OPEN for the whole live
|
|
6307
6543
|
* surface, closed ONCE and synchronously by the application's surface-stop
|
|
@@ -6312,23 +6548,75 @@ async function createRemoteApplicationRuntime(options) {
|
|
|
6312
6548
|
let dispatchAdmissionOpen = true;
|
|
6313
6549
|
try {
|
|
6314
6550
|
backendRuntime = await createRemoteBackendRuntime({
|
|
6315
|
-
runtime:
|
|
6316
|
-
fetch:
|
|
6551
|
+
runtime: input.client,
|
|
6552
|
+
fetch: input.fetch,
|
|
6317
6553
|
isDispatchAllowed: () => dispatchAdmissionOpen,
|
|
6554
|
+
...input.promptSerializer === void 0 ? {} : { promptSerializer: input.promptSerializer },
|
|
6555
|
+
...input.delivery === void 0 ? {} : { delivery: input.delivery },
|
|
6556
|
+
...input.surfaceRevision === void 0 ? {} : { surfaceRevision: input.surfaceRevision },
|
|
6557
|
+
...input.onQualification === void 0 ? {} : { onQualification: input.onQualification }
|
|
6558
|
+
});
|
|
6559
|
+
ownerServices = createRemoteSessionOwnerServices(input.client.sessions, input.client.connection.generation);
|
|
6560
|
+
presentation = createRemotePresentationSource(input.client, backendRuntime);
|
|
6561
|
+
} catch (error) {
|
|
6562
|
+
const disposeErrors = [...presentation === void 0 ? [] : await collectDisposeErrors$1(() => presentation.task.dispose()), ...backendRuntime === void 0 ? [] : await collectDisposeErrors$1(() => backendRuntime.dispose())];
|
|
6563
|
+
if (disposeErrors.length > 0) {
|
|
6564
|
+
const secondary = disposeErrors.length === 1 ? disposeErrors[0] : new AggregateError(disposeErrors, "remote application runtime: disposal failures during stage construction");
|
|
6565
|
+
throw mergeCause(error instanceof Error ? error : new Error(String(error)), secondary);
|
|
6566
|
+
}
|
|
6567
|
+
throw error;
|
|
6568
|
+
}
|
|
6569
|
+
const composed = {
|
|
6570
|
+
backendRuntime,
|
|
6571
|
+
ownerServices,
|
|
6572
|
+
presentation
|
|
6573
|
+
};
|
|
6574
|
+
let adaptersDisposed = false;
|
|
6575
|
+
return {
|
|
6576
|
+
backendRuntime: composed.backendRuntime,
|
|
6577
|
+
owners: composed.ownerServices.owners,
|
|
6578
|
+
retirement: composed.ownerServices.retirement,
|
|
6579
|
+
presentation: composed.presentation,
|
|
6580
|
+
stopSurfaceAdmission: () => {
|
|
6581
|
+
dispatchAdmissionOpen = false;
|
|
6582
|
+
},
|
|
6583
|
+
async disposeAdapters() {
|
|
6584
|
+
if (adaptersDisposed) return;
|
|
6585
|
+
adaptersDisposed = true;
|
|
6586
|
+
const errors = [...await collectDisposeErrors$1(() => composed.presentation.task.dispose()), ...await collectDisposeErrors$1(() => composed.backendRuntime.dispose())];
|
|
6587
|
+
if (errors.length > 0) throwAggregated(errors, "remote application runtime adapter disposal");
|
|
6588
|
+
}
|
|
6589
|
+
};
|
|
6590
|
+
}
|
|
6591
|
+
/**
|
|
6592
|
+
* Compose the M3 Remote application runtime as ONE graph. Failure semantics: a
|
|
6593
|
+
* Host/Client construction failure unwinds inside
|
|
6594
|
+
* `createExperimentalRemoteRuntime` (no leaked fibers); a backend/owner
|
|
6595
|
+
* failure after the wire exists disposes the wire (both steps run; the
|
|
6596
|
+
* original error surfaces with disposal failures on its cause chain, never
|
|
6597
|
+
* masked by them) and rethrows.
|
|
6598
|
+
*/
|
|
6599
|
+
async function createRemoteApplicationRuntime(options) {
|
|
6600
|
+
const wire = await createExperimentalRemoteRuntime({
|
|
6601
|
+
hostContext: options.hostContext,
|
|
6602
|
+
waitForHostPrerequisites: options.waitForHostPrerequisites,
|
|
6603
|
+
signal: options.signal
|
|
6604
|
+
});
|
|
6605
|
+
let stage;
|
|
6606
|
+
try {
|
|
6607
|
+
stage = await composeRemoteApplicationStage({
|
|
6608
|
+
client: wire.client,
|
|
6609
|
+
fetch: wire.host.carrier.fetch,
|
|
6318
6610
|
...options.promptSerializer === void 0 ? {} : { promptSerializer: options.promptSerializer }
|
|
6319
6611
|
});
|
|
6320
|
-
ownerServices = createRemoteSessionOwnerServices(wire.client.sessions);
|
|
6321
6612
|
} catch (error) {
|
|
6322
|
-
const
|
|
6323
|
-
const disposeErrors = [...constructed !== void 0 ? await collectDisposeErrors$1(() => constructed.dispose()) : [], ...await collectDisposeErrors$1(() => wire.dispose())];
|
|
6613
|
+
const disposeErrors = await collectDisposeErrors$1(() => wire.dispose());
|
|
6324
6614
|
if (disposeErrors.length > 0) {
|
|
6325
|
-
const secondary = disposeErrors.length === 1 ? disposeErrors[0] : new AggregateError(disposeErrors, "remote application runtime: disposal failures during
|
|
6615
|
+
const secondary = disposeErrors.length === 1 ? disposeErrors[0] : new AggregateError(disposeErrors, "remote application runtime: disposal failures during stage-failure unwind");
|
|
6326
6616
|
throw mergeCause(error instanceof Error ? error : new Error(String(error)), secondary);
|
|
6327
6617
|
}
|
|
6328
6618
|
throw error;
|
|
6329
6619
|
}
|
|
6330
|
-
let transportDisposed = false;
|
|
6331
|
-
const presentation = createRemotePresentationSource(wire, backendRuntime);
|
|
6332
6620
|
let clientUi;
|
|
6333
6621
|
try {
|
|
6334
6622
|
clientUi = await createRemoteClientUiRuntime({
|
|
@@ -6336,41 +6624,35 @@ async function createRemoteApplicationRuntime(options) {
|
|
|
6336
6624
|
startup: options.clientUiStartup
|
|
6337
6625
|
});
|
|
6338
6626
|
} catch (error) {
|
|
6339
|
-
const disposeErrors = [
|
|
6340
|
-
...await collectDisposeErrors$1(() => presentation.task.dispose()),
|
|
6341
|
-
...await collectDisposeErrors$1(() => backendRuntime.dispose()),
|
|
6342
|
-
...await collectDisposeErrors$1(() => wire.dispose())
|
|
6343
|
-
];
|
|
6627
|
+
const disposeErrors = [...await collectDisposeErrors$1(() => stage.disposeAdapters()), ...await collectDisposeErrors$1(() => wire.dispose())];
|
|
6344
6628
|
if (disposeErrors.length > 0) {
|
|
6345
6629
|
const secondary = disposeErrors.length === 1 ? disposeErrors[0] : new AggregateError(disposeErrors, "remote application runtime: disposal failures during client-UI construction failure");
|
|
6346
6630
|
throw mergeCause(error instanceof Error ? error : new Error(String(error)), secondary);
|
|
6347
6631
|
}
|
|
6348
6632
|
throw error;
|
|
6349
6633
|
}
|
|
6634
|
+
let transportDisposed = false;
|
|
6350
6635
|
return {
|
|
6351
6636
|
selected: {
|
|
6352
6637
|
kind: "remote",
|
|
6353
|
-
backend: backendRuntime.backend,
|
|
6354
|
-
owners:
|
|
6355
|
-
retirement:
|
|
6356
|
-
stopSurfaceAdmission:
|
|
6357
|
-
dispatchAdmissionOpen = false;
|
|
6358
|
-
},
|
|
6638
|
+
backend: stage.backendRuntime.backend,
|
|
6639
|
+
owners: stage.owners,
|
|
6640
|
+
retirement: stage.retirement,
|
|
6641
|
+
stopSurfaceAdmission: stage.stopSurfaceAdmission,
|
|
6359
6642
|
disposeTransport: async () => {
|
|
6360
6643
|
if (transportDisposed) return;
|
|
6361
6644
|
transportDisposed = true;
|
|
6362
6645
|
const errors = [
|
|
6363
6646
|
...await collectDisposeErrors$1(() => clientUi.dispose()),
|
|
6364
|
-
...await collectDisposeErrors$1(() =>
|
|
6365
|
-
...await collectDisposeErrors$1(() => backendRuntime.dispose()),
|
|
6647
|
+
...await collectDisposeErrors$1(() => stage.disposeAdapters()),
|
|
6366
6648
|
...await collectDisposeErrors$1(() => wire.dispose())
|
|
6367
6649
|
];
|
|
6368
6650
|
if (errors.length > 0) throwAggregated(errors, "remote application runtime transport disposal");
|
|
6369
6651
|
}
|
|
6370
6652
|
},
|
|
6371
6653
|
wire,
|
|
6372
|
-
backendRuntime,
|
|
6373
|
-
presentation,
|
|
6654
|
+
backendRuntime: stage.backendRuntime,
|
|
6655
|
+
presentation: stage.presentation,
|
|
6374
6656
|
clientUi
|
|
6375
6657
|
};
|
|
6376
6658
|
}
|
|
@@ -6434,9 +6716,11 @@ async function createExperimentalRemoteRuntime(options) {
|
|
|
6434
6716
|
}
|
|
6435
6717
|
};
|
|
6436
6718
|
}
|
|
6437
|
-
/** Compile-time proof that the
|
|
6438
|
-
* ConfigPort's narrow source face (never called; referenced by the
|
|
6439
|
-
* official-contract gate).
|
|
6719
|
+
/** Compile-time proof that the shared Client runtime source satisfies the
|
|
6720
|
+
* Remote ConfigPort's narrow source face (never called; referenced by the
|
|
6721
|
+
* official-contract gate). The M3-1 Client runtime AND the real split
|
|
6722
|
+
* Client's Domain mount are the same structural source; the config-plane
|
|
6723
|
+
* namespaces stay part of the ONE `remote` service, never a second object. */
|
|
6440
6724
|
function remoteConfigRuntimeSourceOf(runtime) {
|
|
6441
6725
|
return runtime;
|
|
6442
6726
|
}
|
|
@@ -6471,7 +6755,10 @@ async function createRemoteBackendRuntime(options) {
|
|
|
6471
6755
|
try {
|
|
6472
6756
|
const semantics = createRemoteM3ASemantics(remoteM3ARuntimeSourceOf(options.runtime), {
|
|
6473
6757
|
promptSerializer: options.promptSerializer ?? RemotePromptSerializerProduction.overSessions(options.runtime.sessions),
|
|
6474
|
-
...options.isDispatchAllowed === void 0 ? {} : { isDispatchAllowed: options.isDispatchAllowed }
|
|
6758
|
+
...options.isDispatchAllowed === void 0 ? {} : { isDispatchAllowed: options.isDispatchAllowed },
|
|
6759
|
+
...options.delivery === void 0 ? {} : { delivery: options.delivery },
|
|
6760
|
+
...options.surfaceRevision === void 0 ? {} : { surfaceRevision: options.surfaceRevision },
|
|
6761
|
+
...options.onQualification === void 0 ? {} : { onQualification: options.onQualification }
|
|
6475
6762
|
});
|
|
6476
6763
|
unwind.push(() => semantics.dispose());
|
|
6477
6764
|
const config = new RemoteConfigPort(remoteConfigRuntimeSourceOf(options.runtime));
|