ReadonlylastRequest: GenerateRequest | undefinedThe request from the most recent call, or undefined if never called.
ReadonlylastRequestMessage: Message | undefinedThe final message of the most recent request, wrapped as a Message
so you can read it the same way you read a response — .text, .media,
.toolRequests, etc. undefined if the model was never called.
assert.match(model.lastRequestMessage!.text, /Summarize: long text/);
ReadonlylastRequestText: string | undefinedThe full assembled conversation of the most recent request, flattened to a
single string (system + every message, in order). Use it for prompt-
assembly assertions on any mock — including ones returning structured
output, where echoModel can't be used. undefined if never called.
assert.match(model.lastRequestText!, /system: Be terse/);
ReadonlyrequestCount: numberHow many times this model was called.
Readonlyrequests: GenerateRequest[]Every request this model received, oldest first.
ReadonlytoolResponses: { name: string; output: unknown; ref?: string }[]The tool results fed back to the model in the most recent request, in order. Use it to assert which tools ran and what they returned, without digging through message content yourself. Empty if the model was never called or saw no tool results.
assert.deepStrictEqual(model.toolResponses.map((t) => t.name), ['lookup']);
Clears recorded history (requests, requestCount, …) and restores the
respond behavior given at construction, re-arming a queued respond from
its first item. Call it in beforeEach so tests sharing a mock stay
order-independent.
Replaces the respond behavior for subsequent calls. Accepts everything MockModelOptions.respond does; an array re-arms as a fresh queue. Recorded history is untouched — use MockModel.reset for that.
Together with reset() this supports the register-once idiom: define the
mock once per test file, then give each test its own behavior.
const model = mockModel(ai, { name: 'menuModel' });
beforeEach(() => model.reset());
test('...', async () => {
model.respondWith({ text: 'scripted' });
// ...
});
A mock model with typed inspection of the calls it received. The extra members are read-only views over the recorded calls.