import { html, nothing } from 'lit'; import { LightElement } from '../lib/base.js'; const PAGE_ID = 'tic'; const PER_PAGE = 20; function formatDate(iso) { if (!iso) return '—'; return new Date(iso).toLocaleString(undefined, { day: '2-digit', month: '2-digit', year: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit', }); } function formatDateShort(iso) { if (!iso) return '—'; return new Date(iso).toLocaleString(undefined, { day: '2-digit', month: '2-digit', year: '2-digit', hour: '2-digit', minute: '2-digit', }); } export class TicSessionsPage extends LightElement { static properties = { _open: { state: true }, _items: { state: true }, _total: { state: true }, _page: { state: true }, _loading: { state: true }, _error: { state: true }, }; constructor() { super(); this._open = false; this._items = []; this._total = 0; this._page = 1; this._loading = false; this._error = null; } connectedCallback() { super.connectedCallback(); window.addEventListener('llm-page-change', (e) => { this._open = e.detail.page === PAGE_ID; this.style.display = this._open ? 'flex' : 'none'; if (this._open && this._items.length === 0) this._fetch(1); }); } async _fetch(page) { this._loading = true; this._error = null; try { const params = new URLSearchParams({ source: 'tic', page, per_page: PER_PAGE }); const res = await fetch(`/api/sessions?${params}`); if (!res.ok) throw new Error(`HTTP ${res.status}`); const data = await res.json(); this._items = data.items; this._total = data.total; this._page = data.page; } catch (e) { this._error = e.message; } finally { this._loading = false; } } _openSession(id) { window.location.hash = `session/${id}`; } get _totalPages() { return Math.max(1, Math.ceil(this._total / PER_PAGE)); } _renderTable() { if (this._loading) return html`
| # | Agent | Started | Messages | Last activity |
|---|---|---|---|---|
| ${r.id} | ${r.agent_id ?? '—'} | ${formatDateShort(r.created_at)} | ${r.message_count} | ${formatDate(r.last_message_at)} |