@mastra/codemod 0.1.0-beta.1 → 0.1.0-beta.3
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/CHANGELOG.md +12 -0
- package/README.md +1 -0
- package/dist/codemods/v1/mcp-get-tools.js +3 -1
- package/dist/codemods/v1/mcp-get-tools.js.map +1 -1
- package/dist/codemods/v1/mcp-get-toolsets.js +3 -1
- package/dist/codemods/v1/mcp-get-toolsets.js.map +1 -1
- package/dist/codemods/v1/not-implemented/mastra-required-id.js +1 -0
- package/dist/codemods/v1/not-implemented/mastra-required-id.js.map +1 -1
- package/dist/codemods/v1/workflow-stream-vnext.js +35 -0
- package/dist/codemods/v1/workflow-stream-vnext.js.map +1 -0
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/package.json +5 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @mastra/codemod
|
|
2
2
|
|
|
3
|
+
## 0.1.0-beta.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Add `v1/workflow-stream-vnext` codemod. This codemod renames `streamVNext()`, `resumeStreamVNext()`, and `observeStreamVNext()` to their "non-VNext" counterparts. ([#10802](https://github.com/mastra-ai/mastra/pull/10802))
|
|
8
|
+
|
|
9
|
+
## 0.1.0-beta.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Fix `mastra-required-id`, `mcp-get-toolsets`, and `mcp-get-tools` codemods to add missing imports and instances. ([#10221](https://github.com/mastra-ai/mastra/pull/10221))
|
|
14
|
+
|
|
3
15
|
## 0.1.0-beta.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -70,6 +70,7 @@ npx @mastra/codemod@beta v1/mastra-core-imports .
|
|
|
70
70
|
| `v1/workflow-create-run-async` | Renames `workflow.createRunAsync()` → `workflow.createRun()` |
|
|
71
71
|
| `v1/workflow-list-runs` | Renames `workflow.getWorkflowRuns()` → `workflow.listWorkflowRuns()` |
|
|
72
72
|
| `v1/workflow-run-count` | Renames `context.runCount` → `context.retryCount` in step execution functions |
|
|
73
|
+
| `v1/workflow-stream-vnext` | Renames `streamVNext()`, `resumeStreamVNext()`, and `observeStreamVNext()` |
|
|
73
74
|
|
|
74
75
|
## CLI Options
|
|
75
76
|
|
|
@@ -9,7 +9,9 @@ import {
|
|
|
9
9
|
// src/codemods/v1/mcp-get-tools.ts
|
|
10
10
|
var mcp_get_tools_default = createTransformer((_fileInfo, _api, _options, context) => {
|
|
11
11
|
const { j, root } = context;
|
|
12
|
-
const
|
|
12
|
+
const mcpServerInstances = trackClassInstances(j, root, "MCPServer");
|
|
13
|
+
const mcpClientInstances = trackClassInstances(j, root, "MCPClient");
|
|
14
|
+
const mcpInstances = /* @__PURE__ */ new Set([...mcpServerInstances, ...mcpClientInstances]);
|
|
13
15
|
const count = renameMethod(j, root, mcpInstances, "getTools", "listTools");
|
|
14
16
|
if (count > 0) {
|
|
15
17
|
context.hasChanges = true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/codemods/v1/mcp-get-tools.ts"],"sourcesContent":["import { createTransformer } from '../lib/create-transformer';\nimport { trackClassInstances, renameMethod } from '../lib/utils';\n\n/**\n * Transforms MCPServer getTools method to listTools:\n * - mcp.getTools() → mcp.listTools()\n *\n * Only transforms methods on variables that were instantiated with `new MCPServer(...)`\n */\nexport default createTransformer((_fileInfo, _api, _options, context) => {\n const { j, root } = context;\n\n // Track MCPServer instances and rename method in a single optimized pass\n const
|
|
1
|
+
{"version":3,"sources":["../../../src/codemods/v1/mcp-get-tools.ts"],"sourcesContent":["import { createTransformer } from '../lib/create-transformer';\nimport { trackClassInstances, renameMethod } from '../lib/utils';\n\n/**\n * Transforms MCPServer and MCPClient getTools method to listTools:\n * - mcp.getTools() → mcp.listTools()\n *\n * Only transforms methods on variables that were instantiated with `new MCPServer(...)` or `new MCPClient(...)`\n */\nexport default createTransformer((_fileInfo, _api, _options, context) => {\n const { j, root } = context;\n\n // Track MCPServer and MCPClient instances and rename method in a single optimized pass\n const mcpServerInstances = trackClassInstances(j, root, 'MCPServer');\n const mcpClientInstances = trackClassInstances(j, root, 'MCPClient');\n const mcpInstances = new Set([...mcpServerInstances, ...mcpClientInstances]);\n const count = renameMethod(j, root, mcpInstances, 'getTools', 'listTools');\n\n if (count > 0) {\n context.hasChanges = true;\n context.messages.push(`Transformed MCPServer method: getTools → listTools`);\n }\n});\n"],"mappings":";;;;;;;;;AASA,IAAO,wBAAQ,kBAAkB,CAAC,WAAW,MAAM,UAAU,YAAY;AACvE,QAAM,EAAE,GAAG,KAAK,IAAI;AAGpB,QAAM,qBAAqB,oBAAoB,GAAG,MAAM,WAAW;AACnE,QAAM,qBAAqB,oBAAoB,GAAG,MAAM,WAAW;AACnE,QAAM,eAAe,oBAAI,IAAI,CAAC,GAAG,oBAAoB,GAAG,kBAAkB,CAAC;AAC3E,QAAM,QAAQ,aAAa,GAAG,MAAM,cAAc,YAAY,WAAW;AAEzE,MAAI,QAAQ,GAAG;AACb,YAAQ,aAAa;AACrB,YAAQ,SAAS,KAAK,yDAAoD;AAAA,EAC5E;AACF,CAAC;","names":[]}
|
|
@@ -9,7 +9,9 @@ import {
|
|
|
9
9
|
// src/codemods/v1/mcp-get-toolsets.ts
|
|
10
10
|
var mcp_get_toolsets_default = createTransformer((_fileInfo, _api, _options, context) => {
|
|
11
11
|
const { j, root } = context;
|
|
12
|
-
const
|
|
12
|
+
const mcpServerInstances = trackClassInstances(j, root, "MCPServer");
|
|
13
|
+
const mcpClientInstances = trackClassInstances(j, root, "MCPClient");
|
|
14
|
+
const mcpInstances = /* @__PURE__ */ new Set([...mcpServerInstances, ...mcpClientInstances]);
|
|
13
15
|
const count = renameMethod(j, root, mcpInstances, "getToolsets", "listToolsets");
|
|
14
16
|
if (count > 0) {
|
|
15
17
|
context.hasChanges = true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/codemods/v1/mcp-get-toolsets.ts"],"sourcesContent":["import { createTransformer } from '../lib/create-transformer';\nimport { trackClassInstances, renameMethod } from '../lib/utils';\n\n/**\n * Transforms MCPServer getToolsets method to listToolsets:\n * - mcp.getToolsets() → mcp.listToolsets()\n *\n * Only transforms methods on variables that were instantiated with `new MCPServer(...)`\n */\nexport default createTransformer((_fileInfo, _api, _options, context) => {\n const { j, root } = context;\n\n // Track MCPServer instances and rename method in a single optimized pass\n const
|
|
1
|
+
{"version":3,"sources":["../../../src/codemods/v1/mcp-get-toolsets.ts"],"sourcesContent":["import { createTransformer } from '../lib/create-transformer';\nimport { trackClassInstances, renameMethod } from '../lib/utils';\n\n/**\n * Transforms MCPServer and MCPClient getToolsets method to listToolsets:\n * - mcp.getToolsets() → mcp.listToolsets()\n *\n * Only transforms methods on variables that were instantiated with `new MCPServer(...)` or `new MCPClient(...)`\n */\nexport default createTransformer((_fileInfo, _api, _options, context) => {\n const { j, root } = context;\n\n // Track MCPServer and MCPClient instances and rename method in a single optimized pass\n const mcpServerInstances = trackClassInstances(j, root, 'MCPServer');\n const mcpClientInstances = trackClassInstances(j, root, 'MCPClient');\n const mcpInstances = new Set([...mcpServerInstances, ...mcpClientInstances]);\n const count = renameMethod(j, root, mcpInstances, 'getToolsets', 'listToolsets');\n\n if (count > 0) {\n context.hasChanges = true;\n context.messages.push(`Transformed MCPServer method: getToolsets → listToolsets`);\n }\n});\n"],"mappings":";;;;;;;;;AASA,IAAO,2BAAQ,kBAAkB,CAAC,WAAW,MAAM,UAAU,YAAY;AACvE,QAAM,EAAE,GAAG,KAAK,IAAI;AAGpB,QAAM,qBAAqB,oBAAoB,GAAG,MAAM,WAAW;AACnE,QAAM,qBAAqB,oBAAoB,GAAG,MAAM,WAAW;AACnE,QAAM,eAAe,oBAAI,IAAI,CAAC,GAAG,oBAAoB,GAAG,kBAAkB,CAAC;AAC3E,QAAM,QAAQ,aAAa,GAAG,MAAM,cAAc,eAAe,cAAc;AAE/E,MAAI,QAAQ,GAAG;AACb,YAAQ,aAAa;AACrB,YAAQ,SAAS,KAAK,+DAA0D;AAAA,EAClF;AACF,CAAC;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/codemods/v1/not-implemented/mastra-required-id.ts"],"sourcesContent":["/* eslint-disable no-warning-comments */\nimport { insertCommentOnce } from '../../lib/add-comment';\nimport { createTransformer } from '../../lib/create-transformer';\n\n/**\n * Adds FIXME comments to Mastra primitives that now require an `id` parameter.\n * This includes storages, vector stores, agents, workflows, tools, scorers, and MCP servers.\n *\n * Before:\n * const agent = new Agent({ name: 'Support Agent' });\n * const tool = createTool({ description: 'Get weather' });\n *\n * After:\n * /* FIXME(mastra): Add a unique `id` parameter. See: ... *\\/\n * const agent = new Agent({ name: 'Support Agent' });\n * /* FIXME(mastra): Add a unique `id` parameter. See: ... *\\/\n * const tool = createTool({ description: 'Get weather' });\n */\nexport default createTransformer((fileInfo, api, options, context) => {\n const { j, root } = context;\n\n const COMMENT_MESSAGE =\n 'FIXME(mastra): Add a unique `id` parameter. See: https://mastra.ai/guides/v1/migrations/upgrade-to-v1/mastra#required-id-parameter-for-all-mastra-primitives';\n\n // List of class names that require id\n const storageClasses = [\n 'LibSQLStore',\n 'PostgresStore',\n 'D1Store',\n 'MongoDBStore',\n 'DynamoDBStore',\n 'PgVector',\n 'ChromaVector',\n 'PineconeVector',\n 'QdrantVector',\n 'LanceVector',\n 'Agent',\n 'MCPServer',\n ];\n\n // List of function names that require id\n const createFunctions = ['createWorkflow', 'createTool', 'createScorer'];\n\n // Find NewExpression for classes\n root.find(j.NewExpression).forEach(path => {\n if (path.value.callee.type === 'Identifier') {\n const className = path.value.callee.name;\n\n if (storageClasses.includes(className)) {\n // Check if the config already has an id property\n const hasId = path.value.arguments.some(arg => {\n if (arg.type === 'ObjectExpression') {\n return arg.properties?.some(\n prop =>\n (prop.type === 'Property' || prop.type === 'ObjectProperty') &&\n prop.key?.type === 'Identifier' &&\n prop.key.name === 'id',\n );\n }\n return false;\n });\n\n if (!hasId) {\n // Find the parent statement to add comment\n let parent = path.parent;\n const statementTypes = new Set([\n 'VariableDeclaration',\n 'ExpressionStatement',\n 'ReturnStatement',\n 'ExportDefaultDeclaration',\n 'ExportNamedDeclaration',\n 'Program',\n ]);\n\n while (parent && !statementTypes.has(parent.value.type)) {\n parent = parent.parent;\n }\n\n if (parent && parent.value) {\n // For export declarations, add comment to the export itself\n let targetNode = parent.value;\n if (\n targetNode.type !== 'ExportDefaultDeclaration' &&\n targetNode.type !== 'ExportNamedDeclaration' &&\n parent.parent &&\n (parent.parent.value.type === 'ExportDefaultDeclaration' ||\n parent.parent.value.type === 'ExportNamedDeclaration')\n ) {\n targetNode = parent.parent.value;\n }\n\n const added = insertCommentOnce(targetNode, j, COMMENT_MESSAGE);\n if (added) {\n context.hasChanges = true;\n }\n }\n }\n }\n }\n });\n\n // Find CallExpression for create functions\n root.find(j.CallExpression).forEach(path => {\n if (path.value.callee.type === 'Identifier') {\n const functionName = path.value.callee.name;\n\n if (createFunctions.includes(functionName)) {\n // Check if the config already has an id property\n const hasId = path.value.arguments.some(arg => {\n if (arg.type === 'ObjectExpression') {\n return arg.properties?.some(\n prop =>\n (prop.type === 'Property' || prop.type === 'ObjectProperty') &&\n prop.key?.type === 'Identifier' &&\n prop.key.name === 'id',\n );\n }\n return false;\n });\n\n if (!hasId) {\n // Find the parent statement to add comment\n let parent = path.parent;\n const statementTypes = new Set([\n 'VariableDeclaration',\n 'ExpressionStatement',\n 'ReturnStatement',\n 'ExportDefaultDeclaration',\n 'ExportNamedDeclaration',\n 'Program',\n ]);\n\n while (parent && !statementTypes.has(parent.value.type)) {\n parent = parent.parent;\n }\n\n if (parent && parent.value) {\n // For export declarations, add comment to the export itself\n let targetNode = parent.value;\n if (\n targetNode.type !== 'ExportDefaultDeclaration' &&\n targetNode.type !== 'ExportNamedDeclaration' &&\n parent.parent &&\n (parent.parent.value.type === 'ExportDefaultDeclaration' ||\n parent.parent.value.type === 'ExportNamedDeclaration')\n ) {\n targetNode = parent.parent.value;\n }\n\n const added = insertCommentOnce(targetNode, j, COMMENT_MESSAGE);\n if (added) {\n context.hasChanges = true;\n }\n }\n }\n }\n }\n });\n\n if (context.hasChanges) {\n context.messages.push(`Not Implemented ${fileInfo.path}: Mastra primitives now require a unique id parameter.`);\n }\n});\n"],"mappings":";;;;;;;;AAkBA,IAAO,6BAAQ,kBAAkB,CAAC,UAAU,KAAK,SAAS,YAAY;AACpE,QAAM,EAAE,GAAG,KAAK,IAAI;AAEpB,QAAM,kBACJ;AAGF,QAAM,iBAAiB;AAAA,IACrB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAGA,QAAM,kBAAkB,CAAC,kBAAkB,cAAc,cAAc;AAGvE,OAAK,KAAK,EAAE,aAAa,EAAE,QAAQ,UAAQ;AACzC,QAAI,KAAK,MAAM,OAAO,SAAS,cAAc;AAC3C,YAAM,YAAY,KAAK,MAAM,OAAO;AAEpC,UAAI,eAAe,SAAS,SAAS,GAAG;AAEtC,cAAM,QAAQ,KAAK,MAAM,UAAU,KAAK,SAAO;AAC7C,cAAI,IAAI,SAAS,oBAAoB;AACnC,mBAAO,IAAI,YAAY;AAAA,cACrB,WACG,KAAK,SAAS,cAAc,KAAK,SAAS,qBAC3C,KAAK,KAAK,SAAS,gBACnB,KAAK,IAAI,SAAS;AAAA,YACtB;AAAA,UACF;AACA,iBAAO;AAAA,QACT,CAAC;AAED,YAAI,CAAC,OAAO;AAEV,cAAI,SAAS,KAAK;AAClB,gBAAM,iBAAiB,oBAAI,IAAI;AAAA,YAC7B;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACF,CAAC;AAED,iBAAO,UAAU,CAAC,e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,4BACpB,OAAO,WACN,OAAO,OAAO,MAAM,SAAS,8BAC5B,OAAO,OAAO,MAAM,SAAS,2BAC/B;AACA,2BAAa,OAAO,OAAO;AAAA,YAC7B;AAEA,kBAAM,QAAQ,kBAAkB,YAAY,GAAG,eAAe;AAC9D,gBAAI,OAAO;AACT,sBAAQ,aAAa;AAAA,YACvB;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC;AAED,MAAI,QAAQ,YAAY;AACtB,YAAQ,SAAS,KAAK,mBAAmB,SAAS,IAAI,wDAAwD;AAAA,EAChH;AACF,CAAC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/codemods/v1/not-implemented/mastra-required-id.ts"],"sourcesContent":["/* eslint-disable no-warning-comments */\nimport { insertCommentOnce } from '../../lib/add-comment';\nimport { createTransformer } from '../../lib/create-transformer';\n\n/**\n * Adds FIXME comments to Mastra primitives that now require an `id` parameter.\n * This includes storages, vector stores, agents, workflows, tools, scorers, and MCP servers.\n *\n * Before:\n * const agent = new Agent({ name: 'Support Agent' });\n * const tool = createTool({ description: 'Get weather' });\n *\n * After:\n * /* FIXME(mastra): Add a unique `id` parameter. See: ... *\\/\n * const agent = new Agent({ name: 'Support Agent' });\n * /* FIXME(mastra): Add a unique `id` parameter. See: ... *\\/\n * const tool = createTool({ description: 'Get weather' });\n */\nexport default createTransformer((fileInfo, api, options, context) => {\n const { j, root } = context;\n\n const COMMENT_MESSAGE =\n 'FIXME(mastra): Add a unique `id` parameter. See: https://mastra.ai/guides/v1/migrations/upgrade-to-v1/mastra#required-id-parameter-for-all-mastra-primitives';\n\n // List of class names that require id\n const storageClasses = [\n 'LibSQLStore',\n 'PostgresStore',\n 'D1Store',\n 'MongoDBStore',\n 'DynamoDBStore',\n 'LibSQLVector',\n 'PgVector',\n 'ChromaVector',\n 'PineconeVector',\n 'QdrantVector',\n 'LanceVector',\n 'Agent',\n 'MCPServer',\n ];\n\n // List of function names that require id\n const createFunctions = ['createWorkflow', 'createTool', 'createScorer'];\n\n // Find NewExpression for classes\n root.find(j.NewExpression).forEach(path => {\n if (path.value.callee.type === 'Identifier') {\n const className = path.value.callee.name;\n\n if (storageClasses.includes(className)) {\n // Check if the config already has an id property\n const hasId = path.value.arguments.some(arg => {\n if (arg.type === 'ObjectExpression') {\n return arg.properties?.some(\n prop =>\n (prop.type === 'Property' || prop.type === 'ObjectProperty') &&\n prop.key?.type === 'Identifier' &&\n prop.key.name === 'id',\n );\n }\n return false;\n });\n\n if (!hasId) {\n // Find the parent statement to add comment\n let parent = path.parent;\n const statementTypes = new Set([\n 'VariableDeclaration',\n 'ExpressionStatement',\n 'ReturnStatement',\n 'ExportDefaultDeclaration',\n 'ExportNamedDeclaration',\n 'Program',\n ]);\n\n while (parent && !statementTypes.has(parent.value.type)) {\n parent = parent.parent;\n }\n\n if (parent && parent.value) {\n // For export declarations, add comment to the export itself\n let targetNode = parent.value;\n if (\n targetNode.type !== 'ExportDefaultDeclaration' &&\n targetNode.type !== 'ExportNamedDeclaration' &&\n parent.parent &&\n (parent.parent.value.type === 'ExportDefaultDeclaration' ||\n parent.parent.value.type === 'ExportNamedDeclaration')\n ) {\n targetNode = parent.parent.value;\n }\n\n const added = insertCommentOnce(targetNode, j, COMMENT_MESSAGE);\n if (added) {\n context.hasChanges = true;\n }\n }\n }\n }\n }\n });\n\n // Find CallExpression for create functions\n root.find(j.CallExpression).forEach(path => {\n if (path.value.callee.type === 'Identifier') {\n const functionName = path.value.callee.name;\n\n if (createFunctions.includes(functionName)) {\n // Check if the config already has an id property\n const hasId = path.value.arguments.some(arg => {\n if (arg.type === 'ObjectExpression') {\n return arg.properties?.some(\n prop =>\n (prop.type === 'Property' || prop.type === 'ObjectProperty') &&\n prop.key?.type === 'Identifier' &&\n prop.key.name === 'id',\n );\n }\n return false;\n });\n\n if (!hasId) {\n // Find the parent statement to add comment\n let parent = path.parent;\n const statementTypes = new Set([\n 'VariableDeclaration',\n 'ExpressionStatement',\n 'ReturnStatement',\n 'ExportDefaultDeclaration',\n 'ExportNamedDeclaration',\n 'Program',\n ]);\n\n while (parent && !statementTypes.has(parent.value.type)) {\n parent = parent.parent;\n }\n\n if (parent && parent.value) {\n // For export declarations, add comment to the export itself\n let targetNode = parent.value;\n if (\n targetNode.type !== 'ExportDefaultDeclaration' &&\n targetNode.type !== 'ExportNamedDeclaration' &&\n parent.parent &&\n (parent.parent.value.type === 'ExportDefaultDeclaration' ||\n parent.parent.value.type === 'ExportNamedDeclaration')\n ) {\n targetNode = parent.parent.value;\n }\n\n const added = insertCommentOnce(targetNode, j, COMMENT_MESSAGE);\n if (added) {\n context.hasChanges = true;\n }\n }\n }\n }\n }\n });\n\n if (context.hasChanges) {\n context.messages.push(`Not Implemented ${fileInfo.path}: Mastra primitives now require a unique id parameter.`);\n }\n});\n"],"mappings":";;;;;;;;AAkBA,IAAO,6BAAQ,kBAAkB,CAAC,UAAU,KAAK,SAAS,YAAY;AACpE,QAAM,EAAE,GAAG,KAAK,IAAI;AAEpB,QAAM,kBACJ;AAGF,QAAM,iBAAiB;AAAA,IACrB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAGA,QAAM,kBAAkB,CAAC,kBAAkB,cAAc,cAAc;AAGvE,OAAK,KAAK,EAAE,aAAa,EAAE,QAAQ,UAAQ;AACzC,QAAI,KAAK,MAAM,OAAO,SAAS,cAAc;AAC3C,YAAM,YAAY,KAAK,MAAM,OAAO;AAEpC,UAAI,eAAe,SAAS,SAAS,GAAG;AAEtC,cAAM,QAAQ,KAAK,MAAM,UAAU,KAAK,SAAO;AAC7C,cAAI,IAAI,SAAS,oBAAoB;AACnC,mBAAO,IAAI,YAAY;AAAA,cACrB,WACG,KAAK,SAAS,cAAc,KAAK,SAAS,qBAC3C,KAAK,KAAK,SAAS,gBACnB,KAAK,IA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A;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACF,CAAC;AAED,iBAAO,UAAU,CAAC,eAAe,IAAI,OAAO,MAAM,IAAI,GAAG;AACvD,qBAAS,OAAO;AAAA,UAClB;AAEA,cAAI,UAAU,OAAO,OAAO;AAE1B,gBAAI,aAAa,OAAO;AACxB,gBACE,WAAW,SAAS,8BACpB,WAAW,SAAS,4BACpB,OAAO,WACN,OAAO,OAAO,MAAM,SAAS,8BAC5B,OAAO,OAAO,MAAM,SAAS,2BAC/B;AACA,2BAAa,OAAO,OAAO;AAAA,YAC7B;AAEA,kBAAM,QAAQ,kBAAkB,YAAY,GAAG,eAAe;AAC9D,gBAAI,OAAO;AACT,sBAAQ,aAAa;AAAA,YACvB;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC;AAED,MAAI,QAAQ,YAAY;AACtB,YAAQ,SAAS,KAAK,mBAAmB,SAAS,IAAI,wDAAwD;AAAA,EAChH;AACF,CAAC;","names":[]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createTransformer
|
|
3
|
+
} from "../chunk-JNFQ6J6B.js";
|
|
4
|
+
|
|
5
|
+
// src/codemods/v1/workflow-stream-vnext.ts
|
|
6
|
+
var workflow_stream_vnext_default = createTransformer((fileInfo, api, options, context) => {
|
|
7
|
+
const { j, root } = context;
|
|
8
|
+
const methodRenames = {
|
|
9
|
+
streamVNext: "stream",
|
|
10
|
+
resumeStreamVNext: "resumeStream",
|
|
11
|
+
observeStreamVNext: "observeStream"
|
|
12
|
+
};
|
|
13
|
+
let count = 0;
|
|
14
|
+
root.find(j.CallExpression).forEach((path) => {
|
|
15
|
+
const { callee } = path.value;
|
|
16
|
+
if (callee.type !== "MemberExpression") return;
|
|
17
|
+
if (callee.property.type !== "Identifier") return;
|
|
18
|
+
const oldName = callee.property.name;
|
|
19
|
+
const newName = methodRenames[oldName];
|
|
20
|
+
if (newName) {
|
|
21
|
+
callee.property.name = newName;
|
|
22
|
+
count++;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
if (count > 0) {
|
|
26
|
+
context.hasChanges = true;
|
|
27
|
+
context.messages.push(
|
|
28
|
+
`Renamed workflow run VNext methods: streamVNext/resumeStreamVNext/observeStreamVNext \u2192 stream/resumeStream/observeStream`
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
export {
|
|
33
|
+
workflow_stream_vnext_default as default
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=workflow-stream-vnext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/codemods/v1/workflow-stream-vnext.ts"],"sourcesContent":["import { createTransformer } from '../lib/create-transformer';\n\n/**\n * Transforms workflow run VNext methods to their standard names:\n * - run.streamVNext() → run.stream()\n * - run.resumeStreamVNext() → run.resumeStream()\n * - run.observeStreamVNext() → run.observeStream()\n *\n * These methods are called on the result of workflow.createRun().\n */\nexport default createTransformer((fileInfo, api, options, context) => {\n const { j, root } = context;\n\n // Map of old method names to new method names\n const methodRenames: Record<string, string> = {\n streamVNext: 'stream',\n resumeStreamVNext: 'resumeStream',\n observeStreamVNext: 'observeStream',\n };\n\n let count = 0;\n\n // Find all call expressions and rename VNext methods\n // These method names are unique enough to Mastra workflow runs\n // that we can safely rename them globally\n root.find(j.CallExpression).forEach(path => {\n const { callee } = path.value;\n if (callee.type !== 'MemberExpression') return;\n if (callee.property.type !== 'Identifier') return;\n\n const oldName = callee.property.name;\n const newName = methodRenames[oldName];\n\n if (newName) {\n callee.property.name = newName;\n count++;\n }\n });\n\n if (count > 0) {\n context.hasChanges = true;\n context.messages.push(\n `Renamed workflow run VNext methods: streamVNext/resumeStreamVNext/observeStreamVNext → stream/resumeStream/observeStream`,\n );\n }\n});\n"],"mappings":";;;;;AAUA,IAAO,gCAAQ,kBAAkB,CAAC,UAAU,KAAK,SAAS,YAAY;AACpE,QAAM,EAAE,GAAG,KAAK,IAAI;AAGpB,QAAM,gBAAwC;AAAA,IAC5C,aAAa;AAAA,IACb,mBAAmB;AAAA,IACnB,oBAAoB;AAAA,EACtB;AAEA,MAAI,QAAQ;AAKZ,OAAK,KAAK,EAAE,cAAc,EAAE,QAAQ,UAAQ;AAC1C,UAAM,EAAE,OAAO,IAAI,KAAK;AACxB,QAAI,OAAO,SAAS,mBAAoB;AACxC,QAAI,OAAO,SAAS,SAAS,aAAc;AAE3C,UAAM,UAAU,OAAO,SAAS;AAChC,UAAM,UAAU,cAAc,OAAO;AAErC,QAAI,SAAS;AACX,aAAO,SAAS,OAAO;AACvB;AAAA,IACF;AAAA,EACF,CAAC;AAED,MAAI,QAAQ,GAAG;AACb,YAAQ,aAAa;AACrB,YAAQ,SAAS;AAAA,MACf;AAAA,IACF;AAAA,EACF;AACF,CAAC;","names":[]}
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
2
|
import { Command } from 'commander';
|
|
3
3
|
import debug from 'debug';
|
|
4
|
-
import fs from 'fs';
|
|
5
4
|
import child_process from 'child_process';
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
import path from 'path';
|
|
6
7
|
import { fileURLToPath } from 'url';
|
|
7
8
|
import util from 'util';
|
|
8
|
-
import path from 'path';
|
|
9
9
|
import { intro, spinner, outro } from '@clack/prompts';
|
|
10
10
|
|
|
11
11
|
var exec = util.promisify(child_process.exec);
|
|
@@ -116,6 +116,7 @@ var BUNDLE = [
|
|
|
116
116
|
"v1/workflow-create-run-async",
|
|
117
117
|
"v1/workflow-run-count",
|
|
118
118
|
"v1/workflow-list-runs",
|
|
119
|
+
"v1/workflow-stream-vnext",
|
|
119
120
|
"v1/memory-query-to-recall",
|
|
120
121
|
"v1/memory-vector-search-param",
|
|
121
122
|
"v1/memory-message-v2-type",
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":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AAA,KAAW;AACvB,EAAA,IAAI;AACF,IAAA,MAAM,UAAU,OAAO,CAAA;AAAA,EACzB,SAAS,GAAA,EAAU;AACjB,IAAAA,MAAAA,CAAM,CAAA,oBAAA,EAAuB,GAAG,CAAA,CAAE,CAAA;AAClC,IAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,EAChB;AACF,CAAC,CAAA;AAEH,OAAA,CAAQ,KAAA,CAAM,QAAQ,IAAI,CAAA","file":"index.js","sourcesContent":["import fs from 'fs';\nimport child_process from 'node:child_process';\nimport { fileURLToPath } from 'node:url';\nimport util from 'node:util';\nimport path from 'path';\nimport debug from 'debug';\n\nconst exec = util.promisify(child_process.exec);\n\ninterface TransformOptions {\n dry?: boolean;\n print?: boolean;\n verbose?: boolean;\n jscodeshift?: string;\n}\n\nconst log = debug('codemod:transform');\nconst error = debug('codemod:transform:error');\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\n\nfunction getJscodeshift(): string {\n const localJscodeshift = path.resolve(__dirname, '../node_modules/.bin/jscodeshift');\n return fs.existsSync(localJscodeshift) ? localJscodeshift : 'jscodeshift';\n}\n\nfunction buildCommand(codemodPath: string, targetPath: string, jscodeshift: string, options: TransformOptions): string {\n // Ignoring everything under `.*/` covers `.mastra/` along with any other\n // framework build related or otherwise intended-to-be-hidden directories.\n let command = `${jscodeshift} -t ${codemodPath} ${targetPath} \\\n --parser tsx \\\n --ignore-pattern=\"**/node_modules/**\" \\\n --ignore-pattern=\"**/.*/**\" \\\n --ignore-pattern=\"**/dist/**\" \\\n --ignore-pattern=\"**/build/**\" \\\n --ignore-pattern=\"**/*.min.js\" \\\n --ignore-pattern=\"**/*.bundle.js\"`;\n\n if (options.dry) {\n command += ' --dry';\n }\n\n if (options.print) {\n command += ' --print';\n }\n\n if (options.verbose) {\n command += ' --verbose';\n }\n\n if (options.jscodeshift) {\n command += ` ${options.jscodeshift}`;\n }\n\n return command;\n}\n\nexport type TransformErrors = {\n transform: string;\n filename: string;\n summary: string;\n}[];\n\nfunction parseErrors(transform: string, output: string): TransformErrors {\n const errors: TransformErrors = [];\n const errorRegex = /ERR (.+) Transformation error/g;\n const syntaxErrorRegex = /SyntaxError: .+/g;\n\n let match;\n while ((match = errorRegex.exec(output)) !== null) {\n const filename = match[1]!;\n const syntaxErrorMatch = syntaxErrorRegex.exec(output);\n if (syntaxErrorMatch) {\n const summary = syntaxErrorMatch[0];\n errors.push({ transform, filename, summary });\n }\n }\n\n return errors;\n}\n\nfunction parseNotImplementedErrors(transform: string, output: string): TransformErrors {\n const notImplementedErrors: TransformErrors = [];\n const notImplementedRegex = /Not Implemented (.+): (.+)/g;\n\n let match;\n while ((match = notImplementedRegex.exec(output)) !== null) {\n const filename = match[1]!;\n const summary = match[2]!;\n notImplementedErrors.push({ transform, filename, summary });\n }\n\n return notImplementedErrors;\n}\n\nexport async function transform(\n codemod: string,\n source: string,\n transformOptions: TransformOptions,\n options: { logStatus: boolean } = { logStatus: true },\n): Promise<{ errors: TransformErrors; notImplementedErrors: TransformErrors }> {\n if (options.logStatus) {\n log(`Applying codemod '${codemod}': ${source}`);\n }\n const codemodPath = path.resolve(__dirname, `./codemods/${codemod}.js`);\n const targetPath = path.resolve(source);\n const jscodeshift = getJscodeshift();\n const command = buildCommand(codemodPath, targetPath, jscodeshift, transformOptions);\n const { stdout } = await exec(command, { encoding: 'utf8' });\n const errors = parseErrors(codemod, stdout);\n const notImplementedErrors = parseNotImplementedErrors(codemod, stdout);\n if (options.logStatus) {\n if (errors.length > 0) {\n errors.forEach(({ transform, filename, summary }) => {\n error(`Error applying codemod [codemod=${transform}, path=${filename}, summary=${summary}]`);\n });\n }\n\n if (notImplementedErrors.length > 0) {\n log(\n `Some files require manual changes. Please search your codebase for \\`FIXME(mastra): \\` comments and follow the instructions to complete the upgrade.`,\n );\n notImplementedErrors.forEach(({ transform, filename, summary }) => {\n log(`Not Implemented [codemod=${transform}, path=${filename}, summary=${summary}]`);\n });\n }\n }\n\n return { errors, notImplementedErrors };\n}\n","// List of all codemods\nexport const BUNDLE = [\n 'v1/mastra-core-imports',\n 'v1/runtime-context',\n 'v1/not-implemented/mastra-memory',\n 'v1/mastra-plural-apis',\n 'v1/not-implemented/mastra-required-id',\n 'v1/agent-property-access',\n 'v1/agent-voice',\n 'v1/agent-processor-methods',\n 'v1/agent-generate-stream-v-next',\n 'v1/agent-abort-signal',\n 'v1/not-implemented/agent-format-parameter',\n 'v1/not-implemented/agent-to-step',\n 'v1/voice-property-names',\n 'v1/mcp-get-tools',\n 'v1/mcp-get-toolsets',\n 'v1/client-sdk-types',\n 'v1/client-to-ai-sdk-format',\n 'v1/client-offset-limit',\n 'v1/client-get-memory-thread',\n 'v1/experimental-auth',\n 'v1/evals-run-experiment',\n 'v1/evals-scorer-by-name',\n 'v1/evals-prebuilt-imports',\n 'v1/workflow-create-run-async',\n 'v1/workflow-run-count',\n 'v1/workflow-list-runs',\n 'v1/memory-query-to-recall',\n 'v1/memory-vector-search-param',\n 'v1/memory-message-v2-type',\n 'v1/storage-get-threads-by-resource',\n 'v1/storage-list-messages-by-id',\n 'v1/storage-postgres-schema-name',\n 'v1/storage-get-messages-paginated',\n 'v1/storage-list-workflow-runs',\n 'v1/vector-pg-constructor',\n];\n","import { spinner, intro, outro } from '@clack/prompts';\nimport debug from 'debug';\nimport { BUNDLE } from './bundle';\nimport type { TransformErrors } from './transform';\nimport { transform } from './transform';\n\ninterface TransformOptions {\n dry?: true;\n print?: true;\n verbose?: true;\n jscodeshift?: string;\n}\n\nconst log = debug('codemod:upgrade');\nconst error = debug('codemod:upgrade:error');\n\n// Extract v1 codemods from the bundle\nconst v1Bundle = BUNDLE.filter(codemod => codemod.startsWith('v1/'));\n\nasync function runCodemods(codemods: string[], options: TransformOptions, versionLabel: string) {\n const cwd = process.cwd();\n intro(`Starting ${versionLabel} codemods`);\n const modCount = codemods.length;\n const s = spinner();\n\n s.start(`Running ${modCount} ${versionLabel} codemods`);\n\n const allErrors: TransformErrors = [];\n let notImplementedAvailable = false;\n let count = 0;\n for (const [_, codemod] of codemods.entries()) {\n const { errors, notImplementedErrors } = await transform(codemod, cwd, options, {\n logStatus: false,\n });\n allErrors.push(...errors);\n if (notImplementedErrors.length > 0) {\n notImplementedAvailable = true;\n }\n count++;\n s.message(`Codemod ${count}/${modCount} (${codemod})`);\n }\n s.stop(`Ran ${count}/${modCount} codemods.`);\n\n if (allErrors.length > 0) {\n log(`Some ${versionLabel} codemods did not apply successfully to all files. Details:`);\n allErrors.forEach(({ transform, filename, summary }) => {\n error(`codemod=${transform}, path=${filename}, summary=${summary}`);\n });\n }\n\n if (notImplementedAvailable) {\n log(\n `Some ${versionLabel} codemods require manual changes. Please search your codebase for \\`FIXME(mastra): \\` comments and follow the instructions to complete the upgrade.`,\n );\n }\n\n outro(`${versionLabel} codemods complete.`);\n}\n\nexport async function upgradeV1(options: TransformOptions) {\n await runCodemods(v1Bundle, options, 'v1');\n}\n","#! /usr/bin/env node\n\nimport { Command } from 'commander';\nimport debug from 'debug';\nimport { transform } from './lib/transform';\nimport { upgradeV1 } from './lib/upgrade';\n\nconst error = debug('codemod:error');\ndebug.enable('codemod:*');\n\nconst program = new Command();\n\nprogram\n .name('codemod')\n .description('CLI for running Mastra codemods')\n .argument('<codemod>', 'Codemod to run')\n .argument('<source>', 'Path to source files or directory')\n .option('-d, --dry', 'Dry run (no changes are made to files)')\n .option('-p, --print', 'Print transformed files to stdout')\n .option('--verbose', 'Show more information about the transform process')\n .option('-j, --jscodeshift <options>', 'Pass options directly to jscodeshift')\n .action(async (codemod, source, options) => {\n try {\n await transform(codemod, source, options);\n } catch (err: any) {\n error(`Error transforming: ${err}`);\n process.exit(1);\n }\n });\n\nprogram\n .command('v1')\n .description('Apply all v1 codemods (v0.x to v1)')\n .option('-d, --dry', 'Dry run (no changes are made to files)')\n .option('-p, --print', 'Print transformed files to stdout')\n .option('--verbose', 'Show more information about the transform process')\n .option('-j, --jscodeshift <options>', 'Pass options directly to jscodeshift')\n .action(async options => {\n try {\n await upgradeV1(options);\n } catch (err: any) {\n error(`Error transforming: ${err}`);\n process.exit(1);\n }\n });\n\nprogram.parse(process.argv);\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/lib/transform.ts","../src/lib/bundle.ts","../src/lib/upgrade.ts","../src/index.ts"],"names":["transform","log","debug","error"],"mappings":";;;;;;;;;;AAOA,IAAM,IAAA,GAAO,IAAA,CAAK,SAAA,CAAU,aAAA,CAAc,IAAI,CAAA;AAS9C,IAAM,GAAA,GAAM,MAAM,mBAAmB,CAAA;AACrC,IAAM,KAAA,GAAQ,MAAM,yBAAyB,CAAA;AAC7C,IAAM,UAAA,GAAa,aAAA,CAAc,MAAA,CAAA,IAAA,CAAY,GAAG,CAAA;AAChD,IAAM,SAAA,GAAY,IAAA,CAAK,OAAA,CAAQ,UAAU,CAAA;AAEzC,SAAS,cAAA,GAAyB;AAChC,EAAA,MAAM,gBAAA,GAAmB,IAAA,CAAK,OAAA,CAAQ,SAAA,EAAW,kCAAkC,CAAA;AACnF,EAAA,OAAO,EAAA,CAAG,UAAA,CAAW,gBAAgB,CAAA,GAAI,gBAAA,GAAmB,aAAA;AAC9D;AAEA,SAAS,YAAA,CAAa,WAAA,EAAqB,UAAA,EAAoB,WAAA,EAAqB,OAAA,EAAmC;AAGrH,EAAA,IAAI,UAAU,CAAA,EAAG,WAAW,CAAA,IAAA,EAAO,WAAW,IAAI,UAAU,CAAA,yOAAA,CAAA;AAS5D,EAAA,IAAI,QAAQ,GAAA,EAAK;AACf,IAAA,OAAA,IAAW,QAAA;AAAA,EACb;AAEA,EAAA,IAAI,QAAQ,KAAA,EAAO;AACjB,IAAA,OAAA,IAAW,UAAA;AAAA,EACb;AAEA,EAAA,IAAI,QAAQ,OAAA,EAAS;AACnB,IAAA,OAAA,IAAW,YAAA;AAAA,EACb;AAEA,EAAA,IAAI,QAAQ,WAAA,EAAa;AACvB,IAAA,OAAA,IAAW,CAAA,CAAA,EAAI,QAAQ,WAAW,CAAA,C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,CAAO,aAAA,EAAe,mCAAmC,CAAA,CACzD,MAAA,CAAO,WAAA,EAAa,mDAAmD,CAAA,CACvE,MAAA,CAAO,+BAA+B,sCAAsC,CAAA,CAC5E,MAAA,CAAO,OAAM,OAAA,KAAW;AACvB,EAAA,IAAI;AACF,IAAA,MAAM,UAAU,OAAO,CAAA;AAAA,EACzB,SAAS,GAAA,EAAU;AACjB,IAAAA,MAAAA,CAAM,CAAA,oBAAA,EAAuB,GAAG,CAAA,CAAE,CAAA;AAClC,IAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,EAChB;AACF,CAAC,CAAA;AAEH,OAAA,CAAQ,KAAA,CAAM,QAAQ,IAAI,CAAA","file":"index.js","sourcesContent":["import child_process from 'node:child_process';\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport util from 'node:util';\nimport debug from 'debug';\n\nconst exec = util.promisify(child_process.exec);\n\ninterface TransformOptions {\n dry?: boolean;\n print?: boolean;\n verbose?: boolean;\n jscodeshift?: string;\n}\n\nconst log = debug('codemod:transform');\nconst error = debug('codemod:transform:error');\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\n\nfunction getJscodeshift(): string {\n const localJscodeshift = path.resolve(__dirname, '../node_modules/.bin/jscodeshift');\n return fs.existsSync(localJscodeshift) ? localJscodeshift : 'jscodeshift';\n}\n\nfunction buildCommand(codemodPath: string, targetPath: string, jscodeshift: string, options: TransformOptions): string {\n // Ignoring everything under `.*/` covers `.mastra/` along with any other\n // framework build related or otherwise intended-to-be-hidden directories.\n let command = `${jscodeshift} -t ${codemodPath} ${targetPath} \\\n --parser tsx \\\n --ignore-pattern=\"**/node_modules/**\" \\\n --ignore-pattern=\"**/.*/**\" \\\n --ignore-pattern=\"**/dist/**\" \\\n --ignore-pattern=\"**/build/**\" \\\n --ignore-pattern=\"**/*.min.js\" \\\n --ignore-pattern=\"**/*.bundle.js\"`;\n\n if (options.dry) {\n command += ' --dry';\n }\n\n if (options.print) {\n command += ' --print';\n }\n\n if (options.verbose) {\n command += ' --verbose';\n }\n\n if (options.jscodeshift) {\n command += ` ${options.jscodeshift}`;\n }\n\n return command;\n}\n\nexport type TransformErrors = {\n transform: string;\n filename: string;\n summary: string;\n}[];\n\nfunction parseErrors(transform: string, output: string): TransformErrors {\n const errors: TransformErrors = [];\n const errorRegex = /ERR (.+) Transformation error/g;\n const syntaxErrorRegex = /SyntaxError: .+/g;\n\n let match;\n while ((match = errorRegex.exec(output)) !== null) {\n const filename = match[1]!;\n const syntaxErrorMatch = syntaxErrorRegex.exec(output);\n if (syntaxErrorMatch) {\n const summary = syntaxErrorMatch[0];\n errors.push({ transform, filename, summary });\n }\n }\n\n return errors;\n}\n\nfunction parseNotImplementedErrors(transform: string, output: string): TransformErrors {\n const notImplementedErrors: TransformErrors = [];\n const notImplementedRegex = /Not Implemented (.+): (.+)/g;\n\n let match;\n while ((match = notImplementedRegex.exec(output)) !== null) {\n const filename = match[1]!;\n const summary = match[2]!;\n notImplementedErrors.push({ transform, filename, summary });\n }\n\n return notImplementedErrors;\n}\n\nexport async function transform(\n codemod: string,\n source: string,\n transformOptions: TransformOptions,\n options: { logStatus: boolean } = { logStatus: true },\n): Promise<{ errors: TransformErrors; notImplementedErrors: TransformErrors }> {\n if (options.logStatus) {\n log(`Applying codemod '${codemod}': ${source}`);\n }\n const codemodPath = path.resolve(__dirname, `./codemods/${codemod}.js`);\n const targetPath = path.resolve(source);\n const jscodeshift = getJscodeshift();\n const command = buildCommand(codemodPath, targetPath, jscodeshift, transformOptions);\n const { stdout } = await exec(command, { encoding: 'utf8' });\n const errors = parseErrors(codemod, stdout);\n const notImplementedErrors = parseNotImplementedErrors(codemod, stdout);\n if (options.logStatus) {\n if (errors.length > 0) {\n errors.forEach(({ transform, filename, summary }) => {\n error(`Error applying codemod [codemod=${transform}, path=${filename}, summary=${summary}]`);\n });\n }\n\n if (notImplementedErrors.length > 0) {\n log(\n `Some files require manual changes. Please search your codebase for \\`FIXME(mastra): \\` comments and follow the instructions to complete the upgrade.`,\n );\n notImplementedErrors.forEach(({ transform, filename, summary }) => {\n log(`Not Implemented [codemod=${transform}, path=${filename}, summary=${summary}]`);\n });\n }\n }\n\n return { errors, notImplementedErrors };\n}\n","// List of all codemods\nexport const BUNDLE = [\n 'v1/mastra-core-imports',\n 'v1/runtime-context',\n 'v1/not-implemented/mastra-memory',\n 'v1/mastra-plural-apis',\n 'v1/not-implemented/mastra-required-id',\n 'v1/agent-property-access',\n 'v1/agent-voice',\n 'v1/agent-processor-methods',\n 'v1/agent-generate-stream-v-next',\n 'v1/agent-abort-signal',\n 'v1/not-implemented/agent-format-parameter',\n 'v1/not-implemented/agent-to-step',\n 'v1/voice-property-names',\n 'v1/mcp-get-tools',\n 'v1/mcp-get-toolsets',\n 'v1/client-sdk-types',\n 'v1/client-to-ai-sdk-format',\n 'v1/client-offset-limit',\n 'v1/client-get-memory-thread',\n 'v1/experimental-auth',\n 'v1/evals-run-experiment',\n 'v1/evals-scorer-by-name',\n 'v1/evals-prebuilt-imports',\n 'v1/workflow-create-run-async',\n 'v1/workflow-run-count',\n 'v1/workflow-list-runs',\n 'v1/workflow-stream-vnext',\n 'v1/memory-query-to-recall',\n 'v1/memory-vector-search-param',\n 'v1/memory-message-v2-type',\n 'v1/storage-get-threads-by-resource',\n 'v1/storage-list-messages-by-id',\n 'v1/storage-postgres-schema-name',\n 'v1/storage-get-messages-paginated',\n 'v1/storage-list-workflow-runs',\n 'v1/vector-pg-constructor',\n];\n","import { spinner, intro, outro } from '@clack/prompts';\nimport debug from 'debug';\nimport { BUNDLE } from './bundle';\nimport type { TransformErrors } from './transform';\nimport { transform } from './transform';\n\ninterface TransformOptions {\n dry?: true;\n print?: true;\n verbose?: true;\n jscodeshift?: string;\n}\n\nconst log = debug('codemod:upgrade');\nconst error = debug('codemod:upgrade:error');\n\n// Extract v1 codemods from the bundle\nconst v1Bundle = BUNDLE.filter(codemod => codemod.startsWith('v1/'));\n\nasync function runCodemods(codemods: string[], options: TransformOptions, versionLabel: string) {\n const cwd = process.cwd();\n intro(`Starting ${versionLabel} codemods`);\n const modCount = codemods.length;\n const s = spinner();\n\n s.start(`Running ${modCount} ${versionLabel} codemods`);\n\n const allErrors: TransformErrors = [];\n let notImplementedAvailable = false;\n let count = 0;\n for (const [_, codemod] of codemods.entries()) {\n const { errors, notImplementedErrors } = await transform(codemod, cwd, options, {\n logStatus: false,\n });\n allErrors.push(...errors);\n if (notImplementedErrors.length > 0) {\n notImplementedAvailable = true;\n }\n count++;\n s.message(`Codemod ${count}/${modCount} (${codemod})`);\n }\n s.stop(`Ran ${count}/${modCount} codemods.`);\n\n if (allErrors.length > 0) {\n log(`Some ${versionLabel} codemods did not apply successfully to all files. Details:`);\n allErrors.forEach(({ transform, filename, summary }) => {\n error(`codemod=${transform}, path=${filename}, summary=${summary}`);\n });\n }\n\n if (notImplementedAvailable) {\n log(\n `Some ${versionLabel} codemods require manual changes. Please search your codebase for \\`FIXME(mastra): \\` comments and follow the instructions to complete the upgrade.`,\n );\n }\n\n outro(`${versionLabel} codemods complete.`);\n}\n\nexport async function upgradeV1(options: TransformOptions) {\n await runCodemods(v1Bundle, options, 'v1');\n}\n","#! /usr/bin/env node\n\nimport { Command } from 'commander';\nimport debug from 'debug';\nimport { transform } from './lib/transform';\nimport { upgradeV1 } from './lib/upgrade';\n\nconst error = debug('codemod:error');\ndebug.enable('codemod:*');\n\nconst program = new Command();\n\nprogram\n .name('codemod')\n .description('CLI for running Mastra codemods')\n .argument('<codemod>', 'Codemod to run')\n .argument('<source>', 'Path to source files or directory')\n .option('-d, --dry', 'Dry run (no changes are made to files)')\n .option('-p, --print', 'Print transformed files to stdout')\n .option('--verbose', 'Show more information about the transform process')\n .option('-j, --jscodeshift <options>', 'Pass options directly to jscodeshift')\n .action(async (codemod, source, options) => {\n try {\n await transform(codemod, source, options);\n } catch (err: any) {\n error(`Error transforming: ${err}`);\n process.exit(1);\n }\n });\n\nprogram\n .command('v1')\n .description('Apply all v1 codemods (v0.x to v1)')\n .option('-d, --dry', 'Dry run (no changes are made to files)')\n .option('-p, --print', 'Print transformed files to stdout')\n .option('--verbose', 'Show more information about the transform process')\n .option('-j, --jscodeshift <options>', 'Pass options directly to jscodeshift')\n .action(async options => {\n try {\n await upgradeV1(options);\n } catch (err: any) {\n error(`Error transforming: ${err}`);\n process.exit(1);\n }\n });\n\nprogram.parse(process.argv);\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/codemod",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.0-beta.
|
|
4
|
+
"version": "0.1.0-beta.3",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"description": "Codemod CLI for Mastra",
|
|
7
7
|
"bin": {
|
|
@@ -27,11 +27,13 @@
|
|
|
27
27
|
"@commander-js/extra-typings": "^14.0.0",
|
|
28
28
|
"@types/debug": "^4.1.12",
|
|
29
29
|
"@types/jscodeshift": "^17.3.0",
|
|
30
|
-
"@types/node": "
|
|
30
|
+
"@types/node": "22.13.17",
|
|
31
|
+
"@vitest/coverage-v8": "4.0.12",
|
|
32
|
+
"@vitest/ui": "4.0.12",
|
|
31
33
|
"eslint": "^9.37.0",
|
|
32
34
|
"tsup": "^8.5.0",
|
|
33
35
|
"typescript": "^5.8.3",
|
|
34
|
-
"vitest": "
|
|
36
|
+
"vitest": "4.0.12",
|
|
35
37
|
"@internal/lint": "0.0.53"
|
|
36
38
|
},
|
|
37
39
|
"homepage": "https://mastra.ai",
|