|
|
@@ -257,6 +257,22 @@ export class ContainerComputerProvider implements ComputerProvider {
|
|
|
// Persistent workspace deletion is a separate, explicit operation.
|
|
|
})
|
|
|
}
|
|
|
+ private async waitForDesktop(state:ComputerState,authorize:()=>void,signal?:AbortSignal):Promise<void> {
|
|
|
+ const deadline=Date.now()+15000
|
|
|
+ for(;;){
|
|
|
+ authorize()
|
|
|
+ if(signal?.aborted)throw new ComputerError('computer_cancelled','操作已停止')
|
|
|
+ try {
|
|
|
+ await this.run(this.runtime,['exec','--user','1000:1000','--',state.containerId,CUA_DRIVER,'call','health_report','{}','--socket',CUA_SOCKET],{timeout:3000,signal})
|
|
|
+ authorize()
|
|
|
+ return
|
|
|
+ }catch(error){
|
|
|
+ if(signal?.aborted)throw new ComputerError('computer_cancelled','操作已停止')
|
|
|
+ if(!/Cua Driver daemon is not running on/.test(String((error as any).stderr??''))||Date.now()>=deadline)throw error
|
|
|
+ await new Promise(resolve=>setTimeout(resolve,250))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
async execute(value:ComputerSpecification,argv:string[],options:{authorize():void;signal?:AbortSignal;timeout?:number;input?:Buffer;lane?:ComputerLane;mayFence?():boolean;user?:ComputerUser}):Promise<CommandResult> {
|
|
|
const spec=this.validateSpecification(value)
|
|
|
if(!argv.length||argv.length>64||argv.some(arg=>typeof arg!=='string'||arg.includes('\0'))||argv.join('').length>65536)throw new ComputerError('computer_command_invalid','电脑命令无效或过长')
|
|
|
@@ -265,6 +281,7 @@ export class ContainerComputerProvider implements ComputerProvider {
|
|
|
const state=await this.inspect(spec)
|
|
|
if(!state?.running)throw new ComputerError('computer_not_running','电脑环境尚未运行')
|
|
|
options.authorize()
|
|
|
+ if(argv[0]===CUA_DRIVER)await this.waitForDesktop(state,options.authorize,options.signal)
|
|
|
if(options.signal?.aborted)throw new ComputerError('computer_cancelled','操作已停止')
|
|
|
const operationId=randomUUID(),timeout=Math.min(60000,Math.max(1000,options.timeout??30000))
|
|
|
let cancellation:Promise<void>|undefined
|
|
|
@@ -316,6 +333,7 @@ export class ContainerComputerProvider implements ComputerProvider {
|
|
|
return this.lane(spec.id).read(async()=>{
|
|
|
const state=await this.inspect(spec)
|
|
|
authorize();if(!state?.running)throw new ComputerError('computer_not_running','电脑尚未运行')
|
|
|
+ await this.waitForDesktop(state,authorize)
|
|
|
const file=`/tmp/yaoyao-view-${randomBytes(12).toString('hex')}.png`
|
|
|
const exec=(args:string[])=>this.run(this.runtime,['exec','--user','1000:1000','--',state.containerId,...args],{timeout:10000})
|
|
|
try{
|