forked from kaiban-ai/KaibanJS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Babel configuration, ESLint rules, and package dependencies; r…
…emove Jest config and workflow controller - Updated Babel preset to target the current Node version. - Added ESLint rule to disable focused tests in Jest. - Removed obsolete Jest configuration file. - Updated package dependencies, including Babel and added new dependencies: `dependency-graph` and `fastq`. - Added a new CLI command for refreshing the project environment. - Refactored task management in the application by introducing a TaskManager and subscribing to task and workflow status updates. - Removed the workflow controller to streamline task management. - Enhanced agent utility functions with a new cloning mechanism for agents. Related GH Issue: kaiban-ai#153
- Loading branch information
1 parent
9776374
commit 122cdc9
Showing
22 changed files
with
3,441 additions
and
1,029 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
// "presets": ["@babel/preset-env"], | ||
"presets": [["@babel/preset-env", { "targets": { "node": "current" } }]] | ||
// "plugins": ["@babel/plugin-syntax-import-meta"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const config = { | ||
testEnvironment: 'node', | ||
transform: { | ||
'^.+\\.[t|j]sx?$': 'babel-jest', | ||
}, | ||
collectCoverageFrom: ['src/**/*.js', '!**/node_modules/**', '!**/vendor/**'], | ||
moduleNameMapper: { | ||
'^kaibanjs$': '<rootDir>/dist/bundle.cjs', | ||
}, | ||
coverageThreshold: { | ||
global: { | ||
branches: 80, | ||
functions: 80, | ||
lines: 80, | ||
statements: 80, | ||
}, | ||
}, | ||
testMatch: ['<rootDir>/tests/**/*.test.js'], | ||
}; | ||
|
||
export default config; |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
src/managers/executionStrategies/hierarchyExecutionStrategy.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import DepGraph from 'dependency-graph'; | ||
import { TASK_STATUS_enum } from '../../utils/enums'; | ||
import WorkflowExecutionStrategy from './workflowExecutionStrategy'; | ||
|
||
/** | ||
* Class for hierarchical workflow execution strategy | ||
* | ||
* This strategy is used when tasks have dependencies on each other, and the workflow needs to be executed in a hierarchical manner. | ||
* It ensures that tasks are executed in the correct order, taking into account dependencies and ensuring that tasks are not started | ||
* until all of their prerequisites are complete. | ||
*/ | ||
class HierarchyExecutionStrategy extends WorkflowExecutionStrategy { | ||
constructor(useTeamStore) { | ||
super(useTeamStore); | ||
this.graph = new DepGraph(); | ||
|
||
// Initialize dependency graph | ||
const tasks = useTeamStore.getState().tasks; | ||
tasks.forEach((task) => { | ||
this.graph.addNode(task.id); | ||
}); | ||
|
||
// Add dependencies | ||
tasks.forEach((task) => { | ||
if (task.dependsOn) { | ||
task.dependsOn.forEach((depId) => { | ||
this.graph.addDependency(task.id, depId); | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
isAgentBusy(agent, tasks) { | ||
return tasks.some( | ||
(t) => t.agent.id === agent.id && t.status === TASK_STATUS_enum.DOING | ||
); | ||
} | ||
|
||
/** | ||
* Gets all tasks that the given task depends on (its prerequisites) | ||
* @param {Object} task - The task to find dependencies for | ||
* @param {Array} allTasks - Array of all tasks in the workflow | ||
* @returns {Array} Array of task objects that are dependencies of the given task | ||
*/ | ||
getTaskDependencies(task, allTasks) { | ||
if (!task.dependsOn || task.dependsOn.length === 0) { | ||
return []; | ||
} | ||
return allTasks.filter((t) => task.dependsOn.includes(t.id)); | ||
} | ||
|
||
/** | ||
* Gets all tasks that depend on the given task (tasks that have this task as a prerequisite) | ||
* @param {Object} task - The task to find dependent tasks for | ||
* @param {Array} allTasks - Array of all tasks in the workflow | ||
* @returns {Array} Array of task objects that depend on the given task | ||
*/ | ||
getAllTasksDependingOn(task, allTasks) { | ||
return allTasks.filter((t) => t.dependsOn && t.dependsOn.includes(task.id)); | ||
} | ||
|
||
/** | ||
* Gets all tasks that are ready to be executed | ||
* @param {Array} allTasks - Array of all tasks in the workflow | ||
* @returns {Array} Array of task objects that are ready to be executed | ||
*/ | ||
getReadyTasks(allTasks) { | ||
return allTasks.filter((task) => { | ||
// Task must be in TODO status | ||
if (task.status !== TASK_STATUS_enum.TODO) return false; | ||
|
||
// All dependencies must be DONE | ||
const deps = this.getTaskDependencies(task, allTasks); | ||
return ( | ||
deps.length === 0 || | ||
deps.every((dep) => dep.status === TASK_STATUS_enum.DONE) | ||
); | ||
}); | ||
} | ||
|
||
async execute(changedTasks, allTasks) { | ||
// Handle changed tasks first | ||
for (const changedTask of changedTasks) { | ||
switch (changedTask.status) { | ||
case TASK_STATUS_enum.DOING: | ||
// Execute the task | ||
await super._executeTask(changedTask); | ||
break; | ||
|
||
case TASK_STATUS_enum.REVISE: | ||
{ | ||
// Block all dependent tasks | ||
const dependentTasks = this.getAllTasksDependingOn( | ||
changedTask, | ||
allTasks | ||
); | ||
dependentTasks.forEach((task) => { | ||
this.useTeamStore | ||
.getState() | ||
.updateTaskStatus(task.id, TASK_STATUS_enum.BLOCKED); | ||
}); | ||
} | ||
|
||
break; | ||
} | ||
} | ||
|
||
// Find and execute all possible tasks | ||
const executableTasks = allTasks.filter((task) => { | ||
if (task.status !== TASK_STATUS_enum.TODO) return false; | ||
|
||
// Check if task has no dependencies or all dependencies are done | ||
const deps = this.getTaskDependencies(task, allTasks); | ||
return ( | ||
deps.length === 0 || | ||
deps.every((dep) => dep.status === TASK_STATUS_enum.DONE) | ||
); | ||
}); | ||
|
||
executableTasks.forEach((task) => { | ||
super._executeTask(task); | ||
}); | ||
} | ||
} | ||
|
||
export default HierarchyExecutionStrategy; |
14 changes: 14 additions & 0 deletions
14
src/managers/executionStrategies/managerLLMExecutionStrategy.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import WorkflowExecutionStrategy from './workflowExecutionStrategy'; | ||
|
||
class ManagerLLMStrategy extends WorkflowExecutionStrategy { | ||
constructor(useTeamStore) { | ||
super(useTeamStore); | ||
} | ||
|
||
execute(_changedTasks, _allTasks) { | ||
// TODO: Implement ManagerLLMStrategy.execute() | ||
throw new Error('ManagerLLMStrategy.execute() not implemented'); | ||
} | ||
} | ||
|
||
export default ManagerLLMStrategy; |
55 changes: 55 additions & 0 deletions
55
src/managers/executionStrategies/sequentialExecutionStrategy.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import fastq from 'fastq'; | ||
import { TASK_STATUS_enum } from '../../utils/enums'; | ||
import WorkflowExecutionStrategy from './workflowExecutionStrategy'; | ||
|
||
class SequentialExecutionStrategy extends WorkflowExecutionStrategy { | ||
constructor(useTeamStore) { | ||
super(useTeamStore); | ||
this.taskQueue = fastq(async (task, callback) => { | ||
await this._executeTask(task); | ||
callback(); | ||
}, 1); | ||
} | ||
|
||
async execute(changedTasks, allTasks) { | ||
// Implement the logic for the sequential execution strategy | ||
// This method should handle the tasks in the order they are received | ||
// and ensure that tasks are executed sequentially | ||
for (const changedTask of changedTasks) { | ||
switch (changedTask.status) { | ||
case TASK_STATUS_enum.DOING: | ||
this.taskQueue.push(changedTask); | ||
break; | ||
case TASK_STATUS_enum.REVISE: | ||
{ | ||
// Find the index of the current revise task | ||
const taskIndex = allTasks.findIndex( | ||
(t) => t.id === changedTask.id | ||
); | ||
|
||
// Move all subsequent tasks to TODO | ||
for (let i = taskIndex + 1; i < allTasks.length; i++) { | ||
this._updateTaskStatus(allTasks[i].id, TASK_STATUS_enum.TODO); | ||
} | ||
|
||
this._updateTaskStatus(changedTask.id, TASK_STATUS_enum.DOING); | ||
} | ||
break; | ||
case TASK_STATUS_enum.DONE: | ||
{ | ||
const tasks = this.useTeamStore.getState().tasks; | ||
const nextTask = tasks.find( | ||
(t) => t.status === TASK_STATUS_enum.TODO | ||
); | ||
console.log({ nextTask }); | ||
if (nextTask) { | ||
this._updateTaskStatus(nextTask.id, TASK_STATUS_enum.DOING); | ||
} | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
export default SequentialExecutionStrategy; |
Oops, something went wrong.