{"version":3,"file":"agent/types.mjs","sources":["webpack://@agent-infra/browser-use/./src/agent/types.ts"],"sourcesContent":["/**\n * The following code is modified based on\n * https://github.com/nanobrowser/nanobrowser/blob/master/chrome-extension/src/background/agent/types.ts\n *\n * Apache-2.0 License\n * Copyright (c) 2024 alexchenzl\n * https://github.com/nanobrowser/nanobrowser/blob/master/LICENSE\n */\nimport { z } from 'zod';\nimport type BrowserContext from '../browser/context';\nimport type MessageManager from './messages/service';\nimport type { EventManager } from './event/manager';\nimport { type Actors, type ExecutionState, AgentEvent } from './event/types';\nimport { BrowserState, PageState } from '../browser/types';\n\nexport interface AgentOptions {\n  maxSteps: number;\n  maxActionsPerStep: number;\n  maxFailures: number;\n  retryDelay: number;\n  maxInputTokens: number;\n  maxErrorLength: number;\n  useVision: boolean;\n  useVisionForPlanner: boolean;\n  validateOutput: boolean;\n  includeAttributes: string[];\n  planningInterval: number;\n}\n\nexport const DEFAULT_AGENT_OPTIONS: AgentOptions = {\n  maxSteps: 100,\n  maxActionsPerStep: 10,\n  maxFailures: 3,\n  retryDelay: 10,\n  maxInputTokens: 128000,\n  maxErrorLength: 400,\n  useVision: false,\n  useVisionForPlanner: false,\n  validateOutput: true,\n  includeAttributes: [\n    'title',\n    'type',\n    'name',\n    'role',\n    'tabindex',\n    'aria-label',\n    'placeholder',\n    'value',\n    'alt',\n    'aria-expanded',\n  ],\n  planningInterval: 3,\n};\n\nexport class AgentContext {\n  taskId: string;\n  browserContext: BrowserContext;\n  messageManager: MessageManager;\n  eventManager: EventManager;\n  options: AgentOptions;\n  paused: boolean;\n  stopped: boolean;\n  consecutiveFailures: number;\n  nSteps: number;\n  stepInfo: AgentStepInfo | null;\n  actionResults: ActionResult[];\n  stateMessageAdded: boolean;\n  constructor(\n    taskId: string,\n    browserContext: BrowserContext,\n    messageManager: MessageManager,\n    eventManager: EventManager,\n    options: Partial<AgentOptions>,\n  ) {\n    this.taskId = taskId;\n    this.browserContext = browserContext;\n    this.messageManager = messageManager;\n    this.eventManager = eventManager;\n    this.options = { ...DEFAULT_AGENT_OPTIONS, ...options };\n\n    this.paused = false;\n    this.stopped = false;\n    this.nSteps = 0;\n    this.consecutiveFailures = 0;\n    this.stepInfo = null;\n    this.actionResults = [];\n    this.stateMessageAdded = false;\n  }\n\n  async emitEvent(\n    actor: Actors,\n    state: ExecutionState,\n    eventDetails: string,\n    browserState?: BrowserState,\n  ) {\n    const event = new AgentEvent(actor, state, {\n      taskId: this.taskId,\n      step: this.nSteps,\n      maxSteps: this.options.maxSteps,\n      details: eventDetails,\n      browserState,\n    });\n    await this.eventManager.emit(event);\n  }\n\n  async pause() {\n    this.paused = true;\n  }\n\n  async resume() {\n    this.paused = false;\n  }\n\n  async stop() {\n    this.stopped = true;\n  }\n}\n\nexport class AgentStepInfo {\n  stepNumber: number;\n  maxSteps: number;\n\n  constructor(params: { stepNumber: number; maxSteps: number }) {\n    this.stepNumber = params.stepNumber;\n    this.maxSteps = params.maxSteps;\n  }\n}\n\ninterface ActionResultParams {\n  isDone?: boolean;\n  extractedContent?: string | null;\n  error?: string | null;\n  includeInMemory?: boolean;\n}\n\nexport class ActionResult {\n  isDone: boolean;\n  extractedContent: string | null;\n  error: string | null;\n  includeInMemory: boolean;\n\n  constructor(params: ActionResultParams = {}) {\n    this.isDone = params.isDone ?? false;\n    this.extractedContent = params.extractedContent ?? null;\n    this.error = params.error ?? null;\n    this.includeInMemory = params.includeInMemory ?? false;\n  }\n}\n\nexport type WrappedActionResult = ActionResult & {\n  toolCallId: string;\n};\n\nexport const agentBrainSchema = z.object({\n  page_summary: z.string(),\n  evaluation_previous_goal: z.string(),\n  memory: z.string(),\n  next_goal: z.string(),\n});\n\nexport type AgentBrain = z.infer<typeof agentBrainSchema>;\n\n// Make AgentOutput generic with Zod schema\nexport interface AgentOutput<T = unknown> {\n  /**\n   * The unique identifier for the agent\n   */\n  id: string;\n\n  /**\n   * The result of the agent's step\n   */\n  result?: T;\n  /**\n   * The error that occurred during the agent's action\n   */\n  error?: string;\n}\n"],"names":["DEFAULT_AGENT_OPTIONS","AgentContext","actor","state","eventDetails","browserState","event","AgentEvent","taskId","browserContext","messageManager","eventManager","options","AgentStepInfo","params","ActionResult","agentBrainSchema","z"],"mappings":";;;;;;AAOC;;;;;;;;;;AAsBM,MAAMA,wBAAsC;IACjD,UAAU;IACV,mBAAmB;IACnB,aAAa;IACb,YAAY;IACZ,gBAAgB;IAChB,gBAAgB;IAChB,WAAW;IACX,qBAAqB;IACrB,gBAAgB;IAChB,mBAAmB;QACjB;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;KACD;IACD,kBAAkB;AACpB;AAEO,MAAMC;IAmCX,MAAM,UACJC,KAAa,EACbC,KAAqB,EACrBC,YAAoB,EACpBC,YAA2B,EAC3B;QACA,MAAMC,QAAQ,IAAIC,WAAWL,OAAOC,OAAO;YACzC,QAAQ,IAAI,CAAC,MAAM;YACnB,MAAM,IAAI,CAAC,MAAM;YACjB,UAAU,IAAI,CAAC,OAAO,CAAC,QAAQ;YAC/B,SAASC;YACTC;QACF;QACA,MAAM,IAAI,CAAC,YAAY,CAAC,IAAI,CAACC;IAC/B;IAEA,MAAM,QAAQ;QACZ,IAAI,CAAC,MAAM,GAAG;IAChB;IAEA,MAAM,SAAS;QACb,IAAI,CAAC,MAAM,GAAG;IAChB;IAEA,MAAM,OAAO;QACX,IAAI,CAAC,OAAO,GAAG;IACjB;IAhDA,YACEE,MAAc,EACdC,cAA8B,EAC9BC,cAA8B,EAC9BC,YAA0B,EAC1BC,OAA8B,CAC9B;QAlBF;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QAQE,IAAI,CAAC,MAAM,GAAGJ;QACd,IAAI,CAAC,cAAc,GAAGC;QACtB,IAAI,CAAC,cAAc,GAAGC;QACtB,IAAI,CAAC,YAAY,GAAGC;QACpB,IAAI,CAAC,OAAO,GAAG;YAAE,GAAGX,qBAAqB;YAAE,GAAGY,OAAO;QAAC;QAEtD,IAAI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