Skip to content

Commit 2953cb5

Browse files
committed
Merge branch 'main' of https://github.com/kaiban-ai/KaibanJS into fixing-types
2 parents 09887ef + e3bf624 commit 2953cb5

File tree

8 files changed

+2447
-3
lines changed

8 files changed

+2447
-3
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "kaibanjs",
3-
"version": "0.14.0",
3+
"version": "0.14.1",
44
"description": "AI Multi-Agent library for Javascript Developers.",
55
"main": "./dist/bundle.cjs",
66
"types": "./dist/bundle.d.ts",

playground/nodejs-esm/.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# OpenAI API Key for KaibanJS
2+
OPENAI_API_KEY=your-api-key-here

playground/nodejs-esm/README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Node.js ESM Example
2+
3+
This example demonstrates using KaibanJS in a Node.js environment with ESM (ECMAScript Modules) imports. It includes both ESM and CommonJS versions of the same code to showcase compatibility across different module systems.
4+
5+
## Environment Setup
6+
7+
- Node.js version: >=21.0.0 (tested with Node.js 21)
8+
- KaibanJS version: ^0.14.0
9+
10+
## Project Structure
11+
12+
```
13+
nodejs-esm/
14+
├── .env # Environment variables configuration
15+
├── index.js # ESM version using import statements
16+
├── index.cjs # CommonJS version using require statements
17+
└── package.json # Project configuration with "type": "module"
18+
```
19+
20+
## Key Features
21+
22+
- Demonstrates KaibanJS usage in a Node.js environment
23+
- Shows both ESM and CommonJS module system compatibility
24+
- Implements a complete team workflow with multiple agents and tasks
25+
- Includes proper error handling and workflow status monitoring
26+
27+
## Getting Started
28+
29+
1. Install dependencies:
30+
```bash
31+
npm install
32+
```
33+
34+
2. Configure your environment:
35+
- Copy `.env.example` to `.env` (if not already done)
36+
- Add your OpenAI API key to `.env`:
37+
```
38+
OPENAI_API_KEY=your-api-key-here
39+
```
40+
41+
3. Run the examples:
42+
```bash
43+
# Run ESM version
44+
npm start
45+
46+
# Run CommonJS version
47+
npm run start:cjs
48+
```
49+
50+
## Code Examples
51+
52+
### ESM Version (index.js)
53+
```javascript
54+
import { Agent, Task, Team } from 'kaibanjs';
55+
```
56+
57+
### CommonJS Version (index.cjs)
58+
```javascript
59+
const { Agent, Task, Team } = require('kaibanjs');
60+
```
61+
62+
## Notes
63+
64+
- This example demonstrates that KaibanJS works in Node.js environments without requiring React as a dependency
65+
- The example uses zustand's core functionality without React-specific features
66+
- Both ESM and CommonJS versions implement the same functionality to showcase module system compatibility

playground/nodejs-esm/index.cjs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// CommonJS version
2+
const { Agent, Task, Team } = require('kaibanjs');
3+
const dotenv = require('dotenv');
4+
5+
dotenv.config();
6+
7+
// Create multiple agents with different roles
8+
const researcher = new Agent({
9+
name: 'ResearchBot',
10+
role: 'Research Specialist',
11+
goal: 'Gather and analyze information',
12+
background: 'Expert in data collection and analysis',
13+
});
14+
15+
const writer = new Agent({
16+
name: 'WriterBot',
17+
role: 'Content Writer',
18+
goal: 'Create engaging content from research',
19+
background: 'Professional content creator and editor',
20+
});
21+
22+
const reviewer = new Agent({
23+
name: 'ReviewBot',
24+
role: 'Quality Reviewer',
25+
goal: 'Ensure content meets quality standards',
26+
background: 'Quality assurance specialist',
27+
});
28+
29+
// Create tasks for each agent
30+
const researchTask = new Task({
31+
title: 'Research Topic',
32+
description: 'Research the given topic and extract key information',
33+
expectedOutput: 'Structured research data',
34+
agent: researcher,
35+
});
36+
37+
const writingTask = new Task({
38+
title: 'Create Content',
39+
description: 'Transform research into engaging content',
40+
expectedOutput: 'Draft content',
41+
agent: writer,
42+
});
43+
44+
const reviewTask = new Task({
45+
title: 'Review Content',
46+
description: 'Review and polish the content',
47+
expectedOutput: 'Final polished content',
48+
agent: reviewer,
49+
});
50+
51+
// Create and configure the team
52+
const team = new Team({
53+
name: 'Content Creation Team',
54+
agents: [researcher, writer, reviewer],
55+
tasks: [researchTask, writingTask, reviewTask],
56+
inputs: {
57+
topic:
58+
'The impact of artificial intelligence on modern software development',
59+
},
60+
env: { OPENAI_API_KEY: process.env.OPENAI_API_KEY },
61+
});
62+
63+
// Subscribe to team status updates
64+
const unsubscribe = team.subscribeToChanges(
65+
(updatedFields) => {
66+
console.log('Team Status Updated:', updatedFields);
67+
},
68+
['teamWorkflowStatus']
69+
);
70+
71+
// Start the team workflow
72+
console.log('Starting team workflow...');
73+
(async () => {
74+
try {
75+
const result = await team.start();
76+
console.log('Final Result:', result);
77+
} catch (error) {
78+
console.error('Error during workflow:', error);
79+
} finally {
80+
unsubscribe();
81+
}
82+
})();

playground/nodejs-esm/index.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// ESM version
2+
import { Agent, Task, Team } from 'kaibanjs';
3+
import * as dotenv from 'dotenv';
4+
5+
dotenv.config();
6+
7+
// Create multiple agents with different roles
8+
const researcher = new Agent({
9+
name: 'ResearchBot',
10+
role: 'Research Specialist',
11+
goal: 'Gather and analyze information',
12+
background: 'Expert in data collection and analysis',
13+
});
14+
15+
const writer = new Agent({
16+
name: 'WriterBot',
17+
role: 'Content Writer',
18+
goal: 'Create engaging content from research',
19+
background: 'Professional content creator and editor',
20+
});
21+
22+
const reviewer = new Agent({
23+
name: 'ReviewBot',
24+
role: 'Quality Reviewer',
25+
goal: 'Ensure content meets quality standards',
26+
background: 'Quality assurance specialist',
27+
});
28+
29+
// Create tasks for each agent
30+
const researchTask = new Task({
31+
title: 'Research Topic',
32+
description: 'Research the given topic and extract key information',
33+
expectedOutput: 'Structured research data',
34+
agent: researcher,
35+
});
36+
37+
const writingTask = new Task({
38+
title: 'Create Content',
39+
description: 'Transform research into engaging content',
40+
expectedOutput: 'Draft content',
41+
agent: writer,
42+
});
43+
44+
const reviewTask = new Task({
45+
title: 'Review Content',
46+
description: 'Review and polish the content',
47+
expectedOutput: 'Final polished content',
48+
agent: reviewer,
49+
});
50+
51+
// Create and configure the team
52+
const team = new Team({
53+
name: 'Content Creation Team',
54+
agents: [researcher, writer, reviewer],
55+
tasks: [researchTask, writingTask, reviewTask],
56+
inputs: {
57+
topic:
58+
'The impact of artificial intelligence on modern software development',
59+
},
60+
env: { OPENAI_API_KEY: process.env.OPENAI_API_KEY },
61+
});
62+
63+
// Subscribe to team status updates
64+
const unsubscribe = team.subscribeToChanges(
65+
(updatedFields) => {
66+
console.log('Team Status Updated:', updatedFields);
67+
},
68+
['teamWorkflowStatus']
69+
);
70+
71+
// Start the team workflow
72+
console.log('Starting team workflow...');
73+
try {
74+
const result = await team.start();
75+
console.log('Final Result:', result);
76+
} catch (error) {
77+
console.error('Error during workflow:', error);
78+
} finally {
79+
unsubscribe();
80+
}

0 commit comments

Comments
 (0)