UNPKG

capsule-ai-cli

Version:

The AI Model Orchestrator - Intelligent multi-model workflows with device-locked licensing

151 lines • 5.86 kB
import React, { useState, useEffect } from 'react'; import { Text, Box, useApp, useStdin } from 'ink'; export var Mode; (function (Mode) { Mode["CHAT"] = "chat"; Mode["AGENT"] = "agent"; Mode["PLAN"] = "plan"; Mode["FUSION"] = "fusion"; })(Mode || (Mode = {})); const modeColors = { [Mode.CHAT]: 'cyan', [Mode.AGENT]: 'yellow', [Mode.PLAN]: 'blue', [Mode.FUSION]: 'magenta' }; const modeIcons = { [Mode.CHAT]: 'šŸ’¬', [Mode.AGENT]: 'šŸ¤–', [Mode.PLAN]: 'šŸ“‹', [Mode.FUSION]: '⚔' }; export const SimpleInteractiveCLI = ({ model, provider }) => { const [mode, setMode] = useState(Mode.CHAT); const [input, setInput] = useState(''); const [messages, setMessages] = useState([]); const [isProcessing, setIsProcessing] = useState(false); const { exit } = useApp(); const { stdin, setRawMode } = useStdin(); useEffect(() => { if (setRawMode) setRawMode(true); const handleData = (data) => { const key = data.toString(); if (key === '\x03') { exit(); return; } if (key === '\r' || key === '\n') { handleSubmit(); return; } if (key === '\x7f' || key === '\b') { setInput(prev => prev.slice(0, -1)); return; } if (key === '\t') { const modes = Object.values(Mode); const currentIndex = modes.indexOf(mode); const nextIndex = (currentIndex + 1) % modes.length; setMode(modes[nextIndex]); return; } if (key.length === 1 && key >= ' ' && key <= '~') { setInput(prev => prev + key); } }; stdin?.on('data', handleData); return () => { stdin?.off('data', handleData); if (setRawMode) setRawMode(false); }; }, [mode, input, stdin, setRawMode, exit]); const handleSubmit = async () => { const value = input.trim(); if (!value) return; if (value.startsWith('/')) { const command = value.substring(1).toLowerCase(); if (command === 'exit') { exit(); return; } if (command === 'clear') { setMessages([]); setInput(''); return; } if (command === 'help') { setMessages([...messages, { role: 'assistant', content: 'Commands: /clear, /exit, /help\nTab to switch modes, Ctrl+C to exit', mode }]); setInput(''); return; } } const userMessage = { role: 'user', content: value, mode }; setMessages([...messages, userMessage]); setInput(''); setIsProcessing(true); setTimeout(() => { const response = getResponseForMode(value, mode); setMessages(prev => [...prev, { role: 'assistant', content: response, mode }]); setIsProcessing(false); }, 1000); }; const getResponseForMode = (input, mode) => { switch (mode) { case Mode.AGENT: return `Task analyzed: "${input}"\n1. Breaking down requirements\n2. Planning execution steps\n3. Ready to proceed autonomously`; case Mode.PLAN: return `Strategic plan for: "${input}"\n• Architecture: Microservices\n• Timeline: 2-3 weeks\n• Resources: 3 developers`; case Mode.FUSION: return `Orchestrating models for: "${input}"\n→ GPT-4: Initial analysis\n→ Claude: Implementation\n→ Gemini: Optimization`; default: return `I understand you want help with: "${input}"\n[Demo response - real AI integration coming soon]`; } }; return (React.createElement(Box, { flexDirection: "column" }, React.createElement(Box, { flexDirection: "column", marginBottom: 1 }, messages.slice(-10).map((msg, idx) => (React.createElement(Box, { key: idx, marginBottom: 1 }, msg.role === 'user' ? (React.createElement(Text, null, React.createElement(Text, { color: modeColors[msg.mode], bold: true }, modeIcons[msg.mode], " You (", msg.mode, "):"), React.createElement(Text, null, " ", msg.content))) : (React.createElement(Box, { flexDirection: "column" }, React.createElement(Text, { color: "green", bold: true }, "\uD83E\uDD16 Capsule AI:"), React.createElement(Text, { dimColor: true }, msg.content)))))), isProcessing && (React.createElement(Text, { color: "yellow" }, "\u26A1 Processing..."))), React.createElement(Box, { marginBottom: 1 }, React.createElement(Text, { dimColor: true }, "\u25B6\u25B6 ", mode, " mode on ", React.createElement(Text, { color: "gray" }, "(tab to cycle)"))), React.createElement(Box, null, React.createElement(Text, { color: modeColors[mode], bold: true }, modeIcons[mode], " ", mode, ":"), React.createElement(Text, null, " ", input), React.createElement(Text, { dimColor: true }, "\u258A")))); }; export default SimpleInteractiveCLI; //# sourceMappingURL=SimpleInteractiveCLI.js.map