File size: 3,329 Bytes
f39c319
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
export enum ErrorCode {
  SOURCE_MISSING = 4001,
  INVALID_URL = 4002,
  PARSE_FAILED = 4003,
  NO_CONTENT = 4004,
  CRAWL_FAILED = 5001,
  DIFF_FAILED = 5002,
  DB_SAVE_FAILED = 5003,
  EXPORT_STRUCT_FAILED = 5004
}

export type SourceType = 'peer_bank' | 'regulator' | 'sdk_vendor';
export type CrawlFrequency = '4h' | 'daily' | 'weekly';
export type Priority = 'high' | 'medium' | 'low';

export interface SourceRegistry {
  source_id: string;
  source_name: string;
  source_type: SourceType;
  domain: string;
  entry_url: string;
  url_pattern: string;
  parser_type: string;
  crawl_frequency: CrawlFrequency;
  priority: Priority;
  enabled: boolean;
  topic_tags: string[];
  created_at?: string;
  updated_at?: string;
}

export type TriggerType = 'schedule' | 'manual' | 'webhook';
export type JobStatus = 'queued' | 'running' | 'success' | 'failed';

export interface CrawlJob {
  job_id: string;
  source_id: string;
  trigger_type: TriggerType;
  status: JobStatus;
  started_at?: string;
  ended_at?: string;
  error_code?: string;
  error_message?: string;
  retry_count: number;
}

export interface RawSnapshot {
  snapshot_id: string;
  source_id: string;
  job_id: string;
  fetched_at: string;
  content_type: string;
  raw_body: string;
  raw_hash: string;
  http_status: number;
  final_url: string;
}

export type DocStatus = 'active' | 'archived';

export interface NormalizedDocument {
  doc_id: string;
  source_id: string;
  snapshot_id: string;
  title: string;
  version_date: string;
  effective_date: string;
  normalized_text: string;
  normalized_hash: string;
  doc_status: DocStatus;
  created_at?: string;
}

export type EmbeddingStatus = 'pending' | 'ready' | 'failed';

export interface ClauseChunk {
  chunk_id: string;
  doc_id: string;
  section_path: string;
  section_title: string;
  clause_text: string;
  topic_tags: string[];
  embedding_status: EmbeddingStatus;
  chunk_order: number;
  created_at?: string;
}

export type ChangeType = 'added' | 'removed' | 'modified' | 'unchanged';
export type ImpactLevel = 'high' | 'medium' | 'low';

export interface DiffEvent {
  event_id: string;
  source_id: string;
  from_doc_id: string;
  to_doc_id: string;
  change_type: ChangeType;
  section_title: string;
  old_excerpt: string;
  new_excerpt: string;
  topic_tags: string[];
  impact_level: ImpactLevel;
  detected_at: string;
}

// API Requests / Responses

export interface CreateSourceRequest {
  source_name: string;
  source_type: SourceType;
  domain: string;
  entry_url: string;
  url_pattern: string;
  parser_type: string;
  crawl_frequency: CrawlFrequency;
  priority: Priority;
  enabled: boolean;
  topic_tags: string[];
}

export interface CreateSourceResponse {
  source_id: string;
  success: boolean;
}

export interface GetSourcesQuery {
  source_type?: SourceType;
  enabled?: boolean;
  priority?: Priority;
}

export interface GetSourcesResponse {
  items: SourceRegistry[];
  total: number;
}

export interface CreateJobsRequest {
  source_ids: string[];
  trigger_type: TriggerType;
}

export interface CreateJobsResponse {
  job_ids: string[];
  status: string;
}

export interface GetJobResponse {
  job_id: string;
  source_id: string;
  status: JobStatus;
  started_at?: string;
  ended_at?: string;
  error_code?: string | null;
  retry_count: number;
}