@trainly/react 1.6.3 → 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 +111 -13
- 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 +18 -1
- package/dist/api/TrainlyClient.js +291 -60
- 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 +262 -0
- package/package.json +1 -1
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fine-tuning client for managing DPO preference pairs and training jobs.
|
|
3
|
+
*/
|
|
4
|
+
import { PreferencePair, TrainingJob, PaginatedPairs, BatchResult } from "../types";
|
|
5
|
+
export declare class FineTuningClient {
|
|
6
|
+
private baseUrl;
|
|
7
|
+
private chatId;
|
|
8
|
+
private getHeaders;
|
|
9
|
+
constructor(baseUrl: string, chatId: string, getHeaders: () => HeadersInit);
|
|
10
|
+
private request;
|
|
11
|
+
createPreferencePair(params: {
|
|
12
|
+
input_messages: Array<{
|
|
13
|
+
role: string;
|
|
14
|
+
content: string;
|
|
15
|
+
}>;
|
|
16
|
+
preferred_output: string;
|
|
17
|
+
non_preferred_output: string;
|
|
18
|
+
source?: string;
|
|
19
|
+
notes?: string;
|
|
20
|
+
}): Promise<PreferencePair>;
|
|
21
|
+
batchCreatePairs(pairs: Array<{
|
|
22
|
+
input_messages: Array<{
|
|
23
|
+
role: string;
|
|
24
|
+
content: string;
|
|
25
|
+
}>;
|
|
26
|
+
preferred_output: string;
|
|
27
|
+
non_preferred_output: string;
|
|
28
|
+
source?: string;
|
|
29
|
+
notes?: string;
|
|
30
|
+
}>): Promise<BatchResult>;
|
|
31
|
+
updatePair(pairId: string, updates: {
|
|
32
|
+
preferred_output?: string;
|
|
33
|
+
non_preferred_output?: string;
|
|
34
|
+
status?: string;
|
|
35
|
+
notes?: string;
|
|
36
|
+
}): Promise<PreferencePair>;
|
|
37
|
+
deletePair(pairId: string): Promise<boolean>;
|
|
38
|
+
listPairs(params?: {
|
|
39
|
+
status?: string;
|
|
40
|
+
page?: number;
|
|
41
|
+
limit?: number;
|
|
42
|
+
}): Promise<PaginatedPairs>;
|
|
43
|
+
approvePairs(pairIds: string[]): Promise<BatchResult>;
|
|
44
|
+
rejectPairs(pairIds: string[]): Promise<BatchResult>;
|
|
45
|
+
generatePairsFromTestRun(runId: string, onlyFailed?: boolean, synthesizeGood?: boolean): Promise<PreferencePair[]>;
|
|
46
|
+
startTrainingJob(params?: {
|
|
47
|
+
base_model?: string;
|
|
48
|
+
suffix?: string;
|
|
49
|
+
beta?: number;
|
|
50
|
+
min_approved_pairs?: number;
|
|
51
|
+
}): Promise<TrainingJob>;
|
|
52
|
+
getJobStatus(jobId: string): Promise<TrainingJob>;
|
|
53
|
+
listJobs(status?: string): Promise<TrainingJob[]>;
|
|
54
|
+
cancelJob(jobId: string): Promise<boolean>;
|
|
55
|
+
waitForJob(jobId: string, timeout?: number, pollInterval?: number): Promise<TrainingJob>;
|
|
56
|
+
activateModel(modelId: string): Promise<boolean>;
|
|
57
|
+
deactivateFineTunedModel(): Promise<boolean>;
|
|
58
|
+
getActiveModel(): Promise<string | null>;
|
|
59
|
+
}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fine-tuning client for managing DPO preference pairs and training jobs.
|
|
3
|
+
*/
|
|
4
|
+
var __assign = (this && this.__assign) || function () {
|
|
5
|
+
__assign = Object.assign || function(t) {
|
|
6
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
7
|
+
s = arguments[i];
|
|
8
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
9
|
+
t[p] = s[p];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
return __assign.apply(this, arguments);
|
|
14
|
+
};
|
|
15
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
16
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
17
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
18
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
19
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
20
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
21
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
25
|
+
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);
|
|
26
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
27
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
28
|
+
function step(op) {
|
|
29
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
30
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
31
|
+
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;
|
|
32
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
33
|
+
switch (op[0]) {
|
|
34
|
+
case 0: case 1: t = op; break;
|
|
35
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
36
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
37
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
38
|
+
default:
|
|
39
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
40
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
41
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
42
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
43
|
+
if (t[2]) _.ops.pop();
|
|
44
|
+
_.trys.pop(); continue;
|
|
45
|
+
}
|
|
46
|
+
op = body.call(thisArg, _);
|
|
47
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
48
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
var FineTuningClient = /** @class */ (function () {
|
|
52
|
+
function FineTuningClient(baseUrl, chatId, getHeaders) {
|
|
53
|
+
this.baseUrl = baseUrl;
|
|
54
|
+
this.chatId = chatId;
|
|
55
|
+
this.getHeaders = getHeaders;
|
|
56
|
+
}
|
|
57
|
+
FineTuningClient.prototype.request = function (method, endpoint, body) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
59
|
+
var url, response, error;
|
|
60
|
+
return __generator(this, function (_a) {
|
|
61
|
+
switch (_a.label) {
|
|
62
|
+
case 0:
|
|
63
|
+
url = "".concat(this.baseUrl, "/").concat(endpoint);
|
|
64
|
+
return [4 /*yield*/, fetch(url, {
|
|
65
|
+
method: method,
|
|
66
|
+
headers: this.getHeaders(),
|
|
67
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
68
|
+
})];
|
|
69
|
+
case 1:
|
|
70
|
+
response = _a.sent();
|
|
71
|
+
if (!!response.ok) return [3 /*break*/, 3];
|
|
72
|
+
return [4 /*yield*/, response.json().catch(function () { return ({ detail: response.statusText }); })];
|
|
73
|
+
case 2:
|
|
74
|
+
error = _a.sent();
|
|
75
|
+
throw new Error(error.detail || "HTTP ".concat(response.status));
|
|
76
|
+
case 3: return [2 /*return*/, response.json()];
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
// Preference Pair Management
|
|
82
|
+
FineTuningClient.prototype.createPreferencePair = function (params) {
|
|
83
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
84
|
+
return __generator(this, function (_a) {
|
|
85
|
+
return [2 /*return*/, this.request("POST", "v1/".concat(this.chatId, "/fine-tuning/pairs"), __assign(__assign({}, params), { source: params.source || "manual" }))];
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
FineTuningClient.prototype.batchCreatePairs = function (pairs) {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
91
|
+
return __generator(this, function (_a) {
|
|
92
|
+
return [2 /*return*/, this.request("POST", "v1/".concat(this.chatId, "/fine-tuning/pairs/batch"), { pairs: pairs })];
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
FineTuningClient.prototype.updatePair = function (pairId, updates) {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
98
|
+
return __generator(this, function (_a) {
|
|
99
|
+
return [2 /*return*/, this.request("PUT", "v1/".concat(this.chatId, "/fine-tuning/pairs/").concat(pairId), updates)];
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
FineTuningClient.prototype.deletePair = function (pairId) {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
105
|
+
var result;
|
|
106
|
+
return __generator(this, function (_a) {
|
|
107
|
+
switch (_a.label) {
|
|
108
|
+
case 0: return [4 /*yield*/, this.request("DELETE", "v1/".concat(this.chatId, "/fine-tuning/pairs/").concat(pairId))];
|
|
109
|
+
case 1:
|
|
110
|
+
result = _a.sent();
|
|
111
|
+
return [2 /*return*/, result.success];
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
FineTuningClient.prototype.listPairs = function (params) {
|
|
117
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
118
|
+
var searchParams;
|
|
119
|
+
return __generator(this, function (_a) {
|
|
120
|
+
searchParams = new URLSearchParams(__assign({ page: ((params === null || params === void 0 ? void 0 : params.page) || 1).toString(), limit: ((params === null || params === void 0 ? void 0 : params.limit) || 50).toString() }, ((params === null || params === void 0 ? void 0 : params.status) && { status: params.status })));
|
|
121
|
+
return [2 /*return*/, this.request("GET", "v1/".concat(this.chatId, "/fine-tuning/pairs?").concat(searchParams))];
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
FineTuningClient.prototype.approvePairs = function (pairIds) {
|
|
126
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
127
|
+
return __generator(this, function (_a) {
|
|
128
|
+
return [2 /*return*/, this.request("POST", "v1/".concat(this.chatId, "/fine-tuning/pairs/bulk-approve"), {
|
|
129
|
+
pair_ids: pairIds,
|
|
130
|
+
})];
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
FineTuningClient.prototype.rejectPairs = function (pairIds) {
|
|
135
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
136
|
+
return __generator(this, function (_a) {
|
|
137
|
+
return [2 /*return*/, this.request("POST", "v1/".concat(this.chatId, "/fine-tuning/pairs/bulk-reject"), {
|
|
138
|
+
pair_ids: pairIds,
|
|
139
|
+
})];
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
// Generate Training Data from Tests
|
|
144
|
+
FineTuningClient.prototype.generatePairsFromTestRun = function (runId_1) {
|
|
145
|
+
return __awaiter(this, arguments, void 0, function (runId, onlyFailed, synthesizeGood) {
|
|
146
|
+
var result;
|
|
147
|
+
if (onlyFailed === void 0) { onlyFailed = true; }
|
|
148
|
+
if (synthesizeGood === void 0) { synthesizeGood = true; }
|
|
149
|
+
return __generator(this, function (_a) {
|
|
150
|
+
switch (_a.label) {
|
|
151
|
+
case 0: return [4 /*yield*/, this.request("POST", "v1/".concat(this.chatId, "/fine-tuning/pairs/generate-from-test-run"), { run_id: runId, only_failed: onlyFailed, synthesize_good: synthesizeGood })];
|
|
152
|
+
case 1:
|
|
153
|
+
result = _a.sent();
|
|
154
|
+
return [2 /*return*/, result.pairs];
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
// Training Job Management
|
|
160
|
+
FineTuningClient.prototype.startTrainingJob = function (params) {
|
|
161
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
162
|
+
return __generator(this, function (_a) {
|
|
163
|
+
return [2 /*return*/, this.request("POST", "v1/".concat(this.chatId, "/fine-tuning/jobs"), {
|
|
164
|
+
base_model: (params === null || params === void 0 ? void 0 : params.base_model) || "gpt-4o-mini",
|
|
165
|
+
suffix: params === null || params === void 0 ? void 0 : params.suffix,
|
|
166
|
+
beta: (params === null || params === void 0 ? void 0 : params.beta) || 0.1,
|
|
167
|
+
min_approved_pairs: (params === null || params === void 0 ? void 0 : params.min_approved_pairs) || 10,
|
|
168
|
+
})];
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
FineTuningClient.prototype.getJobStatus = function (jobId) {
|
|
173
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
174
|
+
return __generator(this, function (_a) {
|
|
175
|
+
return [2 /*return*/, this.request("GET", "v1/".concat(this.chatId, "/fine-tuning/jobs/").concat(jobId))];
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
FineTuningClient.prototype.listJobs = function (status) {
|
|
180
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
181
|
+
var params, result;
|
|
182
|
+
return __generator(this, function (_a) {
|
|
183
|
+
switch (_a.label) {
|
|
184
|
+
case 0:
|
|
185
|
+
params = status ? "?status=".concat(status) : "";
|
|
186
|
+
return [4 /*yield*/, this.request("GET", "v1/".concat(this.chatId, "/fine-tuning/jobs").concat(params))];
|
|
187
|
+
case 1:
|
|
188
|
+
result = _a.sent();
|
|
189
|
+
return [2 /*return*/, result.jobs];
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
FineTuningClient.prototype.cancelJob = function (jobId) {
|
|
195
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
196
|
+
var result;
|
|
197
|
+
return __generator(this, function (_a) {
|
|
198
|
+
switch (_a.label) {
|
|
199
|
+
case 0: return [4 /*yield*/, this.request("POST", "v1/".concat(this.chatId, "/fine-tuning/jobs/").concat(jobId, "/cancel"))];
|
|
200
|
+
case 1:
|
|
201
|
+
result = _a.sent();
|
|
202
|
+
return [2 /*return*/, result.success];
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
};
|
|
207
|
+
FineTuningClient.prototype.waitForJob = function (jobId_1) {
|
|
208
|
+
return __awaiter(this, arguments, void 0, function (jobId, timeout, pollInterval) {
|
|
209
|
+
var startTime, job;
|
|
210
|
+
if (timeout === void 0) { timeout = 3600000; }
|
|
211
|
+
if (pollInterval === void 0) { pollInterval = 30000; }
|
|
212
|
+
return __generator(this, function (_a) {
|
|
213
|
+
switch (_a.label) {
|
|
214
|
+
case 0:
|
|
215
|
+
startTime = Date.now();
|
|
216
|
+
_a.label = 1;
|
|
217
|
+
case 1:
|
|
218
|
+
if (!(Date.now() - startTime < timeout)) return [3 /*break*/, 4];
|
|
219
|
+
return [4 /*yield*/, this.getJobStatus(jobId)];
|
|
220
|
+
case 2:
|
|
221
|
+
job = _a.sent();
|
|
222
|
+
if (["succeeded", "failed", "cancelled"].includes(job.status)) {
|
|
223
|
+
if (job.status === "failed") {
|
|
224
|
+
throw new Error("Training job failed: ".concat(job.error || "Unknown error"));
|
|
225
|
+
}
|
|
226
|
+
return [2 /*return*/, job];
|
|
227
|
+
}
|
|
228
|
+
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, pollInterval); })];
|
|
229
|
+
case 3:
|
|
230
|
+
_a.sent();
|
|
231
|
+
return [3 /*break*/, 1];
|
|
232
|
+
case 4: throw new Error("Training job ".concat(jobId, " did not complete within ").concat(timeout, "ms"));
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
};
|
|
237
|
+
// Model Management
|
|
238
|
+
FineTuningClient.prototype.activateModel = function (modelId) {
|
|
239
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
240
|
+
var result;
|
|
241
|
+
return __generator(this, function (_a) {
|
|
242
|
+
switch (_a.label) {
|
|
243
|
+
case 0: return [4 /*yield*/, this.request("POST", "v1/".concat(this.chatId, "/fine-tuning/activate-model"), { model_id: modelId })];
|
|
244
|
+
case 1:
|
|
245
|
+
result = _a.sent();
|
|
246
|
+
return [2 /*return*/, result.success];
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
};
|
|
251
|
+
FineTuningClient.prototype.deactivateFineTunedModel = function () {
|
|
252
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
253
|
+
var result;
|
|
254
|
+
return __generator(this, function (_a) {
|
|
255
|
+
switch (_a.label) {
|
|
256
|
+
case 0: return [4 /*yield*/, this.request("POST", "v1/".concat(this.chatId, "/fine-tuning/deactivate-model"))];
|
|
257
|
+
case 1:
|
|
258
|
+
result = _a.sent();
|
|
259
|
+
return [2 /*return*/, result.success];
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
};
|
|
264
|
+
FineTuningClient.prototype.getActiveModel = function () {
|
|
265
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
266
|
+
var result;
|
|
267
|
+
return __generator(this, function (_a) {
|
|
268
|
+
switch (_a.label) {
|
|
269
|
+
case 0: return [4 /*yield*/, this.request("GET", "v1/".concat(this.chatId, "/fine-tuning/active-model"))];
|
|
270
|
+
case 1:
|
|
271
|
+
result = _a.sent();
|
|
272
|
+
return [2 /*return*/, result.model_id || null];
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
};
|
|
277
|
+
return FineTuningClient;
|
|
278
|
+
}());
|
|
279
|
+
export { FineTuningClient };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Testing client for managing test suites, test cases, and test execution.
|
|
3
|
+
*/
|
|
4
|
+
import { TestSuite, TestCase, TestRun, TestRunResults, TestAnalytics, PaginatedSuites, TestAssertion } from "../types";
|
|
5
|
+
export declare class TestingClient {
|
|
6
|
+
private baseUrl;
|
|
7
|
+
private chatId;
|
|
8
|
+
private getHeaders;
|
|
9
|
+
constructor(baseUrl: string, chatId: string, getHeaders: () => HeadersInit);
|
|
10
|
+
private request;
|
|
11
|
+
createSuite(name: string, description?: string, tags?: string[]): Promise<TestSuite>;
|
|
12
|
+
updateSuite(suiteId: string, updates: {
|
|
13
|
+
name?: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
tags?: string[];
|
|
16
|
+
}): Promise<TestSuite>;
|
|
17
|
+
deleteSuite(suiteId: string): Promise<boolean>;
|
|
18
|
+
listSuites(page?: number, limit?: number, status?: string): Promise<PaginatedSuites>;
|
|
19
|
+
getSuite(suiteId: string): Promise<TestSuite>;
|
|
20
|
+
createTestCase(params: {
|
|
21
|
+
suiteId?: string;
|
|
22
|
+
name: string;
|
|
23
|
+
query: string;
|
|
24
|
+
expected_answer: string;
|
|
25
|
+
category?: string;
|
|
26
|
+
expected_decision?: string;
|
|
27
|
+
assertions?: TestAssertion[];
|
|
28
|
+
expected_source_file?: string;
|
|
29
|
+
}): Promise<TestCase>;
|
|
30
|
+
generateTestCases(countPerCategory?: number, scopeFilters?: Record<string, any>): Promise<TestCase[]>;
|
|
31
|
+
updateTestCase(caseId: string, updates: {
|
|
32
|
+
name?: string;
|
|
33
|
+
query?: string;
|
|
34
|
+
expected_answer?: string;
|
|
35
|
+
category?: string;
|
|
36
|
+
suite_id?: string;
|
|
37
|
+
}): Promise<TestCase>;
|
|
38
|
+
deleteTestCase(caseId: string): Promise<boolean>;
|
|
39
|
+
listTestCases(params?: {
|
|
40
|
+
suiteId?: string;
|
|
41
|
+
category?: string;
|
|
42
|
+
page?: number;
|
|
43
|
+
limit?: number;
|
|
44
|
+
}): Promise<TestCase[]>;
|
|
45
|
+
runSuite(suiteId: string, parallel?: boolean, stopOnFailure?: boolean): Promise<TestRun>;
|
|
46
|
+
getRunResults(runId: string): Promise<TestRunResults>;
|
|
47
|
+
getRunHistory(suiteId: string, limit?: number): Promise<TestRun[]>;
|
|
48
|
+
cancelRun(runId: string): Promise<boolean>;
|
|
49
|
+
waitForRun(runId: string, timeout?: number, pollInterval?: number): Promise<TestRunResults>;
|
|
50
|
+
getSuiteAnalytics(suiteId: string): Promise<TestAnalytics>;
|
|
51
|
+
}
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Testing client for managing test suites, test cases, and test execution.
|
|
3
|
+
*/
|
|
4
|
+
var __assign = (this && this.__assign) || function () {
|
|
5
|
+
__assign = Object.assign || function(t) {
|
|
6
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
7
|
+
s = arguments[i];
|
|
8
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
9
|
+
t[p] = s[p];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
return __assign.apply(this, arguments);
|
|
14
|
+
};
|
|
15
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
16
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
17
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
18
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
19
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
20
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
21
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
25
|
+
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);
|
|
26
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
27
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
28
|
+
function step(op) {
|
|
29
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
30
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
31
|
+
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;
|
|
32
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
33
|
+
switch (op[0]) {
|
|
34
|
+
case 0: case 1: t = op; break;
|
|
35
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
36
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
37
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
38
|
+
default:
|
|
39
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
40
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
41
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
42
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
43
|
+
if (t[2]) _.ops.pop();
|
|
44
|
+
_.trys.pop(); continue;
|
|
45
|
+
}
|
|
46
|
+
op = body.call(thisArg, _);
|
|
47
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
48
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
var TestingClient = /** @class */ (function () {
|
|
52
|
+
function TestingClient(baseUrl, chatId, getHeaders) {
|
|
53
|
+
this.baseUrl = baseUrl;
|
|
54
|
+
this.chatId = chatId;
|
|
55
|
+
this.getHeaders = getHeaders;
|
|
56
|
+
}
|
|
57
|
+
TestingClient.prototype.request = function (method, endpoint, body) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
59
|
+
var url, response, error;
|
|
60
|
+
return __generator(this, function (_a) {
|
|
61
|
+
switch (_a.label) {
|
|
62
|
+
case 0:
|
|
63
|
+
url = "".concat(this.baseUrl, "/").concat(endpoint);
|
|
64
|
+
return [4 /*yield*/, fetch(url, {
|
|
65
|
+
method: method,
|
|
66
|
+
headers: this.getHeaders(),
|
|
67
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
68
|
+
})];
|
|
69
|
+
case 1:
|
|
70
|
+
response = _a.sent();
|
|
71
|
+
if (!!response.ok) return [3 /*break*/, 3];
|
|
72
|
+
return [4 /*yield*/, response.json().catch(function () { return ({ detail: response.statusText }); })];
|
|
73
|
+
case 2:
|
|
74
|
+
error = _a.sent();
|
|
75
|
+
throw new Error(error.detail || "HTTP ".concat(response.status));
|
|
76
|
+
case 3: return [2 /*return*/, response.json()];
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
// Suite Management
|
|
82
|
+
TestingClient.prototype.createSuite = function (name, description, tags) {
|
|
83
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
84
|
+
return __generator(this, function (_a) {
|
|
85
|
+
return [2 /*return*/, this.request("POST", "v1/".concat(this.chatId, "/testing/suites"), {
|
|
86
|
+
name: name,
|
|
87
|
+
description: description,
|
|
88
|
+
tags: tags,
|
|
89
|
+
})];
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
TestingClient.prototype.updateSuite = function (suiteId, updates) {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
95
|
+
return __generator(this, function (_a) {
|
|
96
|
+
return [2 /*return*/, this.request("PUT", "v1/".concat(this.chatId, "/testing/suites/").concat(suiteId), updates)];
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
TestingClient.prototype.deleteSuite = function (suiteId) {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
102
|
+
var result;
|
|
103
|
+
return __generator(this, function (_a) {
|
|
104
|
+
switch (_a.label) {
|
|
105
|
+
case 0: return [4 /*yield*/, this.request("DELETE", "v1/".concat(this.chatId, "/testing/suites/").concat(suiteId))];
|
|
106
|
+
case 1:
|
|
107
|
+
result = _a.sent();
|
|
108
|
+
return [2 /*return*/, result.success];
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
TestingClient.prototype.listSuites = function () {
|
|
114
|
+
return __awaiter(this, arguments, void 0, function (page, limit, status) {
|
|
115
|
+
var params;
|
|
116
|
+
if (page === void 0) { page = 1; }
|
|
117
|
+
if (limit === void 0) { limit = 20; }
|
|
118
|
+
return __generator(this, function (_a) {
|
|
119
|
+
params = new URLSearchParams(__assign({ page: page.toString(), limit: limit.toString() }, (status && { status: status })));
|
|
120
|
+
return [2 /*return*/, this.request("GET", "v1/".concat(this.chatId, "/testing/suites?").concat(params))];
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
TestingClient.prototype.getSuite = function (suiteId) {
|
|
125
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
126
|
+
return __generator(this, function (_a) {
|
|
127
|
+
return [2 /*return*/, this.request("GET", "v1/".concat(this.chatId, "/testing/suites/").concat(suiteId))];
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
// Test Case Management
|
|
132
|
+
TestingClient.prototype.createTestCase = function (params) {
|
|
133
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
134
|
+
return __generator(this, function (_a) {
|
|
135
|
+
return [2 /*return*/, this.request("POST", "v1/".concat(this.chatId, "/testing/cases"), params)];
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
TestingClient.prototype.generateTestCases = function () {
|
|
140
|
+
return __awaiter(this, arguments, void 0, function (countPerCategory, scopeFilters) {
|
|
141
|
+
var result;
|
|
142
|
+
if (countPerCategory === void 0) { countPerCategory = 3; }
|
|
143
|
+
return __generator(this, function (_a) {
|
|
144
|
+
switch (_a.label) {
|
|
145
|
+
case 0: return [4 /*yield*/, this.request("POST", "v1/".concat(this.chatId, "/testing/cases/generate"), { count_per_category: countPerCategory, scope_filters: scopeFilters })];
|
|
146
|
+
case 1:
|
|
147
|
+
result = _a.sent();
|
|
148
|
+
return [2 /*return*/, result.cases];
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
TestingClient.prototype.updateTestCase = function (caseId, updates) {
|
|
154
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
155
|
+
return __generator(this, function (_a) {
|
|
156
|
+
return [2 /*return*/, this.request("PUT", "v1/".concat(this.chatId, "/testing/cases/").concat(caseId), updates)];
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
TestingClient.prototype.deleteTestCase = function (caseId) {
|
|
161
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
162
|
+
var result;
|
|
163
|
+
return __generator(this, function (_a) {
|
|
164
|
+
switch (_a.label) {
|
|
165
|
+
case 0: return [4 /*yield*/, this.request("DELETE", "v1/".concat(this.chatId, "/testing/cases/").concat(caseId))];
|
|
166
|
+
case 1:
|
|
167
|
+
result = _a.sent();
|
|
168
|
+
return [2 /*return*/, result.success];
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
TestingClient.prototype.listTestCases = function (params) {
|
|
174
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
175
|
+
var searchParams, result;
|
|
176
|
+
return __generator(this, function (_a) {
|
|
177
|
+
switch (_a.label) {
|
|
178
|
+
case 0:
|
|
179
|
+
searchParams = new URLSearchParams(__assign(__assign({ page: ((params === null || params === void 0 ? void 0 : params.page) || 1).toString(), limit: ((params === null || params === void 0 ? void 0 : params.limit) || 50).toString() }, ((params === null || params === void 0 ? void 0 : params.suiteId) && { suite_id: params.suiteId })), ((params === null || params === void 0 ? void 0 : params.category) && { category: params.category })));
|
|
180
|
+
return [4 /*yield*/, this.request("GET", "v1/".concat(this.chatId, "/testing/cases?").concat(searchParams))];
|
|
181
|
+
case 1:
|
|
182
|
+
result = _a.sent();
|
|
183
|
+
return [2 /*return*/, result.cases];
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
};
|
|
188
|
+
// Test Execution
|
|
189
|
+
TestingClient.prototype.runSuite = function (suiteId_1) {
|
|
190
|
+
return __awaiter(this, arguments, void 0, function (suiteId, parallel, stopOnFailure) {
|
|
191
|
+
if (parallel === void 0) { parallel = true; }
|
|
192
|
+
if (stopOnFailure === void 0) { stopOnFailure = false; }
|
|
193
|
+
return __generator(this, function (_a) {
|
|
194
|
+
return [2 /*return*/, this.request("POST", "v1/".concat(this.chatId, "/testing/suites/").concat(suiteId, "/run"), {
|
|
195
|
+
parallel: parallel,
|
|
196
|
+
stop_on_failure: stopOnFailure,
|
|
197
|
+
})];
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
};
|
|
201
|
+
TestingClient.prototype.getRunResults = function (runId) {
|
|
202
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
203
|
+
return __generator(this, function (_a) {
|
|
204
|
+
return [2 /*return*/, this.request("GET", "v1/".concat(this.chatId, "/testing/runs/").concat(runId, "/results"))];
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
};
|
|
208
|
+
TestingClient.prototype.getRunHistory = function (suiteId_1) {
|
|
209
|
+
return __awaiter(this, arguments, void 0, function (suiteId, limit) {
|
|
210
|
+
var params, result;
|
|
211
|
+
if (limit === void 0) { limit = 10; }
|
|
212
|
+
return __generator(this, function (_a) {
|
|
213
|
+
switch (_a.label) {
|
|
214
|
+
case 0:
|
|
215
|
+
params = new URLSearchParams({ limit: limit.toString() });
|
|
216
|
+
return [4 /*yield*/, this.request("GET", "v1/".concat(this.chatId, "/testing/suites/").concat(suiteId, "/runs?").concat(params))];
|
|
217
|
+
case 1:
|
|
218
|
+
result = _a.sent();
|
|
219
|
+
return [2 /*return*/, result.runs];
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
};
|
|
224
|
+
TestingClient.prototype.cancelRun = function (runId) {
|
|
225
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
226
|
+
var result;
|
|
227
|
+
return __generator(this, function (_a) {
|
|
228
|
+
switch (_a.label) {
|
|
229
|
+
case 0: return [4 /*yield*/, this.request("POST", "v1/".concat(this.chatId, "/testing/runs/").concat(runId, "/cancel"))];
|
|
230
|
+
case 1:
|
|
231
|
+
result = _a.sent();
|
|
232
|
+
return [2 /*return*/, result.success];
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
};
|
|
237
|
+
TestingClient.prototype.waitForRun = function (runId_1) {
|
|
238
|
+
return __awaiter(this, arguments, void 0, function (runId, timeout, pollInterval) {
|
|
239
|
+
var startTime, results;
|
|
240
|
+
if (timeout === void 0) { timeout = 300000; }
|
|
241
|
+
if (pollInterval === void 0) { pollInterval = 5000; }
|
|
242
|
+
return __generator(this, function (_a) {
|
|
243
|
+
switch (_a.label) {
|
|
244
|
+
case 0:
|
|
245
|
+
startTime = Date.now();
|
|
246
|
+
_a.label = 1;
|
|
247
|
+
case 1:
|
|
248
|
+
if (!(Date.now() - startTime < timeout)) return [3 /*break*/, 4];
|
|
249
|
+
return [4 /*yield*/, this.getRunResults(runId)];
|
|
250
|
+
case 2:
|
|
251
|
+
results = _a.sent();
|
|
252
|
+
if (["completed", "failed", "cancelled"].includes(results.status)) {
|
|
253
|
+
return [2 /*return*/, results];
|
|
254
|
+
}
|
|
255
|
+
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, pollInterval); })];
|
|
256
|
+
case 3:
|
|
257
|
+
_a.sent();
|
|
258
|
+
return [3 /*break*/, 1];
|
|
259
|
+
case 4: throw new Error("Test run ".concat(runId, " did not complete within ").concat(timeout, "ms"));
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
};
|
|
264
|
+
// Analytics
|
|
265
|
+
TestingClient.prototype.getSuiteAnalytics = function (suiteId) {
|
|
266
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
267
|
+
return __generator(this, function (_a) {
|
|
268
|
+
return [2 /*return*/, this.request("GET", "v1/".concat(this.chatId, "/testing/suites/").concat(suiteId, "/analytics"))];
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
};
|
|
272
|
+
return TestingClient;
|
|
273
|
+
}());
|
|
274
|
+
export { TestingClient };
|