mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-18 05:02:15 +03:00
Implements the secure, opt-in Video Bridge for issue #9760, including bounded FFmpeg frame extraction, capability-aware routing, telemetry, settings UI, localization, documentation, and regression coverage.
85 lines
3.0 KiB
TypeScript
85 lines
3.0 KiB
TypeScript
/**
|
|
* Build-local capability/context/override resolution snapshot (#9199).
|
|
*
|
|
* Catalog preparation bulk-loads the capability and custom-model tables once into a
|
|
* build-local view for pure in-memory resolution. This must not flip models.dev's
|
|
* module-global all-row cache, and ordinary runtime callers keep on-demand DB reads.
|
|
*
|
|
* Override maps are nested by provider then model so provider/model pairs cannot
|
|
* collide via delimiter composition.
|
|
*/
|
|
import { listModelCapabilityOverrides } from "@/lib/db/modelCapabilityOverrides";
|
|
import { listModelContextOverrides } from "@/lib/db/modelContextOverrides";
|
|
import {
|
|
listCustomModelVisionOverrides,
|
|
type CustomModelVisionOverrideMap,
|
|
type CustomModelVisionOverrideReadOptions,
|
|
} from "@/lib/db/models";
|
|
import {
|
|
loadAllSyncedCapabilitiesUncached,
|
|
type CapabilitiesByProvider,
|
|
} from "@/lib/modelsDevSync";
|
|
|
|
/** Nested provider → model → numeric override map (collision-free). */
|
|
export type NestedOverrideMap = ReadonlyMap<string, ReadonlyMap<string, number>>;
|
|
|
|
export interface ModelCapabilityResolutionSnapshot {
|
|
readonly synced: CapabilitiesByProvider;
|
|
readonly maxTokenOverrides: NestedOverrideMap;
|
|
readonly maxInputTokenOverrides: NestedOverrideMap;
|
|
readonly contextOverrides: NestedOverrideMap;
|
|
readonly customVisionOverrides: CustomModelVisionOverrideMap;
|
|
}
|
|
|
|
export interface ModelCapabilityResolutionSnapshotOptions {
|
|
customModelVision?: CustomModelVisionOverrideReadOptions;
|
|
}
|
|
|
|
function setNestedOverride(
|
|
map: Map<string, Map<string, number>>,
|
|
provider: string,
|
|
modelId: string,
|
|
value: number
|
|
): void {
|
|
let byModel = map.get(provider);
|
|
if (!byModel) {
|
|
byModel = new Map();
|
|
map.set(provider, byModel);
|
|
}
|
|
byModel.set(modelId, value);
|
|
}
|
|
|
|
/**
|
|
* Load all capability/custom-model tables in one uninterrupted JS turn.
|
|
* Callers must not yield between the bulk reads if they need a coherent view;
|
|
* existing catalog generation guards remain authoritative across later yields.
|
|
*/
|
|
export function createModelCapabilityResolutionSnapshot(
|
|
options: ModelCapabilityResolutionSnapshotOptions = {}
|
|
): ModelCapabilityResolutionSnapshot {
|
|
const synced = loadAllSyncedCapabilitiesUncached();
|
|
|
|
const maxTokenOverrides = new Map<string, Map<string, number>>();
|
|
const maxInputTokenOverrides = new Map<string, Map<string, number>>();
|
|
for (const entry of listModelCapabilityOverrides()) {
|
|
if (entry.key === "max_output_tokens") {
|
|
setNestedOverride(maxTokenOverrides, entry.provider, entry.modelId, entry.value);
|
|
} else if (entry.key === "max_input_tokens") {
|
|
setNestedOverride(maxInputTokenOverrides, entry.provider, entry.modelId, entry.value);
|
|
}
|
|
}
|
|
|
|
const contextOverrides = new Map<string, Map<string, number>>();
|
|
for (const entry of listModelContextOverrides()) {
|
|
setNestedOverride(contextOverrides, entry.provider, entry.modelId, entry.realContext);
|
|
}
|
|
|
|
return {
|
|
synced,
|
|
maxTokenOverrides,
|
|
maxInputTokenOverrides,
|
|
contextOverrides,
|
|
customVisionOverrides: listCustomModelVisionOverrides(options.customModelVision),
|
|
};
|
|
}
|