Interface IHistoryInstanceCallbacks

Callbacks for managing history instance lifecycle and message handling.

interface IHistoryInstanceCallbacks {
    filterCondition?: (
        message: IModelMessage,
        clientId: string,
        agentName: string,
    ) => boolean | Promise<boolean>;
    getData: (
        clientId: string,
        agentName: string,
    ) => IModelMessage<object>[] | Promise<IModelMessage<object>[]>;
    getSystemPrompt?: (
        clientId: string,
        agentName: string,
    ) => string[] | Promise<string[]>;
    onChange: (
        data: IModelMessage<object>[],
        clientId: string,
        agentName: string,
    ) => void;
    onDispose: (clientId: string) => void;
    onInit: (clientId: string) => void;
    onPop: (
        data: IModelMessage<object>,
        clientId: string,
        agentName: string,
    ) => void;
    onPush: (data: IModelMessage, clientId: string, agentName: string) => void;
    onRead: (
        message: IModelMessage,
        clientId: string,
        agentName: string,
    ) => void;
    onReadBegin: (clientId: string, agentName: string) => void;
    onReadEnd: (clientId: string, agentName: string) => void;
    onRef: (history: IHistoryInstance) => void;
}

Properties

filterCondition?: (
    message: IModelMessage,
    clientId: string,
    agentName: string,
) => boolean | Promise<boolean>

Determines whether a message should be included in the history iteration.

getData: (
    clientId: string,
    agentName: string,
) => IModelMessage<object>[] | Promise<IModelMessage<object>[]>

Fetches initial history data for an agent.

getSystemPrompt?: (
    clientId: string,
    agentName: string,
) => string[] | Promise<string[]>

Retrieves dynamic system prompt messages for an agent.

onChange: (
    data: IModelMessage<object>[],
    clientId: string,
    agentName: string,
) => void

Called when the history array changes (e.g., after push or pop).

onDispose: (clientId: string) => void

Called when the history instance is disposed.

onInit: (clientId: string) => void

Called when the history instance is initialized.

onPop: (
    data: IModelMessage<object>,
    clientId: string,
    agentName: string,
) => void

Called when the last message is popped from the history.

onPush: (data: IModelMessage, clientId: string, agentName: string) => void

Called when a new message is pushed to the history.

onRead: (message: IModelMessage, clientId: string, agentName: string) => void

Called for each message during iteration when reading.

onReadBegin: (clientId: string, agentName: string) => void

Called at the start of a history read operation.

onReadEnd: (clientId: string, agentName: string) => void

Called at the end of a history read operation.

onRef: (history: IHistoryInstance) => void

Provides a reference to the history instance after creation.