rig-review 4.6.0 → 4.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/docs/REVIEW_PACKAGE.md +235 -16
- package/docs/STABILITY.md +62 -4
- package/package.json +1 -1
- package/src/canonical-json.ts +14 -0
- package/src/create-pin-gate.ts +1 -1
- package/src/feedback-export.ts +2 -2
- package/src/interview-project.ts +27 -19
- package/src/interview-scene.ts +18 -11
- package/src/job-act.ts +85 -9
- package/src/job-api.ts +182 -31
- package/src/job-checkpoint-evidence.ts +19 -6
- package/src/job-cli.ts +6 -6
- package/src/job-contract.ts +85 -14
- package/src/job-front.ts +100 -78
- package/src/job-host.ts +9 -2
- package/src/job-previous-draft.ts +37 -0
- package/src/job-session.ts +74 -40
- package/src/job-source.ts +196 -35
- package/src/manifest.ts +43 -14
- package/src/mesh-edit.ts +7 -1
- package/src/parts-comment-crops.ts +15 -3
- package/src/parts-comparison.ts +21 -8
- package/src/parts-view.ts +23 -8
- package/web/catalog-en.ts +10 -0
- package/web/catalog-ko.ts +10 -0
- package/web/job-rig-screen.ts +65 -21
- package/web/job-session.ts +54 -26
- package/web/main.ts +158 -50
- package/web/mesh-editor.ts +124 -13
- package/web/part-selection.ts +1 -1
- package/web/parts-viewport-provider.ts +45 -8
- package/web/rig-host.ts +5 -3
- package/web/stage-comments.ts +77 -14
- package/web/styles.css +2 -0
- package/web/workspace-layout.ts +10 -0
- package/web/workspace-ui.ts +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {realpathSync} from 'node:fs';
|
|
1
|
+
import {lstatSync, realpathSync} from 'node:fs';
|
|
2
2
|
import type {JobCheckpointEvidence, JobCheckpointTable, JobFileIdentity, JobPlanIdentity, JobSubject, RecordSubject} from './job-contract.ts';
|
|
3
3
|
import {exactObject, jobHash, jobId, jobPath, jobSha} from './job-api.ts';
|
|
4
4
|
import {JobError} from './job-store.ts';
|
|
@@ -81,14 +81,27 @@ export function parseCheckpointTable(bytes: Buffer): JobCheckpointTable {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
/** Exact retained closure reads reuse regular-file, containment and descriptor bounds. */
|
|
84
|
-
export function readCheckpointEvidenceBytes(root: string, file: JobFileIdentity, limit: number
|
|
85
|
-
|
|
84
|
+
export function readCheckpointEvidenceBytes(root: string, file: JobFileIdentity, limit: number,
|
|
85
|
+
refuse: (failure: 'path' | 'limit' | 'hash') => JobError = failure => failure === 'hash'
|
|
86
|
+
? new JobError('JOB_SOURCE_MISMATCH', 'CHECKPOINT_EVIDENCE_HASH_MISMATCH')
|
|
87
|
+
: new JobError('JOB_SOURCE_UNRETAINABLE', 'CHECKPOINT_EVIDENCE_PATH_REFUSED')): Buffer {
|
|
88
|
+
let bytes: Buffer | undefined;
|
|
86
89
|
try {
|
|
87
90
|
if (realpathSync(root) !== root) throw new Error('Noncanonical evidence root');
|
|
88
|
-
|
|
91
|
+
const path = checkedPath(root, jobPath(file.path));
|
|
92
|
+
const before = lstatSync(path);
|
|
93
|
+
if (!before.isFile()) throw new Error('Expected a regular evidence file');
|
|
94
|
+
if (before.size <= limit) {
|
|
95
|
+
bytes = readRegular(path, limit);
|
|
96
|
+
const after = lstatSync(path);
|
|
97
|
+
if (realpathSync(path) !== path || bytes.length !== before.size || before.dev !== after.dev ||
|
|
98
|
+
before.ino !== after.ino || before.size !== after.size || before.mtimeMs !== after.mtimeMs ||
|
|
99
|
+
before.ctimeMs !== after.ctimeMs) throw new Error('Evidence file changed during read');
|
|
100
|
+
}
|
|
89
101
|
}
|
|
90
|
-
catch { throw
|
|
91
|
-
if (
|
|
102
|
+
catch { throw refuse('path'); }
|
|
103
|
+
if (bytes === undefined) throw refuse('limit');
|
|
104
|
+
if (jobHash(bytes) !== file.sha256) throw refuse('hash');
|
|
92
105
|
return bytes;
|
|
93
106
|
}
|
|
94
107
|
|
package/src/job-cli.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import {closeSync, constants, fstatSync, fsyncSync, lstatSync, openSync, readFileSync, renameSync, unlinkSync, writeSync} from 'node:fs';
|
|
3
3
|
import {join} from 'node:path';
|
|
4
|
-
import { JOB_API_SCHEMA, JOB_ACT_SCHEMA, JOB_PARTS_VERDICT_ACT_SCHEMA, JOB_RIG_REVIEW_ACT_SCHEMA, JOB_COMMENTS_ACT_SCHEMA, JOB_ENABLED_ACT_KINDS, jobRawActMediaType, jobStillByteLimit, jobActDeliveryLimit, jobResponseBodyLimit,
|
|
5
|
-
type JobAct, type JobCommentsAct, type JobAgentRequest, type JobNextRequest, type JobNextValue } from './job-contract.ts';
|
|
6
|
-
import { assertJobApiSchema, jobFailure, jobHash, jobId, jobInteger, jobObject, jobWaitLimitMs, parseJobRequest, parseCommentsAct } from './job-api.ts';
|
|
4
|
+
import { JOB_API_SCHEMA, JOB_ACT_SCHEMA, JOB_PARTS_VERDICT_ACT_SCHEMA, JOB_RIG_REVIEW_ACT_SCHEMA, JOB_COMMENTS_ACT_SCHEMA, JOB_MESH_EDITS_ACT_SCHEMA, JOB_ENABLED_ACT_KINDS, jobRawActMediaType, jobStillByteLimit, jobActDeliveryLimit, jobResponseBodyLimit,
|
|
5
|
+
type JobAct, type JobCommentsAct, type JobMeshEditsAct, type JobAgentRequest, type JobNextRequest, type JobNextValue } from './job-contract.ts';
|
|
6
|
+
import { assertJobApiSchema, jobFailure, jobHash, jobId, jobInteger, jobObject, jobWaitLimitMs, parseJobRequest, parseCommentsAct, parseMeshEditsAct } from './job-api.ts';
|
|
7
7
|
import { JobError } from './job-store.ts';
|
|
8
8
|
import {validatePngBytes} from './comment-crops.ts';
|
|
9
9
|
import {destinationDirectory} from './destination-directory.ts';
|
|
@@ -145,15 +145,15 @@ async function consumerBytes(stream: ReadableStream<Uint8Array> | null, maximum:
|
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
type ConsumerAct = JobAct | JobCommentsAct;
|
|
148
|
+
type ConsumerAct = JobAct | JobCommentsAct | JobMeshEditsAct;
|
|
149
149
|
|
|
150
150
|
function parseConsumerAct(bytes: Buffer, job: string, actId: string): ConsumerAct {
|
|
151
151
|
let value: unknown;
|
|
152
152
|
try { value = JSON.parse(new TextDecoder('utf-8', {fatal: true}).decode(bytes)); }
|
|
153
153
|
catch { throw new JobError('JOB_REQUEST_INVALID'); }
|
|
154
154
|
const act = jobObject(value, ['schema', 'actId', 'jobId', 'askId', 'publicationId', 'kind', 'authority', 'at', 'source', 'value', 'still']);
|
|
155
|
-
if (act.schema === JOB_COMMENTS_ACT_SCHEMA) {
|
|
156
|
-
const comments = parseCommentsAct(act);
|
|
155
|
+
if (act.schema === JOB_COMMENTS_ACT_SCHEMA || act.schema === JOB_MESH_EDITS_ACT_SCHEMA) {
|
|
156
|
+
const comments = act.schema === JOB_MESH_EDITS_ACT_SCHEMA ? parseMeshEditsAct(act) : parseCommentsAct(act);
|
|
157
157
|
if (comments.jobId !== job || comments.actId !== actId) throw new JobError('JOB_ACT_INVALID');
|
|
158
158
|
return comments;
|
|
159
159
|
}
|
package/src/job-contract.ts
CHANGED
|
@@ -18,6 +18,7 @@ import type { CompareFeedback, CompareSession } from './compare-session.ts';
|
|
|
18
18
|
import type { MarkRegion } from './stage-comment.ts';
|
|
19
19
|
import type { PartsVerdict } from './parts-view.ts';
|
|
20
20
|
import type { ControlNumericCamera, ControlPart } from './control.ts';
|
|
21
|
+
import type { MeshOp, Vec } from './mesh-edit.ts';
|
|
21
22
|
|
|
22
23
|
export const JOB_API_SCHEMA = 'rig-review/job-api@2' as const;
|
|
23
24
|
export const JOB_API_V3_SCHEMA = 'rig-review/job-api@3' as const;
|
|
@@ -32,6 +33,8 @@ export const JOB_PARTS_VERDICT_ACT_SCHEMA = 'rig-review/act@5' as const;
|
|
|
32
33
|
export const JOB_COMMENTS_ACT_SCHEMA = 'rig-review/act@6' as const;
|
|
33
34
|
/** @6 plus an optional per-comment `context`. Emitted only behind EMIT_UNPINNED_CREATE_FIELDS (#714). */
|
|
34
35
|
export const JOB_COMMENT_CONTEXT_ACT_SCHEMA = 'rig-review/act@7' as const;
|
|
36
|
+
/** @7 plus a mesh payload on a compiled rig's Request changes (#952). */
|
|
37
|
+
export const JOB_MESH_EDITS_ACT_SCHEMA = 'rig-review/act@8' as const;
|
|
35
38
|
export const REVIEW_COMMENTS_SESSION_SCHEMA = 'rig-review-session/2' as const;
|
|
36
39
|
export const REVIEW_COMMENTS_COMPARE_SESSION_SCHEMA = 'rig-review-compare-session/2' as const;
|
|
37
40
|
export const PARTS_COMMENTS_VERDICT_SCHEMA = 'rig-review-parts-verdict/5' as const;
|
|
@@ -96,6 +99,49 @@ export type JobContextCommentsAct = {
|
|
|
96
99
|
readonly value: Omit<JobCommentsActValues[Kind], 'comments'> & { readonly comments: readonly JobContextComment[] };
|
|
97
100
|
}
|
|
98
101
|
}[keyof JobCommentsActValues];
|
|
102
|
+
|
|
103
|
+
export interface JobMeshEditValue {
|
|
104
|
+
readonly slot: string;
|
|
105
|
+
readonly skin: string;
|
|
106
|
+
readonly attachment: string;
|
|
107
|
+
readonly basis: 'setup';
|
|
108
|
+
readonly source: {
|
|
109
|
+
readonly vertexCount: number;
|
|
110
|
+
readonly triangleCount: number;
|
|
111
|
+
readonly hullLength: number;
|
|
112
|
+
/** SHA-256 of JSON.stringify(entry) in the retained model's stored key order. */
|
|
113
|
+
readonly hash: JobSha256;
|
|
114
|
+
readonly frame: {readonly width: number; readonly height: number};
|
|
115
|
+
/** Unrounded displayed setup positions in rig canvas crop px, in source vertex order. */
|
|
116
|
+
readonly positions: readonly Vec[];
|
|
117
|
+
};
|
|
118
|
+
readonly ops: readonly MeshOp[];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export interface JobMeshEdit {
|
|
122
|
+
readonly edit: JobMeshEditValue;
|
|
123
|
+
readonly sha256: JobSha256;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
type JobRigMeshEditsAct = Omit<Extract<JobContextCommentsAct, {kind: 'review-verdict'}>, 'schema' | 'source' | 'value' | 'still'> & {
|
|
127
|
+
readonly schema: typeof JOB_MESH_EDITS_ACT_SCHEMA;
|
|
128
|
+
readonly source: JobRigReviewAct['source'];
|
|
129
|
+
readonly still: JobRigStill;
|
|
130
|
+
readonly value: {
|
|
131
|
+
readonly stage: 'rig-review';
|
|
132
|
+
readonly verdict: 'changes-requested';
|
|
133
|
+
readonly comments: readonly JobContextComment[];
|
|
134
|
+
readonly meshEdits: readonly JobMeshEdit[];
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
/** Decoder grammar for @8, whose writer emits it only when mesh edits are present. */
|
|
139
|
+
export type JobMeshEditsAct = JobRigMeshEditsAct | {
|
|
140
|
+
[Kind in keyof JobCommentsActValues]: Omit<Extract<JobContextCommentsAct, {kind: Kind}>, 'schema' | 'value'> & {
|
|
141
|
+
readonly schema: typeof JOB_MESH_EDITS_ACT_SCHEMA;
|
|
142
|
+
readonly value: Extract<JobContextCommentsAct, {kind: Kind}>['value'] & {readonly meshEdits?: never};
|
|
143
|
+
}
|
|
144
|
+
}[keyof JobCommentsActValues];
|
|
99
145
|
export type ReviewCommentsSession = Omit<ReviewSession, 'schema' | 'feedback' | 'checkpoints'> & {
|
|
100
146
|
schema: typeof REVIEW_COMMENTS_SESSION_SCHEMA;
|
|
101
147
|
checkpoints: Record<string, { outcome: 'pending' | 'pass' | 'fail' }>;
|
|
@@ -193,6 +239,7 @@ export const JOB_RECORD_ACT_KINDS = [
|
|
|
193
239
|
'reopen',
|
|
194
240
|
] as const;
|
|
195
241
|
|
|
242
|
+
/** Standalone asks and acts for these kinds remain disabled. */
|
|
196
243
|
export const JOB_RESERVED_ACT_KINDS = ['described-correction', 'mesh-edit'] as const;
|
|
197
244
|
export type JobEnabledActKind = typeof JOB_ENABLED_ACT_KINDS[number];
|
|
198
245
|
export type RecordActKind = typeof JOB_RECORD_ACT_KINDS[number];
|
|
@@ -208,16 +255,6 @@ export const JOB_PLAN_BOUND_SIGNOFF_STAGES = [
|
|
|
208
255
|
/** Record-only approval stages; not part of the public job-host runtime exports. */
|
|
209
256
|
export const JOB_RECORD_SIGNOFF_STAGES = [...JOB_PLAN_BOUND_SIGNOFF_STAGES, 'direction-review', 'interview'] as const;
|
|
210
257
|
|
|
211
|
-
/** Reserved kinds have no accepted value shape and cannot be asked or submitted.
|
|
212
|
-
* Described correction awaits the joint Create #182 context allowlist.
|
|
213
|
-
* Mesh edit awaits the joint Parts #1159 freeze. Proposal 6ff03ec9 discusses
|
|
214
|
-
* slot/attachment/skin identity, setup basis, vertex/triangle/hull counts and
|
|
215
|
-
* at most 300 closed move/add/remove/edge/unedge operations in crop pixels.
|
|
216
|
-
* The exact attachment bytes behind source.hash and the canonical payload
|
|
217
|
-
* digest replacing delta_sha256 are UNRESOLVED. This contract defines neither.
|
|
218
|
-
* A future submitted mesh act must carry human UI authority, time, exact rig
|
|
219
|
-
* revision/source and recomputable provenance. Drafts are never consumer acts.
|
|
220
|
-
*/
|
|
221
258
|
export const JOB_CONSUMER_AUTH_MODE = 'writer-owned-sibling-fetch-capability' as const;
|
|
222
259
|
|
|
223
260
|
/** Hex digests, opaque IDs/cursors and timestamps require runtime validation.
|
|
@@ -380,6 +417,16 @@ export interface JobPartsIdentity {
|
|
|
380
417
|
}[];
|
|
381
418
|
}
|
|
382
419
|
|
|
420
|
+
export const JOB_PREVIOUS_DRAFT_SCHEMA = 'rig-review-previous-draft/1';
|
|
421
|
+
|
|
422
|
+
/** Publisher-owned accepted draft and work-root-relative seals for its comparison. */
|
|
423
|
+
export interface JobPreviousDraft {
|
|
424
|
+
readonly schema: typeof JOB_PREVIOUS_DRAFT_SCHEMA;
|
|
425
|
+
readonly draft: { readonly id: JobId; readonly revision: JobSha256 };
|
|
426
|
+
readonly composites: { readonly current: JobFileIdentity; readonly previous: JobFileIdentity };
|
|
427
|
+
readonly diff?: JobFileIdentity;
|
|
428
|
+
}
|
|
429
|
+
|
|
383
430
|
export type JobSelector =
|
|
384
431
|
| { readonly kind: 'draft'; readonly id: string }
|
|
385
432
|
| { readonly kind: 'rig'; readonly version: number }
|
|
@@ -391,6 +438,7 @@ export type JobSelector =
|
|
|
391
438
|
*/
|
|
392
439
|
export interface JobModelSourceBinding {
|
|
393
440
|
readonly checkpointEvidence?: readonly JobCheckpointEvidence[];
|
|
441
|
+
readonly previousDraft?: JobPreviousDraft;
|
|
394
442
|
readonly subject?: never;
|
|
395
443
|
readonly sourceHash: JobSha256;
|
|
396
444
|
readonly projectHash: JobSha256 | null;
|
|
@@ -499,11 +547,17 @@ export interface JobActValues {
|
|
|
499
547
|
* supplies checkpoint ID, outcome and words only. Create derives execution
|
|
500
548
|
* stage from its authoritative step phase/order. Review never stamps a stage.
|
|
501
549
|
*/
|
|
502
|
-
export type JobUIActValues = Omit<JobActValues, 'checkpoint' | 'review-verdict'> & {
|
|
550
|
+
export type JobUIActValues = Omit<JobActValues, 'checkpoint' | 'parts-verdict' | 'review-verdict'> & {
|
|
503
551
|
readonly checkpoint: Omit<JobActValues['checkpoint'], 'planStepId'>;
|
|
552
|
+
readonly 'parts-verdict': PartsVerdictValue & {readonly general?: readonly string[]};
|
|
504
553
|
readonly 'review-verdict': JobImageReviewValue
|
|
505
554
|
| (JobModelReviewValue & {readonly stage: 'direction-review'})
|
|
506
|
-
| (JobModelReviewValue & {
|
|
555
|
+
| (JobModelReviewValue & {
|
|
556
|
+
readonly stage: 'rig-review';
|
|
557
|
+
readonly feedback?: readonly Feedback[];
|
|
558
|
+
readonly general?: readonly string[];
|
|
559
|
+
readonly meshEdits?: readonly JobMeshEdit[];
|
|
560
|
+
});
|
|
507
561
|
};
|
|
508
562
|
|
|
509
563
|
export interface JobActSources {
|
|
@@ -571,8 +625,8 @@ export type JobPartsVerdictAct = Omit<Extract<JobLegacyAct, {kind: 'parts-verdic
|
|
|
571
625
|
};
|
|
572
626
|
|
|
573
627
|
/** Historical @2 acts remain readable without being backfilled or relabelled.
|
|
574
|
-
* Fresh checkpoint, parts, rig/post verdict and signoff acts
|
|
575
|
-
export type JobAct = JobLegacyAct | JobRigReviewAct | JobPartsVerdictAct | JobCommentsAct;
|
|
628
|
+
* Fresh checkpoint, parts, rig/post verdict and signoff acts use @6, with @8 gated for mesh edits. */
|
|
629
|
+
export type JobAct = JobLegacyAct | JobRigReviewAct | JobPartsVerdictAct | JobCommentsAct | JobRigMeshEditsAct;
|
|
576
630
|
|
|
577
631
|
/** Authenticated browser provenance. The daemon validates identity and hashes PNG bytes. */
|
|
578
632
|
export interface JobRigCapture {
|
|
@@ -967,6 +1021,17 @@ export type AskRequestV3 = Omit<JobAskRequest, 'schema' | 'subject'> & {
|
|
|
967
1021
|
readonly subject: JobSubject | RecordSubject;
|
|
968
1022
|
};
|
|
969
1023
|
|
|
1024
|
+
/** One request that asks every listed subject of the head record publication (#963). */
|
|
1025
|
+
export type AskBatchRequestV3 = Omit<AskRequestV3, 'verb' | 'subject'> & {
|
|
1026
|
+
readonly verb: 'ask-batch';
|
|
1027
|
+
readonly subjects: readonly (JobSubject | RecordSubject)[];
|
|
1028
|
+
};
|
|
1029
|
+
|
|
1030
|
+
/** `asks[i]` answers `subjects[i]` of the request. */
|
|
1031
|
+
export interface AskBatchValueV3 {
|
|
1032
|
+
readonly asks: readonly PendingAskV3[];
|
|
1033
|
+
}
|
|
1034
|
+
|
|
970
1035
|
export type NextRequestV3 = Omit<JobNextRequest, 'schema'> & {
|
|
971
1036
|
readonly schema: typeof JOB_API_V3_SCHEMA;
|
|
972
1037
|
};
|
|
@@ -978,6 +1043,7 @@ export type CloseRequestV3 = Omit<JobCloseRequest, 'schema'> & {
|
|
|
978
1043
|
export type AgentRequestV3 =
|
|
979
1044
|
| PublishRequestV3
|
|
980
1045
|
| AskRequestV3
|
|
1046
|
+
| AskBatchRequestV3
|
|
981
1047
|
| NextRequestV3
|
|
982
1048
|
| CloseRequestV3;
|
|
983
1049
|
|
|
@@ -1160,11 +1226,13 @@ export type ActV3 = JobAct | RecordAct;
|
|
|
1160
1226
|
export interface JobCapabilitiesV3 extends JobCapabilities {
|
|
1161
1227
|
readonly recordPublication: true;
|
|
1162
1228
|
readonly recordActSchema: typeof JOB_RECORD_ACT_SCHEMA;
|
|
1229
|
+
readonly askBatch: true;
|
|
1163
1230
|
}
|
|
1164
1231
|
|
|
1165
1232
|
export const JOB_CAPABILITIES_V3: JobCapabilitiesV3 = Object.freeze({
|
|
1166
1233
|
recordPublication: true,
|
|
1167
1234
|
recordActSchema: JOB_RECORD_ACT_SCHEMA,
|
|
1235
|
+
askBatch: true,
|
|
1168
1236
|
});
|
|
1169
1237
|
|
|
1170
1238
|
export interface PendingAskV3 extends Omit<JobPendingAsk, 'subject' | 'source'> {
|
|
@@ -1206,6 +1274,7 @@ export interface NextValueV3 {
|
|
|
1206
1274
|
export interface ResponseValuesV3 {
|
|
1207
1275
|
readonly publish: PublicationV3;
|
|
1208
1276
|
readonly ask: PendingAskV3;
|
|
1277
|
+
readonly 'ask-batch': AskBatchValueV3;
|
|
1209
1278
|
readonly next: NextValueV3;
|
|
1210
1279
|
readonly close: { readonly status: 'closed'; readonly cursor: JobCursor | null };
|
|
1211
1280
|
readonly 'fetch-act': ActV3;
|
|
@@ -1229,6 +1298,8 @@ export type JobProjectRecord = ProjectRecord;
|
|
|
1229
1298
|
export type JobRecordFreeze = RecordFreeze;
|
|
1230
1299
|
export type JobPublishRequestV3 = PublishRequestV3;
|
|
1231
1300
|
export type JobAskRequestV3 = AskRequestV3;
|
|
1301
|
+
export type JobAskBatchRequestV3 = AskBatchRequestV3;
|
|
1302
|
+
export type JobAskBatchValueV3 = AskBatchValueV3;
|
|
1232
1303
|
export type JobNextRequestV3 = NextRequestV3;
|
|
1233
1304
|
export type JobCloseRequestV3 = CloseRequestV3;
|
|
1234
1305
|
export type JobAgentRequestV3 = AgentRequestV3;
|
package/src/job-front.ts
CHANGED
|
@@ -5,13 +5,15 @@ import {checkpointEvidenceMetadata, readCheckpointEvidenceBytes} from './job-che
|
|
|
5
5
|
import { JOB_API_SCHEMA, JOB_ACT_SCHEMA, type JobErrorCode, type JobHostPorts, type JobId, type JobPublicationMode, type JobResult, type JobReviewerBinding } from './job-contract.ts';
|
|
6
6
|
import { createJobHostPorts, jobBody, jobHash, jobId, jobObject, jobPartsEnumeratorVersion } from './job-api.ts';
|
|
7
7
|
import { JobSession } from './job-session.ts';
|
|
8
|
-
import { assertJobRoot, assertRetainedSnapshotIntact, captureJobRoot, planTextMetadata, isRetainedRecordSource, loadRetainedJobReview, type JobRootIdentity } from './job-source.ts';
|
|
8
|
+
import { assertJobRoot, assertRetainedSnapshotIntact, captureJobRoot, planTextMetadata, isRetainedRecordSource, loadRetainedJobReview, loadRetainedRecordRig, readPreviousDraftBytes, type JobRootIdentity } from './job-source.ts';
|
|
9
|
+
import { checkedPath } from './interview-project.ts';
|
|
9
10
|
import type { JobWorkerOptions } from './job-worker.ts';
|
|
10
11
|
import { JobError, JobStore, jobCropReferences } from './job-store.ts';
|
|
11
12
|
import { safeFile, packagePath, type ReviewPackage } from './manifest.ts';
|
|
12
13
|
import { serveReference, assertReviewUnchanged } from './reference.ts';
|
|
13
14
|
import {preparePartsComment} from './parts-comment-crops.ts';
|
|
14
|
-
import {
|
|
15
|
+
import type { DifferenceRaster } from './parts-comparison.ts';
|
|
16
|
+
import { loadPartsView, partsViewJson, partsDifference, previousDraftDifference, servedImage, type PartsViewPackage } from './parts-view.ts';
|
|
15
17
|
import { destinationDirectory, DestinationDirectoryError } from './destination-directory.ts';
|
|
16
18
|
import { dirname, extname, isAbsolute, join, relative, sep } from 'node:path';
|
|
17
19
|
import { constants, openSync, closeSync, readSync, fstatSync, lstatSync, statSync, type Stats } from 'node:fs';
|
|
@@ -258,9 +260,60 @@ export function retainedPublicationRoutes(session: JobSession) {
|
|
|
258
260
|
const sealedFile = async (relativePath: string) => {
|
|
259
261
|
const seal = retained.seals.find(file => file.path === relativePath);
|
|
260
262
|
if (!seal) return failure('JOB_SOURCE_UNRETAINABLE', 404);
|
|
263
|
+
let literal: string | undefined;
|
|
264
|
+
if (isRetainedRecordSource(retained)) {
|
|
265
|
+
try {literal = checkedPath(retained.snapshotRoot, relativePath);}
|
|
266
|
+
catch {return failure('JOB_SOURCE_UNRETAINABLE', 404);}
|
|
267
|
+
}
|
|
261
268
|
const file = await safeFile(retained.snapshotRoot, relativePath);
|
|
269
|
+
if (literal !== undefined && literal !== file)
|
|
270
|
+
return failure('JOB_SOURCE_UNRETAINABLE', 404);
|
|
262
271
|
return serveReference(request, file, seal.sha256, headers);
|
|
263
272
|
};
|
|
273
|
+
const reviewMetadata = (review: ReviewPackage | null) => json({
|
|
274
|
+
...checkpointEvidenceMetadata(retained.snapshotRoot, retained.source.checkpointEvidence),
|
|
275
|
+
...(isRetainedRecordSource(retained) ? {recordSource: retained.source} : {}),
|
|
276
|
+
sourceHash: retained.source.sourceHash,
|
|
277
|
+
assetsBase: display.routes.assetsBase,
|
|
278
|
+
...(review ? {
|
|
279
|
+
manifest: review.manifest,
|
|
280
|
+
reviewedSource: review.reviewedSource,
|
|
281
|
+
initialAnimation: null,
|
|
282
|
+
setsHash: review.setsHash,
|
|
283
|
+
direction: review.direction && {...review.direction, ...(retained.source.selector?.kind==='post'?{postVersion:retained.source.selector.version}:{})},
|
|
284
|
+
scene: review.scene,
|
|
285
|
+
referenceHashes: review.referenceHashes,
|
|
286
|
+
sourcePainting: review.sourcePainting && {...review.sourcePainting, url: '/review-painting'},
|
|
287
|
+
} : {}),
|
|
288
|
+
feedbackCatalog: review?.feedbackCatalog ?? {slots: null},
|
|
289
|
+
capabilities: {playback: !!review?.manifest.model,
|
|
290
|
+
interview: questions.length > 0 || (retained.interview?.records.length ?? 0) > 0 ||
|
|
291
|
+
(retained.interview?.diagnostics.length ?? 0) > 0,
|
|
292
|
+
preRig: retained.source.selector?.kind === 'draft', modeling: false, motion: false, feedback: true, audio: false},
|
|
293
|
+
});
|
|
294
|
+
const interviewMetadata = (rigPicture = false) => {
|
|
295
|
+
const interview = isRetainedRecordSource(retained) ? undefined :
|
|
296
|
+
retained.interview !== undefined ? retained.interview : display.publication.interview;
|
|
297
|
+
return json({
|
|
298
|
+
questions: questions.map(question => ({...question,
|
|
299
|
+
...(rigPicture && question.missingPicture === 'rig' ? {missingPicture: undefined} : {}),
|
|
300
|
+
images: question.images.map((image, index) => ({name: image.name,
|
|
301
|
+
url: `/api/interview/image/${question.ref.sha256}/${index}`})),
|
|
302
|
+
})),
|
|
303
|
+
...(interview === undefined ? {} : {interview}),
|
|
304
|
+
});
|
|
305
|
+
};
|
|
306
|
+
const interview = /^api\/interview\/image\/([a-f0-9]{64})\/(0|[1-9]\d*)$/.exec(path);
|
|
307
|
+
const interviewImage = (match: RegExpExecArray) => {
|
|
308
|
+
const image = retained.questions.find(question => question.ref.sha256 === match[1])?.images[Number(match[2])];
|
|
309
|
+
return image ? sealedFile(image.ref.path) : failure('JOB_SOURCE_UNRETAINABLE', 404);
|
|
310
|
+
};
|
|
311
|
+
const reviewAsset = (review: ReviewPackage | null) => {
|
|
312
|
+
if (!review) return failure('JOB_SOURCE_UNRETAINABLE', 404);
|
|
313
|
+
const asset = packagePath(decodeURIComponent(path.slice('assets/'.length)));
|
|
314
|
+
if (!review.files.has(asset)) return failure('JOB_SOURCE_UNRETAINABLE', 404);
|
|
315
|
+
return sealedFile(relative(retained.snapshotRoot, join(review.root, asset)).split('\\').join('/'));
|
|
316
|
+
};
|
|
264
317
|
const evidenceRoute = /^api\/checkpoint-evidence\/([A-Za-z0-9][A-Za-z0-9._-]*)\/(table|tiles\/(0|[1-9]\d*))$/.exec(path);
|
|
265
318
|
if (evidenceRoute) {
|
|
266
319
|
const packet = retained.source.checkpointEvidence?.find(item => item.checkpointId === evidenceRoute[1]);
|
|
@@ -296,36 +349,22 @@ export function retainedPublicationRoutes(session: JobSession) {
|
|
|
296
349
|
const file = servedImage(parts, image[1] as 'image'|'page', Number(image[2]));
|
|
297
350
|
return file ? await sealedFile(relative(retained.snapshotRoot,file).split('\\').join('/')) : failure('JOB_SOURCE_UNRETAINABLE',404);
|
|
298
351
|
}
|
|
299
|
-
if (path === 'api/review') {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
},
|
|
314
|
-
feedbackCatalog: {slots: null},
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
if (path === 'api/interview') {
|
|
318
|
-
return json({questions: questions.map(question => ({...question,
|
|
319
|
-
images: question.images.map((image, index) => ({name: image.name,
|
|
320
|
-
url: `/api/interview/image/${question.ref.sha256}/${index}`})),
|
|
321
|
-
}))});
|
|
322
|
-
}
|
|
323
|
-
const interview = /^api\/interview\/image\/([a-f0-9]{64})\/(0|[1-9]\d*)$/.exec(path);
|
|
324
|
-
if (interview) {
|
|
325
|
-
const image = retained.questions.find(question => question.ref.sha256 === interview[1])?.images[Number(interview[2])];
|
|
326
|
-
if (!image) return failure('JOB_SOURCE_UNRETAINABLE', 404);
|
|
327
|
-
return await sealedFile(image.ref.path);
|
|
352
|
+
if (path === 'api/review' || path === 'api/interview' || path.startsWith('assets/')) {
|
|
353
|
+
let review: ReviewPackage | null = null;
|
|
354
|
+
if (!question) {
|
|
355
|
+
let pending = views.get(publicationId);
|
|
356
|
+
if (!pending) {
|
|
357
|
+
pending = loadRetainedRecordRig(retained).then(review => ({review, parts: null}));
|
|
358
|
+
views.set(publicationId, pending);
|
|
359
|
+
}
|
|
360
|
+
({review} = await pending);
|
|
361
|
+
}
|
|
362
|
+
if (path === 'api/review') return reviewMetadata(review);
|
|
363
|
+
if (path === 'api/interview') return interviewMetadata(!!review);
|
|
364
|
+
try {return await reviewAsset(review);}
|
|
365
|
+
catch {return failure('JOB_SOURCE_UNRETAINABLE', 404);}
|
|
328
366
|
}
|
|
367
|
+
if (interview) return await interviewImage(interview);
|
|
329
368
|
return failure('JOB_REQUEST_INVALID', 404);
|
|
330
369
|
}
|
|
331
370
|
let pending = views.get(publicationId);
|
|
@@ -368,43 +407,9 @@ export function retainedPublicationRoutes(session: JobSession) {
|
|
|
368
407
|
if (retained.checkpointEvidencePackageHash !== undefined && retained.checkpointEvidencePackageHash !== review.sourceHash) {
|
|
369
408
|
throw new JobError('JOB_SOURCE_MISMATCH');
|
|
370
409
|
}
|
|
371
|
-
if (path === 'api/review')
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
manifest: review.manifest,
|
|
375
|
-
sourceHash: retained.source.sourceHash,
|
|
376
|
-
reviewedSource: review.reviewedSource,
|
|
377
|
-
initialAnimation: null,
|
|
378
|
-
setsHash: review.setsHash,
|
|
379
|
-
direction: review.direction && {...review.direction, ...(retained.source.selector?.kind==='post'?{postVersion:retained.source.selector.version}:{})},
|
|
380
|
-
scene: review.scene,
|
|
381
|
-
referenceHashes: review.referenceHashes,
|
|
382
|
-
sourcePainting: review.sourcePainting && {...review.sourcePainting, url: '/review-painting'},
|
|
383
|
-
feedbackCatalog: review.feedbackCatalog,
|
|
384
|
-
assetsBase: display.routes.assetsBase,
|
|
385
|
-
capabilities: {playback: !!review.manifest.model,
|
|
386
|
-
interview: retained.questions.length > 0 ||
|
|
387
|
-
(retained.interview?.records.length ?? 0) > 0 ||
|
|
388
|
-
(retained.interview?.diagnostics.length ?? 0) > 0,
|
|
389
|
-
preRig: retained.source.selector?.kind === 'draft', modeling: false, motion: false, feedback: true, audio: false},
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
|
-
if (path === 'api/interview') {
|
|
393
|
-
const interview = retained.interview !== undefined ? retained.interview : display.publication.interview;
|
|
394
|
-
return json({
|
|
395
|
-
questions: questions.map(question => ({...question,
|
|
396
|
-
images: question.images.map((image, index) => ({name: image.name,
|
|
397
|
-
url: `/api/interview/image/${question.ref.sha256}/${index}`})),
|
|
398
|
-
})),
|
|
399
|
-
...(interview === undefined ? {} : {interview}),
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
const interview = /^api\/interview\/image\/([a-f0-9]{64})\/(0|[1-9]\d*)$/.exec(path);
|
|
403
|
-
if (interview) {
|
|
404
|
-
const image = retained.questions.find(question => question.ref.sha256 === interview[1])?.images[Number(interview[2])];
|
|
405
|
-
if (!image) return failure('JOB_SOURCE_UNRETAINABLE', 404);
|
|
406
|
-
return await sealedFile(image.ref.path);
|
|
407
|
-
}
|
|
410
|
+
if (path === 'api/review') return reviewMetadata(review);
|
|
411
|
+
if (path === 'api/interview') return interviewMetadata();
|
|
412
|
+
if (interview) return await interviewImage(interview);
|
|
408
413
|
if (crop) {
|
|
409
414
|
if (!parts) return failure('JOB_SOURCE_UNRETAINABLE', 409);
|
|
410
415
|
if (request.headers.get('origin') !== new URL(request.url).origin)
|
|
@@ -417,7 +422,9 @@ export function retainedPublicationRoutes(session: JobSession) {
|
|
|
417
422
|
assertRetainedSnapshotIntact(retained.snapshotRoot, retained.seals);
|
|
418
423
|
let comment;
|
|
419
424
|
try {
|
|
420
|
-
comment = await preparePartsComment(parts, raw, false, {
|
|
425
|
+
comment = await preparePartsComment(parts, raw, false, {
|
|
426
|
+
sourceHash: retained.source.sourceHash, previousDraft: retained.source.previousDraft,
|
|
427
|
+
});
|
|
421
428
|
} catch (error) {
|
|
422
429
|
if (error instanceof JobError ||
|
|
423
430
|
error instanceof Error && error.message.startsWith('PARTS_COMMENT_STALE_SOURCE:')) throw error;
|
|
@@ -430,16 +437,34 @@ export function retainedPublicationRoutes(session: JobSession) {
|
|
|
430
437
|
}
|
|
431
438
|
if (path === 'api/stage-parts') {
|
|
432
439
|
if (!parts) return failure('JOB_SOURCE_UNRETAINABLE', 409);
|
|
433
|
-
return json({...partsViewJson(parts, {verdict: null, stale: null}), sourceHash: retained.source.sourceHash,
|
|
440
|
+
return json({...partsViewJson(parts, {verdict: null, stale: null}, retained.source.previousDraft?.draft), sourceHash: retained.source.sourceHash,
|
|
434
441
|
inspectionSourceHash: retained.source.sourceHash, readOnly: true});
|
|
435
442
|
}
|
|
436
443
|
const difference=/^api\/stage-parts\/difference\/(0|[1-9]\d*)$/.exec(path);
|
|
437
444
|
if(difference&&parts){
|
|
438
|
-
const
|
|
445
|
+
const query=new URL(request.url).searchParams,threshold=query.get('threshold'),footprints=query.get('footprints');
|
|
446
|
+
const operand=query.get('operand');
|
|
439
447
|
if(!threshold||!/^\d{1,3}$/.test(threshold)||!['true','false'].includes(footprints??''))return failure('JOB_REQUEST_INVALID',400);
|
|
448
|
+
// The existing route's 0 address plus this operand names the whole canvas.
|
|
449
|
+
if(operand!==null&&(operand!=='previous-draft'||difference[1]!=='0'||footprints!=='false'||query.size!==3))
|
|
450
|
+
return failure('JOB_REQUEST_INVALID',400);
|
|
440
451
|
try {
|
|
441
|
-
const
|
|
442
|
-
|
|
452
|
+
const previous=operand==='previous-draft'?retained.source.previousDraft:undefined;
|
|
453
|
+
if(operand!==null&&!previous)return failure('PARTS_DIFFERENCE_UNAVAILABLE',400);
|
|
454
|
+
const responseHeaders:Record<string,string>={...headers,'Content-Type':'image/png'};
|
|
455
|
+
let raster:DifferenceRaster;
|
|
456
|
+
if(previous){
|
|
457
|
+
raster=previousDraftDifference(parts,readPreviousDraftBytes(retained.snapshotRoot,previous.composites.current,'current'),
|
|
458
|
+
readPreviousDraftBytes(retained.snapshotRoot,previous.composites.previous,'previous'),Number(threshold));
|
|
459
|
+
}else{
|
|
460
|
+
const painting=await partsDifference(parts,Number(difference[1]),Number(threshold),footprints==='true');
|
|
461
|
+
raster=painting;
|
|
462
|
+
responseHeaders['X-Difference-Count']=String(painting.count);
|
|
463
|
+
responseHeaders['X-Difference-Covered']=String(painting.covered);
|
|
464
|
+
responseHeaders['X-Difference-Compared']=String(painting.compared);
|
|
465
|
+
}
|
|
466
|
+
const png=new PNG({width:raster.width,height:raster.height});png.data=Buffer.from(raster.data);
|
|
467
|
+
return new Response(request.method==='HEAD'?null:new Uint8Array(PNG.sync.write(png)),{headers:responseHeaders});
|
|
443
468
|
} catch (error) {
|
|
444
469
|
const code = error instanceof Error ? /^(PARTS_DIFFERENCE_UNAVAILABLE|PARTS_DIFFERENCE_PNG):/.exec(error.message)?.[1] : undefined;
|
|
445
470
|
if (code) return failure(code, 400);
|
|
@@ -455,11 +480,7 @@ export function retainedPublicationRoutes(session: JobSession) {
|
|
|
455
480
|
if (path === 'review-painting' && review.sourcePainting && review.handoff?.source) {
|
|
456
481
|
return await sealedFile(relative(retained.snapshotRoot, review.handoff.source).split('\\').join('/'));
|
|
457
482
|
}
|
|
458
|
-
if (path.startsWith('assets/'))
|
|
459
|
-
const asset = packagePath(decodeURIComponent(path.slice('assets/'.length)));
|
|
460
|
-
if (!review.files.has(asset)) return failure('JOB_SOURCE_UNRETAINABLE', 404);
|
|
461
|
-
return await sealedFile(relative(retained.snapshotRoot, join(review.root, asset)).split('\\').join('/'));
|
|
462
|
-
}
|
|
483
|
+
if (path.startsWith('assets/')) return await reviewAsset(review);
|
|
463
484
|
return failure('JOB_REQUEST_INVALID', 404);
|
|
464
485
|
});
|
|
465
486
|
} catch (error) {
|
|
@@ -467,6 +488,7 @@ export function retainedPublicationRoutes(session: JobSession) {
|
|
|
467
488
|
error instanceof Error && error.message.startsWith('PARTS_COMMENT_STALE_SOURCE:')
|
|
468
489
|
? 'PARTS_COMMENT_STALE_SOURCE' : 'JOB_SOURCE_MISMATCH';
|
|
469
490
|
const message = error instanceof JobError && (/^(CHECKPOINT_EVIDENCE|PLAN_TEXT)_[A-Z_]+$/.test(error.message) ||
|
|
491
|
+
/^PREVIOUS_DRAFT_[A-Z_]+(?: |$)/.test(error.message) ||
|
|
470
492
|
error.code === 'JOB_SOURCE_UNRETAINABLE' && error.message.startsWith('snapshot reload '))
|
|
471
493
|
? error.message : undefined;
|
|
472
494
|
return failure(code, errorStatus[code as JobErrorCode] ?? 409, undefined, message);
|
package/src/job-host.ts
CHANGED
|
@@ -21,19 +21,20 @@ export type {
|
|
|
21
21
|
JobRootIdentity,
|
|
22
22
|
} from './job-source.ts';
|
|
23
23
|
export {parseRecordAct} from './job-api.ts';
|
|
24
|
-
export {parseCommentsAct, parseContextCommentsAct} from './job-api.ts';
|
|
24
|
+
export {parseCommentsAct, parseContextCommentsAct, parseMeshEditsAct} from './job-api.ts';
|
|
25
25
|
export {projectComments} from './stage-comment.ts';
|
|
26
26
|
export {parseCommentsSession} from './session.ts';
|
|
27
27
|
export {parseCommentsCompareSession} from './compare-session.ts';
|
|
28
28
|
export {parseCommentsPartsVerdict} from './parts-view.ts';
|
|
29
29
|
export {projectSelectedCommentsFeedback} from './feedback-export.ts';
|
|
30
30
|
export {
|
|
31
|
-
JOB_COMMENTS_ACT_SCHEMA, JOB_COMMENT_CONTEXT_ACT_SCHEMA, REVIEW_COMMENTS_SESSION_SCHEMA,
|
|
31
|
+
JOB_COMMENTS_ACT_SCHEMA, JOB_COMMENT_CONTEXT_ACT_SCHEMA, JOB_MESH_EDITS_ACT_SCHEMA, REVIEW_COMMENTS_SESSION_SCHEMA,
|
|
32
32
|
REVIEW_COMMENTS_COMPARE_SESSION_SCHEMA, PARTS_COMMENTS_VERDICT_SCHEMA,
|
|
33
33
|
} from './job-contract.ts';
|
|
34
34
|
export type {
|
|
35
35
|
JobComment, JobCommentAnchor, JobCommentFeedbackAnchor, JobCommentPartsAnchor, JobCommentImageAnchor,
|
|
36
36
|
JobCommentsAct, JobCommentsActValues, ReviewCommentsSession,
|
|
37
|
+
JobMeshEditValue, JobMeshEdit, JobMeshEditsAct,
|
|
37
38
|
JobCommentContext, JobContextComment, JobContextCommentsAct, CompareCommentsSession, PartsCommentsVerdict,
|
|
38
39
|
} from './job-contract.ts';
|
|
39
40
|
export {prepareJobRecordAct} from './job-act.ts';
|
|
@@ -45,6 +46,7 @@ export {
|
|
|
45
46
|
JOB_RECORD_ACT_SCHEMA,
|
|
46
47
|
JOB_RECORD_READER_ID,
|
|
47
48
|
JOB_PARTS_ENUMERATOR_RANGE,
|
|
49
|
+
JOB_PREVIOUS_DRAFT_SCHEMA,
|
|
48
50
|
JOB_ENABLED_ACT_KINDS,
|
|
49
51
|
JOB_RESERVED_ACT_KINDS,
|
|
50
52
|
JOB_PLAN_BOUND_SIGNOFF_STAGES,
|
|
@@ -55,6 +57,8 @@ export type {
|
|
|
55
57
|
ActV3,
|
|
56
58
|
AgentRequestV3,
|
|
57
59
|
ApiResponseV3,
|
|
60
|
+
AskBatchRequestV3,
|
|
61
|
+
AskBatchValueV3,
|
|
58
62
|
AskRequestV3,
|
|
59
63
|
CloseRequestV3,
|
|
60
64
|
DisplayPublicationV3,
|
|
@@ -77,6 +81,7 @@ export type {
|
|
|
77
81
|
JobPartsManifestPath,
|
|
78
82
|
JobPartImagePath,
|
|
79
83
|
JobPartsIdentity,
|
|
84
|
+
JobPreviousDraft,
|
|
80
85
|
JobPartsRole,
|
|
81
86
|
JobPartsFileReference,
|
|
82
87
|
JobPartsEnumerator,
|
|
@@ -119,6 +124,8 @@ export type {
|
|
|
119
124
|
JobPublishRequestV3,
|
|
120
125
|
JobAskRequest,
|
|
121
126
|
JobAskRequestV3,
|
|
127
|
+
JobAskBatchRequestV3,
|
|
128
|
+
JobAskBatchValueV3,
|
|
122
129
|
JobNextRequest,
|
|
123
130
|
JobNextRequestV3,
|
|
124
131
|
JobCloseRequest,
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {exactObject, jobId, jobSha, parseFileRow} from './job-api.ts';
|
|
2
|
+
import {JOB_PREVIOUS_DRAFT_SCHEMA, type JobFileIdentity, type JobPreviousDraft, type JobSelector} from './job-contract.ts';
|
|
3
|
+
import {JobError} from './job-store.ts';
|
|
4
|
+
|
|
5
|
+
function parsePreviousDraft(value: unknown): JobPreviousDraft {
|
|
6
|
+
try {
|
|
7
|
+
const item = exactObject(value, ['schema', 'draft', 'composites'], 'JOB_SOURCE_MISMATCH', ['diff']);
|
|
8
|
+
if (item.schema !== JOB_PREVIOUS_DRAFT_SCHEMA) throw new Error('schema');
|
|
9
|
+
const draft = exactObject(item.draft, ['id', 'revision'], 'JOB_SOURCE_MISMATCH');
|
|
10
|
+
const composites = exactObject(item.composites, ['current', 'previous'], 'JOB_SOURCE_MISMATCH');
|
|
11
|
+
return {schema: JOB_PREVIOUS_DRAFT_SCHEMA, draft: {id: jobId(draft.id), revision: jobSha(draft.revision)},
|
|
12
|
+
composites: {current: parseFileRow(composites.current, 'JOB_SOURCE_MISMATCH'),
|
|
13
|
+
previous: parseFileRow(composites.previous, 'JOB_SOURCE_MISMATCH')},
|
|
14
|
+
...('diff' in item ? {diff: parseFileRow(item.diff, 'JOB_SOURCE_MISMATCH')} : {})};
|
|
15
|
+
} catch {
|
|
16
|
+
throw new JobError('JOB_SOURCE_MISMATCH', 'PREVIOUS_DRAFT_INVALID');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** The decoder checks the declaration. Admission additionally supplies the actual files closure. */
|
|
21
|
+
export function previousDraftFields(holder: object, selector: JobSelector | null,
|
|
22
|
+
files?: readonly JobFileIdentity[]): {previousDraft?: JobPreviousDraft} {
|
|
23
|
+
if (!('previousDraft' in holder)) return {};
|
|
24
|
+
if (selector?.kind !== 'draft') throw new JobError('JOB_SOURCE_MISMATCH', 'PREVIOUS_DRAFT_SELECTOR');
|
|
25
|
+
const previousDraft = parsePreviousDraft(holder.previousDraft);
|
|
26
|
+
if (previousDraft.draft.id === selector.id) throw new JobError('JOB_SOURCE_MISMATCH', 'PREVIOUS_DRAFT_SELF');
|
|
27
|
+
if (Buffer.byteLength(JSON.stringify(previousDraft)) > 4096) {
|
|
28
|
+
throw new JobError('JOB_SOURCE_UNRETAINABLE', 'PREVIOUS_DRAFT_LIMIT operand=declaration');
|
|
29
|
+
}
|
|
30
|
+
const operands = {...previousDraft.composites, diff: previousDraft.diff};
|
|
31
|
+
for (const [operand, file] of Object.entries(operands)) {
|
|
32
|
+
if (file && files && !files.some(seal => seal.path === file.path && seal.sha256 === file.sha256)) {
|
|
33
|
+
throw new JobError('JOB_SOURCE_MISMATCH', `PREVIOUS_DRAFT_UNSEALED operand=${operand}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return {previousDraft};
|
|
37
|
+
}
|