@@ -40,7 +40,7 @@ Future<List<ServerMessage>> getMessagesServer({
40
40
Future <List <ServerMessage >> clearChatServer ({String ? pluginId}) async {
41
41
if (pluginId == 'no_selected' ) pluginId = null ;
42
42
var response = await makeApiCall (
43
- url: '${Env .apiBaseUrl }v1 /messages?plugin_id=${pluginId ?? '' }' ,
43
+ url: '${Env .apiBaseUrl }v2 /messages?plugin_id=${pluginId ?? '' }' ,
44
44
headers: {},
45
45
method: 'DELETE' ,
46
46
body: '' ,
@@ -53,32 +53,6 @@ Future<List<ServerMessage>> clearChatServer({String? pluginId}) async {
53
53
}
54
54
}
55
55
56
- Future <ServerMessage > sendMessageServer (String text, {String ? appId, List <String >? fileIds}) {
57
- var url = '${Env .apiBaseUrl }v1/messages?plugin_id=$appId ' ;
58
- if (appId == null || appId.isEmpty || appId == 'null' || appId == 'no_selected' ) {
59
- url = '${Env .apiBaseUrl }v1/messages' ;
60
- }
61
- return makeApiCall (
62
- url: url,
63
- headers: {},
64
- method: 'POST' ,
65
- body: jsonEncode ({'text' : text, 'file_ids' : fileIds}),
66
- ).then ((response) {
67
- if (response == null ) throw Exception ('Failed to send message' );
68
- if (response.statusCode == 200 ) {
69
- return ServerMessage .fromJson (jsonDecode (response.body));
70
- } else {
71
- Logger .error ('Failed to send message ${response .body }' );
72
- CrashReporting .reportHandledCrash (
73
- Exception ('Failed to send message ${response .body }' ),
74
- StackTrace .current,
75
- level: NonFatalExceptionLevel .error,
76
- );
77
- return ServerMessage .failedMessage ();
78
- }
79
- });
80
- }
81
-
82
56
ServerMessageChunk ? parseMessageChunk (String line, String messageId) {
83
57
if (line.startsWith ('think: ' )) {
84
58
return ServerMessageChunk (messageId, line.substring (7 ).replaceAll ("__CRLF__" , "\n " ), MessageChunkType .think);
@@ -164,7 +138,7 @@ Stream<ServerMessageChunk> sendMessageStreamServer(String text, {String? appId,
164
138
165
139
Future <ServerMessage > getInitialAppMessage (String ? appId) {
166
140
return makeApiCall (
167
- url: '${Env .apiBaseUrl }v1 /initial-message?plugin_id =$appId ' ,
141
+ url: '${Env .apiBaseUrl }v2 /initial-message?app_id =$appId ' ,
168
142
headers: {},
169
143
method: 'POST' ,
170
144
body: '' ,
@@ -235,36 +209,10 @@ Stream<ServerMessageChunk> sendVoiceMessageStreamServer(List<File> files) async*
235
209
}
236
210
}
237
211
238
- Future <List <ServerMessage >> sendVoiceMessageServer (List <File > files) async {
239
- var request = http.MultipartRequest (
240
- 'POST' ,
241
- Uri .parse ('${Env .apiBaseUrl }v1/voice-messages' ),
242
- );
243
- for (var file in files) {
244
- request.files.add (await http.MultipartFile .fromPath ('files' , file.path, filename: basename (file.path)));
245
- }
246
- request.headers.addAll ({'Authorization' : await getAuthHeader ()});
247
-
248
- try {
249
- var streamedResponse = await request.send ();
250
- var response = await http.Response .fromStream (streamedResponse);
251
- if (response.statusCode == 200 ) {
252
- debugPrint ('sendVoiceMessageServer response body: ${jsonDecode (response .body )}' );
253
- return ((jsonDecode (response.body) ?? []) as List <dynamic >).map ((m) => ServerMessage .fromJson (m)).toList ();
254
- } else {
255
- debugPrint ('Failed to upload sample. Status code: ${response .statusCode } ${response .body }' );
256
- throw Exception ('Failed to upload sample. Status code: ${response .statusCode }' );
257
- }
258
- } catch (e) {
259
- debugPrint ('An error occurred uploadSample: $e ' );
260
- throw Exception ('An error occurred uploadSample: $e ' );
261
- }
262
- }
263
-
264
212
Future <List <MessageFile >?> uploadFilesServer (List <File > files, {String ? appId}) async {
265
- var url = '${Env .apiBaseUrl }v1 /files?plugin_id =$appId ' ;
213
+ var url = '${Env .apiBaseUrl }v2 /files?app_id =$appId ' ;
266
214
if (appId == null || appId.isEmpty || appId == 'null' || appId == 'no_selected' ) {
267
- url = '${Env .apiBaseUrl }v1 /files' ;
215
+ url = '${Env .apiBaseUrl }v2 /files' ;
268
216
}
269
217
var request = http.MultipartRequest (
270
218
'POST' ,
@@ -301,7 +249,7 @@ Future<List<MessageFile>?> uploadFilesServer(List<File> files, {String? appId})
301
249
302
250
Future reportMessageServer (String messageId) async {
303
251
var response = await makeApiCall (
304
- url: '${Env .apiBaseUrl }v1 /messages/$messageId /report' ,
252
+ url: '${Env .apiBaseUrl }v2 /messages/$messageId /report' ,
305
253
headers: {},
306
254
method: 'POST' ,
307
255
body: '' ,
@@ -312,20 +260,19 @@ Future reportMessageServer(String messageId) async {
312
260
}
313
261
}
314
262
315
-
316
263
Future <String > transcribeVoiceMessage (File audioFile) async {
317
264
try {
318
265
var request = http.MultipartRequest (
319
266
'POST' ,
320
- Uri .parse ('${Env .apiBaseUrl }v1 /voice-message/transcribe' ),
267
+ Uri .parse ('${Env .apiBaseUrl }v2 /voice-message/transcribe' ),
321
268
);
322
-
269
+
323
270
request.headers.addAll ({'Authorization' : await getAuthHeader ()});
324
271
request.files.add (await http.MultipartFile .fromPath ('files' , audioFile.path));
325
-
272
+
326
273
var streamedResponse = await request.send ();
327
274
var response = await http.Response .fromStream (streamedResponse);
328
-
275
+
329
276
if (response.statusCode == 200 ) {
330
277
final data = jsonDecode (response.body);
331
278
return data['transcript' ] ?? '' ;
0 commit comments