-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathproviderTemplates.ts
More file actions
217 lines (208 loc) 路 6.69 KB
/
Copy pathproviderTemplates.ts
File metadata and controls
217 lines (208 loc) 路 6.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
import { getModelsDevProvider } from './models-dev'
import { CHATGPT_PROVIDER_DISPLAY_NAME } from './provider-display-names'
import type { ProviderType } from './types'
/**
* Provider template for quick setup
* @public
*/
export interface ProviderTemplate {
id: ProviderType
name: string
defaultBaseUrl: string
defaultModelId: string
supportsImages: boolean
contextWindow: number
setupGuideUrl?: string
apiKeyUrl?: string
}
function enrichTemplate(
providerId: ProviderType,
overrides: {
defaultModelId: string
defaultBaseUrl?: string
apiKeyUrl?: string
setupGuideUrl?: string
},
): ProviderTemplate {
const provider = getModelsDevProvider(providerId)
const model = provider?.models.find((m) => m.id === overrides.defaultModelId)
return {
id: providerId,
name: provider?.name ?? providerId,
defaultBaseUrl: overrides.defaultBaseUrl ?? provider?.api ?? '',
defaultModelId: overrides.defaultModelId,
supportsImages: model?.supportsImages ?? true,
contextWindow: model?.contextWindow ?? 128000,
...(overrides.apiKeyUrl && { apiKeyUrl: overrides.apiKeyUrl }),
...(overrides.setupGuideUrl && { setupGuideUrl: overrides.setupGuideUrl }),
}
}
/**
* Available provider templates for quick setup
* @public
*/
export const providerTemplates: ProviderTemplate[] = [
{
id: 'chatgpt-pro',
name: CHATGPT_PROVIDER_DISPLAY_NAME,
defaultBaseUrl: 'https://chatgpt.com/backend-api',
defaultModelId: 'gpt-5.5',
supportsImages: true,
contextWindow: 1050000,
setupGuideUrl: 'https://docs.browseros.com/features/chatgpt-pro-oauth',
},
{
id: 'github-copilot',
name: 'GitHub Copilot',
defaultBaseUrl: 'https://api.githubcopilot.com',
defaultModelId: 'gpt-5-mini',
supportsImages: true,
contextWindow: 128000,
setupGuideUrl: 'https://docs.browseros.com/features/github-copilot-oauth',
},
{
id: 'qwen-code',
name: 'Qwen Code',
defaultBaseUrl: 'https://portal.qwen.ai/v1',
defaultModelId: 'coder-model',
supportsImages: true,
contextWindow: 1000000,
setupGuideUrl: 'https://docs.browseros.com/features/qwen-code-oauth',
},
{
id: 'moonshot',
name: 'Moonshot AI',
defaultBaseUrl: 'https://api.moonshot.ai/v1',
defaultModelId: 'kimi-k2.5',
supportsImages: true,
contextWindow: 200000,
apiKeyUrl: 'https://platform.moonshot.ai/console/api-keys',
setupGuideUrl: 'https://platform.moonshot.ai/console/api-keys',
},
enrichTemplate('openai', {
defaultModelId: 'gpt-5',
apiKeyUrl: 'https://platform.openai.com/api-keys',
setupGuideUrl:
'https://docs.browseros.com/features/bring-your-own-llm#openai',
}),
{
id: 'openai-compatible',
name: 'OpenAI Compatible',
defaultBaseUrl: '',
defaultModelId: '',
supportsImages: true,
contextWindow: 128000,
},
enrichTemplate('anthropic', {
defaultModelId: 'claude-sonnet-4-6',
apiKeyUrl: 'https://console.anthropic.com/settings/keys',
setupGuideUrl:
'https://docs.browseros.com/features/bring-your-own-llm#claude',
}),
enrichTemplate('google', {
defaultModelId: 'gemini-2.5-flash',
apiKeyUrl: 'https://aistudio.google.com/app/apikey',
setupGuideUrl:
'https://docs.browseros.com/features/bring-your-own-llm#gemini',
}),
{
id: 'ollama',
name: 'Ollama',
defaultBaseUrl: 'http://localhost:11434/v1',
defaultModelId: 'llama3.2',
supportsImages: false,
contextWindow: 128000,
setupGuideUrl:
'https://docs.browseros.com/features/bring-your-own-llm#ollama',
},
enrichTemplate('openrouter', {
defaultModelId: 'anthropic/claude-sonnet-4.5',
apiKeyUrl: 'https://openrouter.ai/keys',
setupGuideUrl:
'https://docs.browseros.com/features/bring-your-own-llm#openrouter',
}),
enrichTemplate('lmstudio', {
defaultModelId: 'openai/gpt-oss-20b',
defaultBaseUrl: 'http://localhost:1234/v1',
setupGuideUrl:
'https://docs.browseros.com/features/bring-your-own-llm#lmstudio',
}),
enrichTemplate('azure', {
defaultModelId: '',
apiKeyUrl:
'https://portal.azure.com/#view/Microsoft_Azure_ProjectOxford/CognitiveServicesHub/~/OpenAI',
}),
enrichTemplate('bedrock', {
defaultModelId: 'anthropic.claude-sonnet-4-6',
setupGuideUrl:
'https://docs.aws.amazon.com/bedrock/latest/userguide/getting-started.html',
}),
]
/**
* Provider type options for select dropdowns
* @public
*/
export const providerTypeOptions: { value: ProviderType; label: string }[] = [
{ value: 'chatgpt-pro', label: CHATGPT_PROVIDER_DISPLAY_NAME },
{ value: 'github-copilot', label: 'GitHub Copilot' },
{ value: 'qwen-code', label: 'Qwen Code' },
{ value: 'moonshot', label: 'Moonshot AI' },
{ value: 'anthropic', label: 'Anthropic' },
{ value: 'openai', label: 'OpenAI' },
{ value: 'openai-compatible', label: 'OpenAI Compatible' },
{ value: 'google', label: 'Gemini' },
{ value: 'openrouter', label: 'OpenRouter' },
{ value: 'azure', label: 'Azure' },
{ value: 'ollama', label: 'Ollama' },
{ value: 'lmstudio', label: 'LM Studio' },
{ value: 'bedrock', label: 'AWS Bedrock' },
{ value: 'browseros', label: 'BrowserOS' },
]
/**
* Get provider template by type
* @public
*/
export const getProviderTemplate = (
type: ProviderType,
): ProviderTemplate | undefined => {
return providerTemplates.find((t) => t.id === type)
}
/**
* Default base URLs for each provider type
* Auto-fills when user selects a provider type
*/
const DEFAULT_BASE_URLS: Record<ProviderType, string> = {
'chatgpt-pro': 'https://chatgpt.com/backend-api',
'github-copilot': 'https://api.githubcopilot.com',
'qwen-code': 'https://portal.qwen.ai/v1',
moonshot: 'https://api.moonshot.ai/v1',
anthropic: 'https://api.anthropic.com/v1',
openai: 'https://api.openai.com/v1',
'openai-compatible': '',
google: 'https://generativelanguage.googleapis.com/v1beta',
openrouter: 'https://openrouter.ai/api/v1',
azure: '',
ollama: 'http://localhost:11434/v1',
lmstudio: 'http://localhost:1234/v1',
bedrock: '',
browseros: '',
}
/**
* Get default base URL for a provider type
* @public
*/
/**
* Whether a stored type string is one this build understands.
*
* Keyed off DEFAULT_BASE_URLS because it is a `Record<ProviderType, string>`,
* so the compiler keeps it exhaustive as the union changes. Used to filter
* rows written by a newer build after a downgrade: icons, templates and base
* URLs are all keyed by this union, so an unknown type would read as
* undefined through every one of them.
*/
export function isProviderType(value: string): value is ProviderType {
return Object.hasOwn(DEFAULT_BASE_URLS, value)
}
export const getDefaultBaseUrlForProviders = (type: ProviderType): string => {
return DEFAULT_BASE_URLS[type] || ''
}