@mastra/code-sdk 1.18.0-alpha.3 → 1.19.0-alpha.0
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/acp/agent.js +2 -2
- package/dist/acp/runtime.js +2 -2
- package/dist/agent-connections/state-processor.js +3 -3
- package/dist/agent-connections/tools.js +2 -2
- package/dist/agents/instructions.d.ts +5 -2
- package/dist/agents/instructions.d.ts.map +1 -1
- package/dist/agents/instructions.js +5 -3
- package/dist/agents/instructions.js.map +1 -1
- package/dist/agents/mastracode-gateway.js +5 -5
- package/dist/agents/memory.js +2 -2
- package/dist/agents/model.js +5 -5
- package/dist/agents/prompts/index.d.ts +2 -0
- package/dist/agents/prompts/index.d.ts.map +1 -1
- package/dist/agents/prompts/index.js +8 -5
- package/dist/agents/prompts/index.js.map +1 -1
- package/dist/agents/prompts/plan.d.ts +1 -0
- package/dist/agents/prompts/plan.d.ts.map +1 -1
- package/dist/agents/prompts/plan.js +4 -1
- package/dist/agents/prompts/plan.js.map +1 -1
- package/dist/agents/prompts/tool-guidance.d.ts.map +1 -1
- package/dist/agents/prompts/tool-guidance.js +9 -1
- package/dist/agents/prompts/tool-guidance.js.map +1 -1
- package/dist/agents/tool-availability.d.ts +7 -2
- package/dist/agents/tool-availability.d.ts.map +1 -1
- package/dist/agents/tool-availability.js +15 -7
- package/dist/agents/tool-availability.js.map +1 -1
- package/dist/agents/tools.js +2 -2
- package/dist/agents/workflow-builder-agent.js +2 -2
- package/dist/agents/workspace.d.ts +3 -1
- package/dist/agents/workspace.d.ts.map +1 -1
- package/dist/agents/workspace.js +3 -3
- package/dist/agents/workspace.js.map +1 -1
- package/dist/auth/account-rotation-processor.js +4 -4
- package/dist/auth/index.js +3 -3
- package/dist/evals/index.js +1 -1
- package/dist/factory/client.d.ts +4 -1
- package/dist/factory/client.d.ts.map +1 -1
- package/dist/factory/client.js +22 -7
- package/dist/factory/client.js.map +1 -1
- package/dist/headless/cli.js +7 -7
- package/dist/headless/index.js +2 -2
- package/dist/headless/run-mc.js +2 -2
- package/dist/hooks/index.js +2 -2
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +36 -33
- package/dist/index.js.map +1 -1
- package/dist/mcp/index.js +1 -1
- package/dist/onboarding/settings.js +2 -2
- package/dist/plugins/install.js +2 -2
- package/dist/plugins/manager.js +3 -3
- package/dist/providers/claude-max.js +5 -5
- package/dist/providers/claude-max.js.map +1 -1
- package/dist/providers/github-copilot.js +2 -2
- package/dist/providers/github-copilot.js.map +1 -1
- package/dist/providers/google-thinking.js +1 -1
- package/dist/providers/google-thinking.js.map +1 -1
- package/dist/providers/kimi-coding.js +1 -1
- package/dist/providers/openai-codex.js +5 -5
- package/dist/providers/openai-codex.js.map +1 -1
- package/dist/providers/provider-thinking.d.ts +1 -1
- package/dist/providers/provider-thinking.d.ts.map +1 -1
- package/dist/providers/provider-thinking.js +2 -2
- package/dist/providers/provider-thinking.js.map +1 -1
- package/dist/providers/xai.js +1 -1
- package/dist/schedules/tools.js +1 -1
- package/dist/tools/utils.js +1 -1
- package/dist/tools/workflows/list-available-tools.js +1 -1
- package/dist/utils/plans.d.ts +2 -0
- package/dist/utils/plans.d.ts.map +1 -1
- package/dist/utils/plans.js +6 -0
- package/dist/utils/plans.js.map +1 -1
- package/dist/utils/prune-cli.js +2 -2
- package/dist/workflows/register-primitives.js +2 -2
- package/package.json +19 -18
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-thinking.js","names":[],"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:
|
|
1
|
+
{"version":3,"file":"provider-thinking.js","names":[],"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<Model extends AiSdkLanguageModel>(\n model: Model,\n thinking: ProviderThinkingOptions | undefined,\n): Model | ReturnType<typeof wrapLanguageModel> {\n if (!thinking) return model;\n return wrapLanguageModel({\n model,\n middleware: {\n specificationVersion: 'v4',\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,UAC8C;CAC9C,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,KAAK,YAAY;CACnB;CAEA,WAAoB,SAA8C;EAChE,OAAO,MAAM,WAAW,oBAAoB,SAAS,KAAK,SAAS,CAAC;CACtE;CAEA,SAAkB,SAA8C;EAC9D,OAAO,MAAM,SAAS,oBAAoB,SAAS,KAAK,SAAS,CAAC;CACpE;AACF"}
|
package/dist/providers/xai.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AuthStorage } from "../auth/storage.js";
|
|
2
1
|
import { ProviderAuthRequiredError, rejectUnauthorizedResponse } from "../auth/provider-auth-error.js";
|
|
2
|
+
import { AuthStorage } from "../auth/storage.js";
|
|
3
3
|
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
4
4
|
// src/providers/xai.ts
|
|
5
5
|
/**
|
package/dist/schedules/tools.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { parseInterval, validateInterval } from "./interval.js";
|
|
2
|
-
import { describeScheduleSource, shortScheduleId } from "./scheduler.js";
|
|
3
2
|
import { resolveScriptCommand } from "./run-script.js";
|
|
3
|
+
import { describeScheduleSource, shortScheduleId } from "./scheduler.js";
|
|
4
4
|
import * as path$1 from "path";
|
|
5
5
|
import { createTool } from "@mastra/core/tools";
|
|
6
6
|
import { z } from "zod";
|
package/dist/tools/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { WORKFLOW_BUILDER_NOISE_TOOL_IDS } from "./tool-ids.js";
|
|
2
1
|
import { extractJsonSchema } from "./extract-json-schema.js";
|
|
2
|
+
import { WORKFLOW_BUILDER_NOISE_TOOL_IDS } from "./tool-ids.js";
|
|
3
3
|
import { createTool } from "@mastra/core/tools";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
// src/tools/workflows/list-available-tools.ts
|
package/dist/utils/plans.d.ts
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
export declare function getPlansDir(): string;
|
|
3
3
|
export interface LocalPlansOptions {
|
|
4
4
|
factoryProjectId?: string | null;
|
|
5
|
+
/** Host-configured workspace-relative plans directory; wins over the default. */
|
|
6
|
+
plansDir?: string;
|
|
5
7
|
}
|
|
6
8
|
/** Workspace-relative directory the agent writes plan files into. */
|
|
7
9
|
export declare function getLocalPlansRelativeDir(options?: LocalPlansOptions): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plans.d.ts","sourceRoot":"","sources":["../../src/utils/plans.ts"],"names":[],"mappings":"AAKA,yDAAyD;AACzD,wBAAgB,WAAW,IAAI,MAAM,CAEpC;AAED,MAAM,WAAW,iBAAiB;IAChC,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"plans.d.ts","sourceRoot":"","sources":["../../src/utils/plans.ts"],"names":[],"mappings":"AAKA,yDAAyD;AACzD,wBAAgB,WAAW,IAAI,MAAM,CAEpC;AAED,MAAM,WAAW,iBAAiB;IAChC,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,iFAAiF;IACjF,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,qEAAqE;AACrE,wBAAgB,wBAAwB,CAAC,OAAO,GAAE,iBAAsB,GAAG,MAAM,CAQhF;AAED,sFAAsF;AACtF,wBAAgB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es plan files into. */
|
|
11
11
|
function getLocalPlansRelativeDir(options = {}) {
|
|
12
|
+
if (options.plansDir) {
|
|
13
|
+
const dir = path.normalize(options.plansDir);
|
|
14
|
+
let end = dir.length;
|
|
15
|
+
while (end > 0 && (dir[end - 1] === "/" || dir[end - 1] === "\\")) end--;
|
|
16
|
+
return dir.slice(0, end);
|
|
17
|
+
}
|
|
12
18
|
return options.factoryProjectId ? path.join(".artifacts", "plans") : path.join(DEFAULT_CONFIG_DIR, "plans");
|
|
13
19
|
}
|
|
14
20
|
/** Local (project-scoped) plans directory where the agent writes named plan files. */
|
package/dist/utils/plans.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plans.js","names":[],"sources":["../../src/utils/plans.ts"],"sourcesContent":["import fs from 'node:fs/promises';\nimport path from 'node:path';\nimport { DEFAULT_CONFIG_DIR } from '../constants.js';\nimport { getAppDataDir } from './project.js';\n\n/** Global plans directory for approved-plan archives. */\nexport function getPlansDir(): string {\n return process.env.MASTRA_PLANS_DIR ?? path.join(getAppDataDir(), 'plans');\n}\n\nexport interface LocalPlansOptions {\n factoryProjectId?: string | null;\n}\n\n/** Workspace-relative directory the agent writes plan files into. */\nexport function getLocalPlansRelativeDir(options: LocalPlansOptions = {}): string {\n return options.factoryProjectId ? path.join('.artifacts', 'plans') : path.join(DEFAULT_CONFIG_DIR, 'plans');\n}\n\n/** Local (project-scoped) plans directory where the agent writes named plan files. */\nexport function getLocalPlansDir(projectPath: string, options: LocalPlansOptions = {}): string {\n return path.join(projectPath, getLocalPlansRelativeDir(options));\n}\n\nfunction slugify(str: string): string {\n const slug = str\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, '-')\n .replace(/^-|-$/g, '');\n return slug || 'untitled';\n}\n\n/** Derive a plan filename from a title (e.g. `add-dark-mode.md`). */\nexport function getPlanFilename(title: string): string {\n return `${slugify(title)}.md`;\n}\n\n/**\n * Suggested workspace-relative path for a new plan file, shown in plan-mode prompts.\n * Without a title we fall back to a generic name the agent can rename later.\n */\nexport function getSuggestedPlanRelativePath(title?: string, options: LocalPlansOptions = {}): string {\n const filename = title ? getPlanFilename(title) : 'plan.md';\n return path.join(getLocalPlansRelativeDir(options), filename);\n}\n\n/**\n * Resolve a plan path submitted by the agent (absolute or project-relative) to an\n * absolute path. Returns `undefined` when no usable path was provided.\n */\nexport function resolvePlanPath(projectPath: string, submittedPath: string): string | undefined {\n if (!submittedPath) return undefined;\n return path.isAbsolute(submittedPath) ? submittedPath : path.resolve(projectPath, submittedPath);\n}\n\n/**\n * Whether `targetPath` (absolute or project-relative) is a valid plan file: a `.md`\n * file located directly inside the project's configured plan directory. Used by the\n * plan-mode write guard so the agent can write any named plan file there, but nothing\n * outside that directory.\n */\nexport function isPlanFilePath(projectPath: string, targetPath: string, options: LocalPlansOptions = {}): boolean {\n const abs = resolvePlanPath(projectPath, targetPath);\n if (!abs) return false;\n if (path.extname(abs).toLowerCase() !== '.md') return false;\n\n const plansDir = path.resolve(getLocalPlansDir(projectPath, options));\n const rel = path.relative(plansDir, abs);\n // Must be directly inside the plans dir (no nested subdirectories, no escaping it).\n if (rel === '' || rel.startsWith('..') || path.isAbsolute(rel)) return false;\n return !rel.includes(path.sep);\n}\n\nexport async function savePlanToDisk(opts: {\n title: string;\n plan: string;\n resourceId: string;\n plansDir?: string;\n}): Promise<void> {\n const { title, plan, resourceId } = opts;\n const plansDir = opts.plansDir ?? getPlansDir();\n const baseDir = path.resolve(plansDir);\n const dir = path.resolve(baseDir, resourceId);\n const rel = path.relative(baseDir, dir);\n if (rel.startsWith('..') || path.isAbsolute(rel)) {\n throw new Error(`Invalid resourceId: ${resourceId}`);\n }\n\n await fs.mkdir(dir, { recursive: true });\n\n const now = new Date();\n const timestamp = now.toISOString().replace(/:/g, '-');\n const slug = slugify(title);\n const filename = `${timestamp}-${slug}.md`;\n\n const content = `# ${title}\\n\\nApproved: ${now.toISOString()}\\n\\n${plan}\\n`;\n\n await fs.writeFile(path.join(dir, filename), content, 'utf-8');\n}\n\n/**\n * Read a plan markdown file by absolute path.\n *\n * The leading `# <title>` heading (if present) is parsed as the title and the remaining\n * content is returned as the plan body. Returns `undefined` when the file does not exist.\n */\nexport async function readPlanFile(absPath: string): Promise<{ title: string; plan: string } | undefined> {\n let raw: string;\n try {\n raw = await fs.readFile(absPath, 'utf-8');\n } catch {\n return undefined;\n }\n\n const lines = raw.split(/\\r?\\n/);\n const headingIndex = lines.findIndex(line => line.trim().length > 0);\n const heading = headingIndex >= 0 ? lines[headingIndex] : undefined;\n if (heading?.startsWith('# ')) {\n const title = heading.slice(2).trim();\n const plan = lines\n .slice(headingIndex + 1)\n .join('\\n')\n .replace(/^\\n+/, '')\n .trimEnd();\n return { title, plan };\n }\n\n return { title: '', plan: raw.trimEnd() };\n}\n\n/**\n * Approve the plan file at `planPath`: write a timestamped copy to the global plans\n * archive so approved plans are findable later. The local named plan file is left in\n * place so the user can review every plan made over time.\n *\n * Returns the local plan filename (e.g. `add-dark-mode.md`), or `undefined` when there\n * was no plan file to approve.\n */\nexport async function approvePlanFile(opts: {\n planPath: string;\n title: string;\n resourceId: string;\n plansDir?: string;\n}): Promise<string | undefined> {\n const { planPath, title, resourceId, plansDir } = opts;\n\n const current = await readPlanFile(planPath);\n if (!current) {\n return undefined;\n }\n\n const resolvedTitle = title || current.title || 'Implementation Plan';\n\n // Global archive (timestamped, never overwritten) so approved plans are findable later.\n await savePlanToDisk({ title: resolvedTitle, plan: current.plan, resourceId, plansDir });\n\n return path.basename(planPath);\n}\n"],"mappings":";;;;;;AAMA,SAAgB,cAAsB;CACpC,OAAO,QAAQ,IAAI,oBAAoB,KAAK,KAAK,cAAc,GAAG,OAAO;AAC3E;;
|
|
1
|
+
{"version":3,"file":"plans.js","names":[],"sources":["../../src/utils/plans.ts"],"sourcesContent":["import fs from 'node:fs/promises';\nimport path from 'node:path';\nimport { DEFAULT_CONFIG_DIR } from '../constants.js';\nimport { getAppDataDir } from './project.js';\n\n/** Global plans directory for approved-plan archives. */\nexport function getPlansDir(): string {\n return process.env.MASTRA_PLANS_DIR ?? path.join(getAppDataDir(), 'plans');\n}\n\nexport interface LocalPlansOptions {\n factoryProjectId?: string | null;\n /** Host-configured workspace-relative plans directory; wins over the default. */\n plansDir?: string;\n}\n\n/** Workspace-relative directory the agent writes plan files into. */\nexport function getLocalPlansRelativeDir(options: LocalPlansOptions = {}): string {\n if (options.plansDir) {\n const dir = path.normalize(options.plansDir);\n let end = dir.length;\n while (end > 0 && (dir[end - 1] === '/' || dir[end - 1] === '\\\\')) end--;\n return dir.slice(0, end);\n }\n return options.factoryProjectId ? path.join('.artifacts', 'plans') : path.join(DEFAULT_CONFIG_DIR, 'plans');\n}\n\n/** Local (project-scoped) plans directory where the agent writes named plan files. */\nexport function getLocalPlansDir(projectPath: string, options: LocalPlansOptions = {}): string {\n return path.join(projectPath, getLocalPlansRelativeDir(options));\n}\n\nfunction slugify(str: string): string {\n const slug = str\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, '-')\n .replace(/^-|-$/g, '');\n return slug || 'untitled';\n}\n\n/** Derive a plan filename from a title (e.g. `add-dark-mode.md`). */\nexport function getPlanFilename(title: string): string {\n return `${slugify(title)}.md`;\n}\n\n/**\n * Suggested workspace-relative path for a new plan file, shown in plan-mode prompts.\n * Without a title we fall back to a generic name the agent can rename later.\n */\nexport function getSuggestedPlanRelativePath(title?: string, options: LocalPlansOptions = {}): string {\n const filename = title ? getPlanFilename(title) : 'plan.md';\n return path.join(getLocalPlansRelativeDir(options), filename);\n}\n\n/**\n * Resolve a plan path submitted by the agent (absolute or project-relative) to an\n * absolute path. Returns `undefined` when no usable path was provided.\n */\nexport function resolvePlanPath(projectPath: string, submittedPath: string): string | undefined {\n if (!submittedPath) return undefined;\n return path.isAbsolute(submittedPath) ? submittedPath : path.resolve(projectPath, submittedPath);\n}\n\n/**\n * Whether `targetPath` (absolute or project-relative) is a valid plan file: a `.md`\n * file located directly inside the project's configured plan directory. Used by the\n * plan-mode write guard so the agent can write any named plan file there, but nothing\n * outside that directory.\n */\nexport function isPlanFilePath(projectPath: string, targetPath: string, options: LocalPlansOptions = {}): boolean {\n const abs = resolvePlanPath(projectPath, targetPath);\n if (!abs) return false;\n if (path.extname(abs).toLowerCase() !== '.md') return false;\n\n const plansDir = path.resolve(getLocalPlansDir(projectPath, options));\n const rel = path.relative(plansDir, abs);\n // Must be directly inside the plans dir (no nested subdirectories, no escaping it).\n if (rel === '' || rel.startsWith('..') || path.isAbsolute(rel)) return false;\n return !rel.includes(path.sep);\n}\n\nexport async function savePlanToDisk(opts: {\n title: string;\n plan: string;\n resourceId: string;\n plansDir?: string;\n}): Promise<void> {\n const { title, plan, resourceId } = opts;\n const plansDir = opts.plansDir ?? getPlansDir();\n const baseDir = path.resolve(plansDir);\n const dir = path.resolve(baseDir, resourceId);\n const rel = path.relative(baseDir, dir);\n if (rel.startsWith('..') || path.isAbsolute(rel)) {\n throw new Error(`Invalid resourceId: ${resourceId}`);\n }\n\n await fs.mkdir(dir, { recursive: true });\n\n const now = new Date();\n const timestamp = now.toISOString().replace(/:/g, '-');\n const slug = slugify(title);\n const filename = `${timestamp}-${slug}.md`;\n\n const content = `# ${title}\\n\\nApproved: ${now.toISOString()}\\n\\n${plan}\\n`;\n\n await fs.writeFile(path.join(dir, filename), content, 'utf-8');\n}\n\n/**\n * Read a plan markdown file by absolute path.\n *\n * The leading `# <title>` heading (if present) is parsed as the title and the remaining\n * content is returned as the plan body. Returns `undefined` when the file does not exist.\n */\nexport async function readPlanFile(absPath: string): Promise<{ title: string; plan: string } | undefined> {\n let raw: string;\n try {\n raw = await fs.readFile(absPath, 'utf-8');\n } catch {\n return undefined;\n }\n\n const lines = raw.split(/\\r?\\n/);\n const headingIndex = lines.findIndex(line => line.trim().length > 0);\n const heading = headingIndex >= 0 ? lines[headingIndex] : undefined;\n if (heading?.startsWith('# ')) {\n const title = heading.slice(2).trim();\n const plan = lines\n .slice(headingIndex + 1)\n .join('\\n')\n .replace(/^\\n+/, '')\n .trimEnd();\n return { title, plan };\n }\n\n return { title: '', plan: raw.trimEnd() };\n}\n\n/**\n * Approve the plan file at `planPath`: write a timestamped copy to the global plans\n * archive so approved plans are findable later. The local named plan file is left in\n * place so the user can review every plan made over time.\n *\n * Returns the local plan filename (e.g. `add-dark-mode.md`), or `undefined` when there\n * was no plan file to approve.\n */\nexport async function approvePlanFile(opts: {\n planPath: string;\n title: string;\n resourceId: string;\n plansDir?: string;\n}): Promise<string | undefined> {\n const { planPath, title, resourceId, plansDir } = opts;\n\n const current = await readPlanFile(planPath);\n if (!current) {\n return undefined;\n }\n\n const resolvedTitle = title || current.title || 'Implementation Plan';\n\n // Global archive (timestamped, never overwritten) so approved plans are findable later.\n await savePlanToDisk({ title: resolvedTitle, plan: current.plan, resourceId, plansDir });\n\n return path.basename(planPath);\n}\n"],"mappings":";;;;;;AAMA,SAAgB,cAAsB;CACpC,OAAO,QAAQ,IAAI,oBAAoB,KAAK,KAAK,cAAc,GAAG,OAAO;AAC3E;;AASA,SAAgB,yBAAyB,UAA6B,CAAC,GAAW;CAChF,IAAI,QAAQ,UAAU;EACpB,MAAM,MAAM,KAAK,UAAU,QAAQ,QAAQ;EAC3C,IAAI,MAAM,IAAI;EACd,OAAO,MAAM,MAAM,IAAI,MAAM,OAAO,OAAO,IAAI,MAAM,OAAO,OAAO;EACnE,OAAO,IAAI,MAAM,GAAG,GAAG;CACzB;CACA,OAAO,QAAQ,mBAAmB,KAAK,KAAK,cAAc,OAAO,IAAI,KAAK,KAAK,oBAAoB,OAAO;AAC5G;;AAGA,SAAgB,iBAAiB,aAAqB,UAA6B,CAAC,GAAW;CAC7F,OAAO,KAAK,KAAK,aAAa,yBAAyB,OAAO,CAAC;AACjE;AAEA,SAAS,QAAQ,KAAqB;CAKpC,OAJa,IACV,YAAY,CAAC,CACb,QAAQ,eAAe,GAAG,CAAC,CAC3B,QAAQ,UAAU,EACX,KAAK;AACjB;;AAGA,SAAgB,gBAAgB,OAAuB;CACrD,OAAO,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Q,MAAM,GAEtB,EAAE,GADjB,QAAQ,KACe,EAAE;CAEtC,MAAM,UAAU,KAAK,MAAM,gBAAgB,IAAI,YAAY,EAAE,MAAM,KAAK;CAExE,MAAM,GAAG,UAAU,KAAK,KAAK,KAAK,QAAQ,GAAG,SAAS,OAAO;AAC/D;;;;;;;AAQA,eAAsB,aAAa,SAAuE;CACxG,IAAI;CACJ,IAAI;EACF,MAAM,MAAM,GAAG,SAAS,SAAS,OAAO;CAC1C,QAAQ;EACN;CACF;CAEA,MAAM,QAAQ,IAAI,MAAM,OAAO;CAC/B,MAAM,eAAe,MAAM,WAAU,SAAQ,KAAK,KAAK,CAAC,CAAC,SAAS,CAAC;CACnE,MAAM,UAAU,gBAAgB,IAAI,MAAM,gBAAgB,KAAA;CAC1D,IAAI,SAAS,WAAW,IAAI,GAO1B,OAAO;EAAE,OANK,QAAQ,MAAM,CAAC,CAAC,CAAC,KAMlB;EAAG,MALH,MACV,MAAM,eAAe,CAAC,CAAC,CACvB,KAAK,IAAI,CAAC,CACV,QAAQ,QAAQ,EAAE,CAAC,CACnB,QACgB;CAAE;CAGvB,OAAO;EAAE,OAAO;EAAI,MAAM,IAAI,QAAQ;CAAE;AAC1C;;;;;;;;;AAUA,eAAsB,gBAAgB,MAKN;CAC9B,MAAM,EAAE,UAAU,OAAO,YAAY,aAAa;CAElD,MAAM,UAAU,MAAM,aAAa,QAAQ;CAC3C,IAAI,CAAC,SACH;CAMF,MAAM,eAAe;EAAE,OAHD,SAAS,QAAQ,SAAS;EAGH,MAAM,QAAQ;EAAM;EAAY;CAAS,CAAC;CAEvF,OAAO,KAAK,SAAS,QAAQ;AAC/B"}
|
package/dist/utils/prune-cli.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { DEFAULT_CONFIG_DIR } from "../constants.js";
|
|
2
|
-
import { detectProject, getStorageConfig } from "./project.js";
|
|
3
2
|
import { loadSettings } from "../onboarding/settings.js";
|
|
4
3
|
import { acquireMaintenanceLock } from "./maintenance-lock.js";
|
|
5
|
-
import {
|
|
4
|
+
import { detectProject, getStorageConfig } from "./project.js";
|
|
6
5
|
import { createStorage, createVectorStore } from "./storage-factory.js";
|
|
6
|
+
import { DEFAULT_RETENTION, createStorageMaintenance, resolveLocalDbFiles, runStorageMaintenance } from "./storage-maintenance.js";
|
|
7
7
|
import path from "path";
|
|
8
8
|
import { LibSQLVector } from "@mastra/libsql";
|
|
9
9
|
// src/utils/prune-cli.ts
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { MC_TOOLS } from "../tool-names.js";
|
|
2
|
-
import { createConfiguredWebTools } from "../tools/web-search.js";
|
|
3
1
|
import { createMastraCodeWorkspaceTools } from "../agents/tool-availability.js";
|
|
4
2
|
import { LazyNotificationsStorage } from "../agents/tools.js";
|
|
5
3
|
import { workflowBuilderAgent } from "../agents/workflow-builder-agent.js";
|
|
4
|
+
import { MC_TOOLS } from "../tool-names.js";
|
|
5
|
+
import { createConfiguredWebTools } from "../tools/web-search.js";
|
|
6
6
|
import { LocalFilesystem, LocalSandbox, Workspace, createWorkspaceTools } from "@mastra/core/workspace";
|
|
7
7
|
import { createNotificationInboxTool } from "@mastra/core/notifications";
|
|
8
8
|
// src/workflows/register-primitives.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/code-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.19.0-alpha.0",
|
|
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": {
|
|
@@ -47,13 +47,13 @@
|
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@agentclientprotocol/sdk": "^0.21.1",
|
|
49
49
|
"@ai-sdk/amazon-bedrock": "^5.0.130",
|
|
50
|
-
"@ai-sdk/anthropic": "^
|
|
50
|
+
"@ai-sdk/anthropic": "^4.0.94",
|
|
51
51
|
"@ai-sdk/google-vertex": "^3.0.186",
|
|
52
|
-
"@ai-sdk/openai": "^
|
|
53
|
-
"@ai-sdk/openai-compatible": "^
|
|
52
|
+
"@ai-sdk/openai": "^4.0.106",
|
|
53
|
+
"@ai-sdk/openai-compatible": "^3.0.82",
|
|
54
54
|
"@ast-grep/napi": "^0.42.3",
|
|
55
55
|
"@aws-sdk/credential-providers": "^3.1156.0",
|
|
56
|
-
"ai": "^
|
|
56
|
+
"ai": "^7.0.159",
|
|
57
57
|
"execa": "^9.6.1",
|
|
58
58
|
"libsql": "^0.5.29",
|
|
59
59
|
"posthog-node": "^5.57.1",
|
|
@@ -64,21 +64,22 @@
|
|
|
64
64
|
"yaml": "^2.9.1",
|
|
65
65
|
"zod": "^4.6.7",
|
|
66
66
|
"@mastra/agent-browser": "0.6.0",
|
|
67
|
-
"@mastra/client-js": "1.
|
|
68
|
-
"@mastra/duckdb": "1.
|
|
67
|
+
"@mastra/client-js": "1.60.0-alpha.0",
|
|
68
|
+
"@mastra/duckdb": "1.19.0-alpha.0",
|
|
69
69
|
"@mastra/fastembed": "1.3.6",
|
|
70
70
|
"@mastra/github-signals": "0.5.2",
|
|
71
|
-
"@mastra/libsql": "1.
|
|
72
|
-
"@mastra/mcp": "2.
|
|
73
|
-
"@mastra/memory": "1.41.
|
|
74
|
-
"@mastra/observability": "1.23.
|
|
75
|
-
"@mastra/parallel": "0.1.5
|
|
76
|
-
"@mastra/pg": "1.
|
|
71
|
+
"@mastra/libsql": "1.30.0-alpha.0",
|
|
72
|
+
"@mastra/mcp": "2.9.0-alpha.0",
|
|
73
|
+
"@mastra/memory": "1.41.1-alpha.0",
|
|
74
|
+
"@mastra/observability": "1.23.2-alpha.0",
|
|
75
|
+
"@mastra/parallel": "0.1.5",
|
|
76
|
+
"@mastra/pg": "1.36.0-alpha.0",
|
|
77
77
|
"@mastra/schema-compat": "1.3.17",
|
|
78
78
|
"@mastra/stagehand": "0.4.0",
|
|
79
79
|
"@mastra/tavily": "1.1.3"
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
82
|
+
"@ai-sdk/provider": "^4.0.35",
|
|
82
83
|
"@copilotkit/aimock": "^1.46.0",
|
|
83
84
|
"@libsql/client": "^0.18.0",
|
|
84
85
|
"@types/node": "22.19.15",
|
|
@@ -87,13 +88,13 @@
|
|
|
87
88
|
"tsx": "^4.23.15",
|
|
88
89
|
"typescript": "^6.0.3",
|
|
89
90
|
"vitest": "5.1.0",
|
|
90
|
-
"@internal/lint": "0.0.
|
|
91
|
-
"@internal/types-builder": "0.0.
|
|
92
|
-
"@internal/workspace-test-utils": "0.0.
|
|
93
|
-
"@mastra/core": "1.
|
|
91
|
+
"@internal/lint": "0.0.148",
|
|
92
|
+
"@internal/types-builder": "0.0.123",
|
|
93
|
+
"@internal/workspace-test-utils": "0.0.92",
|
|
94
|
+
"@mastra/core": "1.83.0-alpha.0"
|
|
94
95
|
},
|
|
95
96
|
"peerDependencies": {
|
|
96
|
-
"@mastra/core": ">=1.
|
|
97
|
+
"@mastra/core": ">=1.83.0-0 <2.0.0-0"
|
|
97
98
|
},
|
|
98
99
|
"engines": {
|
|
99
100
|
"node": ">=22.19.0"
|