@mastra/codemod 0.1.0-beta.7 → 1.0.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/CHANGELOG.md +109 -0
- package/README.md +8 -8
- package/dist/codemods/v1/not-implemented/agent-format-parameter.js +1 -1
- package/dist/codemods/v1/not-implemented/agent-format-parameter.js.map +1 -1
- package/dist/codemods/v1/not-implemented/agent-to-step.js +1 -1
- package/dist/codemods/v1/not-implemented/agent-to-step.js.map +1 -1
- package/dist/codemods/v1/not-implemented/mastra-required-id.js +1 -1
- package/dist/codemods/v1/not-implemented/mastra-required-id.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,114 @@
|
|
|
1
1
|
# @mastra/codemod
|
|
2
2
|
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- Mark as stable ([#12096](https://github.com/mastra-ai/mastra/pull/12096))
|
|
8
|
+
|
|
9
|
+
### Minor Changes
|
|
10
|
+
|
|
11
|
+
- Initial release of `@mastra/codemod` package ([#9579](https://github.com/mastra-ai/mastra/pull/9579))
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Add new `v1/client-msg-function-args` codemod. It transforms MastraClient agent method calls to use messages as the first argument. ([#12061](https://github.com/mastra-ai/mastra/pull/12061))
|
|
16
|
+
|
|
17
|
+
- Fixed a bug where `[native code]` was incorrectly added to the output ([#10971](https://github.com/mastra-ai/mastra/pull/10971))
|
|
18
|
+
|
|
19
|
+
- **Breaking Change:** `memory.readOnly` has been moved to `memory.options.readOnly` ([#11523](https://github.com/mastra-ai/mastra/pull/11523))
|
|
20
|
+
|
|
21
|
+
The `readOnly` option now lives inside `memory.options` alongside other memory configuration like `lastMessages` and `semanticRecall`.
|
|
22
|
+
|
|
23
|
+
**Before:**
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
agent.stream('Hello', {
|
|
27
|
+
memory: {
|
|
28
|
+
thread: threadId,
|
|
29
|
+
resource: resourceId,
|
|
30
|
+
readOnly: true,
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**After:**
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
agent.stream('Hello', {
|
|
39
|
+
memory: {
|
|
40
|
+
thread: threadId,
|
|
41
|
+
resource: resourceId,
|
|
42
|
+
options: {
|
|
43
|
+
readOnly: true,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
**Migration:** Run the codemod to update your code automatically:
|
|
50
|
+
|
|
51
|
+
```shell
|
|
52
|
+
npx @mastra/codemod@beta v1/memory-readonly-to-options .
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
This also fixes issue #11519 where `readOnly: true` was being ignored and messages were saved to memory anyway.
|
|
56
|
+
|
|
57
|
+
- 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))
|
|
58
|
+
|
|
59
|
+
- Remove incorrect codemod ([#11826](https://github.com/mastra-ai/mastra/pull/11826))
|
|
60
|
+
|
|
61
|
+
- 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))
|
|
62
|
+
|
|
63
|
+
- Added new `listThreads` method for flexible thread filtering across all storage adapters. ([#11832](https://github.com/mastra-ai/mastra/pull/11832))
|
|
64
|
+
|
|
65
|
+
**New Features**
|
|
66
|
+
- Filter threads by `resourceId`, `metadata`, or both (with AND logic for metadata key-value pairs)
|
|
67
|
+
- All filter parameters are optional, allowing you to list all threads or filter as needed
|
|
68
|
+
- Full pagination and sorting support
|
|
69
|
+
|
|
70
|
+
**Example Usage**
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
// List all threads
|
|
74
|
+
const allThreads = await memory.listThreads({});
|
|
75
|
+
|
|
76
|
+
// Filter by resourceId only
|
|
77
|
+
const userThreads = await memory.listThreads({
|
|
78
|
+
filter: { resourceId: 'user-123' },
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// Filter by metadata only
|
|
82
|
+
const supportThreads = await memory.listThreads({
|
|
83
|
+
filter: { metadata: { category: 'support' } },
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// Filter by both with pagination
|
|
87
|
+
const filteredThreads = await memory.listThreads({
|
|
88
|
+
filter: {
|
|
89
|
+
resourceId: 'user-123',
|
|
90
|
+
metadata: { priority: 'high', status: 'open' },
|
|
91
|
+
},
|
|
92
|
+
orderBy: { field: 'updatedAt', direction: 'DESC' },
|
|
93
|
+
page: 0,
|
|
94
|
+
perPage: 20,
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
**Security Improvements**
|
|
99
|
+
- Added validation to prevent SQL injection via malicious metadata keys
|
|
100
|
+
- Added pagination parameter validation to prevent integer overflow attacks
|
|
101
|
+
|
|
102
|
+
- - Improve existing codemods ([#9959](https://github.com/mastra-ai/mastra/pull/9959))
|
|
103
|
+
- Make package ESM-only
|
|
104
|
+
- Add new codemods
|
|
105
|
+
|
|
106
|
+
## 1.0.0-beta.8
|
|
107
|
+
|
|
108
|
+
### Major Changes
|
|
109
|
+
|
|
110
|
+
- Mark as stable ([#12096](https://github.com/mastra-ai/mastra/pull/12096))
|
|
111
|
+
|
|
3
112
|
## 0.1.0-beta.7
|
|
4
113
|
|
|
5
114
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ Codemods are transformations that run on your codebase programmatically, allowin
|
|
|
9
9
|
### Run Version-Specific Codemods
|
|
10
10
|
|
|
11
11
|
```sh
|
|
12
|
-
npx @mastra/codemod
|
|
12
|
+
npx @mastra/codemod v1
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
### Run Individual Codemods
|
|
@@ -17,20 +17,20 @@ npx @mastra/codemod@beta v1
|
|
|
17
17
|
To run a specific codemod:
|
|
18
18
|
|
|
19
19
|
```sh
|
|
20
|
-
npx @mastra/codemod
|
|
20
|
+
npx @mastra/codemod <codemod-name> <path>
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
Examples:
|
|
24
24
|
|
|
25
25
|
```sh
|
|
26
26
|
# Transform a specific file
|
|
27
|
-
npx @mastra/codemod
|
|
27
|
+
npx @mastra/codemod v1/mastra-core-imports src/mastra.ts
|
|
28
28
|
|
|
29
29
|
# Transform a directory
|
|
30
|
-
npx @mastra/codemod
|
|
30
|
+
npx @mastra/codemod v1/mastra-core-imports src/lib/
|
|
31
31
|
|
|
32
32
|
# Transform entire project
|
|
33
|
-
npx @mastra/codemod
|
|
33
|
+
npx @mastra/codemod v1/mastra-core-imports .
|
|
34
34
|
```
|
|
35
35
|
|
|
36
36
|
## Available Codemods
|
|
@@ -79,7 +79,7 @@ npx @mastra/codemod@beta v1/mastra-core-imports .
|
|
|
79
79
|
### Commands
|
|
80
80
|
|
|
81
81
|
```sh
|
|
82
|
-
npx @mastra/codemod
|
|
82
|
+
npx @mastra/codemod <command> [options]
|
|
83
83
|
```
|
|
84
84
|
|
|
85
85
|
**Available Commands:**
|
|
@@ -96,10 +96,10 @@ npx @mastra/codemod@beta <command> [options]
|
|
|
96
96
|
|
|
97
97
|
```sh
|
|
98
98
|
# Show verbose output for specific codemod
|
|
99
|
-
npx @mastra/codemod
|
|
99
|
+
npx @mastra/codemod --verbose v1/mastra-core-imports src/
|
|
100
100
|
|
|
101
101
|
# Print transformed code for specific codemod
|
|
102
|
-
npx @mastra/codemod
|
|
102
|
+
npx @mastra/codemod --print v1/mastra-core-imports src/mastra.ts
|
|
103
103
|
```
|
|
104
104
|
|
|
105
105
|
## Contributing
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
// src/codemods/v1/not-implemented/agent-format-parameter.ts
|
|
9
9
|
var agent_format_parameter_default = createTransformer((fileInfo, api, options, context) => {
|
|
10
10
|
const { j, root } = context;
|
|
11
|
-
const COMMENT_MESSAGE = "FIXME(mastra): The format parameter has been removed. See: https://mastra.ai/guides/
|
|
11
|
+
const COMMENT_MESSAGE = "FIXME(mastra): The format parameter has been removed. See: https://mastra.ai/guides/migrations/upgrade-to-v1/agent#format-parameter-from-stream-and-generate";
|
|
12
12
|
const agentInstances = /* @__PURE__ */ new Set();
|
|
13
13
|
root.find(j.NewExpression, {
|
|
14
14
|
callee: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/codemods/v1/not-implemented/agent-format-parameter.ts"],"sourcesContent":["/* eslint-disable no-warning-comments */\nimport { insertCommentOnce } from '../../lib/add-comment';\nimport { createTransformer } from '../../lib/create-transformer';\n\n/**\n * Adds a FIXME comment above the format parameter in agent.generate() and agent.stream() calls.\n * The format parameter has been removed in v1 and requires manual migration.\n *\n * Before:\n * agent.generate('prompt', { format: 'aisdk' })\n *\n * After:\n * agent.generate('prompt', {\n * /* FIXME(mastra): The format parameter has been removed. See: https://mastra.ai/guides/
|
|
1
|
+
{"version":3,"sources":["../../../../src/codemods/v1/not-implemented/agent-format-parameter.ts"],"sourcesContent":["/* eslint-disable no-warning-comments */\nimport { insertCommentOnce } from '../../lib/add-comment';\nimport { createTransformer } from '../../lib/create-transformer';\n\n/**\n * Adds a FIXME comment above the format parameter in agent.generate() and agent.stream() calls.\n * The format parameter has been removed in v1 and requires manual migration.\n *\n * Before:\n * agent.generate('prompt', { format: 'aisdk' })\n *\n * After:\n * agent.generate('prompt', {\n * /* FIXME(mastra): The format parameter has been removed. See: https://mastra.ai/guides/migrations/upgrade-to-v1/agent#format-parameter-from-stream-and-generate *\\/\n * format: 'aisdk'\n * })\n */\nexport default createTransformer((fileInfo, api, options, context) => {\n const { j, root } = context;\n\n const COMMENT_MESSAGE =\n 'FIXME(mastra): The format parameter has been removed. See: https://mastra.ai/guides/migrations/upgrade-to-v1/agent#format-parameter-from-stream-and-generate';\n\n // Track Agent instances\n const agentInstances = new Set<string>();\n\n root\n .find(j.NewExpression, {\n callee: {\n type: 'Identifier',\n name: 'Agent',\n },\n })\n .forEach(path => {\n const parent = path.parent.value;\n if (parent.type === 'VariableDeclarator' && parent.id.type === 'Identifier') {\n agentInstances.add(parent.id.name);\n }\n });\n\n // Find agent.generate() and agent.stream() calls\n root\n .find(j.CallExpression)\n .filter(path => {\n const { callee } = path.value;\n if (callee.type !== 'MemberExpression') return false;\n if (callee.object.type !== 'Identifier') return false;\n if (callee.property.type !== 'Identifier') return false;\n\n // Only process if called on an Agent instance\n if (!agentInstances.has(callee.object.name)) return false;\n\n // Only process generate() and stream() methods\n return callee.property.name === 'generate' || callee.property.name === 'stream';\n })\n .forEach(path => {\n const args = path.value.arguments;\n\n // We're looking for calls with an options object that has format parameter\n if (args.length < 2) return;\n\n const optionsArg = args[1];\n if (!optionsArg || optionsArg.type !== 'ObjectExpression') return;\n if (!optionsArg.properties) return;\n\n // Find the format property\n optionsArg.properties.forEach(prop => {\n if (\n (prop.type === 'Property' || prop.type === 'ObjectProperty') &&\n prop.key?.type === 'Identifier' &&\n prop.key.name === 'format'\n ) {\n // Add FIXME comment to the format property\n const added = insertCommentOnce(prop, j, COMMENT_MESSAGE);\n if (added) {\n context.hasChanges = true;\n }\n }\n });\n });\n\n if (context.hasChanges) {\n context.messages.push(`Not Implemented ${fileInfo.path}: The format 'aisdk' parameter has been removed.`);\n }\n});\n"],"mappings":";;;;;;;;AAiBA,IAAO,iCAAQ,kBAAkB,CAAC,UAAU,KAAK,SAAS,YAAY;AACpE,QAAM,EAAE,GAAG,KAAK,IAAI;AAEpB,QAAM,kBACJ;AAGF,QAAM,iBAAiB,oBAAI,IAAY;AAEvC,OACG,KAAK,EAAE,eAAe;AAAA,IACrB,QAAQ;AAAA,MACN,MAAM;AAAA,MACN,MAAM;AAAA,IACR;AAAA,EACF,CAAC,EACA,QAAQ,UAAQ;AACf,UAAM,SAAS,KAAK,OAAO;AAC3B,QAAI,OAAO,SAAS,wBAAwB,OAAO,GAAG,SAAS,cAAc;AAC3E,qBAAe,IAAI,OAAO,GAAG,IAAI;AAAA,IACnC;AAAA,EACF,CAAC;AAGH,OACG,KAAK,EAAE,cAAc,EACrB,OAAO,UAAQ;AACd,UAAM,EAAE,OAAO,IAAI,KAAK;AACxB,QAAI,OAAO,SAAS,mBAAoB,QAAO;AAC/C,QAAI,OAAO,OAAO,SAAS,aAAc,QAAO;AAChD,QAAI,OAAO,SAAS,SAAS,aAAc,QAAO;AAGlD,QAAI,CAAC,eAAe,IAAI,OAAO,OAAO,IAAI,EAAG,QAAO;AAGpD,WAAO,OAAO,SAAS,SAAS,cAAc,OAAO,SAAS,SAAS;AAAA,EACzE,CAAC,EACA,QAAQ,UAAQ;AACf,UAAM,OAAO,KAAK,MAAM;AAGxB,QAAI,KAAK,SAAS,EAAG;AAErB,UAAM,aAAa,KAAK,CAAC;AACzB,QAAI,CAAC,cAAc,WAAW,SAAS,mBAAoB;AAC3D,QAAI,CAAC,WAAW,WAAY;AAG5B,eAAW,WAAW,QAAQ,UAAQ;AACpC,WACG,KAAK,SAAS,cAAc,KAAK,SAAS,qBAC3C,KAAK,KAAK,SAAS,gBACnB,KAAK,IAAI,SAAS,UAClB;AAEA,cAAM,QAAQ,kBAAkB,MAAM,GAAG,eAAe;AACxD,YAAI,OAAO;AACT,kBAAQ,aAAa;AAAA,QACvB;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AAEH,MAAI,QAAQ,YAAY;AACtB,YAAQ,SAAS,KAAK,mBAAmB,SAAS,IAAI,kDAAkD;AAAA,EAC1G;AACF,CAAC;","names":[]}
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
// src/codemods/v1/not-implemented/agent-to-step.ts
|
|
9
9
|
var agent_to_step_default = createTransformer((fileInfo, api, options, context) => {
|
|
10
10
|
const { j, root } = context;
|
|
11
|
-
const COMMENT_MESSAGE = "FIXME(mastra): The toStep() method has been removed. See: https://mastra.ai/guides/
|
|
11
|
+
const COMMENT_MESSAGE = "FIXME(mastra): The toStep() method has been removed. See: https://mastra.ai/guides/migrations/upgrade-to-v1/agent#agenttostep-method";
|
|
12
12
|
const agentInstances = /* @__PURE__ */ new Set();
|
|
13
13
|
root.find(j.NewExpression, {
|
|
14
14
|
callee: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/codemods/v1/not-implemented/agent-to-step.ts"],"sourcesContent":["/* eslint-disable no-warning-comments */\nimport { insertCommentOnce } from '../../lib/add-comment';\nimport { createTransformer } from '../../lib/create-transformer';\n\n/**\n * Adds a FIXME comment above agent.toStep() method calls.\n * The toStep() method has been removed in v1 and requires manual migration.\n *\n * Before:\n * const step = agent.toStep();\n *\n * After:\n * /* FIXME(mastra): The toStep() method has been removed. See: https://mastra.ai/guides/
|
|
1
|
+
{"version":3,"sources":["../../../../src/codemods/v1/not-implemented/agent-to-step.ts"],"sourcesContent":["/* eslint-disable no-warning-comments */\nimport { insertCommentOnce } from '../../lib/add-comment';\nimport { createTransformer } from '../../lib/create-transformer';\n\n/**\n * Adds a FIXME comment above agent.toStep() method calls.\n * The toStep() method has been removed in v1 and requires manual migration.\n *\n * Before:\n * const step = agent.toStep();\n *\n * After:\n * /* FIXME(mastra): The toStep() method has been removed. See: https://mastra.ai/guides/migrations/upgrade-to-v1/agent#agenttostep-method *\\/\n * const step = agent.toStep();\n */\nexport default createTransformer((fileInfo, api, options, context) => {\n const { j, root } = context;\n\n const COMMENT_MESSAGE =\n 'FIXME(mastra): The toStep() method has been removed. See: https://mastra.ai/guides/migrations/upgrade-to-v1/agent#agenttostep-method';\n\n // Track Agent instances\n const agentInstances = new Set<string>();\n\n root\n .find(j.NewExpression, {\n callee: {\n type: 'Identifier',\n name: 'Agent',\n },\n })\n .forEach(path => {\n const parent = path.parent.value;\n if (parent.type === 'VariableDeclarator' && parent.id.type === 'Identifier') {\n agentInstances.add(parent.id.name);\n }\n });\n\n // Find agent.toStep() calls\n root\n .find(j.CallExpression)\n .filter(path => {\n const { callee } = path.value;\n if (callee.type !== 'MemberExpression') return false;\n if (callee.object.type !== 'Identifier') return false;\n if (callee.property.type !== 'Identifier') return false;\n\n // Only process if called on an Agent instance\n if (!agentInstances.has(callee.object.name)) return false;\n\n // Only process toStep() method\n return callee.property.name === 'toStep';\n })\n .forEach(path => {\n // Find the parent statement to add the comment to\n let parent = path.parent;\n while (parent && parent.value.type !== 'VariableDeclaration' && parent.value.type !== 'ExpressionStatement') {\n parent = parent.parent;\n }\n\n if (parent && parent.value) {\n // Check if this statement is wrapped in an export declaration\n let targetNode = parent.value;\n if (parent.parent && parent.parent.value.type === 'ExportNamedDeclaration') {\n targetNode = parent.parent.value;\n }\n\n // Add FIXME comment to the statement (or export if it's exported)\n const added = insertCommentOnce(targetNode, j, COMMENT_MESSAGE);\n if (added) {\n context.hasChanges = true;\n }\n }\n });\n\n if (context.hasChanges) {\n context.messages.push(`Not Implemented ${fileInfo.path}: The toStep() method has been removed.`);\n }\n});\n"],"mappings":";;;;;;;;AAeA,IAAO,wBAAQ,kBAAkB,CAAC,UAAU,KAAK,SAAS,YAAY;AACpE,QAAM,EAAE,GAAG,KAAK,IAAI;AAEpB,QAAM,kBACJ;AAGF,QAAM,iBAAiB,oBAAI,IAAY;AAEvC,OACG,KAAK,EAAE,eAAe;AAAA,IACrB,QAAQ;AAAA,MACN,MAAM;AAAA,MACN,MAAM;AAAA,IACR;AAAA,EACF,CAAC,EACA,QAAQ,UAAQ;AACf,UAAM,SAAS,KAAK,OAAO;AAC3B,QAAI,OAAO,SAAS,wBAAwB,OAAO,GAAG,SAAS,cAAc;AAC3E,qBAAe,IAAI,OAAO,GAAG,IAAI;AAAA,IACnC;AAAA,EACF,CAAC;AAGH,OACG,KAAK,EAAE,cAAc,EACrB,OAAO,UAAQ;AACd,UAAM,EAAE,OAAO,IAAI,KAAK;AACxB,QAAI,OAAO,SAAS,mBAAoB,QAAO;AAC/C,QAAI,OAAO,OAAO,SAAS,aAAc,QAAO;AAChD,QAAI,OAAO,SAAS,SAAS,aAAc,QAAO;AAGlD,QAAI,CAAC,eAAe,IAAI,OAAO,OAAO,IAAI,EAAG,QAAO;AAGpD,WAAO,OAAO,SAAS,SAAS;AAAA,EAClC,CAAC,EACA,QAAQ,UAAQ;AAEf,QAAI,SAAS,KAAK;AAClB,WAAO,UAAU,OAAO,MAAM,SAAS,yBAAyB,OAAO,MAAM,SAAS,uBAAuB;AAC3G,eAAS,OAAO;AAAA,IAClB;AAEA,QAAI,UAAU,OAAO,OAAO;AAE1B,UAAI,aAAa,OAAO;AACxB,UAAI,OAAO,UAAU,OAAO,OAAO,MAAM,SAAS,0BAA0B;AAC1E,qBAAa,OAAO,OAAO;AAAA,MAC7B;AAGA,YAAM,QAAQ,kBAAkB,YAAY,GAAG,eAAe;AAC9D,UAAI,OAAO;AACT,gBAAQ,aAAa;AAAA,MACvB;AAAA,IACF;AAAA,EACF,CAAC;AAEH,MAAI,QAAQ,YAAY;AACtB,YAAQ,SAAS,KAAK,mBAAmB,SAAS,IAAI,yCAAyC;AAAA,EACjG;AACF,CAAC;","names":[]}
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
// src/codemods/v1/not-implemented/mastra-required-id.ts
|
|
9
9
|
var mastra_required_id_default = createTransformer((fileInfo, api, options, context) => {
|
|
10
10
|
const { j, root } = context;
|
|
11
|
-
const COMMENT_MESSAGE = "FIXME(mastra): Add a unique `id` parameter. See: https://mastra.ai/guides/
|
|
11
|
+
const COMMENT_MESSAGE = "FIXME(mastra): Add a unique `id` parameter. See: https://mastra.ai/guides/migrations/upgrade-to-v1/mastra#required-id-parameter-for-all-mastra-primitives";
|
|
12
12
|
const STATEMENT_TYPES = /* @__PURE__ */ new Set([
|
|
13
13
|
"VariableDeclaration",
|
|
14
14
|
"ExpressionStatement",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/codemods/v1/not-implemented/mastra-required-id.ts"],"sourcesContent":["/* eslint-disable no-warning-comments */\nimport type { ASTPath } from 'jscodeshift';\n\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/
|
|
1
|
+
{"version":3,"sources":["../../../../src/codemods/v1/not-implemented/mastra-required-id.ts"],"sourcesContent":["/* eslint-disable no-warning-comments */\nimport type { ASTPath } from 'jscodeshift';\n\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/migrations/upgrade-to-v1/mastra#required-id-parameter-for-all-mastra-primitives';\n\n const STATEMENT_TYPES = new Set([\n 'VariableDeclaration',\n 'ExpressionStatement',\n 'ReturnStatement',\n 'ExportDefaultDeclaration',\n 'ExportNamedDeclaration',\n 'Program',\n ]);\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 /**\n * Checks if an expression's arguments contain an object with an 'id' property\n */\n function hasIdProperty(args: ASTPath<any>['value']['arguments']): boolean {\n return args.some((arg: ASTPath<any>['value']) => {\n if (arg.type === 'ObjectExpression') {\n return arg.properties?.some(\n (prop: ASTPath<any>['value']) =>\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\n /**\n * Adds a FIXME comment to the appropriate node based on the expression's context.\n * - If nested in an object property, adds comment to the property\n * - If nested in an array, adds comment to the expression itself\n * - Otherwise, walks up to find the parent statement and adds comment there\n */\n function addCommentToAppropriateNode(path: ASTPath<any>): void {\n let parent = path.parent;\n\n // If the direct parent is an object property, add comment to that property\n if (parent?.value && (parent.value.type === 'Property' || parent.value.type === 'ObjectProperty')) {\n if (insertCommentOnce(parent.value, j, COMMENT_MESSAGE)) {\n context.hasChanges = true;\n }\n return;\n }\n\n // If the parent is an array, add comment directly to the expression\n if (parent?.value?.type === 'ArrayExpression') {\n if (insertCommentOnce(path.value, j, COMMENT_MESSAGE)) {\n context.hasChanges = true;\n }\n return;\n }\n\n // Find the parent statement to add comment\n while (parent && !STATEMENT_TYPES.has(parent.value.type)) {\n parent = parent.parent;\n }\n\n if (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 if (insertCommentOnce(targetNode, j, COMMENT_MESSAGE)) {\n context.hasChanges = true;\n }\n }\n }\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) && !hasIdProperty(path.value.arguments)) {\n addCommentToAppropriateNode(path);\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) && !hasIdProperty(path.value.arguments)) {\n addCommentToAppropriateNode(path);\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":";;;;;;;;AAoBA,IAAO,6BAAQ,kBAAkB,CAAC,UAAU,KAAK,SAAS,YAAY;AACpE,QAAM,EAAE,GAAG,KAAK,IAAI;AAEpB,QAAM,kBACJ;AAEF,QAAM,kBAAkB,oBAAI,IAAI;AAAA,IAC9B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAGD,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;AAKvE,WAAS,cAAc,MAAmD;AACxE,WAAO,KAAK,KAAK,CAAC,QAA+B;AAC/C,UAAI,IAAI,SAAS,oBAAoB;AACnC,eAAO,IAAI,YAAY;AAAA,UACrB,CAAC,UACE,KAAK,SAAS,cAAc,KAAK,SAAS,qBAC3C,KAAK,KAAK,SAAS,gBACnB,KAAK,IAAI,SAAS;AAAA,QACtB;AAAA,MACF;AACA,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AAQA,WAAS,4BAA4B,MAA0B;AAC7D,QAAI,SAAS,KAAK;AAGlB,QAAI,QAAQ,UAAU,OAAO,MAAM,SAAS,cAAc,OAAO,MAAM,SAAS,mBAAmB;AACjG,UAAI,kBAAkB,OAAO,OAAO,GAAG,eAAe,GAAG;AACvD,gBAAQ,aAAa;AAAA,MACvB;AACA;AAAA,IACF;AAGA,QAAI,QAAQ,OAAO,SAAS,mBAAmB;AAC7C,UAAI,kBAAkB,KAAK,OAAO,GAAG,eAAe,GAAG;AACrD,gBAAQ,aAAa;AAAA,MACvB;AACA;AAAA,IACF;AAGA,WAAO,UAAU,CAAC,gBAAgB,IAAI,OAAO,MAAM,IAAI,GAAG;AACxD,eAAS,OAAO;AAAA,IAClB;AAEA,QAAI,QAAQ,OAAO;AAEjB,UAAI,aAAa,OAAO;AACxB,UACE,WAAW,SAAS,8BACpB,WAAW,SAAS,4BACpB,OAAO,WACN,OAAO,OAAO,MAAM,SAAS,8BAC5B,OAAO,OAAO,MAAM,SAAS,2BAC/B;AACA,qBAAa,OAAO,OAAO;AAAA,MAC7B;AAEA,UAAI,kBAAkB,YAAY,GAAG,eAAe,GAAG;AACrD,gBAAQ,aAAa;AAAA,MACvB;AAAA,IACF;AAAA,EACF;AAGA,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,KAAK,CAAC,cAAc,KAAK,MAAM,SAAS,GAAG;AAC9E,oCAA4B,IAAI;AAAA,MAClC;AAAA,IACF;AAAA,EACF,CAAC;AAGD,OAAK,KAAK,EAAE,cAAc,EAAE,QAAQ,UAAQ;AAC1C,QAAI,KAAK,MAAM,OAAO,SAAS,cAAc;AAC3C,YAAM,eAAe,KAAK,MAAM,OAAO;AAEvC,UAAI,gBAAgB,SAAS,YAAY,KAAK,CAAC,cAAc,KAAK,MAAM,SAAS,GAAG;AAClF,oCAA4B,IAAI;AAAA,MAClC;AAAA,IACF;AAAA,EACF,CAAC;AAED,MAAI,QAAQ,YAAY;AACtB,YAAQ,SAAS,KAAK,mBAAmB,SAAS,IAAI,wDAAwD;AAAA,EAChH;AACF,CAAC;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/codemod",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "1.0.0",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"description": "Codemod CLI for Mastra",
|
|
7
7
|
"bin": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"tsup": "^8.5.0",
|
|
35
35
|
"typescript": "^5.9.3",
|
|
36
36
|
"vitest": "4.0.16",
|
|
37
|
-
"@internal/lint": "0.0.
|
|
37
|
+
"@internal/lint": "0.0.54"
|
|
38
38
|
},
|
|
39
39
|
"homepage": "https://mastra.ai",
|
|
40
40
|
"repository": {
|