@inkeep/agents-sdk 0.41.2 → 0.43.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.
Files changed (43) hide show
  1. package/README.md +356 -2
  2. package/dist/agent.d.ts +84 -73
  3. package/dist/agent.js +42 -4
  4. package/dist/agentFullClient.d.ts +8 -8
  5. package/dist/agentFullClient.js +4 -4
  6. package/dist/artifact-component.d.ts +8 -8
  7. package/dist/artifact-component.js +2 -2
  8. package/dist/builderFunctions.d.ts +337 -248
  9. package/dist/builderFunctions.js +131 -2
  10. package/dist/builderFunctionsExperimental.d.ts +17 -17
  11. package/dist/builders.d.ts +48 -48
  12. package/dist/credential-provider.d.ts +93 -93
  13. package/dist/credential-provider.js +1 -1
  14. package/dist/credential-ref.d.ts +37 -37
  15. package/dist/data-component.d.ts +9 -9
  16. package/dist/data-component.js +2 -2
  17. package/dist/environment-settings.d.ts +4 -4
  18. package/dist/evaluationClient.d.ts +78 -0
  19. package/dist/evaluationClient.js +1202 -0
  20. package/dist/external-agent.d.ts +17 -17
  21. package/dist/external-agent.js +2 -2
  22. package/dist/index.d.ts +5 -3
  23. package/dist/index.js +4 -2
  24. package/dist/module-hosted-tool-manager.d.ts +1 -1
  25. package/dist/module-hosted-tool-manager.js +1 -1
  26. package/dist/project.d.ts +83 -83
  27. package/dist/project.js +23 -4
  28. package/dist/projectFullClient.d.ts +8 -8
  29. package/dist/projectFullClient.js +4 -4
  30. package/dist/runner.d.ts +15 -15
  31. package/dist/status-component.d.ts +3 -3
  32. package/dist/subAgent.d.ts +2 -2
  33. package/dist/subAgent.js +7 -7
  34. package/dist/telemetry-provider.d.ts +76 -76
  35. package/dist/tool.d.ts +16 -16
  36. package/dist/tool.js +23 -3
  37. package/dist/trigger.d.ts +46 -0
  38. package/dist/trigger.js +65 -0
  39. package/dist/types.d.ts +31 -22
  40. package/dist/utils/generateIdFromName.d.ts +4 -4
  41. package/dist/utils/tool-normalization.d.ts +10 -10
  42. package/dist/utils/validateFunction.d.ts +5 -5
  43. package/package.json +2 -2
@@ -0,0 +1,1202 @@
1
+ import { apiFetch, getLogger } from "@inkeep/agents-core";
2
+
3
+ //#region src/evaluationClient.ts
4
+ /**
5
+ * Client-side class for interacting with the Evaluations API
6
+ * These methods make HTTP requests to the server instead of direct database calls
7
+ */
8
+ const logger = getLogger("evaluationClient");
9
+ function parseError(errorText) {
10
+ try {
11
+ const errorJson = JSON.parse(errorText);
12
+ if (errorJson.error) {
13
+ const { error } = errorJson;
14
+ return error?.message ?? error;
15
+ }
16
+ } catch {
17
+ if (errorText) return errorText;
18
+ }
19
+ }
20
+ var EvaluationClient = class {
21
+ tenantId;
22
+ projectId;
23
+ apiUrl;
24
+ apiKey;
25
+ constructor(config) {
26
+ this.tenantId = config.tenantId;
27
+ this.projectId = config.projectId;
28
+ this.apiUrl = config.apiUrl;
29
+ this.apiKey = config.apiKey;
30
+ }
31
+ buildUrl(...pathSegments) {
32
+ return `${this.apiUrl}/manage/tenants/${this.tenantId}/projects/${this.projectId}/evals/${pathSegments.join("/")}`;
33
+ }
34
+ buildHeaders() {
35
+ const headers = { "Content-Type": "application/json" };
36
+ if (this.apiKey) headers.Authorization = `Bearer ${this.apiKey}`;
37
+ return headers;
38
+ }
39
+ async listDatasets() {
40
+ logger.info({
41
+ tenantId: this.tenantId,
42
+ projectId: this.projectId
43
+ }, "Listing datasets via API");
44
+ const url = this.buildUrl("datasets");
45
+ try {
46
+ const response = await apiFetch(url, {
47
+ method: "GET",
48
+ headers: this.buildHeaders()
49
+ });
50
+ if (!response.ok) {
51
+ const errorMessage = parseError(await response.text()) ?? `Failed to list datasets: ${response.status} ${response.statusText}`;
52
+ logger.error({
53
+ status: response.status,
54
+ error: errorMessage
55
+ }, "Failed to list datasets via API");
56
+ throw new Error(errorMessage);
57
+ }
58
+ return (await response.json()).data;
59
+ } catch (error) {
60
+ logger.error({
61
+ error,
62
+ tenantId: this.tenantId,
63
+ projectId: this.projectId
64
+ }, "Failed to list datasets");
65
+ throw error;
66
+ }
67
+ }
68
+ async getDataset(datasetId) {
69
+ logger.info({
70
+ tenantId: this.tenantId,
71
+ projectId: this.projectId,
72
+ datasetId
73
+ }, "Getting dataset via API");
74
+ const url = this.buildUrl("datasets", datasetId);
75
+ try {
76
+ const response = await apiFetch(url, {
77
+ method: "GET",
78
+ headers: this.buildHeaders()
79
+ });
80
+ if (!response.ok) {
81
+ if (response.status === 404) {
82
+ logger.info({ datasetId }, "Dataset not found");
83
+ return null;
84
+ }
85
+ const errorMessage = parseError(await response.text()) ?? `Failed to get dataset: ${response.status} ${response.statusText}`;
86
+ logger.error({
87
+ status: response.status,
88
+ error: errorMessage
89
+ }, "Failed to get dataset via API");
90
+ throw new Error(errorMessage);
91
+ }
92
+ return (await response.json()).data;
93
+ } catch (error) {
94
+ logger.error({
95
+ error,
96
+ tenantId: this.tenantId,
97
+ projectId: this.projectId,
98
+ datasetId
99
+ }, "Failed to get dataset");
100
+ throw error;
101
+ }
102
+ }
103
+ async createDataset(datasetData) {
104
+ logger.info({
105
+ tenantId: this.tenantId,
106
+ projectId: this.projectId
107
+ }, "Creating dataset via API");
108
+ const url = this.buildUrl("datasets");
109
+ try {
110
+ const response = await apiFetch(url, {
111
+ method: "POST",
112
+ headers: this.buildHeaders(),
113
+ body: JSON.stringify(datasetData)
114
+ });
115
+ if (!response.ok) {
116
+ const errorMessage = parseError(await response.text()) ?? `Failed to create dataset: ${response.status} ${response.statusText}`;
117
+ logger.error({
118
+ status: response.status,
119
+ error: errorMessage
120
+ }, "Failed to create dataset via API");
121
+ throw new Error(errorMessage);
122
+ }
123
+ const result = await response.json();
124
+ logger.info({
125
+ tenantId: this.tenantId,
126
+ projectId: this.projectId
127
+ }, "Successfully created dataset via API");
128
+ return result.data;
129
+ } catch (error) {
130
+ logger.error({
131
+ error,
132
+ tenantId: this.tenantId,
133
+ projectId: this.projectId
134
+ }, "Failed to create dataset");
135
+ throw error;
136
+ }
137
+ }
138
+ async updateDataset(datasetId, updateData) {
139
+ logger.info({
140
+ tenantId: this.tenantId,
141
+ projectId: this.projectId,
142
+ datasetId
143
+ }, "Updating dataset via API");
144
+ const url = this.buildUrl("datasets", datasetId);
145
+ try {
146
+ const response = await apiFetch(url, {
147
+ method: "PATCH",
148
+ headers: this.buildHeaders(),
149
+ body: JSON.stringify(updateData)
150
+ });
151
+ if (!response.ok) {
152
+ const errorMessage = parseError(await response.text()) ?? `Failed to update dataset: ${response.status} ${response.statusText}`;
153
+ logger.error({
154
+ status: response.status,
155
+ error: errorMessage
156
+ }, "Failed to update dataset via API");
157
+ throw new Error(errorMessage);
158
+ }
159
+ const result = await response.json();
160
+ logger.info({
161
+ tenantId: this.tenantId,
162
+ projectId: this.projectId,
163
+ datasetId
164
+ }, "Successfully updated dataset via API");
165
+ return result.data;
166
+ } catch (error) {
167
+ logger.error({
168
+ error,
169
+ tenantId: this.tenantId,
170
+ projectId: this.projectId,
171
+ datasetId
172
+ }, "Failed to update dataset");
173
+ throw error;
174
+ }
175
+ }
176
+ async deleteDataset(datasetId) {
177
+ logger.info({
178
+ tenantId: this.tenantId,
179
+ projectId: this.projectId,
180
+ datasetId
181
+ }, "Deleting dataset via API");
182
+ const url = this.buildUrl("datasets", datasetId);
183
+ try {
184
+ const response = await apiFetch(url, {
185
+ method: "DELETE",
186
+ headers: this.buildHeaders()
187
+ });
188
+ if (!response.ok) {
189
+ const errorMessage = parseError(await response.text()) ?? `Failed to delete dataset: ${response.status} ${response.statusText}`;
190
+ logger.error({
191
+ status: response.status,
192
+ error: errorMessage
193
+ }, "Failed to delete dataset via API");
194
+ throw new Error(errorMessage);
195
+ }
196
+ logger.info({
197
+ tenantId: this.tenantId,
198
+ projectId: this.projectId,
199
+ datasetId
200
+ }, "Successfully deleted dataset via API");
201
+ } catch (error) {
202
+ logger.error({
203
+ error,
204
+ tenantId: this.tenantId,
205
+ projectId: this.projectId,
206
+ datasetId
207
+ }, "Failed to delete dataset");
208
+ throw error;
209
+ }
210
+ }
211
+ async listDatasetItems(datasetId) {
212
+ logger.info({
213
+ tenantId: this.tenantId,
214
+ projectId: this.projectId,
215
+ datasetId
216
+ }, "Listing dataset items via API");
217
+ const url = this.buildUrl("dataset-items", datasetId);
218
+ try {
219
+ const response = await apiFetch(url, {
220
+ method: "GET",
221
+ headers: this.buildHeaders()
222
+ });
223
+ if (!response.ok) {
224
+ const errorMessage = parseError(await response.text()) ?? `Failed to list dataset items: ${response.status} ${response.statusText}`;
225
+ logger.error({
226
+ status: response.status,
227
+ error: errorMessage
228
+ }, "Failed to list dataset items via API");
229
+ throw new Error(errorMessage);
230
+ }
231
+ return (await response.json()).data;
232
+ } catch (error) {
233
+ logger.error({
234
+ error,
235
+ tenantId: this.tenantId,
236
+ projectId: this.projectId,
237
+ datasetId
238
+ }, "Failed to list dataset items");
239
+ throw error;
240
+ }
241
+ }
242
+ async getDatasetItem(datasetId, itemId) {
243
+ logger.info({
244
+ tenantId: this.tenantId,
245
+ projectId: this.projectId,
246
+ datasetId,
247
+ itemId
248
+ }, "Getting dataset item via API");
249
+ const url = this.buildUrl("dataset-items", datasetId, "items", itemId);
250
+ try {
251
+ const response = await apiFetch(url, {
252
+ method: "GET",
253
+ headers: this.buildHeaders()
254
+ });
255
+ if (!response.ok) {
256
+ if (response.status === 404) {
257
+ logger.info({ itemId }, "Dataset item not found");
258
+ return null;
259
+ }
260
+ const errorMessage = parseError(await response.text()) ?? `Failed to get dataset item: ${response.status} ${response.statusText}`;
261
+ logger.error({
262
+ status: response.status,
263
+ error: errorMessage
264
+ }, "Failed to get dataset item via API");
265
+ throw new Error(errorMessage);
266
+ }
267
+ return (await response.json()).data;
268
+ } catch (error) {
269
+ logger.error({
270
+ error,
271
+ tenantId: this.tenantId,
272
+ projectId: this.projectId,
273
+ datasetId,
274
+ itemId
275
+ }, "Failed to get dataset item");
276
+ throw error;
277
+ }
278
+ }
279
+ async createDatasetItem(datasetId, itemData) {
280
+ logger.info({
281
+ tenantId: this.tenantId,
282
+ projectId: this.projectId,
283
+ datasetId
284
+ }, "Creating dataset item via API");
285
+ const url = this.buildUrl("dataset-items", datasetId, "items");
286
+ try {
287
+ const response = await apiFetch(url, {
288
+ method: "POST",
289
+ headers: this.buildHeaders(),
290
+ body: JSON.stringify(itemData)
291
+ });
292
+ if (!response.ok) {
293
+ const errorMessage = parseError(await response.text()) ?? `Failed to create dataset item: ${response.status} ${response.statusText}`;
294
+ logger.error({
295
+ status: response.status,
296
+ error: errorMessage
297
+ }, "Failed to create dataset item via API");
298
+ throw new Error(errorMessage);
299
+ }
300
+ const result = await response.json();
301
+ logger.info({
302
+ tenantId: this.tenantId,
303
+ projectId: this.projectId,
304
+ datasetId
305
+ }, "Successfully created dataset item via API");
306
+ return result.data;
307
+ } catch (error) {
308
+ logger.error({
309
+ error,
310
+ tenantId: this.tenantId,
311
+ projectId: this.projectId,
312
+ datasetId
313
+ }, "Failed to create dataset item");
314
+ throw error;
315
+ }
316
+ }
317
+ async createDatasetItems(datasetId, itemsData) {
318
+ logger.info({
319
+ tenantId: this.tenantId,
320
+ projectId: this.projectId,
321
+ datasetId,
322
+ count: itemsData.length
323
+ }, "Creating dataset items via API");
324
+ const url = this.buildUrl("dataset-items", datasetId, "items", "bulk");
325
+ try {
326
+ const response = await apiFetch(url, {
327
+ method: "POST",
328
+ headers: this.buildHeaders(),
329
+ body: JSON.stringify(itemsData)
330
+ });
331
+ if (!response.ok) {
332
+ const errorMessage = parseError(await response.text()) ?? `Failed to create dataset items: ${response.status} ${response.statusText}`;
333
+ logger.error({
334
+ status: response.status,
335
+ error: errorMessage
336
+ }, "Failed to create dataset items via API");
337
+ throw new Error(errorMessage);
338
+ }
339
+ const result = await response.json();
340
+ logger.info({
341
+ tenantId: this.tenantId,
342
+ projectId: this.projectId,
343
+ datasetId,
344
+ count: result.data.length
345
+ }, "Successfully created dataset items via API");
346
+ return result.data;
347
+ } catch (error) {
348
+ logger.error({
349
+ error,
350
+ tenantId: this.tenantId,
351
+ projectId: this.projectId,
352
+ datasetId
353
+ }, "Failed to create dataset items");
354
+ throw error;
355
+ }
356
+ }
357
+ async updateDatasetItem(datasetId, itemId, updateData) {
358
+ logger.info({
359
+ tenantId: this.tenantId,
360
+ projectId: this.projectId,
361
+ datasetId,
362
+ itemId
363
+ }, "Updating dataset item via API");
364
+ const url = this.buildUrl("dataset-items", datasetId, "items", itemId);
365
+ try {
366
+ const response = await apiFetch(url, {
367
+ method: "PATCH",
368
+ headers: this.buildHeaders(),
369
+ body: JSON.stringify(updateData)
370
+ });
371
+ if (!response.ok) {
372
+ const errorMessage = parseError(await response.text()) ?? `Failed to update dataset item: ${response.status} ${response.statusText}`;
373
+ logger.error({
374
+ status: response.status,
375
+ error: errorMessage
376
+ }, "Failed to update dataset item via API");
377
+ throw new Error(errorMessage);
378
+ }
379
+ const result = await response.json();
380
+ logger.info({
381
+ tenantId: this.tenantId,
382
+ projectId: this.projectId,
383
+ datasetId,
384
+ itemId
385
+ }, "Successfully updated dataset item via API");
386
+ return result.data;
387
+ } catch (error) {
388
+ logger.error({
389
+ error,
390
+ tenantId: this.tenantId,
391
+ projectId: this.projectId,
392
+ datasetId,
393
+ itemId
394
+ }, "Failed to update dataset item");
395
+ throw error;
396
+ }
397
+ }
398
+ async deleteDatasetItem(datasetId, itemId) {
399
+ logger.info({
400
+ tenantId: this.tenantId,
401
+ projectId: this.projectId,
402
+ datasetId,
403
+ itemId
404
+ }, "Deleting dataset item via API");
405
+ const url = this.buildUrl("dataset-items", datasetId, "items", itemId);
406
+ try {
407
+ const response = await apiFetch(url, {
408
+ method: "DELETE",
409
+ headers: this.buildHeaders()
410
+ });
411
+ if (!response.ok) {
412
+ const errorMessage = parseError(await response.text()) ?? `Failed to delete dataset item: ${response.status} ${response.statusText}`;
413
+ logger.error({
414
+ status: response.status,
415
+ error: errorMessage
416
+ }, "Failed to delete dataset item via API");
417
+ throw new Error(errorMessage);
418
+ }
419
+ logger.info({
420
+ tenantId: this.tenantId,
421
+ projectId: this.projectId,
422
+ datasetId,
423
+ itemId
424
+ }, "Successfully deleted dataset item via API");
425
+ } catch (error) {
426
+ logger.error({
427
+ error,
428
+ tenantId: this.tenantId,
429
+ projectId: this.projectId,
430
+ datasetId,
431
+ itemId
432
+ }, "Failed to delete dataset item");
433
+ throw error;
434
+ }
435
+ }
436
+ async listEvaluators() {
437
+ logger.info({
438
+ tenantId: this.tenantId,
439
+ projectId: this.projectId
440
+ }, "Listing evaluators via API");
441
+ const url = this.buildUrl("evaluators");
442
+ try {
443
+ const response = await apiFetch(url, {
444
+ method: "GET",
445
+ headers: this.buildHeaders()
446
+ });
447
+ if (!response.ok) {
448
+ const errorMessage = parseError(await response.text()) ?? `Failed to list evaluators: ${response.status} ${response.statusText}`;
449
+ logger.error({
450
+ status: response.status,
451
+ error: errorMessage
452
+ }, "Failed to list evaluators via API");
453
+ throw new Error(errorMessage);
454
+ }
455
+ return (await response.json()).data;
456
+ } catch (error) {
457
+ logger.error({
458
+ error,
459
+ tenantId: this.tenantId,
460
+ projectId: this.projectId
461
+ }, "Failed to list evaluators");
462
+ throw error;
463
+ }
464
+ }
465
+ async getEvaluator(evaluatorId) {
466
+ logger.info({
467
+ tenantId: this.tenantId,
468
+ projectId: this.projectId,
469
+ evaluatorId
470
+ }, "Getting evaluator via API");
471
+ const url = this.buildUrl("evaluators", evaluatorId);
472
+ try {
473
+ const response = await apiFetch(url, {
474
+ method: "GET",
475
+ headers: this.buildHeaders()
476
+ });
477
+ if (!response.ok) {
478
+ if (response.status === 404) {
479
+ logger.info({ evaluatorId }, "Evaluator not found");
480
+ return null;
481
+ }
482
+ const errorMessage = parseError(await response.text()) ?? `Failed to get evaluator: ${response.status} ${response.statusText}`;
483
+ logger.error({
484
+ status: response.status,
485
+ error: errorMessage
486
+ }, "Failed to get evaluator via API");
487
+ throw new Error(errorMessage);
488
+ }
489
+ return (await response.json()).data;
490
+ } catch (error) {
491
+ logger.error({
492
+ error,
493
+ tenantId: this.tenantId,
494
+ projectId: this.projectId,
495
+ evaluatorId
496
+ }, "Failed to get evaluator");
497
+ throw error;
498
+ }
499
+ }
500
+ async createEvaluator(evaluatorData) {
501
+ logger.info({
502
+ tenantId: this.tenantId,
503
+ projectId: this.projectId
504
+ }, "Creating evaluator via API");
505
+ const url = this.buildUrl("evaluators");
506
+ try {
507
+ const response = await apiFetch(url, {
508
+ method: "POST",
509
+ headers: this.buildHeaders(),
510
+ body: JSON.stringify(evaluatorData)
511
+ });
512
+ if (!response.ok) {
513
+ const errorMessage = parseError(await response.text()) ?? `Failed to create evaluator: ${response.status} ${response.statusText}`;
514
+ logger.error({
515
+ status: response.status,
516
+ error: errorMessage
517
+ }, "Failed to create evaluator via API");
518
+ throw new Error(errorMessage);
519
+ }
520
+ const result = await response.json();
521
+ logger.info({
522
+ tenantId: this.tenantId,
523
+ projectId: this.projectId
524
+ }, "Successfully created evaluator via API");
525
+ return result.data;
526
+ } catch (error) {
527
+ logger.error({
528
+ error,
529
+ tenantId: this.tenantId,
530
+ projectId: this.projectId
531
+ }, "Failed to create evaluator");
532
+ throw error;
533
+ }
534
+ }
535
+ async updateEvaluator(evaluatorId, updateData) {
536
+ logger.info({
537
+ tenantId: this.tenantId,
538
+ projectId: this.projectId,
539
+ evaluatorId
540
+ }, "Updating evaluator via API");
541
+ const url = this.buildUrl("evaluators", evaluatorId);
542
+ try {
543
+ const response = await apiFetch(url, {
544
+ method: "PATCH",
545
+ headers: this.buildHeaders(),
546
+ body: JSON.stringify(updateData)
547
+ });
548
+ if (!response.ok) {
549
+ const errorMessage = parseError(await response.text()) ?? `Failed to update evaluator: ${response.status} ${response.statusText}`;
550
+ logger.error({
551
+ status: response.status,
552
+ error: errorMessage
553
+ }, "Failed to update evaluator via API");
554
+ throw new Error(errorMessage);
555
+ }
556
+ const result = await response.json();
557
+ logger.info({
558
+ tenantId: this.tenantId,
559
+ projectId: this.projectId,
560
+ evaluatorId
561
+ }, "Successfully updated evaluator via API");
562
+ return result.data;
563
+ } catch (error) {
564
+ logger.error({
565
+ error,
566
+ tenantId: this.tenantId,
567
+ projectId: this.projectId,
568
+ evaluatorId
569
+ }, "Failed to update evaluator");
570
+ throw error;
571
+ }
572
+ }
573
+ async deleteEvaluator(evaluatorId) {
574
+ logger.info({
575
+ tenantId: this.tenantId,
576
+ projectId: this.projectId,
577
+ evaluatorId
578
+ }, "Deleting evaluator via API");
579
+ const url = this.buildUrl("evaluators", evaluatorId);
580
+ try {
581
+ const response = await apiFetch(url, {
582
+ method: "DELETE",
583
+ headers: this.buildHeaders()
584
+ });
585
+ if (!response.ok) {
586
+ const errorMessage = parseError(await response.text()) ?? `Failed to delete evaluator: ${response.status} ${response.statusText}`;
587
+ logger.error({
588
+ status: response.status,
589
+ error: errorMessage
590
+ }, "Failed to delete evaluator via API");
591
+ throw new Error(errorMessage);
592
+ }
593
+ logger.info({
594
+ tenantId: this.tenantId,
595
+ projectId: this.projectId,
596
+ evaluatorId
597
+ }, "Successfully deleted evaluator via API");
598
+ } catch (error) {
599
+ logger.error({
600
+ error,
601
+ tenantId: this.tenantId,
602
+ projectId: this.projectId,
603
+ evaluatorId
604
+ }, "Failed to delete evaluator");
605
+ throw error;
606
+ }
607
+ }
608
+ async listEvaluationSuiteConfigs() {
609
+ logger.info({
610
+ tenantId: this.tenantId,
611
+ projectId: this.projectId
612
+ }, "Listing evaluation suite configs via API");
613
+ const url = this.buildUrl("evaluation-suite-configs");
614
+ try {
615
+ const response = await apiFetch(url, {
616
+ method: "GET",
617
+ headers: this.buildHeaders()
618
+ });
619
+ if (!response.ok) {
620
+ const errorMessage = parseError(await response.text()) ?? `Failed to list evaluation suite configs: ${response.status} ${response.statusText}`;
621
+ logger.error({
622
+ status: response.status,
623
+ error: errorMessage
624
+ }, "Failed to list evaluation suite configs via API");
625
+ throw new Error(errorMessage);
626
+ }
627
+ return (await response.json()).data;
628
+ } catch (error) {
629
+ logger.error({
630
+ error,
631
+ tenantId: this.tenantId,
632
+ projectId: this.projectId
633
+ }, "Failed to list evaluation suite configs");
634
+ throw error;
635
+ }
636
+ }
637
+ async getEvaluationSuiteConfig(configId) {
638
+ logger.info({
639
+ tenantId: this.tenantId,
640
+ projectId: this.projectId,
641
+ configId
642
+ }, "Getting evaluation suite config via API");
643
+ const url = this.buildUrl("evaluation-suite-configs", configId);
644
+ try {
645
+ const response = await apiFetch(url, {
646
+ method: "GET",
647
+ headers: this.buildHeaders()
648
+ });
649
+ if (!response.ok) {
650
+ if (response.status === 404) {
651
+ logger.info({ configId }, "Evaluation suite config not found");
652
+ return null;
653
+ }
654
+ const errorMessage = parseError(await response.text()) ?? `Failed to get evaluation suite config: ${response.status} ${response.statusText}`;
655
+ logger.error({
656
+ status: response.status,
657
+ error: errorMessage
658
+ }, "Failed to get evaluation suite config via API");
659
+ throw new Error(errorMessage);
660
+ }
661
+ return (await response.json()).data;
662
+ } catch (error) {
663
+ logger.error({
664
+ error,
665
+ tenantId: this.tenantId,
666
+ projectId: this.projectId,
667
+ configId
668
+ }, "Failed to get evaluation suite config");
669
+ throw error;
670
+ }
671
+ }
672
+ async createEvaluationSuiteConfig(configData) {
673
+ logger.info({
674
+ tenantId: this.tenantId,
675
+ projectId: this.projectId
676
+ }, "Creating evaluation suite config via API");
677
+ const url = this.buildUrl("evaluation-suite-configs");
678
+ try {
679
+ const response = await apiFetch(url, {
680
+ method: "POST",
681
+ headers: this.buildHeaders(),
682
+ body: JSON.stringify(configData)
683
+ });
684
+ if (!response.ok) {
685
+ const errorMessage = parseError(await response.text()) ?? `Failed to create evaluation suite config: ${response.status} ${response.statusText}`;
686
+ logger.error({
687
+ status: response.status,
688
+ error: errorMessage
689
+ }, "Failed to create evaluation suite config via API");
690
+ throw new Error(errorMessage);
691
+ }
692
+ const result = await response.json();
693
+ logger.info({
694
+ tenantId: this.tenantId,
695
+ projectId: this.projectId
696
+ }, "Successfully created evaluation suite config via API");
697
+ return result.data;
698
+ } catch (error) {
699
+ logger.error({
700
+ error,
701
+ tenantId: this.tenantId,
702
+ projectId: this.projectId
703
+ }, "Failed to create evaluation suite config");
704
+ throw error;
705
+ }
706
+ }
707
+ async updateEvaluationSuiteConfig(configId, updateData) {
708
+ logger.info({
709
+ tenantId: this.tenantId,
710
+ projectId: this.projectId,
711
+ configId
712
+ }, "Updating evaluation suite config via API");
713
+ const url = this.buildUrl("evaluation-suite-configs", configId);
714
+ try {
715
+ const response = await apiFetch(url, {
716
+ method: "PATCH",
717
+ headers: this.buildHeaders(),
718
+ body: JSON.stringify(updateData)
719
+ });
720
+ if (!response.ok) {
721
+ const errorMessage = parseError(await response.text()) ?? `Failed to update evaluation suite config: ${response.status} ${response.statusText}`;
722
+ logger.error({
723
+ status: response.status,
724
+ error: errorMessage
725
+ }, "Failed to update evaluation suite config via API");
726
+ throw new Error(errorMessage);
727
+ }
728
+ const result = await response.json();
729
+ logger.info({
730
+ tenantId: this.tenantId,
731
+ projectId: this.projectId,
732
+ configId
733
+ }, "Successfully updated evaluation suite config via API");
734
+ return result.data;
735
+ } catch (error) {
736
+ logger.error({
737
+ error,
738
+ tenantId: this.tenantId,
739
+ projectId: this.projectId,
740
+ configId
741
+ }, "Failed to update evaluation suite config");
742
+ throw error;
743
+ }
744
+ }
745
+ async deleteEvaluationSuiteConfig(configId) {
746
+ logger.info({
747
+ tenantId: this.tenantId,
748
+ projectId: this.projectId,
749
+ configId
750
+ }, "Deleting evaluation suite config via API");
751
+ const url = this.buildUrl("evaluation-suite-configs", configId);
752
+ try {
753
+ const response = await apiFetch(url, {
754
+ method: "DELETE",
755
+ headers: this.buildHeaders()
756
+ });
757
+ if (!response.ok) {
758
+ const errorMessage = parseError(await response.text()) ?? `Failed to delete evaluation suite config: ${response.status} ${response.statusText}`;
759
+ logger.error({
760
+ status: response.status,
761
+ error: errorMessage
762
+ }, "Failed to delete evaluation suite config via API");
763
+ throw new Error(errorMessage);
764
+ }
765
+ logger.info({
766
+ tenantId: this.tenantId,
767
+ projectId: this.projectId,
768
+ configId
769
+ }, "Successfully deleted evaluation suite config via API");
770
+ } catch (error) {
771
+ logger.error({
772
+ error,
773
+ tenantId: this.tenantId,
774
+ projectId: this.projectId,
775
+ configId
776
+ }, "Failed to delete evaluation suite config");
777
+ throw error;
778
+ }
779
+ }
780
+ async listEvaluationSuiteConfigEvaluators(configId) {
781
+ logger.info({
782
+ tenantId: this.tenantId,
783
+ projectId: this.projectId,
784
+ configId
785
+ }, "Listing evaluators for evaluation suite config via API");
786
+ const url = this.buildUrl("evaluation-suite-configs", configId, "evaluators");
787
+ try {
788
+ const response = await apiFetch(url, {
789
+ method: "GET",
790
+ headers: this.buildHeaders()
791
+ });
792
+ if (!response.ok) {
793
+ const errorMessage = parseError(await response.text()) ?? `Failed to list evaluators for evaluation suite config: ${response.status} ${response.statusText}`;
794
+ logger.error({
795
+ status: response.status,
796
+ error: errorMessage
797
+ }, "Failed to list evaluators for evaluation suite config via API");
798
+ throw new Error(errorMessage);
799
+ }
800
+ return (await response.json()).data;
801
+ } catch (error) {
802
+ logger.error({
803
+ error,
804
+ tenantId: this.tenantId,
805
+ projectId: this.projectId,
806
+ configId
807
+ }, "Failed to list evaluators for evaluation suite config");
808
+ throw error;
809
+ }
810
+ }
811
+ async addEvaluatorToSuiteConfig(configId, evaluatorId) {
812
+ logger.info({
813
+ tenantId: this.tenantId,
814
+ projectId: this.projectId,
815
+ configId,
816
+ evaluatorId
817
+ }, "Adding evaluator to evaluation suite config via API");
818
+ const url = this.buildUrl("evaluation-suite-configs", configId, "evaluators", evaluatorId);
819
+ try {
820
+ const response = await apiFetch(url, {
821
+ method: "POST",
822
+ headers: this.buildHeaders()
823
+ });
824
+ if (!response.ok) {
825
+ const errorMessage = parseError(await response.text()) ?? `Failed to add evaluator to evaluation suite config: ${response.status} ${response.statusText}`;
826
+ logger.error({
827
+ status: response.status,
828
+ error: errorMessage
829
+ }, "Failed to add evaluator to evaluation suite config via API");
830
+ throw new Error(errorMessage);
831
+ }
832
+ const result = await response.json();
833
+ logger.info({
834
+ tenantId: this.tenantId,
835
+ projectId: this.projectId,
836
+ configId,
837
+ evaluatorId
838
+ }, "Successfully added evaluator to evaluation suite config via API");
839
+ return result.data;
840
+ } catch (error) {
841
+ logger.error({
842
+ error,
843
+ tenantId: this.tenantId,
844
+ projectId: this.projectId,
845
+ configId,
846
+ evaluatorId
847
+ }, "Failed to add evaluator to evaluation suite config");
848
+ throw error;
849
+ }
850
+ }
851
+ async removeEvaluatorFromSuiteConfig(configId, evaluatorId) {
852
+ logger.info({
853
+ tenantId: this.tenantId,
854
+ projectId: this.projectId,
855
+ configId,
856
+ evaluatorId
857
+ }, "Removing evaluator from evaluation suite config via API");
858
+ const url = this.buildUrl("evaluation-suite-configs", configId, "evaluators", evaluatorId);
859
+ try {
860
+ const response = await apiFetch(url, {
861
+ method: "DELETE",
862
+ headers: this.buildHeaders()
863
+ });
864
+ if (!response.ok) {
865
+ const errorMessage = parseError(await response.text()) ?? `Failed to remove evaluator from evaluation suite config: ${response.status} ${response.statusText}`;
866
+ logger.error({
867
+ status: response.status,
868
+ error: errorMessage
869
+ }, "Failed to remove evaluator from evaluation suite config via API");
870
+ throw new Error(errorMessage);
871
+ }
872
+ logger.info({
873
+ tenantId: this.tenantId,
874
+ projectId: this.projectId,
875
+ configId,
876
+ evaluatorId
877
+ }, "Successfully removed evaluator from evaluation suite config via API");
878
+ } catch (error) {
879
+ logger.error({
880
+ error,
881
+ tenantId: this.tenantId,
882
+ projectId: this.projectId,
883
+ configId,
884
+ evaluatorId
885
+ }, "Failed to remove evaluator from evaluation suite config");
886
+ throw error;
887
+ }
888
+ }
889
+ async getEvaluationResult(resultId) {
890
+ logger.info({
891
+ tenantId: this.tenantId,
892
+ projectId: this.projectId,
893
+ resultId
894
+ }, "Getting evaluation result via API");
895
+ const url = this.buildUrl("evaluation-results", resultId);
896
+ try {
897
+ const response = await apiFetch(url, {
898
+ method: "GET",
899
+ headers: this.buildHeaders()
900
+ });
901
+ if (!response.ok) {
902
+ if (response.status === 404) {
903
+ logger.info({ resultId }, "Evaluation result not found");
904
+ return null;
905
+ }
906
+ const errorMessage = parseError(await response.text()) ?? `Failed to get evaluation result: ${response.status} ${response.statusText}`;
907
+ logger.error({
908
+ status: response.status,
909
+ error: errorMessage
910
+ }, "Failed to get evaluation result via API");
911
+ throw new Error(errorMessage);
912
+ }
913
+ return (await response.json()).data;
914
+ } catch (error) {
915
+ logger.error({
916
+ error,
917
+ tenantId: this.tenantId,
918
+ projectId: this.projectId,
919
+ resultId
920
+ }, "Failed to get evaluation result");
921
+ throw error;
922
+ }
923
+ }
924
+ async createEvaluationResult(resultData) {
925
+ logger.info({
926
+ tenantId: this.tenantId,
927
+ projectId: this.projectId
928
+ }, "Creating evaluation result via API");
929
+ const url = this.buildUrl("evaluation-results");
930
+ try {
931
+ const response = await apiFetch(url, {
932
+ method: "POST",
933
+ headers: this.buildHeaders(),
934
+ body: JSON.stringify(resultData)
935
+ });
936
+ if (!response.ok) {
937
+ const errorMessage = parseError(await response.text()) ?? `Failed to create evaluation result: ${response.status} ${response.statusText}`;
938
+ logger.error({
939
+ status: response.status,
940
+ error: errorMessage
941
+ }, "Failed to create evaluation result via API");
942
+ throw new Error(errorMessage);
943
+ }
944
+ const result = await response.json();
945
+ logger.info({
946
+ tenantId: this.tenantId,
947
+ projectId: this.projectId
948
+ }, "Successfully created evaluation result via API");
949
+ return result.data;
950
+ } catch (error) {
951
+ logger.error({
952
+ error,
953
+ tenantId: this.tenantId,
954
+ projectId: this.projectId
955
+ }, "Failed to create evaluation result");
956
+ throw error;
957
+ }
958
+ }
959
+ async updateEvaluationResult(resultId, updateData) {
960
+ logger.info({
961
+ tenantId: this.tenantId,
962
+ projectId: this.projectId,
963
+ resultId
964
+ }, "Updating evaluation result via API");
965
+ const url = this.buildUrl("evaluation-results", resultId);
966
+ try {
967
+ const response = await apiFetch(url, {
968
+ method: "PATCH",
969
+ headers: this.buildHeaders(),
970
+ body: JSON.stringify(updateData)
971
+ });
972
+ if (!response.ok) {
973
+ const errorMessage = parseError(await response.text()) ?? `Failed to update evaluation result: ${response.status} ${response.statusText}`;
974
+ logger.error({
975
+ status: response.status,
976
+ error: errorMessage
977
+ }, "Failed to update evaluation result via API");
978
+ throw new Error(errorMessage);
979
+ }
980
+ const result = await response.json();
981
+ logger.info({
982
+ tenantId: this.tenantId,
983
+ projectId: this.projectId,
984
+ resultId
985
+ }, "Successfully updated evaluation result via API");
986
+ return result.data;
987
+ } catch (error) {
988
+ logger.error({
989
+ error,
990
+ tenantId: this.tenantId,
991
+ projectId: this.projectId,
992
+ resultId
993
+ }, "Failed to update evaluation result");
994
+ throw error;
995
+ }
996
+ }
997
+ async deleteEvaluationResult(resultId) {
998
+ logger.info({
999
+ tenantId: this.tenantId,
1000
+ projectId: this.projectId,
1001
+ resultId
1002
+ }, "Deleting evaluation result via API");
1003
+ const url = this.buildUrl("evaluation-results", resultId);
1004
+ try {
1005
+ const response = await apiFetch(url, {
1006
+ method: "DELETE",
1007
+ headers: this.buildHeaders()
1008
+ });
1009
+ if (!response.ok) {
1010
+ const errorMessage = parseError(await response.text()) ?? `Failed to delete evaluation result: ${response.status} ${response.statusText}`;
1011
+ logger.error({
1012
+ status: response.status,
1013
+ error: errorMessage
1014
+ }, "Failed to delete evaluation result via API");
1015
+ throw new Error(errorMessage);
1016
+ }
1017
+ logger.info({
1018
+ tenantId: this.tenantId,
1019
+ projectId: this.projectId,
1020
+ resultId
1021
+ }, "Successfully deleted evaluation result via API");
1022
+ } catch (error) {
1023
+ logger.error({
1024
+ error,
1025
+ tenantId: this.tenantId,
1026
+ projectId: this.projectId,
1027
+ resultId
1028
+ }, "Failed to delete evaluation result");
1029
+ throw error;
1030
+ }
1031
+ }
1032
+ /**
1033
+ * Trigger batch evaluation of conversations with selected evaluators.
1034
+ * Supports filtering by conversation IDs, date range, or dataset run IDs.
1035
+ */
1036
+ async triggerBatchEvaluation(evaluationData) {
1037
+ const jobFilters = {};
1038
+ if (evaluationData.conversationIds?.length) jobFilters.conversationIds = evaluationData.conversationIds;
1039
+ if (evaluationData.dateRange) jobFilters.dateRange = evaluationData.dateRange;
1040
+ if (evaluationData.datasetRunIds?.length) jobFilters.datasetRunIds = evaluationData.datasetRunIds;
1041
+ logger.info({
1042
+ tenantId: this.tenantId,
1043
+ projectId: this.projectId,
1044
+ jobFilters,
1045
+ evaluatorIds: evaluationData.evaluatorIds
1046
+ }, "Triggering batch evaluation via API");
1047
+ const url = this.buildUrl("evaluation-job-configs");
1048
+ try {
1049
+ const response = await apiFetch(url, {
1050
+ method: "POST",
1051
+ headers: this.buildHeaders(),
1052
+ body: JSON.stringify({
1053
+ name: evaluationData.name || `Batch Evaluation ${(/* @__PURE__ */ new Date()).toISOString()}`,
1054
+ evaluatorIds: evaluationData.evaluatorIds,
1055
+ jobFilters
1056
+ })
1057
+ });
1058
+ if (!response.ok) {
1059
+ const errorMessage = parseError(await response.text()) ?? `Failed to trigger batch evaluation: ${response.status} ${response.statusText}`;
1060
+ logger.error({
1061
+ status: response.status,
1062
+ error: errorMessage
1063
+ }, "Failed to trigger batch evaluation via API");
1064
+ throw new Error(errorMessage);
1065
+ }
1066
+ const result = await response.json();
1067
+ logger.info({
1068
+ tenantId: this.tenantId,
1069
+ projectId: this.projectId,
1070
+ evaluationJobConfigId: result.data.id
1071
+ }, "Successfully triggered batch evaluation via API");
1072
+ return {
1073
+ message: "Batch evaluation triggered successfully",
1074
+ evaluationJobConfigId: result.data.id,
1075
+ evaluatorIds: evaluationData.evaluatorIds
1076
+ };
1077
+ } catch (error) {
1078
+ logger.error({
1079
+ error,
1080
+ tenantId: this.tenantId,
1081
+ projectId: this.projectId
1082
+ }, "Failed to trigger batch evaluation");
1083
+ throw error;
1084
+ }
1085
+ }
1086
+ async listDatasetRuns(datasetId) {
1087
+ logger.info({
1088
+ tenantId: this.tenantId,
1089
+ projectId: this.projectId,
1090
+ datasetId
1091
+ }, "Listing dataset runs via API");
1092
+ const url = this.buildUrl("dataset-runs", "by-dataset", datasetId);
1093
+ try {
1094
+ const response = await apiFetch(url, {
1095
+ method: "GET",
1096
+ headers: this.buildHeaders()
1097
+ });
1098
+ if (!response.ok) {
1099
+ const errorMessage = parseError(await response.text()) ?? `Failed to list dataset runs: ${response.status} ${response.statusText}`;
1100
+ logger.error({
1101
+ status: response.status,
1102
+ error: errorMessage
1103
+ }, "Failed to list dataset runs via API");
1104
+ throw new Error(errorMessage);
1105
+ }
1106
+ return (await response.json()).data;
1107
+ } catch (error) {
1108
+ logger.error({
1109
+ error,
1110
+ tenantId: this.tenantId,
1111
+ projectId: this.projectId,
1112
+ datasetId
1113
+ }, "Failed to list dataset runs");
1114
+ throw error;
1115
+ }
1116
+ }
1117
+ async getDatasetRun(runId) {
1118
+ logger.info({
1119
+ tenantId: this.tenantId,
1120
+ projectId: this.projectId,
1121
+ runId
1122
+ }, "Getting dataset run via API");
1123
+ const url = this.buildUrl("dataset-runs", runId);
1124
+ try {
1125
+ const response = await apiFetch(url, {
1126
+ method: "GET",
1127
+ headers: this.buildHeaders()
1128
+ });
1129
+ if (!response.ok) {
1130
+ if (response.status === 404) {
1131
+ logger.info({ runId }, "Dataset run not found");
1132
+ return null;
1133
+ }
1134
+ const errorMessage = parseError(await response.text()) ?? `Failed to get dataset run: ${response.status} ${response.statusText}`;
1135
+ logger.error({
1136
+ status: response.status,
1137
+ error: errorMessage
1138
+ }, "Failed to get dataset run via API");
1139
+ throw new Error(errorMessage);
1140
+ }
1141
+ return (await response.json()).data;
1142
+ } catch (error) {
1143
+ logger.error({
1144
+ error,
1145
+ tenantId: this.tenantId,
1146
+ projectId: this.projectId,
1147
+ runId
1148
+ }, "Failed to get dataset run");
1149
+ throw error;
1150
+ }
1151
+ }
1152
+ async triggerDatasetRun(datasetId, runData) {
1153
+ logger.info({
1154
+ tenantId: this.tenantId,
1155
+ projectId: this.projectId,
1156
+ datasetId,
1157
+ agentIds: runData.agentIds,
1158
+ evaluatorIds: runData.evaluatorIds
1159
+ }, "Triggering dataset run via API");
1160
+ const url = this.buildUrl("datasets", datasetId, "trigger");
1161
+ try {
1162
+ const response = await apiFetch(url, {
1163
+ method: "POST",
1164
+ headers: this.buildHeaders(),
1165
+ body: JSON.stringify(runData)
1166
+ });
1167
+ if (!response.ok) {
1168
+ const errorMessage = parseError(await response.text()) ?? `Failed to trigger dataset run: ${response.status} ${response.statusText}`;
1169
+ logger.error({
1170
+ status: response.status,
1171
+ error: errorMessage
1172
+ }, "Failed to trigger dataset run via API");
1173
+ throw new Error(errorMessage);
1174
+ }
1175
+ const result = await response.json();
1176
+ logger.info({
1177
+ tenantId: this.tenantId,
1178
+ projectId: this.projectId,
1179
+ datasetId,
1180
+ datasetRunId: result.datasetRunId
1181
+ }, "Successfully triggered dataset run via API");
1182
+ return result;
1183
+ } catch (error) {
1184
+ logger.error({
1185
+ error,
1186
+ tenantId: this.tenantId,
1187
+ projectId: this.projectId,
1188
+ datasetId
1189
+ }, "Failed to trigger dataset run");
1190
+ throw error;
1191
+ }
1192
+ }
1193
+ };
1194
+ /**
1195
+ * Helper function to create an EvaluationClient instance
1196
+ */
1197
+ function evaluationClient(config) {
1198
+ return new EvaluationClient(config);
1199
+ }
1200
+
1201
+ //#endregion
1202
+ export { EvaluationClient, evaluationClient };