API Reference
Complete API documentation for PACE.js.
PACE Class
The main orchestrator class.
Constructor
new PACE(config)Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
config | PACEConfig | Yes | Configuration object |
PACEConfig
interface PACEConfig {
// Required
container: string | HTMLElement // DOM selector or element
products: string | Product[] | ProductConfig // Path, array, or object
// AI Configuration
aiAdapter?: 'claude' | 'openai' | AIAdapter
apiKey?: string
model?: string
// UI Configuration
greeting?: string
defaultView?: 'product' | 'about' | 'chat' | 'summary'
enableExecutiveSummary?: boolean
// Theme
theme?: string | ThemeConfig
primaryColor?: string
accentColor?: string
// Advanced
plugins?: Plugin[]
customComponents?: ComponentMap
stateInitializer?: () => object
}Methods
mount()
pace.mount(): voidMount PACE to the DOM. Call after creating instance.
Example:
const pace = new PACE({ container: '#app', products: './products.json' })
pace.mount()use()
pace.use(plugin: Plugin): PACEAdd a plugin. Returns this for chaining.
Example:
pace
.use(analyticsPlugin)
.use(i18nPlugin)
.mount()on()
pace.on(event: string, callback: Function): voidListen to events.
Example:
pace.on('ready', () => {
console.log('PACE initialized')
})emit()
pace.emit(event: string, payload?: any): voidEmit custom events.
Example:
pace.emit('custom:event', { data: 'value' })navigate()
pace.navigate(view: string, params?: object): voidNavigate to a view programmatically.
Example:
pace.navigate('product')
pace.navigate('product', { id: 'sql-mcp' })destroy()
pace.destroy(): voidClean up and remove PACE from DOM.
Example:
pace.destroy()State Class
Reactive state management.
Constructor
new State(initialState?)Parameters
| Parameter | Type | Description |
|---|---|---|
initialState | object | Initial state values |
Methods
get()
state.get(key: string): anyRetrieve a value from state.
Example:
const view = state.get('activeView')set()
state.set(key: string, value: any): voidUpdate state and notify subscribers.
Example:
state.set('activeView', 'chat')subscribe()
state.subscribe(key: string, callback: Function): FunctionListen to state changes. Returns unsubscribe function.
Example:
const unsubscribe = state.subscribe('activeView', (newValue, oldValue) => {
console.log(`View changed: ${oldValue} → ${newValue}`)
})
// Later...
unsubscribe()getAll()
state.getAll(): objectGet all state values.
Example:
const allState = state.getAll()
console.log(allState)Router Class
Hash-based routing.
Constructor
new Router(state)Parameters
| Parameter | Type | Description |
|---|---|---|
state | State | State instance |
Methods
init()
router.init(): voidInitialize router and start listening to hash changes.
navigate()
router.navigate(route: string, params?: object): voidNavigate to a route.
Example:
router.navigate('product')
router.navigate('product', { id: 'sql-mcp' })on()
router.on(event: string, callback: Function): voidListen to router events.
Example:
router.on('navigate', (route, params) => {
console.log('Navigated to:', route, params)
})ProductCatalog Class
Product display component.
Constructor
new ProductCatalog(products, state)Methods
render()
render(): stringGenerate HTML for the catalog.
search()
search(query: string): Product[]Filter products by search query.
filterByCategory()
filterByCategory(category: string): Product[]Filter products by category.
attachEvents()
attachEvents(): voidAttach DOM event listeners.
AboutPage Class
About page component.
Constructor
new AboutPage(config, state)Methods
render()
render(): stringGenerate HTML for the about page.
ChatWidget Class
Chat interface component.
Constructor
new ChatWidget(config, state)Methods
render()
render(): stringGenerate HTML for chat widget.
sendMessage()
sendMessage(message: string): Promise<void>Send a message to the AI.
Example:
await chat.sendMessage('Tell me about SQL MCP')clearHistory()
clearHistory(): voidClear chat history.
ExecutiveSummary Class
Executive summary component.
Constructor
new ExecutiveSummary(config, state)Methods
render()
render(): stringGenerate HTML for executive summary.
update()
update(data: SummaryData): voidUpdate summary data.
trackProduct()
trackProduct(product: Product): voidAdd a product to discussed list.
AI Adapters
ClaudeAdapter
import { ClaudeAdapter } from '@semanticintent/pace-pattern'
const adapter = new ClaudeAdapter({
apiKey: 'sk-...',
model: 'claude-3-sonnet-20240229'
})Configuration
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | Required | Anthropic API key |
model | string | 'claude-3-sonnet-20240229' | Model to use |
maxTokens | number | 1024 | Max response tokens |
temperature | number | 1.0 | Sampling temperature |
Methods
sendMessage()
async sendMessage(message: string, context?: object): Promise<Response>Send a message to Claude.
Returns:
{
response: string,
metadata: {
expertise?: 'beginner' | 'intermediate' | 'advanced',
products?: string[],
intent?: string
}
}OpenAIAdapter
import { OpenAIAdapter } from '@semanticintent/pace-pattern'
const adapter = new OpenAIAdapter({
apiKey: 'sk-...',
model: 'gpt-4'
})Configuration
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | Required | OpenAI API key |
model | string | 'gpt-4' | Model to use |
maxTokens | number | 1024 | Max response tokens |
temperature | number | 0.7 | Sampling temperature |
Custom Adapter
Implement the AIAdapter interface:
interface AIAdapter {
sendMessage(message: string, context?: object): Promise<{
response: string,
metadata?: object
}>
}Example:
class MyAdapter {
async sendMessage(message, context) {
const response = await fetch('/api/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message, context })
})
const data = await response.json()
return {
response: data.reply,
metadata: {
expertise: data.expertise,
products: data.products
}
}
}
}
const pace = new PACE({
aiAdapter: new MyAdapter()
})Plugin System
Plugin Interface
interface Plugin {
name: string
version?: string
install(pace: PACE): void
}Example Plugin
const analyticsPlugin = {
name: 'analytics',
version: '1.0.0',
install(pace) {
pace.on('product:select', ({ product }) => {
gtag('event', 'product_view', {
product_id: product.id,
product_name: product.name
})
})
pace.on('chat:message', ({ message }) => {
gtag('event', 'chat_message', {
message_length: message.length
})
})
}
}
pace.use(analyticsPlugin)Events
Core Events
| Event | Payload | Description |
|---|---|---|
ready | { version: string } | PACE initialized |
navigate | { view: string, params: object } | Route changed |
state:change | { key: string, value: any } | State updated |
error | { error: Error } | Error occurred |
Product Events
| Event | Payload | Description |
|---|---|---|
product:select | { product: Product } | Product clicked |
product:search | { query: string, results: Product[] } | Search performed |
product:filter | { category: string } | Category filtered |
Chat Events
| Event | Payload | Description |
|---|---|---|
chat:message | { message: string, role: 'user' } | User sent message |
chat:response | { message: string, role: 'assistant', metadata: object } | AI responded |
chat:error | { error: Error } | Chat error |
chat:typing | { isTyping: boolean } | Typing indicator |
Summary Events
| Event | Payload | Description |
|---|---|---|
summary:update | { data: SummaryData } | Summary updated |
summary:product-tracked | { product: Product } | Product tracked |
summary:expertise-changed | { level: string } | Expertise changed |
TypeScript Definitions
Product
interface Product {
id: string
name: string
tagline: string
category: string
description: string
action_label?: string
action_url?: string
icon?: string
metadata?: Record<string, any>
}Message
interface Message {
role: 'user' | 'assistant'
content: string
timestamp: number
metadata?: {
expertise?: 'beginner' | 'intermediate' | 'advanced'
products?: string[]
intent?: string
}
}SummaryData
interface SummaryData {
conversationSummary: string
productsDiscussed: Array<{
id: string
name: string
status: 'interested' | 'viewed' | 'deferred'
}>
userExpertise: 'beginner' | 'intermediate' | 'advanced'
detectedInterests: string[]
suggestedNextSteps: string[]
metrics?: {
messagesExchanged: number
productsViewed: number
timeSpent: number
}
}CSS Classes
PACE.js uses these CSS classes for styling:
Layout
.pace-container— Main container.pace-sidebar— Left sidebar.pace-main— Main content area
Navigation
.pace-nav— Navigation container.pace-nav-item— Navigation item.pace-nav-item.active— Active nav item
Product Catalog
.pace-product-catalog— Catalog container.pace-product-grid— Product grid.pace-product-card— Individual product card.pace-category-section— Category section.pace-search-input— Search input
Chat
.pace-chat-widget— Chat container.pace-chat-messages— Messages container.pace-chat-message— Individual message.pace-chat-message.user— User message.pace-chat-message.assistant— AI message.pace-chat-input— Input field
Executive Summary
.pace-executive-summary— Summary container.pace-summary-section— Summary section.pace-summary-products— Products list.pace-summary-metric— Metric display
CSS Variables
Customize appearance with CSS custom properties:
:root {
--pace-primary: #667eea;
--pace-accent: #764ba2;
--pace-bg: #ffffff;
--pace-bg-soft: #f9f9f9;
--pace-text: #1a1a1a;
--pace-text-secondary: #666666;
--pace-border: #e0e0e0;
--pace-font: Inter, system-ui, sans-serif;
--pace-radius: 8px;
--pace-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}Error Handling
PACE.js throws these errors:
ConfigurationError
try {
new PACE({ /* missing container */ })
} catch (error) {
if (error instanceof ConfigurationError) {
console.error('Invalid configuration:', error.message)
}
}AIAdapterError
pace.on('chat:error', ({ error }) => {
if (error instanceof AIAdapterError) {
console.error('AI error:', error.message)
// Show user-friendly message
}
})RouterError
pace.on('error', ({ error }) => {
if (error instanceof RouterError) {
console.error('Routing error:', error.message)
}
})Version
import { PACE } from '@semanticintent/pace-pattern'
console.log(PACE.version) // "1.0.1"See Also
- Core Concepts — Architecture deep dive
- Components — Component API
- Build Your First App — Hands-on tutorial
Complete API reference for PACE.js. 📚