{"version":3,"file":"agent-abort-signal.mjs","names":[],"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,IAAA,6BAAe,mBAAmB,WAAW,MAAM,UAAU,YAAY;CACvE,MAAM,EAAE,GAAG,SAAS;CAGpB,MAAM,iBAAiB,oBAAoB,GAAG,MAAM,OAAO;CAG3D,IAAI,eAAe,SAAS,GAAG;CAG/B,KAAK,KAAK,EAAE,cAAc,CAAC,CAAC,SAAQ,SAAQ;EAC1C,MAAM,EAAE,WAAW,KAAK;EACxB,IAAI,OAAO,SAAS,oBAAoB;EACxC,IAAI,OAAO,OAAO,SAAS,cAAc;EAGzC,IAAI,CAAC,eAAe,IAAI,OAAO,OAAO,IAAI,GAAG;EAE7C,MAAM,OAAO,KAAK,MAAM;EAGxB,IAAI,KAAK,SAAS,GAAG;EAErB,MAAM,aAAa,KAAK;EACxB,IAAI,CAAC,cAAc,WAAW,SAAS,oBAAoB;EAC3D,IAAI,CAAC,WAAW,YAAY;EAI5B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