@gacua/backend
Version:
GACUA Backend
52 lines • 1.9 kB
JavaScript
/**
* @license
* Copyright 2025 MuleRun
* SPDX-License-Identifier: Apache-2.0
*/
import { SchemaValidator } from '@gacua/gemini-cli-core';
import { toScreenCoords as toScreenCoordinate, } from '../screen.js';
export class BaseGroundableTool {
validate(args) {
return SchemaValidator.validate(this.functionDeclaration.parameters, args);
}
validateImageElementPair(args) {
const result = SchemaValidator.validate(this.functionDeclaration.parameters, args);
if (result) {
return result;
}
if (typeof args !== 'object' || args === null) {
return 'Arguments must be an object';
}
const typedArgs = args;
if (typedArgs.image_id === undefined &&
typedArgs.element_description !== undefined) {
return 'When element_description is provided, image_id must be provided';
}
if (typedArgs.image_id !== undefined &&
typedArgs.element_description === undefined) {
return 'When image_id is provided, element_description must be provided';
}
return null;
}
async detectAndTransform(imageId, croppedScreenshotParts, detectElement) {
if (imageId >= croppedScreenshotParts.length) {
return `Image ID exceeds the number of cropped screenshots: ${imageId} >= ${croppedScreenshotParts.length}`;
}
let box;
try {
box = await detectElement(croppedScreenshotParts[imageId].imagePart);
}
catch (e) {
return `Failed to detect element: ${e}`;
}
const screenCoords = toScreenCoordinate({
index: imageId,
boxOrCoordinate: box,
});
return {
indexAndBox: { index: imageId, box },
screenCoordinate: screenCoords,
};
}
}
//# sourceMappingURL=groundable-tool.js.map