A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
feat(editor): earlier conversations, and picking one back up
esengine36b549c29780
diff --git a/desktop/src/components/AgentDrawer.tsx b/desktop/src/components/AgentDrawer.tsxindex ed7b565f2..0f182f086 100644--- a/desktop/src/components/AgentDrawer.tsx+++ b/desktop/src/components/AgentDrawer.tsx@@ -27,13 +27,13 @@ import { memo, useCallback, useEffect, useLayoutEffect, useRef, useState, useSynimport {X, Plus, PanelRight, ArrowUp, Square, ChevronRight, ChevronDown, Check, TriangleAlert,Loader, Copy, Pencil, Eye, KeyRound, Boxes, Stethoscope, Image as ImageIcon, RotateCcw,- File as FileIcon, ArrowRight,+ File as FileIcon, ArrowRight, History as HistoryIcon, Trash2,} from 'lucide-react';import { useEditorStore } from '@/store/editorStore';import {useAgent, sendAgentMessage, stopAgentTurn, confirmAgentCall, startNewConversation,peekEntities, entitiesInInput, effectiveSelection, selectAgentModel, retryAgentTurn, setAgentDraft,- RESUMABLE,+ RESUMABLE, openAgentHistory, closeAgentHistory, resumeConversation, forgetConversation,type AgentTurn, type AgentEntry, type AgentToolEntry, type AgentProseEntry,} from '@/store/AgentStore';import type { ConfirmAnswer } from '../../electron/agent/types';@@ -703,6 +703,78 @@ const Turn = memo(function Turn({ turn, isLast, running, until }: {);});+/**+ * The conversations this project has had.+ *+ * Over the transcript rather than beside it: picking one REPLACES what is on+ * screen, and a list that sat alongside would suggest you could read both. Esc+ * goes back, so opening it costs nothing.+ */+function History() {+ const conversations = useAgent((s) => s.conversations);+ const current = useAgent((s) => s.turns.length > 0);+ useEffect(() => {+ const onKey = (e: KeyboardEvent) => {+ if (e.key !== 'Escape') return;+ e.stopPropagation(); // Esc closes the history, not the drawer behind it+ closeAgentHistory();+ };+ window.addEventListener('keydown', onKey, true);+ return () => window.removeEventListener('keydown', onKey, true);+ }, []);++ return (+ <div className="ag-history">+ <div className="ag-history-h">+ <span>{t('agent.history.title')}</span>+ <span className="ag-sp" />+ <button type="button" title={t('agent.history.close')} onClick={closeAgentHistory}>+ <X size={13} strokeWidth={2} />+ </button>+ </div>+ {conversations.length === 0 ? (+ <div className="ag-history-none">{t('agent.history.none')}</div>+ ) : (+ <div className="ag-history-l">+ {conversations.map((c) => (+ <div className="ag-hrow" key={c.id}>+ <button type="button" className="ag-hrow-go" onClick={() => void resumeConversation(c.id)}>+ <span className="ag-hrow-t">{c.title || t('agent.history.untitled')}</span>+ <span className="ag-hrow-m">+ {relativeDay(c.updatedAt)}+ <span className="ag-hrow-n">{t('agent.history.turns', { count: c.turns })}</span>+ <span className="ag-hrow-model">{c.model}</span>+ </span>+ </button>+ {/* Quiet until the row is hovered — it destroys something. */}+ <button+ type="button"+ className="ag-hrow-x"+ title={t('agent.history.forget')}+ onClick={() => void forgetConversation(c.id)}+ >+ <Trash2 size={12} strokeWidth={1.9} />+ </button>+ </div>+ ))}+ </div>+ )}+ {/* Said here because the list is where someone would look for it: what is+ on screen now is not in the list until its next turn ends. */}+ {current && <div className="ag-history-note">{t('agent.history.currentNote')}</div>}+ </div>+ );+}++/** Today / yesterday / a date — a timestamp is not what anyone is scanning for. */+function relativeDay(at: number): string {+ const day = 86_400_000;+ const midnight = new Date().setHours(0, 0, 0, 0);+ if (at >= midnight) return t('agent.history.today');+ if (at >= midnight - day) return t('agent.history.yesterday');+ return new Date(at).toLocaleDateString();+}+function EmptyState() {const ready = useAgent((s) => s.status.ready);const openSettings = useEditorStore((s) => s.openSettings);@@ -1008,6 +1080,7 @@ export function AgentPanel({ docked }: { docked?: boolean }) {const turns = useAgent((s) => s.turns);const status = useAgent((s) => s.status);const queued = useAgent((s) => s.queued);+ const historyOpen = useAgent((s) => s.historyOpen);const logRef = useRef<HTMLDivElement>(null);const stuck = useRef(true);// A question that has scrolled away is a turn that looks hung. Watched per@@ -1041,6 +1114,14 @@ export function AgentPanel({ docked }: { docked?: boolean }) {<AgentMark size={docked ? 13 : 15} live={status.phase !== 'idle'} />{!docked && <span className="ag-ttl">{t('agent.title')}</span>}<span className="ag-sp" />+ <button+ type="button"+ className={historyOpen ? 'on' : undefined}+ title={t('agent.history.open')}+ onClick={() => (historyOpen ? closeAgentHistory() : openAgentHistory())}+ >+ <HistoryIcon size={14} strokeWidth={1.9} />+ </button><button type="button" title={t('agent.newConversation')} onClick={() => void startNewConversation()}><Plus size={14} strokeWidth={2} /></button>@@ -1079,7 +1160,7 @@ export function AgentPanel({ docked }: { docked?: boolean }) {{turns.length > 0 && turns[0].id > 0 && (<div className="ag-sys">{t('agent.earlier', { count: turns[0].id })}</div>)}- {turns.length === 0+ {historyOpen ? <History /> : turns.length === 0? <EmptyState />: turns.map((turn, i) => (<Turndiff --git a/desktop/src/i18n/messages/agent.ts b/desktop/src/i18n/messages/agent.tsindex df2e0c2f7..63ccad5d5 100644--- a/desktop/src/i18n/messages/agent.ts+++ b/desktop/src/i18n/messages/agent.ts@@ -29,6 +29,24 @@ export const agentMessages = defineMessages({'agent.hint.mention': { en: 'reference', zh: '引用' },'agent.mention': { en: 'Reference', zh: '引用' },+ // — Conversations this project has had —+ 'agent.history.open': { en: 'Earlier conversations', zh: '历史对话' },+ 'agent.history.title': { en: 'Earlier conversations', zh: '历史对话' },+ 'agent.history.close': { en: 'Back (Esc)', zh: '返回 (Esc)' },+ 'agent.history.none': {+ en: 'Nothing kept yet. A conversation is saved with the project once a run finishes.',+ zh: '还没有保存的对话。一轮跑完后,对话会随项目一起保存。',+ },+ 'agent.history.untitled': { en: '(no question yet)', zh: '(还没有提问)' },+ 'agent.history.turns': { en: '{count} runs', zh: '{count} 轮' },+ 'agent.history.today': { en: 'today', zh: '今天' },+ 'agent.history.yesterday': { en: 'yesterday', zh: '昨天' },+ 'agent.history.forget': { en: 'Forget this conversation', zh: '删除这段对话' },+ 'agent.history.currentNote': {+ en: 'The conversation on screen joins this list when its next run ends.',+ zh: '当前这段会在下一轮结束时进入列表。',+ },+// — Ending a conversation, on purpose or as the price of a switch —'agent.new.title': { en: 'Start a new conversation?', zh: '开始新对话?' },'agent.new.body': {diff --git a/desktop/src/store/AgentStore.ts b/desktop/src/store/AgentStore.tsindex b286baa18..845409578 100644--- a/desktop/src/store/AgentStore.ts+++ b/desktop/src/store/AgentStore.ts@@ -142,13 +142,62 @@ interface AgentState {checkpointDone: number | null;/** What the user picked, or null for "whichever provider has a key". */selection: AgentSelection | null;+ /**+ * Conversations saved with this project, newest first, and whether the list+ * is showing. Read on demand rather than kept in step: the only thing that+ * writes them is main, at the end of a turn.+ */+ conversations: readonly ConversationSummary[];+ historyOpen: boolean;+}++/** One saved conversation as the list shows it (electron/agent/store.ts). */+export interface ConversationSummary {+ id: string;+ startedAt: number;+ updatedAt: number;+ title: string;+ model: string;+ turns: number;}export const useAgent = create<AgentState>(() => ({status: IDLE, turns: [], driving: false, peeked: [], queued: [], checkpointDone: null,- draft: '', selection: loadSelection(),+ draft: '', selection: loadSelection(), conversations: [], historyOpen: false,}));+// ── Conversations kept with the project ─────────────────────────────────────++/** Re-read the list. Called when the history opens, and after it changes. */+export async function refreshConversations(): Promise<void> {+ const conversations = await window.estella?.agent?.conversations?.() ?? [];+ useAgent.setState({ conversations });+}++export function openAgentHistory(): void {+ useAgent.setState({ historyOpen: true });+ void refreshConversations();+}++export const closeAgentHistory = (): void => useAgent.setState({ historyOpen: false });++/**+ * Carry on a saved conversation. The transcript arrives as a replayed event+ * stream (the same path an attaching window takes), so nothing here rebuilds it+ * — main pushes `conversation_reset` and then every event, and the projection+ * does the rest.+ */+export async function resumeConversation(id: string): Promise<void> {+ useAgent.setState({ historyOpen: false, queued: [], checkpointDone: null });+ const status = await window.estella?.agent?.resumeConversation?.(id);+ if (status) adoptStatus(status);+}++export async function forgetConversation(id: string): Promise<void> {+ await window.estella?.agent?.deleteConversation?.(id);+ await refreshConversations();+}+export const peekEntities = (ids: readonly number[]): void => useAgent.setState({ peeked: ids });export const setAgentDraft = (draft: string): void => useAgent.setState({ draft });diff --git a/desktop/src/theme/agent.css b/desktop/src/theme/agent.cssindex aad7dcb61..3fd9a182e 100644--- a/desktop/src/theme/agent.css+++ b/desktop/src/theme/agent.css@@ -403,6 +403,67 @@.ag-skel.s3 { width: 56%; }@keyframes ag-shimmer { from { background-position: 120% 0; } to { background-position: -120% 0; } }+/* ── Earlier conversations ───────────────────────────────────────────────────+ Over the transcript, not beside it: picking one REPLACES what is on screen,+ and a list sitting alongside would suggest you could have both. */+.ag-history { display: flex; flex-direction: column; min-height: 0; }+.ag-history-h {+ display: flex; align-items: center; gap: 8px;+ padding: 11px 14px 9px;+ font: 500 var(--fs-2xs) var(--font-ui);+ letter-spacing: 0.09em;+ text-transform: uppercase;+ color: var(--text-faint);+ border-bottom: 1px solid var(--line);+}+.ag-history-h button {+ width: 22px; height: 22px;+ display: grid; place-items: center;+ border-radius: var(--r-sm);+ color: var(--text-faint);+ transition: color var(--t-fast), background var(--t-fast);+}+.ag-history-h button:hover { color: var(--text-hi); background: var(--hover); }+.ag-history-none, .ag-history-note {+ padding: 16px 14px;+ font-size: var(--fs-sm);+ line-height: 1.7;+ color: var(--text-faint);+}+.ag-history-note { padding: 10px 14px; font-size: var(--fs-2xs); }+.ag-history-l { display: flex; flex-direction: column; }+.ag-hrow { display: flex; align-items: stretch; border-bottom: 1px solid var(--line); }+.ag-hrow:hover { background: var(--hover); }+.ag-hrow-go {+ flex: 1; min-width: 0;+ display: flex; flex-direction: column; gap: 4px;+ padding: 11px 6px 11px 14px;+ text-align: left;+}+.ag-hrow-t {+ font-size: var(--fs-md);+ color: var(--text-hi);+ letter-spacing: -0.008em;+ overflow: hidden; text-overflow: ellipsis; white-space: nowrap;+}+.ag-hrow-m {+ display: flex; align-items: center; gap: 10px;+ font: var(--fs-2xs) var(--font-mono);+ color: var(--text-faint);+}+.ag-hrow-model { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }+/* Quiet until the row is hovered — it destroys something. */+.ag-hrow-x {+ flex: none;+ width: 34px;+ display: grid; place-items: center;+ color: var(--text-faint);+ opacity: 0;+ transition: opacity var(--t-fast), color var(--t-fast);+}+.ag-hrow:hover .ag-hrow-x, .ag-hrow-x:focus-visible { opacity: 1; }+.ag-hrow-x:hover { color: var(--error); }+/* ── Empty states ────────────────────────────────────────────────────────── */.ag-empty { padding: 40px 14px; text-align: center; display: flex; flex-direction: column; align-items: center; }.ag-empty-mark { color: var(--text-faint); opacity: 0.5; }