rig-review 2.7.1 → 2.8.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/src/job-act.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { randomUUID } from 'node:crypto';
2
2
  import {
3
- JOB_ACT_SCHEMA, JOB_RECORD_ACT_SCHEMA, JOB_RIG_REVIEW_ACT_SCHEMA, jobStillByteLimit, JOB_ENABLED_ACT_KINDS, JOB_PLAN_BOUND_SIGNOFF_STAGES, JOB_RESERVED_ACT_KINDS,
4
- type ActV3, type JobAct, type JobActValues, type JobPendingAsk, type JobReviewerBinding,
3
+ JOB_ACT_SCHEMA, JOB_API_SCHEMA, JOB_API_V3_SCHEMA, JOB_RECORD_ACT_KINDS, JOB_RECORD_ACT_SCHEMA, JOB_RIG_REVIEW_ACT_SCHEMA, jobStillByteLimit, JOB_ENABLED_ACT_KINDS, JOB_PLAN_BOUND_SIGNOFF_STAGES, JOB_RESERVED_ACT_KINDS,
4
+ type ActV3, type JobAct, type JobActValues, type JobApiSchema, type JobPendingAsk, type JobPublicationMode, type JobReviewerBinding,
5
5
  type JobSourceBinding, type JobSubject, type JobUISubmission, type JobRigCapture, type JobRigStill,
6
- type PendingAskV3, type RecordAct, type RecordSource, type RecordSubject, type SourceV3,
6
+ type PendingAskV3, type RecordAct, type RecordSource, type RecordSubject, type SourceV3, type UISubmissionV3,
7
7
  } from './job-contract.ts';
8
8
  import {
9
9
  isRecordSource, jobHash, jobId, jobInteger, jobObject,
@@ -75,6 +75,12 @@ export function bindJobRecordAsk(subject: unknown, retained: JobRetainedRecordSo
75
75
  }
76
76
  return source;
77
77
  }
78
+ case 'reopen': {
79
+ if (source.subject !== 'plan') {
80
+ throw new JobError('JOB_ASK_INVALID');
81
+ }
82
+ return source;
83
+ }
78
84
  }
79
85
  }
80
86
 
@@ -121,24 +127,45 @@ export function bindJobAsk(subject: JobSubject | RecordSubject, retained: JobRet
121
127
  if (!declared) throw new JobError('JOB_ASK_INVALID');
122
128
  if ((JOB_PLAN_BOUND_SIGNOFF_STAGES as readonly string[]).includes(subject.stage)) requirePlan(source);
123
129
  return source;
130
+ case 'reopen':
131
+ throw new JobError('JOB_ASK_INVALID');
124
132
  }
125
133
  }
126
134
 
127
- export function parseUISubmission(value: unknown): JobUISubmission {
135
+ export function parseUISubmission(
136
+ value: unknown,
137
+ mode?: typeof JOB_API_SCHEMA | 'package-only',
138
+ ): JobUISubmission;
139
+ export function parseUISubmission(
140
+ value: unknown,
141
+ mode: typeof JOB_API_V3_SCHEMA | 'record-and-package',
142
+ ): UISubmissionV3;
143
+ export function parseUISubmission(
144
+ value: unknown,
145
+ mode?: JobApiSchema | JobPublicationMode,
146
+ ): UISubmissionV3;
147
+ export function parseUISubmission(
148
+ value: unknown,
149
+ mode: JobApiSchema | JobPublicationMode = JOB_API_SCHEMA,
150
+ ): JobUISubmission | UISubmissionV3 {
128
151
  const item = jobObject(value, ['publicationId', 'askId', 'pageId', 'displayedNonce', 'expectedGeneration', 'submissionId', 'kind', 'value', 'capture']);
129
152
  if ((JOB_RESERVED_ACT_KINDS as readonly unknown[]).includes(item.kind)) throw new JobError('JOB_ACT_KIND_DISABLED');
130
153
  jobId(item.publicationId); jobId(item.askId); jobId(item.pageId); jobId(item.displayedNonce); jobId(item.submissionId);
131
154
  jobInteger(item.expectedGeneration);
132
- if (!(JOB_ENABLED_ACT_KINDS as readonly string[]).includes(String(item.kind))) {
155
+ const recordEnabled = mode === JOB_API_V3_SCHEMA || mode === 'record-and-package';
156
+ const kind = String(item.kind);
157
+ const allowed = (JOB_ENABLED_ACT_KINDS as readonly string[]).includes(kind) ||
158
+ (recordEnabled && (JOB_RECORD_ACT_KINDS as readonly string[]).includes(kind));
159
+ if (!allowed) {
133
160
  throw new JobError('JOB_ACT_INVALID');
134
161
  }
135
162
  if (item.capture !== undefined && (item.kind !== 'review-verdict' ||
136
163
  (item.value as {stage?: unknown} | null)?.stage !== 'rig-review')) throw new JobError('JOB_REQUEST_INVALID');
137
- return item as unknown as JobUISubmission;
164
+ return item as unknown as UISubmissionV3;
138
165
  }
139
166
 
140
167
  /** The browser supplies pixels and draw provenance, never a trusted hash or path. */
141
- export function prepareJobStill(input: JobUISubmission, ask: JobPendingAsk, retained: JobRetainedSource): {
168
+ export function prepareJobStill(input: UISubmissionV3, ask: JobPendingAsk, retained: JobRetainedSource): {
142
169
  readonly still: JobRigStill;
143
170
  readonly bytes: Buffer;
144
171
  readonly binding: JobRigCapture['binding'];
@@ -201,7 +228,7 @@ function actIdField(value: unknown): string {
201
228
 
202
229
  export function prepareJobRecordAct(options: {
203
230
  readonly jobId: string;
204
- readonly submission: JobUISubmission;
231
+ readonly submission: UISubmissionV3;
205
232
  readonly ask: PendingAskV3;
206
233
  readonly retained: JobRetainedRecordSource;
207
234
  readonly reviewer: JobReviewerBinding;
@@ -379,6 +406,26 @@ export function prepareJobRecordAct(options: {
379
406
  },
380
407
  });
381
408
  }
409
+ case 'reopen': {
410
+ if (boundSource.subject !== 'plan') throw new JobError('JOB_ACT_SOURCE_STALE');
411
+ const value = actObject(submission.value, ['stage', 'words']);
412
+ if (
413
+ !('stage' in value) ||
414
+ !('words' in value) ||
415
+ value.stage !== askSubject.stage
416
+ ) {
417
+ throw new JobError('JOB_ACT_INVALID');
418
+ }
419
+ return parseRecordAct({
420
+ ...envelope,
421
+ kind: 'reopen',
422
+ source: boundSource,
423
+ value: {
424
+ stage: askSubject.stage,
425
+ words: words(value.words),
426
+ },
427
+ });
428
+ }
382
429
  }
383
430
  }
384
431
 
@@ -395,7 +442,7 @@ export function finalizeJobAct(options: {
395
442
  }): JobAct;
396
443
  export function finalizeJobAct(options: {
397
444
  readonly jobId: string;
398
- readonly submission: JobUISubmission;
445
+ readonly submission: UISubmissionV3;
399
446
  readonly ask: PendingAskV3;
400
447
  readonly retained: JobRetainedRecordSource;
401
448
  readonly reviewer: JobReviewerBinding;
@@ -405,7 +452,7 @@ export function finalizeJobAct(options: {
405
452
  }): RecordAct;
406
453
  export function finalizeJobAct(options: {
407
454
  readonly jobId: string;
408
- readonly submission: JobUISubmission;
455
+ readonly submission: UISubmissionV3;
409
456
  readonly ask: JobPendingAsk | PendingAskV3;
410
457
  readonly retained: JobRetainedSourceV3;
411
458
  readonly reviewer: JobReviewerBinding;
@@ -415,7 +462,7 @@ export function finalizeJobAct(options: {
415
462
  }): ActV3;
416
463
  export function finalizeJobAct(options: {
417
464
  readonly jobId: string;
418
- readonly submission: JobUISubmission;
465
+ readonly submission: UISubmissionV3;
419
466
  readonly ask: JobPendingAsk | PendingAskV3;
420
467
  readonly retained: JobRetainedSourceV3;
421
468
  readonly reviewer: JobReviewerBinding;
@@ -435,6 +482,7 @@ export function finalizeJobAct(options: {
435
482
  at: options.at,
436
483
  });
437
484
  }
485
+ if ((options.submission.kind as string) === 'reopen') throw new JobError('JOB_ACT_INVALID');
438
486
  const { submission, ask, retained, reviewer } = options as {
439
487
  readonly jobId: string;
440
488
  readonly submission: JobUISubmission;
package/src/job-api.ts CHANGED
@@ -5,7 +5,8 @@ import {
5
5
  JOB_RESERVED_ACT_KINDS,
6
6
  type AgentRequestV3, type FetchActRequestV3, type JobAgentRequest, type JobApiSchema,
7
7
  type JobDisplayAcknowledgment, type JobErrorCode, type JobFetchActRequest, type JobFileIdentity,
8
- type JobHostPorts, type JobHumanAuthority, type JobPlanIdentity, type JobPublicationMode,
8
+ type JobHostPorts, type JobHumanAuthority, type JobInterviewDiagnostic, type JobInterviewDiagnostics,
9
+ type JobInterviewJson, type JobInterviewRecord, type JobPlanIdentity, type JobPublicationMode,
9
10
  type JobPublishRequest, type JobResult, type JobSelector, type JobSha256, type JobSubject,
10
11
  type OptionContext, type OptionSource, type PlanContext, type PlanSource, type ProjectRecord,
11
12
  type PublishRequestV3, type PublishResultV3, type RecordAct, type RecordFreeze,
@@ -16,6 +17,13 @@ import {
16
17
  import { JobError } from './job-store.ts';
17
18
  import type { JobSession } from './job-session.ts';
18
19
 
20
+ export type {
21
+ JobInterviewJson,
22
+ JobInterviewRecord,
23
+ JobInterviewDiagnostic,
24
+ JobInterviewDiagnostics,
25
+ } from './job-contract.ts';
26
+
19
27
  export const jobBodyLimit = 256 * 1024;
20
28
  export const jobWaitLimitMs = 30_000;
21
29
  const requestDeadlineMs = 10_000;
@@ -219,7 +227,12 @@ export function parseRecordSubject(value: unknown): RecordSubject {
219
227
  if ((JOB_RESERVED_ACT_KINDS as readonly unknown[]).includes(item.kind)) {
220
228
  throw new JobError('JOB_ACT_KIND_DISABLED');
221
229
  }
222
- if (item.kind !== 'interview-picks' && item.kind !== 'checkpoint' && item.kind !== 'signoff') {
230
+ if (
231
+ item.kind !== 'interview-picks' &&
232
+ item.kind !== 'checkpoint' &&
233
+ item.kind !== 'signoff' &&
234
+ item.kind !== 'reopen'
235
+ ) {
223
236
  throw new JobError('JOB_ASK_INVALID');
224
237
  }
225
238
  switch (item.kind) {
@@ -237,6 +250,9 @@ export function parseRecordSubject(value: unknown): RecordSubject {
237
250
  }
238
251
  return { kind: 'signoff', stage: stage as RecordSignoffStage };
239
252
  }
253
+ case 'reopen':
254
+ jobObject(item, ['kind', 'stage']);
255
+ return { kind: 'reopen', stage: jobId(item.stage) };
240
256
  }
241
257
  }
242
258
 
@@ -248,6 +264,10 @@ export function parseJobRequest(
248
264
  value: unknown,
249
265
  mode: typeof JOB_API_V3_SCHEMA | 'record-and-package',
250
266
  ): AgentRequestV3 | FetchActRequestV3;
267
+ export function parseJobRequest(
268
+ value: unknown,
269
+ mode: JobApiSchema | JobPublicationMode,
270
+ ): JobAgentRequest | JobFetchActRequest | AgentRequestV3 | FetchActRequestV3;
251
271
  export function parseJobRequest(
252
272
  value: unknown,
253
273
  mode: JobApiSchema | JobPublicationMode = JOB_API_SCHEMA,
@@ -299,9 +319,20 @@ export function parseJobRequest(
299
319
  };
300
320
  return parsedRecordPublish;
301
321
  }
302
- case 'ask':
322
+ case 'ask': {
303
323
  jobObject(item, ['schema', 'jobId', 'requestId', 'verb', 'expectedGeneration', 'idempotencyKey', 'publicationId', 'subject']);
304
- return { ...mutation, verb: 'ask', publicationId: jobId(item.publicationId), subject: parseJobSubject(item.subject) };
324
+ const isReopenSubject =
325
+ item.subject !== null &&
326
+ typeof item.subject === 'object' &&
327
+ !Array.isArray(item.subject) &&
328
+ (item.subject as { kind?: unknown }).kind === 'reopen';
329
+ return {
330
+ ...mutation,
331
+ verb: 'ask',
332
+ publicationId: jobId(item.publicationId),
333
+ subject: isReopenSubject ? parseRecordSubject(item.subject) : parseJobSubject(item.subject),
334
+ };
335
+ }
305
336
  case 'close':
306
337
  jobObject(item, ['schema', 'jobId', 'requestId', 'verb', 'expectedGeneration', 'idempotencyKey', 'reason']);
307
338
  return { ...mutation, verb: 'close', reason: jobText(item.reason, 1024) };
@@ -377,6 +408,119 @@ function parseFileRow(value: unknown, code: JobErrorCode): JobFileIdentity {
377
408
  return asCode(() => ({ path: jobPath(item.path), sha256: jobSha(item.sha256) }), code);
378
409
  }
379
410
 
411
+ function parseInterviewJson(value: unknown, code: JobErrorCode, depth = 0): JobInterviewJson {
412
+ if (depth > 32) throw new JobError(code);
413
+ if (value === null || typeof value === 'boolean' || typeof value === 'string') return value;
414
+ if (typeof value === 'number') {
415
+ if (!Number.isFinite(value)) throw new JobError(code);
416
+ return value;
417
+ }
418
+ if (Array.isArray(value)) {
419
+ return value.map(entry => parseInterviewJson(entry, code, depth + 1));
420
+ }
421
+ if (typeof value === 'object') {
422
+ return Object.fromEntries(
423
+ Object.entries(value as Record<string, unknown>).map(([key, child]) => [
424
+ key,
425
+ parseInterviewJson(child, code, depth + 1),
426
+ ]),
427
+ );
428
+ }
429
+ throw new JobError(code);
430
+ }
431
+
432
+ function parseInterviewJsonObject(
433
+ value: unknown,
434
+ code: JobErrorCode,
435
+ ): { readonly [key: string]: JobInterviewJson } {
436
+ if (value === null || typeof value !== 'object' || Array.isArray(value)) {
437
+ throw new JobError(code);
438
+ }
439
+ return parseInterviewJson(value, code) as { readonly [key: string]: JobInterviewJson };
440
+ }
441
+
442
+ export function parseJobInterviewDiagnostics(
443
+ value: unknown,
444
+ code: JobErrorCode = 'JOB_REQUEST_INVALID',
445
+ ): JobInterviewDiagnostics | null | undefined {
446
+ if (value === undefined) return undefined;
447
+ if (value === null) return null;
448
+ const item = exactObject(
449
+ value,
450
+ ['schema', 'project', 'evaluatedAt', 'records', 'diagnostics'],
451
+ code,
452
+ );
453
+ if (item.schema !== 'rig-review/job-interview@1') throw new JobError(code);
454
+ const project = asCode(() => parseProjectRecord(item.project, code), code);
455
+ const evaluatedAt = asCode(() => jobText(item.evaluatedAt), code);
456
+ if (!Number.isFinite(Date.parse(evaluatedAt))) throw new JobError(code);
457
+ if (!Array.isArray(item.records) || item.records.length > maxRecordFiles ||
458
+ !Array.isArray(item.diagnostics) || item.diagnostics.length > maxRecordFiles) {
459
+ throw new JobError(code);
460
+ }
461
+ const recordsByLocator = new Map<string, JobInterviewRecord>();
462
+ const records: JobInterviewRecord[] = item.records.map(rawRow => {
463
+ const row = exactObject(
464
+ rawRow,
465
+ ['questionId', 'record', 'setId', 'ref', 'observedSet', 'timeKind', 'at', 'original'],
466
+ code,
467
+ );
468
+ const questionId = asCode(() => jobId(row.questionId), code);
469
+ const record = asCode(() => jobText(row.record, 256), code);
470
+ if (recordsByLocator.has(record)) throw new JobError(code);
471
+ const setId = row.setId === null ? null : asCode(() => jobId(row.setId), code);
472
+ const ref = parseFileRow(row.ref, code);
473
+ const observedSet = row.observedSet === null ? null : parseFileRow(row.observedSet, code);
474
+ if (row.timeKind !== 'inspection' && row.timeKind !== 'answer' && row.timeKind !== 'decision') {
475
+ throw new JobError(code);
476
+ }
477
+ const timeKind = row.timeKind;
478
+ const at = row.at === null ? null : asCode(() => jobText(row.at), code);
479
+ if (timeKind === 'inspection') {
480
+ if (at !== evaluatedAt || row.original !== null) throw new JobError(code);
481
+ const parsed: JobInterviewRecord = { questionId, record, setId, ref, observedSet, timeKind, at, original: null };
482
+ recordsByLocator.set(record, parsed);
483
+ return parsed;
484
+ }
485
+ const original = parseInterviewJsonObject(row.original, code);
486
+ if (timeKind === 'decision') {
487
+ const completed = ['at', 'value', 'fragments'].some(key => Object.hasOwn(original, key));
488
+ if (!completed && at !== null) throw new JobError(code);
489
+ }
490
+ const parsed: JobInterviewRecord = { questionId, record, setId, ref, observedSet, timeKind, at, original };
491
+ recordsByLocator.set(record, parsed);
492
+ return parsed;
493
+ });
494
+ const seenDiagnosticRecords = new Set<string>();
495
+ const diagnostics: JobInterviewDiagnostic[] = item.diagnostics.map(rawDiag => {
496
+ const diag = exactObject(rawDiag, ['record', 'at', 'code', 'severity'], code);
497
+ const record = asCode(() => jobText(diag.record, 256), code);
498
+ const at = diag.at === null ? null : asCode(() => jobText(diag.at), code);
499
+ if (seenDiagnosticRecords.has(record)) throw new JobError(code);
500
+ const matching = recordsByLocator.get(record);
501
+ if (!matching || matching.at !== at) throw new JobError(code);
502
+ if (matching.timeKind === 'decision' && matching.original &&
503
+ !['at', 'value', 'fragments'].some(key => Object.hasOwn(matching.original!, key))) {
504
+ throw new JobError(code);
505
+ }
506
+ seenDiagnosticRecords.add(record);
507
+ if (diag.code === 'INTERVIEW_OPTIONS_STALE' && diag.severity === 'error') {
508
+ return { record, at, code: 'INTERVIEW_OPTIONS_STALE', severity: 'error' };
509
+ }
510
+ if (diag.code === 'INTERVIEW_OPTIONS_SCENE_LEGACY' && diag.severity === 'warning') {
511
+ return { record, at, code: 'INTERVIEW_OPTIONS_SCENE_LEGACY', severity: 'warning' };
512
+ }
513
+ throw new JobError(code);
514
+ });
515
+ return {
516
+ schema: 'rig-review/job-interview@1',
517
+ project,
518
+ evaluatedAt,
519
+ records,
520
+ diagnostics,
521
+ };
522
+ }
523
+
380
524
  function parseFileClosure(
381
525
  rawInputs: unknown,
382
526
  rawFiles: unknown,
@@ -440,9 +584,6 @@ function parsePlanSubjects(
440
584
  if (!Array.isArray(rawSubjects) || rawSubjects.length > maxRecordFiles) {
441
585
  throw new JobError(code);
442
586
  }
443
- if (rawSubjects.length > 0 && stepIds.size === 0) {
444
- throw new JobError(code);
445
- }
446
587
  const seen = new Set<string>();
447
588
  return rawSubjects.map(raw => {
448
589
  const parsed = asCode(() => parseRecordSubject(raw), code);
@@ -454,6 +595,13 @@ function parsePlanSubjects(
454
595
  seen.add(key);
455
596
  return { kind: 'checkpoint', checkpointId: parsed.checkpointId };
456
597
  }
598
+ if (parsed.kind === 'reopen') {
599
+ const key = `reopen:${parsed.stage}`;
600
+ if (seen.has(key)) throw new JobError(code);
601
+ seen.add(key);
602
+ return { kind: 'reopen', stage: parsed.stage };
603
+ }
604
+ if (stepIds.size === 0) throw new JobError(code);
457
605
  const key = `signoff:${parsed.stage}`;
458
606
  if (seen.has(key)) throw new JobError(code);
459
607
  seen.add(key);
@@ -872,14 +1020,17 @@ export function validateRecordAskSubject(subject: unknown, source: RecordSource)
872
1020
  }
873
1021
  return parsed;
874
1022
  }
875
- if (parsed.kind === 'interview-picks' || checkedSource.plan.steps.length === 0) {
1023
+ if (
1024
+ parsed.kind === 'interview-picks' ||
1025
+ ((parsed.kind === 'checkpoint' || parsed.kind === 'signoff') && checkedSource.plan.steps.length === 0)
1026
+ ) {
876
1027
  throw new JobError('JOB_ASK_INVALID');
877
1028
  }
878
1029
  const declared = checkedSource.subjects.some(candidate =>
879
1030
  candidate.kind === parsed.kind &&
880
1031
  (candidate.kind === 'checkpoint'
881
1032
  ? candidate.checkpointId === (parsed as Extract<RecordPlanSubject, { kind: 'checkpoint' }>).checkpointId
882
- : candidate.stage === (parsed as Extract<RecordPlanSubject, { kind: 'signoff' }>).stage),
1033
+ : candidate.stage === (parsed as Extract<RecordPlanSubject, { kind: 'signoff' | 'reopen' }>).stage),
883
1034
  );
884
1035
  if (!declared) throw new JobError('JOB_ASK_INVALID');
885
1036
  return parsed;
@@ -993,6 +1144,25 @@ export function parseRecordAct(value: unknown): RecordAct {
993
1144
  value: { stage: stage as RecordSignoffStage, decision: 'approved', words },
994
1145
  };
995
1146
  }
1147
+ case 'reopen': {
1148
+ if (source.subject !== 'plan') throw new JobError('JOB_ACT_INVALID');
1149
+ const rawValue = exactObject(item.value, ['stage', 'words'], 'JOB_ACT_INVALID');
1150
+ const stage = asCode(() => jobId(rawValue.stage), 'JOB_ACT_INVALID');
1151
+ asCode(() => validateRecordAskSubject({ kind: 'reopen', stage }, source), 'JOB_ACT_INVALID');
1152
+ const words = parseActWords(rawValue.words, 'JOB_ACT_INVALID');
1153
+ return {
1154
+ schema: JOB_RECORD_ACT_SCHEMA,
1155
+ actId,
1156
+ jobId: jobIdValue,
1157
+ askId,
1158
+ publicationId,
1159
+ kind: 'reopen',
1160
+ authority,
1161
+ at,
1162
+ source,
1163
+ value: { stage, words },
1164
+ };
1165
+ }
996
1166
  }
997
1167
  throw new JobError('JOB_ACT_INVALID');
998
1168
  }
@@ -1069,10 +1239,21 @@ export function createJobHostPorts(session: JobSession, origin: string): JobHost
1069
1239
  }
1070
1240
  return {
1071
1241
  async handleJobApi(request) {
1072
- let input: JobAgentRequest | JobFetchActRequest | null = null;
1242
+ let input: JobAgentRequest | AgentRequestV3 | JobFetchActRequest | FetchActRequestV3 | null = null;
1243
+ let responseSchema: typeof JOB_API_SCHEMA | typeof JOB_API_V3_SCHEMA = session.apiSchema;
1073
1244
  try {
1074
1245
  gate(request, base + '/api', false);
1075
- input = parseJobRequest(await jobBody(request));
1246
+ const body = await jobBody(request);
1247
+ const mode: JobPublicationMode =
1248
+ session.publicationMode === 'record-and-package' &&
1249
+ body !== null &&
1250
+ typeof body === 'object' &&
1251
+ !Array.isArray(body) &&
1252
+ (body as { schema?: unknown }).schema === JOB_API_SCHEMA
1253
+ ? 'package-only'
1254
+ : session.publicationMode;
1255
+ responseSchema = jobApiSchemaForMode(mode);
1256
+ input = parseJobRequest(body, mode);
1076
1257
  if (input.jobId !== session.jobId) throw new JobError('JOB_UNKNOWN');
1077
1258
  session.authorize(input.verb === 'fetch-act' ? 'consumer' : 'agent', request.headers.get('authorization'));
1078
1259
  if (input.verb === 'fetch-act') {
@@ -1086,13 +1267,13 @@ export function createJobHostPorts(session: JobSession, origin: string): JobHost
1086
1267
  if (accept && accept !== '*/*' && accept !== 'application/json') throw new JobError('JOB_REQUEST_INVALID');
1087
1268
  }
1088
1269
  const value = await session.execute(input, request.signal);
1089
- return Response.json({ schema: JOB_API_SCHEMA, verb: input.verb, jobId: input.jobId, requestId: input.requestId,
1270
+ return Response.json({ schema: responseSchema, verb: input.verb, jobId: input.jobId, requestId: input.requestId,
1090
1271
  generation: session.status().generation, ok: true, value }, { headers: responseHeaders });
1091
1272
  } catch (error) {
1092
1273
  const failure = jobFailure(error);
1093
1274
  const status = failure.error.code.includes('CAPABILITY') || failure.error.code === 'JOB_AUTHORITY_REFUSED' ? 403 :
1094
1275
  failure.error.code === 'JOB_BODY_LIMIT' ? 413 : failure.error.code === 'JOB_REQUEST_INVALID' ? 400 : 409;
1095
- return Response.json({ schema: JOB_API_SCHEMA, verb: input?.verb ?? null, jobId: session.jobId,
1276
+ return Response.json({ schema: responseSchema, verb: input?.verb ?? null, jobId: session.jobId,
1096
1277
  requestId: input?.requestId ?? null, generation: session.lastObservedGeneration, ...failure }, { status, headers: responseHeaders });
1097
1278
  }
1098
1279
  },
@@ -39,8 +39,16 @@ export const JOB_ENABLED_ACT_KINDS = [
39
39
  'signoff',
40
40
  ] as const;
41
41
 
42
+ export const JOB_RECORD_ACT_KINDS = [
43
+ 'interview-picks',
44
+ 'checkpoint',
45
+ 'signoff',
46
+ 'reopen',
47
+ ] as const;
48
+
42
49
  export const JOB_RESERVED_ACT_KINDS = ['described-correction', 'mesh-edit'] as const;
43
50
  export type JobEnabledActKind = typeof JOB_ENABLED_ACT_KINDS[number];
51
+ export type RecordActKind = typeof JOB_RECORD_ACT_KINDS[number];
44
52
  export type JobReservedActKind = typeof JOB_RESERVED_ACT_KINDS[number];
45
53
  export type JobActKind = JobEnabledActKind | JobReservedActKind;
46
54
 
@@ -384,6 +392,47 @@ export interface JobPendingAsk {
384
392
  readonly status: 'pending' | 'answered' | 'superseded';
385
393
  }
386
394
 
395
+ export type JobInterviewJson =
396
+ | null
397
+ | boolean
398
+ | number
399
+ | string
400
+ | readonly JobInterviewJson[]
401
+ | { readonly [key: string]: JobInterviewJson };
402
+
403
+ export interface JobInterviewRecord {
404
+ readonly questionId: string;
405
+ readonly record: string;
406
+ readonly setId: string | null;
407
+ readonly ref: JobFileIdentity;
408
+ readonly observedSet: JobFileIdentity | null;
409
+ readonly timeKind: 'inspection' | 'answer' | 'decision';
410
+ readonly at: string | null;
411
+ readonly original: { readonly [key: string]: JobInterviewJson } | null;
412
+ }
413
+
414
+ export type JobInterviewDiagnostic = {
415
+ readonly record: string;
416
+ readonly at: string | null;
417
+ } & (
418
+ | {
419
+ readonly code: 'INTERVIEW_OPTIONS_STALE';
420
+ readonly severity: 'error';
421
+ }
422
+ | {
423
+ readonly code: 'INTERVIEW_OPTIONS_SCENE_LEGACY';
424
+ readonly severity: 'warning';
425
+ }
426
+ );
427
+
428
+ export interface JobInterviewDiagnostics {
429
+ readonly schema: 'rig-review/job-interview@1';
430
+ readonly project: JobFileIdentity;
431
+ readonly evaluatedAt: string;
432
+ readonly records: readonly JobInterviewRecord[];
433
+ readonly diagnostics: readonly JobInterviewDiagnostic[];
434
+ }
435
+
387
436
  export interface JobPublication {
388
437
  readonly publicationId: JobPublicationId;
389
438
  readonly instanceKey: JobSha256;
@@ -395,6 +444,7 @@ export interface JobPublication {
395
444
  readonly status: 'unavailable';
396
445
  readonly code: string;
397
446
  };
447
+ readonly interview?: JobInterviewDiagnostics | null;
398
448
  }
399
449
 
400
450
  export interface JobStatus {
@@ -607,9 +657,9 @@ export interface JobHostPorts {
607
657
  readonly jobId: JobId;
608
658
  readonly after: JobCursor | null;
609
659
  readonly signal: AbortSignal;
610
- }): AsyncIterable<JobEvent>;
611
- readPublication(jobId: JobId, publicationId: JobPublicationId): Promise<JobResult<JobDisplayPublication>>;
612
- commitUIAct(jobId: JobId, request: Request): Promise<JobResult<JobAct>>;
660
+ }): AsyncIterable<EventV3>;
661
+ readPublication(jobId: JobId, publicationId: JobPublicationId): Promise<JobResult<DisplayPublicationV3>>;
662
+ commitUIAct(jobId: JobId, request: Request): Promise<JobResult<ActV3>>;
613
663
  ackDisplayed(jobId: JobId, request: Request): Promise<JobResult<JobDisplayReceipt>>;
614
664
  jobLiveness(jobId: JobId): Promise<JobResult<{
615
665
  readonly active: boolean;
@@ -690,8 +740,9 @@ export type PublishRequestV3 = Omit<JobPublishRequest, 'schema' | 'result' | 'fr
690
740
  }
691
741
  );
692
742
 
693
- export type AskRequestV3 = Omit<JobAskRequest, 'schema'> & {
743
+ export type AskRequestV3 = Omit<JobAskRequest, 'schema' | 'subject'> & {
694
744
  readonly schema: typeof JOB_API_V3_SCHEMA;
745
+ readonly subject: JobSubject | RecordSubject;
695
746
  };
696
747
 
697
748
  export type NextRequestV3 = Omit<JobNextRequest, 'schema'> & {
@@ -730,7 +781,12 @@ export interface RecordSignoffSubject {
730
781
  readonly stage: RecordSignoffStage;
731
782
  }
732
783
 
733
- export type RecordPlanSubject = RecordCheckpointSubject | RecordSignoffSubject;
784
+ export interface RecordReopenSubject {
785
+ readonly kind: 'reopen';
786
+ readonly stage: JobId;
787
+ }
788
+
789
+ export type RecordPlanSubject = RecordCheckpointSubject | RecordSignoffSubject | RecordReopenSubject;
734
790
  export type RecordSubject = RecordPicksSubject | RecordPlanSubject;
735
791
 
736
792
  export interface RecordPartsIdentity {
@@ -781,6 +837,15 @@ export interface RecordHostHooks {
781
837
  }
782
838
 
783
839
  export interface RecordSourceBase {
840
+ readonly package?: never;
841
+ readonly selector?: never;
842
+ readonly model?: never;
843
+ readonly direction?: never;
844
+ readonly appliedResult?: never;
845
+ readonly parts?: never;
846
+ readonly imageSet?: never;
847
+ readonly imageSetDigest?: never;
848
+ readonly duplicateHashes?: never;
784
849
  readonly sourceHash: JobSha256;
785
850
  readonly projectHash: JobSha256;
786
851
  readonly record: ProjectRecord;
@@ -812,6 +877,34 @@ export type RecordSignoffValue = Omit<JobActValues['signoff'], 'stage'> & {
812
877
  readonly stage: RecordSignoffStage;
813
878
  };
814
879
 
880
+ export interface RecordReopenValue {
881
+ readonly stage: JobId;
882
+ readonly words: string;
883
+ }
884
+
885
+ export interface RecordUIActValues {
886
+ readonly 'interview-picks': JobUIActValues['interview-picks'];
887
+ readonly checkpoint: JobUIActValues['checkpoint'];
888
+ readonly signoff: JobUIActValues['signoff'];
889
+ readonly reopen: RecordReopenValue;
890
+ }
891
+
892
+ export type RecordUISubmission = {
893
+ [Kind in keyof RecordUIActValues]: {
894
+ readonly publicationId: JobPublicationId;
895
+ readonly askId: JobAskId;
896
+ readonly pageId: string;
897
+ readonly displayedNonce: string;
898
+ readonly expectedGeneration: number;
899
+ readonly submissionId: string;
900
+ readonly kind: Kind;
901
+ readonly value: RecordUIActValues[Kind];
902
+ readonly capture?: never;
903
+ };
904
+ }[keyof RecordUIActValues];
905
+
906
+ export type UISubmissionV3 = JobUISubmission | RecordUISubmission;
907
+
815
908
  export type RecordAct = Pick<JobLegacyAct,
816
909
  'actId' | 'jobId' | 'askId' | 'publicationId' | 'authority' | 'at'> & {
817
910
  readonly schema: typeof JOB_RECORD_ACT_SCHEMA;
@@ -831,6 +924,11 @@ export type RecordAct = Pick<JobLegacyAct,
831
924
  readonly source: PlanSource;
832
925
  readonly value: RecordSignoffValue;
833
926
  }
927
+ | {
928
+ readonly kind: 'reopen';
929
+ readonly source: PlanSource;
930
+ readonly value: RecordReopenValue;
931
+ }
834
932
  );
835
933
 
836
934
  export type SourceV3 = JobSourceBinding | RecordSource;
@@ -847,7 +945,8 @@ export const JOB_CAPABILITIES_V3: JobCapabilitiesV3 = Object.freeze({
847
945
  recordActSchema: JOB_RECORD_ACT_SCHEMA,
848
946
  });
849
947
 
850
- export interface PendingAskV3 extends Omit<JobPendingAsk, 'source'> {
948
+ export interface PendingAskV3 extends Omit<JobPendingAsk, 'subject' | 'source'> {
949
+ readonly subject: JobSubject | RecordSubject;
851
950
  readonly source: SourceV3;
852
951
  }
853
952
 
@@ -855,6 +954,10 @@ export interface PublicationV3 extends Omit<JobPublication, 'source'> {
855
954
  readonly source: SourceV3;
856
955
  }
857
956
 
957
+ export interface DisplayPublicationV3 extends Omit<JobDisplayPublication, 'publication'> {
958
+ readonly publication: PublicationV3;
959
+ }
960
+
858
961
  export interface StatusV3 extends Omit<JobStatus, 'publication' | 'pending'> {
859
962
  readonly publication: PublicationV3 | null;
860
963
  readonly pending: readonly PendingAskV3[];
@@ -872,7 +975,7 @@ export type EventV3 = {
872
975
  );
873
976
 
874
977
  export interface NextValueV3 {
875
- readonly capabilities?: JobCapabilitiesV3;
978
+ readonly capabilities?: JobCapabilities | JobCapabilitiesV3;
876
979
  readonly events: readonly EventV3[];
877
980
  readonly cursor: JobCursor | null;
878
981
  readonly status: 'events' | 'timeout' | 'closed';
@@ -912,8 +1015,10 @@ export type JobRecordPicksSubject = RecordPicksSubject;
912
1015
  export type JobRecordCheckpointSubject = RecordCheckpointSubject;
913
1016
  export type JobRecordSignoffStage = RecordSignoffStage;
914
1017
  export type JobRecordSignoffSubject = RecordSignoffSubject;
1018
+ export type JobRecordReopenSubject = RecordReopenSubject;
915
1019
  export type JobRecordPlanSubject = RecordPlanSubject;
916
1020
  export type JobRecordSubject = RecordSubject;
1021
+ export type JobRecordActKind = RecordActKind;
917
1022
  export type JobRecordPartsIdentity = RecordPartsIdentity;
918
1023
  export type JobRecordContextBase = RecordContextBase;
919
1024
  export type JobOptionContext = OptionContext;
@@ -927,11 +1032,16 @@ export type JobOptionSource = OptionSource;
927
1032
  export type JobPlanSource = PlanSource;
928
1033
  export type JobRecordSource = RecordSource;
929
1034
  export type JobRecordSignoffValue = RecordSignoffValue;
1035
+ export type JobRecordReopenValue = RecordReopenValue;
1036
+ export type JobRecordUIActValues = RecordUIActValues;
1037
+ export type JobRecordUISubmission = RecordUISubmission;
1038
+ export type JobUISubmissionV3 = UISubmissionV3;
930
1039
  export type JobRecordAct = RecordAct;
931
1040
  export type JobSourceV3 = SourceV3;
932
1041
  export type JobActV3 = ActV3;
933
1042
  export type JobPendingAskV3 = PendingAskV3;
934
1043
  export type JobPublicationV3 = PublicationV3;
1044
+ export type JobDisplayPublicationV3 = DisplayPublicationV3;
935
1045
  export type JobStatusV3 = StatusV3;
936
1046
  export type JobEventV3 = EventV3;
937
1047
  export type JobNextValueV3 = NextValueV3;