Commit acd7d896 authored by Mahmoud Aglan's avatar Mahmoud Aglan

GoCommitinChat

parent 8bb1768b
......@@ -256,6 +256,19 @@ export default function ChatView({ chatId }) {
setShowCommitModal(true);
}
function openCommitAllForMessage(messageContent) {
const blocks = extractCodeBlocks(messageContent);
if (!blocks.length) return;
const map = new Map();
blocks.forEach((b) => map.set(b.file_path, b));
const deduped = Array.from(map.values());
setCommitFiles(deduped);
setCommitBranch(selectedBranch || "main");
setCommitMessage(`Update ${deduped.length} file${deduped.length > 1 ? "s" : ""} from Son of Anton`);
setCommitResult(null);
setShowCommitModal(true);
}
async function executeCommit() {
if (!commitFiles.length || committing) return;
setCommitting(true);
......@@ -288,6 +301,7 @@ export default function ChatView({ chatId }) {
<MessageBubble
key={m.id} message={m} token={state.token}
onCommitFile={hasLinkedRepo ? openCommitSingle : undefined}
onCommitAll={hasLinkedRepo ? openCommitAllForMessage : undefined}
/>
))}
{streaming && (streamData.thinking || streamData.text) && (
......@@ -295,6 +309,7 @@ export default function ChatView({ chatId }) {
message={{ id: "streaming", role: "assistant", content: streamData.text, thinking_content: streamData.thinking || null, attachments: [] }}
isStreaming isThinking={streamData.isThinking} token={state.token}
onCommitFile={hasLinkedRepo ? openCommitSingle : undefined}
onCommitAll={hasLinkedRepo ? openCommitAllForMessage : undefined}
/>
)}
{streaming && !streamData.text && !streamData.thinking && (
......
......@@ -5,14 +5,14 @@ import CodeBlock from "./CodeBlock";
import { getAttachmentUrl } from "../api";
import {
User, Flame, ChevronDown, ChevronRight, Brain, Copy, Check,
Image, Film, FileText, ExternalLink,
Image, Film, FileText, ExternalLink, GitCommitHorizontal,
} from "lucide-react";
const FILE_TYPE_ICONS = {
image: Image, video: Film, document: FileText, text: FileText,
};
const MessageBubble = React.memo(function MessageBubble({ message, isStreaming, isThinking, token, onCommitFile }) {
const MessageBubble = React.memo(function MessageBubble({ message, isStreaming, isThinking, token, onCommitFile, onCommitAll }) {
const { role, content, thinking_content, input_tokens, output_tokens, attachments } = message;
const isUser = role === "user";
const [showThinking, setShowThinking] = useState(false);
......@@ -139,6 +139,11 @@ const MessageBubble = React.memo(function MessageBubble({ message, isStreaming,
{copied ? <Check size={11} className="text-anton-success" /> : <Copy size={11} />}
{copied ? "Copied" : "Copy"}
</button>
{onCommitAll && /```\S*:\S+/.test(content) && (
<button onClick={() => onCommitAll(content)} className="flex items-center gap-1 text-[11px] text-green-500/70 hover:text-green-400 transition">
<GitCommitHorizontal size={11} /> Commit All
</button>
)}
{(input_tokens > 0 || output_tokens > 0) && (
<span className="text-[11px] text-anton-muted">
{input_tokens?.toLocaleString()}↓ / {output_tokens?.toLocaleString()}↑ tokens
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment