@orion-agents/orion-code 0.3.65 → 0.4.3
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/CHANGELOG.md +128 -2
- package/README.md +78 -361
- package/README.zh-CN.md +71 -263
- package/bin/orion +4 -1
- package/dist/acp/session-updates.d.ts +34 -0
- package/dist/acp/session-updates.js +162 -0
- package/dist/acp/sessions.d.ts +32 -0
- package/dist/acp/sessions.js +315 -0
- package/dist/acp/stdio.d.ts +3 -0
- package/dist/acp/stdio.js +59 -0
- package/dist/cli.js +136 -185
- package/dist/commands/context-tool-command-handlers.d.ts +1 -1
- package/dist/commands/context-tool-command-handlers.js +24 -3
- package/dist/commands/core-command-handlers.js +5 -1
- package/dist/commands/diagnostic-command-handlers.js +20 -6
- package/dist/commands/diagnostic-commands.js +0 -12
- package/dist/commands/init-command.d.ts +3 -0
- package/dist/commands/init-command.js +131 -0
- package/dist/commands/model-command-handlers.d.ts +1 -2
- package/dist/commands/model-command-handlers.js +15 -100
- package/dist/commands/model-commands.js +0 -11
- package/dist/commands/registry.js +0 -18
- package/dist/commands/rsi-command.d.ts +2 -0
- package/dist/commands/rsi-command.js +180 -0
- package/dist/commands/session-command-handlers.js +28 -19
- package/dist/commands/system-commands.js +0 -1
- package/dist/commands/tool-commands.js +1 -1
- package/dist/commands/types.d.ts +4 -10
- package/dist/commands/types.js +1 -21
- package/dist/commands/workflow-command-handlers.js +13 -4
- package/dist/framework/loop-budget-contract.d.ts +7 -2
- package/dist/framework/loop-budget-contract.js +4 -1
- package/dist/framework/loop-progress.d.ts +22 -0
- package/dist/framework/loop-progress.js +79 -0
- package/dist/framework/prompt.d.ts +0 -2
- package/dist/framework/prompt.js +9 -27
- package/dist/framework/query.d.ts +27 -20
- package/dist/framework/query.js +453 -153
- package/dist/framework/store.d.ts +6 -10
- package/dist/framework/store.js +2 -21
- package/dist/framework/tool-call-orchestrator.d.ts +7 -0
- package/dist/framework/tool-call-orchestrator.js +8 -3
- package/dist/framework/tool-state.d.ts +2 -0
- package/dist/framework/tool.d.ts +0 -23
- package/dist/framework/verification-command.d.ts +15 -0
- package/dist/framework/verification-command.js +32 -0
- package/dist/harness/assembler.d.ts +1 -0
- package/dist/harness/assembler.js +24 -0
- package/dist/harness/capsule.d.ts +1 -1
- package/dist/harness/capsule.js +33 -14
- package/dist/harness/context-harness.d.ts +31 -12
- package/dist/harness/context-harness.js +491 -35
- package/dist/harness/contract.js +1 -1
- package/dist/harness/drift-guard.d.ts +4 -0
- package/dist/harness/drift-guard.js +68 -16
- package/dist/harness/intent.js +21 -0
- package/dist/harness/ledger.d.ts +6 -11
- package/dist/harness/ledger.js +39 -9
- package/dist/harness/progress-controller.d.ts +12 -7
- package/dist/harness/progress-controller.js +66 -21
- package/dist/harness/state.js +9 -1
- package/dist/harness/task-checklist.d.ts +16 -0
- package/dist/harness/task-checklist.js +95 -0
- package/dist/harness/types.d.ts +73 -1
- package/dist/harness/verification.d.ts +19 -1
- package/dist/harness/verification.js +116 -29
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -3
- package/dist/print-ui/event-stream.d.ts +38 -0
- package/dist/print-ui/event-stream.js +187 -0
- package/dist/print-ui/launch.d.ts +12 -1
- package/dist/print-ui/launch.js +173 -11
- package/dist/product/environment.d.ts +1 -1
- package/dist/product/environment.js +1 -1
- package/dist/product/identity.d.ts +1 -1
- package/dist/product/identity.js +1 -1
- package/dist/product/paths.d.ts +3 -2
- package/dist/product/paths.js +6 -2
- package/dist/runtime/agent-loop.d.ts +11 -2
- package/dist/runtime/agent-loop.js +165 -25
- package/dist/runtime/agent-runtime-controller.d.ts +13 -3
- package/dist/runtime/agent-runtime-controller.js +347 -183
- package/dist/runtime/agent-runtime-protocol.d.ts +10 -18
- package/dist/runtime/agent-runtime-runner.d.ts +10 -0
- package/dist/runtime/builtin-tool-provider.js +5 -1
- package/dist/runtime/capability-receipt-journal.js +1 -0
- package/dist/runtime/durable-tool-receipt-reader.js +2 -1
- package/dist/runtime/first-party-tool-services.d.ts +1 -0
- package/dist/runtime/first-party-tool-services.js +2 -12
- package/dist/runtime/first-party-tool-universe.d.ts +1 -0
- package/dist/runtime/first-party-tool-universe.js +1 -1
- package/dist/runtime/followup-queue-store.d.ts +16 -0
- package/dist/runtime/followup-queue-store.js +75 -0
- package/dist/runtime/goal-lifecycle-v2.d.ts +11 -1
- package/dist/runtime/goal-lifecycle-v2.js +85 -15
- package/dist/runtime/goal-runtime-coordinator.d.ts +10 -1
- package/dist/runtime/goal-runtime-coordinator.js +81 -24
- package/dist/runtime/loop-budget.js +7 -5
- package/dist/runtime/mcp/first-party-mcp-adapter.d.ts +2 -0
- package/dist/runtime/mcp/first-party-mcp-adapter.js +23 -19
- package/dist/runtime/model-coordinator.js +2 -5
- package/dist/runtime/orion-runtime-v1.d.ts +18 -2
- package/dist/runtime/orion-runtime-v1.js +135 -39
- package/dist/runtime/orion-session-runner.d.ts +7 -0
- package/dist/runtime/orion-session-runner.js +82 -0
- package/dist/runtime/plan-review.d.ts +1 -0
- package/dist/runtime/plan-review.js +8 -4
- package/dist/runtime/product-bootstrap.d.ts +6 -0
- package/dist/runtime/product-bootstrap.js +41 -51
- package/dist/runtime/product-orion-runtime.js +128 -52
- package/dist/runtime/release-receipts.d.ts +24 -124
- package/dist/runtime/release-receipts.js +129 -683
- package/dist/runtime/rich-text/layout.js +108 -65
- package/dist/runtime/rsi/contracts.d.ts +50 -0
- package/dist/runtime/rsi/contracts.js +17 -0
- package/dist/runtime/rsi/diagnosis.d.ts +46 -0
- package/dist/runtime/rsi/diagnosis.js +98 -0
- package/dist/runtime/rsi/evaluation-suite.d.ts +25 -0
- package/dist/runtime/rsi/evaluation-suite.js +141 -0
- package/dist/runtime/rsi/evaluation-worker.d.ts +19 -0
- package/dist/runtime/rsi/evaluation-worker.js +64 -0
- package/dist/runtime/rsi/evaluation.d.ts +49 -0
- package/dist/runtime/rsi/evaluation.js +351 -0
- package/dist/runtime/rsi/lifecycle.d.ts +54 -0
- package/dist/runtime/rsi/lifecycle.js +279 -0
- package/dist/runtime/rsi/proposal.d.ts +39 -0
- package/dist/runtime/rsi/proposal.js +312 -0
- package/dist/runtime/rsi/receipt.d.ts +28 -0
- package/dist/runtime/rsi/receipt.js +138 -0
- package/dist/runtime/rsi/skill-state.d.ts +7 -0
- package/dist/runtime/rsi/skill-state.js +50 -0
- package/dist/runtime/rsi/trajectory.d.ts +19 -0
- package/dist/runtime/rsi/trajectory.js +314 -0
- package/dist/runtime/rsi/triage.d.ts +274 -0
- package/dist/runtime/rsi/triage.js +58 -0
- package/dist/runtime/session-composer-control.d.ts +5 -24
- package/dist/runtime/session-composer-control.js +27 -189
- package/dist/runtime/step-snapshot.d.ts +1 -0
- package/dist/runtime/subagents/policy.js +0 -1
- package/dist/runtime/subagents/production.js +1 -1
- package/dist/runtime/subagents/runtime-integration.js +2 -4
- package/dist/runtime/subagents/types.d.ts +0 -5
- package/dist/runtime/subagents/types.js +0 -2
- package/dist/runtime/task-context-recovery.d.ts +55 -0
- package/dist/runtime/task-context-recovery.js +342 -0
- package/dist/runtime/task-context-service.d.ts +16 -10
- package/dist/runtime/task-context-service.js +35 -4
- package/dist/runtime/thread-admission.d.ts +1 -1
- package/dist/runtime/thread-admission.js +12 -6
- package/dist/runtime/thread-event-store.d.ts +2 -2
- package/dist/runtime/thread-event-store.js +7 -2
- package/dist/runtime/thread-projection.js +4 -2
- package/dist/runtime/thread-runtime.d.ts +7 -0
- package/dist/runtime/thread-runtime.js +43 -0
- package/dist/runtime/thread-session-index.d.ts +8 -0
- package/dist/runtime/thread-session-index.js +50 -1
- package/dist/runtime/thread-session-view.d.ts +2 -1
- package/dist/runtime/thread-session-view.js +4 -0
- package/dist/runtime/thread-tool-journal.d.ts +1 -0
- package/dist/runtime/thread-tool-journal.js +6 -2
- package/dist/runtime/thread-ui-adapter.d.ts +1 -0
- package/dist/runtime/thread-ui-adapter.js +88 -11
- package/dist/runtime/tool-gateway.d.ts +7 -0
- package/dist/runtime/tool-gateway.js +20 -0
- package/dist/runtime/tool-transcript-entry.d.ts +16 -0
- package/dist/runtime/tool-transcript-entry.js +73 -0
- package/dist/runtime/turn-commit.d.ts +4 -1
- package/dist/runtime/turn-commit.js +19 -15
- package/dist/runtime/ui-events.d.ts +12 -0
- package/dist/runtime/ui-view-model.d.ts +6 -5
- package/dist/runtime/ui-view-model.js +33 -19
- package/dist/runtime/workspace-runtime-kernel.js +0 -1
- package/dist/services/atomic-write.d.ts +2 -0
- package/dist/services/atomic-write.js +12 -1
- package/dist/services/code-review/format.d.ts +4 -1
- package/dist/services/code-review/format.js +5 -1
- package/dist/services/code-review/runner.d.ts +2 -2
- package/dist/services/code-review/runner.js +86 -64
- package/dist/services/code-review/snapshot.d.ts +9 -9
- package/dist/services/code-review/snapshot.js +182 -166
- package/dist/services/compact/auto-compact.d.ts +21 -6
- package/dist/services/compact/auto-compact.js +148 -22
- package/dist/services/compact/background-candidate.d.ts +33 -0
- package/dist/services/compact/background-candidate.js +184 -0
- package/dist/services/compact/compact.d.ts +4 -1
- package/dist/services/compact/compact.js +30 -3
- package/dist/services/compact/coordinator.d.ts +10 -4
- package/dist/services/compact/coordinator.js +17 -7
- package/dist/services/compact/summary-generator.d.ts +4 -2
- package/dist/services/compact/summary-generator.js +17 -3
- package/dist/services/config.d.ts +5 -5
- package/dist/services/config.js +30 -45
- package/dist/services/doctor.js +85 -13
- package/dist/services/effort.d.ts +5 -5
- package/dist/services/effort.js +5 -11
- package/dist/services/file-lock.d.ts +9 -3
- package/dist/services/file-lock.js +92 -26
- package/dist/services/global-config.d.ts +26 -56
- package/dist/services/global-config.js +213 -183
- package/dist/services/llm.d.ts +40 -4
- package/dist/services/llm.js +164 -45
- package/dist/services/model-client-pool.d.ts +15 -9
- package/dist/services/model-client-pool.js +62 -33
- package/dist/services/model-context.d.ts +2 -1
- package/dist/services/model-context.js +15 -9
- package/dist/services/model-registry.d.ts +4 -15
- package/dist/services/model-registry.js +32 -101
- package/dist/services/provider-diagnostics.d.ts +7 -0
- package/dist/services/provider-diagnostics.js +9 -10
- package/dist/services/provider-resilience/coordinator.d.ts +1 -1
- package/dist/services/provider-resilience/coordinator.js +10 -6
- package/dist/services/provider-resilience/request-gate.d.ts +3 -0
- package/dist/services/provider-resilience/request-gate.js +29 -18
- package/dist/services/provider-resilience/types.d.ts +2 -0
- package/dist/services/session-storage.d.ts +7 -10
- package/dist/services/session-storage.js +57 -30
- package/dist/services/settings-coordinator.d.ts +0 -6
- package/dist/services/settings-coordinator.js +19 -56
- package/dist/services/settings-document-repository.d.ts +3 -10
- package/dist/services/settings-document-repository.js +7 -85
- package/dist/services/usage-state.d.ts +3 -3
- package/dist/services/usage-state.js +11 -42
- package/dist/terminal-ui/answer-format.d.ts +14 -0
- package/dist/terminal-ui/answer-format.js +119 -0
- package/dist/terminal-ui/launch.d.ts +7 -6
- package/dist/terminal-ui/launch.js +160 -70
- package/dist/terminal-ui/output-queue.d.ts +2 -1
- package/dist/terminal-ui/output-queue.js +1 -1
- package/dist/terminal-ui/raw-editor.d.ts +2 -1
- package/dist/terminal-ui/raw-editor.js +56 -15
- package/dist/tools/core/edit-file.js +2 -0
- package/dist/tools/core/write-file.js +5 -0
- package/dist/tools/lsp.d.ts +16 -1
- package/dist/tools/lsp.js +60 -19
- package/dist/tools/sandbox.d.ts +1 -1
- package/dist/tools/sandbox.js +3 -16
- package/dist/tools/todo.d.ts +4 -2
- package/dist/tools/todo.js +76 -31
- package/dist/tui-core/input-parser.d.ts +1 -0
- package/dist/tui-core/input-parser.js +6 -0
- package/dist/tui-core/style.d.ts +1 -8
- package/dist/tui-core/style.js +3 -110
- package/dist/tui-ui/chrome-view-model.d.ts +1 -1
- package/dist/tui-ui/chrome-view-model.js +22 -27
- package/dist/tui-ui/launch.js +14 -14
- package/dist/tui-ui/layout.d.ts +5 -7
- package/dist/tui-ui/layout.js +129 -124
- package/dist/tui-ui/runner.d.ts +11 -12
- package/dist/tui-ui/runner.js +88 -67
- package/dist/tui-ui/state.d.ts +0 -11
- package/dist/tui-ui/state.js +22 -33
- package/dist/tui-ui/terminal-image.js +22 -4
- package/dist/tui-ui/transcript-inspector-layout.js +6 -3
- package/dist/tui-ui/transcript-inspector.d.ts +1 -0
- package/dist/tui-ui/transcript-inspector.js +7 -1
- package/dist/tui-ui/transcript-layout.js +42 -6
- package/dist/utils/terminal-text.d.ts +11 -0
- package/dist/utils/terminal-text.js +114 -0
- package/docs/cli-guide.md +562 -0
- package/docs/orion.example.yaml +42 -0
- package/docs/readme.md +12 -57
- package/npm-shrinkwrap.json +484 -1855
- package/package.json +13 -63
- package/dist/migration/command.d.ts +0 -9
- package/dist/migration/command.js +0 -100
- package/dist/migration/index.d.ts +0 -7
- package/dist/migration/index.js +0 -14
- package/dist/migration/migrate.d.ts +0 -19
- package/dist/migration/migrate.js +0 -406
- package/dist/migration/types.d.ts +0 -55
- package/dist/migration/types.js +0 -6
- package/dist/services/tool-allowlist.d.ts +0 -110
- package/dist/services/tool-allowlist.js +0 -299
- package/dist/services/yaml-config.d.ts +0 -57
- package/dist/services/yaml-config.js +0 -178
- package/dist/web/cli-options.d.ts +0 -17
- package/dist/web/cli-options.js +0 -51
- package/dist/web/code-review-run-service.d.ts +0 -68
- package/dist/web/code-review-run-service.js +0 -228
- package/dist/web/context-text.d.ts +0 -17
- package/dist/web/context-text.js +0 -40
- package/dist/web/errors.d.ts +0 -6
- package/dist/web/errors.js +0 -13
- package/dist/web/event-hub.d.ts +0 -45
- package/dist/web/event-hub.js +0 -370
- package/dist/web/file-read-service.d.ts +0 -101
- package/dist/web/file-read-service.js +0 -593
- package/dist/web/file-write-service.d.ts +0 -16
- package/dist/web/file-write-service.js +0 -103
- package/dist/web/git-compare-service.d.ts +0 -45
- package/dist/web/git-compare-service.js +0 -160
- package/dist/web/git-diff-document.d.ts +0 -102
- package/dist/web/git-diff-document.js +0 -258
- package/dist/web/git-file-source.d.ts +0 -25
- package/dist/web/git-file-source.js +0 -21
- package/dist/web/git-history-service.d.ts +0 -151
- package/dist/web/git-history-service.js +0 -619
- package/dist/web/git-index-transaction.d.ts +0 -45
- package/dist/web/git-index-transaction.js +0 -174
- package/dist/web/git-patch-builder.d.ts +0 -30
- package/dist/web/git-patch-builder.js +0 -138
- package/dist/web/git-read-model-service.d.ts +0 -452
- package/dist/web/git-read-model-service.js +0 -1833
- package/dist/web/git-version-service.d.ts +0 -79
- package/dist/web/git-version-service.js +0 -279
- package/dist/web/host-daemon.d.ts +0 -70
- package/dist/web/host-daemon.js +0 -237
- package/dist/web/index.d.ts +0 -6
- package/dist/web/index.js +0 -28
- package/dist/web/launch.d.ts +0 -12
- package/dist/web/launch.js +0 -89
- package/dist/web/native-directory-picker.d.ts +0 -63
- package/dist/web/native-directory-picker.js +0 -169
- package/dist/web/protocol.d.ts +0 -705
- package/dist/web/protocol.js +0 -639
- package/dist/web/review-service.d.ts +0 -22
- package/dist/web/review-service.js +0 -68
- package/dist/web/server.d.ts +0 -20
- package/dist/web/server.js +0 -1453
- package/dist/web/session-runtime-registry.d.ts +0 -138
- package/dist/web/session-runtime-registry.js +0 -471
- package/dist/web/terminal-manager.d.ts +0 -156
- package/dist/web/terminal-manager.js +0 -779
- package/dist/web/terminal-server.d.ts +0 -8
- package/dist/web/terminal-server.js +0 -304
- package/dist/web/workbench-controller.d.ts +0 -395
- package/dist/web/workbench-controller.js +0 -3077
- package/dist/web/workspace-discovery.d.ts +0 -92
- package/dist/web/workspace-discovery.js +0 -324
- package/dist/web/workspace-mutation-arbiter.d.ts +0 -54
- package/dist/web/workspace-mutation-arbiter.js +0 -267
- package/dist/web/workspace-open-telemetry.d.ts +0 -55
- package/dist/web/workspace-open-telemetry.js +0 -73
- package/dist/web-client/assets/FilesPanel-iBYj9ZRf.js +0 -1
- package/dist/web-client/assets/GitPanel-D33R_bZr.js +0 -4
- package/dist/web-client/assets/ReviewPanel-C_0upsDk.js +0 -6
- package/dist/web-client/assets/TerminalPanel-C7A8dMNf.js +0 -23
- package/dist/web-client/assets/TerminalPanel-DLuoa74B.css +0 -1
- package/dist/web-client/assets/index-BaOxrwGB.css +0 -1
- package/dist/web-client/assets/index-CqCgJ2ov.js +0 -20
- package/dist/web-client/assets/useAutoNotice-C1qM-_Sg.js +0 -1
- package/dist/web-client/favicon.svg +0 -9
- package/dist/web-client/index.html +0 -17
- package/docs/architecture/agent-mode-permission-contract.md +0 -87
- package/docs/architecture/v0.3.0-web-api.yaml +0 -1340
- package/docs/architecture/v0.3.1-web-api.yaml +0 -2338
- package/docs/architecture/v0.3.2-web-api.yaml +0 -3029
- package/docs/architecture/v0.3.3-web-api.yaml +0 -3205
- package/docs/architecture/v0.3.4-stabilization-contract.md +0 -32
- package/docs/migration/v0.1.9-to-v0.2.0.md +0 -98
- package/docs/migration/v0.2.2-to-v0.3.0-settings.md +0 -114
- package/docs/migration/v0.2.2-to-v0.3.0.md +0 -55
- package/docs/migration/v0.3.0-to-v0.3.1.md +0 -88
- package/docs/migration/v0.3.1-to-v0.3.2.md +0 -94
- package/docs/migration/v0.3.2-to-v0.3.3.md +0 -62
- package/docs/migration/v0.3.3-to-v0.3.4.md +0 -36
- package/docs/orion.example.json +0 -86
- package/docs/plan/v0.2.0-dsh-harness-redesign-plan.md +0 -1234
- package/docs/plan/v0.2.0-release-checklist.md +0 -91
- package/docs/plan/v0.3.0-node-runtime-compatibility-plan.md +0 -57
- package/docs/plan/v0.3.0-settings-integration-plan.md +0 -740
- package/docs/plan/v0.3.0-web-workbench-plan.md +0 -376
- package/docs/plan/v0.3.1-web-workbench-professional-shell-plan.md +0 -848
- package/docs/plan/v0.3.2-web-workbench-layout-and-composer-plan.md +0 -869
- package/docs/plan/v0.3.3-plan.md +0 -1113
- package/docs/plan/v0.3.4-stabilization-plan.md +0 -89
- package/docs/test/v0.3.1-web-workbench-e2e-plan.md +0 -140
- package/docs/test/v0.3.2-web-workbench-e2e-plan.md +0 -100
- package/docs/test/v0.3.3-web-workbench-e2e-plan.md +0 -79
- package/docs/test/v0.3.4-stabilization-e2e-plan.md +0 -54
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Server } from 'http';
|
|
2
|
-
import type { TerminalManagerV1 } from './terminal-manager';
|
|
3
|
-
export interface TerminalWebSocketHandle {
|
|
4
|
-
close(): Promise<void>;
|
|
5
|
-
}
|
|
6
|
-
export declare function attachTerminalWebSocketServer(server: Server, origin: () => string, manager: TerminalManagerV1): TerminalWebSocketHandle;
|
|
7
|
-
export declare const TERMINAL_WEBSOCKET_PROTOCOL = "orion-terminal-v1";
|
|
8
|
-
//# sourceMappingURL=terminal-server.d.ts.map
|
|
@@ -1,304 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TERMINAL_WEBSOCKET_PROTOCOL = void 0;
|
|
4
|
-
exports.attachTerminalWebSocketServer = attachTerminalWebSocketServer;
|
|
5
|
-
const ws_1 = require("ws");
|
|
6
|
-
const errors_1 = require("./errors");
|
|
7
|
-
const TERMINAL_PROTOCOL = 'orion-terminal-v1';
|
|
8
|
-
const MAX_WS_BUFFERED_BYTES = 2 * 1024 * 1024;
|
|
9
|
-
const PAUSE_WS_BUFFERED_BYTES = 512 * 1024;
|
|
10
|
-
const RESUME_WS_BUFFERED_BYTES = 128 * 1024;
|
|
11
|
-
const BACKPRESSURE_POLL_MS = 10;
|
|
12
|
-
const AUTH_TIMEOUT_MS = 5000;
|
|
13
|
-
function attachTerminalWebSocketServer(server, origin, manager) {
|
|
14
|
-
const webSockets = new ws_1.WebSocketServer({
|
|
15
|
-
noServer: true,
|
|
16
|
-
perMessageDeflate: false,
|
|
17
|
-
maxPayload: 72 * 1024,
|
|
18
|
-
clientTracking: true,
|
|
19
|
-
});
|
|
20
|
-
const onUpgrade = (request, socket, head) => {
|
|
21
|
-
const expectedOrigin = origin();
|
|
22
|
-
if (!expectedOrigin || request.headers.origin !== expectedOrigin) {
|
|
23
|
-
rejectUpgrade(socket, 403, 'Origin rejected');
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
const expectedHost = new URL(expectedOrigin).host;
|
|
27
|
-
if (request.headers.host !== expectedHost) {
|
|
28
|
-
rejectUpgrade(socket, 421, 'Host rejected');
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
const protocols = String(request.headers['sec-websocket-protocol'] ?? '')
|
|
32
|
-
.split(',')
|
|
33
|
-
.map(value => value.trim());
|
|
34
|
-
if (!protocols.includes(TERMINAL_PROTOCOL)) {
|
|
35
|
-
rejectUpgrade(socket, 400, 'Protocol rejected');
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
const requestUrl = new URL(request.url ?? '/', expectedOrigin);
|
|
39
|
-
const match = requestUrl.pathname.match(/^\/api\/v1\/terminals\/([^/]+)\/stream$/u);
|
|
40
|
-
if (!match || requestUrl.search) {
|
|
41
|
-
rejectUpgrade(socket, 404, 'Stream not found');
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
let terminalId;
|
|
45
|
-
try {
|
|
46
|
-
terminalId = decodeURIComponent(match[1]);
|
|
47
|
-
}
|
|
48
|
-
catch {
|
|
49
|
-
rejectUpgrade(socket, 400, 'Terminal identity rejected');
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
webSockets.handleUpgrade(request, socket, head, webSocket => {
|
|
53
|
-
ownTerminalSocket(webSocket, terminalId, manager);
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
server.on('upgrade', onUpgrade);
|
|
57
|
-
return Object.freeze({
|
|
58
|
-
close: () => new Promise(resolvePromise => {
|
|
59
|
-
server.off('upgrade', onUpgrade);
|
|
60
|
-
for (const client of webSockets.clients)
|
|
61
|
-
client.close(1001, 'Host closing');
|
|
62
|
-
webSockets.close(() => resolvePromise());
|
|
63
|
-
}),
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
function ownTerminalSocket(webSocket, terminalId, manager) {
|
|
67
|
-
let connection;
|
|
68
|
-
let backpressurePaused = false;
|
|
69
|
-
let replayPaused = false;
|
|
70
|
-
const replayTail = [];
|
|
71
|
-
let replayExit;
|
|
72
|
-
let drainTimer;
|
|
73
|
-
let replayTimer;
|
|
74
|
-
const timer = setTimeout(() => webSocket.close(4401, 'Authentication timeout'), AUTH_TIMEOUT_MS);
|
|
75
|
-
timer.unref();
|
|
76
|
-
const applyFlowControl = () => {
|
|
77
|
-
if (!connection)
|
|
78
|
-
return;
|
|
79
|
-
try {
|
|
80
|
-
connection.setOutputPaused(backpressurePaused || replayPaused);
|
|
81
|
-
}
|
|
82
|
-
catch {
|
|
83
|
-
webSocket.close(1011, 'Terminal flow control failed');
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
const scheduleDrainCheck = () => {
|
|
87
|
-
if (drainTimer || webSocket.readyState !== ws_1.WebSocket.OPEN)
|
|
88
|
-
return;
|
|
89
|
-
drainTimer = setTimeout(() => {
|
|
90
|
-
drainTimer = undefined;
|
|
91
|
-
checkBackpressure();
|
|
92
|
-
}, BACKPRESSURE_POLL_MS);
|
|
93
|
-
drainTimer.unref();
|
|
94
|
-
};
|
|
95
|
-
const checkBackpressure = () => {
|
|
96
|
-
if (webSocket.readyState !== ws_1.WebSocket.OPEN)
|
|
97
|
-
return;
|
|
98
|
-
if (webSocket.bufferedAmount > MAX_WS_BUFFERED_BYTES) {
|
|
99
|
-
backpressurePaused = true;
|
|
100
|
-
applyFlowControl();
|
|
101
|
-
webSocket.close(4413, 'Terminal stream backpressure');
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
if (webSocket.bufferedAmount >= PAUSE_WS_BUFFERED_BYTES) {
|
|
105
|
-
if (!backpressurePaused) {
|
|
106
|
-
backpressurePaused = true;
|
|
107
|
-
applyFlowControl();
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
else if (backpressurePaused && webSocket.bufferedAmount <= RESUME_WS_BUFFERED_BYTES) {
|
|
111
|
-
backpressurePaused = false;
|
|
112
|
-
applyFlowControl();
|
|
113
|
-
}
|
|
114
|
-
if (backpressurePaused)
|
|
115
|
-
scheduleDrainCheck();
|
|
116
|
-
};
|
|
117
|
-
const send = (value, onSent) => {
|
|
118
|
-
if (webSocket.readyState !== ws_1.WebSocket.OPEN)
|
|
119
|
-
return false;
|
|
120
|
-
const payload = JSON.stringify(value);
|
|
121
|
-
if (Buffer.byteLength(payload, 'utf8') > MAX_WS_BUFFERED_BYTES ||
|
|
122
|
-
webSocket.bufferedAmount > MAX_WS_BUFFERED_BYTES) {
|
|
123
|
-
backpressurePaused = true;
|
|
124
|
-
applyFlowControl();
|
|
125
|
-
webSocket.close(4413, 'Terminal stream backpressure');
|
|
126
|
-
return false;
|
|
127
|
-
}
|
|
128
|
-
webSocket.send(payload, error => {
|
|
129
|
-
if (error) {
|
|
130
|
-
webSocket.close(1011, 'Terminal stream failed');
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
checkBackpressure();
|
|
134
|
-
onSent?.();
|
|
135
|
-
});
|
|
136
|
-
checkBackpressure();
|
|
137
|
-
return true;
|
|
138
|
-
};
|
|
139
|
-
const sendExit = (event) => {
|
|
140
|
-
if (!send(event, () => webSocket.close(1000, 'Terminal exited'))) {
|
|
141
|
-
webSocket.close(1000, 'Terminal exited');
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
const drainReplayTail = () => {
|
|
145
|
-
if (webSocket.readyState !== ws_1.WebSocket.OPEN)
|
|
146
|
-
return;
|
|
147
|
-
const next = replayTail.shift();
|
|
148
|
-
if (next !== undefined) {
|
|
149
|
-
send(next, drainReplayTail);
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
if (replayExit !== undefined) {
|
|
153
|
-
const exit = replayExit;
|
|
154
|
-
replayExit = undefined;
|
|
155
|
-
sendExit(exit);
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
replayPaused = false;
|
|
159
|
-
applyFlowControl();
|
|
160
|
-
};
|
|
161
|
-
const sendReplay = (values, index = 0) => {
|
|
162
|
-
if (webSocket.readyState !== ws_1.WebSocket.OPEN)
|
|
163
|
-
return;
|
|
164
|
-
if (index >= values.length) {
|
|
165
|
-
drainReplayTail();
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
if (webSocket.bufferedAmount >= PAUSE_WS_BUFFERED_BYTES) {
|
|
169
|
-
backpressurePaused = true;
|
|
170
|
-
applyFlowControl();
|
|
171
|
-
scheduleDrainCheck();
|
|
172
|
-
replayTimer = setTimeout(() => sendReplay(values, index), BACKPRESSURE_POLL_MS);
|
|
173
|
-
replayTimer.unref();
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
send(values[index], () => sendReplay(values, index + 1));
|
|
177
|
-
};
|
|
178
|
-
const dispose = () => {
|
|
179
|
-
clearTimeout(timer);
|
|
180
|
-
if (drainTimer)
|
|
181
|
-
clearTimeout(drainTimer);
|
|
182
|
-
if (replayTimer)
|
|
183
|
-
clearTimeout(replayTimer);
|
|
184
|
-
connection?.dispose();
|
|
185
|
-
connection = undefined;
|
|
186
|
-
};
|
|
187
|
-
webSocket.once('close', dispose);
|
|
188
|
-
webSocket.once('error', dispose);
|
|
189
|
-
webSocket.on('message', (data, binary) => {
|
|
190
|
-
if (binary) {
|
|
191
|
-
webSocket.close(4400, 'Binary client messages are not supported');
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
let message;
|
|
195
|
-
try {
|
|
196
|
-
message = JSON.parse(data.toString());
|
|
197
|
-
}
|
|
198
|
-
catch {
|
|
199
|
-
webSocket.close(4400, 'Invalid terminal message');
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
try {
|
|
203
|
-
if (!connection) {
|
|
204
|
-
const auth = parseAuthenticate(message);
|
|
205
|
-
connection = manager.attach({
|
|
206
|
-
terminalId,
|
|
207
|
-
ticket: auth.ticket,
|
|
208
|
-
afterSequence: auth.afterSequence,
|
|
209
|
-
onFrame: frame => {
|
|
210
|
-
if (replayPaused)
|
|
211
|
-
replayTail.push(frame);
|
|
212
|
-
else
|
|
213
|
-
send(frame);
|
|
214
|
-
},
|
|
215
|
-
onExit: event => {
|
|
216
|
-
if (replayPaused)
|
|
217
|
-
replayExit = event;
|
|
218
|
-
else
|
|
219
|
-
sendExit(event);
|
|
220
|
-
},
|
|
221
|
-
onReplaced: () => webSocket.close(4409, 'Terminal connection replaced'),
|
|
222
|
-
});
|
|
223
|
-
clearTimeout(timer);
|
|
224
|
-
replayPaused = true;
|
|
225
|
-
applyFlowControl();
|
|
226
|
-
sendReplay([
|
|
227
|
-
{ type: 'ready', terminal: connection.terminal },
|
|
228
|
-
...(connection.gap ? [connection.gap] : []),
|
|
229
|
-
...connection.replay,
|
|
230
|
-
]);
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
233
|
-
const command = parseTerminalCommand(message);
|
|
234
|
-
if (command.type === 'input')
|
|
235
|
-
connection.write(command.data);
|
|
236
|
-
else if (command.type === 'resize')
|
|
237
|
-
connection.resize(command.cols, command.rows);
|
|
238
|
-
else
|
|
239
|
-
send({ type: 'pong', timestamp: command.timestamp });
|
|
240
|
-
}
|
|
241
|
-
catch (error) {
|
|
242
|
-
const code = error instanceof errors_1.WebWorkbenchError ? error.code : 'terminal_protocol_error';
|
|
243
|
-
send({ type: 'error', code });
|
|
244
|
-
webSocket.close(error instanceof errors_1.WebWorkbenchError ? 4403 : 4400, 'Terminal request rejected');
|
|
245
|
-
}
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
function parseAuthenticate(value) {
|
|
249
|
-
const row = requireRecord(value);
|
|
250
|
-
assertKeys(row, ['type', 'ticket', 'afterSequence']);
|
|
251
|
-
if (row.type !== 'authenticate' ||
|
|
252
|
-
typeof row.ticket !== 'string' ||
|
|
253
|
-
row.ticket.length < 32 ||
|
|
254
|
-
row.ticket.length > 128 ||
|
|
255
|
-
!Number.isSafeInteger(row.afterSequence) ||
|
|
256
|
-
Number(row.afterSequence) < 0) {
|
|
257
|
-
throw new errors_1.WebWorkbenchError(400, 'Terminal authentication is invalid.');
|
|
258
|
-
}
|
|
259
|
-
return { ticket: row.ticket, afterSequence: Number(row.afterSequence) };
|
|
260
|
-
}
|
|
261
|
-
function parseTerminalCommand(value) {
|
|
262
|
-
const row = requireRecord(value);
|
|
263
|
-
if (row.type === 'input') {
|
|
264
|
-
assertKeys(row, ['type', 'data']);
|
|
265
|
-
if (typeof row.data !== 'string')
|
|
266
|
-
throw new Error('invalid input');
|
|
267
|
-
return { type: 'input', data: row.data };
|
|
268
|
-
}
|
|
269
|
-
if (row.type === 'resize') {
|
|
270
|
-
assertKeys(row, ['type', 'cols', 'rows']);
|
|
271
|
-
if (!Number.isSafeInteger(row.cols) || !Number.isSafeInteger(row.rows)) {
|
|
272
|
-
throw new Error('invalid resize');
|
|
273
|
-
}
|
|
274
|
-
return { type: 'resize', cols: Number(row.cols), rows: Number(row.rows) };
|
|
275
|
-
}
|
|
276
|
-
if (row.type === 'ping') {
|
|
277
|
-
assertKeys(row, ['type', 'timestamp']);
|
|
278
|
-
if (typeof row.timestamp !== 'number' || !Number.isFinite(row.timestamp)) {
|
|
279
|
-
throw new Error('invalid ping');
|
|
280
|
-
}
|
|
281
|
-
return { type: 'ping', timestamp: row.timestamp };
|
|
282
|
-
}
|
|
283
|
-
throw new Error('unknown terminal command');
|
|
284
|
-
}
|
|
285
|
-
function requireRecord(value) {
|
|
286
|
-
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
287
|
-
throw new Error('invalid object');
|
|
288
|
-
return value;
|
|
289
|
-
}
|
|
290
|
-
function assertKeys(row, allowed) {
|
|
291
|
-
const keys = new Set(allowed);
|
|
292
|
-
if (Object.keys(row).some(key => !keys.has(key)))
|
|
293
|
-
throw new Error('unknown field');
|
|
294
|
-
}
|
|
295
|
-
function rejectUpgrade(socket, status, message) {
|
|
296
|
-
if (!socket.writable) {
|
|
297
|
-
socket.destroy();
|
|
298
|
-
return;
|
|
299
|
-
}
|
|
300
|
-
const body = `${message}\n`;
|
|
301
|
-
socket.end(`HTTP/1.1 ${status} Rejected\r\nConnection: close\r\nContent-Type: text/plain; charset=utf-8\r\nContent-Length: ${Buffer.byteLength(body)}\r\n\r\n${body}`);
|
|
302
|
-
}
|
|
303
|
-
exports.TERMINAL_WEBSOCKET_PROTOCOL = TERMINAL_PROTOCOL;
|
|
304
|
-
//# sourceMappingURL=terminal-server.js.map
|