// The Research API's shapes (app/api/research/*), shared by the routes and the // page. Types only: safe for a client component. export type SourceKind = "local" | "remote" | "hub"; /** A corpus the ask bar can read: the local corpus, a published site, the hub. */ export type SourceOption = { /** The MCP's own handle form: `local:`, `remote:`, `hub:`. */ handle: string; kind: SourceKind; label: string; /** "published", "this machine", the site's url. */ detail?: string; }; /** What a search or a preview is scoped to (the scope chips). */ export type Scope = { source: string; /** Channel keys (a hub's are `:`); none = every channel. */ channels?: string[]; /** YYYY-MM-DD, inclusive. */ dateFrom?: string; dateTo?: string; /** VideoState values kept; none = all. */ states?: string[]; mediaType?: "video" | "livestream"; /** Search the posts corpus too. */ posts?: boolean; }; export type ChannelChoice = { key: string; slug: string; name: string; videoCount?: number; site?: string; /** Candace's: may show here, never in anything exported (lib/research/rules.mjs). */ localOnly?: boolean; }; /** Transcripts vs captions, as far as a full scan has counted them. */ export type TrackCensus = { transcript: number; captions: number; unknown: number; /** Channels of the scope counted / in the scope. */ counted: number; of: number; }; /** GET /api/research/scope: what the scope holds, before anything runs. */ export type ScopeSummary = { source: SourceOption; channels: ChannelChoice[]; /** Channels the scope selects. */ selected: number; /** Videos in the scope (summaries index; the channels' counts without one). */ videos: number; /** Upload dates, YYYYMMDD, when the source ships a summaries index. */ first: string | null; last: string | null; /** Counted only when a search has read the scope's channels whole. */ tracks: TrackCensus | null; /** A kept count from another build of this source: not used, said so. */ tracksStale?: string; /** Curated aliases the source ships (a plain query expands through them). */ aliases: number; /** Tokens that matched nothing, and other things the filters said. */ warnings: string[]; }; export type Snip = { t: number; clock: string; text: string; /** [start, end) of each match in `text`. */ marks: [number, number][]; /** An alternate caption track's hit (common/lib/captionTracks.ts). */ track?: string; /** A non-timed layer (description, tags): no timecode to cite. */ scope?: string; }; export type ResultHit = { /** `/`: the reading log's key. */ key: string; kind: "video" | "post"; videoId: string; channelSlug: string; channelKey: string; channelName: string; site?: string; title: string; uploadDate: string; /** transcript | captions | unknown, or post. */ track: string; /** VideoState from the summaries ("available" when the source says nothing). */ state: string; duration?: number; matches: number; snippets: Snip[]; mirrors?: { videoId: string; channelName: string }[]; author?: string; localOnly?: boolean; }; export type Facets = { years: { year: string; n: number }[]; channels: { slug: string; name: string; n: number }[]; tracks: Record; states: Record; }; export type LogMarks = Record; /** POST /api/research/search: the whole match set, once. */ export type SearchResponse = { session: string; query: string; regex: boolean; source: SourceOption; /** Recordings (mirrors folded): enumerate_matches' total. */ total: number; /** Matching lines across them. */ matches: number; complete: boolean; /** When capped: the channels never reached, and where it stopped. */ notReached: string[]; stopped?: { channel: string; page: number; pages: number }; scanned: { pages: number; channels: number }; mirrorsFolded: number; batches: number; aliases: string[]; warnings: string[]; hits: ResultHit[]; facets: Facets; log: { marks: LogMarks; error?: string }; tookMs: number; }; export type WindowCue = { t: number; end: number; text: string }; /** GET /api/research/window: the transcript around a cue, for the reader. */ export type WindowResponse = { kind: "video" | "post"; title: string; channelSlug: string; channelName: string; videoId: string; uploadDate: string; duration: number; state: string; /** transcript | captions | unknown. */ track: string; /** The alternate track read, by its label, when not the primary. */ trackLabel?: string; cueCount: number; at: number; span: number; cues: WindowCue[]; /** Index into `cues` of the cited cue. */ lit: number; citation: { text: string; url: string | null }; /** Files umtool can play from this machine, best first. */ media: LocalMedia[]; /** A post's text, when kind is post. */ text?: string; author?: string; localOnly?: boolean; }; export type LocalMedia = { name: string; kind: "window" | "source" | "audio"; /** A clip window's span, source seconds. */ from?: number; to?: number; }; /** POST /api/research/fetch: the editor's answer, as fetch_clip reads it. */ export type FetchAnswer = | { state: "ready"; file: string; from?: number; to?: number; cached: boolean } | { state: "queued"; job: string; status: string } | { state: "failed"; message: string; job?: string }; export type CoverageRow = { key: string; slug: string; name: string; localOnly?: boolean; /** Published: the source's summaries, by upload year. */ published: { total: number; byYear: Record; byState: Record; /** The states that are not "available", per year. */ missingByYear: Record>; }; /** Held on disk (channel_coverage), by coverage date; null when not known. */ held: { total: number; byYear: Record; gaps: { after: string; before: string; days: number }[]; gapYears: string[]; first: string | null; last: string | null; } | null; /** Transcripts vs captions per year, when a search counted the channel whole. */ tracks: Record | null; }; /** GET /api/research/coverage: channels × years. */ export type CoverageResponse = { source: SourceOption; years: string[]; rows: CoverageRow[]; /** Where `held` came from, and why not the editor when it did not. */ held: { via: "editor" | "disk" | "none"; note?: string; /** When the oldest of these held counts was read (ms since the epoch): they are kept 5 minutes. */ at: number; /** Every count came from the memo; `asked` channels were read this time. */ cached: boolean; asked: number; }; gapDays: number; };