Add brand visual style to page profile and logo palette to image prompts

Adds PageProfile.visualStyle (with migration), feeds it into every AI
prompt route, and samples a logo palette for image generation. Also
hardens Chrome focus handling and image copy in the ChatGPT driver.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Loma Bot Ops
2026-11-23 20:58:06 +07:00
parent dc6ee09a55
commit 4c93bf0a11
18 changed files with 166 additions and 49 deletions
+1 -1
View File
@@ -49,7 +49,7 @@ export async function POST(req: Request) {
// SUPERADMIN passes the role check for any id, so confirm the page exists.
const page = await prisma.page.findUnique({
where: { id: pageId },
select: { profile: { select: { business: true, audience: true, tone: true, avoid: true, cta: true } } },
select: { profile: { select: { business: true, audience: true, tone: true, visualStyle: true, avoid: true, cta: true } } },
});
if (!page) return NextResponse.json({ error: "ไม่พบเพจ" }, { status: 404 });
const profile = page.profile;
+1 -1
View File
@@ -48,7 +48,7 @@ export async function POST(req: Request) {
const page = await prisma.page.findUnique({
where: { id: pageId },
select: { profile: { select: { business: true, audience: true, tone: true, avoid: true, cta: true } } },
select: { profile: { select: { business: true, audience: true, tone: true, visualStyle: true, avoid: true, cta: true } } },
});
if (!page) return NextResponse.json({ error: "ไม่พบเพจ" }, { status: 404 });
+5 -3
View File
@@ -10,6 +10,7 @@ import { profilePrompt } from "@/lib/ai/shared";
import { assertImageQuota, generateImage } from "@/lib/ai/image";
import { IMAGE_PROMPT_MAX, IMAGE_SIZES, type ImageSizeKey } from "@/lib/ai/image-shared";
import { putBlob } from "@/lib/storage/blob";
import { logoPalettePrompt } from "@/lib/ai/brand-palette";
export const maxDuration = 360;
@@ -24,7 +25,7 @@ const SYSTEM = `You write prompts for an AI image generator. The images illustra
- Ask for no text, lettering, logos, watermarks or brand names inside the image (image models spell Thai badly; the caption carries the words).
- No identifiable real people, celebrities or copyrighted characters. If people appear, keep them generic.
- No before/after imagery and no exaggerated results (cures, guaranteed outcomes).
- Match the shop's tone and audience through the visual mood.`;
- Follow "สีและสไตล์ภาพของแบรนด์" exactly when supplied, especially its palette, medium, lighting and exclusions. Match the shop's tone and audience through the visual mood.`;
/**
* Two steps, both explicit button presses in the editor:
@@ -42,7 +43,7 @@ export async function POST(req: Request) {
// SUPERADMIN passes the role check for any id, so confirm the page exists.
const page = await prisma.page.findUnique({
where: { id: pageId },
select: { profile: { select: { business: true, audience: true, tone: true, avoid: true, cta: true } } },
select: { pictureUrl: true, profile: { select: { business: true, audience: true, tone: true, visualStyle: true, avoid: true, cta: true } } },
});
if (!page) return NextResponse.json({ error: "ไม่พบเพจ" }, { status: 404 });
@@ -51,12 +52,13 @@ export async function POST(req: Request) {
const description = str(body.description).trim();
if (!description) throw new UserFacingError("บอก AI ว่าอยากได้รูปแบบไหน");
if (description.length > 1000) throw new UserFacingError("คำอธิบายยาวเกิน 1,000 ตัวอักษร");
const logoPalette = await logoPalettePrompt(page.pictureUrl);
const result = await generateStructured({
kind: "image-prompt",
pageId,
userId: auth.user.id,
system: SYSTEM,
prompt: `${profilePrompt(page.profile)}\n\nWrite the image prompt for the idea below.\n\n<idea>\n${description}\n</idea>`,
prompt: `${profilePrompt(page.profile)}\n${logoPalette}\n\nWrite the image prompt for the idea below.\n\n<idea>\n${description}\n</idea>`,
schema: ImagePrompt,
effort: "low",
});
+1 -1
View File
@@ -38,7 +38,7 @@ export async function POST(req: Request) {
if (existing.pageId !== pageId || existing.topic !== topic || existing.targets.join() !== targets.join() || existing.plannedAt?.toISOString() !== plannedAt?.toISOString()) throw new UserFacingError("คำขอนี้ใช้กับงานอื่นแล้ว กรุณาสร้างคำขอใหม่");
return { job: existing, duplicate: true };
}
const page = await tx.page.findUnique({ where: { id: pageId }, select: { status: true, igUserId: true, profile: { select: { business: true, audience: true, tone: true, avoid: true, cta: true } } } });
const page = await tx.page.findUnique({ where: { id: pageId }, select: { status: true, igUserId: true, profile: { select: { business: true, audience: true, tone: true, visualStyle: true, avoid: true, cta: true } } } });
if (!page || page.status === "DISCONNECTED") throw new UserFacingError("ไม่พบเพจที่พร้อมสร้างโพสต์");
if (!page.profile?.business.trim()) throw new UserFacingError("ตั้งค่าโปรไฟล์ร้านก่อน เพื่อให้ AI สร้างโพสต์จากข้อมูลจริงของร้าน");
if (targets.includes("INSTAGRAM") && !page.igUserId) throw new UserFacingError("เพจนี้ยังไม่ได้ผูก Instagram");
+1 -1
View File
@@ -34,7 +34,7 @@ export async function POST(req: Request) {
if (!conversationId) throw new UserFacingError("เลือกแชทก่อน");
const profile = await prisma.pageProfile.findUnique({
where: { pageId },
select: { business: true, audience: true, tone: true, avoid: true, cta: true },
select: { business: true, audience: true, tone: true, visualStyle: true, avoid: true, cta: true },
});
const messages = await listMessages(await getPageCredentials(pageId), conversationId, 15);
if (!messages.some((m) => !m.fromPage)) throw new UserFacingError("ยังไม่มีข้อความจากลูกค้าในแชทนี้");
+1 -1
View File
@@ -52,7 +52,7 @@ export async function POST(req: Request) {
const page = await prisma.page.findUnique({
where: { id: pageId },
select: { profile: { select: { business: true, audience: true, tone: true, avoid: true, cta: true } } },
select: { profile: { select: { business: true, audience: true, tone: true, visualStyle: true, avoid: true, cta: true } } },
});
if (!page) return NextResponse.json({ error: "ไม่พบเพจ" }, { status: 404 });
@@ -12,6 +12,7 @@ const DraftProfile = z.object({
business: z.string().describe("What the shop sells, price ranges, delivery area and selling points seen in the posts"),
audience: z.string().describe("Who the posts speak to"),
tone: z.string().describe("How the page writes: formality, how it addresses customers, emoji use"),
visualStyle: z.string().describe("Brand colours and visual direction explicitly mentioned in posts; otherwise empty"),
avoid: z.string().describe("Only things the posts clearly avoid; otherwise empty"),
cta: z.string().describe("How the posts ask customers to buy or get in touch"),
});