Repository navigation
Expand file tree
/
Copy pathmodels.ts
More file actions
88 lines (79 loc) · 2.69 KB
/
Copy pathmodels.ts
File metadata and controls
88 lines (79 loc) · 2.69 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
export const ASSISTANT_MODEL_VALUES = [
"auto",
"hauku",
"sonnet",
"opus",
"fable",
"luna",
"terra",
"sol",
] as const;
export type AssistantModel = (typeof ASSISTANT_MODEL_VALUES)[number];
export type AssistantProvider = "anthropic" | "openai";
export type AssistantApiKeys = {
anthropic: string;
openai: string;
};
export type ResolvedAssistantModel = {
selection: AssistantModel;
provider: AssistantProvider;
model: string;
apiKey: string;
effort?: "low" | "medium" | "high";
};
type ModelDefinition = {
label: string;
provider: AssistantProvider;
model: string;
effort?: "low" | "medium" | "high";
};
const MODEL_DEFINITIONS: Record<Exclude<AssistantModel, "auto">, ModelDefinition> = {
// Keep the user-facing spelling requested for the picker while using
// Anthropic's canonical Haiku alias on the wire.
hauku: { label: "Hauku", provider: "anthropic", model: "claude-haiku-4-5" },
sonnet: { label: "Sonnet", provider: "anthropic", model: "claude-sonnet-5", effort: "low" },
opus: { label: "Opus", provider: "anthropic", model: "claude-opus-5", effort: "low" },
fable: { label: "Fable", provider: "anthropic", model: "claude-fable-5", effort: "low" },
luna: { label: "Luna", provider: "openai", model: "gpt-5.6-luna", effort: "low" },
terra: { label: "Terra", provider: "openai", model: "gpt-5.6-terra", effort: "low" },
sol: { label: "Sol", provider: "openai", model: "gpt-5.6-sol", effort: "low" },
};
export function assistantModelLabel(value: AssistantModel): string {
return value === "auto" ? "Auto" : MODEL_DEFINITIONS[value].label;
}
export function assistantModelProvider(value: AssistantModel): AssistantProvider | null {
return value === "auto" ? null : MODEL_DEFINITIONS[value].provider;
}
/**
* Resolve Auto and attach the credential needed by the chosen provider.
* Auto intentionally prefers Terra over Sonnet when both keys are available.
*/
export function resolveAssistantModel(
selection: AssistantModel,
keys: AssistantApiKeys,
): ResolvedAssistantModel | null {
const normalizedKeys: AssistantApiKeys = {
anthropic: keys.anthropic.trim(),
openai: keys.openai.trim(),
};
let resolvedSelection = selection;
if (selection === "auto") {
if (normalizedKeys.openai) {
resolvedSelection = "terra";
} else if (normalizedKeys.anthropic) {
resolvedSelection = "sonnet";
} else {
return null;
}
}
const definition = MODEL_DEFINITIONS[resolvedSelection as Exclude<AssistantModel, "auto">];
const apiKey = normalizedKeys[definition.provider];
if (!apiKey) return null;
return {
selection,
provider: definition.provider,
model: definition.model,
apiKey,
effort: definition.effort,
};
}