@mastra/code-sdk 0.0.0-aggregate-trace-20261015182851
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/LICENSE.md +32 -0
- package/README.md +284 -0
- package/dist/acp/agent.d.ts +48 -0
- package/dist/acp/agent.d.ts.map +1 -0
- package/dist/acp/agent.js +416 -0
- package/dist/acp/agent.js.map +1 -0
- package/dist/acp/errors.d.ts +3 -0
- package/dist/acp/errors.d.ts.map +1 -0
- package/dist/acp/errors.js +14 -0
- package/dist/acp/errors.js.map +1 -0
- package/dist/acp/event-mapper.d.ts +28 -0
- package/dist/acp/event-mapper.d.ts.map +1 -0
- package/dist/acp/event-mapper.js +279 -0
- package/dist/acp/event-mapper.js.map +1 -0
- package/dist/acp/index.d.ts +9 -0
- package/dist/acp/index.d.ts.map +1 -0
- package/dist/acp/index.js +24 -0
- package/dist/acp/index.js.map +1 -0
- package/dist/acp/runtime.d.ts +5 -0
- package/dist/acp/runtime.d.ts.map +1 -0
- package/dist/acp/runtime.js +91 -0
- package/dist/acp/runtime.js.map +1 -0
- package/dist/acp/server.d.ts +4 -0
- package/dist/acp/server.d.ts.map +1 -0
- package/dist/acp/server.js +38 -0
- package/dist/acp/server.js.map +1 -0
- package/dist/acp/skills.d.ts +6 -0
- package/dist/acp/skills.d.ts.map +1 -0
- package/dist/acp/skills.js +33 -0
- package/dist/acp/skills.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/agent-connections/messaging-processor.d.ts +17 -0
- package/dist/agent-connections/messaging-processor.d.ts.map +1 -0
- package/dist/agent-connections/messaging-processor.js +134 -0
- package/dist/agent-connections/messaging-processor.js.map +1 -0
- package/dist/agent-connections/ownership.d.ts +24 -0
- package/dist/agent-connections/ownership.d.ts.map +1 -0
- package/dist/agent-connections/ownership.js +99 -0
- package/dist/agent-connections/ownership.js.map +1 -0
- package/dist/agent-connections/registry.d.ts +20 -0
- package/dist/agent-connections/registry.d.ts.map +1 -0
- package/dist/agent-connections/registry.js +170 -0
- package/dist/agent-connections/registry.js.map +1 -0
- package/dist/agent-connections/session-advertisement.d.ts +27 -0
- package/dist/agent-connections/session-advertisement.d.ts.map +1 -0
- package/dist/agent-connections/session-advertisement.js +89 -0
- package/dist/agent-connections/session-advertisement.js.map +1 -0
- package/dist/agent-connections/signal-provider.d.ts +141 -0
- package/dist/agent-connections/signal-provider.d.ts.map +1 -0
- package/dist/agent-connections/signal-provider.js +38 -0
- package/dist/agent-connections/signal-provider.js.map +1 -0
- package/dist/agent-connections/state-processor.d.ts +23 -0
- package/dist/agent-connections/state-processor.d.ts.map +1 -0
- package/dist/agent-connections/state-processor.js +273 -0
- package/dist/agent-connections/state-processor.js.map +1 -0
- package/dist/agent-connections/thread-state.d.ts +41 -0
- package/dist/agent-connections/thread-state.d.ts.map +1 -0
- package/dist/agent-connections/thread-state.js +160 -0
- package/dist/agent-connections/thread-state.js.map +1 -0
- package/dist/agent-connections/tools.d.ts +133 -0
- package/dist/agent-connections/tools.d.ts.map +1 -0
- package/dist/agent-connections/tools.js +552 -0
- package/dist/agent-connections/tools.js.map +1 -0
- package/dist/agent-connections/types.d.ts +99 -0
- package/dist/agent-connections/types.d.ts.map +1 -0
- package/dist/agent-connections/types.js +7 -0
- package/dist/agent-connections/types.js.map +1 -0
- package/dist/agent-connections/untrusted-text.d.ts +5 -0
- package/dist/agent-connections/untrusted-text.d.ts.map +1 -0
- package/dist/agent-connections/untrusted-text.js +22 -0
- package/dist/agent-connections/untrusted-text.js.map +1 -0
- package/dist/agents/background-completion-events.d.ts +16 -0
- package/dist/agents/background-completion-events.d.ts.map +1 -0
- package/dist/agents/background-completion-events.js +19 -0
- package/dist/agents/background-completion-events.js.map +1 -0
- package/dist/agents/background-completion.d.ts +9 -0
- package/dist/agents/background-completion.d.ts.map +1 -0
- package/dist/agents/background-completion.js +59 -0
- package/dist/agents/background-completion.js.map +1 -0
- package/dist/agents/context-audit.d.ts +84 -0
- package/dist/agents/context-audit.d.ts.map +1 -0
- package/dist/agents/context-audit.js +118 -0
- package/dist/agents/context-audit.js.map +1 -0
- package/dist/agents/credential-resolver.d.ts +67 -0
- package/dist/agents/credential-resolver.d.ts.map +1 -0
- package/dist/agents/credential-resolver.js +136 -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 +40 -0
- package/dist/agents/instructions.d.ts.map +1 -0
- package/dist/agents/instructions.js +63 -0
- package/dist/agents/instructions.js.map +1 -0
- package/dist/agents/mastracode-gateway.d.ts +76 -0
- package/dist/agents/mastracode-gateway.d.ts.map +1 -0
- package/dist/agents/mastracode-gateway.js +434 -0
- package/dist/agents/mastracode-gateway.js.map +1 -0
- package/dist/agents/memory.d.ts +39 -0
- package/dist/agents/memory.d.ts.map +1 -0
- package/dist/agents/memory.js +266 -0
- package/dist/agents/memory.js.map +1 -0
- package/dist/agents/model.d.ts +123 -0
- package/dist/agents/model.d.ts.map +1 -0
- package/dist/agents/model.js +295 -0
- package/dist/agents/model.js.map +1 -0
- package/dist/agents/modes/build.d.ts +12 -0
- package/dist/agents/modes/build.d.ts.map +1 -0
- package/dist/agents/modes/build.js +36 -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 +28 -0
- package/dist/agents/modes/explore.js.map +1 -0
- package/dist/agents/modes/plan.d.ts +8 -0
- package/dist/agents/modes/plan.d.ts.map +1 -0
- package/dist/agents/modes/plan.js +46 -0
- package/dist/agents/modes/plan.js.map +1 -0
- package/dist/agents/prompts/agent-instructions.d.ts +99 -0
- package/dist/agents/prompts/agent-instructions.d.ts.map +1 -0
- package/dist/agents/prompts/agent-instructions.js +275 -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 +54 -0
- package/dist/agents/prompts/index.d.ts.map +1 -0
- package/dist/agents/prompts/index.js +127 -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 +8 -0
- package/dist/agents/prompts/plan.d.ts.map +1 -0
- package/dist/agents/prompts/plan.js +129 -0
- package/dist/agents/prompts/plan.js.map +1 -0
- package/dist/agents/prompts/tool-guidance.d.ts +18 -0
- package/dist/agents/prompts/tool-guidance.d.ts.map +1 -0
- package/dist/agents/prompts/tool-guidance.js +181 -0
- package/dist/agents/prompts/tool-guidance.js.map +1 -0
- package/dist/agents/sandbox-filesystem.d.ts +151 -0
- package/dist/agents/sandbox-filesystem.d.ts.map +1 -0
- package/dist/agents/sandbox-filesystem.js +581 -0
- package/dist/agents/sandbox-filesystem.js.map +1 -0
- package/dist/agents/subagents/execute.d.ts +3 -0
- package/dist/agents/subagents/execute.d.ts.map +1 -0
- package/dist/agents/subagents/execute.js +27 -0
- package/dist/agents/subagents/execute.js.map +1 -0
- package/dist/agents/subagents/explore.d.ts +3 -0
- package/dist/agents/subagents/explore.d.ts.map +1 -0
- package/dist/agents/subagents/explore.js +18 -0
- package/dist/agents/subagents/explore.js.map +1 -0
- package/dist/agents/subagents/plan.d.ts +3 -0
- package/dist/agents/subagents/plan.d.ts.map +1 -0
- package/dist/agents/subagents/plan.js +18 -0
- package/dist/agents/subagents/plan.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 +12 -0
- package/dist/agents/tool-availability.d.ts.map +1 -0
- package/dist/agents/tool-availability.js +129 -0
- package/dist/agents/tool-availability.js.map +1 -0
- package/dist/agents/tools.d.ts +37 -0
- package/dist/agents/tools.d.ts.map +1 -0
- package/dist/agents/tools.js +131 -0
- package/dist/agents/tools.js.map +1 -0
- package/dist/agents/workflow-builder-agent.d.ts +2 -0
- package/dist/agents/workflow-builder-agent.d.ts.map +1 -0
- package/dist/agents/workflow-builder-agent.js +82 -0
- package/dist/agents/workflow-builder-agent.js.map +1 -0
- package/dist/agents/workspace.d.ts +33 -0
- package/dist/agents/workspace.d.ts.map +1 -0
- package/dist/agents/workspace.js +208 -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 +162 -0
- package/dist/analytics.js.map +1 -0
- package/dist/auth/account-rotation-processor.d.ts +182 -0
- package/dist/auth/account-rotation-processor.d.ts.map +1 -0
- package/dist/auth/account-rotation-processor.js +609 -0
- package/dist/auth/account-rotation-processor.js.map +1 -0
- package/dist/auth/account-routing-context.d.ts +13 -0
- package/dist/auth/account-routing-context.d.ts.map +1 -0
- package/dist/auth/account-routing-context.js +41 -0
- package/dist/auth/account-routing-context.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 +13 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +9 -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/provider-auth-error.d.ts +12 -0
- package/dist/auth/provider-auth-error.d.ts.map +1 -0
- package/dist/auth/provider-auth-error.js +16 -0
- package/dist/auth/provider-auth-error.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 +120 -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 +362 -0
- package/dist/auth/providers/github-copilot.js.map +1 -0
- package/dist/auth/providers/kimi-coding.d.ts +38 -0
- package/dist/auth/providers/kimi-coding.d.ts.map +1 -0
- package/dist/auth/providers/kimi-coding.js +228 -0
- package/dist/auth/providers/kimi-coding.js.map +1 -0
- package/dist/auth/providers/openai-codex.d.ts +141 -0
- package/dist/auth/providers/openai-codex.d.ts.map +1 -0
- package/dist/auth/providers/openai-codex.js +533 -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 +226 -0
- package/dist/auth/providers/xai.js.map +1 -0
- package/dist/auth/storage.d.ts +214 -0
- package/dist/auth/storage.d.ts.map +1 -0
- package/dist/auth/storage.js +774 -0
- package/dist/auth/storage.js.map +1 -0
- package/dist/auth/types.d.ts +164 -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 +12 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +20 -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/experimental-agent.d.ts +11 -0
- package/dist/experimental-agent.d.ts.map +1 -0
- package/dist/experimental-agent.js +36 -0
- package/dist/experimental-agent.js.map +1 -0
- package/dist/goal-manager.d.ts +114 -0
- package/dist/goal-manager.d.ts.map +1 -0
- package/dist/goal-manager.js +354 -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 +48 -0
- package/dist/headless/cli.d.ts.map +1 -0
- package/dist/headless/cli.js +239 -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 +203 -0
- package/dist/headless/flags.js.map +1 -0
- package/dist/headless/format.d.ts +39 -0
- package/dist/headless/format.d.ts.map +1 -0
- package/dist/headless/format.js +85 -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 +408 -0
- package/dist/headless/run-mc.js.map +1 -0
- package/dist/headless/types.d.ts +174 -0
- package/dist/headless/types.d.ts.map +1 -0
- package/dist/headless/types.js +19 -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 +80 -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 +129 -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 +54 -0
- package/dist/hooks/manager.d.ts.map +1 -0
- package/dist/hooks/manager.js +241 -0
- package/dist/hooks/manager.js.map +1 -0
- package/dist/hooks/types.d.ts +172 -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 +463 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1305 -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/knowledge-inspector.d.ts +123 -0
- package/dist/knowledge-inspector.d.ts.map +1 -0
- package/dist/knowledge-inspector.js +516 -0
- package/dist/knowledge-inspector.js.map +1 -0
- package/dist/knowledge-scope.d.ts +35 -0
- package/dist/knowledge-scope.d.ts.map +1 -0
- package/dist/knowledge-scope.js +47 -0
- package/dist/knowledge-scope.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 +77 -0
- package/dist/mcp/config.d.ts.map +1 -0
- package/dist/mcp/config.js +316 -0
- package/dist/mcp/config.js.map +1 -0
- package/dist/mcp/index.d.ts +6 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +3 -0
- package/dist/mcp/manager.d.ts +102 -0
- package/dist/mcp/manager.d.ts.map +1 -0
- package/dist/mcp/manager.js +650 -0
- package/dist/mcp/manager.js.map +1 -0
- package/dist/mcp/state.d.ts +35 -0
- package/dist/mcp/state.d.ts.map +1 -0
- package/dist/mcp/state.js +97 -0
- package/dist/mcp/state.js.map +1 -0
- package/dist/mcp/types.d.ts +139 -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 +20 -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 +47 -0
- package/dist/onboarding/om-settings.d.ts.map +1 -0
- package/dist/onboarding/om-settings.js +83 -0
- package/dist/onboarding/om-settings.js.map +1 -0
- package/dist/onboarding/pack-activation.d.ts +52 -0
- package/dist/onboarding/pack-activation.d.ts.map +1 -0
- package/dist/onboarding/pack-activation.js +108 -0
- package/dist/onboarding/pack-activation.js.map +1 -0
- package/dist/onboarding/packs.d.ts +102 -0
- package/dist/onboarding/packs.d.ts.map +1 -0
- package/dist/onboarding/packs.js +278 -0
- package/dist/onboarding/packs.js.map +1 -0
- package/dist/onboarding/settings.d.ts +538 -0
- package/dist/onboarding/settings.d.ts.map +1 -0
- package/dist/onboarding/settings.js +1060 -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 +142 -0
- package/dist/permissions.js.map +1 -0
- package/dist/plugin.d.ts +156 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +30 -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 +87 -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 +19 -0
- package/dist/plugins/loader.d.ts.map +1 -0
- package/dist/plugins/loader.js +260 -0
- package/dist/plugins/loader.js.map +1 -0
- package/dist/plugins/manager.d.ts +98 -0
- package/dist/plugins/manager.d.ts.map +1 -0
- package/dist/plugins/manager.js +456 -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/signal-lane.d.ts +58 -0
- package/dist/plugins/signal-lane.d.ts.map +1 -0
- package/dist/plugins/signal-lane.js +166 -0
- package/dist/plugins/signal-lane.js.map +1 -0
- package/dist/plugins/types.d.ts +81 -0
- package/dist/plugins/types.d.ts.map +1 -0
- package/dist/plugins/types.js +1 -0
- package/dist/process-memory-diagnostics.d.ts +135 -0
- package/dist/process-memory-diagnostics.d.ts.map +1 -0
- package/dist/process-memory-diagnostics.js +499 -0
- package/dist/process-memory-diagnostics.js.map +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 +144 -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 +102 -0
- package/dist/providers/amazon-bedrock.js.map +1 -0
- package/dist/providers/anthropic-prompt-cache.d.ts +19 -0
- package/dist/providers/anthropic-prompt-cache.d.ts.map +1 -0
- package/dist/providers/anthropic-prompt-cache.js +11 -0
- package/dist/providers/anthropic-prompt-cache.js.map +1 -0
- package/dist/providers/anthropic-thinking.d.ts +5 -0
- package/dist/providers/anthropic-thinking.d.ts.map +1 -0
- package/dist/providers/anthropic-thinking.js +25 -0
- package/dist/providers/anthropic-thinking.js.map +1 -0
- package/dist/providers/claude-max.d.ts +67 -0
- package/dist/providers/claude-max.d.ts.map +1 -0
- package/dist/providers/claude-max.js +226 -0
- package/dist/providers/claude-max.js.map +1 -0
- package/dist/providers/github-copilot-gateway.d.ts +35 -0
- package/dist/providers/github-copilot-gateway.d.ts.map +1 -0
- package/dist/providers/github-copilot-gateway.js +61 -0
- package/dist/providers/github-copilot-gateway.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 +318 -0
- package/dist/providers/github-copilot.js.map +1 -0
- package/dist/providers/google-thinking.d.ts +31 -0
- package/dist/providers/google-thinking.d.ts.map +1 -0
- package/dist/providers/google-thinking.js +67 -0
- package/dist/providers/google-thinking.js.map +1 -0
- package/dist/providers/kimi-coding.d.ts +14 -0
- package/dist/providers/kimi-coding.d.ts.map +1 -0
- package/dist/providers/kimi-coding.js +78 -0
- package/dist/providers/kimi-coding.js.map +1 -0
- package/dist/providers/model-ids.d.ts +30 -0
- package/dist/providers/model-ids.d.ts.map +1 -0
- package/dist/providers/model-ids.js +79 -0
- package/dist/providers/model-ids.js.map +1 -0
- package/dist/providers/openai-codex.d.ts +84 -0
- package/dist/providers/openai-codex.d.ts.map +1 -0
- package/dist/providers/openai-codex.js +347 -0
- package/dist/providers/openai-codex.js.map +1 -0
- package/dist/providers/provider-thinking.d.ts +23 -0
- package/dist/providers/provider-thinking.d.ts.map +1 -0
- package/dist/providers/provider-thinking.js +64 -0
- package/dist/providers/provider-thinking.js.map +1 -0
- package/dist/providers/thinking-request.d.ts +14 -0
- package/dist/providers/thinking-request.d.ts.map +1 -0
- package/dist/providers/thinking-request.js +90 -0
- package/dist/providers/thinking-request.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 +71 -0
- package/dist/providers/xai.js.map +1 -0
- package/dist/schedules/index.d.ts +10 -0
- package/dist/schedules/index.d.ts.map +1 -0
- package/dist/schedules/index.js +6 -0
- package/dist/schedules/interval.d.ts +49 -0
- package/dist/schedules/interval.d.ts.map +1 -0
- package/dist/schedules/interval.js +215 -0
- package/dist/schedules/interval.js.map +1 -0
- package/dist/schedules/prompt.d.ts +36 -0
- package/dist/schedules/prompt.d.ts.map +1 -0
- package/dist/schedules/prompt.js +39 -0
- package/dist/schedules/prompt.js.map +1 -0
- package/dist/schedules/run-script.d.ts +8 -0
- package/dist/schedules/run-script.d.ts.map +1 -0
- package/dist/schedules/run-script.js +83 -0
- package/dist/schedules/run-script.js.map +1 -0
- package/dist/schedules/scheduler.d.ts +101 -0
- package/dist/schedules/scheduler.d.ts.map +1 -0
- package/dist/schedules/scheduler.js +169 -0
- package/dist/schedules/scheduler.js.map +1 -0
- package/dist/schedules/tools.d.ts +57 -0
- package/dist/schedules/tools.d.ts.map +1 -0
- package/dist/schedules/tools.js +220 -0
- package/dist/schedules/tools.js.map +1 -0
- package/dist/schema.d.ts +499 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +134 -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/thinking-catalog.d.ts +4 -0
- package/dist/thinking-catalog.d.ts.map +1 -0
- package/dist/thinking-catalog.js +13 -0
- package/dist/thinking-catalog.js.map +1 -0
- package/dist/thinking.d.ts +37 -0
- package/dist/thinking.d.ts.map +1 -0
- package/dist/thinking.js +137 -0
- package/dist/thinking.js.map +1 -0
- package/dist/tool-names.d.ts +77 -0
- package/dist/tool-names.d.ts.map +1 -0
- package/dist/tool-names.js +56 -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 +80 -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 +114 -0
- package/dist/tools/web-search.d.ts.map +1 -0
- package/dist/tools/web-search.js +155 -0
- package/dist/tools/web-search.js.map +1 -0
- package/dist/tools/workflows/create-workflow.d.ts +7 -0
- package/dist/tools/workflows/create-workflow.d.ts.map +1 -0
- package/dist/tools/workflows/create-workflow.js +81 -0
- package/dist/tools/workflows/create-workflow.js.map +1 -0
- package/dist/tools/workflows/delete-workflow.d.ts +7 -0
- package/dist/tools/workflows/delete-workflow.d.ts.map +1 -0
- package/dist/tools/workflows/delete-workflow.js +21 -0
- package/dist/tools/workflows/delete-workflow.js.map +1 -0
- package/dist/tools/workflows/ephemeral-memory.d.ts +28 -0
- package/dist/tools/workflows/ephemeral-memory.d.ts.map +1 -0
- package/dist/tools/workflows/ephemeral-memory.js +44 -0
- package/dist/tools/workflows/ephemeral-memory.js.map +1 -0
- package/dist/tools/workflows/extract-json-schema.d.ts +12 -0
- package/dist/tools/workflows/extract-json-schema.d.ts.map +1 -0
- package/dist/tools/workflows/extract-json-schema.js +22 -0
- package/dist/tools/workflows/extract-json-schema.js.map +1 -0
- package/dist/tools/workflows/get-workflow.d.ts +11 -0
- package/dist/tools/workflows/get-workflow.d.ts.map +1 -0
- package/dist/tools/workflows/get-workflow.js +34 -0
- package/dist/tools/workflows/get-workflow.js.map +1 -0
- package/dist/tools/workflows/list-available-agents.d.ts +8 -0
- package/dist/tools/workflows/list-available-agents.d.ts.map +1 -0
- package/dist/tools/workflows/list-available-agents.js +32 -0
- package/dist/tools/workflows/list-available-agents.js.map +1 -0
- package/dist/tools/workflows/list-available-classifiers.d.ts +19 -0
- package/dist/tools/workflows/list-available-classifiers.d.ts.map +1 -0
- package/dist/tools/workflows/list-available-classifiers.js +56 -0
- package/dist/tools/workflows/list-available-classifiers.js.map +1 -0
- package/dist/tools/workflows/list-available-tools.d.ts +9 -0
- package/dist/tools/workflows/list-available-tools.d.ts.map +1 -0
- package/dist/tools/workflows/list-available-tools.js +40 -0
- package/dist/tools/workflows/list-available-tools.js.map +1 -0
- package/dist/tools/workflows/list-available-workflows.d.ts +9 -0
- package/dist/tools/workflows/list-available-workflows.d.ts.map +1 -0
- package/dist/tools/workflows/list-available-workflows.js +32 -0
- package/dist/tools/workflows/list-available-workflows.js.map +1 -0
- package/dist/tools/workflows/list-workflows.d.ts +9 -0
- package/dist/tools/workflows/list-workflows.d.ts.map +1 -0
- package/dist/tools/workflows/list-workflows.js +33 -0
- package/dist/tools/workflows/list-workflows.js.map +1 -0
- package/dist/tools/workflows/run-workflow.d.ts +9 -0
- package/dist/tools/workflows/run-workflow.d.ts.map +1 -0
- package/dist/tools/workflows/run-workflow.js +52 -0
- package/dist/tools/workflows/run-workflow.js.map +1 -0
- package/dist/tools/workflows/save-workflow.d.ts +1125 -0
- package/dist/tools/workflows/save-workflow.d.ts.map +1 -0
- package/dist/tools/workflows/save-workflow.js +28 -0
- package/dist/tools/workflows/save-workflow.js.map +1 -0
- package/dist/tools/workflows/tool-ids.d.ts +16 -0
- package/dist/tools/workflows/tool-ids.d.ts.map +1 -0
- package/dist/tools/workflows/tool-ids.js +20 -0
- package/dist/tools/workflows/tool-ids.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/discarding-scores-storage.d.ts +33 -0
- package/dist/utils/discarding-scores-storage.d.ts.map +1 -0
- package/dist/utils/discarding-scores-storage.js +54 -0
- package/dist/utils/discarding-scores-storage.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 +196 -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/maintenance-lock.d.ts +42 -0
- package/dist/utils/maintenance-lock.d.ts.map +1 -0
- package/dist/utils/maintenance-lock.js +199 -0
- package/dist/utils/maintenance-lock.js.map +1 -0
- package/dist/utils/notification-dispatch.d.ts +59 -0
- package/dist/utils/notification-dispatch.d.ts.map +1 -0
- package/dist/utils/notification-dispatch.js +109 -0
- package/dist/utils/notification-dispatch.js.map +1 -0
- package/dist/utils/open-url.d.ts +10 -0
- package/dist/utils/open-url.d.ts.map +1 -0
- package/dist/utils/open-url.js +30 -0
- package/dist/utils/open-url.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 +59 -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/prune-cli.d.ts +24 -0
- package/dist/utils/prune-cli.d.ts.map +1 -0
- package/dist/utils/prune-cli.js +125 -0
- package/dist/utils/prune-cli.js.map +1 -0
- package/dist/utils/signals-pubsub.d.ts +101 -0
- package/dist/utils/signals-pubsub.d.ts.map +1 -0
- package/dist/utils/signals-pubsub.js +410 -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 +142 -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 +109 -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 +121 -0
- package/dist/utils/storage-maintenance.d.ts.map +1 -0
- package/dist/utils/storage-maintenance.js +355 -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 +151 -0
- package/dist/utils/update-check.d.ts.map +1 -0
- package/dist/utils/update-check.js +432 -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/dist/workflows/register-primitives.d.ts +52 -0
- package/dist/workflows/register-primitives.d.ts.map +1 -0
- package/dist/workflows/register-primitives.js +40 -0
- package/dist/workflows/register-primitives.js.map +1 -0
- package/dist/workflows/service.d.ts +64 -0
- package/dist/workflows/service.d.ts.map +1 -0
- package/dist/workflows/service.js +53 -0
- package/dist/workflows/service.js.map +1 -0
- package/package.json +107 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1305 @@
|
|
|
1
|
+
import { DEFAULT_OM_MODEL_ID, validateConfigDirName } from "./constants.js";
|
|
2
|
+
import { detectProject, getObservabilityDatabasePath, getResourceIdOverride, getStorageConfig } from "./utils/project.js";
|
|
3
|
+
import { isKimiCodingDeviceId } from "./auth/providers/kimi-coding.js";
|
|
4
|
+
import { AuthStorage } from "./auth/storage.js";
|
|
5
|
+
import { setAuthStorage } from "./providers/openai-codex.js";
|
|
6
|
+
import { getAvailableOmPacks, resolveAutoOMModelId } from "./onboarding/packs.js";
|
|
7
|
+
import { MASTRA_GATEWAY_PROVIDER, OBSERVABILITY_AUTH_PREFIX, loadSettings, resolveOmRoleModel, saveSettings } from "./onboarding/settings.js";
|
|
8
|
+
import { resolveExperimentalAgent, validateExperimentalAgent, wrapExperimentalAgent } from "./experimental-agent.js";
|
|
9
|
+
import { createSessionThreadAdvertisement } from "./agent-connections/session-advertisement.js";
|
|
10
|
+
import { AgentConnectionsSignalProvider } from "./agent-connections/signal-provider.js";
|
|
11
|
+
import { createBackgroundCompletionEvents } from "./agents/background-completion-events.js";
|
|
12
|
+
import { createBackgroundCompletionCallbacks } from "./agents/background-completion.js";
|
|
13
|
+
import { hasCredentialStoreProvider, withCredentialTenantPreparation } from "./agents/credential-resolver.js";
|
|
14
|
+
import { getDynamicWorkspace, getGoalJudgeTools } from "./agents/workspace.js";
|
|
15
|
+
import { createGitRefReminderReader, instructionSourcePaths, loadSessionInstructions, sessionInstructionRoots } from "./agents/prompts/agent-instructions.js";
|
|
16
|
+
import { getDynamicInstructions } from "./agents/instructions.js";
|
|
17
|
+
import { LOCAL_KNOWLEDGE_ORG_ID } from "./knowledge-scope.js";
|
|
18
|
+
import { createAmazonBedrockGateway } from "./providers/amazon-bedrock-gateway.js";
|
|
19
|
+
import { setAuthStorage as setAuthStorage$1 } from "./providers/claude-max.js";
|
|
20
|
+
import { setAuthStorage as setAuthStorage$2 } from "./providers/github-copilot.js";
|
|
21
|
+
import { setAuthStorage as setAuthStorage$3 } from "./providers/kimi-coding.js";
|
|
22
|
+
import { setAuthStorage as setAuthStorage$4 } from "./providers/xai.js";
|
|
23
|
+
import { createMastraCodeGateway, getDynamicModel, getGoalJudgeModel, resolveModel } from "./agents/model.js";
|
|
24
|
+
import { getDynamicMemory, hasSubconsciousTools } from "./agents/memory.js";
|
|
25
|
+
import { buildMode } from "./agents/modes/build.js";
|
|
26
|
+
import { fastMode } from "./agents/modes/explore.js";
|
|
27
|
+
import { createPlanMode } from "./agents/modes/plan.js";
|
|
28
|
+
import { executeSubagent } from "./agents/subagents/execute.js";
|
|
29
|
+
import { exploreSubagent } from "./agents/subagents/explore.js";
|
|
30
|
+
import { planSubagent } from "./agents/subagents/plan.js";
|
|
31
|
+
import { attachOMThreadStatePersistence, restoreOMThreadStateForCurrentThread } from "./agents/thread-caveman-state.js";
|
|
32
|
+
import { createDynamicTools, createToolHooks } from "./agents/tools.js";
|
|
33
|
+
import { AccountRotationProcessor, AccountStartNoticeProcessor, MODEL_FALLBACK_STATE_KEY } from "./auth/account-rotation-processor.js";
|
|
34
|
+
import { createOutcomeScorer } from "./evals/scorers/outcome.js";
|
|
35
|
+
import { createEfficiencyScorer } from "./evals/scorers/efficiency.js";
|
|
36
|
+
import "./evals/scorers/index.js";
|
|
37
|
+
import { HookManager } from "./hooks/manager.js";
|
|
38
|
+
import "./hooks/index.js";
|
|
39
|
+
import { KnowledgeInspectorError, createKnowledgeInspector } from "./knowledge-inspector.js";
|
|
40
|
+
import { createMcpManager } from "./mcp/manager.js";
|
|
41
|
+
import "./mcp/index.js";
|
|
42
|
+
import { getToolCategory } from "./permissions.js";
|
|
43
|
+
import { PluginManager } from "./plugins/manager.js";
|
|
44
|
+
import { PluginSignalLane } from "./plugins/signal-lane.js";
|
|
45
|
+
import { PlanRejectionAbortProcessor } from "./processors/plan-rejection-abort.js";
|
|
46
|
+
import { createGitHubCopilotGateway } from "./providers/github-copilot-gateway.js";
|
|
47
|
+
import { assembleSchedulePrompt } from "./schedules/prompt.js";
|
|
48
|
+
import { ThreadScheduler, scheduleSignalAttributes, shortScheduleId } from "./schedules/scheduler.js";
|
|
49
|
+
import { runScript } from "./schedules/run-script.js";
|
|
50
|
+
import { createScheduleTools } from "./schedules/tools.js";
|
|
51
|
+
import "./schedules/index.js";
|
|
52
|
+
import { stateSchema } from "./schema.js";
|
|
53
|
+
import { mastraBrand } from "./theme-palette.js";
|
|
54
|
+
import { DiscardingScoresStorage } from "./utils/discarding-scores-storage.js";
|
|
55
|
+
import { syncGateways } from "./utils/gateway-sync.js";
|
|
56
|
+
import { registerSessionAndWaitForMaintenance, unregisterSession } from "./utils/maintenance-lock.js";
|
|
57
|
+
import { createSignalsPubSub } from "./utils/signals-pubsub.js";
|
|
58
|
+
import { createResourceNotificationDispatcher, shouldHoldNotificationDelivery } from "./utils/notification-dispatch.js";
|
|
59
|
+
import { DEFAULT_RETENTION, createStorageMaintenance, resolveLocalDbFiles } from "./utils/storage-maintenance.js";
|
|
60
|
+
import { createStorage, createVectorStore } from "./utils/storage-factory.js";
|
|
61
|
+
import { acquireThreadLock, releaseThreadLock } from "./utils/thread-lock.js";
|
|
62
|
+
import { registerWorkflowBuilderPrimitives } from "./workflows/register-primitives.js";
|
|
63
|
+
import { autoApprovePolicy, denyPolicy, permissionModeToPolicy } from "./headless/policy.js";
|
|
64
|
+
import { runMC } from "./headless/run-mc.js";
|
|
65
|
+
import { formatHuman, formatJsonl, renderJsonResult, renderTextResult } from "./headless/format.js";
|
|
66
|
+
import { hasHeadlessFlag, runMCCli } from "./headless/cli.js";
|
|
67
|
+
import "./headless/index.js";
|
|
68
|
+
import path from "path";
|
|
69
|
+
import { createHash, randomUUID } from "crypto";
|
|
70
|
+
import { statSync } from "fs";
|
|
71
|
+
import { homedir, hostname } from "os";
|
|
72
|
+
import { PROVIDER_REGISTRY, findGatewayForModel, getGatewayId } from "@mastra/core/llm";
|
|
73
|
+
import { readFile } from "fs/promises";
|
|
74
|
+
import { AgentController, migratePersistedModelSelection } from "@mastra/core/agent-controller";
|
|
75
|
+
import { createCodingAgent } from "@mastra/core/coding-agent";
|
|
76
|
+
import { Knowledge } from "@mastra/core/knowledge";
|
|
77
|
+
import { Mastra } from "@mastra/core/mastra";
|
|
78
|
+
import { defaultNotificationDeliveryDecision } from "@mastra/core/notifications";
|
|
79
|
+
import { AgentsMDInjector, CyberRefusalHandler, ProviderHistoryCompat, StreamErrorRetryProcessor, createBackgroundWorkSignalProcessor, isBadRequestError } from "@mastra/core/processors";
|
|
80
|
+
import { RequestContext } from "@mastra/core/request-context";
|
|
81
|
+
import { TaskSignalProvider } from "@mastra/core/signals";
|
|
82
|
+
import { MastraCompositeStore } from "@mastra/core/storage";
|
|
83
|
+
import { DEFAULT_GOAL_JUDGE_PROMPT } from "@mastra/core/tools";
|
|
84
|
+
import { DuckDBStore } from "@mastra/duckdb";
|
|
85
|
+
import { GithubSignals } from "@mastra/github-signals";
|
|
86
|
+
import { LibSQLStore, LibSQLVector } from "@mastra/libsql";
|
|
87
|
+
import { MastraPlatformExporter, MastraStorageExporter, Observability, SensitiveDataFilter } from "@mastra/observability";
|
|
88
|
+
import { PostgresStore } from "@mastra/pg";
|
|
89
|
+
//#region src/index.ts
|
|
90
|
+
const CODE_AGENT_ID = "code-agent";
|
|
91
|
+
const MASTRACODE_TRANSIENT_CONNECTION_MAX_RETRIES = 10;
|
|
92
|
+
const MASTRACODE_MAX_PROCESSOR_RETRIES = 64;
|
|
93
|
+
const MASTRACODE_TRANSIENT_CONNECTION_RETRY_INITIAL_DELAY_MS = 500;
|
|
94
|
+
const MASTRACODE_TRANSIENT_CONNECTION_RETRY_MAX_DELAY_MS = 3e4;
|
|
95
|
+
const TRANSIENT_CONNECTION_ERROR_CODES = /* @__PURE__ */ new Set(["ECONNRESET", "EPIPE"]);
|
|
96
|
+
const TRANSIENT_CONNECTION_MESSAGE_PATTERN = /econnreset|socket hang up|write epipe|other side closed/i;
|
|
97
|
+
const isTransientServerStatus = (status) => status >= 500 && status < 600;
|
|
98
|
+
const TRANSIENT_SERVER_ERROR_MESSAGE_PATTERN = /internal server|server error|api may be experiencing issues/i;
|
|
99
|
+
/**
|
|
100
|
+
* Matcher for transient connection failures. Cause-chain traversal is handled
|
|
101
|
+
* by `StreamErrorRetryProcessor.isRetryableStreamError`, which calls each
|
|
102
|
+
* matcher at every level of the cause chain.
|
|
103
|
+
*/
|
|
104
|
+
/**
|
|
105
|
+
* Read the session state fields the AgentsMDInjector callbacks need from the
|
|
106
|
+
* controller request context (set by hosts like the factory review flow).
|
|
107
|
+
*/
|
|
108
|
+
function getInjectorSessionState(requestContext) {
|
|
109
|
+
return (requestContext?.get("controller"))?.getState();
|
|
110
|
+
}
|
|
111
|
+
function isTransientConnectionError(error) {
|
|
112
|
+
if (!error) return false;
|
|
113
|
+
const code = typeof error === "object" && "code" in error ? error.code : void 0;
|
|
114
|
+
if (typeof code === "string" && TRANSIENT_CONNECTION_ERROR_CODES.has(code.toUpperCase())) return true;
|
|
115
|
+
const message = error instanceof Error ? error.message : void 0;
|
|
116
|
+
if (typeof message === "string" && TRANSIENT_CONNECTION_MESSAGE_PATTERN.test(message)) return true;
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
function isTransientServerError(error) {
|
|
120
|
+
if (!error) return false;
|
|
121
|
+
const errorObj = typeof error === "object" ? error : void 0;
|
|
122
|
+
if (typeof errorObj?.status === "number" && isTransientServerStatus(errorObj.status) || typeof errorObj?.statusCode === "number" && isTransientServerStatus(errorObj.statusCode)) return true;
|
|
123
|
+
const message = error instanceof Error ? error.message : void 0;
|
|
124
|
+
return typeof message === "string" && TRANSIENT_SERVER_ERROR_MESSAGE_PATTERN.test(message);
|
|
125
|
+
}
|
|
126
|
+
function getTransientRetryDelay(retryCount) {
|
|
127
|
+
return Math.min(MASTRACODE_TRANSIENT_CONNECTION_RETRY_INITIAL_DELAY_MS * Math.pow(2, retryCount), MASTRACODE_TRANSIENT_CONNECTION_RETRY_MAX_DELAY_MS);
|
|
128
|
+
}
|
|
129
|
+
function emitTransientRetry(error, retryCount, delayMs, requestContext) {
|
|
130
|
+
(requestContext?.get("controller"))?.emitEvent?.({
|
|
131
|
+
type: "error",
|
|
132
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
133
|
+
retryable: true,
|
|
134
|
+
retryDelay: delayMs,
|
|
135
|
+
retryAttempt: retryCount + 1,
|
|
136
|
+
maxRetries: MASTRACODE_TRANSIENT_CONNECTION_MAX_RETRIES
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
/** Short deterministic hash (sha256, first 12 hex chars) matching project.ts shortHash style. */
|
|
140
|
+
function shortHash(input) {
|
|
141
|
+
return createHash("sha256").update(input).digest("hex").slice(0, 12);
|
|
142
|
+
}
|
|
143
|
+
function applyModeDefaultsToModes(modes, modeDefaults) {
|
|
144
|
+
return modes.map((mode) => {
|
|
145
|
+
const savedModel = modeDefaults[mode.id];
|
|
146
|
+
if (!savedModel) return mode;
|
|
147
|
+
return {
|
|
148
|
+
...mode,
|
|
149
|
+
defaultModelId: savedModel
|
|
150
|
+
};
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
function addPluginToolsToModeAllowlists(modes, pluginToolNames) {
|
|
154
|
+
if (pluginToolNames.length === 0) return modes;
|
|
155
|
+
return modes.map((mode) => {
|
|
156
|
+
if (!mode.availableTools) return mode;
|
|
157
|
+
return {
|
|
158
|
+
...mode,
|
|
159
|
+
availableTools: Array.from(/* @__PURE__ */ new Set([...mode.availableTools, ...pluginToolNames]))
|
|
160
|
+
};
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
function createAuthStorage() {
|
|
164
|
+
const authStorage = new AuthStorage();
|
|
165
|
+
setAuthStorage$1(authStorage);
|
|
166
|
+
setAuthStorage(authStorage);
|
|
167
|
+
setAuthStorage$2(authStorage);
|
|
168
|
+
setAuthStorage$3(authStorage);
|
|
169
|
+
setAuthStorage$4(authStorage);
|
|
170
|
+
return authStorage;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Resolve cloud observability credentials for the MastraPlatformExporter.
|
|
174
|
+
* Priority: per-resource settings > MASTRACODE_* environment variables > undefined (no exporter).
|
|
175
|
+
*
|
|
176
|
+
* The env vars are deliberately namespaced `MASTRACODE_*`, not `MASTRA_*`: the
|
|
177
|
+
* cwd `.env` is loaded into `process.env`, so reading `MASTRA_PROJECT_ID` /
|
|
178
|
+
* `MASTRA_CLOUD_ACCESS_TOKEN` would export Mastra Code's own traces into
|
|
179
|
+
* whatever Mastra project the user happens to be working in (and crash on
|
|
180
|
+
* project ids the exporter rejects).
|
|
181
|
+
*/
|
|
182
|
+
function resolveCloudObservabilityConfig(settings, authStorage, resourceId, env = process.env) {
|
|
183
|
+
const resourceConfig = settings.observability.resources[resourceId];
|
|
184
|
+
if (resourceConfig) {
|
|
185
|
+
const token = authStorage.getStoredApiKey(`${OBSERVABILITY_AUTH_PREFIX}${resourceId}`);
|
|
186
|
+
if (token) return {
|
|
187
|
+
accessToken: token,
|
|
188
|
+
projectId: resourceConfig.projectId
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
const accessToken = env.MASTRACODE_CLOUD_ACCESS_TOKEN?.trim();
|
|
192
|
+
if (!accessToken) return void 0;
|
|
193
|
+
return {
|
|
194
|
+
accessToken,
|
|
195
|
+
projectId: env.MASTRACODE_PROJECT_ID?.trim() || void 0
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Base factory: builds every shared MastraCode resource (storage, observability,
|
|
200
|
+
* memory, MCP, providers, gateways, agent, modes) and the {@link AgentController}, but
|
|
201
|
+
* does NOT call `init()` or create a session. The controller is returned inert so
|
|
202
|
+
* the composition layer can decide its Mastra ownership and session model.
|
|
203
|
+
*
|
|
204
|
+
* See {@link bootLocalAgentController} (Case 3) and `mountAgentControllerOnMastra` (Cases 1 & 2).
|
|
205
|
+
*/
|
|
206
|
+
/**
|
|
207
|
+
* `instanceof` checks against Mastra classes are unreliable here: published
|
|
208
|
+
* packages pin exact `@mastra/core` versions, so a user's dependency graph can
|
|
209
|
+
* contain multiple copies of core (and peer-keyed copies of `@mastra/libsql` /
|
|
210
|
+
* `@mastra/pg`). A store built against one copy fails `instanceof` against
|
|
211
|
+
* another — the injected instance then silently fell through to the
|
|
212
|
+
* StorageConfig path and crashed on `config.url`. These structural checks work
|
|
213
|
+
* across duplicated copies.
|
|
214
|
+
*/
|
|
215
|
+
function isInjectedStorageInstance(storage) {
|
|
216
|
+
if (!storage) return false;
|
|
217
|
+
if (storage instanceof MastraCompositeStore) return true;
|
|
218
|
+
const candidate = storage;
|
|
219
|
+
return typeof candidate.init === "function" && typeof candidate.__registerMastra === "function";
|
|
220
|
+
}
|
|
221
|
+
/** Cross-copy-safe class check: walks the prototype chain by constructor name. */
|
|
222
|
+
function hasAncestorClassNamed(value, className) {
|
|
223
|
+
for (let proto = Object.getPrototypeOf(value); proto; proto = Object.getPrototypeOf(proto)) if (proto.constructor?.name === className) return true;
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
function resolveInjectedStorageBackend(storage, configuredBackend) {
|
|
227
|
+
if (configuredBackend) return configuredBackend;
|
|
228
|
+
if (storage instanceof LibSQLStore || hasAncestorClassNamed(storage, "LibSQLStore")) return "libsql";
|
|
229
|
+
if (storage instanceof PostgresStore || hasAncestorClassNamed(storage, "PostgresStore")) return "pg";
|
|
230
|
+
throw new Error("storageBackend is required when injecting a custom storage instance.");
|
|
231
|
+
}
|
|
232
|
+
/** Whether the model router would resolve `modelId` through a gateway outside `sdkGatewayIds`. */
|
|
233
|
+
function routesToOtherGateway(modelId, gateways, sdkGatewayIds) {
|
|
234
|
+
try {
|
|
235
|
+
return !sdkGatewayIds.has(getGatewayId(findGatewayForModel(modelId, gateways)));
|
|
236
|
+
} catch (error) {
|
|
237
|
+
if (error?.id === "MODEL_ROUTER_NO_GATEWAY_FOUND") return false;
|
|
238
|
+
throw error;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
async function createMastraCodeAgentController(config) {
|
|
242
|
+
const cwd = config?.cwd ?? process.cwd();
|
|
243
|
+
const homeDir = config?.homeDir ?? config?.initialState?.homeDir;
|
|
244
|
+
const configDir = config?.configDir ?? ".mastracode";
|
|
245
|
+
const modeless = config?.modes === false;
|
|
246
|
+
let activeSession;
|
|
247
|
+
const liveSessions = /* @__PURE__ */ new Set();
|
|
248
|
+
let pluginRuntimeController;
|
|
249
|
+
if (configDir !== ".mastracode") validateConfigDirName(configDir);
|
|
250
|
+
if (!config?.disableEnvFile) try {
|
|
251
|
+
process.loadEnvFile(path.join(cwd, ".env"));
|
|
252
|
+
} catch {}
|
|
253
|
+
const authStorage = createAuthStorage();
|
|
254
|
+
const globalSettings = loadSettings(config?.settingsPath);
|
|
255
|
+
const experimentalAgent = resolveExperimentalAgent(globalSettings);
|
|
256
|
+
const backgroundToolsEnabled = globalSettings.backgroundTools?.enabled ?? false;
|
|
257
|
+
const storedGatewayKey = authStorage.getStoredApiKey(MASTRA_GATEWAY_PROVIDER);
|
|
258
|
+
const storedGatewayUrl = globalSettings.memoryGateway?.baseUrl;
|
|
259
|
+
if (storedGatewayKey) process.env["MASTRA_GATEWAY_API_KEY"] ??= storedGatewayKey;
|
|
260
|
+
if (storedGatewayUrl) process.env["MASTRA_GATEWAY_URL"] ??= storedGatewayUrl;
|
|
261
|
+
if (!hasCredentialStoreProvider()) try {
|
|
262
|
+
const registry = PROVIDER_REGISTRY;
|
|
263
|
+
const providerEnvVars = {};
|
|
264
|
+
for (const [provider, cfg] of Object.entries(registry)) {
|
|
265
|
+
const envVars = cfg?.apiKeyEnvVar;
|
|
266
|
+
providerEnvVars[provider] = Array.isArray(envVars) ? envVars[0] : envVars;
|
|
267
|
+
}
|
|
268
|
+
providerEnvVars[MASTRA_GATEWAY_PROVIDER] ??= "MASTRA_GATEWAY_API_KEY";
|
|
269
|
+
authStorage.loadStoredApiKeysIntoEnv(providerEnvVars);
|
|
270
|
+
} catch {
|
|
271
|
+
authStorage.loadStoredApiKeysIntoEnv({
|
|
272
|
+
[MASTRA_GATEWAY_PROVIDER]: "MASTRA_GATEWAY_API_KEY",
|
|
273
|
+
anthropic: "ANTHROPIC_API_KEY",
|
|
274
|
+
openai: "OPENAI_API_KEY",
|
|
275
|
+
google: "GOOGLE_GENERATIVE_AI_API_KEY",
|
|
276
|
+
cerebras: "CEREBRAS_API_KEY",
|
|
277
|
+
deepseek: "DEEPSEEK_API_KEY"
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
const mgApiKey = process.env["MASTRA_GATEWAY_API_KEY"] ?? storedGatewayKey;
|
|
281
|
+
const mastraCodeGateway = createMastraCodeGateway({
|
|
282
|
+
mastraGatewayBaseUrl: (process.env["MASTRA_GATEWAY_URL"] ?? storedGatewayUrl ?? "https://gateway-api.mastra.ai").replace(/\/+$/, "").replace(/\/v1$/, ""),
|
|
283
|
+
mastraGatewayApiKey: mgApiKey,
|
|
284
|
+
routeThroughMastraGateway: false,
|
|
285
|
+
settingsPath: config?.settingsPath
|
|
286
|
+
});
|
|
287
|
+
const amazonBedrockGateway = createAmazonBedrockGateway();
|
|
288
|
+
const githubCopilotGateway = createGitHubCopilotGateway();
|
|
289
|
+
const project = detectProject(cwd);
|
|
290
|
+
const resourceIdOverride = getResourceIdOverride(project.rootPath, configDir);
|
|
291
|
+
if (resourceIdOverride) {
|
|
292
|
+
project.resourceId = resourceIdOverride;
|
|
293
|
+
project.resourceIdOverride = true;
|
|
294
|
+
}
|
|
295
|
+
const cloudObservabilityConfig = resolveCloudObservabilityConfig(globalSettings, authStorage, project.resourceId);
|
|
296
|
+
const sessionId = `mastracode-session-${shortHash(project.resourceId)}`;
|
|
297
|
+
const ownerId = `mastracode-${shortHash(`${hostname()}\0${project.rootPath}`)}`;
|
|
298
|
+
const useCrossAgentSignals = config?.crossAgentSignals ?? globalSettings.signals?.experimentalCrossAgentSignals ?? false;
|
|
299
|
+
const configuredPubSub = config?.pubsub;
|
|
300
|
+
const useUnixSocketPubSub = (config?.unixSocketPubSub ?? globalSettings.signals?.unixSocketPubSub ?? false) && process.platform !== "win32";
|
|
301
|
+
const ownSignalsPubSub = !configuredPubSub && useUnixSocketPubSub ? createSignalsPubSub(project.resourceId, { sharedAgentDiscovery: useCrossAgentSignals }) : void 0;
|
|
302
|
+
const signalsPubSub = configuredPubSub ?? ownSignalsPubSub;
|
|
303
|
+
const crossProcessPubSub = config?.crossProcessPubSub ?? Boolean(ownSignalsPubSub);
|
|
304
|
+
if (crossProcessPubSub && !signalsPubSub) throw new Error("crossProcessPubSub requires a pubsub instance");
|
|
305
|
+
const useScheduleTools = config?.scheduleTools ?? globalSettings.signals?.experimentalScheduleTools ?? false;
|
|
306
|
+
const injectedStorage = isInjectedStorageInstance(config?.storage) ? config.storage : void 0;
|
|
307
|
+
const storageConfig = injectedStorage ? void 0 : config?.storage ?? getStorageConfig(project.rootPath, globalSettings.storage, configDir);
|
|
308
|
+
if (!injectedStorage) await registerSessionAndWaitForMaintenance({ onWait: (pid) => console.error(`Waiting for storage maintenance (mastracode prune${pid === -1 ? "" : `, PID ${pid}`}) to finish. Press Ctrl+C to give up.`) });
|
|
309
|
+
let storageResult;
|
|
310
|
+
if (injectedStorage) storageResult = {
|
|
311
|
+
storage: injectedStorage,
|
|
312
|
+
backend: resolveInjectedStorageBackend(injectedStorage, config?.storageBackend)
|
|
313
|
+
};
|
|
314
|
+
else try {
|
|
315
|
+
storageResult = await createStorage(storageConfig);
|
|
316
|
+
} catch (error) {
|
|
317
|
+
unregisterSession();
|
|
318
|
+
throw error;
|
|
319
|
+
}
|
|
320
|
+
const storageWarning = storageResult.warning;
|
|
321
|
+
let observabilityDomain;
|
|
322
|
+
let observabilityWarning;
|
|
323
|
+
if (globalSettings.observability.localTracing) try {
|
|
324
|
+
const observabilityDuckDB = new DuckDBStore({
|
|
325
|
+
id: "mastra-code-observability",
|
|
326
|
+
path: getObservabilityDatabasePath()
|
|
327
|
+
});
|
|
328
|
+
await observabilityDuckDB.db.getConnection();
|
|
329
|
+
observabilityDomain = observabilityDuckDB.observability;
|
|
330
|
+
} catch (err) {
|
|
331
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
332
|
+
if (/lock|locked|busy/i.test(message)) observabilityWarning = "Observability unavailable — another MastraCode instance holds the database lock. Traces, scores, and feedback will not be recorded in this session.";
|
|
333
|
+
else observabilityWarning = `Observability unavailable — DuckDB initialization failed: ${message}`;
|
|
334
|
+
}
|
|
335
|
+
const scoresStorage = new DiscardingScoresStorage();
|
|
336
|
+
const storage = new MastraCompositeStore({
|
|
337
|
+
id: "mastra-code-storage",
|
|
338
|
+
default: storageResult.storage,
|
|
339
|
+
domains: {
|
|
340
|
+
observability: observabilityDomain ?? false,
|
|
341
|
+
scores: scoresStorage
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
const observability = new Observability({ configs: { default: {
|
|
345
|
+
serviceName: "mastracode",
|
|
346
|
+
requestContextKeys: [
|
|
347
|
+
"controller.threadId",
|
|
348
|
+
"controller.resourceId",
|
|
349
|
+
"controller.session.modeId",
|
|
350
|
+
"controller.controllerId",
|
|
351
|
+
"controller.state.projectName",
|
|
352
|
+
"controller.state.gitBranch",
|
|
353
|
+
"controller.session.modelId",
|
|
354
|
+
"controller.state.subagentModelId",
|
|
355
|
+
"controller.state.yolo",
|
|
356
|
+
"controller.state.thinkingLevel",
|
|
357
|
+
"controller.state.smartEditing",
|
|
358
|
+
"controller.state.omScope",
|
|
359
|
+
"om.observer.selectionMode",
|
|
360
|
+
"om.observer.effectiveModelId",
|
|
361
|
+
"om.reflector.selectionMode",
|
|
362
|
+
"om.reflector.effectiveModelId",
|
|
363
|
+
"controller.state.observationThreshold",
|
|
364
|
+
"controller.state.reflectionThreshold"
|
|
365
|
+
],
|
|
366
|
+
exporters: [...observabilityDomain ? [new MastraStorageExporter({ strategy: "event-sourced" })] : [], new MastraPlatformExporter({
|
|
367
|
+
...cloudObservabilityConfig,
|
|
368
|
+
resolveFromEnv: false
|
|
369
|
+
})],
|
|
370
|
+
spanOutputProcessors: [new SensitiveDataFilter()]
|
|
371
|
+
} } });
|
|
372
|
+
const vector = config?.vector ?? (storageConfig ? await createVectorStore(storageConfig, storageResult.backend) : void 0);
|
|
373
|
+
const storageMaintenance = createStorageMaintenance({
|
|
374
|
+
storage: storageResult.storage,
|
|
375
|
+
backend: storageResult.backend,
|
|
376
|
+
retention: DEFAULT_RETENTION,
|
|
377
|
+
localDbFiles: storageConfig ? resolveLocalDbFiles(storageConfig, storageResult.backend) : [],
|
|
378
|
+
closeVector: vector instanceof LibSQLVector ? () => vector.close() : void 0
|
|
379
|
+
});
|
|
380
|
+
const configuredKnowledgeKey = config?.knowledge?.key.trim();
|
|
381
|
+
if (config?.knowledge && !configuredKnowledgeKey) throw new Error("knowledge.key must be a non-empty string.");
|
|
382
|
+
const knowledge = config?.knowledge?.instance ?? (process.env.MASTRACODE_EXPERIMENTAL_SUBCONSCIOUS === "1" ? new Knowledge({
|
|
383
|
+
id: "mastracode",
|
|
384
|
+
name: "MastraCode Knowledge",
|
|
385
|
+
storage
|
|
386
|
+
}) : void 0);
|
|
387
|
+
const knowledgeKey = configuredKnowledgeKey ?? "default";
|
|
388
|
+
const dynamicMemory = config?.memory === void 0 ? getDynamicMemory(storage, vector, config?.settingsPath, { disableSettingsOmSeed: config?.disableSettingsOmSeed }, knowledge) : void 0;
|
|
389
|
+
const memory = config?.memory === false ? void 0 : config?.memory ?? (dynamicMemory && Object.assign(withCredentialTenantPreparation(dynamicMemory), { settled: dynamicMemory.settled }));
|
|
390
|
+
const hasSubconscious = config?.memory === void 0 ? (state) => hasSubconsciousTools(vector, state) : false;
|
|
391
|
+
const mcpManager = config?.disableMcp ? void 0 : createMcpManager(project.rootPath, configDir, config?.mcpServers, globalSettings.mcp);
|
|
392
|
+
const hookManager = config?.disableHooks ? void 0 : new HookManager(project.rootPath, "session-init", configDir, homeDir, project.isWorktree ? {
|
|
393
|
+
path: project.rootPath,
|
|
394
|
+
branch: project.gitBranch,
|
|
395
|
+
mainRepoPath: project.mainRepoPath
|
|
396
|
+
} : void 0);
|
|
397
|
+
const pluginManager = config?.disablePlugins ? void 0 : config?.pluginManager ?? new PluginManager({
|
|
398
|
+
projectRoot: project.rootPath,
|
|
399
|
+
configDir,
|
|
400
|
+
homeDir
|
|
401
|
+
});
|
|
402
|
+
pluginManager?.setRuntime({
|
|
403
|
+
getController: () => pluginRuntimeController,
|
|
404
|
+
getActiveSession: () => activeSession,
|
|
405
|
+
getStorage: () => ({
|
|
406
|
+
storage,
|
|
407
|
+
storageBackend: storageResult.backend,
|
|
408
|
+
vector
|
|
409
|
+
})
|
|
410
|
+
});
|
|
411
|
+
const loadedPlugins = pluginManager ? await pluginManager.reload() : [];
|
|
412
|
+
const pluginTools = pluginManager?.getPluginTools() ?? {};
|
|
413
|
+
const outcomeScorer = createOutcomeScorer();
|
|
414
|
+
const efficiencyScorer = createEfficiencyScorer();
|
|
415
|
+
const ownsNotificationDispatch = !configuredPubSub;
|
|
416
|
+
const dispatchLeasePubSub = ownsNotificationDispatch && !ownSignalsPubSub && process.platform !== "win32" ? createSignalsPubSub(project.resourceId) : void 0;
|
|
417
|
+
const notificationDispatcher = createResourceNotificationDispatcher({
|
|
418
|
+
getMastra: () => controller.getMastra(),
|
|
419
|
+
getResourceIds: () => [...liveSessions].map((session) => session.identity.getResourceId()),
|
|
420
|
+
leases: ownsNotificationDispatch ? (ownSignalsPubSub ?? dispatchLeasePubSub)?.getLeaseProvider() : void 0,
|
|
421
|
+
owner: `${ownerId}:${process.pid}:${randomUUID()}`,
|
|
422
|
+
onError: (error) => console.warn("Notification dispatch failed:", error)
|
|
423
|
+
});
|
|
424
|
+
const getWakeStreamOptions = async ({ resourceId, threadId }) => {
|
|
425
|
+
const session = await controller.getSessionByResource(resourceId);
|
|
426
|
+
if (!session) return void 0;
|
|
427
|
+
const targetThread = await session.thread.getById({ threadId });
|
|
428
|
+
const metadata = targetThread?.resourceId === resourceId ? targetThread.metadata : void 0;
|
|
429
|
+
const modes = controller.listModes();
|
|
430
|
+
const savedModeId = metadata?.currentModeId;
|
|
431
|
+
const defaultMode = modes.find((mode) => mode.default) ?? modes[0];
|
|
432
|
+
const modeId = typeof savedModeId === "string" && modes.some((mode) => mode.id === savedModeId) ? savedModeId : defaultMode?.id ?? session.mode.get();
|
|
433
|
+
const persistedModelId = metadata ? await migratePersistedModelSelection({
|
|
434
|
+
getMetadata: async () => (await session.thread.getById({ threadId }))?.metadata ?? {},
|
|
435
|
+
modeId,
|
|
436
|
+
set: (key, value) => session.thread.setSettingOn({
|
|
437
|
+
threadId,
|
|
438
|
+
key,
|
|
439
|
+
value
|
|
440
|
+
}),
|
|
441
|
+
threadId,
|
|
442
|
+
validModeIds: modes.map((mode) => mode.id)
|
|
443
|
+
}) : void 0;
|
|
444
|
+
const defaultModeModelId = modes.find((mode) => mode.id === modeId)?.defaultModelId;
|
|
445
|
+
const modelId = persistedModelId ?? defaultModeModelId ?? session.model.get() ?? "";
|
|
446
|
+
const baseState = { ...session.state.get() };
|
|
447
|
+
delete baseState.modelRoute;
|
|
448
|
+
delete baseState.mastracodePendingModelFallback;
|
|
449
|
+
const persistedSandboxPaths = metadata?.sandboxAllowedPaths;
|
|
450
|
+
baseState.sandboxAllowedPaths = Array.isArray(persistedSandboxPaths) && persistedSandboxPaths.every((path) => typeof path === "string") ? persistedSandboxPaths : [];
|
|
451
|
+
const persistedStateKeys = [
|
|
452
|
+
"thinkingLevel",
|
|
453
|
+
"notifications",
|
|
454
|
+
"modelRoute",
|
|
455
|
+
MODEL_FALLBACK_STATE_KEY
|
|
456
|
+
];
|
|
457
|
+
for (const key of persistedStateKeys) {
|
|
458
|
+
const value = metadata?.[key];
|
|
459
|
+
if (value !== void 0) baseState[key] = value;
|
|
460
|
+
}
|
|
461
|
+
let notificationState = baseState;
|
|
462
|
+
const getNotificationState = () => ({ ...notificationState });
|
|
463
|
+
const setNotificationState = async (updates) => {
|
|
464
|
+
notificationState = {
|
|
465
|
+
...notificationState,
|
|
466
|
+
...updates
|
|
467
|
+
};
|
|
468
|
+
if (session.thread.getId() === threadId) await session.state.set(updates);
|
|
469
|
+
};
|
|
470
|
+
const updateNotificationState = async (updater) => {
|
|
471
|
+
const update = await updater(getNotificationState());
|
|
472
|
+
if (update.updates) await setNotificationState(update.updates);
|
|
473
|
+
for (const event of update.events ?? []) if (session.thread.getId() === threadId) session.emit(event);
|
|
474
|
+
return update.result;
|
|
475
|
+
};
|
|
476
|
+
const requestContext = new RequestContext();
|
|
477
|
+
const agentControllerContext = {
|
|
478
|
+
controllerId: controller.id,
|
|
479
|
+
state: getNotificationState(),
|
|
480
|
+
getState: getNotificationState,
|
|
481
|
+
setState: setNotificationState,
|
|
482
|
+
updateState: updateNotificationState,
|
|
483
|
+
getThreadSetting: (key) => session.thread.getSettingOn({
|
|
484
|
+
threadId,
|
|
485
|
+
key
|
|
486
|
+
}),
|
|
487
|
+
setThreadSetting: (setting) => session.thread.setSettingOn({
|
|
488
|
+
threadId,
|
|
489
|
+
key: setting.key,
|
|
490
|
+
value: setting.value
|
|
491
|
+
}),
|
|
492
|
+
isThreadActive: () => session.thread.getId() === threadId,
|
|
493
|
+
threadId,
|
|
494
|
+
resourceId,
|
|
495
|
+
session: {
|
|
496
|
+
id: session.identity.getId(),
|
|
497
|
+
ownerId: session.identity.getOwnerId(),
|
|
498
|
+
modeId,
|
|
499
|
+
modelId,
|
|
500
|
+
state: {
|
|
501
|
+
get: getNotificationState,
|
|
502
|
+
set: setNotificationState,
|
|
503
|
+
update: updateNotificationState
|
|
504
|
+
}
|
|
505
|
+
},
|
|
506
|
+
workspace: session.getWorkspace(),
|
|
507
|
+
emitEvent: (event) => {
|
|
508
|
+
if (session.thread.getId() === threadId) session.emit(event);
|
|
509
|
+
},
|
|
510
|
+
getSubagentModelId: (params) => {
|
|
511
|
+
const agentType = params?.agentType;
|
|
512
|
+
const perType = agentType ? metadata?.[`subagentModelId_${agentType}`] : void 0;
|
|
513
|
+
const global = metadata?.subagentModelId;
|
|
514
|
+
if (typeof perType === "string") return perType;
|
|
515
|
+
if (typeof global === "string") return global;
|
|
516
|
+
return session.thread.getId() === threadId ? session.subagents.model.get(params ?? {}) : null;
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
requestContext.set("controller", agentControllerContext);
|
|
520
|
+
await config?.prepareWakeRequestContext?.({
|
|
521
|
+
requestContext,
|
|
522
|
+
resourceId,
|
|
523
|
+
threadId
|
|
524
|
+
});
|
|
525
|
+
return {
|
|
526
|
+
memory: {
|
|
527
|
+
thread: threadId,
|
|
528
|
+
resource: resourceId
|
|
529
|
+
},
|
|
530
|
+
requestContext,
|
|
531
|
+
maxSteps: 1e3,
|
|
532
|
+
savePerStep: false,
|
|
533
|
+
requireToolApproval: notificationState.yolo !== true,
|
|
534
|
+
modelSettings: { temperature: 1 }
|
|
535
|
+
};
|
|
536
|
+
};
|
|
537
|
+
const threadScheduler = new ThreadScheduler({
|
|
538
|
+
assemblePrompt: (schedule) => assembleSchedulePrompt(schedule, {
|
|
539
|
+
cwd: project.rootPath,
|
|
540
|
+
runScript,
|
|
541
|
+
readFile: (absPath) => readFile(absPath, "utf8")
|
|
542
|
+
}),
|
|
543
|
+
deliver: async (schedule, assembled) => {
|
|
544
|
+
const target = {
|
|
545
|
+
resourceId: schedule.resourceId,
|
|
546
|
+
threadId: schedule.threadId
|
|
547
|
+
};
|
|
548
|
+
const streamOptions = await getWakeStreamOptions(target);
|
|
549
|
+
const accepted = await codeAgent.sendSignal({
|
|
550
|
+
type: "user",
|
|
551
|
+
tagName: "user",
|
|
552
|
+
contents: assembled.prompt,
|
|
553
|
+
attributes: scheduleSignalAttributes(schedule, assembled)
|
|
554
|
+
}, {
|
|
555
|
+
...target,
|
|
556
|
+
ifActive: { behavior: "deliver" },
|
|
557
|
+
ifIdle: {
|
|
558
|
+
behavior: "wake",
|
|
559
|
+
...streamOptions ? { streamOptions } : {}
|
|
560
|
+
}
|
|
561
|
+
}).accepted;
|
|
562
|
+
if (accepted.action === "blocked" || accepted.action === "discard") throw new Error(`the agent did not accept the prompt (${accepted.action})`);
|
|
563
|
+
},
|
|
564
|
+
onError: (error, schedule) => {
|
|
565
|
+
console.warn(`Schedule ${shortScheduleId(schedule.id)} failed to fire:`, error);
|
|
566
|
+
}
|
|
567
|
+
});
|
|
568
|
+
const scheduleTools = useScheduleTools ? createScheduleTools({
|
|
569
|
+
scheduler: threadScheduler,
|
|
570
|
+
fileOptions: () => ({
|
|
571
|
+
cwd: project.rootPath,
|
|
572
|
+
homeDir: homedir(),
|
|
573
|
+
fileExists: (absPath) => {
|
|
574
|
+
try {
|
|
575
|
+
return statSync(absPath).isFile();
|
|
576
|
+
} catch {
|
|
577
|
+
return false;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
})
|
|
581
|
+
}) : void 0;
|
|
582
|
+
const githubSignals = globalSettings.signals?.experimentalGithubSignals && !config?.disableGithubSignals ? new GithubSignals({
|
|
583
|
+
cwd: project.rootPath,
|
|
584
|
+
pollIntervalMs: globalSettings.signals.githubPollIntervalMs,
|
|
585
|
+
gitcrawlCommand: process.env.MASTRACODE_GITCRAWL_BIN ?? process.env.GITCRAWL_BIN ?? process.env.MASTRACODE_GITCRAWL_COMMAND ?? process.env.GITCRAWL_COMMAND,
|
|
586
|
+
getNotificationStreamOptions: getWakeStreamOptions
|
|
587
|
+
}) : void 0;
|
|
588
|
+
const mastraCodeInputProcessors = [
|
|
589
|
+
...Array.isArray(config?.inputProcessors) ? config.inputProcessors : [],
|
|
590
|
+
new PlanRejectionAbortProcessor(),
|
|
591
|
+
...backgroundToolsEnabled ? [createBackgroundWorkSignalProcessor()] : [],
|
|
592
|
+
new AgentsMDInjector({
|
|
593
|
+
isEnabled: ({ requestContext }) => {
|
|
594
|
+
const state = getInjectorSessionState(requestContext);
|
|
595
|
+
return state?.untrustedCheckout !== true || typeof state?.baseRef === "string";
|
|
596
|
+
},
|
|
597
|
+
getBasePath: ({ requestContext }) => getInjectorSessionState(requestContext)?.projectPath ?? project.rootPath,
|
|
598
|
+
getReader: ({ requestContext }) => {
|
|
599
|
+
const state = getInjectorSessionState(requestContext);
|
|
600
|
+
if (state?.untrustedCheckout !== true || typeof state?.baseRef !== "string") return void 0;
|
|
601
|
+
const projectPath = state?.projectPath ?? project.rootPath;
|
|
602
|
+
const [primary] = sessionInstructionRoots(projectPath, state.instructionRoots);
|
|
603
|
+
const reader = createGitRefReminderReader(primary, state.baseRef);
|
|
604
|
+
if (primary === projectPath) return reader;
|
|
605
|
+
const outsidePrimary = (filePath) => {
|
|
606
|
+
const inProject = path.relative(projectPath, filePath);
|
|
607
|
+
const inPrimary = path.relative(primary, filePath);
|
|
608
|
+
const under = (rel) => rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel);
|
|
609
|
+
return under(inProject) && !under(inPrimary);
|
|
610
|
+
};
|
|
611
|
+
return {
|
|
612
|
+
...reader,
|
|
613
|
+
pathExists: (filePath) => !outsidePrimary(filePath) && reader.pathExists(filePath),
|
|
614
|
+
isDirectory: (filePath) => !outsidePrimary(filePath) && reader.isDirectory(filePath)
|
|
615
|
+
};
|
|
616
|
+
},
|
|
617
|
+
getIgnoredInstructionPaths: ({ requestContext }) => {
|
|
618
|
+
const state = getInjectorSessionState(requestContext);
|
|
619
|
+
const projectPath = state?.projectPath ?? project.rootPath;
|
|
620
|
+
const untrusted = state?.untrustedCheckout === true && typeof state?.baseRef === "string";
|
|
621
|
+
const roots = sessionInstructionRoots(projectPath, state?.instructionRoots);
|
|
622
|
+
return instructionSourcePaths(loadSessionInstructions({
|
|
623
|
+
workingDir: projectPath,
|
|
624
|
+
instructionRoots: state?.instructionRoots,
|
|
625
|
+
untrustedCheckout: untrusted,
|
|
626
|
+
baseRef: untrusted ? state?.baseRef : void 0
|
|
627
|
+
}), roots);
|
|
628
|
+
}
|
|
629
|
+
})
|
|
630
|
+
];
|
|
631
|
+
const disabledBuiltinTools = new Set(config?.disableBuiltinTools ?? []);
|
|
632
|
+
const taskSignalProvider = new TaskSignalProvider();
|
|
633
|
+
if (disabledBuiltinTools.size > 0) {
|
|
634
|
+
const taskTools = Object.entries(taskSignalProvider.getTools?.() ?? {});
|
|
635
|
+
const enabledTaskTools = Object.fromEntries(taskTools.filter(([id]) => !disabledBuiltinTools.has(id)));
|
|
636
|
+
taskSignalProvider.getTools = () => enabledTaskTools;
|
|
637
|
+
}
|
|
638
|
+
const agentConnectionsSignalProvider = useCrossAgentSignals ? new AgentConnectionsSignalProvider(config?.agentConnections) : void 0;
|
|
639
|
+
const NO_PLUGIN_PROCESSORS = {
|
|
640
|
+
input: [],
|
|
641
|
+
output: []
|
|
642
|
+
};
|
|
643
|
+
let pluginProcessorReadWarned = false;
|
|
644
|
+
const pluginSignalLane = pluginManager ? new PluginSignalLane({ reservedProviderIds: [
|
|
645
|
+
taskSignalProvider.id,
|
|
646
|
+
...agentConnectionsSignalProvider ? [agentConnectionsSignalProvider.id] : [],
|
|
647
|
+
...githubSignals ? [githubSignals.id] : []
|
|
648
|
+
] }) : void 0;
|
|
649
|
+
let unsubscribePluginReload;
|
|
650
|
+
/**
|
|
651
|
+
* Plugin processors are read through a function so that enabling, disabling or
|
|
652
|
+
* updating a plugin takes effect on the next request rather than requiring a
|
|
653
|
+
* new agent. This runs before every LLM call, and also outside the request
|
|
654
|
+
* path when the Agent catalogues its configured processors — where a throw is
|
|
655
|
+
* swallowed into a debug log. So it only reads already-resolved state: no
|
|
656
|
+
* filesystem, no network, no construction, and it never throws.
|
|
657
|
+
*/
|
|
658
|
+
const readPluginProcessors = () => {
|
|
659
|
+
try {
|
|
660
|
+
return pluginManager?.getPluginProcessors() ?? NO_PLUGIN_PROCESSORS;
|
|
661
|
+
} catch (error) {
|
|
662
|
+
if (!pluginProcessorReadWarned) {
|
|
663
|
+
pluginProcessorReadWarned = true;
|
|
664
|
+
console.warn("Failed to read plugin processors:", error);
|
|
665
|
+
}
|
|
666
|
+
return NO_PLUGIN_PROCESSORS;
|
|
667
|
+
}
|
|
668
|
+
};
|
|
669
|
+
const codeAgent = wrapExperimentalAgent(createCodingAgent({
|
|
670
|
+
id: CODE_AGENT_ID,
|
|
671
|
+
name: "Code Agent",
|
|
672
|
+
workspace: void 0,
|
|
673
|
+
instructions: async ({ requestContext }) => {
|
|
674
|
+
const configured = config?.hostInstructions;
|
|
675
|
+
return getDynamicInstructions({
|
|
676
|
+
requestContext,
|
|
677
|
+
hostInstructions: typeof configured === "function" ? await configured({ requestContext }) : configured,
|
|
678
|
+
coAuthor: config?.coAuthor,
|
|
679
|
+
hasSubconscious,
|
|
680
|
+
hasSubagents: subagents.length > 0,
|
|
681
|
+
disabledBuiltinTools: config?.disableBuiltinTools
|
|
682
|
+
});
|
|
683
|
+
},
|
|
684
|
+
model: withCredentialTenantPreparation((ctx) => getDynamicModel(ctx, config?.settingsPath, { modeless })),
|
|
685
|
+
notifications: { deliveryPolicy: { decide: async (input) => {
|
|
686
|
+
const decision = defaultNotificationDeliveryDecision(input);
|
|
687
|
+
if (!input.record.resourceId) return decision;
|
|
688
|
+
const streamOptions = await getWakeStreamOptions({
|
|
689
|
+
resourceId: input.record.resourceId,
|
|
690
|
+
threadId: input.record.threadId
|
|
691
|
+
});
|
|
692
|
+
const withOptions = streamOptions ? {
|
|
693
|
+
...decision,
|
|
694
|
+
streamOptions
|
|
695
|
+
} : decision;
|
|
696
|
+
if (!ownsNotificationDispatch) return withOptions;
|
|
697
|
+
return shouldHoldNotificationDelivery({
|
|
698
|
+
resourceId: input.record.resourceId,
|
|
699
|
+
ownedHere: streamOptions !== void 0,
|
|
700
|
+
dispatcher: notificationDispatcher
|
|
701
|
+
}) ? {
|
|
702
|
+
...withOptions,
|
|
703
|
+
hold: true
|
|
704
|
+
} : withOptions;
|
|
705
|
+
} } },
|
|
706
|
+
tools: createDynamicTools(mcpManager, config?.extraTools, config?.disabledTools, storage, pluginTools, backgroundToolsEnabled, scheduleTools),
|
|
707
|
+
hooks: createToolHooks(hookManager, config?.postToolObserver),
|
|
708
|
+
scorers: {
|
|
709
|
+
outcome: {
|
|
710
|
+
scorer: outcomeScorer,
|
|
711
|
+
sampling: { type: "none" }
|
|
712
|
+
},
|
|
713
|
+
efficiency: {
|
|
714
|
+
scorer: efficiencyScorer,
|
|
715
|
+
sampling: {
|
|
716
|
+
type: "ratio",
|
|
717
|
+
rate: .3
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
},
|
|
721
|
+
signals: [
|
|
722
|
+
taskSignalProvider,
|
|
723
|
+
...agentConnectionsSignalProvider ? [agentConnectionsSignalProvider] : [],
|
|
724
|
+
...githubSignals ? [githubSignals] : []
|
|
725
|
+
],
|
|
726
|
+
goal: {
|
|
727
|
+
judge: withCredentialTenantPreparation((ctx) => getGoalJudgeModel(ctx, config?.settingsPath)),
|
|
728
|
+
maxRuns: globalSettings.models.goalMaxTurns ?? 50,
|
|
729
|
+
maxSteps: 1e3,
|
|
730
|
+
prompt: DEFAULT_GOAL_JUDGE_PROMPT,
|
|
731
|
+
tools: getGoalJudgeTools
|
|
732
|
+
},
|
|
733
|
+
inputProcessors: ({ requestContext }) => {
|
|
734
|
+
const resolveProcessors = (configured) => [
|
|
735
|
+
...configured,
|
|
736
|
+
...mastraCodeInputProcessors,
|
|
737
|
+
new AccountStartNoticeProcessor({ credentialStore: authStorage }),
|
|
738
|
+
...readPluginProcessors().input.map((entry) => entry.value),
|
|
739
|
+
...pluginSignalLane?.getInputProcessors() ?? []
|
|
740
|
+
];
|
|
741
|
+
if (typeof config?.inputProcessors !== "function") return resolveProcessors([]);
|
|
742
|
+
const configured = config.inputProcessors({ requestContext });
|
|
743
|
+
return configured instanceof Promise ? configured.then(resolveProcessors) : resolveProcessors(configured);
|
|
744
|
+
},
|
|
745
|
+
outputProcessors: () => [
|
|
746
|
+
new CyberRefusalHandler(),
|
|
747
|
+
...readPluginProcessors().output.map((entry) => entry.value),
|
|
748
|
+
...pluginSignalLane?.getOutputProcessors() ?? []
|
|
749
|
+
],
|
|
750
|
+
errorProcessors: [
|
|
751
|
+
new ProviderHistoryCompat(),
|
|
752
|
+
new CyberRefusalHandler(),
|
|
753
|
+
new StreamErrorRetryProcessor({ matchers: [
|
|
754
|
+
{
|
|
755
|
+
match: isBadRequestError,
|
|
756
|
+
maxRetries: 1,
|
|
757
|
+
delayMs: 2e3
|
|
758
|
+
},
|
|
759
|
+
{
|
|
760
|
+
match: isTransientConnectionError,
|
|
761
|
+
maxRetries: MASTRACODE_TRANSIENT_CONNECTION_MAX_RETRIES,
|
|
762
|
+
delayMs: ({ retryCount }) => getTransientRetryDelay(retryCount),
|
|
763
|
+
onRetry: ({ error, retryCount, delayMs, requestContext }) => emitTransientRetry(error, retryCount, delayMs, requestContext)
|
|
764
|
+
},
|
|
765
|
+
{
|
|
766
|
+
match: isTransientServerError,
|
|
767
|
+
maxRetries: MASTRACODE_TRANSIENT_CONNECTION_MAX_RETRIES,
|
|
768
|
+
delayMs: ({ retryCount }) => getTransientRetryDelay(retryCount),
|
|
769
|
+
onRetry: ({ error, retryCount, delayMs, requestContext }) => emitTransientRetry(error, retryCount, delayMs, requestContext)
|
|
770
|
+
}
|
|
771
|
+
] }),
|
|
772
|
+
new AccountRotationProcessor({
|
|
773
|
+
credentialStore: authStorage,
|
|
774
|
+
maxProcessorRetries: MASTRACODE_MAX_PROCESSOR_RETRIES,
|
|
775
|
+
settingsPath: config?.settingsPath,
|
|
776
|
+
modeless
|
|
777
|
+
})
|
|
778
|
+
],
|
|
779
|
+
maxProcessorRetries: MASTRACODE_MAX_PROCESSOR_RETRIES
|
|
780
|
+
}), experimentalAgent);
|
|
781
|
+
const planMode = createPlanMode(!disabledBuiltinTools.has("submit_plan"));
|
|
782
|
+
const defaultModes = [
|
|
783
|
+
{
|
|
784
|
+
...buildMode,
|
|
785
|
+
metadata: {
|
|
786
|
+
...buildMode.metadata,
|
|
787
|
+
color: mastraBrand.green
|
|
788
|
+
}
|
|
789
|
+
},
|
|
790
|
+
{
|
|
791
|
+
...planMode,
|
|
792
|
+
metadata: {
|
|
793
|
+
...planMode.metadata,
|
|
794
|
+
color: mastraBrand.purple
|
|
795
|
+
}
|
|
796
|
+
},
|
|
797
|
+
{
|
|
798
|
+
...fastMode,
|
|
799
|
+
metadata: {
|
|
800
|
+
...fastMode.metadata,
|
|
801
|
+
color: mastraBrand.orange
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
];
|
|
805
|
+
const intervalHandlers = config?.intervalHandlers ?? [{
|
|
806
|
+
id: "gateway-sync",
|
|
807
|
+
intervalMs: 300 * 1e3,
|
|
808
|
+
immediate: false,
|
|
809
|
+
handler: () => syncGateways()
|
|
810
|
+
}];
|
|
811
|
+
const anthropicCred = authStorage.get("anthropic");
|
|
812
|
+
const openaiCred = authStorage.get("openai-codex");
|
|
813
|
+
const githubCopilotCred = authStorage.get("github-copilot");
|
|
814
|
+
const kimiCodingCred = authStorage.get("kimi-for-coding");
|
|
815
|
+
const startupAccess = {
|
|
816
|
+
anthropic: anthropicCred?.type === "oauth" ? "oauth" : anthropicCred?.type === "api_key" && anthropicCred.key.trim().length > 0 ? "apikey" : false,
|
|
817
|
+
openai: openaiCred?.type === "oauth" ? "oauth" : openaiCred?.type === "api_key" && openaiCred.key.trim().length > 0 ? "apikey" : false,
|
|
818
|
+
cerebras: process.env.CEREBRAS_API_KEY ? "apikey" : false,
|
|
819
|
+
google: process.env.GOOGLE_GENERATIVE_AI_API_KEY ? "apikey" : false,
|
|
820
|
+
deepseek: process.env.DEEPSEEK_API_KEY ? "apikey" : false,
|
|
821
|
+
"github-copilot": githubCopilotCred?.type === "oauth" ? "oauth" : false,
|
|
822
|
+
"kimi-for-coding": kimiCodingCred?.type === "oauth" && isKimiCodingDeviceId(kimiCodingCred.deviceId) ? "oauth" : kimiCodingCred?.type === "api_key" && kimiCodingCred.key.trim().length > 0 || Boolean(process.env.KIMI_API_KEY?.trim()) ? "apikey" : false
|
|
823
|
+
};
|
|
824
|
+
if (mgApiKey) {
|
|
825
|
+
if (!startupAccess.anthropic) startupAccess.anthropic = "apikey";
|
|
826
|
+
if (!startupAccess.openai) startupAccess.openai = "apikey";
|
|
827
|
+
}
|
|
828
|
+
try {
|
|
829
|
+
const registry = PROVIDER_REGISTRY;
|
|
830
|
+
for (const [provider, config] of Object.entries(registry)) {
|
|
831
|
+
if (startupAccess[provider] === "oauth" || startupAccess[provider] === "apikey") continue;
|
|
832
|
+
if (provider === "anthropic" || provider === "openai") continue;
|
|
833
|
+
const envVars = config?.apiKeyEnvVar;
|
|
834
|
+
if ((Array.isArray(envVars) ? envVars : envVars ? [envVars] : []).some((envVar) => process.env[envVar])) startupAccess[provider] = "apikey";
|
|
835
|
+
}
|
|
836
|
+
} catch {}
|
|
837
|
+
const builtinOmPacks = getAvailableOmPacks(startupAccess);
|
|
838
|
+
const effectiveDefaults = globalSettings.models.modeDefaults;
|
|
839
|
+
const effectiveObserverModel = resolveOmRoleModel(globalSettings, "observer", builtinOmPacks);
|
|
840
|
+
const effectiveReflectorModel = resolveOmRoleModel(globalSettings, "reflector", builtinOmPacks);
|
|
841
|
+
const observerModelSelection = globalSettings.models.observerModelSelection;
|
|
842
|
+
const reflectorModelSelection = globalSettings.models.reflectorModelSelection;
|
|
843
|
+
const effectiveObservationThreshold = globalSettings.models.omObservationThreshold ?? void 0;
|
|
844
|
+
const effectiveReflectionThreshold = globalSettings.models.omReflectionThreshold ?? void 0;
|
|
845
|
+
const effectiveCavemanObservations = globalSettings.models.omCavemanObservations ?? void 0;
|
|
846
|
+
const effectiveObserveAttachments = globalSettings.models.omObserveAttachments ?? "auto";
|
|
847
|
+
const modes = addPluginToolsToModeAllowlists(applyModeDefaultsToModes(config?.modes === false ? [buildMode] : config?.modes ?? defaultModes, effectiveDefaults), Object.keys(pluginTools));
|
|
848
|
+
const defaultModeId = modes.find((mode) => mode.metadata?.default === true)?.id ?? modes.find((mode) => mode.id === "build")?.id ?? modes[0]?.id;
|
|
849
|
+
if (!defaultModeId) throw new Error("MastraCode requires at least one mode");
|
|
850
|
+
const subagentModeMap = {
|
|
851
|
+
explore: "fast",
|
|
852
|
+
plan: "plan",
|
|
853
|
+
execute: "build"
|
|
854
|
+
};
|
|
855
|
+
const disabledTools = new Set(config?.disabledTools);
|
|
856
|
+
const subagents = (config?.subagents ?? [
|
|
857
|
+
exploreSubagent,
|
|
858
|
+
planSubagent,
|
|
859
|
+
executeSubagent
|
|
860
|
+
]).map((definition) => ({
|
|
861
|
+
...definition,
|
|
862
|
+
...config?.subagents == null && { defaultModelId: modes.find((mode) => mode.id === subagentModeMap[definition.id])?.defaultModelId ?? modes.find((mode) => mode.id === defaultModeId)?.defaultModelId },
|
|
863
|
+
allowedControllerTools: definition.allowedControllerTools?.filter((name) => !disabledTools.has(name)),
|
|
864
|
+
allowedWorkspaceTools: definition.allowedWorkspaceTools?.filter((name) => !disabledTools.has(name)),
|
|
865
|
+
...definition.tools && { tools: Object.fromEntries(Object.entries(definition.tools).filter(([name]) => !disabledTools.has(name))) }
|
|
866
|
+
}));
|
|
867
|
+
const globalInitialState = {};
|
|
868
|
+
if (!config?.disableSettingsOmSeed) {
|
|
869
|
+
if (observerModelSelection === "auto") globalInitialState.observerModelSelection = "auto";
|
|
870
|
+
else if (effectiveObserverModel) {
|
|
871
|
+
globalInitialState.observerModelId = effectiveObserverModel;
|
|
872
|
+
globalInitialState.observerModelSelection = effectiveObserverModel;
|
|
873
|
+
} else globalInitialState.observerModelSelection = "auto";
|
|
874
|
+
if (reflectorModelSelection === "auto") globalInitialState.reflectorModelSelection = "auto";
|
|
875
|
+
else if (effectiveReflectorModel) {
|
|
876
|
+
globalInitialState.reflectorModelId = effectiveReflectorModel;
|
|
877
|
+
globalInitialState.reflectorModelSelection = effectiveReflectorModel;
|
|
878
|
+
} else globalInitialState.reflectorModelSelection = "auto";
|
|
879
|
+
if (effectiveObservationThreshold !== void 0) globalInitialState.observationThreshold = effectiveObservationThreshold;
|
|
880
|
+
if (effectiveReflectionThreshold !== void 0) globalInitialState.reflectionThreshold = effectiveReflectionThreshold;
|
|
881
|
+
if (effectiveCavemanObservations !== void 0) globalInitialState.cavemanObservations = effectiveCavemanObservations;
|
|
882
|
+
if (effectiveObserveAttachments !== void 0) globalInitialState.observeAttachments = effectiveObserveAttachments;
|
|
883
|
+
}
|
|
884
|
+
if (globalSettings.preferences.yolo !== null) globalInitialState.yolo = globalSettings.preferences.yolo;
|
|
885
|
+
if (config?.omScope) globalInitialState.omScope = config.omScope;
|
|
886
|
+
for (const [key, modelId] of Object.entries(globalSettings.models.subagentModels)) if (key === "default" || key === "_default") globalInitialState.subagentModelId = modelId;
|
|
887
|
+
else globalInitialState[`subagentModelId_${key}`] = modelId;
|
|
888
|
+
const typedStateSchema = stateSchema;
|
|
889
|
+
const backgroundCompletionEvents = backgroundToolsEnabled ? createBackgroundCompletionEvents() : void 0;
|
|
890
|
+
let controller;
|
|
891
|
+
controller = new AgentController({
|
|
892
|
+
id: "mastra-code",
|
|
893
|
+
resourceId: project.resourceId,
|
|
894
|
+
storage,
|
|
895
|
+
...backgroundToolsEnabled ? { backgroundTasks: {
|
|
896
|
+
enabled: true,
|
|
897
|
+
recoverStaleTasksOnStart: false,
|
|
898
|
+
...createBackgroundCompletionCallbacks(() => controller, backgroundCompletionEvents)
|
|
899
|
+
} } : {},
|
|
900
|
+
observability,
|
|
901
|
+
memory,
|
|
902
|
+
pubsub: signalsPubSub,
|
|
903
|
+
stateSchema: typedStateSchema,
|
|
904
|
+
omConfig: {
|
|
905
|
+
observerModel: "auto",
|
|
906
|
+
defaultObserverModelId: DEFAULT_OM_MODEL_ID,
|
|
907
|
+
reflectorModel: "auto",
|
|
908
|
+
defaultReflectorModelId: DEFAULT_OM_MODEL_ID,
|
|
909
|
+
resolveAutoModelId: ({ currentModelId }) => resolveAutoOMModelId(currentModelId)
|
|
910
|
+
},
|
|
911
|
+
agent: codeAgent,
|
|
912
|
+
subagents,
|
|
913
|
+
...config?.disableBuiltinTools?.length ? { disableBuiltinTools: config.disableBuiltinTools } : {},
|
|
914
|
+
resolveSubagentModel: (modelId, { requestContext }) => routesToOtherGateway(modelId, Object.values(controller.getMastra()?.listGateways() ?? {}), /* @__PURE__ */ new Set([
|
|
915
|
+
mastraCodeGateway.id,
|
|
916
|
+
amazonBedrockGateway.id,
|
|
917
|
+
githubCopilotGateway.id,
|
|
918
|
+
"models.dev"
|
|
919
|
+
])) ? modelId : resolveModel(modelId, { requestContext }),
|
|
920
|
+
gateways: [
|
|
921
|
+
amazonBedrockGateway,
|
|
922
|
+
githubCopilotGateway,
|
|
923
|
+
mastraCodeGateway
|
|
924
|
+
],
|
|
925
|
+
workspace: config?.workspace ?? ((args) => getDynamicWorkspace({
|
|
926
|
+
...args,
|
|
927
|
+
backgroundToolsEnabled
|
|
928
|
+
})),
|
|
929
|
+
browser: config?.browser,
|
|
930
|
+
idGenerator: config?.idGenerator,
|
|
931
|
+
toolCategoryResolver: getToolCategory,
|
|
932
|
+
initialState: {
|
|
933
|
+
projectPath: project.rootPath,
|
|
934
|
+
projectName: project.name,
|
|
935
|
+
gitBranch: project.gitBranch,
|
|
936
|
+
pluginSkillPaths: loadedPlugins.flatMap((plugin) => plugin.status === "active" ? plugin.skillPaths ?? [] : []),
|
|
937
|
+
pluginCommandPaths: loadedPlugins.flatMap((plugin) => plugin.status === "active" ? plugin.commandPaths ?? [] : []),
|
|
938
|
+
pluginInstructions: loadedPlugins.flatMap((plugin) => plugin.status === "active" && plugin.instructions ? [plugin.instructions] : []),
|
|
939
|
+
yolo: true,
|
|
940
|
+
...globalInitialState,
|
|
941
|
+
...config?.initialState,
|
|
942
|
+
configDir
|
|
943
|
+
},
|
|
944
|
+
modes,
|
|
945
|
+
intervalHandlers,
|
|
946
|
+
modelUseCountProvider: () => loadSettings().modelUseCounts,
|
|
947
|
+
modelUseCountTracker: (modelId) => {
|
|
948
|
+
try {
|
|
949
|
+
const settings = loadSettings();
|
|
950
|
+
settings.modelUseCounts[modelId] = (settings.modelUseCounts[modelId] ?? 0) + 1;
|
|
951
|
+
saveSettings(settings);
|
|
952
|
+
} catch (error) {
|
|
953
|
+
console.error("Failed to persist model usage count", error);
|
|
954
|
+
}
|
|
955
|
+
},
|
|
956
|
+
threadLock: crossProcessPubSub ? void 0 : {
|
|
957
|
+
acquire: acquireThreadLock,
|
|
958
|
+
release: releaseThreadLock
|
|
959
|
+
}
|
|
960
|
+
});
|
|
961
|
+
controller.onSessionCreated((session) => {
|
|
962
|
+
liveSessions.add(session);
|
|
963
|
+
});
|
|
964
|
+
controller.onSessionDeleted((session) => {
|
|
965
|
+
liveSessions.delete(session);
|
|
966
|
+
});
|
|
967
|
+
const sessionPeerCleanup = /* @__PURE__ */ new WeakMap();
|
|
968
|
+
if (useCrossAgentSignals) {
|
|
969
|
+
controller.onSessionCreated(async (session) => {
|
|
970
|
+
const advertisement = createSessionThreadAdvertisement({
|
|
971
|
+
session,
|
|
972
|
+
controller,
|
|
973
|
+
projectName: project.name
|
|
974
|
+
});
|
|
975
|
+
sessionPeerCleanup.set(session, () => advertisement.close());
|
|
976
|
+
const initialThreadId = session.thread.getId();
|
|
977
|
+
if (initialThreadId) await Promise.race([advertisement.claim(initialThreadId), new Promise((resolve) => {
|
|
978
|
+
setTimeout(resolve, 5e3).unref?.();
|
|
979
|
+
})]);
|
|
980
|
+
}, { blocking: true });
|
|
981
|
+
controller.onSessionDeleted((session) => {
|
|
982
|
+
sessionPeerCleanup.get(session)?.();
|
|
983
|
+
sessionPeerCleanup.delete(session);
|
|
984
|
+
});
|
|
985
|
+
}
|
|
986
|
+
pluginRuntimeController = controller;
|
|
987
|
+
if (pluginSignalLane && pluginManager) {
|
|
988
|
+
pluginSignalLane.sync(pluginManager.getPluginSignalProviders());
|
|
989
|
+
unsubscribePluginReload = pluginManager.onReload(() => pluginSignalLane.sync(pluginManager.getPluginSignalProviders()));
|
|
990
|
+
}
|
|
991
|
+
return {
|
|
992
|
+
controller,
|
|
993
|
+
storage,
|
|
994
|
+
storageMaintenance,
|
|
995
|
+
createKnowledgeInspector: (session, knowledgeKey) => createKnowledgeInspector({
|
|
996
|
+
storage,
|
|
997
|
+
knowledge: knowledgeKey ?? knowledge,
|
|
998
|
+
mastra: controller.getMastra(),
|
|
999
|
+
session
|
|
1000
|
+
}),
|
|
1001
|
+
observability,
|
|
1002
|
+
memory,
|
|
1003
|
+
knowledge,
|
|
1004
|
+
knowledgeKey,
|
|
1005
|
+
mcpManager,
|
|
1006
|
+
hookManager,
|
|
1007
|
+
pluginManager,
|
|
1008
|
+
loadedPlugins,
|
|
1009
|
+
pluginTools,
|
|
1010
|
+
signalsPubSub,
|
|
1011
|
+
authStorage,
|
|
1012
|
+
resolveModel,
|
|
1013
|
+
storageWarning,
|
|
1014
|
+
observabilityWarning,
|
|
1015
|
+
builtinOmPacks,
|
|
1016
|
+
effectiveDefaults,
|
|
1017
|
+
githubSignals,
|
|
1018
|
+
backgroundToolsEnabled,
|
|
1019
|
+
backgroundCompletionEvents,
|
|
1020
|
+
sessionId,
|
|
1021
|
+
ownerId,
|
|
1022
|
+
projectPath: project.rootPath,
|
|
1023
|
+
codeAgent,
|
|
1024
|
+
setActiveSession: (session) => {
|
|
1025
|
+
activeSession = session;
|
|
1026
|
+
},
|
|
1027
|
+
/**
|
|
1028
|
+
* Starts the signal providers contributed by plugins. Called by the
|
|
1029
|
+
* composition layer once the controller is inited, because that is when a
|
|
1030
|
+
* Mastra instance exists — a provider without one has no storage, and
|
|
1031
|
+
* nothing else will hand it one: the Agent propagates Mastra only to the
|
|
1032
|
+
* providers in its own `signals` array, which these deliberately are not in.
|
|
1033
|
+
*/
|
|
1034
|
+
startPluginSignalProviders: () => {
|
|
1035
|
+
const mastra = controller.getMastra();
|
|
1036
|
+
if (!pluginSignalLane || !mastra) return;
|
|
1037
|
+
pluginSignalLane.setMastra(mastra, codeAgent);
|
|
1038
|
+
},
|
|
1039
|
+
/**
|
|
1040
|
+
* Stops every plugin-contributed signal provider and stops listening for
|
|
1041
|
+
* plugin reloads. The inverse of `startPluginSignalProviders`, for an
|
|
1042
|
+
* embedder that is done with this controller: a `pluginManager` shared
|
|
1043
|
+
* across controllers (`MastraCodeConfig.pluginManager`) outlives any one of
|
|
1044
|
+
* them, so without this its providers keep polling and its reload listener
|
|
1045
|
+
* keeps firing for a controller that is gone.
|
|
1046
|
+
*/
|
|
1047
|
+
stopPluginSignalProviders: () => {
|
|
1048
|
+
unsubscribePluginReload?.();
|
|
1049
|
+
unsubscribePluginReload = void 0;
|
|
1050
|
+
pluginSignalLane?.stopAll();
|
|
1051
|
+
},
|
|
1052
|
+
/** Process-local `/schedules` scheduler. Call `stop()` on shutdown. */
|
|
1053
|
+
threadScheduler,
|
|
1054
|
+
/**
|
|
1055
|
+
* Starts delivering the due notifications of this controller's sessions'
|
|
1056
|
+
* resources from this process. Called by the composition layer once the
|
|
1057
|
+
* controller is inited. A no-op when the embedder configured its own
|
|
1058
|
+
* PubSub, whose shared dispatch schedule keeps delivering everything.
|
|
1059
|
+
*/
|
|
1060
|
+
startNotificationDispatch: () => {
|
|
1061
|
+
if (ownsNotificationDispatch) notificationDispatcher.start();
|
|
1062
|
+
},
|
|
1063
|
+
/**
|
|
1064
|
+
* Stops advertising every live session's threads and releases their
|
|
1065
|
+
* ownership claims. Call first on shutdown: a claim otherwise stays held
|
|
1066
|
+
* (and renewed) through the rest of teardown, so a restarted process cannot
|
|
1067
|
+
* claim the thread — and peers cannot reach it — until this one exits.
|
|
1068
|
+
*/
|
|
1069
|
+
releaseThreadClaims: () => {
|
|
1070
|
+
for (const session of liveSessions) {
|
|
1071
|
+
sessionPeerCleanup.get(session)?.();
|
|
1072
|
+
sessionPeerCleanup.delete(session);
|
|
1073
|
+
}
|
|
1074
|
+
},
|
|
1075
|
+
/** Stops this process's notification dispatch and releases its leases. Call on shutdown. */
|
|
1076
|
+
stopNotificationDispatch: async () => {
|
|
1077
|
+
await notificationDispatcher.stop();
|
|
1078
|
+
await dispatchLeasePubSub?.close();
|
|
1079
|
+
},
|
|
1080
|
+
/**
|
|
1081
|
+
* Hands Mastra to the statically configured input processors.
|
|
1082
|
+
*
|
|
1083
|
+
* The Agent does this itself, but only for processors configured as a
|
|
1084
|
+
* plain array (`Array.isArray` in `__registerMastra`). This lane is a
|
|
1085
|
+
* function so plugins can contribute to it, which takes those processors
|
|
1086
|
+
* out of that branch — including any an embedder passed as
|
|
1087
|
+
* `config.inputProcessors`, some of which need Mastra to work at all
|
|
1088
|
+
* (`CostGuardProcessor` reads observability storage there). Doing it here
|
|
1089
|
+
* keeps that unchanged.
|
|
1090
|
+
*
|
|
1091
|
+
* Plugin processors are deliberately not included: they come and go with
|
|
1092
|
+
* their plugin, and the registry keeps the first instance registered under
|
|
1093
|
+
* an id forever, which would leave a retired instance behind. Plugins
|
|
1094
|
+
* reach Mastra through `getController()` on the plugin context instead.
|
|
1095
|
+
*/
|
|
1096
|
+
registerConfiguredProcessorsWithMastra: () => {
|
|
1097
|
+
const mastra = controller.getMastra();
|
|
1098
|
+
if (!mastra) return;
|
|
1099
|
+
for (const processor of mastraCodeInputProcessors) {
|
|
1100
|
+
mastra.addProcessor(processor);
|
|
1101
|
+
mastra.addProcessorConfiguration(processor, CODE_AGENT_ID, "input");
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
};
|
|
1105
|
+
}
|
|
1106
|
+
/**
|
|
1107
|
+
* Wires the session-scoped concerns MastraCode layers on top of a Session:
|
|
1108
|
+
* hookManager thread-id sync, GitHub PR polling for the current thread, and
|
|
1109
|
+
* per-thread persistence of the mastracode-only `/om` settings.
|
|
1110
|
+
*
|
|
1111
|
+
* Used by {@link bootLocalAgentController} for the single local session. A server can
|
|
1112
|
+
* call this for any session it mints if it wants the same background wiring.
|
|
1113
|
+
*/
|
|
1114
|
+
async function wireSessionConcerns(base, session) {
|
|
1115
|
+
const { hookManager, githubSignals } = base;
|
|
1116
|
+
base.setActiveSession(session);
|
|
1117
|
+
if (hookManager) session.subscribe((event) => {
|
|
1118
|
+
if (event.type === "thread_changed") hookManager.setSessionId(event.threadId);
|
|
1119
|
+
else if (event.type === "thread_created") hookManager.setSessionId(event.thread.id);
|
|
1120
|
+
});
|
|
1121
|
+
if (githubSignals) {
|
|
1122
|
+
const startGithubPollingForCurrentThread = async (threadId) => {
|
|
1123
|
+
if (!threadId) return;
|
|
1124
|
+
githubSignals.stopAllPolling();
|
|
1125
|
+
try {
|
|
1126
|
+
const thread = (await session.thread.list({ allResources: true })).find((item) => item.id === threadId);
|
|
1127
|
+
await githubSignals.startPollingForThread({
|
|
1128
|
+
threadId,
|
|
1129
|
+
resourceId: thread?.resourceId ?? session.identity.getResourceId()
|
|
1130
|
+
}, { pollImmediately: true });
|
|
1131
|
+
} catch (error) {
|
|
1132
|
+
console.warn("Failed to start GitHub PR polling:", error);
|
|
1133
|
+
}
|
|
1134
|
+
};
|
|
1135
|
+
session.subscribe((event) => {
|
|
1136
|
+
if (event.type === "thread_changed") startGithubPollingForCurrentThread(event.threadId);
|
|
1137
|
+
else if (event.type === "thread_created") startGithubPollingForCurrentThread(event.thread.id);
|
|
1138
|
+
});
|
|
1139
|
+
startGithubPollingForCurrentThread(session.thread.getId());
|
|
1140
|
+
}
|
|
1141
|
+
const omThreadStateSession = session;
|
|
1142
|
+
attachOMThreadStatePersistence(omThreadStateSession);
|
|
1143
|
+
await restoreOMThreadStateForCurrentThread(omThreadStateSession).catch(() => {});
|
|
1144
|
+
}
|
|
1145
|
+
/**
|
|
1146
|
+
* Case 3 (AgentController local + TUI/headless): build the controller, let it stand up its
|
|
1147
|
+
* own internal Mastra via `init()`, and mint the single eager session that all
|
|
1148
|
+
* work in this process runs through. The AgentController owns no session of its own.
|
|
1149
|
+
*/
|
|
1150
|
+
async function bootLocalAgentController(config) {
|
|
1151
|
+
const base = await createMastraCodeAgentController(config);
|
|
1152
|
+
const { controller, sessionId, ownerId, projectPath, codeAgent, mcpManager } = base;
|
|
1153
|
+
await controller.init();
|
|
1154
|
+
validateExperimentalAgent(codeAgent, controller.getMastra());
|
|
1155
|
+
const mastra = controller.getMastra();
|
|
1156
|
+
registerSelectedKnowledge(mastra, base.knowledgeKey, base.knowledge);
|
|
1157
|
+
if (mastra) await registerWorkflowBuilderPrimitives(mastra, {
|
|
1158
|
+
projectPath,
|
|
1159
|
+
codeAgent,
|
|
1160
|
+
mcpManager
|
|
1161
|
+
});
|
|
1162
|
+
await mastra?.startWorkers();
|
|
1163
|
+
base.registerConfiguredProcessorsWithMastra();
|
|
1164
|
+
base.startPluginSignalProviders();
|
|
1165
|
+
base.startNotificationDispatch();
|
|
1166
|
+
const session = await controller.createSession({
|
|
1167
|
+
id: sessionId,
|
|
1168
|
+
ownerId,
|
|
1169
|
+
createInitialThread: config?.createInitialThread
|
|
1170
|
+
});
|
|
1171
|
+
await wireSessionConcerns(base, session);
|
|
1172
|
+
let knowledgeInspector;
|
|
1173
|
+
let knowledgeInspectorUnavailableReason;
|
|
1174
|
+
if (!base.knowledge) knowledgeInspectorUnavailableReason = "Knowledge is off. Set MASTRACODE_EXPERIMENTAL_SUBCONSCIOUS=1 or pass a `knowledge` instance to createMastraCode.";
|
|
1175
|
+
else try {
|
|
1176
|
+
knowledgeInspector = await base.createKnowledgeInspector(session);
|
|
1177
|
+
if (!knowledgeInspector) knowledgeInspectorUnavailableReason = "Knowledge inspection requires a configured knowledge storage domain.";
|
|
1178
|
+
} catch (error) {
|
|
1179
|
+
knowledgeInspectorUnavailableReason = `Knowledge is unavailable: ${error instanceof Error ? error.message : String(error)}`;
|
|
1180
|
+
}
|
|
1181
|
+
return {
|
|
1182
|
+
...base,
|
|
1183
|
+
session,
|
|
1184
|
+
knowledgeInspector,
|
|
1185
|
+
knowledgeInspectorUnavailableReason
|
|
1186
|
+
};
|
|
1187
|
+
}
|
|
1188
|
+
/**
|
|
1189
|
+
* Registers the selected Knowledge on a Mastra built outside `mastraArgs` (the
|
|
1190
|
+
* controller's internal Mastra, or a caller-owned one) so keyed lookups resolve
|
|
1191
|
+
* it and an instance without its own storage inherits the Mastra's.
|
|
1192
|
+
*/
|
|
1193
|
+
function registerSelectedKnowledge(mastra, key, knowledge) {
|
|
1194
|
+
if (!mastra || !knowledge) return;
|
|
1195
|
+
const existing = mastra.listKnowledge()[key];
|
|
1196
|
+
if (existing === knowledge) return;
|
|
1197
|
+
if (existing) throw new Error(`This Mastra already registers a different Knowledge instance under "${key}".`);
|
|
1198
|
+
mastra.addKnowledge(knowledge, key);
|
|
1199
|
+
}
|
|
1200
|
+
/**
|
|
1201
|
+
* Cases 1 & 2 (AgentController in Server + Web/TUI): build the controller, register it on a
|
|
1202
|
+
* server-owned Mastra, THEN init it. Registering before `init()` is what makes
|
|
1203
|
+
* the controller inherit the server's Mastra (storage, agents, gateways) instead of
|
|
1204
|
+
* spinning up its own internal one — there is a single shared Mastra.
|
|
1205
|
+
*
|
|
1206
|
+
* No eager session is minted: each client (browser or terminal) creates/resumes
|
|
1207
|
+
* its own isolated session via `controller.createSession({ resourceId })`, so one
|
|
1208
|
+
* server can drive many concurrent users.
|
|
1209
|
+
*
|
|
1210
|
+
* Pass an existing `mastra` to mount onto a Mastra that already hosts other
|
|
1211
|
+
* primitives; otherwise a Mastra is created that owns the controller's storage so
|
|
1212
|
+
* durability is configured in one place.
|
|
1213
|
+
*/
|
|
1214
|
+
async function mountAgentControllerOnMastra(config) {
|
|
1215
|
+
const prepared = await prepareAgentControllerMount(config);
|
|
1216
|
+
if (config?.mastra) {
|
|
1217
|
+
prepared.base.controller.__registerMastra(config.mastra);
|
|
1218
|
+
registerSelectedKnowledge(config.mastra, prepared.base.knowledgeKey, prepared.base.knowledge);
|
|
1219
|
+
await prepared.finalize();
|
|
1220
|
+
return {
|
|
1221
|
+
...prepared.base,
|
|
1222
|
+
mastra: config.mastra
|
|
1223
|
+
};
|
|
1224
|
+
}
|
|
1225
|
+
const mastra = new Mastra(prepared.mastraArgs);
|
|
1226
|
+
await prepared.finalize();
|
|
1227
|
+
return {
|
|
1228
|
+
...prepared.base,
|
|
1229
|
+
mastra
|
|
1230
|
+
};
|
|
1231
|
+
}
|
|
1232
|
+
/**
|
|
1233
|
+
* Assemble everything needed to construct the server-owned Mastra WITHOUT
|
|
1234
|
+
* constructing it, so a caller (the platform entry `src/mastra/index.ts`) can
|
|
1235
|
+
* run the `new Mastra(...)` literal in its own module. The deployer's
|
|
1236
|
+
* `checkConfigExport` Babel plugin only marks the config valid when it finds a
|
|
1237
|
+
* top-level `new Mastra(...)` exported as `mastra` in the ENTRY file; hiding the
|
|
1238
|
+
* construction inside this helper would trip the "Invalid Mastra config" warning.
|
|
1239
|
+
*
|
|
1240
|
+
* Returns the constructor args plus a `finalize()` that runs the post-construct
|
|
1241
|
+
* boot (`controller.init()` + `startWorkers()`). The controller is registered on
|
|
1242
|
+
* the Mastra via the `agentControllers` arg at construction time.
|
|
1243
|
+
*/
|
|
1244
|
+
async function prepareAgentControllerMount(config) {
|
|
1245
|
+
const base = await createMastraCodeAgentController(config);
|
|
1246
|
+
const { controller, storage, authStorage, projectPath, codeAgent, mcpManager, backgroundToolsEnabled, backgroundCompletionEvents } = base;
|
|
1247
|
+
const controllerId = config?.controllerId ?? controller.id;
|
|
1248
|
+
const apiRoutes = config?.buildApiRoutes?.({
|
|
1249
|
+
controller,
|
|
1250
|
+
authStorage
|
|
1251
|
+
});
|
|
1252
|
+
const extraServerConfig = config?.buildServerConfig?.({
|
|
1253
|
+
controller,
|
|
1254
|
+
authStorage
|
|
1255
|
+
});
|
|
1256
|
+
const weOwnTheMastra = !config?.mastra;
|
|
1257
|
+
const serverConfig = {
|
|
1258
|
+
...extraServerConfig,
|
|
1259
|
+
...apiRoutes?.length ? { apiRoutes } : {}
|
|
1260
|
+
};
|
|
1261
|
+
const mastraArgs = {
|
|
1262
|
+
agentControllers: { [controllerId]: controller },
|
|
1263
|
+
storage,
|
|
1264
|
+
...backgroundToolsEnabled ? { backgroundTasks: {
|
|
1265
|
+
enabled: true,
|
|
1266
|
+
recoverStaleTasksOnStart: false,
|
|
1267
|
+
...createBackgroundCompletionCallbacks(() => controller, backgroundCompletionEvents)
|
|
1268
|
+
} } : {},
|
|
1269
|
+
...base.knowledge ? { knowledge: { [base.knowledgeKey]: base.knowledge } } : {},
|
|
1270
|
+
...base.signalsPubSub ? { pubsub: base.signalsPubSub } : {},
|
|
1271
|
+
...Object.keys(serverConfig).length ? { server: serverConfig } : {}
|
|
1272
|
+
};
|
|
1273
|
+
const finalize = async () => {
|
|
1274
|
+
await controller.init();
|
|
1275
|
+
validateExperimentalAgent(codeAgent, controller.getMastra());
|
|
1276
|
+
if (weOwnTheMastra) {
|
|
1277
|
+
const mastra = controller.getMastra();
|
|
1278
|
+
if (mastra) await registerWorkflowBuilderPrimitives(mastra, {
|
|
1279
|
+
projectPath,
|
|
1280
|
+
codeAgent,
|
|
1281
|
+
mcpManager
|
|
1282
|
+
});
|
|
1283
|
+
}
|
|
1284
|
+
await controller.getMastra()?.startWorkers();
|
|
1285
|
+
base.registerConfiguredProcessorsWithMastra();
|
|
1286
|
+
base.startPluginSignalProviders();
|
|
1287
|
+
base.startNotificationDispatch();
|
|
1288
|
+
};
|
|
1289
|
+
return {
|
|
1290
|
+
base,
|
|
1291
|
+
mastraArgs,
|
|
1292
|
+
finalize
|
|
1293
|
+
};
|
|
1294
|
+
}
|
|
1295
|
+
/**
|
|
1296
|
+
* Back-compat alias. Historically `createMastraCode` built and booted a local
|
|
1297
|
+
* controller with a single session; that behavior now lives in
|
|
1298
|
+
* {@link bootLocalAgentController}. New code should call the explicit factory for its
|
|
1299
|
+
* case: `bootLocalAgentController` (local) or {@link mountAgentControllerOnMastra} (server).
|
|
1300
|
+
*/
|
|
1301
|
+
const createMastraCode = bootLocalAgentController;
|
|
1302
|
+
//#endregion
|
|
1303
|
+
export { KnowledgeInspectorError, LOCAL_KNOWLEDGE_ORG_ID, autoApprovePolicy, bootLocalAgentController, createAuthStorage, createKnowledgeInspector, createMastraCode, createMastraCodeAgentController, denyPolicy, formatHuman, formatJsonl, hasHeadlessFlag, mountAgentControllerOnMastra, permissionModeToPolicy, prepareAgentControllerMount, renderJsonResult, renderTextResult, resolveCloudObservabilityConfig, runMC, runMCCli, wireSessionConcerns };
|
|
1304
|
+
|
|
1305
|
+
//# sourceMappingURL=index.js.map
|