@novalux/core 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +19 -0
- package/src/__tests__/limits.test.ts +51 -0
- package/src/index.ts +3 -0
- package/src/limits.ts +27 -0
- package/src/models.ts +32 -0
- package/src/types.ts +36 -0
- package/tsconfig.json +9 -0
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@novalux/core",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"types": "./dist/index.d.ts",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "tsc",
|
|
8
|
+
"test": "vitest run"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"ai": "^4.0.0",
|
|
12
|
+
"@ai-sdk/openai": "^1.0.0"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"typescript": "*",
|
|
16
|
+
"vitest": "*",
|
|
17
|
+
"@types/node": "*"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { PLAN_LIMITS, WINDOW_DURATION_MS, getTokenLimit, isModelAllowed } from '../limits'
|
|
3
|
+
|
|
4
|
+
describe('PLAN_LIMITS', () => {
|
|
5
|
+
it('free tier has 15K token limit', () => {
|
|
6
|
+
expect(PLAN_LIMITS.free.tokensPerWindow).toBe(15_000)
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
it('starter tier has 100K token limit', () => {
|
|
10
|
+
expect(PLAN_LIMITS.starter.tokensPerWindow).toBe(100_000)
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
it('pro tier has 350K token limit', () => {
|
|
14
|
+
expect(PLAN_LIMITS.pro.tokensPerWindow).toBe(350_000)
|
|
15
|
+
})
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
describe('WINDOW_DURATION_MS', () => {
|
|
19
|
+
it('is 5 hours in milliseconds', () => {
|
|
20
|
+
expect(WINDOW_DURATION_MS).toBe(5 * 60 * 60 * 1000)
|
|
21
|
+
})
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
describe('getTokenLimit', () => {
|
|
25
|
+
it('returns correct limit for each plan', () => {
|
|
26
|
+
expect(getTokenLimit('free')).toBe(15_000)
|
|
27
|
+
expect(getTokenLimit('starter')).toBe(100_000)
|
|
28
|
+
expect(getTokenLimit('pro')).toBe(350_000)
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
describe('isModelAllowed', () => {
|
|
33
|
+
it('free plan only allows deepseek', () => {
|
|
34
|
+
expect(isModelAllowed('free', 'deepseek')).toBe(true)
|
|
35
|
+
expect(isModelAllowed('free', 'gemini')).toBe(false)
|
|
36
|
+
expect(isModelAllowed('free', 'qwen')).toBe(false)
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it('starter plan allows deepseek and gemini', () => {
|
|
40
|
+
expect(isModelAllowed('starter', 'deepseek')).toBe(true)
|
|
41
|
+
expect(isModelAllowed('starter', 'gemini')).toBe(true)
|
|
42
|
+
expect(isModelAllowed('starter', 'qwen')).toBe(false)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('pro plan allows all models', () => {
|
|
46
|
+
expect(isModelAllowed('pro', 'deepseek')).toBe(true)
|
|
47
|
+
expect(isModelAllowed('pro', 'gemini')).toBe(true)
|
|
48
|
+
expect(isModelAllowed('pro', 'qwen')).toBe(true)
|
|
49
|
+
expect(isModelAllowed('pro', 'kimi')).toBe(true)
|
|
50
|
+
})
|
|
51
|
+
})
|
package/src/index.ts
ADDED
package/src/limits.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type Plan = 'free' | 'starter' | 'pro'
|
|
2
|
+
export type ModelId = 'deepseek' | 'gemini' | 'qwen' | 'kimi'
|
|
3
|
+
|
|
4
|
+
export const WINDOW_DURATION_MS = 5 * 60 * 60 * 1000 // 5 hours
|
|
5
|
+
|
|
6
|
+
export const PLAN_LIMITS = {
|
|
7
|
+
free: {
|
|
8
|
+
tokensPerWindow: 15_000,
|
|
9
|
+
models: ['deepseek'] as ModelId[],
|
|
10
|
+
},
|
|
11
|
+
starter: {
|
|
12
|
+
tokensPerWindow: 100_000,
|
|
13
|
+
models: ['deepseek', 'gemini'] as ModelId[],
|
|
14
|
+
},
|
|
15
|
+
pro: {
|
|
16
|
+
tokensPerWindow: 350_000,
|
|
17
|
+
models: ['deepseek', 'gemini', 'qwen', 'kimi'] as ModelId[],
|
|
18
|
+
},
|
|
19
|
+
} as const satisfies Record<Plan, { tokensPerWindow: number; models: ModelId[] }>
|
|
20
|
+
|
|
21
|
+
export function getTokenLimit(plan: Plan): number {
|
|
22
|
+
return PLAN_LIMITS[plan].tokensPerWindow
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function isModelAllowed(plan: Plan, model: ModelId): boolean {
|
|
26
|
+
return (PLAN_LIMITS[plan].models as readonly string[]).includes(model)
|
|
27
|
+
}
|
package/src/models.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { createOpenAI } from '@ai-sdk/openai'
|
|
2
|
+
import type { LanguageModel } from 'ai'
|
|
3
|
+
import type { ModelId } from './limits'
|
|
4
|
+
|
|
5
|
+
export const MODEL_LABELS: Record<ModelId, string> = {
|
|
6
|
+
deepseek: 'DeepSeek V4 Flash',
|
|
7
|
+
gemini: 'Gemini 2.5 Flash',
|
|
8
|
+
qwen: 'Qwen3.7 Max',
|
|
9
|
+
kimi: 'Kimi K2.6',
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const openrouter = createOpenAI({
|
|
13
|
+
baseURL: 'https://openrouter.ai/api/v1',
|
|
14
|
+
apiKey: process.env.OPENROUTER_API_KEY!,
|
|
15
|
+
headers: {
|
|
16
|
+
'HTTP-Referer': 'https://novalux.dev',
|
|
17
|
+
'X-Title': 'Novalux',
|
|
18
|
+
},
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
export function getModel(modelId: ModelId): LanguageModel {
|
|
22
|
+
switch (modelId) {
|
|
23
|
+
case 'deepseek':
|
|
24
|
+
return openrouter('deepseek/deepseek-chat-v4-5')
|
|
25
|
+
case 'gemini':
|
|
26
|
+
return openrouter('google/gemini-2.5-flash')
|
|
27
|
+
case 'qwen':
|
|
28
|
+
return openrouter('qwen/qwen3-235b-a22b')
|
|
29
|
+
case 'kimi':
|
|
30
|
+
return openrouter('moonshotai/kimi-k2')
|
|
31
|
+
}
|
|
32
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ModelId, Plan } from './limits'
|
|
2
|
+
|
|
3
|
+
export type { ModelId, Plan }
|
|
4
|
+
|
|
5
|
+
export interface Message {
|
|
6
|
+
role: 'user' | 'assistant'
|
|
7
|
+
content: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface ChatRequest {
|
|
11
|
+
messages: Message[]
|
|
12
|
+
model: ModelId
|
|
13
|
+
mode: 'plan' | 'edit'
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface TokenUsage {
|
|
17
|
+
tokensUsed: number
|
|
18
|
+
tokenLimit: number
|
|
19
|
+
windowStart: string
|
|
20
|
+
resetsAt: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface ApiKeyInfo {
|
|
24
|
+
id: string
|
|
25
|
+
prefix: string
|
|
26
|
+
createdAt: string
|
|
27
|
+
lastUsedAt: string | null
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface User {
|
|
31
|
+
id: string
|
|
32
|
+
clerkId: string
|
|
33
|
+
email: string
|
|
34
|
+
plan: Plan
|
|
35
|
+
modelPreference: ModelId
|
|
36
|
+
}
|