79dce1a01c
Adds discussArticle() to BriefingApi and wires it through to the RSS news cards in BriefingScreen so tapping Discuss opens a chat conversation seeded with the article. Also caps RSS cards per message at 3 to avoid overly long briefing threads. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
98 lines
3.1 KiB
Dart
98 lines
3.1 KiB
Dart
import 'package:dio/dio.dart';
|
|
|
|
import '../models/briefing_conversation.dart';
|
|
import '../models/message.dart';
|
|
import 'api_client.dart';
|
|
|
|
class BriefingApi {
|
|
final Dio _dio;
|
|
const BriefingApi(this._dio);
|
|
|
|
/// GET /api/briefing/conversations/today
|
|
/// Returns (or creates) today's briefing conversation with messages embedded.
|
|
Future<BriefingConversation> getToday() async {
|
|
try {
|
|
final response = await _dio.get('/api/briefing/conversations/today');
|
|
return BriefingConversation.fromJson(
|
|
response.data as Map<String, dynamic>);
|
|
} on DioException catch (e) {
|
|
throw dioToApp(e);
|
|
}
|
|
}
|
|
|
|
/// GET /api/briefing/conversations
|
|
/// Returns list of past briefing conversations (no messages embedded).
|
|
Future<List<BriefingConversation>> getHistory() async {
|
|
try {
|
|
final response = await _dio.get('/api/briefing/conversations');
|
|
final data = response.data as Map<String, dynamic>;
|
|
final list = data['conversations'] as List<dynamic>;
|
|
return list
|
|
.map((e) => BriefingConversation.fromJson(e as Map<String, dynamic>))
|
|
.toList();
|
|
} on DioException catch (e) {
|
|
throw dioToApp(e);
|
|
}
|
|
}
|
|
|
|
/// GET /api/briefing/conversations/`<id>`/messages
|
|
Future<List<Message>> getMessages(int convId) async {
|
|
try {
|
|
final response =
|
|
await _dio.get('/api/briefing/conversations/$convId/messages');
|
|
final data = response.data as Map<String, dynamic>;
|
|
final list = data['messages'] as List<dynamic>;
|
|
return list
|
|
.map((e) => Message.fromJson(e as Map<String, dynamic>))
|
|
.toList();
|
|
} on DioException catch (e) {
|
|
throw dioToApp(e);
|
|
}
|
|
}
|
|
|
|
/// POST /api/briefing/trigger body: {"slot": slot}
|
|
/// slot: "compilation" | "morning" | "midday" | "afternoon"
|
|
Future<void> triggerSlot(String slot) async {
|
|
try {
|
|
await _dio.post('/api/briefing/trigger', data: {'slot': slot});
|
|
} on DioException catch (e) {
|
|
throw dioToApp(e);
|
|
}
|
|
}
|
|
|
|
/// POST /api/briefing/rss-reactions body: {rss_item_id, reaction: "up"|"down"}
|
|
Future<void> postRssReaction(int rssItemId, String reaction) async {
|
|
try {
|
|
await _dio.post('/api/briefing/rss-reactions',
|
|
data: {'rss_item_id': rssItemId, 'reaction': reaction});
|
|
} on DioException catch (e) {
|
|
throw dioToApp(e);
|
|
}
|
|
}
|
|
|
|
/// POST /api/briefing/articles/{itemId}/discuss body: {"conv_id": convId}
|
|
/// Injects the article as context and triggers LLM generation.
|
|
/// Returns the assistant_message_id of the generating placeholder.
|
|
Future<int> discussArticle(int convId, int itemId) async {
|
|
try {
|
|
final response = await _dio.post(
|
|
'/api/briefing/articles/$itemId/discuss',
|
|
data: {'conv_id': convId},
|
|
);
|
|
final data = response.data as Map<String, dynamic>;
|
|
return data['assistant_message_id'] as int;
|
|
} on DioException catch (e) {
|
|
throw dioToApp(e);
|
|
}
|
|
}
|
|
|
|
/// DELETE /api/briefing/rss-reactions/{rssItemId}
|
|
Future<void> deleteRssReaction(int rssItemId) async {
|
|
try {
|
|
await _dio.delete('/api/briefing/rss-reactions/$rssItemId');
|
|
} on DioException catch (e) {
|
|
throw dioToApp(e);
|
|
}
|
|
}
|
|
}
|