@artenx/dshb 0.1.54 → 0.1.56
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/index.js +1 -1
- package/lib/auth/index.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 +138 -5
- package/lib/core/index.js.map +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 +54 -26
- package/lib/core/sync/coordinator.js.map +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 +83 -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/node-sync.js +2 -4
- package/lib/core/sync/node-sync.js.map +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/remote-helper.js +6 -4
- package/lib/core/sync/remote-helper.js.map +1 -1
- 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-bindings.js +62 -24
- package/lib/core/workspace-bindings.js.map +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/{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-DrilvkP1.js} +171 -98
- package/lib/session-sync-DrilvkP1.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/README.md
CHANGED
|
@@ -1,22 +1,37 @@
|
|
|
1
|
-
# @artenx/dshb
|
|
1
|
+
# DSH HoneyBee (@artenx/dshb)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Turn DSH into an always-available, multi-device Agent workbench.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
把 DSH 变成随时可用的多设备 Agent 工作台。
|
|
6
|
+
|
|
7
|
+
Add remote machines as execution nodes to your local DSH, then work with them as if they were local — sessions, file directories, and terminals all just work. Sync data between multiple DSH instances that have this plugin installed, and when deployed on a cloud server, the Web app supports login authentication.
|
|
8
|
+
|
|
9
|
+
将远程机器添加为本地 DSH 的执行节点后,即可像操作本地内容一样使用它们——会话环境、文件目录、终端开箱即用。支持在多个安装了本插件的 DSH 实例之间同步数据;部署在云服务器上时,Web 端支持登录认证。
|
|
10
|
+
|
|
11
|
+
## Highlights / 核心能力
|
|
12
|
+
|
|
13
|
+
- **Remote nodes as if local / 远程节点本地化操作** — Route filesystem, shell, subprocess, and PTY operations to local, SSH, or Docker execution nodes.文件系统、Shell、子进程与 PTY 操作可路由到本地、SSH 或 Docker 执行节点。
|
|
14
|
+
- **Remote sessions on demand / 远程会话按需打开** — Browse a remote node's sessions in your local sidebar and open them natively with one click.在本地侧边栏浏览远程节点的会话,一键原生打开。
|
|
15
|
+
- **Instance-to-instance sync / 实例间数据同步** — Keep sessions, workspaces, and project instructions in sync across DSH instances.会话、工作区与项目指令在 DSH 实例间保持同步。
|
|
16
|
+
- **Login protection for the Web app / Web 端登录认证** — An authentication gate with credential custody protects browser access.认证门禁与凭据托管保护浏览器端访问。
|
|
17
|
+
- **Mobile-aware management UI / 移动端管理界面** — Manage nodes and settings from a phone-friendly UI.手机友好的节点与设置管理界面。
|
|
18
|
+
|
|
19
|
+
## Install / 安装
|
|
6
20
|
|
|
7
21
|
```sh
|
|
8
22
|
dsh plugin --profile web add @artenx/dshb
|
|
9
23
|
```
|
|
10
24
|
|
|
11
|
-
Restart the corresponding DSH Web profile after installation.
|
|
25
|
+
Restart the corresponding DSH Web profile after installation. 安装后重启对应的 DSH Web profile。
|
|
12
26
|
|
|
13
|
-
Desktop app: install from **Settings → Plugins → More** in the DSH desktop app; the plugin takes effect on next startup.
|
|
27
|
+
Desktop app: install from **Settings → Plugins → More** in the DSH desktop app; the plugin takes effect on next startup. 桌面端在 **设置 → 插件 → 更多** 中安装,重启后生效。
|
|
14
28
|
|
|
15
|
-
The Authentication settings entry appears in the browser-based Web app. The DSH desktop shell uses the `dsh-app://` protocol and omits this entry; its loopback requests are admitted automatically.
|
|
29
|
+
The Authentication settings entry appears in the browser-based Web app. The DSH desktop shell uses the `dsh-app://` protocol and omits this entry; its loopback requests are admitted automatically. 认证设置入口仅在浏览器版 Web 应用中出现;桌面端使用 `dsh-app://` 协议,回环请求自动放行,因此不含该入口。
|
|
16
30
|
|
|
17
|
-
## Requirements
|
|
31
|
+
## Requirements / 环境要求
|
|
18
32
|
|
|
19
33
|
- Node.js 22.13 or newer
|
|
20
34
|
- DeepSeek Harness 0.1.7-rc.1, 0.2.1-rc.2, or 0.2.2-rc.1 (Web or Desktop)
|
|
21
35
|
|
|
22
36
|
Source code and complete documentation: https://github.com/Artenx/dsh-honeybee
|
|
37
|
+
源码与完整文档:https://github.com/Artenx/dsh-honeybee
|
package/lib/auth/index.js
CHANGED
|
@@ -60,7 +60,7 @@ function registerFrontendBootRaceWorkaround(ctx) {
|
|
|
60
60
|
const assetPath = join(assetDir, assetName);
|
|
61
61
|
const source = readFileSync(assetPath, "utf8");
|
|
62
62
|
const legacyPatch = source.replace(/await ([A-Za-z_$][\w$]*)\.await\(\),this\.assertEntriesActive\(([A-Za-z_$][\w$]*)\)/, "await $1.await(),await new Promise(r=>setTimeout(r,8000)),this.assertEntriesActive($2)");
|
|
63
|
-
const patched = legacyPatch !== source ? legacyPatch : source.replace(/await ([A-Za-z_$][\w$]*)\.await\(\),([A-Za-z_$][\w$]*)\(([A-Za-z_$][\w$]*),([A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*)\)/, "await $1.await(),await new Promise(r=>setTimeout(r,8000)),$2($
|
|
63
|
+
const patched = legacyPatch !== source ? legacyPatch : source.replace(/await ([A-Za-z_$][\w$]*)\.await\(\),(await )?([A-Za-z_$][\w$]*)\(([A-Za-z_$][\w$]*),([A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*)\)/, "await $1.await(),await new Promise(r=>setTimeout(r,8000)),$2$3($4,$5)");
|
|
64
64
|
if (patched === source) return;
|
|
65
65
|
ctx.effect(() => ctx.webServer.register({
|
|
66
66
|
kind: "exact",
|
package/lib/auth/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/auth/index.ts"],"sourcesContent":["import { readFileSync, readdirSync, realpathSync } from 'node:fs'\nimport { createRequire } from 'node:module'\nimport { basename, dirname, join } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport type { IncomingMessage } from 'node:http'\nimport type { Context } from '@deepseek-ai/cordis'\nimport { credentialKey } from '@deepseek-ai/dsh-credentials'\nimport { sharedCredentialStore } from './credentials.js'\nimport { decorateWebServer } from './decorate-webserver.js'\nimport { AuthGate, isTrustedAuthRequest, type BrowserSessionSecretProvider } from './gate.js'\nimport { installLoopbackCompat } from './loopback-compat.js'\nimport { LoginRateLimiter } from './ratelimit.js'\nimport { registerAuthRoutes } from './routes.js'\nimport { browserSessionSecret } from '../core/sync/relay-auth.js'\n\nexport const name = 'dshb-auth'\n\nexport const inject = ['webServer', 'credentials']\n\n/**\n * 定位 dshb 实际安装所在 profile 的 node_modules。\n * link 安装(开发预览)下 ESM 真实路径解析会把 import.meta.url 指向仓库源码,\n * 由此向上 resolve 会命中仓库工作区的 @deepseek-ai/dsh-web-app 副本;服务器\n * 实际服务的却是 profile 内那份。通过 DSH_HOME/profiles 扫描 realpath 匹配\n * 找回安装位置;常规安装(真实文件就在 profile 内)时现有解析本就正确。\n */\nfunction profileNodeModulesFor(realSelfPath: string): string | undefined {\n const home = process.env.DSH_HOME\n if (!home) return undefined\n const profilesDir = join(home, 'profiles')\n let names: string[]\n try {\n names = readdirSync(profilesDir)\n } catch {\n return undefined\n }\n for (const name of names) {\n const installed = join(profilesDir, name, 'node_modules', '@artenx', 'dshb')\n try {\n const realInstalled = realpathSync(installed)\n if (realInstalled === realSelfPath || realSelfPath.startsWith(`${realInstalled}/`)) {\n return join(profilesDir, name, 'node_modules')\n }\n } catch {\n /* profile without this package */\n }\n }\n return undefined\n}\n\nfunction registerFrontendBootRaceWorkaround(ctx: Context): void {\n try {\n // Resolve the frontend through the same runtime package tree the webserver\n // loads, so the patched hashed asset is the one the static fallback serves.\n // A linked plugin profile may contain only @artenx/dshb; its DSH executable\n // supplies the actual @deepseek-ai bundle tree.\n const resolver = createRequire(import.meta.url)\n const realSelf = realpathSync(fileURLToPath(import.meta.url))\n const profileModules = profileNodeModulesFor(realSelf)\n const webAppResolvers: Array<() => string> = []\n if (profileModules) {\n webAppResolvers.push(() => resolver.resolve('@deepseek-ai/dsh-web-app/package.json', { paths: [profileModules] }))\n }\n if (process.argv[1]) {\n webAppResolvers.push(() => createRequire(realpathSync(process.argv[1]!)).resolve('@deepseek-ai/dsh-web-app/package.json'))\n }\n webAppResolvers.push(() => resolver.resolve('@deepseek-ai/dsh-web-app/package.json'))\n let webAppManifest: string | undefined\n for (const resolveWebApp of webAppResolvers) {\n try {\n webAppManifest = resolveWebApp()\n break\n } catch {\n // Try the next runtime-owned package tree.\n }\n }\n let manifestPath: string\n if (webAppManifest) {\n manifestPath = createRequire(webAppManifest).resolve('@deepseek-ai/dsh-web-frontend/package.json')\n } else {\n manifestPath = resolver.resolve('@deepseek-ai/dsh-web-frontend/package.json', {\n paths: [process.cwd()],\n })\n }\n const assetDir = join(dirname(manifestPath), 'dist', 'assets')\n const assetName = readdirSync(assetDir).find((name) => /^index-.*\\.js$/.test(name))\n if (!assetName) return\n\n const assetPath = join(assetDir, assetName)\n const source = readFileSync(assetPath, 'utf8')\n // DSH asserts before api-remotes' dynamic remote namespace fibers settle.\n // Delay the assertion so mountApp sees the complete client graph; real\n // activation failures still throw after the bounded wait. The minified\n // identifiers vary between builds, and 0.1.7 moved the assertion into nE.\n const legacyPatch = source.replace(\n /await ([A-Za-z_$][\\w$]*)\\.await\\(\\),this\\.assertEntriesActive\\(([A-Za-z_$][\\w$]*)\\)/,\n 'await $1.await(),await new Promise(r=>setTimeout(r,8000)),this.assertEntriesActive($2)',\n )\n const patched = legacyPatch !== source\n ? legacyPatch\n : source.replace(\n /await ([A-Za-z_$][\\w$]*)\\.await\\(\\),([A-Za-z_$][\\w$]*)\\(([A-Za-z_$][\\w$]*),([A-Za-z_$][\\w$]*(?:\\.[A-Za-z_$][\\w$]*)*)\\)/,\n 'await $1.await(),await new Promise(r=>setTimeout(r,8000)),$2($3,$4)',\n )\n if (patched === source) return\n\n ctx.effect(() =>\n ctx.webServer.register({\n kind: 'exact',\n path: `/assets/${basename(assetPath)}`,\n handler: (_req, res) => {\n res.writeHead(200, {\n 'cache-control': 'no-store',\n 'content-type': 'application/javascript; charset=utf-8',\n })\n res.end(patched)\n },\n }),\n )\n } catch {\n // Upstream assets are optional from DSHB's perspective. A missing or changed\n // frontend layout simply skips this version-specific workaround.\n }\n}\n\nexport function apply(ctx: Context): void {\n const store = sharedCredentialStore()\n // relay cookie 校验需读 dsh browser-session 密钥;credentials 可能晚于\n // auth 插件就绪,provider 每次按需读取并缓存(密钥仅在凭据重置时变化)。\n let cachedBrowserSecret: Buffer | null | undefined\n let browserSecretFetchInFlight = false\n const credentialsLike = (ctx as unknown as { credentials?: { readRecord: (key: unknown) => Promise<unknown> } }).credentials\n const browserSecretProvider: BrowserSessionSecretProvider = async () => {\n if (cachedBrowserSecret !== undefined) return cachedBrowserSecret ?? undefined\n if (!credentialsLike || browserSecretFetchInFlight) return undefined\n browserSecretFetchInFlight = true\n try {\n const record = await credentialsLike.readRecord(credentialKey('client-connection', 'browser-session'))\n cachedBrowserSecret = browserSessionSecret(record) ?? null\n } catch {\n cachedBrowserSecret = null\n } finally {\n browserSecretFetchInFlight = false\n }\n return cachedBrowserSecret ?? undefined\n }\n const gate = new AuthGate(store, browserSecretProvider)\n ctx.effect(() => decorateWebServer(ctx.webServer, store, gate))\n registerFrontendBootRaceWorkaround(ctx)\n ctx.effect(() => ctx.webServer.tapIndex(installLoopbackCompat))\n registerAuthRoutes(ctx, store, new LoginRateLimiter())\n\n // DSH 0.1.5 introduced a browser-auth fence on the connection package: the SPA\n // fallback calls connection.authorizeIndex() on \"/\" (mints/checks DSH's own\n // launch-token cookie), and /api routes run requestRejection() which 401s when\n // that DSH cookie is absent. DSHB uses its own session cookie and must stay the\n // sole auth gate (DSH 0.1.1 had no such connection fence, so DSHB worked there).\n // Neutralize the connection's browserAuth.isAuthenticated check so DSH's fence\n // never rejects a DSHB-authenticated (or loopback) request; DSHB's gate still\n // rejects unauthenticated access to gated routes. Property is read at request\n // time, so installing it once after connection is ready suffices.\n ctx.inject(['connection'], (connCtx: Context) => {\n connCtx.effect(() => {\n const conn = (connCtx as unknown as {\n connection?: {\n browserAuth?: { isAuthenticated?: (...a: unknown[]) => unknown; __dshbNeutralized?: true }\n requestRejection?: (request: IncomingMessage) => number | undefined\n }\n }).connection\n const auth = conn?.browserAuth\n const originalIsAuthenticated = auth?.isAuthenticated\n const neutralizedIsAuthenticated = () => true\n let installedNeutralizer = false\n if (auth && typeof originalIsAuthenticated === 'function' && !auth.__dshbNeutralized) {\n auth.isAuthenticated = neutralizedIsAuthenticated\n auth.__dshbNeutralized = true\n installedNeutralizer = true\n }\n if (conn && typeof conn.requestRejection === 'function') {\n gate.setAuthRequestTrustCheck((req) => {\n const rejection = conn.requestRejection!(req)\n // DSH 401 is its browser-cookie gate; DSHB owns that check for these routes.\n if (rejection === undefined || rejection === 401) return true\n // DSH fence rejects non-loopback authorities (403). Preview reverse\n // proxies keep the external Host header, so DSHB falls back to its own\n // source checks (loopback peer address + cross-site protection); the\n // session gate still owns every authenticated route after login.\n return isTrustedAuthRequest(req)\n })\n }\n return () => {\n if (!auth || !installedNeutralizer) return\n if (auth.isAuthenticated === neutralizedIsAuthenticated && originalIsAuthenticated) {\n auth.isAuthenticated = originalIsAuthenticated\n }\n delete auth.__dshbNeutralized\n }\n })\n })\n}\n"],"mappings":";;;;;;;;;;;;;AAeA,MAAa,OAAO;AAEpB,MAAa,SAAS,CAAC,aAAa,aAAa;;;;;;;;AASjD,SAA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B;EAC/C,QAAQ,aAAa;GACnB,MAAM,OAAQ,QAKX;GACH,MAAM,OAAO,MAAM;GACnB,MAAM,0BAA0B,MAAM;GACtC,MAAM,mCAAmC;GACzC,IAAI,uBAAuB;GAC3B,IAAI,QAAQ,OAAO,4BAA4B,cAAc,CAAC,KAAK,mBAAmB;IACpF,KAAK,kBAAkB;IACvB,KAAK,oBAAoB;IACzB,uBAAuB;GACzB;GACA,IAAI,QAAQ,OAAO,KAAK,qBAAqB,YAC3C,KAAK,0BAA0B,QAAQ;IACrC,MAAM,YAAY,KAAK,iBAAkB,GAAG;IAE5C,IAAI,cAAc,KAAA,KAAa,cAAc,KAAK,OAAO;IAKzD,OAAO,qBAAqB,GAAG;GACjC,CAAC;GAEH,aAAa;IACX,IAAI,CAAC,QAAQ,CAAC,sBAAsB;IACpC,IAAI,KAAK,oBAAoB,8BAA8B,yBACzD,KAAK,kBAAkB;IAEzB,OAAO,KAAK;GACd;EACF,CAAC;CACH,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/auth/index.ts"],"sourcesContent":["import { readFileSync, readdirSync, realpathSync } from 'node:fs'\nimport { createRequire } from 'node:module'\nimport { basename, dirname, join } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport type { IncomingMessage } from 'node:http'\nimport type { Context } from '@deepseek-ai/cordis'\nimport { credentialKey } from '@deepseek-ai/dsh-credentials'\nimport { sharedCredentialStore } from './credentials.js'\nimport { decorateWebServer } from './decorate-webserver.js'\nimport { AuthGate, isTrustedAuthRequest, type BrowserSessionSecretProvider } from './gate.js'\nimport { installLoopbackCompat } from './loopback-compat.js'\nimport { LoginRateLimiter } from './ratelimit.js'\nimport { registerAuthRoutes } from './routes.js'\nimport { browserSessionSecret } from '../core/sync/relay-auth.js'\n\nexport const name = 'dshb-auth'\n\nexport const inject = ['webServer', 'credentials']\n\n/**\n * 定位 dshb 实际安装所在 profile 的 node_modules。\n * link 安装(开发预览)下 ESM 真实路径解析会把 import.meta.url 指向仓库源码,\n * 由此向上 resolve 会命中仓库工作区的 @deepseek-ai/dsh-web-app 副本;服务器\n * 实际服务的却是 profile 内那份。通过 DSH_HOME/profiles 扫描 realpath 匹配\n * 找回安装位置;常规安装(真实文件就在 profile 内)时现有解析本就正确。\n */\nfunction profileNodeModulesFor(realSelfPath: string): string | undefined {\n const home = process.env.DSH_HOME\n if (!home) return undefined\n const profilesDir = join(home, 'profiles')\n let names: string[]\n try {\n names = readdirSync(profilesDir)\n } catch {\n return undefined\n }\n for (const name of names) {\n const installed = join(profilesDir, name, 'node_modules', '@artenx', 'dshb')\n try {\n const realInstalled = realpathSync(installed)\n if (realInstalled === realSelfPath || realSelfPath.startsWith(`${realInstalled}/`)) {\n return join(profilesDir, name, 'node_modules')\n }\n } catch {\n /* profile without this package */\n }\n }\n return undefined\n}\n\nfunction registerFrontendBootRaceWorkaround(ctx: Context): void {\n try {\n // Resolve the frontend through the same runtime package tree the webserver\n // loads, so the patched hashed asset is the one the static fallback serves.\n // A linked plugin profile may contain only @artenx/dshb; its DSH executable\n // supplies the actual @deepseek-ai bundle tree.\n const resolver = createRequire(import.meta.url)\n const realSelf = realpathSync(fileURLToPath(import.meta.url))\n const profileModules = profileNodeModulesFor(realSelf)\n const webAppResolvers: Array<() => string> = []\n if (profileModules) {\n webAppResolvers.push(() => resolver.resolve('@deepseek-ai/dsh-web-app/package.json', { paths: [profileModules] }))\n }\n if (process.argv[1]) {\n webAppResolvers.push(() => createRequire(realpathSync(process.argv[1]!)).resolve('@deepseek-ai/dsh-web-app/package.json'))\n }\n webAppResolvers.push(() => resolver.resolve('@deepseek-ai/dsh-web-app/package.json'))\n let webAppManifest: string | undefined\n for (const resolveWebApp of webAppResolvers) {\n try {\n webAppManifest = resolveWebApp()\n break\n } catch {\n // Try the next runtime-owned package tree.\n }\n }\n let manifestPath: string\n if (webAppManifest) {\n manifestPath = createRequire(webAppManifest).resolve('@deepseek-ai/dsh-web-frontend/package.json')\n } else {\n manifestPath = resolver.resolve('@deepseek-ai/dsh-web-frontend/package.json', {\n paths: [process.cwd()],\n })\n }\n const assetDir = join(dirname(manifestPath), 'dist', 'assets')\n const assetName = readdirSync(assetDir).find((name) => /^index-.*\\.js$/.test(name))\n if (!assetName) return\n\n const assetPath = join(assetDir, assetName)\n const source = readFileSync(assetPath, 'utf8')\n // DSH asserts before api-remotes' dynamic remote namespace fibers settle.\n // Delay the assertion so mountApp sees the complete client graph; real\n // activation failures still throw after the bounded wait. The minified\n // identifiers vary between builds, and 0.1.7 moved the assertion into nE.\n const legacyPatch = source.replace(\n /await ([A-Za-z_$][\\w$]*)\\.await\\(\\),this\\.assertEntriesActive\\(([A-Za-z_$][\\w$]*)\\)/,\n 'await $1.await(),await new Promise(r=>setTimeout(r,8000)),this.assertEntriesActive($2)',\n )\n const patched = legacyPatch !== source\n ? legacyPatch\n : source.replace(\n /await ([A-Za-z_$][\\w$]*)\\.await\\(\\),(await )?([A-Za-z_$][\\w$]*)\\(([A-Za-z_$][\\w$]*),([A-Za-z_$][\\w$]*(?:\\.[A-Za-z_$][\\w$]*)*)\\)/,\n 'await $1.await(),await new Promise(r=>setTimeout(r,8000)),$2$3($4,$5)',\n )\n if (patched === source) return\n\n ctx.effect(() =>\n ctx.webServer.register({\n kind: 'exact',\n path: `/assets/${basename(assetPath)}`,\n handler: (_req, res) => {\n res.writeHead(200, {\n 'cache-control': 'no-store',\n 'content-type': 'application/javascript; charset=utf-8',\n })\n res.end(patched)\n },\n }),\n )\n } catch {\n // Upstream assets are optional from DSHB's perspective. A missing or changed\n // frontend layout simply skips this version-specific workaround.\n }\n}\n\nexport function apply(ctx: Context): void {\n const store = sharedCredentialStore()\n // relay cookie 校验需读 dsh browser-session 密钥;credentials 可能晚于\n // auth 插件就绪,provider 每次按需读取并缓存(密钥仅在凭据重置时变化)。\n let cachedBrowserSecret: Buffer | null | undefined\n let browserSecretFetchInFlight = false\n const credentialsLike = (ctx as unknown as { credentials?: { readRecord: (key: unknown) => Promise<unknown> } }).credentials\n const browserSecretProvider: BrowserSessionSecretProvider = async () => {\n if (cachedBrowserSecret !== undefined) return cachedBrowserSecret ?? undefined\n if (!credentialsLike || browserSecretFetchInFlight) return undefined\n browserSecretFetchInFlight = true\n try {\n const record = await credentialsLike.readRecord(credentialKey('client-connection', 'browser-session'))\n cachedBrowserSecret = browserSessionSecret(record) ?? null\n } catch {\n cachedBrowserSecret = null\n } finally {\n browserSecretFetchInFlight = false\n }\n return cachedBrowserSecret ?? undefined\n }\n const gate = new AuthGate(store, browserSecretProvider)\n ctx.effect(() => decorateWebServer(ctx.webServer, store, gate))\n registerFrontendBootRaceWorkaround(ctx)\n ctx.effect(() => ctx.webServer.tapIndex(installLoopbackCompat))\n registerAuthRoutes(ctx, store, new LoginRateLimiter())\n\n // DSH 0.1.5 introduced a browser-auth fence on the connection package: the SPA\n // fallback calls connection.authorizeIndex() on \"/\" (mints/checks DSH's own\n // launch-token cookie), and /api routes run requestRejection() which 401s when\n // that DSH cookie is absent. DSHB uses its own session cookie and must stay the\n // sole auth gate (DSH 0.1.1 had no such connection fence, so DSHB worked there).\n // Neutralize the connection's browserAuth.isAuthenticated check so DSH's fence\n // never rejects a DSHB-authenticated (or loopback) request; DSHB's gate still\n // rejects unauthenticated access to gated routes. Property is read at request\n // time, so installing it once after connection is ready suffices.\n ctx.inject(['connection'], (connCtx: Context) => {\n connCtx.effect(() => {\n const conn = (connCtx as unknown as {\n connection?: {\n browserAuth?: { isAuthenticated?: (...a: unknown[]) => unknown; __dshbNeutralized?: true }\n requestRejection?: (request: IncomingMessage) => number | undefined\n }\n }).connection\n const auth = conn?.browserAuth\n const originalIsAuthenticated = auth?.isAuthenticated\n const neutralizedIsAuthenticated = () => true\n let installedNeutralizer = false\n if (auth && typeof originalIsAuthenticated === 'function' && !auth.__dshbNeutralized) {\n auth.isAuthenticated = neutralizedIsAuthenticated\n auth.__dshbNeutralized = true\n installedNeutralizer = true\n }\n if (conn && typeof conn.requestRejection === 'function') {\n gate.setAuthRequestTrustCheck((req) => {\n const rejection = conn.requestRejection!(req)\n // DSH 401 is its browser-cookie gate; DSHB owns that check for these routes.\n if (rejection === undefined || rejection === 401) return true\n // DSH fence rejects non-loopback authorities (403). Preview reverse\n // proxies keep the external Host header, so DSHB falls back to its own\n // source checks (loopback peer address + cross-site protection); the\n // session gate still owns every authenticated route after login.\n return isTrustedAuthRequest(req)\n })\n }\n return () => {\n if (!auth || !installedNeutralizer) return\n if (auth.isAuthenticated === neutralizedIsAuthenticated && originalIsAuthenticated) {\n auth.isAuthenticated = originalIsAuthenticated\n }\n delete auth.__dshbNeutralized\n }\n })\n })\n}\n"],"mappings":";;;;;;;;;;;;;AAeA,MAAa,OAAO;AAEpB,MAAa,SAAS,CAAC,aAAa,aAAa;;;;;;;;AASjD,SAAS,sBAAsB,cAA0C;CACvE,MAAM,OAAO,QAAQ,IAAI;CACzB,IAAI,CAAC,MAAM,OAAO,KAAA;CAClB,MAAM,cAAc,KAAK,MAAM,UAAU;CACzC,IAAI;CACJ,IAAI;EACF,QAAQ,YAAY,WAAW;CACjC,QAAQ;EACN;CACF;CACA,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,YAAY,KAAK,aAAa,MAAM,gBAAgB,WAAW,MAAM;EAC3E,IAAI;GACF,MAAM,gBAAgB,aAAa,SAAS;GAC5C,IAAI,kBAAkB,gBAAgB,aAAa,WAAW,GAAG,cAAc,EAAE,GAC/E,OAAO,KAAK,aAAa,MAAM,cAAc;EAEjD,QAAQ,CAER;CACF;AAEF;AAEA,SAAS,mCAAmC,KAAoB;CAC9D,IAAI;EAKF,MAAM,WAAW,cAAc,YAAY,GAAG;EAE9C,MAAM,iBAAiB,sBADN,aAAa,cAAc,YAAY,GAAG,CACP,CAAC;EACrD,MAAM,kBAAuC,CAAC;EAC9C,IAAI,gBACF,gBAAgB,WAAW,SAAS,QAAQ,yCAAyC,EAAE,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;EAEnH,IAAI,QAAQ,KAA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
|
50
|
-
|
|
49
|
+
"deleted",
|
|
50
|
+
"archived",
|
|
51
|
+
"blank"
|
|
52
|
+
].includes(key)) || typeof value.sessionId !== "string" || !value.sessionId || value.sessionId.length > 512 || value.title !== void 0 && (typeof value.title !== "string" || value.title.length > 512 || /[\u0000-\u001f\u007f]/.test(value.title)) || value.workspaceRemotePath !== void 0 && (typeof value.workspaceRemotePath !== "string" || value.workspaceRemotePath.length > 4096 || !posix.isAbsolute(value.workspaceRemotePath) || posix.normalize(value.workspaceRemotePath) !== value.workspaceRemotePath) || value.sizeBytes !== void 0 && !isNonNegativeSafeInteger(value.sizeBytes) || value.branchId !== void 0 && (typeof value.branchId !== "string" || !/^b-[a-f0-9]{32}$/.test(value.branchId)) || value.deleted !== void 0 && typeof value.deleted !== "boolean" || value.archived !== void 0 && typeof value.archived !== "boolean" || value.blank !== void 0 && typeof value.blank !== "boolean") throw new Error("sync catalog session is invalid");
|
|
51
53
|
return {
|
|
52
54
|
origin: parseOrigin(value.origin),
|
|
53
55
|
...value.workspaceOrigin === void 0 ? {} : { workspaceOrigin: parseOrigin(value.workspaceOrigin) },
|
|
@@ -57,7 +59,9 @@ function validateCatalogSession(value) {
|
|
|
57
59
|
...value.title === void 0 ? {} : { title: value.title },
|
|
58
60
|
...value.sizeBytes === void 0 ? {} : { sizeBytes: value.sizeBytes },
|
|
59
61
|
...value.branchId === void 0 ? {} : { branchId: value.branchId },
|
|
60
|
-
...value.deleted === void 0 ? {} : { deleted: value.deleted }
|
|
62
|
+
...value.deleted === void 0 ? {} : { deleted: value.deleted },
|
|
63
|
+
...value.archived === void 0 ? {} : { archived: value.archived },
|
|
64
|
+
...value.blank === void 0 ? {} : { blank: value.blank }
|
|
61
65
|
};
|
|
62
66
|
}
|
|
63
67
|
function validateSyncCatalog(value) {
|
|
@@ -118,4 +122,4 @@ async function exportSyncCatalog(nodes, sessions) {
|
|
|
118
122
|
//#endregion
|
|
119
123
|
export { validateSyncCatalog as n, exportSyncCatalog as t };
|
|
120
124
|
|
|
121
|
-
//# sourceMappingURL=catalog-
|
|
125
|
+
//# sourceMappingURL=catalog-B6Qvy7bH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog-B6Qvy7bH.js","names":[],"sources":["../src/core/sync/catalog.ts"],"sourcesContent":["import { posix } from 'node:path'\nimport type { SyncCatalog, SyncCatalogNode, SyncCatalogSession, SyncCatalogWorkspace, SyncOrigin } from './model.js'\nimport { isNonNegativeSafeInteger, isRecord } from './model.js'\nimport type { SyncNodeService } from './node-sync.js'\nimport type { SyncSessionService } from './session-sync.js'\nimport { MAX_SYNC_TRANSFER_BYTES } from './protocol.js'\n\nconst MAX_CATALOG_ITEMS = 10_000\n\nfunction parseOrigin(value: unknown): SyncOrigin {\n if (!isRecord(value) || Object.keys(value).some((key) => key !== 'originInstanceId' && key !== 'originEntityId') ||\n typeof value.originInstanceId !== 'string' || value.originInstanceId.length === 0 || value.originInstanceId.length > 512 ||\n typeof value.originEntityId !== 'string' || value.originEntityId.length === 0 || value.originEntityId.length > 512 ||\n /[\\u0000-\\u001f\\u007f]/.test(value.originInstanceId) || /[\\u0000-\\u001f\\u007f]/.test(value.originEntityId)) {\n throw new Error('sync catalog origin is invalid')\n }\n return { originInstanceId: value.originInstanceId, originEntityId: value.originEntityId }\n}\n\nfunction validateCatalogNode(value: unknown): SyncCatalogNode {\n if (!isRecord(value) || Object.keys(value).some((key) => !['origin', 'name', 'type'].includes(key)) ||\n typeof value.name !== 'string' || !value.name.trim() || value.name.length > 128 ||\n (value.type !== 'remote-ssh' && value.type !== 'remote-docker')) {\n throw new Error('sync catalog node is invalid')\n }\n return { origin: parseOrigin(value.origin), name: value.name, type: value.type }\n}\n\nfunction validateCatalogWorkspace(value: unknown): SyncCatalogWorkspace {\n if (!isRecord(value) || Object.keys(value).some((key) => !['origin', 'nodeOrigin', 'remotePath', 'title'].includes(key)) ||\n typeof value.remotePath !== 'string' || value.remotePath.length > 4096 || !posix.isAbsolute(value.remotePath) || posix.normalize(value.remotePath) !== value.remotePath ||\n typeof value.title !== 'string' || value.title.length > 512) {\n throw new Error('sync catalog workspace is invalid')\n }\n return {\n origin: parseOrigin(value.origin),\n nodeOrigin: parseOrigin(value.nodeOrigin),\n remotePath: value.remotePath,\n title: value.title,\n }\n}\n\nfunction validateCatalogSession(value: unknown): SyncCatalogSession {\n if (!isRecord(value) || Object.keys(value).some((key) => ![\n 'origin', 'workspaceOrigin', 'workspaceRemotePath', 'nodeOrigin', 'sessionId', 'title', 'sizeBytes', 'branchId', 'deleted', 'archived', 'blank',\n ].includes(key)) || typeof value.sessionId !== 'string' || !value.sessionId || value.sessionId.length > 512 ||\n (value.title !== undefined && (typeof value.title !== 'string' || value.title.length > 512 || /[\\u0000-\\u001f\\u007f]/.test(value.title))) ||\n (value.workspaceRemotePath !== undefined && (typeof value.workspaceRemotePath !== 'string' || value.workspaceRemotePath.length > 4096 ||\n !posix.isAbsolute(value.workspaceRemotePath) || posix.normalize(value.workspaceRemotePath) !== value.workspaceRemotePath)) ||\n (value.sizeBytes !== undefined && !isNonNegativeSafeInteger(value.sizeBytes)) ||\n (value.branchId !== undefined && (typeof value.branchId !== 'string' || !/^b-[a-f0-9]{32}$/.test(value.branchId))) ||\n (value.deleted !== undefined && typeof value.deleted !== 'boolean') ||\n (value.archived !== undefined && typeof value.archived !== 'boolean') ||\n (value.blank !== undefined && typeof value.blank !== 'boolean')) {\n throw new Error('sync catalog session is invalid')\n }\n return {\n origin: parseOrigin(value.origin),\n ...(value.workspaceOrigin === undefined ? {} : { workspaceOrigin: parseOrigin(value.workspaceOrigin) }),\n ...(value.workspaceRemotePath === undefined ? {} : { workspaceRemotePath: value.workspaceRemotePath as string }),\n ...(value.nodeOrigin === undefined ? {} : { nodeOrigin: parseOrigin(value.nodeOrigin) }),\n sessionId: value.sessionId,\n ...(value.title === undefined ? {} : { title: value.title as string }),\n ...(value.sizeBytes === undefined ? {} : { sizeBytes: value.sizeBytes as number }),\n ...(value.branchId === undefined ? {} : { branchId: value.branchId }),\n ...(value.deleted === undefined ? {} : { deleted: value.deleted }),\n ...(value.archived === undefined ? {} : { archived: value.archived }),\n ...(value.blank === undefined ? {} : { blank: value.blank }),\n }\n}\n\nexport function validateSyncCatalog(value: unknown): SyncCatalog {\n if (!isRecord(value) || value.protocolVersion !== 1 || typeof value.instanceId !== 'string' ||\n !/^i-[a-f0-9]{32}$/.test(value.instanceId) || !Array.isArray(value.nodes) ||\n !Array.isArray(value.workspaces) || !Array.isArray(value.sessions) ||\n value.nodes.length > MAX_CATALOG_ITEMS || value.workspaces.length > MAX_CATALOG_ITEMS ||\n value.sessions.length > MAX_CATALOG_ITEMS || Object.keys(value).some((key) =>\n !['protocolVersion', 'instanceId', 'nodes', 'workspaces', 'sessions'].includes(key))) {\n throw new Error('sync catalog is invalid')\n }\n const catalog: SyncCatalog = {\n protocolVersion: 1,\n instanceId: value.instanceId,\n nodes: value.nodes.map(validateCatalogNode),\n workspaces: value.workspaces.map(validateCatalogWorkspace),\n sessions: value.sessions.map(validateCatalogSession),\n }\n const keys = [\n ...catalog.nodes.map((item) => JSON.stringify(['node', item.origin.originInstanceId, item.origin.originEntityId])),\n ...catalog.workspaces.map((item) => JSON.stringify(['workspace', item.origin.originInstanceId, item.origin.originEntityId, item.remotePath])),\n ...catalog.sessions.map((item) => JSON.stringify(['session', item.branchId ?? item.origin.originEntityId, item.origin.originInstanceId])),\n ]\n if (new Set(keys).size !== keys.length) throw new Error('sync catalog contains duplicate records')\n if (Buffer.byteLength(JSON.stringify(catalog), 'utf8') > MAX_SYNC_TRANSFER_BYTES) throw new Error('sync catalog exceeds the transfer limit')\n return catalog\n}\n\nexport async function exportSyncCatalog(nodes: SyncNodeService, sessions: SyncSessionService): Promise<SyncCatalog> {\n const manifest = await nodes.exportManifest()\n const sessionCatalog = await sessions.exportCatalog()\n return validateSyncCatalog({\n protocolVersion: 1,\n instanceId: manifest.instanceId,\n nodes: manifest.records.flatMap((entry) => entry.profile && !entry.metadata.deleted\n ? [{\n origin: { originInstanceId: entry.metadata.originInstanceId, originEntityId: entry.metadata.originEntityId },\n name: entry.profile.name,\n type: entry.profile.type,\n }]\n : []),\n workspaces: sessionCatalog.workspaces,\n sessions: sessionCatalog.sessions,\n })\n}\n"],"mappings":";;;;AAOA,MAAM,oBAAoB;AAE1B,SAAS,YAAY,OAA4B;CAC/C,IAAI,CAAC,SAAS,KAAK,KAAK,OAAO,KAAK,KAAK,CAAC,CAAC,MAAM,QAAQ,QAAQ,sBAAsB,QAAQ,gBAAgB,KAC7G,OAAO,MAAM,qBAAqB,YAAY,MAAM,iBAAiB,WAAW,KAAK,MAAM,iBAAiB,SAAS,OACrH,OAAO,MAAM,mBAAmB,YAAY,MAAM,eAAe,WAAW,KAAK,MAAM,eAAe,SAAS,OAC/G,wBAAwB,KAAK,MAAM,gBAAgB,KAAK,wBAAwB,KAAK,MAAM,cAAc,GACzG,MAAM,IAAI,MAAM,gCAAgC;CAElD,OAAO;EAAE,kBAAkB,MAAM;EAAkB,gBAAgB,MAAM;CAAe;AAC1F;AAEA,SAAS,oBAAoB,OAAiC;CAC5D,IAAI,CAAC,SAAS,KAAK,KAAK,OAAO,KAAK,KAAK,CAAC,CAAC,MAAM,QAAQ,CAAC;EAAC;EAAU;EAAQ;CAAM,CAAC,CAAC,SAAS,GAAG,CAAC,KAChG,OAAO,MAAM,SAAS,YAAY,CAAC,MAAM,KAAK,KAAK,KAAK,MAAM,KAAK,SAAS,OAC3E,MAAM,SAAS,gBAAgB,MAAM,SAAS,iBAC/C,MAAM,IAAI,MAAM,8BAA8B;CAEhD,OAAO;EAAE,QAAQ,YAAY,MAAM,MAAM;EAAG,MAAM,MAAM;EAAM,MAAM,MAAM;CAAK;AACjF;AAEA,SAAS,yBAAyB,OAAsC;CACtE,IAAI,CAAC,SAAS,KAAK,KAAK,OAAO,KAAK,KAAK,CAAC,CAAC,MAAM,QAAQ,CAAC;EAAC;EAAU;EAAc;EAAc;CAAO,CAAC,CAA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