raindrop-ai 0.8.0 → 0.9.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/{chunk-EWHJ2YBW.mjs → chunk-RIL2CV7Q.mjs} +1 -2
- package/dist/{chunk-EFATLUNL.mjs → chunk-UY6537WW.mjs} +359 -357
- package/dist/{chunk-22CNYHSA.mjs → chunk-VBZXQNJY.mjs} +101 -699
- package/dist/evals/cli.js +667 -1803
- package/dist/evals/cli.mjs +3 -3
- package/dist/{index-gf1epf_P.d.ts → index-DZB7DoZS.d.mts} +33354 -32553
- package/dist/{index-gf1epf_P.d.mts → index-DZB7DoZS.d.ts} +33354 -32553
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +868 -1451
- package/dist/index.mjs +5 -3
- package/dist/{portable-runtime-6X2HHB4Y.mjs → portable-runtime-F7W4STGH.mjs} +1 -1
- package/dist/tracing/index.d.mts +1 -1
- package/dist/tracing/index.d.ts +1 -1
- package/dist/tracing/index.js +1 -1
- package/dist/tracing/index.mjs +1 -1
- package/package.json +2 -2
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
POST_SHUTDOWN_TIMEOUT_MS,
|
|
9
9
|
SHUTDOWN_DEADLINE_MS,
|
|
10
10
|
authHintForKey,
|
|
11
|
-
boundedClone,
|
|
12
11
|
capText,
|
|
13
12
|
createAppGitContext,
|
|
14
13
|
currentEvalScope,
|
|
@@ -37,29 +36,28 @@ import {
|
|
|
37
36
|
withReplayTraceDestination,
|
|
38
37
|
withRoutingContext,
|
|
39
38
|
withTask
|
|
40
|
-
} from "./chunk-
|
|
39
|
+
} from "./chunk-RIL2CV7Q.mjs";
|
|
41
40
|
import {
|
|
42
41
|
CapturedTraceSnapshotSchema,
|
|
42
|
+
EvalCaseExpectationSchema,
|
|
43
43
|
EvalCaseTracePairSchema,
|
|
44
44
|
EvalDatasetCaseIdSchema,
|
|
45
45
|
EvalScoreSchema,
|
|
46
|
+
JsonValueSchema,
|
|
46
47
|
defineDataset,
|
|
47
48
|
defineEvalSuite,
|
|
48
49
|
defineEvaluatorProgram,
|
|
49
|
-
evaluatePortableEvaluator,
|
|
50
50
|
evaluatorName,
|
|
51
51
|
evaluatorOutput,
|
|
52
52
|
importPortableEvaluator,
|
|
53
53
|
isEvalDataset,
|
|
54
54
|
isEvalSuiteDefinition,
|
|
55
55
|
isPublishedEvalSuite,
|
|
56
|
-
projectCapturedEvent,
|
|
57
|
-
projectWorkshopTrace,
|
|
58
56
|
traceOutput,
|
|
59
57
|
traceToolCalls,
|
|
60
58
|
validateEvaluatorOutput,
|
|
61
59
|
verifyPortableEvalArtifact
|
|
62
|
-
} from "./chunk-
|
|
60
|
+
} from "./chunk-UY6537WW.mjs";
|
|
63
61
|
import {
|
|
64
62
|
__commonJS,
|
|
65
63
|
__toESM
|
|
@@ -755,11 +753,11 @@ var require_lodash = __commonJS({
|
|
|
755
753
|
function unicodeWords(string) {
|
|
756
754
|
return string.match(reUnicodeWord) || [];
|
|
757
755
|
}
|
|
758
|
-
var runInContext = (function runInContext2(
|
|
759
|
-
|
|
760
|
-
var Array2 =
|
|
756
|
+
var runInContext = (function runInContext2(context2) {
|
|
757
|
+
context2 = context2 == null ? root : _.defaults(root.Object(), context2, _.pick(root, contextProps));
|
|
758
|
+
var Array2 = context2.Array, Date2 = context2.Date, Error2 = context2.Error, Function2 = context2.Function, Math2 = context2.Math, Object2 = context2.Object, RegExp2 = context2.RegExp, String2 = context2.String, TypeError = context2.TypeError;
|
|
761
759
|
var arrayProto = Array2.prototype, funcProto = Function2.prototype, objectProto = Object2.prototype;
|
|
762
|
-
var coreJsData =
|
|
760
|
+
var coreJsData = context2["__core-js_shared__"];
|
|
763
761
|
var funcToString = funcProto.toString;
|
|
764
762
|
var hasOwnProperty = objectProto.hasOwnProperty;
|
|
765
763
|
var idCounter = 0;
|
|
@@ -773,7 +771,7 @@ var require_lodash = __commonJS({
|
|
|
773
771
|
var reIsNative = RegExp2(
|
|
774
772
|
"^" + funcToString.call(hasOwnProperty).replace(reRegExpChar, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$"
|
|
775
773
|
);
|
|
776
|
-
var Buffer2 = moduleExports ?
|
|
774
|
+
var Buffer2 = moduleExports ? context2.Buffer : undefined2, Symbol2 = context2.Symbol, Uint8Array2 = context2.Uint8Array, allocUnsafe = Buffer2 ? Buffer2.allocUnsafe : undefined2, getPrototype = overArg(Object2.getPrototypeOf, Object2), objectCreate = Object2.create, propertyIsEnumerable = objectProto.propertyIsEnumerable, splice = arrayProto.splice, spreadableSymbol = Symbol2 ? Symbol2.isConcatSpreadable : undefined2, symIterator = Symbol2 ? Symbol2.iterator : undefined2, symToStringTag = Symbol2 ? Symbol2.toStringTag : undefined2;
|
|
777
775
|
var defineProperty = (function() {
|
|
778
776
|
try {
|
|
779
777
|
var func = getNative(Object2, "defineProperty");
|
|
@@ -782,9 +780,9 @@ var require_lodash = __commonJS({
|
|
|
782
780
|
} catch (e) {
|
|
783
781
|
}
|
|
784
782
|
})();
|
|
785
|
-
var ctxClearTimeout =
|
|
786
|
-
var nativeCeil = Math2.ceil, nativeFloor = Math2.floor, nativeGetSymbols = Object2.getOwnPropertySymbols, nativeIsBuffer = Buffer2 ? Buffer2.isBuffer : undefined2, nativeIsFinite =
|
|
787
|
-
var DataView = getNative(
|
|
783
|
+
var ctxClearTimeout = context2.clearTimeout !== root.clearTimeout && context2.clearTimeout, ctxNow = Date2 && Date2.now !== root.Date.now && Date2.now, ctxSetTimeout = context2.setTimeout !== root.setTimeout && context2.setTimeout;
|
|
784
|
+
var nativeCeil = Math2.ceil, nativeFloor = Math2.floor, nativeGetSymbols = Object2.getOwnPropertySymbols, nativeIsBuffer = Buffer2 ? Buffer2.isBuffer : undefined2, nativeIsFinite = context2.isFinite, nativeJoin = arrayProto.join, nativeKeys = overArg(Object2.keys, Object2), nativeMax = Math2.max, nativeMin = Math2.min, nativeNow = Date2.now, nativeParseInt = context2.parseInt, nativeRandom = Math2.random, nativeReverse = arrayProto.reverse;
|
|
785
|
+
var DataView = getNative(context2, "DataView"), Map2 = getNative(context2, "Map"), Promise2 = getNative(context2, "Promise"), Set2 = getNative(context2, "Set"), WeakMap2 = getNative(context2, "WeakMap"), nativeCreate = getNative(Object2, "create");
|
|
788
786
|
var metaMap = WeakMap2 && new WeakMap2();
|
|
789
787
|
var realNames = {};
|
|
790
788
|
var dataViewCtorString = toSource(DataView), mapCtorString = toSource(Map2), promiseCtorString = toSource(Promise2), setCtorString = toSource(Set2), weakMapCtorString = toSource(WeakMap2);
|
|
@@ -10041,21 +10039,37 @@ var EVAL_DATASET_MAX_REQUEST_BYTES = 4 * 1024 * 1024;
|
|
|
10041
10039
|
var EVAL_DATASET_MAX_REFERENCE_BYTES = 1024 * 1024;
|
|
10042
10040
|
var EvalDatasetSlugSchema = z2.string().min(1).max(64).regex(/^[a-z0-9]+(-[a-z0-9]+)*$/);
|
|
10043
10041
|
var EvalDatasetFingerprintSchema = z2.string().regex(/^[0-9a-f]{64}$/);
|
|
10042
|
+
var EvalDatasetEventSourceSchema = z2.object({
|
|
10043
|
+
sourceEventId: z2.string().trim().min(1).max(512),
|
|
10044
|
+
sourceEventTimestamp: z2.string().datetime({ offset: true }).optional()
|
|
10045
|
+
}).strict();
|
|
10046
|
+
var EvalDatasetCaptureRefSchema = EvalDatasetEventSourceSchema.extend({
|
|
10047
|
+
id: EvalDatasetFingerprintSchema
|
|
10048
|
+
}).strict();
|
|
10049
|
+
var EvalReferenceVerdictSchema = z2.union([
|
|
10050
|
+
z2.object({ pass: z2.boolean() }).strict(),
|
|
10051
|
+
z2.object({ score: z2.number().int().min(1).max(5) }).strict(),
|
|
10052
|
+
z2.object({ value: z2.number().finite() }).strict()
|
|
10053
|
+
]);
|
|
10044
10054
|
var EvalDatasetCaseInputSchema = z2.object({
|
|
10045
10055
|
id: EvalDatasetCaseIdSchema,
|
|
10046
10056
|
name: z2.string().trim().min(1).max(200),
|
|
10047
10057
|
input: z2.string().nullable(),
|
|
10058
|
+
output: JsonValueSchema.optional(),
|
|
10048
10059
|
properties: z2.record(z2.string(), z2.string()),
|
|
10049
|
-
referenceTrace: CapturedTraceSnapshotSchema.optional()
|
|
10060
|
+
referenceTrace: CapturedTraceSnapshotSchema.optional(),
|
|
10061
|
+
referenceCapture: EvalDatasetCaptureRefSchema.optional(),
|
|
10062
|
+
expectation: EvalCaseExpectationSchema.optional(),
|
|
10063
|
+
expectedVerdict: EvalReferenceVerdictSchema.optional()
|
|
10050
10064
|
}).strict();
|
|
10051
10065
|
var EvalDatasetVersionCaseSchema = EvalDatasetCaseInputSchema.extend({
|
|
10052
10066
|
referenceTraceSha256: EvalDatasetFingerprintSchema.optional()
|
|
10053
10067
|
});
|
|
10054
|
-
var EvalDatasetCaseInputsSchema = z2.array(EvalDatasetCaseInputSchema).min(1).max(EVAL_DATASET_MAX_CASES).superRefine((cases,
|
|
10068
|
+
var EvalDatasetCaseInputsSchema = z2.array(EvalDatasetCaseInputSchema).min(1).max(EVAL_DATASET_MAX_CASES).superRefine((cases, context2) => {
|
|
10055
10069
|
const seen = /* @__PURE__ */ new Set();
|
|
10056
10070
|
for (const [index, entry] of cases.entries()) {
|
|
10057
10071
|
if (seen.has(entry.id)) {
|
|
10058
|
-
|
|
10072
|
+
context2.addIssue({
|
|
10059
10073
|
code: z2.ZodIssueCode.custom,
|
|
10060
10074
|
message: `Duplicate row id ${entry.id}`,
|
|
10061
10075
|
path: [index, "id"]
|
|
@@ -10071,6 +10085,21 @@ var PublishEvalDatasetVersionInputSchema = z2.object({
|
|
|
10071
10085
|
fingerprint: EvalDatasetFingerprintSchema,
|
|
10072
10086
|
cases: EvalDatasetCaseInputsSchema
|
|
10073
10087
|
}).strict();
|
|
10088
|
+
var CaptureEvalDatasetCaseSchema = EvalDatasetCaseInputSchema.pick({
|
|
10089
|
+
id: true,
|
|
10090
|
+
name: true,
|
|
10091
|
+
properties: true,
|
|
10092
|
+
expectation: true,
|
|
10093
|
+
expectedVerdict: true
|
|
10094
|
+
}).merge(EvalDatasetEventSourceSchema).strict();
|
|
10095
|
+
var CaptureEvalDatasetVersionInputSchema = PublishEvalDatasetVersionInputSchema.omit({
|
|
10096
|
+
cases: true,
|
|
10097
|
+
fingerprint: true
|
|
10098
|
+
}).extend({
|
|
10099
|
+
requestKey: z2.string().uuid().optional(),
|
|
10100
|
+
expectedCurrentVersionId: z2.string().uuid().nullable().optional(),
|
|
10101
|
+
cases: z2.array(CaptureEvalDatasetCaseSchema).min(1).max(EVAL_DATASET_MAX_CASES).refine((cases) => new Set(cases.map((entry) => entry.id)).size === cases.length, "Case IDs must be unique")
|
|
10102
|
+
}).strict();
|
|
10074
10103
|
var EvalDatasetIdentitySchema = z2.object({
|
|
10075
10104
|
id: z2.string().uuid(),
|
|
10076
10105
|
slug: EvalDatasetSlugSchema,
|
|
@@ -10092,9 +10121,13 @@ var EvalDatasetManifestSchema = z2.object({
|
|
|
10092
10121
|
id: true,
|
|
10093
10122
|
name: true,
|
|
10094
10123
|
input: true,
|
|
10124
|
+
output: true,
|
|
10095
10125
|
properties: true
|
|
10096
10126
|
}).extend({
|
|
10097
|
-
referenceTraceSha256: EvalDatasetFingerprintSchema.optional()
|
|
10127
|
+
referenceTraceSha256: EvalDatasetFingerprintSchema.optional(),
|
|
10128
|
+
referenceCapture: EvalDatasetCaptureRefSchema.optional(),
|
|
10129
|
+
expectation: EvalCaseExpectationSchema.optional(),
|
|
10130
|
+
expectedVerdict: EvalReferenceVerdictSchema.optional()
|
|
10098
10131
|
}))
|
|
10099
10132
|
});
|
|
10100
10133
|
function compareNanoseconds(left, right) {
|
|
@@ -10183,11 +10216,12 @@ var ReplayRowSchema = z3.object({
|
|
|
10183
10216
|
id: z3.string(),
|
|
10184
10217
|
name: z3.string(),
|
|
10185
10218
|
input: z3.string().nullable(),
|
|
10186
|
-
output:
|
|
10219
|
+
output: JsonValueSchema,
|
|
10187
10220
|
properties: z3.record(z3.string())
|
|
10188
10221
|
});
|
|
10189
10222
|
var WireEvalManifestSchema = z3.object({
|
|
10190
10223
|
dataset_id: z3.string().uuid(),
|
|
10224
|
+
dataset_version_id: z3.string().uuid().optional(),
|
|
10191
10225
|
fingerprint: z3.string().regex(/^[a-f0-9]{64}$/),
|
|
10192
10226
|
rows: z3.array(ReplayRowSchema.extend({ id: z3.string().min(1) }))
|
|
10193
10227
|
});
|
|
@@ -10273,20 +10307,20 @@ var ReplayTraceEvidenceEntrySchema = z3.object({
|
|
|
10273
10307
|
rowId: z3.string().min(1).max(512),
|
|
10274
10308
|
traceId: z3.string().regex(/^[a-f0-9]{32}$/),
|
|
10275
10309
|
spanIds: z3.array(z3.string().regex(/^[a-f0-9]{16}$/)).min(1).max(500)
|
|
10276
|
-
}).superRefine((entry,
|
|
10310
|
+
}).superRefine((entry, context2) => {
|
|
10277
10311
|
if (new Set(entry.spanIds).size !== entry.spanIds.length) {
|
|
10278
|
-
|
|
10312
|
+
context2.addIssue({
|
|
10279
10313
|
code: z3.ZodIssueCode.custom,
|
|
10280
10314
|
message: "Replay trace evidence span ids must be unique",
|
|
10281
10315
|
path: ["spanIds"]
|
|
10282
10316
|
});
|
|
10283
10317
|
}
|
|
10284
10318
|
});
|
|
10285
|
-
var ReplayTraceEvidenceSchema = z3.array(ReplayTraceEvidenceEntrySchema).superRefine((entries,
|
|
10319
|
+
var ReplayTraceEvidenceSchema = z3.array(ReplayTraceEvidenceEntrySchema).superRefine((entries, context2) => {
|
|
10286
10320
|
const seen = /* @__PURE__ */ new Set();
|
|
10287
10321
|
for (const [index, entry] of entries.entries()) {
|
|
10288
10322
|
if (seen.has(entry.rowId)) {
|
|
10289
|
-
|
|
10323
|
+
context2.addIssue({
|
|
10290
10324
|
code: z3.ZodIssueCode.custom,
|
|
10291
10325
|
message: "Replay trace evidence row ids must be unique",
|
|
10292
10326
|
path: [index, "rowId"]
|
|
@@ -10730,6 +10764,7 @@ async function readEvalManifest(client, dataset, options) {
|
|
|
10730
10764
|
}
|
|
10731
10765
|
return {
|
|
10732
10766
|
datasetId: manifest.dataset_id,
|
|
10767
|
+
datasetVersionId: manifest.dataset_version_id,
|
|
10733
10768
|
fingerprint: manifest.fingerprint,
|
|
10734
10769
|
cases: manifest.rows
|
|
10735
10770
|
};
|
|
@@ -10751,7 +10786,7 @@ async function readEvalDataset(client, dataset, options) {
|
|
|
10751
10786
|
schema: EvalDatasetManifestSchema
|
|
10752
10787
|
})
|
|
10753
10788
|
);
|
|
10754
|
-
if (manifest.dataset.slug !== slug) {
|
|
10789
|
+
if (manifest.dataset.slug !== slug && manifest.dataset.id !== slug) {
|
|
10755
10790
|
throw new Error(`Raindrop eval dataset ${slug} returned mismatched dataset identity`);
|
|
10756
10791
|
}
|
|
10757
10792
|
if (versionId !== void 0 && manifest.version.id !== versionId) {
|
|
@@ -12407,15 +12442,11 @@ async function publishEvalSuite(client, definition, options = {}) {
|
|
|
12407
12442
|
const localDataset = isEvalDataset(suite.dataset) ? suite.dataset : void 0;
|
|
12408
12443
|
const slug = EvalDatasetSlugSchema.parse(localDataset ? localDataset.id : suite.dataset);
|
|
12409
12444
|
const rows = localDataset == null ? void 0 : localDataset.rows.map((row) => {
|
|
12410
|
-
if (row.output !== null) {
|
|
12411
|
-
throw new Error(
|
|
12412
|
-
"Publish reference evidence with publishEvalDataset first; a local row output is not a reference trace"
|
|
12413
|
-
);
|
|
12414
|
-
}
|
|
12415
12445
|
return EvalDatasetCaseInputSchema.parse({
|
|
12416
12446
|
id: row.id,
|
|
12417
12447
|
name: row.name,
|
|
12418
12448
|
input: row.input,
|
|
12449
|
+
output: row.output === null ? void 0 : row.output,
|
|
12419
12450
|
properties: row.properties
|
|
12420
12451
|
});
|
|
12421
12452
|
});
|
|
@@ -12462,7 +12493,7 @@ async function publishEvalSuite(client, definition, options = {}) {
|
|
|
12462
12493
|
});
|
|
12463
12494
|
return defineEvalSuite({
|
|
12464
12495
|
...suite,
|
|
12465
|
-
dataset: slug,
|
|
12496
|
+
dataset: dataset.dataset.slug,
|
|
12466
12497
|
datasetVersionId: dataset.version.id,
|
|
12467
12498
|
evaluators
|
|
12468
12499
|
});
|
|
@@ -12528,7 +12559,7 @@ var EvalSnapshotSchema = z7.object({
|
|
|
12528
12559
|
id: z7.string(),
|
|
12529
12560
|
name: z7.string(),
|
|
12530
12561
|
input: z7.string().nullable(),
|
|
12531
|
-
output:
|
|
12562
|
+
output: JsonValueSchema,
|
|
12532
12563
|
properties: z7.record(z7.string())
|
|
12533
12564
|
})
|
|
12534
12565
|
)
|
|
@@ -12688,9 +12719,6 @@ async function writeSnapshot(path, value) {
|
|
|
12688
12719
|
}
|
|
12689
12720
|
}
|
|
12690
12721
|
|
|
12691
|
-
// src/evals/run.ts
|
|
12692
|
-
import { context as context2, trace as otelTrace } from "@opentelemetry/api";
|
|
12693
|
-
|
|
12694
12722
|
// src/evals/policy.ts
|
|
12695
12723
|
function assessEvalVerdict(evaluator, verdict, resolvedOutput) {
|
|
12696
12724
|
var _a;
|
|
@@ -12732,132 +12760,10 @@ function outputMismatch(name, output) {
|
|
|
12732
12760
|
return new Error(`Raindrop evaluator ${name} expected a ${output} verdict`);
|
|
12733
12761
|
}
|
|
12734
12762
|
|
|
12735
|
-
// src/evals/workshop.ts
|
|
12736
|
-
import { z as z8 } from "zod";
|
|
12737
|
-
var WorkshopRunSchema = z8.object({
|
|
12738
|
-
id: z8.string(),
|
|
12739
|
-
event_id: z8.string().nullable(),
|
|
12740
|
-
name: z8.string().nullable(),
|
|
12741
|
-
event_name: z8.string().nullable(),
|
|
12742
|
-
user_id: z8.string().nullable(),
|
|
12743
|
-
convo_id: z8.string().nullable(),
|
|
12744
|
-
started_at: z8.number().nullable(),
|
|
12745
|
-
last_updated_at: z8.number().nullable(),
|
|
12746
|
-
metadata: z8.string().nullable(),
|
|
12747
|
-
model: z8.string().nullable(),
|
|
12748
|
-
finished: z8.number().nullable()
|
|
12749
|
-
});
|
|
12750
|
-
var WorkshopSpanSchema = z8.object({
|
|
12751
|
-
id: z8.string(),
|
|
12752
|
-
run_id: z8.string(),
|
|
12753
|
-
parent_span_id: z8.string().nullable(),
|
|
12754
|
-
name: z8.string(),
|
|
12755
|
-
span_type: z8.string().nullable(),
|
|
12756
|
-
status: z8.string().nullable(),
|
|
12757
|
-
input_payload: z8.string().nullable(),
|
|
12758
|
-
output_payload: z8.string().nullable(),
|
|
12759
|
-
start_time_ms: z8.number().nullable(),
|
|
12760
|
-
end_time_ms: z8.number().nullable(),
|
|
12761
|
-
duration_ms: z8.number().nullable(),
|
|
12762
|
-
model: z8.string().nullable(),
|
|
12763
|
-
provider: z8.string().nullable(),
|
|
12764
|
-
input_tokens: z8.number().nullable(),
|
|
12765
|
-
output_tokens: z8.number().nullable(),
|
|
12766
|
-
attributes: z8.string().nullable()
|
|
12767
|
-
});
|
|
12768
|
-
var WorkshopTraceEnvelopeSchema = z8.object({
|
|
12769
|
-
status: z8.literal("complete"),
|
|
12770
|
-
correlationId: z8.string(),
|
|
12771
|
-
traceId: z8.string(),
|
|
12772
|
-
rootSpanId: z8.string(),
|
|
12773
|
-
spanCount: z8.number().int().positive(),
|
|
12774
|
-
run: WorkshopRunSchema,
|
|
12775
|
-
spans: z8.array(WorkshopSpanSchema).min(1)
|
|
12776
|
-
});
|
|
12777
|
-
async function readWorkshopTrace(input) {
|
|
12778
|
-
if (!Number.isFinite(input.waitMs) || input.waitMs < 0)
|
|
12779
|
-
throw new Error("Workshop waitMs must be finite and non-negative");
|
|
12780
|
-
const deadlineAt = Date.now() + input.waitMs;
|
|
12781
|
-
if (input.expectedSpanIds.length === 0) {
|
|
12782
|
-
throw new Error(`Workshop trace ${input.correlationId} exported no spans`);
|
|
12783
|
-
}
|
|
12784
|
-
const url = new URL(
|
|
12785
|
-
`${credentialEndpoint(input.workshopUrl).href.replace(/\/+$/, "")}/v1/evals/traces/${encodeURIComponent(input.correlationId)}`
|
|
12786
|
-
);
|
|
12787
|
-
for (const spanId of input.expectedSpanIds) url.searchParams.append("expectedSpanId", spanId);
|
|
12788
|
-
while (true) {
|
|
12789
|
-
const response = await runWithTracingSuppressed(
|
|
12790
|
-
() => fetch(url, {
|
|
12791
|
-
redirect: "error",
|
|
12792
|
-
signal: AbortSignal.timeout(
|
|
12793
|
-
Math.min(3e4, Math.max(1, Math.ceil(deadlineAt - Date.now())))
|
|
12794
|
-
)
|
|
12795
|
-
})
|
|
12796
|
-
);
|
|
12797
|
-
if (response.ok) {
|
|
12798
|
-
const parsed = WorkshopTraceEnvelopeSchema.safeParse(await response.json());
|
|
12799
|
-
if (!parsed.success) {
|
|
12800
|
-
throw new Error(`Workshop returned an invalid completed trace: ${parsed.error.message}`);
|
|
12801
|
-
}
|
|
12802
|
-
return parsed.data;
|
|
12803
|
-
}
|
|
12804
|
-
if (response.status !== 404 && response.status !== 409) {
|
|
12805
|
-
throw new Error(
|
|
12806
|
-
`Workshop trace read failed with ${response.status}: ${await response.text()}`
|
|
12807
|
-
);
|
|
12808
|
-
}
|
|
12809
|
-
if (Date.now() >= deadlineAt) {
|
|
12810
|
-
const state = response.status === 404 ? "missing" : "incomplete";
|
|
12811
|
-
throw new Error(`Workshop trace ${input.correlationId} remained ${state}`);
|
|
12812
|
-
}
|
|
12813
|
-
await new Promise(
|
|
12814
|
-
(resolve) => setTimeout(resolve, Math.min(50, Math.max(0, deadlineAt - Date.now())))
|
|
12815
|
-
);
|
|
12816
|
-
}
|
|
12817
|
-
}
|
|
12818
|
-
async function writeWorkshopEvalRun(workshopUrl, packet) {
|
|
12819
|
-
const normalized = {
|
|
12820
|
-
...packet,
|
|
12821
|
-
cases: packet.cases.map((entry) => ({
|
|
12822
|
-
...entry,
|
|
12823
|
-
task: entry.task.state === "completed" ? { ...entry.task, output: serializableOutput(entry.task.output) } : entry.task
|
|
12824
|
-
}))
|
|
12825
|
-
};
|
|
12826
|
-
const response = await runWithTracingSuppressed(
|
|
12827
|
-
() => fetch(`${credentialEndpoint(workshopUrl).href.replace(/\/+$/, "")}/v1/evals/runs`, {
|
|
12828
|
-
method: "POST",
|
|
12829
|
-
headers: { "content-type": "application/json" },
|
|
12830
|
-
body: JSON.stringify(normalized),
|
|
12831
|
-
redirect: "error",
|
|
12832
|
-
signal: AbortSignal.timeout(3e4)
|
|
12833
|
-
})
|
|
12834
|
-
);
|
|
12835
|
-
if (!response.ok) {
|
|
12836
|
-
throw new Error(
|
|
12837
|
-
`Workshop eval result write failed with ${response.status}: ${await response.text()}`
|
|
12838
|
-
);
|
|
12839
|
-
}
|
|
12840
|
-
const body = await response.json();
|
|
12841
|
-
if (typeof body !== "object" || body === null || !("id" in body) || typeof body.id !== "string") {
|
|
12842
|
-
throw new Error("Workshop eval result write returned an invalid response");
|
|
12843
|
-
}
|
|
12844
|
-
return { id: body.id };
|
|
12845
|
-
}
|
|
12846
|
-
function serializableOutput(value) {
|
|
12847
|
-
try {
|
|
12848
|
-
const serialized = JSON.stringify(boundedClone(value, 64e3));
|
|
12849
|
-
if (serialized === void 0) return null;
|
|
12850
|
-
if (serialized.length > 64e3) return "[Output exceeds 64000 characters]";
|
|
12851
|
-
return JSON.parse(serialized);
|
|
12852
|
-
} catch (e) {
|
|
12853
|
-
return "[Output could not be serialized]";
|
|
12854
|
-
}
|
|
12855
|
-
}
|
|
12856
|
-
|
|
12857
12763
|
// src/evals/run.ts
|
|
12858
|
-
var DEFAULT_WORKSHOP_TRACE_WAIT_MS = 3e4;
|
|
12859
12764
|
function createEvalSuiteRun(client, definition, options) {
|
|
12860
12765
|
var _a;
|
|
12766
|
+
assertRaindropDestination(options.destination);
|
|
12861
12767
|
const validated = validateDefinition(definition);
|
|
12862
12768
|
const execution = bindSuite(validated, (_a = options.parameters) != null ? _a : {});
|
|
12863
12769
|
const session = createSuiteSession(client, validated, execution.run, options);
|
|
@@ -12879,66 +12785,41 @@ function bindSuite(definition, parameters) {
|
|
|
12879
12785
|
return definition.agent.start(parameters);
|
|
12880
12786
|
}
|
|
12881
12787
|
function createSuiteSession(client, validated, run, options) {
|
|
12882
|
-
if (validated.datasetVersionId &&
|
|
12788
|
+
if (validated.datasetVersionId && options.selection.dataset.version.id !== validated.datasetVersionId) {
|
|
12883
12789
|
throw new Error("Selected dataset version does not match the published suite");
|
|
12884
12790
|
}
|
|
12885
|
-
if (
|
|
12886
|
-
|
|
12887
|
-
throw new Error("Raindrop remote eval sessions require selected rows");
|
|
12888
|
-
}
|
|
12889
|
-
if (typeof validated.dataset !== "string") {
|
|
12890
|
-
throw new Error("Raindrop remote eval sessions require a dataset slug");
|
|
12891
|
-
}
|
|
12892
|
-
if (options.selection.dataset.dataset.slug !== validated.dataset) {
|
|
12893
|
-
throw new Error(
|
|
12894
|
-
`Raindrop eval ${validated.name} pinned dataset ${options.selection.dataset.dataset.slug} does not match ${validated.dataset}`
|
|
12895
|
-
);
|
|
12896
|
-
}
|
|
12897
|
-
const localEvaluators = validated.evaluators.flatMap((entry) => {
|
|
12898
|
-
const evaluator = replayEvaluator(entry);
|
|
12899
|
-
return typeof evaluator === "string" ? [] : [evaluator];
|
|
12900
|
-
});
|
|
12901
|
-
if (localEvaluators.length !== validated.evaluators.length) {
|
|
12902
|
-
throw new Error("Raindrop row-scoped eval sessions support local evaluators only");
|
|
12903
|
-
}
|
|
12904
|
-
const selection = validateRemoteSelection(validated.dataset, options.selection);
|
|
12905
|
-
if (!selection) throw new Error("Raindrop remote eval sessions require selected rows");
|
|
12906
|
-
return new RaindropRowEvalRun(
|
|
12907
|
-
client,
|
|
12908
|
-
validated,
|
|
12909
|
-
run,
|
|
12910
|
-
options.destination,
|
|
12911
|
-
options.selection.dataset,
|
|
12912
|
-
selection.rowIds,
|
|
12913
|
-
localEvaluators
|
|
12914
|
-
);
|
|
12915
|
-
}
|
|
12916
|
-
if (!isEvalDataset(validated.dataset)) {
|
|
12917
|
-
throw new Error("Workshop eval execution requires a pulled or local dataset snapshot");
|
|
12918
|
-
}
|
|
12919
|
-
credentialEndpoint(options.destination.url);
|
|
12920
|
-
const hosted = validated.evaluators.find((entry) => typeof entry.evaluator === "string");
|
|
12921
|
-
if (hosted && typeof hosted.evaluator === "string") {
|
|
12922
|
-
throw new Error(`Workshop evaluator ${hosted.evaluator} must be pulled before local execution`);
|
|
12791
|
+
if (typeof validated.dataset !== "string") {
|
|
12792
|
+
throw new Error("Raindrop eval sessions require a dataset slug");
|
|
12923
12793
|
}
|
|
12924
|
-
if (validated.
|
|
12925
|
-
(entry) => typeof entry.evaluator !== "string" && "kind" in entry.evaluator && entry.evaluator.kind === "program"
|
|
12926
|
-
)) {
|
|
12794
|
+
if (options.selection.dataset.dataset.id !== validated.dataset && options.selection.dataset.dataset.slug !== validated.dataset) {
|
|
12927
12795
|
throw new Error(
|
|
12928
|
-
|
|
12796
|
+
`Raindrop eval ${validated.name} pinned dataset ${options.selection.dataset.dataset.slug} does not match ${validated.dataset}`
|
|
12929
12797
|
);
|
|
12930
12798
|
}
|
|
12931
|
-
|
|
12799
|
+
const localEvaluators = validated.evaluators.flatMap((entry) => {
|
|
12800
|
+
const evaluator = replayEvaluator(entry);
|
|
12801
|
+
return typeof evaluator === "string" ? [] : [evaluator];
|
|
12802
|
+
});
|
|
12803
|
+
if (localEvaluators.length !== validated.evaluators.length) {
|
|
12804
|
+
throw new Error("Raindrop row-scoped eval sessions support local evaluators only");
|
|
12805
|
+
}
|
|
12806
|
+
const selection = validateRemoteSelection(validated.dataset, options.selection);
|
|
12807
|
+
if (!selection) throw new Error("Raindrop eval sessions require selected rows");
|
|
12808
|
+
return new RaindropRowEvalRun(
|
|
12932
12809
|
client,
|
|
12933
|
-
|
|
12810
|
+
validated,
|
|
12934
12811
|
run,
|
|
12935
|
-
options.destination
|
|
12812
|
+
options.destination,
|
|
12813
|
+
options.selection.dataset,
|
|
12814
|
+
selection.rowIds,
|
|
12815
|
+
localEvaluators
|
|
12936
12816
|
);
|
|
12937
12817
|
}
|
|
12938
12818
|
async function runEvalSuite(client, definition, options = {}) {
|
|
12939
|
-
var _a;
|
|
12819
|
+
var _a, _b;
|
|
12820
|
+
assertRaindropDestination((_a = options.destination) != null ? _a : { kind: "raindrop" });
|
|
12940
12821
|
const validated = validateDefinition(definition);
|
|
12941
|
-
const execution = bindSuite(validated, (
|
|
12822
|
+
const execution = bindSuite(validated, (_b = options.parameters) != null ? _b : {});
|
|
12942
12823
|
return finishWith(execution, () => runSuite(client, validated, execution.run, options));
|
|
12943
12824
|
}
|
|
12944
12825
|
async function runSuite(client, definition, run, options) {
|
|
@@ -12948,12 +12829,6 @@ async function runSuite(client, definition, run, options) {
|
|
|
12948
12829
|
if (validated.datasetVersionId && ((_b = options.selection) == null ? void 0 : _b.dataset) && options.selection.dataset.version.id !== validated.datasetVersionId) {
|
|
12949
12830
|
throw new Error("Selected dataset version does not match the published suite");
|
|
12950
12831
|
}
|
|
12951
|
-
if (destination.kind === "workshop") {
|
|
12952
|
-
if (options.runId !== void 0) throw new Error("Queued runs are only supported in Raindrop");
|
|
12953
|
-
const session = createSuiteSession(client, validated, run, { destination });
|
|
12954
|
-
await session.run({ selection: options.selection, attempt: options.attempt });
|
|
12955
|
-
return session.finish();
|
|
12956
|
-
}
|
|
12957
12832
|
const alreadyPublished = isPublishedEvalSuite(validated);
|
|
12958
12833
|
if (typeof validated.dataset === "string" && ((_c = options.selection) == null ? void 0 : _c.dataset)) {
|
|
12959
12834
|
validateRemoteSelection(validated.dataset, options.selection);
|
|
@@ -13183,328 +13058,6 @@ function replayEvaluatorsFromVerdicts(verdicts) {
|
|
|
13183
13058
|
}
|
|
13184
13059
|
return [...evaluators.values()];
|
|
13185
13060
|
}
|
|
13186
|
-
var WorkshopEvalRun = class {
|
|
13187
|
-
constructor(client, definition, runRow, destination) {
|
|
13188
|
-
this.client = client;
|
|
13189
|
-
this.definition = definition;
|
|
13190
|
-
this.runRow = runRow;
|
|
13191
|
-
this.destination = destination;
|
|
13192
|
-
this.id = randomId();
|
|
13193
|
-
this.startedAt = /* @__PURE__ */ new Date();
|
|
13194
|
-
this.completed = [];
|
|
13195
|
-
this.active = /* @__PURE__ */ new Set();
|
|
13196
|
-
this.state = "open";
|
|
13197
|
-
this.runningRows = 0;
|
|
13198
|
-
this.rowWaiters = [];
|
|
13199
|
-
}
|
|
13200
|
-
async run(options = {}) {
|
|
13201
|
-
if (this.state !== "open") throw new Error(`Raindrop eval run ${this.id} is already finishing`);
|
|
13202
|
-
const operation = this.runOnce(options);
|
|
13203
|
-
this.active.add(operation);
|
|
13204
|
-
try {
|
|
13205
|
-
return await operation;
|
|
13206
|
-
} finally {
|
|
13207
|
-
this.active.delete(operation);
|
|
13208
|
-
}
|
|
13209
|
-
}
|
|
13210
|
-
async runOnce(options) {
|
|
13211
|
-
var _a;
|
|
13212
|
-
const rows = selectLocalRows(this.definition, options.selection);
|
|
13213
|
-
const completed = await Promise.all(
|
|
13214
|
-
rows.map((row) => this.withRowPermit(() => {
|
|
13215
|
-
var _a2;
|
|
13216
|
-
return this.executeRow(row, (_a2 = options.attempt) != null ? _a2 : 0);
|
|
13217
|
-
}))
|
|
13218
|
-
);
|
|
13219
|
-
const graded = await this.applyPortableEvaluators(completed, (_a = options.attempt) != null ? _a : 0);
|
|
13220
|
-
this.completed.push(...graded);
|
|
13221
|
-
return workshopResult(
|
|
13222
|
-
this.id,
|
|
13223
|
-
this.definition.name,
|
|
13224
|
-
graded.map((entry) => entry.result)
|
|
13225
|
-
);
|
|
13226
|
-
}
|
|
13227
|
-
finish() {
|
|
13228
|
-
if (this.finishPromise) return this.finishPromise;
|
|
13229
|
-
this.state = "finishing";
|
|
13230
|
-
this.finishPromise = this.finishOnce();
|
|
13231
|
-
return this.finishPromise;
|
|
13232
|
-
}
|
|
13233
|
-
async finishOnce() {
|
|
13234
|
-
await Promise.allSettled([...this.active]);
|
|
13235
|
-
const result = workshopResult(
|
|
13236
|
-
this.id,
|
|
13237
|
-
this.definition.name,
|
|
13238
|
-
this.completed.map((entry) => entry.result)
|
|
13239
|
-
);
|
|
13240
|
-
if (this.completed.length > 0) {
|
|
13241
|
-
const packet = {
|
|
13242
|
-
schemaVersion: 1,
|
|
13243
|
-
run: {
|
|
13244
|
-
id: this.id,
|
|
13245
|
-
name: this.definition.name,
|
|
13246
|
-
destination: "workshop",
|
|
13247
|
-
startedAt: this.startedAt.toISOString(),
|
|
13248
|
-
finishedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
13249
|
-
dataset: {
|
|
13250
|
-
id: this.definition.dataset.id,
|
|
13251
|
-
name: this.definition.dataset.name,
|
|
13252
|
-
version: this.definition.dataset.version
|
|
13253
|
-
},
|
|
13254
|
-
evaluators: this.definition.evaluators.map((entry) => {
|
|
13255
|
-
if (typeof entry.evaluator === "string") {
|
|
13256
|
-
throw new Error(
|
|
13257
|
-
`Workshop evaluator ${entry.evaluator} must be pulled before local execution`
|
|
13258
|
-
);
|
|
13259
|
-
}
|
|
13260
|
-
if (isPortableEvaluator(entry.evaluator)) {
|
|
13261
|
-
return {
|
|
13262
|
-
slug: entry.evaluator.slug,
|
|
13263
|
-
name: entry.evaluator.name,
|
|
13264
|
-
output: entry.evaluator.output,
|
|
13265
|
-
execution: "portable",
|
|
13266
|
-
version: entry.evaluator.artifact.evaluator.programVersion,
|
|
13267
|
-
artifactSha256: entry.evaluator.artifact.sha256,
|
|
13268
|
-
scope: entry.evaluator.scope,
|
|
13269
|
-
threshold: entry.threshold
|
|
13270
|
-
};
|
|
13271
|
-
}
|
|
13272
|
-
return {
|
|
13273
|
-
slug: entry.evaluator.slug,
|
|
13274
|
-
name: entry.evaluator.name,
|
|
13275
|
-
output: entry.evaluator.output,
|
|
13276
|
-
execution: "local",
|
|
13277
|
-
scope: entry.evaluator.scope === "row" ? "case" : entry.evaluator.scope,
|
|
13278
|
-
threshold: entry.threshold
|
|
13279
|
-
};
|
|
13280
|
-
})
|
|
13281
|
-
},
|
|
13282
|
-
cases: this.completed.map((entry) => entry.packet)
|
|
13283
|
-
};
|
|
13284
|
-
await writeWorkshopEvalRun(this.destination.url, packet);
|
|
13285
|
-
}
|
|
13286
|
-
this.state = "finished";
|
|
13287
|
-
return result;
|
|
13288
|
-
}
|
|
13289
|
-
async executeRow(row, attempt) {
|
|
13290
|
-
var _a, _b, _c;
|
|
13291
|
-
const correlationId = randomId();
|
|
13292
|
-
const exportedSpanIds = /* @__PURE__ */ new Set();
|
|
13293
|
-
const startedAt = Date.now();
|
|
13294
|
-
let completedAgent;
|
|
13295
|
-
let taskError;
|
|
13296
|
-
try {
|
|
13297
|
-
const destination = {
|
|
13298
|
-
kind: "workshop",
|
|
13299
|
-
url: this.destination.url,
|
|
13300
|
-
exportedSpanIds
|
|
13301
|
-
};
|
|
13302
|
-
const value = await withReplayTraceDestination(
|
|
13303
|
-
destination,
|
|
13304
|
-
() => withEvalScope(
|
|
13305
|
-
{ correlationId },
|
|
13306
|
-
() => this.client.tracer().withSpan(
|
|
13307
|
-
{
|
|
13308
|
-
name: "raindrop.eval.case",
|
|
13309
|
-
properties: {
|
|
13310
|
-
"raindrop.eval.run_id": this.id,
|
|
13311
|
-
"raindrop.eval.case_id": row.id,
|
|
13312
|
-
"raindrop.eval.attempt": String(attempt)
|
|
13313
|
-
},
|
|
13314
|
-
inputParameters: [row],
|
|
13315
|
-
traceContent: true
|
|
13316
|
-
},
|
|
13317
|
-
() => {
|
|
13318
|
-
var _a2;
|
|
13319
|
-
const parent = (_a2 = otelTrace.getSpan(context2.active())) == null ? void 0 : _a2.spanContext();
|
|
13320
|
-
if (!parent) return this.runRow(row);
|
|
13321
|
-
return withReplayTraceDestination(
|
|
13322
|
-
{
|
|
13323
|
-
...destination,
|
|
13324
|
-
parentSpanContext: {
|
|
13325
|
-
traceIdB64: Buffer.from(parent.traceId, "hex").toString("base64"),
|
|
13326
|
-
spanIdB64: Buffer.from(parent.spanId, "hex").toString("base64"),
|
|
13327
|
-
eventId: parent.traceId
|
|
13328
|
-
}
|
|
13329
|
-
},
|
|
13330
|
-
() => this.runRow(row)
|
|
13331
|
-
);
|
|
13332
|
-
}
|
|
13333
|
-
)
|
|
13334
|
-
)
|
|
13335
|
-
);
|
|
13336
|
-
completedAgent = { value };
|
|
13337
|
-
} catch (cause) {
|
|
13338
|
-
taskError = describeError2(cause);
|
|
13339
|
-
}
|
|
13340
|
-
const durationMs = Date.now() - startedAt;
|
|
13341
|
-
const taskCompleted = completedAgent !== void 0;
|
|
13342
|
-
let trace2;
|
|
13343
|
-
let traceId = null;
|
|
13344
|
-
let traceError;
|
|
13345
|
-
try {
|
|
13346
|
-
await this.client.forceFlush();
|
|
13347
|
-
const envelope = await readWorkshopTrace({
|
|
13348
|
-
workshopUrl: this.destination.url,
|
|
13349
|
-
correlationId,
|
|
13350
|
-
waitMs: (_a = this.definition.traceWaitMs) != null ? _a : DEFAULT_WORKSHOP_TRACE_WAIT_MS,
|
|
13351
|
-
expectedSpanIds: [...exportedSpanIds]
|
|
13352
|
-
});
|
|
13353
|
-
traceId = envelope.traceId;
|
|
13354
|
-
trace2 = canonicalWorkshopTrace(envelope);
|
|
13355
|
-
} catch (cause) {
|
|
13356
|
-
traceError = describeError2(cause);
|
|
13357
|
-
}
|
|
13358
|
-
const verdicts = [];
|
|
13359
|
-
if (completedAgent && !traceError && trace2) {
|
|
13360
|
-
const agentResult = completedAgent.value;
|
|
13361
|
-
await Promise.all(
|
|
13362
|
-
this.definition.evaluators.map(async (entry) => {
|
|
13363
|
-
if (typeof entry.evaluator === "string") return;
|
|
13364
|
-
if (isPortableEvaluator(entry.evaluator)) return;
|
|
13365
|
-
if ("kind" in entry.evaluator && entry.evaluator.kind === "program") return;
|
|
13366
|
-
try {
|
|
13367
|
-
const verdict = parseLocalVerdict2(
|
|
13368
|
-
entry.evaluator.output,
|
|
13369
|
-
await entry.evaluator.judge({ trace: trace2, row, result: agentResult })
|
|
13370
|
-
);
|
|
13371
|
-
verdicts.push(
|
|
13372
|
-
withVerdictIdentity(entry.evaluator.slug, this.id, this.destination.url, verdict)
|
|
13373
|
-
);
|
|
13374
|
-
} catch (cause) {
|
|
13375
|
-
verdicts.push({
|
|
13376
|
-
evaluator: entry.evaluator.slug,
|
|
13377
|
-
runId: this.id,
|
|
13378
|
-
url: workshopEvalUrl(this.destination.url, this.id),
|
|
13379
|
-
state: "errored",
|
|
13380
|
-
message: describeError2(cause)
|
|
13381
|
-
});
|
|
13382
|
-
}
|
|
13383
|
-
})
|
|
13384
|
-
);
|
|
13385
|
-
}
|
|
13386
|
-
if (taskCompleted && traceError) {
|
|
13387
|
-
for (const entry of this.definition.evaluators) {
|
|
13388
|
-
if (typeof entry.evaluator === "string") continue;
|
|
13389
|
-
verdicts.push({
|
|
13390
|
-
evaluator: entry.evaluator.slug,
|
|
13391
|
-
runId: this.id,
|
|
13392
|
-
url: workshopEvalUrl(this.destination.url, this.id),
|
|
13393
|
-
state: "ungraded",
|
|
13394
|
-
reason: "trace unavailable"
|
|
13395
|
-
});
|
|
13396
|
-
}
|
|
13397
|
-
}
|
|
13398
|
-
const assessments = verdicts.map((verdict) => {
|
|
13399
|
-
const evaluator = this.definition.evaluators.find(
|
|
13400
|
-
(entry) => evaluatorName(entry) === verdict.evaluator
|
|
13401
|
-
);
|
|
13402
|
-
if (!evaluator)
|
|
13403
|
-
throw new Error(`Raindrop eval result included unknown evaluator ${verdict.evaluator}`);
|
|
13404
|
-
return assessEvalVerdict(evaluator, verdict, evaluatorOutput(evaluator));
|
|
13405
|
-
});
|
|
13406
|
-
const error = (_b = taskError != null ? taskError : traceError) != null ? _b : null;
|
|
13407
|
-
const result = {
|
|
13408
|
-
...row,
|
|
13409
|
-
attempt,
|
|
13410
|
-
status: error ? "missing" : "done",
|
|
13411
|
-
traceId,
|
|
13412
|
-
error,
|
|
13413
|
-
verdicts: assessments
|
|
13414
|
-
};
|
|
13415
|
-
const packet = {
|
|
13416
|
-
caseId: row.id,
|
|
13417
|
-
caseName: row.name,
|
|
13418
|
-
input: row.input,
|
|
13419
|
-
...row.output === null ? {} : { expected: row.output },
|
|
13420
|
-
attempt,
|
|
13421
|
-
traceId,
|
|
13422
|
-
...taskCompleted && traceError ? { traceError } : {},
|
|
13423
|
-
task: taskError ? { state: "failed", error: taskError, durationMs } : { state: "completed", output: (_c = completedAgent == null ? void 0 : completedAgent.value) != null ? _c : null, durationMs },
|
|
13424
|
-
verdicts: verdicts.map(workshopVerdict),
|
|
13425
|
-
passed: error === null && assessments.every(
|
|
13426
|
-
(assessment) => assessment.state === "passed" || assessment.state === "measurement"
|
|
13427
|
-
)
|
|
13428
|
-
};
|
|
13429
|
-
return { result, packet, trace: trace2 };
|
|
13430
|
-
}
|
|
13431
|
-
async withRowPermit(run) {
|
|
13432
|
-
var _a;
|
|
13433
|
-
const limit = (_a = this.definition.concurrency) != null ? _a : 4;
|
|
13434
|
-
if (this.runningRows >= limit) {
|
|
13435
|
-
await new Promise((resolve) => this.rowWaiters.push(resolve));
|
|
13436
|
-
} else {
|
|
13437
|
-
this.runningRows += 1;
|
|
13438
|
-
}
|
|
13439
|
-
try {
|
|
13440
|
-
return await run();
|
|
13441
|
-
} finally {
|
|
13442
|
-
const next = this.rowWaiters.shift();
|
|
13443
|
-
if (next) next();
|
|
13444
|
-
else this.runningRows -= 1;
|
|
13445
|
-
}
|
|
13446
|
-
}
|
|
13447
|
-
async applyPortableEvaluators(completed, attempt) {
|
|
13448
|
-
let current = completed;
|
|
13449
|
-
for (const entry of this.definition.evaluators) {
|
|
13450
|
-
if (typeof entry.evaluator === "string" || !isPortableEvaluator(entry.evaluator)) continue;
|
|
13451
|
-
const portableEvaluator = entry.evaluator;
|
|
13452
|
-
const traces = current.flatMap(
|
|
13453
|
-
(item) => item.packet.task.state === "completed" && item.trace ? [item.trace] : []
|
|
13454
|
-
);
|
|
13455
|
-
if (traces.length === 0) continue;
|
|
13456
|
-
let outcomes;
|
|
13457
|
-
try {
|
|
13458
|
-
const portable = await evaluatePortableEvaluator(portableEvaluator, {
|
|
13459
|
-
traces,
|
|
13460
|
-
seed: `${this.id}:${attempt}:${portableEvaluator.slug}`
|
|
13461
|
-
});
|
|
13462
|
-
const programFailure = portable.failures.join("; ");
|
|
13463
|
-
outcomes = new Map(
|
|
13464
|
-
portable.outcomes.map((outcome) => [
|
|
13465
|
-
outcome.traceId,
|
|
13466
|
-
programFailure ? {
|
|
13467
|
-
state: "errored",
|
|
13468
|
-
traceId: outcome.traceId,
|
|
13469
|
-
message: programFailure
|
|
13470
|
-
} : outcome
|
|
13471
|
-
])
|
|
13472
|
-
);
|
|
13473
|
-
} catch (cause) {
|
|
13474
|
-
const message = describeError2(cause);
|
|
13475
|
-
outcomes = new Map(
|
|
13476
|
-
traces.map((trace2) => [
|
|
13477
|
-
trace2.event.id,
|
|
13478
|
-
{ state: "errored", traceId: trace2.event.id, message }
|
|
13479
|
-
])
|
|
13480
|
-
);
|
|
13481
|
-
}
|
|
13482
|
-
current = current.map((item) => {
|
|
13483
|
-
if (item.packet.task.state !== "completed" || !item.trace) return item;
|
|
13484
|
-
const outcome = outcomes.get(item.trace.event.id);
|
|
13485
|
-
if (!outcome) return item;
|
|
13486
|
-
const verdict = portableVerdict(
|
|
13487
|
-
portableEvaluator.slug,
|
|
13488
|
-
this.id,
|
|
13489
|
-
this.destination.url,
|
|
13490
|
-
outcome
|
|
13491
|
-
);
|
|
13492
|
-
const assessment = assessEvalVerdict(entry, verdict, portableEvaluator.output);
|
|
13493
|
-
const verdicts = [...item.result.verdicts, assessment];
|
|
13494
|
-
return {
|
|
13495
|
-
...item,
|
|
13496
|
-
result: { ...item.result, verdicts },
|
|
13497
|
-
packet: {
|
|
13498
|
-
...item.packet,
|
|
13499
|
-
verdicts: [...item.packet.verdicts, workshopVerdict(verdict)],
|
|
13500
|
-
passed: item.packet.passed && (assessment.state === "passed" || assessment.state === "measurement")
|
|
13501
|
-
}
|
|
13502
|
-
};
|
|
13503
|
-
});
|
|
13504
|
-
}
|
|
13505
|
-
return current;
|
|
13506
|
-
}
|
|
13507
|
-
};
|
|
13508
13061
|
async function runRaindropEval(client, definition, run, destination, options) {
|
|
13509
13062
|
var _a, _b, _c, _d;
|
|
13510
13063
|
if (typeof definition.dataset !== "string") {
|
|
@@ -13517,7 +13070,7 @@ async function runRaindropEval(client, definition, run, destination, options) {
|
|
|
13517
13070
|
queryUrl: destination.queryUrl,
|
|
13518
13071
|
versionId: definition.datasetVersionId
|
|
13519
13072
|
}) : void 0;
|
|
13520
|
-
if (pinnedDataset && pinnedDataset.dataset.slug !== datasetReference) {
|
|
13073
|
+
if (pinnedDataset && pinnedDataset.dataset.id !== datasetReference && pinnedDataset.dataset.slug !== datasetReference) {
|
|
13521
13074
|
throw new Error(
|
|
13522
13075
|
`Raindrop eval ${definition.name} pinned dataset ${pinnedDataset.dataset.slug} does not match ${datasetReference}`
|
|
13523
13076
|
);
|
|
@@ -13646,20 +13199,6 @@ function validateDefinition(definition) {
|
|
|
13646
13199
|
throw new Error("Raindrop runEvalSuite requires a definition created by defineEvalSuite");
|
|
13647
13200
|
return definition;
|
|
13648
13201
|
}
|
|
13649
|
-
function selectLocalRows(definition, selection) {
|
|
13650
|
-
if (!selection) return definition.dataset.rows;
|
|
13651
|
-
if (selection.rowIds.length === 0)
|
|
13652
|
-
throw new Error(`Raindrop eval ${definition.name} selection cannot be empty`);
|
|
13653
|
-
if (new Set(selection.rowIds).size !== selection.rowIds.length)
|
|
13654
|
-
throw new Error(`Raindrop eval ${definition.name} selection row ids must be unique`);
|
|
13655
|
-
const byId = new Map(definition.dataset.rows.map((row) => [row.id, row]));
|
|
13656
|
-
return selection.rowIds.map((id) => {
|
|
13657
|
-
const row = byId.get(id);
|
|
13658
|
-
if (!row)
|
|
13659
|
-
throw new Error(`Raindrop eval ${definition.name} selection contains unknown row ${id}`);
|
|
13660
|
-
return row;
|
|
13661
|
-
});
|
|
13662
|
-
}
|
|
13663
13202
|
function validateRemoteSelection(dataset, selection) {
|
|
13664
13203
|
var _a;
|
|
13665
13204
|
if (!selection) return void 0;
|
|
@@ -13675,157 +13214,20 @@ function validateRemoteSelection(dataset, selection) {
|
|
|
13675
13214
|
throw new Error(`Raindrop eval ${dataset} selection contains unknown row ${unknown}`);
|
|
13676
13215
|
return { rowIds: selection.rowIds };
|
|
13677
13216
|
}
|
|
13678
|
-
function canonicalWorkshopTrace(envelope) {
|
|
13679
|
-
var _a, _b, _c, _d, _e, _f;
|
|
13680
|
-
const spans = envelope.spans.map(rawTraceSpan);
|
|
13681
|
-
const timestamp = new Date((_a = envelope.run.started_at) != null ? _a : Date.now()).toISOString();
|
|
13682
|
-
const event = projectCapturedEvent({
|
|
13683
|
-
eventId: (_b = envelope.run.event_id) != null ? _b : envelope.traceId,
|
|
13684
|
-
internalEventId: envelope.run.id,
|
|
13685
|
-
name: (_d = (_c = envelope.run.event_name) != null ? _c : envelope.run.name) != null ? _d : "ai_generation",
|
|
13686
|
-
timestamp,
|
|
13687
|
-
receivedAt: new Date((_e = envelope.run.last_updated_at) != null ? _e : Date.now()).toISOString(),
|
|
13688
|
-
userId: (_f = envelope.run.user_id) != null ? _f : "local-eval",
|
|
13689
|
-
convoId: envelope.run.convo_id,
|
|
13690
|
-
properties: parseAttributes(envelope.run.metadata),
|
|
13691
|
-
spans
|
|
13692
|
-
});
|
|
13693
|
-
return projectWorkshopTrace({ origin: "replay", event, spans });
|
|
13694
|
-
}
|
|
13695
|
-
function rawTraceSpan(span) {
|
|
13696
|
-
var _a, _b, _c, _d, _e, _f;
|
|
13697
|
-
const attributes = parseAttributes(span.attributes);
|
|
13698
|
-
return {
|
|
13699
|
-
span_id: span.id,
|
|
13700
|
-
parent_span_id: (_a = span.parent_span_id) != null ? _a : void 0,
|
|
13701
|
-
span_name: span.name,
|
|
13702
|
-
span_type: (_b = span.span_type) != null ? _b : void 0,
|
|
13703
|
-
status: (_c = span.status) != null ? _c : void 0,
|
|
13704
|
-
duration_ns: span.duration_ms === null ? void 0 : span.duration_ms * 1e6,
|
|
13705
|
-
start_unix_ns: span.start_time_ms === null ? void 0 : span.start_time_ms * 1e6,
|
|
13706
|
-
model: (_d = span.model) != null ? _d : void 0,
|
|
13707
|
-
input_tokens: (_e = span.input_tokens) != null ? _e : void 0,
|
|
13708
|
-
output_tokens: (_f = span.output_tokens) != null ? _f : void 0,
|
|
13709
|
-
input_payload: span.input_payload,
|
|
13710
|
-
output_payload: span.output_payload,
|
|
13711
|
-
attributes_string: Object.fromEntries(
|
|
13712
|
-
Object.entries(attributes).filter(
|
|
13713
|
-
(entry) => typeof entry[1] === "string"
|
|
13714
|
-
)
|
|
13715
|
-
),
|
|
13716
|
-
attributes_num: Object.fromEntries(
|
|
13717
|
-
Object.entries(attributes).filter(
|
|
13718
|
-
(entry) => typeof entry[1] === "number"
|
|
13719
|
-
)
|
|
13720
|
-
)
|
|
13721
|
-
};
|
|
13722
|
-
}
|
|
13723
|
-
function parseAttributes(raw) {
|
|
13724
|
-
if (!raw) return {};
|
|
13725
|
-
try {
|
|
13726
|
-
const value = JSON.parse(raw);
|
|
13727
|
-
return isAttributeRecord(value) ? value : {};
|
|
13728
|
-
} catch (e) {
|
|
13729
|
-
return {};
|
|
13730
|
-
}
|
|
13731
|
-
}
|
|
13732
|
-
function isAttributeRecord(value) {
|
|
13733
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13734
|
-
}
|
|
13735
|
-
function parseLocalVerdict2(output, value) {
|
|
13736
|
-
if (output === "boolean") return { state: "graded", ...LocalBooleanVerdictSchema.parse(value) };
|
|
13737
|
-
if (output === "score") return { state: "graded", ...LocalScoreVerdictSchema.parse(value) };
|
|
13738
|
-
return { state: "graded", ...LocalNumberVerdictSchema.parse(value) };
|
|
13739
|
-
}
|
|
13740
|
-
function withVerdictIdentity(evaluator, runId, workshopUrl, verdict) {
|
|
13741
|
-
return {
|
|
13742
|
-
evaluator,
|
|
13743
|
-
runId,
|
|
13744
|
-
url: workshopEvalUrl(workshopUrl, runId),
|
|
13745
|
-
...verdict
|
|
13746
|
-
};
|
|
13747
|
-
}
|
|
13748
|
-
function workshopVerdict(assessment) {
|
|
13749
|
-
const { evaluator, state } = assessment;
|
|
13750
|
-
if (state === "errored") return { evaluator, state, message: assessment.message };
|
|
13751
|
-
if (state === "ungraded") return { evaluator, state, reason: assessment.reason };
|
|
13752
|
-
if ("pass" in assessment)
|
|
13753
|
-
return {
|
|
13754
|
-
evaluator,
|
|
13755
|
-
state,
|
|
13756
|
-
pass: assessment.pass,
|
|
13757
|
-
...assessment.note ? { note: assessment.note } : {}
|
|
13758
|
-
};
|
|
13759
|
-
if ("score" in assessment)
|
|
13760
|
-
return {
|
|
13761
|
-
evaluator,
|
|
13762
|
-
state,
|
|
13763
|
-
score: assessment.score,
|
|
13764
|
-
...assessment.note ? { note: assessment.note } : {}
|
|
13765
|
-
};
|
|
13766
|
-
return {
|
|
13767
|
-
evaluator,
|
|
13768
|
-
state,
|
|
13769
|
-
value: assessment.value,
|
|
13770
|
-
...assessment.note ? { note: assessment.note } : {}
|
|
13771
|
-
};
|
|
13772
|
-
}
|
|
13773
|
-
function portableVerdict(evaluator, runId, workshopUrl, outcome) {
|
|
13774
|
-
const identity = { evaluator, runId, url: workshopEvalUrl(workshopUrl, runId) };
|
|
13775
|
-
if (outcome.state === "errored") {
|
|
13776
|
-
return { ...identity, state: outcome.state, message: outcome.message };
|
|
13777
|
-
}
|
|
13778
|
-
if (outcome.state === "ungraded") {
|
|
13779
|
-
return { ...identity, state: outcome.state, reason: outcome.reason };
|
|
13780
|
-
}
|
|
13781
|
-
if ("pass" in outcome)
|
|
13782
|
-
return {
|
|
13783
|
-
...identity,
|
|
13784
|
-
state: outcome.state,
|
|
13785
|
-
pass: outcome.pass,
|
|
13786
|
-
...outcome.note ? { note: outcome.note } : {}
|
|
13787
|
-
};
|
|
13788
|
-
if ("score" in outcome)
|
|
13789
|
-
return {
|
|
13790
|
-
...identity,
|
|
13791
|
-
state: outcome.state,
|
|
13792
|
-
score: outcome.score,
|
|
13793
|
-
...outcome.note ? { note: outcome.note } : {}
|
|
13794
|
-
};
|
|
13795
|
-
return {
|
|
13796
|
-
...identity,
|
|
13797
|
-
state: outcome.state,
|
|
13798
|
-
value: outcome.value,
|
|
13799
|
-
...outcome.note ? { note: outcome.note } : {}
|
|
13800
|
-
};
|
|
13801
|
-
}
|
|
13802
|
-
function workshopResult(id, name, rows) {
|
|
13803
|
-
const done = rows.filter((entry) => entry.status === "done").length;
|
|
13804
|
-
const missing = rows.filter((entry) => entry.status === "missing").length;
|
|
13805
|
-
return {
|
|
13806
|
-
runId: id,
|
|
13807
|
-
name,
|
|
13808
|
-
status: missing > 0 ? "failed" : "complete",
|
|
13809
|
-
counts: { total: rows.length, pending: 0, done, missing },
|
|
13810
|
-
tracesExpireAt: null,
|
|
13811
|
-
tracesExpired: false,
|
|
13812
|
-
evaluators: [],
|
|
13813
|
-
rows
|
|
13814
|
-
};
|
|
13815
|
-
}
|
|
13816
|
-
function workshopEvalUrl(baseUrl, id) {
|
|
13817
|
-
return `${baseUrl.replace(/\/+$/, "")}/evals/${encodeURIComponent(id)}`;
|
|
13818
|
-
}
|
|
13819
13217
|
function randomId() {
|
|
13820
13218
|
var _a, _b, _c;
|
|
13821
13219
|
return (_c = (_b = (_a = globalThis.crypto) == null ? void 0 : _a.randomUUID) == null ? void 0 : _b.call(_a)) != null ? _c : `eval-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
13822
13220
|
}
|
|
13823
|
-
function describeError2(cause) {
|
|
13824
|
-
return cause instanceof Error ? cause.message : String(cause);
|
|
13825
|
-
}
|
|
13826
13221
|
function isPortableEvaluator(value) {
|
|
13827
13222
|
return "kind" in value && value.kind === "portable";
|
|
13828
13223
|
}
|
|
13224
|
+
function assertRaindropDestination(destination) {
|
|
13225
|
+
if (destination.kind !== "raindrop") {
|
|
13226
|
+
throw new Error(
|
|
13227
|
+
"Eval runs store results in Raindrop; Workshop is no longer an eval destination"
|
|
13228
|
+
);
|
|
13229
|
+
}
|
|
13230
|
+
}
|
|
13829
13231
|
|
|
13830
13232
|
// src/index.ts
|
|
13831
13233
|
function rawAppGitProperties(properties) {
|
|
@@ -14293,14 +13695,14 @@ var Raindrop = class {
|
|
|
14293
13695
|
const description = buildSelfDiagnosticsDescription(signals, options.guidance);
|
|
14294
13696
|
const inputSchema = buildSelfDiagnosticsInputSchema(signalKeys);
|
|
14295
13697
|
const onMissingEventId = (_b = options.onMissingEventId) != null ? _b : "warn";
|
|
14296
|
-
const execute = async (rawInput,
|
|
13698
|
+
const execute = async (rawInput, context2) => {
|
|
14297
13699
|
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
14298
13700
|
const input = isRecord(rawInput) ? rawInput : void 0;
|
|
14299
13701
|
const fallbackCategory = (_a2 = signalKeys[0]) != null ? _a2 : "unknown";
|
|
14300
13702
|
const categoryCandidate = normalizeEventId(input == null ? void 0 : input["category"]);
|
|
14301
13703
|
const category = categoryCandidate && signalKeySet.has(categoryCandidate) ? categoryCandidate : fallbackCategory;
|
|
14302
13704
|
const detail = (_b2 = normalizeEventId(input == null ? void 0 : input["detail"])) != null ? _b2 : "";
|
|
14303
|
-
const eventId = (_l = (_k = (_i = (_g = (_f = (_e = (_d = normalizeEventId(
|
|
13705
|
+
const eventId = (_l = (_k = (_i = (_g = (_f = (_e = (_d = normalizeEventId(context2 == null ? void 0 : context2.eventId)) != null ? _d : (_c = context2 == null ? void 0 : context2.interaction) == null ? void 0 : _c.getEventId()) != null ? _e : resolveEventIdFromMetadata(context2 == null ? void 0 : context2.metadata)) != null ? _f : normalizeEventId(input == null ? void 0 : input["event_id"])) != null ? _g : normalizeEventId(input == null ? void 0 : input["eventId"])) != null ? _i : (_h = options.interaction) == null ? void 0 : _h.getEventId()) != null ? _k : (_j = options.getEventId) == null ? void 0 : _j.call(options)) != null ? _l : normalizeEventId(options.eventId);
|
|
14304
13706
|
if (!eventId) {
|
|
14305
13707
|
const message = "self diagnostics signal skipped: missing eventId. Pass eventId, interaction, or getEventId when creating or executing the tool.";
|
|
14306
13708
|
if (onMissingEventId === "throw") {
|
|
@@ -14318,11 +13720,11 @@ var Raindrop = class {
|
|
|
14318
13720
|
type: "agent",
|
|
14319
13721
|
sentiment: signalDefinition == null ? void 0 : signalDefinition.sentiment,
|
|
14320
13722
|
properties: {
|
|
14321
|
-
source: (
|
|
13723
|
+
source: (context2 == null ? void 0 : context2.source) || options.source || SELF_DIAGNOSTICS_SOURCE_DEFAULT,
|
|
14322
13724
|
category,
|
|
14323
13725
|
signal_description: signalDefinition == null ? void 0 : signalDefinition.description,
|
|
14324
13726
|
...detail ? { detail } : {},
|
|
14325
|
-
...(_m =
|
|
13727
|
+
...(_m = context2 == null ? void 0 : context2.properties) != null ? _m : {}
|
|
14326
13728
|
}
|
|
14327
13729
|
});
|
|
14328
13730
|
return { acknowledged: true, category, eventId };
|
|
@@ -14728,7 +14130,7 @@ var Raindrop = class {
|
|
|
14728
14130
|
}
|
|
14729
14131
|
getContext() {
|
|
14730
14132
|
const runtime = detectRuntime();
|
|
14731
|
-
const
|
|
14133
|
+
const context2 = {
|
|
14732
14134
|
library: {
|
|
14733
14135
|
name: package_default.name,
|
|
14734
14136
|
version: package_default.version
|
|
@@ -14738,9 +14140,9 @@ var Raindrop = class {
|
|
|
14738
14140
|
}
|
|
14739
14141
|
};
|
|
14740
14142
|
if (runtime === "node") {
|
|
14741
|
-
|
|
14143
|
+
context2.metadata.nodeVersion = process.version;
|
|
14742
14144
|
}
|
|
14743
|
-
return
|
|
14145
|
+
return context2;
|
|
14744
14146
|
}
|
|
14745
14147
|
formatZodError(error) {
|
|
14746
14148
|
return error.issues.map((issue) => `(path: ${issue.path.join(".")}): ${issue.message}`).join(", ");
|