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 @@
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AAO,CAAC,eAAe,EAAE,CAAC,CAgB/C;IAEK,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAiB3B;YAEa,YAAY;YAeZ,OAAO;YAuBP,MAAM;IAuCpB,OAAO,CAAC,kBAAkB;YA2BZ,SAAS;YAWT,kBAAkB;IAahC,OAAO,CAAC,aAAa;YAIP,iBAAiB;YAOjB,MAAM;IASpB,OAAO,CAAC,eAAe;IAWvB,OAAO,CAAC,oBAAoB;YAId,YAAY;CAsB1B","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type { Command, EventEnvelope, SessionMetadata, SessionSnapshot } from \"@earendil-works/pi-protocol\";\nimport type { ByteConnection, ConnectionState } from \"./connection.ts\";\nimport { PiServerError } from \"./errors.ts\";\nimport type { CreateSessionOptions, PiServerService, PiSessionRuntime, PiSessionRuntimeEvent } from \"./types.ts\";\n\ninterface LiveSession {\n\tid: string;\n\truntime: PiSessionRuntime;\n\tconnections: Set<ConnectionState>;\n\tunsubscribe: () => void;\n\toperationCount: number;\n\tready: boolean;\n\tterminal: boolean;\n\tdisposing?: Promise<void>;\n}\n\ninterface LiveSessionManagerOptions {\n\tservice: PiServerService;\n\tisClosing: () => boolean;\n\tsendMessage: (connection: ConnectionState, message: EventEnvelope) => Promise<boolean>;\n\tcloseConnection: (connection: ByteConnection) => Promise<void>;\n\tdisconnect: (connection: ConnectionState) => Promise<void>;\n\tbroadcastServerSnapshot: () => void;\n\treportError: (error: unknown) => void;\n}\n\nfunction toMetadata(snapshot: SessionSnapshot): SessionMetadata {\n\treturn {\n\t\tid: snapshot.id,\n\t\tcreatedAt: snapshot.createdAt,\n\t\tupdatedAt: snapshot.updatedAt,\n\t\tsessionName: snapshot.name,\n\t\tcwd: snapshot.cwd,\n\t};\n}\n\nexport class LiveSessionManager {\n\tprivate readonly options: LiveSessionManagerOptions;\n\tprivate readonly liveSessions = new Map<string, LiveSession>();\n\tprivate readonly openingSessions = new Map<string, Promise<LiveSession>>();\n\n\tconstructor(options: LiveSessionManagerOptions) {\n\t\tthis.options = options;\n\t}\n\n\tasync executeCommand(connection: ConnectionState, command: Command) {\n\t\tswitch (command.command) {\n\t\t\tcase \"list\":\n\t\t\t\treturn { command: \"list\" as const, sessions: await this.listMetadata() };\n\t\t\tcase \"create\": {\n\t\t\t\tconst id = randomUUID();\n\t\t\t\tconst options: CreateSessionOptions = {\n\t\t\t\t\tid,\n\t\t\t\t\tcwd: command.cwd,\n\t\t\t\t\tname: command.name,\n\t\t\t\t\tmodel: command.model,\n\t\t\t\t\tthinkingLevel: command.thinkingLevel,\n\t\t\t\t};\n\t\t\t\tconst live = await this.acquire(id, () => this.options.service.createSession(options));\n\t\t\t\tawait this.attach(connection, live);\n\t\t\t\tconst session = this.forConnection(await this.broadcastSnapshot(live), connection);\n\t\t\t\tthis.options.broadcastServerSnapshot();\n\t\t\t\treturn { command: \"create\" as const, session };\n\t\t\t}\n\t\t\tcase \"attach\": {\n\t\t\t\tconst live = await this.acquire(command.sessionId, () =>\n\t\t\t\t\tthis.options.service.openSession(command.sessionId),\n\t\t\t\t);\n\t\t\t\tawait this.attach(connection, live);\n\t\t\t\tconst session = this.forConnection(await this.broadcastSnapshot(live), connection);\n\t\t\t\tthis.options.broadcastServerSnapshot();\n\t\t\t\treturn { command: \"attach\" as const, session };\n\t\t\t}\n\t\t\tcase \"detach\": {\n\t\t\t\tconst live = this.liveSessions.get(command.sessionId);\n\t\t\t\tif (connection.sessionIds.has(command.sessionId)) {\n\t\t\t\t\tconnection.sessionIds.delete(command.sessionId);\n\t\t\t\t\tconnection.extensionUiSessions.delete(command.sessionId);\n\t\t\t\t\tif (live) {\n\t\t\t\t\t\tlive.connections.delete(connection);\n\t\t\t\t\t\tif (live.connections.size > 0 && !live.terminal && !live.disposing) {\n\t\t\t\t\t\t\tawait this.broadcastSnapshot(live);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tawait this.maybeDispose(live);\n\t\t\t\t\t}\n\t\t\t\t\tthis.options.broadcastServerSnapshot();\n\t\t\t\t}\n\t\t\t\treturn { command: \"detach\" as const, sessionId: command.sessionId };\n\t\t\t}\n\t\t\tcase \"prompt\": {\n\t\t\t\tconst live = this.requireAttached(connection, command.sessionId);\n\t\t\t\tconst session = await this.runOperation(connection, live, () =>\n\t\t\t\t\tlive.runtime.prompt({ text: command.text }),\n\t\t\t\t);\n\t\t\t\treturn { command: \"prompt\" as const, session };\n\t\t\t}\n\t\t\tcase \"steer\": {\n\t\t\t\tconst live = this.requireAttached(connection, command.sessionId);\n\t\t\t\tconst session = await this.runOperation(connection, live, () => live.runtime.steer({ text: command.text }));\n\t\t\t\treturn { command: \"steer\" as const, session };\n\t\t\t}\n\t\t\tcase \"abort\": {\n\t\t\t\tconst live = this.requireAttached(connection, command.sessionId);\n\t\t\t\tconst session = await this.runOperation(connection, live, () => live.runtime.abort());\n\t\t\t\treturn { command: \"abort\" as const, session };\n\t\t\t}\n\t\t\tcase \"set_model\": {\n\t\t\t\tconst live = this.requireAttached(connection, command.sessionId);\n\t\t\t\tconst session = await this.runOperation(connection, live, () => live.runtime.setModel(command.model));\n\t\t\t\treturn { command: \"set_model\" as const, session };\n\t\t\t}\n\t\t\tcase \"set_thinking\": {\n\t\t\t\tconst live = this.requireAttached(connection, command.sessionId);\n\t\t\t\tconst session = await this.runOperation(connection, live, () =>\n\t\t\t\t\tlive.runtime.setThinking(command.thinkingLevel),\n\t\t\t\t);\n\t\t\t\treturn { command: \"set_thinking\" as const, session };\n\t\t\t}\n\t\t\tcase \"subscribe_extension_ui\": {\n\t\t\t\tthis.requireAttached(connection, command.sessionId);\n\t\t\t\tconnection.extensionUiSessions.add(command.sessionId);\n\t\t\t\treturn { command: \"subscribe_extension_ui\" as const, sessionId: command.sessionId };\n\t\t\t}\n\t\t\tcase \"extension_ui_answer\": {\n\t\t\t\tconst live = this.requireAttached(connection, command.sessionId);\n\t\t\t\tawait live.runtime.answerExtensionUi(command.requestId, command.answer);\n\t\t\t\treturn {\n\t\t\t\t\tcommand: \"extension_ui_answer\" as const,\n\t\t\t\t\tsessionId: command.sessionId,\n\t\t\t\t\trequestId: command.requestId,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t}\n\n\tasync disconnect(connection: ConnectionState): Promise<void> {\n\t\tconst sessions = [...connection.sessionIds]\n\t\t\t.map((id) => this.liveSessions.get(id))\n\t\t\t.filter((live): live is LiveSession => live !== undefined);\n\t\tconnection.sessionIds.clear();\n\t\tconnection.extensionUiSessions.clear();\n\t\tfor (const live of sessions) live.connections.delete(connection);\n\t\tconst results = await Promise.allSettled(sessions.map((live) => this.maybeDispose(live)));\n\t\tfor (const result of results) {\n\t\t\tif (result.status === \"rejected\") this.options.reportError(result.reason);\n\t\t}\n\t}\n\n\tasync listMetadata(): Promise<SessionMetadata[]> {\n\t\tconst stored = await this.options.service.listSessions();\n\t\tconst liveSnapshots = await Promise.all(\n\t\t\t[...this.liveSessions.values()]\n\t\t\t\t.filter((live) => !live.disposing)\n\t\t\t\t.map(async (live) => [live.id, await this.normalizedSnapshot(live)] as const),\n\t\t);\n\t\tconst liveById = new Map(liveSnapshots);\n\t\tconst metadata = stored.map((item) => {\n\t\t\tconst snapshot = liveById.get(item.id);\n\t\t\tif (!snapshot) return item;\n\t\t\tliveById.delete(item.id);\n\t\t\treturn { ...item, ...toMetadata(snapshot) };\n\t\t});\n\t\tfor (const snapshot of liveById.values()) metadata.push(toMetadata(snapshot));\n\t\treturn metadata;\n\t}\n\n\tasync close(): Promise<void> {\n\t\tconst openingResults = await Promise.allSettled([...this.openingSessions.values()]);\n\t\tfor (const result of openingResults) {\n\t\t\tif (result.status === \"rejected\") this.options.reportError(result.reason);\n\t\t}\n\t\tconst sessions = [...this.liveSessions.values()];\n\t\tthis.liveSessions.clear();\n\t\tawait Promise.all(\n\t\t\tsessions.map(async (live) => {\n\t\t\t\tif (live.disposing) {\n\t\t\t\t\tawait live.disposing;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tlive.unsubscribe();\n\t\t\t\tawait live.runtime.dispose();\n\t\t\t}),\n\t\t);\n\t}\n\n\tprivate async runOperation(\n\t\tconnection: ConnectionState,\n\t\tlive: LiveSession,\n\t\toperation: () => Promise<void>,\n\t): Promise<SessionSnapshot> {\n\t\tlive.operationCount += 1;\n\t\ttry {\n\t\t\tawait operation();\n\t\t\treturn this.forConnection(await this.broadcastSnapshot(live), connection);\n\t\t} finally {\n\t\t\tlive.operationCount -= 1;\n\t\t\tthis.scheduleMaybeDispose(live);\n\t\t}\n\t}\n\n\tprivate async acquire(id: string, acquireRuntime: () => Promise<PiSessionRuntime>): Promise<LiveSession> {\n\t\tfor (;;) {\n\t\t\tconst existing = this.liveSessions.get(id);\n\t\t\tif (existing) {\n\t\t\t\tif (existing.terminal) throw new PiServerError(\"session_locked\", `Session runtime is terminating: ${id}`);\n\t\t\t\tif (existing.disposing) {\n\t\t\t\t\tawait existing.disposing;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\treturn existing;\n\t\t\t}\n\t\t\tconst opening = this.openingSessions.get(id);\n\t\t\tif (opening) return opening;\n\t\t\tconst pending = this.create(id, acquireRuntime);\n\t\t\tthis.openingSessions.set(id, pending);\n\t\t\ttry {\n\t\t\t\treturn await pending;\n\t\t\t} finally {\n\t\t\t\tif (this.openingSessions.get(id) === pending) this.openingSessions.delete(id);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async create(id: string, acquireRuntime: () => Promise<PiSessionRuntime>): Promise<LiveSession> {\n\t\tconst runtime = await acquireRuntime();\n\t\tif (this.options.isClosing()) {\n\t\t\tawait runtime.dispose();\n\t\t\tthrow new Error(\"PiServer closed while acquiring a session runtime\");\n\t\t}\n\t\tlet live: LiveSession | undefined;\n\t\ttry {\n\t\t\tconst snapshot = await runtime.snapshot();\n\t\t\tif (snapshot.id !== id) {\n\t\t\t\tthrow new PiServerError(\n\t\t\t\t\t\"invalid_request\",\n\t\t\t\t\t`Service returned session ${snapshot.id} for server-assigned session ${id}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tlive = {\n\t\t\t\tid,\n\t\t\t\truntime,\n\t\t\t\tconnections: new Set(),\n\t\t\t\tunsubscribe: () => {},\n\t\t\t\toperationCount: 0,\n\t\t\t\tready: false,\n\t\t\t\tterminal: false,\n\t\t\t};\n\t\t\tlive.unsubscribe = runtime.subscribe((event) => this.handleRuntimeEvent(live!, event));\n\t\t\tthis.liveSessions.set(id, live);\n\t\t\tlive.ready = true;\n\t\t\treturn live;\n\t\t} catch (error) {\n\t\t\tif (live) live.unsubscribe();\n\t\t\ttry {\n\t\t\t\tawait runtime.dispose();\n\t\t\t} catch (disposeError) {\n\t\t\t\tthis.options.reportError(disposeError);\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tprivate handleRuntimeEvent(live: LiveSession, event: PiSessionRuntimeEvent): void {\n\t\tif (event.type === \"error\") {\n\t\t\tvoid this.terminate(live, event.error).catch((error: unknown) => this.options.reportError(error));\n\t\t\treturn;\n\t\t}\n\t\tif (event.type === \"progress\") {\n\t\t\tconst envelope: EventEnvelope = {\n\t\t\t\ttype: \"event\",\n\t\t\t\tevent: { type: \"session_progress\", sessionId: live.id, progress: event.progress },\n\t\t\t};\n\t\t\tfor (const connection of live.connections) void this.options.sendMessage(connection, envelope);\n\t\t} else if (event.type === \"extension_ui\") {\n\t\t\tconst envelope: EventEnvelope = {\n\t\t\t\ttype: \"event\",\n\t\t\t\tevent: { type: \"extension_ui\", sessionId: live.id, payload: event.payload },\n\t\t\t};\n\t\t\tfor (const connection of live.connections) {\n\t\t\t\tif (connection.extensionUiSessions.has(live.id)) {\n\t\t\t\t\tvoid this.options.sendMessage(connection, envelope);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tvoid this.broadcastSnapshot(live).catch((error: unknown) => this.options.reportError(error));\n\t\t}\n\t\tthis.scheduleMaybeDispose(live);\n\t}\n\n\tprivate async terminate(live: LiveSession, error: PiServerError): Promise<void> {\n\t\tif (live.terminal) return;\n\t\tlive.terminal = true;\n\t\tthis.options.reportError(error);\n\t\tlive.unsubscribe();\n\t\tconst connections = [...live.connections];\n\t\tawait Promise.all(connections.map((connection) => this.options.closeConnection(connection.connection)));\n\t\tawait Promise.all(connections.map((connection) => this.options.disconnect(connection)));\n\t\tawait this.maybeDispose(live);\n\t}\n\n\tprivate async normalizedSnapshot(live: LiveSession): Promise<SessionSnapshot> {\n\t\tconst snapshot = await live.runtime.snapshot();\n\t\tif (snapshot.id !== live.id) {\n\t\t\tthrow new PiServerError(\"invalid_request\", `Runtime session ID changed from ${live.id} to ${snapshot.id}`);\n\t\t}\n\t\treturn {\n\t\t\t...snapshot,\n\t\t\tphase: live.runtime.getPhase(),\n\t\t\tattached: live.connections.size > 0,\n\t\t\tlocked: true,\n\t\t};\n\t}\n\n\tprivate forConnection(snapshot: SessionSnapshot, connection: ConnectionState): SessionSnapshot {\n\t\treturn { ...snapshot, attached: connection.sessionIds.has(snapshot.id) };\n\t}\n\n\tprivate async broadcastSnapshot(live: LiveSession): Promise<SessionSnapshot> {\n\t\tconst snapshot = await this.normalizedSnapshot(live);\n\t\tconst envelope: EventEnvelope = { type: \"event\", event: { type: \"session_snapshot\", snapshot } };\n\t\tfor (const connection of live.connections) void this.options.sendMessage(connection, envelope);\n\t\treturn snapshot;\n\t}\n\n\tprivate async attach(connection: ConnectionState, live: LiveSession): Promise<void> {\n\t\tif (connection.disconnected || connection.stage !== \"ready\" || connection.connection.closed) {\n\t\t\tawait this.maybeDispose(live);\n\t\t\tthrow new PiServerError(\"invalid_request\", \"Connection closed while attaching to a session\");\n\t\t}\n\t\tconnection.sessionIds.add(live.id);\n\t\tlive.connections.add(connection);\n\t}\n\n\tprivate requireAttached(connection: ConnectionState, sessionId: string): LiveSession {\n\t\tif (!connection.sessionIds.has(sessionId)) {\n\t\t\tthrow new PiServerError(\"invalid_request\", `Connection is not attached to session ${sessionId}`);\n\t\t}\n\t\tconst live = this.liveSessions.get(sessionId);\n\t\tif (!live || live.terminal || live.disposing) {\n\t\t\tthrow new PiServerError(\"not_found\", `Session is not live: ${sessionId}`);\n\t\t}\n\t\treturn live;\n\t}\n\n\tprivate scheduleMaybeDispose(live: LiveSession): void {\n\t\tvoid this.maybeDispose(live).catch((error: unknown) => this.options.reportError(error));\n\t}\n\n\tprivate async maybeDispose(live: LiveSession): Promise<void> {\n\t\tif (\n\t\t\tthis.options.isClosing() ||\n\t\t\t!live.ready ||\n\t\t\tlive.disposing ||\n\t\t\tlive.connections.size > 0 ||\n\t\t\tlive.operationCount > 0 ||\n\t\t\t(!live.terminal && live.runtime.getPhase() !== \"idle\")\n\t\t) {\n\t\t\treturn live.disposing;\n\t\t}\n\t\tlive.unsubscribe();\n\t\tlive.disposing = (async () => {\n\t\t\ttry {\n\t\t\t\tawait live.runtime.dispose();\n\t\t\t} finally {\n\t\t\t\tif (this.liveSessions.get(live.id) === live) this.liveSessions.delete(live.id);\n\t\t\t}\n\t\t})();\n\t\tawait live.disposing;\n\t\tif (!this.options.isClosing()) this.options.broadcastServerSnapshot();\n\t}\n}\n"]}
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { PiServerError } from "./errors.js";
|
|
3
|
+
function toMetadata(snapshot) {
|
|
4
|
+
return {
|
|
5
|
+
id: snapshot.id,
|
|
6
|
+
createdAt: snapshot.createdAt,
|
|
7
|
+
updatedAt: snapshot.updatedAt,
|
|
8
|
+
sessionName: snapshot.name,
|
|
9
|
+
cwd: snapshot.cwd,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export class LiveSessionManager {
|
|
13
|
+
options;
|
|
14
|
+
liveSessions = new Map();
|
|
15
|
+
openingSessions = new Map();
|
|
16
|
+
constructor(options) {
|
|
17
|
+
this.options = options;
|
|
18
|
+
}
|
|
19
|
+
async executeCommand(connection, command) {
|
|
20
|
+
switch (command.command) {
|
|
21
|
+
case "list":
|
|
22
|
+
return { command: "list", sessions: await this.listMetadata() };
|
|
23
|
+
case "create": {
|
|
24
|
+
const id = randomUUID();
|
|
25
|
+
const options = {
|
|
26
|
+
id,
|
|
27
|
+
cwd: command.cwd,
|
|
28
|
+
name: command.name,
|
|
29
|
+
model: command.model,
|
|
30
|
+
thinkingLevel: command.thinkingLevel,
|
|
31
|
+
};
|
|
32
|
+
const live = await this.acquire(id, () => this.options.service.createSession(options));
|
|
33
|
+
await this.attach(connection, live);
|
|
34
|
+
const session = this.forConnection(await this.broadcastSnapshot(live), connection);
|
|
35
|
+
this.options.broadcastServerSnapshot();
|
|
36
|
+
return { command: "create", session };
|
|
37
|
+
}
|
|
38
|
+
case "attach": {
|
|
39
|
+
const live = await this.acquire(command.sessionId, () => this.options.service.openSession(command.sessionId));
|
|
40
|
+
await this.attach(connection, live);
|
|
41
|
+
const session = this.forConnection(await this.broadcastSnapshot(live), connection);
|
|
42
|
+
this.options.broadcastServerSnapshot();
|
|
43
|
+
return { command: "attach", session };
|
|
44
|
+
}
|
|
45
|
+
case "detach": {
|
|
46
|
+
const live = this.liveSessions.get(command.sessionId);
|
|
47
|
+
if (connection.sessionIds.has(command.sessionId)) {
|
|
48
|
+
connection.sessionIds.delete(command.sessionId);
|
|
49
|
+
connection.extensionUiSessions.delete(command.sessionId);
|
|
50
|
+
if (live) {
|
|
51
|
+
live.connections.delete(connection);
|
|
52
|
+
if (live.connections.size > 0 && !live.terminal && !live.disposing) {
|
|
53
|
+
await this.broadcastSnapshot(live);
|
|
54
|
+
}
|
|
55
|
+
await this.maybeDispose(live);
|
|
56
|
+
}
|
|
57
|
+
this.options.broadcastServerSnapshot();
|
|
58
|
+
}
|
|
59
|
+
return { command: "detach", sessionId: command.sessionId };
|
|
60
|
+
}
|
|
61
|
+
case "prompt": {
|
|
62
|
+
const live = this.requireAttached(connection, command.sessionId);
|
|
63
|
+
const session = await this.runOperation(connection, live, () => live.runtime.prompt({ text: command.text }));
|
|
64
|
+
return { command: "prompt", session };
|
|
65
|
+
}
|
|
66
|
+
case "steer": {
|
|
67
|
+
const live = this.requireAttached(connection, command.sessionId);
|
|
68
|
+
const session = await this.runOperation(connection, live, () => live.runtime.steer({ text: command.text }));
|
|
69
|
+
return { command: "steer", session };
|
|
70
|
+
}
|
|
71
|
+
case "abort": {
|
|
72
|
+
const live = this.requireAttached(connection, command.sessionId);
|
|
73
|
+
const session = await this.runOperation(connection, live, () => live.runtime.abort());
|
|
74
|
+
return { command: "abort", session };
|
|
75
|
+
}
|
|
76
|
+
case "set_model": {
|
|
77
|
+
const live = this.requireAttached(connection, command.sessionId);
|
|
78
|
+
const session = await this.runOperation(connection, live, () => live.runtime.setModel(command.model));
|
|
79
|
+
return { command: "set_model", session };
|
|
80
|
+
}
|
|
81
|
+
case "set_thinking": {
|
|
82
|
+
const live = this.requireAttached(connection, command.sessionId);
|
|
83
|
+
const session = await this.runOperation(connection, live, () => live.runtime.setThinking(command.thinkingLevel));
|
|
84
|
+
return { command: "set_thinking", session };
|
|
85
|
+
}
|
|
86
|
+
case "subscribe_extension_ui": {
|
|
87
|
+
this.requireAttached(connection, command.sessionId);
|
|
88
|
+
connection.extensionUiSessions.add(command.sessionId);
|
|
89
|
+
return { command: "subscribe_extension_ui", sessionId: command.sessionId };
|
|
90
|
+
}
|
|
91
|
+
case "extension_ui_answer": {
|
|
92
|
+
const live = this.requireAttached(connection, command.sessionId);
|
|
93
|
+
await live.runtime.answerExtensionUi(command.requestId, command.answer);
|
|
94
|
+
return {
|
|
95
|
+
command: "extension_ui_answer",
|
|
96
|
+
sessionId: command.sessionId,
|
|
97
|
+
requestId: command.requestId,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async disconnect(connection) {
|
|
103
|
+
const sessions = [...connection.sessionIds]
|
|
104
|
+
.map((id) => this.liveSessions.get(id))
|
|
105
|
+
.filter((live) => live !== undefined);
|
|
106
|
+
connection.sessionIds.clear();
|
|
107
|
+
connection.extensionUiSessions.clear();
|
|
108
|
+
for (const live of sessions)
|
|
109
|
+
live.connections.delete(connection);
|
|
110
|
+
const results = await Promise.allSettled(sessions.map((live) => this.maybeDispose(live)));
|
|
111
|
+
for (const result of results) {
|
|
112
|
+
if (result.status === "rejected")
|
|
113
|
+
this.options.reportError(result.reason);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async listMetadata() {
|
|
117
|
+
const stored = await this.options.service.listSessions();
|
|
118
|
+
const liveSnapshots = await Promise.all([...this.liveSessions.values()]
|
|
119
|
+
.filter((live) => !live.disposing)
|
|
120
|
+
.map(async (live) => [live.id, await this.normalizedSnapshot(live)]));
|
|
121
|
+
const liveById = new Map(liveSnapshots);
|
|
122
|
+
const metadata = stored.map((item) => {
|
|
123
|
+
const snapshot = liveById.get(item.id);
|
|
124
|
+
if (!snapshot)
|
|
125
|
+
return item;
|
|
126
|
+
liveById.delete(item.id);
|
|
127
|
+
return { ...item, ...toMetadata(snapshot) };
|
|
128
|
+
});
|
|
129
|
+
for (const snapshot of liveById.values())
|
|
130
|
+
metadata.push(toMetadata(snapshot));
|
|
131
|
+
return metadata;
|
|
132
|
+
}
|
|
133
|
+
async close() {
|
|
134
|
+
const openingResults = await Promise.allSettled([...this.openingSessions.values()]);
|
|
135
|
+
for (const result of openingResults) {
|
|
136
|
+
if (result.status === "rejected")
|
|
137
|
+
this.options.reportError(result.reason);
|
|
138
|
+
}
|
|
139
|
+
const sessions = [...this.liveSessions.values()];
|
|
140
|
+
this.liveSessions.clear();
|
|
141
|
+
await Promise.all(sessions.map(async (live) => {
|
|
142
|
+
if (live.disposing) {
|
|
143
|
+
await live.disposing;
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
live.unsubscribe();
|
|
147
|
+
await live.runtime.dispose();
|
|
148
|
+
}));
|
|
149
|
+
}
|
|
150
|
+
async runOperation(connection, live, operation) {
|
|
151
|
+
live.operationCount += 1;
|
|
152
|
+
try {
|
|
153
|
+
await operation();
|
|
154
|
+
return this.forConnection(await this.broadcastSnapshot(live), connection);
|
|
155
|
+
}
|
|
156
|
+
finally {
|
|
157
|
+
live.operationCount -= 1;
|
|
158
|
+
this.scheduleMaybeDispose(live);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
async acquire(id, acquireRuntime) {
|
|
162
|
+
for (;;) {
|
|
163
|
+
const existing = this.liveSessions.get(id);
|
|
164
|
+
if (existing) {
|
|
165
|
+
if (existing.terminal)
|
|
166
|
+
throw new PiServerError("session_locked", `Session runtime is terminating: ${id}`);
|
|
167
|
+
if (existing.disposing) {
|
|
168
|
+
await existing.disposing;
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
return existing;
|
|
172
|
+
}
|
|
173
|
+
const opening = this.openingSessions.get(id);
|
|
174
|
+
if (opening)
|
|
175
|
+
return opening;
|
|
176
|
+
const pending = this.create(id, acquireRuntime);
|
|
177
|
+
this.openingSessions.set(id, pending);
|
|
178
|
+
try {
|
|
179
|
+
return await pending;
|
|
180
|
+
}
|
|
181
|
+
finally {
|
|
182
|
+
if (this.openingSessions.get(id) === pending)
|
|
183
|
+
this.openingSessions.delete(id);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
async create(id, acquireRuntime) {
|
|
188
|
+
const runtime = await acquireRuntime();
|
|
189
|
+
if (this.options.isClosing()) {
|
|
190
|
+
await runtime.dispose();
|
|
191
|
+
throw new Error("PiServer closed while acquiring a session runtime");
|
|
192
|
+
}
|
|
193
|
+
let live;
|
|
194
|
+
try {
|
|
195
|
+
const snapshot = await runtime.snapshot();
|
|
196
|
+
if (snapshot.id !== id) {
|
|
197
|
+
throw new PiServerError("invalid_request", `Service returned session ${snapshot.id} for server-assigned session ${id}`);
|
|
198
|
+
}
|
|
199
|
+
live = {
|
|
200
|
+
id,
|
|
201
|
+
runtime,
|
|
202
|
+
connections: new Set(),
|
|
203
|
+
unsubscribe: () => { },
|
|
204
|
+
operationCount: 0,
|
|
205
|
+
ready: false,
|
|
206
|
+
terminal: false,
|
|
207
|
+
};
|
|
208
|
+
live.unsubscribe = runtime.subscribe((event) => this.handleRuntimeEvent(live, event));
|
|
209
|
+
this.liveSessions.set(id, live);
|
|
210
|
+
live.ready = true;
|
|
211
|
+
return live;
|
|
212
|
+
}
|
|
213
|
+
catch (error) {
|
|
214
|
+
if (live)
|
|
215
|
+
live.unsubscribe();
|
|
216
|
+
try {
|
|
217
|
+
await runtime.dispose();
|
|
218
|
+
}
|
|
219
|
+
catch (disposeError) {
|
|
220
|
+
this.options.reportError(disposeError);
|
|
221
|
+
}
|
|
222
|
+
throw error;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
handleRuntimeEvent(live, event) {
|
|
226
|
+
if (event.type === "error") {
|
|
227
|
+
void this.terminate(live, event.error).catch((error) => this.options.reportError(error));
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
if (event.type === "progress") {
|
|
231
|
+
const envelope = {
|
|
232
|
+
type: "event",
|
|
233
|
+
event: { type: "session_progress", sessionId: live.id, progress: event.progress },
|
|
234
|
+
};
|
|
235
|
+
for (const connection of live.connections)
|
|
236
|
+
void this.options.sendMessage(connection, envelope);
|
|
237
|
+
}
|
|
238
|
+
else if (event.type === "extension_ui") {
|
|
239
|
+
const envelope = {
|
|
240
|
+
type: "event",
|
|
241
|
+
event: { type: "extension_ui", sessionId: live.id, payload: event.payload },
|
|
242
|
+
};
|
|
243
|
+
for (const connection of live.connections) {
|
|
244
|
+
if (connection.extensionUiSessions.has(live.id)) {
|
|
245
|
+
void this.options.sendMessage(connection, envelope);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
void this.broadcastSnapshot(live).catch((error) => this.options.reportError(error));
|
|
251
|
+
}
|
|
252
|
+
this.scheduleMaybeDispose(live);
|
|
253
|
+
}
|
|
254
|
+
async terminate(live, error) {
|
|
255
|
+
if (live.terminal)
|
|
256
|
+
return;
|
|
257
|
+
live.terminal = true;
|
|
258
|
+
this.options.reportError(error);
|
|
259
|
+
live.unsubscribe();
|
|
260
|
+
const connections = [...live.connections];
|
|
261
|
+
await Promise.all(connections.map((connection) => this.options.closeConnection(connection.connection)));
|
|
262
|
+
await Promise.all(connections.map((connection) => this.options.disconnect(connection)));
|
|
263
|
+
await this.maybeDispose(live);
|
|
264
|
+
}
|
|
265
|
+
async normalizedSnapshot(live) {
|
|
266
|
+
const snapshot = await live.runtime.snapshot();
|
|
267
|
+
if (snapshot.id !== live.id) {
|
|
268
|
+
throw new PiServerError("invalid_request", `Runtime session ID changed from ${live.id} to ${snapshot.id}`);
|
|
269
|
+
}
|
|
270
|
+
return {
|
|
271
|
+
...snapshot,
|
|
272
|
+
phase: live.runtime.getPhase(),
|
|
273
|
+
attached: live.connections.size > 0,
|
|
274
|
+
locked: true,
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
forConnection(snapshot, connection) {
|
|
278
|
+
return { ...snapshot, attached: connection.sessionIds.has(snapshot.id) };
|
|
279
|
+
}
|
|
280
|
+
async broadcastSnapshot(live) {
|
|
281
|
+
const snapshot = await this.normalizedSnapshot(live);
|
|
282
|
+
const envelope = { type: "event", event: { type: "session_snapshot", snapshot } };
|
|
283
|
+
for (const connection of live.connections)
|
|
284
|
+
void this.options.sendMessage(connection, envelope);
|
|
285
|
+
return snapshot;
|
|
286
|
+
}
|
|
287
|
+
async attach(connection, live) {
|
|
288
|
+
if (connection.disconnected || connection.stage !== "ready" || connection.connection.closed) {
|
|
289
|
+
await this.maybeDispose(live);
|
|
290
|
+
throw new PiServerError("invalid_request", "Connection closed while attaching to a session");
|
|
291
|
+
}
|
|
292
|
+
connection.sessionIds.add(live.id);
|
|
293
|
+
live.connections.add(connection);
|
|
294
|
+
}
|
|
295
|
+
requireAttached(connection, sessionId) {
|
|
296
|
+
if (!connection.sessionIds.has(sessionId)) {
|
|
297
|
+
throw new PiServerError("invalid_request", `Connection is not attached to session ${sessionId}`);
|
|
298
|
+
}
|
|
299
|
+
const live = this.liveSessions.get(sessionId);
|
|
300
|
+
if (!live || live.terminal || live.disposing) {
|
|
301
|
+
throw new PiServerError("not_found", `Session is not live: ${sessionId}`);
|
|
302
|
+
}
|
|
303
|
+
return live;
|
|
304
|
+
}
|
|
305
|
+
scheduleMaybeDispose(live) {
|
|
306
|
+
void this.maybeDispose(live).catch((error) => this.options.reportError(error));
|
|
307
|
+
}
|
|
308
|
+
async maybeDispose(live) {
|
|
309
|
+
if (this.options.isClosing() ||
|
|
310
|
+
!live.ready ||
|
|
311
|
+
live.disposing ||
|
|
312
|
+
live.connections.size > 0 ||
|
|
313
|
+
live.operationCount > 0 ||
|
|
314
|
+
(!live.terminal && live.runtime.getPhase() !== "idle")) {
|
|
315
|
+
return live.disposing;
|
|
316
|
+
}
|
|
317
|
+
live.unsubscribe();
|
|
318
|
+
live.disposing = (async () => {
|
|
319
|
+
try {
|
|
320
|
+
await live.runtime.dispose();
|
|
321
|
+
}
|
|
322
|
+
finally {
|
|
323
|
+
if (this.liveSessions.get(live.id) === live)
|
|
324
|
+
this.liveSessions.delete(live.id);
|
|
325
|
+
}
|
|
326
|
+
})();
|
|
327
|
+
await live.disposing;
|
|
328
|
+
if (!this.options.isClosing())
|
|
329
|
+
this.options.broadcastServerSnapshot();
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
//# sourceMappingURL=sessions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sessions.js","sourceRoot":"","sources":["../src/sessions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAwB5C,SAAS,UAAU,CAAC,QAAyB,EAAmB;IAC/D,OAAO;QACN,EAAE,EAAE,QAAQ,CAAC,EAAE;QACf,SAAS,EAAE,QAAQ,CAAC,SAAS;QAC7B,SAAS,EAAE,QAAQ,CAAC,SAAS;QAC7B,WAAW,EAAE,QAAQ,CAAC,IAAI;QAC1B,G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oB,CAAC,IAAiB,EAAQ;QACrD,KAAK,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;IAAA,CACxF;IAEO,KAAK,CAAC,YAAY,CAAC,IAAiB,EAAiB;QAC5D,IACC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE;YACxB,CAAC,IAAI,CAAC,KAAK;YACX,IAAI,CAAC,SAAS;YACd,IAAI,CAAC,WAAW,CAAC,IAAI,GAAG,CAAC;YACzB,IAAI,CAAC,cAAc,GAAG,CAAC;YACvB,CAAC,CAAC,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,MAAM,CAAC,EACrD,CAAC;YACF,OAAO,IAAI,CAAC,SAAS,CAAC;QACvB,CAAC;QACD,IAAI,CAAC,WAAW,EAAE,CAAC;QACnB,IAAI,CAAC,SAAS,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC;YAC7B,IAAI,CAAC;gBACJ,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;YAC9B,CAAC;oBAAS,CAAC;gBACV,IAAI,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,IAAI;oBAAE,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAChF,CAAC;QAAA,CACD,CAAC,EAAE,CAAC;QACL,MAAM,IAAI,CAAC,SAAS,CAAC;QACrB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE;YAAE,IAAI,CAAC,OAAO,CAAC,uBAAuB,EAAE,CAAC;IAAA,CACtE;CACD","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type { Command, EventEnvelope, SessionMetadata, SessionSnapshot } from \"@earendil-works/pi-protocol\";\nimport type { ByteConnection, ConnectionState } from \"./connection.ts\";\nimport { PiServerError } from \"./errors.ts\";\nimport type { CreateSessionOptions, PiServerService, PiSessionRuntime, PiSessionRuntimeEvent } from \"./types.ts\";\n\ninterface LiveSession {\n\tid: string;\n\truntime: PiSessionRuntime;\n\tconnections: Set<ConnectionState>;\n\tunsubscribe: () => void;\n\toperationCount: number;\n\tready: boolean;\n\tterminal: boolean;\n\tdisposing?: Promise<void>;\n}\n\ninterface LiveSessionManagerOptions {\n\tservice: PiServerService;\n\tisClosing: () => boolean;\n\tsendMessage: (connection: ConnectionState, message: EventEnvelope) => Promise<boolean>;\n\tcloseConnection: (connection: ByteConnection) => Promise<void>;\n\tdisconnect: (connection: ConnectionState) => Promise<void>;\n\tbroadcastServerSnapshot: () => void;\n\treportError: (error: unknown) => void;\n}\n\nfunction toMetadata(snapshot: SessionSnapshot): SessionMetadata {\n\treturn {\n\t\tid: snapshot.id,\n\t\tcreatedAt: snapshot.createdAt,\n\t\tupdatedAt: snapshot.updatedAt,\n\t\tsessionName: snapshot.name,\n\t\tcwd: snapshot.cwd,\n\t};\n}\n\nexport class LiveSessionManager {\n\tprivate readonly options: LiveSessionManagerOptions;\n\tprivate readonly liveSessions = new Map<string, LiveSession>();\n\tprivate readonly openingSessions = new Map<string, Promise<LiveSession>>();\n\n\tconstructor(options: LiveSessionManagerOptions) {\n\t\tthis.options = options;\n\t}\n\n\tasync executeCommand(connection: ConnectionState, command: Command) {\n\t\tswitch (command.command) {\n\t\t\tcase \"list\":\n\t\t\t\treturn { command: \"list\" as const, sessions: await this.listMetadata() };\n\t\t\tcase \"create\": {\n\t\t\t\tconst id = randomUUID();\n\t\t\t\tconst options: CreateSessionOptions = {\n\t\t\t\t\tid,\n\t\t\t\t\tcwd: command.cwd,\n\t\t\t\t\tname: command.name,\n\t\t\t\t\tmodel: command.model,\n\t\t\t\t\tthinkingLevel: command.thinkingLevel,\n\t\t\t\t};\n\t\t\t\tconst live = await this.acquire(id, () => this.options.service.createSession(options));\n\t\t\t\tawait this.attach(connection, live);\n\t\t\t\tconst session = this.forConnection(await this.broadcastSnapshot(live), connection);\n\t\t\t\tthis.options.broadcastServerSnapshot();\n\t\t\t\treturn { command: \"create\" as const, session };\n\t\t\t}\n\t\t\tcase \"attach\": {\n\t\t\t\tconst live = await this.acquire(command.sessionId, () =>\n\t\t\t\t\tthis.options.service.openSession(command.sessionId),\n\t\t\t\t);\n\t\t\t\tawait this.attach(connection, live);\n\t\t\t\tconst session = this.forConnection(await this.broadcastSnapshot(live), connection);\n\t\t\t\tthis.options.broadcastServerSnapshot();\n\t\t\t\treturn { command: \"attach\" as const, session };\n\t\t\t}\n\t\t\tcase \"detach\": {\n\t\t\t\tconst live = this.liveSessions.get(command.sessionId);\n\t\t\t\tif (connection.sessionIds.has(command.sessionId)) {\n\t\t\t\t\tconnection.sessionIds.delete(command.sessionId);\n\t\t\t\t\tconnection.extensionUiSessions.delete(command.sessionId);\n\t\t\t\t\tif (live) {\n\t\t\t\t\t\tlive.connections.delete(connection);\n\t\t\t\t\t\tif (live.connections.size > 0 && !live.terminal && !live.disposing) {\n\t\t\t\t\t\t\tawait this.broadcastSnapshot(live);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tawait this.maybeDispose(live);\n\t\t\t\t\t}\n\t\t\t\t\tthis.options.broadcastServerSnapshot();\n\t\t\t\t}\n\t\t\t\treturn { command: \"detach\" as const, sessionId: command.sessionId };\n\t\t\t}\n\t\t\tcase \"prompt\": {\n\t\t\t\tconst live = this.requireAttached(connection, command.sessionId);\n\t\t\t\tconst session = await this.runOperation(connection, live, () =>\n\t\t\t\t\tlive.runtime.prompt({ text: command.text }),\n\t\t\t\t);\n\t\t\t\treturn { command: \"prompt\" as const, session };\n\t\t\t}\n\t\t\tcase \"steer\": {\n\t\t\t\tconst live = this.requireAttached(connection, command.sessionId);\n\t\t\t\tconst session = await this.runOperation(connection, live, () => live.runtime.steer({ text: command.text }));\n\t\t\t\treturn { command: \"steer\" as const, session };\n\t\t\t}\n\t\t\tcase \"abort\": {\n\t\t\t\tconst live = this.requireAttached(connection, command.sessionId);\n\t\t\t\tconst session = await this.runOperation(connection, live, () => live.runtime.abort());\n\t\t\t\treturn { command: \"abort\" as const, session };\n\t\t\t}\n\t\t\tcase \"set_model\": {\n\t\t\t\tconst live = this.requireAttached(connection, command.sessionId);\n\t\t\t\tconst session = await this.runOperation(connection, live, () => live.runtime.setModel(command.model));\n\t\t\t\treturn { command: \"set_model\" as const, session };\n\t\t\t}\n\t\t\tcase \"set_thinking\": {\n\t\t\t\tconst live = this.requireAttached(connection, command.sessionId);\n\t\t\t\tconst session = await this.runOperation(connection, live, () =>\n\t\t\t\t\tlive.runtime.setThinking(command.thinkingLevel),\n\t\t\t\t);\n\t\t\t\treturn { command: \"set_thinking\" as const, session };\n\t\t\t}\n\t\t\tcase \"subscribe_extension_ui\": {\n\t\t\t\tthis.requireAttached(connection, command.sessionId);\n\t\t\t\tconnection.extensionUiSessions.add(command.sessionId);\n\t\t\t\treturn { command: \"subscribe_extension_ui\" as const, sessionId: command.sessionId };\n\t\t\t}\n\t\t\tcase \"extension_ui_answer\": {\n\t\t\t\tconst live = this.requireAttached(connection, command.sessionId);\n\t\t\t\tawait live.runtime.answerExtensionUi(command.requestId, command.answer);\n\t\t\t\treturn {\n\t\t\t\t\tcommand: \"extension_ui_answer\" as const,\n\t\t\t\t\tsessionId: command.sessionId,\n\t\t\t\t\trequestId: command.requestId,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t}\n\n\tasync disconnect(connection: ConnectionState): Promise<void> {\n\t\tconst sessions = [...connection.sessionIds]\n\t\t\t.map((id) => this.liveSessions.get(id))\n\t\t\t.filter((live): live is LiveSession => live !== undefined);\n\t\tconnection.sessionIds.clear();\n\t\tconnection.extensionUiSessions.clear();\n\t\tfor (const live of sessions) live.connections.delete(connection);\n\t\tconst results = await Promise.allSettled(sessions.map((live) => this.maybeDispose(live)));\n\t\tfor (const result of results) {\n\t\t\tif (result.status === \"rejected\") this.options.reportError(result.reason);\n\t\t}\n\t}\n\n\tasync listMetadata(): Promise<SessionMetadata[]> {\n\t\tconst stored = await this.options.service.listSessions();\n\t\tconst liveSnapshots = await Promise.all(\n\t\t\t[...this.liveSessions.values()]\n\t\t\t\t.filter((live) => !live.disposing)\n\t\t\t\t.map(async (live) => [live.id, await this.normalizedSnapshot(live)] as const),\n\t\t);\n\t\tconst liveById = new Map(liveSnapshots);\n\t\tconst metadata = stored.map((item) => {\n\t\t\tconst snapshot = liveById.get(item.id);\n\t\t\tif (!snapshot) return item;\n\t\t\tliveById.delete(item.id);\n\t\t\treturn { ...item, ...toMetadata(snapshot) };\n\t\t});\n\t\tfor (const snapshot of liveById.values()) metadata.push(toMetadata(snapshot));\n\t\treturn metadata;\n\t}\n\n\tasync close(): Promise<void> {\n\t\tconst openingResults = await Promise.allSettled([...this.openingSessions.values()]);\n\t\tfor (const result of openingResults) {\n\t\t\tif (result.status === \"rejected\") this.options.reportError(result.reason);\n\t\t}\n\t\tconst sessions = [...this.liveSessions.values()];\n\t\tthis.liveSessions.clear();\n\t\tawait Promise.all(\n\t\t\tsessions.map(async (live) => {\n\t\t\t\tif (live.disposing) {\n\t\t\t\t\tawait live.disposing;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tlive.unsubscribe();\n\t\t\t\tawait live.runtime.dispose();\n\t\t\t}),\n\t\t);\n\t}\n\n\tprivate async runOperation(\n\t\tconnection: ConnectionState,\n\t\tlive: LiveSession,\n\t\toperation: () => Promise<void>,\n\t): Promise<SessionSnapshot> {\n\t\tlive.operationCount += 1;\n\t\ttry {\n\t\t\tawait operation();\n\t\t\treturn this.forConnection(await this.broadcastSnapshot(live), connection);\n\t\t} finally {\n\t\t\tlive.operationCount -= 1;\n\t\t\tthis.scheduleMaybeDispose(live);\n\t\t}\n\t}\n\n\tprivate async acquire(id: string, acquireRuntime: () => Promise<PiSessionRuntime>): Promise<LiveSession> {\n\t\tfor (;;) {\n\t\t\tconst existing = this.liveSessions.get(id);\n\t\t\tif (existing) {\n\t\t\t\tif (existing.terminal) throw new PiServerError(\"session_locked\", `Session runtime is terminating: ${id}`);\n\t\t\t\tif (existing.disposing) {\n\t\t\t\t\tawait existing.disposing;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\treturn existing;\n\t\t\t}\n\t\t\tconst opening = this.openingSessions.get(id);\n\t\t\tif (opening) return opening;\n\t\t\tconst pending = this.create(id, acquireRuntime);\n\t\t\tthis.openingSessions.set(id, pending);\n\t\t\ttry {\n\t\t\t\treturn await pending;\n\t\t\t} finally {\n\t\t\t\tif (this.openingSessions.get(id) === pending) this.openingSessions.delete(id);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async create(id: string, acquireRuntime: () => Promise<PiSessionRuntime>): Promise<LiveSession> {\n\t\tconst runtime = await acquireRuntime();\n\t\tif (this.options.isClosing()) {\n\t\t\tawait runtime.dispose();\n\t\t\tthrow new Error(\"PiServer closed while acquiring a session runtime\");\n\t\t}\n\t\tlet live: LiveSession | undefined;\n\t\ttry {\n\t\t\tconst snapshot = await runtime.snapshot();\n\t\t\tif (snapshot.id !== id) {\n\t\t\t\tthrow new PiServerError(\n\t\t\t\t\t\"invalid_request\",\n\t\t\t\t\t`Service returned session ${snapshot.id} for server-assigned session ${id}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tlive = {\n\t\t\t\tid,\n\t\t\t\truntime,\n\t\t\t\tconnections: new Set(),\n\t\t\t\tunsubscribe: () => {},\n\t\t\t\toperationCount: 0,\n\t\t\t\tready: false,\n\t\t\t\tterminal: false,\n\t\t\t};\n\t\t\tlive.unsubscribe = runtime.subscribe((event) => this.handleRuntimeEvent(live!, event));\n\t\t\tthis.liveSessions.set(id, live);\n\t\t\tlive.ready = true;\n\t\t\treturn live;\n\t\t} catch (error) {\n\t\t\tif (live) live.unsubscribe();\n\t\t\ttry {\n\t\t\t\tawait runtime.dispose();\n\t\t\t} catch (disposeError) {\n\t\t\t\tthis.options.reportError(disposeError);\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tprivate handleRuntimeEvent(live: LiveSession, event: PiSessionRuntimeEvent): void {\n\t\tif (event.type === \"error\") {\n\t\t\tvoid this.terminate(live, event.error).catch((error: unknown) => this.options.reportError(error));\n\t\t\treturn;\n\t\t}\n\t\tif (event.type === \"progress\") {\n\t\t\tconst envelope: EventEnvelope = {\n\t\t\t\ttype: \"event\",\n\t\t\t\tevent: { type: \"session_progress\", sessionId: live.id, progress: event.progress },\n\t\t\t};\n\t\t\tfor (const connection of live.connections) void this.options.sendMessage(connection, envelope);\n\t\t} else if (event.type === \"extension_ui\") {\n\t\t\tconst envelope: EventEnvelope = {\n\t\t\t\ttype: \"event\",\n\t\t\t\tevent: { type: \"extension_ui\", sessionId: live.id, payload: event.payload },\n\t\t\t};\n\t\t\tfor (const connection of live.connections) {\n\t\t\t\tif (connection.extensionUiSessions.has(live.id)) {\n\t\t\t\t\tvoid this.options.sendMessage(connection, envelope);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tvoid this.broadcastSnapshot(live).catch((error: unknown) => this.options.reportError(error));\n\t\t}\n\t\tthis.scheduleMaybeDispose(live);\n\t}\n\n\tprivate async terminate(live: LiveSession, error: PiServerError): Promise<void> {\n\t\tif (live.terminal) return;\n\t\tlive.terminal = true;\n\t\tthis.options.reportError(error);\n\t\tlive.unsubscribe();\n\t\tconst connections = [...live.connections];\n\t\tawait Promise.all(connections.map((connection) => this.options.closeConnection(connection.connection)));\n\t\tawait Promise.all(connections.map((connection) => this.options.disconnect(connection)));\n\t\tawait this.maybeDispose(live);\n\t}\n\n\tprivate async normalizedSnapshot(live: LiveSession): Promise<SessionSnapshot> {\n\t\tconst snapshot = await live.runtime.snapshot();\n\t\tif (snapshot.id !== live.id) {\n\t\t\tthrow new PiServerError(\"invalid_request\", `Runtime session ID changed from ${live.id} to ${snapshot.id}`);\n\t\t}\n\t\treturn {\n\t\t\t...snapshot,\n\t\t\tphase: live.runtime.getPhase(),\n\t\t\tattached: live.connections.size > 0,\n\t\t\tlocked: true,\n\t\t};\n\t}\n\n\tprivate forConnection(snapshot: SessionSnapshot, connection: ConnectionState): SessionSnapshot {\n\t\treturn { ...snapshot, attached: connection.sessionIds.has(snapshot.id) };\n\t}\n\n\tprivate async broadcastSnapshot(live: LiveSession): Promise<SessionSnapshot> {\n\t\tconst snapshot = await this.normalizedSnapshot(live);\n\t\tconst envelope: EventEnvelope = { type: \"event\", event: { type: \"session_snapshot\", snapshot } };\n\t\tfor (const connection of live.connections) void this.options.sendMessage(connection, envelope);\n\t\treturn snapshot;\n\t}\n\n\tprivate async attach(connection: ConnectionState, live: LiveSession): Promise<void> {\n\t\tif (connection.disconnected || connection.stage !== \"ready\" || connection.connection.closed) {\n\t\t\tawait this.maybeDispose(live);\n\t\t\tthrow new PiServerError(\"invalid_request\", \"Connection closed while attaching to a session\");\n\t\t}\n\t\tconnection.sessionIds.add(live.id);\n\t\tlive.connections.add(connection);\n\t}\n\n\tprivate requireAttached(connection: ConnectionState, sessionId: string): LiveSession {\n\t\tif (!connection.sessionIds.has(sessionId)) {\n\t\t\tthrow new PiServerError(\"invalid_request\", `Connection is not attached to session ${sessionId}`);\n\t\t}\n\t\tconst live = this.liveSessions.get(sessionId);\n\t\tif (!live || live.terminal || live.disposing) {\n\t\t\tthrow new PiServerError(\"not_found\", `Session is not live: ${sessionId}`);\n\t\t}\n\t\treturn live;\n\t}\n\n\tprivate scheduleMaybeDispose(live: LiveSession): void {\n\t\tvoid this.maybeDispose(live).catch((error: unknown) => this.options.reportError(error));\n\t}\n\n\tprivate async maybeDispose(live: LiveSession): Promise<void> {\n\t\tif (\n\t\t\tthis.options.isClosing() ||\n\t\t\t!live.ready ||\n\t\t\tlive.disposing ||\n\t\t\tlive.connections.size > 0 ||\n\t\t\tlive.operationCount > 0 ||\n\t\t\t(!live.terminal && live.runtime.getPhase() !== \"idle\")\n\t\t) {\n\t\t\treturn live.disposing;\n\t\t}\n\t\tlive.unsubscribe();\n\t\tlive.disposing = (async () => {\n\t\t\ttry {\n\t\t\t\tawait live.runtime.dispose();\n\t\t\t} finally {\n\t\t\t\tif (this.liveSessions.get(live.id) === live) this.liveSessions.delete(live.id);\n\t\t\t}\n\t\t})();\n\t\tawait live.disposing;\n\t\tif (!this.options.isClosing()) this.options.broadcastServerSnapshot();\n\t}\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type EventEnvelope, type ModelMetadata, type ServerSnapshot, type SessionMetadata } from "@earendil-works/pi-protocol";
|
|
2
|
+
import type { ConnectionState } from "./connection.ts";
|
|
3
|
+
import type { PiServerService } from "./types.ts";
|
|
4
|
+
interface ServerSnapshotPublisherOptions {
|
|
5
|
+
serverId: string;
|
|
6
|
+
service: PiServerService;
|
|
7
|
+
connections: Set<ConnectionState>;
|
|
8
|
+
isClosing: () => boolean;
|
|
9
|
+
listSessions: () => Promise<SessionMetadata[]>;
|
|
10
|
+
sendMessage: (connection: ConnectionState, message: EventEnvelope) => Promise<boolean>;
|
|
11
|
+
reportError: (error: unknown) => void;
|
|
12
|
+
}
|
|
13
|
+
export declare class ServerSnapshotPublisher {
|
|
14
|
+
private readonly options;
|
|
15
|
+
private revision;
|
|
16
|
+
private broadcastQueue;
|
|
17
|
+
constructor(options: ServerSnapshotPublisherOptions);
|
|
18
|
+
get currentRevision(): number;
|
|
19
|
+
get(models?: ModelMetadata[]): Promise<ServerSnapshot>;
|
|
20
|
+
broadcast(): Promise<void>;
|
|
21
|
+
private performBroadcast;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=snapshots.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshots.d.ts","sourceRoot":"","sources":["../src/snapshots.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,aAAa,EAClB,KAAK,aAAa,EAElB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,UAAU,8BAA8B;IACvC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,eAAe,CAAC;IACzB,WAAW,EAAE,GAAG,CAAC,eAAe,CAAC,CAAC;IAClC,SAAS,EAAE,MAAM,OAAO,CAAC;IACzB,YAAY,EAAE,MAAM,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC;IAC/C,WAAW,EAAE,CAAC,UAAU,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACvF,WAAW,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CACtC;AAED,qBAAa,uBAAuB;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiC;IACzD,OAAO,CAAC,QAAQ,CAAK;IACrB,OAAO,CAAC,cAAc,CAAoC;IAE1D,YAAY,OAAO,EAAE,8BAA8B,EAElD;IAED,IAAI,eAAe,IAAI,MAAM,CAE5B;IAEK,GAAG,CAAC,MAAM,CAAC,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,cAAc,CAAC,CAQ3D;IAED,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAIzB;YAEa,gBAAgB;CAY9B","sourcesContent":["import {\n\ttype EventEnvelope,\n\ttype ModelMetadata,\n\tPROTOCOL_VERSION,\n\ttype ServerSnapshot,\n\ttype SessionMetadata,\n} from \"@earendil-works/pi-protocol\";\nimport type { ConnectionState } from \"./connection.ts\";\nimport type { PiServerService } from \"./types.ts\";\n\ninterface ServerSnapshotPublisherOptions {\n\tserverId: string;\n\tservice: PiServerService;\n\tconnections: Set<ConnectionState>;\n\tisClosing: () => boolean;\n\tlistSessions: () => Promise<SessionMetadata[]>;\n\tsendMessage: (connection: ConnectionState, message: EventEnvelope) => Promise<boolean>;\n\treportError: (error: unknown) => void;\n}\n\nexport class ServerSnapshotPublisher {\n\tprivate readonly options: ServerSnapshotPublisherOptions;\n\tprivate revision = 0;\n\tprivate broadcastQueue: Promise<void> = Promise.resolve();\n\n\tconstructor(options: ServerSnapshotPublisherOptions) {\n\t\tthis.options = options;\n\t}\n\n\tget currentRevision(): number {\n\t\treturn this.revision;\n\t}\n\n\tasync get(models?: ModelMetadata[]): Promise<ServerSnapshot> {\n\t\treturn {\n\t\t\tserverId: this.options.serverId,\n\t\t\tprotocolVersion: PROTOCOL_VERSION,\n\t\t\trevision: this.revision,\n\t\t\tsessions: await this.options.listSessions(),\n\t\t\tmodels: models ?? (await this.options.service.listModels()),\n\t\t};\n\t}\n\n\tbroadcast(): Promise<void> {\n\t\tconst broadcast = this.broadcastQueue.then(() => this.performBroadcast());\n\t\tthis.broadcastQueue = broadcast.catch((error: unknown) => this.options.reportError(error));\n\t\treturn broadcast;\n\t}\n\n\tprivate async performBroadcast(): Promise<void> {\n\t\tconst readyConnections = [...this.options.connections].filter(\n\t\t\t(connection) => connection.stage === \"ready\" && !connection.disconnected,\n\t\t);\n\t\tif (readyConnections.length === 0 || this.options.isClosing()) return;\n\t\tconst revision = ++this.revision;\n\t\tconst models = await this.options.service.listModels();\n\t\tconst current = await this.get(models);\n\t\tconst snapshot: ServerSnapshot = { ...current, revision };\n\t\tconst envelope: EventEnvelope = { type: \"event\", event: { type: \"server_snapshot\", snapshot } };\n\t\tfor (const connection of readyConnections) await this.options.sendMessage(connection, envelope);\n\t}\n}\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { PROTOCOL_VERSION, } from "@earendil-works/pi-protocol";
|
|
2
|
+
export class ServerSnapshotPublisher {
|
|
3
|
+
options;
|
|
4
|
+
revision = 0;
|
|
5
|
+
broadcastQueue = Promise.resolve();
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.options = options;
|
|
8
|
+
}
|
|
9
|
+
get currentRevision() {
|
|
10
|
+
return this.revision;
|
|
11
|
+
}
|
|
12
|
+
async get(models) {
|
|
13
|
+
return {
|
|
14
|
+
serverId: this.options.serverId,
|
|
15
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
16
|
+
revision: this.revision,
|
|
17
|
+
sessions: await this.options.listSessions(),
|
|
18
|
+
models: models ?? (await this.options.service.listModels()),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
broadcast() {
|
|
22
|
+
const broadcast = this.broadcastQueue.then(() => this.performBroadcast());
|
|
23
|
+
this.broadcastQueue = broadcast.catch((error) => this.options.reportError(error));
|
|
24
|
+
return broadcast;
|
|
25
|
+
}
|
|
26
|
+
async performBroadcast() {
|
|
27
|
+
const readyConnections = [...this.options.connections].filter((connection) => connection.stage === "ready" && !connection.disconnected);
|
|
28
|
+
if (readyConnections.length === 0 || this.options.isClosing())
|
|
29
|
+
return;
|
|
30
|
+
const revision = ++this.revision;
|
|
31
|
+
const models = await this.options.service.listModels();
|
|
32
|
+
const current = await this.get(models);
|
|
33
|
+
const snapshot = { ...current, revision };
|
|
34
|
+
const envelope = { type: "event", event: { type: "server_snapshot", snapshot } };
|
|
35
|
+
for (const connection of readyConnections)
|
|
36
|
+
await this.options.sendMessage(connection, envelope);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=snapshots.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshots.js","sourceRoot":"","sources":["../src/snapshots.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,gBAAgB,GAGhB,MAAM,6BAA6B,CAAC;AAcrC,MAAM,OAAO,uBAAuB;IAClB,OAAO,CAAiC;IACjD,QAAQ,GAAG,CAAC,CAAC;IACb,cAAc,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;IAE1D,YAAY,OAAuC,EAAE;QACpD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAAA,CACvB;IAED,IAAI,eAAe,GAAW;QAC7B,OAAO,IAAI,C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,CAAC,CAAC;QACvC,MAAM,QAAQ,GAAmB,EAAE,GAAG,OAAO,EAAE,QAAQ,EAAE,CAAC;QAC1D,MAAM,QAAQ,GAAkB,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,iBAAiB,EAAE,QAAQ,EAAE,EAAE,CAAC;QAChG,KAAK,MAAM,UAAU,IAAI,gBAAgB;YAAE,MAAM,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IAAA,CAChG;CACD","sourcesContent":["import {\n\ttype EventEnvelope,\n\ttype ModelMetadata,\n\tPROTOCOL_VERSION,\n\ttype ServerSnapshot,\n\ttype SessionMetadata,\n} from \"@earendil-works/pi-protocol\";\nimport type { ConnectionState } from \"./connection.ts\";\nimport type { PiServerService } from \"./types.ts\";\n\ninterface ServerSnapshotPublisherOptions {\n\tserverId: string;\n\tservice: PiServerService;\n\tconnections: Set<ConnectionState>;\n\tisClosing: () => boolean;\n\tlistSessions: () => Promise<SessionMetadata[]>;\n\tsendMessage: (connection: ConnectionState, message: EventEnvelope) => Promise<boolean>;\n\treportError: (error: unknown) => void;\n}\n\nexport class ServerSnapshotPublisher {\n\tprivate readonly options: ServerSnapshotPublisherOptions;\n\tprivate revision = 0;\n\tprivate broadcastQueue: Promise<void> = Promise.resolve();\n\n\tconstructor(options: ServerSnapshotPublisherOptions) {\n\t\tthis.options = options;\n\t}\n\n\tget currentRevision(): number {\n\t\treturn this.revision;\n\t}\n\n\tasync get(models?: ModelMetadata[]): Promise<ServerSnapshot> {\n\t\treturn {\n\t\t\tserverId: this.options.serverId,\n\t\t\tprotocolVersion: PROTOCOL_VERSION,\n\t\t\trevision: this.revision,\n\t\t\tsessions: await this.options.listSessions(),\n\t\t\tmodels: models ?? (await this.options.service.listModels()),\n\t\t};\n\t}\n\n\tbroadcast(): Promise<void> {\n\t\tconst broadcast = this.broadcastQueue.then(() => this.performBroadcast());\n\t\tthis.broadcastQueue = broadcast.catch((error: unknown) => this.options.reportError(error));\n\t\treturn broadcast;\n\t}\n\n\tprivate async performBroadcast(): Promise<void> {\n\t\tconst readyConnections = [...this.options.connections].filter(\n\t\t\t(connection) => connection.stage === \"ready\" && !connection.disconnected,\n\t\t);\n\t\tif (readyConnections.length === 0 || this.options.isClosing()) return;\n\t\tconst revision = ++this.revision;\n\t\tconst models = await this.options.service.listModels();\n\t\tconst current = await this.get(models);\n\t\tconst snapshot: ServerSnapshot = { ...current, revision };\n\t\tconst envelope: EventEnvelope = { type: \"event\", event: { type: \"server_snapshot\", snapshot } };\n\t\tfor (const connection of readyConnections) await this.options.sendMessage(connection, envelope);\n\t}\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { InstanceRecord, MachineRecord } from "./types.ts";
|
|
2
|
+
export declare function loadMachine(): MachineRecord | undefined;
|
|
3
|
+
export declare function saveMachine(machine: MachineRecord): void;
|
|
4
|
+
export declare function deleteMachine(): void;
|
|
5
|
+
export declare function loadInstances(): InstanceRecord[];
|
|
6
|
+
export declare function saveInstances(instances: InstanceRecord[]): void;
|
|
7
|
+
export declare function getInstance(instanceId: string): InstanceRecord | undefined;
|
|
8
|
+
export declare function upsertInstance(instance: InstanceRecord): void;
|
|
9
|
+
export declare function removeInstance(instanceId: string): void;
|
|
10
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAShE,wBAAgB,WAAW,IAAI,aAAa,GAAG,SAAS,CAQvD;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,CAGxD;AAED,wBAAgB,aAAa,IAAI,IAAI,CAMpC;AAED,wBAAgB,aAAa,IAAI,cAAc,EAAE,CAQhD;AAED,wBAAgB,aAAa,CAAC,SAAS,EAAE,cAAc,EAAE,GAAG,IAAI,CAG/D;AAED,wBAAgB,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAE1E;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI,CAW7D;AAED,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAGvD","sourcesContent":["import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from \"node:fs\";\nimport { getInstancesPath, getMachinePath, getServerDir } from \"./config.ts\";\nimport type { InstanceRecord, MachineRecord } from \"./types.ts\";\n\nfunction ensureServerDir(): void {\n\tconst serverDir = getServerDir();\n\tif (!existsSync(serverDir)) {\n\t\tmkdirSync(serverDir, { recursive: true });\n\t}\n}\n\nexport function loadMachine(): MachineRecord | undefined {\n\tconst machinePath = getMachinePath();\n\tif (!existsSync(machinePath)) {\n\t\treturn undefined;\n\t}\n\n\tconst data = readFileSync(machinePath, \"utf-8\");\n\treturn JSON.parse(data) as MachineRecord;\n}\n\nexport function saveMachine(machine: MachineRecord): void {\n\tensureServerDir();\n\twriteFileSync(getMachinePath(), JSON.stringify(machine, null, 2));\n}\n\nexport function deleteMachine(): void {\n\tconst machinePath = getMachinePath();\n\tif (!existsSync(machinePath)) {\n\t\treturn;\n\t}\n\trmSync(machinePath);\n}\n\nexport function loadInstances(): InstanceRecord[] {\n\tconst instancesPath = getInstancesPath();\n\tif (!existsSync(instancesPath)) {\n\t\treturn [];\n\t}\n\n\tconst data = readFileSync(instancesPath, \"utf-8\");\n\treturn JSON.parse(data) as InstanceRecord[];\n}\n\nexport function saveInstances(instances: InstanceRecord[]): void {\n\tensureServerDir();\n\twriteFileSync(getInstancesPath(), JSON.stringify(instances, null, 2));\n}\n\nexport function getInstance(instanceId: string): InstanceRecord | undefined {\n\treturn loadInstances().find((instance) => instance.id === instanceId);\n}\n\nexport function upsertInstance(instance: InstanceRecord): void {\n\tconst instances = loadInstances();\n\tconst index = instances.findIndex((existing) => existing.id === instance.id);\n\tif (index === -1) {\n\t\tinstances.push(instance);\n\t\tsaveInstances(instances);\n\t\treturn;\n\t}\n\n\tinstances[index] = instance;\n\tsaveInstances(instances);\n}\n\nexport function removeInstance(instanceId: string): void {\n\tconst instances = loadInstances().filter((instance) => instance.id !== instanceId);\n\tsaveInstances(instances);\n}\n"]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { getInstancesPath, getMachinePath, getServerDir } from "./config.js";
|
|
3
|
+
function ensureServerDir() {
|
|
4
|
+
const serverDir = getServerDir();
|
|
5
|
+
if (!existsSync(serverDir)) {
|
|
6
|
+
mkdirSync(serverDir, { recursive: true });
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export function loadMachine() {
|
|
10
|
+
const machinePath = getMachinePath();
|
|
11
|
+
if (!existsSync(machinePath)) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
const data = readFileSync(machinePath, "utf-8");
|
|
15
|
+
return JSON.parse(data);
|
|
16
|
+
}
|
|
17
|
+
export function saveMachine(machine) {
|
|
18
|
+
ensureServerDir();
|
|
19
|
+
writeFileSync(getMachinePath(), JSON.stringify(machine, null, 2));
|
|
20
|
+
}
|
|
21
|
+
export function deleteMachine() {
|
|
22
|
+
const machinePath = getMachinePath();
|
|
23
|
+
if (!existsSync(machinePath)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
rmSync(machinePath);
|
|
27
|
+
}
|
|
28
|
+
export function loadInstances() {
|
|
29
|
+
const instancesPath = getInstancesPath();
|
|
30
|
+
if (!existsSync(instancesPath)) {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
const data = readFileSync(instancesPath, "utf-8");
|
|
34
|
+
return JSON.parse(data);
|
|
35
|
+
}
|
|
36
|
+
export function saveInstances(instances) {
|
|
37
|
+
ensureServerDir();
|
|
38
|
+
writeFileSync(getInstancesPath(), JSON.stringify(instances, null, 2));
|
|
39
|
+
}
|
|
40
|
+
export function getInstance(instanceId) {
|
|
41
|
+
return loadInstances().find((instance) => instance.id === instanceId);
|
|
42
|
+
}
|
|
43
|
+
export function upsertInstance(instance) {
|
|
44
|
+
const instances = loadInstances();
|
|
45
|
+
const index = instances.findIndex((existing) => existing.id === instance.id);
|
|
46
|
+
if (index === -1) {
|
|
47
|
+
instances.push(instance);
|
|
48
|
+
saveInstances(instances);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
instances[index] = instance;
|
|
52
|
+
saveInstances(instances);
|
|
53
|
+
}
|
|
54
|
+
export function removeInstance(instanceId) {
|
|
55
|
+
const instances = loadInstances().filter((instance) => instance.id !== instanceId);
|
|
56
|
+
saveInstances(instances);
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACrF,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG7E,SAAS,eAAe,GAAS;IAChC,MAAM,SAAS,GAAG,YAAY,EAAE,CAAC;IACjC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QAC5B,SAAS,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3C,CAAC;AAAA,CACD;AAED,MAAM,UAAU,WAAW,GAA8B;IACxD,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IACrC,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;QAC9B,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,MAAM,IAAI,GA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EAAE,CAAC;IAClC,MAAM,KAAK,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,KAAK,QAAQ,CAAC,EAAE,CAAC,CAAC;IAC7E,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;QAClB,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACzB,aAAa,CAAC,SAAS,CAAC,CAAC;QACzB,OAAO;IACR,CAAC;IAED,SAAS,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC;IAC5B,aAAa,CAAC,SAAS,CAAC,CAAC;AAAA,CACzB;AAED,MAAM,UAAU,cAAc,CAAC,UAAkB,EAAQ;IACxD,MAAM,SAAS,GAAG,aAAa,EAAE,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,KAAK,UAAU,CAAC,CAAC;IACnF,aAAa,CAAC,SAAS,CAAC,CAAC;AAAA,CACzB","sourcesContent":["import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from \"node:fs\";\nimport { getInstancesPath, getMachinePath, getServerDir } from \"./config.ts\";\nimport type { InstanceRecord, MachineRecord } from \"./types.ts\";\n\nfunction ensureServerDir(): void {\n\tconst serverDir = getServerDir();\n\tif (!existsSync(serverDir)) {\n\t\tmkdirSync(serverDir, { recursive: true });\n\t}\n}\n\nexport function loadMachine(): MachineRecord | undefined {\n\tconst machinePath = getMachinePath();\n\tif (!existsSync(machinePath)) {\n\t\treturn undefined;\n\t}\n\n\tconst data = readFileSync(machinePath, \"utf-8\");\n\treturn JSON.parse(data) as MachineRecord;\n}\n\nexport function saveMachine(machine: MachineRecord): void {\n\tensureServerDir();\n\twriteFileSync(getMachinePath(), JSON.stringify(machine, null, 2));\n}\n\nexport function deleteMachine(): void {\n\tconst machinePath = getMachinePath();\n\tif (!existsSync(machinePath)) {\n\t\treturn;\n\t}\n\trmSync(machinePath);\n}\n\nexport function loadInstances(): InstanceRecord[] {\n\tconst instancesPath = getInstancesPath();\n\tif (!existsSync(instancesPath)) {\n\t\treturn [];\n\t}\n\n\tconst data = readFileSync(instancesPath, \"utf-8\");\n\treturn JSON.parse(data) as InstanceRecord[];\n}\n\nexport function saveInstances(instances: InstanceRecord[]): void {\n\tensureServerDir();\n\twriteFileSync(getInstancesPath(), JSON.stringify(instances, null, 2));\n}\n\nexport function getInstance(instanceId: string): InstanceRecord | undefined {\n\treturn loadInstances().find((instance) => instance.id === instanceId);\n}\n\nexport function upsertInstance(instance: InstanceRecord): void {\n\tconst instances = loadInstances();\n\tconst index = instances.findIndex((existing) => existing.id === instance.id);\n\tif (index === -1) {\n\t\tinstances.push(instance);\n\t\tsaveInstances(instances);\n\t\treturn;\n\t}\n\n\tinstances[index] = instance;\n\tsaveInstances(instances);\n}\n\nexport function removeInstance(instanceId: string): void {\n\tconst instances = loadInstances().filter((instance) => instance.id !== instanceId);\n\tsaveInstances(instances);\n}\n"]}
|