@openplanr/protocol 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/README.md +9 -0
  2. package/package.json +17 -1
  3. package/registries/commands.json +11 -11
  4. package/registries/skills.json +86 -8
  5. package/registry/v1.17.0/commands.json +88 -0
  6. package/schemas/v1.16.0/artifact-envelope.schema.json +408 -0
  7. package/schemas/v1.16.0/design-review-bundle.schema.json +590 -0
  8. package/schemas/v1.17.0/artifact-paste-v2.schema.json +52 -0
  9. package/schemas/v1.17.0/artifact-room-append-v3.schema.json +159 -0
  10. package/schemas/v1.17.0/artifact-room-create-v3.schema.json +111 -0
  11. package/schemas/v1.17.0/artifact-room-descriptor-v3.schema.json +92 -0
  12. package/schemas/v1.17.0/artifact-room-event-v3.schema.json +130 -0
  13. package/schemas/v1.17.0/artifact-room-management-v3.schema.json +47 -0
  14. package/schemas/v1.17.0/artifact-room-read-page-v3.schema.json +308 -0
  15. package/schemas/v1.17.0/company-resource-manifest.schema.json +128 -0
  16. package/schemas/v1.17.0/company-resource-upload-prepare.schema.json +164 -0
  17. package/schemas/v1.17.0/company-resource-upload-receipt.schema.json +63 -0
  18. package/schemas/v1.17.0/company-resource-upload-status.schema.json +123 -0
  19. package/schemas/v1.17.0/diagram-authoring-bundle.schema.json +1117 -0
  20. package/schemas/v1.17.0/diagram-edit-transaction.schema.json +3295 -0
  21. package/schemas/v1.17.0/diagram-presentation.schema.json +37 -0
  22. package/schemas/v1.17.0/diagram-review-bundle.schema.json +2439 -0
  23. package/schemas/v1.17.0/encrypted-resource-manifest.schema.json +131 -0
  24. package/schemas/v1.17.0/encrypted-upload-commit.schema.json +38 -0
  25. package/schemas/v1.17.0/encrypted-upload-prepare.schema.json +234 -0
  26. package/schemas/v1.17.0/encrypted-upload-receipt.schema.json +54 -0
  27. package/schemas/v1.17.0/encrypted-upload-status.schema.json +129 -0
  28. package/schemas/v1.17.0/encrypted-workspace-event-v2.schema.json +79 -0
  29. package/schemas/v1.17.0/encrypted-workspace-v2.schema.json +91 -0
  30. package/schemas/v1.17.0/enterprise-agent-handoff.schema.json +985 -0
  31. package/schemas/v1.17.0/enterprise-artifact-revision.schema.json +115 -0
  32. package/schemas/v1.17.0/enterprise-change-proposal.schema.json +379 -0
  33. package/schemas/v1.17.0/enterprise-evidence-reference.schema.json +159 -0
  34. package/schemas/v1.17.0/enterprise-review-thread.schema.json +298 -0
  35. package/schemas/v1.17.0/enterprise-sync-state.schema.json +189 -0
  36. package/schemas/v1.17.0/preview-bridge-message.schema.json +197 -0
  37. package/schemas/v1.17.0/resource-catalog.schema.json +145 -0
  38. package/schemas/v1.17.0/sharing-crypto-aad.schema.json +36 -0
  39. package/schemas/v1.17.0/workspace-management-v2.schema.json +45 -0
  40. package/schemas/v1.17.0/workspace-rotation-v2.schema.json +61 -0
  41. package/src/bounded-json-data.d.mts +2 -0
  42. package/src/bounded-json-data.mjs +56 -0
  43. package/src/browser-contracts.d.mts +14 -1
  44. package/src/browser-contracts.mjs +16 -0
  45. package/src/canonical-json.mjs +17 -16
  46. package/src/contracts.d.mts +1 -1
  47. package/src/contracts.mjs +90 -2
  48. package/src/diagram-authoring-contracts.d.mts +12 -0
  49. package/src/diagram-authoring-contracts.mjs +174 -1
  50. package/src/enterprise-contract-validation.d.mts +44 -0
  51. package/src/enterprise-contract-validation.mjs +279 -0
  52. package/src/enterprise-contracts.mjs +25 -231
  53. package/src/enterprise-resource-contracts.d.mts +72 -0
  54. package/src/enterprise-resource-contracts.mjs +202 -0
  55. package/src/generated/artifact-envelope-metadata.mjs +769 -0
  56. package/src/generated/canonical-registries.mjs +97 -19
  57. package/src/index.d.mts +21 -0
  58. package/src/index.mjs +23 -0
  59. package/src/large-object-contracts.d.mts +107 -0
  60. package/src/large-object-contracts.mjs +473 -0
  61. package/src/large-object-limits.d.mts +16 -0
  62. package/src/large-object-limits.mjs +17 -0
  63. package/src/registries.mjs +1 -0
  64. package/src/review-experience-contracts.d.mts +1 -0
  65. package/src/review-experience-contracts.mjs +25 -4
  66. package/src/sharing-security-contracts.d.mts +63 -0
  67. package/src/sharing-security-contracts.mjs +403 -0
  68. package/src/studio-presentation-contracts.d.mts +92 -0
  69. package/src/studio-presentation-contracts.mjs +287 -0
@@ -0,0 +1,287 @@
1
+ import { canonicalizeJson, sha256Hex } from './canonical-json.mjs';
2
+ import {
3
+ assertDiagramAuthoringBundle,
4
+ assertDiagramData,
5
+ assertDiagramEditTransaction,
6
+ copyImmutableDiagramData,
7
+ DIAGRAM_AUTHORING_SCHEMAS,
8
+ diagramAuthoringBundleDigest,
9
+ sealImmutableDiagramData,
10
+ validateDiagramAuthoringArtifact,
11
+ } from './diagram-authoring-contracts.mjs';
12
+ /** Versioned brand presentation; semantic diagram scene and historical palettes stay unchanged. */
13
+ import {
14
+ assertDiagramReviewBundle,
15
+ DIAGRAM_REVIEW_BUNDLE_SCHEMA,
16
+ } from './diagram-review-contracts.mjs';
17
+ import { validateJson } from './json-schema.mjs';
18
+ export const DIAGRAM_PRESENTATION_SCHEMA = {
19
+ $schema: 'https://json-schema.org/draft/2020-12/schema',
20
+ $id: 'https://openplanr.dev/schemas/v1.17.0/diagram-presentation.schema.json',
21
+ 'x-openplanr-contract': { id: 'diagram-presentation', version: '1.17.0' },
22
+ type: 'object',
23
+ additionalProperties: false,
24
+ required: ['kind', 'schemaVersion', 'palette', 'theme', 'fontFamily'],
25
+ properties: {
26
+ kind: { const: 'openplanr-diagram-presentation' },
27
+ schemaVersion: { const: '2.0.0' },
28
+ palette: { const: 'openplanr-brand-v2' },
29
+ theme: { enum: ['light', 'dark'] },
30
+ fontFamily: { const: 'Inter' },
31
+ },
32
+ };
33
+ export const DIAGRAM_REVIEW_BUNDLE_V11_SCHEMA = structuredClone(DIAGRAM_REVIEW_BUNDLE_SCHEMA);
34
+ Object.assign(DIAGRAM_REVIEW_BUNDLE_V11_SCHEMA, {
35
+ $id: 'https://openplanr.dev/schemas/v1.17.0/diagram-review-bundle.schema.json',
36
+ 'x-openplanr-contract': { id: 'diagram-review-bundle', version: '1.17.0' },
37
+ });
38
+ DIAGRAM_REVIEW_BUNDLE_V11_SCHEMA.properties.schemaVersion = { const: '1.1.0' };
39
+ DIAGRAM_REVIEW_BUNDLE_V11_SCHEMA.properties.presentation = DIAGRAM_PRESENTATION_SCHEMA;
40
+ DIAGRAM_REVIEW_BUNDLE_V11_SCHEMA.required.push('presentation');
41
+ export function assertDiagramPresentation(value) {
42
+ assertDiagramData(value);
43
+ if (validateJson(value, DIAGRAM_PRESENTATION_SCHEMA).length)
44
+ throw new TypeError('Invalid diagram presentation.');
45
+ return value;
46
+ }
47
+ export function normalizeDiagramPresentation(options = {}) {
48
+ assertDiagramData(options);
49
+ const { theme = 'light' } = options;
50
+ return assertDiagramPresentation({
51
+ kind: 'openplanr-diagram-presentation',
52
+ schemaVersion: '2.0.0',
53
+ palette: 'openplanr-brand-v2',
54
+ theme,
55
+ fontFamily: 'Inter',
56
+ });
57
+ }
58
+ export function assertDiagramReviewBundleV11(value) {
59
+ assertDiagramData(value);
60
+ if (validateJson(value, DIAGRAM_REVIEW_BUNDLE_V11_SCHEMA).length)
61
+ throw new TypeError('Invalid diagram review bundle 1.1.0.');
62
+ const { presentation, ...legacy } = value;
63
+ assertDiagramPresentation(presentation);
64
+ if (legacy.authored?.schemaVersion === '1.1.0') {
65
+ assertVersionedDiagramAuthoringBundle(legacy.authored);
66
+ if (canonicalizeJson(legacy.authored.studioPresentation) !== canonicalizeJson(presentation))
67
+ throw new TypeError('Review and authored presentations differ.');
68
+ legacy.authored = legacyDiagramAuthoringProjection(legacy.authored);
69
+ }
70
+ assertDiagramReviewBundle({ ...legacy, schemaVersion: '1.0.0' });
71
+ return value;
72
+ }
73
+ export function assertVersionedDiagramReviewBundle(value) {
74
+ assertDiagramData(value);
75
+ return value?.schemaVersion === '1.1.0'
76
+ ? assertDiagramReviewBundleV11(value)
77
+ : assertDiagramReviewBundle(value);
78
+ }
79
+
80
+ export function versionedDiagramReviewBundleDigest(value) {
81
+ return sha256Hex(canonicalizeJson(assertVersionedDiagramReviewBundle(value)));
82
+ }
83
+
84
+ /** Authoring 1.1 adds explicit brand palette custody without changing historical geometry themes. */
85
+ export const DIAGRAM_AUTHORING_BUNDLE_V11_SCHEMA = structuredClone(
86
+ DIAGRAM_AUTHORING_SCHEMAS['diagram-authoring-bundle'],
87
+ );
88
+ Object.assign(DIAGRAM_AUTHORING_BUNDLE_V11_SCHEMA, {
89
+ $id: 'https://openplanr.dev/schemas/v1.17.0/diagram-authoring-bundle.schema.json',
90
+ 'x-openplanr-contract': { id: 'diagram-authoring-bundle', version: '1.17.0' },
91
+ });
92
+ Object.assign(DIAGRAM_AUTHORING_BUNDLE_V11_SCHEMA.properties, {
93
+ schemaVersion: { const: '1.1.0' },
94
+ protocolVersion: { const: '1.17.0' },
95
+ studioPresentation: DIAGRAM_PRESENTATION_SCHEMA,
96
+ });
97
+ DIAGRAM_AUTHORING_BUNDLE_V11_SCHEMA.required.push('studioPresentation');
98
+ export const DIAGRAM_EDIT_TRANSACTION_V11_SCHEMA = structuredClone(
99
+ DIAGRAM_AUTHORING_SCHEMAS['diagram-edit-transaction'],
100
+ );
101
+ Object.assign(DIAGRAM_EDIT_TRANSACTION_V11_SCHEMA, {
102
+ $id: 'https://openplanr.dev/schemas/v1.17.0/diagram-edit-transaction.schema.json',
103
+ 'x-openplanr-contract': { id: 'diagram-edit-transaction', version: '1.17.0' },
104
+ });
105
+ Object.assign(DIAGRAM_EDIT_TRANSACTION_V11_SCHEMA.properties, {
106
+ schemaVersion: { const: '1.1.0' },
107
+ protocolVersion: { const: '1.17.0' },
108
+ });
109
+ DIAGRAM_EDIT_TRANSACTION_V11_SCHEMA.properties.operations.items.oneOf.push({
110
+ type: 'object',
111
+ additionalProperties: false,
112
+ required: ['type', 'before', 'after'],
113
+ properties: {
114
+ type: { const: 'set-studio-presentation' },
115
+ before: { anyOf: [DIAGRAM_PRESENTATION_SCHEMA, { type: 'null' }] },
116
+ after: { anyOf: [DIAGRAM_PRESENTATION_SCHEMA, { type: 'null' }] },
117
+ },
118
+ });
119
+ export function legacyDiagramAuthoringProjection(value) {
120
+ assertDiagramData(value);
121
+ const { studioPresentation: _studio, ...legacy } = value;
122
+ legacy.schemaVersion = '1.0.0';
123
+ legacy.protocolVersion = '1.13.0';
124
+ legacy.bundleDigest = diagramAuthoringBundleDigest(legacy);
125
+ return legacy;
126
+ }
127
+ export function assertVersionedDiagramAuthoringBundle(value) {
128
+ assertDiagramData(value);
129
+ if (value?.schemaVersion !== '1.1.0') return assertDiagramAuthoringBundle(value);
130
+ if (
131
+ validateJson(value, DIAGRAM_AUTHORING_BUNDLE_V11_SCHEMA).length ||
132
+ value.bundleDigest !== diagramAuthoringBundleDigest(value)
133
+ )
134
+ throw new TypeError('Invalid diagram authoring bundle 1.1.0.');
135
+ assertDiagramPresentation(value.studioPresentation);
136
+ assertDiagramAuthoringBundle(legacyDiagramAuthoringProjection(value));
137
+ return value;
138
+ }
139
+ export function assertVersionedDiagramEditTransaction(value, options = {}) {
140
+ assertDiagramData(value);
141
+ assertDiagramData(options);
142
+ if (value?.schemaVersion !== '1.1.0') return assertDiagramEditTransaction(value, options);
143
+ if (validateJson(value, DIAGRAM_EDIT_TRANSACTION_V11_SCHEMA).length)
144
+ throw new TypeError('Invalid diagram transaction 1.1.0.');
145
+ const basis = options.baseBundle ?? options.bundle;
146
+ if (!basis) return value;
147
+ assertVersionedDiagramAuthoringBundle(basis);
148
+ if (
149
+ value.diagramId !== basis.diagramId ||
150
+ value.base.bundleDigest !== basis.bundleDigest ||
151
+ value.base.semanticDigest !== basis.document.documentDigest ||
152
+ value.base.presentationDigest !== basis.presentation.presentationDigest
153
+ )
154
+ throw new TypeError('Studio transaction basis differs.');
155
+ let presentation = basis.studioPresentation ?? null;
156
+ const ordinary = [];
157
+ for (const op of value.operations) {
158
+ if (op.type !== 'set-studio-presentation') {
159
+ ordinary.push(op);
160
+ continue;
161
+ }
162
+ if (
163
+ canonicalizeJson(op.before) !== canonicalizeJson(presentation) ||
164
+ canonicalizeJson(op.after) === canonicalizeJson(presentation)
165
+ )
166
+ throw new TypeError('Studio presentation operation before/after differs.');
167
+ presentation = op.after;
168
+ }
169
+ if (ordinary.length) {
170
+ const legacy = legacyDiagramAuthoringProjection(basis);
171
+ assertDiagramEditTransaction(
172
+ {
173
+ ...value,
174
+ schemaVersion: '1.0.0',
175
+ protocolVersion: '1.13.0',
176
+ base: { ...value.base, bundleDigest: legacy.bundleDigest },
177
+ operations: ordinary,
178
+ },
179
+ { baseBundle: legacy },
180
+ );
181
+ }
182
+ return value;
183
+ }
184
+
185
+ DIAGRAM_REVIEW_BUNDLE_V11_SCHEMA.properties.authored = {
186
+ oneOf: [
187
+ DIAGRAM_REVIEW_BUNDLE_V11_SCHEMA.properties.authored,
188
+ DIAGRAM_AUTHORING_BUNDLE_V11_SCHEMA,
189
+ ],
190
+ };
191
+
192
+ export const versionedDiagramAuthoringBundleDigest = diagramAuthoringBundleDigest;
193
+ export function validateVersionedDiagramAuthoringBundle(value) {
194
+ try {
195
+ assertVersionedDiagramAuthoringBundle(value);
196
+ return [];
197
+ } catch (error) {
198
+ return [{ path: '$', rule: 'diagram-authoring-contract', detail: error.message }];
199
+ }
200
+ }
201
+ export function validateVersionedDiagramEditTransaction(value, options) {
202
+ try {
203
+ assertVersionedDiagramEditTransaction(value, options);
204
+ return [];
205
+ } catch (error) {
206
+ return [{ path: '$', rule: 'diagram-edit-contract', detail: error.message }];
207
+ }
208
+ }
209
+
210
+ /** Validate historical authoring artifacts against an exact versioned bundle context. */
211
+ export function validateVersionedDiagramAuthoringArtifact(kind, value, options = {}) {
212
+ try {
213
+ assertDiagramData(value);
214
+ assertDiagramData(options);
215
+ } catch (error) {
216
+ return [{ path: '$', rule: 'diagram-authoring-contract', detail: error.message }];
217
+ }
218
+ if (kind === 'diagram-authoring-bundle') return validateVersionedDiagramAuthoringBundle(value);
219
+ if (kind === 'diagram-edit-transaction' && value?.schemaVersion === '1.1.0')
220
+ return validateVersionedDiagramEditTransaction(value, options);
221
+ const context = options.baseBundle ?? options.bundle;
222
+ if (context?.schemaVersion !== '1.1.0')
223
+ return validateDiagramAuthoringArtifact(kind, value, options);
224
+ const failures = validateVersionedDiagramAuthoringBundle(context);
225
+ if (failures.length) return failures.map((entry) => ({ ...entry, path: '$options.bundle' }));
226
+ if (
227
+ options.bundle &&
228
+ options.baseBundle &&
229
+ canonicalizeJson(options.bundle) !== canonicalizeJson(options.baseBundle)
230
+ )
231
+ return [
232
+ { path: '$options', rule: 'basis', detail: 'Conflicting bundle contexts are not accepted.' },
233
+ ];
234
+ const legacy = legacyDiagramAuthoringProjection(context);
235
+ const fullSnapshot = {
236
+ bundleDigest: context.bundleDigest,
237
+ semanticDigest: context.document.documentDigest,
238
+ presentationDigest: context.presentation.presentationDigest,
239
+ };
240
+ let invalidBasis = false;
241
+ function project(item) {
242
+ if (!item || typeof item !== 'object') return;
243
+ if (
244
+ Object.hasOwn(item, 'bundleDigest') &&
245
+ Object.hasOwn(item, 'semanticDigest') &&
246
+ Object.hasOwn(item, 'presentationDigest')
247
+ ) {
248
+ if (canonicalizeJson(item) === canonicalizeJson(fullSnapshot))
249
+ item.bundleDigest = legacy.bundleDigest;
250
+ else if (item.bundleDigest === legacy.bundleDigest) invalidBasis = true;
251
+ }
252
+ for (const child of Object.values(item)) project(child);
253
+ }
254
+ // First bound shape/complexity without trusting any context, then project only exact snapshots.
255
+ const shape = validateDiagramAuthoringArtifact(kind, value);
256
+ if (shape.length) return shape;
257
+ const projected = structuredClone(value);
258
+ project(projected);
259
+ if (invalidBasis)
260
+ return [
261
+ {
262
+ path: '$',
263
+ rule: 'basis',
264
+ detail: 'The artifact must reference the complete supplied bundle snapshot.',
265
+ },
266
+ ];
267
+ const projectedOptions = {
268
+ ...options,
269
+ ...(options.bundle ? { bundle: legacy } : {}),
270
+ ...(options.baseBundle ? { baseBundle: legacy } : {}),
271
+ };
272
+ return validateDiagramAuthoringArtifact(kind, projected, projectedOptions);
273
+ }
274
+
275
+ /** Create an internal immutable snapshot, retaining full schema, semantic and digest validation. */
276
+ export function createVersionedDiagramAuthoringSnapshot(value, previous = null) {
277
+ const copy = copyImmutableDiagramData(value, previous);
278
+ assertVersionedDiagramAuthoringBundle(copy);
279
+ return copy;
280
+ }
281
+
282
+ /** Seal then fully validate one internal immutable revision; public outputs copy it. */
283
+ export function sealVersionedDiagramAuthoringSnapshot(value, previous = null) {
284
+ const copy = sealImmutableDiagramData(value, previous);
285
+ assertVersionedDiagramAuthoringBundle(copy);
286
+ return copy;
287
+ }