@trainly/react 1.6.1 → 1.6.3
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/dist/TrainlyProvider.js +58 -0
- package/dist/api/TrainlyClient.d.ts +17 -0
- package/dist/api/TrainlyClient.js +65 -3
- package/dist/types.d.ts +16 -0
- package/package.json +1 -1
package/dist/TrainlyProvider.js
CHANGED
|
@@ -692,6 +692,62 @@ export function TrainlyProvider(_a) {
|
|
|
692
692
|
var clearError = function () { return setError(null); };
|
|
693
693
|
var reconnect = function () { return connect(); };
|
|
694
694
|
var clearMessages = function () { return setMessages([]); };
|
|
695
|
+
var getChatSettings = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
696
|
+
var res, err_11, error_10;
|
|
697
|
+
return __generator(this, function (_a) {
|
|
698
|
+
switch (_a.label) {
|
|
699
|
+
case 0:
|
|
700
|
+
_a.trys.push([0, 2, 3, 4]);
|
|
701
|
+
setIsLoading(true);
|
|
702
|
+
setError(null);
|
|
703
|
+
return [4 /*yield*/, client.getChatSettings()];
|
|
704
|
+
case 1:
|
|
705
|
+
res = _a.sent();
|
|
706
|
+
return [2 /*return*/, res];
|
|
707
|
+
case 2:
|
|
708
|
+
err_11 = _a.sent();
|
|
709
|
+
error_10 = {
|
|
710
|
+
code: "GET_CHAT_SETTINGS_FAILED",
|
|
711
|
+
message: "Failed to fetch chat settings",
|
|
712
|
+
details: err_11,
|
|
713
|
+
};
|
|
714
|
+
setError(error_10);
|
|
715
|
+
throw error_10;
|
|
716
|
+
case 3:
|
|
717
|
+
setIsLoading(false);
|
|
718
|
+
return [7 /*endfinally*/];
|
|
719
|
+
case 4: return [2 /*return*/];
|
|
720
|
+
}
|
|
721
|
+
});
|
|
722
|
+
}); };
|
|
723
|
+
var updateChatSettings = function (settings) { return __awaiter(_this, void 0, void 0, function () {
|
|
724
|
+
var res, err_12, error_11;
|
|
725
|
+
return __generator(this, function (_a) {
|
|
726
|
+
switch (_a.label) {
|
|
727
|
+
case 0:
|
|
728
|
+
_a.trys.push([0, 2, 3, 4]);
|
|
729
|
+
setIsLoading(true);
|
|
730
|
+
setError(null);
|
|
731
|
+
return [4 /*yield*/, client.updateChatSettings(settings)];
|
|
732
|
+
case 1:
|
|
733
|
+
res = _a.sent();
|
|
734
|
+
return [2 /*return*/, res];
|
|
735
|
+
case 2:
|
|
736
|
+
err_12 = _a.sent();
|
|
737
|
+
error_11 = {
|
|
738
|
+
code: "UPDATE_CHAT_SETTINGS_FAILED",
|
|
739
|
+
message: "Failed to update chat settings",
|
|
740
|
+
details: err_12,
|
|
741
|
+
};
|
|
742
|
+
setError(error_11);
|
|
743
|
+
throw error_11;
|
|
744
|
+
case 3:
|
|
745
|
+
setIsLoading(false);
|
|
746
|
+
return [7 /*endfinally*/];
|
|
747
|
+
case 4: return [2 /*return*/];
|
|
748
|
+
}
|
|
749
|
+
});
|
|
750
|
+
}); };
|
|
695
751
|
var value = {
|
|
696
752
|
ask: ask,
|
|
697
753
|
askWithCitations: askWithCitations, // Deprecated - kept for backward compatibility
|
|
@@ -701,6 +757,8 @@ export function TrainlyProvider(_a) {
|
|
|
701
757
|
bulkUploadText: bulkUploadText, // NEW: Bulk text content upload
|
|
702
758
|
listFiles: listFiles, // NEW: File management methods
|
|
703
759
|
deleteFile: deleteFile,
|
|
760
|
+
getChatSettings: getChatSettings,
|
|
761
|
+
updateChatSettings: updateChatSettings,
|
|
704
762
|
connectWithOAuthToken: connectWithOAuthToken, // NEW: V1 OAuth connection method
|
|
705
763
|
isLoading: isLoading,
|
|
706
764
|
isConnected: isConnected,
|
|
@@ -27,6 +27,23 @@ export declare class TrainlyClient {
|
|
|
27
27
|
deleteFile(fileId: string): Promise<FileDeleteResult>;
|
|
28
28
|
private waitForFileReady;
|
|
29
29
|
private getChatId;
|
|
30
|
+
getChatSettings(): Promise<{
|
|
31
|
+
success: boolean;
|
|
32
|
+
chat_id?: string;
|
|
33
|
+
settings?: any;
|
|
34
|
+
}>;
|
|
35
|
+
updateChatSettings(settings: {
|
|
36
|
+
custom_prompt?: string;
|
|
37
|
+
temperature?: number;
|
|
38
|
+
max_tokens?: number;
|
|
39
|
+
selected_model?: string;
|
|
40
|
+
}): Promise<{
|
|
41
|
+
success: boolean;
|
|
42
|
+
chat_id?: string;
|
|
43
|
+
updated?: any;
|
|
44
|
+
settings?: any;
|
|
45
|
+
message?: string;
|
|
46
|
+
}>;
|
|
30
47
|
private extractChatId;
|
|
31
48
|
private generateAnonymousId;
|
|
32
49
|
}
|
|
@@ -142,11 +142,12 @@ var TrainlyClient = /** @class */ (function () {
|
|
|
142
142
|
};
|
|
143
143
|
TrainlyClient.prototype.ask = function (question_1) {
|
|
144
144
|
return __awaiter(this, arguments, void 0, function (question, options) {
|
|
145
|
-
var params, response_1, error, data_1, url, headers, body, response, error, data;
|
|
145
|
+
var includeCitations, params, response_1, error, data_1, url, headers, body, response, error, data;
|
|
146
146
|
if (options === void 0) { options = {}; }
|
|
147
147
|
return __generator(this, function (_a) {
|
|
148
148
|
switch (_a.label) {
|
|
149
149
|
case 0:
|
|
150
|
+
includeCitations = options.includeCitations !== false;
|
|
150
151
|
if (!this.scopedToken) {
|
|
151
152
|
throw new Error("Not connected. Call connect() or connectWithOAuthToken() first.");
|
|
152
153
|
}
|
|
@@ -181,7 +182,7 @@ var TrainlyClient = /** @class */ (function () {
|
|
|
181
182
|
data_1 = _a.sent();
|
|
182
183
|
return [2 /*return*/, {
|
|
183
184
|
answer: data_1.answer,
|
|
184
|
-
citations: data_1.citations || [],
|
|
185
|
+
citations: includeCitations ? data_1.citations || [] : [],
|
|
185
186
|
}];
|
|
186
187
|
case 5:
|
|
187
188
|
url = this.config.apiKey
|
|
@@ -218,7 +219,7 @@ var TrainlyClient = /** @class */ (function () {
|
|
|
218
219
|
data = _a.sent();
|
|
219
220
|
return [2 /*return*/, {
|
|
220
221
|
answer: data.answer,
|
|
221
|
-
citations: data.citations || [],
|
|
222
|
+
citations: includeCitations ? data.citations || [] : [],
|
|
222
223
|
}];
|
|
223
224
|
}
|
|
224
225
|
});
|
|
@@ -850,6 +851,67 @@ var TrainlyClient = /** @class */ (function () {
|
|
|
850
851
|
}
|
|
851
852
|
return this.extractChatId();
|
|
852
853
|
};
|
|
854
|
+
// === Chat settings management ===
|
|
855
|
+
TrainlyClient.prototype.getChatSettings = function () {
|
|
856
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
857
|
+
var response, text;
|
|
858
|
+
return __generator(this, function (_a) {
|
|
859
|
+
switch (_a.label) {
|
|
860
|
+
case 0:
|
|
861
|
+
if (!this.config.apiKey) {
|
|
862
|
+
throw new Error("API key required to get chat settings");
|
|
863
|
+
}
|
|
864
|
+
return [4 /*yield*/, fetch("".concat(this.config.baseUrl, "/v1/").concat(this.getChatId(), "/settings"), {
|
|
865
|
+
method: "GET",
|
|
866
|
+
headers: {
|
|
867
|
+
Authorization: "Bearer ".concat(this.config.apiKey),
|
|
868
|
+
},
|
|
869
|
+
})];
|
|
870
|
+
case 1:
|
|
871
|
+
response = _a.sent();
|
|
872
|
+
if (!!response.ok) return [3 /*break*/, 3];
|
|
873
|
+
return [4 /*yield*/, response.text()];
|
|
874
|
+
case 2:
|
|
875
|
+
text = _a.sent();
|
|
876
|
+
console.error("[TrainlyClient] getChatSettings failed", response.status, response.statusText, text);
|
|
877
|
+
throw new Error("Failed to fetch chat settings: ".concat(response.status, " ").concat(response.statusText, " - ").concat(text));
|
|
878
|
+
case 3: return [4 /*yield*/, response.json()];
|
|
879
|
+
case 4: return [2 /*return*/, _a.sent()];
|
|
880
|
+
}
|
|
881
|
+
});
|
|
882
|
+
});
|
|
883
|
+
};
|
|
884
|
+
TrainlyClient.prototype.updateChatSettings = function (settings) {
|
|
885
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
886
|
+
var response, text;
|
|
887
|
+
return __generator(this, function (_a) {
|
|
888
|
+
switch (_a.label) {
|
|
889
|
+
case 0:
|
|
890
|
+
if (!this.config.apiKey) {
|
|
891
|
+
throw new Error("API key required to update chat settings");
|
|
892
|
+
}
|
|
893
|
+
return [4 /*yield*/, fetch("".concat(this.config.baseUrl, "/v1/").concat(this.getChatId(), "/settings"), {
|
|
894
|
+
method: "POST",
|
|
895
|
+
headers: {
|
|
896
|
+
"Content-Type": "application/json",
|
|
897
|
+
Authorization: "Bearer ".concat(this.config.apiKey),
|
|
898
|
+
},
|
|
899
|
+
body: JSON.stringify(settings),
|
|
900
|
+
})];
|
|
901
|
+
case 1:
|
|
902
|
+
response = _a.sent();
|
|
903
|
+
if (!!response.ok) return [3 /*break*/, 3];
|
|
904
|
+
return [4 /*yield*/, response.text()];
|
|
905
|
+
case 2:
|
|
906
|
+
text = _a.sent();
|
|
907
|
+
console.error("[TrainlyClient] updateChatSettings failed", response.status, response.statusText, text);
|
|
908
|
+
throw new Error("Failed to update chat settings: ".concat(response.status, " ").concat(response.statusText, " - ").concat(text));
|
|
909
|
+
case 3: return [4 /*yield*/, response.json()];
|
|
910
|
+
case 4: return [2 /*return*/, _a.sent()];
|
|
911
|
+
}
|
|
912
|
+
});
|
|
913
|
+
});
|
|
914
|
+
};
|
|
853
915
|
TrainlyClient.prototype.extractChatId = function () {
|
|
854
916
|
if (!this.config.apiKey) {
|
|
855
917
|
throw new Error("API key not provided");
|
package/dist/types.d.ts
CHANGED
|
@@ -110,6 +110,22 @@ export interface TrainlyContextValue {
|
|
|
110
110
|
deleteFile: (fileId: string) => Promise<FileDeleteResult>;
|
|
111
111
|
bulkUploadFiles: (files: File[], scopeValues?: Record<string, string | number | boolean>) => Promise<BulkUploadResult>;
|
|
112
112
|
bulkUploadText: (textContents: TextContent[], scopeValues?: Record<string, string | number | boolean>) => Promise<BulkUploadResult>;
|
|
113
|
+
getChatSettings: () => Promise<{
|
|
114
|
+
success: boolean;
|
|
115
|
+
chat_id?: string;
|
|
116
|
+
settings?: any;
|
|
117
|
+
}>;
|
|
118
|
+
updateChatSettings: (settings: {
|
|
119
|
+
custom_prompt?: string;
|
|
120
|
+
temperature?: number;
|
|
121
|
+
max_tokens?: number;
|
|
122
|
+
selected_model?: string;
|
|
123
|
+
}) => Promise<{
|
|
124
|
+
success: boolean;
|
|
125
|
+
chat_id?: string;
|
|
126
|
+
updated?: any;
|
|
127
|
+
message?: string;
|
|
128
|
+
}>;
|
|
113
129
|
connectWithOAuthToken: (idToken: string) => Promise<void>;
|
|
114
130
|
isLoading: boolean;
|
|
115
131
|
isConnected: boolean;
|