File size: 956 Bytes
06671aa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { getSelectableModelIds } from "./inference/config";
import { runSql } from "./supabase";

export const PILOT_FAST_MODEL_ID = "gemini-3.1-flash-lite-high";
export const PILOT_PRO_MODEL_ID = "gemini-3.1-pro-high";

const PILOT_MODEL_IDS = new Set([PILOT_FAST_MODEL_ID, PILOT_PRO_MODEL_ID]);

export async function isOperatorUser(userId: string): Promise<boolean> {
    const result = await runSql(
        "select is_operator from auth.users where id = $1 limit 1",
        [userId],
    );
    return result.rows[0]?.is_operator === true;
}

export function normalizeModelForAccess(
    modelId: string | null | undefined,
    isOperator: boolean,
): string {
    if (isOperator) {
        const selectable = new Set(getSelectableModelIds());
        if (modelId && selectable.has(modelId)) return modelId;
        return PILOT_FAST_MODEL_ID;
    }

    if (modelId && PILOT_MODEL_IDS.has(modelId)) return modelId;
    return PILOT_FAST_MODEL_ID;
}