Merge branch 'clipper/roles' into clipper/integ

This commit is contained in:
Mateuus
2026-11-18 04:45:34 -03:00
28 changed files with 2914 additions and 262 deletions
+119 -2
View File
@@ -18,8 +18,40 @@ export type ClipperStatus = {
};
export type JudgeModel = { id: string; label: string; description?: string };
/** `faceTrack` é opcional: o serviço antigo (antes do rastreio de reação) não manda. */
export type JudgeOptions = { scanEnabled: boolean; scanIntervalS: number; vision: boolean; camDetect: boolean; faceTrack?: boolean };
/** `faceTrack` e `timelineJson` são opcionais: o serviço antigo não manda. `timelineJson` = a IA lê o vídeo como
* linha do tempo JSON curta (novo); false = transcrição + chat + frames soltos (antigo, para comparar). */
export type JudgeOptions = {
scanEnabled: boolean; scanIntervalS: number; vision: boolean; camDetect: boolean; faceTrack?: boolean; timelineJson?: boolean;
};
/** Equipe de IA (doc/clipador/EQUIPE-IA.md): quatro papéis, cada um com a sua IA. */
export type AiRoleId = "scan" | "analyst" | "editor" | "judge";
export type AiRoleProvider = Exclude<JudgeProvider, "off">;
export type AiEffort = "" | "low" | "medium" | "high";
export type AiImages = "mosaic" | "frames" | "none";
export type ContextCheckId = "setup" | "payoff" | "who_what" | "standalone" | "intelligible" | "faithful" | "strong_open";
export type AiRole = {
enabled: boolean;
provider: AiRoleProvider;
/** "" = padrão do provedor. */
model: string;
/** Raciocínio (só Codex); "" = padrão (baixo). */
effort: AiEffort;
/** Instruções do administrador, somadas às padrão (podem ser em português). */
extra: string;
/** Só varredura e analista. */
images?: AiImages;
// Só o juiz: checagens críticas, se pode ajustar o trecho e pôr frase de contexto, e quanto cada checagem
// não crítica tira da nota.
critical?: ContextCheckId[];
allowFix?: boolean;
allowContextLine?: boolean;
penalty?: number;
/** Só leitura (o serviço calcula): modelo efetivo e a ordem de tentativa (reserva) deste papel. */
resolvedModel?: string;
chain?: AiRoleProvider[];
};
export type AiRoles = Record<AiRoleId, AiRole>;
export type JudgeConfig = {
provider: JudgeProvider;
/** Modelo do EDITOR (2º juiz). null com o juiz desligado. */
@@ -41,8 +73,37 @@ export type JudgeConfig = {
fallback?: { enabled: boolean; cooldownMin: number; chain: Exclude<JudgeProvider, "off">[] };
/** IAs em pausa depois de falha de indisponibilidade (`until` em ISO, UTC). */
pauses?: JudgePause[];
/** Equipe de IA (serviço novo): cada papel com a sua IA. Ausente = serviço antigo (um provedor só). */
roles?: AiRoles;
/** Instruções padrão de cada papel nos dois idiomas (só leitura). Só em GET/PUT /judge. */
roleDefaults?: Record<AiRoleId, { pt: string; en: string }>;
/** Checagens do juiz de contexto (id + nome em português). */
checks?: { id: ContextCheckId; label: string }[];
/** Situação de cada IA (Configurações → IA): ligada, pronta e por que não. */
providers?: Partial<Record<AiRoleProvider, { ready: boolean; reason: string | null; enabled: boolean }>>;
};
/** GET /judge/report: medição da Equipe de IA (F0) — chamadas e tokens por papel, decisões do juiz e concordância com você. */
export type AiReport = {
window: { days: number; since: string | null; sessionId: number | null; liveHours: number };
calls: {
role: string; purpose: string; provider: string; model: string; mode: string; calls: number; failures: number;
avgChars: number; avgImages: number; imageKB: number; tokensIn: number | null; tokensOut: number | null;
tokensCached: number | null; withUsage: number; avgMs: number;
}[];
perHour: Record<string, { calls: number | null; tokensIn: number | null; tokensOut: number | null; estTokensIn: number | null }>;
clips: { total: number; byStatus: Partial<Record<ClipStatus, number>>; approvalRate: number | null; labeled: number; noContext: number };
judge: { approve: number; adjust: number; discard: number; warn: number; error: number; contextLine: number };
agreement: Record<"judge" | "editor", AiAgreement>;
};
export type AiAgreement = {
pairs: number; agree: number; rate: number | null; kappa: number | null;
matrix: Record<"keep" | "discard", Record<OwnerLabel, number>>;
};
/** Sua avaliação do corte (conjunto de avaliação do juiz). */
export type OwnerLabel = "good" | "bad" | "no_context";
export type JudgePause = { provider: Exclude<JudgeProvider, "off">; until: string; reason: string };
export type ClipperChannel = {
@@ -173,9 +234,42 @@ export type ClipJudge = null
model: string; keep: boolean; score: number; reason: string; analysis?: ClipAnalysis | null; analystModel?: string;
/** Fonte em inglês: título, legenda e motivo em português (só para ler; o post sai em inglês). */
pt?: { title?: string; caption?: string; reason?: string };
/** Juiz de contexto (EQUIPE-IA.md). Ausente = juiz desligado, editor descartou ou corte de antes. */
context?: ClipContext;
/** "context" = quem descartou foi o juiz de contexto (dá para forçar o render). */
discardedBy?: "context";
}
| { error: string };
export type ContextCheck = { ok: boolean; t: number | null; why: string };
export type ClipContext =
| { error: string }
| {
model: string;
/** O que um espectador que nunca viu a live entende (escrito antes das checagens). */
viewerSummary: string;
checks: Partial<Record<ContextCheckId, ContextCheck>>;
fix: { start_s: number | null; end_s: number | null; context_line: string };
confidence: number;
reason: string;
/** Fonte em inglês: resumo, motivo, frase e o porquê de cada checagem em português. */
pt?: { viewer_summary?: string; reason?: string; context_line?: string; checks?: Partial<Record<ContextCheckId, string>> };
/** O que o código decidiu pelas respostas. */
decision: "approve" | "adjust" | "discard" | "warn";
failed: ContextCheckId[];
failedCritical: ContextCheckId[];
solvedByLine: ContextCheckId[];
/** Frase de contexto que vai na tela no começo do corte ("" = nenhuma). */
contextLine: string;
scoreAfter: number | null;
/** Motivo da decisão, em português (montado pelo código). */
reasonPt: string;
/** Trecho novo quando o juiz ajustou. */
window?: [number, number];
/** 1ª rodada, quando houve ajuste (o juiz conferiu de novo). */
first?: { viewerSummary: string; checks: Partial<Record<ContextCheckId, ContextCheck>>; failedCritical: ContextCheckId[]; reasonPt: string };
};
export type ClipTags = { risada?: number; susto?: number; hype?: number; clip?: number };
export type Clip = {
@@ -227,6 +321,9 @@ export type Clip = {
final?: ClipFinal | null;
/** O único arquivo que vai para as redes: o final pronto. null = ainda não (a publicação espera). */
publishFile?: string | null;
/** Sua avaliação (bom / ruim / sem contexto) para medir o juiz. Opcional: o serviço antigo não manda. */
ownerLabel?: OwnerLabel | null;
ownerNote?: string | null;
};
export type ClipFinal = {
@@ -525,6 +622,26 @@ export const TAG_LABEL: Record<keyof ClipTags, string> = { risada: "risada", sus
export const PROVIDER_LABEL: Record<JudgeProvider, string> = { codex: "Codex (GPT)", claude: "Claude", gemini: "Gemini", off: "Desligado" };
/** Equipe de IA: nome e o que cada papel faz (cartões da configuração). */
export const ROLE_INFO: Record<AiRoleId, { label: string; does: string }> = {
scan: { label: "Varredura", does: "Assiste a live por janelas e propõe momentos mesmo sem pico de chat; descreve a tela para a linha do tempo." },
analyst: { label: "Analista", does: "Olha tela, fala e chat do trecho e diz o que aconteceu (lag, jogada, treta…). Não decide." },
editor: { label: "Editor", does: "Decide se vira corte, escolhe o trecho e escreve título, legenda e hashtags." },
judge: { label: "Juiz", does: "Só texto: vê o que vai no corte e confere se quem nunca viu a live entende — começo, desfecho, funciona sozinho." },
};
export const ROLE_ORDER: AiRoleId[] = ["scan", "analyst", "editor", "judge"];
export const CHECK_LABEL: Record<ContextCheckId, string> = {
setup: "começo (setup)", payoff: "desfecho", who_what: "quem/o quê", standalone: "funciona sozinho",
intelligible: "fala clara", faithful: "título fiel", strong_open: "abertura forte",
};
export const OWNER_LABEL: Record<OwnerLabel, { label: string; tone: Tone }> = {
good: { label: "Bom", tone: "success" }, bad: { label: "Ruim", tone: "danger" }, no_context: { label: "Sem contexto", tone: "warning" },
};
export const CONTEXT_DECISION: Record<"approve" | "adjust" | "discard" | "warn", { label: string; tone: Tone }> = {
approve: { label: "aprovou", tone: "success" }, adjust: { label: "ajustou o trecho", tone: "info" },
discard: { label: "descartou", tone: "danger" }, warn: { label: "avisou", tone: "warning" },
};
/** Sessões que ainda mudam sozinhas (vale consultar de novo). */
export const ACTIVE_SESSION: SessionStatus[] = ["starting", "recording", "processing"];
/** Cortes que ainda mudam sozinhos (IA ou render). */