@frogbotai/plugin-ai-evals 0.0.0-stage → 0.43.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.
@@ -0,0 +1,367 @@
1
+ import { APIError } from 'frogbot';
2
+ export const DATASETS = 'eval-datasets';
3
+ export const CASES = 'eval-cases';
4
+ export const RUNS = 'eval-runs';
5
+ export const RESULTS = 'eval-results';
6
+ export const WORKFLOW = 'frogbot-eval-run';
7
+ /** Set on the plugin's own writes to a run, so its hooks leave them alone. */ export const PLUGIN_WRITE = 'pluginEvalsWrite';
8
+ const group = 'Evals';
9
+ const runOwned = [
10
+ 'dataset',
11
+ 'agent',
12
+ 'model',
13
+ 'status',
14
+ 'total',
15
+ 'passed',
16
+ 'errored',
17
+ 'score',
18
+ 'scorerMeans',
19
+ 'startedAt',
20
+ 'finishedAt'
21
+ ];
22
+ export function runJobID(run) {
23
+ return `${WORKFLOW}:${run}`;
24
+ }
25
+ export function toID(value) {
26
+ if (typeof value === 'object' && value !== null) return value.id;
27
+ return value;
28
+ }
29
+ const prepareRun = async ({ data, operation, originalDoc, req, context })=>{
30
+ if (context[PLUGIN_WRITE]) return data;
31
+ if (operation === 'update') {
32
+ const kept = originalDoc;
33
+ return {
34
+ ...data,
35
+ ...Object.fromEntries(runOwned.map((name)=>[
36
+ name,
37
+ kept[name]
38
+ ]))
39
+ };
40
+ }
41
+ const datasetID = toID(data.dataset);
42
+ const dataset = datasetID === undefined ? null : await req.frogbot.findByID({
43
+ collection: DATASETS,
44
+ id: datasetID,
45
+ depth: 0,
46
+ disableErrors: true,
47
+ overrideAccess: true,
48
+ req
49
+ });
50
+ const agent = dataset?.agent ? req.frogbot.agents[dataset.agent] : undefined;
51
+ if (!agent) throw new APIError(`Dataset '${String(datasetID)}' has no agent.`, 400);
52
+ const model = typeof data.model === 'string' && data.model !== '' ? data.model : undefined;
53
+ if (model !== undefined && !agent.config.model.options.some((option)=>option === model)) {
54
+ throw new APIError(`Model '${model}' isn't one of agent '${agent.slug}''s models.`, 400);
55
+ }
56
+ return {
57
+ ...data,
58
+ agent: agent.slug,
59
+ model: model ?? null,
60
+ status: 'queued',
61
+ total: null,
62
+ passed: null,
63
+ errored: null,
64
+ score: null,
65
+ scorerMeans: null,
66
+ startedAt: null,
67
+ finishedAt: null
68
+ };
69
+ };
70
+ const queueRun = async ({ doc, operation, req, context })=>{
71
+ if (operation !== 'create' || context[PLUGIN_WRITE]) return doc;
72
+ const id = doc.id;
73
+ const input = {
74
+ run: id,
75
+ ...req.user ? {
76
+ userCollection: String(req.user.collection),
77
+ userID: req.user.id
78
+ } : {}
79
+ };
80
+ await req.frogbot.jobs.queue({
81
+ workflow: WORKFLOW,
82
+ input,
83
+ jobId: runJobID(id),
84
+ overrideAccess: true,
85
+ req
86
+ });
87
+ return doc;
88
+ };
89
+ export function createEvalCollections({ agents, scorers, access }) {
90
+ const shared = {
91
+ ...access ? {
92
+ access
93
+ } : {}
94
+ };
95
+ const readOnly = {
96
+ readOnly: true
97
+ };
98
+ return [
99
+ {
100
+ slug: DATASETS,
101
+ ...shared,
102
+ labels: {
103
+ singular: 'Eval dataset',
104
+ plural: 'Eval datasets'
105
+ },
106
+ admin: {
107
+ group,
108
+ icon: 'database',
109
+ useAsTitle: 'name'
110
+ },
111
+ fields: [
112
+ {
113
+ name: 'name',
114
+ type: 'text',
115
+ required: true,
116
+ unique: true
117
+ },
118
+ {
119
+ name: 'agent',
120
+ type: 'select',
121
+ required: true,
122
+ options: [
123
+ ...agents
124
+ ]
125
+ },
126
+ {
127
+ name: 'scorers',
128
+ type: 'select',
129
+ hasMany: true,
130
+ required: true,
131
+ options: [
132
+ ...scorers
133
+ ]
134
+ }
135
+ ]
136
+ },
137
+ {
138
+ slug: CASES,
139
+ ...shared,
140
+ labels: {
141
+ singular: 'Eval case',
142
+ plural: 'Eval cases'
143
+ },
144
+ admin: {
145
+ group,
146
+ icon: 'check-list',
147
+ useAsTitle: 'input'
148
+ },
149
+ fields: [
150
+ {
151
+ name: 'dataset',
152
+ type: 'relationship',
153
+ relationTo: DATASETS,
154
+ required: true,
155
+ index: true
156
+ },
157
+ {
158
+ name: 'input',
159
+ type: 'textarea',
160
+ required: true
161
+ },
162
+ {
163
+ name: 'expected',
164
+ type: 'textarea'
165
+ },
166
+ {
167
+ name: 'expectedTools',
168
+ type: 'text',
169
+ hasMany: true
170
+ },
171
+ {
172
+ name: 'metadata',
173
+ type: 'json'
174
+ }
175
+ ]
176
+ },
177
+ {
178
+ slug: RUNS,
179
+ ...shared,
180
+ labels: {
181
+ singular: 'Eval run',
182
+ plural: 'Eval runs'
183
+ },
184
+ admin: {
185
+ group,
186
+ icon: 'chart-bar',
187
+ views: [
188
+ {
189
+ type: 'list',
190
+ defaultFields: [
191
+ 'dataset',
192
+ 'model',
193
+ 'status',
194
+ 'score',
195
+ 'passed',
196
+ 'total',
197
+ 'createdAt'
198
+ ]
199
+ }
200
+ ]
201
+ },
202
+ hooks: {
203
+ beforeChange: [
204
+ prepareRun
205
+ ],
206
+ afterChange: [
207
+ queueRun
208
+ ]
209
+ },
210
+ fields: [
211
+ {
212
+ name: 'dataset',
213
+ type: 'relationship',
214
+ relationTo: DATASETS,
215
+ required: true,
216
+ index: true
217
+ },
218
+ {
219
+ name: 'agent',
220
+ type: 'text',
221
+ admin: readOnly
222
+ },
223
+ {
224
+ name: 'model',
225
+ type: 'text',
226
+ admin: {
227
+ description: "One of the agent's models. Empty uses its default."
228
+ }
229
+ },
230
+ {
231
+ name: 'status',
232
+ type: 'select',
233
+ options: [
234
+ 'queued',
235
+ 'running',
236
+ 'completed',
237
+ 'failed'
238
+ ],
239
+ defaultValue: 'queued',
240
+ index: true,
241
+ admin: readOnly
242
+ },
243
+ {
244
+ name: 'total',
245
+ type: 'number',
246
+ admin: readOnly
247
+ },
248
+ {
249
+ name: 'passed',
250
+ type: 'number',
251
+ admin: readOnly
252
+ },
253
+ {
254
+ name: 'errored',
255
+ type: 'number',
256
+ admin: readOnly
257
+ },
258
+ {
259
+ name: 'score',
260
+ type: 'number',
261
+ min: 0,
262
+ max: 1,
263
+ admin: readOnly
264
+ },
265
+ {
266
+ name: 'scorerMeans',
267
+ type: 'json',
268
+ admin: readOnly
269
+ },
270
+ {
271
+ name: 'startedAt',
272
+ type: 'date',
273
+ admin: readOnly
274
+ },
275
+ {
276
+ name: 'finishedAt',
277
+ type: 'date',
278
+ admin: readOnly
279
+ }
280
+ ]
281
+ },
282
+ {
283
+ slug: RESULTS,
284
+ ...shared,
285
+ authorship: false,
286
+ labels: {
287
+ singular: 'Eval result',
288
+ plural: 'Eval results'
289
+ },
290
+ admin: {
291
+ group,
292
+ icon: 'checkmark-circle'
293
+ },
294
+ fields: [
295
+ {
296
+ name: 'run',
297
+ type: 'relationship',
298
+ relationTo: RUNS,
299
+ required: true,
300
+ index: true
301
+ },
302
+ {
303
+ name: 'case',
304
+ type: 'relationship',
305
+ relationTo: CASES,
306
+ index: true
307
+ },
308
+ {
309
+ name: 'caseSnapshot',
310
+ type: 'json',
311
+ admin: readOnly
312
+ },
313
+ {
314
+ name: 'output',
315
+ type: 'textarea',
316
+ admin: readOnly
317
+ },
318
+ {
319
+ name: 'toolCalls',
320
+ type: 'json',
321
+ admin: readOnly
322
+ },
323
+ {
324
+ name: 'usage',
325
+ type: 'json',
326
+ admin: readOnly
327
+ },
328
+ {
329
+ name: 'durationMs',
330
+ type: 'number',
331
+ admin: readOnly
332
+ },
333
+ {
334
+ name: 'error',
335
+ type: 'textarea',
336
+ admin: readOnly
337
+ },
338
+ {
339
+ name: 'scores',
340
+ type: 'array',
341
+ admin: readOnly,
342
+ fields: [
343
+ {
344
+ name: 'scorer',
345
+ type: 'text',
346
+ required: true
347
+ },
348
+ {
349
+ name: 'score',
350
+ type: 'number'
351
+ },
352
+ {
353
+ name: 'reason',
354
+ type: 'textarea'
355
+ },
356
+ {
357
+ name: 'error',
358
+ type: 'textarea'
359
+ }
360
+ ]
361
+ }
362
+ ]
363
+ }
364
+ ];
365
+ }
366
+
367
+ //# sourceMappingURL=collections.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/collections.ts"],"names":["APIError","DATASETS","CASES","RUNS","RESULTS","WORKFLOW","PLUGIN_WRITE","group","runOwned","runJobID","run","toID","value","id","prepareRun","data","operation","originalDoc","req","context","kept","Object","fromEntries","map","name","datasetID","dataset","undefined","frogbot","findByID","collection","depth","disableErrors","overrideAccess","agent","agents","String","model","config","options","some","option","slug","status","total","passed","errored","score","scorerMeans","startedAt","finishedAt","queueRun","doc","input","user","userCollection","userID","jobs","queue","workflow","jobId","createEvalCollections","scorers","access","shared","readOnly","labels","singular","plural","admin","icon","useAsTitle","fields","type","required","unique","hasMany","relationTo","index","views","defaultFields","hooks","beforeChange","afterChange","description","defaultValue","min","max","authorship"],"mappings":"AAOA,SAASA,QAAQ,QAAQ,UAAU;AAEnC,OAAO,MAAMC,WAAW,gBAAgB;AACxC,OAAO,MAAMC,QAAQ,aAAa;AAClC,OAAO,MAAMC,OAAO,YAAY;AAChC,OAAO,MAAMC,UAAU,eAAe;AACtC,OAAO,MAAMC,WAAW,mBAAmB;AAE3C,4EAA4E,GAC5E,OAAO,MAAMC,eAAe,mBAAmB;AAE/C,MAAMC,QAAQ;AAQd,MAAMC,WAAW;IACf;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED,OAAO,SAASC,SAASC,GAAU;IACjC,OAAO,GAAGL,SAAS,CAAC,EAAEK,KAAK;AAC7B;AAEA,OAAO,SAASC,KAAKC,KAAc;IACjC,IAAI,OAAOA,UAAU,YAAYA,UAAU,MAAM,OAAO,AAACA,MAAyBC,EAAE;IAEpF,OAAOD;AACT;AAEA,MAAME,aAAyC,OAAO,EACpDC,IAAI,EACJC,SAAS,EACTC,WAAW,EACXC,GAAG,EACHC,OAAO,EACR;IACC,IAAIA,OAAO,CAACb,aAAa,EAAE,OAAOS;IAElC,IAAIC,cAAc,UAAU;QAC1B,MAAMI,OAAOH;Q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AACH","file":"collections.js"}
@@ -0,0 +1,14 @@
1
+ import { type Plugin } from 'frogbot';
2
+ import type { AIEvalsPluginOptions, EvalsResolvedOptions } from './options.js';
3
+ export { checks } from './checks.js';
4
+ export { judge } from './judge.js';
5
+ export type { AIEvalsPluginOptions } from './options.js';
6
+ export type { EvalToolCall, Scorer, ScorerArgs, ScoreResult, ScorerFunction } from './scorers.js';
7
+ export { defineScorer } from './scorers.js';
8
+ declare module 'frogbot' {
9
+ interface RegisteredPlugins {
10
+ 'plugin-ai-evals': EvalsResolvedOptions;
11
+ }
12
+ }
13
+ export declare function aiEvalsPlugin(options: AIEvalsPluginOptions): Plugin;
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,MAAM,EAAE,MAAM,SAAS,CAAC;AAIpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAI/E,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,YAAY,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACzD,YAAY,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAClG,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,QAAQ,SAAS,CAAC;IACvB,UAAU,iBAAiB;QACzB,iBAAiB,EAAE,oBAAoB,CAAC;KACzC;CACF;AA2CD,wBAAgB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,MAAM,CAEnE"}
package/dist/index.js ADDED
@@ -0,0 +1,52 @@
1
+ import { definePlugin } from 'frogbot';
2
+ import { evalsRunCommand } from './cli.js';
3
+ import { createEvalCollections } from './collections.js';
4
+ import { resolveOptions } from './options.js';
5
+ import { createEvalWorkflow } from './workflow.js';
6
+ export { checks } from './checks.js';
7
+ export { judge } from './judge.js';
8
+ export { defineScorer } from './scorers.js';
9
+ const aiEvals = definePlugin({
10
+ slug: 'plugin-ai-evals',
11
+ order: 200,
12
+ plugin: ({ config, options })=>{
13
+ if (!config.ai) throw new Error('[plugin-ai-evals] AI configuration is required.');
14
+ const agents = (config.agents ?? []).map(({ slug })=>slug);
15
+ if (agents.length === 0) {
16
+ throw new Error('[plugin-ai-evals] The config has no agents to evaluate.');
17
+ }
18
+ if (!config.ai.smallModel && Object.values(options.scorers).some((scorer)=>scorer.usesSmallModel)) {
19
+ throw new Error('[plugin-ai-evals] judge() without a model needs ai.smallModel.');
20
+ }
21
+ return {
22
+ ...config,
23
+ collections: [
24
+ ...config.collections,
25
+ ...createEvalCollections({
26
+ agents,
27
+ scorers: Object.keys(options.scorers),
28
+ access: options.access
29
+ })
30
+ ],
31
+ jobs: {
32
+ ...config.jobs,
33
+ workflows: [
34
+ ...config.jobs?.workflows ?? [],
35
+ createEvalWorkflow(options)
36
+ ]
37
+ },
38
+ cli: {
39
+ ...config.cli,
40
+ commands: {
41
+ ...config.cli?.commands,
42
+ 'evals:run': evalsRunCommand
43
+ }
44
+ }
45
+ };
46
+ }
47
+ });
48
+ export function aiEvalsPlugin(options) {
49
+ return aiEvals(resolveOptions(options));
50
+ }
51
+
52
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":["definePlugin","evalsRunCommand","createEvalCollections","resolveOptions","createEvalWorkflow","checks","judge","defineScorer","aiEvals","slug","order","plugin","config","options","ai","Error","agents","map","length","smallModel","Object","values","scorers","some","scorer","usesSmallModel","collections","keys","access","jobs","workflows","cli","commands","aiEvalsPlugin"],"mappings":"AAAA,SAASA,YAAY,QAAqB,UAAU;AAEpD,SAASC,eAAe,QAAQ,WAAW;AAC3C,SAASC,qBAAqB,QAAQ,mBAAmB;AAEzD,SA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ModelId } from 'frogbot';
2
+ import type { Scorer, ScorerArgs } from './scorers.js';
3
+ export declare function judgePrompt({ rubric, input, expected, output, toolCalls, }: Pick<ScorerArgs, 'input' | 'expected' | 'output' | 'toolCalls'> & {
4
+ rubric: string;
5
+ }): string;
6
+ /** Scores each case with one model call against `rubric`, on `model` or else `ai.smallModel`. */
7
+ export declare function judge({ rubric, model }: {
8
+ rubric: string;
9
+ model?: ModelId;
10
+ }): Scorer;
11
+ //# sourceMappingURL=judge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"judge.d.ts","sourceRoot":"","sources":["../src/judge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAIvC,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAavD,wBAAgB,WAAW,CAAC,EAC1B,MAAM,EACN,KAAK,EACL,QAAQ,EACR,MAAM,EACN,SAAS,GACV,EAAE,IAAI,CAAC,UAAU,EAAE,OAAO,GAAG,UAAU,GAAG,QAAQ,GAAG,WAAW,CAAC,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAQ/F;AAED,iGAAiG;AACjG,wBAAgB,KAAK,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,MAAM,CAsBpF"}
package/dist/judge.js ADDED
@@ -0,0 +1,51 @@
1
+ import { Output } from 'frogbot';
2
+ import { z } from 'zod';
3
+ import { defineScorer } from './scorers.js';
4
+ const verdict = z.object({
5
+ score: z.number().min(0).max(1),
6
+ reason: z.string()
7
+ });
8
+ const instructions = [
9
+ "You grade an AI agent's answer against a rubric.",
10
+ 'Give a score from 0 (fails the rubric) to 1 (fully meets it) and a one-sentence reason.'
11
+ ].join(' ');
12
+ export function judgePrompt({ rubric, input, expected, output, toolCalls }) {
13
+ return [
14
+ `<rubric>\n${rubric}\n</rubric>`,
15
+ `<question>\n${input}\n</question>`,
16
+ ...expected === undefined ? [] : [
17
+ `<expected>\n${expected}\n</expected>`
18
+ ],
19
+ `<tool-calls>\n${JSON.stringify(toolCalls, null, 2)}\n</tool-calls>`,
20
+ `<answer>\n${output}\n</answer>`
21
+ ].join('\n\n');
22
+ }
23
+ /** Scores each case with one model call against `rubric`, on `model` or else `ai.smallModel`. */ export function judge({ rubric, model }) {
24
+ const scorer = defineScorer({
25
+ score: async (args)=>{
26
+ const { req, overrideAccess } = args;
27
+ const judgeModel = model ?? req.frogbot.config.ai?.smallModel;
28
+ if (judgeModel === undefined) throw new Error('judge() needs a model or ai.smallModel.');
29
+ const { output } = await req.frogbot.generateText({
30
+ model: judgeModel,
31
+ instructions,
32
+ prompt: judgePrompt({
33
+ rubric,
34
+ ...args
35
+ }),
36
+ output: Output.object({
37
+ schema: verdict
38
+ }),
39
+ req,
40
+ overrideAccess
41
+ });
42
+ return output;
43
+ }
44
+ });
45
+ return model === undefined ? {
46
+ ...scorer,
47
+ usesSmallModel: true
48
+ } : scorer;
49
+ }
50
+
51
+ //# sourceMappingURL=judge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/judge.ts"],"names":["Output","z","defineScorer","verdict","object","score","number","min","max","reason","string","instructions","join","judgePrompt","rubric","input","expected","output","toolCalls","undefined","JSON","stringify","judge","model","scorer","args","req","overrideAccess","judgeModel","frogbot","config","ai","smallModel","Error","generateText","prompt","schema","usesSmallModel"],"mappings":"AACA,SAASA,MAAM,QAAQ,UAAU;AACjC,SAASC,CAAC,QAAQ,MAAM;AAGxB,SAASC,YAAY,QAAQ,eAAe;AAE5C,MAAMC,UAAUF,EAAEG,MAAM,CAAC;IACvBC,OAAOJ,EAAEK,MAAM,GAAGC,GAAG,CAAC,GAAGC,GAAG,CAAC;IAC7BC,QAAQR,EAAES,MAAM;AAClB;AAEA,MAAMC,eAAe;IACnB;IACA;CACD,CAACC,IAAI,CAAC;AAEP,OAAO,SAASC,YAAY,EAC1BC,MAAM,EACNC,KAAK,EACLC,QAAQ,EACRC,MAAM,EACNC,SAAS,EAC4E;IACrF,OAAO;QACL,CAAC,UAAU,EAAEJ,OAAO,WAAW,CAAC;QAChC,CAAC,YAAY,EAAEC,MAAM,aAAa,CAAC;WAC/BC,aAAaG,YAAY,EAAE,GAAG;YAAC,CAAC,YAAY,EAAEH,SAAS,aAAa,CAAC;SAAC;QAC1E,CAAC,cAAc,EAAEI,KAAKC,SAAS,CAACH,WAAW,MAAM,GAAG,eAAe,CAAC;QACpE,CAAC,UAAU,EAAED,OAAO,WAAW,CAAC;KACjC,CAACL,IAAI,CAAC;AACT;AAEA,+FAA+F,GAC/F,OAAO,SAASU,MAAM,EAAER,MAAM,EAAES,KAAK,EAAuC;IAC1E,MAAMC,SAAStB,aAAa;QAC1BG,OAAO,OAAOoB;YACZ,MAAM,EAAEC,GAAG,EAAEC,cAAc,EAAE,GAAGF;YAChC,MAAMG,aAAaL,SAASG,IAAIG,OAAO,CAACC,MAAM,CAACC,EAAE,EAAEC;YAEnD,IAAIJ,eAAeT,WAAW,MAAM,IAAIc,MAAM;YAE9C,MAAM,EAAEhB,MAAM,EAAE,GAAG,MAAMS,IAAIG,OAAO,CAACK,YAAY,CAAC;gBAChDX,OAAOK;gBACPjB;gBACAwB,QAAQtB,YAAY;oBAAEC;oBAAQ,GAAGW,IAAI;gBAAC;gBACtCR,QAAQjB,OAAOI,MAAM,CAAC;oBAAEgC,QAAQjC;gBAAQ;gBACxCuB;gBACAC;YACF;YAEA,OAAOV;QACT;IACF;IAEA,OAAOM,UAAUJ,YAAY;QAAE,GAAGK,MAAM;QAAEa,gBAAgB;IAAK,IAAIb;AACrE","file":"judge.js"}
@@ -0,0 +1,15 @@
1
+ import type { CollectionAccess } from 'frogbot';
2
+ import type { Scorer } from './scorers.js';
3
+ export type AIEvalsPluginOptions = {
4
+ /** Scorers by name. A dataset picks which of them score its cases. */
5
+ scorers: Record<string, Scorer>;
6
+ /** Cases a run scores at once. Default `5`. */
7
+ concurrency?: number;
8
+ /** Access for the four collections. None by default: set your own. */
9
+ access?: CollectionAccess;
10
+ };
11
+ export type EvalsResolvedOptions = AIEvalsPluginOptions & {
12
+ concurrency: number;
13
+ };
14
+ export declare function resolveOptions(options: AIEvalsPluginOptions): EvalsResolvedOptions;
15
+ //# sourceMappingURL=options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAG3C,MAAM,MAAM,oBAAoB,GAAG;IACjC,sEAAsE;IACtE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,+CAA+C;IAC/C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sEAAsE;IACtE,MAAM,CAAC,EAAE,gBAAgB,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,oBAAoB,GAAG;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC;AAElF,wBAAgB,cAAc,CAAC,OAAO,EAAE,oBAAoB,GAAG,oBAAoB,CAoBlF"}
@@ -0,0 +1,20 @@
1
+ import { isScorer } from './scorers.js';
2
+ export function resolveOptions(options) {
3
+ const entries = Object.entries(options?.scorers ?? {});
4
+ if (entries.length === 0) throw new Error('[plugin-ai-evals] scorers needs at least one scorer.');
5
+ for (const [name, scorer] of entries){
6
+ if (!isScorer(scorer)) {
7
+ throw new Error(`[plugin-ai-evals] Scorer '${name}' must come from defineScorer(), judge() or checks.`);
8
+ }
9
+ }
10
+ const concurrency = options.concurrency ?? 5;
11
+ if (!Number.isInteger(concurrency) || concurrency < 1) {
12
+ throw new Error('[plugin-ai-evals] concurrency must be a positive integer.');
13
+ }
14
+ return {
15
+ ...options,
16
+ concurrency
17
+ };
18
+ }
19
+
20
+ //# sourceMappingURL=options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/options.ts"],"names":["isScorer","resolveOptions","options","entries","Object","scorers","length","Error","name","scorer","concurrency","Number","isInteger"],"mappings":"AAGA,SAASA,QAAQ,QAAQ,eAAe;AAaxC,OAAO,SAASC,eAAeC,OAA6B;IAC1D,MAAMC,UAAUC,OAAOD,OAAO,CAACD,SAASG,WAAW,CAAC;IAEpD,IAAIF,QAAQG,MAAM,KAAK,GAAG,MAAM,IAAIC,MAAM;IAE1C,KAAK,MAAM,CAACC,MAAMC,OAAO,IAAIN,QAAS;QACpC,IAAI,CAACH,SAASS,SAAS;YACrB,MAAM,IAAIF,MACR,CAAC,0BAA0B,EAAEC,KAAK,mDAAmD,CAAC;QAE1F;IACF;IAEA,MAAME,cAAcR,QAAQQ,WAAW,IAAI;IAE3C,IAAI,CAACC,OAAOC,SAAS,CAACF,gBAAgBA,cAAc,GAAG;QACrD,MAAM,IAAIH,MAAM;IAClB;IAEA,OAAO;QAAE,GAAGL,OAAO;QAAEQ;IAAY;AACnC","file":"options.js"}
@@ -0,0 +1,27 @@
1
+ import type { AgentInstance, AgentModelId, DocID, FrogBotRequest } from 'frogbot';
2
+ import type { EvalToolCall, Scorer } from './scorers.js';
3
+ export type EvalCase = {
4
+ id: DocID;
5
+ input: string;
6
+ expected?: string | null;
7
+ expectedTools?: string[] | null;
8
+ metadata?: unknown;
9
+ };
10
+ export type CaseOutcome = {
11
+ result: DocID;
12
+ errored: boolean;
13
+ scores: Record<string, number | null>;
14
+ };
15
+ export declare function toToolCalls(steps: readonly {
16
+ content: readonly unknown[];
17
+ }[]): EvalToolCall[];
18
+ export declare function runCase({ run, evalCase, agent, scorers, req, overrideAccess, model, }: {
19
+ run: DocID;
20
+ evalCase: EvalCase;
21
+ agent: AgentInstance;
22
+ scorers: readonly (readonly [string, Scorer])[];
23
+ req: FrogBotRequest;
24
+ overrideAccess: boolean;
25
+ model?: AgentModelId;
26
+ }): Promise<CaseOutcome>;
27
+ //# sourceMappingURL=runCase.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runCase.d.ts","sourceRoot":"","sources":["../src/runCase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAGlF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,EAAiB,MAAM,cAAc,CAAC;AAGxE,MAAM,MAAM,QAAQ,GAAG;IACrB,EAAE,EAAE,KAAK,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAChC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,KAAK,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC;CACvC,CAAC;AAOF,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS;IAAE,OAAO,EAAE,SAAS,OAAO,EAAE,CAAA;CAAE,EAAE,GAAG,YAAY,EAAE,CAsB7F;AAyCD,wBAAsB,OAAO,CAAC,EAC5B,GAAG,EACH,QAAQ,EACR,KAAK,EACL,OAAO,EACP,GAAG,EACH,cAAc,EACd,KAAK,GACN,EAAE;IACD,GAAG,EAAE,KAAK,CAAC;IACX,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,EAAE,aAAa,CAAC;IACrB,OAAO,EAAE,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC;IAChD,GAAG,EAAE,cAAc,CAAC;IACpB,cAAc,EAAE,OAAO,CAAC;IAC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