45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"github.com/Nwflower/reims-go/internal/console"
|
|
"github.com/Nwflower/reims-go/internal/plugin/builtin"
|
|
)
|
|
|
|
var fallbackComputerUse = console.NewManager()
|
|
|
|
func (a *App) computerUseService() (builtin.ComputerUseService, error) {
|
|
a.mu.Lock()
|
|
mgr := a.pluginMgr
|
|
a.mu.Unlock()
|
|
if mgr == nil {
|
|
return fallbackComputerUse, nil
|
|
}
|
|
raw, ok := mgr.Registry().LookupService(builtin.ServiceComputerUse)
|
|
if !ok {
|
|
return nil, a.computerUseHostError("computer_use_unavailable", "err.computer_use.disabled", nil)
|
|
}
|
|
service, ok := raw.(builtin.ComputerUseService)
|
|
if !ok || service == nil {
|
|
return nil, a.computerUseHostError("computer_use_unavailable", "err.computer_use.unavailable", nil)
|
|
}
|
|
return service, nil
|
|
}
|
|
|
|
func (a *App) computerUseInternalService() builtin.ComputerUseService {
|
|
service, err := a.computerUseService()
|
|
if err == nil {
|
|
return service
|
|
}
|
|
return fallbackComputerUse
|
|
}
|
|
|
|
func (a *App) withComputerUseVM(ctx context.Context, vmDir string, operation func(context.Context) error) error {
|
|
if strings.TrimSpace(vmDir) == "" {
|
|
return operation(ctx)
|
|
}
|
|
return a.computerUseInternalService().WithVM(ctx, vmDir, operation)
|
|
}
|