-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel-registry.ts
More file actions
58 lines (49 loc) · 1.67 KB
/
Copy pathmodel-registry.ts
File metadata and controls
58 lines (49 loc) · 1.67 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
const REGISTRY_URL =
'https://raw.githubusercontent.com/meetopenbot/openbot-registry/main/registry.json';
const ANTHROPIC_PROVIDER = 'anthropic';
type RegistryModel = { id: string; label: string; description: string };
type Registry = {
providers?: Record<string, { label: string; models: RegistryModel[] }>;
};
export type ModelConfigField = {
type: 'string';
description: string;
default?: string;
override?: boolean;
enum?: string[];
options?: Array<{ label: string; value: string; description?: string }>;
};
const freeInputModelField = (): ModelConfigField => ({
type: 'string',
override: true,
description: 'Claude model alias or full id (e.g. sonnet, opus, claude-opus-4-5).',
default: 'sonnet',
});
export async function resolveModelConfigField(): Promise<ModelConfigField> {
try {
const res = await fetch(REGISTRY_URL, {
headers: { Accept: 'application/json' },
signal: AbortSignal.timeout(15_000),
});
if (!res.ok) return freeInputModelField();
const registry = (await res.json()) as Registry;
const models = registry.providers?.[ANTHROPIC_PROVIDER]?.models ?? [];
if (models.length === 0) return freeInputModelField();
const defaultModel =
models.find((model) => /sonnet/i.test(model.id))?.id ?? models[0].id;
return {
type: 'string',
override: true,
description: 'Claude model from the OpenBot registry (Anthropic).',
default: defaultModel,
enum: models.map((model) => model.id),
options: models.map((model) => ({
label: model.label,
value: model.id,
description: model.description,
})),
};
} catch {
return freeInputModelField();
}
}