@deepagents/evals 7.1.2 → 7.1.4
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/evaluate/index.js +8 -0
- package/dist/evaluate/index.js.map +3 -3
- package/dist/index.js +61 -131
- package/dist/index.js.map +2 -2
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/index.js +61 -131
- package/dist/store/index.js.map +2 -2
- package/package.json +3 -1
package/dist/index.js
CHANGED
|
@@ -648,6 +648,8 @@ function weighted(config) {
|
|
|
648
648
|
}
|
|
649
649
|
|
|
650
650
|
// packages/evals/src/store/index.ts
|
|
651
|
+
import { Declaration } from "@zukhruf/sqlite-drift";
|
|
652
|
+
import { transaction } from "@zukhruf/sqlite-transaction";
|
|
651
653
|
import { mkdirSync } from "node:fs";
|
|
652
654
|
import { dirname } from "node:path";
|
|
653
655
|
import {
|
|
@@ -655,9 +657,10 @@ import {
|
|
|
655
657
|
} from "node:sqlite";
|
|
656
658
|
|
|
657
659
|
// packages/evals/src/store/ddl.sqlite.sql
|
|
658
|
-
var ddl_sqlite_default = "
|
|
660
|
+
var ddl_sqlite_default = "CREATE TABLE IF NOT EXISTS suites (\n id TEXT PRIMARY KEY,\n name TEXT NOT NULL,\n created_at INTEGER NOT NULL DEFAULT (unixepoch() * 1000)\n);\n\nCREATE TABLE IF NOT EXISTS runs (\n id TEXT PRIMARY KEY,\n suite_id TEXT NOT NULL,\n name TEXT NOT NULL,\n model TEXT NOT NULL,\n config TEXT,\n started_at INTEGER NOT NULL,\n finished_at INTEGER,\n status TEXT NOT NULL DEFAULT 'running' CHECK(status IN ('running', 'completed', 'failed')),\n summary TEXT,\n FOREIGN KEY (suite_id) REFERENCES suites(id) ON DELETE CASCADE\n);\n\nCREATE INDEX IF NOT EXISTS idx_runs_suite_id ON runs(suite_id);\nCREATE INDEX IF NOT EXISTS idx_runs_started_at ON runs(started_at);\n\nCREATE TABLE IF NOT EXISTS cases (\n id TEXT PRIMARY KEY,\n run_id TEXT NOT NULL,\n idx INTEGER NOT NULL,\n input TEXT NOT NULL,\n output TEXT,\n expected TEXT,\n latency_ms INTEGER,\n tokens_in INTEGER,\n tokens_out INTEGER,\n error TEXT,\n FOREIGN KEY (run_id) REFERENCES runs(id) ON DELETE CASCADE\n);\n\nCREATE INDEX IF NOT EXISTS idx_cases_run_id ON cases(run_id);\n\nCREATE TABLE IF NOT EXISTS scores (\n id TEXT PRIMARY KEY,\n case_id TEXT NOT NULL,\n scorer_name TEXT NOT NULL,\n score REAL NOT NULL,\n reason TEXT,\n FOREIGN KEY (case_id) REFERENCES cases(id) ON DELETE CASCADE\n);\n\nCREATE INDEX IF NOT EXISTS idx_scores_case_id ON scores(case_id);\n\nCREATE TABLE IF NOT EXISTS prompts (\n id TEXT PRIMARY KEY,\n name TEXT NOT NULL,\n version INTEGER NOT NULL DEFAULT 1,\n content TEXT NOT NULL,\n created_at INTEGER NOT NULL DEFAULT (unixepoch() * 1000),\n UNIQUE(name, version)\n);\n\nCREATE INDEX IF NOT EXISTS idx_prompts_created_at ON prompts(created_at);\nCREATE INDEX IF NOT EXISTS idx_prompts_name_version ON prompts(name, version DESC);\n";
|
|
659
661
|
|
|
660
662
|
// packages/evals/src/store/index.ts
|
|
663
|
+
var schema = new Declaration([ddl_sqlite_default], { rows: "keep" });
|
|
661
664
|
var RUN_STATUSES = ["running", "completed", "failed"];
|
|
662
665
|
function isRunStatus(value) {
|
|
663
666
|
return RUN_STATUSES.some((status) => status === value);
|
|
@@ -805,20 +808,6 @@ var RunStore = class {
|
|
|
805
808
|
#all(columns, sql2, ...params) {
|
|
806
809
|
return this.#stmt(sql2).all(...params).map((row) => readRow(row, columns, sql2));
|
|
807
810
|
}
|
|
808
|
-
#transaction(fn) {
|
|
809
|
-
this.#db.exec("BEGIN TRANSACTION");
|
|
810
|
-
try {
|
|
811
|
-
const result = fn();
|
|
812
|
-
this.#db.exec("COMMIT");
|
|
813
|
-
return result;
|
|
814
|
-
} catch (error) {
|
|
815
|
-
try {
|
|
816
|
-
this.#db.exec("ROLLBACK");
|
|
817
|
-
} catch {
|
|
818
|
-
}
|
|
819
|
-
throw error;
|
|
820
|
-
}
|
|
821
|
-
}
|
|
822
811
|
constructor(pathOrDb) {
|
|
823
812
|
if (pathOrDb instanceof DatabaseSync) {
|
|
824
813
|
this.#db = pathOrDb;
|
|
@@ -827,93 +816,22 @@ var RunStore = class {
|
|
|
827
816
|
mkdirSync(dirname(dbPath), { recursive: true });
|
|
828
817
|
this.#db = new DatabaseSync(dbPath);
|
|
829
818
|
}
|
|
830
|
-
this.#db.exec(
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
);
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
if (columns.length === 0) return;
|
|
840
|
-
if (columns.some((column) => column.name === "version")) return;
|
|
841
|
-
this.#transaction(() => {
|
|
842
|
-
this.#db.exec("ALTER TABLE prompts RENAME TO prompts_legacy");
|
|
843
|
-
this.#db.exec(`
|
|
844
|
-
CREATE TABLE prompts (
|
|
845
|
-
id TEXT PRIMARY KEY,
|
|
846
|
-
name TEXT NOT NULL,
|
|
847
|
-
version INTEGER NOT NULL,
|
|
848
|
-
content TEXT NOT NULL,
|
|
849
|
-
created_at INTEGER NOT NULL DEFAULT (unixepoch() * 1000),
|
|
850
|
-
UNIQUE(name, version)
|
|
851
|
-
)
|
|
852
|
-
`);
|
|
853
|
-
this.#db.exec(`
|
|
854
|
-
INSERT INTO prompts (id, name, version, content, created_at)
|
|
855
|
-
SELECT id, name, 1, content, created_at
|
|
856
|
-
FROM prompts_legacy
|
|
857
|
-
`);
|
|
858
|
-
this.#db.exec("DROP TABLE prompts_legacy");
|
|
859
|
-
this.#db.exec(
|
|
860
|
-
"CREATE INDEX IF NOT EXISTS idx_prompts_created_at ON prompts(created_at)"
|
|
861
|
-
);
|
|
862
|
-
this.#db.exec(
|
|
863
|
-
"CREATE INDEX IF NOT EXISTS idx_prompts_name_version ON prompts(name, version DESC)"
|
|
864
|
-
);
|
|
865
|
-
});
|
|
866
|
-
}
|
|
867
|
-
#migrateRunsTableToSuiteRequired() {
|
|
868
|
-
const columns = this.#all(
|
|
869
|
-
{ name: "text", notnull: "number" },
|
|
870
|
-
"PRAGMA table_info(runs)"
|
|
871
|
-
);
|
|
872
|
-
if (columns.length === 0) return;
|
|
873
|
-
const suiteColumn = columns.find((column) => column.name === "suite_id");
|
|
874
|
-
const hasNonNullSuite = suiteColumn?.notnull === 1;
|
|
875
|
-
const runForeignKeys = this.#all(
|
|
876
|
-
{ from: "text", on_delete: "text", table: "text" },
|
|
877
|
-
"PRAGMA foreign_key_list(runs)"
|
|
878
|
-
);
|
|
879
|
-
const suiteForeignKey = runForeignKeys.find(
|
|
880
|
-
(fk) => fk.from === "suite_id" && fk.table === "suites"
|
|
819
|
+
this.#db.exec(`
|
|
820
|
+
PRAGMA journal_mode = WAL;
|
|
821
|
+
PRAGMA synchronous = NORMAL;
|
|
822
|
+
PRAGMA foreign_keys = ON;
|
|
823
|
+
PRAGMA busy_timeout = 5000;
|
|
824
|
+
`);
|
|
825
|
+
const runsTable = this.#get(
|
|
826
|
+
{ name: "text" },
|
|
827
|
+
"SELECT name FROM sqlite_schema WHERE type = 'table' AND name = 'runs'"
|
|
881
828
|
);
|
|
882
|
-
|
|
883
|
-
if (hasNonNullSuite && hasCascadeDelete) return;
|
|
884
|
-
this.#statements.clear();
|
|
885
|
-
this.#transaction(() => {
|
|
886
|
-
this.#db.exec(`
|
|
887
|
-
CREATE TABLE runs_next (
|
|
888
|
-
id TEXT PRIMARY KEY,
|
|
889
|
-
suite_id TEXT NOT NULL,
|
|
890
|
-
name TEXT NOT NULL,
|
|
891
|
-
model TEXT NOT NULL,
|
|
892
|
-
config TEXT,
|
|
893
|
-
started_at INTEGER NOT NULL,
|
|
894
|
-
finished_at INTEGER,
|
|
895
|
-
status TEXT NOT NULL DEFAULT 'running' CHECK(status IN ('running', 'completed', 'failed')),
|
|
896
|
-
summary TEXT,
|
|
897
|
-
FOREIGN KEY (suite_id) REFERENCES suites(id) ON DELETE CASCADE
|
|
898
|
-
)
|
|
899
|
-
`);
|
|
900
|
-
this.#db.exec("DELETE FROM runs WHERE suite_id IS NULL");
|
|
901
|
-
this.#db.exec(`
|
|
902
|
-
INSERT INTO runs_next (id, suite_id, name, model, config, started_at, finished_at, status, summary)
|
|
903
|
-
SELECT r.id, r.suite_id, r.name, r.model, r.config, r.started_at, r.finished_at, r.status, r.summary
|
|
904
|
-
FROM runs r
|
|
905
|
-
JOIN suites s ON s.id = r.suite_id
|
|
906
|
-
`);
|
|
907
|
-
this.#db.exec("DROP TABLE runs");
|
|
908
|
-
this.#db.exec("ALTER TABLE runs_next RENAME TO runs");
|
|
829
|
+
if (runsTable !== void 0) {
|
|
909
830
|
this.#db.exec(
|
|
910
|
-
"
|
|
831
|
+
"DELETE FROM runs WHERE suite_id IS NULL OR NOT EXISTS (SELECT 1 FROM suites WHERE suites.id = runs.suite_id)"
|
|
911
832
|
);
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
);
|
|
915
|
-
});
|
|
916
|
-
this.#statements.clear();
|
|
833
|
+
}
|
|
834
|
+
schema.apply(this.#db);
|
|
917
835
|
}
|
|
918
836
|
createSuite(name) {
|
|
919
837
|
const id = crypto.randomUUID();
|
|
@@ -958,35 +876,43 @@ var RunStore = class {
|
|
|
958
876
|
).run(Date.now(), status, summary ? JSON.stringify(summary) : null, runId);
|
|
959
877
|
}
|
|
960
878
|
saveCases(cases) {
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
stmt.run(
|
|
967
|
-
c.id,
|
|
968
|
-
c.run_id,
|
|
969
|
-
c.idx,
|
|
970
|
-
JSON.stringify(c.input),
|
|
971
|
-
c.output,
|
|
972
|
-
c.expected != null ? JSON.stringify(c.expected) : null,
|
|
973
|
-
c.latency_ms,
|
|
974
|
-
c.tokens_in,
|
|
975
|
-
c.tokens_out,
|
|
976
|
-
c.error ?? null
|
|
879
|
+
transaction(
|
|
880
|
+
this.#db,
|
|
881
|
+
() => {
|
|
882
|
+
const stmt = this.#stmt(
|
|
883
|
+
"INSERT INTO cases (id, run_id, idx, input, output, expected, latency_ms, tokens_in, tokens_out, error) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
|
|
977
884
|
);
|
|
978
|
-
|
|
979
|
-
|
|
885
|
+
for (const c of cases) {
|
|
886
|
+
stmt.run(
|
|
887
|
+
c.id,
|
|
888
|
+
c.run_id,
|
|
889
|
+
c.idx,
|
|
890
|
+
JSON.stringify(c.input),
|
|
891
|
+
c.output,
|
|
892
|
+
c.expected != null ? JSON.stringify(c.expected) : null,
|
|
893
|
+
c.latency_ms,
|
|
894
|
+
c.tokens_in,
|
|
895
|
+
c.tokens_out,
|
|
896
|
+
c.error ?? null
|
|
897
|
+
);
|
|
898
|
+
}
|
|
899
|
+
},
|
|
900
|
+
{ mode: "deferred" }
|
|
901
|
+
);
|
|
980
902
|
}
|
|
981
903
|
saveScores(scores) {
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
904
|
+
transaction(
|
|
905
|
+
this.#db,
|
|
906
|
+
() => {
|
|
907
|
+
const stmt = this.#stmt(
|
|
908
|
+
"INSERT INTO scores (id, case_id, scorer_name, score, reason) VALUES (?, ?, ?, ?, ?)"
|
|
909
|
+
);
|
|
910
|
+
for (const s of scores) {
|
|
911
|
+
stmt.run(s.id, s.case_id, s.scorer_name, s.score, s.reason ?? null);
|
|
912
|
+
}
|
|
913
|
+
},
|
|
914
|
+
{ mode: "deferred" }
|
|
915
|
+
);
|
|
990
916
|
}
|
|
991
917
|
getRun(runId) {
|
|
992
918
|
const row = this.#get(runColumns, "SELECT * FROM runs WHERE id = ?", runId);
|
|
@@ -1154,12 +1080,16 @@ var RunStore = class {
|
|
|
1154
1080
|
this.#stmt("DELETE FROM prompts WHERE id = ?").run(id);
|
|
1155
1081
|
}
|
|
1156
1082
|
resetRun(id) {
|
|
1157
|
-
|
|
1158
|
-
this.#
|
|
1159
|
-
|
|
1160
|
-
"
|
|
1161
|
-
|
|
1162
|
-
|
|
1083
|
+
transaction(
|
|
1084
|
+
this.#db,
|
|
1085
|
+
() => {
|
|
1086
|
+
this.#stmt("DELETE FROM cases WHERE run_id = ?").run(id);
|
|
1087
|
+
this.#stmt(
|
|
1088
|
+
"UPDATE runs SET status = ?, started_at = ?, finished_at = NULL, summary = NULL WHERE id = ?"
|
|
1089
|
+
).run("running", Date.now(), id);
|
|
1090
|
+
},
|
|
1091
|
+
{ mode: "deferred" }
|
|
1092
|
+
);
|
|
1163
1093
|
}
|
|
1164
1094
|
deleteRun(id) {
|
|
1165
1095
|
this.#stmt("DELETE FROM runs WHERE id = ?").run(id);
|