human fight sequence fix
This commit is contained in:
@@ -28,6 +28,8 @@ export function clearAllPending(): void {
|
||||
}
|
||||
|
||||
const DEFAULT_HUMAN_TIMEOUT_MS = 8_000
|
||||
// Extra time for humans: accounts for network latency, SSE/polling delivery delay, reading time
|
||||
const HUMAN_EXTRA_MS = 5_000
|
||||
|
||||
export function isHumanPlayer(webhookUrl: string): boolean {
|
||||
return webhookUrl === 'http://human.local/'
|
||||
@@ -115,7 +117,7 @@ export function waitForHumanResponse(
|
||||
const choices = generateChoices(challenge)
|
||||
const promise = new Promise<{ answer: string | null; trashTalk?: string; timedOut: boolean }>((resolve) => {
|
||||
const key = `${fightId}:${botId}`
|
||||
const timeoutMs = challenge.timeout_ms || DEFAULT_HUMAN_TIMEOUT_MS
|
||||
const timeoutMs = (challenge.timeout_ms || DEFAULT_HUMAN_TIMEOUT_MS) + HUMAN_EXTRA_MS
|
||||
|
||||
const timeoutHandle = setTimeout(() => {
|
||||
pending.delete(key)
|
||||
@@ -174,7 +176,7 @@ export function getPendingChallenge(
|
||||
const entry = pending.get(key)
|
||||
if (!entry) return null
|
||||
|
||||
const timeoutMs = entry.challenge.timeout_ms || DEFAULT_HUMAN_TIMEOUT_MS
|
||||
const timeoutMs = (entry.challenge.timeout_ms || DEFAULT_HUMAN_TIMEOUT_MS) + HUMAN_EXTRA_MS
|
||||
const elapsed = Date.now() - entry.createdAt
|
||||
const remaining = Math.max(0, timeoutMs - elapsed)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user