@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.
- package/README.md +9 -0
- package/package.json +17 -1
- package/registries/commands.json +11 -11
- package/registries/skills.json +86 -8
- package/registry/v1.17.0/commands.json +88 -0
- package/schemas/v1.16.0/artifact-envelope.schema.json +408 -0
- package/schemas/v1.16.0/design-review-bundle.schema.json +590 -0
- package/schemas/v1.17.0/artifact-paste-v2.schema.json +52 -0
- package/schemas/v1.17.0/artifact-room-append-v3.schema.json +159 -0
- package/schemas/v1.17.0/artifact-room-create-v3.schema.json +111 -0
- package/schemas/v1.17.0/artifact-room-descriptor-v3.schema.json +92 -0
- package/schemas/v1.17.0/artifact-room-event-v3.schema.json +130 -0
- package/schemas/v1.17.0/artifact-room-management-v3.schema.json +47 -0
- package/schemas/v1.17.0/artifact-room-read-page-v3.schema.json +308 -0
- package/schemas/v1.17.0/company-resource-manifest.schema.json +128 -0
- package/schemas/v1.17.0/company-resource-upload-prepare.schema.json +164 -0
- package/schemas/v1.17.0/company-resource-upload-receipt.schema.json +63 -0
- package/schemas/v1.17.0/company-resource-upload-status.schema.json +123 -0
- package/schemas/v1.17.0/diagram-authoring-bundle.schema.json +1117 -0
- package/schemas/v1.17.0/diagram-edit-transaction.schema.json +3295 -0
- package/schemas/v1.17.0/diagram-presentation.schema.json +37 -0
- package/schemas/v1.17.0/diagram-review-bundle.schema.json +2439 -0
- package/schemas/v1.17.0/encrypted-resource-manifest.schema.json +131 -0
- package/schemas/v1.17.0/encrypted-upload-commit.schema.json +38 -0
- package/schemas/v1.17.0/encrypted-upload-prepare.schema.json +234 -0
- package/schemas/v1.17.0/encrypted-upload-receipt.schema.json +54 -0
- package/schemas/v1.17.0/encrypted-upload-status.schema.json +129 -0
- package/schemas/v1.17.0/encrypted-workspace-event-v2.schema.json +79 -0
- package/schemas/v1.17.0/encrypted-workspace-v2.schema.json +91 -0
- package/schemas/v1.17.0/enterprise-agent-handoff.schema.json +985 -0
- package/schemas/v1.17.0/enterprise-artifact-revision.schema.json +115 -0
- package/schemas/v1.17.0/enterprise-change-proposal.schema.json +379 -0
- package/schemas/v1.17.0/enterprise-evidence-reference.schema.json +159 -0
- package/schemas/v1.17.0/enterprise-review-thread.schema.json +298 -0
- package/schemas/v1.17.0/enterprise-sync-state.schema.json +189 -0
- package/schemas/v1.17.0/preview-bridge-message.schema.json +197 -0
- package/schemas/v1.17.0/resource-catalog.schema.json +145 -0
- package/schemas/v1.17.0/sharing-crypto-aad.schema.json +36 -0
- package/schemas/v1.17.0/workspace-management-v2.schema.json +45 -0
- package/schemas/v1.17.0/workspace-rotation-v2.schema.json +61 -0
- package/src/bounded-json-data.d.mts +2 -0
- package/src/bounded-json-data.mjs +56 -0
- package/src/browser-contracts.d.mts +14 -1
- package/src/browser-contracts.mjs +16 -0
- package/src/canonical-json.mjs +17 -16
- package/src/contracts.d.mts +1 -1
- package/src/contracts.mjs +90 -2
- package/src/diagram-authoring-contracts.d.mts +12 -0
- package/src/diagram-authoring-contracts.mjs +174 -1
- package/src/enterprise-contract-validation.d.mts +44 -0
- package/src/enterprise-contract-validation.mjs +279 -0
- package/src/enterprise-contracts.mjs +25 -231
- package/src/enterprise-resource-contracts.d.mts +72 -0
- package/src/enterprise-resource-contracts.mjs +202 -0
- package/src/generated/artifact-envelope-metadata.mjs +769 -0
- package/src/generated/canonical-registries.mjs +97 -19
- package/src/index.d.mts +21 -0
- package/src/index.mjs +23 -0
- package/src/large-object-contracts.d.mts +107 -0
- package/src/large-object-contracts.mjs +473 -0
- package/src/large-object-limits.d.mts +16 -0
- package/src/large-object-limits.mjs +17 -0
- package/src/registries.mjs +1 -0
- package/src/review-experience-contracts.d.mts +1 -0
- package/src/review-experience-contracts.mjs +25 -4
- package/src/sharing-security-contracts.d.mts +63 -0
- package/src/sharing-security-contracts.mjs +403 -0
- package/src/studio-presentation-contracts.d.mts +92 -0
- package/src/studio-presentation-contracts.mjs +287 -0
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
/** Protocol 1.17 room-v3 and paste-v2 contracts; legacy formats remain frozen. */
|
|
2
|
+
import { assertLargeObjectData } from './bounded-json-data.mjs';
|
|
3
|
+
import { canonicalizeJson } from './canonical-json.mjs';
|
|
4
|
+
import { validateJson } from './json-schema.mjs';
|
|
5
|
+
export const ROOM_V3_READ_LIMITS = Object.freeze({
|
|
6
|
+
pageBytes: 8 * 1024 * 1024,
|
|
7
|
+
eventPageBytes: 1024 * 1024,
|
|
8
|
+
eventPageCount: 100,
|
|
9
|
+
aggregateBytes: 128 * 1024 * 1024,
|
|
10
|
+
projectionBytes: 128 * 1024 * 1024,
|
|
11
|
+
retainedEvents: 10000,
|
|
12
|
+
});
|
|
13
|
+
export const ROOM_V3_VERSION = '3.0.0';
|
|
14
|
+
export const ROOM_V3_API = '/api/v2/rooms';
|
|
15
|
+
export const ROOM_V3_GENESIS_HASH = `sha256:${'0'.repeat(64)}`;
|
|
16
|
+
export const ROOM_V3_CAPABILITIES = Object.freeze({
|
|
17
|
+
read: 'room-read',
|
|
18
|
+
reviewer: 'reviewer-write',
|
|
19
|
+
owner: 'owner-verdict',
|
|
20
|
+
management: 'room-management',
|
|
21
|
+
});
|
|
22
|
+
export const SHARING_CRYPTO_VERSION = '2.0.0';
|
|
23
|
+
export const SHARING_CRYPTO_CONTEXT = 'openplanr.sharing.aes-gcm.v2';
|
|
24
|
+
const id = { type: 'string', pattern: '^[A-Za-z0-9_-]{16,128}$' };
|
|
25
|
+
const token = { type: 'string', pattern: '^[A-Za-z0-9_-]{43}$' };
|
|
26
|
+
const sha = { type: 'string', pattern: '^sha256:[a-f0-9]{64}$' };
|
|
27
|
+
const digest = { type: 'string', pattern: '^[a-f0-9]{64}$' };
|
|
28
|
+
const integer = { type: 'integer', minimum: 0, maximum: Number.MAX_SAFE_INTEGER };
|
|
29
|
+
const iso = { type: 'string', format: 'date-time', maxLength: 40 };
|
|
30
|
+
const signature = { type: 'string', pattern: '^[A-Za-z0-9_-]{86}$' };
|
|
31
|
+
const closed = (properties, required = Object.keys(properties)) => ({
|
|
32
|
+
type: 'object',
|
|
33
|
+
additionalProperties: false,
|
|
34
|
+
properties,
|
|
35
|
+
required,
|
|
36
|
+
});
|
|
37
|
+
const schema = (name, properties, required) => ({
|
|
38
|
+
$schema: 'https://json-schema.org/draft/2020-12/schema',
|
|
39
|
+
$id: `https://openplanr.dev/schemas/v1.17.0/${name}.schema.json`,
|
|
40
|
+
'x-openplanr-contract': { id: name, version: '1.17.0' },
|
|
41
|
+
...closed(properties, required),
|
|
42
|
+
});
|
|
43
|
+
const ownerKey = closed({
|
|
44
|
+
algorithm: { const: 'ECDSA-P256-SHA256' },
|
|
45
|
+
encoding: { const: 'spki-base64url' },
|
|
46
|
+
keyId: sha,
|
|
47
|
+
value: { type: 'string', pattern: '^[A-Za-z0-9_-]+$', minLength: 86, maxLength: 342 },
|
|
48
|
+
});
|
|
49
|
+
const cipher = (limit) => ({
|
|
50
|
+
iv: { type: 'string', pattern: '^[A-Za-z0-9_-]{16}$' },
|
|
51
|
+
ciphertext: {
|
|
52
|
+
type: 'string',
|
|
53
|
+
pattern: '^[A-Za-z0-9_-]+$',
|
|
54
|
+
minLength: 22,
|
|
55
|
+
maxLength: Math.ceil((limit * 4) / 3),
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
export const ROOM_V3_DESCRIPTOR_SCHEMA = schema('artifact-room-descriptor-v3', {
|
|
59
|
+
schemaVersion: { const: ROOM_V3_VERSION },
|
|
60
|
+
protocolVersion: { const: ROOM_V3_VERSION },
|
|
61
|
+
roomId: id,
|
|
62
|
+
reviewCommitment: digest,
|
|
63
|
+
ownerKey,
|
|
64
|
+
capabilities: closed(
|
|
65
|
+
Object.fromEntries(
|
|
66
|
+
Object.entries(ROOM_V3_CAPABILITIES).map(([key, value]) => [key, { const: value }]),
|
|
67
|
+
),
|
|
68
|
+
),
|
|
69
|
+
createdAt: iso,
|
|
70
|
+
});
|
|
71
|
+
export const ROOM_V3_CREATE_SCHEMA = schema('artifact-room-create-v3', {
|
|
72
|
+
schemaVersion: { const: ROOM_V3_VERSION },
|
|
73
|
+
operation: { const: 'create' },
|
|
74
|
+
roomId: id,
|
|
75
|
+
creationId: token,
|
|
76
|
+
ttl: { enum: ['1d', '7d', '30d'] },
|
|
77
|
+
reviewCommitment: digest,
|
|
78
|
+
...cipher(5 * 1024 * 1024),
|
|
79
|
+
ownerKey,
|
|
80
|
+
readCapability: token,
|
|
81
|
+
reviewerCapability: token,
|
|
82
|
+
ownerCapability: token,
|
|
83
|
+
manageCapability: token,
|
|
84
|
+
signature,
|
|
85
|
+
});
|
|
86
|
+
export const ROOM_V3_EVENT_SCHEMA = schema('artifact-room-event-v3', {
|
|
87
|
+
schemaVersion: { const: ROOM_V3_VERSION },
|
|
88
|
+
protocolVersion: { const: ROOM_V3_VERSION },
|
|
89
|
+
roomId: id,
|
|
90
|
+
eventId: { type: 'string', pattern: '^[A-Za-z0-9._:-]{1,128}$' },
|
|
91
|
+
sequence: { ...integer, minimum: 1 },
|
|
92
|
+
predecessor: sha,
|
|
93
|
+
kind: {
|
|
94
|
+
enum: ['pin', 'reply', 'pin_status', 'recommendation', 'owner_decision', 'review_snapshot'],
|
|
95
|
+
},
|
|
96
|
+
reviewCommitment: digest,
|
|
97
|
+
authorRole: { enum: ['owner', 'reviewer'] },
|
|
98
|
+
authorKey: ownerKey,
|
|
99
|
+
capability: { enum: ['reviewer-write', 'owner-verdict'] },
|
|
100
|
+
createdAt: iso,
|
|
101
|
+
...cipher(256 * 1024),
|
|
102
|
+
ciphertextDigest: sha,
|
|
103
|
+
signature,
|
|
104
|
+
});
|
|
105
|
+
export const ROOM_V3_APPEND_SCHEMA = schema('artifact-room-append-v3', {
|
|
106
|
+
schemaVersion: { const: ROOM_V3_VERSION },
|
|
107
|
+
operation: { const: 'append' },
|
|
108
|
+
expectedGeneration: integer,
|
|
109
|
+
record: ROOM_V3_EVENT_SCHEMA,
|
|
110
|
+
});
|
|
111
|
+
export const ROOM_V3_READ_PAGE_SCHEMA = schema(
|
|
112
|
+
'artifact-room-read-page-v3',
|
|
113
|
+
{
|
|
114
|
+
version: { const: 'v3' },
|
|
115
|
+
descriptor: ROOM_V3_DESCRIPTOR_SCHEMA,
|
|
116
|
+
expiresAt: iso,
|
|
117
|
+
commentsEnabled: { type: 'boolean' },
|
|
118
|
+
generation: integer,
|
|
119
|
+
sequence: { ...integer, maximum: ROOM_V3_READ_LIMITS.retainedEvents },
|
|
120
|
+
head: sha,
|
|
121
|
+
cursor: { ...integer, maximum: ROOM_V3_READ_LIMITS.retainedEvents },
|
|
122
|
+
eventBytes: { ...integer, maximum: ROOM_V3_READ_LIMITS.eventPageBytes },
|
|
123
|
+
events: {
|
|
124
|
+
type: 'array',
|
|
125
|
+
maxItems: ROOM_V3_READ_LIMITS.eventPageCount,
|
|
126
|
+
items: ROOM_V3_EVENT_SCHEMA,
|
|
127
|
+
},
|
|
128
|
+
nextCursor: {
|
|
129
|
+
oneOf: [
|
|
130
|
+
{ ...integer, minimum: 1, maximum: ROOM_V3_READ_LIMITS.retainedEvents },
|
|
131
|
+
{ type: 'null' },
|
|
132
|
+
],
|
|
133
|
+
},
|
|
134
|
+
...cipher(5 * 1024 * 1024),
|
|
135
|
+
},
|
|
136
|
+
[
|
|
137
|
+
'version',
|
|
138
|
+
'descriptor',
|
|
139
|
+
'expiresAt',
|
|
140
|
+
'commentsEnabled',
|
|
141
|
+
'generation',
|
|
142
|
+
'sequence',
|
|
143
|
+
'head',
|
|
144
|
+
'cursor',
|
|
145
|
+
'eventBytes',
|
|
146
|
+
'events',
|
|
147
|
+
'nextCursor',
|
|
148
|
+
],
|
|
149
|
+
);
|
|
150
|
+
export const ROOM_V3_MANAGEMENT_SCHEMA = schema('artifact-room-management-v3', {
|
|
151
|
+
schemaVersion: { const: ROOM_V3_VERSION },
|
|
152
|
+
roomId: id,
|
|
153
|
+
operation: { enum: ['pause', 'resume', 'delete'] },
|
|
154
|
+
operationId: id,
|
|
155
|
+
expectedGeneration: integer,
|
|
156
|
+
signature,
|
|
157
|
+
});
|
|
158
|
+
export const PASTE_V2_SCHEMA = schema('artifact-paste-v2', {
|
|
159
|
+
schemaVersion: { const: '2.0.0' },
|
|
160
|
+
operation: { const: 'create' },
|
|
161
|
+
id,
|
|
162
|
+
creationId: token,
|
|
163
|
+
ttl: { enum: ['1d', '7d', '30d'] },
|
|
164
|
+
...cipher(5 * 1024 * 1024),
|
|
165
|
+
});
|
|
166
|
+
export const SHARING_CRYPTO_AAD_SCHEMA = schema('sharing-crypto-aad', {
|
|
167
|
+
version: { const: '2.0.0' },
|
|
168
|
+
purpose: { enum: ['artifact-paste', 'room-envelope', 'room-event'] },
|
|
169
|
+
objectId: id,
|
|
170
|
+
recordId: { type: 'string', pattern: '^[A-Za-z0-9._:-]{1,128}$' },
|
|
171
|
+
});
|
|
172
|
+
export const PREVIEW_BRIDGE_MESSAGE_SCHEMA = {
|
|
173
|
+
$schema: 'https://json-schema.org/draft/2020-12/schema',
|
|
174
|
+
$id: 'https://openplanr.dev/schemas/v1.17.0/preview-bridge-message.schema.json',
|
|
175
|
+
'x-openplanr-contract': { id: 'preview-bridge-message', version: '1.17.0' },
|
|
176
|
+
oneOf: [
|
|
177
|
+
schema('preview-bridge-ready', {
|
|
178
|
+
schemaVersion: { const: '1.0.0' },
|
|
179
|
+
channel: token,
|
|
180
|
+
type: { const: 'ready' },
|
|
181
|
+
viewId: id,
|
|
182
|
+
}),
|
|
183
|
+
schema('preview-bridge-navigate', {
|
|
184
|
+
schemaVersion: { const: '1.0.0' },
|
|
185
|
+
channel: token,
|
|
186
|
+
type: { const: 'navigate' },
|
|
187
|
+
viewId: id,
|
|
188
|
+
screenId: id,
|
|
189
|
+
}),
|
|
190
|
+
schema('preview-bridge-select', {
|
|
191
|
+
schemaVersion: { const: '1.0.0' },
|
|
192
|
+
channel: token,
|
|
193
|
+
type: { const: 'select' },
|
|
194
|
+
viewId: id,
|
|
195
|
+
elementId: id,
|
|
196
|
+
}),
|
|
197
|
+
schema('preview-bridge-state', {
|
|
198
|
+
schemaVersion: { const: '1.0.0' },
|
|
199
|
+
channel: token,
|
|
200
|
+
type: { const: 'state' },
|
|
201
|
+
viewId: id,
|
|
202
|
+
state: closed({ session: { type: 'object' }, forms: { type: 'object' } }),
|
|
203
|
+
}),
|
|
204
|
+
schema('preview-bridge-failed', {
|
|
205
|
+
schemaVersion: { const: '1.0.0' },
|
|
206
|
+
channel: token,
|
|
207
|
+
type: { const: 'failed' },
|
|
208
|
+
viewId: id,
|
|
209
|
+
}),
|
|
210
|
+
],
|
|
211
|
+
};
|
|
212
|
+
// Artifact view/screen/element IDs are semantic tokens, not opaque service object IDs.
|
|
213
|
+
for (const alternative of PREVIEW_BRIDGE_MESSAGE_SCHEMA.oneOf)
|
|
214
|
+
for (const key of ['viewId', 'screenId', 'elementId'])
|
|
215
|
+
if (alternative.properties[key])
|
|
216
|
+
alternative.properties[key] = {
|
|
217
|
+
type: 'string',
|
|
218
|
+
pattern: '^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$',
|
|
219
|
+
};
|
|
220
|
+
export function assertPreviewBridgeMessage(value) {
|
|
221
|
+
assertLargeObjectData(value);
|
|
222
|
+
if (validateJson(value, PREVIEW_BRIDGE_MESSAGE_SCHEMA).length)
|
|
223
|
+
throw new TypeError('Invalid preview bridge message.');
|
|
224
|
+
if (value.type === 'state') {
|
|
225
|
+
let keys = 0;
|
|
226
|
+
const pending = [[value.state, 0]],
|
|
227
|
+
seen = new Set();
|
|
228
|
+
for (let entry = pending.pop(); entry; entry = pending.pop()) {
|
|
229
|
+
const [item, depth] = entry;
|
|
230
|
+
if (depth > 6) throw new RangeError('Preview state exceeds its depth limit.');
|
|
231
|
+
if (item === null || typeof item === 'boolean') continue;
|
|
232
|
+
if (typeof item === 'number') {
|
|
233
|
+
if (!Number.isFinite(item)) throw new TypeError('Preview state numbers must be finite.');
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
if (typeof item === 'string') {
|
|
237
|
+
if (item.length > 8192) throw new RangeError('Preview state string is too long.');
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
if (!item || typeof item !== 'object' || seen.has(item))
|
|
241
|
+
throw new TypeError('Preview state must be acyclic JSON.');
|
|
242
|
+
seen.add(item);
|
|
243
|
+
if (Array.isArray(item)) {
|
|
244
|
+
if (item.length > 128) throw new RangeError('Preview state array is too long.');
|
|
245
|
+
for (const child of item) pending.push([child, depth + 1]);
|
|
246
|
+
} else {
|
|
247
|
+
if (
|
|
248
|
+
Object.getPrototypeOf(item) !== Object.prototype &&
|
|
249
|
+
Object.getPrototypeOf(item) !== null
|
|
250
|
+
)
|
|
251
|
+
throw new TypeError('Preview state must be plain JSON.');
|
|
252
|
+
for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(item))) {
|
|
253
|
+
if (
|
|
254
|
+
++keys > 128 ||
|
|
255
|
+
key.length > 256 ||
|
|
256
|
+
['__proto__', 'constructor', 'prototype'].includes(key) ||
|
|
257
|
+
!('value' in descriptor)
|
|
258
|
+
)
|
|
259
|
+
throw new TypeError('Preview state key is invalid.');
|
|
260
|
+
pending.push([descriptor.value, depth + 1]);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
if (new TextEncoder().encode(canonicalizeJson(value.state)).byteLength > 16384)
|
|
265
|
+
throw new RangeError('Preview state exceeds its byte limit.');
|
|
266
|
+
}
|
|
267
|
+
return value;
|
|
268
|
+
}
|
|
269
|
+
export const SHARING_SECURITY_SCHEMAS = Object.freeze({
|
|
270
|
+
'preview-bridge-message': PREVIEW_BRIDGE_MESSAGE_SCHEMA,
|
|
271
|
+
'artifact-room-descriptor-v3': ROOM_V3_DESCRIPTOR_SCHEMA,
|
|
272
|
+
'artifact-room-create-v3': ROOM_V3_CREATE_SCHEMA,
|
|
273
|
+
'artifact-room-read-page-v3': ROOM_V3_READ_PAGE_SCHEMA,
|
|
274
|
+
'artifact-room-append-v3': ROOM_V3_APPEND_SCHEMA,
|
|
275
|
+
'artifact-room-event-v3': ROOM_V3_EVENT_SCHEMA,
|
|
276
|
+
'artifact-room-management-v3': ROOM_V3_MANAGEMENT_SCHEMA,
|
|
277
|
+
'artifact-paste-v2': PASTE_V2_SCHEMA,
|
|
278
|
+
'sharing-crypto-aad': SHARING_CRYPTO_AAD_SCHEMA,
|
|
279
|
+
});
|
|
280
|
+
function decode(value, limit) {
|
|
281
|
+
if (!/^[A-Za-z0-9_-]+$/u.test(value) || value.length > Math.ceil((limit * 4) / 3))
|
|
282
|
+
throw new TypeError('Invalid room encoding.');
|
|
283
|
+
const bytes = Uint8Array.from(atob(value.replaceAll('-', '+').replaceAll('_', '/')), (char) =>
|
|
284
|
+
char.charCodeAt(0),
|
|
285
|
+
);
|
|
286
|
+
let binary = '';
|
|
287
|
+
for (let offset = 0; offset < bytes.length; offset += 8192)
|
|
288
|
+
binary += String.fromCharCode(...bytes.subarray(offset, offset + 8192));
|
|
289
|
+
if (
|
|
290
|
+
btoa(binary).replaceAll('+', '-').replaceAll('/', '_').replace(/=+$/u, '') !== value ||
|
|
291
|
+
bytes.byteLength > limit
|
|
292
|
+
)
|
|
293
|
+
throw new TypeError('Noncanonical room encoding.');
|
|
294
|
+
return bytes;
|
|
295
|
+
}
|
|
296
|
+
export function assertSharingSecurityContract(value, kind) {
|
|
297
|
+
if (kind === 'preview-bridge-message') return assertPreviewBridgeMessage(value);
|
|
298
|
+
assertLargeObjectData(value);
|
|
299
|
+
const selected = Object.hasOwn(SHARING_SECURITY_SCHEMAS, kind)
|
|
300
|
+
? SHARING_SECURITY_SCHEMAS[kind]
|
|
301
|
+
: null;
|
|
302
|
+
if (!selected || validateJson(value, selected).length) throw new TypeError(`Invalid ${kind}.`);
|
|
303
|
+
if (kind === 'artifact-room-append-v3')
|
|
304
|
+
assertSharingSecurityContract(value.record, 'artifact-room-event-v3');
|
|
305
|
+
if (kind === 'artifact-room-read-page-v3') {
|
|
306
|
+
const actual = new TextEncoder().encode(canonicalizeJson(value.events)).byteLength;
|
|
307
|
+
if (
|
|
308
|
+
actual !== value.eventBytes ||
|
|
309
|
+
actual > ROOM_V3_READ_LIMITS.eventPageBytes ||
|
|
310
|
+
new TextEncoder().encode(canonicalizeJson(value)).byteLength >
|
|
311
|
+
ROOM_V3_READ_LIMITS.pageBytes ||
|
|
312
|
+
value.cursor > value.sequence ||
|
|
313
|
+
value.generation < value.sequence
|
|
314
|
+
)
|
|
315
|
+
throw new TypeError('Room page byte accounting or snapshot is invalid.');
|
|
316
|
+
if (
|
|
317
|
+
value.cursor === 0
|
|
318
|
+
? !value.iv || !value.ciphertext
|
|
319
|
+
: Object.hasOwn(value, 'iv') || Object.hasOwn(value, 'ciphertext')
|
|
320
|
+
)
|
|
321
|
+
throw new TypeError('Only the first room page carries its envelope.');
|
|
322
|
+
let last = value.cursor;
|
|
323
|
+
for (const event of value.events) {
|
|
324
|
+
if (event.sequence !== last + 1) throw new TypeError('Room page skips event history.');
|
|
325
|
+
last = event.sequence;
|
|
326
|
+
}
|
|
327
|
+
if (
|
|
328
|
+
last > value.sequence ||
|
|
329
|
+
(value.nextCursor === null
|
|
330
|
+
? last !== value.sequence
|
|
331
|
+
: !value.events.length || value.nextCursor !== last || last >= value.sequence)
|
|
332
|
+
)
|
|
333
|
+
throw new TypeError('Room page continuation is incomplete.');
|
|
334
|
+
}
|
|
335
|
+
if (value.ciphertext) {
|
|
336
|
+
const bytes = decode(
|
|
337
|
+
value.ciphertext,
|
|
338
|
+
kind === 'artifact-room-event-v3' ? 256 * 1024 : 5 * 1024 * 1024,
|
|
339
|
+
);
|
|
340
|
+
if (bytes.byteLength < 16) throw new TypeError('Room ciphertext is too small.');
|
|
341
|
+
}
|
|
342
|
+
if (
|
|
343
|
+
kind === 'artifact-room-create-v3' &&
|
|
344
|
+
new Set([
|
|
345
|
+
value.readCapability,
|
|
346
|
+
value.reviewerCapability,
|
|
347
|
+
value.ownerCapability,
|
|
348
|
+
value.manageCapability,
|
|
349
|
+
]).size !== 4
|
|
350
|
+
)
|
|
351
|
+
throw new TypeError('Room capabilities must be distinct.');
|
|
352
|
+
if (kind === 'artifact-room-event-v3') {
|
|
353
|
+
const ownerKind = ['owner_decision', 'review_snapshot'].includes(value.kind);
|
|
354
|
+
if (
|
|
355
|
+
(value.authorRole === 'owner') !== ownerKind ||
|
|
356
|
+
value.capability !== ROOM_V3_CAPABILITIES[value.authorRole]
|
|
357
|
+
)
|
|
358
|
+
throw new TypeError('Room event role is invalid.');
|
|
359
|
+
}
|
|
360
|
+
return value;
|
|
361
|
+
}
|
|
362
|
+
export function roomV3SignatureBytes(type, value) {
|
|
363
|
+
if (!['create', 'event', 'management'].includes(type))
|
|
364
|
+
throw new TypeError('Unknown room signature purpose.');
|
|
365
|
+
const { signature: _signature, ...body } = value;
|
|
366
|
+
return new TextEncoder().encode(
|
|
367
|
+
canonicalizeJson({ context: `openplanr.artifact-live-room.${type}.v3`, ...body }),
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
export async function verifyRoomV3Signature(
|
|
371
|
+
type,
|
|
372
|
+
value,
|
|
373
|
+
publicKey,
|
|
374
|
+
{ crypto: provider = globalThis.crypto } = {},
|
|
375
|
+
) {
|
|
376
|
+
try {
|
|
377
|
+
const bytes = decode(publicKey.value, 256),
|
|
378
|
+
hash = [...new Uint8Array(await provider.subtle.digest('SHA-256', bytes))]
|
|
379
|
+
.map((part) => part.toString(16).padStart(2, '0'))
|
|
380
|
+
.join('');
|
|
381
|
+
if (
|
|
382
|
+
publicKey.algorithm !== 'ECDSA-P256-SHA256' ||
|
|
383
|
+
publicKey.encoding !== 'spki-base64url' ||
|
|
384
|
+
publicKey.keyId !== `sha256:${hash}`
|
|
385
|
+
)
|
|
386
|
+
return false;
|
|
387
|
+
const key = await provider.subtle.importKey(
|
|
388
|
+
'spki',
|
|
389
|
+
bytes,
|
|
390
|
+
{ name: 'ECDSA', namedCurve: 'P-256' },
|
|
391
|
+
false,
|
|
392
|
+
['verify'],
|
|
393
|
+
);
|
|
394
|
+
return provider.subtle.verify(
|
|
395
|
+
{ name: 'ECDSA', hash: 'SHA-256' },
|
|
396
|
+
key,
|
|
397
|
+
decode(value.signature, 64),
|
|
398
|
+
roomV3SignatureBytes(type, value),
|
|
399
|
+
);
|
|
400
|
+
} catch {
|
|
401
|
+
return false;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
DiagramAuthoringBundle,
|
|
3
|
+
DiagramEditOperation,
|
|
4
|
+
DiagramEditTransaction,
|
|
5
|
+
} from './diagram-authoring-contracts.mjs';
|
|
6
|
+
import type { DiagramReviewBundle } from './diagram-review-contracts.mjs';
|
|
7
|
+
export interface DiagramPresentation {
|
|
8
|
+
kind: 'openplanr-diagram-presentation';
|
|
9
|
+
schemaVersion: '2.0.0';
|
|
10
|
+
palette: 'openplanr-brand-v2';
|
|
11
|
+
theme: 'light' | 'dark';
|
|
12
|
+
fontFamily: 'Inter';
|
|
13
|
+
}
|
|
14
|
+
export type DiagramReviewBundleV11 = Omit<DiagramReviewBundle, 'schemaVersion' | 'authored'> & {
|
|
15
|
+
schemaVersion: '1.1.0';
|
|
16
|
+
presentation: DiagramPresentation;
|
|
17
|
+
authored?: VersionedDiagramAuthoringBundle;
|
|
18
|
+
};
|
|
19
|
+
export declare const DIAGRAM_PRESENTATION_SCHEMA: Record<string, unknown>;
|
|
20
|
+
export declare const DIAGRAM_REVIEW_BUNDLE_V11_SCHEMA: Record<string, unknown>;
|
|
21
|
+
/** Rejects non-inert or over-budget data before reading presentation fields; retains input identity. */
|
|
22
|
+
export declare function assertDiagramPresentation<T>(value: T): T;
|
|
23
|
+
export declare function normalizeDiagramPresentation(options?: {
|
|
24
|
+
theme?: 'light' | 'dark';
|
|
25
|
+
}): DiagramPresentation;
|
|
26
|
+
export declare function assertDiagramReviewBundleV11<T>(value: T): T;
|
|
27
|
+
export declare function assertVersionedDiagramReviewBundle<T>(value: T): T;
|
|
28
|
+
|
|
29
|
+
export declare function versionedDiagramReviewBundleDigest(value: unknown): string;
|
|
30
|
+
|
|
31
|
+
export declare const DIAGRAM_AUTHORING_BUNDLE_V11_SCHEMA: Record<string, unknown>;
|
|
32
|
+
export declare const DIAGRAM_EDIT_TRANSACTION_V11_SCHEMA: Record<string, unknown>;
|
|
33
|
+
export declare function legacyDiagramAuthoringProjection(
|
|
34
|
+
value: VersionedDiagramAuthoringBundle,
|
|
35
|
+
): DiagramAuthoringBundle;
|
|
36
|
+
export declare function assertVersionedDiagramAuthoringBundle<T>(value: T): T;
|
|
37
|
+
/** Inspects both the value and supplied context before version inference or schema validation. */
|
|
38
|
+
export declare function assertVersionedDiagramEditTransaction<T>(
|
|
39
|
+
value: T,
|
|
40
|
+
options?: { baseBundle?: unknown; bundle?: unknown },
|
|
41
|
+
): T;
|
|
42
|
+
|
|
43
|
+
export declare function versionedDiagramAuthoringBundleDigest(value: unknown): string;
|
|
44
|
+
export declare function validateVersionedDiagramAuthoringBundle(
|
|
45
|
+
value: unknown,
|
|
46
|
+
): Array<{ path: string; rule: string; detail: string }>;
|
|
47
|
+
export declare function validateVersionedDiagramEditTransaction(
|
|
48
|
+
value: unknown,
|
|
49
|
+
options?: { baseBundle?: unknown; bundle?: unknown },
|
|
50
|
+
): Array<{ path: string; rule: string; detail: string }>;
|
|
51
|
+
|
|
52
|
+
export type DiagramAuthoringBundleV11 = Omit<
|
|
53
|
+
DiagramAuthoringBundle,
|
|
54
|
+
'schemaVersion' | 'protocolVersion'
|
|
55
|
+
> & { schemaVersion: '1.1.0'; protocolVersion: '1.17.0'; studioPresentation: DiagramPresentation };
|
|
56
|
+
export type VersionedDiagramAuthoringBundle = DiagramAuthoringBundle | DiagramAuthoringBundleV11;
|
|
57
|
+
export interface SetStudioPresentationOperation {
|
|
58
|
+
type: 'set-studio-presentation';
|
|
59
|
+
before: DiagramPresentation | null;
|
|
60
|
+
after: DiagramPresentation | null;
|
|
61
|
+
}
|
|
62
|
+
export type DiagramEditTransactionV11 = Omit<
|
|
63
|
+
DiagramEditTransaction,
|
|
64
|
+
'schemaVersion' | 'protocolVersion' | 'operations'
|
|
65
|
+
> & {
|
|
66
|
+
schemaVersion: '1.1.0';
|
|
67
|
+
protocolVersion: '1.17.0';
|
|
68
|
+
operations: Array<DiagramEditOperation | SetStudioPresentationOperation>;
|
|
69
|
+
};
|
|
70
|
+
export type VersionedDiagramEditTransaction = DiagramEditTransaction | DiagramEditTransactionV11;
|
|
71
|
+
|
|
72
|
+
export declare function validateVersionedDiagramAuthoringArtifact(
|
|
73
|
+
kind: string,
|
|
74
|
+
value: unknown,
|
|
75
|
+
options?: {
|
|
76
|
+
document?: unknown;
|
|
77
|
+
bundle?: VersionedDiagramAuthoringBundle;
|
|
78
|
+
baseBundle?: VersionedDiagramAuthoringBundle;
|
|
79
|
+
sourceText?: string;
|
|
80
|
+
},
|
|
81
|
+
): Array<{ path: string; rule: string; detail: string }>;
|
|
82
|
+
|
|
83
|
+
/** Engine-internal immutable copy; ordinary public authoring outputs remain mutable. */
|
|
84
|
+
export declare function createVersionedDiagramAuthoringSnapshot(
|
|
85
|
+
value: unknown,
|
|
86
|
+
previous?: VersionedDiagramAuthoringBundle | null,
|
|
87
|
+
): VersionedDiagramAuthoringBundle;
|
|
88
|
+
|
|
89
|
+
export declare function sealVersionedDiagramAuthoringSnapshot(
|
|
90
|
+
value: VersionedDiagramAuthoringBundle,
|
|
91
|
+
previous?: VersionedDiagramAuthoringBundle | null,
|
|
92
|
+
): VersionedDiagramAuthoringBundle;
|