@trainly/react 1.6.2 → 2.0.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.
- package/dist/TrainlyProvider.js +157 -1
- package/dist/api/AnalyticsClient.d.ts +33 -0
- package/dist/api/AnalyticsClient.js +160 -0
- package/dist/api/ConfigClient.d.ts +47 -0
- package/dist/api/ConfigClient.js +201 -0
- package/dist/api/FineTuningClient.d.ts +59 -0
- package/dist/api/FineTuningClient.js +279 -0
- package/dist/api/TestingClient.d.ts +51 -0
- package/dist/api/TestingClient.js +274 -0
- package/dist/api/TrainlyClient.d.ts +35 -1
- package/dist/api/TrainlyClient.js +346 -54
- package/dist/api/VersionsClient.d.ts +18 -0
- package/dist/api/VersionsClient.js +160 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.js +6 -0
- package/dist/types.d.ts +278 -0
- package/package.json +1 -1
package/dist/TrainlyProvider.js
CHANGED
|
@@ -35,6 +35,31 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
39
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
40
|
+
var m = o[Symbol.asyncIterator], i;
|
|
41
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
42
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
43
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
44
|
+
};
|
|
45
|
+
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
46
|
+
var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
|
|
47
|
+
var i, p;
|
|
48
|
+
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
|
49
|
+
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }
|
|
50
|
+
};
|
|
51
|
+
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
52
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
53
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
54
|
+
return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
55
|
+
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
56
|
+
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
57
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
58
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
59
|
+
function fulfill(value) { resume("next", value); }
|
|
60
|
+
function reject(value) { resume("throw", value); }
|
|
61
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
62
|
+
};
|
|
38
63
|
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
39
64
|
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
40
65
|
if (ar || !(i in from)) {
|
|
@@ -44,6 +69,17 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
44
69
|
}
|
|
45
70
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
71
|
};
|
|
72
|
+
var __values = (this && this.__values) || function(o) {
|
|
73
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
74
|
+
if (m) return m.call(o);
|
|
75
|
+
if (o && typeof o.length === "number") return {
|
|
76
|
+
next: function () {
|
|
77
|
+
if (o && i >= o.length) o = void 0;
|
|
78
|
+
return { value: o && o[i++], done: !o };
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
82
|
+
};
|
|
47
83
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
48
84
|
import * as React from "react";
|
|
49
85
|
import { TrainlyClient } from "./api/TrainlyClient";
|
|
@@ -52,7 +88,7 @@ export function TrainlyProvider(_a) {
|
|
|
52
88
|
var _this = this;
|
|
53
89
|
var children = _a.children, appSecret = _a.appSecret, apiKey = _a.apiKey, appId = _a.appId, // NEW: For V1 authentication
|
|
54
90
|
_b = _a.baseUrl, // NEW: For V1 authentication
|
|
55
|
-
baseUrl = _b === void 0 ? "
|
|
91
|
+
baseUrl = _b === void 0 ? "https://api.trainlyai.com" : _b, userId = _a.userId, userEmail = _a.userEmail, getToken = _a.getToken;
|
|
56
92
|
var client = React.useState(function () {
|
|
57
93
|
return new TrainlyClient({
|
|
58
94
|
appSecret: appSecret,
|
|
@@ -692,8 +728,126 @@ export function TrainlyProvider(_a) {
|
|
|
692
728
|
var clearError = function () { return setError(null); };
|
|
693
729
|
var reconnect = function () { return connect(); };
|
|
694
730
|
var clearMessages = function () { return setMessages([]); };
|
|
731
|
+
function askStream(question, options) {
|
|
732
|
+
return __asyncGenerator(this, arguments, function askStream_1() {
|
|
733
|
+
var err_11, errorMessage, newToken, refreshErr_1, error_10;
|
|
734
|
+
return __generator(this, function (_a) {
|
|
735
|
+
switch (_a.label) {
|
|
736
|
+
case 0:
|
|
737
|
+
_a.trys.push([0, 3, 13, 14]);
|
|
738
|
+
setIsLoading(true);
|
|
739
|
+
setError(null);
|
|
740
|
+
return [5 /*yield**/, __values(__asyncDelegator(__asyncValues(client.askStream(question, options || {}))))];
|
|
741
|
+
case 1: return [4 /*yield*/, __await.apply(void 0, [_a.sent()])];
|
|
742
|
+
case 2:
|
|
743
|
+
_a.sent();
|
|
744
|
+
return [3 /*break*/, 14];
|
|
745
|
+
case 3:
|
|
746
|
+
err_11 = _a.sent();
|
|
747
|
+
errorMessage = err_11 instanceof Error ? err_11.message : String(err_11);
|
|
748
|
+
if (!(getToken &&
|
|
749
|
+
appId &&
|
|
750
|
+
(errorMessage.includes("401") ||
|
|
751
|
+
errorMessage.includes("authentication") ||
|
|
752
|
+
errorMessage.includes("Unauthorized")))) return [3 /*break*/, 12];
|
|
753
|
+
_a.label = 4;
|
|
754
|
+
case 4:
|
|
755
|
+
_a.trys.push([4, 11, , 12]);
|
|
756
|
+
console.log("🔄 Token expired, refreshing...");
|
|
757
|
+
return [4 /*yield*/, __await(getToken())];
|
|
758
|
+
case 5:
|
|
759
|
+
newToken = _a.sent();
|
|
760
|
+
if (!newToken) return [3 /*break*/, 10];
|
|
761
|
+
return [4 /*yield*/, __await(client.connectWithOAuthToken(newToken))];
|
|
762
|
+
case 6:
|
|
763
|
+
_a.sent();
|
|
764
|
+
return [5 /*yield**/, __values(__asyncDelegator(__asyncValues(client.askStream(question, options || {}))))];
|
|
765
|
+
case 7: return [4 /*yield*/, __await.apply(void 0, [_a.sent()])];
|
|
766
|
+
case 8:
|
|
767
|
+
_a.sent();
|
|
768
|
+
console.log("✅ Streaming succeeded after token refresh");
|
|
769
|
+
return [4 /*yield*/, __await(void 0)];
|
|
770
|
+
case 9: return [2 /*return*/, _a.sent()];
|
|
771
|
+
case 10: return [3 /*break*/, 12];
|
|
772
|
+
case 11:
|
|
773
|
+
refreshErr_1 = _a.sent();
|
|
774
|
+
console.error("Token refresh failed:", refreshErr_1);
|
|
775
|
+
return [3 /*break*/, 12];
|
|
776
|
+
case 12:
|
|
777
|
+
error_10 = {
|
|
778
|
+
code: "ASK_STREAM_FAILED",
|
|
779
|
+
message: "Failed to stream response",
|
|
780
|
+
details: err_11,
|
|
781
|
+
};
|
|
782
|
+
setError(error_10);
|
|
783
|
+
throw error_10;
|
|
784
|
+
case 13:
|
|
785
|
+
setIsLoading(false);
|
|
786
|
+
return [7 /*endfinally*/];
|
|
787
|
+
case 14: return [2 /*return*/];
|
|
788
|
+
}
|
|
789
|
+
});
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
var getChatSettings = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
793
|
+
var res, err_12, error_11;
|
|
794
|
+
return __generator(this, function (_a) {
|
|
795
|
+
switch (_a.label) {
|
|
796
|
+
case 0:
|
|
797
|
+
_a.trys.push([0, 2, 3, 4]);
|
|
798
|
+
setIsLoading(true);
|
|
799
|
+
setError(null);
|
|
800
|
+
return [4 /*yield*/, client.getChatSettings()];
|
|
801
|
+
case 1:
|
|
802
|
+
res = _a.sent();
|
|
803
|
+
return [2 /*return*/, res];
|
|
804
|
+
case 2:
|
|
805
|
+
err_12 = _a.sent();
|
|
806
|
+
error_11 = {
|
|
807
|
+
code: "GET_CHAT_SETTINGS_FAILED",
|
|
808
|
+
message: "Failed to fetch chat settings",
|
|
809
|
+
details: err_12,
|
|
810
|
+
};
|
|
811
|
+
setError(error_11);
|
|
812
|
+
throw error_11;
|
|
813
|
+
case 3:
|
|
814
|
+
setIsLoading(false);
|
|
815
|
+
return [7 /*endfinally*/];
|
|
816
|
+
case 4: return [2 /*return*/];
|
|
817
|
+
}
|
|
818
|
+
});
|
|
819
|
+
}); };
|
|
820
|
+
var updateChatSettings = function (settings) { return __awaiter(_this, void 0, void 0, function () {
|
|
821
|
+
var res, err_13, error_12;
|
|
822
|
+
return __generator(this, function (_a) {
|
|
823
|
+
switch (_a.label) {
|
|
824
|
+
case 0:
|
|
825
|
+
_a.trys.push([0, 2, 3, 4]);
|
|
826
|
+
setIsLoading(true);
|
|
827
|
+
setError(null);
|
|
828
|
+
return [4 /*yield*/, client.updateChatSettings(settings)];
|
|
829
|
+
case 1:
|
|
830
|
+
res = _a.sent();
|
|
831
|
+
return [2 /*return*/, res];
|
|
832
|
+
case 2:
|
|
833
|
+
err_13 = _a.sent();
|
|
834
|
+
error_12 = {
|
|
835
|
+
code: "UPDATE_CHAT_SETTINGS_FAILED",
|
|
836
|
+
message: "Failed to update chat settings",
|
|
837
|
+
details: err_13,
|
|
838
|
+
};
|
|
839
|
+
setError(error_12);
|
|
840
|
+
throw error_12;
|
|
841
|
+
case 3:
|
|
842
|
+
setIsLoading(false);
|
|
843
|
+
return [7 /*endfinally*/];
|
|
844
|
+
case 4: return [2 /*return*/];
|
|
845
|
+
}
|
|
846
|
+
});
|
|
847
|
+
}); };
|
|
695
848
|
var value = {
|
|
696
849
|
ask: ask,
|
|
850
|
+
askStream: askStream,
|
|
697
851
|
askWithCitations: askWithCitations, // Deprecated - kept for backward compatibility
|
|
698
852
|
upload: upload,
|
|
699
853
|
uploadText: uploadText, // NEW: Text content upload
|
|
@@ -701,6 +855,8 @@ export function TrainlyProvider(_a) {
|
|
|
701
855
|
bulkUploadText: bulkUploadText, // NEW: Bulk text content upload
|
|
702
856
|
listFiles: listFiles, // NEW: File management methods
|
|
703
857
|
deleteFile: deleteFile,
|
|
858
|
+
getChatSettings: getChatSettings,
|
|
859
|
+
updateChatSettings: updateChatSettings,
|
|
704
860
|
connectWithOAuthToken: connectWithOAuthToken, // NEW: V1 OAuth connection method
|
|
705
861
|
isLoading: isLoading,
|
|
706
862
|
isConnected: isConnected,
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Analytics client for query traces, metrics, and performance analysis.
|
|
3
|
+
*/
|
|
4
|
+
import { QueryTrace, QueryTraceDetails, MetricsSummary, CostBreakdown, PerformanceStats } from "../types";
|
|
5
|
+
export declare class AnalyticsClient {
|
|
6
|
+
private baseUrl;
|
|
7
|
+
private chatId;
|
|
8
|
+
private getHeaders;
|
|
9
|
+
private limited;
|
|
10
|
+
constructor(baseUrl: string, chatId: string, getHeaders: () => HeadersInit, limited?: boolean);
|
|
11
|
+
private request;
|
|
12
|
+
getQueryTraces(params?: {
|
|
13
|
+
limit?: number;
|
|
14
|
+
status?: string;
|
|
15
|
+
start_date?: string;
|
|
16
|
+
end_date?: string;
|
|
17
|
+
}): Promise<QueryTrace[]>;
|
|
18
|
+
getTraceDetails(traceId: string): Promise<QueryTraceDetails>;
|
|
19
|
+
getMetricsSummary(params?: {
|
|
20
|
+
start_date?: string;
|
|
21
|
+
end_date?: string;
|
|
22
|
+
}): Promise<MetricsSummary>;
|
|
23
|
+
exportQueryLogs(params?: {
|
|
24
|
+
format?: "csv" | "json" | "jsonl";
|
|
25
|
+
start_date?: string;
|
|
26
|
+
end_date?: string;
|
|
27
|
+
}): Promise<string>;
|
|
28
|
+
getCostBreakdown(params?: {
|
|
29
|
+
start_date?: string;
|
|
30
|
+
end_date?: string;
|
|
31
|
+
}): Promise<CostBreakdown>;
|
|
32
|
+
getPerformanceStats(): Promise<PerformanceStats>;
|
|
33
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Analytics client for query traces, metrics, and performance analysis.
|
|
3
|
+
*/
|
|
4
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
5
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
6
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
7
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
8
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
9
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
10
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
14
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
15
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
16
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
17
|
+
function step(op) {
|
|
18
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
19
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
20
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
21
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
22
|
+
switch (op[0]) {
|
|
23
|
+
case 0: case 1: t = op; break;
|
|
24
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
25
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
26
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
27
|
+
default:
|
|
28
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
29
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
30
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
31
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
32
|
+
if (t[2]) _.ops.pop();
|
|
33
|
+
_.trys.pop(); continue;
|
|
34
|
+
}
|
|
35
|
+
op = body.call(thisArg, _);
|
|
36
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
37
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var AnalyticsClient = /** @class */ (function () {
|
|
41
|
+
function AnalyticsClient(baseUrl, chatId, getHeaders, limited) {
|
|
42
|
+
if (limited === void 0) { limited = false; }
|
|
43
|
+
this.baseUrl = baseUrl;
|
|
44
|
+
this.chatId = chatId;
|
|
45
|
+
this.getHeaders = getHeaders;
|
|
46
|
+
this.limited = limited;
|
|
47
|
+
}
|
|
48
|
+
AnalyticsClient.prototype.request = function (method, endpoint, params) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
50
|
+
var queryString, url, response, error;
|
|
51
|
+
return __generator(this, function (_a) {
|
|
52
|
+
switch (_a.label) {
|
|
53
|
+
case 0:
|
|
54
|
+
queryString = params ? "?".concat(new URLSearchParams(params)) : "";
|
|
55
|
+
url = "".concat(this.baseUrl, "/").concat(endpoint).concat(queryString);
|
|
56
|
+
return [4 /*yield*/, fetch(url, {
|
|
57
|
+
method: method,
|
|
58
|
+
headers: this.getHeaders(),
|
|
59
|
+
})];
|
|
60
|
+
case 1:
|
|
61
|
+
response = _a.sent();
|
|
62
|
+
if (!!response.ok) return [3 /*break*/, 3];
|
|
63
|
+
return [4 /*yield*/, response.json().catch(function () { return ({ detail: response.statusText }); })];
|
|
64
|
+
case 2:
|
|
65
|
+
error = _a.sent();
|
|
66
|
+
throw new Error(error.detail || "HTTP ".concat(response.status));
|
|
67
|
+
case 3: return [2 /*return*/, response.json()];
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
// Query Traces
|
|
73
|
+
AnalyticsClient.prototype.getQueryTraces = function (params) {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
75
|
+
var searchParams, result;
|
|
76
|
+
return __generator(this, function (_a) {
|
|
77
|
+
switch (_a.label) {
|
|
78
|
+
case 0:
|
|
79
|
+
searchParams = {
|
|
80
|
+
limit: ((params === null || params === void 0 ? void 0 : params.limit) || 100).toString(),
|
|
81
|
+
};
|
|
82
|
+
if (params === null || params === void 0 ? void 0 : params.status)
|
|
83
|
+
searchParams.status = params.status;
|
|
84
|
+
if (params === null || params === void 0 ? void 0 : params.start_date)
|
|
85
|
+
searchParams.start_date = params.start_date;
|
|
86
|
+
if (params === null || params === void 0 ? void 0 : params.end_date)
|
|
87
|
+
searchParams.end_date = params.end_date;
|
|
88
|
+
return [4 /*yield*/, this.request("GET", "v1/".concat(this.chatId, "/analytics/traces"), searchParams)];
|
|
89
|
+
case 1:
|
|
90
|
+
result = _a.sent();
|
|
91
|
+
return [2 /*return*/, result.traces];
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
AnalyticsClient.prototype.getTraceDetails = function (traceId) {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
98
|
+
return __generator(this, function (_a) {
|
|
99
|
+
return [2 /*return*/, this.request("GET", "v1/".concat(this.chatId, "/analytics/traces/").concat(traceId))];
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
// Metrics & Analytics
|
|
104
|
+
AnalyticsClient.prototype.getMetricsSummary = function (params) {
|
|
105
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
106
|
+
var searchParams;
|
|
107
|
+
return __generator(this, function (_a) {
|
|
108
|
+
searchParams = {};
|
|
109
|
+
if (params === null || params === void 0 ? void 0 : params.start_date)
|
|
110
|
+
searchParams.start_date = params.start_date;
|
|
111
|
+
if (params === null || params === void 0 ? void 0 : params.end_date)
|
|
112
|
+
searchParams.end_date = params.end_date;
|
|
113
|
+
return [2 /*return*/, this.request("GET", "v1/".concat(this.chatId, "/analytics/metrics"), searchParams)];
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
AnalyticsClient.prototype.exportQueryLogs = function (params) {
|
|
118
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
119
|
+
var searchParams, result;
|
|
120
|
+
return __generator(this, function (_a) {
|
|
121
|
+
switch (_a.label) {
|
|
122
|
+
case 0:
|
|
123
|
+
searchParams = {
|
|
124
|
+
format: (params === null || params === void 0 ? void 0 : params.format) || "csv",
|
|
125
|
+
};
|
|
126
|
+
if (params === null || params === void 0 ? void 0 : params.start_date)
|
|
127
|
+
searchParams.start_date = params.start_date;
|
|
128
|
+
if (params === null || params === void 0 ? void 0 : params.end_date)
|
|
129
|
+
searchParams.end_date = params.end_date;
|
|
130
|
+
return [4 /*yield*/, this.request("GET", "v1/".concat(this.chatId, "/analytics/export"), searchParams)];
|
|
131
|
+
case 1:
|
|
132
|
+
result = _a.sent();
|
|
133
|
+
return [2 /*return*/, result.download_url];
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
AnalyticsClient.prototype.getCostBreakdown = function (params) {
|
|
139
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
140
|
+
var searchParams;
|
|
141
|
+
return __generator(this, function (_a) {
|
|
142
|
+
searchParams = {};
|
|
143
|
+
if (params === null || params === void 0 ? void 0 : params.start_date)
|
|
144
|
+
searchParams.start_date = params.start_date;
|
|
145
|
+
if (params === null || params === void 0 ? void 0 : params.end_date)
|
|
146
|
+
searchParams.end_date = params.end_date;
|
|
147
|
+
return [2 /*return*/, this.request("GET", "v1/".concat(this.chatId, "/analytics/cost-breakdown"), searchParams)];
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
AnalyticsClient.prototype.getPerformanceStats = function () {
|
|
152
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
153
|
+
return __generator(this, function (_a) {
|
|
154
|
+
return [2 /*return*/, this.request("GET", "v1/".concat(this.chatId, "/analytics/performance"))];
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
return AnalyticsClient;
|
|
159
|
+
}());
|
|
160
|
+
export { AnalyticsClient };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration client for managing RAG settings, validation policies, and chat configuration.
|
|
3
|
+
*/
|
|
4
|
+
import { ChatSettings, RagConfig, ValidationPolicy, RepairLoopConfig } from "../types";
|
|
5
|
+
export declare class ConfigClient {
|
|
6
|
+
private baseUrl;
|
|
7
|
+
private chatId;
|
|
8
|
+
private getHeaders;
|
|
9
|
+
private readonly;
|
|
10
|
+
constructor(baseUrl: string, chatId: string, getHeaders: () => HeadersInit, readonly?: boolean);
|
|
11
|
+
private request;
|
|
12
|
+
getSettings(): Promise<ChatSettings>;
|
|
13
|
+
updateSettings(updates: {
|
|
14
|
+
model?: string;
|
|
15
|
+
temperature?: number;
|
|
16
|
+
max_tokens?: number;
|
|
17
|
+
custom_prompt?: string;
|
|
18
|
+
}): Promise<ChatSettings>;
|
|
19
|
+
getRagConfig(): Promise<RagConfig>;
|
|
20
|
+
updateChunking(params: {
|
|
21
|
+
strategy?: string;
|
|
22
|
+
chunk_size?: number;
|
|
23
|
+
chunk_overlap?: number;
|
|
24
|
+
}): Promise<RagConfig>;
|
|
25
|
+
updateRetrieval(params: {
|
|
26
|
+
mode?: string;
|
|
27
|
+
top_k?: number;
|
|
28
|
+
similarity_threshold?: number;
|
|
29
|
+
vector_weight?: number;
|
|
30
|
+
keyword_weight?: number;
|
|
31
|
+
}): Promise<RagConfig>;
|
|
32
|
+
updateReranking(params: {
|
|
33
|
+
enabled: boolean;
|
|
34
|
+
model?: string;
|
|
35
|
+
top_n?: number;
|
|
36
|
+
}): Promise<RagConfig>;
|
|
37
|
+
getValidationPolicy(): Promise<ValidationPolicy>;
|
|
38
|
+
setValidationPolicy(policy: Partial<ValidationPolicy>): Promise<ValidationPolicy>;
|
|
39
|
+
generateValidationPolicy(params?: {
|
|
40
|
+
task_description?: string;
|
|
41
|
+
old_integration?: string;
|
|
42
|
+
new_integration?: string;
|
|
43
|
+
}): Promise<Record<string, any>>;
|
|
44
|
+
configureRepairLoop(enabled: boolean, maxRetries?: number): Promise<RepairLoopConfig>;
|
|
45
|
+
setMinimumReliabilityScore(score: number): Promise<boolean>;
|
|
46
|
+
enableDeploymentGating(enabled: boolean): Promise<boolean>;
|
|
47
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration client for managing RAG settings, validation policies, and chat configuration.
|
|
3
|
+
*/
|
|
4
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
5
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
6
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
7
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
8
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
9
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
10
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
14
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
15
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
16
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
17
|
+
function step(op) {
|
|
18
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
19
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
20
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
21
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
22
|
+
switch (op[0]) {
|
|
23
|
+
case 0: case 1: t = op; break;
|
|
24
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
25
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
26
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
27
|
+
default:
|
|
28
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
29
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
30
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
31
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
32
|
+
if (t[2]) _.ops.pop();
|
|
33
|
+
_.trys.pop(); continue;
|
|
34
|
+
}
|
|
35
|
+
op = body.call(thisArg, _);
|
|
36
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
37
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var ConfigClient = /** @class */ (function () {
|
|
41
|
+
function ConfigClient(baseUrl, chatId, getHeaders, readonly) {
|
|
42
|
+
if (readonly === void 0) { readonly = false; }
|
|
43
|
+
this.baseUrl = baseUrl;
|
|
44
|
+
this.chatId = chatId;
|
|
45
|
+
this.getHeaders = getHeaders;
|
|
46
|
+
this.readonly = readonly;
|
|
47
|
+
}
|
|
48
|
+
ConfigClient.prototype.request = function (method, endpoint, body) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
50
|
+
var url, response, error;
|
|
51
|
+
return __generator(this, function (_a) {
|
|
52
|
+
switch (_a.label) {
|
|
53
|
+
case 0:
|
|
54
|
+
if (this.readonly && method !== "GET") {
|
|
55
|
+
throw new Error("Configuration modifications not available in current authentication mode");
|
|
56
|
+
}
|
|
57
|
+
url = "".concat(this.baseUrl, "/").concat(endpoint);
|
|
58
|
+
return [4 /*yield*/, fetch(url, {
|
|
59
|
+
method: method,
|
|
60
|
+
headers: this.getHeaders(),
|
|
61
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
62
|
+
})];
|
|
63
|
+
case 1:
|
|
64
|
+
response = _a.sent();
|
|
65
|
+
if (!!response.ok) return [3 /*break*/, 3];
|
|
66
|
+
return [4 /*yield*/, response.json().catch(function () { return ({ detail: response.statusText }); })];
|
|
67
|
+
case 2:
|
|
68
|
+
error = _a.sent();
|
|
69
|
+
throw new Error(error.detail || "HTTP ".concat(response.status));
|
|
70
|
+
case 3: return [2 /*return*/, response.json()];
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
// Chat Settings
|
|
76
|
+
ConfigClient.prototype.getSettings = function () {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
78
|
+
return __generator(this, function (_a) {
|
|
79
|
+
return [2 /*return*/, this.request("GET", "v1/".concat(this.chatId, "/config/settings"))];
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
ConfigClient.prototype.updateSettings = function (updates) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
85
|
+
return __generator(this, function (_a) {
|
|
86
|
+
return [2 /*return*/, this.request("PUT", "v1/".concat(this.chatId, "/config/settings"), updates)];
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
// RAG Configuration
|
|
91
|
+
ConfigClient.prototype.getRagConfig = function () {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
93
|
+
return __generator(this, function (_a) {
|
|
94
|
+
return [2 /*return*/, this.request("GET", "v1/".concat(this.chatId, "/config/rag"))];
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
ConfigClient.prototype.updateChunking = function (params) {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
100
|
+
return __generator(this, function (_a) {
|
|
101
|
+
return [2 /*return*/, this.request("PUT", "v1/".concat(this.chatId, "/config/rag/chunking"), {
|
|
102
|
+
strategy: params.strategy || "auto",
|
|
103
|
+
chunk_size: params.chunk_size,
|
|
104
|
+
chunk_overlap: params.chunk_overlap,
|
|
105
|
+
})];
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
ConfigClient.prototype.updateRetrieval = function (params) {
|
|
110
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
111
|
+
return __generator(this, function (_a) {
|
|
112
|
+
return [2 /*return*/, this.request("PUT", "v1/".concat(this.chatId, "/config/rag/retrieval"), {
|
|
113
|
+
mode: params.mode || "hybrid",
|
|
114
|
+
top_k: params.top_k || 10,
|
|
115
|
+
similarity_threshold: params.similarity_threshold || 0.7,
|
|
116
|
+
vector_weight: params.vector_weight,
|
|
117
|
+
keyword_weight: params.keyword_weight,
|
|
118
|
+
})];
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
ConfigClient.prototype.updateReranking = function (params) {
|
|
123
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
124
|
+
return __generator(this, function (_a) {
|
|
125
|
+
return [2 /*return*/, this.request("PUT", "v1/".concat(this.chatId, "/config/rag/reranking"), {
|
|
126
|
+
enabled: params.enabled,
|
|
127
|
+
model: params.model || "cohere",
|
|
128
|
+
top_n: params.top_n,
|
|
129
|
+
})];
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
// Validation Policy
|
|
134
|
+
ConfigClient.prototype.getValidationPolicy = function () {
|
|
135
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
136
|
+
return __generator(this, function (_a) {
|
|
137
|
+
return [2 /*return*/, this.request("GET", "v1/".concat(this.chatId, "/config/validation-policy"))];
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
ConfigClient.prototype.setValidationPolicy = function (policy) {
|
|
142
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
143
|
+
return __generator(this, function (_a) {
|
|
144
|
+
return [2 /*return*/, this.request("PUT", "v1/".concat(this.chatId, "/config/validation-policy"), policy)];
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
ConfigClient.prototype.generateValidationPolicy = function (params) {
|
|
149
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
150
|
+
var result;
|
|
151
|
+
return __generator(this, function (_a) {
|
|
152
|
+
switch (_a.label) {
|
|
153
|
+
case 0: return [4 /*yield*/, this.request("POST", "v1/".concat(this.chatId, "/config/validation-policy/generate"), params)];
|
|
154
|
+
case 1:
|
|
155
|
+
result = _a.sent();
|
|
156
|
+
return [2 /*return*/, result.policy];
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
// Repair Loop & Deployment Gating
|
|
162
|
+
ConfigClient.prototype.configureRepairLoop = function (enabled_1) {
|
|
163
|
+
return __awaiter(this, arguments, void 0, function (enabled, maxRetries) {
|
|
164
|
+
if (maxRetries === void 0) { maxRetries = 2; }
|
|
165
|
+
return __generator(this, function (_a) {
|
|
166
|
+
return [2 /*return*/, this.request("PUT", "v1/".concat(this.chatId, "/config/repair-loop"), {
|
|
167
|
+
enabled: enabled,
|
|
168
|
+
max_retries: maxRetries,
|
|
169
|
+
})];
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
ConfigClient.prototype.setMinimumReliabilityScore = function (score) {
|
|
174
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
175
|
+
var result;
|
|
176
|
+
return __generator(this, function (_a) {
|
|
177
|
+
switch (_a.label) {
|
|
178
|
+
case 0: return [4 /*yield*/, this.request("PUT", "v1/".concat(this.chatId, "/config/deployment-gating"), { minimum_reliability_score: score })];
|
|
179
|
+
case 1:
|
|
180
|
+
result = _a.sent();
|
|
181
|
+
return [2 /*return*/, result.success];
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
};
|
|
186
|
+
ConfigClient.prototype.enableDeploymentGating = function (enabled) {
|
|
187
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
188
|
+
var result;
|
|
189
|
+
return __generator(this, function (_a) {
|
|
190
|
+
switch (_a.label) {
|
|
191
|
+
case 0: return [4 /*yield*/, this.request("PUT", "v1/".concat(this.chatId, "/config/deployment-gating"), { deployment_gating_enabled: enabled })];
|
|
192
|
+
case 1:
|
|
193
|
+
result = _a.sent();
|
|
194
|
+
return [2 /*return*/, result.success];
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
};
|
|
199
|
+
return ConfigClient;
|
|
200
|
+
}());
|
|
201
|
+
export { ConfigClient };
|