import { Message } from "../contracts/conversation-message.type.mjs"; import { ModelCallOptions, ModelCapabilities, ModelContract, ModelResponse, ModelStreamChunk } from "../contracts/model.contract.mjs"; import { MockModelResponse } from "./mock-config.type.mjs"; //#region ../ai/src/mock/mock-model.d.ts type RecordedCall = { messages: Message[]; options?: ModelCallOptions; }; /** * Deterministic in-memory `ModelContract` implementation for tests. * * **Role.** Stands in for a real provider model so agent/workflow/supervisor * tests can assert behavior without hitting the network, spending tokens, or * depending on non-deterministic LLM output. * * **Responsibility.** * - Owns: a scripted queue of `MockModelResponse` entries, a call-history * log for assertions, and the index pointer that advances through the * queue on each `complete()` / `stream()` call. * - Does NOT own: any real inference, tokenization, or network I/O โ€” when * the queue is exhausted, the final entry is reused so tests never crash * on accidental over-consumption. * * Every AI-related test in this repo uses `MockSDK` / `MockModel` โ€” real * provider APIs are never hit from the test suite (see ยง6 of code-style.md). * * @example * const model = new MockModel("mock-gpt", [ * { content: "Hello!", finishReason: "stop" }, * { content: "Second turn.", finishReason: "stop" }, * ]); * * const first = await model.complete([{ role: "user", content: "hi" }]); * expect(first.content).toBe("Hello!"); * expect(model.callCount).toBe(1); */ declare class MockModel implements ModelContract { readonly name: string; private readonly responses; readonly provider = "mock"; readonly capabilities?: ModelCapabilities; private responseIndex; private calls; constructor(name: string, responses: MockModelResponse[], capabilities?: ModelCapabilities); /** * Full history of calls made to this model. Each entry is the exact * `{ messages, options }` pair that was passed โ€” useful for asserting * that an agent built the right prompt or forwarded the right tool list. */ get callHistory(): RecordedCall[]; /** * Number of times `complete()` or `stream()` has been invoked. Convenient * shorthand for `callHistory.length` in assertions. */ get callCount(): number; /** * Advance the scripted response queue by one and return the entry at the * current pointer. If the queue is exhausted, the final scripted entry is * returned repeatedly so over-consumption in tests produces predictable * output instead of `undefined`. */ private nextResponse; /** * Convert a scripted `MockModelResponse` into a full `ModelResponse` with * synthesized usage numbers when the script didn't supply them. Input * usage is a fixed estimate; output usage is derived from content length. */ private buildResponse; /** * Record the call, optionally delay (to simulate latency), and either * throw the scripted error or return the scripted response. Mirrors the * real provider's `complete()` contract so agents cannot tell the * difference at runtime. */ complete(messages: Message[], options?: ModelCallOptions): Promise; /** * Record the call, optionally delay, then emit the scripted response as a * sequence of stream chunks: the scripted `deltas` when the entry * supplies them, otherwise content split word-by-word, as `delta` * chunks, each scripted tool call as a `tool-call` chunk, and finally a * `done` chunk with finish reason + usage. Throws eagerly if the scripted * entry carries an `error`. */ stream(messages: Message[], options?: ModelCallOptions): AsyncIterable; /** * Reset call history and response pointer back to their initial state. * Intended for test-suite `beforeEach` hooks so a single `MockModel` * instance can be reused across cases without cross-test leakage. */ reset(): void; } //#endregion export { MockModel }; //# sourceMappingURL=mock-model.d.mts.map