Packaging & Bundlers
Use praisonai in Node, browsers, React Native, and edge runtimes
praisonai ships both ESM and CommonJS builds, so it works out-of-the-box with modern bundlers and legacy Node projects alike.
Quick Start
- Install
npm npm install praisonaiyarn yarn add praisonai - Create an agent (ESM or CommonJS)
ESM
typescript import { Agent } from 'praisonai'; const agent = new Agent({ instructions: 'You are a helpful AI assistant' }); agent.start('Write a movie script about a robot in Mars');CommonJS
javascript const { Agent } = require('praisonai'); const agent = new Agent({ instructions: 'You are a helpful AI assistant' }); agent.start('Write a movie script about a robot in Mars');
How It Works
The package.json entry points tell each runtime and bundler which build to load.
import resolves to the ESM build, require resolves to the CJS build, and TypeScript reads the shared type declarations — no configuration needed on your side.
| Field | Value | What it does |
|---|---|---|
main | dist/index.js | CommonJS entry for require |
module | dist/esm/index.js | Hints bundlers at the ESM build |
types | dist/index.d.ts | TypeScript declarations |
exports["."].import | ./dist/esm/index.js | ESM entry for import |
exports["."].require | ./dist/index.js | CJS entry for require |
The ESM build is produced by a small shim that rewrites relative specifiers, adds a createRequire banner for interop, and drops a dist/esm/package.json marked { "type": "module" }.
Using in Different Environments
Pick the entry point that matches where you run praisonai.
Node.js (CommonJS)
const { Agent } = require('praisonai');
const agent = new Agent({ instructions: 'You are a helpful AI assistant' });
agent.start('Write a haiku about the ocean');Node.js (ESM)
import { Agent } from 'praisonai';
const agent = new Agent({ instructions: 'You are a helpful AI assistant' });
agent.start('Write a haiku about the ocean');TypeScript
{
"compilerOptions": {
"module": "esnext",
"moduleResolution": "bundler",
"target": "es2022"
}
}import { Agent } from 'praisonai';
const agent = new Agent({ instructions: 'You are a helpful AI assistant' });
agent.start('Explain quantum computing simply');Vite / Rollup / esbuild
import { Agent } from 'praisonai';
const agent = new Agent({ instructions: 'You are a helpful AI assistant' });
await agent.start('Summarise the latest AI news');Next.js
import { Agent } from 'praisonai';
export async function POST(req: Request) {
const { prompt } = await req.json();
const agent = new Agent({ instructions: 'You are a helpful AI assistant' });
const result = await agent.start(prompt);
return Response.json({ result });
}React Native (Metro)
import { Agent } from 'praisonai/agent/simple';
const agent = new Agent({ instructions: 'You are a helpful AI assistant' });
agent.start('Suggest a name for my app');Deno / Bun
import { Agent } from 'praisonai';
const agent = new Agent({ instructions: 'You are a helpful AI assistant' });
agent.start('Write a limerick about coffee');Subpath Imports
Import from a subpath to load only the module you need.
import { Agent, Agents } from 'praisonai';import { generateText, streamText } from 'praisonai/ai';import { createTool, tool } from 'praisonai/tools';import { Agent } from 'praisonai/agent/simple';| Subpath | Import | Contents |
|---|---|---|
. | praisonai | Full public API (Agent, Agents, Workflow, tools, providers) |
./ai | praisonai/ai | AI SDK wrappers (generateText, streamText, generateObject) |
./tools | praisonai/tools | Tool base classes and registry (createTool, tool) |
./agent/simple | praisonai/agent/simple | The Agent class plus agent-related type exports (SimpleAgentConfig, AgentTeamConfig, PraisonAIAgentsConfig). The team-class values (AgentTeam, PraisonAIAgents, Agents) are not re-exported here — import those from praisonai or praisonai/agent. |
Best Practices
Prefer ESM imports in new projects
Use import { Agent } from 'praisonai' for new code. ESM is the default for bundlers and edge runtimes, and it preserves await import() as a lazy chunk instead of forcing a synchronous require().
Bundle for the browser today — what works and what doesn't
The root barrel (praisonai) still pulls in the CLI and other Node-only code, so a raw import 'praisonai' in a browser or React Native bundle drags in Node built-ins. Use deep imports — for example praisonai/agent/simple — to keep browser and React Native bundles Node-safe.
Verify your install with verify:dist
Contributors can run npm run verify:dist to confirm both the CJS and ESM entry points load in a real Node process before publishing.
Node version — 18 or later
The package sets engines.node >= 18. The bundled openai dependency needs Node 18, so older runtimes are not supported.