返回 CodeWhale
capture-caption.ts
根目录 / web / lib / capture-caption.ts
1 export type CaptionKey = "captionReleased";
2
3 export type CaptureFrameRef = {
4 id?: string;
5 provenance: "released";
6 shows?: {
7 testRun: boolean;
8 askPosture: boolean;
9 modelName: boolean;
10 modelConnected: boolean;
11 taskSession: boolean;
12 };
13 };
14
15 export type CaptureFrameNote = {
16 id: string | null;
17 lacksAskPosture: boolean;
18 lacksModelName: boolean;
19 needsPostureNote: boolean;
20 };
21
22 export type CaptureCaption = {
23 caption: CaptionKey | null;
24 reason: string | null;
25 frames: CaptureFrameNote[];
26 };
27
28 export function frameNote(frame: CaptureFrameRef): CaptureFrameNote {
29 const shows = frame.shows;
30 const lacksAskPosture = shows ? !shows.askPosture : false;
31 const lacksModelName = shows ? shows.modelConnected && !shows.modelName : false;
32 return {
33 id: frame.id ?? null,
34 lacksAskPosture,
35 lacksModelName,
36 needsPostureNote: lacksAskPosture || lacksModelName,
37 };
38 }
39
40 export function captureCaption(frames: readonly CaptureFrameRef[]): CaptureCaption {
41 const notes = frames.map(frameNote);
42 const none = (reason: string): CaptureCaption => ({ caption: null, reason, frames: notes });
43 if (frames.length === 0) return none("no frames");
44 const released = frames.map((frame) => frame.shows);
45 if (released.some((shows) => !shows)) return none("a released frame carries no record of what it shows");
46 if (released.some((shows) => !shows?.taskSession)) {
47 return none("a frame from before the task is shown, and the caption is about the task");
48 }
49 if (!released.some((shows) => shows?.testRun)) {
50 return none("no frame shown has a test run in it, and the caption says the tests ran");
51 }
52 return { caption: "captionReleased", reason: null, frames: notes };
53 }
54
54 lines TYPESCRIPT