Core SDK API Reference
Complete API reference for the @pillar-ai/sdk package. Use this for vanilla JavaScript applications or direct SDK access.
Pillar.init()
Initialize the SDK. Returns a promise that resolves when ready.
Signature
Pillar.init(config: InitConfig): Promise<PillarInstance>
Parameters
| Property | Type | Required | Description |
|---|---|---|---|
productKey | string | Yes | Your product key from app.trypillar.com |
publicKey | string | Yes | Your public API key |
panel | PanelConfig | No | Panel configuration |
theme | ThemeConfig | No | Theme configuration |
textSelection | TextSelectionConfig | No | Text selection configuration |
customCSS | string | No | Custom CSS to inject |
Example
import { Pillar } from '@pillar-ai/sdk';const pillar = await Pillar.init({productKey: 'your-product-key',publicKey: 'pk_live_xxx',panel: { position: 'right', mode: 'push' },theme: { mode: 'auto', colors: { primary: '#2563eb' } },});
Panel Methods
Pillar.open()
Open the help panel.
Pillar.open(options?: OpenOptions): void
| Option | Type | Description |
|---|---|---|
article | string | Open to a specific article by slug |
search | string | Open with a search query |
focusInput | boolean | Focus the chat input |
Pillar.open(); // Open to homePillar.open({ article: 'getting-started' }); // Open articlePillar.open({ search: 'billing' }); // Open with search
Pillar.close()
Close the help panel.
Pillar.close(): void
Pillar.toggle()
Toggle the panel open/closed.
Pillar.toggle(): void
Context Methods
Pillar.setContext()
Set user context for smarter AI responses and action filtering.
Pillar.setContext(context: ContextData): void
| Property | Type | Description |
|---|---|---|
currentPage | string | Current URL path |
currentFeature | string | Human-readable feature name |
userRole | string | User's role for action filtering |
userState | string | User's current state |
errorState | { code: string, message: string } | Current error |
custom | Record<string, unknown> | Any additional data |
Pillar.setContext({currentPage: '/settings/billing',currentFeature: 'Billing Settings',userRole: 'admin',custom: { plan: 'pro' },});
Task Handling
Pillar.onTask()
Register a handler for when the AI suggests an action.
Pillar.onTask(actionName: string, handler: TaskHandler): () => void
Returns an unsubscribe function.
const unsubscribe = Pillar.onTask('navigate', (data) => {window.location.href = data.path;return { success: true };});// Later: unsubscribe();
TaskHandler Return Value
interface TaskResult {success: boolean;message?: string;}
Theme Methods
Pillar.setTheme()
Update the theme at runtime.
Pillar.setTheme(update: ThemeUpdate): void
// Change modePillar.setTheme({ mode: 'dark' });// Update colorsPillar.setTheme({ colors: { primary: '#10b981' } });// Update dark mode colorsPillar.setTheme({ darkColors: { primary: '#34d399' } });
Plan Methods
Pillar.startPlan()
Start an awaiting plan.
Pillar.startPlan(): Promise<void>
Pillar.completeAction()
Signal that an action has completed. For wizard actions (modals, multi-step flows), call this when the user finishes. If there's an active plan waiting on this action, it automatically advances to the next step.
Pillar.completeAction(actionName: string,success?: boolean,data?: Record<string, unknown>): Promise<void>
// When user completes a wizard triggered by an actionPillar.completeAction('add_source', true, { sourceId: '123' });
Pillar.skipPlanStep()
Skip a plan step.
Pillar.skipPlanStep(stepId: string): Promise<void>
Pillar.cancelPlan()
Cancel the current plan.
Pillar.cancelPlan(): Promise<void>
Event Methods
Pillar.on()
Subscribe to SDK events.
Pillar.on(event: string, callback: Function): () => void
Returns an unsubscribe function.
const unsubscribe = Pillar.on('panel:open', () => {console.log('Panel opened');});// Later: unsubscribe();
See Events Reference for all available events.
Card Registration
Pillar.registerCard()
Register a custom card renderer for vanilla JS.
Pillar.registerCard(cardType: string,renderer: CardRenderer): void
type CardRenderer = (container: HTMLElement,data: Record<string, unknown>,callbacks: { onConfirm: Function, onCancel: Function }) => () => void; // Returns cleanup function
Pillar.registerCard('invite_members', (container, data, callbacks) => {container.innerHTML = `<div><p>Invite ${data.emails.length} members</p><button id="cancel">Cancel</button><button id="confirm">Confirm</button></div>`;container.querySelector('#confirm').onclick = () => callbacks.onConfirm(data);container.querySelector('#cancel').onclick = callbacks.onCancel;return () => { container.innerHTML = ''; };});
Lifecycle
Pillar.destroy()
Destroy the SDK instance and clean up.
Pillar.destroy(): void
Use on logout or when the SDK is no longer needed:
function handleLogout() {Pillar.destroy();// Continue with logout...}
Properties
Pillar.activePlan
The currently active plan, if any.
Pillar.activePlan: ExecutionPlan | null
Pillar.isReady
Whether the SDK is initialized and ready.
Pillar.isReady: boolean
Pillar.isPanelOpen
Whether the panel is currently open.
Pillar.isPanelOpen: boolean