Skip to content

[AISAGE-789] refactor(ai-gateway): split rewriteModelResponse by API kind - #8892

Merged
chrarnoldus merged 1 commit into
mainfrom
kilo/great-frame-cg9
Oct 26, 2026
Merged

chrarnoldus merged 1 commit into
mainfrom
kilo/great-frame-cg9

Conversation

@chrarnoldus

@chrarnoldus chrarnoldus commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

rewriteModelResponse.ts had grown to ~1000 lines. This PR splits it by API kind, using the same naming as the existing processUsage.*.ts files:

File Contents
rewriteModelResponse.ts Entry point: request-log capture (api_request_log), logUnrewrittenResponse, redactApiRequestLogRequest, and the rewriteModelResponse dispatcher
rewriteModelResponse.shared.ts RequestLogCapture/RewriteResponseParams types, read-error mapping, readResponseText, the SSE pump (rewriteSseStream), progress/terminal-event logging, OpenRouter rewriteUsage
rewriteModelResponse.chatCompletions.ts rewriteModelResponse_ChatCompletions
rewriteModelResponse.messages.ts rewriteModelResponse_Messages and Anthropic usage types
rewriteModelResponse.responses.ts rewriteModelResponse_Responses

The code was moved without changes. Only imports and export keywords differ. Log prefixes ([rewriteModelResponse] ...) are unchanged. External consumers (handlers/llm-proxy.ts and its test mock) still import rewriteModelResponse and logUnrewrittenResponse from the same module. The rewrite test now imports the per-kind functions from their new modules.

Verification

  • Moved code is identical to the original: compared the original file with the new files after removing imports, export, and blank lines.
  • pnpm --filter @kilocode/web-shared typecheck: passes
  • oxlint --config .oxlintrc.json on the changed files: no findings
  • oxfmt on the changed files; git diff --check is clean
  • jest rewriteModelResponse.test.ts handlers/llm-proxy.test.ts (from apps/web): 302/302 pass

Context

Tracked in AISAGE-789.

This behavior-preserving refactor is preparation for:

Splitting the response rewriting by API kind makes those follow-up changes easier to implement and review. This PR does not implement or close either issue.

@chrarnoldus chrarnoldus self-assigned this Oct 25, 2026
@kilo-code-bot

kilo-code-bot Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

Refactor of rewriteModelResponse.ts into per-API-kind modules verified as a faithful code move; no behavior changes, broken imports, or new resource leaks found across the 6 changed files.

Assumptions: [INFERENCE] typecheck and Jest results were not re-run (read-only review); verified by diffing the extracted original functions against the new modules, which matched exactly except for added export keywords.

Files Reviewed (6 files)
  • packages/web-shared/src/lib/ai-gateway/rewriteModelResponse.ts - no issues
  • packages/web-shared/src/lib/ai-gateway/rewriteModelResponse.shared.ts - no issues (extracted helpers byte-identical to original; setInterval progress logger still cleared in finally)
  • packages/web-shared/src/lib/ai-gateway/rewriteModelResponse.chatCompletions.ts - no issues (identical)
  • packages/web-shared/src/lib/ai-gateway/rewriteModelResponse.messages.ts - no issues (identical)
  • packages/web-shared/src/lib/ai-gateway/rewriteModelResponse.responses.ts - no issues (identical)
  • packages/web-shared/src/lib/ai-gateway/rewriteModelResponse.test.ts - no issues (per-kind imports updated; module-level jest.mock targets are shared dependencies and still apply)

Verification performed: removed exported types (RequestLogCapture, RewriteResponseParams, RewriteChatCompletionsResponseParams) have no remaining consumers (@kilocode/web-shared is private, llm-proxy.ts/llm-proxy.test.ts still import from the unchanged entry point); no circular imports between the new modules and rewriteModelResponse.ts; dispatcher, request-log capture, and redaction code unchanged.


Reviewed by deepseek-flash-latest · Input: 53.7K · Output: 7.6K · Cached: 709.4K

Review guidance: REVIEW.md from base branch main

@chrarnoldus chrarnoldus changed the title refactor(ai-gateway): split rewriteModelResponse by API kind [AISAGE-789] refactor(ai-gateway): split rewriteModelResponse by API kind Oct 26, 2026
@chrarnoldus
chrarnoldus added this pull request to the merge queue Oct 26, 2026
Merged via the queue into main with commit 079da62 Oct 26, 2026
57 checks passed
@chrarnoldus
chrarnoldus deleted the kilo/great-frame-cg9 branch October 26, 2026 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants