Implement OpenAI-compatible provider (Story 7) and switch default to OpenRouter + GLM 5.2#2
Merged
Merged
Conversation
…uter + GLM 5.2 Implements Story 7 (OpenAI-compat adapter) and AD-4 (gateway pattern): - `OpenAICompatProvider` adapter with bearer auth, OpenRouter attribution headers, json_schema structured output with json_object fallback on schema-rejection 400 - Factory wired in `lib/providers/index.ts`; provider stub removed - Default changed to `openai_compat` + `z-ai/glm-5.2` via OpenRouter (~3-4× cheaper than Sonnet for this workload); existing users keep their configured provider - `https://openrouter.ai/*` added to optional_host_permissions - OpenAI-compatible section in options UI (base URL, model, write-only key, Test connection) - `openai_compat` added to production PROVIDER_OPTIONS - Secrets migration test for `openai_compat` in `lib/storage/secrets.test.ts` - LEARNINGS.md note on the default-provider change and calibration watch items - Existing component tests updated to reflect new default provider and extra key field Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
🤖 Agent-Generated PR
Closes #1
Agent Used: Claude Code (claude-sonnet-4-6)
Complexity: medium
Summary
OpenAICompatProvideradapter (Story 7 / AD-4) with bearer auth, OpenRouter attribution headers, andjson_schemastructured output with ajson_objectfallback triggered only on schema-rejection 400sDEFAULT_SETTINGS.activeProvidertoopenai_compat+z-ai/glm-5.2via OpenRouter (~3–4× cheaper than Claude Sonnet 4.6 for Slopwatch's prompt shape; verified slug and pricing from OpenRouter API)Implementation Notes
ProviderErrorwithkind: 'bad_response'and detail containingjson_schema,response_format, orunsupported, then retries once withjson_object. Any other 4xx propagates immediately — no silent fallback.HTTP-Referer: https://github.com/DisplaceTech/slopwatch,X-Title: Slopwatch— always sent, harmless on non-OpenRouter gateways.z-ai/glm-5.2at $1.20/$4.10 per 1M tokens (verified 2026-06-21),gpt-4o-miniat $0.15/$0.60; returnsundefinedfor unknown models.resetSettings(); existing users keep their configured provider via the v1 settings round-trip.#anthropic-keyselector.Changes
lib/providers/openai-compat.ts— new adapterlib/providers/openai-compat.test.ts— 11 unit tests covering happy path, json_object fallback, non-json_schema 400, auth, rate-limit, repair, validate, header assertions, URL trimming, and cost estimationlib/providers/index.ts— factory wired; stub removed;OpenAICompatProviderexportedlib/storage/settings.ts— default flipped toopenai_compat+z-ai/glm-5.2/ OpenRouterwxt.config.ts—https://openrouter.ai/*added tooptional_host_permissionsentrypoints/options/App.tsx— OpenAI-compatible section added;openai_compatin productionPROVIDER_OPTIONSlib/storage/secrets.test.ts— new: round-tripsopenai_compatsecret throughapplyPersistencePreferencedocs/LEARNINGS.md— note on provider default change and calibration watch itemstests/component/options.test.tsx,tests/component/popup.test.tsx— updated for new defaults and multiple key fieldsTesting
Automated:
130 passed (22 test files))Manual testing performed:
pnpm lint && pnpm typecheck && pnpm test && pnpm build && pnpm build:firefoxall cleanReview Checklist
Correctness
Code Quality
Security
Performance
Tests
Reviewer Notes
The GLM 5.2 model slug on OpenRouter is
z-ai/glm-5.2(verified fromhttps://openrouter.ai/api/v1/models). There's a// TODO(slopwatch):note to evaluate the canonical timestamped slug once it stabilizes. The pricing table ($1.20/$4.10 per 1M tokens) was verified from the same API on 2026-06-21.🤖 Generated with Claude Code