@mastra/code-sdk 0.0.0-agent-tags-alpha-20261125185303
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.js +414 -0
- package/dist/acp/errors.d.ts +3 -0
- package/dist/acp/errors.js +11 -0
- package/dist/acp/event-mapper.d.ts +28 -0
- package/dist/acp/event-mapper.js +274 -0
- package/dist/acp/index.d.ts +9 -0
- package/dist/acp/index.js +21 -0
- package/dist/acp/runtime.d.ts +5 -0
- package/dist/acp/runtime.js +91 -0
- package/dist/acp/server.d.ts +4 -0
- package/dist/acp/server.js +35 -0
- package/dist/acp/skills.d.ts +6 -0
- package/dist/acp/skills.js +30 -0
- package/dist/acp.d.ts +2 -0
- package/dist/acp.js +1 -0
- package/dist/agent-connections/messaging-processor.d.ts +17 -0
- package/dist/agent-connections/messaging-processor.js +131 -0
- package/dist/agent-connections/ownership.d.ts +24 -0
- package/dist/agent-connections/ownership.js +96 -0
- package/dist/agent-connections/registry.d.ts +20 -0
- package/dist/agent-connections/registry.js +167 -0
- package/dist/agent-connections/session-advertisement.d.ts +27 -0
- package/dist/agent-connections/session-advertisement.js +86 -0
- package/dist/agent-connections/signal-provider.d.ts +141 -0
- package/dist/agent-connections/signal-provider.js +35 -0
- package/dist/agent-connections/state-processor.d.ts +23 -0
- package/dist/agent-connections/state-processor.js +270 -0
- package/dist/agent-connections/thread-state.d.ts +41 -0
- package/dist/agent-connections/thread-state.js +157 -0
- package/dist/agent-connections/tools.d.ts +133 -0
- package/dist/agent-connections/tools.js +616 -0
- package/dist/agent-connections/types.d.ts +99 -0
- package/dist/agent-connections/types.js +4 -0
- package/dist/agent-connections/untrusted-text.d.ts +5 -0
- package/dist/agent-connections/untrusted-text.js +19 -0
- package/dist/agents/background-completion-events.d.ts +16 -0
- package/dist/agents/background-completion-events.js +16 -0
- package/dist/agents/background-completion.d.ts +22 -0
- package/dist/agents/background-completion.js +73 -0
- package/dist/agents/context-audit.d.ts +84 -0
- package/dist/agents/context-audit.js +115 -0
- package/dist/agents/credential-resolver.d.ts +74 -0
- package/dist/agents/credential-resolver.js +142 -0
- package/dist/agents/custom-provider-source.d.ts +35 -0
- package/dist/agents/custom-provider-source.js +22 -0
- package/dist/agents/fastembed-subprocess.d.ts +52 -0
- package/dist/agents/fastembed-subprocess.js +282 -0
- package/dist/agents/instructions.d.ts +42 -0
- package/dist/agents/instructions.js +69 -0
- package/dist/agents/mastracode-gateway.d.ts +85 -0
- package/dist/agents/mastracode-gateway.js +500 -0
- package/dist/agents/memory.d.ts +36 -0
- package/dist/agents/memory.js +248 -0
- package/dist/agents/model.d.ts +158 -0
- package/dist/agents/model.js +382 -0
- package/dist/agents/modes/build.d.ts +12 -0
- package/dist/agents/modes/build.js +33 -0
- package/dist/agents/modes/explore.d.ts +10 -0
- package/dist/agents/modes/explore.js +25 -0
- package/dist/agents/modes/plan.d.ts +8 -0
- package/dist/agents/modes/plan.js +43 -0
- package/dist/agents/prompts/agent-instructions.d.ts +122 -0
- package/dist/agents/prompts/agent-instructions.js +617 -0
- package/dist/agents/prompts/build.d.ts +12 -0
- package/dist/agents/prompts/build.js +73 -0
- package/dist/agents/prompts/fast.d.ts +5 -0
- package/dist/agents/prompts/fast.js +23 -0
- package/dist/agents/prompts/index.d.ts +61 -0
- package/dist/agents/prompts/index.js +141 -0
- package/dist/agents/prompts/model.d.ts +5 -0
- package/dist/agents/prompts/model.js +20 -0
- package/dist/agents/prompts/plan.d.ts +11 -0
- package/dist/agents/prompts/plan.js +132 -0
- package/dist/agents/prompts/tool-guidance.d.ts +18 -0
- package/dist/agents/prompts/tool-guidance.js +158 -0
- package/dist/agents/sandbox-filesystem.d.ts +232 -0
- package/dist/agents/sandbox-filesystem.js +851 -0
- package/dist/agents/subagents/execute.d.ts +3 -0
- package/dist/agents/subagents/execute.js +24 -0
- package/dist/agents/subagents/explore.d.ts +3 -0
- package/dist/agents/subagents/explore.js +15 -0
- package/dist/agents/subagents/index.d.ts +6 -0
- package/dist/agents/subagents/index.js +15 -0
- package/dist/agents/subagents/plan.d.ts +3 -0
- package/dist/agents/subagents/plan.js +15 -0
- package/dist/agents/thread-caveman-state.d.ts +17 -0
- package/dist/agents/thread-caveman-state.js +104 -0
- package/dist/agents/tool-availability.d.ts +17 -0
- package/dist/agents/tool-availability.js +134 -0
- package/dist/agents/tools.d.ts +37 -0
- package/dist/agents/tools.js +154 -0
- package/dist/agents/workflow-builder-agent.d.ts +2 -0
- package/dist/agents/workflow-builder-agent.js +79 -0
- package/dist/agents/workspace.d.ts +35 -0
- package/dist/agents/workspace.js +207 -0
- package/dist/analytics.d.ts +18 -0
- package/dist/analytics.js +159 -0
- package/dist/auth/account-rotation-processor.d.ts +210 -0
- package/dist/auth/account-rotation-processor.js +662 -0
- package/dist/auth/account-routing-context.d.ts +17 -0
- package/dist/auth/account-routing-context.js +38 -0
- package/dist/auth/authorization-input.d.ts +16 -0
- package/dist/auth/authorization-input.js +39 -0
- package/dist/auth/device-code.d.ts +93 -0
- package/dist/auth/device-code.js +126 -0
- package/dist/auth/index.d.ts +13 -0
- package/dist/auth/index.js +9 -0
- package/dist/auth/pkce.d.ts +13 -0
- package/dist/auth/pkce.js +29 -0
- package/dist/auth/provider-auth-error.d.ts +24 -0
- package/dist/auth/provider-auth-error.js +44 -0
- package/dist/auth/providers/anthropic.d.ts +40 -0
- package/dist/auth/providers/anthropic.js +117 -0
- package/dist/auth/providers/github-copilot.d.ts +154 -0
- package/dist/auth/providers/github-copilot.js +359 -0
- package/dist/auth/providers/kimi-coding.d.ts +38 -0
- package/dist/auth/providers/kimi-coding.js +225 -0
- package/dist/auth/providers/openai-codex.d.ts +141 -0
- package/dist/auth/providers/openai-codex.js +531 -0
- package/dist/auth/providers/xai.d.ts +64 -0
- package/dist/auth/providers/xai.js +223 -0
- package/dist/auth/storage.d.ts +222 -0
- package/dist/auth/storage.js +805 -0
- package/dist/auth/types.d.ts +164 -0
- package/dist/auth/types.js +1 -0
- package/dist/clipboard/index.d.ts +26 -0
- package/dist/clipboard/index.js +224 -0
- package/dist/constants.d.ts +29 -0
- package/dist/constants.js +34 -0
- package/dist/error-classification.d.ts +10 -0
- package/dist/error-classification.js +19 -0
- package/dist/evals/context-builder.d.ts +41 -0
- package/dist/evals/context-builder.js +156 -0
- package/dist/evals/index.d.ts +4 -0
- package/dist/evals/index.js +5 -0
- package/dist/evals/scorers/classify-command.d.ts +30 -0
- package/dist/evals/scorers/classify-command.js +61 -0
- package/dist/evals/scorers/efficiency.d.ts +44 -0
- package/dist/evals/scorers/efficiency.js +256 -0
- package/dist/evals/scorers/extract-tools.d.ts +25 -0
- package/dist/evals/scorers/extract-tools.js +57 -0
- package/dist/evals/scorers/index.d.ts +3 -0
- package/dist/evals/scorers/index.js +3 -0
- package/dist/evals/scorers/outcome.d.ts +49 -0
- package/dist/evals/scorers/outcome.js +360 -0
- package/dist/experimental-agent.d.ts +19 -0
- package/dist/experimental-agent.js +45 -0
- package/dist/factory/client.d.ts +44 -0
- package/dist/factory/client.js +110 -0
- package/dist/factory/remote-controller.d.ts +34 -0
- package/dist/factory/remote-controller.js +40 -0
- package/dist/factory/remote-session.d.ts +210 -0
- package/dist/factory/remote-session.js +415 -0
- package/dist/goal-manager.d.ts +114 -0
- package/dist/goal-manager.js +351 -0
- package/dist/goal-signal.d.ts +14 -0
- package/dist/goal-signal.js +14 -0
- package/dist/headless/cli.d.ts +55 -0
- package/dist/headless/cli.js +261 -0
- package/dist/headless/flags.d.ts +33 -0
- package/dist/headless/flags.js +207 -0
- package/dist/headless/format.d.ts +41 -0
- package/dist/headless/format.js +94 -0
- package/dist/headless/index.d.ts +25 -0
- package/dist/headless/index.js +6 -0
- package/dist/headless/policy.d.ts +17 -0
- package/dist/headless/policy.js +39 -0
- package/dist/headless/run-mc.d.ts +7 -0
- package/dist/headless/run-mc.js +438 -0
- package/dist/headless/types.d.ts +175 -0
- package/dist/headless/types.js +16 -0
- package/dist/hooks/config.d.ts +11 -0
- package/dist/hooks/config.js +77 -0
- package/dist/hooks/executor.d.ts +13 -0
- package/dist/hooks/executor.js +128 -0
- package/dist/hooks/index.d.ts +6 -0
- package/dist/hooks/index.js +5 -0
- package/dist/hooks/manager.d.ts +75 -0
- package/dist/hooks/manager.js +289 -0
- package/dist/hooks/types.d.ts +180 -0
- package/dist/hooks/types.js +5 -0
- package/dist/index.d.ts +537 -0
- package/dist/index.js +1399 -0
- package/dist/ipc/ipc-reporter.d.ts +14 -0
- package/dist/ipc/ipc-reporter.js +18 -0
- package/dist/knowledge-inspector.d.ts +139 -0
- package/dist/knowledge-inspector.js +533 -0
- package/dist/knowledge-scope-id.d.ts +7 -0
- package/dist/knowledge-scope-id.js +10 -0
- package/dist/knowledge-scope.d.ts +41 -0
- package/dist/knowledge-scope.js +85 -0
- package/dist/lsp/client.d.ts +56 -0
- package/dist/lsp/client.js +248 -0
- package/dist/lsp/index.d.ts +4 -0
- package/dist/lsp/index.js +4 -0
- package/dist/lsp/language.d.ts +9 -0
- package/dist/lsp/language.js +41 -0
- package/dist/lsp/manager.d.ts +34 -0
- package/dist/lsp/manager.js +79 -0
- package/dist/lsp/server.d.ts +27 -0
- package/dist/lsp/server.js +158 -0
- package/dist/lsp/workspace.d.ts +9 -0
- package/dist/lsp/workspace.js +52 -0
- package/dist/mcp/config.d.ts +77 -0
- package/dist/mcp/config.js +313 -0
- package/dist/mcp/index.d.ts +6 -0
- package/dist/mcp/index.js +3 -0
- package/dist/mcp/manager.d.ts +104 -0
- package/dist/mcp/manager.js +693 -0
- package/dist/mcp/state.d.ts +35 -0
- package/dist/mcp/state.js +94 -0
- package/dist/mcp/types.d.ts +139 -0
- package/dist/mcp/types.js +1 -0
- package/dist/onboarding/custom-packs.d.ts +7 -0
- package/dist/onboarding/custom-packs.js +17 -0
- package/dist/onboarding/custom-providers.d.ts +4 -0
- package/dist/onboarding/custom-providers.js +27 -0
- package/dist/onboarding/index.d.ts +5 -0
- package/dist/onboarding/index.js +3 -0
- package/dist/onboarding/om-settings.d.ts +47 -0
- package/dist/onboarding/om-settings.js +80 -0
- package/dist/onboarding/pack-activation.d.ts +43 -0
- package/dist/onboarding/pack-activation.js +105 -0
- package/dist/onboarding/packs.d.ts +106 -0
- package/dist/onboarding/packs.js +283 -0
- package/dist/onboarding/settings.d.ts +563 -0
- package/dist/onboarding/settings.js +1110 -0
- package/dist/permissions.d.ts +55 -0
- package/dist/permissions.js +139 -0
- package/dist/platform/index.d.ts +74 -0
- package/dist/platform/index.js +199 -0
- package/dist/plugin.d.ts +156 -0
- package/dist/plugin.js +27 -0
- package/dist/plugins/dependencies.d.ts +9 -0
- package/dist/plugins/dependencies.js +84 -0
- package/dist/plugins/install.d.ts +21 -0
- package/dist/plugins/install.js +187 -0
- package/dist/plugins/loader.d.ts +25 -0
- package/dist/plugins/loader.js +264 -0
- package/dist/plugins/manager.d.ts +115 -0
- package/dist/plugins/manager.js +507 -0
- package/dist/plugins/manifest.d.ts +14 -0
- package/dist/plugins/manifest.js +47 -0
- package/dist/plugins/package-link.d.ts +3 -0
- package/dist/plugins/package-link.js +58 -0
- package/dist/plugins/paths.d.ts +10 -0
- package/dist/plugins/paths.js +22 -0
- package/dist/plugins/registry.d.ts +8 -0
- package/dist/plugins/registry.js +109 -0
- package/dist/plugins/scaffold.d.ts +10 -0
- package/dist/plugins/scaffold.js +115 -0
- package/dist/plugins/signal-lane.d.ts +59 -0
- package/dist/plugins/signal-lane.js +163 -0
- package/dist/plugins/types.d.ts +95 -0
- package/dist/plugins/types.js +1 -0
- package/dist/process-memory-diagnostics.d.ts +136 -0
- package/dist/process-memory-diagnostics.js +497 -0
- package/dist/processors/plan-rejection-abort.d.ts +16 -0
- package/dist/processors/plan-rejection-abort.js +62 -0
- package/dist/providers/amazon-bedrock-gateway.d.ts +47 -0
- package/dist/providers/amazon-bedrock-gateway.js +142 -0
- package/dist/providers/amazon-bedrock.d.ts +28 -0
- package/dist/providers/amazon-bedrock.js +99 -0
- package/dist/providers/anthropic-prompt-cache.d.ts +19 -0
- package/dist/providers/anthropic-prompt-cache.js +8 -0
- package/dist/providers/anthropic-thinking.d.ts +5 -0
- package/dist/providers/anthropic-thinking.js +22 -0
- package/dist/providers/claude-max.d.ts +67 -0
- package/dist/providers/claude-max.js +232 -0
- package/dist/providers/github-copilot-gateway.d.ts +35 -0
- package/dist/providers/github-copilot-gateway.js +58 -0
- package/dist/providers/github-copilot.d.ts +60 -0
- package/dist/providers/github-copilot.js +320 -0
- package/dist/providers/google-thinking.d.ts +31 -0
- package/dist/providers/google-thinking.js +64 -0
- package/dist/providers/google-vertex-gateway.d.ts +23 -0
- package/dist/providers/google-vertex-gateway.js +49 -0
- package/dist/providers/google-vertex.d.ts +6 -0
- package/dist/providers/google-vertex.js +51 -0
- package/dist/providers/kimi-coding.d.ts +14 -0
- package/dist/providers/kimi-coding.js +80 -0
- package/dist/providers/model-ids.d.ts +53 -0
- package/dist/providers/model-ids.js +132 -0
- package/dist/providers/openai-codex.d.ts +114 -0
- package/dist/providers/openai-codex.js +427 -0
- package/dist/providers/provider-thinking.d.ts +23 -0
- package/dist/providers/provider-thinking.js +61 -0
- package/dist/providers/thinking-request.d.ts +14 -0
- package/dist/providers/thinking-request.js +87 -0
- package/dist/providers/xai.d.ts +33 -0
- package/dist/providers/xai.js +72 -0
- package/dist/schedules/index.d.ts +10 -0
- package/dist/schedules/index.js +6 -0
- package/dist/schedules/interval.d.ts +49 -0
- package/dist/schedules/interval.js +212 -0
- package/dist/schedules/prompt.d.ts +36 -0
- package/dist/schedules/prompt.js +36 -0
- package/dist/schedules/run-script.d.ts +8 -0
- package/dist/schedules/run-script.js +80 -0
- package/dist/schedules/scheduler.d.ts +101 -0
- package/dist/schedules/scheduler.js +167 -0
- package/dist/schedules/tools.d.ts +57 -0
- package/dist/schedules/tools.js +217 -0
- package/dist/schema.d.ts +499 -0
- package/dist/schema.js +131 -0
- package/dist/theme-palette.d.ts +17 -0
- package/dist/theme-palette.js +18 -0
- package/dist/thinking-catalog.d.ts +4 -0
- package/dist/thinking-catalog.js +13 -0
- package/dist/thinking.d.ts +37 -0
- package/dist/thinking.js +134 -0
- package/dist/tool-names.d.ts +77 -0
- package/dist/tool-names.js +53 -0
- package/dist/tools/index.d.ts +6 -0
- package/dist/tools/index.js +3 -0
- package/dist/tools/request-sandbox-access.d.ts +6 -0
- package/dist/tools/request-sandbox-access.js +80 -0
- package/dist/tools/utils.d.ts +20 -0
- package/dist/tools/utils.js +31 -0
- package/dist/tools/web-search.d.ts +116 -0
- package/dist/tools/web-search.js +158 -0
- package/dist/tools/workflows/create-workflow.d.ts +7 -0
- package/dist/tools/workflows/create-workflow.js +82 -0
- package/dist/tools/workflows/delete-workflow.d.ts +7 -0
- package/dist/tools/workflows/delete-workflow.js +18 -0
- package/dist/tools/workflows/ephemeral-memory.d.ts +28 -0
- package/dist/tools/workflows/ephemeral-memory.js +41 -0
- package/dist/tools/workflows/extract-json-schema.d.ts +12 -0
- package/dist/tools/workflows/extract-json-schema.js +19 -0
- package/dist/tools/workflows/get-workflow.d.ts +11 -0
- package/dist/tools/workflows/get-workflow.js +31 -0
- package/dist/tools/workflows/list-available-agents.d.ts +8 -0
- package/dist/tools/workflows/list-available-agents.js +29 -0
- package/dist/tools/workflows/list-available-classifiers.d.ts +19 -0
- package/dist/tools/workflows/list-available-classifiers.js +53 -0
- package/dist/tools/workflows/list-available-tools.d.ts +9 -0
- package/dist/tools/workflows/list-available-tools.js +37 -0
- package/dist/tools/workflows/list-available-workflows.d.ts +9 -0
- package/dist/tools/workflows/list-available-workflows.js +29 -0
- package/dist/tools/workflows/list-workflows.d.ts +9 -0
- package/dist/tools/workflows/list-workflows.js +30 -0
- package/dist/tools/workflows/run-workflow.d.ts +9 -0
- package/dist/tools/workflows/run-workflow.js +49 -0
- package/dist/tools/workflows/save-workflow.d.ts +1125 -0
- package/dist/tools/workflows/save-workflow.js +25 -0
- package/dist/tools/workflows/tool-ids.d.ts +16 -0
- package/dist/tools/workflows/tool-ids.js +17 -0
- package/dist/utils/binaries.d.ts +7 -0
- package/dist/utils/binaries.js +97 -0
- package/dist/utils/debug-log.d.ts +12 -0
- package/dist/utils/debug-log.js +56 -0
- package/dist/utils/discarding-scores-storage.d.ts +33 -0
- package/dist/utils/discarding-scores-storage.js +51 -0
- package/dist/utils/errors.d.ts +36 -0
- package/dist/utils/errors.js +215 -0
- package/dist/utils/gateway-sync.d.ts +26 -0
- package/dist/utils/gateway-sync.js +58 -0
- package/dist/utils/local-observability.d.ts +19 -0
- package/dist/utils/local-observability.js +54 -0
- package/dist/utils/maintenance-lock.d.ts +42 -0
- package/dist/utils/maintenance-lock.js +196 -0
- package/dist/utils/notification-dispatch.d.ts +74 -0
- package/dist/utils/notification-dispatch.js +128 -0
- package/dist/utils/open-url.d.ts +10 -0
- package/dist/utils/open-url.js +27 -0
- package/dist/utils/path-security.d.ts +2 -0
- package/dist/utils/path-security.js +7 -0
- package/dist/utils/plan-diff.d.ts +25 -0
- package/dist/utils/plan-diff.js +59 -0
- package/dist/utils/plans.d.ts +61 -0
- package/dist/utils/plans.js +120 -0
- package/dist/utils/project.d.ts +160 -0
- package/dist/utils/project.js +361 -0
- package/dist/utils/prune-cli.d.ts +24 -0
- package/dist/utils/prune-cli.js +124 -0
- package/dist/utils/signals-pubsub.d.ts +103 -0
- package/dist/utils/signals-pubsub.js +409 -0
- package/dist/utils/slash-command-loader.d.ts +52 -0
- package/dist/utils/slash-command-loader.js +139 -0
- package/dist/utils/slash-command-processor.d.ts +14 -0
- package/dist/utils/slash-command-processor.js +106 -0
- package/dist/utils/stdin-pipe.d.ts +33 -0
- package/dist/utils/stdin-pipe.js +93 -0
- package/dist/utils/storage-factory.d.ts +50 -0
- package/dist/utils/storage-factory.js +118 -0
- package/dist/utils/storage-maintenance.d.ts +121 -0
- package/dist/utils/storage-maintenance.js +352 -0
- package/dist/utils/thread-lock.d.ts +26 -0
- package/dist/utils/thread-lock.js +109 -0
- package/dist/utils/token-estimator.d.ts +3 -0
- package/dist/utils/token-estimator.js +19 -0
- package/dist/utils/update-check.d.ts +151 -0
- package/dist/utils/update-check.js +430 -0
- package/dist/utils/wake-session.d.ts +44 -0
- package/dist/utils/wake-session.js +83 -0
- package/dist/voice/stt-registry.d.ts +67 -0
- package/dist/voice/stt-registry.js +144 -0
- package/dist/voice/transcribe.d.ts +10 -0
- package/dist/voice/transcribe.js +75 -0
- package/dist/workflows/register-primitives.d.ts +52 -0
- package/dist/workflows/register-primitives.js +40 -0
- package/dist/workflows/service.d.ts +64 -0
- package/dist/workflows/service.js +50 -0
- package/package.json +117 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
// src/plugins/package-link.ts
|
|
5
|
+
const MODULE_DIR = path.dirname(fileURLToPath(import.meta.url));
|
|
6
|
+
let cachedPackageRoot;
|
|
7
|
+
function mastraCodePackageRoot() {
|
|
8
|
+
if (cachedPackageRoot === void 0) 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
|
+
return cachedPackageRoot;
|
|
16
|
+
}
|
|
17
|
+
function readPackageName(dir) {
|
|
18
|
+
const packageJsonPath = path.join(dir, "package.json");
|
|
19
|
+
if (!fs.existsSync(packageJsonPath)) return void 0;
|
|
20
|
+
return JSON.parse(fs.readFileSync(packageJsonPath, "utf8")).name;
|
|
21
|
+
}
|
|
22
|
+
function findMastraCodePackageRoot(startDir) {
|
|
23
|
+
let currentDir = path.resolve(startDir);
|
|
24
|
+
while (true) {
|
|
25
|
+
const packageName = readPackageName(currentDir);
|
|
26
|
+
if (packageName === "mastracode") return currentDir;
|
|
27
|
+
if (packageName === "@mastra/code-sdk") {
|
|
28
|
+
for (const candidate of [path.resolve(currentDir, "..", "tui"), path.resolve(currentDir, "..", "..", "mastracode")]) if (readPackageName(candidate) === "mastracode") return candidate;
|
|
29
|
+
}
|
|
30
|
+
const parentDir = path.dirname(currentDir);
|
|
31
|
+
if (parentDir === currentDir) throw new Error(`Could not find mastracode package root from ${startDir}`);
|
|
32
|
+
currentDir = parentDir;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function ensureMastraCodePackageLink(pluginDir) {
|
|
36
|
+
if (declaresInstallableMastraCodeDependency(pluginDir)) return;
|
|
37
|
+
const packageRoot = mastraCodePackageRoot();
|
|
38
|
+
const nodeModulesDir = path.join(pluginDir, "node_modules");
|
|
39
|
+
const linkPath = path.join(nodeModulesDir, "mastracode");
|
|
40
|
+
try {
|
|
41
|
+
if (fs.realpathSync(linkPath) === fs.realpathSync(packageRoot)) return;
|
|
42
|
+
fs.rmSync(linkPath, {
|
|
43
|
+
recursive: true,
|
|
44
|
+
force: true
|
|
45
|
+
});
|
|
46
|
+
} catch (error) {
|
|
47
|
+
if (error.code !== "ENOENT") throw error;
|
|
48
|
+
}
|
|
49
|
+
fs.mkdirSync(nodeModulesDir, { recursive: true });
|
|
50
|
+
fs.symlinkSync(packageRoot, linkPath, "dir");
|
|
51
|
+
}
|
|
52
|
+
function declaresInstallableMastraCodeDependency(pluginDir) {
|
|
53
|
+
const packageJsonPath = path.join(pluginDir, "package.json");
|
|
54
|
+
if (!fs.existsSync(packageJsonPath)) return false;
|
|
55
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
56
|
+
return Boolean(packageJson.dependencies?.mastracode ?? packageJson.devDependencies?.mastracode ?? packageJson.optionalDependencies?.mastracode);
|
|
57
|
+
}
|
|
58
|
+
export { ensureMastraCodePackageLink, findMastraCodePackageRoot };
|
|
@@ -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
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import "../constants.js";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import os from "os";
|
|
4
|
+
// src/plugins/paths.ts
|
|
5
|
+
function getPluginRoot(scope, options) {
|
|
6
|
+
const configDir = options.configDir ?? ".mastracode";
|
|
7
|
+
const baseDir = scope === "project" ? options.projectRoot : options.homeDir ?? os.homedir();
|
|
8
|
+
return path.join(baseDir, configDir, "plugins");
|
|
9
|
+
}
|
|
10
|
+
function getPluginRegistryPath(scope, options) {
|
|
11
|
+
return path.join(getPluginRoot(scope, options), "plugins.json");
|
|
12
|
+
}
|
|
13
|
+
function getPluginScopePaths(scope, options) {
|
|
14
|
+
const root = getPluginRoot(scope, options);
|
|
15
|
+
return {
|
|
16
|
+
scope,
|
|
17
|
+
root,
|
|
18
|
+
registryPath: path.join(root, "plugins.json"),
|
|
19
|
+
sourcesPath: path.join(root, "sources")
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export { getPluginRegistryPath, getPluginRoot, getPluginScopePaths };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { InstalledPluginRecord, PluginRegistry, ScopedInstalledPluginRecord } from './types.js';
|
|
2
|
+
export declare const EMPTY_PLUGIN_REGISTRY: PluginRegistry;
|
|
3
|
+
export declare function loadPluginRegistry(registryPath: string): PluginRegistry;
|
|
4
|
+
export declare function savePluginRegistry(registryPath: string, registry: PluginRegistry): void;
|
|
5
|
+
export declare function mergePluginRegistries(globalRegistry: PluginRegistry, projectRegistry: PluginRegistry): ScopedInstalledPluginRecord[];
|
|
6
|
+
export declare function setPluginRecord(registry: PluginRegistry, pluginId: string, record: InstalledPluginRecord): PluginRegistry;
|
|
7
|
+
export declare function removePluginRecord(registry: PluginRegistry, pluginId: string): PluginRegistry;
|
|
8
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
// src/plugins/registry.ts
|
|
4
|
+
const EMPTY_PLUGIN_REGISTRY = {
|
|
5
|
+
plugins: {},
|
|
6
|
+
disabledPlugins: []
|
|
7
|
+
};
|
|
8
|
+
function loadPluginRegistry(registryPath) {
|
|
9
|
+
try {
|
|
10
|
+
if (!fs.existsSync(registryPath)) return {
|
|
11
|
+
plugins: {},
|
|
12
|
+
disabledPlugins: []
|
|
13
|
+
};
|
|
14
|
+
return validatePluginRegistry(JSON.parse(fs.readFileSync(registryPath, "utf-8")));
|
|
15
|
+
} catch {
|
|
16
|
+
return {
|
|
17
|
+
plugins: {},
|
|
18
|
+
disabledPlugins: []
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function savePluginRegistry(registryPath, registry) {
|
|
23
|
+
fs.mkdirSync(path.dirname(registryPath), { recursive: true });
|
|
24
|
+
fs.writeFileSync(registryPath, `${JSON.stringify(validatePluginRegistry(registry), null, 2)}\n`);
|
|
25
|
+
}
|
|
26
|
+
function mergePluginRegistries(globalRegistry, projectRegistry) {
|
|
27
|
+
const merged = /* @__PURE__ */ new Map();
|
|
28
|
+
const disabledPlugins = /* @__PURE__ */ new Set([...globalRegistry.disabledPlugins ?? [], ...projectRegistry.disabledPlugins ?? []]);
|
|
29
|
+
for (const [id, record] of Object.entries(globalRegistry.plugins)) merged.set(id, {
|
|
30
|
+
id,
|
|
31
|
+
scope: "global",
|
|
32
|
+
...record
|
|
33
|
+
});
|
|
34
|
+
for (const [id, record] of Object.entries(projectRegistry.plugins)) merged.set(id, {
|
|
35
|
+
id,
|
|
36
|
+
scope: "project",
|
|
37
|
+
...record
|
|
38
|
+
});
|
|
39
|
+
return [...merged.values()].map((record) => disabledPlugins.has(record.id) ? {
|
|
40
|
+
...record,
|
|
41
|
+
blocked: true
|
|
42
|
+
} : record).sort((a, b) => {
|
|
43
|
+
if (a.scope !== b.scope) return a.scope === "project" ? -1 : 1;
|
|
44
|
+
return a.id.localeCompare(b.id);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function setPluginRecord(registry, pluginId, record) {
|
|
48
|
+
return {
|
|
49
|
+
plugins: {
|
|
50
|
+
...registry.plugins,
|
|
51
|
+
[pluginId]: record
|
|
52
|
+
},
|
|
53
|
+
disabledPlugins: registry.disabledPlugins ?? []
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function removePluginRecord(registry, pluginId) {
|
|
57
|
+
const plugins = { ...registry.plugins };
|
|
58
|
+
delete plugins[pluginId];
|
|
59
|
+
return {
|
|
60
|
+
plugins,
|
|
61
|
+
disabledPlugins: registry.disabledPlugins ?? []
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function validatePluginRegistry(raw) {
|
|
65
|
+
if (!raw || typeof raw !== "object") return {
|
|
66
|
+
plugins: {},
|
|
67
|
+
disabledPlugins: []
|
|
68
|
+
};
|
|
69
|
+
const plugins = raw.plugins;
|
|
70
|
+
if (!plugins || typeof plugins !== "object" || Array.isArray(plugins)) return {
|
|
71
|
+
plugins: {},
|
|
72
|
+
disabledPlugins: []
|
|
73
|
+
};
|
|
74
|
+
const disabledPlugins = raw.disabledPlugins;
|
|
75
|
+
const validated = {
|
|
76
|
+
plugins: {},
|
|
77
|
+
disabledPlugins: Array.isArray(disabledPlugins) ? [...new Set(disabledPlugins.filter((pluginId) => typeof pluginId === "string"))].sort() : []
|
|
78
|
+
};
|
|
79
|
+
for (const [id, value] of Object.entries(plugins)) {
|
|
80
|
+
if (typeof id !== "string" || id.trim().length === 0) continue;
|
|
81
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) continue;
|
|
82
|
+
const record = value;
|
|
83
|
+
if (typeof record.enabled !== "boolean") continue;
|
|
84
|
+
if (record.source !== "local" && record.source !== "github") continue;
|
|
85
|
+
if (typeof record.specifier !== "string") continue;
|
|
86
|
+
if (typeof record.path !== "string") continue;
|
|
87
|
+
if (typeof record.entry !== "string") continue;
|
|
88
|
+
validated.plugins[id] = {
|
|
89
|
+
enabled: record.enabled,
|
|
90
|
+
source: record.source,
|
|
91
|
+
specifier: record.specifier,
|
|
92
|
+
path: record.path,
|
|
93
|
+
entry: record.entry,
|
|
94
|
+
...typeof record.ref === "string" ? { ref: record.ref } : {},
|
|
95
|
+
...typeof record.version === "string" ? { version: record.version } : {},
|
|
96
|
+
...record.config && typeof record.config === "object" && !Array.isArray(record.config) ? { config: validatePluginConfigValues(record.config) } : {}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
return validated;
|
|
100
|
+
}
|
|
101
|
+
function validatePluginConfigValues(raw) {
|
|
102
|
+
const values = {};
|
|
103
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
104
|
+
if (typeof key !== "string" || key.trim().length === 0) continue;
|
|
105
|
+
if (typeof value === "string" || typeof value === "boolean") values[key] = value;
|
|
106
|
+
}
|
|
107
|
+
return values;
|
|
108
|
+
}
|
|
109
|
+
export { EMPTY_PLUGIN_REGISTRY, loadPluginRegistry, mergePluginRegistries, removePluginRecord, savePluginRegistry, setPluginRecord };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type ScaffoldPluginOptions = {
|
|
2
|
+
id?: string;
|
|
3
|
+
name?: string;
|
|
4
|
+
projectRoot?: string;
|
|
5
|
+
configDir?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function resolveScaffoldTarget(target: string, options?: Pick<ScaffoldPluginOptions, 'projectRoot' | 'configDir'>): string;
|
|
8
|
+
export declare function scaffoldPlugin(targetDir: string, options?: ScaffoldPluginOptions): string;
|
|
9
|
+
export declare function formatScaffoldSuccess(targetDir: string): string;
|
|
10
|
+
//# sourceMappingURL=scaffold.d.ts.map
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import "../constants.js";
|
|
2
|
+
import { upsertPluginManifestEntry } from "./manifest.js";
|
|
3
|
+
import { ensureMastraCodePackageLink } from "./package-link.js";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import fs from "fs";
|
|
6
|
+
// src/plugins/scaffold.ts
|
|
7
|
+
function resolveScaffoldTarget(target, options = {}) {
|
|
8
|
+
if (isBarePluginName(target)) return path.join(options.projectRoot ?? process.cwd(), options.configDir ?? ".mastracode", "plugins", "sources", "local", target);
|
|
9
|
+
return path.resolve(options.projectRoot ?? process.cwd(), target);
|
|
10
|
+
}
|
|
11
|
+
function scaffoldPlugin(targetDir, options = {}) {
|
|
12
|
+
const dir = resolveScaffoldTarget(targetDir, options);
|
|
13
|
+
if (fs.existsSync(dir) && fs.readdirSync(dir).length > 0) throw new Error(`Directory already exists and is not empty: ${targetDir}`);
|
|
14
|
+
const packageName = path.basename(dir).toLowerCase().replace(/[^a-z0-9_.-]+/g, "-").replace(/^-|-$/g, "") || "mastracode-plugin";
|
|
15
|
+
const pluginId = options.id ?? packageName;
|
|
16
|
+
const pluginName = options.name ?? humanizeName(packageName);
|
|
17
|
+
fs.mkdirSync(path.join(dir, "src"), { recursive: true });
|
|
18
|
+
fs.writeFileSync(path.join(dir, "package.json"), `${JSON.stringify({
|
|
19
|
+
name: packageName,
|
|
20
|
+
type: "module",
|
|
21
|
+
exports: "./src/index.ts",
|
|
22
|
+
peerDependencies: { mastracode: "*" },
|
|
23
|
+
devDependencies: { typescript: "^5.9.3" },
|
|
24
|
+
scripts: { check: "tsc --noEmit" }
|
|
25
|
+
}, null, 2)}\n`);
|
|
26
|
+
fs.writeFileSync(path.join(dir, "tsconfig.json"), `${JSON.stringify({
|
|
27
|
+
compilerOptions: {
|
|
28
|
+
target: "ES2024",
|
|
29
|
+
module: "NodeNext",
|
|
30
|
+
moduleResolution: "NodeNext",
|
|
31
|
+
strict: true,
|
|
32
|
+
verbatimModuleSyntax: true,
|
|
33
|
+
erasableSyntaxOnly: true,
|
|
34
|
+
skipLibCheck: true,
|
|
35
|
+
noEmit: true
|
|
36
|
+
},
|
|
37
|
+
include: ["src/**/*.ts"]
|
|
38
|
+
}, null, 2)}\n`);
|
|
39
|
+
fs.writeFileSync(path.join(dir, "src/index.ts"), renderIndex(pluginId, pluginName));
|
|
40
|
+
fs.writeFileSync(path.join(dir, "README.md"), renderReadme(pluginName, pluginId));
|
|
41
|
+
writeScaffoldManifest(targetDir, dir, pluginId, pluginName, options);
|
|
42
|
+
ensureMastraCodePackageLink(dir);
|
|
43
|
+
return dir;
|
|
44
|
+
}
|
|
45
|
+
function writeScaffoldManifest(originalTarget, scaffoldDir, pluginId, pluginName, options) {
|
|
46
|
+
const projectRoot = options.projectRoot ?? process.cwd();
|
|
47
|
+
const manifestRoot = isBarePluginName(originalTarget) ? projectRoot : scaffoldDir;
|
|
48
|
+
const entry = isBarePluginName(originalTarget) ? path.join(path.relative(projectRoot, scaffoldDir), "src/index.ts") : "src/index.ts";
|
|
49
|
+
upsertPluginManifestEntry(manifestRoot, {
|
|
50
|
+
id: pluginId,
|
|
51
|
+
name: pluginName,
|
|
52
|
+
entry: entry.split(path.sep).join("/")
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
function formatScaffoldSuccess(targetDir) {
|
|
56
|
+
return [
|
|
57
|
+
`Created Mastra Code plugin scaffold at ${targetDir}`,
|
|
58
|
+
"",
|
|
59
|
+
"Next steps:",
|
|
60
|
+
` cd ${targetDir}`,
|
|
61
|
+
" pnpm install",
|
|
62
|
+
" pnpm check",
|
|
63
|
+
" mastracode",
|
|
64
|
+
" /plugins",
|
|
65
|
+
" Install new plugin → Local path"
|
|
66
|
+
].join("\n");
|
|
67
|
+
}
|
|
68
|
+
function isBarePluginName(target) {
|
|
69
|
+
return !path.isAbsolute(target) && !target.startsWith(".") && !target.includes("/") && !target.includes("\\");
|
|
70
|
+
}
|
|
71
|
+
function renderIndex(pluginId, pluginName) {
|
|
72
|
+
return `import { createTool, defineMastraCodePlugin, z } from 'mastracode/plugin';
|
|
73
|
+
|
|
74
|
+
export default defineMastraCodePlugin({
|
|
75
|
+
id: ${JSON.stringify(pluginId)},
|
|
76
|
+
name: ${JSON.stringify(pluginName)},
|
|
77
|
+
description: 'A Mastra Code tool plugin.',
|
|
78
|
+
tools: {
|
|
79
|
+
example_tool: {
|
|
80
|
+
tool: createTool({
|
|
81
|
+
id: 'example_tool',
|
|
82
|
+
description: 'Echo a message from the scaffolded plugin.',
|
|
83
|
+
inputSchema: z.object({
|
|
84
|
+
message: z.string(),
|
|
85
|
+
}),
|
|
86
|
+
execute: async context => {
|
|
87
|
+
return { message: context.message };
|
|
88
|
+
},
|
|
89
|
+
}),
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
`;
|
|
94
|
+
}
|
|
95
|
+
function renderReadme(pluginName, pluginId) {
|
|
96
|
+
return `# ${pluginName}
|
|
97
|
+
|
|
98
|
+
Mastra Code tool plugin: \`${pluginId}\`.
|
|
99
|
+
|
|
100
|
+
## Develop
|
|
101
|
+
|
|
102
|
+
\`\`\`sh
|
|
103
|
+
pnpm install
|
|
104
|
+
pnpm check
|
|
105
|
+
\`\`\`
|
|
106
|
+
|
|
107
|
+
## Install locally
|
|
108
|
+
|
|
109
|
+
Open Mastra Code, run \`/plugins\`, and install this directory as a local plugin.
|
|
110
|
+
`;
|
|
111
|
+
}
|
|
112
|
+
function humanizeName(value) {
|
|
113
|
+
return value.split(/[-_.]+/g).filter(Boolean).map((part) => part[0]?.toUpperCase() + part.slice(1)).join(" ") || "Mastra Code Plugin";
|
|
114
|
+
}
|
|
115
|
+
export { formatScaffoldSuccess, resolveScaffoldTarget, scaffoldPlugin };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { Agent } from '@mastra/core/agent';
|
|
2
|
+
import type { Mastra } from '@mastra/core/mastra';
|
|
3
|
+
import type { InputProcessorOrWorkflow, OutputProcessorOrWorkflow } from '@mastra/core/processors';
|
|
4
|
+
import type { SignalProvider } from '@mastra/core/signals';
|
|
5
|
+
import type { PluginContribution } from './types.js';
|
|
6
|
+
export type PluginSignalLaneOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* Ids of providers Mastra Code wires itself (through the Agent constructor).
|
|
9
|
+
* The lane refuses to start a provider that collides with one of them:
|
|
10
|
+
* two live instances of the same provider silently clobber each other's
|
|
11
|
+
* polling, and the built-ins are invisible to the lane's own registry.
|
|
12
|
+
*/
|
|
13
|
+
reservedProviderIds?: string[];
|
|
14
|
+
/** Called with the id of the plugin that owns the failing provider. */
|
|
15
|
+
onError?: (message: string, error: unknown, pluginId: string) => void;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Owns the lifecycle of signal providers contributed by plugins.
|
|
19
|
+
*
|
|
20
|
+
* Providers are long-lived; processors are per-request. The Agent constructor
|
|
21
|
+
* conflates the two — it harvests a provider's processors into a closure that
|
|
22
|
+
* can never be undone — so plugin providers are deliberately kept out of the
|
|
23
|
+
* `signals` array and driven from here instead, through the same public methods
|
|
24
|
+
* the constructor uses. That is what makes a provider removable when its plugin
|
|
25
|
+
* is disabled, updated or uninstalled.
|
|
26
|
+
*/
|
|
27
|
+
export declare class PluginSignalLane {
|
|
28
|
+
#private;
|
|
29
|
+
constructor(options?: PluginSignalLaneOptions);
|
|
30
|
+
getInputProcessors(): readonly InputProcessorOrWorkflow[];
|
|
31
|
+
getOutputProcessors(): readonly OutputProcessorOrWorkflow[];
|
|
32
|
+
/**
|
|
33
|
+
* Reconciles the live providers against a freshly loaded plugin list.
|
|
34
|
+
*
|
|
35
|
+
* A plugin whose stamp is unchanged keeps the provider instance it already
|
|
36
|
+
* has, and the freshly resolved one is dropped without ever being registered,
|
|
37
|
+
* connected or polled — reload re-runs every plugin's resolver, so unchanged
|
|
38
|
+
* plugins hand over new instances on every call.
|
|
39
|
+
*
|
|
40
|
+
* Providers of plugins that went inactive, failed to load or were uninstalled
|
|
41
|
+
* are absent from the contributions and get stopped here.
|
|
42
|
+
*/
|
|
43
|
+
sync(contributions: PluginContribution<SignalProvider<string>>[]): void;
|
|
44
|
+
/**
|
|
45
|
+
* Called once Mastra exists. Providers resolved before then are registered and
|
|
46
|
+
* started here — without a Mastra instance a provider has no storage, and
|
|
47
|
+
* nothing else will ever hand it one: the Agent propagates Mastra only to the
|
|
48
|
+
* providers in its own `signals` array, which these deliberately are not in.
|
|
49
|
+
*/
|
|
50
|
+
setMastra(mastra: Mastra, agent: Agent): void;
|
|
51
|
+
/**
|
|
52
|
+
* Retires every live provider and empties both processor lanes. The inverse of
|
|
53
|
+
* `sync()`, for a caller that is done with this lane — an embedder sharing one
|
|
54
|
+
* `PluginManager` across controllers would otherwise leave a controller's
|
|
55
|
+
* providers polling after it is gone.
|
|
56
|
+
*/
|
|
57
|
+
stopAll(): void;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=signal-lane.d.ts.map
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
// src/plugins/signal-lane.ts
|
|
2
|
+
/**
|
|
3
|
+
* Owns the lifecycle of signal providers contributed by plugins.
|
|
4
|
+
*
|
|
5
|
+
* Providers are long-lived; processors are per-request. The Agent constructor
|
|
6
|
+
* conflates the two — it harvests a provider's processors into a closure that
|
|
7
|
+
* can never be undone — so plugin providers are deliberately kept out of the
|
|
8
|
+
* `signals` array and driven from here instead, through the same public methods
|
|
9
|
+
* the constructor uses. That is what makes a provider removable when its plugin
|
|
10
|
+
* is disabled, updated or uninstalled.
|
|
11
|
+
*/
|
|
12
|
+
var PluginSignalLane = class {
|
|
13
|
+
#live = /* @__PURE__ */ new Map();
|
|
14
|
+
#reservedProviderIds;
|
|
15
|
+
#onError;
|
|
16
|
+
#agent;
|
|
17
|
+
#mastra;
|
|
18
|
+
#inputProcessors = [];
|
|
19
|
+
#outputProcessors = [];
|
|
20
|
+
constructor(options = {}) {
|
|
21
|
+
this.#reservedProviderIds = new Set(options.reservedProviderIds ?? []);
|
|
22
|
+
this.#onError = options.onError ?? ((message, error) => {
|
|
23
|
+
console.warn(message, error);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
getInputProcessors() {
|
|
27
|
+
return this.#inputProcessors;
|
|
28
|
+
}
|
|
29
|
+
getOutputProcessors() {
|
|
30
|
+
return this.#outputProcessors;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Reconciles the live providers against a freshly loaded plugin list.
|
|
34
|
+
*
|
|
35
|
+
* A plugin whose stamp is unchanged keeps the provider instance it already
|
|
36
|
+
* has, and the freshly resolved one is dropped without ever being registered,
|
|
37
|
+
* connected or polled — reload re-runs every plugin's resolver, so unchanged
|
|
38
|
+
* plugins hand over new instances on every call.
|
|
39
|
+
*
|
|
40
|
+
* Providers of plugins that went inactive, failed to load or were uninstalled
|
|
41
|
+
* are absent from the contributions and get stopped here.
|
|
42
|
+
*/
|
|
43
|
+
sync(contributions) {
|
|
44
|
+
const seen = /* @__PURE__ */ new Set();
|
|
45
|
+
for (const { pluginId, versionStamp, value: provider } of contributions) {
|
|
46
|
+
const key = `${pluginId}::${provider.id}`;
|
|
47
|
+
seen.add(key);
|
|
48
|
+
const live = this.#live.get(key);
|
|
49
|
+
if (live && live.versionStamp === versionStamp) continue;
|
|
50
|
+
if (live) this.#retire(key, live);
|
|
51
|
+
if (this.#isProviderIdTaken(provider.id)) {
|
|
52
|
+
this.#onError(`Plugin "${pluginId}" signal provider "${provider.id}" is already running; refusing to start a second instance.`, void 0, pluginId);
|
|
53
|
+
seen.delete(key);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
this.#live.set(key, {
|
|
57
|
+
pluginId,
|
|
58
|
+
provider,
|
|
59
|
+
versionStamp,
|
|
60
|
+
started: false
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
for (const [key, live] of this.#live) if (!seen.has(key)) this.#retire(key, live);
|
|
64
|
+
this.#startPending();
|
|
65
|
+
this.#rebuildProcessors();
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Called once Mastra exists. Providers resolved before then are registered and
|
|
69
|
+
* started here — without a Mastra instance a provider has no storage, and
|
|
70
|
+
* nothing else will ever hand it one: the Agent propagates Mastra only to the
|
|
71
|
+
* providers in its own `signals` array, which these deliberately are not in.
|
|
72
|
+
*/
|
|
73
|
+
setMastra(mastra, agent) {
|
|
74
|
+
this.#mastra = mastra;
|
|
75
|
+
this.#agent = agent;
|
|
76
|
+
this.#startPending();
|
|
77
|
+
this.#rebuildProcessors();
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Retires every live provider and empties both processor lanes. The inverse of
|
|
81
|
+
* `sync()`, for a caller that is done with this lane — an embedder sharing one
|
|
82
|
+
* `PluginManager` across controllers would otherwise leave a controller's
|
|
83
|
+
* providers polling after it is gone.
|
|
84
|
+
*/
|
|
85
|
+
stopAll() {
|
|
86
|
+
for (const [key, live] of this.#live) this.#retire(key, live);
|
|
87
|
+
this.#rebuildProcessors();
|
|
88
|
+
}
|
|
89
|
+
#startPending() {
|
|
90
|
+
const mastra = this.#mastra;
|
|
91
|
+
const agent = this.#agent;
|
|
92
|
+
if (!mastra || !agent) return;
|
|
93
|
+
for (const [key, live] of this.#live) {
|
|
94
|
+
if (live.started) continue;
|
|
95
|
+
try {
|
|
96
|
+
live.provider.__registerMastra(mastra);
|
|
97
|
+
live.provider.connect(agent);
|
|
98
|
+
live.provider.startPolling();
|
|
99
|
+
live.started = true;
|
|
100
|
+
this.#runStart(key, live);
|
|
101
|
+
} catch (error) {
|
|
102
|
+
this.#failProvider(key, live, error);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async #runStart(key, live) {
|
|
107
|
+
try {
|
|
108
|
+
await live.provider.start?.();
|
|
109
|
+
if (this.#live.get(key) !== live) this.#stopProvider(live);
|
|
110
|
+
} catch (error) {
|
|
111
|
+
if (this.#live.get(key) !== live) {
|
|
112
|
+
this.#stopProvider(live);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
this.#failProvider(key, live, error);
|
|
116
|
+
this.#rebuildProcessors();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Isolated: one failing provider does not take down its plugin's tools,
|
|
121
|
+
* commands, skills or sibling providers. A plugin author who wants a provider
|
|
122
|
+
* treated as required throws from the `signalProviders` resolver instead,
|
|
123
|
+
* which fails the whole plugin record.
|
|
124
|
+
*/
|
|
125
|
+
#failProvider(key, live, error) {
|
|
126
|
+
this.#onError(`Plugin "${live.pluginId}" signal provider "${live.provider.id}" failed to start:`, error, live.pluginId);
|
|
127
|
+
this.#retire(key, live);
|
|
128
|
+
}
|
|
129
|
+
#retire(key, live) {
|
|
130
|
+
this.#stopProvider(live);
|
|
131
|
+
this.#live.delete(key);
|
|
132
|
+
}
|
|
133
|
+
#stopProvider(live) {
|
|
134
|
+
try {
|
|
135
|
+
live.provider.stop();
|
|
136
|
+
} catch (error) {
|
|
137
|
+
this.#onError(`Plugin "${live.pluginId}" signal provider "${live.provider.id}" failed to stop:`, error, live.pluginId);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
#isProviderIdTaken(providerId) {
|
|
141
|
+
if (this.#reservedProviderIds.has(providerId)) return true;
|
|
142
|
+
for (const live of this.#live.values()) if (live.provider.id === providerId) return true;
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
#rebuildProcessors() {
|
|
146
|
+
const input = [];
|
|
147
|
+
const output = [];
|
|
148
|
+
for (const live of this.#live.values()) {
|
|
149
|
+
if (!live.started) continue;
|
|
150
|
+
try {
|
|
151
|
+
const providerInput = live.provider.getInputProcessors?.() ?? [];
|
|
152
|
+
const providerOutput = live.provider.getOutputProcessors?.() ?? [];
|
|
153
|
+
input.push(...providerInput);
|
|
154
|
+
output.push(...providerOutput);
|
|
155
|
+
} catch (error) {
|
|
156
|
+
this.#onError(`Plugin "${live.pluginId}" signal provider "${live.provider.id}" failed to provide processors:`, error, live.pluginId);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
this.#inputProcessors = input;
|
|
160
|
+
this.#outputProcessors = output;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
export { PluginSignalLane };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { InputProcessor, OutputProcessor } from '@mastra/core/processors';
|
|
2
|
+
import type { SignalProvider } from '@mastra/core/signals';
|
|
3
|
+
import type { MastraCodePluginConfigSchema, MastraCodePluginConfigValue, MastraCodePluginTools, MastraCodeToolRenderConfig } from '../plugin.js';
|
|
4
|
+
/** Processors a plugin contributed, normalized into the lane they belong to. */
|
|
5
|
+
export type LoadedPluginProcessors = {
|
|
6
|
+
input: InputProcessor[];
|
|
7
|
+
output: OutputProcessor[];
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* A single contribution, carrying the id of the plugin that owns it. Ownership
|
|
11
|
+
* has to survive collection: the signal lane keys live providers by
|
|
12
|
+
* `(pluginId, providerId)`, and a processor's state id is derived from the
|
|
13
|
+
* plugin id so it stays stable when the plugin is reloaded.
|
|
14
|
+
*/
|
|
15
|
+
export type PluginContribution<TValue> = {
|
|
16
|
+
pluginId: string;
|
|
17
|
+
/** The owning plugin's {@link LoadedPlugin.versionStamp} at collection time. */
|
|
18
|
+
versionStamp: string;
|
|
19
|
+
value: TValue;
|
|
20
|
+
};
|
|
21
|
+
export type PluginProcessorEntries = {
|
|
22
|
+
input: PluginContribution<InputProcessor>[];
|
|
23
|
+
output: PluginContribution<OutputProcessor>[];
|
|
24
|
+
};
|
|
25
|
+
export type PluginScope = 'global' | 'project';
|
|
26
|
+
export type PluginSource = 'local' | 'github';
|
|
27
|
+
export type PluginStatus = 'active' | 'inactive' | 'blocked' | 'load failed' | 'conflicted';
|
|
28
|
+
export type InstalledPluginRecord = {
|
|
29
|
+
enabled: boolean;
|
|
30
|
+
source: PluginSource;
|
|
31
|
+
specifier: string;
|
|
32
|
+
path: string;
|
|
33
|
+
entry: string;
|
|
34
|
+
ref?: string;
|
|
35
|
+
version?: string;
|
|
36
|
+
config?: Record<string, MastraCodePluginConfigValue>;
|
|
37
|
+
};
|
|
38
|
+
export type PluginRegistry = {
|
|
39
|
+
plugins: Record<string, InstalledPluginRecord>;
|
|
40
|
+
disabledPlugins?: string[];
|
|
41
|
+
};
|
|
42
|
+
export type ScopedInstalledPluginRecord = InstalledPluginRecord & {
|
|
43
|
+
id: string;
|
|
44
|
+
scope: PluginScope;
|
|
45
|
+
blocked?: boolean;
|
|
46
|
+
};
|
|
47
|
+
export type LoadedPlugin = ScopedInstalledPluginRecord & {
|
|
48
|
+
name?: string;
|
|
49
|
+
description?: string;
|
|
50
|
+
instructions?: string;
|
|
51
|
+
status: PluginStatus;
|
|
52
|
+
error?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Set when the latest reload of this plugin failed while an earlier load of it
|
|
55
|
+
* was active. The record is then that earlier load, kept whole (tools,
|
|
56
|
+
* providers, stamp), and this holds the error the reload hit.
|
|
57
|
+
*/
|
|
58
|
+
reloadError?: string;
|
|
59
|
+
tools: MastraCodePluginTools;
|
|
60
|
+
renderConfigs?: Record<string, MastraCodeToolRenderConfig>;
|
|
61
|
+
toolNames: string[];
|
|
62
|
+
processors?: LoadedPluginProcessors;
|
|
63
|
+
signalProviders?: SignalProvider<string>[];
|
|
64
|
+
skillPaths?: string[];
|
|
65
|
+
commandPaths?: string[];
|
|
66
|
+
configSchema?: MastraCodePluginConfigSchema;
|
|
67
|
+
configValues?: Record<string, MastraCodePluginConfigValue>;
|
|
68
|
+
conflicts?: string[];
|
|
69
|
+
/**
|
|
70
|
+
* Changes when this plugin's contributions should be rebuilt: source content
|
|
71
|
+
* (git HEAD for GitHub checkouts, entry file version for local plugins) plus
|
|
72
|
+
* the registry record's config values and enabled flag. Reload fires on
|
|
73
|
+
* non-content events too — a config edit hands the plugin different values
|
|
74
|
+
* while every file is untouched — so both halves matter.
|
|
75
|
+
*
|
|
76
|
+
* Consumers that own long-lived instances (the signal-provider lane) compare
|
|
77
|
+
* this to decide between keeping what they have and cycling it.
|
|
78
|
+
*/
|
|
79
|
+
versionStamp?: string;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* A plugin problem the user should see: a reload that failed while the previous
|
|
83
|
+
* load kept running, or a signal provider that failed at runtime.
|
|
84
|
+
*/
|
|
85
|
+
export type PluginErrorEvent = {
|
|
86
|
+
pluginId: string;
|
|
87
|
+
message: string;
|
|
88
|
+
};
|
|
89
|
+
export type PluginScopePaths = {
|
|
90
|
+
scope: PluginScope;
|
|
91
|
+
root: string;
|
|
92
|
+
registryPath: string;
|
|
93
|
+
sourcesPath: string;
|
|
94
|
+
};
|
|
95
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|