smooth-operator-agent-tools
Version:
Node.js client library for Smooth Operator Agent Tools - a toolkit for programmers developing Computer Use Agents on Windows systems
577 lines • 23.4 kB
JavaScript
"use strict";
/**
* Type definitions for Smooth Operator Agent Tools
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.OverviewResponse = exports.ChromeElementInfo = exports.FocusInformation = exports.TabData = exports.ChromeOverview = exports.WindowDetailInfosDTO = exports.WindowDetailResponse = exports.WindowInfoDTO = exports.ControlDTO = exports.InstalledProgramDTO = exports.TaskbarIconDTO = exports.DesktopIconDTO = exports.SimpleResponse = exports.CSharpCodeResponse = exports.ChromeScriptResponse = exports.ChromeTabDetails = exports.ChromeTab = exports.ScreenGrasp2Response = exports.ActionResponse = exports.Point = exports.ScreenshotResponse = exports.ExistingChromeInstanceStrategy = exports.MechanismType = void 0;
/**
* Specifies the mechanism to use for AI-based UI element interaction.
*/
var MechanismType;
(function (MechanismType) {
MechanismType["ScreenGrasp2"] = "screengrasp2";
MechanismType["ScreenGrasp2Low"] = "screengrasp2-low";
MechanismType["ScreenGraspMedium"] = "screengrasp-medium";
MechanismType["ScreenGraspHigh"] = "screengrasp-high";
MechanismType["LLabs"] = "llabs";
MechanismType["AnthropicComputerUse"] = "anthropic-computer-use";
MechanismType["OpenAIComputerUse"] = "openai-computer-use";
MechanismType["Qwen25Vl72b"] = "qwen25-vl-72b";
})(MechanismType || (exports.MechanismType = MechanismType = {}));
/**
* Strategy to use when an existing Chrome instance is already running with the same user profile.
* Mirrors the C# enum.
*/
var ExistingChromeInstanceStrategy;
(function (ExistingChromeInstanceStrategy) {
/** Throw an error if an existing Chrome instance is using the same user profile. */
ExistingChromeInstanceStrategy[ExistingChromeInstanceStrategy["ThrowError"] = 0] = "ThrowError";
/** Force close any existing Chrome instances before starting a new one. */
ExistingChromeInstanceStrategy[ExistingChromeInstanceStrategy["ForceClose"] = 1] = "ForceClose";
/** Start a Playwright-managed Chrome without using the user profile. */
ExistingChromeInstanceStrategy[ExistingChromeInstanceStrategy["StartWithoutUserProfile"] = 2] = "StartWithoutUserProfile";
})(ExistingChromeInstanceStrategy || (exports.ExistingChromeInstanceStrategy = ExistingChromeInstanceStrategy = {}));
/**
* Response from the screenshot endpoint
*/
class ScreenshotResponse {
constructor(data) {
var _a;
this.success = data.success;
this.imageBase64 = data.imageBase64;
this.timestamp = data.timestamp;
this.message = (_a = data.message) !== null && _a !== void 0 ? _a : null;
}
/** Raw image bytes */
get imageBytes() {
return Buffer.from(this.imageBase64, 'base64');
}
/** Mime type of the image */
get imageMimeType() {
// Assuming JPEG as per C# comment, though this could be dynamic in future
return "image/jpeg";
}
toJSON() {
return {
success: this.success,
imageBase64: this.imageBase64,
timestamp: this.timestamp,
message: this.message,
};
}
}
exports.ScreenshotResponse = ScreenshotResponse;
/**
* Represents a point on the screen with X and Y coordinates
*/
class Point {
constructor(data) {
this.x = data.x;
this.y = data.y;
}
toJSON() {
return {
x: this.x,
y: this.y,
};
}
}
exports.Point = Point;
/**
* Generic response for action endpoints
*/
class ActionResponse {
constructor(data) {
var _a, _b;
this.success = data.success;
this.message = (_a = data.message) !== null && _a !== void 0 ? _a : null;
this.resultValue = (_b = data.resultValue) !== null && _b !== void 0 ? _b : null; // Initialize new property
}
toJSON() {
return {
success: this.success,
message: this.message,
resultValue: this.resultValue, // Added to JSON output
};
}
}
exports.ActionResponse = ActionResponse;
/**
* Response from the ScreenGrasp2 endpoint (find-ui-element-by-description)
*/
class ScreenGrasp2Response extends ActionResponse {
constructor(data) {
var _a, _b, _c;
super({ success: data.success, message: data.message });
this.x = (_a = data.x) !== null && _a !== void 0 ? _a : null;
this.y = (_b = data.y) !== null && _b !== void 0 ? _b : null;
this.status = (_c = data.status) !== null && _c !== void 0 ? _c : null;
}
// Override toJSON to include specific properties
toJSON() {
return {
...super.toJSON(),
x: this.x,
y: this.y,
status: this.status,
};
}
}
exports.ScreenGrasp2Response = ScreenGrasp2Response;
/**
* Information about a Chrome browser tab
*/
class ChromeTab {
constructor(data) {
this.id = data.id;
this.title = data.title;
this.url = data.url;
this.isActive = data.isActive;
}
toJSON() {
return {
id: this.id,
title: this.title,
url: this.url,
isActive: this.isActive,
};
}
}
exports.ChromeTab = ChromeTab;
/**
* Detailed information about a Chrome tab
*/
class ChromeTabDetails {
constructor(data) {
var _a;
this.currentTabTitle = data.currentTabTitle;
this.currentTabIndex = data.currentTabIndex;
this.currentChromeTabMostRelevantElements = data.currentChromeTabMostRelevantElements;
this.chromeInstances = data.chromeInstances;
this.note = (_a = data.note) !== null && _a !== void 0 ? _a : null;
}
toJSON() {
var _a, _b;
return {
currentTabTitle: this.currentTabTitle,
currentTabIndex: this.currentTabIndex,
currentChromeTabMostRelevantElements: (_a = this.currentChromeTabMostRelevantElements) === null || _a === void 0 ? void 0 : _a.map(e => e.toJSON ? e.toJSON() : e),
chromeInstances: (_b = this.chromeInstances) === null || _b === void 0 ? void 0 : _b.map(i => i.toJSON ? i.toJSON() : i),
note: this.note,
};
}
}
exports.ChromeTabDetails = ChromeTabDetails;
/**
* Response from Chrome script execution
*/
class ChromeScriptResponse extends ActionResponse {
constructor(data) {
var _a;
super({ success: data.success, message: data.message });
this.result = (_a = data.result) !== null && _a !== void 0 ? _a : null;
}
toJSON() {
return {
...super.toJSON(),
result: this.result,
};
}
}
exports.ChromeScriptResponse = ChromeScriptResponse;
/**
* Response from C# code execution
*/
class CSharpCodeResponse extends ActionResponse {
constructor(data) {
var _a;
super({ success: data.success, message: data.message });
this.result = (_a = data.result) !== null && _a !== void 0 ? _a : null;
}
toJSON() {
return {
...super.toJSON(),
result: this.result,
};
}
}
exports.CSharpCodeResponse = CSharpCodeResponse;
/**
* Simple response with a message
*/
class SimpleResponse {
constructor(data) {
var _a, _b, _c;
this.success = (_a = data.success) !== null && _a !== void 0 ? _a : true;
this.message = (_b = data.message) !== null && _b !== void 0 ? _b : null;
this.internalMessage = (_c = data.internalMessage) !== null && _c !== void 0 ? _c : null;
}
toJSON() {
return {
success: this.success,
message: this.message,
internalMessage: this.internalMessage,
};
}
}
exports.SimpleResponse = SimpleResponse;
/**
* Information about a desktop icon
*/
class DesktopIconDTO {
constructor(data) {
this.name = data.name;
this.path = data.path;
}
toJSON() {
return {
name: this.name,
path: this.path,
};
}
}
exports.DesktopIconDTO = DesktopIconDTO;
/**
* Information about a taskbar icon
*/
class TaskbarIconDTO {
constructor(data) {
this.name = data.name;
this.path = data.path;
}
toJSON() {
return {
name: this.name,
path: this.path,
};
}
}
exports.TaskbarIconDTO = TaskbarIconDTO;
/**
* Information about an installed program
*/
class InstalledProgramDTO {
constructor(data) {
this.name = data.name;
this.executablePath = data.executablePath;
}
toJSON() {
return {
name: this.name,
executablePath: this.executablePath,
};
}
}
exports.InstalledProgramDTO = InstalledProgramDTO;
/**
* Information about a UI control
*/
// Note: We deliberately exclude recursive properties and parent from toJSON
class ControlDTO {
constructor(data) {
var _a, _b, _c, _d, _e, _f;
this.id = data.id;
this.name = (_a = data.name) !== null && _a !== void 0 ? _a : null;
this.creationDate = data.creationDate;
this.controlType = (_b = data.controlType) !== null && _b !== void 0 ? _b : null;
this.supportsSetValue = (_c = data.supportsSetValue) !== null && _c !== void 0 ? _c : null;
this.supportsInvoke = (_d = data.supportsInvoke) !== null && _d !== void 0 ? _d : null;
this.currentValue = (_e = data.currentValue) !== null && _e !== void 0 ? _e : null;
// Reconstruct children as ControlDTO instances if they exist
this.children = data.children ? data.children.map(cData => new ControlDTO(cData)) : null;
// IMPORTANT: Avoid creating a new parent instance here to prevent infinite loops
// The parent should ideally be assigned after creation if needed for navigation,
// but the raw data shouldn't contain nested parent ControlDTOs.
this.parent = (_f = data.parent) !== null && _f !== void 0 ? _f : null;
this.isSmoothOperator = data.isSmoothOperator;
// Set parent for children after construction
if (this.children) {
this.children.forEach(child => child.parent = this);
}
}
/** Recursively get all descendant controls. */
get childrenRecursive() {
const descendants = [];
if (!this.children) {
return descendants;
}
for (const child of this.children) {
if (child) { // Check if child is not null
descendants.push(child);
descendants.push(...child.childrenRecursive); // Recursive call
}
}
return descendants;
}
/** Get all ancestor controls. */
get parentsRecursive() {
const ancestors = [];
let current = this.parent;
while (current) {
ancestors.push(current);
current = current.parent; // Move up the hierarchy
}
return ancestors;
}
/** Find the closest ancestor control that is a Window. */
get parentWindow() {
let current = this.parent;
while (current) {
if (current.controlType === "Window") {
return current;
}
current = current.parent;
}
return null;
}
// We don't need allChildrenRecursive or allParentsRecursive as separate properties;
// the getters above compute them on demand.
/** Custom serialization to avoid circular references and large payloads */
toJSON() {
var _a, _b;
// Explicitly list properties to include, excluding 'parent' and computed getters
return {
id: this.id,
name: this.name,
creationDate: this.creationDate,
controlType: this.controlType,
supportsSetValue: this.supportsSetValue,
supportsInvoke: this.supportsInvoke,
currentValue: this.currentValue,
// Serialize children, but ensure they also use toJSON to avoid parent recursion
children: (_b = (_a = this.children) === null || _a === void 0 ? void 0 : _a.map((child) => (child === null || child === void 0 ? void 0 : child.toJSON) ? child.toJSON() : child)) !== null && _b !== void 0 ? _b : null,
isSmoothOperator: this.isSmoothOperator,
};
}
}
exports.ControlDTO = ControlDTO;
/**
* Information about a window
*/
class WindowInfoDTO {
constructor(data) {
var _a, _b, _c, _d, _e;
this.id = data.id;
this.title = (_a = data.title) !== null && _a !== void 0 ? _a : null;
this.executablePath = (_b = data.executablePath) !== null && _b !== void 0 ? _b : null;
this.isForeground = (_c = data.isForeground) !== null && _c !== void 0 ? _c : null;
this.processName = (_d = data.processName) !== null && _d !== void 0 ? _d : null;
this.isMinimized = (_e = data.isMinimized) !== null && _e !== void 0 ? _e : null;
// Reconstruct detailInfos if present
this.detailInfos = data.detailInfos ? new WindowDetailResponse(data.detailInfos) : null;
}
toJSON() {
var _a;
return {
id: this.id,
title: this.title,
executablePath: this.executablePath,
isForeground: this.isForeground,
processName: this.processName,
isMinimized: this.isMinimized,
// Serialize detailInfos if it exists
detailInfos: ((_a = this.detailInfos) === null || _a === void 0 ? void 0 : _a.toJSON) ? this.detailInfos.toJSON() : this.detailInfos,
};
}
}
exports.WindowInfoDTO = WindowInfoDTO;
/**
* Wrapper for WindowDetailInfosDTO, potentially from older API versions
*/
class WindowDetailResponse {
constructor(data) {
var _a;
// Reconstruct details if present
this.details = data.details ? new WindowDetailInfosDTO(data.details) : null;
this.message = (_a = data.message) !== null && _a !== void 0 ? _a : null;
}
toJSON() {
var _a;
return {
// Serialize details if it exists
details: ((_a = this.details) === null || _a === void 0 ? void 0 : _a.toJSON) ? this.details.toJSON() : this.details,
message: this.message,
};
}
}
exports.WindowDetailResponse = WindowDetailResponse;
/**
* Detailed UI automation information for a window
*/
class WindowDetailInfosDTO {
constructor(data) {
var _a;
this.note = (_a = data.note) !== null && _a !== void 0 ? _a : null;
// Reconstruct window and userInterfaceElements if present
this.window = data.window ? new WindowInfoDTO(data.window) : null;
this.userInterfaceElements = data.userInterfaceElements ? new ControlDTO(data.userInterfaceElements) : null;
}
toJSON() {
var _a, _b;
return {
note: this.note,
// Serialize window and userInterfaceElements if they exist
window: ((_a = this.window) === null || _a === void 0 ? void 0 : _a.toJSON) ? this.window.toJSON() : this.window,
userInterfaceElements: ((_b = this.userInterfaceElements) === null || _b === void 0 ? void 0 : _b.toJSON) ? this.userInterfaceElements.toJSON() : this.userInterfaceElements,
};
}
}
exports.WindowDetailInfosDTO = WindowDetailInfosDTO;
/**
* Overview information about a single Chrome instance
*/
class ChromeOverview {
constructor(data) {
this.instanceId = data.instanceId;
// Reconstruct tabs as TabData instances
this.tabs = data.tabs.map(tData => new TabData(tData));
this.lastUpdate = data.lastUpdate;
}
toJSON() {
return {
instanceId: this.instanceId,
// Serialize tabs
tabs: this.tabs.map(tab => tab.toJSON()),
lastUpdate: this.lastUpdate,
};
}
}
exports.ChromeOverview = ChromeOverview;
/**
* Data for a single tab within a Chrome instance
*/
class TabData {
constructor(data) {
var _a, _b, _c;
this.id = data.id;
this.url = data.url;
this.isActive = data.isActive;
this.html = (_a = data.html) !== null && _a !== void 0 ? _a : null;
this.text = (_b = data.text) !== null && _b !== void 0 ? _b : null;
this.idString = (_c = data.idString) !== null && _c !== void 0 ? _c : null;
this.tabNr = data.tabNr;
}
toJSON() {
return {
id: this.id,
url: this.url,
isActive: this.isActive,
html: this.html,
text: this.text,
idString: this.idString,
tabNr: this.tabNr,
};
}
}
exports.TabData = TabData;
/**
* Information about the currently focused element
*/
class FocusInformation {
constructor(data) {
var _a;
// Reconstruct complex types
this.focusedElement = data.focusedElement ? new ControlDTO(data.focusedElement) : null;
this.focusedElementParentWindow = data.focusedElementParentWindow ? new WindowInfoDTO(data.focusedElementParentWindow) : null;
this.someOtherElementsInSameWindowThatMightBeRelevant = data.someOtherElementsInSameWindowThatMightBeRelevant
? data.someOtherElementsInSameWindowThatMightBeRelevant.map(cData => new ControlDTO(cData))
: null;
this.currentChromeTabMostRelevantElements = data.currentChromeTabMostRelevantElements
? data.currentChromeTabMostRelevantElements.map(eData => new ChromeElementInfo(eData))
: null;
this.isChrome = data.isChrome;
this.note = (_a = data.note) !== null && _a !== void 0 ? _a : null;
}
toJSON() {
var _a, _b, _c, _d, _e, _f;
return {
// Serialize complex types if they exist
focusedElement: ((_a = this.focusedElement) === null || _a === void 0 ? void 0 : _a.toJSON) ? this.focusedElement.toJSON() : this.focusedElement,
focusedElementParentWindow: ((_b = this.focusedElementParentWindow) === null || _b === void 0 ? void 0 : _b.toJSON) ? this.focusedElementParentWindow.toJSON() : this.focusedElementParentWindow,
someOtherElementsInSameWindowThatMightBeRelevant: (_d = (_c = this.someOtherElementsInSameWindowThatMightBeRelevant) === null || _c === void 0 ? void 0 : _c.map(el => el.toJSON ? el.toJSON() : el)) !== null && _d !== void 0 ? _d : null,
currentChromeTabMostRelevantElements: (_f = (_e = this.currentChromeTabMostRelevantElements) === null || _e === void 0 ? void 0 : _e.map(el => el.toJSON ? el.toJSON() : el)) !== null && _f !== void 0 ? _f : null,
isChrome: this.isChrome,
note: this.note,
};
}
}
exports.FocusInformation = FocusInformation;
/**
* Detailed information about an element within a Chrome tab
*/
class ChromeElementInfo {
constructor(data) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
this.smoothOpId = (_a = data.smoothOpId) !== null && _a !== void 0 ? _a : null;
this.tagName = (_b = data.tagName) !== null && _b !== void 0 ? _b : null;
this.cssSelector = (_c = data.cssSelector) !== null && _c !== void 0 ? _c : null;
this.innerText = (_d = data.innerText) !== null && _d !== void 0 ? _d : null;
this.isVisible = (_e = data.isVisible) !== null && _e !== void 0 ? _e : null;
this.score = (_f = data.score) !== null && _f !== void 0 ? _f : null;
this.role = (_g = data.role) !== null && _g !== void 0 ? _g : null;
this.value = (_h = data.value) !== null && _h !== void 0 ? _h : null;
this.type = (_j = data.type) !== null && _j !== void 0 ? _j : null;
this.name = (_k = data.name) !== null && _k !== void 0 ? _k : null;
this.className = (_l = data.className) !== null && _l !== void 0 ? _l : null;
this.semantic = (_m = data.semantic) !== null && _m !== void 0 ? _m : null;
this.dataAttributes = (_o = data.dataAttributes) !== null && _o !== void 0 ? _o : null;
this.truncatedHtml = (_p = data.truncatedHtml) !== null && _p !== void 0 ? _p : null;
this.boundingRect = (_q = data.boundingRect) !== null && _q !== void 0 ? _q : null;
// Reconstruct centerPoint if present
this.centerPoint = data.centerPoint ? new Point(data.centerPoint) : null;
}
toJSON() {
var _a;
return {
smoothOpId: this.smoothOpId,
tagName: this.tagName,
cssSelector: this.cssSelector,
innerText: this.innerText,
isVisible: this.isVisible,
score: this.score,
role: this.role,
value: this.value,
type: this.type,
name: this.name,
className: this.className,
semantic: this.semantic,
dataAttributes: this.dataAttributes,
truncatedHtml: this.truncatedHtml,
boundingRect: this.boundingRect,
// Serialize centerPoint if it exists
centerPoint: ((_a = this.centerPoint) === null || _a === void 0 ? void 0 : _a.toJSON) ? this.centerPoint.toJSON() : this.centerPoint,
};
}
}
exports.ChromeElementInfo = ChromeElementInfo;
/**
* Response from the system overview endpoint
*/
class OverviewResponse {
constructor(data) {
var _a;
// Reconstruct complex lists
this.windows = data.windows ? data.windows.map(wData => new WindowInfoDTO(wData)) : null;
this.focusInfo = data.focusInfo ? new FocusInformation(data.focusInfo) : null;
this.chromeInstances = data.chromeInstances ? data.chromeInstances.map(cData => new ChromeOverview(cData)) : null;
this.taskbarIcons = data.taskbarIcons ? data.taskbarIcons.map(tData => new TaskbarIconDTO(tData)) : null;
this.desktopIcons = data.desktopIcons ? data.desktopIcons.map(dData => new DesktopIconDTO(dData)) : null;
this.installedPrograms = data.installedPrograms ? data.installedPrograms.map(pData => new InstalledProgramDTO(pData)) : null;
this.importantNote = (_a = data.importantNote) !== null && _a !== void 0 ? _a : null;
}
toJSON() {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
return {
// Serialize complex lists if they exist
windows: (_b = (_a = this.windows) === null || _a === void 0 ? void 0 : _a.map(el => el.toJSON ? el.toJSON() : el)) !== null && _b !== void 0 ? _b : null,
focusInfo: ((_c = this.focusInfo) === null || _c === void 0 ? void 0 : _c.toJSON) ? this.focusInfo.toJSON() : this.focusInfo,
chromeInstances: (_e = (_d = this.chromeInstances) === null || _d === void 0 ? void 0 : _d.map(el => el.toJSON ? el.toJSON() : el)) !== null && _e !== void 0 ? _e : null,
taskbarIcons: (_g = (_f = this.taskbarIcons) === null || _f === void 0 ? void 0 : _f.map(el => el.toJSON ? el.toJSON() : el)) !== null && _g !== void 0 ? _g : null,
desktopIcons: (_j = (_h = this.desktopIcons) === null || _h === void 0 ? void 0 : _h.map(el => el.toJSON ? el.toJSON() : el)) !== null && _j !== void 0 ? _j : null,
installedPrograms: (_l = (_k = this.installedPrograms) === null || _k === void 0 ? void 0 : _k.map(el => el.toJSON ? el.toJSON() : el)) !== null && _l !== void 0 ? _l : null,
importantNote: this.importantNote,
};
}
}
exports.OverviewResponse = OverviewResponse;
//# sourceMappingURL=models.js.map