@trainly/react 1.4.2 → 1.5.0

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.
@@ -246,7 +246,7 @@ export function TrainlyProvider(_a) {
246
246
  }
247
247
  });
248
248
  }); };
249
- var ask = function (question) { return __awaiter(_this, void 0, void 0, function () {
249
+ var ask = function (question, options) { return __awaiter(_this, void 0, void 0, function () {
250
250
  var response, err_3, errorMessage, newToken, response, refreshError_1, error_3;
251
251
  return __generator(this, function (_a) {
252
252
  switch (_a.label) {
@@ -254,10 +254,10 @@ export function TrainlyProvider(_a) {
254
254
  _a.trys.push([0, 2, 10, 11]);
255
255
  setIsLoading(true);
256
256
  setError(null);
257
- return [4 /*yield*/, client.ask(question)];
257
+ return [4 /*yield*/, client.ask(question, options || {})];
258
258
  case 1:
259
259
  response = _a.sent();
260
- return [2 /*return*/, response.answer];
260
+ return [2 /*return*/, response];
261
261
  case 2:
262
262
  err_3 = _a.sent();
263
263
  errorMessage = err_3 instanceof Error ? err_3.message : String(err_3);
@@ -277,11 +277,11 @@ export function TrainlyProvider(_a) {
277
277
  return [4 /*yield*/, client.connectWithOAuthToken(newToken)];
278
278
  case 5:
279
279
  _a.sent();
280
- return [4 /*yield*/, client.ask(question)];
280
+ return [4 /*yield*/, client.ask(question, options || {})];
281
281
  case 6:
282
282
  response = _a.sent();
283
283
  console.log("✅ Query succeeded after token refresh");
284
- return [2 /*return*/, response.answer];
284
+ return [2 /*return*/, response];
285
285
  case 7: return [3 /*break*/, 9];
286
286
  case 8:
287
287
  refreshError_1 = _a.sent();
@@ -302,18 +302,33 @@ export function TrainlyProvider(_a) {
302
302
  }
303
303
  });
304
304
  }); };
305
- var askWithOptions = function (question, options) { return __awaiter(_this, void 0, void 0, function () {
306
- var response, err_4, errorMessage, newToken, response, refreshError_2, error_4;
305
+ // Legacy wrapper for backward compatibility (deprecated - use ask() with options instead)
306
+ var askWithCitations = function (question) { return __awaiter(_this, void 0, void 0, function () {
307
+ var response;
308
+ return __generator(this, function (_a) {
309
+ switch (_a.label) {
310
+ case 0: return [4 /*yield*/, ask(question, { includeCitations: true })];
311
+ case 1:
312
+ response = _a.sent();
313
+ return [2 /*return*/, {
314
+ answer: response.answer,
315
+ citations: response.citations || [],
316
+ }];
317
+ }
318
+ });
319
+ }); };
320
+ var upload = function (file, scopeValues) { return __awaiter(_this, void 0, void 0, function () {
321
+ var result, err_4, errorMessage, newToken, result, refreshError_2, error_4;
307
322
  return __generator(this, function (_a) {
308
323
  switch (_a.label) {
309
324
  case 0:
310
325
  _a.trys.push([0, 2, 10, 11]);
311
326
  setIsLoading(true);
312
327
  setError(null);
313
- return [4 /*yield*/, client.ask(question, options || {})];
328
+ return [4 /*yield*/, client.upload(file, scopeValues)];
314
329
  case 1:
315
- response = _a.sent();
316
- return [2 /*return*/, response];
330
+ result = _a.sent();
331
+ return [2 /*return*/, result];
317
332
  case 2:
318
333
  err_4 = _a.sent();
319
334
  errorMessage = err_4 instanceof Error ? err_4.message : String(err_4);
@@ -325,7 +340,7 @@ export function TrainlyProvider(_a) {
325
340
  _a.label = 3;
326
341
  case 3:
327
342
  _a.trys.push([3, 8, , 9]);
328
- console.log("🔄 Token expired, refreshing...");
343
+ console.log("🔄 Token expired during upload, refreshing...");
329
344
  return [4 /*yield*/, getToken()];
330
345
  case 4:
331
346
  newToken = _a.sent();
@@ -333,11 +348,11 @@ export function TrainlyProvider(_a) {
333
348
  return [4 /*yield*/, client.connectWithOAuthToken(newToken)];
334
349
  case 5:
335
350
  _a.sent();
336
- return [4 /*yield*/, client.ask(question, options || {})];
351
+ return [4 /*yield*/, client.upload(file, scopeValues)];
337
352
  case 6:
338
- response = _a.sent();
339
- console.log("✅ Query succeeded after token refresh");
340
- return [2 /*return*/, response];
353
+ result = _a.sent();
354
+ console.log("✅ Upload succeeded after token refresh");
355
+ return [2 /*return*/, result];
341
356
  case 7: return [3 /*break*/, 9];
342
357
  case 8:
343
358
  refreshError_2 = _a.sent();
@@ -345,8 +360,8 @@ export function TrainlyProvider(_a) {
345
360
  return [3 /*break*/, 9];
346
361
  case 9:
347
362
  error_4 = {
348
- code: "QUERY_FAILED",
349
- message: "Failed to get answer",
363
+ code: "UPLOAD_FAILED",
364
+ message: "Failed to upload file",
350
365
  details: err_4,
351
366
  };
352
367
  setError(error_4);
@@ -358,46 +373,71 @@ export function TrainlyProvider(_a) {
358
373
  }
359
374
  });
360
375
  }); };
361
- var askWithCitations = function (question) { return __awaiter(_this, void 0, void 0, function () {
362
- var response, err_5, error_5;
376
+ var uploadText = function (text, contentName, scopeValues) { return __awaiter(_this, void 0, void 0, function () {
377
+ var result, err_5, errorMessage, newToken, result, refreshError_3, error_5;
363
378
  return __generator(this, function (_a) {
364
379
  switch (_a.label) {
365
380
  case 0:
366
- _a.trys.push([0, 2, 3, 4]);
381
+ _a.trys.push([0, 2, 10, 11]);
367
382
  setIsLoading(true);
368
383
  setError(null);
369
- return [4 /*yield*/, client.ask(question, { includeCitations: true })];
384
+ return [4 /*yield*/, client.uploadText(text, contentName, scopeValues)];
370
385
  case 1:
371
- response = _a.sent();
372
- return [2 /*return*/, {
373
- answer: response.answer,
374
- citations: response.citations || [],
375
- }];
386
+ result = _a.sent();
387
+ return [2 /*return*/, result];
376
388
  case 2:
377
389
  err_5 = _a.sent();
390
+ errorMessage = err_5 instanceof Error ? err_5.message : String(err_5);
391
+ if (!(getToken &&
392
+ appId &&
393
+ (errorMessage.includes("401") ||
394
+ errorMessage.includes("authentication") ||
395
+ errorMessage.includes("Unauthorized")))) return [3 /*break*/, 9];
396
+ _a.label = 3;
397
+ case 3:
398
+ _a.trys.push([3, 8, , 9]);
399
+ console.log("🔄 Token expired during text upload, refreshing...");
400
+ return [4 /*yield*/, getToken()];
401
+ case 4:
402
+ newToken = _a.sent();
403
+ if (!newToken) return [3 /*break*/, 7];
404
+ return [4 /*yield*/, client.connectWithOAuthToken(newToken)];
405
+ case 5:
406
+ _a.sent();
407
+ return [4 /*yield*/, client.uploadText(text, contentName, scopeValues)];
408
+ case 6:
409
+ result = _a.sent();
410
+ console.log("✅ Text upload succeeded after token refresh");
411
+ return [2 /*return*/, result];
412
+ case 7: return [3 /*break*/, 9];
413
+ case 8:
414
+ refreshError_3 = _a.sent();
415
+ console.error("❌ Token refresh failed:", refreshError_3);
416
+ return [3 /*break*/, 9];
417
+ case 9:
378
418
  error_5 = {
379
- code: "QUERY_FAILED",
380
- message: "Failed to get answer with citations",
419
+ code: "TEXT_UPLOAD_FAILED",
420
+ message: "Failed to upload text content",
381
421
  details: err_5,
382
422
  };
383
423
  setError(error_5);
384
424
  throw error_5;
385
- case 3:
425
+ case 10:
386
426
  setIsLoading(false);
387
427
  return [7 /*endfinally*/];
388
- case 4: return [2 /*return*/];
428
+ case 11: return [2 /*return*/];
389
429
  }
390
430
  });
391
431
  }); };
392
- var upload = function (file, scopeValues) { return __awaiter(_this, void 0, void 0, function () {
393
- var result, err_6, errorMessage, newToken, result, refreshError_3, error_6;
432
+ var bulkUploadFiles = function (files, scopeValues) { return __awaiter(_this, void 0, void 0, function () {
433
+ var result, err_6, errorMessage, newToken, result, refreshError_4, error_6;
394
434
  return __generator(this, function (_a) {
395
435
  switch (_a.label) {
396
436
  case 0:
397
437
  _a.trys.push([0, 2, 10, 11]);
398
438
  setIsLoading(true);
399
439
  setError(null);
400
- return [4 /*yield*/, client.upload(file, scopeValues)];
440
+ return [4 /*yield*/, client.bulkUploadFiles(files, scopeValues)];
401
441
  case 1:
402
442
  result = _a.sent();
403
443
  return [2 /*return*/, result];
@@ -412,7 +452,7 @@ export function TrainlyProvider(_a) {
412
452
  _a.label = 3;
413
453
  case 3:
414
454
  _a.trys.push([3, 8, , 9]);
415
- console.log("🔄 Token expired during upload, refreshing...");
455
+ console.log("🔄 Token expired during bulk upload, refreshing...");
416
456
  return [4 /*yield*/, getToken()];
417
457
  case 4:
418
458
  newToken = _a.sent();
@@ -420,20 +460,20 @@ export function TrainlyProvider(_a) {
420
460
  return [4 /*yield*/, client.connectWithOAuthToken(newToken)];
421
461
  case 5:
422
462
  _a.sent();
423
- return [4 /*yield*/, client.upload(file, scopeValues)];
463
+ return [4 /*yield*/, client.bulkUploadFiles(files, scopeValues)];
424
464
  case 6:
425
465
  result = _a.sent();
426
- console.log("✅ Upload succeeded after token refresh");
466
+ console.log("✅ Bulk upload succeeded after token refresh");
427
467
  return [2 /*return*/, result];
428
468
  case 7: return [3 /*break*/, 9];
429
469
  case 8:
430
- refreshError_3 = _a.sent();
431
- console.error("❌ Token refresh failed:", refreshError_3);
470
+ refreshError_4 = _a.sent();
471
+ console.error("❌ Token refresh failed during bulk upload:", refreshError_4);
432
472
  return [3 /*break*/, 9];
433
473
  case 9:
434
474
  error_6 = {
435
- code: "UPLOAD_FAILED",
436
- message: "Failed to upload file",
475
+ code: "BULK_UPLOAD_FAILED",
476
+ message: "Failed to upload files",
437
477
  details: err_6,
438
478
  };
439
479
  setError(error_6);
@@ -445,15 +485,15 @@ export function TrainlyProvider(_a) {
445
485
  }
446
486
  });
447
487
  }); };
448
- var bulkUploadFiles = function (files, scopeValues) { return __awaiter(_this, void 0, void 0, function () {
449
- var result, err_7, errorMessage, newToken, result, refreshError_4, error_7;
488
+ var bulkUploadText = function (textContents, scopeValues) { return __awaiter(_this, void 0, void 0, function () {
489
+ var result, err_7, errorMessage, newToken, result, refreshError_5, error_7;
450
490
  return __generator(this, function (_a) {
451
491
  switch (_a.label) {
452
492
  case 0:
453
493
  _a.trys.push([0, 2, 10, 11]);
454
494
  setIsLoading(true);
455
495
  setError(null);
456
- return [4 /*yield*/, client.bulkUploadFiles(files, scopeValues)];
496
+ return [4 /*yield*/, client.bulkUploadText(textContents, scopeValues)];
457
497
  case 1:
458
498
  result = _a.sent();
459
499
  return [2 /*return*/, result];
@@ -468,7 +508,7 @@ export function TrainlyProvider(_a) {
468
508
  _a.label = 3;
469
509
  case 3:
470
510
  _a.trys.push([3, 8, , 9]);
471
- console.log("🔄 Token expired during bulk upload, refreshing...");
511
+ console.log("🔄 Token expired during bulk text upload, refreshing...");
472
512
  return [4 /*yield*/, getToken()];
473
513
  case 4:
474
514
  newToken = _a.sent();
@@ -476,20 +516,20 @@ export function TrainlyProvider(_a) {
476
516
  return [4 /*yield*/, client.connectWithOAuthToken(newToken)];
477
517
  case 5:
478
518
  _a.sent();
479
- return [4 /*yield*/, client.bulkUploadFiles(files, scopeValues)];
519
+ return [4 /*yield*/, client.bulkUploadText(textContents, scopeValues)];
480
520
  case 6:
481
521
  result = _a.sent();
482
- console.log("✅ Bulk upload succeeded after token refresh");
522
+ console.log("✅ Bulk text upload succeeded after token refresh");
483
523
  return [2 /*return*/, result];
484
524
  case 7: return [3 /*break*/, 9];
485
525
  case 8:
486
- refreshError_4 = _a.sent();
487
- console.error("❌ Token refresh failed during bulk upload:", refreshError_4);
526
+ refreshError_5 = _a.sent();
527
+ console.error("❌ Token refresh failed during bulk text upload:", refreshError_5);
488
528
  return [3 /*break*/, 9];
489
529
  case 9:
490
530
  error_7 = {
491
- code: "BULK_UPLOAD_FAILED",
492
- message: "Failed to upload files",
531
+ code: "BULK_TEXT_UPLOAD_FAILED",
532
+ message: "Failed to upload text content",
493
533
  details: err_7,
494
534
  };
495
535
  setError(error_7);
@@ -502,7 +542,7 @@ export function TrainlyProvider(_a) {
502
542
  });
503
543
  }); };
504
544
  var listFiles = function () { return __awaiter(_this, void 0, void 0, function () {
505
- var result, err_8, errorMessage, newToken, result, refreshError_5, error_8;
545
+ var result, err_8, errorMessage, newToken, result, refreshError_6, error_8;
506
546
  return __generator(this, function (_a) {
507
547
  switch (_a.label) {
508
548
  case 0:
@@ -539,8 +579,8 @@ export function TrainlyProvider(_a) {
539
579
  return [2 /*return*/, result];
540
580
  case 7: return [3 /*break*/, 9];
541
581
  case 8:
542
- refreshError_5 = _a.sent();
543
- console.error("❌ Token refresh failed:", refreshError_5);
582
+ refreshError_6 = _a.sent();
583
+ console.error("❌ Token refresh failed:", refreshError_6);
544
584
  return [3 /*break*/, 9];
545
585
  case 9:
546
586
  error_8 = {
@@ -558,7 +598,7 @@ export function TrainlyProvider(_a) {
558
598
  });
559
599
  }); };
560
600
  var deleteFile = function (fileId) { return __awaiter(_this, void 0, void 0, function () {
561
- var result, err_9, errorMessage, newToken, result, refreshError_6, error_9;
601
+ var result, err_9, errorMessage, newToken, result, refreshError_7, error_9;
562
602
  return __generator(this, function (_a) {
563
603
  switch (_a.label) {
564
604
  case 0:
@@ -595,8 +635,8 @@ export function TrainlyProvider(_a) {
595
635
  return [2 /*return*/, result];
596
636
  case 7: return [3 /*break*/, 9];
597
637
  case 8:
598
- refreshError_6 = _a.sent();
599
- console.error("❌ Token refresh failed:", refreshError_6);
638
+ refreshError_7 = _a.sent();
639
+ console.error("❌ Token refresh failed:", refreshError_7);
600
640
  return [3 /*break*/, 9];
601
641
  case 9:
602
642
  error_9 = {
@@ -654,10 +694,11 @@ export function TrainlyProvider(_a) {
654
694
  var clearMessages = function () { return setMessages([]); };
655
695
  var value = {
656
696
  ask: ask,
657
- askWithCitations: askWithCitations,
658
- askWithOptions: askWithOptions, // NEW: Ask with scope filters and options
697
+ askWithCitations: askWithCitations, // Deprecated - kept for backward compatibility
659
698
  upload: upload,
699
+ uploadText: uploadText, // NEW: Text content upload
660
700
  bulkUploadFiles: bulkUploadFiles, // NEW: Bulk file upload method
701
+ bulkUploadText: bulkUploadText, // NEW: Bulk text content upload
661
702
  listFiles: listFiles, // NEW: File management methods
662
703
  deleteFile: deleteFile,
663
704
  connectWithOAuthToken: connectWithOAuthToken, // NEW: V1 OAuth connection method
@@ -1,4 +1,4 @@
1
- import { TrainlyConfig, Citation, UploadResult, FileListResult, FileDeleteResult, BulkUploadResult } from "../types";
1
+ import { TrainlyConfig, Citation, UploadResult, FileListResult, FileDeleteResult, BulkUploadResult, TextContent } from "../types";
2
2
  interface QueryResponse {
3
3
  answer: string;
4
4
  citations?: Citation[];
@@ -20,7 +20,9 @@ export declare class TrainlyClient {
20
20
  scope_filters?: Record<string, string | number | boolean>;
21
21
  }): Promise<QueryResponse>;
22
22
  upload(file: File, scopeValues?: Record<string, string | number | boolean>): Promise<UploadResult>;
23
+ uploadText(text: string, contentName: string, scopeValues?: Record<string, string | number | boolean>): Promise<UploadResult>;
23
24
  bulkUploadFiles(files: File[], scopeValues?: Record<string, string | number | boolean>): Promise<BulkUploadResult>;
25
+ bulkUploadText(textContents: TextContent[], scopeValues?: Record<string, string | number | boolean>): Promise<BulkUploadResult>;
24
26
  listFiles(): Promise<FileListResult>;
25
27
  deleteFile(fileId: string): Promise<FileDeleteResult>;
26
28
  private extractChatId;
@@ -338,6 +338,55 @@ var TrainlyClient = /** @class */ (function () {
338
338
  });
339
339
  });
340
340
  };
341
+ TrainlyClient.prototype.uploadText = function (text, contentName, scopeValues) {
342
+ return __awaiter(this, void 0, void 0, function () {
343
+ var formData, response, error, data;
344
+ return __generator(this, function (_a) {
345
+ switch (_a.label) {
346
+ case 0:
347
+ if (!this.scopedToken) {
348
+ throw new Error("Not connected. Call connect() or connectWithOAuthToken() first.");
349
+ }
350
+ if (!(this.isV1Mode && this.config.appId)) return [3 /*break*/, 5];
351
+ formData = new FormData();
352
+ formData.append("text_content", text);
353
+ formData.append("content_name", contentName);
354
+ // Add scope values if provided
355
+ if (scopeValues && Object.keys(scopeValues).length > 0) {
356
+ formData.append("scope_values", JSON.stringify(scopeValues));
357
+ }
358
+ return [4 /*yield*/, fetch("".concat(this.config.baseUrl, "/v1/me/chats/files/upload"), {
359
+ method: "POST",
360
+ headers: {
361
+ Authorization: "Bearer ".concat(this.scopedToken),
362
+ "X-App-ID": this.config.appId,
363
+ },
364
+ body: formData,
365
+ })];
366
+ case 1:
367
+ response = _a.sent();
368
+ if (!!response.ok) return [3 /*break*/, 3];
369
+ return [4 /*yield*/, response.json()];
370
+ case 2:
371
+ error = _a.sent();
372
+ throw new Error("V1 text upload failed: ".concat(error.detail || response.statusText));
373
+ case 3: return [4 /*yield*/, response.json()];
374
+ case 4:
375
+ data = _a.sent();
376
+ return [2 /*return*/, {
377
+ success: data.success,
378
+ filename: data.filename,
379
+ size: data.size_bytes,
380
+ message: data.message ||
381
+ "Text content uploaded to your permanent private subchat",
382
+ }];
383
+ case 5:
384
+ // For non-V1 modes, text upload is not yet supported
385
+ throw new Error("Text upload is currently only available in V1 Trusted Issuer mode");
386
+ }
387
+ });
388
+ });
389
+ };
341
390
  TrainlyClient.prototype.bulkUploadFiles = function (files, scopeValues) {
342
391
  return __awaiter(this, void 0, void 0, function () {
343
392
  var formData_1, response, error, data, results, successful_uploads, total_size_bytes, _i, files_1, file, uploadResult, error_1;
@@ -450,6 +499,118 @@ var TrainlyClient = /** @class */ (function () {
450
499
  });
451
500
  });
452
501
  };
502
+ TrainlyClient.prototype.bulkUploadText = function (textContents, scopeValues) {
503
+ return __awaiter(this, void 0, void 0, function () {
504
+ var formData, texts, names, response, error, data, results, successful_uploads, total_size_bytes, _i, textContents_1, textContent, uploadResult, error_2;
505
+ return __generator(this, function (_a) {
506
+ switch (_a.label) {
507
+ case 0:
508
+ if (!this.scopedToken) {
509
+ throw new Error("Not connected. Call connect() or connectWithOAuthToken() first.");
510
+ }
511
+ if (!textContents || textContents.length === 0) {
512
+ throw new Error("No text content provided for bulk upload.");
513
+ }
514
+ if (textContents.length > 10) {
515
+ throw new Error("Too many items. Maximum 10 items per bulk upload.");
516
+ }
517
+ if (!(this.isV1Mode && this.config.appId)) return [3 /*break*/, 5];
518
+ formData = new FormData();
519
+ texts = textContents.map(function (tc) { return tc.text; });
520
+ names = textContents.map(function (tc) { return tc.contentName; });
521
+ formData.append("text_contents", JSON.stringify(texts));
522
+ formData.append("content_names", JSON.stringify(names));
523
+ // Add scope values if provided
524
+ if (scopeValues && Object.keys(scopeValues).length > 0) {
525
+ formData.append("scope_values", JSON.stringify(scopeValues));
526
+ }
527
+ return [4 /*yield*/, fetch("".concat(this.config.baseUrl, "/v1/me/chats/files/upload-bulk"), {
528
+ method: "POST",
529
+ headers: {
530
+ Authorization: "Bearer ".concat(this.scopedToken),
531
+ "X-App-ID": this.config.appId,
532
+ },
533
+ body: formData,
534
+ })];
535
+ case 1:
536
+ response = _a.sent();
537
+ if (!!response.ok) return [3 /*break*/, 3];
538
+ return [4 /*yield*/, response.json()];
539
+ case 2:
540
+ error = _a.sent();
541
+ throw new Error("V1 bulk text upload failed: ".concat(error.detail || response.statusText));
542
+ case 3: return [4 /*yield*/, response.json()];
543
+ case 4:
544
+ data = _a.sent();
545
+ return [2 /*return*/, {
546
+ success: data.success,
547
+ total_files: data.total_files,
548
+ successful_uploads: data.successful_uploads,
549
+ failed_uploads: data.failed_uploads,
550
+ total_size_bytes: data.total_size_bytes,
551
+ chat_id: data.chat_id,
552
+ user_id: data.user_id,
553
+ results: data.results,
554
+ message: data.message,
555
+ }];
556
+ case 5:
557
+ results = [];
558
+ successful_uploads = 0;
559
+ total_size_bytes = 0;
560
+ _i = 0, textContents_1 = textContents;
561
+ _a.label = 6;
562
+ case 6:
563
+ if (!(_i < textContents_1.length)) return [3 /*break*/, 11];
564
+ textContent = textContents_1[_i];
565
+ _a.label = 7;
566
+ case 7:
567
+ _a.trys.push([7, 9, , 10]);
568
+ return [4 /*yield*/, this.uploadText(textContent.text, textContent.contentName, scopeValues)];
569
+ case 8:
570
+ uploadResult = _a.sent();
571
+ results.push({
572
+ filename: uploadResult.filename,
573
+ success: uploadResult.success,
574
+ error: null,
575
+ file_id: null,
576
+ size_bytes: uploadResult.size,
577
+ processing_status: uploadResult.success ? "completed" : "failed",
578
+ message: uploadResult.message,
579
+ });
580
+ if (uploadResult.success) {
581
+ successful_uploads++;
582
+ total_size_bytes += uploadResult.size;
583
+ }
584
+ return [3 /*break*/, 10];
585
+ case 9:
586
+ error_2 = _a.sent();
587
+ results.push({
588
+ filename: textContent.contentName,
589
+ success: false,
590
+ error: error_2 instanceof Error ? error_2.message : String(error_2),
591
+ file_id: null,
592
+ size_bytes: textContent.text.length,
593
+ processing_status: "failed",
594
+ });
595
+ return [3 /*break*/, 10];
596
+ case 10:
597
+ _i++;
598
+ return [3 /*break*/, 6];
599
+ case 11: return [2 /*return*/, {
600
+ success: successful_uploads > 0,
601
+ total_files: textContents.length,
602
+ successful_uploads: successful_uploads,
603
+ failed_uploads: textContents.length - successful_uploads,
604
+ total_size_bytes: total_size_bytes,
605
+ chat_id: this.currentUserId || "",
606
+ user_id: this.currentUserId || "",
607
+ results: results,
608
+ message: "Bulk text upload completed: ".concat(successful_uploads, "/").concat(textContents.length, " items processed successfully"),
609
+ }];
610
+ }
611
+ });
612
+ });
613
+ };
453
614
  TrainlyClient.prototype.listFiles = function () {
454
615
  return __awaiter(this, void 0, void 0, function () {
455
616
  var response, error, data;
@@ -50,7 +50,7 @@ import { useTrainly } from "../useTrainly";
50
50
  export function TrainlyChat(_a) {
51
51
  var _this = this;
52
52
  var _b = _a.height, height = _b === void 0 ? "400px" : _b, _c = _a.className, className = _c === void 0 ? "" : _c, _d = _a.placeholder, placeholder = _d === void 0 ? "Ask me anything..." : _d, _e = _a.showCitations, showCitations = _e === void 0 ? true : _e, _f = _a.enableFileUpload, enableFileUpload = _f === void 0 ? true : _f, _g = _a.theme, theme = _g === void 0 ? "auto" : _g, scopeFilters = _a.scopeFilters, onMessage = _a.onMessage, onError = _a.onError;
53
- var askWithOptions = useTrainly().askWithOptions;
53
+ var ask = useTrainly().ask;
54
54
  var _h = React.useState(""), input = _h[0], setInput = _h[1];
55
55
  var _j = React.useState([]), messages = _j[0], setMessages = _j[1];
56
56
  var _k = React.useState(false), isLoading = _k[0], setIsLoading = _k[1];
@@ -91,7 +91,7 @@ export function TrainlyChat(_a) {
91
91
  _a.label = 1;
92
92
  case 1:
93
93
  _a.trys.push([1, 3, 4, 5]);
94
- return [4 /*yield*/, askWithOptions(messageContent, {
94
+ return [4 /*yield*/, ask(messageContent, {
95
95
  includeCitations: showCitations,
96
96
  scope_filters: scopeFilters,
97
97
  })];
package/dist/index.d.ts CHANGED
@@ -4,4 +4,4 @@ export { TrainlyChat } from "./components/TrainlyChat";
4
4
  export { TrainlyUpload } from "./components/TrainlyUpload";
5
5
  export { TrainlyStatus } from "./components/TrainlyStatus";
6
6
  export { TrainlyFileManager } from "./components/TrainlyFileManager";
7
- export type { TrainlyProviderProps, TrainlyConfig, ChatMessage, Citation, UploadResult, FileInfo, FileListResult, FileDeleteResult, TrainlyError, TrainlyFileManagerProps, } from "./types";
7
+ export type { TrainlyProviderProps, TrainlyConfig, ChatMessage, Citation, UploadResult, TextContent, BulkUploadResult, BulkUploadFileResult, FileInfo, FileListResult, FileDeleteResult, TrainlyError, TrainlyFileManagerProps, } from "./types";
package/dist/types.d.ts CHANGED
@@ -34,6 +34,10 @@ export interface UploadResult {
34
34
  size: number;
35
35
  message?: string;
36
36
  }
37
+ export interface TextContent {
38
+ text: string;
39
+ contentName: string;
40
+ }
37
41
  export interface BulkUploadFileResult {
38
42
  filename: string;
39
43
  success: boolean;
@@ -88,22 +92,23 @@ export interface TrainlyFileManagerProps {
88
92
  maxFileSize?: number;
89
93
  }
90
94
  export interface TrainlyContextValue {
91
- ask: (question: string) => Promise<string>;
92
- askWithCitations: (question: string) => Promise<{
93
- answer: string;
94
- citations: Citation[];
95
- }>;
96
- askWithOptions: (question: string, options?: {
95
+ ask: (question: string, options?: {
97
96
  includeCitations?: boolean;
98
97
  scope_filters?: Record<string, string | number | boolean>;
99
98
  }) => Promise<{
100
99
  answer: string;
101
100
  citations?: Citation[];
102
101
  }>;
102
+ askWithCitations: (question: string) => Promise<{
103
+ answer: string;
104
+ citations: Citation[];
105
+ }>;
103
106
  upload: (file: File, scopeValues?: Record<string, string | number | boolean>) => Promise<UploadResult>;
107
+ uploadText: (text: string, contentName: string, scopeValues?: Record<string, string | number | boolean>) => Promise<UploadResult>;
104
108
  listFiles: () => Promise<FileListResult>;
105
109
  deleteFile: (fileId: string) => Promise<FileDeleteResult>;
106
110
  bulkUploadFiles: (files: File[], scopeValues?: Record<string, string | number | boolean>) => Promise<BulkUploadResult>;
111
+ bulkUploadText: (textContents: TextContent[], scopeValues?: Record<string, string | number | boolean>) => Promise<BulkUploadResult>;
107
112
  connectWithOAuthToken: (idToken: string) => Promise<void>;
108
113
  isLoading: boolean;
109
114
  isConnected: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trainly/react",
3
- "version": "1.4.2",
3
+ "version": "1.5.0",
4
4
  "description": "Dead simple RAG integration for React apps with OAuth authentication and custom scopes",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",