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 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 | 240x 233x 275x 19x 4x 4x 3x 3x 64x 13x 6x 64x 64x 52x 42x 10x 64x 16x 11x 8x 6x 2x 2x 4x 2x 9x 3x 3x 2x 2x 2x 2x 64x 49x | import {
ClarifyAnswers,
ClarifyQuestion,
ClarifySource,
HitlExchange,
HitlInterruptType,
HitlOutcome,
NodeHitl,
} from "@/objects/Hitl";
import { Doc } from "./Doc";
import type { ChatCommandRecord } from "./ChatCommand";
import type { DecisionVerdict } from "./Decision";
import type { GovernanceOutcome } from "./Governance";
import type { RuleLayer, RuleScope } from "./Rule";
import type { SearchReport, WebSearchSummary } from "./WebSearch";
import { parseServerDate } from "@/util/time";
export type DataRegion = "uk" | "eu" | "us" | "global";
/**
* Whose service runs a model on this deployment — svc-ai's inference
* backends (`inference_routes.BACKENDS`): the vendor's own API, or Amazon
* Bedrock. A model keeps its vendor as its provider on either.
*/
export type InferenceBackend = "direct" | "bedrock";
/**
* How much reasoning a model brings, as a band that means the same thing
* across providers — svc-ai's `ModelEnum.Effort`.
*
* Providers name their tiers differently (Claude Haiku / Sonnet / Opus /
* Fable, GPT Luna / Terra / Sol / Astra) and the names say nothing to
* somebody comparing the two. The band does, which is what makes it a
* filter rather than a label.
*/
export type ModelEffort = "light" | "balanced" | "deep" | "frontier";
/**
* Comparative response speed within the catalogue — svc-ai's
* `ModelEnum.Latency`. A position relative to the other models, not a
* measured figure: real latency moves with prompt length, output length and
* reasoning effort.
*/
export type ModelLatency = "fastest" | "fast" | "moderate" | "slower";
export interface ModelProvider {
id: string;
name: string;
display_name: string;
base_url: string | null;
is_enabled: boolean;
}
export interface Model extends Doc {
/** Whether the model honours an explicit `temperature` — the newest
* Anthropic and OpenAI reasoning models reject it. From svc-ai's
* capability table; absent from an older svc-ai. */
supports_temperature?: boolean | null;
/** Whether the model takes a reasoning-effort level. */
supports_effort?: boolean | null;
/** Whose service runs it here, so who receives a prompt to it: the
* provider is the model's vendor whichever it is. Absent from an older
* svc-ai, which only ever called the vendor. */
inference_backend?: InferenceBackend | null;
provider_id: string;
provider: ModelProvider;
model_name: string;
display_name: string | null;
description: string | null;
is_chat: boolean;
is_embedding: boolean;
is_vision: boolean;
is_available: boolean;
is_default: boolean;
is_recommended: boolean;
context_window: number | null;
max_output_tokens: number | null;
input_cost_per_token: string | null;
output_cost_per_token: string | null;
/** Per-token rates for cached input, cache writes and (Anthropic) 1-hour
* cache writes — each the model's own rate, not a multiplier. */
cache_read_cost_per_token?: string | null;
cache_write_cost_per_token?: string | null;
cache_write_1h_cost_per_token?: string | null;
/** Prompt size past which the whole request is repriced by the two
* multipliers (OpenAI's 272K tier); null when the model has no tier. */
long_context_threshold?: number | null;
long_context_input_multiplier?: string | null;
long_context_output_multiplier?: string | null;
data_region: DataRegion | null;
effort: ModelEffort | null;
latency: ModelLatency | null;
/** Reliable knowledge cutoff, ISO date (`YYYY-MM-DD`). */
knowledge_cutoff: string | null;
config: Record<string, unknown> | null;
created_at?: string;
updated_at?: string;
/** Set when svc-ai took the model out of the catalogue. Archived models
* arrive only from `model_router.list({ includeArchived: true })`, to
* name what old conversations and traces ran on. */
archived_at?: string | null;
}
/** Returns the best display label for a model. */
export function modelDisplayName(model: Model): string {
return model.display_name ?? model.model_name;
}
/**
* Whether a model may be offered to run: a chat model this deployment
* serves. An unavailable one (a model with no route on the inference
* backend, such as GPT on Amazon Bedrock) stays in the catalogue, since old
* conversations, runs and variants name it, but no picker offers it. Only
* an explicit `false` rules a model out, as these pickers always read it.
*/
export function isSelectableModel(model: Model): boolean {
return model.is_chat !== false && model.is_available !== false;
}
/** The models a picker offers: the selectable ones, plus the current choice
* if it no longer is, so an existing selection still reads as itself. */
export function selectableModels(
models: readonly Model[],
current?: string | null,
): Model[] {
return models.filter((m) => isSelectableModel(m) || (!!current && m.id === current));
}
/**
* Formats a per-token cost string (e.g. "0.0000025000") as a human-readable
* per-million-token price (e.g. "$2.50 / 1M").
* Returns "—" when the value is null or unparseable.
*/
export function formatCostPerMToken(raw: string | null | undefined): string {
if (!raw) return "—";
const perToken = parseFloat(raw);
if (isNaN(perToken)) return "—";
const perMillion = perToken * 1_000_000;
return `$${perMillion % 1 === 0 ? perMillion.toFixed(2) : perMillion.toPrecision(4)} / 1M`;
}
interface DataRegionMeta {
label: string;
pill: string; // pill background + text classes
badge: string; // darker badge classes for the viewer strip
}
const REGION_META: Record<DataRegion, DataRegionMeta> = {
uk: {
label: "UK 🇬🇧",
pill: "bg-blue-50 dark:bg-blue-950/40 text-blue-700 dark:text-blue-300 border-blue-200 dark:border-blue-800",
badge: "bg-blue-100 dark:bg-blue-900/40 text-blue-800 dark:text-blue-200",
},
eu: {
label: "EU 🇪🇺",
pill: "bg-indigo-50 dark:bg-indigo-950/40 text-indigo-700 dark:text-indigo-300 border-indigo-200 dark:border-indigo-800",
badge:
"bg-indigo-100 dark:bg-indigo-900/40 text-indigo-800 dark:text-indigo-200",
},
us: {
label: "US 🇺🇸",
pill: "bg-red-50 dark:bg-red-950/40 text-red-700 dark:text-red-300 border-red-200 dark:border-red-800",
badge: "bg-red-100 dark:bg-red-900/40 text-red-800 dark:text-red-200",
},
global: {
label: "Global 🌐",
pill: "bg-teal-50 dark:bg-teal-950/40 text-teal-700 dark:text-teal-300 border-teal-200 dark:border-teal-800",
badge: "bg-teal-100 dark:bg-teal-900/40 text-teal-800 dark:text-teal-200",
},
};
/** Returns display metadata for a data_region value, or null if unknown/absent. */
export function dataRegionMeta(
region: DataRegion | string | null | undefined,
): DataRegionMeta | null {
if (!region) return null;
return REGION_META[region as DataRegion] ?? null;
}
/**
* Effort bands, ordered lightest → strongest.
*
* Exported as an array rather than derived from the meta record because the
* order *is* the meaning: it backs the "at least this tier" reading of a
* filter and the effort sort, and object key order is not a contract.
*/
export const MODEL_EFFORTS: readonly ModelEffort[] = [
"light",
"balanced",
"deep",
"frontier",
];
interface ModelEffortMeta {
label: string;
/** Which tier each provider fills with this band — the whole point of the
* classification, so it travels with the label rather than being folded
* into a tooltip somewhere. */
examples: string;
description: string;
pill: string;
badge: string;
/** Position in MODEL_EFFORTS, so callers can compare bands without
* re-deriving the order. */
rank: number;
}
// Deliberately not a StatusBadge scale: those tones carry a judgement
// ("succeeded", "failed") and a tier carries none — `frontier` is not a
// warning. This is an ordered ramp, the way REGION_META below is a lookup.
// Class names are written out in full because Tailwind scans source text and
// cannot see an interpolated name.
const EFFORT_META: Record<ModelEffort, ModelEffortMeta> = {
light: {
label: "Light",
examples: "Claude Haiku · GPT Luna",
description: "Fastest and cheapest. High-volume, well-defined work.",
pill: "bg-sky-50 dark:bg-sky-950/40 text-sky-700 dark:text-sky-300 border-sky-200 dark:border-sky-800",
badge: "bg-sky-100 dark:bg-sky-900/40 text-sky-800 dark:text-sky-200",
rank: 0,
},
balanced: {
label: "Balanced",
examples: "Claude Sonnet · GPT Terra",
description: "The everyday tier — speed and intelligence together.",
pill: "bg-emerald-50 dark:bg-emerald-950/40 text-emerald-700 dark:text-emerald-300 border-emerald-200 dark:border-emerald-800",
badge:
"bg-emerald-100 dark:bg-emerald-900/40 text-emerald-800 dark:text-emerald-200",
rank: 1,
},
deep: {
label: "Deep",
examples: "Claude Opus · GPT Sol",
description: "Complex agentic and professional work.",
pill: "bg-violet-50 dark:bg-violet-950/40 text-violet-700 dark:text-violet-300 border-violet-200 dark:border-violet-800",
badge:
"bg-violet-100 dark:bg-violet-900/40 text-violet-800 dark:text-violet-200",
rank: 2,
},
frontier: {
label: "Frontier",
examples: "Claude Fable · GPT Astra",
description: "Demanding reasoning and long-horizon agentic work.",
pill: "bg-amber-50 dark:bg-amber-950/40 text-amber-700 dark:text-amber-300 border-amber-200 dark:border-amber-800",
badge:
"bg-amber-100 dark:bg-amber-900/40 text-amber-800 dark:text-amber-200",
rank: 3,
},
};
/** Returns display metadata for an effort band, or null if unknown/absent. */
export function modelEffortMeta(
effort: ModelEffort | string | null | undefined,
): ModelEffortMeta | null {
if (!effort) return null;
return EFFORT_META[effort as ModelEffort] ?? null;
}
/** Sort position of an effort band, lightest first. Models with no band sort
* last rather than leading, so an unclassified row never heads the list. */
export function modelEffortRank(
effort: ModelEffort | string | null | undefined,
): number {
return modelEffortMeta(effort)?.rank ?? MODEL_EFFORTS.length;
}
interface ModelLatencyMeta {
label: string;
/** 1–4 filled bars, so the band reads at a glance next to a number. */
bars: number;
}
const LATENCY_META: Record<ModelLatency, ModelLatencyMeta> = {
fastest: { label: "Fastest", bars: 4 },
fast: { label: "Fast", bars: 3 },
moderate: { label: "Moderate", bars: 2 },
slower: { label: "Slower", bars: 1 },
};
/** Returns display metadata for a latency band, or null if unknown/absent. */
export function modelLatencyMeta(
latency: ModelLatency | string | null | undefined,
): ModelLatencyMeta | null {
if (!latency) return null;
return LATENCY_META[latency as ModelLatency] ?? null;
}
/**
* Formats a token count as a compact window size — 1_050_000 → "1.05M",
* 200_000 → "200K". Returns "—" when absent.
*
* Context windows are now seven digits, and a card cannot show
* "1,050,000 tokens" next to a price without wrapping.
*/
export function formatTokenCount(tokens: number | null | undefined): string {
if (tokens == null || !Number.isFinite(tokens)) return "—";
if (tokens >= 1_000_000) {
const millions = tokens / 1_000_000;
// 1M, not 1.00M; 1.05M keeps the digits that distinguish it from 1M.
return `${parseFloat(millions.toFixed(2))}M`;
}
if (tokens >= 1_000) return `${parseFloat((tokens / 1_000).toFixed(1))}K`;
return `${tokens}`;
}
/**
* Formats a knowledge cutoff (`YYYY-MM-DD`) as "Jun 2026".
*
* Providers publish this to the month; showing a day would imply a precision
* they do not claim. Parsed as UTC rather than through `parseServerDate(iso)` in
* local time, which turns 2026-06-01 into May 2026 west of Greenwich.
*/
export function formatKnowledgeCutoff(
iso: string | null | undefined,
): string {
if (!iso) return "—";
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(iso);
if (!match) return "—";
const [, year, month, day] = match;
const date = new Date(Date.UTC(+year, +month - 1, +day));
Iif (isNaN(date.getTime())) return "—";
return date.toLocaleDateString(undefined, {
year: "numeric",
month: "short",
timeZone: "UTC",
});
}
/** A link as a citation carries it. */
export interface CitationLink {
url: string;
/** The link's anchor text (for `links`) — or the page title (for `via`). */
text?: string;
title?: string;
}
/** What a citation is a source of, by the tool that produced it (svc-ai
* `source_ledger.TOOL_KINDS`): the web, a knowledge base's passages, a
* knowledge graph, a document read in full, or another tool's result. */
export const CITATION_KINDS = ["web", "knowledge", "graph", "document", "other"] as const;
export type CitationKind = (typeof CITATION_KINDS)[number];
export function isCitationKind(value: unknown): value is CitationKind {
return (CITATION_KINDS as readonly unknown[]).includes(value);
}
export interface Citation {
index: number;
/** The number the answer cites it by — ``[2]`` in the text and the entry
* of the Sources block svc-ai writes (``answer_sources``). Absent on a
* source the answer does not cite, and on answers stored before it. */
marker?: number | null;
tool: string;
source: string;
title: string;
/** Absent on citations stored before svc-ai stamped one on each. */
kind?: CitationKind;
collection?: string;
/** Knowledge-base citations (svc-ai RetrievedPassage.citation). */
citation_id?: string;
kb_name?: string;
/** The document a knowledge passage came from, and its page. */
document_id?: string | null;
page_number?: number | null;
/** A knowledge base's web page: the page itself and when it was read. */
url?: string | null;
fetched_at?: string | null;
/** Deep citation — pages this passage links to (the article a listing
* entry points at, the report a post cites). */
links?: CitationLink[] | null;
/** Deep citation — for a page read because another crawled page linked to
* it, the page(s) that did. */
via?: CitationLink[] | null;
/** When the page was published, and by whom — from the page or the feed
* that listed it. What dates a news answer. */
published?: string | null;
author?: string | null;
/** The credit its source's licence asks for, and the licence itself. */
attribution?: string | null;
licence_url?: string | null;
}
export interface MessageSegment {
worker_slug: string;
content: string;
sequence: number;
}
export interface ChatMessageMeta {
token_count?: number;
temperature?: number;
output_format?: string;
output_schema?: string;
model_name?: string;
provider?: string;
/** Name of the policy rule that blocked this turn, when status is "blocked". */
rule?: string;
/** Every time the turn stopped for the person, and what they answered. */
hitl?: HitlExchange[];
/** On a user's message: the chat command it ran. */
command?: ChatCommandRecord;
/** On an answer: the person stopped it, and its text is what it had
* written (stored with status "error"). */
stopped?: boolean;
}
/** A document a message attached (svc-core `meta.attachments`). `id` names
* it in the workspace's library, where its original opens; a message from
* before 24 October 2026 names it only, by what was pasted into its text. */
export type AttachmentRef = {
name: string;
id?: string;
mime_type?: string;
};
/** Outcome of a chat turn — "blocked" (policy rule) and "error" (any other
* failure) are recorded, not just dropped, so History/Activity stay exhaustive. */
export type ChatMessageStatus = "completed" | "blocked" | "error";
export type ChatMessage = {
/** The persisted `ChatMessage.id`, when this came from a stored
* conversation. Absent while a turn is still streaming — nothing has been
* written yet — which is why it is optional rather than required.
* Deep links (`?message=`) resolve against it. */
id?: string;
/** The governed turn it was part of: what "Why did it do this?" opens
* (`decisionHref`). Absent on turns from before turns had ids. */
invocation_id?: string | null;
/** On an answer: the turn's verdict, when somebody gave one. */
verdict?: DecisionVerdict | null;
/** On an answer: what its turn cost, from the usage ledger — null when
* nothing in it could be priced, absent when the turn is not on it. */
cost_usd?: number | null;
/** Calls in it that could not be priced: `cost_usd` is then a floor. */
unpriced_calls?: number;
role: "system" | "user" | "assistant";
content: string;
status?: ChatMessageStatus;
citations?: Citation[];
sent_at?: string;
segments?: MessageSegment[];
attachments?: AttachmentRef[];
// Inlined so ChatPanel can access it without resolving ChatMessageMeta separately
meta?: {
token_count?: number;
temperature?: number;
output_format?: string;
output_schema?: string;
model_name?: string;
provider?: string;
rule?: string;
hitl?: HitlExchange[];
/** On a user's message: the chat command it ran (svc-core
* `chat_commands`), shown as a chip above the request. Read through
* `commandOf`: a chat stored it as the whole meta until 24 October 2026. */
command?: ChatCommandRecord;
/** On a user's message: the documents it attached, by id. */
attachments?: AttachmentRef[];
/** What became of the answer at the quality check; absent when it
* never reached one. */
eval_outcome?: QualityOutcome;
/** The check's score out of 100 — only when a check ran. */
eval_score?: number;
/** An Economy profile's lighter model wrote the answer (svc-core
* `services/lighter_model.py`); `model_name` is it. */
lighter_model?: LighterModelAnswer;
/** The cost profile the agent ran under, when not the default. */
cost_profile?: string;
/** On an answer: the sources it cites, as stored with it (read through
* `storedCitations`). */
cited_sources?: Citation[];
/** On an answer: an Output rule withheld it; the content is the rule's
* message. */
withheld?: WithheldAnswer;
/** On an answer: what the turn's web searches came to, and what each
* Tools rule did to them (svc-core `meta.web_search`). */
web_search?: WebSearchSummary;
};
trace?: TraceEvent[] | null;
};
/** `meta.withheld`: an Output rule withheld the answer (svc-core
* `rule_engine.Withheld.meta`). The message's content is the rule's own
* message; the answer itself went to review, or was kept nowhere. */
export interface WithheldAnswer {
rule?: string | null;
rule_id?: string | null;
rule_version?: number | null;
/** The answer went to the workspace's reviewers. */
review?: boolean;
}
/** `meta.lighter_model`: the answer was written by the lighter model. */
export interface LighterModelAnswer {
answered?: boolean;
/** Why it answered: `simple` — triage called the request simple. */
reason?: string;
}
/** svc-ai's `QualityOutcome`: passed, revised (the agent revised a failed
* answer and the revision passed), failed (no revision passed),
* unavailable (no check ran) or skipped (the agent's cost profile answered
* a simple request without one). */
export type QualityOutcome =
| "passed"
| "revised"
| "failed"
| "unavailable"
/** The agent's cost profile answered a simple request unchecked. */
| "skipped";
export type PromptResponse = {
response: string;
conversation_id: string;
output_tokens?: number;
/** Rule-enforcement trace frames (policy/audit governance actions). */
trace?: TraceEvent[] | null;
/** Stop ended the turn: `response` is what it had written, as stored. */
stopped?: boolean;
/** The turn's id: what "Why did it do this?" opens. */
invocation_id?: string | null;
/** What the turn cost, read back from the usage ledger. */
cost_usd?: number | null;
unpriced_calls?: number;
/** An Output rule withheld the answer: `response` is its message. */
withheld?: WithheldAnswer | null;
/** What the turn's web searches came to (`meta.web_search`). */
web_search?: WebSearchSummary | null;
};
/** A single fired rule action inside a __policy__/__audit__ trace node. */
export interface RuleTraceEvent {
rule: string;
rule_id?: string | null;
action: string;
phase: "input" | "output";
reviewer?: string;
/** False when the action ran and found nothing to do (a redactor over clean
* text). Absent means it acted. */
changed?: boolean;
message?: string;
redacted?: Record<string, number>;
}
/**
* One applicable rule inside a __policy__/__audit__ trace node, and what came
* of it — the same four outcomes as Governance → Rules → Activity. Every rule
* that applied to the invocation has one, including the ones whose conditions
* did not hold; traces persisted before these existed carry `events` only.
*/
export interface RuleTraceEvaluation {
rule: string | null;
rule_id?: string | null;
rule_version?: number | null;
layer?: RuleLayer | null;
/** Traces stored before layers (svc-core migration 105) name a type
* instead: "policy", "audit" or "routing". Read through `ruleLayer.layerOf`. */
rule_type?: string | null;
scope_type?: RuleScope | null;
scope_id?: string | null;
outcome: GovernanceOutcome;
/** Action types that ran, in order. Empty when the conditions did not hold. */
actions: string[];
/** Per-action specifics keyed by action type — never the matched text. */
detail: Record<string, Record<string, unknown>>;
/** svc-core evaluated it, svc-ai enforced it inside the run, or both. */
enforced_in?: "core" | "ai" | "both";
}
export interface RuleTraceResult {
phase?: "input" | "output";
evaluations?: RuleTraceEvaluation[];
events?: RuleTraceEvent[];
}
export interface NodePlanResult {
node_id: string;
goal: string;
expected_output: string;
success_criteria: string;
}
/**
* The route the gate's triage call chose, before the gate's own rules
* changed it (svc-ai `GraphState.triage_route`, the gate frame's `triage`).
* Absent on traces stored before it, and on a trivial turn.
*/
export interface TriageChoice {
route: string;
/** Empty unless `route` is `retrieve`. */
retrieval_type: string;
/** `fallback`: the triage call failed (or had no model), and the route was
* read from the request instead. */
source: "triage" | "fallback";
/** One line per change the gate made, each ending in the route it led to. */
adjustments?: string[];
}
/**
* What the internal retrieval pipeline ran without (svc-ai
* `graph._retrieval_report`, the retrieval frame's `report`). Sent only when
* something is set; absent on traces stored before it.
*/
export interface RetrievalReport {
/** The query planner failed and the request was searched as written. */
planner_failure?: string;
/** The relevance judge failed: its passages were kept unjudged. */
judge_failure?: string;
/** Search legs that could not run, one line per knowledge base. */
degraded?: string[];
/** Passages the judge ruled out as not bearing on the request. */
judged_out?: number;
}
/** A lane of a turn's knowledge mix (svc-ai `knowledge.mix.Lane`): one kind
* of knowledge, its role and how much it may take. */
export interface KnowledgeMixLane {
category: string;
/** `primary` (the evidence the answer rests on), `supporting` or
* `method` (a framework to apply). */
role: string;
kb_ids: string[];
/** Its share of the context budget, 0–1. */
share: number;
candidate_k: number;
judge_slots: number;
max_queries: number;
/** Why it runs, in svc-ai's fixed words. */
reason: string;
}
/** Which kinds of knowledge a turn searched and why (svc-ai
* `knowledge.mix.Mix.wire`, on the gate's frame and the plan's). */
export interface KnowledgeMix {
profile: string;
modifiers: string[];
lanes: KnowledgeMixLane[];
/** Kinds the agent holds that the turn left out, and why. */
scoped_out: { category: string; kb_ids: string[]; reason: string }[];
signals: {
live?: boolean;
complexity?: string | null;
window_days?: number | null;
web_led?: boolean;
named?: string[];
};
}
/** `__knowledge_plan__`'s result: what the turn's lanes search for. */
export interface KnowledgePlanResult {
/** `pipeline` | `hybrid` | `agentic` | `gap` (a corrective pass) | `none`. */
mode: string;
mix: KnowledgeMix | null;
lanes: { category: string; role: string; kb_ids: string[]; queries: string[] }[];
planner_failure: string;
/** The quality check's gaps, on a corrective pass. */
gaps: string[];
error: string;
}
/** A lane's result: what its search did (counts, never a passage). */
export interface LaneSearchResult {
category: string;
role: string;
kb_ids: string[];
queries: string[];
found: number;
/** Passages its relevance judge was shown. */
judged: number;
ruled_out: number;
out_of_window: number;
handed_on: number;
judge_failure: string;
degraded: string[];
timings_ms: Record<string, number>;
error: string;
}
/** How a lane fared in the join's packing (svc-ai `retrieval.LanePacking`):
* its budget and use in tokens, the passages it packed, and the budget it
* took over from lanes that left theirs unused. */
export interface LanePacking {
role: string;
budget: number;
used: number;
packed: number;
spilled_in: number;
}
/** One `__memory_read__` entry: an object since svc-ai migration 28, a bare
* string before (`recalledMemory`). `reason`, `lexical` and `dense` say why
* recall chose it, for the trace only; absent on traces stored before them. */
export type RecalledMemoryEntry =
| string
| {
kind: string;
text: string;
recorded: string;
id: string;
reason?: string;
lexical?: number | null;
dense?: number | null;
};
export type SystemNodeResult =
| { task_summary: string; overall_goal: string; retrieval_focus: string; node_plans: NodePlanResult[] }
| {
route: string;
retrieval_type: string;
trivial_output: string;
kb_metadata?: string;
/** False when a count, a document list or a graph schema could not be read. */
kb_inventory_complete?: boolean;
triage?: TriageChoice;
}
| { recon_context: string; complexity: string; use_skill_graph: boolean; relevant_tools: string[]; resource_notes: string }
| {
retrieval_context: string;
/** Frameworks from reasoning knowledge, handed on apart from the
* evidence (internal retrieval only). */
frameworks_context?: string;
error?: string;
report?: RetrievalReport;
}
| { output: string; error?: string }
| { memories: RecalledMemoryEntry[] }
| { stored: boolean; content: string }
| { passed: boolean; score: number; gaps: string[]; critique: string; final_output: string }
| RuleTraceResult
| Record<string, unknown>;
/**
* One stage of the pipeline svc-ai announces up-front in its `graph_plan`
* frame. A stage holds several `node_ids` when only a subset of them runs
* (the retrieval stage) or when they run in parallel.
*/
export interface GraphPlanStage {
/** Stable stage key — `skill:<node_id>` for skill-graph nodes. */
id: string;
node_ids: string[];
/** Routing may legitimately bypass the stage — render it skipped, not failed. */
optional: boolean;
is_system_stage: boolean;
/** A parallel stage (retrieval, since October 2026): the node that starts
* its branches, the branches that may run side by side (a lane per kind
* of knowledge the agent holds, the web, the tools), and the node they
* meet in. Absent on other stages and on traces stored before them. */
fork?: string;
branches?: string[];
join?: string;
}
export interface TraceEvent {
type:
| "graph_plan"
| "node_start"
| "node_end"
| "tool_call"
| "system_node_result"
/** The run stopped for a person at `node_id` (svc-ai). */
| "hitl_pause"
/** The person answered that pause, or it was abandoned (svc-core). */
| "hitl_resume";
/** Empty on `graph_plan` frames, which describe the run rather than a node. */
node_id: string;
is_system_node?: boolean;
output_preview?: string;
tokens?: { input: number; output: number };
duration_ms?: number;
tool?: string;
params?: Record<string, unknown>;
status?: "success" | "error";
/** A web search's report, on its `tool_call` frame (`objects/WebSearch.ts`). */
report?: SearchReport;
result?: SystemNodeResult;
/** Input context passed to the system node (present on system_node_result events). */
input?: Record<string, unknown>;
/** LLM model name used for this node (present on node_end events). */
model_name?: string;
/** LLM provider used for this node (present on node_end events). */
provider?: string;
/** Milliseconds from the stream's start (node_start / node_end); absent
* on traces stored before it. */
t_ms?: number;
/** The graph pass a node starts on (node_start): 0, then one more per
* revision after the quality check. */
pass?: number;
/** Ordered pipeline stages (present on graph_plan events only). */
stages?: GraphPlanStage[];
// ── hitl_pause / hitl_resume (see objects/Hitl.ts) ──
interrupt_type?: HitlInterruptType;
source?: ClarifySource;
title?: string | null;
intro?: string | null;
reason?: string | null;
questions?: ClarifyQuestion[];
task?: string;
output?: string;
paused_at?: string;
outcome?: HitlOutcome;
answers?: ClarifyAnswers;
approved?: boolean;
feedback?: string;
answered_at?: string | null;
answered_by?: string | null;
waited_ms?: number | null;
redacted?: boolean;
}
export interface NodeExecution {
node_id: string;
is_system_node: boolean;
streamingContent: string;
tools: {
tool: string;
output_preview: string;
status: "success" | "error";
params?: Record<string, unknown>;
/** A web search's report (`objects/WebSearch.ts`). */
report?: SearchReport;
}[];
done: boolean;
output?: string;
system_result?: SystemNodeResult;
/** Input context that was passed to this system node's LLM call. */
system_input?: Record<string, unknown>;
tokens?: { input: number; output: number };
duration_ms?: number;
/** When it started and ended, in ms from the stream's start (`t_ms`). */
started_ms?: number;
ended_ms?: number;
/** The graph pass it ran on (0 the first, one more per revision). */
pass?: number;
/** Set when this execution stopped for a person (see objects/Hitl.ts). */
hitl?: NodeHitl;
}
export interface ConversationMessage {
id: string;
/** The governed turn it was part of (svc-core migration 91). */
invocation_id?: string | null;
/** On an answer: the turn's verdict (`decision_outcomes`). */
verdict?: DecisionVerdict | null;
/** On an answer: what its turn cost, joined from the usage ledger by
* `invocation_id` (null: unpriced; absent: not on the ledger). */
cost_usd?: number | null;
unpriced_calls?: number;
role: "system" | "user" | "assistant";
content: string;
status?: ChatMessageStatus;
token_count: number;
sent_at: string;
conversation_id: string;
trace?: TraceEvent[] | null;
segments?: MessageSegment[] | null;
meta?: {
token_count?: number;
temperature?: number;
output_format?: string;
output_schema?: string;
model_name?: string;
provider?: string;
rule?: string;
/**
* Which revision of the agent produced this turn, and which agent.
*
* Stamped when the agent's configuration was *read*, so it survives every
* later edit — which is what makes a result traceable to the exact
* configuration behind it rather than merely attributed to an agent whose
* prompt has since changed. Resolves through the agent's own `/history`
* to a snapshot and a diff.
*
* Absent where no versioned resource was involved (a direct model prompt)
* or where the agent had no history rows yet.
*/
agent_version?: number;
agent_id?: string;
/** Every pause of the turn and its answer (svc-core `services/hitl.py`). */
hitl?: HitlExchange[];
/** On a user's message: the chat command it ran. */
command?: ChatCommandRecord;
/** On an answer: the person stopped it, and its text is what it had
* written (stored with status "error"). */
stopped?: boolean;
/** On an answer: what its quality check concluded, and the score when
* a check ran. */
eval_outcome?: QualityOutcome;
eval_score?: number;
/** On an answer: an Economy profile's lighter model wrote it. */
lighter_model?: LighterModelAnswer;
/** The cost profile the agent ran under, when not the default. */
cost_profile?: string;
/** On an answer: an Output rule withheld it; the content is the rule's
* message. */
withheld?: WithheldAnswer;
/** On an answer: what the turn's web searches came to. */
web_search?: WebSearchSummary;
/**
* On an answer: the sources the answer itself cites (svc-ai
* `cited_citations`), as svc-core stored them with it — redacted by the
* turn's output rules, without the passages' text or scores. `[]` when
* it cites none; absent on turns stored before October 2026 and on a
* blocked turn. Read it through `storedCitations`.
*/
cited_sources?: Citation[];
} | null;
}
export interface Conversation {
id: string;
ai_model_id: string | null;
agent_id: string | null;
owner_user_id?: string | null;
owner_organisation_id?: string | null;
owner_project_id?: string | null;
messages: ConversationMessage[];
total_input_tokens: number;
total_output_tokens: number;
total_tokens: number;
/** The answers' costs added up; null when none has one. */
cost_usd?: number | null;
unpriced_calls?: number;
created_at: string;
}
|