vibepkg
v1.0.0
Published
Experimental library that generates and executes code on-the-fly based on function calls using AI
Downloads
7
Maintainers
Readme
vibepkg
An experimental npm library that generates JavaScript code on-the-fly using AI. Call any function name - it will be generated and executed automatically.
import vibe from 'vibepkg';
const area = await vibe.calculateCircleArea(5); // 78.54
const slug = await vibe.createSlug('Hello World!'); // 'hello-world'
const sorted = await vibe.sortNumbers([3,1,4]); // [1,3,4]How It Works
- Proxy Intercept - JavaScript Proxy catches any function call
- AI Generation - Function name + params → OpenAI/Ollama → JavaScript code
- VM Execution - Code runs in isolated Node.js VM (5s timeout)
- Smart Caching - Identical calls cached (2ms vs 1500ms average)
Installation & Setup
npm install vibepkg
# Option 1: OpenAI (fast, costs money)
export OPENAI_API_KEY=your_key
# Option 2: Ollama (free, slower)
ollama serve
ollama run llama3:latestCode Execution Context
Available at Runtime:
- JavaScript built-ins:
Math,Date,JSON,Object,Array,String,Number,Boolean,RegExp - Function parameters:
param0,param1, etc. - Passed variables/functions work as expected
Disabled for Security:
- File system: No
fs,path,require() - Network: No
http,fetch(), external APIs - Process: No
process,child_process,Buffer - Timers: No
setTimeout,setInterval - Console:
console.log()disabled
Execution Phases:
- Compile Time - TypeScript → JavaScript (build step)
- Request Time - AI generates code string (~1500ms)
- Runtime - VM executes in sandboxed context (5s max)
🚀 Future Enhancement: Static code generation at compile time for zero-latency function calls
Testing
Results vary due to AI non-determinism (80-100% success rate):
npm test # Run 23 test functions
node debug.js # Test individual componentsCommon Issues:
- Code truncation causing syntax errors
- Type confusion (Date vs string)
- Algorithm variance between runs
Configuration
import { createVibe } from 'vibepkg';
const vibe = createVibe({
openaiApiKey: 'sk-...', // Optional
model: 'gpt-4', // Optional
debug: true // Show generated code
});Security
- Sandboxed VM - No file/network access
- 5s timeout - Prevents infinite loops
- Input sanitization - Basic function name validation
- No eval() - Uses Node.js vm module
⚠️ Don't use with untrusted inputs - Generated code is executed
Performance
| Metric | Value | |--------|-------| | First call | ~1500ms (AI generation) | | Cached call | ~2ms (memory lookup) | | Success rate | 80-100% (varies by complexity) | | VM timeout | 5000ms max execution |
License
ISC
