localgreenchain/lib/agents/types.ts
Claude 507df5912f
Deploy GrowerAdvisoryAgent (Agent 10) and fix type errors
- Add GrowerAdvisoryAgent test file
- Fix PlantChain constructor initialization order (plantIndex before genesis block)
- Fix blockchain.getChain() calls to use blockchain.chain property
- Add PropagationType export to blockchain types
- Fix SoilComposition.type property references (was soilType)
- Fix ClimateConditions.temperatureDay property references (was avgTemperature)
- Fix ClimateConditions.humidityAverage property references (was avgHumidity)
- Fix LightingConditions.naturalLight.hoursPerDay nested access
- Add 'critical' severity to QualityReport issues
- Add 'sqm' unit to PlantingRecommendation.quantityUnit
- Fix GrowerAdvisoryAgent growthMetrics property access
- Update TypeScript to v5 for react-hook-form compatibility
- Enable downlevelIteration in tsconfig for Map iteration
- Fix crypto Buffer type issues in anonymity.ts
- Fix zones.tsx status type comparison
- Fix next.config.js images.domains filter
- Rename [[...slug]].tsx to [...slug].tsx to resolve routing conflict
2025-11-23 00:44:58 +00:00

166 lines
3.7 KiB
TypeScript

/**
* Agent Types for LocalGreenChain
* Defines common interfaces and types for all autonomous agents
*/
export type AgentStatus = 'idle' | 'running' | 'paused' | 'error' | 'completed';
export type AgentPriority = 'low' | 'medium' | 'high' | 'critical';
export interface AgentConfig {
id: string;
name: string;
description: string;
enabled: boolean;
intervalMs: number;
priority: AgentPriority;
maxRetries: number;
timeoutMs: number;
}
export interface AgentTask {
id: string;
agentId: string;
type: string;
payload: Record<string, any>;
priority: AgentPriority;
createdAt: string;
scheduledFor?: string;
status: 'pending' | 'running' | 'completed' | 'failed';
result?: any;
error?: string;
retryCount: number;
}
export interface AgentMetrics {
agentId: string;
tasksCompleted: number;
tasksFailed: number;
averageExecutionMs: number;
lastRunAt: string | null;
lastSuccessAt: string | null;
lastErrorAt: string | null;
uptime: number;
errors: AgentError[];
}
export interface AgentError {
timestamp: string;
message: string;
taskId?: string;
stack?: string;
}
export interface AgentEvent {
id: string;
agentId: string;
eventType: 'task_started' | 'task_completed' | 'task_failed' | 'agent_started' | 'agent_stopped' | 'alert';
timestamp: string;
data: Record<string, any>;
}
export interface AgentAlert {
id: string;
agentId: string;
severity: 'info' | 'warning' | 'error' | 'critical';
title: string;
message: string;
timestamp: string;
acknowledged: boolean;
actionRequired?: string;
relatedEntityId?: string;
relatedEntityType?: string;
}
export interface BaseAgent {
config: AgentConfig;
status: AgentStatus;
metrics: AgentMetrics;
start(): Promise<void>;
stop(): Promise<void>;
pause(): void;
resume(): void;
runOnce(): Promise<AgentTask | null>;
getMetrics(): AgentMetrics;
getAlerts(): AgentAlert[];
}
// Recommendation types
export interface PlantingRecommendation {
id: string;
growerId: string;
produceType: string;
recommendedQuantity: number;
quantityUnit: string;
expectedYieldKg: number;
projectedRevenue: number;
riskLevel: 'low' | 'medium' | 'high';
explanation: string;
demandSignalIds: string[];
timestamp: string;
}
export interface EnvironmentRecommendation {
plantId: string;
category: string;
currentValue: any;
recommendedValue: any;
priority: 'low' | 'medium' | 'high';
reason: string;
expectedImpact: string;
}
export interface MarketMatch {
id: string;
supplyId: string;
demandSignalId: string;
produceType: string;
matchedQuantityKg: number;
pricePerKg: number;
deliveryDistanceKm: number;
carbonFootprintKg: number;
matchScore: number;
timestamp: string;
}
export interface SustainabilityReport {
periodStart: string;
periodEnd: string;
totalCarbonSavedKg: number;
totalFoodMilesSaved: number;
localProductionPercentage: number;
wasteReductionPercentage: number;
waterSavedLiters: number;
recommendations: string[];
}
export interface NetworkAnalysis {
totalNodes: number;
totalConnections: number;
clusters: {
centroid: { lat: number; lon: number };
nodeCount: number;
avgDistance: number;
dominantSpecies: string[];
}[];
hotspots: {
location: { lat: number; lon: number };
intensity: number;
type: 'grower' | 'consumer' | 'mixed';
}[];
recommendations: string[];
}
export interface QualityReport {
chainId: string;
isValid: boolean;
blocksVerified: number;
integrityScore: number;
issues: {
blockIndex: number;
issueType: string;
description: string;
severity: 'low' | 'medium' | 'high' | 'critical';
}[];
lastVerifiedAt: string;
}