@rig-c/review 4.10.0 → 4.12.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.
@@ -1,4 +1,4 @@
1
- import {formFor, jobCheckpointContext, jobPublicationRoutes, jobSourceDraftId, prepareJobForms, prepareJobInspection, jobSubmissionRefusal, type JobForm, type JobFormDependencies, type JobPreparedInspection} from './job-session.ts';
1
+ import {formFor, jobCheckpointContext, jobJson, jobPublicationRoutes, jobSourceDraftId, prepareJobForms, prepareJobInspection, jobSubmissionRefusal, type JobForm, type JobFormDependencies, type JobPreparedInspection} from './job-session.ts';
2
2
  import {commentPartsIssues,type PartsIssue} from '../src/parts-comment.ts';
3
3
  import type {PartsSubjectData} from './parts-viewport-provider.ts';
4
4
  /** Card I (#709): a rig publication of a live job opens the one review screen (`main.ts`) instead of the job
@@ -29,6 +29,11 @@ export function jobRigScreenAnswers(ask: Pick<PendingAskV3, 'subject'>, checkpoi
29
29
  return subject.kind === 'review-verdict' ? (subject.stage === 'rig-review' || subject.stage === 'direction-review') :
30
30
  subject.kind === 'checkpoint' && checkpoints.has(subject.checkpointId);
31
31
  }
32
+ /** #1048: the sealed identities the server attached to the record's question images (none elsewhere). */
33
+ function questionPictures(questions:readonly {readonly images:readonly {readonly name:string;readonly path?:string;readonly sha256?:string}[]}[]|undefined):{questionPictures?:{name:string;path:string;sha256:string}[]} {
34
+ const rows=(questions??[]).flatMap(question=>question.images.flatMap(image=>image.path&&image.sha256?[{name:image.name,path:image.path,sha256:image.sha256}]:[]));
35
+ return rows.length?{questionPictures:rows}:{};
36
+ }
32
37
  /** One ask-availability check for both the route and its retained modal forms. */
33
38
  export function jobRigScreenAsk(display:DisplayPublicationV3,ask:PendingAskV3,checkpoints:ReadonlySet<string>):boolean {
34
39
  const source=display.publication.source;
@@ -143,11 +148,12 @@ export function createJobRigScreen(options: {
143
148
  try {
144
149
  const {entry} = options.routes(display);
145
150
  const {manifest, reviewedSource} = inspection.metadata;
146
- let picture: JobRigScreenPrepared | null = manifest?.model && reviewedSource?.rig
151
+ // #983: a declared plan picture ranks first; the walk below runs only without it.
152
+ let picture: JobRigScreenPrepared | null = !inspection.planPicture && manifest?.model && reviewedSource?.rig
147
153
  ? {jobRigScreen:true, display, entry, checkpoints:new Set(), review:{...inspection.metadata, manifest, reviewedSource}}
148
154
  : null;
149
155
  const missingBoundPicture = inspection.interview?.questions.some(question => question.missingPicture);
150
- let previous = missingBoundPicture ? null : display.publication.previousPublicationId;
156
+ let previous = missingBoundPicture || inspection.planPicture ? null : display.publication.previousPublicationId;
151
157
  const jobId=jobPublicationRoutes(display,location.origin).jobId;
152
158
  const seen = new Set([display.publication.publicationId]);
153
159
  let generation = display.publication.generation;
@@ -165,7 +171,7 @@ export function createJobRigScreen(options: {
165
171
  if (jobRigScreenSubject(candidate.publication.source, candidate.rigDraftVerdict)) {picture = await prepare(candidate, signal, true);break;}
166
172
  previous = candidate.publication.previousPublicationId;
167
173
  }
168
- if (!picture && !missingBoundPicture && inspection.interview?.questions.some(question => question.hasParts)) {
174
+ if (!picture && !missingBoundPicture && !inspection.planPicture && inspection.interview?.questions.some(question => question.hasParts)) {
169
175
  const response = await fetch(options.routes(display).api('stage-parts'), {signal});
170
176
  if (!response.ok) throw new Error('JOB_VISUAL_UNAVAILABLE');
171
177
  const parts = await response.json() as PartsSubjectData;
@@ -189,9 +195,10 @@ export function createJobRigScreen(options: {
189
195
  }catch(error){inspection.dispose();throw error;}
190
196
  }
191
197
  const routes = options.routes(display);
192
- const response = await fetch(routes.api('review'), {signal});
193
- if (!response.ok) throw new Error('JOB_VISUAL_UNAVAILABLE');
194
- const review = await response.json() as ReviewJson;
198
+ // #1050: the modal inspection below reads the same metadata; jobJson hands it this request.
199
+ const review = await jobJson<ReviewJson>(routes.api('review'), signal).catch((error: unknown) => {
200
+ throw error instanceof Error && error.message === 'JOB_PRELOAD_FAILED' ? new Error('JOB_VISUAL_UNAVAILABLE') : error;
201
+ });
195
202
  if (!review.manifest || !review.reviewedSource || review.sourceHash !== source.sourceHash ||
196
203
  review.manifest.id !== source.package.id || review.manifest.revision !== source.package.revision ||
197
204
  (review.reviewedSource.rig?.sha256 ?? null) !== (source.model?.sha256 ?? null)) throw new Error('JOB_DISPLAY_MISMATCH');
@@ -307,7 +314,7 @@ export function createJobRigScreen(options: {
307
314
  return {...(backdrop?.subject?{subject:backdrop.subject}:{}),access:{...(backdrop?.access??access),capability:null,
308
315
  headers:init=>{const headers=options.access.headers(init);headers.delete('X-Review-Capability');return headers;}},
309
316
  ownerActAccess:{capability:options.access.capability},
310
- record:{...(jobId?{jobId}:{}),draftId,publicationId:prepared.display.publication.publicationId,previousPublicationId,label:prepared.display.publication.label,sourceHash:prepared.display.publication.source.sourceHash,hasPicture:!!record.picture,missingPicture:question?.missingPicture,questionPicture:question?.scenePicture || (question?.missingPicture && question.images.length ? true : undefined)},...prepared.refusal?{unavailable:prepared.refusal}:{},pendingSubjects,
317
+ record:{...(jobId?{jobId}:{}),draftId,publicationId:prepared.display.publication.publicationId,previousPublicationId,label:prepared.display.publication.label,sourceHash:prepared.display.publication.source.sourceHash,hasPicture:!!record.picture,...record.inspection.planPicture?{planPicture:record.inspection.planPicture}:{},...questionPictures(record.inspection.interview?.questions),missingPicture:question?.missingPicture,questionPicture:question?.scenePicture || (question?.missingPicture && question.images.length ? true : undefined)},...prepared.refusal?{unavailable:prepared.refusal}:{},pendingSubjects,
311
318
  read:(path,method)=>method==='GET'&&backdrop?backdrop.read(path,method):Promise.reject(new Error('JOB_REVIEW_READ_ONLY')),
312
319
  submit:async()=>{throw new Error('JOB_REVIEW_READ_ONLY');},
313
320
  submitParts:async()=>{throw new Error('JOB_REVIEW_READ_ONLY');},
@@ -23,7 +23,7 @@ import type {
23
23
  import {enCatalog} from './catalog-en.ts';
24
24
  import {koCatalog} from './catalog-ko.ts';
25
25
  import {t,onLanguageChange} from './i18n.ts';
26
- import type {InstanceAccess} from './instance-access.ts';
26
+ import {hashCapabilityAccess, type InstanceAccess} from './instance-access.ts';
27
27
  import {JOB_PLAN_TEXT_FIELDS, parseJobPlanTextProjection, type JobPlanTextProjection} from '../src/job-contract.ts';
28
28
  import {createJobRigScreen, type JobRigScreenPrepared} from './job-rig-screen.ts';
29
29
  import type {JobRigPresentation} from './viewport-capture.ts';
@@ -413,27 +413,9 @@ export function jobWindowAccess(href: string, storage: Pick<Storage, 'getItem' |
413
413
  const jobId = match[1]!;
414
414
  const base = url.pathname;
415
415
  const slot = 'rig-review-job-capability/1:' + jobId;
416
- let capability: string | null = null;
417
- if (url.hash.startsWith('#cap=')) {
418
- const value = url.hash.slice(5);
419
- if (/^[a-f0-9]{64}$/.test(value))
420
- capability = value;
421
- url.hash = '';
422
- replace(url.href);
423
- try {
424
- if (capability)
425
- storage?.setItem(slot, capability);
426
- }
427
- catch { /* Memory-only capability when storage is denied. */ }
428
- }
429
- if (!capability) {
430
- try {
431
- const saved = storage?.getItem(slot);
432
- if (saved && /^[a-f0-9]{64}$/.test(saved))
433
- capability = saved;
434
- }
435
- catch { /* A copied link remains read-only. */ }
436
- }
416
+ const capability = hashCapabilityAccess(url, slot, () => storage, replace, {
417
+ strip: 'cap-before-storage', storedValue: 'validate', fallback: null,
418
+ });
437
419
  return {
438
420
  jobId, base, capability,
439
421
  route(path) {
@@ -759,6 +741,9 @@ type JobInterview = {
759
741
  images: {
760
742
  name: string;
761
743
  url: string;
744
+ /** #1048: the sealed `files` entry, present on a record publication only. */
745
+ path?: string;
746
+ sha256?: string;
762
747
  }[];
763
748
  })[];
764
749
  interview?: JobInterviewDiagnostics | null;
@@ -863,6 +848,9 @@ export interface JobPreparedInspection {
863
848
  images: readonly HTMLImageElement[];
864
849
  }[];
865
850
  references: JobReferenceView[];
851
+ /** #983: the record plan's declared picture, hash-checked and decoded; the record screen draws it first.
852
+ * #1048: `path` and `sha256` are the sealed `files` entry, never a browser digest; pins name the picture by them. */
853
+ planPicture?: {name: string; src: string; path: string; sha256: string};
866
854
  assets: ModelAssets | null;
867
855
  player: RigPlayer | null;
868
856
  rigRoot: HTMLElement;
@@ -871,7 +859,19 @@ export interface JobPreparedInspection {
871
859
  setupPose(setup?: boolean): void;
872
860
  dispose(): void;
873
861
  }
862
+ /** One request per resource per preparation (#1050). Every caller in one preparation passes the same signal; a
863
+ * later preparation (a republish, a reload) brings a new signal and so a new request. The URL carries the
864
+ * publication id and instance key, so a republished resource never shares an older promise. */
865
+ const jobBytesBySignal = new WeakMap<AbortSignal, Map<string, Promise<Uint8Array<ArrayBuffer>>>>();
874
866
  async function jobBytes(url: string, signal: AbortSignal, maximum: number, refusal?: { status: number; code: string }): Promise<Uint8Array<ArrayBuffer>> {
867
+ let shared = jobBytesBySignal.get(signal);
868
+ if (!shared) jobBytesBySignal.set(signal, shared = new Map());
869
+ const key = `${url}\n${maximum}\n${refusal ? `${refusal.status}:${refusal.code}` : ''}`;
870
+ let pending = shared.get(key);
871
+ if (!pending) shared.set(key, pending = readJobBytes(url, signal, maximum, refusal));
872
+ return (await pending).slice();
873
+ }
874
+ async function readJobBytes(url: string, signal: AbortSignal, maximum: number, refusal?: { status: number; code: string }): Promise<Uint8Array<ArrayBuffer>> {
875
875
  const response = await fetch(url, { signal });
876
876
  if (!response.ok || !response.body) {
877
877
  void response.body?.cancel().catch(() => {});
@@ -907,7 +907,7 @@ async function jobDigest(bytes: Uint8Array<ArrayBuffer>): Promise<string> {
907
907
  return [...new Uint8Array(await crypto.subtle.digest('SHA-256', bytes))]
908
908
  .map(value => value.toString(16).padStart(2, '0')).join('');
909
909
  }
910
- async function jobJson<Value>(url: string, signal: AbortSignal, refusal?: { status: number; code: string }): Promise<Value> {
910
+ export async function jobJson<Value>(url: string, signal: AbortSignal, refusal?: { status: number; code: string }): Promise<Value> {
911
911
  const bytes = await jobBytes(url, signal, 2 * 1024 * 1024, refusal);
912
912
  return JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes)) as Value;
913
913
  }
@@ -1218,6 +1218,14 @@ export async function prepareJobInspection(display: DisplayPublicationV3, signal
1218
1218
  preload.push(image(routes.api('stage-parts/page/' + page.index))
1219
1219
  .then(element => { partPages.set(page.index, element); }));
1220
1220
  }
1221
+ let planPicture: {name: string; src: string; path: string; sha256: string} | undefined;
1222
+ const declaredPlanPicture = record && publishedSource.subject === 'plan' ? publishedSource.planPicture : undefined;
1223
+ if (preloadVisuals && declaredPlanPicture) {
1224
+ preload.push(image(routes.api('plan-picture'), declaredPlanPicture.sha256).then(element => {
1225
+ planPicture = {name: declaredPlanPicture.path.split('/').at(-1)!, src: element.src,
1226
+ path: declaredPlanPicture.path, sha256: declaredPlanPicture.sha256};
1227
+ }));
1228
+ }
1221
1229
  const preloaded = await Promise.allSettled(preload);
1222
1230
  const failed = preloaded.find(result => result.status === 'rejected');
1223
1231
  if (failed?.status === 'rejected')
@@ -1264,6 +1272,7 @@ export async function prepareJobInspection(display: DisplayPublicationV3, signal
1264
1272
  references.sort((a, b) => order.indexOf(a.id) - order.indexOf(b.id));
1265
1273
  return {
1266
1274
  display, metadata, interview, parts, partImages, partPages, checkpointEvidence, references, assets, rigRoot,
1275
+ ...(planPicture ? {planPicture} : {}),
1267
1276
  get rigPresentation() { return rigPresentation; },
1268
1277
  set rigPresentation(value) {
1269
1278
  clearRigPresentation();
@@ -1388,11 +1397,12 @@ export function createJobFormHelpers(node: JobFormNode, t: typeof import('./i18n
1388
1397
  const issue = row.issues.find(issue => issue.field === field);
1389
1398
  if (issue) value.append(node('span', 'job.plan.field.' + issue.reason));
1390
1399
  else if (field === 'rests_on') {
1391
- const rests = node('ul');
1400
+ const rests = node('ul'), questions = projection?.status === 'projected' ? projection.questions : undefined;
1392
1401
  for (const text of row.rests_on!) {
1393
1402
  const rest = node('li'), dependency = plan.steps.find(step => step.id === text);
1403
+ const question = !dependency && questions && Object.hasOwn(questions, text) ? questions[text] : undefined;
1394
1404
  if (dependency) {planStepText(rest, dependency, projection); rest.title = text;}
1395
- else {rest.textContent = text; rest.setAttribute('translate', 'no');}
1405
+ else {rest.textContent = question ?? text; if (question !== undefined) rest.title = text; rest.setAttribute('translate', 'no');}
1396
1406
  rests.append(rest);
1397
1407
  }
1398
1408
  value.append(rests);
@@ -1542,7 +1552,7 @@ export interface JobFormDependencies {
1542
1552
  }
1543
1553
  questionSet=jobQuestionSet(ask,prepared,t);
1544
1554
  interviewForm=createInterviewForm({question,id:'interview-answer-'+ask.askId,node,form,fieldset:fields,source,mainView:true,
1545
- images:question.images.map(image=>({name:image.name,src:jobPublicationRoutes(prepared.display,location.origin).instance(image.url)})),answered:ask.status==='answered',
1555
+ images:question.images.map(image=>({name:image.name,src:jobPublicationRoutes(prepared.display,location.origin).instance(image.url),...(image.path&&image.sha256?{path:image.path,sha256:image.sha256}:{})})),answered:ask.status==='answered',
1546
1556
  ...questionSet?.list});
1547
1557
  if (prepared.metadata.recordSource && (question.missingPicture || !question.images.length) && !prepared.metadata.manifest?.model) {
1548
1558
  fields.prepend(node('p', question.missingPicture === 'rig'
@@ -1553,7 +1563,9 @@ export interface JobFormDependencies {
1553
1563
  }
1554
1564
  const {localize,dispose,read:readInterview}=interviewForm;
1555
1565
  const offLanguage=onLanguageChange(localize);
1556
- disposeInterview=()=>{offLanguage();dispose();};read=readInterview;
1566
+ disposeInterview=()=>{offLanguage();dispose();};
1567
+ // #1048: a record interview carries its comments in the optional `words`; none keeps the old value bytes.
1568
+ read=()=>{const value=readInterview(),words=prepared.metadata.recordSource?commentWords():'';return words?{...value,words}:value;};
1557
1569
  submitKey = 'interview.save';
1558
1570
  }
1559
1571
  else if (subject.kind === 'checkpoint') {
@@ -49,7 +49,8 @@ export function placeLabels(inputs:readonly LabelInput[],options:LabelPlacementO
49
49
  const active=inputs.filter(x=>onCanvas(x.at));
50
50
  const inferSide=(input:LabelInput):'left'|'right'=>{
51
51
  if(input.side)return input.side;
52
- const right=input.at.x+gap,left=input.at.x-gap-input.width,band=active.filter(o=>o!==input&&Math.abs(o.at.y-input.at.y)<=step);
52
+ // The band is the row the home box sits in (it rises above the point), so a neighbour just above the point counts at any zoom.
53
+ const right=input.at.x+gap,left=input.at.x-gap-input.width,row=input.at.y-(options.rise??2)-h/2,band=active.filter(o=>o!==input&&Math.abs(o.at.y-row)<=step);
53
54
  return band.filter(o=>o.at.x>=right&&o.at.x<=right+input.width).length>band.filter(o=>o.at.x>=left&&o.at.x<=left+input.width).length?'left':'right';
54
55
  };
55
56
  const placed:LabelBox[]=[...(options.obstacles??[])],labels:LabelBox[]=[],out:PlacedLabel[]=new Array(inputs.length);