{"version":3,"file":"memory-readonly-to-options.mjs","names":[],"sources":["../../../src/codemods/v1/memory-readonly-to-options.ts"],"sourcesContent":["import { createTransformer } from '../lib/create-transformer';\n\n/**\n * Moves memory.readOnly to memory.options.readOnly in agent.stream() and agent.generate() calls.\n * The top-level readOnly property has been removed in favor of options.readOnly.\n *\n * Before:\n * agent.stream('Hello', {\n *   memory: {\n *     thread: threadId,\n *     resource: resourceId,\n *     readOnly: true,\n *   },\n * });\n *\n * After:\n * agent.stream('Hello', {\n *   memory: {\n *     thread: threadId,\n *     resource: resourceId,\n *     options: {\n *       readOnly: true,\n *     },\n *   },\n * });\n */\nexport default createTransformer((_fileInfo, _api, _options, context) => {\n  const { j, root } = context;\n\n  // Find all object expressions that have a 'memory' property\n  root.find(j.ObjectExpression).forEach(path => {\n    const memoryProp = path.value.properties.find(\n      (prop: any) =>\n        (prop.type === 'Property' || prop.type === 'ObjectProperty') &&\n        prop.key &&\n        prop.key.type === 'Identifier' &&\n        prop.key.name === 'memory',\n    ) as any;\n\n    if (!memoryProp || !memoryProp.value || memoryProp.value.type !== 'ObjectExpression') {\n      return;\n    }\n\n    const memoryObj = memoryProp.value;\n    const properties = memoryObj.properties;\n\n    // Find readOnly property\n    const readOnlyPropIndex = properties.findIndex(\n      (prop: any) =>\n        (prop.type === 'Property' || prop.type === 'ObjectProperty') &&\n        prop.key &&\n        prop.key.type === 'Identifier' &&\n        prop.key.name === 'readOnly',\n    );\n\n    if (readOnlyPropIndex === -1) {\n      return;\n    }\n\n    const readOnlyProp = properties[readOnlyPropIndex] as any;\n    const readOnlyValue = readOnlyProp.value;\n\n    // Remove readOnly from top level\n    properties.splice(readOnlyPropIndex, 1);\n\n    // Find or create options property\n    let optionsProp = properties.find(\n      (prop: any) =>\n        (prop.type === 'Property' || prop.type === 'ObjectProperty') &&\n        prop.key &&\n        prop.key.type === 'Identifier' &&\n        prop.key.name === 'options',\n    ) as any;\n\n    if (optionsProp && optionsProp.value && optionsProp.value.type === 'ObjectExpression') {\n      // Add readOnly to existing options\n      optionsProp.value.properties.push(j.property('init', j.identifier('readOnly'), readOnlyValue));\n    } else {\n      // Create new options object with readOnly\n      const newOptionsProp = j.property(\n        'init',\n        j.identifier('options'),\n        j.objectExpression([j.property('init', j.identifier('readOnly'), readOnlyValue)]),\n      );\n      properties.push(newOptionsProp);\n    }\n\n    context.hasChanges = true;\n  });\n\n  if (context.hasChanges) {\n    context.messages.push('Moved memory.readOnly to memory.options.readOnly');\n  }\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,IAAA,qCAAe,mBAAmB,WAAW,MAAM,UAAU,YAAY;CACvE,MAAM,EAAE,GAAG,SAAS;CAGpB,KAAK,KAAK,EAAE,gBAAgB,CAAC,CAAC,SAAQ,SAAQ;EAC5C,MAAM,aAAa,KAAK,MAAM,WAAW,MACtC,UACE,KAAK,SAAS,cAAc,KAAK,SAAS,qBAC3C,KAAK,OACL,KAAK,IAAI,SAAS,gBAClB,KAAK,IAAI,SAAS,QACtB;EAEA,IAAI,CAAC,cAAc,CAAC,WAAW,SAAS,WAAW,MAAM,SAAS,oBAChE;EAIF,MAAM,aADY,WAAW,MACA;EAG7B,MAAM,oBAAoB,WAAW,WAClC,UACE,KAAK,SAAS,cAAc,KAAK,SAAS,qBAC3C,KAAK,OACL,KAAK,IAAI,SAAS,gBAClB,KAAK,IAAI,SAAS,UACtB;EAEA,IAAI,sBAAsB,IACxB;EAIF,MAAM,gBADe,WAAW,kBACE,CAAC;EAGnC,WAAW,OAAO,mBAAmB,CAAC;EAGtC,IAAI,cAAc,WAAW,MAC1B,UACE,KAAK,SAAS,cAAc,KAAK,SAAS,qBAC3C,KAAK,OACL,KAAK,IAAI,SAAS,gBAClB,KAAK,IAAI,SAAS,SACtB;EAEA,IAAI,eAAe,YAAY,SAAS,YAAY,MAAM,SAAS,oBAEjE,YAAY,MAAM,WAAW,KAAK,EAAE,SAAS,QAAQ,EAAE,WAAW,UAAU,GAAG,aAAa,CAAC;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