mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-06 23:32:12 +03:00
* refactor(cli): remove legacy Qwen Code integration * refactor(qwen): remove deprecated Qwen OAuth provider * feat(cli): rebuild Qwen Code integration for upstream V4 * fix(qwen): clear stale CLI auth on reset * test(qwen): align retired provider coverage * fix(db): renumber qwen-cleanup migration 129 -> 130 release/v3.8.49 tip took slot 129 via #7843 (usage_history_codex_strong_identity, itself renumbered from 128 during the #7838/#7840 base-red cleanup) after this branch forked; renumber remove_unregistered_qwen_data to 130. Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> --------- Co-authored-by: Diego Rodrigues de Sa e Souza <8016841+diegosouzapw@users.noreply.github.com>
64 lines
1.6 KiB
TypeScript
64 lines
1.6 KiB
TypeScript
/**
|
|
* Request Timeout Utility — FASE-04 Observability
|
|
*
|
|
* Wraps fetch/async calls with configurable timeouts and
|
|
* abort controller support.
|
|
*
|
|
* @module shared/utils/requestTimeout
|
|
*/
|
|
|
|
/**
|
|
* Execute any async function with a timeout.
|
|
*
|
|
* @template T
|
|
* @param {() => Promise<T>} fn - Async function to execute
|
|
* @param {number} timeoutMs - Timeout in milliseconds
|
|
* @param {string} [label='Operation'] - Label for error messages
|
|
* @returns {Promise<T>}
|
|
* @throws {Error} With name 'TimeoutError' if operation times out
|
|
*/
|
|
export async function withTimeout<T>(
|
|
fn: () => Promise<T>,
|
|
timeoutMs: number,
|
|
label = "Operation"
|
|
): Promise<T> {
|
|
return new Promise<T>((resolve, reject) => {
|
|
const timeoutId = setTimeout(() => {
|
|
const error: any = new Error(`${label} timed out after ${timeoutMs}ms`);
|
|
error.name = "TimeoutError";
|
|
error.timeoutMs = timeoutMs;
|
|
reject(error);
|
|
}, timeoutMs);
|
|
|
|
fn()
|
|
.then((result) => {
|
|
clearTimeout(timeoutId);
|
|
resolve(result);
|
|
})
|
|
.catch((error) => {
|
|
clearTimeout(timeoutId);
|
|
reject(error);
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Default provider timeouts (ms).
|
|
*/
|
|
export const PROVIDER_TIMEOUTS: Record<string, number> = {
|
|
openai: 60000,
|
|
claude: 90000, // Claude can be slower for long outputs
|
|
gemini: 60000,
|
|
codex: 120000, // Coding tasks often take longer
|
|
deepseek: 60000,
|
|
cohere: 45000,
|
|
groq: 30000, // Groq is fast
|
|
mistral: 45000,
|
|
openrouter: 60000,
|
|
default: 60000,
|
|
};
|
|
|
|
export function getProviderTimeout(provider: string): number {
|
|
return PROVIDER_TIMEOUTS[provider] || PROVIDER_TIMEOUTS.default;
|
|
}
|