Complete API documentation for all classes, methods, and interfaces in the Persona SDK.
Core Classes
Persona
Main persona class representing an individual with attributes.
Constructor
new Persona(name: string, attributes: PersonaAttributes)
Creates a new persona with required attributes: age, occupation, sex.
Properties
readonly id: string // Unique identifierreadonly name: string // Persona namereadonly age: number // Age in yearsreadonly occupation: string // Job/occupationreadonly sex: Sex // 'male' | 'female' | 'other'readonly attributes: Record<string, any> // Custom attributes
Methods
toObject(): PersonaData // Serialize to plain objecttoJSON(): string // Serialize to JSON stringgetSummary(): string // Get human-readable summaryclone(newName?: string): Persona // Create a copysetAttribute(key: string, value: any): void // Update attributegetAttribute(key: string): any // Get attribute valuehasAttribute(key: string): boolean // Check if attribute exists
PersonaBuilder
Fluent API for constructing personas with method chaining.
Static Methods
PersonaBuilder.create(): PersonaBuilderPersonaBuilder.fromPrompt(prompt: string, options?: AIOptions): Promise<Persona>PersonaBuilder.generateMultiple(prompt: string, count: number, options?: AIOptions): Promise<Persona[]>
Builder Methods
withName(name: string | Distribution<string>): PersonaBuilderwithAge(age: number | Distribution<number>): PersonaBuilderwithOccupation(occupation: string | Distribution<string>): PersonaBuilderwithSex(sex: Sex): PersonaBuilderwithAttribute(key: string, value: any): PersonaBuilderwithAttributes(attributes: Record<string, any>): PersonaBuilderwithValidation(rules: ValidationRule[]): PersonaBuilder
Build Methods
build(): PersonabuildMany(count: number, namePrefix?: string): Persona[]buildWithCorrelations(config: CorrelationConfig): Persona
PersonaGroup
Collection manager for multiple personas with analysis capabilities.
Constructor
new PersonaGroup(name: string, personas?: Persona[])
Properties
readonly name: stringreadonly size: numberreadonly personas: Persona[]
Methods
add(persona: Persona): voidaddMany(personas: Persona[]): voidremove(id: string): booleanclear(): voidfind(predicate: (persona: Persona) => boolean): Persona | undefinedfilter(predicate: (persona: Persona) => boolean): Persona[]getStatistics(attribute: string): AttributeStatisticsgroupBy(attribute: string): Map<any, Persona[]>sample(count: number): Persona[]toArray(): Persona[]toObject(): GroupData
Distribution Classes
NormalDistribution
new NormalDistribution( mean: number, stdDev: number, seed?: number)
UniformDistribution
new UniformDistribution( min: number, max: number, seed?: number)
CategoricalDistribution
new CategoricalDistribution( categories: CategoryOption[], seed?: number)
ExponentialDistribution
new ExponentialDistribution( lambda: number, seed?: number)
Distribution Interface
All distributions implement the Distribution interface:
interface Distribution<T> { sample(): T; // Generate a random sample mean(): number; // Expected value variance(): number; // Variance toString(): string; // String representation}
Type Definitions
Core Types
type Sex = 'male' | 'female' | 'other';
interface PersonaAttributes { age: number; occupation: string; sex: Sex; [key: string]: any;}
interface PersonaData { id: string; name: string; attributes: PersonaAttributes;}
interface GroupData { name: string; size: number; personas: PersonaData[];}
Correlation Types
interface CorrelationConfig { attributes: Record<string, Distribution<any>>; correlations: Correlation[]; conditionals?: Conditional[];}
interface Correlation { attribute1: string; attribute2: string; correlation: number; type?: 'linear' | 'exponential' | 'logarithmic';}
interface Conditional { attribute: string; dependsOn: string; transform: (value: any, dependency: any) => any;}
AI Integration Types
interface AIOptions { apiKey: string; model?: string; temperature?: number; maxTokens?: number;}
interface StructuredOutputSchema { name: string; description: string; schema: any; // Zod schema}
📚 Additional Resources
- • GitHub Repository - Source code and examples
- • npm Package - Installation and version info
- • TypeScript Support: Full type definitions included
- • Node.js Compatibility: Requires Node.js 16+
- • Browser Support: Modern browsers with ES2020+ support