modelrig 0.8.1 → 0.9.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.
Files changed (245) hide show
  1. package/CHANGELOG.md +145 -0
  2. package/README.md +4 -2
  3. package/dist/artifacts/artifact.d.ts +12 -13
  4. package/dist/artifacts/artifact.d.ts.map +1 -1
  5. package/dist/artifacts/artifact.js +17 -23
  6. package/dist/artifacts/index.d.ts +13 -5
  7. package/dist/artifacts/index.d.ts.map +1 -1
  8. package/dist/artifacts/index.js +11 -4
  9. package/dist/artifacts/run-context.d.ts +3 -24
  10. package/dist/artifacts/run-context.d.ts.map +1 -1
  11. package/dist/artifacts/run-context.js +3 -39
  12. package/dist/bakeoff/engine.d.ts +29 -0
  13. package/dist/bakeoff/engine.d.ts.map +1 -1
  14. package/dist/bakeoff/engine.js +47 -0
  15. package/dist/bakeoff/eval-cases-rig.d.ts +36 -0
  16. package/dist/bakeoff/eval-cases-rig.d.ts.map +1 -0
  17. package/dist/bakeoff/eval-cases-rig.js +27 -0
  18. package/dist/bakeoff/eval-cases.d.ts +19 -0
  19. package/dist/bakeoff/eval-cases.d.ts.map +1 -1
  20. package/dist/bakeoff/eval-cases.js +18 -1
  21. package/dist/bakeoff/golden-judge.d.ts +47 -0
  22. package/dist/bakeoff/golden-judge.d.ts.map +1 -0
  23. package/dist/bakeoff/golden-judge.js +49 -0
  24. package/dist/bakeoff/quality.d.ts +30 -0
  25. package/dist/bakeoff/quality.d.ts.map +1 -1
  26. package/dist/bakeoff/quality.js +21 -0
  27. package/dist/bakeoff/replay.d.ts +11 -0
  28. package/dist/bakeoff/replay.d.ts.map +1 -1
  29. package/dist/bakeoff/replay.js +8 -0
  30. package/dist/bakeoff/report.d.ts +7 -0
  31. package/dist/bakeoff/report.d.ts.map +1 -1
  32. package/dist/bakeoff/report.js +26 -0
  33. package/dist/cli-judge.d.ts +12 -0
  34. package/dist/cli-judge.d.ts.map +1 -0
  35. package/dist/cli-judge.js +48 -0
  36. package/dist/cli.d.ts.map +1 -1
  37. package/dist/cli.js +14 -42
  38. package/dist/config.d.ts +54 -29
  39. package/dist/config.d.ts.map +1 -1
  40. package/dist/config.js +86 -47
  41. package/dist/detect/detector.d.ts +4 -2
  42. package/dist/detect/detector.d.ts.map +1 -1
  43. package/dist/detect/safe-harbor.d.ts +57 -0
  44. package/dist/detect/safe-harbor.d.ts.map +1 -0
  45. package/dist/detect/safe-harbor.js +278 -0
  46. package/dist/feedback/coverage.d.ts +11 -8
  47. package/dist/feedback/coverage.d.ts.map +1 -1
  48. package/dist/feedback/coverage.js +29 -16
  49. package/dist/feedback/grade.d.ts +51 -0
  50. package/dist/feedback/grade.d.ts.map +1 -0
  51. package/dist/feedback/grade.js +63 -0
  52. package/dist/gateway/http-protocol.d.ts +1 -1
  53. package/dist/gateway/http-protocol.d.ts.map +1 -1
  54. package/dist/gateway/http-protocol.js +1 -1
  55. package/dist/index.d.ts +44 -27
  56. package/dist/index.d.ts.map +1 -1
  57. package/dist/index.js +110 -43
  58. package/dist/init/observe-cli.js +1 -1
  59. package/dist/init/observe.d.ts +2 -2
  60. package/dist/init/observe.d.ts.map +1 -1
  61. package/dist/init/observe.js +11 -7
  62. package/dist/mask/arm.d.ts +112 -0
  63. package/dist/mask/arm.d.ts.map +1 -0
  64. package/dist/mask/arm.js +179 -0
  65. package/dist/mask/index.d.ts +2 -0
  66. package/dist/mask/index.d.ts.map +1 -1
  67. package/dist/mask/index.js +7 -1
  68. package/dist/mask/mask-policy-cli.d.ts +12 -4
  69. package/dist/mask/mask-policy-cli.d.ts.map +1 -1
  70. package/dist/mask/mask-policy-cli.js +34 -9
  71. package/dist/query/grammar.d.ts +2 -2
  72. package/dist/query/grammar.d.ts.map +1 -1
  73. package/dist/query/grammar.js +3 -1
  74. package/dist/query/saved.d.ts +13 -0
  75. package/dist/query/saved.d.ts.map +1 -1
  76. package/dist/query/saved.js +67 -1
  77. package/dist/receipts/types.d.ts +1 -1
  78. package/dist/receipts/types.d.ts.map +1 -1
  79. package/dist/receipts/types.js +1 -0
  80. package/dist/registry/build.d.ts +43 -1
  81. package/dist/registry/build.d.ts.map +1 -1
  82. package/dist/registry/build.js +52 -0
  83. package/dist/registry/pricing-shape.d.ts +29 -0
  84. package/dist/registry/pricing-shape.d.ts.map +1 -1
  85. package/dist/registry/pricing-shape.js +10 -1
  86. package/dist/registry/rows.d.ts.map +1 -1
  87. package/dist/registry/rows.js +1 -0
  88. package/dist/registry/select.d.ts +6 -1
  89. package/dist/registry/select.d.ts.map +1 -1
  90. package/dist/registry/select.js +11 -0
  91. package/dist/routes/call-config.d.ts +199 -0
  92. package/dist/routes/call-config.d.ts.map +1 -0
  93. package/dist/routes/call-config.js +343 -0
  94. package/dist/routes/loader.js +5 -3
  95. package/dist/routes/objective-loader.d.ts +12 -0
  96. package/dist/routes/objective-loader.d.ts.map +1 -1
  97. package/dist/routes/objective-loader.js +82 -0
  98. package/dist/routes/resolved-bundle.d.ts +50 -0
  99. package/dist/routes/resolved-bundle.d.ts.map +1 -1
  100. package/dist/routes/resolved-bundle.js +52 -0
  101. package/dist/routes/screen-loader.d.ts +28 -0
  102. package/dist/routes/screen-loader.d.ts.map +1 -1
  103. package/dist/routes/screen-loader.js +51 -0
  104. package/dist/run/accept.d.ts +2 -0
  105. package/dist/run/accept.d.ts.map +1 -1
  106. package/dist/run/accept.js +1 -0
  107. package/dist/run/dispatch.d.ts +42 -13
  108. package/dist/run/dispatch.d.ts.map +1 -1
  109. package/dist/run/dispatch.js +107 -25
  110. package/dist/run/grounding.d.ts +28 -2
  111. package/dist/run/grounding.d.ts.map +1 -1
  112. package/dist/run/grounding.js +54 -10
  113. package/dist/run/record-attempt.d.ts +4 -0
  114. package/dist/run/record-attempt.d.ts.map +1 -1
  115. package/dist/run/record-attempt.js +4 -0
  116. package/dist/run/routing-docs.js +1 -1
  117. package/dist/run/run.d.ts.map +1 -1
  118. package/dist/run/run.js +21 -26
  119. package/dist/savings/odometer.d.ts +4 -0
  120. package/dist/savings/odometer.d.ts.map +1 -1
  121. package/dist/savings/odometer.js +20 -1
  122. package/dist/savings/swap-execute.d.ts +7 -0
  123. package/dist/savings/swap-execute.d.ts.map +1 -1
  124. package/dist/savings/swap-execute.js +30 -0
  125. package/dist/savings/swaps-client.d.ts +10 -0
  126. package/dist/savings/swaps-client.d.ts.map +1 -1
  127. package/dist/screen/fixtures/probe-corpora.d.ts +23 -0
  128. package/dist/screen/fixtures/probe-corpora.d.ts.map +1 -0
  129. package/dist/screen/fixtures/probe-corpora.js +69 -0
  130. package/dist/screen/index.d.ts +21 -0
  131. package/dist/screen/index.d.ts.map +1 -0
  132. package/dist/screen/index.js +64 -0
  133. package/dist/screen/model-screen.d.ts +111 -0
  134. package/dist/screen/model-screen.d.ts.map +1 -0
  135. package/dist/screen/model-screen.js +178 -0
  136. package/dist/screen/patterns.d.ts +51 -0
  137. package/dist/screen/patterns.d.ts.map +1 -0
  138. package/dist/screen/patterns.js +151 -0
  139. package/dist/screen/phi-gate.d.ts +52 -0
  140. package/dist/screen/phi-gate.d.ts.map +1 -0
  141. package/dist/screen/phi-gate.js +86 -0
  142. package/dist/screen/policy.d.ts +71 -0
  143. package/dist/screen/policy.d.ts.map +1 -0
  144. package/dist/screen/policy.js +334 -0
  145. package/dist/screen/probe.d.ts +118 -0
  146. package/dist/screen/probe.d.ts.map +1 -0
  147. package/dist/screen/probe.js +132 -0
  148. package/dist/screen/screen-cli.d.ts +16 -0
  149. package/dist/screen/screen-cli.d.ts.map +1 -0
  150. package/dist/screen/screen-cli.js +178 -0
  151. package/dist/screen/screen.d.ts +99 -0
  152. package/dist/screen/screen.d.ts.map +1 -0
  153. package/dist/screen/screen.js +0 -0
  154. package/dist/screen/sidecar.d.ts +69 -0
  155. package/dist/screen/sidecar.d.ts.map +1 -0
  156. package/dist/screen/sidecar.js +145 -0
  157. package/dist/screen/types.d.ts +43 -2
  158. package/dist/screen/types.d.ts.map +1 -1
  159. package/dist/settings/api-fetcher.d.ts +14 -3
  160. package/dist/settings/api-fetcher.d.ts.map +1 -1
  161. package/dist/settings/api-fetcher.js +61 -10
  162. package/dist/settings/grading-guide.d.ts +76 -0
  163. package/dist/settings/grading-guide.d.ts.map +1 -0
  164. package/dist/settings/grading-guide.js +23 -0
  165. package/dist/settings/index.d.ts +3 -2
  166. package/dist/settings/index.d.ts.map +1 -1
  167. package/dist/settings/index.js +2 -1
  168. package/dist/settings/task-settings.d.ts +44 -7
  169. package/dist/settings/task-settings.d.ts.map +1 -1
  170. package/dist/settings/task-settings.js +53 -12
  171. package/dist/status.d.ts +26 -20
  172. package/dist/status.d.ts.map +1 -1
  173. package/dist/status.js +47 -29
  174. package/dist/telemetry/artifact-store.d.ts +5 -6
  175. package/dist/telemetry/artifact-store.d.ts.map +1 -1
  176. package/dist/telemetry/artifact-store.js +10 -24
  177. package/dist/telemetry/attempt-meta.d.ts +21 -0
  178. package/dist/telemetry/attempt-meta.d.ts.map +1 -1
  179. package/dist/telemetry/attempt-meta.js +9 -0
  180. package/dist/telemetry/exporter.d.ts +2 -2
  181. package/dist/telemetry/exporter.d.ts.map +1 -1
  182. package/dist/telemetry/exporter.js +22 -41
  183. package/dist/telemetry/grade-mappers.d.ts +22 -0
  184. package/dist/telemetry/grade-mappers.d.ts.map +1 -0
  185. package/dist/telemetry/grade-mappers.js +58 -0
  186. package/dist/telemetry/grades-sql.d.ts +53 -0
  187. package/dist/telemetry/grades-sql.d.ts.map +1 -0
  188. package/dist/telemetry/grades-sql.js +133 -0
  189. package/dist/telemetry/ingest-protocol.d.ts +29 -46
  190. package/dist/telemetry/ingest-protocol.d.ts.map +1 -1
  191. package/dist/telemetry/ingest-protocol.js +16 -54
  192. package/dist/telemetry/store-migrations.d.ts.map +1 -1
  193. package/dist/telemetry/store-migrations.js +51 -0
  194. package/dist/telemetry/store.d.ts +9 -6
  195. package/dist/telemetry/store.d.ts.map +1 -1
  196. package/dist/telemetry/store.js +8 -50
  197. package/dist/tenancy/api-key-format.d.ts +30 -1
  198. package/dist/tenancy/api-key-format.d.ts.map +1 -1
  199. package/dist/tenancy/api-key-format.js +33 -1
  200. package/dist/types/provider.d.ts +3 -0
  201. package/dist/types/provider.d.ts.map +1 -1
  202. package/dist/types/provider.js +25 -0
  203. package/dist/types/route.d.ts +78 -2
  204. package/dist/types/route.d.ts.map +1 -1
  205. package/dist/types/telemetry.d.ts +43 -46
  206. package/dist/types/telemetry.d.ts.map +1 -1
  207. package/dist/validate-cli.d.ts.map +1 -1
  208. package/dist/validate-cli.js +32 -0
  209. package/dist/verify/verify.d.ts +5 -0
  210. package/dist/verify/verify.d.ts.map +1 -1
  211. package/dist/verify/verify.js +2 -0
  212. package/dist/watch/evaluate.d.ts +84 -1
  213. package/dist/watch/evaluate.d.ts.map +1 -1
  214. package/dist/watch/evaluate.js +28 -0
  215. package/dist/watch/monitor.d.ts +8 -2
  216. package/dist/watch/monitor.d.ts.map +1 -1
  217. package/dist/watch/monitor.js +13 -5
  218. package/dist/watch/regret-monitor-cli.d.ts +16 -0
  219. package/dist/watch/regret-monitor-cli.d.ts.map +1 -0
  220. package/dist/watch/regret-monitor-cli.js +137 -0
  221. package/dist/watch/regret-monitor.d.ts +168 -0
  222. package/dist/watch/regret-monitor.d.ts.map +1 -0
  223. package/dist/watch/regret-monitor.js +304 -0
  224. package/dist/watch/upgrade.d.ts +62 -0
  225. package/dist/watch/upgrade.d.ts.map +1 -0
  226. package/dist/watch/upgrade.js +57 -0
  227. package/docs/agent-skill/SKILL.md +109 -5
  228. package/docs/how-it-fits.md +3 -2
  229. package/docs/instrumentation.md +149 -21
  230. package/docs/llms.txt +64 -20
  231. package/docs/mcp-oracle.md +249 -0
  232. package/docs/quickstart.md +95 -7
  233. package/package.json +16 -3
  234. package/registry/leaderboard.json +74 -0
  235. package/registry/registry.json +150 -112
  236. package/screen.d.ts +16 -0
  237. package/templates/call-disposition-qa.json +77 -0
  238. package/templates/catalog-cleansing.json +77 -0
  239. package/templates/compliance-review.json +76 -0
  240. package/templates/cs-next-action.json +76 -0
  241. package/templates/document-extraction.json +78 -0
  242. package/templates/financial-classification.json +75 -0
  243. package/templates/lead-qualification.json +76 -0
  244. package/templates/medical-classification.json +71 -0
  245. package/templates/ticket-triage.json +76 -0
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ /**
3
+ * Shared SQLite DDL + row mapping for the local `grades` table (grade primitive).
4
+ *
5
+ * The unified judgment table is written by TWO better-sqlite3 handles over the
6
+ * same telemetry file — the main telemetry store (`store.ts`, for inference/run
7
+ * grades via `rig.grade`) and the artifact store (`artifact-store.ts`, for
8
+ * artifact-subject grades, which already transact on that handle). Both must
9
+ * agree on the table shape and the bind mapping, so both live here once (DRY,
10
+ * and the two cannot drift). The telemetry handle owns the READ side (the
11
+ * exporter's `:grades` stream).
12
+ *
13
+ * project_id is NOT stored locally: like every telemetry row, it is stamped at
14
+ * export from the principal, never held on the row (one rig = one tenant).
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.GRADES_TABLE_SQL = void 0;
18
+ exports.prepareGradeInsert = prepareGradeInsert;
19
+ exports.gradeBindParams = gradeBindParams;
20
+ exports.toGradeRow = toGradeRow;
21
+ exports.backfillGradesFromFeedback = backfillGradesFromFeedback;
22
+ exports.backfillGradesFromEvaluations = backfillGradesFromEvaluations;
23
+ /** `CREATE TABLE IF NOT EXISTS grades …` — safe to run on every open. Mirrors
24
+ * `public.grades` minus the export-stamped columns (org handling below). */
25
+ exports.GRADES_TABLE_SQL = `
26
+ CREATE TABLE IF NOT EXISTS grades (
27
+ id TEXT PRIMARY KEY,
28
+ ts TEXT,
29
+ subject_kind TEXT NOT NULL CHECK (subject_kind IN ('inference','run','artifact')),
30
+ subject_id TEXT NOT NULL,
31
+ score REAL NOT NULL,
32
+ scale_max REAL,
33
+ scale_label TEXT,
34
+ comment TEXT,
35
+ kind TEXT NOT NULL CHECK (kind IN ('human','model-judge','deterministic')),
36
+ grader TEXT,
37
+ source TEXT,
38
+ org_id TEXT,
39
+ created_by TEXT
40
+ );
41
+ CREATE INDEX IF NOT EXISTS idx_grades_subject ON grades (subject_kind, subject_id);
42
+ `;
43
+ const INSERT_GRADE_SQL = `
44
+ INSERT OR IGNORE INTO grades (
45
+ id, ts, subject_kind, subject_id, score, scale_max, scale_label, comment,
46
+ kind, grader, source, org_id, created_by
47
+ ) VALUES (
48
+ @id, @ts, @subject_kind, @subject_id, @score, @scale_max, @scale_label, @comment,
49
+ @kind, @grader, @source, @org_id, @created_by
50
+ )`;
51
+ /** Prepare the grade insert statement against an open handle. INSERT OR IGNORE:
52
+ * a grade id is unique, and a re-inserted id (e.g. the backfill racing a live
53
+ * write) is a harmless no-op. */
54
+ function prepareGradeInsert(db) {
55
+ return db.prepare(INSERT_GRADE_SQL);
56
+ }
57
+ /** Bind a GradeRow to the insert statement's named params. */
58
+ function gradeBindParams(row) {
59
+ return {
60
+ id: row.id,
61
+ ts: row.ts,
62
+ subject_kind: row.subjectKind,
63
+ subject_id: row.subjectId,
64
+ score: row.score,
65
+ scale_max: row.scaleMax,
66
+ scale_label: row.scaleLabel,
67
+ comment: row.comment,
68
+ kind: row.kind,
69
+ grader: row.grader,
70
+ source: row.source,
71
+ org_id: row.orgId,
72
+ created_by: row.createdBy,
73
+ };
74
+ }
75
+ /** Read one SQLite grade row back into a GradeRow. */
76
+ function toGradeRow(r) {
77
+ return {
78
+ id: r.id,
79
+ ts: r.ts,
80
+ subjectKind: r.subject_kind,
81
+ subjectId: r.subject_id,
82
+ score: r.score,
83
+ scaleMax: r.scale_max,
84
+ scaleLabel: r.scale_label,
85
+ comment: r.comment,
86
+ kind: r.kind,
87
+ grader: r.grader,
88
+ source: r.source,
89
+ orgId: r.org_id ?? null,
90
+ createdBy: r.created_by ?? null,
91
+ };
92
+ }
93
+ /** Backfill `grades` from the local `feedback` table, if it exists (grade
94
+ * primitive, GP-1). Same mapping as migration 00070's feedback→grades leg.
95
+ * Idempotent (INSERT OR IGNORE keyed on the source row id). Runs inside the
96
+ * telemetry store's migration ladder. */
97
+ function backfillGradesFromFeedback(db) {
98
+ const hasFeedback = db.prepare("PRAGMA table_info(feedback)").all().length > 0;
99
+ if (!hasFeedback)
100
+ return;
101
+ db.exec(`
102
+ INSERT OR IGNORE INTO grades
103
+ (id, ts, subject_kind, subject_id, score, comment, kind, grader, source, org_id, created_by)
104
+ SELECT
105
+ f.id, f.ts,
106
+ CASE WHEN f.inference_id IS NOT NULL THEN 'inference' ELSE 'run' END,
107
+ COALESCE(f.inference_id, f.episode_key),
108
+ COALESCE(f.score, CASE WHEN f.verdict = 'up' THEN 1.0 ELSE 0.0 END),
109
+ f.note, 'human', f.source, f.source, f.org_id, f.created_by
110
+ FROM feedback f
111
+ WHERE COALESCE(f.inference_id, f.episode_key) IS NOT NULL
112
+ `);
113
+ }
114
+ /** Backfill `grades` from the local `artifact_evaluations` table, if it exists
115
+ * (grade primitive, GP-1). Same mapping as migration 00070's evaluation leg.
116
+ * Idempotent. Runs when the artifact store opens (it owns that table). */
117
+ function backfillGradesFromEvaluations(db) {
118
+ const hasEvals = db.prepare("PRAGMA table_info(artifact_evaluations)").all().length > 0;
119
+ if (!hasEvals)
120
+ return;
121
+ db.exec(`
122
+ INSERT OR IGNORE INTO grades
123
+ (id, ts, subject_kind, subject_id, score, scale_label, comment, kind, grader, source, org_id, created_by)
124
+ SELECT
125
+ e.id, NULL,
126
+ CASE WHEN e.artifact_id IS NOT NULL THEN 'artifact' ELSE 'run' END,
127
+ COALESCE(e.artifact_id, e.run_id),
128
+ COALESCE(e.score, CASE WHEN e.passed = 1 THEN 1.0 ELSE 0.0 END),
129
+ e.label, e.explanation, e.evaluator_kind, e.evaluator, NULL, NULL, e.created_by
130
+ FROM artifact_evaluations e
131
+ WHERE COALESCE(e.artifact_id, e.run_id) IS NOT NULL
132
+ `);
133
+ }
@@ -22,16 +22,17 @@
22
22
  * stamped by whoever holds the principal — the exporter's config in direct
23
23
  * mode, the resolved key in api mode.
24
24
  *
25
- * The single exception is `feedback.org_id`, and it is the reason WS2 exists.
26
- * A verdict recorded on OUR hosted server belongs to the org of the person who
25
+ * The single exception is `grade.org_id`, and it is the reason WS2 exists.
26
+ * A judgment recorded on OUR hosted server belongs to the org of the person who
27
27
  * recorded it, not to the org the server runs as, and one SQLite store holds
28
- * verdicts for many orgs. So a feedback row may name its own org — and the
29
- * ingest endpoint VERIFIES that name against the key rather than trusting it
30
- * (see `foreignOrgFeedback`). A service-role exporter needs no such check: it
31
- * already holds a credential that can write any row in the database.
28
+ * grades for many orgs. So a grade row may name its own org — and the ingest
29
+ * endpoint VERIFIES that name against the key rather than trusting it (see
30
+ * `foreignOrgGrades`). A service-role exporter needs no such check: it already
31
+ * holds a credential that can write any row in the database.
32
32
  */
33
33
  import type { FailureClass } from "../types/failures";
34
34
  import type { ResolvedRouteBundle } from "../routes/resolved-bundle";
35
+ export { foreignOrgGrades } from "./grade-mappers";
35
36
  /** The path the api sink posts to. Spelled once. */
36
37
  export declare const INGEST_PATH = "/v1/ingest";
37
38
  /** The CURRENT protocol version — the maximum the SDK can speak (ruling d).
@@ -106,20 +107,27 @@ export interface WireInference {
106
107
  * the batch). NEVER carries a matched value. */
107
108
  readonly mask?: unknown;
108
109
  }
109
- export interface WireFeedback {
110
+ /**
111
+ * A unified judgment (grade primitive, R1) — the wire shape of a `grades` row.
112
+ * `score` is the 0–1 primitive (always present); the pass/fail verdict is DERIVED
113
+ * server-side, never carried. A grade may name its OWN org (a verdict recorded
114
+ * through a hosted server for another org); the ingest endpoint verifies that name
115
+ * against the key (`foreignOrgGrades`). `scale_label` is the one display label.
116
+ */
117
+ export interface WireGrade {
110
118
  readonly id: string;
111
- readonly ts: string;
112
- readonly inference_id: string | null;
113
- readonly episode_key: string | null;
114
- readonly verdict: "up" | "down";
115
- readonly score: number | null;
116
- readonly note: string | null;
117
- /** WHO judged — "sdk", "console", a review-agent name. Not a tenant. */
118
- readonly source: string;
119
- /** Authenticated user who recorded it (00017), or null. */
119
+ readonly subject_kind: "inference" | "run" | "artifact";
120
+ readonly subject_id: string;
121
+ readonly score: number;
122
+ readonly scale_max: number | null;
123
+ readonly scale_label: string | null;
124
+ readonly comment: string | null;
125
+ readonly kind: "human" | "model-judge" | "deterministic";
126
+ readonly grader: string | null;
127
+ readonly source: string | null;
120
128
  readonly created_by: string | null;
121
- /** The verdict's OWN org, when it differs from the exporter's. See the
122
- * module header — this is the one field the ingest endpoint must verify. */
129
+ readonly ts: string | null;
130
+ /** The grade's OWN org, when it differs from the exporter's (feedback doctrine). */
123
131
  readonly org_id?: string;
124
132
  }
125
133
  export interface WireEnvelope {
@@ -240,24 +248,6 @@ export interface WireEvalCase {
240
248
  readonly note: string | null;
241
249
  readonly created_by: string | null;
242
250
  }
243
- /** An evaluation recorded against a SUBJECT — one of an artifact or a whole run
244
- * (E5 chunk V, subject-one-of per trajectory F3). Exactly one of artifact_id /
245
- * run_id is non-null; the server's validEvaluation enforces the XOR and the
246
- * 00051 CHECK is the backstop. A fact. */
247
- export interface WireArtifactEvaluation {
248
- readonly id: string;
249
- /** The artifact subject — null when this evaluates a whole run instead. */
250
- readonly artifact_id: string | null;
251
- /** The run subject (E5 V) — null when this evaluates an artifact. */
252
- readonly run_id?: string | null;
253
- readonly evaluator: string;
254
- readonly evaluator_kind: "deterministic" | "model-judge" | "human";
255
- readonly score: number | null;
256
- readonly passed: boolean | null;
257
- readonly label: string | null;
258
- readonly explanation: string | null;
259
- readonly created_by: string | null;
260
- }
261
251
  export interface WireManifest {
262
252
  readonly name: string;
263
253
  readonly dimensions: unknown;
@@ -279,7 +269,9 @@ export interface IngestBatch {
279
269
  * trusted to be unique across tenants. */
280
270
  readonly source: string;
281
271
  readonly inferences?: readonly WireInference[];
282
- readonly feedback?: readonly WireFeedback[];
272
+ /** Unified judgments (grade primitive, R1) — the SOLE judgment write path;
273
+ * a grade lands in `public.grades`. */
274
+ readonly grades?: readonly WireGrade[];
283
275
  readonly envelopes?: readonly WireEnvelope[];
284
276
  readonly routes?: readonly WireRoute[];
285
277
  /** Protocol v2 (spec §1). Present only when the SDK's artifact namespace is
@@ -288,7 +280,6 @@ export interface IngestBatch {
288
280
  readonly steps?: readonly WireStep[];
289
281
  readonly artifacts?: readonly WireArtifact[];
290
282
  readonly artifact_edges?: readonly WireArtifactEdge[];
291
- readonly artifact_evaluations?: readonly WireArtifactEvaluation[];
292
283
  /** Promoted eval cases (E4 chunk A). Present only when the SDK's artifact
293
284
  * namespace is active and a promote happened; a v1 batch never carries them. */
294
285
  readonly eval_cases?: readonly WireEvalCase[];
@@ -315,14 +306,6 @@ export interface TableWrite {
315
306
  * and both modes gain it at once — which is the point.
316
307
  */
317
308
  export declare function stampBatch(batch: IngestBatch, tenancy: Tenancy): TableWrite[];
318
- /**
319
- * Feedback rows naming an org other than the presented key's.
320
- *
321
- * Exists as its own exported function because the ingest endpoint must drop
322
- * these and COUNT them, and a check that lives inline in a request handler is
323
- * a check nobody can test in isolation. Returns the offending ids.
324
- */
325
- export declare function foreignOrgFeedback(rows: readonly WireFeedback[], keyOrgId: string): readonly string[];
326
309
  /** What `/v1/ingest` answers. Counts only — a per-row error list on a
327
310
  * fire-and-forget telemetry path is a payload nobody reads and a leak surface
328
311
  * nobody audits. */
@@ -1 +1 @@
1
- {"version":3,"file":"ingest-protocol.d.ts","sourceRoot":"","sources":["../../src/telemetry/ingest-protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAGrE,oDAAoD;AACpD,eAAO,MAAM,WAAW,eAAe,CAAC;AAExC;;;;6DAI6D;AAC7D,eAAO,MAAM,uBAAuB,IAAI,CAAC;AAEzC;;+EAE+E;AAC/E,eAAO,MAAM,0BAA0B,IAAI,CAAC;AAE5C,kEAAkE;AAClE,eAAO,MAAM,kBAAkB,4BAA4B,CAAC;AAE5D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BAAgB,EAAE,CAAC;IACtD;oFACgF;IAChF,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,YAAY,EAAE,CAAC;IAC9C,QAAQ,CAAC,QAAQ,CAAC,EAAE,YAAY,CAAC;IACjC,2EAA2E;IAC3E,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED;mEACmE;AACnE,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;IAClD,0DAA0D;IAC1D,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B;2EACuE;IACvE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,GAAG,UAAU,EAAE,CAsR7E;AAED;;oBAEoB;AACpB,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACpD,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACnD;qCACiC;IACjC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACpD"}
@@ -23,19 +23,21 @@
23
23
  * stamped by whoever holds the principal — the exporter's config in direct
24
24
  * mode, the resolved key in api mode.
25
25
  *
26
- * The single exception is `feedback.org_id`, and it is the reason WS2 exists.
27
- * A verdict recorded on OUR hosted server belongs to the org of the person who
26
+ * The single exception is `grade.org_id`, and it is the reason WS2 exists.
27
+ * A judgment recorded on OUR hosted server belongs to the org of the person who
28
28
  * recorded it, not to the org the server runs as, and one SQLite store holds
29
- * verdicts for many orgs. So a feedback row may name its own org — and the
30
- * ingest endpoint VERIFIES that name against the key rather than trusting it
31
- * (see `foreignOrgFeedback`). A service-role exporter needs no such check: it
32
- * already holds a credential that can write any row in the database.
29
+ * grades for many orgs. So a grade row may name its own org — and the ingest
30
+ * endpoint VERIFIES that name against the key rather than trusting it (see
31
+ * `foreignOrgGrades`). A service-role exporter needs no such check: it already
32
+ * holds a credential that can write any row in the database.
33
33
  */
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.DEFAULT_INGEST_URL = exports.INGEST_PROTOCOL_VERSION_V1 = exports.INGEST_PROTOCOL_VERSION = exports.INGEST_PATH = void 0;
35
+ exports.DEFAULT_INGEST_URL = exports.INGEST_PROTOCOL_VERSION_V1 = exports.INGEST_PROTOCOL_VERSION = exports.INGEST_PATH = exports.foreignOrgGrades = void 0;
36
36
  exports.stampBatch = stampBatch;
37
- exports.foreignOrgFeedback = foreignOrgFeedback;
38
37
  const fingerprint_1 = require("../registry/fingerprint");
38
+ const grade_mappers_1 = require("./grade-mappers");
39
+ var grade_mappers_2 = require("./grade-mappers");
40
+ Object.defineProperty(exports, "foreignOrgGrades", { enumerable: true, get: function () { return grade_mappers_2.foreignOrgGrades; } });
39
41
  /** The path the api sink posts to. Spelled once. */
40
42
  exports.INGEST_PATH = "/v1/ingest";
41
43
  /** The CURRENT protocol version — the maximum the SDK can speak (ruling d).
@@ -225,28 +227,6 @@ function stampBatch(batch, tenancy) {
225
227
  })),
226
228
  });
227
229
  }
228
- if (batch.artifact_evaluations !== undefined && batch.artifact_evaluations.length > 0) {
229
- writes.push({
230
- table: "artifact_evaluations",
231
- onConflict: "org_id,id",
232
- merge: false,
233
- rows: batch.artifact_evaluations.map((v) => ({
234
- org_id: tenancy.org_id,
235
- id: v.id,
236
- artifact_id: v.artifact_id,
237
- // Subject-one-of (00051): a run-subject row carries run_id, artifact_id
238
- // null; the CHECK rejects a row that sets both or neither.
239
- run_id: v.run_id ?? null,
240
- evaluator: v.evaluator,
241
- evaluator_kind: v.evaluator_kind,
242
- score: v.score,
243
- passed: v.passed,
244
- label: v.label,
245
- explanation: v.explanation,
246
- created_by: v.created_by,
247
- })),
248
- });
249
- }
250
230
  if (batch.eval_cases !== undefined && batch.eval_cases.length > 0) {
251
231
  writes.push({
252
232
  // An eval case is created once (via promote); a retry must not rewrite it.
@@ -319,20 +299,14 @@ function stampBatch(batch, tenancy) {
319
299
  ],
320
300
  });
321
301
  }
322
- if (batch.feedback !== undefined && batch.feedback.length > 0) {
302
+ if (batch.grades !== undefined && batch.grades.length > 0) {
303
+ // The SDK's current judgment write path. A grade may name its own org
304
+ // (feedback doctrine, verified by foreignOrgGrades before this).
323
305
  writes.push({
324
- table: "feedback",
325
- onConflict: "id",
306
+ table: "grades",
307
+ onConflict: "org_id,id",
326
308
  merge: false,
327
- rows: batch.feedback.map(({ org_id, ...row }) => ({
328
- // The verdict's own org wins when it has one — that is the whole of
329
- // QA-P6-010's fix. Note that `source_id` is deliberately absent:
330
- // `feedback.source` already means "who judged", and two columns a
331
- // letter apart meaning different things is N2's cautionary tale.
332
- org_id: org_id ?? tenancy.org_id,
333
- project_id: tenancy.project_id,
334
- ...row,
335
- })),
309
+ rows: batch.grades.map((g) => (0, grade_mappers_1.gradeToRow)(g, tenancy)),
336
310
  });
337
311
  }
338
312
  if (batch.envelopes !== undefined && batch.envelopes.length > 0) {
@@ -352,15 +326,3 @@ function stampBatch(batch, tenancy) {
352
326
  }
353
327
  return writes;
354
328
  }
355
- /**
356
- * Feedback rows naming an org other than the presented key's.
357
- *
358
- * Exists as its own exported function because the ingest endpoint must drop
359
- * these and COUNT them, and a check that lives inline in a request handler is
360
- * a check nobody can test in isolation. Returns the offending ids.
361
- */
362
- function foreignOrgFeedback(rows, keyOrgId) {
363
- return rows
364
- .filter((r) => r.org_id !== undefined && r.org_id !== keyOrgId)
365
- .map((r) => r.id);
366
- }
@@ -1 +1 @@
1
- {"version":3,"file":"store-migrations.d.ts","sourceRoot":"","sources":["../../src/telemetry/store-migrations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAE3C;sCACsC;AACtC,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,QAAQ,CAAC,QAAQ,GAAG,IAAI,CAiI9D"}
1
+ {"version":3,"file":"store-migrations.d.ts","sourceRoot":"","sources":["../../src/telemetry/store-migrations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAG3C;sCACsC;AACtC,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,QAAQ,CAAC,QAAQ,GAAG,IAAI,CAmL9D"}
@@ -11,6 +11,7 @@
11
11
  */
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  exports.runStoreMigrations = runStoreMigrations;
14
+ const grades_sql_1 = require("./grades-sql");
14
15
  /** Apply every pending schema migration to an open telemetry database. Safe to
15
16
  * call on every open (idempotent). */
16
17
  function runStoreMigrations(db) {
@@ -142,4 +143,54 @@ function runStoreMigrations(db) {
142
143
  }
143
144
  db.pragma("user_version = 13");
144
145
  }
146
+ // v14 (grade primitive, R1): the unified `grades` table + a one-time backfill
147
+ // from the local `feedback` table (the local mirror of migration 00070). The
148
+ // table itself comes from SCHEMA_SQL's CREATE IF NOT EXISTS (a no-op on
149
+ // migrating databases); this rung backfills existing feedback rows so a
150
+ // pre-grade database's verdicts still export as grades. The evaluations
151
+ // backfill lives in artifact-store.ts (it owns that table). INSERT OR IGNORE
152
+ // makes the backfill idempotent even if it races a live write. Additive.
153
+ if (db.pragma("user_version", { simple: true }) < 14) {
154
+ (0, grades_sql_1.backfillGradesFromFeedback)(db);
155
+ db.pragma("user_version = 14");
156
+ }
157
+ // v15 (grade primitive GP-2, mirrors migration 00072): drop the three GP-1-only
158
+ // compat columns `legacy_score`, `origin`, `label` from the local `grades` table,
159
+ // folding any `label` into `scale_label` first. SQLite cannot DROP COLUMN when a
160
+ // CHECK constraint references the column (`origin` has one), so this rebuilds the
161
+ // table into the new shape (= GRADES_TABLE_SQL) and copies the surviving columns.
162
+ // Idempotent: guarded on the presence of the `origin` column, so a re-open no-ops.
163
+ if (db.pragma("user_version", { simple: true }) < 15) {
164
+ const gradeCols = db.pragma("table_info(grades)");
165
+ const hasGrades = gradeCols.length > 0;
166
+ const hasOrigin = gradeCols.some((c) => c.name === "origin");
167
+ if (hasGrades && hasOrigin) {
168
+ db.exec(`
169
+ CREATE TABLE grades_gp2 (
170
+ id TEXT PRIMARY KEY,
171
+ ts TEXT,
172
+ subject_kind TEXT NOT NULL CHECK (subject_kind IN ('inference','run','artifact')),
173
+ subject_id TEXT NOT NULL,
174
+ score REAL NOT NULL,
175
+ scale_max REAL,
176
+ scale_label TEXT,
177
+ comment TEXT,
178
+ kind TEXT NOT NULL CHECK (kind IN ('human','model-judge','deterministic')),
179
+ grader TEXT,
180
+ source TEXT,
181
+ org_id TEXT,
182
+ created_by TEXT
183
+ );
184
+ INSERT OR IGNORE INTO grades_gp2
185
+ (id, ts, subject_kind, subject_id, score, scale_max, scale_label, comment, kind, grader, source, org_id, created_by)
186
+ SELECT
187
+ id, ts, subject_kind, subject_id, score, scale_max, COALESCE(scale_label, label), comment, kind, grader, source, org_id, created_by
188
+ FROM grades;
189
+ DROP TABLE grades;
190
+ ALTER TABLE grades_gp2 RENAME TO grades;
191
+ CREATE INDEX IF NOT EXISTS idx_grades_subject ON grades (subject_kind, subject_id);
192
+ `);
193
+ }
194
+ db.pragma("user_version = 15");
195
+ }
145
196
  }
@@ -9,7 +9,7 @@
9
9
  * separate handle. ExportableTelemetryStore MUST NOT gain capture accessors;
10
10
  * the export-isolation tests are the tripwire.
11
11
  */
12
- import type { EnvelopeRow, FeedbackRow, RunRow, StepRow, TelemetryRow, TelemetryStore } from "../types/telemetry";
12
+ import type { EnvelopeRow, GradeRow, RunRow, StepRow, TelemetryRow, TelemetryStore } from "../types/telemetry";
13
13
  import { type EndpointHealth } from "./health";
14
14
  /**
15
15
  * Superset of the TelemetryStore contract with the enumeration hooks the
@@ -23,10 +23,15 @@ export interface ExportableTelemetryStore extends TelemetryStore {
23
23
  rowid: number;
24
24
  row: TelemetryRow;
25
25
  }>;
26
- /** Feedback rows past the watermark, oldest first (Phase 4 mirror). */
27
- readFeedbackAfter(afterRowid: number, limit: number): Array<{
26
+ /** Record a unified judgment (grade primitive, R1) — the canonical write path
27
+ * for `rig.grade`. Writes the shared local `grades` table. */
28
+ recordGrade(row: GradeRow): void;
29
+ /** Grade rows past the watermark, oldest first (grade primitive `:grades`
30
+ * stream). Reads grades written by EITHER handle (telemetry + artifact) — one
31
+ * physical table over the shared telemetry file. */
32
+ readGradesAfter(afterRowid: number, limit: number): Array<{
28
33
  rowid: number;
29
- row: FeedbackRow;
34
+ row: GradeRow;
30
35
  }>;
31
36
  /** Record a run (E2 chunk A) — run.start/run.end. Upsert: run.end overwrites
32
37
  * the running projection with its terminal status/ended_at. */
@@ -47,8 +52,6 @@ export interface ExportableTelemetryStore extends TelemetryStore {
47
52
  * non-null inference_id, or null (E4 chunk A: bake-off rehydration resolves an
48
53
  * eval case's source step to the inference that keys its captured input). */
49
54
  getStepInferenceId(runId: string, stepKey: string): string | null;
50
- /** Newest-first local feedback read (console/dev inspection). */
51
- listFeedback(limit: number): FeedbackRow[];
52
55
  listEnvelopes(): EnvelopeRow[];
53
56
  /** Local exporter watermark (per source instance), 0 when unset. */
54
57
  getExportWatermark(sourceId: string): number;
@@ -1 +1 @@
1
- {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/telemetry/store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,MAAM,EACN,OAAO,EACP,YAAY,EACZ,cAAc,EACf,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAA2B,KAAK,cAAc,EAAuB,MAAM,UAAU,CAAC;AAG7F;;;;;GAKG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A;KAAE,CAAC,CAAC;IACxF,mEAAmE;IACnE,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAC1F;;iFAE6E;IAC7E,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAClE,aAAa,IAAI,WAAW,EAAE,CAAC;IAC/B,oEAAoE;IACpE,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7C,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9D;;;;;OAKG;IACH,kBAAkB,CAAC,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,cAAc,EAAE,CAAC;CAC3E;AAgSD,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,wBAAwB,CA6P3E"}
@@ -20,6 +20,7 @@ const node_fs_1 = require("node:fs");
20
20
  const node_path_1 = require("node:path");
21
21
  const health_1 = require("./health");
22
22
  const store_migrations_1 = require("./store-migrations");
23
+ const grades_sql_1 = require("./grades-sql");
23
24
  const SCHEMA_SQL = `
24
25
  CREATE TABLE IF NOT EXISTS inferences (
25
26
  id TEXT PRIMARY KEY,
@@ -154,7 +155,7 @@ CREATE TABLE IF NOT EXISTS steps (
154
155
  PRIMARY KEY (run_id, step_key, attempt_no)
155
156
  );
156
157
  CREATE INDEX IF NOT EXISTS idx_steps_run ON steps (run_id);
157
- `;
158
+ ${grades_sql_1.GRADES_TABLE_SQL}`;
158
159
  function toRunRow(r) {
159
160
  return {
160
161
  id: r.id,
@@ -185,25 +186,6 @@ function toStepRow(r) {
185
186
  failureClass: r.failure_class,
186
187
  };
187
188
  }
188
- function toFeedbackRow(r) {
189
- return {
190
- id: r.id,
191
- ts: r.ts,
192
- inferenceId: r.inference_id,
193
- episodeKey: r.episode_key,
194
- verdict: r.verdict,
195
- score: r.score,
196
- note: r.note,
197
- source: r.source,
198
- // `?? null` rather than a bare read: a v6 database returns `undefined`
199
- // for a column that did not exist when its rows were written, and
200
- // `undefined` would serialize to a MISSING key on the wire rather than an
201
- // explicit null — which reads to the server as "no opinion" instead of
202
- // "no org", a distinction that matters exactly once and expensively.
203
- orgId: r.org_id ?? null,
204
- createdBy: r.created_by ?? null,
205
- };
206
- }
207
189
  function toTelemetryRow(r) {
208
190
  return {
209
191
  id: r.id,
@@ -288,14 +270,6 @@ function openTelemetryStore(dbPath) {
288
270
  INSERT INTO envelopes (envelope_key, budget_usd, spent_usd, status)
289
271
  VALUES (?, ?, 0, 'open')
290
272
  ON CONFLICT (envelope_key) DO NOTHING
291
- `);
292
- const insertFeedback = db.prepare(`
293
- INSERT INTO feedback (
294
- id, ts, inference_id, episode_key, verdict, score, note, source, org_id, created_by
295
- )
296
- VALUES (
297
- @id, @ts, @inference_id, @episode_key, @verdict, @score, @note, @source, @org_id, @created_by
298
- )
299
273
  `);
300
274
  const accrueEnvelope = db.prepare(`
301
275
  UPDATE envelopes
@@ -321,6 +295,7 @@ function openTelemetryStore(dbPath) {
321
295
  export_seq = excluded.export_seq,
322
296
  meta_json = excluded.meta_json
323
297
  `);
298
+ const insertGrade = (0, grades_sql_1.prepareGradeInsert)(db);
324
299
  const insertStep = db.prepare(`
325
300
  INSERT OR IGNORE INTO steps (
326
301
  run_id, step_key, attempt_no, task, provenance, inference_id, span_trace_id, span_id,
@@ -374,25 +349,14 @@ function openTelemetryStore(dbPath) {
374
349
  mask_json: row.mask != null ? JSON.stringify(row.mask) : null,
375
350
  });
376
351
  },
377
- recordFeedback(row) {
378
- insertFeedback.run({
379
- id: row.id,
380
- ts: row.ts,
381
- inference_id: row.inferenceId,
382
- episode_key: row.episodeKey,
383
- verdict: row.verdict,
384
- score: row.score,
385
- note: row.note,
386
- source: row.source,
387
- org_id: row.orgId,
388
- created_by: row.createdBy,
389
- });
352
+ recordGrade(row) {
353
+ insertGrade.run((0, grades_sql_1.gradeBindParams)(row));
390
354
  },
391
- readFeedbackAfter(afterRowid, limit) {
355
+ readGradesAfter(afterRowid, limit) {
392
356
  const rows = db
393
- .prepare("SELECT rowid AS __rowid, * FROM feedback WHERE rowid > ? ORDER BY rowid LIMIT ?")
357
+ .prepare("SELECT rowid AS __rowid, * FROM grades WHERE rowid > ? ORDER BY rowid LIMIT ?")
394
358
  .all(afterRowid, limit);
395
- return rows.map((r) => ({ rowid: r.__rowid, row: toFeedbackRow(r) }));
359
+ return rows.map((r) => ({ rowid: r.__rowid, row: (0, grades_sql_1.toGradeRow)(r) }));
396
360
  },
397
361
  recordRun(row) {
398
362
  const seq = nextRunSeq.get().n;
@@ -446,12 +410,6 @@ function openTelemetryStore(dbPath) {
446
410
  .get(runId, stepKey);
447
411
  return r === undefined ? null : r.inference_id;
448
412
  },
449
- listFeedback(limit) {
450
- const rows = db
451
- .prepare("SELECT * FROM feedback ORDER BY ts DESC, rowid DESC LIMIT ?")
452
- .all(limit);
453
- return rows.map(toFeedbackRow);
454
- },
455
413
  queryByTag(tag, value) {
456
414
  return selectByTag.all(tag, value).map(toTelemetryRow);
457
415
  },