rig-review 3.7.0 → 4.0.1
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 +3 -3
- package/docs/DESIGN.md +145 -74
- package/docs/PANELS.md +20 -12
- package/docs/PARTS_VIEW.md +133 -76
- package/docs/REVIEW_PACKAGE.md +446 -100
- package/docs/STABILITY.md +132 -198
- package/docs/WORKFLOWS.md +41 -120
- package/package.json +4 -3
- package/skills/rig-review/SKILL.md +41 -27
- package/src/build.ts +10 -2
- package/src/cli.ts +17 -16
- package/src/comment-crops.ts +6 -1
- package/src/compare-html.ts +22 -24
- package/src/compare-server.ts +1 -1
- package/src/compare-session.ts +41 -3
- package/src/correction-handoff.ts +27 -4
- package/src/create-pin-gate.ts +3 -0
- package/src/direction-inspection.ts +6 -2
- package/src/feedback-export.ts +68 -1
- package/src/front.ts +5 -200
- package/src/handoff.ts +1 -1
- package/src/interview-routes.ts +1 -1
- package/src/interview-scene.ts +3 -3
- package/src/job-act.ts +77 -73
- package/src/job-api.ts +326 -13
- package/src/job-checkpoint-evidence.ts +113 -0
- package/src/job-cli.ts +27 -14
- package/src/job-contract.ts +284 -62
- package/src/job-front.ts +192 -61
- package/src/job-host.ts +23 -4
- package/src/job-session.ts +109 -24
- package/src/job-source.ts +227 -58
- package/src/job-store.ts +80 -6
- package/src/job-worker.ts +1 -47
- package/src/joined-project.ts +61 -4
- package/src/manifest.ts +32 -4
- package/src/open-workspace.ts +12 -12
- package/src/open.ts +19 -12
- package/src/parts-comment-crops.ts +126 -31
- package/src/parts-comment.ts +351 -28
- package/src/parts-server.ts +19 -7
- package/src/parts-view.ts +588 -109
- package/src/scene-inspection.ts +50 -0
- package/src/server.ts +31 -22
- package/src/session.ts +58 -0
- package/src/stage-comment.ts +48 -1
- package/src/stage-parts.ts +23 -11
- package/web/animation-inspection.ts +1 -1
- package/web/bones-panel.ts +1 -3
- package/web/catalog-en.ts +175 -39
- package/web/catalog-ko.ts +175 -39
- package/web/cloth-panel.ts +1 -2
- package/web/compare.css +3 -13
- package/web/compare.html +3 -3
- package/web/compare.ts +69 -64
- package/web/cuts-panel.ts +1 -3
- package/web/density-strip-panel.ts +1 -2
- package/web/direction-panel.ts +22 -6
- package/web/i18n.ts +13 -1
- package/web/idle-panel.ts +1 -2
- package/web/index.html +1 -5
- package/web/inspection-persistence.ts +2 -1
- package/web/inspector-blocks.ts +149 -40
- package/web/instance-access.ts +24 -5
- package/web/interview-panel.ts +224 -175
- package/web/job-rig-capture.ts +164 -21
- package/web/job-rig-screen.ts +344 -0
- package/web/job-session.ts +611 -1443
- package/web/main.ts +614 -151
- package/web/mesh-panel.ts +1 -2
- package/web/owner-workspace.ts +88 -109
- package/web/part-selection.ts +47 -6
- package/web/part-thumbnails.ts +20 -6
- package/web/parts-render.ts +26 -19
- package/web/parts-viewport-provider.ts +181 -7
- package/web/physics-panel.ts +1 -2
- package/web/readings-panel.ts +1 -2
- package/web/requirements-panel.ts +1 -3
- package/web/retained-frame-stage.ts +105 -0
- package/web/retarget-panel.ts +2 -3
- package/web/rig-fields-panel.ts +1 -2
- package/web/rig-host.ts +64 -0
- package/web/rig-viewport-provider.ts +65 -16
- package/web/scene-plates.ts +57 -4
- package/web/stage-comments.ts +103 -46
- package/web/styles.css +117 -63
- package/web/view-controls.ts +201 -12
- package/web/viewport-capture.ts +12 -2
- package/web/viewport-controller.ts +107 -27
- package/web/viewport-pair.ts +2 -1
- package/web/workspace-preferences.ts +5 -4
- package/web/workspace-ui.ts +151 -19
- package/src/front-worker.ts +0 -2
- package/src/interview-server.ts +0 -54
- package/src/job-hub.ts +0 -304
- package/src/job-image-set.ts +0 -50
- package/web/interview.css +0 -28
- package/web/interview.html +0 -17
- package/web/interview.ts +0 -40
- package/web/job-hub.css +0 -14
- package/web/job-hub.html +0 -5
- package/web/job-hub.ts +0 -179
- package/web/owner-workspace.css +0 -14
- package/web/owner-workspace.html +0 -5
- package/web/parts-flags.ts +0 -48
- package/web/parts.css +0 -104
- package/web/parts.html +0 -49
- package/web/parts.ts +0 -604
- package/web/stage-nav.ts +0 -136
package/web/job-rig-capture.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import {CanvasRenderer, RigPlayer, type ModelAssets, type PosedFrame} from '@rig-c/play';
|
|
2
|
+
import {assertOriginalPaintingSize} from '../src/parts-comparison.ts';
|
|
2
3
|
import {jobStillByteLimit, type JobRigCapture, type JobUISubmission} from '../src/job-contract.ts';
|
|
3
|
-
import
|
|
4
|
+
import {cameraFrame} from './camera-view.ts';
|
|
5
|
+
import {partBounds} from './part-selection.ts';
|
|
6
|
+
import type {ControlNumericCamera} from '../src/control.ts';
|
|
7
|
+
import {paintPosedViewport, presentJobRigViewport, type JobRigPresentation} from './viewport-capture.ts';
|
|
4
8
|
|
|
5
9
|
type DrawSource = Pick<JobRigCapture['binding'], 'publicationId' | 'instanceKey' | 'sourceHash' | 'pageId'>;
|
|
6
10
|
export interface JobRigDrawState {
|
|
@@ -40,6 +44,36 @@ const sourceKey = (source: DrawSource) => JSON.stringify([
|
|
|
40
44
|
source.publicationId, source.instanceKey, source.sourceHash, source.pageId,
|
|
41
45
|
]);
|
|
42
46
|
|
|
47
|
+
/** Native original-art comparison needs the declared canvas, never a fitted viewport or inferred bounds. */
|
|
48
|
+
export function rigRestCanvas(assets: Pick<ModelAssets, 'stage'>, painting: {width: number; height: number}) {
|
|
49
|
+
const stage = assets.stage;
|
|
50
|
+
assertOriginalPaintingSize(painting.width, painting.height, stage ? [stage.width, stage.height] : null, 1);
|
|
51
|
+
if (!stage || !Number.isSafeInteger(stage.x) || !Number.isSafeInteger(stage.y) ||
|
|
52
|
+
stage.width > 16384 || stage.height > 16384 || stage.width * stage.height > 16777216) {
|
|
53
|
+
throw new Error('PARTS_PAINTING_MAPPING: declared rig_size and positive scale_rig_per_source required');
|
|
54
|
+
}
|
|
55
|
+
return {x: stage.x, y: stage.y, width: stage.width, height: stage.height};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Standalone Setup operand. A fresh public player has no animation, slot filter, previews or environment history.
|
|
59
|
+
* This is deliberately separate from freezing the displayed job bitmap: its fixed-camera and binding guards stay intact. */
|
|
60
|
+
export function captureRigRestStill(assets: ModelAssets, painting: {width: number; height: number}): HTMLCanvasElement {
|
|
61
|
+
const viewport = rigRestCanvas(assets, painting), root = document.createElement('div');
|
|
62
|
+
const player = new RigPlayer(root, assets, {mode: 'canvas'});
|
|
63
|
+
try {
|
|
64
|
+
const renderer = player.renderer;
|
|
65
|
+
if (!(renderer instanceof CanvasRenderer)) throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
66
|
+
// Public clear(0) holds Setup even on a model without animations or sets. No clip is played.
|
|
67
|
+
renderer.viewport = viewport; renderer.pixelRatio = 1;
|
|
68
|
+
player.clear(0); player.draw();
|
|
69
|
+
const frame = player.posedFrame();
|
|
70
|
+
if (renderer.backendActive === 'canvas2d' && frame.order.some(row => row.tint.slice(0, 3).some(c => c !== 1) || row.dark?.some(c => c !== 0))) {
|
|
71
|
+
throw new Error('COMMENT_CAPTURE_UNAVAILABLE: Canvas2D cannot reproduce active RGB/dark tint');
|
|
72
|
+
}
|
|
73
|
+
return copyRigBitmap(renderer.canvas, viewport.width, viewport.height);
|
|
74
|
+
} finally {player.dispose();}
|
|
75
|
+
}
|
|
76
|
+
|
|
43
77
|
/** Bind local placement and physical-pixel phase while allowing whole-pixel page movement. */
|
|
44
78
|
export function jobRigPixelPlacement(pane: Pick<DOMRect, 'left' | 'top'>,
|
|
45
79
|
canvas: Pick<DOMRect, 'left' | 'top'>, ratio: number) {
|
|
@@ -123,8 +157,8 @@ export function recordJobRigDraw(state: JobRigDrawState, drawGeneration: number)
|
|
|
123
157
|
/** copy() runs synchronously. The returned encoder owns an already copied bitmap. */
|
|
124
158
|
export function freezeJobRigCapture(draw: JobRigDraw | undefined, state: JobRigDrawState, askId: string,
|
|
125
159
|
copy: () => JobRigPixels): FrozenJobRigCapture {
|
|
126
|
-
if (!state.defaultCamera) throw new Error('
|
|
127
|
-
if (!state.wholeRig
|
|
160
|
+
if (!state.defaultCamera) throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
161
|
+
if (!state.wholeRig) throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
128
162
|
if (!draw || typeof state.player.entry !== 'function') throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
129
163
|
if (draw.animation !== null && !draw.animation) throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
130
164
|
if (!matchesDrawState(draw, state)) {
|
|
@@ -153,14 +187,64 @@ export function freezeJobRigCapture(draw: JobRigDraw | undefined, state: JobRigD
|
|
|
153
187
|
}};
|
|
154
188
|
}
|
|
155
189
|
|
|
156
|
-
/**
|
|
157
|
-
export function
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
190
|
+
/** Conservative PNG budget includes raw RGBA, row filters and deflate overhead. */
|
|
191
|
+
export function jobRigStillSize(requestedWidth:number,requestedHeight:number) {
|
|
192
|
+
if(![requestedWidth,requestedHeight].every(n=>Number.isFinite(n)&&n>0))throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
193
|
+
const scale=Math.min(1,16384/requestedWidth,16384/requestedHeight,
|
|
194
|
+
Math.sqrt((jobStillByteLimit-65536)/5/(requestedWidth*requestedHeight)));
|
|
195
|
+
return {width:Math.max(1,Math.floor(requestedWidth*scale)),height:Math.max(1,Math.floor(requestedHeight*scale)),scale};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** Fixed whole-rig evidence from the held public pose; never mutates the inspection player or DOM. */
|
|
199
|
+
export function freezeJobRigStage(stage: Pick<JobRigStage, 'pane'|'player'|'playing'|'source'> &
|
|
200
|
+
{readonly assets:ModelAssets|null}, askId:string, drawGeneration:number):FrozenJobRigCapture {
|
|
201
|
+
const {player,assets}=stage;
|
|
202
|
+
if(!assets)throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
203
|
+
const posed=player.posedFrame(null),bounds=posed.order.map(row=>partBounds(posed,row.slot)).filter(box=>box!==null);
|
|
204
|
+
const declared=assets.stage;
|
|
205
|
+
if(declared&&declared.width>0&&declared.height>0)bounds.push(declared);
|
|
206
|
+
if(!bounds.length)throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
207
|
+
const x=Math.min(...bounds.map(b=>b.x)),y=Math.min(...bounds.map(b=>b.y));
|
|
208
|
+
const box={x,y,width:Math.max(...bounds.map(b=>b.x+b.width))-x,height:Math.max(...bounds.map(b=>b.y+b.height))-y};
|
|
209
|
+
const ratio=globalThis.devicePixelRatio||1;
|
|
210
|
+
const requestedWidth=Math.max(1,stage.pane.clientWidth||stage.pane.parentElement?.clientWidth||800)*ratio;
|
|
211
|
+
const requestedHeight=Math.max(1,stage.pane.clientHeight||stage.pane.parentElement?.clientHeight||800)*ratio;
|
|
212
|
+
// RGBA plus PNG scanline/deflate overhead fits the unchanged byte cap even for incompressible pixels.
|
|
213
|
+
const {width,height,scale}=jobRigStillSize(requestedWidth,requestedHeight);
|
|
214
|
+
const frame=cameraFrame('world',box,width,height,28*ratio*scale,58*ratio*scale);
|
|
215
|
+
if(!frame)throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
216
|
+
const visible={x:frame.center.x-width/frame.baseScale/2,y:frame.center.y-height/frame.baseScale/2,
|
|
217
|
+
width:width/frame.baseScale,height:height/frame.baseScale};
|
|
218
|
+
const camera:ControlNumericCamera={space:'world',center:frame.center,zoom:1,viewport:{width,height},visible};
|
|
219
|
+
const canvas=document.createElement('canvas');canvas.width=width;canvas.height=height;
|
|
220
|
+
const context=canvas.getContext('2d');if(!context)throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
221
|
+
const renderer=player.renderer;
|
|
222
|
+
const backend=renderer instanceof CanvasRenderer?renderer.backendActive:renderer.meshBackendActive;
|
|
223
|
+
const presentation={canvas,width,height,ratio:1,area:{x:0,y:0,width,height}};
|
|
224
|
+
const state:JobRigDrawState={player,presentation,frameGeneration:posed.generation,source:stage.source,
|
|
225
|
+
layout:JSON.stringify(camera),defaultCamera:true,wholeRig:true,playing:stage.playing};
|
|
226
|
+
const draw=recordJobRigDraw(state,drawGeneration);
|
|
227
|
+
return freezeJobRigCapture(draw,state,askId,()=>{
|
|
228
|
+
paintPosedViewport(context,posed,assets,camera,backend);
|
|
229
|
+
if(scale<1)console.info({evidenceStillScale:scale,width,height});
|
|
230
|
+
return encodeJobRigBitmap(canvas);
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** The owned bitmap is encoded after the synchronous pose and binding checks. */
|
|
235
|
+
function encodeJobRigBitmap(canvas:HTMLCanvasElement):JobRigPixels {
|
|
236
|
+
return {width:canvas.width,height:canvas.height,encode:()=>new Promise<string>((resolve,reject)=>{
|
|
237
|
+
canvas.toBlob(blob=>{
|
|
238
|
+
if(!blob||blob.size>jobStillByteLimit){reject(new Error('JOB_STILL_CAPTURE_FAILED'));return;}
|
|
239
|
+
const reader=new FileReader();
|
|
240
|
+
reader.onload=()=>typeof reader.result==='string'?resolve(reader.result):reject(new Error('JOB_STILL_CAPTURE_FAILED'));
|
|
241
|
+
reader.onerror=()=>reject(new Error('JOB_STILL_CAPTURE_FAILED'));reader.readAsDataURL(blob);
|
|
242
|
+
},'image/png');
|
|
243
|
+
})};
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** One lossless bitmap-copy implementation for job evidence and standalone native rest inspection. */
|
|
247
|
+
function copyRigBitmap(displayed: HTMLCanvasElement, width: number, height: number): HTMLCanvasElement {
|
|
164
248
|
const canvas = document.createElement('canvas');
|
|
165
249
|
canvas.width = width;
|
|
166
250
|
canvas.height = height;
|
|
@@ -170,15 +254,19 @@ export function copyJobRigViewport(presentation: JobRigPresentation): JobRigPixe
|
|
|
170
254
|
if (!source || !context) throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
171
255
|
context.putImageData(source.getImageData(0, 0, width, height), 0, 0);
|
|
172
256
|
} catch { throw new Error('JOB_STILL_CAPTURE_FAILED'); }
|
|
173
|
-
return
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
257
|
+
return canvas;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** Copy the committed display bitmap synchronously, before asynchronous PNG encoding. */
|
|
261
|
+
export function copyJobRigViewport(presentation: JobRigPresentation): JobRigPixels {
|
|
262
|
+
const {canvas: displayed, width, height, ratio} = presentation;
|
|
263
|
+
if (!displayed.isConnected || displayed.width !== width || displayed.height !== height ||
|
|
264
|
+
ratio !== (globalThis.devicePixelRatio || 1) || width < 1 || height < 1 ||
|
|
265
|
+
width > 16384 || height > 16384 || width * height > 16777216) {
|
|
266
|
+
throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
267
|
+
}
|
|
268
|
+
const canvas = copyRigBitmap(displayed, width, height);
|
|
269
|
+
return encodeJobRigBitmap(canvas);
|
|
182
270
|
}
|
|
183
271
|
|
|
184
272
|
/** Per-form first attempt, including human words and observed generation, survives a lost reply. */
|
|
@@ -209,3 +297,58 @@ export function createJobRigSubmission() {
|
|
|
209
297
|
},
|
|
210
298
|
};
|
|
211
299
|
}
|
|
300
|
+
|
|
301
|
+
/** One screen's rig pane as the still reads it: the job window's and the one review screen's share this. */
|
|
302
|
+
export interface JobRigStage {
|
|
303
|
+
readonly pane: HTMLElement;
|
|
304
|
+
readonly paneHidden: boolean;
|
|
305
|
+
readonly root: HTMLElement;
|
|
306
|
+
readonly player: RigPlayer;
|
|
307
|
+
readonly presentation: JobRigPresentation | undefined;
|
|
308
|
+
readonly frameGeneration: number | undefined;
|
|
309
|
+
readonly camera: ControlNumericCamera | null | undefined;
|
|
310
|
+
readonly frame: {readonly center: {readonly x: number; readonly y: number}} | null;
|
|
311
|
+
readonly source: DrawSource;
|
|
312
|
+
/** No part selected or solo, images only, no mesh, bones or background sentinel. */
|
|
313
|
+
readonly wholeRig: boolean;
|
|
314
|
+
readonly playing: boolean;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/** The draw state a still is bound to: pane geometry, camera, canonical pixels and the posed frame. */
|
|
318
|
+
export function jobRigDrawState(stage: JobRigStage): JobRigDrawState {
|
|
319
|
+
const {pane, root, player, presentation, frame, camera} = stage;
|
|
320
|
+
const rect = pane.getBoundingClientRect(), ratio = globalThis.devicePixelRatio || 1;
|
|
321
|
+
if (!frame || !camera || !pane.isConnected || !root.isConnected || stage.paneHidden ||
|
|
322
|
+
rect.width <= 0 || rect.height <= 0) throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
323
|
+
const style = getComputedStyle(root), paneStyle = getComputedStyle(pane);
|
|
324
|
+
const plain = style.filter === 'none' && style.perspective === 'none' && style.opacity === '1' &&
|
|
325
|
+
paneStyle.filter === 'none' && paneStyle.transform === 'none' && paneStyle.perspective === 'none' && paneStyle.opacity === '1';
|
|
326
|
+
const canvas = presentation?.canvas;
|
|
327
|
+
const pixels = canvas?.getBoundingClientRect();
|
|
328
|
+
const canvasStyle = canvas ? getComputedStyle(canvas) : null;
|
|
329
|
+
if (canvas && (!canvas.isConnected || canvasStyle?.visibility !== 'visible' ||
|
|
330
|
+
canvasStyle.display === 'none' || canvasStyle.opacity !== '1' || canvasStyle.filter !== 'none' ||
|
|
331
|
+
canvasStyle.transform !== 'none')) throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
332
|
+
return {player, presentation, frameGeneration: stage.frameGeneration, source: stage.source,
|
|
333
|
+
layout: JSON.stringify([
|
|
334
|
+
pane.clientWidth, pane.clientHeight, rect.width, rect.height, ratio,
|
|
335
|
+
root.getAttribute('style'), style.transform, camera, presentation?.area, presentation?.ratio,
|
|
336
|
+
pixels ? jobRigPixelPlacement(rect, pixels, ratio) : null,
|
|
337
|
+
pixels?.width, pixels?.height, canvas?.width, canvas?.height, canvas?.getAttribute('style'),
|
|
338
|
+
]),
|
|
339
|
+
defaultCamera: plain && camera.zoom === 1 && camera.center.x === frame.center.x && camera.center.y === frame.center.y,
|
|
340
|
+
wholeRig: stage.wholeRig, playing: stage.playing};
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/** Paint the pane's actual pixels into one canonical canvas and put it on the pane. */
|
|
344
|
+
export function presentJobRigStage(stage: Pick<JobRigStage, 'pane' | 'root' | 'player' | 'camera'> &
|
|
345
|
+
{readonly posed: PosedFrame | undefined; readonly assets: ModelAssets | null}): JobRigPresentation {
|
|
346
|
+
const renderer = stage.player.renderer;
|
|
347
|
+
if (!stage.posed || !stage.assets || !stage.camera) throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
348
|
+
const presentation = presentJobRigViewport({pane: stage.pane, root: stage.root, images: true,
|
|
349
|
+
canvas: renderer instanceof CanvasRenderer ? renderer.canvas : undefined,
|
|
350
|
+
backend: renderer instanceof CanvasRenderer ? renderer.backendActive : renderer.meshBackendActive},
|
|
351
|
+
{camera: stage.camera, posed: stage.posed, assets: stage.assets});
|
|
352
|
+
stage.pane.append(presentation.canvas);
|
|
353
|
+
return presentation;
|
|
354
|
+
}
|
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
import {formFor, jobCheckpointContext, jobPublicationRoutes, prepareJobForms, prepareJobInspection, jobSubmissionRefusal, type JobForm, type JobFormDependencies, type JobPreparedInspection} from './job-session.ts';
|
|
2
|
+
import {commentPartsIssues,type PartsIssue} from '../src/parts-comment.ts';
|
|
3
|
+
import type {PartsSubjectData} from './parts-viewport-provider.ts';
|
|
4
|
+
/** Card I (#709): a rig publication of a live job opens the one review screen (`main.ts`) instead of the job
|
|
5
|
+
* window. The job stays the transport: same asks, act kinds, still, displayed-ack and submission idempotency.
|
|
6
|
+
* Rig verdicts use the act bar; supported approval and interview asks use the shared ask dialog. */
|
|
7
|
+
import type {ActV3, DisplayPublicationV3, JobResult, JobUISubmission, PendingAskV3, SourceV3, UISubmissionV3} from '../src/job-contract.ts';
|
|
8
|
+
import type {Feedback, ReviewSession} from '../src/session.ts';
|
|
9
|
+
import type {ReviewManifest, ReviewedSource} from '../src/manifest.ts';
|
|
10
|
+
import {checkpointNoteComments, feedbackItemComments, projectComments} from '../src/stage-comment.ts';
|
|
11
|
+
import {createJobRigSubmission, freezeJobRigStage} from './job-rig-capture.ts';
|
|
12
|
+
import {setRigHost, rigHost, type RigHost, type RigHostScreen, type RigHostCommit, type RigHostNavigation} from './rig-host.ts';
|
|
13
|
+
import type {InstanceAccess} from './instance-access.ts';
|
|
14
|
+
|
|
15
|
+
/** The shared screen hosts model packages and parts drafts; records have their own shared host seam. */
|
|
16
|
+
export function jobRigScreenSubject(source: SourceV3): boolean {
|
|
17
|
+
if ('record' in source) return false;
|
|
18
|
+
if(source.selector?.kind==='draft'&&source.parts)return true;
|
|
19
|
+
return !!source.model && (source.direction ? source.selector?.kind === 'post' : source.selector === null || source.selector.kind === 'rig');
|
|
20
|
+
}
|
|
21
|
+
/** The asks the rig screen's act bar answers: the rig verdict and checkpoints the package declares. */
|
|
22
|
+
export function jobRigScreenAnswers(ask: Pick<PendingAskV3, 'subject'>, checkpoints: ReadonlySet<string>): boolean {
|
|
23
|
+
const subject = ask.subject;
|
|
24
|
+
return subject.kind === 'review-verdict' ? (subject.stage === 'rig-review' || subject.stage === 'direction-review') :
|
|
25
|
+
subject.kind === 'checkpoint' && checkpoints.has(subject.checkpointId);
|
|
26
|
+
}
|
|
27
|
+
/** One ask-availability check for both the route and its retained modal forms. */
|
|
28
|
+
export function jobRigScreenAsk(display:DisplayPublicationV3,ask:PendingAskV3,checkpoints:ReadonlySet<string>):boolean {
|
|
29
|
+
const source=display.publication.source;
|
|
30
|
+
if(ask.subject.kind==='checkpoint'){
|
|
31
|
+
try {prepareJobForms(display,[ask],()=>jobCheckpointContext(ask,[]));return true;}catch{return false;}
|
|
32
|
+
}
|
|
33
|
+
if(ask.subject.kind==='signoff'||ask.subject.kind==='interview-picks')return true;
|
|
34
|
+
if('record' in source)return ask.subject.kind==='reopen';
|
|
35
|
+
return !!source.model&&jobRigScreenAnswers(ask,checkpoints)&&
|
|
36
|
+
(ask.subject.kind!=='review-verdict'||ask.subject.stage===(source.direction?'direction-review':'rig-review'));
|
|
37
|
+
}
|
|
38
|
+
export function jobRigScreenRoute(display: DisplayPublicationV3, pending: readonly PendingAskV3[],
|
|
39
|
+
checkpoints: ReadonlySet<string>): boolean {
|
|
40
|
+
const source=display.publication.source,id=display.publication.publicationId;
|
|
41
|
+
if('record' in source)return false;
|
|
42
|
+
if(source.selector?.kind==='draft'&&source.parts)return true;
|
|
43
|
+
return (jobRigScreenSubject(source)||!source.model&&!source.parts)&&pending.every(ask=>
|
|
44
|
+
ask.publicationId!==id||ask.status!=='pending'||jobRigScreenAsk(display,ask,checkpoints));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Refusals describe missing producer inputs without granting a new act authority. */
|
|
48
|
+
export function jobRigScreenRefusal(display:DisplayPublicationV3,pending:readonly PendingAskV3[],checkpoints:ReadonlySet<string>,hasPicture=false):string|null {
|
|
49
|
+
const source=display.publication.source;
|
|
50
|
+
if('record' in source)return null;
|
|
51
|
+
{
|
|
52
|
+
if(source.selector?.kind==='post'&&!source.direction)return 'JOB_DIRECTION_MISSING';
|
|
53
|
+
if(source.selector?.kind==='draft'&&!source.parts)return 'JOB_PARTS_MISSING';
|
|
54
|
+
if(!source.model&&!source.parts&&!hasPicture&&!pending.some(ask=>ask.publicationId===display.publication.publicationId&&ask.status==='pending'&&ask.subject.kind!=='review-verdict'&&jobRigScreenAsk(display,ask,checkpoints)))return 'JOB_MODEL_MISSING';
|
|
55
|
+
}
|
|
56
|
+
return jobRigScreenRoute(display,pending,checkpoints)?null:'JOB_ASK_UNSUPPORTED';
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export type JobRigScreenDecision =
|
|
60
|
+
| {readonly ask: PendingAskV3; readonly kind: 'checkpoint'; readonly value: Extract<JobUISubmission, {kind: 'checkpoint'}>['value']}
|
|
61
|
+
| {readonly ask: PendingAskV3; readonly kind: 'review-verdict'; readonly value: {stage: 'rig-review' | 'direction-review'; verdict: 'approved' | 'changes-requested'; words: string; feedback?: readonly Feedback[]}};
|
|
62
|
+
/** The act bar's decisions as the pending asks' values. `words` is the comments' projection (act@6's), or empty;
|
|
63
|
+
* a decision still pending is not sent, so a pending ask is never answered with "pending". Checkpoints go first. */
|
|
64
|
+
export function jobRigScreenDecisions(session: Pick<ReviewSession, 'status' | 'checkpoints' | 'feedback'>,
|
|
65
|
+
pending: readonly PendingAskV3[], publicationId: string): JobRigScreenDecision[] {
|
|
66
|
+
const open = pending.filter(ask => ask.publicationId === publicationId && ask.status === 'pending');
|
|
67
|
+
const decisions: JobRigScreenDecision[] = [];
|
|
68
|
+
for (const ask of open) {
|
|
69
|
+
if (ask.subject.kind !== 'checkpoint') continue;
|
|
70
|
+
const {checkpointId} = ask.subject, entry = session.checkpoints[checkpointId];
|
|
71
|
+
if (!entry || entry.outcome === 'pending') continue;
|
|
72
|
+
const planStepId = ('planStepId' in ask.subject ? ask.subject.planStepId : undefined) ?? checkpointId;
|
|
73
|
+
decisions.push({ask, kind: 'checkpoint', value: {checkpointId, outcome: entry.outcome,
|
|
74
|
+
words: entry.note.trim() ? projectComments(checkpointNoteComments({checkpointId, planStepId, note: entry.note})) : ''}});
|
|
75
|
+
}
|
|
76
|
+
const verdict = open.find(ask => ask.subject.kind === 'review-verdict' && (ask.subject.stage === 'rig-review' || ask.subject.stage === 'direction-review'));
|
|
77
|
+
if (verdict?.subject.kind === 'review-verdict' && verdict.subject.stage !== 'image-review' && session.status !== 'pending') {
|
|
78
|
+
decisions.push({ask: verdict, kind: 'review-verdict', value: {stage: verdict.subject.stage, verdict: session.status,
|
|
79
|
+
words: session.feedback.length ? projectComments(feedbackItemComments(session.feedback)) : '',
|
|
80
|
+
...(verdict.subject.kind === 'review-verdict' && verdict.subject.stage === 'rig-review' && session.feedback.length ? {feedback: structuredClone(session.feedback)} : {})}});
|
|
81
|
+
}
|
|
82
|
+
return decisions;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
interface ReviewJson {manifest: ReviewManifest; reviewedSource: ReviewedSource; sourceHash: string}
|
|
86
|
+
export interface JobRigScreenPrepared {readonly jobRigScreen: true; readonly display: DisplayPublicationV3; readonly entry: string;
|
|
87
|
+
readonly refusal?:string; readonly modals?: {inspection:JobPreparedInspection;forms:Map<string,JobForm>}; readonly review?: ReviewJson; readonly record?: {inspection:JobPreparedInspection;forms:Map<string,JobForm>;picture:JobRigScreenPrepared|null}; readonly parts?:PartsSubjectData; readonly checkpoints: ReadonlySet<string>}
|
|
88
|
+
export function isJobRigScreen(value: unknown): value is JobRigScreenPrepared {
|
|
89
|
+
return !!value && typeof value === 'object' && (value as {jobRigScreen?: unknown}).jobRigScreen === true;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function createJobRigScreen(options: {
|
|
93
|
+
host: HTMLElement;
|
|
94
|
+
pageId: string;
|
|
95
|
+
access: {readonly capability: string | null; headers(init?: HeadersInit): Headers};
|
|
96
|
+
window: {state(): {readonly pending: readonly (PendingAskV3 & {readonly act?:ActV3})[]; readonly receipt: {readonly displayedNonce: string} | null;
|
|
97
|
+
readonly generation: number; readonly preparing: boolean; readonly closed: boolean}; submit(input: UISubmissionV3): Promise<JobResult<ActV3>>};
|
|
98
|
+
routes(display: DisplayPublicationV3): {entry: string; api(path: string): string};
|
|
99
|
+
readPublication?(publicationId:string,signal:AbortSignal):Promise<JobResult<DisplayPublicationV3>>;
|
|
100
|
+
formDependencies?:JobFormDependencies;
|
|
101
|
+
refusal(error: unknown, fallback?: string): string;
|
|
102
|
+
translate(key: string,values?:readonly (string|number)[]): string;
|
|
103
|
+
/** Imports the rig composition once the host is set. */
|
|
104
|
+
load(): Promise<unknown>;
|
|
105
|
+
}) {
|
|
106
|
+
let mounted: JobRigScreenPrepared | null = null, screen: RigHostScreen | null = null, drawGeneration = 0;
|
|
107
|
+
let transition:{rollback():Promise<void>;finalize():void}|null=null;
|
|
108
|
+
const attempts = new Map<string, {key: string; submissionId: string; rig: ReturnType<typeof createJobRigSubmission>; commit: Omit<RigHostCommit, 'at'>}>();
|
|
109
|
+
async function prepare(display: DisplayPublicationV3, signal: AbortSignal, backdropOnly=false): Promise<JobRigScreenPrepared | null> {
|
|
110
|
+
if(signal.aborted)throw new Error('JOB_PRELOAD_CANCELLED');
|
|
111
|
+
const source = display.publication.source;
|
|
112
|
+
if ('record' in source) {
|
|
113
|
+
if (!options.formDependencies) throw new Error('JOB_ACT_KIND_DISABLED');
|
|
114
|
+
const inspection = await prepareJobInspection(display, signal);
|
|
115
|
+
try {
|
|
116
|
+
const forms = prepareJobForms(display, options.window.state().pending, ask => formFor(ask, inspection, options.formDependencies!));
|
|
117
|
+
let previous = display.publication.previousPublicationId, picture:JobRigScreenPrepared|null = null;
|
|
118
|
+
const jobId=jobPublicationRoutes(display,location.origin).jobId;
|
|
119
|
+
const seen = new Set([display.publication.publicationId]);
|
|
120
|
+
let generation = display.publication.generation;
|
|
121
|
+
while (previous) {
|
|
122
|
+
if(signal.aborted)throw new Error('JOB_PRELOAD_CANCELLED');
|
|
123
|
+
if (seen.has(previous) || !options.readPublication) throw new Error('JOB_DISPLAY_MISMATCH');
|
|
124
|
+
seen.add(previous);
|
|
125
|
+
const result = await options.readPublication(previous, signal);
|
|
126
|
+
if (!result.ok) throw new Error(result.error.code);
|
|
127
|
+
if(signal.aborted)throw new Error('JOB_PRELOAD_CANCELLED');
|
|
128
|
+
const candidate = result.value;
|
|
129
|
+
if(jobPublicationRoutes(candidate,location.origin).jobId!==jobId)throw new Error('JOB_DISPLAY_MISMATCH');
|
|
130
|
+
if (candidate.publication.publicationId !== previous || candidate.publication.generation >= generation) throw new Error('JOB_DISPLAY_MISMATCH');
|
|
131
|
+
generation = candidate.publication.generation;
|
|
132
|
+
if (jobRigScreenSubject(candidate.publication.source)) {picture = await prepare(candidate, signal, true);break;}
|
|
133
|
+
previous = candidate.publication.previousPublicationId;
|
|
134
|
+
}
|
|
135
|
+
if (!picture && inspection.interview?.questions.some(question => question.hasParts)) {
|
|
136
|
+
const response = await fetch(options.routes(display).api('stage-parts'), {signal});
|
|
137
|
+
if (!response.ok) throw new Error('JOB_VISUAL_UNAVAILABLE');
|
|
138
|
+
const parts = await response.json() as PartsSubjectData;
|
|
139
|
+
if (parts.sourceHash !== source.sourceHash || parts.mode !== 'parts') throw new Error('JOB_DISPLAY_MISMATCH');
|
|
140
|
+
picture = {jobRigScreen:true,display,entry:options.routes(display).entry,checkpoints:new Set(),parts};
|
|
141
|
+
}
|
|
142
|
+
if(signal.aborted)throw new Error('JOB_PRELOAD_CANCELLED');
|
|
143
|
+
return {jobRigScreen:true,display,entry:options.routes(display).entry,checkpoints:new Set(),record:{inspection,forms,picture}};
|
|
144
|
+
} catch(error) {inspection.dispose();throw error;}
|
|
145
|
+
}
|
|
146
|
+
if (!jobRigScreenSubject(source)) {
|
|
147
|
+
if(!options.formDependencies)throw new Error('JOB_ACT_KIND_DISABLED');
|
|
148
|
+
const inspection=await prepareJobInspection(display,signal,true);
|
|
149
|
+
try {
|
|
150
|
+
const pending=options.window.state().pending,checkpoints=new Set(inspection.metadata.manifest?.checkpoints.map(item=>item.id)??[]);
|
|
151
|
+
const forms=prepareJobForms(display,pending.filter(ask=>ask.subject.kind!=='review-verdict'&&jobRigScreenAsk(display,ask,checkpoints)),ask=>formFor(ask,inspection,options.formDependencies!));
|
|
152
|
+
const picture:JobRigScreenPrepared|null=!source.model&&inspection.references.length?{jobRigScreen:true,display,entry:options.routes(display).entry,checkpoints,review:inspection.metadata as ReviewJson}:null;
|
|
153
|
+
return {jobRigScreen:true,display,entry:options.routes(display).entry,checkpoints,record:{inspection,forms,picture},refusal:jobRigScreenRefusal(display,pending,checkpoints,!!picture)??undefined};
|
|
154
|
+
}catch(error){inspection.dispose();throw error;}
|
|
155
|
+
}
|
|
156
|
+
const routes = options.routes(display);
|
|
157
|
+
const response = await fetch(routes.api('review'), {signal});
|
|
158
|
+
if (!response.ok) throw new Error('JOB_VISUAL_UNAVAILABLE');
|
|
159
|
+
const review = await response.json() as ReviewJson;
|
|
160
|
+
if (!review.manifest || !review.reviewedSource || review.sourceHash !== source.sourceHash ||
|
|
161
|
+
review.manifest.id !== source.package.id || review.manifest.revision !== source.package.revision ||
|
|
162
|
+
(review.reviewedSource.rig?.sha256 ?? null) !== (source.model?.sha256 ?? null)) throw new Error('JOB_DISPLAY_MISMATCH');
|
|
163
|
+
const checkpoints = new Set(review.manifest.checkpoints.map(item => item.id));
|
|
164
|
+
const refusal=backdropOnly?null:jobRigScreenRefusal(display,options.window.state().pending,checkpoints);
|
|
165
|
+
let parts:PartsSubjectData|undefined;
|
|
166
|
+
if(source.selector?.kind==='draft'&&source.parts){
|
|
167
|
+
const response=await fetch(routes.api('stage-parts'),{signal});if(!response.ok)throw new Error('JOB_VISUAL_UNAVAILABLE');
|
|
168
|
+
parts=await response.json() as PartsSubjectData;
|
|
169
|
+
if(parts.sourceHash!==source.sourceHash||parts.mode!=='parts')throw new Error('JOB_DISPLAY_MISMATCH');
|
|
170
|
+
}
|
|
171
|
+
let modals:JobRigScreenPrepared['modals'];
|
|
172
|
+
const asks=options.window.state().pending.filter(ask=>ask.publicationId===display.publication.publicationId&&ask.subject.kind!=='review-verdict'&&ask.subject.kind!=='parts-verdict'&&jobRigScreenAsk(display,ask,checkpoints));
|
|
173
|
+
if(!backdropOnly&&options.formDependencies){
|
|
174
|
+
const inspection=await prepareJobInspection(display,signal,true);
|
|
175
|
+
try{modals={inspection,forms:prepareJobForms(display,asks,ask=>formFor(ask,inspection,options.formDependencies!))};}
|
|
176
|
+
catch(error){inspection.dispose();throw error;}
|
|
177
|
+
}
|
|
178
|
+
return {jobRigScreen: true, display, entry: routes.entry, review, checkpoints,...refusal?{refusal}:{},...parts?{parts}:{},...modals?{modals}:{}};
|
|
179
|
+
}
|
|
180
|
+
function still(ask: PendingAskV3, prepared: JobRigScreenPrepared) {
|
|
181
|
+
const stage = screen?.stage();
|
|
182
|
+
if (!stage) throw new Error('JOB_STILL_CAPTURE_FAILED');
|
|
183
|
+
const publication = prepared.display.publication;
|
|
184
|
+
const source = {pageId: options.pageId, publicationId: publication.publicationId, instanceKey: publication.instanceKey,
|
|
185
|
+
sourceHash: publication.source.sourceHash};
|
|
186
|
+
return freezeJobRigStage({...stage,source},ask.askId,++drawGeneration);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
async function submit(session: ReviewSession, committed: (commit: RigHostCommit) => void | Promise<void>, directionWords?:string): Promise<string> {
|
|
190
|
+
const prepared = mounted, state = options.window.state();
|
|
191
|
+
if (!prepared || !state.receipt || state.preparing) throw new Error('JOB_ACT_SOURCE_STALE');
|
|
192
|
+
if (state.closed) throw new Error('JOB_CLOSED');
|
|
193
|
+
const refusal=jobRigScreenRefusal(prepared.display,state.pending,prepared.checkpoints);if(refusal)throw new Error(options.translate('job.refusal.'+refusal));
|
|
194
|
+
if (!options.access.capability) throw new Error('JOB_CAPABILITY_REQUIRED');
|
|
195
|
+
const decisions=jobRigScreenDecisions(session, state.pending.filter(ask=>!prepared.modals?.forms.has(ask.askId)), prepared.display.publication.publicationId);
|
|
196
|
+
if(directionWords!==undefined)for(const decision of decisions)if(decision.kind==='review-verdict'&&decision.value.stage==='direction-review')decision.value.words=directionWords;
|
|
197
|
+
if (!decisions.length) throw new Error('JOB_ACT_NOTHING_TO_SUBMIT');
|
|
198
|
+
for (const decision of decisions) {
|
|
199
|
+
const key = JSON.stringify(decision.value);
|
|
200
|
+
let attempt = attempts.get(decision.ask.askId);
|
|
201
|
+
if (!attempt || attempt.key !== key) attempts.set(decision.ask.askId, attempt = {key, submissionId: crypto.randomUUID(), rig: createJobRigSubmission(),
|
|
202
|
+
commit: decision.kind === 'checkpoint' ? {checkpoints: {[decision.value.checkpointId]: structuredClone(session.checkpoints[decision.value.checkpointId]!)}} :
|
|
203
|
+
{review: {status: decision.value.verdict, feedback: structuredClone(session.feedback)}}});
|
|
204
|
+
const latest = options.window.state();
|
|
205
|
+
if (!latest.receipt) throw new Error('JOB_ACT_SOURCE_STALE');
|
|
206
|
+
const input = {kind: decision.kind, publicationId: decision.ask.publicationId, askId: decision.ask.askId, pageId: options.pageId,
|
|
207
|
+
displayedNonce: latest.receipt.displayedNonce, expectedGeneration: latest.generation, submissionId: attempt.submissionId,
|
|
208
|
+
value: decision.value} as JobUISubmission;
|
|
209
|
+
const ask = decision.ask, current = attempt;
|
|
210
|
+
const frozen = decision.kind === 'review-verdict' && decision.value.stage === 'rig-review' ? await current.rig.prepare(input, () => still(ask, prepared)) : input;
|
|
211
|
+
const result = await options.window.submit(frozen);
|
|
212
|
+
if (!result.ok) throw new Error(result.error.code, {cause: (result.error as {cause?: unknown}).cause});
|
|
213
|
+
attempts.delete(ask.askId);
|
|
214
|
+
await committed({...current.commit, at: result.value.at});
|
|
215
|
+
}
|
|
216
|
+
return options.translate('job.saved');
|
|
217
|
+
}
|
|
218
|
+
const partsAttempts=new Map<string,{key:string;submissionId:string}>();
|
|
219
|
+
/** One parts verdict act. A pending signoff remains independent and is never synthesized here. */
|
|
220
|
+
async function submitParts(issues:readonly PartsIssue[]):Promise<string>{
|
|
221
|
+
const prepared=mounted,state=options.window.state();
|
|
222
|
+
if(!prepared?.parts||!state.receipt||state.preparing)throw new Error('JOB_ACT_SOURCE_STALE');
|
|
223
|
+
if(state.closed)throw new Error('JOB_CLOSED');
|
|
224
|
+
const ask=state.pending.find(ask=>ask.publicationId===prepared.display.publication.publicationId&&ask.status==='pending'&&ask.subject.kind==='parts-verdict');
|
|
225
|
+
if(!ask)throw new Error('JOB_ACT_NOTHING_TO_SUBMIT');
|
|
226
|
+
const value={verdict:issues.length?'changes-requested' as const:'approved' as const,issues:structuredClone(issues),words:''},key=JSON.stringify(value);
|
|
227
|
+
let attempt=partsAttempts.get(ask.askId);if(!attempt||attempt.key!==key){attempt={key,submissionId:crypto.randomUUID()};partsAttempts.set(ask.askId,attempt);}
|
|
228
|
+
const result=await options.window.submit({kind:'parts-verdict',publicationId:ask.publicationId,askId:ask.askId,pageId:options.pageId,displayedNonce:state.receipt.displayedNonce,expectedGeneration:state.generation,submissionId:attempt.submissionId,value});
|
|
229
|
+
if(!result.ok)throw new Error(result.error.code);
|
|
230
|
+
partsAttempts.delete(ask.askId);return options.translate('job.saved');
|
|
231
|
+
}
|
|
232
|
+
const pendingSubjects=()=>options.window.state().pending.filter(ask=>ask.publicationId===mounted?.display.publication.publicationId&&ask.status==='pending').map(ask=>ask.subject);
|
|
233
|
+
function host(prepared: JobRigScreenPrepared, ready: {resolve(): void; reject(error: unknown): void}, navigation?:RigHostNavigation): RigHost {
|
|
234
|
+
const base = new URL(prepared.entry).pathname;
|
|
235
|
+
const access: InstanceAccess = {base, key: prepared.display.publication.instanceKey, capability: options.access.capability,
|
|
236
|
+
route: path => {if (!path.startsWith('/') || path.startsWith('//')) throw new Error('Instance route must be app-absolute'); return base + path.slice(1);},
|
|
237
|
+
headers: init => options.access.headers(init)};
|
|
238
|
+
const review = prepared.review;
|
|
239
|
+
if(prepared.record){
|
|
240
|
+
const record=prepared.record,backdrop=record.picture?host(record.picture,ready):null;
|
|
241
|
+
return {...(backdrop?.subject?{subject:backdrop.subject}:{}),access:{...(backdrop?.access??access),capability:null,
|
|
242
|
+
headers:init=>{const headers=options.access.headers(init);headers.delete('X-Review-Capability');return headers;}},
|
|
243
|
+
ownerActAccess:{capability:options.access.capability},
|
|
244
|
+
record:{publicationId:prepared.display.publication.publicationId,label:prepared.display.publication.label,sourceHash:prepared.display.publication.source.sourceHash,hasPicture:!!record.picture},...prepared.refusal?{unavailable:prepared.refusal}:{},pendingSubjects,
|
|
245
|
+
read:(path,method)=>method==='GET'&&backdrop?backdrop.read(path,method):Promise.reject(new Error('JOB_REVIEW_READ_ONLY')),
|
|
246
|
+
submit:async()=>{throw new Error('JOB_REVIEW_READ_ONLY');},
|
|
247
|
+
submitParts:async()=>{throw new Error('JOB_REVIEW_READ_ONLY');},
|
|
248
|
+
attach:value=>{screen=value;screen.pendingSubjects?.(pendingSubjects());refreshRecordForms();},
|
|
249
|
+
displayed:()=>ready.resolve(),failed:error=>ready.reject(error)};
|
|
250
|
+
}
|
|
251
|
+
if(!review&&!prepared.parts)throw new Error('JOB_DISPLAY_MISMATCH');
|
|
252
|
+
return {access,pendingSubjects,navigation,...prepared.refusal?{unavailable:prepared.refusal}:{},...prepared.display.publication.source.direction?{direction:{publicationId:prepared.display.publication.publicationId,sourceHash:prepared.display.publication.source.sourceHash}}:{},
|
|
253
|
+
reviewState(issues,sending) {
|
|
254
|
+
if(sending)return options.translate('job.parts.sending');
|
|
255
|
+
const kind=prepared.parts?'parts-verdict':'review-verdict';
|
|
256
|
+
const ask=options.window.state().pending.filter(ask=>ask.publicationId===prepared.display.publication.publicationId&&
|
|
257
|
+
ask.subject.kind===kind&&(ask.subject.kind!=='review-verdict'||(ask.subject.stage==='rig-review'||ask.subject.stage==='direction-review'))).at(-1);
|
|
258
|
+
const act=ask?.status==='answered'?ask.act:undefined;
|
|
259
|
+
const verdict=act?.kind===kind&&(act.kind==='parts-verdict'||act.kind==='review-verdict')?act.value.verdict:null;
|
|
260
|
+
return verdict==='changes-requested'?options.translate('job.parts.sent'):verdict==='approved'?options.translate('job.review.approved'):
|
|
261
|
+
options.translate('job.parts.reviewing',[issues]);
|
|
262
|
+
},...prepared.parts?{subject:'parts' as const,submitParts}: {},
|
|
263
|
+
read(path, method) {
|
|
264
|
+
if (method !== 'GET') return prepared.parts?undefined:Promise.reject(new Error('JOB_REVIEW_READ_ONLY'));
|
|
265
|
+
if(prepared.parts){
|
|
266
|
+
if(path==='/api/review')return Promise.resolve({subject:'parts',parts:structuredClone(prepared.parts)});
|
|
267
|
+
if(path==='/api/access')return Promise.resolve({capabilityRequired:true,control:false});
|
|
268
|
+
if(path==='/api/session'){const act=options.window.state().pending.filter(ask=>ask.publicationId===prepared.display.publication.publicationId&&ask.subject.kind==='parts-verdict').at(-1)?.act;return Promise.resolve({subject:'parts',issues:act?.kind==='parts-verdict'&&act.schema==='rig-review/act@6'?commentPartsIssues(act.value.comments):act?.kind==='parts-verdict'&&act.schema==='rig-review/act@5'?act.value.issues:[]});}
|
|
269
|
+
return undefined;
|
|
270
|
+
}
|
|
271
|
+
if (path === '/api/review') return Promise.resolve(structuredClone(review!));
|
|
272
|
+
if (path === '/api/access') return Promise.resolve({capabilityRequired: true, control: false});
|
|
273
|
+
if (path === '/api/session') return Promise.resolve({schema: 'rig-review-session/1', id: review!.manifest.id, revision: review!.manifest.revision,
|
|
274
|
+
sourceHash: review!.sourceHash, reviewedSource: structuredClone(review!.reviewedSource), status: 'pending', checkpoints: {}, feedback: [],
|
|
275
|
+
feedbackWarnings: [], updatedAt: null} satisfies ReviewSession);
|
|
276
|
+
return Promise.reject(new Error('JOB_REVIEW_READ_ONLY'));
|
|
277
|
+
},
|
|
278
|
+
submit,
|
|
279
|
+
attach: value => {screen = value;screen.pendingSubjects?.(pendingSubjects());refreshRecordForms();},
|
|
280
|
+
displayed: () => ready.resolve(),
|
|
281
|
+
failed: error => ready.reject(error)};
|
|
282
|
+
}
|
|
283
|
+
/** Pending and completed forms keep the same source-bound builder and receipt gates. */
|
|
284
|
+
function refreshRecordForms():void {
|
|
285
|
+
const record=mounted?.record??mounted?.modals,deps=options.formDependencies;if(!record||!deps)return;
|
|
286
|
+
const state=options.window.state(),display=record.inspection.display;
|
|
287
|
+
const next=prepareJobForms(display,state.pending.filter(ask=>ask.subject.kind!=='parts-verdict'&&ask.subject.kind!=='review-verdict'&&jobRigScreenAsk(display,ask,mounted!.checkpoints)),ask=>record.forms.get(ask.askId)??formFor(ask,record.inspection,deps));
|
|
288
|
+
for(const [id,entry]of next)record.forms.set(id,entry);
|
|
289
|
+
for(const [id,entry]of record.forms){const ask=state.pending.find(ask=>ask.askId===id);entry.fieldset.disabled=entry.submitting||ask?.status!=='pending'||state.preparing||state.closed||!state.receipt||!options.access.capability;}
|
|
290
|
+
screen?.recordForms?.([...record.forms.values()].map(entry=>entry.form));
|
|
291
|
+
}
|
|
292
|
+
return {
|
|
293
|
+
prepare,
|
|
294
|
+
mounted: () => mounted,
|
|
295
|
+
report:(error:unknown,fallback?:string)=>screen?.message(options.refusal(error,fallback),true,jobSubmissionRefusal(error).title),
|
|
296
|
+
commit(prepared: JobRigScreenPrepared) {
|
|
297
|
+
const previous=mounted;mounted=prepared;
|
|
298
|
+
return {async rollback(){try{await transition?.rollback();}finally{transition=null;mounted=previous;}},finalize(){try{transition?.finalize();}finally{transition=null;if(previous!==prepared){const modal=previous?.record??previous?.modals;for(const entry of modal?.forms.values()??[])entry.dispose?.();modal?.inspection.dispose();}}}};
|
|
299
|
+
},
|
|
300
|
+
/** The rig composition draws first; the job acknowledges the display after. */
|
|
301
|
+
async painted(prepared: JobRigScreenPrepared, signal: AbortSignal): Promise<void> {
|
|
302
|
+
let ready!: {resolve(): void; reject(error: unknown): void};
|
|
303
|
+
const shown = new Promise<void>((resolve, reject) => {ready = {resolve, reject};});
|
|
304
|
+
const previous=screen,previousNodes=[...options.host.childNodes??[]],previousHost=rigHost();
|
|
305
|
+
const navigation=previousHost?.record||prepared.record?undefined:previous?.navigation?.();previous?.suspend?.();
|
|
306
|
+
const previousTitle=document.title,previousUrl=typeof location==='undefined'?null:location.href;
|
|
307
|
+
const previousReady=document.body?.getAttribute('data-ready')??null,previousInert=document.body?.inert;
|
|
308
|
+
let candidate:{dispose?():void}|undefined,finished=false,recovery:Promise<void>|null=null;
|
|
309
|
+
const rollback=():Promise<void>=>{
|
|
310
|
+
if(finished)return recovery??Promise.resolve();finished=true;
|
|
311
|
+
if(candidate?.dispose)candidate.dispose();else if(screen!==previous)screen?.dispose?.();screen=previous;
|
|
312
|
+
options.host.replaceChildren(...previousNodes);setRigHost(previousHost);document.title=previousTitle;
|
|
313
|
+
if(previousUrl)history.replaceState(null,'',previousUrl);
|
|
314
|
+
if(document.body){if(previousReady===null)document.body.removeAttribute('data-ready');else document.body.setAttribute('data-ready',previousReady);document.body.inert=previousInert??false;}
|
|
315
|
+
recovery=Promise.resolve(previous?.resume?.());return recovery;
|
|
316
|
+
};
|
|
317
|
+
transition={rollback,finalize(){if(finished)return;finished=true;previous?.dispose?.();}};
|
|
318
|
+
try {
|
|
319
|
+
setRigHost(host(prepared, ready,navigation));
|
|
320
|
+
const app = document.createElement('div');app.id = 'app';
|
|
321
|
+
options.host.replaceChildren(app);document.body?.removeAttribute('data-ready');
|
|
322
|
+
const loaded=await options.load();
|
|
323
|
+
if(loaded&&typeof loaded==='object')candidate=loaded as {dispose?():void};
|
|
324
|
+
await shown;
|
|
325
|
+
if (signal.aborted) throw new Error('JOB_PRELOAD_CANCELLED');
|
|
326
|
+
}catch(error){await rollback();throw error;}
|
|
327
|
+
},
|
|
328
|
+
/** Unsupported asks stay on the shared screen with a named explanation. */
|
|
329
|
+
changed(state: {readonly pending: readonly PendingAskV3[]; readonly closed: boolean; readonly preparing?:boolean; readonly error?:string|null; readonly errorOrigin?:string; readonly previousLabel?:string|null; readonly displayed?:DisplayPublicationV3|null}): void {
|
|
330
|
+
if (!mounted) return;
|
|
331
|
+
if(mounted.record){refreshRecordForms();if(mounted.refusal){screen?.message(options.translate('job.refusal.'+mounted.refusal),true);const notice=document.getElementById('message');if(notice)notice.title=mounted.refusal;}if(state.closed)screen?.message(options.translate('job.closed'),true);return;}
|
|
332
|
+
const refusal=jobRigScreenRefusal(mounted.display,state.pending,mounted.checkpoints);
|
|
333
|
+
if(refusal){screen?.message(options.translate('job.refusal.'+refusal),true);const notice=document.getElementById('message');if(notice)notice.title=refusal;return;}
|
|
334
|
+
screen?.pendingSubjects?.(pendingSubjects());
|
|
335
|
+
refreshRecordForms();
|
|
336
|
+
if(state.error)screen?.message(options.translate('job.failed')+' · '+options.refusal(state.error),true,jobSubmissionRefusal(new Error(state.error,{cause:state.errorOrigin})).title);
|
|
337
|
+
else if (state.closed) screen?.message(options.translate('job.closed'), true);
|
|
338
|
+
else if(!state.preparing&&state.displayed?.publication.publicationId===mounted.display.publication.publicationId){
|
|
339
|
+
const label=state.previousLabel?options.translate('job.updated',[state.previousLabel,mounted.display.publication.label]):mounted.display.publication.label;
|
|
340
|
+
screen?.message(label+(screen.incompatible?.()?' · '+options.translate('job.incompatible'):''));
|
|
341
|
+
}
|
|
342
|
+
},
|
|
343
|
+
};
|
|
344
|
+
}
|