@action-state-group/capsule-viewer 0.3.0 → 0.5.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/README.md +3 -2
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +5 -3
- package/dist/browser.js.map +1 -1
- package/dist/chart-dataset.d.ts +23 -0
- package/dist/chart-dataset.js +195 -0
- package/dist/chart-dataset.js.map +1 -0
- package/dist/chart-spec.d.ts +141 -0
- package/dist/chart-spec.js +646 -0
- package/dist/chart-spec.js.map +1 -0
- package/dist/chart-view.d.ts +34 -0
- package/dist/chart-view.js +389 -0
- package/dist/chart-view.js.map +1 -0
- package/dist/compliance-styles.js +0 -1
- package/dist/compliance-styles.js.map +1 -1
- package/dist/compliance-view.js +53 -17
- package/dist/compliance-view.js.map +1 -1
- package/dist/contract-report-wording.js +51 -2
- package/dist/contract-report-wording.js.map +1 -1
- package/dist/core-strip.d.ts +38 -0
- package/dist/core-strip.js +183 -0
- package/dist/core-strip.js.map +1 -0
- package/dist/emitter-shell.html +10 -1
- package/dist/emitter.js +13 -3
- package/dist/emitter.js.map +1 -1
- package/dist/evidence-graph-view.d.ts +6 -0
- package/dist/evidence-graph-view.js +244 -91
- package/dist/evidence-graph-view.js.map +1 -1
- package/dist/evidence-graph.iife.js +6351 -1633
- package/dist/outcome-report-view.js +49 -25
- package/dist/outcome-report-view.js.map +1 -1
- package/dist/presentation-builder.d.ts +15 -0
- package/dist/presentation-builder.js +36 -2
- package/dist/presentation-builder.js.map +1 -1
- package/dist/presentation-mount.d.ts +2 -0
- package/dist/presentation-mount.js +1 -0
- package/dist/presentation-mount.js.map +1 -1
- package/dist/report-front-styles.d.ts +2 -2
- package/dist/report-front-styles.js +3 -15
- package/dist/report-front-styles.js.map +1 -1
- package/dist/report-front.d.ts +2 -24
- package/dist/report-front.js +11 -145
- package/dist/report-front.js.map +1 -1
- package/dist/report-levels.d.ts +33 -1
- package/dist/report-levels.js +135 -0
- package/dist/report-levels.js.map +1 -1
- package/dist/report-provenance.d.ts +28 -0
- package/dist/report-provenance.js +60 -11
- package/dist/report-provenance.js.map +1 -1
- package/dist/report-view-render.d.ts +13 -0
- package/dist/report-view-render.js +280 -0
- package/dist/report-view-render.js.map +1 -0
- package/dist/report-view.d.ts +29 -0
- package/dist/report-view.js +170 -0
- package/dist/report-view.js.map +1 -0
- package/dist/viewer-build.js +3 -3
- package/dist/viewer-build.js.map +1 -1
- package/dist/wording/contract-report-eu-ai-act.en.json +36 -0
- package/dist/wording/contract-report-outcomes.en.json +36 -0
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -19,8 +19,9 @@ The in-browser renderer (`renderEvidenceGraph`) ships bundled as
|
|
|
19
19
|
module ships the same build as `go/pageruntime`. Bundle verification comes from
|
|
20
20
|
`@action-state-group/agent-action-capsule`. Besides `registerPresentation`,
|
|
21
21
|
the runtime's global `EvidenceGraph` carries the verifier functions a
|
|
22
|
-
presentation module may call: `
|
|
23
|
-
`verifiedPayload`, `verifyDisclosureEnvelope` and
|
|
22
|
+
presentation module may call: `buildResultRoot`, `disclosureOf`,
|
|
23
|
+
`ed25519Available`, `verifiedPayload`, `verifyDisclosureEnvelope` and
|
|
24
|
+
`verifyProducerEnvelope`.
|
|
24
25
|
|
|
25
26
|
The code moved here from agent-action-capsule (agent-action-capsule#281) and
|
|
26
27
|
keeps its BSD-3-Clause license (`LICENSE-BSD-3-Clause`); the rest of the
|
package/dist/browser.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ export * from "./contract-report-wording.js";
|
|
|
4
4
|
export { conversationStatus } from "./outcome-report-view.js";
|
|
5
5
|
export { obligationStatus, rowStatus } from "./compliance-view.js";
|
|
6
6
|
export * from "./presentation-mount.js";
|
|
7
|
-
export { buildResultRoot, disclosureOf, ed25519Available, verifiedPayload, verifyDisclosureEnvelope, verifyProducerEnvelope, } from "@action-state-group/agent-action-capsule";
|
|
7
|
+
export { buildResultRoot, buildVerifiedBundleContext, disclosureOf, ed25519Available, verifiedPayload, verifyDisclosureEnvelope, verifyProducerEnvelope, } from "@action-state-group/agent-action-capsule";
|
package/dist/browser.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// The in-browser renderer the emitted page runs. It is published only as
|
|
3
3
|
// dist/evidence-graph.iife.js (`npm run emitter:iife`), which exposes
|
|
4
4
|
// renderEvidenceGraph, and not as a package export. It bundles
|
|
5
|
-
// @action-state-group/agent-action-capsule (0.
|
|
5
|
+
// @action-state-group/agent-action-capsule (0.9.0 or later) through that
|
|
6
6
|
// package's own browser entry, by plain package resolution. The Go module
|
|
7
7
|
// ships the build as go/pageruntime.
|
|
8
8
|
export * from "./evidence-graph-view.js";
|
|
@@ -17,9 +17,11 @@ export * from "./presentation-mount.js";
|
|
|
17
17
|
// the same verifier the page does (ed25519Available is its check that the
|
|
18
18
|
// browser can verify Ed25519 signatures; buildResultRoot is its Result
|
|
19
19
|
// reader, which the Show-evidence component, static/show_evidence.js, draws
|
|
20
|
-
// from
|
|
20
|
+
// from; buildVerifiedBundleContext verifies a bundle a module carries inside
|
|
21
|
+
// the one the page verified, such as each member of a composed/v1 bundle,
|
|
22
|
+
// capsule-viewer#167). This list is the runtime's contract
|
|
21
23
|
// with presentation modules: a name is added here only from
|
|
22
24
|
// agent-action-capsule's verifier, and removing one breaks the modules that
|
|
23
25
|
// call it.
|
|
24
|
-
export { buildResultRoot, disclosureOf, ed25519Available, verifiedPayload, verifyDisclosureEnvelope, verifyProducerEnvelope, } from "@action-state-group/agent-action-capsule";
|
|
26
|
+
export { buildResultRoot, buildVerifiedBundleContext, disclosureOf, ed25519Available, verifiedPayload, verifyDisclosureEnvelope, verifyProducerEnvelope, } from "@action-state-group/agent-action-capsule";
|
|
25
27
|
//# sourceMappingURL=browser.js.map
|
package/dist/browser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,yEAAyE;AACzE,sEAAsE;AACtE,+DAA+D;AAC/D,yEAAyE;AACzE,0EAA0E;AAC1E,qCAAqC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACnE,cAAc,yBAAyB,CAAC;AAExC,yEAAyE;AACzE,8EAA8E;AAC9E,8EAA8E;AAC9E,0EAA0E;AAC1E,uEAAuE;AACvE,4EAA4E;AAC5E,
|
|
1
|
+
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,yEAAyE;AACzE,sEAAsE;AACtE,+DAA+D;AAC/D,yEAAyE;AACzE,0EAA0E;AAC1E,qCAAqC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACnE,cAAc,yBAAyB,CAAC;AAExC,yEAAyE;AACzE,8EAA8E;AAC9E,8EAA8E;AAC9E,0EAA0E;AAC1E,uEAAuE;AACvE,4EAA4E;AAC5E,6EAA6E;AAC7E,0EAA0E;AAC1E,2DAA2D;AAC3D,4DAA4D;AAC5D,4EAA4E;AAC5E,WAAW;AACX,OAAO,EACL,eAAe,EACf,0BAA0B,EAC1B,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,0CAA0C,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type ResultRoot, type VerifiedBundleContext } from "@action-state-group/agent-action-capsule";
|
|
2
|
+
import { ChartRefusal, type ChartDataset } from "./chart-spec.js";
|
|
3
|
+
/** evidencebook's member through which a caller-sealed capsule carries its own header. */
|
|
4
|
+
export declare const RECORD_HEADER_MEMBER = "evidence_record_header";
|
|
5
|
+
/**
|
|
6
|
+
* The dataset a report's Result names, as the chart checker reads it; or
|
|
7
|
+
* undefined when the Result names none or the bundle does not disclose its
|
|
8
|
+
* plan or dataset (the checker refuses a chart then, `chart-no-dataset`).
|
|
9
|
+
* Throws a {@link ChartRefusal} (`chart-dataset-invalid`) for a plan or
|
|
10
|
+
* dataset that does not match its digests or shape.
|
|
11
|
+
*/
|
|
12
|
+
export declare function chartDatasetOf(context: VerifiedBundleContext, result: ResultRoot): Promise<ChartDataset | undefined>;
|
|
13
|
+
/** One chart's build-time verdict: drawn, or refused with its reason. */
|
|
14
|
+
export interface ChartBuildCheck {
|
|
15
|
+
readonly index: number;
|
|
16
|
+
readonly refusal?: ChartRefusal;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Check every chart spec against a verified bundle, as the builder does
|
|
20
|
+
* before it writes any packaging. A bundle that did not verify, or whose
|
|
21
|
+
* root is not an Evidence Result, has no dataset to check against.
|
|
22
|
+
*/
|
|
23
|
+
export declare function checkChartsAgainst(context: VerifiedBundleContext, charts: readonly unknown[]): Promise<ChartBuildCheck[]>;
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// SPDX-License-Identifier: BSD-3-Clause
|
|
2
|
+
import { buildResultRoot, bundleVerified, committedDigest, disclosureOf, isResultRoot, JcsFloatError, JcsUnsafeIntegerError, jsonDigest, } from "@action-state-group/agent-action-capsule";
|
|
3
|
+
import { ChartRefusal, checkChart, } from "./chart-spec.js";
|
|
4
|
+
import { checkView, isView } from "./report-view.js";
|
|
5
|
+
const isObj = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
6
|
+
/** evidencebook's member through which a caller-sealed capsule carries its own header. */
|
|
7
|
+
export const RECORD_HEADER_MEMBER = "evidence_record_header";
|
|
8
|
+
const DATASET_VERSION = "evidence-dataset-v0";
|
|
9
|
+
const HEX64 = /^[0-9a-f]{64}$/u;
|
|
10
|
+
const invalid = (message) => {
|
|
11
|
+
throw new ChartRefusal("chart-dataset-invalid", message);
|
|
12
|
+
};
|
|
13
|
+
/** `{digest_alg: "SHA-256", digest}`, or undefined when the member is absent. */
|
|
14
|
+
function digestRef(value, what) {
|
|
15
|
+
if (value === undefined)
|
|
16
|
+
return undefined;
|
|
17
|
+
if (!isObj(value) ||
|
|
18
|
+
value.digest_alg !== "SHA-256" ||
|
|
19
|
+
typeof value.digest !== "string" ||
|
|
20
|
+
!HEX64.test(value.digest))
|
|
21
|
+
return invalid(`${what} is not {digest_alg: "SHA-256", digest: <64-hex>}`);
|
|
22
|
+
return value.digest;
|
|
23
|
+
}
|
|
24
|
+
/** The Result document the root carries: the member itself, or a book header's statement. */
|
|
25
|
+
function resultDocument(context, result) {
|
|
26
|
+
const member = disclosureOf(context, result.capsuleId, result.member);
|
|
27
|
+
if (member.state !== "disclosed" || !isObj(member.payload))
|
|
28
|
+
return undefined;
|
|
29
|
+
const document = result.form === "book" ? member.payload.statement : member.payload;
|
|
30
|
+
return isObj(document) ? document : undefined;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The JCS SHA-256 of a value, or undefined for one with no canonical form
|
|
34
|
+
* (a fraction or an unsafe integer, which this JCS refuses): no plan, dataset or row can name it.
|
|
35
|
+
*/
|
|
36
|
+
async function digestOf(value) {
|
|
37
|
+
try {
|
|
38
|
+
return await jsonDigest(value);
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
if (err instanceof JcsFloatError || err instanceof JcsUnsafeIntegerError)
|
|
42
|
+
return undefined;
|
|
43
|
+
throw err;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** Every disclosed document that could be a plan or a dataset, by the digest of its JCS. */
|
|
47
|
+
async function documentsByDigest(context) {
|
|
48
|
+
const found = new Map();
|
|
49
|
+
const consider = async (value) => {
|
|
50
|
+
// Only a document that names itself a dataset or a plan is hashed.
|
|
51
|
+
if (!isObj(value) ||
|
|
52
|
+
(value.dataset_version === undefined &&
|
|
53
|
+
!(isObj(value.header) && value.header.ir_version !== undefined)))
|
|
54
|
+
return;
|
|
55
|
+
const digest = await digestOf(value);
|
|
56
|
+
if (digest !== undefined)
|
|
57
|
+
found.set(digest, value);
|
|
58
|
+
};
|
|
59
|
+
for (const record of context.records) {
|
|
60
|
+
for (const member of ["agent_input", "agent_output"]) {
|
|
61
|
+
const disclosed = disclosureOf(context, record.capsule_id, member);
|
|
62
|
+
if (disclosed.state !== "disclosed")
|
|
63
|
+
continue;
|
|
64
|
+
await consider(disclosed.payload);
|
|
65
|
+
if (isObj(disclosed.payload))
|
|
66
|
+
await consider(disclosed.payload.statement);
|
|
67
|
+
}
|
|
68
|
+
const inline = record[RECORD_HEADER_MEMBER];
|
|
69
|
+
if (isObj(inline))
|
|
70
|
+
await consider(inline.statement);
|
|
71
|
+
}
|
|
72
|
+
return found;
|
|
73
|
+
}
|
|
74
|
+
/** Every disclosed record header, by the digest a dataset row names it with. */
|
|
75
|
+
async function headersByDigest(context) {
|
|
76
|
+
const found = new Map();
|
|
77
|
+
for (const record of context.records) {
|
|
78
|
+
const inline = record[RECORD_HEADER_MEMBER];
|
|
79
|
+
if (isObj(inline)) {
|
|
80
|
+
const digest = await digestOf(inline);
|
|
81
|
+
if (digest !== undefined)
|
|
82
|
+
found.set(digest, { header: inline, recordId: record.capsule_id });
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
const digest = committedDigest(record, "agent_input");
|
|
86
|
+
const disclosed = disclosureOf(context, record.capsule_id, "agent_input");
|
|
87
|
+
if (digest !== undefined &&
|
|
88
|
+
disclosed.state === "disclosed" &&
|
|
89
|
+
isObj(disclosed.payload))
|
|
90
|
+
found.set(digest, {
|
|
91
|
+
header: disclosed.payload,
|
|
92
|
+
recordId: record.capsule_id,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return found;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The dataset a report's Result names, as the chart checker reads it; or
|
|
99
|
+
* undefined when the Result names none or the bundle does not disclose its
|
|
100
|
+
* plan or dataset (the checker refuses a chart then, `chart-no-dataset`).
|
|
101
|
+
* Throws a {@link ChartRefusal} (`chart-dataset-invalid`) for a plan or
|
|
102
|
+
* dataset that does not match its digests or shape.
|
|
103
|
+
*/
|
|
104
|
+
export async function chartDatasetOf(context, result) {
|
|
105
|
+
const document = resultDocument(context, result);
|
|
106
|
+
if (document === undefined)
|
|
107
|
+
return undefined;
|
|
108
|
+
const planRef = digestRef(document.plan_ref, "the Result's plan_ref");
|
|
109
|
+
const datasetRef = digestRef(document.dataset_ref, "the Result's dataset_ref");
|
|
110
|
+
if (planRef === undefined || datasetRef === undefined)
|
|
111
|
+
return undefined;
|
|
112
|
+
const documents = await documentsByDigest(context);
|
|
113
|
+
const plan = documents.get(planRef);
|
|
114
|
+
const dataset = documents.get(datasetRef);
|
|
115
|
+
if (plan === undefined || dataset === undefined)
|
|
116
|
+
return undefined;
|
|
117
|
+
const keys = Object.keys(dataset).sort().join(",");
|
|
118
|
+
if (keys !== "dataset_version,plan_ref,rows" ||
|
|
119
|
+
dataset.dataset_version !== DATASET_VERSION ||
|
|
120
|
+
!Array.isArray(dataset.rows))
|
|
121
|
+
invalid(`the dataset is not an ${DATASET_VERSION} document`);
|
|
122
|
+
if (digestRef(dataset.plan_ref, "the dataset's plan_ref") !== planRef)
|
|
123
|
+
invalid("the dataset's plan_ref is not the Result's plan_ref");
|
|
124
|
+
if (!Array.isArray(plan.nodes))
|
|
125
|
+
invalid("the dataset plan has no nodes");
|
|
126
|
+
const headers = await headersByDigest(context);
|
|
127
|
+
const rows = [];
|
|
128
|
+
let last = -1;
|
|
129
|
+
for (const raw of dataset.rows) {
|
|
130
|
+
if (!isObj(raw) ||
|
|
131
|
+
Object.keys(raw).sort().join(",") !==
|
|
132
|
+
"digest,digest_alg,record_type,seq" ||
|
|
133
|
+
!Number.isSafeInteger(raw.seq) ||
|
|
134
|
+
raw.seq <= last ||
|
|
135
|
+
typeof raw.record_type !== "string" ||
|
|
136
|
+
raw.digest_alg !== "SHA-256" ||
|
|
137
|
+
typeof raw.digest !== "string" ||
|
|
138
|
+
!HEX64.test(raw.digest))
|
|
139
|
+
return invalid("a dataset row is not {seq, record_type, digest_alg, digest}, in seq order");
|
|
140
|
+
last = raw.seq;
|
|
141
|
+
const found = headers.get(raw.digest);
|
|
142
|
+
if (found !== undefined &&
|
|
143
|
+
(found.header.seq !== raw.seq ||
|
|
144
|
+
found.header.record_type !== raw.record_type))
|
|
145
|
+
invalid(`dataset row seq ${String(raw.seq)} names a header whose seq or record_type differs`);
|
|
146
|
+
rows.push({
|
|
147
|
+
seq: raw.seq,
|
|
148
|
+
recordType: raw.record_type,
|
|
149
|
+
digest: raw.digest,
|
|
150
|
+
...(found === undefined
|
|
151
|
+
? {}
|
|
152
|
+
: { header: found.header, recordId: found.recordId }),
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
return { plan, rows };
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Check every chart spec against a verified bundle, as the builder does
|
|
159
|
+
* before it writes any packaging. A bundle that did not verify, or whose
|
|
160
|
+
* root is not an Evidence Result, has no dataset to check against.
|
|
161
|
+
*/
|
|
162
|
+
export async function checkChartsAgainst(context, charts) {
|
|
163
|
+
let dataset;
|
|
164
|
+
let invalid;
|
|
165
|
+
const verified = bundleVerified(context.verification);
|
|
166
|
+
const result = verified && (await isResultRoot(context))
|
|
167
|
+
? await buildResultRoot(context)
|
|
168
|
+
: undefined;
|
|
169
|
+
try {
|
|
170
|
+
dataset =
|
|
171
|
+
result === undefined ? undefined : await chartDatasetOf(context, result);
|
|
172
|
+
}
|
|
173
|
+
catch (err) {
|
|
174
|
+
if (!(err instanceof ChartRefusal))
|
|
175
|
+
throw err;
|
|
176
|
+
invalid = err;
|
|
177
|
+
}
|
|
178
|
+
return charts.map((spec, index) => {
|
|
179
|
+
try {
|
|
180
|
+
if (invalid !== undefined)
|
|
181
|
+
throw invalid;
|
|
182
|
+
if (isView(spec))
|
|
183
|
+
checkView(spec, dataset);
|
|
184
|
+
else
|
|
185
|
+
checkChart(spec, dataset);
|
|
186
|
+
return { index };
|
|
187
|
+
}
|
|
188
|
+
catch (err) {
|
|
189
|
+
if (!(err instanceof ChartRefusal))
|
|
190
|
+
throw err;
|
|
191
|
+
return { index, refusal: err };
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=chart-dataset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart-dataset.js","sourceRoot":"","sources":["../src/chart-dataset.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,OAAO,EACL,eAAe,EACf,cAAc,EACd,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,qBAAqB,EACrB,UAAU,GAGX,MAAM,0CAA0C,CAAC;AAClD,OAAO,EACL,YAAY,EACZ,UAAU,GAGX,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AA2BrD,MAAM,KAAK,GAAG,CAAC,KAAc,EAAgB,EAAE,CAC7C,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAEvE,0FAA0F;AAC1F,MAAM,CAAC,MAAM,oBAAoB,GAAG,wBAAwB,CAAC;AAC7D,MAAM,eAAe,GAAG,qBAAqB,CAAC;AAC9C,MAAM,KAAK,GAAG,iBAAiB,CAAC;AAEhC,MAAM,OAAO,GAAG,CAAC,OAAe,EAAS,EAAE;IACzC,MAAM,IAAI,YAAY,CAAC,uBAAuB,EAAE,OAAO,CAAC,CAAC;AAC3D,CAAC,CAAC;AAEF,i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ed subset. This module is
|
|
5
|
+
* the data half: it reads a spec, checks it against the sealed dataset the
|
|
6
|
+
* report's Result names (agent-action-capsule spec/evidence-plan-ir-v0.md
|
|
7
|
+
* §5.1 and §6.2), and returns the groups the page draws, recomputed from the
|
|
8
|
+
* rows. It touches no DOM. The Go twin (go/chartspec) runs the same vectors,
|
|
9
|
+
* `vectors/chart-spec/`.
|
|
10
|
+
*/
|
|
11
|
+
type Obj = Record<string, unknown>;
|
|
12
|
+
/** Why a chart was refused. Each has its own vector. */
|
|
13
|
+
export type ChartRefusalReason = "chart-unsupported-member" | "chart-aggregate-shape" | "chart-no-dataset" | "chart-dataset-invalid" | "chart-row-withheld" | "chart-field-missing" | "chart-field-type" | "chart-window-mismatch" | "chart-runs-missing" | "chart-runs-field-mismatch" | "chart-runs-unsealed" | "chart-population-mismatch" | "chart-aggregate-mismatch" | "view-unsupported-member" | "view-chart-shape" | "view-runs-unsealed" | "view-runs-mismatch" | "view-window-not-months" | "view-overlap";
|
|
14
|
+
/** A refused chart: its reason, the JSON pointer it names (if any) and why. */
|
|
15
|
+
export declare class ChartRefusal extends Error {
|
|
16
|
+
readonly reason: ChartRefusalReason;
|
|
17
|
+
readonly pointer: string | undefined;
|
|
18
|
+
constructor(reason: ChartRefusalReason, message: string, pointer?: string);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* One dataset row as the checker reads it: the row's own members and, when
|
|
22
|
+
* the bundle discloses it, the record header the row's digest names.
|
|
23
|
+
* `recordId` is the bundle record that carries the header, for the page's
|
|
24
|
+
* links; the checker never reads it.
|
|
25
|
+
*/
|
|
26
|
+
export interface ChartRow {
|
|
27
|
+
readonly seq: number;
|
|
28
|
+
readonly recordType: string;
|
|
29
|
+
readonly digest: string;
|
|
30
|
+
readonly header?: Obj;
|
|
31
|
+
readonly recordId?: string;
|
|
32
|
+
}
|
|
33
|
+
/** The sealed selection a chart is checked against: its plan and its rows, in `seq` order. */
|
|
34
|
+
export interface ChartDataset {
|
|
35
|
+
readonly plan: Obj;
|
|
36
|
+
readonly rows: readonly ChartRow[];
|
|
37
|
+
}
|
|
38
|
+
export type Scalar = string | number | boolean;
|
|
39
|
+
export type ChannelName = "x" | "y" | "color";
|
|
40
|
+
export type ChartMark = "bar" | "line" | "point" | "rect";
|
|
41
|
+
export type TimeUnit = "utcyearmonthdate" | "utcyearmonth";
|
|
42
|
+
type FieldType = "quantitative" | "ordinal" | "nominal" | "temporal";
|
|
43
|
+
export interface Channel {
|
|
44
|
+
readonly field?: string;
|
|
45
|
+
readonly type: FieldType;
|
|
46
|
+
readonly aggregate?: "count" | "sum";
|
|
47
|
+
readonly timeUnit?: TimeUnit;
|
|
48
|
+
}
|
|
49
|
+
export interface ChartWindow {
|
|
50
|
+
readonly field: string;
|
|
51
|
+
readonly from: string;
|
|
52
|
+
readonly to: string;
|
|
53
|
+
}
|
|
54
|
+
/** One drawn group: its key, its value (absent when not run) and the rows it counts. */
|
|
55
|
+
export interface ChartGroup {
|
|
56
|
+
readonly key: Readonly<Partial<Record<ChannelName, Scalar>>>;
|
|
57
|
+
readonly value?: number;
|
|
58
|
+
readonly notRun: boolean;
|
|
59
|
+
readonly rows: readonly ChartRow[];
|
|
60
|
+
/** On a temporal chart with `runs`: the run records dated in this group's unit. */
|
|
61
|
+
readonly runRows: readonly ChartRow[];
|
|
62
|
+
}
|
|
63
|
+
export interface CheckedChart {
|
|
64
|
+
readonly mark: ChartMark;
|
|
65
|
+
readonly channels: Readonly<Partial<Record<ChannelName, Channel>>>;
|
|
66
|
+
/** The channel that holds the number. */
|
|
67
|
+
readonly aggregate: ChannelName;
|
|
68
|
+
/** The key channels, in the order groups are sorted by. */
|
|
69
|
+
readonly keys: readonly ChannelName[];
|
|
70
|
+
readonly temporal?: ChannelName;
|
|
71
|
+
readonly population: number;
|
|
72
|
+
readonly window?: ChartWindow;
|
|
73
|
+
/** True only when the chart can say "not run": a temporal chart with `runs` on a one-window plan. */
|
|
74
|
+
readonly runs: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* On a temporal chart, every unit of the window in order and whether it was
|
|
77
|
+
* not run. A chart whose other key channel has no values after `transform`
|
|
78
|
+
* has no groups, yet its units still say which days ran (report-view.ts).
|
|
79
|
+
*/
|
|
80
|
+
readonly units?: readonly {
|
|
81
|
+
readonly unit: string;
|
|
82
|
+
readonly notRun: boolean;
|
|
83
|
+
}[];
|
|
84
|
+
readonly groups: readonly ChartGroup[];
|
|
85
|
+
}
|
|
86
|
+
export type Predicate = {
|
|
87
|
+
readonly kind: "equal";
|
|
88
|
+
readonly field: string;
|
|
89
|
+
readonly value: Scalar;
|
|
90
|
+
} | {
|
|
91
|
+
readonly kind: "oneOf";
|
|
92
|
+
readonly field: string;
|
|
93
|
+
readonly values: readonly Scalar[];
|
|
94
|
+
} | {
|
|
95
|
+
readonly kind: "range";
|
|
96
|
+
readonly field: string;
|
|
97
|
+
readonly from: string;
|
|
98
|
+
readonly to: string;
|
|
99
|
+
} | {
|
|
100
|
+
readonly kind: "and" | "or";
|
|
101
|
+
readonly items: readonly Predicate[];
|
|
102
|
+
} | {
|
|
103
|
+
readonly kind: "not";
|
|
104
|
+
readonly item: Predicate;
|
|
105
|
+
};
|
|
106
|
+
export declare function readPredicate(value: unknown, at: string): Predicate;
|
|
107
|
+
declare const MISSING: unique symbol;
|
|
108
|
+
/** A field path resolved on a record header: each name an own member of the object before it. */
|
|
109
|
+
export declare function resolveField(header: Obj, path: string): unknown | typeof MISSING;
|
|
110
|
+
interface Statement {
|
|
111
|
+
readonly population: number;
|
|
112
|
+
readonly window?: ChartWindow;
|
|
113
|
+
readonly runs?: {
|
|
114
|
+
readonly filter: Predicate;
|
|
115
|
+
readonly field: string;
|
|
116
|
+
};
|
|
117
|
+
readonly values: readonly Obj[];
|
|
118
|
+
}
|
|
119
|
+
export interface ChartSpec {
|
|
120
|
+
readonly mark: ChartMark;
|
|
121
|
+
readonly transform: readonly Predicate[];
|
|
122
|
+
readonly channels: Readonly<Partial<Record<ChannelName, Channel>>>;
|
|
123
|
+
readonly aggregate: ChannelName;
|
|
124
|
+
readonly keys: readonly ChannelName[];
|
|
125
|
+
readonly temporal?: ChannelName;
|
|
126
|
+
readonly statement: Statement;
|
|
127
|
+
}
|
|
128
|
+
/** Read a spec in the closed subset, or refuse it (structure only; no data is read). */
|
|
129
|
+
export declare function readChartSpec(value: unknown): ChartSpec;
|
|
130
|
+
/** Compare two key values: false before true, numbers by value, strings by code point. */
|
|
131
|
+
export declare function compareScalar(a: Scalar, b: Scalar): number;
|
|
132
|
+
/**
|
|
133
|
+
* Check one spec against the dataset and return what the page draws. The
|
|
134
|
+
* checks run in the design note's order (section 3), and each refuses with
|
|
135
|
+
* its own reason: the subset; the dataset; withheld rows; fields; window;
|
|
136
|
+
* runs; population; values.
|
|
137
|
+
*/
|
|
138
|
+
export declare function checkChart(value: unknown, dataset: ChartDataset | undefined): CheckedChart;
|
|
139
|
+
/** A checked chart's groups in the statement's `values` form, for vectors. */
|
|
140
|
+
export declare function groupsAsValues(chart: CheckedChart): Obj[];
|
|
141
|
+
export {};
|