@mastra/code-sdk 0.0.0-livekit-beta-v3-20260709031728
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +41 -0
- package/LICENSE.md +30 -0
- package/README.md +50 -0
- package/dist/acp/agent.d.ts +35 -0
- package/dist/acp/agent.d.ts.map +1 -0
- package/dist/acp/agent.js +173 -0
- package/dist/acp/agent.js.map +1 -0
- package/dist/acp/event-mapper.d.ts +22 -0
- package/dist/acp/event-mapper.d.ts.map +1 -0
- package/dist/acp/event-mapper.js +166 -0
- package/dist/acp/event-mapper.js.map +1 -0
- package/dist/acp/index.d.ts +8 -0
- package/dist/acp/index.d.ts.map +1 -0
- package/dist/acp/index.js +54 -0
- package/dist/acp/index.js.map +1 -0
- package/dist/acp/server.d.ts +7 -0
- package/dist/acp/server.d.ts.map +1 -0
- package/dist/acp/server.js +34 -0
- package/dist/acp/server.js.map +1 -0
- package/dist/acp.d.ts +2 -0
- package/dist/acp.d.ts.map +1 -0
- package/dist/acp.js +5 -0
- package/dist/acp.js.map +1 -0
- package/dist/agents/instructions.d.ts +6 -0
- package/dist/agents/instructions.d.ts.map +1 -0
- package/dist/agents/instructions.js +41 -0
- package/dist/agents/instructions.js.map +1 -0
- package/dist/agents/mastracode-gateway.d.ts +65 -0
- package/dist/agents/mastracode-gateway.d.ts.map +1 -0
- package/dist/agents/mastracode-gateway.js +442 -0
- package/dist/agents/mastracode-gateway.js.map +1 -0
- package/dist/agents/memory.d.ts +13 -0
- package/dist/agents/memory.d.ts.map +1 -0
- package/dist/agents/memory.js +107 -0
- package/dist/agents/memory.js.map +1 -0
- package/dist/agents/model.d.ts +55 -0
- package/dist/agents/model.d.ts.map +1 -0
- package/dist/agents/model.js +115 -0
- package/dist/agents/model.js.map +1 -0
- package/dist/agents/modes/build.d.ts +10 -0
- package/dist/agents/modes/build.d.ts.map +1 -0
- package/dist/agents/modes/build.js +45 -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 +38 -0
- package/dist/agents/modes/explore.js.map +1 -0
- package/dist/agents/modes/plan.d.ts +6 -0
- package/dist/agents/modes/plan.d.ts.map +1 -0
- package/dist/agents/modes/plan.js +38 -0
- package/dist/agents/modes/plan.js.map +1 -0
- package/dist/agents/prompts/agent-instructions.d.ts +20 -0
- package/dist/agents/prompts/agent-instructions.d.ts.map +1 -0
- package/dist/agents/prompts/agent-instructions.js +82 -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 +73 -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 +22 -0
- package/dist/agents/prompts/fast.js.map +1 -0
- package/dist/agents/prompts/index.d.ts +19 -0
- package/dist/agents/prompts/index.d.ts.map +1 -0
- package/dist/agents/prompts/index.js +57 -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 +22 -0
- package/dist/agents/prompts/model.js.map +1 -0
- package/dist/agents/prompts/plan.d.ts +6 -0
- package/dist/agents/prompts/plan.d.ts.map +1 -0
- package/dist/agents/prompts/plan.js +107 -0
- package/dist/agents/prompts/plan.js.map +1 -0
- package/dist/agents/prompts/tool-guidance.d.ts +13 -0
- package/dist/agents/prompts/tool-guidance.d.ts.map +1 -0
- package/dist/agents/prompts/tool-guidance.js +181 -0
- package/dist/agents/prompts/tool-guidance.js.map +1 -0
- package/dist/agents/sandbox-filesystem.d.ts +89 -0
- package/dist/agents/sandbox-filesystem.d.ts.map +1 -0
- package/dist/agents/sandbox-filesystem.js +268 -0
- package/dist/agents/sandbox-filesystem.js.map +1 -0
- package/dist/agents/sandbox-reattach.d.ts +19 -0
- package/dist/agents/sandbox-reattach.d.ts.map +1 -0
- package/dist/agents/sandbox-reattach.js +17 -0
- package/dist/agents/sandbox-reattach.js.map +1 -0
- package/dist/agents/thread-caveman-state.d.ts +17 -0
- package/dist/agents/thread-caveman-state.d.ts.map +1 -0
- package/dist/agents/thread-caveman-state.js +96 -0
- package/dist/agents/thread-caveman-state.js.map +1 -0
- package/dist/agents/tool-availability.d.ts +10 -0
- package/dist/agents/tool-availability.d.ts.map +1 -0
- package/dist/agents/tool-availability.js +105 -0
- package/dist/agents/tool-availability.js.map +1 -0
- package/dist/agents/tools.d.ts +18 -0
- package/dist/agents/tools.d.ts.map +1 -0
- package/dist/agents/tools.js +126 -0
- package/dist/agents/tools.js.map +1 -0
- package/dist/agents/workspace.d.ts +22 -0
- package/dist/agents/workspace.d.ts.map +1 -0
- package/dist/agents/workspace.js +194 -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 +152 -0
- package/dist/analytics.js.map +1 -0
- package/dist/auth/index.d.ts +9 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +11 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/pkce.d.ts +13 -0
- package/dist/auth/pkce.d.ts.map +1 -0
- package/dist/auth/pkce.js +21 -0
- package/dist/auth/pkce.js.map +1 -0
- package/dist/auth/providers/anthropic.d.ts +17 -0
- package/dist/auth/providers/anthropic.d.ts.map +1 -0
- package/dist/auth/providers/anthropic.js +94 -0
- package/dist/auth/providers/anthropic.js.map +1 -0
- package/dist/auth/providers/github-copilot.d.ts +100 -0
- package/dist/auth/providers/github-copilot.d.ts.map +1 -0
- package/dist/auth/providers/github-copilot.js +302 -0
- package/dist/auth/providers/github-copilot.js.map +1 -0
- package/dist/auth/providers/openai-codex.d.ts +95 -0
- package/dist/auth/providers/openai-codex.d.ts.map +1 -0
- package/dist/auth/providers/openai-codex.js +527 -0
- package/dist/auth/providers/openai-codex.js.map +1 -0
- package/dist/auth/storage.d.ts +91 -0
- package/dist/auth/storage.d.ts.map +1 -0
- package/dist/auth/storage.js +187 -0
- package/dist/auth/storage.js.map +1 -0
- package/dist/auth/types.d.ts +68 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +1 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/clipboard/index.d.ts +26 -0
- package/dist/clipboard/index.d.ts.map +1 -0
- package/dist/clipboard/index.js +192 -0
- package/dist/clipboard/index.js.map +1 -0
- package/dist/constants.d.ts +10 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +23 -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 +14 -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 +120 -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 +8 -0
- package/dist/evals/index.js.map +1 -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 +52 -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 +201 -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 +56 -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 +7 -0
- package/dist/evals/scorers/index.js.map +1 -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 +238 -0
- package/dist/evals/scorers/outcome.js.map +1 -0
- package/dist/headless/cli.d.ts +42 -0
- package/dist/headless/cli.d.ts.map +1 -0
- package/dist/headless/cli.js +196 -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 +188 -0
- package/dist/headless/flags.js.map +1 -0
- package/dist/headless/format.d.ts +38 -0
- package/dist/headless/format.d.ts.map +1 -0
- package/dist/headless/format.js +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 +32 -0
- package/dist/headless/index.js.map +1 -0
- package/dist/headless/policy.d.ts +17 -0
- package/dist/headless/policy.d.ts.map +1 -0
- package/dist/headless/policy.js +38 -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 +296 -0
- package/dist/headless/run-mc.js.map +1 -0
- package/dist/headless/types.d.ts +134 -0
- package/dist/headless/types.d.ts.map +1 -0
- package/dist/headless/types.js +9 -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 +78 -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 +125 -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 +16 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/manager.d.ts +47 -0
- package/dist/hooks/manager.d.ts.map +1 -0
- package/dist/hooks/manager.js +284 -0
- package/dist/hooks/manager.js.map +1 -0
- package/dist/hooks/types.d.ts +152 -0
- package/dist/hooks/types.d.ts.map +1 -0
- package/dist/hooks/types.js +7 -0
- package/dist/hooks/types.js.map +1 -0
- package/dist/index.d.ts +241 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +712 -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 +24 -0
- package/dist/ipc/ipc-reporter.js.map +1 -0
- package/dist/lsp/client.d.ts +56 -0
- package/dist/lsp/client.d.ts.map +1 -0
- package/dist/lsp/client.js +309 -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 +9 -0
- package/dist/lsp/index.js.map +1 -0
- package/dist/lsp/language.d.ts +9 -0
- package/dist/lsp/language.d.ts.map +1 -0
- package/dist/lsp/language.js +48 -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 +97 -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 +128 -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 +52 -0
- package/dist/lsp/workspace.js.map +1 -0
- package/dist/mcp/config.d.ts +34 -0
- package/dist/mcp/config.d.ts.map +1 -0
- package/dist/mcp/config.js +205 -0
- package/dist/mcp/config.js.map +1 -0
- package/dist/mcp/index.d.ts +5 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +10 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/manager.d.ts +49 -0
- package/dist/mcp/manager.d.ts.map +1 -0
- package/dist/mcp/manager.js +374 -0
- package/dist/mcp/manager.js.map +1 -0
- package/dist/mcp/types.d.ts +85 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/mcp/types.js +1 -0
- package/dist/mcp/types.js.map +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 +28 -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 +21 -0
- package/dist/onboarding/index.js.map +1 -0
- package/dist/onboarding/om-settings.d.ts +20 -0
- package/dist/onboarding/om-settings.d.ts.map +1 -0
- package/dist/onboarding/om-settings.js +26 -0
- package/dist/onboarding/om-settings.js.map +1 -0
- package/dist/onboarding/packs.d.ts +48 -0
- package/dist/onboarding/packs.d.ts.map +1 -0
- package/dist/onboarding/packs.js +111 -0
- package/dist/onboarding/packs.js.map +1 -0
- package/dist/onboarding/settings.d.ts +323 -0
- package/dist/onboarding/settings.d.ts.map +1 -0
- package/dist/onboarding/settings.js +594 -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 +119 -0
- package/dist/permissions.js.map +1 -0
- package/dist/plugin.d.ts +81 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +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 +141 -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 +200 -0
- package/dist/plugins/install.js.map +1 -0
- package/dist/plugins/loader.d.ts +15 -0
- package/dist/plugins/loader.d.ts.map +1 -0
- package/dist/plugins/loader.js +221 -0
- package/dist/plugins/loader.js.map +1 -0
- package/dist/plugins/manager.d.ts +60 -0
- package/dist/plugins/manager.d.ts.map +1 -0
- package/dist/plugins/manager.js +378 -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 +75 -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 +77 -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 +26 -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 +96 -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 +152 -0
- package/dist/plugins/scaffold.js.map +1 -0
- package/dist/plugins/types.d.ts +45 -0
- package/dist/plugins/types.d.ts.map +1 -0
- package/dist/plugins/types.js +1 -0
- package/dist/plugins/types.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 +53 -0
- package/dist/processors/plan-rejection-abort.js.map +1 -0
- package/dist/providers/amazon-bedrock-gateway.d.ts +40 -0
- package/dist/providers/amazon-bedrock-gateway.d.ts.map +1 -0
- package/dist/providers/amazon-bedrock-gateway.js +79 -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 +62 -0
- package/dist/providers/amazon-bedrock.js.map +1 -0
- package/dist/providers/claude-max.d.ts +50 -0
- package/dist/providers/claude-max.d.ts.map +1 -0
- package/dist/providers/claude-max.js +151 -0
- package/dist/providers/claude-max.js.map +1 -0
- package/dist/providers/github-copilot.d.ts +58 -0
- package/dist/providers/github-copilot.d.ts.map +1 -0
- package/dist/providers/github-copilot.js +263 -0
- package/dist/providers/github-copilot.js.map +1 -0
- package/dist/providers/openai-codex.d.ts +70 -0
- package/dist/providers/openai-codex.d.ts.map +1 -0
- package/dist/providers/openai-codex.js +291 -0
- package/dist/providers/openai-codex.js.map +1 -0
- package/dist/schema.d.ts +167 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +92 -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 +17 -0
- package/dist/theme-palette.js.map +1 -0
- package/dist/tool-names.d.ts +73 -0
- package/dist/tool-names.d.ts.map +1 -0
- package/dist/tool-names.js +43 -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 +9 -0
- package/dist/tools/index.js.map +1 -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 +88 -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 +22 -0
- package/dist/tools/utils.js.map +1 -0
- package/dist/tools/web-search.d.ts +35 -0
- package/dist/tools/web-search.d.ts.map +1 -0
- package/dist/tools/web-search.js +65 -0
- package/dist/tools/web-search.js.map +1 -0
- package/dist/utils/binaries.d.ts +7 -0
- package/dist/utils/binaries.d.ts.map +1 -0
- package/dist/utils/binaries.js +74 -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 +55 -0
- package/dist/utils/debug-log.js.map +1 -0
- package/dist/utils/errors.d.ts +36 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +207 -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 +49 -0
- package/dist/utils/gateway-sync.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 +43 -0
- package/dist/utils/plan-diff.js.map +1 -0
- package/dist/utils/plans.d.ts +56 -0
- package/dist/utils/plans.d.ts.map +1 -0
- package/dist/utils/plans.js +99 -0
- package/dist/utils/plans.js.map +1 -0
- package/dist/utils/project.d.ts +161 -0
- package/dist/utils/project.d.ts.map +1 -0
- package/dist/utils/project.js +302 -0
- package/dist/utils/project.js.map +1 -0
- package/dist/utils/signals-pubsub.d.ts +41 -0
- package/dist/utils/signals-pubsub.d.ts.map +1 -0
- package/dist/utils/signals-pubsub.js +104 -0
- package/dist/utils/signals-pubsub.js.map +1 -0
- package/dist/utils/slash-command-loader.d.ts +48 -0
- package/dist/utils/slash-command-loader.d.ts.map +1 -0
- package/dist/utils/slash-command-loader.js +155 -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 +96 -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 +72 -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 +98 -0
- package/dist/utils/storage-factory.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 +108 -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 +52 -0
- package/dist/utils/update-check.d.ts.map +1 -0
- package/dist/utils/update-check.js +177 -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 +126 -0
- package/dist/voice/stt-registry.js.map +1 -0
- package/package.json +92 -0
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { execa } from "execa";
|
|
4
|
+
import { getEntryPackageRoot, installPluginDependenciesForEntry } from "./dependencies.js";
|
|
5
|
+
import { discoverLocalPlugins, installGithubPlugin, installLocalPlugin, NON_INTERACTIVE_GIT_ENV } from "./install.js";
|
|
6
|
+
import { collectActivePluginTools, isInsideDirectory, loadPlugins, resolvePluginEntryPath } from "./loader.js";
|
|
7
|
+
import { ensureMastraCodePackageLink } from "./package-link.js";
|
|
8
|
+
import { getPluginScopePaths } from "./paths.js";
|
|
9
|
+
import { loadPluginRegistry, removePluginRecord, savePluginRegistry, setPluginRecord } from "./registry.js";
|
|
10
|
+
const GITHUB_PLUGIN_POLL_INTERVAL_MS = 6e4;
|
|
11
|
+
function gitExecOptions(cwd) {
|
|
12
|
+
return { cwd, env: NON_INTERACTIVE_GIT_ENV };
|
|
13
|
+
}
|
|
14
|
+
function getEntryVersion(entryPath) {
|
|
15
|
+
const stat = fs.statSync(entryPath, { bigint: true });
|
|
16
|
+
return `${stat.mtimeNs}:${stat.size}`;
|
|
17
|
+
}
|
|
18
|
+
class PluginManager {
|
|
19
|
+
constructor(options) {
|
|
20
|
+
this.options = options;
|
|
21
|
+
}
|
|
22
|
+
options;
|
|
23
|
+
loadedPlugins = [];
|
|
24
|
+
pluginTools = {};
|
|
25
|
+
rawPluginTools = {};
|
|
26
|
+
toolRenderConfigs = /* @__PURE__ */ new Map();
|
|
27
|
+
watchedLocalEntries = /* @__PURE__ */ new Set();
|
|
28
|
+
localEntryVersions = /* @__PURE__ */ new Map();
|
|
29
|
+
githubPollTimer;
|
|
30
|
+
githubPollInFlight;
|
|
31
|
+
reloadInFlight;
|
|
32
|
+
reloadListeners = /* @__PURE__ */ new Set();
|
|
33
|
+
onReload(listener) {
|
|
34
|
+
this.reloadListeners.add(listener);
|
|
35
|
+
return () => this.reloadListeners.delete(listener);
|
|
36
|
+
}
|
|
37
|
+
async reload() {
|
|
38
|
+
if (this.reloadInFlight) return this.reloadInFlight;
|
|
39
|
+
this.reloadInFlight = (async () => {
|
|
40
|
+
this.loadedPlugins = await loadPlugins(this.options);
|
|
41
|
+
this.updateLocalEntryWatchers(this.loadedPlugins);
|
|
42
|
+
this.updateGithubPoller(this.loadedPlugins);
|
|
43
|
+
this.updatePluginRenderConfigs(this.loadedPlugins);
|
|
44
|
+
this.updatePluginTools(collectActivePluginTools(this.loadedPlugins));
|
|
45
|
+
await this.notifyReloadListeners(this.loadedPlugins);
|
|
46
|
+
return this.loadedPlugins;
|
|
47
|
+
})().finally(() => {
|
|
48
|
+
this.reloadInFlight = void 0;
|
|
49
|
+
});
|
|
50
|
+
return this.reloadInFlight;
|
|
51
|
+
}
|
|
52
|
+
async listPlugins() {
|
|
53
|
+
if (this.loadedPlugins.length === 0) {
|
|
54
|
+
await this.reload();
|
|
55
|
+
}
|
|
56
|
+
return this.loadedPlugins;
|
|
57
|
+
}
|
|
58
|
+
getLoadedPlugins() {
|
|
59
|
+
return this.loadedPlugins;
|
|
60
|
+
}
|
|
61
|
+
getPluginTools() {
|
|
62
|
+
return this.pluginTools;
|
|
63
|
+
}
|
|
64
|
+
getToolRenderConfig(toolName) {
|
|
65
|
+
return this.toolRenderConfigs.get(toolName);
|
|
66
|
+
}
|
|
67
|
+
getPluginSkillPaths() {
|
|
68
|
+
return this.loadedPlugins.flatMap((plugin) => plugin.status === "active" ? plugin.skillPaths ?? [] : []);
|
|
69
|
+
}
|
|
70
|
+
getPluginCommandPaths() {
|
|
71
|
+
return this.loadedPlugins.flatMap((plugin) => plugin.status === "active" ? plugin.commandPaths ?? [] : []);
|
|
72
|
+
}
|
|
73
|
+
getPluginInstructions() {
|
|
74
|
+
return this.loadedPlugins.flatMap(
|
|
75
|
+
(plugin) => plugin.status === "active" && plugin.instructions ? [plugin.instructions] : []
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
async notifyReloadListeners(plugins) {
|
|
79
|
+
await Promise.all([...this.reloadListeners].map((listener) => Promise.resolve(listener(plugins))));
|
|
80
|
+
}
|
|
81
|
+
updatePluginRenderConfigs(plugins) {
|
|
82
|
+
this.toolRenderConfigs.clear();
|
|
83
|
+
for (const plugin of plugins) {
|
|
84
|
+
if (plugin.status !== "active") continue;
|
|
85
|
+
for (const [toolName, renderConfig] of Object.entries(plugin.renderConfigs ?? {})) {
|
|
86
|
+
if (!this.toolRenderConfigs.has(toolName)) {
|
|
87
|
+
this.toolRenderConfigs.set(toolName, renderConfig);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
updatePluginTools(nextTools) {
|
|
93
|
+
for (const name of Object.keys(this.rawPluginTools)) {
|
|
94
|
+
if (!(name in nextTools)) {
|
|
95
|
+
delete this.rawPluginTools[name];
|
|
96
|
+
delete this.pluginTools[name];
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
for (const [name, tool] of Object.entries(nextTools)) {
|
|
100
|
+
this.rawPluginTools[name] = tool;
|
|
101
|
+
if (!this.pluginTools[name]) {
|
|
102
|
+
this.pluginTools[name] = this.createLiveToolProxy(name);
|
|
103
|
+
}
|
|
104
|
+
this.syncLiveToolProxy(name, tool);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
createLiveToolProxy(toolName) {
|
|
108
|
+
return {
|
|
109
|
+
execute: async (...args) => {
|
|
110
|
+
await this.reloadChangedLocalPlugins();
|
|
111
|
+
const latestTool = this.rawPluginTools[toolName];
|
|
112
|
+
if (!latestTool?.execute) {
|
|
113
|
+
throw new Error(`Plugin tool "${toolName}" is no longer available`);
|
|
114
|
+
}
|
|
115
|
+
return latestTool.execute(...args);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
syncLiveToolProxy(toolName, tool) {
|
|
120
|
+
const proxy = this.pluginTools[toolName];
|
|
121
|
+
if (!proxy) return;
|
|
122
|
+
const mutableProxy = proxy;
|
|
123
|
+
for (const key of Object.keys(mutableProxy)) {
|
|
124
|
+
delete mutableProxy[key];
|
|
125
|
+
}
|
|
126
|
+
Object.assign(proxy, tool);
|
|
127
|
+
proxy.execute = this.createLiveToolProxy(toolName).execute;
|
|
128
|
+
}
|
|
129
|
+
async reloadChangedLocalPlugins() {
|
|
130
|
+
for (const plugin of this.loadedPlugins) {
|
|
131
|
+
if (plugin.source !== "local" || plugin.status !== "active") continue;
|
|
132
|
+
const entryPath = resolvePluginEntryPath(plugin, this.options);
|
|
133
|
+
const currentVersion = getEntryVersion(entryPath);
|
|
134
|
+
if (this.localEntryVersions.get(entryPath) !== currentVersion) {
|
|
135
|
+
await this.reload();
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
updateLocalEntryWatchers(plugins) {
|
|
141
|
+
const nextEntries = /* @__PURE__ */ new Set();
|
|
142
|
+
for (const plugin of plugins) {
|
|
143
|
+
if (plugin.source !== "local" || plugin.status !== "active") continue;
|
|
144
|
+
let entryPath;
|
|
145
|
+
let entryVersion;
|
|
146
|
+
try {
|
|
147
|
+
entryPath = resolvePluginEntryPath(plugin, this.options);
|
|
148
|
+
entryVersion = getEntryVersion(entryPath);
|
|
149
|
+
} catch {
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
nextEntries.add(entryPath);
|
|
153
|
+
this.localEntryVersions.set(entryPath, entryVersion);
|
|
154
|
+
if (this.watchedLocalEntries.has(entryPath)) continue;
|
|
155
|
+
const watcher = fs.watchFile(entryPath, { interval: 500 }, (current, previous) => {
|
|
156
|
+
if (current.mtimeMs === previous.mtimeMs) return;
|
|
157
|
+
void this.reload().catch(() => void 0);
|
|
158
|
+
});
|
|
159
|
+
watcher.unref?.();
|
|
160
|
+
this.watchedLocalEntries.add(entryPath);
|
|
161
|
+
}
|
|
162
|
+
for (const entryPath of this.watchedLocalEntries) {
|
|
163
|
+
if (nextEntries.has(entryPath)) continue;
|
|
164
|
+
fs.unwatchFile(entryPath);
|
|
165
|
+
this.watchedLocalEntries.delete(entryPath);
|
|
166
|
+
this.localEntryVersions.delete(entryPath);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
updateGithubPoller(plugins) {
|
|
170
|
+
const hasGithubPlugin = plugins.some(
|
|
171
|
+
(plugin) => plugin.source === "github" && plugin.status !== "inactive" && plugin.status !== "blocked"
|
|
172
|
+
);
|
|
173
|
+
if (hasGithubPlugin && !this.githubPollTimer) {
|
|
174
|
+
this.githubPollTimer = setInterval(() => {
|
|
175
|
+
void this.pollGithubSourcesForUpdates().catch(() => void 0);
|
|
176
|
+
}, GITHUB_PLUGIN_POLL_INTERVAL_MS);
|
|
177
|
+
this.githubPollTimer.unref?.();
|
|
178
|
+
}
|
|
179
|
+
if (!hasGithubPlugin && this.githubPollTimer) {
|
|
180
|
+
clearInterval(this.githubPollTimer);
|
|
181
|
+
this.githubPollTimer = void 0;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
async pollGithubSourcesForUpdates() {
|
|
185
|
+
if (this.githubPollInFlight) return this.githubPollInFlight;
|
|
186
|
+
this.githubPollInFlight = this.pollGithubSourcesForUpdatesOnce().finally(() => {
|
|
187
|
+
this.githubPollInFlight = void 0;
|
|
188
|
+
});
|
|
189
|
+
return this.githubPollInFlight;
|
|
190
|
+
}
|
|
191
|
+
async pollGithubSourcesForUpdatesOnce() {
|
|
192
|
+
let changed = false;
|
|
193
|
+
const seen = /* @__PURE__ */ new Set();
|
|
194
|
+
for (const plugin of this.loadedPlugins) {
|
|
195
|
+
if (plugin.source !== "github" || plugin.status === "inactive" || plugin.status === "blocked") continue;
|
|
196
|
+
const checkoutPath = this.resolvePluginSourcePath(plugin);
|
|
197
|
+
if (seen.has(checkoutPath) || !fs.existsSync(path.join(checkoutPath, ".git"))) continue;
|
|
198
|
+
seen.add(checkoutPath);
|
|
199
|
+
const before = await this.readGitHead(checkoutPath);
|
|
200
|
+
const checkoutChanged = await this.refreshGithubCheckout(plugin, checkoutPath, before);
|
|
201
|
+
const after = await this.readGitHead(checkoutPath);
|
|
202
|
+
if (checkoutChanged || before !== after) changed = true;
|
|
203
|
+
}
|
|
204
|
+
if (changed) {
|
|
205
|
+
await this.reload();
|
|
206
|
+
}
|
|
207
|
+
return changed;
|
|
208
|
+
}
|
|
209
|
+
async refreshGithubCheckout(plugin, checkoutPath, currentHead) {
|
|
210
|
+
await execa("git", ["fetch", "origin"], gitExecOptions(checkoutPath));
|
|
211
|
+
const upstream = await this.resolveGitUpstream(checkoutPath, plugin.ref);
|
|
212
|
+
if (!upstream) return false;
|
|
213
|
+
const [localOnly, remoteOnly] = await this.readGitAheadBehind(checkoutPath, upstream);
|
|
214
|
+
const hasLocalChanges = await this.hasGitWorkingTreeChanges(checkoutPath);
|
|
215
|
+
if (localOnly > 0 || hasLocalChanges) {
|
|
216
|
+
await this.backupGitCheckout(checkoutPath, currentHead, hasLocalChanges);
|
|
217
|
+
}
|
|
218
|
+
if (remoteOnly > 0 || localOnly > 0 || hasLocalChanges) {
|
|
219
|
+
await execa("git", ["reset", "--hard", upstream], gitExecOptions(checkoutPath));
|
|
220
|
+
try {
|
|
221
|
+
await installPluginDependenciesForEntry(checkoutPath, plugin.entry);
|
|
222
|
+
ensureMastraCodePackageLink(getEntryPackageRoot(checkoutPath, plugin.entry));
|
|
223
|
+
} catch (error) {
|
|
224
|
+
await execa("git", ["reset", "--hard", currentHead], gitExecOptions(checkoutPath));
|
|
225
|
+
throw error;
|
|
226
|
+
}
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
async backupGitCheckout(checkoutPath, currentHead, includeWorkingTree) {
|
|
232
|
+
const backupBranch = this.createGitBackupBranchName(currentHead);
|
|
233
|
+
if (includeWorkingTree) {
|
|
234
|
+
const currentBranch = await this.readGitCurrentBranch(checkoutPath);
|
|
235
|
+
await execa("git", ["switch", "-c", backupBranch], gitExecOptions(checkoutPath));
|
|
236
|
+
await execa("git", ["add", "-A"], gitExecOptions(checkoutPath));
|
|
237
|
+
const hasStagedChanges = await this.hasGitStagedChanges(checkoutPath);
|
|
238
|
+
if (hasStagedChanges) {
|
|
239
|
+
await execa(
|
|
240
|
+
"git",
|
|
241
|
+
[
|
|
242
|
+
"-c",
|
|
243
|
+
"user.name=Mastra Code",
|
|
244
|
+
"-c",
|
|
245
|
+
"user.email=noreply@mastra.ai",
|
|
246
|
+
"commit",
|
|
247
|
+
"-m",
|
|
248
|
+
"chore: backup local plugin checkout changes"
|
|
249
|
+
],
|
|
250
|
+
gitExecOptions(checkoutPath)
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
await this.restoreGitCheckout(checkoutPath, currentBranch, currentHead);
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
await execa("git", ["branch", backupBranch, "HEAD"], gitExecOptions(checkoutPath));
|
|
257
|
+
}
|
|
258
|
+
async resolveGitUpstream(cwd, installedRef) {
|
|
259
|
+
try {
|
|
260
|
+
const { stdout } = await execa(
|
|
261
|
+
"git",
|
|
262
|
+
["rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{u}"],
|
|
263
|
+
gitExecOptions(cwd)
|
|
264
|
+
);
|
|
265
|
+
return stdout.trim();
|
|
266
|
+
} catch {
|
|
267
|
+
return installedRef ? void 0 : "origin/main";
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
async readGitAheadBehind(cwd, upstream) {
|
|
271
|
+
const { stdout } = await execa(
|
|
272
|
+
"git",
|
|
273
|
+
["rev-list", "--left-right", "--count", `HEAD...${upstream}`],
|
|
274
|
+
gitExecOptions(cwd)
|
|
275
|
+
);
|
|
276
|
+
const [ahead = "0", behind = "0"] = stdout.trim().split(/\s+/);
|
|
277
|
+
return [Number(ahead) || 0, Number(behind) || 0];
|
|
278
|
+
}
|
|
279
|
+
async hasGitWorkingTreeChanges(cwd) {
|
|
280
|
+
const { stdout } = await execa("git", ["status", "--porcelain"], gitExecOptions(cwd));
|
|
281
|
+
return stdout.trim().length > 0;
|
|
282
|
+
}
|
|
283
|
+
async hasGitStagedChanges(cwd) {
|
|
284
|
+
try {
|
|
285
|
+
await execa("git", ["diff", "--cached", "--quiet"], gitExecOptions(cwd));
|
|
286
|
+
return false;
|
|
287
|
+
} catch {
|
|
288
|
+
return true;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
async restoreGitCheckout(cwd, branch, fallbackHead) {
|
|
292
|
+
if (branch) {
|
|
293
|
+
await execa("git", ["switch", branch], gitExecOptions(cwd));
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
await execa("git", ["checkout", fallbackHead], gitExecOptions(cwd));
|
|
297
|
+
}
|
|
298
|
+
async readGitCurrentBranch(cwd) {
|
|
299
|
+
const { stdout } = await execa("git", ["branch", "--show-current"], gitExecOptions(cwd));
|
|
300
|
+
const branch = stdout.trim();
|
|
301
|
+
return branch.length > 0 ? branch : void 0;
|
|
302
|
+
}
|
|
303
|
+
createGitBackupBranchName(currentHead) {
|
|
304
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
305
|
+
return `mastracode/plugin-backup/${timestamp}-${currentHead.slice(0, 8)}`;
|
|
306
|
+
}
|
|
307
|
+
resolvePluginSourcePath(plugin) {
|
|
308
|
+
const paths = getPluginScopePaths(plugin.scope, this.options);
|
|
309
|
+
return path.isAbsolute(plugin.path) ? plugin.path : path.join(paths.root, plugin.path);
|
|
310
|
+
}
|
|
311
|
+
async readGitHead(cwd) {
|
|
312
|
+
const { stdout } = await execa("git", ["rev-parse", "HEAD"], gitExecOptions(cwd));
|
|
313
|
+
return stdout.trim();
|
|
314
|
+
}
|
|
315
|
+
discoverLocal(searchRoot = ".") {
|
|
316
|
+
return discoverLocalPlugins(searchRoot, this.options);
|
|
317
|
+
}
|
|
318
|
+
async installLocal(localPath, scope, options = {}) {
|
|
319
|
+
const id = await installLocalPlugin(localPath, scope, { ...this.options, ...options });
|
|
320
|
+
await this.reload();
|
|
321
|
+
return id;
|
|
322
|
+
}
|
|
323
|
+
async installGithub(url, scope, options = {}) {
|
|
324
|
+
const id = await installGithubPlugin(url, scope, { ...this.options, ...options });
|
|
325
|
+
await this.reload();
|
|
326
|
+
return id;
|
|
327
|
+
}
|
|
328
|
+
async setEnabled(pluginId, scope, enabled) {
|
|
329
|
+
const paths = getPluginScopePaths(scope, this.options);
|
|
330
|
+
const registry = loadPluginRegistry(paths.registryPath);
|
|
331
|
+
const record = registry.plugins[pluginId];
|
|
332
|
+
if (!record) {
|
|
333
|
+
throw new Error(`Plugin "${pluginId}" is not installed in ${scope} scope`);
|
|
334
|
+
}
|
|
335
|
+
savePluginRegistry(paths.registryPath, setPluginRecord(registry, pluginId, { ...record, enabled }));
|
|
336
|
+
await this.reload();
|
|
337
|
+
}
|
|
338
|
+
async setConfigValue(pluginId, scope, key, value) {
|
|
339
|
+
const paths = getPluginScopePaths(scope, this.options);
|
|
340
|
+
const registry = loadPluginRegistry(paths.registryPath);
|
|
341
|
+
const record = registry.plugins[pluginId];
|
|
342
|
+
if (!record) {
|
|
343
|
+
throw new Error(`Plugin "${pluginId}" is not installed in ${scope} scope`);
|
|
344
|
+
}
|
|
345
|
+
const config = { ...record.config ?? {} };
|
|
346
|
+
if (value === void 0 || value === "") {
|
|
347
|
+
delete config[key];
|
|
348
|
+
} else {
|
|
349
|
+
config[key] = value;
|
|
350
|
+
}
|
|
351
|
+
const nextRecord = { ...record, config: Object.keys(config).length > 0 ? config : void 0 };
|
|
352
|
+
savePluginRegistry(paths.registryPath, setPluginRecord(registry, pluginId, nextRecord));
|
|
353
|
+
await this.reload();
|
|
354
|
+
}
|
|
355
|
+
async uninstall(pluginId, scope) {
|
|
356
|
+
const paths = getPluginScopePaths(scope, this.options);
|
|
357
|
+
const registry = loadPluginRegistry(paths.registryPath);
|
|
358
|
+
const record = registry.plugins[pluginId];
|
|
359
|
+
if (!record) {
|
|
360
|
+
throw new Error(`Plugin "${pluginId}" is not installed in ${scope} scope`);
|
|
361
|
+
}
|
|
362
|
+
savePluginRegistry(paths.registryPath, removePluginRecord(registry, pluginId));
|
|
363
|
+
if (record.source === "github") {
|
|
364
|
+
const checkoutPath = path.resolve(
|
|
365
|
+
path.isAbsolute(record.path) ? record.path : path.join(paths.root, record.path)
|
|
366
|
+
);
|
|
367
|
+
const githubSourcesPath = path.resolve(paths.sourcesPath, "github");
|
|
368
|
+
if (isInsideDirectory(checkoutPath, githubSourcesPath)) {
|
|
369
|
+
fs.rmSync(checkoutPath, { recursive: true, force: true });
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
await this.reload();
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
export {
|
|
376
|
+
PluginManager
|
|
377
|
+
};
|
|
378
|
+
//# sourceMappingURL=manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/manager.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nimport { execa } from 'execa';\n\nimport type { MastraCodePluginConfigValue } from '../plugin.js';\nimport { getEntryPackageRoot, installPluginDependenciesForEntry } from './dependencies.js';\nimport { discoverLocalPlugins, installGithubPlugin, installLocalPlugin, NON_INTERACTIVE_GIT_ENV } from './install.js';\nimport type { InstallPluginOptions } from './install.js';\nimport { collectActivePluginTools, isInsideDirectory, loadPlugins, resolvePluginEntryPath } from './loader.js';\nimport { ensureMastraCodePackageLink } from './package-link.js';\nimport { getPluginScopePaths } from './paths.js';\nimport type { PluginPathOptions } from './paths.js';\nimport { loadPluginRegistry, removePluginRecord, savePluginRegistry, setPluginRecord } from './registry.js';\nimport type { LoadedPlugin, PluginScope } from './types.js';\n\nconst GITHUB_PLUGIN_POLL_INTERVAL_MS = 60_000;\n\nfunction gitExecOptions(cwd: string) {\n return { cwd, env: NON_INTERACTIVE_GIT_ENV };\n}\n\nfunction getEntryVersion(entryPath: string): string {\n const stat = fs.statSync(entryPath, { bigint: true });\n return `${stat.mtimeNs}:${stat.size}`;\n}\n\ntype PluginManagerOptions = PluginPathOptions & {\n githubCliPath?: string;\n};\n\nexport class PluginManager {\n private loadedPlugins: LoadedPlugin[] = [];\n private readonly pluginTools: ReturnType<typeof collectActivePluginTools> = {};\n private readonly rawPluginTools: ReturnType<typeof collectActivePluginTools> = {};\n private readonly toolRenderConfigs = new Map<string, NonNullable<LoadedPlugin['renderConfigs']>[string]>();\n private readonly watchedLocalEntries = new Set<string>();\n private readonly localEntryVersions = new Map<string, string>();\n private githubPollTimer: ReturnType<typeof setInterval> | undefined;\n private githubPollInFlight: Promise<boolean> | undefined;\n private reloadInFlight: Promise<LoadedPlugin[]> | undefined;\n private readonly reloadListeners = new Set<(plugins: LoadedPlugin[]) => void | Promise<void>>();\n\n constructor(private readonly options: PluginManagerOptions) {}\n\n onReload(listener: (plugins: LoadedPlugin[]) => void | Promise<void>): () => void {\n this.reloadListeners.add(listener);\n return () => this.reloadListeners.delete(listener);\n }\n\n async reload(): Promise<LoadedPlugin[]> {\n if (this.reloadInFlight) return this.reloadInFlight;\n\n this.reloadInFlight = (async () => {\n this.loadedPlugins = await loadPlugins(this.options);\n this.updateLocalEntryWatchers(this.loadedPlugins);\n this.updateGithubPoller(this.loadedPlugins);\n this.updatePluginRenderConfigs(this.loadedPlugins);\n this.updatePluginTools(collectActivePluginTools(this.loadedPlugins));\n await this.notifyReloadListeners(this.loadedPlugins);\n return this.loadedPlugins;\n })().finally(() => {\n this.reloadInFlight = undefined;\n });\n\n return this.reloadInFlight;\n }\n\n async listPlugins(): Promise<LoadedPlugin[]> {\n if (this.loadedPlugins.length === 0) {\n await this.reload();\n }\n return this.loadedPlugins;\n }\n\n getLoadedPlugins(): LoadedPlugin[] {\n return this.loadedPlugins;\n }\n\n getPluginTools() {\n return this.pluginTools;\n }\n\n getToolRenderConfig(toolName: string) {\n return this.toolRenderConfigs.get(toolName);\n }\n\n getPluginSkillPaths(): string[] {\n return this.loadedPlugins.flatMap(plugin => (plugin.status === 'active' ? (plugin.skillPaths ?? []) : []));\n }\n\n getPluginCommandPaths(): string[] {\n return this.loadedPlugins.flatMap(plugin => (plugin.status === 'active' ? (plugin.commandPaths ?? []) : []));\n }\n\n getPluginInstructions(): string[] {\n return this.loadedPlugins.flatMap(plugin =>\n plugin.status === 'active' && plugin.instructions ? [plugin.instructions] : [],\n );\n }\n\n private async notifyReloadListeners(plugins: LoadedPlugin[]): Promise<void> {\n await Promise.all([...this.reloadListeners].map(listener => Promise.resolve(listener(plugins))));\n }\n\n private updatePluginRenderConfigs(plugins: LoadedPlugin[]): void {\n this.toolRenderConfigs.clear();\n for (const plugin of plugins) {\n if (plugin.status !== 'active') continue;\n for (const [toolName, renderConfig] of Object.entries(plugin.renderConfigs ?? {})) {\n if (!this.toolRenderConfigs.has(toolName)) {\n this.toolRenderConfigs.set(toolName, renderConfig);\n }\n }\n }\n }\n\n private updatePluginTools(nextTools: ReturnType<typeof collectActivePluginTools>): void {\n for (const name of Object.keys(this.rawPluginTools)) {\n if (!(name in nextTools)) {\n delete this.rawPluginTools[name];\n delete this.pluginTools[name];\n }\n }\n\n for (const [name, tool] of Object.entries(nextTools)) {\n this.rawPluginTools[name] = tool;\n if (!this.pluginTools[name]) {\n this.pluginTools[name] = this.createLiveToolProxy(name);\n }\n this.syncLiveToolProxy(name, tool);\n }\n }\n\n private createLiveToolProxy(toolName: string) {\n return {\n execute: async (...args: any[]) => {\n await this.reloadChangedLocalPlugins();\n const latestTool = this.rawPluginTools[toolName];\n if (!latestTool?.execute) {\n throw new Error(`Plugin tool \"${toolName}\" is no longer available`);\n }\n return (latestTool.execute as (...args: any[]) => unknown)(...args);\n },\n } as LoadedPlugin['tools'][string];\n }\n\n private syncLiveToolProxy(toolName: string, tool: LoadedPlugin['tools'][string]): void {\n const proxy = this.pluginTools[toolName];\n if (!proxy) return;\n const mutableProxy = proxy as unknown as Record<string, unknown>;\n for (const key of Object.keys(mutableProxy)) {\n delete mutableProxy[key];\n }\n Object.assign(proxy, tool);\n proxy.execute = this.createLiveToolProxy(toolName).execute;\n }\n\n private async reloadChangedLocalPlugins(): Promise<void> {\n for (const plugin of this.loadedPlugins) {\n if (plugin.source !== 'local' || plugin.status !== 'active') continue;\n const entryPath = resolvePluginEntryPath(plugin, this.options);\n const currentVersion = getEntryVersion(entryPath);\n if (this.localEntryVersions.get(entryPath) !== currentVersion) {\n await this.reload();\n return;\n }\n }\n }\n\n private updateLocalEntryWatchers(plugins: LoadedPlugin[]): void {\n const nextEntries = new Set<string>();\n for (const plugin of plugins) {\n if (plugin.source !== 'local' || plugin.status !== 'active') continue;\n let entryPath: string;\n let entryVersion: string;\n try {\n entryPath = resolvePluginEntryPath(plugin, this.options);\n entryVersion = getEntryVersion(entryPath);\n } catch {\n continue;\n }\n nextEntries.add(entryPath);\n this.localEntryVersions.set(entryPath, entryVersion);\n if (this.watchedLocalEntries.has(entryPath)) continue;\n\n const watcher = fs.watchFile(entryPath, { interval: 500 }, (current, previous) => {\n if (current.mtimeMs === previous.mtimeMs) return;\n void this.reload().catch(() => undefined);\n });\n watcher.unref?.();\n this.watchedLocalEntries.add(entryPath);\n }\n\n for (const entryPath of this.watchedLocalEntries) {\n if (nextEntries.has(entryPath)) continue;\n fs.unwatchFile(entryPath);\n this.watchedLocalEntries.delete(entryPath);\n this.localEntryVersions.delete(entryPath);\n }\n }\n\n private updateGithubPoller(plugins: LoadedPlugin[]): void {\n const hasGithubPlugin = plugins.some(\n plugin => plugin.source === 'github' && plugin.status !== 'inactive' && plugin.status !== 'blocked',\n );\n if (hasGithubPlugin && !this.githubPollTimer) {\n this.githubPollTimer = setInterval(() => {\n void this.pollGithubSourcesForUpdates().catch(() => undefined);\n }, GITHUB_PLUGIN_POLL_INTERVAL_MS);\n this.githubPollTimer.unref?.();\n }\n if (!hasGithubPlugin && this.githubPollTimer) {\n clearInterval(this.githubPollTimer);\n this.githubPollTimer = undefined;\n }\n }\n\n async pollGithubSourcesForUpdates(): Promise<boolean> {\n if (this.githubPollInFlight) return this.githubPollInFlight;\n this.githubPollInFlight = this.pollGithubSourcesForUpdatesOnce().finally(() => {\n this.githubPollInFlight = undefined;\n });\n return this.githubPollInFlight;\n }\n\n private async pollGithubSourcesForUpdatesOnce(): Promise<boolean> {\n let changed = false;\n const seen = new Set<string>();\n for (const plugin of this.loadedPlugins) {\n if (plugin.source !== 'github' || plugin.status === 'inactive' || plugin.status === 'blocked') continue;\n const checkoutPath = this.resolvePluginSourcePath(plugin);\n if (seen.has(checkoutPath) || !fs.existsSync(path.join(checkoutPath, '.git'))) continue;\n seen.add(checkoutPath);\n\n const before = await this.readGitHead(checkoutPath);\n const checkoutChanged = await this.refreshGithubCheckout(plugin, checkoutPath, before);\n const after = await this.readGitHead(checkoutPath);\n if (checkoutChanged || before !== after) changed = true;\n }\n\n if (changed) {\n await this.reload();\n }\n return changed;\n }\n\n private async refreshGithubCheckout(\n plugin: LoadedPlugin,\n checkoutPath: string,\n currentHead: string,\n ): Promise<boolean> {\n await execa('git', ['fetch', 'origin'], gitExecOptions(checkoutPath));\n const upstream = await this.resolveGitUpstream(checkoutPath, plugin.ref);\n if (!upstream) return false;\n const [localOnly, remoteOnly] = await this.readGitAheadBehind(checkoutPath, upstream);\n const hasLocalChanges = await this.hasGitWorkingTreeChanges(checkoutPath);\n\n if (localOnly > 0 || hasLocalChanges) {\n await this.backupGitCheckout(checkoutPath, currentHead, hasLocalChanges);\n }\n\n if (remoteOnly > 0 || localOnly > 0 || hasLocalChanges) {\n await execa('git', ['reset', '--hard', upstream], gitExecOptions(checkoutPath));\n try {\n await installPluginDependenciesForEntry(checkoutPath, plugin.entry);\n ensureMastraCodePackageLink(getEntryPackageRoot(checkoutPath, plugin.entry));\n } catch (error) {\n await execa('git', ['reset', '--hard', currentHead], gitExecOptions(checkoutPath));\n throw error;\n }\n return true;\n }\n\n return false;\n }\n\n private async backupGitCheckout(\n checkoutPath: string,\n currentHead: string,\n includeWorkingTree: boolean,\n ): Promise<void> {\n const backupBranch = this.createGitBackupBranchName(currentHead);\n\n if (includeWorkingTree) {\n const currentBranch = await this.readGitCurrentBranch(checkoutPath);\n await execa('git', ['switch', '-c', backupBranch], gitExecOptions(checkoutPath));\n await execa('git', ['add', '-A'], gitExecOptions(checkoutPath));\n const hasStagedChanges = await this.hasGitStagedChanges(checkoutPath);\n if (hasStagedChanges) {\n await execa(\n 'git',\n [\n '-c',\n 'user.name=Mastra Code',\n '-c',\n 'user.email=noreply@mastra.ai',\n 'commit',\n '-m',\n 'chore: backup local plugin checkout changes',\n ],\n gitExecOptions(checkoutPath),\n );\n }\n await this.restoreGitCheckout(checkoutPath, currentBranch, currentHead);\n return;\n }\n\n await execa('git', ['branch', backupBranch, 'HEAD'], gitExecOptions(checkoutPath));\n }\n\n private async resolveGitUpstream(cwd: string, installedRef?: string): Promise<string | undefined> {\n try {\n const { stdout } = await execa(\n 'git',\n ['rev-parse', '--abbrev-ref', '--symbolic-full-name', '@{u}'],\n gitExecOptions(cwd),\n );\n return stdout.trim();\n } catch {\n return installedRef ? undefined : 'origin/main';\n }\n }\n\n private async readGitAheadBehind(cwd: string, upstream: string): Promise<[number, number]> {\n const { stdout } = await execa(\n 'git',\n ['rev-list', '--left-right', '--count', `HEAD...${upstream}`],\n gitExecOptions(cwd),\n );\n const [ahead = '0', behind = '0'] = stdout.trim().split(/\\s+/);\n return [Number(ahead) || 0, Number(behind) || 0];\n }\n\n private async hasGitWorkingTreeChanges(cwd: string): Promise<boolean> {\n const { stdout } = await execa('git', ['status', '--porcelain'], gitExecOptions(cwd));\n return stdout.trim().length > 0;\n }\n\n private async hasGitStagedChanges(cwd: string): Promise<boolean> {\n try {\n await execa('git', ['diff', '--cached', '--quiet'], gitExecOptions(cwd));\n return false;\n } catch {\n return true;\n }\n }\n\n private async restoreGitCheckout(cwd: string, branch: string | undefined, fallbackHead: string): Promise<void> {\n if (branch) {\n await execa('git', ['switch', branch], gitExecOptions(cwd));\n return;\n }\n await execa('git', ['checkout', fallbackHead], gitExecOptions(cwd));\n }\n\n private async readGitCurrentBranch(cwd: string): Promise<string | undefined> {\n const { stdout } = await execa('git', ['branch', '--show-current'], gitExecOptions(cwd));\n const branch = stdout.trim();\n return branch.length > 0 ? branch : undefined;\n }\n\n private createGitBackupBranchName(currentHead: string): string {\n const timestamp = new Date().toISOString().replace(/[:.]/g, '-');\n return `mastracode/plugin-backup/${timestamp}-${currentHead.slice(0, 8)}`;\n }\n\n private resolvePluginSourcePath(plugin: LoadedPlugin): string {\n const paths = getPluginScopePaths(plugin.scope, this.options);\n return path.isAbsolute(plugin.path) ? plugin.path : path.join(paths.root, plugin.path);\n }\n\n private async readGitHead(cwd: string): Promise<string> {\n const { stdout } = await execa('git', ['rev-parse', 'HEAD'], gitExecOptions(cwd));\n return stdout.trim();\n }\n\n discoverLocal(searchRoot = '.'): ReturnType<typeof discoverLocalPlugins> {\n return discoverLocalPlugins(searchRoot, this.options);\n }\n\n async installLocal(\n localPath: string,\n scope: PluginScope,\n options: Pick<InstallPluginOptions, 'entry'> = {},\n ): Promise<string> {\n const id = await installLocalPlugin(localPath, scope, { ...this.options, ...options });\n await this.reload();\n return id;\n }\n\n async installGithub(\n url: string,\n scope: PluginScope,\n options: Pick<InstallPluginOptions, 'entry' | 'ref' | 'onOutput' | 'signal'> = {},\n ): Promise<string> {\n const id = await installGithubPlugin(url, scope, { ...this.options, ...options });\n await this.reload();\n return id;\n }\n\n async setEnabled(pluginId: string, scope: PluginScope, enabled: boolean): Promise<void> {\n const paths = getPluginScopePaths(scope, this.options);\n const registry = loadPluginRegistry(paths.registryPath);\n const record = registry.plugins[pluginId];\n if (!record) {\n throw new Error(`Plugin \"${pluginId}\" is not installed in ${scope} scope`);\n }\n savePluginRegistry(paths.registryPath, setPluginRecord(registry, pluginId, { ...record, enabled }));\n await this.reload();\n }\n\n async setConfigValue(\n pluginId: string,\n scope: PluginScope,\n key: string,\n value: MastraCodePluginConfigValue,\n ): Promise<void> {\n const paths = getPluginScopePaths(scope, this.options);\n const registry = loadPluginRegistry(paths.registryPath);\n const record = registry.plugins[pluginId];\n if (!record) {\n throw new Error(`Plugin \"${pluginId}\" is not installed in ${scope} scope`);\n }\n const config = { ...(record.config ?? {}) };\n if (value === undefined || value === '') {\n delete config[key];\n } else {\n config[key] = value;\n }\n const nextRecord = { ...record, config: Object.keys(config).length > 0 ? config : undefined };\n savePluginRegistry(paths.registryPath, setPluginRecord(registry, pluginId, nextRecord));\n await this.reload();\n }\n\n async uninstall(pluginId: string, scope: PluginScope): Promise<void> {\n const paths = getPluginScopePaths(scope, this.options);\n const registry = loadPluginRegistry(paths.registryPath);\n const record = registry.plugins[pluginId];\n if (!record) {\n throw new Error(`Plugin \"${pluginId}\" is not installed in ${scope} scope`);\n }\n\n savePluginRegistry(paths.registryPath, removePluginRecord(registry, pluginId));\n if (record.source === 'github') {\n const checkoutPath = path.resolve(\n path.isAbsolute(record.path) ? record.path : path.join(paths.root, record.path),\n );\n const githubSourcesPath = path.resolve(paths.sourcesPath, 'github');\n if (isInsideDirectory(checkoutPath, githubSourcesPath)) {\n fs.rmSync(checkoutPath, { recursive: true, force: true });\n }\n }\n await this.reload();\n }\n}\n"],"mappings":"AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AAEjB,SAAS,aAAa;AAGtB,SAAS,qBAAqB,yCAAyC;AACvE,SAAS,sBAAsB,qBAAqB,oBAAoB,+BAA+B;AAEvG,SAAS,0BAA0B,mBAAmB,aAAa,8BAA8B;AACjG,SAAS,mCAAmC;AAC5C,SAAS,2BAA2B;AAEpC,SAAS,oBAAoB,oBAAoB,oBAAoB,uBAAuB;AAG5F,MAAM,iCAAiC;AAEvC,SAAS,eAAe,KAAa;AACnC,SAAO,EAAE,KAAK,KAAK,wBAAwB;AAC7C;AAEA,SAAS,gBAAgB,WAA2B;AAClD,QAAM,OAAO,GAAG,SAAS,WAAW,EAAE,QAAQ,KAAK,CAAC;AACpD,SAAO,GAAG,KAAK,OAAO,IAAI,KAAK,IAAI;AACrC;AAMO,MAAM,cAAc;AAAA,EAYzB,YAA6B,SAA+B;AAA/B;AAAA,EAAgC;AAAA,EAAhC;AAAA,EAXrB,gBAAgC,CAAC;AAAA,EACxB,cAA2D,CAAC;AAAA,EAC5D,iBAA8D,CAAC;AAAA,EAC/D,oBAAoB,oBAAI,IAAgE;AAAA,EACxF,sBAAsB,oBAAI,IAAY;AAAA,EACtC,qBAAqB,oBAAI,IAAoB;AAAA,EACtD;AAAA,EACA;AAAA,EACA;AAAA,EACS,kBAAkB,oBAAI,IAAuD;AAAA,EAI9F,SAAS,UAAyE;AAChF,SAAK,gBAAgB,IAAI,QAAQ;AACjC,WAAO,MAAM,KAAK,gBAAgB,OAAO,QAAQ;AAAA,EACnD;AAAA,EAEA,MAAM,SAAkC;AACtC,QAAI,KAAK,eAAgB,QAAO,KAAK;AAErC,SA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AW,mBAAmB,MAAM,YAAY;AACtD,UAAM,SAAS,SAAS,QAAQ,QAAQ;AACxC,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI,MAAM,WAAW,QAAQ,yBAAyB,KAAK,QAAQ;AAAA,IAC3E;AAEA,uBAAmB,MAAM,cAAc,mBAAmB,UAAU,QAAQ,CAAC;AAC7E,QAAI,OAAO,WAAW,UAAU;AAC9B,YAAM,eAAe,KAAK;AAAA,QACxB,KAAK,WAAW,OAAO,IAAI,IAAI,OAAO,OAAO,KAAK,KAAK,MAAM,MAAM,OAAO,IAAI;AAAA,MAChF;AACA,YAAM,oBAAoB,KAAK,QAAQ,MAAM,aAAa,QAAQ;AAClE,UAAI,kBAAkB,cAAc,iBAAiB,GAAG;AACtD,WAAG,OAAO,cAAc,EAAE,WAAW,MAAM,OAAO,KAAK,CAAC;AAAA,MAC1D;AAAA,IACF;AACA,UAAM,KAAK,OAAO;AAAA,EACpB;AACF;","names":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const PLUGIN_MANIFEST_FILE = ".mastracode-plugin.json";
|
|
2
|
+
export type PluginManifestEntry = {
|
|
3
|
+
id: string;
|
|
4
|
+
name?: string;
|
|
5
|
+
entry: string;
|
|
6
|
+
};
|
|
7
|
+
export type PluginManifest = {
|
|
8
|
+
plugins: PluginManifestEntry[];
|
|
9
|
+
};
|
|
10
|
+
export declare function loadPluginManifest(rootDir: string): PluginManifest | undefined;
|
|
11
|
+
export declare function savePluginManifest(rootDir: string, manifest: PluginManifest): void;
|
|
12
|
+
export declare function upsertPluginManifestEntry(rootDir: string, entry: PluginManifestEntry): void;
|
|
13
|
+
export declare function getSingleManifestPlugin(rootDir: string): PluginManifestEntry | undefined;
|
|
14
|
+
//# sourceMappingURL=manifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/plugins/manifest.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,oBAAoB,4BAA4B,CAAC;AAE9D,MAAM,MAAM,mBAAmB,GAAG;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,mBAAmB,EAAE,CAAC;CAChC,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAoB9E;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,GAAG,IAAI,CAElF;AAED,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,mBAAmB,GAAG,IAAI,CAU3F;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,mBAAmB,GAAG,SAAS,CAYxF"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
const PLUGIN_MANIFEST_FILE = ".mastracode-plugin.json";
|
|
4
|
+
function loadPluginManifest(rootDir) {
|
|
5
|
+
const manifestPath = path.join(rootDir, PLUGIN_MANIFEST_FILE);
|
|
6
|
+
if (!fs.existsSync(manifestPath)) return void 0;
|
|
7
|
+
let parsed;
|
|
8
|
+
try {
|
|
9
|
+
parsed = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
|
10
|
+
} catch (error) {
|
|
11
|
+
throw new Error(
|
|
12
|
+
`Could not parse ${PLUGIN_MANIFEST_FILE}: ${error instanceof Error ? error.message : String(error)}`
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
if (!parsed || typeof parsed !== "object" || !Array.isArray(parsed.plugins)) {
|
|
16
|
+
throw new Error(`${PLUGIN_MANIFEST_FILE} must contain a plugins array`);
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
plugins: parsed.plugins.map((entry, index) => validateManifestEntry(entry, index))
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function savePluginManifest(rootDir, manifest) {
|
|
23
|
+
fs.writeFileSync(path.join(rootDir, PLUGIN_MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}
|
|
24
|
+
`);
|
|
25
|
+
}
|
|
26
|
+
function upsertPluginManifestEntry(rootDir, entry) {
|
|
27
|
+
const manifest = loadPluginManifest(rootDir) ?? { plugins: [] };
|
|
28
|
+
const validatedEntry = validateManifestEntry(entry, manifest.plugins.length);
|
|
29
|
+
const existingIndex = manifest.plugins.findIndex((plugin) => plugin.id === validatedEntry.id);
|
|
30
|
+
if (existingIndex >= 0) {
|
|
31
|
+
manifest.plugins[existingIndex] = validateManifestEntry(validatedEntry, existingIndex);
|
|
32
|
+
} else {
|
|
33
|
+
manifest.plugins.push(validatedEntry);
|
|
34
|
+
}
|
|
35
|
+
savePluginManifest(rootDir, manifest);
|
|
36
|
+
}
|
|
37
|
+
function getSingleManifestPlugin(rootDir) {
|
|
38
|
+
const manifest = loadPluginManifest(rootDir);
|
|
39
|
+
if (!manifest) return void 0;
|
|
40
|
+
if (manifest.plugins.length === 0) return void 0;
|
|
41
|
+
if (manifest.plugins.length > 1) {
|
|
42
|
+
throw new Error(
|
|
43
|
+
`${PLUGIN_MANIFEST_FILE} contains multiple plugins. Provide an entry path for one of: ${manifest.plugins.map((plugin) => `${plugin.id} (${plugin.entry})`).join(", ")}`
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
return manifest.plugins[0];
|
|
47
|
+
}
|
|
48
|
+
function validateManifestEntry(entry, index) {
|
|
49
|
+
if (!entry || typeof entry !== "object") {
|
|
50
|
+
throw new Error(`${PLUGIN_MANIFEST_FILE} plugin at index ${index} must be an object`);
|
|
51
|
+
}
|
|
52
|
+
const candidate = entry;
|
|
53
|
+
if (typeof candidate.id !== "string" || candidate.id.length === 0) {
|
|
54
|
+
throw new Error(`${PLUGIN_MANIFEST_FILE} plugin at index ${index} must include an id`);
|
|
55
|
+
}
|
|
56
|
+
if (typeof candidate.entry !== "string" || candidate.entry.length === 0) {
|
|
57
|
+
throw new Error(`${PLUGIN_MANIFEST_FILE} plugin ${candidate.id} must include an entry`);
|
|
58
|
+
}
|
|
59
|
+
if (candidate.name !== void 0 && typeof candidate.name !== "string") {
|
|
60
|
+
throw new Error(`${PLUGIN_MANIFEST_FILE} plugin ${candidate.id} name must be a string`);
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
id: candidate.id,
|
|
64
|
+
entry: candidate.entry,
|
|
65
|
+
...candidate.name ? { name: candidate.name } : {}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export {
|
|
69
|
+
PLUGIN_MANIFEST_FILE,
|
|
70
|
+
getSingleManifestPlugin,
|
|
71
|
+
loadPluginManifest,
|
|
72
|
+
savePluginManifest,
|
|
73
|
+
upsertPluginManifestEntry
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/manifest.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nexport const PLUGIN_MANIFEST_FILE = '.mastracode-plugin.json';\n\nexport type PluginManifestEntry = {\n id: string;\n name?: string;\n entry: string;\n};\n\nexport type PluginManifest = {\n plugins: PluginManifestEntry[];\n};\n\nexport function loadPluginManifest(rootDir: string): PluginManifest | undefined {\n const manifestPath = path.join(rootDir, PLUGIN_MANIFEST_FILE);\n if (!fs.existsSync(manifestPath)) return undefined;\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));\n } catch (error) {\n throw new Error(\n `Could not parse ${PLUGIN_MANIFEST_FILE}: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n\n if (!parsed || typeof parsed !== 'object' || !Array.isArray((parsed as { plugins?: unknown }).plugins)) {\n throw new Error(`${PLUGIN_MANIFEST_FILE} must contain a plugins array`);\n }\n\n return {\n plugins: (parsed as { plugins: unknown[] }).plugins.map((entry, index) => validateManifestEntry(entry, index)),\n };\n}\n\nexport function savePluginManifest(rootDir: string, manifest: PluginManifest): void {\n fs.writeFileSync(path.join(rootDir, PLUGIN_MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}\\n`);\n}\n\nexport function upsertPluginManifestEntry(rootDir: string, entry: PluginManifestEntry): void {\n const manifest = loadPluginManifest(rootDir) ?? { plugins: [] };\n const validatedEntry = validateManifestEntry(entry, manifest.plugins.length);\n const existingIndex = manifest.plugins.findIndex(plugin => plugin.id === validatedEntry.id);\n if (existingIndex >= 0) {\n manifest.plugins[existingIndex] = validateManifestEntry(validatedEntry, existingIndex);\n } else {\n manifest.plugins.push(validatedEntry);\n }\n savePluginManifest(rootDir, manifest);\n}\n\nexport function getSingleManifestPlugin(rootDir: string): PluginManifestEntry | undefined {\n const manifest = loadPluginManifest(rootDir);\n if (!manifest) return undefined;\n if (manifest.plugins.length === 0) return undefined;\n if (manifest.plugins.length > 1) {\n throw new Error(\n `${PLUGIN_MANIFEST_FILE} contains multiple plugins. Provide an entry path for one of: ${manifest.plugins\n .map(plugin => `${plugin.id} (${plugin.entry})`)\n .join(', ')}`,\n );\n }\n return manifest.plugins[0];\n}\n\nfunction validateManifestEntry(entry: unknown, index: number): PluginManifestEntry {\n if (!entry || typeof entry !== 'object') {\n throw new Error(`${PLUGIN_MANIFEST_FILE} plugin at index ${index} must be an object`);\n }\n const candidate = entry as { id?: unknown; name?: unknown; entry?: unknown };\n if (typeof candidate.id !== 'string' || candidate.id.length === 0) {\n throw new Error(`${PLUGIN_MANIFEST_FILE} plugin at index ${index} must include an id`);\n }\n if (typeof candidate.entry !== 'string' || candidate.entry.length === 0) {\n throw new Error(`${PLUGIN_MANIFEST_FILE} plugin ${candidate.id} must include an entry`);\n }\n if (candidate.name !== undefined && typeof candidate.name !== 'string') {\n throw new Error(`${PLUGIN_MANIFEST_FILE} plugin ${candidate.id} name must be a string`);\n }\n return {\n id: candidate.id,\n entry: candidate.entry,\n ...(candidate.name ? { name: candidate.name } : {}),\n };\n}\n"],"mappings":"AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AAEV,MAAM,uBAAuB;AAY7B,SAAS,mBAAmB,SAA6C;AAC9E,QAAM,eAAe,KAAK,KAAK,SAAS,oBAAoB;AAC5D,MAAI,CAAC,GAAG,WAAW,YAAY,EAAG,QAAO;AAEzC,MAAI;AACJ,MAAI;AACF,aAAS,KAAK,MAAM,GAAG,aAAa,cAAc,MAAM,CAAC;AAAA,EAC3D,SAAS,OAAO;AACd,UAAM,IAAI;AAAA,MACR,mBAAmB,oBAAoB,KAAK,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AAAA,IACpG;AAAA,EACF;AAEA,MAAI,CAAC,UAAU,OAAO,WAAW,YAAY,CAAC,MAAM,QAAS,OAAiC,OAAO,GAAG;AACtG,UAAM,IAAI,MAAM,GAAG,oBAAoB,+BAA+B;AAAA,EACxE;AAEA,SAAO;AAAA,IACL,SAAU,OAAkC,QAAQ,IAAI,CAAC,OAAO,UAAU,sBAAsB,OAAO,KAAK,CAAC;AAAA,EAC/G;AACF;AAEO,SAAS,mBAAmB,SAAiB,UAAgC;AAClF,KAAG,cAAc,KAAK,KAAK,SAAS,oBAAoB,GAAG,GAAG,KAAK,UAAU,UAAU,MAAM,CAAC,CAAC;AAAA,CAAI;AACrG;AAEO,SAAS,0BAA0B,SAAiB,OAAkC;AAC3F,QAAM,WAAW,mBAAmB,OAAO,KAAK,EAAE,SAAS,CAAC,EAAE;AAC9D,QAAM,iBAAiB,sBAAsB,OAAO,SAAS,QAAQ,MAAM;AAC3E,QAAM,gBAAgB,SAAS,QAAQ,UAAU,YAAU,OAAO,OAAO,eAAe,EAAE;AAC1F,MAAI,iBAAiB,GAAG;AACtB,aAAS,QAAQ,aAAa,IAAI,sBAAsB,gBAAgB,aAAa;AAAA,EACvF,OAAO;AACL,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sources":["../../src/plugins/package-link.ts"],"names":[],"mappings":"AA+BA,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CA4BlE;AAED,wBAAgB,2BAA2B,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAmBnE"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
const MODULE_DIR = path.dirname(fileURLToPath(import.meta.url));
|
|
5
|
+
let cachedPackageRoot;
|
|
6
|
+
function mastraCodePackageRoot() {
|
|
7
|
+
if (cachedPackageRoot === void 0) {
|
|
8
|
+
try {
|
|
9
|
+
cachedPackageRoot = findMastraCodePackageRoot(MODULE_DIR);
|
|
10
|
+
} catch (error) {
|
|
11
|
+
const entryScript = process.argv[1];
|
|
12
|
+
if (!entryScript) throw error;
|
|
13
|
+
cachedPackageRoot = findMastraCodePackageRoot(path.dirname(fs.realpathSync(entryScript)));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return cachedPackageRoot;
|
|
17
|
+
}
|
|
18
|
+
function readPackageName(dir) {
|
|
19
|
+
const packageJsonPath = path.join(dir, "package.json");
|
|
20
|
+
if (!fs.existsSync(packageJsonPath)) return void 0;
|
|
21
|
+
return JSON.parse(fs.readFileSync(packageJsonPath, "utf8")).name;
|
|
22
|
+
}
|
|
23
|
+
function findMastraCodePackageRoot(startDir) {
|
|
24
|
+
let currentDir = path.resolve(startDir);
|
|
25
|
+
while (true) {
|
|
26
|
+
const packageName = readPackageName(currentDir);
|
|
27
|
+
if (packageName === "mastracode") {
|
|
28
|
+
return currentDir;
|
|
29
|
+
}
|
|
30
|
+
if (packageName === "@mastra/code-sdk") {
|
|
31
|
+
for (const candidate of [
|
|
32
|
+
path.resolve(currentDir, "..", "tui"),
|
|
33
|
+
path.resolve(currentDir, "..", "..", "mastracode")
|
|
34
|
+
]) {
|
|
35
|
+
if (readPackageName(candidate) === "mastracode") {
|
|
36
|
+
return candidate;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const parentDir = path.dirname(currentDir);
|
|
41
|
+
if (parentDir === currentDir) {
|
|
42
|
+
throw new Error(`Could not find mastracode package root from ${startDir}`);
|
|
43
|
+
}
|
|
44
|
+
currentDir = parentDir;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function ensureMastraCodePackageLink(pluginDir) {
|
|
48
|
+
if (declaresInstallableMastraCodeDependency(pluginDir)) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const packageRoot = mastraCodePackageRoot();
|
|
52
|
+
const nodeModulesDir = path.join(pluginDir, "node_modules");
|
|
53
|
+
const linkPath = path.join(nodeModulesDir, "mastracode");
|
|
54
|
+
try {
|
|
55
|
+
if (fs.realpathSync(linkPath) === fs.realpathSync(packageRoot)) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
fs.rmSync(linkPath, { recursive: true, force: true });
|
|
59
|
+
} catch (error) {
|
|
60
|
+
if (error.code !== "ENOENT") throw error;
|
|
61
|
+
}
|
|
62
|
+
fs.mkdirSync(nodeModulesDir, { recursive: true });
|
|
63
|
+
fs.symlinkSync(packageRoot, linkPath, "dir");
|
|
64
|
+
}
|
|
65
|
+
function declaresInstallableMastraCodeDependency(pluginDir) {
|
|
66
|
+
const packageJsonPath = path.join(pluginDir, "package.json");
|
|
67
|
+
if (!fs.existsSync(packageJsonPath)) return false;
|
|
68
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
69
|
+
return Boolean(
|
|
70
|
+
packageJson.dependencies?.mastracode ?? packageJson.devDependencies?.mastracode ?? packageJson.optionalDependencies?.mastracode
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
export {
|
|
74
|
+
ensureMastraCodePackageLink,
|
|
75
|
+
findMastraCodePackageRoot
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=package-link.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/package-link.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nconst MODULE_DIR = path.dirname(fileURLToPath(import.meta.url));\n\nlet cachedPackageRoot: string | undefined;\n\n// This module ships in @mastra/code-sdk, so the `mastracode` package root is\n// resolved lazily: from the module location (source tree / bundled dist), or —\n// for the published CLI where the sdk is an external dependency — from the\n// entry script, which lives inside the `mastracode` package.\nfunction mastraCodePackageRoot(): string {\n if (cachedPackageRoot === undefined) {\n try {\n cachedPackageRoot = findMastraCodePackageRoot(MODULE_DIR);\n } catch (error) {\n const entryScript = process.argv[1];\n if (!entryScript) throw error;\n cachedPackageRoot = findMastraCodePackageRoot(path.dirname(fs.realpathSync(entryScript)));\n }\n }\n return cachedPackageRoot;\n}\n\nfunction readPackageName(dir: string): string | undefined {\n const packageJsonPath = path.join(dir, 'package.json');\n if (!fs.existsSync(packageJsonPath)) return undefined;\n return (JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')) as { name?: string }).name;\n}\n\nexport function findMastraCodePackageRoot(startDir: string): string {\n let currentDir = path.resolve(startDir);\n\n while (true) {\n const packageName = readPackageName(currentDir);\n if (packageName === 'mastracode') {\n return currentDir;\n }\n if (packageName === '@mastra/code-sdk') {\n // The `mastracode` package sits next to the sdk: mastracode/sdk ↔\n // mastracode/tui in the source tree, node_modules/@mastra/code-sdk ↔\n // node_modules/mastracode when installed.\n for (const candidate of [\n path.resolve(currentDir, '..', 'tui'),\n path.resolve(currentDir, '..', '..', 'mastracode'),\n ]) {\n if (readPackageName(candidate) === 'mastracode') {\n return candidate;\n }\n }\n }\n\n const parentDir = path.dirname(currentDir);\n if (parentDir === currentDir) {\n throw new Error(`Could not find mastracode package root from ${startDir}`);\n }\n currentDir = parentDir;\n }\n}\n\nexport function ensureMastraCodePackageLink(pluginDir: string): void {\n if (declaresInstallableMastraCodeDependency(pluginDir)) {\n return;\n }\n\n const packageRoot = mastraCodePackageRoot();\n const nodeModulesDir = path.join(pluginDir, 'node_modules');\n const linkPath = path.join(nodeModulesDir, 'mastracode');\n try {\n if (fs.realpathSync(linkPath) === fs.realpathSync(packageRoot)) {\n return;\n }\n fs.rmSync(linkPath, { recursive: true, force: true });\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error;\n }\n\n fs.mkdirSync(nodeModulesDir, { recursive: true });\n fs.symlinkSync(packageRoot, linkPath, 'dir');\n}\n\nfunction declaresInstallableMastraCodeDependency(pluginDir: string): boolean {\n const packageJsonPath = path.join(pluginDir, 'package.json');\n if (!fs.existsSync(packageJsonPath)) return false;\n\n const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')) as {\n dependencies?: Record<string, unknown>;\n devDependencies?: Record<string, unknown>;\n optionalDependencies?: Record<string, unknown>;\n };\n\n return Boolean(\n packageJson.dependencies?.mastracode ??\n packageJson.devDependencies?.mastracode ??\n packageJson.optionalDependencies?.mastracode,\n );\n}\n"],"mappings":"AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,SAAS,qBAAqB;AAE9B,MAAM,aAAa,KAAK,QAAQ,cAAc,YAAY,GAAG,CAAC;AAE9D,IAAI;AAMJ,SAAS,wBAAgC;AACvC,MAAI,sBAAsB,QAAW;AACnC,QAAI;AACF,0BAAoB,0BAA0B,UAAU;AAAA,IAC1D,SAAS,OAAO;AACd,YAAM,cAAc,QAAQ,KAAK,CAAC;AAClC,UAAI,CAAC,YAAa,OAAM;AACxB,0BAAoB,0BAA0B,KAAK,QAAQ,GAAG,aAAa,WAAW,CAAC,CAAC;AAAA,IAC1F;AAAA,EACF;AACA,SAAO;AACT;AAEA,SAAS,gBAAgB,KAAiC;AACxD,QAAM,kBAAkB,KAAK,KAAK,KAAK,cAAc;AACrD,MAAI,CAAC,GAAG,WAAW,eAAe,EAAG,QAAO;AAC5C,SAAQ,KAAK,M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AG,QAAO;AAE5C,QAAM,cAAc,KAAK,MAAM,GAAG,aAAa,iBAAiB,MAAM,CAAC;AAMvE,SAAO;AAAA,IACL,YAAY,cAAc,cAC1B,YAAY,iBAAiB,cAC7B,YAAY,sBAAsB;AAAA,EACpC;AACF;","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PluginScope, PluginScopePaths } from './types.js';
|
|
2
|
+
export type PluginPathOptions = {
|
|
3
|
+
projectRoot: string;
|
|
4
|
+
configDir?: string;
|
|
5
|
+
homeDir?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function getPluginRoot(scope: PluginScope, options: PluginPathOptions): string;
|
|
8
|
+
export declare function getPluginRegistryPath(scope: PluginScope, options: PluginPathOptions): string;
|
|
9
|
+
export declare function getPluginScopePaths(scope: PluginScope, options: PluginPathOptions): PluginScopePaths;
|
|
10
|
+
//# sourceMappingURL=paths.d.ts.map
|