/** * A scriptable model double, so an agent can be tested offline. * * Python parity: `praisonaiagents.model_harness.scripted` * (`ScriptedModel`, `ScriptExhausted`). * * ```ts * const model = new ScriptedModel(['Refunded order A1.']); * const agent = new Agent({ instructions: 'Support bot.', llm: model }); * * expect(await agent.chat('refund order A1')).toBe('Refunded order A1.'); * expect(model.requestCount).toBe(1); * expect(model.requests[0].prompt).toBe('refund order A1'); * ``` * * Like the Python version, this subclasses the real {@link BaseLLM} and * replaces only the provider-facing methods, so prompt assembly, options * handling and the response shape all run production code. The double cannot * drift from the real client, because it *is* the real client with its network * boundary swapped out. */ import { BaseLLM, type LLMConfig, type LLMResponse, type LLMGenerateOptions } from '../llm'; import type { LLMProvider, GenerateTextOptions, GenerateTextResult, StreamTextOptions, StreamChunk, GenerateObjectOptions, GenerateObjectResult } from '../llm/providers/types'; /** Thrown when the script runs out of replies. */ export declare class ScriptExhausted extends Error { constructor(consumed: number, prompt: string); } /** One request the agent actually sent, recorded for assertions. */ export interface RecordedRequest { prompt: string; systemPrompt?: string; options?: LLMGenerateOptions; } /** A scripted reply: a plain string, or a function of the request. */ export type ScriptEntry = string | ((request: RecordedRequest) => string); export declare class ScriptedModel extends BaseLLM implements LLMProvider { private readonly script; private cursor; /** Every request the agent sent, in order. */ readonly requests: RecordedRequest[]; constructor(script: ScriptEntry[], config?: Partial); /** How many completions the agent asked for. */ get requestCount(): number; /** Replies left unconsumed. */ get remaining(): number; /** Rewind so the same instance can drive another run. */ reset(): void; /** Append more replies to the script. */ extend(...entries: ScriptEntry[]): void; private next; generate(prompt: string, options?: LLMGenerateOptions): Promise; generateStream(prompt: string, options?: LLMGenerateOptions): AsyncGenerator; readonly providerId = "scripted"; get modelId(): string; /** The last user message, which is the prompt the agent is asking about. */ private static lastUserText; private static systemText; generateText(options: GenerateTextOptions): Promise; streamText(options: StreamTextOptions): Promise>; generateObject(options: GenerateObjectOptions): Promise>; }