update ai insight migration for all page

This commit is contained in:
Alberto-Audrix committed 2026-09-17 10:11:14 +07:00
1 parent 07d36081ce
commit 18790ab8f6
69 files changed
+9457 -399

No files matched your search

+99 -4
View File
@@ -209,17 +209,112 @@ export type PanelIoT = {
export type AIInsight = {
id: number;
cycle: number;
kandang: number;
flock_id: number;
kandang: number | null;
flock_id?: number;
date: string;
insight_text: string;
/** Condition from graded facts: healthy | warning | critical | unknown */
alert: string;
section: string;
session: string;
topic: string;
report_type: string;
report_period: string;
source?: InsightSource;
summary?: string;
citations?: InsightCitation[];
created_at: string;
updated_at: string;
};
/** Source label shown in AI Insight UI — never hide local fallback as LLM. */
export type InsightSource = 'generated' | 'cache' | 'local_fallback';
export type InsightReportType = 'page' | 'daily' | 'weekly' | 'end_cycle';
export type InsightTopic =
| 'hitung_ayam'
| 'berat_ayam'
| 'fcr'
| 'eef'
| 'iot_panel'
| 'hitung_karung'
| 'dashboard';
export type InsightCitation = {
id?: string;
title?: string;
chapter?: string;
excerpt?: string;
source?: string;
};
/**
* Curated page context sent to the insight service.
* `kandangId` is required — never generate for "all kandang".
*/
export type InsightContext = {
kandangId: number;
kandangName?: string;
cycleId?: number;
hari_ke?: number | null;
totalDays?: number | null;
periode?: string | null;
[key: string]: unknown;
};
export type InsightGenerateParams = {
cycle_id: number;
kandang_id: number;
topic: InsightTopic | string;
report_type?: InsightReportType;
report_period?: string | null;
context: InsightContext;
force_refresh?: boolean;
};
export type InsightCachedParams = {
cycle_id: number;
kandang_id: number;
topic: InsightTopic | string;
report_type?: InsightReportType;
report_period?: string | null;
};
export type InsightStatusLabel = 'ok' | 'warning' | 'critical' | 'unknown';
export type InsightStructuredSection = {
status: InsightStatusLabel;
bullets: string[];
evidence: string[];
actions: string[];
};
export type InsightStructuredReport = {
summary: {
headline: string;
bullets: string[];
risks: string[];
actions: string[];
};
detailed?: Partial<
Record<
'hitung_ayam' | 'berat_ayam' | 'fcr' | 'eef' | 'panel_iot' | 'data_quality',
InsightStructuredSection
>
>;
};
/** Response from generate / cached insight endpoints. */
export type InsightApiResponse = {
success?: boolean;
source: InsightSource;
insight_text: string;
summary?: string;
insight?: string;
structured?: InsightStructuredReport | null;
citations?: InsightCitation[];
message?: string;
};
export type KarungRequestResult = {
karung: Karung;
upstream: Record<string, unknown>;