@artenx/dshb 0.1.53 → 0.1.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -7
- package/lib/auth/decorate-webserver.js +4 -4
- package/lib/auth/decorate-webserver.js.map +1 -1
- package/lib/auth/gate.d.ts +11 -3
- package/lib/auth/gate.js +14 -2
- package/lib/auth/gate.js.map +1 -1
- package/lib/auth/index.js +22 -3
- package/lib/auth/index.js.map +1 -1
- package/lib/auth/webserver.js +4 -4
- package/lib/auth/webserver.js.map +1 -1
- package/lib/{catalog-BPkswHoz.js → catalog-B6Qvy7bH.js} +8 -4
- package/lib/catalog-B6Qvy7bH.js.map +1 -0
- package/lib/client.js +421 -29
- package/lib/client.js.map +1 -1
- package/lib/core/index.js +132 -202
- package/lib/core/index.js.map +1 -1
- package/lib/core/node-registry.js +1 -1
- package/lib/core/routes.d.ts +1 -1
- package/lib/core/sync/coordinator.d.ts +5 -5
- package/lib/core/sync/coordinator.js +1 -1
- package/lib/core/sync/host-key.d.ts +1 -1
- package/lib/core/sync/internal-routes.d.ts +3 -3
- package/lib/core/sync/internal-routes.js +52 -2
- package/lib/core/sync/internal-routes.js.map +1 -1
- package/lib/core/sync/model.d.ts +1 -1
- package/lib/core/sync/model.js.map +1 -1
- package/lib/core/sync/node-sync.d.ts +1 -1
- package/lib/core/sync/offline-archive.d.ts +4 -4
- package/lib/core/sync/offline-archive.js +2 -2
- package/lib/core/sync/offline-routes.js +1 -1
- package/lib/core/sync/peer-manager.d.ts +2 -2
- package/lib/core/sync/routes.d.ts +9 -4
- package/lib/core/sync/routes.js +31 -4
- package/lib/core/sync/routes.js.map +1 -1
- package/lib/core/sync/session-journal.d.ts +1 -1
- package/lib/core/sync/session-open-routes.d.ts +32 -0
- package/lib/core/sync/session-open-routes.js +239 -0
- package/lib/core/sync/session-open-routes.js.map +1 -0
- package/lib/core/sync/session-routes.d.ts +1 -1
- package/lib/core/sync/session-routes.js +1 -1
- package/lib/core/sync/session-sync.d.ts +1 -1
- package/lib/core/sync/session-sync.js +1 -1
- package/lib/core/sync/ssh-transport.d.ts +1 -1
- package/lib/core/sync/ssh-transport.js +44 -1
- package/lib/core/sync/ssh-transport.js.map +1 -1
- package/lib/core/sync/stores.d.ts +1 -1
- package/lib/core/workspace-instruction-context.d.ts +1 -1
- package/lib/core/workspace-instructions.js +9 -1
- package/lib/core/workspace-instructions.js.map +1 -1
- package/lib/core/workspaces.d.ts +1 -1
- package/lib/{host-key-hIj6EY1x.d.ts → host-key-kbG50cnS.d.ts} +2 -2
- package/lib/{index-VF8bcBeX.d.ts → index-D6KDknUV.d.ts} +3 -309
- package/lib/{model-ByASrkzO.d.ts → model-zRfOihS3.d.ts} +4 -1
- package/lib/{node-sync-Cv1Amudy.d.ts → node-sync-Ba4yARei.d.ts} +3 -3
- package/lib/relay-auth-CtwES4Xn.js +240 -0
- package/lib/relay-auth-CtwES4Xn.js.map +1 -0
- package/lib/{session-journal-BnpGWLo2.d.ts → session-journal-BKjaO_1l.d.ts} +2 -2
- package/lib/{session-sync-Bn5ZXU8H.d.ts → session-sync-B5MCI0TW.d.ts} +31 -8
- package/lib/{session-sync-Dwz4dp4U.js → session-sync-Bsv3Qnof.js} +156 -96
- package/lib/session-sync-Bsv3Qnof.js.map +1 -0
- package/lib/{ssh-transport-CcGpOVy5.d.ts → ssh-transport-Uii7j8la.d.ts} +14 -5
- package/lib/{stores-BfruQqD-.d.ts → stores-DnyrIi4h.d.ts} +2 -2
- package/package.json +6 -2
- package/lib/catalog-BPkswHoz.js.map +0 -1
- package/lib/session-sync-Dwz4dp4U.js.map +0 -1
package/lib/core/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i as relayCookieHeader, r as registerRelayTicketRoutes, t as RelayTicketError } from "../relay-auth-CtwES4Xn.js";
|
|
2
2
|
import { sharedWorldResolver } from "../router/resolve.js";
|
|
3
3
|
import { sharedAuditLogger } from "./audit.js";
|
|
4
4
|
import { KnownHostsStore } from "./known-hosts.js";
|
|
@@ -12,7 +12,7 @@ import { registerWorkspaceInstructionRoutes } from "./workspace-instruction-rout
|
|
|
12
12
|
import { WorkspaceBindingsStore } from "./workspace-bindings.js";
|
|
13
13
|
import { registerWorkspaceInstructionInjector } from "./workspace-instruction-context.js";
|
|
14
14
|
import { SyncPeerManager, SyncPeerNotFoundError } from "./sync/peer-manager.js";
|
|
15
|
-
import { i as SyncSessionService } from "../session-sync-
|
|
15
|
+
import { i as SyncSessionService } from "../session-sync-Bsv3Qnof.js";
|
|
16
16
|
import { SyncSessionJournalStore } from "./sync/session-journal.js";
|
|
17
17
|
import { registerSyncInternalRoutes } from "./sync/internal-routes.js";
|
|
18
18
|
import { SyncSshProbeError, SyncSshTransport } from "./sync/ssh-transport.js";
|
|
@@ -20,207 +20,15 @@ import { SyncCoordinator } from "./sync/coordinator.js";
|
|
|
20
20
|
import { registerSyncPeerRoutes } from "./sync/routes.js";
|
|
21
21
|
import { SyncScheduler } from "./sync/scheduler.js";
|
|
22
22
|
import { registerSyncSessionRoutes } from "./sync/session-routes.js";
|
|
23
|
+
import { registerSyncSessionOpenRoutes } from "./sync/session-open-routes.js";
|
|
23
24
|
import { SyncOfflineArchiveService } from "./sync/offline-archive.js";
|
|
24
25
|
import { registerSyncOfflineRoutes } from "./sync/offline-routes.js";
|
|
25
26
|
import { SyncPeerStore, SyncStateStore } from "./sync/stores.js";
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
27
|
+
import { homedir } from "node:os";
|
|
28
|
+
import { chmodSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
29
|
+
import { join } from "node:path";
|
|
30
|
+
import { randomUUID } from "node:crypto";
|
|
28
31
|
import { request } from "node:http";
|
|
29
|
-
//#region src/core/sync/relay-auth.ts
|
|
30
|
-
const RELAY_COOKIE_PREFIX = "dsh-auth-";
|
|
31
|
-
const RELAY_COOKIE_VERSION = 1;
|
|
32
|
-
const RELAY_SECRET_BYTES = 32;
|
|
33
|
-
const RELAY_TICKET_MAX_AGE_MS = 6e5;
|
|
34
|
-
const MAX_TICKETS_PER_MINUTE = 30;
|
|
35
|
-
const AUTHORITY_PATTERN = /^(?:[A-Za-z0-9](?:[A-Za-z0-9.-]*[A-Za-z0-9])?|\[(?:[0-9A-Fa-f:.]+)\])(?::\d{1,5})?$/;
|
|
36
|
-
var RelayTicketError = class extends Error {
|
|
37
|
-
code;
|
|
38
|
-
constructor(code, message) {
|
|
39
|
-
super(message);
|
|
40
|
-
this.code = code;
|
|
41
|
-
this.name = "RelayTicketError";
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
function encodeBase64Url(value) {
|
|
45
|
-
return Buffer.from(value).toString("base64").replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/u, "");
|
|
46
|
-
}
|
|
47
|
-
function decodeBase64Url(value) {
|
|
48
|
-
if (!/^[A-Za-z0-9_-]*$/.test(value) || value.length % 4 === 1) return void 0;
|
|
49
|
-
const decoded = Buffer.from(value.replaceAll("-", "+").replaceAll("_", "/"), "base64");
|
|
50
|
-
return encodeBase64Url(decoded) === value ? decoded : void 0;
|
|
51
|
-
}
|
|
52
|
-
/** 校验并提取 credentials 记录中的浏览器会话签名密钥(32 字节)。 */
|
|
53
|
-
function browserSessionSecret(record) {
|
|
54
|
-
if (record === null || typeof record !== "object" || Array.isArray(record)) throw new RelayTicketError("relay-secret-unavailable", "browser session credential record is missing");
|
|
55
|
-
const payload = record.payload;
|
|
56
|
-
if (payload === null || typeof payload !== "object" || Array.isArray(payload)) throw new RelayTicketError("relay-secret-unavailable", "browser session credential payload is missing");
|
|
57
|
-
const { version, secret } = payload;
|
|
58
|
-
if (version !== RELAY_COOKIE_VERSION || typeof secret !== "string") throw new RelayTicketError("relay-secret-unavailable", "browser session credential payload is unsupported");
|
|
59
|
-
const decoded = decodeBase64Url(secret);
|
|
60
|
-
if (decoded === void 0 || decoded.byteLength !== RELAY_SECRET_BYTES) throw new RelayTicketError("relay-secret-unavailable", "browser session credential secret is invalid");
|
|
61
|
-
return decoded;
|
|
62
|
-
}
|
|
63
|
-
function validateRelayAuthority(value) {
|
|
64
|
-
if (typeof value !== "string" || value.length > 255 || !AUTHORITY_PATTERN.test(value)) throw new RelayTicketError("authority-invalid", "relay authority must be a bare host or host:port");
|
|
65
|
-
const port = value.includes("]:") || !value.includes("]") && value.includes(":") ? Number(value.slice(value.lastIndexOf(":") + 1)) : 80;
|
|
66
|
-
if (!Number.isInteger(port) || port < 1 || port > 65535) throw new RelayTicketError("authority-invalid", "relay authority port is invalid");
|
|
67
|
-
return value;
|
|
68
|
-
}
|
|
69
|
-
/** 与 browser-auth 相同的 cookie 名派生:dsh-auth- + base64url(sha256(authority))。 */
|
|
70
|
-
function relayCookieName(authority) {
|
|
71
|
-
return RELAY_COOKIE_PREFIX + encodeBase64Url(createHash("sha256").update(authority).digest());
|
|
72
|
-
}
|
|
73
|
-
/** 按远端 Host browser-auth 的格式铸造一个权威名绑定的短时效签名 cookie。 */
|
|
74
|
-
function mintRelayCookie(secret, authority, now, maxAgeMs = RELAY_TICKET_MAX_AGE_MS) {
|
|
75
|
-
const issuedAt = now;
|
|
76
|
-
const expiresAt = issuedAt + maxAgeMs;
|
|
77
|
-
const body = encodeBase64Url(Buffer.from(JSON.stringify({
|
|
78
|
-
version: RELAY_COOKIE_VERSION,
|
|
79
|
-
authority,
|
|
80
|
-
issuedAt,
|
|
81
|
-
expiresAt
|
|
82
|
-
}), "utf8"));
|
|
83
|
-
const signature = createHmac("sha256", secret).update(body).digest();
|
|
84
|
-
return {
|
|
85
|
-
name: relayCookieName(authority),
|
|
86
|
-
value: `v1.${body}.${encodeBase64Url(signature)}`,
|
|
87
|
-
expiresAt,
|
|
88
|
-
maxAgeSeconds: Math.floor(maxAgeMs / 1e3)
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
function relayCookieHeader(cookie) {
|
|
92
|
-
return `${cookie.name}=${cookie.value}`;
|
|
93
|
-
}
|
|
94
|
-
function readJsonBody(req, maxBytes) {
|
|
95
|
-
return new Promise((resolve) => {
|
|
96
|
-
const chunks = [];
|
|
97
|
-
let size = 0;
|
|
98
|
-
let settled = false;
|
|
99
|
-
const fail = () => {
|
|
100
|
-
if (settled) return;
|
|
101
|
-
settled = true;
|
|
102
|
-
resolve(null);
|
|
103
|
-
};
|
|
104
|
-
req.on("data", (chunk) => {
|
|
105
|
-
if (settled) return;
|
|
106
|
-
size += chunk.length;
|
|
107
|
-
if (size > maxBytes) {
|
|
108
|
-
fail();
|
|
109
|
-
req.destroy();
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
chunks.push(chunk);
|
|
113
|
-
});
|
|
114
|
-
req.on("end", () => {
|
|
115
|
-
if (settled) return;
|
|
116
|
-
try {
|
|
117
|
-
const value = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
118
|
-
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
119
|
-
fail();
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
settled = true;
|
|
123
|
-
resolve(value);
|
|
124
|
-
} catch {
|
|
125
|
-
fail();
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
req.on("error", fail);
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* 远端侧中继凭据铸造路由:POST /api/dshb/sync/internal/relay-ticket。
|
|
133
|
-
* 仅接受回环请求;用本机 credentials 的浏览器会话密钥为请求指定的
|
|
134
|
-
* authority 铸造 ≤10 分钟签名 cookie。凭据只在响应中返回一次。
|
|
135
|
-
*/
|
|
136
|
-
function registerRelayTicketRoutes(ctx, credentials) {
|
|
137
|
-
const rateLimit = {
|
|
138
|
-
windowStart: 0,
|
|
139
|
-
count: 0
|
|
140
|
-
};
|
|
141
|
-
ctx.effect(() => ctx.webServer.register({
|
|
142
|
-
kind: "exact",
|
|
143
|
-
path: "/api/dshb/sync/internal/relay-ticket",
|
|
144
|
-
handler: async (req, res) => {
|
|
145
|
-
const deny = (status, body) => {
|
|
146
|
-
res.writeHead(status, {
|
|
147
|
-
"content-type": "application/json",
|
|
148
|
-
"cache-control": "no-store"
|
|
149
|
-
});
|
|
150
|
-
res.end(JSON.stringify(body));
|
|
151
|
-
};
|
|
152
|
-
if (!isLoopbackRequest(req.socket.remoteAddress, req.headers.host)) {
|
|
153
|
-
deny(403, {
|
|
154
|
-
ok: false,
|
|
155
|
-
error: "loopback access required"
|
|
156
|
-
});
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
if (req.method !== "POST") {
|
|
160
|
-
deny(405, {
|
|
161
|
-
ok: false,
|
|
162
|
-
error: "method not allowed"
|
|
163
|
-
});
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
const now = Date.now();
|
|
167
|
-
if (now - rateLimit.windowStart > 6e4) {
|
|
168
|
-
rateLimit.windowStart = now;
|
|
169
|
-
rateLimit.count = 0;
|
|
170
|
-
}
|
|
171
|
-
rateLimit.count += 1;
|
|
172
|
-
if (rateLimit.count > MAX_TICKETS_PER_MINUTE) {
|
|
173
|
-
deny(429, {
|
|
174
|
-
ok: false,
|
|
175
|
-
error: "relay ticket rate limit exceeded"
|
|
176
|
-
});
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
const body = await readJsonBody(req, 1024);
|
|
180
|
-
let authority;
|
|
181
|
-
try {
|
|
182
|
-
authority = validateRelayAuthority(body?.authority);
|
|
183
|
-
} catch (error) {
|
|
184
|
-
deny(400, {
|
|
185
|
-
ok: false,
|
|
186
|
-
code: error instanceof RelayTicketError ? error.code : "authority-invalid",
|
|
187
|
-
error: error instanceof Error ? error.message : "authority is invalid"
|
|
188
|
-
});
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
try {
|
|
192
|
-
const cookie = mintRelayCookie(browserSessionSecret(await credentials.readRecord(credentialKey("client-connection", "browser-session"))), authority, now);
|
|
193
|
-
res.writeHead(200, {
|
|
194
|
-
"content-type": "application/json",
|
|
195
|
-
"cache-control": "no-store"
|
|
196
|
-
});
|
|
197
|
-
res.end(JSON.stringify({
|
|
198
|
-
ok: true,
|
|
199
|
-
cookie: {
|
|
200
|
-
name: cookie.name,
|
|
201
|
-
value: cookie.value,
|
|
202
|
-
maxAgeSeconds: cookie.maxAgeSeconds
|
|
203
|
-
}
|
|
204
|
-
}));
|
|
205
|
-
} catch (error) {
|
|
206
|
-
if (error instanceof RelayTicketError) {
|
|
207
|
-
deny(503, {
|
|
208
|
-
ok: false,
|
|
209
|
-
code: error.code,
|
|
210
|
-
error: error.message
|
|
211
|
-
});
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
deny(500, {
|
|
215
|
-
ok: false,
|
|
216
|
-
code: "relay-ticket-failed",
|
|
217
|
-
error: "relay ticket minting failed"
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
}));
|
|
222
|
-
}
|
|
223
|
-
//#endregion
|
|
224
32
|
//#region src/core/sync/remote-relay.ts
|
|
225
33
|
const DEFAULT_REMOTE_WEB_PORT = 3080;
|
|
226
34
|
const MAX_RELAY_RESPONSE_BYTES = 67108864;
|
|
@@ -602,6 +410,28 @@ var RemoteRelayService = class {
|
|
|
602
410
|
channel.close();
|
|
603
411
|
}
|
|
604
412
|
}
|
|
413
|
+
/**
|
|
414
|
+
* 经 direct-tcpip 通道调用远端 dshb internal 数据端点(manifest/entries/objects)。
|
|
415
|
+
* 相比 SSH helper 协议省去每次 RPC 的握手与远端进程启动;调用方负责在
|
|
416
|
+
* RemoteRelayError 时降级回 helper 路径。
|
|
417
|
+
*/
|
|
418
|
+
async relayInternal(peerId, method, path, body) {
|
|
419
|
+
const authority = await this.remoteAuthority(peerId);
|
|
420
|
+
const cookie = await this.relayTicket(peerId);
|
|
421
|
+
const result = await this.relayRequest(peerId, {
|
|
422
|
+
method,
|
|
423
|
+
path,
|
|
424
|
+
authority,
|
|
425
|
+
headers: body === void 0 ? {} : { "content-type": "application/json" },
|
|
426
|
+
body,
|
|
427
|
+
cookie
|
|
428
|
+
});
|
|
429
|
+
if (result.status !== 200) throw new RemoteRelayError("internal-request-failed", `remote internal endpoint returned ${result.status}`);
|
|
430
|
+
return {
|
|
431
|
+
status: result.status,
|
|
432
|
+
body: result.body
|
|
433
|
+
};
|
|
434
|
+
}
|
|
605
435
|
/** 丢弃指定对端缓存的中继凭据(对端重启或凭据被拒时调用)。 */
|
|
606
436
|
dropTicket(peerId) {
|
|
607
437
|
this.tickets.delete(peerId);
|
|
@@ -812,6 +642,81 @@ function readBody(req, maxBytes = 8388608) {
|
|
|
812
642
|
});
|
|
813
643
|
}
|
|
814
644
|
//#endregion
|
|
645
|
+
//#region src/core/sync/peer-imports.ts
|
|
646
|
+
const PEER_ID = /^p-[a-f0-9]{24}$/;
|
|
647
|
+
function homePath(home) {
|
|
648
|
+
return home ?? process.env.DSH_HOME ?? join(homedir(), ".dsh");
|
|
649
|
+
}
|
|
650
|
+
/** Durable ownership index for sessions imported on demand from metadata peers. */
|
|
651
|
+
var SyncPeerImportStore = class {
|
|
652
|
+
filePath;
|
|
653
|
+
data;
|
|
654
|
+
constructor(home) {
|
|
655
|
+
this.filePath = join(homePath(home), "dshb", "sync-peer-imports.json");
|
|
656
|
+
}
|
|
657
|
+
list(peerId) {
|
|
658
|
+
this.assertPeerId(peerId);
|
|
659
|
+
return [...this.load().peers[peerId] ?? []];
|
|
660
|
+
}
|
|
661
|
+
add(peerId, localSessionId) {
|
|
662
|
+
this.assertPeerId(peerId);
|
|
663
|
+
if (!localSessionId || localSessionId.length > 512 || /[\u0000-\u001f\u007f]/.test(localSessionId)) throw new Error("invalid imported session ID");
|
|
664
|
+
const data = this.load();
|
|
665
|
+
const ids = data.peers[peerId] ?? [];
|
|
666
|
+
if (!ids.includes(localSessionId)) data.peers[peerId] = [...ids, localSessionId];
|
|
667
|
+
this.save();
|
|
668
|
+
}
|
|
669
|
+
clear(peerId) {
|
|
670
|
+
this.assertPeerId(peerId);
|
|
671
|
+
delete this.load().peers[peerId];
|
|
672
|
+
this.save();
|
|
673
|
+
}
|
|
674
|
+
assertPeerId(peerId) {
|
|
675
|
+
if (!PEER_ID.test(peerId)) throw new Error("invalid sync peer ID");
|
|
676
|
+
}
|
|
677
|
+
load() {
|
|
678
|
+
if (this.data) return this.data;
|
|
679
|
+
try {
|
|
680
|
+
const value = JSON.parse(readFileSync(this.filePath, "utf8"));
|
|
681
|
+
if (value === null || typeof value !== "object" || Array.isArray(value) || value.version !== 1 || value.peers === null || typeof value.peers !== "object" || Array.isArray(value.peers)) throw new Error("invalid sync peer import store");
|
|
682
|
+
const peers = Object.create(null);
|
|
683
|
+
for (const [id, sessions] of Object.entries(value.peers)) {
|
|
684
|
+
if (!PEER_ID.test(id) || !Array.isArray(sessions) || !sessions.every((s) => typeof s === "string" && s.length > 0 && s.length <= 512)) throw new Error("invalid sync peer import entry");
|
|
685
|
+
peers[id] = [...new Set(sessions)];
|
|
686
|
+
}
|
|
687
|
+
this.data = {
|
|
688
|
+
version: 1,
|
|
689
|
+
peers
|
|
690
|
+
};
|
|
691
|
+
} catch (error) {
|
|
692
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") this.data = {
|
|
693
|
+
version: 1,
|
|
694
|
+
peers: Object.create(null)
|
|
695
|
+
};
|
|
696
|
+
else throw error;
|
|
697
|
+
}
|
|
698
|
+
return this.data;
|
|
699
|
+
}
|
|
700
|
+
save() {
|
|
701
|
+
const dir = join(this.filePath, "..");
|
|
702
|
+
mkdirSync(dir, {
|
|
703
|
+
recursive: true,
|
|
704
|
+
mode: 448
|
|
705
|
+
});
|
|
706
|
+
const temporary = `${this.filePath}.${process.pid}.tmp`;
|
|
707
|
+
try {
|
|
708
|
+
writeFileSync(temporary, `${JSON.stringify(this.load(), null, 2)}\n`, { mode: 384 });
|
|
709
|
+
renameSync(temporary, this.filePath);
|
|
710
|
+
chmodSync(this.filePath, 384);
|
|
711
|
+
} catch (error) {
|
|
712
|
+
try {
|
|
713
|
+
unlinkSync(temporary);
|
|
714
|
+
} catch {}
|
|
715
|
+
throw error;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
};
|
|
719
|
+
//#endregion
|
|
815
720
|
//#region src/core/index.ts
|
|
816
721
|
const name = "dshb-core";
|
|
817
722
|
const inject = ["webServer", "credentials"];
|
|
@@ -822,6 +727,7 @@ function apply(ctx) {
|
|
|
822
727
|
const syncPeers = new SyncPeerStore();
|
|
823
728
|
const syncState = new SyncStateStore();
|
|
824
729
|
const syncPeerManager = new SyncPeerManager(syncPeers, syncState, ctx.credentials);
|
|
730
|
+
const syncPeerImports = new SyncPeerImportStore(process.env.DSH_HOME);
|
|
825
731
|
const syncSshTransport = new SyncSshTransport(syncPeerManager);
|
|
826
732
|
let workspaceRegistry;
|
|
827
733
|
if (typeof ctx.inject === "function") ctx.inject(["workspaceRegistry"], (workspaceCtx) => {
|
|
@@ -834,8 +740,22 @@ function apply(ctx) {
|
|
|
834
740
|
dockerWorlds?.remove?.(nodeId);
|
|
835
741
|
});
|
|
836
742
|
const syncSessions = new SyncSessionService(syncState, syncNodes, registry, bindings, () => workspaceRegistry, () => ctx.get("sessionPersistence"), () => ctx.get("attachments"), () => ctx.get("spillStore"), sharedSessionInstructionSnapshotStore(), void 0, void 0, process.env.DSH_HOME, void 0, (header) => {
|
|
837
|
-
const
|
|
838
|
-
|
|
743
|
+
const values = (ctx.get("sessionProjectionCache")?.cachedSnapshot?.(header, ["title", "sessionListMetadata"]))?.values;
|
|
744
|
+
let title = values?.title;
|
|
745
|
+
let listMeta = values?.sessionListMetadata;
|
|
746
|
+
if (!listMeta || typeof title !== "string" || !title.trim()) try {
|
|
747
|
+
const home = process.env.DSH_HOME ?? join(process.env.HOME ?? "", ".dsh");
|
|
748
|
+
const file = join(home, "storages", "session_projcache", "sessions", String(header.id) + ".json");
|
|
749
|
+
const rows = JSON.parse(readFileSync(file, "utf8")).record?.rows ?? {};
|
|
750
|
+
const row = rows.sessionListMetadata?.val ?? void 0;
|
|
751
|
+
const titleRow = rows.title?.val;
|
|
752
|
+
if (!listMeta && row) listMeta = row;
|
|
753
|
+
if ((typeof title !== "string" || !title.trim()) && typeof titleRow === "string" && titleRow.trim()) title = titleRow;
|
|
754
|
+
} catch {}
|
|
755
|
+
return {
|
|
756
|
+
...typeof title === "string" && title.trim() ? { title } : {},
|
|
757
|
+
...listMeta?.blank === true ? { blank: true } : {}
|
|
758
|
+
};
|
|
839
759
|
});
|
|
840
760
|
const syncOfflineArchives = new SyncOfflineArchiveService(syncNodes, syncSessions, void 0, void 0, syncState);
|
|
841
761
|
try {
|
|
@@ -865,13 +785,23 @@ function apply(ctx) {
|
|
|
865
785
|
registerWorkspaceRoutes(ctx, registry, bindings, syncNodes);
|
|
866
786
|
registerRemoteDownloadRoutes(ctx, registry, bindings);
|
|
867
787
|
registerWorkspaceInstructionRoutes(ctx, sharedWorkspaceInstructionStore());
|
|
868
|
-
registerSyncPeerRoutes(ctx, syncPeerManager, syncSshTransport, syncCoordinator)
|
|
788
|
+
registerSyncPeerRoutes(ctx, syncPeerManager, syncSshTransport, syncCoordinator, async (peer, remoteInstanceId) => {
|
|
789
|
+
if (peer.mode !== "metadata") return {
|
|
790
|
+
sessionsArchived: 0,
|
|
791
|
+
workspacesRemoved: 0,
|
|
792
|
+
workspacesDetached: 0
|
|
793
|
+
};
|
|
794
|
+
const fallbackSourceName = (await syncPeerManager.list()).filter((candidate) => candidate.name === peer.name).length === 1 ? peer.name : void 0;
|
|
795
|
+
return syncSessions.removeMetadataPeerImports(remoteInstanceId, syncPeerImports.list(peer.id), fallbackSourceName);
|
|
796
|
+
}, (peerId) => syncPeerImports.clear(peerId));
|
|
869
797
|
registerSyncInternalRoutes(ctx, syncState, syncNodes, syncSessions);
|
|
870
798
|
registerSyncSessionRoutes(ctx, syncSessions);
|
|
799
|
+
registerSyncSessionOpenRoutes(ctx, syncPeerManager, syncSshTransport, syncSessions, syncState, syncPeerImports, syncCoordinator, () => workspaceRegistry);
|
|
871
800
|
registerSyncOfflineRoutes(ctx, syncOfflineArchives);
|
|
872
801
|
registerRelayTicketRoutes(ctx, ctx.credentials);
|
|
873
802
|
const remoteRelay = new RemoteRelayService(syncPeerManager, syncSshTransport);
|
|
874
803
|
ctx.provide("remoteRelayService", remoteRelay);
|
|
804
|
+
syncSshTransport.setRelayDataPlane(remoteRelay);
|
|
875
805
|
const sessionJournal = new SyncSessionJournalStore(process.env.DSH_HOME);
|
|
876
806
|
registerRemoteRelayRoutes(ctx, remoteRelay, { resolveSessionOrigin: (sessionId) => {
|
|
877
807
|
const state = syncState.read();
|