Skip to content

Thread history

ui.ThreadHistory is a component for past conversations: a search box and the threads grouped by when they were last updated (Today, Yesterday, This week, This month, Older). Each row shows the title, an optional detail (the model or the agent) and a delete button. threads are dicts or objects with id, title, updated (a time.time() timestamp) and detail; selected marks the open one. Picking a thread reports on_open and the trash button on_delete, both with the thread’s id in event.value. The component keeps the search text itself.

ui.ThreadHistory · Category: AI agents · Full reference →

Thread historyThread history
  • In a side panel or a popover of a chat app, to reopen an earlier conversation.
import pyzed as pz
from pyzed import ui
class Chats(pz.App):
def __init__(self):
self.threads = load_threads() # [{"id", "title", "updated", "detail"}, ...]
self.open_id = ""
def delete(self, ident):
self.threads = [t for t in self.threads if t["id"] != ident]
def view(self):
return ui.ThreadHistory(threads=self.threads, selected=self.open_id,
on_open=lambda e: setattr(self, "open_id", e.value),
on_delete=lambda e: self.delete(e.value))

The search ones are drawn with text typed in the box (the component keeps it).

Thread history: Grouped by dayThread history: Grouped by day
Grouped by day
Code
import time
now = time.time()
threads = [
{"id": "1", "title": "Add a login form", "updated": now - 60, "detail": "Claude"},
{"id": "2", "title": "Fix the failing tests", "updated": now - 86400},
{"id": "3", "title": "Export the table to CSV", "updated": now - 4 * 86400},
]
pz.container(ui.ThreadHistory(threads=threads), width=320, height=260)
Thread history: selected="2"Thread history: selected="2"
selected="2"
Code
import time
now = time.time()
threads = [
{"id": "1", "title": "Add a login form", "updated": now - 60, "detail": "Claude"},
{"id": "2", "title": "Fix the failing tests", "updated": now - 86400},
{"id": "3", "title": "Export the table to CSV", "updated": now - 4 * 86400},
]
pz.container(ui.ThreadHistory(threads=threads, selected="2"), width=320, height=260)
Thread history: No threadsThread history: No threads
No threads
Code
pz.container(ui.ThreadHistory(threads=[]), width=320, height=110)
Thread history: SearchingThread history: Searching
Searching
Code
import time
now = time.time()
threads = [
{"id": "1", "title": "Add a login form", "updated": now - 60, "detail": "Claude"},
{"id": "2", "title": "Fix the failing tests", "updated": now - 86400},
{"id": "3", "title": "Export the table to CSV", "updated": now - 4 * 86400},
]
pz.container(ui.ThreadHistory(threads=threads), width=320, height=160)
Thread history: Nothing matchesThread history: Nothing matches
Nothing matches
Code
import time
now = time.time()
threads = [
{"id": "1", "title": "Add a login form", "updated": now - 60, "detail": "Claude"},
{"id": "2", "title": "Fix the failing tests", "updated": now - 86400},
{"id": "3", "title": "Export the table to CSV", "updated": now - 4 * 86400},
]
pz.container(ui.ThreadHistory(threads=threads), width=320, height=110)

Thread history has 2 events of its own, listed below. Like every widget it also has the 18 common events (click, double_click, right_click, mouse_enter, drag, key_down, resize…), attached with .on(...): see Events and Events of every component.

It is a pz.Component, so it also raises on_mount and on_unmount, and its handlers get a pz.Event whose value holds the data.

Event Handler gets When
on_open (event) A thread was picked (event.value is its id).
on_delete (event) Delete was pressed on a thread.

Handler gets is what Pyzed passes to your callable: () means nothing. Any handler can also be a message (a value that is not callable), which goes to update().

The same events written three ways. Imperative: methods of the app change self. Declarative: the handlers produce messages and one update() decides. Functional: a pure function draws an immutable state and asks for changes with set_state(...). See Imperative, declarative and functional.

import time
class Chats(pz.App):
def __init__(self):
now = time.time()
self.threads = [{"id": "1", "title": "Add a login form", "updated": now - 60},
{"id": "2", "title": "Fix the tests", "updated": now - 900}]
self.open_id = "1"
def view(self): # event.value is the thread's id
return ui.ThreadHistory(threads=self.threads, selected=self.open_id,
on_open=lambda e: setattr(self, "open_id", e.value),
on_delete=lambda e: self.delete(e.value))
def delete(self, ident):
self.threads = [t for t in self.threads if t["id"] != ident]
class ThreadHistory

A component for past conversations: a search box and the threads grouped by day (Today, Yesterday, This week, This month, Older), each with a delete button.

Property Default Description
threads None Dicts or objects with id, title, updated (a timestamp) and an optional detail.
selected "" The id of the open thread.
theme None Theme.

Events: on_open, on_delete (events).

Full reference →