refactor: simplify provider validation and enhance plugin configuration

- Commented out the provider support check in `RuntimeExecutor` to streamline initialization.
- Updated `providerToAiSdkConfig` to utilize `AiCore.isSupported` for improved provider validation.
- Enhanced middleware configuration in `ModernAiProvider` to ensure tools are only added when enabled and available.
- Added comments in `transformParameters` for clarity on parameter handling and plugin activation.
This commit is contained in:
suyao 2025-06-29 03:55:29 +08:00
parent 54c36040af
commit 60cb198f44
No known key found for this signature in database
4 changed files with 10 additions and 13 deletions

View File

@ -7,7 +7,6 @@ import { generateObject, generateText, LanguageModel, LanguageModelV1Middleware,
import { type ProviderId, type ProviderSettingsMap } from '../../types'
import { createModel, getProviderInfo } from '../models'
import { type AiPlugin } from '../plugins'
import { isProviderSupported } from '../providers/registry'
import { PluginEngine } from './pluginEngine'
import { type RuntimeConfig } from './types'
@ -17,9 +16,9 @@ export class RuntimeExecutor<T extends ProviderId = ProviderId> {
private config: RuntimeConfig<T>
constructor(config: RuntimeConfig<T>) {
if (!isProviderSupported(config.providerId)) {
throw new Error(`Unsupported provider: ${config.providerId}`)
}
// if (!isProviderSupported(config.providerId)) {
// throw new Error(`Unsupported provider: ${config.providerId}`)
// }
// 存储options供后续使用
// this.options = config.options

View File

@ -9,6 +9,7 @@
*/
import {
AiCore,
AiPlugin,
createExecutor,
ProviderConfigFactory,
@ -54,12 +55,8 @@ function providerToAiSdkConfig(provider: Provider): {
const aiSdkProviderId = getAiSdkProviderId(actualProvider)
if (aiSdkProviderId !== 'openai-compatible') {
const options = ProviderConfigFactory.fromProvider(aiSdkProviderId, {
...actualProvider
// 使用ai-sdk内置的baseURL
// baseURL: actualProvider.apiHost
})
if (AiCore.isSupported(aiSdkProviderId) && aiSdkProviderId !== 'openai-compatible') {
const options = ProviderConfigFactory.fromProvider(aiSdkProviderId, actualProvider)
return {
providerId: aiSdkProviderId as ProviderId,
@ -138,7 +135,7 @@ export default class ModernAiProvider {
}
// 3. 启用Prompt工具调用时添加工具插件
if (middlewareConfig.enableTool) {
if (middlewareConfig.enableTool && middlewareConfig.mcpTools && middlewareConfig.mcpTools.length > 0) {
plugins.push(
createMCPPromptPlugin({
enabled: true,

View File

@ -24,8 +24,8 @@ export function getAiSdkProviderId(provider: Provider): ProviderId | 'openai-com
}
if (AiCore.isSupported(provider.id)) {
return provider.id as ProviderId as ProviderId
return provider.id as ProviderId
}
return 'openai-compatible'
return provider.id as ProviderId
}

View File

@ -206,6 +206,7 @@ export async function buildStreamTextParams(
const { maxTokens, reasoning_effort } = getAssistantSettings(assistant)
// 这三个变量透传出来,交给下面动态启用插件/中间件
// 也可以在外部构建好再传入buildStreamTextParams
const enableReasoning =
((isSupportedThinkingTokenModel(model) || isSupportedReasoningEffortModel(model)) &&
reasoning_effort !== undefined) ||