@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
package/dist/logger.js
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { appendFileSync, existsSync, mkdirSync, renameSync, statSync, unlinkSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
function _define_property(obj, key, value) {
|
|
5
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
6
|
+
value: value,
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
writable: true
|
|
10
|
+
});
|
|
11
|
+
else obj[key] = value;
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
const DEFAULT_LOG_FILE_NAME = "wingman.log";
|
|
15
|
+
const DEFAULT_LOG_DIR = join(homedir(), ".wingman", "logs");
|
|
16
|
+
const DEFAULT_MAX_BYTES = parsePositiveInt(process.env.WINGMAN_LOG_MAX_BYTES, 5242880);
|
|
17
|
+
const DEFAULT_MAX_FILES = parsePositiveInt(process.env.WINGMAN_LOG_MAX_FILES, 5);
|
|
18
|
+
function serializeLogArg(arg) {
|
|
19
|
+
const isError = "function" == typeof Error.isError ? Error.isError(arg) : arg instanceof Error;
|
|
20
|
+
if (isError) return {
|
|
21
|
+
name: arg.name,
|
|
22
|
+
message: arg.message,
|
|
23
|
+
stack: arg.stack
|
|
24
|
+
};
|
|
25
|
+
return arg;
|
|
26
|
+
}
|
|
27
|
+
function parsePositiveInt(value, fallback) {
|
|
28
|
+
if (!value) return fallback;
|
|
29
|
+
const parsed = Number.parseInt(value, 10);
|
|
30
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
|
|
31
|
+
}
|
|
32
|
+
function resolveDefaultLogFileName() {
|
|
33
|
+
const isoDate = new Date().toISOString().slice(0, 10);
|
|
34
|
+
return `wingman-${isoDate}.log`;
|
|
35
|
+
}
|
|
36
|
+
function resolveLogFilePath() {
|
|
37
|
+
const explicitFile = process.env.WINGMAN_LOG_FILE;
|
|
38
|
+
if (explicitFile && explicitFile.trim().length > 0) return explicitFile;
|
|
39
|
+
const logDir = process.env.WINGMAN_LOG_DIR?.trim() || DEFAULT_LOG_DIR;
|
|
40
|
+
return join(logDir, resolveDefaultLogFileName() || DEFAULT_LOG_FILE_NAME);
|
|
41
|
+
}
|
|
42
|
+
function getLogFilePath() {
|
|
43
|
+
return resolveLogFilePath();
|
|
44
|
+
}
|
|
45
|
+
function writeToLogFile(chunk) {
|
|
46
|
+
const text = "string" == typeof chunk ? chunk : chunk.toString("utf-8");
|
|
47
|
+
getSharedFileWriter().write(text);
|
|
48
|
+
}
|
|
49
|
+
class RollingFileWriter {
|
|
50
|
+
write(chunk) {
|
|
51
|
+
try {
|
|
52
|
+
this.ensureInitialized();
|
|
53
|
+
const bytes = Buffer.byteLength(chunk);
|
|
54
|
+
if (this.currentSize + bytes > this.maxBytes) {
|
|
55
|
+
this.rotate();
|
|
56
|
+
this.currentSize = 0;
|
|
57
|
+
}
|
|
58
|
+
appendFileSync(this.filePath, chunk);
|
|
59
|
+
this.currentSize += bytes;
|
|
60
|
+
} catch {}
|
|
61
|
+
}
|
|
62
|
+
ensureInitialized() {
|
|
63
|
+
if (this.initialized) return;
|
|
64
|
+
this.initialized = true;
|
|
65
|
+
mkdirSync(dirname(this.filePath), {
|
|
66
|
+
recursive: true
|
|
67
|
+
});
|
|
68
|
+
if (existsSync(this.filePath)) this.currentSize = statSync(this.filePath).size;
|
|
69
|
+
}
|
|
70
|
+
rotate() {
|
|
71
|
+
try {
|
|
72
|
+
const oldest = `${this.filePath}.${this.maxFiles}`;
|
|
73
|
+
if (existsSync(oldest)) unlinkSync(oldest);
|
|
74
|
+
for(let i = this.maxFiles - 1; i >= 1; i--){
|
|
75
|
+
const source = `${this.filePath}.${i}`;
|
|
76
|
+
if (existsSync(source)) renameSync(source, `${this.filePath}.${i + 1}`);
|
|
77
|
+
}
|
|
78
|
+
if (existsSync(this.filePath)) renameSync(this.filePath, `${this.filePath}.1`);
|
|
79
|
+
} catch {}
|
|
80
|
+
}
|
|
81
|
+
constructor(filePath, maxBytes, maxFiles){
|
|
82
|
+
_define_property(this, "currentSize", 0);
|
|
83
|
+
_define_property(this, "initialized", false);
|
|
84
|
+
_define_property(this, "filePath", void 0);
|
|
85
|
+
_define_property(this, "maxBytes", void 0);
|
|
86
|
+
_define_property(this, "maxFiles", void 0);
|
|
87
|
+
this.filePath = filePath;
|
|
88
|
+
this.maxBytes = Math.max(1, maxBytes);
|
|
89
|
+
this.maxFiles = Math.max(1, maxFiles);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
let sharedFileWriter = null;
|
|
93
|
+
function getSharedFileWriter() {
|
|
94
|
+
if (!sharedFileWriter) sharedFileWriter = new RollingFileWriter(resolveLogFilePath(), DEFAULT_MAX_BYTES, DEFAULT_MAX_FILES);
|
|
95
|
+
return sharedFileWriter;
|
|
96
|
+
}
|
|
97
|
+
class WingmanLogger {
|
|
98
|
+
shouldLog(level) {
|
|
99
|
+
const levels = [
|
|
100
|
+
"debug",
|
|
101
|
+
"info",
|
|
102
|
+
"warn",
|
|
103
|
+
"error",
|
|
104
|
+
"silent"
|
|
105
|
+
];
|
|
106
|
+
const currentIndex = levels.indexOf(this.level);
|
|
107
|
+
const messageIndex = levels.indexOf(level);
|
|
108
|
+
return "silent" !== this.level && messageIndex >= currentIndex;
|
|
109
|
+
}
|
|
110
|
+
log(level, message, ...args) {
|
|
111
|
+
if (!this.shouldLog(level)) return;
|
|
112
|
+
const timestamp = new Date().toISOString();
|
|
113
|
+
const prefix = `[${timestamp}] [${level.toUpperCase()}]`;
|
|
114
|
+
this.output.write(`${prefix} ${message}\n`);
|
|
115
|
+
if (args.length > 0) {
|
|
116
|
+
const serialized = args.map((arg)=>serializeLogArg(arg));
|
|
117
|
+
this.output.write(`${JSON.stringify(serialized, null, 2)}\n`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
debug(message, ...args) {
|
|
121
|
+
this.log("debug", message, ...args);
|
|
122
|
+
}
|
|
123
|
+
info(message, ...args) {
|
|
124
|
+
this.log("info", message, ...args);
|
|
125
|
+
}
|
|
126
|
+
warn(message, ...args) {
|
|
127
|
+
this.log("warn", message, ...args);
|
|
128
|
+
}
|
|
129
|
+
error(message, ...args) {
|
|
130
|
+
this.log("error", message, ...args);
|
|
131
|
+
}
|
|
132
|
+
constructor(level = "info", output = getSharedFileWriter()){
|
|
133
|
+
_define_property(this, "level", void 0);
|
|
134
|
+
_define_property(this, "output", void 0);
|
|
135
|
+
this.level = level;
|
|
136
|
+
this.output = output;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
class SilentLogger {
|
|
140
|
+
debug() {}
|
|
141
|
+
info() {}
|
|
142
|
+
warn() {}
|
|
143
|
+
error() {}
|
|
144
|
+
}
|
|
145
|
+
function createLogger(level = process.env.WINGMAN_LOG_LEVEL || "info") {
|
|
146
|
+
if ("silent" === level) return new SilentLogger();
|
|
147
|
+
return new WingmanLogger(level);
|
|
148
|
+
}
|
|
149
|
+
function createLoggerFromConfig(config) {
|
|
150
|
+
return createLogger(config.level);
|
|
151
|
+
}
|
|
152
|
+
class EventLogger {
|
|
153
|
+
shouldLog(level) {
|
|
154
|
+
const levels = [
|
|
155
|
+
"debug",
|
|
156
|
+
"info",
|
|
157
|
+
"warn",
|
|
158
|
+
"error",
|
|
159
|
+
"silent"
|
|
160
|
+
];
|
|
161
|
+
const currentIndex = levels.indexOf(this.level);
|
|
162
|
+
const messageIndex = levels.indexOf(level);
|
|
163
|
+
return "silent" !== this.level && messageIndex >= currentIndex;
|
|
164
|
+
}
|
|
165
|
+
log(level, message, ...args) {
|
|
166
|
+
if (!this.shouldLog(level)) return;
|
|
167
|
+
this.callback({
|
|
168
|
+
level,
|
|
169
|
+
message,
|
|
170
|
+
timestamp: new Date().toISOString(),
|
|
171
|
+
args: args.length > 0 ? args : void 0
|
|
172
|
+
});
|
|
173
|
+
if (!this.secondaryLogger) return;
|
|
174
|
+
switch(level){
|
|
175
|
+
case "debug":
|
|
176
|
+
this.secondaryLogger.debug(message, ...args);
|
|
177
|
+
break;
|
|
178
|
+
case "info":
|
|
179
|
+
this.secondaryLogger.info(message, ...args);
|
|
180
|
+
break;
|
|
181
|
+
case "warn":
|
|
182
|
+
this.secondaryLogger.warn(message, ...args);
|
|
183
|
+
break;
|
|
184
|
+
case "error":
|
|
185
|
+
this.secondaryLogger.error(message, ...args);
|
|
186
|
+
break;
|
|
187
|
+
case "silent":
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
debug(message, ...args) {
|
|
192
|
+
this.log("debug", message, ...args);
|
|
193
|
+
}
|
|
194
|
+
info(message, ...args) {
|
|
195
|
+
this.log("info", message, ...args);
|
|
196
|
+
}
|
|
197
|
+
warn(message, ...args) {
|
|
198
|
+
this.log("warn", message, ...args);
|
|
199
|
+
}
|
|
200
|
+
error(message, ...args) {
|
|
201
|
+
this.log("error", message, ...args);
|
|
202
|
+
}
|
|
203
|
+
constructor(callback, level = "info", secondaryLogger){
|
|
204
|
+
_define_property(this, "callback", void 0);
|
|
205
|
+
_define_property(this, "level", void 0);
|
|
206
|
+
_define_property(this, "secondaryLogger", void 0);
|
|
207
|
+
this.callback = callback;
|
|
208
|
+
this.level = level;
|
|
209
|
+
this.secondaryLogger = secondaryLogger;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
function createEventLogger(callback, level = "info") {
|
|
213
|
+
return new EventLogger(callback, level, createLogger(level));
|
|
214
|
+
}
|
|
215
|
+
export { EventLogger, SilentLogger, WingmanLogger, createEventLogger, createLogger, createLoggerFromConfig, getLogFilePath, writeToLogFile };
|
|
@@ -0,0 +1,148 @@
|
|
|
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
|
+
createCopilotFetch: ()=>createCopilotFetch
|
|
28
|
+
});
|
|
29
|
+
const external_credentials_cjs_namespaceObject = require("./credentials.cjs");
|
|
30
|
+
const external_registry_cjs_namespaceObject = require("./registry.cjs");
|
|
31
|
+
const COPILOT_HEADERS = {
|
|
32
|
+
"User-Agent": "GitHubCopilotChat/0.35.0",
|
|
33
|
+
"Editor-Version": "vscode/1.107.0",
|
|
34
|
+
"Editor-Plugin-Version": "copilot-chat/0.35.0",
|
|
35
|
+
"Copilot-Integration-Id": "vscode-chat"
|
|
36
|
+
};
|
|
37
|
+
const RESPONSES_API_ALTERNATE_INPUT_TYPES = new Set([
|
|
38
|
+
"file_search_call",
|
|
39
|
+
"computer_call",
|
|
40
|
+
"computer_call_output",
|
|
41
|
+
"web_search_call",
|
|
42
|
+
"function_call",
|
|
43
|
+
"function_call_output",
|
|
44
|
+
"image_generation_call",
|
|
45
|
+
"code_interpreter_call",
|
|
46
|
+
"local_shell_call",
|
|
47
|
+
"local_shell_call_output",
|
|
48
|
+
"mcp_list_tools",
|
|
49
|
+
"mcp_approval_request",
|
|
50
|
+
"mcp_approval_response",
|
|
51
|
+
"mcp_call",
|
|
52
|
+
"reasoning"
|
|
53
|
+
]);
|
|
54
|
+
const REFRESH_BUFFER_MS = 300000;
|
|
55
|
+
function createCopilotFetch() {
|
|
56
|
+
const baseFetch = globalThis.fetch.bind(globalThis);
|
|
57
|
+
return async (input, init)=>{
|
|
58
|
+
const accessToken = await resolveCopilotAccessToken(baseFetch);
|
|
59
|
+
const { isAgentCall, isVisionRequest } = inspectRequest(init?.body);
|
|
60
|
+
const headers = new Headers(init?.headers || {});
|
|
61
|
+
headers.delete("authorization");
|
|
62
|
+
headers.delete("x-api-key");
|
|
63
|
+
for (const [key, value] of Object.entries(COPILOT_HEADERS))headers.set(key, value);
|
|
64
|
+
headers.set("Authorization", `Bearer ${accessToken}`);
|
|
65
|
+
headers.set("Openai-Intent", "conversation-edits");
|
|
66
|
+
headers.set("X-Initiator", isAgentCall ? "agent" : "user");
|
|
67
|
+
if (isVisionRequest) headers.set("Copilot-Vision-Request", "true");
|
|
68
|
+
return baseFetch(input, {
|
|
69
|
+
...init,
|
|
70
|
+
headers
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
async function resolveCopilotAccessToken(baseFetch) {
|
|
75
|
+
const provider = (0, external_registry_cjs_namespaceObject.getProviderSpec)("copilot");
|
|
76
|
+
const credentials = (0, external_credentials_cjs_namespaceObject.getProviderCredentials)("copilot");
|
|
77
|
+
const envToken = (0, external_credentials_cjs_namespaceObject.resolveProviderToken)("copilot").token;
|
|
78
|
+
const refreshToken = credentials?.refreshToken || credentials?.accessToken || credentials?.apiKey || envToken;
|
|
79
|
+
if (!refreshToken) throw new Error("Copilot credentials missing. Run `wingman provider login copilot`.");
|
|
80
|
+
const expiresAt = credentials?.expiresAt ? Date.parse(credentials.expiresAt) : void 0;
|
|
81
|
+
const hasValidAccessToken = Boolean(credentials?.accessToken) && (!expiresAt || expiresAt > Date.now() + REFRESH_BUFFER_MS);
|
|
82
|
+
if (hasValidAccessToken && credentials?.accessToken) return credentials.accessToken;
|
|
83
|
+
const tokenUrl = buildCopilotTokenUrl(provider?.baseURL);
|
|
84
|
+
const response = await baseFetch(tokenUrl, {
|
|
85
|
+
headers: {
|
|
86
|
+
Accept: "application/json",
|
|
87
|
+
Authorization: `Bearer ${refreshToken}`,
|
|
88
|
+
...COPILOT_HEADERS
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
if (!response.ok) throw new Error(`Copilot token refresh failed: ${response.status}`);
|
|
92
|
+
const tokenData = await response.json();
|
|
93
|
+
if (!tokenData.token) throw new Error("Copilot token refresh failed: missing token.");
|
|
94
|
+
const expiresAtIso = computeExpiry(tokenData);
|
|
95
|
+
(0, external_credentials_cjs_namespaceObject.setProviderCredentials)("copilot", {
|
|
96
|
+
accessToken: tokenData.token,
|
|
97
|
+
expiresAt: expiresAtIso
|
|
98
|
+
});
|
|
99
|
+
return tokenData.token;
|
|
100
|
+
}
|
|
101
|
+
function buildCopilotTokenUrl(baseURL) {
|
|
102
|
+
const fallback = "https://api.githubcopilot.com";
|
|
103
|
+
const root = baseURL || fallback;
|
|
104
|
+
return new URL("/copilot_internal/v2/token", root).toString();
|
|
105
|
+
}
|
|
106
|
+
function computeExpiry(tokenData) {
|
|
107
|
+
if (tokenData.expires_at) return new Date(1000 * tokenData.expires_at - REFRESH_BUFFER_MS).toISOString();
|
|
108
|
+
if (tokenData.expires_in) return new Date(Date.now() + 1000 * tokenData.expires_in - REFRESH_BUFFER_MS).toISOString();
|
|
109
|
+
}
|
|
110
|
+
function inspectRequest(body) {
|
|
111
|
+
let isAgentCall = false;
|
|
112
|
+
let isVisionRequest = false;
|
|
113
|
+
if (!body || "string" != typeof body) return {
|
|
114
|
+
isAgentCall,
|
|
115
|
+
isVisionRequest
|
|
116
|
+
};
|
|
117
|
+
try {
|
|
118
|
+
const parsed = JSON.parse(body);
|
|
119
|
+
if (parsed?.messages) {
|
|
120
|
+
if (parsed.messages.length > 0) {
|
|
121
|
+
const lastMessage = parsed.messages[parsed.messages.length - 1];
|
|
122
|
+
isAgentCall = lastMessage?.role && [
|
|
123
|
+
"tool",
|
|
124
|
+
"assistant"
|
|
125
|
+
].includes(lastMessage.role);
|
|
126
|
+
}
|
|
127
|
+
isVisionRequest = parsed.messages.some((message)=>Array.isArray(message?.content) && message.content.some((part)=>part?.type === "image_url"));
|
|
128
|
+
}
|
|
129
|
+
if (parsed?.input) {
|
|
130
|
+
const lastInput = parsed.input[parsed.input.length - 1];
|
|
131
|
+
const isAssistant = lastInput?.role === "assistant";
|
|
132
|
+
const hasAgentType = lastInput?.type ? RESPONSES_API_ALTERNATE_INPUT_TYPES.has(lastInput.type) : false;
|
|
133
|
+
isAgentCall = isAssistant || hasAgentType;
|
|
134
|
+
isVisionRequest = Array.isArray(lastInput?.content) && lastInput.content.some((part)=>part?.type === "input_image");
|
|
135
|
+
}
|
|
136
|
+
} catch {}
|
|
137
|
+
return {
|
|
138
|
+
isAgentCall,
|
|
139
|
+
isVisionRequest
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
exports.createCopilotFetch = __webpack_exports__.createCopilotFetch;
|
|
143
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
144
|
+
"createCopilotFetch"
|
|
145
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
146
|
+
Object.defineProperty(exports, '__esModule', {
|
|
147
|
+
value: true
|
|
148
|
+
});
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { getProviderCredentials, resolveProviderToken, setProviderCredentials } from "./credentials.js";
|
|
2
|
+
import { getProviderSpec } from "./registry.js";
|
|
3
|
+
const COPILOT_HEADERS = {
|
|
4
|
+
"User-Agent": "GitHubCopilotChat/0.35.0",
|
|
5
|
+
"Editor-Version": "vscode/1.107.0",
|
|
6
|
+
"Editor-Plugin-Version": "copilot-chat/0.35.0",
|
|
7
|
+
"Copilot-Integration-Id": "vscode-chat"
|
|
8
|
+
};
|
|
9
|
+
const RESPONSES_API_ALTERNATE_INPUT_TYPES = new Set([
|
|
10
|
+
"file_search_call",
|
|
11
|
+
"computer_call",
|
|
12
|
+
"computer_call_output",
|
|
13
|
+
"web_search_call",
|
|
14
|
+
"function_call",
|
|
15
|
+
"function_call_output",
|
|
16
|
+
"image_generation_call",
|
|
17
|
+
"code_interpreter_call",
|
|
18
|
+
"local_shell_call",
|
|
19
|
+
"local_shell_call_output",
|
|
20
|
+
"mcp_list_tools",
|
|
21
|
+
"mcp_approval_request",
|
|
22
|
+
"mcp_approval_response",
|
|
23
|
+
"mcp_call",
|
|
24
|
+
"reasoning"
|
|
25
|
+
]);
|
|
26
|
+
const REFRESH_BUFFER_MS = 300000;
|
|
27
|
+
function createCopilotFetch() {
|
|
28
|
+
const baseFetch = globalThis.fetch.bind(globalThis);
|
|
29
|
+
return async (input, init)=>{
|
|
30
|
+
const accessToken = await resolveCopilotAccessToken(baseFetch);
|
|
31
|
+
const { isAgentCall, isVisionRequest } = inspectRequest(init?.body);
|
|
32
|
+
const headers = new Headers(init?.headers || {});
|
|
33
|
+
headers.delete("authorization");
|
|
34
|
+
headers.delete("x-api-key");
|
|
35
|
+
for (const [key, value] of Object.entries(COPILOT_HEADERS))headers.set(key, value);
|
|
36
|
+
headers.set("Authorization", `Bearer ${accessToken}`);
|
|
37
|
+
headers.set("Openai-Intent", "conversation-edits");
|
|
38
|
+
headers.set("X-Initiator", isAgentCall ? "agent" : "user");
|
|
39
|
+
if (isVisionRequest) headers.set("Copilot-Vision-Request", "true");
|
|
40
|
+
return baseFetch(input, {
|
|
41
|
+
...init,
|
|
42
|
+
headers
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
async function resolveCopilotAccessToken(baseFetch) {
|
|
47
|
+
const provider = getProviderSpec("copilot");
|
|
48
|
+
const credentials = getProviderCredentials("copilot");
|
|
49
|
+
const envToken = resolveProviderToken("copilot").token;
|
|
50
|
+
const refreshToken = credentials?.refreshToken || credentials?.accessToken || credentials?.apiKey || envToken;
|
|
51
|
+
if (!refreshToken) throw new Error("Copilot credentials missing. Run `wingman provider login copilot`.");
|
|
52
|
+
const expiresAt = credentials?.expiresAt ? Date.parse(credentials.expiresAt) : void 0;
|
|
53
|
+
const hasValidAccessToken = Boolean(credentials?.accessToken) && (!expiresAt || expiresAt > Date.now() + REFRESH_BUFFER_MS);
|
|
54
|
+
if (hasValidAccessToken && credentials?.accessToken) return credentials.accessToken;
|
|
55
|
+
const tokenUrl = buildCopilotTokenUrl(provider?.baseURL);
|
|
56
|
+
const response = await baseFetch(tokenUrl, {
|
|
57
|
+
headers: {
|
|
58
|
+
Accept: "application/json",
|
|
59
|
+
Authorization: `Bearer ${refreshToken}`,
|
|
60
|
+
...COPILOT_HEADERS
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
if (!response.ok) throw new Error(`Copilot token refresh failed: ${response.status}`);
|
|
64
|
+
const tokenData = await response.json();
|
|
65
|
+
if (!tokenData.token) throw new Error("Copilot token refresh failed: missing token.");
|
|
66
|
+
const expiresAtIso = computeExpiry(tokenData);
|
|
67
|
+
setProviderCredentials("copilot", {
|
|
68
|
+
accessToken: tokenData.token,
|
|
69
|
+
expiresAt: expiresAtIso
|
|
70
|
+
});
|
|
71
|
+
return tokenData.token;
|
|
72
|
+
}
|
|
73
|
+
function buildCopilotTokenUrl(baseURL) {
|
|
74
|
+
const fallback = "https://api.githubcopilot.com";
|
|
75
|
+
const root = baseURL || fallback;
|
|
76
|
+
return new URL("/copilot_internal/v2/token", root).toString();
|
|
77
|
+
}
|
|
78
|
+
function computeExpiry(tokenData) {
|
|
79
|
+
if (tokenData.expires_at) return new Date(1000 * tokenData.expires_at - REFRESH_BUFFER_MS).toISOString();
|
|
80
|
+
if (tokenData.expires_in) return new Date(Date.now() + 1000 * tokenData.expires_in - REFRESH_BUFFER_MS).toISOString();
|
|
81
|
+
}
|
|
82
|
+
function inspectRequest(body) {
|
|
83
|
+
let isAgentCall = false;
|
|
84
|
+
let isVisionRequest = false;
|
|
85
|
+
if (!body || "string" != typeof body) return {
|
|
86
|
+
isAgentCall,
|
|
87
|
+
isVisionRequest
|
|
88
|
+
};
|
|
89
|
+
try {
|
|
90
|
+
const parsed = JSON.parse(body);
|
|
91
|
+
if (parsed?.messages) {
|
|
92
|
+
if (parsed.messages.length > 0) {
|
|
93
|
+
const lastMessage = parsed.messages[parsed.messages.length - 1];
|
|
94
|
+
isAgentCall = lastMessage?.role && [
|
|
95
|
+
"tool",
|
|
96
|
+
"assistant"
|
|
97
|
+
].includes(lastMessage.role);
|
|
98
|
+
}
|
|
99
|
+
isVisionRequest = parsed.messages.some((message)=>Array.isArray(message?.content) && message.content.some((part)=>part?.type === "image_url"));
|
|
100
|
+
}
|
|
101
|
+
if (parsed?.input) {
|
|
102
|
+
const lastInput = parsed.input[parsed.input.length - 1];
|
|
103
|
+
const isAssistant = lastInput?.role === "assistant";
|
|
104
|
+
const hasAgentType = lastInput?.type ? RESPONSES_API_ALTERNATE_INPUT_TYPES.has(lastInput.type) : false;
|
|
105
|
+
isAgentCall = isAssistant || hasAgentType;
|
|
106
|
+
isVisionRequest = Array.isArray(lastInput?.content) && lastInput.content.some((part)=>part?.type === "input_image");
|
|
107
|
+
}
|
|
108
|
+
} catch {}
|
|
109
|
+
return {
|
|
110
|
+
isAgentCall,
|
|
111
|
+
isVisionRequest
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
export { createCopilotFetch };
|
|
@@ -0,0 +1,154 @@
|
|
|
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
|
+
saveProviderToken: ()=>saveProviderToken,
|
|
28
|
+
readCredentialsFile: ()=>readCredentialsFile,
|
|
29
|
+
deleteProviderCredentials: ()=>deleteProviderCredentials,
|
|
30
|
+
writeCredentialsFile: ()=>writeCredentialsFile,
|
|
31
|
+
getProviderCredentials: ()=>getProviderCredentials,
|
|
32
|
+
getCredentialsPath: ()=>getCredentialsPath,
|
|
33
|
+
setProviderCredentials: ()=>setProviderCredentials,
|
|
34
|
+
resolveProviderToken: ()=>resolveProviderToken
|
|
35
|
+
});
|
|
36
|
+
const external_node_fs_namespaceObject = require("node:fs");
|
|
37
|
+
const external_node_os_namespaceObject = require("node:os");
|
|
38
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
39
|
+
const external_registry_cjs_namespaceObject = require("./registry.cjs");
|
|
40
|
+
const CREDENTIALS_VERSION = 1;
|
|
41
|
+
const CREDENTIALS_DIR = (0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.homedir)(), ".wingman");
|
|
42
|
+
const CREDENTIALS_PATH = (0, external_node_path_namespaceObject.join)(CREDENTIALS_DIR, "credentials.json");
|
|
43
|
+
function getCredentialsPath() {
|
|
44
|
+
return CREDENTIALS_PATH;
|
|
45
|
+
}
|
|
46
|
+
function emptyCredentials() {
|
|
47
|
+
return {
|
|
48
|
+
version: CREDENTIALS_VERSION,
|
|
49
|
+
updatedAt: new Date().toISOString(),
|
|
50
|
+
providers: {}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function readCredentialsFile() {
|
|
54
|
+
if (!(0, external_node_fs_namespaceObject.existsSync)(CREDENTIALS_PATH)) return emptyCredentials();
|
|
55
|
+
try {
|
|
56
|
+
const raw = (0, external_node_fs_namespaceObject.readFileSync)(CREDENTIALS_PATH, "utf-8");
|
|
57
|
+
const parsed = JSON.parse(raw);
|
|
58
|
+
const providers = parsed && "object" == typeof parsed.providers && parsed.providers ? parsed.providers : {};
|
|
59
|
+
return {
|
|
60
|
+
version: "number" == typeof parsed?.version ? parsed.version : CREDENTIALS_VERSION,
|
|
61
|
+
updatedAt: "string" == typeof parsed?.updatedAt ? parsed.updatedAt : new Date().toISOString(),
|
|
62
|
+
providers
|
|
63
|
+
};
|
|
64
|
+
} catch {
|
|
65
|
+
return emptyCredentials();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function writeCredentialsFile(data) {
|
|
69
|
+
(0, external_node_fs_namespaceObject.mkdirSync)(CREDENTIALS_DIR, {
|
|
70
|
+
recursive: true
|
|
71
|
+
});
|
|
72
|
+
(0, external_node_fs_namespaceObject.writeFileSync)(CREDENTIALS_PATH, JSON.stringify(data, null, 2));
|
|
73
|
+
}
|
|
74
|
+
function getProviderCredentials(provider) {
|
|
75
|
+
const file = readCredentialsFile();
|
|
76
|
+
return file.providers[provider];
|
|
77
|
+
}
|
|
78
|
+
function setProviderCredentials(provider, credentials) {
|
|
79
|
+
const file = readCredentialsFile();
|
|
80
|
+
file.providers[provider] = {
|
|
81
|
+
...file.providers[provider] || {},
|
|
82
|
+
...credentials
|
|
83
|
+
};
|
|
84
|
+
file.updatedAt = new Date().toISOString();
|
|
85
|
+
writeCredentialsFile(file);
|
|
86
|
+
}
|
|
87
|
+
function deleteProviderCredentials(provider) {
|
|
88
|
+
const file = readCredentialsFile();
|
|
89
|
+
if (!file.providers[provider]) return false;
|
|
90
|
+
delete file.providers[provider];
|
|
91
|
+
file.updatedAt = new Date().toISOString();
|
|
92
|
+
writeCredentialsFile(file);
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
function saveProviderToken(providerName, token) {
|
|
96
|
+
const provider = (0, external_registry_cjs_namespaceObject.getProviderSpec)(providerName);
|
|
97
|
+
if (!provider) throw new Error(`Unknown provider: "${providerName}"`);
|
|
98
|
+
const normalized = token.trim();
|
|
99
|
+
if (!normalized) throw new Error("Token is required");
|
|
100
|
+
const existing = getProviderCredentials(provider.name) || {};
|
|
101
|
+
const updated = {
|
|
102
|
+
...existing
|
|
103
|
+
};
|
|
104
|
+
if ("oauth" === provider.type) {
|
|
105
|
+
updated.accessToken = normalized;
|
|
106
|
+
updated.tokenType = "bearer";
|
|
107
|
+
} else updated.apiKey = normalized;
|
|
108
|
+
setProviderCredentials(provider.name, updated);
|
|
109
|
+
return updated;
|
|
110
|
+
}
|
|
111
|
+
function resolveProviderToken(providerName) {
|
|
112
|
+
const provider = (0, external_registry_cjs_namespaceObject.getProviderSpec)(providerName);
|
|
113
|
+
if (!provider) return {
|
|
114
|
+
source: "missing"
|
|
115
|
+
};
|
|
116
|
+
for (const envVar of provider.envVars){
|
|
117
|
+
const value = process.env[envVar];
|
|
118
|
+
if (value && value.trim()) return {
|
|
119
|
+
token: value.trim(),
|
|
120
|
+
source: "env",
|
|
121
|
+
envVar
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
const credentials = getProviderCredentials(provider.name);
|
|
125
|
+
const token = credentials?.accessToken ?? credentials?.apiKey ?? credentials?.refreshToken;
|
|
126
|
+
if (token && token.trim()) return {
|
|
127
|
+
token: token.trim(),
|
|
128
|
+
source: "credentials"
|
|
129
|
+
};
|
|
130
|
+
return {
|
|
131
|
+
source: "missing"
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
exports.deleteProviderCredentials = __webpack_exports__.deleteProviderCredentials;
|
|
135
|
+
exports.getCredentialsPath = __webpack_exports__.getCredentialsPath;
|
|
136
|
+
exports.getProviderCredentials = __webpack_exports__.getProviderCredentials;
|
|
137
|
+
exports.readCredentialsFile = __webpack_exports__.readCredentialsFile;
|
|
138
|
+
exports.resolveProviderToken = __webpack_exports__.resolveProviderToken;
|
|
139
|
+
exports.saveProviderToken = __webpack_exports__.saveProviderToken;
|
|
140
|
+
exports.setProviderCredentials = __webpack_exports__.setProviderCredentials;
|
|
141
|
+
exports.writeCredentialsFile = __webpack_exports__.writeCredentialsFile;
|
|
142
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
143
|
+
"deleteProviderCredentials",
|
|
144
|
+
"getCredentialsPath",
|
|
145
|
+
"getProviderCredentials",
|
|
146
|
+
"readCredentialsFile",
|
|
147
|
+
"resolveProviderToken",
|
|
148
|
+
"saveProviderToken",
|
|
149
|
+
"setProviderCredentials",
|
|
150
|
+
"writeCredentialsFile"
|
|
151
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
152
|
+
Object.defineProperty(exports, '__esModule', {
|
|
153
|
+
value: true
|
|
154
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ProviderName } from "./registry.js";
|
|
2
|
+
export interface ProviderCredentials {
|
|
3
|
+
apiKey?: string;
|
|
4
|
+
accessToken?: string;
|
|
5
|
+
refreshToken?: string;
|
|
6
|
+
expiresAt?: string;
|
|
7
|
+
tokenType?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ProviderCredentialsFile {
|
|
10
|
+
version: number;
|
|
11
|
+
updatedAt: string;
|
|
12
|
+
providers: Record<string, ProviderCredentials>;
|
|
13
|
+
}
|
|
14
|
+
export type ProviderAuthSource = "env" | "credentials" | "missing";
|
|
15
|
+
export declare function getCredentialsPath(): string;
|
|
16
|
+
export declare function readCredentialsFile(): ProviderCredentialsFile;
|
|
17
|
+
export declare function writeCredentialsFile(data: ProviderCredentialsFile): void;
|
|
18
|
+
export declare function getProviderCredentials(provider: ProviderName): ProviderCredentials | undefined;
|
|
19
|
+
export declare function setProviderCredentials(provider: ProviderName, credentials: ProviderCredentials): void;
|
|
20
|
+
export declare function deleteProviderCredentials(provider: ProviderName): boolean;
|
|
21
|
+
export declare function saveProviderToken(providerName: string, token: string): ProviderCredentials;
|
|
22
|
+
export declare function resolveProviderToken(providerName: string): {
|
|
23
|
+
token?: string;
|
|
24
|
+
source: ProviderAuthSource;
|
|
25
|
+
envVar?: string;
|
|
26
|
+
};
|