UNPKG

cookie-ai-cli

Version:

A command-line interface tool designed to bridge the gap between natural language processing and command-line operations.

61 lines 2.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.handleAction = void 0; const ask_question_1 = require("./ask-question"); const handle_command_1 = require("./handle-command"); const send_chat_1 = require("./send-chat"); const prompt_user_1 = require("./prompt-user"); const colors_1 = require("./utils/colors"); async function handleAction({ result, rl }) { if (result.action === "command") { await (0, handle_command_1.handleCommand)({ rl, command: result.command, description: result.description, }); } else if (result.action === "command_list") { for (const command of result.commands) { await (0, handle_command_1.handleCommand)({ rl, command, description: result.description, }); } } else if (result.action === "user_info_required") { const values = {}; for (const item of result.values) { const answer = await (0, ask_question_1.askQuestion)(rl, item.label); values[item.value] = answer; } if (result.suggested_command_list) { for (const command of result.suggested_command_list) { await (0, handle_command_1.handleCommand)({ rl, command, values, description: result.description, }); } } if (result.suggested_command) { await (0, handle_command_1.handleCommand)({ rl, command: result.suggested_command, values, description: result.description, }); } } else { console.log(`${colors_1.colors.red}AI tried to use an unsupported action, telling AI to retry: ${colors_1.colors.reset}`, result.action); await (0, send_chat_1.sendChat)({ message: `${result.action} is not a supported action. Make sure you respond only with JSON that satisfies the Response type.`, rl, }); } (0, prompt_user_1.promptUser)({ rl }); } exports.handleAction = handleAction; //# sourceMappingURL=handle-action.js.map