@wingman-ai/gateway 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.wingman/agents/README.md +161 -0
- package/.wingman/agents/coding/agent.md +147 -0
- package/.wingman/agents/coding/implementor.md +56 -0
- package/.wingman/agents/main/agent.md +19 -0
- package/.wingman/agents/researcher/agent.md +62 -0
- package/.wingman/agents/stock-trader/agent.md +223 -0
- package/.wingman/agents/stock-trader/chain-curator.md +24 -0
- package/.wingman/agents/stock-trader/goal-translator.md +42 -0
- package/.wingman/agents/stock-trader/guardrails-veto.md +11 -0
- package/.wingman/agents/stock-trader/path-planner.md +23 -0
- package/.wingman/agents/stock-trader/regime-analyst.md +15 -0
- package/.wingman/agents/stock-trader/risk.md +20 -0
- package/.wingman/agents/stock-trader/selection.md +22 -0
- package/.wingman/agents/stock-trader/strategy-composer.md +38 -0
- package/.wingman/agents/wingman/agent.json +12 -0
- package/bin/wingman +7 -0
- package/dist/agent/config/agentConfig.cjs +95 -0
- package/dist/agent/config/agentConfig.d.ts +187 -0
- package/dist/agent/config/agentConfig.js +52 -0
- package/dist/agent/config/agentLoader.cjs +242 -0
- package/dist/agent/config/agentLoader.d.ts +42 -0
- package/dist/agent/config/agentLoader.js +208 -0
- package/dist/agent/config/mcpClientManager.cjs +168 -0
- package/dist/agent/config/mcpClientManager.d.ts +41 -0
- package/dist/agent/config/mcpClientManager.js +134 -0
- package/dist/agent/config/modelFactory.cjs +175 -0
- package/dist/agent/config/modelFactory.d.ts +33 -0
- package/dist/agent/config/modelFactory.js +141 -0
- package/dist/agent/config/toolRegistry.cjs +111 -0
- package/dist/agent/config/toolRegistry.d.ts +25 -0
- package/dist/agent/config/toolRegistry.js +71 -0
- package/dist/agent/middleware/additional-messages.cjs +60 -0
- package/dist/agent/middleware/additional-messages.d.ts +7 -0
- package/dist/agent/middleware/additional-messages.js +26 -0
- package/dist/agent/middleware/hooks/executor.cjs +137 -0
- package/dist/agent/middleware/hooks/executor.d.ts +52 -0
- package/dist/agent/middleware/hooks/executor.js +103 -0
- package/dist/agent/middleware/hooks/input-builder.cjs +55 -0
- package/dist/agent/middleware/hooks/input-builder.d.ts +15 -0
- package/dist/agent/middleware/hooks/input-builder.js +21 -0
- package/dist/agent/middleware/hooks/matcher.cjs +59 -0
- package/dist/agent/middleware/hooks/matcher.d.ts +27 -0
- package/dist/agent/middleware/hooks/matcher.js +22 -0
- package/dist/agent/middleware/hooks/merger.cjs +54 -0
- package/dist/agent/middleware/hooks/merger.d.ts +18 -0
- package/dist/agent/middleware/hooks/merger.js +20 -0
- package/dist/agent/middleware/hooks/types.cjs +62 -0
- package/dist/agent/middleware/hooks/types.d.ts +82 -0
- package/dist/agent/middleware/hooks/types.js +19 -0
- package/dist/agent/middleware/hooks.cjs +79 -0
- package/dist/agent/middleware/hooks.d.ts +19 -0
- package/dist/agent/middleware/hooks.js +45 -0
- package/dist/agent/middleware/media-compat.cjs +80 -0
- package/dist/agent/middleware/media-compat.d.ts +7 -0
- package/dist/agent/middleware/media-compat.js +46 -0
- package/dist/agent/tests/agentConfig.test.cjs +132 -0
- package/dist/agent/tests/agentConfig.test.d.ts +1 -0
- package/dist/agent/tests/agentConfig.test.js +126 -0
- package/dist/agent/tests/agentLoader.test.cjs +235 -0
- package/dist/agent/tests/agentLoader.test.d.ts +1 -0
- package/dist/agent/tests/agentLoader.test.js +229 -0
- package/dist/agent/tests/modelFactory.test.cjs +114 -0
- package/dist/agent/tests/modelFactory.test.d.ts +1 -0
- package/dist/agent/tests/modelFactory.test.js +108 -0
- package/dist/agent/tests/test-agent-loader.cjs +33 -0
- package/dist/agent/tests/test-agent-loader.d.ts +1 -0
- package/dist/agent/tests/test-agent-loader.js +27 -0
- package/dist/agent/tests/test-subagent-loading.cjs +99 -0
- package/dist/agent/tests/test-subagent-loading.d.ts +1 -0
- package/dist/agent/tests/test-subagent-loading.js +93 -0
- package/dist/agent/tests/toolRegistry.test.cjs +109 -0
- package/dist/agent/tests/toolRegistry.test.d.ts +1 -0
- package/dist/agent/tests/toolRegistry.test.js +103 -0
- package/dist/agent/tools/code_search.cjs +108 -0
- package/dist/agent/tools/code_search.d.ts +24 -0
- package/dist/agent/tools/code_search.js +74 -0
- package/dist/agent/tools/command_execute.cjs +136 -0
- package/dist/agent/tools/command_execute.d.ts +12 -0
- package/dist/agent/tools/command_execute.js +99 -0
- package/dist/agent/tools/git_status.cjs +126 -0
- package/dist/agent/tools/git_status.d.ts +15 -0
- package/dist/agent/tools/git_status.js +92 -0
- package/dist/agent/tools/internet_search.cjs +93 -0
- package/dist/agent/tools/internet_search.d.ts +25 -0
- package/dist/agent/tools/internet_search.js +56 -0
- package/dist/agent/tools/think.cjs +53 -0
- package/dist/agent/tools/think.d.ts +26 -0
- package/dist/agent/tools/think.js +16 -0
- package/dist/agent/tools/web_crawler.cjs +180 -0
- package/dist/agent/tools/web_crawler.d.ts +31 -0
- package/dist/agent/tools/web_crawler.js +143 -0
- package/dist/agent/utils.cjs +54 -0
- package/dist/agent/utils.d.ts +1 -0
- package/dist/agent/utils.js +10 -0
- package/dist/cli/commands/agent.cjs +169 -0
- package/dist/cli/commands/agent.d.ts +15 -0
- package/dist/cli/commands/agent.js +125 -0
- package/dist/cli/commands/gateway.cjs +601 -0
- package/dist/cli/commands/gateway.d.ts +12 -0
- package/dist/cli/commands/gateway.js +567 -0
- package/dist/cli/commands/init.cjs +681 -0
- package/dist/cli/commands/init.d.ts +10 -0
- package/dist/cli/commands/init.js +634 -0
- package/dist/cli/commands/provider.cjs +208 -0
- package/dist/cli/commands/provider.d.ts +5 -0
- package/dist/cli/commands/provider.js +174 -0
- package/dist/cli/commands/skill.cjs +145 -0
- package/dist/cli/commands/skill.d.ts +10 -0
- package/dist/cli/commands/skill.js +111 -0
- package/dist/cli/config/loader.cjs +143 -0
- package/dist/cli/config/loader.d.ts +14 -0
- package/dist/cli/config/loader.js +109 -0
- package/dist/cli/config/schema.cjs +262 -0
- package/dist/cli/config/schema.d.ts +268 -0
- package/dist/cli/config/schema.js +213 -0
- package/dist/cli/core/agentInvoker.cjs +284 -0
- package/dist/cli/core/agentInvoker.d.ts +77 -0
- package/dist/cli/core/agentInvoker.js +247 -0
- package/dist/cli/core/commandHandler.cjs +257 -0
- package/dist/cli/core/commandHandler.d.ts +62 -0
- package/dist/cli/core/commandHandler.js +223 -0
- package/dist/cli/core/database/bunSqliteAdapter.cjs +87 -0
- package/dist/cli/core/database/bunSqliteAdapter.d.ts +34 -0
- package/dist/cli/core/database/bunSqliteAdapter.js +53 -0
- package/dist/cli/core/loggerBridge.cjs +42 -0
- package/dist/cli/core/loggerBridge.d.ts +8 -0
- package/dist/cli/core/loggerBridge.js +8 -0
- package/dist/cli/core/outputManager.cjs +106 -0
- package/dist/cli/core/outputManager.d.ts +43 -0
- package/dist/cli/core/outputManager.js +72 -0
- package/dist/cli/core/sessionManager.cjs +535 -0
- package/dist/cli/core/sessionManager.d.ts +111 -0
- package/dist/cli/core/sessionManager.js +486 -0
- package/dist/cli/core/streamParser.cjs +328 -0
- package/dist/cli/core/streamParser.d.ts +42 -0
- package/dist/cli/core/streamParser.js +288 -0
- package/dist/cli/index.cjs +211 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +205 -0
- package/dist/cli/services/skillRepository.cjs +178 -0
- package/dist/cli/services/skillRepository.d.ts +35 -0
- package/dist/cli/services/skillRepository.js +144 -0
- package/dist/cli/services/skillService.cjs +336 -0
- package/dist/cli/services/skillService.d.ts +48 -0
- package/dist/cli/services/skillService.js +302 -0
- package/dist/cli/types/gateway.cjs +18 -0
- package/dist/cli/types/gateway.d.ts +18 -0
- package/dist/cli/types/gateway.js +0 -0
- package/dist/cli/types/init.cjs +18 -0
- package/dist/cli/types/init.d.ts +13 -0
- package/dist/cli/types/init.js +0 -0
- package/dist/cli/types/provider.cjs +18 -0
- package/dist/cli/types/provider.d.ts +9 -0
- package/dist/cli/types/provider.js +0 -0
- package/dist/cli/types/skill.cjs +18 -0
- package/dist/cli/types/skill.d.ts +71 -0
- package/dist/cli/types/skill.js +0 -0
- package/dist/cli/types.cjs +18 -0
- package/dist/cli/types.d.ts +175 -0
- package/dist/cli/types.js +0 -0
- package/dist/cli/ui/AgentOutput.cjs +82 -0
- package/dist/cli/ui/AgentOutput.d.ts +8 -0
- package/dist/cli/ui/AgentOutput.js +38 -0
- package/dist/cli/ui/App.cjs +285 -0
- package/dist/cli/ui/App.d.ts +6 -0
- package/dist/cli/ui/App.js +241 -0
- package/dist/cli/ui/ErrorDisplay.cjs +65 -0
- package/dist/cli/ui/ErrorDisplay.d.ts +8 -0
- package/dist/cli/ui/ErrorDisplay.js +21 -0
- package/dist/cli/ui/LogDisplay.cjs +74 -0
- package/dist/cli/ui/LogDisplay.d.ts +13 -0
- package/dist/cli/ui/LogDisplay.js +30 -0
- package/dist/cli/ui/SessionListDisplay.cjs +135 -0
- package/dist/cli/ui/SessionListDisplay.d.ts +9 -0
- package/dist/cli/ui/SessionListDisplay.js +91 -0
- package/dist/cli/ui/blockHelpers.cjs +80 -0
- package/dist/cli/ui/blockHelpers.d.ts +21 -0
- package/dist/cli/ui/blockHelpers.js +40 -0
- package/dist/cli/ui/components/ToolCallDisplay.cjs +207 -0
- package/dist/cli/ui/components/ToolCallDisplay.d.ts +7 -0
- package/dist/cli/ui/components/ToolCallDisplay.js +162 -0
- package/dist/cli/ui/components/ToolResultDisplay.cjs +86 -0
- package/dist/cli/ui/components/ToolResultDisplay.d.ts +8 -0
- package/dist/cli/ui/components/ToolResultDisplay.js +42 -0
- package/dist/cli/ui/toolDisplayHelpers.cjs +112 -0
- package/dist/cli/ui/toolDisplayHelpers.d.ts +3 -0
- package/dist/cli/ui/toolDisplayHelpers.js +72 -0
- package/dist/gateway/adapters/discord.cjs +298 -0
- package/dist/gateway/adapters/discord.d.ts +42 -0
- package/dist/gateway/adapters/discord.js +246 -0
- package/dist/gateway/auth.cjs +94 -0
- package/dist/gateway/auth.d.ts +36 -0
- package/dist/gateway/auth.js +60 -0
- package/dist/gateway/broadcast.cjs +131 -0
- package/dist/gateway/broadcast.d.ts +76 -0
- package/dist/gateway/broadcast.js +97 -0
- package/dist/gateway/client.cjs +282 -0
- package/dist/gateway/client.d.ts +141 -0
- package/dist/gateway/client.js +248 -0
- package/dist/gateway/daemon.cjs +195 -0
- package/dist/gateway/daemon.d.ts +67 -0
- package/dist/gateway/daemon.js +161 -0
- package/dist/gateway/discovery/index.cjs +72 -0
- package/dist/gateway/discovery/index.d.ts +3 -0
- package/dist/gateway/discovery/index.js +3 -0
- package/dist/gateway/discovery/mdns.cjs +221 -0
- package/dist/gateway/discovery/mdns.d.ts +37 -0
- package/dist/gateway/discovery/mdns.js +177 -0
- package/dist/gateway/discovery/tailscale.cjs +140 -0
- package/dist/gateway/discovery/tailscale.d.ts +31 -0
- package/dist/gateway/discovery/tailscale.js +106 -0
- package/dist/gateway/discovery/types.cjs +18 -0
- package/dist/gateway/discovery/types.d.ts +41 -0
- package/dist/gateway/discovery/types.js +0 -0
- package/dist/gateway/env.cjs +45 -0
- package/dist/gateway/env.d.ts +2 -0
- package/dist/gateway/env.js +8 -0
- package/dist/gateway/hooks/loader.cjs +137 -0
- package/dist/gateway/hooks/loader.d.ts +10 -0
- package/dist/gateway/hooks/loader.js +103 -0
- package/dist/gateway/hooks/registry.cjs +128 -0
- package/dist/gateway/hooks/registry.d.ts +13 -0
- package/dist/gateway/hooks/registry.js +94 -0
- package/dist/gateway/hooks/types.cjs +58 -0
- package/dist/gateway/hooks/types.d.ts +50 -0
- package/dist/gateway/hooks/types.js +18 -0
- package/dist/gateway/http/agents.cjs +280 -0
- package/dist/gateway/http/agents.d.ts +2 -0
- package/dist/gateway/http/agents.js +246 -0
- package/dist/gateway/http/fs.cjs +81 -0
- package/dist/gateway/http/fs.d.ts +2 -0
- package/dist/gateway/http/fs.js +47 -0
- package/dist/gateway/http/providers.cjs +120 -0
- package/dist/gateway/http/providers.d.ts +2 -0
- package/dist/gateway/http/providers.js +86 -0
- package/dist/gateway/http/routines.cjs +196 -0
- package/dist/gateway/http/routines.d.ts +20 -0
- package/dist/gateway/http/routines.js +159 -0
- package/dist/gateway/http/sessions.cjs +241 -0
- package/dist/gateway/http/sessions.d.ts +2 -0
- package/dist/gateway/http/sessions.js +207 -0
- package/dist/gateway/http/types.cjs +18 -0
- package/dist/gateway/http/types.d.ts +25 -0
- package/dist/gateway/http/types.js +0 -0
- package/dist/gateway/http/voice.cjs +167 -0
- package/dist/gateway/http/voice.d.ts +2 -0
- package/dist/gateway/http/voice.js +133 -0
- package/dist/gateway/http/webhooks.cjs +353 -0
- package/dist/gateway/http/webhooks.d.ts +22 -0
- package/dist/gateway/http/webhooks.js +313 -0
- package/dist/gateway/index.cjs +119 -0
- package/dist/gateway/index.d.ts +8 -0
- package/dist/gateway/index.js +9 -0
- package/dist/gateway/node.cjs +218 -0
- package/dist/gateway/node.d.ts +112 -0
- package/dist/gateway/node.js +184 -0
- package/dist/gateway/router.cjs +85 -0
- package/dist/gateway/router.d.ts +9 -0
- package/dist/gateway/router.js +51 -0
- package/dist/gateway/rpcClient.cjs +152 -0
- package/dist/gateway/rpcClient.d.ts +24 -0
- package/dist/gateway/rpcClient.js +118 -0
- package/dist/gateway/server.cjs +1175 -0
- package/dist/gateway/server.d.ts +185 -0
- package/dist/gateway/server.js +1138 -0
- package/dist/gateway/transport/http.cjs +153 -0
- package/dist/gateway/transport/http.d.ts +25 -0
- package/dist/gateway/transport/http.js +119 -0
- package/dist/gateway/transport/index.cjs +40 -0
- package/dist/gateway/transport/index.d.ts +3 -0
- package/dist/gateway/transport/index.js +3 -0
- package/dist/gateway/transport/types.cjs +18 -0
- package/dist/gateway/transport/types.d.ts +59 -0
- package/dist/gateway/transport/types.js +0 -0
- package/dist/gateway/transport/websocket.cjs +132 -0
- package/dist/gateway/transport/websocket.d.ts +21 -0
- package/dist/gateway/transport/websocket.js +98 -0
- package/dist/gateway/types.cjs +18 -0
- package/dist/gateway/types.d.ts +215 -0
- package/dist/gateway/types.js +0 -0
- package/dist/gateway/validation.cjs +225 -0
- package/dist/gateway/validation.d.ts +157 -0
- package/dist/gateway/validation.js +158 -0
- package/dist/index.cjs +95 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/logger.cjs +270 -0
- package/dist/logger.d.ts +54 -0
- package/dist/logger.js +215 -0
- package/dist/providers/copilot.cjs +148 -0
- package/dist/providers/copilot.d.ts +3 -0
- package/dist/providers/copilot.js +114 -0
- package/dist/providers/credentials.cjs +154 -0
- package/dist/providers/credentials.d.ts +26 -0
- package/dist/providers/credentials.js +99 -0
- package/dist/providers/oauth.cjs +279 -0
- package/dist/providers/oauth.d.ts +13 -0
- package/dist/providers/oauth.js +245 -0
- package/dist/providers/registry.cjs +138 -0
- package/dist/providers/registry.d.ts +32 -0
- package/dist/providers/registry.js +98 -0
- package/dist/tests/additionalMessageMiddleware.test.cjs +45 -0
- package/dist/tests/additionalMessageMiddleware.test.d.ts +1 -0
- package/dist/tests/additionalMessageMiddleware.test.js +39 -0
- package/dist/tests/agent-config-voice.test.cjs +25 -0
- package/dist/tests/agent-config-voice.test.d.ts +1 -0
- package/dist/tests/agent-config-voice.test.js +19 -0
- package/dist/tests/agentInvokerAttachments.test.cjs +67 -0
- package/dist/tests/agentInvokerAttachments.test.d.ts +1 -0
- package/dist/tests/agentInvokerAttachments.test.js +61 -0
- package/dist/tests/attachments-utils.test.cjs +46 -0
- package/dist/tests/attachments-utils.test.d.ts +1 -0
- package/dist/tests/attachments-utils.test.js +40 -0
- package/dist/tests/bunSqliteAdapter.test.cjs +265 -0
- package/dist/tests/bunSqliteAdapter.test.d.ts +1 -0
- package/dist/tests/bunSqliteAdapter.test.js +259 -0
- package/dist/tests/candleRange.test.cjs +48 -0
- package/dist/tests/candleRange.test.d.ts +1 -0
- package/dist/tests/candleRange.test.js +42 -0
- package/dist/tests/cli-config-loader.test.cjs +364 -0
- package/dist/tests/cli-config-loader.test.d.ts +1 -0
- package/dist/tests/cli-config-loader.test.js +358 -0
- package/dist/tests/cli-init.test.cjs +82 -0
- package/dist/tests/cli-init.test.d.ts +1 -0
- package/dist/tests/cli-init.test.js +76 -0
- package/dist/tests/discord-adapter.test.cjs +55 -0
- package/dist/tests/discord-adapter.test.d.ts +1 -0
- package/dist/tests/discord-adapter.test.js +49 -0
- package/dist/tests/gateway.test.cjs +319 -0
- package/dist/tests/gateway.test.d.ts +1 -0
- package/dist/tests/gateway.test.js +313 -0
- package/dist/tests/hooks-matcher.test.cjs +309 -0
- package/dist/tests/hooks-matcher.test.d.ts +1 -0
- package/dist/tests/hooks-matcher.test.js +303 -0
- package/dist/tests/hooks-merger.test.cjs +528 -0
- package/dist/tests/hooks-merger.test.d.ts +1 -0
- package/dist/tests/hooks-merger.test.js +522 -0
- package/dist/tests/integration/agent-invocation.integration.test.cjs +264 -0
- package/dist/tests/integration/agent-invocation.integration.test.d.ts +1 -0
- package/dist/tests/integration/agent-invocation.integration.test.js +258 -0
- package/dist/tests/integration/finnhub-candles.integration.test.cjs +98 -0
- package/dist/tests/integration/finnhub-candles.integration.test.d.ts +1 -0
- package/dist/tests/integration/finnhub-candles.integration.test.js +92 -0
- package/dist/tests/logger.test.cjs +353 -0
- package/dist/tests/logger.test.d.ts +1 -0
- package/dist/tests/logger.test.js +347 -0
- package/dist/tests/mediaCompatibilityMiddleware.test.cjs +106 -0
- package/dist/tests/mediaCompatibilityMiddleware.test.d.ts +1 -0
- package/dist/tests/mediaCompatibilityMiddleware.test.js +100 -0
- package/dist/tests/routines-api.test.cjs +107 -0
- package/dist/tests/routines-api.test.d.ts +1 -0
- package/dist/tests/routines-api.test.js +101 -0
- package/dist/tests/sessionMessageAttachments.test.cjs +108 -0
- package/dist/tests/sessionMessageAttachments.test.d.ts +1 -0
- package/dist/tests/sessionMessageAttachments.test.js +102 -0
- package/dist/tests/sessionMessageRole.test.cjs +44 -0
- package/dist/tests/sessionMessageRole.test.d.ts +1 -0
- package/dist/tests/sessionMessageRole.test.js +38 -0
- package/dist/tests/sessionStateMessages.test.cjs +72 -0
- package/dist/tests/sessionStateMessages.test.d.ts +1 -0
- package/dist/tests/sessionStateMessages.test.js +66 -0
- package/dist/tests/sessions-api.test.cjs +68 -0
- package/dist/tests/sessions-api.test.d.ts +1 -0
- package/dist/tests/sessions-api.test.js +62 -0
- package/dist/tests/technicalIndicators.test.cjs +82 -0
- package/dist/tests/technicalIndicators.test.d.ts +1 -0
- package/dist/tests/technicalIndicators.test.js +76 -0
- package/dist/tests/toolDisplayHelpers.test.cjs +43 -0
- package/dist/tests/toolDisplayHelpers.test.d.ts +1 -0
- package/dist/tests/toolDisplayHelpers.test.js +37 -0
- package/dist/tests/voice-config.test.cjs +35 -0
- package/dist/tests/voice-config.test.d.ts +1 -0
- package/dist/tests/voice-config.test.js +29 -0
- package/dist/tests/yahooCandles.test.cjs +111 -0
- package/dist/tests/yahooCandles.test.d.ts +1 -0
- package/dist/tests/yahooCandles.test.js +105 -0
- package/dist/tools/finance/candleRange.cjs +71 -0
- package/dist/tools/finance/candleRange.d.ts +21 -0
- package/dist/tools/finance/candleRange.js +28 -0
- package/dist/tools/finance/optionsAnalytics.cjs +222 -0
- package/dist/tools/finance/optionsAnalytics.d.ts +44 -0
- package/dist/tools/finance/optionsAnalytics.js +188 -0
- package/dist/tools/finance/optionsAnalytics.test.cjs +128 -0
- package/dist/tools/finance/optionsAnalytics.test.d.ts +1 -0
- package/dist/tools/finance/optionsAnalytics.test.js +122 -0
- package/dist/tools/finance/technicalIndicators.cjs +111 -0
- package/dist/tools/finance/technicalIndicators.d.ts +15 -0
- package/dist/tools/finance/technicalIndicators.js +68 -0
- package/dist/tools/finance/yahooCandles.cjs +125 -0
- package/dist/tools/finance/yahooCandles.d.ts +41 -0
- package/dist/tools/finance/yahooCandles.js +85 -0
- package/dist/tools/mcp-finance.cjs +649 -0
- package/dist/tools/mcp-finance.d.ts +1 -0
- package/dist/tools/mcp-finance.js +631 -0
- package/dist/types/agents.cjs +18 -0
- package/dist/types/agents.d.ts +11 -0
- package/dist/types/agents.js +0 -0
- package/dist/types/hooks.cjs +18 -0
- package/dist/types/hooks.d.ts +82 -0
- package/dist/types/hooks.js +0 -0
- package/dist/types/mcp.cjs +86 -0
- package/dist/types/mcp.d.ts +107 -0
- package/dist/types/mcp.js +40 -0
- package/dist/types/voice.cjs +103 -0
- package/dist/types/voice.d.ts +117 -0
- package/dist/types/voice.js +51 -0
- package/dist/utils/attachments.cjs +46 -0
- package/dist/utils/attachments.d.ts +7 -0
- package/dist/utils/attachments.js +12 -0
- package/dist/voice/config.cjs +52 -0
- package/dist/voice/config.d.ts +8 -0
- package/dist/voice/config.js +18 -0
- package/dist/webui/assets/index-BA0HaStz.css +1 -0
- package/dist/webui/assets/index-NHgTZsWN.js +112 -0
- package/dist/webui/assets/wingman_icon-DOy91UEF.webp +0 -0
- package/dist/webui/assets/wingman_logo-Cogyt3qm.webp +0 -0
- package/dist/webui/index.html +19 -0
- package/package.json +130 -0
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { HTTPBridgeTransport, WebSocketTransport } from "./transport/index.js";
|
|
2
|
+
import { createLogger } from "../logger.js";
|
|
3
|
+
function _define_property(obj, key, value) {
|
|
4
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
5
|
+
value: value,
|
|
6
|
+
enumerable: true,
|
|
7
|
+
configurable: true,
|
|
8
|
+
writable: true
|
|
9
|
+
});
|
|
10
|
+
else obj[key] = value;
|
|
11
|
+
return obj;
|
|
12
|
+
}
|
|
13
|
+
class GatewayClient {
|
|
14
|
+
async connect() {
|
|
15
|
+
const transportType = this.selectTransport();
|
|
16
|
+
this.transport = this.createTransport(transportType);
|
|
17
|
+
this.transport.onMessage((message)=>{
|
|
18
|
+
this.handleMessage(message);
|
|
19
|
+
});
|
|
20
|
+
try {
|
|
21
|
+
await this.transport.connect();
|
|
22
|
+
this.reconnectAttempts = 0;
|
|
23
|
+
this.events.connected?.();
|
|
24
|
+
this.register();
|
|
25
|
+
} catch (error) {
|
|
26
|
+
this.logger.error("Transport connection failed", error);
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
selectTransport() {
|
|
31
|
+
if ("auto" === this.transportType) {
|
|
32
|
+
if (this.url.startsWith("ws://") || this.url.startsWith("wss://")) return "websocket";
|
|
33
|
+
return "http";
|
|
34
|
+
}
|
|
35
|
+
return this.transportType;
|
|
36
|
+
}
|
|
37
|
+
createTransport(type) {
|
|
38
|
+
const transportOptions = {
|
|
39
|
+
token: this.token,
|
|
40
|
+
autoReconnect: true,
|
|
41
|
+
maxReconnectAttempts: this.maxReconnectAttempts,
|
|
42
|
+
reconnectDelay: this.reconnectDelay
|
|
43
|
+
};
|
|
44
|
+
if ("http" === type) return new HTTPBridgeTransport(this.url, transportOptions);
|
|
45
|
+
return new WebSocketTransport(this.url, transportOptions);
|
|
46
|
+
}
|
|
47
|
+
disconnect() {
|
|
48
|
+
if (this.pingInterval) {
|
|
49
|
+
clearInterval(this.pingInterval);
|
|
50
|
+
this.pingInterval = null;
|
|
51
|
+
}
|
|
52
|
+
if (this.transport) {
|
|
53
|
+
this.transport.disconnect();
|
|
54
|
+
this.transport = null;
|
|
55
|
+
}
|
|
56
|
+
if (this.ws) {
|
|
57
|
+
this.ws.close();
|
|
58
|
+
this.ws = null;
|
|
59
|
+
}
|
|
60
|
+
this.nodeId = null;
|
|
61
|
+
}
|
|
62
|
+
register() {
|
|
63
|
+
const payload = {
|
|
64
|
+
name: this.nodeName,
|
|
65
|
+
capabilities: this.capabilities,
|
|
66
|
+
token: this.token
|
|
67
|
+
};
|
|
68
|
+
this.send({
|
|
69
|
+
type: "register",
|
|
70
|
+
payload,
|
|
71
|
+
timestamp: Date.now()
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
async joinGroup(groupName, options = {}) {
|
|
75
|
+
const payload = {
|
|
76
|
+
groupName,
|
|
77
|
+
createIfNotExists: options.createIfNotExists ?? true,
|
|
78
|
+
description: options.description
|
|
79
|
+
};
|
|
80
|
+
this.send({
|
|
81
|
+
type: "join_group",
|
|
82
|
+
nodeId: this.nodeId || void 0,
|
|
83
|
+
payload,
|
|
84
|
+
timestamp: Date.now()
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
async leaveGroup(groupId) {
|
|
88
|
+
this.send({
|
|
89
|
+
type: "leave_group",
|
|
90
|
+
nodeId: this.nodeId || void 0,
|
|
91
|
+
groupId,
|
|
92
|
+
timestamp: Date.now()
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
broadcast(groupId, message) {
|
|
96
|
+
const payload = {
|
|
97
|
+
groupId,
|
|
98
|
+
message
|
|
99
|
+
};
|
|
100
|
+
this.send({
|
|
101
|
+
type: "broadcast",
|
|
102
|
+
nodeId: this.nodeId || void 0,
|
|
103
|
+
payload,
|
|
104
|
+
timestamp: Date.now()
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
sendDirect(targetNodeId, message) {
|
|
108
|
+
const payload = {
|
|
109
|
+
targetNodeId,
|
|
110
|
+
message
|
|
111
|
+
};
|
|
112
|
+
this.send({
|
|
113
|
+
type: "direct",
|
|
114
|
+
nodeId: this.nodeId || void 0,
|
|
115
|
+
payload,
|
|
116
|
+
timestamp: Date.now()
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
ping() {
|
|
120
|
+
this.send({
|
|
121
|
+
type: "ping",
|
|
122
|
+
nodeId: this.nodeId || void 0,
|
|
123
|
+
timestamp: Date.now()
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
handleMessage(msg) {
|
|
127
|
+
try {
|
|
128
|
+
switch(msg.type){
|
|
129
|
+
case "registered":
|
|
130
|
+
if ("nodeId" in msg && msg.nodeId) {
|
|
131
|
+
this.nodeId = msg.nodeId;
|
|
132
|
+
this.events.registered?.(msg.nodeId, this.nodeName);
|
|
133
|
+
this.startPingInterval();
|
|
134
|
+
}
|
|
135
|
+
break;
|
|
136
|
+
case "ack":
|
|
137
|
+
this.handleAck(msg);
|
|
138
|
+
break;
|
|
139
|
+
case "broadcast":
|
|
140
|
+
this.handleBroadcast(msg);
|
|
141
|
+
break;
|
|
142
|
+
case "direct":
|
|
143
|
+
this.handleDirect(msg);
|
|
144
|
+
break;
|
|
145
|
+
case "ping":
|
|
146
|
+
this.handlePing(msg);
|
|
147
|
+
break;
|
|
148
|
+
case "pong":
|
|
149
|
+
this.handlePong(msg);
|
|
150
|
+
break;
|
|
151
|
+
case "error":
|
|
152
|
+
this.handleError(msg);
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
} catch (error) {
|
|
156
|
+
this.logger.error("Failed to handle message", error);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
handleAck(msg) {
|
|
160
|
+
const payload = msg.payload;
|
|
161
|
+
if (payload.nodeId && !this.nodeId) {
|
|
162
|
+
this.nodeId = payload.nodeId;
|
|
163
|
+
this.events.registered?.(payload.nodeId, payload.name);
|
|
164
|
+
this.startPingInterval();
|
|
165
|
+
}
|
|
166
|
+
if (payload.groupId && payload.groupName) this.events.joinedGroup?.(payload.groupId, payload.groupName);
|
|
167
|
+
if (msg.groupId && !payload.groupName) this.events.leftGroup?.(msg.groupId);
|
|
168
|
+
}
|
|
169
|
+
handleBroadcast(msg) {
|
|
170
|
+
if (msg.nodeId && msg.groupId) this.events.broadcast?.(msg.payload, msg.nodeId, msg.groupId);
|
|
171
|
+
}
|
|
172
|
+
handleDirect(msg) {
|
|
173
|
+
if (msg.nodeId) this.events.direct?.(msg.payload, msg.nodeId);
|
|
174
|
+
}
|
|
175
|
+
handlePing(msg) {
|
|
176
|
+
this.send({
|
|
177
|
+
type: "pong",
|
|
178
|
+
nodeId: this.nodeId || void 0,
|
|
179
|
+
timestamp: Date.now()
|
|
180
|
+
});
|
|
181
|
+
this.events.ping?.();
|
|
182
|
+
}
|
|
183
|
+
handlePong(msg) {
|
|
184
|
+
this.events.pong?.();
|
|
185
|
+
}
|
|
186
|
+
handleError(msg) {
|
|
187
|
+
const error = msg.payload;
|
|
188
|
+
this.events.error?.(error);
|
|
189
|
+
this.logger.error(`Gateway error: ${error.code} - ${error.message}`);
|
|
190
|
+
}
|
|
191
|
+
handleDisconnect() {
|
|
192
|
+
if (this.pingInterval) {
|
|
193
|
+
clearInterval(this.pingInterval);
|
|
194
|
+
this.pingInterval = null;
|
|
195
|
+
}
|
|
196
|
+
this.events.disconnected?.();
|
|
197
|
+
if (this.reconnectAttempts < this.maxReconnectAttempts) {
|
|
198
|
+
this.reconnectAttempts++;
|
|
199
|
+
const delay = this.reconnectDelay * this.reconnectAttempts;
|
|
200
|
+
this.logger.info(`Reconnecting in ${delay}ms (attempt ${this.reconnectAttempts}/${this.maxReconnectAttempts})`);
|
|
201
|
+
setTimeout(()=>this.connect(), delay);
|
|
202
|
+
} else this.logger.error("Max reconnection attempts reached");
|
|
203
|
+
}
|
|
204
|
+
startPingInterval() {
|
|
205
|
+
if (this.pingInterval) clearInterval(this.pingInterval);
|
|
206
|
+
this.pingInterval = setInterval(()=>{
|
|
207
|
+
this.ping();
|
|
208
|
+
}, 30000);
|
|
209
|
+
}
|
|
210
|
+
send(message) {
|
|
211
|
+
if (this.transport && this.transport.isConnected()) return void this.transport.send(message);
|
|
212
|
+
if (this.ws && this.ws.readyState === WebSocket.OPEN) return void this.ws.send(JSON.stringify(message));
|
|
213
|
+
this.logger.error("No transport is connected");
|
|
214
|
+
}
|
|
215
|
+
getNodeId() {
|
|
216
|
+
return this.nodeId;
|
|
217
|
+
}
|
|
218
|
+
getNodeName() {
|
|
219
|
+
return this.nodeName;
|
|
220
|
+
}
|
|
221
|
+
isConnected() {
|
|
222
|
+
return null !== this.ws && this.ws.readyState === WebSocket.OPEN;
|
|
223
|
+
}
|
|
224
|
+
constructor(url, name, options = {}){
|
|
225
|
+
_define_property(this, "url", void 0);
|
|
226
|
+
_define_property(this, "transport", null);
|
|
227
|
+
_define_property(this, "nodeId", null);
|
|
228
|
+
_define_property(this, "nodeName", void 0);
|
|
229
|
+
_define_property(this, "token", void 0);
|
|
230
|
+
_define_property(this, "capabilities", void 0);
|
|
231
|
+
_define_property(this, "events", void 0);
|
|
232
|
+
_define_property(this, "reconnectAttempts", 0);
|
|
233
|
+
_define_property(this, "maxReconnectAttempts", 5);
|
|
234
|
+
_define_property(this, "reconnectDelay", 1000);
|
|
235
|
+
_define_property(this, "pingInterval", null);
|
|
236
|
+
_define_property(this, "transportType", void 0);
|
|
237
|
+
_define_property(this, "logger", void 0);
|
|
238
|
+
_define_property(this, "ws", null);
|
|
239
|
+
this.url = url;
|
|
240
|
+
this.nodeName = name;
|
|
241
|
+
this.token = options.token;
|
|
242
|
+
this.capabilities = options.capabilities;
|
|
243
|
+
this.events = options.events || {};
|
|
244
|
+
this.transportType = options.transport || "auto";
|
|
245
|
+
this.logger = createLogger();
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
export { GatewayClient };
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
GatewayDaemon: ()=>GatewayDaemon
|
|
28
|
+
});
|
|
29
|
+
const external_child_process_namespaceObject = require("child_process");
|
|
30
|
+
const external_fs_namespaceObject = require("fs");
|
|
31
|
+
const external_path_namespaceObject = require("path");
|
|
32
|
+
const external_os_namespaceObject = require("os");
|
|
33
|
+
const external_logger_cjs_namespaceObject = require("../logger.cjs");
|
|
34
|
+
function _define_property(obj, key, value) {
|
|
35
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
36
|
+
value: value,
|
|
37
|
+
enumerable: true,
|
|
38
|
+
configurable: true,
|
|
39
|
+
writable: true
|
|
40
|
+
});
|
|
41
|
+
else obj[key] = value;
|
|
42
|
+
return obj;
|
|
43
|
+
}
|
|
44
|
+
class GatewayDaemon {
|
|
45
|
+
resolveRuntime() {
|
|
46
|
+
const isBunRuntime = void 0 !== globalThis.Bun;
|
|
47
|
+
if (isBunRuntime) return process.execPath;
|
|
48
|
+
const probe = (0, external_child_process_namespaceObject.spawnSync)("bun", [
|
|
49
|
+
"--version"
|
|
50
|
+
], {
|
|
51
|
+
stdio: "ignore"
|
|
52
|
+
});
|
|
53
|
+
if (probe.error || 0 !== probe.status) throw new Error("Bun runtime is required to start the gateway. Install Bun from https://bun.sh and retry.");
|
|
54
|
+
return "bun";
|
|
55
|
+
}
|
|
56
|
+
async start(config) {
|
|
57
|
+
if (this.isRunning()) throw new Error("Gateway is already running");
|
|
58
|
+
this.saveConfig(config);
|
|
59
|
+
const scriptPath = process.argv[1];
|
|
60
|
+
const runtime = this.resolveRuntime();
|
|
61
|
+
const child = (0, external_child_process_namespaceObject.spawn)(runtime, [
|
|
62
|
+
scriptPath,
|
|
63
|
+
"gateway",
|
|
64
|
+
"run",
|
|
65
|
+
"--daemon"
|
|
66
|
+
], {
|
|
67
|
+
detached: true,
|
|
68
|
+
stdio: [
|
|
69
|
+
"ignore",
|
|
70
|
+
"pipe",
|
|
71
|
+
"pipe"
|
|
72
|
+
],
|
|
73
|
+
env: {
|
|
74
|
+
...process.env,
|
|
75
|
+
WINGMAN_GATEWAY_CONFIG: this.configFile
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
(0, external_fs_namespaceObject.writeFileSync)(this.pidFile, child.pid.toString());
|
|
79
|
+
child.stdout?.on("data", (data)=>{
|
|
80
|
+
(0, external_logger_cjs_namespaceObject.writeToLogFile)(data);
|
|
81
|
+
});
|
|
82
|
+
child.stderr?.on("data", (data)=>{
|
|
83
|
+
(0, external_logger_cjs_namespaceObject.writeToLogFile)(data);
|
|
84
|
+
});
|
|
85
|
+
child.unref();
|
|
86
|
+
console.log(`Gateway daemon started with PID ${child.pid}`);
|
|
87
|
+
console.log(`Logs: ${this.logFile}`);
|
|
88
|
+
}
|
|
89
|
+
async stop() {
|
|
90
|
+
if (!this.isRunning()) throw new Error("Gateway is not running");
|
|
91
|
+
const pid = this.getPid();
|
|
92
|
+
if (!pid) throw new Error("Could not read PID file");
|
|
93
|
+
try {
|
|
94
|
+
process.kill(pid, "SIGTERM");
|
|
95
|
+
await new Promise((resolve)=>setTimeout(resolve, 2000));
|
|
96
|
+
if (this.isProcessRunning(pid)) process.kill(pid, "SIGKILL");
|
|
97
|
+
this.removePidFile();
|
|
98
|
+
console.log("Gateway daemon stopped");
|
|
99
|
+
} catch (error) {
|
|
100
|
+
this.removePidFile();
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async restart() {
|
|
105
|
+
const config = this.loadConfig();
|
|
106
|
+
if (!config) throw new Error("No saved configuration found");
|
|
107
|
+
if (this.isRunning()) await this.stop();
|
|
108
|
+
await this.start(config);
|
|
109
|
+
}
|
|
110
|
+
getStatus() {
|
|
111
|
+
const running = this.isRunning();
|
|
112
|
+
const pid = this.getPid();
|
|
113
|
+
const config = this.loadConfig();
|
|
114
|
+
if (!running) return {
|
|
115
|
+
running: false
|
|
116
|
+
};
|
|
117
|
+
const uptime = pid ? this.getProcessUptime(pid) : void 0;
|
|
118
|
+
return {
|
|
119
|
+
running: true,
|
|
120
|
+
pid,
|
|
121
|
+
uptime,
|
|
122
|
+
config
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
isRunning() {
|
|
126
|
+
const pid = this.getPid();
|
|
127
|
+
if (!pid) return false;
|
|
128
|
+
return this.isProcessRunning(pid);
|
|
129
|
+
}
|
|
130
|
+
getPid() {
|
|
131
|
+
if (!(0, external_fs_namespaceObject.existsSync)(this.pidFile)) return;
|
|
132
|
+
try {
|
|
133
|
+
const pidStr = (0, external_fs_namespaceObject.readFileSync)(this.pidFile, "utf-8").trim();
|
|
134
|
+
return parseInt(pidStr, 10);
|
|
135
|
+
} catch (error) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
isProcessRunning(pid) {
|
|
140
|
+
try {
|
|
141
|
+
process.kill(pid, 0);
|
|
142
|
+
return true;
|
|
143
|
+
} catch (error) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
getProcessUptime(pid) {
|
|
148
|
+
try {
|
|
149
|
+
const pidFileStats = (0, external_fs_namespaceObject.statSync)(this.pidFile);
|
|
150
|
+
return Date.now() - pidFileStats.mtimeMs;
|
|
151
|
+
} catch (error) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
removePidFile() {
|
|
156
|
+
if ((0, external_fs_namespaceObject.existsSync)(this.pidFile)) (0, external_fs_namespaceObject.unlinkSync)(this.pidFile);
|
|
157
|
+
}
|
|
158
|
+
saveConfig(config) {
|
|
159
|
+
(0, external_fs_namespaceObject.writeFileSync)(this.configFile, JSON.stringify(config, null, 2));
|
|
160
|
+
}
|
|
161
|
+
loadConfig() {
|
|
162
|
+
if (!(0, external_fs_namespaceObject.existsSync)(this.configFile)) return;
|
|
163
|
+
try {
|
|
164
|
+
const configStr = (0, external_fs_namespaceObject.readFileSync)(this.configFile, "utf-8");
|
|
165
|
+
return JSON.parse(configStr);
|
|
166
|
+
} catch (error) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
getLogFile() {
|
|
171
|
+
return this.logFile;
|
|
172
|
+
}
|
|
173
|
+
getPidFile() {
|
|
174
|
+
return this.pidFile;
|
|
175
|
+
}
|
|
176
|
+
getConfigFile() {
|
|
177
|
+
return this.configFile;
|
|
178
|
+
}
|
|
179
|
+
constructor(){
|
|
180
|
+
_define_property(this, "pidFile", void 0);
|
|
181
|
+
_define_property(this, "logFile", void 0);
|
|
182
|
+
_define_property(this, "configFile", void 0);
|
|
183
|
+
const wingmanDir = (0, external_path_namespaceObject.join)((0, external_os_namespaceObject.homedir)(), ".wingman");
|
|
184
|
+
this.pidFile = (0, external_path_namespaceObject.join)(wingmanDir, "gateway.pid");
|
|
185
|
+
this.logFile = (0, external_logger_cjs_namespaceObject.getLogFilePath)();
|
|
186
|
+
this.configFile = (0, external_path_namespaceObject.join)(wingmanDir, "gateway.json");
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
exports.GatewayDaemon = __webpack_exports__.GatewayDaemon;
|
|
190
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
191
|
+
"GatewayDaemon"
|
|
192
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
193
|
+
Object.defineProperty(exports, '__esModule', {
|
|
194
|
+
value: true
|
|
195
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { GatewayConfig, DaemonStatus } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Daemon manager for running the gateway in the background
|
|
4
|
+
*/
|
|
5
|
+
export declare class GatewayDaemon {
|
|
6
|
+
private pidFile;
|
|
7
|
+
private logFile;
|
|
8
|
+
private configFile;
|
|
9
|
+
constructor();
|
|
10
|
+
private resolveRuntime;
|
|
11
|
+
/**
|
|
12
|
+
* Start the gateway as a daemon
|
|
13
|
+
*/
|
|
14
|
+
start(config: GatewayConfig): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Stop the gateway daemon
|
|
17
|
+
*/
|
|
18
|
+
stop(): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Restart the gateway daemon
|
|
21
|
+
*/
|
|
22
|
+
restart(): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Get the status of the gateway daemon
|
|
25
|
+
*/
|
|
26
|
+
getStatus(): DaemonStatus;
|
|
27
|
+
/**
|
|
28
|
+
* Check if the gateway is running
|
|
29
|
+
*/
|
|
30
|
+
isRunning(): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Get the PID from the PID file
|
|
33
|
+
*/
|
|
34
|
+
private getPid;
|
|
35
|
+
/**
|
|
36
|
+
* Check if a process is running
|
|
37
|
+
*/
|
|
38
|
+
private isProcessRunning;
|
|
39
|
+
/**
|
|
40
|
+
* Get process uptime in milliseconds
|
|
41
|
+
*/
|
|
42
|
+
private getProcessUptime;
|
|
43
|
+
/**
|
|
44
|
+
* Remove the PID file
|
|
45
|
+
*/
|
|
46
|
+
private removePidFile;
|
|
47
|
+
/**
|
|
48
|
+
* Save gateway configuration
|
|
49
|
+
*/
|
|
50
|
+
private saveConfig;
|
|
51
|
+
/**
|
|
52
|
+
* Load gateway configuration
|
|
53
|
+
*/
|
|
54
|
+
private loadConfig;
|
|
55
|
+
/**
|
|
56
|
+
* Get the log file path
|
|
57
|
+
*/
|
|
58
|
+
getLogFile(): string;
|
|
59
|
+
/**
|
|
60
|
+
* Get the PID file path
|
|
61
|
+
*/
|
|
62
|
+
getPidFile(): string;
|
|
63
|
+
/**
|
|
64
|
+
* Get the config file path
|
|
65
|
+
*/
|
|
66
|
+
getConfigFile(): string;
|
|
67
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { spawn, spawnSync } from "child_process";
|
|
2
|
+
import { existsSync, readFileSync, statSync, unlinkSync, writeFileSync } from "fs";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
import { homedir } from "os";
|
|
5
|
+
import { getLogFilePath, writeToLogFile } from "../logger.js";
|
|
6
|
+
function _define_property(obj, key, value) {
|
|
7
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
8
|
+
value: value,
|
|
9
|
+
enumerable: true,
|
|
10
|
+
configurable: true,
|
|
11
|
+
writable: true
|
|
12
|
+
});
|
|
13
|
+
else obj[key] = value;
|
|
14
|
+
return obj;
|
|
15
|
+
}
|
|
16
|
+
class GatewayDaemon {
|
|
17
|
+
resolveRuntime() {
|
|
18
|
+
const isBunRuntime = void 0 !== globalThis.Bun;
|
|
19
|
+
if (isBunRuntime) return process.execPath;
|
|
20
|
+
const probe = spawnSync("bun", [
|
|
21
|
+
"--version"
|
|
22
|
+
], {
|
|
23
|
+
stdio: "ignore"
|
|
24
|
+
});
|
|
25
|
+
if (probe.error || 0 !== probe.status) throw new Error("Bun runtime is required to start the gateway. Install Bun from https://bun.sh and retry.");
|
|
26
|
+
return "bun";
|
|
27
|
+
}
|
|
28
|
+
async start(config) {
|
|
29
|
+
if (this.isRunning()) throw new Error("Gateway is already running");
|
|
30
|
+
this.saveConfig(config);
|
|
31
|
+
const scriptPath = process.argv[1];
|
|
32
|
+
const runtime = this.resolveRuntime();
|
|
33
|
+
const child = spawn(runtime, [
|
|
34
|
+
scriptPath,
|
|
35
|
+
"gateway",
|
|
36
|
+
"run",
|
|
37
|
+
"--daemon"
|
|
38
|
+
], {
|
|
39
|
+
detached: true,
|
|
40
|
+
stdio: [
|
|
41
|
+
"ignore",
|
|
42
|
+
"pipe",
|
|
43
|
+
"pipe"
|
|
44
|
+
],
|
|
45
|
+
env: {
|
|
46
|
+
...process.env,
|
|
47
|
+
WINGMAN_GATEWAY_CONFIG: this.configFile
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
writeFileSync(this.pidFile, child.pid.toString());
|
|
51
|
+
child.stdout?.on("data", (data)=>{
|
|
52
|
+
writeToLogFile(data);
|
|
53
|
+
});
|
|
54
|
+
child.stderr?.on("data", (data)=>{
|
|
55
|
+
writeToLogFile(data);
|
|
56
|
+
});
|
|
57
|
+
child.unref();
|
|
58
|
+
console.log(`Gateway daemon started with PID ${child.pid}`);
|
|
59
|
+
console.log(`Logs: ${this.logFile}`);
|
|
60
|
+
}
|
|
61
|
+
async stop() {
|
|
62
|
+
if (!this.isRunning()) throw new Error("Gateway is not running");
|
|
63
|
+
const pid = this.getPid();
|
|
64
|
+
if (!pid) throw new Error("Could not read PID file");
|
|
65
|
+
try {
|
|
66
|
+
process.kill(pid, "SIGTERM");
|
|
67
|
+
await new Promise((resolve)=>setTimeout(resolve, 2000));
|
|
68
|
+
if (this.isProcessRunning(pid)) process.kill(pid, "SIGKILL");
|
|
69
|
+
this.removePidFile();
|
|
70
|
+
console.log("Gateway daemon stopped");
|
|
71
|
+
} catch (error) {
|
|
72
|
+
this.removePidFile();
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async restart() {
|
|
77
|
+
const config = this.loadConfig();
|
|
78
|
+
if (!config) throw new Error("No saved configuration found");
|
|
79
|
+
if (this.isRunning()) await this.stop();
|
|
80
|
+
await this.start(config);
|
|
81
|
+
}
|
|
82
|
+
getStatus() {
|
|
83
|
+
const running = this.isRunning();
|
|
84
|
+
const pid = this.getPid();
|
|
85
|
+
const config = this.loadConfig();
|
|
86
|
+
if (!running) return {
|
|
87
|
+
running: false
|
|
88
|
+
};
|
|
89
|
+
const uptime = pid ? this.getProcessUptime(pid) : void 0;
|
|
90
|
+
return {
|
|
91
|
+
running: true,
|
|
92
|
+
pid,
|
|
93
|
+
uptime,
|
|
94
|
+
config
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
isRunning() {
|
|
98
|
+
const pid = this.getPid();
|
|
99
|
+
if (!pid) return false;
|
|
100
|
+
return this.isProcessRunning(pid);
|
|
101
|
+
}
|
|
102
|
+
getPid() {
|
|
103
|
+
if (!existsSync(this.pidFile)) return;
|
|
104
|
+
try {
|
|
105
|
+
const pidStr = readFileSync(this.pidFile, "utf-8").trim();
|
|
106
|
+
return parseInt(pidStr, 10);
|
|
107
|
+
} catch (error) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
isProcessRunning(pid) {
|
|
112
|
+
try {
|
|
113
|
+
process.kill(pid, 0);
|
|
114
|
+
return true;
|
|
115
|
+
} catch (error) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
getProcessUptime(pid) {
|
|
120
|
+
try {
|
|
121
|
+
const pidFileStats = statSync(this.pidFile);
|
|
122
|
+
return Date.now() - pidFileStats.mtimeMs;
|
|
123
|
+
} catch (error) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
removePidFile() {
|
|
128
|
+
if (existsSync(this.pidFile)) unlinkSync(this.pidFile);
|
|
129
|
+
}
|
|
130
|
+
saveConfig(config) {
|
|
131
|
+
writeFileSync(this.configFile, JSON.stringify(config, null, 2));
|
|
132
|
+
}
|
|
133
|
+
loadConfig() {
|
|
134
|
+
if (!existsSync(this.configFile)) return;
|
|
135
|
+
try {
|
|
136
|
+
const configStr = readFileSync(this.configFile, "utf-8");
|
|
137
|
+
return JSON.parse(configStr);
|
|
138
|
+
} catch (error) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
getLogFile() {
|
|
143
|
+
return this.logFile;
|
|
144
|
+
}
|
|
145
|
+
getPidFile() {
|
|
146
|
+
return this.pidFile;
|
|
147
|
+
}
|
|
148
|
+
getConfigFile() {
|
|
149
|
+
return this.configFile;
|
|
150
|
+
}
|
|
151
|
+
constructor(){
|
|
152
|
+
_define_property(this, "pidFile", void 0);
|
|
153
|
+
_define_property(this, "logFile", void 0);
|
|
154
|
+
_define_property(this, "configFile", void 0);
|
|
155
|
+
const wingmanDir = join(homedir(), ".wingman");
|
|
156
|
+
this.pidFile = join(wingmanDir, "gateway.pid");
|
|
157
|
+
this.logFile = getLogFilePath();
|
|
158
|
+
this.configFile = join(wingmanDir, "gateway.json");
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
export { GatewayDaemon };
|