Skip to content

Add GLM 5 and MiniMax M2.5 model support with tier-based rate limiting - #629

Merged
2witstudios merged 3 commits into
masterfrom
glm
Feb 13, 2026
Merged

2witstudios merged 3 commits into
masterfrom
glm

Conversation

@2witstudios

@2witstudios 2witstudios commented Feb 13, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Updates PageSpace tier models: Standard (glm-4.7), Pro (glm-5)
  • Adds GLM 5 and MiniMax M2.5 to OpenRouter and direct provider configurations
  • Adds pricing and context window data for cost tracking and context management
  • Refactors rate limiting to use tier-based lookup instead of hardcoded model names
  • Includes database migration for existing users

Changes

Provider Configuration

  • PAGESPACE_MODEL_ALIASES: standard → glm-4.7, pro → glm-5
  • Added z-ai/glm-5 and minimax/minimax-m2.5 to OpenRouter
  • Added glm-5 and MiniMax-M2.5 to direct providers
  • Updated getUserFacingModelName() and getDefaultModel()

Rate Limiting (Refactored)

  • Added getPageSpaceModelTier(model) function for reverse alias lookup
  • Rate limiting now uses tier-based detection instead of hardcoded model names
  • Future model changes only require updating PAGESPACE_MODEL_ALIASES

Monitoring & Pricing

  • Added pricing: GLM 5 ($0.80/$2.56 OpenRouter, $1.00/$3.20 native), MiniMax M2.5 ($0.30/$1.20)
  • Added context windows: GLM 5 (200k-202k), MiniMax M2.5 (204k-1M)
  • Updated ai-context-calculator.ts with GLM 5 and MiniMax patterns

Database

  • Migration 0083_migrate_pagespace_model_tiers.sql updates existing users
  • Default model in auth schema updated to glm-4.7

Test plan

  • TypeScript compilation passes
  • 24 new tests for ai-providers-config functions (all pass)
  • 52 subscription/rate-limiting tests (all pass)
  • 158 AI core tests (all pass)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added GLM-5 (Pro tier) and MiniMax M2.5 models to available AI options.
    • MiniMax M2.5 now supports vision capabilities.
    • Enhanced model tier system with improved user-facing labels.
  • Tests

    • Added comprehensive test suite for AI provider configuration and model aliasing logic.
  • Chores

    • Updated default model assignments and pricing data for new models.
    • Database migration to update existing user model selections.

- Update PageSpace tier models: Standard (glm-4.7), Pro (glm-5)
- Add GLM 5 and MiniMax M2.5 to OpenRouter and direct providers
- Add pricing data for new models in ai-monitoring.ts
- Add context window data for new models (GLM 5: 200k, MiniMax M2.5: 1M)
- Update ai-context-calculator with GLM 5 and MiniMax patterns
- Refactor rate limiting to use tier-based lookup via getPageSpaceModelTier()
  instead of hardcoded model names - future model changes only need
  PAGESPACE_MODEL_ALIASES update
- Add MiniMax M2.5 to vision-capable models
- Add migration to update existing users to new tier models
- Add comprehensive tests for ai-providers-config functions

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Feb 13, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@2witstudios has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 7 minutes and 9 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📝 Walkthrough

Walkthrough

This PR updates PageSpace model tiers and configurations across the application. It introduces glm-5 as a Pro tier model, migrates references from glm-4.5-air (Standard) to glm-4.7, adds new models (glm-5, MiniMax M2.5) to pricing and context mappings, updates rate-limiting to use tier-based logic, and includes a database migration script to align existing user data with the new tier structure.

Changes

Cohort / File(s) Summary
Model Configuration & Tests
apps/web/src/lib/ai/core/ai-providers-config.ts, apps/web/src/lib/ai/core/__tests__/ai-providers-config.test.ts
Added comprehensive test suite validating model aliases, tier resolution, defaults, and user-facing names. Updated PageSpace aliases (standard→glm-4.7, pro→glm-5). Introduced new public function getPageSpaceModelTier(). Added glm-5 and MiniMax M2.5 models to provider registries.
Provider & Factory Updates
apps/web/src/lib/ai/core/provider-factory.ts, apps/web/src/lib/ai/core/__tests__/provider-factory.test.ts
Changed default AI model from glm-4.5-air to glm-4.7. Updated test expectations to reflect new model alias mappings.
Rate Limiting & Subscriptions
apps/web/src/lib/subscription/rate-limit-middleware.ts
Added userId parameter to checkAIRateLimit(). Enhanced RateLimitResult interface with remaining, limit, and subscriptionTier fields. Implemented tier-based provider type determination using getPageSpaceModelTier().
Vision & Context Configuration
apps/web/src/lib/ai/core/vision-models.ts, packages/lib/src/monitoring/ai-context-calculator.ts, packages/lib/src/monitoring/ai-monitoring.ts
Registered MiniMax-M2.5 as vision-capable. Added context window mappings for glm-5 (200,000 tokens) and MiniMax-M2.5 (1,000,000 tokens). Introduced pricing data for new models across OpenRouter and direct GLM/MiniMax providers.
Database Schema & Migration
packages/db/src/schema/auth.ts, packages/db/drizzle/0083_migrate_pagespace_model_tiers.sql
Updated default currentAiModel column value from glm-4.5-air to glm-4.7. Added migration script to upgrade Pro tier users to glm-5 and Standard tier users to glm-4.7.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 New models hop into the den,
glm-5 bounds forth, again and again!
Standard and Pro now dance with ease,
Tiers aligned to surely please.
Pagespace hops forward, swift and free! ✨

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main changes: adding GLM 5 and MiniMax M2.5 model support with tier-based rate limiting, which are the primary objectives of this changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into master

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch glm

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/web/src/lib/ai/core/provider-factory.ts (1)

90-95: ⚠️ Potential issue | 🟡 Minor

Stale comment references old model alias.

Line 92 still says 'standard' -> 'glm-4.5-air' but the alias now resolves to 'glm-4.7'.

📝 Fix the comment
-  // Resolve model aliases for PageSpace provider (e.g., 'standard' -> 'glm-4.5-air')
+  // Resolve model aliases for PageSpace provider (e.g., 'standard' -> 'glm-4.7')
🤖 Fix all issues with AI agents
In `@packages/db/src/schema/auth.ts`:
- Line 24: The schema default change on the column symbol currentAiModel (in
auth.ts) must be captured by an auto-generated DDL migration: run `pnpm
db:generate` to produce the migration that records the default change
(glm-4.5-air -> glm-4.7), add that generated migration file to the commit, and
remove or revert any manual schema edits so that only the auto-generated
migration (not a hand-edited change) introduces the default update; ensure the
existing manual data migration (0083) remains only for data changes and not the
column-default DDL.
🧹 Nitpick comments (4)
packages/db/drizzle/0083_migrate_pagespace_model_tiers.sql (1)

8-18: Migration logic and ordering look correct.

The execution order (Pro before Standard) correctly prevents double-migration. The WHERE clauses are appropriately scoped to currentAiProvider = 'pagespace' only.

One minor consideration: there's no explicit transaction boundary. If the migration runner doesn't auto-wrap each file in a transaction, a failure between Step 1 and Step 2 could leave the database in an inconsistent state.

🛡️ Suggested: wrap in a transaction
+BEGIN;
+
 -- Step 1: Migrate Pro users from glm-4.7 to glm-5
 UPDATE users
 SET "currentAiModel" = 'glm-5'
 WHERE "currentAiProvider" = 'pagespace'
   AND "currentAiModel" = 'glm-4.7';
 
 -- Step 2: Migrate Standard users from glm-4.5-air to glm-4.7
 UPDATE users
 SET "currentAiModel" = 'glm-4.7'
 WHERE "currentAiProvider" = 'pagespace'
   AND "currentAiModel" = 'glm-4.5-air';
+
+COMMIT;
apps/web/src/lib/ai/core/ai-providers-config.ts (3)

33-48: Well-structured reverse lookup for tier resolution.

The function is clean and the case-insensitive matching is a good touch. The as 'standard' | 'pro' cast is safe given the current alias map.

One minor resilience note: if a third tier is ever added to PAGESPACE_MODEL_ALIASES, the return type and cast would need a manual update. Consider deriving the tier type from the alias keys to keep them in sync:

♻️ Optional: derive tier type from alias keys
+type PageSpaceTier = keyof typeof PAGESPACE_MODEL_ALIASES;
+
-export function getPageSpaceModelTier(model: string): 'standard' | 'pro' | null {
+export function getPageSpaceModelTier(model: string): PageSpaceTier | null {
   const modelLower = model.toLowerCase();
   for (const [tier, tierModel] of Object.entries(PAGESPACE_MODEL_ALIASES)) {
     if (tierModel.toLowerCase() === modelLower) {
-      return tier as 'standard' | 'pro';
+      return tier as PageSpaceTier;
     }
   }
   return null;
 }

Note: This would require removing the Record<string, string> type annotation on PAGESPACE_MODEL_ALIASES (keeping only as const) so keyof typeof yields literal key types instead of string. That's a broader change, so feel free to defer.


11-14: Record<string, string> widens away the as const narrowing.

The explicit type annotation Record<string, string> makes the as const assertion a no-op — keys and values are widened to string. This is pre-existing, but it's the root reason getPageSpaceModelTier needs the as cast on Line 44. If you ever want to derive types from this map (as suggested above), you'd drop the annotation:

-export const PAGESPACE_MODEL_ALIASES: Record<string, string> = {
+export const PAGESPACE_MODEL_ALIASES = {
   standard: 'glm-4.7',
   pro: 'glm-5',
 } as const;

This is a low-priority cleanup — no functional impact.


446-454: Consider using getPageSpaceModelTier here for consistency.

The rate-limit middleware was refactored to use getPageSpaceModelTier instead of hardcoded model IDs, but getUserFacingModelName still compares against literal strings 'glm-5' and 'glm-4.7'. If the alias mapping changes, this function would also need a manual update.

♻️ Optional: use tier lookup for consistency
   if (provider === 'pagespace') {
     const resolvedModel = resolvePageSpaceModel(model);
-    if (resolvedModel === 'glm-5') {
+    const tier = getPageSpaceModelTier(resolvedModel);
+    if (tier === 'pro') {
       return 'PageSpace Pro';
     }
-    if (resolvedModel === 'glm-4.7') {
-      return 'PageSpace Standard';
-    }
     // Any other PageSpace model defaults to Standard
     return 'PageSpace Standard';
   }

Comment thread packages/db/src/schema/auth.ts
Update comment to reflect correct model alias:
'standard' -> 'glm-4.7' (was incorrectly 'glm-4.5-air')

Addresses CodeRabbit review feedback.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@2witstudios

Copy link
Copy Markdown
Owner Author

Addressing CodeRabbit Review Feedback

Fixed: Stale comment in provider-factory.ts

Updated the comment at line 92 to correctly reference 'standard' -> 'glm-4.7' instead of the outdated 'standard' -> 'glm-4.5-air'.

Commit: 35dcff2

Regarding Nitpick Suggestions

The nitpick suggestions (transaction boundary, type derivation, etc.) are good ideas for future refactoring but are out of scope for this PR which focuses on model tier updates. The current implementation is correct and functional.

- Added 0084_update_default_ai_model.sql to update column default
- Updated migration journal to include both data (0083) and DDL (0084) migrations
- Added snapshots for migration tracking

This addresses the CodeRabbit review feedback about running pnpm db:generate
to capture the schema default change from 'glm-4.5-air' to 'glm-4.7'.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@2witstudios

Copy link
Copy Markdown
Owner Author

Fixed: DDL Migration for Default AI Model Change

Ran pnpm db:generate and added the auto-generated DDL migration as requested:

  • 0084_update_default_ai_model.sql: Changes the column default from 'glm-4.5-air' to 'glm-4.7'
  • Updated migration journal to include both data migration (0083) and DDL migration (0084)
  • Added snapshots for Drizzle migration tracking

Commit: 73798bd

This addresses the CodeRabbit review feedback at packages/db/src/schema/auth.ts:24.

@2witstudios
2witstudios merged commit f1a9986 into master Feb 13, 2026
10 checks passed
@2witstudios
2witstudios deleted the glm branch March 11, 2026 03:12
@coderabbitai coderabbitai Bot mentioned this pull request Mar 17, 2026
4 of 6 tasks
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.

1 participant