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): entity names in the answer are ways into the scene
esengine258950a04e96
diff --git a/desktop/src/components/AgentDrawer.tsx b/desktop/src/components/AgentDrawer.tsxindex b19083836..ed42e46ba 100644--- a/desktop/src/components/AgentDrawer.tsx+++ b/desktop/src/components/AgentDrawer.tsx@@ -43,6 +43,7 @@ import { MarkdownView } from '@/components/MarkdownView';import { dockApi } from '@/layout/dockApi';import { EditorHistory, type HistoryMark } from '@/engine/EditorHistory';import { useSelection } from '@/store/selectionStore';+import { EditorControlSurface } from '@/engine/EditorSession';import { t } from '@/i18n';const TOOL_ICON: Record<string, typeof Eye> = {@@ -139,7 +140,7 @@ function Prose({ text, streaming }: { text: string; streaming?: boolean }) {const [copied, setCopied] = useState(false);return (<div className="ag-say">- <MarkdownView text={text} />+ <MarkdownView text={text} entity={entityByName} />{/* The caret rides the last paragraph while tokens are still arriving —the difference between "thinking" and "finished" at a glance. */}{streaming && <span className="ag-caret" />}@@ -680,6 +681,20 @@ function formatElapsed(ms: number): string {const hasInput = (input: Record<string, unknown>): boolean => Object.keys(input).length > 0;+/**+ * An entity by the name the model wrote, or null.+ *+ * Read live rather than cached: the tree changes under the conversation — often+ * BECAUSE of it — and a name that resolved when the paragraph streamed may not+ * be the same entity a minute later. Ambiguous names resolve to nothing: two+ * entities called "Panel" make a link that is right half the time, which is+ * worse than no link.+ */+function entityByName(name: string): number | null {+ const hits = EditorControlSurface.getSceneTree().filter((n) => n.name === name);+ return hits.length === 1 ? hits[0].id : null;+}+const compact = (n: number): string => (n >= 1000 ? `${(n / 1000).toFixed(1)}k` : String(n));/** One line of the call's arguments — enough to tell two calls apart. */diff --git a/desktop/src/components/MarkdownView.tsx b/desktop/src/components/MarkdownView.tsxindex b9e837809..129cc22ed 100644--- a/desktop/src/components/MarkdownView.tsx+++ b/desktop/src/components/MarkdownView.tsx@@ -10,13 +10,23 @@import { useMemo, useState } from 'react';import { Copy, Check } from 'lucide-react';import { parseBlocks, type Block, type Inline } from './markdown';+import { peekEntities } from '@/store/AgentStore';+import { useSelection } from '@/store/selectionStore';import { t } from '@/i18n';-function Spans({ spans }: { spans: readonly Inline[] }) {+function Spans({ spans, entity }: { spans: readonly Inline[]; entity?: (name: string) => number | null }) {return (<>{spans.map((s, i) => {- if (s.kind === 'code') return <code className="md-code" key={i}>{s.text}</code>;+ if (s.kind === 'code') {+ // A code span naming an entity becomes a way into the scene. Keyed on+ // code rather than prose because models write identifiers as code and+ // English writes "the camera" — matching bare words would turn half a+ // sentence into links and send the reader somewhere they did not point.+ const id = entity?.(s.text) ?? null;+ if (id !== null) return <EntityRef key={i} id={id} name={s.text} />;+ return <code className="md-code" key={i}>{s.text}</code>;+ }if (s.kind === 'strong') return <strong key={i}>{s.text}</strong>;if (s.kind === 'em') return <em key={i}>{s.text}</em>;// `_blank` rather than in-app navigation: main's window-open handler@@ -35,6 +45,22 @@ function Spans({ spans }: { spans: readonly Inline[] }) {);}+/** An entity named in the answer: hovering echoes it where the work is, clicking+ * selects it. The same two gestures the transcript's tool rows already have. */+function EntityRef({ id, name }: { id: number; name: string }) {+ return (+ <button+ type="button"+ className="md-ent"+ onMouseEnter={() => peekEntities([id])}+ onMouseLeave={() => peekEntities([])}+ onClick={() => useSelection.getState().select(id)}+ >+ {name}+ </button>+ );+}+function CodeBlock({ block }: { block: Extract<Block, { kind: 'code' }> }) {const [copied, setCopied] = useState(false);return (@@ -58,7 +84,11 @@ function CodeBlock({ block }: { block: Extract<Block, { kind: 'code' }> }) {);}-export function MarkdownView({ text }: { text: string }) {+export function MarkdownView({ text, entity }: {+ text: string;+ /** Resolve a code span to a scene entity, making it clickable. */+ entity?: (name: string) => number | null;+}) {const blocks = useMemo(() => parseBlocks(text), [text]);return (<div className="md">@@ -68,22 +98,22 @@ export function MarkdownView({ text }: { text: string }) {return <CodeBlock key={i} block={b} />;case 'h': {const Tag = (`h${Math.min(b.level + 2, 6)}`) as 'h3';- return <Tag className="md-h" key={i}><Spans spans={b.spans} /></Tag>;+ return <Tag className="md-h" key={i}><Spans spans={b.spans} entity={entity} /></Tag>;}case 'list':return b.ordered ? (<ol className="md-list" key={i}>- {b.items.map((item, j) => <li key={j}><Spans spans={item} /></li>)}+ {b.items.map((item, j) => <li key={j}><Spans spans={item} entity={entity} /></li>)}</ol>) : (<ul className="md-list" key={i}>- {b.items.map((item, j) => <li key={j}><Spans spans={item} /></li>)}+ {b.items.map((item, j) => <li key={j}><Spans spans={item} entity={entity} /></li>)}</ul>);case 'rule':return <hr className="md-rule" key={i} />;default:- return <p className="md-p" key={i}><Spans spans={b.spans} /></p>;+ return <p className="md-p" key={i}><Spans spans={b.spans} entity={entity} /></p>;}})}</div>diff --git a/desktop/src/theme/agent.css b/desktop/src/theme/agent.cssindex 4d7b7c697..ed1de52fd 100644--- a/desktop/src/theme/agent.css+++ b/desktop/src/theme/agent.css@@ -653,3 +653,15 @@transition: opacity var(--t-fast);z-index: 3;}+/* An entity named in the answer. A hairline under it, not a colour: it is a+ thing in the scene, not a hyperlink out of the editor. */+.md-ent {+ font: 500 var(--fs-xs) var(--font-mono);+ color: var(--text-hi);+ padding: 1px 4px;+ border-radius: 3px;+ background: var(--inset);+ border-bottom: 1px solid var(--line-strong);+ letter-spacing: -0.01em;+}+.md-ent:hover { border-bottom-color: var(--nebula); background: var(--hover); }