Skip to content

feat(ai-gateway): map custom LLM thought content - #5133

Merged
chrarnoldus merged 6 commits into
mainfrom
thought-content-mapping
Aug 7, 2026
Merged

chrarnoldus merged 6 commits into
mainfrom
thought-content-mapping

Conversation

@chrarnoldus

Copy link
Copy Markdown
Contributor

Summary

  • add a validated thought_content_mapping property path to custom LLM configuration
  • expose only response-safe transform settings to the response pipeline
  • move marked streamed delta content into reasoning_content while preserving unmarked deltas

Testing

  • pnpm --filter web exec jest --runInBand --forceExit --runTestsByPath src/lib/ai-gateway/experiments/build-direct-provider.test.ts src/lib/rewriteModelResponse.test.ts src/app/api/openrouter/[...path]/route.test.ts
  • pnpm --filter web typecheck

@chrarnoldus chrarnoldus self-assigned this Aug 7, 2026
@kilo-code-bot

kilo-code-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

Incremental review of commit 78e55ef ("require nullable transform fields"): ProviderResponseTransforms.thoughtContentMapping is now required-but-nullable and the rewriteModelResponse responseTransforms parameter lost its default; the sole production caller (route.ts:1037) and all Provider constructions already pass explicit values, the only ProviderResponseTransforms object literal (build-direct-provider.ts:206) always includes the property, consumption remains null-safe via optional chaining, and all test call sites pass an explicit argument — no runtime, security, or type-consistency issues introduced.

Files Reviewed (3 files)
  • apps/web/src/lib/ai-gateway/providers/types.ts
  • apps/web/src/lib/rewriteModelResponse.ts
  • apps/web/src/lib/rewriteModelResponse.test.ts
Previous Review Summaries (3 snapshots, latest commit 9a9614b)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 9a9614b)

Status: No Issues Found | Recommendation: Merge

Executive Summary

Incremental review of commit 9a9614b ("require response transform argument"): the responseTransforms parameter of rewriteModelResponse_ChatCompletions is now required-but-nullable, the sole production call chain (rewriteModelResponse → line 885) passes it explicitly, consumption remains null-safe via optional chaining, and all test call sites were updated with an explicit fifth argument — no runtime, security, or memory-leak issues introduced.

Files Reviewed (2 files)
  • apps/web/src/lib/rewriteModelResponse.ts
  • apps/web/src/lib/rewriteModelResponse.test.ts

Previous review (commit 4c6b7ad)

Status: No Issues Found | Recommendation: Merge

Executive Summary

Incremental review of the responseTransforms type refactor (optional undefined → required null): all Provider constructions (6 provider definitions, direct-BYOK, build-direct-provider, and both test mocks) now set responseTransforms: null, the rewriteModelResponse/rewriteModelResponse_ChatCompletions signatures default to null with unchanged falsy optional-chaining consumption, and the updated tests assert the new null behavior — runtime semantics are fully preserved and no memory-leak surface was introduced.

Files Reviewed (8 files)
  • apps/web/src/app/api/openrouter/[...path]/route.test.ts
  • apps/web/src/lib/ai-gateway/experiments/build-direct-provider.ts
  • apps/web/src/lib/ai-gateway/experiments/build-direct-provider.test.ts
  • apps/web/src/lib/ai-gateway/providers/get-provider.ts
  • apps/web/src/lib/ai-gateway/providers/provider-definitions.ts
  • apps/web/src/lib/ai-gateway/providers/types.ts
  • apps/web/src/lib/ai-gateway/providers/upstream-request.generation.test.ts
  • apps/web/src/lib/rewriteModelResponse.ts

Previous review (commit a33dd92)

Status: No Issues Found | Recommendation: Merge

Reviewed the thought-content-mapping feature end to end: the property path is schema-validated (rejecting __proto__/constructor/prototype and empty segments), read-only at traversal time, exposed as an optional provider transform, and applied only to streamed chat-completions deltas as described; the broadened per-choice loop and optional signature parameters are backwards compatible, and no memory-leak surface (intervals, listeners, retained buffers) was introduced.

Files Reviewed (8 files)
  • apps/web/src/app/api/openrouter/[...path]/route.ts
  • apps/web/src/app/api/openrouter/[...path]/route.test.ts
  • apps/web/src/lib/ai-gateway/experiments/build-direct-provider.ts
  • apps/web/src/lib/ai-gateway/experiments/build-direct-provider.test.ts
  • apps/web/src/lib/ai-gateway/providers/types.ts
  • apps/web/src/lib/rewriteModelResponse.ts
  • apps/web/src/lib/rewriteModelResponse.test.ts
  • packages/db/src/schema-types.ts

Reviewed by kimi-k3 · Input: 25.3K · Output: 2.5K · Cached: 94.2K

Review guidance: REVIEW.md from base branch main

@chrarnoldus
chrarnoldus merged commit bac516f into main Aug 7, 2026
42 of 44 checks passed
@chrarnoldus
chrarnoldus deleted the thought-content-mapping branch August 7, 2026 12:50
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