raindrop-ai 3.0.0 → 3.0.1
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-CSH7U5JZ.mjs → chunk-HKOAIPQF.mjs} +246 -50
- package/dist/{chunk-BU322D7Q.mjs → chunk-Q2I2277O.mjs} +2 -2
- package/dist/{chunk-24GTHPYP.mjs → chunk-RSUQ3BU2.mjs} +2 -2
- package/dist/{chunk-XAV5H3AL.mjs → chunk-XN3N4TAL.mjs} +3 -3
- package/dist/evals/cli.js +416 -88
- package/dist/evals/cli.mjs +143 -9
- package/dist/index.js +278 -82
- package/dist/index.mjs +4 -4
- package/dist/{portable-runtime-G27RYK6P.mjs → portable-runtime-HVIGFQHE.mjs} +2 -2
- package/dist/tracing/index.js +11 -9
- package/dist/tracing/index.mjs +2 -2
- package/package.json +2 -2
package/dist/evals/cli.mjs
CHANGED
|
@@ -1,23 +1,126 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
+
DEFAULT_QUERY_URL,
|
|
3
4
|
index_default,
|
|
4
5
|
publishEvalSuite,
|
|
5
6
|
readEvaluator,
|
|
6
7
|
runEvalSuite
|
|
7
|
-
} from "../chunk-
|
|
8
|
-
import "../chunk-
|
|
8
|
+
} from "../chunk-XN3N4TAL.mjs";
|
|
9
|
+
import "../chunk-RSUQ3BU2.mjs";
|
|
9
10
|
import {
|
|
11
|
+
credentialEndpoint,
|
|
10
12
|
isEvalSuiteDefinition
|
|
11
|
-
} from "../chunk-
|
|
12
|
-
import
|
|
13
|
+
} from "../chunk-Q2I2277O.mjs";
|
|
14
|
+
import {
|
|
15
|
+
runWithTracingSuppressed
|
|
16
|
+
} from "../chunk-HKOAIPQF.mjs";
|
|
13
17
|
|
|
14
18
|
// src/evals/cli.ts
|
|
15
19
|
import { resolve } from "path";
|
|
16
20
|
import { pathToFileURL } from "url";
|
|
17
21
|
import { parseArgs } from "util";
|
|
22
|
+
import { z as z2 } from "zod/v4";
|
|
23
|
+
|
|
24
|
+
// src/evals/endpoint.ts
|
|
18
25
|
import { z } from "zod/v4";
|
|
19
|
-
var
|
|
20
|
-
|
|
26
|
+
var SavedEvalEndpointSchema = z.object({
|
|
27
|
+
id: z.string(),
|
|
28
|
+
name: z.string(),
|
|
29
|
+
url: z.string(),
|
|
30
|
+
hasCredentials: z.boolean(),
|
|
31
|
+
agents: z.array(
|
|
32
|
+
z.object({ slug: z.string(), name: z.string(), description: z.string().nullable() })
|
|
33
|
+
),
|
|
34
|
+
discoveryError: z.string().nullable()
|
|
35
|
+
});
|
|
36
|
+
var ENDPOINT_VARIABLE_PREFIX = "EVAL_ENDPOINT_";
|
|
37
|
+
function evalEndpointQueryUrl(value = DEFAULT_QUERY_URL) {
|
|
38
|
+
const url = credentialEndpoint(value);
|
|
39
|
+
const loopback = ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
|
|
40
|
+
if (!loopback && !(url.protocol === "https:" && url.hostname.endsWith(".raindrop.ai")))
|
|
41
|
+
throw new Error(
|
|
42
|
+
"endpoint save only sends the auth header to https://*.raindrop.ai or a loopback Query API"
|
|
43
|
+
);
|
|
44
|
+
return url;
|
|
45
|
+
}
|
|
46
|
+
var bareToken = (value) => value.trim().replace(/^Bearer\s+/i, "").trim();
|
|
47
|
+
function evalEndpointHeaderFromEnv(flags, env = process.env) {
|
|
48
|
+
var _a;
|
|
49
|
+
const { bearerEnv, headerName, headerValueEnv } = flags;
|
|
50
|
+
if (bearerEnv !== void 0 && (headerName !== void 0 || headerValueEnv !== void 0))
|
|
51
|
+
throw new Error("Use --bearer-env, or --header-name with --header-value-env, not both");
|
|
52
|
+
if (headerName === void 0 !== (headerValueEnv === void 0))
|
|
53
|
+
throw new Error("--header-name and --header-value-env go together");
|
|
54
|
+
const variable = bearerEnv != null ? bearerEnv : headerValueEnv;
|
|
55
|
+
if (variable === void 0) return void 0;
|
|
56
|
+
if (!variable.startsWith(ENDPOINT_VARIABLE_PREFIX))
|
|
57
|
+
throw new Error(
|
|
58
|
+
`--bearer-env and --header-value-env only read variables named ${ENDPOINT_VARIABLE_PREFIX}*, such as EVAL_ENDPOINT_TOKEN`
|
|
59
|
+
);
|
|
60
|
+
const value = env[variable];
|
|
61
|
+
if (value === void 0 || value.trim() === "")
|
|
62
|
+
throw new Error(`Environment variable ${variable} is not set`);
|
|
63
|
+
if (bareToken(value) === bareToken((_a = env.RAINDROP_QUERY_API_KEY) != null ? _a : ""))
|
|
64
|
+
throw new Error(
|
|
65
|
+
`Environment variable ${variable} holds the Raindrop Query key; use the endpoint's own token`
|
|
66
|
+
);
|
|
67
|
+
return bearerEnv !== void 0 ? { Authorization: `Bearer ${value}` } : { [headerName != null ? headerName : "Authorization"]: value };
|
|
68
|
+
}
|
|
69
|
+
async function saveEvalEndpoint(client, endpoint, options = {}) {
|
|
70
|
+
var _a, _b;
|
|
71
|
+
const apiKey = (_a = client.connection.apiKey) == null ? void 0 : _a.trim();
|
|
72
|
+
if (!apiKey) throw new Error("Raindrop evals require a Query SDK API key (apiKey)");
|
|
73
|
+
const base = evalEndpointQueryUrl(options.queryUrl).href.replace(/\/+$/, "");
|
|
74
|
+
const headers = {
|
|
75
|
+
Authorization: `Bearer ${apiKey}`,
|
|
76
|
+
"Content-Type": "application/json"
|
|
77
|
+
};
|
|
78
|
+
if (client.connection.projectId !== void 0)
|
|
79
|
+
headers["X-Raindrop-Project-Id"] = client.connection.projectId;
|
|
80
|
+
const secrets = [
|
|
81
|
+
apiKey,
|
|
82
|
+
...Object.values((_b = endpoint.headers) != null ? _b : {}).flatMap((value) => [
|
|
83
|
+
value,
|
|
84
|
+
value.trim(),
|
|
85
|
+
value.replace(/^Bearer\s+/i, "").trim()
|
|
86
|
+
])
|
|
87
|
+
].filter((secret) => secret !== "").flatMap((secret) => [secret, JSON.stringify(secret).slice(1, -1)]);
|
|
88
|
+
const redact = (text) => secrets.reduce((redacted, secret) => redacted.replaceAll(secret, "[redacted]"), text);
|
|
89
|
+
const controller = new AbortController();
|
|
90
|
+
const timeout = setTimeout(() => controller.abort(), 3e4);
|
|
91
|
+
try {
|
|
92
|
+
const response = await runWithTracingSuppressed(
|
|
93
|
+
() => fetch(`${base}/v1/eval-endpoints`, {
|
|
94
|
+
method: "PUT",
|
|
95
|
+
headers,
|
|
96
|
+
body: JSON.stringify(endpoint),
|
|
97
|
+
redirect: "error",
|
|
98
|
+
signal: controller.signal
|
|
99
|
+
})
|
|
100
|
+
);
|
|
101
|
+
const body = await response.text();
|
|
102
|
+
if (!response.ok)
|
|
103
|
+
throw new Error(`Raindrop PUT /v1/eval-endpoints: ${response.status} ${redact(body)}`);
|
|
104
|
+
const saved = SavedEvalEndpointSchema.parse(JSON.parse(body));
|
|
105
|
+
return {
|
|
106
|
+
...saved,
|
|
107
|
+
agents: saved.agents.map((agent) => ({
|
|
108
|
+
slug: redact(agent.slug),
|
|
109
|
+
name: redact(agent.name),
|
|
110
|
+
description: agent.description === null ? null : redact(agent.description)
|
|
111
|
+
})),
|
|
112
|
+
discoveryError: saved.discoveryError === null ? null : redact(saved.discoveryError)
|
|
113
|
+
};
|
|
114
|
+
} catch (error) {
|
|
115
|
+
throw new Error(redact(error instanceof Error ? error.message : String(error)));
|
|
116
|
+
} finally {
|
|
117
|
+
clearTimeout(timeout);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// src/evals/cli.ts
|
|
122
|
+
var SuiteModuleSchema = z2.object({
|
|
123
|
+
default: z2.custom(isEvalSuiteDefinition)
|
|
21
124
|
});
|
|
22
125
|
async function main() {
|
|
23
126
|
var _a, _b;
|
|
@@ -29,18 +132,29 @@ async function main() {
|
|
|
29
132
|
"replay-ingest-url": { type: "string" },
|
|
30
133
|
"run-id": { type: "string" },
|
|
31
134
|
repetitions: { type: "string" },
|
|
135
|
+
id: { type: "string" },
|
|
136
|
+
name: { type: "string" },
|
|
137
|
+
url: { type: "string" },
|
|
138
|
+
"bearer-env": { type: "string" },
|
|
139
|
+
"header-name": { type: "string" },
|
|
140
|
+
"header-value-env": { type: "string" },
|
|
32
141
|
json: { type: "boolean" },
|
|
33
142
|
help: { type: "boolean" }
|
|
34
143
|
}
|
|
35
144
|
});
|
|
36
|
-
const [command, file] = positionals;
|
|
145
|
+
const [command, file, extra] = positionals;
|
|
37
146
|
if (values.help || !command) {
|
|
38
147
|
process.stdout.write(
|
|
39
148
|
[
|
|
40
149
|
"raindrop-evals publish <suite.mjs> [--project slug] [--json]",
|
|
41
150
|
"raindrop-evals run <suite.mjs> [--run-id queued-run-id] [--repetitions n] [--project slug] [--json]",
|
|
42
151
|
"raindrop-evals read <evaluator-slug> [--json]",
|
|
152
|
+
"raindrop-evals endpoint save --name <name> --url <https url> [--bearer-env EVAL_ENDPOINT_<NAME> | --header-name <name> --header-value-env EVAL_ENDPOINT_<NAME>] [--id endpoint-id]",
|
|
43
153
|
"",
|
|
154
|
+
"endpoint save stores an agent endpoint and lists its agents. --bearer-env names the environment",
|
|
155
|
+
"variable holding the endpoint's token (sent as Authorization: Bearer <value>); the value is read",
|
|
156
|
+
"from the environment and never printed. Only variables named EVAL_ENDPOINT_* are read.",
|
|
157
|
+
"Without a header flag, saved headers are kept.",
|
|
44
158
|
"Publish resolves the dataset version and pins existing evaluators without running them.",
|
|
45
159
|
"The module must default-export defineEvalSuite(...) with a dataset UUID from list_datasets.",
|
|
46
160
|
"Create datasets with the Raindrop app or MCP upload_dataset, and hosted evaluators in Raindrop.",
|
|
@@ -55,10 +169,14 @@ async function main() {
|
|
|
55
169
|
);
|
|
56
170
|
return;
|
|
57
171
|
}
|
|
58
|
-
if (!file || !["publish", "run", "read"].includes(command))
|
|
172
|
+
if (!file || !["publish", "run", "read", "endpoint"].includes(command))
|
|
59
173
|
throw new Error("Invalid command. Use --help.");
|
|
60
174
|
const apiKey = process.env.RAINDROP_QUERY_API_KEY;
|
|
61
175
|
if (!apiKey) throw new Error("Set RAINDROP_QUERY_API_KEY to a Query SDK organization key");
|
|
176
|
+
if (command === "endpoint" && extra !== void 0)
|
|
177
|
+
throw new Error("endpoint save takes flags only; pass the endpoint ID as --id");
|
|
178
|
+
if (command === "endpoint") evalEndpointQueryUrl(values["query-url"]);
|
|
179
|
+
const endpoint = command === "endpoint" ? endpointFromFlags(file, values) : void 0;
|
|
62
180
|
const client = new index_default({
|
|
63
181
|
apiKey,
|
|
64
182
|
projectId: (_b = (_a = values.project) != null ? _a : process.env.RAINDROP_PROJECT_ID) != null ? _b : "default",
|
|
@@ -66,7 +184,9 @@ async function main() {
|
|
|
66
184
|
});
|
|
67
185
|
const options = { queryUrl: values["query-url"] };
|
|
68
186
|
try {
|
|
69
|
-
if (
|
|
187
|
+
if (endpoint) {
|
|
188
|
+
print(await saveEvalEndpoint(client, endpoint, options));
|
|
189
|
+
} else if (command === "read") {
|
|
70
190
|
print(await readEvaluator(client, file, options));
|
|
71
191
|
} else {
|
|
72
192
|
const module = SuiteModuleSchema.parse(await import(pathToFileURL(resolve(file)).href));
|
|
@@ -107,6 +227,20 @@ async function main() {
|
|
|
107
227
|
await client.close();
|
|
108
228
|
}
|
|
109
229
|
}
|
|
230
|
+
function endpointFromFlags(action, flags) {
|
|
231
|
+
if (action !== "save") throw new Error("Invalid command. Use --help.");
|
|
232
|
+
if (!flags.name || !flags.url) throw new Error("endpoint save requires --name and --url");
|
|
233
|
+
return {
|
|
234
|
+
id: flags.id,
|
|
235
|
+
name: flags.name,
|
|
236
|
+
url: flags.url,
|
|
237
|
+
headers: evalEndpointHeaderFromEnv({
|
|
238
|
+
bearerEnv: flags["bearer-env"],
|
|
239
|
+
headerName: flags["header-name"],
|
|
240
|
+
headerValueEnv: flags["header-value-env"]
|
|
241
|
+
})
|
|
242
|
+
};
|
|
243
|
+
}
|
|
110
244
|
function print(value) {
|
|
111
245
|
process.stdout.write(JSON.stringify(value, null, 2) + "\n");
|
|
112
246
|
}
|