loopengine 0.3.100 → 0.3.101
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/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/models.yaml +9 -2
- package/dist/web/agents-config-page.js +212 -57
- package/dist/web/goals-page.js +2 -1
- package/dist/web/workflow-evidence.d.ts +86 -12
- package/dist/web/workflow-evidence.js +180 -42
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -94,7 +94,7 @@ export { createTrigger, updateTrigger, rotateTrigger, listTriggers, findTriggerB
|
|
|
94
94
|
export { checkCallbackUrl, callbackSecret, signCallback, deliverCallback, runCallbackPayload, isPrivateAddress, CallbackUrlError, type CallbackDelivery, type CallbackPending, type RunCallbackEvent } from './core/run-callbacks.js';
|
|
95
95
|
export { WorkflowRunner, FileRunStore, getRunStore, setRunStore, listRuns, getRun, isUnderWay, RunError, type WorkflowRun, type WorkflowRunStatus, type RunStore, type ExecuteRun, type RunOutcome, type StartRunInput } from './core/workflow-runs.js';
|
|
96
96
|
export { readWorkflows, readWorkflow, setWorkflowFields, setWorkflowDelivery, clearWorkflowFields, validateParams, workflowRunMessage, workflowPreviewMessage, migrateWorkflowsFile, WorkflowParamsError, readWorkspacePolicies, writeWorkspacePolicies, type Workflow, type WorkflowFields, type WorkflowParameter, type WorkflowModel, type WorkflowDelivery, type RunMessageExtras } from './core/workflows.js';
|
|
97
|
-
export { EvidenceError, workflowScores, runFeedbackFrom, readEvals, addEvalCase, updateEvalCase, removeEvalCase,
|
|
97
|
+
export { EvidenceError, workflowScores, runFeedbackFrom, readEvals, addEvalCase, updateEvalCase, removeEvalCase, setEvalCriteria, effectiveCriteria, codeCheck, judgeCriteria, checkCase, roundSummary, draftCriteria, startEvalRound, EVAL_CRITERIA_PROMPT, DRAFT_CRITERIA_PROMPT, REFERENCE_CRITERION, type WorkflowScores, type EvalCase, type EvalCaseResult, type EvalCheck, type EvalCriterion, type CriterionKind, type EvalRound, type WorkflowEvals, type EvalRunDeps } from './web/workflow-evidence.js';
|
|
98
98
|
export { globalConfigPageHtml } from './web/global-config-page.js';
|
|
99
99
|
export { playgroundHtml } from './web/playground.js';
|
|
100
100
|
export { readSkill, writeSkill, deleteSkill, SkillInvalidIdError, SkillNotFoundError } from './web/skills-admin.js';
|
package/dist/index.js
CHANGED
|
@@ -87,7 +87,7 @@ export { createTrigger, updateTrigger, rotateTrigger, listTriggers, findTriggerB
|
|
|
87
87
|
export { checkCallbackUrl, callbackSecret, signCallback, deliverCallback, runCallbackPayload, isPrivateAddress, CallbackUrlError } from './core/run-callbacks.js';
|
|
88
88
|
export { WorkflowRunner, FileRunStore, getRunStore, setRunStore, listRuns, getRun, isUnderWay, RunError } from './core/workflow-runs.js';
|
|
89
89
|
export { readWorkflows, readWorkflow, setWorkflowFields, setWorkflowDelivery, clearWorkflowFields, validateParams, workflowRunMessage, workflowPreviewMessage, migrateWorkflowsFile, WorkflowParamsError, readWorkspacePolicies, writeWorkspacePolicies } from './core/workflows.js';
|
|
90
|
-
export { EvidenceError, workflowScores, runFeedbackFrom, readEvals, addEvalCase, updateEvalCase, removeEvalCase,
|
|
90
|
+
export { EvidenceError, workflowScores, runFeedbackFrom, readEvals, addEvalCase, updateEvalCase, removeEvalCase, setEvalCriteria, effectiveCriteria, codeCheck, judgeCriteria, checkCase, roundSummary, draftCriteria, startEvalRound, EVAL_CRITERIA_PROMPT, DRAFT_CRITERIA_PROMPT, REFERENCE_CRITERION } from './web/workflow-evidence.js';
|
|
91
91
|
export { globalConfigPageHtml } from './web/global-config-page.js';
|
|
92
92
|
export { playgroundHtml } from './web/playground.js';
|
|
93
93
|
export { readSkill, writeSkill, deleteSkill, SkillInvalidIdError, SkillNotFoundError } from './web/skills-admin.js';
|
package/dist/models.yaml
CHANGED
|
@@ -17,10 +17,14 @@
|
|
|
17
17
|
|
|
18
18
|
# Taken from each provider's model pages and agent guides (2026-10-31),
|
|
19
19
|
# trimmed to models for agents and checked against the live model lists
|
|
20
|
-
# (2026-11-10)
|
|
21
|
-
#
|
|
20
|
+
# (2026-11-10), with later models added on 2026-11-24 (OpenAI's GPT-6.2
|
|
21
|
+
# and Gemini 4, both checked against the live lists). Older
|
|
22
|
+
# generations, "lite" and "mini" models are left out; type one under
|
|
23
|
+
# "Other…" to use it.
|
|
22
24
|
|
|
23
25
|
openai:
|
|
26
|
+
- gpt-6.2-sol
|
|
27
|
+
- gpt-6.2-astra
|
|
24
28
|
- gpt-6.1-terra
|
|
25
29
|
- gpt-6.1-sol
|
|
26
30
|
- gpt-6-luna
|
|
@@ -38,7 +42,10 @@ anthropic:
|
|
|
38
42
|
- claude-haiku-5-5
|
|
39
43
|
|
|
40
44
|
gemini:
|
|
45
|
+
- gemini-4-neon
|
|
41
46
|
- gemini-4-argon
|
|
47
|
+
- gemini-4-carbon
|
|
48
|
+
- gemini-4-hydrogen
|
|
42
49
|
- gemini-3.8-flash
|
|
43
50
|
- gemini-3.7-flash
|
|
44
51
|
- gemini-3.6-flash
|
|
@@ -68,6 +68,28 @@ export const agentsConfigPageHtml = `<!doctype html>
|
|
|
68
68
|
actions), then rows that open: its message, instructions, run options
|
|
69
69
|
and recent runs. */
|
|
70
70
|
.le-tab .le-pending { margin-left: 4px; font-size: 11px; padding: 0 6px; border-radius: 999px; background: var(--warn-soft); color: var(--warn); }
|
|
71
|
+
/* A workflow's own page: the agent's header and list intro give way to it. */
|
|
72
|
+
.wf-page-mode > .le-head, .wf-page-mode .wf-tab-head { display: none; }
|
|
73
|
+
.wf-page { display: grid; gap: 20px; }
|
|
74
|
+
.wf-page-head { display: grid; gap: 10px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
|
|
75
|
+
.wf-page-crumb-row { display: flex; align-items: center; gap: 10px; }
|
|
76
|
+
.wf-page-crumb { font-size: 13px; color: var(--ink-muted); text-decoration: none; }
|
|
77
|
+
.wf-page-crumb:hover { color: var(--accent-ink); }
|
|
78
|
+
.wf-page-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
|
|
79
|
+
.wf-page-title-row h1 { margin: 0; font-size: 24px; letter-spacing: -0.01em; line-height: 1.2; }
|
|
80
|
+
.wf-page-desc { margin: 0; color: var(--ink-muted); max-width: 80ch; }
|
|
81
|
+
.wf-page-meta { display: flex; flex-wrap: wrap; gap: 8px 28px; font-size: 13px; }
|
|
82
|
+
.wf-page-meta-item { display: grid; gap: 2px; min-width: 0; }
|
|
83
|
+
.wf-page-meta-k { font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-faint); }
|
|
84
|
+
.wf-page-meta-item a { color: var(--accent-ink); font-weight: 600; text-decoration: none; }
|
|
85
|
+
.wf-page .wf-page-body { padding: 0; gap: 16px; }
|
|
86
|
+
.wf-page-starts { display: grid; gap: 2px; color: var(--ink); }
|
|
87
|
+
.wf-page-last { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
|
|
88
|
+
.wf-list-box.wf-page-box { border: 0; border-radius: 0; background: none; overflow: visible; }
|
|
89
|
+
.wf-page-brief { display: grid; gap: 10px; }
|
|
90
|
+
.wf-page-brief h2 { margin: 0; font-size: 15px; }
|
|
91
|
+
.wf-page .workflow-steps-text { margin: 0; padding: 14px 16px; border-radius: 10px; background: var(--surface); font-size: 13.5px; line-height: 1.6; max-height: 480px; overflow: auto; white-space: pre-wrap; }
|
|
92
|
+
.wf-page .workflow-result:empty { display: none; }
|
|
71
93
|
.wf-tab-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin: 0 0 20px; }
|
|
72
94
|
.wf-tab-head p { margin: 0; max-width: 72ch; }
|
|
73
95
|
.wf-new-btn { flex: none; display: inline-flex; align-items: center; height: 36px; padding: 0 16px; border-radius: 8px; background: var(--accent); color: var(--on-accent); font-size: 13.5px; font-weight: 600; text-decoration: none; white-space: nowrap; }
|
|
@@ -184,6 +206,20 @@ export const agentsConfigPageHtml = `<!doctype html>
|
|
|
184
206
|
.wf-score-v { font-size: 18px; font-variant-numeric: tabular-nums; }
|
|
185
207
|
.wf-evals-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
|
|
186
208
|
.wf-evals-bar button, .wf-case-actions button { height: 30px; padding: 0 12px; border-radius: 8px; font-size: 13px; font-weight: 600; border: 1px solid var(--accent); background: var(--accent-soft); color: var(--accent-ink); }
|
|
209
|
+
.wf-crits { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
|
|
210
|
+
.wf-crit { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: center; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; }
|
|
211
|
+
.wf-crit-kind { font-size: 12px; color: var(--ink-muted); }
|
|
212
|
+
.wf-crit-rate { font-variant-numeric: tabular-nums; }
|
|
213
|
+
.wf-crit-form { display: grid; gap: 8px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
|
|
214
|
+
.wf-crit-form[hidden] { display: none; }
|
|
215
|
+
.wf-crit-row { display: grid; grid-template-columns: 170px minmax(0, 1fr) 180px auto; gap: 8px; align-items: center; }
|
|
216
|
+
.wf-crit-row select, .wf-crit-row input { font: inherit; font-size: 13px; height: 32px; padding: 0 8px; min-width: 0; }
|
|
217
|
+
.wf-crit-row input[data-crit-value][hidden] { visibility: hidden; display: block; }
|
|
218
|
+
.wf-crit-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
|
|
219
|
+
.wf-crit-bar button, .wf-crit-edit { height: 30px; padding: 0 12px; border-radius: 8px; font-size: 13px; font-weight: 600; border: 1px solid var(--accent); background: var(--accent-soft); color: var(--accent-ink); }
|
|
220
|
+
.wf-crit-bar button.plain { border-color: var(--line); background: var(--bg); color: var(--ink); }
|
|
221
|
+
.wf-case-fails { margin: 0; padding-left: 18px; display: grid; gap: 2px; font-size: 12.5px; color: var(--ink-muted); }
|
|
222
|
+
@media (max-width: 720px) { .wf-crit-row { grid-template-columns: minmax(0, 1fr) auto; } .wf-crit-row input[data-crit-text] { grid-column: 1 / -1; } }
|
|
187
223
|
.wf-cases { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
|
|
188
224
|
.wf-case { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; display: grid; gap: 6px; font-size: 13px; }
|
|
189
225
|
.wf-case-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
|
|
@@ -890,8 +926,17 @@ ${renderMarkdownScript}
|
|
|
890
926
|
|
|
891
927
|
// Which workflow is open in the list, and each one's chosen tab: kept
|
|
892
928
|
// across redraws (a running run's refresh, a save), and in the URL.
|
|
893
|
-
var openWorkflowId =
|
|
929
|
+
var openWorkflowId = null;
|
|
894
930
|
var workflowTabs = {};
|
|
931
|
+
// A workflow's own page: ?tab=workflows&workflow=<id> shows that one
|
|
932
|
+
// workflow (its brief on top, its tabs below) in place of the agent's
|
|
933
|
+
// header and list. Every link to a workflow lands here.
|
|
934
|
+
var pageParams = new URLSearchParams(location.search);
|
|
935
|
+
var workflowPageId = pageParams.get('tab') === 'workflows' && pageParams.get('workflow') || null;
|
|
936
|
+
if (workflowPageId && pageParams.get('wtab')) workflowTabs[workflowPageId] = pageParams.get('wtab');
|
|
937
|
+
function workflowPageHref(agent, id, tab) {
|
|
938
|
+
return '/agents/config?agent=' + encodeURIComponent(agent) + '&tab=workflows&workflow=' + encodeURIComponent(id) + (tab ? '&wtab=' + encodeURIComponent(tab) : '');
|
|
939
|
+
}
|
|
895
940
|
|
|
896
941
|
function workflowLastRun(w) {
|
|
897
942
|
return (w.recentRuns || []).slice().sort(function (a, b) { return String(b.started_at).localeCompare(String(a.started_at)); })[0] || null;
|
|
@@ -942,6 +987,7 @@ ${renderMarkdownScript}
|
|
|
942
987
|
|
|
943
988
|
// Opens one workflow's row (closing the one open before), or closes it.
|
|
944
989
|
function setWorkflowOpen(card, open) {
|
|
990
|
+
if (card.classList.contains('wf-page')) return;
|
|
945
991
|
var list = card.parentNode;
|
|
946
992
|
if (open && list) {
|
|
947
993
|
var others = list.querySelectorAll('.wf-row.is-open');
|
|
@@ -1147,40 +1193,95 @@ ${renderMarkdownScript}
|
|
|
1147
1193
|
return '<div class="wf-score"><span class="wf-score-k">' + label + '</span><strong class="wf-score-v">' + value + '</strong>' + (detail ? '<span class="hint">' + detail + '</span>' : '') + '</div>';
|
|
1148
1194
|
}
|
|
1149
1195
|
|
|
1196
|
+
// A criterion's kind, in words, for its row and its editor.
|
|
1197
|
+
var CRIT_KINDS = [
|
|
1198
|
+
['judge', 'Judge decides'],
|
|
1199
|
+
['contains', 'Result contains'],
|
|
1200
|
+
['not_contains', 'Result doesn' + String.fromCharCode(8217) + 't contain'],
|
|
1201
|
+
['tool_called', 'Calls tool'],
|
|
1202
|
+
['tool_not_called', 'Doesn' + String.fromCharCode(8217) + 't call tool'],
|
|
1203
|
+
['reference', 'Matches the good result'],
|
|
1204
|
+
];
|
|
1205
|
+
function critKindText(c) {
|
|
1206
|
+
var label = (CRIT_KINDS.filter(function (k) { return k[0] === c.kind; })[0] || CRIT_KINDS[0])[1];
|
|
1207
|
+
return c.value ? label + ' ' + String.fromCharCode(8220) + c.value + String.fromCharCode(8221) : label;
|
|
1208
|
+
}
|
|
1209
|
+
function critRowHtml(c) {
|
|
1210
|
+
var needsValue = c.kind !== 'judge' && c.kind !== 'reference';
|
|
1211
|
+
return '<div class="wf-crit-row" data-crit-id="' + escapeHtml(c.id || '') + '">' +
|
|
1212
|
+
'<select data-crit-kind aria-label="How it' + RSQ + 's checked">' + CRIT_KINDS.map(function (k) { return '<option value="' + k[0] + '"' + (k[0] === c.kind ? ' selected' : '') + '>' + k[1] + '</option>'; }).join('') + '</select>' +
|
|
1213
|
+
'<input data-crit-text value="' + escapeHtml(c.text || '') + '" placeholder="e.g. The reply gives the order' + RSQ + 's tracking number" aria-label="The check">' +
|
|
1214
|
+
'<input data-crit-value value="' + escapeHtml(c.value || '') + '" placeholder="' + (c.kind && c.kind.indexOf('tool') === 0 ? 'tool name' : 'exact text') + '" aria-label="What to look for"' + (needsValue ? '' : ' hidden') + '>' +
|
|
1215
|
+
'<button type="button" class="wf-link wf-crit-remove">Remove</button></div>';
|
|
1216
|
+
}
|
|
1217
|
+
var REFERENCE_CRIT = { id: 'reference', text: 'Matches the good result: the same facts and decisions', kind: 'reference' };
|
|
1218
|
+
|
|
1150
1219
|
function workflowEvidenceHtml(w, runsHtml) {
|
|
1151
1220
|
var s = w.scores || { runs: 0, done: 0, failed: 0, approvals: { approved: 0, refused: 0 }, feedback: { count: 0, good: 0, bad: 0, edits: { none: 0, light: 0, heavy: 0 } } };
|
|
1152
|
-
var evals = w.evals || { cases: [], rounds: [] };
|
|
1221
|
+
var evals = w.evals || { cases: [], criteria: [], rounds: [] };
|
|
1222
|
+
var criteria = evals.criteria && evals.criteria.length ? evals.criteria : [REFERENCE_CRIT];
|
|
1153
1223
|
var round = evals.rounds[0];
|
|
1224
|
+
var checked = round && round.passRates;
|
|
1154
1225
|
var decided = s.approvals.approved + s.approvals.refused;
|
|
1155
1226
|
var f = s.feedback;
|
|
1227
|
+
var evalsValue = !round ? String.fromCharCode(8212) : checked ? round.allPassed + ' / ' + round.cases.length : typeof round.average === 'number' ? round.average.toFixed(1) + ' / 5' : String.fromCharCode(8212);
|
|
1228
|
+
var evalsDetail = !round ? (evals.cases.length ? 'not run yet' : 'no cases yet') : (checked ? 'passed every check' + DOT : '') + new Date(round.at).toLocaleDateString(undefined, { month: 'short', day: 'numeric' });
|
|
1156
1229
|
var tiles = '<div class="wf-scores">' +
|
|
1157
1230
|
scoreTileHtml('Runs', String(s.runs), s.runs ? s.done + ' done' + DOT + s.failed + ' failed' : 'none yet') +
|
|
1158
1231
|
scoreTileHtml('Approvals', decided ? Math.round(100 * s.approvals.approved / decided) + '%' : String.fromCharCode(8212), decided ? s.approvals.approved + ' approved' + DOT + s.approvals.refused + ' refused' : 'none asked yet') +
|
|
1159
1232
|
scoreTileHtml('Feedback', f.count ? String(f.count) : String.fromCharCode(8212), f.count ? (f.good + f.bad ? f.good + ' good' + DOT + f.bad + ' bad' + DOT : '') + f.edits.none + ' unedited' + DOT + f.edits.light + ' light' + DOT + f.edits.heavy + ' heavy edits' : 'none reported yet') +
|
|
1160
|
-
scoreTileHtml('Evals',
|
|
1233
|
+
scoreTileHtml('Evals', evalsValue, evalsDetail) +
|
|
1161
1234
|
'</div>';
|
|
1162
1235
|
var feedbackHint = f.count ? '' : '<p class="hint" style="margin:0">An app reports what happened to a result with <code>POST /agents/' + escapeHtml(currentName || '') + '/runs/<runId>/feedback</code> and <code>{"final": "the text it sent"}</code> or <code>{"verdict": "good"}</code>.</p>';
|
|
1236
|
+
// Each criterion, with how often the latest round passed it.
|
|
1237
|
+
var rateOf = {};
|
|
1238
|
+
(checked ? round.passRates : []).forEach(function (r) { rateOf[r.criterionId] = r; });
|
|
1239
|
+
var critList = criteria.map(function (c) {
|
|
1240
|
+
var r = rateOf[c.id];
|
|
1241
|
+
var pill = !r || !r.total ? '' : '<span class="le-pill ' + (r.passed === r.total ? 'good' : r.passed * 2 >= r.total ? 'ask' : 'bad') + ' wf-crit-rate">' + r.passed + ' / ' + r.total + '</span>';
|
|
1242
|
+
return '<li class="wf-crit"><span><strong>' + escapeHtml(c.text) + '</strong><br><span class="wf-crit-kind">' + escapeHtml(critKindText(c)) + '</span></span>' + pill + '</li>';
|
|
1243
|
+
}).join('');
|
|
1244
|
+
var critSection = '<h4 class="wf-sub">Criteria</h4>' +
|
|
1245
|
+
'<p class="hint" style="margin:0">' + (evals.criteria && evals.criteria.length
|
|
1246
|
+
? 'Every result is checked on each of these, yes or no. Exact text and tool checks are checked directly; the rest by a judge model from another provider.'
|
|
1247
|
+
: 'No criteria yet, so each result is only compared with its case' + RSQ + 's good result. Add the checks that matter, or draft them from the brief.') + '</p>' +
|
|
1248
|
+
'<ul class="wf-crits">' + critList + '</ul>' +
|
|
1249
|
+
'<div class="wf-crit-bar"><button type="button" class="wf-crit-edit">' + (evals.criteria && evals.criteria.length ? 'Edit criteria' : 'Add criteria') + '</button></div>' +
|
|
1250
|
+
'<div class="wf-crit-form" hidden>' +
|
|
1251
|
+
'<div class="wf-crit-rows">' + (evals.criteria && evals.criteria.length ? evals.criteria : []).map(critRowHtml).join('') + '</div>' +
|
|
1252
|
+
'<div class="wf-crit-bar"><button type="button" class="plain wf-crit-add">+ Add a check</button><button type="button" class="plain wf-crit-draft">Draft from the brief</button>' +
|
|
1253
|
+
'<span style="flex:1"></span><button type="button" class="plain wf-crit-cancel">Cancel</button><button type="button" class="wf-crit-save">Save criteria</button></div>' +
|
|
1254
|
+
'<span class="hint wf-crit-status"></span>' +
|
|
1255
|
+
'</div>';
|
|
1163
1256
|
var latest = {};
|
|
1164
1257
|
(round ? round.cases : []).forEach(function (c) { latest[c.caseId] = c; });
|
|
1258
|
+
var critName = {};
|
|
1259
|
+
((round && round.criteria) || criteria).forEach(function (c) { critName[c.id] = c.text; });
|
|
1165
1260
|
var running = evals.running;
|
|
1166
1261
|
var cases = evals.cases.map(function (c, i) {
|
|
1167
1262
|
var last = latest[c.id];
|
|
1168
1263
|
var values = Object.keys(c.params || {}).map(function (k) { var v = String(c.params[k]); return escapeHtml(k) + ': ' + escapeHtml(v.length > 60 ? v.slice(0, 60) + String.fromCharCode(8230) : v); }).join(DOT);
|
|
1169
|
-
|
|
1170
|
-
|
|
1264
|
+
var fails = last && last.checks ? last.checks.filter(function (x) { return !x.pass; }) : [];
|
|
1265
|
+
var pill = !last ? ''
|
|
1266
|
+
: last.checks ? (fails.length ? '<span class="le-pill bad">' + fails.length + ' of ' + last.checks.length + ' checks failed</span>' : '<span class="le-pill good">All ' + last.checks.length + ' checks passed</span>')
|
|
1267
|
+
: typeof last.score === 'number' ? '<span class="le-pill ' + (last.score >= 4 ? 'good' : last.score === 3 ? 'ask' : 'bad') + '">' + last.score + ' / 5</span>' : '<span class="le-pill bad">Not scored</span>';
|
|
1268
|
+
var why = !last ? ''
|
|
1269
|
+
: last.checks ? (fails.length ? '<ul class="wf-case-fails">' + fails.map(function (x) { return '<li><strong>' + escapeHtml(critName[x.criterionId] || x.criterionId) + '</strong>' + (x.reason ? ': ' + escapeHtml(x.reason) : '') + '</li>'; }).join('') + '</ul>' : '')
|
|
1270
|
+
: '<p class="hint" style="margin:0">' + escapeHtml(last.reason || last.error || '') + '</p>';
|
|
1271
|
+
return '<li class="wf-case" data-case="' + escapeHtml(c.id) + '"><div class="wf-case-head"><strong>Case ' + (i + 1) + '</strong>' + pill +
|
|
1171
1272
|
'<span class="hint">' + (values || 'no inputs') + '</span><button type="button" class="wf-link wf-case-remove">Remove</button></div>' +
|
|
1172
|
-
|
|
1173
|
-
'<details><summary>Good result' + (last && last.result ? ' and its latest result' : '') + '</summary>' +
|
|
1174
|
-
'<textarea class="wf-case-ref" aria-label="Good result for case ' + (i + 1) + '">' + escapeHtml(c.reference) + '</textarea>' +
|
|
1273
|
+
why +
|
|
1274
|
+
'<details><summary>Good result' + (c.reference ? '' : ' (none)') + (last && last.result ? ' and its latest result' : '') + '</summary>' +
|
|
1275
|
+
'<textarea class="wf-case-ref" aria-label="Good result for case ' + (i + 1) + '" placeholder="Optional: what a good result says, to compare against">' + escapeHtml(c.reference || '') + '</textarea>' +
|
|
1175
1276
|
'<div class="wf-case-actions"><button type="button" class="wf-case-save">Save good result</button></div>' +
|
|
1176
|
-
(last && last.result ? '<div class="workflow-run-entry-label">Latest result</div><div class="workflow-steps-text">' + escapeHtml(last.result) + '</div>' : '') +
|
|
1277
|
+
(last && last.result ? '<div class="workflow-run-entry-label">Latest result' + (last.tools && last.tools.length ? ' <span class="hint">(called ' + escapeHtml(last.tools.join(', ')) + ')</span>' : '') + '</div><div class="workflow-steps-text">' + escapeHtml(last.result) + '</div>' : '') +
|
|
1177
1278
|
'</details></li>';
|
|
1178
1279
|
}).join('');
|
|
1179
|
-
return tiles + feedbackHint +
|
|
1280
|
+
return tiles + feedbackHint + critSection +
|
|
1180
1281
|
'<h4 class="wf-sub">Eval cases</h4>' +
|
|
1181
1282
|
'<div class="wf-evals-bar"><button type="button" class="wf-evals-run"' + (!evals.cases.length || running ? ' disabled' : '') + '>' + (running ? 'Running ' + running.done + ' of ' + running.total + String.fromCharCode(8230) : 'Run evals') + '</button>' +
|
|
1182
1283
|
'<span class="hint">' + (round ? 'Last run ' + escapeHtml(new Date(round.at).toLocaleString()) + DOT + 'model ' + escapeHtml(round.model) + DOT + 'judged by ' + escapeHtml(round.judge) : 'A test run: tools that need approval aren' + RSQ + 't run, and nobody is asked anything.') + '</span></div>' +
|
|
1183
|
-
(cases ? '<ul class="wf-cases">' + cases + '</ul>' : '<p class="hint" style="margin:0">No cases yet. Save a
|
|
1284
|
+
(cases ? '<ul class="wf-cases">' + cases + '</ul>' : '<p class="hint" style="margin:0">No cases yet. Save a run from History below as a case, then run the cases after each change to the instructions or model.</p>') +
|
|
1184
1285
|
'<h4 class="wf-sub">History</h4>' +
|
|
1185
1286
|
(runsHtml ? '<ul class="schedule-history">' + runsHtml + '</ul>' : '<p class="hint" style="margin:0">No runs yet.</p>');
|
|
1186
1287
|
}
|
|
@@ -1199,13 +1300,18 @@ ${renderMarkdownScript}
|
|
|
1199
1300
|
}
|
|
1200
1301
|
|
|
1201
1302
|
function renderWorkflowsHtml(name, workflows) {
|
|
1303
|
+
if (workflowPageId) {
|
|
1304
|
+
var page = workflows.filter(function (x) { return x.id === workflowPageId; });
|
|
1305
|
+
if (!page.length) return '<div class="wf-empty-state"><strong>No workflow ' + escapeHtml(workflowPageId) + ' on this agent</strong><p>It may have been removed.</p><a class="wf-new-btn" href="/agents/config?agent=' + encodeURIComponent(name) + '&tab=workflows">See its workflows</a></div>';
|
|
1306
|
+
workflows = page;
|
|
1307
|
+
}
|
|
1202
1308
|
if (!workflows.length) {
|
|
1203
1309
|
return '<div class="wf-empty-state"><strong>No workflows yet</strong><p>Say what this agent should do in a sentence or two, or start from an example, and it' + String.fromCharCode(8217) + 's planned and set up for you.</p><a class="wf-new-btn" href="/workflows/new?agent=' + encodeURIComponent(name) + '">Build a workflow</a></div>';
|
|
1204
1310
|
}
|
|
1205
1311
|
// Those that need someone first: waiting for a decision, then failed.
|
|
1206
1312
|
var rank = function (w) { return workflowNeedsDecision(w) ? 0 : (workflowLastRun(w) || {}).status === 'error' ? 1 : 2; };
|
|
1207
1313
|
var sorted = workflows.map(function (w, i) { return { w: w, i: i }; }).sort(function (a, b) { return rank(a.w) - rank(b.w) || a.i - b.i; }).map(function (x) { return x.w; });
|
|
1208
|
-
return '<div class="wf-list-box">' + sorted.map(function (w) {
|
|
1314
|
+
return '<div class="wf-list-box' + (workflowPageId ? ' wf-page-box' : '') + '">' + sorted.map(function (w) {
|
|
1209
1315
|
var paramNames = Object.keys(w.parameters || {});
|
|
1210
1316
|
var params = paramNames.map(function (p) {
|
|
1211
1317
|
var spec = w.parameters[p];
|
|
@@ -1231,10 +1337,39 @@ ${renderMarkdownScript}
|
|
|
1231
1337
|
runEvidenceHtml(w, r) + '</li>';
|
|
1232
1338
|
}).join('');
|
|
1233
1339
|
var last = workflowLastRun(w);
|
|
1234
|
-
var tab = workflowTabs[w.id] || 'brief';
|
|
1340
|
+
var tab = workflowTabs[w.id] || (workflowPageId ? 'evidence' : 'brief');
|
|
1235
1341
|
var open = openWorkflowId === w.id;
|
|
1236
1342
|
var panel = function (key, html) { return '<div class="wf-panel" data-panel="' + key + '"' + (tab === key ? '' : ' hidden') + '>' + html + '</div>'; };
|
|
1237
1343
|
var tabBtn = function (key, label) { return '<button type="button" role="tab" class="wf-tab" data-tab="' + key + '" aria-selected="' + (tab === key) + '">' + label + '</button>'; };
|
|
1344
|
+
if (workflowPageId) {
|
|
1345
|
+
var agentLabel = currentCfg && currentCfg.displayName ? currentCfg.displayName : name;
|
|
1346
|
+
document.title = w.title + ' ' + String.fromCharCode(183) + ' ' + agentLabel;
|
|
1347
|
+
return '<article class="workflow-card wf-page is-open" data-workflow="' + escapeHtml(w.id) + '">' +
|
|
1348
|
+
'<header class="wf-page-head">' +
|
|
1349
|
+
'<div class="wf-page-crumb-row"><button type="button" class="le-menu-btn" data-le-menu aria-label="Open navigation">☰</button>' +
|
|
1350
|
+
'<a class="wf-page-crumb" href="/agents/config?agent=' + encodeURIComponent(name) + '&tab=workflows">' + String.fromCharCode(8592) + ' ' + escapeHtml(agentLabel) + ' ' + String.fromCharCode(183) + ' Workflows</a></div>' +
|
|
1351
|
+
'<div class="wf-page-title-row"><h1>' + escapeHtml(w.title) + '</h1>' +
|
|
1352
|
+
'<span class="wf-row-actions"><button type="button" class="workflow-edit">Edit</button></span></div>' +
|
|
1353
|
+
(w.description && w.description !== w.title ? '<p class="wf-page-desc">' + escapeHtml(w.description) + '</p>' : '') +
|
|
1354
|
+
'<div class="wf-page-meta">' +
|
|
1355
|
+
'<span class="wf-page-meta-item"><span class="wf-page-meta-k">Agent</span><a href="/agents/config?agent=' + encodeURIComponent(name) + '">' + escapeHtml(agentLabel) + '</a></span>' +
|
|
1356
|
+
'<span class="wf-page-meta-item"><span class="wf-page-meta-k">Starts</span><span class="wf-page-starts">' + workflowStartsSummary(w) + '</span></span>' +
|
|
1357
|
+
'<span class="wf-page-meta-item"><span class="wf-page-meta-k">Last run</span><span class="wf-page-last">' + workflowLastRunHtml(last) + '</span></span>' +
|
|
1358
|
+
(w.jobs && w.jobs.length ? '<span class="wf-page-meta-item"><span class="wf-page-meta-k">For job</span><span>' + w.jobs.map(function (j) { return '<a href="/jobs?job=' + encodeURIComponent(j.id) + '">' + escapeHtml(j.title) + '</a>'; }).join(', ') + '</span></span>' : '') +
|
|
1359
|
+
'</div>' +
|
|
1360
|
+
'</header>' +
|
|
1361
|
+
'<div class="wf-row-body wf-page-body">' +
|
|
1362
|
+
'<section class="wf-page-brief"><h2>Brief</h2>' + workflowBriefHtml(w) + '</section>' +
|
|
1363
|
+
'<div class="wf-tabs" role="tablist">' + tabBtn('evidence', 'Evidence' + (runs ? ' <span class="wf-tab-count">' + w.recentRuns.length + '</span>' : '')) + tabBtn('triggers', 'Triggers') + tabBtn('messages', 'Messages') + tabBtn('contract', 'Contract') + '</div>' +
|
|
1364
|
+
panel('evidence', workflowEvidenceHtml(w, runs)) +
|
|
1365
|
+
panel('triggers', workflowTriggersHtml(w, name, params)) +
|
|
1366
|
+
panel('messages', workflowMessagesHtml(w, name)) +
|
|
1367
|
+
panel('contract', workflowContractHtml(w, name, params)) +
|
|
1368
|
+
'<div class="hint workflow-result"></div>' +
|
|
1369
|
+
'<div class="wf-row-foot"><span class="hint">ID <code>' + escapeHtml(w.id) + '</code>, used by the API, schedules and webhooks</span><button type="button" class="wf-remove workflow-forget" title="Its schedules and webhooks go; its instructions stay as a skill for Chat">Remove</button></div>' +
|
|
1370
|
+
'</div>' +
|
|
1371
|
+
'</article>';
|
|
1372
|
+
}
|
|
1238
1373
|
return '<article class="workflow-card wf-row' + (open ? ' is-open' : '') + '" data-workflow="' + escapeHtml(w.id) + '">' +
|
|
1239
1374
|
'<div class="wf-row-head" role="button" tabindex="0" aria-expanded="' + open + '">' +
|
|
1240
1375
|
'<span class="wf-row-caret" aria-hidden="true"></span>' +
|
|
@@ -1286,23 +1421,6 @@ ${renderMarkdownScript}
|
|
|
1286
1421
|
var workflowsRefreshTimer = null;
|
|
1287
1422
|
// Set by a workflow's "Add a schedule", for the Schedules tab's form.
|
|
1288
1423
|
var pendingScheduleWorkflow = null;
|
|
1289
|
-
// Set by a schedule's workflow link: the card to scroll to and mark.
|
|
1290
|
-
var pendingWorkflowFocus = null;
|
|
1291
|
-
|
|
1292
|
-
function focusWorkflowCard(tries) {
|
|
1293
|
-
if (!pendingWorkflowFocus) return;
|
|
1294
|
-
var card = detail.querySelector('.workflow-card[data-workflow="' + CSS.escape(pendingWorkflowFocus) + '"]');
|
|
1295
|
-
if (!card) {
|
|
1296
|
-
if ((tries || 0) < 40) setTimeout(function () { focusWorkflowCard((tries || 0) + 1); }, 150);
|
|
1297
|
-
return;
|
|
1298
|
-
}
|
|
1299
|
-
pendingWorkflowFocus = null;
|
|
1300
|
-
setWorkflowOpen(card, true);
|
|
1301
|
-
card.scrollIntoView({ block: 'start' });
|
|
1302
|
-
card.classList.add('workflow-focus');
|
|
1303
|
-
setTimeout(function () { card.classList.remove('workflow-focus'); }, 2500);
|
|
1304
|
-
}
|
|
1305
|
-
|
|
1306
1424
|
// Set by a workflow's Edit on the Skills list: the workflow to open in
|
|
1307
1425
|
// its editor once the Workflows tab has drawn it.
|
|
1308
1426
|
var pendingWorkflowEdit = null;
|
|
@@ -1823,24 +1941,25 @@ ${renderMarkdownScript}
|
|
|
1823
1941
|
var id = card.dataset.workflow;
|
|
1824
1942
|
var result = card.querySelector('.workflow-result');
|
|
1825
1943
|
var base = '/agents/' + encodeURIComponent(name) + '/workflows/' + encodeURIComponent(id);
|
|
1944
|
+
// A row in the list opens the workflow's own page.
|
|
1826
1945
|
var head = card.querySelector('.wf-row-head');
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1946
|
+
if (head) {
|
|
1947
|
+
head.addEventListener('click', function (ev) {
|
|
1948
|
+
if (ev.target.closest('button, a')) return;
|
|
1949
|
+
location.href = workflowPageHref(name, id);
|
|
1950
|
+
});
|
|
1951
|
+
head.addEventListener('keydown', function (ev) {
|
|
1952
|
+
if (ev.target !== head || (ev.key !== 'Enter' && ev.key !== ' ')) return;
|
|
1953
|
+
ev.preventDefault();
|
|
1954
|
+
location.href = workflowPageHref(name, id);
|
|
1955
|
+
});
|
|
1956
|
+
}
|
|
1836
1957
|
var tabs = card.querySelectorAll('.wf-tab');
|
|
1837
1958
|
for (var t = 0; t < tabs.length; t++) tabs[t].addEventListener('click', function (ev) { showWorkflowTab(card, ev.currentTarget.dataset.tab); });
|
|
1838
1959
|
card.querySelector('.workflow-edit').addEventListener('click', function () { openWorkflowEditor(name, card); });
|
|
1839
|
-
// Opens the
|
|
1840
|
-
card.querySelector('.workflow-triggers-open')
|
|
1841
|
-
|
|
1842
|
-
showWorkflowTab(card, 'triggers');
|
|
1843
|
-
});
|
|
1960
|
+
// Opens the workflow's page on its Triggers tab.
|
|
1961
|
+
var triggersBtn = card.querySelector('.workflow-triggers-open');
|
|
1962
|
+
if (triggersBtn) triggersBtn.addEventListener('click', function () { location.href = workflowPageHref(name, id, 'triggers'); });
|
|
1844
1963
|
// Messages: where every run's updates and decisions go.
|
|
1845
1964
|
var msgForm = card.querySelector('.wf-msg-form');
|
|
1846
1965
|
if (msgForm) {
|
|
@@ -1907,7 +2026,52 @@ ${renderMarkdownScript}
|
|
|
1907
2026
|
}
|
|
1908
2027
|
}
|
|
1909
2028
|
// Evidence: save a run as an eval case, change or remove a case, run them.
|
|
1910
|
-
card.querySelector('.wf-row-body')
|
|
2029
|
+
var body = card.querySelector('.wf-row-body');
|
|
2030
|
+
// Criteria: the editor's rows, drafting from the brief, saving.
|
|
2031
|
+
var critForm = card.querySelector('.wf-crit-form');
|
|
2032
|
+
var critStatus = card.querySelector('.wf-crit-status');
|
|
2033
|
+
body.addEventListener('change', function (ev) {
|
|
2034
|
+
var kind = ev.target.closest('[data-crit-kind]');
|
|
2035
|
+
if (!kind) return;
|
|
2036
|
+
var value = kind.closest('.wf-crit-row').querySelector('[data-crit-value]');
|
|
2037
|
+
value.hidden = kind.value === 'judge' || kind.value === 'reference';
|
|
2038
|
+
value.placeholder = kind.value.indexOf('tool') === 0 ? 'tool name' : 'exact text';
|
|
2039
|
+
});
|
|
2040
|
+
body.addEventListener('click', function (ev) {
|
|
2041
|
+
var cbtn = ev.target.closest('.wf-crit-edit, .wf-crit-add, .wf-crit-remove, .wf-crit-cancel, .wf-crit-draft, .wf-crit-save');
|
|
2042
|
+
if (!cbtn || !critForm) return;
|
|
2043
|
+
var rows = critForm.querySelector('.wf-crit-rows');
|
|
2044
|
+
if (cbtn.classList.contains('wf-crit-edit')) {
|
|
2045
|
+
critForm.hidden = false;
|
|
2046
|
+
cbtn.hidden = true;
|
|
2047
|
+
if (!rows.children.length) rows.insertAdjacentHTML('beforeend', critRowHtml({ kind: 'judge' }));
|
|
2048
|
+
return;
|
|
2049
|
+
}
|
|
2050
|
+
if (cbtn.classList.contains('wf-crit-add')) { rows.insertAdjacentHTML('beforeend', critRowHtml({ kind: 'judge' })); return; }
|
|
2051
|
+
if (cbtn.classList.contains('wf-crit-remove')) { cbtn.closest('.wf-crit-row').remove(); return; }
|
|
2052
|
+
if (cbtn.classList.contains('wf-crit-cancel')) { workflowTabs[id] = 'evidence'; loadWorkflowsSection(name); return; }
|
|
2053
|
+
cbtn.disabled = true;
|
|
2054
|
+
if (cbtn.classList.contains('wf-crit-draft')) {
|
|
2055
|
+
critStatus.textContent = 'Drafting from the brief' + String.fromCharCode(8230);
|
|
2056
|
+
fetchJsonRetryOnce(base + '/evals/criteria/draft', { method: 'POST', headers: { 'content-type': 'application/json' }, body: '{}' }).then(function (r) {
|
|
2057
|
+
cbtn.disabled = false;
|
|
2058
|
+
if (!r.ok) { critStatus.textContent = r.body.error || 'Couldn' + String.fromCharCode(8217) + 't draft them.'; return; }
|
|
2059
|
+
rows.innerHTML = r.body.criteria.map(critRowHtml).join('');
|
|
2060
|
+
critStatus.textContent = 'Drafted ' + r.body.criteria.length + ': edit or remove any, then save.';
|
|
2061
|
+
});
|
|
2062
|
+
return;
|
|
2063
|
+
}
|
|
2064
|
+
var list = Array.prototype.map.call(rows.querySelectorAll('.wf-crit-row'), function (row) {
|
|
2065
|
+
return { id: row.dataset.critId || undefined, kind: row.querySelector('[data-crit-kind]').value, text: row.querySelector('[data-crit-text]').value, value: row.querySelector('[data-crit-value]').value };
|
|
2066
|
+
}).filter(function (c) { return c.text.trim() || c.value.trim(); });
|
|
2067
|
+
fetchJsonRetryOnce(base + '/evals/criteria', { method: 'PUT', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ criteria: list }) }).then(function (r) {
|
|
2068
|
+
cbtn.disabled = false;
|
|
2069
|
+
if (!r.ok) { critStatus.textContent = r.body.error || 'That didn' + String.fromCharCode(8217) + 't save.'; return; }
|
|
2070
|
+
workflowTabs[id] = 'evidence';
|
|
2071
|
+
loadWorkflowsSection(name);
|
|
2072
|
+
});
|
|
2073
|
+
});
|
|
2074
|
+
body.addEventListener('click', function (ev) {
|
|
1911
2075
|
var btn = ev.target.closest('.wf-save-case, .wf-case-remove, .wf-case-save, .wf-evals-run');
|
|
1912
2076
|
if (!btn) return;
|
|
1913
2077
|
var caseEl = btn.closest('[data-case]');
|
|
@@ -3322,7 +3486,7 @@ ${renderMarkdownScript}
|
|
|
3322
3486
|
return '<tr id="schedule-' + escapeHtml(t.task_id) + '">' +
|
|
3323
3487
|
'<td style="min-width:180px"><strong>' + escapeHtml(t.task_name || 'Untitled') + '</strong>' +
|
|
3324
3488
|
(t.workflow
|
|
3325
|
-
? '<div><span class="le-pill accent">Workflow</span> <a href="
|
|
3489
|
+
? '<div><span class="le-pill accent">Workflow</span> <a href="' + escapeHtml(workflowPageHref(currentName, t.workflow.id)) + '" class="schedule-workflow-link" title="Open the workflow">' + escapeHtml(t.workflow.title) + '</a></div>' +
|
|
3326
3490
|
'<div class="schedule-result hint">' + escapeHtml(t.workflow.description || t.workflow.start_message) +
|
|
3327
3491
|
(t.params ? '<br>' + Object.keys(t.params).map(function (k) { return escapeHtml(k) + ': ' + escapeHtml(t.params[k]); }).join(' ' + String.fromCharCode(183) + ' ') : '') + '</div>'
|
|
3328
3492
|
: t.workflow_missing
|
|
@@ -3399,17 +3563,6 @@ ${renderMarkdownScript}
|
|
|
3399
3563
|
function wireSchedulesHandlers(name) {
|
|
3400
3564
|
var content = schedulesContentEl();
|
|
3401
3565
|
if (!content) return;
|
|
3402
|
-
// A schedule's workflow opens its card on the Workflows tab.
|
|
3403
|
-
var workflowLinks = content.querySelectorAll('.schedule-workflow-link');
|
|
3404
|
-
for (var wl = 0; wl < workflowLinks.length; wl++) {
|
|
3405
|
-
workflowLinks[wl].addEventListener('click', function (ev) {
|
|
3406
|
-
if (ev.metaKey || ev.ctrlKey || ev.shiftKey) return;
|
|
3407
|
-
ev.preventDefault();
|
|
3408
|
-
pendingWorkflowFocus = ev.currentTarget.dataset.workflow;
|
|
3409
|
-
switchTab('workflows');
|
|
3410
|
-
focusWorkflowCard();
|
|
3411
|
-
});
|
|
3412
|
-
}
|
|
3413
3566
|
var actionBtns = content.querySelectorAll('.schedule-action');
|
|
3414
3567
|
for (var i = 0; i < actionBtns.length; i++) {
|
|
3415
3568
|
actionBtns[i].addEventListener('click', function (ev) {
|
|
@@ -5418,6 +5571,7 @@ ${renderMarkdownScript}
|
|
|
5418
5571
|
|
|
5419
5572
|
function renderDetail(cfg) {
|
|
5420
5573
|
currentCfg = cfg;
|
|
5574
|
+
detail.classList.toggle('wf-page-mode', Boolean(workflowPageId) && cfg.name === pageParams.get('agent'));
|
|
5421
5575
|
detail.innerHTML =
|
|
5422
5576
|
leShell.renderHead({
|
|
5423
5577
|
name: cfg.name,
|
|
@@ -5518,6 +5672,7 @@ ${renderMarkdownScript}
|
|
|
5518
5672
|
document.addEventListener('click', function (ev) {
|
|
5519
5673
|
var link = ev.target.closest('a[data-le-agent]');
|
|
5520
5674
|
if (!link || ev.button !== 0 || ev.metaKey || ev.ctrlKey || ev.shiftKey || ev.altKey) return;
|
|
5675
|
+
if (workflowPageId) return;
|
|
5521
5676
|
if (document.querySelector('dialog[open]')) return;
|
|
5522
5677
|
ev.preventDefault();
|
|
5523
5678
|
var name = link.dataset.leAgent;
|
package/dist/web/goals-page.js
CHANGED
|
@@ -538,7 +538,8 @@ ${consoleShellScript}
|
|
|
538
538
|
var waiting = (w.recentRuns || []).filter(function (x) { return x.status === 'awaiting_approval'; }).length + (w.schedules || []).filter(function (x) { return x.waiting; }).length;
|
|
539
539
|
var bits = [startsText(w), sc.runs ? sc.runs + ' run' + (sc.runs === 1 ? '' : 's') + (sc.failed ? ', ' + sc.failed + ' failed' : '') : 'no runs yet'];
|
|
540
540
|
var round = w.evals && w.evals.rounds && w.evals.rounds[0];
|
|
541
|
-
if (round &&
|
|
541
|
+
if (round && round.passRates) bits.push('evals: ' + round.allPassed + ' of ' + round.cases.length + ' passed every check');
|
|
542
|
+
else if (round && typeof round.average === 'number') bits.push('evals ' + round.average.toFixed(1) + ' / 5');
|
|
542
543
|
meta.innerHTML = esc(bits.join(' ' + String.fromCharCode(183) + ' ')) + (waiting ? ' <span class="gl-waiting">' + waiting + ' waiting for your decision</span>' : '');
|
|
543
544
|
if (waiting) {
|
|
544
545
|
var card = mine[j].closest('[data-wf]');
|
|
@@ -30,16 +30,39 @@ export declare function runFeedbackFrom(run: WorkflowRun, body: Record<string, u
|
|
|
30
30
|
export interface EvalCase {
|
|
31
31
|
id: string;
|
|
32
32
|
params: Record<string, string>;
|
|
33
|
-
/** The good result to compare against
|
|
33
|
+
/** The good result to compare against; empty for a case checked only
|
|
34
|
+
* on criteria that need none. */
|
|
34
35
|
reference: string;
|
|
35
36
|
/** The run it was saved from. */
|
|
36
37
|
fromRun?: string;
|
|
37
38
|
createdAt: string;
|
|
38
39
|
}
|
|
40
|
+
/** A yes or no check on every result. `judge`: a statement the judge
|
|
41
|
+
* says is true or false of the result. `reference`: the result matches
|
|
42
|
+
* the case's good result (cases without one skip it). `contains` /
|
|
43
|
+
* `not_contains`: `value` is or isn't in the result, ignoring case.
|
|
44
|
+
* `tool_called` / `tool_not_called`: the run did or didn't call tool
|
|
45
|
+
* `value` (in a test run, a call it would have made counts). */
|
|
46
|
+
export type CriterionKind = 'judge' | 'reference' | 'contains' | 'not_contains' | 'tool_called' | 'tool_not_called';
|
|
47
|
+
export interface EvalCriterion {
|
|
48
|
+
id: string;
|
|
49
|
+
text: string;
|
|
50
|
+
kind: CriterionKind;
|
|
51
|
+
value?: string;
|
|
52
|
+
}
|
|
53
|
+
export interface EvalCheck {
|
|
54
|
+
criterionId: string;
|
|
55
|
+
pass: boolean;
|
|
56
|
+
reason?: string;
|
|
57
|
+
}
|
|
39
58
|
export interface EvalCaseResult {
|
|
40
59
|
caseId: string;
|
|
41
60
|
result?: string;
|
|
42
61
|
error?: string;
|
|
62
|
+
/** The tools the test run called. */
|
|
63
|
+
tools?: string[];
|
|
64
|
+
checks?: EvalCheck[];
|
|
65
|
+
/** Rounds from before criteria: a 1-5 score. */
|
|
43
66
|
score?: number;
|
|
44
67
|
reason?: string;
|
|
45
68
|
}
|
|
@@ -49,11 +72,23 @@ export interface EvalRound {
|
|
|
49
72
|
model: string;
|
|
50
73
|
judge: string;
|
|
51
74
|
cases: EvalCaseResult[];
|
|
52
|
-
/**
|
|
75
|
+
/** The criteria the round checked, as they were. */
|
|
76
|
+
criteria?: EvalCriterion[];
|
|
77
|
+
/** Each criterion's pass rate: cases that passed it, of those it
|
|
78
|
+
* applied to. */
|
|
79
|
+
passRates?: {
|
|
80
|
+
criterionId: string;
|
|
81
|
+
passed: number;
|
|
82
|
+
total: number;
|
|
83
|
+
}[];
|
|
84
|
+
/** Cases that passed every check that applied to them. */
|
|
85
|
+
allPassed?: number;
|
|
86
|
+
/** Rounds from before criteria: the mean 1-5 score. */
|
|
53
87
|
average?: number;
|
|
54
88
|
}
|
|
55
89
|
export interface WorkflowEvals {
|
|
56
90
|
cases: EvalCase[];
|
|
91
|
+
criteria: EvalCriterion[];
|
|
57
92
|
rounds: EvalRound[];
|
|
58
93
|
/** Set while a round is running. */
|
|
59
94
|
running?: {
|
|
@@ -62,6 +97,8 @@ export interface WorkflowEvals {
|
|
|
62
97
|
total: number;
|
|
63
98
|
};
|
|
64
99
|
}
|
|
100
|
+
/** The check a workflow has before anyone sets criteria. */
|
|
101
|
+
export declare const REFERENCE_CRITERION: EvalCriterion;
|
|
65
102
|
export declare function readEvals(agentDir: string, workflowId: string): WorkflowEvals;
|
|
66
103
|
/** Adds a case: from a past run (its inputs, and its result unless a
|
|
67
104
|
* `reference` is given), or from `params` and a `reference`. */
|
|
@@ -72,16 +109,49 @@ export declare function addEvalCase(agentDir: string, workflowId: string, input:
|
|
|
72
109
|
}): EvalCase;
|
|
73
110
|
export declare function updateEvalCase(agentDir: string, workflowId: string, caseId: string, reference: unknown): void;
|
|
74
111
|
export declare function removeEvalCase(agentDir: string, workflowId: string, caseId: string): void;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
export declare function
|
|
112
|
+
/** Replaces the workflow's criteria. Each needs its words; a code check
|
|
113
|
+
* needs its value. */
|
|
114
|
+
export declare function setEvalCriteria(agentDir: string, workflowId: string, input: unknown): EvalCriterion[];
|
|
115
|
+
/** The criteria a round checks: the workflow's, or with none set,
|
|
116
|
+
* whether the result matches the good result. */
|
|
117
|
+
export declare function effectiveCriteria(evals: Pick<WorkflowEvals, 'criteria'>): EvalCriterion[];
|
|
118
|
+
/** The checks a program answers, on one result. */
|
|
119
|
+
export declare function codeCheck(criterion: EvalCriterion, run: {
|
|
120
|
+
result: string;
|
|
121
|
+
tools: string[];
|
|
122
|
+
}): EvalCheck | undefined;
|
|
123
|
+
export declare const EVAL_CRITERIA_PROMPT = "You check one result of an AI agent's workflow against a list of statements. For each statement, say whether it is true of the result.\n\nJudge substance, not style: the same facts and decisions in other words count. A test run doesn't make calls that need approval; a result saying it would have made one, or a call listed as attempted, counts as making it. When a statement can't be checked from what you're given, it is false, and say why.\n\nReply with JSON only: {\"checks\": [{\"id\": \"<the statement's id>\", \"pass\": true or false, \"reason\": \"<one sentence; required when false>\"}]}, one entry per statement.";
|
|
124
|
+
/** The judge's answers for one result, one call for all its statements. */
|
|
125
|
+
export declare function judgeCriteria(judge: ModelCall, input: {
|
|
78
126
|
instructions: string;
|
|
79
|
-
reference
|
|
127
|
+
reference?: string;
|
|
80
128
|
result: string;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
129
|
+
tools: string[];
|
|
130
|
+
criteria: EvalCriterion[];
|
|
131
|
+
}): Promise<EvalCheck[]>;
|
|
132
|
+
/** Every check on one case's result: the program's, then the judge's in
|
|
133
|
+
* one call. A case with no good result skips the reference check; a
|
|
134
|
+
* failed run fails every check that applies. */
|
|
135
|
+
export declare function checkCase(judge: ModelCall, input: {
|
|
136
|
+
instructions: string;
|
|
137
|
+
criteria: EvalCriterion[];
|
|
138
|
+
reference: string;
|
|
139
|
+
run: {
|
|
140
|
+
result: string;
|
|
141
|
+
tools: string[];
|
|
142
|
+
} | {
|
|
143
|
+
error: string;
|
|
144
|
+
};
|
|
145
|
+
}): Promise<EvalCheck[]>;
|
|
146
|
+
/** A round's pass rate per criterion, and the cases that passed all. */
|
|
147
|
+
export declare function roundSummary(criteria: EvalCriterion[], cases: EvalCaseResult[]): Pick<EvalRound, 'passRates' | 'allPassed'>;
|
|
148
|
+
export declare const DRAFT_CRITERIA_PROMPT = "You write the checks a workflow's results are tested against, from its brief: what the agent is told to do, its rules and policies.\n\nWrite three to six yes or no checks, the ones that matter most: a result failing one is a result a person would have to fix. Each is a short statement true of a good result (\"The reply gives the order's tracking number\", \"It doesn't promise a refund\"). Take them from the brief's rules and its job; never invent requirements it doesn't state.\n\nEach check has a kind:\n- \"judge\": a statement a reviewer decides by reading the result (most checks).\n- \"contains\" / \"not_contains\" with \"value\": an exact phrase that must or mustn't appear, only when the brief names the exact words (a sign-off, a banned phrase).\n- \"tool_called\" / \"tool_not_called\" with \"value\": a tool the run must or mustn't call, only when the brief says so and the tool's exact name is in the list given.\n\nReply with JSON only: {\"criteria\": [{\"text\": \"...\", \"kind\": \"judge\"}, {\"text\": \"...\", \"kind\": \"tool_called\", \"value\": \"<tool name>\"}]}";
|
|
149
|
+
/** Criteria drafted from a workflow's brief, for a person to edit before
|
|
150
|
+
* saving. */
|
|
151
|
+
export declare function draftCriteria(model: ModelCall, input: {
|
|
152
|
+
instructions: string;
|
|
153
|
+
tools: string[];
|
|
154
|
+
}): Promise<EvalCriterion[]>;
|
|
85
155
|
export interface EvalRunDeps {
|
|
86
156
|
agentDir: string;
|
|
87
157
|
workflowId: string;
|
|
@@ -90,8 +160,12 @@ export interface EvalRunDeps {
|
|
|
90
160
|
model: string;
|
|
91
161
|
judgeLabel: string;
|
|
92
162
|
judge: ModelCall;
|
|
93
|
-
/** One test run of the workflow with these inputs
|
|
94
|
-
|
|
163
|
+
/** One test run of the workflow with these inputs: its result, and
|
|
164
|
+
* the tools it called. */
|
|
165
|
+
runCase(params: Record<string, string>): Promise<{
|
|
166
|
+
result: string;
|
|
167
|
+
tools: string[];
|
|
168
|
+
}>;
|
|
95
169
|
}
|
|
96
170
|
/** Runs every case once and scores it, recording progress as it goes.
|
|
97
171
|
* Throws when a round is already running or there are no cases. */
|
|
@@ -6,14 +6,21 @@
|
|
|
6
6
|
// the feedback an app or person reported afterwards
|
|
7
7
|
// (POST /agents/:name/runs/:id/feedback): the text actually used,
|
|
8
8
|
// compared with the result (none, light or heavy edits), and a verdict.
|
|
9
|
-
// - Eval cases: real inputs
|
|
10
|
-
// beside its skill
|
|
11
|
-
//
|
|
9
|
+
// - Eval cases: real inputs, and when there is one a good result to
|
|
10
|
+
// compare against, kept beside its skill
|
|
11
|
+
// (agents/<name>/skills/<id>/evals.json). A case is usually saved from
|
|
12
|
+
// a past run, its result edited into the good one.
|
|
13
|
+
// - Criteria: the workflow's yes or no checks, in the same file. Some a
|
|
14
|
+
// program answers (a phrase is or isn't in the result, a tool was or
|
|
15
|
+
// wasn't called); the rest a judge model answers, one call per case
|
|
16
|
+
// for all of them, a model other than the workflow's own (models
|
|
17
|
+
// favour their own writing). With none set, the one check is whether
|
|
18
|
+
// the result matches the case's good result.
|
|
12
19
|
// - Eval results: each time the cases are run, as a test run (tools its
|
|
13
20
|
// rules don't allow aren't run, nobody is asked anything), every
|
|
14
|
-
// result is
|
|
15
|
-
//
|
|
16
|
-
// The latest 10 rounds are kept.
|
|
21
|
+
// result is checked against every criterion; a round reports each
|
|
22
|
+
// criterion's pass rate and how many cases passed them all. A crash
|
|
23
|
+
// fails every check. The latest 10 rounds are kept.
|
|
17
24
|
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
18
25
|
import { dirname, join } from 'node:path';
|
|
19
26
|
import { randomUUID } from 'node:crypto';
|
|
@@ -75,16 +82,20 @@ export function runFeedbackFrom(run, body) {
|
|
|
75
82
|
}
|
|
76
83
|
const MAX_CASES = 30;
|
|
77
84
|
const MAX_ROUNDS = 10;
|
|
85
|
+
const MAX_CRITERIA = 8;
|
|
86
|
+
const CRITERION_KINDS = ['judge', 'reference', 'contains', 'not_contains', 'tool_called', 'tool_not_called'];
|
|
87
|
+
/** The check a workflow has before anyone sets criteria. */
|
|
88
|
+
export const REFERENCE_CRITERION = { id: 'reference', text: 'Matches the good result: the same facts and decisions', kind: 'reference' };
|
|
78
89
|
function evalsFile(agentDir, workflowId) {
|
|
79
90
|
return join(agentDir, 'skills', workflowId, 'evals.json');
|
|
80
91
|
}
|
|
81
92
|
export function readEvals(agentDir, workflowId) {
|
|
82
93
|
try {
|
|
83
94
|
const raw = JSON.parse(readFileSync(evalsFile(agentDir, workflowId), 'utf8'));
|
|
84
|
-
return { cases: Array.isArray(raw.cases) ? raw.cases : [], rounds: Array.isArray(raw.rounds) ? raw.rounds : [], ...(raw.running ? { running: raw.running } : {}) };
|
|
95
|
+
return { cases: Array.isArray(raw.cases) ? raw.cases : [], criteria: Array.isArray(raw.criteria) ? raw.criteria : [], rounds: Array.isArray(raw.rounds) ? raw.rounds : [], ...(raw.running ? { running: raw.running } : {}) };
|
|
85
96
|
}
|
|
86
97
|
catch {
|
|
87
|
-
return { cases: [], rounds: [] };
|
|
98
|
+
return { cases: [], criteria: [], rounds: [] };
|
|
88
99
|
}
|
|
89
100
|
}
|
|
90
101
|
function writeEvals(agentDir, workflowId, evals) {
|
|
@@ -102,10 +113,10 @@ export function addEvalCase(agentDir, workflowId, input) {
|
|
|
102
113
|
const evals = readEvals(agentDir, workflowId);
|
|
103
114
|
if (evals.cases.length >= MAX_CASES)
|
|
104
115
|
throw new EvidenceError(`A workflow keeps up to ${MAX_CASES} eval cases; remove one first.`);
|
|
105
|
-
const reference = typeof input.reference === 'string' && input.reference.trim() ? input.reference.trim() : input.run?.result?.trim();
|
|
106
|
-
if (!reference)
|
|
107
|
-
throw new EvidenceError('A case needs a good result to compare against.');
|
|
116
|
+
const reference = (typeof input.reference === 'string' && input.reference.trim() ? input.reference.trim() : input.run?.result?.trim()) ?? '';
|
|
108
117
|
const params = input.run?.params ?? input.params ?? {};
|
|
118
|
+
if (!reference && !Object.keys(params).length)
|
|
119
|
+
throw new EvidenceError('A case needs its inputs, a good result, or both.');
|
|
109
120
|
if (input.run && evals.cases.some((c) => c.fromRun === input.run.run_id))
|
|
110
121
|
throw new EvidenceError('That run is already a case.');
|
|
111
122
|
const c = { id: randomUUID().slice(0, 8), params, reference: reference.slice(0, 50000), ...(input.run ? { fromRun: input.run.run_id } : {}), createdAt: new Date().toISOString() };
|
|
@@ -114,8 +125,8 @@ export function addEvalCase(agentDir, workflowId, input) {
|
|
|
114
125
|
}
|
|
115
126
|
export function updateEvalCase(agentDir, workflowId, caseId, reference) {
|
|
116
127
|
const evals = readEvals(agentDir, workflowId);
|
|
117
|
-
if (typeof reference !== 'string'
|
|
118
|
-
throw new EvidenceError('
|
|
128
|
+
if (typeof reference !== 'string')
|
|
129
|
+
throw new EvidenceError('reference must be text; send "" for none.');
|
|
119
130
|
if (!evals.cases.some((c) => c.id === caseId))
|
|
120
131
|
throw new EvidenceError('No such case.');
|
|
121
132
|
writeEvals(agentDir, workflowId, { ...evals, cases: evals.cases.map((c) => (c.id === caseId ? { ...c, reference: reference.trim().slice(0, 50000) } : c)) });
|
|
@@ -124,32 +135,158 @@ export function removeEvalCase(agentDir, workflowId, caseId) {
|
|
|
124
135
|
const evals = readEvals(agentDir, workflowId);
|
|
125
136
|
writeEvals(agentDir, workflowId, { ...evals, cases: evals.cases.filter((c) => c.id !== caseId) });
|
|
126
137
|
}
|
|
127
|
-
|
|
138
|
+
/** Replaces the workflow's criteria. Each needs its words; a code check
|
|
139
|
+
* needs its value. */
|
|
140
|
+
export function setEvalCriteria(agentDir, workflowId, input) {
|
|
141
|
+
if (!Array.isArray(input))
|
|
142
|
+
throw new EvidenceError('criteria must be a list.');
|
|
143
|
+
if (input.length > MAX_CRITERIA)
|
|
144
|
+
throw new EvidenceError(`Keep it to ${MAX_CRITERIA} criteria: the ones that matter most.`);
|
|
145
|
+
const used = new Set();
|
|
146
|
+
const criteria = input.map((raw, i) => {
|
|
147
|
+
const c = (raw ?? {});
|
|
148
|
+
const kind = CRITERION_KINDS.includes(c.kind) ? c.kind : 'judge';
|
|
149
|
+
const text = typeof c.text === 'string' ? c.text.trim().slice(0, 300) : '';
|
|
150
|
+
const value = typeof c.value === 'string' ? c.value.trim().slice(0, 300) : '';
|
|
151
|
+
if (!text)
|
|
152
|
+
throw new EvidenceError(`Criterion ${i + 1} needs its words.`);
|
|
153
|
+
if (kind !== 'judge' && kind !== 'reference' && !value)
|
|
154
|
+
throw new EvidenceError(`Criterion ${i + 1} needs ${kind.startsWith('tool') ? 'the tool' : 'the text to look for'}.`);
|
|
155
|
+
let id = typeof c.id === 'string' && /^[a-z0-9-]{1,40}$/.test(c.id) ? c.id : randomUUID().slice(0, 8);
|
|
156
|
+
if (used.has(id))
|
|
157
|
+
id = randomUUID().slice(0, 8);
|
|
158
|
+
used.add(id);
|
|
159
|
+
return { id, text, kind, ...(value && kind !== 'judge' && kind !== 'reference' ? { value } : {}) };
|
|
160
|
+
});
|
|
161
|
+
const evals = readEvals(agentDir, workflowId);
|
|
162
|
+
writeEvals(agentDir, workflowId, { ...evals, criteria });
|
|
163
|
+
return criteria;
|
|
164
|
+
}
|
|
165
|
+
/** The criteria a round checks: the workflow's, or with none set,
|
|
166
|
+
* whether the result matches the good result. */
|
|
167
|
+
export function effectiveCriteria(evals) {
|
|
168
|
+
return evals.criteria.length ? evals.criteria : [REFERENCE_CRITERION];
|
|
169
|
+
}
|
|
170
|
+
/** The checks a program answers, on one result. */
|
|
171
|
+
export function codeCheck(criterion, run) {
|
|
172
|
+
const value = (criterion.value ?? '').toLowerCase();
|
|
173
|
+
const text = run.result.toLowerCase();
|
|
174
|
+
switch (criterion.kind) {
|
|
175
|
+
case 'contains': return { criterionId: criterion.id, pass: text.includes(value), ...(text.includes(value) ? {} : { reason: `"${criterion.value}" isn't in the result.` }) };
|
|
176
|
+
case 'not_contains': return { criterionId: criterion.id, pass: !text.includes(value), ...(text.includes(value) ? { reason: `"${criterion.value}" is in the result.` } : {}) };
|
|
177
|
+
case 'tool_called': {
|
|
178
|
+
const called = run.tools.some((t) => t.toLowerCase() === value);
|
|
179
|
+
return { criterionId: criterion.id, pass: called, ...(called ? {} : { reason: `It didn't call ${criterion.value}.` }) };
|
|
180
|
+
}
|
|
181
|
+
case 'tool_not_called': {
|
|
182
|
+
const called = run.tools.some((t) => t.toLowerCase() === value);
|
|
183
|
+
return { criterionId: criterion.id, pass: !called, ...(called ? { reason: `It called ${criterion.value}.` } : {}) };
|
|
184
|
+
}
|
|
185
|
+
default: return undefined;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
export const EVAL_CRITERIA_PROMPT = `You check one result of an AI agent's workflow against a list of statements. For each statement, say whether it is true of the result.
|
|
189
|
+
|
|
190
|
+
Judge substance, not style: the same facts and decisions in other words count. A test run doesn't make calls that need approval; a result saying it would have made one, or a call listed as attempted, counts as making it. When a statement can't be checked from what you're given, it is false, and say why.
|
|
191
|
+
|
|
192
|
+
Reply with JSON only: {"checks": [{"id": "<the statement's id>", "pass": true or false, "reason": "<one sentence; required when false>"}]}, one entry per statement.`;
|
|
193
|
+
/** The judge's answers for one result, one call for all its statements. */
|
|
194
|
+
export async function judgeCriteria(judge, input) {
|
|
195
|
+
const statements = input.criteria.map((c) => `- ${c.id}: ${c.kind === 'reference' ? 'The result has the same facts and decisions as the good result (wording may differ).' : c.text}`).join('\n');
|
|
196
|
+
const content = `The workflow's instructions:\n<instructions>\n${input.instructions.slice(0, 12000)}\n</instructions>\n\n` +
|
|
197
|
+
(input.reference ? `The good result for these inputs:\n<good_result>\n${input.reference.slice(0, 12000)}\n</good_result>\n\n` : '') +
|
|
198
|
+
`Tools the run called: ${input.tools.length ? input.tools.join(', ') : 'none'}\n\nThe result to check:\n<result>\n${input.result.slice(0, 12000)}\n</result>\n\nThe statements:\n${statements}`;
|
|
199
|
+
const response = await judge([{ role: 'user', content }], EVAL_CRITERIA_PROMPT, []);
|
|
200
|
+
const text = response.content.filter((b) => b.type === 'text').map((b) => b.text ?? '').join('');
|
|
201
|
+
const match = /\{[\s\S]*\}/.exec(text);
|
|
202
|
+
let parsed = {};
|
|
203
|
+
try {
|
|
204
|
+
parsed = JSON.parse(match?.[0] ?? '');
|
|
205
|
+
}
|
|
206
|
+
catch { }
|
|
207
|
+
const answers = new Map();
|
|
208
|
+
for (const a of Array.isArray(parsed.checks) ? parsed.checks : []) {
|
|
209
|
+
const x = (a ?? {});
|
|
210
|
+
if (typeof x.id === 'string' && typeof x.pass === 'boolean')
|
|
211
|
+
answers.set(x.id, { pass: x.pass, reason: typeof x.reason === 'string' ? x.reason.slice(0, 400) : '' });
|
|
212
|
+
}
|
|
213
|
+
if (!answers.size)
|
|
214
|
+
throw new Error('The judge did not answer the checks.');
|
|
215
|
+
return input.criteria.map((c) => {
|
|
216
|
+
const a = answers.get(c.id);
|
|
217
|
+
return a ? { criterionId: c.id, pass: a.pass, ...(a.reason && !a.pass ? { reason: a.reason } : {}) } : { criterionId: c.id, pass: false, reason: 'The judge gave no answer for this check.' };
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
/** Every check on one case's result: the program's, then the judge's in
|
|
221
|
+
* one call. A case with no good result skips the reference check; a
|
|
222
|
+
* failed run fails every check that applies. */
|
|
223
|
+
export async function checkCase(judge, input) {
|
|
224
|
+
const applies = input.criteria.filter((c) => c.kind !== 'reference' || input.reference.trim());
|
|
225
|
+
if ('error' in input.run) {
|
|
226
|
+
const error = input.run.error;
|
|
227
|
+
return applies.map((c) => ({ criterionId: c.id, pass: false, reason: `The run failed: ${error.slice(0, 200)}` }));
|
|
228
|
+
}
|
|
229
|
+
const run = input.run;
|
|
230
|
+
const coded = new Map(applies.flatMap((c) => { const r = codeCheck(c, run); return r ? [[c.id, r]] : []; }));
|
|
231
|
+
const forJudge = applies.filter((c) => !coded.has(c.id));
|
|
232
|
+
let judged = new Map();
|
|
233
|
+
if (forJudge.length) {
|
|
234
|
+
try {
|
|
235
|
+
judged = new Map((await judgeCriteria(judge, { instructions: input.instructions, reference: input.reference || undefined, result: run.result, tools: run.tools, criteria: forJudge })).map((c) => [c.criterionId, c]));
|
|
236
|
+
}
|
|
237
|
+
catch (err) {
|
|
238
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
239
|
+
judged = new Map(forJudge.map((c) => [c.id, { criterionId: c.id, pass: false, reason }]));
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return applies.map((c) => coded.get(c.id) ?? judged.get(c.id));
|
|
243
|
+
}
|
|
244
|
+
/** A round's pass rate per criterion, and the cases that passed all. */
|
|
245
|
+
export function roundSummary(criteria, cases) {
|
|
246
|
+
const passRates = criteria.map((c) => {
|
|
247
|
+
const checks = cases.flatMap((r) => (r.checks ?? []).filter((x) => x.criterionId === c.id));
|
|
248
|
+
return { criterionId: c.id, passed: checks.filter((x) => x.pass).length, total: checks.length };
|
|
249
|
+
});
|
|
250
|
+
return { passRates, allPassed: cases.filter((r) => (r.checks ?? []).length && r.checks.every((x) => x.pass)).length };
|
|
251
|
+
}
|
|
252
|
+
export const DRAFT_CRITERIA_PROMPT = `You write the checks a workflow's results are tested against, from its brief: what the agent is told to do, its rules and policies.
|
|
128
253
|
|
|
129
|
-
|
|
130
|
-
5 = as good as the good result or better: same facts and decisions, nothing wrong or missing that matters.
|
|
131
|
-
4 = right in substance, small gaps or wording differences that wouldn't matter to the person using it.
|
|
132
|
-
3 = usable after edits: a fact, step or decision missing or off, but nothing harmful.
|
|
133
|
-
2 = needs a rewrite: wrong in a way that matters (a wrong fact, a wrong decision, a promise it shouldn't make).
|
|
134
|
-
1 = wrong or harmful, or no real result.
|
|
254
|
+
Write three to six yes or no checks, the ones that matter most: a result failing one is a result a person would have to fix. Each is a short statement true of a good result ("The reply gives the order's tracking number", "It doesn't promise a refund"). Take them from the brief's rules and its job; never invent requirements it doesn't state.
|
|
135
255
|
|
|
136
|
-
|
|
256
|
+
Each check has a kind:
|
|
257
|
+
- "judge": a statement a reviewer decides by reading the result (most checks).
|
|
258
|
+
- "contains" / "not_contains" with "value": an exact phrase that must or mustn't appear, only when the brief names the exact words (a sign-off, a banned phrase).
|
|
259
|
+
- "tool_called" / "tool_not_called" with "value": a tool the run must or mustn't call, only when the brief says so and the tool's exact name is in the list given.
|
|
137
260
|
|
|
138
|
-
Reply with JSON only: {"
|
|
139
|
-
/**
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
const
|
|
261
|
+
Reply with JSON only: {"criteria": [{"text": "...", "kind": "judge"}, {"text": "...", "kind": "tool_called", "value": "<tool name>"}]}`;
|
|
262
|
+
/** Criteria drafted from a workflow's brief, for a person to edit before
|
|
263
|
+
* saving. */
|
|
264
|
+
export async function draftCriteria(model, input) {
|
|
265
|
+
const content = `The workflow's brief:\n<brief>\n${input.instructions.slice(0, 16000)}\n</brief>\n\nIts tools: ${input.tools.length ? input.tools.join(', ') : 'none'}`;
|
|
266
|
+
const response = await model([{ role: 'user', content }], DRAFT_CRITERIA_PROMPT, []);
|
|
143
267
|
const text = response.content.filter((b) => b.type === 'text').map((b) => b.text ?? '').join('');
|
|
144
268
|
const match = /\{[\s\S]*\}/.exec(text);
|
|
269
|
+
let parsed = {};
|
|
145
270
|
try {
|
|
146
|
-
|
|
147
|
-
const score = Math.round(Number(parsed.score));
|
|
148
|
-
if (score >= 1 && score <= 5)
|
|
149
|
-
return { score, reason: typeof parsed.reason === 'string' ? parsed.reason.slice(0, 600) : '' };
|
|
271
|
+
parsed = JSON.parse(match?.[0] ?? '');
|
|
150
272
|
}
|
|
151
273
|
catch { }
|
|
152
|
-
|
|
274
|
+
const tools = new Set(input.tools.map((t) => t.toLowerCase()));
|
|
275
|
+
const drafted = (Array.isArray(parsed.criteria) ? parsed.criteria : []).flatMap((raw) => {
|
|
276
|
+
const c = (raw ?? {});
|
|
277
|
+
const text = typeof c.text === 'string' ? c.text.trim().slice(0, 300) : '';
|
|
278
|
+
let kind = CRITERION_KINDS.includes(c.kind) && c.kind !== 'reference' ? c.kind : 'judge';
|
|
279
|
+
const value = typeof c.value === 'string' ? c.value.trim().slice(0, 300) : '';
|
|
280
|
+
// A tool it can't call, or a phrase with no words, is judged instead.
|
|
281
|
+
if ((kind === 'tool_called' || kind === 'tool_not_called') && !tools.has(value.toLowerCase()))
|
|
282
|
+
kind = 'judge';
|
|
283
|
+
if ((kind === 'contains' || kind === 'not_contains') && !value)
|
|
284
|
+
kind = 'judge';
|
|
285
|
+
return text ? [{ id: randomUUID().slice(0, 8), text, kind, ...(kind !== 'judge' ? { value } : {}) }] : [];
|
|
286
|
+
});
|
|
287
|
+
if (!drafted.length)
|
|
288
|
+
throw new EvidenceError('No checks could be drafted from this brief: add them by hand.');
|
|
289
|
+
return drafted.slice(0, MAX_CRITERIA);
|
|
153
290
|
}
|
|
154
291
|
/** Runs every case once and scores it, recording progress as it goes.
|
|
155
292
|
* Throws when a round is already running or there are no cases. */
|
|
@@ -163,32 +300,33 @@ export function startEvalRound(deps) {
|
|
|
163
300
|
const cases = evals.cases;
|
|
164
301
|
const startedAt = new Date().toISOString();
|
|
165
302
|
writeEvals(deps.agentDir, deps.workflowId, { ...evals, running: { startedAt, done: 0, total: cases.length } });
|
|
303
|
+
const criteria = effectiveCriteria(evals);
|
|
166
304
|
return (async () => {
|
|
167
305
|
const results = [];
|
|
168
306
|
for (const c of cases) {
|
|
307
|
+
let run;
|
|
169
308
|
try {
|
|
170
|
-
|
|
171
|
-
try {
|
|
172
|
-
const verdict = await judgeEvalResult(deps.judge, { instructions: deps.instructions, reference: c.reference, result });
|
|
173
|
-
results.push({ caseId: c.id, result: result.slice(0, 20000), ...verdict });
|
|
174
|
-
}
|
|
175
|
-
catch (err) {
|
|
176
|
-
results.push({ caseId: c.id, result: result.slice(0, 20000), error: err instanceof Error ? err.message : String(err) });
|
|
177
|
-
}
|
|
309
|
+
run = await deps.runCase(c.params);
|
|
178
310
|
}
|
|
179
311
|
catch (err) {
|
|
180
|
-
|
|
312
|
+
run = { error: err instanceof Error ? err.message : String(err) };
|
|
181
313
|
}
|
|
314
|
+
const checks = await checkCase(deps.judge, { instructions: deps.instructions, criteria, reference: c.reference ?? '', run });
|
|
315
|
+
results.push({
|
|
316
|
+
caseId: c.id,
|
|
317
|
+
...('error' in run ? { error: run.error } : { result: run.result.slice(0, 20000), tools: [...new Set(run.tools)] }),
|
|
318
|
+
checks,
|
|
319
|
+
});
|
|
182
320
|
const now = readEvals(deps.agentDir, deps.workflowId);
|
|
183
321
|
writeEvals(deps.agentDir, deps.workflowId, { ...now, running: { startedAt, done: results.length, total: cases.length } });
|
|
184
322
|
}
|
|
185
|
-
const scored = results.filter((r) => typeof r.score === 'number');
|
|
186
323
|
const round = {
|
|
187
324
|
at: startedAt,
|
|
188
325
|
model: deps.model,
|
|
189
326
|
judge: deps.judgeLabel,
|
|
190
327
|
cases: results,
|
|
191
|
-
|
|
328
|
+
criteria,
|
|
329
|
+
...roundSummary(criteria, results),
|
|
192
330
|
};
|
|
193
331
|
const now = readEvals(deps.agentDir, deps.workflowId);
|
|
194
332
|
const { running: _done, ...rest } = now;
|