MockAgent
An in-memory agent with writable test signals, captured submissions, and a stop invocation counter.
import type { MockAgent } from '@threadplane/chat';Declaration
export interface MockAgent extends Agent {
_internal: {
streamStartedAt: WritableSignal<number | null>;
};
error: WritableSignal<AgentError | undefined>;
events$: Observable<AgentEvent>;
history?: WritableSignal<AgentCheckpoint[]>;
interrupt?: WritableSignal<AgentInterrupt | undefined>;
isLoading: WritableSignal<boolean>;
lifecycle: {
streamStartedAt: Signal<number | null>;
};
messages: WritableSignal<Message[]>;
state: WritableSignal<Record<string, unknown>>;
status: WritableSignal<AgentStatus>;
stopCount: number;
subagents?: WritableSignal<Map<string, Subagent>>;
submitCalls: Array<{
input: AgentSubmitInput;
opts?: AgentSubmitOptions;
}>;
toolCalls: WritableSignal<ToolCall[]>;
}Members
_internal
Test-only escape hatch for driving lifecycle signals from a spec. Mirrors
the _internal pattern used by CHAT_LIFECYCLE so tests can flip the
underlying writable without going through a full submit/stream cycle.
_internal: {
streamStartedAt: WritableSignal<number | null>;
};error
error: WritableSignal<AgentError | undefined>;events$
events$: Observable<AgentEvent>;history
history?: WritableSignal<AgentCheckpoint[]>;interrupt
interrupt?: WritableSignal<AgentInterrupt | undefined>;isLoading
isLoading: WritableSignal<boolean>;lifecycle
Minimal lifecycle stub the chat lib's effects subscribe to. We only
model the signals the chat composition currently reads; richer adapter
lifecycles (langgraph, AG-UI) extend this contract on their own mocks.
The public lifecycle view is a readonly signal; tests drive the
value via _internal.streamStartedAt.set(...) below.
lifecycle: {
streamStartedAt: Signal<number | null>;
};messages
messages: WritableSignal<Message[]>;state
state: WritableSignal<Record<string, unknown>>;status
status: WritableSignal<AgentStatus>;stopCount
Count of stop() invocations.
stopCount: number;subagents
subagents?: WritableSignal<Map<string, Subagent>>;submitCalls
Captured calls to submit() in order.
submitCalls: Array<{
input: AgentSubmitInput;
opts?: AgentSubmitOptions;
}>;toolCalls
toolCalls: WritableSignal<ToolCall[]>;