@rig-c/review 2.4.6 → 2.5.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.
@@ -13,6 +13,11 @@
13
13
 
14
14
  export const JOB_API_SCHEMA = 'rig-review/job-api@2' as const;
15
15
  export const JOB_ACT_SCHEMA = 'rig-review/act@2' as const;
16
+ /** New rig verdicts only. Store/reuse markers and all other acts retain @2. */
17
+ export const JOB_RIG_REVIEW_ACT_SCHEMA = 'rig-review/act@3' as const;
18
+ export const jobStillByteLimit = 8 * 1024 * 1024;
19
+ export const jobCaptureBodyLimit = 12 * 1024 * 1024;
20
+ export const jobRawActMediaType = 'application/vnd.rig-review.act+json';
16
21
  export const JOB_PARTS_ENUMERATOR_RANGE = '>=2.25.0 <3.0.0' as const;
17
22
 
18
23
  export const JOB_ENABLED_ACT_KINDS = [
@@ -284,7 +289,7 @@ export interface JobActSources {
284
289
  * Checkpoint stage is derived by Create. Plan-bound signoff requirements apply
285
290
  * to every stage in JOB_PLAN_BOUND_SIGNOFF_STAGES before act creation.
286
291
  */
287
- export type JobAct = {
292
+ export type JobLegacyAct = {
288
293
  [Kind in JobEnabledActKind]: {
289
294
  readonly schema: typeof JOB_ACT_SCHEMA;
290
295
  readonly actId: JobActId;
@@ -300,6 +305,50 @@ export type JobAct = {
300
305
  ) : {readonly source: JobActSources[Kind]; readonly value: JobActValues[Kind]});
301
306
  }[JobEnabledActKind];
302
307
 
308
+ export type JobRigStill = {
309
+ readonly path: string;
310
+ readonly sha256: JobSha256;
311
+ readonly camera: 'fixed';
312
+ } & (
313
+ | {readonly frame: 'setup'; readonly animation?: never}
314
+ | {readonly frame: number; readonly animation: string}
315
+ );
316
+
317
+ export type JobRigReviewAct = Omit<Extract<JobLegacyAct, {kind: 'review-verdict'}>, 'schema' | 'source' | 'value'> & {
318
+ readonly schema: typeof JOB_RIG_REVIEW_ACT_SCHEMA;
319
+ readonly source: JobModelSourceBinding & {
320
+ readonly selector: Extract<JobSelector, {kind: 'rig'}>;
321
+ readonly model: JobFileIdentity;
322
+ };
323
+ readonly value: JobModelReviewValue & {readonly stage: 'rig-review'};
324
+ readonly still: JobRigStill;
325
+ };
326
+
327
+ /** Historical @2 rig acts remain readable without being backfilled or relabelled. */
328
+ export type JobAct = JobLegacyAct | JobRigReviewAct;
329
+
330
+ /** Authenticated browser provenance. The daemon validates identity and hashes PNG bytes. */
331
+ export interface JobRigCapture {
332
+ readonly png: string;
333
+ readonly width: number;
334
+ readonly height: number;
335
+ readonly camera: 'fixed';
336
+ readonly framing: 'default';
337
+ readonly view: 'whole-rig';
338
+ readonly frame: 'setup' | number;
339
+ readonly animation?: string;
340
+ readonly playing: boolean;
341
+ readonly binding: {
342
+ readonly publicationId: JobPublicationId;
343
+ readonly instanceKey: string;
344
+ readonly sourceHash: JobSha256;
345
+ readonly pageId: string;
346
+ readonly askId: JobAskId;
347
+ readonly drawGeneration: number;
348
+ readonly playerGeneration: number;
349
+ };
350
+ }
351
+
303
352
  export type JobSubject =
304
353
  | { readonly kind: 'interview-picks'; readonly questionId: string; readonly setId: string }
305
354
  | {
@@ -435,6 +484,12 @@ export const JOB_ERROR_CODES = [
435
484
  'JOB_ACT_KIND_DISABLED',
436
485
  'JOB_ACT_SOURCE_STALE',
437
486
  'JOB_DISPLAY_MISMATCH',
487
+ 'JOB_STILL_CAPTURE_FAILED',
488
+ 'JOB_STILL_CAMERA_NOT_FIXED',
489
+ 'JOB_STILL_VIEW_UNSUPPORTED',
490
+ 'JOB_STILL_BINDING_MISMATCH',
491
+ 'JOB_STILL_UNAVAILABLE',
492
+ 'JOB_STILL_OUTPUT_FAILED',
438
493
  'JOB_CURSOR_INVALID',
439
494
  'JOB_STORAGE_FAILED',
440
495
  'JOB_AGENT_ISOLATION_HOLE',
@@ -502,6 +557,7 @@ export type JobUISubmission = {
502
557
  readonly submissionId: string;
503
558
  readonly kind: Kind;
504
559
  readonly value: JobUIActValues[Kind];
560
+ readonly capture?: Kind extends 'review-verdict' ? JobRigCapture : never;
505
561
  };
506
562
  }[JobEnabledActKind];
507
563
 
package/src/job-host.ts CHANGED
@@ -47,6 +47,10 @@ export type {
47
47
  JobUIActValues,
48
48
  JobActSources,
49
49
  JobAct,
50
+ JobLegacyAct,
51
+ JobRigReviewAct,
52
+ JobRigStill,
53
+ JobRigCapture,
50
54
  JobSubject,
51
55
  JobPendingAsk,
52
56
  JobPublication,
@@ -1,11 +1,11 @@
1
1
  import { randomBytes, randomUUID } from 'node:crypto';
2
2
  import { isAbsolute, relative, sep } from 'node:path';
3
3
  import {
4
- JOB_API_SCHEMA, JOB_ACT_SCHEMA, JOB_CAPABILITIES, JOB_ENABLED_ACT_KINDS, type JobPartsEnumerator, type JobAct, type JobAgentRequest, type JobDisplayAcknowledgment,
4
+ JOB_API_SCHEMA, JOB_ACT_SCHEMA, JOB_RIG_REVIEW_ACT_SCHEMA, jobStillByteLimit, JOB_CAPABILITIES, JOB_ENABLED_ACT_KINDS, type JobPartsEnumerator, type JobAct, type JobAgentRequest, type JobDisplayAcknowledgment,
5
5
  type JobDisplayPublication, type JobDisplayReceipt, type JobEvent, type JobFetchActRequest,
6
6
  type JobNextValue, type JobPendingAsk, type JobPublication, type JobReviewerBinding, type JobStatus,
7
7
  } from './job-contract.ts';
8
- import { bindJobAsk, finalizeJobAct, parseUISubmission } from './job-act.ts';
8
+ import { bindJobAsk, finalizeJobAct, parseUISubmission, prepareJobStill } from './job-act.ts';
9
9
  import { jobHash, jobPartsEnumeratorVersion, jobWaitLimitMs, requestDigest, sameCapability } from './job-api.ts';
10
10
  import {
11
11
  assertJobRoot, assertJobSourceCurrent, captureJobRoot, prepareJobSource, jobSnapshotHash, removeOwnedJobSnapshot,
@@ -397,6 +397,26 @@ export class JobSession {
397
397
  }
398
398
  }
399
399
 
400
+ /** Bounded immutable bytes selected only through the authenticated consumer port. */
401
+ readActExport(actId: string, png: boolean): Buffer {
402
+ const current = this.current();
403
+ if (!current.active) throw new JobError('JOB_CLOSED');
404
+ const act = current.data.acts[actId];
405
+ if (!act) throw new JobError('JOB_ACT_UNKNOWN');
406
+ if (act.schema !== JOB_RIG_REVIEW_ACT_SCHEMA) {
407
+ if (png) throw new JobError('JOB_STILL_UNAVAILABLE');
408
+ return Buffer.from(JSON.stringify(act));
409
+ }
410
+ const stored = this.store.readStill(this.jobId, actId);
411
+ if (!stored || stored.png.byteLength > jobStillByteLimit || stored.actBytes.byteLength > maximumEventBytes ||
412
+ stored.sha256 !== act.still.sha256 || jobHash(stored.png) !== act.still.sha256 ||
413
+ act.still.path !== act.still.sha256 + '.png' ||
414
+ !Buffer.from(stored.actBytes).equals(Buffer.from(JSON.stringify(act)))) {
415
+ throw new JobError('JOB_STILL_CAPTURE_FAILED');
416
+ }
417
+ return Buffer.from(png ? stored.png : stored.actBytes);
418
+ }
419
+
400
420
  ackDisplayed(input: JobDisplayAcknowledgment): JobDisplayReceipt {
401
421
  const current = this.current();
402
422
  let receipt: JobDisplayReceipt;
@@ -434,13 +454,20 @@ export class JobSession {
434
454
  if (!ask) throw new JobError('JOB_ASK_INVALID');
435
455
  const retained = fresh.data.publications[input.publicationId].retained;
436
456
  assertJobSourceCurrent(retained);
437
- act = finalizeJobAct({ jobId: this.jobId, submission: input, ask, retained, reviewer: fresh.data.reviewer });
457
+ const captured = ask.subject.kind === 'review-verdict' && ask.subject.stage === 'rig-review' ?
458
+ prepareJobStill(input, ask, retained) : undefined;
459
+ act = finalizeJobAct({ jobId: this.jobId, submission: input, ask, retained, reviewer: fresh.data.reviewer,
460
+ still: captured?.still });
438
461
  fresh.data.generation++;
439
462
  fresh.data.acts[act.actId] = act;
440
463
  fresh.data.asks[ask.askId] = { ...ask, status: 'answered' };
441
464
  fresh.data.replays[key] = { digest, value: act };
442
465
  this.event(fresh.data, { type: 'act', act } as Omit<JobEvent, 'cursor' | 'jobId' | 'generation'>);
443
- return { data: fresh.data };
466
+ return { data: fresh.data, ...(captured ? {still: {
467
+ actId: act.actId, pageId: input.pageId, submissionId: input.submissionId,
468
+ sha256: captured.still.sha256, binding: JSON.stringify(captured.binding),
469
+ png: captured.bytes, actBytes: Buffer.from(JSON.stringify(act)),
470
+ }} : {}) };
444
471
  }, fresh => {
445
472
  const raced = this.replay(fresh.data, key, digest);
446
473
  if (!raced) return false;
package/src/job-store.ts CHANGED
@@ -42,6 +42,16 @@ export interface JobSnapshotTombstone {
42
42
  readonly reason: 'closed' | 'superseded';
43
43
  }
44
44
 
45
+ export interface JobStoredStill {
46
+ readonly actId: string;
47
+ readonly pageId: string;
48
+ readonly submissionId: string;
49
+ readonly sha256: string;
50
+ readonly binding: string;
51
+ readonly png: Uint8Array;
52
+ readonly actBytes: Uint8Array;
53
+ }
54
+
45
55
  interface JobRow {
46
56
  job_id: string;
47
57
  root_key: string;
@@ -143,6 +153,11 @@ export class JobStore<Data> {
143
153
  job_id TEXT NOT NULL, publication_id TEXT NOT NULL, snapshot_hash TEXT NOT NULL,
144
154
  reclaimed_at TEXT NOT NULL, reason TEXT NOT NULL CHECK(reason IN ('closed','superseded')),
145
155
  PRIMARY KEY(job_id, publication_id)
156
+ );
157
+ CREATE TABLE IF NOT EXISTS job_act_stills (
158
+ job_id TEXT NOT NULL, act_id TEXT NOT NULL, page_id TEXT NOT NULL, submission_id TEXT NOT NULL,
159
+ sha256 TEXT NOT NULL, binding TEXT NOT NULL, png BLOB NOT NULL, act_bytes BLOB NOT NULL,
160
+ PRIMARY KEY(job_id, act_id), UNIQUE(job_id, page_id, submission_id)
146
161
  );`);
147
162
  } catch {
148
163
  throw new JobError('JOB_STORAGE_FAILED', 'Private job storage could not be opened');
@@ -207,6 +222,7 @@ export class JobStore<Data> {
207
222
  readonly data: Data;
208
223
  readonly active?: boolean;
209
224
  readonly snapshot?: JobSnapshotOwner;
225
+ readonly still?: JobStoredStill;
210
226
  }, replay?: (current: StoredJob<Data>) => boolean): StoredJob<Data> {
211
227
  return this.transaction(() => {
212
228
  const current = this.get(jobId);
@@ -221,12 +237,24 @@ export class JobStore<Data> {
221
237
  (job_id,publication_id,snapshot_hash,snapshot_root,dev,ino) VALUES(?,?,?,?,?,?)`)
222
238
  .run(jobId, snapshot.publicationId, snapshot.snapshotHash, snapshot.snapshotRoot, snapshot.dev, snapshot.ino);
223
239
  }
240
+ if (next.still) {
241
+ const still = next.still;
242
+ this.db.query(`INSERT INTO job_act_stills
243
+ (job_id,act_id,page_id,submission_id,sha256,binding,png,act_bytes) VALUES(?,?,?,?,?,?,?,?)`)
244
+ .run(jobId, still.actId, still.pageId, still.submissionId, still.sha256, still.binding, still.png, still.actBytes);
245
+ }
224
246
  this.db.query('UPDATE jobs SET revision=?,active=?,document=? WHERE job_id=?')
225
247
  .run(current.revision + 1, active ? 1 : 0, document, jobId);
226
248
  return this.get(jobId);
227
249
  });
228
250
  }
229
251
 
252
+ readStill(jobId: string, actId: string): Pick<JobStoredStill, 'sha256' | 'png' | 'actBytes'> | null {
253
+ return this.db.query<{sha256: string; png: Uint8Array; actBytes: Uint8Array}, [string, string]>(
254
+ 'SELECT sha256,png,act_bytes AS actBytes FROM job_act_stills WHERE job_id=? AND act_id=?',
255
+ ).get(jobId, actId);
256
+ }
257
+
230
258
  /** Close never grows or rewrites the bounded historical document. */
231
259
  sealClose(jobId: string, expectedRevision: number,
232
260
  replay: (current: StoredJob<Data>) => Pick<JobClosure, 'replay'> | null,
package/web/catalog-en.ts CHANGED
@@ -1,4 +1,10 @@
1
1
  export const enCatalog: Readonly<Record<string, string>> = {
2
+ "JOB_STILL_CAPTURE_FAILED": "JOB_STILL_CAPTURE_FAILED · The displayed Rig frame could not be captured. Wait for a successful draw and try again.",
3
+ "JOB_STILL_CAMERA_NOT_FIXED": "JOB_STILL_CAMERA_NOT_FIXED · Restore the default Rig framing before submitting this verdict.",
4
+ "JOB_STILL_VIEW_UNSUPPORTED": "JOB_STILL_VIEW_UNSUPPORTED · Show the whole Rig without solo, highlight or comparison layers before submitting.",
5
+ "JOB_STILL_BINDING_MISMATCH": "JOB_STILL_BINDING_MISMATCH · The displayed source, page or drawn frame changed. Start a new verdict attempt.",
6
+ "JOB_STILL_UNAVAILABLE": "JOB_STILL_UNAVAILABLE · This historical or non-rig act has no retained Rig PNG.",
7
+ "JOB_STILL_OUTPUT_FAILED": "JOB_STILL_OUTPUT_FAILED · The consumer could not finish writing the Rig PNG or act output.",
2
8
  "WORKSPACE_BODY_TIMEOUT": "WORKSPACE_BODY_TIMEOUT",
3
9
  "rig-review-target/1": "rig-review-target/1",
4
10
  "Review workspace": "Review workspace",
package/web/catalog-ko.ts CHANGED
@@ -1,4 +1,10 @@
1
1
  export const koCatalog: Readonly<Record<string, string>> = {
2
+ "JOB_STILL_CAPTURE_FAILED": "JOB_STILL_CAPTURE_FAILED · 표시된 리그 프레임을 캡처하지 못했습니다. 정상적으로 그려진 뒤 다시 시도하세요.",
3
+ "JOB_STILL_CAMERA_NOT_FIXED": "JOB_STILL_CAMERA_NOT_FIXED · 판정을 제출하기 전에 리그를 기본 화면 구도로 되돌리세요.",
4
+ "JOB_STILL_VIEW_UNSUPPORTED": "JOB_STILL_VIEW_UNSUPPORTED · 단독 표시·강조·비교 레이어를 해제하고 전체 리그를 표시한 뒤 제출하세요.",
5
+ "JOB_STILL_BINDING_MISMATCH": "JOB_STILL_BINDING_MISMATCH · 표시된 소스·페이지·그려진 프레임이 바뀌었습니다. 새 판정 시도를 시작하세요.",
6
+ "JOB_STILL_UNAVAILABLE": "JOB_STILL_UNAVAILABLE · 이 과거 기록 또는 리그 외 판정에는 보관된 리그 PNG가 없습니다.",
7
+ "JOB_STILL_OUTPUT_FAILED": "JOB_STILL_OUTPUT_FAILED · 소비자가 리그 PNG 또는 판정 출력을 끝까지 기록하지 못했습니다.",
2
8
  "WORKSPACE_BODY_TIMEOUT": "WORKSPACE_BODY_TIMEOUT",
3
9
  "rig-review-target/1": "rig-review-target/1",
4
10
  "Review workspace": "검토 작업 공간",
@@ -0,0 +1,169 @@
1
+ import type {RigPlayer} from '@rig-c/play';
2
+ import {jobStillByteLimit, type JobRigCapture, type JobUISubmission} from '../src/job-contract.ts';
3
+ import type {JobRigPresentation} from './viewport-capture.ts';
4
+
5
+ type DrawSource = Pick<JobRigCapture['binding'], 'publicationId' | 'instanceKey' | 'sourceHash' | 'pageId'>;
6
+ export interface JobRigDrawState {
7
+ player: Pick<RigPlayer, 'generation' | 'current' | 'time' | 'slots'> & {readonly renderer: object};
8
+ frameGeneration: number | undefined;
9
+ presentation: JobRigPresentation | undefined;
10
+ source: DrawSource;
11
+ layout: string;
12
+ defaultCamera: boolean;
13
+ wholeRig: boolean;
14
+ playing: boolean;
15
+ }
16
+ export interface JobRigDraw {
17
+ readonly player: JobRigDrawState['player'];
18
+ readonly renderer: object;
19
+ readonly presentation: JobRigPresentation;
20
+ readonly playerGeneration: number;
21
+ readonly drawGeneration: number;
22
+ readonly animation: string | null;
23
+ readonly time: number;
24
+ readonly playing: boolean;
25
+ readonly source: DrawSource;
26
+ readonly layout: string;
27
+ }
28
+ export interface JobRigPixels {
29
+ readonly width: number;
30
+ readonly height: number;
31
+ encode(): Promise<string>;
32
+ }
33
+ export interface FrozenJobRigCapture {
34
+ encode(): Promise<JobRigCapture>;
35
+ }
36
+
37
+ const sourceKey = (source: DrawSource) => JSON.stringify([
38
+ source.publicationId, source.instanceKey, source.sourceHash, source.pageId,
39
+ ]);
40
+
41
+ /** Bind local placement and physical-pixel phase while allowing whole-pixel page movement. */
42
+ export function jobRigPixelPlacement(pane: Pick<DOMRect, 'left' | 'top'>,
43
+ canvas: Pick<DOMRect, 'left' | 'top'>, ratio: number) {
44
+ function phase(coordinate: number): number {
45
+ const deviceCoordinate = coordinate * ratio;
46
+ return deviceCoordinate - Math.floor(deviceCoordinate);
47
+ }
48
+ return {
49
+ offsetX: canvas.left - pane.left,
50
+ offsetY: canvas.top - pane.top,
51
+ panePhaseX: phase(pane.left),
52
+ panePhaseY: phase(pane.top),
53
+ canvasPhaseX: phase(canvas.left),
54
+ canvasPhaseY: phase(canvas.top),
55
+ };
56
+ }
57
+
58
+ /** Called after the public draw/present and viewport-render boundaries succeed. */
59
+ export function recordJobRigDraw(state: JobRigDrawState, drawGeneration: number): JobRigDraw {
60
+ if (!state.presentation || state.frameGeneration !== state.player.generation || !Number.isSafeInteger(drawGeneration) || drawGeneration < 1 ||
61
+ !Number.isSafeInteger(state.player.generation) || state.player.generation < 0 || !Number.isFinite(state.player.time) || state.player.time < 0) {
62
+ throw new Error('JOB_STILL_CAPTURE_FAILED');
63
+ }
64
+ return Object.freeze({
65
+ player: state.player,
66
+ renderer: state.player.renderer,
67
+ presentation: state.presentation,
68
+ playerGeneration: state.player.generation,
69
+ drawGeneration,
70
+ animation: state.player.current,
71
+ time: state.player.time,
72
+ playing: state.playing,
73
+ source: Object.freeze({...state.source}),
74
+ layout: state.layout,
75
+ });
76
+ }
77
+
78
+ /** copy() runs synchronously. The returned encoder owns an already copied bitmap. */
79
+ export function freezeJobRigCapture(draw: JobRigDraw | undefined, state: JobRigDrawState, askId: string,
80
+ copy: () => JobRigPixels): FrozenJobRigCapture {
81
+ if (!state.defaultCamera) throw new Error('JOB_STILL_CAMERA_NOT_FIXED');
82
+ if (!state.wholeRig || state.player.slots !== null) throw new Error('JOB_STILL_VIEW_UNSUPPORTED');
83
+ if (!draw) throw new Error('JOB_STILL_CAPTURE_FAILED');
84
+ if (draw.presentation !== state.presentation || draw.player !== state.player || draw.renderer !== state.player.renderer || draw.playerGeneration !== state.player.generation ||
85
+ state.frameGeneration !== draw.playerGeneration || draw.animation !== state.player.current ||
86
+ draw.time !== state.player.time || draw.layout !== state.layout || sourceKey(draw.source) !== sourceKey(state.source)) {
87
+ throw new Error('JOB_STILL_BINDING_MISMATCH');
88
+ }
89
+ if (draw.animation !== null && !draw.animation) throw new Error('JOB_STILL_CAPTURE_FAILED');
90
+ const pixels = copy();
91
+ if (state.presentation !== draw.presentation || state.player.renderer !== draw.renderer || state.player.generation !== draw.playerGeneration || state.player.current !== draw.animation ||
92
+ state.player.time !== draw.time || draw.layout !== state.layout || sourceKey(draw.source) !== sourceKey(state.source)) {
93
+ throw new Error('JOB_STILL_BINDING_MISMATCH');
94
+ }
95
+ if (!Number.isSafeInteger(pixels.width) || !Number.isSafeInteger(pixels.height) || pixels.width < 1 || pixels.height < 1 ||
96
+ pixels.width > 16384 || pixels.height > 16384 || pixels.width * pixels.height > 16777216) {
97
+ throw new Error('JOB_STILL_CAPTURE_FAILED');
98
+ }
99
+ const metadata: Omit<JobRigCapture, 'png'> = {
100
+ width: pixels.width, height: pixels.height, camera: 'fixed', framing: 'default', view: 'whole-rig',
101
+ frame: draw.animation === null ? 'setup' : draw.time,
102
+ ...(draw.animation === null ? {} : {animation: draw.animation}), playing: draw.playing,
103
+ binding: {...draw.source, askId, drawGeneration: draw.drawGeneration, playerGeneration: draw.playerGeneration},
104
+ };
105
+ return {async encode() {
106
+ const png = await pixels.encode();
107
+ if (!png.startsWith('data:image/png;base64,') || png.length > 22 + Math.ceil(jobStillByteLimit / 3) * 4) {
108
+ throw new Error('JOB_STILL_CAPTURE_FAILED');
109
+ }
110
+ return {...metadata, png};
111
+ }};
112
+ }
113
+
114
+ /** Copy the committed display bitmap synchronously, before asynchronous PNG encoding. */
115
+ export function copyJobRigViewport(presentation: JobRigPresentation): JobRigPixels {
116
+ const {canvas: displayed, width, height, ratio} = presentation;
117
+ if (!displayed.isConnected || displayed.width !== width || displayed.height !== height ||
118
+ ratio !== (globalThis.devicePixelRatio || 1) || width < 1 || height < 1 ||
119
+ width > 16384 || height > 16384 || width * height > 16777216) {
120
+ throw new Error('JOB_STILL_CAPTURE_FAILED');
121
+ }
122
+ const canvas = document.createElement('canvas');
123
+ canvas.width = width;
124
+ canvas.height = height;
125
+ try {
126
+ const source = displayed.getContext('2d');
127
+ const context = canvas.getContext('2d');
128
+ if (!source || !context) throw new Error('JOB_STILL_CAPTURE_FAILED');
129
+ context.putImageData(source.getImageData(0, 0, width, height), 0, 0);
130
+ } catch { throw new Error('JOB_STILL_CAPTURE_FAILED'); }
131
+ return {width, height, encode: () => new Promise<string>((resolve, reject) => {
132
+ canvas.toBlob(blob => {
133
+ if (!blob || blob.size > jobStillByteLimit) {reject(new Error('JOB_STILL_CAPTURE_FAILED')); return;}
134
+ const reader = new FileReader();
135
+ reader.onload = () => typeof reader.result === 'string' ? resolve(reader.result) : reject(new Error('JOB_STILL_CAPTURE_FAILED'));
136
+ reader.onerror = () => reject(new Error('JOB_STILL_CAPTURE_FAILED'));
137
+ reader.readAsDataURL(blob);
138
+ }, 'image/png');
139
+ }).catch(() => {throw new Error('JOB_STILL_CAPTURE_FAILED');})};
140
+ }
141
+
142
+ /** Per-form first attempt, including human words and observed generation, survives a lost reply. */
143
+ export function createJobRigSubmission() {
144
+ let frozen: {identity: string; base: Extract<JobUISubmission, {kind: 'review-verdict'}>; copy?: FrozenJobRigCapture;
145
+ pending?: Promise<JobUISubmission>; request?: JobUISubmission} | undefined;
146
+ return {
147
+ reset() {frozen = undefined;},
148
+ prepare(input: JobUISubmission, copy: () => FrozenJobRigCapture): Promise<JobUISubmission> {
149
+ if (input.kind !== 'review-verdict' || input.value.stage !== 'rig-review') throw new Error('JOB_ACT_INVALID');
150
+ const identity = JSON.stringify([input.publicationId, input.pageId, input.displayedNonce, input.askId, input.submissionId, input.kind]);
151
+ if (frozen && frozen.identity !== identity) throw new Error('JOB_STILL_BINDING_MISMATCH');
152
+ if (!frozen) {
153
+ const base = structuredClone(input);
154
+ frozen = {identity, base, copy: copy()};
155
+ }
156
+ const saved = frozen;
157
+ if (saved.request) return Promise.resolve(saved.request);
158
+ if (!saved.pending) saved.pending = saved.copy!.encode().then(capture => {
159
+ Object.freeze(capture.binding);
160
+ Object.freeze(capture);
161
+ Object.freeze(saved.base.value);
162
+ saved.request = Object.freeze({...saved.base, capture});
163
+ saved.copy = undefined;
164
+ return saved.request;
165
+ }).finally(() => {saved.pending = undefined;});
166
+ return saved.pending;
167
+ },
168
+ };
169
+ }