Historial de hilos
ui.ThreadHistory es un componente para conversaciones pasadas: un buscador y los hilos agrupados según cuándo se actualizaron (Hoy, Ayer, Esta semana, Este mes, Antes). Cada fila muestra el título, un detail opcional (el modelo o el agente) y un botón para borrarlo. threads son diccionarios u objetos con id, title, updated (una marca de time.time()) y detail; selected marca el que está abierto. Elegir un hilo llega a on_open y el botón de la papelera a on_delete, los dos con el id del hilo en event.value. El componente guarda el texto de búsqueda por su cuenta.
ui.ThreadHistory · Categoría: Agentes de IA · Referencia completa →


import time
now = time.time()pz.container(ui.ThreadHistory(threads=[ {"id": "1", "title": "Add a login form", "updated": now - 60, "detail": "Claude"}, {"id": "2", "title": "Fix the failing tests", "updated": now - 900, "detail": "Claude"}, {"id": "3", "title": "Dark theme for the settings", "updated": now - 86400, "detail": "Gemini CLI"}, {"id": "4", "title": "Export the table to CSV", "updated": now - 4 * 86400}, {"id": "5", "title": "First steps", "updated": now - 60 * 86400},], selected="1", on_open=on_open, on_delete=on_delete), width=380, height=320)Cuándo usarlo
Sección titulada «Cuándo usarlo»- En un panel lateral o un popover de una app de chat, para volver a abrir una conversación anterior.
import pyzed as pzfrom 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))Variantes
Sección titulada «Variantes»Las de búsqueda se dibujan con texto escrito en la caja (el componente lo guarda).


Código
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)

selected="2"Código
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)

Código
pz.container(ui.ThreadHistory(threads=[]), width=320, height=110)

Código
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)

Código
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)Eventos
Sección titulada «Eventos»Historial de hilos tiene 2 eventos propios, en la tabla de abajo. Como todo widget, también tiene los 18 eventos comunes (click, double_click, right_click, mouse_enter, drag, key_down, resize…), que se conectan con .on(...): mira Eventos y Eventos de cada componente.
Es un pz.Component, así que también lanza on_mount y on_unmount, y sus handlers reciben un pz.Event cuyo value trae el dato.
| Evento | El handler recibe | Cuándo |
|---|---|---|
on_open |
(event) |
Se eligió un hilo (event.value es su id). |
on_delete |
(event) |
Se pulsó eliminar en un hilo. |
El handler recibe es lo que Pyzed le pasa a tu función: () es nada. Cualquier handler también puede ser un mensaje (un valor que no se puede llamar), que va a update().
Manejar los eventos
Sección titulada «Manejar los eventos»Los mismos eventos escritos de tres formas. Imperativa: métodos de la app que cambian self. Declarativa: los handlers producen mensajes y un único update() decide. Funcional: una función pura dibuja un estado inmutable y pide cambios con set_state(...). Mira Imperativo, declarativo y funcional.
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]from dataclasses import dataclass
@dataclassclass OpenThread: ident: str
@dataclassclass DeleteThread: ident: str
class Chats(pz.App): threads = [{"id": "1", "title": "Add a login form", "updated": 0}] open_id = ""
def update(self, message): match message: case OpenThread(ident): self.open_id = ident case DeleteThread(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: OpenThread(e.value), on_delete=lambda e: DeleteThread(e.value))from dataclasses import dataclass
@dataclass(frozen=True)class State: threads: tuple = ({"id": "1", "title": "Add a login form", "updated": 0},) open_id: str = ""
def view(state, set_state): return ui.ThreadHistory( threads=list(state.threads), selected=state.open_id, on_open=lambda e: set_state(open_id=e.value), on_delete=lambda e: set_state(threads=tuple(t for t in state.threads if t["id"] != e.value)))Propiedades y API
Sección titulada «Propiedades y API»ui.ThreadHistory
Sección titulada «ui.ThreadHistory»class ThreadHistoryUn componente para conversaciones anteriores: un buscador y los hilos agrupados por día (Hoy, Ayer, Esta semana, Este mes, Antes), cada uno con un botón para eliminarlo.
| Propiedad | Por defecto | Descripción |
|---|---|---|
threads |
None |
Dicts u objetos con id, title, updated (una marca de tiempo) y un detail opcional. |
selected |
"" |
El id del hilo abierto. |
theme |
None |
Tema. |
Eventos: on_open, on_delete (eventos).