React API Reference
Complete API reference for the @pillar-ai/react package.
PillarProvider
The root component that initializes and configures the Pillar SDK.
Props
| Prop | Type | Required | Description |
|---|---|---|---|
productKey | string | Yes | Your product key from app.trypillar.com |
publicKey | string | Yes | Your public API key |
config | PillarConfig | No | SDK configuration options |
onTask | (task: Task) => void | No | Handler for task execution |
cards | Record<string, CardComponent> | No | Custom card components |
Example
examples/reference/react/pillar-provider-example.tsx
import { PillarProvider } from '@pillar-ai/react';<PillarProviderproductKey="your-product-key"publicKey="pk_live_xxx"config={{panel: { position: 'right', mode: 'push', width: 400 },theme: { mode: 'auto', colors: { primary: '#2563eb' } },}}onTask={(task) => { /* handle tasks */ }}cards={{ invite_members: InviteMembersCard }}>{children} {/* Your app content */}</PillarProvider>
usePillar
The main hook for accessing SDK state and methods.
Return Value
| Property | Type | Description |
|---|---|---|
pillar | PillarInstance | null | The SDK instance |
isReady | boolean | Whether SDK is initialized |
isPanelOpen | boolean | Panel open state |
open | (options?) => void | Open the panel |
close | () => void | Close the panel |
toggle | () => void | Toggle the panel |
navigate | (view: string) => void | Navigate to a view |
setTheme | (theme: ThemeUpdate) => void | Update theme at runtime |
on | (event, callback) => () => void | Subscribe to events |
onTask | (name, handler) => () => void | Register task handler |
activePlan | ExecutionPlan | null | Current active plan |
Example
examples/reference/react/use-pillar-example.tsx
import { usePillar } from '@pillar-ai/react';function MyComponent() {const {pillar, // SDK instanceisReady, // Whether SDK is initializedisPanelOpen, // Panel open stateopen, // Open the panelclose, // Close the paneltoggle, // Toggle the panelnavigate, // Navigate to a viewsetTheme, // Update theme at runtimeon, // Subscribe to eventsonTask, // Register task handleractivePlan, // Current active plan} = usePillar();if (!isReady) {return <div>Loading...</div>;}return (<button onClick={() => open()}>Get Help</button>);}
Open Options
examples/reference/react/open-options.tsx
// Open to home viewopen();// Open to a specific articleopen({ article: 'getting-started' });// Open with a search queryopen({ search: 'billing' });// Open and focus the inputopen({ focusInput: true });// Open to the chat viewopen({ view: 'chat' });
Type-Safe Task Handlers
examples/reference/react/type-safe-task-handlers.tsx
import { usePillar } from '@pillar-ai/react';import type { actions } from '@/lib/pillar/actions';function TaskHandlers() {const { onTask } = usePillar<typeof actions>();useEffect(() => {// TypeScript knows the exact data shape for each actionconst unsub = onTask('add_source', (data) => {console.log(data.url); // Typed as stringreturn { success: true };});return unsub;}, [onTask]);return null;}
useHelpPanel
Focused hook for panel controls only.
Return Value
| Property | Type | Description |
|---|---|---|
isOpen | boolean | Panel open state |
open | (options?) => void | Open the panel |
close | () => void | Close the panel |
toggle | () => void | Toggle the panel |
openArticle | (slug: string) => void | Open a specific article |
openCategory | (slug: string) => void | Open a category view |
openSearch | (query?: string) => void | Open search |
openChat | () => void | Open the co-pilot chat view |
Example
examples/reference/react/use-help-panel-example.tsx
import { useHelpPanel } from '@pillar-ai/react';function HelpButton() {const {isOpen,open,close,toggle,openArticle,openCategory,openSearch,openChat,} = useHelpPanel();return (<div><button onClick={toggle}>{isOpen ? 'Close' : 'Help'}</button><button onClick={() => openArticle('getting-started')}>Getting Started</button><button onClick={openChat}>Ask co-pilot</button></div>);}
PillarPanel
Component for manual panel placement. Use when you want to control exactly where the panel renders.
Props
| Prop | Type | Description |
|---|---|---|
className | string | CSS class for the panel container |
style | CSSProperties | Inline styles |
Example
examples/reference/react/pillar-panel-example.tsx
import { PillarProvider, PillarPanel } from '@pillar-ai/react';function App() {return (<PillarProviderproductKey="your-product-key"publicKey="pk_live_xxx"config={{panel: { enabled: false }, // Disable auto-rendering}}><div className="app-layout"><main>Your app content</main>{/* Render panel in a custom location */}<aside className="help-sidebar"><PillarPanel className="custom-panel" /></aside></div></PillarProvider>);}
CardComponentProps
Type definition for custom card components.
examples/reference/react/card-component-props.ts
interface CardComponentProps<T = Record<string, unknown>> {/** Data extracted by the AI */data: T;/** Call when user confirms the action */onConfirm: (modifiedData?: Record<string, unknown>) => void;/** Call when user cancels */onCancel: () => void;/** Report state changes */onStateChange?: (state: 'loading' | 'success' | 'error', message?: string) => void;}
Example
examples/reference/react/card-component-props-example.tsx
import type { CardComponentProps } from '@pillar-ai/react';interface InviteData {emails: string[];role: 'admin' | 'member';}export function InviteMembersCard({ data, onConfirm, onCancel }: CardComponentProps<InviteData>) {return (<div><p>Invite {data.emails.length} members as {data.role}</p><button onClick={onCancel}>Cancel</button><button onClick={() => onConfirm(data)}>Confirm</button></div>);}
Types
PillarConfig
examples/reference/react/pillar-config.ts
interface PillarConfig {/** Panel configuration */panel?: {enabled?: boolean;position?: 'left' | 'right';mode?: 'overlay' | 'push';width?: number;container?: string | HTMLElement;};/** Edge trigger configuration */edgeTrigger?: {enabled?: boolean;position?: 'left' | 'right';label?: string;};/** Text selection popover */textSelection?: {enabled?: boolean;label?: string;};/** Theme configuration */theme?: ThemeConfig;/** Custom CSS to inject */customCSS?: string;}
ThemeColors
examples/reference/react/theme-colors.ts
interface ThemeColors {/** Brand color for buttons, links, accents */primary?: string;/** Hover state for primary color */primaryHover?: string;/** Main background color */background?: string;/** Secondary background (cards, inputs) */backgroundSecondary?: string;/** Primary text color */text?: string;/** Secondary/muted text color */textMuted?: string;/** Border color */border?: string;/** Subtle border color */borderLight?: string;}
Task
examples/reference/react/task.ts
interface Task {/** Unique identifier for this task execution */id: string;/** The action name that triggered this task */name: string;/** Data extracted by the AI, matching the action's dataSchema */data: Record<string, unknown>;/** Complete the task and report the result */complete: (result: TaskResult) => void;}interface TaskResult {/** Whether the task completed successfully */success: boolean;/** Optional message to display to the user */message?: string;}