@jingyi0605/codingns4dsh 0.1.0
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 +1114 -0
- package/assets/provider-icons/claude-code.png +0 -0
- package/assets/provider-icons/codex.png +0 -0
- package/assets/provider-icons/command-code.svg +5 -0
- package/assets/provider-icons/deepseek-harness.svg +9 -0
- package/assets/provider-icons/gemini.png +0 -0
- package/assets/provider-icons/grok.png +0 -0
- package/assets/provider-icons/kimi.png +0 -0
- package/assets/provider-icons/opencode.png +0 -0
- package/assets/provider-icons/pi.svg +7 -0
- package/data/build/dist/bootstrap/dsh-connection-adapter.d.ts +97 -0
- package/data/build/dist/bootstrap/dsh-connection-adapter.js +169 -0
- package/data/build/dist/bootstrap/index.d.ts +38 -0
- package/data/build/dist/bootstrap/index.js +44 -0
- package/data/build/dist/client/account-bar.d.ts +9 -0
- package/data/build/dist/client/account-bar.js +398 -0
- package/data/build/dist/client/bundle.js +26167 -0
- package/data/build/dist/client/cli-catalog.d.ts +24 -0
- package/data/build/dist/client/cli-catalog.js +108 -0
- package/data/build/dist/client/cli-slots.d.ts +38 -0
- package/data/build/dist/client/cli-slots.js +297 -0
- package/data/build/dist/client/debug/ui.d.ts +12 -0
- package/data/build/dist/client/debug/ui.js +451 -0
- package/data/build/dist/client/dsh-h5-bootstrap.d.ts +64 -0
- package/data/build/dist/client/dsh-h5-bootstrap.js +293 -0
- package/data/build/dist/client/dsh-runtime-version.d.ts +3 -0
- package/data/build/dist/client/dsh-runtime-version.js +11 -0
- package/data/build/dist/client/external-tool-stream.d.ts +24 -0
- package/data/build/dist/client/external-tool-stream.js +114 -0
- package/data/build/dist/client/features/cli-adapters.d.ts +7 -0
- package/data/build/dist/client/features/cli-adapters.js +215 -0
- package/data/build/dist/client/features/debug.d.ts +4 -0
- package/data/build/dist/client/features/debug.js +24 -0
- package/data/build/dist/client/features/index.d.ts +33 -0
- package/data/build/dist/client/features/index.js +44 -0
- package/data/build/dist/client/features/lan-access-panel.d.ts +5 -0
- package/data/build/dist/client/features/lan-access-panel.js +146 -0
- package/data/build/dist/client/features/lan-access.d.ts +9 -0
- package/data/build/dist/client/features/lan-access.js +30 -0
- package/data/build/dist/client/features/login-protection-panel.d.ts +5 -0
- package/data/build/dist/client/features/login-protection-panel.js +91 -0
- package/data/build/dist/client/features/login-protection-session.d.ts +6 -0
- package/data/build/dist/client/features/login-protection-session.js +25 -0
- package/data/build/dist/client/features/login-protection.d.ts +4 -0
- package/data/build/dist/client/features/login-protection.js +23 -0
- package/data/build/dist/client/features/reverse-proxy-panel.d.ts +9 -0
- package/data/build/dist/client/features/reverse-proxy-panel.js +159 -0
- package/data/build/dist/client/features/reverse-proxy.d.ts +12 -0
- package/data/build/dist/client/features/reverse-proxy.js +112 -0
- package/data/build/dist/client/features/terminal-enhancement-panel.d.ts +5 -0
- package/data/build/dist/client/features/terminal-enhancement-panel.js +160 -0
- package/data/build/dist/client/features/terminal-enhancement.d.ts +4 -0
- package/data/build/dist/client/features/terminal-enhancement.js +24 -0
- package/data/build/dist/client/features/types.d.ts +58 -0
- package/data/build/dist/client/features/types.js +2 -0
- package/data/build/dist/client/features/workspace-session-enhancement-panel.d.ts +5 -0
- package/data/build/dist/client/features/workspace-session-enhancement-panel.js +66 -0
- package/data/build/dist/client/features/workspace-session-enhancement.d.ts +4 -0
- package/data/build/dist/client/features/workspace-session-enhancement.js +101 -0
- package/data/build/dist/client/h5-bootstrap-entry.d.ts +2 -0
- package/data/build/dist/client/h5-bootstrap-entry.js +17 -0
- package/data/build/dist/client/index.d.ts +31 -0
- package/data/build/dist/client/index.js +98 -0
- package/data/build/dist/client/lan-access.d.ts +28 -0
- package/data/build/dist/client/lan-access.js +68 -0
- package/data/build/dist/client/locale.d.ts +20 -0
- package/data/build/dist/client/locale.js +393 -0
- package/data/build/dist/client/provider-icon-assets.d.ts +2 -0
- package/data/build/dist/client/provider-icon-assets.js +23 -0
- package/data/build/dist/client/provider-icons.d.ts +19 -0
- package/data/build/dist/client/provider-icons.js +39 -0
- package/data/build/dist/client/remote-web-context.d.ts +57 -0
- package/data/build/dist/client/remote-web-context.js +939 -0
- package/data/build/dist/client/session-adapter-cache.d.ts +18 -0
- package/data/build/dist/client/session-adapter-cache.js +84 -0
- package/data/build/dist/client/settings-bridge.d.ts +32 -0
- package/data/build/dist/client/settings-bridge.js +126 -0
- package/data/build/dist/client/settings-section.d.ts +30 -0
- package/data/build/dist/client/settings-section.js +93 -0
- package/data/build/dist/client/subscription-slot.d.ts +18 -0
- package/data/build/dist/client/subscription-slot.js +223 -0
- package/data/build/dist/client/terminal/index.d.ts +4 -0
- package/data/build/dist/client/terminal/index.js +3 -0
- package/data/build/dist/client/terminal/model.d.ts +116 -0
- package/data/build/dist/client/terminal/model.js +435 -0
- package/data/build/dist/client/terminal/styles.d.ts +21 -0
- package/data/build/dist/client/terminal/styles.js +51 -0
- package/data/build/dist/client/terminal/ui.d.ts +19 -0
- package/data/build/dist/client/terminal/ui.js +257 -0
- package/data/build/dist/client/terminal/xterm-view.d.ts +13 -0
- package/data/build/dist/client/terminal/xterm-view.js +213 -0
- package/data/build/dist/client/theme.d.ts +56 -0
- package/data/build/dist/client/theme.js +186 -0
- package/data/build/dist/client/workspace-session-archive-dom.d.ts +29 -0
- package/data/build/dist/client/workspace-session-archive-dom.js +525 -0
- package/data/build/dist/client/workspace-session-fiber.d.ts +3 -0
- package/data/build/dist/client/workspace-session-fiber.js +33 -0
- package/data/build/dist/client/workspace-session-logo-dom.d.ts +26 -0
- package/data/build/dist/client/workspace-session-logo-dom.js +128 -0
- package/data/build/dist/features/index.d.ts +3 -0
- package/data/build/dist/features/index.js +2 -0
- package/data/build/dist/features/registry.d.ts +74 -0
- package/data/build/dist/features/registry.js +382 -0
- package/data/build/dist/features/resource-scope/index.d.ts +39 -0
- package/data/build/dist/features/resource-scope/index.js +161 -0
- package/data/build/dist/host/auth-session.d.ts +42 -0
- package/data/build/dist/host/auth-session.js +186 -0
- package/data/build/dist/host/cli-adapters/claude-driver.d.ts +14 -0
- package/data/build/dist/host/cli-adapters/claude-driver.js +103 -0
- package/data/build/dist/host/cli-adapters/codex-driver.d.ts +45 -0
- package/data/build/dist/host/cli-adapters/codex-driver.js +534 -0
- package/data/build/dist/host/cli-adapters/command-code-driver.d.ts +38 -0
- package/data/build/dist/host/cli-adapters/command-code-driver.js +394 -0
- package/data/build/dist/host/cli-adapters/command-code-subscription.d.ts +19 -0
- package/data/build/dist/host/cli-adapters/command-code-subscription.js +126 -0
- package/data/build/dist/host/cli-adapters/driver.d.ts +41 -0
- package/data/build/dist/host/cli-adapters/driver.js +2 -0
- package/data/build/dist/host/cli-adapters/dsh-message-projector.d.ts +37 -0
- package/data/build/dist/host/cli-adapters/dsh-message-projector.js +180 -0
- package/data/build/dist/host/cli-adapters/dsh-tool-history.d.ts +48 -0
- package/data/build/dist/host/cli-adapters/dsh-tool-history.js +373 -0
- package/data/build/dist/host/cli-adapters/feature.d.ts +7 -0
- package/data/build/dist/host/cli-adapters/feature.js +335 -0
- package/data/build/dist/host/cli-adapters/gemini-driver.d.ts +24 -0
- package/data/build/dist/host/cli-adapters/gemini-driver.js +427 -0
- package/data/build/dist/host/cli-adapters/grok-driver.d.ts +38 -0
- package/data/build/dist/host/cli-adapters/grok-driver.js +372 -0
- package/data/build/dist/host/cli-adapters/http-sse-client.d.ts +22 -0
- package/data/build/dist/host/cli-adapters/http-sse-client.js +99 -0
- package/data/build/dist/host/cli-adapters/interaction-events.d.ts +11 -0
- package/data/build/dist/host/cli-adapters/interaction-events.js +80 -0
- package/data/build/dist/host/cli-adapters/json-rpc-process.d.ts +65 -0
- package/data/build/dist/host/cli-adapters/json-rpc-process.js +256 -0
- package/data/build/dist/host/cli-adapters/kimi-driver.d.ts +21 -0
- package/data/build/dist/host/cli-adapters/kimi-driver.js +382 -0
- package/data/build/dist/host/cli-adapters/model-catalog.d.ts +22 -0
- package/data/build/dist/host/cli-adapters/model-catalog.js +89 -0
- package/data/build/dist/host/cli-adapters/opencode-driver.d.ts +55 -0
- package/data/build/dist/host/cli-adapters/opencode-driver.js +728 -0
- package/data/build/dist/host/cli-adapters/pi-driver.d.ts +43 -0
- package/data/build/dist/host/cli-adapters/pi-driver.js +312 -0
- package/data/build/dist/host/cli-adapters/process-utils.d.ts +16 -0
- package/data/build/dist/host/cli-adapters/process-utils.js +27 -0
- package/data/build/dist/host/cli-adapters/provider-subscription.d.ts +82 -0
- package/data/build/dist/host/cli-adapters/provider-subscription.js +610 -0
- package/data/build/dist/host/cli-adapters/registry.d.ts +95 -0
- package/data/build/dist/host/cli-adapters/registry.js +659 -0
- package/data/build/dist/host/cli-adapters/rpc-driver-utils.d.ts +24 -0
- package/data/build/dist/host/cli-adapters/rpc-driver-utils.js +119 -0
- package/data/build/dist/host/cli-adapters/session-probe.d.ts +20 -0
- package/data/build/dist/host/cli-adapters/session-probe.js +139 -0
- package/data/build/dist/host/cli-adapters/session-store.d.ts +68 -0
- package/data/build/dist/host/cli-adapters/session-store.js +180 -0
- package/data/build/dist/host/cli-adapters/standard-stream-driver.d.ts +45 -0
- package/data/build/dist/host/cli-adapters/standard-stream-driver.js +205 -0
- package/data/build/dist/host/cli-adapters/stream-normalizer.d.ts +25 -0
- package/data/build/dist/host/cli-adapters/stream-normalizer.js +83 -0
- package/data/build/dist/host/cli-adapters/tool-observation.d.ts +9 -0
- package/data/build/dist/host/cli-adapters/tool-observation.js +39 -0
- package/data/build/dist/host/control-api-client.d.ts +84 -0
- package/data/build/dist/host/control-api-client.js +130 -0
- package/data/build/dist/host/credential-store.d.ts +54 -0
- package/data/build/dist/host/credential-store.js +114 -0
- package/data/build/dist/host/debug.d.ts +79 -0
- package/data/build/dist/host/debug.js +295 -0
- package/data/build/dist/host/dsh-device-runtime.d.ts +39 -0
- package/data/build/dist/host/dsh-device-runtime.js +118 -0
- package/data/build/dist/host/dsh-gateway-feature.d.ts +5 -0
- package/data/build/dist/host/dsh-gateway-feature.js +55 -0
- package/data/build/dist/host/dsh-runtime-version.d.ts +12 -0
- package/data/build/dist/host/dsh-runtime-version.js +69 -0
- package/data/build/dist/host/features/auth.d.ts +11 -0
- package/data/build/dist/host/features/auth.js +273 -0
- package/data/build/dist/host/features/debug.d.ts +5 -0
- package/data/build/dist/host/features/debug.js +90 -0
- package/data/build/dist/host/features/host-status.d.ts +12 -0
- package/data/build/dist/host/features/host-status.js +54 -0
- package/data/build/dist/host/features/index.d.ts +19 -0
- package/data/build/dist/host/features/index.js +29 -0
- package/data/build/dist/host/features/lan-access-dsh.d.ts +8 -0
- package/data/build/dist/host/features/lan-access-dsh.js +45 -0
- package/data/build/dist/host/features/terminal-process.d.ts +5 -0
- package/data/build/dist/host/features/terminal-process.js +110 -0
- package/data/build/dist/host/features/terminal-status.d.ts +18 -0
- package/data/build/dist/host/features/terminal-status.js +56 -0
- package/data/build/dist/host/features/types.d.ts +41 -0
- package/data/build/dist/host/features/types.js +2 -0
- package/data/build/dist/host/index.d.ts +43 -0
- package/data/build/dist/host/index.js +135 -0
- package/data/build/dist/host/lan-access-dsh.d.ts +83 -0
- package/data/build/dist/host/lan-access-dsh.js +831 -0
- package/data/build/dist/host/native-session-bridge.d.ts +130 -0
- package/data/build/dist/host/native-session-bridge.js +317 -0
- package/data/build/dist/host/relay-tunnel-runtime.d.ts +97 -0
- package/data/build/dist/host/relay-tunnel-runtime.js +361 -0
- package/data/build/dist/host/remote-web-runtime.d.ts +78 -0
- package/data/build/dist/host/remote-web-runtime.js +559 -0
- package/data/build/dist/host/rpc-table.d.ts +32 -0
- package/data/build/dist/host/rpc-table.js +47 -0
- package/data/build/dist/host/rpc.d.ts +18 -0
- package/data/build/dist/host/rpc.js +248 -0
- package/data/build/dist/host/settings.d.ts +19 -0
- package/data/build/dist/host/settings.js +80 -0
- package/data/build/dist/host/terminal/attachment-registry.d.ts +17 -0
- package/data/build/dist/host/terminal/attachment-registry.js +49 -0
- package/data/build/dist/host/terminal/backends/conpty-backend.d.ts +39 -0
- package/data/build/dist/host/terminal/backends/conpty-backend.js +160 -0
- package/data/build/dist/host/terminal/backends/local-pty-backend.d.ts +36 -0
- package/data/build/dist/host/terminal/backends/local-pty-backend.js +178 -0
- package/data/build/dist/host/terminal/backends/tmux-backend.d.ts +40 -0
- package/data/build/dist/host/terminal/backends/tmux-backend.js +191 -0
- package/data/build/dist/host/terminal/broker/conpty-broker-client.d.ts +27 -0
- package/data/build/dist/host/terminal/broker/conpty-broker-client.js +154 -0
- package/data/build/dist/host/terminal/broker/conpty-broker-process.d.ts +10 -0
- package/data/build/dist/host/terminal/broker/conpty-broker-process.js +147 -0
- package/data/build/dist/host/terminal/broker/conpty-broker-protocol.d.ts +92 -0
- package/data/build/dist/host/terminal/broker/conpty-broker-protocol.js +134 -0
- package/data/build/dist/host/terminal/controller-factory.d.ts +37 -0
- package/data/build/dist/host/terminal/controller-factory.js +82 -0
- package/data/build/dist/host/terminal/index.d.ts +17 -0
- package/data/build/dist/host/terminal/index.js +17 -0
- package/data/build/dist/host/terminal/runtime-adapter.d.ts +77 -0
- package/data/build/dist/host/terminal/runtime-adapter.js +18 -0
- package/data/build/dist/host/terminal/runtime-manager.d.ts +41 -0
- package/data/build/dist/host/terminal/runtime-manager.js +179 -0
- package/data/build/dist/host/terminal/shell-detection.d.ts +23 -0
- package/data/build/dist/host/terminal/shell-detection.js +105 -0
- package/data/build/dist/host/terminal/startup.d.ts +33 -0
- package/data/build/dist/host/terminal/startup.js +100 -0
- package/data/build/dist/host/terminal/terminal-controller.d.ts +78 -0
- package/data/build/dist/host/terminal/terminal-controller.js +324 -0
- package/data/build/dist/host/terminal/terminal-process-service.d.ts +30 -0
- package/data/build/dist/host/terminal/terminal-process-service.js +194 -0
- package/data/build/dist/host/terminal/terminal-process-store.d.ts +45 -0
- package/data/build/dist/host/terminal/terminal-process-store.js +183 -0
- package/data/build/dist/host/terminal/terminal-service.d.ts +87 -0
- package/data/build/dist/host/terminal/terminal-service.js +528 -0
- package/data/build/dist/host/terminal/terminal-store.d.ts +49 -0
- package/data/build/dist/host/terminal/terminal-store.js +242 -0
- package/data/build/dist/index.d.ts +37 -0
- package/data/build/dist/index.js +26 -0
- package/data/build/dist/shared/contracts/auth.d.ts +122 -0
- package/data/build/dist/shared/contracts/auth.js +8 -0
- package/data/build/dist/shared/contracts/cli-adapter.d.ts +192 -0
- package/data/build/dist/shared/contracts/cli-adapter.js +2 -0
- package/data/build/dist/shared/contracts/command-code.d.ts +5 -0
- package/data/build/dist/shared/contracts/command-code.js +2 -0
- package/data/build/dist/shared/contracts/config.d.ts +113 -0
- package/data/build/dist/shared/contracts/config.js +86 -0
- package/data/build/dist/shared/contracts/debug-config.d.ts +28 -0
- package/data/build/dist/shared/contracts/debug-config.js +78 -0
- package/data/build/dist/shared/contracts/debug.d.ts +75 -0
- package/data/build/dist/shared/contracts/debug.js +121 -0
- package/data/build/dist/shared/contracts/dsh-device.d.ts +72 -0
- package/data/build/dist/shared/contracts/dsh-device.js +2 -0
- package/data/build/dist/shared/contracts/errors.d.ts +33 -0
- package/data/build/dist/shared/contracts/errors.js +41 -0
- package/data/build/dist/shared/contracts/feature.d.ts +71 -0
- package/data/build/dist/shared/contracts/feature.js +2 -0
- package/data/build/dist/shared/contracts/host-status.d.ts +14 -0
- package/data/build/dist/shared/contracts/host-status.js +2 -0
- package/data/build/dist/shared/contracts/lan-access-dsh.d.ts +30 -0
- package/data/build/dist/shared/contracts/lan-access-dsh.js +2 -0
- package/data/build/dist/shared/contracts/peer-host.d.ts +37 -0
- package/data/build/dist/shared/contracts/peer-host.js +9 -0
- package/data/build/dist/shared/contracts/signaling.d.ts +67 -0
- package/data/build/dist/shared/contracts/signaling.js +2 -0
- package/data/build/dist/shared/contracts/subscription.d.ts +69 -0
- package/data/build/dist/shared/contracts/subscription.js +2 -0
- package/data/build/dist/shared/contracts/terminal-process.d.ts +65 -0
- package/data/build/dist/shared/contracts/terminal-process.js +2 -0
- package/data/build/dist/shared/contracts/terminal.d.ts +127 -0
- package/data/build/dist/shared/contracts/terminal.js +2 -0
- package/data/build/dist/shared/contracts/transport.d.ts +45 -0
- package/data/build/dist/shared/contracts/transport.js +3 -0
- package/data/build/dist/shared/contracts/version.d.ts +19 -0
- package/data/build/dist/shared/contracts/version.js +74 -0
- package/data/build/dist/shared/index.d.ts +22 -0
- package/data/build/dist/shared/index.js +9 -0
- package/data/build/dist/transport/carrier.d.ts +38 -0
- package/data/build/dist/transport/carrier.js +268 -0
- package/data/build/dist/transport/debug.d.ts +22 -0
- package/data/build/dist/transport/debug.js +57 -0
- package/data/build/dist/transport/dsh-envelope.d.ts +41 -0
- package/data/build/dist/transport/dsh-envelope.js +107 -0
- package/data/build/dist/transport/dsh-gateway.d.ts +64 -0
- package/data/build/dist/transport/dsh-gateway.js +254 -0
- package/data/build/dist/transport/dsh-session.d.ts +55 -0
- package/data/build/dist/transport/dsh-session.js +256 -0
- package/data/build/dist/transport/dsh-transport.d.ts +57 -0
- package/data/build/dist/transport/dsh-transport.js +125 -0
- package/data/build/dist/transport/frame.d.ts +132 -0
- package/data/build/dist/transport/frame.js +168 -0
- package/data/build/dist/transport/index.d.ts +11 -0
- package/data/build/dist/transport/index.js +11 -0
- package/data/build/dist/transport/multiplexer.d.ts +63 -0
- package/data/build/dist/transport/multiplexer.js +323 -0
- package/data/build/dist/transport/webrtc-client.d.ts +65 -0
- package/data/build/dist/transport/webrtc-client.js +255 -0
- package/data/build/dist/transport/webrtc-host.d.ts +58 -0
- package/data/build/dist/transport/webrtc-host.js +252 -0
- package/data/build/dist/typert.host.d.ts +25 -0
- package/data/build/dist/typert.host.js +150 -0
- package/dsh.bundle.patch +12 -0
- package/package.json +135 -0
- package/profile/README.md +27 -0
- package/profile/cordis.patch.yml +2 -0
- package/profile/package.json +20 -0
- package/profile/scripts/check-dsh-install.mjs +71 -0
- package/profile/version.json +5 -0
- package/scripts/check-dsh-install.mjs +88 -0
- package/version.json +6 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
import type { CodingNsAgentQuestion, CodingNsAgentQuestionResponse } from '../shared/contracts/cli-adapter.js';
|
|
3
|
+
/**
|
|
4
|
+
* DSH Host 原生会话服务的最小运行时面。
|
|
5
|
+
*
|
|
6
|
+
* 这里故意不直接依赖 dsh-session 或 dsh-api-session-controller:插件的
|
|
7
|
+
* package.json 只锁定 DSH 兼容版本,某些精简 Host 可能没有装载完整会话服务。
|
|
8
|
+
* 运行时探测可以让这类 Host 继续使用 Codingns4DSH,而完整 DSH 则优先走原生 API。
|
|
9
|
+
*/
|
|
10
|
+
export interface CodingNsNativeSessionStore {
|
|
11
|
+
get(sessionId: string): unknown;
|
|
12
|
+
list(): readonly unknown[];
|
|
13
|
+
flush?(session: unknown): Promise<boolean> | Promise<void> | boolean | void;
|
|
14
|
+
}
|
|
15
|
+
/** 公共 CLI 投影层写入 DSH 的工具调用,不包含任何 Provider 私有字段。 */
|
|
16
|
+
export interface CodingNsNativeToolCall {
|
|
17
|
+
readonly callId: string;
|
|
18
|
+
readonly name: string;
|
|
19
|
+
readonly arguments: string;
|
|
20
|
+
}
|
|
21
|
+
/** 一次工具调用在 DSH Session 中的稳定位置。 */
|
|
22
|
+
export interface CodingNsNativeToolCallHandle {
|
|
23
|
+
readonly sessionId: string;
|
|
24
|
+
readonly turn: number;
|
|
25
|
+
readonly step: number;
|
|
26
|
+
readonly callId: string;
|
|
27
|
+
readonly callSeq: number;
|
|
28
|
+
}
|
|
29
|
+
/** 公共 CLI 投影层写入 DSH 的工具结果。 */
|
|
30
|
+
export interface CodingNsNativeToolResult {
|
|
31
|
+
readonly output: string;
|
|
32
|
+
readonly isError: boolean;
|
|
33
|
+
readonly error?: string;
|
|
34
|
+
readonly meta?: unknown;
|
|
35
|
+
}
|
|
36
|
+
/** 外部 Agent 工具在 DSH Session 中的只读时间线标记。 */
|
|
37
|
+
export interface CodingNsNativeExternalToolEvent {
|
|
38
|
+
readonly phase: 'start' | 'update';
|
|
39
|
+
readonly callId: string;
|
|
40
|
+
readonly name: string;
|
|
41
|
+
readonly arguments: string;
|
|
42
|
+
readonly status: 'running' | 'completed' | 'failed';
|
|
43
|
+
readonly output?: string;
|
|
44
|
+
readonly error?: string;
|
|
45
|
+
}
|
|
46
|
+
export type CodingNsNativeApprovalOutcome = 'allowed-once' | 'rejected' | 'cancelled' | 'unavailable';
|
|
47
|
+
/** 公共消息投影层交给 DSH 原生权限服务的请求。 */
|
|
48
|
+
export interface CodingNsNativeApprovalRequest {
|
|
49
|
+
readonly requestId: string;
|
|
50
|
+
readonly toolName: string;
|
|
51
|
+
readonly callId?: string;
|
|
52
|
+
readonly reason?: string;
|
|
53
|
+
readonly signal?: AbortSignal;
|
|
54
|
+
}
|
|
55
|
+
/** 公共消息投影层交给 DSH 原生问题服务的请求。 */
|
|
56
|
+
export interface CodingNsNativeQuestionRequest {
|
|
57
|
+
readonly requestId: string;
|
|
58
|
+
readonly questions: readonly CodingNsAgentQuestion[];
|
|
59
|
+
readonly signal?: AbortSignal;
|
|
60
|
+
}
|
|
61
|
+
/** 外部 Agent 已确认的模型路由上下文容量,用于 DSH token-meter 的上下文占用投影。 */
|
|
62
|
+
export interface CodingNsNativeRequestContext {
|
|
63
|
+
readonly provider: string;
|
|
64
|
+
readonly model: string;
|
|
65
|
+
readonly contextWindow?: number;
|
|
66
|
+
}
|
|
67
|
+
export interface CodingNsNativeSessionController {
|
|
68
|
+
create?(request: {
|
|
69
|
+
readonly sessionId?: string;
|
|
70
|
+
readonly cwd?: string;
|
|
71
|
+
}): Promise<{
|
|
72
|
+
readonly sessionId: string;
|
|
73
|
+
}>;
|
|
74
|
+
list?(request?: unknown, signal?: AbortSignal): Promise<{
|
|
75
|
+
readonly items: readonly unknown[];
|
|
76
|
+
}>;
|
|
77
|
+
}
|
|
78
|
+
/** DSH 工作区控制器负责改变原生侧栏中的会话可见性。 */
|
|
79
|
+
export interface CodingNsNativeWorkspaceController {
|
|
80
|
+
archiveSession?(request: {
|
|
81
|
+
readonly sessionId: string;
|
|
82
|
+
}): Promise<unknown> | unknown;
|
|
83
|
+
unarchiveSession?(request: {
|
|
84
|
+
readonly sessionId: string;
|
|
85
|
+
}): Promise<unknown> | unknown;
|
|
86
|
+
}
|
|
87
|
+
export interface CodingNsNativeSessionBridge {
|
|
88
|
+
readonly available: boolean;
|
|
89
|
+
/** 当前 Host 是否提供可接收 Session 事件的事件总线。 */
|
|
90
|
+
readonly supportsEvents: boolean;
|
|
91
|
+
readonly store: CodingNsNativeSessionStore | undefined;
|
|
92
|
+
readonly controller: CodingNsNativeSessionController | undefined;
|
|
93
|
+
readonly workspaceController?: CodingNsNativeWorkspaceController;
|
|
94
|
+
/** 获取已经进入 DSH 原生 SessionStore 的会话。 */
|
|
95
|
+
get(sessionId: string): unknown | undefined;
|
|
96
|
+
/** 获取当前 Host 已装载的原生会话;失败时返回空数组。 */
|
|
97
|
+
list(): readonly unknown[];
|
|
98
|
+
/** 调用 DSH 原生 session/list;无 Controller 时回退到本地 SessionStore。 */
|
|
99
|
+
listRemote(signal?: AbortSignal): Promise<readonly unknown[]>;
|
|
100
|
+
/** 创建或采用一个 DSH 原生会话。 */
|
|
101
|
+
ensure(sessionId: string, cwd?: string): Promise<string | null>;
|
|
102
|
+
/** 等待 DSH 原生持久化监听器完成当前会话的检查点。 */
|
|
103
|
+
flush(sessionId: string): Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* 只追加已由外部 Agent 执行的工具历史,不经过 DSH Agent Loop。
|
|
106
|
+
* 返回 null 表示会话或活动 step 不可用,调用方应安静降级。
|
|
107
|
+
*/
|
|
108
|
+
appendToolCall?(sessionId: string, call: CodingNsNativeToolCall): CodingNsNativeToolCallHandle | null;
|
|
109
|
+
/** 追加与 appendToolCall 配对的只读结果;不会再次执行工具。 */
|
|
110
|
+
appendToolResult?(handle: CodingNsNativeToolCallHandle, result: CodingNsNativeToolResult): boolean;
|
|
111
|
+
/** 兼容旧调用方;内部仍转换为 DSH 原生 tool/call 与 tool/result。 */
|
|
112
|
+
appendExternalToolEvent?(sessionId: string, event: CodingNsNativeExternalToolEvent): boolean;
|
|
113
|
+
/** 写入当前原生步骤的路由上下文元数据,不携带凭据或消息正文。 */
|
|
114
|
+
appendRequestContext?(sessionId: string, context: CodingNsNativeRequestContext): boolean;
|
|
115
|
+
/** 使用 DSH 原生 approval 组件请求一次权限决定;服务不可用时拒绝。 */
|
|
116
|
+
requestApproval?(sessionId: string, request: CodingNsNativeApprovalRequest): Promise<CodingNsNativeApprovalOutcome>;
|
|
117
|
+
/** 使用 DSH 原生 userQuestions 组件提问;服务不可用或取消时返回 null。 */
|
|
118
|
+
askQuestions?(sessionId: string, request: CodingNsNativeQuestionRequest): Promise<CodingNsAgentQuestionResponse | null>;
|
|
119
|
+
/** 从 DSH 原生侧栏归档会话;控制器不可用时返回 false。 */
|
|
120
|
+
archive?(sessionId: string): Promise<boolean>;
|
|
121
|
+
/** 恢复 DSH 原生侧栏中的归档会话;控制器不可用时返回 false。 */
|
|
122
|
+
unarchive?(sessionId: string): Promise<boolean>;
|
|
123
|
+
/** 订阅 DSH 的原生事件流;返回值用于在功能停用时移除监听器。 */
|
|
124
|
+
subscribe(handlers: {
|
|
125
|
+
readonly onEvent?: (session: unknown, event: unknown) => void;
|
|
126
|
+
readonly onFlush?: (session: unknown) => void | Promise<void>;
|
|
127
|
+
}): () => void;
|
|
128
|
+
}
|
|
129
|
+
export declare function createCodingNsNativeSessionBridge(ctx: Context): CodingNsNativeSessionBridge;
|
|
130
|
+
//# sourceMappingURL=native-session-bridge.d.ts.map
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
export function createCodingNsNativeSessionBridge(ctx) {
|
|
2
|
+
// Cordis Context 是运行时代理,直接读取未在 inject 中声明的可选服务会抛错。
|
|
3
|
+
// get() 专门用于无强制依赖的服务探测,精简 Host 缺少服务时会返回 undefined。
|
|
4
|
+
const storeValue = ctx.get('sessions');
|
|
5
|
+
const controllerValue = ctx.get('sessionController');
|
|
6
|
+
const workspaceControllerValue = ctx.get('workspaceController');
|
|
7
|
+
const store = isSessionStore(storeValue) ? storeValue : undefined;
|
|
8
|
+
const controller = isSessionController(controllerValue) ? controllerValue : undefined;
|
|
9
|
+
const workspaceController = isWorkspaceController(workspaceControllerValue) ? workspaceControllerValue : undefined;
|
|
10
|
+
const currentWorkspaceController = () => {
|
|
11
|
+
const value = ctx.get('workspaceController');
|
|
12
|
+
return isWorkspaceController(value) ? value : undefined;
|
|
13
|
+
};
|
|
14
|
+
const on = typeof ctx.on === 'function'
|
|
15
|
+
? ctx.on.bind(ctx)
|
|
16
|
+
: undefined;
|
|
17
|
+
const externalHandles = new Map();
|
|
18
|
+
const appendNativeToolCall = (sessionId, call) => {
|
|
19
|
+
const session = appendableSession(store?.get(sessionId));
|
|
20
|
+
const position = session === null ? null : activeStep(session);
|
|
21
|
+
if (session === null || position === null)
|
|
22
|
+
return null;
|
|
23
|
+
const event = session.append('tool/call', {
|
|
24
|
+
turn: position.turn,
|
|
25
|
+
step: position.step,
|
|
26
|
+
callId: call.callId,
|
|
27
|
+
name: call.name,
|
|
28
|
+
arguments: call.arguments,
|
|
29
|
+
});
|
|
30
|
+
const callSeq = eventSeq(event);
|
|
31
|
+
return callSeq === null ? null : { sessionId, ...position, callId: call.callId, callSeq };
|
|
32
|
+
};
|
|
33
|
+
const appendNativeToolResult = (handle, result) => {
|
|
34
|
+
const session = appendableSession(store?.get(handle.sessionId));
|
|
35
|
+
if (session === null)
|
|
36
|
+
return false;
|
|
37
|
+
const error = result.error?.trim();
|
|
38
|
+
session.append('tool/result', {
|
|
39
|
+
turn: handle.turn,
|
|
40
|
+
step: handle.step,
|
|
41
|
+
message: {
|
|
42
|
+
id: `${handle.callId}-result-${handle.turn}-${handle.step}`,
|
|
43
|
+
role: 'user',
|
|
44
|
+
content: [{
|
|
45
|
+
type: 'tool-result',
|
|
46
|
+
toolCallId: handle.callId,
|
|
47
|
+
content: [{ type: 'text', text: result.output }],
|
|
48
|
+
...(result.isError ? { isError: true } : {}),
|
|
49
|
+
}],
|
|
50
|
+
source: { kind: 'tool', callId: handle.callId },
|
|
51
|
+
},
|
|
52
|
+
...(result.isError
|
|
53
|
+
? { error: { name: 'ExternalToolError', code: 'EXTERNAL_TOOL_FAILED', ...(error ? { reason: error } : {}) } }
|
|
54
|
+
: {}),
|
|
55
|
+
...(result.meta === undefined ? {} : { meta: result.meta }),
|
|
56
|
+
}, {
|
|
57
|
+
surfaceOp: 'append',
|
|
58
|
+
sourceEventSeqs: [handle.callSeq],
|
|
59
|
+
});
|
|
60
|
+
return true;
|
|
61
|
+
};
|
|
62
|
+
const appendNativeRequestContext = (sessionId, context) => {
|
|
63
|
+
const session = appendableSession(store?.get(sessionId));
|
|
64
|
+
if (session === null || context.provider.trim() === '' || context.model.trim() === '')
|
|
65
|
+
return false;
|
|
66
|
+
try {
|
|
67
|
+
session.append('request/context', {
|
|
68
|
+
provider: context.provider,
|
|
69
|
+
model: context.model,
|
|
70
|
+
...(context.contextWindow === undefined ? {} : { contextWindow: context.contextWindow }),
|
|
71
|
+
});
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
return {
|
|
79
|
+
get available() {
|
|
80
|
+
return store !== undefined || controller !== undefined || currentWorkspaceController() !== undefined;
|
|
81
|
+
},
|
|
82
|
+
supportsEvents: on !== undefined,
|
|
83
|
+
store,
|
|
84
|
+
controller,
|
|
85
|
+
...(workspaceController === undefined ? {} : { workspaceController }),
|
|
86
|
+
get(sessionId) {
|
|
87
|
+
return store?.get(sessionId);
|
|
88
|
+
},
|
|
89
|
+
list() {
|
|
90
|
+
try {
|
|
91
|
+
return store?.list() ?? [];
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return [];
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
async listRemote(signal) {
|
|
98
|
+
if (controller?.list !== undefined) {
|
|
99
|
+
try {
|
|
100
|
+
return (await controller.list({}, signal)).items;
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return this.list();
|
|
107
|
+
},
|
|
108
|
+
async ensure(sessionId, cwd) {
|
|
109
|
+
if (sessionId.trim() === '')
|
|
110
|
+
return null;
|
|
111
|
+
if (store?.get(sessionId) !== undefined)
|
|
112
|
+
return sessionId;
|
|
113
|
+
if (controller?.create !== undefined) {
|
|
114
|
+
const created = await controller.create({ sessionId, ...(cwd ? { cwd } : {}) });
|
|
115
|
+
return typeof created.sessionId === 'string' && created.sessionId.trim() ? created.sessionId : sessionId;
|
|
116
|
+
}
|
|
117
|
+
// 不调用裸 SessionStore.create():它把会话绑定到插件 Fiber,停用插件
|
|
118
|
+
// 时会被移除,无法满足长期会话和原生侧栏持久化要求。
|
|
119
|
+
return null;
|
|
120
|
+
},
|
|
121
|
+
async flush(sessionId) {
|
|
122
|
+
const session = store?.get(sessionId);
|
|
123
|
+
if (session === undefined || store?.flush === undefined)
|
|
124
|
+
return;
|
|
125
|
+
await store.flush(session);
|
|
126
|
+
},
|
|
127
|
+
appendToolCall(sessionId, call) {
|
|
128
|
+
return appendNativeToolCall(sessionId, call);
|
|
129
|
+
},
|
|
130
|
+
appendToolResult(handle, result) {
|
|
131
|
+
return appendNativeToolResult(handle, result);
|
|
132
|
+
},
|
|
133
|
+
appendRequestContext(sessionId, context) {
|
|
134
|
+
return appendNativeRequestContext(sessionId, context);
|
|
135
|
+
},
|
|
136
|
+
appendExternalToolEvent(sessionId, externalTool) {
|
|
137
|
+
try {
|
|
138
|
+
// 兼容旧调用方,但仍然写入 DSH 原生工具事件,绝不能伪造 assistant/attempt。
|
|
139
|
+
const key = `${sessionId}:${externalTool.callId}`;
|
|
140
|
+
if (externalTool.phase === 'start') {
|
|
141
|
+
if (externalHandles.has(key))
|
|
142
|
+
return true;
|
|
143
|
+
const handle = appendNativeToolCall(sessionId, {
|
|
144
|
+
callId: externalTool.callId,
|
|
145
|
+
name: externalTool.name,
|
|
146
|
+
arguments: externalTool.arguments,
|
|
147
|
+
});
|
|
148
|
+
if (handle === null)
|
|
149
|
+
return false;
|
|
150
|
+
externalHandles.set(key, handle);
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
const handle = externalHandles.get(key);
|
|
154
|
+
if (handle === undefined)
|
|
155
|
+
return false;
|
|
156
|
+
if (externalTool.status === 'running')
|
|
157
|
+
return true;
|
|
158
|
+
const result = appendNativeToolResult(handle, {
|
|
159
|
+
output: externalTool.output ?? externalTool.error ?? '',
|
|
160
|
+
isError: externalTool.status === 'failed',
|
|
161
|
+
...(externalTool.error ? { error: externalTool.error } : {}),
|
|
162
|
+
});
|
|
163
|
+
if (result)
|
|
164
|
+
externalHandles.delete(key);
|
|
165
|
+
return result;
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
async requestApproval(sessionId, request) {
|
|
172
|
+
const agent = nativeAgent(ctx, sessionId);
|
|
173
|
+
const approval = nativeApproval(ctx);
|
|
174
|
+
if (agent === null || approval === null)
|
|
175
|
+
return 'unavailable';
|
|
176
|
+
try {
|
|
177
|
+
const outcome = await approval.request({
|
|
178
|
+
agent,
|
|
179
|
+
toolName: request.toolName,
|
|
180
|
+
...(request.callId ? { callId: request.callId } : {}),
|
|
181
|
+
...(request.reason ? { reason: request.reason } : {}),
|
|
182
|
+
...(request.signal === undefined ? {} : { signal: request.signal }),
|
|
183
|
+
});
|
|
184
|
+
return isApprovalOutcome(outcome) ? outcome : 'unavailable';
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
return request.signal?.aborted ? 'cancelled' : 'unavailable';
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
async askQuestions(sessionId, request) {
|
|
191
|
+
const agent = nativeAgent(ctx, sessionId);
|
|
192
|
+
const userQuestions = nativeUserQuestions(ctx);
|
|
193
|
+
if (agent === null || userQuestions === null)
|
|
194
|
+
return null;
|
|
195
|
+
try {
|
|
196
|
+
const answer = await userQuestions.ask({
|
|
197
|
+
agent,
|
|
198
|
+
questions: request.questions,
|
|
199
|
+
...(request.signal === undefined ? {} : { signal: request.signal }),
|
|
200
|
+
});
|
|
201
|
+
if (!isQuestionAnswer(answer))
|
|
202
|
+
return null;
|
|
203
|
+
return { requestId: request.requestId, answers: answer.answers };
|
|
204
|
+
}
|
|
205
|
+
catch {
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
async archive(sessionId) {
|
|
210
|
+
const current = currentWorkspaceController();
|
|
211
|
+
if (sessionId.trim() === '' || current?.archiveSession === undefined)
|
|
212
|
+
return false;
|
|
213
|
+
await current.archiveSession({ sessionId });
|
|
214
|
+
return true;
|
|
215
|
+
},
|
|
216
|
+
async unarchive(sessionId) {
|
|
217
|
+
const current = currentWorkspaceController();
|
|
218
|
+
if (sessionId.trim() === '' || current?.unarchiveSession === undefined)
|
|
219
|
+
return false;
|
|
220
|
+
await current.unarchiveSession({ sessionId });
|
|
221
|
+
return true;
|
|
222
|
+
},
|
|
223
|
+
subscribe(handlers) {
|
|
224
|
+
const disposers = [];
|
|
225
|
+
if (on !== undefined && handlers.onEvent !== undefined) {
|
|
226
|
+
disposers.push(on('session/event', (session, event) => handlers.onEvent?.(session, event)));
|
|
227
|
+
}
|
|
228
|
+
if (on !== undefined && handlers.onFlush !== undefined) {
|
|
229
|
+
disposers.push(on('session/flush', (session) => handlers.onFlush?.(session)));
|
|
230
|
+
}
|
|
231
|
+
return () => { for (const dispose of disposers)
|
|
232
|
+
dispose(); };
|
|
233
|
+
},
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
function appendableSession(value) {
|
|
237
|
+
if (!isRecord(value))
|
|
238
|
+
return null;
|
|
239
|
+
if (typeof value.snapshotEvents !== 'function' || typeof value.append !== 'function')
|
|
240
|
+
return null;
|
|
241
|
+
return value;
|
|
242
|
+
}
|
|
243
|
+
function activeStep(session) {
|
|
244
|
+
let events;
|
|
245
|
+
try {
|
|
246
|
+
events = session.snapshotEvents();
|
|
247
|
+
}
|
|
248
|
+
catch {
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
const closed = new Set();
|
|
252
|
+
for (let index = events.length - 1; index >= 0; index -= 1) {
|
|
253
|
+
const candidate = events[index];
|
|
254
|
+
const event = isRecord(candidate) ? candidate : null;
|
|
255
|
+
const data = isRecord(event?.data) ? event.data : null;
|
|
256
|
+
const turn = finiteInteger(data?.turn);
|
|
257
|
+
const step = finiteInteger(data?.step);
|
|
258
|
+
if (turn === null || step === null)
|
|
259
|
+
continue;
|
|
260
|
+
const key = `${turn}:${step}`;
|
|
261
|
+
if (event?.type === 'step/end')
|
|
262
|
+
closed.add(key);
|
|
263
|
+
if (event?.type === 'step/start' && !closed.has(key))
|
|
264
|
+
return { turn, step };
|
|
265
|
+
}
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
function eventSeq(value) {
|
|
269
|
+
return isRecord(value) ? finiteInteger(value.seq) : null;
|
|
270
|
+
}
|
|
271
|
+
function finiteInteger(value) {
|
|
272
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0 ? value : null;
|
|
273
|
+
}
|
|
274
|
+
function isSessionStore(value) {
|
|
275
|
+
return isRecord(value) && typeof value.get === 'function' && typeof value.list === 'function';
|
|
276
|
+
}
|
|
277
|
+
function isSessionController(value) {
|
|
278
|
+
return isRecord(value) && (typeof value.create === 'function' || typeof value.list === 'function');
|
|
279
|
+
}
|
|
280
|
+
function isWorkspaceController(value) {
|
|
281
|
+
return isRecord(value) && (typeof value.archiveSession === 'function' || typeof value.unarchiveSession === 'function');
|
|
282
|
+
}
|
|
283
|
+
function isRecord(value) {
|
|
284
|
+
return typeof value === 'object' && value !== null;
|
|
285
|
+
}
|
|
286
|
+
function nativeAgent(ctx, sessionId) {
|
|
287
|
+
const value = ctx.get('agents');
|
|
288
|
+
if (!isRecord(value) || typeof value.get !== 'function')
|
|
289
|
+
return null;
|
|
290
|
+
try {
|
|
291
|
+
return value.get(sessionId) ?? null;
|
|
292
|
+
}
|
|
293
|
+
catch {
|
|
294
|
+
return null;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
function nativeApproval(ctx) {
|
|
298
|
+
const value = ctx.get('approval');
|
|
299
|
+
return isRecord(value) && typeof value.request === 'function' ? value : null;
|
|
300
|
+
}
|
|
301
|
+
function nativeUserQuestions(ctx) {
|
|
302
|
+
const value = ctx.get('userQuestions');
|
|
303
|
+
return isRecord(value) && typeof value.ask === 'function' ? value : null;
|
|
304
|
+
}
|
|
305
|
+
function isApprovalOutcome(value) {
|
|
306
|
+
return value === 'allowed-once' || value === 'rejected' || value === 'cancelled' || value === 'unavailable';
|
|
307
|
+
}
|
|
308
|
+
function isQuestionAnswer(value) {
|
|
309
|
+
if (!isRecord(value) || !Array.isArray(value.answers))
|
|
310
|
+
return false;
|
|
311
|
+
return value.answers.every((answer) => isRecord(answer)
|
|
312
|
+
&& typeof answer.id === 'string'
|
|
313
|
+
&& Array.isArray(answer.selected)
|
|
314
|
+
&& answer.selected.every((item) => typeof item === 'string')
|
|
315
|
+
&& (answer.custom === undefined || typeof answer.custom === 'string'));
|
|
316
|
+
}
|
|
317
|
+
//# sourceMappingURL=native-session-bridge.js.map
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { RTCCertificate } from 'werift';
|
|
2
|
+
import type { FeatureResourceScope } from '../shared/contracts/feature.js';
|
|
3
|
+
import type { FeatureModule } from '../shared/contracts/feature.js';
|
|
4
|
+
import type { FeatureRegistry } from '../features/registry.js';
|
|
5
|
+
import type { RelayIceServer, RelaySignalingTicketResponse } from '../shared/contracts/signaling.js';
|
|
6
|
+
import type { CodingNsControlApiClient } from './control-api-client.js';
|
|
7
|
+
import { type HostPeerConnectionLike, type WebRtcHostAcceptor, type WebRtcHostSession } from '../transport/webrtc-host.js';
|
|
8
|
+
import { DshGateway, type DshGatewayFeature } from '../transport/dsh-gateway.js';
|
|
9
|
+
import { type DshTransportDebugLogger } from '../transport/debug.js';
|
|
10
|
+
/** Relay Tunnel 规定的 DataChannel label,不允许使用插件自定义值。 */
|
|
11
|
+
export declare const CODINGNS_TUNNEL_DATA_CHANNEL_LABEL = "codingns-tunnel";
|
|
12
|
+
export interface HostDtlsIdentityMaterial {
|
|
13
|
+
privateKeyPem: string;
|
|
14
|
+
certPem: string;
|
|
15
|
+
signatureHash: {
|
|
16
|
+
signature: number;
|
|
17
|
+
hash: number;
|
|
18
|
+
};
|
|
19
|
+
fingerprint: string;
|
|
20
|
+
createdAt: string;
|
|
21
|
+
updatedAt: string;
|
|
22
|
+
}
|
|
23
|
+
export interface HostDtlsIdentityStore {
|
|
24
|
+
read(): Promise<HostDtlsIdentityMaterial | null>;
|
|
25
|
+
write(identity: HostDtlsIdentityMaterial): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
/** 文件存储适用于 Host 桌面进程;先写临时文件再 rename,避免半截证书。 */
|
|
28
|
+
export declare class FileHostDtlsIdentityStore implements HostDtlsIdentityStore {
|
|
29
|
+
private readonly filePath;
|
|
30
|
+
constructor(filePath: string);
|
|
31
|
+
read(): Promise<HostDtlsIdentityMaterial | null>;
|
|
32
|
+
write(identity: HostDtlsIdentityMaterial): Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
/** 生成一张新的 werift DTLS 证书,并返回控制面约定的 sha-256 指纹。 */
|
|
35
|
+
export declare function generateHostDtlsIdentity(): Promise<HostDtlsIdentityMaterial>;
|
|
36
|
+
/** 读取已有身份,否则生成并持久化;指纹因此跨进程重启保持不变。 */
|
|
37
|
+
export declare function ensureHostDtlsIdentity(store: HostDtlsIdentityStore): Promise<HostDtlsIdentityMaterial>;
|
|
38
|
+
export declare function formatHostDtlsFingerprint(certificate: Pick<RTCCertificate, 'getFingerprints'>): string;
|
|
39
|
+
export interface HostRelaySession extends WebRtcHostSession {
|
|
40
|
+
readonly tunnelDomain: string;
|
|
41
|
+
readonly gateway: DshGateway;
|
|
42
|
+
}
|
|
43
|
+
export interface HostRelayRuntimeOptions {
|
|
44
|
+
readonly controlClient: Pick<CodingNsControlApiClient, 'createSignalingTicket'>;
|
|
45
|
+
/** DSH 独立设备可注入自己的票据申请器,避免复用 Codingns4DSH binding。 */
|
|
46
|
+
readonly createTicket?: (input: {
|
|
47
|
+
accessToken: string;
|
|
48
|
+
identity: HostDtlsIdentityMaterial;
|
|
49
|
+
credentialVersion?: number;
|
|
50
|
+
}) => Promise<RelaySignalingTicketResponse>;
|
|
51
|
+
readonly accessToken: string;
|
|
52
|
+
readonly bindingId?: string;
|
|
53
|
+
readonly credentialVersion?: number;
|
|
54
|
+
readonly dtlsStore: HostDtlsIdentityStore;
|
|
55
|
+
readonly signalingSocketFactory?: (url: string) => Promise<HostSignalingSocket> | HostSignalingSocket;
|
|
56
|
+
readonly peerConnectionFactory?: (options: {
|
|
57
|
+
iceServers: RelayIceServer[];
|
|
58
|
+
iceTransportPolicy: 'all' | 'relay';
|
|
59
|
+
}) => HostPeerConnectionLike;
|
|
60
|
+
readonly resources?: Pick<FeatureResourceScope, 'add'>;
|
|
61
|
+
readonly onSession?: (session: HostRelaySession) => void | Promise<void>;
|
|
62
|
+
readonly gatewayFeatures?: readonly DshGatewayFeature[];
|
|
63
|
+
/** 传给 DSH Gateway 的运行时版本;缺省时仅保留独立模块测试兼容性。 */
|
|
64
|
+
readonly dshVersion?: string;
|
|
65
|
+
readonly gatewayRegistry?: FeatureRegistry<unknown, FeatureModule<unknown>>;
|
|
66
|
+
readonly debug?: DshTransportDebugLogger;
|
|
67
|
+
readonly generation?: string;
|
|
68
|
+
readonly hostId?: string;
|
|
69
|
+
readonly ticketRenewSkewMs?: number;
|
|
70
|
+
}
|
|
71
|
+
export interface HostRelayRuntime {
|
|
72
|
+
readonly identity: HostDtlsIdentityMaterial;
|
|
73
|
+
readonly ticket: RelaySignalingTicketResponse;
|
|
74
|
+
readonly acceptor: WebRtcHostAcceptor;
|
|
75
|
+
readonly sessions: ReadonlyMap<string, WebRtcHostSession>;
|
|
76
|
+
close(): Promise<void>;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* 启动一个可接收多个 Client 的 Host Relay runtime。
|
|
80
|
+
* `resources` 若提供,所有 WebSocket、PeerConnection、心跳和换票计时器都会登记。
|
|
81
|
+
*/
|
|
82
|
+
export declare function startHostRelayRuntime(options: HostRelayRuntimeOptions): Promise<HostRelayRuntime>;
|
|
83
|
+
/** 为 Host answerer 创建 werift PeerConnection,并适配到 transport 的注入接口。 */
|
|
84
|
+
export declare function createWeriftPeerConnectionFactory(identity?: HostDtlsIdentityMaterial): NonNullable<HostRelayRuntimeOptions['peerConnectionFactory']>;
|
|
85
|
+
export interface HostSignalingSocket {
|
|
86
|
+
readonly readyState: number;
|
|
87
|
+
send(data: string): void;
|
|
88
|
+
close(code?: number, reason?: string): void;
|
|
89
|
+
addEventListener(type: 'message' | 'close' | 'error', listener: (event: Event) => void): void;
|
|
90
|
+
removeEventListener(type: 'message' | 'close' | 'error', listener: (event: Event) => void): void;
|
|
91
|
+
}
|
|
92
|
+
/** 建立 Host 信令并等待服务端 registered;registered 后每 20 秒发 ping。 */
|
|
93
|
+
export declare function createRegisteredHostSignalingSocket(url: string, options?: {
|
|
94
|
+
registrationTimeoutMs?: number;
|
|
95
|
+
heartbeatIntervalMs?: number;
|
|
96
|
+
}): Promise<HostSignalingSocket>;
|
|
97
|
+
//# sourceMappingURL=relay-tunnel-runtime.d.ts.map
|