{"version":3,"file":"agent-to-step.mjs","names":[],"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,IAAA,wBAAe,mBAAmB,UAAU,KAAK,SAAS,YAAY;CACpE,MAAM,EAAE,GAAG,SAAS;CAEpB,MAAM,kBACJ;CAGF,MAAM,iCAAiB,IAAI,IAAY;CAEvC,KACG,KAAK,EAAE,eAAe,EACrB,QAAQ;EACN,MAAM;EACN,MAAM;CACR,EACF,CAAC,CAAC,CACD,SAAQ,SAAQ;EACf,MAAM,SAAS,KAAK,OAAO;EAC3B,IAAI,OAAO,SAAS,wBAAwB,OAAO,GAAG,SAAS,cAC7D,eAAe,IAAI,OAAO,GAAG,IAAI;CAErC,CAAC;CAGH,KACG,KAAK,EAAE,cAAc,CAAC,CACtB,QAAO,SAAQ;EACd,MAAM,EAAE,WAAW,KAAK;EACxB,IAAI,OAAO,SAAS,oBAAoB,OAAO;EAC/C,IAAI,OAAO,OAAO,SAAS,cAAc,OAAO;EAChD,IAAI,OAAO,SAAS,SAAS,cAAc,OAAO;EAGlD,IAAI,CAAC,eAAe,IAAI,OAAO,OAAO,IAAI,GAAG,OAAO;EAGpD,OAAO,OAAO,SAAS,SAAS;CAClC,CAAC,CAAC,CACD,SAAQ,SAAQ;EAEf,IAAI,SAAS,KAAK;EAClB,OAAO,UAAU,OAAO,MAAM,SAAS,yBAAyB,OAAO,MAAM,SAAS,uBACpF,SAAS,OAAO;EAGlB,IAAI,UAAU,OAAO,OAAO;GAE1B,IAAI,aAAa,OAAO;GACxB,IAAI,OAAO,UAAU,OAAO,OAAO,MAAM,SAAS,0BAChD,aAAa,OAAO,OAAO;GAK7B,IADc,kBAAkB,YAAY,GAAG,eACvC,GACN,QAAQ,aAAa;EAEzB;CACF,CAAC;CAEH,IAAI,QAAQ,YACV,QAAQ,SAAS,KAAK,mBAAmB,SAAS,KAAK,wCAAwC;AAEnG,CAAC"}