UNPKG

browser-use-typescript

Version:

A TypeScript-based browser automation framework

97 lines (96 loc) 5.92 kB
import { BaseChatModel } from "@langchain/core/language_models/chat_models"; import { BaseMessage } from "@langchain/core/messages"; import { Browser } from "../../browser/playwrightBrowser/browserService"; import { BrowserContext } from "../../browser/playwrightBrowser/browserContext"; import { Controller } from "../../controller/controllerContext"; import { ActionResult, AgentHistory, AgentHistoryList, AgentOutput, AgentSettings, AgentState, StepMetadata, ToolCallingMethod } from "../types"; import { DOMHistoryElement } from "../../domHIstory/historyTypes"; import { AgentStepInfo } from "../types"; import { BrowserState } from "../../browser/playwrightBrowser/type"; import { MessageManager } from "../message_manager/services"; import { ActionModel } from "../../controller/registry/types"; declare class Logger { private debugEnabled; private isDebugger; private colors; constructor(debugEnabled?: boolean, isDebugger?: boolean); error(message: string): void; log(message: string): void; debug(message: string): void; info(message: string): void; warn(message: string): void; trace(message: string): void; success(message: string): void; debuggerError(message: string): void; } export declare const logger: Logger; type NewStepCallback = ((browserState: BrowserState, agentOutput: AgentOutput, step: number) => void) | ((browserState: BrowserState, agentOutput: AgentOutput, step: number) => Promise<void>) | null; type DoneCallback = ((agentHistoryList: AgentHistoryList) => Promise<void>) | ((agentHistoryList: AgentHistoryList) => void) | null; type ExternalAgentStatusCallback = (() => Promise<boolean>) | null; export declare class Agent<Context = any> { task: string; llm: BaseChatModel; controller: Controller<Context>; sensitive_data: Record<string, string> | null; plannerModelName: string; settings: AgentSettings; state: AgentState; available_actions: string; tool_calling_method: ToolCallingMethod; initial_actions?: ActionModel[]; chat_model_library?: string; model_name?: string; browser_use_version?: string; browser_use_source?: string; private _message_manager; browser: Browser | null; browser_context: BrowserContext | null; injected_browser: boolean; injected_browser_context: boolean; register_new_step_callback: NewStepCallback; register_done_callback: DoneCallback; register_external_agent_status_raise_error_callback: ExternalAgentStatusCallback; context: Context | null; DoneActionModel: any; DoneAgentOutput: AgentOutput | undefined; ActionModel: ActionModel | undefined; AgentOutput: AgentOutput | undefined; /** * Agent constructor * Equivalent to Python's __init__ method */ constructor(task: string, llm: BaseChatModel, browser?: Browser | null, browser_context?: BrowserContext | null, controller?: Controller<Context>, sensitive_data?: Record<string, string> | null, initial_actions?: Array<Record<string, Record<string, any>>> | null, register_new_step_callback?: NewStepCallback, register_done_callback?: DoneCallback, register_external_agent_status_raise_error_callback?: ExternalAgentStatusCallback, use_vision?: boolean, use_vision_for_planner?: boolean, save_conversation_path?: string | null, save_conversation_path_encoding?: string | null, max_failures?: number, retry_delay?: number, override_system_message?: string | null, extend_system_message?: string | null, max_input_tokens?: number, validate_output?: boolean, message_context?: string | null, generate_gif?: boolean | string, available_file_paths?: string[] | null, include_attributes?: string[], max_actions_per_step?: number, tool_calling_method?: ToolCallingMethod | null, page_extraction_llm?: BaseChatModel | null, planner_llm?: BaseChatModel | null, planner_interval?: number, // Run planner every N steps injected_agent_state?: AgentState | null, context?: Context | null); take_step(): Promise<[boolean, boolean]>; run(this: Agent, max_steps?: number): Promise<AgentHistoryList | undefined>; multi_act(this: Agent, actions: ActionModel[], check_for_new_elements?: boolean): Promise<ActionResult[]>; _validate_output(): Promise<boolean>; add_new_task(new_task: string): void; _raise_if_stopped_or_paused(): Promise<void>; step(this: Agent, step_info?: AgentStepInfo): Promise<void>; _handle_step_error(error: Error): Promise<ActionResult[]>; _make_history_item(model_output: AgentOutput | null, state: BrowserState, result: ActionResult[], metadata?: StepMetadata): Promise<void>; _set_message_context(): string | null; _set_model_names(): void; _setup_action_models(): Promise<void>; _set_tool_calling_method(): ToolCallingMethod | null; THINK_TAGS: RegExp; STRAY_CLOSE_TAG: RegExp; _remove_think_tags(this: any, text: string): string; _convert_input_messages(this: any, input_messages: BaseMessage[]): BaseMessage[]; extract_json_from_model_output(this: Agent, content: string): any; get_next_action(this: Agent, input_messages: BaseMessage[]): Promise<AgentOutput>; rerun_history(history: AgentHistoryList, max_retries?: number, skip_failures?: boolean, delay_between_actions?: number): Promise<ActionResult[]>; _execute_history_step(history_item: AgentHistory, delay: number): Promise<ActionResult[]>; _update_action_indices(historical_element: DOMHistoryElement | null, action: ActionModel, // Type this properly based on your action model current_state: BrowserState): Promise<ActionModel | null>; save_history(file_path?: string): void; pause(): void; resume(): void; stop(): void; _convert_initial_actions(actions: Array<Record<string, Record<string, any>>>): ActionModel[]; _run_planner(): Promise<string | null>; get message_manager(): MessageManager; close(): Promise<void>; } export {};