(lastTaskId: string, tasks: Record<string, LLMTask>)
| 115 | } |
| 116 | |
| 117 | export function taskChain(lastTaskId: string, tasks: Record<string, LLMTask>) { |
| 118 | // Start with the selected task |
| 119 | let currentTaskID = lastTaskId; |
| 120 | const conversationList: string[] = []; |
| 121 | |
| 122 | // Trace back the parentIDs to the original task in the chain |
| 123 | while (currentTaskID) { |
| 124 | // Get the current task |
| 125 | const currentTask = tasks[currentTaskID]; |
| 126 | if (!currentTask) break; // Break if we reach a task that doesn't exist |
| 127 | |
| 128 | // Prepend the current task to the conversation list so the selected task ends up being the last in the list |
| 129 | conversationList.unshift(currentTaskID); |
| 130 | |
| 131 | // Move to the parent task |
| 132 | if (currentTask.parentID) { |
| 133 | currentTaskID = currentTask.parentID; // This can now be string | undefined |
| 134 | } else break; // Break if we reach an "initial" task |
| 135 | } |
| 136 | |
| 137 | return conversationList; |
| 138 | } |
| 139 | |
| 140 | function base64Uuid() { |
| 141 | // Generate a UUID |
no outgoing calls
no test coverage detected