Coverage for app / db / postgres / enums.py: 100%
295 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-10-31 11:21 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-10-31 11:21 +0000
1from enum import StrEnum
4class MessageEnum:
5 class Role(StrEnum):
6 SYSTEM = "system"
7 USER = "user"
8 ASSISTANT = "assistant"
9 TOOL = "tool"
11 class Status(StrEnum):
12 COMPLETED = "completed"
13 BLOCKED = "blocked"
14 ERROR = "error"
17class PermissionEnum:
18 class Code(StrEnum):
19 ORG_UPDATE = "org:update"
20 ORG_INVITE = "org:invite"
21 ORG_MEMBERS = "org:members"
22 ORG_DELETE = "org:delete"
24 PROJECT_CREATE = "project:create"
25 PROJECT_UPDATE = "project:update"
26 PROJECT_DELETE = "project:delete"
28 USER_INVITE = "user:invite"
31class OwnerEnum:
32 class Resource(StrEnum):
33 user = "user"
34 organisation = "organisation"
35 project = "project"
37 class Infra(StrEnum):
38 system = "system"
39 user = "user"
40 organisation = "organisation"
42 class LLMArtifact(StrEnum):
43 model = "model"
44 agent = "agent"
47class AgentEnum:
48 class Type(StrEnum):
49 skill_based = "skill_based"
50 tool_based = "tool_based"
53class RunnableEnum:
54 class Status(StrEnum):
55 queued = "queued"
56 running = "running"
57 completed = "completed"
58 failed = "failed"
59 cancelled = "cancelled"
62class EvaluationEnum:
63 class Status(StrEnum):
64 draft = "draft"
65 active = "active"
66 archived = "archived"
68 class Scorer(StrEnum):
69 manual = "manual"
70 llm = "llm"
71 exact_match = "exact_match"
72 contains = "contains"
73 not_contains = "not_contains"
74 regex = "regex"
75 json_match = "json_match"
78class SimulationEnum:
79 class Status(StrEnum):
80 draft = "draft"
81 active = "active"
82 archived = "archived"
84 class Strategy(StrEnum):
85 cooperative = "cooperative"
86 competitive = "competitive"
87 mixed = "mixed"
88 adversarial = "adversarial"
89 custom = "custom"
92class RuleEnum:
93 class Layer(StrEnum):
94 """Where in a request a rule acts, in the order a request meets them:
95 whether it may run, what the model reads, where it may look things
96 up, what people receive.
98 What each layer carries — its label, the question it answers, the
99 fields its conditions see — lives in ``app.services.rules.layers``,
100 one class per member. Replaced the policy / routing / audit types in
101 migration 105; ``tools`` was added by migration 106.
102 """
104 access = "access"
105 input = "input"
106 tools = "tools"
107 output = "output"
109 class Scope(StrEnum):
110 """What a governance rule governs.
112 Ordered broad to narrow. ``organisation`` and ``project`` are
113 *ownership* scopes — no invocation names one directly, but every
114 governed resource belongs to one, so a rule written there reaches
115 everything inside it. The rest name a participant in the call itself.
117 The vocabulary each scope carries — its label, how narrowly it aims,
118 and how it narrows the usage ledger — lives in
119 ``app.services.rules.scopes``, one class per member.
120 """
122 global_ = "global"
123 organisation = "organisation"
124 project = "project"
125 model = "model"
126 agent = "agent"
127 skill = "skill"
128 worker = "worker"
131class GovernanceEnum:
132 """The record of governance actually running.
134 A rule's *definition* is a :class:`RuleEnum` affair; this is what happened
135 when it was evaluated against a real invocation. The two enums below are
136 what make the activity log answerable rather than a pile of events: when
137 the rule ran, and whether it changed anything.
138 """
140 class Phase(StrEnum):
141 """Which side of the invocation the rule was evaluated against.
143 ``input`` before the prompt reached the model — Access and Input rules.
144 ``output`` after the response came back — Output rules (and a budget
145 stopping a turn part-way, an Access rule's row).
146 """
148 input = "input"
149 output = "output"
151 class Outcome(StrEnum):
152 """What came of one rule being evaluated.
154 The distinction the log exists for is between the last two. A rule
155 that ran and changed nothing is *working*: a redaction rule over a
156 prompt with no PII in it has done its job. Recording only the rules
157 that acted would make an unexercised rule indistinguishable from one
158 that was never evaluated at all — and "was this governed?" is the
159 question an audit asks first.
160 """
162 #: The rule refused the invocation.
163 blocked = "blocked"
164 #: The rule matched and its actions changed something.
165 applied = "applied"
166 #: The rule matched, its actions ran, and there was nothing to do.
167 no_change = "no_change"
168 #: The rule's conditions did not hold, so no action ran.
169 not_matched = "not_matched"
171 class EnforcedIn(StrEnum):
172 """Which service carried the rule out.
174 svc-core evaluates every applicable rule against the prompt and the
175 final response; svc-ai re-enforces the forwardable ones inside a graph
176 run. Recording which is which is what stops the same rule reading as
177 two separate events for one turn.
178 """
180 core = "core"
181 ai = "ai"
184class UsageEnum:
185 """The governance usage ledger — what an invocation came to.
187 Kept separate from :class:`GovernanceEnum`, whose outcomes are about a
188 *rule* being evaluated. This one is about the invocation itself, and it
189 exists so that "how many of this agent's calls failed this week?" is a
190 question the ledger can answer at all.
191 """
193 class Outcome(StrEnum):
194 """Whether the invocation this row records succeeded.
196 Only two values, deliberately. A *blocked* invocation is already
197 recorded — one ``governance_events`` row per rule that refused it,
198 with the rule, the reason and the invocation id — and writing it here
199 as well would have the same turn counted twice by two surfaces that
200 both claim to be authoritative. This ledger records what reached the
201 provider.
202 """
204 #: The provider answered.
205 ok = "ok"
206 #: The call was attempted and failed — provider error, timeout, or a
207 #: response svc-ai could not return.
208 error = "error"
210 class Source(StrEnum):
211 """The resource an invocation's spend is *attributed* to.
213 Not the same thing as ``scope_type``. The scope is what a governance
214 rule governs — the agent or model that ran — and a dashboard tile or
215 an evaluation cell runs *as* an agent or model it borrows. So "what did
216 this dashboard cost?" could not be asked of the scope. The source is
217 the resource whose cost monitoring the row counts toward: the thing
218 the user built that caused the call.
220 Stored as a string, so a new source is one member here and one row in
221 ``services/llm_paths.py`` — never a migration. See
222 ``docs/guides/cost-monitoring.md``.
223 """
225 #: A chat turn with an agent (including CHAINR Bot).
226 agent = "agent"
227 #: A direct prompt to a model.
228 model = "model"
229 #: A standalone skill run.
230 skill = "skill"
231 #: A dashboard tile's refresh.
232 dashboard = "dashboard"
233 #: An evaluation run — its cells, its judge and its optimiser.
234 experiment = "experiment"
235 #: A generative flow (agent, skillset, toolkit, knowledge, rule and
236 #: dashboard setup) — attributed to its ``GenerationRun``.
237 generation = "generation"
238 #: Knowledge work: a knowledge base's search queries and the embeddings
239 #: its website crawls index.
240 knowledge = "knowledge"
241 #: A search across a knowledge repository.
242 knowledge_repository = "knowledge_repository"
243 #: A simulation run.
244 simulation = "simulation"
245 #: A swarm run — every task its agents did: planning, work, review
246 #: and synthesis (``app/services/swarms``).
247 swarm = "swarm"
249 class ExecutionType(StrEnum):
250 """What kind of work a ledger row records — its ``execution_type``,
251 and what a rule's ``execution_type`` condition names, since svc-core
252 governs every path under the same word it ledgers it under.
254 One member per kind of path in ``services/llm_paths.py``, which
255 labels each one. Stored as a string, like ``Source``: a new kind of
256 work is a member here and a label there — never a migration.
257 """
259 #: A chat turn with an agent (including CHAINR Bot).
260 agent = "agent"
261 #: A direct prompt to a model.
262 model = "model"
263 #: A standalone skill run.
264 skill = "skill"
265 #: An evaluation run's cell, or its optimiser.
266 evaluation = "evaluation"
267 #: A dashboard tile's refresh.
268 dashboard = "dashboard"
269 #: A generative setup flow.
270 generation = "generation"
271 #: A knowledge or repository search.
272 retrieval = "retrieval"
273 #: Indexing: the embeddings a document or crawled page is stored as.
274 embedding = "embedding"
275 #: A simulation run.
276 simulation = "simulation"
277 #: A task of a swarm run: one agent's turn planning, working,
278 #: reviewing or writing the answer.
279 swarm = "swarm"
282class SchedulerEnum:
283 """Background jobs — the scheduler the stack did not used to have."""
285 class Status(StrEnum):
286 """How a job's last run ended.
288 ``skipped`` is separate from ``ok`` because "ran and found nothing to
289 do" and "did not run" look identical in a log and mean opposite things
290 when somebody is asking whether retention is being enforced.
291 """
293 #: The job ran and did something.
294 ok = "ok"
295 #: The job ran and there was nothing to do.
296 skipped = "skipped"
297 #: The job raised. The scheduler keeps going; the row records it.
298 failed = "failed"
301class SkillRunEnum:
302 """A standalone run of a skill — a skill used as a structured workflow
303 rather than as the body of an agent turn.
305 Stored as strings (``skill_runs``), like the crawl vocabulary, so a new
306 status is one member here and never a migration.
307 """
309 class Status(StrEnum):
310 #: Accepted and handed to a worker; svc-ai has not answered yet.
311 running = "running"
312 #: svc-ai answered and the audit rules have run over the answer.
313 completed = "completed"
314 #: svc-ai could not be reached, returned an error, or the process
315 #: running it went away before it finished.
316 failed = "failed"
317 #: A policy rule refused it before it reached a model. Kept apart
318 #: from ``failed``: nothing went wrong, a rule did its job.
319 blocked = "blocked"
320 #: Paused mid-run for a person: a node asked clarifying questions, or
321 #: an approval gate is waiting. Resumed from the run page.
322 awaiting_input = "awaiting_input"
323 #: A person declined an approval gate, so it stopped there.
324 rejected = "rejected"
325 #: A person abandoned it while it was waiting for input.
326 cancelled = "cancelled"
329class SwarmEnum:
330 """A swarm (``app/services/swarms``): a team of agents in a shape, sent
331 on one long task under a budget and a time cap.
333 Stored as strings (``swarm_runs``, ``swarm_tasks``), like a skill run's
334 status, so a new status or kind is one member here and never a
335 migration.
336 """
338 class RunStatus(StrEnum):
339 #: Accepted; the lead is planning the work.
340 planning = "planning"
341 #: The lead's plan waits for a person to approve it.
342 awaiting_approval = "awaiting_approval"
343 #: The team is working.
344 running = "running"
345 #: Every task that could run has; one or more wait on a person's
346 #: answer.
347 awaiting_input = "awaiting_input"
348 #: A cap was reached or someone pressed Stop: no new work starts,
349 #: and the lead writes the answer from what is done.
350 wrapping_up = "wrapping_up"
351 #: Finished with every task done.
352 completed = "completed"
353 #: Finished with an answer written from part of the work: a cap,
354 #: Stop, or tasks that failed.
355 partial = "partial"
356 #: Nothing usable came of it.
357 failed = "failed"
358 #: A rule refused its first step.
359 blocked = "blocked"
360 #: Rejected at approval, or stopped before any work was done.
361 cancelled = "cancelled"
363 class TaskStatus(StrEnum):
364 #: Waiting for what it depends on, or for a free place.
365 queued = "queued"
366 #: Its agent is working on it.
367 running = "running"
368 #: Its agent asked a question; it runs again with the answer.
369 awaiting_input = "awaiting_input"
370 done = "done"
371 failed = "failed"
372 #: A rule refused it.
373 blocked = "blocked"
374 #: Never run: the run wrapped up first, or a person dropped it.
375 skipped = "skipped"
376 #: Replaced by a task the review asked for, or dropped at approval.
377 cancelled = "cancelled"
378 #: Its worker went away mid-call (a restart); it runs again.
379 interrupted = "interrupted"
381 class TaskKind(StrEnum):
382 #: The lead breaks the task into work for the team.
383 plan = "plan"
384 #: An agent does one piece of the work.
385 work = "work"
386 #: The lead checks the work against what each piece was for.
387 review = "review"
388 #: The lead writes the answer from the work.
389 synthesise = "synthesise"
390 #: A router sends each part of the task to the experts best suited
391 #: to it (a mixture of experts).
392 route = "route"
393 #: A council member chooses the best of the proposals.
394 vote = "vote"
396 class WrapUpReason(StrEnum):
397 """Why a run stopped starting work and wrote its answer early."""
399 #: What was left of the budget was the answer's reserve.
400 budget = "budget"
401 #: What was left of the time cap was the answer's reserve.
402 time = "time"
403 #: A person pressed Stop.
404 stopped = "stopped"
405 #: Nobody answered an agent's questions, and nothing else could go
406 #: on without them, for ``engine.WAIT_TTL``.
407 unanswered = "unanswered"
409 class Tier(StrEnum):
410 """Which model a level's agents answer on."""
412 #: Each agent's own model.
413 as_configured = "as_configured"
414 #: A lighter model of the same maker (``services/lighter_model.py``).
415 lighter = "lighter"
418class UploadEnum:
419 """A document uploaded to a workspace's library for chats
420 (``app/services/uploads.py``). Stored as a string (``uploaded_files``)."""
422 class Status(StrEnum):
423 #: Stored, and its text being read by docling in the background. A
424 #: chat refuses it until it is ``ready``.
425 reading = "reading"
426 #: Its text is read and a chat can attach it.
427 ready = "ready"
428 #: No text could be read from it; ``error`` says why.
429 failed = "failed"
432class BackgroundEnum:
433 """Work the platform did on a user's behalf without being asked in a request.
435 Stored as strings (``background_events``), like the crawl vocabulary, so
436 a new kind is one member here and never a migration.
437 """
439 class Kind(StrEnum):
440 #: A dynamic dashboard tile regenerated its cached answer.
441 widget_refresh = "widget_refresh"
442 #: A website knowledge source was crawled.
443 knowledge_crawl = "knowledge_crawl"
444 #: Review flags past their retention period were deleted.
445 review_retention = "review_retention"
446 #: The platform benchmark ran a built-in experiment (a deploy).
447 platform_benchmark = "platform_benchmark"
448 #: A knowledge base's search index was rebuilt for a new embedding
449 #: model (``services/knowledge/reindex.py``).
450 knowledge_reindex = "knowledge_reindex"
452 class Trigger(StrEnum):
453 #: The scheduler found it due.
454 scheduled = "scheduled"
455 #: Somebody opened the board and the tile was stale.
456 view = "view"
457 #: Somebody asked for it ("Refresh now").
458 manual = "manual"
459 #: The thing was just created, so it had nothing to show.
460 created = "created"
461 #: Its settings changed, so what it showed answered the old question.
462 updated = "updated"
463 #: The platform's embedding model changed, so its vectors had to be
464 #: made again.
465 model_changed = "model_changed"
466 #: A built-in source was granted to an agent and had never been
467 #: crawled (``knowledge/built_in_crawls``).
468 granted = "granted"
470 class Status(StrEnum):
471 ok = "ok"
472 failed = "failed"
475class ReviewEnum:
476 """States a flagged invocation moves through in the reviewer queue."""
478 class Kind(StrEnum):
479 """What raised the item. Stored as a string (``review_flags.kind``),
480 so a new kind is one member here and never a migration."""
482 #: An audit rule's ``flag_for_review`` fired on an invocation.
483 rule = "rule"
484 #: An evaluation run scored worse than its last comparable run.
485 regression = "regression"
486 #: An Output rule withheld an answer and sent it here: the one place
487 #: the answer is kept, for its reviewers (``review.record_withheld``).
488 withheld = "withheld"
490 class Status(StrEnum):
491 #: Raised by an audit rule, nobody has looked at it yet.
492 pending = "pending"
493 #: A person looked and judged it acceptable.
494 reviewed = "reviewed"
495 #: A person looked and judged the flag itself unwarranted.
496 dismissed = "dismissed"
499class DecisionEnum:
500 """The decision record (``app/services/decisions``): one governed turn,
501 assembled from every row that carries its ``invocation_id``."""
503 class Kind(StrEnum):
504 #: An agent's or a model's answer in a chat.
505 answer = "answer"
506 #: A standalone run of a skill.
507 skill_run = "skill_run"
508 #: One task of a swarm run: one agent's turn in the team.
509 swarm_task = "swarm_task"
511 class Verdict(StrEnum):
512 """A person's verdict on an answer or a run (``decision_outcomes``).
513 Stored as a string: a new verdict is one member here."""
515 #: Right as it stands.
516 accepted = "accepted"
517 #: Right once corrected: the corrected text is kept.
518 edited = "edited"
519 #: Wrong.
520 rejected = "rejected"
522 class OutcomeSource(StrEnum):
523 """Where a verdict was given."""
525 #: On the answer itself: in the chat, or on its decision record.
526 answer = "answer"
527 #: While resolving a review flag raised on it.
528 review = "review"
530 class Access(StrEnum):
531 """Why the reader may read a record."""
533 #: It was their turn: their conversation, or their skill run.
534 owner = "owner"
535 #: They may review a flag raised on it (``review.may_review``).
536 reviewer = "reviewer"
538 class SectionStatus(StrEnum):
539 """What a section of the record can say. A gap reads as a gap: a
540 section never shows an empty list where nothing was recorded."""
542 #: The section holds what the turn recorded.
543 recorded = "recorded"
544 #: Recorded, and there was nothing: no rule applied, no tool called.
545 empty = "empty"
546 #: The turn did not record this (older turns, paths that store none).
547 not_recorded = "not_recorded"
548 #: Recorded elsewhere, and that service could not be reached.
549 unavailable = "unavailable"
552class DashboardEnum:
553 class WidgetType(StrEnum):
554 """What a dashboard widget renders.
556 Types split into two families. *Static* widgets are rendered by the
557 frontend straight from existing platform APIs (stats, conversations,
558 resource lists) or from their own stored config, so the backend only
559 persists placement. *Dynamic* widgets own a cached result that
560 svc-core regenerates by invoking a model or agent — see
561 ``app.services.dashboards.widgets`` for the per-type strategy.
562 """
564 note = "note"
565 shortcuts = "shortcuts"
566 stat = "stat"
567 chart = "chart"
568 breakdown = "breakdown"
569 pinned_message = "pinned_message"
570 message_list = "message_list"
571 resource_list = "resource_list"
572 weather = "weather"
573 rss = "rss"
574 market = "market"
575 automation = "automation"
576 comparison = "comparison"
577 knowledge_network = "knowledge_network"
578 agent_memory = "agent_memory"
579 web_link_graph = "web_link_graph"
580 knowledge_graph = "knowledge_graph"
581 assurance = "assurance"
583 class DataKind(StrEnum):
584 """Where a widget's content comes from — surfaced in the UI.
586 A board deliberately mixes exact data with model inference, so every
587 tile states which it is. ``stored``/``platform``/``feed`` are all
588 factual: the user wrote it, it came from their own records, or it was
589 fetched verbatim from a named external source. ``generated`` is a
590 model's judgement and is labelled as such wherever it appears.
591 """
593 stored = "stored"
594 platform = "platform"
595 feed = "feed"
596 generated = "generated"
598 class RefreshStatus(StrEnum):
599 """Lifecycle of a dynamic widget's cached result."""
601 empty = "empty"
602 refreshing = "refreshing"
603 ready = "ready"
604 failed = "failed"
607class HistoryEnum:
608 class ResourceType(StrEnum):
609 agent = "agent"
610 toolkit = "toolkit"
611 skillset = "skillset"
612 skill = "skill"
613 # Retired: the `Tool` resource is gone, so nothing writes this any
614 # more. The label stays because it is a PostgreSQL enum value on
615 # `resource_versions.resource_type` and existing rows still carry it —
616 # a deleted resource's history is exactly when it matters most, and
617 # Postgres cannot drop an enum label without recreating the type.
618 tool = "tool"
619 mcp_server = "mcp_server"
620 custom_worker = "custom_worker"
621 knowledge = "knowledge"
622 knowledge_repository = "knowledge_repository"
623 rule = "rule"
624 # Retired, like ``tool``: the unmounted pipelines router was deleted
625 # with its tables (migration 92). Nothing ever wrote this, but it is a
626 # PostgreSQL label on ``resource_version_type_enum``, which cannot be
627 # dropped without recreating the type, and fe-core's
628 # ``ActivityResourceType`` mirrors this enum.
629 pipeline = "pipeline"
630 experiment = "experiment"
631 test_suite = "test_suite"
632 simulation_world = "simulation_world"
633 dashboard = "dashboard"
634 project = "project"
635 organisation = "organisation"
636 uploaded_file = "uploaded_file"
637 swarm = "swarm"
639 class Action(StrEnum):
640 created = "created"
641 updated = "updated"
642 deleted = "deleted"
644 class Origin(StrEnum):
645 """Who wrote a version that no person made.
647 ``release`` — CHAIN-R did, in a release: a migration that changed
648 users' resources (migration 104 removed routing rules). History reads
649 such a version as a CHAIN-R release rather than as a deleted user's.
650 """
652 release = "release"
655class GenerationEnum:
656 """Provenance for resources the platform generated rather than the user
657 hand-building them.
659 A :class:`~app.db.postgres.models.GenerationRun` row is one *invocation*
660 of a generative flow — the arguments the user supplied, the model that
661 answered, and what came of it. Resources created by that invocation carry
662 its id, so "why does this exist?" resolves to an exact call rather than a
663 bare ``is_ai_generated`` boolean.
664 """
666 class Flow(StrEnum):
667 """Which generative entry point was invoked."""
669 agent_setup = "agent_setup"
670 skillset_setup = "skillset_setup"
671 toolkit_setup = "toolkit_setup"
672 dashboard_setup = "dashboard_setup"
673 knowledge_setup = "knowledge_setup"
674 rule_setup = "rule_setup"
675 skill_setup = "skill_setup"
676 #: Finding real sources for knowledge that exists or was proposed
677 #: already: the agent wizard's, or an empty source's.
678 source_discovery = "source_discovery"
680 class Status(StrEnum):
681 """How far an invocation got.
683 ``running`` the flow is still working in the background (knowledge
684 setup searches the web first); ``progress`` on the run
685 says where it has got to.
686 ``proposed`` the model answered and the proposal was returned for
687 review; nothing was persisted.
688 ``applied`` the user accepted it and resources were created.
689 ``failed`` the model could not be reached, or returned nothing
690 usable. Kept rather than discarded — a failed generation
691 is still an event worth being able to show.
692 """
694 running = "running"
695 proposed = "proposed"
696 applied = "applied"
697 failed = "failed"