File size: 1,328 Bytes
e249c6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import type { AgentRuntimeAuthModelRoute } from "./types.js";

function normalizeRouteBaseUrl(value: string): string {
  return value.replace(/\/+$/u, "");
}

function sameCompatibleRuntimeIds(
  left: readonly string[] | undefined,
  right: readonly string[] | undefined,
): boolean {
  if (left === right) {
    return true;
  }
  if (!left || !right) {
    return false;
  }
  const leftIds = new Set(left);
  const rightIds = new Set(right);
  if (leftIds.size !== rightIds.size) {
    return false;
  }
  for (const id of leftIds) {
    if (!rightIds.has(id)) {
      return false;
    }
  }
  return true;
}

/** Compares the complete secret-free identity of two prepared model routes. */
export function sameAgentRuntimeAuthModelRoute(
  left: AgentRuntimeAuthModelRoute,
  right: AgentRuntimeAuthModelRoute,
): boolean {
  return (
    left.provider.trim().toLowerCase() === right.provider.trim().toLowerCase() &&
    left.modelId === right.modelId &&
    left.api === right.api &&
    left.authRequirement === right.authRequirement &&
    left.requestTransportOverrides === right.requestTransportOverrides &&
    sameCompatibleRuntimeIds(
      left.runtimePolicy?.compatibleIds,
      right.runtimePolicy?.compatibleIds,
    ) &&
    normalizeRouteBaseUrl(left.baseUrl) === normalizeRouteBaseUrl(right.baseUrl)
  );
}