@mutagent/cli 0.1.196 → 0.1.197
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/bin/cli.js +13 -602
- package/dist/bin/cli.js.map +9 -10
- package/dist/index.js +1 -566
- package/dist/index.js.map +5 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -316,125 +316,6 @@ var init_errors = __esm(() => {
|
|
|
316
316
|
};
|
|
317
317
|
});
|
|
318
318
|
|
|
319
|
-
// src/lib/scorecard-extraction.ts
|
|
320
|
-
function extractScorecardDetails(rawState, iterCtx) {
|
|
321
|
-
if (!iterCtx)
|
|
322
|
-
return {};
|
|
323
|
-
const gc = rawState.globalContext;
|
|
324
|
-
const gcCtx = gc?.context;
|
|
325
|
-
const beforeExec = gcCtx?.executions;
|
|
326
|
-
const beforeResults = beforeExec?.results ?? [];
|
|
327
|
-
const beforeById = new Map;
|
|
328
|
-
for (const r of beforeResults) {
|
|
329
|
-
const id = r.id;
|
|
330
|
-
if (id)
|
|
331
|
-
beforeById.set(id, r);
|
|
332
|
-
}
|
|
333
|
-
let originalScore;
|
|
334
|
-
if (beforeResults.length > 0) {
|
|
335
|
-
const sum = beforeResults.reduce((acc, r) => {
|
|
336
|
-
const eval_ = r.evaluation;
|
|
337
|
-
return acc + (eval_?.score ?? 0);
|
|
338
|
-
}, 0);
|
|
339
|
-
originalScore = sum / beforeResults.length;
|
|
340
|
-
}
|
|
341
|
-
const afterExec = iterCtx.executionResults;
|
|
342
|
-
const afterResults = afterExec?.executions ?? [];
|
|
343
|
-
const datasetResults = afterResults.length > 0 ? afterResults.map((r) => {
|
|
344
|
-
const id = r.id || "unknown";
|
|
345
|
-
const afterEval = r.evaluation;
|
|
346
|
-
const afterScore = afterEval?.score ?? 0;
|
|
347
|
-
const beforeResult = beforeById.get(id);
|
|
348
|
-
const beforeEval = beforeResult?.evaluation;
|
|
349
|
-
const beforeScore = beforeEval?.score;
|
|
350
|
-
return { id, beforeScore, afterScore };
|
|
351
|
-
}) : undefined;
|
|
352
|
-
const criteriaScores = extractCriteriaScores(beforeResults, afterResults);
|
|
353
|
-
const rawFailureModes = iterCtx.failureModes;
|
|
354
|
-
const failureModes = rawFailureModes?.categories && rawFailureModes.failures ? rawFailureModes.categories.map((category) => ({
|
|
355
|
-
category,
|
|
356
|
-
failures: (rawFailureModes.failures?.[category] ?? []).map((f) => ({
|
|
357
|
-
description: f.description ?? f.label,
|
|
358
|
-
summary: f.summary
|
|
359
|
-
}))
|
|
360
|
-
})) : undefined;
|
|
361
|
-
const rawMutations = iterCtx.mutations;
|
|
362
|
-
const mutations = rawMutations && rawMutations.length > 0 ? rawMutations.map((m) => ({
|
|
363
|
-
label: m.label ?? "Unknown mutation",
|
|
364
|
-
status: m.status ?? "pending",
|
|
365
|
-
priority: m.priority,
|
|
366
|
-
rationale: m.target?.rationale
|
|
367
|
-
})) : undefined;
|
|
368
|
-
const evaluationDetails = afterResults.length > 0 ? afterResults.map((r) => {
|
|
369
|
-
const id = r.id || "unknown";
|
|
370
|
-
const eval_ = r.evaluation;
|
|
371
|
-
const score = eval_?.score ?? 0;
|
|
372
|
-
const success = eval_?.success ?? false;
|
|
373
|
-
const metrics = eval_?.evaluations?.map((metric) => {
|
|
374
|
-
const criteria = metric.evaluationChecklist?.items?.map((item) => ({
|
|
375
|
-
name: item.evaluationParameter ?? item.criteria ?? "unknown",
|
|
376
|
-
score: item.llmScore ?? 0,
|
|
377
|
-
success: item.success ?? false
|
|
378
|
-
}));
|
|
379
|
-
return {
|
|
380
|
-
name: metric.name ?? "unknown",
|
|
381
|
-
score: metric.score ?? 0,
|
|
382
|
-
success: metric.success ?? false,
|
|
383
|
-
failureMode: metric.failureMode,
|
|
384
|
-
reasoning: metric.reasoning,
|
|
385
|
-
criteria: criteria && criteria.length > 0 ? criteria : undefined
|
|
386
|
-
};
|
|
387
|
-
});
|
|
388
|
-
return {
|
|
389
|
-
itemId: id,
|
|
390
|
-
score,
|
|
391
|
-
success,
|
|
392
|
-
metrics: metrics && metrics.length > 0 ? metrics : undefined
|
|
393
|
-
};
|
|
394
|
-
}) : undefined;
|
|
395
|
-
return {
|
|
396
|
-
originalScore,
|
|
397
|
-
criteriaScores,
|
|
398
|
-
datasetResults,
|
|
399
|
-
failureModes,
|
|
400
|
-
mutations,
|
|
401
|
-
evaluationDetails
|
|
402
|
-
};
|
|
403
|
-
}
|
|
404
|
-
function extractCriteriaScores(beforeResults, afterResults) {
|
|
405
|
-
const metricNames = new Set;
|
|
406
|
-
const beforeScores = new Map;
|
|
407
|
-
const afterScores = new Map;
|
|
408
|
-
for (const r of beforeResults) {
|
|
409
|
-
const eval_ = r.evaluation;
|
|
410
|
-
for (const m of eval_?.evaluations ?? []) {
|
|
411
|
-
const name = m.name ?? "unknown";
|
|
412
|
-
metricNames.add(name);
|
|
413
|
-
const existing = beforeScores.get(name) ?? [];
|
|
414
|
-
existing.push(m.score ?? 0);
|
|
415
|
-
beforeScores.set(name, existing);
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
for (const r of afterResults) {
|
|
419
|
-
const eval_ = r.evaluation;
|
|
420
|
-
for (const m of eval_?.evaluations ?? []) {
|
|
421
|
-
const name = m.name ?? "unknown";
|
|
422
|
-
metricNames.add(name);
|
|
423
|
-
const existing = afterScores.get(name) ?? [];
|
|
424
|
-
existing.push(m.score ?? 0);
|
|
425
|
-
afterScores.set(name, existing);
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
if (metricNames.size === 0)
|
|
429
|
-
return;
|
|
430
|
-
const avg = (arr) => arr.reduce((a, b) => a + b, 0) / arr.length;
|
|
431
|
-
return Array.from(metricNames).map((name) => ({
|
|
432
|
-
name,
|
|
433
|
-
before: beforeScores.has(name) ? avg(beforeScores.get(name) ?? []) : undefined,
|
|
434
|
-
after: afterScores.has(name) ? avg(afterScores.get(name) ?? []) : undefined
|
|
435
|
-
}));
|
|
436
|
-
}
|
|
437
|
-
|
|
438
319
|
// src/lib/sdk-client.ts
|
|
439
320
|
var exports_sdk_client = {};
|
|
440
321
|
__export(exports_sdk_client, {
|
|
@@ -545,416 +426,6 @@ class SDKClientWrapper {
|
|
|
545
426
|
}
|
|
546
427
|
return response.json();
|
|
547
428
|
}
|
|
548
|
-
async requestRaw(path, options) {
|
|
549
|
-
const optHeaders = options?.headers;
|
|
550
|
-
let extraHeaders = {};
|
|
551
|
-
if (optHeaders instanceof Headers) {
|
|
552
|
-
optHeaders.forEach((value, key) => {
|
|
553
|
-
extraHeaders[key] = value;
|
|
554
|
-
});
|
|
555
|
-
} else if (optHeaders) {
|
|
556
|
-
extraHeaders = optHeaders;
|
|
557
|
-
}
|
|
558
|
-
const tenancyHeaders = {};
|
|
559
|
-
if (this.workspaceId)
|
|
560
|
-
tenancyHeaders["x-workspace-id"] = this.workspaceId;
|
|
561
|
-
if (this.organizationId)
|
|
562
|
-
tenancyHeaders["x-organization-id"] = this.organizationId;
|
|
563
|
-
return fetch(`${this.endpoint}${path}`, {
|
|
564
|
-
...options,
|
|
565
|
-
headers: {
|
|
566
|
-
"x-api-key": this.apiKey,
|
|
567
|
-
"Content-Type": "application/json",
|
|
568
|
-
...tenancyHeaders,
|
|
569
|
-
...extraHeaders
|
|
570
|
-
}
|
|
571
|
-
});
|
|
572
|
-
}
|
|
573
|
-
async listPrompts() {
|
|
574
|
-
try {
|
|
575
|
-
const response = await this.sdk.prompt.listPrompts();
|
|
576
|
-
return response.result.data;
|
|
577
|
-
} catch (error) {
|
|
578
|
-
this.handleError(error);
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
async getPrompt(id) {
|
|
582
|
-
try {
|
|
583
|
-
const response = await this.sdk.prompt.getPrompt({ id: parseInt(id, 10) });
|
|
584
|
-
return response;
|
|
585
|
-
} catch (error) {
|
|
586
|
-
this.handleError(error);
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
async createPrompt(data) {
|
|
590
|
-
try {
|
|
591
|
-
const response = await this.sdk.prompt.createPrompt({
|
|
592
|
-
name: data.name ?? "",
|
|
593
|
-
description: data.description ?? undefined,
|
|
594
|
-
version: data.version ?? undefined,
|
|
595
|
-
isLatest: data.isLatest ?? undefined,
|
|
596
|
-
systemPrompt: data.systemPrompt ?? undefined,
|
|
597
|
-
humanPrompt: data.humanPrompt ?? undefined,
|
|
598
|
-
rawPrompt: data.rawPrompt ?? undefined,
|
|
599
|
-
inputSchema: data.inputSchema ?? undefined,
|
|
600
|
-
outputSchema: data.outputSchema ?? undefined,
|
|
601
|
-
metadata: data.metadata ?? undefined,
|
|
602
|
-
tags: data.tags ?? undefined
|
|
603
|
-
});
|
|
604
|
-
return response;
|
|
605
|
-
} catch (error) {
|
|
606
|
-
this.handleError(error);
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
async updatePrompt(id, data) {
|
|
610
|
-
try {
|
|
611
|
-
const body = {
|
|
612
|
-
description: data.description ?? undefined,
|
|
613
|
-
isLatest: data.isLatest ?? undefined,
|
|
614
|
-
systemPrompt: data.systemPrompt ?? undefined,
|
|
615
|
-
humanPrompt: data.humanPrompt ?? undefined,
|
|
616
|
-
rawPrompt: data.rawPrompt ?? undefined,
|
|
617
|
-
inputSchema: data.inputSchema,
|
|
618
|
-
outputSchema: data.outputSchema,
|
|
619
|
-
metadata: data.metadata,
|
|
620
|
-
tags: data.tags ?? undefined
|
|
621
|
-
};
|
|
622
|
-
if (data.name !== undefined) {
|
|
623
|
-
body.name = data.name;
|
|
624
|
-
}
|
|
625
|
-
const updateArgs = { id: parseInt(id, 10), body };
|
|
626
|
-
const response = await this.sdk.prompt.updatePrompt(updateArgs);
|
|
627
|
-
return response;
|
|
628
|
-
} catch (error) {
|
|
629
|
-
this.handleError(error);
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
async deletePrompt(id, options) {
|
|
633
|
-
try {
|
|
634
|
-
if (options?.force) {
|
|
635
|
-
await this.request(`/api/prompt/${id}?force=true`, { method: "DELETE" });
|
|
636
|
-
} else {
|
|
637
|
-
await this.sdk.prompt.deletePrompt({ id: parseInt(id, 10) });
|
|
638
|
-
}
|
|
639
|
-
} catch (error) {
|
|
640
|
-
this.handleError(error);
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
async getDataset(datasetId) {
|
|
644
|
-
try {
|
|
645
|
-
return await this.request(`/api/prompts/datasets/${String(datasetId)}`);
|
|
646
|
-
} catch (error) {
|
|
647
|
-
this.handleError(error);
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
async getDatasetItem(itemId) {
|
|
651
|
-
try {
|
|
652
|
-
return await this.request(`/api/prompts/dataset-items/${String(itemId)}`);
|
|
653
|
-
} catch (error) {
|
|
654
|
-
this.handleError(error);
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
async listDatasets(promptId) {
|
|
658
|
-
try {
|
|
659
|
-
const response = await this.request(`/api/prompt/${promptId}/datasets`);
|
|
660
|
-
return Array.isArray(response) ? response : response.data;
|
|
661
|
-
} catch (error) {
|
|
662
|
-
this.handleError(error);
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
async addDataset(promptId, fileContent, name) {
|
|
666
|
-
try {
|
|
667
|
-
let parsed;
|
|
668
|
-
try {
|
|
669
|
-
parsed = JSON.parse(fileContent);
|
|
670
|
-
} catch {
|
|
671
|
-
parsed = null;
|
|
672
|
-
}
|
|
673
|
-
let datasetName = name ?? `Dataset ${new Date().toISOString().slice(0, 16)}`;
|
|
674
|
-
let items;
|
|
675
|
-
if (parsed !== null && !Array.isArray(parsed) && typeof parsed === "object" && "name" in parsed) {
|
|
676
|
-
const meta = parsed;
|
|
677
|
-
datasetName = meta.name ?? datasetName;
|
|
678
|
-
if (Array.isArray(meta.items)) {
|
|
679
|
-
items = meta.items;
|
|
680
|
-
}
|
|
681
|
-
} else if (Array.isArray(parsed)) {
|
|
682
|
-
items = parsed;
|
|
683
|
-
}
|
|
684
|
-
const dataset = await this.request(`/api/prompt/${promptId}/datasets`, {
|
|
685
|
-
method: "POST",
|
|
686
|
-
body: JSON.stringify({
|
|
687
|
-
name: datasetName
|
|
688
|
-
})
|
|
689
|
-
});
|
|
690
|
-
let itemCount = 0;
|
|
691
|
-
if (items && items.length > 0) {
|
|
692
|
-
const mappedItems = items.map((item, index) => ({
|
|
693
|
-
input: item.input ?? item,
|
|
694
|
-
expectedOutput: item.expectedOutput ?? item.expected_output ?? undefined,
|
|
695
|
-
name: item.name ?? `Item ${String(index + 1)}`,
|
|
696
|
-
userFeedback: item.userFeedback,
|
|
697
|
-
systemFeedback: item.systemFeedback,
|
|
698
|
-
labels: item.labels,
|
|
699
|
-
metadata: item.metadata
|
|
700
|
-
}));
|
|
701
|
-
const missingExpectedOutputCount = mappedItems.filter((item) => item.expectedOutput === undefined).length;
|
|
702
|
-
const bulkResult = await this.requestRaw(`/api/prompts/datasets/${String(dataset.id)}/items/bulk`, {
|
|
703
|
-
method: "POST",
|
|
704
|
-
body: JSON.stringify({ items: mappedItems })
|
|
705
|
-
});
|
|
706
|
-
if (!bulkResult.ok) {
|
|
707
|
-
const bodyText = await bulkResult.text();
|
|
708
|
-
let parsed2;
|
|
709
|
-
try {
|
|
710
|
-
parsed2 = JSON.parse(bodyText);
|
|
711
|
-
} catch {}
|
|
712
|
-
const typed = parsed2;
|
|
713
|
-
if (typed && typed.kind === "bulk_insert_rollback") {
|
|
714
|
-
const constraint = typeof typed.failingConstraint === "string" ? typed.failingConstraint : "unknown";
|
|
715
|
-
const rowIndex = typeof typed.failingRowIndex === "number" ? typed.failingRowIndex : null;
|
|
716
|
-
throw new ApiError(bulkResult.status, `Bulk insert rolled back — constraint: ${constraint}` + (rowIndex !== null ? `, first failing row: ${String(rowIndex)}` : ""));
|
|
717
|
-
}
|
|
718
|
-
throw new ApiError(bulkResult.status, bodyText || "Bulk insert failed");
|
|
719
|
-
}
|
|
720
|
-
itemCount = mappedItems.length;
|
|
721
|
-
return { ...dataset, itemCount, missingExpectedOutputCount };
|
|
722
|
-
}
|
|
723
|
-
return { ...dataset, itemCount };
|
|
724
|
-
} catch (error) {
|
|
725
|
-
this.handleError(error);
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
async listDatasetItems(datasetId) {
|
|
729
|
-
try {
|
|
730
|
-
const response = await this.request(`/api/prompts/datasets/${datasetId}/items`);
|
|
731
|
-
return Array.isArray(response) ? response : response.data;
|
|
732
|
-
} catch (error) {
|
|
733
|
-
this.handleError(error);
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
async deleteDataset(_promptId, datasetId, options) {
|
|
737
|
-
try {
|
|
738
|
-
const query = options?.force ? "?force=true" : "";
|
|
739
|
-
await this.request(`/api/prompts/datasets/${datasetId}${query}`, { method: "DELETE" });
|
|
740
|
-
} catch (error) {
|
|
741
|
-
this.handleError(error);
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
|
-
async listEvaluations(promptId) {
|
|
745
|
-
try {
|
|
746
|
-
const response = await this.request(`/api/prompts/evaluations?promptId=${promptId}`);
|
|
747
|
-
return response.data;
|
|
748
|
-
} catch (error) {
|
|
749
|
-
this.handleError(error);
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
async getEvaluation(evaluationId) {
|
|
753
|
-
try {
|
|
754
|
-
return await this.request(`/api/prompts/evaluations/${evaluationId}`);
|
|
755
|
-
} catch (error) {
|
|
756
|
-
this.handleError(error);
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
async createEvaluation(promptId, data) {
|
|
760
|
-
try {
|
|
761
|
-
return await this.request("/api/prompts/evaluations", {
|
|
762
|
-
method: "POST",
|
|
763
|
-
body: JSON.stringify({
|
|
764
|
-
promptId: parseInt(promptId, 10),
|
|
765
|
-
name: data.name,
|
|
766
|
-
description: data.description,
|
|
767
|
-
evalConfig: data.evalConfig,
|
|
768
|
-
llmConfig: data.llmConfig,
|
|
769
|
-
tags: data.tags,
|
|
770
|
-
metadata: data.metadata
|
|
771
|
-
})
|
|
772
|
-
});
|
|
773
|
-
} catch (error) {
|
|
774
|
-
this.handleError(error);
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
async deleteEvaluation(evaluationId) {
|
|
778
|
-
try {
|
|
779
|
-
await this.request(`/api/prompts/evaluations/${evaluationId}`, { method: "DELETE" });
|
|
780
|
-
} catch (error) {
|
|
781
|
-
this.handleError(error);
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
async listOptimizations() {
|
|
785
|
-
try {
|
|
786
|
-
const response = await this.request("/api/optimizations");
|
|
787
|
-
if (Array.isArray(response))
|
|
788
|
-
return response;
|
|
789
|
-
const r = response;
|
|
790
|
-
if (Array.isArray(r.data))
|
|
791
|
-
return r.data;
|
|
792
|
-
return [];
|
|
793
|
-
} catch (error) {
|
|
794
|
-
this.handleError(error);
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
async listExperiments(filters) {
|
|
798
|
-
try {
|
|
799
|
-
const params = new URLSearchParams;
|
|
800
|
-
if (filters?.promptId !== undefined)
|
|
801
|
-
params.set("promptId", String(filters.promptId));
|
|
802
|
-
if (filters?.status)
|
|
803
|
-
params.set("status", filters.status);
|
|
804
|
-
if (filters?.limit !== undefined)
|
|
805
|
-
params.set("limit", String(filters.limit));
|
|
806
|
-
if (filters?.offset !== undefined)
|
|
807
|
-
params.set("offset", String(filters.offset));
|
|
808
|
-
const qs = params.toString();
|
|
809
|
-
const response = await this.request(`/api/prompts/experiments${qs ? `?${qs}` : ""}`);
|
|
810
|
-
if (Array.isArray(response))
|
|
811
|
-
return { experiments: response, total: response.length };
|
|
812
|
-
const r = response;
|
|
813
|
-
const experiments = r.experiments ?? r.data ?? [];
|
|
814
|
-
return { experiments, total: r.total ?? experiments.length };
|
|
815
|
-
} catch (error) {
|
|
816
|
-
this.handleError(error);
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
async createExperiment(data) {
|
|
820
|
-
try {
|
|
821
|
-
return await this.request("/api/prompts/experiments", {
|
|
822
|
-
method: "POST",
|
|
823
|
-
body: JSON.stringify(data)
|
|
824
|
-
});
|
|
825
|
-
} catch (error) {
|
|
826
|
-
this.handleError(error);
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
async getExperiment(id) {
|
|
830
|
-
try {
|
|
831
|
-
return await this.request(`/api/prompts/experiments/${id}`);
|
|
832
|
-
} catch (error) {
|
|
833
|
-
this.handleError(error);
|
|
834
|
-
}
|
|
835
|
-
}
|
|
836
|
-
async deleteExperiment(id) {
|
|
837
|
-
try {
|
|
838
|
-
await this.request(`/api/prompts/experiments/${id}`, { method: "DELETE" });
|
|
839
|
-
} catch (error) {
|
|
840
|
-
this.handleError(error);
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
async executeExperiment(id) {
|
|
844
|
-
try {
|
|
845
|
-
return await this.request(`/api/prompts/experiments/${id}/execute`, { method: "POST", body: JSON.stringify({}) });
|
|
846
|
-
} catch (error) {
|
|
847
|
-
this.handleError(error);
|
|
848
|
-
}
|
|
849
|
-
}
|
|
850
|
-
async playgroundEval(promptId, data) {
|
|
851
|
-
try {
|
|
852
|
-
return await this.request(`/api/prompt/${promptId}/playground/eval`, {
|
|
853
|
-
method: "POST",
|
|
854
|
-
body: JSON.stringify(data)
|
|
855
|
-
});
|
|
856
|
-
} catch (error) {
|
|
857
|
-
this.handleError(error);
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
async cancelOptimization(jobId) {
|
|
861
|
-
try {
|
|
862
|
-
return await this.request(`/api/optimization/${jobId}/cancel`, {
|
|
863
|
-
method: "POST"
|
|
864
|
-
});
|
|
865
|
-
} catch (error) {
|
|
866
|
-
this.handleError(error);
|
|
867
|
-
}
|
|
868
|
-
}
|
|
869
|
-
async startOptimization(promptId, datasetId, evaluationId, config) {
|
|
870
|
-
try {
|
|
871
|
-
return await this.request(`/api/prompt/${promptId}/optimize`, {
|
|
872
|
-
method: "POST",
|
|
873
|
-
body: JSON.stringify({
|
|
874
|
-
datasetId: parseInt(datasetId, 10),
|
|
875
|
-
evaluationId: parseInt(evaluationId, 10),
|
|
876
|
-
config: {
|
|
877
|
-
maxIterations: config?.maxIterations ?? 1,
|
|
878
|
-
targetScore: config?.targetScore ?? 0.8,
|
|
879
|
-
patience: config?.patience,
|
|
880
|
-
...config?.executionModel ? { executionModel: config.executionModel } : {},
|
|
881
|
-
...config?.evaluationModel ? { evaluationModel: config.evaluationModel } : {},
|
|
882
|
-
...config?.optimizationModel ? { optimizationModel: config.optimizationModel } : {},
|
|
883
|
-
...config?.providerId ? { executionProviderId: config.providerId } : {},
|
|
884
|
-
...config?.evalProviderId ? { evaluationProviderId: config.evalProviderId } : {},
|
|
885
|
-
...config?.optProviderId ? { optimizationProviderId: config.optProviderId } : {}
|
|
886
|
-
},
|
|
887
|
-
executionMode: "worker_loop"
|
|
888
|
-
})
|
|
889
|
-
});
|
|
890
|
-
} catch (error) {
|
|
891
|
-
this.handleError(error);
|
|
892
|
-
}
|
|
893
|
-
}
|
|
894
|
-
async getOptimizationStatus(jobId) {
|
|
895
|
-
try {
|
|
896
|
-
const raw = await this.request(`/api/optimization/${jobId}`);
|
|
897
|
-
const id = raw.id;
|
|
898
|
-
return {
|
|
899
|
-
...raw,
|
|
900
|
-
jobId: id ?? jobId,
|
|
901
|
-
progressPercent: typeof raw.progress === "number" ? raw.progress : 0
|
|
902
|
-
};
|
|
903
|
-
} catch (error) {
|
|
904
|
-
this.handleError(error);
|
|
905
|
-
}
|
|
906
|
-
}
|
|
907
|
-
async getOptimizationScorecard(jobId) {
|
|
908
|
-
try {
|
|
909
|
-
const res = await this.request(`/api/optimization/${jobId}/results`);
|
|
910
|
-
if (res.scorecard?.rendered) {
|
|
911
|
-
return { rendered: res.scorecard.rendered, data: res.scorecard.data ?? [] };
|
|
912
|
-
}
|
|
913
|
-
return null;
|
|
914
|
-
} catch {
|
|
915
|
-
return null;
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
|
-
async getOptimizationResults(jobId) {
|
|
919
|
-
try {
|
|
920
|
-
const job = await this.request(`/api/optimization/${jobId}`);
|
|
921
|
-
const progress = await this.request(`/api/optimization/${jobId}/progress`);
|
|
922
|
-
const prompt = await this.getPrompt(String(job.promptId ?? ""));
|
|
923
|
-
const statesRes = await this.request(`/api/optimization/${jobId}/states`).catch(() => ({ states: [] }));
|
|
924
|
-
const scorecardDigest = await this.getOptimizationScorecard(jobId);
|
|
925
|
-
const latestState = statesRes.states[statesRes.states.length - 1];
|
|
926
|
-
const rawState = latestState?.state ?? {};
|
|
927
|
-
const iterCtx = rawState.iterationContext ?? rawState.current?.context;
|
|
928
|
-
const basePromptObj = iterCtx?.basePrompt;
|
|
929
|
-
const currentPromptObj = iterCtx?.currentPrompt;
|
|
930
|
-
const mutatedPromptText = typeof currentPromptObj?.prompt === "string" ? currentPromptObj.prompt : undefined;
|
|
931
|
-
const originalPromptText = typeof basePromptObj?.prompt === "string" ? basePromptObj.prompt : undefined;
|
|
932
|
-
const extracted = extractScorecardDetails(rawState, iterCtx);
|
|
933
|
-
return {
|
|
934
|
-
job: {
|
|
935
|
-
id: job.id ?? jobId,
|
|
936
|
-
promptId: job.promptId ?? 0,
|
|
937
|
-
status: job.status ?? "unknown",
|
|
938
|
-
config: job.config
|
|
939
|
-
},
|
|
940
|
-
prompt,
|
|
941
|
-
bestScore: job.bestScore,
|
|
942
|
-
originalScore: extracted.originalScore,
|
|
943
|
-
iterationsCompleted: job.currentIteration,
|
|
944
|
-
scoreProgression: Array.isArray(progress.progression) ? progress.progression.map((p) => typeof p.score === "number" ? p.score : 0) : undefined,
|
|
945
|
-
mutatedPromptText,
|
|
946
|
-
originalPromptText,
|
|
947
|
-
criteriaScores: extracted.criteriaScores,
|
|
948
|
-
datasetResults: extracted.datasetResults,
|
|
949
|
-
failureModes: extracted.failureModes,
|
|
950
|
-
mutations: extracted.mutations,
|
|
951
|
-
evaluationDetails: extracted.evaluationDetails,
|
|
952
|
-
...scorecardDigest ? { scorecard: scorecardDigest } : {}
|
|
953
|
-
};
|
|
954
|
-
} catch (error) {
|
|
955
|
-
this.handleError(error);
|
|
956
|
-
}
|
|
957
|
-
}
|
|
958
429
|
async listAgents(filters) {
|
|
959
430
|
try {
|
|
960
431
|
const response = await this.sdk.agents.listAgents({
|
|
@@ -1062,42 +533,6 @@ class SDKClientWrapper {
|
|
|
1062
533
|
this.handleError(error);
|
|
1063
534
|
}
|
|
1064
535
|
}
|
|
1065
|
-
async executePrompt(promptId, input, options) {
|
|
1066
|
-
try {
|
|
1067
|
-
return await this.request(`/api/prompt/${promptId}/playground/call`, {
|
|
1068
|
-
method: "POST",
|
|
1069
|
-
body: JSON.stringify({ input, model: options?.model })
|
|
1070
|
-
});
|
|
1071
|
-
} catch (error) {
|
|
1072
|
-
this.handleError(error);
|
|
1073
|
-
}
|
|
1074
|
-
}
|
|
1075
|
-
async executePromptStream(promptId, input, options) {
|
|
1076
|
-
const response = await fetch(`${this.endpoint}/api/prompt/${promptId}/execute/stream`, {
|
|
1077
|
-
method: "POST",
|
|
1078
|
-
headers: {
|
|
1079
|
-
"x-api-key": this.apiKey,
|
|
1080
|
-
"Content-Type": "application/json",
|
|
1081
|
-
Accept: "text/event-stream"
|
|
1082
|
-
},
|
|
1083
|
-
body: JSON.stringify({ input, ...options })
|
|
1084
|
-
});
|
|
1085
|
-
if (!response.ok) {
|
|
1086
|
-
if (response.status === 401) {
|
|
1087
|
-
throw new AuthenticationError;
|
|
1088
|
-
}
|
|
1089
|
-
if (response.status === 403) {
|
|
1090
|
-
throw new ApiError(403, await response.text() || "Access denied");
|
|
1091
|
-
}
|
|
1092
|
-
const error = await response.text();
|
|
1093
|
-
const errorLower = error.toLowerCase();
|
|
1094
|
-
if (errorLower.includes("workspace") && (errorLower.includes("missing") || errorLower.includes("required")) || errorLower.includes("x-workspace-id")) {
|
|
1095
|
-
throw new WorkspaceContextError(error);
|
|
1096
|
-
}
|
|
1097
|
-
throw new ApiError(response.status, error);
|
|
1098
|
-
}
|
|
1099
|
-
return response;
|
|
1100
|
-
}
|
|
1101
536
|
async listProviders(filters) {
|
|
1102
537
|
try {
|
|
1103
538
|
const response = await this.sdk.providerConfigs.listProviders({
|
|
@@ -1501,5 +936,5 @@ export {
|
|
|
1501
936
|
ApiError
|
|
1502
937
|
};
|
|
1503
938
|
|
|
1504
|
-
//# debugId=
|
|
939
|
+
//# debugId=19176E018FECFE2064756E2164756E21
|
|
1505
940
|
//# sourceMappingURL=index.js.map
|