raindrop-ai 0.9.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -5799,6 +5799,36 @@ var init_manifest = __esm({
5799
5799
  });
5800
5800
 
5801
5801
  // src/evals/generated/trace.ts
5802
+ function jsonTreeKind(value, ancestors) {
5803
+ switch (typeof value) {
5804
+ case "string":
5805
+ case "boolean":
5806
+ return "plain";
5807
+ case "number":
5808
+ return Number.isNaN(value) ? "other" : "plain";
5809
+ case "object":
5810
+ break;
5811
+ default:
5812
+ return "other";
5813
+ }
5814
+ if (value === null)
5815
+ return "plain";
5816
+ if (ancestors.has(value))
5817
+ return "cycle";
5818
+ const prototype = Object.getPrototypeOf(value);
5819
+ const children = Array.isArray(value) ? prototype === Array.prototype && Object.keys(value).length === value.length ? value : null : (prototype === Object.prototype || prototype === null) && !Object.hasOwn(value, "__proto__") ? Object.values(value) : null;
5820
+ if (children === null)
5821
+ return "other";
5822
+ ancestors.add(value);
5823
+ let kind = "plain";
5824
+ for (const child of children) {
5825
+ kind = jsonTreeKind(child, ancestors);
5826
+ if (kind !== "plain")
5827
+ break;
5828
+ }
5829
+ ancestors.delete(value);
5830
+ return kind;
5831
+ }
5802
5832
  function compareNanoseconds(left, right) {
5803
5833
  if (Number.isFinite(left) && Number.isFinite(right))
5804
5834
  return Number(left) - Number(right);
@@ -5995,6 +6025,9 @@ function traceStepsToEntries(steps) {
5995
6025
  function projectWorkshopTrace(input) {
5996
6026
  return createTrace(input.origin, input.event, traceStepsToEntries(buildTraceSteps([...input.spans], { includePayloads: true })).map(boundEvalEntry));
5997
6027
  }
6028
+ function formatTrace(trace8) {
6029
+ return JSON.stringify(trace8);
6030
+ }
5998
6031
  function traceOutput(trace8) {
5999
6032
  var _a;
6000
6033
  return (_a = trace8.event.aiData.output) != null ? _a : null;
@@ -6002,19 +6035,33 @@ function traceOutput(trace8) {
6002
6035
  function traceToolCalls(trace8, name) {
6003
6036
  return trace8.entries.filter((entry) => entry.type === "tool_call" && (name === void 0 || entry.name === name));
6004
6037
  }
6005
- var import_zod3, JsonValueSchema, stringToJSONSchema, SignalPropertiesSchema, AIEventMetadataSchema, AnalyticsEventSchema, LensInfoSchema, AttachmentSchema2, SignalSchema, RichTextContentSchema, RichJsonContentSchema, RichMediaContentSchema, RichReferenceContentSchema, RichContentSchema, RichPayloadValueSchema, RichEntrySourceSchema, RichInteractionEntryBaseSchema, RichSystemEntrySchema, RichUserMessageEntrySchema, RichAssistantTextEntrySchema, RichReasoningEntrySchema, RichToolCallEntrySchema, RichUnknownSpanEntrySchema, RichSubAgentEntrySchema, RichDetachedSubAgentEntrySchema, RichAgentHandoffEntrySchema, RichInteractionEntrySchema, RichSpanSummarySchema, RichDiagnosticWarningSchema, RichInteractionStatsSchema, RichEventInteractionSchema, CoreEventSchema, AIAnalyticsEventSchema, SpanStatusSchema, SpanTypeSchema, TracesListPipe, UINT64_MAX, NANOSECONDS_PATTERN, NanosecondsStringSchema, ReplayTraceSnapshotSpanSchema, EvalDatasetCaseIdSchema, EvalCaseExpectationSchema, TraceSchema, CapturedTraceSpanSchema, EVAL_DATASET_MAX_SPANS_PER_TRACE, CapturedTraceSnapshotSchema, EvalCaseTraceSchema, EvalCaseTracePairSchema, MAX_CUSTOM_ATTRIBUTES, MAX_ATTRIBUTE_VALUE_CHARS, KNOWN_ATTRIBUTE_PREFIXES, SENSITIVE_KEY_TOKENS, SENSITIVE_KEY_TOKEN_PAIRS, MAX_EVAL_PAYLOAD_RAW_CHARS, TRACE_PROJECTION_SHA256;
6038
+ var import_zod3, JsonValueLazySchema, JsonValueSchema, stringToJSONSchema, SignalPropertiesSchema, AIEventMetadataSchema, AnalyticsEventSchema, LensInfoSchema, AttachmentSchema2, SignalSchema, RichTextContentSchema, RichJsonContentSchema, RichMediaContentSchema, RichReferenceContentSchema, RichContentSchema, RichPayloadValueSchema, RichEntrySourceSchema, RichInteractionEntryBaseSchema, RichSystemEntrySchema, RichUserMessageEntrySchema, RichAssistantTextEntrySchema, RichReasoningEntrySchema, RichToolCallEntrySchema, RichUnknownSpanEntrySchema, RichSubAgentEntrySchema, RichDetachedSubAgentEntrySchema, RichAgentHandoffEntrySchema, RichInteractionEntrySchema, RichSpanSummarySchema, RichDiagnosticWarningSchema, RichInteractionStatsSchema, RichEventInteractionSchema, CoreEventSchema, AIAnalyticsEventSchema, SpanStatusSchema, SpanTypeSchema, TracesListPipe, UINT64_MAX, NANOSECONDS_PATTERN, NanosecondsStringSchema, ReplayTraceSnapshotSpanSchema, EvalDatasetCaseIdSchema, EvalCaseExpectationSchema, TraceSchema, EvalContextSchema, CapturedTraceSpanSchema, EVAL_DATASET_MAX_SPANS_PER_TRACE, CapturedTraceSnapshotSchema, EvalCaseTraceSchema, EvalCaseTracePairSchema, MAX_CUSTOM_ATTRIBUTES, MAX_ATTRIBUTE_VALUE_CHARS, KNOWN_ATTRIBUTE_PREFIXES, SENSITIVE_KEY_TOKENS, SENSITIVE_KEY_TOKEN_PAIRS, MAX_EVAL_PAYLOAD_RAW_CHARS, TRACE_PROJECTION_SHA256;
6006
6039
  var init_trace = __esm({
6007
6040
  "src/evals/generated/trace.ts"() {
6008
6041
  "use strict";
6009
6042
  import_zod3 = __toESM(require("zod"));
6010
- JsonValueSchema = import_zod3.default.lazy(() => import_zod3.default.union([
6011
- import_zod3.default.string(),
6012
- import_zod3.default.number(),
6013
- import_zod3.default.boolean(),
6014
- import_zod3.default.null(),
6015
- import_zod3.default.array(JsonValueSchema),
6016
- import_zod3.default.record(JsonValueSchema)
6017
- ]));
6043
+ JsonValueLazySchema = class extends import_zod3.default.ZodLazy {
6044
+ _parse(input) {
6045
+ const kind = jsonTreeKind(input.data, /* @__PURE__ */ new Set());
6046
+ if (kind === "plain")
6047
+ return import_zod3.default.OK(input.data);
6048
+ if (kind === "other")
6049
+ return super._parse(input);
6050
+ import_zod3.default.addIssueToContext(this._getOrReturnCtx(input), { code: import_zod3.default.ZodIssueCode.custom, message: "JSON values cannot contain cycles" });
6051
+ return import_zod3.default.INVALID;
6052
+ }
6053
+ };
6054
+ JsonValueSchema = new JsonValueLazySchema({
6055
+ typeName: import_zod3.default.ZodFirstPartyTypeKind.ZodLazy,
6056
+ getter: () => import_zod3.default.union([
6057
+ import_zod3.default.string(),
6058
+ import_zod3.default.number(),
6059
+ import_zod3.default.boolean(),
6060
+ import_zod3.default.null(),
6061
+ import_zod3.default.array(JsonValueSchema),
6062
+ import_zod3.default.record(JsonValueSchema)
6063
+ ])
6064
+ });
6018
6065
  stringToJSONSchema = import_zod3.default.string().transform((str, ctx) => {
6019
6066
  try {
6020
6067
  return JSON.parse(str);
@@ -6395,6 +6442,12 @@ var init_trace = __esm({
6395
6442
  entries: import_zod3.default.array(RichInteractionEntrySchema),
6396
6443
  caseContext: import_zod3.default.object({ caseId: EvalDatasetCaseIdSchema, expectation: EvalCaseExpectationSchema.optional() }).optional()
6397
6444
  });
6445
+ EvalContextSchema = import_zod3.default.object({
6446
+ trace: TraceSchema,
6447
+ expectedOutput: JsonValueSchema.optional(),
6448
+ referenceTrace: TraceSchema.optional(),
6449
+ rowMetadata: import_zod3.default.record(import_zod3.default.string(), import_zod3.default.string())
6450
+ });
6398
6451
  CapturedTraceSpanSchema = ReplayTraceSnapshotSpanSchema;
6399
6452
  EVAL_DATASET_MAX_SPANS_PER_TRACE = 500;
6400
6453
  CapturedTraceSnapshotSchema = import_zod3.default.object({
@@ -6491,6 +6544,7 @@ var init_trace = __esm({
6491
6544
  EvalCaseTracePairSchema = import_zod3.default.object({
6492
6545
  caseId: EvalDatasetCaseIdSchema,
6493
6546
  output: JsonValueSchema.optional(),
6547
+ rowMetadata: import_zod3.default.record(import_zod3.default.string(), import_zod3.default.string()).optional(),
6494
6548
  candidate: EvalCaseTraceSchema.extend({
6495
6549
  trace: TraceSchema.extend({ origin: import_zod3.default.enum(["replay", "dataset"]) })
6496
6550
  }),
@@ -6562,7 +6616,7 @@ var init_trace = __esm({
6562
6616
  "refresh token"
6563
6617
  ]);
6564
6618
  MAX_EVAL_PAYLOAD_RAW_CHARS = 16 * 1024;
6565
- TRACE_PROJECTION_SHA256 = "22c666c6ace47d74d3f7dc477e68b27547257b319ba4014a4a32fbf977baac72";
6619
+ TRACE_PROJECTION_SHA256 = "243e395493cfac6358d104d6be52e35bf739a0192aed2367fa780b2119f0721c";
6566
6620
  }
6567
6621
  });
6568
6622
 
@@ -6578,7 +6632,7 @@ function defineDataset(dataset) {
6578
6632
  id: parsed.id,
6579
6633
  name: (_a2 = parsed.name) != null ? _a2 : parsed.id,
6580
6634
  input: parsed.input,
6581
- output: parsed.output,
6635
+ output: structuredClone(parsed.output),
6582
6636
  properties: parsed.properties
6583
6637
  };
6584
6638
  });
@@ -6653,7 +6707,7 @@ function defineEvaluatorProgram(program) {
6653
6707
  return {
6654
6708
  ...program,
6655
6709
  kind: "program",
6656
- scope: import_zod4.z.literal("batch").parse((_c = program.scope) != null ? _c : "batch"),
6710
+ scope: import_zod4.z.literal("trace").parse((_c = program.scope) != null ? _c : "trace"),
6657
6711
  slug,
6658
6712
  name,
6659
6713
  source,
@@ -6846,106 +6900,129 @@ __export(portable_runtime_exports, {
6846
6900
  runPortableEvaluator: () => runPortableEvaluator
6847
6901
  });
6848
6902
  async function runPortableEvaluator(evaluator, input) {
6849
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
6903
+ var _a, _b, _c, _d, _e, _f, _g;
6904
+ const limits = PortableEvalLimitsSchema.parse((_a = evaluator.limits) != null ? _a : {});
6850
6905
  const inputJson = JSON.stringify(input);
6851
- const maxInputBytes = (_b = (_a = evaluator.limits) == null ? void 0 : _a.maxInputBytes) != null ? _b : DEFAULT_MAX_INPUT_BYTES;
6906
+ const maxInputBytes = (_b = limits.maxInputBytes) != null ? _b : DEFAULT_MAX_INPUT_BYTES;
6852
6907
  if (byteLength(inputJson) > maxInputBytes) {
6853
6908
  throw new Error(`Raindrop portable evaluator input exceeds ${maxInputBytes} bytes`);
6854
6909
  }
6855
6910
  const QuickJS = await (0, import_quickjs_emscripten_core.newQuickJSWASMModuleFromVariant)(import_quickjs_singlefile_cjs_release_sync.default);
6856
6911
  const runtime = QuickJS.newRuntime();
6857
- runtime.setMemoryLimit((_d = (_c = evaluator.limits) == null ? void 0 : _c.memoryBytes) != null ? _d : DEFAULT_MEMORY_BYTES);
6858
- runtime.setMaxStackSize((_f = (_e = evaluator.limits) == null ? void 0 : _e.stackBytes) != null ? _f : DEFAULT_STACK_BYTES);
6859
- const timeoutMs = (_h = (_g = evaluator.limits) == null ? void 0 : _g.timeoutMs) != null ? _h : evaluator.artifact.evaluator.executionMode === "judge" ? DEFAULT_JUDGE_TIMEOUT_MS : DEFAULT_TIMEOUT_MS;
6860
- const deadline = Date.now() + timeoutMs;
6861
- runtime.setInterruptHandler((0, import_quickjs_emscripten_core.shouldInterruptAfterDeadline)(deadline));
6862
- const context8 = runtime.newContext();
6863
- const deferreds = [];
6864
- const hostCalls = /* @__PURE__ */ new Set();
6865
- const tracesById = new Map(input.traces.map((trace8) => [trace8.event.id, trace8]));
6866
- const casesByTraceId = new Map(
6867
- input.cases.map((entry) => [entry.candidate.trace.event.id, entry])
6868
- );
6869
- let activeJudgeCalls = 0;
6870
6912
  try {
6871
- const bridge = context8.newFunction("__raindrop_eval_judge", (requestHandle) => {
6872
- var _a2, _b2;
6873
- const deferred = context8.newPromise();
6874
- deferreds.push(deferred);
6875
- const requestJson = context8.getString(requestHandle);
6876
- const judgeConcurrency = (_b2 = (_a2 = evaluator.limits) == null ? void 0 : _a2.judgeConcurrency) != null ? _b2 : DEFAULT_JUDGE_CONCURRENCY;
6877
- let acquired = false;
6878
- const hostCall = resolveJudge(
6879
- evaluator,
6880
- requestJson,
6881
- Math.max(1, deadline - Date.now()),
6882
- tracesById,
6883
- casesByTraceId,
6884
- () => {
6885
- if (activeJudgeCalls >= judgeConcurrency) return false;
6913
+ runtime.setMemoryLimit((_c = limits.memoryBytes) != null ? _c : DEFAULT_MEMORY_BYTES);
6914
+ runtime.setMaxStackSize((_d = limits.stackBytes) != null ? _d : DEFAULT_STACK_BYTES);
6915
+ const context8 = runtime.newContext();
6916
+ try {
6917
+ const timeoutMs = (_e = limits.timeoutMs) != null ? _e : evaluator.artifact.evaluator.executionMode === "judge" ? DEFAULT_JUDGE_TIMEOUT_MS : DEFAULT_TIMEOUT_MS;
6918
+ const deadline = Date.now() + timeoutMs;
6919
+ const cancellation = new AbortController();
6920
+ const deadlineTimer = setTimeout(() => cancellation.abort(), timeoutMs);
6921
+ runtime.setInterruptHandler((0, import_quickjs_emscripten_core.shouldInterruptAfterDeadline)(deadline));
6922
+ const deferreds = [];
6923
+ const hostCalls = /* @__PURE__ */ new Set();
6924
+ const tracesById = new Map(input.traces.map((trace8) => [trace8.event.id, trace8]));
6925
+ const casesByTraceId = new Map(
6926
+ input.cases.map((entry) => [entry.candidate.trace.event.id, entry])
6927
+ );
6928
+ let activeJudgeCalls = 0;
6929
+ const judgeWaiters = [];
6930
+ const judgeConcurrency = (_f = limits.judgeConcurrency) != null ? _f : DEFAULT_JUDGE_CONCURRENCY;
6931
+ const acquire = async () => {
6932
+ if (activeJudgeCalls >= judgeConcurrency) {
6933
+ await new Promise((resolve2) => judgeWaiters.push(resolve2));
6934
+ } else {
6886
6935
  activeJudgeCalls += 1;
6887
- acquired = true;
6888
- return true;
6889
6936
  }
6890
- ).then((responseJson) => {
6891
- const response = context8.newString(responseJson);
6937
+ };
6938
+ const release = () => {
6939
+ const next = judgeWaiters.shift();
6940
+ if (next) next();
6941
+ else activeJudgeCalls -= 1;
6942
+ };
6943
+ try {
6944
+ const bridge = context8.newFunction("__raindrop_eval_judge", (requestHandle) => {
6945
+ const deferred = context8.newPromise();
6946
+ deferreds.push(deferred);
6947
+ const requestJson = context8.getString(requestHandle);
6948
+ let acquired = false;
6949
+ const hostCall = resolveJudge(
6950
+ evaluator,
6951
+ requestJson,
6952
+ deadline,
6953
+ tracesById,
6954
+ casesByTraceId,
6955
+ cancellation.signal,
6956
+ async () => {
6957
+ await acquire();
6958
+ acquired = true;
6959
+ }
6960
+ ).then((responseJson) => {
6961
+ const response = context8.newString(responseJson);
6962
+ try {
6963
+ deferred.resolve(response);
6964
+ } finally {
6965
+ response.dispose();
6966
+ }
6967
+ }).finally(() => {
6968
+ if (acquired) release();
6969
+ hostCalls.delete(hostCall);
6970
+ });
6971
+ hostCalls.add(hostCall);
6972
+ return deferred.handle;
6973
+ });
6974
+ context8.setProp(context8.global, "__raindrop_eval_judge", bridge);
6975
+ bridge.dispose();
6976
+ const loaded = context8.evalCode(evaluator.artifact.source, "raindrop-evaluator.js");
6977
+ context8.unwrapResult(loaded).dispose();
6978
+ const entrypoint = context8.getProp(context8.global, "__raindrop_eval_run");
6979
+ const inputHandle = context8.newString(inputJson);
6980
+ let promiseHandle;
6892
6981
  try {
6893
- deferred.resolve(response);
6982
+ promiseHandle = context8.unwrapResult(
6983
+ context8.callFunction(entrypoint, context8.global, inputHandle)
6984
+ );
6894
6985
  } finally {
6895
- response.dispose();
6986
+ inputHandle.dispose();
6987
+ entrypoint.dispose();
6896
6988
  }
6897
- }).finally(() => {
6898
- if (acquired) activeJudgeCalls -= 1;
6899
- hostCalls.delete(hostCall);
6900
- });
6901
- hostCalls.add(hostCall);
6902
- return deferred.handle;
6903
- });
6904
- context8.setProp(context8.global, "__raindrop_eval_judge", bridge);
6905
- bridge.dispose();
6906
- const loaded = context8.evalCode(evaluator.artifact.source, "raindrop-evaluator.js");
6907
- context8.unwrapResult(loaded).dispose();
6908
- const entrypoint = context8.getProp(context8.global, "__raindrop_eval_run");
6909
- const inputHandle = context8.newString(inputJson);
6910
- let promiseHandle;
6911
- try {
6912
- promiseHandle = context8.unwrapResult(
6913
- context8.callFunction(entrypoint, context8.global, inputHandle)
6914
- );
6915
- } finally {
6916
- inputHandle.dispose();
6917
- entrypoint.dispose();
6918
- }
6919
- try {
6920
- const result = await drivePromise(runtime, context8, promiseHandle, deadline);
6921
- const outputHandle = context8.unwrapResult(result);
6922
- try {
6923
- const outputJson = context8.getString(outputHandle);
6924
- const maxOutputBytes = (_j = (_i = evaluator.limits) == null ? void 0 : _i.maxOutputBytes) != null ? _j : DEFAULT_MAX_OUTPUT_BYTES;
6925
- if (byteLength(outputJson) > maxOutputBytes) {
6926
- throw new Error(`Raindrop portable evaluator output exceeds ${maxOutputBytes} bytes`);
6989
+ try {
6990
+ const result = await drivePromise(runtime, context8, promiseHandle, deadline);
6991
+ const outputHandle = context8.unwrapResult(result);
6992
+ try {
6993
+ const outputJson = context8.getString(outputHandle);
6994
+ const maxOutputBytes = (_g = limits.maxOutputBytes) != null ? _g : DEFAULT_MAX_OUTPUT_BYTES;
6995
+ if (byteLength(outputJson) > maxOutputBytes) {
6996
+ throw new Error(`Raindrop portable evaluator output exceeds ${maxOutputBytes} bytes`);
6997
+ }
6998
+ const envelope = JSON.parse(outputJson);
6999
+ if (typeof envelope !== "object" || envelope === null || !("type" in envelope) || envelope.type !== "result" || !("result" in envelope)) {
7000
+ throw new Error("Raindrop portable evaluator returned an invalid result envelope");
7001
+ }
7002
+ return parsePortableEvalResult(envelope.result);
7003
+ } finally {
7004
+ outputHandle.dispose();
7005
+ }
7006
+ } finally {
7007
+ promiseHandle.dispose();
6927
7008
  }
6928
- const envelope = JSON.parse(outputJson);
6929
- if (typeof envelope !== "object" || envelope === null || !("type" in envelope) || envelope.type !== "result" || !("result" in envelope)) {
6930
- throw new Error("Raindrop portable evaluator returned an invalid result envelope");
7009
+ } catch (cause) {
7010
+ const message = cause instanceof Error ? cause.message : String(cause);
7011
+ if (Date.now() >= deadline || message.includes("interrupted")) {
7012
+ throw new Error(`Raindrop portable evaluator exceeded ${timeoutMs}ms`);
6931
7013
  }
6932
- return parsePortableEvalResult(envelope.result);
7014
+ throw new Error(`Raindrop portable evaluator failed: ${message}`);
6933
7015
  } finally {
6934
- outputHandle.dispose();
7016
+ cancellation.abort();
7017
+ clearTimeout(deadlineTimer);
7018
+ for (const resume of judgeWaiters.splice(0)) resume();
7019
+ await Promise.allSettled([...hostCalls]);
7020
+ for (const deferred of deferreds) deferred.dispose();
6935
7021
  }
6936
7022
  } finally {
6937
- promiseHandle.dispose();
7023
+ context8.dispose();
6938
7024
  }
6939
- } catch (cause) {
6940
- const message = cause instanceof Error ? cause.message : String(cause);
6941
- if (Date.now() >= deadline || message.includes("interrupted")) {
6942
- throw new Error(`Raindrop portable evaluator exceeded ${timeoutMs}ms`);
6943
- }
6944
- throw new Error(`Raindrop portable evaluator failed: ${message}`);
6945
7025
  } finally {
6946
- await Promise.allSettled([...hostCalls]);
6947
- for (const deferred of deferreds) deferred.dispose();
6948
- context8.dispose();
6949
7026
  runtime.dispose();
6950
7027
  }
6951
7028
  }
@@ -6959,7 +7036,7 @@ async function drivePromise(runtime, context8, promise, deadline) {
6959
7036
  if (Date.now() >= deadline) throw new Error("interrupted");
6960
7037
  }
6961
7038
  }
6962
- async function resolveJudge(evaluator, rawRequest, remainingMs, tracesById, casesByTraceId, acquire) {
7039
+ async function resolveJudge(evaluator, rawRequest, deadline, tracesById, casesByTraceId, signal, acquire) {
6963
7040
  var _a, _b;
6964
7041
  let requestId = "unknown";
6965
7042
  try {
@@ -6968,19 +7045,23 @@ async function resolveJudge(evaluator, rawRequest, remainingMs, tracesById, case
6968
7045
  const trace8 = tracesById.get(request.traceId);
6969
7046
  if (!trace8) throw new Error("Judge trace is outside this run");
6970
7047
  if (!evaluator.judge) throw new Error("Judge unavailable");
6971
- if (!acquire()) throw new Error("Judge concurrency exceeded");
7048
+ await acquire();
7049
+ signal.throwIfAborted();
7050
+ const remainingMs = deadline - Date.now();
7051
+ if (remainingMs <= 0) throw new Error("Judge deadline exceeded");
6972
7052
  const controller = new AbortController();
6973
- const timeoutMs = Math.min(
6974
- (_b = (_a = evaluator.limits) == null ? void 0 : _a.judgeTimeoutMs) != null ? _b : DEFAULT_JUDGE_REQUEST_TIMEOUT_MS,
6975
- remainingMs
6976
- );
6977
- const timeout = setTimeout(() => controller.abort(), timeoutMs);
7053
+ const timeoutMs = (_b = (_a = evaluator.limits) == null ? void 0 : _a.judgeTimeoutMs) != null ? _b : DEFAULT_JUDGE_REQUEST_TIMEOUT_MS;
7054
+ const abort = () => controller.abort();
7055
+ signal.addEventListener("abort", abort, { once: true });
7056
+ const timeout = setTimeout(abort, timeoutMs);
6978
7057
  const result = await Promise.race([
6979
7058
  Promise.resolve().then(
6980
7059
  () => {
6981
7060
  var _a2;
6982
7061
  return (_a2 = evaluator.judge) == null ? void 0 : _a2.call(evaluator, {
6983
7062
  trace: trace8,
7063
+ text: request.text,
7064
+ outputType: request.outputType,
6984
7065
  tracePair: rowTracePair(casesByTraceId.get(request.traceId)),
6985
7066
  rubric: request.rubric.slice(0, 4e4),
6986
7067
  signal: controller.signal
@@ -6994,7 +7075,10 @@ async function resolveJudge(evaluator, rawRequest, remainingMs, tracesById, case
6994
7075
  { once: true }
6995
7076
  );
6996
7077
  })
6997
- ]).finally(() => clearTimeout(timeout));
7078
+ ]).finally(() => {
7079
+ clearTimeout(timeout);
7080
+ signal.removeEventListener("abort", abort);
7081
+ });
6998
7082
  if (typeof result !== "object" || result === null) throw new Error("invalid judge response");
6999
7083
  return JSON.stringify({ type: "judge_response", requestId, status: "completed", result });
7000
7084
  } catch (e) {
@@ -7034,7 +7118,9 @@ var init_portable_runtime = __esm({
7034
7118
  type: import_zod10.z.literal("judge_request"),
7035
7119
  requestId: import_zod10.z.string(),
7036
7120
  traceId: import_zod10.z.string(),
7037
- rubric: import_zod10.z.string()
7121
+ rubric: import_zod10.z.string().min(1).max(4e4),
7122
+ text: import_zod10.z.string().max(4 * 1024 * 1024),
7123
+ outputType: import_zod10.z.enum(["boolean", "score"])
7038
7124
  });
7039
7125
  }
7040
7126
  });
@@ -7056,7 +7142,7 @@ function importPortableEvaluator(rawArtifact, options = {}) {
7056
7142
  artifact,
7057
7143
  expectedSha256: options.expectedSha256,
7058
7144
  judge: options.judge,
7059
- limits: options.limits,
7145
+ limits: options.limits === void 0 ? void 0 : PortableEvalLimitsSchema.parse(options.limits),
7060
7146
  slug: artifact.evaluator.slug,
7061
7147
  name: ((_a = options.name) == null ? void 0 : _a.trim()) || artifact.evaluator.slug,
7062
7148
  output: artifact.evaluator.outputType,
@@ -7068,6 +7154,9 @@ async function evaluatePortableEvaluator(evaluator, input) {
7068
7154
  const artifact = await verifyPortableEvalArtifact(evaluator.artifact, {
7069
7155
  expectedSha256: evaluator.expectedSha256
7070
7156
  });
7157
+ if (new Set(input.traces.map((trace8) => trace8.event.id)).size !== input.traces.length) {
7158
+ throw new Error("Raindrop portable evaluator input trace ids must be unique");
7159
+ }
7071
7160
  const { runPortableEvaluator: runPortableEvaluator2 } = await Promise.resolve().then(() => (init_portable_runtime(), portable_runtime_exports));
7072
7161
  const cases = ((_a = input.rows) != null ? _a : []).map(({ rowId, ...pair }) => ({ ...pair, caseId: rowId }));
7073
7162
  if (cases.length > 0 && (cases.length !== input.traces.length || cases.some(
@@ -7108,9 +7197,6 @@ function validatePortableResult(artifact, traces, result) {
7108
7197
  throw new Error("Raindrop portable evaluator returned an inconsistent trace count");
7109
7198
  }
7110
7199
  const expected = new Set(traces.map((trace8) => trace8.event.id));
7111
- if (expected.size !== traces.length) {
7112
- throw new Error("Raindrop portable evaluator input trace ids must be unique");
7113
- }
7114
7200
  const returned = /* @__PURE__ */ new Set();
7115
7201
  for (const outcome of result.outcomes) {
7116
7202
  if (!expected.has(outcome.traceId)) {
@@ -7146,7 +7232,7 @@ function canonicalJson2(value) {
7146
7232
  if (Array.isArray(value)) return `[${value.map(canonicalJson2).join(",")}]`;
7147
7233
  return `{${Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, entry]) => `${JSON.stringify(key)}:${canonicalJson2(entry)}`).join(",")}}`;
7148
7234
  }
7149
- var import_zod11, PortableEvalArtifactSchema, PortableEvalResultSchema;
7235
+ var import_zod11, PortableEvalArtifactSchema, PortableEvalLimitsSchema, PortableEvalResultSchema;
7150
7236
  var init_portable = __esm({
7151
7237
  "src/evals/portable.ts"() {
7152
7238
  "use strict";
@@ -7156,20 +7242,29 @@ var init_portable = __esm({
7156
7242
  PortableEvalArtifactSchema = import_zod11.z.object({
7157
7243
  format: import_zod11.z.literal("raindrop.eval-program"),
7158
7244
  formatVersion: import_zod11.z.literal(1),
7159
- runtimeAbi: import_zod11.z.literal("raindrop-eval-v2"),
7245
+ runtimeAbi: import_zod11.z.literal("raindrop-eval-v3"),
7160
7246
  evaluator: import_zod11.z.object({
7161
7247
  id: import_zod11.z.string().uuid(),
7162
7248
  slug: import_zod11.z.string().min(1),
7163
7249
  programVersion: import_zod11.z.number().int().positive(),
7164
7250
  executionMode: import_zod11.z.enum(["deterministic", "judge"]),
7165
7251
  outputType: import_zod11.z.enum(["boolean", "score", "number"]),
7166
- scope: import_zod11.z.literal("batch")
7252
+ scope: import_zod11.z.literal("trace")
7167
7253
  }).strict(),
7168
7254
  traceProjectionVersion: import_zod11.z.literal(1),
7169
7255
  traceProjectionSha256: import_zod11.z.string().regex(/^[a-f0-9]{64}$/),
7170
7256
  source: import_zod11.z.string().min(1),
7171
7257
  sha256: import_zod11.z.string().regex(/^[a-f0-9]{64}$/)
7172
7258
  }).strict();
7259
+ PortableEvalLimitsSchema = import_zod11.z.object({
7260
+ memoryBytes: import_zod11.z.number().int().positive().optional(),
7261
+ stackBytes: import_zod11.z.number().int().positive().optional(),
7262
+ timeoutMs: import_zod11.z.number().int().positive().max(2147483647).optional(),
7263
+ maxInputBytes: import_zod11.z.number().int().positive().optional(),
7264
+ maxOutputBytes: import_zod11.z.number().int().positive().optional(),
7265
+ judgeTimeoutMs: import_zod11.z.number().int().positive().max(2147483647).optional(),
7266
+ judgeConcurrency: import_zod11.z.number().int().positive().optional()
7267
+ }).readonly();
7173
7268
  PortableEvalResultSchema = import_zod11.z.object({
7174
7269
  outcomes: import_zod11.z.array(
7175
7270
  import_zod11.z.union([
@@ -7221,6 +7316,7 @@ __export(index_exports, {
7221
7316
  DEFAULT_QUERY_URL: () => DEFAULT_QUERY_URL,
7222
7317
  DEFAULT_TRACE_WAIT_MS: () => DEFAULT_TRACE_WAIT_MS,
7223
7318
  EVAL_CORRELATION_ID_ATTRIBUTE: () => EVAL_CORRELATION_ID_ATTRIBUTE2,
7319
+ EvalContextSchema: () => EvalContextSchema,
7224
7320
  EvalDatasetPublishConflictError: () => EvalDatasetPublishConflictError,
7225
7321
  EvalDatasetRowInputSchema: () => EvalDatasetRowInputSchema,
7226
7322
  EvalParameterError: () => EvalParameterError,
@@ -7256,6 +7352,7 @@ __export(index_exports, {
7256
7352
  evaluateEvalRun: () => evaluateEvalRun,
7257
7353
  evaluatePortableEvaluator: () => evaluatePortableEvaluator,
7258
7354
  evaluateReplay: () => evaluateReplay,
7355
+ formatTrace: () => formatTrace,
7259
7356
  importPortableEvaluator: () => importPortableEvaluator,
7260
7357
  isEvalDataset: () => isEvalDataset,
7261
7358
  isEvalSuiteDefinition: () => isEvalSuiteDefinition,
@@ -13182,7 +13279,7 @@ var SignalEventSchema = external_exports.object({
13182
13279
  // package.json
13183
13280
  var package_default = {
13184
13281
  name: "raindrop-ai",
13185
- version: "0.9.1",
13282
+ version: "1.0.0",
13186
13283
  main: "dist/index.js",
13187
13284
  module: "dist/index.mjs",
13188
13285
  types: "dist/index.d.ts",
@@ -13249,8 +13346,8 @@ var package_default = {
13249
13346
  tsup: "^8.4.0",
13250
13347
  tsx: "^4.20.3",
13251
13348
  typescript: "^5.3.3",
13252
- vite: "^7.3.2",
13253
- vitest: "^4.0.10"
13349
+ vite: "^7.3.5",
13350
+ vitest: "^4.1.11"
13254
13351
  },
13255
13352
  dependencies: {
13256
13353
  "@jitl/quickjs-singlefile-cjs-release-sync": "0.32.0",
@@ -18366,6 +18463,7 @@ var LocalEvalReplaySessionImpl = class {
18366
18463
  }
18367
18464
  const verdicts = await Promise.all(
18368
18465
  this.parents.map(async (parent) => {
18466
+ var _a2;
18369
18467
  const judgeStartedAt = Date.now();
18370
18468
  let verdict;
18371
18469
  try {
@@ -18373,6 +18471,9 @@ var LocalEvalReplaySessionImpl = class {
18373
18471
  parent.evaluator,
18374
18472
  await parent.evaluator.judge({
18375
18473
  trace: pair.candidate.trace,
18474
+ expectedOutput: pair.output,
18475
+ rowMetadata: row.properties,
18476
+ referenceTrace: (_a2 = pair.reference) == null ? void 0 : _a2.trace,
18376
18477
  case: pair,
18377
18478
  row,
18378
18479
  result
@@ -18664,12 +18765,16 @@ async function claimSuiteRun(client, runId, dataset, rowIds, queryUrl) {
18664
18765
  async function runLocalEvaluators(evaluators, evalCase, row, result) {
18665
18766
  await Promise.all(
18666
18767
  evaluators.map(async (state2) => {
18768
+ var _a;
18667
18769
  const startedAt = Date.now();
18668
18770
  try {
18669
18771
  const verdict = parseLocalVerdict(
18670
18772
  state2.evaluator,
18671
18773
  await state2.evaluator.judge({
18672
18774
  trace: evalCase.candidate.trace,
18775
+ expectedOutput: evalCase.output,
18776
+ rowMetadata: row.properties,
18777
+ referenceTrace: (_a = evalCase.reference) == null ? void 0 : _a.trace,
18673
18778
  row,
18674
18779
  result,
18675
18780
  case: evalCase
@@ -19583,7 +19688,7 @@ async function readEvaluator(client, slug, options = {}) {
19583
19688
  slug: data.slug,
19584
19689
  name: data.name,
19585
19690
  output: data.outputType,
19586
- scope: "batch",
19691
+ scope: "trace",
19587
19692
  executionMode: data.kind,
19588
19693
  source: data.programSource,
19589
19694
  description: data.description,
@@ -20340,7 +20445,7 @@ function replayEvaluator(entry) {
20340
20445
  slug: evaluator.slug,
20341
20446
  name: evaluator.name,
20342
20447
  output: evaluator.output,
20343
- judge: ({ trace: trace8, row, result, case: pair }) => evaluator.judge({ trace: trace8, row, result, reference: pair == null ? void 0 : pair.reference }),
20448
+ judge: ({ case: pair, ...context8 }) => evaluator.judge({ ...context8, reference: pair == null ? void 0 : pair.reference }),
20344
20449
  requiresReference: evaluator.requiresReference
20345
20450
  };
20346
20451
  case "score":
@@ -20348,7 +20453,7 @@ function replayEvaluator(entry) {
20348
20453
  slug: evaluator.slug,
20349
20454
  name: evaluator.name,
20350
20455
  output: evaluator.output,
20351
- judge: ({ trace: trace8, row, result, case: pair }) => evaluator.judge({ trace: trace8, row, result, reference: pair == null ? void 0 : pair.reference }),
20456
+ judge: ({ case: pair, ...context8 }) => evaluator.judge({ ...context8, reference: pair == null ? void 0 : pair.reference }),
20352
20457
  requiresReference: evaluator.requiresReference
20353
20458
  };
20354
20459
  case "number":
@@ -20356,7 +20461,7 @@ function replayEvaluator(entry) {
20356
20461
  slug: evaluator.slug,
20357
20462
  name: evaluator.name,
20358
20463
  output: evaluator.output,
20359
- judge: ({ trace: trace8, row, result, case: pair }) => evaluator.judge({ trace: trace8, row, result, reference: pair == null ? void 0 : pair.reference }),
20464
+ judge: ({ case: pair, ...context8 }) => evaluator.judge({ ...context8, reference: pair == null ? void 0 : pair.reference }),
20360
20465
  requiresReference: evaluator.requiresReference
20361
20466
  };
20362
20467
  }
@@ -21759,6 +21864,7 @@ var withEvalScope2 = withEvalScope;
21759
21864
  DEFAULT_QUERY_URL,
21760
21865
  DEFAULT_TRACE_WAIT_MS,
21761
21866
  EVAL_CORRELATION_ID_ATTRIBUTE,
21867
+ EvalContextSchema,
21762
21868
  EvalDatasetPublishConflictError,
21763
21869
  EvalDatasetRowInputSchema,
21764
21870
  EvalParameterError,
@@ -21793,6 +21899,7 @@ var withEvalScope2 = withEvalScope;
21793
21899
  evaluateEvalRun,
21794
21900
  evaluatePortableEvaluator,
21795
21901
  evaluateReplay,
21902
+ formatTrace,
21796
21903
  importPortableEvaluator,
21797
21904
  isEvalDataset,
21798
21905
  isEvalSuiteDefinition,
package/dist/index.mjs CHANGED
@@ -46,10 +46,11 @@ import {
46
46
  runReplay,
47
47
  traceTools,
48
48
  withEvalScope
49
- } from "./chunk-SUW3YBV3.mjs";
50
- import "./chunk-WLBBPTI6.mjs";
49
+ } from "./chunk-MVJNJ4TS.mjs";
50
+ import "./chunk-GQKFYSJ5.mjs";
51
51
  import {
52
52
  BooleanThresholdSchema,
53
+ EvalContextSchema,
53
54
  EvalSuiteManifestSchema,
54
55
  NumericThresholdSchema,
55
56
  TraceSchema,
@@ -58,6 +59,7 @@ import {
58
59
  defineEvaluatorProgram,
59
60
  defineLocalEvaluator,
60
61
  evaluatePortableEvaluator,
62
+ formatTrace,
61
63
  importPortableEvaluator,
62
64
  isEvalDataset,
63
65
  isEvalSuiteDefinition,
@@ -66,7 +68,7 @@ import {
66
68
  traceOutput,
67
69
  traceToolCalls,
68
70
  verifyPortableEvalArtifact
69
- } from "./chunk-UY6537WW.mjs";
71
+ } from "./chunk-X637VXF6.mjs";
70
72
  import "./chunk-UJCSKKID.mjs";
71
73
  export {
72
74
  BooleanThresholdSchema,
@@ -75,6 +77,7 @@ export {
75
77
  DEFAULT_QUERY_URL,
76
78
  DEFAULT_TRACE_WAIT_MS,
77
79
  EVAL_CORRELATION_ID_ATTRIBUTE,
80
+ EvalContextSchema,
78
81
  EvalDatasetPublishConflictError,
79
82
  EvalDatasetRowInputSchema,
80
83
  EvalParameterError,
@@ -110,6 +113,7 @@ export {
110
113
  evaluateEvalRun,
111
114
  evaluatePortableEvaluator,
112
115
  evaluateReplay,
116
+ formatTrace,
113
117
  importPortableEvaluator,
114
118
  isEvalDataset,
115
119
  isEvalSuiteDefinition,