All files / src/objects Decision.tsx

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

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 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378                                                                                                                                                                                                                                                          15x                                                                                                                                                                                                                                                                                                                                                                                                                                     15x                                                                                  
/**
 * The decision record — one governed turn (an answer or a skill run), read
 * back from every row that carries its id: svc-core `GET /app/decisions/:id`
 * (`app/services/decisions`). What "Why did it do this?" opens.
 *
 * Each section says through `status` whether it holds what the turn
 * recorded, found nothing, or cannot say, and why in `note`. A gap reads as
 * a gap, never as an empty list.
 */
 
import type { TestCase } from "@/objects/Evaluation";
import type { GovernanceEvent } from "@/objects/Governance";
import type { SearchReport, WebSearchSummary } from "@/objects/WebSearch";
import type { AttachmentRef } from "@/objects/Model";
import type { HitlExchange } from "@/objects/Hitl";
import type { QualityOutcome } from "@/objects/Model";
import type { ReviewFlag } from "@/objects/Review";
 
export type DecisionKind = "answer" | "skill_run" | "swarm_task";
 
/** Why the reader may read it: their own turn, or one flagged for them to
 *  review (and so logged). */
export type DecisionAccess = "owner" | "reviewer";
 
/** svc-core `DecisionEnum.SectionStatus`. */
export type DecisionSectionStatus =
  | "recorded"
  | "empty"
  | "not_recorded"
  | "unavailable";
 
interface SectionBase {
  title: string;
  status: DecisionSectionStatus;
  note?: string | null;
}
 
export interface RequestSection extends SectionBase {
  key: "request";
  prompt?: string | null;
  /** The chat command the turn ran (svc-core `chat_commands`). */
  command?: Record<string, unknown> | null;
  /** The documents the message attached, by id — never their text. */
  attachments?: AttachmentRef[] | null;
  task?: string | null;
  inputs?: Record<string, unknown> | null;
}
 
export interface AnswerSection extends SectionBase {
  key: "answer";
  /** The message's status (completed / blocked / error) or the run's. */
  outcome?: string | null;
  content?: string | null;
  outputs?: Record<string, unknown> | null;
  stopped?: boolean;
  blocked_by?: string | null;
  error?: string | null;
}
 
export interface ConfigurationSection extends SectionBase {
  key: "configuration";
  agent_id?: string | null;
  agent_name?: string | null;
  agent_version?: number | null;
  skill_id?: string | null;
  skill_name?: string | null;
  skill_version?: number | null;
  ai_model_id?: string | null;
  provider?: string | null;
  model_name?: string | null;
  /** The cost profile the agent ran under (`thorough` when it named none). */
  cost_profile?: string | null;
  /** Set when an Economy profile's lighter model wrote the answer. */
  lighter_model?: { answered?: boolean; reason?: string } | null;
}
 
export interface RulesSection extends SectionBase {
  key: "rules";
  events: GovernanceEvent[];
  outcomes: Record<string, number>;
}
 
/** One web search the turn made, as svc-ai recorded the call. */
export interface DecisionWebSearch {
  created_at?: string | null;
  /** What the agent searched for. */
  query?: string | null;
  /** None for a search recorded before reports were kept. */
  report?: SearchReport | null;
}
 
export interface WebSourcesSection extends SectionBase {
  key: "web_sources";
  searches: DecisionWebSearch[];
  /** The turn's searches together, with what each Tools rule did. */
  summary?: WebSearchSummary | null;
}
 
export interface QualityCheckSection extends SectionBase {
  key: "quality_check";
  outcome?: QualityOutcome | null;
  /** Uncalibrated: a reading, never a confidence. */
  score?: number | null;
  critique?: string | null;
  gaps: string[];
}
 
export interface HumanInputSection extends SectionBase {
  key: "human_input";
  exchanges: HitlExchange[];
  /** A pause still waiting for an answer. */
  pending?: Record<string, unknown> | null;
}
 
export interface ReviewsSection extends SectionBase {
  key: "reviews";
  flags: ReviewFlag[];
}
 
/** A person's verdict on an answer or a run (svc-core
 *  `DecisionEnum.Verdict`). */
export type DecisionVerdict = "accepted" | "edited" | "rejected";
 
/** How each verdict reads on a page. "Corrected" rather than "Edited": what
 *  the person did was say what the answer should have been. */
export const VERDICT_LABELS: Record<DecisionVerdict, string> = {
  accepted: "Accepted",
  edited: "Corrected",
  rejected: "Rejected",
};
 
export interface DecisionOutcome {
  id: string;
  verdict: DecisionVerdict;
  /** The answer as it should have been (`edited`). */
  corrected_text?: string | null;
  /** The business outcome the team attached. */
  label?: string | null;
  note?: string | null;
  /** On the answer, or while resolving a review flag. */
  source: "answer" | "review";
  review_flag_id?: string | null;
  actor_user_id: string;
  actor_name?: string | null;
  created_at: string;
}
 
/** A dataset case made from this turn ("Add to dataset"). */
export interface DecisionCaseRef {
  case_id: string;
  test_suite_id: string;
  test_suite_name?: string | null;
  created_at?: string | null;
}
 
export interface OutcomeSection extends SectionBase {
  key: "outcome";
  /** The turn's verdict: the newest. */
  current?: DecisionOutcome | null;
  /** Every verdict, oldest first. */
  history: DecisionOutcome[];
  cases: DecisionCaseRef[];
}
 
/** A verdict to record. `corrected_text` is required for `edited`. */
export interface OutcomeCreate {
  verdict: DecisionVerdict;
  corrected_text?: string;
  label?: string;
  note?: string;
}
 
export interface DecisionCaseCreate {
  test_suite_id: string;
  /** On unless turned off. */
  redact_pii?: boolean;
}
 
export interface DecisionCaseCreated {
  case: TestCase;
  /** Values redacted, by kind of personal data. */
  redacted: Record<string, number>;
}
 
/** A knowledge lane's search, as the record keeps it: counts only, never a
 *  query or a passage. */
export interface DecisionLaneStep {
  /** `domain` / `temporal` / `reasoning`. */
  category: string;
  /** `primary` / `supporting` / `method`; empty before roles. */
  role: string;
  knowledge_bases: number;
  queries: number;
  found: number;
  judged: number;
  ruled_out: number;
  out_of_window: number;
  handed_on: number;
  /** What the join packed of it; absent when the join was not recorded. */
  packed?: number | null;
  judge_failure?: string | null;
  failure?: string | null;
}
 
export interface DecisionStep {
  node_id: string;
  /** `system` for the platform's own nodes, `node` for the agent's or a
   *  skill's. */
  kind: string;
  model_name?: string | null;
  provider?: string | null;
  input_tokens?: number | null;
  output_tokens?: number | null;
  duration_ms?: number | null;
  error?: boolean;
  output_preview?: string | null;
  tools: string[];
  /** Earlier turns its model could not be sent: the conversation was fitted
   *  to the model's window and price tier. Absent when it got them all. */
  history_turns_omitted?: number | null;
  /** Set on a knowledge lane's step. */
  lane?: DecisionLaneStep | null;
}
 
export interface StepsSection extends SectionBase {
  key: "steps";
  steps: DecisionStep[];
}
 
export interface DecisionModelCall {
  provider: string;
  model_name: string;
  model_display_name?: string | null;
  node?: string | null;
  kind?: string;
  purpose?: string | null;
  prompt_tokens: number;
  completion_tokens: number;
  cache_read_tokens: number;
  cache_write_tokens: number;
  reasoning_tokens: number;
  latency_ms?: number | null;
  status: string;
  error_detail?: string | null;
  /** Null when the call could not be priced — never 0 for that. */
  estimated_cost_usd?: number | null;
}
 
export interface ModelCallsSection extends SectionBase {
  key: "model_calls";
  calls: DecisionModelCall[];
}
 
export interface DecisionCitation {
  index: number;
  source_type: string;
  source: string;
  title: string;
  collection?: string | null;
  relevance_score?: number | null;
}
 
export interface DecisionToolCall {
  tool_name: string;
  created_at?: string | null;
  input_args?: Record<string, unknown> | null;
  output?: string | null;
  /** The output was cut for the record. */
  truncated?: boolean;
  latency_ms?: number | null;
  status: string;
  error_detail?: string | null;
  citations: DecisionCitation[];
  /** A web search's report. */
  report?: SearchReport | null;
}
 
export interface ToolCallsSection extends SectionBase {
  key: "tool_calls";
  calls: DecisionToolCall[];
}
 
export interface DecisionLedgerEntry {
  occurred_at?: string | null;
  execution_type?: string | null;
  outcome: string;
  input_tokens: number;
  output_tokens: number;
  estimated_cost_usd?: number | null;
  llm_calls: number;
  unpriced_calls: number;
  latency_ms?: number | null;
}
 
export interface CostSection extends SectionBase {
  key: "cost";
  entries: DecisionLedgerEntry[];
  /** The priced part; a lower bound when `complete` is false. */
  cost_usd?: number | null;
  complete: boolean;
  input_tokens: number;
  output_tokens: number;
}
 
export interface DecisionReadLog {
  reader_user_id: string;
  reader_name?: string | null;
  access: string;
  flag_id?: string | null;
  read_at: string;
}
 
export interface ReadsSection extends SectionBase {
  key: "reads";
  reads: DecisionReadLog[];
}
 
export type DecisionSection =
  | RequestSection
  | AnswerSection
  | ConfigurationSection
  | RulesSection
  | WebSourcesSection
  | QualityCheckSection
  | HumanInputSection
  | ReviewsSection
  | OutcomeSection
  | StepsSection
  | ModelCallsSection
  | ToolCallsSection
  | CostSection
  | ReadsSection;
 
/** Every section key svc-core serves, in reading order. Pinned to its
 *  registry (`app/services/decisions/sections.py`) by svc-core's
 *  `tests/test_decision_record.py`. */
export const DECISION_SECTION_KEYS = [
  "request",
  "answer",
  "configuration",
  "rules",
  "web_sources",
  "quality_check",
  "human_input",
  "reviews",
  "outcome",
  "steps",
  "model_calls",
  "tool_calls",
  "cost",
  "reads",
] as const;
 
export type DecisionSectionKey = (typeof DECISION_SECTION_KEYS)[number];
 
export interface Decision {
  /** The turn's `invocation_id`. */
  id: string;
  kind: DecisionKind;
  access: DecisionAccess;
  /** The agent, model or skill that answered, by name. */
  subject?: string | null;
  status: string;
  started_at?: string | null;
  finished_at?: string | null;
  conversation_id?: string | null;
  /** The answer's message (the assistant's). */
  message_id?: string | null;
  agent_id?: string | null;
  ai_model_id?: string | null;
  skill_id?: string | null;
  skill_run_id?: string | null;
  /** For a swarm task: the run it belongs to, and the task. */
  swarm_run_id?: string | null;
  swarm_task_id?: string | null;
  sections: DecisionSection[];
}