|
| 1 | +/** |
| 2 | + * AntragWorkflowGraph Types |
| 3 | + * Type definitions for the LangGraph-based Antrag workflow |
| 4 | + */ |
| 5 | + |
| 6 | +import type { Request } from 'express'; |
| 7 | +import type AIWorkerPool from '../../../workers/aiWorkerPool.js'; |
| 8 | + |
| 9 | +// ============================================================================ |
| 10 | +// Input & Output Types |
| 11 | +// ============================================================================ |
| 12 | + |
| 13 | +export interface AntragWorkflowInput { |
| 14 | + // Required |
| 15 | + inhalt: string; |
| 16 | + requestType: 'antrag' | 'kleine_anfrage' | 'grosse_anfrage'; |
| 17 | + userId: string; |
| 18 | + |
| 19 | + // Optional |
| 20 | + gliederung?: string; |
| 21 | + locale?: 'de-DE' | 'de-AT'; |
| 22 | + useWebSearch?: boolean; |
| 23 | + usePrivacyMode?: boolean; |
| 24 | + selectedDocumentIds?: string[]; |
| 25 | + selectedTextIds?: string[]; |
| 26 | + |
| 27 | + // Context |
| 28 | + aiWorkerPool: AIWorkerPool; |
| 29 | + req: Request; |
| 30 | + workflowId?: string; |
| 31 | +} |
| 32 | + |
| 33 | +export interface AntragWorkflowOutput { |
| 34 | + success: boolean; |
| 35 | + workflowId: string; |
| 36 | + |
| 37 | + // Phase outputs |
| 38 | + plan?: PlanData; |
| 39 | + questions?: QuestionsData; |
| 40 | + revisedPlan?: string; |
| 41 | + productionContent?: ProductionData; |
| 42 | + |
| 43 | + // Metadata |
| 44 | + metadata: { |
| 45 | + executionTimeMs: number; |
| 46 | + phasesExecuted: string[]; |
| 47 | + totalAICalls: number; |
| 48 | + }; |
| 49 | + |
| 50 | + error?: string; |
| 51 | +} |
| 52 | + |
| 53 | +// ============================================================================ |
| 54 | +// State Schema |
| 55 | +// ============================================================================ |
| 56 | + |
| 57 | +export interface AntragWorkflowState { |
| 58 | + // Input parameters (immutable during workflow) |
| 59 | + input: AntragWorkflowInput; |
| 60 | + |
| 61 | + // Workflow control |
| 62 | + workflowId: string; |
| 63 | + currentPhase: 'plan' | 'questions' | 'revision' | 'production' | 'completed' | 'error'; |
| 64 | + |
| 65 | + // Enrichment results (cached from Phase 1) |
| 66 | + enrichedState?: { |
| 67 | + documents?: any[]; |
| 68 | + webSearchResults?: any[]; |
| 69 | + knowledgeBase?: any[]; |
| 70 | + greenFraming?: string[]; |
| 71 | + enrichmentMetadata?: any; |
| 72 | + }; |
| 73 | + |
| 74 | + // Phase 1: Plan Generation |
| 75 | + planData?: PlanData; |
| 76 | + planGenerationTimeMs?: number; |
| 77 | + |
| 78 | + // Phase 2: Questions |
| 79 | + questionsData?: QuestionsData; |
| 80 | + questionsGenerationTimeMs?: number; |
| 81 | + userAnswers?: Record<string, string | string[]>; |
| 82 | + skipQuestions?: boolean; |
| 83 | + |
| 84 | + // Phase 3: Revision |
| 85 | + revisedPlanData?: { |
| 86 | + revisedPlan: string; |
| 87 | + changes: string; |
| 88 | + revisionTimeMs: number; |
| 89 | + }; |
| 90 | + |
| 91 | + // Phase 4: Production |
| 92 | + productionData?: ProductionData; |
| 93 | + productionTimeMs?: number; |
| 94 | + |
| 95 | + // Metadata & tracking |
| 96 | + startTime: number; |
| 97 | + phasesExecuted: string[]; |
| 98 | + totalAICalls: number; |
| 99 | + |
| 100 | + // Error handling |
| 101 | + error?: string; |
| 102 | + success: boolean; |
| 103 | +} |
| 104 | + |
| 105 | +// ============================================================================ |
| 106 | +// Data Structures |
| 107 | +// ============================================================================ |
| 108 | + |
| 109 | +export interface PlanData { |
| 110 | + originalPlan: string; |
| 111 | + planSummary: string; |
| 112 | + confidenceScore: number; |
| 113 | + enrichmentMetadata?: any; |
| 114 | +} |
| 115 | + |
| 116 | +export interface QuestionsData { |
| 117 | + needsClarification: boolean; |
| 118 | + questions: GeneratedQuestion[]; |
| 119 | + questionRound: number; |
| 120 | + confidenceReason: string; |
| 121 | +} |
| 122 | + |
| 123 | +export interface GeneratedQuestion { |
| 124 | + id: string; |
| 125 | + questionText: string; |
| 126 | + questionType: 'verstaendnis' | 'rueckfrage'; |
| 127 | + why: string; |
| 128 | + options: string[]; |
| 129 | + clarificationPurpose?: string; |
| 130 | +} |
| 131 | + |
| 132 | +export interface ProductionData { |
| 133 | + content: string; |
| 134 | + metadata: { |
| 135 | + executionTimeMs: number; |
| 136 | + aiCallsCount: number; |
| 137 | + approvedPlanUsed: string; |
| 138 | + }; |
| 139 | +} |
| 140 | + |
| 141 | +// ============================================================================ |
| 142 | +// Node Return Types |
| 143 | +// ============================================================================ |
| 144 | + |
| 145 | +export type PlanGenerationNodeOutput = Partial<AntragWorkflowState>; |
| 146 | +export type QuestionsNodeOutput = Partial<AntragWorkflowState>; |
| 147 | +export type RevisionNodeOutput = Partial<AntragWorkflowState>; |
| 148 | +export type ProductionNodeOutput = Partial<AntragWorkflowState>; |
| 149 | + |
| 150 | +// ============================================================================ |
| 151 | +// Prompt Configurations |
| 152 | +// ============================================================================ |
| 153 | + |
| 154 | +export interface PromptConfig { |
| 155 | + systemPrompt: string; |
| 156 | + generationPrompt: string; |
| 157 | + toolSchema?: any; |
| 158 | + options?: { |
| 159 | + max_tokens?: number; |
| 160 | + temperature?: number; |
| 161 | + tool_choice?: any; |
| 162 | + }; |
| 163 | +} |
0 commit comments