feat: update role-tier structure to include prefixes for models and enhance related configurations
This commit is contained in:
104
lib/tiers.ts
104
lib/tiers.ts
@@ -1,28 +1,20 @@
|
||||
/**
|
||||
* Developer tier definitions and model resolution.
|
||||
*
|
||||
* Tasks are assigned to developer tiers (junior, medior, senior, qa)
|
||||
* instead of raw model names. Each tier maps to a configurable LLM model.
|
||||
* Tier names always include the role prefix: "dev.junior", "qa.reviewer", etc.
|
||||
* This makes tier names globally unique and self-documenting.
|
||||
*/
|
||||
|
||||
export const DEV_TIERS = ["junior", "medior", "senior"] as const;
|
||||
export const QA_TIERS = ["reviewer", "tester"] as const;
|
||||
export const DEV_TIERS = ["dev.junior", "dev.medior", "dev.senior"] as const;
|
||||
export const QA_TIERS = ["qa.reviewer", "qa.tester"] as const;
|
||||
export const ALL_TIERS = [...DEV_TIERS, ...QA_TIERS] as const;
|
||||
|
||||
export type DevTier = (typeof DEV_TIERS)[number];
|
||||
export type QaTier = (typeof QA_TIERS)[number];
|
||||
export type Tier = (typeof ALL_TIERS)[number];
|
||||
|
||||
export const DEFAULT_MODELS: Record<Tier, string> = {
|
||||
junior: "anthropic/claude-haiku-4-5",
|
||||
medior: "anthropic/claude-sonnet-4-5",
|
||||
senior: "anthropic/claude-opus-4-5",
|
||||
reviewer: "anthropic/claude-sonnet-4-5",
|
||||
tester: "anthropic/claude-haiku-4-5",
|
||||
};
|
||||
|
||||
/** Default models by role-tier structure. */
|
||||
export const DEFAULT_MODELS_BY_ROLE = {
|
||||
/** Default models, nested by role. */
|
||||
export const DEFAULT_MODELS = {
|
||||
dev: {
|
||||
junior: "anthropic/claude-haiku-4-5",
|
||||
medior: "anthropic/claude-sonnet-4-5",
|
||||
@@ -34,13 +26,17 @@ export const DEFAULT_MODELS_BY_ROLE = {
|
||||
},
|
||||
};
|
||||
|
||||
/** Emoji used in announcements per tier. */
|
||||
export const TIER_EMOJI: Record<Tier, string> = {
|
||||
junior: "⚡",
|
||||
medior: "🔧",
|
||||
senior: "🧠",
|
||||
reviewer: "🔍",
|
||||
tester: "👀",
|
||||
/** Emoji used in announcements, nested by role. */
|
||||
export const TIER_EMOJI = {
|
||||
dev: {
|
||||
junior: "⚡",
|
||||
medior: "🔧",
|
||||
senior: "🧠",
|
||||
},
|
||||
qa: {
|
||||
reviewer: "🔍",
|
||||
tester: "👀",
|
||||
},
|
||||
};
|
||||
|
||||
/** Check if a string is a valid tier name. */
|
||||
@@ -48,38 +44,72 @@ export function isTier(value: string): value is Tier {
|
||||
return (ALL_TIERS as readonly string[]).includes(value);
|
||||
}
|
||||
|
||||
/** Check if a string is a valid dev tier name. */
|
||||
/** Check if a tier belongs to the dev role. */
|
||||
export function isDevTier(value: string): value is DevTier {
|
||||
return (DEV_TIERS as readonly string[]).includes(value);
|
||||
}
|
||||
|
||||
/** Extract the role from a tier name (e.g. "dev.junior" → "dev"). */
|
||||
export function tierRole(tier: string): "dev" | "qa" | undefined {
|
||||
if (tier.startsWith("dev.")) return "dev";
|
||||
if (tier.startsWith("qa.")) return "qa";
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/** Extract the short name from a tier (e.g. "dev.junior" → "junior"). */
|
||||
export function tierName(tier: string): string {
|
||||
const dot = tier.indexOf(".");
|
||||
return dot >= 0 ? tier.slice(dot + 1) : tier;
|
||||
}
|
||||
|
||||
/** Look up a value from a nested role structure using a full tier name. */
|
||||
function lookupNested<T>(map: Record<string, Record<string, T>>, tier: string): T | undefined {
|
||||
const role = tierRole(tier);
|
||||
if (!role) return undefined;
|
||||
return map[role]?.[tierName(tier)];
|
||||
}
|
||||
|
||||
/** Get the default model for a tier. */
|
||||
export function defaultModel(tier: string): string | undefined {
|
||||
return lookupNested(DEFAULT_MODELS, tier);
|
||||
}
|
||||
|
||||
/** Get the emoji for a tier. */
|
||||
export function tierEmoji(tier: string): string | undefined {
|
||||
return lookupNested(TIER_EMOJI, tier);
|
||||
}
|
||||
|
||||
/** Build a flat Record<Tier, string> of all default models. */
|
||||
export function allDefaultModels(): Record<Tier, string> {
|
||||
const result = {} as Record<Tier, string>;
|
||||
for (const tier of ALL_TIERS) {
|
||||
result[tier] = defaultModel(tier)!;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a tier name to a full model ID.
|
||||
*
|
||||
* Resolution order:
|
||||
* 1. Plugin config `models.<role>.<tier>` nested structure (user overrides)
|
||||
* 2. Plugin config `models.<tier>` flat structure (backward compatibility)
|
||||
* 3. DEFAULT_MODELS (hardcoded defaults)
|
||||
* 4. Treat input as raw model ID (passthrough for non-tier values)
|
||||
* 1. Parse "role.name" → look up config `models.<role>.<name>`
|
||||
* 2. DEFAULT_MODELS[role][name]
|
||||
* 3. Passthrough (treat as raw model ID)
|
||||
*/
|
||||
export function resolveTierToModel(
|
||||
tier: string,
|
||||
pluginConfig?: Record<string, unknown>,
|
||||
role?: "dev" | "qa",
|
||||
): string {
|
||||
const models = (pluginConfig as { models?: Record<string, unknown> })?.models;
|
||||
|
||||
// Try nested role-tier structure first
|
||||
if (role && models && typeof models === "object") {
|
||||
const roleModels = models[role] as Record<string, string> | undefined;
|
||||
if (roleModels?.[tier]) return roleModels[tier];
|
||||
}
|
||||
|
||||
// Fall back to flat structure for backward compatibility
|
||||
if (models && typeof models === "object") {
|
||||
const flatModel = (models as Record<string, string>)[tier];
|
||||
if (flatModel) return flatModel;
|
||||
const role = tierRole(tier);
|
||||
const name = tierName(tier);
|
||||
if (role) {
|
||||
const roleModels = models[role] as Record<string, string> | undefined;
|
||||
if (roleModels?.[name]) return roleModels[name];
|
||||
}
|
||||
}
|
||||
|
||||
return DEFAULT_MODELS[tier as Tier] ?? tier;
|
||||
return defaultModel(tier) ?? tier;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user