| 296 | } |
| 297 | |
| 298 | export function stabilizeStructuredContent(content: unknown): unknown { |
| 299 | if (typeof content === 'string') { |
| 300 | return stabilizeResponseOutput(content); |
| 301 | } |
| 302 | if (Array.isArray(content)) { |
| 303 | return content.map(item => stabilizeStructuredContent(item)); |
| 304 | } |
| 305 | if (typeof content === 'object' && content !== null) { |
| 306 | const result: Record<string, unknown> = {}; |
| 307 | for (const [key, value] of Object.entries(content)) { |
| 308 | if (key === 'snapshotFilePath' && typeof value === 'string') { |
| 309 | result[key] = '<file>'; |
| 310 | } else { |
| 311 | result[key] = stabilizeStructuredContent(value); |
| 312 | } |
| 313 | } |
| 314 | return result; |
| 315 | } |
| 316 | return content; |
| 317 | } |
| 318 | |
| 319 | export function stabilizeResponseOutput(text: unknown) { |
| 320 | if (typeof text !== 'string') { |