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,315 @@
|
|
|
1
|
+
/** One dependency-free registry parser, also emitted into the standalone CLI by check-capabilities.mjs. */
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
export const DEFAULT_CAPABILITIES_PATH = '~/.nova-audio-agent/capabilities.json';
|
|
6
|
+
export const BAILIAN_SEARCH_MCP_URL = 'https://dashscope.aliyuncs.com/api/v1/mcps/EnhancedSearch/mcp';
|
|
7
|
+
export const BAILIAN_SEARCH_MCP_TOOL = 'search_pro';
|
|
8
|
+
export const DEFAULT_FRONTBRAIN_TOOL_BUDGET = 24;
|
|
9
|
+
export const MCP_NON_AUTH_HEADERS = ['accept', 'content-type', 'user-agent'];
|
|
10
|
+
const ENV_NAME = /^[A-Za-z_][A-Za-z0-9_]{0,127}$/u;
|
|
11
|
+
const SERVER_NAME = /^[a-z][a-z0-9_]{0,31}$/u;
|
|
12
|
+
const MAX_CONFIG_BYTES = 256 * 1024;
|
|
13
|
+
/** Legacy `exposeTo.codex` authorizes only Codex; every other backend needs an explicit grant. */
|
|
14
|
+
export function mcpBackendAuthorized(config, backend) {
|
|
15
|
+
return config.enabled && (config.exposeTo.backends?.[backend] ?? (backend === 'codex' && config.exposeTo.codex));
|
|
16
|
+
}
|
|
17
|
+
function backendGrants(value, field) {
|
|
18
|
+
if (value === undefined)
|
|
19
|
+
return undefined;
|
|
20
|
+
const grants = object(value, field, ['codex', 'opencode', 'codebuddy', 'pi', 'deepseek']);
|
|
21
|
+
return Object.fromEntries(Object.entries(grants).map(([key, enabled]) => [key, bool(enabled, false, `${field}.${key}`)]));
|
|
22
|
+
}
|
|
23
|
+
export class CapabilityConfigurationError extends Error {
|
|
24
|
+
reason;
|
|
25
|
+
code = 'invalid_capabilities_configuration';
|
|
26
|
+
constructor(reason) {
|
|
27
|
+
super(`invalid capabilities configuration: ${reason}`);
|
|
28
|
+
this.reason = reason;
|
|
29
|
+
this.name = 'CapabilityConfigurationError';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function environmentOverride(environment, name) {
|
|
33
|
+
const value = environment[name]?.trim();
|
|
34
|
+
return value === '' ? undefined : value;
|
|
35
|
+
}
|
|
36
|
+
function omittedDefault(value, fallback) { return value === undefined ? fallback : value; }
|
|
37
|
+
function invalid(field) { throw new CapabilityConfigurationError(field); }
|
|
38
|
+
function object(value, field, keys) {
|
|
39
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
40
|
+
invalid(field);
|
|
41
|
+
const record = value;
|
|
42
|
+
if (keys !== undefined && Object.keys(record).some(key => !keys.includes(key)))
|
|
43
|
+
invalid(field);
|
|
44
|
+
return record;
|
|
45
|
+
}
|
|
46
|
+
function bool(value, fallback, field) {
|
|
47
|
+
if (value === undefined)
|
|
48
|
+
return fallback;
|
|
49
|
+
if (typeof value !== 'boolean')
|
|
50
|
+
invalid(field);
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
function string(value, field, max = 8192) {
|
|
54
|
+
if (typeof value !== 'string' || value.trim() === '' || value.length > max || /[\u0000\r\n]/u.test(value))
|
|
55
|
+
invalid(field);
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
58
|
+
function integer(value, fallback, max, field) {
|
|
59
|
+
if (value === undefined)
|
|
60
|
+
return fallback;
|
|
61
|
+
if (typeof value !== 'number' || !Number.isInteger(value) || value < 1 || value > max)
|
|
62
|
+
invalid(field);
|
|
63
|
+
return value;
|
|
64
|
+
}
|
|
65
|
+
function stringMap(value, field) {
|
|
66
|
+
const entries = Object.entries(object(omittedDefault(value, {}), field));
|
|
67
|
+
if (entries.length > 64)
|
|
68
|
+
invalid(field);
|
|
69
|
+
return Object.fromEntries(entries.map(([key, val]) => {
|
|
70
|
+
if (!/^[A-Za-z_][A-Za-z0-9_-]{0,127}$/u.test(key))
|
|
71
|
+
invalid(field);
|
|
72
|
+
if (typeof val !== 'string' || val.length > 8192 || /[\u0000\r\n]/u.test(val))
|
|
73
|
+
invalid(field);
|
|
74
|
+
return [key, val];
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
export function interpolateCapabilityValue(value, environment) {
|
|
78
|
+
const resolved = value.replace(/\$\{([^}]+)\}/gu, (_match, name) => {
|
|
79
|
+
if (!ENV_NAME.test(name))
|
|
80
|
+
invalid('invalid_environment_reference');
|
|
81
|
+
const replacement = environment[name];
|
|
82
|
+
if (replacement === undefined || replacement.trim() === '')
|
|
83
|
+
invalid(`missing_environment:${name}`);
|
|
84
|
+
if (/[\u0000\r\n]/u.test(replacement))
|
|
85
|
+
invalid(`invalid_environment:${name}`);
|
|
86
|
+
return replacement;
|
|
87
|
+
});
|
|
88
|
+
if (resolved.length > 8192)
|
|
89
|
+
invalid('interpolated_value_too_large');
|
|
90
|
+
return resolved;
|
|
91
|
+
}
|
|
92
|
+
function missingEnvironment(values, environment) {
|
|
93
|
+
for (const value of values) {
|
|
94
|
+
for (const [, name = ''] of value.matchAll(/\$\{([^}]+)\}/gu)) {
|
|
95
|
+
if (ENV_NAME.test(name) && !environment[name]?.trim())
|
|
96
|
+
return name;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
function interpolateMap(value, environment) {
|
|
102
|
+
return Object.fromEntries(Object.entries(value).map(([key, val]) => [key, interpolateCapabilityValue(val, environment)]));
|
|
103
|
+
}
|
|
104
|
+
export function validateMcpEndpoint(value, headers = {}) {
|
|
105
|
+
let url;
|
|
106
|
+
try {
|
|
107
|
+
url = new URL(value);
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
invalid('invalid_mcp_endpoint');
|
|
111
|
+
}
|
|
112
|
+
const loopback = ['localhost', '127.0.0.1', '[::1]'].includes(url.hostname);
|
|
113
|
+
// Unknown custom headers may themselves be credentials. Only known non-auth metadata is safe on HTTP.
|
|
114
|
+
const hasAuth = Object.keys(headers).some(key => !MCP_NON_AUTH_HEADERS.some(name => name === key.toLowerCase()));
|
|
115
|
+
if (url.username || url.password || url.hash
|
|
116
|
+
|| (url.protocol !== 'https:' && (url.protocol !== 'http:' || !loopback || hasAuth)))
|
|
117
|
+
invalid('insecure_mcp_endpoint');
|
|
118
|
+
}
|
|
119
|
+
function moduleConfig(value, field, keys) {
|
|
120
|
+
return object(omittedDefault(value, {}), field, ['enabled', ...keys]);
|
|
121
|
+
}
|
|
122
|
+
export function parseCapabilityRegistry(input, environment = {}) {
|
|
123
|
+
const document = object(input, 'document', ['version', 'modules', 'mcpServers', 'frontbrainToolBudget']);
|
|
124
|
+
if (document.version !== 1)
|
|
125
|
+
invalid('version');
|
|
126
|
+
const modules = object(omittedDefault(document.modules, {}), 'modules', ['search', 'camera', 'coding', 'knowledge']);
|
|
127
|
+
const search = moduleConfig(modules.search, 'modules.search', ['provider', 'mcp', 'tavily']);
|
|
128
|
+
const camera = moduleConfig(modules.camera, 'modules.camera', []);
|
|
129
|
+
const coding = moduleConfig(modules.coding, 'modules.coding', []);
|
|
130
|
+
const knowledge = moduleConfig(modules.knowledge, 'modules.knowledge', ['exposeToCodex', 'exposeToBackends']);
|
|
131
|
+
const knowledgeGrants = backendGrants(knowledge.exposeToBackends, 'modules.knowledge.exposeToBackends');
|
|
132
|
+
const legacyKnowledgeGrant = bool(knowledge.exposeToCodex, false, 'modules.knowledge.exposeToCodex');
|
|
133
|
+
const requestedEnabled = bool(search.enabled, true, 'modules.search.enabled');
|
|
134
|
+
const configuredProvider = omittedDefault(search.provider, 'tavily');
|
|
135
|
+
if (configuredProvider !== 'tavily' && configuredProvider !== 'mcp')
|
|
136
|
+
invalid('modules.search.provider');
|
|
137
|
+
const requestedProvider = environmentOverride(environment, 'SEARCH_PROVIDER') ?? configuredProvider;
|
|
138
|
+
if (requestedProvider !== 'tavily' && requestedProvider !== 'mcp')
|
|
139
|
+
invalid('SEARCH_PROVIDER');
|
|
140
|
+
const overrides = [];
|
|
141
|
+
if (environment.SEARCH_PROVIDER?.trim())
|
|
142
|
+
overrides.push('SEARCH_PROVIDER');
|
|
143
|
+
let cameraEnabled = bool(camera.enabled, true, 'modules.camera.enabled');
|
|
144
|
+
const cameraOverride = environment.CAMERA_MODULE_ENABLED?.trim().toLowerCase();
|
|
145
|
+
if (cameraOverride) {
|
|
146
|
+
if (!['true', 'false', '1', '0', 'yes', 'no', 'on', 'off'].includes(cameraOverride))
|
|
147
|
+
invalid('CAMERA_MODULE_ENABLED');
|
|
148
|
+
cameraEnabled = ['true', '1', 'yes', 'on'].includes(cameraOverride);
|
|
149
|
+
overrides.push('CAMERA_MODULE_ENABLED');
|
|
150
|
+
}
|
|
151
|
+
let codingEnabled = bool(coding.enabled, true, 'modules.coding.enabled');
|
|
152
|
+
const codingOverride = environment.CODING_MODULE_ENABLED?.trim().toLowerCase();
|
|
153
|
+
if (codingOverride) {
|
|
154
|
+
if (!['true', 'false', '1', '0', 'yes', 'no', 'on', 'off'].includes(codingOverride))
|
|
155
|
+
invalid('CODING_MODULE_ENABLED');
|
|
156
|
+
codingEnabled = ['true', '1', 'yes', 'on'].includes(codingOverride);
|
|
157
|
+
overrides.push('CODING_MODULE_ENABLED');
|
|
158
|
+
}
|
|
159
|
+
const tavily = object(omittedDefault(search.tavily, {}), 'modules.search.tavily', ['apiKeyEnv']);
|
|
160
|
+
const apiKeyEnv = string(omittedDefault(tavily.apiKeyEnv, 'TAVILY_API_KEY'), 'modules.search.tavily.apiKeyEnv', 128);
|
|
161
|
+
if (!ENV_NAME.test(apiKeyEnv))
|
|
162
|
+
invalid('modules.search.tavily.apiKeyEnv');
|
|
163
|
+
// Search is optional: a missing Tavily key reuses the DashScope key through the Bailian preset, or turns search off.
|
|
164
|
+
const tavilyUnavailable = requestedEnabled && requestedProvider === 'tavily' && !environment[apiKeyEnv]?.trim();
|
|
165
|
+
const fallback = tavilyUnavailable && search.mcp === undefined && !environmentOverride(environment, 'SEARCH_MCP_URL')
|
|
166
|
+
&& Boolean(environment.DASHSCOPE_API_KEY?.trim()) ? 'bailian_mcp' : undefined;
|
|
167
|
+
let enabled = requestedEnabled && (!tavilyUnavailable || fallback !== undefined);
|
|
168
|
+
const provider = fallback === undefined ? requestedProvider : 'mcp';
|
|
169
|
+
let reason = tavilyUnavailable ? `missing_environment:${apiKeyEnv}` : undefined;
|
|
170
|
+
let mcp;
|
|
171
|
+
if (search.mcp !== undefined || (enabled && provider === 'mcp')) {
|
|
172
|
+
const config = object(omittedDefault(search.mcp, {}), 'modules.search.mcp', ['url', 'tool', 'headers', 'timeoutMs', 'maxResultBytes']);
|
|
173
|
+
const urlOverride = environmentOverride(environment, 'SEARCH_MCP_URL');
|
|
174
|
+
const toolOverride = environmentOverride(environment, 'SEARCH_MCP_TOOL');
|
|
175
|
+
const preset = !urlOverride && config.url === undefined;
|
|
176
|
+
const configuredUrl = string(omittedDefault(config.url, BAILIAN_SEARCH_MCP_URL), 'modules.search.mcp.url');
|
|
177
|
+
const rawUrl = string(urlOverride ?? configuredUrl, 'modules.search.mcp.url');
|
|
178
|
+
const configuredTool = string(omittedDefault(config.tool, preset ? BAILIAN_SEARCH_MCP_TOOL : 'web_search'), 'modules.search.mcp.tool', 256);
|
|
179
|
+
const tool = string(toolOverride ?? configuredTool, 'modules.search.mcp.tool', 256);
|
|
180
|
+
const rawHeaders = stringMap(omittedDefault(config.headers, preset ? { authorization: 'Bearer ${DASHSCOPE_API_KEY}' } : {}), 'modules.search.mcp.headers');
|
|
181
|
+
// A search endpoint whose key is not set turns search off, like a missing Tavily key.
|
|
182
|
+
const missing = enabled && provider === 'mcp' ? missingEnvironment([rawUrl, ...Object.values(rawHeaders)], environment) : undefined;
|
|
183
|
+
if (missing !== undefined) {
|
|
184
|
+
enabled = false;
|
|
185
|
+
reason = `missing_environment:${missing}`;
|
|
186
|
+
}
|
|
187
|
+
const headers = enabled && provider === 'mcp' ? interpolateMap(rawHeaders, environment) : rawHeaders;
|
|
188
|
+
const url = enabled && provider === 'mcp' ? interpolateCapabilityValue(rawUrl, environment) : rawUrl;
|
|
189
|
+
if (enabled && provider === 'mcp')
|
|
190
|
+
validateMcpEndpoint(url, headers);
|
|
191
|
+
mcp = { url, tool, headers,
|
|
192
|
+
timeoutMs: integer(config.timeoutMs, 8000, 60000, 'modules.search.mcp.timeoutMs'),
|
|
193
|
+
maxResultBytes: integer(config.maxResultBytes, 262144, 1048576, 'modules.search.mcp.maxResultBytes') };
|
|
194
|
+
if (urlOverride)
|
|
195
|
+
overrides.push('SEARCH_MCP_URL');
|
|
196
|
+
if (toolOverride)
|
|
197
|
+
overrides.push('SEARCH_MCP_TOOL');
|
|
198
|
+
}
|
|
199
|
+
const servers = object(omittedDefault(document.mcpServers, {}), 'mcpServers');
|
|
200
|
+
if (Object.keys(servers).length > 8)
|
|
201
|
+
invalid('mcpServers:max_8');
|
|
202
|
+
const mcpServers = Object.create(null);
|
|
203
|
+
const serverStatuses = [];
|
|
204
|
+
for (const [index, [name, value]] of Object.entries(servers).entries()) {
|
|
205
|
+
const safeName = SERVER_NAME.test(name) ? name : `invalid_server_${index + 1}`;
|
|
206
|
+
try {
|
|
207
|
+
if (!SERVER_NAME.test(name))
|
|
208
|
+
invalid('invalid_server_name');
|
|
209
|
+
if (name === 'nova_camera' || name === 'nova_knowledge')
|
|
210
|
+
invalid('reserved_server_name');
|
|
211
|
+
const server = parseServer(value, environment);
|
|
212
|
+
mcpServers[name] = server;
|
|
213
|
+
serverStatuses.push({ name, status: server.enabled ? 'configured' : 'disabled' });
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
serverStatuses.push({ name: safeName, status: 'failed', reason: error instanceof CapabilityConfigurationError ? error.reason : 'invalid_server' });
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return { version: 1, modules: {
|
|
220
|
+
search: { enabled, provider, tavily: { apiKeyEnv, ...(environment[apiKeyEnv] === undefined ? {} : { apiKey: environment[apiKeyEnv] }) }, ...(mcp === undefined ? {} : { mcp }),
|
|
221
|
+
...(fallback === undefined ? {} : { fallback }), ...(reason === undefined ? {} : { reason }) },
|
|
222
|
+
camera: { enabled: cameraEnabled }, coding: { enabled: codingEnabled },
|
|
223
|
+
knowledge: { enabled: bool(knowledge.enabled, false, 'modules.knowledge.enabled'),
|
|
224
|
+
exposeToCodex: knowledgeGrants?.codex ?? legacyKnowledgeGrant,
|
|
225
|
+
...(knowledgeGrants === undefined ? {} : { exposeToBackends: knowledgeGrants }) },
|
|
226
|
+
}, mcpServers, serverStatuses, overrides,
|
|
227
|
+
frontbrainToolBudget: integer(document.frontbrainToolBudget, DEFAULT_FRONTBRAIN_TOOL_BUDGET, 256, 'frontbrainToolBudget') };
|
|
228
|
+
}
|
|
229
|
+
function parseServer(value, environment) {
|
|
230
|
+
const config = object(value, 'server', ['enabled', 'transport', 'url', 'headers', 'command', 'args', 'env', 'tools', 'exposeTo', 'computerUse']);
|
|
231
|
+
const physical = config.computerUse === undefined ? undefined : object(config.computerUse, 'server.computerUse', ['resource']);
|
|
232
|
+
const computerUse = physical === undefined ? {} : { computerUse: { resource: physical.resource === null ? null : string(physical.resource, 'server.computerUse.resource', 512).trim() } };
|
|
233
|
+
const enabled = bool(config.enabled, true, 'server.enabled');
|
|
234
|
+
const transport = config.transport;
|
|
235
|
+
if (transport !== 'streamable-http' && transport !== 'stdio')
|
|
236
|
+
invalid('server.transport');
|
|
237
|
+
const exposure = object(omittedDefault(config.exposeTo, {}), 'server.exposeTo', ['frontbrain', 'codex', 'backends']);
|
|
238
|
+
const grants = backendGrants(exposure.backends, 'server.exposeTo.backends');
|
|
239
|
+
const legacyCodexGrant = bool(exposure.codex, true, 'server.exposeTo.codex');
|
|
240
|
+
const exposeTo = { frontbrain: bool(exposure.frontbrain, false, 'server.exposeTo.frontbrain'),
|
|
241
|
+
codex: grants?.codex ?? legacyCodexGrant,
|
|
242
|
+
...(grants === undefined ? {} : { backends: grants }) };
|
|
243
|
+
const rawTools = object(omittedDefault(config.tools, {}), 'server.tools');
|
|
244
|
+
if (Object.keys(rawTools).length > 32)
|
|
245
|
+
invalid('server.tools:max_32');
|
|
246
|
+
const tools = Object.fromEntries(Object.entries(rawTools).map(([name, value]) => {
|
|
247
|
+
string(name, 'server.tool_name', 256);
|
|
248
|
+
const tool = object(value, 'server.tool', ['enabled', 'timeoutMs', 'maxResultBytes', 'maxCallsPerTurn']);
|
|
249
|
+
return [name, { enabled: bool(tool.enabled, false, 'server.tool.enabled'),
|
|
250
|
+
timeoutMs: integer(tool.timeoutMs, 8000, 60000, 'server.tool.timeoutMs'),
|
|
251
|
+
maxResultBytes: integer(tool.maxResultBytes, 32768, 1048576, 'server.tool.maxResultBytes'),
|
|
252
|
+
maxCallsPerTurn: integer(tool.maxCallsPerTurn, 2, 32, 'server.tool.maxCallsPerTurn') }];
|
|
253
|
+
}));
|
|
254
|
+
if (transport === 'streamable-http') {
|
|
255
|
+
if (config.command !== undefined || config.args !== undefined || config.env !== undefined)
|
|
256
|
+
invalid('server.transport_fields');
|
|
257
|
+
const rawHeaders = stringMap(config.headers, 'server.headers');
|
|
258
|
+
const rawUrl = string(config.url, 'server.url');
|
|
259
|
+
const headers = enabled ? interpolateMap(rawHeaders, environment) : rawHeaders;
|
|
260
|
+
const url = enabled ? interpolateCapabilityValue(rawUrl, environment) : rawUrl;
|
|
261
|
+
if (enabled)
|
|
262
|
+
validateMcpEndpoint(url, headers);
|
|
263
|
+
return { ...computerUse, enabled, transport, url, urlInterpolated: /\$\{[A-Za-z_][A-Za-z0-9_]*\}/u.test(rawUrl), headers, tools, exposeTo };
|
|
264
|
+
}
|
|
265
|
+
if (config.url !== undefined || config.headers !== undefined)
|
|
266
|
+
invalid('server.transport_fields');
|
|
267
|
+
const command = string(config.command, 'server.command');
|
|
268
|
+
const args = omittedDefault(config.args, []);
|
|
269
|
+
if (!Array.isArray(args) || args.length > 64 || args.some(arg => typeof arg !== 'string' || arg.length > 8192 || arg.includes('\0')))
|
|
270
|
+
invalid('server.args');
|
|
271
|
+
const env = stringMap(config.env, 'server.env');
|
|
272
|
+
if (Object.keys(env).some(key => !ENV_NAME.test(key)))
|
|
273
|
+
invalid('server.env');
|
|
274
|
+
return { ...computerUse, enabled, transport, command, args: args, env: enabled ? interpolateMap(env, environment) : env, tools, exposeTo };
|
|
275
|
+
}
|
|
276
|
+
export function loadCapabilityRegistry(options = {}) {
|
|
277
|
+
const environment = options.environment ?? process.env;
|
|
278
|
+
const explicitPath = (options.path === '' ? undefined : options.path) ?? environmentOverride(environment, 'CAPABILITIES_CONFIG');
|
|
279
|
+
const path = explicitPath ?? DEFAULT_CAPABILITIES_PATH;
|
|
280
|
+
const explicit = explicitPath !== undefined;
|
|
281
|
+
const resolved = path.startsWith('~/') ? join(options.home ?? homedir(), path.slice(2)) : path;
|
|
282
|
+
let input;
|
|
283
|
+
try {
|
|
284
|
+
const bytes = readFileSync(resolved);
|
|
285
|
+
if (bytes.byteLength > MAX_CONFIG_BYTES)
|
|
286
|
+
invalid('file_too_large');
|
|
287
|
+
input = JSON.parse(bytes.toString('utf8'));
|
|
288
|
+
}
|
|
289
|
+
catch (error) {
|
|
290
|
+
if (!explicit && error.code === 'ENOENT')
|
|
291
|
+
input = { version: 1 };
|
|
292
|
+
else
|
|
293
|
+
throw error instanceof CapabilityConfigurationError ? error : new CapabilityConfigurationError('file_unreadable_or_invalid_json');
|
|
294
|
+
}
|
|
295
|
+
return parseCapabilityRegistry(input, environment);
|
|
296
|
+
}
|
|
297
|
+
export function capabilityStatus(registry, toolCount = null) {
|
|
298
|
+
return { modules: {
|
|
299
|
+
search: { enabled: registry.modules.search.enabled, provider: registry.modules.search.provider,
|
|
300
|
+
...(registry.modules.search.fallback === undefined ? {} : { fallback: registry.modules.search.fallback }),
|
|
301
|
+
...(registry.modules.search.reason === undefined ? {} : { reason: registry.modules.search.reason }) },
|
|
302
|
+
camera: registry.modules.camera, coding: registry.modules.coding, knowledge: registry.modules.knowledge,
|
|
303
|
+
}, servers: registry.serverStatuses, overrides: registry.overrides, toolCount, toolBudget: registry.frontbrainToolBudget };
|
|
304
|
+
}
|
|
305
|
+
export function inspectCapabilities(options = {}) {
|
|
306
|
+
try {
|
|
307
|
+
const registry = loadCapabilityRegistry(options);
|
|
308
|
+
// A switched or disabled search is a reported degradation, not a failed configuration.
|
|
309
|
+
return { ok: registry.serverStatuses.every(server => server.status !== 'failed'), ...capabilityStatus(registry) };
|
|
310
|
+
}
|
|
311
|
+
catch (error) {
|
|
312
|
+
return { ok: false, reason: error instanceof CapabilityConfigurationError ? error.reason : 'invalid_configuration' };
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
//# sourceMappingURL=capability-registry.js.map
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { selfHostedEndpoint } from './self-hosted.js';
|
|
2
|
+
/** Pure normalization and validation for one selected cascaded provider graph. */
|
|
3
|
+
import { ConfigurationError, OPENAI_BASE_URL, GEMINI_BASE_URL, cascadedCredentialField, DASHSCOPE_COMPATIBLE_BASE_URL, requireCascadedCredentials, resolveCascadedSelection, } from './config.js';
|
|
4
|
+
import { stripLikePython } from '../text/python-text.js';
|
|
5
|
+
export { DASHSCOPE_COMPATIBLE_BASE_URL } from './config.js';
|
|
6
|
+
export function requireSelectedCascadedRealtimeConfig(settings) {
|
|
7
|
+
const selection = resolveCascadedSelection(settings);
|
|
8
|
+
const credentials = requireCascadedCredentials(settings, selection);
|
|
9
|
+
const endpointing = resolveEndpointingConfig(settings);
|
|
10
|
+
const asr = resolveAsrConfig(settings, credentials.asrApiKey);
|
|
11
|
+
const llm = requireSelectedCascadedLlmConfig(settings);
|
|
12
|
+
const tts = resolveTtsConfig(settings, credentials.ttsApiKey);
|
|
13
|
+
return Object.freeze({ selection, endpointing, asr, llm, tts });
|
|
14
|
+
}
|
|
15
|
+
/** Text sessions require only their selected LLM, independent of speech configuration. */
|
|
16
|
+
export function requireSelectedCascadedLlmConfig(settings) {
|
|
17
|
+
const selection = resolveCascadedSelection(settings);
|
|
18
|
+
const field = cascadedCredentialField(selection.llmProvider);
|
|
19
|
+
const apiKey = stripLikePython(settings[field] ?? '');
|
|
20
|
+
if (!apiKey && selection.llmProvider !== 'self-hosted')
|
|
21
|
+
throw new ConfigurationError(`缺少 ${field.toUpperCase()}`);
|
|
22
|
+
return selection.llmProvider !== 'ark'
|
|
23
|
+
? Object.freeze({
|
|
24
|
+
provider: selection.llmProvider,
|
|
25
|
+
config: Object.freeze({
|
|
26
|
+
baseUrl: selection.llmProvider === 'self-hosted' ? selfHostedEndpoint(settings.self_hosted_llm_base_url, 'http', 'SELF_HOSTED_LLM_BASE_URL') : selection.llmProvider === 'openai' ? OPENAI_BASE_URL : selection.llmProvider === 'gemini' ? GEMINI_BASE_URL : selection.llmProvider === 'deepseek' ? 'https://api.deepseek.com' : DASHSCOPE_COMPATIBLE_BASE_URL,
|
|
27
|
+
...(selection.llmProvider !== 'qwen' ? { provider: selection.llmProvider } : {}),
|
|
28
|
+
apiKey: apiKey,
|
|
29
|
+
model: selection.llmModel,
|
|
30
|
+
}),
|
|
31
|
+
})
|
|
32
|
+
: Object.freeze({
|
|
33
|
+
provider: 'ark',
|
|
34
|
+
config: Object.freeze({
|
|
35
|
+
baseUrl: secureEndpoint(settings.volcengine_ark_base_url, 'https', 'VOLCENGINE_ARK_BASE_URL'),
|
|
36
|
+
apiKey: apiKey,
|
|
37
|
+
model: selection.llmModel,
|
|
38
|
+
}),
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function resolveEndpointingConfig(settings) {
|
|
42
|
+
if (!(settings.volcengine_vad_threshold > 0 && settings.volcengine_vad_threshold <= 1)) {
|
|
43
|
+
throw new ConfigurationError('VOLCENGINE_VAD_THRESHOLD 必须在 (0, 1] 内');
|
|
44
|
+
}
|
|
45
|
+
if (settings.volcengine_vad_pre_roll_ms < 0 || settings.volcengine_vad_speech_pad_ms < 0) {
|
|
46
|
+
throw new ConfigurationError('火山 VAD pre-roll 与 speech pad 不能为负数');
|
|
47
|
+
}
|
|
48
|
+
if (settings.volcengine_vad_min_speech_ms <= 0 || settings.volcengine_vad_silence_end_ms <= 0) {
|
|
49
|
+
throw new ConfigurationError('火山 VAD min speech 与 silence end 必须为正整数');
|
|
50
|
+
}
|
|
51
|
+
if (settings.volcengine_vad_max_utterance_ms < settings.volcengine_vad_min_speech_ms) {
|
|
52
|
+
throw new ConfigurationError('火山 VAD max utterance 不能短于 min speech');
|
|
53
|
+
}
|
|
54
|
+
return Object.freeze({
|
|
55
|
+
vadThreshold: settings.volcengine_vad_threshold,
|
|
56
|
+
vadPreRollMs: settings.volcengine_vad_pre_roll_ms,
|
|
57
|
+
vadMinSpeechMs: settings.volcengine_vad_min_speech_ms,
|
|
58
|
+
vadSilenceEndMs: settings.volcengine_vad_silence_end_ms,
|
|
59
|
+
vadSpeechPadMs: settings.volcengine_vad_speech_pad_ms,
|
|
60
|
+
vadMaxUtteranceMs: settings.volcengine_vad_max_utterance_ms,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
export function requireSelectedCascadedAsrConfig(settings) {
|
|
64
|
+
if (settings.cascade_asr_provider === 'self-hosted')
|
|
65
|
+
return resolveAsrConfig(settings, stripLikePython(settings.self_hosted_asr_api_key ?? ''));
|
|
66
|
+
if (settings.cascade_asr_provider === 'gemini')
|
|
67
|
+
return resolveGeminiSpeechConfig(settings, 'asr', stripLikePython(settings.gemini_api_key ?? ''));
|
|
68
|
+
const key = stripLikePython(settings.doubao_asr_api_key ?? '') || stripLikePython(settings.doubao_bigmodel_api_key ?? '');
|
|
69
|
+
if (!key)
|
|
70
|
+
throw new ConfigurationError('缺少 DOUBAO_ASR_API_KEY');
|
|
71
|
+
return resolveAsrConfig(settings, key);
|
|
72
|
+
}
|
|
73
|
+
function resolveAsrConfig(settings, apiKey) {
|
|
74
|
+
if (settings.cascade_asr_provider === 'self-hosted')
|
|
75
|
+
return { provider: 'self-hosted', endpoint: selfHostedEndpoint(settings.self_hosted_asr_url, 'ws', 'SELF_HOSTED_ASR_URL'), apiKey };
|
|
76
|
+
if (settings.cascade_asr_provider === 'gemini')
|
|
77
|
+
return resolveGeminiSpeechConfig(settings, 'asr', apiKey);
|
|
78
|
+
if (settings.doubao_asr_chunk_ms <= 0) {
|
|
79
|
+
throw new ConfigurationError('DOUBAO_ASR_CHUNK_MS 必须为正整数');
|
|
80
|
+
}
|
|
81
|
+
const voiceprint = settings.doubao_asr_voiceprint_enabled
|
|
82
|
+
? { id: settings.doubao_asr_voiceprint_id, name: settings.doubao_asr_voiceprint_name } : undefined;
|
|
83
|
+
if (voiceprint && (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(voiceprint.id)
|
|
84
|
+
|| !voiceprint.name.trim() || /^\d+$/.test(voiceprint.name)
|
|
85
|
+
|| voiceprint.name.length > 128 || /[\u0000-\u001f\u007f]/.test(voiceprint.name))) {
|
|
86
|
+
throw new ConfigurationError('请先注册有效声纹,再开启火山 ASR 声纹验证');
|
|
87
|
+
}
|
|
88
|
+
return Object.freeze({
|
|
89
|
+
...(voiceprint ? { voiceprint } : {}),
|
|
90
|
+
...(settings.doubao_asr_voiceprint_health_url ? { voiceprintHealthUrl: secureEndpoint(settings.doubao_asr_voiceprint_health_url, 'https', 'DOUBAO_ASR_VOICEPRINT_HEALTH_URL') } : {}),
|
|
91
|
+
endpoint: secureEndpoint(settings.doubao_asr_endpoint, 'wss', 'DOUBAO_ASR_ENDPOINT'),
|
|
92
|
+
resourceId: requiredSetting(settings.doubao_asr_resource_id, 'DOUBAO_ASR_RESOURCE_ID'),
|
|
93
|
+
apiKey,
|
|
94
|
+
chunkMs: settings.doubao_asr_chunk_ms,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
function resolveTtsConfig(settings, apiKey) {
|
|
98
|
+
if (settings.cascade_tts_provider === 'self-hosted')
|
|
99
|
+
return { provider: 'self-hosted', endpoint: selfHostedEndpoint(settings.self_hosted_tts_url, 'http', 'SELF_HOSTED_TTS_URL'), apiKey };
|
|
100
|
+
if (settings.cascade_tts_provider === 'gemini')
|
|
101
|
+
return resolveGeminiSpeechConfig(settings, 'tts', apiKey);
|
|
102
|
+
if (settings.doubao_tts_output_sample_rate !== 24_000) {
|
|
103
|
+
throw new ConfigurationError('DOUBAO_TTS_OUTPUT_SAMPLE_RATE 必须为 24000');
|
|
104
|
+
}
|
|
105
|
+
return Object.freeze({
|
|
106
|
+
endpoint: secureEndpoint(settings.doubao_tts_endpoint, 'wss', 'DOUBAO_TTS_ENDPOINT'),
|
|
107
|
+
resourceId: requiredSetting(settings.doubao_tts_resource_id, 'DOUBAO_TTS_RESOURCE_ID'),
|
|
108
|
+
voice: requiredSetting(settings.doubao_tts_voice, 'DOUBAO_TTS_VOICE'),
|
|
109
|
+
apiKey,
|
|
110
|
+
outputSampleRate: 24_000,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
function requiredSetting(value, name) {
|
|
114
|
+
const normalized = stripLikePython(value);
|
|
115
|
+
if (normalized === '')
|
|
116
|
+
throw new ConfigurationError(`${name} 不能为空`);
|
|
117
|
+
return normalized;
|
|
118
|
+
}
|
|
119
|
+
function secureEndpoint(value, scheme, name) {
|
|
120
|
+
let normalized = stripLikePython(value);
|
|
121
|
+
while (normalized.endsWith('/'))
|
|
122
|
+
normalized = normalized.slice(0, -1);
|
|
123
|
+
const separator = normalized.indexOf('://');
|
|
124
|
+
const tail = separator < 0 ? '' : normalized.slice(separator + 3);
|
|
125
|
+
const end = tail.search(/[/?#]/u);
|
|
126
|
+
const authority = end < 0 ? tail : tail.slice(0, end);
|
|
127
|
+
let parsed = null;
|
|
128
|
+
try {
|
|
129
|
+
parsed = new URL(normalized);
|
|
130
|
+
}
|
|
131
|
+
catch { /* stable field-only error below */ }
|
|
132
|
+
const valid = parsed?.protocol === `${scheme}:` && parsed.hostname !== ''
|
|
133
|
+
&& !authority.includes('@') && parsed.username === '' && parsed.password === ''
|
|
134
|
+
&& parsed.hash === '';
|
|
135
|
+
if (!valid)
|
|
136
|
+
throw new ConfigurationError(`${name} 必须是安全的 ${scheme}:// 地址`);
|
|
137
|
+
return normalized;
|
|
138
|
+
}
|
|
139
|
+
function resolveGeminiSpeechConfig(settings, service, apiKey) {
|
|
140
|
+
if (!apiKey)
|
|
141
|
+
throw new ConfigurationError('缺少 GEMINI_API_KEY');
|
|
142
|
+
return { provider: 'gemini', endpoint: 'https://generativelanguage.googleapis.com/v1beta', apiKey,
|
|
143
|
+
model: requiredSetting(settings[service === 'asr' ? 'gemini_asr_model' : 'gemini_tts_model'], `GEMINI_${service.toUpperCase()}_MODEL`),
|
|
144
|
+
voice: service === 'tts' ? requiredSetting(settings.gemini_tts_voice, 'GEMINI_TTS_VOICE') : settings.gemini_tts_voice };
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=cascaded-realtime-config.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Every backend a project session can bind to. Codex keeps its native app-server transport. */
|
|
2
|
+
export const CODING_BACKEND_IDS = Object.freeze(['codex', 'opencode', 'codebuddy', 'pi', 'deepseek']);
|
|
3
|
+
/** Backends reached through the Agent Client Protocol. */
|
|
4
|
+
export const ACP_BACKEND_IDS = Object.freeze(['opencode', 'codebuddy', 'pi', 'deepseek']);
|
|
5
|
+
export function isAcpBackend(value) {
|
|
6
|
+
return ACP_BACKEND_IDS.includes(value);
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=coding-backends.js.map
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { isAbsolute } from 'node:path';
|
|
3
|
+
import { ACP_BACKEND_IDS } from './coding-backends.js';
|
|
4
|
+
/** Codex sessions keep the app-server's own home semantics under one fixed profile. */
|
|
5
|
+
export const CODEX_PROFILE_ID = 'codex:legacy';
|
|
6
|
+
/** Per-backend ACP executable override, e.g. `OPENCODE_ACP_BIN`. */
|
|
7
|
+
export function acpBinaryEnvironmentName(backendId) {
|
|
8
|
+
return `${backendId.toUpperCase()}_ACP_BIN`;
|
|
9
|
+
}
|
|
10
|
+
// Only source locations inherited by ACP profiles; never hash credentials or config contents.
|
|
11
|
+
const CONFIG_SOURCE_ENV = ['HOME', 'APPDATA', 'LOCALAPPDATA', 'USERPROFILE', 'HOMEDRIVE', 'HOMEPATH',
|
|
12
|
+
'XDG_CONFIG_HOME', 'XDG_DATA_HOME', 'XDG_STATE_HOME', 'XDG_CACHE_HOME', 'XDG_RUNTIME_DIR'];
|
|
13
|
+
const BACKEND_CONFIG_ENV = {
|
|
14
|
+
opencode: ['OPENCODE_CONFIG', 'OPENCODE_CONFIG_DIR'], codebuddy: [], pi: ['PI_CODING_AGENT_DIR'], deepseek: ['DSH_HOME'],
|
|
15
|
+
};
|
|
16
|
+
const CONFIG_PATH_BACKENDS = new Set(['opencode', 'pi', 'deepseek']);
|
|
17
|
+
const defaultProfileId = (backendId) => `${backendId}:default`;
|
|
18
|
+
/**
|
|
19
|
+
* Rebuild the available identities from effective sources. An identity changes whenever the
|
|
20
|
+
* binary or any config-source location changes, so a drifted session is refused rather than
|
|
21
|
+
* resumed against a different account; ordinary token refresh does not rebind.
|
|
22
|
+
*/
|
|
23
|
+
export function runtimeCodingProfiles(registry, environment) {
|
|
24
|
+
const defaults = { ...registry.defaults };
|
|
25
|
+
const profiles = Object.create(null);
|
|
26
|
+
const builtin = Object.fromEntries(ACP_BACKEND_IDS.map(backendId => [defaultProfileId(backendId), {
|
|
27
|
+
backendId, binaryPath: environment[acpBinaryEnvironmentName(backendId)] ?? '', configPath: '',
|
|
28
|
+
}]));
|
|
29
|
+
for (const [settingsId, profile] of Object.entries({ ...builtin, ...registry.profiles })) {
|
|
30
|
+
const env = { ...environment };
|
|
31
|
+
if (profile.configPath) {
|
|
32
|
+
const key = BACKEND_CONFIG_ENV[profile.backendId][0];
|
|
33
|
+
if (key !== undefined)
|
|
34
|
+
env[key] = profile.configPath;
|
|
35
|
+
}
|
|
36
|
+
const sources = Object.fromEntries([...CONFIG_SOURCE_ENV, ...BACKEND_CONFIG_ENV[profile.backendId]]
|
|
37
|
+
.map(key => [key, env[key] ?? null]));
|
|
38
|
+
const id = `${profile.backendId}:source-v1:${createHash('sha256')
|
|
39
|
+
.update(JSON.stringify({ backendId: profile.backendId, binaryPath: profile.binaryPath, sources })).digest('hex')}`;
|
|
40
|
+
profiles[id] = Object.freeze({ backendId: profile.backendId, binaryPath: profile.binaryPath, environment: Object.freeze(env) });
|
|
41
|
+
if (registry.defaults[profile.backendId] === settingsId)
|
|
42
|
+
defaults[profile.backendId] = id;
|
|
43
|
+
}
|
|
44
|
+
return { defaults: Object.freeze(defaults), profiles: Object.freeze(profiles) };
|
|
45
|
+
}
|
|
46
|
+
/** Parse the host-private `CODING_PROFILES` document; every profile id is its content hash. */
|
|
47
|
+
export function parseCodingProfiles(raw) {
|
|
48
|
+
const defaults = Object.fromEntries(ACP_BACKEND_IDS.map(id => [id, defaultProfileId(id)]));
|
|
49
|
+
const profiles = Object.create(null);
|
|
50
|
+
if (raw === undefined || raw === '')
|
|
51
|
+
return { defaults, profiles };
|
|
52
|
+
const fail = () => { throw new Error('invalid_coding_profiles'); };
|
|
53
|
+
const record = (value) => {
|
|
54
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
55
|
+
return fail();
|
|
56
|
+
return value;
|
|
57
|
+
};
|
|
58
|
+
let parsed;
|
|
59
|
+
try {
|
|
60
|
+
parsed = JSON.parse(raw);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return fail();
|
|
64
|
+
}
|
|
65
|
+
const document = record(parsed);
|
|
66
|
+
if (Object.keys(document).sort().join(',') !== 'defaults,profiles')
|
|
67
|
+
return fail();
|
|
68
|
+
for (const [id, value] of Object.entries(record(document.profiles))) {
|
|
69
|
+
const source = record(value);
|
|
70
|
+
if (Object.keys(source).sort().join(',') !== 'backendId,binaryPath,configPath')
|
|
71
|
+
return fail();
|
|
72
|
+
const { backendId, binaryPath, configPath } = source;
|
|
73
|
+
if (!ACP_BACKEND_IDS.includes(backendId))
|
|
74
|
+
return fail();
|
|
75
|
+
for (const path of [binaryPath, configPath]) {
|
|
76
|
+
if (typeof path !== 'string' || (path !== '' && !isAbsolute(path)) || /[\x00-\x1f\x7f]/u.test(path))
|
|
77
|
+
return fail();
|
|
78
|
+
}
|
|
79
|
+
if (configPath && !CONFIG_PATH_BACKENDS.has(backendId))
|
|
80
|
+
return fail();
|
|
81
|
+
const profile = { backendId, binaryPath, configPath };
|
|
82
|
+
const expected = `${profile.backendId}:${createHash('sha256').update(JSON.stringify(profile)).digest('hex')}`;
|
|
83
|
+
if (id !== expected)
|
|
84
|
+
return fail();
|
|
85
|
+
profiles[id] = Object.freeze(profile);
|
|
86
|
+
}
|
|
87
|
+
const selected = record(document.defaults);
|
|
88
|
+
if (Object.keys(selected).sort().join(',') !== [...ACP_BACKEND_IDS].sort().join(','))
|
|
89
|
+
return fail();
|
|
90
|
+
for (const backend of ACP_BACKEND_IDS) {
|
|
91
|
+
const id = selected[backend];
|
|
92
|
+
if (typeof id !== 'string' || (id !== defaults[backend] && profiles[id]?.backendId !== backend))
|
|
93
|
+
return fail();
|
|
94
|
+
defaults[backend] = id;
|
|
95
|
+
}
|
|
96
|
+
return { defaults, profiles: Object.freeze(profiles) };
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=coding-profiles.js.map
|