@trainly/react 1.3.1 → 1.4.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.
@@ -333,7 +333,7 @@ export function TrainlyProvider(_a) {
333
333
  }
334
334
  });
335
335
  }); };
336
- var upload = function (file) { return __awaiter(_this, void 0, void 0, function () {
336
+ var upload = function (file, scopeValues) { return __awaiter(_this, void 0, void 0, function () {
337
337
  var result, err_5, errorMessage, newToken, result, refreshError_2, error_5;
338
338
  return __generator(this, function (_a) {
339
339
  switch (_a.label) {
@@ -341,7 +341,7 @@ export function TrainlyProvider(_a) {
341
341
  _a.trys.push([0, 2, 10, 11]);
342
342
  setIsLoading(true);
343
343
  setError(null);
344
- return [4 /*yield*/, client.upload(file)];
344
+ return [4 /*yield*/, client.upload(file, scopeValues)];
345
345
  case 1:
346
346
  result = _a.sent();
347
347
  return [2 /*return*/, result];
@@ -364,7 +364,7 @@ export function TrainlyProvider(_a) {
364
364
  return [4 /*yield*/, client.connectWithOAuthToken(newToken)];
365
365
  case 5:
366
366
  _a.sent();
367
- return [4 /*yield*/, client.upload(file)];
367
+ return [4 /*yield*/, client.upload(file, scopeValues)];
368
368
  case 6:
369
369
  result = _a.sent();
370
370
  console.log("✅ Upload succeeded after token refresh");
@@ -389,7 +389,7 @@ export function TrainlyProvider(_a) {
389
389
  }
390
390
  });
391
391
  }); };
392
- var bulkUploadFiles = function (files) { return __awaiter(_this, void 0, void 0, function () {
392
+ var bulkUploadFiles = function (files, scopeValues) { return __awaiter(_this, void 0, void 0, function () {
393
393
  var result, err_6, errorMessage, newToken, result, refreshError_3, error_6;
394
394
  return __generator(this, function (_a) {
395
395
  switch (_a.label) {
@@ -397,7 +397,7 @@ export function TrainlyProvider(_a) {
397
397
  _a.trys.push([0, 2, 10, 11]);
398
398
  setIsLoading(true);
399
399
  setError(null);
400
- return [4 /*yield*/, client.bulkUploadFiles(files)];
400
+ return [4 /*yield*/, client.bulkUploadFiles(files, scopeValues)];
401
401
  case 1:
402
402
  result = _a.sent();
403
403
  return [2 /*return*/, result];
@@ -420,7 +420,7 @@ export function TrainlyProvider(_a) {
420
420
  return [4 /*yield*/, client.connectWithOAuthToken(newToken)];
421
421
  case 5:
422
422
  _a.sent();
423
- return [4 /*yield*/, client.bulkUploadFiles(files)];
423
+ return [4 /*yield*/, client.bulkUploadFiles(files, scopeValues)];
424
424
  case 6:
425
425
  result = _a.sent();
426
426
  console.log("✅ Bulk upload succeeded after token refresh");
@@ -18,8 +18,8 @@ export declare class TrainlyClient {
18
18
  ask(question: string, options?: {
19
19
  includeCitations?: boolean;
20
20
  }): Promise<QueryResponse>;
21
- upload(file: File): Promise<UploadResult>;
22
- bulkUploadFiles(files: File[]): Promise<BulkUploadResult>;
21
+ upload(file: File, scopeValues?: Record<string, string | number | boolean>): Promise<UploadResult>;
22
+ bulkUploadFiles(files: File[], scopeValues?: Record<string, string | number | boolean>): Promise<BulkUploadResult>;
23
23
  listFiles(): Promise<FileListResult>;
24
24
  deleteFile(fileId: string): Promise<FileDeleteResult>;
25
25
  private extractChatId;
@@ -218,7 +218,7 @@ var TrainlyClient = /** @class */ (function () {
218
218
  });
219
219
  });
220
220
  };
221
- TrainlyClient.prototype.upload = function (file) {
221
+ TrainlyClient.prototype.upload = function (file, scopeValues) {
222
222
  return __awaiter(this, void 0, void 0, function () {
223
223
  var formData, response, error, data, formData, response, error, presignedResponse, error, _a, upload_url, upload_headers, formData, uploadResponse;
224
224
  return __generator(this, function (_b) {
@@ -230,6 +230,10 @@ var TrainlyClient = /** @class */ (function () {
230
230
  if (!(this.isV1Mode && this.config.appId)) return [3 /*break*/, 5];
231
231
  formData = new FormData();
232
232
  formData.append("file", file);
233
+ // Add scope values if provided
234
+ if (scopeValues && Object.keys(scopeValues).length > 0) {
235
+ formData.append("scope_values", JSON.stringify(scopeValues));
236
+ }
233
237
  return [4 /*yield*/, fetch("".concat(this.config.baseUrl, "/v1/me/chats/files/upload"), {
234
238
  method: "POST",
235
239
  headers: {
@@ -258,6 +262,10 @@ var TrainlyClient = /** @class */ (function () {
258
262
  if (!this.config.apiKey) return [3 /*break*/, 9];
259
263
  formData = new FormData();
260
264
  formData.append("file", file);
265
+ // Add scope values if provided
266
+ if (scopeValues && Object.keys(scopeValues).length > 0) {
267
+ formData.append("scope_values", JSON.stringify(scopeValues));
268
+ }
261
269
  return [4 /*yield*/, fetch("".concat(this.config.baseUrl, "/v1/").concat(this.extractChatId(), "/upload_file"), {
262
270
  method: "POST",
263
271
  headers: {
@@ -324,7 +332,7 @@ var TrainlyClient = /** @class */ (function () {
324
332
  });
325
333
  });
326
334
  };
327
- TrainlyClient.prototype.bulkUploadFiles = function (files) {
335
+ TrainlyClient.prototype.bulkUploadFiles = function (files, scopeValues) {
328
336
  return __awaiter(this, void 0, void 0, function () {
329
337
  var formData_1, response, error, data, results, successful_uploads, total_size_bytes, _i, files_1, file, uploadResult, error_1;
330
338
  return __generator(this, function (_a) {
@@ -345,6 +353,10 @@ var TrainlyClient = /** @class */ (function () {
345
353
  files.forEach(function (file) {
346
354
  formData_1.append("files", file);
347
355
  });
356
+ // Add scope values if provided
357
+ if (scopeValues && Object.keys(scopeValues).length > 0) {
358
+ formData_1.append("scope_values", JSON.stringify(scopeValues));
359
+ }
348
360
  return [4 /*yield*/, fetch("".concat(this.config.baseUrl, "/v1/me/chats/files/upload-bulk"), {
349
361
  method: "POST",
350
362
  headers: {
@@ -386,7 +398,7 @@ var TrainlyClient = /** @class */ (function () {
386
398
  _a.label = 7;
387
399
  case 7:
388
400
  _a.trys.push([7, 9, , 10]);
389
- return [4 /*yield*/, this.upload(file)];
401
+ return [4 /*yield*/, this.upload(file, scopeValues)];
390
402
  case 8:
391
403
  uploadResult = _a.sent();
392
404
  results.push({
@@ -6,5 +6,6 @@ export interface TrainlyUploadProps {
6
6
  className?: string;
7
7
  onUpload?: (files: File[]) => void;
8
8
  onError?: (error: string) => void;
9
+ scopeValues?: Record<string, string | number | boolean>;
9
10
  }
10
- export declare function TrainlyUpload({ variant, accept, maxSize, multiple, className, onUpload, onError, }: TrainlyUploadProps): import("react/jsx-runtime").JSX.Element;
11
+ export declare function TrainlyUpload({ variant, accept, maxSize, multiple, className, onUpload, onError, scopeValues, }: TrainlyUploadProps): import("react/jsx-runtime").JSX.Element;
@@ -40,7 +40,7 @@ import * as React from "react";
40
40
  import { useTrainly } from "../useTrainly";
41
41
  export function TrainlyUpload(_a) {
42
42
  var _this = this;
43
- var _b = _a.variant, variant = _b === void 0 ? "drag-drop" : _b, _c = _a.accept, accept = _c === void 0 ? ".pdf,.doc,.docx,.txt,.md" : _c, _d = _a.maxSize, maxSize = _d === void 0 ? "10MB" : _d, _e = _a.multiple, multiple = _e === void 0 ? false : _e, _f = _a.className, className = _f === void 0 ? "" : _f, onUpload = _a.onUpload, onError = _a.onError;
43
+ var _b = _a.variant, variant = _b === void 0 ? "drag-drop" : _b, _c = _a.accept, accept = _c === void 0 ? ".pdf,.doc,.docx,.txt,.md" : _c, _d = _a.maxSize, maxSize = _d === void 0 ? "10MB" : _d, _e = _a.multiple, multiple = _e === void 0 ? false : _e, _f = _a.className, className = _f === void 0 ? "" : _f, onUpload = _a.onUpload, onError = _a.onError, scopeValues = _a.scopeValues;
44
44
  var _g = useTrainly(), upload = _g.upload, isLoading = _g.isLoading;
45
45
  var _h = React.useState(false), isDragOver = _h[0], setIsDragOver = _h[1];
46
46
  var fileInputRef = React.useRef(null);
@@ -70,7 +70,7 @@ export function TrainlyUpload(_a) {
70
70
  case 2:
71
71
  if (!(_a < fileArray_2.length)) return [3 /*break*/, 5];
72
72
  file = fileArray_2[_a];
73
- return [4 /*yield*/, upload(file)];
73
+ return [4 /*yield*/, upload(file, scopeValues)];
74
74
  case 3:
75
75
  _b.sent();
76
76
  _b.label = 4;
package/dist/types.d.ts CHANGED
@@ -93,10 +93,10 @@ export interface TrainlyContextValue {
93
93
  answer: string;
94
94
  citations: Citation[];
95
95
  }>;
96
- upload: (file: File) => Promise<UploadResult>;
96
+ upload: (file: File, scopeValues?: Record<string, string | number | boolean>) => Promise<UploadResult>;
97
97
  listFiles: () => Promise<FileListResult>;
98
98
  deleteFile: (fileId: string) => Promise<FileDeleteResult>;
99
- bulkUploadFiles: (files: File[]) => Promise<BulkUploadResult>;
99
+ bulkUploadFiles: (files: File[], scopeValues?: Record<string, string | number | boolean>) => Promise<BulkUploadResult>;
100
100
  connectWithOAuthToken: (idToken: string) => Promise<void>;
101
101
  isLoading: boolean;
102
102
  isConnected: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trainly/react",
3
- "version": "1.3.1",
3
+ "version": "1.4.0",
4
4
  "description": "Dead simple RAG integration for React apps with OAuth authentication",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",