UNPKG

@graphteon/juricode

Version:

We are forging the future with lines of digital steel

118 lines (116 loc) • 4.57 kB
import prompts from 'prompts'; import chalk from 'chalk'; import ora from 'ora'; import boxen from 'boxen'; import OpenHands from '../api/open-hands'; import { runTaskChat } from './chat'; const getTaskTypeColor = (taskType) => { switch (taskType) { case 'FAILING_CHECKS': return chalk.red(taskType); case 'MERGE_CONFLICTS': return chalk.yellow(taskType); case 'OPEN_ISSUE': return chalk.blue(taskType); default: return chalk.white(taskType); } }; const getTaskTypeIcon = (taskType) => { switch (taskType) { case 'FAILING_CHECKS': return 'āŒ'; case 'MERGE_CONFLICTS': return 'šŸ”€'; case 'OPEN_ISSUE': return 'šŸ“‹'; default: return 'šŸ“'; } }; export const listSuggestedTasks = async () => { const spinner = ora('Fetching suggested tasks...').start(); try { const suggestedTasks = await OpenHands.getSuggestedTasks(); spinner.succeed('Suggested tasks fetched successfully!'); if (suggestedTasks.length === 0) { console.log(chalk.yellow('No suggested tasks found')); return; } const taskAnswer = await prompts({ type: 'select', name: 'selectedTask', message: 'Select a suggested task to work on:', choices: suggestedTasks.map((task, index) => ({ title: `${getTaskTypeIcon(task.task_type)} [${index + 1}] ${task.title}`, value: task, description: `${chalk.cyan(task.repo)} | ${getTaskTypeColor(task.task_type)} | Issue #${task.issue_number}` })) }); if (taskAnswer.selectedTask) { const selectedTask = taskAnswer.selectedTask; console.log(boxen(`${getTaskTypeIcon(selectedTask.task_type)} ${chalk.bold(selectedTask.title)} Repository: ${chalk.cyan(selectedTask.repo)} Provider: ${chalk.green(selectedTask.git_provider)} Type: ${getTaskTypeColor(selectedTask.task_type)} Issue: ${chalk.yellow(`#${selectedTask.issue_number}`)}`, { padding: 1, margin: { top: 1 }, borderColor: 'cyan', borderStyle: 'round' })); const actionAnswer = await prompts({ type: 'select', name: 'action', message: 'What would you like to do with this suggested task?', choices: [ { title: 'šŸš€ Start Working on Task', value: 'start' }, { title: 'ā†©ļø Back to Task List', value: 'back' }, { title: 'šŸ  Return to Main Menu', value: 'main' } ] }); if (actionAnswer.action === 'start') { await startSuggestedTask(selectedTask); } else if (actionAnswer.action === 'back') { await listSuggestedTasks(); } } } catch (error) { spinner.fail('Failed to fetch suggested tasks'); console.error(chalk.red(error instanceof Error ? error.message : 'Unknown error')); } }; const startSuggestedTask = async (suggestedTask) => { const spinner = ora('Creating conversation from suggested task...').start(); try { const response = await OpenHands.createConversationFromSuggestedTask(suggestedTask); spinner.succeed('Conversation created successfully!'); console.log(boxen(`šŸŽ‰ ${chalk.green('Task Started Successfully!')} Conversation ID: ${chalk.cyan(response.conversation_id)} Status: ${chalk.yellow(response.conversation_status)} Repository: ${chalk.cyan(suggestedTask.repo)} Task: ${chalk.white(suggestedTask.title)}`, { padding: 1, margin: { top: 1 }, borderColor: 'green', borderStyle: 'double' })); const chatAnswer = await prompts({ type: 'confirm', name: 'startChat', message: 'Would you like to start chatting with the AI about this task?', initial: true }); if (chatAnswer.startChat) { console.log(chalk.blue('\nšŸ¤– Starting chat session...\n')); await runTaskChat(response.conversation_id); } } catch (error) { spinner.fail('Failed to create conversation from suggested task'); console.error(chalk.red(error instanceof Error ? error.message : 'Unknown error')); } }; //# sourceMappingURL=suggested-tasks.js.map