batched round: queue actions/diplomacy, jump forward commits one turn (v0.2.0)
CI / build + unit + e2e (pull_request) Successful in 1m51s

This commit is contained in:
2026-10-11 14:36:35 +00:00
parent 3297658c81
commit 9bce14254d
16 changed files with 563 additions and 246 deletions
+26 -32
View File
@@ -225,38 +225,37 @@ export default function App() {
[screen],
);
const runAction = useCallback(
async (action: string) => {
// Add an action to the pending round. Fast, non-LLM — no `busy`; the pending
// list updates from the response and the SSE `state` event.
const runAddAction = useCallback(
async (text: string) => {
if (!game) return;
setBusy(true);
try {
const { state } = await api.turn(game.id, action);
setGame(state);
const { game: g } = await api.addAction(game.id, text);
setGame(g);
} catch (e) {
toastError(e);
} finally {
setBusy(false);
}
},
[game],
);
const runChat = useCallback(
// Add a diplomatic message to the pending round. Fast, non-LLM — no `busy`.
const runAddDiplomacy = useCallback(
async (to: string, message: string) => {
if (!game) return;
setBusy(true);
try {
const { state } = await api.turn(game.id, undefined, { to, message });
setGame(state);
const { game: g } = await api.addDiplomacy(game.id, to, message);
setGame(g);
} catch (e) {
toastError(e);
} finally {
setBusy(false);
}
},
[game],
);
// Jump forward: the single LLM call that commits the pending round. Only this
// sets `busy` (the adds above are fast and non-LLM).
const runJump = useCallback(async () => {
if (!game) return;
setBusy(true);
@@ -321,8 +320,8 @@ export default function App() {
regions={regions}
busy={busy}
advisors={advisors}
onAction={runAction}
onChat={runChat}
onAddAction={runAddAction}
onAddDiplomacy={runAddDiplomacy}
onAdvisor={askAdvisor}
onJump={runJump}
onHome={goHome}
@@ -360,8 +359,8 @@ interface GameScreenProps {
regions: RegionMap;
busy: boolean;
advisors: string[];
onAction: (a: string) => void;
onChat: (to: string, m: string) => void;
onAddAction: (a: string) => void;
onAddDiplomacy: (to: string, m: string) => void;
onAdvisor: (p?: string) => void;
onJump: () => void;
onHome: () => void;
@@ -383,8 +382,8 @@ function GameScreen({
regions,
busy,
advisors,
onAction,
onChat,
onAddAction,
onAddDiplomacy,
onAdvisor,
onJump,
onHome,
@@ -561,7 +560,7 @@ function GameScreen({
<EventFeed events={game.events} nations={game.nations} inWindow />
</FloatingWindow>
{/* Command deck ("Your move"), bottom-center — the prominent typing spot. */}
{/* Command deck ("Your move"), bottom-center — queue items, then commit. */}
<FloatingWindow
id="action"
anchor="bottom-center"
@@ -569,16 +568,11 @@ function GameScreen({
title="Your move"
titleIcon={<Radar className="size-4 text-primary" />}
titleExtra={
<Button
variant="secondary"
size="sm"
onClick={onJump}
disabled={busy}
data-testid="jump-forward"
className="shrink-0"
>
{busy ? 'Simulating…' : 'Jump forward'}
</Button>
game.pending.length > 0 ? (
<Badge variant="secondary" className="shrink-0 text-xs tabular-nums" data-testid="title-queued">
{game.pending.length} queued
</Badge>
) : undefined
}
collapsed={!!collapsed.action}
onCollapsedChange={(c) => setCollapsedFor('action', c)}
@@ -588,8 +582,8 @@ function GameScreen({
game={game}
busy={busy}
advisors={advisors}
onAction={onAction}
onChat={onChat}
onAddAction={onAddAction}
onAddDiplomacy={onAddDiplomacy}
onAdvisor={onAdvisor}
onJump={onJump}
inWindow