(input: {
providers: { keyEnv?: string; keySet?: boolean }[];
schedulesEnabled: number;
botRunning: boolean;
modelSet: boolean;
lastRunStatus?: string;
/** Content-grade web-search keys (Firecrawl/Tavily/Brave): how many are set, and the first
* missing one to suggest. Omitted → no badge (old callers unaffected). */
webKeys?: { set: number; total: number; suggest?: { service: string; env: string; url: string } };
})
| 13 | |
| 14 | /** Roll up a few at-a-glance health signals from the gathered dashboard facts. PURE. */ |
| 15 | export function computeHealth(input: { |
| 16 | providers: { keyEnv?: string; keySet?: boolean }[]; |
| 17 | schedulesEnabled: number; |
| 18 | botRunning: boolean; |
| 19 | modelSet: boolean; |
| 20 | lastRunStatus?: string; |
| 21 | /** Content-grade web-search keys (Firecrawl/Tavily/Brave): how many are set, and the first |
| 22 | * missing one to suggest. Omitted → no badge (old callers unaffected). */ |
| 23 | webKeys?: { set: number; total: number; suggest?: { service: string; env: string; url: string } }; |
| 24 | }): HealthItem[] { |
| 25 | const cloud = input.providers.filter(p => p.keyEnv); |
| 26 | const ready = cloud.filter(p => p.keySet).length; |
| 27 | const items: HealthItem[] = []; |
| 28 | items.push({ |
| 29 | label: 'Provider keys', |
| 30 | ok: cloud.length === 0 || ready === cloud.length, |
| 31 | detail: cloud.length === 0 ? 'all local' : `${ready}/${cloud.length} cloud keys set`, |
| 32 | }); |
| 33 | items.push({ label: 'Default model', ok: input.modelSet, detail: input.modelSet ? 'configured' : 'unset — run `qodex setup`' }); |
| 34 | if (input.webKeys) { |
| 35 | const w = input.webKeys; |
| 36 | items.push({ |
| 37 | label: 'Web search', |
| 38 | ok: w.set > 0, |
| 39 | detail: w.set > 0 |
| 40 | ? `${w.set}/${w.total} content-grade backend(s) keyed` |
| 41 | : `keyless fallback only — ${w.suggest ? `get a free ${w.suggest.service} key at ${w.suggest.url} (${w.suggest.env})` : 'set a search API key'}`, |
| 42 | }); |
| 43 | } |
| 44 | items.push({ label: 'Scheduler', ok: true, detail: `${input.schedulesEnabled} task(s) enabled` }); |
| 45 | items.push({ label: 'Bot', ok: true, detail: input.botRunning ? 'running' : 'stopped' }); |
| 46 | if (input.lastRunStatus) { |
| 47 | items.push({ label: 'Last scheduled run', ok: input.lastRunStatus === 'success', detail: input.lastRunStatus }); |
| 48 | } |
| 49 | return items; |
| 50 | } |
no test coverage detected