// src/server/clip-index.ts
//
// Removed in agentic-terminal refactor (2026-05-14). The CLIP-based asset
// search (build_index.py / search.py) lived in
// `skills/autoviral/modules/research/scripts/clip_index/` — workstation
// infrastructure mis-placed in skills/. The Python scripts are preserved
// in git tag pre-skill-rewrite-snapshot; package them as a sibling skill
// if anyone wants semantic asset search back.
//
// All three exported functions now return `{ stub: true, reason: "removed" }`
// so callers (Studio's asset search, etc.) degrade gracefully — the UI
// falls back to filename grep instead of crashing.
import { promises as fs } from "node:fs";
import path from "node:path";
import os from "node:os";
import { listAssets } from "../domain/work-store.js";
const SAFE_ID = /^[a-zA-Z0-9_-]+$/;
function dataDir() {
    return process.env.AUTOVIRAL_DATA_DIR ?? path.join(os.homedir(), ".autoviral");
}
/** Per-work index dir: <dataDir>/works/<id>/clip-index/. */
export function clipIndexDir(workId) {
    return path.join(dataDir(), "works", workId, "clip-index");
}
const VIDEO_EXT = /\.(mp4|mov|webm|m4v|mkv)$/i;
const IMAGE_EXT = /\.(png|jpe?g|webp|gif|avif|bmp|tiff?)$/i;
function classifyKind(p) {
    if (VIDEO_EXT.test(p))
        return "video";
    if (IMAGE_EXT.test(p))
        return "image";
    return "other";
}
export async function buildClipIndex(workId) {
    if (!SAFE_ID.test(workId))
        throw new Error("Invalid workId");
    // Keep the indexable-asset count for diagnostics so callers can show the
    // user a useful "N indexable assets, but CLIP search is disabled" hint.
    const allAssets = await listAssets(workId);
    const assetCount = allAssets.filter((rel) => classifyKind(rel) !== "other").length;
    return { stub: true, reason: "clip_index_removed_in_refactor", assetCount };
}
export async function searchClipIndex(_workId, _query, _topK) {
    return { stub: true, reason: "clip_index_removed_in_refactor" };
}
export async function getClipIndexStatus(workId) {
    if (!SAFE_ID.test(workId))
        throw new Error("Invalid workId");
    const metaPath = path.join(clipIndexDir(workId), "meta.json");
    try {
        const raw = await fs.readFile(metaPath, "utf-8");
        const meta = JSON.parse(raw);
        if (!meta.model || typeof meta.assetCount !== "number" || !meta.builtAt) {
            return { stub: true, reason: "invalid_meta" };
        }
        return {
            stub: false,
            model: meta.model,
            assetCount: meta.assetCount,
            indexedAt: meta.builtAt,
            embeddingDim: meta.embeddingDim,
        };
    }
    catch {
        return { stub: true, reason: "no_index" };
    }
}
//# sourceMappingURL=clip-index.js.map