| 374 | } |
| 375 | |
| 376 | export function stabilizeStructuredContent(content: unknown): string { |
| 377 | if (typeof content === 'string') { |
| 378 | return stabilizeResponseOutput(content); |
| 379 | } |
| 380 | const stabilize = (c: unknown): unknown => { |
| 381 | if (typeof c === 'string') { |
| 382 | return stabilizeResponseOutput(c); |
| 383 | } |
| 384 | if (Array.isArray(c)) { |
| 385 | return c.map(item => stabilize(item)); |
| 386 | } |
| 387 | if (typeof c === 'object' && c !== null) { |
| 388 | const result: Record<string, unknown> = {}; |
| 389 | for (const [key, value] of Object.entries(c)) { |
| 390 | if (key === 'snapshotFilePath' && typeof value === 'string') { |
| 391 | result[key] = '<file>'; |
| 392 | } else { |
| 393 | result[key] = stabilize(value); |
| 394 | } |
| 395 | } |
| 396 | return result; |
| 397 | } |
| 398 | return c; |
| 399 | }; |
| 400 | |
| 401 | return JSON.stringify(stabilize(content), null, 2); |
| 402 | } |
| 403 | |
| 404 | export function stabilizeResponseOutput(text: unknown): string { |
| 405 | if (typeof text !== 'string') { |