You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[AISAGE-789] refactor(ai-gateway): split rewriteModelResponse by API kind - #8892
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.
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.
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.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
rewriteModelResponse.tshad grown to ~1000 lines. This PR splits it by API kind, using the same naming as the existingprocessUsage.*.tsfiles:rewriteModelResponse.tsapi_request_log),logUnrewrittenResponse,redactApiRequestLogRequest, and therewriteModelResponsedispatcherrewriteModelResponse.shared.tsRequestLogCapture/RewriteResponseParamstypes, read-error mapping,readResponseText, the SSE pump (rewriteSseStream), progress/terminal-event logging, OpenRouterrewriteUsagerewriteModelResponse.chatCompletions.tsrewriteModelResponse_ChatCompletionsrewriteModelResponse.messages.tsrewriteModelResponse_Messagesand Anthropic usage typesrewriteModelResponse.responses.tsrewriteModelResponse_ResponsesThe code was moved without changes. Only imports and
exportkeywords differ. Log prefixes ([rewriteModelResponse] ...) are unchanged. External consumers (handlers/llm-proxy.tsand its test mock) still importrewriteModelResponseandlogUnrewrittenResponsefrom the same module. The rewrite test now imports the per-kind functions from their new modules.Verification
export, and blank lines.pnpm --filter @kilocode/web-shared typecheck: passesoxlint --config .oxlintrc.jsonon the changed files: no findingsoxfmton the changed files;git diff --checkis cleanjest rewriteModelResponse.test.ts handlers/llm-proxy.test.ts(fromapps/web): 302/302 passContext
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.