Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,32 @@ function tracer() {
return { order, fetchFn };
}

test("BenchRunner.createSession: forwards the session thinking level", async () => {
let body: unknown;
const fetchFn: typeof fetch = async (_input, init) => {
body = JSON.parse(String(init?.body));
return new Response(JSON.stringify({
id: "sid-thinking",
session: { thinkingLevel: "high" },
}), { status: 200 });
};
const runner = new BenchRunner({ baseUrl: "http://runtime", fetchFn, thinkingLevel: "high" });
assert.equal(await runner.createSession(), "sid-thinking");
assert.deepEqual(body, { thinkingLevel: "high" });
});

test("BenchRunner.createSession: rejects a silently downgraded thinking level", async () => {
const fetchFn: typeof fetch = async () => new Response(JSON.stringify({
id: "sid-thinking",
session: { thinkingLevel: "medium" },
}), { status: 200 });
const runner = new BenchRunner({ baseUrl: "http://runtime", fetchFn, thinkingLevel: "high" });
await assert.rejects(
runner.createSession(),
/thinking level mismatch: requested high, observed medium/,
);
});

test("BenchRunner.run: setup hook runs before the first prompt", async () => {
const { order, fetchFn } = tracer();
const result = await new BenchRunner({ baseUrl: "http://runtime", fetchFn }).run(makeTask(), {
Expand Down
25 changes: 23 additions & 2 deletions src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export interface RunnerOptions {
/** Quiet period after all observed runs finish before declaring session idle. */
settleMs?: number;
fetchFn?: typeof fetch;
/** Session-wide reasoning effort shared by every BrainPilot agent. */
thinkingLevel?: "off" | "low" | "medium" | "high";
}

export interface RunResult {
Expand Down Expand Up @@ -94,21 +96,40 @@ export class BenchRunner {
private fetchFn: typeof fetch;
private configuredIdleMs?: number;
private configuredSettleMs?: number;
private thinkingLevel?: "off" | "low" | "medium" | "high";
constructor(opts: RunnerOptions) {
this.base = opts.baseUrl.replace(/\/+$/, "");
this.fetchFn = opts.fetchFn ?? fetch;
this.configuredIdleMs = opts.idleMs;
this.configuredSettleMs = opts.settleMs;
const thinkingLevel = opts.thinkingLevel ?? process.env.BPB_THINKING_LEVEL;
if (thinkingLevel && !["off", "low", "medium", "high"].includes(thinkingLevel)) {
throw new Error(`invalid BPB_THINKING_LEVEL: ${thinkingLevel}`);
}
this.thinkingLevel = thinkingLevel as RunnerOptions["thinkingLevel"];
}
private url(tmpl: string, params?: Record<string, string>) { return this.base + fillPath(tmpl, params); }

async createSession(): Promise<string> {
const r = await this.fetchFn(this.url(RUNTIME_ROUTES.createSession.path), {
method: RUNTIME_ROUTES.createSession.method,
headers: { "content-type": "application/json" }, body: "{}",
headers: { "content-type": "application/json" },
body: JSON.stringify(this.thinkingLevel ? { thinkingLevel: this.thinkingLevel } : {}),
});
if (!r.ok) throw new Error(`createSession ${r.status}`);
return (await r.json()).id;
const created = await r.json() as {
id: string;
session?: { thinkingLevel?: string };
};
if (this.thinkingLevel) {
const observed = created.session?.thinkingLevel;
if (observed !== this.thinkingLevel) {
throw new Error(
`createSession thinking level mismatch: requested ${this.thinkingLevel}, observed ${observed ?? "missing"}`,
);
}
}
return created.id;
}
private async send(sid: string, content: string): Promise<void> {
const r = await this.fetchFn(this.url(RUNTIME_ROUTES.sendMessage.path, { id: sid }), {
Expand Down
Loading