dal-code 1.0.9 → 1.0.10
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 +6 -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/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,254 @@
|
|
|
1
|
+
import { PiServerError } from "../errors.js";
|
|
2
|
+
export const TEST_MODEL = {
|
|
3
|
+
provider: "test",
|
|
4
|
+
id: "small",
|
|
5
|
+
name: "Test Small",
|
|
6
|
+
api: "test-api",
|
|
7
|
+
reasoning: true,
|
|
8
|
+
input: ["text", "image"],
|
|
9
|
+
contextWindow: 16_000,
|
|
10
|
+
maxTokens: 2_000,
|
|
11
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
12
|
+
supportedThinkingLevels: ["off", "medium", "high"],
|
|
13
|
+
authenticated: true,
|
|
14
|
+
};
|
|
15
|
+
export class Deferred {
|
|
16
|
+
promise;
|
|
17
|
+
resolvePromise;
|
|
18
|
+
constructor() {
|
|
19
|
+
this.promise = new Promise((resolve) => {
|
|
20
|
+
this.resolvePromise = resolve;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
resolve(value) {
|
|
24
|
+
this.resolvePromise(value);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export class TestSessionRuntime {
|
|
28
|
+
disposed = new Deferred();
|
|
29
|
+
disposeCount = 0;
|
|
30
|
+
steers = [];
|
|
31
|
+
extensionUiAnswers = [];
|
|
32
|
+
stored;
|
|
33
|
+
onDispose;
|
|
34
|
+
listeners = new Set();
|
|
35
|
+
pendingPrompt;
|
|
36
|
+
pendingExtensionUi = new Map();
|
|
37
|
+
constructor(stored, onDispose) {
|
|
38
|
+
this.stored = stored;
|
|
39
|
+
this.onDispose = onDispose;
|
|
40
|
+
}
|
|
41
|
+
snapshot() {
|
|
42
|
+
return structuredClone(this.stored.snapshot);
|
|
43
|
+
}
|
|
44
|
+
getPhase() {
|
|
45
|
+
return this.stored.snapshot.phase;
|
|
46
|
+
}
|
|
47
|
+
async prompt(input) {
|
|
48
|
+
if (this.getPhase() !== "idle")
|
|
49
|
+
throw new PiServerError("busy", "A prompt is already running");
|
|
50
|
+
const done = new Deferred();
|
|
51
|
+
this.pendingPrompt = { input, done };
|
|
52
|
+
this.update({
|
|
53
|
+
phase: "turn",
|
|
54
|
+
transcript: [
|
|
55
|
+
...this.stored.snapshot.transcript,
|
|
56
|
+
{
|
|
57
|
+
id: `user-${this.stored.snapshot.revision + 1}`,
|
|
58
|
+
role: "user",
|
|
59
|
+
content: [{ type: "text", text: input.text }],
|
|
60
|
+
timestamp: this.stored.snapshot.revision + 1,
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
});
|
|
64
|
+
const outcome = await done.promise;
|
|
65
|
+
const assistant = outcome === "complete"
|
|
66
|
+
? {
|
|
67
|
+
id: `assistant-${this.stored.snapshot.revision + 1}`,
|
|
68
|
+
role: "assistant",
|
|
69
|
+
content: [{ type: "text", text: `reply:${input.text}` }],
|
|
70
|
+
status: "complete",
|
|
71
|
+
model: this.stored.snapshot.model,
|
|
72
|
+
stopReason: "stop",
|
|
73
|
+
timestamp: this.stored.snapshot.revision + 1,
|
|
74
|
+
}
|
|
75
|
+
: {
|
|
76
|
+
id: `assistant-${this.stored.snapshot.revision + 1}`,
|
|
77
|
+
role: "assistant",
|
|
78
|
+
content: [{ type: "text", text: "" }],
|
|
79
|
+
status: "aborted",
|
|
80
|
+
model: this.stored.snapshot.model,
|
|
81
|
+
stopReason: "aborted",
|
|
82
|
+
timestamp: this.stored.snapshot.revision + 1,
|
|
83
|
+
};
|
|
84
|
+
this.update({
|
|
85
|
+
phase: "idle",
|
|
86
|
+
transcript: [...this.stored.snapshot.transcript, assistant],
|
|
87
|
+
});
|
|
88
|
+
this.pendingPrompt = undefined;
|
|
89
|
+
}
|
|
90
|
+
async steer(input) {
|
|
91
|
+
if (this.getPhase() === "idle")
|
|
92
|
+
throw new PiServerError("busy", "There is no active prompt to steer");
|
|
93
|
+
this.steers.push(input);
|
|
94
|
+
this.update({
|
|
95
|
+
queuedSteerCount: this.stored.snapshot.queuedSteerCount + 1,
|
|
96
|
+
queuedSteer: [
|
|
97
|
+
...this.stored.snapshot.queuedSteer,
|
|
98
|
+
{
|
|
99
|
+
id: `steer-${this.stored.snapshot.revision + 1}`,
|
|
100
|
+
role: "user",
|
|
101
|
+
content: [{ type: "text", text: input.text }],
|
|
102
|
+
timestamp: this.stored.snapshot.revision + 1,
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
async abort() {
|
|
108
|
+
if (!this.pendingPrompt)
|
|
109
|
+
throw new PiServerError("busy", "There is no active prompt to abort");
|
|
110
|
+
this.pendingPrompt.done.resolve("aborted");
|
|
111
|
+
}
|
|
112
|
+
async setModel(model) {
|
|
113
|
+
if (this.getPhase() !== "idle")
|
|
114
|
+
throw new PiServerError("busy", "Session is busy");
|
|
115
|
+
this.update({ model });
|
|
116
|
+
}
|
|
117
|
+
async setThinking(thinkingLevel) {
|
|
118
|
+
if (this.getPhase() !== "idle")
|
|
119
|
+
throw new PiServerError("busy", "Session is busy");
|
|
120
|
+
this.update({ thinkingLevel });
|
|
121
|
+
}
|
|
122
|
+
async answerExtensionUi(requestId, answer) {
|
|
123
|
+
this.extensionUiAnswers.push({ requestId, answer });
|
|
124
|
+
const pending = this.pendingExtensionUi.get(requestId);
|
|
125
|
+
if (pending) {
|
|
126
|
+
this.pendingExtensionUi.delete(requestId);
|
|
127
|
+
pending.resolve(undefined);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
emitExtensionUi(payload) {
|
|
131
|
+
for (const listener of this.listeners)
|
|
132
|
+
listener({ type: "extension_ui", payload });
|
|
133
|
+
}
|
|
134
|
+
subscribe(listener) {
|
|
135
|
+
this.listeners.add(listener);
|
|
136
|
+
return () => this.listeners.delete(listener);
|
|
137
|
+
}
|
|
138
|
+
async dispose() {
|
|
139
|
+
this.disposeCount += 1;
|
|
140
|
+
this.onDispose();
|
|
141
|
+
this.disposed.resolve(undefined);
|
|
142
|
+
}
|
|
143
|
+
setPhase(phase) {
|
|
144
|
+
this.stored.snapshot = { ...this.stored.snapshot, phase };
|
|
145
|
+
}
|
|
146
|
+
finishPrompt() {
|
|
147
|
+
if (!this.pendingPrompt)
|
|
148
|
+
throw new Error("No prompt is pending");
|
|
149
|
+
this.pendingPrompt.done.resolve("complete");
|
|
150
|
+
}
|
|
151
|
+
emitProgress(progress) {
|
|
152
|
+
for (const listener of this.listeners)
|
|
153
|
+
listener({ type: "progress", progress });
|
|
154
|
+
}
|
|
155
|
+
emitError(error) {
|
|
156
|
+
for (const listener of this.listeners)
|
|
157
|
+
listener({ type: "error", error });
|
|
158
|
+
}
|
|
159
|
+
emitSnapshot() {
|
|
160
|
+
for (const listener of this.listeners)
|
|
161
|
+
listener({ type: "snapshot" });
|
|
162
|
+
}
|
|
163
|
+
update(updates) {
|
|
164
|
+
this.stored.snapshot = {
|
|
165
|
+
...this.stored.snapshot,
|
|
166
|
+
...updates,
|
|
167
|
+
revision: this.stored.snapshot.revision + 1,
|
|
168
|
+
updatedAt: this.stored.snapshot.updatedAt + 1,
|
|
169
|
+
};
|
|
170
|
+
this.emitSnapshot();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
export class TestServerService {
|
|
174
|
+
sessions = new Map();
|
|
175
|
+
runtimes = new Map();
|
|
176
|
+
locked = new Set();
|
|
177
|
+
lastCreatedId;
|
|
178
|
+
nextListDelay;
|
|
179
|
+
async listSessions() {
|
|
180
|
+
const delay = this.nextListDelay;
|
|
181
|
+
if (delay) {
|
|
182
|
+
this.nextListDelay = undefined;
|
|
183
|
+
delay.entered.resolve(undefined);
|
|
184
|
+
await delay.release.promise;
|
|
185
|
+
}
|
|
186
|
+
return [...this.sessions.values()].map(({ snapshot }) => ({
|
|
187
|
+
id: snapshot.id,
|
|
188
|
+
createdAt: snapshot.createdAt,
|
|
189
|
+
updatedAt: snapshot.updatedAt,
|
|
190
|
+
sessionName: snapshot.name,
|
|
191
|
+
cwd: snapshot.cwd,
|
|
192
|
+
}));
|
|
193
|
+
}
|
|
194
|
+
async listModels() {
|
|
195
|
+
return [TEST_MODEL];
|
|
196
|
+
}
|
|
197
|
+
async createSession(options) {
|
|
198
|
+
this.lastCreatedId = options.id;
|
|
199
|
+
if (this.sessions.has(options.id))
|
|
200
|
+
throw new PiServerError("session_locked", "Session already exists");
|
|
201
|
+
this.seed(options.id, options.name, options.cwd, options.model, options.thinkingLevel);
|
|
202
|
+
return this.acquire(options.id);
|
|
203
|
+
}
|
|
204
|
+
async openSession(sessionId) {
|
|
205
|
+
if (!this.sessions.has(sessionId))
|
|
206
|
+
throw new PiServerError("not_found", `Unknown session: ${sessionId}`);
|
|
207
|
+
if (this.locked.has(sessionId))
|
|
208
|
+
throw new PiServerError("session_locked", `Session is locked: ${sessionId}`);
|
|
209
|
+
return this.acquire(sessionId);
|
|
210
|
+
}
|
|
211
|
+
seed(id = "session-1", name = `Session ${id}`, cwd = "/tmp/pi-server-conformance", model = { provider: TEST_MODEL.provider, id: TEST_MODEL.id }, thinkingLevel = "off") {
|
|
212
|
+
this.sessions.set(id, {
|
|
213
|
+
snapshot: {
|
|
214
|
+
id,
|
|
215
|
+
name,
|
|
216
|
+
cwd,
|
|
217
|
+
createdAt: 1,
|
|
218
|
+
updatedAt: 1,
|
|
219
|
+
phase: "idle",
|
|
220
|
+
model,
|
|
221
|
+
thinkingLevel,
|
|
222
|
+
attached: false,
|
|
223
|
+
locked: false,
|
|
224
|
+
revision: 0,
|
|
225
|
+
transcript: [],
|
|
226
|
+
queuedSteer: [],
|
|
227
|
+
queuedSteerCount: 0,
|
|
228
|
+
},
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
delayNextList() {
|
|
232
|
+
const delay = { entered: new Deferred(), release: new Deferred() };
|
|
233
|
+
this.nextListDelay = delay;
|
|
234
|
+
return delay;
|
|
235
|
+
}
|
|
236
|
+
latestRuntime(id) {
|
|
237
|
+
const runtimes = this.runtimes.get(id);
|
|
238
|
+
if (!runtimes?.length)
|
|
239
|
+
throw new Error(`No runtime for ${id}`);
|
|
240
|
+
return runtimes.at(-1);
|
|
241
|
+
}
|
|
242
|
+
acquire(id) {
|
|
243
|
+
const stored = this.sessions.get(id);
|
|
244
|
+
if (!stored)
|
|
245
|
+
throw new Error(`Unknown session: ${id}`);
|
|
246
|
+
this.locked.add(id);
|
|
247
|
+
const runtime = new TestSessionRuntime(stored, () => this.locked.delete(id));
|
|
248
|
+
const runtimes = this.runtimes.get(id) ?? [];
|
|
249
|
+
runtimes.push(runtime);
|
|
250
|
+
this.runtimes.set(id, runtimes);
|
|
251
|
+
return runtime;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
//# sourceMappingURL=service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../src/testing/service.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAS7C,MAAM,CAAC,MAAM,UAAU,GAAkB;IACxC,QAAQ,EAAE,MAAM;IAChB,EAAE,EAAE,OAAO;IACX,IAAI,EAAE,YAAY;IAClB,GAAG,EAAE,UAAU;IACf,SAAS,EAAE,IAAI;IACf,KAAK,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC;IACxB,aAAa,EAAE,MAAM;IACrB,SAAS,EAAE,KAAK;IAChB,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE;IAC1D,uBAAuB,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC;IAClD,aAAa,EAAE,IAAI;CACnB,CAAC;AAEF,MAAM,OAAO,QAAQ;IACX,OAAO,CAAa;IACrB,cAAc,CAAsB;IAE5C,cAAc;QACb,IAAI,CAAC,OAAO,GAAG,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,EAAE,CAAC;YAC1C,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC;QAAA,CAC9B,CAAC,CAAC;IAAA,CACH;IAED,OAAO,CAAC,KAAQ,EAAQ;QACvB,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAAA,CAC3B;CACD;AAMD,MAAM,OAAO,kBAAkB;IACrB,QAAQ,GAAG,IAAI,QAAQ,EAAQ,CAAC;IACzC,YAAY,GAAG,CAAC,CAAC;IACR,MAAM,GAAkB,EAAE,CAAC;IAC3B,kBAAkB,GAA4D,EAAE,CAAC;IACzE,MAAM,CAAgB;IACtB,SAAS,CAAa;IACtB,S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AkB,EAAE,EAAE,CAAC,CAAC;QAC/D,OAAO,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAE,CAAC;IAAA,CACxB;IAEO,OAAO,CAAC,EAAU,EAAsB;QAC/C,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACrC,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,oBAAoB,EAAE,EAAE,CAAC,CAAC;QACvD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACpB,MAAM,OAAO,GAAG,IAAI,kBAAkB,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;QAC7E,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC;QAC7C,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;QAChC,OAAO,OAAO,CAAC;IAAA,CACf;CACD","sourcesContent":["import type {\n\tExtensionUiAnswer,\n\tExtensionUiPayload,\n\tModelMetadata,\n\tModelRef,\n\tSessionMetadata,\n\tSessionPhase,\n\tSessionSnapshot,\n\tThinkingLevel,\n\tTranscriptProgress,\n} from \"@earendil-works/pi-protocol\";\nimport { PiServerError } from \"../errors.ts\";\nimport type {\n\tCreateSessionOptions,\n\tPiServerService,\n\tPiSessionRuntime,\n\tPiSessionRuntimeEvent,\n\tPromptInput,\n} from \"../types.ts\";\n\nexport const TEST_MODEL: ModelMetadata = {\n\tprovider: \"test\",\n\tid: \"small\",\n\tname: \"Test Small\",\n\tapi: \"test-api\",\n\treasoning: true,\n\tinput: [\"text\", \"image\"],\n\tcontextWindow: 16_000,\n\tmaxTokens: 2_000,\n\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },\n\tsupportedThinkingLevels: [\"off\", \"medium\", \"high\"],\n\tauthenticated: true,\n};\n\nexport class Deferred<T> {\n\treadonly promise: Promise<T>;\n\tprivate resolvePromise!: (value: T) => void;\n\n\tconstructor() {\n\t\tthis.promise = new Promise<T>((resolve) => {\n\t\t\tthis.resolvePromise = resolve;\n\t\t});\n\t}\n\n\tresolve(value: T): void {\n\t\tthis.resolvePromise(value);\n\t}\n}\n\ninterface StoredSession {\n\tsnapshot: SessionSnapshot;\n}\n\nexport class TestSessionRuntime implements PiSessionRuntime {\n\treadonly disposed = new Deferred<void>();\n\tdisposeCount = 0;\n\treadonly steers: PromptInput[] = [];\n\treadonly extensionUiAnswers: Array<{ requestId: string; answer: ExtensionUiAnswer }> = [];\n\tprivate readonly stored: StoredSession;\n\tprivate readonly onDispose: () => void;\n\tprivate readonly listeners = new Set<(event: PiSessionRuntimeEvent) => void>();\n\tprivate pendingPrompt?: { input: PromptInput; done: Deferred<\"complete\" | \"aborted\"> };\n\tprivate readonly pendingExtensionUi = new Map<string, Deferred<void>>();\n\n\tconstructor(stored: StoredSession, onDispose: () => void) {\n\t\tthis.stored = stored;\n\t\tthis.onDispose = onDispose;\n\t}\n\n\tsnapshot(): SessionSnapshot {\n\t\treturn structuredClone(this.stored.snapshot);\n\t}\n\n\tgetPhase(): SessionPhase {\n\t\treturn this.stored.snapshot.phase;\n\t}\n\n\tasync prompt(input: PromptInput): Promise<void> {\n\t\tif (this.getPhase() !== \"idle\") throw new PiServerError(\"busy\", \"A prompt is already running\");\n\t\tconst done = new Deferred<\"complete\" | \"aborted\">();\n\t\tthis.pendingPrompt = { input, done };\n\t\tthis.update({\n\t\t\tphase: \"turn\",\n\t\t\ttranscript: [\n\t\t\t\t...this.stored.snapshot.transcript,\n\t\t\t\t{\n\t\t\t\t\tid: `user-${this.stored.snapshot.revision + 1}`,\n\t\t\t\t\trole: \"user\",\n\t\t\t\t\tcontent: [{ type: \"text\", text: input.text }],\n\t\t\t\t\ttimestamp: this.stored.snapshot.revision + 1,\n\t\t\t\t},\n\t\t\t],\n\t\t});\n\t\tconst outcome = await done.promise;\n\t\tconst assistant =\n\t\t\toutcome === \"complete\"\n\t\t\t\t? {\n\t\t\t\t\t\tid: `assistant-${this.stored.snapshot.revision + 1}`,\n\t\t\t\t\t\trole: \"assistant\" as const,\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: `reply:${input.text}` }],\n\t\t\t\t\t\tstatus: \"complete\" as const,\n\t\t\t\t\t\tmodel: this.stored.snapshot.model,\n\t\t\t\t\t\tstopReason: \"stop\" as const,\n\t\t\t\t\t\ttimestamp: this.stored.snapshot.revision + 1,\n\t\t\t\t\t}\n\t\t\t\t: {\n\t\t\t\t\t\tid: `assistant-${this.stored.snapshot.revision + 1}`,\n\t\t\t\t\t\trole: \"assistant\" as const,\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: \"\" }],\n\t\t\t\t\t\tstatus: \"aborted\" as const,\n\t\t\t\t\t\tmodel: this.stored.snapshot.model,\n\t\t\t\t\t\tstopReason: \"aborted\" as const,\n\t\t\t\t\t\ttimestamp: this.stored.snapshot.revision + 1,\n\t\t\t\t\t};\n\t\tthis.update({\n\t\t\tphase: \"idle\",\n\t\t\ttranscript: [...this.stored.snapshot.transcript, assistant],\n\t\t});\n\t\tthis.pendingPrompt = undefined;\n\t}\n\n\tasync steer(input: PromptInput): Promise<void> {\n\t\tif (this.getPhase() === \"idle\") throw new PiServerError(\"busy\", \"There is no active prompt to steer\");\n\t\tthis.steers.push(input);\n\t\tthis.update({\n\t\t\tqueuedSteerCount: this.stored.snapshot.queuedSteerCount + 1,\n\t\t\tqueuedSteer: [\n\t\t\t\t...this.stored.snapshot.queuedSteer,\n\t\t\t\t{\n\t\t\t\t\tid: `steer-${this.stored.snapshot.revision + 1}`,\n\t\t\t\t\trole: \"user\",\n\t\t\t\t\tcontent: [{ type: \"text\", text: input.text }],\n\t\t\t\t\ttimestamp: this.stored.snapshot.revision + 1,\n\t\t\t\t},\n\t\t\t],\n\t\t});\n\t}\n\n\tasync abort(): Promise<void> {\n\t\tif (!this.pendingPrompt) throw new PiServerError(\"busy\", \"There is no active prompt to abort\");\n\t\tthis.pendingPrompt.done.resolve(\"aborted\");\n\t}\n\n\tasync setModel(model: ModelRef): Promise<void> {\n\t\tif (this.getPhase() !== \"idle\") throw new PiServerError(\"busy\", \"Session is busy\");\n\t\tthis.update({ model });\n\t}\n\n\tasync setThinking(thinkingLevel: ThinkingLevel): Promise<void> {\n\t\tif (this.getPhase() !== \"idle\") throw new PiServerError(\"busy\", \"Session is busy\");\n\t\tthis.update({ thinkingLevel });\n\t}\n\n\tasync answerExtensionUi(requestId: string, answer: ExtensionUiAnswer): Promise<void> {\n\t\tthis.extensionUiAnswers.push({ requestId, answer });\n\t\tconst pending = this.pendingExtensionUi.get(requestId);\n\t\tif (pending) {\n\t\t\tthis.pendingExtensionUi.delete(requestId);\n\t\t\tpending.resolve(undefined);\n\t\t}\n\t}\n\n\temitExtensionUi(payload: ExtensionUiPayload): void {\n\t\tfor (const listener of this.listeners) listener({ type: \"extension_ui\", payload });\n\t}\n\n\tsubscribe(listener: (event: PiSessionRuntimeEvent) => void): () => void {\n\t\tthis.listeners.add(listener);\n\t\treturn () => this.listeners.delete(listener);\n\t}\n\n\tasync dispose(): Promise<void> {\n\t\tthis.disposeCount += 1;\n\t\tthis.onDispose();\n\t\tthis.disposed.resolve(undefined);\n\t}\n\n\tsetPhase(phase: SessionPhase): void {\n\t\tthis.stored.snapshot = { ...this.stored.snapshot, phase };\n\t}\n\n\tfinishPrompt(): void {\n\t\tif (!this.pendingPrompt) throw new Error(\"No prompt is pending\");\n\t\tthis.pendingPrompt.done.resolve(\"complete\");\n\t}\n\n\temitProgress(progress: TranscriptProgress): void {\n\t\tfor (const listener of this.listeners) listener({ type: \"progress\", progress });\n\t}\n\n\temitError(error: PiServerError): void {\n\t\tfor (const listener of this.listeners) listener({ type: \"error\", error });\n\t}\n\n\temitSnapshot(): void {\n\t\tfor (const listener of this.listeners) listener({ type: \"snapshot\" });\n\t}\n\n\tprivate update(updates: Partial<SessionSnapshot>): void {\n\t\tthis.stored.snapshot = {\n\t\t\t...this.stored.snapshot,\n\t\t\t...updates,\n\t\t\trevision: this.stored.snapshot.revision + 1,\n\t\t\tupdatedAt: this.stored.snapshot.updatedAt + 1,\n\t\t};\n\t\tthis.emitSnapshot();\n\t}\n}\n\ninterface ListDelay {\n\tentered: Deferred<void>;\n\trelease: Deferred<void>;\n}\n\nexport class TestServerService implements PiServerService {\n\treadonly sessions = new Map<string, StoredSession>();\n\treadonly runtimes = new Map<string, TestSessionRuntime[]>();\n\treadonly locked = new Set<string>();\n\tlastCreatedId?: string;\n\tprivate nextListDelay?: ListDelay;\n\n\tasync listSessions(): Promise<SessionMetadata[]> {\n\t\tconst delay = this.nextListDelay;\n\t\tif (delay) {\n\t\t\tthis.nextListDelay = undefined;\n\t\t\tdelay.entered.resolve(undefined);\n\t\t\tawait delay.release.promise;\n\t\t}\n\t\treturn [...this.sessions.values()].map(({ snapshot }) => ({\n\t\t\tid: snapshot.id,\n\t\t\tcreatedAt: snapshot.createdAt,\n\t\t\tupdatedAt: snapshot.updatedAt,\n\t\t\tsessionName: snapshot.name,\n\t\t\tcwd: snapshot.cwd,\n\t\t}));\n\t}\n\n\tasync listModels(): Promise<ModelMetadata[]> {\n\t\treturn [TEST_MODEL];\n\t}\n\n\tasync createSession(options: CreateSessionOptions): Promise<PiSessionRuntime> {\n\t\tthis.lastCreatedId = options.id;\n\t\tif (this.sessions.has(options.id)) throw new PiServerError(\"session_locked\", \"Session already exists\");\n\t\tthis.seed(options.id, options.name, options.cwd, options.model, options.thinkingLevel);\n\t\treturn this.acquire(options.id);\n\t}\n\n\tasync openSession(sessionId: string): Promise<PiSessionRuntime> {\n\t\tif (!this.sessions.has(sessionId)) throw new PiServerError(\"not_found\", `Unknown session: ${sessionId}`);\n\t\tif (this.locked.has(sessionId)) throw new PiServerError(\"session_locked\", `Session is locked: ${sessionId}`);\n\t\treturn this.acquire(sessionId);\n\t}\n\n\tseed(\n\t\tid = \"session-1\",\n\t\tname = `Session ${id}`,\n\t\tcwd = \"/tmp/pi-server-conformance\",\n\t\tmodel: ModelRef = { provider: TEST_MODEL.provider, id: TEST_MODEL.id },\n\t\tthinkingLevel: ThinkingLevel = \"off\",\n\t): void {\n\t\tthis.sessions.set(id, {\n\t\t\tsnapshot: {\n\t\t\t\tid,\n\t\t\t\tname,\n\t\t\t\tcwd,\n\t\t\t\tcreatedAt: 1,\n\t\t\t\tupdatedAt: 1,\n\t\t\t\tphase: \"idle\",\n\t\t\t\tmodel,\n\t\t\t\tthinkingLevel,\n\t\t\t\tattached: false,\n\t\t\t\tlocked: false,\n\t\t\t\trevision: 0,\n\t\t\t\ttranscript: [],\n\t\t\t\tqueuedSteer: [],\n\t\t\t\tqueuedSteerCount: 0,\n\t\t\t},\n\t\t});\n\t}\n\n\tdelayNextList(): ListDelay {\n\t\tconst delay = { entered: new Deferred<void>(), release: new Deferred<void>() };\n\t\tthis.nextListDelay = delay;\n\t\treturn delay;\n\t}\n\n\tlatestRuntime(id: string): TestSessionRuntime {\n\t\tconst runtimes = this.runtimes.get(id);\n\t\tif (!runtimes?.length) throw new Error(`No runtime for ${id}`);\n\t\treturn runtimes.at(-1)!;\n\t}\n\n\tprivate acquire(id: string): TestSessionRuntime {\n\t\tconst stored = this.sessions.get(id);\n\t\tif (!stored) throw new Error(`Unknown session: ${id}`);\n\t\tthis.locked.add(id);\n\t\tconst runtime = new TestSessionRuntime(stored, () => this.locked.delete(id));\n\t\tconst runtimes = this.runtimes.get(id) ?? [];\n\t\truntimes.push(runtime);\n\t\tthis.runtimes.set(id, runtimes);\n\t\treturn runtime;\n\t}\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../../src/transports/unix/address.ts"],"names":[],"mappings":"AAEA,yEAAyE;AACzE,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,MAAM,CAKnF","sourcesContent":["import { join } from \"node:path\";\n\n/** Derive the local Unix socket path for one logical server identity. */\nexport function getUnixSocketPath(serverId: string, serverDirectory: string): string {\n\tif (!/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(serverId)) {\n\t\tthrow new TypeError(\"Unix serverId must be a canonical lowercase UUIDv4\");\n\t}\n\treturn join(serverDirectory, `${serverId}.sock`);\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
/** Derive the local Unix socket path for one logical server identity. */
|
|
3
|
+
export function getUnixSocketPath(serverId, serverDirectory) {
|
|
4
|
+
if (!/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(serverId)) {
|
|
5
|
+
throw new TypeError("Unix serverId must be a canonical lowercase UUIDv4");
|
|
6
|
+
}
|
|
7
|
+
return join(serverDirectory, `${serverId}.sock`);
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=address.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.js","sourceRoot":"","sources":["../../../src/transports/unix/address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,yEAAyE;AACzE,MAAM,UAAU,iBAAiB,CAAC,QAAgB,EAAE,eAAuB,EAAU;IACpF,IAAI,CAAC,uEAAuE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC7F,MAAM,IAAI,SAAS,CAAC,oDAAoD,CAAC,CAAC;IAC3E,CAAC;IACD,OAAO,IAAI,CAAC,eAAe,EAAE,GAAG,QAAQ,OAAO,CAAC,CAAC;AAAA,CACjD","sourcesContent":["import { join } from \"node:path\";\n\n/** Derive the local Unix socket path for one logical server identity. */\nexport function getUnixSocketPath(serverId: string, serverDirectory: string): string {\n\tif (!/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(serverId)) {\n\t\tthrow new TypeError(\"Unix serverId must be a canonical lowercase UUIDv4\");\n\t}\n\treturn join(serverDirectory, `${serverId}.sock`);\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/transports/unix/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC","sourcesContent":["export { getUnixSocketPath } from \"./address.ts\";\nexport { createUnixListener } from \"./listener.ts\";\nexport { createUnixServer } from \"./preset.ts\";\nexport type { UnixListenerOptions, UnixServerOptions } from \"./types.ts\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/transports/unix/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC","sourcesContent":["export { getUnixSocketPath } from \"./address.ts\";\nexport { createUnixListener } from \"./listener.ts\";\nexport { createUnixServer } from \"./preset.ts\";\nexport type { UnixListenerOptions, UnixServerOptions } from \"./types.ts\";\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type Socket } from "node:net";
|
|
2
|
+
import type { ByteConnection } from "../../connection.ts";
|
|
3
|
+
import type { ServerListener } from "../../listener.ts";
|
|
4
|
+
import type { UnixListenerOptions } from "./types.ts";
|
|
5
|
+
/** @internal Exported only for transport-level verification. */
|
|
6
|
+
export declare class UnixByteConnection implements ByteConnection {
|
|
7
|
+
private readonly socket;
|
|
8
|
+
private readonly gracefulCloseTimeoutMs;
|
|
9
|
+
private readonly maxPendingBytes;
|
|
10
|
+
private pendingBytes;
|
|
11
|
+
private closedValue;
|
|
12
|
+
private closing;
|
|
13
|
+
private writeTail;
|
|
14
|
+
private closePromise?;
|
|
15
|
+
private resolveClose?;
|
|
16
|
+
constructor(socket: Socket, gracefulCloseTimeoutMs: number, maxPendingBytes: number);
|
|
17
|
+
get closed(): boolean;
|
|
18
|
+
send(chunk: Uint8Array): Promise<void>;
|
|
19
|
+
close(finalChunk?: Uint8Array): Promise<void>;
|
|
20
|
+
markClosed(): void;
|
|
21
|
+
private write;
|
|
22
|
+
}
|
|
23
|
+
export declare function createUnixListener(options: UnixListenerOptions): ServerListener;
|
|
24
|
+
//# sourceMappingURL=listener.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listener.d.ts","sourceRoot":"","sources":["../../../src/transports/unix/listener.ts"],"names":[],"mappings":"AAGA,OAAO,EAA+C,KAAK,MAAM,EAAE,MAAM,UAAU,CAAC;AAGpF,OAAO,KAAK,EAAE,cAAc,EAA0B,MAAM,qBAAqB,CAAC;AAClF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAqLtD,gEAAgE;AAChE,qBAAa,kBAAmB,YAAW,cAAc;IACxD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAS;IAChD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,SAAS,CAAoC;IACrD,OAAO,CAAC,YAAY,CAAC,CAAgB;IACrC,OAAO,CAAC,YAAY,CAAC,CAAa;IAElC,YAAY,MAAM,EAAE,MAAM,EAAE,sBAAsB,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAIlF;IAED,IAAI,MAAM,IAAI,OAAO,CAEpB;IAED,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBrC;IAED,KAAK,CAAC,UAAU,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CA8B5C;IAED,UAAU,IAAI,IAAI,CAMjB;IAED,OAAO,CAAC,KAAK;CAsBb;AAgGD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,cAAc,CAE/E","sourcesContent":["import { createHash, randomUUID } from \"node:crypto\";\nimport type { Stats } from \"node:fs\";\nimport { chmod, link, lstat, mkdir, rename, unlink } from \"node:fs/promises\";\nimport { createConnection, createServer, type Server, type Socket } from \"node:net\";\nimport { dirname, join } from \"node:path\";\nimport { DEFAULT_MAX_FRAME_LENGTH } from \"@earendil-works/pi-protocol\";\nimport type { ByteConnection, ByteConnectionAcceptor } from \"../../connection.ts\";\nimport type { ServerListener } from \"../../listener.ts\";\nimport type { UnixListenerOptions } from \"./types.ts\";\n\nconst DEFAULT_SOCKET_MODE = 0o600;\nconst DEFAULT_GRACEFUL_CLOSE_TIMEOUT_MS = 5_000;\nconst MAX_UINT32 = 0xffff_ffff;\nconst MAX_TIMER_DELAY_MS = 2_147_483_647;\nconst SOCKET_PROBE_TIMEOUT_MS = 1_000;\n\ninterface ResolvedUnixListenerOptions {\n\tpath: string;\n\tmode: number;\n\tgracefulCloseTimeoutMs: number;\n\tmaxPendingBytes: number;\n\tonError?: (error: Error) => void;\n}\n\ninterface FileIdentity {\n\tdev: number;\n\tino: number;\n}\nclass UnixListener implements ServerListener {\n\tprivate readonly options: ResolvedUnixListenerOptions;\n\tprivate readonly path: string;\n\tprivate readonly mode: number;\n\tprivate readonly connections = new Set<UnixByteConnection>();\n\tprivate server?: Server;\n\tprivate socketIdentity?: FileIdentity;\n\tprivate ownedBindPath?: string;\n\tprivate closing = false;\n\tprivate closePromise?: Promise<void>;\n\tprivate accept?: ByteConnectionAcceptor;\n\n\tconstructor(options: UnixListenerOptions) {\n\t\tthis.options = resolveUnixListenerOptions(options);\n\t\tthis.path = this.options.path;\n\t\tthis.mode = this.options.mode;\n\t}\n\n\tasync start(accept: ByteConnectionAcceptor): Promise<void> {\n\t\tif (this.server) throw new Error(\"Unix listener is already started\");\n\t\tif (this.closing) throw new Error(\"Unix listener is closing or closed\");\n\t\tthis.accept = accept;\n\n\t\tconst ownedBindPath = getOwnedBindPath(this.path);\n\t\tawait mkdir(dirname(this.path), { recursive: true, mode: 0o700 });\n\t\tawait removeStaleSocket(this.path);\n\t\tawait removeStaleSocket(ownedBindPath);\n\t\tthis.ownedBindPath = ownedBindPath;\n\t\tconst server = createServer((socket) => this.acceptSocket(socket));\n\t\tserver.on(\"error\", (error) => this.reportError(error));\n\t\tthis.server = server;\n\t\ttry {\n\t\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\t\tconst onError = (error: Error): void => {\n\t\t\t\t\tserver.off(\"listening\", onListening);\n\t\t\t\t\treject(error);\n\t\t\t\t};\n\t\t\t\tconst onListening = (): void => {\n\t\t\t\t\tserver.off(\"error\", onError);\n\t\t\t\t\tresolve();\n\t\t\t\t};\n\t\t\t\tserver.once(\"error\", onError);\n\t\t\t\tserver.once(\"listening\", onListening);\n\t\t\t\tserver.listen(ownedBindPath);\n\t\t\t});\n\t\t\tconst stats = await lstat(ownedBindPath);\n\t\t\tif (!stats.isSocket()) throw new Error(`Unix listener path is not a socket after binding: ${ownedBindPath}`);\n\t\t\tthis.socketIdentity = { dev: stats.dev, ino: stats.ino };\n\t\t\tawait link(ownedBindPath, this.path);\n\t\t\tawait setSocketMode(this.path, this.mode);\n\t\t\tawait removePath(ownedBindPath);\n\t\t\tthis.ownedBindPath = undefined;\n\t\t} catch (error) {\n\t\t\tawait this.closeServerAndCleanup(server);\n\t\t\tthis.server = undefined;\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tasync close(): Promise<void> {\n\t\tif (this.closePromise) return this.closePromise;\n\t\tthis.closing = true;\n\t\tthis.closePromise = this.closeInternal();\n\t\treturn this.closePromise;\n\t}\n\n\tprivate acceptSocket(socket: Socket): void {\n\t\tif (this.closing) {\n\t\t\tsocket.destroy();\n\t\t\treturn;\n\t\t}\n\t\tconst connection = new UnixByteConnection(\n\t\t\tsocket,\n\t\t\tthis.options.gracefulCloseTimeoutMs,\n\t\t\tthis.options.maxPendingBytes,\n\t\t);\n\t\tthis.connections.add(connection);\n\t\tconst accept = this.accept;\n\t\tif (!accept) {\n\t\t\tsocket.destroy();\n\t\t\treturn;\n\t\t}\n\t\tconst handler = accept(connection);\n\t\tsocket.on(\"data\", (chunk) => {\n\t\t\thandler.onData(new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength));\n\t\t});\n\t\tsocket.on(\"error\", (error) => {\n\t\t\thandler.onError(error);\n\t\t\tsocket.destroy();\n\t\t});\n\t\tsocket.once(\"close\", () => {\n\t\t\tconnection.markClosed();\n\t\t\tthis.connections.delete(connection);\n\t\t\thandler.onClose();\n\t\t});\n\t}\n\n\tprivate async closeInternal(): Promise<void> {\n\t\tconst serverClosed = this.server ? this.closeServerAndCleanup(this.server) : this.cleanupOwnedSocket();\n\t\tawait Promise.all([...this.connections].map((connection) => connection.close()));\n\t\tawait serverClosed;\n\t\tif (this.ownedBindPath) await removePath(this.ownedBindPath);\n\t\tthis.ownedBindPath = undefined;\n\t\tthis.connections.clear();\n\t\tthis.server = undefined;\n\t}\n\n\tprivate async closeServerAndCleanup(server: Server): Promise<void> {\n\t\ttry {\n\t\t\tawait closeNetServer(server, (error) => this.reportError(error));\n\t\t} finally {\n\t\t\t// Remove an unpublished startup bind path before the public route.\n\t\t\tif (this.ownedBindPath) await removePath(this.ownedBindPath);\n\t\t\tthis.ownedBindPath = undefined;\n\t\t\tawait this.cleanupOwnedSocket();\n\t\t}\n\t}\n\n\tprivate async cleanupOwnedSocket(): Promise<void> {\n\t\tconst identity = this.socketIdentity;\n\t\tthis.socketIdentity = undefined;\n\t\tif (!identity) return;\n\t\tlet current: Stats;\n\t\ttry {\n\t\t\tcurrent = await lstat(this.path);\n\t\t} catch (error) {\n\t\t\tif (isErrorCode(error, \"ENOENT\")) return;\n\t\t\tthrow error;\n\t\t}\n\t\tif (!current.isSocket() || current.dev !== identity.dev || current.ino !== identity.ino) return;\n\n\t\tconst preserved = join(dirname(this.path), `cleanup-${randomUUID().slice(0, 6)}`);\n\t\ttry {\n\t\t\tawait rename(this.path, preserved);\n\t\t} catch (error) {\n\t\t\tif (isErrorCode(error, \"ENOENT\")) return;\n\t\t\tthrow error;\n\t\t}\n\t\tconst moved = await lstat(preserved);\n\t\tif (moved.isSocket() && moved.dev === identity.dev && moved.ino === identity.ino) {\n\t\t\tawait removePath(preserved);\n\t\t\treturn;\n\t\t}\n\t\ttry {\n\t\t\tawait lstat(this.path);\n\t\t} catch (error) {\n\t\t\tif (isErrorCode(error, \"ENOENT\")) await rename(preserved, this.path);\n\t\t\telse throw error;\n\t\t}\n\t\tthrow new Error(`Unix listener path changed during cleanup; preserved replacement at ${preserved}`);\n\t}\n\n\tprivate reportError(error: unknown): void {\n\t\ttry {\n\t\t\tthis.options.onError?.(error instanceof Error ? error : new Error(String(error)));\n\t\t} catch {\n\t\t\t// Error observers cannot affect listener state.\n\t\t}\n\t}\n}\n\n/** @internal Exported only for transport-level verification. */\nexport class UnixByteConnection implements ByteConnection {\n\tprivate readonly socket: Socket;\n\tprivate readonly gracefulCloseTimeoutMs: number;\n\tprivate readonly maxPendingBytes: number;\n\tprivate pendingBytes = 0;\n\tprivate closedValue = false;\n\tprivate closing = false;\n\tprivate writeTail: Promise<void> = Promise.resolve();\n\tprivate closePromise?: Promise<void>;\n\tprivate resolveClose?: () => void;\n\n\tconstructor(socket: Socket, gracefulCloseTimeoutMs: number, maxPendingBytes: number) {\n\t\tthis.socket = socket;\n\t\tthis.gracefulCloseTimeoutMs = gracefulCloseTimeoutMs;\n\t\tthis.maxPendingBytes = maxPendingBytes;\n\t}\n\n\tget closed(): boolean {\n\t\treturn this.closedValue;\n\t}\n\n\tsend(chunk: Uint8Array): Promise<void> {\n\t\tif (!(chunk instanceof Uint8Array)) {\n\t\t\treturn Promise.reject(new TypeError(\"Unix connection chunks must be Uint8Array\"));\n\t\t}\n\t\tif (this.closedValue || this.closing) return Promise.reject(new Error(\"Unix connection is closed\"));\n\t\tif (this.pendingBytes + chunk.byteLength > this.maxPendingBytes) {\n\t\t\treturn Promise.reject(new Error(\"Unix connection exceeded its pending byte limit\"));\n\t\t}\n\t\tthis.pendingBytes += chunk.byteLength;\n\t\tconst bytes = chunk.slice();\n\t\tconst write = this.writeTail.then(() => this.write(bytes));\n\t\tconst tracked = write.finally(() => {\n\t\t\tthis.pendingBytes -= bytes.byteLength;\n\t\t});\n\t\tthis.writeTail = tracked.catch(() => {});\n\t\treturn tracked;\n\t}\n\n\tclose(finalChunk?: Uint8Array): Promise<void> {\n\t\tif (this.closedValue || this.socket.destroyed) {\n\t\t\tthis.markClosed();\n\t\t\treturn Promise.resolve();\n\t\t}\n\t\tif (this.closePromise) return this.closePromise;\n\t\tthis.closing = true;\n\t\tconst finalBytes = finalChunk?.slice();\n\t\tthis.closePromise = new Promise<void>((resolve) => {\n\t\t\tthis.resolveClose = resolve;\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tif (!this.socket.destroyed) this.socket.destroy();\n\t\t\t\tthis.markClosed();\n\t\t\t}, this.gracefulCloseTimeoutMs);\n\t\t\ttimer.unref();\n\t\t\tthis.socket.once(\"close\", () => clearTimeout(timer));\n\t\t\tvoid this.writeTail.then(() => {\n\t\t\t\tif (this.socket.destroyed) {\n\t\t\t\t\tthis.markClosed();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tif (finalBytes) this.socket.end(finalBytes);\n\t\t\t\t\telse this.socket.end();\n\t\t\t\t} catch {\n\t\t\t\t\tthis.socket.destroy();\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t\treturn this.closePromise;\n\t}\n\n\tmarkClosed(): void {\n\t\tif (this.closedValue) return;\n\t\tthis.closedValue = true;\n\t\tthis.closing = true;\n\t\tthis.resolveClose?.();\n\t\tthis.resolveClose = undefined;\n\t}\n\n\tprivate write(chunk: Uint8Array): Promise<void> {\n\t\tif (this.closedValue || this.closing || !this.socket.writable) {\n\t\t\treturn Promise.reject(new Error(\"Unix connection is closed\"));\n\t\t}\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\tlet settled = false;\n\t\t\tconst onClose = (): void => finish(new Error(\"Unix connection closed during write\"));\n\t\t\tconst finish = (error?: Error | null): void => {\n\t\t\t\tif (settled) return;\n\t\t\t\tsettled = true;\n\t\t\t\tthis.socket.off(\"close\", onClose);\n\t\t\t\tif (error) reject(error);\n\t\t\t\telse resolve();\n\t\t\t};\n\t\t\tthis.socket.once(\"close\", onClose);\n\t\t\ttry {\n\t\t\t\tthis.socket.write(chunk, finish);\n\t\t\t} catch (error) {\n\t\t\t\tfinish(error instanceof Error ? error : new Error(String(error)));\n\t\t\t}\n\t\t});\n\t}\n}\n\nfunction getOwnedBindPath(path: string): string {\n\tconst suffix = createHash(\"sha256\").update(path).digest(\"hex\").slice(0, 8);\n\treturn join(dirname(path), `bind-${suffix}`);\n}\n\nasync function removeStaleSocket(path: string): Promise<void> {\n\tlet original: Stats;\n\ttry {\n\t\toriginal = await lstat(path);\n\t} catch (error) {\n\t\tif (isErrorCode(error, \"ENOENT\")) return;\n\t\tthrow error;\n\t}\n\tif (!original.isSocket()) throw new Error(`Refusing to remove non-socket Unix listener path: ${path}`);\n\tif (await isSocketLive(path)) throw new Error(`Unix listener is already running: ${path}`);\n\n\tconst preserved = join(dirname(path), `stale-${randomUUID().slice(0, 6)}`);\n\ttry {\n\t\tawait rename(path, preserved);\n\t} catch (error) {\n\t\tif (isErrorCode(error, \"ENOENT\")) return;\n\t\tthrow error;\n\t}\n\tconst current = await lstat(preserved);\n\tif (!current.isSocket() || current.dev !== original.dev || current.ino !== original.ino) {\n\t\ttry {\n\t\t\tawait lstat(path);\n\t\t} catch (error) {\n\t\t\tif (isErrorCode(error, \"ENOENT\")) await rename(preserved, path);\n\t\t\telse throw error;\n\t\t}\n\t\tthrow new Error(`Unix listener path changed while checking for a stale socket: ${path}`);\n\t}\n\tawait removePath(preserved);\n}\n\nasync function removePath(path: string): Promise<void> {\n\ttry {\n\t\tawait unlink(path);\n\t} catch (error) {\n\t\tif (!isErrorCode(error, \"ENOENT\")) throw error;\n\t}\n}\n\nfunction isSocketLive(path: string): Promise<boolean> {\n\treturn new Promise<boolean>((resolve, reject) => {\n\t\tconst socket = createConnection(path);\n\t\tlet settled = false;\n\t\tlet timer: NodeJS.Timeout | undefined;\n\t\tconst finish = (result: boolean, error?: Error): void => {\n\t\t\tif (settled) return;\n\t\t\tsettled = true;\n\t\t\tif (timer) clearTimeout(timer);\n\t\t\tsocket.removeAllListeners();\n\t\t\tsocket.destroy();\n\t\t\tif (error) reject(error);\n\t\t\telse resolve(result);\n\t\t};\n\t\tsocket.once(\"connect\", () => finish(true));\n\t\tsocket.once(\"error\", (error: NodeJS.ErrnoException) => {\n\t\t\tif ([\"ECONNREFUSED\", \"ENOENT\", \"EPIPE\", \"ECONNRESET\"].includes(error.code ?? \"\")) {\n\t\t\t\tfinish(false);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tfinish(false, error);\n\t\t});\n\t\ttimer = setTimeout(() => finish(true), SOCKET_PROBE_TIMEOUT_MS);\n\t\ttimer.unref();\n\t});\n}\n\nasync function setSocketMode(path: string, mode: number): Promise<void> {\n\tif (process.platform === \"win32\") return;\n\ttry {\n\t\tawait chmod(path, mode);\n\t} catch (error) {\n\t\tif (!isErrorCode(error, \"ENOSYS\") && !isErrorCode(error, \"ENOTSUP\")) throw error;\n\t}\n}\n\nfunction closeNetServer(server: Server, reportError: (error: Error) => void): Promise<void> {\n\tif (!server.listening) return Promise.resolve();\n\treturn new Promise<void>((resolve) => {\n\t\tserver.close((error) => {\n\t\t\tif (error) reportError(error);\n\t\t\tresolve();\n\t\t});\n\t});\n}\n\nfunction isErrorCode(error: unknown, code: string): boolean {\n\treturn error instanceof Error && \"code\" in error && error.code === code;\n}\n\nexport function createUnixListener(options: UnixListenerOptions): ServerListener {\n\treturn new UnixListener(options);\n}\n\nfunction resolveUnixListenerOptions(options: UnixListenerOptions): ResolvedUnixListenerOptions {\n\tif (!options.path) throw new TypeError(\"Server Unix socket path must not be empty\");\n\tconst mode = options.mode ?? DEFAULT_SOCKET_MODE;\n\tif (!Number.isInteger(mode) || mode < 0 || mode > 0o777) {\n\t\tthrow new TypeError(\"Server Unix socket mode must be an integer between 0 and 0o777\");\n\t}\n\tconst maxFrameLength = options.maxFrameLength ?? DEFAULT_MAX_FRAME_LENGTH;\n\tif (!Number.isSafeInteger(maxFrameLength) || maxFrameLength <= 0 || maxFrameLength > MAX_UINT32) {\n\t\tthrow new TypeError(`Server maxFrameLength must be an integer between 1 and ${MAX_UINT32}`);\n\t}\n\tconst maxPendingBytes = options.maxPendingBytes ?? maxFrameLength * 4;\n\tif (!Number.isSafeInteger(maxPendingBytes) || maxPendingBytes < maxFrameLength + 4) {\n\t\tthrow new TypeError(\"Server maxPendingBytes must be a safe integer at least maxFrameLength + 4\");\n\t}\n\tconst gracefulCloseTimeoutMs = options.gracefulCloseTimeoutMs ?? DEFAULT_GRACEFUL_CLOSE_TIMEOUT_MS;\n\tif (\n\t\t!Number.isSafeInteger(gracefulCloseTimeoutMs) ||\n\t\tgracefulCloseTimeoutMs <= 0 ||\n\t\tgracefulCloseTimeoutMs > MAX_TIMER_DELAY_MS\n\t) {\n\t\tthrow new TypeError(`Server gracefulCloseTimeoutMs must be an integer between 1 and ${MAX_TIMER_DELAY_MS}`);\n\t}\n\treturn {\n\t\tpath: options.path,\n\t\tmode,\n\t\tmaxPendingBytes,\n\t\tgracefulCloseTimeoutMs,\n\t\tonError: options.onError,\n\t};\n}\n"]}
|