From 35748147f98946aa57754308a5d45ba58fc1ba9d Mon Sep 17 00:00:00 2001 From: Tom Beckenham <34339192+tombeckenham@users.noreply.github.com> Date: Sat, 21 Nov 2026 18:57:17 +1100 Subject: [PATCH 1/2] Score an origin link only where the link rules write one completeness.originLink asked a looser matcher of its own whether a row needs a link, so regional twins, hosts with no maker row and stated upstreams that resolve to nothing counted as gaps the service can never close. It now reads the link reconcileSameAs wrote (served sameAs): need and have are the same rows. originIdKeys and originIndex are gone. A worker test runs one table of cases (regional twins, a three-hop chain, a host-only model, a maker's own row, a stated upstream that resolves to nothing, a variant suffix, a case-only difference) through reconcileSameAs and the scorer and asserts they agree row by row. The completeness cache_meta key moves to v4. --- .changeset/origin-link-score-matches-links.md | 5 + CLAUDE.md | 3 + docs/api-changes.md | 8 + docs/source-silent/README.md | 7 +- openapi.json | 2 +- packages/client/src/generated/types.gen.ts | 2 +- src/lib/completeness.test.ts | 34 ++-- src/lib/completeness.ts | 90 ++------- src/routes/index.tsx | 4 +- .../ingest/origin-link-score.worker.test.ts | 178 ++++++++++++++++++ src/server/openapi.ts | 2 +- src/server/status.ts | 3 +- src/server/status.worker.test.ts | 2 +- 13 files changed, 236 insertions(+), 104 deletions(-) create mode 100644 .changeset/origin-link-score-matches-links.md create mode 100644 src/server/ingest/origin-link-score.worker.test.ts diff --git a/.changeset/origin-link-score-matches-links.md b/.changeset/origin-link-score-matches-links.md new file mode 100644 index 00000000..23530961 --- /dev/null +++ b/.changeset/origin-link-score-matches-links.md @@ -0,0 +1,5 @@ +--- +'@modelschemas/client': patch +--- + +`completeness.originLink.need` on `GET /v1/status` counts only models the link rules linked (`sameAs` set), not every model whose id another provider also lists. The type is unchanged; its description says so. See docs/api-changes.md. diff --git a/CLAUDE.md b/CLAUDE.md index 0389769f..9f4f8d54 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -183,6 +183,9 @@ ones). `scripts/gap-report.ts`; the Worker bundles `docs/source-silent/*.md` (`source-silent.ts`). The 15-minute cron scores once after the poll (`recordCompleteness`, one `cache_meta` row); requests only read it. + Its `originLink` reads the served `sameAs` and never re-matches names: + a row needs a link only when `reconcileSameAs` wrote one (pinned by + `origin-link-score.worker.test.ts`). BytePlus chat, Seedance, and Seedream cards come from its public ModelArk pricing doc (`byteplus-pricing.ts`; the console pricing view and `arkcli pricing` are login-gated). An id that page diff --git a/docs/api-changes.md b/docs/api-changes.md index 8c7e4df7..7c536bff 100644 --- a/docs/api-changes.md +++ b/docs/api-changes.md @@ -4,6 +4,14 @@ Non-additive changes to the catalog and estimate API. Package release steps stay in the README under "Releasing on npm". npm package changelogs are written by changesets. +**Changed (0.1.x):** `completeness.originLink.need` on `GET /v1/status` +and `GET /v1/providers` counts only models the link rules linked +(`sameAs` set), not every model whose id another provider also lists. A +model no rule can link (no declared maker's row, regional twins, a host's +own model, a stated upstream that matches nothing) no longer lowers the +score. Stored scores are null until the first models poll after the +deploy. + **Added (0.1.x):** model rows gain `sameAsRoot` and `firstParty` (#719), and `factSources` gains `firstParty`. `sameAs` can now be name-inferred for a row whose provider states no upstream: `factSources.sameAs` is then diff --git a/docs/source-silent/README.md b/docs/source-silent/README.md index 8f4a390d..4fcfbf7a 100644 --- a/docs/source-silent/README.md +++ b/docs/source-silent/README.md @@ -24,9 +24,10 @@ that is not a models.dev price), `endpoint`, `modalities` (input) and which it always lacks: classify the row, do not ledger it. Rows of an activity with no fact set (embeddings, moderation, decision, world, search) are listed with `facts: null` and not scored. `originLink` is -scored on every row: a row needs an upstream link when its raw id or an -alias, also with dots read as hyphens, matches a row at another provider -and no row links to it; a row with `sameAs` set has one. A provider-wide +scored on every row: a row needs an upstream link when the link rules +(`reconcileSameAs`) link it, and has one when `sameAs` is served. A row +no rule can link (no declared maker's row, two roots, a maker's own row, +a stated upstream that matches nothing) needs none. A provider-wide entry applies to every activity that scores that key. For a fact missing only on particular models, use the exact native raw model id: diff --git a/openapi.json b/openapi.json index 7766c2da..58912938 100644 --- a/openapi.json +++ b/openapi.json @@ -1375,7 +1375,7 @@ }, "originLink": { "type": "object", - "description": "Models that need an upstream link (need) and models that have one (have, sameAs set). Silent and exact-model exceptions are not subtracted here.", + "description": "Models the link rules linked to another provider's row (need) and models whose sameAs is served (have). A model no rule can link (no declared maker's row, two roots, a declared maker's own row, a stated upstream that matches nothing) needs none. Silent and exact-model exceptions are not subtracted here.", "required": [ "have", "need" diff --git a/packages/client/src/generated/types.gen.ts b/packages/client/src/generated/types.gen.ts index e396f080..7daa5e3a 100644 --- a/packages/client/src/generated/types.gen.ts +++ b/packages/client/src/generated/types.gen.ts @@ -150,7 +150,7 @@ export type ServiceStatus = { } } /** - * Models that need an upstream link (need) and models that have one (have, sameAs set). Silent and exact-model exceptions are not subtracted here. + * Models the link rules linked to another provider's row (need) and models whose sameAs is served (have). A model no rule can link (no declared maker's row, two roots, a declared maker's own row, a stated upstream that matches nothing) needs none. Silent and exact-model exceptions are not subtracted here. */ originLink: { have: number diff --git a/src/lib/completeness.test.ts b/src/lib/completeness.test.ts index 443ec07a..6df1f0f5 100644 --- a/src/lib/completeness.test.ts +++ b/src/lib/completeness.test.ts @@ -2,7 +2,6 @@ import { describe, expect, it } from 'vitest' import { buildReport, - originIndex, parseLedger, rowCompleteness, scoreRow, @@ -191,41 +190,30 @@ describe('origin links', () => { sameAs: { provider: 'maker', rawId: 'model-4-5' }, } - it('needs a link where another provider lists the same id', () => { + // The link rules' cases are pinned against reconcileSameAs in + // src/server/ingest/origin-link-score.worker.test.ts. + it('needs a link only where the service wrote one', () => { const report = buildReport([ origin, linked, + // The same name, unlinked: the rules found no single maker root. { provider: 'host', rawId: 'model-4.5' }, - { provider: 'host', rawId: 'own-model' }, ]) const by = (id: string) => report.providers.find((p) => p.provider === id)?.originLink - // The link target is the origin: it needs no link of its own. expect(by('maker')).toEqual({ have: 0, need: 0, modelSilent: 0 }) expect(by('gateway')).toEqual({ have: 1, need: 1, modelSilent: 0 }) - // Matches after dots are read as hyphens; `own-model` matches nothing. - expect(by('host')).toEqual({ have: 0, need: 1, modelSilent: 0 }) - }) - - it('matches by alias and ignores ids at the same provider', () => { - const report = buildReport([ - { provider: 'maker', rawId: 'm-latest', aliases: ['m-1'] }, - { provider: 'maker', rawId: 'm-1' }, - { provider: 'host', rawId: 'm-1' }, - ]) - const by = (id: string) => - report.providers.find((p) => p.provider === id)?.originLink.need - expect(by('maker')).toBe(2) - expect(by('host')).toBe(1) + expect(by('host')).toEqual({ have: 0, need: 0, modelSilent: 0 }) }) it('names the missing facts of one row', () => { const row: ModelRow = { ...chat, maxOutput: null } - const origins = originIndex([row, { provider: 'other', rawId: 'm' }]) expect( - rowCompleteness( - scoreRow(row, parseLedger('- host: cacheRead — none'), origins), - ), - ).toEqual({ filled: 9, needed: 11, missing: ['maxOutput', 'originLink'] }) + rowCompleteness(scoreRow(row, parseLedger('- host: cacheRead — none'))), + ).toEqual({ filled: 9, needed: 10, missing: ['maxOutput'] }) + // A linked row needs its link and has it. + expect( + rowCompleteness(scoreRow({ ...row, sameAs: linked.sameAs })), + ).toEqual({ filled: 11, needed: 12, missing: ['maxOutput'] }) }) }) diff --git a/src/lib/completeness.ts b/src/lib/completeness.ts index 8a600a6f..6a40b206 100644 --- a/src/lib/completeness.ts +++ b/src/lib/completeness.ts @@ -93,7 +93,6 @@ export type ModelRow = { provider: string /** Exact native model id, never the slugged catalog id. */ rawId?: string - aliases?: Array | null /** The upstream row this one is linked to, as `/v1/models` serves it. */ sameAs?: { provider: string; rawId: string } | null activity?: string | null @@ -146,8 +145,8 @@ export type ProviderReport = { /** By activity, plus `unclassified` for rows with none. */ activities: Partial> /** - * Rows whose id matches a row at another provider and that no row links - * to, plus every row with `sameAs` set. `have` counts `sameAs` set. + * Rows the link rules linked (`need`) and rows with `sameAs` served + * (`have`): the same rows, so `need` counts only links the service writes. */ originLink: FactTally & { modelSilent: number } silent: Array @@ -212,59 +211,18 @@ export function parseLedger(markdown: string): Ledger { } /** - * The ids a row matches another provider's row by: its raw id and aliases, - * each also with dots read as hyphens. The same tiers `reconcileSameAs` - * (`src/server/ingest/model-identity.ts`) links by. + * `originLink` asks only what `reconcileSameAs` + * (`src/server/ingest/model-identity.ts`) decided: a row needs an origin + * link exactly when the link rules write one, and has it when `sameAs` is + * served. The rules (the stated tiers, then the name tier `inferLinks` over + * `originNameKey` and `isOwnRow`) read what a served row does not carry: + * stated evidence that resolves to nothing, deprecated rows, and the + * namespace prefixes, so re-running them here would be a second, partial + * copy. A row no rule can link (no maker row, two roots, a host's own row, + * a declared maker's own row, stated evidence that resolves to nothing) + * needs none. */ -export function originIdKeys(row: Pick) { - const ids = row.rawId === undefined ? [] : [row.rawId] - ids.push(...(row.aliases ?? [])) - return new Set(ids.flatMap((id) => [id, id.replaceAll('.', '-')])) -} - -/** Which rows need an origin link; built once over the whole catalog. */ -export type OriginIndex = { - providersById: Map> - /** `provider/rawId` of every row some other row links to. */ - targets: Set -} - -const NO_ORIGINS: OriginIndex = { providersById: new Map(), targets: new Set() } - -export function originIndex(rows: Array): OriginIndex { - const providersById = new Map>() - const targets = new Set() - for (const row of rows) { - for (const key of originIdKeys(row)) { - const set = providersById.get(key) ?? new Set() - set.add(row.provider) - providersById.set(key, set) - } - if (row.sameAs) - targets.add(modelLedgerScope(row.sameAs.provider, row.sameAs.rawId)) - } - return { providersById, targets } -} - -/** - * A row with `sameAs` set needs a link and has one. Otherwise it needs one - * when an id key matches a row at another provider, unless a row links to - * it: a link target is the origin, not the copy. - */ -function needsOriginLink(row: ModelRow, origins: OriginIndex): boolean { - if (row.sameAs) return true - if ( - row.rawId !== undefined && - origins.targets.has(modelLedgerScope(row.provider, row.rawId)) - ) { - return false - } - return [...originIdKeys(row)].some((key) => - [...(origins.providersById.get(key) ?? [])].some( - (provider) => provider !== row.provider, - ), - ) -} +const linked = (row: ModelRow) => row.sameAs != null /** * Public endpoint id, query and leading slash stripped. The route's wire @@ -346,7 +304,7 @@ const nonEmpty = (value: unknown) => Array.isArray(value) && value.length > 0 const FACTS: Record< FactKey, { - need?: (row: ModelRow, origins: OriginIndex) => boolean + need?: (row: ModelRow) => boolean have: (row: ModelRow) => boolean } > = { @@ -400,7 +358,7 @@ const FACTS: Record< .replayReasoningContent === 'boolean', }, activity: { have: (row) => row.activity != null }, - originLink: { need: needsOriginLink, have: (row) => row.sameAs != null }, + originLink: { need: linked, have: linked }, } /** @@ -421,8 +379,7 @@ const FLAGS: Record< reasoningUnknown: { silencedBy: 'reasoning', match: (row) => - FACTS.reasoning.need?.(row, NO_ORIGINS) === true && - !FACTS.reasoning.have(row), + FACTS.reasoning.need?.(row) === true && !FACTS.reasoning.have(row), }, // The catalog reads `[]` as unknown; an unknown list is stored as null. outputModalitiesEmpty: { @@ -454,14 +411,12 @@ export function activityBucket(row: Pick): string { /** * The facts that apply to one row and whether it carries each: its - * activity's set, then `originLink`. Empty for an activity with no fact - * set when no link applies. Without `origins` the link is asked only of a - * row with `sameAs` set, which has it. + * activity's set, then `originLink` when `sameAs` is set. Empty for an + * activity with no fact set when the row has no link. */ export function scoreRow( row: ModelRow, ledger: Ledger = new Map(), - origins: OriginIndex = NO_ORIGINS, ): Array { const bucket = activityBucket(row) const keys: Array = [ @@ -475,7 +430,7 @@ export function scoreRow( : ledger.get(modelLedgerScope(row.provider, row.rawId)) return keys.flatMap((fact): Array => { const { need, have } = FACTS[fact] - if (need && !need(row, origins)) return [] + if (need && !need(row)) return [] const has = have(row) const silent = providerSilent?.has(fact) === true || @@ -523,7 +478,6 @@ export function buildReport( ledger: Ledger = new Map(), now: Date = new Date(), ): GapReport { - const origins = originIndex(rows) const byProvider = new Map>() for (const row of rows) { const group = byProvider.get(row.provider) @@ -550,11 +504,7 @@ export function buildReport( score: null, }) report.rows += 1 - for (const { fact, have, silent: rowSilent } of scoreRow( - row, - ledger, - origins, - )) { + for (const { fact, have, silent: rowSilent } of scoreRow(row, ledger)) { const providerSilent = silent.includes(fact) const modelSilent = rowSilent && !providerSilent if (fact === 'originLink') { diff --git a/src/routes/index.tsx b/src/routes/index.tsx index d01c780c..9d361c5b 100644 --- a/src/routes/index.tsx +++ b/src/routes/index.tsx @@ -196,7 +196,7 @@ function CompletenessCell({ )} @@ -382,7 +382,7 @@ function Landing() { complete diff --git a/src/server/ingest/origin-link-score.worker.test.ts b/src/server/ingest/origin-link-score.worker.test.ts new file mode 100644 index 00000000..b4fcd2fe --- /dev/null +++ b/src/server/ingest/origin-link-score.worker.test.ts @@ -0,0 +1,178 @@ +/** + * Pins the completeness scorer's `originLink` to the link rules: one table + * of cases runs through `reconcileSameAs` (stated tiers, then the name tier + * `inferLinks`), the catalog serves the rows, and `scoreRow` must say a row + * needs a link exactly when the rules wrote one. + */ +import { describe, expect, it } from 'vitest' +import { env } from 'cloudflare:test' +import { and, eq, isNotNull } from 'drizzle-orm' + +import { getDb } from '#/db/index.ts' +import { models } from '#/db/schema.ts' +import { buildReport, scoreRow } from '#/lib/completeness.ts' +import type { ModelRow } from '#/lib/completeness.ts' +import { listModelsCatalog } from '#/server/catalog.ts' +import { namespacedUpstreamIdentity } from '#/server/providers/upstream-model.ts' +import type { ModelInfo, ProviderConfig } from '#/server/providers/types.ts' +import { modelDbId, pollProviderModels } from './poll-models.ts' +import type { SyncDeps } from './sync.ts' +import { reconcileSameAs } from './model-identity.ts' + +const SOURCE = { + derivation: 'listing' as const, + sourceUrl: 'https://example.com/models', + path: 'data[].id', +} + +function stub( + id: string, + listed: Array, + extra: Partial = {}, +): ProviderConfig { + return { + id, + displayName: id, + specSourceUrl: `https://example.com/${id}`, + defaultDerivation: 'upstream-spec', + fetchSpec: async () => ({ + specs: [], + sources: [], + outputStrategy: 'post-200', + }), + listModels: async () => ({ models: listed }), + classify: () => null, + ...extra, + } +} + +const maker = { makesOwnModels: true } +const gateway = { + upstreamModelIdentity: (rawId: string) => + namespacedUpstreamIdentity(rawId, SOURCE), +} + +/** [provider, rawId, needs a link]: the rules' answer for each case. */ +const CASES: Record> = { + // dashscope / dashscope-cn: shared ids, neither a declared maker. + 'regional twins, no maker': [ + ['ols-ds', 'qwen9-max', false], + ['ols-ds-cn', 'qwen9-max', false], + ], + // Two declared twins: a bare host's candidates lead to two roots. + 'regional twins, two roots': [ + ['ols-kimi', 'kimi-k9', false], + ['ols-kimi-cn', 'kimi-k9', false], + ['ols-host-a', 'kimi-k9', false], + ], + 'three-hop chain': [ + ['ols-maker', 'opus-9', false], + ['ols-cloud', 'ols-maker/opus-9', true], + ['ols-router', 'ols-cloud/ols-maker/opus-9', true], + ['ols-edge', 'ols-router/ols-cloud/ols-maker/opus-9', true], + ], + 'host-only model': [ + ['ols-host-a', 'llama-9-70b', false], + ['ols-host-b', 'llama-9-70b', false], + ], + "maker's own row": [['ols-maker', 'sonnet-9', false]], + // The name would match the maker, but stated evidence never falls through. + 'stated evidence that resolves to nothing': [['ols-stated', 'opus-9', false]], + 'variant suffix': [['ols-gw', 'ols-maker/opus-9:batch', true]], + 'case-only difference': [['ols-bare', 'OPUS-9', true]], +} + +async function seed(d: SyncDeps) { + const poll = (p: ProviderConfig) => pollProviderModels(d, p) + await poll(stub('ols-ds', [{ rawId: 'qwen9-max' }])) + await poll(stub('ols-ds-cn', [{ rawId: 'qwen9-max' }])) + await poll(stub('ols-kimi', [{ rawId: 'kimi-k9' }], maker)) + await poll(stub('ols-kimi-cn', [{ rawId: 'kimi-k9' }], maker)) + await poll( + stub('ols-host-a', [{ rawId: 'kimi-k9' }, { rawId: 'llama-9-70b' }]), + ) + await poll(stub('ols-host-b', [{ rawId: 'llama-9-70b' }])) + await poll( + stub('ols-maker', [{ rawId: 'opus-9' }, { rawId: 'sonnet-9' }], maker), + ) + await poll(stub('ols-cloud', [{ rawId: 'ols-maker/opus-9' }], gateway)) + await poll( + stub('ols-router', [{ rawId: 'ols-cloud/ols-maker/opus-9' }], gateway), + ) + await poll( + stub( + 'ols-edge', + [{ rawId: 'ols-router/ols-cloud/ols-maker/opus-9' }], + gateway, + ), + ) + await poll( + stub('ols-stated', [ + { + rawId: 'opus-9', + upstream: { + providerNamespace: 'ols-nowhere', + rawId: 'opus-9', + source: SOURCE, + }, + }, + ]), + ) + await poll( + stub('ols-gw', [ + { + rawId: 'ols-maker/opus-9:batch', + upstream: { + providerNamespace: 'ols-maker', + rawId: 'opus-9', + source: { ...SOURCE, variant: 'batch' }, + }, + }, + ]), + ) + await poll(stub('ols-bare', [{ rawId: 'OPUS-9' }])) +} + +describe('originLink need agrees with the links reconcileSameAs writes', () => { + it.each(Object.entries(CASES))('%s', async (_, rows) => { + let now = 1_781_150_000 + const d: SyncDeps = { + db: getDb(env), + kv: env.SCHEMA_CACHE, + secrets: {}, + now: () => now++, + } + await seed(d) + await reconcileSameAs(d.db, now) + const served = (await listModelsCatalog(d.db, { pricing: true })) + .models as Array + for (const [provider, rawId, expected] of rows) { + const stored = await d.db.query.models.findFirst({ + where: eq(models.id, modelDbId(provider, rawId)), + }) + const row = served.find( + (r) => r.provider === provider && r.rawId === rawId, + ) + if (!stored || !row) throw new Error(`${provider}/${rawId} not seeded`) + const needs = scoreRow(row).some((f) => f.fact === 'originLink') + const label = `${provider}/${rawId}` + expect({ label, linked: stored.sameAsModelId !== null }).toEqual({ + label, + linked: expected, + }) + expect({ label, needs }).toEqual({ label, needs: expected }) + } + // The catalog-wide report agrees too: it counts no row the rules left + // unlinked, however many providers list the same name. + const report = buildReport(served) + for (const provider of new Set(rows.map(([p]) => p))) { + const linked = await d.db.$count( + models, + and(eq(models.providerId, provider), isNotNull(models.sameAsModelId)), + ) + expect( + report.providers.find((p) => p.provider === provider)?.originLink, + ).toEqual({ have: linked, need: linked, modelSilent: 0 }) + } + }) +}) diff --git a/src/server/openapi.ts b/src/server/openapi.ts index 3b19f58c..b2ce3b23 100644 --- a/src/server/openapi.ts +++ b/src/server/openapi.ts @@ -1121,7 +1121,7 @@ export const openApiDocument = { originLink: { type: 'object', description: - 'Models that need an upstream link (need) and models that have one (have, sameAs set). Silent and exact-model exceptions are not subtracted here.', + "Models the link rules linked to another provider's row (need) and models whose sameAs is served (have). A model no rule can link (no declared maker's row, two roots, a declared maker's own row, a stated upstream that matches nothing) needs none. Silent and exact-model exceptions are not subtracted here.", required: ['have', 'need'], properties: { have: { type: 'integer' }, diff --git a/src/server/status.ts b/src/server/status.ts index 12e092f9..7a5e70b8 100644 --- a/src/server/status.ts +++ b/src/server/status.ts @@ -123,12 +123,11 @@ const live = (where = sql`1`) => * Bump the version when the scorer or the `Completeness` shape changes: the * old row then reads as no record, and scores are null until the next poll. */ -const COMPLETENESS_KEY = 'status:completeness:v3' +const COMPLETENESS_KEY = 'status:completeness:v4' /** * Completeness of every provider with live rows: the rows `GET * /v1/models?pricing=1` serves, so this and the CLI score the same thing. - * Origin links match across the whole catalog, so every row is read. */ async function scoreCompleteness( db: Db, diff --git a/src/server/status.worker.test.ts b/src/server/status.worker.test.ts index e4d0301a..d4614adc 100644 --- a/src/server/status.worker.test.ts +++ b/src/server/status.worker.test.ts @@ -411,7 +411,7 @@ describe('getServiceStatus', () => { } }) - const KEY = 'status:completeness:v3' + const KEY = 'status:completeness:v4' const scoreOf = async (db: ReturnType, id: string) => { const status = await getServiceStatus(db, NOW) return { From c4f776469d2cd5a4e1a6696bc6b86d7feee3ac7b Mon Sep 17 00:00:00 2001 From: Tom Beckenham <34339192+tombeckenham@users.noreply.github.com> Date: Sat, 21 Nov 2026 19:08:25 +1100 Subject: [PATCH 2/2] Take origin links out of the completeness score; serve a count need always equalled have, so originLink only lifted the scores of providers with links. Completeness drops the term, and /v1/status, the gap report and the home page serve originLinks, the number of live models with sameAs served. The stored-record validator rejects the old originLink shape, and the ledger refuses an originLink entry. --- .changeset/origin-link-score-matches-links.md | 4 +- CLAUDE.md | 6 +- docs/api-changes.md | 17 +++-- docs/source-silent/README.md | 10 ++- openapi.json | 24 ++----- packages/client/src/generated/types.gen.ts | 11 ++- scripts/gap-report.test.ts | 2 +- scripts/gap-report.ts | 8 +-- skill/modelschemas/SKILL.md | 2 +- src/lib/completeness.test.ts | 23 +++--- src/lib/completeness.ts | 72 +++++++------------ src/routes/index.tsx | 24 ++++--- src/routes/models/index.tsx | 9 +-- .../ingest/origin-link-score.worker.test.ts | 36 +++++----- src/server/llms-txt.ts | 2 +- src/server/openapi.ts | 17 ++--- src/server/status.ts | 24 +++---- src/server/status.worker.test.ts | 15 ++-- 18 files changed, 136 insertions(+), 170 deletions(-) diff --git a/.changeset/origin-link-score-matches-links.md b/.changeset/origin-link-score-matches-links.md index 23530961..2ebbabb7 100644 --- a/.changeset/origin-link-score-matches-links.md +++ b/.changeset/origin-link-score-matches-links.md @@ -1,5 +1,5 @@ --- -'@modelschemas/client': patch +'@modelschemas/client': minor --- -`completeness.originLink.need` on `GET /v1/status` counts only models the link rules linked (`sameAs` set), not every model whose id another provider also lists. The type is unchanged; its description says so. See docs/api-changes.md. +`completeness` on `GET /v1/status` no longer scores origin links: `originLink` (`{ have, need }`) is replaced by `originLinks`, the number of live models with `sameAs` set, which is not part of `score`. See docs/api-changes.md. diff --git a/CLAUDE.md b/CLAUDE.md index 6271b121..070469b6 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -79,7 +79,7 @@ register→execute), `pnpm run client-smoke` (typed client), shares `classifyAndBundle` with the sync engine), `pnpm run gap:report -- --table` (per-provider score for the facts `@tanstack/ai-models` needs: chat, image, video and audio rows on their own fact sets, null-activity rows as a gap, -and origin links; one +and an origin-link count (not scored); one `/v1/models` request; `docs/source-silent/.md` lists facts a provider does not publish; `--check` exits 1 below `--target`). Admin sync: `curl -X POST localhost:3100/v1/admin/sync/openrouter -H "X-Admin-Key: $ADMIN_KEY"`. @@ -183,8 +183,8 @@ ones). `scripts/gap-report.ts`; the Worker bundles `docs/source-silent/*.md` (`source-silent.ts`). The 15-minute cron scores once after the poll (`recordCompleteness`, one `cache_meta` row); requests only read it. - Its `originLink` reads the served `sameAs` and never re-matches names: - a row needs a link only when `reconcileSameAs` wrote one (pinned by + Origin links are not scored: `originLinks` counts rows with `sameAs` + served, the links `reconcileSameAs` wrote (pinned by `origin-link-score.worker.test.ts`). BytePlus chat, Seedance, and Seedream cards come from its public ModelArk pricing doc (`byteplus-pricing.ts`; the console diff --git a/docs/api-changes.md b/docs/api-changes.md index 7c536bff..1c2aa29c 100644 --- a/docs/api-changes.md +++ b/docs/api-changes.md @@ -4,13 +4,16 @@ Non-additive changes to the catalog and estimate API. Package release steps stay in the README under "Releasing on npm". npm package changelogs are written by changesets. -**Changed (0.1.x):** `completeness.originLink.need` on `GET /v1/status` -and `GET /v1/providers` counts only models the link rules linked -(`sameAs` set), not every model whose id another provider also lists. A -model no rule can link (no declared maker's row, regional twins, a host's -own model, a stated upstream that matches nothing) no longer lowers the -score. Stored scores are null until the first models poll after the -deploy. +**Breaking:** `completeness` on `GET /v1/status` and `GET /v1/providers` +no longer scores origin links. `originLink` (`{ have, need }`) is replaced +by `originLinks`, the number of live models with `sameAs` set: a count, +not part of `score`, `filled` or `needed`. The old `need` counted every +model whose id another provider also lists, including models no link rule +can link (no declared maker's row, regional twins, a stated upstream that +matches nothing). Scores drop the origin term, so a provider with links +no longer gets a lift from them. Scores are null until the first models +poll after the deploy. A `source-silent` ledger entry for `originLink` is +now refused. **Added (0.1.x):** model rows gain `sameAsRoot` and `firstParty` (#719), and `factSources` gains `firstParty`. `sameAs` can now be name-inferred diff --git a/docs/source-silent/README.md b/docs/source-silent/README.md index 4fcfbf7a..a250813a 100644 --- a/docs/source-silent/README.md +++ b/docs/source-silent/README.md @@ -23,12 +23,10 @@ that is not a models.dev price), `endpoint`, `modalities` (input) and `outputModalities`. A row with a null activity is scored on `activity`, which it always lacks: classify the row, do not ledger it. Rows of an activity with no fact set (embeddings, moderation, decision, world, -search) are listed with `facts: null` and not scored. `originLink` is -scored on every row: a row needs an upstream link when the link rules -(`reconcileSameAs`) link it, and has one when `sameAs` is served. A row -no rule can link (no declared maker's row, two roots, a maker's own row, -a stated upstream that matches nothing) needs none. A provider-wide -entry applies to every activity that scores that key. +search) are listed with `facts: null` and not scored. Origin links are +not scored: the report counts rows with `sameAs` served (`originLinks`), +and a ledger entry for `originLink` is refused. A provider-wide entry +applies to every activity that scores that key. For a fact missing only on particular models, use the exact native raw model id: `- provider/maker/model-id: fact — why, https://provider.example/model, checked YYYY-MM-DD`. diff --git a/openapi.json b/openapi.json index 58912938..9f45f5d4 100644 --- a/openapi.json +++ b/openapi.json @@ -1305,7 +1305,7 @@ }, "completeness": { "type": "object", - "description": "The gap-report score over the live models of the provider (src/lib/completeness.ts). Each activity has its own fact set. chat: contextWindow, maxOutput, modalities, priced, cacheRead, capabilities, reasoning, efforts, requestMap, endpoint, replayReasoningContent. image, video and audio: priced (any stored rate card that is not a models.dev price), endpoint, modalities (input) and outputModalities. A row with a null activity is in unclassified and counts as one missing fact (activity). Rows of an activity with no fact set (embeddings, moderation, decision, world, search) are listed with score null and do not change the score. originLink is scored on every row: a row needs an upstream link when its raw id or an alias, also with dots read as hyphens, matches a row at another provider and no row links to it; a row with sameAs set needs one and has it. Summed per model, each fact counted only where it applies. requestMap applies on chat/completions, completions, and responses routes. replayReasoningContent applies on chat/completions routes whose rows reason. A stated cached-input absence (factSources.cacheRead path not-offered) fills cacheRead. Provider-wide and exact-model source-silent exceptions are excluded. Computed at the models poll (completenessComputedAt), not per request.", + "description": "The gap-report score over the live models of the provider (src/lib/completeness.ts). Each activity has its own fact set. chat: contextWindow, maxOutput, modalities, priced, cacheRead, capabilities, reasoning, efforts, requestMap, endpoint, replayReasoningContent. image, video and audio: priced (any stored rate card that is not a models.dev price), endpoint, modalities (input) and outputModalities. A row with a null activity is in unclassified and counts as one missing fact (activity). Rows of an activity with no fact set (embeddings, moderation, decision, world, search) are listed with score null and do not change the score. Origin links are not scored: originLinks counts them. Summed per model, each fact counted only where it applies. requestMap applies on chat/completions, completions, and responses routes. replayReasoningContent applies on chat/completions routes whose rows reason. A stated cached-input absence (factSources.cacheRead path not-offered) fills cacheRead. Provider-wide and exact-model source-silent exceptions are excluded. Computed at the models poll (completenessComputedAt), not per request.", "required": [ "score", "rows", @@ -1313,7 +1313,7 @@ "needed", "silent", "activities", - "originLink" + "originLinks" ], "properties": { "score": { @@ -1321,7 +1321,7 @@ "number", "null" ], - "description": "filled / needed, 0 to 1, over every scored activity and originLink. 1 when every fact that applies is in silent. null when nothing is scored (every live model is of an activity with no fact set and none needs an origin link), when no score is stored yet, and when the live models changed since the stored score." + "description": "filled / needed, 0 to 1, over every scored activity. 1 when every fact that applies is in silent. null when nothing is scored (every live model is of an activity with no fact set), when no score is stored yet, and when the live models changed since the stored score." }, "rows": { "type": "integer", @@ -1373,21 +1373,9 @@ } } }, - "originLink": { - "type": "object", - "description": "Models the link rules linked to another provider's row (need) and models whose sameAs is served (have). A model no rule can link (no declared maker's row, two roots, a declared maker's own row, a stated upstream that matches nothing) needs none. Silent and exact-model exceptions are not subtracted here.", - "required": [ - "have", - "need" - ], - "properties": { - "have": { - "type": "integer" - }, - "need": { - "type": "integer" - } - } + "originLinks": { + "type": "integer", + "description": "Live models whose sameAs is served: links to the origin row at another provider. A count, not part of score: whether an unlinked model could be linked depends on what the link rules read and the catalog does not serve (stated upstreams that match nothing, the namespace table, the maker declaration). 0 when no score is served." } } }, diff --git a/packages/client/src/generated/types.gen.ts b/packages/client/src/generated/types.gen.ts index 7daa5e3a..1eb9eb74 100644 --- a/packages/client/src/generated/types.gen.ts +++ b/packages/client/src/generated/types.gen.ts @@ -112,11 +112,11 @@ export type ServiceStatus = { priced: number } /** - * The gap-report score over the live models of the provider (src/lib/completeness.ts). Each activity has its own fact set. chat: contextWindow, maxOutput, modalities, priced, cacheRead, capabilities, reasoning, efforts, requestMap, endpoint, replayReasoningContent. image, video and audio: priced (any stored rate card that is not a models.dev price), endpoint, modalities (input) and outputModalities. A row with a null activity is in unclassified and counts as one missing fact (activity). Rows of an activity with no fact set (embeddings, moderation, decision, world, search) are listed with score null and do not change the score. originLink is scored on every row: a row needs an upstream link when its raw id or an alias, also with dots read as hyphens, matches a row at another provider and no row links to it; a row with sameAs set needs one and has it. Summed per model, each fact counted only where it applies. requestMap applies on chat/completions, completions, and responses routes. replayReasoningContent applies on chat/completions routes whose rows reason. A stated cached-input absence (factSources.cacheRead path not-offered) fills cacheRead. Provider-wide and exact-model source-silent exceptions are excluded. Computed at the models poll (completenessComputedAt), not per request. + * The gap-report score over the live models of the provider (src/lib/completeness.ts). Each activity has its own fact set. chat: contextWindow, maxOutput, modalities, priced, cacheRead, capabilities, reasoning, efforts, requestMap, endpoint, replayReasoningContent. image, video and audio: priced (any stored rate card that is not a models.dev price), endpoint, modalities (input) and outputModalities. A row with a null activity is in unclassified and counts as one missing fact (activity). Rows of an activity with no fact set (embeddings, moderation, decision, world, search) are listed with score null and do not change the score. Origin links are not scored: originLinks counts them. Summed per model, each fact counted only where it applies. requestMap applies on chat/completions, completions, and responses routes. replayReasoningContent applies on chat/completions routes whose rows reason. A stated cached-input absence (factSources.cacheRead path not-offered) fills cacheRead. Provider-wide and exact-model source-silent exceptions are excluded. Computed at the models poll (completenessComputedAt), not per request. */ completeness?: { /** - * filled / needed, 0 to 1, over every scored activity and originLink. 1 when every fact that applies is in silent. null when nothing is scored (every live model is of an activity with no fact set and none needs an origin link), when no score is stored yet, and when the live models changed since the stored score. + * filled / needed, 0 to 1, over every scored activity. 1 when every fact that applies is in silent. null when nothing is scored (every live model is of an activity with no fact set), when no score is stored yet, and when the live models changed since the stored score. */ score: number | null /** @@ -150,12 +150,9 @@ export type ServiceStatus = { } } /** - * Models the link rules linked to another provider's row (need) and models whose sameAs is served (have). A model no rule can link (no declared maker's row, two roots, a declared maker's own row, a stated upstream that matches nothing) needs none. Silent and exact-model exceptions are not subtracted here. + * Live models whose sameAs is served: links to the origin row at another provider. A count, not part of score: whether an unlinked model could be linked depends on what the link rules read and the catalog does not serve (stated upstreams that match nothing, the namespace table, the maker declaration). 0 when no score is served. */ - originLink: { - have: number - need: number - } + originLinks: number } /** * Model tallies count live models only: what GET /v1/models lists by default. Deprecated models are in deprecated and nowhere else. diff --git a/scripts/gap-report.test.ts b/scripts/gap-report.test.ts index c5f8c969..8fdb1af3 100644 --- a/scripts/gap-report.test.ts +++ b/scripts/gap-report.test.ts @@ -198,7 +198,7 @@ describe('gap report scoring', () => { expect(speech.providers[0]?.score).toBeNull() expect(formatTable(speech)).toContain('n/a') expect(formatTable(speech)).toMatch( - /unscored.*originLink.*media\.outputModalities/, + /unscored.*originLinks.*media\.outputModalities/, ) expect(failing(speech, 1, ['speech', 'absent'])).toEqual(['absent']) }) diff --git a/scripts/gap-report.ts b/scripts/gap-report.ts index b0adb812..5997ce08 100644 --- a/scripts/gap-report.ts +++ b/scripts/gap-report.ts @@ -1,6 +1,6 @@ /** * Gap report: which facts `@tanstack/ai-models` needs are still missing, - * per provider and activity, with origin-link coverage. One HTTP request; + * per provider and activity, with origin-link counts. One HTTP request; * no per-model detail calls. * * pnpm run gap:report # JSON @@ -110,7 +110,7 @@ export function formatTable(report: GapReport): string { ...MEDIA, 'noAct', 'unscored', - 'originLink', + 'originLinks', 'm.dev', ...CHAT_FACT_KEYS, ...MEDIA_FACT_KEYS.map((key) => `media.${key}`), @@ -126,9 +126,7 @@ export function formatTable(report: GapReport): string { }), String(p.activities[UNCLASSIFIED]?.rows ?? 0), String(unscoredRows(p)), - p.silent.includes('originLink') - ? 'silent' - : `${p.originLink.have}/${p.originLink.need}`, + String(p.originLinks), String(p.fromModelsDev), ...CHAT_FACT_KEYS.map((key) => factCell(p, key, ['chat'])), ...MEDIA_FACT_KEYS.map((key) => factCell(p, key, MEDIA)), diff --git a/skill/modelschemas/SKILL.md b/skill/modelschemas/SKILL.md index 82f89f77..a5fbc0d4 100644 --- a/skill/modelschemas/SKILL.md +++ b/skill/modelschemas/SKILL.md @@ -124,7 +124,7 @@ spec syncs daily. Responses are JSON unless noted (`text/typescript`, the full card. `/v1/status` counts live `priced` models per provider and scores `completeness` (the share of facts filled: chat, image, video and audio rows on their own fact sets, a null activity as a gap, - and origin links; `score` is null when nothing is scored). A provider there carries `docsFailing`, + and an origin-link count, not scored; `score` is null when nothing is scored). A provider there carries `docsFailing`, `priceClearsRefused`, `updateStorm`, or `staleProbes` while its stored docs facts or prices may be stale, one poll rewrote most of its live rows, or a probe record is older than 90 days. A model row's diff --git a/src/lib/completeness.test.ts b/src/lib/completeness.test.ts index 6df1f0f5..b3370d57 100644 --- a/src/lib/completeness.test.ts +++ b/src/lib/completeness.test.ts @@ -192,7 +192,7 @@ describe('origin links', () => { // The link rules' cases are pinned against reconcileSameAs in // src/server/ingest/origin-link-score.worker.test.ts. - it('needs a link only where the service wrote one', () => { + it('counts the links the service wrote and scores none', () => { const report = buildReport([ origin, linked, @@ -200,20 +200,27 @@ describe('origin links', () => { { provider: 'host', rawId: 'model-4.5' }, ]) const by = (id: string) => - report.providers.find((p) => p.provider === id)?.originLink - expect(by('maker')).toEqual({ have: 0, need: 0, modelSilent: 0 }) - expect(by('gateway')).toEqual({ have: 1, need: 1, modelSilent: 0 }) - expect(by('host')).toEqual({ have: 0, need: 0, modelSilent: 0 }) + report.providers.find((p) => p.provider === id)?.originLinks + expect(by('maker')).toBe(0) + expect(by('gateway')).toBe(1) + expect(by('host')).toBe(0) + // Each row lacks only its activity: the link adds nothing to the score. + expect(report.providers.map((p) => p.score)).toEqual([0, 0, 0]) }) - it('names the missing facts of one row', () => { + it('leaves a link out of one row’s facts', () => { const row: ModelRow = { ...chat, maxOutput: null } expect( rowCompleteness(scoreRow(row, parseLedger('- host: cacheRead — none'))), ).toEqual({ filled: 9, needed: 10, missing: ['maxOutput'] }) - // A linked row needs its link and has it. expect( rowCompleteness(scoreRow({ ...row, sameAs: linked.sameAs })), - ).toEqual({ filled: 11, needed: 12, missing: ['maxOutput'] }) + ).toEqual({ filled: 10, needed: 11, missing: ['maxOutput'] }) + }) + + it('refuses an origin-link ledger entry', () => { + expect(() => parseLedger('- host: originLink — none')).toThrow( + /origin links are not scored/, + ) }) }) diff --git a/src/lib/completeness.ts b/src/lib/completeness.ts index 6a40b206..a1df0995 100644 --- a/src/lib/completeness.ts +++ b/src/lib/completeness.ts @@ -6,8 +6,8 @@ * * Each activity has its own fact set (`ACTIVITY_FACTS`). A row whose * activity is null is a gap (`unclassified`); a row whose activity has no - * fact set is listed with `facts: null` and never scored. `originLink` is - * scored on every row, whatever its activity. + * fact set is listed with `facts: null` and never scored. `originLinks` + * counts the rows with `sameAs` served; it is information, not a fact. * * `docs/source-silent/.md` lists facts a provider does not publish; * those are left out of that provider's score and listed under `silent`. @@ -29,7 +29,6 @@ export const FACT_KEYS = [ 'replayReasoningContent', 'outputModalities', 'activity', - 'originLink', ] as const export type FactKey = (typeof FACT_KEYS)[number] @@ -145,14 +144,18 @@ export type ProviderReport = { /** By activity, plus `unclassified` for rows with none. */ activities: Partial> /** - * Rows the link rules linked (`need`) and rows with `sameAs` served - * (`have`): the same rows, so `need` counts only links the service writes. + * Rows with `sameAs` served: the links `reconcileSameAs` + * (`src/server/ingest/model-identity.ts`) wrote. A count, not a fact: the + * rules read what a served row does not carry (stated evidence that + * resolves to nothing, the namespace table, the maker declaration), so + * the scorer cannot tell which unlinked rows could be linked, and a + * "needs a link" read from `sameAs` would always equal this count. */ - originLink: FactTally & { modelSilent: number } + originLinks: number silent: Array /** - * 0 to 1 over every scored activity and `originLink`. Null when nothing - * is scored: every row's activity has no fact set and no row needs a link. + * 0 to 1 over every scored activity. Null when nothing is scored: every + * row's activity has no fact set. */ score: number | null /** Raw ids of the chat rows each flag matches. */ @@ -192,6 +195,12 @@ export function parseLedger(markdown: string): Ledger { const entry = parseLedgerEntry(line) if (!entry) continue const { scope, fact } = entry + // Origin links are a count, not a scored fact: nothing to ledger. + if (fact === 'originLink' || fact === 'originLinks') { + throw new Error( + `source-silent ledger: origin links are not scored, do not ledger them: ${line}`, + ) + } if (!isLedgerKey(fact)) { throw new Error( `source-silent ledger: unknown fact "${fact}" in: ${line}`, @@ -210,20 +219,6 @@ export function parseLedger(markdown: string): Ledger { return ledger } -/** - * `originLink` asks only what `reconcileSameAs` - * (`src/server/ingest/model-identity.ts`) decided: a row needs an origin - * link exactly when the link rules write one, and has it when `sameAs` is - * served. The rules (the stated tiers, then the name tier `inferLinks` over - * `originNameKey` and `isOwnRow`) read what a served row does not carry: - * stated evidence that resolves to nothing, deprecated rows, and the - * namespace prefixes, so re-running them here would be a second, partial - * copy. A row no rule can link (no maker row, two roots, a host's own row, - * a declared maker's own row, stated evidence that resolves to nothing) - * needs none. - */ -const linked = (row: ModelRow) => row.sameAs != null - /** * Public endpoint id, query and leading slash stripped. The route's wire * is this path. There is no provider list. @@ -298,8 +293,7 @@ const nonEmpty = (value: unknown) => Array.isArray(value) && value.length > 0 /** * `need`: the fact applies to this row. `have`: the row carries it. Only - * the facts of the row's activity are asked (`ACTIVITY_FACTS`), and - * `originLink` of every row. + * the facts of the row's activity are asked (`ACTIVITY_FACTS`). */ const FACTS: Record< FactKey, @@ -358,7 +352,6 @@ const FACTS: Record< .replayReasoningContent === 'boolean', }, activity: { have: (row) => row.activity != null }, - originLink: { need: linked, have: linked }, } /** @@ -411,18 +404,16 @@ export function activityBucket(row: Pick): string { /** * The facts that apply to one row and whether it carries each: its - * activity's set, then `originLink` when `sameAs` is set. Empty for an - * activity with no fact set when the row has no link. + * activity's set. Empty for an activity with no fact set. */ export function scoreRow( row: ModelRow, ledger: Ledger = new Map(), ): Array { const bucket = activityBucket(row) - const keys: Array = [ - ...(isScoredActivity(bucket) ? ACTIVITY_FACTS[bucket] : []), - 'originLink', - ] + const keys: ReadonlyArray = isScoredActivity(bucket) + ? ACTIVITY_FACTS[bucket] + : [] const providerSilent = ledger.get(row.provider) const modelSilent = row.rawId === undefined @@ -455,7 +446,7 @@ export function rowCompleteness(facts: Array): { /** Facts filled and needed across a provider, ledgered ones left out. */ export function scoredFacts( - report: Pick, + report: Pick, ): FactTally { let have = 0 let need = 0 @@ -463,10 +454,6 @@ export function scoredFacts( have += activity?.filled ?? 0 need += activity?.needed ?? 0 } - if (!report.silent.includes('originLink')) { - have += report.originLink.have - need += report.originLink.need - report.originLink.modelSilent - } return { have, need } } @@ -488,7 +475,6 @@ export function buildReport( const providers = [...byProvider].map(([provider, group]): ProviderReport => { const silent = FACT_KEYS.filter((key) => ledger.get(provider)?.has(key)) const activities: Record = {} - const originLink = { have: 0, need: 0, modelSilent: 0 } for (const row of group) { const bucket = activityBucket(row) const report = (activities[bucket] ??= { @@ -507,12 +493,6 @@ export function buildReport( for (const { fact, have, silent: rowSilent } of scoreRow(row, ledger)) { const providerSilent = silent.includes(fact) const modelSilent = rowSilent && !providerSilent - if (fact === 'originLink') { - originLink.need += 1 - if (have) originLink.have += 1 - if (modelSilent) originLink.modelSilent += 1 - continue - } const tally = report.facts?.[fact] if (!tally) continue tally.need += 1 @@ -549,17 +529,17 @@ export function buildReport( }), ) as ProviderReport['flags'] - const total = scoredFacts({ activities, originLink, silent }) + const total = scoredFacts({ activities }) const scoredRows = Object.values(activities) .filter((a) => a.facts !== null) - .reduce((sum, a) => sum + a.rows, originLink.need) + .reduce((sum, a) => sum + a.rows, 0) return { provider, rows: group.length, noActivity: activities[UNCLASSIFIED]?.rows ?? 0, fromModelsDev: group.filter(isModelsDev).length, activities, - originLink, + originLinks: group.filter((row) => row.sameAs != null).length, silent, score: ratio(total, scoredRows), flags, diff --git a/src/routes/index.tsx b/src/routes/index.tsx index 9d361c5b..26e0ce1a 100644 --- a/src/routes/index.tsx +++ b/src/routes/index.tsx @@ -101,7 +101,7 @@ function completenessNote(c: Completeness): string { const UNSCORED_NOTE = 'No current score: none computed yet, or the live models changed since the last poll scored them' -/** `chat 82%` / `video —` / `origin 3/5`, each with its own tooltip. */ +/** `chat 82%` / `video —`, each with its own tooltip. */ function ScoreLine({ label, value, @@ -137,7 +137,7 @@ function ScoreLine({ ) } -/** The total, then one line per activity the provider serves, then origin links. */ +/** The total, one line per activity the provider serves, then the origin-link count. */ function CompletenessCell({ id, c, @@ -167,7 +167,7 @@ function CompletenessCell({ className="cursor-help font-semibold" title={ c.score === null - ? 'Nothing scored: no activity of these models has a fact set and none needs an origin link' + ? 'Nothing scored: no activity of these models has a fact set' : completenessNote(c) } tabIndex={0} @@ -192,12 +192,16 @@ function CompletenessCell({ href={`/models?provider=${id}${name === UNCLASSIFIED ? '' : `&activity=${name}`}`} /> ))} - {c.originLink.need > 0 && ( - + {c.originLinks > 0 && ( +
  • + + {c.originLinks} origin {c.originLinks === 1 ? 'link' : 'links'} + +
  • )} @@ -382,7 +386,7 @@ function Landing() { complete diff --git a/src/routes/models/index.tsx b/src/routes/models/index.tsx index fb68a5b9..6cd1c780 100644 --- a/src/routes/models/index.tsx +++ b/src/routes/models/index.tsx @@ -71,12 +71,9 @@ const getCatalog = createServerFn({ method: 'GET' }) continue } // Same scorer as the front page and `pnpm run gap:report`, one row at a - // time, against the row's own activity's facts. Origin links need the - // whole catalog, which this page does not read, so they are left out. + // time, against the row's own activity's facts. completeness[row.id] = rowCompleteness( - scoreRow(row as unknown as ModelRow, sourceSilentLedger).filter( - (fact) => fact.fact !== 'originLink', - ), + scoreRow(row as unknown as ModelRow, sourceSilentLedger), ) } return { @@ -274,7 +271,7 @@ function ModelsCatalog() { priced complete diff --git a/src/server/ingest/origin-link-score.worker.test.ts b/src/server/ingest/origin-link-score.worker.test.ts index b4fcd2fe..2cc10f13 100644 --- a/src/server/ingest/origin-link-score.worker.test.ts +++ b/src/server/ingest/origin-link-score.worker.test.ts @@ -1,8 +1,8 @@ /** - * Pins the completeness scorer's `originLink` to the link rules: one table - * of cases runs through `reconcileSameAs` (stated tiers, then the name tier - * `inferLinks`), the catalog serves the rows, and `scoreRow` must say a row - * needs a link exactly when the rules wrote one. + * Pins the gap report's `originLinks` count to the link rules: one table of + * cases runs through `reconcileSameAs` (stated tiers, then the name tier + * `inferLinks`), the catalog serves the rows, and the report must count + * exactly the links the rules wrote, without moving the score. */ import { describe, expect, it } from 'vitest' import { env } from 'cloudflare:test' @@ -10,7 +10,7 @@ import { and, eq, isNotNull } from 'drizzle-orm' import { getDb } from '#/db/index.ts' import { models } from '#/db/schema.ts' -import { buildReport, scoreRow } from '#/lib/completeness.ts' +import { buildReport } from '#/lib/completeness.ts' import type { ModelRow } from '#/lib/completeness.ts' import { listModelsCatalog } from '#/server/catalog.ts' import { namespacedUpstreamIdentity } from '#/server/providers/upstream-model.ts' @@ -52,7 +52,7 @@ const gateway = { namespacedUpstreamIdentity(rawId, SOURCE), } -/** [provider, rawId, needs a link]: the rules' answer for each case. */ +/** [provider, rawId, linked]: the rules' answer for each case. */ const CASES: Record> = { // dashscope / dashscope-cn: shared ids, neither a declared maker. 'regional twins, no maker': [ @@ -133,7 +133,7 @@ async function seed(d: SyncDeps) { await poll(stub('ols-bare', [{ rawId: 'OPUS-9' }])) } -describe('originLink need agrees with the links reconcileSameAs writes', () => { +describe('originLinks counts the links reconcileSameAs writes', () => { it.each(Object.entries(CASES))('%s', async (_, rows) => { let now = 1_781_150_000 const d: SyncDeps = { @@ -154,25 +154,27 @@ describe('originLink need agrees with the links reconcileSameAs writes', () => { (r) => r.provider === provider && r.rawId === rawId, ) if (!stored || !row) throw new Error(`${provider}/${rawId} not seeded`) - const needs = scoreRow(row).some((f) => f.fact === 'originLink') const label = `${provider}/${rawId}` - expect({ label, linked: stored.sameAsModelId !== null }).toEqual({ + expect({ label, - linked: expected, - }) - expect({ label, needs }).toEqual({ label, needs: expected }) + linked: stored.sameAsModelId !== null, + served: row.sameAs != null, + }).toEqual({ label, linked: expected, served: expected }) } - // The catalog-wide report agrees too: it counts no row the rules left - // unlinked, however many providers list the same name. + // The report counts exactly the stored links, however many providers + // list the same name, and a link never moves the score. const report = buildReport(served) + const unlinked = buildReport(served.map((r) => ({ ...r, sameAs: null }))) for (const provider of new Set(rows.map(([p]) => p))) { const linked = await d.db.$count( models, and(eq(models.providerId, provider), isNotNull(models.sameAsModelId)), ) - expect( - report.providers.find((p) => p.provider === provider)?.originLink, - ).toEqual({ have: linked, need: linked, modelSilent: 0 }) + const scored = report.providers.find((p) => p.provider === provider) + expect(scored?.originLinks).toBe(linked) + expect(scored?.score).toBe( + unlinked.providers.find((p) => p.provider === provider)?.score, + ) } }) }) diff --git a/src/server/llms-txt.ts b/src/server/llms-txt.ts index cf90dc4a..ca0daa79 100644 --- a/src/server/llms-txt.ts +++ b/src/server/llms-txt.ts @@ -26,7 +26,7 @@ spec syncs daily. Responses are JSON unless noted (\`text/typescript\`, the full card. \`/v1/status\` counts live \`priced\` models per provider and scores \`completeness\` (the share of facts filled: chat, image, video and audio rows on their own fact sets, a null activity as a gap, - and origin links; \`score\` is null when nothing is scored). A provider there carries \`docsFailing\`, + and an origin-link count, not scored; \`score\` is null when nothing is scored). A provider there carries \`docsFailing\`, \`priceClearsRefused\`, \`updateStorm\`, or \`staleProbes\` while its stored docs facts or prices may be stale, one poll rewrote most of its live rows, or a probe record is older than 90 days. A model row's diff --git a/src/server/openapi.ts b/src/server/openapi.ts index b2ce3b23..8c265a0e 100644 --- a/src/server/openapi.ts +++ b/src/server/openapi.ts @@ -1063,7 +1063,7 @@ export const openApiDocument = { completeness: { type: 'object', description: - 'The gap-report score over the live models of the provider (src/lib/completeness.ts). Each activity has its own fact set. chat: contextWindow, maxOutput, modalities, priced, cacheRead, capabilities, reasoning, efforts, requestMap, endpoint, replayReasoningContent. image, video and audio: priced (any stored rate card that is not a models.dev price), endpoint, modalities (input) and outputModalities. A row with a null activity is in unclassified and counts as one missing fact (activity). Rows of an activity with no fact set (embeddings, moderation, decision, world, search) are listed with score null and do not change the score. originLink is scored on every row: a row needs an upstream link when its raw id or an alias, also with dots read as hyphens, matches a row at another provider and no row links to it; a row with sameAs set needs one and has it. Summed per model, each fact counted only where it applies. requestMap applies on chat/completions, completions, and responses routes. replayReasoningContent applies on chat/completions routes whose rows reason. A stated cached-input absence (factSources.cacheRead path not-offered) fills cacheRead. Provider-wide and exact-model source-silent exceptions are excluded. Computed at the models poll (completenessComputedAt), not per request.', + 'The gap-report score over the live models of the provider (src/lib/completeness.ts). Each activity has its own fact set. chat: contextWindow, maxOutput, modalities, priced, cacheRead, capabilities, reasoning, efforts, requestMap, endpoint, replayReasoningContent. image, video and audio: priced (any stored rate card that is not a models.dev price), endpoint, modalities (input) and outputModalities. A row with a null activity is in unclassified and counts as one missing fact (activity). Rows of an activity with no fact set (embeddings, moderation, decision, world, search) are listed with score null and do not change the score. Origin links are not scored: originLinks counts them. Summed per model, each fact counted only where it applies. requestMap applies on chat/completions, completions, and responses routes. replayReasoningContent applies on chat/completions routes whose rows reason. A stated cached-input absence (factSources.cacheRead path not-offered) fills cacheRead. Provider-wide and exact-model source-silent exceptions are excluded. Computed at the models poll (completenessComputedAt), not per request.', required: [ 'score', 'rows', @@ -1071,13 +1071,13 @@ export const openApiDocument = { 'needed', 'silent', 'activities', - 'originLink', + 'originLinks', ], properties: { score: { type: ['number', 'null'], description: - 'filled / needed, 0 to 1, over every scored activity and originLink. 1 when every fact that applies is in silent. null when nothing is scored (every live model is of an activity with no fact set and none needs an origin link), when no score is stored yet, and when the live models changed since the stored score.', + 'filled / needed, 0 to 1, over every scored activity. 1 when every fact that applies is in silent. null when nothing is scored (every live model is of an activity with no fact set), when no score is stored yet, and when the live models changed since the stored score.', }, rows: { type: 'integer', @@ -1118,15 +1118,10 @@ export const openApiDocument = { }, }, }, - originLink: { - type: 'object', + originLinks: { + type: 'integer', description: - "Models the link rules linked to another provider's row (need) and models whose sameAs is served (have). A model no rule can link (no declared maker's row, two roots, a declared maker's own row, a stated upstream that matches nothing) needs none. Silent and exact-model exceptions are not subtracted here.", - required: ['have', 'need'], - properties: { - have: { type: 'integer' }, - need: { type: 'integer' }, - }, + 'Live models whose sameAs is served: links to the origin row at another provider. A count, not part of score: whether an unlinked model could be linked depends on what the link rules read and the catalog does not serve (stated upstreams that match nothing, the namespace table, the maker declaration). 0 when no score is served.', }, }, }, diff --git a/src/server/status.ts b/src/server/status.ts index 7a5e70b8..391ac875 100644 --- a/src/server/status.ts +++ b/src/server/status.ts @@ -35,9 +35,9 @@ export interface ActivityCompleteness { */ export interface Completeness { /** - * 0 to 1 over every scored activity and `originLink`. Null when nothing - * is scored (every row's activity has no fact set and no row needs a - * link), and when there is no current score: none computed yet, or the + * 0 to 1 over every scored activity. Null when nothing is scored (every + * row's activity has no fact set), and when there is no current score: + * none computed yet, or the * provider's live rows changed since the last poll scored them. */ score: number | null @@ -51,8 +51,8 @@ export interface Completeness { silent: Array /** By activity, plus `unclassified` for rows with a null activity. */ activities: Record - /** Rows that need an upstream link (`need`) and rows that have one. */ - originLink: { have: number; need: number } + /** Live models with `sameAs` served. A count, not part of `score`. */ + originLinks: number } export interface ProviderStatus { @@ -156,10 +156,7 @@ async function scoreCompleteness( needed: need, silent: provider.silent, activities, - originLink: { - have: provider.originLink.have, - need: provider.originLink.need, - }, + originLinks: provider.originLinks, }, ] }), @@ -179,7 +176,6 @@ const isScore = (value: unknown) => value === null || isCount(value) function isCompleteness(value: unknown): value is Completeness { if (typeof value !== 'object' || value === null) return false const entry = value as Partial> - const link = entry.originLink as Record | null | undefined return ( isScore(entry.score) && isCount(entry.rows) && @@ -200,10 +196,8 @@ function isCompleteness(value: unknown): value is Completeness { isCount(act.needed) ) }) && - typeof link === 'object' && - link !== null && - isCount(link.have) && - isCount(link.need) + // The previous `originLink: { have, need }` shape is no record. + isCount(entry.originLinks) ) } @@ -353,7 +347,7 @@ export async function getServiceStatus( sourceSilentLedger.get(providerId)?.has(key), ), activities: {}, - originLink: { have: 0, need: 0 }, + originLinks: 0, } } diff --git a/src/server/status.worker.test.ts b/src/server/status.worker.test.ts index d4614adc..7c6f89cf 100644 --- a/src/server/status.worker.test.ts +++ b/src/server/status.worker.test.ts @@ -372,7 +372,7 @@ describe('getServiceStatus', () => { needed: 4, silent: [], activities: { image: { rows: 1, score: 1 / 4, filled: 1, needed: 4 } }, - originLink: { have: 0, need: 0 }, + originLinks: 0, }) // Chat rows with every fact on the ledger have nothing left to fill. expect(allSilent).toEqual({ @@ -382,7 +382,7 @@ describe('getServiceStatus', () => { needed: 0, silent: [...FACT_KEYS], activities: { chat: { rows: 1, score: 1, filled: 0, needed: 0 } }, - originLink: { have: 0, need: 0 }, + originLinks: 0, }) // full: 10 of 10. thin: contextWindow and capabilities of 7 (no // OpenAI-compat route, so requestMap and replay are not scored). @@ -397,7 +397,7 @@ describe('getServiceStatus', () => { chat: { rows: 3, score: 12 / 23, filled: 12, needed: 23 }, image: { rows: 1, score: 0, filled: 0, needed: 4 }, }, - originLink: { have: 0, need: 0 }, + originLinks: 0, }) // The same rows as `pnpm run gap:report` reads them, off the API. @@ -477,7 +477,7 @@ describe('getServiceStatus', () => { needed: 8, silent: [], activities: {}, - originLink: { have: 0, need: 0 }, + originLinks: 0, } for (const entry of [ 7, @@ -485,7 +485,10 @@ describe('getServiceStatus', () => { { ...whole, score: 'high', silent: 'x' }, { ...whole, silent: [1] }, { ...whole, activities: { chat: { rows: 1 } } }, - { ...whole, originLink: null }, + { ...whole, originLinks: null }, + // The `originLink: { have, need }` shape stored before origin links + // left the score. + { ...whole, originLinks: undefined, originLink: { have: 0, need: 0 } }, // The chat-only shape stored before per-activity scores. { score: 0, chat: 1, filled: 0, needed: 8, silent: [] }, ]) { @@ -501,7 +504,7 @@ describe('getServiceStatus', () => { needed: 0, silent: [], activities: {}, - originLink: { have: 0, need: 0 }, + originLinks: 0, }) } // An array is not a record. One bad entry does not cost the good ones.