aws-runtime-bridge 1.9.172 → 1.9.179
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 +314 -0
- package/README.md +61 -2
- package/dist/adapter/AcodeSdkAdapter.d.ts +374 -1
- package/dist/adapter/AcodeSdkAdapter.js +3 -3
- package/dist/adapter/AdapterRegistry.d.ts +28 -0
- package/dist/adapter/ClaudeSdkAdapter.d.ts +71 -0
- package/dist/adapter/CodexSdkAdapter.d.ts +14 -0
- package/dist/adapter/OpencodeSdkAdapter.d.ts +44 -0
- package/dist/adapter/acode-tool-names.d.ts +9 -0
- package/dist/adapter/idle-poll-loop.d.ts +20 -0
- package/dist/adapter/index.d.ts +3 -0
- package/dist/adapter/instance-ai-config-resolver.d.ts +20 -0
- package/dist/adapter/prompts.d.ts +12 -0
- package/dist/adapter/types.d.ts +184 -0
- package/dist/browser/browser-bootstrap.d.ts +15 -0
- package/dist/browser/browser-connect-token.d.ts +11 -0
- package/dist/browser/browser-frame-encode.d.ts +32 -0
- package/dist/browser/browser-pool.d.ts +129 -0
- package/dist/browser/browser-profile-store.d.ts +41 -0
- package/dist/browser/browser-ws-bridge.d.ts +20 -0
- package/dist/browser/built-in-browser-tools.d.ts +44 -0
- package/dist/browser/element-locator.d.ts +25 -0
- package/dist/browser/element-picker.d.ts +30 -0
- package/dist/browser/frame-encode.d.ts +19 -0
- package/dist/browser/input-dispatcher.d.ts +35 -0
- package/dist/browser/listener-store.d.ts +44 -0
- package/dist/browser/page-listener-manager.d.ts +88 -0
- package/dist/browser/page-listener-types.d.ts +38 -0
- package/dist/browser/screencast-differ.d.ts +10 -0
- package/dist/browser/screencast-manager.d.ts +94 -0
- package/dist/browser/snapshot-serializer.d.ts +56 -0
- package/dist/browser/ssrf-guard.d.ts +44 -0
- package/dist/browser/stealth.d.ts +21 -0
- package/dist/browser/step-archive.d.ts +13 -0
- package/dist/browser/types.d.ts +100 -0
- package/dist/browser/ws-server.d.ts +54 -0
- package/dist/config.d.ts +138 -2
- package/dist/config.js +2 -2
- package/dist/desktop/built-in-desktop-tools.d.ts +68 -0
- package/dist/desktop/built-in-desktop-tools.js +2 -1
- package/dist/desktop/desktop-control.d.ts +142 -0
- package/dist/desktop/desktop-control.js +2 -0
- package/dist/desktop/desktop-mcp-client.d.ts +28 -0
- package/dist/desktop/desktop-staleness.d.ts +66 -0
- package/dist/desktop/desktop-staleness.js +2 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +1 -1
- package/dist/middleware/auth.d.ts +26 -0
- package/dist/middleware/auth.js +1 -1
- package/dist/remote-desktop/computer-control.d.ts +3 -0
- package/dist/remote-desktop/coords.d.ts +6 -0
- package/dist/remote-desktop/frame-backpressure.d.ts +10 -0
- package/dist/remote-desktop/frame-encode.d.ts +3 -0
- package/dist/remote-desktop/index.js +2 -2
- package/dist/remote-desktop/input-dispatcher.d.ts +4 -0
- package/dist/remote-desktop/permission-manager.d.ts +3 -0
- package/dist/remote-desktop/screen-capture.d.ts +91 -0
- package/dist/remote-desktop/session-manager.d.ts +47 -0
- package/dist/remote-desktop/session-manager.js +1 -1
- package/dist/remote-desktop/system-backend.d.ts +64 -0
- package/dist/remote-desktop/types.d.ts +25 -0
- package/dist/remote-desktop/ui-automation.d.ts +11 -0
- package/dist/remote-desktop/win32-api.d.ts +10 -0
- package/dist/routes/acode-todos.d.ts +13 -0
- package/dist/routes/agent-state.d.ts +15 -0
- package/dist/routes/ai-sources.js +1 -1
- package/dist/routes/background-tasks.d.ts +18 -0
- package/dist/routes/background-tasks.js +2 -2
- package/dist/routes/bridge-temp-files.d.ts +1 -0
- package/dist/routes/bridge-temp-files.js +2 -0
- package/dist/routes/browser-listeners.d.ts +17 -0
- package/dist/routes/browser-sessions.d.ts +10 -0
- package/dist/routes/capabilities.js +1 -1
- package/dist/routes/dashboard-icon.d.ts +9 -0
- package/dist/routes/dashboard-icon.js +2 -0
- package/dist/routes/dashboard-theme.d.ts +24 -0
- package/dist/routes/dashboard-theme.js +157 -0
- package/dist/routes/dashboard.d.ts +9 -0
- package/dist/routes/dashboard.js +2021 -628
- package/dist/routes/debug-mount.d.ts +16 -0
- package/dist/routes/desktop-control.d.ts +15 -0
- package/dist/routes/desktop-control.js +2 -0
- package/dist/routes/events.d.ts +4 -0
- package/dist/routes/file-browser.d.ts +15 -10
- package/dist/routes/file-browser.js +1 -1
- package/dist/routes/file-change-diff.d.ts +25 -0
- package/dist/routes/file-diff-rollback.d.ts +28 -0
- package/dist/routes/file-snapshot.d.ts +7 -0
- package/dist/routes/git.d.ts +185 -0
- package/dist/routes/git.js +34 -34
- package/dist/routes/instance-tool-status.d.ts +5 -0
- package/dist/routes/instance.d.ts +8 -0
- package/dist/routes/instance.js +1 -1
- package/dist/routes/jdks.d.ts +4 -0
- package/dist/routes/launch.d.ts +5 -0
- package/dist/routes/lsp-providers.d.ts +11 -0
- package/dist/routes/lsp-providers.js +2 -0
- package/dist/routes/lsp.d.ts +41 -0
- package/dist/routes/lsp.js +4 -2
- package/dist/routes/mcp-extra.d.ts +15 -0
- package/dist/routes/mcp.d.ts +16 -0
- package/dist/routes/mcp.js +1 -1
- package/dist/routes/plugins.d.ts +19 -0
- package/dist/routes/plugins.js +1 -1
- package/dist/routes/processes.d.ts +4 -0
- package/dist/routes/properties.d.ts +4 -0
- package/dist/routes/pty.d.ts +29 -0
- package/dist/routes/runtime-binding.d.ts +3 -0
- package/dist/routes/sessions.d.ts +22 -0
- package/dist/routes/sessions.js +1 -1
- package/dist/routes/skills.d.ts +15 -0
- package/dist/routes/skills.js +1 -1
- package/dist/routes/sub-agents.d.ts +11 -0
- package/dist/routes/sub-agents.js +1 -1
- package/dist/routes/task-context.d.ts +5 -0
- package/dist/routes/tech-stack.d.ts +6 -0
- package/dist/routes/tech-stack.js +2 -0
- package/dist/routes/terminal.d.ts +122 -0
- package/dist/routes/terminal.js +22 -22
- package/dist/routes/workspace-index.d.ts +12 -0
- package/dist/routes/workspace-index.js +2 -0
- package/dist/routes/yml.d.ts +4 -0
- package/dist/scripts/migrate-user-scopes.d.ts +26 -0
- package/dist/scripts/migrate-user-scopes.js +2 -0
- package/dist/services/access-control.d.ts +21 -0
- package/dist/services/acode-bg-manager.d.ts +21 -0
- package/dist/services/acode-package.d.ts +10 -0
- package/dist/services/acode-package.js +1 -1
- package/dist/services/agent-capability-sync.d.ts +26 -0
- package/dist/services/agent-capability-sync.js +1 -1
- package/dist/services/agent-event-store.d.ts +20 -0
- package/dist/services/agent-ownership.d.ts +58 -0
- package/dist/services/agent-ownership.js +3 -0
- package/dist/services/agent-process-manager.d.ts +154 -0
- package/dist/services/agent-pty-manager.d.ts +39 -0
- package/dist/services/agent-pty-manager.js +5 -4
- package/dist/services/agent-startup-memory.d.ts +34 -0
- package/dist/services/agent-startup-memory.js +4 -4
- package/dist/services/ai-config-service.d.ts +26 -52
- package/dist/services/ai-config-service.js +1 -3
- package/dist/services/ai-source-apply.d.ts +7 -15
- package/dist/services/ai-source-apply.js +1 -1
- package/dist/services/auto-register.d.ts +165 -1
- package/dist/services/auto-register.js +1 -1
- package/dist/services/aws-client-agent-mcp.d.ts +14 -0
- package/dist/services/aws-client-agent-mcp.js +2 -2
- package/dist/services/bridge-package-publish-hooks.d.ts +14 -0
- package/dist/services/bridge-pairing.d.ts +82 -0
- package/dist/services/bridge-pairing.js +2 -0
- package/dist/services/bridge-temp-files.d.ts +65 -0
- package/dist/services/bridge-temp-files.js +2 -0
- package/dist/services/browser-session-manager.d.ts +71 -0
- package/dist/services/capability-config.d.ts +60 -15
- package/dist/services/capability-config.js +2 -2
- package/dist/services/change-cache-retention.d.ts +9 -0
- package/dist/services/changelog.d.ts +9 -0
- package/dist/services/cli-commands.d.ts +82 -0
- package/dist/services/cli-commands.js +6 -6
- package/dist/services/connection-key-rotation.d.ts +27 -0
- package/dist/services/connection-key-rotation.js +2 -0
- package/dist/services/debug-mount.d.ts +49 -0
- package/dist/services/desktop-mcp-manager.d.ts +103 -1
- package/dist/services/desktop-mcp-manager.js +1 -1
- package/dist/services/event-delta-pusher.d.ts +15 -0
- package/dist/services/fileSnapshotStore.d.ts +42 -0
- package/dist/services/fileSnapshotStore.js +1 -1
- package/dist/services/gitignore.d.ts +21 -0
- package/dist/services/gitignore.js +2 -0
- package/dist/services/instance-ai-config-service.d.ts +9 -0
- package/dist/services/instance-ai-config-service.js +1 -1
- package/dist/services/instance-features.d.ts +127 -0
- package/dist/services/instance-features.js +1 -1
- package/dist/services/instance-init-service.d.ts +3 -0
- package/dist/services/instance-init-service.js +1 -1
- package/dist/services/instance-state.d.ts +23 -0
- package/dist/services/jdk-scanner.d.ts +15 -0
- package/dist/services/launch-manager.d.ts +138 -0
- package/dist/services/launch-metrics.d.ts +42 -0
- package/dist/services/launch-streams.d.ts +19 -0
- package/dist/services/lifecycle-state.d.ts +5 -0
- package/dist/services/log-retention.d.ts +38 -0
- package/dist/services/log-retention.js +1 -1
- package/dist/services/lsp/install-manager.d.ts +55 -0
- package/dist/services/lsp/install-manager.js +2 -0
- package/dist/services/lsp/provider-registry.d.ts +108 -0
- package/dist/services/lsp/provider-registry.js +2 -0
- package/dist/services/lsp/uri-rewrite.d.ts +44 -0
- package/dist/services/lsp/uri-rewrite.js +2 -0
- package/dist/services/lsp-stdio-bridge.d.ts +41 -4
- package/dist/services/lsp-stdio-bridge.js +3 -3
- package/dist/services/mcp-deploy.d.ts +45 -4
- package/dist/services/mcp-deploy.js +4 -4
- package/dist/services/mcp-env-injector.d.ts +52 -0
- package/dist/services/mcp-launch-binding-queue.d.ts +12 -0
- package/dist/services/mcp-package.d.ts +22 -0
- package/dist/services/mcp-package.js +1 -1
- package/dist/services/mcp-probe-client.d.ts +19 -0
- package/dist/services/mcp-probe-client.js +1 -1
- package/dist/services/open-doc-events.d.ts +43 -0
- package/dist/services/open-doc-events.js +2 -0
- package/dist/services/open-doc-registry.d.ts +59 -0
- package/dist/services/open-doc-registry.js +2 -0
- package/dist/services/orphan-monitor.d.ts +43 -0
- package/dist/services/panel-auth.d.ts +24 -0
- package/dist/services/panel-env.d.ts +28 -0
- package/dist/services/plugin-deployment.d.ts +34 -1
- package/dist/services/plugin-deployment.js +2 -2
- package/dist/services/plugin-event-buffer.d.ts +21 -0
- package/dist/services/plugin-fs.d.ts +11 -0
- package/dist/services/plugin-handler-adapter.d.ts +13 -0
- package/dist/services/plugin-listener-runner.d.ts +10 -0
- package/dist/services/plugin-loader.d.ts +15 -0
- package/dist/services/plugin-manager.d.ts +95 -9
- package/dist/services/plugin-manager.js +4 -4
- package/dist/services/plugin-manifest.d.ts +14 -0
- package/dist/services/plugin-package.d.ts +13 -0
- package/dist/services/plugin-runtime.d.ts +15 -0
- package/dist/services/port-detector.d.ts +15 -0
- package/dist/services/process-detail.d.ts +3 -0
- package/dist/services/process-detector.d.ts +132 -0
- package/dist/services/process-registry.d.ts +120 -0
- package/dist/services/process-top.d.ts +6 -0
- package/dist/services/request-identity.d.ts +77 -0
- package/dist/services/request-identity.js +2 -0
- package/dist/services/request-invalid-dump.d.ts +4 -0
- package/dist/services/request-invalid-dump.js +1 -1
- package/dist/services/ring-buffer.d.ts +33 -0
- package/dist/services/runtime-binding.d.ts +56 -4
- package/dist/services/runtime-binding.js +4 -4
- package/dist/services/runtime-lifecycle-policy.d.ts +17 -0
- package/dist/services/runtime-resources-snapshot.d.ts +26 -0
- package/dist/services/runtime-resources-snapshot.js +2 -2
- package/dist/services/sdk-tool-file-change-recorder.d.ts +9 -0
- package/dist/services/session-output.d.ts +63 -0
- package/dist/services/session-output.js +3 -3
- package/dist/services/skill-manager.d.ts +42 -5
- package/dist/services/skill-manager.js +3 -3
- package/dist/services/snapshot-retention.d.ts +30 -0
- package/dist/services/snapshot-retention.js +2 -0
- package/dist/services/startup-config-wizard.d.ts +7 -1
- package/dist/services/startup-config-wizard.js +10 -10
- package/dist/services/system-metrics.d.ts +3 -0
- package/dist/services/tech-stack-scanner.d.ts +43 -0
- package/dist/services/tech-stack-scanner.js +2 -0
- package/dist/services/terminal-persistence.d.ts +43 -0
- package/dist/services/tool-installer.d.ts +12 -0
- package/dist/services/tunnel-client.d.ts +99 -2
- package/dist/services/tunnel-client.js +1 -1
- package/dist/services/update-log.d.ts +6 -0
- package/dist/services/update-notifier.d.ts +17 -0
- package/dist/services/update-notifier.js +2 -2
- package/dist/services/user-scope.d.ts +115 -0
- package/dist/services/user-scope.js +2 -0
- package/dist/services/windows-service-manager.d.ts +12 -0
- package/dist/services/workspace-files.d.ts +64 -0
- package/dist/services/workspace-index/index-manager.d.ts +46 -0
- package/dist/services/workspace-index/index-manager.js +2 -0
- package/dist/services/workspace-index/indexer.d.ts +15 -0
- package/dist/services/workspace-index/indexer.js +2 -0
- package/dist/services/workspace-index/query.d.ts +74 -0
- package/dist/services/workspace-index/query.js +5 -0
- package/dist/services/workspace-index/resolver.d.ts +26 -0
- package/dist/services/workspace-index/resolver.js +2 -0
- package/dist/services/workspace-index/types.d.ts +89 -0
- package/dist/services/workspace-index/types.js +2 -0
- package/dist/services/workspace-watch.d.ts +4 -0
- package/dist/services/workspaceTaskChangeWatcher.d.ts +49 -0
- package/dist/services/workspaceTaskChangeWatcher.js +2 -2
- package/dist/types.d.ts +9 -0
- package/dist/utils/config-write-queue.d.ts +11 -0
- package/dist/utils/env-safety.d.ts +21 -0
- package/dist/utils/file-utils.d.ts +15 -0
- package/dist/utils/instance-ai-config-debug-logger.d.ts +15 -0
- package/dist/utils/lifecycle-log.d.ts +5 -0
- package/dist/utils/logger.d.ts +13 -0
- package/dist/utils/logger.js +2 -1
- package/dist/utils/npm-version.d.ts +10 -0
- package/dist/utils/path-utils.d.ts +12 -0
- package/dist/utils/scheduler-url.d.ts +18 -0
- package/dist/utils/scheduler-url.js +2 -0
- package/dist/utils/sdk-package-loader.d.ts +13 -0
- package/dist/utils/sdk-package-loader.js +1 -1
- package/dist/utils/target-identity.d.ts +31 -0
- package/dist/utils/target-identity.js +2 -0
- package/dist/utils/validation.d.ts +17 -0
- package/dist/utils/yaml-utils.d.ts +48 -0
- package/package/acode/dist/__tests__/summary-request-helper.d.ts +12 -0
- package/package/acode/dist/__tests__/summary-request-helper.js +2 -0
- package/package/acode/dist/ask-user-question-tool.d.ts +17 -0
- package/package/acode/dist/await-complete-tool.d.ts +12 -0
- package/package/acode/dist/background-command-manager.d.ts +105 -0
- package/package/acode/dist/background-command-store.d.ts +27 -0
- package/package/acode/dist/background-command-tools.d.ts +8 -0
- package/package/acode/dist/background-output-ringbuffer.d.ts +15 -0
- package/package/acode/dist/built-in-file-tools.d.ts +65 -0
- package/package/acode/dist/built-in-symbols-tool.d.ts +3 -0
- package/package/acode/dist/builtins/commandArtifacts.d.ts +3 -0
- package/package/acode/dist/builtins/shellCommandPreparation.d.ts +17 -0
- package/package/acode/dist/builtins/shellCommandRunner.d.ts +4 -0
- package/package/acode/dist/builtins/shellOutputDecoder.d.ts +15 -0
- package/package/acode/dist/cache-control.d.ts +71 -0
- package/package/acode/dist/cache-control.js +2 -0
- package/package/acode/dist/commands/commandLoader.d.ts +3 -0
- package/package/acode/dist/commands/commandParser.d.ts +3 -0
- package/package/acode/dist/commands/commandRegistry.d.ts +3 -0
- package/package/acode/dist/compaction.d.ts +388 -4
- package/package/acode/dist/compaction.js +19 -17
- package/package/acode/dist/config.d.ts +3 -0
- package/package/acode/dist/context-overflow.d.ts +32 -0
- package/package/acode/dist/fs-utils.d.ts +18 -0
- package/package/acode/dist/hooks/hookBus.d.ts +3 -0
- package/package/acode/dist/image-utils.d.ts +35 -0
- package/package/acode/dist/index.d.ts +1 -0
- package/package/acode/dist/index.js +1 -1
- package/package/acode/dist/mcpToolNames.d.ts +32 -0
- package/package/acode/dist/microcompact.d.ts +110 -0
- package/package/acode/dist/microcompact.js +2 -0
- package/package/acode/dist/parsers/ast-cache.d.ts +41 -0
- package/package/acode/dist/parsers/file-index.d.ts +83 -0
- package/package/acode/dist/parsers/file-index.js +4 -0
- package/package/acode/dist/parsers/language-detector.d.ts +4 -0
- package/package/acode/dist/parsers/tree-sitter-loader.d.ts +12 -0
- package/package/acode/dist/parsers/types.d.ts +11 -0
- package/package/acode/dist/paths.d.ts +14 -0
- package/package/acode/dist/plugin-types.d.ts +34 -0
- package/package/acode/dist/read-file-state.d.ts +15 -0
- package/package/acode/dist/runtime-environment.d.ts +16 -0
- package/package/acode/dist/runtime.d.ts +828 -9
- package/package/acode/dist/runtime.js +40 -33
- package/package/acode/dist/skill-tool.d.ts +20 -0
- package/package/acode/dist/sub-agent-manager.d.ts +169 -0
- package/package/acode/dist/sub-agent-manager.js +1 -1
- package/package/acode/dist/sub-agent-store.d.ts +50 -0
- package/package/acode/dist/sub-agent-tools.d.ts +15 -0
- package/package/acode/dist/sub-agent-types.d.ts +13 -0
- package/package/acode/dist/terminal-tool.d.ts +15 -0
- package/package/acode/dist/terminal-types.d.ts +10 -0
- package/package/acode/dist/todo-store.d.ts +15 -0
- package/package/acode/dist/token-estimator.d.ts +32 -0
- package/package/acode/dist/token-estimator.js +2 -0
- package/package/acode/dist/tool-allocation.d.ts +113 -0
- package/package/acode/dist/tool-concurrency/index.d.ts +8 -0
- package/package/acode/dist/tool-concurrency/observability.d.ts +32 -0
- package/package/acode/dist/tool-concurrency/resource-lock.d.ts +30 -0
- package/package/acode/dist/tool-concurrency/scheduler.d.ts +19 -0
- package/package/acode/dist/tool-concurrency/types.d.ts +57 -0
- package/package/acode/dist/tool-group-manager.d.ts +195 -0
- package/package/acode/dist/tool-group-manager.js +4 -4
- package/package/acode/dist/types.d.ts +192 -0
- package/package/aws-client-agent-mcp/README.md +130 -215
- package/package/aws-client-agent-mcp/dist/ability-market-tools.d.ts +57 -0
- package/package/aws-client-agent-mcp/dist/ability-market-tools.js +1 -1
- package/package/aws-client-agent-mcp/dist/agent-client.d.ts +290 -3
- package/package/aws-client-agent-mcp/dist/agent-client.js +1 -1
- package/package/aws-client-agent-mcp/dist/config.d.ts +18 -0
- package/package/aws-client-agent-mcp/dist/constants.d.ts +2 -0
- package/package/aws-client-agent-mcp/dist/context-manager.d.ts +70 -0
- package/package/aws-client-agent-mcp/dist/http-client.d.ts +61 -0
- package/package/aws-client-agent-mcp/dist/index.d.ts +10 -0
- package/package/aws-client-agent-mcp/dist/logger.d.ts +24 -0
- package/package/aws-client-agent-mcp/dist/mcp-server.d.ts +610 -0
- package/package/aws-client-agent-mcp/dist/mcp-server.js +25 -23
- package/package/aws-client-agent-mcp/dist/mcp-tools.d.ts +158 -0
- package/package/aws-client-agent-mcp/dist/mcp-tools.js +38 -22
- package/package/aws-client-agent-mcp/dist/memory-store.d.ts +102 -2
- package/package/aws-client-agent-mcp/dist/memory-store.js +27 -2
- package/package/aws-client-agent-mcp/dist/memory-tools.d.ts +18 -0
- package/package/aws-client-agent-mcp/dist/memory-tools.js +13 -9
- package/package/aws-client-agent-mcp/dist/message-buffer.d.ts +86 -0
- package/package/aws-client-agent-mcp/dist/messageContent.d.ts +24 -0
- package/package/aws-client-agent-mcp/dist/office/office-equation.d.ts +19 -0
- package/package/aws-client-agent-mcp/dist/office/office-image.d.ts +18 -0
- package/package/aws-client-agent-mcp/dist/office/office-workspace.d.ts +29 -0
- package/package/aws-client-agent-mcp/dist/parent-lifecycle.d.ts +18 -0
- package/package/aws-client-agent-mcp/dist/runtime-launch-binding.d.ts +6 -0
- package/package/aws-client-agent-mcp/dist/server-memory-store.d.ts +5 -1
- package/package/aws-client-agent-mcp/dist/server-memory-store.js +1 -1
- package/package/aws-client-agent-mcp/dist/status-reporter.d.ts +41 -0
- package/package/aws-client-agent-mcp/dist/tool-groups.d.ts +136 -0
- package/package/aws-client-agent-mcp/dist/types.d.ts +174 -0
- package/package/aws-client-agent-mcp/dist/watchdog.d.ts +7 -0
- package/package/aws-client-agent-mcp/dist/websocket-client.d.ts +108 -0
- package/package.json +1 -1
package/dist/routes/lsp.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import $ from"node:path";import u,{WebSocketServer as b}from"ws";import{isRuntimeTokenValid as y}from"../middleware/auth.js";import{isUpgradeAllowed as A}from"../services/access-control.js";import{buildLaunchSpec as g,checkProviderAvailability as T,getProvider as f,resolveLanguageId as E,resolveProviderForFile as L}from"../services/lsp/provider-registry.js";import{buildUriRewriteRules as R,canonicalizePath as v,invertRules as N,rewriteMessageUris as h}from"../services/lsp/uri-rewrite.js";import{LspProcessBridge as z}from"../services/lsp-stdio-bridge.js";import{createLogger as O}from"../utils/logger.js";const a=O("lsp-ws"),M=6e4,_=Number(process.env.AWS_LSP_MAX_PROCESSES||6),d=new Map;function W(e){return $.resolve(e)}function m(e){return[W(e.workspacePath),e.providerId||"typescript",e.clientId||"default"].join("::")}function C(e){const r=e.toString("utf8");if(!r.trim())return null;try{return JSON.parse(r)}catch{return null}}function w(e){e.idleTimer&&(clearTimeout(e.idleTimer),e.idleTimer=null)}function F(e){w(e),e.idleTimer=setTimeout(()=>{if(!(e.ws!==null&&e.ws.readyState===u.OPEN)){for(const[i,o]of d)if(o===e){d.delete(i);break}e.bridge.dispose(),a.info(`[lsp-ws] \u7A7A\u95F2\u56DE\u6536\u8BED\u8A00\u670D\u52A1 provider=${e.providerId}`)}},M)}function U(){for(;d.size>_;){let e=null,r=Number.POSITIVE_INFINITY;for(const[o,t]of d)t.ws!==null&&t.ws.readyState===u.OPEN||t.lastActiveAt<r&&(r=t.lastActiveAt,e=o);if(!e)break;const i=d.get(e);d.delete(e),i?.bridge.dispose(),a.info(`[lsp-ws] \u8FDB\u7A0B\u4E0A\u9650\u6DD8\u6C70 provider=${i?.providerId} key=${e}`)}}function P(e,r,i,o=[]){const t=new z({workspacePath:r.workspacePath,language:r.language,providerId:r.providerId,launch:i},{onMessage:s=>{const n=d.get(e)?.ws;if(n&&n.readyState===u.OPEN)try{const l=o.length>0?h(s,o):s;n.send(JSON.stringify(l))}catch(l){a.warn(`[lsp-ws] \u8F6C\u53D1 server \u6D88\u606F\u5931\u8D25: ${l.message}`)}},onExit:()=>{d.get(e)?.bridge===t&&d.delete(e)},onError:s=>{a.warn(`[lsp-ws] \u8BED\u8A00\u670D\u52A1\u9519\u8BEF provider=${r.providerId} ${r.workspacePath}: ${s.message}`)}});return t.start(),t}async function B(e,r,i){const o=await g(i,{workspacePath:r.workspacePath,filePath:r.filePath});if(!o){const p=T(i);return a.warn(`[lsp-ws] provider \u4E0D\u53EF\u7528 provider=${i.id} reason=${p.reason??"unknown"}`),null}const t=await v(r.workspacePath),s=await v(r.filePath),n=R(r.workspacePath,t,r.filePath,s),l=N(n);return n.length>0&&a.info(`[lsp-ws] URI \u89C4\u8303\u5316\u542F\u7528 workspace=${r.workspacePath} -> ${t}`),U(),{bridge:P(e,r,o,l),ws:null,idleTimer:null,initialized:!1,lastActiveAt:Date.now(),providerId:i.id,toServerRules:n,toClientRules:l}}function D(e){const r=e.searchParams.get("workspacePath")||"",i=e.searchParams.get("file")||"",o=e.searchParams.get("language")||"",t=(e.searchParams.get("provider")||"").trim().toLowerCase(),s=(e.searchParams.get("clientId")||"default").trim()||"default";if(!r||!i)return{ctx:{workspacePath:r,filePath:i,language:"plaintext",providerId:"",clientId:s},provider:null,error:"workspacePath and file are required"};let n=t?f(t):null;if(n||(n=L(i)),n||(o==="typescript"||o==="javascript")&&(n=f("typescript")),!n)return{ctx:{workspacePath:r,filePath:i,language:o||"plaintext",providerId:"",clientId:s},provider:null,error:`no lsp provider for file: ${i}`};const l=E(n,i);return{ctx:{workspacePath:r,filePath:i,language:l,providerId:n.id,clientId:s},provider:n}}function J(e,r,i){const o=m(r),t=d.get(o);if(!t){B(o,r,i).then(s=>{if(!s){e.close(1011,"lsp provider unavailable");return}d.set(o,s),I(s,e,r)}).catch(s=>{a.warn(`[lsp-ws] \u521B\u5EFA\u8BED\u8A00\u670D\u52A1\u5931\u8D25 provider=${r.providerId}: ${s.message}`),e.close(1011,"lsp provider start failed")});return}I(t,e,r)}function I(e,r,i){const o=m(i);w(e);const t=e;t.ws&&t.ws!==r&&t.ws.readyState===u.OPEN&&(a.info(`[lsp-ws] \u6324\u5360\u65E7\u8FDE\u63A5 workspace=${i.workspacePath} provider=${i.providerId}`),t.ws.close(1e3,"superseded by new lsp connection")),t.ws=r,t.lastActiveAt=Date.now(),r.on("message",s=>{t.lastActiveAt=Date.now();const n=C(s);if(n===null){a.warn(`[lsp-ws] \u5FFD\u7565\u65E0\u6CD5\u89E3\u6790\u7684\u6D88\u606F: ${s.toString("utf8").slice(0,200)}`);return}const l=h(n,t.toServerRules);if(l.method==="initialize"){if(t.initialized){a.info(`[lsp-ws] \u590D\u7528\u8FDB\u7A0B\u6536\u5230\u4E8C\u6B21 initialize\uFF0C\u91CD\u5EFA\u8BED\u8A00\u670D\u52A1\u8FDB\u7A0B workspace=${i.workspacePath} provider=${i.providerId}`);const p=t.bridge;g(f(i.providerId)??f("typescript"),{workspacePath:i.workspacePath,filePath:i.filePath}).then(c=>{if(!c){r.close(1011,"lsp provider unavailable");return}p.dispose(),t.bridge=P(o,i,c,t.toClientRules),t.bridge.send(l)}).catch(c=>{a.warn(`[lsp-ws] \u91CD\u5EFA\u8BED\u8A00\u670D\u52A1\u5931\u8D25: ${c.message}`),r.close(1011,"lsp provider restart failed")});return}t.initialized=!0}t.bridge.send(l)}),r.on("close",()=>{t.ws===r&&(t.ws=null),F(t)}),r.on("error",s=>{a.warn(`[lsp-ws] \u8FDE\u63A5\u5F02\u5E38 workspace=${i.workspacePath} provider=${i.providerId}: ${s.message}`)}),a.info(`[lsp-ws] \u8FDE\u63A5\u5EFA\u7ACB workspace=${i.workspacePath} file=${i.filePath} provider=${i.providerId} language=${i.language} client=${i.clientId} reused=${e.bridge.running}`)}function K(e,r){const i=r.searchParams.get("token")||"";if(i.trim())return i.trim();const o=e.headers["x-runtime-token"];return Array.isArray(o)?o[0]?.trim()||"":typeof o=="string"?o.trim():String(e.headers.authorization||"").match(/^Bearer\s+(.+)$/i)?.[1]?.trim()||""}function V(e){const r=String(e.socket?.remoteAddress||"");return r==="127.0.0.1"||r==="::1"||r==="::ffff:127.0.0.1"||r.startsWith("127.")}function x(e){const r=new b({noServer:!0});e.on("upgrade",(i,o,t)=>{if(!A(i,o))return;const s=i.headers.host||"localhost",n=new URL(i.url||"/",`http://${s}`);if(n.pathname!=="/ws/lsp")return;const l=K(i,n);if(!y(l)&&!V(i)){a.warn("[lsp-ws] upgrade \u9274\u6743\u5931\u8D25\uFF1A\u7F3A\u5C11\u6216\u975E\u6CD5 runtime token"),o.write(`HTTP/1.1 401 Unauthorized\r
|
|
2
2
|
\r
|
|
3
|
-
`),
|
|
3
|
+
`),o.destroy();return}const p=D(n);if(!p.provider){a.warn(`[lsp-ws] upgrade \u53C2\u6570\u65E0\u6548: ${p.error}`),o.write(`HTTP/1.1 400 Bad Request\r
|
|
4
|
+
\r
|
|
5
|
+
`),o.destroy();return}const{ctx:c,provider:k}=p;r.handleUpgrade(i,o,t,S=>{J(S,c,k)})})}function ee(){return[...d.entries()].map(([e,r])=>({key:e,providerId:r.providerId,running:r.bridge.running,connected:r.ws!==null&&r.ws.readyState===u.OPEN}))}function re(){for(const e of d.values())w(e),e.bridge.dispose();d.clear()}export{x as attachLspWebSocketServer,re as disposeAllLspProcesses,ee as listLspProcesses,D as resolveLspSocketContext};
|
|
4
6
|
|
package/dist/routes/mcp.d.ts
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
2
13
|
import { type McpDeploySpec } from "../services/mcp-deploy.js";
|
|
3
14
|
export declare const mcpRouter: import("express-serve-static-core").Router;
|
|
4
15
|
export declare function normalizeSpec(raw: unknown): McpDeploySpec | null;
|
|
5
16
|
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
6
22
|
export declare function stripBuiltinMcpDisable(map: Record<string, unknown>): Record<string, unknown>;
|
package/dist/routes/mcp.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Router as
|
|
1
|
+
import{Router as h}from"express";import{validateToken as a}from"../middleware/auth.js";import{assertAgentOwnership as g}from"../services/agent-ownership.js";import{getEffective as b,setDefault as S,setInherited as k,setOverride as v}from"../services/capability-config.js";import{McpDeployManager as l}from"../services/mcp-deploy.js";import{isBuiltinMcpName as u}from"../services/mcp-env-injector.js";import{probeDeployedMcp as M}from"../services/mcp-probe-client.js";import{getPanelEnvVars as w,getAgentMeta as I}from"../services/panel-env.js";import{getUserScopeOrThrow as d,requireAgentOwnership as O,requireUserScope as m}from"../services/user-scope.js";import{sanitizeEnvForChild as A}from"../utils/env-safety.js";import{createLogger as E}from"../utils/logger.js";const C=E("mcp"),c=h();function p(n){return(e,t)=>{n(e,t).catch(o=>{if(C.error("[mcp] %s %s \u5931\u8D25: %s",e.method,e.path,o.message),!t.headersSent){const s=o.message.includes("agent-ownership-mismatch")?403:500;t.status(s).json({ok:!1,error:o.message})}})}}function D(n){if(!n||typeof n!="object")return null;const e=n,o={type:String(e.type||e.transport||"stdio").trim().toLowerCase()||"stdio"};e.command!==null&&e.command!==void 0&&String(e.command).trim()&&(o.command=String(e.command).trim()),e.url!==null&&e.url!==void 0&&String(e.url).trim()&&(o.url=String(e.url).trim()),Array.isArray(e.args)&&(o.args=e.args.map(r=>String(r))),e.env&&typeof e.env=="object"&&(o.env=e.env),e.headers&&typeof e.headers=="object"&&(o.headers=e.headers),e.collapsed===!0&&(o.collapsed=!0);const s=e.description===null||e.description===void 0?"":String(e.description).trim();return s&&(o.description=s),o}function P(n){const e={};for(const[t,o]of Object.entries(n))u(t)&&o===!1||(e[t]=o);return e}c.post("/mcp/deployed/list",a,m,p(async(n,e)=>{const t=d(n),s=l.forScope(t).listDeployed().map(r=>({...r,enabled:b(t,"","mcp",r.name)}));e.json({ok:!0,deployedMcp:s})})),c.get("/mcp/deployed",a,m,p(async(n,e)=>{const t=d(n),s=l.forScope(t).listDeployed().map(r=>({...r,enabled:b(t,"","mcp",r.name)}));e.json({ok:!0,deployedMcp:s})})),c.post("/mcp/deployed/default",a,m,p(async(n,e)=>{const t=String((n.body??{})?.name??"").trim();if(!t){e.status(400).json({ok:!1,error:"name is required"});return}const o=String((n.body??{})?.agentId??"").trim(),s=(n.body??{})?.enabled,r=s==null?null:!!s;if(u(t)&&r===!1){e.status(400).json({ok:!1,error:`\u300C${t}\u300D\u662F\u5185\u7F6E\u901A\u8BAF MCP\uFF0C\u6052\u4E3A\u9ED8\u8BA4\u542F\u7528\uFF0C\u4E0D\u53EF\u5173\u95ED`});return}const i=d(n);if(o){if(!g(o,i)){e.status(403).json({ok:!1,error:"agent-ownership-mismatch"});return}v(i,o,"mcp",t,r)}else S(i,"mcp",t,r);e.json({ok:!0,name:t,agentId:o,enabled:r})})),c.post("/mcp/deployed/inherited",a,m,p(async(n,e)=>{const t=String((n.body??{})?.agentId??"").trim();if(!t){e.status(400).json({ok:!1,error:"agentId is required"});return}const o=d(n);if(!g(t,o)){e.status(403).json({ok:!1,error:"agent-ownership-mismatch"});return}const s=(n.body??{})?.map,r=s&&typeof s=="object"&&!Array.isArray(s)?P(s):s??null;k(o,t,"mcp",r),e.json({ok:!0,agentId:t,count:r&&typeof r=="object"?Object.keys(r).length:0})})),c.post("/mcp/deployed/save",a,m,p(async(n,e)=>{const{name:t,spec:o,defaultEnabled:s,sha256:r}=n.body??{},i=String(t??"").trim();if(!i){e.status(400).json({ok:!1,error:"name is required"});return}const f=D(o);if(!f){e.status(400).json({ok:!1,error:"spec \u975E\u6CD5"});return}if(u(i)){e.status(400).json({ok:!1,error:`\u300C${i}\u300D\u662F\u5185\u7F6E\u901A\u8BAF MCP\uFF0C\u7531\u5B9E\u4F8B\u521D\u59CB\u5316\u81EA\u52A8\u90E8\u7F72\uFF0C\u4E0D\u53EF\u8986\u76D6`});return}const j=d(n),y=l.forScope(j).saveMcp(i,f,s!==!1,r?String(r):void 0);e.status(y.ok?200:400).json(y)})),c.post("/mcp/deployed/remove",a,m,p(async(n,e)=>{const t=String((n.body??{})?.name??"").trim(),o=d(n),s=l.forScope(o).removeMcp(t);e.status(s.ok?200:400).json(s)})),c.post("/mcp/probe",a,m,O,p(async(n,e)=>{const t=n.body??{},o=String(t.name??"").trim();if(!o){e.status(400).json({ok:!1,error:"name is required"});return}if(Object.prototype.hasOwnProperty.call(t,"spec")){e.status(400).json({ok:!1,error:"probe \u53EA\u63A5\u53D7\u5DF2\u90E8\u7F72 MCP \u7684 name\uFF0C\u4E0D\u63A5\u53D7\u8C03\u7528\u65B9\u4F20\u5165 spec"});return}const s=String(t.agentId??"").trim(),r={...s?w(s):{},...A(t.env)},i=await M(o,{scope:d(n),effectiveEnv:r,agentMeta:s?I(s):void 0});e.json(i)})),c.post("/mcp/cc-switch/list",a,p(async(n,e)=>{e.json({ok:!0,mcpServers:[],state:{skills:[],mcpServers:[]}})}));export{c as mcpRouter,D as normalizeSpec,P as stripBuiltinMcpDisable};
|
|
2
2
|
|
package/dist/routes/plugins.d.ts
CHANGED
package/dist/routes/plugins.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Router as
|
|
1
|
+
import{Router as S}from"express";import{raw as w}from"express";import{validateToken as g,validateTokenOrLoopback as I}from"../middleware/auth.js";import{assertAgentOwnership as j}from"../services/agent-ownership.js";import{getEffective as h,setDefault as N,setInherited as v,setOverride as O}from"../services/capability-config.js";import{isValidPluginName as f,pluginManager as u}from"../services/plugin-manager.js";import{getUserScopeOrThrow as y,requireAgentOwnership as m,requireUserScope as l}from"../services/user-scope.js";import{createLogger as E}from"../utils/logger.js";const P=E("plugins"),r=S();function i(s){return(n,e)=>{s(n,e).catch(t=>{if(P.error("[plugins] %s %s \u5931\u8D25: %s",n.method,n.path,t.message),!e.headersSent){const a=t.message.includes("agent-ownership-mismatch")?403:500;e.status(a).json({ok:!1,error:t.message})}})}}r.get("/plugins/deployed",g,l,i(async(s,n)=>{const e=y(s),a=(await u.listDeployed(e)).map(o=>({...o,enabled:h(e,"","plugins",o.pluginName)}));n.json({ok:!0,deployedPlugins:a})})),r.post("/plugins/deployed/default",g,l,i(async(s,n)=>{const e=String((s.body??{})?.pluginName??"").trim();if(!f(e)){n.status(400).json({ok:!1,error:"pluginName \u975E\u6CD5\uFF08\u987B\u4E3A kebab-case\uFF0C1~64 \u5B57\u7B26\uFF09"});return}const t=String((s.body??{})?.agentId??"").trim(),a=(s.body??{})?.enabled,o=a==null?null:!!a,c=y(s);if(t){if(!j(t,c)){n.status(403).json({ok:!1,error:"agent-ownership-mismatch"});return}O(c,t,"plugins",e,o)}else N(c,"plugins",e,o);n.json({ok:!0,pluginName:e,agentId:t,enabled:o})})),r.post("/plugins/deployed/inherited",g,l,i(async(s,n)=>{const e=String((s.body??{})?.agentId??"").trim();if(!e){n.status(400).json({ok:!1,error:"agentId is required"});return}const t=y(s);if(!j(e,t)){n.status(403).json({ok:!1,error:"agent-ownership-mismatch"});return}const a=(s.body??{})?.map;v(t,e,"plugins",a??null),n.json({ok:!0,agentId:e,count:Object.keys(a??{}).length})})),r.post("/plugins/deployed/remove",g,l,i(async(s,n)=>{const e=String((s.body??{})?.pluginName??"").trim();if(!f(e)){n.status(400).json({ok:!1,error:"pluginName \u975E\u6CD5\uFF08\u987B\u4E3A kebab-case\uFF0C1~64 \u5B57\u7B26\uFF09"});return}const t=y(s),a=await u.removeDeployedPlugin(e,t);n.status(a.ok?200:400).json(a)})),r.get("/plugins/:agentId",g,l,m,i(async(s,n)=>{const e=String(s.params.agentId??"").trim();if(!e){n.status(400).json({ok:!1,error:"agentId is required"});return}const t=await u.list(e);n.json({ok:!0,agentId:e,plugins:t})})),r.post("/plugins/:agentId/install",g,l,m,i(async(s,n)=>{const e=String(s.params.agentId??"").trim(),t=s.body??{},a=typeof t.source=="string"?t.source:"",o=t.config&&typeof t.config=="object"&&!Array.isArray(t.config)?Object.fromEntries(Object.entries(t.config).filter(d=>typeof d[1]=="string")):void 0;if(!e){n.status(400).json({ok:!1,error:"agentId is required"});return}const c={action:"install",source:a,...o?{config:o}:{}},p=await u.manage(e,c);n.status(p.ok?200:400).json(p)}));function b(s){return[g,l,m,i(async(n,e)=>{const t=String(n.params.agentId??"").trim(),a=String(n.params.name??"").trim();if(!t||t==="deployed"||!f(a)){e.status(400).json({ok:!1,error:"agentId \u4E14 name \u987B\u4E3A\u5408\u6CD5\u63D2\u4EF6\u540D\uFF08kebab-case\uFF0C1~64 \u5B57\u7B26\uFF09"});return}const o=await u.manage(t,{action:s,name:a});e.status(o.ok?200:400).json(o)})]}r.post("/plugins/:agentId/:name/reload",...b("reload")),r.post("/plugins/:agentId/:name/enable",...b("enable")),r.post("/plugins/:agentId/:name/disable",...b("disable")),r.delete("/plugins/:agentId/:name",...b("uninstall")),r.get("/plugins/:agentId/:name/logs",g,l,m,i(async(s,n)=>{const e=String(s.params.agentId??"").trim(),t=String(s.params.name??"").trim();if(!e||!f(t)){n.status(400).json({ok:!1,error:"agentId \u4E14 name \u987B\u4E3A\u5408\u6CD5\u63D2\u4EF6\u540D\uFF08kebab-case\uFF0C1~64 \u5B57\u7B26\uFF09"});return}const a=await u.getLogs(e,t);n.status(a.ok?200:404).json(a)})),r.get("/plugins/:agentId/commands",g,l,m,i(async(s,n)=>{const e=String(s.params.agentId??"").trim();if(!e){n.status(400).json({ok:!1,error:"agentId is required"});return}const t=await u.getPluginCommands(e);n.json({ok:!0,agentId:e,commands:t.map(a=>({name:a.name,description:a.description??"",argumentHint:a.argumentHint??"",sourcePath:a.sourcePath,plugin:a.plugin}))})})),r.get("/plugin-events/:agentId/events",I,i(async(s,n)=>{const e=String(s.params.agentId??"").trim();if(!e){n.status(400).json({ok:!1,error:"agentId is required"});return}const t=Number(s.query.maxPerKey),a=Number.isFinite(t)&&t>0?t:void 0,o=await u.drainEvents(e,{maxPerKey:a});n.json({ok:!0,agentId:e,...o})})),r.post("/plugin-events/:agentId/callback/:plugin",I,i(async(s,n)=>{const e=String(s.params.agentId??"").trim(),t=String(s.params.plugin??"").trim(),a=s.body??{};if(!e||!t){n.status(400).json({ok:!1,error:"agentId and plugin are required"});return}const o=await u.enqueueExternalEvent(e,t,a);n.status(o.ok?200:400).json(o)})),r.post("/plugins/:agentId/private-save",g,l,m,i(async(s,n)=>{const e=String(s.params.agentId??"").trim();if(!e){n.status(400).json({ok:!1,error:"agentId is required"});return}const t=s.body??{},a=Buffer.from(String(t.contentBase64??""),"base64");if(a.length===0){n.status(400).json({ok:!1,error:"contentBase64 \u4E3A\u7A7A"});return}const o=String(t.fileName??"plugin.zip"),c=t.config&&typeof t.config=="object"&&!Array.isArray(t.config)?Object.fromEntries(Object.entries(t.config).filter(d=>typeof d[1]=="string")):void 0,p=await u.installFromZip(e,a,o,c);n.status(p.ok?200:400).json(p)})),r.post("/plugins/:agentId/private-remove",g,l,m,i(async(s,n)=>{const e=String(s.params.agentId??"").trim(),t=String((s.body??{})?.pluginName??"").trim();if(!e||!f(t)){n.status(400).json({ok:!1,error:"agentId \u4E0E pluginName \u5FC5\u586B\uFF08kebab-case\uFF09"});return}const a=await u.manage(e,{action:"uninstall",name:t});n.status(a.ok?200:400).json(a)})),r.post("/plugins/:agentId/upload",g,l,m,w({type:()=>!0,limit:"100mb"}),i(async(s,n)=>{const e=String(s.params.agentId??"").trim();if(!e){n.status(400).json({ok:!1,error:"agentId is required"});return}const t=s.body;if(!Buffer.isBuffer(t)||t.length===0){n.status(400).json({ok:!1,error:"\u7F3A\u5C11 zip \u5185\u5BB9\uFF08raw body, Content-Type: application/zip\uFF09"});return}const a=String(s.query.filename??"plugin.zip");if(!a.toLowerCase().endsWith(".zip")){n.status(400).json({ok:!1,error:"\u4EC5\u652F\u6301 .zip \u63D2\u4EF6\u5305"});return}let o;const c=String(s.query.config??"").trim();if(c)try{const d=JSON.parse(c);if(d&&typeof d=="object"&&!Array.isArray(d))o=Object.fromEntries(Object.entries(d).filter(k=>typeof k[1]=="string"));else{n.status(400).json({ok:!1,error:"config \u5FC5\u987B\u662F JSON \u5BF9\u8C61"});return}}catch{n.status(400).json({ok:!1,error:"config \u4E0D\u662F\u5408\u6CD5\u7684 JSON \u5BF9\u8C61"});return}const p=await u.installFromZip(e,t,a,o);n.status(p.ok?200:400).json(p)}));export{r as pluginsRouter};
|
|
2
2
|
|
package/dist/routes/pty.d.ts
CHANGED
|
@@ -38,24 +38,44 @@ export interface PtySessionEntry extends PtySessionSummary {
|
|
|
38
38
|
}
|
|
39
39
|
export declare const ptySessions: Map<string, PtySessionEntry>;
|
|
40
40
|
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
41
44
|
export declare function resolvePtyIdleTtlMs(env?: NodeJS.ProcessEnv): number;
|
|
42
45
|
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
43
51
|
export declare function resolveDefaultShell(platform?: NodeJS.Platform, env?: NodeJS.ProcessEnv, existsSync?: (path: fs.PathLike) => boolean): {
|
|
44
52
|
shell: string;
|
|
45
53
|
args: string[];
|
|
46
54
|
};
|
|
47
55
|
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
48
59
|
export declare function resolveRequestedShell(requestedShell: unknown, platform?: NodeJS.Platform, env?: NodeJS.ProcessEnv): {
|
|
49
60
|
shell: string;
|
|
50
61
|
args: string[];
|
|
51
62
|
};
|
|
52
63
|
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
53
67
|
export declare function isPathInsideRoot(candidatePath: string, rootPath: string): boolean;
|
|
54
68
|
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
55
72
|
export declare function resolvePtyWorkspacePath(workspacePath: unknown, env?: NodeJS.ProcessEnv): string;
|
|
56
73
|
|
|
57
74
|
export declare function readPtyOutputBuffer(session: PtySessionEntry): string;
|
|
58
75
|
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
59
79
|
export declare function createPtySession(input: {
|
|
60
80
|
workspacePath: unknown;
|
|
61
81
|
title?: unknown;
|
|
@@ -73,15 +93,24 @@ export declare function resolveMaxPtySessions(env?: NodeJS.ProcessEnv): number;
|
|
|
73
93
|
export declare function listPtySessions(): PtySessionSummary[];
|
|
74
94
|
export declare function getPtySessionSummary(id: string): PtySessionSummary | undefined;
|
|
75
95
|
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
76
99
|
export declare function createPtyConnectToken(sessionId: string): {
|
|
77
100
|
token: string;
|
|
78
101
|
expiresAt: string;
|
|
79
102
|
} | undefined;
|
|
80
103
|
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
81
107
|
export declare function closePtySession(id: string, reason?: string): boolean;
|
|
82
108
|
export declare function closeAllPtySessions(reason?: string): void;
|
|
83
109
|
export declare const ptyRouter: Router;
|
|
84
110
|
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
85
114
|
export declare function attachPtyWebSocketServer(server: {
|
|
86
115
|
on: (event: "upgrade", listener: (request: IncomingMessage, socket: Socket, head: Buffer) => void) => unknown;
|
|
87
116
|
}): void;
|
|
@@ -13,5 +13,8 @@ export interface RuntimeTokenRequestResult {
|
|
|
13
13
|
error?: string;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
16
19
|
export declare function resolveRuntimeTokenRequest(input: RuntimeTokenRequestInput): RuntimeTokenRequestResult;
|
|
17
20
|
export declare function logRuntimeBindingStartupState(): void;
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
2
6
|
export declare const sessionsRouter: import("express-serve-static-core").Router;
|
|
3
7
|
export interface HandleCapabilityToolsRequestInput {
|
|
4
8
|
agentId: string;
|
|
@@ -11,6 +15,14 @@ export interface HandleCapabilityToolsRequestInput {
|
|
|
11
15
|
resolveAdapter?: (providerId: string) => unknown;
|
|
12
16
|
}
|
|
13
17
|
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
14
26
|
export declare function handleCapabilityToolsRequest(input: HandleCapabilityToolsRequestInput): Promise<{
|
|
15
27
|
status: number;
|
|
16
28
|
body: Record<string, unknown>;
|
|
@@ -27,9 +39,19 @@ export interface HandleCapabilityToolCallRequestInput {
|
|
|
27
39
|
resolveAdapter?: (providerId: string) => unknown;
|
|
28
40
|
}
|
|
29
41
|
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
30
49
|
export declare function handleCapabilityToolCallRequest(input: HandleCapabilityToolCallRequestInput): Promise<{
|
|
31
50
|
status: number;
|
|
32
51
|
body: Record<string, unknown>;
|
|
33
52
|
}>;
|
|
34
53
|
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
35
57
|
export declare function resolveActiveSdkSessionSnapshotStatus(adapterStatus?: string, currentRuntimeStatus?: string, currentRuntimeActionType?: string): string;
|
package/dist/routes/sessions.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{execSync as R}from"node:child_process";import{Router as C}from"express";import{adapterRegistry as y}from"../adapter/index.js";import{validateToken as I,validateTokenOrLoopback as P}from"../middleware/auth.js";import{isProcessRunning as w,findOrphanProcessByAgentId as b,findOrphanProcessByWorkspace as F}from"../services/process-detector.js";import{findPersistedSessionByAgentId as S,loadPersistedSessions as E,removePersistedSession as A}from"../services/terminal-persistence.js";import{createLogger as K}from"../utils/logger.js";import{sdkSessions as m,cleanupSdkSessionByAgentId as L}from"./terminal.js";const d=K("sessions"),h=C();h.post("/sessions/:agentId/notify-force-message",P,(i,r)=>{const e=String(i.params.agentId??"").trim();if(!e){r.status(400).json({ok:!1,error:"agentId is required"});return}const n=Array.from(m.entries()).find(([,a])=>a.agentId===e);if(!n){r.json({ok:!0,notified:!1,message:"No active SDK session for this agentId"});return}const[o,s]=n,t=y.get(s.providerId||"claude-code");if(typeof t.notifyForceMessage=="function"){const a=t.notifyForceMessage(o);r.json({ok:!0,notified:a})}else r.json({ok:!0,notified:!1,message:"Adapter does not support force message notification"})}),h.post("/sessions/:agentId/capability-tools",P,async(i,r)=>{const e=String(i.params.agentId??"").trim(),n=()=>{const s=Array.from(m.entries()).find(([,t])=>t.agentId===e);return s?{agentId:e,providerId:s[1].providerId||""}:void 0},o=await x({agentId:e,capability:String(i.body?.capability??""),action:i.body?.action,resolveSession:n,resolveAdapter:s=>y.get(s||"claude-code")});r.status(o.status).json(o.body)}),h.post("/sessions/:agentId/capability-tools/call",P,async(i,r)=>{const e=String(i.params.agentId??"").trim(),n=()=>{const s=Array.from(m.entries()).find(([,t])=>t.agentId===e);return s?{agentId:e,providerId:s[1].providerId||""}:void 0},o=await B({agentId:e,capability:String(i.body?.capability??""),tool:String(i.body?.tool??""),args:i.body?.args??{},resolveSession:n,resolveAdapter:s=>y.get(s||"claude-code")});r.status(o.status).json(o.body)});const D=new Set(["browser","desktop"]);async function x(i){const r=String(i.agentId??"").trim();if(!r)return{status:400,body:{ok:!1,error:"agentId is required"}};const e=String(i.capability??"").trim();if(!D.has(e))return{status:400,body:{ok:!1,error:'capability must be "browser" or "desktop"'}};const n=i.action;if(n!=="expand"&&n!=="collapse")return{status:400,body:{ok:!1,error:`action must be "expand" or "collapse", got: ${String(n)}`}};const o=i.resolveSession();if(!o)return{status:200,body:{ok:!0,changed:{sessions:0,tools:0}}};const s=i.resolveAdapter?.(o.providerId);if(!s||typeof s.setBuiltInCapabilityTools!="function")return{status:200,body:{ok:!0,changed:{sessions:0,tools:0},message:`Adapter for provider "${o.providerId}" does not support setBuiltInCapabilityTools`}};try{const t=await s.setBuiltInCapabilityTools(r,e,n),a={ok:!0,changed:{sessions:t.sessions,tools:t.tools}};return n==="expand"&&Array.isArray(t.manifests)&&(a.manifests=t.manifests),{status:200,body:a}}catch(t){const a=t instanceof Error?t.message:String(t);return d.error(`capability-tools ${n} failed for agent ${r}: ${a}`),{status:500,body:{ok:!1,error:a}}}}async function B(i){const r=String(i.agentId??"").trim();if(!r)return{status:400,body:{ok:!1,error:"agentId is required"}};const e=String(i.capability??"").trim();if(!D.has(e))return{status:400,body:{ok:!1,error:'capability must be "browser" or "desktop"'}};const n=String(i.tool??"").trim();if(!n)return{status:400,body:{ok:!1,error:"tool is required"}};const o=i.resolveSession();if(!o)return{status:200,body:{ok:!1,error:`No active SDK session for agentId "${r}"`}};const s=i.resolveAdapter?.(o.providerId);if(!s||typeof s.callBuiltInCapabilityTool!="function")return{status:200,body:{ok:!1,error:`Adapter for provider "${o.providerId}" does not support callBuiltInCapabilityTool`}};try{return{status:200,body:await s.callBuiltInCapabilityTool(r,e,n,i.args??{})}}catch(t){const a=t instanceof Error?t.message:String(t);return d.error(`capability-tools/call ${n} failed for agent ${r}: ${a}`),{status:500,body:{ok:!1,error:a}}}}function j(i,r,e){const n=String(i||"").trim();if(n){const s=String(r||"").trim(),t=String(e||"").trim().toLowerCase();return n.toLowerCase()==="tool_using"&&s.toLowerCase()==="waiting_input"&&t==="idle"?s:n}return String(r||"").trim()||"running"}h.get("/sessions",I,async(i,r)=>{try{const n=Array.from(m.entries()).map(([p,u])=>{const l=y.get(u.providerId||"claude-code"),c=j(l.getSessionStatus(p),u.currentRuntimeStatus,u.currentRuntimeActionType);return{sessionId:p,agentId:u.agentId,workspacePath:u.workspacePath,status:c,runtimeStatus:c,runtimeActionType:u.currentRuntimeActionType,runtimeActionLabel:u.currentRuntimeActionLabel,runtimeActionDetail:u.currentRuntimeActionDetail,mode:"sdk",startedAt:null}}),o=await E(),s=new Set(n.map(p=>p.sessionId)),t=o.filter(p=>!s.has(p.sessionId)),a={ok:!0,active:n,persisted:t};r.json(a)}catch(e){const n=e;r.status(500).json({error:n.message})}}),h.post("/sessions/recover",I,async(i,r)=>{const{agentId:e,workspacePath:n,command:o}=i.body;if(!e){r.status(400).json({error:"agentId is required"});return}try{const s=Array.from(m.entries()).find(([,g])=>g.agentId===e);if(s){const g=y.get(s[1].providerId||"claude-code"),k=j(g.getSessionStatus(s[0]),s[1].currentRuntimeStatus,s[1].currentRuntimeActionType);r.json({ok:!0,sessionId:s[0],agentId:e,workspacePath:s[1].workspacePath,command:s[1].config.command,status:k,runtimeStatus:k,runtimeActionType:s[1].currentRuntimeActionType,runtimeActionLabel:s[1].currentRuntimeActionLabel,runtimeActionDetail:s[1].currentRuntimeActionDetail,mode:"sdk",recovered:!1,message:"SDK session already active"});return}const t=await S(e);let a=!1,p;if(t?.pid&&await w(t.pid))a=!0,p=t.pid,d.info(`[Recover] Detected orphan process for agentId=${e}, pid=${t.pid}`);else if(t?.mode==="sdk"||!t?.pid){const g=await b(e);g&&(a=!0,p=g.pid,d.info(`[Recover] Found orphan process by agentId search: agentId=${e}, pid=${g.pid}`))}const u=n||t?.workspacePath,l=o||t?.command||"acode",c=t?.mode||"sdk";if(!u){r.status(400).json({error:"workspacePath is required (not found in persisted session)"});return}if(a&&p){d.info(`[Recover] Returning orphan process info for agentId=${e}`),r.json({ok:!0,sessionId:t?.sessionId||"",agentId:e,workspacePath:u,command:l,status:"orphan_detected",runtimeStatus:t?.runtimeStatus,runtimeActionType:t?.runtimeActionType,runtimeActionLabel:t?.runtimeActionLabel,runtimeActionDetail:t?.runtimeActionDetail,recovered:!1,orphan:{pid:p,message:"Found orphan process still running. Manual intervention may be required."},mode:c});return}await A(t?.sessionId||"");const f={ok:!1,sessionId:t?.sessionId||"",agentId:e,workspacePath:u,command:l,status:"stopped",recovered:!1,message:"No active SDK session found; start a new SDK runtime session instead."};r.json(f)}catch(s){const t=s;d.error("Error:",t),r.status(500).json({error:t.message})}}),h.post("/search-orphan",I,async(i,r)=>{const{agentId:e,workspacePath:n}=i.body;if(!e){r.status(400).json({error:"agentId is required"});return}try{const o=Array.from(m.entries()).find(([,c])=>c.agentId===e);let s=!1,t,a;if(o){const[c,f]=o,g=y.get(f.providerId||"claude-code");t=g.getSessionPid?.(c),a=f.config?.command;const k=t?await w(t):!1,v=g.getSessionStatus(c),T=v==="completed"||v==="terminated"||v==="error";if(k)s=!0;else if(t&&!k)d.info(`[search-orphan] Cleaning up stale SDK session (process dead): agentId=${e}, sessionId=${c}, pid=${t}`),m.delete(c),await A(c);else if(T){d.info(`[search-orphan] Cleaning up stale in-process SDK session (status=${v}): agentId=${e}, sessionId=${c}`);try{await g.terminateSession(c)}catch($){d.warn(`[search-orphan] Failed to terminate stale in-process session: ${$}`)}m.delete(c),await A(c)}else{d.info(`[search-orphan] Terminating unreachable in-process SDK session: agentId=${e}, sessionId=${c}, status=${v||"unknown"}`);try{await g.abortCurrentTurn(c).catch(()=>{}),await g.terminateSession(c)}catch($){d.warn(`[search-orphan] Failed to terminate in-process session: ${$}`)}m.delete(c),await A(c)}}const p=await b(e);if(p){d.info(`[search-orphan] Found orphan process for agentId=${e}, pid=${p.pid}`),r.json({ok:!0,agentId:e,hasActiveSession:s,found:!0,orphan:{pid:p.pid,command:p.command,cwd:p.cwd,startedAt:p.startedAt,message:"Found orphan process. Click terminate to stop it."}});return}if(s&&t){d.info(`[search-orphan] Active session process still running, reporting as terminable orphan: agentId=${e}, pid=${t}`),r.json({ok:!0,agentId:e,hasActiveSession:!0,found:!0,orphan:{pid:t,command:a||"(active SDK session)",message:"Found active SDK session process. Click terminate to stop it."}});return}const u=await S(e);if(u?.pid&&await w(u.pid)){d.info(`[search-orphan] Found orphan by persisted PID: agentId=${e}, pid=${u.pid}`),r.json({ok:!0,agentId:e,hasActiveSession:s,found:!0,orphan:{pid:u.pid,command:u.command||"(persisted session)",message:"Found orphan process by persisted PID. Click terminate to stop it."}});return}const l=n||u?.workspacePath;if(l){const c=await F(l);if(c){d.info(`[search-orphan] Found orphan by workspace: agentId=${e}, pid=${c.pid}, workspace=${l}`),r.json({ok:!0,agentId:e,hasActiveSession:s,found:!0,orphan:{pid:c.pid,command:c.command,message:"Found orphan process by workspace path. Click terminate to stop it."}});return}}d.info(`[search-orphan] No orphan process found for agentId=${e}, hasActiveSession=${!!s}`),r.json({ok:!0,agentId:e,hasActiveSession:!!s,found:!1,orphan:null,message:s?"Agent has active session in runtime-bridge":"No orphan process and no active session found"})}catch(o){const s=o;d.error("[search-orphan] Error:",s),r.status(500).json({error:s.message})}}),h.post("/terminate-orphan",I,async(i,r)=>{const{agentId:e,pid:n}=i.body;if(!e||!n){r.status(400).json({error:"agentId and pid are required"});return}try{const o=Array.from(m.entries()).find(([,a])=>a.agentId===e);if(o){const[a,p]=o,u=y.get(p.providerId||"claude-code");try{await u.terminateSession(a)}catch(l){d.warn(`[terminate-orphan] Failed to terminate SDK session for agentId=${e}:`,l)}m.delete(a),await A(a),d.info(`[terminate-orphan] Cleaned up SDK session for agentId=${e}, sessionId=${a}`)}if(!await w(n)){r.json({ok:!0,agentId:e,pid:n,terminated:!1,message:"Process already terminated"});return}const s=process.platform;let t=!1;if(s==="win32")try{R(`taskkill /PID ${n} /T /F`,{encoding:"utf8",timeout:5e3}),t=!0}catch(a){d.warn(`[terminate-orphan] taskkill failed for pid=${n}:`,a)}else try{process.kill(n,"SIGTERM"),t=!0}catch(a){d.warn(`[terminate-orphan] kill failed for pid=${n}:`,a)}t?(d.info(`[terminate-orphan] Terminated orphan process for agentId=${e}, pid=${n}`),r.json({ok:!0,agentId:e,pid:n,terminated:!0,message:"Orphan process terminated successfully"})):r.json({ok:!0,agentId:e,pid:n,terminated:!1,message:"Failed to terminate process"})}catch(o){const s=o;d.error("[terminate-orphan] Error:",s),r.status(500).json({error:s.message})}}),h.get("/sessions/by-agent/:agentId",I,async(i,r)=>{const e=i.params.agentId,n=Array.isArray(e)?e[0]:e;if(!n){r.status(400).json({error:"agentId is required"});return}try{const o=Array.from(m.entries()).find(([,t])=>t.agentId===n);if(o){const t=y.get(o[1].providerId||"claude-code"),a=t.getSessionPid?.(o[0]),p=j(t.getSessionStatus(o[0]),o[1].currentRuntimeStatus,o[1].currentRuntimeActionType);r.json({ok:!0,sessionId:o[0],agentId:n,workspacePath:o[1].workspacePath,status:p,runtimeStatus:p,isActive:!0,mode:"sdk",pid:a,isManaged:!0,providerId:o[1].providerId});return}const s=await S(n);if(s){const{isProcessRunning:t}=await import("../services/process-detector.js"),a=s.pid?await t(s.pid):!1;r.json({ok:!0,sessionId:s.sessionId,agentId:n,workspacePath:s.workspacePath,command:s.command,status:a?"orphan":"stopped",runtimeStatus:s.runtimeStatus,runtimeActionType:s.runtimeActionType,runtimeActionLabel:s.runtimeActionLabel,runtimeActionDetail:s.runtimeActionDetail,startedAt:s.startedAt,isActive:!1,mode:s.mode,pid:s.pid,isManaged:!1,isProcessAlive:a,isOrphan:a});return}r.json({ok:!0,agentId:n,status:"none",isActive:!1,isManaged:!1})}catch(o){const s=o;d.error("[sessions/by-agent] Error:",s),r.status(500).json({error:s.message})}}),h.post("/takeover-session",I,async(i,r)=>{const{agentId:e}=i.body;if(!e){r.status(400).json({error:"agentId is required"});return}try{const n=Array.from(m.entries()).find(([,t])=>t.agentId===e);if(n){r.json({ok:!0,agentId:e,sessionId:n[0],mode:"sdk",status:"running",isActive:!0,recovered:!1,message:"SDK session already active"});return}const o=await S(e);if(!o){r.status(404).json({error:"No persisted session found for this agentId",agentId:e});return}let s=!1;if(o.mode==="sdk"&&(s=!!await b(e),!s&&o.pid&&(s=await w(o.pid))),!s){d.info(`[takeover-session] Process not alive for agentId=${e}, mode=${o.mode}`),r.json({ok:!1,agentId:e,status:"process_not_alive",isActive:!1,message:"Agent process is no longer running"});return}if(d.info(`[takeover-session] Taking over session for agentId=${e}, mode=${o.mode}, pid=${o.pid}`),o.mode==="sdk"){const t=await b(e);t?(d.info(`[takeover-session] Found SDK process for agentId=${e}, pid=${t.pid}`),r.json({ok:!0,agentId:e,sessionId:o.sessionId,mode:"sdk",status:"running",isActive:!0,recovered:!0,pid:t.pid||o.pid,message:"SDK session process found, can be taken over by aws-mcp-server"})):r.json({ok:!1,agentId:e,status:"process_not_alive",isActive:!1,message:"SDK process not found"})}else r.status(410).json({error:"Session takeover is no longer supported; start a new SDK runtime session.",agentId:e,mode:"sdk"})}catch(n){const o=n;d.error("[takeover-session] Error:",o),r.status(500).json({error:o.message})}}),h.post("/terminate-tree",I,async(i,r)=>{const{agentId:e,sessionId:n}=i.body;if(!e){r.status(400).json({error:"agentId is required"});return}try{let o=n;if(!o){const f=await S(e);if(!f){r.status(404).json({error:"Session not found for this agentId"});return}o=f.sessionId}const s=m.get(o);let t,a;if(s)t=y.get(s.providerId||"claude-code").getSessionPid?.(o),a="sdk";else{const f=await S(e);if(!f?.pid){r.status(404).json({error:"Session PID not found"});return}t=f.pid,a=f.mode||"sdk"}const{terminateProcessTree:p,waitForProcessExit:u}=await import("../services/process-detector.js");if(!t){r.status(404).json({error:"PID not found"});return}const l=await p(t),c=await u(t,5e3);L(e),await import("../services/terminal-persistence.js").then(f=>f.removePersistedSession(o)),d.info(`[terminate-tree] Terminated process tree for agentId=${e}, pid=${t}, mode=${a}, terminated=${l.terminated}, failed=${l.failed}, exited=${c}`),r.json({ok:!0,agentId:e,pid:t,mode:a,terminated:l.terminated,failed:l.failed,exited:c,message:c?`Successfully terminated ${l.terminated} processes`:`Terminated ${l.terminated} processes, but process ${t} still running`})}catch(o){const s=o;d.error("[terminate-tree] Error:",s),r.status(500).json({error:s.message})}}),h.get("/health/:agentId",I,async(i,r)=>{const e=i.params.agentId,n=Array.isArray(e)?e[0]:e;if(!n){r.status(400).json({error:"agentId is required"});return}try{const o=await S(n);if(!o){r.status(404).json({error:"Session not found"});return}const s=m.get(o.sessionId),t=!!s,{checkProcessHealth:a}=await import("../services/process-detector.js"),p={sessionId:o.sessionId,mode:o.mode,workspacePath:o.workspacePath,isManaged:t,isActive:!!s};if(o.pid){const u=await a(o.pid,n);Object.assign(p,u)}else Object.assign(p,{pid:0,alive:!1,cpu:0,memoryMB:0,status:"dead",lastUpdate:new Date});r.json({agentId:n,...p})}catch(o){const s=o;d.error("[health] Error:",s),r.status(500).json({error:s.message})}});export{B as handleCapabilityToolCallRequest,x as handleCapabilityToolsRequest,j as resolveActiveSdkSessionSnapshotStatus,h as sessionsRouter};
|
|
1
|
+
import{execSync as R}from"node:child_process";import{Router as C}from"express";import{adapterRegistry as I}from"../adapter/index.js";import{validateToken as h,validateTokenOrLoopback as b}from"../middleware/auth.js";import{isProcessRunning as A,findOrphanProcessByAgentId as $,findOrphanProcessByWorkspace as L}from"../services/process-detector.js";import{findPersistedSessionByAgentId as S,loadPersistedSessions as F,removePersistedSession as w}from"../services/terminal-persistence.js";import{createLogger as E}from"../utils/logger.js";import{sdkSessions as m,cleanupSdkSessionByAgentId as K}from"./terminal.js";const d=E("sessions"),y=C();y.post("/sessions/:agentId/notify-force-message",b,(i,r)=>{const e=String(i.params.agentId??"").trim();if(!e){r.status(400).json({ok:!1,error:"agentId is required"});return}const n=Array.from(m.entries()).find(([,a])=>a.agentId===e);if(!n){r.json({ok:!0,notified:!1,message:"No active SDK session for this agentId"});return}const[o,t]=n,s=I.get(t.providerId||"claude-code");if(typeof s.notifyForceMessage=="function"){const a=s.notifyForceMessage(o);r.json({ok:!0,notified:a})}else r.json({ok:!0,notified:!1,message:"Adapter does not support force message notification"})}),y.post("/sessions/:agentId/capability-tools",b,async(i,r)=>{const e=String(i.params.agentId??"").trim(),n=()=>{const t=Array.from(m.entries()).find(([,s])=>s.agentId===e);return t?{agentId:e,providerId:t[1].providerId||""}:void 0},o=await B({agentId:e,capability:String(i.body?.capability??""),action:i.body?.action,resolveSession:n,resolveAdapter:t=>I.get(t||"claude-code")});r.status(o.status).json(o.body)}),y.post("/sessions/:agentId/capability-tools/call",b,async(i,r)=>{const e=String(i.params.agentId??"").trim(),n=()=>{const t=Array.from(m.entries()).find(([,s])=>s.agentId===e);return t?{agentId:e,providerId:t[1].providerId||""}:void 0},o=await x({agentId:e,capability:String(i.body?.capability??""),tool:String(i.body?.tool??""),args:i.body?.args??{},resolveSession:n,resolveAdapter:t=>I.get(t||"claude-code")});r.status(o.status).json(o.body)});const T=new Set(["browser","desktop"]);async function B(i){const r=String(i.agentId??"").trim();if(!r)return{status:400,body:{ok:!1,error:"agentId is required"}};const e=String(i.capability??"").trim();if(!T.has(e))return{status:400,body:{ok:!1,error:'capability must be "browser" or "desktop"'}};const n=i.action;if(n!=="expand"&&n!=="collapse")return{status:400,body:{ok:!1,error:`action must be "expand" or "collapse", got: ${String(n)}`}};const o=i.resolveSession();if(!o)return{status:200,body:{ok:!0,changed:{sessions:0,tools:0}}};const t=i.resolveAdapter?.(o.providerId);if(!t||typeof t.setBuiltInCapabilityTools!="function")return{status:200,body:{ok:!0,changed:{sessions:0,tools:0},message:`Adapter for provider "${o.providerId}" does not support setBuiltInCapabilityTools`}};try{const s=await t.setBuiltInCapabilityTools(r,e,n),a={ok:!0,changed:{sessions:s.sessions,tools:s.tools}};return n==="expand"&&Array.isArray(s.manifests)&&(a.manifests=s.manifests),{status:200,body:a}}catch(s){const a=s instanceof Error?s.message:String(s);return d.error(`capability-tools ${n} failed for agent ${r}: ${a}`),{status:500,body:{ok:!1,error:a}}}}async function x(i){const r=String(i.agentId??"").trim();if(!r)return{status:400,body:{ok:!1,error:"agentId is required"}};const e=String(i.capability??"").trim();if(!T.has(e))return{status:400,body:{ok:!1,error:'capability must be "browser" or "desktop"'}};const n=String(i.tool??"").trim();if(!n)return{status:400,body:{ok:!1,error:"tool is required"}};const o=i.resolveSession();if(!o)return{status:200,body:{ok:!1,error:`No active SDK session for agentId "${r}"`}};const t=i.resolveAdapter?.(o.providerId);if(!t||typeof t.callBuiltInCapabilityTool!="function")return{status:200,body:{ok:!1,error:`Adapter for provider "${o.providerId}" does not support callBuiltInCapabilityTool`}};try{return{status:200,body:await t.callBuiltInCapabilityTool(r,e,n,i.args??{})}}catch(s){const a=s instanceof Error?s.message:String(s);return d.error(`capability-tools/call ${n} failed for agent ${r}: ${a}`),{status:500,body:{ok:!1,error:a}}}}function P(i,r,e){const n=String(i||"").trim();if(n){const t=String(r||"").trim(),s=String(e||"").trim().toLowerCase();return n.toLowerCase()==="tool_using"&&t.toLowerCase()==="waiting_input"&&s==="idle"?t:n}return String(r||"").trim()||"running"}y.get("/sessions",h,async(i,r)=>{try{const n=Array.from(m.entries()).map(([u,p])=>{const l=I.get(p.providerId||"claude-code"),c=P(l.getSessionStatus(u),p.currentRuntimeStatus,p.currentRuntimeActionType);return{sessionId:u,agentId:p.agentId,workspacePath:p.workspacePath,status:c,runtimeStatus:c,runtimeActionType:p.currentRuntimeActionType,runtimeActionLabel:p.currentRuntimeActionLabel,runtimeActionDetail:p.currentRuntimeActionDetail,mode:"sdk",startedAt:null}}),o=await F(),t=new Set(n.map(u=>u.sessionId)),s=o.filter(u=>!t.has(u.sessionId)),a={ok:!0,active:n,persisted:s};r.json(a)}catch(e){const n=e;r.status(500).json({error:n.message})}}),y.post("/sessions/recover",h,async(i,r)=>{const{agentId:e,workspacePath:n,command:o}=i.body;if(!e){r.status(400).json({error:"agentId is required"});return}try{const t=Array.from(m.entries()).find(([,g])=>g.agentId===e);if(t){const g=I.get(t[1].providerId||"claude-code"),k=P(g.getSessionStatus(t[0]),t[1].currentRuntimeStatus,t[1].currentRuntimeActionType);r.json({ok:!0,sessionId:t[0],agentId:e,workspacePath:t[1].workspacePath,command:t[1].config.command,status:k,runtimeStatus:k,runtimeActionType:t[1].currentRuntimeActionType,runtimeActionLabel:t[1].currentRuntimeActionLabel,runtimeActionDetail:t[1].currentRuntimeActionDetail,mode:"sdk",recovered:!1,message:"SDK session already active"});return}const s=await S(e);let a=!1,u;if(s?.pid&&await A(s.pid))a=!0,u=s.pid,d.info(`[Recover] Detected orphan process for agentId=${e}, pid=${s.pid}`);else if(s?.mode==="sdk"||!s?.pid){const g=await $(e);g&&(a=!0,u=g.pid,d.info(`[Recover] Found orphan process by agentId search: agentId=${e}, pid=${g.pid}`))}const p=n||s?.workspacePath,l=o||s?.command||"acode",c=s?.mode||"sdk";if(!p){r.status(400).json({error:"workspacePath is required (not found in persisted session)"});return}if(a&&u){d.info(`[Recover] Returning orphan process info for agentId=${e}`),r.json({ok:!0,sessionId:s?.sessionId||"",agentId:e,workspacePath:p,command:l,status:"orphan_detected",runtimeStatus:s?.runtimeStatus,runtimeActionType:s?.runtimeActionType,runtimeActionLabel:s?.runtimeActionLabel,runtimeActionDetail:s?.runtimeActionDetail,recovered:!1,orphan:{pid:u,message:"Found orphan process still running. Manual intervention may be required."},mode:c});return}await w(s?.sessionId||"");const f={ok:!1,sessionId:s?.sessionId||"",agentId:e,workspacePath:p,command:l,status:"stopped",recovered:!1,message:"No active SDK session found; start a new SDK runtime session instead."};r.json(f)}catch(t){const s=t;d.error("Error:",s),r.status(500).json({error:s.message})}}),y.post("/search-orphan",h,async(i,r)=>{const{agentId:e,workspacePath:n}=i.body;if(!e){r.status(400).json({error:"agentId is required"});return}try{const o=Array.from(m.entries()).find(([,c])=>c.agentId===e);let t=!1,s,a;if(o){const[c,f]=o,g=I.get(f.providerId||"claude-code");s=g.getSessionPid?.(c),a=f.config?.command;const k=s?await A(s):!1,v=g.getSessionStatus(c),D=v==="completed"||v==="terminated"||v==="error";if(k)t=!0;else if(s&&!k)d.info(`[search-orphan] Cleaning up stale SDK session (process dead): agentId=${e}, sessionId=${c}, pid=${s}`),m.delete(c),await w(c);else if(D){d.info(`[search-orphan] Cleaning up stale in-process SDK session (status=${v}): agentId=${e}, sessionId=${c}`);try{await g.terminateSession(c)}catch(j){d.warn(`[search-orphan] Failed to terminate stale in-process session: ${j}`)}m.delete(c),await w(c)}else{d.info(`[search-orphan] Terminating unreachable in-process SDK session: agentId=${e}, sessionId=${c}, status=${v||"unknown"}`);try{await g.abortCurrentTurn(c).catch(()=>{}),await g.terminateSession(c)}catch(j){d.warn(`[search-orphan] Failed to terminate in-process session: ${j}`)}m.delete(c),await w(c)}}const u=await $(e);if(u){d.info(`[search-orphan] Found orphan process for agentId=${e}, pid=${u.pid}`),r.json({ok:!0,agentId:e,hasActiveSession:t,found:!0,orphan:{pid:u.pid,command:u.command,cwd:u.cwd,startedAt:u.startedAt,message:"Found orphan process. Click terminate to stop it."}});return}if(t&&s){d.info(`[search-orphan] Active session process still running, reporting as terminable orphan: agentId=${e}, pid=${s}`),r.json({ok:!0,agentId:e,hasActiveSession:!0,found:!0,orphan:{pid:s,command:a||"(active SDK session)",message:"Found active SDK session process. Click terminate to stop it."}});return}const p=await S(e);if(p?.pid&&await A(p.pid)){d.info(`[search-orphan] Found orphan by persisted PID: agentId=${e}, pid=${p.pid}`),r.json({ok:!0,agentId:e,hasActiveSession:t,found:!0,orphan:{pid:p.pid,command:p.command||"(persisted session)",message:"Found orphan process by persisted PID. Click terminate to stop it."}});return}const l=n||p?.workspacePath;if(l){const c=await L(l);if(c){d.info(`[search-orphan] Found orphan by workspace: agentId=${e}, pid=${c.pid}, workspace=${l}`),r.json({ok:!0,agentId:e,hasActiveSession:t,found:!0,orphan:{pid:c.pid,command:c.command,message:"Found orphan process by workspace path. Click terminate to stop it."}});return}}d.info(`[search-orphan] No orphan process found for agentId=${e}, hasActiveSession=${!!t}`),r.json({ok:!0,agentId:e,hasActiveSession:!!t,found:!1,orphan:null,message:t?"Agent has active session in runtime-bridge":"No orphan process and no active session found"})}catch(o){const t=o;d.error("[search-orphan] Error:",t),r.status(500).json({error:t.message})}}),y.post("/terminate-orphan",h,async(i,r)=>{const{agentId:e,pid:n}=i.body;if(!e||!n){r.status(400).json({error:"agentId and pid are required"});return}try{const o=Array.from(m.entries()).find(([,a])=>a.agentId===e);if(o){const[a,u]=o,p=I.get(u.providerId||"claude-code");try{await p.terminateSession(a)}catch(l){d.warn(`[terminate-orphan] Failed to terminate SDK session for agentId=${e}:`,l)}m.delete(a),await w(a),d.info(`[terminate-orphan] Cleaned up SDK session for agentId=${e}, sessionId=${a}`)}if(!await A(n)){r.json({ok:!0,agentId:e,pid:n,terminated:!1,message:"Process already terminated"});return}const t=process.platform;let s=!1;if(t==="win32")try{R(`taskkill /PID ${n} /T /F`,{encoding:"utf8",timeout:5e3}),s=!0}catch(a){d.warn(`[terminate-orphan] taskkill failed for pid=${n}:`,a)}else try{process.kill(n,"SIGTERM"),s=!0}catch(a){d.warn(`[terminate-orphan] kill failed for pid=${n}:`,a)}s?(d.info(`[terminate-orphan] Terminated orphan process for agentId=${e}, pid=${n}`),r.json({ok:!0,agentId:e,pid:n,terminated:!0,message:"Orphan process terminated successfully"})):r.json({ok:!0,agentId:e,pid:n,terminated:!1,message:"Failed to terminate process"})}catch(o){const t=o;d.error("[terminate-orphan] Error:",t),r.status(500).json({error:t.message})}}),y.get("/sessions/:agentId/current-action",b,(i,r)=>{const e=i.params.agentId,n=Array.isArray(e)?e[0]:e;if(!n){r.status(400).json({ok:!1,error:"agentId is required"});return}const o=Array.from(m.entries()).find(([,a])=>a.agentId===n)?.[1];if(!o){r.json({ok:!0,found:!1});return}const t=I.get(o.providerId||"claude-code"),s=typeof t.hasActiveBlockingToolCall=="function"?t.hasActiveBlockingToolCall(o.sessionId)===!0:!1;r.json({ok:!0,found:!0,hasActiveBlockingToolCall:s,runtimeStatus:o.currentRuntimeStatus,runtimeActionType:o.currentRuntimeActionType,runtimeActionLabel:o.currentRuntimeActionLabel,runtimeActionDetail:o.currentRuntimeActionDetail})}),y.get("/sessions/by-agent/:agentId",h,async(i,r)=>{const e=i.params.agentId,n=Array.isArray(e)?e[0]:e;if(!n){r.status(400).json({error:"agentId is required"});return}try{const o=Array.from(m.entries()).find(([,s])=>s.agentId===n);if(o){const s=I.get(o[1].providerId||"claude-code"),a=s.getSessionPid?.(o[0]),u=P(s.getSessionStatus(o[0]),o[1].currentRuntimeStatus,o[1].currentRuntimeActionType);r.json({ok:!0,sessionId:o[0],agentId:n,workspacePath:o[1].workspacePath,status:u,runtimeStatus:u,isActive:!0,mode:"sdk",pid:a,isManaged:!0,providerId:o[1].providerId});return}const t=await S(n);if(t){const{isProcessRunning:s}=await import("../services/process-detector.js"),a=t.pid?await s(t.pid):!1;r.json({ok:!0,sessionId:t.sessionId,agentId:n,workspacePath:t.workspacePath,command:t.command,status:a?"orphan":"stopped",runtimeStatus:t.runtimeStatus,runtimeActionType:t.runtimeActionType,runtimeActionLabel:t.runtimeActionLabel,runtimeActionDetail:t.runtimeActionDetail,startedAt:t.startedAt,isActive:!1,mode:t.mode,pid:t.pid,isManaged:!1,isProcessAlive:a,isOrphan:a});return}r.json({ok:!0,agentId:n,status:"none",isActive:!1,isManaged:!1})}catch(o){const t=o;d.error("[sessions/by-agent] Error:",t),r.status(500).json({error:t.message})}}),y.post("/takeover-session",h,async(i,r)=>{const{agentId:e}=i.body;if(!e){r.status(400).json({error:"agentId is required"});return}try{const n=Array.from(m.entries()).find(([,s])=>s.agentId===e);if(n){r.json({ok:!0,agentId:e,sessionId:n[0],mode:"sdk",status:"running",isActive:!0,recovered:!1,message:"SDK session already active"});return}const o=await S(e);if(!o){r.status(404).json({error:"No persisted session found for this agentId",agentId:e});return}let t=!1;if(o.mode==="sdk"&&(t=!!await $(e),!t&&o.pid&&(t=await A(o.pid))),!t){d.info(`[takeover-session] Process not alive for agentId=${e}, mode=${o.mode}`),r.json({ok:!1,agentId:e,status:"process_not_alive",isActive:!1,message:"Agent process is no longer running"});return}if(d.info(`[takeover-session] Taking over session for agentId=${e}, mode=${o.mode}, pid=${o.pid}`),o.mode==="sdk"){const s=await $(e);s?(d.info(`[takeover-session] Found SDK process for agentId=${e}, pid=${s.pid}`),r.json({ok:!0,agentId:e,sessionId:o.sessionId,mode:"sdk",status:"running",isActive:!0,recovered:!0,pid:s.pid||o.pid,message:"SDK session process found, can be taken over by aws-mcp-server"})):r.json({ok:!1,agentId:e,status:"process_not_alive",isActive:!1,message:"SDK process not found"})}else r.status(410).json({error:"Session takeover is no longer supported; start a new SDK runtime session.",agentId:e,mode:"sdk"})}catch(n){const o=n;d.error("[takeover-session] Error:",o),r.status(500).json({error:o.message})}}),y.post("/terminate-tree",h,async(i,r)=>{const{agentId:e,sessionId:n}=i.body;if(!e){r.status(400).json({error:"agentId is required"});return}try{let o=n;if(!o){const f=await S(e);if(!f){r.status(404).json({error:"Session not found for this agentId"});return}o=f.sessionId}const t=m.get(o);let s,a;if(t)s=I.get(t.providerId||"claude-code").getSessionPid?.(o),a="sdk";else{const f=await S(e);if(!f?.pid){r.status(404).json({error:"Session PID not found"});return}s=f.pid,a=f.mode||"sdk"}const{terminateProcessTree:u,waitForProcessExit:p}=await import("../services/process-detector.js");if(!s){r.status(404).json({error:"PID not found"});return}const l=await u(s),c=await p(s,5e3);K(e),await import("../services/terminal-persistence.js").then(f=>f.removePersistedSession(o)),d.info(`[terminate-tree] Terminated process tree for agentId=${e}, pid=${s}, mode=${a}, terminated=${l.terminated}, failed=${l.failed}, exited=${c}`),r.json({ok:!0,agentId:e,pid:s,mode:a,terminated:l.terminated,failed:l.failed,exited:c,message:c?`Successfully terminated ${l.terminated} processes`:`Terminated ${l.terminated} processes, but process ${s} still running`})}catch(o){const t=o;d.error("[terminate-tree] Error:",t),r.status(500).json({error:t.message})}}),y.get("/health/:agentId",h,async(i,r)=>{const e=i.params.agentId,n=Array.isArray(e)?e[0]:e;if(!n){r.status(400).json({error:"agentId is required"});return}try{const o=await S(n);if(!o){r.status(404).json({error:"Session not found"});return}const t=m.get(o.sessionId),s=!!t,{checkProcessHealth:a}=await import("../services/process-detector.js"),u={sessionId:o.sessionId,mode:o.mode,workspacePath:o.workspacePath,isManaged:s,isActive:!!t};if(o.pid){const p=await a(o.pid,n);Object.assign(u,p)}else Object.assign(u,{pid:0,alive:!1,cpu:0,memoryMB:0,status:"dead",lastUpdate:new Date});r.json({agentId:n,...u})}catch(o){const t=o;d.error("[health] Error:",t),r.status(500).json({error:t.message})}});export{x as handleCapabilityToolCallRequest,B as handleCapabilityToolsRequest,P as resolveActiveSdkSessionSnapshotStatus,y as sessionsRouter};
|
|
2
2
|
|
package/dist/routes/skills.d.ts
CHANGED
package/dist/routes/skills.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Router as
|
|
1
|
+
import{Router as j}from"express";import{raw as h}from"express";import{validateToken as a}from"../middleware/auth.js";import{assertAgentOwnership as v}from"../services/agent-ownership.js";import{getEffective as b,setDefault as I,setInherited as N,setOverride as w}from"../services/capability-config.js";import{SkillManager as u,isValidSkillName as y}from"../services/skill-manager.js";import{getUserScopeOrThrow as r,requireUserScope as c}from"../services/user-scope.js";import{createLogger as B}from"../utils/logger.js";const z=B("skills"),d=j();function f(s){return(e,t)=>{s(e,t).catch(o=>{if(z.error("[skills] %s %s \u5931\u8D25: %s",e.method,e.path,o.message),!t.headersSent){const n=o.message.includes("agent-ownership-mismatch")?403:500;t.status(n).json({ok:!1,error:o.message})}})}}function m(s,e,t){const o=r(s);return v(t,o)?!0:(e.status(403).json({ok:!1,error:"agent-ownership-mismatch",message:"\u8BE5\u5B9E\u4F8B\u4E0D\u5C5E\u4E8E\u5F53\u524D\u7528\u6237"}),!1)}d.post("/skills/deployed/list",a,c,f(async(s,e)=>{const t=r(s),i=u.forScope(t).listDeployed().map(l=>({...l,enabled:b(t,"","skills",l.skillName)}));e.json({ok:!0,deployedSkills:i})})),d.get("/skills/deployed",a,c,f(async(s,e)=>{const t=r(s),i=u.forScope(t).listDeployed().map(l=>({...l,enabled:b(t,"","skills",l.skillName)}));e.json({ok:!0,deployedSkills:i})})),d.post("/skills/deployed/default",a,c,f(async(s,e)=>{const t=r(s),o=String((s.body??{})?.skillName??"").trim();if(!y(o)){e.status(400).json({ok:!1,error:"skillName \u975E\u6CD5"});return}const n=String((s.body??{})?.agentId??"").trim();if(n&&!m(s,e,n))return;const i=(s.body??{})?.enabled,l=i==null?null:!!i;n?w(t,n,"skills",o,l):I(t,"skills",o,l),e.json({ok:!0,skillName:o,agentId:n,enabled:l})})),d.post("/skills/deployed/inherited",a,c,f(async(s,e)=>{const t=r(s),o=String((s.body??{})?.agentId??"").trim();if(!o){e.status(400).json({ok:!1,error:"agentId is required"});return}if(!m(s,e,o))return;const n=(s.body??{})?.map;N(t,o,"skills",n??null),e.json({ok:!0,agentId:o,count:Object.keys(n??{}).length})})),d.post("/skills/deployed/upload",a,c,h({type:"application/zip",limit:"200mb"}),f(async(s,e)=>{const t=r(s),o=s.body??{},n=Buffer.isBuffer(o)?o:Buffer.from(o??"");if(!n||n.length===0){e.status(400).json({ok:!1,error:"zip \u5185\u5BB9\u4E3A\u7A7A"});return}const i=String(s.query.filename??s.headers["x-filename"]??"skill.zip"),l=String(s.query.sha256??"").trim()||void 0,k=s.query.defaultEnabled!=="false",p=await u.forScope(t).saveSharedSkill(n,String(i),k,l);e.status(p.ok?200:400).json(p)})),d.post("/skills/deployed/remove",a,c,f(async(s,e)=>{const t=r(s),o=String((s.body??{})?.skillName??"").trim();if(!y(o)){e.status(400).json({ok:!1,error:"skillName \u975E\u6CD5"});return}const n=await u.forScope(t).removeDeployedSkill(o);e.status(n.ok?200:400).json(n)})),d.post("/skills/private/:agentId/upload",a,c,h({type:()=>!0,limit:"200mb"}),f(async(s,e)=>{const t=String(s.params.agentId??"").trim();if(!t){e.status(400).json({ok:!1,error:"agentId is required"});return}if(!m(s,e,t))return;const o=r(s),n=s.body;if(!Buffer.isBuffer(n)||n.length===0){e.status(400).json({ok:!1,error:"zip \u5185\u5BB9\u4E3A\u7A7A"});return}const i=s.query,l=String(i.filename??s.headers["x-filename"]??"skill.zip"),k=String(i.sha256??"").trim()||void 0,p=String(i.skillName??"").trim()||void 0,g=await u.forScope(o).savePrivateSkill(t,n,l,k,p);e.status(g.ok?200:400).json(g)})),d.post("/skills/private/:agentId/save",a,c,f(async(s,e)=>{const t=String(s.params.agentId??"").trim();if(!t){e.status(400).json({ok:!1,error:"agentId is required"});return}if(!m(s,e,t))return;const o=r(s),n=s.body??{},i=String(n.contentBase64??""),l=Buffer.from(i,"base64");if(l.length===0){e.status(400).json({ok:!1,error:"contentBase64 \u4E3A\u7A7A"});return}const k=String(n.fileName??"skill.zip"),p=String(n.sha256??"").trim()||void 0,g=String(n.skillName??"").trim()||void 0,S=await u.forScope(o).savePrivateSkill(t,l,k,p,g);e.status(S.ok?200:400).json(S)})),d.post("/skills/private/:agentId/remove",a,c,f(async(s,e)=>{const t=String(s.params.agentId??"").trim(),o=String((s.body??{})?.skillName??"").trim();if(!t||!y(o)){e.status(400).json({ok:!1,error:"agentId \u4E0E skillName \u5FC5\u586B"});return}if(!m(s,e,t))return;const n=r(s),i=await u.forScope(n).removePrivateSkill(t,o);e.status(i.ok?200:400).json(i)})),d.post("/skills/private/:agentId/list",a,c,f(async(s,e)=>{const t=String(s.params.agentId??"").trim();if(!t){e.status(400).json({ok:!1,error:"agentId is required"});return}if(!m(s,e,t))return;const o=r(s);e.json({ok:!0,agentId:t,privateSkills:u.forScope(o).listPrivateSkills(t)})})),d.post("/skills/cc-switch/list",a,c,f(async(s,e)=>{e.json({ok:!0,skills:[],state:{skills:[],mcpServers:[]}})}));export{d as skillsRouter};
|
|
2
2
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{Router as m}from"express";import{validateToken as c}from"../middleware/auth.js";import{
|
|
1
|
+
import{Router as m}from"express";import{validateToken as c}from"../middleware/auth.js";import{subAgentManager as u,subAgentStore as g}from"../services/sub-agent-manager-instance.js";import{createLogger as f}from"../utils/logger.js";import{noteDashboardActivity as l}from"./dashboard.js";const b=f("sub-agents"),p=m();p.get("/sub-agents/:agentId",c,async(r,t)=>{const s=String(r.params.agentId??"");if(!s.trim()){t.status(400).json({ok:!1,error:"agentId is required"});return}try{const e=await g.list(s),n=u.listActiveByParent(s),o=new Set(n.map(a=>a.subId)),i=n.map(a=>({subId:a.subId,parentAgentId:a.parentAgentId,parentSessionId:a.parentSessionId,subagentType:a.subagentType,description:a.description,prompt:a.prompt,status:a.status,startedAt:a.startedAt,contextSnapshot:a.contextSnapshot,availableTools:a.availableTools})),d=e.filter(a=>!o.has(a.subId)&&a.status!=="running"&&a.status!=="pending"),I=await g.read(s);t.json({ok:!0,agentId:s,updatedAt:I.updatedAt,running:i,history:d})}catch(e){const n=e;b.error("[sub-agents] \u5217\u8868\u5931\u8D25: %s",n.message),t.status(500).json({ok:!1,error:n.message})}}),p.get("/sub-agents/:agentId/events",c,async(r,t)=>{l();const s=String(r.params.agentId??"");if(!s.trim()){t.status(400).json({ok:!1,error:"agentId is required"});return}t.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive","X-Accel-Buffering":"no"}),t.write(`: connected
|
|
2
2
|
|
|
3
3
|
`);const e=u.listActiveByParent(s);e.length>0&&t.write(`data: ${JSON.stringify({type:"snapshot",agentId:s,timestamp:new Date().toISOString(),data:{running:e.map(i=>({subId:i.subId,subagentType:i.subagentType,description:i.description,status:i.status,startedAt:i.startedAt}))}})}
|
|
4
4
|
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{Router as s}from"express";import{validateToken as c}from"../middleware/auth.js";import{scanTechStack as n}from"../services/tech-stack-scanner.js";import{createLogger as k}from"../utils/logger.js";const m=k("tech-stack"),p=s();p.post("/tech-stack/scan",c,async(e,r)=>{const t=e.body?.workspacePath;if(typeof t!="string"||!t.trim()){r.status(400).json({error:"workspacePath \u4E0D\u80FD\u4E3A\u7A7A"});return}try{const o=await n(t);r.json({ok:!0,...o})}catch(o){const a=o;m.warn(`[tech-stack/scan] workspacePath=${t} error=${a.message}`),r.status(400).json({error:a.message})}});export{p as techStackRouter};
|
|
2
|
+
|