Context
Set user context and manage identity.
import Pillar from '@pillar-ai/sdk'
Methods
Pillar.setContext()
Set context for the assistant. Use this to tell Pillar what the user is doing for smarter, more relevant assistance.
setContext(ctx: Partial<Context>): void
Parameters
ctxExample
pillar.setContext({currentPage: '/settings/billing',currentFeature: 'Billing Settings',userRole: 'admin',});
Pillar.getChatContext()
Get the current chat context (conversation ID and messages). Useful for escalation to human support with conversation history.
getChatContext(): ChatContext | null
Returns
ChatContext | nullExample
// Get chat context for escalationconst context = pillar.getChatContext();if (context) {const summary = context.messages.map(m => `${m.role}: ${m.content.slice(0, 100)}`).join('\n');showIntercom(`Escalating from AI assistant:\n${summary}`);}
Pillar.identify()
Identify the current user after login. Call this when a user logs into your application to: - Link their anonymous conversation history to their account - Enable cross-device conversation history retrieval - Associate future conversations with their user ID
identify(userId: string, profile?: {name?: string;email?: string;metadata?: Record<string, unknown>;}, options?: { preserveConversation?: boolean }): Promise<void>
Parameters
userIdprofileoptionsReturns
Promise<void>Example
// When user logs inawait pillar.identify('user-123', {name: 'John Doe',email: 'john@example.com',});// Keep current conversation when identifyingawait pillar.identify('user-123', undefined, { preserveConversation: true });
Pillar.logout()
Clear the user's identity (logout). Call this when a user logs out of your application. Future conversations will be tracked anonymously until identify() is called again. Note: This does not delete existing conversations - they remain associated with the user's account for future retrieval.
logout(options?: { preserveConversation?: boolean }): void
Parameters
optionsExample
// When user logs outpillar.logout();// Keep current conversation when logging outpillar.logout({ preserveConversation: true });
Types
Context
interfaceContext for the assistant. Pass this to help the assistant understand what the user is doing.
interface Context {/** Current page path (e.g., "/settings/billing") */currentPage?: string;/** Current feature or section (e.g., "Billing Settings") */currentFeature?: string;/** User's role in the product (e.g., "admin", "member") */userRole?: string;/** Current user state or mode (e.g., "onboarding", "trial") */userState?: string;/** Any error state the user is experiencing */errorState?: {code: string;message: string;};/** Custom context data */custom?: Record<string, unknown>;}
Properties
currentPagecurrentFeatureuserRoleuserStateerrorStatecustomUserProfile
interfaceUser profile for personalization.
interface UserProfile {/** User identifier (for conversation continuity) */userId?: string;/** User's name for personalized responses */name?: string;/** User's role/permissions */role?: string;/** Account/organization info */accountType?: string;/** User's experience level */experienceLevel?: 'beginner' | 'intermediate' | 'advanced';}
Properties
userIdnameroleaccountTypeexperienceLevelSuggestion
interfaceSuggestion returned from the suggestions API.
interface Suggestion {type: 'article' | 'video' | 'tutorial' | 'action';id: string;title: string;description: string;relevanceScore: number;url?: string;}
Properties
typeidtitledescriptionrelevanceScoreurl