frontend/src/react/plugins/agent/AGENT.md
This document explains how the page agent works and how to maintain it. It is intended for both humans and LLMs.
frontend/src/plugins/agent/
├── components/ # Vue UI (AgentWindow, message rendering)
├── dom/ # DOM interaction layer
│ ├── actions.ts # Execute DOM actions (click, input, select, scroll)
│ └── domTree.ts # Extract interactive DOM elements and snapshot-local eN refs
├── logic/
│ ├── agentLoop.ts # Main agent loop: tool calls, retries, message history
│ ├── context.ts # Extract page context from Pinia stores
│ ├── prompt.ts # System prompt construction
│ ├── types.ts # Shared types
│ ├── skills/ # On-demand workflow guides
│ │ ├── index.ts # Skill registry and get_skill handler
│ │ ├── query.ts
│ │ ├── databaseChange.ts
│ │ └── grantPermission.ts
│ └── tools/ # Tool implementations
│ ├── index.ts # Tool definitions and executor dispatcher
│ ├── callApi.ts # Execute API endpoints
│ ├── searchApi.ts # API discovery with search + alias map
│ ├── navigate.ts # Router navigation + route listing
│ ├── pageState.ts # Page context (semantic or DOM)
│ ├── domAction.ts # DOM action wrapper
│ └── gen/ # Generated API discovery artifacts
│ └── openapi-index.ts # Generated API endpoint and schema index
└── store/ # Pinia store for agent state
| Tool | Purpose |
|---|---|
search_api | Discover API endpoints, browse services, get request/response schemas |
call_api | Execute a Bytebase API endpoint |
navigate | Navigate to a page or list available routes |
get_page_state | Get current page context (route, stores, or DOM tree) |
dom_action | Interact with DOM elements (click, input, select, read, scroll) |
get_skill | Load step-by-step workflow guides for multi-step tasks |
The agent chooses between DOM and API based on page context:
When updating prompt text, examples, or maintenance docs for the page agent DOM tools:
[e1], not numeric indices.dom_action(ref="e1", ...) in examples.get_page_state(mode="dom") snapshot and must be refreshed after the DOM changes or the page is re-read.What: A compact, feature-grouped summary of API services. It is embedded directly in logic/prompt.ts so the agent can choose the right service quickly before using search_api for exact endpoint details.
Where: logic/prompt.ts (serviceDirectory constant)
Source of truth:
serviceDirectory string in logic/prompt.ts is a checked-in, manually maintained prompt aid.openapi-index.ts and search_api remain the actual API discovery source of truth.When to update:
pnpm --dir frontend run generate:openapi-index warns about uncovered servicesHow to update:
pnpm --dir frontend run generate:openapi-index.serviceDirectory block in logic/prompt.ts manually.serviceDirectory constant name.When users repeatedly search for a feature using terms that do not map cleanly to the right service, update the search heuristics in logic/tools/searchApi.ts so the agent can discover the relevant APIs more reliably.
What: Step-by-step workflow guides for multi-step tasks (e.g., running a query, creating a schema change).
Where: logic/skills/
How to add a new skill:
logic/skills/mySkill.ts exporting { name, description, content }logic/skills/index.tsget_skill tool description in logic/tools/index.ts to list the new skillWhat: The navigate tool supports list=true which returns all valid route patterns from Vue Router at runtime. No maintenance needed — it reads directly from the router instance.
pnpm --dir frontend run generate:openapi-index
This reads backend/api/mcp/gen/openapi.yaml and produces gen/openapi-index.ts with all endpoint definitions and schemas. Run after proto changes that affect the API.