-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp_models.go
More file actions
295 lines (267 loc) · 13.3 KB
/
app_models.go
File metadata and controls
295 lines (267 loc) · 13.3 KB
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
package main
// ----------------------
// API Response Wrapper
// ----------------------
// APIResponse is a standard wrapper for all responses sent by the backend API.
//
// It ensures every response indicates success/failure and optionally carries
// either an error message or the requested data payload.
//
// Example JSON:
//
// {
// "success": true,
// "error": "",
// "data": {...}
// }
type APIResponse struct {
Success bool `json:"success"` // True if the operation succeeded, false otherwise
Error string `json:"error,omitempty"` // Optional error message when Success is false
Data interface{} `json:"data,omitempty"` // Optional payload for successful responses
}
// ----------------------
// Debug Log Entry
// ----------------------
// DebugLogEntry represents a single log entry in the P2P debug log database.
//
// Each entry includes a unique ID, timestamp, message, log level, and optional metadata.
// These entries are stored in OrbitDB (or similar) and are intended for debugging
// and operational tracing of the P2P node.
//
// Example JSON:
//
// {
// "_id": "uuid",
// "timestamp": "2025-11-26T09:36:11.340Z",
// "message": "Node debug DB initialized",
// "level": "info",
// "meta": { "port": "9001" }
// }
type DebugLogEntry struct {
ID string `json:"_id"` // Unique identifier for the log entry (UUID recommended)
Timestamp string `json:"timestamp"` // ISO 8601 timestamp of when the entry was created
Message string `json:"message"` // Human-readable log message
Level string `json:"level"` // Log level: "info", "warn", or "error"
Meta map[string]interface{} `json:"meta,omitempty"` // Optional metadata, e.g., port number, type, or context info
}
// ----------------------
// Source Metadata
// ----------------------
// SourceMeta holds basic information about a source and its bias.
// - Name: the human-readable source name
// - Bias: political or ideological bias (e.g., "left", "right", "neutral")
// - Confidence: optional confidence score in bias assessment (0-1)
type SourceMeta struct {
Name string `json:"name"` // Name of the source, e.g., "CBS News"
Bias string `json:"bias"` // Political/ideological leaning: "left", "center", "right"
Confidence *float64 `json:"confidence,omitempty"` // Confidence score in bias classification (0-1)
}
// ----------------------
// Source Definition
// ----------------------
// Source defines a data source for articles, including endpoints, auth, and metadata.
// - Parser / Normalizer: define how the data is processed and normalized
// - Bias / Factuality: optional bias and factuality scoring
// - Ownership: company or organization ownership info
type Source struct {
Name string `json:"name"` // Name of the source (e.g., "BBC News")
Endpoint string `json:"endpoint"` // API or RSS endpoint URL
APIKey *string `json:"apiKey,omitempty"` // Optional API key provided by the user
Instructions *string `json:"instructions,omitempty"` // Optional instructions for using the source
APILink *string `json:"apiLink,omitempty"` // Optional link to API docs
Enabled *bool `json:"enabled,omitempty"` // Optional flag indicating if source is active
RequiresAPIKey *bool `json:"requiresApiKey,omitempty"` // Optional flag for API key requirement
Category *string `json:"category,omitempty"` // Optional source category (e.g., news, blog, rss)
Tags []string `json:"tags,omitempty"` // Optional array of tags
Language *string `json:"language,omitempty"` // Optional ISO 639-1 language code
Region *string `json:"region,omitempty"` // Optional region code
AuthType *string `json:"authType,omitempty"` // Optional auth type: none, apiKey, bearerToken, oauth, etc.
RateLimitPerMin *int `json:"rateLimitPerMinute,omitempty"` // Optional rate limit
Headers map[string]string `json:"headers,omitempty"` // Optional custom headers
LastUpdated *string `json:"lastUpdated,omitempty"`
Pinned *bool `json:"pinned,omitempty"`
// Parser & Normalizer
Parser string `json:"parser"` // defaults to "json"
Normalizer string `json:"normalizer"` // defaults to "json"
// Bias / Factuality
Bias string `json:"bias,omitempty"`
Factuality *string `json:"factuality,omitempty"`
Confidence *float64 `json:"confidence,omitempty"`
// Ownership info
Ownership *Ownership `json:"ownership,omitempty"`
// Last fetched timestamp
LastFetched *string `json:"lastFetched,omitempty"`
}
// ----------------------
// Ownership Schema
// ----------------------
// Ownership represents the owner organization of a source.
// - CompanyName: official organization name
// - Type: type of organization (private, government, NGO, etc.)
// - Country: optional country code
type Ownership struct {
CompanyName string `json:"companyName"`
Type string `json:"type"` // private, government, ngo, etc.
Country *string `json:"country,omitempty"`
}
// ----------------------
// Article Editions
// ----------------------
// Edition defines the regional or contextual edition of an article.
type Edition string
const (
EditionInternational Edition = "international"
EditionUS Edition = "us"
EditionUK Edition = "uk"
EditionKR Edition = "kr"
EditionCN Edition = "cn"
EditionOther Edition = "other"
)
// ----------------------
// Federated Article Pointer
// ----------------------
// FederatedArticlePointer is a minimal representation of an article shared across nodes.
// - CID: IPFS Content Identifier for fetching full content
// - Timestamp: creation or last update of the pointer
// - Hash: optional content hash for verification
// - Analyzed: true if this article has been analyzed
// - Source / Edition: optional metadata
type FederatedArticlePointer struct {
CID string `json:"cid"` // Content Identifier (IPFS)
Timestamp string `json:"timestamp"` // ISO timestamp of creation/update
Hash *string `json:"hash,omitempty"` // Optional content hash
Analyzed bool `json:"analyzed"` // True if article was analyzed
Source *string `json:"source,omitempty"` // Optional source name
Edition *string `json:"edition,omitempty"` // Optional edition/region
}
// ----------------------
// Raw Article (Ingested)
// ----------------------
// Article represents a raw article before analysis, including minimal metadata.
// - ID, Title, URL: required identifiers
// - Content, Summary, Image: optional media and text fields
// - Categories / Tags: optional classification
// - SourceMeta: optional bias/factuality metadata
type Article struct {
ID string `json:"id"` // Unique identifier (hash, UUID)
Title string `json:"title"` // Article title
URL string `json:"url"` // Fully qualified URL
Content *string `json:"content,omitempty"` // Full content
Summary *string `json:"summary,omitempty"` // Optional short summary
Image *string `json:"image,omitempty"` // Primary image URL
Categories []string `json:"categories,omitempty"` // Optional categories
Tags []string `json:"tags,omitempty"` // Optional tags
Language *string `json:"language,omitempty"` // ISO 639-1 language code
Author *string `json:"author,omitempty"` // Optional author
PublishedAt *string `json:"publishedAt,omitempty"` // Optional ISO timestamp
Edition *Edition `json:"edition,omitempty"` // Optional regional edition
Analyzed bool `json:"analyzed"` // False until analyzed
IPFSHash *string `json:"ipfsHash,omitempty"`
Raw interface{} `json:"raw,omitempty"`
SourceMeta *SourceMeta `json:"sourceMeta,omitempty"`
FetchedAt *string `json:"fetchedAt,omitempty"`
Parser string `json:"parser"` // frontend-compatible parser
Normalizer string `json:"normalizer"` // frontend-compatible normalizer
Confidence *float64 `json:"confidence,omitempty"`
MobileURL *string `json:"mobileUrl,omitempty"`
Source *string `json:"source,omitempty"`
SourceDomain *string `json:"sourceDomain,omitempty"`
SourceType *string `json:"sourceType,omitempty"`
SourceCountry *string `json:"sourceCountry,omitempty"`
}
// ----------------------
// Analyzed Article
// ----------------------
// CognitiveBias represents one detected cognitive bias in an article.
type CognitiveBias struct {
Bias string `json:"bias"`
Snippet string `json:"snippet"`
Explanation string `json:"explanation"`
Severity string `json:"severity"`
Description *string `json:"description,omitempty"`
Category *string `json:"category,omitempty"`
}
// ArticleAnalyzed extends Article with AI-enriched fields.
// - PoliticalBias: optional political/ideological classification
// - Antithesis / Philosophical: optional interpretative summaries
// - Sentiment: optional sentiment label and valence
// - CognitiveBiases: optional array of detected cognitive biases
// - ClickbaitLevel, CredibilityLevel, SubjectivityLevel: optional quality metrics
// - EmotionalPalette: optional dominant/secondary emotions
// - Readability: optional reading difficulty metrics
// - Trustworthiness: optional 1-5 score
// - AnalysisTimestamp: when analysis was performed
type ArticleAnalyzed struct {
Article // Embed base Article
PoliticalBias *string `json:"politicalBias,omitempty"` // Optional political/ideological bias
Antithesis *string `json:"antithesis,omitempty"` // Concise summary of opposing viewpoints
Philosophical *string `json:"philosophical,omitempty"` // Optional philosophical interpretation
Sentiment *string `json:"sentiment,omitempty"` // e.g., positive/negative/neutral
CognitiveBiases []CognitiveBias `json:"cognitiveBiases,omitempty"` // Array of detected biases
Confidence *float64 `json:"confidence,omitempty"` // Confidence of analysis (0-1)
SentimentValence *float64 `json:"sentimentValence,omitempty"`
ClickbaitLevel *string `json:"clickbaitLevel,omitempty"`
CredibilityLevel *string `json:"credibilityLevel,omitempty"`
EmotionalPalette *struct {
Dominant string `json:"dominant"`
Secondary *string `json:"secondary,omitempty"`
} `json:"emotionalPalette,omitempty"`
Readability *struct {
FleschEase *float64 `json:"fleschEase,omitempty"`
FleschGrade *float64 `json:"fleschGrade,omitempty"`
ReadingLevel *string `json:"readingLevel,omitempty"`
} `json:"readability,omitempty"`
SubjectivityLevel *string `json:"subjectivityLevel,omitempty"`
Trustworthiness *float64 `json:"trustworthiness,omitempty"`
AnalysisTimestamp *string `json:"analysisTimestamp,omitempty"`
}
// ArticlesResponse represents the standard response from the P2P HTTP API
// when fetching multiple articles from sources.
//
// The response wraps the list of articles in a success envelope to indicate
// whether the operation was successful, along with the actual articles array.
//
// Example JSON:
//
// {
// "success": true,
// "articles": [
// { "id": "123", "title": "Example Article", "url": "https://example.com" },
// ...
// ]
// }
type ArticlesResponse struct {
Success bool `json:"success"` // True if the fetch operation succeeded
Articles []Article `json:"articles"` // Array of Article objects retrieved
}
// ArticlesBySource represents a collection of raw feed data grouped by source name.
//
// Each entry maps a source name to the raw response fetched from that source.
// The raw data can be JSON, XML, RSS, HTML, or any other format provided by the source.
// Parsing and normalization is intended to be handled by the Node/JS frontend.
//
// This structure allows the frontend to handle different formats per source,
// while Go focuses solely on fetching the data.
//
// Example:
//
// {
// "BBC News": "<rss>...</rss>",
// "NY Times": "[{ \"id\": \"3\", \"title\": \"Article C\", \"url\": \"https://nytimes.com/c\" }]"
//
// }
type ArticlesBySource map[string][]byte
// ArticleStatus represents the processing state of an article
type ArticleStatus struct {
ID string `json:"id"`
Status string `json:"status"` // "pending" | "complete" | "error"
Body string `json:"body"` // may be empty if pending
ErrorMsg string `json:"errorMsg"` // optional
}
// TranslationRequest represents the request body for translating specified fields of articles
type TranslationRequest struct {
Identifiers []string `json:"identifiers"` // Article URLs, internal IDs, or IPFS CIDs
TargetLanguage string `json:"targetLanguage"` // e.g., "en", "ko"
Keys []string `json:"keys,omitempty"` // Fields to translate, default ["title"]
Overwrite bool `json:"overwrite"` // Whether to overwrite existing translations
}