UNPKG

together-code

Version:

AI-powered coding assistant that plans, then builds

95 lines (94 loc) 4 kB
import React from 'react'; import { Box, Text } from 'ink'; const StepResult = ({ step, content, files, tokens, duration }) => { // Parse the structured response const parseStructuredContent = (content) => { const sections = { summary: '', changes: [], code: '', notes: '' }; const lines = content.split('\n'); let currentSection = ''; let buffer = []; for (const line of lines) { if (line.startsWith('## Summary')) { currentSection = 'summary'; continue; } else if (line.startsWith('## Changes Made')) { if (currentSection === 'summary') { sections.summary = buffer.join('\n').trim(); } currentSection = 'changes'; buffer = []; continue; } else if (line.startsWith('## Code')) { if (currentSection === 'changes') { sections.changes = buffer.filter(l => l.trim().startsWith('-')).map(l => l.trim().substring(1).trim()); } currentSection = 'code'; buffer = []; continue; } else if (line.startsWith('## Notes')) { if (currentSection === 'code') { sections.code = buffer.join('\n').trim(); } currentSection = 'notes'; buffer = []; continue; } else { buffer.push(line); } } // Handle last section if (currentSection === 'notes') { sections.notes = buffer.join('\n').trim(); } else if (currentSection === 'code') { sections.code = buffer.join('\n').trim(); } else if (currentSection === 'changes') { sections.changes = buffer.filter(l => l.trim().startsWith('-')).map(l => l.trim().substring(1).trim()); } else if (currentSection === 'summary') { sections.summary = buffer.join('\n').trim(); } return sections; }; const sections = parseStructuredContent(content); return (React.createElement(Box, { flexDirection: "column", marginBottom: 1 }, React.createElement(Box, { marginBottom: 1 }, React.createElement(Text, { color: "green", bold: true }, "\u2705 ", step.title), duration && (React.createElement(Text, { color: "gray" }, " (", duration, "s)")), tokens && (React.createElement(Text, { color: "gray" }, " \u2022 ", tokens, " tokens"))), sections.summary && (React.createElement(Box, { marginBottom: 1, paddingLeft: 2 }, React.createElement(Text, { color: "white" }, sections.summary))), sections.changes.length > 0 && (React.createElement(Box, { flexDirection: "column", marginBottom: 1, paddingLeft: 2 }, React.createElement(Text, { color: "blue", bold: true }, "Changes:"), sections.changes.map((change, index) => (React.createElement(Text, { key: index, color: "gray" }, " \u2022 ", change))))), files && files.length > 0 && (React.createElement(Box, { flexDirection: "column", marginBottom: 1, paddingLeft: 2 }, React.createElement(Text, { color: "green", bold: true }, "Files created:"), files.map((file, index) => (React.createElement(Text, { key: index, color: "gray" }, " \uD83D\uDCC4 ", file.path))))), sections.notes && (React.createElement(Box, { marginBottom: 1, paddingLeft: 2 }, React.createElement(Text, { color: "yellow" }, "\uD83D\uDCA1 ", sections.notes))))); }; export default StepResult;