mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-15 03:32:21 +03:00
Introduce runtime-configurable payload mutation/filter rules with file reload support and a settings API so upstream request bodies can be customized per model and protocol without restarts. Expand search support with Google PSE, Linkup, SearchAPI, and SearXNG, including validation, routing, analytics costing, MCP schema updates, and search-type-aware provider selection. Update Pollinations to support anonymous access, endpoint failover, and the latest public model lineup. Add OmniRoute response metadata headers/SSE comments, per-connection model exclusion rules, combo tag-based routing, buffered spend writes, and scheduled daily/weekly/monthly budget resets. Update model catalog and dashboard UIs to surface source labels and hide models excluded by all active connections.
65 lines
2.0 KiB
TypeScript
65 lines
2.0 KiB
TypeScript
type JsonRecord = Record<string, unknown>;
|
|
|
|
export type RoutingTagMatchMode = "any" | "all";
|
|
|
|
function asRecord(value: unknown): JsonRecord {
|
|
return value && typeof value === "object" && !Array.isArray(value) ? (value as JsonRecord) : {};
|
|
}
|
|
|
|
function normalizeSingleRoutingTag(value: unknown): string | null {
|
|
if (typeof value !== "string") return null;
|
|
const normalized = value.trim().toLowerCase();
|
|
return normalized.length > 0 ? normalized : null;
|
|
}
|
|
|
|
export function normalizeRoutingTags(value: unknown): string[] {
|
|
const rawValues = Array.isArray(value)
|
|
? value
|
|
: typeof value === "string"
|
|
? value.split(",")
|
|
: [];
|
|
|
|
const deduped = new Set<string>();
|
|
for (const rawValue of rawValues) {
|
|
const normalized = normalizeSingleRoutingTag(rawValue);
|
|
if (normalized) deduped.add(normalized);
|
|
}
|
|
return Array.from(deduped);
|
|
}
|
|
|
|
export function normalizeRoutingTagMatchMode(value: unknown): RoutingTagMatchMode {
|
|
const normalized =
|
|
typeof value === "string" ? value.trim().toLowerCase() : typeof value === "number" ? "" : "";
|
|
return normalized === "all" ? "all" : "any";
|
|
}
|
|
|
|
export function getConnectionRoutingTags(providerSpecificData: unknown): string[] {
|
|
return normalizeRoutingTags(asRecord(providerSpecificData).tags);
|
|
}
|
|
|
|
export function matchesRoutingTags(
|
|
connectionTags: string[],
|
|
requestTags: string[],
|
|
matchMode: RoutingTagMatchMode = "any"
|
|
): boolean {
|
|
if (requestTags.length === 0) return true;
|
|
if (connectionTags.length === 0) return false;
|
|
|
|
const tagSet = new Set(connectionTags);
|
|
if (matchMode === "all") {
|
|
return requestTags.every((tag) => tagSet.has(tag));
|
|
}
|
|
return requestTags.some((tag) => tagSet.has(tag));
|
|
}
|
|
|
|
export function resolveRequestRoutingTags(body: Record<string, unknown> | null | undefined): {
|
|
tags: string[];
|
|
matchMode: RoutingTagMatchMode;
|
|
} {
|
|
const metadata = asRecord(body?.metadata);
|
|
return {
|
|
tags: normalizeRoutingTags(metadata.tags),
|
|
matchMode: normalizeRoutingTagMatchMode(metadata.tag_match_mode ?? metadata.tagMatchMode),
|
|
};
|
|
}
|