@mastra/codemod 0.0.0-fix-thread-list-20251105222841 → 0.0.0-fix-issue-10434-concurrent-write-corruption-20251124213939

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.
Files changed (87) hide show
  1. package/CHANGELOG.md +29 -1
  2. package/README.md +46 -11
  3. package/dist/codemods/chunk-JNFQ6J6B.js +21 -0
  4. package/dist/codemods/chunk-JNFQ6J6B.js.map +1 -0
  5. package/dist/codemods/chunk-LGW3NUAJ.js +32 -0
  6. package/dist/codemods/chunk-LGW3NUAJ.js.map +1 -0
  7. package/dist/codemods/chunk-PKCFDS7J.js +177 -0
  8. package/dist/codemods/chunk-PKCFDS7J.js.map +1 -0
  9. package/dist/codemods/lib/add-comment.js +6 -54
  10. package/dist/codemods/lib/add-comment.js.map +1 -1
  11. package/dist/codemods/lib/create-transformer.js +5 -43
  12. package/dist/codemods/lib/create-transformer.js.map +1 -1
  13. package/dist/codemods/lib/utils.js +23 -0
  14. package/dist/codemods/lib/utils.js.map +1 -0
  15. package/dist/codemods/v1/agent-abort-signal.js +61 -0
  16. package/dist/codemods/v1/agent-abort-signal.js.map +1 -0
  17. package/dist/codemods/v1/agent-generate-stream-v-next.js +26 -0
  18. package/dist/codemods/v1/agent-generate-stream-v-next.js.map +1 -0
  19. package/dist/codemods/v1/agent-processor-methods.js +28 -0
  20. package/dist/codemods/v1/agent-processor-methods.js.map +1 -0
  21. package/dist/codemods/v1/agent-property-access.js +42 -0
  22. package/dist/codemods/v1/agent-property-access.js.map +1 -0
  23. package/dist/codemods/v1/agent-voice.js +37 -0
  24. package/dist/codemods/v1/agent-voice.js.map +1 -0
  25. package/dist/codemods/v1/client-get-memory-thread.js +58 -0
  26. package/dist/codemods/v1/client-get-memory-thread.js.map +1 -0
  27. package/dist/codemods/v1/client-offset-limit.js +49 -0
  28. package/dist/codemods/v1/client-offset-limit.js.map +1 -0
  29. package/dist/codemods/v1/client-sdk-types.js +56 -0
  30. package/dist/codemods/v1/client-sdk-types.js.map +1 -0
  31. package/dist/codemods/v1/client-to-ai-sdk-format.js +20 -0
  32. package/dist/codemods/v1/client-to-ai-sdk-format.js.map +1 -0
  33. package/dist/codemods/v1/evals-prebuilt-imports.js +24 -0
  34. package/dist/codemods/v1/evals-prebuilt-imports.js.map +1 -0
  35. package/dist/codemods/v1/evals-run-experiment.js +20 -0
  36. package/dist/codemods/v1/evals-run-experiment.js.map +1 -0
  37. package/dist/codemods/v1/evals-scorer-by-name.js +22 -0
  38. package/dist/codemods/v1/evals-scorer-by-name.js.map +1 -0
  39. package/dist/codemods/v1/experimental-auth.js +27 -0
  40. package/dist/codemods/v1/experimental-auth.js.map +1 -0
  41. package/dist/codemods/v1/mastra-core-imports.js +11 -47
  42. package/dist/codemods/v1/mastra-core-imports.js.map +1 -1
  43. package/dist/codemods/v1/mastra-plural-apis.js +31 -0
  44. package/dist/codemods/v1/mastra-plural-apis.js.map +1 -0
  45. package/dist/codemods/v1/mcp-get-tools.js +24 -0
  46. package/dist/codemods/v1/mcp-get-tools.js.map +1 -0
  47. package/dist/codemods/v1/mcp-get-toolsets.js +24 -0
  48. package/dist/codemods/v1/mcp-get-toolsets.js.map +1 -0
  49. package/dist/codemods/v1/memory-message-v2-type.js +50 -0
  50. package/dist/codemods/v1/memory-message-v2-type.js.map +1 -0
  51. package/dist/codemods/v1/memory-query-to-recall.js +22 -0
  52. package/dist/codemods/v1/memory-query-to-recall.js.map +1 -0
  53. package/dist/codemods/v1/memory-vector-search-param.js +31 -0
  54. package/dist/codemods/v1/memory-vector-search-param.js.map +1 -0
  55. package/dist/codemods/v1/not-implemented/agent-format-parameter.js +53 -0
  56. package/dist/codemods/v1/not-implemented/agent-format-parameter.js.map +1 -0
  57. package/dist/codemods/v1/not-implemented/agent-to-step.js +54 -0
  58. package/dist/codemods/v1/not-implemented/agent-to-step.js.map +1 -0
  59. package/dist/codemods/v1/not-implemented/mastra-memory.js +50 -0
  60. package/dist/codemods/v1/not-implemented/mastra-memory.js.map +1 -0
  61. package/dist/codemods/v1/not-implemented/mastra-required-id.js +113 -0
  62. package/dist/codemods/v1/not-implemented/mastra-required-id.js.map +1 -0
  63. package/dist/codemods/v1/runtime-context.js +6 -42
  64. package/dist/codemods/v1/runtime-context.js.map +1 -1
  65. package/dist/codemods/v1/storage-get-messages-paginated.js +41 -0
  66. package/dist/codemods/v1/storage-get-messages-paginated.js.map +1 -0
  67. package/dist/codemods/v1/storage-get-threads-by-resource.js +23 -0
  68. package/dist/codemods/v1/storage-get-threads-by-resource.js.map +1 -0
  69. package/dist/codemods/v1/storage-list-messages-by-id.js +23 -0
  70. package/dist/codemods/v1/storage-list-messages-by-id.js.map +1 -0
  71. package/dist/codemods/v1/storage-list-workflow-runs.js +23 -0
  72. package/dist/codemods/v1/storage-list-workflow-runs.js.map +1 -0
  73. package/dist/codemods/v1/storage-postgres-schema-name.js +20 -0
  74. package/dist/codemods/v1/storage-postgres-schema-name.js.map +1 -0
  75. package/dist/codemods/v1/vector-pg-constructor.js +27 -0
  76. package/dist/codemods/v1/vector-pg-constructor.js.map +1 -0
  77. package/dist/codemods/v1/voice-property-names.js +42 -0
  78. package/dist/codemods/v1/voice-property-names.js.map +1 -0
  79. package/dist/codemods/v1/workflow-create-run-async.js +22 -0
  80. package/dist/codemods/v1/workflow-create-run-async.js.map +1 -0
  81. package/dist/codemods/v1/workflow-list-runs.js +22 -0
  82. package/dist/codemods/v1/workflow-list-runs.js.map +1 -0
  83. package/dist/codemods/v1/workflow-run-count.js +53 -0
  84. package/dist/codemods/v1/workflow-run-count.js.map +1 -0
  85. package/dist/index.js +114 -27
  86. package/dist/index.js.map +1 -1
  87. package/package.json +9 -5
package/CHANGELOG.md CHANGED
@@ -1,6 +1,34 @@
1
1
  # @mastra/codemod
2
2
 
3
- ## 0.0.0-fix-thread-list-20251105222841
3
+ ## 0.0.0-fix-issue-10434-concurrent-write-corruption-20251124213939
4
+
5
+ ### Minor Changes
6
+
7
+ - Initial release of `@mastra/codemod` package ([#9579](https://github.com/mastra-ai/mastra/pull/9579))
8
+
9
+ ### Patch Changes
10
+
11
+ - 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))
12
+
13
+ - - Improve existing codemods ([#9959](https://github.com/mastra-ai/mastra/pull/9959))
14
+ - Make package ESM-only
15
+ - Add new codemods
16
+
17
+ ## 0.1.0-beta.2
18
+
19
+ ### Patch Changes
20
+
21
+ - 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))
22
+
23
+ ## 0.1.0-beta.1
24
+
25
+ ### Patch Changes
26
+
27
+ - - Improve existing codemods ([#9959](https://github.com/mastra-ai/mastra/pull/9959))
28
+ - Make package ESM-only
29
+ - Add new codemods
30
+
31
+ ## 0.1.0-beta.0
4
32
 
5
33
  ### Minor Changes
6
34
 
package/README.md CHANGED
@@ -6,42 +6,77 @@ Codemods are transformations that run on your codebase programmatically, allowin
6
6
 
7
7
  ## Quick Start
8
8
 
9
+ ### Run Version-Specific Codemods
10
+
11
+ ```sh
12
+ npx @mastra/codemod@beta v1
13
+ ```
14
+
9
15
  ### Run Individual Codemods
10
16
 
11
17
  To run a specific codemod:
12
18
 
13
19
  ```sh
14
- npx @mastra/codemod <codemod-name> <path>
20
+ npx @mastra/codemod@beta <codemod-name> <path>
15
21
  ```
16
22
 
17
23
  Examples:
18
24
 
19
25
  ```sh
20
26
  # Transform a specific file
21
- npx @mastra/codemod v1/mastra-core-imports src/mastra.ts
27
+ npx @mastra/codemod@beta v1/mastra-core-imports src/mastra.ts
22
28
 
23
29
  # Transform a directory
24
- npx @mastra/codemod v1/mastra-core-imports src/lib/
30
+ npx @mastra/codemod@beta v1/mastra-core-imports src/lib/
25
31
 
26
32
  # Transform entire project
27
- npx @mastra/codemod v1/mastra-core-imports .
33
+ npx @mastra/codemod@beta v1/mastra-core-imports .
28
34
  ```
29
35
 
30
36
  ## Available Codemods
31
37
 
32
38
  ### v1 Codemods (v0 → v1 Migration)
33
39
 
34
- | Codemod | Description |
35
- | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------ |
36
- | `v1/mastra-core-imports` | Updates all imports from `@mastra/core` to use the new subpath imports. For v1, all exports except `Mastra` and `Config` have moved to subpaths. |
37
- | `v1/runtime-context` | Update `RuntimeContext` to `RequestContext` and rename all instances of parameter names. |
40
+ | Codemod | Description |
41
+ | ------------------------------------ | ------------------------------------------------------------------------------------------------------------------ |
42
+ | `v1/agent-abort-signal` | Moves `abortSignal` from `modelSettings` to top-level options in agent method calls |
43
+ | `v1/agent-generate-stream-v-next` | Renames `agent.generateVNext()` `agent.generate()` and `agent.streamVNext()` `agent.stream()` |
44
+ | `v1/agent-processor-methods` | Renames `agent.getInputProcessors()` → `agent.listInputProcessors()` and similar output processor methods |
45
+ | `v1/agent-property-access` | Transforms agent property access to method calls: `agent.llm` → `agent.getLLM()` |
46
+ | `v1/agent-voice` | Moves agent voice methods to namespace: `agent.speak()` → `agent.voice.speak()` |
47
+ | `v1/client-get-memory-thread` | Updates `client.getMemoryThread(threadId, agentId)` to use object parameter |
48
+ | `v1/client-offset-limit` | Renames pagination properties from `offset`/`limit` to `page`/`perPage` |
49
+ | `v1/client-sdk-types` | Renames Client SDK types from Get\* to List\* pattern |
50
+ | `v1/client-to-ai-sdk-format` | Renames `toAISdkFormat` to `toAISdkStream` |
51
+ | `v1/evals-prebuilt-imports` | Updates prebuilt scorer imports from `scorers/llm` and `scorers/code` to `scorers/prebuilt` |
52
+ | `v1/evals-run-experiment` | Renames `runExperiment()` → `runEvals()` in imports and usages |
53
+ | `v1/evals-scorer-by-name` | Renames `mastra.getScorerByName()` → `mastra.getScorerById()` |
54
+ | `v1/experimental-auth` | Renames `experimental_auth` to `auth` in Mastra configuration |
55
+ | `v1/mastra-core-imports` | Updates imports from `@mastra/core` to use new subpath imports |
56
+ | `v1/mastra-plural-apis` | Renames Mastra plural API methods from get\* to list\* |
57
+ | `v1/mcp-get-tools` | Renames `mcp.getTools()` → `mcp.listTools()` |
58
+ | `v1/mcp-get-toolsets` | Renames `mcp.getToolsets()` → `mcp.listToolsets()` |
59
+ | `v1/memory-message-v2-type` | Renames `MastraMessageV2` type → `MastraDBMessage` in imports and usages |
60
+ | `v1/memory-query-to-recall` | Renames `memory.query()` → `memory.recall()` |
61
+ | `v1/memory-vector-search-param` | Renames `vectorMessageSearch` parameter → `vectorSearchString` in `memory.recall()` calls |
62
+ | `v1/runtime-context` | Renames `RuntimeContext` to `RequestContext` and updates parameter names from `runtimeContext` to `requestContext` |
63
+ | `v1/storage-get-messages-paginated` | Renames `storage.getMessagesPaginated()` → `storage.listMessages()` and `offset`/`limit` → `page`/`perPage` |
64
+ | `v1/storage-get-threads-by-resource` | Renames `storage.getThreadsByResourceId()` → `storage.listThreadsByResourceId()` |
65
+ | `v1/storage-list-messages-by-id` | Renames `storage.getMessagesById()` → `storage.listMessagesById()` |
66
+ | `v1/storage-list-workflow-runs` | Renames `storage.getWorkflowRuns()` → `storage.listWorkflowRuns()` |
67
+ | `v1/storage-postgres-schema-name` | Renames `schema` property → `schemaName` in PostgresStore constructor |
68
+ | `v1/vector-pg-constructor` | Converts `new PgVector(connectionString)` to `new PgVector({ connectionString })` |
69
+ | `v1/voice-property-names` | Renames voice property names in Agent configuration: `speakProvider` → `output` |
70
+ | `v1/workflow-create-run-async` | Renames `workflow.createRunAsync()` → `workflow.createRun()` |
71
+ | `v1/workflow-list-runs` | Renames `workflow.getWorkflowRuns()` → `workflow.listWorkflowRuns()` |
72
+ | `v1/workflow-run-count` | Renames `context.runCount` → `context.retryCount` in step execution functions |
38
73
 
39
74
  ## CLI Options
40
75
 
41
76
  ### Commands
42
77
 
43
78
  ```sh
44
- npx @mastra/codemod <command> [options]
79
+ npx @mastra/codemod@beta <command> [options]
45
80
  ```
46
81
 
47
82
  **Available Commands:**
@@ -58,10 +93,10 @@ npx @mastra/codemod <command> [options]
58
93
 
59
94
  ```sh
60
95
  # Show verbose output for specific codemod
61
- npx @mastra/codemod --verbose v1/mastra-core-imports src/
96
+ npx @mastra/codemod@beta --verbose v1/mastra-core-imports src/
62
97
 
63
98
  # Print transformed code for specific codemod
64
- npx @mastra/codemod --print v1/mastra-core-imports src/mastra.ts
99
+ npx @mastra/codemod@beta --print v1/mastra-core-imports src/mastra.ts
65
100
  ```
66
101
 
67
102
  ## Contributing
@@ -0,0 +1,21 @@
1
+ // src/codemods/lib/create-transformer.ts
2
+ function createTransformer(transformFn) {
3
+ return function transformer(fileInfo, api, options) {
4
+ const j = api.jscodeshift;
5
+ const root = j(fileInfo.source);
6
+ const context = {
7
+ j,
8
+ root,
9
+ hasChanges: false,
10
+ messages: []
11
+ };
12
+ transformFn(fileInfo, api, options, context);
13
+ context.messages.forEach((message) => api.report(message));
14
+ return context.hasChanges ? root.toSource({ quote: "single" }) : null;
15
+ };
16
+ }
17
+
18
+ export {
19
+ createTransformer
20
+ };
21
+ //# sourceMappingURL=chunk-JNFQ6J6B.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/codemods/lib/create-transformer.ts"],"sourcesContent":["// Copied from https://github.com/vercel/ai/blob/main/packages/codemod/src/codemods/lib/create-transformer.ts\n// License: Apache-2.0\n\nimport type { FileInfo, API, JSCodeshift, Collection } from 'jscodeshift';\n\ntype TransformerFunction = (\n fileInfo: FileInfo,\n api: API,\n options: Record<string, unknown>,\n context: TransformContext,\n) => void;\n\nexport interface TransformContext {\n /**\n * The jscodeshift API object.\n */\n j: JSCodeshift;\n\n /**\n * The root collection of the AST.\n */\n root: Collection<any>;\n\n /**\n * Codemods should set this to true if they make any changes to the AST.\n */\n hasChanges: boolean;\n\n /**\n * Codemods can append messages to this array to report information to the user.\n */\n messages: string[];\n}\n\nexport function createTransformer(transformFn: TransformerFunction) {\n // Note the return type of this function is explicitly designed to conform to\n // the signature expected by jscodeshift. For more see\n // https://github.com/facebook/jscodeshift\n return function transformer(fileInfo: FileInfo, api: API, options: Record<string, unknown>) {\n const j = api.jscodeshift;\n const root = j(fileInfo.source);\n const context: TransformContext = {\n j,\n root,\n hasChanges: false,\n messages: [],\n };\n\n // Execute the transformation\n transformFn(fileInfo, api, options, context);\n\n // Report any messages\n context.messages.forEach(message => api.report(message));\n\n // Return the transformed source code if changes were made\n return context.hasChanges ? root.toSource({ quote: 'single' }) : null;\n };\n}\n"],"mappings":";AAkCO,SAAS,kBAAkB,aAAkC;AAIlE,SAAO,SAAS,YAAY,UAAoB,KAAU,SAAkC;AAC1F,UAAM,IAAI,IAAI;AACd,UAAM,OAAO,EAAE,SAAS,MAAM;AAC9B,UAAM,UAA4B;AAAA,MAChC;AAAA,MACA;AAAA,MACA,YAAY;AAAA,MACZ,UAAU,CAAC;AAAA,IACb;AAGA,gBAAY,UAAU,KAAK,SAAS,OAAO;AAG3C,YAAQ,SAAS,QAAQ,aAAW,IAAI,OAAO,OAAO,CAAC;AAGvD,WAAO,QAAQ,aAAa,KAAK,SAAS,EAAE,OAAO,SAAS,CAAC,IAAI;AAAA,EACnE;AACF;","names":[]}
@@ -0,0 +1,32 @@
1
+ // src/codemods/lib/add-comment.ts
2
+ var ERROR_PREFIX = "FIXME(mastra): ";
3
+ function existsComment(comments, comment) {
4
+ let hasComment = false;
5
+ if (comments) {
6
+ comments.forEach((commentNode) => {
7
+ const currentComment = commentNode.value.trim();
8
+ if (currentComment === comment) {
9
+ hasComment = true;
10
+ }
11
+ });
12
+ if (hasComment) {
13
+ return true;
14
+ }
15
+ }
16
+ return false;
17
+ }
18
+ function insertCommentOnce(node, j, comment) {
19
+ const hasCommentInInlineComments = existsComment(node.comments, comment);
20
+ const hasCommentInLeadingComments = existsComment(node.leadingComments, comment);
21
+ if (!hasCommentInInlineComments && !hasCommentInLeadingComments) {
22
+ node.comments = [...node.comments || [], j.commentBlock(` ${comment} `)];
23
+ return true;
24
+ }
25
+ return false;
26
+ }
27
+
28
+ export {
29
+ ERROR_PREFIX,
30
+ insertCommentOnce
31
+ };
32
+ //# sourceMappingURL=chunk-LGW3NUAJ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/codemods/lib/add-comment.ts"],"sourcesContent":["import type { API, ASTPath } from 'jscodeshift';\n\nexport const ERROR_PREFIX = 'FIXME(mastra): ';\n\nfunction existsComment(comments: ASTPath<any>['node']['comments'], comment: string): boolean {\n let hasComment = false;\n\n if (comments) {\n comments.forEach((commentNode: { value: string; type: string }) => {\n const currentComment = commentNode.value.trim();\n if (currentComment === comment) {\n hasComment = true;\n }\n });\n\n if (hasComment) {\n return true;\n }\n }\n return false;\n}\n\nexport function insertCommentOnce(node: ASTPath<any>['node'], j: API['j'], comment: string): boolean {\n const hasCommentInInlineComments = existsComment(node.comments, comment);\n const hasCommentInLeadingComments = existsComment(node.leadingComments, comment);\n\n if (!hasCommentInInlineComments && !hasCommentInLeadingComments) {\n node.comments = [...(node.comments || []), j.commentBlock(` ${comment} `)];\n return true;\n }\n\n return false;\n}\n"],"mappings":";AAEO,IAAM,eAAe;AAE5B,SAAS,cAAc,UAA4C,SAA0B;AAC3F,MAAI,aAAa;AAEjB,MAAI,UAAU;AACZ,aAAS,QAAQ,CAAC,gBAAiD;AACjE,YAAM,iBAAiB,YAAY,MAAM,KAAK;AAC9C,UAAI,mBAAmB,SAAS;AAC9B,qBAAa;AAAA,MACf;AAAA,IACF,CAAC;AAED,QAAI,YAAY;AACd,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAEO,SAAS,kBAAkB,MAA4B,GAAa,SAA0B;AACnG,QAAM,6BAA6B,cAAc,KAAK,UAAU,OAAO;AACvE,QAAM,8BAA8B,cAAc,KAAK,iBAAiB,OAAO;AAE/E,MAAI,CAAC,8BAA8B,CAAC,6BAA6B;AAC/D,SAAK,WAAW,CAAC,GAAI,KAAK,YAAY,CAAC,GAAI,EAAE,aAAa,IAAI,OAAO,GAAG,CAAC;AACzE,WAAO;AAAA,EACT;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1,177 @@
1
+ // src/codemods/lib/utils.ts
2
+ function trackClassInstances(j, root, className) {
3
+ const instances = /* @__PURE__ */ new Set();
4
+ root.find(j.NewExpression, {
5
+ callee: {
6
+ type: "Identifier",
7
+ name: className
8
+ }
9
+ }).forEach((path) => {
10
+ const parent = path.parent.value;
11
+ if (parent.type === "VariableDeclarator" && parent.id.type === "Identifier") {
12
+ instances.add(parent.id.name);
13
+ }
14
+ });
15
+ return instances;
16
+ }
17
+ function trackMultipleClassInstances(j, root, classNames) {
18
+ const instances = /* @__PURE__ */ new Set();
19
+ const classNameSet = new Set(classNames);
20
+ root.find(j.NewExpression).forEach((path) => {
21
+ const { callee } = path.value;
22
+ if (callee.type !== "Identifier") return;
23
+ if (!classNameSet.has(callee.name)) return;
24
+ const parent = path.parent.value;
25
+ if (parent.type === "VariableDeclarator" && parent.id.type === "Identifier") {
26
+ instances.add(parent.id.name);
27
+ }
28
+ });
29
+ return instances;
30
+ }
31
+ function transformMethodCalls(j, root, instances, methodName, transform) {
32
+ if (instances.size === 0) return 0;
33
+ let count = 0;
34
+ root.find(j.CallExpression).forEach((path) => {
35
+ const { callee } = path.value;
36
+ if (callee.type !== "MemberExpression") return;
37
+ if (callee.object.type !== "Identifier") return;
38
+ if (callee.property.type !== "Identifier") return;
39
+ if (!instances.has(callee.object.name)) return;
40
+ if (methodName && callee.property.name !== methodName) return;
41
+ transform(path);
42
+ count++;
43
+ });
44
+ return count;
45
+ }
46
+ function renameMethod(j, root, instances, oldMethodName, newMethodName) {
47
+ if (instances.size === 0) return 0;
48
+ let count = 0;
49
+ root.find(j.CallExpression).forEach((path) => {
50
+ const { callee } = path.value;
51
+ if (callee.type !== "MemberExpression") return;
52
+ if (callee.object.type !== "Identifier") return;
53
+ if (callee.property.type !== "Identifier") return;
54
+ if (!instances.has(callee.object.name)) return;
55
+ if (callee.property.name !== oldMethodName) return;
56
+ callee.property.name = newMethodName;
57
+ count++;
58
+ });
59
+ return count;
60
+ }
61
+ function renameMethods(j, root, instances, methodRenames) {
62
+ if (instances.size === 0) return 0;
63
+ let count = 0;
64
+ root.find(j.CallExpression).forEach((path) => {
65
+ const { callee } = path.value;
66
+ if (callee.type !== "MemberExpression") return;
67
+ if (callee.object.type !== "Identifier") return;
68
+ if (callee.property.type !== "Identifier") return;
69
+ if (!instances.has(callee.object.name)) return;
70
+ const oldName = callee.property.name;
71
+ const newName = methodRenames[oldName];
72
+ if (newName) {
73
+ callee.property.name = newName;
74
+ count++;
75
+ }
76
+ });
77
+ return count;
78
+ }
79
+ function transformObjectProperties(obj, propertyRenames) {
80
+ let count = 0;
81
+ const recurse = (o) => {
82
+ if (!o.properties) return;
83
+ o.properties.forEach((prop) => {
84
+ if ((prop.type === "Property" || prop.type === "ObjectProperty") && prop.key?.type === "Identifier") {
85
+ const oldName = prop.key.name;
86
+ const newName = propertyRenames[oldName];
87
+ if (newName) {
88
+ prop.key.name = newName;
89
+ count++;
90
+ }
91
+ if (prop.value?.type === "ObjectExpression") {
92
+ recurse(prop.value);
93
+ }
94
+ }
95
+ });
96
+ };
97
+ recurse(obj);
98
+ return count;
99
+ }
100
+ function isMemberExpressionOnInstance(node, instances, propertyName) {
101
+ if (node.type !== "MemberExpression") return false;
102
+ if (node.object.type !== "Identifier") return false;
103
+ if (!instances.has(node.object.name)) return false;
104
+ if (propertyName && node.property.type === "Identifier" && node.property.name !== propertyName) {
105
+ return false;
106
+ }
107
+ return true;
108
+ }
109
+ function renameImportAndUsages(j, root, packageName, oldName, newName) {
110
+ let changes = 0;
111
+ const localNamesToReplace = /* @__PURE__ */ new Set();
112
+ root.find(j.ImportDeclaration).filter((path) => {
113
+ const source = path.value.source.value;
114
+ return typeof source === "string" && source === packageName;
115
+ }).forEach((path) => {
116
+ if (!path.value.specifiers) return;
117
+ path.value.specifiers.forEach((specifier) => {
118
+ if (specifier.type === "ImportSpecifier" && specifier.imported.type === "Identifier" && specifier.imported.name === oldName) {
119
+ const isAliased = specifier.local && specifier.local.name !== oldName;
120
+ specifier.imported.name = newName;
121
+ changes++;
122
+ if (!isAliased) {
123
+ if (specifier.local) {
124
+ specifier.local.name = newName;
125
+ }
126
+ localNamesToReplace.add(oldName);
127
+ }
128
+ }
129
+ });
130
+ });
131
+ localNamesToReplace.forEach((localName) => {
132
+ root.find(j.Identifier, { name: localName }).forEach((path) => {
133
+ const parent = path.parent;
134
+ if (parent && parent.value.type === "ImportSpecifier") {
135
+ return;
136
+ }
137
+ path.value.name = newName;
138
+ changes++;
139
+ });
140
+ });
141
+ return changes;
142
+ }
143
+ function transformConstructorProperties(j, root, className, propertyRenames) {
144
+ let count = 0;
145
+ root.find(j.NewExpression, {
146
+ callee: { type: "Identifier", name: className }
147
+ }).forEach((path) => {
148
+ const args = path.value.arguments;
149
+ if (args.length === 0) return;
150
+ const firstArg = args[0];
151
+ if (!firstArg || firstArg.type !== "ObjectExpression" || !firstArg.properties) return;
152
+ firstArg.properties.forEach((prop) => {
153
+ if ((prop.type === "Property" || prop.type === "ObjectProperty") && prop.key?.type === "Identifier") {
154
+ const oldName = prop.key.name;
155
+ const newName = propertyRenames[oldName];
156
+ if (newName) {
157
+ prop.key.name = newName;
158
+ count++;
159
+ }
160
+ }
161
+ });
162
+ });
163
+ return count;
164
+ }
165
+
166
+ export {
167
+ trackClassInstances,
168
+ trackMultipleClassInstances,
169
+ transformMethodCalls,
170
+ renameMethod,
171
+ renameMethods,
172
+ transformObjectProperties,
173
+ isMemberExpressionOnInstance,
174
+ renameImportAndUsages,
175
+ transformConstructorProperties
176
+ };
177
+ //# sourceMappingURL=chunk-PKCFDS7J.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/codemods/lib/utils.ts"],"sourcesContent":["// Shared utility functions for codemods\n\nimport type { Collection, JSCodeshift } from 'jscodeshift';\n\n/**\n * Efficiently tracks instances of a specific class by finding all `new ClassName()` expressions\n * and extracting the variable names they're assigned to.\n *\n * @param j - JSCodeshift API\n * @param root - Root collection\n * @param className - Name of the class to track\n * @returns Set of variable names that are instances of the class\n */\nexport function trackClassInstances(j: JSCodeshift, root: Collection<any>, className: string): Set<string> {\n const instances = new Set<string>();\n\n root\n .find(j.NewExpression, {\n callee: {\n type: 'Identifier',\n name: className,\n },\n })\n .forEach(path => {\n const parent = path.parent.value;\n if (parent.type === 'VariableDeclarator' && parent.id.type === 'Identifier') {\n instances.add(parent.id.name);\n }\n });\n\n return instances;\n}\n\n/**\n * Efficiently tracks instances of multiple classes in a single pass.\n * This is optimized for codemods that need to track several store types or class variants.\n *\n * @param j - JSCodeshift API\n * @param root - Root collection\n * @param classNames - Array of class names to track\n * @returns Set of variable names that are instances of any of the classes\n */\nexport function trackMultipleClassInstances(j: JSCodeshift, root: Collection<any>, classNames: string[]): Set<string> {\n const instances = new Set<string>();\n const classNameSet = new Set(classNames);\n\n root.find(j.NewExpression).forEach(path => {\n const { callee } = path.value;\n if (callee.type !== 'Identifier') return;\n if (!classNameSet.has(callee.name)) return;\n\n const parent = path.parent.value;\n if (parent.type === 'VariableDeclarator' && parent.id.type === 'Identifier') {\n instances.add(parent.id.name);\n }\n });\n\n return instances;\n}\n\n/**\n * Efficiently finds and transforms method calls on tracked instances.\n * This combines finding, filtering, and transforming in a single pass.\n *\n * @param j - JSCodeshift API\n * @param root - Root collection\n * @param instances - Set of instance variable names to track\n * @param methodName - Name of the method to find (or undefined to match any method)\n * @param transform - Callback to transform matching call expressions\n * @returns Number of transformations made\n */\nexport function transformMethodCalls(\n j: JSCodeshift,\n root: Collection<any>,\n instances: Set<string>,\n methodName: string | undefined,\n transform: (path: any) => void,\n): number {\n if (instances.size === 0) return 0;\n\n let count = 0;\n\n root.find(j.CallExpression).forEach(path => {\n const { callee } = path.value;\n if (callee.type !== 'MemberExpression') return;\n if (callee.object.type !== 'Identifier') return;\n if (callee.property.type !== 'Identifier') return;\n\n // Only process if called on a tracked instance\n if (!instances.has(callee.object.name)) return;\n\n // Only process if it's the method we want (or any method if undefined)\n if (methodName && callee.property.name !== methodName) return;\n\n transform(path);\n count++;\n });\n\n return count;\n}\n\n/**\n * Renames a method on tracked instances efficiently in a single pass.\n *\n * @param j - JSCodeshift API\n * @param root - Root collection\n * @param instances - Set of instance variable names to track\n * @param oldMethodName - Current method name\n * @param newMethodName - New method name\n * @returns Number of renames performed\n */\nexport function renameMethod(\n j: JSCodeshift,\n root: Collection<any>,\n instances: Set<string>,\n oldMethodName: string,\n newMethodName: string,\n): number {\n if (instances.size === 0) return 0;\n\n let count = 0;\n\n root.find(j.CallExpression).forEach(path => {\n const { callee } = path.value;\n if (callee.type !== 'MemberExpression') return;\n if (callee.object.type !== 'Identifier') return;\n if (callee.property.type !== 'Identifier') return;\n\n // Only process if called on tracked instance\n if (!instances.has(callee.object.name)) return;\n\n // Only process if it's the method we want to rename\n if (callee.property.name !== oldMethodName) return;\n\n callee.property.name = newMethodName;\n count++;\n });\n\n return count;\n}\n\n/**\n * Renames multiple methods on tracked instances in a single pass.\n *\n * @param j - JSCodeshift API\n * @param root - Root collection\n * @param instances - Set of instance variable names to track\n * @param methodRenames - Map of old method names to new method names\n * @returns Number of renames performed\n */\nexport function renameMethods(\n j: JSCodeshift,\n root: Collection<any>,\n instances: Set<string>,\n methodRenames: Record<string, string>,\n): number {\n if (instances.size === 0) return 0;\n\n let count = 0;\n\n root.find(j.CallExpression).forEach(path => {\n const { callee } = path.value;\n if (callee.type !== 'MemberExpression') return;\n if (callee.object.type !== 'Identifier') return;\n if (callee.property.type !== 'Identifier') return;\n\n // Only process if called on tracked instance\n if (!instances.has(callee.object.name)) return;\n\n // Check if this is one of the methods we want to rename\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 return count;\n}\n\n/**\n * Transforms object properties in method call arguments.\n * This is a helper for codemods that need to rename properties in object arguments.\n *\n * @param obj - Object expression to transform\n * @param propertyRenames - Map of old property names to new property names\n * @returns Number of properties renamed\n */\nexport function transformObjectProperties(obj: any, propertyRenames: Record<string, string>): number {\n let count = 0;\n\n const recurse = (o: any) => {\n if (!o.properties) return;\n\n o.properties.forEach((prop: any) => {\n if ((prop.type === 'Property' || prop.type === 'ObjectProperty') && prop.key?.type === 'Identifier') {\n const oldName = prop.key.name;\n const newName = propertyRenames[oldName];\n\n if (newName) {\n prop.key.name = newName;\n count++;\n }\n\n // Recursively transform nested objects\n if (prop.value?.type === 'ObjectExpression') {\n recurse(prop.value);\n }\n }\n });\n };\n\n recurse(obj);\n return count;\n}\n\n/**\n * Checks if a node is a member expression accessing a specific property on tracked instances.\n *\n * @param node - AST node to check\n * @param instances - Set of instance variable names to track\n * @param propertyName - Property name to match (or undefined to match any property)\n * @returns true if the node matches\n */\nexport function isMemberExpressionOnInstance(node: any, instances: Set<string>, propertyName?: string): boolean {\n if (node.type !== 'MemberExpression') return false;\n if (node.object.type !== 'Identifier') return false;\n if (!instances.has(node.object.name)) return false;\n\n if (propertyName && node.property.type === 'Identifier' && node.property.name !== propertyName) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Renames an import and all its usages in a single optimized pass.\n * Handles aliased imports correctly - only transforms usages for non-aliased imports.\n * Handles multiple imports of the same name (with different aliases) correctly.\n *\n * For non-aliased imports: Renames both import and all usages\n * import { oldName } → import { newName }\n * oldName() → newName()\n *\n * For aliased imports: Only renames the import, keeps alias in usages\n * import { oldName as alias } → import { newName as alias }\n * alias() → alias() (unchanged)\n *\n * @param j - JSCodeshift API\n * @param root - Root collection\n * @param packageName - Package to import from (e.g., '@mastra/core/evals')\n * @param oldName - Current import name\n * @param newName - New import name\n * @returns Number of changes made\n */\nexport function renameImportAndUsages(\n j: JSCodeshift,\n root: Collection<any>,\n packageName: string,\n oldName: string,\n newName: string,\n): number {\n let changes = 0;\n const localNamesToReplace = new Set<string>();\n\n // First: Transform import specifiers from the specific package and collect local names to replace\n root\n .find(j.ImportDeclaration)\n .filter(path => {\n const source = path.value.source.value;\n return typeof source === 'string' && source === packageName;\n })\n .forEach(path => {\n if (!path.value.specifiers) return;\n\n path.value.specifiers.forEach((specifier: any) => {\n if (\n specifier.type === 'ImportSpecifier' &&\n specifier.imported.type === 'Identifier' &&\n specifier.imported.name === oldName\n ) {\n const isAliased = specifier.local && specifier.local.name !== oldName;\n\n // Always rename the imported name\n specifier.imported.name = newName;\n changes++;\n\n // Only rename the local name and track for usage replacement if NOT aliased\n if (!isAliased) {\n if (specifier.local) {\n specifier.local.name = newName;\n }\n // Track for usage replacement (only non-aliased imports)\n localNamesToReplace.add(oldName);\n }\n }\n });\n });\n\n // Second: Transform usages only for non-aliased imports\n localNamesToReplace.forEach(localName => {\n root.find(j.Identifier, { name: localName }).forEach(path => {\n // Skip identifiers that are part of import declarations\n const parent = path.parent;\n if (parent && parent.value.type === 'ImportSpecifier') {\n return;\n }\n\n path.value.name = newName;\n changes++;\n });\n });\n\n return changes;\n}\n\n/**\n * Transforms properties in constructor call arguments.\n *\n * @param j - JSCodeshift API\n * @param root - Root collection\n * @param className - Name of the class whose constructor to transform\n * @param propertyRenames - Map of old property names to new property names\n * @returns Number of properties renamed\n */\nexport function transformConstructorProperties(\n j: JSCodeshift,\n root: Collection<any>,\n className: string,\n propertyRenames: Record<string, string>,\n): number {\n let count = 0;\n\n root\n .find(j.NewExpression, {\n callee: { type: 'Identifier', name: className },\n })\n .forEach(path => {\n const args = path.value.arguments;\n if (args.length === 0) return;\n\n const firstArg = args[0];\n if (!firstArg || firstArg.type !== 'ObjectExpression' || !firstArg.properties) return;\n\n firstArg.properties.forEach((prop: any) => {\n if ((prop.type === 'Property' || prop.type === 'ObjectProperty') && prop.key?.type === 'Identifier') {\n const oldName = prop.key.name;\n const newName = propertyRenames[oldName];\n\n if (newName) {\n prop.key.name = newName;\n count++;\n }\n }\n });\n });\n\n return count;\n}\n"],"mappings":";AAaO,SAAS,oBAAoB,GAAgB,MAAuB,WAAgC;AACzG,QAAM,YAAY,oBAAI,IAAY;AAElC,OACG,KAAK,EAAE,eAAe;AAAA,IACr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B,UAAI,UAAU,OAAO,MAAM,SAAS,mBAAmB;AACrD;AAAA,MACF;AAEA,WAAK,MAAM,OAAO;AAClB;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AAED,SAAO;AACT;AAWO,SAAS,+BACd,GACA,MACA,WACA,iBACQ;AACR,MAAI,QAAQ;AAEZ,OACG,KAAK,EAAE,eAAe;AAAA,IACrB,QAAQ,EAAE,MAAM,cAAc,MAAM,UAAU;AAAA,EAChD,CAAC,EACA,QAAQ,UAAQ;AACf,UAAM,OAAO,KAAK,MAAM;AACxB,QAAI,KAAK,WAAW,EAAG;AAEvB,UAAM,WAAW,KAAK,CAAC;AACvB,QAAI,CAAC,YAAY,SAAS,SAAS,sBAAsB,CAAC,SAAS,WAAY;AAE/E,aAAS,WAAW,QAAQ,CAAC,SAAc;AACzC,WAAK,KAAK,SAAS,cAAc,KAAK,SAAS,qBAAqB,KAAK,KAAK,SAAS,cAAc;AACnG,cAAM,UAAU,KAAK,IAAI;AACzB,cAAM,UAAU,gBAAgB,OAAO;AAEvC,YAAI,SAAS;AACX,eAAK,IAAI,OAAO;AAChB;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AAEH,SAAO;AACT;","names":[]}
@@ -1,57 +1,9 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/codemods/lib/add-comment.ts
21
- var add_comment_exports = {};
22
- __export(add_comment_exports, {
23
- ERROR_PREFIX: () => ERROR_PREFIX,
24
- insertCommentOnce: () => insertCommentOnce
25
- });
26
- module.exports = __toCommonJS(add_comment_exports);
27
- var ERROR_PREFIX = "FIXME(mastra): ";
28
- function existsComment(comments, comment) {
29
- let hasComment = false;
30
- if (comments) {
31
- comments.forEach((commentNode) => {
32
- const currentComment = commentNode.value.trim();
33
- if (currentComment === comment) {
34
- hasComment = true;
35
- }
36
- });
37
- if (hasComment) {
38
- return true;
39
- }
40
- }
41
- return false;
42
- }
43
- function insertCommentOnce(node, j, comment) {
44
- const hasCommentInInlineComments = existsComment(node.comments, comment);
45
- const hasCommentInLeadingComments = existsComment(node.leadingComments, comment);
46
- if (!hasCommentInInlineComments && !hasCommentInLeadingComments) {
47
- node.comments = [...node.comments || [], j.commentBlock(` ${comment} `)];
48
- return true;
49
- }
50
- return false;
51
- }
52
- // Annotate the CommonJS export names for ESM import in node:
53
- 0 && (module.exports = {
1
+ import {
54
2
  ERROR_PREFIX,
55
3
  insertCommentOnce
56
- });
4
+ } from "../chunk-LGW3NUAJ.js";
5
+ export {
6
+ ERROR_PREFIX,
7
+ insertCommentOnce
8
+ };
57
9
  //# sourceMappingURL=add-comment.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/codemods/lib/add-comment.ts"],"sourcesContent":["import type { API, ASTPath } from 'jscodeshift';\n\nexport const ERROR_PREFIX = 'FIXME(mastra): ';\n\nfunction existsComment(comments: ASTPath<any>['node']['comments'], comment: string): boolean {\n let hasComment = false;\n\n if (comments) {\n comments.forEach((commentNode: any) => {\n const currentComment = commentNode.value.trim();\n if (currentComment === comment) {\n hasComment = true;\n }\n });\n\n if (hasComment) {\n return true;\n }\n }\n return false;\n}\n\nexport function insertCommentOnce(node: ASTPath<any>['node'], j: API['j'], comment: string): boolean {\n const hasCommentInInlineComments = existsComment(node.comments, comment);\n const hasCommentInLeadingComments = existsComment(node.leadingComments, comment);\n\n if (!hasCommentInInlineComments && !hasCommentInLeadingComments) {\n node.comments = [...(node.comments || []), j.commentBlock(` ${comment} `)];\n return true;\n }\n\n return false;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,IAAM,eAAe;AAE5B,SAAS,cAAc,UAA4C,SAA0B;AAC3F,MAAI,aAAa;AAEjB,MAAI,UAAU;AACZ,aAAS,QAAQ,CAAC,gBAAqB;AACrC,YAAM,iBAAiB,YAAY,MAAM,KAAK;AAC9C,UAAI,mBAAmB,SAAS;AAC9B,qBAAa;AAAA,MACf;AAAA,IACF,CAAC;AAED,QAAI,YAAY;AACd,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAEO,SAAS,kBAAkB,MAA4B,GAAa,SAA0B;AACnG,QAAM,6BAA6B,cAAc,KAAK,UAAU,OAAO;AACvE,QAAM,8BAA8B,cAAc,KAAK,iBAAiB,OAAO;AAE/E,MAAI,CAAC,8BAA8B,CAAC,6BAA6B;AAC/D,SAAK,WAAW,CAAC,GAAI,KAAK,YAAY,CAAC,GAAI,EAAE,aAAa,IAAI,OAAO,GAAG,CAAC;AACzE,WAAO;AAAA,EACT;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,45 +1,7 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/codemods/lib/create-transformer.ts
21
- var create_transformer_exports = {};
22
- __export(create_transformer_exports, {
23
- createTransformer: () => createTransformer
24
- });
25
- module.exports = __toCommonJS(create_transformer_exports);
26
- function createTransformer(transformFn) {
27
- return function transformer(fileInfo, api, options) {
28
- const j = api.jscodeshift;
29
- const root = j(fileInfo.source);
30
- const context = {
31
- j,
32
- root,
33
- hasChanges: false,
34
- messages: []
35
- };
36
- transformFn(fileInfo, api, options, context);
37
- context.messages.forEach((message) => api.report(message));
38
- return context.hasChanges ? root.toSource({ quote: "single" }) : null;
39
- };
40
- }
41
- // Annotate the CommonJS export names for ESM import in node:
42
- 0 && (module.exports = {
1
+ import {
43
2
  createTransformer
44
- });
3
+ } from "../chunk-JNFQ6J6B.js";
4
+ export {
5
+ createTransformer
6
+ };
45
7
  //# sourceMappingURL=create-transformer.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/codemods/lib/create-transformer.ts"],"sourcesContent":["// Copied from https://github.com/vercel/ai/blob/main/packages/codemod/src/codemods/lib/create-transformer.ts\n// License: Apache-2.0\n\nimport type { FileInfo, API, JSCodeshift, Collection } from 'jscodeshift';\n\ntype TransformerFunction = (fileInfo: FileInfo, api: API, options: any, context: TransformContext) => void;\n\nexport interface TransformContext {\n /**\n * The jscodeshift API object.\n */\n j: JSCodeshift;\n\n /**\n * The root collection of the AST.\n */\n root: Collection<any>;\n\n /**\n * Codemods should set this to true if they make any changes to the AST.\n */\n hasChanges: boolean;\n\n /**\n * Codemods can append messages to this array to report information to the user.\n */\n messages: string[];\n}\n\nexport function createTransformer(transformFn: TransformerFunction) {\n // Note the return type of this function is explicitly designed to conform to\n // the signature expected by jscodeshift. For more see\n // https://github.com/facebook/jscodeshift\n return function transformer(fileInfo: FileInfo, api: API, options: any) {\n const j = api.jscodeshift;\n const root = j(fileInfo.source);\n const context: TransformContext = {\n j,\n root,\n hasChanges: false,\n messages: [],\n };\n\n // Execute the transformation\n transformFn(fileInfo, api, options, context);\n\n // Report any messages\n context.messages.forEach(message => api.report(message));\n\n // Return the transformed source code if changes were made\n return context.hasChanges ? root.toSource({ quote: 'single' }) : null;\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA6BO,SAAS,kBAAkB,aAAkC;AAIlE,SAAO,SAAS,YAAY,UAAoB,KAAU,SAAc;AACtE,UAAM,IAAI,IAAI;AACd,UAAM,OAAO,EAAE,SAAS,MAAM;AAC9B,UAAM,UAA4B;AAAA,MAChC;AAAA,MACA;AAAA,MACA,YAAY;AAAA,MACZ,UAAU,CAAC;AAAA,IACb;AAGA,gBAAY,UAAU,KAAK,SAAS,OAAO;AAG3C,YAAQ,SAAS,QAAQ,aAAW,IAAI,OAAO,OAAO,CAAC;AAGvD,WAAO,QAAQ,aAAa,KAAK,SAAS,EAAE,OAAO,SAAS,CAAC,IAAI;AAAA,EACnE;AACF;","names":[]}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,23 @@
1
+ import {
2
+ isMemberExpressionOnInstance,
3
+ renameImportAndUsages,
4
+ renameMethod,
5
+ renameMethods,
6
+ trackClassInstances,
7
+ trackMultipleClassInstances,
8
+ transformConstructorProperties,
9
+ transformMethodCalls,
10
+ transformObjectProperties
11
+ } from "../chunk-PKCFDS7J.js";
12
+ export {
13
+ isMemberExpressionOnInstance,
14
+ renameImportAndUsages,
15
+ renameMethod,
16
+ renameMethods,
17
+ trackClassInstances,
18
+ trackMultipleClassInstances,
19
+ transformConstructorProperties,
20
+ transformMethodCalls,
21
+ transformObjectProperties
22
+ };
23
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,61 @@
1
+ import {
2
+ createTransformer
3
+ } from "../chunk-JNFQ6J6B.js";
4
+ import {
5
+ trackClassInstances
6
+ } from "../chunk-PKCFDS7J.js";
7
+
8
+ // src/codemods/v1/agent-abort-signal.ts
9
+ var agent_abort_signal_default = createTransformer((_fileInfo, _api, _options, context) => {
10
+ const { j, root } = context;
11
+ const agentInstances = trackClassInstances(j, root, "Agent");
12
+ if (agentInstances.size === 0) return;
13
+ root.find(j.CallExpression).forEach((path) => {
14
+ const { callee } = path.value;
15
+ if (callee.type !== "MemberExpression") return;
16
+ if (callee.object.type !== "Identifier") return;
17
+ if (!agentInstances.has(callee.object.name)) return;
18
+ const args = path.value.arguments;
19
+ if (args.length < 2) return;
20
+ const optionsArg = args[1];
21
+ if (!optionsArg || optionsArg.type !== "ObjectExpression") return;
22
+ if (!optionsArg.properties) return;
23
+ let modelSettingsIndex = -1;
24
+ const modelSettingsProp = optionsArg.properties.find((prop, index) => {
25
+ if ((prop.type === "Property" || prop.type === "ObjectProperty") && prop.key?.type === "Identifier" && prop.key.name === "modelSettings" && prop.value?.type === "ObjectExpression") {
26
+ modelSettingsIndex = index;
27
+ return true;
28
+ }
29
+ return false;
30
+ });
31
+ if (!modelSettingsProp || modelSettingsProp.value?.type !== "ObjectExpression") return;
32
+ if (modelSettingsIndex === -1) return;
33
+ const modelSettingsValue = modelSettingsProp.value;
34
+ let abortSignalProp;
35
+ const filteredProperties = modelSettingsValue.properties?.filter((prop) => {
36
+ if ((prop.type === "Property" || prop.type === "ObjectProperty") && prop.key?.type === "Identifier" && prop.key.name === "abortSignal") {
37
+ abortSignalProp = prop;
38
+ return false;
39
+ }
40
+ return true;
41
+ });
42
+ if (!abortSignalProp) return;
43
+ modelSettingsValue.properties = filteredProperties;
44
+ const newProperties = [];
45
+ optionsArg.properties.forEach((prop, index) => {
46
+ newProperties.push(prop);
47
+ if (index === modelSettingsIndex) {
48
+ newProperties.push(abortSignalProp);
49
+ }
50
+ });
51
+ optionsArg.properties = newProperties;
52
+ context.hasChanges = true;
53
+ });
54
+ if (context.hasChanges) {
55
+ context.messages.push("Moved abortSignal from modelSettings to top-level options in agent method calls");
56
+ }
57
+ });
58
+ export {
59
+ agent_abort_signal_default as default
60
+ };
61
+ //# sourceMappingURL=agent-abort-signal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/codemods/v1/agent-abort-signal.ts"],"sourcesContent":["import type {\n ObjectProperty,\n Property,\n ObjectExpression,\n SpreadElement,\n ObjectMethod,\n SpreadProperty,\n} from 'jscodeshift';\nimport { createTransformer } from '../lib/create-transformer';\nimport { trackClassInstances } from '../lib/utils';\n\n/**\n * Moves abortSignal from modelSettings to top-level options in agent method calls.\n *\n * ```ts\n * // Before:\n * agent.stream('prompt', {\n * modelSettings: { abortSignal: signal }\n * })\n *\n * // After:\n * agent.stream('prompt', {\n * modelSettings: {},\n * abortSignal: signal\n * })\n * ```\n */\nexport default createTransformer((_fileInfo, _api, _options, context) => {\n const { j, root } = context;\n\n // Track Agent instances\n const agentInstances = trackClassInstances(j, root, 'Agent');\n\n // Early return if no instances found\n if (agentInstances.size === 0) return;\n\n // Single pass: Find and transform agent method calls\n root.find(j.CallExpression).forEach(path => {\n const { callee } = path.value;\n if (callee.type !== 'MemberExpression') return;\n if (callee.object.type !== 'Identifier') return;\n\n // Only process if called on an Agent instance\n if (!agentInstances.has(callee.object.name)) return;\n\n const args = path.value.arguments;\n\n // We're looking for calls with an options object that has modelSettings\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 modelSettings property\n type ObjectProp = SpreadElement | Property | ObjectMethod | ObjectProperty | SpreadProperty;\n let modelSettingsIndex = -1;\n const modelSettingsProp = optionsArg.properties.find((prop, index) => {\n if (\n (prop.type === 'Property' || prop.type === 'ObjectProperty') &&\n prop.key?.type === 'Identifier' &&\n prop.key.name === 'modelSettings' &&\n prop.value?.type === 'ObjectExpression'\n ) {\n modelSettingsIndex = index;\n return true;\n }\n return false;\n }) as Property | ObjectProperty | undefined;\n\n if (!modelSettingsProp || modelSettingsProp.value?.type !== 'ObjectExpression') return;\n if (modelSettingsIndex === -1) return;\n\n const modelSettingsValue = modelSettingsProp.value as ObjectExpression;\n\n // Find abortSignal property inside modelSettings\n let abortSignalProp: Property | ObjectProperty | undefined;\n const filteredProperties = modelSettingsValue.properties?.filter(prop => {\n if (\n (prop.type === 'Property' || prop.type === 'ObjectProperty') &&\n prop.key?.type === 'Identifier' &&\n prop.key.name === 'abortSignal'\n ) {\n abortSignalProp = prop;\n return false; // Remove this property\n }\n return true; // Keep all other properties\n });\n\n if (!abortSignalProp) return;\n\n // Update modelSettings to not include abortSignal\n modelSettingsValue.properties = filteredProperties;\n\n // Rebuild the parent options properties with abortSignal right after modelSettings\n const newProperties: ObjectProp[] = [];\n optionsArg.properties.forEach((prop, index) => {\n newProperties.push(prop);\n if (index === modelSettingsIndex) {\n newProperties.push(abortSignalProp!);\n }\n });\n\n optionsArg.properties = newProperties;\n context.hasChanges = true;\n });\n\n if (context.hasChanges) {\n context.messages.push('Moved abortSignal from modelSettings to top-level options in agent method calls');\n }\n});\n"],"mappings":";;;;;;;;AA2BA,IAAO,6BAAQ,kBAAkB,CAAC,WAAW,MAAM,UAAU,YAAY;AACvE,QAAM,EAAE,GAAG,KAAK,IAAI;AAGpB,QAAM,iBAAiB,oBAAoB,GAAG,MAAM,OAAO;AAG3D,MAAI,eAAe,SAAS,EAAG;AAG/B,OAAK,KAAK,EAAE,cAAc,EAAE,QAAQ,UAAQ;AAC1C,UAAM,EAAE,OAAO,IAAI,KAAK;AACxB,QAAI,OAAO,SAAS,mBAAoB;AACxC,QAAI,OAAO,OAAO,SAAS,aAAc;AAGzC,QAAI,CAAC,eAAe,IAAI,OAAO,OAAO,IAAI,EAAG;AAE7C,UAAM,OAAO,KAAK,MAAM;AAGxB,QAAI,KAAK,SAA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