Model tiers: per-model credits and premium/vip roles

LLM_MODELS entries are now model[=credits][@role]. The default tiers follow
the model comparison rated by an astrologer: Claude Haiku 5.5 (free, 1
credit), GPT-5.6 Terra (premium, 3 credits), Claude Opus 5.5 (vip, 10 credits).
VIP includes premium, admins may use every model.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-15 20:46:30 +00:00
co-authored by Claude Opus 5.5
parent b30a6c8fb1
commit 4aabb7343c
10 changed files with 180 additions and 29 deletions
+5
View File
@@ -0,0 +1,5 @@
-- Subscription tiers as roles: 'premium' and 'vip' unlock the models marked
-- for them in the backend's LLM_MODELS.
ALTER TABLE users DROP CONSTRAINT users_roles_valid;
ALTER TABLE users ADD CONSTRAINT users_roles_valid
CHECK (cardinality(roles) > 0 AND roles <@ ARRAY['admin', 'creator', 'premium', 'vip', 'user']::text[]);
+13 -1
View File
@@ -27,16 +27,22 @@ pub enum Role {
Admin,
/// May write articles (phase 2).
Creator,
/// Paid tier: may use the models marked `@premium`.
Premium,
/// Top tier: may use the `@vip` and `@premium` models.
Vip,
User,
}
impl Role {
pub const ALL: [Role; 3] = [Role::Admin, Role::Creator, Role::User];
pub const ALL: [Role; 5] = [Role::Admin, Role::Creator, Role::Premium, Role::Vip, Role::User];
pub fn as_str(self) -> &'static str {
match self {
Role::Admin => "admin",
Role::Creator => "creator",
Role::Premium => "premium",
Role::Vip => "vip",
Role::User => "user",
}
}
@@ -63,6 +69,12 @@ impl User {
self.roles.iter().any(|r| r == role.as_str())
}
/// Whether the user may use something that needs `role`: admins may use
/// everything, and the VIP tier includes the premium one.
pub fn has_access(&self, role: Role) -> bool {
self.has_role(role) || self.has_role(Role::Admin) || (role == Role::Premium && self.has_role(Role::Vip))
}
pub fn role_list(&self) -> Vec<Role> {
self.roles.iter().filter_map(|r| Role::parse(r)).collect()
}