Open source CapCut alternative.
TypeScript
feat(site): consolidate computer use on Gemini desktop environment
David Le3804694beccd
diff --git a/site/src/lib/credits/provider-pricing.ts b/site/src/lib/credits/provider-pricing.tsindex 46436030..b72d4ad0 100644--- a/site/src/lib/credits/provider-pricing.ts+++ b/site/src/lib/credits/provider-pricing.ts@@ -61,13 +61,6 @@ export function providerCreditPricing(// OpenAIRunModel union, so adding a run model without a price fails the type-check (and the// build). Matched exactly (not by prefix) so it never shadows a more specific table entry.const openaiRunModelPricing: Record<OpenAIRunModel, ProviderCreditPricing> = {- [openaiModels.computerUse]: textTokenPricing({- model: "gpt-5.5",- input: "5",- cachedInput: "0.5",- output: "30",- longContext: { input: "10", cachedInput: "1", output: "45" },- }),[openaiModels.debugInspection]: textTokenPricing({model: "gpt-5.4",input: "2.5",@@ -255,7 +248,6 @@ const openAITextCreditRates: {{ model: "o3-mini", input: "1.1", cachedInput: "0.55", output: "4.4" },{ model: "o3", input: "2", cachedInput: "0.5", output: "8" },{ model: "o4-mini", input: "1.1", cachedInput: "0.275", output: "4.4" },- { model: "computer-use-preview", input: "3", output: "12" },];// Every Gemini model we run must appear here: the Record is keyed by the GeminiModel union,@@ -267,12 +259,6 @@ const geminiModelPricing: Record<GeminiModel, ProviderCreditPricing> = {cachedInput: "0.15",output: "9",}),- [geminiModels.flashComputerUse]: textAudioTokenPricing({- input: "0.5",- cachedInput: "0.05",- output: "3",- inputAudio: "1",- }),[geminiModels.flashLite]: textAudioTokenPricing({input: "0.25",cachedInput: "0.025",diff --git a/site/src/lib/inference/adapters/gemini-computer-use.ts b/site/src/lib/inference/adapters/gemini-computer-use.tsindex 03757a95..90067259 100644--- a/site/src/lib/inference/adapters/gemini-computer-use.ts+++ b/site/src/lib/inference/adapters/gemini-computer-use.ts@@ -46,9 +46,10 @@ const providerID = "gemini-computer-use";const geminiProviderID = "gemini";const defaultDecisionResponsesModel = geminiModelRoles.fastDecision;const defaultVertexResponsesModel = geminiModelRoles.chat;-const defaultComputerUseModel = geminiModelRoles.browserComputerUse;+const defaultComputerUseModel = geminiModelRoles.computerUse;export const geminiBrowserInteractionToolType = "donkey_gemini_browser_interaction";+export const geminiMacDesktopInteractionToolType = "donkey_gemini_mac_desktop_interaction";export const debugUIInspectionToolType = "donkey_debug_ui_inspection";// Note: `generic_harness_planning` is deliberately NOT fast-decision. Planning is the most@@ -68,6 +69,17 @@ const browserOnlyFunctionExclusions = ["drag_and_drop",];+// On the macOS desktop the agent never drives a web browser chrome, so the+// browser-navigation predefined functions are excluded — leaving the GUI actions+// (click, type, scroll, drag_and_drop, key_combination, …) the desktop needs.+const desktopExcludedFunctions = [+ "open_web_browser",+ "navigate",+ "go_back",+ "go_forward",+ "search",+];+export function createGeminiComputerUseProvider(environment: AdapterEnvironment = process.env,clientFactory: GeminiClientFactory = (options) => new GoogleGenAI(options),@@ -101,6 +113,7 @@ export function createGeminiComputerUseProvider(details: {supportedTools: [geminiBrowserInteractionToolType,+ geminiMacDesktopInteractionToolType,debugUIInspectionToolType,],},@@ -306,9 +319,8 @@ function geminiGenerateContentParameters(function geminiTools(registeredTools: string[], rawTools: JsonValue | undefined): Tool[] {const tools: Tool[] = [];- const hasBrowser = registeredTools.includes(geminiBrowserInteractionToolType);- if (hasBrowser) {+ if (registeredTools.includes(geminiBrowserInteractionToolType)) {tools.push({computerUse: {environment: Environment.ENVIRONMENT_BROWSER,@@ -320,6 +332,18 @@ function geminiTools(registeredTools: string[], rawTools: JsonValue | undefined)});}+ if (registeredTools.includes(geminiMacDesktopInteractionToolType)) {+ tools.push({+ computerUse: {+ environment: Environment.ENVIRONMENT_DESKTOP,+ excludedPredefinedFunctions: excludedPredefinedFunctions(+ rawTools,+ desktopExcludedFunctions,+ ),+ },+ });+ }+return tools;}@@ -738,7 +762,10 @@ function responseFormatFromBody(body: JsonObject): { json: boolean; schema?: Jso}function defaultResponseModel(body: JsonObject, registeredTools: string[]) {- if (registeredTools.includes(geminiBrowserInteractionToolType)) {+ if (+ registeredTools.includes(geminiBrowserInteractionToolType) ||+ registeredTools.includes(geminiMacDesktopInteractionToolType)+ ) {return defaultComputerUseModel;}@@ -861,6 +888,8 @@ function registeredToolTypes(tools: JsonValue | undefined): string[] {}if (tool.type === geminiBrowserInteractionToolType) {registered.add(geminiBrowserInteractionToolType);+ } else if (tool.type === geminiMacDesktopInteractionToolType) {+ registered.add(geminiMacDesktopInteractionToolType);} else if (tool.type === debugUIInspectionToolType) {registered.add(debugUIInspectionToolType);}@@ -943,6 +972,7 @@ function hasExplicitUnsupportedTools(return true;}return tool.type !== geminiBrowserInteractionToolType &&+ tool.type !== geminiMacDesktopInteractionToolType &&tool.type !== debugUIInspectionToolType;});}@@ -964,6 +994,7 @@ function staticModel(model: string, computerUse: boolean): InferenceModel {computerUse,registeredTools: [geminiBrowserInteractionToolType,+ geminiMacDesktopInteractionToolType,debugUIInspectionToolType,],}diff --git a/site/src/lib/inference/adapters/hosted-responses.ts b/site/src/lib/inference/adapters/hosted-responses.tsindex d26dc947..4ce6dc75 100644--- a/site/src/lib/inference/adapters/hosted-responses.ts+++ b/site/src/lib/inference/adapters/hosted-responses.ts@@ -23,9 +23,7 @@ type AdapterEnvironment = Record<string, string | undefined>;const providerID = "hosted-responses";const openAIProviderID = "openai";const openAIBaseURL = "https://api.openai.com/v1";-const openAIMacDesktopInteractionToolType = "donkey_openai_mac_desktop_interaction";const debugUIInspectionToolType = "donkey_debug_ui_inspection";-const defaultOpenAIComputerUseModel = openaiModels.computerUse;const defaultOpenAIDebugInspectionModel = openaiModels.debugInspection;const unsupportedOpenAIComputerUseParameters = ["temperature", "top_p", "topP"];@@ -47,7 +45,6 @@ export function createHostedResponsesProvider(}return [- staticModel(defaultOpenAIComputerUseModel),staticModel(defaultOpenAIDebugInspectionModel),];}@@ -58,15 +55,12 @@ export function createHostedResponsesProvider(ensureConfigured(configured);if (!isOpenAIResponsesToolRequest(request.body)) {throw new InferenceProviderError(- "OpenAI Responses is only configured for Mac desktop computer use and read-only debug UI inspection.",+ "OpenAI Responses is only configured for read-only debug UI inspection.",{statusCode: 400,code: "openai_computer_tool_required",details: {supportedTools: [- "computer",- "computer_use_preview",- openAIMacDesktopInteractionToolType,debugUIInspectionToolType,],},@@ -114,11 +108,8 @@ export function createHostedResponsesProvider(};}-function defaultOpenAIModel(body: JsonObject) {- if (hasDebugUIInspectionTool(body) && !hasOpenAIMacDesktopTool(body)) {- return defaultOpenAIDebugInspectionModel;- }- return defaultOpenAIComputerUseModel;+function defaultOpenAIModel(_body: JsonObject) {+ return defaultOpenAIDebugInspectionModel;}function requestBody(body: JsonObject, model: string): JsonObject {@@ -132,9 +123,8 @@ function requestBody(body: JsonObject, model: string): JsonObject {}function normalizeOpenAIComputerUseBody(body: JsonObject): JsonObject {- const hasMacDesktopTool = hasOpenAIMacDesktopTool(body);const hasDebugInspectionTool = hasDebugUIInspectionTool(body);- if (!hasMacDesktopTool && !hasDebugInspectionTool) {+ if (!hasDebugInspectionTool) {return body;}@@ -142,11 +132,7 @@ function normalizeOpenAIComputerUseBody(body: JsonObject): JsonObject {const toolChoice = openAIComputerToolChoice(body.tool_choice);const normalized: JsonObject = {...body,- instructions: openAIInstructions(- body.instructions,- hasMacDesktopTool,- hasDebugInspectionTool,- ),+ instructions: openAIInstructions(body.instructions),...(toolChoice === undefined ? {} : { tool_choice: toolChoice }),};for (const parameter of unsupportedOpenAIComputerUseParameters) {@@ -185,6 +171,9 @@ function openAIComputerToolChoice(value: JsonValue | undefined): JsonValue | und};}+// The debug-inspection tool is read-only and has no OpenAI-native equivalent, so it is stripped from+// the request (the work is driven entirely by the inspection instructions). Any other tool passes+// through untouched.function openAIComputerToolReference(value: JsonValue): JsonValue | null {if (!isJsonObject(value)) {return value;@@ -194,46 +183,16 @@ function openAIComputerToolReference(value: JsonValue): JsonValue | null {return null;}- if (value.type === openAIMacDesktopInteractionToolType) {- return { type: "computer" };- }-- if (- (value.type === "function" || value.type === "custom") &&- value.name === openAIMacDesktopInteractionToolType- ) {- return { type: "computer" };- }-return value;}-function openAIInstructions(- value: JsonValue | undefined,- hasMacDesktopTool: boolean,- hasDebugInspectionTool: boolean,-) {- const instructions: string[] = [];- if (hasMacDesktopTool) {- instructions.push(- [- "Use the OpenAI computer tool for non-browser Mac desktop UI work.",- "The Mac client executes returned computer_call actions with focus, safety, permission, and screenshot feedback.",- ].join(" "),- );- }- if (hasDebugInspectionTool) {- instructions.push(- [- "Perform read-only macOS UI inspection from the provided screenshot.",- "Return strict JSON only and do not return computer_call, function_call, click, type, scroll, drag, or navigation actions.",- ].join(" "),- );- }-+function openAIInstructions(value: JsonValue | undefined) {return [stringValue(value),- ...instructions,+ [+ "Perform read-only macOS UI inspection from the provided screenshot.",+ "Return strict JSON only and do not return computer_call, function_call, click, type, scroll, drag, or navigation actions.",+ ].join(" "),].filter(Boolean).join("\n\n");}@@ -250,9 +209,7 @@ function staticModel(model: string): InferenceModel {provider: openAIProviderID,baseURL: openAIBaseURL,api: "responses",- computerUse: true,registeredTools: [- openAIMacDesktopInteractionToolType,debugUIInspectionToolType,],},@@ -266,24 +223,7 @@ function isOpenAIResponsesToolRequest(body: JsonObject) {}return tools.some((tool) => {- return (- isJsonObject(tool) &&- (tool.type === "computer" ||- tool.type === "computer_use_preview" ||- tool.type === openAIMacDesktopInteractionToolType ||- tool.type === debugUIInspectionToolType)- );- });-}--function hasOpenAIMacDesktopTool(body: JsonObject) {- const tools = body.tools;- if (!Array.isArray(tools)) {- return false;- }-- return tools.some((tool) => {- return isJsonObject(tool) && tool.type === openAIMacDesktopInteractionToolType;+ return isJsonObject(tool) && tool.type === debugUIInspectionToolType;});}diff --git a/site/src/lib/inference/gemini-models.ts b/site/src/lib/inference/gemini-models.tsindex 7ea563d9..7a129848 100644--- a/site/src/lib/inference/gemini-models.ts+++ b/site/src/lib/inference/gemini-models.ts@@ -10,7 +10,6 @@export const geminiModels = {flash: "gemini-3.5-flash",flashLite: "gemini-3.1-flash-lite",- flashComputerUse: "gemini-3-flash-preview",// Generative image editing/generation ("nano banana"). Bump here when adopting a// newer image model; the backend also honors a GEMINI_IMAGE_MODEL override.flashImage: "gemini-2.5-flash-image",@@ -25,8 +24,9 @@ export const geminiModelRoles = {chat: geminiModels.flash,// Fast structured task-intent and follow-up decisions.fastDecision: geminiModels.flashLite,- // Browser Computer Use tool calls.- browserComputerUse: geminiModels.flashComputerUse,+ // Computer Use tool calls (browser and macOS desktop environments). Computer+ // use is a built-in tool of the main flash model, so both share one model.+ computerUse: geminiModels.flash,// Screenshot parsing into read-only UI evidence.screenshotParse: geminiModels.flash,// Vision grounding: a cheap structured pick over already-parsed elements.diff --git a/site/src/lib/inference/openai-models.ts b/site/src/lib/inference/openai-models.tsindex fd0dabed..508d7906 100644--- a/site/src/lib/inference/openai-models.ts+++ b/site/src/lib/inference/openai-models.ts@@ -2,8 +2,6 @@// Anything the code selects lives here so it is priced exhaustively in provider-pricing.ts;// bumping a model is a one-line change here.export const openaiModels = {- // macOS desktop computer-use Responses calls.- computerUse: "gpt-5.5",// Developer UI inspection Responses calls.debugInspection: "gpt-5.4",} as const;