@mastra/code-sdk 0.0.0-aggregate-trace-20261015182851
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +32 -0
- package/README.md +284 -0
- package/dist/acp/agent.d.ts +48 -0
- package/dist/acp/agent.d.ts.map +1 -0
- package/dist/acp/agent.js +416 -0
- package/dist/acp/agent.js.map +1 -0
- package/dist/acp/errors.d.ts +3 -0
- package/dist/acp/errors.d.ts.map +1 -0
- package/dist/acp/errors.js +14 -0
- package/dist/acp/errors.js.map +1 -0
- package/dist/acp/event-mapper.d.ts +28 -0
- package/dist/acp/event-mapper.d.ts.map +1 -0
- package/dist/acp/event-mapper.js +279 -0
- package/dist/acp/event-mapper.js.map +1 -0
- package/dist/acp/index.d.ts +9 -0
- package/dist/acp/index.d.ts.map +1 -0
- package/dist/acp/index.js +24 -0
- package/dist/acp/index.js.map +1 -0
- package/dist/acp/runtime.d.ts +5 -0
- package/dist/acp/runtime.d.ts.map +1 -0
- package/dist/acp/runtime.js +91 -0
- package/dist/acp/runtime.js.map +1 -0
- package/dist/acp/server.d.ts +4 -0
- package/dist/acp/server.d.ts.map +1 -0
- package/dist/acp/server.js +38 -0
- package/dist/acp/server.js.map +1 -0
- package/dist/acp/skills.d.ts +6 -0
- package/dist/acp/skills.d.ts.map +1 -0
- package/dist/acp/skills.js +33 -0
- package/dist/acp/skills.js.map +1 -0
- package/dist/acp.d.ts +2 -0
- package/dist/acp.d.ts.map +1 -0
- package/dist/acp.js +2 -0
- package/dist/agent-connections/messaging-processor.d.ts +17 -0
- package/dist/agent-connections/messaging-processor.d.ts.map +1 -0
- package/dist/agent-connections/messaging-processor.js +134 -0
- package/dist/agent-connections/messaging-processor.js.map +1 -0
- package/dist/agent-connections/ownership.d.ts +24 -0
- package/dist/agent-connections/ownership.d.ts.map +1 -0
- package/dist/agent-connections/ownership.js +99 -0
- package/dist/agent-connections/ownership.js.map +1 -0
- package/dist/agent-connections/registry.d.ts +20 -0
- package/dist/agent-connections/registry.d.ts.map +1 -0
- package/dist/agent-connections/registry.js +170 -0
- package/dist/agent-connections/registry.js.map +1 -0
- package/dist/agent-connections/session-advertisement.d.ts +27 -0
- package/dist/agent-connections/session-advertisement.d.ts.map +1 -0
- package/dist/agent-connections/session-advertisement.js +89 -0
- package/dist/agent-connections/session-advertisement.js.map +1 -0
- package/dist/agent-connections/signal-provider.d.ts +141 -0
- package/dist/agent-connections/signal-provider.d.ts.map +1 -0
- package/dist/agent-connections/signal-provider.js +38 -0
- package/dist/agent-connections/signal-provider.js.map +1 -0
- package/dist/agent-connections/state-processor.d.ts +23 -0
- package/dist/agent-connections/state-processor.d.ts.map +1 -0
- package/dist/agent-connections/state-processor.js +273 -0
- package/dist/agent-connections/state-processor.js.map +1 -0
- package/dist/agent-connections/thread-state.d.ts +41 -0
- package/dist/agent-connections/thread-state.d.ts.map +1 -0
- package/dist/agent-connections/thread-state.js +160 -0
- package/dist/agent-connections/thread-state.js.map +1 -0
- package/dist/agent-connections/tools.d.ts +133 -0
- package/dist/agent-connections/tools.d.ts.map +1 -0
- package/dist/agent-connections/tools.js +552 -0
- package/dist/agent-connections/tools.js.map +1 -0
- package/dist/agent-connections/types.d.ts +99 -0
- package/dist/agent-connections/types.d.ts.map +1 -0
- package/dist/agent-connections/types.js +7 -0
- package/dist/agent-connections/types.js.map +1 -0
- package/dist/agent-connections/untrusted-text.d.ts +5 -0
- package/dist/agent-connections/untrusted-text.d.ts.map +1 -0
- package/dist/agent-connections/untrusted-text.js +22 -0
- package/dist/agent-connections/untrusted-text.js.map +1 -0
- package/dist/agents/background-completion-events.d.ts +16 -0
- package/dist/agents/background-completion-events.d.ts.map +1 -0
- package/dist/agents/background-completion-events.js +19 -0
- package/dist/agents/background-completion-events.js.map +1 -0
- package/dist/agents/background-completion.d.ts +9 -0
- package/dist/agents/background-completion.d.ts.map +1 -0
- package/dist/agents/background-completion.js +59 -0
- package/dist/agents/background-completion.js.map +1 -0
- package/dist/agents/context-audit.d.ts +84 -0
- package/dist/agents/context-audit.d.ts.map +1 -0
- package/dist/agents/context-audit.js +118 -0
- package/dist/agents/context-audit.js.map +1 -0
- package/dist/agents/credential-resolver.d.ts +67 -0
- package/dist/agents/credential-resolver.d.ts.map +1 -0
- package/dist/agents/credential-resolver.js +136 -0
- package/dist/agents/credential-resolver.js.map +1 -0
- package/dist/agents/custom-provider-source.d.ts +35 -0
- package/dist/agents/custom-provider-source.d.ts.map +1 -0
- package/dist/agents/custom-provider-source.js +25 -0
- package/dist/agents/custom-provider-source.js.map +1 -0
- package/dist/agents/instructions.d.ts +40 -0
- package/dist/agents/instructions.d.ts.map +1 -0
- package/dist/agents/instructions.js +63 -0
- package/dist/agents/instructions.js.map +1 -0
- package/dist/agents/mastracode-gateway.d.ts +76 -0
- package/dist/agents/mastracode-gateway.d.ts.map +1 -0
- package/dist/agents/mastracode-gateway.js +434 -0
- package/dist/agents/mastracode-gateway.js.map +1 -0
- package/dist/agents/memory.d.ts +39 -0
- package/dist/agents/memory.d.ts.map +1 -0
- package/dist/agents/memory.js +266 -0
- package/dist/agents/memory.js.map +1 -0
- package/dist/agents/model.d.ts +123 -0
- package/dist/agents/model.d.ts.map +1 -0
- package/dist/agents/model.js +295 -0
- package/dist/agents/model.js.map +1 -0
- package/dist/agents/modes/build.d.ts +12 -0
- package/dist/agents/modes/build.d.ts.map +1 -0
- package/dist/agents/modes/build.js +36 -0
- package/dist/agents/modes/build.js.map +1 -0
- package/dist/agents/modes/explore.d.ts +10 -0
- package/dist/agents/modes/explore.d.ts.map +1 -0
- package/dist/agents/modes/explore.js +28 -0
- package/dist/agents/modes/explore.js.map +1 -0
- package/dist/agents/modes/plan.d.ts +8 -0
- package/dist/agents/modes/plan.d.ts.map +1 -0
- package/dist/agents/modes/plan.js +46 -0
- package/dist/agents/modes/plan.js.map +1 -0
- package/dist/agents/prompts/agent-instructions.d.ts +99 -0
- package/dist/agents/prompts/agent-instructions.d.ts.map +1 -0
- package/dist/agents/prompts/agent-instructions.js +275 -0
- package/dist/agents/prompts/agent-instructions.js.map +1 -0
- package/dist/agents/prompts/build.d.ts +12 -0
- package/dist/agents/prompts/build.d.ts.map +1 -0
- package/dist/agents/prompts/build.js +76 -0
- package/dist/agents/prompts/build.js.map +1 -0
- package/dist/agents/prompts/fast.d.ts +5 -0
- package/dist/agents/prompts/fast.d.ts.map +1 -0
- package/dist/agents/prompts/fast.js +26 -0
- package/dist/agents/prompts/fast.js.map +1 -0
- package/dist/agents/prompts/index.d.ts +54 -0
- package/dist/agents/prompts/index.d.ts.map +1 -0
- package/dist/agents/prompts/index.js +127 -0
- package/dist/agents/prompts/index.js.map +1 -0
- package/dist/agents/prompts/model.d.ts +5 -0
- package/dist/agents/prompts/model.d.ts.map +1 -0
- package/dist/agents/prompts/model.js +23 -0
- package/dist/agents/prompts/model.js.map +1 -0
- package/dist/agents/prompts/plan.d.ts +8 -0
- package/dist/agents/prompts/plan.d.ts.map +1 -0
- package/dist/agents/prompts/plan.js +129 -0
- package/dist/agents/prompts/plan.js.map +1 -0
- package/dist/agents/prompts/tool-guidance.d.ts +18 -0
- package/dist/agents/prompts/tool-guidance.d.ts.map +1 -0
- package/dist/agents/prompts/tool-guidance.js +181 -0
- package/dist/agents/prompts/tool-guidance.js.map +1 -0
- package/dist/agents/sandbox-filesystem.d.ts +151 -0
- package/dist/agents/sandbox-filesystem.d.ts.map +1 -0
- package/dist/agents/sandbox-filesystem.js +581 -0
- package/dist/agents/sandbox-filesystem.js.map +1 -0
- package/dist/agents/subagents/execute.d.ts +3 -0
- package/dist/agents/subagents/execute.d.ts.map +1 -0
- package/dist/agents/subagents/execute.js +27 -0
- package/dist/agents/subagents/execute.js.map +1 -0
- package/dist/agents/subagents/explore.d.ts +3 -0
- package/dist/agents/subagents/explore.d.ts.map +1 -0
- package/dist/agents/subagents/explore.js +18 -0
- package/dist/agents/subagents/explore.js.map +1 -0
- package/dist/agents/subagents/plan.d.ts +3 -0
- package/dist/agents/subagents/plan.d.ts.map +1 -0
- package/dist/agents/subagents/plan.js +18 -0
- package/dist/agents/subagents/plan.js.map +1 -0
- package/dist/agents/thread-caveman-state.d.ts +17 -0
- package/dist/agents/thread-caveman-state.d.ts.map +1 -0
- package/dist/agents/thread-caveman-state.js +107 -0
- package/dist/agents/thread-caveman-state.js.map +1 -0
- package/dist/agents/tool-availability.d.ts +12 -0
- package/dist/agents/tool-availability.d.ts.map +1 -0
- package/dist/agents/tool-availability.js +129 -0
- package/dist/agents/tool-availability.js.map +1 -0
- package/dist/agents/tools.d.ts +37 -0
- package/dist/agents/tools.d.ts.map +1 -0
- package/dist/agents/tools.js +131 -0
- package/dist/agents/tools.js.map +1 -0
- package/dist/agents/workflow-builder-agent.d.ts +2 -0
- package/dist/agents/workflow-builder-agent.d.ts.map +1 -0
- package/dist/agents/workflow-builder-agent.js +82 -0
- package/dist/agents/workflow-builder-agent.js.map +1 -0
- package/dist/agents/workspace.d.ts +33 -0
- package/dist/agents/workspace.d.ts.map +1 -0
- package/dist/agents/workspace.js +208 -0
- package/dist/agents/workspace.js.map +1 -0
- package/dist/analytics.d.ts +18 -0
- package/dist/analytics.d.ts.map +1 -0
- package/dist/analytics.js +162 -0
- package/dist/analytics.js.map +1 -0
- package/dist/auth/account-rotation-processor.d.ts +182 -0
- package/dist/auth/account-rotation-processor.d.ts.map +1 -0
- package/dist/auth/account-rotation-processor.js +609 -0
- package/dist/auth/account-rotation-processor.js.map +1 -0
- package/dist/auth/account-routing-context.d.ts +13 -0
- package/dist/auth/account-routing-context.d.ts.map +1 -0
- package/dist/auth/account-routing-context.js +41 -0
- package/dist/auth/account-routing-context.js.map +1 -0
- package/dist/auth/authorization-input.d.ts +16 -0
- package/dist/auth/authorization-input.d.ts.map +1 -0
- package/dist/auth/authorization-input.js +42 -0
- package/dist/auth/authorization-input.js.map +1 -0
- package/dist/auth/device-code.d.ts +93 -0
- package/dist/auth/device-code.d.ts.map +1 -0
- package/dist/auth/device-code.js +129 -0
- package/dist/auth/device-code.js.map +1 -0
- package/dist/auth/index.d.ts +13 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +9 -0
- package/dist/auth/pkce.d.ts +13 -0
- package/dist/auth/pkce.d.ts.map +1 -0
- package/dist/auth/pkce.js +32 -0
- package/dist/auth/pkce.js.map +1 -0
- package/dist/auth/provider-auth-error.d.ts +12 -0
- package/dist/auth/provider-auth-error.d.ts.map +1 -0
- package/dist/auth/provider-auth-error.js +16 -0
- package/dist/auth/provider-auth-error.js.map +1 -0
- package/dist/auth/providers/anthropic.d.ts +40 -0
- package/dist/auth/providers/anthropic.d.ts.map +1 -0
- package/dist/auth/providers/anthropic.js +120 -0
- package/dist/auth/providers/anthropic.js.map +1 -0
- package/dist/auth/providers/github-copilot.d.ts +154 -0
- package/dist/auth/providers/github-copilot.d.ts.map +1 -0
- package/dist/auth/providers/github-copilot.js +362 -0
- package/dist/auth/providers/github-copilot.js.map +1 -0
- package/dist/auth/providers/kimi-coding.d.ts +38 -0
- package/dist/auth/providers/kimi-coding.d.ts.map +1 -0
- package/dist/auth/providers/kimi-coding.js +228 -0
- package/dist/auth/providers/kimi-coding.js.map +1 -0
- package/dist/auth/providers/openai-codex.d.ts +141 -0
- package/dist/auth/providers/openai-codex.d.ts.map +1 -0
- package/dist/auth/providers/openai-codex.js +533 -0
- package/dist/auth/providers/openai-codex.js.map +1 -0
- package/dist/auth/providers/xai.d.ts +64 -0
- package/dist/auth/providers/xai.d.ts.map +1 -0
- package/dist/auth/providers/xai.js +226 -0
- package/dist/auth/providers/xai.js.map +1 -0
- package/dist/auth/storage.d.ts +214 -0
- package/dist/auth/storage.d.ts.map +1 -0
- package/dist/auth/storage.js +774 -0
- package/dist/auth/storage.js.map +1 -0
- package/dist/auth/types.d.ts +164 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +1 -0
- package/dist/clipboard/index.d.ts +26 -0
- package/dist/clipboard/index.d.ts.map +1 -0
- package/dist/clipboard/index.js +226 -0
- package/dist/clipboard/index.js.map +1 -0
- package/dist/constants.d.ts +12 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +20 -0
- package/dist/constants.js.map +1 -0
- package/dist/error-classification.d.ts +10 -0
- package/dist/error-classification.d.ts.map +1 -0
- package/dist/error-classification.js +22 -0
- package/dist/error-classification.js.map +1 -0
- package/dist/evals/context-builder.d.ts +41 -0
- package/dist/evals/context-builder.d.ts.map +1 -0
- package/dist/evals/context-builder.js +161 -0
- package/dist/evals/context-builder.js.map +1 -0
- package/dist/evals/index.d.ts +4 -0
- package/dist/evals/index.d.ts.map +1 -0
- package/dist/evals/index.js +5 -0
- package/dist/evals/scorers/classify-command.d.ts +31 -0
- package/dist/evals/scorers/classify-command.d.ts.map +1 -0
- package/dist/evals/scorers/classify-command.js +73 -0
- package/dist/evals/scorers/classify-command.js.map +1 -0
- package/dist/evals/scorers/efficiency.d.ts +44 -0
- package/dist/evals/scorers/efficiency.d.ts.map +1 -0
- package/dist/evals/scorers/efficiency.js +259 -0
- package/dist/evals/scorers/efficiency.js.map +1 -0
- package/dist/evals/scorers/extract-tools.d.ts +25 -0
- package/dist/evals/scorers/extract-tools.d.ts.map +1 -0
- package/dist/evals/scorers/extract-tools.js +60 -0
- package/dist/evals/scorers/extract-tools.js.map +1 -0
- package/dist/evals/scorers/index.d.ts +3 -0
- package/dist/evals/scorers/index.d.ts.map +1 -0
- package/dist/evals/scorers/index.js +3 -0
- package/dist/evals/scorers/outcome.d.ts +49 -0
- package/dist/evals/scorers/outcome.d.ts.map +1 -0
- package/dist/evals/scorers/outcome.js +347 -0
- package/dist/evals/scorers/outcome.js.map +1 -0
- package/dist/experimental-agent.d.ts +11 -0
- package/dist/experimental-agent.d.ts.map +1 -0
- package/dist/experimental-agent.js +36 -0
- package/dist/experimental-agent.js.map +1 -0
- package/dist/goal-manager.d.ts +114 -0
- package/dist/goal-manager.d.ts.map +1 -0
- package/dist/goal-manager.js +354 -0
- package/dist/goal-manager.js.map +1 -0
- package/dist/goal-signal.d.ts +14 -0
- package/dist/goal-signal.d.ts.map +1 -0
- package/dist/goal-signal.js +17 -0
- package/dist/goal-signal.js.map +1 -0
- package/dist/headless/cli.d.ts +48 -0
- package/dist/headless/cli.d.ts.map +1 -0
- package/dist/headless/cli.js +239 -0
- package/dist/headless/cli.js.map +1 -0
- package/dist/headless/flags.d.ts +33 -0
- package/dist/headless/flags.d.ts.map +1 -0
- package/dist/headless/flags.js +203 -0
- package/dist/headless/flags.js.map +1 -0
- package/dist/headless/format.d.ts +39 -0
- package/dist/headless/format.d.ts.map +1 -0
- package/dist/headless/format.js +85 -0
- package/dist/headless/format.js.map +1 -0
- package/dist/headless/index.d.ts +25 -0
- package/dist/headless/index.d.ts.map +1 -0
- package/dist/headless/index.js +6 -0
- package/dist/headless/policy.d.ts +17 -0
- package/dist/headless/policy.d.ts.map +1 -0
- package/dist/headless/policy.js +42 -0
- package/dist/headless/policy.js.map +1 -0
- package/dist/headless/run-mc.d.ts +7 -0
- package/dist/headless/run-mc.d.ts.map +1 -0
- package/dist/headless/run-mc.js +408 -0
- package/dist/headless/run-mc.js.map +1 -0
- package/dist/headless/types.d.ts +174 -0
- package/dist/headless/types.d.ts.map +1 -0
- package/dist/headless/types.js +19 -0
- package/dist/headless/types.js.map +1 -0
- package/dist/hooks/config.d.ts +11 -0
- package/dist/hooks/config.d.ts.map +1 -0
- package/dist/hooks/config.js +80 -0
- package/dist/hooks/config.js.map +1 -0
- package/dist/hooks/executor.d.ts +13 -0
- package/dist/hooks/executor.d.ts.map +1 -0
- package/dist/hooks/executor.js +129 -0
- package/dist/hooks/executor.js.map +1 -0
- package/dist/hooks/index.d.ts +6 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +5 -0
- package/dist/hooks/manager.d.ts +54 -0
- package/dist/hooks/manager.d.ts.map +1 -0
- package/dist/hooks/manager.js +241 -0
- package/dist/hooks/manager.js.map +1 -0
- package/dist/hooks/types.d.ts +172 -0
- package/dist/hooks/types.d.ts.map +1 -0
- package/dist/hooks/types.js +8 -0
- package/dist/hooks/types.js.map +1 -0
- package/dist/index.d.ts +463 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1305 -0
- package/dist/index.js.map +1 -0
- package/dist/ipc/ipc-reporter.d.ts +14 -0
- package/dist/ipc/ipc-reporter.d.ts.map +1 -0
- package/dist/ipc/ipc-reporter.js +21 -0
- package/dist/ipc/ipc-reporter.js.map +1 -0
- package/dist/knowledge-inspector.d.ts +123 -0
- package/dist/knowledge-inspector.d.ts.map +1 -0
- package/dist/knowledge-inspector.js +516 -0
- package/dist/knowledge-inspector.js.map +1 -0
- package/dist/knowledge-scope.d.ts +35 -0
- package/dist/knowledge-scope.d.ts.map +1 -0
- package/dist/knowledge-scope.js +47 -0
- package/dist/knowledge-scope.js.map +1 -0
- package/dist/lsp/client.d.ts +56 -0
- package/dist/lsp/client.d.ts.map +1 -0
- package/dist/lsp/client.js +251 -0
- package/dist/lsp/client.js.map +1 -0
- package/dist/lsp/index.d.ts +4 -0
- package/dist/lsp/index.d.ts.map +1 -0
- package/dist/lsp/index.js +4 -0
- package/dist/lsp/language.d.ts +9 -0
- package/dist/lsp/language.d.ts.map +1 -0
- package/dist/lsp/language.js +44 -0
- package/dist/lsp/language.js.map +1 -0
- package/dist/lsp/manager.d.ts +34 -0
- package/dist/lsp/manager.d.ts.map +1 -0
- package/dist/lsp/manager.js +82 -0
- package/dist/lsp/manager.js.map +1 -0
- package/dist/lsp/server.d.ts +27 -0
- package/dist/lsp/server.d.ts.map +1 -0
- package/dist/lsp/server.js +159 -0
- package/dist/lsp/server.js.map +1 -0
- package/dist/lsp/workspace.d.ts +9 -0
- package/dist/lsp/workspace.d.ts.map +1 -0
- package/dist/lsp/workspace.js +55 -0
- package/dist/lsp/workspace.js.map +1 -0
- package/dist/mcp/config.d.ts +77 -0
- package/dist/mcp/config.d.ts.map +1 -0
- package/dist/mcp/config.js +316 -0
- package/dist/mcp/config.js.map +1 -0
- package/dist/mcp/index.d.ts +6 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +3 -0
- package/dist/mcp/manager.d.ts +102 -0
- package/dist/mcp/manager.d.ts.map +1 -0
- package/dist/mcp/manager.js +650 -0
- package/dist/mcp/manager.js.map +1 -0
- package/dist/mcp/state.d.ts +35 -0
- package/dist/mcp/state.d.ts.map +1 -0
- package/dist/mcp/state.js +97 -0
- package/dist/mcp/state.js.map +1 -0
- package/dist/mcp/types.d.ts +139 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/mcp/types.js +1 -0
- package/dist/onboarding/custom-packs.d.ts +7 -0
- package/dist/onboarding/custom-packs.d.ts.map +1 -0
- package/dist/onboarding/custom-packs.js +20 -0
- package/dist/onboarding/custom-packs.js.map +1 -0
- package/dist/onboarding/custom-providers.d.ts +4 -0
- package/dist/onboarding/custom-providers.d.ts.map +1 -0
- package/dist/onboarding/custom-providers.js +30 -0
- package/dist/onboarding/custom-providers.js.map +1 -0
- package/dist/onboarding/index.d.ts +5 -0
- package/dist/onboarding/index.d.ts.map +1 -0
- package/dist/onboarding/index.js +3 -0
- package/dist/onboarding/om-settings.d.ts +47 -0
- package/dist/onboarding/om-settings.d.ts.map +1 -0
- package/dist/onboarding/om-settings.js +83 -0
- package/dist/onboarding/om-settings.js.map +1 -0
- package/dist/onboarding/pack-activation.d.ts +52 -0
- package/dist/onboarding/pack-activation.d.ts.map +1 -0
- package/dist/onboarding/pack-activation.js +108 -0
- package/dist/onboarding/pack-activation.js.map +1 -0
- package/dist/onboarding/packs.d.ts +102 -0
- package/dist/onboarding/packs.d.ts.map +1 -0
- package/dist/onboarding/packs.js +278 -0
- package/dist/onboarding/packs.js.map +1 -0
- package/dist/onboarding/settings.d.ts +538 -0
- package/dist/onboarding/settings.d.ts.map +1 -0
- package/dist/onboarding/settings.js +1060 -0
- package/dist/onboarding/settings.js.map +1 -0
- package/dist/permissions.d.ts +55 -0
- package/dist/permissions.d.ts.map +1 -0
- package/dist/permissions.js +142 -0
- package/dist/permissions.js.map +1 -0
- package/dist/plugin.d.ts +156 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +30 -0
- package/dist/plugin.js.map +1 -0
- package/dist/plugins/dependencies.d.ts +9 -0
- package/dist/plugins/dependencies.d.ts.map +1 -0
- package/dist/plugins/dependencies.js +87 -0
- package/dist/plugins/dependencies.js.map +1 -0
- package/dist/plugins/install.d.ts +21 -0
- package/dist/plugins/install.d.ts.map +1 -0
- package/dist/plugins/install.js +190 -0
- package/dist/plugins/install.js.map +1 -0
- package/dist/plugins/loader.d.ts +19 -0
- package/dist/plugins/loader.d.ts.map +1 -0
- package/dist/plugins/loader.js +260 -0
- package/dist/plugins/loader.js.map +1 -0
- package/dist/plugins/manager.d.ts +98 -0
- package/dist/plugins/manager.d.ts.map +1 -0
- package/dist/plugins/manager.js +456 -0
- package/dist/plugins/manager.js.map +1 -0
- package/dist/plugins/manifest.d.ts +14 -0
- package/dist/plugins/manifest.d.ts.map +1 -0
- package/dist/plugins/manifest.js +50 -0
- package/dist/plugins/manifest.js.map +1 -0
- package/dist/plugins/package-link.d.ts +3 -0
- package/dist/plugins/package-link.d.ts.map +1 -0
- package/dist/plugins/package-link.js +61 -0
- package/dist/plugins/package-link.js.map +1 -0
- package/dist/plugins/paths.d.ts +10 -0
- package/dist/plugins/paths.d.ts.map +1 -0
- package/dist/plugins/paths.js +25 -0
- package/dist/plugins/paths.js.map +1 -0
- package/dist/plugins/registry.d.ts +8 -0
- package/dist/plugins/registry.d.ts.map +1 -0
- package/dist/plugins/registry.js +112 -0
- package/dist/plugins/registry.js.map +1 -0
- package/dist/plugins/scaffold.d.ts +10 -0
- package/dist/plugins/scaffold.d.ts.map +1 -0
- package/dist/plugins/scaffold.js +116 -0
- package/dist/plugins/scaffold.js.map +1 -0
- package/dist/plugins/signal-lane.d.ts +58 -0
- package/dist/plugins/signal-lane.d.ts.map +1 -0
- package/dist/plugins/signal-lane.js +166 -0
- package/dist/plugins/signal-lane.js.map +1 -0
- package/dist/plugins/types.d.ts +81 -0
- package/dist/plugins/types.d.ts.map +1 -0
- package/dist/plugins/types.js +1 -0
- package/dist/process-memory-diagnostics.d.ts +135 -0
- package/dist/process-memory-diagnostics.d.ts.map +1 -0
- package/dist/process-memory-diagnostics.js +499 -0
- package/dist/process-memory-diagnostics.js.map +1 -0
- package/dist/processors/plan-rejection-abort.d.ts +12 -0
- package/dist/processors/plan-rejection-abort.d.ts.map +1 -0
- package/dist/processors/plan-rejection-abort.js +54 -0
- package/dist/processors/plan-rejection-abort.js.map +1 -0
- package/dist/providers/amazon-bedrock-gateway.d.ts +47 -0
- package/dist/providers/amazon-bedrock-gateway.d.ts.map +1 -0
- package/dist/providers/amazon-bedrock-gateway.js +144 -0
- package/dist/providers/amazon-bedrock-gateway.js.map +1 -0
- package/dist/providers/amazon-bedrock.d.ts +28 -0
- package/dist/providers/amazon-bedrock.d.ts.map +1 -0
- package/dist/providers/amazon-bedrock.js +102 -0
- package/dist/providers/amazon-bedrock.js.map +1 -0
- package/dist/providers/anthropic-prompt-cache.d.ts +19 -0
- package/dist/providers/anthropic-prompt-cache.d.ts.map +1 -0
- package/dist/providers/anthropic-prompt-cache.js +11 -0
- package/dist/providers/anthropic-prompt-cache.js.map +1 -0
- package/dist/providers/anthropic-thinking.d.ts +5 -0
- package/dist/providers/anthropic-thinking.d.ts.map +1 -0
- package/dist/providers/anthropic-thinking.js +25 -0
- package/dist/providers/anthropic-thinking.js.map +1 -0
- package/dist/providers/claude-max.d.ts +67 -0
- package/dist/providers/claude-max.d.ts.map +1 -0
- package/dist/providers/claude-max.js +226 -0
- package/dist/providers/claude-max.js.map +1 -0
- package/dist/providers/github-copilot-gateway.d.ts +35 -0
- package/dist/providers/github-copilot-gateway.d.ts.map +1 -0
- package/dist/providers/github-copilot-gateway.js +61 -0
- package/dist/providers/github-copilot-gateway.js.map +1 -0
- package/dist/providers/github-copilot.d.ts +60 -0
- package/dist/providers/github-copilot.d.ts.map +1 -0
- package/dist/providers/github-copilot.js +318 -0
- package/dist/providers/github-copilot.js.map +1 -0
- package/dist/providers/google-thinking.d.ts +31 -0
- package/dist/providers/google-thinking.d.ts.map +1 -0
- package/dist/providers/google-thinking.js +67 -0
- package/dist/providers/google-thinking.js.map +1 -0
- package/dist/providers/kimi-coding.d.ts +14 -0
- package/dist/providers/kimi-coding.d.ts.map +1 -0
- package/dist/providers/kimi-coding.js +78 -0
- package/dist/providers/kimi-coding.js.map +1 -0
- package/dist/providers/model-ids.d.ts +30 -0
- package/dist/providers/model-ids.d.ts.map +1 -0
- package/dist/providers/model-ids.js +79 -0
- package/dist/providers/model-ids.js.map +1 -0
- package/dist/providers/openai-codex.d.ts +84 -0
- package/dist/providers/openai-codex.d.ts.map +1 -0
- package/dist/providers/openai-codex.js +347 -0
- package/dist/providers/openai-codex.js.map +1 -0
- package/dist/providers/provider-thinking.d.ts +23 -0
- package/dist/providers/provider-thinking.d.ts.map +1 -0
- package/dist/providers/provider-thinking.js +64 -0
- package/dist/providers/provider-thinking.js.map +1 -0
- package/dist/providers/thinking-request.d.ts +14 -0
- package/dist/providers/thinking-request.d.ts.map +1 -0
- package/dist/providers/thinking-request.js +90 -0
- package/dist/providers/thinking-request.js.map +1 -0
- package/dist/providers/xai.d.ts +33 -0
- package/dist/providers/xai.d.ts.map +1 -0
- package/dist/providers/xai.js +71 -0
- package/dist/providers/xai.js.map +1 -0
- package/dist/schedules/index.d.ts +10 -0
- package/dist/schedules/index.d.ts.map +1 -0
- package/dist/schedules/index.js +6 -0
- package/dist/schedules/interval.d.ts +49 -0
- package/dist/schedules/interval.d.ts.map +1 -0
- package/dist/schedules/interval.js +215 -0
- package/dist/schedules/interval.js.map +1 -0
- package/dist/schedules/prompt.d.ts +36 -0
- package/dist/schedules/prompt.d.ts.map +1 -0
- package/dist/schedules/prompt.js +39 -0
- package/dist/schedules/prompt.js.map +1 -0
- package/dist/schedules/run-script.d.ts +8 -0
- package/dist/schedules/run-script.d.ts.map +1 -0
- package/dist/schedules/run-script.js +83 -0
- package/dist/schedules/run-script.js.map +1 -0
- package/dist/schedules/scheduler.d.ts +101 -0
- package/dist/schedules/scheduler.d.ts.map +1 -0
- package/dist/schedules/scheduler.js +169 -0
- package/dist/schedules/scheduler.js.map +1 -0
- package/dist/schedules/tools.d.ts +57 -0
- package/dist/schedules/tools.d.ts.map +1 -0
- package/dist/schedules/tools.js +220 -0
- package/dist/schedules/tools.js.map +1 -0
- package/dist/schema.d.ts +499 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +134 -0
- package/dist/schema.js.map +1 -0
- package/dist/theme-palette.d.ts +17 -0
- package/dist/theme-palette.d.ts.map +1 -0
- package/dist/theme-palette.js +21 -0
- package/dist/theme-palette.js.map +1 -0
- package/dist/thinking-catalog.d.ts +4 -0
- package/dist/thinking-catalog.d.ts.map +1 -0
- package/dist/thinking-catalog.js +13 -0
- package/dist/thinking-catalog.js.map +1 -0
- package/dist/thinking.d.ts +37 -0
- package/dist/thinking.d.ts.map +1 -0
- package/dist/thinking.js +137 -0
- package/dist/thinking.js.map +1 -0
- package/dist/tool-names.d.ts +77 -0
- package/dist/tool-names.d.ts.map +1 -0
- package/dist/tool-names.js +56 -0
- package/dist/tool-names.js.map +1 -0
- package/dist/tools/index.d.ts +6 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +3 -0
- package/dist/tools/request-sandbox-access.d.ts +6 -0
- package/dist/tools/request-sandbox-access.d.ts.map +1 -0
- package/dist/tools/request-sandbox-access.js +80 -0
- package/dist/tools/request-sandbox-access.js.map +1 -0
- package/dist/tools/utils.d.ts +20 -0
- package/dist/tools/utils.d.ts.map +1 -0
- package/dist/tools/utils.js +32 -0
- package/dist/tools/utils.js.map +1 -0
- package/dist/tools/web-search.d.ts +114 -0
- package/dist/tools/web-search.d.ts.map +1 -0
- package/dist/tools/web-search.js +155 -0
- package/dist/tools/web-search.js.map +1 -0
- package/dist/tools/workflows/create-workflow.d.ts +7 -0
- package/dist/tools/workflows/create-workflow.d.ts.map +1 -0
- package/dist/tools/workflows/create-workflow.js +81 -0
- package/dist/tools/workflows/create-workflow.js.map +1 -0
- package/dist/tools/workflows/delete-workflow.d.ts +7 -0
- package/dist/tools/workflows/delete-workflow.d.ts.map +1 -0
- package/dist/tools/workflows/delete-workflow.js +21 -0
- package/dist/tools/workflows/delete-workflow.js.map +1 -0
- package/dist/tools/workflows/ephemeral-memory.d.ts +28 -0
- package/dist/tools/workflows/ephemeral-memory.d.ts.map +1 -0
- package/dist/tools/workflows/ephemeral-memory.js +44 -0
- package/dist/tools/workflows/ephemeral-memory.js.map +1 -0
- package/dist/tools/workflows/extract-json-schema.d.ts +12 -0
- package/dist/tools/workflows/extract-json-schema.d.ts.map +1 -0
- package/dist/tools/workflows/extract-json-schema.js +22 -0
- package/dist/tools/workflows/extract-json-schema.js.map +1 -0
- package/dist/tools/workflows/get-workflow.d.ts +11 -0
- package/dist/tools/workflows/get-workflow.d.ts.map +1 -0
- package/dist/tools/workflows/get-workflow.js +34 -0
- package/dist/tools/workflows/get-workflow.js.map +1 -0
- package/dist/tools/workflows/list-available-agents.d.ts +8 -0
- package/dist/tools/workflows/list-available-agents.d.ts.map +1 -0
- package/dist/tools/workflows/list-available-agents.js +32 -0
- package/dist/tools/workflows/list-available-agents.js.map +1 -0
- package/dist/tools/workflows/list-available-classifiers.d.ts +19 -0
- package/dist/tools/workflows/list-available-classifiers.d.ts.map +1 -0
- package/dist/tools/workflows/list-available-classifiers.js +56 -0
- package/dist/tools/workflows/list-available-classifiers.js.map +1 -0
- package/dist/tools/workflows/list-available-tools.d.ts +9 -0
- package/dist/tools/workflows/list-available-tools.d.ts.map +1 -0
- package/dist/tools/workflows/list-available-tools.js +40 -0
- package/dist/tools/workflows/list-available-tools.js.map +1 -0
- package/dist/tools/workflows/list-available-workflows.d.ts +9 -0
- package/dist/tools/workflows/list-available-workflows.d.ts.map +1 -0
- package/dist/tools/workflows/list-available-workflows.js +32 -0
- package/dist/tools/workflows/list-available-workflows.js.map +1 -0
- package/dist/tools/workflows/list-workflows.d.ts +9 -0
- package/dist/tools/workflows/list-workflows.d.ts.map +1 -0
- package/dist/tools/workflows/list-workflows.js +33 -0
- package/dist/tools/workflows/list-workflows.js.map +1 -0
- package/dist/tools/workflows/run-workflow.d.ts +9 -0
- package/dist/tools/workflows/run-workflow.d.ts.map +1 -0
- package/dist/tools/workflows/run-workflow.js +52 -0
- package/dist/tools/workflows/run-workflow.js.map +1 -0
- package/dist/tools/workflows/save-workflow.d.ts +1125 -0
- package/dist/tools/workflows/save-workflow.d.ts.map +1 -0
- package/dist/tools/workflows/save-workflow.js +28 -0
- package/dist/tools/workflows/save-workflow.js.map +1 -0
- package/dist/tools/workflows/tool-ids.d.ts +16 -0
- package/dist/tools/workflows/tool-ids.d.ts.map +1 -0
- package/dist/tools/workflows/tool-ids.js +20 -0
- package/dist/tools/workflows/tool-ids.js.map +1 -0
- package/dist/utils/binaries.d.ts +7 -0
- package/dist/utils/binaries.d.ts.map +1 -0
- package/dist/utils/binaries.js +78 -0
- package/dist/utils/binaries.js.map +1 -0
- package/dist/utils/debug-log.d.ts +12 -0
- package/dist/utils/debug-log.d.ts.map +1 -0
- package/dist/utils/debug-log.js +59 -0
- package/dist/utils/debug-log.js.map +1 -0
- package/dist/utils/discarding-scores-storage.d.ts +33 -0
- package/dist/utils/discarding-scores-storage.d.ts.map +1 -0
- package/dist/utils/discarding-scores-storage.js +54 -0
- package/dist/utils/discarding-scores-storage.js.map +1 -0
- package/dist/utils/errors.d.ts +36 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +196 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/gateway-sync.d.ts +26 -0
- package/dist/utils/gateway-sync.d.ts.map +1 -0
- package/dist/utils/gateway-sync.js +61 -0
- package/dist/utils/gateway-sync.js.map +1 -0
- package/dist/utils/maintenance-lock.d.ts +42 -0
- package/dist/utils/maintenance-lock.d.ts.map +1 -0
- package/dist/utils/maintenance-lock.js +199 -0
- package/dist/utils/maintenance-lock.js.map +1 -0
- package/dist/utils/notification-dispatch.d.ts +59 -0
- package/dist/utils/notification-dispatch.d.ts.map +1 -0
- package/dist/utils/notification-dispatch.js +109 -0
- package/dist/utils/notification-dispatch.js.map +1 -0
- package/dist/utils/open-url.d.ts +10 -0
- package/dist/utils/open-url.d.ts.map +1 -0
- package/dist/utils/open-url.js +30 -0
- package/dist/utils/open-url.js.map +1 -0
- package/dist/utils/path-security.d.ts +2 -0
- package/dist/utils/path-security.d.ts.map +1 -0
- package/dist/utils/path-security.js +10 -0
- package/dist/utils/path-security.js.map +1 -0
- package/dist/utils/plan-diff.d.ts +25 -0
- package/dist/utils/plan-diff.d.ts.map +1 -0
- package/dist/utils/plan-diff.js +62 -0
- package/dist/utils/plan-diff.js.map +1 -0
- package/dist/utils/plans.d.ts +59 -0
- package/dist/utils/plans.d.ts.map +1 -0
- package/dist/utils/plans.js +117 -0
- package/dist/utils/plans.js.map +1 -0
- package/dist/utils/project.d.ts +160 -0
- package/dist/utils/project.d.ts.map +1 -0
- package/dist/utils/project.js +364 -0
- package/dist/utils/project.js.map +1 -0
- package/dist/utils/prune-cli.d.ts +24 -0
- package/dist/utils/prune-cli.d.ts.map +1 -0
- package/dist/utils/prune-cli.js +125 -0
- package/dist/utils/prune-cli.js.map +1 -0
- package/dist/utils/signals-pubsub.d.ts +101 -0
- package/dist/utils/signals-pubsub.d.ts.map +1 -0
- package/dist/utils/signals-pubsub.js +410 -0
- package/dist/utils/signals-pubsub.js.map +1 -0
- package/dist/utils/slash-command-loader.d.ts +52 -0
- package/dist/utils/slash-command-loader.d.ts.map +1 -0
- package/dist/utils/slash-command-loader.js +142 -0
- package/dist/utils/slash-command-loader.js.map +1 -0
- package/dist/utils/slash-command-processor.d.ts +14 -0
- package/dist/utils/slash-command-processor.d.ts.map +1 -0
- package/dist/utils/slash-command-processor.js +109 -0
- package/dist/utils/slash-command-processor.js.map +1 -0
- package/dist/utils/stdin-pipe.d.ts +33 -0
- package/dist/utils/stdin-pipe.d.ts.map +1 -0
- package/dist/utils/stdin-pipe.js +96 -0
- package/dist/utils/stdin-pipe.js.map +1 -0
- package/dist/utils/storage-factory.d.ts +50 -0
- package/dist/utils/storage-factory.d.ts.map +1 -0
- package/dist/utils/storage-factory.js +121 -0
- package/dist/utils/storage-factory.js.map +1 -0
- package/dist/utils/storage-maintenance.d.ts +121 -0
- package/dist/utils/storage-maintenance.d.ts.map +1 -0
- package/dist/utils/storage-maintenance.js +355 -0
- package/dist/utils/storage-maintenance.js.map +1 -0
- package/dist/utils/thread-lock.d.ts +26 -0
- package/dist/utils/thread-lock.d.ts.map +1 -0
- package/dist/utils/thread-lock.js +112 -0
- package/dist/utils/thread-lock.js.map +1 -0
- package/dist/utils/token-estimator.d.ts +3 -0
- package/dist/utils/token-estimator.d.ts.map +1 -0
- package/dist/utils/token-estimator.js +21 -0
- package/dist/utils/token-estimator.js.map +1 -0
- package/dist/utils/update-check.d.ts +151 -0
- package/dist/utils/update-check.d.ts.map +1 -0
- package/dist/utils/update-check.js +432 -0
- package/dist/utils/update-check.js.map +1 -0
- package/dist/voice/stt-registry.d.ts +64 -0
- package/dist/voice/stt-registry.d.ts.map +1 -0
- package/dist/voice/stt-registry.js +144 -0
- package/dist/voice/stt-registry.js.map +1 -0
- package/dist/workflows/register-primitives.d.ts +52 -0
- package/dist/workflows/register-primitives.d.ts.map +1 -0
- package/dist/workflows/register-primitives.js +40 -0
- package/dist/workflows/register-primitives.js.map +1 -0
- package/dist/workflows/service.d.ts +64 -0
- package/dist/workflows/service.d.ts.map +1 -0
- package/dist/workflows/service.js +53 -0
- package/dist/workflows/service.js.map +1 -0
- package/package.json +107 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { thinkingRequestFormatFor } from "./thinking-request.js";
|
|
2
|
+
import { requestableReasoningOptions, runThinkingLevel } from "../thinking.js";
|
|
3
|
+
import { ModelRouterLanguageModel, getModelReasoningOptions } from "@mastra/core/llm";
|
|
4
|
+
import { wrapLanguageModel } from "ai";
|
|
5
|
+
//#region src/providers/provider-thinking.ts
|
|
6
|
+
function providerThinkingOptions(routedModelId, level) {
|
|
7
|
+
const format = thinkingRequestFormatFor(routedModelId);
|
|
8
|
+
if (!format || !level) return void 0;
|
|
9
|
+
const catalogOptions = getModelReasoningOptions(routedModelId);
|
|
10
|
+
const requestable = requestableReasoningOptions(routedModelId, catalogOptions);
|
|
11
|
+
const runLevel = runThinkingLevel(routedModelId, level, catalogOptions);
|
|
12
|
+
if (!requestable?.length || runLevel === "off") return void 0;
|
|
13
|
+
const effortOptions = format.sendEffort?.(runLevel);
|
|
14
|
+
const options = requestable.some((option) => option.type === "effort") ? effortOptions : format.enableThinking;
|
|
15
|
+
if (!options) return void 0;
|
|
16
|
+
const controlKeys = /* @__PURE__ */ new Set([...Object.keys(effortOptions ?? {}), ...Object.keys(format.enableThinking ?? {})]);
|
|
17
|
+
return {
|
|
18
|
+
optionsKey: format.optionsKey,
|
|
19
|
+
options,
|
|
20
|
+
controlKeys
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function withThinkingOptions(callOptions, thinking) {
|
|
24
|
+
if (!thinking) return callOptions;
|
|
25
|
+
const callerOptions = callOptions.providerOptions?.[thinking.optionsKey] ?? {};
|
|
26
|
+
if (Object.keys(callerOptions).some((key) => thinking.controlKeys.has(key))) return callOptions;
|
|
27
|
+
return {
|
|
28
|
+
...callOptions,
|
|
29
|
+
providerOptions: {
|
|
30
|
+
...callOptions.providerOptions,
|
|
31
|
+
[thinking.optionsKey]: {
|
|
32
|
+
...callerOptions,
|
|
33
|
+
...thinking.options
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function withThinkingOptionsModel(model, thinking) {
|
|
39
|
+
if (!thinking) return model;
|
|
40
|
+
return wrapLanguageModel({
|
|
41
|
+
model,
|
|
42
|
+
middleware: {
|
|
43
|
+
specificationVersion: "v3",
|
|
44
|
+
transformParams: async ({ params }) => withThinkingOptions(params, thinking)
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
var ModelRouterLanguageModelWithThinking = class extends ModelRouterLanguageModel {
|
|
49
|
+
#thinking;
|
|
50
|
+
constructor(config, thinking) {
|
|
51
|
+
super(config);
|
|
52
|
+
this.#thinking = thinking;
|
|
53
|
+
}
|
|
54
|
+
doGenerate(options) {
|
|
55
|
+
return super.doGenerate(withThinkingOptions(options, this.#thinking));
|
|
56
|
+
}
|
|
57
|
+
doStream(options) {
|
|
58
|
+
return super.doStream(withThinkingOptions(options, this.#thinking));
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
//#endregion
|
|
62
|
+
export { ModelRouterLanguageModelWithThinking, providerThinkingOptions, withThinkingOptionsModel };
|
|
63
|
+
|
|
64
|
+
//# sourceMappingURL=provider-thinking.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-thinking.js","names":["#thinking"],"sources":["../../src/providers/provider-thinking.ts"],"sourcesContent":["import { getModelReasoningOptions, ModelRouterLanguageModel } from '@mastra/core/llm';\nimport { wrapLanguageModel } from 'ai';\nimport type { JSONValue } from 'ai';\nimport { requestableReasoningOptions, runThinkingLevel } from '../thinking.js';\nimport type { ThinkingLevelSetting } from '../thinking.js';\nimport { thinkingRequestFormatFor } from './thinking-request.js';\n\ntype ProviderOptions = Record<string, Record<string, JSONValue | undefined>>;\n\nexport interface ProviderThinkingOptions {\n optionsKey: string;\n options: Record<string, JSONValue>;\n controlKeys: ReadonlySet<string>;\n}\n\nexport function providerThinkingOptions(\n routedModelId: string,\n level: ThinkingLevelSetting | undefined,\n): ProviderThinkingOptions | undefined {\n const format = thinkingRequestFormatFor(routedModelId);\n if (!format || !level) return undefined;\n const catalogOptions = getModelReasoningOptions(routedModelId);\n const requestable = requestableReasoningOptions(routedModelId, catalogOptions);\n const runLevel = runThinkingLevel(routedModelId, level, catalogOptions);\n if (!requestable?.length || runLevel === 'off') return undefined;\n const effortOptions = format.sendEffort?.(runLevel);\n const sendsEffort = requestable.some(option => option.type === 'effort');\n const options = sendsEffort ? effortOptions : format.enableThinking;\n if (!options) return undefined;\n const controlKeys = new Set([...Object.keys(effortOptions ?? {}), ...Object.keys(format.enableThinking ?? {})]);\n return { optionsKey: format.optionsKey, options, controlKeys };\n}\n\nfunction withThinkingOptions<CallOptions extends { providerOptions?: ProviderOptions }>(\n callOptions: CallOptions,\n thinking: ProviderThinkingOptions | undefined,\n): CallOptions {\n if (!thinking) return callOptions;\n const callerOptions = callOptions.providerOptions?.[thinking.optionsKey] ?? {};\n const callerSetThinking = Object.keys(callerOptions).some(key => thinking.controlKeys.has(key));\n if (callerSetThinking) return callOptions;\n return {\n ...callOptions,\n providerOptions: {\n ...callOptions.providerOptions,\n [thinking.optionsKey]: { ...callerOptions, ...thinking.options },\n },\n };\n}\n\ntype AiSdkLanguageModel = Parameters<typeof wrapLanguageModel>[0]['model'];\n\nexport function withThinkingOptionsModel(\n model: AiSdkLanguageModel,\n thinking: ProviderThinkingOptions | undefined,\n): AiSdkLanguageModel {\n if (!thinking) return model;\n return wrapLanguageModel({\n model,\n middleware: {\n specificationVersion: 'v3',\n transformParams: async ({ params }) => withThinkingOptions(params, thinking),\n },\n });\n}\n\ntype RouterConfig = ConstructorParameters<typeof ModelRouterLanguageModel>[0];\ntype RouterCallOptions = Parameters<ModelRouterLanguageModel['doStream']>[0];\ntype RouterCallResult = ReturnType<ModelRouterLanguageModel['doStream']>;\n\nexport class ModelRouterLanguageModelWithThinking extends ModelRouterLanguageModel {\n readonly #thinking: ProviderThinkingOptions | undefined;\n\n constructor(config: RouterConfig, thinking: ProviderThinkingOptions | undefined) {\n super(config);\n this.#thinking = thinking;\n }\n\n override doGenerate(options: RouterCallOptions): RouterCallResult {\n return super.doGenerate(withThinkingOptions(options, this.#thinking));\n }\n\n override doStream(options: RouterCallOptions): RouterCallResult {\n return super.doStream(withThinkingOptions(options, this.#thinking));\n }\n}\n"],"mappings":";;;;;AAeA,SAAgB,wBACd,eACA,OACqC;CACrC,MAAM,SAAS,yBAAyB,aAAa;CACrD,IAAI,CAAC,UAAU,CAAC,OAAO,OAAO,KAAA;CAC9B,MAAM,iBAAiB,yBAAyB,aAAa;CAC7D,MAAM,cAAc,4BAA4B,eAAe,cAAc;CAC7E,MAAM,WAAW,iBAAiB,eAAe,OAAO,cAAc;CACtE,IAAI,CAAC,aAAa,UAAU,aAAa,OAAO,OAAO,KAAA;CACvD,MAAM,gBAAgB,OAAO,aAAa,QAAQ;CAElD,MAAM,UADc,YAAY,MAAK,WAAU,OAAO,SAAS,QACrC,IAAI,gBAAgB,OAAO;CACrD,IAAI,CAAC,SAAS,OAAO,KAAA;CACrB,MAAM,8BAAc,IAAI,IAAI,CAAC,GAAG,OAAO,KAAK,iBAAiB,CAAC,CAAC,GAAG,GAAG,OAAO,KAAK,OAAO,kBAAkB,CAAC,CAAC,CAAC,CAAC;CAC9G,OAAO;EAAE,YAAY,OAAO;EAAY;EAAS;CAAY;AAC/D;AAEA,SAAS,oBACP,aACA,UACa;CACb,IAAI,CAAC,UAAU,OAAO;CACtB,MAAM,gBAAgB,YAAY,kBAAkB,SAAS,eAAe,CAAC;CAE7E,IAD0B,OAAO,KAAK,aAAa,CAAC,CAAC,MAAK,QAAO,SAAS,YAAY,IAAI,GAAG,CACzE,GAAG,OAAO;CAC9B,OAAO;EACL,GAAG;EACH,iBAAiB;GACf,GAAG,YAAY;IACd,SAAS,aAAa;IAAE,GAAG;IAAe,GAAG,SAAS;GAAQ;EACjE;CACF;AACF;AAIA,SAAgB,yBACd,OACA,UACoB;CACpB,IAAI,CAAC,UAAU,OAAO;CACtB,OAAO,kBAAkB;EACvB;EACA,YAAY;GACV,sBAAsB;GACtB,iBAAiB,OAAO,EAAE,aAAa,oBAAoB,QAAQ,QAAQ;EAC7E;CACF,CAAC;AACH;AAMA,IAAa,uCAAb,cAA0D,yBAAyB;CACjF;CAEA,YAAY,QAAsB,UAA+C;EAC/E,MAAM,MAAM;EACZ,KAAKA,YAAY;CACnB;CAEA,WAAoB,SAA8C;EAChE,OAAO,MAAM,WAAW,oBAAoB,SAAS,KAAKA,SAAS,CAAC;CACtE;CAEA,SAAkB,SAA8C;EAC9D,OAAO,MAAM,SAAS,oBAAoB,SAAS,KAAKA,SAAS,CAAC;CACpE;AACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { JSONValue } from 'ai';
|
|
2
|
+
import type { ActiveThinkingLevel } from '../thinking.js';
|
|
3
|
+
type ThinkingProviderOptions = Record<string, JSONValue>;
|
|
4
|
+
export interface ThinkingRequestFormat {
|
|
5
|
+
optionsKey: string;
|
|
6
|
+
sendEffort?: (effort: ActiveThinkingLevel) => ThinkingProviderOptions;
|
|
7
|
+
acceptedEfforts?: readonly ActiveThinkingLevel[];
|
|
8
|
+
enableThinking?: ThinkingProviderOptions;
|
|
9
|
+
}
|
|
10
|
+
export declare function isThinkingAdapterProvider(provider: string): boolean;
|
|
11
|
+
export declare function isRoutedWithoutThinking(modelId: string): boolean;
|
|
12
|
+
export declare function thinkingRequestFormatFor(modelId: string): ThinkingRequestFormat | undefined;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=thinking-request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"thinking-request.d.ts","sourceRoot":"","sources":["../../src/providers/thinking-request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAG1D,KAAK,uBAAuB,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAEzD,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,mBAAmB,KAAK,uBAAuB,CAAC;IACtE,eAAe,CAAC,EAAE,SAAS,mBAAmB,EAAE,CAAC;IACjD,cAAc,CAAC,EAAE,uBAAuB,CAAC;CAC1C;AAyCD,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEnE;AASD,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAGhE;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,qBAAqB,GAAG,SAAS,CAM3F"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { MASTRA_GATEWAY_PREFIX, stripMastraGatewayPrefix } from "./model-ids.js";
|
|
2
|
+
//#region src/providers/thinking-request.ts
|
|
3
|
+
const LOW_TO_HIGH = [
|
|
4
|
+
"low",
|
|
5
|
+
"medium",
|
|
6
|
+
"high"
|
|
7
|
+
];
|
|
8
|
+
const sendReasoningEffort = (reasoningEffort) => ({ reasoningEffort });
|
|
9
|
+
const ENABLE_REASONING = { reasoning: { enabled: true } };
|
|
10
|
+
const OPENROUTER_FORMAT = {
|
|
11
|
+
optionsKey: "openrouter",
|
|
12
|
+
sendEffort: (effort) => ({ reasoning: { effort } }),
|
|
13
|
+
enableThinking: ENABLE_REASONING
|
|
14
|
+
};
|
|
15
|
+
const REQUEST_FORMATS_BY_PROVIDER = {
|
|
16
|
+
deepseek: {
|
|
17
|
+
optionsKey: "deepseek",
|
|
18
|
+
sendEffort: sendReasoningEffort,
|
|
19
|
+
enableThinking: { thinking: { type: "enabled" } }
|
|
20
|
+
},
|
|
21
|
+
openrouter: OPENROUTER_FORMAT,
|
|
22
|
+
alibaba: {
|
|
23
|
+
optionsKey: "alibaba",
|
|
24
|
+
enableThinking: { enableThinking: true }
|
|
25
|
+
},
|
|
26
|
+
groq: {
|
|
27
|
+
optionsKey: "groq",
|
|
28
|
+
sendEffort: sendReasoningEffort,
|
|
29
|
+
acceptedEfforts: LOW_TO_HIGH
|
|
30
|
+
},
|
|
31
|
+
mistral: {
|
|
32
|
+
optionsKey: "mistral",
|
|
33
|
+
sendEffort: sendReasoningEffort,
|
|
34
|
+
acceptedEfforts: ["high"]
|
|
35
|
+
},
|
|
36
|
+
xai: {
|
|
37
|
+
optionsKey: "xai",
|
|
38
|
+
sendEffort: sendReasoningEffort,
|
|
39
|
+
acceptedEfforts: LOW_TO_HIGH
|
|
40
|
+
},
|
|
41
|
+
togetherai: {
|
|
42
|
+
optionsKey: "togetherai",
|
|
43
|
+
sendEffort: sendReasoningEffort,
|
|
44
|
+
acceptedEfforts: LOW_TO_HIGH,
|
|
45
|
+
enableThinking: ENABLE_REASONING
|
|
46
|
+
},
|
|
47
|
+
deepinfra: {
|
|
48
|
+
optionsKey: "deepinfra",
|
|
49
|
+
sendEffort: sendReasoningEffort,
|
|
50
|
+
acceptedEfforts: LOW_TO_HIGH,
|
|
51
|
+
enableThinking: ENABLE_REASONING
|
|
52
|
+
},
|
|
53
|
+
cerebras: {
|
|
54
|
+
optionsKey: "cerebras",
|
|
55
|
+
sendEffort: sendReasoningEffort
|
|
56
|
+
},
|
|
57
|
+
perplexity: {
|
|
58
|
+
optionsKey: "perplexity",
|
|
59
|
+
sendEffort: (effort) => ({ reasoning_effort: effort })
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const THINKING_ADAPTER_PROVIDERS = /* @__PURE__ */ new Set([
|
|
63
|
+
"anthropic",
|
|
64
|
+
"openai",
|
|
65
|
+
"google"
|
|
66
|
+
]);
|
|
67
|
+
function isThinkingAdapterProvider(provider) {
|
|
68
|
+
return THINKING_ADAPTER_PROVIDERS.has(provider);
|
|
69
|
+
}
|
|
70
|
+
const PROVIDERS_ROUTED_WITHOUT_THINKING = /* @__PURE__ */ new Set([
|
|
71
|
+
"github-copilot",
|
|
72
|
+
"kimi-for-coding",
|
|
73
|
+
"moonshotai",
|
|
74
|
+
"amazon-bedrock"
|
|
75
|
+
]);
|
|
76
|
+
function isRoutedWithoutThinking(modelId) {
|
|
77
|
+
const [provider = ""] = stripMastraGatewayPrefix(modelId).split("/");
|
|
78
|
+
return PROVIDERS_ROUTED_WITHOUT_THINKING.has(provider);
|
|
79
|
+
}
|
|
80
|
+
function thinkingRequestFormatFor(modelId) {
|
|
81
|
+
const routedThroughMastraGateway = modelId.startsWith(MASTRA_GATEWAY_PREFIX);
|
|
82
|
+
const [provider = ""] = stripMastraGatewayPrefix(modelId).split("/");
|
|
83
|
+
if (isThinkingAdapterProvider(provider)) return void 0;
|
|
84
|
+
if (routedThroughMastraGateway) return OPENROUTER_FORMAT;
|
|
85
|
+
return REQUEST_FORMATS_BY_PROVIDER[provider.includes("alibaba") ? "alibaba" : provider];
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
export { isRoutedWithoutThinking, isThinkingAdapterProvider, thinkingRequestFormatFor };
|
|
89
|
+
|
|
90
|
+
//# sourceMappingURL=thinking-request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"thinking-request.js","names":[],"sources":["../../src/providers/thinking-request.ts"],"sourcesContent":["import type { JSONValue } from 'ai';\nimport type { ActiveThinkingLevel } from '../thinking.js';\nimport { MASTRA_GATEWAY_PREFIX, stripMastraGatewayPrefix } from './model-ids.js';\n\ntype ThinkingProviderOptions = Record<string, JSONValue>;\n\nexport interface ThinkingRequestFormat {\n optionsKey: string;\n sendEffort?: (effort: ActiveThinkingLevel) => ThinkingProviderOptions;\n acceptedEfforts?: readonly ActiveThinkingLevel[];\n enableThinking?: ThinkingProviderOptions;\n}\n\nconst LOW_TO_HIGH: readonly ActiveThinkingLevel[] = ['low', 'medium', 'high'];\nconst sendReasoningEffort = (reasoningEffort: ActiveThinkingLevel): ThinkingProviderOptions => ({ reasoningEffort });\nconst ENABLE_REASONING: ThinkingProviderOptions = { reasoning: { enabled: true } };\n\nconst OPENROUTER_FORMAT: ThinkingRequestFormat = {\n optionsKey: 'openrouter',\n sendEffort: effort => ({ reasoning: { effort } }),\n enableThinking: ENABLE_REASONING,\n};\n\nconst REQUEST_FORMATS_BY_PROVIDER: Partial<Record<string, ThinkingRequestFormat>> = {\n deepseek: {\n optionsKey: 'deepseek',\n sendEffort: sendReasoningEffort,\n enableThinking: { thinking: { type: 'enabled' } },\n },\n openrouter: OPENROUTER_FORMAT,\n alibaba: { optionsKey: 'alibaba', enableThinking: { enableThinking: true } },\n groq: { optionsKey: 'groq', sendEffort: sendReasoningEffort, acceptedEfforts: LOW_TO_HIGH },\n mistral: { optionsKey: 'mistral', sendEffort: sendReasoningEffort, acceptedEfforts: ['high'] },\n xai: { optionsKey: 'xai', sendEffort: sendReasoningEffort, acceptedEfforts: LOW_TO_HIGH },\n togetherai: {\n optionsKey: 'togetherai',\n sendEffort: sendReasoningEffort,\n acceptedEfforts: LOW_TO_HIGH,\n enableThinking: ENABLE_REASONING,\n },\n deepinfra: {\n optionsKey: 'deepinfra',\n sendEffort: sendReasoningEffort,\n acceptedEfforts: LOW_TO_HIGH,\n enableThinking: ENABLE_REASONING,\n },\n cerebras: { optionsKey: 'cerebras', sendEffort: sendReasoningEffort },\n perplexity: { optionsKey: 'perplexity', sendEffort: effort => ({ reasoning_effort: effort }) },\n};\n\nconst THINKING_ADAPTER_PROVIDERS: ReadonlySet<string> = new Set(['anthropic', 'openai', 'google']);\n\nexport function isThinkingAdapterProvider(provider: string): boolean {\n return THINKING_ADAPTER_PROVIDERS.has(provider);\n}\n\nconst PROVIDERS_ROUTED_WITHOUT_THINKING: ReadonlySet<string> = new Set([\n 'github-copilot',\n 'kimi-for-coding',\n 'moonshotai',\n 'amazon-bedrock',\n]);\n\nexport function isRoutedWithoutThinking(modelId: string): boolean {\n const [provider = ''] = stripMastraGatewayPrefix(modelId).split('/');\n return PROVIDERS_ROUTED_WITHOUT_THINKING.has(provider);\n}\n\nexport function thinkingRequestFormatFor(modelId: string): ThinkingRequestFormat | undefined {\n const routedThroughMastraGateway = modelId.startsWith(MASTRA_GATEWAY_PREFIX);\n const [provider = ''] = stripMastraGatewayPrefix(modelId).split('/');\n if (isThinkingAdapterProvider(provider)) return undefined;\n if (routedThroughMastraGateway) return OPENROUTER_FORMAT;\n return REQUEST_FORMATS_BY_PROVIDER[provider.includes('alibaba') ? 'alibaba' : provider];\n}\n"],"mappings":";;AAaA,MAAM,cAA8C;CAAC;CAAO;CAAU;AAAM;AAC5E,MAAM,uBAAuB,qBAAmE,EAAE,gBAAgB;AAClH,MAAM,mBAA4C,EAAE,WAAW,EAAE,SAAS,KAAK,EAAE;AAEjF,MAAM,oBAA2C;CAC/C,YAAY;CACZ,aAAY,YAAW,EAAE,WAAW,EAAE,OAAO,EAAE;CAC/C,gBAAgB;AAClB;AAEA,MAAM,8BAA8E;CAClF,UAAU;EACR,YAAY;EACZ,YAAY;EACZ,gBAAgB,EAAE,UAAU,EAAE,MAAM,UAAU,EAAE;CAClD;CACA,YAAY;CACZ,SAAS;EAAE,YAAY;EAAW,gBAAgB,EAAE,gBAAgB,KAAK;CAAE;CAC3E,MAAM;EAAE,YAAY;EAAQ,YAAY;EAAqB,iBAAiB;CAAY;CAC1F,SAAS;EAAE,YAAY;EAAW,YAAY;EAAqB,iBAAiB,CAAC,MAAM;CAAE;CAC7F,KAAK;EAAE,YAAY;EAAO,YAAY;EAAqB,iBAAiB;CAAY;CACxF,YAAY;EACV,YAAY;EACZ,YAAY;EACZ,iBAAiB;EACjB,gBAAgB;CAClB;CACA,WAAW;EACT,YAAY;EACZ,YAAY;EACZ,iBAAiB;EACjB,gBAAgB;CAClB;CACA,UAAU;EAAE,YAAY;EAAY,YAAY;CAAoB;CACpE,YAAY;EAAE,YAAY;EAAc,aAAY,YAAW,EAAE,kBAAkB,OAAO;CAAG;AAC/F;AAEA,MAAM,6CAAkD,IAAI,IAAI;CAAC;CAAa;CAAU;AAAQ,CAAC;AAEjG,SAAgB,0BAA0B,UAA2B;CACnE,OAAO,2BAA2B,IAAI,QAAQ;AAChD;AAEA,MAAM,oDAAyD,IAAI,IAAI;CACrE;CACA;CACA;CACA;AACF,CAAC;AAED,SAAgB,wBAAwB,SAA0B;CAChE,MAAM,CAAC,WAAW,MAAM,yBAAyB,OAAO,CAAC,CAAC,MAAM,GAAG;CACnE,OAAO,kCAAkC,IAAI,QAAQ;AACvD;AAEA,SAAgB,yBAAyB,SAAoD;CAC3F,MAAM,6BAA6B,QAAQ,WAAW,qBAAqB;CAC3E,MAAM,CAAC,WAAW,MAAM,yBAAyB,OAAO,CAAC,CAAC,MAAM,GAAG;CACnE,IAAI,0BAA0B,QAAQ,GAAG,OAAO,KAAA;CAChD,IAAI,4BAA4B,OAAO;CACvC,OAAO,4BAA4B,SAAS,SAAS,SAAS,IAAI,YAAY;AAChF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* xAI (Grok) OAuth Provider
|
|
3
|
+
*
|
|
4
|
+
* Uses OAuth tokens from AuthStorage to authenticate with the xAI API.
|
|
5
|
+
* The xAI API speaks an OpenAI-compatible chat format, and the OAuth access
|
|
6
|
+
* token is accepted as a bearer API key, so we plug `@ai-sdk/openai-compatible`
|
|
7
|
+
* into `https://api.x.ai/v1` with a custom fetch that injects the (auto-refreshed)
|
|
8
|
+
* access token.
|
|
9
|
+
*/
|
|
10
|
+
import type { OpenAICompatibleProvider } from '@ai-sdk/openai-compatible';
|
|
11
|
+
import { AuthStorage } from '../auth/storage.js';
|
|
12
|
+
import type { CredentialStore } from '../auth/types.js';
|
|
13
|
+
/** Get or create the shared AuthStorage instance. */
|
|
14
|
+
export declare function getAuthStorage(): AuthStorage;
|
|
15
|
+
/** Set a custom AuthStorage instance (useful for tests / TUI integration). */
|
|
16
|
+
export declare function setAuthStorage(storage: AuthStorage | undefined): void;
|
|
17
|
+
/**
|
|
18
|
+
* Build a fetch wrapper that authenticates with xAI OAuth.
|
|
19
|
+
* Injects the access token (auto-refreshed by AuthStorage) as a bearer token,
|
|
20
|
+
* preserving non-auth headers from the caller.
|
|
21
|
+
*/
|
|
22
|
+
export declare function buildXAIOAuthFetch(opts?: {
|
|
23
|
+
authStorage?: CredentialStore;
|
|
24
|
+
}): typeof fetch;
|
|
25
|
+
/**
|
|
26
|
+
* Creates an xAI model using OAuth authentication.
|
|
27
|
+
* Uses OAuth tokens from AuthStorage (auto-refreshes when needed).
|
|
28
|
+
*/
|
|
29
|
+
export declare function xaiProvider(modelId: string, options?: {
|
|
30
|
+
headers?: Record<string, string>;
|
|
31
|
+
authStorage?: CredentialStore;
|
|
32
|
+
}): ReturnType<OpenAICompatibleProvider['chatModel']>;
|
|
33
|
+
//# sourceMappingURL=xai.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xai.d.ts","sourceRoot":"","sources":["../../src/providers/xai.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAE1E,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAQxD,qDAAqD;AACrD,wBAAgB,cAAc,IAAI,WAAW,CAK5C;AAED,8EAA8E;AAC9E,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,GAAG,IAAI,CAErE;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,GAAE;IAAE,WAAW,CAAC,EAAE,eAAe,CAAA;CAAO,GAAG,OAAO,KAAK,CAsC7F;AAED;;;GAGG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,WAAW,CAAC,EAAE,eAAe,CAAA;CAAE,GAC5E,UAAU,CAAC,wBAAwB,CAAC,WAAW,CAAC,CAAC,CASnD"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { AuthStorage } from "../auth/storage.js";
|
|
2
|
+
import { ProviderAuthRequiredError } from "../auth/provider-auth-error.js";
|
|
3
|
+
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
4
|
+
//#region src/providers/xai.ts
|
|
5
|
+
/**
|
|
6
|
+
* xAI (Grok) OAuth Provider
|
|
7
|
+
*
|
|
8
|
+
* Uses OAuth tokens from AuthStorage to authenticate with the xAI API.
|
|
9
|
+
* The xAI API speaks an OpenAI-compatible chat format, and the OAuth access
|
|
10
|
+
* token is accepted as a bearer API key, so we plug `@ai-sdk/openai-compatible`
|
|
11
|
+
* into `https://api.x.ai/v1` with a custom fetch that injects the (auto-refreshed)
|
|
12
|
+
* access token.
|
|
13
|
+
*/
|
|
14
|
+
const XAI_PROVIDER_ID = "xai";
|
|
15
|
+
const XAI_BASE_URL = "https://api.x.ai/v1";
|
|
16
|
+
let authStorageInstance = null;
|
|
17
|
+
/** Get or create the shared AuthStorage instance. */
|
|
18
|
+
function getAuthStorage() {
|
|
19
|
+
if (!authStorageInstance) authStorageInstance = new AuthStorage();
|
|
20
|
+
return authStorageInstance;
|
|
21
|
+
}
|
|
22
|
+
/** Set a custom AuthStorage instance (useful for tests / TUI integration). */
|
|
23
|
+
function setAuthStorage(storage) {
|
|
24
|
+
authStorageInstance = storage ?? null;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Build a fetch wrapper that authenticates with xAI OAuth.
|
|
28
|
+
* Injects the access token (auto-refreshed by AuthStorage) as a bearer token,
|
|
29
|
+
* preserving non-auth headers from the caller.
|
|
30
|
+
*/
|
|
31
|
+
function buildXAIOAuthFetch(opts = {}) {
|
|
32
|
+
return (async (url, init) => {
|
|
33
|
+
const storage = opts.authStorage ?? getAuthStorage();
|
|
34
|
+
storage.reload();
|
|
35
|
+
const cred = storage.get(XAI_PROVIDER_ID);
|
|
36
|
+
if (!cred || cred.type !== "oauth") throw new ProviderAuthRequiredError("Not logged in to xAI.");
|
|
37
|
+
const accessToken = await storage.getApiKey(XAI_PROVIDER_ID);
|
|
38
|
+
if (!accessToken) throw new ProviderAuthRequiredError("Failed to refresh the xAI token.");
|
|
39
|
+
const headers = new Headers(url instanceof Request ? url.headers : void 0);
|
|
40
|
+
if (init?.headers) new Headers(init.headers).forEach((value, key) => headers.set(key, value));
|
|
41
|
+
headers.delete("authorization");
|
|
42
|
+
headers.delete("x-api-key");
|
|
43
|
+
headers.set("Authorization", `Bearer ${accessToken}`);
|
|
44
|
+
try {
|
|
45
|
+
return await fetch(url, {
|
|
46
|
+
...init,
|
|
47
|
+
headers
|
|
48
|
+
});
|
|
49
|
+
} catch (error) {
|
|
50
|
+
if (error && typeof error === "object") Object.assign(error, { requestUrl: url instanceof URL ? url.toString() : typeof url === "string" ? url : url.url });
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Creates an xAI model using OAuth authentication.
|
|
57
|
+
* Uses OAuth tokens from AuthStorage (auto-refreshes when needed).
|
|
58
|
+
*/
|
|
59
|
+
function xaiProvider(modelId, options) {
|
|
60
|
+
return createOpenAICompatible({
|
|
61
|
+
name: XAI_PROVIDER_ID,
|
|
62
|
+
baseURL: XAI_BASE_URL,
|
|
63
|
+
apiKey: "oauth-placeholder",
|
|
64
|
+
headers: options?.headers,
|
|
65
|
+
fetch: buildXAIOAuthFetch({ authStorage: options?.authStorage })
|
|
66
|
+
}).chatModel(modelId);
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
export { buildXAIOAuthFetch, getAuthStorage, setAuthStorage, xaiProvider };
|
|
70
|
+
|
|
71
|
+
//# sourceMappingURL=xai.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xai.js","names":[],"sources":["../../src/providers/xai.ts"],"sourcesContent":["/**\n * xAI (Grok) OAuth Provider\n *\n * Uses OAuth tokens from AuthStorage to authenticate with the xAI API.\n * The xAI API speaks an OpenAI-compatible chat format, and the OAuth access\n * token is accepted as a bearer API key, so we plug `@ai-sdk/openai-compatible`\n * into `https://api.x.ai/v1` with a custom fetch that injects the (auto-refreshed)\n * access token.\n */\n\nimport { createOpenAICompatible } from '@ai-sdk/openai-compatible';\nimport type { OpenAICompatibleProvider } from '@ai-sdk/openai-compatible';\nimport { ProviderAuthRequiredError } from '../auth/provider-auth-error.js';\nimport { AuthStorage } from '../auth/storage.js';\nimport type { CredentialStore } from '../auth/types.js';\n\nconst XAI_PROVIDER_ID = 'xai';\nconst XAI_BASE_URL = 'https://api.x.ai/v1';\n\n// Singleton auth storage instance (shared with claude-max.ts / github-copilot.ts when not overridden).\nlet authStorageInstance: AuthStorage | null = null;\n\n/** Get or create the shared AuthStorage instance. */\nexport function getAuthStorage(): AuthStorage {\n if (!authStorageInstance) {\n authStorageInstance = new AuthStorage();\n }\n return authStorageInstance;\n}\n\n/** Set a custom AuthStorage instance (useful for tests / TUI integration). */\nexport function setAuthStorage(storage: AuthStorage | undefined): void {\n authStorageInstance = storage ?? null;\n}\n\n/**\n * Build a fetch wrapper that authenticates with xAI OAuth.\n * Injects the access token (auto-refreshed by AuthStorage) as a bearer token,\n * preserving non-auth headers from the caller.\n */\nexport function buildXAIOAuthFetch(opts: { authStorage?: CredentialStore } = {}): typeof fetch {\n return (async (url: string | URL | Request, init?: Parameters<typeof fetch>[1]) => {\n const storage = opts.authStorage ?? getAuthStorage();\n storage.reload();\n\n const cred = storage.get(XAI_PROVIDER_ID);\n if (!cred || cred.type !== 'oauth') {\n throw new ProviderAuthRequiredError('Not logged in to xAI.');\n }\n\n // getApiKey() refreshes the access token if it has expired.\n const accessToken = await storage.getApiKey(XAI_PROVIDER_ID);\n if (!accessToken) {\n throw new ProviderAuthRequiredError('Failed to refresh the xAI token.');\n }\n\n // Preserve existing headers, strip auth-related ones. Explicit init\n // headers override headers carried by an incoming Request.\n const headers = new Headers(url instanceof Request ? url.headers : undefined);\n if (init?.headers) {\n new Headers(init.headers).forEach((value, key) => headers.set(key, value));\n }\n headers.delete('authorization');\n headers.delete('x-api-key');\n\n headers.set('Authorization', `Bearer ${accessToken}`);\n\n try {\n return await fetch(url, { ...init, headers });\n } catch (error) {\n if (error && typeof error === 'object') {\n Object.assign(error as Record<string, unknown>, {\n requestUrl: url instanceof URL ? url.toString() : typeof url === 'string' ? url : (url as Request).url,\n });\n }\n throw error;\n }\n }) as typeof fetch;\n}\n\n/**\n * Creates an xAI model using OAuth authentication.\n * Uses OAuth tokens from AuthStorage (auto-refreshes when needed).\n */\nexport function xaiProvider(\n modelId: string,\n options?: { headers?: Record<string, string>; authStorage?: CredentialStore },\n): ReturnType<OpenAICompatibleProvider['chatModel']> {\n const provider = createOpenAICompatible({\n name: XAI_PROVIDER_ID,\n baseURL: XAI_BASE_URL,\n apiKey: 'oauth-placeholder', // real auth injected by the custom fetch\n headers: options?.headers,\n fetch: buildXAIOAuthFetch({ authStorage: options?.authStorage }),\n });\n return provider.chatModel(modelId);\n}\n"],"mappings":";;;;;;;;;;;;;AAgBA,MAAM,kBAAkB;AACxB,MAAM,eAAe;AAGrB,IAAI,sBAA0C;;AAG9C,SAAgB,iBAA8B;CAC5C,IAAI,CAAC,qBACH,sBAAsB,IAAI,YAAY;CAExC,OAAO;AACT;;AAGA,SAAgB,eAAe,SAAwC;CACrE,sBAAsB,WAAW;AACnC;;;;;;AAOA,SAAgB,mBAAmB,OAA0C,CAAC,GAAiB;CAC7F,QAAQ,OAAO,KAA6B,SAAuC;EACjF,MAAM,UAAU,KAAK,eAAe,eAAe;EACnD,QAAQ,OAAO;EAEf,MAAM,OAAO,QAAQ,IAAI,eAAe;EACxC,IAAI,CAAC,QAAQ,KAAK,SAAS,SACzB,MAAM,IAAI,0BAA0B,uBAAuB;EAI7D,MAAM,cAAc,MAAM,QAAQ,UAAU,eAAe;EAC3D,IAAI,CAAC,aACH,MAAM,IAAI,0BAA0B,kCAAkC;EAKxE,MAAM,UAAU,IAAI,QAAQ,eAAe,UAAU,IAAI,UAAU,KAAA,CAAS;EAC5E,IAAI,MAAM,SACR,IAAI,QAAQ,KAAK,OAAO,CAAC,CAAC,SAAS,OAAO,QAAQ,QAAQ,IAAI,KAAK,KAAK,CAAC;EAE3E,QAAQ,OAAO,eAAe;EAC9B,QAAQ,OAAO,WAAW;EAE1B,QAAQ,IAAI,iBAAiB,UAAU,aAAa;EAEpD,IAAI;GACF,OAAO,MAAM,MAAM,KAAK;IAAE,GAAG;IAAM;GAAQ,CAAC;EAC9C,SAAS,OAAO;GACd,IAAI,SAAS,OAAO,UAAU,UAC5B,OAAO,OAAO,OAAkC,EAC9C,YAAY,eAAe,MAAM,IAAI,SAAS,IAAI,OAAO,QAAQ,WAAW,MAAO,IAAgB,IACrG,CAAC;GAEH,MAAM;EACR;CACF;AACF;;;;;AAMA,SAAgB,YACd,SACA,SACmD;CAQnD,OAPiB,uBAAuB;EACtC,MAAM;EACN,SAAS;EACT,QAAQ;EACR,SAAS,SAAS;EAClB,OAAO,mBAAmB,EAAE,aAAa,SAAS,YAAY,CAAC;CACjE,CACc,CAAC,CAAC,UAAU,OAAO;AACnC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { parseInterval, validateInterval, nextFireTime } from './interval.js';
|
|
2
|
+
export type { ParsedInterval, IntervalError, IntervalCheck } from './interval.js';
|
|
3
|
+
export { assembleSchedulePrompt, formatScriptOutput, SCRIPT_TIMEOUT_MS } from './prompt.js';
|
|
4
|
+
export type { RunScript, ScriptResult, AssemblePromptOptions, AssembledPrompt } from './prompt.js';
|
|
5
|
+
export { ThreadScheduler, shortScheduleId, describeScheduleSource, scheduleSignalAttributes, SCHEDULE_SIGNAL_SOURCE, LATE_FIRE_GRACE_MS, } from './scheduler.js';
|
|
6
|
+
export type { ThreadSchedule, ThreadScheduleSpec, ThreadScheduleSource, ScheduleTrigger, ScheduleFile, ThreadSchedulerOptions, ScheduleRunResult, } from './scheduler.js';
|
|
7
|
+
export { runScript, resolveScriptCommand, isExecutableFile } from './run-script.js';
|
|
8
|
+
export { createScheduleTools, SCHEDULE_TOOL_IDS } from './tools.js';
|
|
9
|
+
export type { ScheduleToolsOptions, ScheduleFileOptions } from './tools.js';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/schedules/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC9E,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAClF,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC5F,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnG,OAAO,EACL,eAAe,EACf,eAAe,EACf,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACV,cAAc,EACd,kBAAkB,EAClB,oBAAoB,EACpB,eAAe,EACf,YAAY,EACZ,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACpF,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACpE,YAAY,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { nextFireTime, parseInterval, validateInterval } from "./interval.js";
|
|
2
|
+
import { SCRIPT_TIMEOUT_MS, assembleSchedulePrompt, formatScriptOutput } from "./prompt.js";
|
|
3
|
+
import { LATE_FIRE_GRACE_MS, SCHEDULE_SIGNAL_SOURCE, ThreadScheduler, describeScheduleSource, scheduleSignalAttributes, shortScheduleId } from "./scheduler.js";
|
|
4
|
+
import { isExecutableFile, resolveScriptCommand, runScript } from "./run-script.js";
|
|
5
|
+
import { SCHEDULE_TOOL_IDS, createScheduleTools } from "./tools.js";
|
|
6
|
+
export { LATE_FIRE_GRACE_MS, SCHEDULE_SIGNAL_SOURCE, SCHEDULE_TOOL_IDS, SCRIPT_TIMEOUT_MS, ThreadScheduler, assembleSchedulePrompt, createScheduleTools, describeScheduleSource, formatScriptOutput, isExecutableFile, nextFireTime, parseInterval, resolveScriptCommand, runScript, scheduleSignalAttributes, shortScheduleId, validateInterval };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interval parsing and fire-time math for `/schedules`.
|
|
3
|
+
*
|
|
4
|
+
* Users type `5m`, `2h`, `1 day`. Schedules fire on local wall-clock
|
|
5
|
+
* boundaries (5m fires at :00, :05, ...), so only intervals that divide the
|
|
6
|
+
* hour (minutes) or the day (hours) give a stable cadence; anything else is
|
|
7
|
+
* rejected with the nearest valid suggestion instead of silently drifting.
|
|
8
|
+
*/
|
|
9
|
+
export type ParsedInterval = {
|
|
10
|
+
ms: number;
|
|
11
|
+
label: string;
|
|
12
|
+
};
|
|
13
|
+
export type IntervalError = {
|
|
14
|
+
error: string;
|
|
15
|
+
};
|
|
16
|
+
/** Parse `5m`, `2h`, `1 day`, `90 minutes` into milliseconds plus a normalized label. */
|
|
17
|
+
export declare function parseInterval(text: string): ParsedInterval | IntervalError;
|
|
18
|
+
export type IntervalCheck = {
|
|
19
|
+
ok: true;
|
|
20
|
+
} | {
|
|
21
|
+
error: string;
|
|
22
|
+
suggestion?: string;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Check that an interval fires on stable clock boundaries: whole minutes that
|
|
26
|
+
* divide the hour, whole hours that divide the day, or exactly one day.
|
|
27
|
+
*/
|
|
28
|
+
export declare function validateInterval({ ms }: {
|
|
29
|
+
ms: number;
|
|
30
|
+
}): IntervalCheck;
|
|
31
|
+
/**
|
|
32
|
+
* The first boundary strictly after `after`, on the local wall clock
|
|
33
|
+
* (5m → :00, :05, ...; 2h → 00:00, 02:00, ...; 1d → midnight). `intervalMs`
|
|
34
|
+
* must pass {@link validateInterval}.
|
|
35
|
+
*
|
|
36
|
+
* Around daylight-saving changes this behaves like cron:
|
|
37
|
+
* - Sub-hour cadences follow the minute hand, so they keep firing every N real
|
|
38
|
+
* minutes through both the skipped and the repeated hour. Across a
|
|
39
|
+
* half-hour change, the gap between fires never exceeds the interval.
|
|
40
|
+
* - Hourly and daily cadences fire once per wall-clock slot. A boundary that
|
|
41
|
+
* falls in a skipped hour fires at the first minute after the jump (02:00 →
|
|
42
|
+
* 03:00), and a repeated hour does not fire a second time.
|
|
43
|
+
*
|
|
44
|
+
* Computing from `after` rather than from the previous fire means a late
|
|
45
|
+
* timer (sleep, busy event loop) skips missed boundaries instead of bursting
|
|
46
|
+
* to catch up.
|
|
47
|
+
*/
|
|
48
|
+
export declare function nextFireTime(intervalMs: number, after: number): number;
|
|
49
|
+
//# sourceMappingURL=interval.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interval.d.ts","sourceRoot":"","sources":["../../src/schedules/interval.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAOH,MAAM,MAAM,cAAc,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAC3D,MAAM,MAAM,aAAa,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAyB9C,yFAAyF;AACzF,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,aAAa,CAc1E;AAED,MAAM,MAAM,aAAa,GAAG;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAWlF;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,EAAE,EAAE;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG,aAAa,CA6CtE;AAUD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAkBtE"}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
//#region src/schedules/interval.ts
|
|
2
|
+
/**
|
|
3
|
+
* Interval parsing and fire-time math for `/schedules`.
|
|
4
|
+
*
|
|
5
|
+
* Users type `5m`, `2h`, `1 day`. Schedules fire on local wall-clock
|
|
6
|
+
* boundaries (5m fires at :00, :05, ...), so only intervals that divide the
|
|
7
|
+
* hour (minutes) or the day (hours) give a stable cadence; anything else is
|
|
8
|
+
* rejected with the nearest valid suggestion instead of silently drifting.
|
|
9
|
+
*/
|
|
10
|
+
const SECOND_MS = 1e3;
|
|
11
|
+
const MINUTE_MS = 60 * SECOND_MS;
|
|
12
|
+
const HOUR_MS = 60 * MINUTE_MS;
|
|
13
|
+
const DAY_MS = 24 * HOUR_MS;
|
|
14
|
+
const UNIT_MS = {
|
|
15
|
+
s: {
|
|
16
|
+
ms: SECOND_MS,
|
|
17
|
+
short: "s"
|
|
18
|
+
},
|
|
19
|
+
sec: {
|
|
20
|
+
ms: SECOND_MS,
|
|
21
|
+
short: "s"
|
|
22
|
+
},
|
|
23
|
+
secs: {
|
|
24
|
+
ms: SECOND_MS,
|
|
25
|
+
short: "s"
|
|
26
|
+
},
|
|
27
|
+
second: {
|
|
28
|
+
ms: SECOND_MS,
|
|
29
|
+
short: "s"
|
|
30
|
+
},
|
|
31
|
+
seconds: {
|
|
32
|
+
ms: SECOND_MS,
|
|
33
|
+
short: "s"
|
|
34
|
+
},
|
|
35
|
+
m: {
|
|
36
|
+
ms: MINUTE_MS,
|
|
37
|
+
short: "m"
|
|
38
|
+
},
|
|
39
|
+
min: {
|
|
40
|
+
ms: MINUTE_MS,
|
|
41
|
+
short: "m"
|
|
42
|
+
},
|
|
43
|
+
mins: {
|
|
44
|
+
ms: MINUTE_MS,
|
|
45
|
+
short: "m"
|
|
46
|
+
},
|
|
47
|
+
minute: {
|
|
48
|
+
ms: MINUTE_MS,
|
|
49
|
+
short: "m"
|
|
50
|
+
},
|
|
51
|
+
minutes: {
|
|
52
|
+
ms: MINUTE_MS,
|
|
53
|
+
short: "m"
|
|
54
|
+
},
|
|
55
|
+
h: {
|
|
56
|
+
ms: HOUR_MS,
|
|
57
|
+
short: "h"
|
|
58
|
+
},
|
|
59
|
+
hr: {
|
|
60
|
+
ms: HOUR_MS,
|
|
61
|
+
short: "h"
|
|
62
|
+
},
|
|
63
|
+
hrs: {
|
|
64
|
+
ms: HOUR_MS,
|
|
65
|
+
short: "h"
|
|
66
|
+
},
|
|
67
|
+
hour: {
|
|
68
|
+
ms: HOUR_MS,
|
|
69
|
+
short: "h"
|
|
70
|
+
},
|
|
71
|
+
hours: {
|
|
72
|
+
ms: HOUR_MS,
|
|
73
|
+
short: "h"
|
|
74
|
+
},
|
|
75
|
+
d: {
|
|
76
|
+
ms: DAY_MS,
|
|
77
|
+
short: "d"
|
|
78
|
+
},
|
|
79
|
+
day: {
|
|
80
|
+
ms: DAY_MS,
|
|
81
|
+
short: "d"
|
|
82
|
+
},
|
|
83
|
+
days: {
|
|
84
|
+
ms: DAY_MS,
|
|
85
|
+
short: "d"
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
const INTERVAL_RE = /^(\d+)\s*([a-z]+)$/i;
|
|
89
|
+
/** Parse `5m`, `2h`, `1 day`, `90 minutes` into milliseconds plus a normalized label. */
|
|
90
|
+
function parseInterval(text) {
|
|
91
|
+
const match = INTERVAL_RE.exec(text.trim());
|
|
92
|
+
if (!match) return { error: `Invalid interval "${text}". Use a number followed by a unit, e.g. 5m, 2h, 1d.` };
|
|
93
|
+
const value = Number(match[1]);
|
|
94
|
+
const unit = UNIT_MS[match[2].toLowerCase()];
|
|
95
|
+
if (!unit) return { error: `Unknown interval unit "${match[2]}". Use s, m, h, or d.` };
|
|
96
|
+
if (value <= 0) return { error: "Interval must be greater than zero." };
|
|
97
|
+
return {
|
|
98
|
+
ms: value * unit.ms,
|
|
99
|
+
label: `${value}${unit.short}`
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
const MINUTE_DIVISORS = [
|
|
103
|
+
1,
|
|
104
|
+
2,
|
|
105
|
+
3,
|
|
106
|
+
4,
|
|
107
|
+
5,
|
|
108
|
+
6,
|
|
109
|
+
10,
|
|
110
|
+
12,
|
|
111
|
+
15,
|
|
112
|
+
20,
|
|
113
|
+
30,
|
|
114
|
+
60
|
|
115
|
+
];
|
|
116
|
+
const HOUR_DIVISORS = [
|
|
117
|
+
1,
|
|
118
|
+
2,
|
|
119
|
+
3,
|
|
120
|
+
4,
|
|
121
|
+
6,
|
|
122
|
+
8,
|
|
123
|
+
12,
|
|
124
|
+
24
|
|
125
|
+
];
|
|
126
|
+
function nearest(candidates, target) {
|
|
127
|
+
return candidates.reduce((best, candidate) => Math.abs(candidate - target) < Math.abs(best - target) ? candidate : best);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Check that an interval fires on stable clock boundaries: whole minutes that
|
|
131
|
+
* divide the hour, whole hours that divide the day, or exactly one day.
|
|
132
|
+
*/
|
|
133
|
+
function validateInterval({ ms }) {
|
|
134
|
+
if (ms < MINUTE_MS) return {
|
|
135
|
+
error: "Schedules fire at most once per minute.",
|
|
136
|
+
suggestion: "1m"
|
|
137
|
+
};
|
|
138
|
+
if (ms % MINUTE_MS !== 0) {
|
|
139
|
+
const minutes = Math.round(ms / MINUTE_MS);
|
|
140
|
+
return {
|
|
141
|
+
error: "Interval must be a whole number of minutes.",
|
|
142
|
+
suggestion: `${Math.max(1, nearest(MINUTE_DIVISORS, minutes))}m`
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
const minutes = ms / MINUTE_MS;
|
|
146
|
+
if (minutes < 60) {
|
|
147
|
+
if (60 % minutes === 0) return { ok: true };
|
|
148
|
+
return {
|
|
149
|
+
error: `${minutes}m does not divide an hour evenly.`,
|
|
150
|
+
suggestion: `${nearest(MINUTE_DIVISORS, minutes)}m`
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
if (minutes % 60 !== 0) {
|
|
154
|
+
const hours = Math.round(minutes / 60);
|
|
155
|
+
return {
|
|
156
|
+
error: `${minutes}m is not a whole number of hours.`,
|
|
157
|
+
suggestion: hours < 24 ? `${nearest(HOUR_DIVISORS, hours)}h` : "1d"
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
const hours = minutes / 60;
|
|
161
|
+
if (hours < 24) {
|
|
162
|
+
if (24 % hours === 0) return { ok: true };
|
|
163
|
+
return {
|
|
164
|
+
error: `${hours}h does not divide a day evenly.`,
|
|
165
|
+
suggestion: `${nearest(HOUR_DIVISORS, hours)}h`
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
if (hours === 24) return { ok: true };
|
|
169
|
+
return {
|
|
170
|
+
error: "Intervals longer than one day are not supported.",
|
|
171
|
+
suggestion: "1d"
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/** Hour-and-longer cadences: which local wall-clock slot a minute belongs to. */
|
|
175
|
+
function hourSlotKey(date, stepHours) {
|
|
176
|
+
return ((date.getFullYear() * 12 + date.getMonth()) * 31 + date.getDate()) * 24 + Math.floor(date.getHours() / stepHours) * stepHours;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* The first boundary strictly after `after`, on the local wall clock
|
|
180
|
+
* (5m → :00, :05, ...; 2h → 00:00, 02:00, ...; 1d → midnight). `intervalMs`
|
|
181
|
+
* must pass {@link validateInterval}.
|
|
182
|
+
*
|
|
183
|
+
* Around daylight-saving changes this behaves like cron:
|
|
184
|
+
* - Sub-hour cadences follow the minute hand, so they keep firing every N real
|
|
185
|
+
* minutes through both the skipped and the repeated hour. Across a
|
|
186
|
+
* half-hour change, the gap between fires never exceeds the interval.
|
|
187
|
+
* - Hourly and daily cadences fire once per wall-clock slot. A boundary that
|
|
188
|
+
* falls in a skipped hour fires at the first minute after the jump (02:00 →
|
|
189
|
+
* 03:00), and a repeated hour does not fire a second time.
|
|
190
|
+
*
|
|
191
|
+
* Computing from `after` rather than from the previous fire means a late
|
|
192
|
+
* timer (sleep, busy event loop) skips missed boundaries instead of bursting
|
|
193
|
+
* to catch up.
|
|
194
|
+
*/
|
|
195
|
+
function nextFireTime(intervalMs, after) {
|
|
196
|
+
const cursor = /* @__PURE__ */ new Date(Math.floor(after / MINUTE_MS) * MINUTE_MS);
|
|
197
|
+
const stepMinutes = intervalMs / MINUTE_MS;
|
|
198
|
+
if (stepMinutes < 60) {
|
|
199
|
+
const latest = cursor.getTime() + intervalMs;
|
|
200
|
+
do
|
|
201
|
+
cursor.setTime(cursor.getTime() + MINUTE_MS);
|
|
202
|
+
while (cursor.getMinutes() % stepMinutes !== 0 && cursor.getTime() < latest);
|
|
203
|
+
return cursor.getTime();
|
|
204
|
+
}
|
|
205
|
+
const stepHours = stepMinutes / 60;
|
|
206
|
+
const startSlot = hourSlotKey(new Date(after), stepHours);
|
|
207
|
+
do
|
|
208
|
+
cursor.setTime(cursor.getTime() + MINUTE_MS);
|
|
209
|
+
while (hourSlotKey(cursor, stepHours) <= startSlot);
|
|
210
|
+
return cursor.getTime();
|
|
211
|
+
}
|
|
212
|
+
//#endregion
|
|
213
|
+
export { nextFireTime, parseInterval, validateInterval };
|
|
214
|
+
|
|
215
|
+
//# sourceMappingURL=interval.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interval.js","names":[],"sources":["../../src/schedules/interval.ts"],"sourcesContent":["/**\n * Interval parsing and fire-time math for `/schedules`.\n *\n * Users type `5m`, `2h`, `1 day`. Schedules fire on local wall-clock\n * boundaries (5m fires at :00, :05, ...), so only intervals that divide the\n * hour (minutes) or the day (hours) give a stable cadence; anything else is\n * rejected with the nearest valid suggestion instead of silently drifting.\n */\n\nconst SECOND_MS = 1_000;\nconst MINUTE_MS = 60 * SECOND_MS;\nconst HOUR_MS = 60 * MINUTE_MS;\nconst DAY_MS = 24 * HOUR_MS;\n\nexport type ParsedInterval = { ms: number; label: string };\nexport type IntervalError = { error: string };\n\nconst UNIT_MS: Record<string, { ms: number; short: string }> = {\n s: { ms: SECOND_MS, short: 's' },\n sec: { ms: SECOND_MS, short: 's' },\n secs: { ms: SECOND_MS, short: 's' },\n second: { ms: SECOND_MS, short: 's' },\n seconds: { ms: SECOND_MS, short: 's' },\n m: { ms: MINUTE_MS, short: 'm' },\n min: { ms: MINUTE_MS, short: 'm' },\n mins: { ms: MINUTE_MS, short: 'm' },\n minute: { ms: MINUTE_MS, short: 'm' },\n minutes: { ms: MINUTE_MS, short: 'm' },\n h: { ms: HOUR_MS, short: 'h' },\n hr: { ms: HOUR_MS, short: 'h' },\n hrs: { ms: HOUR_MS, short: 'h' },\n hour: { ms: HOUR_MS, short: 'h' },\n hours: { ms: HOUR_MS, short: 'h' },\n d: { ms: DAY_MS, short: 'd' },\n day: { ms: DAY_MS, short: 'd' },\n days: { ms: DAY_MS, short: 'd' },\n};\n\nconst INTERVAL_RE = /^(\\d+)\\s*([a-z]+)$/i;\n\n/** Parse `5m`, `2h`, `1 day`, `90 minutes` into milliseconds plus a normalized label. */\nexport function parseInterval(text: string): ParsedInterval | IntervalError {\n const match = INTERVAL_RE.exec(text.trim());\n if (!match) {\n return { error: `Invalid interval \"${text}\". Use a number followed by a unit, e.g. 5m, 2h, 1d.` };\n }\n const value = Number(match[1]);\n const unit = UNIT_MS[match[2]!.toLowerCase()];\n if (!unit) {\n return { error: `Unknown interval unit \"${match[2]}\". Use s, m, h, or d.` };\n }\n if (value <= 0) {\n return { error: 'Interval must be greater than zero.' };\n }\n return { ms: value * unit.ms, label: `${value}${unit.short}` };\n}\n\nexport type IntervalCheck = { ok: true } | { error: string; suggestion?: string };\n\nconst MINUTE_DIVISORS = [1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30, 60];\nconst HOUR_DIVISORS = [1, 2, 3, 4, 6, 8, 12, 24];\n\nfunction nearest(candidates: number[], target: number): number {\n return candidates.reduce((best, candidate) =>\n Math.abs(candidate - target) < Math.abs(best - target) ? candidate : best,\n );\n}\n\n/**\n * Check that an interval fires on stable clock boundaries: whole minutes that\n * divide the hour, whole hours that divide the day, or exactly one day.\n */\nexport function validateInterval({ ms }: { ms: number }): IntervalCheck {\n if (ms < MINUTE_MS) {\n return { error: 'Schedules fire at most once per minute.', suggestion: '1m' };\n }\n if (ms % MINUTE_MS !== 0) {\n const minutes = Math.round(ms / MINUTE_MS);\n return {\n error: 'Interval must be a whole number of minutes.',\n suggestion: `${Math.max(1, nearest(MINUTE_DIVISORS, minutes))}m`,\n };\n }\n const minutes = ms / MINUTE_MS;\n if (minutes < 60) {\n if (60 % minutes === 0) {\n return { ok: true };\n }\n return {\n error: `${minutes}m does not divide an hour evenly.`,\n suggestion: `${nearest(MINUTE_DIVISORS, minutes)}m`,\n };\n }\n if (minutes % 60 !== 0) {\n const hours = Math.round(minutes / 60);\n return {\n error: `${minutes}m is not a whole number of hours.`,\n suggestion: hours < 24 ? `${nearest(HOUR_DIVISORS, hours)}h` : '1d',\n };\n }\n const hours = minutes / 60;\n if (hours < 24) {\n if (24 % hours === 0) {\n return { ok: true };\n }\n return {\n error: `${hours}h does not divide a day evenly.`,\n suggestion: `${nearest(HOUR_DIVISORS, hours)}h`,\n };\n }\n if (hours === 24) {\n return { ok: true };\n }\n return {\n error: 'Intervals longer than one day are not supported.',\n suggestion: '1d',\n };\n}\n\n/** Hour-and-longer cadences: which local wall-clock slot a minute belongs to. */\nfunction hourSlotKey(date: Date, stepHours: number): number {\n return (\n ((date.getFullYear() * 12 + date.getMonth()) * 31 + date.getDate()) * 24 +\n Math.floor(date.getHours() / stepHours) * stepHours\n );\n}\n\n/**\n * The first boundary strictly after `after`, on the local wall clock\n * (5m → :00, :05, ...; 2h → 00:00, 02:00, ...; 1d → midnight). `intervalMs`\n * must pass {@link validateInterval}.\n *\n * Around daylight-saving changes this behaves like cron:\n * - Sub-hour cadences follow the minute hand, so they keep firing every N real\n * minutes through both the skipped and the repeated hour. Across a\n * half-hour change, the gap between fires never exceeds the interval.\n * - Hourly and daily cadences fire once per wall-clock slot. A boundary that\n * falls in a skipped hour fires at the first minute after the jump (02:00 →\n * 03:00), and a repeated hour does not fire a second time.\n *\n * Computing from `after` rather than from the previous fire means a late\n * timer (sleep, busy event loop) skips missed boundaries instead of bursting\n * to catch up.\n */\nexport function nextFireTime(intervalMs: number, after: number): number {\n // Truncate in UTC: local setters resolve a repeated hour to its first occurrence.\n const cursor = new Date(Math.floor(after / MINUTE_MS) * MINUTE_MS);\n const stepMinutes = intervalMs / MINUTE_MS;\n // Walk minute by minute: at most an hour for sub-hour cadences, ~a day otherwise.\n if (stepMinutes < 60) {\n // Never wait longer than one interval: a half-hour clock change (Lord Howe\n // Island) can otherwise shift the minute hand past the next boundary.\n const latest = cursor.getTime() + intervalMs;\n do cursor.setTime(cursor.getTime() + MINUTE_MS);\n while (cursor.getMinutes() % stepMinutes !== 0 && cursor.getTime() < latest);\n return cursor.getTime();\n }\n const stepHours = stepMinutes / 60;\n const startSlot = hourSlotKey(new Date(after), stepHours);\n do cursor.setTime(cursor.getTime() + MINUTE_MS);\n while (hourSlotKey(cursor, stepHours) <= startSlot);\n return cursor.getTime();\n}\n"],"mappings":";;;;;;;;;AASA,MAAM,YAAY;AAClB,MAAM,YAAY,KAAK;AACvB,MAAM,UAAU,KAAK;AACrB,MAAM,SAAS,KAAK;AAKpB,MAAM,UAAyD;CAC7D,GAAG;EAAE,IAAI;EAAW,OAAO;CAAI;CAC/B,KAAK;EAAE,IAAI;EAAW,OAAO;CAAI;CACjC,MAAM;EAAE,IAAI;EAAW,OAAO;CAAI;CAClC,QAAQ;EAAE,IAAI;EAAW,OAAO;CAAI;CACpC,SAAS;EAAE,IAAI;EAAW,OAAO;CAAI;CACrC,GAAG;EAAE,IAAI;EAAW,OAAO;CAAI;CAC/B,KAAK;EAAE,IAAI;EAAW,OAAO;CAAI;CACjC,MAAM;EAAE,IAAI;EAAW,OAAO;CAAI;CAClC,QAAQ;EAAE,IAAI;EAAW,OAAO;CAAI;CACpC,SAAS;EAAE,IAAI;EAAW,OAAO;CAAI;CACrC,GAAG;EAAE,IAAI;EAAS,OAAO;CAAI;CAC7B,IAAI;EAAE,IAAI;EAAS,OAAO;CAAI;CAC9B,KAAK;EAAE,IAAI;EAAS,OAAO;CAAI;CAC/B,MAAM;EAAE,IAAI;EAAS,OAAO;CAAI;CAChC,OAAO;EAAE,IAAI;EAAS,OAAO;CAAI;CACjC,GAAG;EAAE,IAAI;EAAQ,OAAO;CAAI;CAC5B,KAAK;EAAE,IAAI;EAAQ,OAAO;CAAI;CAC9B,MAAM;EAAE,IAAI;EAAQ,OAAO;CAAI;AACjC;AAEA,MAAM,cAAc;;AAGpB,SAAgB,cAAc,MAA8C;CAC1E,MAAM,QAAQ,YAAY,KAAK,KAAK,KAAK,CAAC;CAC1C,IAAI,CAAC,OACH,OAAO,EAAE,OAAO,qBAAqB,KAAK,sDAAsD;CAElG,MAAM,QAAQ,OAAO,MAAM,EAAE;CAC7B,MAAM,OAAO,QAAQ,MAAM,EAAE,CAAE,YAAY;CAC3C,IAAI,CAAC,MACH,OAAO,EAAE,OAAO,0BAA0B,MAAM,GAAG,uBAAuB;CAE5E,IAAI,SAAS,GACX,OAAO,EAAE,OAAO,sCAAsC;CAExD,OAAO;EAAE,IAAI,QAAQ,KAAK;EAAI,OAAO,GAAG,QAAQ,KAAK;CAAQ;AAC/D;AAIA,MAAM,kBAAkB;CAAC;CAAG;CAAG;CAAG;CAAG;CAAG;CAAG;CAAI;CAAI;CAAI;CAAI;CAAI;AAAE;AACjE,MAAM,gBAAgB;CAAC;CAAG;CAAG;CAAG;CAAG;CAAG;CAAG;CAAI;AAAE;AAE/C,SAAS,QAAQ,YAAsB,QAAwB;CAC7D,OAAO,WAAW,QAAQ,MAAM,cAC9B,KAAK,IAAI,YAAY,MAAM,IAAI,KAAK,IAAI,OAAO,MAAM,IAAI,YAAY,IACvE;AACF;;;;;AAMA,SAAgB,iBAAiB,EAAE,MAAqC;CACtE,IAAI,KAAK,WACP,OAAO;EAAE,OAAO;EAA2C,YAAY;CAAK;CAE9E,IAAI,KAAK,cAAc,GAAG;EACxB,MAAM,UAAU,KAAK,MAAM,KAAK,SAAS;EACzC,OAAO;GACL,OAAO;GACP,YAAY,GAAG,KAAK,IAAI,GAAG,QAAQ,iBAAiB,OAAO,CAAC,EAAE;EAChE;CACF;CACA,MAAM,UAAU,KAAK;CACrB,IAAI,UAAU,IAAI;EAChB,IAAI,KAAK,YAAY,GACnB,OAAO,EAAE,IAAI,KAAK;EAEpB,OAAO;GACL,OAAO,GAAG,QAAQ;GAClB,YAAY,GAAG,QAAQ,iBAAiB,OAAO,EAAE;EACnD;CACF;CACA,IAAI,UAAU,OAAO,GAAG;EACtB,MAAM,QAAQ,KAAK,MAAM,UAAU,EAAE;EACrC,OAAO;GACL,OAAO,GAAG,QAAQ;GAClB,YAAY,QAAQ,KAAK,GAAG,QAAQ,eAAe,KAAK,EAAE,KAAK;EACjE;CACF;CACA,MAAM,QAAQ,UAAU;CACxB,IAAI,QAAQ,IAAI;EACd,IAAI,KAAK,UAAU,GACjB,OAAO,EAAE,IAAI,KAAK;EAEpB,OAAO;GACL,OAAO,GAAG,MAAM;GAChB,YAAY,GAAG,QAAQ,eAAe,KAAK,EAAE;EAC/C;CACF;CACA,IAAI,UAAU,IACZ,OAAO,EAAE,IAAI,KAAK;CAEpB,OAAO;EACL,OAAO;EACP,YAAY;CACd;AACF;;AAGA,SAAS,YAAY,MAAY,WAA2B;CAC1D,SACI,KAAK,YAAY,IAAI,KAAK,KAAK,SAAS,KAAK,KAAK,KAAK,QAAQ,KAAK,KACtE,KAAK,MAAM,KAAK,SAAS,IAAI,SAAS,IAAI;AAE9C;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,aAAa,YAAoB,OAAuB;CAEtE,MAAM,yBAAS,IAAI,KAAK,KAAK,MAAM,QAAQ,SAAS,IAAI,SAAS;CACjE,MAAM,cAAc,aAAa;CAEjC,IAAI,cAAc,IAAI;EAGpB,MAAM,SAAS,OAAO,QAAQ,IAAI;EAClC;GAAG,OAAO,QAAQ,OAAO,QAAQ,IAAI,SAAS;SACvC,OAAO,WAAW,IAAI,gBAAgB,KAAK,OAAO,QAAQ,IAAI;EACrE,OAAO,OAAO,QAAQ;CACxB;CACA,MAAM,YAAY,cAAc;CAChC,MAAM,YAAY,YAAY,IAAI,KAAK,KAAK,GAAG,SAAS;CACxD;EAAG,OAAO,QAAQ,OAAO,QAAQ,IAAI,SAAS;QACvC,YAAY,QAAQ,SAAS,KAAK;CACzC,OAAO,OAAO,QAAQ;AACxB"}
|