refactor: eliminate any types across server and TTS worker
- app.ts: type serveFile context parameter as Hono Context - bets.ts: replace catch(err: any) with err: unknown + narrowing - fight-loop.ts: type pickMatchup style as union literal, replace as any casts with proper result type - tts-worker.ts: import KokoroTTS type, use ProgressInfo inference Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
1ca8a6feb0
commit
010e18fbd3
@@ -1,7 +1,9 @@
|
|||||||
// Web Worker for Kokoro TTS — runs ONNX neural network inference off the main thread.
|
// Web Worker for Kokoro TTS — runs ONNX neural network inference off the main thread.
|
||||||
// This prevents the 1-5 second freezes that occur when generate() runs on the UI thread.
|
// This prevents the 1-5 second freezes that occur when generate() runs on the UI thread.
|
||||||
|
|
||||||
let tts: any = null
|
import type { KokoroTTS } from 'kokoro-js'
|
||||||
|
|
||||||
|
let tts: KokoroTTS | null = null
|
||||||
|
|
||||||
self.addEventListener('message', async (e: MessageEvent) => {
|
self.addEventListener('message', async (e: MessageEvent) => {
|
||||||
const msg = e.data
|
const msg = e.data
|
||||||
@@ -13,8 +15,8 @@ self.addEventListener('message', async (e: MessageEvent) => {
|
|||||||
tts = await KokoroTTS.from_pretrained('onnx-community/Kokoro-82M-ONNX', {
|
tts = await KokoroTTS.from_pretrained('onnx-community/Kokoro-82M-ONNX', {
|
||||||
dtype: 'q8',
|
dtype: 'q8',
|
||||||
device: null,
|
device: null,
|
||||||
progress_callback: (p: any) => {
|
progress_callback: (p) => {
|
||||||
if (p.progress !== undefined) {
|
if ('progress' in p && typeof p.progress === 'number') {
|
||||||
self.postMessage({ type: 'progress', progress: p.progress })
|
self.postMessage({ type: 'progress', progress: p.progress })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
import { Hono } from 'hono'
|
import { Hono, type Context } from 'hono'
|
||||||
import { cors } from 'hono/cors'
|
import { cors } from 'hono/cors'
|
||||||
import { logger } from 'hono/logger'
|
import { logger } from 'hono/logger'
|
||||||
import { secureHeaders } from 'hono/secure-headers'
|
import { secureHeaders } from 'hono/secure-headers'
|
||||||
@@ -79,7 +79,7 @@ if (process.env.NODE_ENV === 'production' && existsSync(publicDir)) {
|
|||||||
webmanifest: 'application/manifest+json',
|
webmanifest: 'application/manifest+json',
|
||||||
}
|
}
|
||||||
|
|
||||||
function serveFile(c: any, reqPath: string, cacheControl: string) {
|
function serveFile(c: Context, reqPath: string, cacheControl: string) {
|
||||||
const resolved = join(publicDir, reqPath)
|
const resolved = join(publicDir, reqPath)
|
||||||
// Prevent path traversal
|
// Prevent path traversal
|
||||||
if (!resolved.startsWith(publicDir)) return c.notFound()
|
if (!resolved.startsWith(publicDir)) return c.notFound()
|
||||||
|
|||||||
@@ -78,8 +78,8 @@ export async function startFightLoop(options: FightLoopOptions = {}): Promise<vo
|
|||||||
onRoundComplete({
|
onRoundComplete({
|
||||||
round: event.data.round as number,
|
round: event.data.round as number,
|
||||||
hp: event.data.hp as { a: number; b: number },
|
hp: event.data.hp as { a: number; b: number },
|
||||||
challengeType: (event.data.result as any)?.challengeType || '',
|
challengeType: (event.data.result as { challengeType?: string } | undefined)?.challengeType || '',
|
||||||
winnerId: (event.data.result as any)?.winnerId || null,
|
winnerId: (event.data.result as { winnerId?: string | null } | undefined)?.winnerId || null,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -151,7 +151,7 @@ export async function startFightLoop(options: FightLoopOptions = {}): Promise<vo
|
|||||||
|
|
||||||
function pickMatchup(
|
function pickMatchup(
|
||||||
bots: { id: string; eloRating: number; name: string; wins: number; losses: number }[],
|
bots: { id: string; eloRating: number; name: string; wins: number; losses: number }[],
|
||||||
style: string,
|
style: 'elo_close' | 'random' | 'mixed',
|
||||||
fightNum: number,
|
fightNum: number,
|
||||||
): [typeof bots[0], typeof bots[0]] {
|
): [typeof bots[0], typeof bots[0]] {
|
||||||
const sorted = [...bots].sort((a, b) => b.eloRating - a.eloRating)
|
const sorted = [...bots].sort((a, b) => b.eloRating - a.eloRating)
|
||||||
|
|||||||
@@ -103,8 +103,8 @@ betsRouter.post('/place', rateLimit(60_000, 10), async (c) => {
|
|||||||
odds: bet.oddsAtPlacement,
|
odds: bet.oddsAtPlacement,
|
||||||
potentialPayout: bet.potentialPayout,
|
potentialPayout: bet.potentialPayout,
|
||||||
})
|
})
|
||||||
} catch (err: any) {
|
} catch (err: unknown) {
|
||||||
return c.json({ error: err.message }, 400)
|
return c.json({ error: err instanceof Error ? err.message : String(err) }, 400)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user