Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import {
} from '@codebuff/common/constants/freebuff-models'
import { openCodeZenModels } from '@codebuff/common/constants/model-config'
import { postChatCompletions } from '../_post'
import {
checkFreeModeRateLimit,
resetFreeModeRateLimits,
} from '../free-mode-rate-limiter'
import { resetFreeModeRateLimits } from '../free-mode-rate-limiter'

import type { TrackEventFn } from '@codebuff/common/types/contracts/analytics'
import type { InsertMessageBigqueryFn } from '@codebuff/common/types/contracts/bigquery'
Expand Down Expand Up @@ -1148,6 +1145,11 @@ describe('/api/v1/chat/completions POST endpoint', () => {
})

it('requires an active session check for the Gemini thinker subagent', async () => {
const checkFreeModeRateLimitForTest = mock((userId: string) => {
expect(userId).toBe('user-new-free-gemini')
return { limited: false as const }
})

const response = await postChatCompletions({
req: new NextRequest('http://localhost:3000/api/v1/chat/completions', {
method: 'POST',
Expand Down Expand Up @@ -1177,11 +1179,11 @@ describe('/api/v1/chat/completions POST endpoint', () => {
expect(params.claimedInstanceId).toBe('inst-123')
return { ok: true, reason: 'active', remainingMs: 60_000 }
},
checkFreeModeRateLimit: checkFreeModeRateLimitForTest,
})

expect(response.status).toBe(200)
expect(checkFreeModeRateLimit('user-new-free-gemini').limited).toBe(false)
expect(checkFreeModeRateLimit('user-new-free-gemini').limited).toBe(true)
expect(checkFreeModeRateLimitForTest).toHaveBeenCalledTimes(1)
})

it(
Expand Down
4 changes: 2 additions & 2 deletions web/src/llm-api/opencode-zen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ const OPENCODE_ZEN_MODELS: Record<

const OPENCODE_ZEN_MODEL_PREFIX = 'opencode/'

export function isOpenCodeZenModel(model: string): boolean {
return model.startsWith(OPENCODE_ZEN_MODEL_PREFIX)
export function isOpenCodeZenModel(model: unknown): model is string {
return typeof model === 'string' && model.startsWith(OPENCODE_ZEN_MODEL_PREFIX)
}

function getOpenCodeZenModelId(model: string): string {
Expand Down
Loading