npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

openai-swarmjs

v0.1.5

Published

Agentic framework inspired from OpenAI's swarm framework for TS, JS

Downloads

267

Readme

SwarmJS

Agentic framework inspired from OpenAI's swarm framework in Python for TypeScript and JavaScript.

Prerequisites

  • Node.js (v16 or higher)
  • npm (v7 or higher)
  • TypeScript (v4.5 or higher)
  • OpenAI API key

Setup

  1. Clone the repository:
git clone https://github.com/yourusername/swarmjs.git
cd swarmjs
  1. Install dependencies:
npm install
  1. Create a .env file in the root directory and add your OpenAI API key:
OPENAI_API_KEY=your_api_key_here
DEBUG=false  # Set to true for detailed logging

Project Structure

swarmjs/
├── core/
│   ├── swarm.ts
│   └── types.ts
├── lib/
│   └── swarms/
│       └── DagSwarm.ts
├── examples/
│   ├── simple-agent.ts
│   └── simple-dag-swarm.ts
├── repl.ts
└── package.json

Available Examples

1. Simple Agent Example

A basic implementation using a single agent to create customized greetings based on timezone:

npm run example:simple-agent
# or
ts-node examples/simple-agent.ts

2. DAG Swarm Example

A more complex implementation using Directed Acyclic Graph (DAG) for planning and execution:

npm run example:dag-swarm
# or
ts-node examples/simple-dag-swarm.ts

Development

Running in Debug Mode

Set the DEBUG environment variable to true in your .env file or when running the command:

DEBUG=true npm run example:simple-agent

Adding New Examples

  1. Create a new file in the examples directory
  2. Import the runExample function from repl.ts
  3. Implement your example following the existing patterns
  4. Add a new script to package.json for easy execution

Example:

import { runExample } from '../repl';
import { Agent } from '../core/types';

// Define your agent and functions
const myAgent: Agent = {
    // Agent configuration
};

runExample('MyExample', () => myAgent);

Building the Project

  1. Build the TypeScript files:
npm run build

This will:

  • Type-check all files
  • Compile TypeScript to JavaScript
  • Output to the dist directory
  1. Run the built version:
node dist/examples/simple-agent.js

Scripts

Add these scripts to your package.json:

{
  "scripts": {
    "build": "tsc",
    "start": "ts-node repl.ts",
    "example:simple-agent": "ts-node examples/simple-agent.ts",
    "example:dag-swarm": "ts-node examples/simple-dag-swarm.ts",
    "dev": "ts-node-dev --respawn --transpile-only repl.ts",
    "lint": "eslint . --ext .ts",
    "test": "jest"
  }
}

Dependencies

Add these to your package.json:

{
  "dependencies": {
    "openai": "^4.0.0",
    "dotenv": "^16.0.0",
    "chalk": "^4.1.2"
  },
  "devDependencies": {
    "@types/node": "^16.0.0",
    "typescript": "^4.5.0",
    "ts-node": "^10.0.0",
    "ts-node-dev": "^2.0.0",
    "@typescript-eslint/eslint-plugin": "^5.0.0",
    "@typescript-eslint/parser": "^5.0.0",
    "eslint": "^8.0.0",
    "jest": "^27.0.0",
    "@types/jest": "^27.0.0",
    "ts-jest": "^27.0.0"
  }
}

TypeScript Configuration

Add this tsconfig.json to your project root:

{
  "compilerOptions": {
    "target": "ES2020",
    "module": "commonjs",
    "lib": ["ES2020"],
    "outDir": "./dist",
    "rootDir": "./",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "resolveJsonModule": true
  },
  "include": ["./**/*.ts"],
  "exclude": ["node_modules", "dist"]
}

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

License

MIT

Support

For support, please open an issue in the GitHub repository.

License

MIT License - see LICENSE for details

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.