API Reference
> Auto-generated from TypeScript source files
Overview
API Reference
Auto-generated from TypeScript source files
Table of Contents
- variables/index
- similarity/index
- quality/index
- parser/index
- builder/index
- builder/chat
- builder/media
- builder/video
- builder/audio
variables/index
Variable Detection Utility Detects common variable-like patterns in text that could be converted to our supported format: ${variableName} or ${variableName:default}
Types
VariablePattern
type VariablePattern = | "double_bracket" // [[name]] or [[ name ]]
| "double_curly" // {{name}} or {{ name }}
| "single_bracket" // [NAME] or [name]
| "single_curly" // {NAME} or {name}
| "angle_bracket" // or <name>
| "percent" // %NAME% or %name%
| "dollar_curly"
Interfaces
DetectedVariable
Variable Detection Utility Detects common variable-like patterns in text that could be converted to our supported format: ${variableName} or ${variableName:default}
| Property | Type | Description |
|---|---|---|
original | string | - |
name | string | - |
defaultValue | string | - |
pattern | VariablePattern | - |
startIndex | number | - |
endIndex | number | - |
Functions
detectVariables()
Detect variable-like patterns in text Returns detected variables that are NOT in our supported format
detectVariables(text: string): DetectedVariable[]
Parameters:
text:string
Returns: DetectedVariable[]
convertToSupportedFormat()
Convert a detected variable to our supported format
convertToSupportedFormat(variable: DetectedVariable): string
Parameters:
variable:DetectedVariable
Returns: string
convertAllVariables()
Convert all detected variables in text to our supported format
convertAllVariables(text: string): string
Parameters:
text:string
Returns: string
getPatternDescription()
Get a human-readable pattern description
getPatternDescription(pattern: VariablePattern): string
Parameters:
pattern:VariablePattern
Returns: string
extractVariables()
Extract variables from our supported ${var} or ${var:default} format
extractVariables(text: string): Array<{ name: string; defaultValue?: string }>
Parameters:
text:string
Returns: Array<{ name: string; defaultValue?: string }>
compile()
Compile a prompt template with variable values
compile(template: string, values: Record<string, string>, options?: { useDefaults?: boolean }): string
Parameters:
template:stringvalues:Record<string, string>options:{ useDefaults?: boolean }(optional) ={}
Returns: string
Constants
normalize
Alias for convertAllVariables - normalizes all variable formats to ${var}
normalize = convertAllVariables
detect
Alias for detectVariables
detect = detectVariables
similarity/index
Content similarity utilities for duplicate detection
Functions
normalizeContent()
Content similarity utilities for duplicate detection
normalizeContent(content: string): string
Parameters:
content:string
Returns: string
calculateSimilarity()
Combined similarity score using multiple algorithms Returns a value between 0 (completely different) and 1 (identical)
calculateSimilarity(content1: string, content2: string): number
Parameters:
content1:stringcontent2:string
Returns: number
isSimilarContent()
Check if two contents are similar enough to be considered duplicates Default threshold is 0.85 (85% similar)
isSimilarContent(content1: string, content2: string, threshold?: number): boolean
Parameters:
content1:stringcontent2:stringthreshold:number(optional) =0.85
Returns: boolean
getContentFingerprint()
Get normalized content hash for database indexing/comparison This is a simple hash for quick lookups before full similarity check
getContentFingerprint(content: string): string
Parameters:
content:string
Returns: string
findDuplicates()
Find duplicates in an array of prompts Returns groups of similar prompts
findDuplicates(prompts: T[], threshold?: number): T[][]
Parameters:
prompts:T[]threshold:number(optional) =0.85
Returns: T[][]
deduplicate()
Deduplicate an array of prompts, keeping the first occurrence
deduplicate(prompts: T[], threshold?: number): T[]
Parameters:
prompts:T[]threshold:number(optional) =0.85
Returns: T[]
Constants
calculate
Alias for calculateSimilarity
calculate = calculateSimilarity
isDuplicate
Alias for isSimilarContent
isDuplicate = isSimilarContent
quality/index
Prompt Quality Checker - Local validation for prompt quality
@example
const result = quality.check("Act as a developer...");
console.log(result.score); // 0.85
console.log(result.issues); // []
Interfaces
QualityIssue
Prompt Quality Checker - Local validation for prompt quality
| Property | Type | Description |
|---|---|---|
type | `'error' | 'warning' |
code | string | - |
message | string | - |
position | { start: number; end: number } | - |
QualityResult
| Property | Type | Description |
|---|---|---|
valid | boolean | - |
score | number | - |
issues | QualityIssue[] | - |
stats | unknown | - |
Functions
check()
Check prompt quality locally (no API needed)
check(prompt: string): QualityResult
Parameters:
prompt:string
Returns: QualityResult
validate()
Validate a prompt and throw if invalid
validate(prompt: string): void
Parameters:
prompt:string
isValid()
Check if a prompt is valid
isValid(prompt: string): boolean
Parameters:
prompt:string
Returns: boolean
getSuggestions()
Get suggestions for improving a prompt
getSuggestions(prompt: string): string[]
Parameters:
prompt:string
Returns: string[]
parser/index
Prompt Parser - Parse and load prompt files in various formats
Supports:
- .prompt.yml / .prompt.yaml (YAML format)
- .prompt.json (JSON format)
- .prompt.md (Markdown with frontmatter)
- .txt (Plain text)
@example
const prompt = parser.parse(`
name: Code Review
messages:
- role: system
content: You are a code reviewer.
`);
Interfaces
PromptMessage
Prompt Parser - Parse and load prompt files in various formats
Supports:
- .prompt.yml / .prompt.yaml (YAML format)
- .prompt.json (JSON format)
- .prompt.md (Markdown with frontmatter)
- .txt (Plain text)
| Property | Type | Description |
|---|---|---|
role | `'system' | 'user' |
content | string | - |
ParsedPrompt
| Property | Type | Description |
|---|---|---|
name | string | - |
description | string | - |
model | string | - |
modelParameters | unknown | - |
messages | PromptMessage[] | - |
variables | unknown | - |
metadata | Record<string, unknown> | - |
Functions
parse()
Parse prompt content in various formats
parse(content: string, format?: 'yaml' | 'json' | 'markdown' | 'text'): ParsedPrompt
Parameters:
content:stringformat:'yaml' | 'json' | 'markdown' | 'text'(optional)
Returns: ParsedPrompt
toYaml()
Serialize a ParsedPrompt to YAML format
toYaml(prompt: ParsedPrompt): string
Parameters:
prompt:ParsedPrompt
Returns: string
toJson()
Serialize a ParsedPrompt to JSON format
toJson(prompt: ParsedPrompt, pretty?: boolean): string
Parameters:
prompt:ParsedPromptpretty:boolean(optional) =true
Returns: string
getSystemPrompt()
Get the system message content from a parsed prompt
getSystemPrompt(prompt: ParsedPrompt): string
Parameters:
prompt:ParsedPrompt
Returns: string
interpolate()
Interpolate variables in a prompt
interpolate(prompt: ParsedPrompt, values: Record<string, string>): ParsedPrompt
Parameters:
prompt:ParsedPromptvalues:Record<string, string>
Returns: ParsedPrompt
builder/index
Prompt Builder - A fluent DSL for creating structured prompts
@example
const prompt = builder()
.role("Senior TypeScript Developer")
.context("You are helping review code")
.task("Analyze the following code for bugs")
.constraints(["Be concise", "Focus on critical issues"])
.output("JSON with { bugs: [], suggestions: [] }")
.variable("code", { required: true })
.build();
Interfaces
PromptVariable
Prompt Builder - A fluent DSL for creating structured prompts
| Property | Type | Description |
|---|---|---|
name | string | - |
description | string | - |
required | boolean | - |
defaultValue | string | - |
BuiltPrompt
| Property | Type | Description |
|---|---|---|
content | string | - |
variables | PromptVariable[] | - |
metadata | unknown | - |
Classes
PromptBuilder
Methods:
| Method | Description |
|---|---|
role(role: string): this | Set the role/persona for the AI |
persona(persona: string): this | Alias for role() |
context(context: string): this | Set the context/background information |
background(background: string): this | Alias for context() |
task(task: string): this | Set the main task/instruction |
instruction(instruction: string): this | Alias for task() |
constraints(constraints: string[]): this | Add constraints/rules the AI should follow |
constraint(constraint: string): this | Add a single constraint |
rules(rules: string[]): this | Alias for constraints() |
output(format: string): this | Set the expected output format |
format(format: string): this | Alias for output() |
example(input: string, output: string): this | Add an example input/output pair |
examples(examples: Array<{ input: string; output: string }>): this | Add multiple examples |
variable(name: string, options?: { description?: string; required?: boolean; defaultValue?: string }): this | Define a variable placeholder |
section(title: string, content: string): this | Add a custom section |
raw(content: string): this | Set raw content (bypasses structured building) |
build(): BuiltPrompt | Build the final prompt |
toString(): string | Build and return only the content string |
role()
Set the role/persona for the AI
role(role: string): this
Parameters:
role:string
Returns: this
persona()
Alias for role()
persona(persona: string): this
Parameters:
persona:string
Returns: this
context()
Set the context/background information
context(context: string): this
Parameters:
context:string
Returns: this
background()
Alias for context()
background(background: string): this
Parameters:
background:string
Returns: this
task()
Set the main task/instruction
task(task: string): this
Parameters:
task:string
Returns: this
instruction()
Alias for task()
instruction(instruction: string): this
Parameters:
instruction:string
Returns: this
constraints()
Add constraints/rules the AI should follow
constraints(constraints: string[]): this
Parameters:
constraints:string[]
Returns: this
constraint()
Add a single constraint
constraint(constraint: string): this
Parameters:
constraint:string
Returns: this
rules()
Alias for constraints()
rules(rules: string[]): this
Parameters:
rules:string[]
Returns: this
output()
Set the expected output format
output(format: string): this
Parameters:
format:string
Returns: this
format()
Alias for output()
format(format: string): this
Parameters:
format:string
Returns: this
example()
Add an example input/output pair
example(input: string, output: string): this
Parameters:
input:stringoutput:string
Returns: this
examples()
Add multiple examples
examples(examples: Array<{ input: string; output: string }>): this
Parameters:
examples:Array<{ input: string; output: string }>
Returns: this
variable()
Define a variable placeholder
variable(name: string, options?: { description?: string; required?: boolean