Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | INFRASTRUCTURE & AUTOMATION4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : MacLustr Social Engine & Remote Navigator8 * File : apps/social-web/src/types.ts9 * Module : social-web10 * Repository : https://git.spboucher.ai/maclustr-social11 * Project Website : https://social.spboucher.ai12 * Created : 2026-12-0113 * Last Modified : 2026-12-0114 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: admin@spboucher.ai23 * Technical Contact: dev@spboucher.ai24 * Security/Admin : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142// Row shapes as returned by the control API (snake_case PostgreSQL rows). Kept loose on purpose:43// the server is the authority, the UI never invents a field.44import type { JobMode, JobState, Role, SessionState } from '@mls/contracts';4546export type Lang2 = 'fr' | 'en';47export type Brand = { id: string; slug: string; name: string; tone: string; languages: Lang2[]; official_urls: string[]; categories: string[]; identity: { primary: string; ink: string; paper: string; wordmark: string }; frequency: { maxPerDay: number; minIntervalMinutes: number }; validation: { approvalsRequired: number; allowSelfApproval: boolean }; timezone: string; status: string; confirmed_pages?: number; created_at: string; updated_at: string };48export type Automation = { level: 'forbidden' | JobMode; basis: string };49export type Page = { id: string; brand_id: string; platform: 'facebook' | 'fixture'; display_name: string; url: string; composer_url: string | null; external_page_id: string | null; status: 'unconfirmed' | 'confirmed' | 'retired'; confirmed_at: string | null; created_at: string; automation?: Automation };50export type Member = { user_id: string; role: Role; handle: string; display_name: string };51export type Campaign = { id: string; brand_id: string; name: string; objective: string; starts_at: string | null; ends_at: string | null; status: string; created_at: string };52export type ContentState = 'DRAFT' | 'REVIEW' | 'APPROVED';53export type ContentRow = { id: string; brand_id: string; campaign_id: string | null; page_id: string | null; title: string; state: ContentState; current_version_id: string; source_event_id: string | null; created_by: string | null; created_at: string; updated_at: string; version: number; lang: Lang2; body: string; link_url: string | null; media_sha256: string[]; alt_text: string | null; content_hash: string; author_kind: 'user' | 'agent' };54export type ContentVersion = { id: string; content_id: string; version: number; lang: Lang2; body: string; link_url: string | null; media_sha256: string[]; alt_text: string | null; content_hash: string; author_kind: 'user' | 'agent'; author_id: string; created_at: string };55export type Approval = { id: string; version_id: string; content_hash: string; page_id: string; approver_id: string; approver: string; decision: 'approve' | 'reject'; comment: string; created_at: string; invalidated_at: string | null; invalidated_reason: string | null };56export type Finding = { severity: 'info' | 'warning' | 'blocker'; issue: string; evidence: string };57export type Check = { id: string; agent: string; status: string; output: { findings?: Finding[]; deterministicOnly?: boolean; verdict?: string } | null; error: string | null; started_at: string; target_id: string };58export type Job = { id: string; brand_id: string; content_id: string; version_id: string; content_hash: string; page_id: string; scheduled_at: string; mode: JobMode; state: JobState; state_reason: string; prepare_attempts: number; dead_letter: boolean; cancel_requested_at: string | null; cancelled_after_submission: boolean; created_at: string; updated_at: string; title?: string; page_name?: string; page_url?: string; platform?: string; brand_name?: string; timezone?: string };59export type ContentDetail = { item: Omit<ContentRow, 'version' | 'lang' | 'body' | 'link_url' | 'media_sha256' | 'alt_text' | 'content_hash' | 'author_kind'>; versions: ContentVersion[]; approvals: Approval[]; checks: Check[]; jobs: Job[] };60export type PendingApproval = { id: string; title: string; brand_id: string; page_id: string | null; created_by: string | null; version_id: string; version: number; lang: Lang2; body: string; link_url: string | null; media_sha256: string[]; alt_text: string | null; content_hash: string; author_kind: 'user' | 'agent'; author_id: string; page_name: string | null; page_status: string | null; brand_name: string };61export type Media = { id: string; brand_id: string; sha256: string; mime: string; width: number; height: number; bytes: number | string; original_name: string; rights: { owner?: string; license?: string; source?: string; attestedAt?: string } | null; status: 'pending' | 'approved' | 'rejected'; alt_text: string | null; created_at: string; url?: string; duplicate?: boolean; strippedMetadata?: unknown };62export type Attempt = { id: string; n: number; phase: string; worker_id: string | null; started_at: string; ended_at: string | null; outcome: string | null; error: string | null; steps: unknown[] };63export type Receipt = { id: string; kind: 'observed' | 'human_attested' | 'evidence'; external_url: string | null; external_id: string | null; evidence_ref: string | null; evidence_sha256: string | null; label: string; attested_by: string | null; created_at: string; evidence_url: string | null };64export type JobDetail = { job: Job; content: { lang: Lang2; body: string; linkUrl: string | null; mediaSha256: string[]; altText: string | null }; attempts: Attempt[]; receipts: Receipt[]; notice: string | null };65export type ReplyDraft = { id: string; comment_id: string; body: string; lang: string; state: 'draft' | 'approved' | 'discarded' | 'posted_manually'; author_kind: string; author_id: string; created_at: string };66export type CommentRow = { id: string; brand_id: string; page_id: string; external_ref: string; body: string; sensitivity: 'unclassified' | 'routine' | 'sensitive'; sensitivity_reasons: string[]; status: 'open' | 'human_required' | 'drafted' | 'closed'; source: string; captured_at: string; drafts: ReplyDraft[] | null };67/** `value` is a PostgreSQL numeric: it arrives as a string, or null when unavailable. */68export type Snapshot = { id?: string; page_id: string; content_id: string | null; metric: string; value: string | number | null; availability: 'available' | 'unavailable'; period_start: string; period_end: string; source: string; captured_at: string; page_name?: string };69export type BrandReport = { generatedAt: string; snapshots: Snapshot[]; campaigns: { id: string; name: string; contents: number; verified: number }[]; perCampaign: { campaign_id: string; metric: string; total: number | null; n: number; missing: number }[]; caveats: string[] };70export type AgentRunResult = { runId: string; agent: string; authority: string; status: string; output: any; error?: string; llm: { status: string; model: string; costUsd: number } | null };71export type AgentRun = { id: string; agent: string; brand_id: string | null; provider: string; model: string; status: string; error: string | null; tokens_in: number; tokens_out: number; cost_usd: string | number; target_kind: string | null; target_id: string | null; started_at: string; ended_at: string | null; output: unknown };72export type SessionRow = { id: string; state: SessionState; wanted: 'running' | 'stopped'; start_url: string | null; scope_page_ids: string[]; confirmed_at: string | null; state_reason: string; state_at: string; last_url_host: string | null; created_at: string; label: string; worker_id: string; worker_name: string; worker_status: string; lease: { holderKind: 'human' | 'agent'; holderId: string; expiresAt: string } | null };73export type Worker = { id: string; name: string; host: string; status: 'online' | 'offline' | 'disabled'; last_heartbeat_at: string | null; info: { version?: string; headed?: boolean; freeDiskGb?: number; axPermission?: boolean; screenPermission?: boolean } | null; created_at: string };74export type AuditEvent = { id: string | number; at: string; correlation_id: string; actor_kind: string; actor_id: string; action: string; target_kind: string; target_id: string; brand_id: string | null; result: string; detail: unknown; hash: string };75export type Alert = { id: string; severity: 'info' | 'warning' | 'critical'; kind: string; message: string; brand_id: string | null; status: string; created_at: string };76export type Overview = { generatedAt: string; emergency: { emergency_stop: boolean; reason: string; changed_at: string }; content: { state: string; n: number }[]; jobs: { state: string; n: number }[]; upcoming: { id: string; scheduled_at: string; state: JobState; mode: JobMode; title: string; brand_name: string; timezone: string }[]; needsHuman: { id: string; state: JobState; state_reason: string; title: string }[]; pendingApprovals: number; comments: { status: string; n: number }[]; sessions: { state: string; n: number }[] | null; workers: { status: string; n: number }[] | null; alerts: Alert[] };77export type SourceEvent = { id: string; brand_id: string; kind: string; source: string; payload: unknown; public_ok: boolean; status: string; created_at: string };78export type GitSource = { id: string; brand_id: string; repo: string; enabled: boolean; last_polled_at: string | null; last_error: string | null };79export type UserRow = { id: string; handle: string; display_name: string; role: Role; status: string; created_at: string; passkeys: number };80export type Recipe = { id: string; slug: string; title: string; purpose: string; platform: string; versions: { id: string; version: number; status: string; origin: string; sha256: string; validated_at: string | null; created_at: string }[] | null };81