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,463 @@
|
|
|
1
|
+
import { EAGER_CODING_PROGRESS_INSTRUCTIONS } from './progress-instructions.js';
|
|
2
|
+
import { codexAgentDescriptor, codingAgentControllerFactory } from './controller.js';
|
|
3
|
+
import { OwnedCodexAppServerTransport, } from './app-server-transport.js';
|
|
4
|
+
import { codexCredentialApiKey } from './host-config.js';
|
|
5
|
+
import { ProjectStore, MAX_PROJECT_WORKSPACE_NAME, ProjectStateError, } from '../../projects/project-store.js';
|
|
6
|
+
import { hostWorkspacePath, } from './process-owner.js';
|
|
7
|
+
import { CodexHostConfigurationError } from './host-config.js';
|
|
8
|
+
import { ProjectCodexAdapter } from './adapter-project.js';
|
|
9
|
+
import { ProjectConfirmationController } from '../../projects/project-confirmation.js';
|
|
10
|
+
import { HostApprovalController } from '../../core/approval.js';
|
|
11
|
+
import {} from '../../core/approval-port.js';
|
|
12
|
+
import { basename } from 'node:path';
|
|
13
|
+
import { randomUUID } from 'node:crypto';
|
|
14
|
+
import { hostPersistentHomeFromConfig } from '../../projects/host-paths.js';
|
|
15
|
+
import { hostCodexHomeValue } from './process-owner.js';
|
|
16
|
+
import { resolveCodexLaunchProfile, } from './launch-profile.js';
|
|
17
|
+
import { CodexTransportError } from './app-server-transport.js';
|
|
18
|
+
import { CODING_BACKEND_IDS, isAcpBackend } from '../../config/coding-backends.js';
|
|
19
|
+
import { CODEX_PROFILE_ID } from '../../config/coding-profiles.js';
|
|
20
|
+
export class OwnedCodexBackendTransportFactory {
|
|
21
|
+
available = true;
|
|
22
|
+
#options;
|
|
23
|
+
constructor(options) {
|
|
24
|
+
this.#options = options;
|
|
25
|
+
}
|
|
26
|
+
create(binding) {
|
|
27
|
+
const project = binding.mode === 'project';
|
|
28
|
+
const codexHome = project ? binding.codexHome : this.#options.ephemeralHomeFactory();
|
|
29
|
+
if (codexHome === null)
|
|
30
|
+
throw new CodexHostConfigurationError('codex_host_unavailable');
|
|
31
|
+
const transport = new OwnedCodexAppServerTransport({
|
|
32
|
+
config: {
|
|
33
|
+
...(binding.managedMcp === undefined ? {} : { managedMcp: binding.managedMcp }),
|
|
34
|
+
generateTitles: project && binding.resumeThreadId === null,
|
|
35
|
+
preserveHome: binding.preserveHome ?? false,
|
|
36
|
+
binary: binding.binary,
|
|
37
|
+
prefixArgs: binding.binaryPrefixArgs,
|
|
38
|
+
workspace: binding.workspace,
|
|
39
|
+
codexHome,
|
|
40
|
+
apiKey: codexCredentialApiKey(binding.credential),
|
|
41
|
+
developerInstructions: binding.eagerProgress === true ? EAGER_CODING_PROGRESS_INSTRUCTIONS : null,
|
|
42
|
+
eagerProgress: binding.eagerProgress === true,
|
|
43
|
+
resumeThreadId: binding.resumeThreadId,
|
|
44
|
+
persistent: project,
|
|
45
|
+
workingInterval: binding.workingInterval,
|
|
46
|
+
launchProfile: binding.launchProfile,
|
|
47
|
+
...(binding.approvalController === null
|
|
48
|
+
? {}
|
|
49
|
+
: { approvalController: binding.approvalController }),
|
|
50
|
+
},
|
|
51
|
+
processFactory: this.#options.processFactory,
|
|
52
|
+
credentialSnapshotter: this.#options.credentialSnapshotter,
|
|
53
|
+
preflightRunner: this.#options.preflightRunner,
|
|
54
|
+
schemaProbe: this.#options.schemaProbe,
|
|
55
|
+
});
|
|
56
|
+
return new CredentialHomeOwningTransport(transport, this.#options.credentialSnapshotter, codexHome);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
class CredentialHomeOwningTransport {
|
|
60
|
+
inner;
|
|
61
|
+
credentials;
|
|
62
|
+
codexHome;
|
|
63
|
+
#closeOperation = null;
|
|
64
|
+
constructor(inner, credentials, codexHome) {
|
|
65
|
+
this.inner = inner;
|
|
66
|
+
this.credentials = credentials;
|
|
67
|
+
this.codexHome = codexHome;
|
|
68
|
+
}
|
|
69
|
+
preflight(deadline) {
|
|
70
|
+
return this.inner.preflight(deadline);
|
|
71
|
+
}
|
|
72
|
+
prewarmConnection(deadline) {
|
|
73
|
+
if (!this.inner.prewarmConnection)
|
|
74
|
+
throw new CodexHostConfigurationError('codex_host_unavailable');
|
|
75
|
+
return this.inner.prewarmConnection(deadline);
|
|
76
|
+
}
|
|
77
|
+
bindProject(binding) {
|
|
78
|
+
if (!this.inner.bindProject)
|
|
79
|
+
throw new CodexHostConfigurationError('codex_host_unavailable');
|
|
80
|
+
this.inner.bindProject(binding);
|
|
81
|
+
}
|
|
82
|
+
prewarm(deadline) {
|
|
83
|
+
return this.inner.prewarm(deadline);
|
|
84
|
+
}
|
|
85
|
+
run(input, observer, deadline, completionDeadline) {
|
|
86
|
+
return this.inner.run(input, observer, deadline, completionDeadline);
|
|
87
|
+
}
|
|
88
|
+
steer(input, deadline) {
|
|
89
|
+
return this.inner.steer(input, deadline);
|
|
90
|
+
}
|
|
91
|
+
close(reason) {
|
|
92
|
+
if (this.#closeOperation !== null)
|
|
93
|
+
return this.#closeOperation;
|
|
94
|
+
const work = this.#close(reason);
|
|
95
|
+
const exposed = work.catch(error => {
|
|
96
|
+
if (this.#closeOperation === exposed)
|
|
97
|
+
this.#closeOperation = null;
|
|
98
|
+
throw error;
|
|
99
|
+
});
|
|
100
|
+
this.#closeOperation = exposed;
|
|
101
|
+
return exposed;
|
|
102
|
+
}
|
|
103
|
+
async #close(reason) {
|
|
104
|
+
await this.inner.close(reason);
|
|
105
|
+
await this.credentials.removeEphemeralHome(this.codexHome);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
export const unavailableCodexBackendTransportFactory = Object.freeze({
|
|
109
|
+
available: false,
|
|
110
|
+
create: () => {
|
|
111
|
+
throw new CodexHostConfigurationError('codex_host_unavailable');
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
const LEGACY_CODEX_BINDING = Object.freeze({ backend_id: 'codex', backend_profile_id: CODEX_PROFILE_ID });
|
|
115
|
+
export async function createCodexAssemblyResource(options) {
|
|
116
|
+
let available = false;
|
|
117
|
+
try {
|
|
118
|
+
available = options.transportFactory.available === true;
|
|
119
|
+
}
|
|
120
|
+
catch { /* safe failure below */ }
|
|
121
|
+
if (!available) {
|
|
122
|
+
throw new CodexHostConfigurationError('codex_host_unavailable');
|
|
123
|
+
}
|
|
124
|
+
return await createProjectResource(options);
|
|
125
|
+
}
|
|
126
|
+
function isCodexTransport(value) {
|
|
127
|
+
try {
|
|
128
|
+
return typeof value === 'object'
|
|
129
|
+
&& value !== null
|
|
130
|
+
&& typeof value.preflight === 'function'
|
|
131
|
+
&& typeof value.prewarm === 'function'
|
|
132
|
+
&& typeof value.run === 'function'
|
|
133
|
+
&& typeof value.steer === 'function'
|
|
134
|
+
&& typeof value.close === 'function';
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
async function createProjectResource(options) {
|
|
141
|
+
const host = options.projectHost;
|
|
142
|
+
const stateRoot = options.config.stateRoot;
|
|
143
|
+
const managedRoot = options.config.managedRoot;
|
|
144
|
+
const launchProfile = resolveCodexLaunchProfile({
|
|
145
|
+
approvalMode: options.config.codexApprovalMode,
|
|
146
|
+
project: true,
|
|
147
|
+
foregroundBroker: options.codexApprovalBroker !== undefined || options.sharedApprovalController !== undefined,
|
|
148
|
+
});
|
|
149
|
+
const approvalController = launchProfile.controller === 'present'
|
|
150
|
+
? options.sharedApprovalController ?? new HostApprovalController({ clock: options.clock, idFactory: options.idFactory,
|
|
151
|
+
...(options.onDiagnostic === undefined ? {} : { onDiagnostic: options.onDiagnostic }) })
|
|
152
|
+
: null;
|
|
153
|
+
if (launchProfile.id === 'ask_headless') {
|
|
154
|
+
try {
|
|
155
|
+
options.onDiagnostic?.('ask_headless_no_broker');
|
|
156
|
+
}
|
|
157
|
+
catch { /* diagnostics are advisory */ }
|
|
158
|
+
}
|
|
159
|
+
const ownsApproval = options.sharedApprovalController === undefined;
|
|
160
|
+
const approvalScopes = new Map();
|
|
161
|
+
const scopedApproval = (work, identity = { executor: 'codex', display_name: 'Codex' }) => {
|
|
162
|
+
if (approvalController === null)
|
|
163
|
+
return null;
|
|
164
|
+
const port = approvalController.forWork(work);
|
|
165
|
+
const scoped = {
|
|
166
|
+
offer: async (offer, signal) => {
|
|
167
|
+
const entry = { port: scoped, resolution: null };
|
|
168
|
+
// A duplicate offer must not replace the active request's cleanup ownership.
|
|
169
|
+
if (!approvalScopes.has(work.work_id))
|
|
170
|
+
approvalScopes.set(work.work_id, entry);
|
|
171
|
+
try {
|
|
172
|
+
const resolution = await port.offer({ ...offer, executorIdentity: identity }, signal);
|
|
173
|
+
entry.resolution = resolution;
|
|
174
|
+
if (resolution === null && approvalScopes.get(work.work_id) === entry)
|
|
175
|
+
approvalScopes.delete(work.work_id);
|
|
176
|
+
return resolution;
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
if (approvalScopes.get(work.work_id) === entry)
|
|
180
|
+
approvalScopes.delete(work.work_id);
|
|
181
|
+
throw error;
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
consume: resolution => {
|
|
185
|
+
const entry = approvalScopes.get(work.work_id);
|
|
186
|
+
if (entry?.port === scoped && entry.resolution === resolution)
|
|
187
|
+
approvalScopes.delete(work.work_id);
|
|
188
|
+
return port.consume(resolution);
|
|
189
|
+
},
|
|
190
|
+
invalidate: reason => {
|
|
191
|
+
if (approvalScopes.get(work.work_id)?.port === scoped)
|
|
192
|
+
approvalScopes.delete(work.work_id);
|
|
193
|
+
return port.invalidate(reason);
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
return scoped;
|
|
197
|
+
};
|
|
198
|
+
const invalidateApprovals = (reason) => {
|
|
199
|
+
for (const { port } of [...approvalScopes.values()])
|
|
200
|
+
port.invalidate(reason);
|
|
201
|
+
if (ownsApproval)
|
|
202
|
+
approvalController?.invalidate(reason);
|
|
203
|
+
};
|
|
204
|
+
const unsubscribeApproval = approvalController === null || !ownsApproval
|
|
205
|
+
? null
|
|
206
|
+
: approvalController.observe(view => { options.codexApprovalBroker?.publish(view); });
|
|
207
|
+
if (host === undefined) {
|
|
208
|
+
unsubscribeApproval?.();
|
|
209
|
+
throw new CodexHostConfigurationError('codex_project_host_unsupported');
|
|
210
|
+
}
|
|
211
|
+
const warmHome = options.config.prewarm && options.config.localCodexHome
|
|
212
|
+
? hostPersistentHomeFromConfig(options.config.localCodexHome, [options.config.localCodexHome]) : null;
|
|
213
|
+
let warmReady = false;
|
|
214
|
+
const routing = options.backends;
|
|
215
|
+
let defaultBackend = routing?.initialBackend ?? 'codex';
|
|
216
|
+
const defaultBinding = () => defaultBackend === 'codex' || routing === undefined || !isAcpBackend(defaultBackend)
|
|
217
|
+
? LEGACY_CODEX_BINDING
|
|
218
|
+
: { backend_id: defaultBackend, backend_profile_id: routing.defaultProfile(defaultBackend) };
|
|
219
|
+
let store = null;
|
|
220
|
+
let startupTransport = null;
|
|
221
|
+
try {
|
|
222
|
+
startupTransport = options.transportFactory.create(Object.freeze({
|
|
223
|
+
...(options.managedMcp === undefined ? {} : { managedMcp: options.managedMcp }),
|
|
224
|
+
mode: warmHome === null ? 'live' : 'project',
|
|
225
|
+
preserveHome: warmHome !== null,
|
|
226
|
+
binary: options.config.binary,
|
|
227
|
+
binaryPrefixArgs: options.config.binaryPrefixArgs,
|
|
228
|
+
workspace: options.config.workspace,
|
|
229
|
+
codexHome: warmHome,
|
|
230
|
+
credential: options.config.credential,
|
|
231
|
+
resumeThreadId: null,
|
|
232
|
+
workingInterval: options.config.workingInterval,
|
|
233
|
+
eagerProgress: options.config.eagerProgress,
|
|
234
|
+
launchProfile: warmHome !== null ? launchProfile : resolveCodexLaunchProfile({
|
|
235
|
+
approvalMode: options.config.codexApprovalMode, project: false, foregroundBroker: false,
|
|
236
|
+
}),
|
|
237
|
+
approvalController: warmHome === null ? null : scopedApproval({ work_id: randomUUID(), project: '', title: 'Codex startup' }),
|
|
238
|
+
}));
|
|
239
|
+
if (!isCodexTransport(startupTransport)) {
|
|
240
|
+
throw new CodexHostConfigurationError('codex_host_unavailable');
|
|
241
|
+
}
|
|
242
|
+
store = await ProjectStore.open({
|
|
243
|
+
stateRoot,
|
|
244
|
+
managedRoot,
|
|
245
|
+
nativeLocks: host.nativeLocks,
|
|
246
|
+
rootFiles: host.rootFiles,
|
|
247
|
+
live: true,
|
|
248
|
+
now: options.now ?? (() => Date.now() / 1_000),
|
|
249
|
+
});
|
|
250
|
+
const derivedName = basename(hostWorkspacePath(options.config.workspace)) || 'workspace';
|
|
251
|
+
const displayName = [...derivedName].slice(0, MAX_PROJECT_WORKSPACE_NAME).join('');
|
|
252
|
+
await store.ensureImported(displayName, options.config.workspace);
|
|
253
|
+
const confirmation = new ProjectConfirmationController({
|
|
254
|
+
clock: options.clock,
|
|
255
|
+
idFactory: options.idFactory,
|
|
256
|
+
});
|
|
257
|
+
const adapter = new ProjectCodexAdapter({
|
|
258
|
+
...(options.managedMcp ? { managedMcp: options.managedMcp } : {}),
|
|
259
|
+
store,
|
|
260
|
+
...(options.config.localCodexHome === undefined ? {} : { localCodexHome: options.config.localCodexHome }),
|
|
261
|
+
confirmation,
|
|
262
|
+
...(approvalController === null ? {} : { codexApproval: approvalController }),
|
|
263
|
+
defaultBackend: defaultBinding,
|
|
264
|
+
transportFactory: {
|
|
265
|
+
create: binding => {
|
|
266
|
+
if (binding.backend_id !== 'codex') {
|
|
267
|
+
const backendId = binding.backend_id;
|
|
268
|
+
// A session bound to a backend this host cannot route stays recorded and retryable.
|
|
269
|
+
if (routing === undefined || !isAcpBackend(backendId))
|
|
270
|
+
throw new CodexTransportError('resume_unavailable');
|
|
271
|
+
const acpApproval = scopedApproval(binding.work, { executor: 'codex', display_name: routing.displayName(backendId) });
|
|
272
|
+
try {
|
|
273
|
+
return routing.create({ backendId, profileId: binding.backend_profile_id, workspace: binding.workspace,
|
|
274
|
+
resumeSessionId: binding.resumeThreadId, approvalController: acpApproval });
|
|
275
|
+
}
|
|
276
|
+
catch (error) {
|
|
277
|
+
acpApproval?.invalidate('transport_creation_failed');
|
|
278
|
+
throw error;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
const codexHome = binding.codexHome;
|
|
282
|
+
if (codexHome === null)
|
|
283
|
+
throw new CodexHostConfigurationError('codex_host_unavailable');
|
|
284
|
+
const approval = scopedApproval(binding.work);
|
|
285
|
+
try {
|
|
286
|
+
if (warmReady && warmHome !== null && startupTransport?.bindProject
|
|
287
|
+
&& hostCodexHomeValue(codexHome).path === hostCodexHomeValue(warmHome).path) {
|
|
288
|
+
warmReady = false;
|
|
289
|
+
startupTransport.bindProject({ workspace: binding.workspace, resumeThreadId: binding.resumeThreadId,
|
|
290
|
+
approvalController: approval });
|
|
291
|
+
try {
|
|
292
|
+
options.onDiagnostic?.('project_prewarm_reused');
|
|
293
|
+
}
|
|
294
|
+
catch { /* advisory */ }
|
|
295
|
+
return startupTransport;
|
|
296
|
+
}
|
|
297
|
+
const transport = options.transportFactory.create(Object.freeze({
|
|
298
|
+
...(options.managedMcp === undefined ? {} : { managedMcp: options.managedMcp }),
|
|
299
|
+
preserveHome: binding.preserveHome ?? false,
|
|
300
|
+
mode: 'project',
|
|
301
|
+
binary: options.config.binary,
|
|
302
|
+
binaryPrefixArgs: options.config.binaryPrefixArgs,
|
|
303
|
+
workspace: binding.workspace,
|
|
304
|
+
codexHome,
|
|
305
|
+
credential: options.config.credential,
|
|
306
|
+
resumeThreadId: binding.resumeThreadId,
|
|
307
|
+
workingInterval: options.config.workingInterval,
|
|
308
|
+
eagerProgress: options.config.eagerProgress,
|
|
309
|
+
launchProfile,
|
|
310
|
+
approvalController: approval,
|
|
311
|
+
}));
|
|
312
|
+
if (!isCodexTransport(transport)) {
|
|
313
|
+
throw new CodexHostConfigurationError('codex_host_unavailable');
|
|
314
|
+
}
|
|
315
|
+
return transport;
|
|
316
|
+
}
|
|
317
|
+
catch (error) {
|
|
318
|
+
approval?.invalidate('transport_creation_failed');
|
|
319
|
+
throw error;
|
|
320
|
+
}
|
|
321
|
+
},
|
|
322
|
+
},
|
|
323
|
+
...(options.onProjectView === undefined ? {} : { onProjectView: options.onProjectView }),
|
|
324
|
+
});
|
|
325
|
+
await adapter.initialize();
|
|
326
|
+
return new ProjectCodexAssemblyResource(adapter, startupTransport, launchProfile.thread.approvalPolicy, approvalController, unsubscribeApproval, invalidateApprovals, warmHome !== null, () => { warmReady = false; try {
|
|
327
|
+
options.onDiagnostic?.('project_prewarm_failed');
|
|
328
|
+
}
|
|
329
|
+
catch { /* advisory */ } }, ready => { warmReady = ready; }, backend => {
|
|
330
|
+
if (!CODING_BACKEND_IDS.includes(backend) || (backend !== 'codex' && routing === undefined))
|
|
331
|
+
throw new Error('invalid_coding_backend');
|
|
332
|
+
defaultBackend = backend;
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
catch (error) {
|
|
336
|
+
invalidateApprovals('resource_creation_failed');
|
|
337
|
+
unsubscribeApproval?.();
|
|
338
|
+
try {
|
|
339
|
+
await startupTransport?.close('failure');
|
|
340
|
+
}
|
|
341
|
+
catch { /* Preserve the construction failure for malformed transports too. */ }
|
|
342
|
+
await store?.close().catch(() => undefined);
|
|
343
|
+
if (error instanceof CodexHostConfigurationError)
|
|
344
|
+
throw error;
|
|
345
|
+
if (error instanceof ProjectStateError) {
|
|
346
|
+
if (['state_busy', 'state_lock_failed', 'state_permissions', 'workspace_not_found', 'workspace_invalid'].includes(error.code))
|
|
347
|
+
throw error;
|
|
348
|
+
throw new CodexHostConfigurationError('codex_project_state_invalid');
|
|
349
|
+
}
|
|
350
|
+
throw new CodexHostConfigurationError('codex_host_unavailable');
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
class ProjectCodexAssemblyResource {
|
|
354
|
+
adapter;
|
|
355
|
+
approvalPolicy;
|
|
356
|
+
approvalController;
|
|
357
|
+
invalidateApprovals;
|
|
358
|
+
prewarmConnection;
|
|
359
|
+
onPrewarmFailure;
|
|
360
|
+
onPrewarmReady;
|
|
361
|
+
setDefaultBackend;
|
|
362
|
+
agentControllerFactory = codingAgentControllerFactory;
|
|
363
|
+
get agentDescriptor() { return codexAgentDescriptor(this.adapter.manifest.name); }
|
|
364
|
+
mode = 'project';
|
|
365
|
+
#startupTransport;
|
|
366
|
+
#unsubscribeApproval;
|
|
367
|
+
#startOperation = null;
|
|
368
|
+
#closeOperation = null;
|
|
369
|
+
#closing = false;
|
|
370
|
+
constructor(adapter, startupTransport, approvalPolicy, approvalController, unsubscribeApproval, invalidateApprovals, prewarmConnection = false, onPrewarmFailure = () => undefined, onPrewarmReady = () => undefined, setDefaultBackend = () => { throw new Error('invalid_coding_backend'); }) {
|
|
371
|
+
this.adapter = adapter;
|
|
372
|
+
this.approvalPolicy = approvalPolicy;
|
|
373
|
+
this.approvalController = approvalController;
|
|
374
|
+
this.invalidateApprovals = invalidateApprovals;
|
|
375
|
+
this.prewarmConnection = prewarmConnection;
|
|
376
|
+
this.onPrewarmFailure = onPrewarmFailure;
|
|
377
|
+
this.onPrewarmReady = onPrewarmReady;
|
|
378
|
+
this.setDefaultBackend = setDefaultBackend;
|
|
379
|
+
this.#startupTransport = startupTransport;
|
|
380
|
+
this.#unsubscribeApproval = unsubscribeApproval;
|
|
381
|
+
}
|
|
382
|
+
get projectView() {
|
|
383
|
+
return this.adapter.publicProjectView(this.adapter.confirmationController.pending);
|
|
384
|
+
}
|
|
385
|
+
updateDefaultBackend(backend) {
|
|
386
|
+
this.setDefaultBackend(backend);
|
|
387
|
+
}
|
|
388
|
+
start() {
|
|
389
|
+
if (this.#startOperation !== null)
|
|
390
|
+
return this.#startOperation;
|
|
391
|
+
this.#startOperation = this.#startFresh();
|
|
392
|
+
return this.#startOperation;
|
|
393
|
+
}
|
|
394
|
+
async #startFresh() {
|
|
395
|
+
if (this.prewarmConnection && this.#startupTransport.prewarmConnection) {
|
|
396
|
+
// Certification remains mandatory; warming a certified connection is only an optimization.
|
|
397
|
+
try {
|
|
398
|
+
await this.#startupTransport.preflight({ expiresAtMs: Date.now() + 20_000 });
|
|
399
|
+
}
|
|
400
|
+
catch (error) {
|
|
401
|
+
try {
|
|
402
|
+
await this.#startupTransport.close('failure');
|
|
403
|
+
}
|
|
404
|
+
catch { /* Preserve the certification failure. */ }
|
|
405
|
+
throw error;
|
|
406
|
+
}
|
|
407
|
+
try {
|
|
408
|
+
const report = await this.#startupTransport.prewarmConnection({ expiresAtMs: Date.now() + 20_000 });
|
|
409
|
+
if (!this.#closing && report !== null)
|
|
410
|
+
this.onPrewarmReady(true);
|
|
411
|
+
}
|
|
412
|
+
catch {
|
|
413
|
+
this.onPrewarmFailure();
|
|
414
|
+
await this.#startupTransport.close('failure');
|
|
415
|
+
}
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
let failure = null;
|
|
419
|
+
try {
|
|
420
|
+
await this.#startupTransport.preflight({ expiresAtMs: Date.now() + 20_000 });
|
|
421
|
+
}
|
|
422
|
+
catch (error) {
|
|
423
|
+
failure = error;
|
|
424
|
+
}
|
|
425
|
+
try {
|
|
426
|
+
await this.#startupTransport.close(failure === null ? 'shutdown' : 'failure');
|
|
427
|
+
}
|
|
428
|
+
catch (error) {
|
|
429
|
+
failure ??= error;
|
|
430
|
+
}
|
|
431
|
+
if (failure instanceof Error)
|
|
432
|
+
throw failure;
|
|
433
|
+
if (failure !== null)
|
|
434
|
+
throw new Error('codex startup failed');
|
|
435
|
+
}
|
|
436
|
+
close() {
|
|
437
|
+
if (this.#closeOperation !== null)
|
|
438
|
+
return this.#closeOperation;
|
|
439
|
+
const work = this.#close();
|
|
440
|
+
const projectClose = work.catch(error => {
|
|
441
|
+
if (this.#closeOperation === projectClose)
|
|
442
|
+
this.#closeOperation = null;
|
|
443
|
+
throw error;
|
|
444
|
+
});
|
|
445
|
+
this.#closeOperation = projectClose;
|
|
446
|
+
return projectClose;
|
|
447
|
+
}
|
|
448
|
+
async #close() {
|
|
449
|
+
this.#closing = true;
|
|
450
|
+
this.onPrewarmReady(false);
|
|
451
|
+
this.invalidateApprovals('shutdown');
|
|
452
|
+
try {
|
|
453
|
+
await this.#startupTransport.close('shutdown');
|
|
454
|
+
await this.adapter.close();
|
|
455
|
+
}
|
|
456
|
+
finally {
|
|
457
|
+
// Approvals scoped to Codex work end with it even when shutdown fails; a borrowed controller stays open.
|
|
458
|
+
this.invalidateApprovals('shutdown');
|
|
459
|
+
this.#unsubscribeApproval?.();
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
//# sourceMappingURL=factory.js.map
|