( task: partialTaskDraft, parent: LLMTask | undefined, chatState: ChatStateType, execute = true )
| 221 | } |
| 222 | |
| 223 | export function addTask2Tree( |
| 224 | task: partialTaskDraft, |
| 225 | parent: LLMTask | undefined, |
| 226 | chatState: ChatStateType, |
| 227 | execute = true |
| 228 | ) { |
| 229 | const uuid = base64Uuid(); |
| 230 | |
| 231 | const newTask: LLMTask = { |
| 232 | role: task.role, |
| 233 | parentID: parent?.id, |
| 234 | content: task.content || null, |
| 235 | state: task.state || 'Open', |
| 236 | childrenIDs: [], |
| 237 | debugging: task.debugging || {}, |
| 238 | id: uuid, |
| 239 | created_at: Date.now(), |
| 240 | context: task.context, |
| 241 | allowedTools: task.allowedTools || parent?.allowedTools, |
| 242 | }; |
| 243 | |
| 244 | console.log('create new Task:', newTask.id); |
| 245 | |
| 246 | // connect task to task tree |
| 247 | chatState.Tasks[newTask.id] = newTask; |
| 248 | if (parent) { |
| 249 | parent.childrenIDs.push(newTask.id); |
| 250 | } |
| 251 | // Push the new function task to processTasksQueue |
| 252 | if (execute) { |
| 253 | processTasksQueue.push(chatState.Tasks[newTask.id]); |
| 254 | chatState.Tasks[newTask.id].state = 'Queued'; |
| 255 | } |
| 256 | chatState.selectedTaskId = newTask.id; |
| 257 | return newTask.id; |
| 258 | } |
no test coverage detected