Files
OmniRoute/open-sse/translator/registry.ts
diegosouzapw 20860877b8 feat: add TypeScript types and modularize translator registry
- Add type annotations to all providerModels helper functions
- Introduce LegacyProvider interface in providerRegistry
- Refactor translator system to use self-registering module pattern
  with bootstrapTranslatorRegistry() and per-file imports
- Simplify translator/index.ts by delegating to modular translators
- Remove hardcoded Gemini OAuth client secret for security
2026-03-04 18:46:49 -03:00

42 lines
999 B
TypeScript

type RequestTranslator = (
model: string,
body: Record<string, unknown>,
stream?: boolean,
credentials?: Record<string, unknown> | null
) => unknown;
type ResponseTranslator = (
chunk: Record<string, unknown>,
state: Record<string, unknown>
) => unknown;
const requestRegistry = new Map<string, RequestTranslator>();
const responseRegistry = new Map<string, ResponseTranslator>();
function makeKey(from: string, to: string) {
return `${from}:${to}`;
}
export function register(
from: string,
to: string,
requestFn?: RequestTranslator,
responseFn?: ResponseTranslator
) {
const key = makeKey(from, to);
if (requestFn) {
requestRegistry.set(key, requestFn);
}
if (responseFn) {
responseRegistry.set(key, responseFn);
}
}
export function getRequestTranslator(from: string, to: string) {
return requestRegistry.get(makeKey(from, to));
}
export function getResponseTranslator(from: string, to: string) {
return responseRegistry.get(makeKey(from, to));
}