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 | 3x 3x 3x 3x 3x 10x 2x 10x 2x 2x 10x 2x 2x 2x | import { ClarifyQuestion } from "@/objects/Hitl";
import { AIGenerated, SystemManaged } from "@/objects/Doc";
// ─── Typed interfaces (skill graph schema v3) ────────────────────────────────
export type FieldType =
| "string"
| "number"
| "integer"
| "boolean"
| "enum"
| "array"
| "object";
export const FIELD_TYPES: FieldType[] = [
"string",
"number",
"integer",
"boolean",
"enum",
"array",
"object",
];
/** One typed field of a worker / skill interface (mirrors svc-ai FieldSpec). */
export interface FieldSpec {
name: string;
type: FieldType;
description?: string;
required?: boolean;
default?: unknown;
/** enum only — closed set of allowed values */
values?: string[];
/** array only — element type */
items?: FieldType;
}
export interface NodeSlotInfo {
node_id: string;
description: string;
default_agent_name: string;
default_agent_display_name: string;
default_agent_role: string;
default_agent_description: string;
config_overrides: Record<string, unknown>;
}
export interface AvailableSkill {
name: string;
display_name: string;
description: string;
use_case: string;
tags: string[];
nodes: NodeSlotInfo[];
edges: string[][];
start_node: string;
end_nodes: string[];
graph_definition: Record<string, unknown>;
}
export interface AgentDefinition {
name: string;
display_name: string;
description: string;
role: string;
tags: string[];
default_tools: Array<{
name: string;
type: string;
config: Record<string, unknown>;
}>;
tools_enabled?: boolean;
/** Typed interface — values a skill node binds into the worker. */
input_schema?: FieldSpec[];
/** Typed interface — non-empty means the worker returns a structured object. */
output_schema?: FieldSpec[];
}
// ─── Graph definition (schema v3, backwards compatible with v1/v2) ───────────
export type GraphNodeType = "agent" | "tool" | "transform";
export type TransformOp =
| "template"
| "merge"
| "select"
| "compose"
| "parse"
| "literal";
export const TRANSFORM_OPS: TransformOp[] = [
"template",
"merge",
"select",
"compose",
"parse",
"literal",
];
/**
* What one graph node overrides on the worker definition behind it.
*
* svc-core validates this shape (`_NodeConfigOverrides`) and refuses a key it
* does not recognise, so the index signature is gone: an override the backend
* will not honour is now a save error rather than something silently dropped
* into svc-ai's `ModelConfig`.
*/
export interface NodeConfigOverrides {
system_prompt?: string;
temperature?: number;
max_tokens?: number;
/** svc-ai's `ModelConfig.effort` — dropped for models that do not take it. */
effort?: "low" | "medium" | "high" | "xhigh" | "max";
tools_enabled?: boolean;
/** Which model answers this node. Both or neither — a lone half is ignored. */
provider?: string;
model?: string;
/**
* MCPServer row ids. Only ids are stored; svc-core resolves them to
* connection descriptors at execution time, so credentials never enter a
* saved graph.
*/
mcp_server_ids?: string[];
}
export interface ToolNodeSpec {
name: string;
args: Record<string, unknown>;
config?: Record<string, unknown>;
}
export interface GraphNodeConfig {
type?: GraphNodeType;
// agent nodes
agent_name?: string;
config_overrides?: NodeConfigOverrides;
prompt_template?: string;
input_keys?: string[];
// tool nodes
tool?: ToolNodeSpec;
// transform nodes
operation?: { op: TransformOp; [key: string]: unknown };
// any type
output_key?: string;
description?: string;
/** worker input field → binding ("{path}" reference or literal) */
inputs?: Record<string, unknown>;
input_schema?: FieldSpec[];
output_schema?: FieldSpec[];
/** Pause *before* this node runs so a person can approve the work so far.
* Rejecting stops the run; feedback on an approval reaches the node. */
approval?: { message?: string } | null;
/** Let this (agent) node ask the person running it clarifying questions. */
ask_user?: boolean;
}
export type ConditionOp =
| "eq"
| "ne"
| "gt"
| "gte"
| "lt"
| "lte"
| "in"
| "not_in"
| "contains"
| "not_contains"
| "starts_with"
| "ends_with"
| "matches"
| "exists"
| "not_exists"
| "empty"
| "not_empty"
| "truthy"
| "falsy";
export const UNARY_OPS: ConditionOp[] = [
"exists",
"not_exists",
"empty",
"not_empty",
"truthy",
"falsy",
];
export const BINARY_OPS: ConditionOp[] = [
"eq",
"ne",
"gt",
"gte",
"lt",
"lte",
"in",
"not_in",
"contains",
"not_contains",
"starts_with",
"ends_with",
"matches",
];
export const CONDITION_OP_LABELS: Record<ConditionOp, string> = {
eq: "equals",
ne: "does not equal",
gt: "greater than",
gte: "at least",
lt: "less than",
lte: "at most",
in: "is one of",
not_in: "is not one of",
contains: "contains",
not_contains: "does not contain",
starts_with: "starts with",
ends_with: "ends with",
matches: "matches regex",
exists: "exists",
not_exists: "does not exist",
empty: "is empty",
not_empty: "is not empty",
truthy: "is true",
falsy: "is false",
};
/** A routing predicate — a leaf comparison or an all / any / not composition. */
export interface ConditionSpec {
var?: string;
op?: ConditionOp;
value?: unknown;
all?: ConditionSpec[];
any?: ConditionSpec[];
not?: ConditionSpec;
}
export interface BranchSpec {
key: string;
target: string;
when?: ConditionSpec;
description?: string;
}
/**
* Conditional routing from one source node. Three forms:
* - `branches` (v3): ordered predicates over graph variables, else `default`.
* - `route_field`: read a field of the source's structured output.
* - legacy: `route_keys` become RouterAgent candidates.
*/
export interface ConditionalEdgeConfig {
branches?: BranchSpec[];
default?: string;
route_field?: string;
route_keys?: string[];
edge_map?: Record<string, string>;
}
export interface StateFieldSpec {
description?: string;
default?: unknown;
type?: FieldType | "";
}
export interface InterfaceOutputSpec {
name: string;
from?: string;
description?: string;
}
export interface SkillInterface {
inputs?: FieldSpec[];
outputs?: InterfaceOutputSpec[];
}
export interface GraphDefinition {
nodes: Record<string, GraphNodeConfig>;
edges: string[][];
start_node: string;
end_nodes: string[];
conditional_edges?: Record<string, ConditionalEdgeConfig>;
state?: Record<string, StateFieldSpec>;
interface?: SkillInterface;
}
export interface Skill extends AIGenerated, SystemManaged {
id: string;
name: string;
description?: string;
tags: string[];
graph_definition: Record<string, unknown>;
owner_user_id?: string | null;
owner_organisation_id?: string | null;
owner_project_id?: string | null;
created_at: string;
}
// ─── Runs (svc-core `services/skill_runs`) ───────────────────────────────────
/**
* Why the run form asks for a field. `interface` is the skill's declared
* contract; the others are what its nodes read that nothing in the graph
* supplies — an unbound worker input, an undefaulted state key, or a
* `{placeholder}` in a prompt template.
*/
export type RunFieldSource = "interface" | "state" | "node" | "template";
/** One value a run can be given: a FieldSpec plus where it came from. */
export interface RunField extends FieldSpec {
source: RunFieldSource;
/** Node ids that read it. */
consumers: string[];
}
export interface RunSchema {
fields: RunField[];
/** The skill takes no inputs, so the task text is all it has. */
requires_prompt: boolean;
/** False when a worker's interface could not be looked up. */
complete: boolean;
}
export type SkillRunStatus =
| "running"
| "awaiting_input"
| "completed"
| "failed"
| "blocked"
| "rejected"
| "cancelled";
/** One model's share of a run, as svc-ai measured it. */
export interface CostDetailRow {
provider: string;
model: string;
calls: number;
input_tokens: number;
output_tokens: number;
/** null when the model is in neither price table — never 0 for unknown. */
cost_usd: number | null;
unpriced_calls: number;
}
/** What a paused run is waiting on. */
export type RunPause =
| {
kind: "clarification";
thread_id: string | null;
paused_at: string;
intro?: string | null;
questions: ClarifyQuestion[];
answered?: boolean;
}
| {
kind: "approval";
thread_id: string | null;
paused_at: string;
node_id?: string | null;
message?: string;
/** Each completed node's output, as the reviewer is shown it. */
completed: Record<string, string>;
answered?: boolean;
};
/** One answer given to a pause. */
export interface RunResponse {
kind: "clarification" | "approval";
node_id?: string | null;
approved?: boolean;
feedback?: string;
answers?: Record<string, string[]>;
answered_at: string;
answered_by: string;
}
export interface SkillRunToolCall {
name: string;
args: Record<string, unknown>;
output: string | null;
error?: boolean;
}
/** What one node did — read off svc-ai's execution trace. */
export interface SkillRunStep {
node_id: string;
/** `system` for svc-ai's pipeline nodes (`__gate__` …). */
kind: "system" | "skill";
output: string;
truncated: boolean;
/** A structured worker's return value. */
structured: Record<string, unknown> | null;
error: boolean;
tool_calls: SkillRunToolCall[];
input_tokens: number;
output_tokens: number;
}
/** A row of the runs list. */
export interface SkillRunSummary {
id: string;
skill_id: string | null;
skill_name: string;
skill_version: number | null;
status: SkillRunStatus;
prompt: string | null;
inputs: Record<string, unknown>;
error: string | null;
input_tokens: number;
output_tokens: number;
latency_ms: number | null;
/** Measured across every segment; null when nothing could be priced. */
cost_usd: number | null;
llm_calls: number;
/** Calls svc-ai could not price — above 0, `cost_usd` is a lower bound. */
unpriced_calls: number;
started_at: string;
finished_at: string | null;
}
export interface SkillRun extends SkillRunSummary {
cost_detail: CostDetailRow[] | null;
interrupt: RunPause | null;
responses: RunResponse[] | null;
task: string | null;
output: string | null;
outputs: Record<string, unknown> | null;
state: Record<string, unknown> | null;
steps: SkillRunStep[] | null;
citations: Array<Record<string, unknown>> | null;
/** Policy + audit trace frames, as the chat trace carries them. */
rule_trace: Array<Record<string, unknown>> | null;
warnings: string[] | null;
invocation_id: string | null;
}
/** A 422 from `POST …/runs`: what was wrong, by field. */
export interface SkillRunRefusal {
message: string;
fields: Record<string, string>;
}
/**
* Normalise a stored graph_definition blob (v1 / v2 / v3) into the typed
* GraphDefinition shape. Returns undefined for an empty draft.
*/
export function parseGraphDefinition(
raw: Record<string, unknown> | undefined | null,
): GraphDefinition | undefined {
if (!raw) return undefined;
const nodes = (raw.nodes ?? {}) as Record<string, GraphNodeConfig>;
Iif (Object.keys(nodes).length === 0) return undefined;
const def: GraphDefinition = {
nodes: Object.fromEntries(
Object.entries(nodes).map(([id, n]) => [
id,
{
...n,
type: n.type ?? "agent",
config_overrides: n.config_overrides ?? {},
},
]),
),
edges: (raw.edges as string[][]) ?? [],
start_node: (raw.start_node as string) ?? "",
end_nodes: (raw.end_nodes as string[]) ?? [],
};
Iif (raw.conditional_edges && Object.keys(raw.conditional_edges).length > 0) {
def.conditional_edges = raw.conditional_edges as Record<
string,
ConditionalEdgeConfig
>;
}
Iif (raw.state && Object.keys(raw.state).length > 0) {
def.state = raw.state as Record<string, StateFieldSpec>;
}
Eif (raw.interface) def.interface = raw.interface as SkillInterface;
return def;
}
|