/** * License 数据结构 — 纯本地授权,零 SaaS 依赖 * * 发放流程: CLI 生成 → HMAC 签名 → license.json → 交给客户 * 验证流程: Gateway 启动 → 读 license.json → 校验签名+过期 → 功能开关 */ // ========== License 文件结构 ========== export interface LicensePayload { /** License ID (UUID) */ id: string; /** 商户 ID */ merchantId: string; /** 商户名称 */ merchantName: string; /** 套餐等级 */ plan: LicensePlan; /** 功能开关 */ features: LicenseFeatures; /** 配额 */ quotas: LicenseQuotas; /** 发放时间 (ISO 8601) */ issuedAt: string; /** 过期时间 (ISO 8601) */ expiresAt: string; /** 绑定的机器指纹 (可选, 防拷贝) */ machineId?: string; } export interface LicenseFile { /** 版本号, 便于未来升级格式 */ version: 1; /** License 载荷 */ payload: LicensePayload; /** HMAC-SHA256 签名 (对 payload JSON 的签名) */ signature: string; } // ========== 套餐 ========== export type LicensePlan = 'free' | 'basic' | 'pro' | 'enterprise'; // ========== 功能开关 ========== export interface LicenseFeatures { /** FTS5 全文搜索 */ fts_search: boolean; /** 向量搜索 (Phase 2) */ vector_search: boolean; /** 知识同步到 SaaS */ knowledge_sync: boolean; /** 多项目支持 */ multi_project: boolean; /** 自定义模型 */ custom_model: boolean; } // ========== 配额 ========== export interface LicenseQuotas { /** 最大项目数 */ maxProjects: number; /** 每项目最大 Agent 数 */ maxAgentsPerProject: number; /** 月 Token 配额 (-1 = 无限) */ monthlyTokens: number; /** 日消息配额 (-1 = 无限) */ dailyMessages: number; } // ========== 套餐预设 ========== export const PLAN_PRESETS: Record = { free: { features: { fts_search: true, vector_search: false, knowledge_sync: false, multi_project: false, custom_model: false, }, quotas: { maxProjects: 1, maxAgentsPerProject: 4, monthlyTokens: 100_000, dailyMessages: 100, }, }, basic: { features: { fts_search: true, vector_search: false, knowledge_sync: true, multi_project: true, custom_model: false, }, quotas: { maxProjects: 3, maxAgentsPerProject: 6, monthlyTokens: 1_000_000, dailyMessages: 500, }, }, pro: { features: { fts_search: true, vector_search: true, knowledge_sync: true, multi_project: true, custom_model: true, }, quotas: { maxProjects: 10, maxAgentsPerProject: -1, monthlyTokens: 5_000_000, dailyMessages: -1, }, }, enterprise: { features: { fts_search: true, vector_search: true, knowledge_sync: true, multi_project: true, custom_model: true, }, quotas: { maxProjects: -1, maxAgentsPerProject: -1, monthlyTokens: -1, dailyMessages: -1, }, }, }; // ========== 验证结果 ========== export interface LicenseValidation { valid: boolean; error?: string; payload?: LicensePayload; /** 剩余天数 (-1 = 已过期) */ daysRemaining: number; /** 是否在宽限期 (过期 7 天内) */ inGracePeriod: boolean; }