@toothfairyai/cli 1.1.2 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/api.js +110 -46
package/package.json
CHANGED
package/src/api.js
CHANGED
|
@@ -207,34 +207,50 @@ class ToothFairyAPI {
|
|
|
207
207
|
const processedAttachments = await this._processAttachments(attachments);
|
|
208
208
|
|
|
209
209
|
if (chatId) {
|
|
210
|
-
// Use existing chat -
|
|
210
|
+
// Use existing chat - let REST endpoint handle message creation
|
|
211
211
|
const messageData = {
|
|
212
|
-
chatID: chatId,
|
|
213
212
|
text: message,
|
|
214
213
|
role: 'user',
|
|
215
214
|
userID: 'CLI',
|
|
216
|
-
...processedAttachments,
|
|
217
215
|
};
|
|
218
|
-
|
|
219
|
-
//
|
|
216
|
+
|
|
217
|
+
// Only include attachment fields if they have content
|
|
218
|
+
if (
|
|
219
|
+
processedAttachments.images &&
|
|
220
|
+
processedAttachments.images.length > 0
|
|
221
|
+
) {
|
|
222
|
+
messageData.images = processedAttachments.images;
|
|
223
|
+
}
|
|
224
|
+
if (
|
|
225
|
+
processedAttachments.audios &&
|
|
226
|
+
processedAttachments.audios.length > 0
|
|
227
|
+
) {
|
|
228
|
+
messageData.audios = processedAttachments.audios;
|
|
229
|
+
}
|
|
230
|
+
if (
|
|
231
|
+
processedAttachments.videos &&
|
|
232
|
+
processedAttachments.videos.length > 0
|
|
233
|
+
) {
|
|
234
|
+
messageData.videos = processedAttachments.videos;
|
|
235
|
+
}
|
|
236
|
+
if (
|
|
237
|
+
processedAttachments.files &&
|
|
238
|
+
processedAttachments.files.length > 0
|
|
239
|
+
) {
|
|
240
|
+
messageData.files = processedAttachments.files;
|
|
241
|
+
}
|
|
220
242
|
|
|
221
243
|
const agentData = {
|
|
222
244
|
chatid: chatId,
|
|
223
|
-
messages: [
|
|
224
|
-
{
|
|
225
|
-
text: createdMessage.text,
|
|
226
|
-
role: createdMessage.role,
|
|
227
|
-
userID: createdMessage.userID || 'System User',
|
|
228
|
-
},
|
|
229
|
-
],
|
|
245
|
+
messages: [messageData],
|
|
230
246
|
agentid: agentId,
|
|
231
247
|
};
|
|
232
|
-
|
|
248
|
+
|
|
233
249
|
const agentResponse = await this.getAgentResponse(agentData);
|
|
234
|
-
|
|
250
|
+
|
|
235
251
|
return {
|
|
236
|
-
chatId: chatId,
|
|
237
|
-
messageId:
|
|
252
|
+
chatId: agentResponse.chatId || chatId,
|
|
253
|
+
messageId: agentResponse.messageId || 'auto-generated',
|
|
238
254
|
agentResponse: agentResponse,
|
|
239
255
|
};
|
|
240
256
|
} else {
|
|
@@ -247,16 +263,28 @@ class ToothFairyAPI {
|
|
|
247
263
|
};
|
|
248
264
|
|
|
249
265
|
// Only include attachment fields if they have content
|
|
250
|
-
if (
|
|
266
|
+
if (
|
|
267
|
+
processedAttachments.images &&
|
|
268
|
+
processedAttachments.images.length > 0
|
|
269
|
+
) {
|
|
251
270
|
messageData.images = processedAttachments.images;
|
|
252
271
|
}
|
|
253
|
-
if (
|
|
272
|
+
if (
|
|
273
|
+
processedAttachments.audios &&
|
|
274
|
+
processedAttachments.audios.length > 0
|
|
275
|
+
) {
|
|
254
276
|
messageData.audios = processedAttachments.audios;
|
|
255
277
|
}
|
|
256
|
-
if (
|
|
278
|
+
if (
|
|
279
|
+
processedAttachments.videos &&
|
|
280
|
+
processedAttachments.videos.length > 0
|
|
281
|
+
) {
|
|
257
282
|
messageData.videos = processedAttachments.videos;
|
|
258
283
|
}
|
|
259
|
-
if (
|
|
284
|
+
if (
|
|
285
|
+
processedAttachments.files &&
|
|
286
|
+
processedAttachments.files.length > 0
|
|
287
|
+
) {
|
|
260
288
|
messageData.files = processedAttachments.files;
|
|
261
289
|
}
|
|
262
290
|
|
|
@@ -271,12 +299,12 @@ class ToothFairyAPI {
|
|
|
271
299
|
providerId: providerId,
|
|
272
300
|
customerInfo: customerInfo,
|
|
273
301
|
};
|
|
274
|
-
|
|
302
|
+
|
|
275
303
|
const agentResponse = await this.getAgentResponse(agentData);
|
|
276
|
-
|
|
304
|
+
|
|
277
305
|
return {
|
|
278
306
|
chatId: agentResponse.chatId || 'auto-generated',
|
|
279
|
-
messageId: agentResponse.messageId || 'auto-generated',
|
|
307
|
+
messageId: agentResponse.messageId || 'auto-generated',
|
|
280
308
|
agentResponse: agentResponse,
|
|
281
309
|
};
|
|
282
310
|
}
|
|
@@ -392,34 +420,48 @@ class ToothFairyAPI {
|
|
|
392
420
|
const processedAttachments = await this._processAttachments(attachments);
|
|
393
421
|
|
|
394
422
|
if (chatId) {
|
|
395
|
-
// Use existing chat -
|
|
423
|
+
// Use existing chat - let SSE endpoint handle message creation
|
|
396
424
|
if (this.verbose) {
|
|
397
425
|
console.debug(`Using existing chat: ${chatId}`);
|
|
398
426
|
}
|
|
399
427
|
|
|
400
428
|
const messageData = {
|
|
401
|
-
chatID: chatId,
|
|
402
429
|
text: message,
|
|
403
430
|
role: 'user',
|
|
404
431
|
userID: 'CLI',
|
|
405
|
-
...processedAttachments,
|
|
406
432
|
};
|
|
407
|
-
|
|
408
|
-
if
|
|
409
|
-
|
|
433
|
+
|
|
434
|
+
// Only include attachment fields if they have content
|
|
435
|
+
if (
|
|
436
|
+
processedAttachments.images &&
|
|
437
|
+
processedAttachments.images.length > 0
|
|
438
|
+
) {
|
|
439
|
+
messageData.images = processedAttachments.images;
|
|
440
|
+
}
|
|
441
|
+
if (
|
|
442
|
+
processedAttachments.audios &&
|
|
443
|
+
processedAttachments.audios.length > 0
|
|
444
|
+
) {
|
|
445
|
+
messageData.audios = processedAttachments.audios;
|
|
446
|
+
}
|
|
447
|
+
if (
|
|
448
|
+
processedAttachments.videos &&
|
|
449
|
+
processedAttachments.videos.length > 0
|
|
450
|
+
) {
|
|
451
|
+
messageData.videos = processedAttachments.videos;
|
|
452
|
+
}
|
|
453
|
+
if (
|
|
454
|
+
processedAttachments.files &&
|
|
455
|
+
processedAttachments.files.length > 0
|
|
456
|
+
) {
|
|
457
|
+
messageData.files = processedAttachments.files;
|
|
410
458
|
}
|
|
411
459
|
|
|
412
460
|
// Prepare agent data for streaming with existing chat
|
|
413
461
|
const agentData = {
|
|
414
462
|
workspaceid: this.workspaceId,
|
|
415
463
|
chatid: chatId,
|
|
416
|
-
messages: [
|
|
417
|
-
{
|
|
418
|
-
text: createdMessage.text,
|
|
419
|
-
role: createdMessage.role,
|
|
420
|
-
userID: createdMessage.userID || 'System User',
|
|
421
|
-
},
|
|
422
|
-
],
|
|
464
|
+
messages: [messageData],
|
|
423
465
|
agentid: agentId,
|
|
424
466
|
};
|
|
425
467
|
|
|
@@ -504,7 +546,10 @@ class ToothFairyAPI {
|
|
|
504
546
|
// Final response with complete data
|
|
505
547
|
onEvent('complete', eventData);
|
|
506
548
|
}
|
|
507
|
-
} else if (
|
|
549
|
+
} else if (
|
|
550
|
+
eventData.text &&
|
|
551
|
+
eventData.type === 'message'
|
|
552
|
+
) {
|
|
508
553
|
// This is streaming text data
|
|
509
554
|
onEvent('data', eventData);
|
|
510
555
|
} else if (
|
|
@@ -519,7 +564,10 @@ class ToothFairyAPI {
|
|
|
519
564
|
) {
|
|
520
565
|
// Callback metadata with function details and execution plan
|
|
521
566
|
onEvent('callback', eventData);
|
|
522
|
-
} else if (
|
|
567
|
+
} else if (
|
|
568
|
+
eventData.type === 'chat_created' ||
|
|
569
|
+
eventData.event === 'chat_created'
|
|
570
|
+
) {
|
|
523
571
|
// Chat creation event
|
|
524
572
|
onEvent('chat_created', eventData);
|
|
525
573
|
} else {
|
|
@@ -563,7 +611,9 @@ class ToothFairyAPI {
|
|
|
563
611
|
} else {
|
|
564
612
|
// No chatId provided - let streaming API create chat automatically
|
|
565
613
|
if (this.verbose) {
|
|
566
|
-
console.debug(
|
|
614
|
+
console.debug(
|
|
615
|
+
'No chatId provided - letting API create chat automatically'
|
|
616
|
+
);
|
|
567
617
|
}
|
|
568
618
|
|
|
569
619
|
// Prepare message data for automatic chat creation
|
|
@@ -574,16 +624,28 @@ class ToothFairyAPI {
|
|
|
574
624
|
};
|
|
575
625
|
|
|
576
626
|
// Only include attachment fields if they have content
|
|
577
|
-
if (
|
|
627
|
+
if (
|
|
628
|
+
processedAttachments.images &&
|
|
629
|
+
processedAttachments.images.length > 0
|
|
630
|
+
) {
|
|
578
631
|
messageData.images = processedAttachments.images;
|
|
579
632
|
}
|
|
580
|
-
if (
|
|
633
|
+
if (
|
|
634
|
+
processedAttachments.audios &&
|
|
635
|
+
processedAttachments.audios.length > 0
|
|
636
|
+
) {
|
|
581
637
|
messageData.audios = processedAttachments.audios;
|
|
582
638
|
}
|
|
583
|
-
if (
|
|
639
|
+
if (
|
|
640
|
+
processedAttachments.videos &&
|
|
641
|
+
processedAttachments.videos.length > 0
|
|
642
|
+
) {
|
|
584
643
|
messageData.videos = processedAttachments.videos;
|
|
585
644
|
}
|
|
586
|
-
if (
|
|
645
|
+
if (
|
|
646
|
+
processedAttachments.files &&
|
|
647
|
+
processedAttachments.files.length > 0
|
|
648
|
+
) {
|
|
587
649
|
messageData.files = processedAttachments.files;
|
|
588
650
|
}
|
|
589
651
|
|
|
@@ -681,7 +743,10 @@ class ToothFairyAPI {
|
|
|
681
743
|
// Final response with complete data
|
|
682
744
|
onEvent('complete', eventData);
|
|
683
745
|
}
|
|
684
|
-
} else if (
|
|
746
|
+
} else if (
|
|
747
|
+
eventData.text &&
|
|
748
|
+
eventData.type === 'message'
|
|
749
|
+
) {
|
|
685
750
|
// This is streaming text data
|
|
686
751
|
onEvent('data', eventData);
|
|
687
752
|
} else if (
|
|
@@ -1244,8 +1309,7 @@ class ToothFairyAPI {
|
|
|
1244
1309
|
externalPath = filePath; // Use URL directly
|
|
1245
1310
|
} else {
|
|
1246
1311
|
// For files, construct S3 path
|
|
1247
|
-
|
|
1248
|
-
externalPath = `s3://files-to-import-aus-prod/imported-pdf/${filename}`;
|
|
1312
|
+
externalPath = `s3://files-to-import-aus-prod/${filePath}`;
|
|
1249
1313
|
}
|
|
1250
1314
|
|
|
1251
1315
|
const documentData = {
|