@m4trix/evals 0.1.0 → 0.2.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/LICENSE +21 -0
- package/README.md +163 -0
- package/dist/cli-simple.cjs +133 -9
- package/dist/cli-simple.cjs.map +1 -1
- package/dist/cli-simple.js +113 -9
- package/dist/cli-simple.js.map +1 -1
- package/dist/cli.cjs +130 -7
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +111 -7
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +134 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +23 -3
- package/dist/index.d.ts +23 -3
- package/dist/index.js +114 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -5,8 +5,10 @@ import { useApp, useInput, Box, Text } from 'ink';
|
|
|
5
5
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
6
6
|
import { randomUUID } from 'crypto';
|
|
7
7
|
import { Effect, PubSub, Queue, Fiber } from 'effect';
|
|
8
|
+
import { existsSync } from 'fs';
|
|
9
|
+
import { resolve, relative, join, dirname } from 'path';
|
|
10
|
+
import * as jitiModule from 'jiti';
|
|
8
11
|
import { mkdir, appendFile, readdir } from 'fs/promises';
|
|
9
|
-
import { relative, join, dirname, resolve } from 'path';
|
|
10
12
|
import { pathToFileURL } from 'url';
|
|
11
13
|
|
|
12
14
|
var SEP = " ";
|
|
@@ -1292,10 +1294,102 @@ var defaultRunnerConfig = {
|
|
|
1292
1294
|
},
|
|
1293
1295
|
artifactDirectory: ".eval-results"
|
|
1294
1296
|
};
|
|
1297
|
+
function toRunnerConfigOverrides(config) {
|
|
1298
|
+
if (!config) {
|
|
1299
|
+
return void 0;
|
|
1300
|
+
}
|
|
1301
|
+
const rawDiscovery = config.discovery;
|
|
1302
|
+
const discovery = {};
|
|
1303
|
+
if (rawDiscovery?.rootDir !== void 0) {
|
|
1304
|
+
discovery.rootDir = rawDiscovery.rootDir;
|
|
1305
|
+
}
|
|
1306
|
+
if (rawDiscovery?.datasetFilePatterns !== void 0) {
|
|
1307
|
+
discovery.datasetSuffixes = rawDiscovery.datasetFilePatterns;
|
|
1308
|
+
} else if (rawDiscovery?.datasetSuffixes !== void 0) {
|
|
1309
|
+
discovery.datasetSuffixes = rawDiscovery.datasetSuffixes;
|
|
1310
|
+
}
|
|
1311
|
+
if (rawDiscovery?.evaluatorFilePatterns !== void 0) {
|
|
1312
|
+
discovery.evaluatorSuffixes = rawDiscovery.evaluatorFilePatterns;
|
|
1313
|
+
} else if (rawDiscovery?.evaluatorSuffixes !== void 0) {
|
|
1314
|
+
discovery.evaluatorSuffixes = rawDiscovery.evaluatorSuffixes;
|
|
1315
|
+
}
|
|
1316
|
+
if (rawDiscovery?.testCaseFilePatterns !== void 0) {
|
|
1317
|
+
discovery.testCaseSuffixes = rawDiscovery.testCaseFilePatterns;
|
|
1318
|
+
} else if (rawDiscovery?.testCaseSuffixes !== void 0) {
|
|
1319
|
+
discovery.testCaseSuffixes = rawDiscovery.testCaseSuffixes;
|
|
1320
|
+
}
|
|
1321
|
+
if (rawDiscovery?.excludeDirectories !== void 0) {
|
|
1322
|
+
discovery.excludeDirectories = rawDiscovery.excludeDirectories;
|
|
1323
|
+
}
|
|
1324
|
+
const overrides = {};
|
|
1325
|
+
if (config.artifactDirectory !== void 0) {
|
|
1326
|
+
overrides.artifactDirectory = config.artifactDirectory;
|
|
1327
|
+
}
|
|
1328
|
+
if (Object.keys(discovery).length > 0) {
|
|
1329
|
+
overrides.discovery = discovery;
|
|
1330
|
+
}
|
|
1331
|
+
return overrides;
|
|
1332
|
+
}
|
|
1295
1333
|
function withRunnerConfig(overrides) {
|
|
1296
|
-
{
|
|
1334
|
+
if (!overrides) {
|
|
1297
1335
|
return defaultRunnerConfig;
|
|
1298
1336
|
}
|
|
1337
|
+
const discovery = overrides.discovery ? {
|
|
1338
|
+
...defaultRunnerConfig.discovery,
|
|
1339
|
+
...overrides.discovery
|
|
1340
|
+
} : defaultRunnerConfig.discovery;
|
|
1341
|
+
return {
|
|
1342
|
+
...defaultRunnerConfig,
|
|
1343
|
+
...overrides,
|
|
1344
|
+
discovery
|
|
1345
|
+
};
|
|
1346
|
+
}
|
|
1347
|
+
var CONFIG_FILE_NAME = "m4trix-eval.config.ts";
|
|
1348
|
+
var cachedLoader;
|
|
1349
|
+
function getJitiLoader() {
|
|
1350
|
+
if (cachedLoader) {
|
|
1351
|
+
return cachedLoader;
|
|
1352
|
+
}
|
|
1353
|
+
const createJiti2 = jitiModule.createJiti ?? jitiModule.default;
|
|
1354
|
+
if (typeof createJiti2 !== "function") {
|
|
1355
|
+
throw new Error("Failed to initialize jiti for m4trix eval config loading.");
|
|
1356
|
+
}
|
|
1357
|
+
cachedLoader = createJiti2(import.meta.url, {
|
|
1358
|
+
interopDefault: true,
|
|
1359
|
+
moduleCache: true
|
|
1360
|
+
});
|
|
1361
|
+
return cachedLoader;
|
|
1362
|
+
}
|
|
1363
|
+
function resolveConfigModuleExport(loadedModule) {
|
|
1364
|
+
if (loadedModule && typeof loadedModule === "object" && "default" in loadedModule) {
|
|
1365
|
+
return loadedModule.default;
|
|
1366
|
+
}
|
|
1367
|
+
return loadedModule;
|
|
1368
|
+
}
|
|
1369
|
+
function resolveConfigValue(value) {
|
|
1370
|
+
if (value === void 0 || value === null) {
|
|
1371
|
+
return void 0;
|
|
1372
|
+
}
|
|
1373
|
+
if (typeof value === "function") {
|
|
1374
|
+
return value();
|
|
1375
|
+
}
|
|
1376
|
+
if (typeof value !== "object") {
|
|
1377
|
+
throw new Error(
|
|
1378
|
+
"Invalid m4trix eval config export. Expected an object or defineConfigFunction(() => config)."
|
|
1379
|
+
);
|
|
1380
|
+
}
|
|
1381
|
+
return value;
|
|
1382
|
+
}
|
|
1383
|
+
function loadRunnerConfigFile(cwd = process.cwd()) {
|
|
1384
|
+
const configPath = resolve(cwd, CONFIG_FILE_NAME);
|
|
1385
|
+
if (!existsSync(configPath)) {
|
|
1386
|
+
return void 0;
|
|
1387
|
+
}
|
|
1388
|
+
const loader = getJitiLoader();
|
|
1389
|
+
const loaded = loader(configPath);
|
|
1390
|
+
const exportedValue = resolveConfigModuleExport(loaded);
|
|
1391
|
+
const config = resolveConfigValue(exportedValue);
|
|
1392
|
+
return toRunnerConfigOverrides(config);
|
|
1299
1393
|
}
|
|
1300
1394
|
var jitiLoader;
|
|
1301
1395
|
function toId(prefix, filePath, name) {
|
|
@@ -1348,12 +1442,12 @@ function hasOneSuffix(filePath, suffixes) {
|
|
|
1348
1442
|
async function loadModuleExports(filePath) {
|
|
1349
1443
|
if (filePath.endsWith(".ts") || filePath.endsWith(".tsx")) {
|
|
1350
1444
|
if (!jitiLoader) {
|
|
1351
|
-
const
|
|
1352
|
-
const
|
|
1353
|
-
if (!
|
|
1445
|
+
const jitiModule2 = await import('jiti');
|
|
1446
|
+
const createJiti2 = jitiModule2.createJiti ?? jitiModule2.default;
|
|
1447
|
+
if (!createJiti2) {
|
|
1354
1448
|
throw new Error("Failed to initialize jiti TypeScript loader");
|
|
1355
1449
|
}
|
|
1356
|
-
jitiLoader =
|
|
1450
|
+
jitiLoader = createJiti2(import.meta.url, {
|
|
1357
1451
|
interopDefault: true,
|
|
1358
1452
|
moduleCache: true
|
|
1359
1453
|
});
|
|
@@ -1758,8 +1852,18 @@ function createNameMatcher(pattern) {
|
|
|
1758
1852
|
}
|
|
1759
1853
|
return (value) => value.toLowerCase() === normalizedPattern.toLowerCase();
|
|
1760
1854
|
}
|
|
1855
|
+
function mergeRunnerOverrides(base, next) {
|
|
1856
|
+
if (!base) {
|
|
1857
|
+
return next;
|
|
1858
|
+
}
|
|
1859
|
+
{
|
|
1860
|
+
return base;
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1761
1863
|
function createRunner(overrides) {
|
|
1762
|
-
|
|
1864
|
+
const fileOverrides = loadRunnerConfigFile();
|
|
1865
|
+
const merged = mergeRunnerOverrides(fileOverrides, overrides);
|
|
1866
|
+
return new EffectRunner(withRunnerConfig(merged));
|
|
1763
1867
|
}
|
|
1764
1868
|
var EffectRunner = class {
|
|
1765
1869
|
constructor(config) {
|