dal-code 1.0.9 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/dist/core/keybindings.d.ts +1 -1
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +1 -1
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/model-config.d.ts +85 -0
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +19 -14
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/session-manager.d.ts +7 -0
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +28 -0
- package/dist/core/session-manager.js.map +1 -1
- package/dist/extensions/llama/client.d.ts +2 -0
- package/dist/extensions/llama/client.d.ts.map +1 -1
- package/dist/extensions/llama/client.js +7 -3
- package/dist/extensions/llama/client.js.map +1 -1
- package/dist/extensions/llama/provider.d.ts.map +1 -1
- package/dist/extensions/llama/provider.js +20 -5
- package/dist/extensions/llama/provider.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +5 -6
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +2 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +31 -21
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/node_modules/@dalcode/dal-bridge/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-gateway/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-guard/package.json +5 -5
- package/dist/node_modules/@dalcode/dal-halo/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-lang/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-lsp/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-mcp/package.json +6 -6
- package/dist/node_modules/@dalcode/dal-office/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-pi-kit/package.json +1 -1
- package/dist/node_modules/@dalcode/dal-skills/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-subagent/package.json +6 -6
- package/dist/node_modules/@dalcode/dal-telemetry/package.json +3 -3
- package/dist/node_modules/@dalcode/deepailab/package.json +4 -4
- package/dist/node_modules/@earendil-works/chord/LICENSE +21 -0
- package/dist/node_modules/@earendil-works/chord/README.md +205 -0
- package/dist/node_modules/@earendil-works/chord/dist/api.d.ts +15 -0
- package/dist/node_modules/@earendil-works/chord/dist/api.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/api.js +72 -0
- package/dist/node_modules/@earendil-works/chord/dist/api.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/bundler.d.ts +6 -0
- package/dist/node_modules/@earendil-works/chord/dist/bundler.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/bundler.js +3 -0
- package/dist/node_modules/@earendil-works/chord/dist/bundler.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/context/index.d.ts +24 -0
- package/dist/node_modules/@earendil-works/chord/dist/context/index.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/context/index.js +97 -0
- package/dist/node_modules/@earendil-works/chord/dist/context/index.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/delta/index.d.ts +119 -0
- package/dist/node_modules/@earendil-works/chord/dist/delta/index.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/delta/index.js +1906 -0
- package/dist/node_modules/@earendil-works/chord/dist/delta/index.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/facets/host.d.ts +12 -0
- package/dist/node_modules/@earendil-works/chord/dist/facets/host.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/facets/host.js +763 -0
- package/dist/node_modules/@earendil-works/chord/dist/facets/host.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/facets/loader.d.ts +3 -0
- package/dist/node_modules/@earendil-works/chord/dist/facets/loader.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/facets/loader.js +5 -0
- package/dist/node_modules/@earendil-works/chord/dist/facets/loader.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/index.d.ts +11 -0
- package/dist/node_modules/@earendil-works/chord/dist/index.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/index.js +10 -0
- package/dist/node_modules/@earendil-works/chord/dist/index.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/json.d.ts +4 -0
- package/dist/node_modules/@earendil-works/chord/dist/json.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/json.js +57 -0
- package/dist/node_modules/@earendil-works/chord/dist/json.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/node/bundle-loader.d.ts +30 -0
- package/dist/node_modules/@earendil-works/chord/dist/node/bundle-loader.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/node/bundle-loader.js +377 -0
- package/dist/node_modules/@earendil-works/chord/dist/node/bundle-loader.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/node/bundle.d.ts +26 -0
- package/dist/node_modules/@earendil-works/chord/dist/node/bundle.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/node/bundle.js +183 -0
- package/dist/node_modules/@earendil-works/chord/dist/node/bundle.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/node/manifest.d.ts +36 -0
- package/dist/node_modules/@earendil-works/chord/dist/node/manifest.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/node/manifest.js +6 -0
- package/dist/node_modules/@earendil-works/chord/dist/node/manifest.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/node/package.d.ts +15 -0
- package/dist/node_modules/@earendil-works/chord/dist/node/package.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/node/package.js +199 -0
- package/dist/node_modules/@earendil-works/chord/dist/node/package.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/node.d.ts +5 -0
- package/dist/node_modules/@earendil-works/chord/dist/node.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/node.js +3 -0
- package/dist/node_modules/@earendil-works/chord/dist/node.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/consumer.d.ts +11 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/consumer.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/consumer.js +537 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/consumer.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/errors.d.ts +8 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/errors.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/errors.js +22 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/errors.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/handle.d.ts +15 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/handle.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/handle.js +99 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/handle.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/instances.d.ts +25 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/instances.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/instances.js +137 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/instances.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/loopback.d.ts +5 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/loopback.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/loopback.js +15 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/loopback.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/provider.d.ts +37 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/provider.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/provider.js +472 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/provider.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/state-codec.d.ts +15 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/state-codec.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/state-codec.js +115 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/state-codec.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/state-internals.d.ts +11 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/state-internals.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/state-internals.js +10 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/state-internals.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/state.d.ts +23 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/state.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/state.js +124 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/state.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/wire.d.ts +60 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/wire.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/wire.js +173 -0
- package/dist/node_modules/@earendil-works/chord/dist/services/wire.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/types.d.ts +203 -0
- package/dist/node_modules/@earendil-works/chord/dist/types.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/chord/dist/types.js +2 -0
- package/dist/node_modules/@earendil-works/chord/dist/types.js.map +1 -0
- package/dist/node_modules/@earendil-works/chord/package.json +62 -0
- package/dist/node_modules/@earendil-works/chord/src/delta/README.md +404 -0
- package/dist/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
- package/dist/node_modules/@earendil-works/pi-ai/README.md +3 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +15 -6
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.js +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-generative-ai.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-generative-ai.js +9 -66
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-generative-ai.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-shared.d.ts +12 -3
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-shared.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-shared.js +50 -3
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-shared.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-vertex.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-vertex.js +13 -58
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/google-vertex.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.js +5 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js +6 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/image-models.generated.d.ts +30 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/image-models.generated.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js +34 -4
- package/dist/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/baseten.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/deepseek.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openai-codex.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode-go.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan-cn.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/zai-coding-cn.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/zai.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/types.d.ts +4 -2
- package/dist/node_modules/@earendil-works/pi-ai/dist/types.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/types.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/overflow.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js +8 -3
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/retry.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/retry.js +2 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/retry.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/package.json +2 -2
- package/dist/node_modules/@earendil-works/pi-client/package.json +2 -2
- package/dist/node_modules/@earendil-works/pi-protocol/package.json +2 -2
- package/dist/node_modules/@earendil-works/pi-server/CHANGELOG.md +57 -0
- package/dist/node_modules/@earendil-works/pi-server/LICENSE +21 -0
- package/dist/node_modules/@earendil-works/pi-server/README.md +79 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/cli.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/cli.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/cli.js +136 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/cli.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/config.d.ts +12 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/config.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/config.js +55 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/config.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/connection.d.ts +35 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/connection.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/connection.js +4 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/connection.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/errors.d.ts +25 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/errors.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/errors.js +41 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/errors.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/handler.d.ts +14 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/handler.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/handler.js +105 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/handler.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/index.d.ts +5 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/index.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/index.js +5 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/index.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/ipc/client.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/ipc/client.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/ipc/client.js +56 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/ipc/client.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/ipc/protocol.d.ts +99 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/ipc/protocol.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/ipc/protocol.js +12 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/ipc/protocol.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/ipc/server.d.ts +20 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/ipc/server.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/ipc/server.js +145 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/ipc/server.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/listener.d.ts +8 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/listener.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/listener.js +2 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/listener.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/protocol.d.ts +22 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/protocol.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/protocol.js +266 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/protocol.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/radius.d.ts +36 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/radius.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/radius.js +360 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/radius.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/rpc-process.d.ts +31 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/rpc-process.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/rpc-process.js +168 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/rpc-process.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/serve.d.ts +2 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/serve.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/serve.js +70 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/serve.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/server.d.ts +46 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/server.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/server.js +549 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/server.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/session-router.d.ts +40 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/session-router.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/session-router.js +264 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/session-router.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/sessions.d.ts +2195 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/sessions.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/sessions.js +332 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/sessions.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/snapshots.d.ts +24 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/snapshots.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/snapshots.js +39 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/snapshots.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/storage.d.ts +10 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/storage.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/storage.js +58 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/storage.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/supervisor.d.ts +34 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/supervisor.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/supervisor.js +290 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/supervisor.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/client.d.ts +35 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/client.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/client.js +138 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/client.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/host.d.ts +57 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/host.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/host.js +189 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/host.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/index.d.ts +6 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/index.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/index.js +4 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/index.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/server.d.ts +13 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/server.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/server.js +17 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/server.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/service.d.ts +66 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/service.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/service.js +254 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/testing/service.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/address.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/address.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/address.js +9 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/address.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/index.d.ts +5 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/index.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/index.js +4 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/index.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/listener.d.ts +24 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/listener.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/listener.js +421 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/listener.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/preset.d.ts +7 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/preset.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/preset.js +22 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/preset.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/types.d.ts +15 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/types.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/types.js +2 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/transports/unix/types.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/types.d.ts +49 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/types.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/types.js +2 -0
- package/dist/node_modules/@earendil-works/pi-server/dist/types.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-server/package.json +45 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/CHANGELOG.md +46 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/LICENSE +21 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/README.md +33 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/index.d.ts +6 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/index.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/index.js +103 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/index.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/branch-cache.d.ts +6 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/branch-cache.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/branch-cache.js +70 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/branch-cache.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/index.d.ts +5 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/index.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/index.js +4 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/index.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/migrations/001_initial.sql +121 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/migrations.d.ts +3 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/migrations.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/migrations.js +7 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/migrations.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/repo.d.ts +41 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/repo.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/repo.js +408 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/repo.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/search-backend.d.ts +14 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/search-backend.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/search-backend.js +153 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/search-backend.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/branch-entries.d.ts +6 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/branch-entries.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/branch-entries.js +213 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/branch-entries.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/entries.d.ts +24 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/entries.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/entries.js +126 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/entries.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/session-row.d.ts +23 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/session-row.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/session-row.js +69 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/session-row.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/session-sequences.d.ts +4 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/session-sequences.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/session-sequences.js +13 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/session-sequences.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/session-stats.d.ts +6 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/session-stats.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/session-stats.js +39 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/session-stats.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/usage-ledger.d.ts +20 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/usage-ledger.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/usage-ledger.js +50 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/usage-ledger.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/values.d.ts +23 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/values.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/values.js +91 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session/values.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session.d.ts +42 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session.js +163 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/session.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/sql.d.ts +19 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/sql.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/sql.js +58 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/sql.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/branch-entries.d.ts +41 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/branch-entries.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/branch-entries.js +112 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/branch-entries.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/branch-tips.d.ts +7 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/branch-tips.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/branch-tips.js +22 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/branch-tips.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/entries.d.ts +34 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/entries.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/entries.js +37 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/entries.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/facts.d.ts +20 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/facts.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/facts.js +38 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/facts.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/lanes.d.ts +35 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/lanes.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/lanes.js +95 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/lanes.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/records.d.ts +38 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/records.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/records.js +49 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/records.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/session-sequences.d.ts +7 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/session-sequences.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/session-sequences.js +22 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/session-sequences.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/session-stats.d.ts +17 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/session-stats.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/session-stats.js +40 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/session-stats.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/sessions.d.ts +26 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/sessions.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/sessions.js +99 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/sessions.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/writer-leases.d.ts +15 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/writer-leases.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/writer-leases.js +31 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage/writer-leases.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage.d.ts +38 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage.js +161 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/storage.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/types.d.ts +29 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/types.d.ts.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/types.js +2 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/dist/sqlite/types.js.map +1 -0
- package/dist/node_modules/@earendil-works/pi-session-backend-sqlite-node/package.json +33 -0
- package/dist/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/layout.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/layout.js +5 -2
- package/dist/node_modules/@earendil-works/pi-tui/dist/layout.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/tui.d.ts.map +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/dist/tui.js +17 -4
- package/dist/node_modules/@earendil-works/pi-tui/dist/tui.js.map +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/official/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/plugins/pi-example-plugin/package.json +1 -1
- package/npm-shrinkwrap.json +3 -14
- package/package.json +2 -2
|
@@ -0,0 +1,549 @@
|
|
|
1
|
+
import { createServiceStateEncoder, decodeServiceControlCall, parseServiceCall, parseServiceSubscriptionSnapshot, RemoteServiceError, } from "@earendil-works/chord";
|
|
2
|
+
import { BACKGROUND_CONTEXT, TODO_CONTEXT, withAbortSignal } from "@earendil-works/pi-agent-core";
|
|
3
|
+
import { ClientMessageDecoder, DEFAULT_MAX_FRAME_LENGTH, encodeServerMessage, isServerId, isSupportedProtocolVersion, PROTOCOL_VERSION, ProtocolValidationError, } from "@earendil-works/pi-protocol";
|
|
4
|
+
import { isTerminalConnection, } from "./connection.js";
|
|
5
|
+
import { INTERNAL_SERVER_ERROR_MESSAGE, ServerError, WrongServerError } from "./errors.js";
|
|
6
|
+
import { SessionRouter } from "./session-router.js";
|
|
7
|
+
const DEFAULT_HANDSHAKE_TIMEOUT_MS = 5_000;
|
|
8
|
+
const MAX_UINT32 = 0xffff_ffff;
|
|
9
|
+
const MAX_TIMER_DELAY_MS = 2_147_483_647;
|
|
10
|
+
export class Server {
|
|
11
|
+
serverId;
|
|
12
|
+
/** Resolves after shutdown, or rejects when listener or routed-Session cleanup fails. */
|
|
13
|
+
closed;
|
|
14
|
+
host;
|
|
15
|
+
listeners;
|
|
16
|
+
maxFrameLength;
|
|
17
|
+
handshakeTimeoutMs;
|
|
18
|
+
onConnectionCountChanged;
|
|
19
|
+
onError;
|
|
20
|
+
connections = new Set();
|
|
21
|
+
sessions;
|
|
22
|
+
closing = false;
|
|
23
|
+
closePromise;
|
|
24
|
+
closedSettled = false;
|
|
25
|
+
rejectClosed;
|
|
26
|
+
resolveClosed;
|
|
27
|
+
startPromise;
|
|
28
|
+
started = false;
|
|
29
|
+
constructor(host, options) {
|
|
30
|
+
const resolved = resolveOptions(options);
|
|
31
|
+
this.host = host;
|
|
32
|
+
this.listeners = options.listeners;
|
|
33
|
+
this.serverId = options.serverId;
|
|
34
|
+
this.maxFrameLength = resolved.maxFrameLength;
|
|
35
|
+
this.handshakeTimeoutMs = resolved.handshakeTimeoutMs;
|
|
36
|
+
this.onConnectionCountChanged = options.onConnectionCountChanged;
|
|
37
|
+
this.onError = options.onError;
|
|
38
|
+
this.sessions = new SessionRouter({
|
|
39
|
+
host,
|
|
40
|
+
serverId: this.serverId,
|
|
41
|
+
isClosing: () => this.closing,
|
|
42
|
+
publishAttachment: async (client, attachment) => {
|
|
43
|
+
await this.sendMessage(client, {
|
|
44
|
+
type: "attachment",
|
|
45
|
+
attachment: attachment ?? null,
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
reportError: (error) => this.reportError(error),
|
|
49
|
+
});
|
|
50
|
+
this.closed = new Promise((resolve, reject) => {
|
|
51
|
+
this.resolveClosed = resolve;
|
|
52
|
+
this.rejectClosed = reject;
|
|
53
|
+
});
|
|
54
|
+
void this.closed.catch(() => { });
|
|
55
|
+
}
|
|
56
|
+
start() {
|
|
57
|
+
if (this.started)
|
|
58
|
+
return Promise.reject(new Error("Server is already started"));
|
|
59
|
+
if (this.startPromise)
|
|
60
|
+
return Promise.reject(new Error("Server is already starting"));
|
|
61
|
+
if (this.closing)
|
|
62
|
+
return Promise.reject(new Error("Server is closing or closed"));
|
|
63
|
+
this.startPromise = this.startInternal();
|
|
64
|
+
return this.startPromise;
|
|
65
|
+
}
|
|
66
|
+
async startInternal() {
|
|
67
|
+
const started = [];
|
|
68
|
+
try {
|
|
69
|
+
for (const listener of this.listeners) {
|
|
70
|
+
await listener.start((connection) => this.accept(connection));
|
|
71
|
+
started.push(listener);
|
|
72
|
+
}
|
|
73
|
+
this.started = true;
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
this.closing = true;
|
|
78
|
+
const cleanupErrors = [];
|
|
79
|
+
const listenerResults = await Promise.allSettled(started.map((listener) => listener.close()));
|
|
80
|
+
for (const result of listenerResults) {
|
|
81
|
+
if (result.status === "rejected")
|
|
82
|
+
cleanupErrors.push(result.reason);
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
await this.closeServerState();
|
|
86
|
+
}
|
|
87
|
+
catch (cleanupError) {
|
|
88
|
+
cleanupErrors.push(cleanupError);
|
|
89
|
+
}
|
|
90
|
+
if (cleanupErrors.length > 0) {
|
|
91
|
+
const failure = new AggregateError([error, ...cleanupErrors], "Server startup and cleanup failed");
|
|
92
|
+
this.settleClosed(failure);
|
|
93
|
+
throw failure;
|
|
94
|
+
}
|
|
95
|
+
this.settleClosed();
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
finally {
|
|
99
|
+
this.startPromise = undefined;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
accept(connection) {
|
|
103
|
+
if (this.closing) {
|
|
104
|
+
void this.closeConnection(connection);
|
|
105
|
+
return {
|
|
106
|
+
onData: () => { },
|
|
107
|
+
onClose: () => { },
|
|
108
|
+
onError: (error) => this.reportError(error),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
let state;
|
|
112
|
+
const handshakeTimeout = setTimeout(() => {
|
|
113
|
+
void this.failProtocol(state, {
|
|
114
|
+
code: "invalid_request",
|
|
115
|
+
message: "Handshake timeout",
|
|
116
|
+
});
|
|
117
|
+
}, this.handshakeTimeoutMs);
|
|
118
|
+
handshakeTimeout.unref();
|
|
119
|
+
state = {
|
|
120
|
+
connection,
|
|
121
|
+
decoder: new ClientMessageDecoder({ maxFrameLength: this.maxFrameLength }),
|
|
122
|
+
serviceStateEncoders: new Map(),
|
|
123
|
+
sessionIds: new Set(),
|
|
124
|
+
extensionUiSessions: new Set(),
|
|
125
|
+
stage: "awaitingHello",
|
|
126
|
+
disconnected: false,
|
|
127
|
+
handshakeTimeout,
|
|
128
|
+
activeRequests: new Map(),
|
|
129
|
+
};
|
|
130
|
+
this.connections.add(state);
|
|
131
|
+
this.notifyConnectionCountChanged();
|
|
132
|
+
return {
|
|
133
|
+
onData: (chunk) => this.receive(state, chunk),
|
|
134
|
+
onClose: () => this.transportClosed(state),
|
|
135
|
+
onError: (error) => {
|
|
136
|
+
this.reportError(error);
|
|
137
|
+
void this.closeConnection(connection).then(() => this.disconnect(state));
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
async close() {
|
|
142
|
+
if (this.closePromise)
|
|
143
|
+
return this.closePromise;
|
|
144
|
+
this.closing = true;
|
|
145
|
+
this.closePromise = this.closeInternal();
|
|
146
|
+
return this.closePromise;
|
|
147
|
+
}
|
|
148
|
+
async closeInternal() {
|
|
149
|
+
const starting = this.startPromise;
|
|
150
|
+
if (starting)
|
|
151
|
+
await starting.catch(() => { });
|
|
152
|
+
const errors = [];
|
|
153
|
+
const listenerResults = await Promise.allSettled(this.listeners.map((listener) => listener.close()));
|
|
154
|
+
for (const result of listenerResults) {
|
|
155
|
+
if (result.status === "rejected")
|
|
156
|
+
errors.push(result.reason);
|
|
157
|
+
}
|
|
158
|
+
try {
|
|
159
|
+
await this.closeServerState();
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
errors.push(error);
|
|
163
|
+
}
|
|
164
|
+
this.started = false;
|
|
165
|
+
if (errors.length > 0) {
|
|
166
|
+
const failure = errors.length === 1 && errors[0] instanceof Error
|
|
167
|
+
? errors[0]
|
|
168
|
+
: new AggregateError(errors, "Server shutdown failed");
|
|
169
|
+
this.settleClosed(failure);
|
|
170
|
+
throw failure;
|
|
171
|
+
}
|
|
172
|
+
this.settleClosed();
|
|
173
|
+
}
|
|
174
|
+
receive(state, chunk) {
|
|
175
|
+
if (isTerminalConnection(state))
|
|
176
|
+
return;
|
|
177
|
+
let messages;
|
|
178
|
+
try {
|
|
179
|
+
messages = state.decoder.push(chunk);
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
void this.failProtocol(state, this.toProtocolError(error));
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
for (const message of messages) {
|
|
186
|
+
if (isTerminalConnection(state))
|
|
187
|
+
return;
|
|
188
|
+
this.dispatchMessage(state, message);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
dispatchMessage(state, message) {
|
|
192
|
+
if (state.stage === "awaitingHello") {
|
|
193
|
+
if (message.type !== "hello") {
|
|
194
|
+
void this.failProtocol(state, {
|
|
195
|
+
code: "invalid_request",
|
|
196
|
+
message: "The first client message must be hello",
|
|
197
|
+
});
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
state.stage = "handshaking";
|
|
201
|
+
state.handshake = this.finishHandshake(state, message).catch((error) => this.failProtocol(state, this.toProtocolError(error)));
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (message.type === "hello") {
|
|
205
|
+
void this.failProtocol(state, {
|
|
206
|
+
code: "invalid_request",
|
|
207
|
+
message: "hello may only be sent as the first message",
|
|
208
|
+
});
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (state.stage === "ready") {
|
|
212
|
+
if (message.type === "cancel")
|
|
213
|
+
this.handleCancel(state, message);
|
|
214
|
+
else
|
|
215
|
+
void this.handleRequest(state, message);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
if (state.stage !== "handshaking")
|
|
219
|
+
return;
|
|
220
|
+
const handshake = state.handshake;
|
|
221
|
+
if (!handshake)
|
|
222
|
+
return;
|
|
223
|
+
void handshake.then(() => {
|
|
224
|
+
if (state.stage !== "ready" || state.disconnected)
|
|
225
|
+
return;
|
|
226
|
+
if (message.type === "cancel")
|
|
227
|
+
this.handleCancel(state, message);
|
|
228
|
+
else
|
|
229
|
+
void this.handleRequest(state, message);
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
async finishHandshake(state, hello) {
|
|
233
|
+
if (!isSupportedProtocolVersion(hello.version)) {
|
|
234
|
+
await this.failProtocol(state, {
|
|
235
|
+
code: "version",
|
|
236
|
+
message: `Unsupported protocol version ${hello.version}; expected ${PROTOCOL_VERSION}`,
|
|
237
|
+
});
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
if (this.closing || state.disconnected || state.stage !== "handshaking" || state.connection.closed)
|
|
241
|
+
return;
|
|
242
|
+
const services = await this.host.serverServices.attachClient({
|
|
243
|
+
attachSession: async (sessionId, context) => {
|
|
244
|
+
await this.sessions.attachClient(state, sessionId, context);
|
|
245
|
+
},
|
|
246
|
+
detachSession: (context) => this.sessions.detachClient(state, context),
|
|
247
|
+
prepareSessionRemoval: (sessionId, context) => this.sessions.removeSession(sessionId, context),
|
|
248
|
+
}, TODO_CONTEXT);
|
|
249
|
+
if (this.closing || state.disconnected || state.stage !== "handshaking" || state.connection.closed) {
|
|
250
|
+
await services.release(TODO_CONTEXT);
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
state.serverServices = services;
|
|
254
|
+
const sent = await this.sendMessage(state, {
|
|
255
|
+
type: "hello",
|
|
256
|
+
version: PROTOCOL_VERSION,
|
|
257
|
+
serverId: this.serverId,
|
|
258
|
+
});
|
|
259
|
+
if (sent && !state.disconnected && state.stage === "handshaking") {
|
|
260
|
+
state.stage = "ready";
|
|
261
|
+
clearTimeout(state.handshakeTimeout);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
handleCancel(state, envelope) {
|
|
265
|
+
if (envelope.target.serverId !== this.serverId)
|
|
266
|
+
return;
|
|
267
|
+
const active = state.activeRequests.get(envelope.id);
|
|
268
|
+
if (active !== undefined && sameTarget(active.target, envelope.target)) {
|
|
269
|
+
active.controller.abort(new DOMException("RPC request cancelled", "AbortError"));
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
async handleRequest(state, envelope) {
|
|
273
|
+
if (state.activeRequests.has(envelope.id)) {
|
|
274
|
+
await this.sendMessage(state, {
|
|
275
|
+
type: "response",
|
|
276
|
+
id: envelope.id,
|
|
277
|
+
ok: false,
|
|
278
|
+
error: { code: "invalid_request", message: "Request ID is already active" },
|
|
279
|
+
});
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
let call;
|
|
283
|
+
try {
|
|
284
|
+
call = parseServiceCall(envelope.call);
|
|
285
|
+
}
|
|
286
|
+
catch {
|
|
287
|
+
await this.sendMessage(state, {
|
|
288
|
+
type: "response",
|
|
289
|
+
id: envelope.id,
|
|
290
|
+
ok: false,
|
|
291
|
+
error: { code: "invalid_request", message: "Invalid service call" },
|
|
292
|
+
});
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
const controller = new AbortController();
|
|
296
|
+
const active = { controller, target: envelope.target };
|
|
297
|
+
state.activeRequests.set(envelope.id, active);
|
|
298
|
+
const context = withAbortSignal(controller.signal, TODO_CONTEXT);
|
|
299
|
+
const control = decodeServiceControlCall(call);
|
|
300
|
+
const subscribing = control?.type === "subscribe" ? control : undefined;
|
|
301
|
+
const pendingUpdates = [];
|
|
302
|
+
let subscriptionReady = subscribing === undefined;
|
|
303
|
+
let installedSubscriptionEncoder = false;
|
|
304
|
+
let responded = false;
|
|
305
|
+
const publish = async (subscriptionId, update) => {
|
|
306
|
+
if (subscribing !== undefined && subscriptionId === subscribing.subscriptionId && !subscriptionReady) {
|
|
307
|
+
pendingUpdates.push({ update });
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
await this.sendServiceUpdate(state, subscriptionId, update);
|
|
311
|
+
};
|
|
312
|
+
try {
|
|
313
|
+
if (envelope.target.serverId !== this.serverId)
|
|
314
|
+
throw new WrongServerError();
|
|
315
|
+
if (subscribing !== undefined && state.serviceStateEncoders.has(subscribing.subscriptionId)) {
|
|
316
|
+
throw new ProtocolValidationError(`Duplicate service subscription ${subscribing.subscriptionId}`);
|
|
317
|
+
}
|
|
318
|
+
let result;
|
|
319
|
+
if ("sessionId" in envelope.target) {
|
|
320
|
+
result = await this.sessions.executeServiceCall(call, envelope.target, state, publish, context);
|
|
321
|
+
}
|
|
322
|
+
else if (state.serverServices !== undefined) {
|
|
323
|
+
result = await state.serverServices.invokeService(call, publish, context);
|
|
324
|
+
}
|
|
325
|
+
else {
|
|
326
|
+
throw new ProtocolValidationError(`Unknown service member ${call.serviceId}.${call.member}`);
|
|
327
|
+
}
|
|
328
|
+
if (subscribing !== undefined) {
|
|
329
|
+
if (result === undefined)
|
|
330
|
+
throw new ProtocolValidationError("Service subscription did not return a snapshot");
|
|
331
|
+
const stateEncoder = createServiceStateEncoder();
|
|
332
|
+
result = stateEncoder.encodeSnapshot(parseServiceSubscriptionSnapshot(result));
|
|
333
|
+
state.serviceStateEncoders.set(subscribing.subscriptionId, stateEncoder);
|
|
334
|
+
installedSubscriptionEncoder = true;
|
|
335
|
+
}
|
|
336
|
+
else if (control?.type === "unsubscribe") {
|
|
337
|
+
state.serviceStateEncoders.delete(control.subscriptionId);
|
|
338
|
+
}
|
|
339
|
+
await this.sendMessage(state, result === undefined
|
|
340
|
+
? { type: "response", id: envelope.id, ok: true }
|
|
341
|
+
: { type: "response", id: envelope.id, ok: true, result });
|
|
342
|
+
responded = true;
|
|
343
|
+
if (subscribing !== undefined) {
|
|
344
|
+
while (pendingUpdates.length > 0) {
|
|
345
|
+
const pending = pendingUpdates.shift();
|
|
346
|
+
if (pending !== undefined)
|
|
347
|
+
await this.sendServiceUpdate(state, subscribing.subscriptionId, pending.update);
|
|
348
|
+
}
|
|
349
|
+
subscriptionReady = true;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
catch (error) {
|
|
353
|
+
if (subscribing !== undefined && installedSubscriptionEncoder && !responded) {
|
|
354
|
+
state.serviceStateEncoders.delete(subscribing.subscriptionId);
|
|
355
|
+
}
|
|
356
|
+
if (responded) {
|
|
357
|
+
this.reportError(error);
|
|
358
|
+
await this.closeConnection(state.connection);
|
|
359
|
+
this.disconnect(state);
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
await this.sendMessage(state, {
|
|
363
|
+
type: "response",
|
|
364
|
+
id: envelope.id,
|
|
365
|
+
ok: false,
|
|
366
|
+
error: controller.signal.aborted
|
|
367
|
+
? { code: "cancelled", message: "RPC request cancelled" }
|
|
368
|
+
: this.toProtocolError(error),
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
finally {
|
|
373
|
+
if (state.activeRequests.get(envelope.id) === active)
|
|
374
|
+
state.activeRequests.delete(envelope.id);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
transportClosed(connection) {
|
|
378
|
+
if (!connection.disconnected && connection.stage !== "closing") {
|
|
379
|
+
try {
|
|
380
|
+
connection.decoder.end();
|
|
381
|
+
}
|
|
382
|
+
catch (error) {
|
|
383
|
+
this.reportError(error);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
this.disconnect(connection);
|
|
387
|
+
}
|
|
388
|
+
disconnect(connection) {
|
|
389
|
+
if (connection.disconnected)
|
|
390
|
+
return;
|
|
391
|
+
connection.disconnected = true;
|
|
392
|
+
connection.stage = "closed";
|
|
393
|
+
clearTimeout(connection.handshakeTimeout);
|
|
394
|
+
for (const { controller } of connection.activeRequests.values()) {
|
|
395
|
+
controller.abort(new Error("Client disconnected"));
|
|
396
|
+
}
|
|
397
|
+
connection.activeRequests.clear();
|
|
398
|
+
connection.serviceStateEncoders.clear();
|
|
399
|
+
if (this.connections.delete(connection))
|
|
400
|
+
this.notifyConnectionCountChanged();
|
|
401
|
+
const serverServices = connection.serverServices;
|
|
402
|
+
delete connection.serverServices;
|
|
403
|
+
void Promise.allSettled([
|
|
404
|
+
this.sessions.disconnect(connection, TODO_CONTEXT),
|
|
405
|
+
serverServices?.release(TODO_CONTEXT),
|
|
406
|
+
]).then((results) => {
|
|
407
|
+
for (const result of results)
|
|
408
|
+
if (result.status === "rejected")
|
|
409
|
+
this.reportError(result.reason);
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
async sendServiceUpdate(connection, subscriptionId, update) {
|
|
413
|
+
const stateEncoder = connection.serviceStateEncoders.get(subscriptionId);
|
|
414
|
+
if (stateEncoder === undefined)
|
|
415
|
+
return;
|
|
416
|
+
await this.sendMessage(connection, {
|
|
417
|
+
type: "service_update",
|
|
418
|
+
subscriptionId,
|
|
419
|
+
update: stateEncoder.encodeUpdate(update),
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
async sendMessage(connection, message) {
|
|
423
|
+
if (connection.disconnected || connection.connection.closed)
|
|
424
|
+
return false;
|
|
425
|
+
let frame;
|
|
426
|
+
try {
|
|
427
|
+
frame = encodeServerMessage(message, { maxFrameLength: this.maxFrameLength });
|
|
428
|
+
}
|
|
429
|
+
catch (error) {
|
|
430
|
+
this.reportError(error);
|
|
431
|
+
await this.closeConnection(connection.connection);
|
|
432
|
+
this.disconnect(connection);
|
|
433
|
+
return false;
|
|
434
|
+
}
|
|
435
|
+
try {
|
|
436
|
+
await connection.connection.send(frame);
|
|
437
|
+
return true;
|
|
438
|
+
}
|
|
439
|
+
catch (error) {
|
|
440
|
+
this.reportError(error);
|
|
441
|
+
await this.closeConnection(connection.connection);
|
|
442
|
+
this.disconnect(connection);
|
|
443
|
+
return false;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
async failProtocol(connection, error) {
|
|
447
|
+
if (connection.disconnected || connection.stage === "closing" || connection.stage === "closed")
|
|
448
|
+
return;
|
|
449
|
+
connection.stage = "closing";
|
|
450
|
+
clearTimeout(connection.handshakeTimeout);
|
|
451
|
+
const message = { type: "hello_error", error };
|
|
452
|
+
let finalFrame;
|
|
453
|
+
try {
|
|
454
|
+
finalFrame = encodeServerMessage(message, { maxFrameLength: this.maxFrameLength });
|
|
455
|
+
}
|
|
456
|
+
catch (encodeError) {
|
|
457
|
+
this.reportError(encodeError);
|
|
458
|
+
}
|
|
459
|
+
await this.closeConnection(connection.connection, finalFrame);
|
|
460
|
+
this.disconnect(connection);
|
|
461
|
+
}
|
|
462
|
+
async closeServerState() {
|
|
463
|
+
const connections = [...this.connections];
|
|
464
|
+
for (const connection of connections) {
|
|
465
|
+
connection.stage = "closing";
|
|
466
|
+
clearTimeout(connection.handshakeTimeout);
|
|
467
|
+
}
|
|
468
|
+
await Promise.all(connections.map((connection) => this.closeConnection(connection.connection)));
|
|
469
|
+
for (const connection of connections)
|
|
470
|
+
this.disconnect(connection);
|
|
471
|
+
const cleanup = await Promise.allSettled([this.sessions.close(BACKGROUND_CONTEXT)]);
|
|
472
|
+
this.connections.clear();
|
|
473
|
+
const errors = cleanup.flatMap((result) => (result.status === "rejected" ? [result.reason] : []));
|
|
474
|
+
if (errors.length === 1)
|
|
475
|
+
throw errors[0];
|
|
476
|
+
if (errors.length > 1)
|
|
477
|
+
throw new AggregateError(errors, "Failed to close server Sessions");
|
|
478
|
+
}
|
|
479
|
+
async closeConnection(connection, finalChunk) {
|
|
480
|
+
try {
|
|
481
|
+
await connection.close(finalChunk);
|
|
482
|
+
}
|
|
483
|
+
catch (error) {
|
|
484
|
+
this.reportError(error);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
toProtocolError(error) {
|
|
488
|
+
if (error instanceof ServerError || error instanceof RemoteServiceError) {
|
|
489
|
+
return { code: error.code, message: error.message };
|
|
490
|
+
}
|
|
491
|
+
if (error instanceof ProtocolValidationError) {
|
|
492
|
+
return { code: "invalid_request", message: error.message };
|
|
493
|
+
}
|
|
494
|
+
this.reportError(error);
|
|
495
|
+
return { code: "internal_error", message: INTERNAL_SERVER_ERROR_MESSAGE };
|
|
496
|
+
}
|
|
497
|
+
notifyConnectionCountChanged() {
|
|
498
|
+
try {
|
|
499
|
+
this.onConnectionCountChanged?.(this.connections.size);
|
|
500
|
+
}
|
|
501
|
+
catch (error) {
|
|
502
|
+
this.reportError(error);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
reportError(error) {
|
|
506
|
+
try {
|
|
507
|
+
this.onError?.(error instanceof Error ? error : new Error(String(error)));
|
|
508
|
+
}
|
|
509
|
+
catch {
|
|
510
|
+
// Error observers cannot affect server state.
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
settleClosed(error) {
|
|
514
|
+
if (this.closedSettled)
|
|
515
|
+
return;
|
|
516
|
+
this.closedSettled = true;
|
|
517
|
+
if (error === undefined)
|
|
518
|
+
this.resolveClosed();
|
|
519
|
+
else
|
|
520
|
+
this.rejectClosed(error);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
function sameTarget(left, right) {
|
|
524
|
+
if (left.serverId !== right.serverId)
|
|
525
|
+
return false;
|
|
526
|
+
if (!("sessionId" in left) || !("sessionId" in right)) {
|
|
527
|
+
return !("sessionId" in left) && !("sessionId" in right);
|
|
528
|
+
}
|
|
529
|
+
return left.sessionId === right.sessionId && left.attachmentId === right.attachmentId;
|
|
530
|
+
}
|
|
531
|
+
function resolveOptions(options) {
|
|
532
|
+
if (!Array.isArray(options.listeners))
|
|
533
|
+
throw new TypeError("Server listeners must be an array");
|
|
534
|
+
if (!isServerId(options.serverId)) {
|
|
535
|
+
throw new TypeError("serverId must be a canonical lowercase UUIDv4");
|
|
536
|
+
}
|
|
537
|
+
const maxFrameLength = options.maxFrameLength ?? DEFAULT_MAX_FRAME_LENGTH;
|
|
538
|
+
if (!Number.isSafeInteger(maxFrameLength) || maxFrameLength <= 0 || maxFrameLength > MAX_UINT32) {
|
|
539
|
+
throw new TypeError(`Server maxFrameLength must be an integer between 1 and ${MAX_UINT32}`);
|
|
540
|
+
}
|
|
541
|
+
const handshakeTimeoutMs = options.handshakeTimeoutMs ?? DEFAULT_HANDSHAKE_TIMEOUT_MS;
|
|
542
|
+
if (!Number.isSafeInteger(handshakeTimeoutMs) ||
|
|
543
|
+
handshakeTimeoutMs <= 0 ||
|
|
544
|
+
handshakeTimeoutMs > MAX_TIMER_DELAY_MS) {
|
|
545
|
+
throw new TypeError(`Server handshakeTimeoutMs must be an integer between 1 and ${MAX_TIMER_DELAY_MS}`);
|
|
546
|
+
}
|
|
547
|
+
return { maxFrameLength, handshakeTimeoutMs };
|
|
548
|
+
}
|
|
549
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EACN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ttype JsonValue,\n\tparseServiceCall,\n\tparseServiceSubscriptionSnapshot,\n\tRemoteServiceError,\n\ttype ServiceCall,\n\ttype ServiceProviderUpdate,\n} from \"@earendil-works/chord\";\nimport { BACKGROUND_CONTEXT, type SessionMetadata, TODO_CONTEXT, withAbortSignal } from \"@earendil-works/pi-agent-core\";\nimport {\n\ttype CancelEnvelope,\n\ttype ClientHello,\n\ttype ClientMessage,\n\tClientMessageDecoder,\n\tDEFAULT_MAX_FRAME_LENGTH,\n\tencodeServerMessage,\n\tisServerId,\n\tisSupportedProtocolVersion,\n\tPROTOCOL_VERSION,\n\ttype ProtocolError,\n\tProtocolValidationError,\n\ttype RequestEnvelope,\n\ttype ResponseEnvelope,\n\ttype RpcTarget,\n\ttype ServerHello,\n\ttype ServerHelloError,\n\ttype ServerMessage,\n} from \"@earendil-works/pi-protocol\";\nimport {\n\ttype ByteConnection,\n\ttype ByteConnectionHandler,\n\ttype ConnectionState,\n\tisTerminalConnection,\n} from \"./connection.ts\";\nimport { INTERNAL_SERVER_ERROR_MESSAGE, ServerError, WrongServerError } from \"./errors.ts\";\nimport type { ServerListener } from \"./listener.ts\";\nimport { SessionRouter } from \"./session-router.ts\";\nimport type { ServerHost, ServerOptions } from \"./types.ts\";\n\nconst DEFAULT_HANDSHAKE_TIMEOUT_MS = 5_000;\nconst MAX_UINT32 = 0xffff_ffff;\nconst MAX_TIMER_DELAY_MS = 2_147_483_647;\n\nexport class Server<TMetadata extends SessionMetadata = SessionMetadata> {\n\treadonly serverId: string;\n\t/** Resolves after shutdown, or rejects when listener or routed-Session cleanup fails. */\n\treadonly closed: Promise<void>;\n\n\tprivate readonly host: ServerHost<TMetadata>;\n\tprivate readonly listeners: readonly ServerListener[];\n\tprivate readonly maxFrameLength: number;\n\tprivate readonly handshakeTimeoutMs: number;\n\tprivate readonly onConnectionCountChanged: ((count: number) => void) | undefined;\n\tprivate readonly onError: ((error: Error) => void) | undefined;\n\tprivate readonly connections = new Set<ConnectionState>();\n\tprivate readonly sessions: SessionRouter<TMetadata>;\n\tprivate closing = false;\n\tprivate closePromise?: Promise<void>;\n\tprivate closedSettled = false;\n\tprivate rejectClosed!: (error: unknown) => void;\n\tprivate resolveClosed!: () => void;\n\tprivate startPromise?: Promise<this>;\n\tprivate started = false;\n\n\tconstructor(host: ServerHost<TMetadata>, options: ServerOptions) {\n\t\tconst resolved = resolveOptions(options);\n\t\tthis.host = host;\n\t\tthis.listeners = options.listeners;\n\t\tthis.serverId = options.serverId;\n\t\tthis.maxFrameLength = resolved.maxFrameLength;\n\t\tthis.handshakeTimeoutMs = resolved.handshakeTimeoutMs;\n\t\tthis.onConnectionCountChanged = options.onConnectionCountChanged;\n\t\tthis.onError = options.onError;\n\t\tthis.sessions = new SessionRouter({\n\t\t\thost,\n\t\t\tserverId: this.serverId,\n\t\t\tisClosing: () => this.closing,\n\t\t\tpublishAttachment: async (client, attachment) => {\n\t\t\t\tawait this.sendMessage(client as ConnectionState, {\n\t\t\t\t\ttype: \"attachment\",\n\t\t\t\t\tattachment: attachment ?? null,\n\t\t\t\t});\n\t\t\t},\n\t\t\treportError: (error) => this.reportError(error),\n\t\t});\n\t\tthis.closed = new Promise((resolve, reject) => {\n\t\t\tthis.resolveClosed = resolve;\n\t\t\tthis.rejectClosed = reject;\n\t\t});\n\t\tvoid this.closed.catch(() => {});\n\t}\n\n\tstart(): Promise<this> {\n\t\tif (this.started) return Promise.reject(new Error(\"Server is already started\"));\n\t\tif (this.startPromise) return Promise.reject(new Error(\"Server is already starting\"));\n\t\tif (this.closing) return Promise.reject(new Error(\"Server is closing or closed\"));\n\t\tthis.startPromise = this.startInternal();\n\t\treturn this.startPromise;\n\t}\n\n\tprivate async startInternal(): Promise<this> {\n\t\tconst started: ServerListener[] = [];\n\t\ttry {\n\t\t\tfor (const listener of this.listeners) {\n\t\t\t\tawait listener.start((connection) => this.accept(connection));\n\t\t\t\tstarted.push(listener);\n\t\t\t}\n\t\t\tthis.started = true;\n\t\t\treturn this;\n\t\t} catch (error) {\n\t\t\tthis.closing = true;\n\t\t\tconst cleanupErrors: unknown[] = [];\n\t\t\tconst listenerResults = await Promise.allSettled(started.map((listener) => listener.close()));\n\t\t\tfor (const result of listenerResults) {\n\t\t\t\tif (result.status === \"rejected\") cleanupErrors.push(result.reason);\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tawait this.closeServerState();\n\t\t\t} catch (cleanupError) {\n\t\t\t\tcleanupErrors.push(cleanupError);\n\t\t\t}\n\t\t\tif (cleanupErrors.length > 0) {\n\t\t\t\tconst failure = new AggregateError([error, ...cleanupErrors], \"Server startup and cleanup failed\");\n\t\t\t\tthis.settleClosed(failure);\n\t\t\t\tthrow failure;\n\t\t\t}\n\t\t\tthis.settleClosed();\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\tthis.startPromise = undefined;\n\t\t}\n\t}\n\n\taccept(connection: ByteConnection): ByteConnectionHandler {\n\t\tif (this.closing) {\n\t\t\tvoid this.closeConnection(connection);\n\t\t\treturn {\n\t\t\t\tonData: () => {},\n\t\t\t\tonClose: () => {},\n\t\t\t\tonError: (error) => this.reportError(error),\n\t\t\t};\n\t\t}\n\n\t\tlet state: ConnectionState;\n\t\tconst handshakeTimeout = setTimeout(() => {\n\t\t\tvoid this.failProtocol(state, {\n\t\t\t\tcode: \"invalid_request\",\n\t\t\t\tmessage: \"Handshake timeout\",\n\t\t\t});\n\t\t}, this.handshakeTimeoutMs);\n\t\thandshakeTimeout.unref();\n\t\tstate = {\n\t\t\tconnection,\n\t\t\tdecoder: new ClientMessageDecoder({ maxFrameLength: this.maxFrameLength }),\n\t\t\tserviceStateEncoders: new Map(),\n\t\t\tsessionIds: new Set(),\n\t\t\textensionUiSessions: new Set(),\n\t\t\tstage: \"awaitingHello\",\n\t\t\tdisconnected: false,\n\t\t\thandshakeTimeout,\n\t\t\tactiveRequests: new Map(),\n\t\t};\n\t\tthis.connections.add(state);\n\t\tthis.notifyConnectionCountChanged();\n\n\t\treturn {\n\t\t\tonData: (chunk) => this.receive(state, chunk),\n\t\t\tonClose: () => this.transportClosed(state),\n\t\t\tonError: (error) => {\n\t\t\t\tthis.reportError(error);\n\t\t\t\tvoid this.closeConnection(connection).then(() => this.disconnect(state));\n\t\t\t},\n\t\t};\n\t}\n\n\tasync close(): Promise<void> {\n\t\tif (this.closePromise) return this.closePromise;\n\t\tthis.closing = true;\n\t\tthis.closePromise = this.closeInternal();\n\t\treturn this.closePromise;\n\t}\n\n\tprivate async closeInternal(): Promise<void> {\n\t\tconst starting = this.startPromise;\n\t\tif (starting) await starting.catch(() => {});\n\t\tconst errors: unknown[] = [];\n\t\tconst listenerResults = await Promise.allSettled(this.listeners.map((listener) => listener.close()));\n\t\tfor (const result of listenerResults) {\n\t\t\tif (result.status === \"rejected\") errors.push(result.reason);\n\t\t}\n\t\ttry {\n\t\t\tawait this.closeServerState();\n\t\t} catch (error) {\n\t\t\terrors.push(error);\n\t\t}\n\t\tthis.started = false;\n\t\tif (errors.length > 0) {\n\t\t\tconst failure =\n\t\t\t\terrors.length === 1 && errors[0] instanceof Error\n\t\t\t\t\t? errors[0]\n\t\t\t\t\t: new AggregateError(errors, \"Server shutdown failed\");\n\t\t\tthis.settleClosed(failure);\n\t\t\tthrow failure;\n\t\t}\n\t\tthis.settleClosed();\n\t}\n\n\tprivate receive(state: ConnectionState, chunk: Uint8Array): void {\n\t\tif (isTerminalConnection(state)) return;\n\t\tlet messages: ClientMessage[];\n\t\ttry {\n\t\t\tmessages = state.decoder.push(chunk);\n\t\t} catch (error) {\n\t\t\tvoid this.failProtocol(state, this.toProtocolError(error));\n\t\t\treturn;\n\t\t}\n\t\tfor (const message of messages) {\n\t\t\tif (isTerminalConnection(state)) return;\n\t\t\tthis.dispatchMessage(state, message);\n\t\t}\n\t}\n\n\tprivate dispatchMessage(state: ConnectionState, message: ClientMessage): void {\n\t\tif (state.stage === \"awaitingHello\") {\n\t\t\tif (message.type !== \"hello\") {\n\t\t\t\tvoid this.failProtocol(state, {\n\t\t\t\t\tcode: \"invalid_request\",\n\t\t\t\t\tmessage: \"The first client message must be hello\",\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tstate.stage = \"handshaking\";\n\t\t\tstate.handshake = this.finishHandshake(state, message).catch((error: unknown) =>\n\t\t\t\tthis.failProtocol(state, this.toProtocolError(error)),\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tif (message.type === \"hello\") {\n\t\t\tvoid this.failProtocol(state, {\n\t\t\t\tcode: \"invalid_request\",\n\t\t\t\tmessage: \"hello may only be sent as the first message\",\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tif (state.stage === \"ready\") {\n\t\t\tif (message.type === \"cancel\") this.handleCancel(state, message);\n\t\t\telse void this.handleRequest(state, message);\n\t\t\treturn;\n\t\t}\n\t\tif (state.stage !== \"handshaking\") return;\n\t\tconst handshake = state.handshake;\n\t\tif (!handshake) return;\n\t\tvoid handshake.then(() => {\n\t\t\tif (state.stage !== \"ready\" || state.disconnected) return;\n\t\t\tif (message.type === \"cancel\") this.handleCancel(state, message);\n\t\t\telse void this.handleRequest(state, message);\n\t\t});\n\t}\n\n\tprivate async finishHandshake(state: ConnectionState, hello: ClientHello): Promise<void> {\n\t\tif (!isSupportedProtocolVersion(hello.version)) {\n\t\t\tawait this.failProtocol(state, {\n\t\t\t\tcode: \"version\",\n\t\t\t\tmessage: `Unsupported protocol version ${hello.version}; expected ${PROTOCOL_VERSION}`,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.closing || state.disconnected || state.stage !== \"handshaking\" || state.connection.closed) return;\n\t\tconst services = await this.host.serverServices.attachClient(\n\t\t\t{\n\t\t\t\tattachSession: async (sessionId, context) => {\n\t\t\t\t\tawait this.sessions.attachClient(state, sessionId, context);\n\t\t\t\t},\n\t\t\t\tdetachSession: (context) => this.sessions.detachClient(state, context),\n\t\t\t\tprepareSessionRemoval: (sessionId, context) => this.sessions.removeSession(sessionId, context),\n\t\t\t},\n\t\t\tTODO_CONTEXT,\n\t\t);\n\t\tif (this.closing || state.disconnected || state.stage !== \"handshaking\" || state.connection.closed) {\n\t\t\tawait services.release(TODO_CONTEXT);\n\t\t\treturn;\n\t\t}\n\t\tstate.serverServices = services;\n\t\tconst sent = await this.sendMessage(state, {\n\t\t\ttype: \"hello\",\n\t\t\tversion: PROTOCOL_VERSION,\n\t\t\tserverId: this.serverId,\n\t\t} satisfies ServerHello);\n\t\tif (sent && !state.disconnected && state.stage === \"handshaking\") {\n\t\t\tstate.stage = \"ready\";\n\t\t\tclearTimeout(state.handshakeTimeout);\n\t\t}\n\t}\n\n\tprivate handleCancel(state: ConnectionState, envelope: CancelEnvelope): void {\n\t\tif (envelope.target.serverId !== this.serverId) return;\n\t\tconst active = state.activeRequests.get(envelope.id);\n\t\tif (active !== undefined && sameTarget(active.target, envelope.target)) {\n\t\t\tactive.controller.abort(new DOMException(\"RPC request cancelled\", \"AbortError\"));\n\t\t}\n\t}\n\n\tprivate async handleRequest(state: ConnectionState, envelope: RequestEnvelope): Promise<void> {\n\t\tif (state.activeRequests.has(envelope.id)) {\n\t\t\tawait this.sendMessage(state, {\n\t\t\t\ttype: \"response\",\n\t\t\t\tid: envelope.id,\n\t\t\t\tok: false,\n\t\t\t\terror: { code: \"invalid_request\", message: \"Request ID is already active\" },\n\t\t\t} satisfies ResponseEnvelope);\n\t\t\treturn;\n\t\t}\n\t\tlet call: ServiceCall;\n\t\ttry {\n\t\t\tcall = parseServiceCall(envelope.call);\n\t\t} catch {\n\t\t\tawait this.sendMessage(state, {\n\t\t\t\ttype: \"response\",\n\t\t\t\tid: envelope.id,\n\t\t\t\tok: false,\n\t\t\t\terror: { code: \"invalid_request\", message: \"Invalid service call\" },\n\t\t\t} satisfies ResponseEnvelope);\n\t\t\treturn;\n\t\t}\n\t\tconst controller = new AbortController();\n\t\tconst active = { controller, target: envelope.target };\n\t\tstate.activeRequests.set(envelope.id, active);\n\t\tconst context = withAbortSignal(controller.signal, TODO_CONTEXT);\n\t\tconst control = decodeServiceControlCall(call);\n\t\tconst subscribing = control?.type === \"subscribe\" ? control : undefined;\n\t\tconst pendingUpdates: { readonly update: ServiceProviderUpdate }[] = [];\n\t\tlet subscriptionReady = subscribing === undefined;\n\t\tlet installedSubscriptionEncoder = false;\n\t\tlet responded = false;\n\t\tconst publish = async (subscriptionId: string, update: ServiceProviderUpdate): Promise<void> => {\n\t\t\tif (subscribing !== undefined && subscriptionId === subscribing.subscriptionId && !subscriptionReady) {\n\t\t\t\tpendingUpdates.push({ update });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tawait this.sendServiceUpdate(state, subscriptionId, update);\n\t\t};\n\t\ttry {\n\t\t\tif (envelope.target.serverId !== this.serverId) throw new WrongServerError();\n\t\t\tif (subscribing !== undefined && state.serviceStateEncoders.has(subscribing.subscriptionId)) {\n\t\t\t\tthrow new ProtocolValidationError(`Duplicate service subscription ${subscribing.subscriptionId}`);\n\t\t\t}\n\t\t\tlet result: JsonValue | undefined;\n\t\t\tif (\"sessionId\" in envelope.target) {\n\t\t\t\tresult = await this.sessions.executeServiceCall(call, envelope.target, state, publish, context);\n\t\t\t} else if (state.serverServices !== undefined) {\n\t\t\t\tresult = await state.serverServices.invokeService(call, publish, context);\n\t\t\t} else {\n\t\t\t\tthrow new ProtocolValidationError(`Unknown service member ${call.serviceId}.${call.member}`);\n\t\t\t}\n\t\t\tif (subscribing !== undefined) {\n\t\t\t\tif (result === undefined)\n\t\t\t\t\tthrow new ProtocolValidationError(\"Service subscription did not return a snapshot\");\n\t\t\t\tconst stateEncoder = createServiceStateEncoder();\n\t\t\t\tresult = stateEncoder.encodeSnapshot(parseServiceSubscriptionSnapshot(result)) as unknown as JsonValue;\n\t\t\t\tstate.serviceStateEncoders.set(subscribing.subscriptionId, stateEncoder);\n\t\t\t\tinstalledSubscriptionEncoder = true;\n\t\t\t} else if (control?.type === \"unsubscribe\") {\n\t\t\t\tstate.serviceStateEncoders.delete(control.subscriptionId);\n\t\t\t}\n\t\t\tawait this.sendMessage(\n\t\t\t\tstate,\n\t\t\t\tresult === undefined\n\t\t\t\t\t? { type: \"response\", id: envelope.id, ok: true }\n\t\t\t\t\t: { type: \"response\", id: envelope.id, ok: true, result },\n\t\t\t);\n\t\t\tresponded = true;\n\t\t\tif (subscribing !== undefined) {\n\t\t\t\twhile (pendingUpdates.length > 0) {\n\t\t\t\t\tconst pending = pendingUpdates.shift();\n\t\t\t\t\tif (pending !== undefined)\n\t\t\t\t\t\tawait this.sendServiceUpdate(state, subscribing.subscriptionId, pending.update);\n\t\t\t\t}\n\t\t\t\tsubscriptionReady = true;\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (subscribing !== undefined && installedSubscriptionEncoder && !responded) {\n\t\t\t\tstate.serviceStateEncoders.delete(subscribing.subscriptionId);\n\t\t\t}\n\t\t\tif (responded) {\n\t\t\t\tthis.reportError(error);\n\t\t\t\tawait this.closeConnection(state.connection);\n\t\t\t\tthis.disconnect(state);\n\t\t\t} else {\n\t\t\t\tawait this.sendMessage(state, {\n\t\t\t\t\ttype: \"response\",\n\t\t\t\t\tid: envelope.id,\n\t\t\t\t\tok: false,\n\t\t\t\t\terror: controller.signal.aborted\n\t\t\t\t\t\t? { code: \"cancelled\", message: \"RPC request cancelled\" }\n\t\t\t\t\t\t: this.toProtocolError(error),\n\t\t\t\t} satisfies ResponseEnvelope);\n\t\t\t}\n\t\t} finally {\n\t\t\tif (state.activeRequests.get(envelope.id) === active) state.activeRequests.delete(envelope.id);\n\t\t}\n\t}\n\n\tprivate transportClosed(connection: ConnectionState): void {\n\t\tif (!connection.disconnected && connection.stage !== \"closing\") {\n\t\t\ttry {\n\t\t\t\tconnection.decoder.end();\n\t\t\t} catch (error) {\n\t\t\t\tthis.reportError(error);\n\t\t\t}\n\t\t}\n\t\tthis.disconnect(connection);\n\t}\n\n\tprivate disconnect(connection: ConnectionState): void {\n\t\tif (connection.disconnected) return;\n\t\tconnection.disconnected = true;\n\t\tconnection.stage = \"closed\";\n\t\tclearTimeout(connection.handshakeTimeout);\n\t\tfor (const { controller } of connection.activeRequests.values()) {\n\t\t\tcontroller.abort(new Error(\"Client disconnected\"));\n\t\t}\n\t\tconnection.activeRequests.clear();\n\t\tconnection.serviceStateEncoders.clear();\n\t\tif (this.connections.delete(connection)) this.notifyConnectionCountChanged();\n\t\tconst serverServices = connection.serverServices;\n\t\tdelete connection.serverServices;\n\t\tvoid Promise.allSettled([\n\t\t\tthis.sessions.disconnect(connection, TODO_CONTEXT),\n\t\t\tserverServices?.release(TODO_CONTEXT),\n\t\t]).then((results) => {\n\t\t\tfor (const result of results) if (result.status === \"rejected\") this.reportError(result.reason);\n\t\t});\n\t}\n\n\tprivate async sendServiceUpdate(\n\t\tconnection: ConnectionState,\n\t\tsubscriptionId: string,\n\t\tupdate: ServiceProviderUpdate,\n\t): Promise<void> {\n\t\tconst stateEncoder = connection.serviceStateEncoders.get(subscriptionId);\n\t\tif (stateEncoder === undefined) return;\n\t\tawait this.sendMessage(connection, {\n\t\t\ttype: \"service_update\",\n\t\t\tsubscriptionId,\n\t\t\tupdate: stateEncoder.encodeUpdate(update) as unknown as JsonValue,\n\t\t});\n\t}\n\n\tprivate async sendMessage(connection: ConnectionState, message: ServerMessage): Promise<boolean> {\n\t\tif (connection.disconnected || connection.connection.closed) return false;\n\t\tlet frame: Uint8Array;\n\t\ttry {\n\t\t\tframe = encodeServerMessage(message, { maxFrameLength: this.maxFrameLength });\n\t\t} catch (error) {\n\t\t\tthis.reportError(error);\n\t\t\tawait this.closeConnection(connection.connection);\n\t\t\tthis.disconnect(connection);\n\t\t\treturn false;\n\t\t}\n\t\ttry {\n\t\t\tawait connection.connection.send(frame);\n\t\t\treturn true;\n\t\t} catch (error) {\n\t\t\tthis.reportError(error);\n\t\t\tawait this.closeConnection(connection.connection);\n\t\t\tthis.disconnect(connection);\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tprivate async failProtocol(connection: ConnectionState, error: ProtocolError): Promise<void> {\n\t\tif (connection.disconnected || connection.stage === \"closing\" || connection.stage === \"closed\") return;\n\t\tconnection.stage = \"closing\";\n\t\tclearTimeout(connection.handshakeTimeout);\n\t\tconst message: ServerHelloError = { type: \"hello_error\", error };\n\t\tlet finalFrame: Uint8Array | undefined;\n\t\ttry {\n\t\t\tfinalFrame = encodeServerMessage(message, { maxFrameLength: this.maxFrameLength });\n\t\t} catch (encodeError) {\n\t\t\tthis.reportError(encodeError);\n\t\t}\n\t\tawait this.closeConnection(connection.connection, finalFrame);\n\t\tthis.disconnect(connection);\n\t}\n\n\tprivate async closeServerState(): Promise<void> {\n\t\tconst connections = [...this.connections];\n\t\tfor (const connection of connections) {\n\t\t\tconnection.stage = \"closing\";\n\t\t\tclearTimeout(connection.handshakeTimeout);\n\t\t}\n\t\tawait Promise.all(connections.map((connection) => this.closeConnection(connection.connection)));\n\t\tfor (const connection of connections) this.disconnect(connection);\n\t\tconst cleanup = await Promise.allSettled([this.sessions.close(BACKGROUND_CONTEXT)]);\n\t\tthis.connections.clear();\n\t\tconst errors = cleanup.flatMap((result) => (result.status === \"rejected\" ? [result.reason] : []));\n\t\tif (errors.length === 1) throw errors[0];\n\t\tif (errors.length > 1) throw new AggregateError(errors, \"Failed to close server Sessions\");\n\t}\n\n\tprivate async closeConnection(connection: ByteConnection, finalChunk?: Uint8Array): Promise<void> {\n\t\ttry {\n\t\t\tawait connection.close(finalChunk);\n\t\t} catch (error) {\n\t\t\tthis.reportError(error);\n\t\t}\n\t}\n\n\tprivate toProtocolError(error: unknown): ProtocolError {\n\t\tif (error instanceof ServerError || error instanceof RemoteServiceError) {\n\t\t\treturn { code: error.code, message: error.message };\n\t\t}\n\t\tif (error instanceof ProtocolValidationError) {\n\t\t\treturn { code: \"invalid_request\", message: error.message };\n\t\t}\n\t\tthis.reportError(error);\n\t\treturn { code: \"internal_error\", message: INTERNAL_SERVER_ERROR_MESSAGE };\n\t}\n\n\tprivate notifyConnectionCountChanged(): void {\n\t\ttry {\n\t\t\tthis.onConnectionCountChanged?.(this.connections.size);\n\t\t} catch (error) {\n\t\t\tthis.reportError(error);\n\t\t}\n\t}\n\n\tprivate reportError(error: unknown): void {\n\t\ttry {\n\t\t\tthis.onError?.(error instanceof Error ? error : new Error(String(error)));\n\t\t} catch {\n\t\t\t// Error observers cannot affect server state.\n\t\t}\n\t}\n\n\tprivate settleClosed(error?: unknown): void {\n\t\tif (this.closedSettled) return;\n\t\tthis.closedSettled = true;\n\t\tif (error === undefined) this.resolveClosed();\n\t\telse this.rejectClosed(error);\n\t}\n}\n\nfunction sameTarget(left: RpcTarget, right: RpcTarget): boolean {\n\tif (left.serverId !== right.serverId) return false;\n\tif (!(\"sessionId\" in left) || !(\"sessionId\" in right)) {\n\t\treturn !(\"sessionId\" in left) && !(\"sessionId\" in right);\n\t}\n\treturn left.sessionId === right.sessionId && left.attachmentId === right.attachmentId;\n}\n\nfunction resolveOptions(options: ServerOptions): {\n\tmaxFrameLength: number;\n\thandshakeTimeoutMs: number;\n} {\n\tif (!Array.isArray(options.listeners)) throw new TypeError(\"Server listeners must be an array\");\n\tif (!isServerId(options.serverId)) {\n\t\tthrow new TypeError(\"serverId must be a canonical lowercase UUIDv4\");\n\t}\n\tconst maxFrameLength = options.maxFrameLength ?? DEFAULT_MAX_FRAME_LENGTH;\n\tif (!Number.isSafeInteger(maxFrameLength) || maxFrameLength <= 0 || maxFrameLength > MAX_UINT32) {\n\t\tthrow new TypeError(`Server maxFrameLength must be an integer between 1 and ${MAX_UINT32}`);\n\t}\n\tconst handshakeTimeoutMs = options.handshakeTimeoutMs ?? DEFAULT_HANDSHAKE_TIMEOUT_MS;\n\tif (\n\t\t!Number.isSafeInteger(handshakeTimeoutMs) ||\n\t\thandshakeTimeoutMs <= 0 ||\n\t\thandshakeTimeoutMs > MAX_TIMER_DELAY_MS\n\t) {\n\t\tthrow new TypeError(`Server handshakeTimeoutMs must be an integer between 1 and ${MAX_TIMER_DELAY_MS}`);\n\t}\n\treturn { maxFrameLength, handshakeTimeoutMs };\n}\n"]}
|