FakeAgentSession
A fake session and the controls a test uses to drive it.
import type { FakeAgentSession } from '@threadplane/angular/chat/testing';Declaration
export interface FakeAgentSession<TTools extends {
[K in keyof TTools]: ToolContract;
} = Record<string, ToolContract>, TState = unknown> {
readonly catalogs: readonly (readonly ClientToolSpec[])[];
readonly checkStatusCount: number;
readonly clientToolResults: readonly FakeClientToolSettlement[];
readonly disposed: boolean;
emitCustomEvent(name: string, data?: PlainValue): void;
readonly flushCount: number;
onResume(handler: FakeResumeHandler<TTools, TState> | undefined): void;
onSubmit(handler: FakeSubmitHandler<TTools, TState> | undefined): void;
push(message: FakeMessageInput): Message;
readonly regenerates: readonly FakeRegenerateCall[];
readonly resumes: readonly FakeResumeCall<TState>[];
readonly retryCount: number;
readonly runs: readonly FakeRunCall<TState>[];
readonly session: AgentSession<TTools, TState>;
set(patch: FakeAgentSnapshotPatch<TTools, TState>): void;
setCheckpoints(checkpoints: readonly AgentCheckpoint[] | undefined, messageCheckpoints?: Readonly<Record<string, string>>): void;
setError(error: AgentError | undefined, cause?: unknown): void;
setInterrupts(interrupts: readonly AgentInterrupt[] | undefined): void;
setState(state: NoInfer<TState> | undefined): void;
setStatus(status: AgentStatus): void;
setSubagents(subagents: readonly FakeSubagentInput[] | undefined): void;
setToolCalls(toolCalls: readonly ToolCall<TTools>[]): void;
setUsage(usage: AgentUsage | undefined): void;
readonly stopCount: number;
stream(options?: {
readonly id?: string;
readonly text?: string;
}): FakeAssistantStream;
readonly submits: readonly FakeSubmitCall<TState>[];
}Type parameters
TTools{ [K in keyof TTools]: ToolContract; }Default:Record<string, ToolContract>TStateDefault:unknown
Members
catalogs
Every catalog given to clientTools.setCatalog, in order; the last is current.
readonly catalogs: readonly (readonly ClientToolSpec[])[];checkStatusCount
readonly checkStatusCount: number;clientToolResults
Results given through clientTools.settle and clientTools.resolve, in order.
readonly clientToolResults: readonly FakeClientToolSettlement[];disposed
readonly disposed: boolean;emitCustomEvent · overload 1
Delivers one custom event to onCustomEvent listeners. A listener that
throws affects neither the others nor the caller. Nothing is delivered
after disposal.
emitCustomEvent(name: string, data?: PlainValue): void;Parameters
name· requiredstringdata· optionalPlainValue
Returns
voidflushCount
readonly flushCount: number;onResume · overload 1
Replaces the handler used by later resumes.
onResume(handler: FakeResumeHandler<TTools, TState> | undefined): void;Parameters
handler· requiredFakeResumeHandler<TTools, TState> | undefined
Returns
voidonSubmit · overload 1
Replaces the handler used by later submissions.
onSubmit(handler: FakeSubmitHandler<TTools, TState> | undefined): void;Parameters
handler· requiredFakeSubmitHandler<TTools, TState> | undefined
Returns
voidpush · overload 1
Appends one message and returns the owned, frozen copy.
push(message: FakeMessageInput): Message;Parameters
message· requiredFakeMessageInput
Returns
Messageregenerates
Calls to regenerate in order, including rejected ones.
readonly regenerates: readonly FakeRegenerateCall[];resumes
Resumes in call order, including ones the fake or the handler rejected.
readonly resumes: readonly FakeResumeCall<TState>[];retryCount
readonly retryCount: number;runs
Calls to runWithoutMessage in order.
readonly runs: readonly FakeRunCall<TState>[];session
Pass this to Chat, useAgent, or any other session consumer.
readonly session: AgentSession<TTools, TState>;set · overload 1
Replaces the listed snapshot fields and notifies subscribers once.
set(patch: FakeAgentSnapshotPatch<TTools, TState>): void;Parameters
patch· requiredFakeAgentSnapshotPatch<TTools, TState>
Returns
voidsetCheckpoints · overload 1
Replaces the loaded history and, when given, the message-to-checkpoint
map; undefined removes both.
setCheckpoints(checkpoints: readonly AgentCheckpoint[] | undefined, messageCheckpoints?: Readonly<Record<string, string>>): void;Parameters
checkpoints· requiredreadonly AgentCheckpoint[] | undefinedmessageCheckpoints· optionalReadonly<Record<string, string>>
Returns
voidsetError · overload 1
Publishes the error with status 'error'; undefined clears it and
returns an errored session to 'idle'. cause is any thrown value: the
fake describes it as the snapshot's errorDiagnostic. Replacing or
clearing the error removes the earlier diagnostic.
setError(error: AgentError | undefined, cause?: unknown): void;Parameters
error· requiredAgentError | undefinedcause· optionalunknown
Returns
voidsetInterrupts · overload 1
Replaces the pending interrupts; undefined removes the field.
setInterrupts(interrupts: readonly AgentInterrupt[] | undefined): void;Parameters
interrupts· requiredreadonly AgentInterrupt[] | undefined
Returns
voidsetState · overload 1
Replaces the state; undefined removes it. Throws when a schema stateType rejects it.
setState(state: NoInfer<TState> | undefined): void;Parameters
state· requiredNoInfer<TState> | undefined
Returns
voidsetStatus · overload 1
setStatus(status: AgentStatus): void;Parameters
status· requiredAgentStatus
Returns
voidsetSubagents · overload 1
Replaces the child agents; undefined removes the field.
setSubagents(subagents: readonly FakeSubagentInput[] | undefined): void;Parameters
subagents· requiredreadonly FakeSubagentInput[] | undefined
Returns
voidsetToolCalls · overload 1
setToolCalls(toolCalls: readonly ToolCall<TTools>[]): void;Parameters
toolCalls· requiredreadonly ToolCall<TTools>[]
Returns
voidsetUsage · overload 1
Replaces the reported usage; undefined removes the field.
setUsage(usage: AgentUsage | undefined): void;Parameters
usage· requiredAgentUsage | undefined
Returns
voidstopCount
readonly stopCount: number;stream · overload 1
Starts a streaming assistant message and sets status 'running'.
stream(options?: {
readonly id?: string;
readonly text?: string;
}): FakeAssistantStream;Parameters
options· optional{ readonly id?: string; readonly text?: string; }
Returns
FakeAssistantStreamsubmits
Submissions in call order, including ones the handler rejected.
readonly submits: readonly FakeSubmitCall<TState>[];