openclaw / src /agents /runtime-plan /model-route.ts
SaylorTwift's picture
SaylorTwift HF Staff
Add files using upload-large-folder tool
e249c6d verified
Raw History Blame Contribute Delete
1.33 kB
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)
);
}