Skip to content

Commit 61d1b8e

Browse files
bidahclaude
andcommitted
🐛 fix(x-bot): include images in saved chat messages + better poll error logging
- Add image parts to saved UIMessage so chat panel shows tweet images - Improve poll route error logging to show full error details (message, name, status, code, stack) instead of truncated "Error: ..." Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f10d004 commit 61d1b8e

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

‎apps/web/app/(app)/api/x-bot/generate/route.ts‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,20 @@ export async function POST(request: NextRequest) {
120120

121121
// Save messages to DB so chat panel shows history
122122
try {
123+
// Build user message parts: text + any attached images
124+
const userParts: UIMessage['parts'] = [{ type: 'text', text: appDescription }]
125+
if (imageUrls && imageUrls.length > 0) {
126+
for (const url of imageUrls) {
127+
userParts.push({ type: 'image', image: url } as any)
128+
}
129+
}
130+
123131
const userMessage: UIMessage = {
124132
id: `xbot-${tweetId}`,
125133
role: 'user',
126134
content: appDescription,
127135
createdAt: new Date(),
128-
parts: [{ type: 'text', text: appDescription }],
136+
parts: userParts,
129137
}
130138
const assistantMessage: UIMessage = {
131139
id: `xbot-${tweetId}-response`,
@@ -168,12 +176,20 @@ export async function POST(request: NextRequest) {
168176
// Save partial content + error to DB so user sees what happened
169177
if (fullContent) {
170178
try {
179+
// Build user message parts: text + any attached images
180+
const userParts: UIMessage['parts'] = [{ type: 'text', text: appDescription }]
181+
if (imageUrls && imageUrls.length > 0) {
182+
for (const url of imageUrls) {
183+
userParts.push({ type: 'image', image: url } as any)
184+
}
185+
}
186+
171187
const userMessage: UIMessage = {
172188
id: `xbot-${tweetId}`,
173189
role: 'user',
174190
content: appDescription,
175191
createdAt: new Date(),
176-
parts: [{ type: 'text', text: appDescription }],
192+
parts: userParts,
177193
}
178194
const assistantMessage: UIMessage = {
179195
id: `xbot-${tweetId}-response`,

‎apps/web/app/(app)/api/x-bot/poll/route.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,13 @@ export async function GET(request: NextRequest) {
158158

159159
return NextResponse.json({ ok: true, processed: results.length, results })
160160
} catch (error: any) {
161-
console.error('[X-Bot Poll] Error:', error)
161+
console.error('[X-Bot Poll] Error:', {
162+
message: error?.message,
163+
name: error?.name,
164+
status: error?.status,
165+
code: error?.code,
166+
stack: error?.stack?.substring(0, 500),
167+
})
162168
return NextResponse.json(
163169
{ error: error.message || 'Poll failed' },
164170
{ status: 500 }

0 commit comments

Comments
 (0)