449 lines
11 KiB
TypeScript
449 lines
11 KiB
TypeScript
/**
|
|
* Voxyz Autonomous Architecture - Database Types Extension
|
|
* Phase 10: Mission Control Autonomous System
|
|
*/
|
|
|
|
import { Database as BaseDatabase } from './database.types';
|
|
import type { Task } from '@/lib/data/tasks';
|
|
|
|
// ============================================
|
|
// ENUM TYPES
|
|
// ============================================
|
|
|
|
export type ProposalStatus =
|
|
| 'pending'
|
|
| 'approved'
|
|
| 'rejected'
|
|
| 'scheduled'
|
|
| 'completed'
|
|
| 'expired';
|
|
|
|
export type PolicyCategory =
|
|
| 'cap_gates'
|
|
| 'scheduling'
|
|
| 'prioritization'
|
|
| 'execution'
|
|
| 'general';
|
|
|
|
export type TriggerType =
|
|
| 'deadline_approaching'
|
|
| 'task_blocked'
|
|
| 'high_priority_created'
|
|
| 'stale_task'
|
|
| 'sprint_ending'
|
|
| 'milestone_reached'
|
|
| 'daily_mission_time'
|
|
| 'manual'
|
|
| 'calendar_conflict';
|
|
|
|
export type ActionType =
|
|
| 'create_proposal'
|
|
| 'send_notification'
|
|
| 'escalate_priority'
|
|
| 'auto_schedule'
|
|
| 'request_review'
|
|
| 'update_status';
|
|
|
|
export type GateType =
|
|
| 'daily_mission_limit'
|
|
| 'concurrent_high_priority'
|
|
| 'workload_capacity'
|
|
| 'focus_time_minimum'
|
|
| 'calendar_buffer'
|
|
| 'reaction_ratio';
|
|
|
|
export type MissionStatus =
|
|
| 'draft'
|
|
| 'review'
|
|
| 'approved'
|
|
| 'scheduled'
|
|
| 'in_progress'
|
|
| 'completed'
|
|
| 'canceled';
|
|
|
|
export type BlockType =
|
|
| 'deep_work'
|
|
| 'mission_execution'
|
|
| 'planning'
|
|
| 'reaction_time'
|
|
| 'buffer'
|
|
| 'meeting';
|
|
|
|
export type AgentName =
|
|
| 'proposal_generator'
|
|
| 'cap_gate_validator'
|
|
| 'calendar_scheduler'
|
|
| 'trigger_monitor'
|
|
| 'mission_optimizer'
|
|
| 'stale_task_detector';
|
|
|
|
export type CalendarProvider = 'google' | 'outlook' | 'apple' | 'other';
|
|
|
|
// ============================================
|
|
// TABLE ROW TYPES
|
|
// ============================================
|
|
|
|
export interface MissionProposal {
|
|
id: string;
|
|
created_at: string;
|
|
updated_at: string;
|
|
proposal_date: string;
|
|
status: ProposalStatus;
|
|
priority_score: number;
|
|
passes_cap_gates: boolean;
|
|
cap_gate_violations: CapGateViolation[];
|
|
source_task_ids: string[];
|
|
source_project_ids: string[];
|
|
title: string;
|
|
description: string | null;
|
|
rationale: string | null;
|
|
ai_analysis: AIAnalysisSummary;
|
|
suggested_start_time: string | null;
|
|
suggested_end_time: string | null;
|
|
estimated_duration_minutes: number | null;
|
|
approved_at: string | null;
|
|
approved_by: string | null;
|
|
rejected_at: string | null;
|
|
rejection_reason: string | null;
|
|
calendar_event_id: string | null;
|
|
calendar_synced_at: string | null;
|
|
executed_at: string | null;
|
|
execution_notes: string | null;
|
|
expires_at: string;
|
|
}
|
|
|
|
export interface Policy {
|
|
id: string;
|
|
created_at: string;
|
|
updated_at: string;
|
|
name: string;
|
|
description: string | null;
|
|
category: PolicyCategory;
|
|
config: Record<string, unknown>;
|
|
rules: Record<string, unknown>;
|
|
is_active: boolean;
|
|
effective_from: string;
|
|
effective_until: string | null;
|
|
version: number;
|
|
previous_version_id: string | null;
|
|
created_by: string | null;
|
|
updated_by: string | null;
|
|
}
|
|
|
|
export interface TriggerRule {
|
|
id: string;
|
|
created_at: string;
|
|
updated_at: string;
|
|
name: string;
|
|
description: string | null;
|
|
trigger_type: TriggerType;
|
|
conditions: TriggerConditions;
|
|
action_type: ActionType;
|
|
action_config: Record<string, unknown>;
|
|
priority: number;
|
|
is_active: boolean;
|
|
cooldown_minutes: number;
|
|
max_triggers_per_day: number;
|
|
last_triggered_at: string | null;
|
|
trigger_count: number;
|
|
created_by: string | null;
|
|
updated_by: string | null;
|
|
}
|
|
|
|
export interface CapGate {
|
|
id: string;
|
|
created_at: string;
|
|
updated_at: string;
|
|
name: string;
|
|
description: string | null;
|
|
gate_type: GateType;
|
|
max_value: number;
|
|
min_value: number;
|
|
unit: string;
|
|
current_value: number;
|
|
last_evaluated_at: string | null;
|
|
policy_id: string | null;
|
|
is_active: boolean;
|
|
is_blocking: boolean;
|
|
evaluation_window_hours: number;
|
|
created_by: string | null;
|
|
updated_by: string | null;
|
|
}
|
|
|
|
export interface DailyMission {
|
|
id: string;
|
|
created_at: string;
|
|
updated_at: string;
|
|
mission_date: string;
|
|
generated_at: string;
|
|
generated_by: 'ai_agent' | 'manual' | 'trigger';
|
|
status: MissionStatus;
|
|
primary_mission_id: string | null;
|
|
secondary_mission_id: string | null;
|
|
tertiary_mission_id: string | null;
|
|
total_estimated_minutes: number | null;
|
|
focus_time_start: string | null;
|
|
focus_time_end: string | null;
|
|
focus_time_minutes: number | null;
|
|
calendar_blocks: DailyMissionCalendarBlock[];
|
|
planned_reactions: number;
|
|
actual_reactions: number;
|
|
reaction_ratio: number;
|
|
completed_at: string | null;
|
|
completion_notes: string | null;
|
|
completion_rating: number | null;
|
|
user_feedback: Record<string, unknown>;
|
|
}
|
|
|
|
export interface DailyMissionCalendarBlock {
|
|
id: string;
|
|
start_time: string;
|
|
end_time: string;
|
|
block_type: BlockType;
|
|
}
|
|
|
|
export interface CalendarBlock {
|
|
id: string;
|
|
created_at: string;
|
|
updated_at: string;
|
|
block_date: string;
|
|
start_time: string;
|
|
end_time: string;
|
|
block_type: BlockType;
|
|
mission_id: string | null;
|
|
proposal_id: string | null;
|
|
calendar_event_id: string | null;
|
|
calendar_provider: CalendarProvider;
|
|
calendar_synced: boolean;
|
|
calendar_synced_at: string | null;
|
|
status: 'scheduled' | 'active' | 'completed' | 'canceled' | 'rescheduled';
|
|
notes: string | null;
|
|
}
|
|
|
|
export interface TriggerLog {
|
|
id: string;
|
|
created_at: string;
|
|
rule_id: string | null;
|
|
rule_name: string;
|
|
triggered_at: string;
|
|
trigger_type: TriggerType;
|
|
context: Record<string, unknown>;
|
|
task_ids: string[];
|
|
action_taken: string | null;
|
|
action_result: string | null;
|
|
success: boolean;
|
|
error_message: string | null;
|
|
proposal_id: string | null;
|
|
}
|
|
|
|
export interface AgentExecutionLog {
|
|
id: string;
|
|
created_at: string;
|
|
agent_name: AgentName;
|
|
execution_type: 'scheduled' | 'triggered' | 'manual' | 'reaction';
|
|
started_at: string;
|
|
completed_at: string | null;
|
|
duration_ms: number | null;
|
|
input_summary: Record<string, unknown>;
|
|
output_summary: Record<string, unknown>;
|
|
proposals_created: number;
|
|
proposals_approved: number;
|
|
tasks_analyzed: number;
|
|
status: 'running' | 'success' | 'partial' | 'failed';
|
|
error_message: string | null;
|
|
ai_tokens_used: number | null;
|
|
ai_cost_usd: number | null;
|
|
}
|
|
|
|
// ============================================
|
|
// JSON/Complex TYPES
|
|
// ============================================
|
|
|
|
export interface CapGateViolation {
|
|
gate_name: string;
|
|
gate_type: GateType | 'prioritization';
|
|
current_value: number;
|
|
max_value: number;
|
|
violation_message: string;
|
|
}
|
|
|
|
export interface AIAnalysisSummary {
|
|
priority_factors?: PriorityFactor[];
|
|
urgency_score?: number;
|
|
impact_score?: number;
|
|
effort_estimate?: 'low' | 'medium' | 'high';
|
|
confidence?: number;
|
|
reasoning?: string;
|
|
similar_completed_tasks?: string[];
|
|
risks?: string[];
|
|
opportunities?: string[];
|
|
}
|
|
|
|
export interface PriorityFactor {
|
|
factor: string;
|
|
weight: number;
|
|
contribution: number;
|
|
}
|
|
|
|
export interface TriggerConditions {
|
|
// Deadline approaching
|
|
hours_before?: number;
|
|
priority?: string;
|
|
|
|
// Task blocked
|
|
blocked_hours?: number;
|
|
|
|
// Stale task
|
|
stale_days?: number;
|
|
status_in?: string[];
|
|
|
|
// Sprint ending
|
|
days_before?: number;
|
|
|
|
// Daily mission time
|
|
hour?: number;
|
|
minute?: number;
|
|
|
|
// Custom conditions
|
|
[key: string]: unknown;
|
|
}
|
|
|
|
// ============================================
|
|
// INPUT/INSERT TYPES
|
|
// ============================================
|
|
|
|
export type MissionProposalInsert = Omit<MissionProposal, 'id' | 'created_at' | 'updated_at'>;
|
|
export type PolicyInsert = Omit<Policy, 'id' | 'created_at' | 'updated_at' | 'version'>;
|
|
export type TriggerRuleInsert = Omit<TriggerRule, 'id' | 'created_at' | 'updated_at' | 'trigger_count'>;
|
|
export type CapGateInsert = Omit<CapGate, 'id' | 'created_at' | 'updated_at' | 'current_value'>;
|
|
export type DailyMissionInsert = Omit<DailyMission, 'id' | 'created_at' | 'updated_at'>;
|
|
export type CalendarBlockInsert = Omit<CalendarBlock, 'id' | 'created_at' | 'updated_at'>;
|
|
|
|
// ============================================
|
|
// DOMAIN-SPECIFIC TYPES
|
|
// ============================================
|
|
|
|
export interface CapGateCheck {
|
|
gate: CapGate;
|
|
passed: boolean;
|
|
currentValue: number;
|
|
violation?: CapGateViolation;
|
|
}
|
|
|
|
export interface CapGateCheckResult {
|
|
allPassed: boolean;
|
|
checks: CapGateCheck[];
|
|
violations: CapGateViolation[];
|
|
summary: string;
|
|
}
|
|
|
|
export interface MissionProposalInput {
|
|
title: string;
|
|
description?: string;
|
|
sourceTaskIds: string[];
|
|
sourceProjectIds: string[];
|
|
suggestedStartTime?: Date;
|
|
suggestedEndTime?: Date;
|
|
estimatedDurationMinutes?: number;
|
|
aiAnalysis?: AIAnalysisSummary;
|
|
}
|
|
|
|
export interface TriggerEvaluationContext {
|
|
currentTime: Date;
|
|
activeTasks: Task[];
|
|
recentProposals: MissionProposal[];
|
|
todayMissions: DailyMission[];
|
|
userAvailability: CalendarBlock[];
|
|
}
|
|
|
|
export interface TriggerEvaluationResult {
|
|
triggered: boolean;
|
|
rule: TriggerRule;
|
|
context: Record<string, unknown>;
|
|
proposalInput?: MissionProposalInput;
|
|
priorityBoost?: number;
|
|
}
|
|
|
|
export interface DailyMissionGenerationInput {
|
|
date: Date;
|
|
targetMissionCount: number;
|
|
includeReactions: boolean;
|
|
forceRegenerate?: boolean;
|
|
}
|
|
|
|
export interface DailyMissionGenerationResult {
|
|
dailyMission: DailyMission;
|
|
proposals: MissionProposal[];
|
|
capGatesChecked: CapGateCheckResult;
|
|
calendarBlocks: CalendarBlock[];
|
|
executionLogId: string;
|
|
}
|
|
|
|
export interface ProposalServiceConfig {
|
|
maxProposalsPerDay: number;
|
|
minProposalsPerDay: number;
|
|
defaultProposalExpiryHours: number;
|
|
priorityScoreThreshold: number;
|
|
autoApproveThreshold: number;
|
|
}
|
|
|
|
export interface CapGateConfig {
|
|
dailyMissionLimit: number;
|
|
concurrentHighPriorityLimit: number;
|
|
maxDailyWorkloadMinutes: number;
|
|
minFocusTimeMinutes: number;
|
|
minCalendarBufferMinutes: number;
|
|
reactionRatio: number;
|
|
}
|
|
|
|
// ============================================
|
|
// EXTENDED DATABASE INTERFACE
|
|
// ============================================
|
|
|
|
export interface VoxyzDatabase extends BaseDatabase {
|
|
public: {
|
|
Tables: BaseDatabase['public']['Tables'] & {
|
|
ops_mission_proposals: {
|
|
Row: MissionProposal;
|
|
Insert: MissionProposalInsert;
|
|
Update: Partial<MissionProposalInsert>;
|
|
};
|
|
ops_policy: {
|
|
Row: Policy;
|
|
Insert: PolicyInsert;
|
|
Update: Partial<PolicyInsert>;
|
|
};
|
|
ops_trigger_rules: {
|
|
Row: TriggerRule;
|
|
Insert: TriggerRuleInsert;
|
|
Update: Partial<TriggerRuleInsert>;
|
|
};
|
|
ops_cap_gates: {
|
|
Row: CapGate;
|
|
Insert: CapGateInsert;
|
|
Update: Partial<CapGateInsert>;
|
|
};
|
|
ops_daily_missions: {
|
|
Row: DailyMission;
|
|
Insert: DailyMissionInsert;
|
|
Update: Partial<DailyMissionInsert>;
|
|
};
|
|
ops_calendar_blocks: {
|
|
Row: CalendarBlock;
|
|
Insert: CalendarBlockInsert;
|
|
Update: Partial<CalendarBlockInsert>;
|
|
};
|
|
ops_trigger_log: {
|
|
Row: TriggerLog;
|
|
Insert: Omit<TriggerLog, 'id' | 'created_at'>;
|
|
Update: Partial<Omit<TriggerLog, 'id' | 'created_at'>>;
|
|
};
|
|
ops_agent_execution_log: {
|
|
Row: AgentExecutionLog;
|
|
Insert: Omit<AgentExecutionLog, 'id' | 'created_at'>;
|
|
Update: Partial<Omit<AgentExecutionLog, 'id' | 'created_at'>>;
|
|
};
|
|
};
|
|
};
|
|
}
|