nova-personal-agent-server 0.0.0-stage → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +30 -2
- package/bin/novapersonal-server.mjs +4 -0
- package/package.json +61 -4
- package/resources/endpointing/volcengine-v1/LICENSE.silero-vad.txt +21 -0
- package/resources/endpointing/volcengine-v1/MANIFEST.json +31 -0
- package/resources/endpointing/volcengine-v1/silence-16k-s16le.pcm +0 -0
- package/resources/endpointing/volcengine-v1/speech-16k-s16le.pcm +0 -0
- package/resources/native/codex-sandbox-probe +0 -0
- package/resources/native/project-native/nova_project_native.node +0 -0
- package/resources/native-resources-v1.json +1 -0
- package/runtime/dist/eval/demos.js +156 -0
- package/runtime/dist/eval/fixture-host.js +385 -0
- package/runtime/dist/eval/fixtures.js +319 -0
- package/runtime/dist/eval/realtime/session-fixtures.js +474 -0
- package/runtime/dist/eval/scorecard.js +285 -0
- package/runtime/dist/eval/sim.js +43 -0
- package/runtime/dist/src/cascaded-text-provider.js +31 -0
- package/runtime/dist/src/cli.js +96 -0
- package/runtime/dist/src/composition/assembly.js +352 -0
- package/runtime/dist/src/composition/cascaded-realtime-assembly.js +455 -0
- package/runtime/dist/src/composition/production-composition.js +389 -0
- package/runtime/dist/src/composition/realtime-assembly.js +1330 -0
- package/runtime/dist/src/config/capability-registry.js +315 -0
- package/runtime/dist/src/config/cascaded-realtime-config.js +146 -0
- package/runtime/dist/src/config/coding-backends.js +8 -0
- package/runtime/dist/src/config/coding-profiles.js +98 -0
- package/runtime/dist/src/config/config.js +857 -0
- package/runtime/dist/src/config/diagnostics.js +139 -0
- package/runtime/dist/src/config/environment-contract.js +202 -0
- package/runtime/dist/src/config/self-hosted.js +23 -0
- package/runtime/dist/src/connectors/composio/client.js +195 -0
- package/runtime/dist/src/connectors/composio/google.js +208 -0
- package/runtime/dist/src/connectors/composio/index.js +334 -0
- package/runtime/dist/src/connectors/feishu/cli.js +220 -0
- package/runtime/dist/src/connectors/feishu/index.js +980 -0
- package/runtime/dist/src/connectors/macos/calendar.js +35 -0
- package/runtime/dist/src/connectors/macos/mail.js +32 -0
- package/runtime/dist/src/connectors/macos/reader.js +62 -0
- package/runtime/dist/src/conversation-voice-provider.js +41 -0
- package/runtime/dist/src/core/approval-port.js +9 -0
- package/runtime/dist/src/core/approval.js +1328 -0
- package/runtime/dist/src/core/calls.js +35 -0
- package/runtime/dist/src/core/camera-session.js +32 -0
- package/runtime/dist/src/core/causal-runtime.js +650 -0
- package/runtime/dist/src/core/clock.js +139 -0
- package/runtime/dist/src/core/context-view.js +156 -0
- package/runtime/dist/src/core/effects.js +62 -0
- package/runtime/dist/src/core/events.js +217 -0
- package/runtime/dist/src/core/executor-diagnostic.js +9 -0
- package/runtime/dist/src/core/ids.js +32 -0
- package/runtime/dist/src/core/media-store.js +104 -0
- package/runtime/dist/src/core/memory.js +296 -0
- package/runtime/dist/src/core/pending-decision.js +64 -0
- package/runtime/dist/src/core/ports.js +125 -0
- package/runtime/dist/src/core/runtime.js +1459 -0
- package/runtime/dist/src/core/schedule-tools.js +15 -0
- package/runtime/dist/src/core/sims.js +186 -0
- package/runtime/dist/src/core/slots.js +97 -0
- package/runtime/dist/src/core/source-processing-instructions.js +3 -0
- package/runtime/dist/src/core/source-processing-tools.js +12 -0
- package/runtime/dist/src/core/suggestions.js +143 -0
- package/runtime/dist/src/core/task-tools.js +22 -0
- package/runtime/dist/src/core/tool-schema.js +212 -0
- package/runtime/dist/src/core/trace.js +34 -0
- package/runtime/dist/src/core/work-tools.js +94 -0
- package/runtime/dist/src/desktop/desktop-camera-source.js +31 -0
- package/runtime/dist/src/desktop/desktop-camera.js +281 -0
- package/runtime/dist/src/desktop/desktop-control.js +140 -0
- package/runtime/dist/src/desktop/desktop-progress.js +162 -0
- package/runtime/dist/src/desktop/desktop-session.js +2106 -0
- package/runtime/dist/src/desktop/desktop-tasks.js +80 -0
- package/runtime/dist/src/desktop/desktop-wire.js +605 -0
- package/runtime/dist/src/desktop/phone-desktop-entry.js +17 -0
- package/runtime/dist/src/desktop/startup-error.js +18 -0
- package/runtime/dist/src/desktop/workbench-acceptance.js +262 -0
- package/runtime/dist/src/desktop-entry.js +106 -0
- package/runtime/dist/src/desktop.js +1092 -0
- package/runtime/dist/src/executors/acp/backends.js +105 -0
- package/runtime/dist/src/executors/acp/mcp.js +81 -0
- package/runtime/dist/src/executors/acp/preflight.js +14 -0
- package/runtime/dist/src/executors/acp/process-owner.js +112 -0
- package/runtime/dist/src/executors/acp/transport.js +760 -0
- package/runtime/dist/src/executors/acp/windows-launch.js +68 -0
- package/runtime/dist/src/executors/agent-controller.js +244 -0
- package/runtime/dist/src/executors/autoglm.js +376 -0
- package/runtime/dist/src/executors/browser-device.js +102 -0
- package/runtime/dist/src/executors/browser.js +61 -0
- package/runtime/dist/src/executors/camera.js +101 -0
- package/runtime/dist/src/executors/chromium-frame-source.js +173 -0
- package/runtime/dist/src/executors/codex/adapter-live.js +292 -0
- package/runtime/dist/src/executors/codex/adapter-project.js +1306 -0
- package/runtime/dist/src/executors/codex/app-server-schema.js +712 -0
- package/runtime/dist/src/executors/codex/app-server-transport.js +1798 -0
- package/runtime/dist/src/executors/codex/approval-protocol.js +439 -0
- package/runtime/dist/src/executors/codex/common.js +655 -0
- package/runtime/dist/src/executors/codex/contract.js +581 -0
- package/runtime/dist/src/executors/codex/controller.js +141 -0
- package/runtime/dist/src/executors/codex/credential-snapshot.js +195 -0
- package/runtime/dist/src/executors/codex/factory.js +463 -0
- package/runtime/dist/src/executors/codex/host-config.js +238 -0
- package/runtime/dist/src/executors/codex/host.js +17 -0
- package/runtime/dist/src/executors/codex/index.js +19 -0
- package/runtime/dist/src/executors/codex/launch-profile.js +37 -0
- package/runtime/dist/src/executors/codex/local-sessions.js +119 -0
- package/runtime/dist/src/executors/codex/managed-mcp.js +196 -0
- package/runtime/dist/src/executors/codex/process-owner.js +398 -0
- package/runtime/dist/src/executors/codex/production-host.js +887 -0
- package/runtime/dist/src/executors/codex/progress-instructions.js +10 -0
- package/runtime/dist/src/executors/codex/protocol.js +581 -0
- package/runtime/dist/src/executors/codex/safe-json.js +87 -0
- package/runtime/dist/src/executors/codex/session-title.js +61 -0
- package/runtime/dist/src/executors/codex/shared-home.js +29 -0
- package/runtime/dist/src/executors/codex/spawn-env.js +162 -0
- package/runtime/dist/src/executors/codex/turn-projection.js +435 -0
- package/runtime/dist/src/executors/codex/version.js +38 -0
- package/runtime/dist/src/executors/codex/windows-guardian.js +716 -0
- package/runtime/dist/src/executors/coding/intake-model.js +103 -0
- package/runtime/dist/src/executors/coding/intake.js +824 -0
- package/runtime/dist/src/executors/coding/json-completion.js +14 -0
- package/runtime/dist/src/executors/coding/target-resolution.js +61 -0
- package/runtime/dist/src/executors/coding/work-order.js +50 -0
- package/runtime/dist/src/executors/coding-executor.js +23 -0
- package/runtime/dist/src/executors/computer-backend.js +188 -0
- package/runtime/dist/src/executors/computer-device.js +187 -0
- package/runtime/dist/src/executors/computer-worker.js +125 -0
- package/runtime/dist/src/executors/computer.js +100 -0
- package/runtime/dist/src/executors/device-lock.js +127 -0
- package/runtime/dist/src/executors/frame-source.js +29 -0
- package/runtime/dist/src/executors/gui-evidence.js +30 -0
- package/runtime/dist/src/executors/gui-execution.js +237 -0
- package/runtime/dist/src/executors/gui-runner.js +88 -0
- package/runtime/dist/src/executors/host-executor-capability.js +12 -0
- package/runtime/dist/src/executors/index.js +13 -0
- package/runtime/dist/src/executors/mcp-client.js +198 -0
- package/runtime/dist/src/executors/mcp.js +210 -0
- package/runtime/dist/src/executors/mobile-android.js +180 -0
- package/runtime/dist/src/executors/mobile-ios.js +303 -0
- package/runtime/dist/src/executors/mobile.js +78 -0
- package/runtime/dist/src/executors/search-mcp.js +146 -0
- package/runtime/dist/src/executors/search.js +524 -0
- package/runtime/dist/src/executors/task-resources.js +38 -0
- package/runtime/dist/src/executors/vision/assess.js +296 -0
- package/runtime/dist/src/executors/vision/controller-core.js +373 -0
- package/runtime/dist/src/executors/vision/controller.js +164 -0
- package/runtime/dist/src/executors/vision/lifecycle.js +69 -0
- package/runtime/dist/src/executors/vision.js +5 -0
- package/runtime/dist/src/executors/watcher.js +718 -0
- package/runtime/dist/src/http/bounded-response.js +37 -0
- package/runtime/dist/src/index.js +56 -0
- package/runtime/dist/src/knowledge/assembly.js +60 -0
- package/runtime/dist/src/knowledge/documents.js +520 -0
- package/runtime/dist/src/knowledge/embeddings.js +201 -0
- package/runtime/dist/src/knowledge/mcp.js +218 -0
- package/runtime/dist/src/knowledge/parse-worker.js +122 -0
- package/runtime/dist/src/knowledge/references.js +51 -0
- package/runtime/dist/src/knowledge/service.js +526 -0
- package/runtime/dist/src/knowledge/store-client.js +185 -0
- package/runtime/dist/src/knowledge/store-worker.js +843 -0
- package/runtime/dist/src/knowledge/types.js +2 -0
- package/runtime/dist/src/mcp/http-server.js +177 -0
- package/runtime/dist/src/mem0/resource.js +35 -0
- package/runtime/dist/src/mem0/store-worker.js +330 -0
- package/runtime/dist/src/memory/blackboard-session.js +205 -0
- package/runtime/dist/src/memory/blackboard-store.js +194 -0
- package/runtime/dist/src/memory/blackboard-worker.js +369 -0
- package/runtime/dist/src/memory/entry.js +39 -0
- package/runtime/dist/src/memory/factory.js +20 -0
- package/runtime/dist/src/memory/personal-memory-inspection.js +18 -0
- package/runtime/dist/src/memory/personal-memory.js +10 -0
- package/runtime/dist/src/memory/prerecall.js +20 -0
- package/runtime/dist/src/memory/provenance.js +17 -0
- package/runtime/dist/src/memory/remote-personal-memory.js +194 -0
- package/runtime/dist/src/memory/retrieval.js +235 -0
- package/runtime/dist/src/memory/sensitivity.js +261 -0
- package/runtime/dist/src/memory-ledger/models.js +98 -0
- package/runtime/dist/src/memory-ledger/store-client.js +210 -0
- package/runtime/dist/src/memory-ledger/store-worker.js +130 -0
- package/runtime/dist/src/memory-ledger/store.js +597 -0
- package/runtime/dist/src/memory-substrate/candidates.js +16 -0
- package/runtime/dist/src/memory-substrate/consolidation.js +124 -0
- package/runtime/dist/src/memory-substrate/file-authority.js +111 -0
- package/runtime/dist/src/memory-substrate/life-operations.js +280 -0
- package/runtime/dist/src/memory-substrate/markdown-repository.js +610 -0
- package/runtime/dist/src/memory-substrate/migration.js +87 -0
- package/runtime/dist/src/memory-substrate/profile-source-input.js +9 -0
- package/runtime/dist/src/memory-substrate/purge.js +398 -0
- package/runtime/dist/src/memory-substrate/resolution.js +32 -0
- package/runtime/dist/src/memory-substrate/resource.js +867 -0
- package/runtime/dist/src/memory-substrate/retrieval.js +85 -0
- package/runtime/dist/src/memory-substrate/source-operations.js +306 -0
- package/runtime/dist/src/memory-substrate/source-processing.js +326 -0
- package/runtime/dist/src/memory-substrate/source-state.js +93 -0
- package/runtime/dist/src/memory-substrate/store.js +534 -0
- package/runtime/dist/src/memory-substrate/workspace-projections.js +106 -0
- package/runtime/dist/src/memory-substrate/workspace.js +21 -0
- package/runtime/dist/src/model/jev-client.js +25 -0
- package/runtime/dist/src/model/model-adapters.js +64 -0
- package/runtime/dist/src/model/model-gateway.js +399 -0
- package/runtime/dist/src/model/model-lane.js +34 -0
- package/runtime/dist/src/model/model-purpose.js +5 -0
- package/runtime/dist/src/model/personal-writer.js +361 -0
- package/runtime/dist/src/model/proactivity.js +72 -0
- package/runtime/dist/src/model/prompting.js +279 -0
- package/runtime/dist/src/model/task-verifier.js +217 -0
- package/runtime/dist/src/model/vision-capability.js +10 -0
- package/runtime/dist/src/news/feeds.js +114 -0
- package/runtime/dist/src/news/jev-ranking.js +25 -0
- package/runtime/dist/src/news/ranking.js +26 -0
- package/runtime/dist/src/news/service.js +262 -0
- package/runtime/dist/src/notifications/adapters/feishu.js +10 -0
- package/runtime/dist/src/notifications/adapters/nova.js +15 -0
- package/runtime/dist/src/notifications/content.js +15 -0
- package/runtime/dist/src/notifications/contracts.js +9 -0
- package/runtime/dist/src/notifications/feed.js +8 -0
- package/runtime/dist/src/notifications/service.js +412 -0
- package/runtime/dist/src/notifications/store.js +4 -0
- package/runtime/dist/src/personal-agent/app-context.js +113 -0
- package/runtime/dist/src/personal-agent/approval-scope.js +8 -0
- package/runtime/dist/src/personal-agent/coding-targets.js +82 -0
- package/runtime/dist/src/personal-agent/context-candidates.js +94 -0
- package/runtime/dist/src/personal-agent/contracts.js +32 -0
- package/runtime/dist/src/personal-agent/conversation-runtime.js +536 -0
- package/runtime/dist/src/personal-agent/conversations.js +187 -0
- package/runtime/dist/src/personal-agent/daily-brief.js +53 -0
- package/runtime/dist/src/personal-agent/host.js +2403 -0
- package/runtime/dist/src/personal-agent/intake-task.js +37 -0
- package/runtime/dist/src/personal-agent/life.js +260 -0
- package/runtime/dist/src/personal-agent/memory-overview.js +19 -0
- package/runtime/dist/src/personal-agent/profile-sources.js +34 -0
- package/runtime/dist/src/personal-agent/profile-warmup.js +244 -0
- package/runtime/dist/src/personal-agent/project-digests.js +242 -0
- package/runtime/dist/src/personal-agent/sampling.js +20 -0
- package/runtime/dist/src/personal-agent/schedule-agent.js +60 -0
- package/runtime/dist/src/personal-agent/schedule-api.js +61 -0
- package/runtime/dist/src/personal-agent/schedule-presets.js +13 -0
- package/runtime/dist/src/personal-agent/schedule-reference.js +3 -0
- package/runtime/dist/src/personal-agent/scheduled-response-scope.js +38 -0
- package/runtime/dist/src/personal-agent/scheduled-run-authority.js +44 -0
- package/runtime/dist/src/personal-agent/scheduled-tasks.js +280 -0
- package/runtime/dist/src/personal-agent/scheduled-time.js +99 -0
- package/runtime/dist/src/personal-agent/scheduled-tool-runtime.js +109 -0
- package/runtime/dist/src/personal-agent/source-priority.js +142 -0
- package/runtime/dist/src/personal-agent/source-processing-agent.js +158 -0
- package/runtime/dist/src/personal-agent/source-walk.js +25 -0
- package/runtime/dist/src/personal-agent/sources.js +1484 -0
- package/runtime/dist/src/personal-agent/store-lock-worker.js +17 -0
- package/runtime/dist/src/personal-agent/store.js +146 -0
- package/runtime/dist/src/personal-agent/task-loop.js +163 -0
- package/runtime/dist/src/personal-agent/tasks.js +920 -0
- package/runtime/dist/src/personal-agent/turn-deadline.js +55 -0
- package/runtime/dist/src/personal-agent/understanding.js +160 -0
- package/runtime/dist/src/personal-agent/workbench-context.js +239 -0
- package/runtime/dist/src/projects/confirmed-project-capability.js +60 -0
- package/runtime/dist/src/projects/host-paths.js +133 -0
- package/runtime/dist/src/projects/managed-workspace-maintenance.js +351 -0
- package/runtime/dist/src/projects/project-confirmation.js +486 -0
- package/runtime/dist/src/projects/project-native-resource.js +284 -0
- package/runtime/dist/src/projects/project-node-files.js +169 -0
- package/runtime/dist/src/projects/project-root-file.js +16 -0
- package/runtime/dist/src/projects/project-state.js +504 -0
- package/runtime/dist/src/projects/project-store-files.js +1271 -0
- package/runtime/dist/src/projects/project-store.js +1345 -0
- package/runtime/dist/src/realtime/aoq.js +141 -0
- package/runtime/dist/src/realtime/bridge.js +652 -0
- package/runtime/dist/src/realtime/cascaded/adapter.js +1669 -0
- package/runtime/dist/src/realtime/cascaded/ark-llm.js +219 -0
- package/runtime/dist/src/realtime/cascaded/chat-completions-llm.js +478 -0
- package/runtime/dist/src/realtime/cascaded/gemini-speech.js +232 -0
- package/runtime/dist/src/realtime/cascaded/llm.js +37 -0
- package/runtime/dist/src/realtime/cascaded/ports.js +2 -0
- package/runtime/dist/src/realtime/cascaded/provider.js +216 -0
- package/runtime/dist/src/realtime/cascaded/qwen-llm.js +7 -0
- package/runtime/dist/src/realtime/cascaded/self-hosted-asr.js +110 -0
- package/runtime/dist/src/realtime/cascaded/self-hosted-tts.js +137 -0
- package/runtime/dist/src/realtime/cascaded/transcribe.js +42 -0
- package/runtime/dist/src/realtime/coding-progress-narration.js +28 -0
- package/runtime/dist/src/realtime/confirmation-turn-isolation.js +586 -0
- package/runtime/dist/src/realtime/dictation.js +28 -0
- package/runtime/dist/src/realtime/evidence.js +276 -0
- package/runtime/dist/src/realtime/floor.js +43 -0
- package/runtime/dist/src/realtime/frontend-instructions.js +195 -0
- package/runtime/dist/src/realtime/gemini.js +517 -0
- package/runtime/dist/src/realtime/history.js +122 -0
- package/runtime/dist/src/realtime/host-delivery.js +1711 -0
- package/runtime/dist/src/realtime/integrated-wire-profile.js +128 -0
- package/runtime/dist/src/realtime/memory-board.js +105 -0
- package/runtime/dist/src/realtime/openai-wire-profile.js +46 -0
- package/runtime/dist/src/realtime/playback.js +242 -0
- package/runtime/dist/src/realtime/project-confirmation-flow.js +1428 -0
- package/runtime/dist/src/realtime/prompt-language.js +17 -0
- package/runtime/dist/src/realtime/protocol.js +428 -0
- package/runtime/dist/src/realtime/provider-projection.js +526 -0
- package/runtime/dist/src/realtime/provider-session.js +491 -0
- package/runtime/dist/src/realtime/qwen-transport.js +144 -0
- package/runtime/dist/src/realtime/qwen.js +1377 -0
- package/runtime/dist/src/realtime/recall.js +341 -0
- package/runtime/dist/src/realtime/service-ports.js +8 -0
- package/runtime/dist/src/realtime/service-state.js +259 -0
- package/runtime/dist/src/realtime/service.js +1726 -0
- package/runtime/dist/src/realtime/session-state.js +684 -0
- package/runtime/dist/src/realtime/session.js +1976 -0
- package/runtime/dist/src/realtime/speech-prep.js +63 -0
- package/runtime/dist/src/realtime/streaming-speech.js +120 -0
- package/runtime/dist/src/realtime/system-prompts.en.js +136 -0
- package/runtime/dist/src/realtime/telemetry.js +144 -0
- package/runtime/dist/src/realtime/tool-continuations.js +1510 -0
- package/runtime/dist/src/realtime/transport.js +8 -0
- package/runtime/dist/src/realtime/usage.js +55 -0
- package/runtime/dist/src/realtime/user-origin-binding.js +173 -0
- package/runtime/dist/src/realtime/volcengine/ark.js +428 -0
- package/runtime/dist/src/realtime/volcengine/asr.js +573 -0
- package/runtime/dist/src/realtime/volcengine/audio.js +39 -0
- package/runtime/dist/src/realtime/volcengine/endpointing-capability.js +834 -0
- package/runtime/dist/src/realtime/volcengine/livekit-endpointing.js +714 -0
- package/runtime/dist/src/realtime/volcengine/local-eot-executor.js +33 -0
- package/runtime/dist/src/realtime/volcengine/protocol.js +247 -0
- package/runtime/dist/src/realtime/volcengine/silence-endpointing.js +237 -0
- package/runtime/dist/src/realtime/volcengine/tts.js +444 -0
- package/runtime/dist/src/realtime/volcengine/websocket.js +293 -0
- package/runtime/dist/src/server/aoq-chat-server.js +497 -0
- package/runtime/dist/src/server/client-pairing.js +192 -0
- package/runtime/dist/src/server/client-protocol.js +87 -0
- package/runtime/dist/src/server/client-server.js +312 -0
- package/runtime/dist/src/server/server-config.js +72 -0
- package/runtime/dist/src/server-entry.js +135 -0
- package/runtime/dist/src/storage/bounded-json.js +63 -0
- package/runtime/dist/src/storage/native-file-lock.js +8 -0
- package/runtime/dist/src/storage/native-resource-snapshot.js +41 -0
- package/runtime/dist/src/storage/private-database.js +120 -0
- package/runtime/dist/src/text/canonical-json.js +60 -0
- package/runtime/dist/src/text/python-number.js +18 -0
- package/runtime/dist/src/text/python-text.js +92 -0
- package/runtime/dist/src/text/unicode-casefold.js +29 -0
- package/runtime/dist/src/text/unicode-normalize.js +138 -0
- package/runtime/dist/src/text/unicode-tables.js +210 -0
- package/runtime/dist/src/understanding/candidates.js +77 -0
- package/runtime/dist/src/understanding/fixture.js +7 -0
- package/runtime/dist/src/understanding/jev.js +20 -0
- package/runtime/dist/src/understanding/pipeline.js +38 -0
- package/runtime/dist/src/voicemem/store-client.js +476 -0
- package/runtime/dist/src/voicemem/store-worker.js +380 -0
- package/runtime/dist/src/voicemem/versioned-memory.js +170 -0
- package/runtime/scripts/pair-device.mjs +109 -0
- package/src/command.mjs +48 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/** Shared screenshot planner. Callers supply only Nova-guarded actions and own target/approval/cleanup. */
|
|
2
|
+
import { Agent } from '@midscene/core';
|
|
3
|
+
import { setLogDirectoryResolver } from '@midscene/shared/logger';
|
|
4
|
+
import { devNull } from 'node:os';
|
|
5
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
6
|
+
// 1.12.9 appends filenames to this path; a null device cannot contain files on either platform.
|
|
7
|
+
setLogDirectoryResolver(() => devNull);
|
|
8
|
+
/** AutoGLM emits distance in screenshot pixels; the SDK only rescales locator centers. */
|
|
9
|
+
export function logicalSwipeDistance(distance, screenshotToLogicalRatio) {
|
|
10
|
+
if (!Number.isFinite(distance) || distance <= 0 || !Number.isFinite(screenshotToLogicalRatio)
|
|
11
|
+
|| screenshotToLogicalRatio <= 0)
|
|
12
|
+
throw new Error('needs_user_action');
|
|
13
|
+
return distance / screenshotToLogicalRatio;
|
|
14
|
+
}
|
|
15
|
+
export function validGuiConfig(config, instruction) {
|
|
16
|
+
try {
|
|
17
|
+
const endpoint = new URL(config.baseUrl);
|
|
18
|
+
const settleMs = config.settleMs ?? 4000;
|
|
19
|
+
return !endpoint.username && !endpoint.password && !endpoint.search && !endpoint.hash
|
|
20
|
+
&& (endpoint.protocol === 'https:' || (endpoint.protocol === 'http:'
|
|
21
|
+
&& ['localhost', '127.0.0.1', '[::1]'].includes(endpoint.hostname)))
|
|
22
|
+
&& ['auto-glm', 'auto-glm-multilingual', 'qwen3-vl'].includes(config.modelFamily)
|
|
23
|
+
&& Boolean(config.model.trim() && config.apiKey && instruction.trim()) && instruction.length <= 4000
|
|
24
|
+
&& Number.isSafeInteger(config.maxSteps) && config.maxSteps >= 1 && config.maxSteps <= 100
|
|
25
|
+
&& Number.isSafeInteger(config.budgetMs) && config.budgetMs >= 1 && config.budgetMs <= 1_800_000
|
|
26
|
+
&& Number.isSafeInteger(settleMs) && settleMs >= 0 && settleMs <= 30_000;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** model_finished is execution status, never task verification. No screenshot persistence or device destruction. */
|
|
33
|
+
export async function runGui(instruction, guarded, options) {
|
|
34
|
+
if (options.signal.aborted)
|
|
35
|
+
return 'cancelled';
|
|
36
|
+
if (!validGuiConfig(options, instruction))
|
|
37
|
+
return 'invalid_configuration';
|
|
38
|
+
const settleMs = options.settleMs ?? 4000;
|
|
39
|
+
let agent;
|
|
40
|
+
let finished = false;
|
|
41
|
+
let limited = false;
|
|
42
|
+
const diagnose = (value) => {
|
|
43
|
+
const message = value instanceof Error ? value.message : typeof value === 'string' ? value : 'model_failed';
|
|
44
|
+
options.diagnostic?.(message.replaceAll(options.apiKey, '[redacted]').replace(/data:image\/[^\s"']+/gu, '[image]').slice(0, 1000));
|
|
45
|
+
};
|
|
46
|
+
try {
|
|
47
|
+
agent = new Agent(guarded, { modelConfig: { MIDSCENE_MODEL_FAMILY: options.modelFamily, MIDSCENE_MODEL_NAME: options.model,
|
|
48
|
+
MIDSCENE_MODEL_BASE_URL: options.baseUrl, MIDSCENE_MODEL_API_KEY: options.apiKey, MIDSCENE_MODEL_RETRY_COUNT: 0,
|
|
49
|
+
MIDSCENE_MODEL_TIMEOUT: Math.min(options.budgetMs, 60_000) },
|
|
50
|
+
waitAfterAction: settleMs, replanningCycleLimit: options.maxSteps, cache: false,
|
|
51
|
+
generateReport: false, persistExecutionDump: false, autoPrintReportMsg: false });
|
|
52
|
+
agent.addProgressListener(event => {
|
|
53
|
+
if (event.scope !== 'aiAct')
|
|
54
|
+
return;
|
|
55
|
+
if (event.phase === 'failed' || event.phase === 'plan_failed') {
|
|
56
|
+
const data = event.data;
|
|
57
|
+
diagnose(data?.error);
|
|
58
|
+
}
|
|
59
|
+
if (event.phase === 'plan_thinking') {
|
|
60
|
+
options.planning();
|
|
61
|
+
options.progress({ phase: 'planning', steps: options.steps() });
|
|
62
|
+
}
|
|
63
|
+
if (event.phase === 'complete' && !options.signal.aborted)
|
|
64
|
+
finished = true;
|
|
65
|
+
if (event.phase === 'failed' && options.steps() >= options.maxSteps)
|
|
66
|
+
limited = true;
|
|
67
|
+
});
|
|
68
|
+
await delay(settleMs, undefined, { signal: options.signal });
|
|
69
|
+
await agent.aiAct(instruction, { abortSignal: options.signal, cacheable: false, context: options.context });
|
|
70
|
+
options.signal.throwIfAborted();
|
|
71
|
+
const lastTask = agent.dump.executions.at(-1)?.tasks.at(-1);
|
|
72
|
+
finished &&= lastTask?.status === 'finished' && !lastTask.error
|
|
73
|
+
&& (options.modelFamily === 'qwen3-vl' || (lastTask.type === 'Action Space' && lastTask.subType === 'Finished'));
|
|
74
|
+
if (finished && options.capture)
|
|
75
|
+
options.capture(await guarded.screenshotBase64(), options.steps());
|
|
76
|
+
if (finished)
|
|
77
|
+
options.progress({ phase: 'model_finished', steps: options.steps() });
|
|
78
|
+
return finished ? 'model_finished' : limited ? 'step_limit' : 'model_failed';
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
diagnose(error);
|
|
82
|
+
return options.signal.aborted ? 'cancelled' : limited ? 'step_limit' : 'model_failed';
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
await agent?.destroy();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=gui-runner.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const CAPABILITIES = new WeakMap();
|
|
2
|
+
/** Host-only bridge. Deliberately not exported from the runtime package root. */
|
|
3
|
+
export function bindHostExecutorCapability(context, capability) {
|
|
4
|
+
CAPABILITIES.set(context, capability);
|
|
5
|
+
}
|
|
6
|
+
/** One-shot host-only read. The value never becomes part of a Delegate or JsonValue. */
|
|
7
|
+
export function consumeHostExecutorCapability(context) {
|
|
8
|
+
const capability = CAPABILITIES.get(context);
|
|
9
|
+
CAPABILITIES.delete(context);
|
|
10
|
+
return capability;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=host-executor-capability.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Executor package registry.
|
|
3
|
+
*
|
|
4
|
+
* Aggregate public exports for the barrel and `desktop.ts`. Compositions may use an executor's
|
|
5
|
+
* dedicated entry point to avoid eagerly loading unrelated packages.
|
|
6
|
+
*/
|
|
7
|
+
export * from './codex/index.js';
|
|
8
|
+
export * from './vision.js';
|
|
9
|
+
export * from './autoglm.js';
|
|
10
|
+
export * from './mobile.js';
|
|
11
|
+
export * from './computer.js';
|
|
12
|
+
export { BrowserExecutor, loadBrowserConfig, BROWSER_DESCRIPTOR } from './browser.js';
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/** Shared bounded MCP I/O. No server error text or resolved configuration leaves this boundary. */
|
|
2
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
3
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
4
|
+
import { getDefaultEnvironment, StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
5
|
+
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
6
|
+
import { ListToolsResultSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
7
|
+
import { validateMcpEndpoint } from '../config/capability-registry.js';
|
|
8
|
+
const DISCOVERY_BYTES = 1024 * 1024;
|
|
9
|
+
const STARTUP_MS = 15_000;
|
|
10
|
+
export class McpFailure extends Error {
|
|
11
|
+
code;
|
|
12
|
+
constructor(code) {
|
|
13
|
+
super(code);
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.name = 'McpFailure';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export async function boundedMcpFetch(url, init, options) {
|
|
19
|
+
// No unsolicited notification stream, reconnect, auth discovery or redirect to another origin.
|
|
20
|
+
if (init?.method === 'GET')
|
|
21
|
+
return new Response(null, { status: 405 });
|
|
22
|
+
const signal = AbortSignal.any([options.signal, ...(init?.signal ? [init.signal] : [])]);
|
|
23
|
+
signal.throwIfAborted();
|
|
24
|
+
if (options.stillWanted !== undefined && !options.stillWanted())
|
|
25
|
+
throw options.failure('stale_user_origin');
|
|
26
|
+
const response = await fetch(url, { ...init, redirect: 'manual', signal });
|
|
27
|
+
if (!response.ok) {
|
|
28
|
+
await response.body?.cancel();
|
|
29
|
+
throw options.failure(options.authorizationStatus && response.status === 401 ? 'unauthorized' : options.authorizationStatus && response.status === 403 ? 'forbidden' : response.status === 401 || response.status === 403 ? 'authentication'
|
|
30
|
+
: response.status === 429 ? 'rate_limited'
|
|
31
|
+
: response.status >= 300 && response.status < 400 ? 'redirect' : 'upstream');
|
|
32
|
+
}
|
|
33
|
+
if (Number(response.headers.get('content-length')) > options.maxBytes) {
|
|
34
|
+
await response.body?.cancel();
|
|
35
|
+
throw options.failure('response_too_large');
|
|
36
|
+
}
|
|
37
|
+
let bytes = 0;
|
|
38
|
+
const body = response.body?.pipeThrough(new TransformStream({
|
|
39
|
+
transform: (chunk, stream) => {
|
|
40
|
+
bytes += chunk.byteLength;
|
|
41
|
+
if (bytes > options.maxBytes)
|
|
42
|
+
throw options.failure('response_too_large');
|
|
43
|
+
stream.enqueue(chunk);
|
|
44
|
+
},
|
|
45
|
+
}));
|
|
46
|
+
return new Response(body ?? null, { status: response.status, headers: response.headers });
|
|
47
|
+
}
|
|
48
|
+
export class McpConnection {
|
|
49
|
+
#client = new Client({ name: 'nova-external-mcp', version: '1' });
|
|
50
|
+
#scope = new AsyncLocalStorage();
|
|
51
|
+
#lifetime = new AbortController();
|
|
52
|
+
#transport;
|
|
53
|
+
#closing;
|
|
54
|
+
#closed = false;
|
|
55
|
+
constructor(config, onFailure, options) {
|
|
56
|
+
if (config.transport === 'stdio') {
|
|
57
|
+
// SDK 1.30 always adds its platform allowlist, even with env: {}. Keep that exact safe
|
|
58
|
+
// HOME/PATH (Windows system paths) policy; no ambient credentials, NODE_OPTIONS or proxies.
|
|
59
|
+
const transport = new StdioClientTransport({ command: config.command, args: [...config.args ?? []],
|
|
60
|
+
env: { ...getDefaultEnvironment(), ...config.env }, stderr: 'pipe', maxBufferSize: DISCOVERY_BYTES + 65536 });
|
|
61
|
+
transport.stderr?.on('data', () => undefined); // A server may print secrets. Drain without logging or retaining them.
|
|
62
|
+
this.#transport = transport;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
const target = new URL(config.url);
|
|
66
|
+
if (!(options?.trustedLoopback && target.protocol === 'http:' && target.hostname === '127.0.0.1'
|
|
67
|
+
&& !target.username && !target.password && !target.hash))
|
|
68
|
+
validateMcpEndpoint(config.url, config.headers);
|
|
69
|
+
this.#transport = new StreamableHTTPClientTransport(new URL(config.url), {
|
|
70
|
+
requestInit: { headers: config.headers ?? {} },
|
|
71
|
+
reconnectionOptions: { maxRetries: 0, maxReconnectionDelay: 0, initialReconnectionDelay: 0, reconnectionDelayGrowFactor: 1 },
|
|
72
|
+
fetch: (url, init) => {
|
|
73
|
+
const scope = this.#scope.getStore();
|
|
74
|
+
if (scope === undefined)
|
|
75
|
+
return Promise.reject(new McpFailure('request_scope_missing'));
|
|
76
|
+
return boundedMcpFetch(url, init, { ...scope, failure: code => new McpFailure(code), ...(options?.trustedLoopback ? { authorizationStatus: true } : {}) });
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
// This is adjacent to the SDK's actual stdio write. HTTP also checks at fetch after its
|
|
81
|
+
// asynchronous header preparation. AsyncLocalStorage keeps concurrent calls independent.
|
|
82
|
+
const transport = this.#transport;
|
|
83
|
+
// SDK stdio clears its child handle before async teardown finishes. Concurrent close calls
|
|
84
|
+
// (connect's failure cleanup and our owner) must await the same teardown, not return early.
|
|
85
|
+
const close = transport.close.bind(transport);
|
|
86
|
+
let closing;
|
|
87
|
+
transport.close = () => closing ??= close();
|
|
88
|
+
const send = transport.send.bind(transport);
|
|
89
|
+
transport.send = (message, options) => {
|
|
90
|
+
const scope = this.#scope.getStore();
|
|
91
|
+
if ('method' in message && message.method === 'tools/call') {
|
|
92
|
+
scope?.signal.throwIfAborted();
|
|
93
|
+
if (scope?.stillWanted !== undefined && !scope.stillWanted())
|
|
94
|
+
return Promise.reject(new McpFailure('stale_user_origin'));
|
|
95
|
+
}
|
|
96
|
+
return send(message, options);
|
|
97
|
+
};
|
|
98
|
+
this.#client.onerror = () => undefined;
|
|
99
|
+
this.#client.onclose = () => {
|
|
100
|
+
const unexpected = !this.#closed;
|
|
101
|
+
this.#closed = true;
|
|
102
|
+
this.#lifetime.abort();
|
|
103
|
+
if (unexpected)
|
|
104
|
+
onFailure?.('connection_closed');
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
async discover(signal) {
|
|
108
|
+
const deadline = AbortSignal.timeout(STARTUP_MS);
|
|
109
|
+
const bound = AbortSignal.any([deadline, this.#lifetime.signal, ...(signal ? [signal] : [])]);
|
|
110
|
+
try {
|
|
111
|
+
return await this.#scope.run({ signal: bound, maxBytes: DISCOVERY_BYTES }, async () => {
|
|
112
|
+
const options = { signal: bound, timeout: STARTUP_MS };
|
|
113
|
+
await this.#client.connect(this.#transport, options);
|
|
114
|
+
const tools = [];
|
|
115
|
+
const names = new Set();
|
|
116
|
+
let cursor;
|
|
117
|
+
for (let page = 0; page < 8; page += 1) {
|
|
118
|
+
// listTools() eagerly compiles output schemas for every remote tool. Discovery must
|
|
119
|
+
// only read metadata, including for tools that are not allowlisted.
|
|
120
|
+
const result = await this.#client.request({ method: 'tools/list', params: cursor === undefined ? {} : { cursor } }, ListToolsResultSchema, options);
|
|
121
|
+
for (const tool of result.tools) {
|
|
122
|
+
if (names.has(tool.name))
|
|
123
|
+
throw new McpFailure('duplicate_tool_name');
|
|
124
|
+
names.add(tool.name);
|
|
125
|
+
tools.push(tool);
|
|
126
|
+
}
|
|
127
|
+
if (Buffer.byteLength(JSON.stringify(tools)) > DISCOVERY_BYTES || tools.length > 1024)
|
|
128
|
+
throw new McpFailure('discovery_too_large');
|
|
129
|
+
if (result.nextCursor === undefined)
|
|
130
|
+
return tools;
|
|
131
|
+
cursor = result.nextCursor;
|
|
132
|
+
}
|
|
133
|
+
throw new McpFailure('discovery_page_limit');
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
const code = signal?.aborted === true ? 'discovery_cancelled' : deadline.aborted ? 'discovery_timeout'
|
|
138
|
+
: error instanceof McpFailure ? error.code : 'discovery_failed';
|
|
139
|
+
await this.close();
|
|
140
|
+
throw new McpFailure(code);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
async call(name, args, options) {
|
|
144
|
+
if (this.#closed)
|
|
145
|
+
throw new McpFailure('transport_closed');
|
|
146
|
+
const signal = AbortSignal.any([options.signal, this.#lifetime.signal, AbortSignal.timeout(Math.ceil(options.timeoutMs))]);
|
|
147
|
+
try {
|
|
148
|
+
return await this.#scope.run({ ...options, signal, maxBytes: options.maxBytes + 65536 }, async () => {
|
|
149
|
+
signal.throwIfAborted();
|
|
150
|
+
const result = await this.#client.callTool({ name, arguments: args }, undefined, { signal, timeout: options.timeoutMs });
|
|
151
|
+
if (Buffer.byteLength(JSON.stringify(result)) > options.maxBytes)
|
|
152
|
+
throw new McpFailure('response_too_large');
|
|
153
|
+
if (result.isError && !options.returnToolErrors)
|
|
154
|
+
throw new McpFailure('tool_failed');
|
|
155
|
+
return result;
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
throw new McpFailure(signal.aborted ? 'timeout' : error instanceof McpFailure ? error.code : 'call_failed');
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
close() {
|
|
163
|
+
if (this.#closing !== undefined)
|
|
164
|
+
return this.#closing;
|
|
165
|
+
this.#closed = true;
|
|
166
|
+
this.#lifetime.abort();
|
|
167
|
+
this.#closing = (async () => {
|
|
168
|
+
const transport = this.#transport;
|
|
169
|
+
if (transport instanceof StreamableHTTPClientTransport && transport.sessionId !== undefined) {
|
|
170
|
+
try {
|
|
171
|
+
await this.#scope.run({ signal: AbortSignal.timeout(250), maxBytes: DISCOVERY_BYTES }, () => transport.terminateSession());
|
|
172
|
+
}
|
|
173
|
+
catch { /* cleanup never echoes server data or masks the primary failure */ }
|
|
174
|
+
}
|
|
175
|
+
await this.#client.close().catch(() => undefined);
|
|
176
|
+
// Connect may fail before the client takes transport ownership.
|
|
177
|
+
await transport.close().catch(() => undefined);
|
|
178
|
+
})();
|
|
179
|
+
return this.#closing;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/** Metadata-only probe for the main process. Never calls a discovered tool; no connection fields returned. */
|
|
183
|
+
export async function probeMcpServer(config, signal) {
|
|
184
|
+
const connection = new McpConnection(config);
|
|
185
|
+
try {
|
|
186
|
+
const tools = (await connection.discover(signal)).map(tool => ({
|
|
187
|
+
name: tool.name, description: tool.description ?? '', readOnlyHint: tool.annotations?.readOnlyHint === true,
|
|
188
|
+
}));
|
|
189
|
+
return { status: 'ok', tools };
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
return { status: 'failed', tools: [], reason: error instanceof McpFailure ? error.code : 'discovery_failed' };
|
|
193
|
+
}
|
|
194
|
+
finally {
|
|
195
|
+
await connection.close();
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=mcp-client.js.map
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { acquireTaskResources, taskResourcesBusy, taskResourcesUncertain, quarantineTaskResources } from './task-resources.js';
|
|
2
|
+
/** External MCP tools are direct, untrusted executors; discovery never grants approval or probe authority. */
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
import { AjvJsonSchemaValidator } from '@modelcontextprotocol/sdk/validation/ajv';
|
|
5
|
+
import { jsonValueSchema } from '../core/events.js';
|
|
6
|
+
import { executorManifestSchema } from '../core/ports.js';
|
|
7
|
+
import { compileToolSchema } from '../core/tool-schema.js';
|
|
8
|
+
import { McpConnection, McpFailure } from './mcp-client.js';
|
|
9
|
+
export function mcpToolAlias(server, original) {
|
|
10
|
+
const prefix = `mcp__${server}__`;
|
|
11
|
+
const budget = 64 - prefix.length;
|
|
12
|
+
if (!/^[a-z][a-z0-9_]{0,31}$/u.test(server))
|
|
13
|
+
throw new McpFailure('invalid_server_name');
|
|
14
|
+
const normalized = original.toLowerCase().replace(/[^a-z0-9_]/gu, '_').replace(/_+/gu, '_').replace(/^_|_$/gu, '');
|
|
15
|
+
const alias = normalized === original && original.length <= budget && original.length > 0 ? original
|
|
16
|
+
: `${normalized.slice(0, budget - 7)}_${createHash('sha256').update(original).digest('hex').slice(0, 6)}`;
|
|
17
|
+
if (prefix.length + alias.length > 64)
|
|
18
|
+
throw new McpFailure('alias_too_long');
|
|
19
|
+
return alias;
|
|
20
|
+
}
|
|
21
|
+
/** A narrow, bounded provider-compatible subset; SDK AJV owns actual argument validation. */
|
|
22
|
+
function compatibleSchema(value, depth = 0) {
|
|
23
|
+
if (depth > 8 || typeof value !== 'object' || value === null || Array.isArray(value))
|
|
24
|
+
throw new McpFailure('incompatible_schema');
|
|
25
|
+
const schema = value;
|
|
26
|
+
const allowed = ['type', 'title', 'description', 'default', 'enum', 'properties', 'required', 'additionalProperties',
|
|
27
|
+
'items', 'minItems', 'maxItems', 'minLength', 'maxLength', 'minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum'];
|
|
28
|
+
if (Object.keys(schema).some(key => !allowed.includes(key))
|
|
29
|
+
|| (typeof schema.type !== 'string' || !['object', 'array', 'string', 'number', 'integer', 'boolean', 'null'].includes(schema.type)))
|
|
30
|
+
throw new McpFailure('incompatible_schema');
|
|
31
|
+
for (const key of ['title', 'description'])
|
|
32
|
+
if (schema[key] !== undefined && typeof schema[key] !== 'string')
|
|
33
|
+
throw new McpFailure('incompatible_schema');
|
|
34
|
+
if (schema.enum !== undefined && (!Array.isArray(schema.enum) || schema.enum.length === 0))
|
|
35
|
+
throw new McpFailure('incompatible_schema');
|
|
36
|
+
for (const key of ['minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum']) {
|
|
37
|
+
if (schema[key] !== undefined && ((schema.type !== 'number' && schema.type !== 'integer') || typeof schema[key] !== 'number' || !Number.isFinite(schema[key])))
|
|
38
|
+
throw new McpFailure('incompatible_schema');
|
|
39
|
+
}
|
|
40
|
+
for (const key of ['minLength', 'maxLength', 'minItems', 'maxItems']) {
|
|
41
|
+
if (schema[key] !== undefined && (schema.type !== (key.endsWith('Items') ? 'array' : 'string') || !Number.isInteger(schema[key]) || schema[key] < 0))
|
|
42
|
+
throw new McpFailure('incompatible_schema');
|
|
43
|
+
}
|
|
44
|
+
if (schema.type === 'object') {
|
|
45
|
+
const properties = schema.properties ?? {};
|
|
46
|
+
if (typeof properties !== 'object' || properties === null || Array.isArray(properties) || Object.keys(properties).length > 128 || 'origin_ref' in properties)
|
|
47
|
+
throw new McpFailure('incompatible_schema');
|
|
48
|
+
if (schema.required !== undefined && (!Array.isArray(schema.required) || !schema.required.every(key => typeof key === 'string' && Object.hasOwn(properties, key)) || new Set(schema.required).size !== schema.required.length))
|
|
49
|
+
throw new McpFailure('incompatible_schema');
|
|
50
|
+
if (schema.additionalProperties !== undefined && typeof schema.additionalProperties !== 'boolean')
|
|
51
|
+
throw new McpFailure('incompatible_schema');
|
|
52
|
+
schema.properties = Object.fromEntries(Object.entries(properties).map(([key, child]) => [key, compatibleSchema(child, depth + 1)]));
|
|
53
|
+
schema.additionalProperties ??= false;
|
|
54
|
+
}
|
|
55
|
+
else if (['properties', 'required', 'additionalProperties'].some(key => key in schema))
|
|
56
|
+
throw new McpFailure('incompatible_schema');
|
|
57
|
+
if (schema.type === 'array')
|
|
58
|
+
schema.items = compatibleSchema(schema.items, depth + 1);
|
|
59
|
+
else if ('items' in schema)
|
|
60
|
+
throw new McpFailure('incompatible_schema');
|
|
61
|
+
return schema;
|
|
62
|
+
}
|
|
63
|
+
export class McpExecutorAdapter {
|
|
64
|
+
server;
|
|
65
|
+
config;
|
|
66
|
+
connection;
|
|
67
|
+
manifest;
|
|
68
|
+
#validators = new Map();
|
|
69
|
+
#counts = new Map();
|
|
70
|
+
#currentTurn;
|
|
71
|
+
constructor(server, config, connection, discovered) {
|
|
72
|
+
this.server = server;
|
|
73
|
+
this.config = config;
|
|
74
|
+
this.connection = connection;
|
|
75
|
+
const aliases = Object.create(null);
|
|
76
|
+
const validator = new AjvJsonSchemaValidator();
|
|
77
|
+
const ops = Object.entries(config.tools).filter(([, policy]) => policy.enabled).map(([original, policy]) => {
|
|
78
|
+
const tool = discovered.find(tool => tool.name === original);
|
|
79
|
+
if (tool === undefined)
|
|
80
|
+
throw new McpFailure('enabled_tool_missing');
|
|
81
|
+
const alias = mcpToolAlias(server, original);
|
|
82
|
+
if (Object.hasOwn(aliases, alias))
|
|
83
|
+
throw new McpFailure('alias_collision');
|
|
84
|
+
aliases[alias] = original;
|
|
85
|
+
try {
|
|
86
|
+
if (tool.inputSchema.type !== 'object')
|
|
87
|
+
throw new McpFailure('incompatible_schema');
|
|
88
|
+
const params = compatibleSchema(structuredClone(tool.inputSchema));
|
|
89
|
+
this.#validators.set(alias, validator.getValidator(params));
|
|
90
|
+
return { name: alias, description: tool.description?.trim() ? tool.description.trim() : `MCP tool ${original} from ${server}`,
|
|
91
|
+
params, readonly: tool.annotations?.readOnlyHint === true, deadline_budget: policy.timeoutMs / 1000,
|
|
92
|
+
sync_result: policy.timeoutMs <= 10000 };
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
throw new McpFailure(`incompatible_tool:${original}`);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
this.manifest = executorManifestSchema.parse({
|
|
99
|
+
name: `mcp__${server}`, display_name: server, roles: [], approvals: false, model_visibility: 'direct', probe_policy: 'none', tool_aliases: aliases, ops,
|
|
100
|
+
policy: { channel: `mcp__${server}`, priority: 40, wake: 'surrogate', typical_latency: 1, compress_watermark: 8000, progress_via_surrogate: true },
|
|
101
|
+
});
|
|
102
|
+
compileToolSchema([this.manifest]); // Existing reserved params/provider schema rules remain authoritative.
|
|
103
|
+
}
|
|
104
|
+
taskResource() { return this.config.computerUse?.resource ?? null; }
|
|
105
|
+
admitRequest(op, request) {
|
|
106
|
+
return this.#validators.get(op)?.(request).valid === true
|
|
107
|
+
? { ok: true, request, sync_result: this.manifest.ops.find(value => value.name === op).sync_result }
|
|
108
|
+
: { ok: false };
|
|
109
|
+
}
|
|
110
|
+
async dispatch(op, request, context) {
|
|
111
|
+
const operation = this.manifest.ops.find(value => value.name === op);
|
|
112
|
+
const original = this.manifest.tool_aliases?.[op];
|
|
113
|
+
const policy = original === undefined ? undefined : this.config.tools[original];
|
|
114
|
+
const failure = (code, outcome = 'refused') => ({ outcome, trust: 'untrusted_external', content: { code, verified: false } });
|
|
115
|
+
if (operation === undefined || original === undefined || policy === undefined || !this.admitRequest(op, request).ok)
|
|
116
|
+
return failure('invalid_params');
|
|
117
|
+
const authority = context.userTurn;
|
|
118
|
+
const wanted = () => authority?.originRef === context.delegate.origin_ref && authority.stillWanted();
|
|
119
|
+
if (!operation.readonly && !wanted())
|
|
120
|
+
return failure('stale_user_origin');
|
|
121
|
+
const turn = context.delegate.origin_ref;
|
|
122
|
+
let counts = this.#counts.get(turn);
|
|
123
|
+
if (wanted() && this.#currentTurn !== turn) {
|
|
124
|
+
this.#counts.clear();
|
|
125
|
+
this.#currentTurn = turn;
|
|
126
|
+
if (counts !== undefined)
|
|
127
|
+
this.#counts.set(turn, counts);
|
|
128
|
+
}
|
|
129
|
+
// Authority retires other turns, preserving any readonly calls already charged to
|
|
130
|
+
// this origin. Unscoped callers cannot evict history to restore their quota.
|
|
131
|
+
if (counts === undefined) {
|
|
132
|
+
if (this.#counts.size >= 1024)
|
|
133
|
+
return failure('turn_history_full');
|
|
134
|
+
counts = new Map();
|
|
135
|
+
this.#counts.set(turn, counts);
|
|
136
|
+
}
|
|
137
|
+
const count = counts.get(op) ?? 0;
|
|
138
|
+
if (count >= policy.maxCallsPerTurn)
|
|
139
|
+
return failure('max_calls_per_turn');
|
|
140
|
+
counts.set(op, count + 1);
|
|
141
|
+
const timeoutMs = Math.min(policy.timeoutMs, Math.max(0, ((context.delegate.deadline ?? (context.clock.now() + policy.timeoutMs / 1000)) - context.clock.now()) * 1000));
|
|
142
|
+
if (timeoutMs <= 0 || context.signal.aborted)
|
|
143
|
+
return failure('timeout', 'unknown');
|
|
144
|
+
const resource = this.taskResource();
|
|
145
|
+
if (this.config.computerUse && !resource)
|
|
146
|
+
return failure('computer_resource_unavailable');
|
|
147
|
+
let release, called = false, uncertain = false;
|
|
148
|
+
try {
|
|
149
|
+
if (resource) {
|
|
150
|
+
if (taskResourcesBusy([resource]))
|
|
151
|
+
await context.resourceWaiting?.(taskResourcesUncertain([resource]) ? 'computer_resource_uncertain' : 'computer_resource_busy');
|
|
152
|
+
release = await acquireTaskResources([resource], AbortSignal.any([context.signal, AbortSignal.timeout(timeoutMs)]));
|
|
153
|
+
await context.resourceWaiting?.(null);
|
|
154
|
+
}
|
|
155
|
+
context.beforeWrite?.();
|
|
156
|
+
if (!operation.readonly && !wanted())
|
|
157
|
+
return failure('stale_user_origin');
|
|
158
|
+
context.progress({ phase: 'started', internal_activity: 0, elapsed: 0, summary: null });
|
|
159
|
+
called = true;
|
|
160
|
+
const result = await this.connection.call(original, request, { signal: context.signal, timeoutMs, maxBytes: policy.maxResultBytes,
|
|
161
|
+
...(operation.readonly ? {} : { stillWanted: wanted }) });
|
|
162
|
+
return { outcome: 'ok', trust: 'untrusted_external', content: { result: jsonValueSchema.parse(result), verified: false } };
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
const code = error instanceof McpFailure ? error.code : 'call_failed';
|
|
166
|
+
uncertain = called && !operation.readonly && code !== 'stale_user_origin';
|
|
167
|
+
if (uncertain && resource)
|
|
168
|
+
quarantineTaskResources([resource]);
|
|
169
|
+
return failure(code, !called || code === 'stale_user_origin' ? 'refused' : operation.readonly ? 'failed' : 'unknown');
|
|
170
|
+
}
|
|
171
|
+
finally {
|
|
172
|
+
if (!uncertain)
|
|
173
|
+
release?.();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
export async function prepareExternalMcp(capabilities, signal) {
|
|
178
|
+
const adapters = [];
|
|
179
|
+
const connections = [];
|
|
180
|
+
const statuses = [...capabilities.serverStatuses];
|
|
181
|
+
const updateStatus = (status) => {
|
|
182
|
+
const index = statuses.findIndex(value => value.name === status.name);
|
|
183
|
+
if (index < 0)
|
|
184
|
+
statuses.push(status);
|
|
185
|
+
else
|
|
186
|
+
statuses[index] = { ...statuses[index], ...status };
|
|
187
|
+
};
|
|
188
|
+
for (const [name, config] of Object.entries(capabilities.mcpServers)) {
|
|
189
|
+
if (!config.enabled || !config.exposeTo.frontbrain)
|
|
190
|
+
continue;
|
|
191
|
+
let connection;
|
|
192
|
+
try {
|
|
193
|
+
if (signal?.aborted === true)
|
|
194
|
+
throw new McpFailure('discovery_cancelled');
|
|
195
|
+
connection = new McpConnection(config, reason => updateStatus({ name, status: 'failed', reason }));
|
|
196
|
+
const discovered = await connection.discover(signal);
|
|
197
|
+
const adapter = new McpExecutorAdapter(name, config, connection, discovered);
|
|
198
|
+
adapters.push(adapter);
|
|
199
|
+
connections.push(connection);
|
|
200
|
+
updateStatus({ name, status: 'ok' });
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
await connection?.close();
|
|
204
|
+
updateStatus({ name, status: 'failed', reason: error instanceof McpFailure ? error.code : 'discovery_failed' });
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return { capabilities: { ...capabilities, serverStatuses: statuses }, adapters,
|
|
208
|
+
close: async () => { await Promise.all(connections.map(connection => connection.close())); } };
|
|
209
|
+
}
|
|
210
|
+
//# sourceMappingURL=mcp.js.map
|