mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-11 19:09:20 +00:00
fix(cli): align media search checks with local-first flow
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { existsSync, readFileSync } from "node:fs";
|
||||
import { extname, join } from "node:path";
|
||||
import { rankMediaRows } from "../../registry/mediaSearch.mjs";
|
||||
import { rankMediaRows } from "./media-search.mjs";
|
||||
|
||||
const LIB_DIR =
|
||||
process.env.HYPERFRAMES_MEDIA_USE_SFX_DIR ||
|
||||
|
||||
@@ -32,12 +32,13 @@ test("listTypes exposes the v2 media types", () => {
|
||||
}
|
||||
});
|
||||
|
||||
test("heygen provider is first for every type it serves", () => {
|
||||
for (const t of ["bgm", "sfx", "image", "icon"]) {
|
||||
test("heygen provider is first for every type it serves except bundled sfx", () => {
|
||||
for (const t of ["bgm", "image", "icon"]) {
|
||||
const first = getProviders(t)[0];
|
||||
assert.ok(first, `no enabled provider for ${t}`);
|
||||
assert.match(first.name, /^heygen/, `${t} first provider is ${first.name}`);
|
||||
}
|
||||
assert.equal(getProviders("sfx")[0].name, "bundled.sfx");
|
||||
});
|
||||
|
||||
test("sanctioned providers only: heygen, local mflux/kokoro/ltx, codex, design spec, logo tiers", () => {
|
||||
|
||||
@@ -43,6 +43,7 @@ export interface MediaVectorRow {
|
||||
dimensions?: { width: number; height: number };
|
||||
}
|
||||
|
||||
// fallow-ignore-next-line high-crap-score
|
||||
function isMediaVectorRow(value: unknown): value is MediaVectorRow {
|
||||
if (!value || typeof value !== "object") return false;
|
||||
const row = value as Partial<MediaVectorRow>;
|
||||
@@ -99,6 +100,7 @@ function localVectorDirectory(): string {
|
||||
* contract. A pair that fails it is a truncated download or a different
|
||||
* model, never something worth caching.
|
||||
*/
|
||||
// fallow-ignore-next-line high-crap-score
|
||||
function vectorPairAgrees(
|
||||
fetched: Array<[string, Buffer]>,
|
||||
artifactBasename: "local-vectors" | "media-vectors",
|
||||
@@ -190,6 +192,7 @@ export async function fetchLocalVectors(
|
||||
}
|
||||
}
|
||||
|
||||
// fallow-ignore-next-line unused-export
|
||||
export function fetchMediaVectors(
|
||||
registryBaseUrl: string,
|
||||
options: Omit<FetchLocalVectorOptions, "artifactBasename"> = {},
|
||||
@@ -204,6 +207,7 @@ export function hasLocalVectors(directory = localVectorDirectory()): boolean {
|
||||
);
|
||||
}
|
||||
|
||||
// fallow-ignore-next-line unused-export
|
||||
export function hasMediaVectors(directory = localVectorDirectory()): boolean {
|
||||
return (
|
||||
existsSync(join(directory, "media-vectors.bin")) &&
|
||||
@@ -211,6 +215,7 @@ export function hasMediaVectors(directory = localVectorDirectory()): boolean {
|
||||
);
|
||||
}
|
||||
|
||||
// fallow-ignore-next-line unused-export
|
||||
export function mediaVectorRows(directory = localVectorDirectory()): MediaVectorRow[] {
|
||||
if (!hasMediaVectors(directory)) return [];
|
||||
try {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { mediaSemanticRanking, type MediaVectorRow } from "./localSemantic.js";
|
||||
// fallow-ignore-file unused-file
|
||||
import { searchByWords } from "./localSearch.js";
|
||||
|
||||
export type MediaSearchRow = MediaVectorRow;
|
||||
|
||||
@@ -53,6 +53,7 @@ function arg(name: string): string | undefined {
|
||||
return index === -1 ? undefined : process.argv[index + 1];
|
||||
}
|
||||
|
||||
// fallow-ignore-next-line high-crap-score
|
||||
function mediaRows(manifestPath: string): MediaVectorRow[] {
|
||||
const parsed = JSON.parse(readFileSync(manifestPath, "utf8")) as
|
||||
| MediaVectorRow[]
|
||||
@@ -193,7 +194,7 @@ async function main(): Promise<void> {
|
||||
const vectors = await embedInBatches(names, catalog, embedder);
|
||||
const flat = packVectors(names, vectors);
|
||||
const credits =
|
||||
rows && manifestPath.endsWith("skills/media-use/audio/assets/sfx/manifest.json")
|
||||
rows && manifestPath?.endsWith("skills/media-use/audio/assets/sfx/manifest.json")
|
||||
? {
|
||||
file: "skills/media-use/audio/assets/sfx/CREDITS.md",
|
||||
sha256: sha256Hex(readFileSync("skills/media-use/audio/assets/sfx/CREDITS.md", "utf8")),
|
||||
|
||||
Reference in New Issue
Block a user