UNPKG

donobu

Version:

Create browser automations with an LLM agent and replay them as Playwright scripts.

63 lines 3.38 kB
import { Locator, Page } from 'playwright'; import { ToolCallContext } from '../models/ToolCallContext'; import { ToolCallResult } from '../models/ToolCallResult'; import { Tool } from './Tool'; import { ElementSelector } from '../models/ElementSelector'; import { BaseToolGptParameters } from '../models/BaseToolGptParameters'; export interface CoreParameters { } export interface SelectorBasedParameters extends CoreParameters { selector: ElementSelector; } export interface AnnotationBasedParameters extends BaseToolGptParameters, CoreParameters { /** * The reason why this particular numbered annotation was chosen. */ whyThisAnnotation: string; /** * The numbered annotation of the element to click. */ annotation: string; } /** * Tools that specify a numbered Donobu annotation to indicate which element to * interact with and support deterministic reruns should extend this interface. */ export declare abstract class ReplayableInteraction<CoreParameters, NonGptParameters extends SelectorBasedParameters & CoreParameters, GptParameters extends AnnotationBasedParameters & CoreParameters> extends Tool<SelectorBasedParameters, GptParameters> { static readonly MAX_LOCATOR_MATCH_COUNT = 5; constructor(name: string, description: string, parametersTypeNameForGptlessSchema: string, parametersTypeNameForGptSchema: string); call(context: ToolCallContext, parameters: NonGptParameters): Promise<ToolCallResult>; callFromGpt(context: ToolCallContext, parameters: GptParameters): Promise<ToolCallResult>; /** * Apply an operation to the given element. * * If the function does not throw, the operation is considered a success and * the returned string is written to the LLM message history. */ protected abstract invoke(context: ToolCallContext, parameters: CoreParameters, element: Locator): Promise<string>; private callCore; /** * Retrieves a list of {@link Locator} objects based on the provided selector * candidates, ordered by their match count in ascending order. If the match * count for a locator exceeds * {@link ReplayableInteraction.MAX_LOCATOR_MATCH_COUNT}, then they are ignored, as * it is considered too broad of a locator to be useful. * * This method iterates through a list of CSS selector candidates and creates * a {@link Locator} for each candidate. It counts the number of elements that * match each selector within a given page. If a frame selector is provided, * it looks for the elements within the specified frame; otherwise, it * searches within the entire page. Only locators with a positive match count * are added to the result list. * * @param page - The the web page to search within. * @param frameSelector - An optional CSS selector for a frame within the * page. If {@code null}, the search is performed in the entire page. * @param selectorCandidates A list of CSS selector strings to be used for * locating elements. * @return A list of {@link Locator} objects that have been found, ordered by * their match count in ascending order. */ static getLocatorsOrderedByMatchCount(page: Page, frameSelector: string | null, selectorCandidates: string[]): Promise<Locator[]>; } //# sourceMappingURL=ReplayableInteraction.d.ts.map