@pupt/lib
v1.7.2
Published
TypeScript library for creating AI prompts using JSX syntax
Downloads
701
Maintainers
Readme
pupt-lib
A TypeScript library for creating AI prompts as versionable, composable, shareable files using JSX syntax. Prompts are becoming critical software artifacts, yet most are written inline, copy-pasted between projects, and lost when chat sessions end. pupt-lib treats prompts as first-class code: version controlled in git, composable from reusable components, and shareable via npm. Simple prompts look like HTML and are accessible to non-developers, while complex prompts have full TypeScript power including loops, conditionals, and type safety.
Read the full documentation — guides, component reference, API docs, and more.
Installation
npm install pupt-libFor build-time JSX transformation (recommended for production), also install the peer dependencies:
npm install --save-dev @babel/core @babel/plugin-transform-react-jsx @babel/preset-typescriptQuick Start
The simplest way to write a prompt is a .prompt file — no imports or exports needed:
<!-- greeting.prompt -->
<Prompt name="greeting" description="A friendly greeting prompt">
<Role>You are a friendly assistant.</Role>
<Task>
Greet the user named <Ask.Text name="userName" label="User's name" /> warmly.
</Task>
<Constraint type="must">Keep the greeting under 50 words.</Constraint>
</Prompt>Load and render it:
import { createPromptFromSource, render } from 'pupt-lib';
import { readFile } from 'fs/promises';
const source = await readFile('./greeting.prompt', 'utf-8');
const element = await createPromptFromSource(source, 'greeting.prompt');
const result = await render(element, {
inputs: { userName: 'Alice' },
});
console.log(result.text);You can also write prompts as .tsx files for full TypeScript type safety — see the Getting Started guide for details.
Features
- JSX Syntax — Write prompts using familiar JSX/TSX syntax with 50+ built-in components
.promptFiles — Simplified format with no imports, no exports — just JSX- Composable — Build complex prompts from reusable, shareable components
- Provider Targeting — Adapt output for Claude, GPT, Gemini, and others via environment config
- Presets — Role, task, constraint, and steps presets encode prompt engineering best practices
- Smart Defaults — Auto-generated role, format, and constraint sections with full opt-out control
- Version Controlled — Prompts live in files, tracked in git, reviewed in PRs
- Shareable — Publish prompt libraries to npm, consume others' work via npm, URLs, or local files
- Browser & Node.js — Works in both environments with runtime JSX transformation
Documentation
Visit apowers313.github.io/pupt-lib for:
- Getting Started — installation, first prompt,
.promptvs.tsx - Component Reference — all 50+ built-in components with props and examples
- Variables & Inputs — collecting user input with
Askcomponents - Conditional Logic —
If,ForEach, and formula evaluation - Environment & Providers — targeting different LLM providers
- Custom Components — building your own components
- Modules & Sharing — publishing and importing prompt libraries
- API Reference — functions, types, and utilities
License
MIT
