remove usage of aisdkprovider id

This commit is contained in:
uinstinct 2026-02-12 15:52:35 +05:30
parent 783fd2a2ce
commit 73ee3e047a
3 changed files with 36 additions and 29 deletions

View file

@ -44,7 +44,7 @@ function mergeUserAgentIntoRequestOptions(
/**
* Creates an LLM API instance from a ModelConfig and auth configuration
* Handles special logic for continue-proxy provider and constructs the API
* Handles special logic for continue-proxy and ai-sdk providers and constructs the API
*/
export function createLlmApi(
model: ModelConfig,
@ -53,30 +53,31 @@ export function createLlmApi(
const accessToken = getAccessToken(authConfig);
const organizationId = getOrganizationId(authConfig);
const config: LLMConfig =
model.provider === "continue-proxy"
? {
provider: model.provider,
requestOptions: mergeUserAgentIntoRequestOptions(
model.requestOptions,
),
apiBase: model.apiBase,
apiKey: accessToken ?? undefined,
env: {
apiKeyLocation: (model as any).apiKeyLocation,
orgScopeId: organizationId ?? null,
proxyUrl:
(model as { onPremProxyUrl: string | undefined })
.onPremProxyUrl ?? (env.apiBase ? env.apiBase : undefined),
},
}
: {
provider: model.provider as any,
apiKey: model.apiKey,
apiBase: model.apiBase,
requestOptions: model.requestOptions,
env: model.env,
};
let config: LLMConfig;
if (model.provider === "continue-proxy") {
config = {
provider: model.provider,
requestOptions: mergeUserAgentIntoRequestOptions(model.requestOptions),
apiBase: model.apiBase,
apiKey: accessToken ?? undefined,
env: {
apiKeyLocation: (model as any).apiKeyLocation,
orgScopeId: organizationId ?? null,
proxyUrl:
(model as { onPremProxyUrl: string | undefined }).onPremProxyUrl ??
(env.apiBase ? env.apiBase : undefined),
},
};
} else {
config = {
provider: model.provider as any,
apiKey: model.apiKey,
apiBase: model.apiBase,
requestOptions: model.requestOptions,
env: model.env,
};
}
return constructLlmApi(config) ?? null;
}

View file

@ -193,6 +193,7 @@ const baseModelFields = {
.record(z.string(), z.union([z.string(), z.boolean(), z.number()]))
.optional(),
autocompleteOptions: autocompleteOptionsSchema.optional(),
aiSdkProviderId: z.string().optional(),
};
export const modelSchema = z.union([

View file

@ -35,9 +35,14 @@ const PROVIDER_MAP: Record<string, AiSdkProviderCreator> = {
export class AiSdkApi implements BaseLlmApi {
private provider?: (modelId: string) => any;
private config: AiSdkConfig;
private providerId: string;
private modelId: string;
constructor(config: AiSdkConfig) {
this.config = config;
const [providerId, ...modelParts] = config.model.split("/");
this.providerId = providerId;
this.modelId = modelParts.join("/");
}
private initializeProvider() {
@ -45,11 +50,11 @@ export class AiSdkApi implements BaseLlmApi {
return;
}
const createFn = PROVIDER_MAP[this.config.aiSdkProviderId];
const createFn = PROVIDER_MAP[this.providerId];
if (!createFn) {
const supportedProviders = Object.keys(PROVIDER_MAP).join(", ");
throw new Error(
`Unknown AI SDK provider: "${this.config.aiSdkProviderId}". ` +
`Unknown AI SDK provider: "${this.providerId}". ` +
`Supported providers: ${supportedProviders}. ` +
`To use a different provider, install the @ai-sdk/* package and add it to the provider map.`,
);
@ -99,7 +104,7 @@ export class AiSdkApi implements BaseLlmApi {
(msg) => msg.role !== "system",
);
const modelId = this.config.model ?? body.model;
const modelId = this.modelId ?? body.model;
const model = this.provider!(modelId);
const vercelTools = await convertToolsToVercelFormat(body.tools);
@ -184,7 +189,7 @@ export class AiSdkApi implements BaseLlmApi {
(msg) => msg.role !== "system",
);
const modelId = this.config.model ?? body.model;
const modelId = this.modelId ?? body.model;
const model = this.provider!(modelId);
const vercelTools = await convertToolsToVercelFormat(body.tools);