UNPKG

eve

Version:

Filesystem-first framework for durable backend AI agents that run anywhere.

94 lines (93 loc) 4.01 kB
import type { LanguageModel } from "ai"; /** A text-only view of one message passed to a mock model. */ export interface MockModelMessage { /** The message author. */ readonly role: "assistant" | "system" | "tool" | "user"; /** Text extracted from the message's content parts. */ readonly text: string; } /** A tool available to a mock model call. */ export interface MockModelTool { /** Tool name exposed to the model. */ readonly name: string; /** Authored tool description, when present. */ readonly description?: string; /** JSON Schema describing the tool input, when present. */ readonly inputSchema?: unknown; } /** A completed tool call present in the model prompt. */ export interface MockModelToolResult { /** Tool-call identifier. */ readonly id: string; /** Name of the tool that produced the result. */ readonly name: string; /** Normalized tool output. */ readonly output: unknown; /** Whether the tool execution failed or was denied. */ readonly isError: boolean; } /** Normalized input supplied to a {@link MockModelResponder}. */ export interface MockModelRequest { /** Every prompt message in order, with text content extracted. */ readonly messages: readonly MockModelMessage[]; /** All user-message text in order. */ readonly userMessages: readonly string[]; /** The latest user-message text, or `null` before the first user message. */ readonly lastUserMessage: string | null; /** Number of user messages in the prompt. */ readonly userMessageCount: number; /** Tools available for this model call. */ readonly tools: readonly MockModelTool[]; /** Tool results already present in the prompt. */ readonly toolResults: readonly MockModelToolResult[]; } /** One tool call emitted by a mock model response. */ export interface MockModelToolCall { /** Name of the tool to call. */ readonly name: string; /** JSON-serializable tool input. Defaults to an empty object. */ readonly input?: unknown; /** Stable call id. eve derives one when omitted. */ readonly id?: string; } /** Optional token counts reported by a mock response. */ export interface MockModelUsage { /** Prompt tokens. eve estimates this value when omitted. */ readonly inputTokens?: number; /** Generated tokens. eve estimates this value when omitted. */ readonly outputTokens?: number; } /** Advanced response shape for text, tool calls, and explicit token usage. */ export interface MockModelResponse { /** Assistant text. May be combined with tool calls. */ readonly text?: string; /** Tool calls emitted by the model. */ readonly toolCalls?: readonly MockModelToolCall[]; /** Token counts to report instead of eve's deterministic estimates. */ readonly usage?: MockModelUsage; } /** Produces the next deterministic mock-model response. */ export type MockModelResponder = (request: MockModelRequest) => MockModelResponse | Promise<MockModelResponse | string> | string; /** Advanced configuration for {@link mockModel}. */ export interface MockModelOptions { /** Model id exposed to the agent runtime. Defaults to `"model"`. */ readonly modelId?: string; /** Provider id exposed to the agent runtime. Defaults to `"eve-mock"`. */ readonly provider?: string; /** Static response or callback used for each model call. */ readonly respond?: MockModelResponder | string; } /** * Creates a deterministic local language model for an eve eval fixture. * * Pass a string for a static reply, a callback for prompt-aware behavior, or * an options object when the model identity or advanced responses need to be * customized. Calling `mockModel()` returns `"Mock response"`. * * @example * ```ts * mockModel("Hello from the test agent"); * mockModel(({ lastUserMessage }) => `Echo: ${lastUserMessage}`); * ``` */ export declare function mockModel(input?: MockModelOptions | MockModelResponder | string): LanguageModel;