@openplanr/protocol 0.6.1 → 0.7.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 +10 -0
- package/lib/dashboard/closed-json-contract.mjs +99 -109
- package/lib/dashboard/operate-experience-audit-display-contract.d.mts +128 -153
- package/lib/dashboard/operate-experience-audit-display-contract.mjs +530 -585
- package/lib/dashboard/operate-experience-display-contract.d.mts +415 -437
- package/lib/dashboard/operate-experience-display-contract.mjs +777 -831
- package/lib/dashboard/operate-experience-surface-contract.d.mts +143 -148
- package/lib/dashboard/operate-experience-surface-contract.mjs +72 -73
- package/lib/dashboard/operate-review-contract.d.mts +7 -14
- package/lib/dashboard/operate-review-contract.mjs +46 -42
- package/lib/dashboard/operate-review-display-workspace-contract.d.mts +2 -5
- package/lib/dashboard/operate-review-display-workspace-contract.mjs +158 -104
- package/lib/dashboard/operate-review-payload-safety.mjs +4 -2
- package/lib/dashboard/operate-review-workspace-projection-v2.d.mts +47 -33
- package/lib/protocol/index.d.ts +2647 -543
- package/package.json +1 -1
- package/registries/artifact-theme.json +64 -0
- package/registries/commands.json +40 -40
- package/registries/skills.json +5 -5
- package/schemas/v1.14.0/artifact-theme.schema.json +316 -0
- package/src/browser-contracts.d.mts +4 -1
- package/src/browser-contracts.mjs +16 -5
- package/src/canonical-json.d.mts +6 -1
- package/src/canonical-json.mjs +100 -22
- package/src/compat/live-evidence-v2.mjs +1611 -485
- package/src/compat/operate-experience-live-patch.mjs +67 -15
- package/src/compat/operating-planning-contracts.mjs +183 -51
- package/src/contracts.d.mts +54 -13
- package/src/contracts.mjs +635 -343
- package/src/design-contracts.mjs +58 -21
- package/src/design-handoff-contracts.d.mts +67 -11
- package/src/design-handoff-contracts.mjs +236 -119
- package/src/design-publication-contracts.mjs +98 -33
- package/src/diagram-authoring-contracts.d.mts +422 -78
- package/src/diagram-authoring-contracts.mjs +1715 -335
- package/src/diagram-contracts.d.mts +4 -1
- package/src/diagram-contracts.mjs +16 -4
- package/src/enterprise-contracts.d.mts +211 -46
- package/src/enterprise-contracts.mjs +738 -184
- package/src/errors.mjs +4 -0
- package/src/generated/canonical-registries.mjs +45 -45
- package/src/index.d.mts +8 -8
- package/src/index.mjs +36 -20
- package/src/json-schema.d.mts +21 -6
- package/src/json-schema.mjs +66 -18
- package/src/planning-contracts.d.mts +8 -2
- package/src/planning-contracts.mjs +33 -7
- package/src/registries.d.mts +11 -3
- package/src/registries.mjs +369 -87
- package/src/review-experience-contracts.d.mts +7 -2
- package/src/review-experience-contracts.mjs +198 -49
- package/src/semver.mjs +5 -1
- package/src/skill-source-contracts.d.mts +36 -16
- package/src/skill-source-contracts.mjs +25 -6
- package/src/task-contracts.d.mts +13 -3
- package/src/task-contracts.mjs +181 -40
- package/src/workspace-contracts.d.mts +38 -10
- package/src/workspace-contracts.mjs +147 -33
|
@@ -1,16 +1,24 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
/** Company publication constraints over the existing, compatible review bundle. */
|
|
2
|
-
|
|
3
|
+
|
|
3
4
|
import { canonicalizeJson, sha256Hex } from './canonical-json.mjs';
|
|
5
|
+
import { assertDesignReviewBundle } from './review-experience-contracts.mjs';
|
|
4
6
|
|
|
7
|
+
/** @type {typeof import('./design-publication-contracts.d.mts').COMPANY_DESIGN_MAX_BYTES} */
|
|
5
8
|
export const COMPANY_DESIGN_MAX_BYTES = 1024 * 1024;
|
|
9
|
+
/** @type {typeof import('./design-publication-contracts.d.mts').COMPANY_DESIGN_MAX_ENTRIES} */
|
|
6
10
|
export const COMPANY_DESIGN_MAX_ENTRIES = 256;
|
|
7
|
-
const fail = message => {
|
|
8
|
-
|
|
11
|
+
const fail = (message) => {
|
|
12
|
+
throw new TypeError(`Invalid company design bundle: ${message}`);
|
|
13
|
+
};
|
|
14
|
+
const isRecord = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
9
15
|
const closed = (value, keys, label) => {
|
|
10
|
-
if (!isRecord(value) || Object.keys(value).some(key => !keys.includes(key)))
|
|
16
|
+
if (!isRecord(value) || Object.keys(value).some((key) => !keys.includes(key)))
|
|
17
|
+
fail(`${label} contains unsupported fields.`);
|
|
11
18
|
};
|
|
12
19
|
const boundedList = (value, max, label) => {
|
|
13
|
-
if (!Array.isArray(value) || !value.length || value.length > max)
|
|
20
|
+
if (!Array.isArray(value) || !value.length || value.length > max)
|
|
21
|
+
fail(`${label} must contain 1–${max} items.`);
|
|
14
22
|
};
|
|
15
23
|
const identities = (items, label) => {
|
|
16
24
|
const map = new Map();
|
|
@@ -21,20 +29,31 @@ const identities = (items, label) => {
|
|
|
21
29
|
return map;
|
|
22
30
|
};
|
|
23
31
|
|
|
24
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* Pure browser/Worker-compatible validation; no artifact or design dependency.
|
|
34
|
+
* @returns {ReturnType<typeof import('./design-publication-contracts.d.mts').assertCompanyDesignBundle>}
|
|
35
|
+
*/
|
|
25
36
|
export function assertCompanyDesignBundle(value) {
|
|
26
37
|
// Bound complexity before recursive schema validation/canonical serialization.
|
|
38
|
+
/** @type {Array<[unknown, number]>} */
|
|
27
39
|
const pending = [[value, 0]];
|
|
28
40
|
let nodes = 0;
|
|
29
|
-
|
|
30
|
-
const [item, depth] =
|
|
41
|
+
for (let next = pending.pop(); next; next = pending.pop()) {
|
|
42
|
+
const [item, depth] = next;
|
|
31
43
|
if (++nodes > 50000 || depth > 40) fail('document complexity exceeds the publication limit.');
|
|
32
|
-
if (item && typeof item === 'object')
|
|
44
|
+
if (item && typeof item === 'object')
|
|
45
|
+
for (const child of Object.values(item)) pending.push([child, depth + 1]);
|
|
33
46
|
}
|
|
34
47
|
let serialized;
|
|
35
|
-
try {
|
|
36
|
-
|
|
37
|
-
|
|
48
|
+
try {
|
|
49
|
+
serialized = canonicalizeJson(value);
|
|
50
|
+
} catch {
|
|
51
|
+
fail('expected bounded JSON data.');
|
|
52
|
+
}
|
|
53
|
+
if (new TextEncoder().encode(serialized).byteLength > COMPANY_DESIGN_MAX_BYTES)
|
|
54
|
+
fail('publication exceeds 1 MiB.');
|
|
55
|
+
if (value?.schemaVersion !== '1.1.0')
|
|
56
|
+
fail('company publication requires review bundle version 1.1.0.');
|
|
38
57
|
assertDesignReviewBundle(value);
|
|
39
58
|
const { design, envelope, entries } = value;
|
|
40
59
|
boundedList(design.screens, 64, 'screens');
|
|
@@ -44,42 +63,88 @@ export function assertCompanyDesignBundle(value) {
|
|
|
44
63
|
const screens = identities(design.screens, 'screens');
|
|
45
64
|
const frames = identities(design.frames, 'frames');
|
|
46
65
|
const variants = identities(design.variants, 'variants');
|
|
47
|
-
if (
|
|
48
|
-
|
|
66
|
+
if (
|
|
67
|
+
design.variants.some((variant) => variant.status !== 'ready') ||
|
|
68
|
+
!variants.has(design.selectedVariant)
|
|
69
|
+
)
|
|
70
|
+
fail('selected and published variants must be ready.');
|
|
71
|
+
if (
|
|
72
|
+
design.screenOrder.length !== screens.size ||
|
|
73
|
+
design.screenOrder.some((id) => !screens.has(id))
|
|
74
|
+
)
|
|
75
|
+
fail('screen order must identify every published screen.');
|
|
49
76
|
identities(design.flows ?? [], 'flows');
|
|
50
|
-
for (const flow of design.flows ?? [])
|
|
51
|
-
|
|
77
|
+
for (const flow of design.flows ?? [])
|
|
78
|
+
if (flow.screens.some((id) => !screens.has(id))) fail('flow references an unknown screen.');
|
|
79
|
+
if (screens.size * frames.size * variants.size !== entries.length)
|
|
80
|
+
fail('entries must cover every screen, frame and ready variant.');
|
|
52
81
|
closed(envelope, ['schemaVersion', 'artifacts', 'viewer'], 'envelope');
|
|
53
82
|
if (envelope.schemaVersion !== '1.0.0') fail('unsupported envelope version.');
|
|
54
83
|
boundedList(envelope.artifacts, COMPANY_DESIGN_MAX_ENTRIES, 'artifacts');
|
|
55
84
|
const artifacts = identities(envelope.artifacts, 'artifacts');
|
|
56
85
|
if (artifacts.size !== entries.length) fail('entries and artifacts must correspond exactly.');
|
|
57
86
|
for (const artifact of artifacts.values()) {
|
|
58
|
-
closed(
|
|
59
|
-
|
|
60
|
-
|
|
87
|
+
closed(
|
|
88
|
+
artifact,
|
|
89
|
+
['id', 'kind', 'title', 'html', 'sha256', 'viewport', 'colorScheme'],
|
|
90
|
+
'artifact',
|
|
91
|
+
);
|
|
92
|
+
if (typeof artifact.id !== 'string' || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/u.test(artifact.id))
|
|
93
|
+
fail('artifact identity is invalid.');
|
|
94
|
+
if (
|
|
95
|
+
artifact.kind !== 'html' ||
|
|
96
|
+
typeof artifact.title !== 'string' ||
|
|
97
|
+
!artifact.title.trim() ||
|
|
98
|
+
artifact.title.length > 512 ||
|
|
99
|
+
typeof artifact.html !== 'string' ||
|
|
100
|
+
!artifact.html.trim()
|
|
101
|
+
)
|
|
102
|
+
fail('artifacts must be titled HTML screens.');
|
|
61
103
|
closed(artifact.viewport, ['width', 'height'], 'viewport');
|
|
62
|
-
if (!['light', 'dark'].includes(artifact.colorScheme))
|
|
63
|
-
|
|
104
|
+
if (!['light', 'dark'].includes(artifact.colorScheme))
|
|
105
|
+
fail('artifact color scheme is invalid.');
|
|
106
|
+
if (
|
|
107
|
+
artifact.sha256 !== sha256Hex(artifact.html.replace(/^\uFEFF/u, '').replace(/\r\n?/gu, '\n'))
|
|
108
|
+
)
|
|
109
|
+
fail('artifact digest does not match its HTML.');
|
|
64
110
|
}
|
|
65
|
-
const usedArtifacts = new Set(),
|
|
111
|
+
const usedArtifacts = new Set(),
|
|
112
|
+
combinations = new Set();
|
|
66
113
|
for (const entry of entries) {
|
|
67
|
-
const artifact = artifacts.get(entry.artifactId),
|
|
68
|
-
|
|
114
|
+
const artifact = artifacts.get(entry.artifactId),
|
|
115
|
+
frame = frames.get(entry.frameId);
|
|
116
|
+
if (!artifact || !frame || !screens.has(entry.screenId) || !variants.has(entry.variantId))
|
|
117
|
+
fail('entry references an unknown screen, variant, frame or artifact.');
|
|
69
118
|
const key = `${entry.screenId}:${entry.variantId}:${entry.frameId}`;
|
|
70
|
-
if (usedArtifacts.has(entry.artifactId) || combinations.has(key))
|
|
71
|
-
|
|
72
|
-
|
|
119
|
+
if (usedArtifacts.has(entry.artifactId) || combinations.has(key))
|
|
120
|
+
fail('entries must uniquely map artboards to artifacts.');
|
|
121
|
+
usedArtifacts.add(entry.artifactId);
|
|
122
|
+
combinations.add(key);
|
|
123
|
+
if (artifact.viewport.width !== frame.width || artifact.viewport.height !== frame.height)
|
|
124
|
+
fail('artifact viewport must match its declared frame.');
|
|
73
125
|
}
|
|
74
126
|
closed(envelope.viewer, ['mode', 'activeArtifactId', 'presentation'], 'viewer');
|
|
75
|
-
if (
|
|
76
|
-
|
|
77
|
-
|
|
127
|
+
if (
|
|
128
|
+
!['single', 'variants'].includes(envelope.viewer.mode) ||
|
|
129
|
+
!artifacts.has(envelope.viewer.activeArtifactId) ||
|
|
130
|
+
envelope.viewer.presentation !== 'canvas'
|
|
131
|
+
)
|
|
132
|
+
fail('viewer must select a published canvas artifact.');
|
|
133
|
+
if (value.fingerprints.length !== entries.length)
|
|
134
|
+
fail('fingerprints must cover every published artboard.');
|
|
135
|
+
for (const key of Object.keys(value.state?.positions ?? {}))
|
|
136
|
+
if (!artifacts.has(key)) fail('layout references an unknown artifact.');
|
|
78
137
|
const components = identities(value.reviewContext.implementation.components, 'review components');
|
|
79
138
|
for (const component of components.values()) {
|
|
80
|
-
if (component.screenIds?.some(id => !screens.has(id)))
|
|
81
|
-
|
|
82
|
-
|
|
139
|
+
if (component.screenIds?.some((id) => !screens.has(id)))
|
|
140
|
+
fail('review guidance references an unknown screen.');
|
|
141
|
+
const anchors = new Set(
|
|
142
|
+
(component.screenIds?.length ? component.screenIds : design.screenOrder).flatMap(
|
|
143
|
+
(id) => screens.get(id).anchors ?? [],
|
|
144
|
+
),
|
|
145
|
+
);
|
|
146
|
+
if (component.anchorIds?.some((id) => !anchors.has(id)))
|
|
147
|
+
fail('review guidance references an undeclared anchor.');
|
|
83
148
|
}
|
|
84
149
|
return value;
|
|
85
150
|
}
|