TypeScript SDK
Install and use the Refrase npm package to optimize prompts from your TypeScript and JavaScript applications.
Installation
Quick Start
API Reference
AdaptOptions Interface
interface AdaptOptions {
/** The system prompt to optimize */
prompt: string;
/** Target model identifier */
model: string;
/** Optional task type for context-aware optimization */
task?: TaskType;
/** Optional example user message for calibration */
userPrompt?: string;
}AdaptResult Interface
interface AdaptResult {
/** The optimized prompt */
adapted: string;
/** The original prompt, unchanged */
original: string;
/** List of changes made during adaptation */
changes: Change[];
/** Target model information */
model: ModelInfo;
/** Metadata about the adaptation */
metadata: {
duration_ms: number;
rules_applied: number;
task: TaskType | null;
};
}Change Interface
interface Change {
/** Type of change: "add" | "remove" | "modify" | "reorder" */
type: string;
/** Human-readable explanation */
description: string;
/** Original text (empty for additions) */
before: string;
/** Modified text (empty for removals) */
after: string;
/** Why this change improves the prompt */
reason: string;
}TaskType
type TaskType = | "chat" | "code" | "analysis" | "creative" | "extraction" | "summarization";
Listing Models
import { listModels } from "refrase";
const models = await listModels();
// Returns: ModelInfo[]
interface ModelInfo {
id: string;
name: string;
provider: string;
capabilities: string[];
}