mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-15 23:12:04 +00:00
feat(insights): render AI parts from the capability map, never as errors
The daily briefing, the hero's briefing paragraph, the trend sentences and the status notes follow the briefing and statusText capabilities: hidden while unavailable, never an error card or a per-card "connect a provider" state. The advisor and status reads only fire while their capability is available; a 403 settles as an outcome instead of throwing. A failed comprehensive read no longer replaces the overview, and every overview section is fenced so a section that throws becomes one error row. The period review always renders its composed narrative. Cycle, breathing and lab-change sections go through the surface map. One calm setup hint appears on the overview while no provider is configured and one could be. Signals, rhythm events and the mood patterns card say a failed read with a retry, the score anatomy no longer calls a failed read insufficient data, the catalog marks only the rows whose read failed, and workouts are not probed while the module is off.
This commit is contained in:
1 parent
61d912627d
commit
48d97ef70d
23 files changed
+687
-460
No files matched your search
@@ -2,6 +2,7 @@
|
||||
|
||||
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import { useAiCapability } from "@/hooks/use-ai-capability";
|
||||
import { useAuth } from "@/hooks/use-auth";
|
||||
import { useTranslations } from "@/lib/i18n/context";
|
||||
import type { MetricStatusMetricId } from "@/lib/insights/metric-status-registry";
|
||||
@@ -295,6 +296,10 @@ const QUERY_KEY_FACTORY: Record<
|
||||
*/
|
||||
export function useInsightStatus(metric: InsightStatusMetric) {
|
||||
const { isAuthenticated } = useAuth();
|
||||
// Status notes are model-written: no read while the `statusText`
|
||||
// capability is unavailable (the card is hidden then anyway). Unavailable
|
||||
// while `/me` loads, so the first paint fires nothing.
|
||||
const statusText = useAiCapability("statusText");
|
||||
const { locale } = useTranslations();
|
||||
const queryKey = QUERY_KEY_FACTORY[metric](locale);
|
||||
|
||||
@@ -305,7 +310,7 @@ export function useInsightStatus(metric: InsightStatusMetric) {
|
||||
`/api/insights/${metric}-status?locale=${locale}`,
|
||||
signal,
|
||||
),
|
||||
enabled: isAuthenticated,
|
||||
enabled: isAuthenticated && statusText.available,
|
||||
staleTime: 60 * 1000,
|
||||
// v1.4.28 FB-D2 — the status route returns a deterministic envelope on
|
||||
// a miss/timeout. Retrying inline re-fires work and lengthens the
|
||||
@@ -359,6 +364,7 @@ export function useInsightMetricStatus(
|
||||
enabled = true,
|
||||
) {
|
||||
const { isAuthenticated } = useAuth();
|
||||
const statusText = useAiCapability("statusText");
|
||||
const { locale } = useTranslations();
|
||||
const queryKey = queryKeys.insightsMetricStatus(metric, locale);
|
||||
|
||||
@@ -371,7 +377,7 @@ export function useInsightMetricStatus(
|
||||
)}&locale=${locale}`,
|
||||
signal,
|
||||
),
|
||||
enabled: isAuthenticated && enabled,
|
||||
enabled: isAuthenticated && enabled && statusText.available,
|
||||
staleTime: 60 * 1000,
|
||||
retry: 0,
|
||||
refetchInterval: (query) =>
|
||||
@@ -409,6 +415,7 @@ export function useInsightBiomarkerAssessment(
|
||||
enabled = true,
|
||||
) {
|
||||
const { isAuthenticated } = useAuth();
|
||||
const statusText = useAiCapability("statusText");
|
||||
const { locale } = useTranslations();
|
||||
const queryKey = queryKeys.insightsBiomarkerAssessment(biomarkerId, locale);
|
||||
|
||||
@@ -421,7 +428,11 @@ export function useInsightBiomarkerAssessment(
|
||||
)}&locale=${locale}`,
|
||||
signal,
|
||||
),
|
||||
enabled: isAuthenticated && enabled && biomarkerId.length > 0,
|
||||
enabled:
|
||||
isAuthenticated &&
|
||||
enabled &&
|
||||
statusText.available &&
|
||||
biomarkerId.length > 0,
|
||||
staleTime: 60 * 1000,
|
||||
retry: 0,
|
||||
refetchInterval: (query) =>
|
||||
|
||||
@@ -70,6 +70,12 @@ export interface UseWorkoutsOptions {
|
||||
since?: string;
|
||||
/** Optional sport-type filter. Pass through the canonical string. */
|
||||
sportType?: string;
|
||||
/**
|
||||
* Whether to read at all. A probe on a surface that shows workouts only
|
||||
* while the Workouts module is on passes the module answer here, so a
|
||||
* switched-off module is never asked for rows. Defaults to true.
|
||||
*/
|
||||
enabled?: boolean;
|
||||
}
|
||||
|
||||
async function fetchWorkouts(
|
||||
@@ -108,7 +114,7 @@ export function useWorkouts(opts: UseWorkoutsOptions = {}): UseWorkoutsResult {
|
||||
sportType: opts.sportType,
|
||||
}),
|
||||
queryFn: () => fetchWorkouts(opts),
|
||||
enabled: isAuthenticated,
|
||||
enabled: isAuthenticated && opts.enabled !== false,
|
||||
staleTime: 60 * 1000,
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user