Skip to content

Open source CapCut alternative.

TypeScript

Generalize screenshot parser provider metadata

David Lef4ac745e5795
diff --git a/apps/Donkey/Sources/Donkey/LocalUIElementDetection/DebugUIInspectionCoordinator.swift b/apps/Donkey/Sources/Donkey/LocalUIElementDetection/DebugUIInspectionCoordinator.swift
index 55c05717..5479361c 100644
--- a/apps/Donkey/Sources/Donkey/LocalUIElementDetection/DebugUIInspectionCoordinator.swift
+++ b/apps/Donkey/Sources/Donkey/LocalUIElementDetection/DebugUIInspectionCoordinator.swift
@@ -201,7 +201,7 @@ final class DebugUIInspectionCoordinator {
}
private func analyzeVisibleScreens(force: Bool) async throws {
- try await analyzeGeminiWindowScreens(force: force)
+ try await analyzeRemoteAIWindowScreens(force: force)
}
private func needsTrackerWarmup(screenID: UInt32) -> Bool {
@@ -350,7 +350,7 @@ final class DebugUIInspectionCoordinator {
)
let fusedFrame = DebugUIInspectionFrameFusion.fused(
accessibilityFrame: progressiveAccessibilityFrame,
- geminiFrame: nonAccessibilityFrame
+ aiFrame: nonAccessibilityFrame
)
guard !fusedFrame.elements.isEmpty,
lastRenderedFrames[screen.screenID]?.isOverlayRenderEquivalent(to: fusedFrame) != true
@@ -442,12 +442,12 @@ final class DebugUIInspectionCoordinator {
overlayController.closeScreens(except: activeScreenIDs)
}
- private func analyzeGeminiWindowScreens(force: Bool) async throws {
+ private func analyzeRemoteAIWindowScreens(force: Bool) async throws {
let screens = try screenSurfaces(scope: currentConfig.screenScope)
let activeScreenIDs = Set(screens.map(\.screenID))
overlayController.closeScreens(except: activeScreenIDs)
lastRenderedFrames = lastRenderedFrames.filter { activeScreenIDs.contains($0.key) }
- let accessibilityFrames = accessibilityFramesForGeminiFusion()
+ let accessibilityFrames = accessibilityFramesForRemoteAIFusion()
renderFastLocalFrames(
screens: screens,
frames: accessibilityFrames,
@@ -457,7 +457,7 @@ final class DebugUIInspectionCoordinator {
let targets = visibleOverlayTargets(on: screens)
guard !targets.isEmpty else {
- ageMissingGeminiScreens(activeScreenIDs: Set(accessibilityFrames.keys))
+ ageMissingRemoteAIScreens(activeScreenIDs: Set(accessibilityFrames.keys))
for screen in screens where accessibilityFrames[screen.screenID] != nil {
let accessibilityFrame = accessibilityFrames[screen.screenID] ?? DebugUIInspectionFrame()
let fingerprint = Self.fingerprint(
@@ -486,7 +486,7 @@ final class DebugUIInspectionCoordinator {
for target in targets {
do {
let screenshot = try await windowScreenshotCapturer.capture(target: target)
- let compressed = Self.compressedGeminiImage(from: screenshot)
+ let compressed = Self.compressedRemoteAIImage(from: screenshot)
captures.append(
DebugUIWindowCapture(
target: target,
@@ -498,7 +498,7 @@ final class DebugUIInspectionCoordinator {
)
} catch {
DebugUIInspectionLog.overlay.error(
- "debug inspection skipped gemini windowID=\(target.windowID, privacy: .public) error=\(String(describing: error), privacy: .public)"
+ "debug inspection skipped remote AI windowID=\(target.windowID, privacy: .public) error=\(String(describing: error), privacy: .public)"
)
}
}
@@ -506,7 +506,7 @@ final class DebugUIInspectionCoordinator {
let renderedScreenIDs = Set(captures.flatMap { capture in
screens.filter { Self.intersects(capture.target.bounds, $0.captureFrame) }.map(\.screenID)
}).union(accessibilityFrames.keys)
- ageMissingGeminiScreens(activeScreenIDs: renderedScreenIDs)
+ ageMissingRemoteAIScreens(activeScreenIDs: renderedScreenIDs)
for screen in screens where renderedScreenIDs.contains(screen.screenID) {
let screenBounds = screen.captureFrame
@@ -519,7 +519,7 @@ final class DebugUIInspectionCoordinator {
)
guard force || lastFingerprints[screen.screenID] != fingerprint || needsTrackerWarmup(screenID: screen.screenID) else {
DebugUIInspectionLog.overlay.debug(
- "debug inspection skipped unchanged gemini screenID=\(screen.screenID, privacy: .public)"
+ "debug inspection skipped unchanged remote AI screenID=\(screen.screenID, privacy: .public)"
)
continue
}
@@ -534,12 +534,12 @@ final class DebugUIInspectionCoordinator {
return currentWindowIDs.contains(windowID)
}
- func renderGeminiFrame(stage: String, updatesFingerprint: Bool) {
+ func renderRemoteAIFrame(stage: String, updatesFingerprint: Bool) {
var tracker = trackers[screen.screenID] ?? DebugUIElementTracker()
- let geminiFrame = DebugUIInspectionFrame(elements: elements)
+ let remoteAIFrame = DebugUIInspectionFrame(elements: elements)
let fusedFrame = DebugUIInspectionFrameFusion.fused(
accessibilityFrame: localEvidenceFrame,
- geminiFrame: geminiFrame
+ aiFrame: remoteAIFrame
)
let trackedFrame = tracker.update(
with: fusedFrame,
@@ -575,7 +575,7 @@ final class DebugUIInspectionCoordinator {
space: .window
)
let request = LocalUIUnderstandingRequest(
- traceID: "debug-ui-gemini-\(screen.screenID)-\(capture.target.windowID)-\(fingerprint)",
+ traceID: "debug-ui-ai-\(screen.screenID)-\(capture.target.windowID)-\(fingerprint)",
targetID: "window-\(capture.target.windowID)",
imageFileURL: nil,
cropBounds: HotLoopRect(
@@ -588,7 +588,6 @@ final class DebugUIInspectionCoordinator {
pixelSize: capturePixelSize,
metadata: [
"source": "debug-ui-inspection-overlay",
- "donkeyVision.ai": "gemini",
"screenshot.scope": "targetWindow",
"screenshot.desktopCaptureAllowed": "false",
"target.windowID": String(capture.target.windowID),
@@ -624,7 +623,7 @@ final class DebugUIInspectionCoordinator {
).elements
elements.removeAll { Self.windowID(for: $0) == capture.target.windowID }
elements += parsedElements
- renderGeminiFrame(stage: "gemini-progress", updatesFingerprint: false)
+ renderRemoteAIFrame(stage: "ai-progress", updatesFingerprint: false)
}
let parsedElements = ScreenshotParseDebugUIOverlayMapper.frame(
from: result,
@@ -635,19 +634,19 @@ final class DebugUIInspectionCoordinator {
).elements
elements.removeAll { Self.windowID(for: $0) == capture.target.windowID }
elements += parsedElements
- renderGeminiFrame(stage: "gemini-progress", updatesFingerprint: false)
+ renderRemoteAIFrame(stage: "ai-progress", updatesFingerprint: false)
} catch {
DebugUIInspectionLog.overlay.error(
- "debug inspection gemini parse failed windowID=\(capture.target.windowID, privacy: .public) error=\(String(describing: error), privacy: .public)"
+ "debug inspection remote AI parse failed windowID=\(capture.target.windowID, privacy: .public) error=\(String(describing: error), privacy: .public)"
)
}
}
- renderGeminiFrame(stage: "gemini-fused", updatesFingerprint: true)
+ renderRemoteAIFrame(stage: "ai-fused", updatesFingerprint: true)
}
}
- private func accessibilityFramesForGeminiFusion() -> [UInt32: DebugUIInspectionFrame] {
+ private func accessibilityFramesForRemoteAIFusion() -> [UInt32: DebugUIInspectionFrame] {
do {
let results = try accessibilityInspectionService.inspect(
scope: currentConfig.screenScope,
@@ -802,7 +801,7 @@ final class DebugUIInspectionCoordinator {
ageMissingScreens(activeScreenIDs: activeScreenIDs)
}
- private func ageMissingGeminiScreens(activeScreenIDs: Set<UInt32>) {
+ private func ageMissingRemoteAIScreens(activeScreenIDs: Set<UInt32>) {
ageMissingScreens(activeScreenIDs: activeScreenIDs)
}
@@ -925,7 +924,7 @@ final class DebugUIInspectionCoordinator {
private static func sourceName(for element: DebugUIElement) -> String {
let fusionSource = element.metadata["debugUIFusion.source"] ?? ""
let sources = metadataValue("localUIElement.sources", metadata: element.metadata) ?? ""
- if fusionSource == "gemini" || sources.contains("gemini") || element.id.hasPrefix("gemini-") {
+ if fusionSource == "ai" || sources.contains("remote-screenshot-parser") || element.id.hasPrefix("ai-") {
return "AI"
}
if fusionSource == "native-visual" || sources.contains("shape") || sources.contains("ocr") || sources.contains("layout") || element.id.hasPrefix("native-visual-") {
@@ -1303,7 +1302,7 @@ final class DebugUIInspectionCoordinator {
)
}
- private static func compressedGeminiImage(
+ private static func compressedRemoteAIImage(
from screenshot: CapturedWindowScreenshot
) -> DebugUICompressedImage {
let fallbackSize = HotLoopSize(
diff --git a/apps/Donkey/Sources/Donkey/LocalUIElementDetection/DebugUIInspectionOverlayController.swift b/apps/Donkey/Sources/Donkey/LocalUIElementDetection/DebugUIInspectionOverlayController.swift
index f3d0ae93..750cd966 100644
--- a/apps/Donkey/Sources/Donkey/LocalUIElementDetection/DebugUIInspectionOverlayController.swift
+++ b/apps/Donkey/Sources/Donkey/LocalUIElementDetection/DebugUIInspectionOverlayController.swift
@@ -286,7 +286,7 @@ private final class DebugUIInspectionSurface {
private func sourceKind(for element: DebugUIElement) -> DebugUIInspectionSourceKind {
let fusionSource = element.metadata["debugUIFusion.source"] ?? ""
let sources = element.metadata["localUIElement.sources"] ?? ""
- if fusionSource == "gemini" || sources.contains("gemini") || element.id.hasPrefix("gemini-") {
+ if fusionSource == "ai" || sources.contains("remote-screenshot-parser") || element.id.hasPrefix("ai-") {
return .ai
}
if fusionSource == "native-visual" || sources.contains("shape") || sources.contains("ocr") || sources.contains("layout") || element.id.hasPrefix("native-visual-") {
diff --git a/apps/Donkey/Sources/DonkeyAI/DebugUIInspectionFrameFusion.swift b/apps/Donkey/Sources/DonkeyAI/DebugUIInspectionFrameFusion.swift
index c4ee51e3..97434a2c 100644
--- a/apps/Donkey/Sources/DonkeyAI/DebugUIInspectionFrameFusion.swift
+++ b/apps/Donkey/Sources/DonkeyAI/DebugUIInspectionFrameFusion.swift
@@ -6,52 +6,52 @@ import Foundation
public enum DebugUIInspectionFrameFusion {
public static func fused(
accessibilityFrame: DebugUIInspectionFrame,
- geminiFrame: DebugUIInspectionFrame
+ aiFrame: DebugUIInspectionFrame
) -> DebugUIInspectionFrame {
let accessibilityElements = accessibilityFrame.elements
let accessibilityDeduplicationBase = accessibilityElements.filter { $0.type != .draggable }
- let geminiOnlyElements = geminiFrame.elements.filter { geminiElement in
+ let aiOnlyElements = aiFrame.elements.filter { aiElement in
!accessibilityDeduplicationBase.contains { accessibilityElement in
- isDuplicate(geminiElement, of: accessibilityElement)
+ isDuplicate(aiElement, of: accessibilityElement)
}
- }.map(annotatedGeminiElement)
+ }.map(annotatedAIElement)
return DebugUIInspectionFrame(
- elements: (accessibilityElements + geminiOnlyElements).sorted(by: elementSort)
+ elements: (accessibilityElements + aiOnlyElements).sorted(by: elementSort)
)
}
private static func isDuplicate(
- _ geminiElement: DebugUIElement,
+ _ aiElement: DebugUIElement,
of accessibilityElement: DebugUIElement
) -> Bool {
- let smallerArea = min(area(geminiElement.bbox), area(accessibilityElement.bbox))
+ let smallerArea = min(area(aiElement.bbox), area(accessibilityElement.bbox))
guard smallerArea > 0 else { return false }
- let geminiLabel = normalized(geminiElement.label)
+ let aiLabel = normalized(aiElement.label)
let accessibilityLabel = normalized(accessibilityElement.label)
- if !geminiLabel.isEmpty,
- geminiLabel == accessibilityLabel,
- centerDistance(geminiElement.bbox, accessibilityElement.bbox) <= 32 {
+ if !aiLabel.isEmpty,
+ aiLabel == accessibilityLabel,
+ centerDistance(aiElement.bbox, accessibilityElement.bbox) <= 32 {
return true
}
- guard areCompatibleTypes(geminiElement.type, accessibilityElement.type) else {
+ guard areCompatibleTypes(aiElement.type, accessibilityElement.type) else {
return false
}
let accessibilityArea = area(accessibilityElement.bbox)
- let geminiArea = area(geminiElement.bbox)
- let areaRatio = smallerArea / max(accessibilityArea, geminiArea)
+ let aiArea = area(aiElement.bbox)
+ let areaRatio = smallerArea / max(accessibilityArea, aiArea)
guard areaRatio >= 0.25 else {
return false
}
- let containmentScore = intersectionArea(geminiElement.bbox, accessibilityElement.bbox) / smallerArea
+ let containmentScore = intersectionArea(aiElement.bbox, accessibilityElement.bbox) / smallerArea
return containmentScore >= 0.62
}
- private static func annotatedGeminiElement(_ element: DebugUIElement) -> DebugUIElement {
+ private static func annotatedAIElement(_ element: DebugUIElement) -> DebugUIElement {
DebugUIElement(
id: element.id,
type: element.type,
@@ -61,7 +61,7 @@ public enum DebugUIInspectionFrameFusion {
confidence: element.confidence,
visualStyle: element.visualStyle,
metadata: element.metadata.merging([
- "debugUIFusion.source": "gemini",
+ "debugUIFusion.source": "ai",
"localUIElement.actionEligibility": "guardedAction",
"directInputActionsAllowed": "true"
]) { current, _ in current }
diff --git a/apps/Donkey/Sources/DonkeyAI/DebugUIInspectionHostedAdapter.swift b/apps/Donkey/Sources/DonkeyAI/DebugUIInspectionHostedAdapter.swift
index fda22656..815c4e2d 100644
--- a/apps/Donkey/Sources/DonkeyAI/DebugUIInspectionHostedAdapter.swift
+++ b/apps/Donkey/Sources/DonkeyAI/DebugUIInspectionHostedAdapter.swift
@@ -10,14 +10,14 @@ public enum DebugUIInspectionHostedAdapterError: Error, Equatable, Sendable {
}
public struct DebugUIInspectionRequest: Equatable, Sendable {
- public var provider: DebugUIInspectionProvider
+ public var provider: DebugUIInspectionProvider?
public var screenshotBase64: String
public var pixelSize: HotLoopSize
public var minConfidence: Double
public var metadata: [String: String]
public init(
- provider: DebugUIInspectionProvider,
+ provider: DebugUIInspectionProvider? = nil,
screenshotBase64: String,
pixelSize: HotLoopSize,
minConfidence: Double = 0.25,
@@ -61,7 +61,7 @@ public struct HostedDebugUIInspectionAnalyzer: DebugUIInspectionAnalyzing {
for request: DebugUIInspectionRequest
) -> RemoteInferenceResponseCreateRequest {
RemoteInferenceResponseCreateRequest(
- donkeyProvider: request.provider.rawValue,
+ donkeyProvider: request.provider?.rawValue,
input: .array([
.object([
"role": .string("user"),
diff --git a/apps/Donkey/Sources/DonkeyAI/ScreenshotParseDebugUIOverlayMapper.swift b/apps/Donkey/Sources/DonkeyAI/ScreenshotParseDebugUIOverlayMapper.swift
index f137bc71..dd9b49e7 100644
--- a/apps/Donkey/Sources/DonkeyAI/ScreenshotParseDebugUIOverlayMapper.swift
+++ b/apps/Donkey/Sources/DonkeyAI/ScreenshotParseDebugUIOverlayMapper.swift
@@ -39,12 +39,15 @@ public enum ScreenshotParseDebugUIOverlayMapper {
return nil
}
+ let parserProvider = result.metadata["parserProvider"]
+ ?? result.metadata["runtime.backend"]
+ ?? "remote-screenshot-parser"
let metadata = control.metadata
.merging([
- "localUIElement.sources": "gemini-screenshot-parser",
+ "localUIElement.sources": "remote-screenshot-parser",
"localUIElement.actionEligibility": LocalUIElementActionEligibility.guardedAction.rawValue,
"remoteScreenshotParsing.status": result.metadata["remoteScreenshotParsing.status"] ?? "used",
- "remoteScreenshotParsing.provider": result.metadata["parserProvider"] ?? result.metadata["runtime.backend"] ?? "gemini-screenshot-parser",
+ "remoteScreenshotParsing.provider": parserProvider,
"target.windowID": String(target.windowID),
"target.appName": target.appName ?? "",
"target.bundleIdentifier": target.bundleIdentifier ?? "",
@@ -56,11 +59,11 @@ public enum ScreenshotParseDebugUIOverlayMapper {
.merging(boundsMetadata(prefix: "debugOverlay.localBounds.", bounds: localBounds)) { current, _ in current }
return DebugUIElement(
- id: "gemini-\(target.windowID)-\(control.id)",
+ id: "ai-\(target.windowID)-\(control.id)",
type: elementType(for: control.kind),
label: control.label,
description: [
- "gemini screenshot parser",
+ "remote screenshot parser",
control.kind.rawValue
].joined(separator: " "),
bbox: bbox,
diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/DonkeyBackendInferenceClientTests.swift b/apps/Donkey/Tests/DonkeyRuntimeTests/DonkeyBackendInferenceClientTests.swift
index 92a0cf97..55fcd359 100644
--- a/apps/Donkey/Tests/DonkeyRuntimeTests/DonkeyBackendInferenceClientTests.swift
+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/DonkeyBackendInferenceClientTests.swift
@@ -351,7 +351,7 @@ struct DonkeyBackendInferenceClientTests {
)
let element = try #require(frame.elements.first)
- #expect(element.id == "gemini-42-review")
+ #expect(element.id == "ai-42-review")
#expect(element.type == .button)
#expect(element.bbox == DebugUIBoundingBox(x: 150, y: 225, width: 100, height: 50))
#expect(element.metadata["directInputActionsAllowed"] == "true")
@@ -411,7 +411,7 @@ struct DonkeyBackendInferenceClientTests {
}
@Test
- func debugUIFusionKeepsAccessibilityGeometryAndAddsGeminiGaps() throws {
+ func debugUIFusionKeepsAccessibilityGeometryAndAddsAIGaps() throws {
let accessibilityFrame = DebugUIInspectionFrame(
elements: [
DebugUIElement(
@@ -432,45 +432,45 @@ struct DonkeyBackendInferenceClientTests {
)
]
)
- let geminiFrame = DebugUIInspectionFrame(
+ let aiFrame = DebugUIInspectionFrame(
elements: [
DebugUIElement(
- id: "gemini-review",
+ id: "ai-review",
type: .button,
label: "Review",
bbox: DebugUIBoundingBox(x: 105, y: 105, width: 60, height: 20),
confidence: 0.95,
- metadata: ["localUIElement.sources": "gemini-screenshot-parser"]
+ metadata: ["localUIElement.sources": "remote-screenshot-parser"]
),
DebugUIElement(
- id: "gemini-voice",
+ id: "ai-voice",
type: .toolbarIcon,
label: "Voice",
bbox: DebugUIBoundingBox(x: 220, y: 100, width: 40, height: 30),
confidence: 0.9,
- metadata: ["localUIElement.sources": "gemini-screenshot-parser"]
+ metadata: ["localUIElement.sources": "remote-screenshot-parser"]
)
]
)
let fused = DebugUIInspectionFrameFusion.fused(
accessibilityFrame: accessibilityFrame,
- geminiFrame: geminiFrame
+ aiFrame: aiFrame
)
let ids = fused.elements.map(\.id)
#expect(ids.contains("ax-review"))
#expect(ids.contains("ax-window"))
- #expect(!ids.contains("gemini-review"))
- #expect(ids.contains("gemini-voice"))
- let geminiElement = try #require(fused.elements.first { $0.id == "gemini-voice" })
- #expect(geminiElement.metadata["debugUIFusion.source"] == "gemini")
- #expect(geminiElement.metadata["directInputActionsAllowed"] == "true")
- #expect(geminiElement.metadata["localUIElement.actionEligibility"] == "guardedAction")
+ #expect(!ids.contains("ai-review"))
+ #expect(ids.contains("ai-voice"))
+ let aiElement = try #require(fused.elements.first { $0.id == "ai-voice" })
+ #expect(aiElement.metadata["debugUIFusion.source"] == "ai")
+ #expect(aiElement.metadata["directInputActionsAllowed"] == "true")
+ #expect(aiElement.metadata["localUIElement.actionEligibility"] == "guardedAction")
}
@Test
- func debugUIFusionDoesNotLetLargeAccessibilityContainersHideGeminiControls() throws {
+ func debugUIFusionDoesNotLetLargeAccessibilityContainersHideAIControls() throws {
let accessibilityFrame = DebugUIInspectionFrame(
elements: [
DebugUIElement(
@@ -483,25 +483,25 @@ struct DonkeyBackendInferenceClientTests {
)
]
)
- let geminiFrame = DebugUIInspectionFrame(
+ let aiFrame = DebugUIInspectionFrame(
elements: [
DebugUIElement(
- id: "gemini-small-icon",
+ id: "ai-small-icon",
type: .toolbarIcon,
label: "Search",
bbox: DebugUIBoundingBox(x: 18, y: 84, width: 28, height: 28),
confidence: 0.88,
- metadata: ["localUIElement.sources": "gemini-screenshot-parser"]
+ metadata: ["localUIElement.sources": "remote-screenshot-parser"]
)
]
)
let fused = DebugUIInspectionFrameFusion.fused(
accessibilityFrame: accessibilityFrame,
- geminiFrame: geminiFrame
+ aiFrame: aiFrame
)
- #expect(fused.elements.map(\.id).contains("gemini-small-icon"))
+ #expect(fused.elements.map(\.id).contains("ai-small-icon"))
}
@Test
diff --git a/site/src/app/api/inference/screenshots/parse/route.ts b/site/src/app/api/inference/screenshots/parse/route.ts
index b98d4d09..f77d09fe 100644
--- a/site/src/app/api/inference/screenshots/parse/route.ts
+++ b/site/src/app/api/inference/screenshots/parse/route.ts
@@ -21,9 +21,9 @@ import {
validationErrorResponse,
} from "@/lib/inference/responses";
import {
+ createScreenshotParserProvider,
parseScreenshot,
parseScreenshotStream,
- screenshotParseModelForRequest,
} from "@/lib/inference/screenshot-parsing";
import { screenshotParseRequestSchema } from "@/lib/inference/screenshot-parsing/schema";
import type { ScreenshotParseRequest } from "@/lib/inference/screenshot-parsing/schema";
@@ -69,10 +69,11 @@ export const POST = withDonkeyAuth(async (request) => {
);
}
- const model = screenshotParseModelForRequest(parsed.data);
+ const parserProvider = createScreenshotParserProvider();
+ const model = parserProvider.modelForRequest(parsed.data);
const credits = await requireInferenceCredits({
model,
- provider: "gemini",
+ provider: parserProvider.inferenceProvider,
route: inferenceUsageRoutes.screenshotParse,
userId: request.donkey.userId,
});
@@ -84,17 +85,18 @@ export const POST = withDonkeyAuth(async (request) => {
return streamScreenshotParseResponse({
clientId: client.clientId,
model,
+ parserProvider,
request: parsed.data,
userId: request.donkey.userId,
});
}
try {
- const result = await parseScreenshot(parsed.data);
+ const result = await parseScreenshot(parsed.data, parserProvider);
const recordedUsage = await recordInferenceUsage({
clientId: client.clientId,
metadata: {
- parserProvider: "gemini-flash",
+ parserProvider: parserProvider.id,
},
model: result.model,
provider: result.provider,
@@ -117,10 +119,10 @@ export const POST = withDonkeyAuth(async (request) => {
clientId: client.clientId,
errorCode: inferenceErrorCode(error),
metadata: {
- parserProvider: "gemini-flash",
+ parserProvider: parserProvider.id,
},
model,
- provider: "gemini",
+ provider: parserProvider.inferenceProvider,
requestKind: "screenshot_parse",
route: inferenceUsageRoutes.screenshotParse,
userId: request.donkey.userId,
@@ -136,6 +138,7 @@ export const POST = withDonkeyAuth(async (request) => {
function streamScreenshotParseResponse(input: {
clientId: string;
model: string;
+ parserProvider: ReturnType<typeof createScreenshotParserProvider>;
request: ScreenshotParseRequest;
userId: string;
}) {
@@ -143,7 +146,7 @@ function streamScreenshotParseResponse(input: {
const stream = new ReadableStream<Uint8Array>({
async start(controller) {
try {
- for await (const event of parseScreenshotStream(input.request)) {
+ for await (const event of parseScreenshotStream(input.request, input.parserProvider)) {
if (event.type === "partial") {
controller.enqueue(encoder.encode(serverSentEvent("partial", event.result)));
continue;
@@ -152,7 +155,7 @@ function streamScreenshotParseResponse(input: {
const recordedUsage = await recordInferenceUsage({
clientId: input.clientId,
metadata: {
- parserProvider: "gemini-flash",
+ parserProvider: input.parserProvider.id,
streaming: true,
},
model: event.model,
@@ -180,11 +183,11 @@ function streamScreenshotParseResponse(input: {
clientId: input.clientId,
errorCode: inferenceErrorCode(error),
metadata: {
- parserProvider: "gemini-flash",
+ parserProvider: input.parserProvider.id,
streaming: true,
},
model: input.model,
- provider: "gemini",
+ provider: input.parserProvider.inferenceProvider,
requestKind: "screenshot_parse",
route: inferenceUsageRoutes.screenshotParse,
userId: input.userId,
@@ -211,7 +214,7 @@ function streamScreenshotParseResponse(input: {
"Content-Type": "text/event-stream; charset=utf-8",
"X-Accel-Buffering": "no",
"X-Donkey-Inference-Model": input.model,
- "X-Donkey-Inference-Provider": "gemini",
+ "X-Donkey-Inference-Provider": input.parserProvider.inferenceProvider,
},
});
}
diff --git a/site/src/lib/inference/screenshot-parsing/gemini-flash.ts b/site/src/lib/inference/screenshot-parsing/gemini-flash.ts
index ef74e332..537cf433 100644
--- a/site/src/lib/inference/screenshot-parsing/gemini-flash.ts
+++ b/site/src/lib/inference/screenshot-parsing/gemini-flash.ts
@@ -51,7 +51,10 @@ export function createGeminiFlashScreenshotParser(
const config = geminiClientConfig(environment);
return {
+ id: screenshotProviderID,
+ inferenceProvider: geminiProviderID,
configured: config.configured,
+ modelForRequest: (request) => screenshotParseModelForRequest(request, environment),
async parse(request) {
ensureConfigured(config.configured);
const client = clientFactory(config.options);
@@ -334,8 +337,7 @@ function screenshotParseProfile(request: ScreenshotParseRequest) {
}
function isDebugOverlayRequest(request: ScreenshotParseRequest) {
- return request.metadata.source === "debug-ui-inspection-overlay"
- || request.metadata.provider === "gemini";
+ return request.metadata.source === "debug-ui-inspection-overlay";
}
function parseGeminiOutput(rawBody: JsonValue) {
diff --git a/site/src/lib/inference/screenshot-parsing/index.ts b/site/src/lib/inference/screenshot-parsing/index.ts
index c17131c0..4fef8e2a 100644
--- a/site/src/lib/inference/screenshot-parsing/index.ts
+++ b/site/src/lib/inference/screenshot-parsing/index.ts
@@ -1,8 +1,5 @@
import { InferenceProviderError } from "@/lib/inference/providers";
-import {
- createGeminiFlashScreenshotParser,
- screenshotParseModelForRequest,
-} from "@/lib/inference/screenshot-parsing/gemini-flash";
+import { createGeminiFlashScreenshotParser } from "@/lib/inference/screenshot-parsing/gemini-flash";
import type {
ScreenshotParserProvider,
ScreenshotParserProviderResult,
@@ -14,8 +11,6 @@ export function createScreenshotParserProvider(): ScreenshotParserProvider {
return createGeminiFlashScreenshotParser();
}
-export { screenshotParseModelForRequest };
-
export async function parseScreenshot(
request: ScreenshotParseRequest,
provider: ScreenshotParserProvider = createScreenshotParserProvider(),
@@ -25,7 +20,7 @@ export async function parseScreenshot(
statusCode: 503,
code: "missing_provider_credentials",
details: {
- provider: "gemini-flash",
+ provider: provider.id,
},
});
}
@@ -42,7 +37,7 @@ export async function* parseScreenshotStream(
statusCode: 503,
code: "missing_provider_credentials",
details: {
- provider: "gemini-flash",
+ provider: provider.id,
},
});
}
diff --git a/site/src/lib/inference/screenshot-parsing/types.ts b/site/src/lib/inference/screenshot-parsing/types.ts
index 1548a666..5af0960d 100644
--- a/site/src/lib/inference/screenshot-parsing/types.ts
+++ b/site/src/lib/inference/screenshot-parsing/types.ts
@@ -55,7 +55,10 @@ export type ScreenshotParserProviderStreamEvent =
};
export type ScreenshotParserProvider = {
+ id: string;
+ inferenceProvider: string;
configured: boolean;
+ modelForRequest: (request: ScreenshotParseRequest) => string;
parse: (request: ScreenshotParseRequest) => Promise<ScreenshotParserProviderResult>;
stream?: (request: ScreenshotParseRequest) => AsyncGenerator<ScreenshotParserProviderStreamEvent>;
};