@mastra/code-sdk 1.13.0 → 1.14.0-alpha.1
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/dist/agents/mastracode-gateway.d.ts.map +1 -1
- package/dist/agents/mastracode-gateway.js +18 -44
- package/dist/agents/mastracode-gateway.js.map +1 -1
- package/dist/agents/model.d.ts +5 -2
- package/dist/agents/model.d.ts.map +1 -1
- package/dist/agents/model.js +7 -7
- package/dist/agents/model.js.map +1 -1
- package/dist/auth/account-rotation-processor.d.ts +2 -0
- package/dist/auth/account-rotation-processor.d.ts.map +1 -1
- package/dist/auth/account-rotation-processor.js +4 -3
- package/dist/auth/account-rotation-processor.js.map +1 -1
- package/dist/auth/storage.js +1 -1
- package/dist/auth/storage.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -4
- package/dist/index.js.map +1 -1
- 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/kimi-coding.d.ts +0 -1
- package/dist/providers/kimi-coding.d.ts.map +1 -1
- package/dist/providers/kimi-coding.js +1 -7
- package/dist/providers/kimi-coding.js.map +1 -1
- package/dist/providers/model-ids.d.ts +18 -0
- package/dist/providers/model-ids.d.ts.map +1 -1
- package/dist/providers/model-ids.js +39 -1
- package/dist/providers/model-ids.js.map +1 -1
- package/dist/providers/provider-thinking.d.ts +5 -0
- package/dist/providers/provider-thinking.d.ts.map +1 -1
- package/dist/providers/provider-thinking.js +32 -2
- package/dist/providers/provider-thinking.js.map +1 -1
- 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 +2 -2
- package/dist/providers/xai.d.ts.map +1 -1
- package/dist/providers/xai.js.map +1 -1
- package/dist/thinking.d.ts +1 -0
- package/dist/thinking.d.ts.map +1 -1
- package/dist/thinking.js +23 -5
- package/dist/thinking.js.map +1 -1
- package/package.json +11 -11
- package/dist/providers/deepseek-thinking.d.ts +0 -4
- package/dist/providers/deepseek-thinking.d.ts.map +0 -1
- package/dist/providers/deepseek-thinking.js +0 -16
- package/dist/providers/deepseek-thinking.js.map +0 -1
package/dist/thinking.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ANTHROPIC_THINKING_BUDGET_TOKENS, getAnthropicThinkingCapability, supportsAnthropicXhighEffort } from "./providers/anthropic-thinking.js";
|
|
2
2
|
import { runGeminiThinkingLevel } from "./providers/google-thinking.js";
|
|
3
3
|
import { normalizeAnthropicModelId, stripMastraGatewayPrefix } from "./providers/model-ids.js";
|
|
4
|
+
import { isRoutedWithoutThinking, isThinkingAdapterProvider, thinkingRequestFormatFor } from "./providers/thinking-request.js";
|
|
4
5
|
//#region src/thinking.ts
|
|
5
6
|
const THINKING_LEVEL_VALUES = [
|
|
6
7
|
"off",
|
|
@@ -54,6 +55,22 @@ const TOGGLE_ON_LEVEL = "high";
|
|
|
54
55
|
function onlyTogglesThinking(reasoningOptions) {
|
|
55
56
|
return !!reasoningOptions?.length && reasoningOptions.every((option) => option.type === "toggle");
|
|
56
57
|
}
|
|
58
|
+
function requestableReasoningOptions(modelId, reasoningOptions) {
|
|
59
|
+
if (isRoutedWithoutThinking(modelId)) return [];
|
|
60
|
+
if (!reasoningOptions) return reasoningOptions;
|
|
61
|
+
const format = thinkingRequestFormatFor(modelId);
|
|
62
|
+
if (!format) return isThinkingAdapterProvider(splitProvider(modelId).provider) ? reasoningOptions : [];
|
|
63
|
+
const acceptedEfforts = format.sendEffort ? format.acceptedEfforts ?? ACTIVE_THINKING_LEVELS : [];
|
|
64
|
+
return reasoningOptions.flatMap((option) => {
|
|
65
|
+
if (option.type === "toggle") return format.enableThinking ? [option] : [];
|
|
66
|
+
if (option.type !== "effort") return [];
|
|
67
|
+
const values = option.values.filter((value) => acceptedEfforts.some((effort) => effort === value));
|
|
68
|
+
return values.length ? [{
|
|
69
|
+
type: "effort",
|
|
70
|
+
values
|
|
71
|
+
}] : [];
|
|
72
|
+
});
|
|
73
|
+
}
|
|
57
74
|
function closestOfferedEffort(level, reasoningOptions) {
|
|
58
75
|
const offered = offeredEffortLevels(reasoningOptions);
|
|
59
76
|
const requestedRank = ACTIVE_THINKING_LEVELS.indexOf(level);
|
|
@@ -81,10 +98,11 @@ function runThinkingLevel(modelId, level, reasoningOptions) {
|
|
|
81
98
|
const { provider, bareModelId } = splitProvider(modelId);
|
|
82
99
|
if (provider === "google") return runGeminiThinkingLevel(bareModelId, level);
|
|
83
100
|
if (provider === "anthropic") return runAnthropicThinkingLevel(normalizeAnthropicModelId(bareModelId), level, reasoningOptions);
|
|
84
|
-
|
|
85
|
-
if (
|
|
86
|
-
if (
|
|
87
|
-
return
|
|
101
|
+
const requestable = requestableReasoningOptions(modelId, reasoningOptions);
|
|
102
|
+
if (requestable?.length === 0) return "off";
|
|
103
|
+
if (onlyTogglesThinking(requestable)) return TOGGLE_ON_LEVEL;
|
|
104
|
+
if (provider === "openai") return runOpenAIThinkingLevel(bareModelId, level, requestable);
|
|
105
|
+
return closestOfferedEffort(level, requestable) ?? level;
|
|
88
106
|
}
|
|
89
107
|
function getAvailableThinkingLevelsForModel(modelId, reasoningOptions) {
|
|
90
108
|
return THINKING_LEVEL_VALUES.filter((level) => runThinkingLevel(modelId, level, reasoningOptions) === level);
|
|
@@ -114,6 +132,6 @@ function resolveDefaultThinkingLevel(defaults, mode) {
|
|
|
114
132
|
};
|
|
115
133
|
}
|
|
116
134
|
//#endregion
|
|
117
|
-
export { THINKING_LEVEL_VALUES, THINK_COMMAND_DESCRIPTOR, getAvailableThinkingLevelsForModel, isThinkingLevelSetting, parseThinkCommand, resolveDefaultThinkingLevel, runThinkingLevel, supportsMaxReasoningEffort };
|
|
135
|
+
export { THINKING_LEVEL_VALUES, THINK_COMMAND_DESCRIPTOR, getAvailableThinkingLevelsForModel, isThinkingLevelSetting, parseThinkCommand, requestableReasoningOptions, resolveDefaultThinkingLevel, runThinkingLevel, supportsMaxReasoningEffort };
|
|
118
136
|
|
|
119
137
|
//# sourceMappingURL=thinking.js.map
|
package/dist/thinking.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thinking.js","names":[],"sources":["../src/thinking.ts"],"sourcesContent":["import type { ModelReasoningOption } from '@mastra/core/llm';\nimport {\n ANTHROPIC_THINKING_BUDGET_TOKENS,\n getAnthropicThinkingCapability,\n supportsAnthropicXhighEffort,\n} from './providers/anthropic-thinking.js';\nimport { runGeminiThinkingLevel } from './providers/google-thinking.js';\nimport { normalizeAnthropicModelId, stripMastraGatewayPrefix } from './providers/model-ids.js';\n\nexport type ThinkingLevelSetting = 'off' | 'low' | 'medium' | 'high' | 'xhigh' | 'max';\n\nexport type ActiveThinkingLevel = Exclude<ThinkingLevelSetting, 'off'>;\n\nexport type ThinkingLevelSource = 'mode-default' | 'global';\n\nexport interface ThinkingDefaults {\n globalDefault: ThinkingLevelSetting;\n modeDefaults: Readonly<Record<string, ThinkingLevelSetting>>;\n}\n\nexport const THINKING_LEVEL_VALUES: ThinkingLevelSetting[] = ['off', 'low', 'medium', 'high', 'xhigh', 'max'];\n\nconst ACTIVE_THINKING_LEVELS: ActiveThinkingLevel[] = ['low', 'medium', 'high', 'xhigh', 'max'];\n\nexport const THINK_COMMAND_DESCRIPTOR = {\n name: 'think',\n args: '[status|default|off|low|medium|high|xhigh|max]',\n description: 'Show or set session thinking level',\n};\n\nexport type ThinkCommandAction =\n | { kind: 'status' }\n | { kind: 'clear' }\n | { kind: 'set'; level: ThinkingLevelSetting }\n | { kind: 'invalid'; value: string; levels: readonly ThinkingLevelSetting[] };\n\nconst GPT_VERSION_RE = /^gpt-(\\d+)(?:\\.(\\d+))?/;\n\nexport function isThinkingLevelSetting(value: unknown): value is ThinkingLevelSetting {\n return typeof value === 'string' && THINKING_LEVEL_VALUES.some(level => level === value);\n}\n\nexport function supportsMaxReasoningEffort(modelId: string): boolean {\n const bareModelId = modelId.startsWith('openai/') ? modelId.slice('openai/'.length) : modelId;\n const match = GPT_VERSION_RE.exec(bareModelId);\n if (!match) return false;\n const major = Number(match[1]);\n const minor = Number(match[2] ?? 0);\n return major > 5 || (major === 5 && minor >= 6);\n}\n\nfunction splitProvider(modelId: string): { provider: string; bareModelId: string } {\n const routedModelId = stripMastraGatewayPrefix(modelId);\n const slash = routedModelId.indexOf('/');\n if (slash === -1) return { provider: '', bareModelId: routedModelId };\n return { provider: routedModelId.slice(0, slash), bareModelId: routedModelId.slice(slash + 1) };\n}\n\nfunction offeredEffortLevels(reasoningOptions: readonly ModelReasoningOption[] | undefined): ActiveThinkingLevel[] {\n const effortValues = reasoningOptions?.flatMap(option => (option.type === 'effort' ? option.values : [])) ?? [];\n return ACTIVE_THINKING_LEVELS.filter(level => effortValues.includes(level));\n}\n\nconst TOGGLE_ON_LEVEL: ActiveThinkingLevel = 'high';\n\nfunction onlyTogglesThinking(reasoningOptions: readonly ModelReasoningOption[] | undefined): boolean {\n return !!reasoningOptions?.length && reasoningOptions.every(option => option.type === 'toggle');\n}\n\nfunction closestOfferedEffort(\n level: ActiveThinkingLevel,\n reasoningOptions: readonly ModelReasoningOption[] | undefined,\n): ActiveThinkingLevel | undefined {\n const offered = offeredEffortLevels(reasoningOptions);\n const requestedRank = ACTIVE_THINKING_LEVELS.indexOf(level);\n const atOrBelow = offered.filter(candidate => ACTIVE_THINKING_LEVELS.indexOf(candidate) <= requestedRank);\n return atOrBelow.at(-1) ?? offered[0];\n}\n\nfunction lowestLevelWithSameBudget(level: ActiveThinkingLevel): ActiveThinkingLevel {\n const budget = ANTHROPIC_THINKING_BUDGET_TOKENS[level];\n return ACTIVE_THINKING_LEVELS.find(candidate => ANTHROPIC_THINKING_BUDGET_TOKENS[candidate] === budget) ?? level;\n}\n\nfunction runAnthropicThinkingLevel(\n modelId: string,\n level: ActiveThinkingLevel,\n reasoningOptions: readonly ModelReasoningOption[] | undefined,\n): ThinkingLevelSetting {\n const capability = getAnthropicThinkingCapability(modelId);\n if (capability === 'none') return 'off';\n if (capability === 'budget') return lowestLevelWithSameBudget(level);\n const offeredEffort = closestOfferedEffort(level, reasoningOptions);\n if (offeredEffort) return offeredEffort;\n return level === 'xhigh' && !supportsAnthropicXhighEffort(modelId) ? 'high' : level;\n}\n\nfunction runOpenAIThinkingLevel(\n modelId: string,\n level: ActiveThinkingLevel,\n reasoningOptions: readonly ModelReasoningOption[] | undefined,\n): ActiveThinkingLevel {\n const offeredEffort = closestOfferedEffort(level, reasoningOptions);\n if (offeredEffort) return offeredEffort;\n return level === 'max' && !supportsMaxReasoningEffort(modelId) ? 'xhigh' : level;\n}\n\nexport function runThinkingLevel(\n modelId: string,\n level: ThinkingLevelSetting,\n reasoningOptions: readonly ModelReasoningOption[] | undefined,\n): ThinkingLevelSetting {\n if (level === 'off') return 'off';\n const { provider, bareModelId } = splitProvider(modelId);\n if (provider === 'google') return runGeminiThinkingLevel(bareModelId, level);\n if (provider === 'anthropic') {\n return runAnthropicThinkingLevel(normalizeAnthropicModelId(bareModelId), level, reasoningOptions);\n }\n const listedWithoutReasoningControls = reasoningOptions?.length === 0;\n if (listedWithoutReasoningControls) return 'off';\n if (onlyTogglesThinking(reasoningOptions)) return TOGGLE_ON_LEVEL;\n if (provider === 'openai') return runOpenAIThinkingLevel(bareModelId, level, reasoningOptions);\n return closestOfferedEffort(level, reasoningOptions) ?? level;\n}\n\nexport function getAvailableThinkingLevelsForModel(\n modelId: string,\n reasoningOptions?: readonly ModelReasoningOption[],\n): ThinkingLevelSetting[] {\n return THINKING_LEVEL_VALUES.filter(level => runThinkingLevel(modelId, level, reasoningOptions) === level);\n}\n\nexport function parseThinkCommand(\n input: string,\n levels: readonly ThinkingLevelSetting[] = THINKING_LEVEL_VALUES,\n): ThinkCommandAction {\n const value = input.trim().toLowerCase();\n if (!value || value === 'status') return { kind: 'status' };\n if (value === 'default' || value === 'clear') return { kind: 'clear' };\n const level = levels.find(candidate => candidate === value);\n return level ? { kind: 'set', level } : { kind: 'invalid', value, levels };\n}\n\nexport function resolveDefaultThinkingLevel(\n defaults: ThinkingDefaults,\n mode?: string | null,\n): { level: ThinkingLevelSetting; source: ThinkingLevelSource } {\n const modeLevel = mode ? defaults.modeDefaults[mode] : undefined;\n return modeLevel ? { level: modeLevel, source: 'mode-default' } : { level: defaults.globalDefault, source: 'global' };\n}\n"],"mappings":";;;;AAoBA,MAAa,wBAAgD;CAAC;CAAO;CAAO;CAAU;CAAQ;CAAS;AAAK;AAE5G,MAAM,yBAAgD;CAAC;CAAO;CAAU;CAAQ;CAAS;AAAK;AAE9F,MAAa,2BAA2B;CACtC,MAAM;CACN,MAAM;CACN,aAAa;AACf;AAQA,MAAM,iBAAiB;AAEvB,SAAgB,uBAAuB,OAA+C;CACpF,OAAO,OAAO,UAAU,YAAY,sBAAsB,MAAK,UAAS,UAAU,KAAK;AACzF;AAEA,SAAgB,2BAA2B,SAA0B;CACnE,MAAM,cAAc,QAAQ,WAAW,SAAS,IAAI,QAAQ,MAAM,CAAgB,IAAI;CACtF,MAAM,QAAQ,eAAe,KAAK,WAAW;CAC7C,IAAI,CAAC,OAAO,OAAO;CACnB,MAAM,QAAQ,OAAO,MAAM,EAAE;CAC7B,MAAM,QAAQ,OAAO,MAAM,MAAM,CAAC;CAClC,OAAO,QAAQ,KAAM,UAAU,KAAK,SAAS;AAC/C;AAEA,SAAS,cAAc,SAA4D;CACjF,MAAM,gBAAgB,yBAAyB,OAAO;CACtD,MAAM,QAAQ,cAAc,QAAQ,GAAG;CACvC,IAAI,UAAU,IAAI,OAAO;EAAE,UAAU;EAAI,aAAa;CAAc;CACpE,OAAO;EAAE,UAAU,cAAc,MAAM,GAAG,KAAK;EAAG,aAAa,cAAc,MAAM,QAAQ,CAAC;CAAE;A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AAa,UAAU,OAAO,uBAAuB,aAAa,KAAK;CAC3E,IAAI,aAAa,aACf,OAAO,0BAA0B,0BAA0B,WAAW,GAAG,OAAO,gBAAgB;CAGlG,IADuC,kBAAkB,WAAW,GAChC,OAAO;CAC3C,IAAI,oBAAoB,gBAAgB,GAAG,OAAO;CAClD,IAAI,aAAa,UAAU,OAAO,uBAAuB,aAAa,OAAO,gBAAgB;CAC7F,OAAO,qBAAqB,OAAO,gBAAgB,KAAK;AAC1D;AAEA,SAAgB,mCACd,SACA,kBACwB;CACxB,OAAO,sBAAsB,QAAO,UAAS,iBAAiB,SAAS,OAAO,gBAAgB,MAAM,KAAK;AAC3G;AAEA,SAAgB,kBACd,OACA,SAA0C,uBACtB;CACpB,MAAM,QAAQ,MAAM,KAAK,CAAC,CAAC,YAAY;CACvC,IAAI,CAAC,SAAS,UAAU,UAAU,OAAO,EAAE,MAAM,SAAS;CAC1D,IAAI,UAAU,aAAa,UAAU,SAAS,OAAO,EAAE,MAAM,QAAQ;CACrE,MAAM,QAAQ,OAAO,MAAK,cAAa,cAAc,KAAK;CAC1D,OAAO,QAAQ;EAAE,MAAM;EAAO;CAAM,IAAI;EAAE,MAAM;EAAW;EAAO;CAAO;AAC3E;AAEA,SAAgB,4BACd,UACA,MAC8D;CAC9D,MAAM,YAAY,OAAO,SAAS,aAAa,QAAQ,KAAA;CACvD,OAAO,YAAY;EAAE,OAAO;EAAW,QAAQ;CAAe,IAAI;EAAE,OAAO,SAAS;EAAe,QAAQ;CAAS;AACtH"}
|
|
1
|
+
{"version":3,"file":"thinking.js","names":[],"sources":["../src/thinking.ts"],"sourcesContent":["import type { ModelReasoningOption } from '@mastra/core/llm';\nimport {\n ANTHROPIC_THINKING_BUDGET_TOKENS,\n getAnthropicThinkingCapability,\n supportsAnthropicXhighEffort,\n} from './providers/anthropic-thinking.js';\nimport { runGeminiThinkingLevel } from './providers/google-thinking.js';\nimport { normalizeAnthropicModelId, stripMastraGatewayPrefix } from './providers/model-ids.js';\nimport {\n isRoutedWithoutThinking,\n isThinkingAdapterProvider,\n thinkingRequestFormatFor,\n} from './providers/thinking-request.js';\n\nexport type ThinkingLevelSetting = 'off' | 'low' | 'medium' | 'high' | 'xhigh' | 'max';\n\nexport type ActiveThinkingLevel = Exclude<ThinkingLevelSetting, 'off'>;\n\nexport type ThinkingLevelSource = 'mode-default' | 'global';\n\nexport interface ThinkingDefaults {\n globalDefault: ThinkingLevelSetting;\n modeDefaults: Readonly<Record<string, ThinkingLevelSetting>>;\n}\n\nexport const THINKING_LEVEL_VALUES: ThinkingLevelSetting[] = ['off', 'low', 'medium', 'high', 'xhigh', 'max'];\n\nconst ACTIVE_THINKING_LEVELS: ActiveThinkingLevel[] = ['low', 'medium', 'high', 'xhigh', 'max'];\n\nexport const THINK_COMMAND_DESCRIPTOR = {\n name: 'think',\n args: '[status|default|off|low|medium|high|xhigh|max]',\n description: 'Show or set session thinking level',\n};\n\nexport type ThinkCommandAction =\n | { kind: 'status' }\n | { kind: 'clear' }\n | { kind: 'set'; level: ThinkingLevelSetting }\n | { kind: 'invalid'; value: string; levels: readonly ThinkingLevelSetting[] };\n\nconst GPT_VERSION_RE = /^gpt-(\\d+)(?:\\.(\\d+))?/;\n\nexport function isThinkingLevelSetting(value: unknown): value is ThinkingLevelSetting {\n return typeof value === 'string' && THINKING_LEVEL_VALUES.some(level => level === value);\n}\n\nexport function supportsMaxReasoningEffort(modelId: string): boolean {\n const bareModelId = modelId.startsWith('openai/') ? modelId.slice('openai/'.length) : modelId;\n const match = GPT_VERSION_RE.exec(bareModelId);\n if (!match) return false;\n const major = Number(match[1]);\n const minor = Number(match[2] ?? 0);\n return major > 5 || (major === 5 && minor >= 6);\n}\n\nfunction splitProvider(modelId: string): { provider: string; bareModelId: string } {\n const routedModelId = stripMastraGatewayPrefix(modelId);\n const slash = routedModelId.indexOf('/');\n if (slash === -1) return { provider: '', bareModelId: routedModelId };\n return { provider: routedModelId.slice(0, slash), bareModelId: routedModelId.slice(slash + 1) };\n}\n\nfunction offeredEffortLevels(reasoningOptions: readonly ModelReasoningOption[] | undefined): ActiveThinkingLevel[] {\n const effortValues = reasoningOptions?.flatMap(option => (option.type === 'effort' ? option.values : [])) ?? [];\n return ACTIVE_THINKING_LEVELS.filter(level => effortValues.includes(level));\n}\n\nconst TOGGLE_ON_LEVEL: ActiveThinkingLevel = 'high';\n\nfunction onlyTogglesThinking(reasoningOptions: readonly ModelReasoningOption[] | undefined): boolean {\n return !!reasoningOptions?.length && reasoningOptions.every(option => option.type === 'toggle');\n}\n\nexport function requestableReasoningOptions(\n modelId: string,\n reasoningOptions: readonly ModelReasoningOption[] | undefined,\n): readonly ModelReasoningOption[] | undefined {\n if (isRoutedWithoutThinking(modelId)) return [];\n if (!reasoningOptions) return reasoningOptions;\n const format = thinkingRequestFormatFor(modelId);\n if (!format) return isThinkingAdapterProvider(splitProvider(modelId).provider) ? reasoningOptions : [];\n const acceptedEfforts = format.sendEffort ? (format.acceptedEfforts ?? ACTIVE_THINKING_LEVELS) : [];\n return reasoningOptions.flatMap((option): ModelReasoningOption[] => {\n if (option.type === 'toggle') return format.enableThinking ? [option] : [];\n if (option.type !== 'effort') return [];\n const values = option.values.filter(value => acceptedEfforts.some(effort => effort === value));\n return values.length ? [{ type: 'effort', values }] : [];\n });\n}\n\nfunction closestOfferedEffort(\n level: ActiveThinkingLevel,\n reasoningOptions: readonly ModelReasoningOption[] | undefined,\n): ActiveThinkingLevel | undefined {\n const offered = offeredEffortLevels(reasoningOptions);\n const requestedRank = ACTIVE_THINKING_LEVELS.indexOf(level);\n const atOrBelow = offered.filter(candidate => ACTIVE_THINKING_LEVELS.indexOf(candidate) <= requestedRank);\n return atOrBelow.at(-1) ?? offered[0];\n}\n\nfunction lowestLevelWithSameBudget(level: ActiveThinkingLevel): ActiveThinkingLevel {\n const budget = ANTHROPIC_THINKING_BUDGET_TOKENS[level];\n return ACTIVE_THINKING_LEVELS.find(candidate => ANTHROPIC_THINKING_BUDGET_TOKENS[candidate] === budget) ?? level;\n}\n\nfunction runAnthropicThinkingLevel(\n modelId: string,\n level: ActiveThinkingLevel,\n reasoningOptions: readonly ModelReasoningOption[] | undefined,\n): ThinkingLevelSetting {\n const capability = getAnthropicThinkingCapability(modelId);\n if (capability === 'none') return 'off';\n if (capability === 'budget') return lowestLevelWithSameBudget(level);\n const offeredEffort = closestOfferedEffort(level, reasoningOptions);\n if (offeredEffort) return offeredEffort;\n return level === 'xhigh' && !supportsAnthropicXhighEffort(modelId) ? 'high' : level;\n}\n\nfunction runOpenAIThinkingLevel(\n modelId: string,\n level: ActiveThinkingLevel,\n reasoningOptions: readonly ModelReasoningOption[] | undefined,\n): ActiveThinkingLevel {\n const offeredEffort = closestOfferedEffort(level, reasoningOptions);\n if (offeredEffort) return offeredEffort;\n return level === 'max' && !supportsMaxReasoningEffort(modelId) ? 'xhigh' : level;\n}\n\nexport function runThinkingLevel(\n modelId: string,\n level: ThinkingLevelSetting,\n reasoningOptions: readonly ModelReasoningOption[] | undefined,\n): ThinkingLevelSetting {\n if (level === 'off') return 'off';\n const { provider, bareModelId } = splitProvider(modelId);\n if (provider === 'google') return runGeminiThinkingLevel(bareModelId, level);\n if (provider === 'anthropic') {\n return runAnthropicThinkingLevel(normalizeAnthropicModelId(bareModelId), level, reasoningOptions);\n }\n const requestable = requestableReasoningOptions(modelId, reasoningOptions);\n const listedWithoutReasoningControls = requestable?.length === 0;\n if (listedWithoutReasoningControls) return 'off';\n if (onlyTogglesThinking(requestable)) return TOGGLE_ON_LEVEL;\n if (provider === 'openai') return runOpenAIThinkingLevel(bareModelId, level, requestable);\n return closestOfferedEffort(level, requestable) ?? level;\n}\n\nexport function getAvailableThinkingLevelsForModel(\n modelId: string,\n reasoningOptions?: readonly ModelReasoningOption[],\n): ThinkingLevelSetting[] {\n return THINKING_LEVEL_VALUES.filter(level => runThinkingLevel(modelId, level, reasoningOptions) === level);\n}\n\nexport function parseThinkCommand(\n input: string,\n levels: readonly ThinkingLevelSetting[] = THINKING_LEVEL_VALUES,\n): ThinkCommandAction {\n const value = input.trim().toLowerCase();\n if (!value || value === 'status') return { kind: 'status' };\n if (value === 'default' || value === 'clear') return { kind: 'clear' };\n const level = levels.find(candidate => candidate === value);\n return level ? { kind: 'set', level } : { kind: 'invalid', value, levels };\n}\n\nexport function resolveDefaultThinkingLevel(\n defaults: ThinkingDefaults,\n mode?: string | null,\n): { level: ThinkingLevelSetting; source: ThinkingLevelSource } {\n const modeLevel = mode ? defaults.modeDefaults[mode] : undefined;\n return modeLevel ? { level: modeLevel, source: 'mode-default' } : { level: defaults.globalDefault, source: 'global' };\n}\n"],"mappings":";;;;;AAyBA,MAAa,wBAAgD;CAAC;CAAO;CAAO;CAAU;CAAQ;CAAS;AAAK;AAE5G,MAAM,yBAAgD;CAAC;CAAO;CAAU;CAAQ;CAAS;AAAK;AAE9F,MAAa,2BAA2B;CACtC,MAAM;CACN,MAAM;CACN,aAAa;AACf;AAQA,MAAM,iBAAiB;AAEvB,SAAgB,uBAAuB,OAA+C;CACpF,OAAO,OAAO,UAAU,YAAY,sBAAsB,MAAK,UAAS,UAAU,KAAK;AACzF;AAEA,SAAgB,2BAA2B,SAA0B;CACnE,MAAM,cAAc,QAAQ,WAAW,SAAS,IAAI,QAAQ,MAAM,CAAgB,IAAI;CACtF,MAAM,QAAQ,eAAe,KAAK,WAAW;CAC7C,IAAI,CAAC,OAAO,OAAO;CACnB,MAAM,QAAQ,OAAO,MAAM,EAAE;CAC7B,MAAM,QAAQ,OAAO,MAAM,MAAM,CAAC;CAClC,OAAO,QAAQ,KAAM,UAAU,KAAK,SAAS;AAC/C;AAEA,SAAS,cAAc,SAA4D;CACjF,MAAM,gBAAgB,yBAAyB,OAAO;CACtD,MAAM,QAAQ,cAAc,QAAQ,GAAG;CACvC,IAAI,UAAU,IAAI,OAAO;EAAE,UAAU;EAAI,aAAa;CAAc;CACpE,OAAO;EAAE,UAAU,cAAc,MAAM,GAAG,KAAK;EAAG,aAAa,cAAc,MAAM,QAAQ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D,IAAI,UAAU,aAAa,UAAU,SAAS,OAAO,EAAE,MAAM,QAAQ;CACrE,MAAM,QAAQ,OAAO,MAAK,cAAa,cAAc,KAAK;CAC1D,OAAO,QAAQ;EAAE,MAAM;EAAO;CAAM,IAAI;EAAE,MAAM;EAAW;EAAO;CAAO;AAC3E;AAEA,SAAgB,4BACd,UACA,MAC8D;CAC9D,MAAM,YAAY,OAAO,SAAS,aAAa,QAAQ,KAAA;CACvD,OAAO,YAAY;EAAE,OAAO;EAAW,QAAQ;CAAe,IAAI;EAAE,OAAO,SAAS;EAAe,QAAQ;CAAS;AACtH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/code-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0-alpha.1",
|
|
4
4
|
"description": "Mastra Code SDK: the agent core behind Mastra Code (everything except the TUI) — build your own UIs and surfaces on top of it",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -62,19 +62,19 @@
|
|
|
62
62
|
"vscode-languageserver-protocol": "^3.17.5",
|
|
63
63
|
"yaml": "^2.7.1",
|
|
64
64
|
"zod": "^4.6.4",
|
|
65
|
-
"@mastra/fastembed": "1.3.3",
|
|
66
65
|
"@mastra/agent-browser": "0.5.3",
|
|
67
66
|
"@mastra/duckdb": "1.14.0",
|
|
68
|
-
"@mastra/core": "1.
|
|
67
|
+
"@mastra/core": "1.78.0-alpha.1",
|
|
69
68
|
"@mastra/github-signals": "0.5.1",
|
|
70
|
-
"@mastra/
|
|
71
|
-
"@mastra/
|
|
72
|
-
"@mastra/
|
|
69
|
+
"@mastra/fastembed": "1.3.3",
|
|
70
|
+
"@mastra/libsql": "1.26.2-alpha.0",
|
|
71
|
+
"@mastra/mcp": "2.4.1-alpha.0",
|
|
73
72
|
"@mastra/memory": "1.37.1",
|
|
74
|
-
"@mastra/
|
|
75
|
-
"@mastra/stagehand": "0.3.5",
|
|
76
|
-
"@mastra/schema-compat": "1.3.14",
|
|
73
|
+
"@mastra/observability": "1.20.1-alpha.0",
|
|
77
74
|
"@mastra/parallel": "0.1.2",
|
|
75
|
+
"@mastra/pg": "1.31.2-alpha.0",
|
|
76
|
+
"@mastra/schema-compat": "1.3.14",
|
|
77
|
+
"@mastra/stagehand": "0.3.5",
|
|
78
78
|
"@mastra/tavily": "1.1.2"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
@@ -87,8 +87,8 @@
|
|
|
87
87
|
"typescript-eslint": "^8.57.0",
|
|
88
88
|
"vitest": "4.1.11",
|
|
89
89
|
"@internal/lint": "0.0.143",
|
|
90
|
-
"@internal/
|
|
91
|
-
"@internal/
|
|
90
|
+
"@internal/types-builder": "0.0.118",
|
|
91
|
+
"@internal/workspace-test-utils": "0.0.87"
|
|
92
92
|
},
|
|
93
93
|
"engines": {
|
|
94
94
|
"node": ">=22.19.0"
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { ThinkingLevelSetting } from '../thinking.js';
|
|
2
|
-
import type { ProviderThinkingOptions } from './provider-thinking.js';
|
|
3
|
-
export declare function deepseekThinkingOptions(routedModelId: string, level: ThinkingLevelSetting | undefined): ProviderThinkingOptions | undefined;
|
|
4
|
-
//# sourceMappingURL=deepseek-thinking.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deepseek-thinking.d.ts","sourceRoot":"","sources":["../../src/providers/deepseek-thinking.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAEtE,wBAAgB,uBAAuB,CACrC,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,oBAAoB,GAAG,SAAS,GACtC,uBAAuB,GAAG,SAAS,CASrC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { runCatalogThinkingLevel } from "../thinking-catalog.js";
|
|
2
|
-
//#region src/providers/deepseek-thinking.ts
|
|
3
|
-
function deepseekThinkingOptions(routedModelId, level) {
|
|
4
|
-
if (!level || level === "off") return void 0;
|
|
5
|
-
const reasoningEffort = runCatalogThinkingLevel(routedModelId, level);
|
|
6
|
-
if (reasoningEffort === "off") return void 0;
|
|
7
|
-
return {
|
|
8
|
-
optionsKey: "deepseek",
|
|
9
|
-
options: { reasoningEffort },
|
|
10
|
-
controlKeys: /* @__PURE__ */ new Set(["thinking", "reasoningEffort"])
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
//#endregion
|
|
14
|
-
export { deepseekThinkingOptions };
|
|
15
|
-
|
|
16
|
-
//# sourceMappingURL=deepseek-thinking.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deepseek-thinking.js","names":[],"sources":["../../src/providers/deepseek-thinking.ts"],"sourcesContent":["import { runCatalogThinkingLevel } from '../thinking-catalog.js';\nimport type { ThinkingLevelSetting } from '../thinking.js';\nimport type { ProviderThinkingOptions } from './provider-thinking.js';\n\nexport function deepseekThinkingOptions(\n routedModelId: string,\n level: ThinkingLevelSetting | undefined,\n): ProviderThinkingOptions | undefined {\n if (!level || level === 'off') return undefined;\n const reasoningEffort = runCatalogThinkingLevel(routedModelId, level);\n if (reasoningEffort === 'off') return undefined;\n return {\n optionsKey: 'deepseek',\n options: { reasoningEffort },\n controlKeys: new Set(['thinking', 'reasoningEffort']),\n };\n}\n"],"mappings":";;AAIA,SAAgB,wBACd,eACA,OACqC;CACrC,IAAI,CAAC,SAAS,UAAU,OAAO,OAAO,KAAA;CACtC,MAAM,kBAAkB,wBAAwB,eAAe,KAAK;CACpE,IAAI,oBAAoB,OAAO,OAAO,KAAA;CACtC,OAAO;EACL,YAAY;EACZ,SAAS,EAAE,gBAAgB;EAC3B,6BAAa,IAAI,IAAI,CAAC,YAAY,iBAAiB,CAAC;CACtD;AACF"}
|