UNPKG

@vibe-kit/grok-cli

Version:

An open-source AI agent that brings the power of Grok directly into your terminal.

141 lines (138 loc) 6.9 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); const react_1 = __importStar(require("react")); const ink_1 = require("ink"); function ConversationalApp({ agent }) { const [input, setInput] = (0, react_1.useState)(''); const [conversation, setConversation] = (0, react_1.useState)([]); const [isProcessing, setIsProcessing] = (0, react_1.useState)(false); const { exit } = (0, ink_1.useApp)(); const scrollRef = (0, react_1.useRef)(); (0, react_1.useEffect)(() => { // Show welcome message const welcomeEntry = { type: 'assistant', content: `👋 Hello! I'm Grok CLI, your AI coding assistant. I can help you with: • Viewing and editing files • Creating new files and directories • Running bash commands • Code analysis and debugging • General programming tasks Just tell me what you'd like to do in natural language! Current directory: ${agent.getCurrentDirectory()}`, timestamp: new Date() }; setConversation([welcomeEntry]); }, []); (0, ink_1.useInput)(async (inputChar, key) => { if (key.ctrl && inputChar === 'c') { exit(); return; } if (key.return) { const userInput = input.trim(); if (userInput === 'exit' || userInput === 'quit') { exit(); return; } if (userInput) { setIsProcessing(true); setInput(''); try { const newEntries = await agent.processUserMessage(userInput); setConversation(prev => [...prev, ...newEntries]); } catch (error) { const errorEntry = { type: 'assistant', content: `Error: ${error.message}`, timestamp: new Date() }; setConversation(prev => [...prev, errorEntry]); } setIsProcessing(false); } return; } if (key.backspace || key.delete) { setInput(prev => prev.slice(0, -1)); return; } if (inputChar && !key.ctrl && !key.meta) { setInput(prev => prev + inputChar); } }); const renderEntry = (entry, index) => { const timeStr = entry.timestamp.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); switch (entry.type) { case 'user': return (react_1.default.createElement(ink_1.Box, { key: index, flexDirection: "column", marginBottom: 1 }, react_1.default.createElement(ink_1.Box, null, react_1.default.createElement(ink_1.Text, { color: "blue", bold: true }, "You (", timeStr, ")")), react_1.default.createElement(ink_1.Box, { marginLeft: 2 }, react_1.default.createElement(ink_1.Text, null, entry.content)))); case 'assistant': return (react_1.default.createElement(ink_1.Box, { key: index, flexDirection: "column", marginBottom: 1 }, react_1.default.createElement(ink_1.Box, null, react_1.default.createElement(ink_1.Text, { color: "green", bold: true }, "\uD83E\uDD16 Grok (", timeStr, ")"), entry.toolCalls && entry.toolCalls.length > 0 && (react_1.default.createElement(ink_1.Text, { color: "yellow" }, " [using tools]"))), react_1.default.createElement(ink_1.Box, { marginLeft: 2 }, react_1.default.createElement(ink_1.Text, null, entry.content)))); case 'tool_result': return (react_1.default.createElement(ink_1.Box, { key: index, flexDirection: "column", marginBottom: 1 }, react_1.default.createElement(ink_1.Box, { marginLeft: 4 }, react_1.default.createElement(ink_1.Text, { color: "cyan", dimColor: true }, "\uD83D\uDD27 Tool result:")), react_1.default.createElement(ink_1.Box, { marginLeft: 6 }, react_1.default.createElement(ink_1.Text, { dimColor: true }, entry.content)))); default: return null; } }; return (react_1.default.createElement(ink_1.Box, { flexDirection: "column", padding: 1 }, react_1.default.createElement(ink_1.Box, { marginBottom: 1 }, react_1.default.createElement(ink_1.Text, { bold: true, color: "cyan" }, "\uD83E\uDD16 Grok CLI - Conversational AI Assistant")), react_1.default.createElement(ink_1.Box, { flexDirection: "column", marginBottom: 1 }, react_1.default.createElement(ink_1.Text, { dimColor: true }, "Type your request in natural language. Type 'exit' or Ctrl+C to quit.")), react_1.default.createElement(ink_1.Box, { flexDirection: "column", marginBottom: 1, ref: scrollRef }, conversation.slice(-20).map(renderEntry)), isProcessing && (react_1.default.createElement(ink_1.Box, { marginBottom: 1 }, react_1.default.createElement(ink_1.Text, { color: "yellow" }, "\uD83E\uDD14 Thinking..."))), react_1.default.createElement(ink_1.Box, null, react_1.default.createElement(ink_1.Text, { color: "blue" }, "\uD83D\uDCAC "), react_1.default.createElement(ink_1.Text, null, input, !isProcessing && react_1.default.createElement(ink_1.Text, { color: "white" }, "\u2588"))))); } exports.default = ConversationalApp; //# sourceMappingURL=ConversationalApp.js.map