# FakeAgentSession

Package: `@threadplane/angular/chat/testing` · 0.3.7

Reference: /docs/api/angular/chat/testing/FakeAgentSession

```typescript
import type { FakeAgentSession } from '@threadplane/angular/chat/testing';
```

## FakeAgentSession

A fake session and the controls a test uses to drive it.

```typescript
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>[];
}
```

### catalogs

Every catalog given to `clientTools.setCatalog`, in order; the last is current.

```typescript
readonly catalogs: readonly (readonly ClientToolSpec[])[];
```

### checkStatusCount

```typescript
readonly checkStatusCount: number;
```

### clientToolResults

Results given through `clientTools.settle` and `clientTools.resolve`, in order.

```typescript
readonly clientToolResults: readonly FakeClientToolSettlement[];
```

### disposed

```typescript
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.

```typescript
emitCustomEvent(name: string, data?: PlainValue): void;
```

### flushCount

```typescript
readonly flushCount: number;
```

### onResume · overload 1

Replaces the handler used by later resumes.

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

### onSubmit · overload 1

Replaces the handler used by later submissions.

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

### push · overload 1

Appends one message and returns the owned, frozen copy.

```typescript
push(message: FakeMessageInput): Message;
```

### regenerates

Calls to `regenerate` in order, including rejected ones.

```typescript
readonly regenerates: readonly FakeRegenerateCall[];
```

### resumes

Resumes in call order, including ones the fake or the handler rejected.

```typescript
readonly resumes: readonly FakeResumeCall<TState>[];
```

### retryCount

```typescript
readonly retryCount: number;
```

### runs

Calls to `runWithoutMessage` in order.

```typescript
readonly runs: readonly FakeRunCall<TState>[];
```

### session

Pass this to `Chat`, `useAgent`, or any other session consumer.

```typescript
readonly session: AgentSession<TTools, TState>;
```

### set · overload 1

Replaces the listed snapshot fields and notifies subscribers once.

```typescript
set(patch: FakeAgentSnapshotPatch<TTools, TState>): void;
```

### setCheckpoints · overload 1

Replaces the loaded history and, when given, the message-to-checkpoint
map; `undefined` removes both.

```typescript
setCheckpoints(checkpoints: readonly AgentCheckpoint[] | undefined, messageCheckpoints?: Readonly<Record<string, string>>): 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.

```typescript
setError(error: AgentError | undefined, cause?: unknown): void;
```

### setInterrupts · overload 1

Replaces the pending interrupts; `undefined` removes the field.

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

### setState · overload 1

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

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

### setStatus · overload 1

```typescript
setStatus(status: AgentStatus): void;
```

### setSubagents · overload 1

Replaces the child agents; `undefined` removes the field.

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

### setToolCalls · overload 1

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

### setUsage · overload 1

Replaces the reported usage; `undefined` removes the field.

```typescript
setUsage(usage: AgentUsage | undefined): void;
```

### stopCount

```typescript
readonly stopCount: number;
```

### stream · overload 1

Starts a streaming assistant message and sets status `'running'`.

```typescript
stream(options?: {
        readonly id?: string;
        readonly text?: string;
    }): FakeAssistantStream;
```

### submits

Submissions in call order, including ones the handler rejected.

```typescript
readonly submits: readonly FakeSubmitCall<TState>[];
```