Ir al contenido

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 →

Historial de hilosHistorial de hilos
  • En un panel lateral o un popover de una app de chat, para volver a abrir una conversación anterior.
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))

Las de búsqueda se dibujan con texto escrito en la caja (el componente lo guarda).

Historial de hilos: Agrupado por díaHistorial de hilos: Agrupado por día
Agrupado por día
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)
Historial de hilos: selected="2"Historial de hilos: selected="2"
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)
Historial de hilos: Sin hilosHistorial de hilos: Sin hilos
Sin hilos
Código
pz.container(ui.ThreadHistory(threads=[]), width=320, height=110)
Historial de hilos: BuscandoHistorial de hilos: Buscando
Buscando
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)
Historial de hilos: Sin coincidenciasHistorial de hilos: Sin coincidencias
Sin coincidencias
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)

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().

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]
class ThreadHistory

Un 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).

Referencia completa →