Files
zeekay 891bcc564b benchmarks: the agent tools board, each kai_* tool as its research runs hold it
/benchmarks#tools draws hanzo-mcp's injection screen, command guard, tool
selection and log triage from GET /v1/research/runs?org=hanzo&benchmark=
mcp.<tool>: the handler now, its parts read alone, and the handler it
replaced, each table linking its runs. The snapshot is saved at prebuild
and the page refetches the same addresses, so a newly filed run shows
without a rebuild. The price tile's speed check reads the tile, not the
page, so the coding board's measured "faster" no longer trips it.

Claude-Session: https://claude.ai/code/session_01M8RoubcPN71KgJuZ8LdBUL
2026-10-14 19:53:05 -07:00

48 lines
1.5 KiB
TypeScript

'use client'
import { useEffect, useState } from 'react'
import { TOOLS, derive, runs, type Board } from '@/lib/tools'
import type { Run } from '@/lib/kai'
/** One fetch a page, whichever of its parts asks first. */
let pending: Promise<Board[]> | null = null
/** A tool's runs as its address answers them now; null when it does not answer. */
async function answer(id: string): Promise<Run[] | null> {
try {
const r = await fetch(runs(id), { credentials: 'omit' })
if (!r.ok) return null
const body = (await r.json()) as { data?: Run[] | null }
return body.data ?? []
} catch {
return null
}
}
/** The boards the answering addresses derive now; a tool whose address did not answer has none. */
async function fetched(): Promise<Board[]> {
const answers = await Promise.all(TOOLS.map((t) => answer(t.id)))
return derive(answers.flatMap((a) => a ?? []))
}
/**
* The tools board, from the build's snapshot until the research API answers,
* then from what it holds, a tool at a time; a tool whose fetch fails or holds
* nothing to draw keeps the build's table.
*/
export function useTools(initial: Board[]): Board[] {
const [boards, set] = useState(initial)
useEffect(() => {
let live = true
;(pending ??= fetched()).then((now) => {
if (!live || !now.length) return
const by = new Map(now.map((b) => [b.id, b]))
set((was) => TOOLS.flatMap((t) => by.get(t.id) ?? was.find((b) => b.id === t.id) ?? []))
})
return () => {
live = false
}
}, [])
return boards
}