Add website link to page profile so the AI can read the shop site

Adds PageProfile.website (with migration). Codex runs without network, so
the profile draft route fetches the site server-side (public hosts only,
redirect-checked, size-capped, cached) and passes its text as
<shop_website>. Other prompts receive the URL via the shop profile.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Loma Bot Ops
2026-11-23 21:20:35 +07:00
parent b592cd43f4
commit 5f8f0c9159
16 changed files with 184 additions and 35 deletions
+33 -15
View File
@@ -8,7 +8,7 @@ import { formatDateTime, Notice } from "./ui";
import { useToast } from "./Toast";
import { PROFILE_FIELDS, type ShopProfile } from "@/lib/ai/shared";
const EMPTY: ShopProfile = { business: "", audience: "", tone: "", visualStyle: "", avoid: "", cta: "" };
const EMPTY: ShopProfile = { business: "", audience: "", tone: "", visualStyle: "", avoid: "", cta: "", website: "" };
export function ProfileForm({
pageId,
@@ -29,7 +29,7 @@ export function ProfileForm({
const [busy, setBusy] = useState<"save" | "draft" | null>(null);
const [error, setError] = useState<string | null>(null);
async function request(path: string, method: string, body?: ShopProfile) {
async function request(path: string, method: string, body?: unknown) {
const res = await fetch(withBase(path), { method, headers: { "Content-Type": "application/json" }, body: body ? JSON.stringify(body) : undefined }).catch(() => null);
const json = res ? await res.json().catch(() => ({})) : {};
return { ok: Boolean(res?.ok), json };
@@ -49,7 +49,7 @@ export function ProfileForm({
async function draft() {
setBusy("draft");
setError(null);
const { ok, json } = await request(`/api/pages/${pageId}/profile/draft`, "POST");
const { ok, json } = await request(`/api/pages/${pageId}/profile/draft`, "POST", { website: values.website });
setBusy(null);
if (!ok) return setError(json.error ?? "AI ร่างโปรไฟล์ไม่สำเร็จ");
const drafted = json.profile as ShopProfile;
@@ -59,7 +59,11 @@ export function ProfileForm({
for (const f of PROFILE_FIELDS) if (drafted[f.key]) next[f.key] = drafted[f.key];
return next;
});
toast.show(`AI ร่างจาก ${json.postCount} โพสต์แล้ว — ตรวจแล้วกดบันทึก`, "warn");
const source = json.websiteRead ? `${json.postCount} โพสต์และเว็บไซต์` : `${json.postCount} โพสต์`;
toast.show(
json.websiteGiven && !json.websiteRead ? `AI ร่างจาก ${source}แล้ว แต่อ่านเว็บไซต์ไม่ได้ — ตรวจแล้วกดบันทึก` : `AI ร่างจาก ${source}แล้ว — ตรวจแล้วกดบันทึก`,
"warn",
);
}
return (
@@ -73,7 +77,7 @@ export function ProfileForm({
{canEdit && canDraft && (
<div className="flex flex-wrap items-center gap-3 rounded-[12px] border border-line bg-board p-3.5">
<Icon name="sparkle" size={18} />
<p className="flex-1 min-w-[220px] text-[13px] text-ink-2">ยังไม่รู้จะเขียนอะไร? ให้ AI อ่านโพสต์ 90 วันล่าสุดของเพจแล้วร่างให้ก่อน</p>
<p className="flex-1 min-w-[220px] text-[13px] text-ink-2">ยังไม่รู้จะเขียนอะไร? ให้ AI อ่านโพสต์ 90 วันล่าสุดของเพจ (และเว็บไซต์ถ้ากรอกลิงก์ไว้) แล้วร่างให้ก่อน</p>
<button type="button" className="btn btn-ghost btn-sm" disabled={busy !== null} onClick={draft}>
{busy === "draft" ? "AI กำลังอ่านโพสต์…" : "ให้ AI ร่างจากโพสต์เดิม"}
</button>
@@ -87,16 +91,30 @@ export function ProfileForm({
{f.key === "business" && <span className="text-danger ml-1">*</span>}
<span className="ml-auto num text-ink-4">{values[f.key].length.toLocaleString("th-TH")}/{f.max.toLocaleString("th-TH")}</span>
</span>
<textarea
className="textarea"
rows={f.rows}
maxLength={f.max}
required={f.key === "business"}
disabled={!canEdit}
value={values[f.key]}
onChange={(e) => setValues({ ...values, [f.key]: e.target.value })}
placeholder={f.hint}
/>
{f.key === "website" ? (
<input
className="input"
type="text"
inputMode="url"
autoComplete="off"
maxLength={f.max}
disabled={!canEdit}
value={values.website}
onChange={(e) => setValues({ ...values, website: e.target.value })}
placeholder={f.hint}
/>
) : (
<textarea
className="textarea"
rows={f.rows}
maxLength={f.max}
required={f.key === "business"}
disabled={!canEdit}
value={values[f.key]}
onChange={(e) => setValues({ ...values, [f.key]: e.target.value })}
placeholder={f.hint}
/>
)}
</label>
))}