Read linked issue #843 and PR details.
UnderstandReviewed relevant source files.
UnderstandChecked changelogs.
UnderstandAdded changelog entry.
EditResolved conflicts and fixed test file.
EditYou are given one or more GitHub PR URLs: https://github.com/badlogic/pi-mono/pull/859
For each PR URL, do the following in order:
packages/*/CHANGELOG.md files. Report whether an entry exists. If missing, state that a changelog entry is required before merge and that you will add it if the user decides to merge. Follow the changelog format rules in AGENTS.md. Verify:
### Breaking Changes, ### Added, ### Fixed, etc.)Fixed foo ([#123](https://github.com/badlogic/pi-mono/pull/123) by [@user](https://github.com/user))### Breaking Changes, not just ### FixedOutput format per PR: PR: Changelog:
If no issues are found, say so under Bad and Ugly.
Now let me read issue #843 that's referenced in the PR:
Now let me read the relevant source files to fully understand the implementation:
Now let me check the changelogs:
Now let me check the documentation that might need updates:
Now I have all the relevant context. Let me check if there's any related documentation that should be updated:
Let me verify the current state of the types by reading the end of the openai-completions file to understand the full context of the changes:
Now I have the complete picture. Here's my review:
PR: https://github.com/badlogic/pi-mono/pull/859
Changelog:
packages/ai/CHANGELOG.md before merge. The entry should be:
### Added under ## [Unreleased]Added OpenRouter provider routing support for custom models via \openRouterRouting` compat field (#859 by @v01dpr1mr0s3)`Good:
openRouterRouting is added to OpenAICompletionsCompat which is the right home for OpenAI-compatible API quirksmodel.baseUrl.includes("openrouter.ai")) rather than provider name, which correctly handles custom "virtual providers" with OpenRouter-specific labels (as the PR author notes)model-registry.ts updated to allow the new field without explodingonly and order together aligns with the author's testing findings about OpenRouter ignoring only aloneBad:
openRouterRouting in getCompat() return object: In openai-completions.ts, the detectCompat() function adds openRouterRouting: {} at line 733, and getCompat() adds openRouterRouting: model.compat.openRouterRouting ?? {} at line 757, but the PR diff shows these are being added. However, looking at the full file, the getCompat() function is missing the openRouterRouting merge logic. Wait, looking again at the diff, it does add line 757. This looks correct.provider field is correctly added to the params when openRouterRouting is set.as any: Line 418 uses (params as any).provider = model.compat.openRouterRouting; which bypasses TypeScript type checking. This is acceptable given OpenAI's SDK types don't include OpenRouter-specific fields.Ugly:
Questions or Assumptions:
provider field format matches what's described in their docs. The PR author has tested this manually.openRouterRouting is set on a non-OpenRouter model? The baseUrl check guards against this, but the compat field could still be set incorrectly. Not a real concern given this is for custom models where the user controls the config.Change summary:
packages/ai/src/types.ts: Added OpenRouterRouting interface with only and order fields. Added openRouterRouting optional field to OpenAICompletionsCompat.packages/ai/src/providers/openai-completions.ts: Added logic in buildParams() to inject provider field into request params when model uses OpenRouter and has openRouterRouting set. Added openRouterRouting to detectCompat() defaults and getCompat() merge logic.packages/coding-agent/src/core/model-registry.ts: Added TypeBox schema for OpenRouterRouting and added it to OpenAICompletionsCompatSchema for validation.Tests:
packages/ai/test/ to verify the routing parameters are correctly passed to OpenRouter requests.Documentation:
packages/coding-agent/README.md does not need modification. The existing "Custom Models and Providers" section covers the compat field, and this PR adds a new sub-field. However, documenting the openRouterRouting field would be beneficial for discoverability. A brief mention in the compat field section would help users find this feature.fuck it merge it via gh cli,
I see the conflict. The PR was based on an older version that didn't have the newer compat fields. Let me resolve it:
manually went in and resolved, check if correct
Looks correct. The conflict is resolved properly: all the existing fields are kept (requiresToolResultName, requiresAssistantAfterToolResult, etc.) and openRouterRouting is added at the end.
There's a type error. The test file needs openRouterRouting added to the compat object:
Now let me add the changelog entry:
Done. PR #859 has been:
openRouterRouting field in the test filepackages/ai/CHANGELOG.md