@mastra/code-sdk 0.0.0-client-tool-results-20260912062135
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 +37 -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/context-audit.d.ts +84 -0
- package/dist/agents/context-audit.d.ts.map +1 -0
- package/dist/agents/context-audit.js +118 -0
- package/dist/agents/context-audit.js.map +1 -0
- package/dist/agents/credential-resolver.d.ts +63 -0
- package/dist/agents/credential-resolver.d.ts.map +1 -0
- package/dist/agents/credential-resolver.js +97 -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 +29 -0
- package/dist/agents/instructions.d.ts.map +1 -0
- package/dist/agents/instructions.js +58 -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 +431 -0
- package/dist/agents/mastracode-gateway.js.map +1 -0
- package/dist/agents/memory.d.ts +30 -0
- package/dist/agents/memory.d.ts.map +1 -0
- package/dist/agents/memory.js +171 -0
- package/dist/agents/memory.js.map +1 -0
- package/dist/agents/model.d.ts +81 -0
- package/dist/agents/model.d.ts.map +1 -0
- package/dist/agents/model.js +155 -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 +49 -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 +42 -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 +42 -0
- package/dist/agents/modes/plan.js.map +1 -0
- package/dist/agents/prompts/agent-instructions.d.ts +70 -0
- package/dist/agents/prompts/agent-instructions.d.ts.map +1 -0
- package/dist/agents/prompts/agent-instructions.js +211 -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 +50 -0
- package/dist/agents/prompts/index.d.ts.map +1 -0
- package/dist/agents/prompts/index.js +119 -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 +18 -0
- package/dist/agents/prompts/tool-guidance.d.ts.map +1 -0
- package/dist/agents/prompts/tool-guidance.js +180 -0
- package/dist/agents/prompts/tool-guidance.js.map +1 -0
- package/dist/agents/sandbox-filesystem.d.ts +117 -0
- package/dist/agents/sandbox-filesystem.d.ts.map +1 -0
- package/dist/agents/sandbox-filesystem.js +356 -0
- package/dist/agents/sandbox-filesystem.js.map +1 -0
- package/dist/agents/subagents/execute.d.ts +3 -0
- package/dist/agents/subagents/execute.d.ts.map +1 -0
- package/dist/agents/subagents/execute.js +27 -0
- package/dist/agents/subagents/execute.js.map +1 -0
- package/dist/agents/subagents/explore.d.ts +3 -0
- package/dist/agents/subagents/explore.d.ts.map +1 -0
- package/dist/agents/subagents/explore.js +18 -0
- package/dist/agents/subagents/explore.js.map +1 -0
- package/dist/agents/subagents/plan.d.ts +3 -0
- package/dist/agents/subagents/plan.d.ts.map +1 -0
- package/dist/agents/subagents/plan.js +18 -0
- package/dist/agents/subagents/plan.js.map +1 -0
- package/dist/agents/thread-caveman-state.d.ts +17 -0
- package/dist/agents/thread-caveman-state.d.ts.map +1 -0
- package/dist/agents/thread-caveman-state.js +107 -0
- package/dist/agents/thread-caveman-state.js.map +1 -0
- package/dist/agents/tool-availability.d.ts +10 -0
- package/dist/agents/tool-availability.d.ts.map +1 -0
- package/dist/agents/tool-availability.js +96 -0
- package/dist/agents/tool-availability.js.map +1 -0
- package/dist/agents/tools.d.ts +36 -0
- package/dist/agents/tools.d.ts.map +1 -0
- package/dist/agents/tools.js +117 -0
- package/dist/agents/tools.js.map +1 -0
- package/dist/agents/workflow-builder-agent.d.ts +2 -0
- package/dist/agents/workflow-builder-agent.d.ts.map +1 -0
- package/dist/agents/workflow-builder-agent.js +80 -0
- package/dist/agents/workflow-builder-agent.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 +208 -0
- package/dist/agents/workspace.js.map +1 -0
- package/dist/analytics.d.ts +18 -0
- package/dist/analytics.d.ts.map +1 -0
- package/dist/analytics.js +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 +12 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +8 -0
- package/dist/auth/pkce.d.ts +13 -0
- package/dist/auth/pkce.d.ts.map +1 -0
- package/dist/auth/pkce.js +32 -0
- package/dist/auth/pkce.js.map +1 -0
- package/dist/auth/provider-auth-error.d.ts +12 -0
- package/dist/auth/provider-auth-error.d.ts.map +1 -0
- package/dist/auth/provider-auth-error.js +16 -0
- package/dist/auth/provider-auth-error.js.map +1 -0
- package/dist/auth/providers/anthropic.d.ts +40 -0
- package/dist/auth/providers/anthropic.d.ts.map +1 -0
- package/dist/auth/providers/anthropic.js +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/kimi-coding.d.ts +38 -0
- package/dist/auth/providers/kimi-coding.d.ts.map +1 -0
- package/dist/auth/providers/kimi-coding.js +232 -0
- package/dist/auth/providers/kimi-coding.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 +92 -0
- package/dist/auth/storage.d.ts.map +1 -0
- package/dist/auth/storage.js +211 -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 +209 -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 +19 -0
- package/dist/headless/types.js.map +1 -0
- package/dist/hooks/config.d.ts +11 -0
- package/dist/hooks/config.d.ts.map +1 -0
- package/dist/hooks/config.js +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 +129 -0
- package/dist/hooks/executor.js.map +1 -0
- package/dist/hooks/index.d.ts +6 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +5 -0
- package/dist/hooks/manager.d.ts +54 -0
- package/dist/hooks/manager.d.ts.map +1 -0
- package/dist/hooks/manager.js +241 -0
- package/dist/hooks/manager.js.map +1 -0
- package/dist/hooks/types.d.ts +172 -0
- package/dist/hooks/types.d.ts.map +1 -0
- package/dist/hooks/types.js +8 -0
- package/dist/hooks/types.js.map +1 -0
- package/dist/index.d.ts +341 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +919 -0
- package/dist/index.js.map +1 -0
- package/dist/ipc/ipc-reporter.d.ts +14 -0
- package/dist/ipc/ipc-reporter.d.ts.map +1 -0
- package/dist/ipc/ipc-reporter.js +21 -0
- package/dist/ipc/ipc-reporter.js.map +1 -0
- package/dist/knowledge-inspector.d.ts +119 -0
- package/dist/knowledge-inspector.d.ts.map +1 -0
- package/dist/knowledge-inspector.js +508 -0
- package/dist/knowledge-inspector.js.map +1 -0
- package/dist/knowledge-scope.d.ts +35 -0
- package/dist/knowledge-scope.d.ts.map +1 -0
- package/dist/knowledge-scope.js +47 -0
- package/dist/knowledge-scope.js.map +1 -0
- package/dist/lsp/client.d.ts +56 -0
- package/dist/lsp/client.d.ts.map +1 -0
- package/dist/lsp/client.js +251 -0
- package/dist/lsp/client.js.map +1 -0
- package/dist/lsp/index.d.ts +4 -0
- package/dist/lsp/index.d.ts.map +1 -0
- package/dist/lsp/index.js +4 -0
- package/dist/lsp/language.d.ts +9 -0
- package/dist/lsp/language.d.ts.map +1 -0
- package/dist/lsp/language.js +44 -0
- package/dist/lsp/language.js.map +1 -0
- package/dist/lsp/manager.d.ts +34 -0
- package/dist/lsp/manager.d.ts.map +1 -0
- package/dist/lsp/manager.js +82 -0
- package/dist/lsp/manager.js.map +1 -0
- package/dist/lsp/server.d.ts +27 -0
- package/dist/lsp/server.d.ts.map +1 -0
- package/dist/lsp/server.js +159 -0
- package/dist/lsp/server.js.map +1 -0
- package/dist/lsp/workspace.d.ts +9 -0
- package/dist/lsp/workspace.d.ts.map +1 -0
- package/dist/lsp/workspace.js +55 -0
- package/dist/lsp/workspace.js.map +1 -0
- package/dist/mcp/config.d.ts +62 -0
- package/dist/mcp/config.d.ts.map +1 -0
- package/dist/mcp/config.js +301 -0
- package/dist/mcp/config.js.map +1 -0
- package/dist/mcp/index.d.ts +6 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +3 -0
- package/dist/mcp/manager.d.ts +101 -0
- package/dist/mcp/manager.d.ts.map +1 -0
- package/dist/mcp/manager.js +644 -0
- package/dist/mcp/manager.js.map +1 -0
- package/dist/mcp/state.d.ts +35 -0
- package/dist/mcp/state.d.ts.map +1 -0
- package/dist/mcp/state.js +97 -0
- package/dist/mcp/state.js.map +1 -0
- package/dist/mcp/types.d.ts +125 -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 +49 -0
- package/dist/onboarding/packs.d.ts.map +1 -0
- package/dist/onboarding/packs.js +182 -0
- package/dist/onboarding/packs.js.map +1 -0
- package/dist/onboarding/settings.d.ts +438 -0
- package/dist/onboarding/settings.d.ts.map +1 -0
- package/dist/onboarding/settings.js +847 -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 +137 -0
- package/dist/permissions.js.map +1 -0
- package/dist/plugin.d.ts +144 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +30 -0
- package/dist/plugin.js.map +1 -0
- package/dist/plugins/dependencies.d.ts +9 -0
- package/dist/plugins/dependencies.d.ts.map +1 -0
- package/dist/plugins/dependencies.js +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 +19 -0
- package/dist/plugins/loader.d.ts.map +1 -0
- package/dist/plugins/loader.js +258 -0
- package/dist/plugins/loader.js.map +1 -0
- package/dist/plugins/manager.d.ts +98 -0
- package/dist/plugins/manager.d.ts.map +1 -0
- package/dist/plugins/manager.js +456 -0
- package/dist/plugins/manager.js.map +1 -0
- package/dist/plugins/manifest.d.ts +14 -0
- package/dist/plugins/manifest.d.ts.map +1 -0
- package/dist/plugins/manifest.js +50 -0
- package/dist/plugins/manifest.js.map +1 -0
- package/dist/plugins/package-link.d.ts +3 -0
- package/dist/plugins/package-link.d.ts.map +1 -0
- package/dist/plugins/package-link.js +61 -0
- package/dist/plugins/package-link.js.map +1 -0
- package/dist/plugins/paths.d.ts +10 -0
- package/dist/plugins/paths.d.ts.map +1 -0
- package/dist/plugins/paths.js +25 -0
- package/dist/plugins/paths.js.map +1 -0
- package/dist/plugins/registry.d.ts +8 -0
- package/dist/plugins/registry.d.ts.map +1 -0
- package/dist/plugins/registry.js +112 -0
- package/dist/plugins/registry.js.map +1 -0
- package/dist/plugins/scaffold.d.ts +10 -0
- package/dist/plugins/scaffold.d.ts.map +1 -0
- package/dist/plugins/scaffold.js +116 -0
- package/dist/plugins/scaffold.js.map +1 -0
- package/dist/plugins/signal-lane.d.ts +58 -0
- package/dist/plugins/signal-lane.d.ts.map +1 -0
- package/dist/plugins/signal-lane.js +166 -0
- package/dist/plugins/signal-lane.js.map +1 -0
- package/dist/plugins/types.d.ts +81 -0
- package/dist/plugins/types.d.ts.map +1 -0
- package/dist/plugins/types.js +1 -0
- package/dist/process-memory-diagnostics.d.ts +135 -0
- package/dist/process-memory-diagnostics.d.ts.map +1 -0
- package/dist/process-memory-diagnostics.js +500 -0
- package/dist/process-memory-diagnostics.js.map +1 -0
- package/dist/processors/plan-rejection-abort.d.ts +12 -0
- package/dist/processors/plan-rejection-abort.d.ts.map +1 -0
- package/dist/processors/plan-rejection-abort.js +54 -0
- package/dist/processors/plan-rejection-abort.js.map +1 -0
- package/dist/providers/amazon-bedrock-gateway.d.ts +47 -0
- package/dist/providers/amazon-bedrock-gateway.d.ts.map +1 -0
- package/dist/providers/amazon-bedrock-gateway.js +153 -0
- package/dist/providers/amazon-bedrock-gateway.js.map +1 -0
- package/dist/providers/amazon-bedrock.d.ts +28 -0
- package/dist/providers/amazon-bedrock.d.ts.map +1 -0
- package/dist/providers/amazon-bedrock.js +102 -0
- package/dist/providers/amazon-bedrock.js.map +1 -0
- package/dist/providers/claude-max.d.ts +65 -0
- package/dist/providers/claude-max.d.ts.map +1 -0
- package/dist/providers/claude-max.js +252 -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 +266 -0
- package/dist/providers/github-copilot.js.map +1 -0
- package/dist/providers/kimi-coding.d.ts +15 -0
- package/dist/providers/kimi-coding.d.ts.map +1 -0
- package/dist/providers/kimi-coding.js +69 -0
- package/dist/providers/kimi-coding.js.map +1 -0
- package/dist/providers/openai-codex.d.ts +73 -0
- package/dist/providers/openai-codex.d.ts.map +1 -0
- package/dist/providers/openai-codex.js +306 -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 +71 -0
- package/dist/providers/xai.js.map +1 -0
- package/dist/schema.d.ts +200 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +92 -0
- package/dist/schema.js.map +1 -0
- package/dist/theme-palette.d.ts +17 -0
- package/dist/theme-palette.d.ts.map +1 -0
- package/dist/theme-palette.js +21 -0
- package/dist/theme-palette.js.map +1 -0
- package/dist/thinking.d.ts +33 -0
- package/dist/thinking.d.ts.map +1 -0
- package/dist/thinking.js +58 -0
- package/dist/thinking.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 +114 -0
- package/dist/tools/web-search.d.ts.map +1 -0
- package/dist/tools/web-search.js +155 -0
- package/dist/tools/web-search.js.map +1 -0
- package/dist/tools/workflows/create-workflow.d.ts +7 -0
- package/dist/tools/workflows/create-workflow.d.ts.map +1 -0
- package/dist/tools/workflows/create-workflow.js +81 -0
- package/dist/tools/workflows/create-workflow.js.map +1 -0
- package/dist/tools/workflows/delete-workflow.d.ts +7 -0
- package/dist/tools/workflows/delete-workflow.d.ts.map +1 -0
- package/dist/tools/workflows/delete-workflow.js +21 -0
- package/dist/tools/workflows/delete-workflow.js.map +1 -0
- package/dist/tools/workflows/ephemeral-memory.d.ts +7 -0
- package/dist/tools/workflows/ephemeral-memory.d.ts.map +1 -0
- package/dist/tools/workflows/ephemeral-memory.js +45 -0
- package/dist/tools/workflows/ephemeral-memory.js.map +1 -0
- package/dist/tools/workflows/extract-json-schema.d.ts +12 -0
- package/dist/tools/workflows/extract-json-schema.d.ts.map +1 -0
- package/dist/tools/workflows/extract-json-schema.js +22 -0
- package/dist/tools/workflows/extract-json-schema.js.map +1 -0
- package/dist/tools/workflows/get-workflow.d.ts +11 -0
- package/dist/tools/workflows/get-workflow.d.ts.map +1 -0
- package/dist/tools/workflows/get-workflow.js +34 -0
- package/dist/tools/workflows/get-workflow.js.map +1 -0
- package/dist/tools/workflows/list-available-agents.d.ts +8 -0
- package/dist/tools/workflows/list-available-agents.d.ts.map +1 -0
- package/dist/tools/workflows/list-available-agents.js +32 -0
- package/dist/tools/workflows/list-available-agents.js.map +1 -0
- package/dist/tools/workflows/list-available-tools.d.ts +9 -0
- package/dist/tools/workflows/list-available-tools.d.ts.map +1 -0
- package/dist/tools/workflows/list-available-tools.js +40 -0
- package/dist/tools/workflows/list-available-tools.js.map +1 -0
- package/dist/tools/workflows/list-available-workflows.d.ts +9 -0
- package/dist/tools/workflows/list-available-workflows.d.ts.map +1 -0
- package/dist/tools/workflows/list-available-workflows.js +32 -0
- package/dist/tools/workflows/list-available-workflows.js.map +1 -0
- package/dist/tools/workflows/list-workflows.d.ts +9 -0
- package/dist/tools/workflows/list-workflows.d.ts.map +1 -0
- package/dist/tools/workflows/list-workflows.js +33 -0
- package/dist/tools/workflows/list-workflows.js.map +1 -0
- package/dist/tools/workflows/run-workflow.d.ts +9 -0
- package/dist/tools/workflows/run-workflow.d.ts.map +1 -0
- package/dist/tools/workflows/run-workflow.js +52 -0
- package/dist/tools/workflows/run-workflow.js.map +1 -0
- package/dist/tools/workflows/save-workflow.d.ts +1015 -0
- package/dist/tools/workflows/save-workflow.d.ts.map +1 -0
- package/dist/tools/workflows/save-workflow.js +28 -0
- package/dist/tools/workflows/save-workflow.js.map +1 -0
- package/dist/tools/workflows/tool-ids.d.ts +15 -0
- package/dist/tools/workflows/tool-ids.d.ts.map +1 -0
- package/dist/tools/workflows/tool-ids.js +19 -0
- package/dist/tools/workflows/tool-ids.js.map +1 -0
- package/dist/utils/binaries.d.ts +7 -0
- package/dist/utils/binaries.d.ts.map +1 -0
- package/dist/utils/binaries.js +78 -0
- package/dist/utils/binaries.js.map +1 -0
- package/dist/utils/debug-log.d.ts +12 -0
- package/dist/utils/debug-log.d.ts.map +1 -0
- package/dist/utils/debug-log.js +59 -0
- package/dist/utils/debug-log.js.map +1 -0
- package/dist/utils/errors.d.ts +36 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +196 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/gateway-sync.d.ts +26 -0
- package/dist/utils/gateway-sync.d.ts.map +1 -0
- package/dist/utils/gateway-sync.js +61 -0
- package/dist/utils/gateway-sync.js.map +1 -0
- package/dist/utils/path-security.d.ts +2 -0
- package/dist/utils/path-security.d.ts.map +1 -0
- package/dist/utils/path-security.js +10 -0
- package/dist/utils/path-security.js.map +1 -0
- package/dist/utils/plan-diff.d.ts +25 -0
- package/dist/utils/plan-diff.d.ts.map +1 -0
- package/dist/utils/plan-diff.js +62 -0
- package/dist/utils/plan-diff.js.map +1 -0
- package/dist/utils/plans.d.ts +59 -0
- package/dist/utils/plans.d.ts.map +1 -0
- package/dist/utils/plans.js +117 -0
- package/dist/utils/plans.js.map +1 -0
- package/dist/utils/project.d.ts +160 -0
- package/dist/utils/project.d.ts.map +1 -0
- package/dist/utils/project.js +364 -0
- package/dist/utils/project.js.map +1 -0
- package/dist/utils/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 +142 -0
- package/dist/utils/slash-command-loader.js.map +1 -0
- package/dist/utils/slash-command-processor.d.ts +14 -0
- package/dist/utils/slash-command-processor.d.ts.map +1 -0
- package/dist/utils/slash-command-processor.js +109 -0
- package/dist/utils/slash-command-processor.js.map +1 -0
- package/dist/utils/stdin-pipe.d.ts +33 -0
- package/dist/utils/stdin-pipe.d.ts.map +1 -0
- package/dist/utils/stdin-pipe.js +96 -0
- package/dist/utils/stdin-pipe.js.map +1 -0
- package/dist/utils/storage-factory.d.ts +50 -0
- package/dist/utils/storage-factory.d.ts.map +1 -0
- package/dist/utils/storage-factory.js +121 -0
- package/dist/utils/storage-factory.js.map +1 -0
- package/dist/utils/storage-maintenance.d.ts +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/dist/workflows/register-primitives.d.ts +52 -0
- package/dist/workflows/register-primitives.d.ts.map +1 -0
- package/dist/workflows/register-primitives.js +40 -0
- package/dist/workflows/register-primitives.js.map +1 -0
- package/dist/workflows/service.d.ts +64 -0
- package/dist/workflows/service.d.ts.map +1 -0
- package/dist/workflows/service.js +53 -0
- package/dist/workflows/service.js.map +1 -0
- package/package.json +97 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"save-workflow.d.ts","sourceRoot":"","sources":["../../../src/tools/workflows/save-workflow.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,2CAA2C,IAAI,0BAA0B,EAAE,MAAM,gCAAgC,CAAC;AAE3H,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAGzC,CAAC;AAEF,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4HAsB3B,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createTool } from "@mastra/core/tools";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { WORKFLOW_BUILDER_MAPPING_CONFIG_DESCRIPTION as MAPPING_CONFIG_DESCRIPTION, normalizeWorkflowBuilderDefinition, workflowBuilderDefinitionSchema } from "@mastra/core/workflows/builder";
|
|
4
|
+
//#region src/tools/workflows/save-workflow.ts
|
|
5
|
+
const workflowDefinitionInputSchema = z.preprocess(normalizeWorkflowBuilderDefinition, workflowBuilderDefinitionSchema);
|
|
6
|
+
const saveWorkflowTool = createTool({
|
|
7
|
+
id: "save-workflow",
|
|
8
|
+
description: "Persist a Dynamic Workflow definition and live-register it on the running Mastra instance. Supports all ten persisted graph families: agent, tool, mapping, nested workflow, parallel, foreach, sleep, sleepUntil, conditional, and loop. Conditional and loop entries require declarative predicates; JS closures cannot round-trip through storage. After this returns, the workflow is immediately runnable. Call it exactly once with the complete definition; there is no incremental save API.",
|
|
9
|
+
inputSchema: workflowDefinitionInputSchema,
|
|
10
|
+
outputSchema: z.object({
|
|
11
|
+
ok: z.literal(true),
|
|
12
|
+
id: z.string()
|
|
13
|
+
}),
|
|
14
|
+
execute: async (def, { mastra }) => {
|
|
15
|
+
if (!mastra) throw new Error("save-workflow requires a Mastra context.");
|
|
16
|
+
const m = mastra;
|
|
17
|
+
const normalizedDefinition = normalizeWorkflowBuilderDefinition(def);
|
|
18
|
+
await m.addDynamicWorkflow(normalizedDefinition);
|
|
19
|
+
return {
|
|
20
|
+
ok: true,
|
|
21
|
+
id: normalizedDefinition.id
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
//#endregion
|
|
26
|
+
export { MAPPING_CONFIG_DESCRIPTION, saveWorkflowTool, workflowDefinitionInputSchema };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=save-workflow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"save-workflow.js","names":[],"sources":["../../../src/tools/workflows/save-workflow.ts"],"sourcesContent":["/**\n * Sub-agent tool: persist the Dynamic Workflow definition and live-register it.\n * Calls `mastra.addDynamicWorkflow()`. After this returns the workflow is\n * immediately runnable.\n *\n * The complete-definition authoring contract (graph families, mapping sources,\n * predicate DSL, and all model-facing guidance) is shared with Studio's\n * `submit-workflow-draft` and lives in `@mastra/core/workflows/builder`.\n */\nimport type { Mastra } from '@mastra/core/mastra';\nimport { createTool } from '@mastra/core/tools';\nimport { normalizeWorkflowBuilderDefinition, workflowBuilderDefinitionSchema } from '@mastra/core/workflows/builder';\nimport { z } from 'zod';\n\nexport { WORKFLOW_BUILDER_MAPPING_CONFIG_DESCRIPTION as MAPPING_CONFIG_DESCRIPTION } from '@mastra/core/workflows/builder';\n\nexport const workflowDefinitionInputSchema = z.preprocess(\n normalizeWorkflowBuilderDefinition,\n workflowBuilderDefinitionSchema,\n);\n\nexport const saveWorkflowTool = createTool({\n id: 'save-workflow',\n description:\n 'Persist a Dynamic Workflow definition and live-register it on the running Mastra instance. Supports all ten persisted graph families: agent, tool, mapping, nested workflow, parallel, foreach, sleep, sleepUntil, conditional, and loop. Conditional and loop entries require declarative predicates; JS closures cannot round-trip through storage. After this returns, the workflow is immediately runnable. Call it exactly once with the complete definition; there is no incremental save API.',\n inputSchema: workflowDefinitionInputSchema,\n outputSchema: z.object({\n ok: z.literal(true),\n id: z.string(),\n }),\n execute: async (def, { mastra }) => {\n if (!mastra) throw new Error('save-workflow requires a Mastra context.');\n const m = mastra as Mastra;\n const normalizedDefinition = normalizeWorkflowBuilderDefinition(def);\n\n // `mastra.addDynamicWorkflow` performs registry pre-flight — a mis-classified\n // agentId/toolId or unregistered id throws before rehydration with an\n // actionable message listing every offender. It also rejects JSON Schemas\n // that use keywords the storage-side converter can't rehydrate\n // (oneOf/anyOf/allOf/not/$ref/patternProperties/discriminator).\n await m.addDynamicWorkflow(normalizedDefinition as Parameters<Mastra['addDynamicWorkflow']>[0]);\n return { ok: true as const, id: normalizedDefinition.id };\n },\n});\n"],"mappings":";;;;AAgBA,MAAa,gCAAgC,EAAE,WAC7C,oCACA,+BACF;AAEA,MAAa,mBAAmB,WAAW;CACzC,IAAI;CACJ,aACE;CACF,aAAa;CACb,cAAc,EAAE,OAAO;EACrB,IAAI,EAAE,QAAQ,IAAI;EAClB,IAAI,EAAE,OAAO;CACf,CAAC;CACD,SAAS,OAAO,KAAK,EAAE,aAAa;EAClC,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,0CAA0C;EACvE,MAAM,IAAI;EACV,MAAM,uBAAuB,mCAAmC,GAAG;EAOnE,MAAM,EAAE,mBAAmB,oBAAmE;EAC9F,OAAO;GAAE,IAAI;GAAe,IAAI,qBAAqB;EAAG;CAC1D;AACF,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const WORKFLOW_AUTHORING_TOOL_IDS: {
|
|
2
|
+
readonly listAgents: "list-available-agents";
|
|
3
|
+
readonly listTools: "list-available-tools";
|
|
4
|
+
readonly listWorkflows: "list-available-workflows";
|
|
5
|
+
readonly saveWorkflow: "save-workflow";
|
|
6
|
+
};
|
|
7
|
+
export declare const WORKFLOW_MANAGEMENT_TOOL_IDS: {
|
|
8
|
+
readonly createWorkflow: "create-workflow";
|
|
9
|
+
readonly listWorkflows: "list-workflows";
|
|
10
|
+
readonly getWorkflow: "get-workflow";
|
|
11
|
+
readonly runWorkflow: "run-workflow";
|
|
12
|
+
readonly deleteWorkflow: "delete-workflow";
|
|
13
|
+
};
|
|
14
|
+
export declare const WORKFLOW_BUILDER_NOISE_TOOL_IDS: readonly ("create-workflow" | "delete-workflow" | "get-workflow" | "list-workflows" | "run-workflow" | "list-available-agents" | "list-available-tools" | "list-available-workflows" | "save-workflow")[];
|
|
15
|
+
//# sourceMappingURL=tool-ids.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-ids.d.ts","sourceRoot":"","sources":["../../../src/tools/workflows/tool-ids.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,2BAA2B;;;;;CAK9B,CAAC;AAEX,eAAO,MAAM,4BAA4B;;;;;;CAM/B,CAAC;AAEX,eAAO,MAAM,+BAA+B,2MAGlC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/tools/workflows/tool-ids.ts
|
|
2
|
+
const WORKFLOW_AUTHORING_TOOL_IDS = {
|
|
3
|
+
listAgents: "list-available-agents",
|
|
4
|
+
listTools: "list-available-tools",
|
|
5
|
+
listWorkflows: "list-available-workflows",
|
|
6
|
+
saveWorkflow: "save-workflow"
|
|
7
|
+
};
|
|
8
|
+
const WORKFLOW_MANAGEMENT_TOOL_IDS = {
|
|
9
|
+
createWorkflow: "create-workflow",
|
|
10
|
+
listWorkflows: "list-workflows",
|
|
11
|
+
getWorkflow: "get-workflow",
|
|
12
|
+
runWorkflow: "run-workflow",
|
|
13
|
+
deleteWorkflow: "delete-workflow"
|
|
14
|
+
};
|
|
15
|
+
const WORKFLOW_BUILDER_NOISE_TOOL_IDS = [...Object.values(WORKFLOW_AUTHORING_TOOL_IDS), ...Object.values(WORKFLOW_MANAGEMENT_TOOL_IDS)];
|
|
16
|
+
//#endregion
|
|
17
|
+
export { WORKFLOW_AUTHORING_TOOL_IDS, WORKFLOW_BUILDER_NOISE_TOOL_IDS, WORKFLOW_MANAGEMENT_TOOL_IDS };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=tool-ids.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-ids.js","names":[],"sources":["../../../src/tools/workflows/tool-ids.ts"],"sourcesContent":["export const WORKFLOW_AUTHORING_TOOL_IDS = {\n listAgents: 'list-available-agents',\n listTools: 'list-available-tools',\n listWorkflows: 'list-available-workflows',\n saveWorkflow: 'save-workflow',\n} as const;\n\nexport const WORKFLOW_MANAGEMENT_TOOL_IDS = {\n createWorkflow: 'create-workflow',\n listWorkflows: 'list-workflows',\n getWorkflow: 'get-workflow',\n runWorkflow: 'run-workflow',\n deleteWorkflow: 'delete-workflow',\n} as const;\n\nexport const WORKFLOW_BUILDER_NOISE_TOOL_IDS = [\n ...Object.values(WORKFLOW_AUTHORING_TOOL_IDS),\n ...Object.values(WORKFLOW_MANAGEMENT_TOOL_IDS),\n] as const;\n"],"mappings":";AAAA,MAAa,8BAA8B;CACzC,YAAY;CACZ,WAAW;CACX,eAAe;CACf,cAAc;AAChB;AAEA,MAAa,+BAA+B;CAC1C,gBAAgB;CAChB,eAAe;CACf,aAAa;CACb,aAAa;CACb,gBAAgB;AAClB;AAEA,MAAa,kCAAkC,CAC7C,GAAG,OAAO,OAAO,2BAA2B,GAC5C,GAAG,OAAO,OAAO,4BAA4B,CAC/C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binaries.d.ts","sourceRoot":"","sources":["../../src/utils/binaries.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB;AAmDD,wBAAgB,oBAAoB,IAAI,YAAY,EAAE,CAOrD;AAED,wBAAsB,yBAAyB,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC,CAiBzE"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { execFile, execFileSync } from "child_process";
|
|
2
|
+
//#region src/utils/binaries.ts
|
|
3
|
+
const COMMON_BINARIES = [
|
|
4
|
+
"python",
|
|
5
|
+
"python3",
|
|
6
|
+
"node",
|
|
7
|
+
"npm",
|
|
8
|
+
"pnpm",
|
|
9
|
+
"yarn",
|
|
10
|
+
"bun",
|
|
11
|
+
"git",
|
|
12
|
+
"rg",
|
|
13
|
+
"fd",
|
|
14
|
+
"fdfind",
|
|
15
|
+
"curl",
|
|
16
|
+
"wget",
|
|
17
|
+
"docker",
|
|
18
|
+
"make",
|
|
19
|
+
"gcc",
|
|
20
|
+
"g++",
|
|
21
|
+
"go",
|
|
22
|
+
"rustc",
|
|
23
|
+
"cargo"
|
|
24
|
+
];
|
|
25
|
+
let cachedBinaries = null;
|
|
26
|
+
let inFlightPromise = null;
|
|
27
|
+
function resolveBinary(name) {
|
|
28
|
+
const command = process.platform === "win32" ? "where" : "which";
|
|
29
|
+
try {
|
|
30
|
+
return execFileSync(command, [name], {
|
|
31
|
+
encoding: "utf-8",
|
|
32
|
+
stdio: [
|
|
33
|
+
"pipe",
|
|
34
|
+
"pipe",
|
|
35
|
+
"pipe"
|
|
36
|
+
]
|
|
37
|
+
}).trim().split(/\r?\n/)[0] || null;
|
|
38
|
+
} catch {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function resolveBinaryAsync(name) {
|
|
43
|
+
const command = process.platform === "win32" ? "where" : "which";
|
|
44
|
+
return new Promise((resolve) => {
|
|
45
|
+
execFile(command, [name], { encoding: "utf-8" }, (err, stdout) => {
|
|
46
|
+
if (err) {
|
|
47
|
+
resolve(null);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
resolve(stdout.trim().split(/\r?\n/)[0] || null);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
function detectCommonBinaries() {
|
|
55
|
+
cachedBinaries ??= COMMON_BINARIES.map((name) => ({
|
|
56
|
+
name,
|
|
57
|
+
path: resolveBinary(name)
|
|
58
|
+
}));
|
|
59
|
+
return cachedBinaries;
|
|
60
|
+
}
|
|
61
|
+
async function detectCommonBinariesAsync() {
|
|
62
|
+
if (cachedBinaries) return cachedBinaries;
|
|
63
|
+
if (inFlightPromise) return inFlightPromise;
|
|
64
|
+
inFlightPromise = Promise.all(COMMON_BINARIES.map(async (name) => ({
|
|
65
|
+
name,
|
|
66
|
+
path: await resolveBinaryAsync(name)
|
|
67
|
+
})));
|
|
68
|
+
try {
|
|
69
|
+
cachedBinaries = await inFlightPromise;
|
|
70
|
+
return cachedBinaries;
|
|
71
|
+
} finally {
|
|
72
|
+
inFlightPromise = null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
//#endregion
|
|
76
|
+
export { detectCommonBinaries, detectCommonBinariesAsync };
|
|
77
|
+
|
|
78
|
+
//# sourceMappingURL=binaries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binaries.js","names":[],"sources":["../../src/utils/binaries.ts"],"sourcesContent":["import { execFile, execFileSync } from 'node:child_process';\n\nexport interface CommonBinary {\n name: string;\n path: string | null;\n}\n\nconst COMMON_BINARIES = [\n 'python',\n 'python3',\n 'node',\n 'npm',\n 'pnpm',\n 'yarn',\n 'bun',\n 'git',\n 'rg',\n 'fd',\n 'fdfind',\n 'curl',\n 'wget',\n 'docker',\n 'make',\n 'gcc',\n 'g++',\n 'go',\n 'rustc',\n 'cargo',\n] as const;\n\nlet cachedBinaries: CommonBinary[] | null = null;\nlet inFlightPromise: Promise<CommonBinary[]> | null = null;\n\nfunction resolveBinary(name: string): string | null {\n const command = process.platform === 'win32' ? 'where' : 'which';\n try {\n const output = execFileSync(command, [name], { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'] }).trim();\n return output.split(/\\r?\\n/)[0] || null;\n } catch {\n return null;\n }\n}\n\nfunction resolveBinaryAsync(name: string): Promise<string | null> {\n const command = process.platform === 'win32' ? 'where' : 'which';\n return new Promise(resolve => {\n execFile(command, [name], { encoding: 'utf-8' }, (err, stdout) => {\n if (err) {\n resolve(null);\n return;\n }\n resolve(stdout.trim().split(/\\r?\\n/)[0] || null);\n });\n });\n}\n\nexport function detectCommonBinaries(): CommonBinary[] {\n cachedBinaries ??= COMMON_BINARIES.map(name => ({\n name,\n path: resolveBinary(name),\n }));\n\n return cachedBinaries;\n}\n\nexport async function detectCommonBinariesAsync(): Promise<CommonBinary[]> {\n if (cachedBinaries) return cachedBinaries;\n if (inFlightPromise) return inFlightPromise;\n\n inFlightPromise = Promise.all(\n COMMON_BINARIES.map(async name => ({\n name,\n path: await resolveBinaryAsync(name),\n })),\n );\n\n try {\n cachedBinaries = await inFlightPromise;\n return cachedBinaries;\n } finally {\n inFlightPromise = null;\n }\n}\n"],"mappings":";;AAOA,MAAM,kBAAkB;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,IAAI,iBAAwC;AAC5C,IAAI,kBAAkD;AAEtD,SAAS,cAAc,MAA6B;CAClD,MAAM,UAAU,QAAQ,aAAa,UAAU,UAAU;CACzD,IAAI;EAEF,OADe,aAAa,SAAS,CAAC,IAAI,GAAG;GAAE,UAAU;GAAS,OAAO;IAAC;IAAQ;IAAQ;GAAM;EAAE,CAAC,CAAC,CAAC,KACzF,CAAC,CAAC,MAAM,OAAO,CAAC,CAAC,MAAM;CACrC,QAAQ;EACN,OAAO;CACT;AACF;AAEA,SAAS,mBAAmB,MAAsC;CAChE,MAAM,UAAU,QAAQ,aAAa,UAAU,UAAU;CACzD,OAAO,IAAI,SAAQ,YAAW;EAC5B,SAAS,SAAS,CAAC,IAAI,GAAG,EAAE,UAAU,QAAQ,IAAI,KAAK,WAAW;GAChE,IAAI,KAAK;IACP,QAAQ,IAAI;IACZ;GACF;GACA,QAAQ,OAAO,KAAK,CAAC,CAAC,MAAM,OAAO,CAAC,CAAC,MAAM,IAAI;EACjD,CAAC;CACH,CAAC;AACH;AAEA,SAAgB,uBAAuC;CACrD,mBAAmB,gBAAgB,KAAI,UAAS;EAC9C;EACA,MAAM,cAAc,IAAI;CAC1B,EAAE;CAEF,OAAO;AACT;AAEA,eAAsB,4BAAqD;CACzE,IAAI,gBAAgB,OAAO;CAC3B,IAAI,iBAAiB,OAAO;CAE5B,kBAAkB,QAAQ,IACxB,gBAAgB,IAAI,OAAM,UAAS;EACjC;EACA,MAAM,MAAM,mBAAmB,IAAI;CACrC,EAAE,CACJ;CAEA,IAAI;EACF,iBAAiB,MAAM;EACvB,OAAO;CACT,UAAU;EACR,kBAAkB;CACpB;AACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Truncate a log file to roughly {@link KEEP_SIZE} bytes if it exceeds
|
|
3
|
+
* {@link MAX_LOG_SIZE}, cutting at the first newline so we don't start mid-line.
|
|
4
|
+
*/
|
|
5
|
+
export declare function truncateLogFile(logFile: string): void;
|
|
6
|
+
/**
|
|
7
|
+
* Set up debug logging. When {@link MASTRA_DEBUG} is `"true"`, redirects
|
|
8
|
+
* `console.error` and `console.warn` to a log file (truncating it first if
|
|
9
|
+
* oversized). Otherwise silences them to avoid corrupting the TUI.
|
|
10
|
+
*/
|
|
11
|
+
export declare function setupDebugLogging(): void;
|
|
12
|
+
//# sourceMappingURL=debug-log.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug-log.d.ts","sourceRoot":"","sources":["../../src/utils/debug-log.ts"],"names":[],"mappings":"AAQA;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAerD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CA4BxC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { getAppDataDir } from "./project.js";
|
|
2
|
+
import * as fs$1 from "fs";
|
|
3
|
+
import * as path$1 from "path";
|
|
4
|
+
//#region src/utils/debug-log.ts
|
|
5
|
+
const MAX_LOG_SIZE = 5 * 1024 * 1024;
|
|
6
|
+
const KEEP_SIZE = 4 * 1024 * 1024;
|
|
7
|
+
/**
|
|
8
|
+
* Truncate a log file to roughly {@link KEEP_SIZE} bytes if it exceeds
|
|
9
|
+
* {@link MAX_LOG_SIZE}, cutting at the first newline so we don't start mid-line.
|
|
10
|
+
*/
|
|
11
|
+
function truncateLogFile(logFile) {
|
|
12
|
+
try {
|
|
13
|
+
const stat = fs$1.statSync(logFile);
|
|
14
|
+
if (stat.size > MAX_LOG_SIZE) {
|
|
15
|
+
const buf = Buffer.alloc(KEEP_SIZE);
|
|
16
|
+
const fd = fs$1.openSync(logFile, "r");
|
|
17
|
+
fs$1.readSync(fd, buf, 0, KEEP_SIZE, stat.size - KEEP_SIZE);
|
|
18
|
+
fs$1.closeSync(fd);
|
|
19
|
+
const firstNewline = buf.indexOf(10);
|
|
20
|
+
const trimmed = firstNewline >= 0 ? buf.subarray(firstNewline + 1) : buf;
|
|
21
|
+
fs$1.writeFileSync(logFile, trimmed);
|
|
22
|
+
}
|
|
23
|
+
} catch {}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Set up debug logging. When {@link MASTRA_DEBUG} is `"true"`, redirects
|
|
27
|
+
* `console.error` and `console.warn` to a log file (truncating it first if
|
|
28
|
+
* oversized). Otherwise silences them to avoid corrupting the TUI.
|
|
29
|
+
*/
|
|
30
|
+
function setupDebugLogging() {
|
|
31
|
+
if (["true", "1"].includes(process.env.MASTRA_DEBUG ?? "")) {
|
|
32
|
+
const logFile = path$1.join(getAppDataDir(), "debug.log");
|
|
33
|
+
truncateLogFile(logFile);
|
|
34
|
+
const logStream = fs$1.createWriteStream(logFile, { flags: "a" });
|
|
35
|
+
const fmt = (a) => {
|
|
36
|
+
if (typeof a === "string") return a;
|
|
37
|
+
if (a instanceof Error) return a.stack ?? `${a.name}: ${a.message}`;
|
|
38
|
+
try {
|
|
39
|
+
return JSON.stringify(a);
|
|
40
|
+
} catch {
|
|
41
|
+
return String(a);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
console.error = (...args) => {
|
|
45
|
+
logStream.write(`[ERROR] ${(/* @__PURE__ */ new Date()).toISOString()} ${args.map(fmt).join(" ")}\n`);
|
|
46
|
+
};
|
|
47
|
+
console.warn = (...args) => {
|
|
48
|
+
logStream.write(`[WARN] ${(/* @__PURE__ */ new Date()).toISOString()} ${args.map(fmt).join(" ")}\n`);
|
|
49
|
+
};
|
|
50
|
+
} else {
|
|
51
|
+
const noop = () => {};
|
|
52
|
+
console.error = noop;
|
|
53
|
+
console.warn = noop;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
export { setupDebugLogging, truncateLogFile };
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=debug-log.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug-log.js","names":["fs","path"],"sources":["../../src/utils/debug-log.ts"],"sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\n\nimport { getAppDataDir } from './project.js';\n\nconst MAX_LOG_SIZE = 5 * 1024 * 1024; // 5 MB\nconst KEEP_SIZE = 4 * 1024 * 1024; // 4 MB\n\n/**\n * Truncate a log file to roughly {@link KEEP_SIZE} bytes if it exceeds\n * {@link MAX_LOG_SIZE}, cutting at the first newline so we don't start mid-line.\n */\nexport function truncateLogFile(logFile: string): void {\n try {\n const stat = fs.statSync(logFile);\n if (stat.size > MAX_LOG_SIZE) {\n const buf = Buffer.alloc(KEEP_SIZE);\n const fd = fs.openSync(logFile, 'r');\n fs.readSync(fd, buf, 0, KEEP_SIZE, stat.size - KEEP_SIZE);\n fs.closeSync(fd);\n const firstNewline = buf.indexOf(10);\n const trimmed = firstNewline >= 0 ? buf.subarray(firstNewline + 1) : buf;\n fs.writeFileSync(logFile, trimmed);\n }\n } catch {\n // File may not exist yet — that's fine\n }\n}\n\n/**\n * Set up debug logging. When {@link MASTRA_DEBUG} is `\"true\"`, redirects\n * `console.error` and `console.warn` to a log file (truncating it first if\n * oversized). Otherwise silences them to avoid corrupting the TUI.\n */\nexport function setupDebugLogging(): void {\n const debugEnabled = ['true', '1'].includes(process.env.MASTRA_DEBUG ?? '');\n\n if (debugEnabled) {\n const logFile = path.join(getAppDataDir(), 'debug.log');\n truncateLogFile(logFile);\n\n const logStream = fs.createWriteStream(logFile, { flags: 'a' });\n const fmt = (a: unknown): string => {\n if (typeof a === 'string') return a;\n if (a instanceof Error) return a.stack ?? `${a.name}: ${a.message}`;\n try {\n return JSON.stringify(a);\n } catch {\n return String(a);\n }\n };\n console.error = (...args: unknown[]) => {\n logStream.write(`[ERROR] ${new Date().toISOString()} ${args.map(fmt).join(' ')}\\n`);\n };\n console.warn = (...args: unknown[]) => {\n logStream.write(`[WARN] ${new Date().toISOString()} ${args.map(fmt).join(' ')}\\n`);\n };\n } else {\n const noop = () => {};\n console.error = noop;\n console.warn = noop;\n }\n}\n"],"mappings":";;;;AAKA,MAAM,eAAe,IAAI,OAAO;AAChC,MAAM,YAAY,IAAI,OAAO;;;;;AAM7B,SAAgB,gBAAgB,SAAuB;CACrD,IAAI;EACF,MAAM,OAAOA,KAAG,SAAS,OAAO;EAChC,IAAI,KAAK,OAAO,cAAc;GAC5B,MAAM,MAAM,OAAO,MAAM,SAAS;GAClC,MAAM,KAAKA,KAAG,SAAS,SAAS,GAAG;GACnC,KAAG,SAAS,IAAI,KAAK,GAAG,WAAW,KAAK,OAAO,SAAS;GACxD,KAAG,UAAU,EAAE;GACf,MAAM,eAAe,IAAI,QAAQ,EAAE;GACnC,MAAM,UAAU,gBAAgB,IAAI,IAAI,SAAS,eAAe,CAAC,IAAI;GACrE,KAAG,cAAc,SAAS,OAAO;EACnC;CACF,QAAQ,CAER;AACF;;;;;;AAOA,SAAgB,oBAA0B;CAGxC,IAFqB,CAAC,QAAQ,GAAG,CAAC,CAAC,SAAS,QAAQ,IAAI,gBAAgB,EAEzD,GAAG;EAChB,MAAM,UAAUC,OAAK,KAAK,cAAc,GAAG,WAAW;EACtD,gBAAgB,OAAO;EAEvB,MAAM,YAAYD,KAAG,kBAAkB,SAAS,EAAE,OAAO,IAAI,CAAC;EAC9D,MAAM,OAAO,MAAuB;GAClC,IAAI,OAAO,MAAM,UAAU,OAAO;GAClC,IAAI,aAAa,OAAO,OAAO,EAAE,SAAS,GAAG,EAAE,KAAK,IAAI,EAAE;GAC1D,IAAI;IACF,OAAO,KAAK,UAAU,CAAC;GACzB,QAAQ;IACN,OAAO,OAAO,CAAC;GACjB;EACF;EACA,QAAQ,SAAS,GAAG,SAAoB;GACtC,UAAU,MAAM,4BAAW,IAAI,KAAK,EAAA,CAAE,YAAY,EAAE,GAAG,KAAK,IAAI,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE,GAAG;EACpF;EACA,QAAQ,QAAQ,GAAG,SAAoB;GACrC,UAAU,MAAM,2BAAU,IAAI,KAAK,EAAA,CAAE,YAAY,EAAE,GAAG,KAAK,IAAI,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE,GAAG;EACnF;CACF,OAAO;EACL,MAAM,aAAa,CAAC;EACpB,QAAQ,QAAQ;EAChB,QAAQ,OAAO;CACjB;AACF"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error handling utilities for the Mastra Code TUI.
|
|
3
|
+
* Parses API errors and provides user-friendly messages.
|
|
4
|
+
*/
|
|
5
|
+
export interface ParsedError {
|
|
6
|
+
/** User-friendly error message */
|
|
7
|
+
message: string;
|
|
8
|
+
/** Extra diagnostic detail to surface to the user */
|
|
9
|
+
detail?: string;
|
|
10
|
+
/** Request URL involved in the failure, when available */
|
|
11
|
+
requestUrl?: string;
|
|
12
|
+
/** Error type for categorization */
|
|
13
|
+
type: ErrorType;
|
|
14
|
+
/** Whether this error is retryable */
|
|
15
|
+
retryable: boolean;
|
|
16
|
+
/** Suggested retry delay in ms (if retryable) */
|
|
17
|
+
retryDelay?: number;
|
|
18
|
+
/** Original error for debugging */
|
|
19
|
+
originalError: Error;
|
|
20
|
+
}
|
|
21
|
+
export type ErrorType = 'rate_limit' | 'auth' | 'network' | 'timeout' | 'invalid_request' | 'server_error' | 'model_not_found' | 'context_length' | 'content_filter' | 'unknown';
|
|
22
|
+
export declare function parseError(error: unknown): ParsedError;
|
|
23
|
+
/**
|
|
24
|
+
* Sleep for a given number of milliseconds.
|
|
25
|
+
*/
|
|
26
|
+
export declare function sleep(ms: number): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Retry a function with exponential backoff.
|
|
29
|
+
*/
|
|
30
|
+
export declare function withRetry<T>(fn: () => Promise<T>, options?: {
|
|
31
|
+
maxRetries?: number;
|
|
32
|
+
initialDelay?: number;
|
|
33
|
+
maxDelay?: number;
|
|
34
|
+
onRetry?: (error: ParsedError, attempt: number) => void;
|
|
35
|
+
}): Promise<T>;
|
|
36
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,MAAM,WAAW,WAAW;IAC1B,kCAAkC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,0DAA0D;IAC1D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oCAAoC;IACpC,IAAI,EAAE,SAAS,CAAC;IAChB,sCAAsC;IACtC,SAAS,EAAE,OAAO,CAAC;IACnB,iDAAiD;IACjD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mCAAmC;IACnC,aAAa,EAAE,KAAK,CAAC;CACtB;AAED,MAAM,MAAM,SAAS,GACjB,YAAY,GACZ,MAAM,GACN,SAAS,GACT,SAAS,GACT,iBAAiB,GACjB,cAAc,GACd,iBAAiB,GACjB,gBAAgB,GAChB,gBAAgB,GAChB,SAAS,CAAC;AAiFd,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,CAqLtD;AAkDD;;GAEG;AACH,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C;AAED;;GAEG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAC/B,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,OAAO,GAAE;IACP,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACpD,GACL,OAAO,CAAC,CAAC,CAAC,CA6BZ"}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import "../auth/provider-auth-error.js";
|
|
2
|
+
//#region src/utils/errors.ts
|
|
3
|
+
/**
|
|
4
|
+
* Error handling utilities for the Mastra Code TUI.
|
|
5
|
+
* Parses API errors and provides user-friendly messages.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Parse an error and return a user-friendly representation.
|
|
9
|
+
*/
|
|
10
|
+
function summarizeErrorDetail(error) {
|
|
11
|
+
if (error instanceof Error) {
|
|
12
|
+
if (error.cause instanceof Error && error.cause.message) return error.cause.message;
|
|
13
|
+
if (typeof error.cause === "string" && error.cause.trim().length > 0) return error.cause;
|
|
14
|
+
if (error.message.trim().length > 0) return error.message;
|
|
15
|
+
}
|
|
16
|
+
if (typeof error === "string" && error.trim().length > 0) return error;
|
|
17
|
+
if (error && typeof error === "object") {
|
|
18
|
+
const errorObj = error;
|
|
19
|
+
const candidates = [
|
|
20
|
+
errorObj["message"],
|
|
21
|
+
errorObj["cause"],
|
|
22
|
+
errorObj["code"],
|
|
23
|
+
errorObj["statusText"]
|
|
24
|
+
];
|
|
25
|
+
for (const candidate of candidates) if (typeof candidate === "string" && candidate.trim().length > 0) return candidate;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function extractRequestUrl(error) {
|
|
29
|
+
if (!error || typeof error !== "object") return;
|
|
30
|
+
const candidates = [];
|
|
31
|
+
const errorObj = error;
|
|
32
|
+
candidates.push(errorObj["requestUrl"], errorObj["url"]);
|
|
33
|
+
if (errorObj["cause"] && typeof errorObj["cause"] === "object") {
|
|
34
|
+
const causeObj = errorObj["cause"];
|
|
35
|
+
candidates.push(causeObj["requestUrl"], causeObj["url"]);
|
|
36
|
+
}
|
|
37
|
+
for (const candidate of candidates) if (typeof candidate === "string" && candidate.trim().length > 0) return candidate;
|
|
38
|
+
}
|
|
39
|
+
/** A flattened error crossing the wire: the server sends `{ name, message }`, not an `Error`. */
|
|
40
|
+
function isSerializedError(value) {
|
|
41
|
+
return typeof value === "object" && value !== null && "name" in value && typeof value.name === "string" && "message" in value && typeof value.message === "string";
|
|
42
|
+
}
|
|
43
|
+
function toError(error) {
|
|
44
|
+
if (error instanceof Error) return error;
|
|
45
|
+
if (!isSerializedError(error)) return new Error(String(error));
|
|
46
|
+
const rebuilt = new Error(error.message);
|
|
47
|
+
rebuilt.name = error.name;
|
|
48
|
+
return rebuilt;
|
|
49
|
+
}
|
|
50
|
+
function parseError(error) {
|
|
51
|
+
const err = toError(error);
|
|
52
|
+
const message = err.message.toLowerCase();
|
|
53
|
+
const errorObj = error;
|
|
54
|
+
const detail = summarizeErrorDetail(error);
|
|
55
|
+
const requestUrl = extractRequestUrl(error);
|
|
56
|
+
if (err.name === "ProviderAuthRequiredError") return {
|
|
57
|
+
message: err.message,
|
|
58
|
+
detail,
|
|
59
|
+
requestUrl,
|
|
60
|
+
type: "auth",
|
|
61
|
+
retryable: false,
|
|
62
|
+
originalError: err
|
|
63
|
+
};
|
|
64
|
+
if (message.includes("rate limit") || message.includes("rate_limit") || message.includes("429") || errorObj.statusCode === 429 || errorObj.status === 429) return {
|
|
65
|
+
message: "Rate limited. Please wait a moment before trying again.",
|
|
66
|
+
type: "rate_limit",
|
|
67
|
+
retryable: true,
|
|
68
|
+
retryDelay: extractRetryAfter(errorObj) || 5e3,
|
|
69
|
+
originalError: err
|
|
70
|
+
};
|
|
71
|
+
if (message.includes("unauthorized") || message.includes("authentication") || message.includes("invalid api key") || message.includes("invalid_api_key") || message.includes("api key") || errorObj.statusCode === 401 || errorObj.status === 401) return {
|
|
72
|
+
message: "Authentication failed. Check the credential configured for this provider.",
|
|
73
|
+
detail,
|
|
74
|
+
requestUrl,
|
|
75
|
+
type: "auth",
|
|
76
|
+
retryable: false,
|
|
77
|
+
originalError: err
|
|
78
|
+
};
|
|
79
|
+
if (errorObj.statusCode === 403 || errorObj.status === 403) return {
|
|
80
|
+
message: "Access denied. You may not have permission to use this model.",
|
|
81
|
+
detail,
|
|
82
|
+
requestUrl,
|
|
83
|
+
type: "auth",
|
|
84
|
+
retryable: false,
|
|
85
|
+
originalError: err
|
|
86
|
+
};
|
|
87
|
+
if (message.includes("network") || message.includes("econnrefused") || message.includes("enotfound") || message.includes("fetch failed") || message.includes("connection")) return {
|
|
88
|
+
message: "Network error while contacting the provider or gateway.",
|
|
89
|
+
detail,
|
|
90
|
+
requestUrl,
|
|
91
|
+
type: "network",
|
|
92
|
+
retryable: true,
|
|
93
|
+
retryDelay: 2e3,
|
|
94
|
+
originalError: err
|
|
95
|
+
};
|
|
96
|
+
if (message.includes("timeout") || message.includes("timed out") || message.includes("etimedout")) return {
|
|
97
|
+
message: "Request timed out. The server may be overloaded.",
|
|
98
|
+
type: "timeout",
|
|
99
|
+
retryable: true,
|
|
100
|
+
retryDelay: 3e3,
|
|
101
|
+
originalError: err
|
|
102
|
+
};
|
|
103
|
+
if (message.includes("model not found") || message.includes("model_not_found") || message.includes("does not exist") || message.includes("invalid model")) return {
|
|
104
|
+
message: "Model not found. Please select a different model with /models.",
|
|
105
|
+
type: "model_not_found",
|
|
106
|
+
retryable: false,
|
|
107
|
+
originalError: err
|
|
108
|
+
};
|
|
109
|
+
if (message.includes("context length") || message.includes("context_length") || message.includes("too many tokens") || message.includes("maximum context") || message.includes("token limit")) return {
|
|
110
|
+
message: "Message too long. Try starting a new thread with /new.",
|
|
111
|
+
type: "context_length",
|
|
112
|
+
retryable: false,
|
|
113
|
+
originalError: err
|
|
114
|
+
};
|
|
115
|
+
if (message.includes("content filter") || message.includes("content_filter") || message.includes("content policy") || message.includes("safety") || message.includes("prohibited")) return {
|
|
116
|
+
message: "Content was filtered by the model's safety system.",
|
|
117
|
+
type: "content_filter",
|
|
118
|
+
retryable: false,
|
|
119
|
+
originalError: err
|
|
120
|
+
};
|
|
121
|
+
if (message.includes("internal server") || message.includes("server error") || errorObj.statusCode === 500 || errorObj.status === 500 || errorObj.statusCode === 502 || errorObj.status === 502 || errorObj.statusCode === 503 || errorObj.status === 503) return {
|
|
122
|
+
message: "Server error. The API may be experiencing issues.",
|
|
123
|
+
type: "server_error",
|
|
124
|
+
retryable: true,
|
|
125
|
+
retryDelay: 5e3,
|
|
126
|
+
originalError: err
|
|
127
|
+
};
|
|
128
|
+
if (message.includes("invalid request") || message.includes("bad request") || errorObj.statusCode === 400 || errorObj.status === 400) return {
|
|
129
|
+
message: `Invalid request: ${extractErrorDetail(err)}`,
|
|
130
|
+
type: "invalid_request",
|
|
131
|
+
retryable: false,
|
|
132
|
+
originalError: err
|
|
133
|
+
};
|
|
134
|
+
return {
|
|
135
|
+
message: extractErrorDetail(err),
|
|
136
|
+
type: "unknown",
|
|
137
|
+
retryable: false,
|
|
138
|
+
originalError: err
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Extract retry-after header value from error.
|
|
143
|
+
*/
|
|
144
|
+
function extractRetryAfter(error) {
|
|
145
|
+
const headers = error.headers;
|
|
146
|
+
const retryAfter = error.retryAfter || headers?.["retry-after"];
|
|
147
|
+
if (typeof retryAfter === "number") return retryAfter * 1e3;
|
|
148
|
+
if (typeof retryAfter === "string") {
|
|
149
|
+
const seconds = parseInt(retryAfter, 10);
|
|
150
|
+
if (!isNaN(seconds)) return seconds * 1e3;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Extract a useful error detail from an error object.
|
|
155
|
+
*/
|
|
156
|
+
function extractErrorDetail(error) {
|
|
157
|
+
const errorObj = error;
|
|
158
|
+
if (errorObj.error && typeof errorObj.error === "object") {
|
|
159
|
+
const apiError = errorObj.error;
|
|
160
|
+
if (apiError.message) return String(apiError.message);
|
|
161
|
+
}
|
|
162
|
+
if (errorObj.message) return String(errorObj.message);
|
|
163
|
+
if (errorObj.detail) return String(errorObj.detail);
|
|
164
|
+
if (errorObj.reason) return String(errorObj.reason);
|
|
165
|
+
let message = error.message;
|
|
166
|
+
message = message.replace(/^(error|exception|failed):\s*/i, "");
|
|
167
|
+
if (message.length > 200) message = message.substring(0, 200) + "...";
|
|
168
|
+
return message || "An unknown error occurred";
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Sleep for a given number of milliseconds.
|
|
172
|
+
*/
|
|
173
|
+
function sleep(ms) {
|
|
174
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Retry a function with exponential backoff.
|
|
178
|
+
*/
|
|
179
|
+
async function withRetry(fn, options = {}) {
|
|
180
|
+
const { maxRetries = 3, initialDelay = 1e3, maxDelay = 3e4, onRetry } = options;
|
|
181
|
+
let lastError;
|
|
182
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) try {
|
|
183
|
+
return await fn();
|
|
184
|
+
} catch (error) {
|
|
185
|
+
lastError = parseError(error);
|
|
186
|
+
if (!lastError.retryable || attempt === maxRetries) throw lastError.originalError;
|
|
187
|
+
const delay = Math.min(lastError.retryDelay || initialDelay * Math.pow(2, attempt), maxDelay);
|
|
188
|
+
if (onRetry) onRetry(lastError, attempt + 1);
|
|
189
|
+
await sleep(delay);
|
|
190
|
+
}
|
|
191
|
+
throw lastError?.originalError || /* @__PURE__ */ new Error("Retry failed");
|
|
192
|
+
}
|
|
193
|
+
//#endregion
|
|
194
|
+
export { parseError, sleep, withRetry };
|
|
195
|
+
|
|
196
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","names":[],"sources":["../../src/utils/errors.ts"],"sourcesContent":["/**\n * Error handling utilities for the Mastra Code TUI.\n * Parses API errors and provides user-friendly messages.\n */\n\nimport { PROVIDER_AUTH_REQUIRED_ERROR } from '../auth/provider-auth-error.js';\n\nexport interface ParsedError {\n /** User-friendly error message */\n message: string;\n /** Extra diagnostic detail to surface to the user */\n detail?: string;\n /** Request URL involved in the failure, when available */\n requestUrl?: string;\n /** Error type for categorization */\n type: ErrorType;\n /** Whether this error is retryable */\n retryable: boolean;\n /** Suggested retry delay in ms (if retryable) */\n retryDelay?: number;\n /** Original error for debugging */\n originalError: Error;\n}\n\nexport type ErrorType =\n | 'rate_limit'\n | 'auth'\n | 'network'\n | 'timeout'\n | 'invalid_request'\n | 'server_error'\n | 'model_not_found'\n | 'context_length'\n | 'content_filter'\n | 'unknown';\n\n/**\n * Parse an error and return a user-friendly representation.\n */\nfunction summarizeErrorDetail(error: unknown): string | undefined {\n if (error instanceof Error) {\n if (error.cause instanceof Error && error.cause.message) {\n return error.cause.message;\n }\n\n if (typeof error.cause === 'string' && error.cause.trim().length > 0) {\n return error.cause;\n }\n\n if (error.message.trim().length > 0) {\n return error.message;\n }\n }\n\n if (typeof error === 'string' && error.trim().length > 0) {\n return error;\n }\n\n if (error && typeof error === 'object') {\n const errorObj = error as Record<string, unknown>;\n const candidates = [errorObj['message'], errorObj['cause'], errorObj['code'], errorObj['statusText']];\n\n for (const candidate of candidates) {\n if (typeof candidate === 'string' && candidate.trim().length > 0) {\n return candidate;\n }\n }\n }\n\n return undefined;\n}\n\nfunction extractRequestUrl(error: unknown): string | undefined {\n if (!error || typeof error !== 'object') {\n return undefined;\n }\n\n const candidates: unknown[] = [];\n const errorObj = error as Record<string, unknown>;\n candidates.push(errorObj['requestUrl'], errorObj['url']);\n\n if (errorObj['cause'] && typeof errorObj['cause'] === 'object') {\n const causeObj = errorObj['cause'] as Record<string, unknown>;\n candidates.push(causeObj['requestUrl'], causeObj['url']);\n }\n\n for (const candidate of candidates) {\n if (typeof candidate === 'string' && candidate.trim().length > 0) {\n return candidate;\n }\n }\n\n return undefined;\n}\n\n/** A flattened error crossing the wire: the server sends `{ name, message }`, not an `Error`. */\nfunction isSerializedError(value: unknown): value is { name: string; message: string } {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'name' in value &&\n typeof value.name === 'string' &&\n 'message' in value &&\n typeof value.message === 'string'\n );\n}\n\nfunction toError(error: unknown): Error {\n if (error instanceof Error) return error;\n if (!isSerializedError(error)) return new Error(String(error));\n const rebuilt = new Error(error.message);\n rebuilt.name = error.name;\n return rebuilt;\n}\n\nexport function parseError(error: unknown): ParsedError {\n const err = toError(error);\n const message = err.message.toLowerCase();\n const errorObj = error as Record<string, unknown>;\n const detail = summarizeErrorDetail(error);\n const requestUrl = extractRequestUrl(error);\n\n // Matched by name, not instance: the error may have crossed a serialization boundary.\n if (err.name === PROVIDER_AUTH_REQUIRED_ERROR) {\n return { message: err.message, detail, requestUrl, type: 'auth', retryable: false, originalError: err };\n }\n\n // Check for rate limiting\n if (\n message.includes('rate limit') ||\n message.includes('rate_limit') ||\n message.includes('429') ||\n errorObj.statusCode === 429 ||\n errorObj.status === 429\n ) {\n const retryAfter = extractRetryAfter(errorObj);\n return {\n message: 'Rate limited. Please wait a moment before trying again.',\n type: 'rate_limit',\n retryable: true,\n retryDelay: retryAfter || 5000,\n originalError: err,\n };\n }\n\n // Check for authentication errors\n if (\n message.includes('unauthorized') ||\n message.includes('authentication') ||\n message.includes('invalid api key') ||\n message.includes('invalid_api_key') ||\n message.includes('api key') ||\n errorObj.statusCode === 401 ||\n errorObj.status === 401\n ) {\n return {\n message: 'Authentication failed. Check the credential configured for this provider.',\n detail,\n requestUrl,\n type: 'auth',\n retryable: false,\n originalError: err,\n };\n }\n\n // Check for forbidden/permission errors\n if (errorObj.statusCode === 403 || errorObj.status === 403) {\n return {\n message: 'Access denied. You may not have permission to use this model.',\n detail,\n requestUrl,\n type: 'auth',\n retryable: false,\n originalError: err,\n };\n }\n\n // Check for network errors\n if (\n message.includes('network') ||\n message.includes('econnrefused') ||\n message.includes('enotfound') ||\n message.includes('fetch failed') ||\n message.includes('connection')\n ) {\n return {\n message: 'Network error while contacting the provider or gateway.',\n detail,\n requestUrl,\n type: 'network',\n retryable: true,\n retryDelay: 2000,\n originalError: err,\n };\n }\n\n // Check for timeout errors\n if (message.includes('timeout') || message.includes('timed out') || message.includes('etimedout')) {\n return {\n message: 'Request timed out. The server may be overloaded.',\n type: 'timeout',\n retryable: true,\n retryDelay: 3000,\n originalError: err,\n };\n }\n\n // Check for model not found\n if (\n message.includes('model not found') ||\n message.includes('model_not_found') ||\n message.includes('does not exist') ||\n message.includes('invalid model')\n ) {\n return {\n message: 'Model not found. Please select a different model with /models.',\n type: 'model_not_found',\n retryable: false,\n originalError: err,\n };\n }\n\n // Check for context length errors\n if (\n message.includes('context length') ||\n message.includes('context_length') ||\n message.includes('too many tokens') ||\n message.includes('maximum context') ||\n message.includes('token limit')\n ) {\n return {\n message: 'Message too long. Try starting a new thread with /new.',\n type: 'context_length',\n retryable: false,\n originalError: err,\n };\n }\n\n // Check for content filter errors\n if (\n message.includes('content filter') ||\n message.includes('content_filter') ||\n message.includes('content policy') ||\n message.includes('safety') ||\n message.includes('prohibited')\n ) {\n return {\n message: \"Content was filtered by the model's safety system.\",\n type: 'content_filter',\n retryable: false,\n originalError: err,\n };\n }\n\n // Check for server errors\n if (\n message.includes('internal server') ||\n message.includes('server error') ||\n errorObj.statusCode === 500 ||\n errorObj.status === 500 ||\n errorObj.statusCode === 502 ||\n errorObj.status === 502 ||\n errorObj.statusCode === 503 ||\n errorObj.status === 503\n ) {\n return {\n message: 'Server error. The API may be experiencing issues.',\n type: 'server_error',\n retryable: true,\n retryDelay: 5000,\n originalError: err,\n };\n }\n\n // Check for invalid request errors\n if (\n message.includes('invalid request') ||\n message.includes('bad request') ||\n errorObj.statusCode === 400 ||\n errorObj.status === 400\n ) {\n return {\n message: `Invalid request: ${extractErrorDetail(err)}`,\n type: 'invalid_request',\n retryable: false,\n originalError: err,\n };\n }\n\n // Unknown error - try to extract useful info\n return {\n message: extractErrorDetail(err),\n type: 'unknown',\n retryable: false,\n originalError: err,\n };\n}\n\n/**\n * Extract retry-after header value from error.\n */\nfunction extractRetryAfter(error: Record<string, unknown>): number | undefined {\n const headers = error.headers as Record<string, unknown> | undefined;\n const retryAfter = error.retryAfter || headers?.['retry-after'];\n if (typeof retryAfter === 'number') {\n return retryAfter * 1000; // Convert seconds to ms\n }\n if (typeof retryAfter === 'string') {\n const seconds = parseInt(retryAfter, 10);\n if (!isNaN(seconds)) {\n return seconds * 1000;\n }\n }\n return undefined;\n}\n\n/**\n * Extract a useful error detail from an error object.\n */\nfunction extractErrorDetail(error: Error): string {\n const errorObj = error as unknown as Record<string, unknown>;\n\n // Try to get a specific error message from common API error formats\n if (errorObj.error && typeof errorObj.error === 'object') {\n const apiError = errorObj.error as Record<string, unknown>;\n if (apiError.message) return String(apiError.message);\n }\n\n if (errorObj.message) return String(errorObj.message);\n if (errorObj.detail) return String(errorObj.detail);\n if (errorObj.reason) return String(errorObj.reason);\n\n // Clean up the error message\n let message = error.message;\n\n // Remove common prefixes\n message = message.replace(/^(error|exception|failed):\\s*/i, '');\n\n // Truncate very long messages\n if (message.length > 200) {\n message = message.substring(0, 200) + '...';\n }\n\n return message || 'An unknown error occurred';\n}\n\n/**\n * Sleep for a given number of milliseconds.\n */\nexport function sleep(ms: number): Promise<void> {\n return new Promise(resolve => setTimeout(resolve, ms));\n}\n\n/**\n * Retry a function with exponential backoff.\n */\nexport async function withRetry<T>(\n fn: () => Promise<T>,\n options: {\n maxRetries?: number;\n initialDelay?: number;\n maxDelay?: number;\n onRetry?: (error: ParsedError, attempt: number) => void;\n } = {},\n): Promise<T> {\n const { maxRetries = 3, initialDelay = 1000, maxDelay = 30000, onRetry } = options;\n\n let lastError: ParsedError | undefined;\n\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n try {\n return await fn();\n } catch (error) {\n lastError = parseError(error);\n\n // Don't retry non-retryable errors\n if (!lastError.retryable || attempt === maxRetries) {\n throw lastError.originalError;\n }\n\n // Calculate delay with exponential backoff\n const delay = Math.min(lastError.retryDelay || initialDelay * Math.pow(2, attempt), maxDelay);\n\n if (onRetry) {\n onRetry(lastError, attempt + 1);\n }\n\n await sleep(delay);\n }\n }\n\n // Should never reach here, but TypeScript needs this\n throw lastError?.originalError || new Error('Retry failed');\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gateway sync utility for keeping the model registry up to date.
|
|
3
|
+
*
|
|
4
|
+
* This is a thin wrapper around `@mastra/core/llm`'s `GatewayRegistry` so
|
|
5
|
+
* mastracode and `mastra dev` share a single implementation for fetching
|
|
6
|
+
* providers, generating types, and writing to the global cache. Keep this
|
|
7
|
+
* file small — provider/registry logic belongs in `@mastra/core`.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Sync gateways and update the global cache via `@mastra/core`'s registry.
|
|
11
|
+
*
|
|
12
|
+
* Skips the sync if the global cache was refreshed within the last
|
|
13
|
+
* `DEFAULT_SYNC_INTERVAL_MS`, unless `force` is set. Multiple calls in
|
|
14
|
+
* the same process coalesce while a sync is in flight.
|
|
15
|
+
*/
|
|
16
|
+
export declare function syncGateways(force?: boolean): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Start periodic gateway sync.
|
|
19
|
+
* @param intervalMs Sync interval in milliseconds (default: 5 minutes)
|
|
20
|
+
*/
|
|
21
|
+
export declare function startGatewaySync(intervalMs?: number): void;
|
|
22
|
+
/**
|
|
23
|
+
* Stop periodic gateway sync.
|
|
24
|
+
*/
|
|
25
|
+
export declare function stopGatewaySync(): void;
|
|
26
|
+
//# sourceMappingURL=gateway-sync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway-sync.d.ts","sourceRoot":"","sources":["../../src/utils/gateway-sync.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAaH;;;;;;GAMG;AACH,wBAAsB,YAAY,CAAC,KAAK,UAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAqB/D;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,SAA2B,GAAG,IAAI,CAe5E;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,IAAI,CAKtC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { GatewayRegistry } from "@mastra/core/llm";
|
|
2
|
+
//#region src/utils/gateway-sync.ts
|
|
3
|
+
/**
|
|
4
|
+
* Gateway sync utility for keeping the model registry up to date.
|
|
5
|
+
*
|
|
6
|
+
* This is a thin wrapper around `@mastra/core/llm`'s `GatewayRegistry` so
|
|
7
|
+
* mastracode and `mastra dev` share a single implementation for fetching
|
|
8
|
+
* providers, generating types, and writing to the global cache. Keep this
|
|
9
|
+
* file small — provider/registry logic belongs in `@mastra/core`.
|
|
10
|
+
*/
|
|
11
|
+
const DEFAULT_SYNC_INTERVAL_MS = 300 * 1e3;
|
|
12
|
+
let syncInterval = null;
|
|
13
|
+
let isSyncing = false;
|
|
14
|
+
function getRegistry() {
|
|
15
|
+
return GatewayRegistry.getInstance({ useDynamicLoading: true });
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Sync gateways and update the global cache via `@mastra/core`'s registry.
|
|
19
|
+
*
|
|
20
|
+
* Skips the sync if the global cache was refreshed within the last
|
|
21
|
+
* `DEFAULT_SYNC_INTERVAL_MS`, unless `force` is set. Multiple calls in
|
|
22
|
+
* the same process coalesce while a sync is in flight.
|
|
23
|
+
*/
|
|
24
|
+
async function syncGateways(force = false) {
|
|
25
|
+
if (isSyncing && !force) return;
|
|
26
|
+
if (!force) {
|
|
27
|
+
const lastSync = getRegistry().getLastRefreshTime();
|
|
28
|
+
if (lastSync && Date.now() - lastSync.getTime() < DEFAULT_SYNC_INTERVAL_MS) return;
|
|
29
|
+
}
|
|
30
|
+
isSyncing = true;
|
|
31
|
+
try {
|
|
32
|
+
await getRegistry().syncGateways(true);
|
|
33
|
+
} catch {} finally {
|
|
34
|
+
isSyncing = false;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Start periodic gateway sync.
|
|
39
|
+
* @param intervalMs Sync interval in milliseconds (default: 5 minutes)
|
|
40
|
+
*/
|
|
41
|
+
function startGatewaySync(intervalMs = DEFAULT_SYNC_INTERVAL_MS) {
|
|
42
|
+
if (syncInterval) return;
|
|
43
|
+
syncGateways().catch(() => {});
|
|
44
|
+
syncInterval = setInterval(() => {
|
|
45
|
+
syncGateways().catch(() => {});
|
|
46
|
+
}, intervalMs);
|
|
47
|
+
syncInterval.unref();
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Stop periodic gateway sync.
|
|
51
|
+
*/
|
|
52
|
+
function stopGatewaySync() {
|
|
53
|
+
if (syncInterval) {
|
|
54
|
+
clearInterval(syncInterval);
|
|
55
|
+
syncInterval = null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
export { startGatewaySync, stopGatewaySync, syncGateways };
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=gateway-sync.js.map
|