Turn on upper-snake-string-unions and convert profile types, failure reasons and anchor sides at their boundaries

This commit is contained in:
Danny Kim
2026-10-19 19:46:31 +09:00
parent 71150900ff
commit c783935936
13 changed files with 144 additions and 113 deletions
+14 -14
View File
@@ -3,18 +3,18 @@ import { webcrypto } from "node:crypto";
import { field, isMapping } from "#common";
import type { BotProfile } from "#profiles";
interface DefaultModels {
claude: string;
codex: string;
opencode: string;
// The model a profile runs when profiles.json names none.
function defaultModel(type: BotProfile["type"]): string {
switch (type) {
case "CLAUDE":
return "claude-sonnet-5";
case "CODEX":
return "gpt-5.6-terra";
case "OPENCODE":
return "openrouter/qwen/qwen3.8-27b";
}
}
const DEFAULT_MODELS: DefaultModels = {
claude: "claude-sonnet-5",
codex: "gpt-5.6-terra",
opencode: "openrouter/qwen/qwen3.8-27b",
};
export interface BotCredentials {
reviewerToken: string;
profiles: BotProfile[];
@@ -91,13 +91,13 @@ async function parseProfile(entry: unknown, index: number, masterKey: string): P
const type = field(entry, "type");
const model = field(entry, "model");
const token = field(entry, "token");
if (type !== "claude" && type !== "codex" && type !== "opencode") {
throw new Error(`${at}.type: expected "claude", "codex", or "opencode"`);
if (type !== "CLAUDE" && type !== "CODEX" && type !== "OPENCODE") {
throw new Error(`${at}.type: expected "CLAUDE", "CODEX", or "OPENCODE"`);
}
if (model !== undefined && (typeof model !== "string" || model === "")) {
throw new Error(`${at}.model: expected a model name`);
}
if ((type === "claude" || type === "opencode") && typeof token !== "string") {
if ((type === "CLAUDE" || type === "OPENCODE") && typeof token !== "string") {
throw new Error(`${at}.token: expected an encrypted credential`);
}
if (token !== undefined && typeof token !== "string") {
@@ -105,7 +105,7 @@ async function parseProfile(entry: unknown, index: number, masterKey: string): P
}
return {
type,
model: model ?? DEFAULT_MODELS[type],
model: model ?? defaultModel(type),
...(typeof token === "string" && {
token: await decryptCredential(token, masterKey),
}),