FakeAgentSession

Unpublished development API. This package is under development and is not available as a published release.

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

import type { FakeAgentSession } from '@threadplane/core/testing';

Declaration

export interface FakeAgentSession<TTools extends {
    [K in keyof TTools]: ToolContract;
} = Record<string, ToolContract>>  {
  readonly disposed: boolean;
  onSubmit(handler: FakeSubmitHandler<TTools> | undefined): void;
  push(message: FakeMessageInput): Message;
  readonly session: AgentSession<TTools>;
  set(patch: FakeAgentSnapshotPatch<TTools>): void;
  setError(error: AgentError | undefined): void;
  setStatus(status: AgentStatus): void;
  setToolCalls(toolCalls: readonly ToolCall<TTools>[]): void;
  readonly stopCount: number;
  stream(options?: {
        readonly id?: string;
        readonly text?: string;
    }): FakeAssistantStream;
  readonly submits: readonly FakeSubmitCall[];
}

Type parameters

TTools
{ [K in keyof TTools]: ToolContract; } Default: Record<string, ToolContract>

Members

disposed

readonly disposed: boolean;

onSubmit · overload 1

Replaces the handler used by later submissions.

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

Parameters

handler · required
FakeSubmitHandler<TTools> | 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

session

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

readonly session: AgentSession<TTools>;

set · overload 1

Replaces the listed snapshot fields and notifies subscribers once.

set(patch: FakeAgentSnapshotPatch<TTools>): void;

Parameters

patch · required
FakeAgentSnapshotPatch<TTools>

Returns

void

setError · overload 1

Publishes the error with status 'error'; undefined clears it and returns an errored session to 'idle'.

setError(error: AgentError | undefined): void;

Parameters

error · required
AgentError | undefined

Returns

void

setStatus · overload 1

setStatus(status: AgentStatus): void;

Parameters

status · required
AgentStatus

Returns

void

setToolCalls · overload 1

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

Parameters

toolCalls · required
readonly ToolCall<TTools>[]

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[];