@trainly/react 1.0.0 → 1.0.2

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.
@@ -1,7 +1,7 @@
1
- import { ReactNode } from "react";
1
+ import * as React from "react";
2
2
  import { TrainlyContextValue } from "./types";
3
3
  export interface TrainlyProviderProps {
4
- children: ReactNode;
4
+ children: React.ReactNode;
5
5
  appSecret?: string;
6
6
  apiKey?: string;
7
7
  baseUrl?: string;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -44,18 +43,15 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
44
43
  }
45
44
  return to.concat(ar || Array.prototype.slice.call(from));
46
45
  };
47
- Object.defineProperty(exports, "__esModule", { value: true });
48
- exports.TrainlyProvider = TrainlyProvider;
49
- exports.useTrainlyContext = useTrainlyContext;
50
- var jsx_runtime_1 = require("react/jsx-runtime");
51
- var react_1 = require("react");
52
- var TrainlyClient_1 = require("./api/TrainlyClient");
53
- var TrainlyContext = (0, react_1.createContext)(undefined);
54
- function TrainlyProvider(_a) {
46
+ import { jsx as _jsx } from "react/jsx-runtime";
47
+ import * as React from "react";
48
+ import { TrainlyClient } from "./api/TrainlyClient";
49
+ var TrainlyContext = React.createContext(undefined);
50
+ export function TrainlyProvider(_a) {
55
51
  var _this = this;
56
- var children = _a.children, appSecret = _a.appSecret, apiKey = _a.apiKey, _b = _a.baseUrl, baseUrl = _b === void 0 ? "https://api.trainly.com" : _b, userId = _a.userId, userEmail = _a.userEmail;
57
- var client = (0, react_1.useState)(function () {
58
- return new TrainlyClient_1.TrainlyClient({
52
+ var children = _a.children, appSecret = _a.appSecret, apiKey = _a.apiKey, _b = _a.baseUrl, baseUrl = _b === void 0 ? "http://localhost:8000" : _b, userId = _a.userId, userEmail = _a.userEmail;
53
+ var client = React.useState(function () {
54
+ return new TrainlyClient({
59
55
  appSecret: appSecret,
60
56
  apiKey: apiKey,
61
57
  baseUrl: baseUrl,
@@ -63,12 +59,12 @@ function TrainlyProvider(_a) {
63
59
  userEmail: userEmail,
64
60
  });
65
61
  })[0];
66
- var _c = (0, react_1.useState)(false), isLoading = _c[0], setIsLoading = _c[1];
67
- var _d = (0, react_1.useState)(false), isConnected = _d[0], setIsConnected = _d[1];
68
- var _e = (0, react_1.useState)(null), error = _e[0], setError = _e[1];
69
- var _f = (0, react_1.useState)([]), messages = _f[0], setMessages = _f[1];
62
+ var _c = React.useState(false), isLoading = _c[0], setIsLoading = _c[1];
63
+ var _d = React.useState(false), isConnected = _d[0], setIsConnected = _d[1];
64
+ var _e = React.useState(null), error = _e[0], setError = _e[1];
65
+ var _f = React.useState([]), messages = _f[0], setMessages = _f[1];
70
66
  // Auto-connect on mount
71
- (0, react_1.useEffect)(function () {
67
+ React.useEffect(function () {
72
68
  connect();
73
69
  }, []);
74
70
  var connect = function () { return __awaiter(_this, void 0, void 0, function () {
@@ -239,10 +235,10 @@ function TrainlyProvider(_a) {
239
235
  sendMessage: sendMessage,
240
236
  clearMessages: clearMessages,
241
237
  };
242
- return ((0, jsx_runtime_1.jsx)(TrainlyContext.Provider, { value: value, children: children }));
238
+ return (_jsx(TrainlyContext.Provider, { value: value, children: children }));
243
239
  }
244
- function useTrainlyContext() {
245
- var context = (0, react_1.useContext)(TrainlyContext);
240
+ export function useTrainlyContext() {
241
+ var context = React.useContext(TrainlyContext);
246
242
  if (context === undefined) {
247
243
  throw new Error("useTrainlyContext must be used within a TrainlyProvider");
248
244
  }
@@ -6,6 +6,7 @@ interface QueryResponse {
6
6
  export declare class TrainlyClient {
7
7
  private config;
8
8
  private scopedToken;
9
+ private currentUserId;
9
10
  constructor(config: TrainlyConfig);
10
11
  connect(): Promise<void>;
11
12
  ask(question: string, options?: {
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -35,11 +34,10 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
34
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
35
  }
37
36
  };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.TrainlyClient = void 0;
40
37
  var TrainlyClient = /** @class */ (function () {
41
38
  function TrainlyClient(config) {
42
39
  this.scopedToken = null;
40
+ this.currentUserId = null;
43
41
  this.config = config;
44
42
  }
45
43
  TrainlyClient.prototype.connect = function () {
@@ -56,6 +54,11 @@ var TrainlyClient = /** @class */ (function () {
56
54
  if (!this.config.appSecret) {
57
55
  throw new Error("Either appSecret or apiKey must be provided");
58
56
  }
57
+ // App secret mode - provision user
58
+ // Ensure we use the same user ID consistently
59
+ if (!this.currentUserId) {
60
+ this.currentUserId = this.config.userId || this.generateAnonymousId();
61
+ }
59
62
  return [4 /*yield*/, fetch("".concat(this.config.baseUrl, "/v1/privacy/apps/users/provision"), {
60
63
  method: "POST",
61
64
  headers: {
@@ -63,7 +66,7 @@ var TrainlyClient = /** @class */ (function () {
63
66
  "Content-Type": "application/json",
64
67
  },
65
68
  body: JSON.stringify({
66
- end_user_id: this.config.userId || this.generateAnonymousId(),
69
+ end_user_id: this.currentUserId,
67
70
  capabilities: ["ask", "upload"],
68
71
  }),
69
72
  })];
@@ -105,7 +108,9 @@ var TrainlyClient = /** @class */ (function () {
105
108
  }
106
109
  else {
107
110
  headers["x-scoped-token"] = this.scopedToken;
108
- body.end_user_id = this.config.userId || this.generateAnonymousId();
111
+ // Use the same user ID that was used during provisioning
112
+ body.end_user_id =
113
+ this.currentUserId || this.config.userId || this.generateAnonymousId();
109
114
  body.include_citations = options.includeCitations || false;
110
115
  }
111
116
  return [4 /*yield*/, fetch(url, {
@@ -170,7 +175,9 @@ var TrainlyClient = /** @class */ (function () {
170
175
  "x-scoped-token": this.scopedToken,
171
176
  },
172
177
  body: JSON.stringify({
173
- end_user_id: this.config.userId || this.generateAnonymousId(),
178
+ end_user_id: this.currentUserId ||
179
+ this.config.userId ||
180
+ this.generateAnonymousId(),
174
181
  filename: file.name,
175
182
  file_type: file.type,
176
183
  }),
@@ -223,4 +230,4 @@ var TrainlyClient = /** @class */ (function () {
223
230
  };
224
231
  return TrainlyClient;
225
232
  }());
226
- exports.TrainlyClient = TrainlyClient;
233
+ export { TrainlyClient };
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -35,25 +34,23 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
34
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
35
  }
37
36
  };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.TrainlyChat = TrainlyChat;
40
- var jsx_runtime_1 = require("react/jsx-runtime");
41
- var react_1 = require("react");
42
- var useTrainly_1 = require("../useTrainly");
43
- function TrainlyChat(_a) {
37
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
38
+ import * as React from "react";
39
+ import { useTrainly } from "../useTrainly";
40
+ export function TrainlyChat(_a) {
44
41
  var _this = this;
45
42
  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, onMessage = _a.onMessage, onError = _a.onError;
46
- var _h = (0, useTrainly_1.useTrainly)(), messages = _h.messages, sendMessage = _h.sendMessage, isLoading = _h.isLoading, error = _h.error, clearError = _h.clearError;
47
- var _j = (0, react_1.useState)(""), input = _j[0], setInput = _j[1];
48
- var messagesEndRef = (0, react_1.useRef)(null);
49
- var fileInputRef = (0, react_1.useRef)(null);
43
+ var _h = useTrainly(), messages = _h.messages, sendMessage = _h.sendMessage, isLoading = _h.isLoading, error = _h.error, clearError = _h.clearError;
44
+ var _j = React.useState(""), input = _j[0], setInput = _j[1];
45
+ var messagesEndRef = React.useRef(null);
46
+ var fileInputRef = React.useRef(null);
50
47
  // Auto-scroll to bottom
51
- (0, react_1.useEffect)(function () {
48
+ React.useEffect(function () {
52
49
  var _a;
53
50
  (_a = messagesEndRef.current) === null || _a === void 0 ? void 0 : _a.scrollIntoView({ behavior: "smooth" });
54
51
  }, [messages]);
55
52
  // Handle errors
56
- (0, react_1.useEffect)(function () {
53
+ React.useEffect(function () {
57
54
  if (error && onError) {
58
55
  onError(error.message);
59
56
  }
@@ -93,9 +90,9 @@ function TrainlyChat(_a) {
93
90
  }
94
91
  };
95
92
  var baseClasses = "\n flex flex-col border border-gray-200 rounded-lg overflow-hidden\n ".concat(theme === "dark" ? "bg-gray-900 text-white border-gray-700" : "bg-white text-gray-900", "\n ").concat(className, "\n ");
96
- return ((0, jsx_runtime_1.jsxs)("div", { className: baseClasses, style: { height: height }, children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex-1 overflow-y-auto p-4 space-y-4", children: [messages.length === 0 && ((0, jsx_runtime_1.jsx)("div", { className: "text-center text-gray-500 py-8", children: (0, jsx_runtime_1.jsx)("p", { children: "Start a conversation by asking a question!" }) })), messages.map(function (message) { return ((0, jsx_runtime_1.jsx)("div", { className: "flex ".concat(message.role === "user" ? "justify-end" : "justify-start"), children: (0, jsx_runtime_1.jsxs)("div", { className: "\n max-w-[80%] p-3 rounded-lg\n ".concat(message.role === "user"
93
+ return (_jsxs("div", { className: baseClasses, style: { height: height }, children: [_jsxs("div", { className: "flex-1 overflow-y-auto p-4 space-y-4", children: [messages.length === 0 && (_jsx("div", { className: "text-center text-gray-500 py-8", children: _jsx("p", { children: "Start a conversation by asking a question!" }) })), messages.map(function (message) { return (_jsx("div", { className: "flex ".concat(message.role === "user" ? "justify-end" : "justify-start"), children: _jsxs("div", { className: "\n max-w-[80%] p-3 rounded-lg\n ".concat(message.role === "user"
97
94
  ? "bg-blue-500 text-white rounded-br-none"
98
- : "bg-gray-100 text-gray-900 rounded-bl-none", "\n "), children: [(0, jsx_runtime_1.jsx)("p", { className: "whitespace-pre-wrap", children: message.content }), showCitations &&
95
+ : "bg-gray-100 text-gray-900 rounded-bl-none", "\n "), children: [_jsx("p", { className: "whitespace-pre-wrap", children: message.content }), showCitations &&
99
96
  message.citations &&
100
- message.citations.length > 0 && ((0, jsx_runtime_1.jsxs)("div", { className: "mt-3 pt-3 border-t border-gray-300", children: [(0, jsx_runtime_1.jsx)("p", { className: "text-xs font-semibold mb-2", children: "Sources:" }), message.citations.map(function (citation, idx) { return ((0, jsx_runtime_1.jsxs)("div", { className: "text-xs bg-white bg-opacity-20 p-2 rounded mb-1", children: [(0, jsx_runtime_1.jsx)("p", { className: "font-medium", children: citation.source }), (0, jsx_runtime_1.jsxs)("p", { className: "opacity-75", children: ["\"", citation.snippet, "\""] })] }, idx)); })] }))] }) }, message.id)); }), isLoading && ((0, jsx_runtime_1.jsx)("div", { className: "flex justify-start", children: (0, jsx_runtime_1.jsx)("div", { className: "bg-gray-100 text-gray-900 p-3 rounded-lg rounded-bl-none", children: (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center space-x-2", children: [(0, jsx_runtime_1.jsx)("div", { className: "animate-spin rounded-full h-4 w-4 border-b-2 border-blue-500" }), (0, jsx_runtime_1.jsx)("span", { children: "Thinking..." })] }) }) })), (0, jsx_runtime_1.jsx)("div", { ref: messagesEndRef })] }), error && ((0, jsx_runtime_1.jsx)("div", { className: "px-4 py-2 bg-red-50 border-t border-red-200 text-red-700 text-sm", children: (0, jsx_runtime_1.jsxs)("div", { className: "flex justify-between items-center", children: [(0, jsx_runtime_1.jsx)("span", { children: error.message }), (0, jsx_runtime_1.jsx)("button", { onClick: clearError, className: "text-red-500 hover:text-red-700", children: "\u00D7" })] }) })), (0, jsx_runtime_1.jsx)("div", { className: "border-t border-gray-200 p-4", children: (0, jsx_runtime_1.jsxs)("form", { onSubmit: handleSubmit, className: "flex gap-2", children: [enableFileUpload && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("input", { ref: fileInputRef, type: "file", accept: ".pdf,.doc,.docx,.txt,.md", onChange: handleFileUpload, className: "hidden" }), (0, jsx_runtime_1.jsx)("button", { type: "button", onClick: function () { var _a; return (_a = fileInputRef.current) === null || _a === void 0 ? void 0 : _a.click(); }, className: "px-3 py-2 text-gray-500 hover:text-gray-700 border border-gray-300 rounded-lg", title: "Upload file", children: "\uD83D\uDCCE" })] })), (0, jsx_runtime_1.jsx)("input", { type: "text", value: input, onChange: function (e) { return setInput(e.target.value); }, placeholder: placeholder, disabled: isLoading, className: "flex-1 px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" }), (0, jsx_runtime_1.jsx)("button", { type: "submit", disabled: isLoading || !input.trim(), className: "px-4 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600 disabled:opacity-50 disabled:cursor-not-allowed", children: "Send" })] }) })] }));
97
+ message.citations.length > 0 && (_jsxs("div", { className: "mt-3 pt-3 border-t border-gray-300", children: [_jsx("p", { className: "text-xs font-semibold mb-2", children: "Sources:" }), message.citations.map(function (citation, idx) { return (_jsxs("div", { className: "text-xs bg-white bg-opacity-20 p-2 rounded mb-1", children: [_jsx("p", { className: "font-medium", children: citation.source }), _jsxs("p", { className: "opacity-75", children: ["\"", citation.snippet, "\""] })] }, idx)); })] }))] }) }, message.id)); }), isLoading && (_jsx("div", { className: "flex justify-start", children: _jsx("div", { className: "bg-gray-100 text-gray-900 p-3 rounded-lg rounded-bl-none", children: _jsxs("div", { className: "flex items-center space-x-2", children: [_jsx("div", { className: "animate-spin rounded-full h-4 w-4 border-b-2 border-blue-500" }), _jsx("span", { children: "Thinking..." })] }) }) })), _jsx("div", { ref: messagesEndRef })] }), error && (_jsx("div", { className: "px-4 py-2 bg-red-50 border-t border-red-200 text-red-700 text-sm", children: _jsxs("div", { className: "flex justify-between items-center", children: [_jsx("span", { children: error.message }), _jsx("button", { onClick: clearError, className: "text-red-500 hover:text-red-700", children: "\u00D7" })] }) })), _jsx("div", { className: "border-t border-gray-200 p-4", children: _jsxs("form", { onSubmit: handleSubmit, className: "flex gap-2", children: [enableFileUpload && (_jsxs(_Fragment, { children: [_jsx("input", { ref: fileInputRef, type: "file", accept: ".pdf,.doc,.docx,.txt,.md", onChange: handleFileUpload, className: "hidden" }), _jsx("button", { type: "button", onClick: function () { var _a; return (_a = fileInputRef.current) === null || _a === void 0 ? void 0 : _a.click(); }, className: "px-3 py-2 text-gray-500 hover:text-gray-700 border border-gray-300 rounded-lg", title: "Upload file", children: "\uD83D\uDCCE" })] })), _jsx("input", { type: "text", value: input, onChange: function (e) { return setInput(e.target.value); }, placeholder: placeholder, disabled: isLoading, className: "flex-1 px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" }), _jsx("button", { type: "submit", disabled: isLoading || !input.trim(), className: "px-4 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600 disabled:opacity-50 disabled:cursor-not-allowed", children: "Send" })] }) })] }));
101
98
  }
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TrainlyStatus = TrainlyStatus;
4
- var jsx_runtime_1 = require("react/jsx-runtime");
5
- var useTrainly_1 = require("../useTrainly");
6
- function TrainlyStatus(_a) {
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useTrainly } from "../useTrainly";
3
+ export function TrainlyStatus(_a) {
7
4
  var _b = _a.showDetails, showDetails = _b === void 0 ? true : _b, _c = _a.position, position = _c === void 0 ? "inline" : _c, _d = _a.className, className = _d === void 0 ? "" : _d;
8
- var _e = (0, useTrainly_1.useTrainly)(), isConnected = _e.isConnected, isLoading = _e.isLoading, error = _e.error;
5
+ var _e = useTrainly(), isConnected = _e.isConnected, isLoading = _e.isLoading, error = _e.error;
9
6
  var getStatusInfo = function () {
10
7
  if (error) {
11
8
  return {
@@ -47,5 +44,5 @@ function TrainlyStatus(_a) {
47
44
  inline: "",
48
45
  };
49
46
  var baseClasses = "\n inline-flex items-center gap-2 px-3 py-2 rounded-lg border text-sm font-medium\n ".concat(status.color, "\n ").concat(positionClasses[position], "\n ").concat(className, "\n ");
50
- return ((0, jsx_runtime_1.jsxs)("div", { className: baseClasses, children: [(0, jsx_runtime_1.jsx)("span", { className: status.icon === "🔄" ? "animate-spin" : "", children: status.icon }), (0, jsx_runtime_1.jsx)("span", { children: status.text }), showDetails && status.details && ((0, jsx_runtime_1.jsxs)("span", { className: "text-xs opacity-75 ml-1", children: ["- ", status.details] }))] }));
47
+ return (_jsxs("div", { className: baseClasses, children: [_jsx("span", { className: status.icon === "🔄" ? "animate-spin" : "", children: status.icon }), _jsx("span", { children: status.text }), showDetails && status.details && (_jsxs("span", { className: "text-xs opacity-75 ml-1", children: ["- ", status.details] }))] }));
51
48
  }
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -35,17 +34,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
34
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
35
  }
37
36
  };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.TrainlyUpload = TrainlyUpload;
40
- var jsx_runtime_1 = require("react/jsx-runtime");
41
- var react_1 = require("react");
42
- var useTrainly_1 = require("../useTrainly");
43
- function TrainlyUpload(_a) {
37
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
38
+ import * as React from "react";
39
+ import { useTrainly } from "../useTrainly";
40
+ export function TrainlyUpload(_a) {
44
41
  var _this = this;
45
42
  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;
46
- var _g = (0, useTrainly_1.useTrainly)(), upload = _g.upload, isLoading = _g.isLoading;
47
- var _h = (0, react_1.useState)(false), isDragOver = _h[0], setIsDragOver = _h[1];
48
- var fileInputRef = (0, react_1.useRef)(null);
43
+ var _g = useTrainly(), upload = _g.upload, isLoading = _g.isLoading;
44
+ var _h = React.useState(false), isDragOver = _h[0], setIsDragOver = _h[1];
45
+ var fileInputRef = React.useRef(null);
49
46
  var maxSizeBytes = parseMaxSize(maxSize);
50
47
  var handleFiles = function (files) { return __awaiter(_this, void 0, void 0, function () {
51
48
  var fileArray, _i, fileArray_1, file, error, _a, fileArray_2, file, err_1;
@@ -107,15 +104,15 @@ function TrainlyUpload(_a) {
107
104
  handleFiles(e.target.files);
108
105
  };
109
106
  if (variant === "button") {
110
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("input", { ref: fileInputRef, type: "file", accept: accept, multiple: multiple, onChange: handleFileSelect, className: "hidden" }), (0, jsx_runtime_1.jsx)("button", { onClick: function () { var _a; return (_a = fileInputRef.current) === null || _a === void 0 ? void 0 : _a.click(); }, disabled: isLoading, className: "\n px-4 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600\n disabled:opacity-50 disabled:cursor-not-allowed\n ".concat(className, "\n "), children: isLoading ? "Uploading..." : "Upload Files" })] }));
107
+ return (_jsxs(_Fragment, { children: [_jsx("input", { ref: fileInputRef, type: "file", accept: accept, multiple: multiple, onChange: handleFileSelect, className: "hidden" }), _jsx("button", { onClick: function () { var _a; return (_a = fileInputRef.current) === null || _a === void 0 ? void 0 : _a.click(); }, disabled: isLoading, className: "\n px-4 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600\n disabled:opacity-50 disabled:cursor-not-allowed\n ".concat(className, "\n "), children: isLoading ? "Uploading..." : "Upload Files" })] }));
111
108
  }
112
109
  if (variant === "minimal") {
113
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("input", { ref: fileInputRef, type: "file", accept: accept, multiple: multiple, onChange: handleFileSelect, className: "hidden" }), (0, jsx_runtime_1.jsx)("button", { onClick: function () { var _a; return (_a = fileInputRef.current) === null || _a === void 0 ? void 0 : _a.click(); }, disabled: isLoading, className: "text-blue-500 hover:text-blue-600 underline ".concat(className), children: isLoading ? "Uploading..." : "Upload" })] }));
110
+ return (_jsxs(_Fragment, { children: [_jsx("input", { ref: fileInputRef, type: "file", accept: accept, multiple: multiple, onChange: handleFileSelect, className: "hidden" }), _jsx("button", { onClick: function () { var _a; return (_a = fileInputRef.current) === null || _a === void 0 ? void 0 : _a.click(); }, disabled: isLoading, className: "text-blue-500 hover:text-blue-600 underline ".concat(className), children: isLoading ? "Uploading..." : "Upload" })] }));
114
111
  }
115
112
  // Default: drag-drop variant
116
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("input", { ref: fileInputRef, type: "file", accept: accept, multiple: multiple, onChange: handleFileSelect, className: "hidden" }), (0, jsx_runtime_1.jsx)("div", { onDrop: handleDrop, onDragOver: handleDragOver, onDragLeave: handleDragLeave, onClick: function () { var _a; return (_a = fileInputRef.current) === null || _a === void 0 ? void 0 : _a.click(); }, className: "\n border-2 border-dashed border-gray-300 rounded-lg p-8 text-center cursor-pointer\n transition-colors duration-200\n ".concat(isDragOver ? "border-blue-500 bg-blue-50" : "hover:border-gray-400", "\n ").concat(isLoading ? "opacity-50 cursor-not-allowed" : "", "\n ").concat(className, "\n "), children: (0, jsx_runtime_1.jsxs)("div", { className: "space-y-4", children: [(0, jsx_runtime_1.jsx)("div", { className: "text-4xl", children: "\uD83D\uDCC4" }), (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("p", { className: "text-lg font-medium text-gray-700", children: isLoading
113
+ return (_jsxs(_Fragment, { children: [_jsx("input", { ref: fileInputRef, type: "file", accept: accept, multiple: multiple, onChange: handleFileSelect, className: "hidden" }), _jsx("div", { onDrop: handleDrop, onDragOver: handleDragOver, onDragLeave: handleDragLeave, onClick: function () { var _a; return (_a = fileInputRef.current) === null || _a === void 0 ? void 0 : _a.click(); }, className: "\n border-2 border-dashed border-gray-300 rounded-lg p-8 text-center cursor-pointer\n transition-colors duration-200\n ".concat(isDragOver ? "border-blue-500 bg-blue-50" : "hover:border-gray-400", "\n ").concat(isLoading ? "opacity-50 cursor-not-allowed" : "", "\n ").concat(className, "\n "), children: _jsxs("div", { className: "space-y-4", children: [_jsx("div", { className: "text-4xl", children: "\uD83D\uDCC4" }), _jsxs("div", { children: [_jsx("p", { className: "text-lg font-medium text-gray-700", children: isLoading
117
114
  ? "Uploading..."
118
- : "Drop files here or click to upload" }), (0, jsx_runtime_1.jsxs)("p", { className: "text-sm text-gray-500 mt-2", children: ["Supports: ", accept.replace(/\./g, "").toUpperCase(), " files up to", " ", maxSize] })] })] }) })] }));
115
+ : "Drop files here or click to upload" }), _jsxs("p", { className: "text-sm text-gray-500 mt-2", children: ["Supports: ", accept.replace(/\./g, "").toUpperCase(), " files up to", " ", maxSize] })] })] }) })] }));
119
116
  }
120
117
  function parseMaxSize(maxSize) {
121
118
  var match = maxSize.match(/^(\d+)\s*(GB|MB|KB)?$/i);
package/dist/index.js CHANGED
@@ -1,15 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TrainlyStatus = exports.TrainlyUpload = exports.TrainlyChat = exports.useTrainly = exports.TrainlyProvider = void 0;
4
1
  // Main exports for @trainly/react SDK
5
- var TrainlyProvider_1 = require("./TrainlyProvider");
6
- Object.defineProperty(exports, "TrainlyProvider", { enumerable: true, get: function () { return TrainlyProvider_1.TrainlyProvider; } });
7
- var useTrainly_1 = require("./useTrainly");
8
- Object.defineProperty(exports, "useTrainly", { enumerable: true, get: function () { return useTrainly_1.useTrainly; } });
2
+ export { TrainlyProvider } from "./TrainlyProvider";
3
+ export { useTrainly } from "./useTrainly";
9
4
  // Pre-built components
10
- var TrainlyChat_1 = require("./components/TrainlyChat");
11
- Object.defineProperty(exports, "TrainlyChat", { enumerable: true, get: function () { return TrainlyChat_1.TrainlyChat; } });
12
- var TrainlyUpload_1 = require("./components/TrainlyUpload");
13
- Object.defineProperty(exports, "TrainlyUpload", { enumerable: true, get: function () { return TrainlyUpload_1.TrainlyUpload; } });
14
- var TrainlyStatus_1 = require("./components/TrainlyStatus");
15
- Object.defineProperty(exports, "TrainlyStatus", { enumerable: true, get: function () { return TrainlyStatus_1.TrainlyStatus; } });
5
+ export { TrainlyChat } from "./components/TrainlyChat";
6
+ export { TrainlyUpload } from "./components/TrainlyUpload";
7
+ export { TrainlyStatus } from "./components/TrainlyStatus";
package/dist/types.js CHANGED
@@ -1,3 +1,2 @@
1
- "use strict";
2
1
  // Core types for Trainly React SDK
3
- Object.defineProperty(exports, "__esModule", { value: true });
2
+ export {};
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useTrainly = useTrainly;
4
- var TrainlyProvider_1 = require("./TrainlyProvider");
1
+ import { useTrainlyContext } from "./TrainlyProvider";
5
2
  /**
6
3
  * Main hook for using Trainly in your React components
7
4
  *
@@ -19,6 +16,6 @@ var TrainlyProvider_1 = require("./TrainlyProvider");
19
16
  * }
20
17
  * ```
21
18
  */
22
- function useTrainly() {
23
- return (0, TrainlyProvider_1.useTrainlyContext)();
19
+ export function useTrainly() {
20
+ return useTrainlyContext();
24
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trainly/react",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Dead simple RAG integration for React apps",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",