( exchanges: readonly CapturedExchange[], state: ReplayingCapiProxyState, )
| 484 | } |
| 485 | |
| 486 | async function writeCapturesToDisk( |
| 487 | exchanges: readonly CapturedExchange[], |
| 488 | state: ReplayingCapiProxyState, |
| 489 | ) { |
| 490 | const data = await transformHttpExchanges( |
| 491 | exchanges, |
| 492 | state.workDir, |
| 493 | state.toolResultNormalizers, |
| 494 | ); |
| 495 | const preservedErrors = state.storedData?.errors; |
| 496 | if (preservedErrors && preservedErrors.length > 0) { |
| 497 | data.errors = preservedErrors; |
| 498 | data.models = [ |
| 499 | ...new Set([ |
| 500 | ...(state.storedData?.models ?? []), |
| 501 | ...data.models, |
| 502 | ...preservedErrors |
| 503 | .map((error) => error.model) |
| 504 | .filter((model): model is string => model !== undefined), |
| 505 | ]), |
| 506 | ]; |
| 507 | } |
| 508 | if (data.conversations.length > 0) { |
| 509 | let yamlText = yaml.stringify(data, { lineWidth: 120 }); |
| 510 | |
| 511 | // We have to normalize line endings explicitly, because yaml.stringify uses Unix-style even on Windows, |
| 512 | // and Git will restore the files with CRLF on Windows so they will appear to be changed |
| 513 | if (process.platform === "win32") { |
| 514 | yamlText = yamlText.replace(/\r?\n/g, "\r\n"); |
| 515 | } |
| 516 | |
| 517 | await mkdir(path.dirname(state.filePath), { recursive: true }); |
| 518 | await writeFileIfDifferent(state.filePath, yamlText); |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | /** |
| 523 | * Produces a human-readable explanation of why no stored conversation matched |
no test coverage detected
searching dependent graphs…