@mastra/code-sdk 0.0.0-esbuild-bundle-worker-20260807173433
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1349 -0
- package/LICENSE.md +30 -0
- package/README.md +70 -0
- package/dist/acp/agent.d.ts +35 -0
- package/dist/acp/agent.d.ts.map +1 -0
- package/dist/acp/agent.js +161 -0
- package/dist/acp/agent.js.map +1 -0
- package/dist/acp/event-mapper.d.ts +22 -0
- package/dist/acp/event-mapper.d.ts.map +1 -0
- package/dist/acp/event-mapper.js +214 -0
- package/dist/acp/event-mapper.js.map +1 -0
- package/dist/acp/index.d.ts +8 -0
- package/dist/acp/index.d.ts.map +1 -0
- package/dist/acp/index.js +65 -0
- package/dist/acp/index.js.map +1 -0
- package/dist/acp/server.d.ts +7 -0
- package/dist/acp/server.d.ts.map +1 -0
- package/dist/acp/server.js +35 -0
- package/dist/acp/server.js.map +1 -0
- package/dist/acp.d.ts +2 -0
- package/dist/acp.d.ts.map +1 -0
- package/dist/acp.js +2 -0
- package/dist/agents/credential-resolver.d.ts +51 -0
- package/dist/agents/credential-resolver.d.ts.map +1 -0
- package/dist/agents/credential-resolver.js +52 -0
- package/dist/agents/credential-resolver.js.map +1 -0
- package/dist/agents/custom-provider-source.d.ts +35 -0
- package/dist/agents/custom-provider-source.d.ts.map +1 -0
- package/dist/agents/custom-provider-source.js +25 -0
- package/dist/agents/custom-provider-source.js.map +1 -0
- package/dist/agents/instructions.d.ts +6 -0
- package/dist/agents/instructions.d.ts.map +1 -0
- package/dist/agents/instructions.js +32 -0
- package/dist/agents/instructions.js.map +1 -0
- package/dist/agents/mastracode-gateway.d.ts +74 -0
- package/dist/agents/mastracode-gateway.d.ts.map +1 -0
- package/dist/agents/mastracode-gateway.js +400 -0
- package/dist/agents/mastracode-gateway.js.map +1 -0
- package/dist/agents/memory.d.ts +13 -0
- package/dist/agents/memory.d.ts.map +1 -0
- package/dist/agents/memory.js +116 -0
- package/dist/agents/memory.js.map +1 -0
- package/dist/agents/model.d.ts +59 -0
- package/dist/agents/model.d.ts.map +1 -0
- package/dist/agents/model.js +132 -0
- package/dist/agents/model.js.map +1 -0
- package/dist/agents/modes/build.d.ts +10 -0
- package/dist/agents/modes/build.d.ts.map +1 -0
- package/dist/agents/modes/build.js +44 -0
- package/dist/agents/modes/build.js.map +1 -0
- package/dist/agents/modes/explore.d.ts +10 -0
- package/dist/agents/modes/explore.d.ts.map +1 -0
- package/dist/agents/modes/explore.js +39 -0
- package/dist/agents/modes/explore.js.map +1 -0
- package/dist/agents/modes/plan.d.ts +6 -0
- package/dist/agents/modes/plan.d.ts.map +1 -0
- package/dist/agents/modes/plan.js +37 -0
- package/dist/agents/modes/plan.js.map +1 -0
- package/dist/agents/prompts/agent-instructions.d.ts +61 -0
- package/dist/agents/prompts/agent-instructions.d.ts.map +1 -0
- package/dist/agents/prompts/agent-instructions.js +201 -0
- package/dist/agents/prompts/agent-instructions.js.map +1 -0
- package/dist/agents/prompts/build.d.ts +12 -0
- package/dist/agents/prompts/build.d.ts.map +1 -0
- package/dist/agents/prompts/build.js +76 -0
- package/dist/agents/prompts/build.js.map +1 -0
- package/dist/agents/prompts/fast.d.ts +5 -0
- package/dist/agents/prompts/fast.d.ts.map +1 -0
- package/dist/agents/prompts/fast.js +26 -0
- package/dist/agents/prompts/fast.js.map +1 -0
- package/dist/agents/prompts/index.d.ts +19 -0
- package/dist/agents/prompts/index.d.ts.map +1 -0
- package/dist/agents/prompts/index.js +65 -0
- package/dist/agents/prompts/index.js.map +1 -0
- package/dist/agents/prompts/model.d.ts +5 -0
- package/dist/agents/prompts/model.d.ts.map +1 -0
- package/dist/agents/prompts/model.js +23 -0
- package/dist/agents/prompts/model.js.map +1 -0
- package/dist/agents/prompts/plan.d.ts +6 -0
- package/dist/agents/prompts/plan.d.ts.map +1 -0
- package/dist/agents/prompts/plan.js +111 -0
- package/dist/agents/prompts/plan.js.map +1 -0
- package/dist/agents/prompts/tool-guidance.d.ts +13 -0
- package/dist/agents/prompts/tool-guidance.d.ts.map +1 -0
- package/dist/agents/prompts/tool-guidance.js +149 -0
- package/dist/agents/prompts/tool-guidance.js.map +1 -0
- package/dist/agents/sandbox-filesystem.d.ts +99 -0
- package/dist/agents/sandbox-filesystem.d.ts.map +1 -0
- package/dist/agents/sandbox-filesystem.js +328 -0
- package/dist/agents/sandbox-filesystem.js.map +1 -0
- package/dist/agents/sandbox-reattach.d.ts +19 -0
- package/dist/agents/sandbox-reattach.d.ts.map +1 -0
- package/dist/agents/sandbox-reattach.js +15 -0
- package/dist/agents/sandbox-reattach.js.map +1 -0
- package/dist/agents/thread-caveman-state.d.ts +17 -0
- package/dist/agents/thread-caveman-state.d.ts.map +1 -0
- package/dist/agents/thread-caveman-state.js +107 -0
- package/dist/agents/thread-caveman-state.js.map +1 -0
- package/dist/agents/tool-availability.d.ts +10 -0
- package/dist/agents/tool-availability.d.ts.map +1 -0
- package/dist/agents/tool-availability.js +87 -0
- package/dist/agents/tool-availability.js.map +1 -0
- package/dist/agents/tools.d.ts +19 -0
- package/dist/agents/tools.d.ts.map +1 -0
- package/dist/agents/tools.js +105 -0
- package/dist/agents/tools.js.map +1 -0
- package/dist/agents/workspace.d.ts +32 -0
- package/dist/agents/workspace.d.ts.map +1 -0
- package/dist/agents/workspace.js +251 -0
- package/dist/agents/workspace.js.map +1 -0
- package/dist/analytics.d.ts +18 -0
- package/dist/analytics.d.ts.map +1 -0
- package/dist/analytics.js +163 -0
- package/dist/analytics.js.map +1 -0
- package/dist/auth/authorization-input.d.ts +16 -0
- package/dist/auth/authorization-input.d.ts.map +1 -0
- package/dist/auth/authorization-input.js +42 -0
- package/dist/auth/authorization-input.js.map +1 -0
- package/dist/auth/device-code.d.ts +93 -0
- package/dist/auth/device-code.d.ts.map +1 -0
- package/dist/auth/device-code.js +129 -0
- package/dist/auth/device-code.js.map +1 -0
- package/dist/auth/index.d.ts +10 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +6 -0
- package/dist/auth/pkce.d.ts +13 -0
- package/dist/auth/pkce.d.ts.map +1 -0
- package/dist/auth/pkce.js +32 -0
- package/dist/auth/pkce.js.map +1 -0
- package/dist/auth/providers/anthropic.d.ts +40 -0
- package/dist/auth/providers/anthropic.d.ts.map +1 -0
- package/dist/auth/providers/anthropic.js +126 -0
- package/dist/auth/providers/anthropic.js.map +1 -0
- package/dist/auth/providers/github-copilot.d.ts +154 -0
- package/dist/auth/providers/github-copilot.d.ts.map +1 -0
- package/dist/auth/providers/github-copilot.js +340 -0
- package/dist/auth/providers/github-copilot.js.map +1 -0
- package/dist/auth/providers/openai-codex.d.ts +139 -0
- package/dist/auth/providers/openai-codex.d.ts.map +1 -0
- package/dist/auth/providers/openai-codex.js +519 -0
- package/dist/auth/providers/openai-codex.js.map +1 -0
- package/dist/auth/providers/xai.d.ts +64 -0
- package/dist/auth/providers/xai.d.ts.map +1 -0
- package/dist/auth/providers/xai.js +205 -0
- package/dist/auth/providers/xai.js.map +1 -0
- package/dist/auth/storage.d.ts +91 -0
- package/dist/auth/storage.d.ts.map +1 -0
- package/dist/auth/storage.js +197 -0
- package/dist/auth/storage.js.map +1 -0
- package/dist/auth/types.d.ts +89 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +1 -0
- package/dist/clipboard/index.d.ts +26 -0
- package/dist/clipboard/index.d.ts.map +1 -0
- package/dist/clipboard/index.js +226 -0
- package/dist/clipboard/index.js.map +1 -0
- package/dist/constants.d.ts +10 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +18 -0
- package/dist/constants.js.map +1 -0
- package/dist/error-classification.d.ts +10 -0
- package/dist/error-classification.d.ts.map +1 -0
- package/dist/error-classification.js +22 -0
- package/dist/error-classification.js.map +1 -0
- package/dist/evals/context-builder.d.ts +41 -0
- package/dist/evals/context-builder.d.ts.map +1 -0
- package/dist/evals/context-builder.js +161 -0
- package/dist/evals/context-builder.js.map +1 -0
- package/dist/evals/index.d.ts +4 -0
- package/dist/evals/index.d.ts.map +1 -0
- package/dist/evals/index.js +5 -0
- package/dist/evals/scorers/classify-command.d.ts +31 -0
- package/dist/evals/scorers/classify-command.d.ts.map +1 -0
- package/dist/evals/scorers/classify-command.js +73 -0
- package/dist/evals/scorers/classify-command.js.map +1 -0
- package/dist/evals/scorers/efficiency.d.ts +44 -0
- package/dist/evals/scorers/efficiency.d.ts.map +1 -0
- package/dist/evals/scorers/efficiency.js +259 -0
- package/dist/evals/scorers/efficiency.js.map +1 -0
- package/dist/evals/scorers/extract-tools.d.ts +25 -0
- package/dist/evals/scorers/extract-tools.d.ts.map +1 -0
- package/dist/evals/scorers/extract-tools.js +60 -0
- package/dist/evals/scorers/extract-tools.js.map +1 -0
- package/dist/evals/scorers/index.d.ts +3 -0
- package/dist/evals/scorers/index.d.ts.map +1 -0
- package/dist/evals/scorers/index.js +3 -0
- package/dist/evals/scorers/outcome.d.ts +49 -0
- package/dist/evals/scorers/outcome.d.ts.map +1 -0
- package/dist/evals/scorers/outcome.js +347 -0
- package/dist/evals/scorers/outcome.js.map +1 -0
- package/dist/goal-manager.d.ts +78 -0
- package/dist/goal-manager.d.ts.map +1 -0
- package/dist/goal-manager.js +273 -0
- package/dist/goal-manager.js.map +1 -0
- package/dist/goal-signal.d.ts +14 -0
- package/dist/goal-signal.d.ts.map +1 -0
- package/dist/goal-signal.js +17 -0
- package/dist/goal-signal.js.map +1 -0
- package/dist/headless/cli.d.ts +42 -0
- package/dist/headless/cli.d.ts.map +1 -0
- package/dist/headless/cli.js +195 -0
- package/dist/headless/cli.js.map +1 -0
- package/dist/headless/flags.d.ts +33 -0
- package/dist/headless/flags.d.ts.map +1 -0
- package/dist/headless/flags.js +190 -0
- package/dist/headless/flags.js.map +1 -0
- package/dist/headless/format.d.ts +38 -0
- package/dist/headless/format.d.ts.map +1 -0
- package/dist/headless/format.js +89 -0
- package/dist/headless/format.js.map +1 -0
- package/dist/headless/index.d.ts +25 -0
- package/dist/headless/index.d.ts.map +1 -0
- package/dist/headless/index.js +6 -0
- package/dist/headless/policy.d.ts +17 -0
- package/dist/headless/policy.d.ts.map +1 -0
- package/dist/headless/policy.js +42 -0
- package/dist/headless/policy.js.map +1 -0
- package/dist/headless/run-mc.d.ts +7 -0
- package/dist/headless/run-mc.d.ts.map +1 -0
- package/dist/headless/run-mc.js +346 -0
- package/dist/headless/run-mc.js.map +1 -0
- package/dist/headless/types.d.ts +158 -0
- package/dist/headless/types.d.ts.map +1 -0
- package/dist/headless/types.js +18 -0
- package/dist/headless/types.js.map +1 -0
- package/dist/hooks/config.d.ts +11 -0
- package/dist/hooks/config.d.ts.map +1 -0
- package/dist/hooks/config.js +73 -0
- package/dist/hooks/config.js.map +1 -0
- package/dist/hooks/executor.d.ts +13 -0
- package/dist/hooks/executor.d.ts.map +1 -0
- package/dist/hooks/executor.js +128 -0
- package/dist/hooks/executor.js.map +1 -0
- package/dist/hooks/index.d.ts +6 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +5 -0
- package/dist/hooks/manager.d.ts +47 -0
- package/dist/hooks/manager.d.ts.map +1 -0
- package/dist/hooks/manager.js +225 -0
- package/dist/hooks/manager.js.map +1 -0
- package/dist/hooks/types.d.ts +152 -0
- package/dist/hooks/types.d.ts.map +1 -0
- package/dist/hooks/types.js +8 -0
- package/dist/hooks/types.js.map +1 -0
- package/dist/index.d.ts +258 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +740 -0
- package/dist/index.js.map +1 -0
- package/dist/ipc/ipc-reporter.d.ts +14 -0
- package/dist/ipc/ipc-reporter.d.ts.map +1 -0
- package/dist/ipc/ipc-reporter.js +21 -0
- package/dist/ipc/ipc-reporter.js.map +1 -0
- package/dist/lsp/client.d.ts +56 -0
- package/dist/lsp/client.d.ts.map +1 -0
- package/dist/lsp/client.js +251 -0
- package/dist/lsp/client.js.map +1 -0
- package/dist/lsp/index.d.ts +4 -0
- package/dist/lsp/index.d.ts.map +1 -0
- package/dist/lsp/index.js +4 -0
- package/dist/lsp/language.d.ts +9 -0
- package/dist/lsp/language.d.ts.map +1 -0
- package/dist/lsp/language.js +44 -0
- package/dist/lsp/language.js.map +1 -0
- package/dist/lsp/manager.d.ts +34 -0
- package/dist/lsp/manager.d.ts.map +1 -0
- package/dist/lsp/manager.js +82 -0
- package/dist/lsp/manager.js.map +1 -0
- package/dist/lsp/server.d.ts +27 -0
- package/dist/lsp/server.d.ts.map +1 -0
- package/dist/lsp/server.js +159 -0
- package/dist/lsp/server.js.map +1 -0
- package/dist/lsp/workspace.d.ts +9 -0
- package/dist/lsp/workspace.d.ts.map +1 -0
- package/dist/lsp/workspace.js +55 -0
- package/dist/lsp/workspace.js.map +1 -0
- package/dist/mcp/config.d.ts +54 -0
- package/dist/mcp/config.d.ts.map +1 -0
- package/dist/mcp/config.js +240 -0
- package/dist/mcp/config.js.map +1 -0
- package/dist/mcp/index.d.ts +5 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +3 -0
- package/dist/mcp/manager.d.ts +98 -0
- package/dist/mcp/manager.d.ts.map +1 -0
- package/dist/mcp/manager.js +612 -0
- package/dist/mcp/manager.js.map +1 -0
- package/dist/mcp/state.d.ts +33 -0
- package/dist/mcp/state.d.ts.map +1 -0
- package/dist/mcp/state.js +88 -0
- package/dist/mcp/state.js.map +1 -0
- package/dist/mcp/types.d.ts +120 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/mcp/types.js +1 -0
- package/dist/onboarding/custom-packs.d.ts +7 -0
- package/dist/onboarding/custom-packs.d.ts.map +1 -0
- package/dist/onboarding/custom-packs.js +17 -0
- package/dist/onboarding/custom-packs.js.map +1 -0
- package/dist/onboarding/custom-providers.d.ts +4 -0
- package/dist/onboarding/custom-providers.d.ts.map +1 -0
- package/dist/onboarding/custom-providers.js +30 -0
- package/dist/onboarding/custom-providers.js.map +1 -0
- package/dist/onboarding/index.d.ts +5 -0
- package/dist/onboarding/index.d.ts.map +1 -0
- package/dist/onboarding/index.js +3 -0
- package/dist/onboarding/om-settings.d.ts +25 -0
- package/dist/onboarding/om-settings.d.ts.map +1 -0
- package/dist/onboarding/om-settings.js +47 -0
- package/dist/onboarding/om-settings.js.map +1 -0
- package/dist/onboarding/packs.d.ts +46 -0
- package/dist/onboarding/packs.d.ts.map +1 -0
- package/dist/onboarding/packs.js +160 -0
- package/dist/onboarding/packs.js.map +1 -0
- package/dist/onboarding/settings.d.ts +338 -0
- package/dist/onboarding/settings.d.ts.map +1 -0
- package/dist/onboarding/settings.js +673 -0
- package/dist/onboarding/settings.js.map +1 -0
- package/dist/permissions.d.ts +55 -0
- package/dist/permissions.d.ts.map +1 -0
- package/dist/permissions.js +132 -0
- package/dist/permissions.js.map +1 -0
- package/dist/plugin.d.ts +81 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +28 -0
- package/dist/plugin.js.map +1 -0
- package/dist/plugins/dependencies.d.ts +9 -0
- package/dist/plugins/dependencies.d.ts.map +1 -0
- package/dist/plugins/dependencies.js +88 -0
- package/dist/plugins/dependencies.js.map +1 -0
- package/dist/plugins/install.d.ts +21 -0
- package/dist/plugins/install.d.ts.map +1 -0
- package/dist/plugins/install.js +190 -0
- package/dist/plugins/install.js.map +1 -0
- package/dist/plugins/loader.d.ts +15 -0
- package/dist/plugins/loader.d.ts.map +1 -0
- package/dist/plugins/loader.js +206 -0
- package/dist/plugins/loader.js.map +1 -0
- package/dist/plugins/manager.d.ts +64 -0
- package/dist/plugins/manager.d.ts.map +1 -0
- package/dist/plugins/manager.js +384 -0
- package/dist/plugins/manager.js.map +1 -0
- package/dist/plugins/manifest.d.ts +14 -0
- package/dist/plugins/manifest.d.ts.map +1 -0
- package/dist/plugins/manifest.js +50 -0
- package/dist/plugins/manifest.js.map +1 -0
- package/dist/plugins/package-link.d.ts +3 -0
- package/dist/plugins/package-link.d.ts.map +1 -0
- package/dist/plugins/package-link.js +61 -0
- package/dist/plugins/package-link.js.map +1 -0
- package/dist/plugins/paths.d.ts +10 -0
- package/dist/plugins/paths.d.ts.map +1 -0
- package/dist/plugins/paths.js +25 -0
- package/dist/plugins/paths.js.map +1 -0
- package/dist/plugins/registry.d.ts +8 -0
- package/dist/plugins/registry.d.ts.map +1 -0
- package/dist/plugins/registry.js +112 -0
- package/dist/plugins/registry.js.map +1 -0
- package/dist/plugins/scaffold.d.ts +10 -0
- package/dist/plugins/scaffold.d.ts.map +1 -0
- package/dist/plugins/scaffold.js +116 -0
- package/dist/plugins/scaffold.js.map +1 -0
- package/dist/plugins/types.d.ts +45 -0
- package/dist/plugins/types.d.ts.map +1 -0
- package/dist/plugins/types.js +1 -0
- package/dist/processors/plan-rejection-abort.d.ts +12 -0
- package/dist/processors/plan-rejection-abort.d.ts.map +1 -0
- package/dist/processors/plan-rejection-abort.js +54 -0
- package/dist/processors/plan-rejection-abort.js.map +1 -0
- package/dist/providers/amazon-bedrock-gateway.d.ts +47 -0
- package/dist/providers/amazon-bedrock-gateway.d.ts.map +1 -0
- package/dist/providers/amazon-bedrock-gateway.js +152 -0
- package/dist/providers/amazon-bedrock-gateway.js.map +1 -0
- package/dist/providers/amazon-bedrock.d.ts +28 -0
- package/dist/providers/amazon-bedrock.d.ts.map +1 -0
- package/dist/providers/amazon-bedrock.js +83 -0
- package/dist/providers/amazon-bedrock.js.map +1 -0
- package/dist/providers/claude-max.d.ts +52 -0
- package/dist/providers/claude-max.d.ts.map +1 -0
- package/dist/providers/claude-max.js +171 -0
- package/dist/providers/claude-max.js.map +1 -0
- package/dist/providers/github-copilot.d.ts +60 -0
- package/dist/providers/github-copilot.d.ts.map +1 -0
- package/dist/providers/github-copilot.js +265 -0
- package/dist/providers/github-copilot.js.map +1 -0
- package/dist/providers/openai-codex.d.ts +72 -0
- package/dist/providers/openai-codex.d.ts.map +1 -0
- package/dist/providers/openai-codex.js +302 -0
- package/dist/providers/openai-codex.js.map +1 -0
- package/dist/providers/xai.d.ts +33 -0
- package/dist/providers/xai.d.ts.map +1 -0
- package/dist/providers/xai.js +70 -0
- package/dist/providers/xai.js.map +1 -0
- package/dist/schema.d.ts +192 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +98 -0
- package/dist/schema.js.map +1 -0
- package/dist/theme-palette.d.ts +17 -0
- package/dist/theme-palette.d.ts.map +1 -0
- package/dist/theme-palette.js +21 -0
- package/dist/theme-palette.js.map +1 -0
- package/dist/tool-names.d.ts +73 -0
- package/dist/tool-names.d.ts.map +1 -0
- package/dist/tool-names.js +52 -0
- package/dist/tool-names.js.map +1 -0
- package/dist/tools/index.d.ts +6 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +3 -0
- package/dist/tools/request-sandbox-access.d.ts +6 -0
- package/dist/tools/request-sandbox-access.d.ts.map +1 -0
- package/dist/tools/request-sandbox-access.js +79 -0
- package/dist/tools/request-sandbox-access.js.map +1 -0
- package/dist/tools/utils.d.ts +20 -0
- package/dist/tools/utils.d.ts.map +1 -0
- package/dist/tools/utils.js +32 -0
- package/dist/tools/utils.js.map +1 -0
- package/dist/tools/web-search.d.ts +35 -0
- package/dist/tools/web-search.d.ts.map +1 -0
- package/dist/tools/web-search.js +61 -0
- package/dist/tools/web-search.js.map +1 -0
- package/dist/utils/binaries.d.ts +7 -0
- package/dist/utils/binaries.d.ts.map +1 -0
- package/dist/utils/binaries.js +78 -0
- package/dist/utils/binaries.js.map +1 -0
- package/dist/utils/debug-log.d.ts +12 -0
- package/dist/utils/debug-log.d.ts.map +1 -0
- package/dist/utils/debug-log.js +59 -0
- package/dist/utils/debug-log.js.map +1 -0
- package/dist/utils/errors.d.ts +36 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +172 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/gateway-sync.d.ts +26 -0
- package/dist/utils/gateway-sync.d.ts.map +1 -0
- package/dist/utils/gateway-sync.js +61 -0
- package/dist/utils/gateway-sync.js.map +1 -0
- package/dist/utils/path-security.d.ts +2 -0
- package/dist/utils/path-security.d.ts.map +1 -0
- package/dist/utils/path-security.js +10 -0
- package/dist/utils/path-security.js.map +1 -0
- package/dist/utils/plan-diff.d.ts +25 -0
- package/dist/utils/plan-diff.d.ts.map +1 -0
- package/dist/utils/plan-diff.js +62 -0
- package/dist/utils/plan-diff.js.map +1 -0
- package/dist/utils/plans.d.ts +56 -0
- package/dist/utils/plans.d.ts.map +1 -0
- package/dist/utils/plans.js +117 -0
- package/dist/utils/plans.js.map +1 -0
- package/dist/utils/project.d.ts +160 -0
- package/dist/utils/project.d.ts.map +1 -0
- package/dist/utils/project.js +364 -0
- package/dist/utils/project.js.map +1 -0
- package/dist/utils/signals-pubsub.d.ts +41 -0
- package/dist/utils/signals-pubsub.d.ts.map +1 -0
- package/dist/utils/signals-pubsub.js +122 -0
- package/dist/utils/signals-pubsub.js.map +1 -0
- package/dist/utils/slash-command-loader.d.ts +52 -0
- package/dist/utils/slash-command-loader.d.ts.map +1 -0
- package/dist/utils/slash-command-loader.js +141 -0
- package/dist/utils/slash-command-loader.js.map +1 -0
- package/dist/utils/slash-command-processor.d.ts +14 -0
- package/dist/utils/slash-command-processor.d.ts.map +1 -0
- package/dist/utils/slash-command-processor.js +105 -0
- package/dist/utils/slash-command-processor.js.map +1 -0
- package/dist/utils/stdin-pipe.d.ts +33 -0
- package/dist/utils/stdin-pipe.d.ts.map +1 -0
- package/dist/utils/stdin-pipe.js +96 -0
- package/dist/utils/stdin-pipe.js.map +1 -0
- package/dist/utils/storage-factory.d.ts +50 -0
- package/dist/utils/storage-factory.d.ts.map +1 -0
- package/dist/utils/storage-factory.js +121 -0
- package/dist/utils/storage-factory.js.map +1 -0
- package/dist/utils/storage-maintenance.d.ts +103 -0
- package/dist/utils/storage-maintenance.d.ts.map +1 -0
- package/dist/utils/storage-maintenance.js +274 -0
- package/dist/utils/storage-maintenance.js.map +1 -0
- package/dist/utils/thread-lock.d.ts +26 -0
- package/dist/utils/thread-lock.d.ts.map +1 -0
- package/dist/utils/thread-lock.js +112 -0
- package/dist/utils/thread-lock.js.map +1 -0
- package/dist/utils/token-estimator.d.ts +3 -0
- package/dist/utils/token-estimator.d.ts.map +1 -0
- package/dist/utils/token-estimator.js +21 -0
- package/dist/utils/token-estimator.js.map +1 -0
- package/dist/utils/update-check.d.ts +101 -0
- package/dist/utils/update-check.d.ts.map +1 -0
- package/dist/utils/update-check.js +383 -0
- package/dist/utils/update-check.js.map +1 -0
- package/dist/voice/stt-registry.d.ts +64 -0
- package/dist/voice/stt-registry.d.ts.map +1 -0
- package/dist/voice/stt-registry.js +144 -0
- package/dist/voice/stt-registry.js.map +1 -0
- package/package.json +96 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.js","names":[],"sources":["../../src/plugins/paths.ts"],"sourcesContent":["import os from 'node:os';\nimport path from 'node:path';\n\nimport { DEFAULT_CONFIG_DIR } from '../constants.js';\nimport type { PluginScope, PluginScopePaths } from './types.js';\n\nexport type PluginPathOptions = {\n projectRoot: string;\n configDir?: string;\n homeDir?: string;\n};\n\nexport function getPluginRoot(scope: PluginScope, options: PluginPathOptions): string {\n const configDir = options.configDir ?? DEFAULT_CONFIG_DIR;\n const baseDir = scope === 'project' ? options.projectRoot : (options.homeDir ?? os.homedir());\n return path.join(baseDir, configDir, 'plugins');\n}\n\nexport function getPluginRegistryPath(scope: PluginScope, options: PluginPathOptions): string {\n return path.join(getPluginRoot(scope, options), 'plugins.json');\n}\n\nexport function getPluginScopePaths(scope: PluginScope, options: PluginPathOptions): PluginScopePaths {\n const root = getPluginRoot(scope, options);\n return {\n scope,\n root,\n registryPath: path.join(root, 'plugins.json'),\n sourcesPath: path.join(root, 'sources'),\n };\n}\n"],"mappings":";;;;AAYA,SAAgB,cAAc,OAAoB,SAAoC;CACpF,MAAM,YAAY,QAAQ,aAAA;CAC1B,MAAM,UAAU,UAAU,YAAY,QAAQ,cAAe,QAAQ,WAAW,GAAG,QAAQ;CAC3F,OAAO,KAAK,KAAK,SAAS,WAAW,SAAS;AAChD;AAEA,SAAgB,sBAAsB,OAAoB,SAAoC;CAC5F,OAAO,KAAK,KAAK,cAAc,OAAO,OAAO,GAAG,cAAc;AAChE;AAEA,SAAgB,oBAAoB,OAAoB,SAA8C;CACpG,MAAM,OAAO,cAAc,OAAO,OAAO;CACzC,OAAO;EACL;EACA;EACA,cAAc,KAAK,KAAK,MAAM,cAAc;EAC5C,aAAa,KAAK,KAAK,MAAM,SAAS;CACxC;AACF"}
|
|
@@ -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 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/plugins/registry.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,cAAc,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAC;AAErG,eAAO,MAAM,qBAAqB,EAAE,cAAqD,CAAC;AAE1F,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,MAAM,GAAG,cAAc,CAQvE;AAED,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,GAAG,IAAI,CAGvF;AAED,wBAAgB,qBAAqB,CACnC,cAAc,EAAE,cAAc,EAC9B,eAAe,EAAE,cAAc,GAC9B,2BAA2B,EAAE,CAqB/B;AAED,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,cAAc,EACxB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,qBAAqB,GAC5B,cAAc,CAQhB;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,GAAG,cAAc,CAI7F"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
//#region 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
|
+
//#endregion
|
|
110
|
+
export { EMPTY_PLUGIN_REGISTRY, loadPluginRegistry, mergePluginRegistries, removePluginRecord, savePluginRegistry, setPluginRecord };
|
|
111
|
+
|
|
112
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","names":[],"sources":["../../src/plugins/registry.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nimport type { InstalledPluginRecord, PluginRegistry, ScopedInstalledPluginRecord } from './types.js';\n\nexport const EMPTY_PLUGIN_REGISTRY: PluginRegistry = { plugins: {}, disabledPlugins: [] };\n\nexport function loadPluginRegistry(registryPath: string): PluginRegistry {\n try {\n if (!fs.existsSync(registryPath)) return { plugins: {}, disabledPlugins: [] };\n const raw = JSON.parse(fs.readFileSync(registryPath, 'utf-8')) as unknown;\n return validatePluginRegistry(raw);\n } catch {\n return { plugins: {}, disabledPlugins: [] };\n }\n}\n\nexport function savePluginRegistry(registryPath: string, registry: PluginRegistry): void {\n fs.mkdirSync(path.dirname(registryPath), { recursive: true });\n fs.writeFileSync(registryPath, `${JSON.stringify(validatePluginRegistry(registry), null, 2)}\\n`);\n}\n\nexport function mergePluginRegistries(\n globalRegistry: PluginRegistry,\n projectRegistry: PluginRegistry,\n): ScopedInstalledPluginRecord[] {\n const merged = new Map<string, ScopedInstalledPluginRecord>();\n const disabledPlugins = new Set([\n ...(globalRegistry.disabledPlugins ?? []),\n ...(projectRegistry.disabledPlugins ?? []),\n ]);\n\n for (const [id, record] of Object.entries(globalRegistry.plugins)) {\n merged.set(id, { id, scope: 'global', ...record });\n }\n\n for (const [id, record] of Object.entries(projectRegistry.plugins)) {\n merged.set(id, { id, scope: 'project', ...record });\n }\n\n return [...merged.values()]\n .map(record => (disabledPlugins.has(record.id) ? { ...record, blocked: true } : record))\n .sort((a, b) => {\n if (a.scope !== b.scope) return a.scope === 'project' ? -1 : 1;\n return a.id.localeCompare(b.id);\n });\n}\n\nexport function setPluginRecord(\n registry: PluginRegistry,\n pluginId: string,\n record: InstalledPluginRecord,\n): PluginRegistry {\n return {\n plugins: {\n ...registry.plugins,\n [pluginId]: record,\n },\n disabledPlugins: registry.disabledPlugins ?? [],\n };\n}\n\nexport function removePluginRecord(registry: PluginRegistry, pluginId: string): PluginRegistry {\n const plugins = { ...registry.plugins };\n delete plugins[pluginId];\n return { plugins, disabledPlugins: registry.disabledPlugins ?? [] };\n}\n\nfunction validatePluginRegistry(raw: unknown): PluginRegistry {\n if (!raw || typeof raw !== 'object') return { plugins: {}, disabledPlugins: [] };\n const plugins = (raw as { plugins?: unknown }).plugins;\n if (!plugins || typeof plugins !== 'object' || Array.isArray(plugins)) return { plugins: {}, disabledPlugins: [] };\n\n const disabledPlugins = (raw as { disabledPlugins?: unknown }).disabledPlugins;\n const validated: PluginRegistry = {\n plugins: {},\n disabledPlugins: Array.isArray(disabledPlugins)\n ? [...new Set(disabledPlugins.filter((pluginId): pluginId is string => typeof pluginId === 'string'))].sort()\n : [],\n };\n for (const [id, value] of Object.entries(plugins)) {\n if (typeof id !== 'string' || id.trim().length === 0) continue;\n if (!value || typeof value !== 'object' || Array.isArray(value)) continue;\n const record = value as Record<string, unknown>;\n if (typeof record.enabled !== 'boolean') continue;\n if (record.source !== 'local' && record.source !== 'github') continue;\n if (typeof record.specifier !== 'string') continue;\n if (typeof record.path !== 'string') continue;\n if (typeof record.entry !== 'string') continue;\n\n validated.plugins[id] = {\n enabled: record.enabled,\n source: record.source,\n specifier: record.specifier,\n path: record.path,\n entry: record.entry,\n ...(typeof record.ref === 'string' ? { ref: record.ref } : {}),\n ...(typeof record.version === 'string' ? { version: record.version } : {}),\n ...(record.config && typeof record.config === 'object' && !Array.isArray(record.config)\n ? { config: validatePluginConfigValues(record.config) }\n : {}),\n };\n }\n\n return validated;\n}\n\nfunction validatePluginConfigValues(raw: object): Record<string, string | boolean> {\n const values: Record<string, string | boolean> = {};\n for (const [key, value] of Object.entries(raw)) {\n if (typeof key !== 'string' || key.trim().length === 0) continue;\n if (typeof value === 'string' || typeof value === 'boolean') values[key] = value;\n }\n return values;\n}\n"],"mappings":";;;AAKA,MAAa,wBAAwC;CAAE,SAAS,CAAC;CAAG,iBAAiB,CAAC;AAAE;AAExF,SAAgB,mBAAmB,cAAsC;CACvE,IAAI;EACF,IAAI,CAAC,GAAG,WAAW,YAAY,GAAG,OAAO;GAAE,SAAS,CAAC;GAAG,iBAAiB,CAAC;EAAE;EAE5E,OAAO,uBADK,KAAK,MAAM,GAAG,aAAa,cAAc,OAAO,CAC5B,CAAC;CACnC,QAAQ;EACN,OAAO;GAAE,SAAS,CAAC;GAAG,iBAAiB,CAAC;EAAE;CAC5C;AACF;AAEA,SAAgB,mBAAmB,cAAsB,UAAgC;CACvF,GAAG,UAAU,KAAK,QAAQ,YAAY,GAAG,EAAE,WAAW,KAAK,CAAC;CAC5D,GAAG,cAAc,cAAc,GAAG,KAAK,UAAU,uBAAuB,QAAQ,GAAG,MAAM,CAAC,EAAE,GAAG;AACjG;AAEA,SAAgB,sBACd,gBACA,iBAC+B;CAC/B,MAAM,yBAAS,IAAI,IAAyC;CAC5D,MAAM,kCAAkB,IAAI,IAAI,CAC9B,GAAI,eAAe,mBAAmB,CAAC,GACvC,GAAI,gBAAgB,mBAAmB,CAAC,CAC1C,CAAC;CAED,KAAK,MAAM,CAAC,IAAI,WAAW,OAAO,QAAQ,eAAe,OAAO,GAC9D,OAAO,IAAI,IAAI;EAAE;EAAI,OAAO;EAAU,GAAG;CAAO,CAAC;CAGnD,KAAK,MAAM,CAAC,IAAI,WAAW,OAAO,QAAQ,gBAAgB,OAAO,GAC/D,OAAO,IAAI,IAAI;EAAE;EAAI,OAAO;EAAW,GAAG;CAAO,CAAC;CAGpD,OAAO,CAAC,GAAG,OAAO,OAAO,CAAC,CAAC,CACxB,KAAI,WAAW,gBAAgB,IAAI,OAAO,EAAE,IAAI;EAAE,GAAG;EAAQ,SAAS;CAAK,IAAI,MAAO,CAAC,CACvF,MAAM,GAAG,MAAM;EACd,IAAI,EAAE,UAAU,EAAE,OAAO,OAAO,EAAE,UAAU,YAAY,KAAK;EAC7D,OAAO,EAAE,GAAG,cAAc,EAAE,EAAE;CAChC,CAAC;AACL;AAEA,SAAgB,gBACd,UACA,UACA,QACgB;CAChB,OAAO;EACL,SAAS;GACP,GAAG,SAAS;IACX,WAAW;EACd;EACA,iBAAiB,SAAS,mBAAmB,CAAC;CAChD;AACF;AAEA,SAAgB,mBAAmB,UAA0B,UAAkC;CAC7F,MAAM,UAAU,EAAE,GAAG,SAAS,QAAQ;CACtC,OAAO,QAAQ;CACf,OAAO;EAAE;EAAS,iBAAiB,SAAS,mBAAmB,CAAC;CAAE;AACpE;AAEA,SAAS,uBAAuB,KAA8B;CAC5D,IAAI,CAAC,OAAO,OAAO,QAAQ,UAAU,OAAO;EAAE,SAAS,CAAC;EAAG,iBAAiB,CAAC;CAAE;CAC/E,MAAM,UAAW,IAA8B;CAC/C,IAAI,CAAC,WAAW,OAAO,YAAY,YAAY,MAAM,QAAQ,OAAO,GAAG,OAAO;EAAE,SAAS,CAAC;EAAG,iBAAiB,CAAC;CAAE;CAEjH,MAAM,kBAAmB,IAAsC;CAC/D,MAAM,YAA4B;EAChC,SAAS,CAAC;EACV,iBAAiB,MAAM,QAAQ,eAAe,IAC1C,CAAC,GAAG,IAAI,IAAI,gBAAgB,QAAQ,aAAiC,OAAO,aAAa,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,IAC1G,CAAC;CACP;CACA,KAAK,MAAM,CAAC,IAAI,UAAU,OAAO,QAAQ,OAAO,GAAG;EACjD,IAAI,OAAO,OAAO,YAAY,GAAG,KAAK,CAAC,CAAC,WAAW,GAAG;EACtD,IAAI,CAAC,SAAS,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GAAG;EACjE,MAAM,SAAS;EACf,IAAI,OAAO,OAAO,YAAY,WAAW;EACzC,IAAI,OAAO,WAAW,WAAW,OAAO,WAAW,UAAU;EAC7D,IAAI,OAAO,OAAO,cAAc,UAAU;EAC1C,IAAI,OAAO,OAAO,SAAS,UAAU;EACrC,IAAI,OAAO,OAAO,UAAU,UAAU;EAEtC,UAAU,QAAQ,MAAM;GACtB,SAAS,OAAO;GAChB,QAAQ,OAAO;GACf,WAAW,OAAO;GAClB,MAAM,OAAO;GACb,OAAO,OAAO;GACd,GAAI,OAAO,OAAO,QAAQ,WAAW,EAAE,KAAK,OAAO,IAAI,IAAI,CAAC;GAC5D,GAAI,OAAO,OAAO,YAAY,WAAW,EAAE,SAAS,OAAO,QAAQ,IAAI,CAAC;GACxE,GAAI,OAAO,UAAU,OAAO,OAAO,WAAW,YAAY,CAAC,MAAM,QAAQ,OAAO,MAAM,IAClF,EAAE,QAAQ,2BAA2B,OAAO,MAAM,EAAE,IACpD,CAAC;EACP;CACF;CAEA,OAAO;AACT;AAEA,SAAS,2BAA2B,KAA+C;CACjF,MAAM,SAA2C,CAAC;CAClD,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,GAAG,GAAG;EAC9C,IAAI,OAAO,QAAQ,YAAY,IAAI,KAAK,CAAC,CAAC,WAAW,GAAG;EACxD,IAAI,OAAO,UAAU,YAAY,OAAO,UAAU,WAAW,OAAO,OAAO;CAC7E;CACA,OAAO;AACT"}
|
|
@@ -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 @@
|
|
|
1
|
+
{"version":3,"file":"scaffold.d.ts","sourceRoot":"","sources":["../../src/plugins/scaffold.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,qBAAqB,GAAG;IAClC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,IAAI,CAAC,qBAAqB,EAAE,aAAa,GAAG,WAAW,CAAM,GACrE,MAAM,CAYR;AAED,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B,GAAG,MAAM,CA8D7F;AAqBD,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAY/D"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import "../constants.js";
|
|
2
|
+
import { upsertPluginManifestEntry } from "./manifest.js";
|
|
3
|
+
import { ensureMastraCodePackageLink } from "./package-link.js";
|
|
4
|
+
import fs from "fs";
|
|
5
|
+
import path from "path";
|
|
6
|
+
//#region 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
|
+
upsertPluginManifestEntry(isBarePluginName(originalTarget) ? projectRoot : scaffoldDir, {
|
|
48
|
+
id: pluginId,
|
|
49
|
+
name: pluginName,
|
|
50
|
+
entry: (isBarePluginName(originalTarget) ? path.join(path.relative(projectRoot, scaffoldDir), "src/index.ts") : "src/index.ts").split(path.sep).join("/")
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function formatScaffoldSuccess(targetDir) {
|
|
54
|
+
return [
|
|
55
|
+
`Created Mastra Code plugin scaffold at ${targetDir}`,
|
|
56
|
+
"",
|
|
57
|
+
"Next steps:",
|
|
58
|
+
` cd ${targetDir}`,
|
|
59
|
+
" pnpm install",
|
|
60
|
+
" pnpm check",
|
|
61
|
+
" mastracode",
|
|
62
|
+
" /plugins",
|
|
63
|
+
" Install new plugin → Local path"
|
|
64
|
+
].join("\n");
|
|
65
|
+
}
|
|
66
|
+
function isBarePluginName(target) {
|
|
67
|
+
return !path.isAbsolute(target) && !target.startsWith(".") && !target.includes("/") && !target.includes("\\");
|
|
68
|
+
}
|
|
69
|
+
function renderIndex(pluginId, pluginName) {
|
|
70
|
+
return `import { createTool, defineMastraCodePlugin, z } from 'mastracode/plugin';
|
|
71
|
+
|
|
72
|
+
export default defineMastraCodePlugin({
|
|
73
|
+
id: ${JSON.stringify(pluginId)},
|
|
74
|
+
name: ${JSON.stringify(pluginName)},
|
|
75
|
+
description: 'A Mastra Code tool plugin.',
|
|
76
|
+
tools: {
|
|
77
|
+
example_tool: {
|
|
78
|
+
tool: createTool({
|
|
79
|
+
id: 'example_tool',
|
|
80
|
+
description: 'Echo a message from the scaffolded plugin.',
|
|
81
|
+
inputSchema: z.object({
|
|
82
|
+
message: z.string(),
|
|
83
|
+
}),
|
|
84
|
+
execute: async context => {
|
|
85
|
+
return { message: context.message };
|
|
86
|
+
},
|
|
87
|
+
}),
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
`;
|
|
92
|
+
}
|
|
93
|
+
function renderReadme(pluginName, pluginId) {
|
|
94
|
+
return `# ${pluginName}
|
|
95
|
+
|
|
96
|
+
Mastra Code tool plugin: \`${pluginId}\`.
|
|
97
|
+
|
|
98
|
+
## Develop
|
|
99
|
+
|
|
100
|
+
\`\`\`sh
|
|
101
|
+
pnpm install
|
|
102
|
+
pnpm check
|
|
103
|
+
\`\`\`
|
|
104
|
+
|
|
105
|
+
## Install locally
|
|
106
|
+
|
|
107
|
+
Open Mastra Code, run \`/plugins\`, and install this directory as a local plugin.
|
|
108
|
+
`;
|
|
109
|
+
}
|
|
110
|
+
function humanizeName(value) {
|
|
111
|
+
return value.split(/[-_.]+/g).filter(Boolean).map((part) => part[0]?.toUpperCase() + part.slice(1)).join(" ") || "Mastra Code Plugin";
|
|
112
|
+
}
|
|
113
|
+
//#endregion
|
|
114
|
+
export { formatScaffoldSuccess, resolveScaffoldTarget, scaffoldPlugin };
|
|
115
|
+
|
|
116
|
+
//# sourceMappingURL=scaffold.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scaffold.js","names":[],"sources":["../../src/plugins/scaffold.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nimport { DEFAULT_CONFIG_DIR } from '../constants.js';\nimport { upsertPluginManifestEntry } from './manifest.js';\nimport { ensureMastraCodePackageLink } from './package-link.js';\n\nexport type ScaffoldPluginOptions = {\n id?: string;\n name?: string;\n projectRoot?: string;\n configDir?: string;\n};\n\nexport function resolveScaffoldTarget(\n target: string,\n options: Pick<ScaffoldPluginOptions, 'projectRoot' | 'configDir'> = {},\n): string {\n if (isBarePluginName(target)) {\n return path.join(\n options.projectRoot ?? process.cwd(),\n options.configDir ?? DEFAULT_CONFIG_DIR,\n 'plugins',\n 'sources',\n 'local',\n target,\n );\n }\n return path.resolve(options.projectRoot ?? process.cwd(), target);\n}\n\nexport function scaffoldPlugin(targetDir: string, options: ScaffoldPluginOptions = {}): string {\n const dir = resolveScaffoldTarget(targetDir, options);\n if (fs.existsSync(dir) && fs.readdirSync(dir).length > 0) {\n throw new Error(`Directory already exists and is not empty: ${targetDir}`);\n }\n\n const packageName =\n path\n .basename(dir)\n .toLowerCase()\n .replace(/[^a-z0-9_.-]+/g, '-')\n .replace(/^-|-$/g, '') || 'mastracode-plugin';\n const pluginId = options.id ?? packageName;\n const pluginName = options.name ?? humanizeName(packageName);\n\n fs.mkdirSync(path.join(dir, 'src'), { recursive: true });\n fs.writeFileSync(\n path.join(dir, 'package.json'),\n `${JSON.stringify(\n {\n name: packageName,\n type: 'module',\n exports: './src/index.ts',\n peerDependencies: {\n mastracode: '*',\n },\n devDependencies: {\n typescript: '^5.9.3',\n },\n scripts: {\n check: 'tsc --noEmit',\n },\n },\n null,\n 2,\n )}\\n`,\n );\n fs.writeFileSync(\n path.join(dir, 'tsconfig.json'),\n `${JSON.stringify(\n {\n compilerOptions: {\n target: 'ES2024',\n module: 'NodeNext',\n moduleResolution: 'NodeNext',\n strict: true,\n verbatimModuleSyntax: true,\n erasableSyntaxOnly: true,\n skipLibCheck: true,\n noEmit: true,\n },\n include: ['src/**/*.ts'],\n },\n null,\n 2,\n )}\\n`,\n );\n fs.writeFileSync(path.join(dir, 'src/index.ts'), renderIndex(pluginId, pluginName));\n fs.writeFileSync(path.join(dir, 'README.md'), renderReadme(pluginName, pluginId));\n writeScaffoldManifest(targetDir, dir, pluginId, pluginName, options);\n ensureMastraCodePackageLink(dir);\n return dir;\n}\n\nfunction writeScaffoldManifest(\n originalTarget: string,\n scaffoldDir: string,\n pluginId: string,\n pluginName: string,\n options: ScaffoldPluginOptions,\n): void {\n const projectRoot = options.projectRoot ?? process.cwd();\n const manifestRoot = isBarePluginName(originalTarget) ? projectRoot : scaffoldDir;\n const entry = isBarePluginName(originalTarget)\n ? path.join(path.relative(projectRoot, scaffoldDir), 'src/index.ts')\n : 'src/index.ts';\n upsertPluginManifestEntry(manifestRoot, {\n id: pluginId,\n name: pluginName,\n entry: entry.split(path.sep).join('/'),\n });\n}\n\nexport function formatScaffoldSuccess(targetDir: string): string {\n return [\n `Created Mastra Code plugin scaffold at ${targetDir}`,\n '',\n 'Next steps:',\n ` cd ${targetDir}`,\n ' pnpm install',\n ' pnpm check',\n ' mastracode',\n ' /plugins',\n ' Install new plugin → Local path',\n ].join('\\n');\n}\n\nfunction isBarePluginName(target: string): boolean {\n return !path.isAbsolute(target) && !target.startsWith('.') && !target.includes('/') && !target.includes('\\\\');\n}\n\nfunction renderIndex(pluginId: string, pluginName: string): string {\n return `import { createTool, defineMastraCodePlugin, z } from 'mastracode/plugin';\n\nexport default defineMastraCodePlugin({\n id: ${JSON.stringify(pluginId)},\n name: ${JSON.stringify(pluginName)},\n description: 'A Mastra Code tool plugin.',\n tools: {\n example_tool: {\n tool: createTool({\n id: 'example_tool',\n description: 'Echo a message from the scaffolded plugin.',\n inputSchema: z.object({\n message: z.string(),\n }),\n execute: async context => {\n return { message: context.message };\n },\n }),\n },\n },\n});\n`;\n}\n\nfunction renderReadme(pluginName: string, pluginId: string): string {\n return `# ${pluginName}\n\nMastra Code tool plugin: \\`${pluginId}\\`.\n\n## Develop\n\n\\`\\`\\`sh\npnpm install\npnpm check\n\\`\\`\\`\n\n## Install locally\n\nOpen Mastra Code, run \\`/plugins\\`, and install this directory as a local plugin.\n`;\n}\n\nfunction humanizeName(value: string): string {\n return (\n value\n .split(/[-_.]+/g)\n .filter(Boolean)\n .map(part => part[0]?.toUpperCase() + part.slice(1))\n .join(' ') || 'Mastra Code Plugin'\n );\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { MastraCodePluginConfigSchema, MastraCodePluginConfigValue, MastraCodePluginTools, MastraCodeToolRenderConfig } from '../plugin.js';
|
|
2
|
+
export type PluginScope = 'global' | 'project';
|
|
3
|
+
export type PluginSource = 'local' | 'github';
|
|
4
|
+
export type PluginStatus = 'active' | 'inactive' | 'blocked' | 'load failed' | 'conflicted';
|
|
5
|
+
export type InstalledPluginRecord = {
|
|
6
|
+
enabled: boolean;
|
|
7
|
+
source: PluginSource;
|
|
8
|
+
specifier: string;
|
|
9
|
+
path: string;
|
|
10
|
+
entry: string;
|
|
11
|
+
ref?: string;
|
|
12
|
+
version?: string;
|
|
13
|
+
config?: Record<string, MastraCodePluginConfigValue>;
|
|
14
|
+
};
|
|
15
|
+
export type PluginRegistry = {
|
|
16
|
+
plugins: Record<string, InstalledPluginRecord>;
|
|
17
|
+
disabledPlugins?: string[];
|
|
18
|
+
};
|
|
19
|
+
export type ScopedInstalledPluginRecord = InstalledPluginRecord & {
|
|
20
|
+
id: string;
|
|
21
|
+
scope: PluginScope;
|
|
22
|
+
blocked?: boolean;
|
|
23
|
+
};
|
|
24
|
+
export type LoadedPlugin = ScopedInstalledPluginRecord & {
|
|
25
|
+
name?: string;
|
|
26
|
+
description?: string;
|
|
27
|
+
instructions?: string;
|
|
28
|
+
status: PluginStatus;
|
|
29
|
+
error?: string;
|
|
30
|
+
tools: MastraCodePluginTools;
|
|
31
|
+
renderConfigs?: Record<string, MastraCodeToolRenderConfig>;
|
|
32
|
+
toolNames: string[];
|
|
33
|
+
skillPaths?: string[];
|
|
34
|
+
commandPaths?: string[];
|
|
35
|
+
configSchema?: MastraCodePluginConfigSchema;
|
|
36
|
+
configValues?: Record<string, MastraCodePluginConfigValue>;
|
|
37
|
+
conflicts?: string[];
|
|
38
|
+
};
|
|
39
|
+
export type PluginScopePaths = {
|
|
40
|
+
scope: PluginScope;
|
|
41
|
+
root: string;
|
|
42
|
+
registryPath: string;
|
|
43
|
+
sourcesPath: string;
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/plugins/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,4BAA4B,EAC5B,2BAA2B,EAC3B,qBAAqB,EACrB,0BAA0B,EAC3B,MAAM,cAAc,CAAC;AAEtB,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC;AAC/C,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,QAAQ,CAAC;AAC9C,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,UAAU,GAAG,SAAS,GAAG,aAAa,GAAG,YAAY,CAAC;AAE5F,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,YAAY,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,2BAA2B,CAAC,CAAC;CACtD,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;IAC/C,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG,qBAAqB,GAAG;IAChE,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,WAAW,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,2BAA2B,GAAG;IACvD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,YAAY,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,qBAAqB,CAAC;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,0BAA0B,CAAC,CAAC;IAC3D,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,YAAY,CAAC,EAAE,4BAA4B,CAAC;IAC5C,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,2BAA2B,CAAC,CAAC;IAC3D,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,WAAW,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Processor that aborts the agentic loop immediately after a `submit_plan` tool
|
|
3
|
+
* returns a rejection result. This prevents the model from generating any text
|
|
4
|
+
* after the user clicks "Request Changes" — the tool result is persisted in
|
|
5
|
+
* thread history (for context on the next run) but no follow-up LLM call is made.
|
|
6
|
+
*/
|
|
7
|
+
import type { Processor, ProcessInputStepArgs } from '@mastra/core/processors';
|
|
8
|
+
export declare class PlanRejectionAbortProcessor implements Processor<'plan-rejection-abort'> {
|
|
9
|
+
id: "plan-rejection-abort";
|
|
10
|
+
processInputStep({ messages, stepNumber, abort }: ProcessInputStepArgs): Promise<undefined>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=plan-rejection-abort.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan-rejection-abort.d.ts","sourceRoot":"","sources":["../../src/processors/plan-rejection-abort.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAyC/E,qBAAa,2BAA4B,YAAW,SAAS,CAAC,sBAAsB,CAAC;IACnF,EAAE,EAAG,sBAAsB,CAAU;IAE/B,gBAAgB,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE,oBAAoB,GAAG,OAAO,CAAC,SAAS,CAAC;CA6ClG"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
//#region src/processors/plan-rejection-abort.ts
|
|
2
|
+
const PLAN_REJECTED_PREFIX = "Plan was not approved";
|
|
3
|
+
function resultText(result) {
|
|
4
|
+
if (typeof result === "string") return result;
|
|
5
|
+
if (result && typeof result === "object") {
|
|
6
|
+
const content = result.content;
|
|
7
|
+
if (typeof content === "string") return content;
|
|
8
|
+
}
|
|
9
|
+
return "";
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Returns true when the invocation is a completed `submit_plan` rejection.
|
|
13
|
+
*/
|
|
14
|
+
function isPlanRejection(inv) {
|
|
15
|
+
if (!inv || inv.state !== "result" || inv.toolName !== "submit_plan") return false;
|
|
16
|
+
return resultText(inv.result).startsWith(PLAN_REJECTED_PREFIX);
|
|
17
|
+
}
|
|
18
|
+
function isPlanRejectionResultPart(part) {
|
|
19
|
+
return part.type === "tool_result" && part.name === "submit_plan" && resultText(part.result).startsWith(PLAN_REJECTED_PREFIX);
|
|
20
|
+
}
|
|
21
|
+
var PlanRejectionAbortProcessor = class {
|
|
22
|
+
id = "plan-rejection-abort";
|
|
23
|
+
async processInputStep({ messages, stepNumber, abort }) {
|
|
24
|
+
if (stepNumber === 0) return void 0;
|
|
25
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
26
|
+
const msg = messages[i];
|
|
27
|
+
if (!msg || msg.role !== "assistant") continue;
|
|
28
|
+
const content = msg.content;
|
|
29
|
+
const parts = Array.isArray(content) ? content : Array.isArray(content?.parts) ? content.parts : [];
|
|
30
|
+
for (const part of parts) {
|
|
31
|
+
if (!part || typeof part !== "object") continue;
|
|
32
|
+
const p = part;
|
|
33
|
+
if (p.type === "tool-invocation" && isPlanRejection(p.toolInvocation)) {
|
|
34
|
+
abort("Plan rejected by user — no further response needed");
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (isPlanRejectionResultPart(p)) {
|
|
38
|
+
abort("Plan rejected by user — no further response needed");
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const legacy = !Array.isArray(content) && Array.isArray(content?.toolInvocations) ? content.toolInvocations : [];
|
|
43
|
+
for (const inv of legacy) if (isPlanRejection(inv)) {
|
|
44
|
+
abort("Plan rejected by user — no further response needed");
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
//#endregion
|
|
52
|
+
export { PlanRejectionAbortProcessor };
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=plan-rejection-abort.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan-rejection-abort.js","names":[],"sources":["../../src/processors/plan-rejection-abort.ts"],"sourcesContent":["/**\n * Processor that aborts the agentic loop immediately after a `submit_plan` tool\n * returns a rejection result. This prevents the model from generating any text\n * after the user clicks \"Request Changes\" — the tool result is persisted in\n * thread history (for context on the next run) but no follow-up LLM call is made.\n */\nimport type { Processor, ProcessInputStepArgs } from '@mastra/core/processors';\n\nconst PLAN_REJECTED_PREFIX = 'Plan was not approved';\n\ntype ToolInvocation = {\n state?: string;\n toolName?: string;\n result?: unknown;\n};\n\ntype ToolResultPart = {\n type?: string;\n name?: string;\n result?: unknown;\n};\n\nfunction resultText(result: unknown): string {\n if (typeof result === 'string') return result;\n if (result && typeof result === 'object') {\n const content = (result as { content?: unknown }).content;\n if (typeof content === 'string') return content;\n }\n return '';\n}\n\n/**\n * Returns true when the invocation is a completed `submit_plan` rejection.\n */\nfunction isPlanRejection(inv: ToolInvocation | undefined): boolean {\n if (!inv || inv.state !== 'result' || inv.toolName !== 'submit_plan') return false;\n return resultText(inv.result).startsWith(PLAN_REJECTED_PREFIX);\n}\n\nfunction isPlanRejectionResultPart(part: ToolResultPart): boolean {\n return (\n part.type === 'tool_result' &&\n part.name === 'submit_plan' &&\n resultText(part.result).startsWith(PLAN_REJECTED_PREFIX)\n );\n}\n\nexport class PlanRejectionAbortProcessor implements Processor<'plan-rejection-abort'> {\n id = 'plan-rejection-abort' as const;\n\n async processInputStep({ messages, stepNumber, abort }: ProcessInputStepArgs): Promise<undefined> {\n // Only act on continuation steps (stepNumber > 0) — step 0 is the initial\n // prompt where the model hasn't responded yet. After tool resume, the tool\n // result is part of step 0 and the loop advances to step 1 for the next\n // model call.\n if (stepNumber === 0) return undefined;\n\n // Walk messages from the end to find the last assistant message.\n for (let i = messages.length - 1; i >= 0; i--) {\n const msg = messages[i];\n if (!msg || msg.role !== 'assistant') continue;\n\n // Check for a submit_plan rejection tool result. Handle the primary\n // `content.parts` shapes (tool-invocation and harness-style tool_result)\n // plus the legacy `content.toolInvocations` array.\n const content = msg.content as { parts?: unknown[]; toolInvocations?: unknown[] } | unknown[] | undefined;\n\n const parts = Array.isArray(content) ? content : Array.isArray(content?.parts) ? content.parts : [];\n for (const part of parts) {\n if (!part || typeof part !== 'object') continue;\n const p = part as { type?: string; toolInvocation?: ToolInvocation } & ToolResultPart;\n if (p.type === 'tool-invocation' && isPlanRejection(p.toolInvocation)) {\n abort('Plan rejected by user — no further response needed');\n return undefined;\n }\n if (isPlanRejectionResultPart(p)) {\n abort('Plan rejected by user — no further response needed');\n return undefined;\n }\n }\n\n const legacy = !Array.isArray(content) && Array.isArray(content?.toolInvocations) ? content.toolInvocations : [];\n for (const inv of legacy) {\n if (isPlanRejection(inv as ToolInvocation)) {\n abort('Plan rejected by user — no further response needed');\n return undefined;\n }\n }\n\n // Only check the most recent assistant message.\n break;\n }\n\n return undefined;\n }\n}\n"],"mappings":";AAQA,MAAM,uBAAuB;AAc7B,SAAS,WAAW,QAAyB;CAC3C,IAAI,OAAO,WAAW,UAAU,OAAO;CACvC,IAAI,UAAU,OAAO,WAAW,UAAU;EACxC,MAAM,UAAW,OAAiC;EAClD,IAAI,OAAO,YAAY,UAAU,OAAO;CAC1C;CACA,OAAO;AACT;;;;AAKA,SAAS,gBAAgB,KAA0C;CACjE,IAAI,CAAC,OAAO,IAAI,UAAU,YAAY,IAAI,aAAa,eAAe,OAAO;CAC7E,OAAO,WAAW,IAAI,MAAM,CAAC,CAAC,WAAW,oBAAoB;AAC/D;AAEA,SAAS,0BAA0B,MAA+B;CAChE,OACE,KAAK,SAAS,iBACd,KAAK,SAAS,iBACd,WAAW,KAAK,MAAM,CAAC,CAAC,WAAW,oBAAoB;AAE3D;AAEA,IAAa,8BAAb,MAAsF;CACpF,KAAK;CAEL,MAAM,iBAAiB,EAAE,UAAU,YAAY,SAAmD;EAKhG,IAAI,eAAe,GAAG,OAAO,KAAA;EAG7B,KAAK,IAAI,IAAI,SAAS,SAAS,GAAG,KAAK,GAAG,KAAK;GAC7C,MAAM,MAAM,SAAS;GACrB,IAAI,CAAC,OAAO,IAAI,SAAS,aAAa;GAKtC,MAAM,UAAU,IAAI;GAEpB,MAAM,QAAQ,MAAM,QAAQ,OAAO,IAAI,UAAU,MAAM,QAAQ,SAAS,KAAK,IAAI,QAAQ,QAAQ,CAAC;GAClG,KAAK,MAAM,QAAQ,OAAO;IACxB,IAAI,CAAC,QAAQ,OAAO,SAAS,UAAU;IACvC,MAAM,IAAI;IACV,IAAI,EAAE,SAAS,qBAAqB,gBAAgB,EAAE,cAAc,GAAG;KACrE,MAAM,oDAAoD;KAC1D;IACF;IACA,IAAI,0BAA0B,CAAC,GAAG;KAChC,MAAM,oDAAoD;KAC1D;IACF;GACF;GAEA,MAAM,SAAS,CAAC,MAAM,QAAQ,OAAO,KAAK,MAAM,QAAQ,SAAS,eAAe,IAAI,QAAQ,kBAAkB,CAAC;GAC/G,KAAK,MAAM,OAAO,QAChB,IAAI,gBAAgB,GAAqB,GAAG;IAC1C,MAAM,oDAAoD;IAC1D;GACF;GAIF;EACF;CAGF;AACF"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { createAmazonBedrock } from '@ai-sdk/amazon-bedrock';
|
|
2
|
+
import { MastraModelGateway } from '@mastra/core/llm';
|
|
3
|
+
import type { GatewayAuthRequest, GatewayAuthResult, GatewayLanguageModel, ProviderConfig } from '@mastra/core/llm';
|
|
4
|
+
type BedrockModel = ReturnType<ReturnType<typeof createAmazonBedrock>>;
|
|
5
|
+
type BedrockPrompt = Parameters<BedrockModel['doGenerate']>[0]['prompt'];
|
|
6
|
+
export declare function supportsBedrockPromptCaching(modelId: string): boolean;
|
|
7
|
+
export declare function addBedrockCachePoints(prompt: BedrockPrompt): BedrockPrompt;
|
|
8
|
+
export declare function withBedrockCache(model: BedrockModel): BedrockModel;
|
|
9
|
+
export declare const AMAZON_BEDROCK_GATEWAY_ID = "amazon-bedrock";
|
|
10
|
+
/**
|
|
11
|
+
* Whether AWS credentials look available for Bedrock.
|
|
12
|
+
*
|
|
13
|
+
* Amazon Bedrock authenticates with AWS SigV4 rather than a bearer API key, so
|
|
14
|
+
* this only governs whether Bedrock models are offered as "authenticated" in the
|
|
15
|
+
* picker. We look for the common signals (env vars, bearer token, a configured
|
|
16
|
+
* profile, or a shared credentials/config file) rather than resolving
|
|
17
|
+
* credentials here, since the auth checker must stay sync.
|
|
18
|
+
*/
|
|
19
|
+
export declare function hasAwsCredentials(): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Standalone Amazon Bedrock gateway.
|
|
22
|
+
*
|
|
23
|
+
* Bedrock is resolved directly via AWS SigV4 (not through the model router) and
|
|
24
|
+
* its models are surfaced from the public models.dev catalog. It is exposed as
|
|
25
|
+
* its own gateway/provider (`amazon-bedrock/...`) rather than nested under the
|
|
26
|
+
* MastraCode gateway namespace.
|
|
27
|
+
*/
|
|
28
|
+
export declare class AmazonBedrockGateway extends MastraModelGateway {
|
|
29
|
+
readonly id = "amazon-bedrock";
|
|
30
|
+
readonly name = "Amazon Bedrock";
|
|
31
|
+
shouldEnable(): boolean;
|
|
32
|
+
fetchProviders(): Promise<Record<string, ProviderConfig>>;
|
|
33
|
+
buildUrl(_modelId: string): string | undefined;
|
|
34
|
+
getApiKey(_modelId: string): Promise<string>;
|
|
35
|
+
resolveAuth(_request: GatewayAuthRequest): GatewayAuthResult | undefined;
|
|
36
|
+
resolveLanguageModel(args: {
|
|
37
|
+
modelId: string;
|
|
38
|
+
providerId: string;
|
|
39
|
+
apiKey: string;
|
|
40
|
+
headers?: Record<string, string>;
|
|
41
|
+
transport?: any;
|
|
42
|
+
responsesWebSocket?: any;
|
|
43
|
+
}): GatewayLanguageModel;
|
|
44
|
+
}
|
|
45
|
+
export declare function createAmazonBedrockGateway(): AmazonBedrockGateway;
|
|
46
|
+
export {};
|
|
47
|
+
//# sourceMappingURL=amazon-bedrock-gateway.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"amazon-bedrock-gateway.d.ts","sourceRoot":"","sources":["../../src/providers/amazon-bedrock-gateway.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAIpH,KAAK,YAAY,GAAG,UAAU,CAAC,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC,CAAC;AACvE,KAAK,aAAa,GAAG,UAAU,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;AAazE,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAErE;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,aAAa,GAAG,aAAa,CAsC1E;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,YAAY,GAAG,YAAY,CAclE;AAED,eAAO,MAAM,yBAAyB,mBAAmB,CAAC;AAE1D;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAuB3C;AA0BD;;;;;;;GAOG;AACH,qBAAa,oBAAqB,SAAQ,kBAAkB;IAC1D,QAAQ,CAAC,EAAE,oBAA6B;IACxC,QAAQ,CAAC,IAAI,oBAAoB;IAEjC,YAAY,IAAI,OAAO;IAIjB,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAiB/D,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAIxC,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIlD,WAAW,CAAC,QAAQ,EAAE,kBAAkB,GAAG,iBAAiB,GAAG,SAAS;IAUxE,oBAAoB,CAAC,IAAI,EAAE;QACzB,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,EAAE,MAAM,CAAC;QACnB,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACjC,SAAS,CAAC,EAAE,GAAG,CAAC;QAChB,kBAAkB,CAAC,EAAE,GAAG,CAAC;KAC1B,GAAG,oBAAoB;CAGzB;AAED,wBAAgB,0BAA0B,IAAI,oBAAoB,CAEjE"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { getBedrockModelCatalog } from "./amazon-bedrock.js";
|
|
2
|
+
import { existsSync } from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { MastraModelGateway } from "@mastra/core/llm";
|
|
5
|
+
import { createAmazonBedrock } from "@ai-sdk/amazon-bedrock";
|
|
6
|
+
import { fromNodeProviderChain } from "@aws-sdk/credential-providers";
|
|
7
|
+
//#region src/providers/amazon-bedrock-gateway.ts
|
|
8
|
+
const CACHEABLE_BEDROCK_MODEL_IDS = [
|
|
9
|
+
"anthropic.claude-3-5-haiku-",
|
|
10
|
+
"anthropic.claude-3-5-sonnet-20241022-v2:0",
|
|
11
|
+
"anthropic.claude-3-7-sonnet-",
|
|
12
|
+
"anthropic.claude-fable-5",
|
|
13
|
+
"anthropic.claude-haiku-4-5-",
|
|
14
|
+
"anthropic.claude-opus-4-",
|
|
15
|
+
"anthropic.claude-sonnet-4-",
|
|
16
|
+
"anthropic.claude-sonnet-5"
|
|
17
|
+
];
|
|
18
|
+
function supportsBedrockPromptCaching(modelId) {
|
|
19
|
+
return CACHEABLE_BEDROCK_MODEL_IDS.some((cacheableModelId) => modelId.includes(cacheableModelId));
|
|
20
|
+
}
|
|
21
|
+
function addBedrockCachePoints(prompt) {
|
|
22
|
+
const result = [...prompt];
|
|
23
|
+
const markCachePoint = (message) => ({
|
|
24
|
+
...message,
|
|
25
|
+
providerOptions: {
|
|
26
|
+
...message.providerOptions,
|
|
27
|
+
bedrock: {
|
|
28
|
+
...message.providerOptions?.bedrock,
|
|
29
|
+
cachePoint: { type: "default" }
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
let lastSystemIndex = -1;
|
|
34
|
+
for (let index = result.length - 1; index >= 0; index--) if (result[index].role === "system") {
|
|
35
|
+
lastSystemIndex = index;
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
if (lastSystemIndex >= 0) result[lastSystemIndex] = markCachePoint(result[lastSystemIndex]);
|
|
39
|
+
let lastNonSystemIndex = -1;
|
|
40
|
+
for (let index = result.length - 1; index >= 0; index--) if (result[index].role !== "system") {
|
|
41
|
+
lastNonSystemIndex = index;
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
if (lastNonSystemIndex >= 0) result[lastNonSystemIndex] = markCachePoint(result[lastNonSystemIndex]);
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
function withBedrockCache(model) {
|
|
48
|
+
return new Proxy(model, { get(target, property, receiver) {
|
|
49
|
+
if (property === "doGenerate") return (options) => target.doGenerate({
|
|
50
|
+
...options,
|
|
51
|
+
prompt: addBedrockCachePoints(options.prompt)
|
|
52
|
+
});
|
|
53
|
+
if (property === "doStream") return (options) => target.doStream({
|
|
54
|
+
...options,
|
|
55
|
+
prompt: addBedrockCachePoints(options.prompt)
|
|
56
|
+
});
|
|
57
|
+
return Reflect.get(target, property, receiver);
|
|
58
|
+
} });
|
|
59
|
+
}
|
|
60
|
+
const AMAZON_BEDROCK_GATEWAY_ID = "amazon-bedrock";
|
|
61
|
+
/**
|
|
62
|
+
* Whether AWS credentials look available for Bedrock.
|
|
63
|
+
*
|
|
64
|
+
* Amazon Bedrock authenticates with AWS SigV4 rather than a bearer API key, so
|
|
65
|
+
* this only governs whether Bedrock models are offered as "authenticated" in the
|
|
66
|
+
* picker. We look for the common signals (env vars, bearer token, a configured
|
|
67
|
+
* profile, or a shared credentials/config file) rather than resolving
|
|
68
|
+
* credentials here, since the auth checker must stay sync.
|
|
69
|
+
*/
|
|
70
|
+
function hasAwsCredentials() {
|
|
71
|
+
if (process.env.AWS_BEARER_TOKEN_BEDROCK || process.env.AWS_ACCESS_KEY_ID && process.env.AWS_SECRET_ACCESS_KEY || process.env.AWS_SHARED_CREDENTIALS_FILE || process.env.AWS_CONFIG_FILE || process.env.AWS_PROFILE || process.env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI || process.env.AWS_CONTAINER_CREDENTIALS_FULL_URI || process.env.AWS_WEB_IDENTITY_TOKEN_FILE) return true;
|
|
72
|
+
const home = process.env.HOME || process.env.USERPROFILE;
|
|
73
|
+
if (home) {
|
|
74
|
+
const awsDir = path.join(home, ".aws");
|
|
75
|
+
const credentialsPath = process.env.AWS_SHARED_CREDENTIALS_FILE ?? path.join(awsDir, "credentials");
|
|
76
|
+
const configPath = process.env.AWS_CONFIG_FILE ?? path.join(awsDir, "config");
|
|
77
|
+
if (existsSync(credentialsPath) || existsSync(configPath)) return true;
|
|
78
|
+
}
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Create an Amazon Bedrock model.
|
|
83
|
+
*
|
|
84
|
+
* Bedrock authenticates with AWS SigV4 rather than a bearer API key, so this
|
|
85
|
+
* resolves credentials through the standard AWS provider chain
|
|
86
|
+
* (`fromNodeProviderChain`): environment variables, shared `~/.aws` config and
|
|
87
|
+
* SSO profiles, and container/instance roles — the same resolution order the AWS
|
|
88
|
+
* CLI uses. The region falls back to `us-east-1` to match the AWS SDK default.
|
|
89
|
+
*
|
|
90
|
+
* When `AWS_BEARER_TOKEN_BEDROCK` is set, `@ai-sdk/amazon-bedrock` uses bearer
|
|
91
|
+
* auth instead and ignores the credential provider, so we leave that path to the
|
|
92
|
+
* SDK and only wire up SigV4 here.
|
|
93
|
+
*/
|
|
94
|
+
function bedrockProvider(modelId, headers) {
|
|
95
|
+
const model = createAmazonBedrock({
|
|
96
|
+
region: process.env.AWS_REGION || process.env.AWS_DEFAULT_REGION || "us-east-1",
|
|
97
|
+
credentialProvider: fromNodeProviderChain(),
|
|
98
|
+
headers
|
|
99
|
+
})(modelId);
|
|
100
|
+
return supportsBedrockPromptCaching(modelId) ? withBedrockCache(model) : model;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Standalone Amazon Bedrock gateway.
|
|
104
|
+
*
|
|
105
|
+
* Bedrock is resolved directly via AWS SigV4 (not through the model router) and
|
|
106
|
+
* its models are surfaced from the public models.dev catalog. It is exposed as
|
|
107
|
+
* its own gateway/provider (`amazon-bedrock/...`) rather than nested under the
|
|
108
|
+
* MastraCode gateway namespace.
|
|
109
|
+
*/
|
|
110
|
+
var AmazonBedrockGateway = class extends MastraModelGateway {
|
|
111
|
+
id = AMAZON_BEDROCK_GATEWAY_ID;
|
|
112
|
+
name = "Amazon Bedrock";
|
|
113
|
+
shouldEnable() {
|
|
114
|
+
return hasAwsCredentials();
|
|
115
|
+
}
|
|
116
|
+
async fetchProviders() {
|
|
117
|
+
const providers = {};
|
|
118
|
+
try {
|
|
119
|
+
const bedrockModels = await getBedrockModelCatalog();
|
|
120
|
+
providers["amazon-bedrock"] = {
|
|
121
|
+
name: "Amazon Bedrock",
|
|
122
|
+
apiKeyEnvVar: "",
|
|
123
|
+
apiKeyHeader: "Authorization",
|
|
124
|
+
gateway: this.id,
|
|
125
|
+
models: bedrockModels.map((model) => model.id)
|
|
126
|
+
};
|
|
127
|
+
} catch (error) {
|
|
128
|
+
console.warn("Failed to load Amazon Bedrock model catalog:", error);
|
|
129
|
+
}
|
|
130
|
+
return providers;
|
|
131
|
+
}
|
|
132
|
+
buildUrl(_modelId) {}
|
|
133
|
+
async getApiKey(_modelId) {
|
|
134
|
+
return hasAwsCredentials() ? "aws-credential-chain" : "";
|
|
135
|
+
}
|
|
136
|
+
resolveAuth(_request) {
|
|
137
|
+
if (hasAwsCredentials()) return {
|
|
138
|
+
apiKey: "aws-credential-chain",
|
|
139
|
+
source: "gateway"
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
resolveLanguageModel(args) {
|
|
143
|
+
return bedrockProvider(args.modelId, args.headers);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
function createAmazonBedrockGateway() {
|
|
147
|
+
return new AmazonBedrockGateway();
|
|
148
|
+
}
|
|
149
|
+
//#endregion
|
|
150
|
+
export { AMAZON_BEDROCK_GATEWAY_ID, AmazonBedrockGateway, addBedrockCachePoints, createAmazonBedrockGateway, hasAwsCredentials, supportsBedrockPromptCaching, withBedrockCache };
|
|
151
|
+
|
|
152
|
+
//# sourceMappingURL=amazon-bedrock-gateway.js.map
|