mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-26 17:12:27 +03:00
perf(executors): lazy-load the executor registry — defer class imports + construction to first use (#11220) (#11421)
Validated in a combined 3-PR batch worktree off release/v3.8.51 tip (a sibling PR from the same author, #11495, was held out — a typecheck error in zai-web.ts only reproduced with this PR + #11495 boarded together, and cleared without #11495; isolated this PR alone confirmed clean on its own too, so the interaction belonged to #11495's side — see its comment). - Golden lock: executor-map-golden.test.ts — passes byte-identical (same keys, classes, provider identities, dispatch guards) - Focused tests part of batch's 94/94 node:test run - typecheck:core, file-size, changelog-integrity, complexity, cognitive-complexity — all OK - Full-repo lint: 228 pre-existing dashboard react-hooks/* findings, unrelated to this diff Thanks for the measured, careful methodology here — the golden-lock contract plus the isolated DATA_DIR benchmarking make this an easy PR to trust despite the wide surface (72 files).
This commit is contained in:
@@ -18,9 +18,10 @@ export function createPricedJudgeClient(
|
||||
provider: string,
|
||||
credentials: ProviderCredentials
|
||||
): ModelClient {
|
||||
const executor = getExecutor(provider);
|
||||
return {
|
||||
async complete(model: string, messages: ChatTurn[]): Promise<ModelCallResult> {
|
||||
// #11220: getExecutor is async (lazy registry) — resolve per call.
|
||||
const executor = await getExecutor(provider);
|
||||
const input: ExecuteInput = {
|
||||
model,
|
||||
body: { model, messages, stream: false },
|
||||
|
||||
@@ -132,12 +132,13 @@ export async function validateClaudeOAuthInline({
|
||||
modelId: string | null | undefined;
|
||||
providerSpecificData?: Record<string, unknown>;
|
||||
}) {
|
||||
const testModelId =
|
||||
providerSpecificData?.validationModelId || modelId || "claude-haiku-4-5-20251001";
|
||||
const override = providerSpecificData?.validationModelId;
|
||||
const testModelId: string =
|
||||
typeof override === "string" && override ? override : modelId || "claude-haiku-4-5-20251001";
|
||||
|
||||
try {
|
||||
const { getExecutor } = await import("@omniroute/open-sse/executors/index.ts");
|
||||
const { response } = await getExecutor("claude").execute({
|
||||
const executed = await (await getExecutor("claude")).execute({
|
||||
model: testModelId,
|
||||
body: {
|
||||
model: testModelId,
|
||||
@@ -148,6 +149,7 @@ export async function validateClaudeOAuthInline({
|
||||
credentials: { accessToken: apiKey, providerSpecificData },
|
||||
});
|
||||
|
||||
const response = executed instanceof Response ? executed : executed.response;
|
||||
if (response.status === 401 || response.status === 403) {
|
||||
return { valid: false, error: "Invalid OAuth token" };
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
import { logger } from "@omniroute/open-sse/utils/logger.ts";
|
||||
import { sanitizeErrorMessage } from "@omniroute/open-sse/utils/error.ts";
|
||||
import { getExecutor } from "@omniroute/open-sse/executors/index.ts";
|
||||
import type { BaseExecutor } from "@omniroute/open-sse/executors/base";
|
||||
import { getCodexUsage } from "@omniroute/open-sse/services/usage/codex.ts";
|
||||
import { getSettings, getProviderConnections, updateProviderConnection } from "@/lib/localDb";
|
||||
import { isConnectionUnavailableToAuxiliaryActivity } from "@/lib/exclusiveLeaseIsolation";
|
||||
@@ -67,7 +68,7 @@ export interface QuotaAutoPingDeps {
|
||||
accessToken?: string,
|
||||
providerSpecificData?: JsonRecord
|
||||
) => Promise<JsonRecord>;
|
||||
getExecutor: (provider: string) => { execute: (input: JsonRecord) => Promise<JsonRecord> };
|
||||
getExecutor: (provider: string) => Promise<BaseExecutor>;
|
||||
canExecuteProvider: (provider: string) => boolean;
|
||||
isConnectionUnavailableToAuxiliaryActivity: (connectionId: string) => Promise<boolean>;
|
||||
}
|
||||
@@ -208,7 +209,7 @@ async function sendCodexPing(
|
||||
providerConfig: QuotaAutoPingProviderConfig,
|
||||
deps: QuotaAutoPingDeps
|
||||
): Promise<boolean> {
|
||||
const executor = deps.getExecutor("codex");
|
||||
const executor = await deps.getExecutor("codex");
|
||||
const result = await executor.execute({
|
||||
model: providerConfig.pingModel,
|
||||
stream: true,
|
||||
|
||||
Reference in New Issue
Block a user