API Integration
HAI Build Code Generator exposes a public API that allows other VS Code extensions to programmatically control Cline tasks. This enables powerful integrations and automation workflows.Overview
The HAI API provides methods to:- Start new coding tasks with optional images
- Send messages to active tasks
- Simulate button interactions
- Control task lifecycle
Getting Started
1. Install the Type Definitions
Copy the type definition file from the HAI Build repository:2. Add Extension Dependency
Ensure HAI Build is activated before your extension by adding it topackage.json:
3. Access the API
Get the API instance in your extension’sactivate function:
API Reference
startNewTask()
Starts a new task with an optional initial message and images. Signature:task(optional): Initial task descriptionimages(optional): Array of image data URIs in base64 format
- Clears any existing task
- Updates the webview state
- Initializes a new task with the provided prompt
- Opens the HAI Build sidebar if not already visible
sendMessage()
Sends a message to the currently active task. Signature:message(optional): Message text to sendimages(optional): Array of image data URIs
pressPrimaryButton()
Simulates clicking the primary button in the chat interface (e.g., “Save”, “Proceed”). Signature:- Auto-approve file changes in automation workflows
- Proceed with task execution programmatically
- Confirm user actions in headless scenarios
pressSecondaryButton()
Simulates clicking the secondary button (e.g., “Reject”, “Cancel”). Signature:Usage Patterns
Pattern 1: Task Automation
Create automated workflows that run Cline tasks:Pattern 2: Context-Aware Commands
Create VS Code commands that pass context to Cline:Pattern 3: Screenshot-Based Tasks
Capture screenshots and send to Cline:Pattern 4: Interactive Approval Flow
Implement custom approval logic:Pattern 5: Git Integration
Integrate with git workflows:Complete Integration Example
Here’s a full extension that integrates with HAI Build:Best Practices
Error Handling
Always check if the extension and API are available:Image Data URIs
Ensure images are properly encoded:Task State Management
Keep track of active tasks to avoid conflicts:Troubleshooting
Extension Not Found
API Not Available
Task Not Responding
IfsendMessage() doesn’t work, ensure a task is active:
Next Steps
CLI Usage
Use Cline from the command line
Custom Experts
Create domain-specific experts