@mastra/code-sdk 0.0.0-agent-tags-alpha-20261125185303
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +32 -0
- package/README.md +284 -0
- package/dist/acp/agent.d.ts +48 -0
- package/dist/acp/agent.js +414 -0
- package/dist/acp/errors.d.ts +3 -0
- package/dist/acp/errors.js +11 -0
- package/dist/acp/event-mapper.d.ts +28 -0
- package/dist/acp/event-mapper.js +274 -0
- package/dist/acp/index.d.ts +9 -0
- package/dist/acp/index.js +21 -0
- package/dist/acp/runtime.d.ts +5 -0
- package/dist/acp/runtime.js +91 -0
- package/dist/acp/server.d.ts +4 -0
- package/dist/acp/server.js +35 -0
- package/dist/acp/skills.d.ts +6 -0
- package/dist/acp/skills.js +30 -0
- package/dist/acp.d.ts +2 -0
- package/dist/acp.js +1 -0
- package/dist/agent-connections/messaging-processor.d.ts +17 -0
- package/dist/agent-connections/messaging-processor.js +131 -0
- package/dist/agent-connections/ownership.d.ts +24 -0
- package/dist/agent-connections/ownership.js +96 -0
- package/dist/agent-connections/registry.d.ts +20 -0
- package/dist/agent-connections/registry.js +167 -0
- package/dist/agent-connections/session-advertisement.d.ts +27 -0
- package/dist/agent-connections/session-advertisement.js +86 -0
- package/dist/agent-connections/signal-provider.d.ts +141 -0
- package/dist/agent-connections/signal-provider.js +35 -0
- package/dist/agent-connections/state-processor.d.ts +23 -0
- package/dist/agent-connections/state-processor.js +270 -0
- package/dist/agent-connections/thread-state.d.ts +41 -0
- package/dist/agent-connections/thread-state.js +157 -0
- package/dist/agent-connections/tools.d.ts +133 -0
- package/dist/agent-connections/tools.js +616 -0
- package/dist/agent-connections/types.d.ts +99 -0
- package/dist/agent-connections/types.js +4 -0
- package/dist/agent-connections/untrusted-text.d.ts +5 -0
- package/dist/agent-connections/untrusted-text.js +19 -0
- package/dist/agents/background-completion-events.d.ts +16 -0
- package/dist/agents/background-completion-events.js +16 -0
- package/dist/agents/background-completion.d.ts +22 -0
- package/dist/agents/background-completion.js +73 -0
- package/dist/agents/context-audit.d.ts +84 -0
- package/dist/agents/context-audit.js +115 -0
- package/dist/agents/credential-resolver.d.ts +74 -0
- package/dist/agents/credential-resolver.js +142 -0
- package/dist/agents/custom-provider-source.d.ts +35 -0
- package/dist/agents/custom-provider-source.js +22 -0
- package/dist/agents/fastembed-subprocess.d.ts +52 -0
- package/dist/agents/fastembed-subprocess.js +282 -0
- package/dist/agents/instructions.d.ts +42 -0
- package/dist/agents/instructions.js +69 -0
- package/dist/agents/mastracode-gateway.d.ts +85 -0
- package/dist/agents/mastracode-gateway.js +500 -0
- package/dist/agents/memory.d.ts +36 -0
- package/dist/agents/memory.js +248 -0
- package/dist/agents/model.d.ts +158 -0
- package/dist/agents/model.js +382 -0
- package/dist/agents/modes/build.d.ts +12 -0
- package/dist/agents/modes/build.js +33 -0
- package/dist/agents/modes/explore.d.ts +10 -0
- package/dist/agents/modes/explore.js +25 -0
- package/dist/agents/modes/plan.d.ts +8 -0
- package/dist/agents/modes/plan.js +43 -0
- package/dist/agents/prompts/agent-instructions.d.ts +122 -0
- package/dist/agents/prompts/agent-instructions.js +617 -0
- package/dist/agents/prompts/build.d.ts +12 -0
- package/dist/agents/prompts/build.js +73 -0
- package/dist/agents/prompts/fast.d.ts +5 -0
- package/dist/agents/prompts/fast.js +23 -0
- package/dist/agents/prompts/index.d.ts +61 -0
- package/dist/agents/prompts/index.js +141 -0
- package/dist/agents/prompts/model.d.ts +5 -0
- package/dist/agents/prompts/model.js +20 -0
- package/dist/agents/prompts/plan.d.ts +11 -0
- package/dist/agents/prompts/plan.js +132 -0
- package/dist/agents/prompts/tool-guidance.d.ts +18 -0
- package/dist/agents/prompts/tool-guidance.js +158 -0
- package/dist/agents/sandbox-filesystem.d.ts +232 -0
- package/dist/agents/sandbox-filesystem.js +851 -0
- package/dist/agents/subagents/execute.d.ts +3 -0
- package/dist/agents/subagents/execute.js +24 -0
- package/dist/agents/subagents/explore.d.ts +3 -0
- package/dist/agents/subagents/explore.js +15 -0
- package/dist/agents/subagents/index.d.ts +6 -0
- package/dist/agents/subagents/index.js +15 -0
- package/dist/agents/subagents/plan.d.ts +3 -0
- package/dist/agents/subagents/plan.js +15 -0
- package/dist/agents/thread-caveman-state.d.ts +17 -0
- package/dist/agents/thread-caveman-state.js +104 -0
- package/dist/agents/tool-availability.d.ts +17 -0
- package/dist/agents/tool-availability.js +134 -0
- package/dist/agents/tools.d.ts +37 -0
- package/dist/agents/tools.js +154 -0
- package/dist/agents/workflow-builder-agent.d.ts +2 -0
- package/dist/agents/workflow-builder-agent.js +79 -0
- package/dist/agents/workspace.d.ts +35 -0
- package/dist/agents/workspace.js +207 -0
- package/dist/analytics.d.ts +18 -0
- package/dist/analytics.js +159 -0
- package/dist/auth/account-rotation-processor.d.ts +210 -0
- package/dist/auth/account-rotation-processor.js +662 -0
- package/dist/auth/account-routing-context.d.ts +17 -0
- package/dist/auth/account-routing-context.js +38 -0
- package/dist/auth/authorization-input.d.ts +16 -0
- package/dist/auth/authorization-input.js +39 -0
- package/dist/auth/device-code.d.ts +93 -0
- package/dist/auth/device-code.js +126 -0
- package/dist/auth/index.d.ts +13 -0
- package/dist/auth/index.js +9 -0
- package/dist/auth/pkce.d.ts +13 -0
- package/dist/auth/pkce.js +29 -0
- package/dist/auth/provider-auth-error.d.ts +24 -0
- package/dist/auth/provider-auth-error.js +44 -0
- package/dist/auth/providers/anthropic.d.ts +40 -0
- package/dist/auth/providers/anthropic.js +117 -0
- package/dist/auth/providers/github-copilot.d.ts +154 -0
- package/dist/auth/providers/github-copilot.js +359 -0
- package/dist/auth/providers/kimi-coding.d.ts +38 -0
- package/dist/auth/providers/kimi-coding.js +225 -0
- package/dist/auth/providers/openai-codex.d.ts +141 -0
- package/dist/auth/providers/openai-codex.js +531 -0
- package/dist/auth/providers/xai.d.ts +64 -0
- package/dist/auth/providers/xai.js +223 -0
- package/dist/auth/storage.d.ts +222 -0
- package/dist/auth/storage.js +805 -0
- package/dist/auth/types.d.ts +164 -0
- package/dist/auth/types.js +1 -0
- package/dist/clipboard/index.d.ts +26 -0
- package/dist/clipboard/index.js +224 -0
- package/dist/constants.d.ts +29 -0
- package/dist/constants.js +34 -0
- package/dist/error-classification.d.ts +10 -0
- package/dist/error-classification.js +19 -0
- package/dist/evals/context-builder.d.ts +41 -0
- package/dist/evals/context-builder.js +156 -0
- package/dist/evals/index.d.ts +4 -0
- package/dist/evals/index.js +5 -0
- package/dist/evals/scorers/classify-command.d.ts +30 -0
- package/dist/evals/scorers/classify-command.js +61 -0
- package/dist/evals/scorers/efficiency.d.ts +44 -0
- package/dist/evals/scorers/efficiency.js +256 -0
- package/dist/evals/scorers/extract-tools.d.ts +25 -0
- package/dist/evals/scorers/extract-tools.js +57 -0
- package/dist/evals/scorers/index.d.ts +3 -0
- package/dist/evals/scorers/index.js +3 -0
- package/dist/evals/scorers/outcome.d.ts +49 -0
- package/dist/evals/scorers/outcome.js +360 -0
- package/dist/experimental-agent.d.ts +19 -0
- package/dist/experimental-agent.js +45 -0
- package/dist/factory/client.d.ts +44 -0
- package/dist/factory/client.js +110 -0
- package/dist/factory/remote-controller.d.ts +34 -0
- package/dist/factory/remote-controller.js +40 -0
- package/dist/factory/remote-session.d.ts +210 -0
- package/dist/factory/remote-session.js +415 -0
- package/dist/goal-manager.d.ts +114 -0
- package/dist/goal-manager.js +351 -0
- package/dist/goal-signal.d.ts +14 -0
- package/dist/goal-signal.js +14 -0
- package/dist/headless/cli.d.ts +55 -0
- package/dist/headless/cli.js +261 -0
- package/dist/headless/flags.d.ts +33 -0
- package/dist/headless/flags.js +207 -0
- package/dist/headless/format.d.ts +41 -0
- package/dist/headless/format.js +94 -0
- package/dist/headless/index.d.ts +25 -0
- package/dist/headless/index.js +6 -0
- package/dist/headless/policy.d.ts +17 -0
- package/dist/headless/policy.js +39 -0
- package/dist/headless/run-mc.d.ts +7 -0
- package/dist/headless/run-mc.js +438 -0
- package/dist/headless/types.d.ts +175 -0
- package/dist/headless/types.js +16 -0
- package/dist/hooks/config.d.ts +11 -0
- package/dist/hooks/config.js +77 -0
- package/dist/hooks/executor.d.ts +13 -0
- package/dist/hooks/executor.js +128 -0
- package/dist/hooks/index.d.ts +6 -0
- package/dist/hooks/index.js +5 -0
- package/dist/hooks/manager.d.ts +75 -0
- package/dist/hooks/manager.js +289 -0
- package/dist/hooks/types.d.ts +180 -0
- package/dist/hooks/types.js +5 -0
- package/dist/index.d.ts +537 -0
- package/dist/index.js +1399 -0
- package/dist/ipc/ipc-reporter.d.ts +14 -0
- package/dist/ipc/ipc-reporter.js +18 -0
- package/dist/knowledge-inspector.d.ts +139 -0
- package/dist/knowledge-inspector.js +533 -0
- package/dist/knowledge-scope-id.d.ts +7 -0
- package/dist/knowledge-scope-id.js +10 -0
- package/dist/knowledge-scope.d.ts +41 -0
- package/dist/knowledge-scope.js +85 -0
- package/dist/lsp/client.d.ts +56 -0
- package/dist/lsp/client.js +248 -0
- package/dist/lsp/index.d.ts +4 -0
- package/dist/lsp/index.js +4 -0
- package/dist/lsp/language.d.ts +9 -0
- package/dist/lsp/language.js +41 -0
- package/dist/lsp/manager.d.ts +34 -0
- package/dist/lsp/manager.js +79 -0
- package/dist/lsp/server.d.ts +27 -0
- package/dist/lsp/server.js +158 -0
- package/dist/lsp/workspace.d.ts +9 -0
- package/dist/lsp/workspace.js +52 -0
- package/dist/mcp/config.d.ts +77 -0
- package/dist/mcp/config.js +313 -0
- package/dist/mcp/index.d.ts +6 -0
- package/dist/mcp/index.js +3 -0
- package/dist/mcp/manager.d.ts +104 -0
- package/dist/mcp/manager.js +693 -0
- package/dist/mcp/state.d.ts +35 -0
- package/dist/mcp/state.js +94 -0
- package/dist/mcp/types.d.ts +139 -0
- package/dist/mcp/types.js +1 -0
- package/dist/onboarding/custom-packs.d.ts +7 -0
- package/dist/onboarding/custom-packs.js +17 -0
- package/dist/onboarding/custom-providers.d.ts +4 -0
- package/dist/onboarding/custom-providers.js +27 -0
- package/dist/onboarding/index.d.ts +5 -0
- package/dist/onboarding/index.js +3 -0
- package/dist/onboarding/om-settings.d.ts +47 -0
- package/dist/onboarding/om-settings.js +80 -0
- package/dist/onboarding/pack-activation.d.ts +43 -0
- package/dist/onboarding/pack-activation.js +105 -0
- package/dist/onboarding/packs.d.ts +106 -0
- package/dist/onboarding/packs.js +283 -0
- package/dist/onboarding/settings.d.ts +563 -0
- package/dist/onboarding/settings.js +1110 -0
- package/dist/permissions.d.ts +55 -0
- package/dist/permissions.js +139 -0
- package/dist/platform/index.d.ts +74 -0
- package/dist/platform/index.js +199 -0
- package/dist/plugin.d.ts +156 -0
- package/dist/plugin.js +27 -0
- package/dist/plugins/dependencies.d.ts +9 -0
- package/dist/plugins/dependencies.js +84 -0
- package/dist/plugins/install.d.ts +21 -0
- package/dist/plugins/install.js +187 -0
- package/dist/plugins/loader.d.ts +25 -0
- package/dist/plugins/loader.js +264 -0
- package/dist/plugins/manager.d.ts +115 -0
- package/dist/plugins/manager.js +507 -0
- package/dist/plugins/manifest.d.ts +14 -0
- package/dist/plugins/manifest.js +47 -0
- package/dist/plugins/package-link.d.ts +3 -0
- package/dist/plugins/package-link.js +58 -0
- package/dist/plugins/paths.d.ts +10 -0
- package/dist/plugins/paths.js +22 -0
- package/dist/plugins/registry.d.ts +8 -0
- package/dist/plugins/registry.js +109 -0
- package/dist/plugins/scaffold.d.ts +10 -0
- package/dist/plugins/scaffold.js +115 -0
- package/dist/plugins/signal-lane.d.ts +59 -0
- package/dist/plugins/signal-lane.js +163 -0
- package/dist/plugins/types.d.ts +95 -0
- package/dist/plugins/types.js +1 -0
- package/dist/process-memory-diagnostics.d.ts +136 -0
- package/dist/process-memory-diagnostics.js +497 -0
- package/dist/processors/plan-rejection-abort.d.ts +16 -0
- package/dist/processors/plan-rejection-abort.js +62 -0
- package/dist/providers/amazon-bedrock-gateway.d.ts +47 -0
- package/dist/providers/amazon-bedrock-gateway.js +142 -0
- package/dist/providers/amazon-bedrock.d.ts +28 -0
- package/dist/providers/amazon-bedrock.js +99 -0
- package/dist/providers/anthropic-prompt-cache.d.ts +19 -0
- package/dist/providers/anthropic-prompt-cache.js +8 -0
- package/dist/providers/anthropic-thinking.d.ts +5 -0
- package/dist/providers/anthropic-thinking.js +22 -0
- package/dist/providers/claude-max.d.ts +67 -0
- package/dist/providers/claude-max.js +232 -0
- package/dist/providers/github-copilot-gateway.d.ts +35 -0
- package/dist/providers/github-copilot-gateway.js +58 -0
- package/dist/providers/github-copilot.d.ts +60 -0
- package/dist/providers/github-copilot.js +320 -0
- package/dist/providers/google-thinking.d.ts +31 -0
- package/dist/providers/google-thinking.js +64 -0
- package/dist/providers/google-vertex-gateway.d.ts +23 -0
- package/dist/providers/google-vertex-gateway.js +49 -0
- package/dist/providers/google-vertex.d.ts +6 -0
- package/dist/providers/google-vertex.js +51 -0
- package/dist/providers/kimi-coding.d.ts +14 -0
- package/dist/providers/kimi-coding.js +80 -0
- package/dist/providers/model-ids.d.ts +53 -0
- package/dist/providers/model-ids.js +132 -0
- package/dist/providers/openai-codex.d.ts +114 -0
- package/dist/providers/openai-codex.js +427 -0
- package/dist/providers/provider-thinking.d.ts +23 -0
- package/dist/providers/provider-thinking.js +61 -0
- package/dist/providers/thinking-request.d.ts +14 -0
- package/dist/providers/thinking-request.js +87 -0
- package/dist/providers/xai.d.ts +33 -0
- package/dist/providers/xai.js +72 -0
- package/dist/schedules/index.d.ts +10 -0
- package/dist/schedules/index.js +6 -0
- package/dist/schedules/interval.d.ts +49 -0
- package/dist/schedules/interval.js +212 -0
- package/dist/schedules/prompt.d.ts +36 -0
- package/dist/schedules/prompt.js +36 -0
- package/dist/schedules/run-script.d.ts +8 -0
- package/dist/schedules/run-script.js +80 -0
- package/dist/schedules/scheduler.d.ts +101 -0
- package/dist/schedules/scheduler.js +167 -0
- package/dist/schedules/tools.d.ts +57 -0
- package/dist/schedules/tools.js +217 -0
- package/dist/schema.d.ts +499 -0
- package/dist/schema.js +131 -0
- package/dist/theme-palette.d.ts +17 -0
- package/dist/theme-palette.js +18 -0
- package/dist/thinking-catalog.d.ts +4 -0
- package/dist/thinking-catalog.js +13 -0
- package/dist/thinking.d.ts +37 -0
- package/dist/thinking.js +134 -0
- package/dist/tool-names.d.ts +77 -0
- package/dist/tool-names.js +53 -0
- package/dist/tools/index.d.ts +6 -0
- package/dist/tools/index.js +3 -0
- package/dist/tools/request-sandbox-access.d.ts +6 -0
- package/dist/tools/request-sandbox-access.js +80 -0
- package/dist/tools/utils.d.ts +20 -0
- package/dist/tools/utils.js +31 -0
- package/dist/tools/web-search.d.ts +116 -0
- package/dist/tools/web-search.js +158 -0
- package/dist/tools/workflows/create-workflow.d.ts +7 -0
- package/dist/tools/workflows/create-workflow.js +82 -0
- package/dist/tools/workflows/delete-workflow.d.ts +7 -0
- package/dist/tools/workflows/delete-workflow.js +18 -0
- package/dist/tools/workflows/ephemeral-memory.d.ts +28 -0
- package/dist/tools/workflows/ephemeral-memory.js +41 -0
- package/dist/tools/workflows/extract-json-schema.d.ts +12 -0
- package/dist/tools/workflows/extract-json-schema.js +19 -0
- package/dist/tools/workflows/get-workflow.d.ts +11 -0
- package/dist/tools/workflows/get-workflow.js +31 -0
- package/dist/tools/workflows/list-available-agents.d.ts +8 -0
- package/dist/tools/workflows/list-available-agents.js +29 -0
- package/dist/tools/workflows/list-available-classifiers.d.ts +19 -0
- package/dist/tools/workflows/list-available-classifiers.js +53 -0
- package/dist/tools/workflows/list-available-tools.d.ts +9 -0
- package/dist/tools/workflows/list-available-tools.js +37 -0
- package/dist/tools/workflows/list-available-workflows.d.ts +9 -0
- package/dist/tools/workflows/list-available-workflows.js +29 -0
- package/dist/tools/workflows/list-workflows.d.ts +9 -0
- package/dist/tools/workflows/list-workflows.js +30 -0
- package/dist/tools/workflows/run-workflow.d.ts +9 -0
- package/dist/tools/workflows/run-workflow.js +49 -0
- package/dist/tools/workflows/save-workflow.d.ts +1125 -0
- package/dist/tools/workflows/save-workflow.js +25 -0
- package/dist/tools/workflows/tool-ids.d.ts +16 -0
- package/dist/tools/workflows/tool-ids.js +17 -0
- package/dist/utils/binaries.d.ts +7 -0
- package/dist/utils/binaries.js +97 -0
- package/dist/utils/debug-log.d.ts +12 -0
- package/dist/utils/debug-log.js +56 -0
- package/dist/utils/discarding-scores-storage.d.ts +33 -0
- package/dist/utils/discarding-scores-storage.js +51 -0
- package/dist/utils/errors.d.ts +36 -0
- package/dist/utils/errors.js +215 -0
- package/dist/utils/gateway-sync.d.ts +26 -0
- package/dist/utils/gateway-sync.js +58 -0
- package/dist/utils/local-observability.d.ts +19 -0
- package/dist/utils/local-observability.js +54 -0
- package/dist/utils/maintenance-lock.d.ts +42 -0
- package/dist/utils/maintenance-lock.js +196 -0
- package/dist/utils/notification-dispatch.d.ts +74 -0
- package/dist/utils/notification-dispatch.js +128 -0
- package/dist/utils/open-url.d.ts +10 -0
- package/dist/utils/open-url.js +27 -0
- package/dist/utils/path-security.d.ts +2 -0
- package/dist/utils/path-security.js +7 -0
- package/dist/utils/plan-diff.d.ts +25 -0
- package/dist/utils/plan-diff.js +59 -0
- package/dist/utils/plans.d.ts +61 -0
- package/dist/utils/plans.js +120 -0
- package/dist/utils/project.d.ts +160 -0
- package/dist/utils/project.js +361 -0
- package/dist/utils/prune-cli.d.ts +24 -0
- package/dist/utils/prune-cli.js +124 -0
- package/dist/utils/signals-pubsub.d.ts +103 -0
- package/dist/utils/signals-pubsub.js +409 -0
- package/dist/utils/slash-command-loader.d.ts +52 -0
- package/dist/utils/slash-command-loader.js +139 -0
- package/dist/utils/slash-command-processor.d.ts +14 -0
- package/dist/utils/slash-command-processor.js +106 -0
- package/dist/utils/stdin-pipe.d.ts +33 -0
- package/dist/utils/stdin-pipe.js +93 -0
- package/dist/utils/storage-factory.d.ts +50 -0
- package/dist/utils/storage-factory.js +118 -0
- package/dist/utils/storage-maintenance.d.ts +121 -0
- package/dist/utils/storage-maintenance.js +352 -0
- package/dist/utils/thread-lock.d.ts +26 -0
- package/dist/utils/thread-lock.js +109 -0
- package/dist/utils/token-estimator.d.ts +3 -0
- package/dist/utils/token-estimator.js +19 -0
- package/dist/utils/update-check.d.ts +151 -0
- package/dist/utils/update-check.js +430 -0
- package/dist/utils/wake-session.d.ts +44 -0
- package/dist/utils/wake-session.js +83 -0
- package/dist/voice/stt-registry.d.ts +67 -0
- package/dist/voice/stt-registry.js +144 -0
- package/dist/voice/transcribe.d.ts +10 -0
- package/dist/voice/transcribe.js +75 -0
- package/dist/workflows/register-primitives.d.ts +52 -0
- package/dist/workflows/register-primitives.js +40 -0
- package/dist/workflows/service.d.ts +64 -0
- package/dist/workflows/service.js +50 -0
- package/package.json +117 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-id helpers shared by the model gateway and the browser settings
|
|
3
|
+
* module. Kept dependency-free so neither side has to import the other.
|
|
4
|
+
*/
|
|
5
|
+
export declare const OPENAI_PREFIX = "openai/";
|
|
6
|
+
export declare const ANTHROPIC_PREFIX = "anthropic/";
|
|
7
|
+
export declare const MASTRA_GATEWAY_PREFIX = "mastra/";
|
|
8
|
+
/** Anthropic's API only accepts dashed ids (`claude-opus-4-6`), but catalogs may list dotted ones. */
|
|
9
|
+
export declare function normalizeAnthropicModelId(modelId: string): string;
|
|
10
|
+
export declare function stripMastraGatewayPrefix(modelId: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Kimi For Coding subscriptions are served from `api.kimi.com`, which models.dev
|
|
13
|
+
* lists as `kimi-code-plan-cn`. Mastra Code augments that provider with the
|
|
14
|
+
* Kimi OAuth/API-key credential instead of defining its own.
|
|
15
|
+
*/
|
|
16
|
+
export declare const KIMI_CODING_PROVIDER_ID = "kimi-code-plan-cn";
|
|
17
|
+
/** Credential id the Kimi login stores accounts under. */
|
|
18
|
+
export declare const KIMI_CODING_CREDENTIAL_ID = "kimi-for-coding";
|
|
19
|
+
export declare function normalizeLegacyProviderId(providerId: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Map model ids saved by older Mastra Code versions (packs, OM settings,
|
|
22
|
+
* thread metadata) to the current catalog id:
|
|
23
|
+
* `mastracode/kimi-for-coding/k3` and `kimi-for-coding/k3` → `kimi-code-plan-cn/k3`,
|
|
24
|
+
* `mastracode/github-copilot/<m>` → `github-copilot/<m>`,
|
|
25
|
+
* `mastracode/amazon-bedrock/<m>` → `amazon-bedrock/<m>`.
|
|
26
|
+
*/
|
|
27
|
+
export declare function normalizeLegacyModelId(modelId: string): string;
|
|
28
|
+
/** Credential-store id that authenticates a catalog provider id. */
|
|
29
|
+
export declare function getCredentialProviderId(providerId: string): string;
|
|
30
|
+
export type CodexServiceTier = 'fast';
|
|
31
|
+
/** `:fast` is reserved on native OpenAI selections, not a catalog model suffix. */
|
|
32
|
+
export declare function parseCodexModelSelection(modelId: string): {
|
|
33
|
+
modelId: string;
|
|
34
|
+
codexServiceTier?: CodexServiceTier;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Adds a `<model>:fast` entry right after each connected OpenAI model that has
|
|
38
|
+
* a Fast tier, when OpenAI is signed in with Codex (Fast has no effect with an
|
|
39
|
+
* API key). Fast entries already in the list are replaced.
|
|
40
|
+
*/
|
|
41
|
+
export declare function withCodexFastModels<T extends {
|
|
42
|
+
id: string;
|
|
43
|
+
modelName: string;
|
|
44
|
+
hasApiKey: boolean;
|
|
45
|
+
}>(models: T[], { codexOAuth }: {
|
|
46
|
+
codexOAuth: boolean;
|
|
47
|
+
}): T[];
|
|
48
|
+
/** Prefer the exact selection if both standard and Fast entries for a model exist. */
|
|
49
|
+
export declare function findRouteModelIndex(entries: Array<{
|
|
50
|
+
modelId?: unknown;
|
|
51
|
+
}>, selectionId: unknown): number;
|
|
52
|
+
export declare function remapOpenAIModelForCodexOAuth(modelId: string): string;
|
|
53
|
+
//# sourceMappingURL=model-ids.d.ts.map
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// src/providers/model-ids.ts
|
|
2
|
+
/**
|
|
3
|
+
* Model-id helpers shared by the model gateway and the browser settings
|
|
4
|
+
* module. Kept dependency-free so neither side has to import the other.
|
|
5
|
+
*/
|
|
6
|
+
const OPENAI_PREFIX = "openai/";
|
|
7
|
+
const ANTHROPIC_PREFIX = "anthropic/";
|
|
8
|
+
const MASTRA_GATEWAY_PREFIX = "mastra/";
|
|
9
|
+
/** Anthropic's API only accepts dashed ids (`claude-opus-4-6`), but catalogs may list dotted ones. */
|
|
10
|
+
function normalizeAnthropicModelId(modelId) {
|
|
11
|
+
return modelId.replace(/\.(?=\d)/g, "-");
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The Codex ChatGPT-account endpoint serves some OpenAI models only under a
|
|
15
|
+
* `-codex` id. Applied wherever a model id is sent over Codex OAuth (chat
|
|
16
|
+
* agents and Stagehand alike) so both paths hit the same upstream model.
|
|
17
|
+
*/
|
|
18
|
+
const CODEX_OPENAI_MODEL_REMAPS = {
|
|
19
|
+
"gpt-5.3": "gpt-5.3-codex",
|
|
20
|
+
"gpt-5.2": "gpt-5.2-codex",
|
|
21
|
+
"gpt-5.1": "gpt-5.1-codex",
|
|
22
|
+
"gpt-5.1-mini": "gpt-5.1-codex-mini",
|
|
23
|
+
"gpt-5": "gpt-5-codex"
|
|
24
|
+
};
|
|
25
|
+
function stripMastraGatewayPrefix(modelId) {
|
|
26
|
+
return modelId.startsWith("mastra/") ? modelId.substring(7) : modelId;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Kimi For Coding subscriptions are served from `api.kimi.com`, which models.dev
|
|
30
|
+
* lists as `kimi-code-plan-cn`. Mastra Code augments that provider with the
|
|
31
|
+
* Kimi OAuth/API-key credential instead of defining its own.
|
|
32
|
+
*/
|
|
33
|
+
const KIMI_CODING_PROVIDER_ID = "kimi-code-plan-cn";
|
|
34
|
+
/** Credential id the Kimi login stores accounts under. */
|
|
35
|
+
const KIMI_CODING_CREDENTIAL_ID = "kimi-for-coding";
|
|
36
|
+
/** Providers Mastra Code used to catalog as `mastracode/<provider>/<model>`. */
|
|
37
|
+
const LEGACY_MASTRACODE_NAMESPACED_PROVIDERS = /* @__PURE__ */ new Set([
|
|
38
|
+
"amazon-bedrock",
|
|
39
|
+
"github-copilot",
|
|
40
|
+
KIMI_CODING_CREDENTIAL_ID
|
|
41
|
+
]);
|
|
42
|
+
/** Provider ids Mastra Code defined itself before augmenting the models.dev provider. */
|
|
43
|
+
const LEGACY_PROVIDER_IDS = { [KIMI_CODING_CREDENTIAL_ID]: KIMI_CODING_PROVIDER_ID };
|
|
44
|
+
function normalizeLegacyProviderId(providerId) {
|
|
45
|
+
return LEGACY_PROVIDER_IDS[providerId] ?? providerId;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Map model ids saved by older Mastra Code versions (packs, OM settings,
|
|
49
|
+
* thread metadata) to the current catalog id:
|
|
50
|
+
* `mastracode/kimi-for-coding/k3` and `kimi-for-coding/k3` → `kimi-code-plan-cn/k3`,
|
|
51
|
+
* `mastracode/github-copilot/<m>` → `github-copilot/<m>`,
|
|
52
|
+
* `mastracode/amazon-bedrock/<m>` → `amazon-bedrock/<m>`.
|
|
53
|
+
*/
|
|
54
|
+
function normalizeLegacyModelId(modelId) {
|
|
55
|
+
let normalized = modelId;
|
|
56
|
+
const namespacedProvider = normalized.startsWith("mastracode/") ? normalized.split("/", 3)[1] : void 0;
|
|
57
|
+
if (namespacedProvider && LEGACY_MASTRACODE_NAMESPACED_PROVIDERS.has(namespacedProvider)) normalized = normalized.slice(11);
|
|
58
|
+
const slash = normalized.indexOf("/");
|
|
59
|
+
if (slash <= 0) return normalized;
|
|
60
|
+
return `${normalizeLegacyProviderId(normalized.slice(0, slash))}${normalized.slice(slash)}`;
|
|
61
|
+
}
|
|
62
|
+
/** Credential-store id that authenticates a catalog provider id. */
|
|
63
|
+
function getCredentialProviderId(providerId) {
|
|
64
|
+
if (providerId === "openai") return "openai-codex";
|
|
65
|
+
if (providerId === "kimi-code-plan-cn") return KIMI_CODING_CREDENTIAL_ID;
|
|
66
|
+
return providerId;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* OpenAI models with a Fast tier on Codex sign-in, per OpenAI's Codex speed docs
|
|
70
|
+
* and rate card. On any other model the service runs the request at standard
|
|
71
|
+
* speed, so `:fast` is dropped there instead of being sent.
|
|
72
|
+
*/
|
|
73
|
+
const CODEX_FAST_MODELS = /* @__PURE__ */ new Set([
|
|
74
|
+
"gpt-6.2-sol",
|
|
75
|
+
"gpt-6.2-astra",
|
|
76
|
+
"gpt-6.1-sol",
|
|
77
|
+
"gpt-6.1-terra",
|
|
78
|
+
"gpt-6-astra",
|
|
79
|
+
"gpt-6-sol",
|
|
80
|
+
"gpt-6-luna",
|
|
81
|
+
"gpt-5.6",
|
|
82
|
+
"gpt-5.6-sol",
|
|
83
|
+
"gpt-5.5",
|
|
84
|
+
"gpt-5.4"
|
|
85
|
+
]);
|
|
86
|
+
/** `:fast` is reserved on native OpenAI selections, not a catalog model suffix. */
|
|
87
|
+
function parseCodexModelSelection(modelId) {
|
|
88
|
+
const selection = stripMastraGatewayPrefix(modelId);
|
|
89
|
+
if (!/^openai\/[^/:]+:fast$/.test(selection)) return { modelId };
|
|
90
|
+
const canonicalModelId = modelId.slice(0, -5);
|
|
91
|
+
return CODEX_FAST_MODELS.has(selection.slice(7, -5)) ? {
|
|
92
|
+
modelId: canonicalModelId,
|
|
93
|
+
codexServiceTier: "fast"
|
|
94
|
+
} : { modelId: canonicalModelId };
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Adds a `<model>:fast` entry right after each connected OpenAI model that has
|
|
98
|
+
* a Fast tier, when OpenAI is signed in with Codex (Fast has no effect with an
|
|
99
|
+
* API key). Fast entries already in the list are replaced.
|
|
100
|
+
*/
|
|
101
|
+
function withCodexFastModels(models, { codexOAuth }) {
|
|
102
|
+
const listed = [];
|
|
103
|
+
for (const model of models) {
|
|
104
|
+
if (parseCodexModelSelection(model.id).modelId !== model.id) continue;
|
|
105
|
+
listed.push(model);
|
|
106
|
+
if (codexOAuth && model.hasApiKey && model.id.startsWith("openai/") && parseCodexModelSelection(`${model.id}:fast`).codexServiceTier) listed.push({
|
|
107
|
+
...model,
|
|
108
|
+
id: `${model.id}:fast`,
|
|
109
|
+
modelName: `${model.modelName}:fast`
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
return listed;
|
|
113
|
+
}
|
|
114
|
+
/** Prefer the exact selection if both standard and Fast entries for a model exist. */
|
|
115
|
+
function findRouteModelIndex(entries, selectionId) {
|
|
116
|
+
if (typeof selectionId !== "string") return -1;
|
|
117
|
+
const exact = entries.findIndex((entry) => entry.modelId === selectionId);
|
|
118
|
+
if (exact !== -1) return exact;
|
|
119
|
+
const { modelId } = parseCodexModelSelection(selectionId);
|
|
120
|
+
return entries.findIndex((entry) => typeof entry.modelId === "string" && parseCodexModelSelection(entry.modelId).modelId === modelId);
|
|
121
|
+
}
|
|
122
|
+
function remapOpenAIModelForCodexOAuth(modelId) {
|
|
123
|
+
const normalizedModelId = stripMastraGatewayPrefix(modelId);
|
|
124
|
+
if (!normalizedModelId.startsWith("openai/")) return modelId;
|
|
125
|
+
const openaiModelId = normalizedModelId.substring(7);
|
|
126
|
+
if (openaiModelId.includes("-codex")) return modelId;
|
|
127
|
+
const codexModelId = CODEX_OPENAI_MODEL_REMAPS[openaiModelId];
|
|
128
|
+
if (!codexModelId) return modelId;
|
|
129
|
+
const remappedModelId = `${OPENAI_PREFIX}${codexModelId}`;
|
|
130
|
+
return modelId.startsWith("mastra/") ? `${MASTRA_GATEWAY_PREFIX}${remappedModelId}` : remappedModelId;
|
|
131
|
+
}
|
|
132
|
+
export { ANTHROPIC_PREFIX, KIMI_CODING_CREDENTIAL_ID, KIMI_CODING_PROVIDER_ID, MASTRA_GATEWAY_PREFIX, OPENAI_PREFIX, findRouteModelIndex, getCredentialProviderId, normalizeAnthropicModelId, normalizeLegacyModelId, normalizeLegacyProviderId, parseCodexModelSelection, remapOpenAIModelForCodexOAuth, stripMastraGatewayPrefix, withCodexFastModels };
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI Codex OAuth Provider
|
|
3
|
+
*
|
|
4
|
+
* Uses OAuth tokens from AuthStorage to authenticate with ChatGPT Plus/Pro subscription.
|
|
5
|
+
* This allows access to OpenAI models through the ChatGPT OAuth flow.
|
|
6
|
+
*
|
|
7
|
+
* Inspired by opencode's Codex plugin implementation:
|
|
8
|
+
* https://github.com/sst/opencode/blob/main/packages/opencode/src/plugin/codex.ts
|
|
9
|
+
*/
|
|
10
|
+
import type { MastraModelConfig } from '@mastra/core/llm';
|
|
11
|
+
import type { LanguageModelMiddleware } from 'ai';
|
|
12
|
+
import { AuthStorage } from '../auth/storage.js';
|
|
13
|
+
import type { CredentialStore } from '../auth/types.js';
|
|
14
|
+
import type { ThinkingLevelSetting } from '../thinking.js';
|
|
15
|
+
import type { CodexServiceTier } from './model-ids.js';
|
|
16
|
+
export { supportsMaxReasoningEffort } from '../thinking.js';
|
|
17
|
+
/**
|
|
18
|
+
* Get or create the shared AuthStorage instance
|
|
19
|
+
*/
|
|
20
|
+
export declare function getAuthStorage(): AuthStorage;
|
|
21
|
+
/**
|
|
22
|
+
* Set a custom AuthStorage instance (useful for TUI integration)
|
|
23
|
+
*/
|
|
24
|
+
export declare function setAuthStorage(storage: AuthStorage | undefined): void;
|
|
25
|
+
export type ThinkingLevel = ThinkingLevelSetting;
|
|
26
|
+
export declare function getEffectiveThinkingLevel(modelId: string, level: ThinkingLevel): ThinkingLevel;
|
|
27
|
+
export declare const THINKING_LEVEL_TO_REASONING_EFFORT: Record<ThinkingLevel, string | undefined>;
|
|
28
|
+
/**
|
|
29
|
+
* Create Codex middleware with the given reasoning effort level.
|
|
30
|
+
*/
|
|
31
|
+
export declare function createCodexMiddleware(reasoningEffort?: string, oauthOptions?: {
|
|
32
|
+
serviceTier?: CodexServiceTier;
|
|
33
|
+
}): LanguageModelMiddleware;
|
|
34
|
+
/**
|
|
35
|
+
* The thread a model request belongs to, from the `x-thread-id` header that
|
|
36
|
+
* model resolution adds for requests made inside a thread.
|
|
37
|
+
*/
|
|
38
|
+
export declare function getRequestThreadId(headers?: Record<string, string>): string | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Create middleware that sends `prompt_cache_key` on OpenAI Responses requests.
|
|
41
|
+
*
|
|
42
|
+
* OpenAI routes a cached prompt by a hash of its start plus this key. Every
|
|
43
|
+
* Mastra Code prompt starts with the same system prompt, so without a key all
|
|
44
|
+
* threads compete for the same cache slot and consecutive steps of one run often
|
|
45
|
+
* land on a machine that doesn't hold their prefix. Keying by thread keeps each
|
|
46
|
+
* thread's requests together. A key the caller already set wins.
|
|
47
|
+
*/
|
|
48
|
+
export declare function createPromptCacheKeyMiddleware(promptCacheKey?: string): LanguageModelMiddleware | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Create middleware that forwards a resolved reasoning effort to an
|
|
51
|
+
* OpenAI-compatible provider as `providerOptions[providerKey].reasoningEffort`.
|
|
52
|
+
*
|
|
53
|
+
* Returns `undefined` when `reasoningEffort` is unset so callers wrap nothing
|
|
54
|
+
* (e.g. thinking level `off`), leaving the wire request without a
|
|
55
|
+
* `reasoning_effort` field. Unlike {@link createCodexMiddleware}, it does not
|
|
56
|
+
* inject Codex-only options (instructions/store); it only sets reasoning
|
|
57
|
+
* effort, keyed by the caller-supplied provider id.
|
|
58
|
+
*/
|
|
59
|
+
export declare function createReasoningEffortMiddleware(providerKey: string, reasoningEffort?: string): LanguageModelMiddleware | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* Make a Responses request body safe for Codex's stateless (`store: false`) mode.
|
|
62
|
+
*
|
|
63
|
+
* AI SDK replays earlier output items with their server ids (`rs_…`, `msg_…`,
|
|
64
|
+
* `fc_…`) even when `store` is false. Codex looks those ids up and answers
|
|
65
|
+
* 404 `Item with id 'rs_…' not found` once its short-lived item cache has
|
|
66
|
+
* expired, so every later request in the thread fails the same way. Like the
|
|
67
|
+
* Codex CLI, send items without ids (the encrypted reasoning content carries the
|
|
68
|
+
* reasoning chain) and drop `item_reference`s, which can never resolve.
|
|
69
|
+
*/
|
|
70
|
+
export declare function stripCodexInputItemIds(body: string): string;
|
|
71
|
+
/**
|
|
72
|
+
* Build a fetch function that handles OpenAI Codex OAuth.
|
|
73
|
+
* Preserves non-authorization headers from init.
|
|
74
|
+
* When rewriteUrl is true (default), rewrites /v1/responses and /chat/completions
|
|
75
|
+
* to the Codex API endpoint. Set rewriteUrl: false for gateway usage where the
|
|
76
|
+
* SDK already targets the correct URL.
|
|
77
|
+
*/
|
|
78
|
+
export declare function buildOpenAICodexOAuthFetch(opts?: {
|
|
79
|
+
authStorage?: CredentialStore;
|
|
80
|
+
rewriteUrl?: boolean;
|
|
81
|
+
}): typeof fetch;
|
|
82
|
+
/**
|
|
83
|
+
* Build a fetch function for Stagehand-on-Codex.
|
|
84
|
+
*
|
|
85
|
+
* The Codex backend has two requirements that AI SDK's non-streaming
|
|
86
|
+
* `generateText` path doesn't naturally satisfy:
|
|
87
|
+
*
|
|
88
|
+
* 1. `stream: true` must be set on every request body.
|
|
89
|
+
* 2. The response is delivered as Server-Sent Events; AI SDK's
|
|
90
|
+
* non-streaming code path expects a single JSON body.
|
|
91
|
+
*
|
|
92
|
+
* This fetch forces streaming on the outgoing request, collects the SSE
|
|
93
|
+
* events, and synthesizes the non-streaming JSON shape that
|
|
94
|
+
* `@ai-sdk/openai`'s Responses API parser expects.
|
|
95
|
+
*
|
|
96
|
+
* Headers, OAuth refresh, and URL targeting are handled by the caller via
|
|
97
|
+
* `baseURL` / `headers` on the AI SDK provider; this fetch only injects the
|
|
98
|
+
* live OAuth bearer per call.
|
|
99
|
+
*/
|
|
100
|
+
export declare function buildCodexStagehandFetch(authStorage: AuthStorage): typeof fetch;
|
|
101
|
+
/**
|
|
102
|
+
* Creates an OpenAI model using ChatGPT OAuth authentication
|
|
103
|
+
* Uses OAuth tokens from AuthStorage (auto-refreshes when needed)
|
|
104
|
+
*
|
|
105
|
+
* IMPORTANT: This uses the Codex API endpoint, not the standard OpenAI API.
|
|
106
|
+
* URLs are rewritten from /v1/responses or /chat/completions to the Codex endpoint.
|
|
107
|
+
*/
|
|
108
|
+
export declare function openaiCodexProvider(modelId?: string, options?: {
|
|
109
|
+
thinkingLevel?: ThinkingLevel;
|
|
110
|
+
headers?: Record<string, string>;
|
|
111
|
+
authStorage?: CredentialStore;
|
|
112
|
+
serviceTier?: CodexServiceTier;
|
|
113
|
+
}): MastraModelConfig;
|
|
114
|
+
//# sourceMappingURL=openai-codex.d.ts.map
|