|
1 | 1 | import type { ScreenshotResultData } from '@agent-device/contracts/capture'; |
2 | 2 | import type { CaptureScreenshotResult } from '@agent-device/contracts/client'; |
3 | 3 | import { isRecord, parsePoint, parseRect, readRequiredString } from '@agent-device/kernel/record'; |
| 4 | +import { readResponseWarnings } from '@agent-device/kernel/success-text'; |
4 | 5 | import type { ScreenshotOverlayRef } from '@agent-device/kernel/snapshot'; |
5 | 6 |
|
6 | 7 | export function pickScreenshotResultData(value: ScreenshotResultData): ScreenshotResultData { |
@@ -45,7 +46,7 @@ type ScreenshotOverlayRefData = { |
45 | 46 |
|
46 | 47 | function readScreenshotResultData(value: unknown): ScreenshotResultData | undefined { |
47 | 48 | if (!isRecord(value)) return undefined; |
48 | | - const warnings = readScreenshotWarnings(value.warnings); |
| 49 | + const warnings = readScreenshotWarnings(value); |
49 | 50 | return pickScreenshotResultData({ |
50 | 51 | path: readStringField(value, 'path'), |
51 | 52 | width: readNumberField(value, 'width'), |
@@ -76,9 +77,11 @@ function readScreenshotOverlayRefs(value: unknown): ScreenshotOverlayRef[] | und |
76 | 77 | }); |
77 | 78 | } |
78 | 79 |
|
79 | | -function readScreenshotWarnings(value: unknown): string[] | undefined { |
80 | | - if (!Array.isArray(value)) return undefined; |
81 | | - return value.filter((entry): entry is string => typeof entry === 'string' && entry.length > 0); |
| 80 | +function readScreenshotWarnings(data: Record<string, unknown>): string[] | undefined { |
| 81 | + // An absent or non-array field is "no warnings channel on this result"; |
| 82 | + // the field contract itself is the shared parser's. |
| 83 | + if (!Array.isArray(data.warnings)) return undefined; |
| 84 | + return readResponseWarnings(data).filter((warning) => warning.length > 0); |
82 | 85 | } |
83 | 86 |
|
84 | 87 | function readScreenshotOverlayRef( |
|
0 commit comments