Skip to content

🎥 Make videos programmatically with React

fix(tp2mg): include attached images in conversation context

ASchwadaca039e91996
diff --git a/packages/template-prompt-to-motion-graphics/src/app/api/generate/route.ts b/packages/template-prompt-to-motion-graphics/src/app/api/generate/route.ts
index 6918fc64c8..679a5c78e7 100644
--- a/packages/template-prompt-to-motion-graphics/src/app/api/generate/route.ts
+++ b/packages/template-prompt-to-motion-graphics/src/app/api/generate/route.ts
@@ -249,6 +249,8 @@ function applyEdits(
interface ConversationContextMessage {
role: "user" | "assistant";
content: string;
+ /** For user messages, attached images as base64 data URLs */
+ attachedImages?: string[];
}
interface ErrorCorrectionContext {
@@ -391,7 +393,13 @@ export async function POST(req: Request) {
conversationContext =
"\n\n## RECENT CONVERSATION:\n" +
contextMessages
- .map((m) => `${m.role.toUpperCase()}: ${m.content}`)
+ .map((m) => {
+ const imageNote =
+ m.attachedImages && m.attachedImages.length > 0
+ ? ` [with ${m.attachedImages.length} attached image${m.attachedImages.length > 1 ? "s" : ""}]`
+ : "";
+ return `${m.role.toUpperCase()}: ${m.content}${imageNote}`;
+ })
.join("\n");
}
diff --git a/packages/template-prompt-to-motion-graphics/src/hooks/useConversationState.ts b/packages/template-prompt-to-motion-graphics/src/hooks/useConversationState.ts
index 73de894ff2..94339acbf0 100644
--- a/packages/template-prompt-to-motion-graphics/src/hooks/useConversationState.ts
+++ b/packages/template-prompt-to-motion-graphics/src/hooks/useConversationState.ts
@@ -123,6 +123,10 @@ export function useConversationState() {
.map((m) => ({
role: m.role as "user" | "assistant",
content: m.role === "user" ? m.content : "[Generated Code]",
+ // Include attached images for user messages so the AI remembers what was shared
+ ...(m.role === "user" && m.attachedImages && m.attachedImages.length > 0
+ ? { attachedImages: m.attachedImages }
+ : {}),
}));
}, [state.messages]);
diff --git a/packages/template-prompt-to-motion-graphics/src/types/conversation.ts b/packages/template-prompt-to-motion-graphics/src/types/conversation.ts
index 814bd9fcf5..38a61e69f2 100644
--- a/packages/template-prompt-to-motion-graphics/src/types/conversation.ts
+++ b/packages/template-prompt-to-motion-graphics/src/types/conversation.ts
@@ -49,6 +49,8 @@ export interface ConversationState {
export interface ConversationContextMessage {
role: "user" | "assistant";
content: string;
+ /** For user messages, attached images as base64 data URLs */
+ attachedImages?: string[];
}
export interface ErrorCorrectionContext {