chore: migrate to oxlint and oxfmt
Co-authored-by: Christoph Nakazawa <christoph.pojer@gmail.com>
This commit is contained in:
@@ -79,11 +79,7 @@ export type OpenRouterScanOptions = {
|
||||
maxAgeDays?: number;
|
||||
providerFilter?: string;
|
||||
probe?: boolean;
|
||||
onProgress?: (update: {
|
||||
phase: "catalog" | "probe";
|
||||
completed: number;
|
||||
total: number;
|
||||
}) => void;
|
||||
onProgress?: (update: { phase: "catalog" | "probe"; completed: number; total: number }) => void;
|
||||
};
|
||||
|
||||
type OpenAIModel = Model<"openai-completions">;
|
||||
@@ -97,9 +93,7 @@ function normalizeCreatedAtMs(value: unknown): number | null {
|
||||
|
||||
function inferParamBFromIdOrName(text: string): number | null {
|
||||
const raw = text.toLowerCase();
|
||||
const matches = raw.matchAll(
|
||||
/(?:^|[^a-z0-9])[a-z]?(\d+(?:\.\d+)?)b(?:[^a-z0-9]|$)/g,
|
||||
);
|
||||
const matches = raw.matchAll(/(?:^|[^a-z0-9])[a-z]?(\d+(?:\.\d+)?)b(?:[^a-z0-9]|$)/g);
|
||||
let best: number | null = null;
|
||||
for (const match of matches) {
|
||||
const numRaw = match[1];
|
||||
@@ -169,9 +163,7 @@ async function withTimeout<T>(
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchOpenRouterModels(
|
||||
fetchImpl: typeof fetch,
|
||||
): Promise<OpenRouterModelMeta[]> {
|
||||
async function fetchOpenRouterModels(fetchImpl: typeof fetch): Promise<OpenRouterModelMeta[]> {
|
||||
const res = await fetchImpl(OPENROUTER_MODELS_URL, {
|
||||
headers: { Accept: "application/json" },
|
||||
});
|
||||
@@ -187,21 +179,17 @@ async function fetchOpenRouterModels(
|
||||
const obj = entry as Record<string, unknown>;
|
||||
const id = typeof obj.id === "string" ? obj.id.trim() : "";
|
||||
if (!id) return null;
|
||||
const name =
|
||||
typeof obj.name === "string" && obj.name.trim() ? obj.name.trim() : id;
|
||||
const name = typeof obj.name === "string" && obj.name.trim() ? obj.name.trim() : id;
|
||||
|
||||
const contextLength =
|
||||
typeof obj.context_length === "number" &&
|
||||
Number.isFinite(obj.context_length)
|
||||
typeof obj.context_length === "number" && Number.isFinite(obj.context_length)
|
||||
? obj.context_length
|
||||
: null;
|
||||
|
||||
const maxCompletionTokens =
|
||||
typeof obj.max_completion_tokens === "number" &&
|
||||
Number.isFinite(obj.max_completion_tokens)
|
||||
typeof obj.max_completion_tokens === "number" && Number.isFinite(obj.max_completion_tokens)
|
||||
? obj.max_completion_tokens
|
||||
: typeof obj.max_output_tokens === "number" &&
|
||||
Number.isFinite(obj.max_output_tokens)
|
||||
: typeof obj.max_output_tokens === "number" && Number.isFinite(obj.max_output_tokens)
|
||||
? obj.max_output_tokens
|
||||
: null;
|
||||
|
||||
@@ -216,9 +204,7 @@ async function fetchOpenRouterModels(
|
||||
const supportsToolsMeta = supportedParameters.includes("tools");
|
||||
|
||||
const modality =
|
||||
typeof obj.modality === "string" && obj.modality.trim()
|
||||
? obj.modality.trim()
|
||||
: null;
|
||||
typeof obj.modality === "string" && obj.modality.trim() ? obj.modality.trim() : null;
|
||||
|
||||
const inferredParamB = inferParamBFromIdOrName(`${id} ${name}`);
|
||||
const createdAtMs = normalizeCreatedAtMs(obj.created_at);
|
||||
@@ -268,9 +254,7 @@ async function probeTool(
|
||||
} satisfies OpenAICompletionsOptions),
|
||||
);
|
||||
|
||||
const hasToolCall = message.content.some(
|
||||
(block) => block.type === "toolCall",
|
||||
);
|
||||
const hasToolCall = message.content.some((block) => block.type === "toolCall");
|
||||
if (!hasToolCall) {
|
||||
return {
|
||||
ok: false,
|
||||
@@ -361,9 +345,7 @@ async function mapWithConcurrency<T, R>(
|
||||
return results;
|
||||
}
|
||||
|
||||
await Promise.all(
|
||||
Array.from({ length: Math.min(limit, items.length) }, () => worker()),
|
||||
);
|
||||
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()));
|
||||
return results;
|
||||
}
|
||||
|
||||
@@ -374,19 +356,11 @@ export async function scanOpenRouterModels(
|
||||
const probe = options.probe ?? true;
|
||||
const apiKey = options.apiKey?.trim() || getEnvApiKey("openrouter") || "";
|
||||
if (probe && !apiKey) {
|
||||
throw new Error(
|
||||
"Missing OpenRouter API key. Set OPENROUTER_API_KEY to run models scan.",
|
||||
);
|
||||
throw new Error("Missing OpenRouter API key. Set OPENROUTER_API_KEY to run models scan.");
|
||||
}
|
||||
|
||||
const timeoutMs = Math.max(
|
||||
1,
|
||||
Math.floor(options.timeoutMs ?? DEFAULT_TIMEOUT_MS),
|
||||
);
|
||||
const concurrency = Math.max(
|
||||
1,
|
||||
Math.floor(options.concurrency ?? DEFAULT_CONCURRENCY),
|
||||
);
|
||||
const timeoutMs = Math.max(1, Math.floor(options.timeoutMs ?? DEFAULT_TIMEOUT_MS));
|
||||
const concurrency = Math.max(1, Math.floor(options.concurrency ?? DEFAULT_CONCURRENCY));
|
||||
const minParamB = Math.max(0, Math.floor(options.minParamB ?? 0));
|
||||
const maxAgeDays = Math.max(0, Math.floor(options.maxAgeDays ?? 0));
|
||||
const providerFilter = options.providerFilter?.trim().toLowerCase() ?? "";
|
||||
|
||||
Reference in New Issue
Block a user