modcomms/frontend/types.ts
michael 9e2473c3e9 Add Knowledge Base management system for AI agent specs
Full-stack implementation enabling UI-driven management of the 5 AI agent knowledge bases
(Legal, Brand Barclays, Brand Barclaycard, Channel Best Practices, Channel Tech Specs).

Backend:
- 4 new DB models: KnowledgeBase, SourceDocument, SpecVersion, ProcessingJob
- Migration 006: creates tables, seeds 5 KB rows, imports existing prompts/*.md as v1 specs
- KnowledgeBaseRepository with full CRUD for all 4 tables
- LlamaParseService for document parsing, KnowledgeBaseService for pipeline orchestration
- ReferenceDocsService updated with DB-backed spec loading + cache invalidation
- 11 REST endpoints under /api/knowledge-base (list, detail, upload, delete, process, job status, versions, diff, activate)
- StorageService extended with KB document storage

Frontend:
- TypeScript types for all KB entities (KnowledgeBaseListItem, SourceDocument, ProcessingJob, SpecVersion, DiffResult)
- ApiService methods for all KB endpoints including multipart file upload
- KnowledgeBase component with 3-level UI: agent grid, detail view (documents + versions tabs), diff viewer
- Drag-and-drop file upload, processing progress bar with 3s polling, version comparison
- KnowledgeBaseIcon + Sidebar nav item with adminOnly filtering

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-12 15:00:36 -06:00

168 lines
3.9 KiB
TypeScript
Executable file

// Fix: Broke a circular dependency by defining the AgentName type directly in this file instead of importing it.
export type AgentName = 'Legal Agent' | 'Brand Agent' | 'Channel Best Practices Agent' | 'Channel Tech Specs Agent';
export type AgentStatus = 'pending' | 'in-progress' | 'complete' | 'issues-found' | 'error';
export type ReviewStatus = {
[key in AgentName]?: AgentStatus;
};
export type RagStatus = 'Red' | 'Amber' | 'Green' | 'Error';
export interface SubReview {
ragStatus: RagStatus;
feedback: string;
issues: string[];
// Revision-aware fields (populated when analyzing version N > 1)
resolvedIssues?: string[];
outstandingIssues?: string[];
newIssues?: string[];
}
export type OverallStatus = 'Passed' | 'Failed' | 'Analysis Error' | 'Requires Manual Legal Review';
export interface AgentReview {
legalAgentReview: SubReview;
brandAgentReview: SubReview;
channelBestPracticesAgentReview: SubReview;
channelTechSpecsAgentReview: SubReview;
leadAgentSummary: string;
overallStatus: OverallStatus;
financialPromotionReason?: string;
}
export interface FlaggedItem {
id: string;
campaignName: string;
proofName: string;
version: number;
submitter: string;
submitAgency: string;
agentFlagged: string;
comments: string;
timestamp: string;
}
export interface ResolvedItem {
id: string;
campaignName: string;
proofName: string;
version: number;
submitter: string;
submitAgency: string;
agent: string;
issue: string;
resolution: string;
timestamp: string;
}
export interface ErrorItem {
id: string;
campaignName: string;
proofName: string;
version: number;
submitter: string;
submitAgency: string;
errorSummary: string;
timestamp: string;
}
export interface PDFPage {
page: number;
data_url: string;
width: number;
height: number;
}
export interface ProofVersion {
version: number;
timestamp: string;
workfrontId: string;
proofPreviewUrl?: string;
fileStorageKey?: string;
feedback: AgentReview;
isIdenticalFile?: boolean;
}
// Knowledge Base types
export interface KnowledgeBaseListItem {
id: string;
agent_key: string;
display_name: string;
description: string | null;
source_document_count: number;
active_spec_version: number | null;
active_spec_char_count: number | null;
latest_job_status: string | null;
latest_job_completed_at: string | null;
created_at: string;
}
export interface SourceDocument {
id: string;
knowledge_base_id: string;
filename: string;
file_storage_key: string;
file_size_bytes: number;
mime_type: string;
uploaded_by_name: string | null;
parse_status: string;
parse_error: string | null;
created_at: string;
}
export interface ProcessingJob {
id: string;
knowledge_base_id: string;
status: string;
triggered_by_name: string | null;
total_documents: number;
parsed_documents: number;
spec_version_id: string | null;
error_message: string | null;
started_at: string | null;
completed_at: string | null;
created_at: string;
}
export interface KnowledgeBaseDetail {
id: string;
agent_key: string;
display_name: string;
description: string | null;
source_documents: SourceDocument[];
active_spec_version: number | null;
active_spec_char_count: number | null;
latest_job: ProcessingJob | null;
created_at: string;
}
export interface SpecVersionListItem {
id: string;
knowledge_base_id: string;
version_number: number;
generated_by_name: string | null;
source_document_ids: string[] | null;
is_active: boolean;
char_count: number;
created_at: string;
}
export interface SpecVersionDetail extends SpecVersionListItem {
content: string;
}
export interface DiffLine {
type: 'add' | 'remove' | 'context';
content: string;
line_number_old: number | null;
line_number_new: number | null;
}
export interface DiffResult {
version_a: number;
version_b: number;
additions: number;
deletions: number;
lines: DiffLine[];
}