donobu
Version:
Create browser automations with an LLM agent and replay them as Playwright scripts.
47 lines • 2.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChangeWebBrowserTabTool = exports.ChangeWebBrowserTabGptSchema = exports.ChangeWebBrowserTabCoreSchema = void 0;
const v4_1 = require("zod/v4");
const ToolCallResult_1 = require("../models/ToolCallResult");
const ToolSchema_1 = require("../models/ToolSchema");
const TargetUtils_1 = require("../utils/TargetUtils");
const Tool_1 = require("./Tool");
exports.ChangeWebBrowserTabCoreSchema = v4_1.z.object({
tabUrl: v4_1.z.string().describe('The URL for the tab to bring focus to.'),
});
exports.ChangeWebBrowserTabGptSchema = v4_1.z.object({
...ToolSchema_1.BaseGptArgsSchema.shape,
...exports.ChangeWebBrowserTabCoreSchema.shape,
});
class ChangeWebBrowserTabTool extends Tool_1.Tool {
constructor() {
super(ChangeWebBrowserTabTool.NAME, 'Change the focus of the current web browser tab to a different tab.', exports.ChangeWebBrowserTabCoreSchema, exports.ChangeWebBrowserTabGptSchema, false, undefined, ['web']);
}
async call(context, parameters) {
const desiredPage = (0, TargetUtils_1.webPage)(context)
.context()
.pages()
.find((tab) => tab.url() === parameters.tabUrl);
if (desiredPage) {
(0, TargetUtils_1.webTarget)(context).current = desiredPage;
return ToolCallResult_1.ToolCallResult.successful();
}
else {
const validTabUrls = (0, TargetUtils_1.webPage)(context)
.context()
.pages()
.map((p) => p.url());
return {
isSuccessful: false,
forLlm: `The ${parameters.tabUrl} tab URL is not present in the tab list: ${JSON.stringify(validTabUrls, null, 2)}`,
metadata: null,
};
}
}
async callFromGpt(context, parameters) {
return this.call(context, parameters);
}
}
exports.ChangeWebBrowserTabTool = ChangeWebBrowserTabTool;
ChangeWebBrowserTabTool.NAME = 'changeWebBrowserTab';
//# sourceMappingURL=ChangeWebBrowserTabTool.js.map