All files / src/objects Activity.tsx

100% Statements 5/5
100% Branches 0/0
100% Functions 0/0
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251                                                                                                                                                                                                          104x                                                                                     104x                                           104x                                                                                                                                         104x             104x                
import {
  ChildrenDiffEntry,
  FieldDiff,
  GenerationRef,
  HistoryAction,
} from "@/objects/History";
 
/**
 * Which resource a change event was about — mirrors svc-core's
 * `HistoryEnum.ResourceType`.
 *
 * Pinned to a union rather than left as `string` so the label/icon maps below
 * are exhaustive by construction: adding a resource type to svc-core and
 * forgetting the frontend becomes a type error rather than an "Unknown" row.
 */
export type ActivityResourceType =
  | "agent"
  | "toolkit"
  | "skillset"
  | "skill"
  | "tool"
  | "mcp_server"
  | "custom_worker"
  | "knowledge"
  | "knowledge_repository"
  | "rule"
  | "pipeline"
  | "experiment"
  | "test_suite"
  | "simulation_world"
  | "dashboard"
  | "project"
  | "organisation"
  | "uploaded_file"
  | "swarm";
 
/** One resource change from `/app/activity`. */
export interface ActivityEvent {
  id: string;
  resource_type: ActivityResourceType;
  resource_id: string;
  /** Read from the version snapshot, so deleted resources keep a label. */
  resource_name?: string | null;
  action: HistoryAction;
  version_number: number;
  changed_fields: string[];
  actor_user_id?: string | null;
  actor_name?: string | null;
  actor_email?: string | null;
  is_ai_generated?: boolean | null;
  generation_id?: string | null;
  generation?: GenerationRef | null;
  created_at?: string | null;
}
 
export interface ActivityEventList {
  events: ActivityEvent[];
  total: number;
}
 
/**
 * One change with the payload a detail panel needs — the snapshot as it stood
 * and the server-computed diff against the version before it.
 */
export interface ActivityEventDetail extends ActivityEvent {
  snapshot: Record<string, unknown>;
  children_snapshot?: Record<string, unknown> | null;
  diff?: {
    from_version: number | null;
    to_version: number;
    fields: FieldDiff[];
    children_diff: Record<string, ChildrenDiffEntry>;
  } | null;
}
 
export interface ActivityTypeCount {
  resource_type: ActivityResourceType;
  count: number;
}
 
export interface ActivitySummary {
  total: number;
  created: number;
  updated: number;
  deleted: number;
  ai_generated: number;
  by_resource_type: ActivityTypeCount[];
}
 
export interface ActivityQuery {
  resource_type?: ActivityResourceType[];
  action?: HistoryAction;
  generated_only?: boolean;
  /** ISO timestamp; events at or after it. */
  since?: string;
  search?: string;
  limit?: number;
  offset?: number;
}
 
/** Display labels for resource types — the raw enum values read as code. */
export const RESOURCE_TYPE_LABELS: Record<ActivityResourceType, string> = {
  agent: "Agent",
  toolkit: "Toolkit",
  skillset: "Skillset",
  skill: "Skill",
  tool: "Tool",
  mcp_server: "MCP Server",
  custom_worker: "Worker",
  knowledge: "Knowledge Base",
  knowledge_repository: "Knowledge Repository",
  rule: "Rule",
  pipeline: "Pipeline",
  // What the product calls them now: the section is "Evaluation", the list
  // is "Evaluations", and a test suite is a "Dataset". The enum names stay.
  experiment: "Evaluation",
  test_suite: "Dataset",
  simulation_world: "Simulation World",
  dashboard: "Dashboard",
  project: "Project",
  organisation: "Organisation",
  // A document in a workspace's library, attached to chats.
  uploaded_file: "Document",
  // A team of agents in a shape, sent on a long task.
  swarm: "Swarm",
};
 
/**
 * Which part of the platform a resource type belongs to.
 *
 * Drives the "domain" filter — seventeen resource types is too many to offer
 * as a flat filter row, and an operator asking "what changed in my knowledge
 * setup?" does not want to tick four boxes to ask it.
 */
export type ActivityDomain =
  | "inference"
  | "knowledge"
  | "governance"
  | "evaluation"
  | "workspace";
 
export const RESOURCE_TYPE_DOMAIN: Record<
  ActivityResourceType,
  ActivityDomain
> = {
  agent: "inference",
  skill: "inference",
  skillset: "inference",
  toolkit: "inference",
  tool: "inference",
  custom_worker: "inference",
  mcp_server: "inference",
  pipeline: "inference",
  knowledge: "knowledge",
  knowledge_repository: "knowledge",
  rule: "governance",
  experiment: "evaluation",
  test_suite: "evaluation",
  simulation_world: "evaluation",
  dashboard: "workspace",
  project: "workspace",
  organisation: "workspace",
  uploaded_file: "knowledge",
  swarm: "inference",
};
 
export const ACTIVITY_DOMAIN_LABELS: Record<ActivityDomain, string> = {
  inference: "Inference",
  knowledge: "Knowledge",
  governance: "Governance",
  evaluation: "Evaluation",
  workspace: "Workspace",
};
 
// ─── Background activity ──────────────────────────────────────────────────────
 
/** What kind of background work an event records — mirrors svc-core's
 *  `BackgroundEnum.Kind`. */
export type BackgroundKind =
  | "widget_refresh"
  | "knowledge_crawl"
  | "review_retention";
 
/** Why it ran — mirrors `BackgroundEnum.Trigger`. */
export type BackgroundTrigger =
  | "scheduled"
  | "view"
  | "manual"
  | "created"
  | "updated"
  | "granted";
 
export type BackgroundStatus = "ok" | "failed";
 
/**
 * One piece of work the platform did for the caller outside a request — a
 * dashboard tile regenerated, a website source re-crawled, review flags
 * deleted by retention. From `/app/activity/background`.
 */
export interface BackgroundEvent {
  id: string;
  kind: BackgroundKind;
  trigger: BackgroundTrigger;
  status: BackgroundStatus;
  /** In the resource vocabulary above (`dashboard`, `knowledge`), so it links
   *  the way a resource change does. */
  subject_type?: ActivityResourceType | null;
  subject_id?: string | null;
  subject_name?: string | null;
  summary: string;
  detail?: Record<string, unknown> | null;
  /** Finer-grained ids: `widget_id` for a refresh, `crawl_id` for a crawl. */
  reference?: Record<string, string> | null;
  error?: string | null;
  started_at?: string | null;
  finished_at: string;
  duration_ms?: number | null;
}
 
export interface BackgroundEventList {
  events: BackgroundEvent[];
  total: number;
  /** Days a record is kept before svc-core's retention job deletes it;
   *  null when retention is off. */
  retention_days?: number | null;
}
 
export interface BackgroundQuery {
  kind?: BackgroundKind[];
  /** ISO timestamp; events finished at or after it. */
  since?: string;
  limit?: number;
  offset?: number;
}
 
export const BACKGROUND_KIND_LABELS: Record<BackgroundKind, string> = {
  widget_refresh: "Dashboard refresh",
  knowledge_crawl: "Website crawl",
  review_retention: "Review retention",
};
 
/** How each trigger reads after "why": "Scheduled", "Board opened", … */
export const BACKGROUND_TRIGGER_LABELS: Record<BackgroundTrigger, string> = {
  scheduled: "Scheduled",
  view: "Board opened",
  manual: "Refresh now",
  created: "Just added",
  updated: "Settings changed",
  granted: "Granted to an agent",
};