MCPcopy Create free account
hub / github.com/apache/maka / resolveModelRuntime

Function resolveModelRuntime

packages/runtime/src/model-runtime.ts:43–97  ·  view source on GitHub ↗
(
  connection: ModelRuntimeConnection,
  modelId: string,
)

Source from the content-addressed store, hash-verified

41}
42
43export function resolveModelRuntime(
44 connection: ModelRuntimeConnection,
45 modelId: string,
46): ResolvedModelRuntime {
47 const override = lookupModelProviderOverride(connection.providerType, modelId);
48 const defaults = PROVIDER_DEFAULTS[connection.providerType];
49 // Unknown providerType with no per-model override → can't resolve an adapter.
50 // Throw a clear error rather than crashing on `.runtimeAdapter`. Mirrors
51 // `isFakeBackend` in @maka/core/connection-readiness.ts.
52 if (!override && !defaults) {
53 throw new Error(
54 `Unknown provider type "${connection.providerType}"; cannot resolve model runtime.`,
55 );
56 }
57 const apiProtocol = connection.models?.find((model) => model.id === modelId)?.apiProtocol;
58 if (
59 connection.providerType === 'kimi-coding-plan' &&
60 apiProtocol !== undefined &&
61 apiProtocol !== 'anthropic-messages' &&
62 apiProtocol !== 'openai-chat'
63 ) {
64 throw new Error(
65 `Kimi Coding Plan protocol must be openai-chat or anthropic-messages, received ${apiProtocol}`,
66 );
67 }
68 const adapter: ProviderRuntimeAdapter =
69 connection.providerType === 'kimi-coding-plan' && apiProtocol === 'openai-chat'
70 ? ({
71 kind: 'openai-compatible',
72 name: 'provider',
73 includeUsage: true,
74 } as const)
75 : override
76 ? runtimeAdapterOverride(override.npm)
77 : defaults.runtimeAdapter;
78 const configuredBaseUrl = connection.baseUrl?.trim();
79 const resolvedBaseUrl = configuredBaseUrl
80 ? effectiveBaseUrl(connection)
81 : (override?.api ?? effectiveBaseUrl(connection));
82 const wire = resolveModelRuntimeWire(connection.providerType, modelId, adapter, apiProtocol);
83 return {
84 adapter,
85 baseUrl:
86 connection.providerType === 'kimi-coding-plan' && apiProtocol === 'openai-chat'
87 ? kimiOpenAiBaseUrl(resolvedBaseUrl)
88 : resolvedBaseUrl,
89 ...(apiProtocol ? { apiProtocol } : {}),
90 wire,
91 reasoningReplay: reasoningReplayContract(adapter, wire),
92 applyPatchProfile: resolveApplyPatchProfile(
93 { wire, applyPatchProtocol: adapter.applyPatchProtocol },
94 modelId,
95 ),
96 };
97}
98
99export function modelUsesAnthropicMessages(
100 connection: ModelRuntimeConnection,

Callers 9

constructorMethod · 0.85
testConnectionModelFunction · 0.85
getAIModelFunction · 0.85
buildFamilyWireFunction · 0.85
constructorMethod · 0.85

Calls 8

effectiveBaseUrlFunction · 0.90
runtimeAdapterOverrideFunction · 0.85
resolveModelRuntimeWireFunction · 0.85
kimiOpenAiBaseUrlFunction · 0.85
reasoningReplayContractFunction · 0.85
resolveApplyPatchProfileFunction · 0.85
trimMethod · 0.45

Tested by

no test coverage detected