Alpha ZealPHP is early-stage and under active development. APIs may change between minor versions until v1.0. Feedback and bug reports welcome on GitHub.
API Index — Namespaces, Packages, Reports, Indices

ChatHistory
in package

Data-access helpers for the chat_history table used by the Learn module.

Each row stores one conversational turn: a role ("user" or "assistant"), an array of content items (serialised as JSON), and a thread_id that groups turns into a logical conversation. All methods are stateless static helpers that accept a \PDO instance so callers control the connection lifetime.

Table of Contents

Methods

append()  : int
Append one conversational turn to the chat_history table.
forThread()  : array<int, array<string, mixed>>
Fetch all turns for a thread in chronological order.
threads()  : array<int, array<string, mixed>>
List the most recent threads for a user, newest first.

Methods

append()

Append one conversational turn to the chat_history table.

public static append(PDO $db, int $userId, string $threadId, string $role, array<int, array<string, mixed>> $items) : int
Parameters
$db : PDO
$userId : int
$threadId : string
$role : string
$items : array<int, array<string, mixed>>

Content items for this turn (e.g. text blocks, tool results).

Return values
int

The auto-increment id of the inserted row.

forThread()

Fetch all turns for a thread in chronological order.

public static forThread(PDO $db, int $userId, string $threadId) : array<int, array<string, mixed>>
Parameters
$db : PDO
$userId : int
$threadId : string
Return values
array<int, array<string, mixed>>

Rows ordered by created_at ASC, id ASC.

threads()

List the most recent threads for a user, newest first.

public static threads(PDO $db, int $userId[, int $limit = 10 ]) : array<int, array<string, mixed>>

Each row contains thread_id, last_at (Unix timestamp of the latest turn), and turns (total turn count for that thread).

Parameters
$db : PDO
$userId : int
$limit : int = 10
Return values
array<int, array<string, mixed>>
On this page