1
/**2
* Exclusive computer use through an installed Cua Driver MCP executable.3
* The MCP client owns discovery, execution, image admission, and reconnection.4
* @module5
*/7
import type { Context, Fiber } from '@deepseek-ai/cordis'8
import z from '@deepseek-ai/schemastery'9
import { ComputerUseProviderName } from '@deepseek-ai/dsh-computer-use/brand'10
import * as McpClient from '@deepseek-ai/dsh-mcp-client'11
import type {} from '@deepseek-ai/dsh-computer-use'13
/** Cordis plugin identity for the installed Cua Driver provider. */14
export const name = 'experimental-computer-use-cua-driver-mcp'16
/** The shared reservation and tool registry must exist before connection. */17
export const inject = ['computerUse', 'tools']19
/** Installed executable and MCP connection overrides. */20
export interface Config {21
/** Executable path or PATH command; defaults to `cua-driver`. */22
command: string23
/** Arguments passed without a shell; defaults to `['mcp']`. */24
args: string[]25
/** Per-call timeout in milliseconds; omission uses the MCP client's default. */26
toolCallTimeoutMs?: number27
/** Reconnection overrides; defaults to the MCP client's policy. */28
reconnect: McpClient.ReconnectConfig29
}31
/** Validate executable options; the MCP client resolves connection defaults. */32
export const Config: z<Partial<Config>, Config> = z.object({33
command: z.string().pattern(/[^\s]/u).default('cua-driver'),34
args: z.array(String).default(['mcp']),35
toolCallTimeoutMs: z.number().min(1),36
reconnect: z.object({37
enabled: z.boolean(),38
initialDelayMs: z.number().min(1),39
maxDelayMs: z.number().min(1),40
maxAttempts: z.number().min(1).step(1),41
}),42
})44
/**45
* Reserve computer use and activate the installed Cua Driver's MCP tools.46
* Initial connection or discovery failure rejects activation and rolls back.47
* Disposal retains the reservation until the MCP child has finished teardown.48
* @param ctx - context providing computer use and the tool registry.49
* @param config - validated executable options and optional connection overrides.50
* @returns initial MCP tool-discovery completion.51
*/52
export async function apply(ctx: Context, config: Config): Promise<void> {53
const connection = McpClient.Config({54
command: config.command,55
args: config.args,56
...config.toolCallTimeoutMs === undefined ? {} : { toolCallTimeoutMs: config.toolCallTimeoutMs },57
reconnect: config.reconnect,58
transport: 'stdio',59
serverName: 'cua-driver-mcp',60
failOnStartupError: true,61
})62
// One effect orders child shutdown before release; separate fiber effects63
// unload concurrently and could otherwise admit another live driver.64
let child!: Fiber65
ctx.effect(function* () {66
yield ctx.computerUse.register(ComputerUseProviderName('cua-driver-mcp'))67
child = ctx.plugin(McpClient, connection)68
yield child.dispose69
}, 'computer-use-cua-driver-mcp.connection')70
await child.await()71
}