contracts.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. """Exact field names mirrored from the current Host domain and Agent wire models.
  2. This module intentionally has no dependency on the parent source tree. The
  3. visualization stays independently runnable while its tests reject incomplete or
  4. invented fake records.
  5. """
  6. from __future__ import annotations
  7. SCHEMA_CATALOG: dict[str, tuple[str, ...]] = {
  8. "ScriptBuildRecord": (
  9. "id",
  10. "execution_id",
  11. "topic_build_id",
  12. "topic_id",
  13. "agent_type",
  14. "agent_config",
  15. "data_source_url",
  16. "status",
  17. "reson_trace_id",
  18. "is_deleted",
  19. "is_favorited",
  20. "summary",
  21. "error_message",
  22. "script_direction",
  23. "build_workflow",
  24. "paragraph_count",
  25. "element_count",
  26. "input_tokens",
  27. "output_tokens",
  28. "cost_usd",
  29. "strategies_config",
  30. "start_time",
  31. "end_time",
  32. ),
  33. "ScriptBuildInputSnapshotV1": (
  34. "snapshot_id",
  35. "script_build_id",
  36. "execution_id",
  37. "topic_build_id",
  38. "topic_id",
  39. "topic",
  40. "account",
  41. "persona_points",
  42. "section_patterns",
  43. "strategies",
  44. "prompt_manifest",
  45. "datasource_manifest",
  46. "model_manifest",
  47. "canonical_sha256",
  48. "created_at",
  49. "parent_snapshot_id",
  50. "parent_snapshot_sha256",
  51. "business_input_sha256",
  52. ),
  53. "InputSnapshotRow": (
  54. "id",
  55. "script_build_id",
  56. "version",
  57. "canonical_json",
  58. "canonical_sha256",
  59. "prompt_manifest_json",
  60. "schema_version",
  61. "created_at",
  62. ),
  63. "MissionBinding": (
  64. "binding_id",
  65. "script_build_id",
  66. "root_trace_id",
  67. "input_snapshot_id",
  68. "active_direction_artifact_version_id",
  69. "accepted_root_artifact_version_id",
  70. "engine_version",
  71. "schema_version",
  72. "created_at",
  73. "updated_at",
  74. "owner_epoch",
  75. "stop_epoch",
  76. "owner_instance_id",
  77. "owner_acquired_at",
  78. ),
  79. "MissionOwnerToken": (
  80. "script_build_id",
  81. "root_trace_id",
  82. "owner_epoch",
  83. "stop_epoch",
  84. "owner_instance_id",
  85. ),
  86. "TaskView": (
  87. "task_id",
  88. "goal_id",
  89. "parent_task_id",
  90. "display_path",
  91. "specs",
  92. "current_spec_version",
  93. "status",
  94. "child_task_ids",
  95. "attempt_ids",
  96. "validation_ids",
  97. "decision_ids",
  98. "repair_count_by_version",
  99. "blocked_reason",
  100. "superseded_by",
  101. "created_at",
  102. "updated_at",
  103. ),
  104. "TaskSpecView": (
  105. "version",
  106. "objective",
  107. "acceptance_criteria",
  108. "context_refs",
  109. "created_at",
  110. ),
  111. "ScriptTaskContractV1": (
  112. "schema_version",
  113. "task_kind",
  114. "scope_ref",
  115. "intent_class",
  116. "objective",
  117. "input_decision_refs",
  118. "base_artifact_ref",
  119. "write_scope",
  120. "gap_ref",
  121. "output_schema",
  122. "criteria",
  123. "budget",
  124. "supersedes_decision_ids",
  125. "candidate_closure_decision_refs",
  126. "adopted_decision_ids",
  127. "held_or_rejected_decision_ids",
  128. "compose_order",
  129. "comparison_decision_refs",
  130. ),
  131. "OperationView": (
  132. "operation_id",
  133. "root_trace_id",
  134. "kind",
  135. "status",
  136. "task_ids",
  137. "attempt_ids",
  138. "validation_ids",
  139. "result_ref",
  140. "execution_epoch",
  141. "deadline_at",
  142. "error",
  143. "started_at",
  144. "completed_at",
  145. "created_at",
  146. "updated_at",
  147. ),
  148. "AttemptView": (
  149. "attempt_id",
  150. "task_id",
  151. "spec_version",
  152. "worker_trace_id",
  153. "worker_preset",
  154. "execution_mode",
  155. "accepted_child_decision_ids",
  156. "status",
  157. "operation_id",
  158. "execution_epoch",
  159. "continue_from_trace_id",
  160. "snapshot_id",
  161. "submission",
  162. "execution_stats",
  163. "error",
  164. "started_at",
  165. "completed_at",
  166. "duration_ms",
  167. "created_at",
  168. "updated_at",
  169. ),
  170. "ValidationView": (
  171. "validation_id",
  172. "task_id",
  173. "attempt_id",
  174. "spec_version",
  175. "snapshot_id",
  176. "validator_trace_id",
  177. "validator_preset",
  178. "validation_plan",
  179. "evidence_queries_used",
  180. "status",
  181. "operation_id",
  182. "execution_epoch",
  183. "verdict",
  184. "criterion_results",
  185. "summary",
  186. "evidence_refs",
  187. "unverified_claims",
  188. "risks",
  189. "recommendation",
  190. "execution_stats",
  191. "error",
  192. "started_at",
  193. "completed_at",
  194. "duration_ms",
  195. "created_at",
  196. "updated_at",
  197. ),
  198. "PlannerDecisionView": (
  199. "decision_id",
  200. "task_id",
  201. "action",
  202. "reason",
  203. "from_status",
  204. "to_status",
  205. "attempt_id",
  206. "validation_id",
  207. "payload",
  208. "created_at",
  209. ),
  210. "EvidenceRecordV1": (
  211. "schema_version",
  212. "evidence_id",
  213. "source_type",
  214. "tool_name",
  215. "query",
  216. "source_refs",
  217. "raw_artifact_ref",
  218. "summary",
  219. "supports",
  220. "confidence",
  221. "limitations",
  222. "created_at",
  223. ),
  224. "ScriptDirectionArtifactV1": (
  225. "schema_version",
  226. "goals",
  227. "criteria",
  228. "domain_criteria",
  229. "topic_refs",
  230. "persona_refs",
  231. "strategy_refs",
  232. "evidence_refs",
  233. "legacy_markdown",
  234. ),
  235. "CandidateLineageV1": (
  236. "scope_ref",
  237. "input_snapshot_ref",
  238. "input_closure_digest",
  239. "base_artifact_ref",
  240. "base_artifact_digest",
  241. "base_revision",
  242. "write_scope",
  243. "supersedes_decision_ids",
  244. "source_lineage",
  245. ),
  246. "StructureArtifactV1": (
  247. "schema_version",
  248. "scope_ref",
  249. "input_snapshot_ref",
  250. "input_closure_digest",
  251. "base_artifact_ref",
  252. "base_artifact_digest",
  253. "base_revision",
  254. "write_scope",
  255. "supersedes_decision_ids",
  256. "source_lineage",
  257. "paragraphs",
  258. ),
  259. "ParagraphArtifactV1": (
  260. "schema_version",
  261. "scope_ref",
  262. "input_snapshot_ref",
  263. "input_closure_digest",
  264. "base_artifact_ref",
  265. "base_artifact_digest",
  266. "base_revision",
  267. "write_scope",
  268. "supersedes_decision_ids",
  269. "source_lineage",
  270. "paragraphs",
  271. "elements",
  272. "paragraph_element_links",
  273. "change_manifest",
  274. ),
  275. "ElementSetArtifactV1": (
  276. "schema_version",
  277. "scope_ref",
  278. "input_snapshot_ref",
  279. "input_closure_digest",
  280. "base_artifact_ref",
  281. "base_artifact_digest",
  282. "base_revision",
  283. "write_scope",
  284. "supersedes_decision_ids",
  285. "source_lineage",
  286. "paragraphs",
  287. "elements",
  288. "paragraph_element_links",
  289. "change_manifest",
  290. ),
  291. "ComparisonArtifactV1": (
  292. "schema_version",
  293. "scope_ref",
  294. "input_snapshot_ref",
  295. "input_closure_digest",
  296. "base_artifact_ref",
  297. "base_artifact_digest",
  298. "base_revision",
  299. "write_scope",
  300. "supersedes_decision_ids",
  301. "source_lineage",
  302. "candidate_artifact_refs",
  303. "criterion_results",
  304. "conflicts",
  305. "recommendation",
  306. ),
  307. "StructuredScriptArtifactV1": (
  308. "schema_version",
  309. "direction_ref",
  310. "input_closure_digest",
  311. "paragraphs",
  312. "elements",
  313. "paragraph_element_links",
  314. "source_artifact_refs",
  315. "evidence_refs",
  316. "acceptance_notes",
  317. ),
  318. "CandidatePortfolioArtifactV1": (
  319. "schema_version",
  320. "adopted_structured_script_ref",
  321. "candidate_structured_script_refs",
  322. "accepted_decision_ids",
  323. "superseded_decision_ids",
  324. "rejected_or_held_decision_ids",
  325. "input_closure_digest",
  326. "unresolved_defects",
  327. "compose_order",
  328. ),
  329. "ArtifactVersion": (
  330. "artifact_version_id",
  331. "script_build_id",
  332. "task_id",
  333. "attempt_id",
  334. "spec_version",
  335. "artifact_type",
  336. "canonical_sha256",
  337. "state",
  338. "artifact",
  339. "created_at",
  340. "frozen_at",
  341. ),
  342. "ArtifactVersionRow": (
  343. "id",
  344. "script_build_id",
  345. "task_id",
  346. "attempt_id",
  347. "spec_version",
  348. "artifact_type",
  349. "legacy_branch_id",
  350. "base_revision",
  351. "parent_artifact_version_id",
  352. "canonical_json",
  353. "canonical_sha256",
  354. "state",
  355. "created_at",
  356. "frozen_at",
  357. "published_at",
  358. ),
  359. "ParagraphRow": (
  360. "id",
  361. "script_build_id",
  362. "branch_id",
  363. "base_ref_id",
  364. "paragraph_index",
  365. "level",
  366. "parent_id",
  367. "name",
  368. "content_range",
  369. "theme",
  370. "form",
  371. "function",
  372. "feeling",
  373. "theme_elements",
  374. "form_elements",
  375. "function_elements",
  376. "feeling_elements",
  377. "description",
  378. "full_description",
  379. "is_active",
  380. "created_at",
  381. "updated_at",
  382. ),
  383. "ElementRow": (
  384. "id",
  385. "script_build_id",
  386. "branch_id",
  387. "base_ref_id",
  388. "name",
  389. "dimension_primary",
  390. "dimension_secondary",
  391. "commonality_analysis",
  392. "topic_support",
  393. "weight_score",
  394. "support_elements",
  395. "is_active",
  396. "created_at",
  397. "updated_at",
  398. ),
  399. "ParagraphElementLinkRow": (
  400. "id",
  401. "script_build_id",
  402. "branch_id",
  403. "paragraph_id",
  404. "element_id",
  405. ),
  406. "RootDeliveryManifestV1": (
  407. "schema_version",
  408. "direction_ref",
  409. "candidate_portfolio_ref",
  410. "structured_script_ref",
  411. "input_closure_digest",
  412. "legacy_projection_digest",
  413. "build_summary",
  414. "blocking_defects",
  415. ),
  416. "LegacyProjectionCanonicalV1": (
  417. "schema_version",
  418. "direction",
  419. "summary",
  420. "paragraph_count",
  421. "element_count",
  422. "link_count",
  423. "paragraphs",
  424. "elements",
  425. "paragraph_element_links",
  426. ),
  427. "Publication": (
  428. "publication_id",
  429. "script_build_id",
  430. "publication_type",
  431. "accept_decision_id",
  432. "artifact_version_id",
  433. "expected_sha256",
  434. "state",
  435. "attempt_count",
  436. "publication_revision",
  437. "last_error_code",
  438. "last_error_summary",
  439. "created_at",
  440. "updated_at",
  441. "published_at",
  442. ),
  443. "PublicationResult": (
  444. "script_build_id",
  445. "publication_id",
  446. "publication_type",
  447. "state",
  448. "legacy_projection_digest",
  449. "committed",
  450. "post_commit_readback_ok",
  451. ),
  452. "HttpCommandRecord": (
  453. "id",
  454. "principal_scope_sha256",
  455. "route_family",
  456. "idempotency_key",
  457. "request_fingerprint",
  458. "preallocated_root_trace_id",
  459. "resource_id",
  460. "state",
  461. "response_status",
  462. "response_json",
  463. "created_at",
  464. "updated_at",
  465. ),
  466. }
  467. ENUM_CATALOG: dict[str, tuple[str, ...]] = {
  468. "BuildStatus": ("running", "stopping", "success", "failed", "partial", "stopped"),
  469. "TaskStatus": (
  470. "pending",
  471. "running",
  472. "awaiting_validation",
  473. "validating",
  474. "awaiting_decision",
  475. "needs_replan",
  476. "waiting_children",
  477. "completed",
  478. "superseded",
  479. "blocked",
  480. "cancelled",
  481. ),
  482. "AttemptStatus": ("running", "submitted", "failed", "stopped", "expired"),
  483. "ValidationRunStatus": (
  484. "pending",
  485. "running",
  486. "completed",
  487. "error",
  488. "stopped",
  489. "expired",
  490. ),
  491. "ValidationVerdict": ("passed", "failed", "inconclusive"),
  492. "DecisionAction": (
  493. "accept",
  494. "repair",
  495. "retry",
  496. "revalidate",
  497. "revise",
  498. "split",
  499. "block",
  500. "unblock",
  501. "cancel",
  502. "supersede",
  503. ),
  504. "ArtifactState": ("draft", "frozen", "published", "discarded"),
  505. "PublicationState": ("pending", "publishing", "published", "failed"),
  506. "ScriptTaskKind": (
  507. "direction",
  508. "pattern-retrieval",
  509. "decode-retrieval",
  510. "external-retrieval",
  511. "knowledge-retrieval",
  512. "structure",
  513. "paragraph",
  514. "element-set",
  515. "compare",
  516. "compose",
  517. "candidate-portfolio",
  518. "root-delivery",
  519. ),
  520. }