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 | 3x 3x 3x 162x 3x 53x 3x 3x 3x | import type { ClarifyQuestion } from "@/objects/Hitl";
/**
* Swarms (svc-core `app/services/swarms`, docs/guides/swarms.md): a team of
* the workspace's agents in a shape, sent on one long task under a budget and
* a time cap. The lead plans, workers do the pieces, the lead reviews them
* and writes the answer — each step a governed turn of a real agent.
*/
/** `SwarmEnum.RunStatus`. */
export type SwarmRunStatus =
| "planning"
| "awaiting_approval"
| "running"
| "awaiting_input"
| "wrapping_up"
| "completed"
| "partial"
| "failed"
| "blocked"
| "cancelled";
/** `SwarmEnum.TaskStatus`. */
export type SwarmTaskStatus =
| "queued"
| "running"
| "awaiting_input"
| "done"
| "failed"
| "blocked"
| "skipped"
| "cancelled"
| "interrupted";
/** `SwarmEnum.TaskKind`. */
export type SwarmTaskKind = "plan" | "work" | "review" | "synthesise" | "route" | "vote";
/** `SwarmEnum.WrapUpReason`. */
export type SwarmWrapUpReason = "budget" | "time" | "stopped" | "unanswered";
/** One roster entry as a swarm stores it: an agent in one of the shape's
* roles. A `spawn` entry is a template the lead briefs as several workers;
* a `note` is what the person wants of it here (a pipeline stage's job). */
export interface SwarmRosterEntry {
role: string;
agent_id: string;
spawn?: boolean;
note?: string;
}
/** What a dispatch starts from (`engine.read_defaults`). */
export interface SwarmDefaults {
budget_usd: number;
time_cap_s: number;
max_parallel: number;
require_approval: boolean;
may_ask: boolean;
}
export interface Swarm {
id: string;
name: string;
description?: string | null;
topology: string;
params: Record<string, unknown>;
roster: SwarmRosterEntry[];
defaults: Partial<SwarmDefaults>;
owner_user_id?: string | null;
owner_organisation_id?: string | null;
owner_project_id?: string | null;
is_ai_generated?: boolean;
generation_id?: string | null;
origin?: "own" | "inherited" | "required" | "built_in" | null;
home_workspace?: string | null;
created_at?: string | null;
updated_at?: string | null;
}
/** The body that creates (or, partly, edits) a swarm. */
export interface SwarmInput {
name: string;
description?: string | null;
topology: string;
params: Record<string, unknown>;
roster: SwarmRosterEntry[];
defaults: Partial<SwarmDefaults>;
}
// ─── The shape catalogue (`GET /swarms/topologies`) ─────────────────────────
export interface TopologyRole {
key: string;
label: string;
description: string;
min_members: number;
max_members: number;
spawn_allowed: boolean;
/** Its members run in the order given, each with a note (its job). */
ordered?: boolean;
}
export interface TopologyParam {
key: string;
label: string;
description: string;
kind: "int" | "choice";
default: unknown;
minimum: number | null;
maximum: number | null;
choices: { value: string; label: string }[];
/** Shown (and used) only while another setting holds one of these values. */
shown_when?: { param: string; values: unknown[] } | null;
}
export interface TopologyPreset {
key: string;
label: string;
description: string;
params: Record<string, unknown>;
}
export interface Topology {
key: string;
label: string;
description: string;
roles: TopologyRole[];
params: TopologyParam[];
presets: TopologyPreset[];
/** Whether a run's first step is a plan a person may approve. */
plans?: boolean;
}
// ─── Runs ────────────────────────────────────────────────────────────────────
/** What a piece of work is asked to do (`schemas.TaskBrief`). */
export interface SwarmTaskBrief {
objective?: string;
output_format?: string;
done_when?: string;
sources?: string;
boundaries?: string;
specialism?: string;
effort?: string;
review_note?: string;
redoes?: string;
final?: boolean;
/** For a piece of a follow-up: the earlier pieces it carries further, by
* ref (`2.T1`: request 2's piece T1). */
builds_on?: string[];
/** Which of the lead's rounds of work it is of (absent: the first); a
* council's round of answers. */
round?: number;
/** The id of the review that asked for it: a piece of a further round, or
* one done again (`units.ASKED_BY_KEY`). */
asked_by?: string;
/** A team plan's budget for the whole team, as a decimal string. */
team_budget?: string;
/** What it was given of finished work's unspent shares, all told. */
topped_up_usd?: string;
/** What it passed on to waiting work (a team: what the team left). */
passed_on_usd?: string;
}
/** A worker's questions while its piece waits, as the run keeps them. */
export interface SwarmTaskPause {
kind: "clarification";
questions: ClarifyQuestion[];
paused_at?: string;
}
export interface SwarmTask {
id: string;
parent_id?: string | null;
seq: number;
depth: number;
kind: SwarmTaskKind;
handle: string;
title: string;
role: string;
agent_id?: string | null;
agent_name: string;
tier: string;
cost_profile?: string | null;
brief: SwarmTaskBrief;
depends_on: string[];
status: SwarmTaskStatus;
attempts: number;
budget_usd?: number | null;
estimate_usd?: number | null;
limit_usd?: number | null;
cost_usd: number;
spent_usd: number;
llm_calls: number;
unpriced_calls: number;
input_tokens: number;
output_tokens: number;
latency_ms?: number | null;
invocation_id?: string | null;
output?: string | null;
result?: Record<string, unknown> | null;
questions?: SwarmTaskPause | null;
responses?: Record<string, unknown>[] | null;
error?: string | null;
created_at: string;
started_at?: string | null;
finished_at?: string | null;
}
/** A run as a list shows it. */
export interface SwarmRunSummary {
id: string;
swarm_id?: string | null;
swarm_name: string;
swarm_version?: number | null;
/** Its thread (svc-core `swarms.thread`): the first request's id, its
* place in it from 1, and the request it follows up. */
thread_id?: string | null;
thread_seq?: number;
parent_run_id?: string | null;
topology: string;
status: SwarmRunStatus;
task: string;
budget_usd: number;
time_cap_s: number;
deadline_at: string;
/** Waiting on a person since: its clock is stopped meanwhile. */
paused_at?: string | null;
reserve_usd: number;
reserve_s: number;
wrap_up_reason?: SwarmWrapUpReason | null;
progress: { done?: number; total?: number; running?: number };
cost_usd: number;
spent_usd: number;
llm_calls: number;
unpriced_calls: number;
input_tokens: number;
output_tokens: number;
error?: string | null;
cancel_requested: boolean;
created_at: string;
finished_at?: string | null;
}
/** A piece of the lead's plan, as a person approves it. */
export interface SwarmPlanPiece extends SwarmTaskBrief {
handle: string;
title: string;
/** The roster handle of the member who does it. */
member: string;
after: string[];
}
export interface SwarmPlan {
approach: string;
assumptions?: string[];
tasks: SwarmPlanPiece[];
estimate_usd?: number;
approved_by?: string;
approved_at?: string;
dropped?: string[];
reassigned?: Record<string, string>;
}
/** A roster member as a run keeps it: who plays which part, by handle. */
export interface SwarmMember {
handle: string;
role: string;
agent_id: string;
agent_name: string;
description?: string;
spawn?: boolean;
note?: string;
}
/** What started a run when a person did not dispatch it (svc-core
* `engine.Origin`): an evaluation's cell, or a scenario. */
export interface SwarmRunOrigin {
kind: "evaluation" | "scenario";
experiment_id?: string | null;
batch_id?: string | null;
variant_id?: string | null;
scenario_run_id?: string | null;
}
/** One request of a thread, as a run's page lists them to move between. */
export interface SwarmThreadStep {
id: string;
seq: number;
/** The request's opening, as far as a list needs it. */
task: string;
status: SwarmRunStatus;
spent_usd: number;
created_at: string;
finished_at?: string | null;
}
/** What a follow-up was sent with (svc-core `config.thread`): the earlier
* requests and how each went, the pieces its lead could build on, and the
* person's documents carried from earlier requests. */
export interface SwarmThreadSnapshot {
position: number;
earlier: { run_id: string; seq: number; task: string; outcome: string; answered: boolean }[];
pieces: { ref: string; task_id: string; title: string; agent: string; objective?: string }[];
carried_files: string[];
}
export interface SwarmRun extends SwarmRunSummary {
config: {
topology?: string;
params?: Record<string, unknown>;
roster?: SwarmMember[];
defaults?: Partial<SwarmDefaults>;
origin?: SwarmRunOrigin;
thread?: SwarmThreadSnapshot;
};
plan?: SwarmPlan | null;
ledger: { facts?: string[]; assumptions?: string[]; gaps?: string[] };
output?: string | null;
warnings?: string[] | null;
file_ids: string[];
tasks: SwarmTask[];
/** Every request of its thread, first to latest (itself included). */
thread?: SwarmThreadStep[];
}
/** A run and its follow-ups, as a list shows them: one item. */
export interface SwarmThread {
thread_id: string;
swarm_id?: string | null;
swarm_name: string;
requests: number;
/** Whether any of its runs is still going or waiting. */
open: boolean;
spent_usd: number;
created_at: string;
updated_at: string;
latest: SwarmRunSummary;
/** First to latest. */
runs: SwarmRunSummary[];
}
/** What to send a swarm on; every setting but the task falls back on the
* swarm's defaults. */
export interface SwarmDispatch {
task: string;
budget_usd?: number;
time_cap_s?: number;
max_parallel?: number;
require_approval?: boolean;
may_ask?: boolean;
file_ids?: string[];
}
/** A follow-up of a run: what to do next, and whether the person's
* documents of the earlier requests go too. */
export interface SwarmFollowUp extends SwarmDispatch {
carry_files?: boolean;
}
/** A person's changes to the plan as they approve it. */
export interface SwarmApproval {
drop?: string[];
assign?: Record<string, string>;
budget_usd?: number;
}
/** What the record says about a swarm's shape (svc-core
* `swarms/advice.py`): read from the viewer's runs and the evaluations
* that ran it, never from a model. */
export interface SwarmAdvice {
key: string;
title: string;
detail: string;
/** What to try: compare it with single agents, change it, or open the
* evaluation that measured it. */
action: "evaluate" | "edit" | "open_evaluation";
tone: "attention" | "good";
evidence: Record<string, unknown>;
experiment_id?: string | null;
}
/** svc-core's 422 / 409 refusal: a message, and what is wrong by field. */
export interface SwarmRefusal {
message: string;
fields: Record<string, string>;
}
// ─── What a status means ─────────────────────────────────────────────────────
/** Statuses a coordinator is working through. */
export const WORKING_RUN_STATUSES: readonly SwarmRunStatus[] = [
"planning",
"running",
"wrapping_up",
];
/** Statuses waiting on the person who started the run. */
export const WAITING_RUN_STATUSES: readonly SwarmRunStatus[] = [
"awaiting_approval",
"awaiting_input",
];
/** Not finished: its page keeps polling, and Stop is offered. */
export const isOpenRun = (run: Pick<SwarmRunSummary, "status">): boolean =>
WORKING_RUN_STATUSES.includes(run.status) ||
WAITING_RUN_STATUSES.includes(run.status);
/** Finished with an answer, whole or part: its answer can be downloaded. */
export const hasAnswered = (run: Pick<SwarmRunSummary, "status">): boolean =>
run.status === "completed" || run.status === "partial";
/** Every status, in the order a run moves through them — pinned to svc-core's
* `SwarmEnum` by `swarmStatus.test.ts`. */
export const SWARM_RUN_STATUSES: readonly SwarmRunStatus[] = [
"planning",
"awaiting_approval",
"running",
"awaiting_input",
"wrapping_up",
"completed",
"partial",
"failed",
"blocked",
"cancelled",
];
export const SWARM_TASK_KINDS: readonly SwarmTaskKind[] = [
"plan",
"work",
"review",
"synthesise",
"route",
"vote",
];
export const SWARM_TASK_STATUSES: readonly SwarmTaskStatus[] = [
"queued",
"running",
"awaiting_input",
"done",
"failed",
"blocked",
"skipped",
"cancelled",
"interrupted",
];
|