@ouro.bot/cli 0.1.0-alpha.1442 → 0.1.0-alpha.1444
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/changelog.json +22 -2
- package/deploy/unraid/sanctuary.ouro/bundle-meta.json +1 -1
- package/deploy/unraid/sanctuary.xml +1 -1
- package/dist/eval/interview-entry.js +106 -0
- package/dist/eval/interview-grade-entry.js +35 -0
- package/dist/eval/interviews/final.js +133 -0
- package/dist/eval/interviews/grader.js +179 -0
- package/dist/eval/interviews/runner.js +292 -0
- package/dist/heart/daemon/cli-commands/entry-points.js +4 -0
- package/dist/senses/voice/realtime-utterances.js +158 -0
- package/dist/senses/voice/twilio-phone.js +121 -31
- package/dist/senses/voice/utterances.js +47 -7
- package/npm-shrinkwrap.json +2 -2
- package/package.json +2 -1
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KNOWN_ARMS = exports.X_KIT = exports.NO_BOOKS = exports.NO_OPERATION = exports.FIDELITY = void 0;
|
|
4
|
+
exports.canonicalX = canonicalX;
|
|
5
|
+
exports.summarizeSessions = summarizeSessions;
|
|
6
|
+
exports.runInterviews = runInterviews;
|
|
7
|
+
exports.parseInterviewArgs = parseInterviewArgs;
|
|
8
|
+
const runtime_1 = require("../../nerves/runtime");
|
|
9
|
+
const assertions_1 = require("../assertions");
|
|
10
|
+
const budget_1 = require("../budget");
|
|
11
|
+
const report_1 = require("../report");
|
|
12
|
+
const allocation_1 = require("./allocation");
|
|
13
|
+
const final_1 = require("./final");
|
|
14
|
+
const arms_1 = require("./guest/arms");
|
|
15
|
+
const loop_1 = require("./guest/loop");
|
|
16
|
+
const operations_1 = require("./guest/operations");
|
|
17
|
+
const latch_1 = require("./latch");
|
|
18
|
+
const protocol_1 = require("./protocol");
|
|
19
|
+
/** What is recorded about each arm before any session: where it differs from the product it stands for. */
|
|
20
|
+
exports.FIDELITY = {
|
|
21
|
+
"X:ouro": [
|
|
22
|
+
"ax-command and its MCP handler are Ouro AX v1.3.445's files unchanged; only their `.ts` import suffixes are dropped so the harness compiles them",
|
|
23
|
+
"the tools are called in-process through the handler's tools/call, not over an MCP transport",
|
|
24
|
+
"ax-command types positional arguments as strings, so this arm asks for a book's id as a string (\"187\") where mcp-plain asks for an integer; its tool descriptions carry the kit's own effect sentence",
|
|
25
|
+
"only the kit's MCP-tool side reaches the model: its parser, `help --json`, `--json` output and exit codes are the same code behind each tool, but the model never sees the command line itself",
|
|
26
|
+
"the kit cuts a tool answer at its own 20,000-character limit; no answer in the books cases comes near it",
|
|
27
|
+
],
|
|
28
|
+
"X:mcp-plain": ["hand-written for this study: the same operations, inputs and JSON results as the other arms, no kit"],
|
|
29
|
+
"X:cli-shell": [
|
|
30
|
+
"the shell runs one `books` command per call, with quoting but no other programs, pipes, redirection or chaining",
|
|
31
|
+
"its human-readable output is generated from the same JSON answer the other arms return",
|
|
32
|
+
],
|
|
33
|
+
"X:all": [
|
|
34
|
+
"every arm runs the eval's books stub in the bundle, against the fake household; paths in answers are shown relative to the books folder",
|
|
35
|
+
"the persona is the Butler's psyche files from the seed bundle with the household's names filled in; the bundle's skills are left out, since they describe the shell command line",
|
|
36
|
+
"the debrief keeps the arm's tools; the job is scored on the household after the debrief, and debrief tool calls are counted",
|
|
37
|
+
"for scoring, each arm's calls are written as the books command line they ran, so the case's trace assertions read every arm the same way; a call the interface refused before any books operation ran (a bad argument, an unknown tool, a help request) is written as `no-operation` in every arm",
|
|
38
|
+
"the loop starts a failed call's answer with `Error: ` in every arm, in place of MCP's isError flag",
|
|
39
|
+
"on the Copilot Responses path the provider's body is rebuilt from the scanned messages before every call, so reasoning items from an earlier call are not sent back",
|
|
40
|
+
],
|
|
41
|
+
};
|
|
42
|
+
/** What a call the interface refused, before any books operation ran, is written as for scoring, in every arm. */
|
|
43
|
+
exports.NO_OPERATION = "no-operation";
|
|
44
|
+
/** The books core for reading calls back on the host, where no operation ever runs. */
|
|
45
|
+
const NO_BOOKS = async () => { throw new Error("the host only reads calls back; it runs no books operation"); };
|
|
46
|
+
exports.NO_BOOKS = NO_BOOKS;
|
|
47
|
+
/** X's calls as the books command lines they ran, so `trace.*` assertions read every arm the same way. */
|
|
48
|
+
function canonicalX(arm, obs) {
|
|
49
|
+
const tools = (0, arms_1.buildArm)(arm, exports.NO_BOOKS);
|
|
50
|
+
return {
|
|
51
|
+
...obs,
|
|
52
|
+
timeline: obs.timeline.map((entry) => {
|
|
53
|
+
if (entry.kind !== "call")
|
|
54
|
+
return entry;
|
|
55
|
+
const ran = tools.operationOf(entry.name, entry.args);
|
|
56
|
+
return ran ? { ...entry, name: "shell", args: JSON.stringify({ command: (0, operations_1.commandLine)((0, operations_1.argvOf)(ran.op, ran.input)) }) } : { ...entry, name: exports.NO_OPERATION };
|
|
57
|
+
}),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
exports.X_KIT = {
|
|
61
|
+
guest: ({ session, arm, case: c, debrief }) => {
|
|
62
|
+
const last = c.prefix[c.prefix.length - 1];
|
|
63
|
+
return {
|
|
64
|
+
entry: "interview-guest-entry.js",
|
|
65
|
+
turn: { product: session.product, arm: arm.arm, labelLine: (0, protocol_1.labelLine)(session.product, arm.label), prefix: c.prefix.slice(0, -1), userText: last.content, followUps: [debrief] },
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
canonical: canonicalX,
|
|
69
|
+
};
|
|
70
|
+
const ZERO = { premium: 0, credits: 0 };
|
|
71
|
+
/** The brand words found, each once, in lower case. */
|
|
72
|
+
const named = (hits) => [...new Set(hits.map((hit) => hit.toLowerCase()))].join(", ");
|
|
73
|
+
const providerFailure = (outcome) => /^(provider-error|sandbox-error|trace-mismatch)/.test(outcome);
|
|
74
|
+
function armRecord(input) {
|
|
75
|
+
const { gaps: _gaps, followUps, ...raw } = input.obs;
|
|
76
|
+
const observation = input.kit.canonical(input.arm.arm, raw);
|
|
77
|
+
const graded = (0, assertions_1.evaluate)(input.c, observation);
|
|
78
|
+
const refused = input.job.refused();
|
|
79
|
+
const verdict = refused ? { passed: false, reason: `refused: ${refused}` } : (0, report_1.gradeRun)(observation, graded);
|
|
80
|
+
const debrief = followUps?.[0];
|
|
81
|
+
const note = debrief && debrief.outcome === "settled" ? debrief.finalReply : "";
|
|
82
|
+
return {
|
|
83
|
+
label: input.arm.label, arm: input.arm.arm, ...verdict, outcome: raw.outcome, checks: graded.checks, note, rating: (0, protocol_1.ratingOf)(note),
|
|
84
|
+
debriefOutcome: debrief?.outcome ?? null, debriefToolCalls: debrief?.toolCalls ?? 0,
|
|
85
|
+
jobCalls: input.job.calls(), debriefCalls: input.debrief.calls(), observation,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/** Runs one session. Returns its record; `stop` when the study must stop (402, 429 or a cap). */
|
|
89
|
+
async function runSession(input) {
|
|
90
|
+
const { session, latch } = input;
|
|
91
|
+
const record = {
|
|
92
|
+
id: session.id, product: session.product, model: session.model, job: session.job, pilot: session.pilot,
|
|
93
|
+
labels: Object.fromEntries(session.arms.map((arm) => [arm.label, arm.arm])), status: "complete", ended: null, arms: [], final: null,
|
|
94
|
+
ouroFirst: false, voidedBy: null, calls: [], spent: ZERO,
|
|
95
|
+
};
|
|
96
|
+
const c = input.cases.get(session.job);
|
|
97
|
+
const guard = (gateFor) => (0, latch_1.guardedRuntime)({
|
|
98
|
+
inner: input.target.runtime, latch, ledger: input.ledger, pricing: input.pricing, gateFor,
|
|
99
|
+
log: (entry) => input.log(JSON.stringify({ session: session.id, ...entry })),
|
|
100
|
+
});
|
|
101
|
+
const end = (status, why) => {
|
|
102
|
+
record.status = status;
|
|
103
|
+
record.ended = why;
|
|
104
|
+
};
|
|
105
|
+
for (const arm of session.arms) {
|
|
106
|
+
const debrief = (0, protocol_1.debriefQuestion)(session.product, arm.label);
|
|
107
|
+
const job = latch.gate("job");
|
|
108
|
+
const debriefGate = latch.gate("debrief");
|
|
109
|
+
const host = guard((request) => request.messages.some((m) => m.role === "user" && m.content === debrief) ? debriefGate : job);
|
|
110
|
+
let obs;
|
|
111
|
+
try {
|
|
112
|
+
obs = await input.runCase({ case: c, host, budget: { take: () => true }, guest: input.kit.guest({ session, arm, case: c, debrief }) });
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
end("crashed", `${arm.label}: ${(0, loop_1.messageOf)(error)}`);
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
const armResult = armRecord({ arm, c, obs, kit: input.kit, job, debrief: debriefGate });
|
|
119
|
+
record.arms.push(armResult);
|
|
120
|
+
if (latch.voided()) {
|
|
121
|
+
end("void", `${arm.label}: a request named ${named(latch.voided())}`);
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
if (input.ledger.stopped()) {
|
|
125
|
+
end("crashed", `${arm.label}: ${input.ledger.stopped()}`);
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
const refusedOnly = job.refused() !== null || debriefGate.refused() !== null;
|
|
129
|
+
const failed = [obs.outcome, armResult.debriefOutcome ?? ""].find((outcome) => providerFailure(outcome));
|
|
130
|
+
if (failed && !refusedOnly) {
|
|
131
|
+
end("crashed", `${arm.label}: ${failed}`);
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (record.status === "complete") {
|
|
136
|
+
const notes = record.arms.map((arm) => ({ label: arm.label, answer: arm.note }));
|
|
137
|
+
const choose = latch.gate("choose");
|
|
138
|
+
const identify = latch.gate("identify");
|
|
139
|
+
const host = guard((request) => request.messages.some((m) => m.role === "user" && m.content === protocol_1.IDENTIFY_QUESTION) ? identify : choose);
|
|
140
|
+
record.final = await (0, final_1.runFinalConversation)({ runtime: host, product: session.product, notes, allowNudge: () => choose.allowOneMore() });
|
|
141
|
+
if (latch.voided())
|
|
142
|
+
end("void", `final: a request named ${named(latch.voided())}`);
|
|
143
|
+
else if (input.ledger.stopped())
|
|
144
|
+
end("crashed", `final: ${input.ledger.stopped()}`);
|
|
145
|
+
else if (record.final.ended && choose.refused() === null && identify.refused() === null && !record.final.choice)
|
|
146
|
+
end("crashed", `final: ${record.final.ended}`);
|
|
147
|
+
}
|
|
148
|
+
const ouroLabel = session.arms.find((arm) => arm.arm === "ouro").label;
|
|
149
|
+
record.ouroFirst = record.status === "complete" && record.final?.choice?.first === ouroLabel;
|
|
150
|
+
record.voidedBy = latch.voided();
|
|
151
|
+
record.calls = latch.calls();
|
|
152
|
+
record.spent = latch.release();
|
|
153
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.interview_session_end", message: "finished an interview session", meta: { session: session.id, status: record.status, calls: record.calls.length } });
|
|
154
|
+
return record;
|
|
155
|
+
}
|
|
156
|
+
/** The counts-only summary: no trace text, no notes, no reasons. */
|
|
157
|
+
function summarizeSessions(records, spent, stopped) {
|
|
158
|
+
const lines = records.map((r) => {
|
|
159
|
+
const passed = r.arms.filter((arm) => arm.passed).length;
|
|
160
|
+
const usage = r.calls.reduce((sum, call) => ({ input: sum.input + (call.usage?.input_tokens ?? 0), output: sum.output + (call.usage?.output_tokens ?? 0) }), { input: 0, output: 0 });
|
|
161
|
+
return `${r.id} ${r.status} ouro-first=${r.ouroFirst ? "yes" : "no"} jobs-passed=${passed}/${r.arms.length} calls=${r.calls.length} tokens-in=${usage.input} tokens-out=${usage.output} credits=${r.spent.credits.toFixed(3)} premium=${r.spent.premium}`;
|
|
162
|
+
});
|
|
163
|
+
return [...lines, `spent: ${spent.credits.toFixed(3)} credits, ${spent.premium} premium requests${stopped ? `; stopped: ${stopped}` : ""}`].join("\n");
|
|
164
|
+
}
|
|
165
|
+
async function runInterviews(args, deps) {
|
|
166
|
+
const all = (0, allocation_1.readAllocation)(deps.readText(args.preregistration), deps.allocationSha256);
|
|
167
|
+
const design = args.reduced ? (0, allocation_1.reducedDesign)(all) : all;
|
|
168
|
+
const unknown = args.sessions.find((id) => !all.some((session) => session.id === id));
|
|
169
|
+
if (unknown)
|
|
170
|
+
throw new Error(`no session ${unknown} in Appendix B`);
|
|
171
|
+
const outside = args.sessions.find((id) => !design.some((session) => session.id === id));
|
|
172
|
+
if (outside)
|
|
173
|
+
throw new Error(`session ${outside} is not in the reduced design`);
|
|
174
|
+
const chosen = args.sessions.length > 0 ? design.filter((session) => args.sessions.includes(session.id)) : design;
|
|
175
|
+
const rerun = chosen.find((session) => deps.started.has(session.id));
|
|
176
|
+
if (rerun)
|
|
177
|
+
throw new Error(`session ${rerun.id} has already started once; a session is never rerun`);
|
|
178
|
+
const missingKit = chosen.find((session) => !deps.kits[session.product]);
|
|
179
|
+
if (missingKit)
|
|
180
|
+
throw new Error(`session ${missingKit.id} is product ${missingKit.product}, which has no runner kit yet`);
|
|
181
|
+
const cases = new Map(deps.loadCases(args.cases).map((c) => [c.id, c]));
|
|
182
|
+
const missingCase = chosen.find((session) => !cases.has(session.job));
|
|
183
|
+
if (missingCase)
|
|
184
|
+
throw new Error(`session ${missingCase.id} needs case ${missingCase.job}, which is not in ${args.cases}`);
|
|
185
|
+
for (const file of [args.output, args.requestLog])
|
|
186
|
+
if (deps.outputExists(file))
|
|
187
|
+
throw new Error(`${file} already exists; name a new file`);
|
|
188
|
+
if (args.budgetCredits !== undefined && (args.priceIn === undefined || args.priceOut === undefined || args.reserveCreditsPerCall === undefined)) {
|
|
189
|
+
throw new Error("a credits cap needs --price-in, --price-out and --reserve-credits-per-call (credits per million tokens, and per call)");
|
|
190
|
+
}
|
|
191
|
+
if (args.budgetCredits !== undefined && !(args.reserveCreditsPerCall > 0))
|
|
192
|
+
throw new Error("--reserve-credits-per-call must be more than 0 with a credits cap, or the cap reserves nothing");
|
|
193
|
+
const target = await deps.resolveTarget(args.target, { agent: args.credentialsAgent });
|
|
194
|
+
const before = await target.quota();
|
|
195
|
+
if (args.budgetCredits === undefined && (target.account === null || before.tokenBased !== false)) {
|
|
196
|
+
throw new Error(`${args.target} is billed by the token (or not known not to be); pass --budget-credits with --price-in, --price-out and --reserve-credits-per-call`);
|
|
197
|
+
}
|
|
198
|
+
const ledger = (0, budget_1.createBudgetLedger)({ premium: args.budgetPremium, ...(args.budgetCredits !== undefined ? { credits: args.budgetCredits } : {}) });
|
|
199
|
+
const pricing = { premiumPerCall: target.unitCost, creditsPerMillionInput: args.priceIn ?? 0, creditsPerMillionOutput: args.priceOut ?? 0 };
|
|
200
|
+
let perCallCredits = args.reserveCreditsPerCall ?? 0;
|
|
201
|
+
const interviewLatch = (0, latch_1.createInterviewLatch)({ ledger, pricing, perCall: () => ({ premium: target.unitCost, credits: perCallCredits }) });
|
|
202
|
+
const log = deps.openLog(args.requestLog);
|
|
203
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.interview_run_start", message: "starting blind-interview sessions", meta: { sessions: chosen.length, target: args.target } });
|
|
204
|
+
const records = [];
|
|
205
|
+
let stopped = null;
|
|
206
|
+
const writeReport = () => {
|
|
207
|
+
const totals = ledger.totals();
|
|
208
|
+
deps.writeReport(args.output, {
|
|
209
|
+
schemaVersion: 1, kind: "blind-interviews", target: args.target, harnessRef: args.harnessRef, reduced: args.reduced, account: target.account,
|
|
210
|
+
premiumMultiplier: target.unitCost, caps: totals.caps, spent: totals.spent, calls: totals.calls, stopped, quota: { before, after: after ?? before },
|
|
211
|
+
fidelity: exports.FIDELITY, pricing, sessions: records,
|
|
212
|
+
});
|
|
213
|
+
};
|
|
214
|
+
let after = null;
|
|
215
|
+
try {
|
|
216
|
+
for (const session of chosen) {
|
|
217
|
+
const notRun = (why) => ({
|
|
218
|
+
id: session.id, product: session.product, model: session.model, job: session.job, pilot: session.pilot,
|
|
219
|
+
labels: Object.fromEntries(session.arms.map((arm) => [arm.label, arm.arm])), status: "not-run", ended: why, arms: [], final: null,
|
|
220
|
+
ouroFirst: false, voidedBy: null, calls: [], spent: ZERO,
|
|
221
|
+
});
|
|
222
|
+
if (stopped) {
|
|
223
|
+
records.push(notRun(`the study stopped: ${stopped}`));
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
const latch = interviewLatch.reserve(session.id, latch_1.SESSION_CALLS);
|
|
227
|
+
if ("refused" in latch) {
|
|
228
|
+
stopped = latch.refused;
|
|
229
|
+
records.push(notRun(latch.refused));
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
deps.started.add(session.id);
|
|
233
|
+
let record;
|
|
234
|
+
try {
|
|
235
|
+
record = await runSession({ session, kit: deps.kits[session.product], cases, latch, target, ledger, pricing, runCase: deps.runCase, log });
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
238
|
+
// Nothing that goes wrong in one session loses the sessions already run, or holds its reservation.
|
|
239
|
+
record = { ...notRun((0, loop_1.messageOf)(error)), status: "crashed", voidedBy: latch.voided(), calls: latch.calls(), spent: latch.release() };
|
|
240
|
+
}
|
|
241
|
+
records.push(record);
|
|
242
|
+
perCallCredits = Math.max(perCallCredits, latch.hold.maxCall());
|
|
243
|
+
if (ledger.stopped())
|
|
244
|
+
stopped = ledger.stopped();
|
|
245
|
+
}
|
|
246
|
+
after = await target.quota();
|
|
247
|
+
}
|
|
248
|
+
finally {
|
|
249
|
+
writeReport();
|
|
250
|
+
}
|
|
251
|
+
deps.print(summarizeSessions(records, ledger.totals().spent, stopped));
|
|
252
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.interview_run_end", message: "finished blind-interview sessions", meta: { sessions: records.length, stopped } });
|
|
253
|
+
return { exitCode: stopped ? 2 : 0, records };
|
|
254
|
+
}
|
|
255
|
+
/** Every X arm, for the parser's check. */
|
|
256
|
+
exports.KNOWN_ARMS = { H: [], U: [], X: arms_1.X_ARMS };
|
|
257
|
+
const STRING_FLAGS = { "--preregistration": "preregistration", "--cases": "cases", "--target": "target", "--credentials-agent": "credentialsAgent", "--output": "output", "--request-log": "requestLog", "--harness-ref": "harnessRef" };
|
|
258
|
+
const NUMBER_FLAGS = { "--budget-premium": "budgetPremium", "--budget-credits": "budgetCredits", "--price-in": "priceIn", "--price-out": "priceOut", "--reserve-credits-per-call": "reserveCreditsPerCall" };
|
|
259
|
+
const REQUIRED = ["--preregistration", "--cases", "--target", "--credentials-agent", "--budget-premium", "--output"];
|
|
260
|
+
function parseInterviewArgs(argv) {
|
|
261
|
+
const out = { sessions: [], reduced: false, harnessRef: "unknown" };
|
|
262
|
+
const seen = new Set();
|
|
263
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
264
|
+
const flag = argv[i];
|
|
265
|
+
if (flag === "--reduced") {
|
|
266
|
+
out.reduced = true;
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
const value = argv[i + 1];
|
|
270
|
+
if (flag !== "--session" && !Object.hasOwn(STRING_FLAGS, flag) && !Object.hasOwn(NUMBER_FLAGS, flag))
|
|
271
|
+
throw new Error(`unknown flag ${flag}`);
|
|
272
|
+
if (value === undefined)
|
|
273
|
+
throw new Error(`${flag} needs a value`);
|
|
274
|
+
i += 1;
|
|
275
|
+
seen.add(flag);
|
|
276
|
+
if (flag === "--session")
|
|
277
|
+
out.sessions.push(value);
|
|
278
|
+
else if (Object.hasOwn(STRING_FLAGS, flag))
|
|
279
|
+
out[STRING_FLAGS[flag]] = value;
|
|
280
|
+
else {
|
|
281
|
+
const number = Number(value);
|
|
282
|
+
if (!(Number.isFinite(number) && number >= 0))
|
|
283
|
+
throw new Error(`${flag} must be a number of at least 0`);
|
|
284
|
+
out[NUMBER_FLAGS[flag]] = number;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
const missing = REQUIRED.find((flag) => !seen.has(flag));
|
|
288
|
+
if (missing)
|
|
289
|
+
throw new Error(`${missing} is required`);
|
|
290
|
+
out.requestLog ??= String(out.output).replace(/(\.json)?$/, ".requests.ndjson");
|
|
291
|
+
return out;
|
|
292
|
+
}
|
|
@@ -151,6 +151,10 @@ exports.ENTRY_POINT_COMMANDS = [
|
|
|
151
151
|
{ code: "budget-stopped", means: "The eval stopped early: a run's reservation would pass a cap, or the provider answered 402 or 429. The report holds the runs that finished.", fix: "Read the summary on stdout. Raise the cap only if that spend is approved; the report keeps every finished run as measured, so a rerun adds runs rather than replacing them." },
|
|
152
152
|
{ code: "eval-error", means: "The eval refused to start or failed: a bad or missing flag, a case that fails its self-test, a report file that exists already, a target without its prices or caps, or a run that threw.", fix: "Read the `eval:` line above it on stderr, fix that, and run again with a new --output path." },
|
|
153
153
|
] } },
|
|
154
|
+
{ name: "node dist/eval/interview-entry.js", effect: "private", summary: "Run blind-interview sessions on a model.", ax: { id: "cli:node dist/eval/interview-entry.js", group: "diagnostics", effect: "consequential", confirm: "It spends model credits or premium requests on the account the flags name, up to the caps you pass, and a session it starts can never run again.", when: "Run the pre-registered blind-interview sessions on one model, writing a private report and request log; each session reserves its worst case first.", errors: [
|
|
155
|
+
{ code: "budget-stopped", means: "The study stopped: a session's reservation would pass a cap, or the provider answered 402 or 429. Later sessions are recorded as not run.", fix: "Read the counts on stdout; the study stays stopped, since a session that didn't run counts as ouro not chosen first." },
|
|
156
|
+
{ code: "eval-error", means: "The interviews refused to start (a bad flag, sandbox or target, or a session not allowed or already started) or failed after starting.", fix: "Read the `interviews:` line on stderr; the started file keeps every session it began, so a new run takes only sessions not yet in it." },
|
|
157
|
+
] } },
|
|
154
158
|
{ name: "node dist/senses/shepherd/judge-evaluation-entry.js", effect: "private", summary: "Evaluate Shepherd's judge on its cases.", ax: { id: "cli:node dist/senses/shepherd/judge-evaluation-entry.js", group: "diagnostics", effect: "write", when: "Measure how Shepherd's judge classifies its evaluation cases, writing a report; it never qualifies v1 on its own.", errors: [
|
|
155
159
|
{ code: "not-passed", means: "The Shepherd judge evaluation finished, but its classification didn't pass or closing its report threw.", fix: "Read the JSON summary on stdout and the report for the failing cases." },
|
|
156
160
|
{ code: "evaluation-error", means: "The Shepherd judge evaluation stopped before running a case (bad arguments, an output that exists already, no judge for the agent, or a bad case corpus), or writing its report threw.", fix: "Read the error in the JSON on stdout, fix it, and run again with a new --output path." },
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.realtimeUtteranceLedger = realtimeUtteranceLedger;
|
|
4
|
+
exports.isAudioPart = isAudioPart;
|
|
5
|
+
exports.responseMadeAudio = responseMadeAudio;
|
|
6
|
+
const runtime_1 = require("../../nerves/runtime");
|
|
7
|
+
const turn_attempts_1 = require("../turn-attempts");
|
|
8
|
+
const utterances_1 = require("./utterances");
|
|
9
|
+
function segment(input) {
|
|
10
|
+
return input.trim().replace(/[^A-Za-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
11
|
+
}
|
|
12
|
+
/** Tool arguments as text: only text values can name who a send goes to or what it says. */
|
|
13
|
+
function textArgs(args) {
|
|
14
|
+
return Object.fromEntries(Object.entries(args).filter((entry) => typeof entry[1] === "string"));
|
|
15
|
+
}
|
|
16
|
+
function realtimeUtteranceLedger(call) {
|
|
17
|
+
const prefix = call.engine === "openai-sip" ? "sip" : "realtime";
|
|
18
|
+
let heardCount = 0;
|
|
19
|
+
let waiting = [];
|
|
20
|
+
const replies = new Map();
|
|
21
|
+
/** What the caller said before the call asked to hang up and no reply spoke to. */
|
|
22
|
+
const unansweredByChoice = new Set();
|
|
23
|
+
const settleAll = (utterances, ...outcome) => {
|
|
24
|
+
for (const utterance of utterances)
|
|
25
|
+
utterance.settle(...outcome);
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
heard(itemId) {
|
|
29
|
+
heardCount += 1;
|
|
30
|
+
const id = `${prefix}-${segment(call.callSid)}-${segment(itemId) || `caller-${heardCount}`}`;
|
|
31
|
+
const record = (0, utterances_1.recordVoiceUtterance)(call.outputDir, id, {
|
|
32
|
+
callSid: call.callSid, friendId: call.friendId, sessionKey: call.sessionKey, transport: call.engine,
|
|
33
|
+
}, call.bridge);
|
|
34
|
+
if (!record)
|
|
35
|
+
return;
|
|
36
|
+
record.beginAttempt();
|
|
37
|
+
waiting.push(record);
|
|
38
|
+
},
|
|
39
|
+
replyStarted(responseId, answers) {
|
|
40
|
+
if (!answers || !responseId || waiting.length === 0)
|
|
41
|
+
return;
|
|
42
|
+
replies.set(responseId, { utterances: waiting, spoke: false, unheard: false, done: false, cut: null });
|
|
43
|
+
waiting = [];
|
|
44
|
+
},
|
|
45
|
+
speaking(responseId) {
|
|
46
|
+
const reply = replies.get(responseId);
|
|
47
|
+
if (!reply)
|
|
48
|
+
return;
|
|
49
|
+
reply.unheard = true;
|
|
50
|
+
if (reply.spoke)
|
|
51
|
+
return;
|
|
52
|
+
reply.spoke = true;
|
|
53
|
+
const spoke = (0, turn_attempts_1.turnSpoke)("speech:audio", null);
|
|
54
|
+
for (const utterance of reply.utterances)
|
|
55
|
+
utterance.noteSpoke(spoke);
|
|
56
|
+
},
|
|
57
|
+
played(responseId) {
|
|
58
|
+
const reply = replies.get(responseId);
|
|
59
|
+
if (!reply)
|
|
60
|
+
return;
|
|
61
|
+
replies.delete(responseId);
|
|
62
|
+
settleAll(reply.utterances, "answered");
|
|
63
|
+
},
|
|
64
|
+
replyDone(responseId, madeAudio = false) {
|
|
65
|
+
const reply = replies.get(responseId);
|
|
66
|
+
if (!reply)
|
|
67
|
+
return;
|
|
68
|
+
// Audio still on its way to the caller may yet play.
|
|
69
|
+
if (reply.unheard || (madeAudio && !reply.cut)) {
|
|
70
|
+
reply.done = true;
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
replies.delete(responseId);
|
|
74
|
+
if (reply.cut)
|
|
75
|
+
settleAll(reply.utterances, "failed", reply.cut);
|
|
76
|
+
else
|
|
77
|
+
waiting = [...reply.utterances, ...waiting];
|
|
78
|
+
},
|
|
79
|
+
toolSending(name, args) {
|
|
80
|
+
const spoke = (0, turn_attempts_1.turnSpokeForTool)(name, textArgs(args));
|
|
81
|
+
if (!spoke)
|
|
82
|
+
return;
|
|
83
|
+
for (const reply of replies.values())
|
|
84
|
+
for (const utterance of reply.utterances)
|
|
85
|
+
utterance.noteSpoke(spoke);
|
|
86
|
+
for (const utterance of waiting)
|
|
87
|
+
utterance.noteSpoke(spoke);
|
|
88
|
+
},
|
|
89
|
+
hangingUp() {
|
|
90
|
+
for (const reply of replies.values())
|
|
91
|
+
if (!reply.spoke)
|
|
92
|
+
for (const utterance of reply.utterances)
|
|
93
|
+
unansweredByChoice.add(utterance);
|
|
94
|
+
for (const utterance of waiting)
|
|
95
|
+
unansweredByChoice.add(utterance);
|
|
96
|
+
},
|
|
97
|
+
cutOff(reason) {
|
|
98
|
+
for (const [responseId, reply] of replies) {
|
|
99
|
+
if (!reply.unheard)
|
|
100
|
+
continue;
|
|
101
|
+
reply.unheard = false;
|
|
102
|
+
reply.cut = reason;
|
|
103
|
+
if (!reply.done)
|
|
104
|
+
continue;
|
|
105
|
+
replies.delete(responseId);
|
|
106
|
+
settleAll(reply.utterances, "failed", reason);
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
ended(silent) {
|
|
110
|
+
const counts = { failed: 0, silent: 0 };
|
|
111
|
+
const settle = (utterances, spoke, failure) => {
|
|
112
|
+
for (const utterance of utterances) {
|
|
113
|
+
if (silent || (!spoke && unansweredByChoice.has(utterance))) {
|
|
114
|
+
utterance.settle("silent", silent ?? "the call was ended without a spoken reply");
|
|
115
|
+
counts.silent += 1;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
utterance.settle("failed", failure);
|
|
119
|
+
counts.failed += 1;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
for (const reply of replies.values()) {
|
|
124
|
+
settle(reply.utterances, reply.spoke, reply.cut && !reply.unheard ? reply.cut : "the call ended before the reply was played");
|
|
125
|
+
}
|
|
126
|
+
replies.clear();
|
|
127
|
+
settle(waiting, false, "the call ended before this was answered");
|
|
128
|
+
waiting = [];
|
|
129
|
+
if (counts.failed + counts.silent === 0)
|
|
130
|
+
return;
|
|
131
|
+
(0, runtime_1.emitNervesEvent)({
|
|
132
|
+
level: counts.failed > 0 ? "warn" : "info",
|
|
133
|
+
component: "senses",
|
|
134
|
+
event: "senses.voice_realtime_utterances_unanswered",
|
|
135
|
+
message: "a phone call ended with things the caller said that no reply played to",
|
|
136
|
+
meta: { engine: call.engine, callSid: segment(call.callSid), ...counts },
|
|
137
|
+
});
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
/** Whether a response content part is audio, as in `response.content_part.added` or a finished response's output. */
|
|
142
|
+
function isAudioPart(part) {
|
|
143
|
+
const type = part && typeof part === "object" ? part.type : undefined;
|
|
144
|
+
return type === "output_audio" || type === "audio";
|
|
145
|
+
}
|
|
146
|
+
/** Whether a finished response's output held audio, from its `response.done` event. */
|
|
147
|
+
function responseMadeAudio(event) {
|
|
148
|
+
const response = event.response;
|
|
149
|
+
if (!response || typeof response !== "object" || Array.isArray(response))
|
|
150
|
+
return false;
|
|
151
|
+
const output = response.output;
|
|
152
|
+
if (!Array.isArray(output))
|
|
153
|
+
return false;
|
|
154
|
+
return output.some((item) => {
|
|
155
|
+
const content = item && typeof item === "object" ? item.content : undefined;
|
|
156
|
+
return Array.isArray(content) && content.some(isAudioPart);
|
|
157
|
+
});
|
|
158
|
+
}
|