AIPex Documentation

repository·main·Indexed 22 days ago

https://github.com/aipexstudio/aipex

An open-source browser automation agent that runs as a browser extension, allowing AI agents (via MCP) and CLI tools to automate web tasks using existing sessions and cookies. Includes the aipex-mcp-bridge for integration with Cursor, Claude Desktop, and Windsurf, a browser-cli for high-level automation, and the @aipexstudio/aipex-react UI toolkit for building chat interfaces and content script UIs.

Tokens
77.1K
Snippets
142
Records
431
Agent score
79%

What's inside AIPex

  1. What is the aipex-browser skill?

    main

    AIPex provides a pre-packaged skill named aipex-browser. This is designed for agents that support the skill protocol (such as Claude Code or OpenClaw runtimes).

    The skill includes:

    • An optimized tool-use strategy.
    • Full parameter schemas for 30+ browser tools.
    • Common automation patterns.

    This allows the agent to control the browser efficiently without needing to perform manual exploration. For the full definition, refer to skill/SKILL.md.

  2. What is the AIPex `aipex-browser` Skill?

    main

    The aipex-browser skill is a pre-packaged automation skill set designed for agents that support the skill protocol (such as Claude Code or OpenClaw).

    It includes:

    • Built-in tool usage strategies.
    • Full parameter schemas for over 30+ browser automation tools.
    • Common automation patterns.

    This allows agents to control the browser efficiently without needing to manually discover tool definitions.

  3. Using Scripts in Skills

    main

    The scripts/ directory contains executable code (JavaScript/Browser/etc.) for tasks requiring deterministic reliability or those that are repeatedly rewritten. Including scripts is token-efficient and allows them to be executed without being fully loaded into the context window.

    Requirement: Every script must export a main function or have a main function as the entry point to serve as the standard interface for execution.

    // Option 1: Direct export
    function main(args) {
      // script logic here
    }
    module.exports = main;
    
    // Option 2: Object export
    function main(args) {
      // script logic here
    }
    module.exports = { main };
  4. Use the aipex-browser Skill

    main

    AIPex provides the aipex-browser skill, a specialized package for agents compatible with skill protocols (such as Claude Code or OpenClaw).

    This skill includes:

    • Tool-use strategies.
    • Full parameter schemas for over 30 browser automation tools.
    • Common usage patterns.

    This allows agents to operate the browser efficiently without trial-and-error. For detailed technical specifications, refer to skill/SKILL.md in the repository.

  5. Extend agent behavior with Plugins

    main

    Plugins allow you to observe and customize runtime behavior using hooks. You can implement an AgentPlugin to:

    • Mutate input before a turn (beforeChat)
    • Observe tool lifecycle events (onToolEvent)
    • Observe per-turn usage metrics (onMetrics)
    • Observe the final response (afterResponse)
    import { google } from "@ai-sdk/google";
    import { AIPex, aisdk, type AgentPlugin } from "@aipexstudio/aipex-core";
    
    const loggerPlugin: AgentPlugin = {
      id: "logger",
      hooks: {
        beforeChat: (payload) => {
          console.log("[beforeChat]", payload.input);
          return payload;
        },
        onToolEvent: ({ event }) => {
          if (event.type === "tool_call_start") {
            console.log("[tool]", event.toolName, event.params);
          }
        },
      },
    };
    
    const agent = AIPex.create({
      instructions: "You are a helpful assistant.",
      model: aisdk(google("gemini-2.5-flash")),
      plugins: [loggerPlugin],
    });
  6. How iframe handling works in snapshots

    main

    The library automatically traverses same-origin iframes to provide a unified snapshot tree.

    • Same-origin iframes: Content is fully traversed and included in the snapshot tree.
    • Nested iframes: Supports recursive traversal of nested same-origin iframes (up to 10 levels deep).
    • Cross-origin iframes: These are skipped due to browser security restrictions.
    • Coordinate tracking: Element bounding boxes account for iframe offsets for accurate positioning.

    Elements inside iframes are accessible via their unique id within the idToNode map.

    // Iframe content is automatically included in the snapshot
    const snapshot = collectDomSnapshot(document);
    
    // Elements inside iframes are accessible via their unique IDs
    const iframeElement = snapshot.idToNode['dom_iframe_element_123'];
  7. Understand the AIPex Monorepo Architecture and Dependency Rules

    main

    AIPex follows a strict multi-package (monorepo) architecture to prevent platform coupling and circular dependencies. When developing or extending the project, you must adhere to these dependency rules:

    • @core: The foundation. Contains pure TypeScript interface definitions, types, and abstract classes. It must have zero dependencies on any other package or platform API.
    • @browser-runtime: The Chrome implementation. It implements the interfaces defined in @core using CDP (Chrome DevTools Protocol) and contains runtime logic. It may only depend on @core.
    • @aipex-react: The UI layer. Contains pure UI components, Hooks, and adapters. It may only depend on @core. Strictly prohibited: @aipex-react must never depend on @browser-runtime to avoid platform coupling.
    • @use-cases: The application layer. Contains workflow templates and use-case implementations. It is allowed to depend on all lower-level packages.
    • browser-ext: The extension entry point. This is the final assembly point where all packages are composed and environment configurations are applied.
    ┌─────────────────────────────────────────────────────┐
    │                     @core                           │
    │            (纯 TypeScript 接口定义)                  │
    │    - 无平台依赖                                      │
    │    - 仅类型、接口、抽象类                            │
    └──────────────┬──────────────────┬───────────────────┘
                   │                  │
           ┌───────┴────────┐  ┌─────┴──────────┐
           │                │  │                 │
           ▼                │  ▼                 │
    ┌─────────────────┐     │  ┌─────────────────┐
    │ @browser-runtime│     │  │  @aipex-react   │
    │ (Chrome 实现)   │     │  │  (React UI)     │
    │ - CDP 集成      │     │  │  - 纯 UI 组件   │
    │ - 工具实现      │     │  │  - Hooks        │
    │ - 运行时逻辑    │     │  │  - 适配器       │
    └────────┬────────┘     │  └────────┬────────┘
             │              │           │
             └──────────────┼───────────┘
                            │
                            ▼
                   ┌─────────────────┐
                   │   @use-cases    │
                   │ (应用层,新建)   │
                   │ - 工作流模板     │
                   │ - 用例实现       │
                   └────────┬────────┘
                            │
                            ▼
                   ┌─────────────────┐
                   │   browser-ext   │
                   │   (扩展入口)     │
                   │ - 最终组装       │
                   │ - 环境配置       │
                   └─────────────────┘
  8. Using Assets in Skills

    main

    The assets/ directory contains files that are not intended to be loaded into the AI's context, but are used in the final output produced by AIPex.

    • Examples: Brand logos (assets/logo.png), PowerPoint templates (assets/slides.pptx), HTML/React boilerplate (assets/frontend-template/), or typography (assets/font.ttf).
    • Benefit: Separates output resources from documentation, allowing AIPex to use files without consuming context window tokens.
  9. Understand tool visibility in `packages/browser-ext`

    main

    In the packages/browser-ext package, the available tool surface for the extension agent is defined entirely by the allBrowserTools bundle (located in new-aipex/packages/browser-ext/src/lib/browser-agent-config.ts).

    Crucial Note: Any tool that is not explicitly included in the allBrowserTools bundle is invisible to the agent and cannot be invoked. If you are implementing or adding new tools, they must be added to this bundle to be accessible.

  10. Privacy and Accuracy Notes for Accessibility Audits

    main

    Privacy Warning

    Audits may capture sensitive information in screenshots or accessibility tree dumps (e.g., account names, personal data, auth tokens).

    • DO NOT include raw sensitive data in the final report.
    • If a screenshot contains PII, note this and recommend masking before sharing.

    Accuracy Disclaimer

    Visual judgments for contrast and visibility are estimates. Always recommend verification with dedicated tools such as WebAIM Contrast Checker or axe DevTools.

  11. What are Skills in AIPex?

    main

    Skills are modular, self-contained packages that extend AIPex's capabilities by providing specialized knowledge, workflows, and tools. They act as "onboarding guides" for specific domains, transforming AIPex from a general-purpose agent into a specialized agent equipped with procedural knowledge.

    Skills provide:

    1. Specialized workflows: Multi-step procedures for specific domains.
    2. Tool integrations: Instructions for working with specific file formats or APIs.
    3. Domain expertise: Company-specific knowledge, schemas, or business logic.
    4. Bundled resources: Scripts, references, and assets for complex tasks.
  12. Security boundaries and message validation for AIPex sidepanel

    main

    AIPex implements different trust levels for various entry points to the sidepanel. When integrating or extending the sidepanel, follow these security models:

    Entry Point Trust Levels

    • Trusted (User-triggered): chrome.action.onClicked and chrome.commands (shortcuts) require no additional validation.
    • Semi-trusted (Content Script): Messages from content scripts via open-sidepanel are handled by the Background script using sidePanel.open. To maintain security, the Background script does not pass data directly through this call.
    • External (External Sources): Messages received via onMessageExternal (e.g., openWithPrompt) must be restricted using the externally_connectable key in manifest.json.

    Message Validation Requirements

    • openWithPrompt: The prompt must be a non-empty string. Data is passed via chrome.storage.local rather than direct UI injection. The sidepanel must validate the timestamp to ensure it is within a 5-second TTL (Time-To-Live).
    • REPLAY_USER_MANUAL: When implementing this external message, you must perform schema validation on the steps array to prevent the injection of malicious step data.
    • Custom Model Hosts: When using BYOK (Bring Your Own Key) with a custom aiHost URL, ensure the URL is validated to prevent SSRF (Server-Side Request Forgery) attacks.