Files
zeekayandGitHub 18728874ce i18n: mark the copy held as data in lib, hooks and data (#68)
Copy written as data is phrase('…') where it is written and t(value)
where it is drawn; a builder that says a sentence with figures in it
takes t: Say = english last and says each sentence as one message.

Say and english come from @hanzo/i18n 0.5.4, so the local lib/say.ts
copy is gone.

Claude-Session: https://claude.ai/code/session_015XYKLjZtDTJEnMo4eK3AFH
2026-10-30 00:53:25 -07:00

312 lines
16 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* The landing's figures, each derived from a document the page reads and drawn only
* while that document still says it.
*
* the race the research API's coding.repair runs (lib/coding)
* the boards the research API's enso.* runs (lib/enso): GPQA Diamond, LiveCodeBench
* the prices the price list, GET /v1/pricing (lib/api/read)
* the spend Kai's billed rate beside frontier LLMs', GET /v1/models (lib/api/read)
* the call one Kai decision beside one LLM call, the decision.latency runs (lib/kai TIMED)
* the clock the Decision Suite's cost row and the served decision.latency run (lib/kai)
* the prefill Zen 6's throughput, measured by Hanzo (components/zen/desks)
*
* Nothing here types a score, a price, a time or a count. What is typed is
* which rows a figure reads: the SKUs we sell, by the names both catalogs bill
* them under, the frontier LLMs Kai is priced beside, and which latency runs
* time a call.
*
* The one figure that divides two costs is lib/enso's: each run's tokens at
* the price list's rate for its own model id (`tile`), the same line the
* landing, /benchmarks and /enso draw. The boards here are drawn by accuracy
* and the price chart by the price list.
*/
import { rate, type Pricing, type Served } from './api/read'
import { ahead as solvedMore, gains, type Coding, type Side, type Speed } from './coding'
import { CODE, GPQA, NEW, SEEN, date, named, pct, sku, usd as cost, type Board as EnsoBoard, type Enso, type Routed, type Rung } from './enso'
import { english, type Say } from '@hanzo/i18n'
import { ahead, newest, TIMED, type Run, type Table } from './kai'
import { topped } from './tally'
/* ---- the race: Hanzo Dev and Claude Code on the same coding tasks ---- */
/** The names the coding runs' systems go by on a page. */
const AGENTS: Record<string, string> = { 'claude-code': 'Claude Code', 'hanzo-dev': 'Hanzo Dev' }
/** One side of the race: its run, its name, its median seconds and model calls a task, and how many tasks it solved. */
export type Lane = { run: string; name: string; seconds: number; calls: number | null; solved: number; of: number }
/**
* Both sides, the paired speed over the tasks both solved, the paths Hanzo Dev
* settled a task by that are resolved gains, and whether the solved counts are
* drawn (only while Hanzo Dev solved more).
*/
export type Race = { base: Lane; ours: Lane; speed: Speed; paths: Speed[]; solved: boolean; split: string; ended: string }
const lane = (s: Side): Lane | null =>
s.median == null ? null : { run: s.id, name: AGENTS[s.system] ?? s.system, seconds: s.median, calls: s.calls, solved: s.solved, of: s.of }
/** The race the coding runs hold, or null while either side has no median (lib/coding draws it only while the speed is a resolved gain). */
export function race(c: Coding | null): Race | null {
if (!c) return null
const base = lane(c.base)
const ours = lane(c.ours)
if (!base || !ours || !(ours.seconds < base.seconds)) return null
return { base, ours, speed: c.speed, paths: gains(c.paths).filter((p) => p.n != null && p.n > 0), solved: solvedMore(c), split: c.split, ended: c.ended }
}
/* ---- the boards: accuracy, run by run ---- */
/**
* A bar as a board draws it: its key, name, the accuracy it is drawn at,
* whether it is ours, the price-list id its lab's mark is read from (none for
* a row that names no lab), and what is said beside its figure.
*/
export type Bar = { key: string; system: string; name: string; accuracy: number; ours: boolean; mark: string | null; aside: string | null }
/** Bars under one heading; a board of one group has none. */
export type Group = { title: string | null; rows: Bar[] }
/** A board as the page draws it: its groups, what its window says of it, the lead it gives, and the line under it. */
export type Bars = {
id: string
label: string
groups: Group[]
aside: string | null
/** Who the board leads with, its figure, its count against the next row, the set it is on, and the day it was measured. */
lead: { who: string; figure: string; note: string; set: string | null; measured: string }
foot: string
}
const run = (r: Rung): Bar => ({ key: `${r.system}-${r.tag}`, system: r.system, name: named(r.system), accuracy: r.accuracy, ours: r.ours, mark: r.sku?.id ?? null, aside: null })
/**
* One board, read for the page: the router (`enso`) and the single models,
* kept only while the router outscores every one of them (lib/tally
* `topped`), so a rerun that loses the lead takes the board off the page.
* Its sentences are said through `t` (@hanzo/i18n `Say`).
*/
export function bars(e: Enso, id: string, t: Say = english): Bars | null {
const b: EnsoBoard | undefined = e.boards.find((x) => x.id === id)
if (!b) return null
const rows = topped(
b.rows.filter((r) => !r.ours || r.system === 'enso').map((r) => ({ ...r, value: r.accuracy })),
(r) => r.ours,
)
const enso = rows.find((r) => r.ours)
const next = rows.find((r) => !r.ours)
if (!enso || !next || enso.correct == null || enso.n == null) return null
return {
id: b.id,
label: b.label,
groups: [{ title: null, rows: rows.map(run) }],
aside: t('{n} questions', { n: enso.n }),
lead: {
who: 'Enso',
figure: pct(enso.accuracy),
note: t('{correct} of {n} right, against {accuracy} for {model}, the next model on the same questions.', {
correct: enso.correct,
n: enso.n,
accuracy: pct(next.accuracy),
model: next.system,
}),
set: null,
measured: date(enso.ended),
},
foot: t("Enso as enso-bench measured it on {date}, beside each single model on the same questions. Each bar is a run's accuracy.", { date: date(enso.ended) }),
}
}
const routed = (r: Routed, aside: string | null): Bar => ({ key: `${r.system}-${r.n}`, system: r.system, name: r.name, accuracy: r.accuracy, ours: r.ours, mark: null, aside })
const per1k = (r: Routed, t: Say) => (r.per1k != null ? t('{cost} per 1k', { cost: cost(r.per1k) }) : null)
/**
* GPQA Diamond as the landing leads with it: Enso routed on new questions,
* the tiers ahead of the best single model and that model, each with what
* 1,000 questions cost; beside them, the tiers on questions they have seen,
* each figure said with its set (lib/enso `routing`). Without a routing, the
* router's board. Its sentences are said through `t` (@hanzo/i18n `Say`).
*/
export function gpqa(e: Enso, t: Say = english): Bars | null {
const r = e.routing
if (!r) return bars(e, GPQA, t)
const top = r.fresh[0]
return {
id: GPQA,
label: r.label,
groups: [
{ title: NEW, rows: [...r.fresh, r.best].map((x) => routed(x, per1k(x, t))) },
...(r.seen.length ? [{ title: SEEN, rows: r.seen.map((x) => routed(x, t('questions it has seen'))) }] : []),
],
aside: null,
lead: {
who: top.name,
figure: pct(top.accuracy),
note:
top.correct != null && top.n != null
? t('{correct} of {n} new questions right, against {accuracy} for the best single model on the same questions.', {
correct: top.correct,
n: top.n,
accuracy: pct(r.best.accuracy),
})
: t('New questions right, against {accuracy} for the best single model on the same questions.', { accuracy: pct(r.best.accuracy) }),
set: NEW,
measured: date(top.ended),
},
foot: t('Each bar is a research run. New questions are ones Enso had never seen, the same for every row; beside each, what 1,000 of them cost.'),
}
}
export const livecode = (e: Enso, t: Say = english) => bars(e, CODE, t)
/* ---- the price per million tokens ---- */
/** The SKUs we sell up front, by the name both the price list and the model list bill them under: `enso` is the one lib/enso prices the router's runs at. */
const OURS: Record<string, string> = { kai: 'Kai', enso: 'Enso', 'enso-flash': 'Enso Flash', 'enso-pro': 'Enso Pro' }
/** A row of the chart: dollars per million input and output tokens. */
export type Rate = { id: string; name: string; ours: boolean; input: number; output: number }
export type Prices = { rows: Rate[]; updated: string | null; top: number }
/**
* The chart: every single model GPQA Diamond's board measured, at the rate the
* price list states for the model id its runs are priced at (lib/enso `sku`),
* beside each SKU of ours the list prices, dearest output first. No row is left
* out for costing less than ours.
*/
export function prices(doc: Pricing, e: Enso): Prices | null {
const board = e.boards.find((b) => b.id === GPQA)
const field: Rate[] = (board?.rows ?? [])
.filter((r) => !r.ours)
.flatMap((r) => {
const m = sku(doc, r.system)
return m ? [{ id: m.id, name: m.name, ours: false, input: m.input, output: m.output }] : []
})
const ours: Rate[] = Object.entries(OURS).flatMap(([id, name]) => {
const p = rate(doc, id)
return p?.input != null && p.output != null ? [{ id, name, ours: true, input: p.input, output: p.output }] : []
})
if (!field.length || !ours.length) return null
const rows = [...new Map([...field, ...ours].map((r) => [r.id, r])).values()].sort((a, b) => b.output - a.output || b.input - a.input)
return { rows, updated: doc.updated ?? null, top: Math.max(...rows.map((r) => Math.max(r.input, r.output))) }
}
/** A rate as the chart prints it: a whole dollar bare, cents from a dollar up, and every digit the price list gives below one. */
export const usd = (v: number) => (Number.isInteger(v) ? `$${v}` : v >= 1 ? `$${v.toFixed(2)}` : `$${v}`)
/* ---- the spend: Kai's price beside frontier LLMs' ---- */
/**
* The frontier LLMs Kai's price is set beside, by the id the model list bills
* each under. One the list does not serve, or serves unpriced, is skipped.
*/
export const FRONTIER = ['anthropic/claude-opus-5', 'openai/gpt-5.5', 'anthropic/claude-fable-5.1', 'openai/gpt-6-astra']
/** A model's billed rate, in dollars per million input and output tokens, as the model list states it. */
export type Billed = { id: string; name: string; input: number; output: number }
/** Kai's rate, each frontier LLM's dearest first, and how many times less Kai bills per input token than the dearest. */
export type Spend = { kai: Billed; field: Billed[]; times: number }
const billed = (m: Served | undefined, name?: string): Billed | null => {
const input = m?.pricing?.input_per_million
const output = m?.pricing?.output_per_million
return m && input != null && input > 0 && output != null && output >= 0 ? { id: m.id, name: name ?? m.name ?? m.id, input, output } : null
}
/** The spend, while Kai and at least one frontier LLM are priced and Kai bills less per input token than every one. */
export function spend(models: Served[]): Spend | null {
const kai = billed(models.find((m) => m.id === 'kai'), 'Kai')
const field = FRONTIER.flatMap((id) => billed(models.find((m) => m.id === id)) ?? []).sort((a, b) => b.input - a.input || b.output - a.output)
if (!kai || !field.length || !field.every((m) => m.input > kai.input)) return null
return { kai, field, times: field[0].input / kai.input }
}
/* ---- the call: one Kai decision beside one LLM call ---- */
/**
* The runs a call is timed by, each read by split and system on the timing
* benchmark, the newest by `ended`, and the measure whose p50 it reads: a
* language model's call as a coding agent's client saw it, a Kai decision on
* api.hanzo.ai from a client over the network, and Kai served on one machine's
* CPU through loopback, its input repeated.
*/
const CALL = {
llm: { split: 'turns', system: 'claude-code', category: 'turn/latency_ms' },
kai: { split: 'network', system: 'kai', category: 'served/network/n1' },
cpu: { split: 'loopback', system: 'kai', category: 'served/loopback/cpu/same/wall' },
}
/** One p50 in milliseconds, the run it is read from, the version that run names and how many calls it is over. */
export type Timed = { run: string; version: string; ms: number; n: number | null }
/**
* One call timed three ways: the LLM's (with the model its run names, as the
* model list names it, and the agent whose client timed it), Kai's over the
* network, and Kai's on one CPU with no network; and how many times faster
* Kai's network call is than the LLM's. The CPU figure is another basis, so no
* multiple is made of it.
*/
export type Call = { llm: Timed & { model: string; agent: string; n: number }; kai: Timed & { n: number }; cpu: Timed | null; times: number }
const p50 = (r: Run | null | undefined, category: string) => r?.measures?.find((m) => m.category === category && m.metric === 'p50ms') ?? null
const timed = (runs: Run[], w: (typeof CALL)[keyof typeof CALL]): Timed | null => {
const r = newest(runs.filter((x) => x.benchmark === TIMED && x.split === w.split && x.system === w.system && p50(x, w.category) != null))
const m = p50(r, w.category)
return r && m && m.value > 0 ? { run: r.id, version: r.version, ms: m.value, n: m.of ?? m.n ?? null } : null
}
/** The model ids the LLM's call runs name: what the model list is asked for, so the LLM is named as the list names it. */
export const callers = (runs: Run[]): string[] => [
...new Set(runs.filter((r) => r.benchmark === TIMED && r.split === CALL.llm.split && r.system === CALL.llm.system).map((r) => r.version)),
]
/**
* The call, while both network runs are public, each says how many calls its
* p50 is over, and Kai's is the faster. The LLM is named as the model list
* names the version its run records, else by that id less its lab.
*/
export function call(runs: Run[], models: Served[] | null): Call | null {
const llm = timed(runs, CALL.llm)
const kai = timed(runs, CALL.kai)
if (!llm || !kai || llm.n == null || kai.n == null || !(kai.ms < llm.ms)) return null
const model = models?.find((m) => m.id === llm.version)?.name ?? llm.version.split('/').pop()!
return {
llm: { ...llm, n: llm.n, model, agent: AGENTS[CALL.llm.system] ?? CALL.llm.system },
kai: { ...kai, n: kai.n },
cpu: timed(runs, CALL.cpu),
times: llm.ms / kai.ms,
}
}
/* ---- the clock: one decision on GPU ---- */
/** The served run: `kai serve` on GPU, runtime and HTTP transport, wall time at the client. */
const SERVED = { id: 'decision.latency-window2-dgx.cuda.n1.transport-kai', same: 'cached/runtime/cuda/n1', fresh: 'cached/http/cuda/n1' }
/** One decision timed three ways on a GPU, each a p50 in milliseconds: cached in process, through the runtime and over HTTP transport. */
export type Clock = { cached: number; same: number | null; fresh: number | null; run: string | null }
/** The clock, once the cost row's latency runs are public; the served lanes only while their run is. */
export function clock(t: Table, runs: Run[]): Clock | null {
const time = t.tasks.find((x) => x.key === 'cost')?.timing
if (!time) return null
const served = runs.find((r) => r.id === SERVED.id)
return {
cached: time.cached[0],
same: p50(served, SERVED.same)?.value ?? null,
fresh: p50(served, SERVED.fresh)?.value ?? null,
run: served ? served.id : null,
}
}
/** A p50 as a sentence says it, in milliseconds: a tenth under ten, whole above, grouped by thousands. */
export const ms = (v: number) => (v < 10 ? v.toFixed(1) : Math.round(v).toLocaleString('en-US'))
/* ---- the Decision Suite as a grid ---- */
/** The tasks of the suite Kai wins, each with the day it was set; null while the suite is not whole. */
export function tasks(t: Table, fixed: string): { label: string; set: string }[] | null {
return t.whole ? t.tasks.filter((x) => ahead(x)).map((x) => ({ label: x.label, set: x.added ?? fixed })) : null
}
/* ---- the prefill ---- */
/** The leading figure of a reading, the conservative end: `~2,400` reads 2400, `1,150–1,400` reads 1150. */
export const lead = (shown: string) => Number((/[\d,.]+/.exec(shown)?.[0] ?? '0').replace(/,/g, ''))