MCPcopy Index your code
hub / github.com/coder/mux / createModel

Method createModel

src/node/services/providerModelFactory.ts:966–999  ·  view source on GitHub ↗

* 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;
    }
  )

Source from the content-addressed store, hash-verified

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,

Callers 2

consolidateMemoryCommandFunction · 0.95
resolveAndCreateModelMethod · 0.95

Calls 4

_createModelCoreMethod · 0.95
createDevToolsMiddlewareFunction · 0.90
moveLanguageModelCleanupFunction · 0.90
OkFunction · 0.90

Tested by

no test coverage detected