Split model call and tool loop helpers

This commit is contained in:
2026-05-18 19:55:00 +03:00
parent 57985ce87b
commit d163d72a0b
8 changed files with 149 additions and 38 deletions
+17
View File
@@ -0,0 +1,17 @@
import test from "node:test";
import assert from "node:assert/strict";
const {runSingleModelRequest} = await import("../dist/ai/model-call-stage.js");
test("single model request wrapper executes exactly once", async () => {
let calls = 0;
const result = await runSingleModelRequest({
async execute() {
calls += 1;
return "ok";
},
});
assert.equal(result, "ok");
assert.equal(calls, 1);
});
+37
View File
@@ -0,0 +1,37 @@
import test from "node:test";
import assert from "node:assert/strict";
const {runToolLoopRounds} = await import("../dist/ai/tool-loop-runner.js");
test("tool loop runner stops when handler requests it", async () => {
const rounds = [];
await runToolLoopRounds({
maxRounds: 5,
async onRound(round) {
rounds.push(round);
return {shouldContinue: round < 1};
},
});
assert.deepEqual(rounds, [0, 1]);
});
test("tool loop runner calls max rounds hook when handler never stops", async () => {
const rounds = [];
let maxRoundsReached = -1;
await runToolLoopRounds({
maxRounds: 3,
async onRound(round) {
rounds.push(round);
return {shouldContinue: true};
},
onMaxRoundsReached(round) {
maxRoundsReached = round;
},
});
assert.deepEqual(rounds, [0, 1, 2]);
assert.equal(maxRoundsReached, 2);
});