* Create an AI SDK model from a model string (e.g., "anthropic:claude-opus-4-1") * * IMPORTANT: We ONLY use providers.jsonc as the single source of truth for provider configuration. * We DO NOT use environment variables or default constructors that might read them. * This ensures consist
(
modelString: string,
muxProviderOptions?: MuxProviderOptions,
opts?: {
agentInitiated?: boolean;
workspaceId?: string;
routeContext?: RouteContext;
}
)
| 964 | * supported by the provider will work without modification. |
| 965 | */ |
| 966 | async createModel( |
| 967 | modelString: string, |
| 968 | muxProviderOptions?: MuxProviderOptions, |
| 969 | opts?: { |
| 970 | agentInitiated?: boolean; |
| 971 | workspaceId?: string; |
| 972 | routeContext?: RouteContext; |
| 973 | } |
| 974 | ): Promise<Result<LanguageModel, SendMessageError>> { |
| 975 | const result = await this._createModelCore(modelString, muxProviderOptions, opts); |
| 976 | if (!result.success) { |
| 977 | return result; |
| 978 | } |
| 979 | |
| 980 | // DevTools middleware wrappers currently support LanguageModelV3 instances only. |
| 981 | if (typeof result.data === "string" || result.data.specificationVersion !== "v3") { |
| 982 | return result; |
| 983 | } |
| 984 | |
| 985 | let model: LanguageModel = result.data; |
| 986 | |
| 987 | const workspaceId = opts?.workspaceId; |
| 988 | const devToolsService = this.devToolsService; |
| 989 | if (workspaceId != null && devToolsService?.enabled) { |
| 990 | const innerModel = model; |
| 991 | model = wrapLanguageModel({ |
| 992 | model, |
| 993 | middleware: createDevToolsMiddleware(workspaceId, devToolsService), |
| 994 | }); |
| 995 | moveLanguageModelCleanup(innerModel, model); |
| 996 | } |
| 997 | |
| 998 | return Ok(model); |
| 999 | } |
| 1000 | |
| 1001 | private async _createModelCore( |
| 1002 | modelString: string, |
no test coverage detected