@inflexa-ai/harness 0.17.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (249) hide show
  1. package/dist/agents/report-builder.d.ts +2 -0
  2. package/dist/agents/report-builder.js +2 -0
  3. package/dist/agents/report-session-agent.d.ts +56 -0
  4. package/dist/agents/report-session-agent.js +72 -0
  5. package/dist/app/report-session-runtime.d.ts +72 -0
  6. package/dist/app/report-session-runtime.js +157 -0
  7. package/dist/app/spawn-report-session.d.ts +85 -0
  8. package/dist/app/spawn-report-session.js +83 -0
  9. package/dist/contracts/chat-events.d.ts +9 -0
  10. package/dist/contracts/index.d.ts +6 -2
  11. package/dist/contracts/index.js +3 -1
  12. package/dist/contracts/organ-system.d.ts +49 -0
  13. package/dist/contracts/organ-system.js +67 -0
  14. package/dist/contracts/report-blocks.d.ts +564 -0
  15. package/dist/contracts/report-blocks.js +117 -0
  16. package/dist/contracts/report-reference.d.ts +459 -0
  17. package/dist/contracts/report-reference.js +256 -0
  18. package/dist/contracts/schemas/chat-events.d.ts +2 -0
  19. package/dist/contracts/schemas/chat-events.js +2 -0
  20. package/dist/contracts/severity.d.ts +15 -0
  21. package/dist/contracts/severity.js +10 -0
  22. package/dist/contracts/target-dossier.d.ts +8675 -12972
  23. package/dist/contracts/target-dossier.js +534 -591
  24. package/dist/data/safety-panel-schema.d.ts +18 -5
  25. package/dist/data/safety-panel-schema.js +4 -4
  26. package/dist/execution/artifact-metadata.js +1 -0
  27. package/dist/execution/report-runner.js +1 -3
  28. package/dist/execution/run-synthesis.js +2 -0
  29. package/dist/index.d.ts +6 -0
  30. package/dist/index.js +19 -0
  31. package/dist/lib/async-utils.d.ts +16 -4
  32. package/dist/lib/async-utils.js +20 -15
  33. package/dist/lib/host-concurrency.js +1 -0
  34. package/dist/loop/__fixtures__/scripted-provider.js +23 -2
  35. package/dist/loop/run-agent.js +58 -10
  36. package/dist/loop/tool-detail.d.ts +40 -0
  37. package/dist/loop/tool-detail.js +35 -3
  38. package/dist/loop/types.d.ts +13 -0
  39. package/dist/memory/thread-history.d.ts +10 -0
  40. package/dist/memory/thread-history.js +12 -1
  41. package/dist/memory/thread-store.d.ts +4 -4
  42. package/dist/memory/thread-store.js +18 -9
  43. package/dist/prompts/report-session.d.ts +1 -0
  44. package/dist/prompts/report-session.js +89 -0
  45. package/dist/prompts/target-assessment/briefs/executive-recommendation.d.ts +1 -1
  46. package/dist/prompts/target-assessment/briefs/executive-recommendation.js +5 -5
  47. package/dist/prompts/target-assessment/briefs/liability-bullets.d.ts +1 -1
  48. package/dist/prompts/target-assessment/briefs/liability-bullets.js +1 -1
  49. package/dist/prompts/target-assessment/briefs/target-organ-liabilities.d.ts +1 -1
  50. package/dist/prompts/target-assessment/briefs/target-organ-liabilities.js +11 -3
  51. package/dist/prompts/target-assessment/investigation/adversarial-critique.d.ts +1 -0
  52. package/dist/prompts/target-assessment/investigation/adversarial-critique.js +67 -0
  53. package/dist/prompts/target-assessment/investigation/claim-reverification.d.ts +1 -0
  54. package/dist/prompts/target-assessment/investigation/claim-reverification.js +49 -0
  55. package/dist/prompts/target-assessment/investigation/index.d.ts +3 -0
  56. package/dist/prompts/target-assessment/investigation/index.js +3 -0
  57. package/dist/prompts/target-assessment/investigation/mechanism-proposal.d.ts +1 -0
  58. package/dist/prompts/target-assessment/investigation/mechanism-proposal.js +49 -0
  59. package/dist/prompts/target-assessment/tox-voice/index.d.ts +1 -1
  60. package/dist/prompts/target-assessment/tox-voice/vocabulary.d.ts +8 -5
  61. package/dist/prompts/target-assessment/tox-voice/vocabulary.js +9 -20
  62. package/dist/providers/__fixtures__/session.d.ts +5 -4
  63. package/dist/providers/__fixtures__/session.js +4 -4
  64. package/dist/providers/ai-sdk.d.ts +77 -0
  65. package/dist/providers/ai-sdk.js +149 -19
  66. package/dist/providers/errors.d.ts +14 -0
  67. package/dist/providers/errors.js +103 -18
  68. package/dist/providers/types.d.ts +16 -0
  69. package/dist/providers/types.js +10 -1
  70. package/dist/report-model/block-walk.d.ts +56 -0
  71. package/dist/report-model/block-walk.js +89 -0
  72. package/dist/report-model/draft-finish.d.ts +60 -0
  73. package/dist/report-model/draft-finish.js +56 -0
  74. package/dist/report-model/draft-operations.d.ts +125 -0
  75. package/dist/report-model/draft-operations.js +341 -0
  76. package/dist/report-model/draft-read.d.ts +59 -0
  77. package/dist/report-model/draft-read.js +109 -0
  78. package/dist/report-model/draft.d.ts +51 -0
  79. package/dist/report-model/draft.js +32 -0
  80. package/dist/report-model/fixture-resolver.d.ts +8 -0
  81. package/dist/report-model/fixture-resolver.js +252 -0
  82. package/dist/report-model/pin-snapshot.d.ts +30 -0
  83. package/dist/report-model/pin-snapshot.js +40 -0
  84. package/dist/report-model/reference-resolver.d.ts +113 -0
  85. package/dist/report-model/reference-resolver.js +60 -0
  86. package/dist/report-model/structural-validation.d.ts +22 -0
  87. package/dist/report-model/structural-validation.js +68 -0
  88. package/dist/report-model/validate.d.ts +72 -0
  89. package/dist/report-model/validate.js +95 -0
  90. package/dist/report-render/chart.d.ts +33 -0
  91. package/dist/report-render/chart.js +538 -0
  92. package/dist/report-render/page.d.ts +127 -0
  93. package/dist/report-render/page.js +307 -0
  94. package/dist/report-render/references.d.ts +32 -0
  95. package/dist/report-render/references.js +44 -0
  96. package/dist/report-render/render.d.ts +25 -0
  97. package/dist/report-render/render.js +125 -0
  98. package/dist/report-render/script-json.d.ts +13 -0
  99. package/dist/report-render/script-json.js +15 -0
  100. package/dist/report-render/types.d.ts +39 -0
  101. package/dist/report-render/types.js +10 -0
  102. package/dist/report-render/value-bridge.d.ts +62 -0
  103. package/dist/report-render/value-bridge.js +82 -0
  104. package/dist/report-render/views/chart-view.d.ts +11 -0
  105. package/dist/report-render/views/chart-view.js +23 -0
  106. package/dist/report-render/views/page-view.d.ts +20 -0
  107. package/dist/report-render/views/page-view.js +49 -0
  108. package/dist/report-render/views/prose.d.ts +28 -0
  109. package/dist/report-render/views/prose.js +75 -0
  110. package/dist/report-render/views/references-view.d.ts +20 -0
  111. package/dist/report-render/views/references-view.js +64 -0
  112. package/dist/report-render/views/values.d.ts +42 -0
  113. package/dist/report-render/views/values.js +43 -0
  114. package/dist/runtime/assemble.d.ts +15 -0
  115. package/dist/runtime/assemble.js +28 -6
  116. package/dist/runtime/boot.d.ts +3 -3
  117. package/dist/runtime/boot.js +15 -4
  118. package/dist/runtime/dbos.d.ts +4 -4
  119. package/dist/state/artifacts.d.ts +16 -0
  120. package/dist/state/artifacts.js +18 -0
  121. package/dist/state/init.js +54 -0
  122. package/dist/state/purge-analysis.js +2 -0
  123. package/dist/state/report-session-state.d.ts +112 -0
  124. package/dist/state/report-session-state.js +150 -0
  125. package/dist/state/report-versions.d.ts +129 -0
  126. package/dist/state/report-versions.js +167 -0
  127. package/dist/state/snapshot-parse.d.ts +34 -0
  128. package/dist/state/snapshot-parse.js +82 -0
  129. package/dist/tasks/data-profile.js +1 -0
  130. package/dist/tools/ad-hoc-router.d.ts +7 -2
  131. package/dist/tools/ad-hoc-router.js +2 -1
  132. package/dist/tools/bio/chembl.js +1 -0
  133. package/dist/tools/bio/comptox.js +1 -0
  134. package/dist/tools/bio/drug-gene-interactions.js +1 -0
  135. package/dist/tools/bio/gene-disease-evidence.js +1 -0
  136. package/dist/tools/bio/gene-preclinical-profile.js +1 -0
  137. package/dist/tools/bio/keys.d.ts +3 -2
  138. package/dist/tools/bio/keys.js +3 -2
  139. package/dist/tools/bio/lookup-annotation.js +1 -0
  140. package/dist/tools/bio/opentargets.d.ts +3 -3
  141. package/dist/tools/bio/opentargets.js +4 -3
  142. package/dist/tools/bio/pubchem.js +1 -0
  143. package/dist/tools/bio/search-clinical-trials.js +1 -0
  144. package/dist/tools/bio/search-faers.js +1 -0
  145. package/dist/tools/bio/search-geo-datasets.js +1 -0
  146. package/dist/tools/bio/search-interactions.js +1 -0
  147. package/dist/tools/bio/target-safety.d.ts +4 -6
  148. package/dist/tools/bio/target-safety.js +7 -6
  149. package/dist/tools/define-tool.d.ts +19 -12
  150. package/dist/tools/define-tool.js +4 -2
  151. package/dist/tools/display/show-user.js +1 -0
  152. package/dist/tools/iterate-report.js +2 -0
  153. package/dist/tools/lib/chembl-client.d.ts +2 -0
  154. package/dist/tools/lib/chembl-client.js +1 -0
  155. package/dist/tools/lib/monarch-client.d.ts +42 -0
  156. package/dist/tools/lib/monarch-client.js +100 -0
  157. package/dist/tools/report/build-report.js +1 -0
  158. package/dist/tools/report/mint-preview-url.js +1 -0
  159. package/dist/tools/report/preview-snapshot.js +1 -0
  160. package/dist/tools/report/submit-report.js +1 -0
  161. package/dist/tools/report/version-fs.js +4 -0
  162. package/dist/tools/report-authoring/authoring-tools.d.ts +241 -0
  163. package/dist/tools/report-authoring/authoring-tools.js +460 -0
  164. package/dist/tools/report-session/index.d.ts +8 -0
  165. package/dist/tools/report-session/index.js +8 -0
  166. package/dist/tools/report-session/preview-report.d.ts +90 -0
  167. package/dist/tools/report-session/preview-report.js +245 -0
  168. package/dist/tools/research/context7-docs.js +2 -0
  169. package/dist/tools/research/generate-analogy-report.js +1 -0
  170. package/dist/tools/research/generate-plan.js +7 -2
  171. package/dist/tools/research/inspect-data-profile.js +4 -0
  172. package/dist/tools/research/literature-reviewer.js +1 -0
  173. package/dist/tools/research/search-arxiv.js +1 -0
  174. package/dist/tools/research/search-github-repos.js +1 -0
  175. package/dist/tools/research/search-semantic-scholar.js +1 -0
  176. package/dist/tools/sandbox/list-available-packages.js +23 -0
  177. package/dist/tools/sandbox/list-available-refs.js +36 -0
  178. package/dist/tools/sandbox/report-blocker.js +1 -0
  179. package/dist/tools/sandbox/skills.js +2 -0
  180. package/dist/tools/workspace/file-stat.js +1 -0
  181. package/dist/tools/workspace/show-file.js +2 -0
  182. package/dist/tools/workspace/show-plan.js +1 -0
  183. package/dist/workflows/execute-analysis.d.ts +5 -1
  184. package/dist/workflows/execute-analysis.js +5 -5
  185. package/dist/workflows/execute-target-assessment.d.ts +13 -2
  186. package/dist/workflows/execute-target-assessment.js +78 -16
  187. package/dist/workflows/target-assessment/assemblers/index.d.ts +1 -1
  188. package/dist/workflows/target-assessment/assemblers/index.js +1 -1
  189. package/dist/workflows/target-assessment/assemblers/literature.d.ts +9 -27
  190. package/dist/workflows/target-assessment/assemblers/literature.js +32 -48
  191. package/dist/workflows/target-assessment/assemblers/orchestrator.d.ts +17 -9
  192. package/dist/workflows/target-assessment/assemblers/orchestrator.js +195 -85
  193. package/dist/workflows/target-assessment/assemblers/safety.d.ts +70 -48
  194. package/dist/workflows/target-assessment/assemblers/safety.js +125 -42
  195. package/dist/workflows/target-assessment/collectors/index.d.ts +5 -2
  196. package/dist/workflows/target-assessment/collectors/index.js +48 -5
  197. package/dist/workflows/target-assessment/coverage.d.ts +43 -27
  198. package/dist/workflows/target-assessment/coverage.js +33 -29
  199. package/dist/workflows/target-assessment/fanout/index.js +1 -0
  200. package/dist/workflows/target-assessment/investigation/index.d.ts +97 -0
  201. package/dist/workflows/target-assessment/investigation/index.js +419 -0
  202. package/dist/workflows/target-assessment/lib/approval-precedents.d.ts +26 -5
  203. package/dist/workflows/target-assessment/lib/approval-precedents.js +95 -29
  204. package/dist/workflows/target-assessment/lib/citation-validator.js +1 -1
  205. package/dist/workflows/target-assessment/lib/clinical-consequence-annotator.d.ts +2 -2
  206. package/dist/workflows/target-assessment/lib/clinical-evidence-attribution.d.ts +2 -3
  207. package/dist/workflows/target-assessment/lib/clinical-evidence-attribution.js +0 -4
  208. package/dist/workflows/target-assessment/lib/compute-derived.d.ts +6 -5
  209. package/dist/workflows/target-assessment/lib/compute-derived.js +14 -5
  210. package/dist/workflows/target-assessment/lib/family-complex-supplement.d.ts +5 -6
  211. package/dist/workflows/target-assessment/lib/family-complex-supplement.js +2 -3
  212. package/dist/workflows/target-assessment/lib/fda-label-safety.d.ts +72 -0
  213. package/dist/workflows/target-assessment/lib/fda-label-safety.js +166 -0
  214. package/dist/workflows/target-assessment/lib/heterodimer-filter.d.ts +0 -9
  215. package/dist/workflows/target-assessment/lib/heterodimer-filter.js +0 -10
  216. package/dist/workflows/target-assessment/lib/hpo-organ-map.d.ts +34 -0
  217. package/dist/workflows/target-assessment/lib/hpo-organ-map.js +63 -0
  218. package/dist/workflows/target-assessment/lib/impc-organ-map.d.ts +19 -0
  219. package/dist/workflows/target-assessment/lib/impc-organ-map.js +39 -0
  220. package/dist/workflows/target-assessment/lib/meddra-organ-map.d.ts +24 -14
  221. package/dist/workflows/target-assessment/lib/meddra-organ-map.js +59 -47
  222. package/dist/workflows/target-assessment/lib/recommendation-sanitizer.js +1 -1
  223. package/dist/workflows/target-assessment/lib/regulatory-actions.d.ts +2 -3
  224. package/dist/workflows/target-assessment/lib/regulatory-actions.js +33 -4
  225. package/dist/workflows/target-assessment/lib/safety-corroboration.d.ts +44 -0
  226. package/dist/workflows/target-assessment/lib/safety-corroboration.js +273 -0
  227. package/dist/workflows/target-assessment/lib/target-identity-filter.d.ts +5 -7
  228. package/dist/workflows/target-assessment/lib/target-identity-filter.js +5 -7
  229. package/dist/workflows/target-assessment/metrics.d.ts +1 -6
  230. package/dist/workflows/target-assessment/metrics.js +1 -13
  231. package/dist/workflows/target-assessment/phase4-assemble.d.ts +2147 -807
  232. package/dist/workflows/target-assessment/phase4-assemble.js +19 -19
  233. package/dist/workflows/target-assessment/phase5-persist.d.ts +20 -21
  234. package/dist/workflows/target-assessment/phase5-persist.js +56 -173
  235. package/dist/workflows/target-assessment/schemas.d.ts +46 -1
  236. package/dist/workflows/target-assessment/schemas.js +19 -0
  237. package/dist/workflows/target-assessment/steps/fanout/polypharm-for-one-modulator-step.d.ts +1 -0
  238. package/dist/workflows/target-assessment/steps/fanout/polypharm-for-one-modulator-step.js +2 -0
  239. package/dist/workflows/target-assessment/steps/phase2-aggregate.d.ts +26 -62
  240. package/dist/workflows/target-assessment/steps/phase2-aggregate.js +0 -4
  241. package/dist/workflows/target-assessment/steps/phase3-aggregate.d.ts +27 -154
  242. package/dist/workflows/target-assessment/steps/phase3-aggregate.js +0 -6
  243. package/dist/workflows/target-assessment/steps/synthesis/diagnostics.d.ts +0 -6
  244. package/dist/workflows/target-assessment/steps/synthesis/diagnostics.js +0 -18
  245. package/dist/workflows/target-assessment/sub-workflows/per-modulator-polypharm.d.ts +1 -0
  246. package/dist/workflows/target-assessment/synthesis/index.d.ts +52 -5
  247. package/dist/workflows/target-assessment/synthesis/index.js +4 -1
  248. package/dist/workflows/target-assessment/synthesis-probes.d.ts +3 -3
  249. package/package.json +4 -1
@@ -0,0 +1,117 @@
1
+ /**
2
+ * The composable block tree of a report.
3
+ *
4
+ * A block is one of eight kinds. The shape of each kind carries its grammar. A `text` block has no
5
+ * binding field, thus an unbound claim is unrepresentable. A `metric` value slot admits one scalar
6
+ * reference only, thus a numeric literal cannot sit there. No atom holds a child-block array, thus a
7
+ * chart inside a metric is unrepresentable. The grammar is the shape, and not a separate pass.
8
+ *
9
+ * The tree is recursive: a `section` holds child blocks, and a child can be another section.
10
+ *
11
+ * Every object schema here and in the reference module is strict. A strict object makes an extra field
12
+ * a parse failure, and not a field that the parser strips in silence. Thus a forbidden field, such as a
13
+ * binding on a `text` block or a child-block array on an atom, is rejected. The absence of a field is a
14
+ * rule only when an extra field fails the parse.
15
+ */
16
+ import { z } from "zod";
17
+ import { ArtifactFileReferenceSchema, ArtifactTableReferenceSchema, CitationReferenceSchema, ReferenceSchema, ScalarReferenceSchema, } from "./report-reference.js";
18
+ /** The chart vocabulary. Each value names one plot form. */
19
+ const ChartTypeSchema = z.enum(["bar", "line", "scatter", "histogram", "box", "heatmap", "pie"]);
20
+ /** The mapping from a data column to a visual channel. Each channel is optional. */
21
+ const ChartEncodingSchema = z.strictObject({
22
+ x: z.string().optional().describe("The column on the x axis."),
23
+ y: z.string().optional().describe("The column on the y axis."),
24
+ group: z.string().optional().describe("The column that splits and colors the series."),
25
+ value: z.string().optional().describe("The value column for a pie or heatmap."),
26
+ });
27
+ /** Prose with no binding. The absence of a binding field is the rule for this kind. */
28
+ export const TextBlockSchema = z.strictObject({
29
+ kind: z.literal("text"),
30
+ id: z.string().min(1).describe("The stable identity of the block."),
31
+ content: z.strictObject({ prose: z.string() }),
32
+ });
33
+ /** Prose with at least one reference that justifies it. */
34
+ export const ClaimBlockSchema = z.strictObject({
35
+ kind: z.literal("claim"),
36
+ id: z.string().min(1).describe("The stable identity of the block."),
37
+ content: z.strictObject({ prose: z.string() }),
38
+ bindings: z.array(ReferenceSchema).min(1).describe("The evidence that justifies the claim."),
39
+ });
40
+ /** A labeled number whose value comes from one scalar reference. */
41
+ export const MetricBlockSchema = z.strictObject({
42
+ kind: z.literal("metric"),
43
+ id: z.string().min(1).describe("The stable identity of the block."),
44
+ label: z.string(),
45
+ value: ScalarReferenceSchema.describe("The one scalar reference that gives the metric value."),
46
+ });
47
+ /** A whole-table artifact rendered as a table. */
48
+ export const TableBlockSchema = z.strictObject({
49
+ kind: z.literal("table"),
50
+ id: z.string().min(1).describe("The stable identity of the block."),
51
+ title: z.string().optional(),
52
+ binding: ArtifactTableReferenceSchema.describe("The whole-table artifact to render."),
53
+ caption: z.string().optional(),
54
+ });
55
+ /** A whole-table artifact rendered as a chart, with the plot form and the channel mapping. */
56
+ export const ChartBlockSchema = z.strictObject({
57
+ kind: z.literal("chart"),
58
+ id: z.string().min(1).describe("The stable identity of the block."),
59
+ title: z.string().optional(),
60
+ binding: ArtifactTableReferenceSchema.describe("The whole-table artifact to plot."),
61
+ chartType: ChartTypeSchema,
62
+ encoding: ChartEncodingSchema,
63
+ caption: z.string().optional(),
64
+ });
65
+ /** A static image artifact. An image has no per-cell address, thus it is pinned whole-file. */
66
+ export const FigureBlockSchema = z.strictObject({
67
+ kind: z.literal("figure"),
68
+ id: z.string().min(1).describe("The stable identity of the block."),
69
+ binding: ArtifactFileReferenceSchema.describe("The image artifact, pinned whole-file by path and hash."),
70
+ caption: z.string().optional(),
71
+ });
72
+ /** An external source, rendered from a citation reference. */
73
+ export const CitationBlockSchema = z.strictObject({
74
+ kind: z.literal("citation"),
75
+ id: z.string().min(1).describe("The stable identity of the block."),
76
+ binding: CitationReferenceSchema,
77
+ note: z.string().optional(),
78
+ });
79
+ /**
80
+ * The seven atoms, as one tuple.
81
+ *
82
+ * A section is the only kind whose rules differ between a finished report and a draft. Thus the atoms are
83
+ * the shared part, and every union of block kinds spreads this tuple beside its own section member. A
84
+ * ninth kind lands here one time, and each union gets it.
85
+ */
86
+ export const ATOM_BLOCK_SCHEMAS = [
87
+ TextBlockSchema,
88
+ ClaimBlockSchema,
89
+ MetricBlockSchema,
90
+ TableBlockSchema,
91
+ ChartBlockSchema,
92
+ FigureBlockSchema,
93
+ CitationBlockSchema,
94
+ ];
95
+ /**
96
+ * A section holds at least one child block, thus an empty section is invalid. The `blocks` field is a
97
+ * `z.lazy` and not a getter, so the discriminated union reads the `kind` discriminator at construction
98
+ * time without a reference to `BlockSchema` before it exists.
99
+ */
100
+ export const SectionBlockSchema = z.strictObject({
101
+ kind: z.literal("section"),
102
+ id: z.string().min(1),
103
+ title: z.string(),
104
+ blocks: z.lazy(() => z.array(BlockSchema).min(1)),
105
+ });
106
+ /** The block union. A `z.ZodType<Block>` annotation gives the recursive members a stable type. */
107
+ export const BlockSchema = z.discriminatedUnion("kind", [SectionBlockSchema, ...ATOM_BLOCK_SCHEMAS]);
108
+ /**
109
+ * The root of a report. It holds at least one section, thus an empty report is invalid.
110
+ *
111
+ * The title carries `min(1)`, because an untitled report is incomplete in the same way that an empty
112
+ * section is. A draft relaxes it, and this schema gates it one time, at the finish.
113
+ */
114
+ export const ReportDocumentSchema = z.strictObject({
115
+ title: z.string().min(1),
116
+ sections: z.array(SectionBlockSchema).min(1).describe("The top-level sections, each with at least one block."),
117
+ });
@@ -0,0 +1,459 @@
1
+ /**
2
+ * A reference binds a report block to the evidence that justifies it. It is the one canonical way a
3
+ * block points at a value, a table, a derived quantity, or an external source.
4
+ *
5
+ * The reference lives here, in `contracts/`, because a consumer reads it back after a run. The consumer
6
+ * imports this module without the harness's own dependencies, thus it holds a reference as plain data.
7
+ *
8
+ * Resolution reads the evidence again at render time. The `assert` field is the authored belief, and
9
+ * the resolver matches the fresh read against it.
10
+ */
11
+ import { type Result } from "neverthrow";
12
+ import { z } from "zod";
13
+ /**
14
+ * A reference to one scalar value inside an artifact, addressed by a locator. It resolves to a scalar,
15
+ * thus it carries the value assert.
16
+ */
17
+ export declare const ArtifactValueReferenceSchema: z.ZodObject<{
18
+ unit: z.ZodOptional<z.ZodString>;
19
+ format: z.ZodOptional<z.ZodString>;
20
+ locator: z.ZodObject<{
21
+ column: z.ZodString;
22
+ rowFilter: z.ZodOptional<z.ZodObject<{
23
+ column: z.ZodString;
24
+ op: z.ZodLiteral<"eq">;
25
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
26
+ }, z.core.$strict>>;
27
+ row: z.ZodOptional<z.ZodNumber>;
28
+ }, z.core.$strict>;
29
+ assert: z.ZodOptional<z.ZodObject<{
30
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
31
+ tolerance: z.ZodOptional<z.ZodNumber>;
32
+ }, z.core.$strict>>;
33
+ run: z.ZodOptional<z.ZodString>;
34
+ path: z.ZodString;
35
+ hash: z.ZodString;
36
+ snapshot: z.ZodOptional<z.ZodString>;
37
+ kind: z.ZodLiteral<"artifact-value">;
38
+ }, z.core.$strict>;
39
+ /**
40
+ * A reference to a whole table artifact. It carries no locator, because it binds every row.
41
+ *
42
+ * It carries no assert. A table is not one value, thus the only belief that an author can hold about it
43
+ * is its bytes, and the pinned `hash` already carries that belief.
44
+ */
45
+ export declare const ArtifactTableReferenceSchema: z.ZodObject<{
46
+ unit: z.ZodOptional<z.ZodString>;
47
+ format: z.ZodOptional<z.ZodString>;
48
+ columns: z.ZodOptional<z.ZodArray<z.ZodString>>;
49
+ run: z.ZodOptional<z.ZodString>;
50
+ path: z.ZodString;
51
+ hash: z.ZodString;
52
+ snapshot: z.ZodOptional<z.ZodString>;
53
+ kind: z.ZodLiteral<"artifact-table">;
54
+ }, z.core.$strict>;
55
+ /**
56
+ * A reference to a whole artifact file, for example an image. It carries no locator and no columns,
57
+ * because a file is pinned whole and has no addressable cell inside it. It carries no assert, for the
58
+ * same reason as a table reference.
59
+ */
60
+ export declare const ArtifactFileReferenceSchema: z.ZodObject<{
61
+ unit: z.ZodOptional<z.ZodString>;
62
+ format: z.ZodOptional<z.ZodString>;
63
+ run: z.ZodOptional<z.ZodString>;
64
+ path: z.ZodString;
65
+ hash: z.ZodString;
66
+ snapshot: z.ZodOptional<z.ZodString>;
67
+ kind: z.ZodLiteral<"artifact-file">;
68
+ }, z.core.$strict>;
69
+ /**
70
+ * A reference to an external source, addressed by an external identifier. It resolves to the prefixed
71
+ * key, thus its assert compares against that key and carries no hash.
72
+ */
73
+ export declare const CitationReferenceSchema: z.ZodObject<{
74
+ unit: z.ZodOptional<z.ZodString>;
75
+ format: z.ZodOptional<z.ZodString>;
76
+ kind: z.ZodLiteral<"citation">;
77
+ idKind: z.ZodEnum<{
78
+ doi: "doi";
79
+ pmid: "pmid";
80
+ arxiv: "arxiv";
81
+ }>;
82
+ id: z.ZodString;
83
+ raw: z.ZodString;
84
+ assert: z.ZodOptional<z.ZodObject<{
85
+ value: z.ZodString;
86
+ }, z.core.$strict>>;
87
+ }, z.core.$strict>;
88
+ /**
89
+ * The one reference kind that a derivation can consume.
90
+ *
91
+ * The arithmetic needs a scalar, and `artifact-value` is the only reference that resolves to one without
92
+ * itself being a derivation. A table, a file, and a citation resolve to something else, thus each is
93
+ * unrepresentable here rather than a parse that succeeds and then always fails at resolution. A
94
+ * derivation is out of the set too, thus a derivation over a derivation stays unrepresentable.
95
+ */
96
+ export declare const DerivationInputReferenceSchema: z.ZodObject<{
97
+ unit: z.ZodOptional<z.ZodString>;
98
+ format: z.ZodOptional<z.ZodString>;
99
+ locator: z.ZodObject<{
100
+ column: z.ZodString;
101
+ rowFilter: z.ZodOptional<z.ZodObject<{
102
+ column: z.ZodString;
103
+ op: z.ZodLiteral<"eq">;
104
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
105
+ }, z.core.$strict>>;
106
+ row: z.ZodOptional<z.ZodNumber>;
107
+ }, z.core.$strict>;
108
+ assert: z.ZodOptional<z.ZodObject<{
109
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
110
+ tolerance: z.ZodOptional<z.ZodNumber>;
111
+ }, z.core.$strict>>;
112
+ run: z.ZodOptional<z.ZodString>;
113
+ path: z.ZodString;
114
+ hash: z.ZodString;
115
+ snapshot: z.ZodOptional<z.ZodString>;
116
+ kind: z.ZodLiteral<"artifact-value">;
117
+ }, z.core.$strict>;
118
+ /**
119
+ * A reference to a value computed from other references. Each of the three operations takes two inputs,
120
+ * thus `inputs` holds exactly two scalar-resolving references and no other count is representable. The
121
+ * result is computed and not artifact-backed, thus its assert carries the value fields only.
122
+ */
123
+ export declare const DerivationReferenceSchema: z.ZodObject<{
124
+ unit: z.ZodOptional<z.ZodString>;
125
+ format: z.ZodOptional<z.ZodString>;
126
+ kind: z.ZodLiteral<"derivation">;
127
+ op: z.ZodEnum<{
128
+ ratio: "ratio";
129
+ delta: "delta";
130
+ pctChange: "pctChange";
131
+ }>;
132
+ inputs: z.ZodArray<z.ZodObject<{
133
+ unit: z.ZodOptional<z.ZodString>;
134
+ format: z.ZodOptional<z.ZodString>;
135
+ locator: z.ZodObject<{
136
+ column: z.ZodString;
137
+ rowFilter: z.ZodOptional<z.ZodObject<{
138
+ column: z.ZodString;
139
+ op: z.ZodLiteral<"eq">;
140
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
141
+ }, z.core.$strict>>;
142
+ row: z.ZodOptional<z.ZodNumber>;
143
+ }, z.core.$strict>;
144
+ assert: z.ZodOptional<z.ZodObject<{
145
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
146
+ tolerance: z.ZodOptional<z.ZodNumber>;
147
+ }, z.core.$strict>>;
148
+ run: z.ZodOptional<z.ZodString>;
149
+ path: z.ZodString;
150
+ hash: z.ZodString;
151
+ snapshot: z.ZodOptional<z.ZodString>;
152
+ kind: z.ZodLiteral<"artifact-value">;
153
+ }, z.core.$strict>>;
154
+ assert: z.ZodOptional<z.ZodObject<{
155
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
156
+ tolerance: z.ZodOptional<z.ZodNumber>;
157
+ }, z.core.$strict>>;
158
+ }, z.core.$strict>;
159
+ /** The full reference union. A block binds to one of these. */
160
+ export declare const ReferenceSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
161
+ unit: z.ZodOptional<z.ZodString>;
162
+ format: z.ZodOptional<z.ZodString>;
163
+ locator: z.ZodObject<{
164
+ column: z.ZodString;
165
+ rowFilter: z.ZodOptional<z.ZodObject<{
166
+ column: z.ZodString;
167
+ op: z.ZodLiteral<"eq">;
168
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
169
+ }, z.core.$strict>>;
170
+ row: z.ZodOptional<z.ZodNumber>;
171
+ }, z.core.$strict>;
172
+ assert: z.ZodOptional<z.ZodObject<{
173
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
174
+ tolerance: z.ZodOptional<z.ZodNumber>;
175
+ }, z.core.$strict>>;
176
+ run: z.ZodOptional<z.ZodString>;
177
+ path: z.ZodString;
178
+ hash: z.ZodString;
179
+ snapshot: z.ZodOptional<z.ZodString>;
180
+ kind: z.ZodLiteral<"artifact-value">;
181
+ }, z.core.$strict>, z.ZodObject<{
182
+ unit: z.ZodOptional<z.ZodString>;
183
+ format: z.ZodOptional<z.ZodString>;
184
+ columns: z.ZodOptional<z.ZodArray<z.ZodString>>;
185
+ run: z.ZodOptional<z.ZodString>;
186
+ path: z.ZodString;
187
+ hash: z.ZodString;
188
+ snapshot: z.ZodOptional<z.ZodString>;
189
+ kind: z.ZodLiteral<"artifact-table">;
190
+ }, z.core.$strict>, z.ZodObject<{
191
+ unit: z.ZodOptional<z.ZodString>;
192
+ format: z.ZodOptional<z.ZodString>;
193
+ run: z.ZodOptional<z.ZodString>;
194
+ path: z.ZodString;
195
+ hash: z.ZodString;
196
+ snapshot: z.ZodOptional<z.ZodString>;
197
+ kind: z.ZodLiteral<"artifact-file">;
198
+ }, z.core.$strict>, z.ZodObject<{
199
+ unit: z.ZodOptional<z.ZodString>;
200
+ format: z.ZodOptional<z.ZodString>;
201
+ kind: z.ZodLiteral<"derivation">;
202
+ op: z.ZodEnum<{
203
+ ratio: "ratio";
204
+ delta: "delta";
205
+ pctChange: "pctChange";
206
+ }>;
207
+ inputs: z.ZodArray<z.ZodObject<{
208
+ unit: z.ZodOptional<z.ZodString>;
209
+ format: z.ZodOptional<z.ZodString>;
210
+ locator: z.ZodObject<{
211
+ column: z.ZodString;
212
+ rowFilter: z.ZodOptional<z.ZodObject<{
213
+ column: z.ZodString;
214
+ op: z.ZodLiteral<"eq">;
215
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
216
+ }, z.core.$strict>>;
217
+ row: z.ZodOptional<z.ZodNumber>;
218
+ }, z.core.$strict>;
219
+ assert: z.ZodOptional<z.ZodObject<{
220
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
221
+ tolerance: z.ZodOptional<z.ZodNumber>;
222
+ }, z.core.$strict>>;
223
+ run: z.ZodOptional<z.ZodString>;
224
+ path: z.ZodString;
225
+ hash: z.ZodString;
226
+ snapshot: z.ZodOptional<z.ZodString>;
227
+ kind: z.ZodLiteral<"artifact-value">;
228
+ }, z.core.$strict>>;
229
+ assert: z.ZodOptional<z.ZodObject<{
230
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
231
+ tolerance: z.ZodOptional<z.ZodNumber>;
232
+ }, z.core.$strict>>;
233
+ }, z.core.$strict>, z.ZodObject<{
234
+ unit: z.ZodOptional<z.ZodString>;
235
+ format: z.ZodOptional<z.ZodString>;
236
+ kind: z.ZodLiteral<"citation">;
237
+ idKind: z.ZodEnum<{
238
+ doi: "doi";
239
+ pmid: "pmid";
240
+ arxiv: "arxiv";
241
+ }>;
242
+ id: z.ZodString;
243
+ raw: z.ZodString;
244
+ assert: z.ZodOptional<z.ZodObject<{
245
+ value: z.ZodString;
246
+ }, z.core.$strict>>;
247
+ }, z.core.$strict>], "kind">;
248
+ /**
249
+ * The references that resolve to one scalar value. A metric's value slot admits only these, thus no
250
+ * numeric literal can sit in the slot: the type admits a reference only.
251
+ */
252
+ export declare const ScalarReferenceSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
253
+ unit: z.ZodOptional<z.ZodString>;
254
+ format: z.ZodOptional<z.ZodString>;
255
+ locator: z.ZodObject<{
256
+ column: z.ZodString;
257
+ rowFilter: z.ZodOptional<z.ZodObject<{
258
+ column: z.ZodString;
259
+ op: z.ZodLiteral<"eq">;
260
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
261
+ }, z.core.$strict>>;
262
+ row: z.ZodOptional<z.ZodNumber>;
263
+ }, z.core.$strict>;
264
+ assert: z.ZodOptional<z.ZodObject<{
265
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
266
+ tolerance: z.ZodOptional<z.ZodNumber>;
267
+ }, z.core.$strict>>;
268
+ run: z.ZodOptional<z.ZodString>;
269
+ path: z.ZodString;
270
+ hash: z.ZodString;
271
+ snapshot: z.ZodOptional<z.ZodString>;
272
+ kind: z.ZodLiteral<"artifact-value">;
273
+ }, z.core.$strict>, z.ZodObject<{
274
+ unit: z.ZodOptional<z.ZodString>;
275
+ format: z.ZodOptional<z.ZodString>;
276
+ kind: z.ZodLiteral<"derivation">;
277
+ op: z.ZodEnum<{
278
+ ratio: "ratio";
279
+ delta: "delta";
280
+ pctChange: "pctChange";
281
+ }>;
282
+ inputs: z.ZodArray<z.ZodObject<{
283
+ unit: z.ZodOptional<z.ZodString>;
284
+ format: z.ZodOptional<z.ZodString>;
285
+ locator: z.ZodObject<{
286
+ column: z.ZodString;
287
+ rowFilter: z.ZodOptional<z.ZodObject<{
288
+ column: z.ZodString;
289
+ op: z.ZodLiteral<"eq">;
290
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
291
+ }, z.core.$strict>>;
292
+ row: z.ZodOptional<z.ZodNumber>;
293
+ }, z.core.$strict>;
294
+ assert: z.ZodOptional<z.ZodObject<{
295
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
296
+ tolerance: z.ZodOptional<z.ZodNumber>;
297
+ }, z.core.$strict>>;
298
+ run: z.ZodOptional<z.ZodString>;
299
+ path: z.ZodString;
300
+ hash: z.ZodString;
301
+ snapshot: z.ZodOptional<z.ZodString>;
302
+ kind: z.ZodLiteral<"artifact-value">;
303
+ }, z.core.$strict>>;
304
+ assert: z.ZodOptional<z.ZodObject<{
305
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
306
+ tolerance: z.ZodOptional<z.ZodNumber>;
307
+ }, z.core.$strict>>;
308
+ }, z.core.$strict>], "kind">;
309
+ /**
310
+ * The reason that a reference did not resolve.
311
+ *
312
+ * Two of the reasons are easy to confuse. `artifact-missing` means that the snapshot holds no entry for
313
+ * the path. `unreadable-artifact` means that the entry exists, and that the resolver cannot read the
314
+ * artifact as a table. Two conditions give the second reason. The file type refuses a read of a cell, or
315
+ * the bytes are unrecoverable.
316
+ */
317
+ export declare const UnresolvedReasonSchema: z.ZodEnum<{
318
+ "artifact-missing": "artifact-missing";
319
+ "hash-mismatch": "hash-mismatch";
320
+ "locator-out-of-range": "locator-out-of-range";
321
+ "ambiguous-match": "ambiguous-match";
322
+ "assertion-failed": "assertion-failed";
323
+ "unreadable-artifact": "unreadable-artifact";
324
+ }>;
325
+ /** A reference that resolution could not bind, with the reason and an optional detail. */
326
+ export declare const UnresolvedReferenceSchema: z.ZodObject<{
327
+ reference: z.ZodDiscriminatedUnion<[z.ZodObject<{
328
+ unit: z.ZodOptional<z.ZodString>;
329
+ format: z.ZodOptional<z.ZodString>;
330
+ locator: z.ZodObject<{
331
+ column: z.ZodString;
332
+ rowFilter: z.ZodOptional<z.ZodObject<{
333
+ column: z.ZodString;
334
+ op: z.ZodLiteral<"eq">;
335
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
336
+ }, z.core.$strict>>;
337
+ row: z.ZodOptional<z.ZodNumber>;
338
+ }, z.core.$strict>;
339
+ assert: z.ZodOptional<z.ZodObject<{
340
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
341
+ tolerance: z.ZodOptional<z.ZodNumber>;
342
+ }, z.core.$strict>>;
343
+ run: z.ZodOptional<z.ZodString>;
344
+ path: z.ZodString;
345
+ hash: z.ZodString;
346
+ snapshot: z.ZodOptional<z.ZodString>;
347
+ kind: z.ZodLiteral<"artifact-value">;
348
+ }, z.core.$strict>, z.ZodObject<{
349
+ unit: z.ZodOptional<z.ZodString>;
350
+ format: z.ZodOptional<z.ZodString>;
351
+ columns: z.ZodOptional<z.ZodArray<z.ZodString>>;
352
+ run: z.ZodOptional<z.ZodString>;
353
+ path: z.ZodString;
354
+ hash: z.ZodString;
355
+ snapshot: z.ZodOptional<z.ZodString>;
356
+ kind: z.ZodLiteral<"artifact-table">;
357
+ }, z.core.$strict>, z.ZodObject<{
358
+ unit: z.ZodOptional<z.ZodString>;
359
+ format: z.ZodOptional<z.ZodString>;
360
+ run: z.ZodOptional<z.ZodString>;
361
+ path: z.ZodString;
362
+ hash: z.ZodString;
363
+ snapshot: z.ZodOptional<z.ZodString>;
364
+ kind: z.ZodLiteral<"artifact-file">;
365
+ }, z.core.$strict>, z.ZodObject<{
366
+ unit: z.ZodOptional<z.ZodString>;
367
+ format: z.ZodOptional<z.ZodString>;
368
+ kind: z.ZodLiteral<"derivation">;
369
+ op: z.ZodEnum<{
370
+ ratio: "ratio";
371
+ delta: "delta";
372
+ pctChange: "pctChange";
373
+ }>;
374
+ inputs: z.ZodArray<z.ZodObject<{
375
+ unit: z.ZodOptional<z.ZodString>;
376
+ format: z.ZodOptional<z.ZodString>;
377
+ locator: z.ZodObject<{
378
+ column: z.ZodString;
379
+ rowFilter: z.ZodOptional<z.ZodObject<{
380
+ column: z.ZodString;
381
+ op: z.ZodLiteral<"eq">;
382
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
383
+ }, z.core.$strict>>;
384
+ row: z.ZodOptional<z.ZodNumber>;
385
+ }, z.core.$strict>;
386
+ assert: z.ZodOptional<z.ZodObject<{
387
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
388
+ tolerance: z.ZodOptional<z.ZodNumber>;
389
+ }, z.core.$strict>>;
390
+ run: z.ZodOptional<z.ZodString>;
391
+ path: z.ZodString;
392
+ hash: z.ZodString;
393
+ snapshot: z.ZodOptional<z.ZodString>;
394
+ kind: z.ZodLiteral<"artifact-value">;
395
+ }, z.core.$strict>>;
396
+ assert: z.ZodOptional<z.ZodObject<{
397
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
398
+ tolerance: z.ZodOptional<z.ZodNumber>;
399
+ }, z.core.$strict>>;
400
+ }, z.core.$strict>, z.ZodObject<{
401
+ unit: z.ZodOptional<z.ZodString>;
402
+ format: z.ZodOptional<z.ZodString>;
403
+ kind: z.ZodLiteral<"citation">;
404
+ idKind: z.ZodEnum<{
405
+ doi: "doi";
406
+ pmid: "pmid";
407
+ arxiv: "arxiv";
408
+ }>;
409
+ id: z.ZodString;
410
+ raw: z.ZodString;
411
+ assert: z.ZodOptional<z.ZodObject<{
412
+ value: z.ZodString;
413
+ }, z.core.$strict>>;
414
+ }, z.core.$strict>], "kind">;
415
+ reason: z.ZodEnum<{
416
+ "artifact-missing": "artifact-missing";
417
+ "hash-mismatch": "hash-mismatch";
418
+ "locator-out-of-range": "locator-out-of-range";
419
+ "ambiguous-match": "ambiguous-match";
420
+ "assertion-failed": "assertion-failed";
421
+ "unreadable-artifact": "unreadable-artifact";
422
+ }>;
423
+ detail: z.ZodOptional<z.ZodString>;
424
+ }, z.core.$strict>;
425
+ export type ArtifactValueReference = z.infer<typeof ArtifactValueReferenceSchema>;
426
+ export type ArtifactTableReference = z.infer<typeof ArtifactTableReferenceSchema>;
427
+ export type ArtifactFileReference = z.infer<typeof ArtifactFileReferenceSchema>;
428
+ export type CitationReference = z.infer<typeof CitationReferenceSchema>;
429
+ export type DerivationInputReference = z.infer<typeof DerivationInputReferenceSchema>;
430
+ export type DerivationReference = z.infer<typeof DerivationReferenceSchema>;
431
+ export type Reference = z.infer<typeof ReferenceSchema>;
432
+ export type ScalarReference = z.infer<typeof ScalarReferenceSchema>;
433
+ export type UnresolvedReason = z.infer<typeof UnresolvedReasonSchema>;
434
+ export type UnresolvedReference = z.infer<typeof UnresolvedReferenceSchema>;
435
+ /**
436
+ * Serialize a reference to a canonical URI.
437
+ *
438
+ * The payload is an opaque base64url of the canonical JSON, and not a structured URI with a field for
439
+ * each property. The reference object is the source of truth. A structured URI re-parses field by
440
+ * field, and it drifts from the object as the shape grows. An opaque payload cannot drift, because it
441
+ * round-trips the whole object.
442
+ */
443
+ export declare function serializeReference(reference: Reference): string;
444
+ /**
445
+ * The reason that a reference URI did not parse. Each of the four modes is distinct: a wrong prefix, a
446
+ * payload that is empty or holds a character outside the base64url alphabet, JSON that does not parse,
447
+ * and a value that the schema rejects. A caller reads the `kind` to tell them apart. `detail` carries no
448
+ * secret, thus a schema mismatch gives the kind alone.
449
+ */
450
+ export type ParseReferenceError = {
451
+ kind: "bad-prefix" | "invalid-payload" | "invalid-json" | "schema-mismatch";
452
+ detail?: string;
453
+ };
454
+ /**
455
+ * Parse a reference URI. Each failure mode gives its own `Err` `kind`, thus a caller tells a wrong
456
+ * prefix from malformed bytes, malformed JSON, and a schema mismatch. This function never throws, thus a
457
+ * caller treats a failed parse as a normal condition.
458
+ */
459
+ export declare function parseReference(uri: string): Result<Reference, ParseReferenceError>;