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

Function resolveConnectionTestModel

packages/runtime/src/test-connection.ts:41–66  ·  view source on GitHub ↗

* Prefer an explicit model, then a still-live configured model. Legacy * connections without a discovered inventory keep the historical * default/fallback order.

(
  connection: ConnectionEffectConnection,
  model: string | undefined,
  fallbackModels: readonly string[],
)

Source from the content-addressed store, hash-verified

39 * default/fallback order.
40 */
41function resolveConnectionTestModel(
42 connection: ConnectionEffectConnection,
43 model: string | undefined,
44 fallbackModels: readonly string[],
45): string | undefined {
46 const explicitModel = model?.trim();
47 if (explicitModel) return explicitModel;
48
49 const hasAuthoritativeInventory =
50 connection.modelSource === 'fetched' && Array.isArray(connection.models);
51 const discoveredIds =
52 connection.models?.map(({ id }) => id.trim()).filter((id) => id.length > 0) ?? [];
53 const discovered =
54 hasAuthoritativeInventory || discoveredIds.length > 0 ? new Set(discoveredIds) : undefined;
55 const candidates = [
56 ...connectionEnabledModelIds(connection),
57 ...fallbackModels,
58 ...discoveredIds,
59 ];
60 for (const candidate of candidates) {
61 const id = candidate.trim();
62 if (!id || (discovered && !discovered.has(id))) continue;
63 return id;
64 }
65 return undefined;
66}
67
68export async function testConnection(
69 connection: LlmConnection,

Callers 1

testConnectionStrictFunction · 0.85

Calls 3

hasMethod · 0.65
trimMethod · 0.45

Tested by

no test coverage detected