raindrop-ai 0.4.0 → 0.5.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/README.md +168 -0
- package/dist/{chunk-MZZJWWWB.mjs → chunk-AUNFORWV.mjs} +1213 -860
- package/dist/chunk-HFHHGRTW.mjs +1201 -0
- package/dist/index-CQj4bn2v.d.mts +60760 -0
- package/dist/index-CQj4bn2v.d.ts +60760 -0
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +11422 -6431
- package/dist/index.mjs +3397 -176
- package/dist/portable-runtime-GBE3SHBZ.mjs +193 -0
- package/dist/tracing/index.d.mts +2 -1
- package/dist/tracing/index.d.ts +2 -1
- package/dist/tracing/index.js +1301 -982
- package/dist/tracing/index.mjs +1 -1
- package/package.json +19 -12
- package/dist/index-CDmWtd83.d.mts +0 -1525
- package/dist/index-CDmWtd83.d.ts +0 -1525
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import {
|
|
2
|
+
parsePortableEvalResult
|
|
3
|
+
} from "./chunk-HFHHGRTW.mjs";
|
|
4
|
+
import "./chunk-UJCSKKID.mjs";
|
|
5
|
+
|
|
6
|
+
// src/evals/portable-runtime.ts
|
|
7
|
+
import variant from "@jitl/quickjs-singlefile-cjs-release-sync";
|
|
8
|
+
import {
|
|
9
|
+
newQuickJSWASMModuleFromVariant,
|
|
10
|
+
shouldInterruptAfterDeadline
|
|
11
|
+
} from "quickjs-emscripten-core";
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
var DEFAULT_MEMORY_BYTES = 32 * 1024 * 1024;
|
|
14
|
+
var DEFAULT_STACK_BYTES = 64 * 1024;
|
|
15
|
+
var DEFAULT_TIMEOUT_MS = 1e3;
|
|
16
|
+
var DEFAULT_JUDGE_TIMEOUT_MS = 6e4;
|
|
17
|
+
var DEFAULT_JUDGE_REQUEST_TIMEOUT_MS = 3e4;
|
|
18
|
+
var DEFAULT_JUDGE_CONCURRENCY = 4;
|
|
19
|
+
var DEFAULT_MAX_INPUT_BYTES = 4 * 1024 * 1024;
|
|
20
|
+
var DEFAULT_MAX_OUTPUT_BYTES = 4 * 1024 * 1024;
|
|
21
|
+
var JudgeRequestSchema = z.object({
|
|
22
|
+
type: z.literal("judge_request"),
|
|
23
|
+
requestId: z.string(),
|
|
24
|
+
traceId: z.string(),
|
|
25
|
+
rubric: z.string()
|
|
26
|
+
});
|
|
27
|
+
async function runPortableEvaluator(evaluator, input) {
|
|
28
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
29
|
+
const inputJson = JSON.stringify(input);
|
|
30
|
+
const maxInputBytes = (_b = (_a = evaluator.limits) == null ? void 0 : _a.maxInputBytes) != null ? _b : DEFAULT_MAX_INPUT_BYTES;
|
|
31
|
+
if (byteLength(inputJson) > maxInputBytes) {
|
|
32
|
+
throw new Error(`Raindrop portable evaluator input exceeds ${maxInputBytes} bytes`);
|
|
33
|
+
}
|
|
34
|
+
const QuickJS = await newQuickJSWASMModuleFromVariant(variant);
|
|
35
|
+
const runtime = QuickJS.newRuntime();
|
|
36
|
+
runtime.setMemoryLimit((_d = (_c = evaluator.limits) == null ? void 0 : _c.memoryBytes) != null ? _d : DEFAULT_MEMORY_BYTES);
|
|
37
|
+
runtime.setMaxStackSize((_f = (_e = evaluator.limits) == null ? void 0 : _e.stackBytes) != null ? _f : DEFAULT_STACK_BYTES);
|
|
38
|
+
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;
|
|
39
|
+
const deadline = Date.now() + timeoutMs;
|
|
40
|
+
runtime.setInterruptHandler(shouldInterruptAfterDeadline(deadline));
|
|
41
|
+
const context = runtime.newContext();
|
|
42
|
+
const deferreds = [];
|
|
43
|
+
const hostCalls = /* @__PURE__ */ new Set();
|
|
44
|
+
const tracesById = new Map(input.traces.map((trace) => [trace.event.id, trace]));
|
|
45
|
+
const casesByTraceId = new Map(
|
|
46
|
+
input.cases.map((entry) => [entry.candidate.trace.event.id, entry])
|
|
47
|
+
);
|
|
48
|
+
let activeJudgeCalls = 0;
|
|
49
|
+
try {
|
|
50
|
+
const bridge = context.newFunction("__raindrop_eval_judge", (requestHandle) => {
|
|
51
|
+
var _a2, _b2;
|
|
52
|
+
const deferred = context.newPromise();
|
|
53
|
+
deferreds.push(deferred);
|
|
54
|
+
const requestJson = context.getString(requestHandle);
|
|
55
|
+
const judgeConcurrency = (_b2 = (_a2 = evaluator.limits) == null ? void 0 : _a2.judgeConcurrency) != null ? _b2 : DEFAULT_JUDGE_CONCURRENCY;
|
|
56
|
+
let acquired = false;
|
|
57
|
+
const hostCall = resolveJudge(
|
|
58
|
+
evaluator,
|
|
59
|
+
requestJson,
|
|
60
|
+
Math.max(1, deadline - Date.now()),
|
|
61
|
+
tracesById,
|
|
62
|
+
casesByTraceId,
|
|
63
|
+
() => {
|
|
64
|
+
if (activeJudgeCalls >= judgeConcurrency) return false;
|
|
65
|
+
activeJudgeCalls += 1;
|
|
66
|
+
acquired = true;
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
).then((responseJson) => {
|
|
70
|
+
const response = context.newString(responseJson);
|
|
71
|
+
try {
|
|
72
|
+
deferred.resolve(response);
|
|
73
|
+
} finally {
|
|
74
|
+
response.dispose();
|
|
75
|
+
}
|
|
76
|
+
}).finally(() => {
|
|
77
|
+
if (acquired) activeJudgeCalls -= 1;
|
|
78
|
+
hostCalls.delete(hostCall);
|
|
79
|
+
});
|
|
80
|
+
hostCalls.add(hostCall);
|
|
81
|
+
return deferred.handle;
|
|
82
|
+
});
|
|
83
|
+
context.setProp(context.global, "__raindrop_eval_judge", bridge);
|
|
84
|
+
bridge.dispose();
|
|
85
|
+
const loaded = context.evalCode(evaluator.artifact.source, "raindrop-evaluator.js");
|
|
86
|
+
context.unwrapResult(loaded).dispose();
|
|
87
|
+
const entrypoint = context.getProp(context.global, "__raindrop_eval_run");
|
|
88
|
+
const inputHandle = context.newString(inputJson);
|
|
89
|
+
let promiseHandle;
|
|
90
|
+
try {
|
|
91
|
+
promiseHandle = context.unwrapResult(
|
|
92
|
+
context.callFunction(entrypoint, context.global, inputHandle)
|
|
93
|
+
);
|
|
94
|
+
} finally {
|
|
95
|
+
inputHandle.dispose();
|
|
96
|
+
entrypoint.dispose();
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
const result = await drivePromise(runtime, context, promiseHandle, deadline);
|
|
100
|
+
const outputHandle = context.unwrapResult(result);
|
|
101
|
+
try {
|
|
102
|
+
const outputJson = context.getString(outputHandle);
|
|
103
|
+
const maxOutputBytes = (_j = (_i = evaluator.limits) == null ? void 0 : _i.maxOutputBytes) != null ? _j : DEFAULT_MAX_OUTPUT_BYTES;
|
|
104
|
+
if (byteLength(outputJson) > maxOutputBytes) {
|
|
105
|
+
throw new Error(`Raindrop portable evaluator output exceeds ${maxOutputBytes} bytes`);
|
|
106
|
+
}
|
|
107
|
+
const envelope = JSON.parse(outputJson);
|
|
108
|
+
if (typeof envelope !== "object" || envelope === null || !("type" in envelope) || envelope.type !== "result" || !("result" in envelope)) {
|
|
109
|
+
throw new Error("Raindrop portable evaluator returned an invalid result envelope");
|
|
110
|
+
}
|
|
111
|
+
return parsePortableEvalResult(envelope.result);
|
|
112
|
+
} finally {
|
|
113
|
+
outputHandle.dispose();
|
|
114
|
+
}
|
|
115
|
+
} finally {
|
|
116
|
+
promiseHandle.dispose();
|
|
117
|
+
}
|
|
118
|
+
} catch (cause) {
|
|
119
|
+
const message = cause instanceof Error ? cause.message : String(cause);
|
|
120
|
+
if (Date.now() >= deadline || message.includes("interrupted")) {
|
|
121
|
+
throw new Error(`Raindrop portable evaluator exceeded ${timeoutMs}ms`);
|
|
122
|
+
}
|
|
123
|
+
throw new Error(`Raindrop portable evaluator failed: ${message}`);
|
|
124
|
+
} finally {
|
|
125
|
+
await Promise.allSettled([...hostCalls]);
|
|
126
|
+
for (const deferred of deferreds) deferred.dispose();
|
|
127
|
+
context.dispose();
|
|
128
|
+
runtime.dispose();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
async function drivePromise(runtime, context, promise, deadline) {
|
|
132
|
+
while (true) {
|
|
133
|
+
runtime.executePendingJobs(100).unwrap();
|
|
134
|
+
const state = context.getPromiseState(promise);
|
|
135
|
+
if (state.type === "fulfilled") return { value: state.value };
|
|
136
|
+
if (state.type === "rejected") return { error: state.error };
|
|
137
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
138
|
+
if (Date.now() >= deadline) throw new Error("interrupted");
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
async function resolveJudge(evaluator, rawRequest, remainingMs, tracesById, casesByTraceId, acquire) {
|
|
142
|
+
var _a, _b;
|
|
143
|
+
let requestId = "unknown";
|
|
144
|
+
try {
|
|
145
|
+
const request = JudgeRequestSchema.parse(JSON.parse(rawRequest));
|
|
146
|
+
requestId = request.requestId;
|
|
147
|
+
const trace = tracesById.get(request.traceId);
|
|
148
|
+
if (!trace) throw new Error("Judge trace is outside this run");
|
|
149
|
+
if (!evaluator.judge) throw new Error("Judge unavailable");
|
|
150
|
+
if (!acquire()) throw new Error("Judge concurrency exceeded");
|
|
151
|
+
const controller = new AbortController();
|
|
152
|
+
const timeoutMs = Math.min(
|
|
153
|
+
(_b = (_a = evaluator.limits) == null ? void 0 : _a.judgeTimeoutMs) != null ? _b : DEFAULT_JUDGE_REQUEST_TIMEOUT_MS,
|
|
154
|
+
remainingMs
|
|
155
|
+
);
|
|
156
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
157
|
+
const result = await Promise.race([
|
|
158
|
+
Promise.resolve().then(
|
|
159
|
+
() => {
|
|
160
|
+
var _a2;
|
|
161
|
+
return (_a2 = evaluator.judge) == null ? void 0 : _a2.call(evaluator, {
|
|
162
|
+
trace,
|
|
163
|
+
tracePair: casesByTraceId.get(request.traceId),
|
|
164
|
+
rubric: request.rubric.slice(0, 4e4),
|
|
165
|
+
signal: controller.signal
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
),
|
|
169
|
+
new Promise((_resolve, reject) => {
|
|
170
|
+
controller.signal.addEventListener(
|
|
171
|
+
"abort",
|
|
172
|
+
() => reject(new Error(`Judge exceeded ${timeoutMs}ms`)),
|
|
173
|
+
{ once: true }
|
|
174
|
+
);
|
|
175
|
+
})
|
|
176
|
+
]).finally(() => clearTimeout(timeout));
|
|
177
|
+
if (typeof result !== "object" || result === null) throw new Error("invalid judge response");
|
|
178
|
+
return JSON.stringify({ type: "judge_response", requestId, status: "completed", result });
|
|
179
|
+
} catch (e) {
|
|
180
|
+
return JSON.stringify({
|
|
181
|
+
type: "judge_response",
|
|
182
|
+
requestId,
|
|
183
|
+
status: "unavailable",
|
|
184
|
+
message: "Judge unavailable"
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
function byteLength(value) {
|
|
189
|
+
return new TextEncoder().encode(value).byteLength;
|
|
190
|
+
}
|
|
191
|
+
export {
|
|
192
|
+
runPortableEvaluator
|
|
193
|
+
};
|
package/dist/tracing/index.d.mts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Instrumentation } from '@opentelemetry/instrumentation';
|
|
2
|
-
import { R as Raindrop, I as InitializeOptions, S as SpanProcessorOptions, a as RaindropSpanProcessor, P as PartialAiTrackEvent, b as Interaction, A as AiTrackUsage, C as CarrierHeaders, T as TraceCarrier, c as SubagentResumeOptions, d as SubagentRun, e as Tracer } from '../index-
|
|
2
|
+
import { R as Raindrop, I as InitializeOptions, S as SpanProcessorOptions, a as RaindropSpanProcessor, P as PartialAiTrackEvent, b as Interaction, A as AiTrackUsage, C as CarrierHeaders, T as TraceCarrier, c as SubagentResumeOptions, d as SubagentRun, e as Tracer } from '../index-CQj4bn2v.mjs';
|
|
3
3
|
import '@opentelemetry/api';
|
|
4
4
|
import 'zod';
|
|
5
5
|
import '@opentelemetry/sdk-trace-base';
|
|
6
|
+
import './eval-scope-BYkhP4uI.js';
|
|
6
7
|
|
|
7
8
|
interface TracingOptions extends InitializeOptions {
|
|
8
9
|
/**
|
package/dist/tracing/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Instrumentation } from '@opentelemetry/instrumentation';
|
|
2
|
-
import { R as Raindrop, I as InitializeOptions, S as SpanProcessorOptions, a as RaindropSpanProcessor, P as PartialAiTrackEvent, b as Interaction, A as AiTrackUsage, C as CarrierHeaders, T as TraceCarrier, c as SubagentResumeOptions, d as SubagentRun, e as Tracer } from '../index-
|
|
2
|
+
import { R as Raindrop, I as InitializeOptions, S as SpanProcessorOptions, a as RaindropSpanProcessor, P as PartialAiTrackEvent, b as Interaction, A as AiTrackUsage, C as CarrierHeaders, T as TraceCarrier, c as SubagentResumeOptions, d as SubagentRun, e as Tracer } from '../index-CQj4bn2v.js';
|
|
3
3
|
import '@opentelemetry/api';
|
|
4
4
|
import 'zod';
|
|
5
5
|
import '@opentelemetry/sdk-trace-base';
|
|
6
|
+
import './eval-scope-BYkhP4uI.js';
|
|
6
7
|
|
|
7
8
|
interface TracingOptions extends InitializeOptions {
|
|
8
9
|
/**
|