UNPKG

donobu

Version:

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

121 lines 5.47 kB
import { Page } from 'playwright'; import { GptClient } from '../clients/GptClient'; import { FlowMetadata } from '../models/FlowMetadata'; import { ProposedToolCall } from '../models/ProposedToolCall'; import { ToolCall } from '../models/ToolCall'; import { GptMessage, StructuredOutputMessage } from '../models/GptMessage'; import { ToolManager } from './ToolManager'; import { ToolTipper } from './ToolTipper'; import { FlowsPersistence } from '../persistence/FlowsPersistence'; import { FocusedPage } from '../models/FocusedPage'; import { DonobuFlowsManager } from './DonobuFlowsManager'; import { BrowserFramework } from '../models/BrowserFramework'; import { JSONSchema7 } from 'json-schema'; /** * Return an object conforming to the given JSON-schema. The object will be * generated considering the given page and tool call history. */ export declare function extractFromPage(instruction: string, jsonSchema: JSONSchema7, page: Page | null, toolCallHistory: ToolCall[], gptClient: GptClient): Promise<StructuredOutputMessage>; /** * This is the main business-logic class of Donobu. This class goes through a * flow via its `run` method. */ export declare class DonobuFlow { readonly flowsManager: DonobuFlowsManager; readonly browserFramework: BrowserFramework; readonly persistence: FlowsPersistence; readonly gptClient: GptClient | null; readonly toolManager: ToolManager; readonly toolTipper: ToolTipper; readonly proposedToolCalls: ProposedToolCall<any>[]; readonly invokedToolCalls: ToolCall[]; readonly gptMessages: GptMessage[]; readonly focusedPage: FocusedPage; readonly metadata: FlowMetadata; private static readonly MAIN_MESSAGE_ELEMENT_LIST_MARKER; private static readonly MAX_PNG_BYTES_FOR_LLM; constructor(flowsManager: DonobuFlowsManager, browserFramework: BrowserFramework, persistence: FlowsPersistence, gptClient: GptClient | null, toolManager: ToolManager, toolTipper: ToolTipper, proposedToolCalls: ProposedToolCall<any>[], invokedToolCalls: ToolCall[], gptMessages: GptMessage[], focusedPage: FocusedPage, metadata: FlowMetadata); run(): Promise<void>; /** * This method re-assigns the currently focused page (presumably due to the * current page being closed). If there are no other pages in the current * browser context, then the flow is marked as a failure. */ private onFocusedPageClosed; /** * This method is called if there are persistent GPT platform failures (there * are internal retries). This method will mark the flow as a failure. */ private onPersistentGptFailure; /** * This method is called if there is an unhandled unexpected exception. This * method will mark the flow as a failure. */ private onUnexpectedException; /** * This method is called when a flow is complete (i.e. when {@link DonobuFlow.run} should return). */ private onComplete; /** * Attempt to POST a JSON body containing given flow ID to the given * ${@link callbackUrl} if the URL is non-null. Note that there is no retying * if the POST fails for any reason; this is a best-effort 1-shot try. */ private static invokeFlowFinishedCallback; private onDialog; private maybeUpdateControlPanel; private getControlPanelMessage; /** * Transitions the flow to its next state. After this method completes, the * `this.metadata.state` will have been updated and the * `this.metadata.nextState` will have been cleared. */ private transitionState; private maybeForceEnableControlPanel; private isHeadless; private setupInitScriptsAndBindings; /** * Returns an object formatted according to the following priority: * * <ol> * <li>If the `result` for this flow is non-null, then it is returned as-is. * <li>If the given next state of the flow is `SUCCESS`, the * `resultJsonSchema` is non-null, and the `gptClient` is non-null, * then an attempt is made to take the context of the entire run and * conform it to this schema. If there is an error when attempting to * map the data of the current flow to the `resultJsonSchema`, then an * object with error details is returned. * <li>Otherwise, the `metadata` of the last tool call is returned. * </ol> */ private createResultJson; /** * All this method does is set the next state to {@link State.INITIALIZING}. */ private onUnstarted; /** * This method sets up the page initialization scripts and bindings, and * initializes the GPT message history. */ private onInitializing; private onRunningAction; private onQueryingLlmForNextAction; private onWaitingForUserForNextAction; private onPaused; private onResuming; private onFailed; private onSuccess; private updateGptMessagesWithUserProposedToolCall; private queryGptForProposedToolCalls; /** * Calls {@link #gptClient} with the given messages and will retry on failure * up to an internally specified maximum number of attempts. */ private queryGptWithRetry; private updateTokenCounts; private static createSystemMessageForOverallObjective; private static createMainUserMessage; private static createOptimizedHistoryForGptCall; private setupDonobuControlPanel; } //# sourceMappingURL=DonobuFlow.d.ts.map