diff --git a/package-lock.json b/package-lock.json
index b522632..72f3c79 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "codepilot",
- "version": "0.17.1",
+ "version": "0.17.2",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "codepilot",
- "version": "0.17.1",
+ "version": "0.17.2",
"dependencies": {
"@ai-sdk/anthropic": "^3.0.47",
"@ai-sdk/google": "^3.0.31",
diff --git a/package.json b/package.json
index d49074b..8695091 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "codepilot",
- "version": "0.17.1",
+ "version": "0.17.2",
"private": true,
"author": {
"name": "op7418",
diff --git a/src/app/api/chat/messages/route.ts b/src/app/api/chat/messages/route.ts
index 9f9c0ff..7057c77 100644
--- a/src/app/api/chat/messages/route.ts
+++ b/src/app/api/chat/messages/route.ts
@@ -1,5 +1,5 @@
import { NextRequest, NextResponse } from 'next/server';
-import { addMessage, getSession } from '@/lib/db';
+import { addMessage, updateMessageContent, getSession } from '@/lib/db';
export const runtime = 'nodejs';
@@ -37,3 +37,31 @@ export async function POST(request: NextRequest) {
return NextResponse.json({ error: msg }, { status: 500 });
}
}
+
+/**
+ * PUT /api/chat/messages
+ * Update the content of an existing message.
+ * Used to replace image-gen-request with image-gen-result after generation.
+ */
+export async function PUT(request: NextRequest) {
+ try {
+ const body = await request.json();
+ const { message_id, content } = body as {
+ message_id: string;
+ content: string;
+ };
+
+ if (!message_id || !content) {
+ return NextResponse.json(
+ { error: 'message_id and content are required' },
+ { status: 400 },
+ );
+ }
+
+ updateMessageContent(message_id, content);
+ return NextResponse.json({ ok: true });
+ } catch (error) {
+ const msg = error instanceof Error ? error.message : 'Failed to update message';
+ return NextResponse.json({ error: msg }, { status: 500 });
+ }
+}
diff --git a/src/components/chat/ImageGenConfirmation.tsx b/src/components/chat/ImageGenConfirmation.tsx
index 20b1c9a..ebeb9e9 100644
--- a/src/components/chat/ImageGenConfirmation.tsx
+++ b/src/components/chat/ImageGenConfirmation.tsx
@@ -17,6 +17,7 @@ const ASPECT_RATIOS = [
const RESOLUTIONS = ['1K', '2K', '4K'] as const;
interface ImageGenConfirmationProps {
+ messageId?: string;
initialPrompt: string;
initialAspectRatio: string;
initialResolution: string;
@@ -32,6 +33,7 @@ function storageKey(prompt: string, sessionId?: string): string {
}
export function ImageGenConfirmation({
+ messageId,
initialPrompt,
initialAspectRatio,
initialResolution,
@@ -140,6 +142,28 @@ export function ImageGenConfirmation({
// storage full
}
+ // Persist result to DB by replacing image-gen-request with image-gen-result
+ if (messageId) {
+ const resultBlock = JSON.stringify({
+ status: 'completed',
+ prompt,
+ aspectRatio,
+ resolution,
+ images: genResult.images.map(img => ({
+ mimeType: img.mimeType,
+ localPath: img.localPath,
+ })),
+ });
+ fetch('/api/chat/messages', {
+ method: 'PUT',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({
+ message_id: messageId,
+ content: '```image-gen-result\n' + resultBlock + '\n```',
+ }),
+ }).catch(() => {});
+ }
+
// Defer event dispatch so React commits setResult/setStatus before
// ChatView's handler calls sendMessage and triggers a re-render
setTimeout(() => {
diff --git a/src/components/chat/MessageItem.tsx b/src/components/chat/MessageItem.tsx
index 808bba4..11cc253 100644
--- a/src/components/chat/MessageItem.tsx
+++ b/src/components/chat/MessageItem.tsx
@@ -491,6 +491,7 @@ export function MessageItem({ message }: MessageItemProps) {
<>
{parsed.beforeText && {parsed.beforeText}}