@action-state-group/capsule-viewer 0.0.0 → 0.3.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/LICENSE +201 -0
- package/LICENSE-BSD-3-Clause +28 -0
- package/README.md +94 -1
- package/dist/alias-interpreters.d.ts +18 -0
- package/dist/alias-interpreters.js +50 -0
- package/dist/alias-interpreters.js.map +1 -0
- package/dist/browser.d.ts +7 -0
- package/dist/browser.js +25 -0
- package/dist/browser.js.map +1 -0
- package/dist/builtin-manifests.d.ts +51 -0
- package/dist/builtin-manifests.js +196 -0
- package/dist/builtin-manifests.js.map +1 -0
- package/dist/compliance-presentation.d.ts +51 -0
- package/dist/compliance-presentation.js +140 -0
- package/dist/compliance-presentation.js.map +1 -0
- package/dist/compliance-styles.d.ts +1 -0
- package/dist/compliance-styles.js +104 -0
- package/dist/compliance-styles.js.map +1 -0
- package/dist/compliance-view.d.ts +46 -0
- package/dist/compliance-view.js +828 -0
- package/dist/compliance-view.js.map +1 -0
- package/dist/compliance.d.ts +121 -0
- package/dist/compliance.js +412 -0
- package/dist/compliance.js.map +1 -0
- package/dist/composed-styles.d.ts +12 -0
- package/dist/composed-styles.js +20 -0
- package/dist/composed-styles.js.map +1 -0
- package/dist/composed-view.d.ts +24 -0
- package/dist/composed-view.js +186 -0
- package/dist/composed-view.js.map +1 -0
- package/dist/contract-report-wording.d.ts +195 -0
- package/dist/contract-report-wording.js +1141 -0
- package/dist/contract-report-wording.js.map +1 -0
- package/dist/contract-report.d.ts +92 -0
- package/dist/contract-report.js +63 -0
- package/dist/contract-report.js.map +1 -0
- package/dist/emitter-shell.html +310 -0
- package/dist/emitter.d.ts +105 -0
- package/dist/emitter.js +329 -0
- package/dist/emitter.js.map +1 -0
- package/dist/evidence-graph-view.d.ts +149 -0
- package/dist/evidence-graph-view.js +2718 -0
- package/dist/evidence-graph-view.js.map +1 -0
- package/dist/evidence-graph.iife.js +18159 -0
- package/dist/frame-tokens.generated.d.ts +3 -0
- package/dist/frame-tokens.generated.js +5 -0
- package/dist/frame-tokens.generated.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/outcome-report-presentation.d.ts +48 -0
- package/dist/outcome-report-presentation.js +90 -0
- package/dist/outcome-report-presentation.js.map +1 -0
- package/dist/outcome-report-styles.d.ts +1 -0
- package/dist/outcome-report-styles.js +228 -0
- package/dist/outcome-report-styles.js.map +1 -0
- package/dist/outcome-report-view.d.ts +78 -0
- package/dist/outcome-report-view.js +1488 -0
- package/dist/outcome-report-view.js.map +1 -0
- package/dist/presentation-builder.d.ts +296 -0
- package/dist/presentation-builder.js +646 -0
- package/dist/presentation-builder.js.map +1 -0
- package/dist/presentation-fragment.d.ts +129 -0
- package/dist/presentation-fragment.js +213 -0
- package/dist/presentation-fragment.js.map +1 -0
- package/dist/presentation-mount.d.ts +26 -0
- package/dist/presentation-mount.js +45 -0
- package/dist/presentation-mount.js.map +1 -0
- package/dist/presentation-registry.d.ts +277 -0
- package/dist/presentation-registry.js +416 -0
- package/dist/presentation-registry.js.map +1 -0
- package/dist/record-content.d.ts +68 -0
- package/dist/record-content.js +153 -0
- package/dist/record-content.js.map +1 -0
- package/dist/record-dating.d.ts +10 -0
- package/dist/record-dating.js +76 -0
- package/dist/record-dating.js.map +1 -0
- package/dist/report-front-styles.d.ts +9 -0
- package/dist/report-front-styles.js +55 -0
- package/dist/report-front-styles.js.map +1 -0
- package/dist/report-front.d.ts +78 -0
- package/dist/report-front.js +274 -0
- package/dist/report-front.js.map +1 -0
- package/dist/report-levels.d.ts +206 -0
- package/dist/report-levels.js +739 -0
- package/dist/report-levels.js.map +1 -0
- package/dist/report-provenance.d.ts +111 -0
- package/dist/report-provenance.js +535 -0
- package/dist/report-provenance.js.map +1 -0
- package/dist/viewer-build.d.ts +37 -0
- package/dist/viewer-build.js +29 -0
- package/dist/viewer-build.js.map +1 -0
- package/dist/wording/contract-report-eu-ai-act.en.json +295 -0
- package/dist/wording/contract-report-outcomes.en.json +394 -0
- package/package.json +48 -4
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
import { bundleVerified, verifiedPayload, } from "@action-state-group/agent-action-capsule";
|
|
2
|
+
import { readCompliancePresentation } from "./compliance-presentation.js";
|
|
3
|
+
import { CONTRACT_REPORT_KIND, readContractReport, } from "@action-state-group/agent-action-capsule";
|
|
4
|
+
import { readOutcomeReportPresentation } from "./outcome-report-presentation.js";
|
|
5
|
+
import { carriesResultDocument, RESULT_VERSION, } from "@action-state-group/agent-action-capsule";
|
|
6
|
+
/**
|
|
7
|
+
* The presentation registry of spec/presentation-contract-v0.md: module
|
|
8
|
+
* manifests (`aac.presentation-manifest/v0`), the resolution descriptor a
|
|
9
|
+
* verified bundle context yields (section 4.2), the static ambiguity test
|
|
10
|
+
* applied at registration (section 4.5) and `resolve` (section 4.3).
|
|
11
|
+
*
|
|
12
|
+
* Precedence lives in the manifests: a registry never orders two modules of
|
|
13
|
+
* one tier. Two that can match one descriptor are rejected when the second
|
|
14
|
+
* is registered, and a runtime tie (only reachable by a resolver that skipped
|
|
15
|
+
* that test) raises {@link PresentationAmbiguityError}, never first-wins.
|
|
16
|
+
*
|
|
17
|
+
* The registry also applies the presentation ABI (section 3.2): a runtime
|
|
18
|
+
* declares the `presentation_api` versions it implements and its runtime
|
|
19
|
+
* version, and a module whose manifest asks for an API it does not implement
|
|
20
|
+
* (or a newer runtime) is registered as REFUSED. A refused module is never
|
|
21
|
+
* selected and none of its methods is called; it still counts for ambiguity,
|
|
22
|
+
* so nothing silently takes its place, and every resolution it would have
|
|
23
|
+
* taken part in carries the refusal.
|
|
24
|
+
*/
|
|
25
|
+
export const PRESENTATION_MANIFEST_VERSION = "aac.presentation-manifest/v0";
|
|
26
|
+
/** The presentation ABI this runtime implements (spec section 3.2). */
|
|
27
|
+
export const PRESENTATION_API_V0 = "aac.presentation-api/v0";
|
|
28
|
+
/** This repository's runtime: exactly `aac.presentation-api/v0`, version 0.1.0. */
|
|
29
|
+
export const REFERENCE_PRESENTATION_RUNTIME = Object.freeze({
|
|
30
|
+
presentationApis: Object.freeze([PRESENTATION_API_V0]),
|
|
31
|
+
runtimeVersion: "0.1.0",
|
|
32
|
+
});
|
|
33
|
+
export const PRESENTATION_FORMATS = [
|
|
34
|
+
"html",
|
|
35
|
+
"fragment",
|
|
36
|
+
"embedded",
|
|
37
|
+
];
|
|
38
|
+
function need(refusal) {
|
|
39
|
+
return refusal.reason === "presentation_api_unsupported"
|
|
40
|
+
? `needs presentation API ${refusal.presentation_api}, which this viewer does not implement`
|
|
41
|
+
: `needs runtime ${refusal.runtime_min} or later; this viewer is ${refusal.runtimeVersion}`;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The semantics cell of the row of an extension a refused module requires
|
|
45
|
+
* (spec section 3.2), exactly. `covered` is whether the bundle digest covers
|
|
46
|
+
* the block.
|
|
47
|
+
*/
|
|
48
|
+
export function presentationRefusalRow(refusal, covered) {
|
|
49
|
+
return `${covered ? "Integrity verified" : "Integrity not verified"}; meaning not interpreted: presentation module ${refusal.id} ${need(refusal)}`;
|
|
50
|
+
}
|
|
51
|
+
/** The line for a refused module that requires no extension (section 3.2). */
|
|
52
|
+
export function presentationRefusalLine(refusal) {
|
|
53
|
+
return `Presentation module ${refusal.id} was not used: it ${need(refusal)}`;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The extension rows with the refusals laid over them: the first refused
|
|
57
|
+
* module (in resolution order) that requires a row's kind replaces that row
|
|
58
|
+
* with its refusal row, whose integrity words follow the row's own
|
|
59
|
+
* `integrity`. Every other row is returned unchanged.
|
|
60
|
+
*/
|
|
61
|
+
export function presentationExtensionRows(rows, refused) {
|
|
62
|
+
return rows.map((row) => {
|
|
63
|
+
const refusal = refused.find((r) => r.extensions.includes(row.id));
|
|
64
|
+
return refusal === undefined
|
|
65
|
+
? row
|
|
66
|
+
: {
|
|
67
|
+
id: row.id,
|
|
68
|
+
integrity: row.integrity,
|
|
69
|
+
refusal,
|
|
70
|
+
semantics: presentationRefusalRow(refusal, row.integrity === "covered"),
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/** The refused modules that have no extension row (section 3.2). */
|
|
75
|
+
export function presentationRefusalNotices(refused) {
|
|
76
|
+
return refused
|
|
77
|
+
.filter((refusal) => refusal.extensions.length === 0)
|
|
78
|
+
.map((refusal) => ({
|
|
79
|
+
id: refusal.id,
|
|
80
|
+
reason: refusal.reason,
|
|
81
|
+
line: presentationRefusalLine(refusal),
|
|
82
|
+
}));
|
|
83
|
+
}
|
|
84
|
+
const RUNTIME_VERSION = /^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$/u;
|
|
85
|
+
const PRESENTATION_API = /^aac\.presentation-api\/v(0|[1-9][0-9]*)$/u;
|
|
86
|
+
function compareVersions(a, b) {
|
|
87
|
+
const left = a.split(".").map(Number);
|
|
88
|
+
const right = b.split(".").map(Number);
|
|
89
|
+
for (let i = 0; i < 3; i += 1)
|
|
90
|
+
if (left[i] !== right[i])
|
|
91
|
+
return left[i] - right[i];
|
|
92
|
+
return 0;
|
|
93
|
+
}
|
|
94
|
+
/** Section 3.2: why `runtime` refuses `manifest`, or undefined. */
|
|
95
|
+
export function presentationRefusalReason(manifest, runtime = REFERENCE_PRESENTATION_RUNTIME) {
|
|
96
|
+
if (!runtime.presentationApis.includes(manifest.presentation_api))
|
|
97
|
+
return "presentation_api_unsupported";
|
|
98
|
+
if (compareVersions(runtime.runtimeVersion, manifest.runtime_min) < 0)
|
|
99
|
+
return "runtime_too_old";
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
function refusalOf(manifest, reason, runtime) {
|
|
103
|
+
return Object.freeze({
|
|
104
|
+
id: manifest.id,
|
|
105
|
+
presentation_api: manifest.presentation_api,
|
|
106
|
+
runtime_min: manifest.runtime_min,
|
|
107
|
+
reason,
|
|
108
|
+
extensions: Object.freeze([
|
|
109
|
+
...(manifest.requires.extensions?.required ?? []),
|
|
110
|
+
]),
|
|
111
|
+
runtimeVersion: runtime.runtimeVersion,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
export class PresentationAmbiguityError extends Error {
|
|
115
|
+
ids;
|
|
116
|
+
constructor(ids, message) {
|
|
117
|
+
super(message ??
|
|
118
|
+
`presentation is ambiguous: ${ids.join(", ")} all match; a tie is an error, never first-wins`);
|
|
119
|
+
this.name = "PresentationAmbiguityError";
|
|
120
|
+
this.ids = ids;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
export class PresentationRegistrationError extends Error {
|
|
124
|
+
constructor(message) {
|
|
125
|
+
super(message);
|
|
126
|
+
this.name = "PresentationRegistrationError";
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// ---------------------------------------------------------------------------
|
|
130
|
+
// The verification gate and the descriptor
|
|
131
|
+
// ---------------------------------------------------------------------------
|
|
132
|
+
// The viewer's verification gate (agent-action-capsule's
|
|
133
|
+
// spec/verification-display-v0.md section 1) is AAC's own `bundleVerified`,
|
|
134
|
+
// re-exported so this package's API keeps the name.
|
|
135
|
+
export { bundleVerified };
|
|
136
|
+
const isPlainObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
137
|
+
/**
|
|
138
|
+
* Extension kinds whose core reader can decline a present block. A kind not
|
|
139
|
+
* listed here is engaged whenever it is present. The two older display kinds
|
|
140
|
+
* are deprecated aliases of `contract-report/v1` (spec section 4.2's
|
|
141
|
+
* deprecation table): read unchanged until their removal.
|
|
142
|
+
*/
|
|
143
|
+
const EXTENSION_READERS = {
|
|
144
|
+
[CONTRACT_REPORT_KIND]: readContractReport,
|
|
145
|
+
"outcome-report/v1": (bundle) => readOutcomeReportPresentation(bundle) !== undefined,
|
|
146
|
+
"eu-ai-act-compliance/v1": (bundle) => readCompliancePresentation(bundle) !== undefined,
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* The descriptor of spec section 4.2, derived from the context alone. It is
|
|
150
|
+
* a helper, not a context field: the context stays the one verification
|
|
151
|
+
* run, and resolution reads it through this function.
|
|
152
|
+
*
|
|
153
|
+
* - `profiles`: `spec_version:<v>` when the root's `agent_input` is disclosed
|
|
154
|
+
* and carries a string `spec_version`; `result_version:evidence-result-v0`
|
|
155
|
+
* when the root carries an Evidence Result v0 in a disclosed member (the
|
|
156
|
+
* same test `isResultRoot` runs).
|
|
157
|
+
* - `extensions`: every member of the bundle's `extensions` object that the
|
|
158
|
+
* core's reader accepts; a present block its reader declines is absent.
|
|
159
|
+
*/
|
|
160
|
+
export function describeContext(context) {
|
|
161
|
+
const bundle = isPlainObject(context.bundle) ? context.bundle : {};
|
|
162
|
+
const verified = bundleVerified(context.verification);
|
|
163
|
+
const bundleKind = typeof bundle.bundle_kind === "string" ? bundle.bundle_kind : undefined;
|
|
164
|
+
// Resolution refuses an unverified context before matching anything, so
|
|
165
|
+
// nothing in an unverified bundle is read to describe it.
|
|
166
|
+
if (!verified)
|
|
167
|
+
return {
|
|
168
|
+
verified,
|
|
169
|
+
bundle_kind: bundleKind,
|
|
170
|
+
profiles: new Set(),
|
|
171
|
+
extensions: new Set(),
|
|
172
|
+
};
|
|
173
|
+
const profiles = new Set();
|
|
174
|
+
if (context.root !== undefined && context.recordIndex.has(context.root)) {
|
|
175
|
+
const input = verifiedPayload(context, context.root, "agent_input");
|
|
176
|
+
if (isPlainObject(input) && typeof input.spec_version === "string")
|
|
177
|
+
profiles.add(`spec_version:${input.spec_version}`);
|
|
178
|
+
}
|
|
179
|
+
if (carriesResultDocument(context))
|
|
180
|
+
profiles.add(`result_version:${RESULT_VERSION}`);
|
|
181
|
+
const extensions = new Set();
|
|
182
|
+
if (isPlainObject(bundle.extensions))
|
|
183
|
+
for (const kind of Object.keys(bundle.extensions)) {
|
|
184
|
+
const reader = EXTENSION_READERS[kind];
|
|
185
|
+
if (reader === undefined || reader(context.bundle))
|
|
186
|
+
extensions.add(kind);
|
|
187
|
+
}
|
|
188
|
+
return { verified, bundle_kind: bundleKind, profiles, extensions };
|
|
189
|
+
}
|
|
190
|
+
// ---------------------------------------------------------------------------
|
|
191
|
+
// Matching, the static test and resolution
|
|
192
|
+
// ---------------------------------------------------------------------------
|
|
193
|
+
const requiredProfiles = (m) => m.requires.profiles ?? [];
|
|
194
|
+
const requiredExtensions = (m) => m.requires.extensions?.required ?? [];
|
|
195
|
+
const forbiddenProfiles = (m) => m.forbids?.profiles ?? [];
|
|
196
|
+
const forbiddenExtensions = (m) => m.forbids?.extensions ?? [];
|
|
197
|
+
const profileKey = (token) => token.split(":", 1)[0];
|
|
198
|
+
function onePerKey(tokens) {
|
|
199
|
+
const keys = new Set();
|
|
200
|
+
for (const token of tokens) {
|
|
201
|
+
const key = profileKey(token);
|
|
202
|
+
if (keys.has(key))
|
|
203
|
+
return false;
|
|
204
|
+
keys.add(key);
|
|
205
|
+
}
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
/** Section 4.3 step 2: the declarative match, nothing else. */
|
|
209
|
+
export function manifestMatches(manifest, descriptor, audience, format) {
|
|
210
|
+
return (manifest.requires.bundle_kind === descriptor.bundle_kind &&
|
|
211
|
+
requiredProfiles(manifest).every((t) => descriptor.profiles.has(t)) &&
|
|
212
|
+
requiredExtensions(manifest).every((k) => descriptor.extensions.has(k)) &&
|
|
213
|
+
!forbiddenProfiles(manifest).some((t) => descriptor.profiles.has(t)) &&
|
|
214
|
+
!forbiddenExtensions(manifest).some((k) => descriptor.extensions.has(k)) &&
|
|
215
|
+
(manifest.audiences.includes("*") ||
|
|
216
|
+
manifest.audiences.includes(audience)) &&
|
|
217
|
+
manifest.formats.includes(format));
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Section 4.5: true exactly when some descriptor matches both manifests,
|
|
221
|
+
* whatever their tiers (the caller compares tiers).
|
|
222
|
+
*/
|
|
223
|
+
export function manifestsCoMatchable(a, b) {
|
|
224
|
+
if (a.requires.bundle_kind !== b.requires.bundle_kind)
|
|
225
|
+
return false;
|
|
226
|
+
if (!a.audiences.includes("*") &&
|
|
227
|
+
!b.audiences.includes("*") &&
|
|
228
|
+
!a.audiences.some((x) => b.audiences.includes(x)))
|
|
229
|
+
return false;
|
|
230
|
+
if (!a.formats.some((f) => b.formats.includes(f)))
|
|
231
|
+
return false;
|
|
232
|
+
const reqP = new Set([...requiredProfiles(a), ...requiredProfiles(b)]);
|
|
233
|
+
const reqE = new Set([...requiredExtensions(a), ...requiredExtensions(b)]);
|
|
234
|
+
const forbP = [...forbiddenProfiles(a), ...forbiddenProfiles(b)];
|
|
235
|
+
const forbE = [...forbiddenExtensions(a), ...forbiddenExtensions(b)];
|
|
236
|
+
if (forbP.some((t) => reqP.has(t)))
|
|
237
|
+
return false;
|
|
238
|
+
if (forbE.some((k) => reqE.has(k)))
|
|
239
|
+
return false;
|
|
240
|
+
return onePerKey(reqP);
|
|
241
|
+
}
|
|
242
|
+
const MANIFEST_MEMBERS = new Set([
|
|
243
|
+
"spec_version",
|
|
244
|
+
"id",
|
|
245
|
+
"presentation_api",
|
|
246
|
+
"runtime_min",
|
|
247
|
+
"trust_class",
|
|
248
|
+
"requires",
|
|
249
|
+
"forbids",
|
|
250
|
+
"audiences",
|
|
251
|
+
"formats",
|
|
252
|
+
"fallback",
|
|
253
|
+
"priority",
|
|
254
|
+
"executable",
|
|
255
|
+
"declarative",
|
|
256
|
+
]);
|
|
257
|
+
const MANIFEST_ID = /^[a-z0-9]+(\.[a-z0-9_-]+)+\/v[0-9]+$/u;
|
|
258
|
+
const PROFILE_TOKEN = /^(spec_version|result_version):[A-Za-z0-9][A-Za-z0-9._/@+-]*$/u;
|
|
259
|
+
const AUDIENCE = /^(\*|[a-z][a-z0-9_-]*)$/u;
|
|
260
|
+
/**
|
|
261
|
+
* The structural rules of `$defs/PresentationManifest` a registry relies on,
|
|
262
|
+
* plus the dead-manifest rule of section 4.5. The JSON Schema stays the full
|
|
263
|
+
* definition; this refuses what would make resolution wrong.
|
|
264
|
+
*/
|
|
265
|
+
export function manifestProblems(manifest) {
|
|
266
|
+
const problems = [];
|
|
267
|
+
const raw = manifest;
|
|
268
|
+
if (!isPlainObject(raw))
|
|
269
|
+
return ["manifest is not an object"];
|
|
270
|
+
for (const member of Object.keys(raw))
|
|
271
|
+
if (!MANIFEST_MEMBERS.has(member))
|
|
272
|
+
problems.push(`unknown member ${JSON.stringify(member)}`);
|
|
273
|
+
if (manifest.spec_version !== PRESENTATION_MANIFEST_VERSION)
|
|
274
|
+
problems.push(`spec_version is not ${PRESENTATION_MANIFEST_VERSION}`);
|
|
275
|
+
if (typeof manifest.id !== "string" || !MANIFEST_ID.test(manifest.id))
|
|
276
|
+
problems.push("id is not <dotted name>/v<major>");
|
|
277
|
+
// A missing or malformed presentation_api is a malformed manifest; a
|
|
278
|
+
// well-formed one the runtime does not implement is a refusal, not this.
|
|
279
|
+
if (typeof manifest.presentation_api !== "string" ||
|
|
280
|
+
!PRESENTATION_API.test(manifest.presentation_api))
|
|
281
|
+
problems.push("presentation_api is not aac.presentation-api/v<major>");
|
|
282
|
+
if (typeof manifest.runtime_min !== "string" ||
|
|
283
|
+
!RUNTIME_VERSION.test(manifest.runtime_min))
|
|
284
|
+
problems.push("runtime_min is not MAJOR.MINOR.PATCH");
|
|
285
|
+
if (manifest.trust_class !== "trusted-executable" &&
|
|
286
|
+
manifest.trust_class !== "declarative")
|
|
287
|
+
problems.push("trust_class is neither trusted-executable nor declarative");
|
|
288
|
+
if (!isPlainObject(manifest.requires) ||
|
|
289
|
+
typeof manifest.requires.bundle_kind !== "string")
|
|
290
|
+
problems.push("requires.bundle_kind is missing");
|
|
291
|
+
for (const token of [
|
|
292
|
+
...requiredProfiles(manifest),
|
|
293
|
+
...forbiddenProfiles(manifest),
|
|
294
|
+
])
|
|
295
|
+
if (!PROFILE_TOKEN.test(token))
|
|
296
|
+
problems.push(`profile token ${JSON.stringify(token)} is malformed`);
|
|
297
|
+
if (!Array.isArray(manifest.audiences) ||
|
|
298
|
+
manifest.audiences.length === 0 ||
|
|
299
|
+
manifest.audiences.some((a) => typeof a !== "string" || !AUDIENCE.test(a)))
|
|
300
|
+
problems.push("audiences is not a non-empty list of audience tokens");
|
|
301
|
+
if (!Array.isArray(manifest.formats) ||
|
|
302
|
+
manifest.formats.length === 0 ||
|
|
303
|
+
manifest.formats.some((f) => !PRESENTATION_FORMATS.includes(f)))
|
|
304
|
+
problems.push("formats is not a non-empty list of html/fragment/embedded");
|
|
305
|
+
if (typeof manifest.fallback !== "boolean")
|
|
306
|
+
problems.push("fallback is not a boolean");
|
|
307
|
+
else if (manifest.fallback && manifest.priority !== undefined)
|
|
308
|
+
problems.push("a fallback carries no priority");
|
|
309
|
+
else if (!manifest.fallback &&
|
|
310
|
+
!(Number.isInteger(manifest.priority) && manifest.priority >= 1))
|
|
311
|
+
problems.push("a specific module needs an integer priority >= 1");
|
|
312
|
+
if ((manifest.trust_class === "trusted-executable") !==
|
|
313
|
+
(manifest.executable !== undefined && manifest.declarative === undefined))
|
|
314
|
+
problems.push("trusted-executable carries executable, declarative carries declarative");
|
|
315
|
+
// Dead manifests (section 4.5): they can never match.
|
|
316
|
+
if (forbiddenProfiles(manifest).some((t) => requiredProfiles(manifest).includes(t)))
|
|
317
|
+
problems.push("requires and forbids share a profile");
|
|
318
|
+
if (forbiddenExtensions(manifest).some((k) => requiredExtensions(manifest).includes(k)))
|
|
319
|
+
problems.push("requires and forbids share an extension");
|
|
320
|
+
if (!onePerKey(requiredProfiles(manifest)))
|
|
321
|
+
problems.push("requires two tokens of one profile key");
|
|
322
|
+
return problems;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Section 4.3 over an explicit module list, exactly. Exported so the
|
|
326
|
+
* algorithm can be exercised without a registry's registration test.
|
|
327
|
+
*/
|
|
328
|
+
export async function resolveModules(modules, descriptor, audience, format, canRender, refuse = () => undefined) {
|
|
329
|
+
// 1. Verification gate: no manifest is matched, no module is called.
|
|
330
|
+
if (!descriptor.verified)
|
|
331
|
+
return { kind: "refusal" };
|
|
332
|
+
// 2. Match, refused modules included.
|
|
333
|
+
const matched = modules.filter((m) => manifestMatches(m.manifest, descriptor, audience, format));
|
|
334
|
+
const refused = [];
|
|
335
|
+
// 3. Specific tier, then 4. fallback tier. Ambiguity is decided on the
|
|
336
|
+
// declarative match, before any canRender is called.
|
|
337
|
+
for (const fallback of [false, true]) {
|
|
338
|
+
const tier = matched.filter((m) => m.manifest.fallback === fallback);
|
|
339
|
+
if (tier.length > 1)
|
|
340
|
+
throw new PresentationAmbiguityError(tier.map((m) => m.manifest.id).sort());
|
|
341
|
+
const only = tier[0];
|
|
342
|
+
if (only === undefined)
|
|
343
|
+
continue;
|
|
344
|
+
// A refused module is recorded and skipped; none of its methods runs.
|
|
345
|
+
const refusal = refuse(only);
|
|
346
|
+
if (refusal !== undefined) {
|
|
347
|
+
refused.push(refusal);
|
|
348
|
+
continue;
|
|
349
|
+
}
|
|
350
|
+
if (await canRender(only))
|
|
351
|
+
return { kind: "module", module: only, refused: Object.freeze(refused) };
|
|
352
|
+
}
|
|
353
|
+
// 5. Nothing.
|
|
354
|
+
return { kind: "no-presentation", refused: Object.freeze(refused) };
|
|
355
|
+
}
|
|
356
|
+
export class PresentationRegistry {
|
|
357
|
+
/** Every module, refused ones included: all of them count for ambiguity. */
|
|
358
|
+
#modules = [];
|
|
359
|
+
#refused = new Map();
|
|
360
|
+
#runtime;
|
|
361
|
+
/** `runtime` is what this registry's runtime implements (section 3.2). */
|
|
362
|
+
constructor(runtime = REFERENCE_PRESENTATION_RUNTIME) {
|
|
363
|
+
this.#runtime = runtime;
|
|
364
|
+
}
|
|
365
|
+
/** The runtime declaration this registry applies. */
|
|
366
|
+
get runtime() {
|
|
367
|
+
return this.#runtime;
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Register a module. Throws on a malformed or dead manifest (a missing
|
|
371
|
+
* `presentation_api` included), a duplicate id, and any module whose
|
|
372
|
+
* manifest some descriptor could match together with an already
|
|
373
|
+
* registered module of the same tier (section 4.5), refused or not.
|
|
374
|
+
*
|
|
375
|
+
* A well-formed manifest whose `presentation_api` this runtime does not
|
|
376
|
+
* implement, or whose `runtime_min` it does not meet, is registered as
|
|
377
|
+
* refused (section 3.2): never selected, reported by every resolution it
|
|
378
|
+
* matches, and listed by {@link refused}.
|
|
379
|
+
*/
|
|
380
|
+
register(module) {
|
|
381
|
+
const manifest = module.manifest;
|
|
382
|
+
const problems = manifestProblems(manifest);
|
|
383
|
+
if (problems.length > 0)
|
|
384
|
+
throw new PresentationRegistrationError(`manifest ${JSON.stringify(manifest?.id)} refused: ${problems.join("; ")}`);
|
|
385
|
+
for (const other of this.#modules) {
|
|
386
|
+
if (other.manifest.id === manifest.id)
|
|
387
|
+
throw new PresentationRegistrationError(`manifest ${manifest.id} is already registered`);
|
|
388
|
+
if (other.manifest.fallback === manifest.fallback &&
|
|
389
|
+
manifestsCoMatchable(other.manifest, manifest))
|
|
390
|
+
throw new PresentationAmbiguityError([other.manifest.id, manifest.id].sort(), `manifests ${other.manifest.id} and ${manifest.id} are both ${manifest.fallback ? "fallbacks" : "specific"} and one descriptor can match both; state precedence with forbids`);
|
|
391
|
+
}
|
|
392
|
+
this.#modules.push(module);
|
|
393
|
+
const reason = presentationRefusalReason(manifest, this.#runtime);
|
|
394
|
+
if (reason === undefined)
|
|
395
|
+
return { status: "registered" };
|
|
396
|
+
const refusal = refusalOf(manifest, reason, this.#runtime);
|
|
397
|
+
this.#refused.set(module, refusal);
|
|
398
|
+
return { status: "refused", refusal };
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Every module this registry can select, in registration order (which
|
|
402
|
+
* decides nothing). Refused modules are not here; see {@link refused}.
|
|
403
|
+
*/
|
|
404
|
+
list() {
|
|
405
|
+
return this.#modules.filter((module) => !this.#refused.has(module));
|
|
406
|
+
}
|
|
407
|
+
/** Every module this runtime refused, with the reason. */
|
|
408
|
+
refused() {
|
|
409
|
+
return [...this.#refused.values()];
|
|
410
|
+
}
|
|
411
|
+
/** Section 4.3: the one module for this context, audience and format. */
|
|
412
|
+
resolve(context, audience, format) {
|
|
413
|
+
return resolveModules(this.#modules, describeContext(context), audience, format, (module) => module.canRender(context), (module) => this.#refused.get(module));
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
//# sourceMappingURL=presentation-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presentation-registry.js","sourceRoot":"","sources":["../src/presentation-registry.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,cAAc,EACd,eAAe,GAChB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EACL,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,0CAA0C,CAAC;AAElD,OAAO,EAAE,6BAA6B,EAAE,MAAM,kCAAkC,CAAC;AACjF,OAAO,EACL,qBAAqB,EACrB,cAAc,GACf,MAAM,0CAA0C,CAAC;AAElD;;;;;;;;;;;;;;;;;;GAkBG;AAEH,MAAM,CAAC,MAAM,6BAA6B,GAAG,8BAA8B,CAAC;AAE5E,uEAAuE;AACvE,MAAM,CAAC,MAAM,mBAAmB,GAAG,yBAAyB,CAAC;AAU7D,mFAAmF;AACnF,MAAM,CAAC,MAAM,8BAA8B,GACzC,MAAM,CAAC,MAAM,CAAC;IACZ,gBAAgB,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,mBAAmB,CAAC,CAAC;IACtD,cAAc,EAAE,OAAO;CACxB,CAAC,CAAC;AAGL,MAAM,CAAC,MAAM,oBAAoB,GAAkC;IACjE,MAAM;IACN,UAAU;IACV,UAAU;CACX,CAAC;AA0IF,SAAS,IAAI,CAAC,OAA4B;IACxC,OAAO,OAAO,CAAC,MAAM,KAAK,8BAA8B;QACtD,CAAC,CAAC,0BAA0B,OAAO,CAAC,gBAAgB,wCAAwC;QAC5F,CAAC,CAAC,iBA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ACrC,CAAC;IAED,yEAAyE;IACzE,OAAO,CACL,OAA8B,EAC9B,QAAgB,EAChB,MAA0B;QAE1B,OAAO,cAAc,CACnB,IAAI,CAAC,QAAQ,EACb,eAAe,CAAC,OAAO,CAAC,EACxB,QAAQ,EACR,MAAM,EACN,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,EACrC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CACtC,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { TranscriptTurn } from "@action-state-group/agent-action-capsule";
|
|
2
|
+
import type { Words } from "./contract-report-wording.js";
|
|
3
|
+
/**
|
|
4
|
+
* How the core draws a record's disclosed content: the core checks it
|
|
5
|
+
* against the record's digest first (the verifier's disclosure resolution;
|
|
6
|
+
* a value that does not hash to its commitment is never drawn), then hands
|
|
7
|
+
* it to the first content module whose `matches` accepts it. With none, the
|
|
8
|
+
* content is shown as recorded, indented, never dropped.
|
|
9
|
+
*
|
|
10
|
+
* A module only draws inside the content block it is handed; it never reads
|
|
11
|
+
* the bundle and never says anything about verification. Today a module
|
|
12
|
+
* recognises content by its shape. Once a payload can declare its type (the
|
|
13
|
+
* CPB `content_type`, for example the proposed `verifiable-agent-conversation`
|
|
14
|
+
* class), a module also lists the types it takes and only `pickContentModule`
|
|
15
|
+
* changes.
|
|
16
|
+
*/
|
|
17
|
+
export interface ContentModule {
|
|
18
|
+
readonly id: string;
|
|
19
|
+
matches(content: unknown): boolean;
|
|
20
|
+
render(content: unknown, w: Words): HTMLElement;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* JSON text of the value with every object's members in canonical order
|
|
24
|
+
* (RFC 8785 JCS: by key, compared as UTF-16 code units), indented by
|
|
25
|
+
* `indent` spaces when given. A record commits to its content's canonical
|
|
26
|
+
* form, and the same content reaches the page with its members in a
|
|
27
|
+
* different order depending on how the bundle was packaged; drawing the
|
|
28
|
+
* canonical order shows every packaging the same text, in the order that
|
|
29
|
+
* was sealed.
|
|
30
|
+
*
|
|
31
|
+
* Written out here rather than by re-ordering an object for JSON.stringify:
|
|
32
|
+
* an object puts integer-like keys ("9", "10") first in numeric order
|
|
33
|
+
* whatever order they are added in, and assigning a member named
|
|
34
|
+
* `__proto__` would set the object's prototype instead of keeping the
|
|
35
|
+
* member. Strings and numbers are written by JSON.stringify, so a number
|
|
36
|
+
* JSON cannot hold exactly was already rounded when the payload was parsed.
|
|
37
|
+
*/
|
|
38
|
+
export declare function canonicalJson(value: unknown, indent?: number): string;
|
|
39
|
+
/**
|
|
40
|
+
* The turns of a conversation payload, or undefined when the content is not
|
|
41
|
+
* one. Mirrors agent-action-capsule `ts/src/outcome-report.ts`
|
|
42
|
+
* `transcriptTurns` (0.6.0), which that package does not export: an
|
|
43
|
+
* `agent_interaction.messages` array, each message's `role`, `content` and
|
|
44
|
+
* `tool_calls`, the call arguments re-serialised (there with JSON.stringify,
|
|
45
|
+
* here in canonical member order). Keep the two in step.
|
|
46
|
+
*/
|
|
47
|
+
export declare function conversationTurns(content: unknown): TranscriptTurn[] | undefined;
|
|
48
|
+
/** A conversation, drawn as a chat (renderChat): who said what, each tool call and its result. */
|
|
49
|
+
export declare const conversationModule: ContentModule;
|
|
50
|
+
/** The content modules the core picks from, in order. */
|
|
51
|
+
export declare const CONTENT_MODULES: readonly ContentModule[];
|
|
52
|
+
/** The first module that takes this content, or undefined. */
|
|
53
|
+
export declare function pickContentModule(content: unknown, modules?: readonly ContentModule[]): ContentModule | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Disclosed content in its content block: by its module when one takes it,
|
|
56
|
+
* otherwise as recorded: the verifier's parsed payload in canonical member
|
|
57
|
+
* order, indented. Indenting adds whitespace only; a number JSON cannot
|
|
58
|
+
* hold exactly was already rounded when the payload was parsed.
|
|
59
|
+
*/
|
|
60
|
+
export declare function renderContent(content: unknown, w: Words, modules?: readonly ContentModule[]): HTMLElement;
|
|
61
|
+
/**
|
|
62
|
+
* The content block's own stylesheet, scoped to `.cv-content`: the records
|
|
63
|
+
* section is the core's, drawn on every page, inside no module's frame, so
|
|
64
|
+
* a chat or a JSON value there cannot lean on a module's styles. Inserted
|
|
65
|
+
* once per page by the core (evidence-graph-view.ts) and listed in
|
|
66
|
+
* CORE_RUNTIME_STYLES, so the CSP carries its hash.
|
|
67
|
+
*/
|
|
68
|
+
export declare const RECORD_CONTENT_CSS = "\n.cv-content pre{margin:4px 0;white-space:pre-wrap;word-break:break-word;font-family:ui-monospace,Menlo,monospace;font-size:12px;max-height:420px;overflow:auto}\n.cv-content .chat .chat-k{font-size:12.5px;margin:4px 0 6px}\n.cv-content .chat ol.turns{list-style:none;margin:0;padding:10px;display:grid;gap:6px;max-height:620px;overflow:auto;border:1px solid #E3DED3;border-radius:10px;background:#FAF8F4}\n.cv-content .chat li.turn{border-radius:10px;padding:6px 10px;max-width:86%;background:#fff;border:1px solid #E3DED3;font-size:13.5px}\n.cv-content .chat li.turn.user{justify-self:end;background:#ECE8F7;border-color:transparent}\n.cv-content .chat li.turn.assistant{justify-self:start}\n.cv-content .chat li.turn.tool,.cv-content .chat li.turn.system{justify-self:center;max-width:96%;border-style:dashed}\n.cv-content .chat li.turn .who{font-size:10.5px;letter-spacing:.06em;text-transform:uppercase;margin-bottom:2px}\n.cv-content .chat li.turn .say{white-space:pre-wrap;word-break:break-word}\n.cv-content .chat li.turn pre.say{margin:0;font-size:11.5px;max-height:180px}\n.cv-content .chat .call{margin-top:4px;font-size:12.5px;background:#FBEFD9;border-radius:6px;padding:3px 8px;word-break:break-word}\n";
|