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>
TState
Default: 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 · required
string
data · optional
PlainValue

Returns

void

flushCount

readonly flushCount: number;

onResume · overload 1

Replaces the handler used by later resumes.

onResume(handler: FakeResumeHandler<TTools, TState> | undefined): void;

Parameters

handler · required
FakeResumeHandler<TTools, TState> | undefined

Returns

void

onSubmit · overload 1

Replaces the handler used by later submissions.

onSubmit(handler: FakeSubmitHandler<TTools, TState> | undefined): void;

Parameters

handler · required
FakeSubmitHandler<TTools, TState> | undefined

Returns

void

push · overload 1

Appends one message and returns the owned, frozen copy.

push(message: FakeMessageInput): Message;

Parameters

message · required
FakeMessageInput

Returns

Message

regenerates

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 · required
FakeAgentSnapshotPatch<TTools, TState>

Returns

void

setCheckpoints · 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 · required
readonly AgentCheckpoint[] | undefined
messageCheckpoints · optional
Readonly<Record<string, string>>

Returns

void

setError · 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 · required
AgentError | undefined
cause · optional
unknown

Returns

void

setInterrupts · overload 1

Replaces the pending interrupts; undefined removes the field.

setInterrupts(interrupts: readonly AgentInterrupt[] | undefined): void;

Parameters

interrupts · required
readonly AgentInterrupt[] | undefined

Returns

void

setState · overload 1

Replaces the state; undefined removes it. Throws when a schema stateType rejects it.

setState(state: NoInfer<TState> | undefined): void;

Parameters

state · required
NoInfer<TState> | undefined

Returns

void

setStatus · overload 1

setStatus(status: AgentStatus): void;

Parameters

status · required
AgentStatus

Returns

void

setSubagents · overload 1

Replaces the child agents; undefined removes the field.

setSubagents(subagents: readonly FakeSubagentInput[] | undefined): void;

Parameters

subagents · required
readonly FakeSubagentInput[] | undefined

Returns

void

setToolCalls · overload 1

setToolCalls(toolCalls: readonly ToolCall<TTools>[]): void;

Parameters

toolCalls · required
readonly ToolCall<TTools>[]

Returns

void

setUsage · overload 1

Replaces the reported usage; undefined removes the field.

setUsage(usage: AgentUsage | undefined): void;

Parameters

usage · required
AgentUsage | undefined

Returns

void

stopCount

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

FakeAssistantStream

submits

Submissions in call order, including ones the handler rejected.

readonly submits: readonly FakeSubmitCall<TState>[];