human fight non multiple choice fix
This commit is contained in:
@@ -113,6 +113,9 @@ export function useHumanChallenge(
|
||||
}
|
||||
if (!humanChallenge.value || humanChallenge.value.roundNumber !== data.roundNumber) {
|
||||
applyChallenge(data)
|
||||
} else if (data.choices?.length && humanChoices.value.length === 0) {
|
||||
// SSE fallback had no choices, polling found them — update
|
||||
humanChoices.value = data.choices
|
||||
}
|
||||
} else if (data.fightStatus === 'finished') {
|
||||
humanChallenge.value = null
|
||||
|
||||
@@ -553,7 +553,6 @@ async function fightAgain(botId: string) {
|
||||
window.history.replaceState({}, '', `/arena/${data.fightId}`)
|
||||
startPolling({ onFinished: () => stopHumanPolling(), onTimeout: () => stopHumanPolling() })
|
||||
if (isHumanFight.value) {
|
||||
startHumanPolling()
|
||||
wireSSE()
|
||||
for (let i = 0; i < 20; i++) {
|
||||
await loadFight()
|
||||
@@ -563,6 +562,7 @@ async function fightAgain(botId: string) {
|
||||
await nextTick()
|
||||
await nextTick()
|
||||
if (liveFightData.value) await initLiveScene()
|
||||
startHumanPolling()
|
||||
}
|
||||
} else {
|
||||
fightError.value = `Failed to start fight (${res.status})`
|
||||
|
||||
@@ -265,6 +265,11 @@ async function getBotResponse(
|
||||
): Promise<WebhookResponse> {
|
||||
if (isHumanPlayer(bot.webhookUrl)) {
|
||||
logger.info('fight', `${bot.name} is human player, waiting for browser response`)
|
||||
// Start waitForHumanResponse FIRST so the pending challenge is stored
|
||||
// before the SSE event tells the frontend to fetch it (fixes race condition
|
||||
// where frontend fetched before pending was set → no choices shown)
|
||||
const start = Date.now()
|
||||
const resultPromise = waitForHumanResponse(fightId, bot.id, challenge, roundNumber)
|
||||
emit(fightId, 'human_challenge', {
|
||||
botId: bot.id,
|
||||
round: roundNumber,
|
||||
@@ -274,8 +279,7 @@ async function getBotResponse(
|
||||
timeoutMs: challenge.timeout_ms,
|
||||
scoring: challenge.scoring,
|
||||
})
|
||||
const start = Date.now()
|
||||
const result = await waitForHumanResponse(fightId, bot.id, challenge, roundNumber)
|
||||
const result = await resultPromise
|
||||
const elapsed = Date.now() - start
|
||||
return { answer: result.answer, trashTalk: result.trashTalk, timeMs: elapsed, timedOut: result.timedOut, error: false }
|
||||
}
|
||||
@@ -389,7 +393,7 @@ async function executeFightRounds(fightId: string, botA: BotRecord, botB: BotRec
|
||||
|
||||
for (let round = 1; round <= MAX_ROUNDS; round++) {
|
||||
lastRound = round
|
||||
const challenge = round === retroRound
|
||||
const challenge = (round === retroRound && !hasHuman)
|
||||
? generateRetroChallenge()
|
||||
: pickChallenge(usedTypes, arena.modifier, undefined, round, hasHuman)
|
||||
usedTypes.add(challenge.type)
|
||||
|
||||
Reference in New Issue
Block a user