panelini.panels.ai.history.document¶
Document-shaped chat history: schema, converters, shared store logic.
The documents defined by chat_history_schema.json (an OO-LD document:
JSON-Schema plus a JSON-LD @context) are both the storage model and the
import/export interchange format. :class:DocumentHistoryStore
implements every :class:~.store.ChatHistoryStore semantic once, on top of
a minimal per-document CRUD that each backend provides.
Module Contents¶
Classes¶
Implements every store semantic over a minimal document CRUD. |
|
Thread-safe in-memory backend for tests, stubs, and Pyodide builds. |
Functions¶
Return the bundled chat history document schema. |
|
Return the schema’s JSON-LD |
|
Validate a conversation document against the v2 schema. |
|
Validate a folder document against the v2 schema. |
|
Return the embedded-message dict for one message record. |
|
Compose the v2 conversation document from records. |
|
Extract the conversation record (without messages) from a document. |
|
Extract the embedded message records from a conversation document. |
|
Compose the folder document from a record. |
|
Extract the folder record from a document. |
Data¶
API¶
- panelini.panels.ai.history.document.SCHEMA_VERSION¶
2
- panelini.panels.ai.history.document.KIND_CONVERSATION¶
‘conversation’
- panelini.panels.ai.history.document.KIND_FOLDER¶
‘folder’
- panelini.panels.ai.history.document.load_schema() dict[str, Any][source]¶
Return the bundled chat history document schema.
- panelini.panels.ai.history.document.document_context() dict[str, Any][source]¶
Return the schema’s JSON-LD
@contextblock.
- panelini.panels.ai.history.document.validate_conversation_document(document: dict[str, Any]) None[source]¶
Validate a conversation document against the v2 schema.
Raises: ValueError: When the document does not match the schema.
- panelini.panels.ai.history.document.validate_folder_document(document: dict[str, Any]) None[source]¶
Validate a folder document against the v2 schema.
Raises: ValueError: When the document does not match the schema.
- panelini.panels.ai.history.document.message_to_dict(record: panelini.panels.ai.history.store.MessageRecord) dict[str, Any][source]¶
Return the embedded-message dict for one message record.
- panelini.panels.ai.history.document.conversation_to_document(record: panelini.panels.ai.history.store.ConversationRecord, messages: collections.abc.Sequence[panelini.panels.ai.history.store.MessageRecord] = ()) dict[str, Any][source]¶
Compose the v2 conversation document from records.
- panelini.panels.ai.history.document.conversation_from_document(document: dict[str, Any]) panelini.panels.ai.history.store.ConversationRecord[source]¶
Extract the conversation record (without messages) from a document.
- panelini.panels.ai.history.document.messages_from_document(document: dict[str, Any]) list[panelini.panels.ai.history.store.MessageRecord][source]¶
Extract the embedded message records from a conversation document.
- panelini.panels.ai.history.document.folder_to_document(record: panelini.panels.ai.history.store.FolderRecord) dict[str, Any][source]¶
Compose the folder document from a record.
- panelini.panels.ai.history.document.folder_from_document(document: dict[str, Any]) panelini.panels.ai.history.store.FolderRecord[source]¶
Extract the folder record from a document.
- class panelini.panels.ai.history.document.DocumentHistoryStore[source]¶
Bases:
panelini.panels.ai.history.store.ChatHistoryStoreImplements every store semantic over a minimal document CRUD.
Backends provide only :meth:
_get, :meth:_put, :meth:_delete,- Meth:
_iter(all scoped byuser_id) and :meth:_transaction, a context manager making the enclosed read-modify-write atomic.
- list_conversations(user_id: str, include_archived: bool = False) list[panelini.panels.ai.history.store.ConversationRecord][source]¶
- search_conversations(user_id: str, query: str, include_archived: bool = False) list[panelini.panels.ai.history.store.ConversationRecord][source]¶
- get_conversation(user_id: str, conversation_id: str) panelini.panels.ai.history.store.ConversationRecord | None[source]¶
- create_conversation(user_id: str, title: str = DEFAULT_TITLE, folder_ids: collections.abc.Sequence[str] = ()) panelini.panels.ai.history.store.ConversationRecord[source]¶
- append_message(user_id: str, conversation_id: str, role: str, content: str, extra: dict[str, Any] | None = None, parent_message_id: str | None = None) panelini.panels.ai.history.store.MessageRecord[source]¶
- load_messages(user_id: str, conversation_id: str) list[panelini.panels.ai.history.store.MessageRecord][source]¶
- restore_conversation(user_id: str, document: dict[str, Any]) None[source]¶
Re-put a conversation document as-is (lossless delete-undo).
The restoring user becomes the owner regardless of the document’s
user_id.
- list_folders(user_id: str) list[panelini.panels.ai.history.store.FolderRecord][source]¶
- class panelini.panels.ai.history.document.InMemoryHistoryStore[source]¶
Bases:
panelini.panels.ai.history.document.DocumentHistoryStoreThread-safe in-memory backend for tests, stubs, and Pyodide builds.
Documents are copied on the way in and out, mirroring the serialization boundary a browser object store would impose.
Initialization