Open source CapCut alternative.
TypeScript
refactor(app): remove dead off-the-shelf vision CV stubs
David Le35d17f26a673
diff --git a/apps/Donkey/Sources/DonkeyRuntime/OffTheShelfVisionPerception.swift b/apps/Donkey/Sources/DonkeyRuntime/OffTheShelfVisionPerception.swiftdeleted file mode 100644index 16159ee8..00000000--- a/apps/Donkey/Sources/DonkeyRuntime/OffTheShelfVisionPerception.swift+++ /dev/null@@ -1,323 +0,0 @@-import DonkeyContracts-import Foundation--public enum OffTheShelfVisionSignalKind: String, Codable, Equatable, Sendable {- case detector- case template- case ocr- case segmentation-}--public enum OffTheShelfVisionInputSource: String, Codable, Equatable, Sendable {- case screenshot- case crop- case recorded-}--public struct OffTheShelfVisionModelCandidate: Codable, Equatable, Sendable {- public var id: String- public var family: String- public var modelName: String- public var signalKind: OffTheShelfVisionSignalKind- public var preferredInputSource: OffTheShelfVisionInputSource- public var componentID: String- public var docsURL: URL- public var lastVerifiedAt: String- public var metadata: [String: String]-- public init(- id: String,- family: String,- modelName: String,- signalKind: OffTheShelfVisionSignalKind,- preferredInputSource: OffTheShelfVisionInputSource,- componentID: String,- docsURL: URL,- lastVerifiedAt: String,- metadata: [String: String] = [:]- ) {- self.id = id- self.family = family- self.modelName = modelName- self.signalKind = signalKind- self.preferredInputSource = preferredInputSource- self.componentID = componentID- self.docsURL = docsURL- self.lastVerifiedAt = lastVerifiedAt- self.metadata = metadata- }-}--public enum OffTheShelfVisionModelCatalog {- public static let stubbedScreenshotSegmentation = OffTheShelfVisionModelCandidate(- id: "stubbed-screenshot-segmentation",- family: "stub",- modelName: "stubbed",- signalKind: .segmentation,- preferredInputSource: .recorded,- componentID: "screenshot-segmentation-stub",- docsURL: URL(string: "https://github.com/dle87/donkey")!,- lastVerifiedAt: "2026-05-26",- metadata: [- "provider": "none",- "task": "stub",- "reason": "cvPipelineRemovedPendingReplacement",- "liveDefault": "false",- "rawPixelsRead": "false"- ]- )-- public static var screenshotSegmentationCandidates: [OffTheShelfVisionModelCandidate] {- []- }-- public static func defaultCandidate(- signalKind: OffTheShelfVisionSignalKind,- inputSource: OffTheShelfVisionInputSource- ) -> OffTheShelfVisionModelCandidate? {- _ = signalKind- _ = inputSource- return nil- }-}--public struct RecordedOffTheShelfVisionObservation: Codable, Equatable, Sendable {- public var id: String- public var label: String- public var bounds: HotLoopRect?- public var confidence: Double- public var metadata: [String: String]-- public init(- id: String,- label: String,- bounds: HotLoopRect? = nil,- confidence: Double,- metadata: [String: String] = [:]- ) {- self.id = id- self.label = label- self.bounds = bounds- self.confidence = Self.clamped(confidence)- self.metadata = metadata- }-- private static func clamped(_ value: Double) -> Double {- min(max(value, 0), 1)- }-}--public struct RecordedOffTheShelfVisionSignal: Codable, Equatable, Sendable {- public var id: String- public var kind: OffTheShelfVisionSignalKind- public var componentID: String- public var modelID: String?- public var cropID: String?- public var confidence: Double- public var observations: [RecordedOffTheShelfVisionObservation]- public var preprocessMS: Double- public var modelInferenceMS: Double- public var adapterOverheadMS: Double- public var metadata: [String: String]-- public init(- id: String,- kind: OffTheShelfVisionSignalKind,- componentID: String,- modelID: String? = nil,- cropID: String? = nil,- confidence: Double,- observations: [RecordedOffTheShelfVisionObservation],- preprocessMS: Double = 0,- modelInferenceMS: Double = 0,- adapterOverheadMS: Double = 1,- metadata: [String: String] = [:]- ) {- self.id = id- self.kind = kind- self.componentID = componentID- self.modelID = modelID- self.cropID = cropID- self.confidence = Self.clamped(confidence)- self.observations = observations- self.preprocessMS = max(0, preprocessMS)- self.modelInferenceMS = max(0, modelInferenceMS)- self.adapterOverheadMS = max(0, adapterOverheadMS)- self.metadata = metadata- }-- private static func clamped(_ value: Double) -> Double {- min(max(value, 0), 1)- }-}--public enum RecordedOffTheShelfVisionMetadataCodec {- public static func encode(signals: [RecordedOffTheShelfVisionSignal]) -> [String: String] {- var metadata = [- "vision.offTheShelf.encoded": "true",- "vision.offTheShelf.rawPixelsExposed": "false",- "vision.offTheShelf.signal.count": String(signals.count)- ]-- for (signalIndex, signal) in signals.enumerated() {- let prefix = "vision.offTheShelf.signal.\(signalIndex)."- metadata[prefix + "id"] = signal.id- metadata[prefix + "kind"] = signal.kind.rawValue- metadata[prefix + "componentID"] = signal.componentID- metadata[prefix + "modelID"] = signal.modelID ?? ""- metadata[prefix + "cropID"] = signal.cropID ?? ""- metadata[prefix + "confidence"] = String(signal.confidence)- metadata[prefix + "latency.preprocessMS"] = String(signal.preprocessMS)- metadata[prefix + "latency.modelInferenceMS"] = String(signal.modelInferenceMS)- metadata[prefix + "latency.adapterOverheadMS"] = String(signal.adapterOverheadMS)- metadata[prefix + "observation.count"] = String(signal.observations.count)- for (key, value) in signal.metadata {- metadata[prefix + "metadata.\(key)"] = value- }-- for (observationIndex, observation) in signal.observations.enumerated() {- let observationPrefix = prefix + "observation.\(observationIndex)."- metadata[observationPrefix + "id"] = observation.id- metadata[observationPrefix + "label"] = observation.label- metadata[observationPrefix + "confidence"] = String(observation.confidence)- if let bounds = observation.bounds {- metadata[observationPrefix + "bounds.x"] = String(bounds.origin.x)- metadata[observationPrefix + "bounds.y"] = String(bounds.origin.y)- metadata[observationPrefix + "bounds.width"] = String(bounds.size.width)- metadata[observationPrefix + "bounds.height"] = String(bounds.size.height)- metadata[observationPrefix + "bounds.space"] = bounds.space.rawValue- }- for (key, value) in observation.metadata {- metadata[observationPrefix + "metadata.\(key)"] = value- }- }- }-- return metadata- }-- public static func decode(from metadata: [String: String]) -> [RecordedOffTheShelfVisionSignal] {- let count = Int(metadata["vision.offTheShelf.signal.count"] ?? "") ?? 0- guard count > 0 else { return [] }-- return (0..<count).compactMap { index -> RecordedOffTheShelfVisionSignal? in- let prefix = "vision.offTheShelf.signal.\(index)."- guard let id = nonEmpty(metadata[prefix + "id"]),- let kind = OffTheShelfVisionSignalKind(rawValue: metadata[prefix + "kind"] ?? ""),- let componentID = nonEmpty(metadata[prefix + "componentID"])- else {- return nil- }-- let observationCount = Int(metadata[prefix + "observation.count"] ?? "") ?? 0- let observations = (0..<observationCount).compactMap { observationIndex -> RecordedOffTheShelfVisionObservation? in- let observationPrefix = prefix + "observation.\(observationIndex)."- guard let observationID = nonEmpty(metadata[observationPrefix + "id"]),- let label = nonEmpty(metadata[observationPrefix + "label"])- else {- return nil- }-- return RecordedOffTheShelfVisionObservation(- id: observationID,- label: label,- bounds: decodeBounds(prefix: observationPrefix + "bounds.", metadata: metadata),- confidence: Double(metadata[observationPrefix + "confidence"] ?? "") ?? 0,- metadata: prefixedMetadata(- prefix: observationPrefix + "metadata.",- metadata: metadata- )- )- }-- return RecordedOffTheShelfVisionSignal(- id: id,- kind: kind,- componentID: componentID,- modelID: nonEmpty(metadata[prefix + "modelID"]),- cropID: nonEmpty(metadata[prefix + "cropID"]),- confidence: Double(metadata[prefix + "confidence"] ?? "") ?? 0,- observations: observations,- preprocessMS: Double(metadata[prefix + "latency.preprocessMS"] ?? "") ?? 0,- modelInferenceMS: Double(metadata[prefix + "latency.modelInferenceMS"] ?? "") ?? 0,- adapterOverheadMS: Double(metadata[prefix + "latency.adapterOverheadMS"] ?? "") ?? 1,- metadata: prefixedMetadata(prefix: prefix + "metadata.", metadata: metadata)- )- }- }-- private static func decodeBounds(- prefix: String,- metadata: [String: String]- ) -> HotLoopRect? {- guard let x = Double(metadata[prefix + "x"] ?? ""),- let y = Double(metadata[prefix + "y"] ?? ""),- let width = Double(metadata[prefix + "width"] ?? ""),- let height = Double(metadata[prefix + "height"] ?? ""),- let space = HotLoopCoordinateSpace(rawValue: metadata[prefix + "space"] ?? "")- else {- return nil- }-- return HotLoopRect(x: x, y: y, width: width, height: height, space: space)- }-- private static func prefixedMetadata(- prefix: String,- metadata: [String: String]- ) -> [String: String] {- metadata.reduce(into: [:]) { result, item in- guard item.key.hasPrefix(prefix) else { return }- let key = String(item.key.dropFirst(prefix.count))- guard !key.isEmpty else { return }- result[key] = item.value- }- }-- private static func nonEmpty(_ value: String?) -> String? {- guard let value, !value.isEmpty else { return nil }- return value- }-}--public struct OffTheShelfVisionPerceptionAdapter: DryRunPerceptionAdapting {- public var adapterName: String-- public init(adapterName: String = "off-the-shelf-vision-perception") {- self.adapterName = adapterName- }-- public func perceive(frame: HotLoopFrame) async -> [HotLoopPerceptionSignal] {- _ = frame- return []- }-}--public struct OffTheShelfVisionWorldStateProjector: DryRunWorldStateProjecting {- public var staleSignalThresholdMS: Double-- public init(staleSignalThresholdMS: Double = 250) {- self.staleSignalThresholdMS = staleSignalThresholdMS- }-- public func project(- frame: HotLoopFrame,- signals: [HotLoopPerceptionSignal],- observedAt: RunTraceTimestamp- ) async -> HotLoopWorldState {- HotLoopWorldState.build(- id: "state-\(frame.id)",- frame: frame,- signals: signals,- observedAt: observedAt,- staleThresholdMS: staleSignalThresholdMS,- actionAffordances: [],- metadata: [- "projector": "off-the-shelf-vision-world-state-projector-stub",- "vision.localEvidence": "false",- "rawPixelsExposed": "false",- "reason": "cvPipelineRemovedPendingReplacement"- ]- )- }-}diff --git a/apps/Donkey/Sources/DonkeyRuntime/ScreenshotSegmentationStubRunner.swift b/apps/Donkey/Sources/DonkeyRuntime/ScreenshotSegmentationStubRunner.swiftdeleted file mode 100644index cb7a03bb..00000000--- a/apps/Donkey/Sources/DonkeyRuntime/ScreenshotSegmentationStubRunner.swift+++ /dev/null@@ -1,233 +0,0 @@-import DonkeyContracts-import Foundation--public struct ScreenshotSegmentationRequest: Equatable, Sendable {- public var traceID: String- public var frameID: String- public var targetID: String- public var cropID: String- public var cropImageFileURL: URL?- public var artifactURL: URL?- public var cropBounds: HotLoopRect- public var pixelSize: HotLoopSize- public var metadata: [String: String]-- public init(- traceID: String,- frameID: String,- targetID: String,- cropID: String,- cropImageFileURL: URL? = nil,- artifactURL: URL? = nil,- cropBounds: HotLoopRect,- pixelSize: HotLoopSize,- metadata: [String: String] = [:]- ) {- self.traceID = traceID- self.frameID = frameID- self.targetID = targetID- self.cropID = cropID- self.cropImageFileURL = cropImageFileURL- self.artifactURL = artifactURL- self.cropBounds = cropBounds- self.pixelSize = pixelSize- self.metadata = metadata- }-}--public struct ScreenshotSegmentationMask: Codable, Equatable, Sendable {- public var id: String- public var label: String- public var bounds: HotLoopRect- public var confidence: Double- public var pointCount: Int- public var metadata: [String: String]-- public init(- id: String,- label: String,- bounds: HotLoopRect,- confidence: Double,- pointCount: Int = 0,- metadata: [String: String] = [:]- ) {- self.id = id- self.label = label- self.bounds = bounds- self.confidence = min(max(confidence, 0), 1)- self.pointCount = max(0, pointCount)- self.metadata = metadata- }-}--public struct ScreenshotSegmentationBackendResult: Equatable, Sendable {- public var masks: [ScreenshotSegmentationMask]- public var preprocessMS: Double- public var modelInferenceMS: Double- public var metadata: [String: String]-- public init(- masks: [ScreenshotSegmentationMask],- preprocessMS: Double,- modelInferenceMS: Double,- metadata: [String: String] = [:]- ) {- self.masks = masks- self.preprocessMS = max(0, preprocessMS)- self.modelInferenceMS = max(0, modelInferenceMS)- self.metadata = metadata- }-}--public struct ScreenshotSegmentationResult: Equatable, Sendable {- public var request: ScreenshotSegmentationRequest- public var model: OffTheShelfVisionModelCandidate- public var signal: RecordedOffTheShelfVisionSignal- public var metadata: [String: String]-- public init(- request: ScreenshotSegmentationRequest,- model: OffTheShelfVisionModelCandidate,- signal: RecordedOffTheShelfVisionSignal,- metadata: [String: String]- ) {- self.request = request- self.model = model- self.signal = signal- self.metadata = metadata- }-}--public protocol ScreenshotSegmentationBackend: Sendable {- func segment(- request: ScreenshotSegmentationRequest,- model: OffTheShelfVisionModelCandidate- ) async throws -> ScreenshotSegmentationBackendResult-}--public enum ScreenshotSegmentationRunnerError: Error, Equatable, Sendable {- case noModelCandidate- case backendUnavailable(String)- case invalidOutput(String)-}--public struct UnavailableScreenshotSegmentationBackend: ScreenshotSegmentationBackend {- public init() {}-- public func segment(- request: ScreenshotSegmentationRequest,- model: OffTheShelfVisionModelCandidate- ) async throws -> ScreenshotSegmentationBackendResult {- throw ScreenshotSegmentationRunnerError.backendUnavailable(model.id)- }-}--public struct ProcessBackedScreenshotSegmentationBackend: ScreenshotSegmentationBackend {- public init(- sidecarRunner: any LocalJSONSidecarRunning = ProcessBackedLocalJSONSidecarRunner(),- encoder: JSONEncoder = JSONEncoder(),- decoder: JSONDecoder = JSONDecoder()- ) {- _ = sidecarRunner- _ = encoder- _ = decoder- }-- public func segment(- request: ScreenshotSegmentationRequest,- model: OffTheShelfVisionModelCandidate- ) async throws -> ScreenshotSegmentationBackendResult {- _ = request- _ = model- return ScreenshotSegmentationBackendResult(- masks: [],- preprocessMS: 0,- modelInferenceMS: 0,- metadata: [- "runner": "screenshot-segmentation-stub",- "reason": "cvPipelineRemovedPendingReplacement",- "rawPixelsRead": "false"- ]- )- }-}--public struct ScreenshotSegmentationStubRunner: Sendable {- public var model: OffTheShelfVisionModelCandidate- public var backend: any ScreenshotSegmentationBackend- public var now: @Sendable () -> RunTraceTimestamp-- public init(- model: OffTheShelfVisionModelCandidate = OffTheShelfVisionModelCatalog.stubbedScreenshotSegmentation,- backend: any ScreenshotSegmentationBackend = UnavailableScreenshotSegmentationBackend(),- now: @escaping @Sendable () -> RunTraceTimestamp = Self.defaultNow- ) {- self.model = model- self.backend = backend- self.now = now- }-- public func run(_ request: ScreenshotSegmentationRequest) async throws -> ScreenshotSegmentationResult {- let startedAt = now()- _ = backend- let backendResult = ScreenshotSegmentationBackendResult(- masks: [],- preprocessMS: 0,- modelInferenceMS: 0,- metadata: [- "runner": "screenshot-segmentation-stub",- "reason": "cvPipelineRemovedPendingReplacement",- "rawPixelsRead": "false"- ]- )- let completedAt = now()- let totalMS = startedAt.milliseconds(until: completedAt) ?? 0- let adapterOverheadMS = max(0, totalMS - backendResult.preprocessMS - backendResult.modelInferenceMS)- let signal = RecordedOffTheShelfVisionSignal(- id: "segmentation-\(request.frameID)-\(request.cropID)",- kind: .segmentation,- componentID: model.componentID,- modelID: model.id,- cropID: request.cropID,- confidence: backendResult.masks.map(\.confidence).max() ?? 0,- observations: backendResult.masks.map { mask in- RecordedOffTheShelfVisionObservation(- id: mask.id,- label: mask.label,- bounds: mask.bounds,- confidence: mask.confidence,- metadata: mask.metadata.merging([- "mask.pointCount": String(mask.pointCount)- ]) { current, _ in current }- )- },- preprocessMS: backendResult.preprocessMS,- modelInferenceMS: backendResult.modelInferenceMS,- adapterOverheadMS: adapterOverheadMS,- metadata: [- "runner": "screenshot-segmentation-stub",- "modelFamily": model.family,- "modelName": model.modelName,- "inputSource": model.preferredInputSource.rawValue,- "liveDefault": model.metadata["liveDefault"] ?? "false",- "reason": "cvPipelineRemovedPendingReplacement",- "rawPixelsRead": "false",- "latency.totalMS": String(totalMS)- ].merging(backendResult.metadata) { current, _ in current }- )-- return ScreenshotSegmentationResult(- request: request,- model: model,- signal: signal,- metadata: RecordedOffTheShelfVisionMetadataCodec.encode(signals: [signal])- )- }-- public static func defaultNow() -> RunTraceTimestamp {- RunTraceTimestamp(- wallClock: Date(),- monotonicUptimeNanoseconds: UInt64(ProcessInfo.processInfo.systemUptime * 1_000_000_000)- )- }-}diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/OffTheShelfVisionPerceptionTests.swift b/apps/Donkey/Tests/DonkeyRuntimeTests/OffTheShelfVisionPerceptionTests.swiftdeleted file mode 100644index 8346333f..00000000--- a/apps/Donkey/Tests/DonkeyRuntimeTests/OffTheShelfVisionPerceptionTests.swift+++ /dev/null@@ -1,209 +0,0 @@-import DonkeyContracts-@testable import DonkeyRuntime-import Foundation-import Testing--@Suite-struct OffTheShelfVisionPerceptionTests {- @Test- func modelCatalogDoesNotExposeRunnableScreenshotSegmentationCandidate() {- let candidate = OffTheShelfVisionModelCatalog.defaultCandidate(- signalKind: .segmentation,- inputSource: .screenshot- )-- #expect(candidate == nil)- #expect(OffTheShelfVisionModelCatalog.screenshotSegmentationCandidates.isEmpty)- #expect(OffTheShelfVisionModelCatalog.stubbedScreenshotSegmentation.metadata["reason"] == "cvPipelineRemovedPendingReplacement")- }-- @Test- func metadataCodecRemainsReadOnlyTraceCodecForLegacyArtifacts() throws {- let metadata = RecordedOffTheShelfVisionMetadataCodec.encode(signals: [- RecordedOffTheShelfVisionSignal(- id: "legacy-signal",- kind: .segmentation,- componentID: "legacy-component",- modelID: "legacy-model",- cropID: "legacy-crop",- confidence: 0.88,- observations: [- RecordedOffTheShelfVisionObservation(- id: "legacy-observation",- label: "legacy",- bounds: HotLoopRect(- x: 0.42,- y: 0.58,- width: 0.12,- height: 0.08,- space: .normalizedTarget- ),- confidence: 0.82- )- ]- )- ])-- let signals = RecordedOffTheShelfVisionMetadataCodec.decode(from: metadata)-- #expect(metadata["vision.offTheShelf.rawPixelsExposed"] == "false")- #expect(signals.first?.kind == .segmentation)- #expect(signals.first?.observations.first?.bounds?.space == .normalizedTarget)- }-- @Test- func adapterIgnoresRecordedVisionMetadataWhilePipelineIsStubbed() async throws {- let frame = HotLoopFrame(- id: "frame-local-vision",- traceID: "trace-local-vision",- targetID: "target-visual-game",- capturedAt: timestamp(10),- sourceKind: .recorded,- windowBounds: HotLoopRect(x: 0, y: 0, width: 390, height: 844, space: .screen),- crop: nil,- pixelSize: HotLoopSize(width: 390, height: 844, space: .window),- metadata: RecordedOffTheShelfVisionMetadataCodec.encode(signals: [- RecordedOffTheShelfVisionSignal(- id: "legacy-signal",- kind: .segmentation,- componentID: "legacy-component",- confidence: 0.88,- observations: [- RecordedOffTheShelfVisionObservation(- id: "legacy-observation",- label: "legacy",- bounds: HotLoopRect(x: 0.42, y: 0.58, width: 0.12, height: 0.08, space: .normalizedTarget),- confidence: 0.82- )- ]- )- ])- )-- let signals = await OffTheShelfVisionPerceptionAdapter().perceive(frame: frame)- let state = await OffTheShelfVisionWorldStateProjector().project(- frame: frame,- signals: signals,- observedAt: timestamp(16)- )-- #expect(signals.isEmpty)- #expect(state.actionAffordances.isEmpty)- #expect(state.metadata["vision.localEvidence"] == "false")- #expect(state.metadata["reason"] == "cvPipelineRemovedPendingReplacement")- }-- @Test- func screenshotSegmentationStubRunnerReturnsStubEvidenceOnly() async throws {- let runner = ScreenshotSegmentationStubRunner(now: fixedClock([100, 118]))- let result = try await runner.run(- ScreenshotSegmentationRequest(- traceID: "trace-segmentation-stub",- frameID: "frame-segmentation-stub",- targetID: "target-segmentation-stub",- cropID: "crop-search",- cropImageFileURL: URL(fileURLWithPath: "/tmp/crop-search.png"),- cropBounds: HotLoopRect(x: 0, y: 0, width: 320, height: 180, space: .window),- pixelSize: HotLoopSize(width: 320, height: 180, space: .crop)- )- )- let decoded = RecordedOffTheShelfVisionMetadataCodec.decode(from: result.metadata)- let signal = try #require(decoded.first)-- #expect(result.model.id == "stubbed-screenshot-segmentation")- #expect(signal.kind == .segmentation)- #expect(signal.observations.isEmpty)- #expect(signal.metadata["reason"] == "cvPipelineRemovedPendingReplacement")- #expect(signal.metadata["rawPixelsRead"] == "false")- }-- @Test- func processBackedScreenshotSegmentationRuntimeIsStubbed() async throws {- let backend = ProcessBackedScreenshotSegmentationBackend()- let result = try await backend.segment(- request: ScreenshotSegmentationRequest(- traceID: "trace-sidecar-segmentation-stub",- frameID: "frame-sidecar-segmentation-stub",- targetID: "target-sidecar-segmentation-stub",- cropID: "crop-play",- cropBounds: HotLoopRect(x: 0, y: 0, width: 100, height: 100, space: .window),- pixelSize: HotLoopSize(width: 100, height: 100, space: .crop)- ),- model: OffTheShelfVisionModelCatalog.stubbedScreenshotSegmentation- )-- #expect(result.masks.isEmpty)- #expect(result.preprocessMS == 0)- #expect(result.modelInferenceMS == 0)- #expect(result.metadata["reason"] == "cvPipelineRemovedPendingReplacement")- }-- @Test- func localUIUnderstandingSidecarFeedsObservationShape() async throws {- let adapter = ProcessBackedLocalUIUnderstandingAdapter(- sidecarRunner: StubbedLocalUIUnderstandingSidecarRunner(- result: LocalJSONSidecarResult(- status: .completed,- outputData: Data("""- {"visibleText":{"title":"Music","result":"Sample Result"},"controls":[{"id":"search","label":"Search","kind":"searchField","frame":{"x":0.1,"y":0.1,"width":0.8,"height":0.08,"space":"normalizedTarget"},"confidence":0.86,"metadata":{"controlID":"search"}}],"formFields":[],"confidence":0.84,"metadata":{"understander":"fake-local-llm"}}- """.utf8),- metadata: ["sidecar.reason": "completed"]- )- )- )- let request = LocalUIUnderstandingRequest(- traceID: "trace-ui-understanding",- targetID: "music-app",- imageFileURL: URL(fileURLWithPath: "/tmp/music-crop.png")- )-- let result = try await adapter.understand(request)- let observation = result.observation(for: request)-- #expect(observation.availableControls["search"] == true)- #expect(observation.visibleText["result"] == "Sample Result")- #expect(observation.metadata["directInputActionsAllowed"] == "false")- #expect(observation.metadata["understander"] == "fake-local-llm")- }-- private func timestamp(_ milliseconds: UInt64) -> RunTraceTimestamp {- RunTraceTimestamp(- wallClock: Date(timeIntervalSince1970: Double(milliseconds) / 1_000),- monotonicUptimeNanoseconds: milliseconds * 1_000_000- )- }-- private func fixedClock(_ milliseconds: [UInt64]) -> @Sendable () -> RunTraceTimestamp {- let clock = FixedVisionClock(milliseconds: milliseconds)- return {- clock.next()- }- }-}--private final class FixedVisionClock: @unchecked Sendable {- private var milliseconds: [UInt64]- private var index = 0-- init(milliseconds: [UInt64]) {- self.milliseconds = milliseconds- }-- func next() -> RunTraceTimestamp {- let value = milliseconds[min(index, milliseconds.count - 1)]- index += 1- return RunTraceTimestamp(- wallClock: Date(timeIntervalSince1970: Double(value) / 1_000),- monotonicUptimeNanoseconds: value * 1_000_000- )- }-}--private struct StubbedLocalUIUnderstandingSidecarRunner: LocalJSONSidecarRunning {- var result: LocalJSONSidecarResult-- func run(_ request: LocalJSONSidecarRequest) async -> LocalJSONSidecarResult {- _ = request- return result- }-}