@mastra/code-sdk 0.0.0-esbuild-bundle-worker-20260807173433
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1349 -0
- package/LICENSE.md +30 -0
- package/README.md +70 -0
- package/dist/acp/agent.d.ts +35 -0
- package/dist/acp/agent.d.ts.map +1 -0
- package/dist/acp/agent.js +161 -0
- package/dist/acp/agent.js.map +1 -0
- package/dist/acp/event-mapper.d.ts +22 -0
- package/dist/acp/event-mapper.d.ts.map +1 -0
- package/dist/acp/event-mapper.js +214 -0
- package/dist/acp/event-mapper.js.map +1 -0
- package/dist/acp/index.d.ts +8 -0
- package/dist/acp/index.d.ts.map +1 -0
- package/dist/acp/index.js +65 -0
- package/dist/acp/index.js.map +1 -0
- package/dist/acp/server.d.ts +7 -0
- package/dist/acp/server.d.ts.map +1 -0
- package/dist/acp/server.js +35 -0
- package/dist/acp/server.js.map +1 -0
- package/dist/acp.d.ts +2 -0
- package/dist/acp.d.ts.map +1 -0
- package/dist/acp.js +2 -0
- package/dist/agents/credential-resolver.d.ts +51 -0
- package/dist/agents/credential-resolver.d.ts.map +1 -0
- package/dist/agents/credential-resolver.js +52 -0
- package/dist/agents/credential-resolver.js.map +1 -0
- package/dist/agents/custom-provider-source.d.ts +35 -0
- package/dist/agents/custom-provider-source.d.ts.map +1 -0
- package/dist/agents/custom-provider-source.js +25 -0
- package/dist/agents/custom-provider-source.js.map +1 -0
- package/dist/agents/instructions.d.ts +6 -0
- package/dist/agents/instructions.d.ts.map +1 -0
- package/dist/agents/instructions.js +32 -0
- package/dist/agents/instructions.js.map +1 -0
- package/dist/agents/mastracode-gateway.d.ts +74 -0
- package/dist/agents/mastracode-gateway.d.ts.map +1 -0
- package/dist/agents/mastracode-gateway.js +400 -0
- package/dist/agents/mastracode-gateway.js.map +1 -0
- package/dist/agents/memory.d.ts +13 -0
- package/dist/agents/memory.d.ts.map +1 -0
- package/dist/agents/memory.js +116 -0
- package/dist/agents/memory.js.map +1 -0
- package/dist/agents/model.d.ts +59 -0
- package/dist/agents/model.d.ts.map +1 -0
- package/dist/agents/model.js +132 -0
- package/dist/agents/model.js.map +1 -0
- package/dist/agents/modes/build.d.ts +10 -0
- package/dist/agents/modes/build.d.ts.map +1 -0
- package/dist/agents/modes/build.js +44 -0
- package/dist/agents/modes/build.js.map +1 -0
- package/dist/agents/modes/explore.d.ts +10 -0
- package/dist/agents/modes/explore.d.ts.map +1 -0
- package/dist/agents/modes/explore.js +39 -0
- package/dist/agents/modes/explore.js.map +1 -0
- package/dist/agents/modes/plan.d.ts +6 -0
- package/dist/agents/modes/plan.d.ts.map +1 -0
- package/dist/agents/modes/plan.js +37 -0
- package/dist/agents/modes/plan.js.map +1 -0
- package/dist/agents/prompts/agent-instructions.d.ts +61 -0
- package/dist/agents/prompts/agent-instructions.d.ts.map +1 -0
- package/dist/agents/prompts/agent-instructions.js +201 -0
- package/dist/agents/prompts/agent-instructions.js.map +1 -0
- package/dist/agents/prompts/build.d.ts +12 -0
- package/dist/agents/prompts/build.d.ts.map +1 -0
- package/dist/agents/prompts/build.js +76 -0
- package/dist/agents/prompts/build.js.map +1 -0
- package/dist/agents/prompts/fast.d.ts +5 -0
- package/dist/agents/prompts/fast.d.ts.map +1 -0
- package/dist/agents/prompts/fast.js +26 -0
- package/dist/agents/prompts/fast.js.map +1 -0
- package/dist/agents/prompts/index.d.ts +19 -0
- package/dist/agents/prompts/index.d.ts.map +1 -0
- package/dist/agents/prompts/index.js +65 -0
- package/dist/agents/prompts/index.js.map +1 -0
- package/dist/agents/prompts/model.d.ts +5 -0
- package/dist/agents/prompts/model.d.ts.map +1 -0
- package/dist/agents/prompts/model.js +23 -0
- package/dist/agents/prompts/model.js.map +1 -0
- package/dist/agents/prompts/plan.d.ts +6 -0
- package/dist/agents/prompts/plan.d.ts.map +1 -0
- package/dist/agents/prompts/plan.js +111 -0
- package/dist/agents/prompts/plan.js.map +1 -0
- package/dist/agents/prompts/tool-guidance.d.ts +13 -0
- package/dist/agents/prompts/tool-guidance.d.ts.map +1 -0
- package/dist/agents/prompts/tool-guidance.js +149 -0
- package/dist/agents/prompts/tool-guidance.js.map +1 -0
- package/dist/agents/sandbox-filesystem.d.ts +99 -0
- package/dist/agents/sandbox-filesystem.d.ts.map +1 -0
- package/dist/agents/sandbox-filesystem.js +328 -0
- package/dist/agents/sandbox-filesystem.js.map +1 -0
- package/dist/agents/sandbox-reattach.d.ts +19 -0
- package/dist/agents/sandbox-reattach.d.ts.map +1 -0
- package/dist/agents/sandbox-reattach.js +15 -0
- package/dist/agents/sandbox-reattach.js.map +1 -0
- package/dist/agents/thread-caveman-state.d.ts +17 -0
- package/dist/agents/thread-caveman-state.d.ts.map +1 -0
- package/dist/agents/thread-caveman-state.js +107 -0
- package/dist/agents/thread-caveman-state.js.map +1 -0
- package/dist/agents/tool-availability.d.ts +10 -0
- package/dist/agents/tool-availability.d.ts.map +1 -0
- package/dist/agents/tool-availability.js +87 -0
- package/dist/agents/tool-availability.js.map +1 -0
- package/dist/agents/tools.d.ts +19 -0
- package/dist/agents/tools.d.ts.map +1 -0
- package/dist/agents/tools.js +105 -0
- package/dist/agents/tools.js.map +1 -0
- package/dist/agents/workspace.d.ts +32 -0
- package/dist/agents/workspace.d.ts.map +1 -0
- package/dist/agents/workspace.js +251 -0
- package/dist/agents/workspace.js.map +1 -0
- package/dist/analytics.d.ts +18 -0
- package/dist/analytics.d.ts.map +1 -0
- package/dist/analytics.js +163 -0
- package/dist/analytics.js.map +1 -0
- package/dist/auth/authorization-input.d.ts +16 -0
- package/dist/auth/authorization-input.d.ts.map +1 -0
- package/dist/auth/authorization-input.js +42 -0
- package/dist/auth/authorization-input.js.map +1 -0
- package/dist/auth/device-code.d.ts +93 -0
- package/dist/auth/device-code.d.ts.map +1 -0
- package/dist/auth/device-code.js +129 -0
- package/dist/auth/device-code.js.map +1 -0
- package/dist/auth/index.d.ts +10 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +6 -0
- package/dist/auth/pkce.d.ts +13 -0
- package/dist/auth/pkce.d.ts.map +1 -0
- package/dist/auth/pkce.js +32 -0
- package/dist/auth/pkce.js.map +1 -0
- package/dist/auth/providers/anthropic.d.ts +40 -0
- package/dist/auth/providers/anthropic.d.ts.map +1 -0
- package/dist/auth/providers/anthropic.js +126 -0
- package/dist/auth/providers/anthropic.js.map +1 -0
- package/dist/auth/providers/github-copilot.d.ts +154 -0
- package/dist/auth/providers/github-copilot.d.ts.map +1 -0
- package/dist/auth/providers/github-copilot.js +340 -0
- package/dist/auth/providers/github-copilot.js.map +1 -0
- package/dist/auth/providers/openai-codex.d.ts +139 -0
- package/dist/auth/providers/openai-codex.d.ts.map +1 -0
- package/dist/auth/providers/openai-codex.js +519 -0
- package/dist/auth/providers/openai-codex.js.map +1 -0
- package/dist/auth/providers/xai.d.ts +64 -0
- package/dist/auth/providers/xai.d.ts.map +1 -0
- package/dist/auth/providers/xai.js +205 -0
- package/dist/auth/providers/xai.js.map +1 -0
- package/dist/auth/storage.d.ts +91 -0
- package/dist/auth/storage.d.ts.map +1 -0
- package/dist/auth/storage.js +197 -0
- package/dist/auth/storage.js.map +1 -0
- package/dist/auth/types.d.ts +89 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +1 -0
- package/dist/clipboard/index.d.ts +26 -0
- package/dist/clipboard/index.d.ts.map +1 -0
- package/dist/clipboard/index.js +226 -0
- package/dist/clipboard/index.js.map +1 -0
- package/dist/constants.d.ts +10 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +18 -0
- package/dist/constants.js.map +1 -0
- package/dist/error-classification.d.ts +10 -0
- package/dist/error-classification.d.ts.map +1 -0
- package/dist/error-classification.js +22 -0
- package/dist/error-classification.js.map +1 -0
- package/dist/evals/context-builder.d.ts +41 -0
- package/dist/evals/context-builder.d.ts.map +1 -0
- package/dist/evals/context-builder.js +161 -0
- package/dist/evals/context-builder.js.map +1 -0
- package/dist/evals/index.d.ts +4 -0
- package/dist/evals/index.d.ts.map +1 -0
- package/dist/evals/index.js +5 -0
- package/dist/evals/scorers/classify-command.d.ts +31 -0
- package/dist/evals/scorers/classify-command.d.ts.map +1 -0
- package/dist/evals/scorers/classify-command.js +73 -0
- package/dist/evals/scorers/classify-command.js.map +1 -0
- package/dist/evals/scorers/efficiency.d.ts +44 -0
- package/dist/evals/scorers/efficiency.d.ts.map +1 -0
- package/dist/evals/scorers/efficiency.js +259 -0
- package/dist/evals/scorers/efficiency.js.map +1 -0
- package/dist/evals/scorers/extract-tools.d.ts +25 -0
- package/dist/evals/scorers/extract-tools.d.ts.map +1 -0
- package/dist/evals/scorers/extract-tools.js +60 -0
- package/dist/evals/scorers/extract-tools.js.map +1 -0
- package/dist/evals/scorers/index.d.ts +3 -0
- package/dist/evals/scorers/index.d.ts.map +1 -0
- package/dist/evals/scorers/index.js +3 -0
- package/dist/evals/scorers/outcome.d.ts +49 -0
- package/dist/evals/scorers/outcome.d.ts.map +1 -0
- package/dist/evals/scorers/outcome.js +347 -0
- package/dist/evals/scorers/outcome.js.map +1 -0
- package/dist/goal-manager.d.ts +78 -0
- package/dist/goal-manager.d.ts.map +1 -0
- package/dist/goal-manager.js +273 -0
- package/dist/goal-manager.js.map +1 -0
- package/dist/goal-signal.d.ts +14 -0
- package/dist/goal-signal.d.ts.map +1 -0
- package/dist/goal-signal.js +17 -0
- package/dist/goal-signal.js.map +1 -0
- package/dist/headless/cli.d.ts +42 -0
- package/dist/headless/cli.d.ts.map +1 -0
- package/dist/headless/cli.js +195 -0
- package/dist/headless/cli.js.map +1 -0
- package/dist/headless/flags.d.ts +33 -0
- package/dist/headless/flags.d.ts.map +1 -0
- package/dist/headless/flags.js +190 -0
- package/dist/headless/flags.js.map +1 -0
- package/dist/headless/format.d.ts +38 -0
- package/dist/headless/format.d.ts.map +1 -0
- package/dist/headless/format.js +89 -0
- package/dist/headless/format.js.map +1 -0
- package/dist/headless/index.d.ts +25 -0
- package/dist/headless/index.d.ts.map +1 -0
- package/dist/headless/index.js +6 -0
- package/dist/headless/policy.d.ts +17 -0
- package/dist/headless/policy.d.ts.map +1 -0
- package/dist/headless/policy.js +42 -0
- package/dist/headless/policy.js.map +1 -0
- package/dist/headless/run-mc.d.ts +7 -0
- package/dist/headless/run-mc.d.ts.map +1 -0
- package/dist/headless/run-mc.js +346 -0
- package/dist/headless/run-mc.js.map +1 -0
- package/dist/headless/types.d.ts +158 -0
- package/dist/headless/types.d.ts.map +1 -0
- package/dist/headless/types.js +18 -0
- package/dist/headless/types.js.map +1 -0
- package/dist/hooks/config.d.ts +11 -0
- package/dist/hooks/config.d.ts.map +1 -0
- package/dist/hooks/config.js +73 -0
- package/dist/hooks/config.js.map +1 -0
- package/dist/hooks/executor.d.ts +13 -0
- package/dist/hooks/executor.d.ts.map +1 -0
- package/dist/hooks/executor.js +128 -0
- package/dist/hooks/executor.js.map +1 -0
- package/dist/hooks/index.d.ts +6 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +5 -0
- package/dist/hooks/manager.d.ts +47 -0
- package/dist/hooks/manager.d.ts.map +1 -0
- package/dist/hooks/manager.js +225 -0
- package/dist/hooks/manager.js.map +1 -0
- package/dist/hooks/types.d.ts +152 -0
- package/dist/hooks/types.d.ts.map +1 -0
- package/dist/hooks/types.js +8 -0
- package/dist/hooks/types.js.map +1 -0
- package/dist/index.d.ts +258 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +740 -0
- package/dist/index.js.map +1 -0
- package/dist/ipc/ipc-reporter.d.ts +14 -0
- package/dist/ipc/ipc-reporter.d.ts.map +1 -0
- package/dist/ipc/ipc-reporter.js +21 -0
- package/dist/ipc/ipc-reporter.js.map +1 -0
- package/dist/lsp/client.d.ts +56 -0
- package/dist/lsp/client.d.ts.map +1 -0
- package/dist/lsp/client.js +251 -0
- package/dist/lsp/client.js.map +1 -0
- package/dist/lsp/index.d.ts +4 -0
- package/dist/lsp/index.d.ts.map +1 -0
- package/dist/lsp/index.js +4 -0
- package/dist/lsp/language.d.ts +9 -0
- package/dist/lsp/language.d.ts.map +1 -0
- package/dist/lsp/language.js +44 -0
- package/dist/lsp/language.js.map +1 -0
- package/dist/lsp/manager.d.ts +34 -0
- package/dist/lsp/manager.d.ts.map +1 -0
- package/dist/lsp/manager.js +82 -0
- package/dist/lsp/manager.js.map +1 -0
- package/dist/lsp/server.d.ts +27 -0
- package/dist/lsp/server.d.ts.map +1 -0
- package/dist/lsp/server.js +159 -0
- package/dist/lsp/server.js.map +1 -0
- package/dist/lsp/workspace.d.ts +9 -0
- package/dist/lsp/workspace.d.ts.map +1 -0
- package/dist/lsp/workspace.js +55 -0
- package/dist/lsp/workspace.js.map +1 -0
- package/dist/mcp/config.d.ts +54 -0
- package/dist/mcp/config.d.ts.map +1 -0
- package/dist/mcp/config.js +240 -0
- package/dist/mcp/config.js.map +1 -0
- package/dist/mcp/index.d.ts +5 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +3 -0
- package/dist/mcp/manager.d.ts +98 -0
- package/dist/mcp/manager.d.ts.map +1 -0
- package/dist/mcp/manager.js +612 -0
- package/dist/mcp/manager.js.map +1 -0
- package/dist/mcp/state.d.ts +33 -0
- package/dist/mcp/state.d.ts.map +1 -0
- package/dist/mcp/state.js +88 -0
- package/dist/mcp/state.js.map +1 -0
- package/dist/mcp/types.d.ts +120 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/mcp/types.js +1 -0
- package/dist/onboarding/custom-packs.d.ts +7 -0
- package/dist/onboarding/custom-packs.d.ts.map +1 -0
- package/dist/onboarding/custom-packs.js +17 -0
- package/dist/onboarding/custom-packs.js.map +1 -0
- package/dist/onboarding/custom-providers.d.ts +4 -0
- package/dist/onboarding/custom-providers.d.ts.map +1 -0
- package/dist/onboarding/custom-providers.js +30 -0
- package/dist/onboarding/custom-providers.js.map +1 -0
- package/dist/onboarding/index.d.ts +5 -0
- package/dist/onboarding/index.d.ts.map +1 -0
- package/dist/onboarding/index.js +3 -0
- package/dist/onboarding/om-settings.d.ts +25 -0
- package/dist/onboarding/om-settings.d.ts.map +1 -0
- package/dist/onboarding/om-settings.js +47 -0
- package/dist/onboarding/om-settings.js.map +1 -0
- package/dist/onboarding/packs.d.ts +46 -0
- package/dist/onboarding/packs.d.ts.map +1 -0
- package/dist/onboarding/packs.js +160 -0
- package/dist/onboarding/packs.js.map +1 -0
- package/dist/onboarding/settings.d.ts +338 -0
- package/dist/onboarding/settings.d.ts.map +1 -0
- package/dist/onboarding/settings.js +673 -0
- package/dist/onboarding/settings.js.map +1 -0
- package/dist/permissions.d.ts +55 -0
- package/dist/permissions.d.ts.map +1 -0
- package/dist/permissions.js +132 -0
- package/dist/permissions.js.map +1 -0
- package/dist/plugin.d.ts +81 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +28 -0
- package/dist/plugin.js.map +1 -0
- package/dist/plugins/dependencies.d.ts +9 -0
- package/dist/plugins/dependencies.d.ts.map +1 -0
- package/dist/plugins/dependencies.js +88 -0
- package/dist/plugins/dependencies.js.map +1 -0
- package/dist/plugins/install.d.ts +21 -0
- package/dist/plugins/install.d.ts.map +1 -0
- package/dist/plugins/install.js +190 -0
- package/dist/plugins/install.js.map +1 -0
- package/dist/plugins/loader.d.ts +15 -0
- package/dist/plugins/loader.d.ts.map +1 -0
- package/dist/plugins/loader.js +206 -0
- package/dist/plugins/loader.js.map +1 -0
- package/dist/plugins/manager.d.ts +64 -0
- package/dist/plugins/manager.d.ts.map +1 -0
- package/dist/plugins/manager.js +384 -0
- package/dist/plugins/manager.js.map +1 -0
- package/dist/plugins/manifest.d.ts +14 -0
- package/dist/plugins/manifest.d.ts.map +1 -0
- package/dist/plugins/manifest.js +50 -0
- package/dist/plugins/manifest.js.map +1 -0
- package/dist/plugins/package-link.d.ts +3 -0
- package/dist/plugins/package-link.d.ts.map +1 -0
- package/dist/plugins/package-link.js +61 -0
- package/dist/plugins/package-link.js.map +1 -0
- package/dist/plugins/paths.d.ts +10 -0
- package/dist/plugins/paths.d.ts.map +1 -0
- package/dist/plugins/paths.js +25 -0
- package/dist/plugins/paths.js.map +1 -0
- package/dist/plugins/registry.d.ts +8 -0
- package/dist/plugins/registry.d.ts.map +1 -0
- package/dist/plugins/registry.js +112 -0
- package/dist/plugins/registry.js.map +1 -0
- package/dist/plugins/scaffold.d.ts +10 -0
- package/dist/plugins/scaffold.d.ts.map +1 -0
- package/dist/plugins/scaffold.js +116 -0
- package/dist/plugins/scaffold.js.map +1 -0
- package/dist/plugins/types.d.ts +45 -0
- package/dist/plugins/types.d.ts.map +1 -0
- package/dist/plugins/types.js +1 -0
- package/dist/processors/plan-rejection-abort.d.ts +12 -0
- package/dist/processors/plan-rejection-abort.d.ts.map +1 -0
- package/dist/processors/plan-rejection-abort.js +54 -0
- package/dist/processors/plan-rejection-abort.js.map +1 -0
- package/dist/providers/amazon-bedrock-gateway.d.ts +47 -0
- package/dist/providers/amazon-bedrock-gateway.d.ts.map +1 -0
- package/dist/providers/amazon-bedrock-gateway.js +152 -0
- package/dist/providers/amazon-bedrock-gateway.js.map +1 -0
- package/dist/providers/amazon-bedrock.d.ts +28 -0
- package/dist/providers/amazon-bedrock.d.ts.map +1 -0
- package/dist/providers/amazon-bedrock.js +83 -0
- package/dist/providers/amazon-bedrock.js.map +1 -0
- package/dist/providers/claude-max.d.ts +52 -0
- package/dist/providers/claude-max.d.ts.map +1 -0
- package/dist/providers/claude-max.js +171 -0
- package/dist/providers/claude-max.js.map +1 -0
- package/dist/providers/github-copilot.d.ts +60 -0
- package/dist/providers/github-copilot.d.ts.map +1 -0
- package/dist/providers/github-copilot.js +265 -0
- package/dist/providers/github-copilot.js.map +1 -0
- package/dist/providers/openai-codex.d.ts +72 -0
- package/dist/providers/openai-codex.d.ts.map +1 -0
- package/dist/providers/openai-codex.js +302 -0
- package/dist/providers/openai-codex.js.map +1 -0
- package/dist/providers/xai.d.ts +33 -0
- package/dist/providers/xai.d.ts.map +1 -0
- package/dist/providers/xai.js +70 -0
- package/dist/providers/xai.js.map +1 -0
- package/dist/schema.d.ts +192 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +98 -0
- package/dist/schema.js.map +1 -0
- package/dist/theme-palette.d.ts +17 -0
- package/dist/theme-palette.d.ts.map +1 -0
- package/dist/theme-palette.js +21 -0
- package/dist/theme-palette.js.map +1 -0
- package/dist/tool-names.d.ts +73 -0
- package/dist/tool-names.d.ts.map +1 -0
- package/dist/tool-names.js +52 -0
- package/dist/tool-names.js.map +1 -0
- package/dist/tools/index.d.ts +6 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +3 -0
- package/dist/tools/request-sandbox-access.d.ts +6 -0
- package/dist/tools/request-sandbox-access.d.ts.map +1 -0
- package/dist/tools/request-sandbox-access.js +79 -0
- package/dist/tools/request-sandbox-access.js.map +1 -0
- package/dist/tools/utils.d.ts +20 -0
- package/dist/tools/utils.d.ts.map +1 -0
- package/dist/tools/utils.js +32 -0
- package/dist/tools/utils.js.map +1 -0
- package/dist/tools/web-search.d.ts +35 -0
- package/dist/tools/web-search.d.ts.map +1 -0
- package/dist/tools/web-search.js +61 -0
- package/dist/tools/web-search.js.map +1 -0
- package/dist/utils/binaries.d.ts +7 -0
- package/dist/utils/binaries.d.ts.map +1 -0
- package/dist/utils/binaries.js +78 -0
- package/dist/utils/binaries.js.map +1 -0
- package/dist/utils/debug-log.d.ts +12 -0
- package/dist/utils/debug-log.d.ts.map +1 -0
- package/dist/utils/debug-log.js +59 -0
- package/dist/utils/debug-log.js.map +1 -0
- package/dist/utils/errors.d.ts +36 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +172 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/gateway-sync.d.ts +26 -0
- package/dist/utils/gateway-sync.d.ts.map +1 -0
- package/dist/utils/gateway-sync.js +61 -0
- package/dist/utils/gateway-sync.js.map +1 -0
- package/dist/utils/path-security.d.ts +2 -0
- package/dist/utils/path-security.d.ts.map +1 -0
- package/dist/utils/path-security.js +10 -0
- package/dist/utils/path-security.js.map +1 -0
- package/dist/utils/plan-diff.d.ts +25 -0
- package/dist/utils/plan-diff.d.ts.map +1 -0
- package/dist/utils/plan-diff.js +62 -0
- package/dist/utils/plan-diff.js.map +1 -0
- package/dist/utils/plans.d.ts +56 -0
- package/dist/utils/plans.d.ts.map +1 -0
- package/dist/utils/plans.js +117 -0
- package/dist/utils/plans.js.map +1 -0
- package/dist/utils/project.d.ts +160 -0
- package/dist/utils/project.d.ts.map +1 -0
- package/dist/utils/project.js +364 -0
- package/dist/utils/project.js.map +1 -0
- package/dist/utils/signals-pubsub.d.ts +41 -0
- package/dist/utils/signals-pubsub.d.ts.map +1 -0
- package/dist/utils/signals-pubsub.js +122 -0
- package/dist/utils/signals-pubsub.js.map +1 -0
- package/dist/utils/slash-command-loader.d.ts +52 -0
- package/dist/utils/slash-command-loader.d.ts.map +1 -0
- package/dist/utils/slash-command-loader.js +141 -0
- package/dist/utils/slash-command-loader.js.map +1 -0
- package/dist/utils/slash-command-processor.d.ts +14 -0
- package/dist/utils/slash-command-processor.d.ts.map +1 -0
- package/dist/utils/slash-command-processor.js +105 -0
- package/dist/utils/slash-command-processor.js.map +1 -0
- package/dist/utils/stdin-pipe.d.ts +33 -0
- package/dist/utils/stdin-pipe.d.ts.map +1 -0
- package/dist/utils/stdin-pipe.js +96 -0
- package/dist/utils/stdin-pipe.js.map +1 -0
- package/dist/utils/storage-factory.d.ts +50 -0
- package/dist/utils/storage-factory.d.ts.map +1 -0
- package/dist/utils/storage-factory.js +121 -0
- package/dist/utils/storage-factory.js.map +1 -0
- package/dist/utils/storage-maintenance.d.ts +103 -0
- package/dist/utils/storage-maintenance.d.ts.map +1 -0
- package/dist/utils/storage-maintenance.js +274 -0
- package/dist/utils/storage-maintenance.js.map +1 -0
- package/dist/utils/thread-lock.d.ts +26 -0
- package/dist/utils/thread-lock.d.ts.map +1 -0
- package/dist/utils/thread-lock.js +112 -0
- package/dist/utils/thread-lock.js.map +1 -0
- package/dist/utils/token-estimator.d.ts +3 -0
- package/dist/utils/token-estimator.d.ts.map +1 -0
- package/dist/utils/token-estimator.js +21 -0
- package/dist/utils/token-estimator.js.map +1 -0
- package/dist/utils/update-check.d.ts +101 -0
- package/dist/utils/update-check.d.ts.map +1 -0
- package/dist/utils/update-check.js +383 -0
- package/dist/utils/update-check.js.map +1 -0
- package/dist/voice/stt-registry.d.ts +64 -0
- package/dist/voice/stt-registry.d.ts.map +1 -0
- package/dist/voice/stt-registry.js +144 -0
- package/dist/voice/stt-registry.js.map +1 -0
- package/package.json +96 -0
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { COPILOT_HEADERS, fetchCopilotModels, getGitHubCopilotBaseUrl } from "../auth/providers/github-copilot.js";
|
|
2
|
+
import { AuthStorage } from "../auth/storage.js";
|
|
3
|
+
import { wrapLanguageModel } from "ai";
|
|
4
|
+
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
5
|
+
import { GoogleSchemaCompatLayer, applyCompatLayer } from "@mastra/schema-compat";
|
|
6
|
+
//#region src/providers/github-copilot.ts
|
|
7
|
+
/**
|
|
8
|
+
* GitHub Copilot OAuth Provider
|
|
9
|
+
*
|
|
10
|
+
* Uses OAuth tokens from AuthStorage to authenticate with GitHub Copilot's chat API.
|
|
11
|
+
* The Copilot API speaks an OpenAI-compatible chat format, so we plug
|
|
12
|
+
* `@ai-sdk/openai-compatible` into Copilot's API URL and use a custom fetch to inject
|
|
13
|
+
* the bearer token and Copilot-specific headers.
|
|
14
|
+
*
|
|
15
|
+
* Inspired by:
|
|
16
|
+
* - opencode: https://github.com/anomalyco/opencode/blob/dev/packages/opencode/src/plugin/github-copilot/copilot.ts
|
|
17
|
+
* - pi-mono: https://github.com/badlogic/pi-mono/blob/main/packages/ai/src/utils/oauth/github-copilot.ts
|
|
18
|
+
*/
|
|
19
|
+
const COPILOT_PROVIDER_ID = "github-copilot";
|
|
20
|
+
let authStorageInstance = null;
|
|
21
|
+
/** Get or create the shared AuthStorage instance. */
|
|
22
|
+
function getAuthStorage() {
|
|
23
|
+
if (!authStorageInstance) authStorageInstance = new AuthStorage();
|
|
24
|
+
return authStorageInstance;
|
|
25
|
+
}
|
|
26
|
+
/** Set a custom AuthStorage instance (useful for tests / TUI integration). */
|
|
27
|
+
function setAuthStorage(storage) {
|
|
28
|
+
authStorageInstance = storage ?? null;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Heuristic: did this request come from the agent (e.g. tool result follow-ups) rather
|
|
32
|
+
* than a fresh user turn? Mirrors opencode's `isAgent` logic — Copilot bills these
|
|
33
|
+
* differently via the `x-initiator` header.
|
|
34
|
+
*/
|
|
35
|
+
function detectIsAgent(body) {
|
|
36
|
+
if (!body || typeof body !== "object") return false;
|
|
37
|
+
const obj = body;
|
|
38
|
+
const messages = obj.messages;
|
|
39
|
+
if (Array.isArray(messages) && messages.length > 0) {
|
|
40
|
+
const last = messages[messages.length - 1];
|
|
41
|
+
if (last?.role && last.role !== "user") return true;
|
|
42
|
+
if (Array.isArray(last?.content)) {
|
|
43
|
+
if (last.content.some((part) => part && typeof part === "object" && part.type === "tool_result")) return true;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const input = obj.input;
|
|
47
|
+
if (Array.isArray(input) && input.length > 0) {
|
|
48
|
+
const last = input[input.length - 1];
|
|
49
|
+
if (last?.role && last.role !== "user") return true;
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
/** Detect image/vision content in a request body. */
|
|
54
|
+
function detectIsVision(body) {
|
|
55
|
+
if (!body || typeof body !== "object") return false;
|
|
56
|
+
const obj = body;
|
|
57
|
+
const matchPart = (part) => {
|
|
58
|
+
if (!part || typeof part !== "object") return false;
|
|
59
|
+
const t = part.type;
|
|
60
|
+
return t === "image" || t === "image_url" || t === "input_image";
|
|
61
|
+
};
|
|
62
|
+
const messages = obj.messages;
|
|
63
|
+
if (Array.isArray(messages)) return messages.some((msg) => msg && typeof msg === "object" && Array.isArray(msg.content) && msg.content.some(matchPart));
|
|
64
|
+
const input = obj.input;
|
|
65
|
+
if (Array.isArray(input)) return input.some((item) => item && typeof item === "object" && Array.isArray(item.content) && item.content.some(matchPart));
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Build a fetch wrapper that authenticates with GitHub Copilot OAuth.
|
|
70
|
+
*
|
|
71
|
+
* - Injects the short-lived Copilot bearer token (auto-refreshed by AuthStorage).
|
|
72
|
+
* - Adds the VS Code-like Copilot headers required by the API.
|
|
73
|
+
* - Rewrites the request URL onto the per-token API base when `rewriteUrl` is true.
|
|
74
|
+
*/
|
|
75
|
+
function buildGitHubCopilotOAuthFetch(opts = {}) {
|
|
76
|
+
return (async (url, init) => {
|
|
77
|
+
const storage = opts.authStorage ?? getAuthStorage();
|
|
78
|
+
storage.reload();
|
|
79
|
+
const cred = storage.get(COPILOT_PROVIDER_ID);
|
|
80
|
+
if (!cred || cred.type !== "oauth") throw new Error("Not logged in to GitHub Copilot. Run /login first.");
|
|
81
|
+
const accessToken = await storage.getApiKey(COPILOT_PROVIDER_ID);
|
|
82
|
+
if (!accessToken) throw new Error("Failed to refresh GitHub Copilot token. Please /login again.");
|
|
83
|
+
storage.reload();
|
|
84
|
+
const enterpriseUrl = cred.enterpriseUrl;
|
|
85
|
+
let parsedBody;
|
|
86
|
+
if (typeof init?.body === "string") try {
|
|
87
|
+
parsedBody = JSON.parse(init.body);
|
|
88
|
+
} catch {
|
|
89
|
+
parsedBody = void 0;
|
|
90
|
+
}
|
|
91
|
+
const isAgent = detectIsAgent(parsedBody);
|
|
92
|
+
const isVision = detectIsVision(parsedBody);
|
|
93
|
+
const headers = new Headers();
|
|
94
|
+
if (init?.headers) (init.headers instanceof Headers ? init.headers : Array.isArray(init.headers) ? new Headers(init.headers) : new Headers(init.headers)).forEach((value, key) => {
|
|
95
|
+
const lower = key.toLowerCase();
|
|
96
|
+
if (lower !== "authorization" && lower !== "x-api-key") headers.set(key, value);
|
|
97
|
+
});
|
|
98
|
+
headers.set("Authorization", `Bearer ${accessToken}`);
|
|
99
|
+
headers.set("x-initiator", isAgent ? "agent" : "user");
|
|
100
|
+
headers.set("Openai-Intent", "conversation-edits");
|
|
101
|
+
if (isVision) headers.set("Copilot-Vision-Request", "true");
|
|
102
|
+
for (const [key, value] of Object.entries(COPILOT_HEADERS)) if (!headers.has(key)) headers.set(key, value);
|
|
103
|
+
const finalUrl = opts.rewriteUrl !== false ? rewriteToCopilotBase(url, accessToken, enterpriseUrl) : url instanceof URL ? url : typeof url === "string" ? new URL(url) : new URL(url.url);
|
|
104
|
+
try {
|
|
105
|
+
return await fetch(finalUrl, {
|
|
106
|
+
...init,
|
|
107
|
+
headers
|
|
108
|
+
});
|
|
109
|
+
} catch (error) {
|
|
110
|
+
if (error && typeof error === "object") Object.assign(error, { requestUrl: finalUrl.toString() });
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
function rewriteToCopilotBase(url, token, enterpriseDomain) {
|
|
116
|
+
const original = url instanceof URL ? url : new URL(typeof url === "string" ? url : url.url);
|
|
117
|
+
const base = new URL(getGitHubCopilotBaseUrl(token, enterpriseDomain));
|
|
118
|
+
const pathname = original.pathname.replace(/^\/v1(\/|$)/, "/");
|
|
119
|
+
return new URL(`${pathname}${original.search}`, base);
|
|
120
|
+
}
|
|
121
|
+
function isGeminiModel(modelId) {
|
|
122
|
+
return modelId.startsWith("gemini-");
|
|
123
|
+
}
|
|
124
|
+
function applyGeminiSchemaCompatToTools(modelId, tools) {
|
|
125
|
+
if (!Array.isArray(tools)) return tools;
|
|
126
|
+
const compatLayer = new GoogleSchemaCompatLayer({
|
|
127
|
+
provider: COPILOT_PROVIDER_ID,
|
|
128
|
+
modelId,
|
|
129
|
+
supportsStructuredOutputs: false
|
|
130
|
+
});
|
|
131
|
+
return tools.map((tool) => {
|
|
132
|
+
if (!tool || typeof tool !== "object" || tool.type !== "function") return tool;
|
|
133
|
+
const functionTool = tool;
|
|
134
|
+
if (!functionTool.inputSchema) return tool;
|
|
135
|
+
return {
|
|
136
|
+
...functionTool,
|
|
137
|
+
inputSchema: applyCompatLayer({
|
|
138
|
+
schema: functionTool.inputSchema,
|
|
139
|
+
compatLayers: [compatLayer],
|
|
140
|
+
mode: "aiSdkSchema"
|
|
141
|
+
}).jsonSchema
|
|
142
|
+
};
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
/** Middleware that prevents sending parameters Copilot's endpoint rejects. */
|
|
146
|
+
function createCopilotMiddleware(modelId) {
|
|
147
|
+
return {
|
|
148
|
+
specificationVersion: "v3",
|
|
149
|
+
transformParams: async ({ params }) => {
|
|
150
|
+
if (params.temperature !== void 0 && params.temperature !== null) delete params.topP;
|
|
151
|
+
if (isGeminiModel(modelId)) params.tools = applyGeminiSchemaCompatToTools(modelId, params.tools);
|
|
152
|
+
return params;
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Creates a model that talks to GitHub Copilot using OAuth credentials.
|
|
158
|
+
*
|
|
159
|
+
* Copilot's `/chat/completions` endpoint is OpenAI-compatible, but GitHub Copilot
|
|
160
|
+
* is not OpenAI. Use the generic OpenAI-compatible adapter with Copilot's base URL
|
|
161
|
+
* instead of the OpenAI provider plus URL rewriting.
|
|
162
|
+
*/
|
|
163
|
+
function githubCopilotProvider(modelId = "gpt-4.1", options) {
|
|
164
|
+
const headers = options?.headers;
|
|
165
|
+
return wrapLanguageModel({
|
|
166
|
+
model: createOpenAICompatible({
|
|
167
|
+
name: COPILOT_PROVIDER_ID,
|
|
168
|
+
baseURL: "https://api.githubcopilot.com",
|
|
169
|
+
apiKey: process.env.NODE_ENV === "test" || process.env.VITEST ? "test-api-key" : "oauth-placeholder",
|
|
170
|
+
headers,
|
|
171
|
+
fetch: process.env.NODE_ENV === "test" || process.env.VITEST ? void 0 : buildGitHubCopilotOAuthFetch({
|
|
172
|
+
rewriteUrl: false,
|
|
173
|
+
authStorage: options?.authStorage
|
|
174
|
+
})
|
|
175
|
+
}).chatModel(modelId),
|
|
176
|
+
middleware: [createCopilotMiddleware(modelId)]
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Hard-coded fallback advertised when the live `/models` request fails (network
|
|
181
|
+
* down, expired token, etc.). Keep this conservative because the live catalog is
|
|
182
|
+
* the source of truth for the user's currently-enabled Copilot models.
|
|
183
|
+
*
|
|
184
|
+
* Available across all paid Copilot tiers and free of premium-request charges.
|
|
185
|
+
*/
|
|
186
|
+
const COPILOT_FALLBACK_MODELS = [{
|
|
187
|
+
id: "gpt-4.1",
|
|
188
|
+
name: "GPT-4.1",
|
|
189
|
+
vendor: "OpenAI",
|
|
190
|
+
supportedEndpoints: ["/chat/completions"],
|
|
191
|
+
isAnthropicShaped: false,
|
|
192
|
+
supportsVision: true,
|
|
193
|
+
supportsToolCalls: true
|
|
194
|
+
}];
|
|
195
|
+
const CATALOG_TTL_MS = 600 * 1e3;
|
|
196
|
+
const CATALOG_FAILURE_TTL_MS = 60 * 1e3;
|
|
197
|
+
const CATALOG_FETCH_TIMEOUT_MS = 5e3;
|
|
198
|
+
let catalogCache = null;
|
|
199
|
+
let inflightFetch = null;
|
|
200
|
+
/** Reset the in-process Copilot catalog cache (test seam, also useful after logout). */
|
|
201
|
+
function clearCopilotCatalogCache() {
|
|
202
|
+
catalogCache = null;
|
|
203
|
+
inflightFetch = null;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Return the user's currently-available Copilot models.
|
|
207
|
+
*
|
|
208
|
+
* - Returns `[]` when the user is not logged in to GitHub Copilot.
|
|
209
|
+
* - Returns the cached list when a recent fetch succeeded.
|
|
210
|
+
* - On the cache-miss / expired path, fetches `/models` with a 5s timeout, filters
|
|
211
|
+
* to picker-enabled and non-policy-disabled models, then caches for 10 minutes.
|
|
212
|
+
* - On fetch failure, returns a small hard-coded fallback (so packs still work
|
|
213
|
+
* offline) and caches that for 1 minute to avoid hammering the API.
|
|
214
|
+
*
|
|
215
|
+
* Concurrent calls during a fetch share the inflight promise.
|
|
216
|
+
*/
|
|
217
|
+
async function getCopilotModelCatalog(opts = {}) {
|
|
218
|
+
const storage = opts.authStorage ?? getAuthStorage();
|
|
219
|
+
storage.reload();
|
|
220
|
+
const cred = storage.get(COPILOT_PROVIDER_ID);
|
|
221
|
+
if (!cred || cred.type !== "oauth") return [];
|
|
222
|
+
if (catalogCache && Date.now() - catalogCache.fetchedAt < catalogCache.ttl) return catalogCache.models;
|
|
223
|
+
if (inflightFetch) return inflightFetch;
|
|
224
|
+
inflightFetch = (async () => {
|
|
225
|
+
try {
|
|
226
|
+
const accessToken = await storage.getApiKey(COPILOT_PROVIDER_ID);
|
|
227
|
+
if (!accessToken) throw new Error("No Copilot bearer token");
|
|
228
|
+
storage.reload();
|
|
229
|
+
const enterpriseUrl = storage.get(COPILOT_PROVIDER_ID)?.enterpriseUrl;
|
|
230
|
+
const baseUrl = getGitHubCopilotBaseUrl(accessToken, enterpriseUrl);
|
|
231
|
+
const controller = new AbortController();
|
|
232
|
+
const timer = setTimeout(() => controller.abort(), CATALOG_FETCH_TIMEOUT_MS);
|
|
233
|
+
try {
|
|
234
|
+
const models = await fetchCopilotModels({
|
|
235
|
+
baseUrl,
|
|
236
|
+
bearerToken: accessToken,
|
|
237
|
+
signal: controller.signal
|
|
238
|
+
});
|
|
239
|
+
catalogCache = {
|
|
240
|
+
fetchedAt: Date.now(),
|
|
241
|
+
ttl: CATALOG_TTL_MS,
|
|
242
|
+
models
|
|
243
|
+
};
|
|
244
|
+
return models;
|
|
245
|
+
} finally {
|
|
246
|
+
clearTimeout(timer);
|
|
247
|
+
}
|
|
248
|
+
} catch (error) {
|
|
249
|
+
catalogCache = {
|
|
250
|
+
fetchedAt: Date.now(),
|
|
251
|
+
ttl: CATALOG_FAILURE_TTL_MS,
|
|
252
|
+
models: COPILOT_FALLBACK_MODELS
|
|
253
|
+
};
|
|
254
|
+
console.warn("Failed to fetch live GitHub Copilot models, using fallback list:", error instanceof Error ? error.message : error);
|
|
255
|
+
return COPILOT_FALLBACK_MODELS;
|
|
256
|
+
} finally {
|
|
257
|
+
inflightFetch = null;
|
|
258
|
+
}
|
|
259
|
+
})();
|
|
260
|
+
return inflightFetch;
|
|
261
|
+
}
|
|
262
|
+
//#endregion
|
|
263
|
+
export { buildGitHubCopilotOAuthFetch, clearCopilotCatalogCache, getAuthStorage, getCopilotModelCatalog, githubCopilotProvider, setAuthStorage };
|
|
264
|
+
|
|
265
|
+
//# sourceMappingURL=github-copilot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"github-copilot.js","names":[],"sources":["../../src/providers/github-copilot.ts"],"sourcesContent":["/**\n * GitHub Copilot OAuth Provider\n *\n * Uses OAuth tokens from AuthStorage to authenticate with GitHub Copilot's chat API.\n * The Copilot API speaks an OpenAI-compatible chat format, so we plug\n * `@ai-sdk/openai-compatible` into Copilot's API URL and use a custom fetch to inject\n * the bearer token and Copilot-specific headers.\n *\n * Inspired by:\n * - opencode: https://github.com/anomalyco/opencode/blob/dev/packages/opencode/src/plugin/github-copilot/copilot.ts\n * - pi-mono: https://github.com/badlogic/pi-mono/blob/main/packages/ai/src/utils/oauth/github-copilot.ts\n */\n\nimport { createOpenAICompatible } from '@ai-sdk/openai-compatible';\nimport type { MastraModelConfig } from '@mastra/core/llm';\nimport type { JSONSchema7 } from '@mastra/schema-compat';\nimport { applyCompatLayer, GoogleSchemaCompatLayer } from '@mastra/schema-compat';\nimport { wrapLanguageModel } from 'ai';\nimport type { LanguageModelMiddleware } from 'ai';\nimport { COPILOT_HEADERS, fetchCopilotModels, getGitHubCopilotBaseUrl } from '../auth/providers/github-copilot.js';\nimport type { CopilotModelEntry, GitHubCopilotCredentials } from '../auth/providers/github-copilot.js';\nimport { AuthStorage } from '../auth/storage.js';\nimport type { CredentialStore } from '../auth/types.js';\n\nconst COPILOT_PROVIDER_ID = 'github-copilot';\n\n// Singleton auth storage instance (shared with claude-max.ts / openai-codex.ts when not overridden).\nlet authStorageInstance: AuthStorage | null = null;\n\n/** Get or create the shared AuthStorage instance. */\nexport function getAuthStorage(): AuthStorage {\n if (!authStorageInstance) {\n authStorageInstance = new AuthStorage();\n }\n return authStorageInstance;\n}\n\n/** Set a custom AuthStorage instance (useful for tests / TUI integration). */\nexport function setAuthStorage(storage: AuthStorage | undefined): void {\n authStorageInstance = storage ?? null;\n}\n\n/**\n * Heuristic: did this request come from the agent (e.g. tool result follow-ups) rather\n * than a fresh user turn? Mirrors opencode's `isAgent` logic — Copilot bills these\n * differently via the `x-initiator` header.\n */\nfunction detectIsAgent(body: unknown): boolean {\n if (!body || typeof body !== 'object') return false;\n const obj = body as Record<string, unknown>;\n\n const messages = obj.messages;\n if (Array.isArray(messages) && messages.length > 0) {\n const last = messages[messages.length - 1] as { role?: string; content?: unknown };\n if (last?.role && last.role !== 'user') return true;\n if (Array.isArray(last?.content)) {\n // If the last user turn carries any tool_result parts, treat it as an agent turn.\n const hasToolResult = last.content.some(\n (part: unknown) => part && typeof part === 'object' && (part as { type?: string }).type === 'tool_result',\n );\n if (hasToolResult) return true;\n }\n }\n\n const input = obj.input;\n if (Array.isArray(input) && input.length > 0) {\n const last = input[input.length - 1] as { role?: string };\n if (last?.role && last.role !== 'user') return true;\n }\n\n return false;\n}\n\n/** Detect image/vision content in a request body. */\nfunction detectIsVision(body: unknown): boolean {\n if (!body || typeof body !== 'object') return false;\n const obj = body as Record<string, unknown>;\n\n const matchPart = (part: unknown): boolean => {\n if (!part || typeof part !== 'object') return false;\n const t = (part as { type?: string }).type;\n return t === 'image' || t === 'image_url' || t === 'input_image';\n };\n\n const messages = obj.messages;\n if (Array.isArray(messages)) {\n return messages.some(\n (msg: unknown) =>\n msg &&\n typeof msg === 'object' &&\n Array.isArray((msg as { content?: unknown }).content) &&\n ((msg as { content: unknown[] }).content as unknown[]).some(matchPart),\n );\n }\n\n const input = obj.input;\n if (Array.isArray(input)) {\n return input.some(\n (item: unknown) =>\n item &&\n typeof item === 'object' &&\n Array.isArray((item as { content?: unknown }).content) &&\n ((item as { content: unknown[] }).content as unknown[]).some(matchPart),\n );\n }\n\n return false;\n}\n\n/**\n * Build a fetch wrapper that authenticates with GitHub Copilot OAuth.\n *\n * - Injects the short-lived Copilot bearer token (auto-refreshed by AuthStorage).\n * - Adds the VS Code-like Copilot headers required by the API.\n * - Rewrites the request URL onto the per-token API base when `rewriteUrl` is true.\n */\nexport function buildGitHubCopilotOAuthFetch(\n opts: { authStorage?: CredentialStore; rewriteUrl?: boolean } = {},\n): typeof fetch {\n return (async (url: string | URL | Request, init?: Parameters<typeof fetch>[1]) => {\n const storage = opts.authStorage ?? getAuthStorage();\n storage.reload();\n\n const cred = storage.get(COPILOT_PROVIDER_ID);\n if (!cred || cred.type !== 'oauth') {\n throw new Error('Not logged in to GitHub Copilot. Run /login first.');\n }\n\n // getApiKey() refreshes the Copilot bearer if it has expired.\n const accessToken = await storage.getApiKey(COPILOT_PROVIDER_ID);\n if (!accessToken) {\n throw new Error('Failed to refresh GitHub Copilot token. Please /login again.');\n }\n storage.reload();\n\n const enterpriseUrl = (cred as GitHubCopilotCredentials).enterpriseUrl;\n\n let parsedBody: unknown;\n if (typeof init?.body === 'string') {\n try {\n parsedBody = JSON.parse(init.body);\n } catch {\n parsedBody = undefined;\n }\n }\n const isAgent = detectIsAgent(parsedBody);\n const isVision = detectIsVision(parsedBody);\n\n // Preserve non-auth headers from caller.\n const headers = new Headers();\n if (init?.headers) {\n const source =\n init.headers instanceof Headers\n ? init.headers\n : Array.isArray(init.headers)\n ? new Headers(init.headers as Array<[string, string]>)\n : new Headers(init.headers as Record<string, string>);\n source.forEach((value, key) => {\n const lower = key.toLowerCase();\n if (lower !== 'authorization' && lower !== 'x-api-key') {\n headers.set(key, value);\n }\n });\n }\n\n headers.set('Authorization', `Bearer ${accessToken}`);\n headers.set('x-initiator', isAgent ? 'agent' : 'user');\n headers.set('Openai-Intent', 'conversation-edits');\n if (isVision) {\n headers.set('Copilot-Vision-Request', 'true');\n }\n for (const [key, value] of Object.entries(COPILOT_HEADERS)) {\n // Only set if caller didn't already provide it (allow overrides for tests).\n if (!headers.has(key)) {\n headers.set(key, value);\n }\n }\n\n const finalUrl =\n opts.rewriteUrl !== false\n ? rewriteToCopilotBase(url, accessToken, enterpriseUrl)\n : url instanceof URL\n ? url\n : typeof url === 'string'\n ? new URL(url)\n : new URL((url as Request).url);\n\n try {\n return await fetch(finalUrl, { ...init, headers });\n } catch (error) {\n if (error && typeof error === 'object') {\n Object.assign(error as Record<string, unknown>, {\n requestUrl: finalUrl.toString(),\n });\n }\n throw error;\n }\n }) as typeof fetch;\n}\n\nfunction rewriteToCopilotBase(url: string | URL | Request, token: string, enterpriseDomain?: string): URL {\n const original = url instanceof URL ? url : new URL(typeof url === 'string' ? url : (url as Request).url);\n const base = new URL(getGitHubCopilotBaseUrl(token, enterpriseDomain));\n // Copilot's OpenAI-compatible API serves endpoints at the root of the base host\n // (`/chat/completions`, `/responses`, `/models`, ...) — not under a `/v1/` prefix\n // like api.openai.com does. The @ai-sdk/openai default baseURL is\n // `https://api.openai.com/v1`, so the SDK builds requests like\n // `https://api.openai.com/v1/chat/completions`. Strip the leading `/v1` segment\n // when rewriting onto the Copilot base or Copilot will return 404 Not Found.\n const pathname = original.pathname.replace(/^\\/v1(\\/|$)/, '/');\n return new URL(`${pathname}${original.search}`, base);\n}\n\nfunction isGeminiModel(modelId: string): boolean {\n return modelId.startsWith('gemini-');\n}\n\nfunction applyGeminiSchemaCompatToTools(modelId: string, tools: unknown): unknown {\n if (!Array.isArray(tools)) {\n return tools;\n }\n\n const compatLayer = new GoogleSchemaCompatLayer({\n provider: COPILOT_PROVIDER_ID,\n modelId,\n supportsStructuredOutputs: false,\n });\n\n return tools.map(tool => {\n if (!tool || typeof tool !== 'object' || (tool as { type?: unknown }).type !== 'function') {\n return tool;\n }\n\n const functionTool = tool as { inputSchema?: JSONSchema7 };\n if (!functionTool.inputSchema) {\n return tool;\n }\n\n return {\n ...functionTool,\n inputSchema: applyCompatLayer({\n schema: functionTool.inputSchema,\n compatLayers: [compatLayer],\n mode: 'aiSdkSchema',\n }).jsonSchema as JSONSchema7,\n };\n });\n}\n\n/** Middleware that prevents sending parameters Copilot's endpoint rejects. */\nfunction createCopilotMiddleware(modelId: string): LanguageModelMiddleware {\n return {\n specificationVersion: 'v3',\n transformParams: async ({ params }) => {\n if (params.temperature !== undefined && params.temperature !== null) {\n delete params.topP;\n }\n\n if (isGeminiModel(modelId)) {\n (params as { tools?: unknown }).tools = applyGeminiSchemaCompatToTools(\n modelId,\n (params as { tools?: unknown }).tools,\n );\n }\n\n return params;\n },\n };\n}\n\n/**\n * Creates a model that talks to GitHub Copilot using OAuth credentials.\n *\n * Copilot's `/chat/completions` endpoint is OpenAI-compatible, but GitHub Copilot\n * is not OpenAI. Use the generic OpenAI-compatible adapter with Copilot's base URL\n * instead of the OpenAI provider plus URL rewriting.\n */\nexport function githubCopilotProvider(\n modelId: string = 'gpt-4.1',\n options?: { headers?: Record<string, string>; authStorage?: CredentialStore },\n): MastraModelConfig {\n const headers = options?.headers;\n const copilot = createOpenAICompatible({\n name: COPILOT_PROVIDER_ID,\n baseURL: 'https://api.githubcopilot.com',\n apiKey: process.env.NODE_ENV === 'test' || process.env.VITEST ? 'test-api-key' : 'oauth-placeholder',\n headers,\n fetch:\n process.env.NODE_ENV === 'test' || process.env.VITEST\n ? undefined\n : (buildGitHubCopilotOAuthFetch({ rewriteUrl: false, authStorage: options?.authStorage }) as any),\n });\n\n return wrapLanguageModel({\n model: copilot.chatModel(modelId),\n middleware: [createCopilotMiddleware(modelId)],\n });\n}\n\n// ---------------------------------------------------------------------------\n// Live model catalog\n// ---------------------------------------------------------------------------\n\n/**\n * Hard-coded fallback advertised when the live `/models` request fails (network\n * down, expired token, etc.). Keep this conservative because the live catalog is\n * the source of truth for the user's currently-enabled Copilot models.\n *\n * Available across all paid Copilot tiers and free of premium-request charges.\n */\nconst COPILOT_FALLBACK_MODELS: CopilotModelEntry[] = [\n {\n id: 'gpt-4.1',\n name: 'GPT-4.1',\n vendor: 'OpenAI',\n supportedEndpoints: ['/chat/completions'],\n isAnthropicShaped: false,\n supportsVision: true,\n supportsToolCalls: true,\n },\n];\n\nconst CATALOG_TTL_MS = 10 * 60 * 1000;\nconst CATALOG_FAILURE_TTL_MS = 60 * 1000;\nconst CATALOG_FETCH_TIMEOUT_MS = 5_000;\n\ninterface CatalogCacheEntry {\n fetchedAt: number;\n ttl: number;\n models: CopilotModelEntry[];\n}\n\nlet catalogCache: CatalogCacheEntry | null = null;\nlet inflightFetch: Promise<CopilotModelEntry[]> | null = null;\n\n/** Reset the in-process Copilot catalog cache (test seam, also useful after logout). */\nexport function clearCopilotCatalogCache(): void {\n catalogCache = null;\n inflightFetch = null;\n}\n\n/**\n * Return the user's currently-available Copilot models.\n *\n * - Returns `[]` when the user is not logged in to GitHub Copilot.\n * - Returns the cached list when a recent fetch succeeded.\n * - On the cache-miss / expired path, fetches `/models` with a 5s timeout, filters\n * to picker-enabled and non-policy-disabled models, then caches for 10 minutes.\n * - On fetch failure, returns a small hard-coded fallback (so packs still work\n * offline) and caches that for 1 minute to avoid hammering the API.\n *\n * Concurrent calls during a fetch share the inflight promise.\n */\nexport async function getCopilotModelCatalog(opts: { authStorage?: AuthStorage } = {}): Promise<CopilotModelEntry[]> {\n const storage = opts.authStorage ?? getAuthStorage();\n storage.reload();\n\n const cred = storage.get(COPILOT_PROVIDER_ID);\n if (!cred || cred.type !== 'oauth') {\n return [];\n }\n\n const now = Date.now();\n if (catalogCache && now - catalogCache.fetchedAt < catalogCache.ttl) {\n return catalogCache.models;\n }\n\n if (inflightFetch) return inflightFetch;\n\n inflightFetch = (async (): Promise<CopilotModelEntry[]> => {\n try {\n // getApiKey() refreshes the Copilot bearer if it has expired.\n const accessToken = await storage.getApiKey(COPILOT_PROVIDER_ID);\n if (!accessToken) throw new Error('No Copilot bearer token');\n storage.reload();\n\n const refreshed = storage.get(COPILOT_PROVIDER_ID);\n const enterpriseUrl = (refreshed as GitHubCopilotCredentials | undefined)?.enterpriseUrl;\n const baseUrl = getGitHubCopilotBaseUrl(accessToken, enterpriseUrl);\n\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), CATALOG_FETCH_TIMEOUT_MS);\n try {\n const models = await fetchCopilotModels({\n baseUrl,\n bearerToken: accessToken,\n signal: controller.signal,\n });\n catalogCache = { fetchedAt: Date.now(), ttl: CATALOG_TTL_MS, models };\n return models;\n } finally {\n clearTimeout(timer);\n }\n } catch (error) {\n catalogCache = {\n fetchedAt: Date.now(),\n ttl: CATALOG_FAILURE_TTL_MS,\n models: COPILOT_FALLBACK_MODELS,\n };\n console.warn(\n 'Failed to fetch live GitHub Copilot models, using fallback list:',\n error instanceof Error ? error.message : error,\n );\n return COPILOT_FALLBACK_MODELS;\n } finally {\n inflightFetch = null;\n }\n })();\n\n return inflightFetch;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAwBA,MAAM,sBAAsB;AAG5B,IAAI,sBAA0C;;AAG9C,SAAgB,iBAA8B;CAC5C,IAAI,CAAC,qBACH,sBAAsB,IAAI,YAAY;CAExC,OAAO;AACT;;AAGA,SAAgB,eAAe,SAAwC;CACrE,sBAAsB,WAAW;AACnC;;;;;;AAOA,SAAS,cAAc,MAAwB;CAC7C,IAAI,CAAC,QAAQ,OAAO,SAAS,UAAU,OAAO;CAC9C,MAAM,MAAM;CAEZ,MAAM,WAAW,IAAI;CACrB,IAAI,MAAM,QAAQ,QAAQ,KAAK,SAAS,SAAS,GAAG;EAClD,MAAM,OAAO,SAAS,SAAS,SAAS;EACxC,IAAI,MAAM,QAAQ,KAAK,SAAS,QAAQ,OAAO;EAC/C,IAAI,MAAM,QAAQ,MAAM,OAAO,GAEP;OAAA,KAAK,QAAQ,MA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mB;KACtC;KACA,aAAa;KACb,QAAQ,WAAW;IACrB,CAAC;IACD,eAAe;KAAE,WAAW,KAAK,IAAI;KAAG,KAAK;KAAgB;IAAO;IACpE,OAAO;GACT,UAAU;IACR,aAAa,KAAK;GACpB;EACF,SAAS,OAAO;GACd,eAAe;IACb,WAAW,KAAK,IAAI;IACpB,KAAK;IACL,QAAQ;GACV;GACA,QAAQ,KACN,oEACA,iBAAiB,QAAQ,MAAM,UAAU,KAC3C;GACA,OAAO;EACT,UAAU;GACR,gBAAgB;EAClB;CACF,EAAA,CAAG;CAEH,OAAO;AACT"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI Codex OAuth Provider
|
|
3
|
+
*
|
|
4
|
+
* Uses OAuth tokens from AuthStorage to authenticate with ChatGPT Plus/Pro subscription.
|
|
5
|
+
* This allows access to OpenAI models through the ChatGPT OAuth flow.
|
|
6
|
+
*
|
|
7
|
+
* Inspired by opencode's Codex plugin implementation:
|
|
8
|
+
* https://github.com/sst/opencode/blob/main/packages/opencode/src/plugin/codex.ts
|
|
9
|
+
*/
|
|
10
|
+
import type { MastraModelConfig } from '@mastra/core/llm';
|
|
11
|
+
import type { LanguageModelMiddleware } from 'ai';
|
|
12
|
+
import { AuthStorage } from '../auth/storage.js';
|
|
13
|
+
import type { CredentialStore } from '../auth/types.js';
|
|
14
|
+
/**
|
|
15
|
+
* Get or create the shared AuthStorage instance
|
|
16
|
+
*/
|
|
17
|
+
export declare function getAuthStorage(): AuthStorage;
|
|
18
|
+
/**
|
|
19
|
+
* Set a custom AuthStorage instance (useful for TUI integration)
|
|
20
|
+
*/
|
|
21
|
+
export declare function setAuthStorage(storage: AuthStorage | undefined): void;
|
|
22
|
+
/** Valid thinking level values. */
|
|
23
|
+
export type ThinkingLevel = 'off' | 'low' | 'medium' | 'high' | 'xhigh';
|
|
24
|
+
export declare function getEffectiveThinkingLevel(modelId: string, level: ThinkingLevel): ThinkingLevel;
|
|
25
|
+
export declare const THINKING_LEVEL_TO_REASONING_EFFORT: Record<ThinkingLevel, string | undefined>;
|
|
26
|
+
/**
|
|
27
|
+
* Create Codex middleware with the given reasoning effort level.
|
|
28
|
+
*/
|
|
29
|
+
export declare function createCodexMiddleware(reasoningEffort?: string): LanguageModelMiddleware;
|
|
30
|
+
/**
|
|
31
|
+
* Build a fetch function that handles OpenAI Codex OAuth.
|
|
32
|
+
* Preserves non-authorization headers from init.
|
|
33
|
+
* When rewriteUrl is true (default), rewrites /v1/responses and /chat/completions
|
|
34
|
+
* to the Codex API endpoint. Set rewriteUrl: false for gateway usage where the
|
|
35
|
+
* SDK already targets the correct URL.
|
|
36
|
+
*/
|
|
37
|
+
export declare function buildOpenAICodexOAuthFetch(opts?: {
|
|
38
|
+
authStorage?: CredentialStore;
|
|
39
|
+
rewriteUrl?: boolean;
|
|
40
|
+
}): typeof fetch;
|
|
41
|
+
/**
|
|
42
|
+
* Build a fetch function for Stagehand-on-Codex.
|
|
43
|
+
*
|
|
44
|
+
* The Codex backend has two requirements that AI SDK's non-streaming
|
|
45
|
+
* `generateText` path doesn't naturally satisfy:
|
|
46
|
+
*
|
|
47
|
+
* 1. `stream: true` must be set on every request body.
|
|
48
|
+
* 2. The response is delivered as Server-Sent Events; AI SDK's
|
|
49
|
+
* non-streaming code path expects a single JSON body.
|
|
50
|
+
*
|
|
51
|
+
* This fetch forces streaming on the outgoing request, collects the SSE
|
|
52
|
+
* events, and synthesizes the non-streaming JSON shape that
|
|
53
|
+
* `@ai-sdk/openai`'s Responses API parser expects.
|
|
54
|
+
*
|
|
55
|
+
* Headers, OAuth refresh, and URL targeting are handled by the caller via
|
|
56
|
+
* `baseURL` / `headers` on the AI SDK provider; this fetch only injects the
|
|
57
|
+
* live OAuth bearer per call.
|
|
58
|
+
*/
|
|
59
|
+
export declare function buildCodexStagehandFetch(authStorage: AuthStorage): typeof fetch;
|
|
60
|
+
/**
|
|
61
|
+
* Creates an OpenAI model using ChatGPT OAuth authentication
|
|
62
|
+
* Uses OAuth tokens from AuthStorage (auto-refreshes when needed)
|
|
63
|
+
*
|
|
64
|
+
* IMPORTANT: This uses the Codex API endpoint, not the standard OpenAI API.
|
|
65
|
+
* URLs are rewritten from /v1/responses or /chat/completions to the Codex endpoint.
|
|
66
|
+
*/
|
|
67
|
+
export declare function openaiCodexProvider(modelId?: string, options?: {
|
|
68
|
+
thinkingLevel?: ThinkingLevel;
|
|
69
|
+
headers?: Record<string, string>;
|
|
70
|
+
authStorage?: CredentialStore;
|
|
71
|
+
}): MastraModelConfig;
|
|
72
|
+
//# sourceMappingURL=openai-codex.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai-codex.d.ts","sourceRoot":"","sources":["../../src/providers/openai-codex.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE1D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,IAAI,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAUxD;;GAEG;AACH,wBAAgB,cAAc,IAAI,WAAW,CAK5C;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,GAAG,IAAI,CAErE;AAOD,mCAAmC;AACnC,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;AAIxE,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,GAAG,aAAa,CAO9F;AAID,eAAO,MAAM,kCAAkC,EAAE,MAAM,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,CAMxF,CAAC;AAEF;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG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