feat: harden intelligence runtime and llm providers
This commit is contained in:
@@ -58,7 +58,15 @@ export async function runSource(name, fn, ...args) {
|
||||
timer = setTimeout(() => reject(new Error(`Source ${name} timed out after ${SOURCE_TIMEOUT_MS / 1000}s`)), SOURCE_TIMEOUT_MS);
|
||||
});
|
||||
const data = await Promise.race([dataPromise, timeoutPromise]);
|
||||
return { name, status: 'ok', durationMs: Date.now() - start, data };
|
||||
const hasError = Boolean(data?.error);
|
||||
const isDegraded = hasError || ['no_credentials', 'degraded', 'failed'].includes(data?.status);
|
||||
return {
|
||||
name,
|
||||
status: isDegraded ? 'degraded' : 'ok',
|
||||
durationMs: Date.now() - start,
|
||||
data,
|
||||
error: hasError ? data.error : null,
|
||||
};
|
||||
} catch (e) {
|
||||
return { name, status: 'error', durationMs: Date.now() - start, error: e.message };
|
||||
} finally {
|
||||
@@ -127,14 +135,15 @@ export async function fullBriefing() {
|
||||
totalDurationMs: totalMs,
|
||||
sourcesQueried: sources.length,
|
||||
sourcesOk: sources.filter(s => s.status === 'ok').length,
|
||||
sourcesFailed: sources.filter(s => s.status !== 'ok').length,
|
||||
sourcesDegraded: sources.filter(s => s.status === 'degraded').length,
|
||||
sourcesFailed: sources.filter(s => s.status === 'error' || s.status === 'failed').length,
|
||||
},
|
||||
sources: Object.fromEntries(
|
||||
sources.filter(s => s.status === 'ok').map(s => [s.name, s.data])
|
||||
sources.filter(s => s.status === 'ok' || s.status === 'degraded').map(s => [s.name, s.data])
|
||||
),
|
||||
errors: sources.filter(s => s.status !== 'ok').map(s => ({ name: s.name, error: s.error })),
|
||||
errors: sources.filter(s => s.status !== 'ok').map(s => ({ name: s.name, status: s.status, error: s.error || s.data?.message || 'degraded' })),
|
||||
timing: Object.fromEntries(
|
||||
sources.map(s => [s.name, { status: s.status, ms: s.durationMs }])
|
||||
sources.map(s => [s.name, { status: s.status, ms: s.durationMs, error: s.error || null }])
|
||||
),
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user