raindrop-ai 0.7.1 → 0.8.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.
@@ -37,7 +37,7 @@ import {
37
37
  withReplayTraceDestination,
38
38
  withRoutingContext,
39
39
  withTask
40
- } from "./chunk-SHH4SYVY.mjs";
40
+ } from "./chunk-EWHJ2YBW.mjs";
41
41
  import {
42
42
  CapturedTraceSnapshotSchema,
43
43
  EvalCaseTracePairSchema,
@@ -59,7 +59,7 @@ import {
59
59
  traceToolCalls,
60
60
  validateEvaluatorOutput,
61
61
  verifyPortableEvalArtifact
62
- } from "./chunk-RMP6BZSY.mjs";
62
+ } from "./chunk-EFATLUNL.mjs";
63
63
  import {
64
64
  __commonJS,
65
65
  __toESM
@@ -3739,7 +3739,7 @@ var require_lodash = __commonJS({
3739
3739
  if (fromIndex < 0) {
3740
3740
  fromIndex = nativeMax(length + fromIndex, 0);
3741
3741
  }
3742
- return isString(collection) ? fromIndex <= length && collection.indexOf(value, fromIndex) > -1 : !!length && baseIndexOf(collection, value, fromIndex) > -1;
3742
+ return isString2(collection) ? fromIndex <= length && collection.indexOf(value, fromIndex) > -1 : !!length && baseIndexOf(collection, value, fromIndex) > -1;
3743
3743
  }
3744
3744
  var invokeMap = baseRest(function(collection, path, args) {
3745
3745
  var index = -1, isFunc = typeof path == "function", result2 = isArrayLike(collection) ? Array2(collection.length) : [];
@@ -3807,7 +3807,7 @@ var require_lodash = __commonJS({
3807
3807
  return 0;
3808
3808
  }
3809
3809
  if (isArrayLike(collection)) {
3810
- return isString(collection) ? stringSize(collection) : collection.length;
3810
+ return isString2(collection) ? stringSize(collection) : collection.length;
3811
3811
  }
3812
3812
  var tag = getTag(collection);
3813
3813
  if (tag == mapTag || tag == setTag) {
@@ -4133,7 +4133,7 @@ var require_lodash = __commonJS({
4133
4133
  function isArrayLikeObject(value) {
4134
4134
  return isObjectLike(value) && isArrayLike(value);
4135
4135
  }
4136
- function isBoolean(value) {
4136
+ function isBoolean2(value) {
4137
4137
  return value === true || value === false || isObjectLike(value) && baseGetTag(value) == boolTag;
4138
4138
  }
4139
4139
  var isBuffer = nativeIsBuffer || stubFalse;
@@ -4209,7 +4209,7 @@ var require_lodash = __commonJS({
4209
4209
  return baseIsMatch(object, source, getMatchData(source), customizer);
4210
4210
  }
4211
4211
  function isNaN(value) {
4212
- return isNumber(value) && value != +value;
4212
+ return isNumber2(value) && value != +value;
4213
4213
  }
4214
4214
  function isNative(value) {
4215
4215
  if (isMaskable(value)) {
@@ -4223,7 +4223,7 @@ var require_lodash = __commonJS({
4223
4223
  function isNil(value) {
4224
4224
  return value == null;
4225
4225
  }
4226
- function isNumber(value) {
4226
+ function isNumber2(value) {
4227
4227
  return typeof value == "number" || isObjectLike(value) && baseGetTag(value) == numberTag;
4228
4228
  }
4229
4229
  function isPlainObject(value) {
@@ -4242,7 +4242,7 @@ var require_lodash = __commonJS({
4242
4242
  return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
4243
4243
  }
4244
4244
  var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
4245
- function isString(value) {
4245
+ function isString2(value) {
4246
4246
  return typeof value == "string" || !isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag;
4247
4247
  }
4248
4248
  function isSymbol(value) {
@@ -4267,7 +4267,7 @@ var require_lodash = __commonJS({
4267
4267
  return [];
4268
4268
  }
4269
4269
  if (isArrayLike(value)) {
4270
- return isString(value) ? stringToArray(value) : copyArray(value);
4270
+ return isString2(value) ? stringToArray(value) : copyArray(value);
4271
4271
  }
4272
4272
  if (symIterator && value[symIterator]) {
4273
4273
  return iteratorToArray(value[symIterator]());
@@ -5275,7 +5275,7 @@ var require_lodash = __commonJS({
5275
5275
  lodash.isArrayBuffer = isArrayBuffer;
5276
5276
  lodash.isArrayLike = isArrayLike;
5277
5277
  lodash.isArrayLikeObject = isArrayLikeObject;
5278
- lodash.isBoolean = isBoolean;
5278
+ lodash.isBoolean = isBoolean2;
5279
5279
  lodash.isBuffer = isBuffer;
5280
5280
  lodash.isDate = isDate;
5281
5281
  lodash.isElement = isElement;
@@ -5294,14 +5294,14 @@ var require_lodash = __commonJS({
5294
5294
  lodash.isNative = isNative;
5295
5295
  lodash.isNil = isNil;
5296
5296
  lodash.isNull = isNull;
5297
- lodash.isNumber = isNumber;
5297
+ lodash.isNumber = isNumber2;
5298
5298
  lodash.isObject = isObject;
5299
5299
  lodash.isObjectLike = isObjectLike;
5300
5300
  lodash.isPlainObject = isPlainObject;
5301
5301
  lodash.isRegExp = isRegExp;
5302
5302
  lodash.isSafeInteger = isSafeInteger;
5303
5303
  lodash.isSet = isSet;
5304
- lodash.isString = isString;
5304
+ lodash.isString = isString2;
5305
5305
  lodash.isSymbol = isSymbol;
5306
5306
  lodash.isTypedArray = isTypedArray;
5307
5307
  lodash.isUndefined = isUndefined;
@@ -6283,15 +6283,15 @@ var makeIssue = (params) => {
6283
6283
  message: issueData.message
6284
6284
  };
6285
6285
  }
6286
- let errorMessage = "";
6286
+ let errorMessage2 = "";
6287
6287
  const maps = errorMaps.filter((m) => !!m).slice().reverse();
6288
6288
  for (const map of maps) {
6289
- errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
6289
+ errorMessage2 = map(fullIssue, { data, defaultError: errorMessage2 }).message;
6290
6290
  }
6291
6291
  return {
6292
6292
  ...issueData,
6293
6293
  path: fullPath,
6294
- message: errorMessage
6294
+ message: errorMessage2
6295
6295
  };
6296
6296
  };
6297
6297
  var EMPTY_PATH = [];
@@ -10161,7 +10161,7 @@ function replayIngestEndpoint(value, trustedUrl) {
10161
10161
 
10162
10162
  // src/replay/index.ts
10163
10163
  var DEFAULT_QUERY_URL = "https://query.raindrop.ai";
10164
- var DEFAULT_TRACE_WAIT_MS = 3e4;
10164
+ var DEFAULT_TRACE_WAIT_MS = 6e4;
10165
10165
  var DEFAULT_EVAL_WAIT_MS = 10 * 6e4;
10166
10166
  var DEFAULT_EVAL_POLL_INTERVAL_MS = 2e3;
10167
10167
  var MAX_EVAL_STATUS_RETRIES = 2;
@@ -10773,6 +10773,9 @@ function validateEvalDatasetManifest(value) {
10773
10773
  async function runReplay(client, handle, options) {
10774
10774
  return (await runReplayRows(client, handle, options)).reading;
10775
10775
  }
10776
+ async function runEvalReplay(client, handle, options) {
10777
+ return runReplayRows(client, handle, options);
10778
+ }
10776
10779
  async function runReplayRows(client, handle, options) {
10777
10780
  var _a, _b, _c, _d, _e, _f, _g, _h;
10778
10781
  if (!Number.isSafeInteger((_a = options.concurrency) != null ? _a : DEFAULT_CONCURRENCY) || ((_b = options.concurrency) != null ? _b : DEFAULT_CONCURRENCY) < 1) {
@@ -10877,12 +10880,17 @@ async function runReplayRows(client, handle, options) {
10877
10880
  }
10878
10881
  }
10879
10882
  };
10880
- await Promise.all(
10883
+ const workers = await Promise.allSettled(
10881
10884
  Array.from(
10882
10885
  { length: Math.min((_f = options.concurrency) != null ? _f : DEFAULT_CONCURRENCY, rows.length) },
10883
10886
  () => worker()
10884
10887
  )
10885
10888
  );
10889
+ const failures = workers.flatMap(
10890
+ (result) => result.status === "rejected" ? [result.reason] : []
10891
+ );
10892
+ if (failures.length === 1) throw failures[0];
10893
+ if (failures.length > 1) throw new AggregateError(failures, "Replay row execution failed");
10886
10894
  await client.forceFlush();
10887
10895
  const traceEvidence = [];
10888
10896
  for (const row of rows) {
@@ -11866,6 +11874,253 @@ function describeError(cause) {
11866
11874
  return String(cause);
11867
11875
  }
11868
11876
 
11877
+ // src/evals/agent.ts
11878
+ import { z as z4 } from "zod";
11879
+ var EvalParameterError = class extends Error {
11880
+ constructor(agent, issues) {
11881
+ super(
11882
+ `Invalid parameters for agent ${agent}: ${issues.map((issue) => `${issue.path.join(".") || "parameters"} ${issue.message}`).join("; ")}`
11883
+ );
11884
+ this.name = "EvalParameterError";
11885
+ }
11886
+ };
11887
+ var AgentMetadataSchema = z4.object({
11888
+ slug: z4.string().trim().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/).max(64),
11889
+ name: z4.string().trim().min(1).max(120),
11890
+ description: z4.string().max(2e3).optional()
11891
+ });
11892
+ var PARAMETER_KEY = /^[A-Za-z_][A-Za-z0-9_]{0,63}$/;
11893
+ var MAX_PARAMETERS = 50;
11894
+ function unwrapField(schema) {
11895
+ let inner = schema;
11896
+ let description;
11897
+ while (inner instanceof z4.ZodDefault || inner instanceof z4.ZodOptional) {
11898
+ description != null ? description : description = inner.description;
11899
+ inner = inner._def.innerType;
11900
+ }
11901
+ const omitted = schema.safeParse(void 0);
11902
+ return {
11903
+ inner,
11904
+ required: !omitted.success,
11905
+ defaultValue: omitted.success ? omitted.data : void 0,
11906
+ description: description != null ? description : inner.description
11907
+ };
11908
+ }
11909
+ function fieldDefault(key, value, guard) {
11910
+ if (value === void 0) return void 0;
11911
+ if (!guard(value)) throw new Error(`Parameter ${key} has a default of the wrong type`);
11912
+ return value;
11913
+ }
11914
+ var isString = (value) => typeof value === "string";
11915
+ var isNumber = (value) => typeof value === "number";
11916
+ var isBoolean = (value) => typeof value === "boolean";
11917
+ function describeParameterField(key, schema) {
11918
+ if (!PARAMETER_KEY.test(key)) throw new Error(`Parameter key ${key} must be an identifier`);
11919
+ const { inner, required, defaultValue, description } = unwrapField(schema);
11920
+ const base = { key, required, ...description === void 0 ? {} : { description } };
11921
+ if (inner instanceof z4.ZodString) {
11922
+ const max = inner._def.checks.find((check) => check.kind === "max");
11923
+ return {
11924
+ ...base,
11925
+ type: "string",
11926
+ default: fieldDefault(key, defaultValue, isString),
11927
+ ...(max == null ? void 0 : max.kind) === "max" ? { maxLength: max.value } : {}
11928
+ };
11929
+ }
11930
+ if (inner instanceof z4.ZodNumber) {
11931
+ const { minValue, maxValue } = inner;
11932
+ return {
11933
+ ...base,
11934
+ type: "number",
11935
+ default: fieldDefault(key, defaultValue, isNumber),
11936
+ integer: inner.isInt,
11937
+ ...minValue === null ? {} : { min: minValue },
11938
+ ...maxValue === null ? {} : { max: maxValue }
11939
+ };
11940
+ }
11941
+ if (inner instanceof z4.ZodBoolean) {
11942
+ return { ...base, type: "boolean", default: fieldDefault(key, defaultValue, isBoolean) };
11943
+ }
11944
+ if (inner instanceof z4.ZodEnum) {
11945
+ const options = inner.options;
11946
+ return { ...base, type: "enum", default: fieldDefault(key, defaultValue, isString), options };
11947
+ }
11948
+ throw new Error(
11949
+ `Parameter ${key} must be a z.string(), z.number(), z.boolean(), or z.enum() schema`
11950
+ );
11951
+ }
11952
+ function defineAgent(definition) {
11953
+ var _a, _b;
11954
+ const { slug, name, description } = AgentMetadataSchema.parse({
11955
+ slug: definition.slug,
11956
+ name: (_a = definition.name) != null ? _a : definition.slug,
11957
+ description: definition.description
11958
+ });
11959
+ if (typeof definition.run !== "function") throw new Error("An agent requires a run function");
11960
+ const fields = (_b = definition.parameters) != null ? _b : {};
11961
+ const entries = Object.entries(fields);
11962
+ if (entries.length > MAX_PARAMETERS)
11963
+ throw new Error(`Agent ${slug} declares more than ${MAX_PARAMETERS} parameters`);
11964
+ const parameters = entries.map(([key, schema2]) => describeParameterField(key, schema2));
11965
+ const schema = z4.object(fields).strict();
11966
+ return {
11967
+ slug,
11968
+ name,
11969
+ description,
11970
+ parameters,
11971
+ start(input) {
11972
+ const parsed = schema.safeParse(input);
11973
+ if (!parsed.success) throw new EvalParameterError(slug, parsed.error.issues);
11974
+ return startAgent(definition, parsed.data);
11975
+ }
11976
+ };
11977
+ }
11978
+ async function finishWith(execution, work) {
11979
+ let result;
11980
+ try {
11981
+ result = await work();
11982
+ } catch (error) {
11983
+ await execution.finish().catch(() => void 0);
11984
+ throw error;
11985
+ }
11986
+ await execution.finish();
11987
+ return result;
11988
+ }
11989
+ function startAgent(definition, parameters) {
11990
+ const active = /* @__PURE__ */ new Set();
11991
+ let finishing;
11992
+ const execution = (runRow, cleanup2) => ({
11993
+ run(row) {
11994
+ if (finishing !== void 0)
11995
+ return Promise.reject(new Error(`Agent ${definition.slug} has already finished`));
11996
+ const pending = runRow(row);
11997
+ active.add(pending);
11998
+ pending.catch(() => void 0).finally(() => active.delete(pending));
11999
+ return pending;
12000
+ },
12001
+ finish: () => finishing != null ? finishing : finishing = Promise.allSettled(active).then(cleanup2)
12002
+ });
12003
+ if (definition.setup === void 0) {
12004
+ const { run: run2, cleanup: cleanup2 } = definition;
12005
+ return execution(
12006
+ (row) => Promise.resolve().then(() => run2(row, { parameters })),
12007
+ async () => {
12008
+ await (cleanup2 == null ? void 0 : cleanup2());
12009
+ }
12010
+ );
12011
+ }
12012
+ const { setup, run, cleanup } = definition;
12013
+ let environment;
12014
+ const ready = () => {
12015
+ if (environment === void 0) {
12016
+ environment = Promise.resolve().then(() => setup(parameters));
12017
+ environment.catch(() => void 0);
12018
+ }
12019
+ return environment;
12020
+ };
12021
+ return execution(
12022
+ async (row) => run(row, { parameters, environment: await ready() }),
12023
+ () => environment === void 0 ? Promise.resolve() : environment.then(
12024
+ (built) => cleanup == null ? void 0 : cleanup(built),
12025
+ () => void 0
12026
+ )
12027
+ );
12028
+ }
12029
+
12030
+ // src/evals/server.ts
12031
+ import { z as z5 } from "zod";
12032
+ var InvocationSchema = z5.object({
12033
+ runId: z5.string().uuid(),
12034
+ agent: z5.string().min(1).max(64),
12035
+ parameters: z5.record(z5.unknown()).default({})
12036
+ });
12037
+ var MAX_BODY_BYTES = 64 * 1024;
12038
+ async function parseInvocation(request) {
12039
+ var _a;
12040
+ if (Number((_a = request.headers.get("content-length")) != null ? _a : 0) > MAX_BODY_BYTES) return void 0;
12041
+ const body = await request.text().catch(() => "");
12042
+ if (new TextEncoder().encode(body).byteLength > MAX_BODY_BYTES) return void 0;
12043
+ try {
12044
+ const parsed = InvocationSchema.safeParse(JSON.parse(body));
12045
+ return parsed.success ? parsed.data : void 0;
12046
+ } catch (e) {
12047
+ return void 0;
12048
+ }
12049
+ }
12050
+ function startExecution(agent, parameters) {
12051
+ try {
12052
+ return agent.start(parameters);
12053
+ } catch (error) {
12054
+ if (error instanceof EvalParameterError)
12055
+ return Response.json({ error: error.message }, { status: 400 });
12056
+ throw error;
12057
+ }
12058
+ }
12059
+ function errorMessage(error) {
12060
+ return error instanceof Error ? error.message : "Eval execution failed";
12061
+ }
12062
+ function createEvalHandler(client, options) {
12063
+ if (options.queryUrl !== void 0) credentialEndpoint(options.queryUrl);
12064
+ if (options.replayIngestUrl !== void 0) credentialEndpoint(options.replayIngestUrl);
12065
+ const agents = new Map(options.agents.map((agent) => [agent.slug, agent]));
12066
+ if (agents.size !== options.agents.length)
12067
+ throw new Error("Registered agent slugs must be unique");
12068
+ const catalog = [...agents.values()].map(({ slug, name, description, parameters }) => ({
12069
+ slug,
12070
+ name,
12071
+ description,
12072
+ parameters
12073
+ }));
12074
+ return async (request) => {
12075
+ if (request.method === "GET") return Response.json({ agents: catalog });
12076
+ if (request.method !== "POST") {
12077
+ return Response.json(
12078
+ { error: "Method not allowed" },
12079
+ { status: 405, headers: { Allow: "GET, POST" } }
12080
+ );
12081
+ }
12082
+ const invocation = await parseInvocation(request);
12083
+ if (invocation === void 0) {
12084
+ return Response.json({ error: "Invalid eval request" }, { status: 400 });
12085
+ }
12086
+ const { runId, parameters } = invocation;
12087
+ const agent = agents.get(invocation.agent);
12088
+ if (agent === void 0) return Response.json({ error: "Unknown agent" }, { status: 404 });
12089
+ const execution = startExecution(agent, parameters);
12090
+ if (execution instanceof Response) return execution;
12091
+ try {
12092
+ const { replay: replay2 } = await readReplayDetails(client, runId, { queryUrl: options.queryUrl });
12093
+ if (replay2.status === "complete" || replay2.status === "failed") {
12094
+ return Response.json({ runId, status: replay2.status, counts: replay2.counts });
12095
+ }
12096
+ if (replay2.status !== "queued") {
12097
+ return Response.json({ error: "Run is already claimed" }, { status: 409 });
12098
+ }
12099
+ const handle = await claimReplay(client, runId, { queryUrl: options.queryUrl });
12100
+ if (handle.replayId !== runId) throw new Error("Raindrop claimed a different run");
12101
+ if (handle.ingestUrl === null) {
12102
+ return Response.json({ error: "Run is already claimed" }, { status: 409 });
12103
+ }
12104
+ const { reading, traceEvidence } = await finishWith(
12105
+ execution,
12106
+ () => runEvalReplay(client, handle, {
12107
+ run: execution.run,
12108
+ queryUrl: options.queryUrl,
12109
+ replayIngestUrl: options.replayIngestUrl
12110
+ })
12111
+ );
12112
+ return Response.json({
12113
+ runId: reading.replayId,
12114
+ status: reading.status,
12115
+ counts: reading.counts,
12116
+ traceEvidence
12117
+ });
12118
+ } catch (error) {
12119
+ return Response.json({ error: errorMessage(error) }, { status: 500 });
12120
+ }
12121
+ };
12122
+ }
12123
+
11869
12124
  // src/evals/rows.ts
11870
12125
  var EvalDatasetRowInputSchema = EvalDatasetCaseInputSchema;
11871
12126
  function datasetFromWire({ cases, ...dataset }) {
@@ -12016,7 +12271,7 @@ function sleep2(ms) {
12016
12271
  }
12017
12272
 
12018
12273
  // src/evals/publish.ts
12019
- import { z as z4 } from "zod";
12274
+ import { z as z6 } from "zod";
12020
12275
 
12021
12276
  // src/evals/runs.ts
12022
12277
  async function readEvalRun(client, runId, options = {}) {
@@ -12065,19 +12320,19 @@ async function evaluateEvalRun(client, runId, options) {
12065
12320
  }
12066
12321
 
12067
12322
  // src/evals/publish.ts
12068
- var EvaluatorIdentitySchema = z4.object({
12069
- id: z4.string().uuid(),
12070
- slug: z4.string(),
12071
- programVersion: z4.number().int().positive(),
12072
- outputType: z4.enum(["boolean", "score", "number"])
12323
+ var EvaluatorIdentitySchema = z6.object({
12324
+ id: z6.string().uuid(),
12325
+ slug: z6.string(),
12326
+ programVersion: z6.number().int().positive(),
12327
+ outputType: z6.enum(["boolean", "score", "number"])
12073
12328
  });
12074
12329
  var EvaluatorSourceSchema = EvaluatorIdentitySchema.extend({
12075
- name: z4.string(),
12076
- description: z4.string().nullable(),
12077
- intent: z4.string(),
12078
- kind: z4.enum(["judge", "deterministic"]),
12079
- programSource: z4.string(),
12080
- rules: z4.array(z4.string())
12330
+ name: z6.string(),
12331
+ description: z6.string().nullable(),
12332
+ intent: z6.string(),
12333
+ kind: z6.enum(["judge", "deterministic"]),
12334
+ programSource: z6.string(),
12335
+ rules: z6.array(z6.string())
12081
12336
  });
12082
12337
  var EvalPublishError = class extends Error {
12083
12338
  constructor(status, message) {
@@ -12086,12 +12341,12 @@ var EvalPublishError = class extends Error {
12086
12341
  this.name = "EvalPublishError";
12087
12342
  }
12088
12343
  };
12089
- var ComparisonRunSchema = z4.object({
12090
- id: z4.string().uuid(),
12091
- programVersion: z4.number().int().positive()
12344
+ var ComparisonRunSchema = z6.object({
12345
+ id: z6.string().uuid(),
12346
+ programVersion: z6.number().int().positive()
12092
12347
  });
12093
- var ComparisonLinkSchema = z4.object({
12094
- url: z4.string().url(),
12348
+ var ComparisonLinkSchema = z6.object({
12349
+ url: z6.string().url(),
12095
12350
  first: ComparisonRunSchema,
12096
12351
  second: ComparisonRunSchema
12097
12352
  });
@@ -12119,7 +12374,7 @@ async function compareEvalRuns(client, options) {
12119
12374
  }
12120
12375
  const before = selected.id;
12121
12376
  const after = counterpart.id;
12122
- const { data } = z4.object({ data: ComparisonLinkSchema }).parse(await evalRequest(client, `/v1/eval-runs/${before}/compare/${after}`, options));
12377
+ const { data } = z6.object({ data: ComparisonLinkSchema }).parse(await evalRequest(client, `/v1/eval-runs/${before}/compare/${after}`, options));
12123
12378
  if (data.first.id !== before || data.second.id !== after) {
12124
12379
  throw new Error("Raindrop returned a different comparison pair");
12125
12380
  }
@@ -12132,7 +12387,7 @@ async function compareEvalRuns(client, options) {
12132
12387
  };
12133
12388
  }
12134
12389
  async function readEvaluator(client, slug, options = {}) {
12135
- const { data } = z4.object({ data: EvaluatorSourceSchema }).parse(await evalRequest(client, `/v1/evals/${encodeURIComponent(slug)}`, options));
12390
+ const { data } = z6.object({ data: EvaluatorSourceSchema }).parse(await evalRequest(client, `/v1/evals/${encodeURIComponent(slug)}`, options));
12136
12391
  if (data.slug !== slug) throw new Error("Raindrop returned a different evaluator slug");
12137
12392
  return defineEvaluatorProgram({
12138
12393
  slug: data.slug,
@@ -12253,32 +12508,32 @@ var traceTools = Object.freeze({
12253
12508
  });
12254
12509
 
12255
12510
  // src/evals/pull.ts
12256
- import { z as z5 } from "zod";
12511
+ import { z as z7 } from "zod";
12257
12512
  var SNAPSHOT_VERSION = 1;
12258
- var PulledEvaluatorSchema = z5.object({
12259
- slug: z5.string().min(1),
12260
- name: z5.string().min(1),
12261
- expectedSha256: z5.string().regex(/^[a-f0-9]{64}$/),
12262
- artifact: z5.unknown()
12513
+ var PulledEvaluatorSchema = z7.object({
12514
+ slug: z7.string().min(1),
12515
+ name: z7.string().min(1),
12516
+ expectedSha256: z7.string().regex(/^[a-f0-9]{64}$/),
12517
+ artifact: z7.unknown()
12263
12518
  });
12264
- var EvalSnapshotSchema = z5.object({
12265
- schemaVersion: z5.literal(SNAPSHOT_VERSION),
12266
- pulledAt: z5.string().datetime(),
12267
- dataset: z5.object({
12268
- reference: z5.string().min(1),
12269
- datasetId: z5.string().uuid(),
12270
- fingerprint: z5.string().regex(/^[a-f0-9]{64}$/),
12271
- rows: z5.array(
12272
- z5.object({
12273
- id: z5.string(),
12274
- name: z5.string(),
12275
- input: z5.string().nullable(),
12276
- output: z5.string().nullable(),
12277
- properties: z5.record(z5.string())
12519
+ var EvalSnapshotSchema = z7.object({
12520
+ schemaVersion: z7.literal(SNAPSHOT_VERSION),
12521
+ pulledAt: z7.string().datetime(),
12522
+ dataset: z7.object({
12523
+ reference: z7.string().min(1),
12524
+ datasetId: z7.string().uuid(),
12525
+ fingerprint: z7.string().regex(/^[a-f0-9]{64}$/),
12526
+ rows: z7.array(
12527
+ z7.object({
12528
+ id: z7.string(),
12529
+ name: z7.string(),
12530
+ input: z7.string().nullable(),
12531
+ output: z7.string().nullable(),
12532
+ properties: z7.record(z7.string())
12278
12533
  })
12279
12534
  )
12280
12535
  }),
12281
- evaluators: z5.array(PulledEvaluatorSchema)
12536
+ evaluators: z7.array(PulledEvaluatorSchema)
12282
12537
  });
12283
12538
  async function pullEval(client, options) {
12284
12539
  var _a;
@@ -12343,11 +12598,11 @@ async function pullEvaluator(client, queryUrl, rawSlug) {
12343
12598
  `Raindrop evaluator ${rawSlug} pull failed with ${response.status}: ${await response.text()}`
12344
12599
  );
12345
12600
  }
12346
- const body = z5.object({
12347
- data: z5.object({
12348
- slug: z5.string(),
12349
- name: z5.string(),
12350
- artifact: z5.unknown().nullable()
12601
+ const body = z7.object({
12602
+ data: z7.object({
12603
+ slug: z7.string(),
12604
+ name: z7.string(),
12605
+ artifact: z7.unknown().nullable()
12351
12606
  })
12352
12607
  }).parse(await response.json());
12353
12608
  if (!body.data.artifact)
@@ -12478,46 +12733,46 @@ function outputMismatch(name, output) {
12478
12733
  }
12479
12734
 
12480
12735
  // src/evals/workshop.ts
12481
- import { z as z6 } from "zod";
12482
- var WorkshopRunSchema = z6.object({
12483
- id: z6.string(),
12484
- event_id: z6.string().nullable(),
12485
- name: z6.string().nullable(),
12486
- event_name: z6.string().nullable(),
12487
- user_id: z6.string().nullable(),
12488
- convo_id: z6.string().nullable(),
12489
- started_at: z6.number().nullable(),
12490
- last_updated_at: z6.number().nullable(),
12491
- metadata: z6.string().nullable(),
12492
- model: z6.string().nullable(),
12493
- finished: z6.number().nullable()
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()
12494
12749
  });
12495
- var WorkshopSpanSchema = z6.object({
12496
- id: z6.string(),
12497
- run_id: z6.string(),
12498
- parent_span_id: z6.string().nullable(),
12499
- name: z6.string(),
12500
- span_type: z6.string().nullable(),
12501
- status: z6.string().nullable(),
12502
- input_payload: z6.string().nullable(),
12503
- output_payload: z6.string().nullable(),
12504
- start_time_ms: z6.number().nullable(),
12505
- end_time_ms: z6.number().nullable(),
12506
- duration_ms: z6.number().nullable(),
12507
- model: z6.string().nullable(),
12508
- provider: z6.string().nullable(),
12509
- input_tokens: z6.number().nullable(),
12510
- output_tokens: z6.number().nullable(),
12511
- attributes: z6.string().nullable()
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()
12512
12767
  });
12513
- var WorkshopTraceEnvelopeSchema = z6.object({
12514
- status: z6.literal("complete"),
12515
- correlationId: z6.string(),
12516
- traceId: z6.string(),
12517
- rootSpanId: z6.string(),
12518
- spanCount: z6.number().int().positive(),
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(),
12519
12774
  run: WorkshopRunSchema,
12520
- spans: z6.array(WorkshopSpanSchema).min(1)
12775
+ spans: z8.array(WorkshopSpanSchema).min(1)
12521
12776
  });
12522
12777
  async function readWorkshopTrace(input) {
12523
12778
  if (!Number.isFinite(input.waitMs) || input.waitMs < 0)
@@ -12602,7 +12857,28 @@ function serializableOutput(value) {
12602
12857
  // src/evals/run.ts
12603
12858
  var DEFAULT_WORKSHOP_TRACE_WAIT_MS = 3e4;
12604
12859
  function createEvalSuiteRun(client, definition, options) {
12860
+ var _a;
12605
12861
  const validated = validateDefinition(definition);
12862
+ const execution = bindSuite(validated, (_a = options.parameters) != null ? _a : {});
12863
+ const session = createSuiteSession(client, validated, execution.run, options);
12864
+ let finishing;
12865
+ return {
12866
+ id: session.id,
12867
+ run: (selection) => session.run(selection),
12868
+ finish: () => finishing != null ? finishing : finishing = finishWith(execution, () => session.finish())
12869
+ };
12870
+ }
12871
+ function bindSuite(definition, parameters) {
12872
+ if (definition.agent === void 0) {
12873
+ const { run } = definition;
12874
+ return {
12875
+ run: (row) => Promise.resolve().then(() => run(row)),
12876
+ finish: () => Promise.resolve()
12877
+ };
12878
+ }
12879
+ return definition.agent.start(parameters);
12880
+ }
12881
+ function createSuiteSession(client, validated, run, options) {
12606
12882
  if (validated.datasetVersionId && "selection" in options && options.selection.dataset.version.id !== validated.datasetVersionId) {
12607
12883
  throw new Error("Selected dataset version does not match the published suite");
12608
12884
  }
@@ -12630,6 +12906,7 @@ function createEvalSuiteRun(client, definition, options) {
12630
12906
  return new RaindropRowEvalRun(
12631
12907
  client,
12632
12908
  validated,
12909
+ run,
12633
12910
  options.destination,
12634
12911
  options.selection.dataset,
12635
12912
  selection.rowIds,
@@ -12654,19 +12931,26 @@ function createEvalSuiteRun(client, definition, options) {
12654
12931
  return new WorkshopEvalRun(
12655
12932
  client,
12656
12933
  { ...validated, dataset: validated.dataset },
12934
+ run,
12657
12935
  options.destination
12658
12936
  );
12659
12937
  }
12660
12938
  async function runEvalSuite(client, definition, options = {}) {
12939
+ var _a;
12940
+ const validated = validateDefinition(definition);
12941
+ const execution = bindSuite(validated, (_a = options.parameters) != null ? _a : {});
12942
+ return finishWith(execution, () => runSuite(client, validated, execution.run, options));
12943
+ }
12944
+ async function runSuite(client, definition, run, options) {
12661
12945
  var _a, _b, _c, _d, _e, _f, _g, _h;
12662
- let validated = validateDefinition(definition);
12946
+ let validated = definition;
12663
12947
  const destination = (_a = options.destination) != null ? _a : { kind: "raindrop" };
12664
12948
  if (validated.datasetVersionId && ((_b = options.selection) == null ? void 0 : _b.dataset) && options.selection.dataset.version.id !== validated.datasetVersionId) {
12665
12949
  throw new Error("Selected dataset version does not match the published suite");
12666
12950
  }
12667
12951
  if (destination.kind === "workshop") {
12668
12952
  if (options.runId !== void 0) throw new Error("Queued runs are only supported in Raindrop");
12669
- const session = createEvalSuiteRun(client, validated, { destination });
12953
+ const session = createSuiteSession(client, validated, run, { destination });
12670
12954
  await session.run({ selection: options.selection, attempt: options.attempt });
12671
12955
  return session.finish();
12672
12956
  }
@@ -12700,7 +12984,7 @@ async function runEvalSuite(client, definition, options = {}) {
12700
12984
  rowIds: (_h = (_g = options.selection) == null ? void 0 : _g.rowIds) != null ? _h : dataset.rows.map((entry) => entry.id)
12701
12985
  });
12702
12986
  if (!selection) throw new Error("Raindrop remote eval requires selected rows");
12703
- const session = createEvalSuiteRun(client, validated, {
12987
+ const session = createSuiteSession(client, validated, run, {
12704
12988
  destination,
12705
12989
  selection: { dataset, rowIds: selection.rowIds }
12706
12990
  });
@@ -12734,7 +13018,7 @@ async function runEvalSuite(client, definition, options = {}) {
12734
13018
  }
12735
13019
  return finished;
12736
13020
  }
12737
- return runRaindropEval(client, validated, destination, options);
13021
+ return runRaindropEval(client, validated, run, destination, options);
12738
13022
  }
12739
13023
  function isRowScopedLocalEval(definition) {
12740
13024
  return definition.evaluators.every(
@@ -12742,9 +13026,10 @@ function isRowScopedLocalEval(definition) {
12742
13026
  );
12743
13027
  }
12744
13028
  var RaindropRowEvalRun = class {
12745
- constructor(client, definition, destination, dataset, rowIds, evaluators) {
13029
+ constructor(client, definition, runRow, destination, dataset, rowIds, evaluators) {
12746
13030
  this.client = client;
12747
13031
  this.definition = definition;
13032
+ this.runRow = runRow;
12748
13033
  this.destination = destination;
12749
13034
  this.dataset = dataset;
12750
13035
  this.rowIds = rowIds;
@@ -12794,7 +13079,7 @@ var RaindropRowEvalRun = class {
12794
13079
  const attemptResult = await replay2.run({
12795
13080
  rowId,
12796
13081
  attempt,
12797
- run: this.definition.run,
13082
+ run: this.runRow,
12798
13083
  traceWaitMs: this.definition.traceWaitMs
12799
13084
  });
12800
13085
  const configured = new Map(
@@ -12899,9 +13184,10 @@ function replayEvaluatorsFromVerdicts(verdicts) {
12899
13184
  return [...evaluators.values()];
12900
13185
  }
12901
13186
  var WorkshopEvalRun = class {
12902
- constructor(client, definition, destination) {
13187
+ constructor(client, definition, runRow, destination) {
12903
13188
  this.client = client;
12904
13189
  this.definition = definition;
13190
+ this.runRow = runRow;
12905
13191
  this.destination = destination;
12906
13192
  this.id = randomId();
12907
13193
  this.startedAt = /* @__PURE__ */ new Date();
@@ -13031,7 +13317,7 @@ var WorkshopEvalRun = class {
13031
13317
  () => {
13032
13318
  var _a2;
13033
13319
  const parent = (_a2 = otelTrace.getSpan(context2.active())) == null ? void 0 : _a2.spanContext();
13034
- if (!parent) return this.definition.run(row);
13320
+ if (!parent) return this.runRow(row);
13035
13321
  return withReplayTraceDestination(
13036
13322
  {
13037
13323
  ...destination,
@@ -13041,7 +13327,7 @@ var WorkshopEvalRun = class {
13041
13327
  eventId: parent.traceId
13042
13328
  }
13043
13329
  },
13044
- () => this.definition.run(row)
13330
+ () => this.runRow(row)
13045
13331
  );
13046
13332
  }
13047
13333
  )
@@ -13219,7 +13505,7 @@ var WorkshopEvalRun = class {
13219
13505
  return current;
13220
13506
  }
13221
13507
  };
13222
- async function runRaindropEval(client, definition, destination, options) {
13508
+ async function runRaindropEval(client, definition, run, destination, options) {
13223
13509
  var _a, _b, _c, _d;
13224
13510
  if (typeof definition.dataset !== "string") {
13225
13511
  throw new Error(
@@ -13246,7 +13532,7 @@ async function runRaindropEval(client, definition, destination, options) {
13246
13532
  dataset: pinnedDataset ? datasetToWire(pinnedDataset) : datasetReference,
13247
13533
  evaluators: definition.evaluators.map((entry) => replayEvaluator(entry)),
13248
13534
  evaluatorPins: hostedEvaluatorPins(definition.evaluators),
13249
- run: definition.run,
13535
+ run,
13250
13536
  concurrency: definition.concurrency,
13251
13537
  traceWaitMs: definition.traceWaitMs,
13252
13538
  evalWaitMs: definition.evalWaitMs,
@@ -14920,6 +15206,9 @@ export {
14920
15206
  runReplay,
14921
15207
  replay,
14922
15208
  evaluateReplay,
15209
+ EvalParameterError,
15210
+ defineAgent,
15211
+ createEvalHandler,
14923
15212
  EvalDatasetRowInputSchema,
14924
15213
  readEvalDataset2 as readEvalDataset,
14925
15214
  EvalDatasetPublishConflictError,