feat(media-use): derive provider cost tier from the registry (#3155)

The provider registry already declares whether a provider is local, free over
the network, or paid over the network via its A/N/P constructors, but nothing
downstream could read that, so anything needing to know whether resolving
through a provider can spend the user's credit had to re-derive it by
string-matching provider names.

Expose it as providerTierFor(name) over the same table and carry the derived
value on the resolve event alongside the provider it came from. Sparse: absent
when the record carries no provider or the name is not declared. A name declared
under two media types must carry one tier; the index throws at import rather
than silently picking one.

Covered by unit tests on the lookup and by end-to-end cases that spawn the real
CLI and read the value off the payload a local server receives, one per tier.
This commit is contained in:
Miguel Ángel
2026-08-10 13:35:25 -04:00
committed by GitHub
parent bd1c1af291
commit 6de29f5bea
5 changed files with 181 additions and 13 deletions
+12 -1
View File
@@ -14,7 +14,13 @@ import {
} from "./lib/manifest.mjs";
import { regenerateIndex } from "./lib/index-gen.mjs";
import { cacheGet, cacheGetByEntity, importFromCache, cachePut } from "./lib/cache.mjs";
import { runCapability, listTypes, providerMatches, providerNamesFor } from "./lib/registry.mjs";
import {
runCapability,
listTypes,
providerMatches,
providerNamesFor,
providerTierFor,
} from "./lib/registry.mjs";
import { freezeUrl, freezeLocalFile, isDirectMediaUrl } from "./lib/freeze.mjs";
import { findExistingAsset } from "./lib/adopt.mjs";
import { track } from "./lib/telemetry.mjs";
@@ -1206,6 +1212,11 @@ async function result(record, source) {
// signal about the fetch that actually consumed a heygen credit, not
// about the (free, no-credential) act of copying a cached file.
auth_method: record.provenance?.authMethod,
// "local" / "network_free" / "network_paid", straight from the registry's own
// A/N/P declaration — so a dashboard can separate free lookups from calls that
// spend credit without hardcoding provider names. Sparse: absent when the
// record carries no provider (cache and reuse hits) or the name is unknown.
provider_tier: providerTierFor(record.provenance?.provider),
local_only: !!args["local-only"],
provider_override: !!args.provider,
});