Files
hanzo.ai/lib/models/distinct.ts
zeekay 6c65e3e941 @hanzo/app 0.2.0: the app SDK, renamed from @hanzo/rooms
Every import, the catalog pin and the docs name @hanzo/app and
github.com/hanzoai/app. lib/rooms.ts is lib/app.ts and
components/rooms.tsx is components/app.tsx.
2026-10-22 19:07:20 -07:00

27 lines
1.2 KiB
TypeScript

import { modelPagePath } from '@hanzo/app/lib/path'
/**
* One row per model.
*
* The gateway lists a family's model under its bare id and under its canonical
* id — `kai` and `hanzo/kai`, `enso` and `hanzo/enso` — and the price list
* carries a row for each, because billing keys on the raw id a caller sends
* (hanzoai/ai controllers/model_routes.go, `canonicalSlug`). Both rows are one
* model, and this site already says so: `modelPagePath` puts both at
* /models/hanzo/kai. So a model is its page, and a catalogue drawn for a reader
* keeps one row per page. The bare id wins, since it is the one the docs tell a
* caller to send; the row named first keeps its place.
*
* No other imports: the build's page list (lib/models/served) and the tables
* drawn in the browser (lib/models/catalog, the price list) ask the same question.
*/
export function distinct<T>(rows: readonly T[], id: (row: T) => string): T[] {
const kept = new Map<string, T>()
for (const row of rows) {
const page = modelPagePath(id(row))
const was = kept.get(page)
if (was === undefined || (id(was).includes('/') && !id(row).includes('/'))) kept.set(page, row)
}
return [...kept.values()]
}