API Reference
Complete reference of every public function, class, and type exported by aixa.js. This page covers the core SDK — see E-Commerce Plugin for the @aixa/plugin-ecommerce package.
AIXA Class
The main entry point. Create an instance to configure and control the AIXA runtime.
Constructor
new AIXA(config: AIXAConfig)
Creates a new AIXA instance with the provided configuration. See AIXAConfig for all options.
import { AIXA } from '@aixa/sdk';
const aixa = new AIXA({
siteId: 'my-store',
inference: { autoDetect: true },
});
Methods
| Method | Signature | Description |
|---|---|---|
start() |
start(): Promise<void> |
Initializes the AIXA runtime: runs auto-inference (if enabled), sets up event listeners, and broadcasts capabilities. Call once after construction. |
stop() |
stop(): void |
Shuts down the AIXA runtime: removes event listeners, clears registrations, and stops broadcasting. |
refreshTools() |
refreshTools(): Promise<InferenceResult> |
Re-runs the auto-inference engine to pick up DOM changes. Useful after dynamic content loads (SPA navigation, AJAX updates). Returns updated inference results. |
getCapabilities() |
getCapabilities(): AgentCapability |
Returns a snapshot of all currently registered capabilities (inferred + manually registered tools). |
broadcastCapabilities() |
broadcastCapabilities(): void |
Dispatches an aixa:capabilities:response event with the current capabilities snapshot. Called automatically by start(), but can be invoked manually to re-announce after registration changes. |
Tool Registration
Register capabilities that agents can discover and invoke. All registration methods are chainable (they return the AIXA instance).
registerSearch()
registerSearch(config: {
endpoint: string;
parameters: ToolParameter[];
handler?: (params: Record<string, any>) => Promise<any>;
method?: 'GET' | 'POST';
}): AIXA
Registers a search endpoint. This is a convenience wrapper that creates a SEARCH-category tool with standard parameter handling. If no handler is provided, aixa.js will fetch() the endpoint with parameters serialized as query string (GET) or JSON body (POST).
| Property | Type | Required | Description |
|---|---|---|---|
endpoint |
string |
Yes | URL for the search API. Parameters are appended as query string for GET, sent as JSON body for POST. |
parameters |
ToolParameter[] |
Yes | Array of parameter definitions. See ToolParameter. |
handler |
function |
No | Custom handler function. Receives params object, must return results. Overrides the default fetch behavior. |
method |
'GET' | 'POST' |
No | HTTP method for the default fetch handler. Default: 'GET'. |
aixa.registerSearch({
endpoint: '/api/products/search',
parameters: [
{ name: 'q', type: 'string', description: 'Search query', required: true },
{ name: 'category', type: 'string', description: 'Category filter' },
{ name: 'maxPrice', type: 'number', description: 'Maximum price' },
],
method: 'GET',
});
registerAction()
registerAction(config: {
name: string;
description: string;
parameters: ToolParameter[];
handler: (params: Record<string, any>) => Promise<any>;
requiresConfirmation?: boolean;
}): AIXA
Registers a named action with a required handler. Use this for custom logic beyond simple fetch — database queries, calculations, third-party API calls with auth, etc.
| Property | Type | Required | Description |
|---|---|---|---|
name |
string |
Yes | Unique name for the action. Used by agents to invoke it. |
description |
string |
Yes | Human-readable description. Shown to agents so they understand what the action does. |
parameters |
ToolParameter[] |
Yes | Array of parameter definitions. See ToolParameter. |
handler |
function |
Yes | Async function that executes the action. Receives params object, must return the result. |
requiresConfirmation |
boolean |
No | If true, the HITL modal prompts the user before execution. Default: false. |
aixa.registerAction({
name: 'get_article',
description: 'Fetch full article content by ID',
parameters: [
{ name: 'id', type: 'string', description: 'Article ID', required: true },
],
handler: async ({ id }) => {
const res = await fetch(`/api/articles/${id}`);
return res.json();
},
});
registerTool()
registerTool(config: {
name: string;
description: string;
parameters: ToolParameter[];
handler?: (params: Record<string, any>) => Promise<any>;
endpoint?: string;
method?: 'GET' | 'POST';
riskLevel?: RiskLevel;
category?: ActionCategory;
}): AIXA
The low-level registration method. registerSearch() and registerAction() are convenience wrappers around this. Use registerTool() when you need full control over all properties.
| Property | Type | Required | Description |
|---|---|---|---|
name |
string |
Yes | Unique tool name. |
description |
string |
Yes | Human-readable description. |
parameters |
ToolParameter[] |
Yes | Array of parameter definitions. |
handler |
function |
No | Custom handler. If omitted and endpoint is provided, uses default fetch. |
endpoint |
string |
No | URL for default fetch handler. |
method |
'GET' | 'POST' |
No | HTTP method for default fetch. Default: 'GET'. |
riskLevel |
RiskLevel |
No | Risk classification. See RiskLevel. Default: 'SAFE'. |
category |
ActionCategory |
No | Functional category. See ActionCategory. Default: 'CUSTOM'. |
unregisterTool()
unregisterTool(name: string): boolean
Removes a previously registered tool by name. Returns true if the tool was found and removed, false if no tool with that name was registered.
clearRegistry()
clearRegistry(): void
Removes all manually registered tools. Does not affect tools discovered via auto-inference (those will be re-inferred on next refreshTools() call).
getRegisteredTools()
getRegisteredTools(): ToolSchema[]
Returns an array of all currently registered tools (both manually registered and auto-inferred).
executeTool()
executeTool(name: string, params: Record<string, any>): Promise<any>
Programmatically executes a registered tool by name with the given parameters. Returns the tool's result. Use this for testing or for chaining tool calls.
const results = await aixa.executeTool('search_catalog', {
q: 'blue shirt',
maxPrice: 100,
});
Inference
inferTools()
inferTools(options?: {
rootSelector?: string;
tagAllowlist?: string[];
}): InferenceResult
Scans the DOM for interactive elements (forms, search inputs, filters, select dropdowns) and automatically generates tool schemas. This is the "zero-config" path — no registration code needed for standard UI patterns.
| Option | Type | Default | Description |
|---|---|---|---|
rootSelector |
string |
'body' |
CSS selector for the root element to scan. Limit the scope for performance on large pages. |
tagAllowlist |
string[] |
['form', 'input', 'select', 'button'] |
HTML tag names to scan. Narrow the list to only relevant elements. |
Returns: InferenceResult
{
tools: ToolSchema[]; // All inferred tools
total: number; // Total count
safe: number; // Count of SAFE tools
highRisk: number; // Count of HIGH_RISK tools
categories: Record<ActionCategory, number>; // Count by category
}
const result = aixa.inferTools({ rootSelector: '#search-section' });
console.log(`Found ${result.total} tools (${result.safe} safe, ${result.highRisk} high-risk)`);
UI Mirroring
mirrorElementValue()
mirrorElementValue(selector: string, value: string): boolean
Programmatically sets the value of a DOM element and dispatches appropriate events (input, change) so that framework bindings (React, Vue, etc.) detect the change. Returns true if the element was found and updated, false if no element matched the selector.
// Agent fills in a search field
aixa.mirrorElementValue('#search-input', 'blue shirt');
E-Commerce Plugin
ecommercePlugin()
ecommercePlugin(config: EcommercePluginConfig): { register(): void; unregister(): void }
Factory function for the e-commerce plugin. See the full E-Commerce Plugin documentation for details.
VERTICAL_TEMPLATES
const VERTICAL_TEMPLATES: {
ecommerce: Partial<EcommercePluginConfig>;
realEstate: Partial<EcommercePluginConfig>;
travel: Partial<EcommercePluginConfig>;
}
Pre-configured parameter sets for common verticals. Spread into your plugin config:
ecommercePlugin({
...VERTICAL_TEMPLATES.realEstate,
searchEndpoint: '/api/properties',
}).register();
Security
createHITLManager()
createHITLManager(options?: {
cssPrefix?: string;
hitlTimeout?: number;
}): {
listen(): void;
destroy(): void;
}
Creates a Human-in-the-Loop (HITL) manager that intercepts high-risk actions and presents a confirmation modal to the user.
| Option | Type | Default | Description |
|---|---|---|---|
cssPrefix |
string |
'aixa' |
CSS class prefix for modal elements. Customize to match your site's styling. |
hitlTimeout |
number |
30000 |
Timeout in milliseconds before auto-denying an unresponded confirmation. Set to 0 to disable timeout. |
Returns: An object with:
listen()— Starts listening for HITL events and shows the modal when needed.destroy()— Removes the modal from the DOM and stops listening.
const hitl = createHITLManager({ hitlTimeout: 15000 });
hitl.listen();
// Later, when cleaning up:
hitl.destroy();
sanitizePayload()
sanitizePayload(data: any): any
Returns a sanitized deep copy of the input, with prompt injection patterns neutralized. Use this before passing agent-provided data to sensitive operations.
const safeParams = sanitizePayload(agentProvidedParams);
// safeParams is a clean copy — original is untouched
Types
AIXAConfig
| Property | Type | Default | Description |
|---|---|---|---|
siteId |
string |
required | Unique identifier for your site. Used for capability announcements and agent routing. |
inference |
{ autoDetect?: boolean; rootSelector?: string; tagAllowlist?: string[] } |
{ autoDetect: true } |
Auto-inference configuration. Set autoDetect: false to disable automatic DOM scanning on start(). |
security |
{ sanitizeInput?: boolean; hitl?: HITLManagerOptions } |
{ sanitizeInput: true } |
Security configuration. sanitizeInput enables auto-sanitization. hitl passes options to the HITL manager. |
debug |
boolean |
false |
Enable verbose console logging for development. |
plugins |
AIXAPlugin[] |
[] |
Array of plugin instances to register on start(). |
ToolSchema
| Property | Type | Description |
|---|---|---|
name |
string |
Unique tool name. |
description |
string |
Human-readable description. |
parameters |
ToolParameter[] |
Array of parameter definitions. |
endpoint |
string | undefined |
Associated API endpoint, if any. |
method |
'GET' | 'POST' |
HTTP method for the endpoint. |
riskLevel |
RiskLevel |
Risk classification. |
category |
ActionCategory |
Functional category. |
requiresConfirmation |
boolean |
Whether the tool requires HITL confirmation. |
ToolParameter
| Property | Type | Required | Description |
|---|---|---|---|
name |
string |
Yes | Parameter name (used as key in params object). |
type |
'string' | 'number' | 'boolean' | 'enum' |
Yes | Expected JavaScript type. |
description |
string |
Yes | Description of what the parameter does. |
required |
boolean |
No | Whether the parameter is required. Default: false. |
enum |
string[] |
No | Allowed values when type is 'enum'. |
default |
any |
No | Default value if not provided. |
AgentCapability
| Property | Type | Description |
|---|---|---|
siteId |
string |
The site identifier from AIXAConfig. |
tools |
ToolSchema[] |
All registered and inferred tools. |
version |
string |
aixa.js SDK version. |
timestamp |
number |
Unix timestamp of when capabilities were computed. |
RiskLevel
enum RiskLevel {
SAFE = 'SAFE',
HIGH_RISK = 'HIGH_RISK',
}
| Value | Description |
|---|---|
SAFE |
Read-only operation. No confirmation needed. Always safe for agents to invoke. |
HIGH_RISK |
Mutation or sensitive operation. Triggers HITL confirmation modal before execution. |
ActionCategory
enum ActionCategory {
SEARCH = 'SEARCH',
FILTER = 'FILTER',
SORT = 'SORT',
FETCH = 'FETCH',
NAVIGATE = 'NAVIGATE',
MUTATE = 'MUTATE',
CUSTOM = 'CUSTOM',
}
| Value | Description |
|---|---|
SEARCH |
Full-text search operations. |
FILTER |
Faceted or parametric filtering. |
SORT |
Result ordering operations. |
FETCH |
Single-item retrieval by ID. |
NAVIGATE |
Page or section navigation. |
MUTATE |
Write operations (create, update, delete). |
CUSTOM |
Any other operation not covered above. |
AgentBridgeEvent
enum AgentBridgeEvent {
CAPABILITIES_REQUEST = 'aixa:capabilities:request',
CAPABILITIES_RESPONSE = 'aixa:capabilities:response',
TOOL_INVOKE = 'aixa:tool:invoke',
TOOL_RESULT = 'aixa:tool:result',
HITL_REQUEST = 'aixa:hitl:request',
HITL_RESPONSE = 'aixa:hitl:response',
}
HITLRequest
| Property | Type | Description |
|---|---|---|
id |
string |
Unique request identifier. |
tool |
ToolSchema |
The tool being invoked. |
params |
Record<string, any> |
The parameters the agent wants to pass. |
reason |
string |
Human-readable explanation of why this action needs confirmation. |
HITLResponse
| Property | Type | Description |
|---|---|---|
id |
string |
Matches the HITLRequest id. |
action |
HITLAction |
The user's decision. |
modifiedParams |
Record<string, any> | undefined |
If the user modified the parameters before approving. |
HITLAction
enum HITLAction {
APPROVE = 'approve',
DENY = 'deny',
MODIFY = 'modify',
}
| Value | Description |
|---|---|
approve |
User approved the action as-is. |
deny |
User denied the action entirely. |
modify |
User approved but with modified parameters. |
Events
All events are dispatched as CustomEvent on window. Use window.addEventListener() to listen.
| Event Name | Direction | Payload Type | Description |
|---|---|---|---|
aixa:capabilities:request |
Agent → Site | { siteId?: string } |
An agent is requesting the site's capabilities. The AIXA runtime responds automatically. |
aixa:capabilities:response |
Site → Agent | AgentCapability |
The site's capability listing. Automatically dispatched by broadcastCapabilities(). |
aixa:tool:invoke |
Agent → Site | { tool: string; params: Record<string, any> } |
An agent is invoking a tool. The AIXA runtime executes the handler automatically. |
aixa:tool:result |
Site → Agent | { tool: string; result: any; error?: string } |
The result (or error) of a tool invocation. |
aixa:hitl:request |
Agent → Site | HITLRequest |
A high-risk action needs user confirmation. The HITL manager shows the modal. |
aixa:hitl:response |
Site → Agent | HITLResponse |
The user's decision on a HITL request. |
// Listen for tool invocations
window.addEventListener('aixa:tool:invoke', (event) => {
const { tool, params } = event.detail;
console.log(`Tool invoked: ${tool}`, params);
});
// Listen for capabilities responses
window.addEventListener('aixa:capabilities:response', (event) => {
const capabilities = event.detail;
console.log(`Site has ${capabilities.tools.length} tools available`);
});