refactor: extract provider logic into modular registry

Each AI provider now has its own module implementing a ProviderModule
interface with createGateway, getAuthHeaders, and fetchModels methods.
This replaces the monolithic switch statements in ai-provider.ts and
models.post.ts with a clean registry pattern.
This commit is contained in:
Zoe
2026-04-27 12:04:49 -05:00
parent 6ca4de4cab
commit 1d40812f2a
21 changed files with 1221 additions and 798 deletions
+42
View File
@@ -0,0 +1,42 @@
import { createOpenAI } from '@ai-sdk/openai';
import { GatewayFetchError } from '~~/server/utils/ai-provider';
import { Err, Ok } from '~~/types/result';
import type { ProviderModule } from '.';
export default {
id: 'inception',
baseUrl: 'https://api.inceptionlabs.ai/v1',
modelsEndpoint: null,
createGateway({ apiKey, baseURL }) {
if (apiKey === undefined) {
return Err(GatewayFetchError.NoProviderApiKey);
}
return Ok({
gateway: createOpenAI({ name: 'Inception', apiKey, baseURL }),
streamTransformer: undefined,
textTransformer: undefined,
});
},
getAuthHeaders(apiKey) {
return apiKey ? { Authorization: `Bearer ${apiKey}` } : {};
},
async fetchModels() {
// inception doesn't have a model list endpoint so we hardcode them
return [
{
id: "mercury-2",
name: "Mercury 2",
attributes: {
inputModalities: ['text'],
outputModalities: ['text'],
capabilities: ['tools', 'reasoning'],
contextWindow: 128_000,
}
},
];
},
} satisfies ProviderModule;