{"version":3,"file":"client-get-memory-thread.mjs","names":[],"sources":["../../../src/codemods/v1/client-get-memory-thread.ts"],"sourcesContent":["import { createTransformer } from '../lib/create-transformer';\n\n/**\n * Updates getMemoryThread method to use object parameter instead of positional arguments.\n * This provides a more consistent API across memory methods.\n *\n * Before:\n * const thread = await client.getMemoryThread(threadId, agentId);\n *\n * After:\n * const thread = await client.getMemoryThread({ threadId, agentId });\n */\nexport default createTransformer((fileInfo, api, options, context) => {\n  const { j, root } = context;\n\n  // Track MastraClient instances\n  const clientInstances = new Set<string>();\n\n  // Find MastraClient instances\n  root\n    .find(j.NewExpression, {\n      callee: {\n        type: 'Identifier',\n        name: 'MastraClient',\n      },\n    })\n    .forEach(path => {\n      const parent = path.parent.value;\n      if (parent.type === 'VariableDeclarator' && parent.id.type === 'Identifier') {\n        clientInstances.add(parent.id.name);\n      }\n    });\n\n  // Find client.getMemoryThread() 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      // Check if it's getMemoryThread called on a MastraClient instance\n      return clientInstances.has(callee.object.name) && callee.property.name === 'getMemoryThread';\n    })\n    .forEach(path => {\n      const args = path.value.arguments;\n\n      // Check if it has exactly 2 arguments (threadId, agentId)\n      if (args.length === 2) {\n        const threadIdArg = args[0];\n        const agentIdArg = args[1];\n\n        if (!threadIdArg || !agentIdArg) return;\n\n        // Skip if arguments are spread elements\n        if (threadIdArg.type === 'SpreadElement' || agentIdArg.type === 'SpreadElement') return;\n\n        // Helper to create property with proper typing\n        type ExpressionKind = Exclude<typeof threadIdArg, { type: 'SpreadElement' }>;\n        type PropertyNode = ReturnType<typeof j.property>;\n\n        const createProperty = (key: string, value: ExpressionKind, useShorthand: boolean): PropertyNode => {\n          const prop = j.property('init', j.identifier(key), value);\n          if (useShorthand) {\n            prop.shorthand = true;\n          }\n          return prop;\n        };\n\n        // Create object properties using jscodeshift builders\n        const properties: PropertyNode[] = [];\n\n        // Check if we can use shorthand for threadId\n        const threadIdShorthand = threadIdArg.type === 'Identifier' && threadIdArg.name === 'threadId';\n        properties.push(createProperty('threadId', threadIdArg, threadIdShorthand));\n\n        // Check if we can use shorthand for agentId\n        const agentIdShorthand = agentIdArg.type === 'Identifier' && agentIdArg.name === 'agentId';\n        properties.push(createProperty('agentId', agentIdArg, agentIdShorthand));\n\n        // Replace with single object argument\n        path.value.arguments = [j.objectExpression(properties)];\n        context.hasChanges = true;\n      }\n    });\n\n  if (context.hasChanges) {\n    context.messages.push(\n      'Updated getMemoryThread method calls to use object parameter instead of positional arguments',\n    );\n  }\n});\n"],"mappings":";;;;;;;;;;;;AAYA,IAAA,mCAAe,mBAAmB,UAAU,KAAK,SAAS,YAAY;CACpE,MAAM,EAAE,GAAG,SAAS;CAGpB,MAAM,kCAAkB,IAAI,IAAY;CAGxC,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,gBAAgB,IAAI,OAAO,GAAG,IAAI;CAEtC,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,OAAO,gBAAgB,IAAI,OAAO,OAAO,IAAI,KAAK,OAAO,SAAS,SAAS;CAC7E,CAAC,CAAC,CACD,SAAQ,SAAQ;EACf,MAAM,OAAO,KAAK,MAAM;EAGxB,IAAI,KAAK,WAAW,GAAG;GACrB,MAAM,cAAc,KAAK;GACzB,MAAM,aAAa,KAAK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