| 305 | } |
| 306 | |
| 307 | export function stabilizeStructuredContent(content: unknown): string { |
| 308 | if (typeof content === 'string') { |
| 309 | return stabilizeResponseOutput(content); |
| 310 | } |
| 311 | const stabilize = (c: unknown): unknown => { |
| 312 | if (typeof c === 'string') { |
| 313 | return stabilizeResponseOutput(c); |
| 314 | } |
| 315 | if (Array.isArray(c)) { |
| 316 | return c.map(item => stabilize(item)); |
| 317 | } |
| 318 | if (typeof c === 'object' && c !== null) { |
| 319 | const result: Record<string, unknown> = {}; |
| 320 | for (const [key, value] of Object.entries(c)) { |
| 321 | if (key === 'snapshotFilePath' && typeof value === 'string') { |
| 322 | result[key] = '<file>'; |
| 323 | } else { |
| 324 | result[key] = stabilize(value); |
| 325 | } |
| 326 | } |
| 327 | return result; |
| 328 | } |
| 329 | return c; |
| 330 | }; |
| 331 | |
| 332 | return JSON.stringify(stabilize(content), null, 2); |
| 333 | } |
| 334 | |
| 335 | export function stabilizeResponseOutput(text: unknown) { |
| 336 | if (typeof text !== 'string') { |