@inflexa-ai/harness 0.16.0 → 0.18.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.
- package/dist/agents/conversation-agent.d.ts +3 -0
- package/dist/agents/conversation-agent.js +5 -2
- package/dist/agents/report-builder.d.ts +2 -0
- package/dist/agents/report-builder.js +2 -0
- package/dist/agents/sandbox/shared.d.ts +3 -0
- package/dist/agents/sandbox/shared.js +5 -0
- package/dist/agents/sandbox/types.d.ts +1 -1
- package/dist/app/chat-turn.d.ts +2 -0
- package/dist/app/chat-turn.js +11 -2
- package/dist/app/spawn-report-session.d.ts +85 -0
- package/dist/app/spawn-report-session.js +83 -0
- package/dist/app/synthesize-run.d.ts +3 -0
- package/dist/app/synthesize-run.js +2 -1
- package/dist/citations/__fixtures__/resolver.d.ts +3 -0
- package/dist/citations/__fixtures__/resolver.js +9 -0
- package/dist/citations/aggregate.d.ts +3 -0
- package/dist/citations/aggregate.js +44 -0
- package/dist/citations/clients/arxiv.d.ts +6 -0
- package/dist/citations/clients/arxiv.js +34 -0
- package/dist/citations/clients/common.d.ts +11 -0
- package/dist/citations/clients/common.js +43 -0
- package/dist/citations/clients/crossref.d.ts +8 -0
- package/dist/citations/clients/crossref.js +98 -0
- package/dist/citations/clients/doi-registry.d.ts +3 -0
- package/dist/citations/clients/doi-registry.js +95 -0
- package/dist/citations/clients/pubmed.d.ts +6 -0
- package/dist/citations/clients/pubmed.js +83 -0
- package/dist/citations/clients/semantic-scholar.d.ts +6 -0
- package/dist/citations/clients/semantic-scholar.js +60 -0
- package/dist/citations/compare.d.ts +9 -0
- package/dist/citations/compare.js +72 -0
- package/dist/citations/match.d.ts +11 -0
- package/dist/citations/match.js +173 -0
- package/dist/citations/normalize.d.ts +31 -0
- package/dist/citations/normalize.js +187 -0
- package/dist/citations/plan.d.ts +2 -0
- package/dist/citations/plan.js +59 -0
- package/dist/citations/resolve.d.ts +28 -0
- package/dist/citations/resolve.js +238 -0
- package/dist/citations/types.d.ts +583 -0
- package/dist/citations/types.js +129 -0
- package/dist/contracts/chat-events.d.ts +9 -0
- package/dist/contracts/index.d.ts +6 -2
- package/dist/contracts/index.js +3 -1
- package/dist/contracts/organ-system.d.ts +49 -0
- package/dist/contracts/organ-system.js +67 -0
- package/dist/contracts/report-blocks.d.ts +564 -0
- package/dist/contracts/report-blocks.js +117 -0
- package/dist/contracts/report-reference.d.ts +459 -0
- package/dist/contracts/report-reference.js +256 -0
- package/dist/contracts/schemas/chat-events.d.ts +2 -0
- package/dist/contracts/schemas/chat-events.js +2 -0
- package/dist/contracts/schemas/chat-parts.d.ts +8 -8
- package/dist/contracts/severity.d.ts +15 -0
- package/dist/contracts/severity.js +10 -0
- package/dist/contracts/target-dossier.d.ts +8673 -12970
- package/dist/contracts/target-dossier.js +534 -591
- package/dist/data/safety-panel-schema.d.ts +18 -5
- package/dist/data/safety-panel-schema.js +4 -4
- package/dist/execution/artifact-metadata.js +1 -0
- package/dist/execution/report-runner.js +1 -3
- package/dist/execution/run-synthesis.d.ts +3 -0
- package/dist/execution/run-synthesis.js +3 -0
- package/dist/index.d.ts +12 -1
- package/dist/index.js +22 -0
- package/dist/lib/async-utils.d.ts +16 -4
- package/dist/lib/async-utils.js +20 -15
- package/dist/lib/cache.d.ts +8 -0
- package/dist/lib/cache.js +35 -0
- package/dist/lib/host-concurrency.js +1 -0
- package/dist/lib/rate-limit.d.ts +35 -0
- package/dist/lib/rate-limit.js +121 -0
- package/dist/literature/sources/arxiv.d.ts +22 -0
- package/dist/literature/sources/arxiv.js +103 -0
- package/dist/literature/sources/http.d.ts +28 -0
- package/dist/literature/sources/http.js +97 -0
- package/dist/literature/sources/pubmed.d.ts +68 -0
- package/dist/literature/sources/pubmed.js +266 -0
- package/dist/literature/sources/semantic-scholar.d.ts +24 -0
- package/dist/literature/sources/semantic-scholar.js +71 -0
- package/dist/loop/__fixtures__/scripted-provider.js +23 -2
- package/dist/loop/run-agent.js +58 -10
- package/dist/loop/tool-detail.d.ts +40 -0
- package/dist/loop/tool-detail.js +35 -3
- package/dist/loop/types.d.ts +13 -0
- package/dist/memory/thread-history.d.ts +10 -0
- package/dist/memory/thread-history.js +12 -1
- package/dist/memory/thread-store.d.ts +142 -25
- package/dist/memory/thread-store.js +228 -40
- package/dist/prompts/literature-reviewer.d.ts +1 -1
- package/dist/prompts/literature-reviewer.js +2 -0
- package/dist/prompts/target-assessment/briefs/executive-recommendation.d.ts +1 -1
- package/dist/prompts/target-assessment/briefs/executive-recommendation.js +5 -5
- package/dist/prompts/target-assessment/briefs/liability-bullets.d.ts +1 -1
- package/dist/prompts/target-assessment/briefs/liability-bullets.js +1 -1
- package/dist/prompts/target-assessment/briefs/target-organ-liabilities.d.ts +1 -1
- package/dist/prompts/target-assessment/briefs/target-organ-liabilities.js +11 -3
- package/dist/prompts/target-assessment/investigation/adversarial-critique.d.ts +1 -0
- package/dist/prompts/target-assessment/investigation/adversarial-critique.js +67 -0
- package/dist/prompts/target-assessment/investigation/claim-reverification.d.ts +1 -0
- package/dist/prompts/target-assessment/investigation/claim-reverification.js +49 -0
- package/dist/prompts/target-assessment/investigation/index.d.ts +3 -0
- package/dist/prompts/target-assessment/investigation/index.js +3 -0
- package/dist/prompts/target-assessment/investigation/mechanism-proposal.d.ts +1 -0
- package/dist/prompts/target-assessment/investigation/mechanism-proposal.js +49 -0
- package/dist/prompts/target-assessment/tox-voice/index.d.ts +1 -1
- package/dist/prompts/target-assessment/tox-voice/vocabulary.d.ts +8 -5
- package/dist/prompts/target-assessment/tox-voice/vocabulary.js +9 -20
- package/dist/providers/__fixtures__/session.d.ts +5 -4
- package/dist/providers/__fixtures__/session.js +4 -4
- package/dist/report-model/block-walk.d.ts +56 -0
- package/dist/report-model/block-walk.js +89 -0
- package/dist/report-model/draft-finish.d.ts +60 -0
- package/dist/report-model/draft-finish.js +56 -0
- package/dist/report-model/draft-operations.d.ts +125 -0
- package/dist/report-model/draft-operations.js +341 -0
- package/dist/report-model/draft-read.d.ts +59 -0
- package/dist/report-model/draft-read.js +109 -0
- package/dist/report-model/draft.d.ts +51 -0
- package/dist/report-model/draft.js +32 -0
- package/dist/report-model/fixture-resolver.d.ts +8 -0
- package/dist/report-model/fixture-resolver.js +252 -0
- package/dist/report-model/mint-snapshot.d.ts +30 -0
- package/dist/report-model/mint-snapshot.js +40 -0
- package/dist/report-model/reference-resolver.d.ts +113 -0
- package/dist/report-model/reference-resolver.js +60 -0
- package/dist/report-model/structural-validation.d.ts +22 -0
- package/dist/report-model/structural-validation.js +68 -0
- package/dist/report-model/validate.d.ts +40 -0
- package/dist/report-model/validate.js +80 -0
- package/dist/report-render/chart.d.ts +33 -0
- package/dist/report-render/chart.js +538 -0
- package/dist/report-render/page.d.ts +127 -0
- package/dist/report-render/page.js +307 -0
- package/dist/report-render/references.d.ts +32 -0
- package/dist/report-render/references.js +44 -0
- package/dist/report-render/render.d.ts +25 -0
- package/dist/report-render/render.js +125 -0
- package/dist/report-render/script-json.d.ts +13 -0
- package/dist/report-render/script-json.js +15 -0
- package/dist/report-render/types.d.ts +39 -0
- package/dist/report-render/types.js +10 -0
- package/dist/report-render/views/chart-view.d.ts +11 -0
- package/dist/report-render/views/chart-view.js +23 -0
- package/dist/report-render/views/page-view.d.ts +20 -0
- package/dist/report-render/views/page-view.js +49 -0
- package/dist/report-render/views/prose.d.ts +28 -0
- package/dist/report-render/views/prose.js +75 -0
- package/dist/report-render/views/references-view.d.ts +20 -0
- package/dist/report-render/views/references-view.js +64 -0
- package/dist/report-render/views/values.d.ts +42 -0
- package/dist/report-render/views/values.js +43 -0
- package/dist/runtime/assemble.d.ts +50 -4
- package/dist/runtime/assemble.js +47 -3
- package/dist/runtime/boot.d.ts +3 -3
- package/dist/runtime/boot.js +22 -5
- package/dist/runtime/dbos.d.ts +4 -4
- package/dist/state/artifacts.d.ts +16 -0
- package/dist/state/artifacts.js +18 -0
- package/dist/state/init.js +77 -1
- package/dist/state/purge-analysis.js +1 -0
- package/dist/state/report-versions.d.ts +132 -0
- package/dist/state/report-versions.js +194 -0
- package/dist/state/schema.d.ts +2 -2
- package/dist/tasks/data-profile.js +1 -0
- package/dist/tools/bio/chembl.js +1 -0
- package/dist/tools/bio/comptox.js +1 -0
- package/dist/tools/bio/drug-gene-interactions.js +1 -0
- package/dist/tools/bio/gene-disease-evidence.js +1 -0
- package/dist/tools/bio/gene-preclinical-profile.d.ts +1 -1
- package/dist/tools/bio/gene-preclinical-profile.js +1 -0
- package/dist/tools/bio/keys.d.ts +4 -2
- package/dist/tools/bio/keys.js +3 -2
- package/dist/tools/bio/lookup-annotation.js +1 -0
- package/dist/tools/bio/opentargets.d.ts +3 -3
- package/dist/tools/bio/opentargets.js +4 -3
- package/dist/tools/bio/pubchem.js +1 -0
- package/dist/tools/bio/pubmed.js +4 -4
- package/dist/tools/bio/search-clinical-trials.js +1 -0
- package/dist/tools/bio/search-faers.js +1 -0
- package/dist/tools/bio/search-geo-datasets.js +1 -0
- package/dist/tools/bio/search-interactions.js +1 -0
- package/dist/tools/bio/target-safety.d.ts +4 -6
- package/dist/tools/bio/target-safety.js +7 -6
- package/dist/tools/define-tool.d.ts +19 -12
- package/dist/tools/define-tool.js +4 -2
- package/dist/tools/display/show-user.js +1 -0
- package/dist/tools/iterate-report.js +2 -0
- package/dist/tools/lib/chembl-client.d.ts +2 -0
- package/dist/tools/lib/chembl-client.js +1 -0
- package/dist/tools/lib/monarch-client.d.ts +42 -0
- package/dist/tools/lib/monarch-client.js +100 -0
- package/dist/tools/lib/ncbi-utils.d.ts +3 -58
- package/dist/tools/lib/ncbi-utils.js +2 -286
- package/dist/tools/lib/pubmed-client.d.ts +5 -12
- package/dist/tools/lib/pubmed-client.js +20 -79
- package/dist/tools/report/build-report.js +1 -0
- package/dist/tools/report/mint-preview-url.js +1 -0
- package/dist/tools/report/preview-snapshot.js +1 -0
- package/dist/tools/report/submit-report.js +1 -0
- package/dist/tools/report/version-fs.js +4 -0
- package/dist/tools/report-authoring/authoring-tools.d.ts +134 -0
- package/dist/tools/report-authoring/authoring-tools.js +352 -0
- package/dist/tools/research/context7-docs.js +2 -0
- package/dist/tools/research/generate-analogy-report.js +3 -2
- package/dist/tools/research/generate-plan.js +3 -0
- package/dist/tools/research/index.d.ts +1 -0
- package/dist/tools/research/index.js +1 -0
- package/dist/tools/research/inspect-data-profile.js +4 -0
- package/dist/tools/research/inspect-run.d.ts +1 -1
- package/dist/tools/research/literature-reviewer.d.ts +3 -0
- package/dist/tools/research/literature-reviewer.js +3 -0
- package/dist/tools/research/resolve-citation.d.ts +3 -0
- package/dist/tools/research/resolve-citation.js +15 -0
- package/dist/tools/research/search-arxiv.d.ts +3 -19
- package/dist/tools/research/search-arxiv.js +10 -105
- package/dist/tools/research/search-github-repos.js +1 -0
- package/dist/tools/research/search-semantic-scholar.d.ts +8 -33
- package/dist/tools/research/search-semantic-scholar.js +30 -88
- package/dist/tools/sandbox/list-available-packages.js +23 -0
- package/dist/tools/sandbox/list-available-refs.js +37 -2
- package/dist/tools/sandbox/report-blocker.js +1 -0
- package/dist/tools/sandbox/skills.js +2 -0
- package/dist/tools/workspace/file-stat.js +1 -0
- package/dist/tools/workspace/show-file.js +2 -0
- package/dist/tools/workspace/show-plan.js +1 -0
- package/dist/workflows/execute-analysis.d.ts +8 -1
- package/dist/workflows/execute-analysis.js +6 -5
- package/dist/workflows/execute-target-assessment.d.ts +13 -2
- package/dist/workflows/execute-target-assessment.js +78 -16
- package/dist/workflows/sandbox-step.d.ts +5 -0
- package/dist/workflows/sandbox-step.js +1 -0
- package/dist/workflows/target-assessment/assemblers/index.d.ts +1 -1
- package/dist/workflows/target-assessment/assemblers/index.js +1 -1
- package/dist/workflows/target-assessment/assemblers/literature.d.ts +9 -27
- package/dist/workflows/target-assessment/assemblers/literature.js +32 -48
- package/dist/workflows/target-assessment/assemblers/orchestrator.d.ts +17 -9
- package/dist/workflows/target-assessment/assemblers/orchestrator.js +195 -85
- package/dist/workflows/target-assessment/assemblers/safety.d.ts +70 -48
- package/dist/workflows/target-assessment/assemblers/safety.js +125 -42
- package/dist/workflows/target-assessment/collectors/index.d.ts +5 -2
- package/dist/workflows/target-assessment/collectors/index.js +48 -5
- package/dist/workflows/target-assessment/coverage.d.ts +43 -27
- package/dist/workflows/target-assessment/coverage.js +33 -29
- package/dist/workflows/target-assessment/fanout/index.js +1 -0
- package/dist/workflows/target-assessment/investigation/index.d.ts +97 -0
- package/dist/workflows/target-assessment/investigation/index.js +419 -0
- package/dist/workflows/target-assessment/lib/approval-precedents.d.ts +26 -5
- package/dist/workflows/target-assessment/lib/approval-precedents.js +95 -29
- package/dist/workflows/target-assessment/lib/citation-validator.js +1 -1
- package/dist/workflows/target-assessment/lib/clinical-consequence-annotator.d.ts +2 -2
- package/dist/workflows/target-assessment/lib/clinical-evidence-attribution.d.ts +2 -3
- package/dist/workflows/target-assessment/lib/clinical-evidence-attribution.js +0 -4
- package/dist/workflows/target-assessment/lib/compute-derived.d.ts +6 -5
- package/dist/workflows/target-assessment/lib/compute-derived.js +14 -5
- package/dist/workflows/target-assessment/lib/family-complex-supplement.d.ts +5 -6
- package/dist/workflows/target-assessment/lib/family-complex-supplement.js +2 -3
- package/dist/workflows/target-assessment/lib/fda-label-safety.d.ts +72 -0
- package/dist/workflows/target-assessment/lib/fda-label-safety.js +166 -0
- package/dist/workflows/target-assessment/lib/heterodimer-filter.d.ts +0 -9
- package/dist/workflows/target-assessment/lib/heterodimer-filter.js +0 -10
- package/dist/workflows/target-assessment/lib/hpo-organ-map.d.ts +34 -0
- package/dist/workflows/target-assessment/lib/hpo-organ-map.js +63 -0
- package/dist/workflows/target-assessment/lib/impc-organ-map.d.ts +19 -0
- package/dist/workflows/target-assessment/lib/impc-organ-map.js +39 -0
- package/dist/workflows/target-assessment/lib/meddra-organ-map.d.ts +24 -14
- package/dist/workflows/target-assessment/lib/meddra-organ-map.js +59 -47
- package/dist/workflows/target-assessment/lib/recommendation-sanitizer.js +1 -1
- package/dist/workflows/target-assessment/lib/regulatory-actions.d.ts +2 -3
- package/dist/workflows/target-assessment/lib/regulatory-actions.js +33 -4
- package/dist/workflows/target-assessment/lib/safety-corroboration.d.ts +44 -0
- package/dist/workflows/target-assessment/lib/safety-corroboration.js +273 -0
- package/dist/workflows/target-assessment/lib/target-identity-filter.d.ts +5 -7
- package/dist/workflows/target-assessment/lib/target-identity-filter.js +5 -7
- package/dist/workflows/target-assessment/metrics.d.ts +1 -6
- package/dist/workflows/target-assessment/metrics.js +1 -13
- package/dist/workflows/target-assessment/phase4-assemble.d.ts +2149 -809
- package/dist/workflows/target-assessment/phase4-assemble.js +19 -19
- package/dist/workflows/target-assessment/phase5-persist.d.ts +20 -21
- package/dist/workflows/target-assessment/phase5-persist.js +56 -173
- package/dist/workflows/target-assessment/schemas.d.ts +48 -3
- package/dist/workflows/target-assessment/schemas.js +19 -0
- package/dist/workflows/target-assessment/steps/fanout/polypharm-for-one-modulator-step.d.ts +1 -0
- package/dist/workflows/target-assessment/steps/fanout/polypharm-for-one-modulator-step.js +2 -0
- package/dist/workflows/target-assessment/steps/phase2-aggregate.d.ts +27 -63
- package/dist/workflows/target-assessment/steps/phase2-aggregate.js +0 -4
- package/dist/workflows/target-assessment/steps/phase3-aggregate.d.ts +28 -155
- package/dist/workflows/target-assessment/steps/phase3-aggregate.js +0 -6
- package/dist/workflows/target-assessment/steps/synthesis/diagnostics.d.ts +0 -6
- package/dist/workflows/target-assessment/steps/synthesis/diagnostics.js +0 -18
- package/dist/workflows/target-assessment/sub-workflows/per-modulator-polypharm.d.ts +1 -0
- package/dist/workflows/target-assessment/synthesis/index.d.ts +52 -5
- package/dist/workflows/target-assessment/synthesis/index.js +4 -1
- package/dist/workflows/target-assessment/synthesis-probes.d.ts +3 -3
- package/package.json +4 -1
|
@@ -0,0 +1,256 @@
|
|
|
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 { err, ok } from "neverthrow";
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
/**
|
|
14
|
+
* The shape of a content hash, as lowercase `algorithm:hex`, for example `sha256:9f86d0...`. The
|
|
15
|
+
* resolver compares this text against a fresh read with exact string equality, and the producer emits
|
|
16
|
+
* lowercase only. Thus the pattern rejects an uppercase hex digit, which would pass a case-insensitive
|
|
17
|
+
* match here but never resolve against the lowercase producer.
|
|
18
|
+
*/
|
|
19
|
+
const HASH_PATTERN = /^[a-z0-9]+:[0-9a-f]+$/;
|
|
20
|
+
/**
|
|
21
|
+
* The pin that ties an artifact reference to one immutable file. It names the analysis-relative path and
|
|
22
|
+
* the content hash, and it can name the run that made the file. The optional `snapshot` names a
|
|
23
|
+
* point-in-time copy when a host keeps one.
|
|
24
|
+
*
|
|
25
|
+
* `path` is the key of `cortex_artifacts`, whose primary key is `(analysis_id, path)`. Thus the path
|
|
26
|
+
* spans the whole analysis and it already holds the run segment for a run output, for example
|
|
27
|
+
* `runs/{runId}/{stepId}/output/de.csv`.
|
|
28
|
+
*/
|
|
29
|
+
const artifactPinShape = {
|
|
30
|
+
run: z.string().min(1).optional().describe("The analysis run id that produced the artifact. It is absent for a staged input file, which no run produced."),
|
|
31
|
+
path: z.string().min(1).describe("The analysis-relative path of the artifact, the key of `cortex_artifacts.path`."),
|
|
32
|
+
hash: z.string().regex(HASH_PATTERN).describe("The content hash as `algorithm:hex`, for example `sha256:...`."),
|
|
33
|
+
snapshot: z.string().optional().describe("An optional point-in-time snapshot id."),
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* The authored belief about the one value that a reference resolves to. `tolerance` gives the permitted
|
|
37
|
+
* numeric difference.
|
|
38
|
+
*
|
|
39
|
+
* `value` is mandatory, thus an assert that asserts nothing is unrepresentable. A `tolerance` alone has
|
|
40
|
+
* nothing to compare against, and an empty assert reads as a belief that the resolver silently ignores.
|
|
41
|
+
*
|
|
42
|
+
* There is no hash field here. An artifact reference already pins `hash`, and resolution compares that
|
|
43
|
+
* pin against the fresh read and gives `hash-mismatch`. A second hash in the assert would compare the
|
|
44
|
+
* reference against itself, thus it adds no evidence.
|
|
45
|
+
*/
|
|
46
|
+
const AssertValueSchema = z.strictObject({
|
|
47
|
+
value: z.union([z.string(), z.number()]).describe("The value the author expects at resolution time."),
|
|
48
|
+
tolerance: z.number().optional().describe("The permitted absolute difference for a numeric match."),
|
|
49
|
+
});
|
|
50
|
+
/**
|
|
51
|
+
* The display hints that every reference kind can carry. `unit` and `format` tell a renderer how to show
|
|
52
|
+
* the resolved value.
|
|
53
|
+
*/
|
|
54
|
+
const displayShape = {
|
|
55
|
+
unit: z.string().optional().describe("The unit of the resolved value, for example `%` or `kb`."),
|
|
56
|
+
format: z.string().optional().describe("A display format hint for the resolved value."),
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* The address of exactly one value inside an artifact. `column` names the field. Exactly one of
|
|
60
|
+
* `rowFilter` or `row` selects the row. The refine makes the "exactly one" rule a parse failure, and
|
|
61
|
+
* not a separate check that runs later.
|
|
62
|
+
*/
|
|
63
|
+
const LocatorSchema = z
|
|
64
|
+
.strictObject({
|
|
65
|
+
column: z.string().describe("The column that holds the value."),
|
|
66
|
+
rowFilter: z
|
|
67
|
+
.strictObject({
|
|
68
|
+
column: z.string(),
|
|
69
|
+
op: z.literal("eq"),
|
|
70
|
+
value: z.union([z.string(), z.number()]),
|
|
71
|
+
})
|
|
72
|
+
.optional()
|
|
73
|
+
.describe("The documented default: the row where a column equals a value."),
|
|
74
|
+
row: z.number().int().nonnegative().optional().describe("A fixed row index. Use it only for an artifact with a stable row order."),
|
|
75
|
+
})
|
|
76
|
+
.refine((v) => (v.rowFilter !== undefined) !== (v.row !== undefined), {
|
|
77
|
+
message: "A locator needs exactly one of `rowFilter` or `row`.",
|
|
78
|
+
});
|
|
79
|
+
/**
|
|
80
|
+
* A reference to one scalar value inside an artifact, addressed by a locator. It resolves to a scalar,
|
|
81
|
+
* thus it carries the value assert.
|
|
82
|
+
*/
|
|
83
|
+
export const ArtifactValueReferenceSchema = z.strictObject({
|
|
84
|
+
kind: z.literal("artifact-value"),
|
|
85
|
+
...artifactPinShape,
|
|
86
|
+
locator: LocatorSchema.describe("The address of the one value that this reference binds."),
|
|
87
|
+
assert: AssertValueSchema.optional().describe("The authored belief that resolution matches against."),
|
|
88
|
+
...displayShape,
|
|
89
|
+
});
|
|
90
|
+
/**
|
|
91
|
+
* A reference to a whole table artifact. It carries no locator, because it binds every row.
|
|
92
|
+
*
|
|
93
|
+
* It carries no assert. A table is not one value, thus the only belief that an author can hold about it
|
|
94
|
+
* is its bytes, and the pinned `hash` already carries that belief.
|
|
95
|
+
*/
|
|
96
|
+
export const ArtifactTableReferenceSchema = z.strictObject({
|
|
97
|
+
kind: z.literal("artifact-table"),
|
|
98
|
+
...artifactPinShape,
|
|
99
|
+
columns: z.array(z.string()).optional().describe("An optional column subset to render. Omit to bind every column."),
|
|
100
|
+
...displayShape,
|
|
101
|
+
});
|
|
102
|
+
/**
|
|
103
|
+
* A reference to a whole artifact file, for example an image. It carries no locator and no columns,
|
|
104
|
+
* because a file is pinned whole and has no addressable cell inside it. It carries no assert, for the
|
|
105
|
+
* same reason as a table reference.
|
|
106
|
+
*/
|
|
107
|
+
export const ArtifactFileReferenceSchema = z.strictObject({
|
|
108
|
+
kind: z.literal("artifact-file"),
|
|
109
|
+
...artifactPinShape,
|
|
110
|
+
...displayShape,
|
|
111
|
+
});
|
|
112
|
+
/**
|
|
113
|
+
* A reference to an external source, addressed by an external identifier. It resolves to the prefixed
|
|
114
|
+
* key, thus its assert compares against that key and carries no hash.
|
|
115
|
+
*/
|
|
116
|
+
export const CitationReferenceSchema = z.strictObject({
|
|
117
|
+
kind: z.literal("citation"),
|
|
118
|
+
idKind: z.enum(["doi", "pmid", "arxiv"]).describe("The external identifier space."),
|
|
119
|
+
id: z.string().describe("The external identifier value."),
|
|
120
|
+
raw: z.string().describe("The original citation text."),
|
|
121
|
+
assert: z
|
|
122
|
+
.strictObject({
|
|
123
|
+
// The value is a string and not the wider scalar union of a value assert. Resolution gives the
|
|
124
|
+
// key as text, thus a number here can never match and the schema would admit a belief that
|
|
125
|
+
// always fails.
|
|
126
|
+
value: z.string().describe("The expected citation key in the prefixed `idKind:id` form, for example `pmid:12345`, and not the bare id."),
|
|
127
|
+
})
|
|
128
|
+
.optional()
|
|
129
|
+
.describe("The authored belief about the citation key that resolution gives."),
|
|
130
|
+
...displayShape,
|
|
131
|
+
});
|
|
132
|
+
/**
|
|
133
|
+
* The one reference kind that a derivation can consume.
|
|
134
|
+
*
|
|
135
|
+
* The arithmetic needs a scalar, and `artifact-value` is the only reference that resolves to one without
|
|
136
|
+
* itself being a derivation. A table, a file, and a citation resolve to something else, thus each is
|
|
137
|
+
* unrepresentable here rather than a parse that succeeds and then always fails at resolution. A
|
|
138
|
+
* derivation is out of the set too, thus a derivation over a derivation stays unrepresentable.
|
|
139
|
+
*/
|
|
140
|
+
export const DerivationInputReferenceSchema = ArtifactValueReferenceSchema;
|
|
141
|
+
/**
|
|
142
|
+
* A reference to a value computed from other references. Each of the three operations takes two inputs,
|
|
143
|
+
* thus `inputs` holds exactly two scalar-resolving references and no other count is representable. The
|
|
144
|
+
* result is computed and not artifact-backed, thus its assert carries the value fields only.
|
|
145
|
+
*/
|
|
146
|
+
export const DerivationReferenceSchema = z.strictObject({
|
|
147
|
+
kind: z.literal("derivation"),
|
|
148
|
+
op: z
|
|
149
|
+
.enum(["ratio", "delta", "pctChange"])
|
|
150
|
+
.describe("The operation over the two inputs `a` and `b`: `ratio` gives `a / b`, `delta` gives `a - b`, and `pctChange` gives `(a - b) / b` as a fraction and not as a percent. A change of one half resolves to 0.5, thus an `assert.value` states the fraction and a `unit` of `%` is a display hint only."),
|
|
151
|
+
inputs: z
|
|
152
|
+
.array(DerivationInputReferenceSchema)
|
|
153
|
+
.length(2)
|
|
154
|
+
.describe("The two input references. Each operation takes exactly two, and each one must resolve to a scalar."),
|
|
155
|
+
assert: AssertValueSchema.optional().describe("The authored belief that resolution matches against."),
|
|
156
|
+
...displayShape,
|
|
157
|
+
});
|
|
158
|
+
/** The full reference union. A block binds to one of these. */
|
|
159
|
+
export const ReferenceSchema = z.discriminatedUnion("kind", [
|
|
160
|
+
ArtifactValueReferenceSchema,
|
|
161
|
+
ArtifactTableReferenceSchema,
|
|
162
|
+
ArtifactFileReferenceSchema,
|
|
163
|
+
DerivationReferenceSchema,
|
|
164
|
+
CitationReferenceSchema,
|
|
165
|
+
]);
|
|
166
|
+
/**
|
|
167
|
+
* The references that resolve to one scalar value. A metric's value slot admits only these, thus no
|
|
168
|
+
* numeric literal can sit in the slot: the type admits a reference only.
|
|
169
|
+
*/
|
|
170
|
+
export const ScalarReferenceSchema = z.discriminatedUnion("kind", [ArtifactValueReferenceSchema, DerivationReferenceSchema]);
|
|
171
|
+
/**
|
|
172
|
+
* The reason that a reference did not resolve.
|
|
173
|
+
*
|
|
174
|
+
* Two of the reasons are easy to confuse. `artifact-missing` means that the snapshot holds no entry for
|
|
175
|
+
* the path. `unreadable-artifact` means that the entry exists, and that the resolver cannot read the
|
|
176
|
+
* artifact as a table. Two conditions give the second reason. The file type refuses a read of a cell, or
|
|
177
|
+
* the bytes are unrecoverable.
|
|
178
|
+
*/
|
|
179
|
+
export const UnresolvedReasonSchema = z.enum([
|
|
180
|
+
"artifact-missing",
|
|
181
|
+
"hash-mismatch",
|
|
182
|
+
"locator-out-of-range",
|
|
183
|
+
"ambiguous-match",
|
|
184
|
+
"assertion-failed",
|
|
185
|
+
"unreadable-artifact",
|
|
186
|
+
]);
|
|
187
|
+
/** A reference that resolution could not bind, with the reason and an optional detail. */
|
|
188
|
+
export const UnresolvedReferenceSchema = z.strictObject({
|
|
189
|
+
reference: ReferenceSchema,
|
|
190
|
+
reason: UnresolvedReasonSchema,
|
|
191
|
+
detail: z.string().optional(),
|
|
192
|
+
});
|
|
193
|
+
/** The URI scheme and version for a serialized reference. The payload after it is opaque. */
|
|
194
|
+
const REFERENCE_URI_PREFIX = "inflexa-ref:v1:";
|
|
195
|
+
/**
|
|
196
|
+
* The alphabet of a non-empty base64url payload. The check is explicit because `Buffer.from(text,
|
|
197
|
+
* "base64url")` never throws: it drops each character outside the alphabet and decodes what is left.
|
|
198
|
+
* Thus a corrupt payload would otherwise decode to mojibake and report as malformed JSON, which names
|
|
199
|
+
* the wrong failure.
|
|
200
|
+
*/
|
|
201
|
+
const BASE64URL_PATTERN = /^[A-Za-z0-9_-]+$/;
|
|
202
|
+
/**
|
|
203
|
+
* Sort the keys of every object so that serialization is deterministic. An array keeps its order,
|
|
204
|
+
* because the order of a derivation's inputs carries meaning.
|
|
205
|
+
*/
|
|
206
|
+
function sortKeysDeep(value) {
|
|
207
|
+
if (Array.isArray(value)) {
|
|
208
|
+
return value.map(sortKeysDeep);
|
|
209
|
+
}
|
|
210
|
+
if (value !== null && typeof value === "object") {
|
|
211
|
+
const sorted = {};
|
|
212
|
+
for (const key of Object.keys(value).sort()) {
|
|
213
|
+
sorted[key] = sortKeysDeep(value[key]);
|
|
214
|
+
}
|
|
215
|
+
return sorted;
|
|
216
|
+
}
|
|
217
|
+
return value;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Serialize a reference to a canonical URI.
|
|
221
|
+
*
|
|
222
|
+
* The payload is an opaque base64url of the canonical JSON, and not a structured URI with a field for
|
|
223
|
+
* each property. The reference object is the source of truth. A structured URI re-parses field by
|
|
224
|
+
* field, and it drifts from the object as the shape grows. An opaque payload cannot drift, because it
|
|
225
|
+
* round-trips the whole object.
|
|
226
|
+
*/
|
|
227
|
+
export function serializeReference(reference) {
|
|
228
|
+
const json = JSON.stringify(sortKeysDeep(reference));
|
|
229
|
+
const payload = Buffer.from(json, "utf8").toString("base64url");
|
|
230
|
+
return REFERENCE_URI_PREFIX + payload;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Parse a reference URI. Each failure mode gives its own `Err` `kind`, thus a caller tells a wrong
|
|
234
|
+
* prefix from malformed bytes, malformed JSON, and a schema mismatch. This function never throws, thus a
|
|
235
|
+
* caller treats a failed parse as a normal condition.
|
|
236
|
+
*/
|
|
237
|
+
export function parseReference(uri) {
|
|
238
|
+
if (!uri.startsWith(REFERENCE_URI_PREFIX)) {
|
|
239
|
+
return err({ kind: "bad-prefix" });
|
|
240
|
+
}
|
|
241
|
+
const payload = uri.slice(REFERENCE_URI_PREFIX.length);
|
|
242
|
+
if (!BASE64URL_PATTERN.test(payload)) {
|
|
243
|
+
return err({ kind: "invalid-payload" });
|
|
244
|
+
}
|
|
245
|
+
const json = Buffer.from(payload, "base64url").toString("utf8");
|
|
246
|
+
let candidate;
|
|
247
|
+
try {
|
|
248
|
+
candidate = JSON.parse(json);
|
|
249
|
+
}
|
|
250
|
+
catch {
|
|
251
|
+
// `JSON.parse` throws on malformed input. The boundary turns the throw into an `Err`.
|
|
252
|
+
return err({ kind: "invalid-json" });
|
|
253
|
+
}
|
|
254
|
+
const result = ReferenceSchema.safeParse(candidate);
|
|
255
|
+
return result.success ? ok(result.data) : err({ kind: "schema-mismatch" });
|
|
256
|
+
}
|
|
@@ -47,6 +47,7 @@ export declare const ToolFinishedEventSchema: z.ZodObject<{
|
|
|
47
47
|
denied: "denied";
|
|
48
48
|
}>;
|
|
49
49
|
detail: z.ZodOptional<z.ZodString>;
|
|
50
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
50
51
|
source: z.ZodObject<{
|
|
51
52
|
agentId: z.ZodString;
|
|
52
53
|
callPath: z.ZodArray<z.ZodString>;
|
|
@@ -108,6 +109,7 @@ export declare const CortexChatEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject
|
|
|
108
109
|
denied: "denied";
|
|
109
110
|
}>;
|
|
110
111
|
detail: z.ZodOptional<z.ZodString>;
|
|
112
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
111
113
|
source: z.ZodObject<{
|
|
112
114
|
agentId: z.ZodString;
|
|
113
115
|
callPath: z.ZodArray<z.ZodString>;
|
|
@@ -29,6 +29,8 @@ export const ToolFinishedEventSchema = z.object({
|
|
|
29
29
|
name: z.string(),
|
|
30
30
|
outcome: ToolOutcomeSchema,
|
|
31
31
|
detail: z.string().optional(),
|
|
32
|
+
/** Optional and absent when unmeasured — never a zero in place of a figure. */
|
|
33
|
+
durationMs: z.number().optional(),
|
|
32
34
|
source: EventSourceSchema,
|
|
33
35
|
});
|
|
34
36
|
export const FinishEventSchema = z.object({
|
|
@@ -182,6 +182,7 @@ export declare const DagStatePartSchema: z.ZodObject<{
|
|
|
182
182
|
}, z.core.$strict>>;
|
|
183
183
|
}, z.core.$strict>;
|
|
184
184
|
export declare const StepPhaseSchema: z.ZodEnum<{
|
|
185
|
+
complete: "complete";
|
|
185
186
|
failed: "failed";
|
|
186
187
|
warning: "warning";
|
|
187
188
|
"sandbox-init": "sandbox-init";
|
|
@@ -190,7 +191,6 @@ export declare const StepPhaseSchema: z.ZodEnum<{
|
|
|
190
191
|
"generating-summary": "generating-summary";
|
|
191
192
|
indexing: "indexing";
|
|
192
193
|
persisting: "persisting";
|
|
193
|
-
complete: "complete";
|
|
194
194
|
retrying: "retrying";
|
|
195
195
|
}>;
|
|
196
196
|
export declare const StepActivityPartSchema: z.ZodObject<{
|
|
@@ -199,6 +199,7 @@ export declare const StepActivityPartSchema: z.ZodObject<{
|
|
|
199
199
|
runId: z.ZodString;
|
|
200
200
|
stepId: z.ZodString;
|
|
201
201
|
phase: z.ZodEnum<{
|
|
202
|
+
complete: "complete";
|
|
202
203
|
failed: "failed";
|
|
203
204
|
warning: "warning";
|
|
204
205
|
"sandbox-init": "sandbox-init";
|
|
@@ -207,7 +208,6 @@ export declare const StepActivityPartSchema: z.ZodObject<{
|
|
|
207
208
|
"generating-summary": "generating-summary";
|
|
208
209
|
indexing: "indexing";
|
|
209
210
|
persisting: "persisting";
|
|
210
|
-
complete: "complete";
|
|
211
211
|
retrying: "retrying";
|
|
212
212
|
}>;
|
|
213
213
|
activity: z.ZodString;
|
|
@@ -314,8 +314,8 @@ export declare const RunCompletedPartSchema: z.ZodObject<{
|
|
|
314
314
|
type: z.ZodLiteral<"data-run-completed">;
|
|
315
315
|
runId: z.ZodString;
|
|
316
316
|
status: z.ZodEnum<{
|
|
317
|
-
completed: "completed";
|
|
318
317
|
partial: "partial";
|
|
318
|
+
completed: "completed";
|
|
319
319
|
}>;
|
|
320
320
|
completedSteps: z.ZodNumber;
|
|
321
321
|
totalSteps: z.ZodNumber;
|
|
@@ -403,11 +403,11 @@ export declare const RunSynthesisPartSchema: z.ZodObject<{
|
|
|
403
403
|
}, z.core.$strip>>;
|
|
404
404
|
}, z.core.$strip>;
|
|
405
405
|
export declare const SynthesisPhaseSchema: z.ZodEnum<{
|
|
406
|
+
complete: "complete";
|
|
406
407
|
failed: "failed";
|
|
407
408
|
skipped: "skipped";
|
|
408
409
|
indexing: "indexing";
|
|
409
410
|
persisting: "persisting";
|
|
410
|
-
complete: "complete";
|
|
411
411
|
starting: "starting";
|
|
412
412
|
researching: "researching";
|
|
413
413
|
drafting: "drafting";
|
|
@@ -419,11 +419,11 @@ export declare const SynthesisProgressPartSchema: z.ZodObject<{
|
|
|
419
419
|
id: z.ZodString;
|
|
420
420
|
runId: z.ZodString;
|
|
421
421
|
phase: z.ZodEnum<{
|
|
422
|
+
complete: "complete";
|
|
422
423
|
failed: "failed";
|
|
423
424
|
skipped: "skipped";
|
|
424
425
|
indexing: "indexing";
|
|
425
426
|
persisting: "persisting";
|
|
426
|
-
complete: "complete";
|
|
427
427
|
starting: "starting";
|
|
428
428
|
researching: "researching";
|
|
429
429
|
drafting: "drafting";
|
|
@@ -574,6 +574,7 @@ export declare const CortexChatPartSchema: z.ZodDiscriminatedUnion<[z.ZodObject<
|
|
|
574
574
|
runId: z.ZodString;
|
|
575
575
|
stepId: z.ZodString;
|
|
576
576
|
phase: z.ZodEnum<{
|
|
577
|
+
complete: "complete";
|
|
577
578
|
failed: "failed";
|
|
578
579
|
warning: "warning";
|
|
579
580
|
"sandbox-init": "sandbox-init";
|
|
@@ -582,7 +583,6 @@ export declare const CortexChatPartSchema: z.ZodDiscriminatedUnion<[z.ZodObject<
|
|
|
582
583
|
"generating-summary": "generating-summary";
|
|
583
584
|
indexing: "indexing";
|
|
584
585
|
persisting: "persisting";
|
|
585
|
-
complete: "complete";
|
|
586
586
|
retrying: "retrying";
|
|
587
587
|
}>;
|
|
588
588
|
activity: z.ZodString;
|
|
@@ -693,11 +693,11 @@ export declare const CortexChatPartSchema: z.ZodDiscriminatedUnion<[z.ZodObject<
|
|
|
693
693
|
id: z.ZodString;
|
|
694
694
|
runId: z.ZodString;
|
|
695
695
|
phase: z.ZodEnum<{
|
|
696
|
+
complete: "complete";
|
|
696
697
|
failed: "failed";
|
|
697
698
|
skipped: "skipped";
|
|
698
699
|
indexing: "indexing";
|
|
699
700
|
persisting: "persisting";
|
|
700
|
-
complete: "complete";
|
|
701
701
|
starting: "starting";
|
|
702
702
|
researching: "researching";
|
|
703
703
|
drafting: "drafting";
|
|
@@ -712,8 +712,8 @@ export declare const CortexChatPartSchema: z.ZodDiscriminatedUnion<[z.ZodObject<
|
|
|
712
712
|
type: z.ZodLiteral<"data-run-completed">;
|
|
713
713
|
runId: z.ZodString;
|
|
714
714
|
status: z.ZodEnum<{
|
|
715
|
-
completed: "completed";
|
|
716
715
|
partial: "partial";
|
|
716
|
+
completed: "completed";
|
|
717
717
|
}>;
|
|
718
718
|
completedSteps: z.ZodNumber;
|
|
719
719
|
totalSteps: z.ZodNumber;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The severity scale shared by the curated safety panel and the dossier's
|
|
3
|
+
* own liability rows.
|
|
4
|
+
*
|
|
5
|
+
* One scale, so a panel-derived severity and a dossier-asserted one mean the
|
|
6
|
+
* same thing and can be compared without a translation table.
|
|
7
|
+
*/
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
export declare const SEVERITIES: readonly ["high", "medium", "low"];
|
|
10
|
+
export declare const SeveritySchema: z.ZodEnum<{
|
|
11
|
+
high: "high";
|
|
12
|
+
medium: "medium";
|
|
13
|
+
low: "low";
|
|
14
|
+
}>;
|
|
15
|
+
export type Severity = (typeof SEVERITIES)[number];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The severity scale shared by the curated safety panel and the dossier's
|
|
3
|
+
* own liability rows.
|
|
4
|
+
*
|
|
5
|
+
* One scale, so a panel-derived severity and a dossier-asserted one mean the
|
|
6
|
+
* same thing and can be compared without a translation table.
|
|
7
|
+
*/
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
export const SEVERITIES = ["high", "medium", "low"];
|
|
10
|
+
export const SeveritySchema = z.enum(SEVERITIES);
|