| 404 | } |
| 405 | |
| 406 | export function stabilizeStructuredContent(content: unknown): string { |
| 407 | if (typeof content === 'string') { |
| 408 | return stabilizeResponseOutput(content); |
| 409 | } |
| 410 | const stabilize = (c: unknown): unknown => { |
| 411 | if (typeof c === 'string') { |
| 412 | return stabilizeResponseOutput(c); |
| 413 | } |
| 414 | if (Array.isArray(c)) { |
| 415 | return c.map(item => stabilize(item)); |
| 416 | } |
| 417 | if (typeof c === 'object' && c !== null) { |
| 418 | const result: Record<string, unknown> = {}; |
| 419 | for (const [key, value] of Object.entries(c)) { |
| 420 | if (key === 'snapshotFilePath' && typeof value === 'string') { |
| 421 | result[key] = '<file>'; |
| 422 | } else { |
| 423 | result[key] = stabilize(value); |
| 424 | } |
| 425 | } |
| 426 | return result; |
| 427 | } |
| 428 | return c; |
| 429 | }; |
| 430 | |
| 431 | return JSON.stringify(stabilize(content), null, 2); |
| 432 | } |
| 433 | |
| 434 | export function stabilizeResponseOutput(text: unknown): string { |
| 435 | if (typeof text !== 'string') { |