Skip to content

feat: route all AI inference through OpenRouter GLM 5.3 Flash - #43

Merged
Programcode merged 7 commits into
mainfrom
codex/openrouter-glm53-20260918
Sep 18, 2026
Merged

Programcode merged 7 commits into
mainfrom
codex/openrouter-glm53-20260918

Conversation

@Programcode

@Programcode Programcode commented Sep 18, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • route every real AI request through OpenRouter
  • make z-ai/glm-5.3-flash the only selectable/default model
  • migrate legacy settings and remove stored client provider credentials
  • use OpenRouter reported usage cost and keep cancelled work non-billable
  • update pricing and privacy copy in English, Spanish, and Hungarian

Verification

  • npm run verify on Node 22: 1,018 Vitest, 172 Edge, build, 134 Chromium
  • pgTAP: 27 passed
  • WebKit: 67 passed
  • release reviewer: no remaining Critical or Important findings

Summary by CodeRabbit

  • New Features

    • AI requests now use OpenRouter with GLM 5.3 Flash as the available model.
    • Pro users can choose low, medium, or high reasoning effort; trial users remain on low reasoning.
    • Model and reasoning settings are validated and migrated to supported defaults.
    • Usage and provider-reported costs are tracked, with incomplete costs shown as unknown.
  • Documentation

    • Updated pricing, privacy, FAQ, upgrade, and setup content across supported languages to reflect the new AI service and limits.

@vercel

vercel Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
debate-navigator Ready Ready Preview Sep 18, 2026 3:56pm UTC

Copilot AI lite review requested due to automatic review settings September 18, 2026 15:55
@coderabbitai

coderabbitai Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Free

Run ID: aab73fdf-1cc1-4d85-bb67-88ea265fd057

📥 Commits

Reviewing files that changed from the base of the PR and between da14bc9 and d87759f.

📒 Files selected for processing (37)
  • docs/architecture.md
  • package.json
  • src/components/ModelSelector.tsx
  • src/lib/ai/client.ts
  • src/lib/ai/providers/types.ts
  • src/lib/ai/streaming.ts
  • src/lib/stores/settings-store.ts
  • src/locales/en.json
  • src/locales/es.json
  • src/locales/hu.json
  • src/pages/AskPage.tsx
  • src/test/ai/client-analytics.test.ts
  • src/test/ai/client-branches.test.ts
  • src/test/ai/client.test.ts
  • src/test/ai/sparring.test.ts
  • src/test/ai/streaming-integration.test.ts
  • src/test/ai/streaming.test.ts
  • src/test/components/ModelSelector.test.tsx
  • src/test/observability.test.ts
  • src/test/providers.test.ts
  • src/test/security-hardening.test.ts
  • src/test/settings-store.test.ts
  • src/test/stores/settings-store-additional.test.ts
  • src/test/stores/settings-store-branches.test.ts
  • src/test/stores/settings-store-extended.test.ts
  • supabase/README.md
  • supabase/functions/_shared/cost.test.ts
  • supabase/functions/_shared/cost.ts
  • supabase/functions/_shared/model-catalog.test.ts
  • supabase/functions/_shared/model-catalog.ts
  • supabase/functions/_shared/research.test.ts
  • supabase/functions/_shared/research.ts
  • supabase/functions/ai-stream/handler_test.ts
  • supabase/functions/ai-stream/index.ts
  • supabase/functions/ai/generate-honesty_test.ts
  • supabase/functions/ai/handler-research.test.ts
  • supabase/functions/ai/index.ts

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The change routes AI requests through OpenRouter with z-ai/glm-5.3-flash, adds catalog-based reasoning controls, normalizes settings and migrations, records provider-reported costs, and updates streaming behavior, documentation, localization, and tests.

Changes

OpenRouter AI integration

Layer / File(s) Summary
Shared model and settings contracts
src/lib/ai/providers/types.ts, src/lib/stores/settings-store.ts, supabase/functions/_shared/model-catalog.ts, src/components/ModelSelector.tsx
The shared catalog defines the GLM model, token limits, and reasoning efforts. Settings normalize legacy values. The selector exposes reasoning controls for Pro subscriptions.
AI proxy and streaming
supabase/functions/ai/index.ts, supabase/functions/ai-stream/index.ts, src/lib/ai/client.ts, src/lib/ai/streaming.ts
AI and streaming requests use OpenRouter, validate catalog values, forward resolved reasoning effort, and handle OpenRouter responses and stream cleanup.
Usage accounting and configuration
supabase/functions/_shared/cost.ts, package.json, supabase/README.md, docs/architecture.md, src/locales/*.json
Usage normalization records valid provider costs and returns unknown cost for incomplete usage. Runtime configuration and product text now identify OpenRouter and the GLM model.
Validation coverage
supabase/functions/**/*test.ts, src/test/**/*.test.*
Tests cover routing, model validation, reasoning tiers, settings migration, streaming failures and cancellation, telemetry, and reported-cost handling.

Estimated code review effort: 5 (Critical) | ~90 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant AIProxy
  participant ModelCatalog
  participant OpenRouter
  Client->>AIProxy: Submit model and reasoningEffort
  AIProxy->>ModelCatalog: Validate model and resolve effort
  ModelCatalog-->>AIProxy: Return limits and effective effort
  AIProxy->>OpenRouter: Send chat completion request
  OpenRouter-->>AIProxy: Return response and usage
  AIProxy-->>Client: Return AI result
Loading

Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Essentials by visiting https://app.coderabbit.ai/settings/billing.

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Add the missing reasoning translations, OpenRouter provider-error classification, and streaming usage option.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Routes AI inference through OpenRouter with GLM 5.3 Flash, reasoning controls, reported-cost accounting, settings migration, and localized copy updates.

Changes:

  • Centralizes OpenRouter model routing and reasoning configuration.
  • Adds cancellation-aware usage and cost handling.
  • Updates settings, tests, documentation, and translations.
File summaries
File Summary
supabase/README.md Documents OpenRouter configuration.
supabase/functions/ai/index.ts Routes non-streaming inference through OpenRouter.
supabase/functions/ai/handler-research.test.ts Tests routing, usage, and cancellation.
supabase/functions/ai/generate-honesty_test.ts Updates provider test fixtures.
supabase/functions/ai-stream/index.ts Implements streaming and cost accounting; usage option remains needed.
supabase/functions/ai-stream/handler_test.ts Tests streaming behavior.
supabase/functions/_shared/research.ts Propagates reasoning controls.
supabase/functions/_shared/research.test.ts Updates research fixtures.
supabase/functions/_shared/model-catalog.ts Defines model and reasoning policies.
supabase/functions/_shared/model-catalog.test.ts Tests catalog behavior.
supabase/functions/_shared/cost.ts Handles reported costs.
supabase/functions/_shared/cost.test.ts Tests cost accounting.
src/test/stores/settings-store-extended.test.ts Tests settings defaults.
src/test/stores/settings-store-branches.test.ts Tests settings migrations.
src/test/stores/settings-store-additional.test.ts Tests settings branches.
src/test/settings-store.test.ts Tests canonicalization and persistence.
src/test/security-hardening.test.ts Tests model allowlisting.
src/test/providers.test.ts Tests the provider catalog.
src/test/observability.test.ts Updates telemetry fixtures.
src/test/components/ModelSelector.test.tsx Tests model and reasoning selection.
src/test/ai/streaming.test.ts Updates streaming helper tests.
src/test/ai/streaming-integration.test.ts Tests reasoning payload forwarding.
src/test/ai/sparring.test.ts Updates sparring fixtures.
src/test/ai/client.test.ts Tests client routing and reasoning.
src/test/ai/client-branches.test.ts Updates client branch coverage.
src/test/ai/client-analytics.test.ts Updates provider analytics expectations.
src/pages/AskPage.tsx Uses OpenRouter result metadata.
src/locales/hu.json Updates Hungarian copy.
src/locales/es.json Updates Spanish copy.
src/locales/en.json Updates English copy; reasoning labels need keys.
src/lib/stores/settings-store.ts Migrates legacy settings and removes credentials.
src/lib/ai/streaming.ts Updates streaming support and payloads.
src/lib/ai/providers/types.ts Defines the OpenRouter provider catalog.
src/lib/ai/client.ts Sends OpenRouter configuration; classifier needs OpenRouter support.
src/components/ModelSelector.tsx Adds model and reasoning selectors.
package.json Updates Edge test permissions.
docs/architecture.md Documents routing and billing behavior.
Review details

Suppressed comments (3)

src/components/ModelSelector.tsx:23

  • The catalog declares GLM 5.3 Flash supports only low and high reasoning (supabase/functions/_shared/model-catalog.ts:19), but this list exposes medium to Pro users. Selecting it persists and sends medium, which the server silently coerces to low, so the UI displays a setting that is not honored. Remove this option or derive the options from the selected model's supportedEfforts.
  { value: 'medium', labelKey: 'modelSelector.reasoningMedium', fallback: 'Medium' },

src/lib/ai/client.ts:372

  • This change makes OpenRouter the provider reported by the client, but the existing isProviderErrorMessage classifier still recognizes only OpenAI, Anthropic, and Google. A backend failure such as OpenRouter error: ... has no error code and will therefore be surfaced as a generic AIError instead of AIProviderError, bypassing provider-specific handling and messaging; update the classifier/label mapping with this provider migration.
  const provider = config.provider === 'mock' ? 'mock' : 'openrouter';

supabase/functions/ai-stream/index.ts:427

  • OpenRouter only sends the terminal usage chunk for a streaming request when stream_options.include_usage is enabled. With only stream: true here, streamUsageRaw will normally remain unset and successful Ask streams will be logged with cost_usd = null, so the new reported-cost accounting does not work for streaming. Add the usage option and assert it in the handler test.
  • Files reviewed: 37/37 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +21 to +24
const reasoningOptions: { value: ReasoningEffort; labelKey: string; fallback: string }[] = [
{ value: 'low', labelKey: 'modelSelector.reasoningLow', fallback: 'Low' },
{ value: 'medium', labelKey: 'modelSelector.reasoningMedium', fallback: 'Medium' },
{ value: 'high', labelKey: 'modelSelector.reasoningHigh', fallback: 'High' },
@Programcode
Programcode merged commit 7fc286b into main Sep 18, 2026
8 checks passed
@Programcode
Programcode deleted the codex/openrouter-glm53-20260918 branch September 18, 2026 17:56

This branch was successfully deployed

1 active deployment
Preview — d87759fc Deployed Sep 18, 2026 by vercel[bot]
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