IKEA assembly, step by step: animated, manual-style 3D guides. Scan any paper manual with Together AI.
TypeScript
Know what every IKEA name is, and say names right
Yousseffb0d4460e9d9
diff --git a/scripts/voice/names.ts b/scripts/voice/names.tsindex c67109c..526ae90 100644--- a/scripts/voice/names.ts+++ b/scripts/voice/names.ts@@ -5,6 +5,7 @@** npm run voice:names spell every catalog name that has no spelling yet* npm run voice:names -- --check say a sample both ways and score what Whisper hears+ * npm run voice:names -- --prune keep a spelling only where Whisper hears the name clearly better with it** Spellings live in src/lib/voice/names.ts and are applied only when a line is* rendered (src/lib/voice/tts.ts), so clip names and the on-screen text don't change.@@ -30,7 +31,28 @@ const PROMPT = `You write how IKEA product names are said out loud in an AmericaWrite each in IPA using ONLY these symbols: ˈ ˌ a b d e f h i j k l m n p s t u v w z æ ð ŋ ɑ ɐ ɔ ə ɛ ɜ ɪ ʊ ʌ ɡ ɹ ʃ ʒ θ ʤ ʧ ɚ ː and the diphthongs A (as in day), I (as in my), O (as in go), W (as in now), Y (as in boy). Put ˈ before the stressed syllable.Reply with JSON only: {"NAME": "ipa", ...} for every name given.`;-async function ask(list: string[]) {+// models often write plain letters for these sounds; Kokoro only knows the IPA ones+const PLAIN: Record<string, string> = { g: "ɡ", r: "ɹ", c: "k", x: "ks", o: "O", y: "i", "ʏ": "ɪ", "ʉ": "u", "ø": "ɜ", "œ": "ɜ", "ɒ": "ɑ", q: "k", "ʁ": "ɹ", "ɾ": "ɹ", "ɐ": "ɐ" };+function tidy(raw: string, name: string) {+ let t = raw.trim().replace(/^\/|\/$/g, "").replace(/[.'’]/g, "");+ t = [...t].map((ch) => PLAIN[ch] ?? ch).join("");+ // one word stays one word, so the voice doesn't pause inside a name+ if (!name.includes(" ")) t = t.replace(/\s+/g, "");+ // a stress mark in front makes Kokoro say a sound before the name+ return t.replace(/^[ˈˌ]+/, "");+}++async function ask(list: string[]): Promise<Record<string, string>> {+ for (let tries = 0; ; tries++) {+ try {+ return await askOnce(list);+ } catch (e) {+ if (tries >= 2) throw e;+ }+ }+}++async function askOnce(list: string[]) {const r = await fetch("https://api.together.xyz/v1/chat/completions", {method: "POST",headers: { Authorization: `Bearer ${key}`, "Content-Type": "application/json" },@@ -38,7 +60,7 @@ async function ask(list: string[]) {model: "openai/gpt-oss-120b",reasoning_effort: "medium",response_format: { type: "json_object" },- max_tokens: 6000,+ max_tokens: 8000,temperature: 0.2,messages: [{ role: "system", content: PROMPT },@@ -70,6 +92,29 @@ function sim(a: string, b: string) {async function main() {const all = [...new Set(PRODUCTS.map((p) => spokenName(p.name)))];+ if (args.includes("--prune")) {+ const queue = all.filter((n) => names[n]);+ let kept = 0, dropped = 0;+ const one = async (n: string) => {+ const line = `Your ${n} is built.`;+ const [a, b] = await Promise.all([speak(line, key!), speak(forTTS(line), key!)]);+ const [ha, hb] = await Promise.all([transcribe(a), transcribe(b)]);+ const word = (h: string) => fold(h.replace(/^\W*your\s+/i, "").replace(/\s+is built.*$/i, ""));+ const sa = sim(fold(n), word(ha)), sb = sim(fold(n), word(hb));+ if (sb >= sa + 0.15) kept++;+ else {+ delete names[n];+ dropped++;+ }+ };+ const work = [...queue];+ await Promise.all(Array.from({ length: 6 }, async () => {+ for (let n = work.shift(); n; n = work.shift()) await one(n).catch(() => {});+ }));+ save();+ console.log(`kept ${kept} spellings, dropped ${dropped}`);+ return;+ }if (args.includes("--check")) {const sample = all.filter((n) => names[n]).slice(0, Number(args[args.indexOf("--check") + 1]) || 30);let plain = 0, spelled = 0;@@ -88,16 +133,16 @@ async function main() {}const todo = all.filter((n) => !names[n]);console.log(`${all.length} names, ${todo.length} to spell`);- for (let i = 0; i < todo.length; i += 60) {- const got = await ask(todo.slice(i, i + 60).map((n) => n.toUpperCase()));+ for (let i = 0; i < todo.length; i += 40) {+ const got = await ask(todo.slice(i, i + 40).map((n) => n.toUpperCase()));for (const [k, v] of Object.entries(got)) {const n = todo.find((x) => x.toUpperCase() === k.toUpperCase());- const ipa = String(v).trim().replace(/^\/|\/$/g, "");+ const ipa = tidy(String(v), n ?? k);if (n && OK.test(ipa)) names[n] = ipa;else if (n) console.log(` skipped ${n}: ${ipa}`);}save();- console.log(`${Math.min(i + 60, todo.length)}/${todo.length}`);+ console.log(`${Math.min(i + 40, todo.length)}/${todo.length}`);}}diff --git a/src/app/api/guide/route.ts b/src/app/api/guide/route.tsindex 5003190..72d9fd5 100644--- a/src/app/api/guide/route.ts+++ b/src/app/api/guide/route.ts@@ -2,6 +2,7 @@ import { PRODUCTS, toSpec } from "@/lib/catalog";import { categoryOf, fold, guessSpec, matchCatalog, searchCatalog } from "@/lib/search";import { parseSpec, SPEC_PROMPT } from "@/lib/spec";import { draft, type Draft } from "@/lib/draft";+import { ikeaType } from "@/lib/ikea";import { chatText, extractJson, hasKey, ipOf, MODELS, rateLimited, TogetherError, userKey } from "@/lib/together";import type { ProductSpec } from "@/lib/types";@@ -19,15 +20,22 @@ export async function POST(req: Request) {const cached = cache.get(key);if (cached) return Response.json({ spec: cached.spec, via: "ai", model: cached.model });- const suggestions = () => [...new Set(searchCatalog(q, 8).filter((h) => h.score >= 40).map((h) => h.entry.name))].slice(0, 4);+ const suggestions = (more: string[] = []) => [...new Set([...more, ...searchCatalog(q, 8).filter((h) => h.score >= 40).map((h) => h.entry.name)])].filter((x) => fold(x) !== key).slice(0, 4);++ // IKEA's own word for what this is: steers the draft, and says plainly when it's something we can't draw+ const type = await ikeaType(q);+ if (type && !drawable(type)) return Response.json({ found: false, ikea: type, suggestions: suggestions(), via: "ikea" });+ // one spelling per name, so the shared draft cache isn't split by upper and lower case+ const said = q.replace(/\s+/g, " ").toUpperCase();+ const hint = type ? `${said} (IKEA sells this as: ${type})` : said;const own = userKey(req);if (hasKey() || own) {if (rateLimited(ipOf(req) + ":guide", 12)) return Response.json({ error: "slow down" }, { status: 429 });try {- const d = await draftWith(own, key, q);+ const d = await draftWith(own, type ? `${key}|${fold(type)}` : key, hint);if (d && "found" in d) {- return Response.json({ found: false, suggestions: d.suggestions.concat(suggestions()).slice(0, 4), via: "ai" });+ return Response.json({ found: false, suggestions: suggestions(d.suggestions), via: "ai" });}if (d) {const { spec, model } = d;@@ -44,14 +52,20 @@ export async function POST(req: Request) {}}- const g = guessSpec(q);- if (g && categoryOf(q)) return Response.json({ spec: g, via: "guess" });- return Response.json({ found: false, suggestions: suggestions(), via: hasKey() || own ? "ai" : "offline" });+ const g = guessSpec(type ? `${q} ${type}` : q);+ if (g && categoryOf(type ? `${q} ${type}` : q)) return Response.json({ spec: { ...g, variant: type ?? g.variant }, via: "guess" });+ return Response.json({ found: false, ikea: type ?? undefined, suggestions: suggestions(), via: hasKey() || own ? "ai" : "offline" });+}++/** Types the plan generator can draw believably; office chairs, corner sofas, lamps and the like it can't yet. */+function drawable(type: string) {+ if (/office|swivel|gaming chair|corner|chaise|sectional|sliding door|cot\b|crib|bunk|loft|lamp|light|mattress|frame\b|mirror|rug|cushion|curtain|plant|pot\b|rail|hook/i.test(type)) return false;+ return categoryOf(type) !== null;}/** The shared, cached draft on the server key; a visitor's own key is never cached under someone else's name. */async function draftWith(own: string | undefined, key: string, q: string): Promise<Draft | null> {- if (!own && hasKey()) return draft(key);+ if (!own && hasKey()) return draft(key, q);const { text, model } = await chatText({key: own,models: MODELS.text,diff --git a/src/app/build/[slug]/opengraph-image.tsx b/src/app/build/[slug]/opengraph-image.tsxindex d2e9e26..66dba86 100644--- a/src/app/build/[slug]/opengraph-image.tsx+++ b/src/app/build/[slug]/opengraph-image.tsx@@ -4,6 +4,9 @@ import { KIND_LABELS } from "@/lib/products";import { kindOf } from "@/lib/search";import { OG_SIZE, drawing, guideCard } from "@/lib/og/card";+/** A drawing to fall back on for each archetype. */+const BY_ARCH: Record<string, string> = { shelf: "bookcase", drawers: "chest", table: "dining", bed: "bed", cabinet: "cabinet", seat: "chair", sofa: "sofa", custom: "cabinet" };+export const alt = "An IKEA assembly guide on Bygga, step by step in 3D";export const size = OG_SIZE;export const contentType = "image/png";@@ -18,7 +21,7 @@ export default async function Image({ params }: { params: Promise<{ slug: stringreturn guideCard({ name, variant: "Assembly, step by step", steps: null, art: await drawing(kind ? `kind-${kind}` : "kind-bookcase") });}const kind = kindOf(`${spec.category} ${spec.variant}`) ?? KIND_LABELS[0].kind;- const art = (await drawing(slug)) ?? (await drawing(`kind-${kind}`));+ const art = (await drawing(slug)) ?? (await drawing(`kind-${kind}`)) ?? (await drawing(`kind-${BY_ARCH[spec.archetype]}`));let steps: number | null = null;try {steps = buildPlan(spec).steps.length;diff --git a/src/app/build/[slug]/twitter-image.tsx b/src/app/build/[slug]/twitter-image.tsxindex d2e9e26..66dba86 100644--- a/src/app/build/[slug]/twitter-image.tsx+++ b/src/app/build/[slug]/twitter-image.tsx@@ -4,6 +4,9 @@ import { KIND_LABELS } from "@/lib/products";import { kindOf } from "@/lib/search";import { OG_SIZE, drawing, guideCard } from "@/lib/og/card";+/** A drawing to fall back on for each archetype. */+const BY_ARCH: Record<string, string> = { shelf: "bookcase", drawers: "chest", table: "dining", bed: "bed", cabinet: "cabinet", seat: "chair", sofa: "sofa", custom: "cabinet" };+export const alt = "An IKEA assembly guide on Bygga, step by step in 3D";export const size = OG_SIZE;export const contentType = "image/png";@@ -18,7 +21,7 @@ export default async function Image({ params }: { params: Promise<{ slug: stringreturn guideCard({ name, variant: "Assembly, step by step", steps: null, art: await drawing(kind ? `kind-${kind}` : "kind-bookcase") });}const kind = kindOf(`${spec.category} ${spec.variant}`) ?? KIND_LABELS[0].kind;- const art = (await drawing(slug)) ?? (await drawing(`kind-${kind}`));+ const art = (await drawing(slug)) ?? (await drawing(`kind-${kind}`)) ?? (await drawing(`kind-${BY_ARCH[spec.archetype]}`));let steps: number | null = null;try {steps = buildPlan(spec).steps.length;diff --git a/src/app/dev/og/list/route.ts b/src/app/dev/og/list/route.tsindex 6bda01a..11724f7 100644--- a/src/app/dev/og/list/route.ts+++ b/src/app/dev/og/list/route.ts@@ -1,9 +1,9 @@import { PRODUCTS } from "@/lib/catalog";-import { KIND_LABELS } from "@/lib/products";+import { KIND_ARCH } from "@/lib/products";/** Dev only: what scripts/og/render.mjs should draw: every kind, then every catalog product. */export async function GET() {if (process.env.NODE_ENV === "production") return new Response(null, { status: 404 });const picks = PRODUCTS.map((p) => ({ slug: p.slug }));- return Response.json([...KIND_LABELS.map((k) => ({ kind: k.kind })), ...picks]);+ return Response.json([...Object.keys(KIND_ARCH).map((kind) => ({ kind })), ...picks]);}diff --git a/src/components/guide/GuideApp.tsx b/src/components/guide/GuideApp.tsxindex 6d123a3..6e25119 100644--- a/src/components/guide/GuideApp.tsx+++ b/src/components/guide/GuideApp.tsx@@ -71,7 +71,7 @@ export default function GuideApp({ slug, query, step, kind }: { slug: string; quuseEffect(() => {if (mounted && local?.slug && local.slug !== slug) router.replace(`/build/${local.slug}` + (step ? `?step=${step}` : ""));}, [mounted, local, slug, step, router]);- const [fetched, setFetched] = useState<{ slug: string; spec?: ProductSpec; via?: Via; suggestions?: string[]; error?: boolean } | null>(null);+ const [fetched, setFetched] = useState<{ slug: string; spec?: ProductSpec; via?: Via; suggestions?: string[]; ikea?: string; error?: boolean } | null>(null);const [ai, setAi] = useState(false);const result = fetched?.slug === slug ? fetched : null;const spec = initial ?? cached ?? result?.spec ?? null;@@ -107,7 +107,7 @@ export default function GuideApp({ slug, query, step, kind }: { slug: string; qusp.slug = slug;cacheSpec(slug, sp);setFetched({ slug, spec: sp, via: j.via });- } else setFetched({ slug, suggestions: j.suggestions ?? [] });+ } else setFetched({ slug, suggestions: j.suggestions ?? [], ikea: j.ikea });}).catch(() => alive && setFetched({ slug, error: true }));return () => {@@ -147,7 +147,7 @@ export default function GuideApp({ slug, query, step, kind }: { slug: string; quif (status === "notfound" || status === "error" || !plan)return (<Shell title={q.toUpperCase()}>- <NotFound query={q} slug={slug} suggestions={suggestions} error={status === "error"} />+ <NotFound query={q} slug={slug} suggestions={suggestions} ikea={result?.ikea} error={status === "error"} /></Shell>);return <Guide key={slug + (picked ?? "")} plan={plan} slug={slug} via={via} ai={ai} startStep={step} />;@@ -169,8 +169,9 @@ function Shell({ title, children }: { title: string; children: React.ReactNode });}-function NotFound({ query, slug, suggestions, error }: { query: string; slug: string; suggestions: string[]; error: boolean }) {+function NotFound({ query, slug, suggestions, ikea, error }: { query: string; slug: string; suggestions: string[]; ikea?: string; error: boolean }) {const name = query.split(" ")[0].toUpperCase();+ const what = ikea?.toLowerCase();const kinds = useMemo(() => KIND_LABELS.map((k) => ({ ...k, plan: buildPlan({ ...specForKind(k.kind, "X"), slug: "kind-" + k.kind }) })), []);if (error)return (@@ -188,8 +189,25 @@ function NotFound({ query, slug, suggestions, error }: { query: string; slug: st<div className="nf-head"><Figure pose="think" bubble="?" size={96} /><div>- <h1>What does {name} look like?</h1>- <p className="sub">We don't have {name} on file yet. Pick the closest shape and we'll walk you through a typical build.</p>+ {what ? (+ <>+ <h1>+ {name} is {/^[aeiou]/.test(what) ? "an" : "a"} {what}+ </h1>+ <p className="sub">+ We can't draw {what.replace(/s$/, "")}s step by step yet, so trust the paper manual for this one.{" "}+ <a href={`https://www.ikea.com/search/?q=${encodeURIComponent(name)}`} target="_blank" rel="noreferrer">+ Find it on ikea.com+ </a>+ . If it looks like one of these, a typical build can still help.+ </p>+ </>+ ) : (+ <>+ <h1>What does {name} look like?</h1>+ <p className="sub">We don't have {name} on file yet. Pick the closest shape and we'll walk you through a typical build.</p>+ </>+ )}</div></div><div className="kind-grid">diff --git a/src/lib/draft.ts b/src/lib/draft.tsindex cf24e1f..411acad 100644--- a/src/lib/draft.ts+++ b/src/lib/draft.ts@@ -11,10 +11,11 @@ export type Draft = { spec: ProductSpec; model: string } | { found: false; sugge* server instance and kept for good, so each name is only paid for once and* the second person to ask gets it instantly. Failures throw and aren't kept.*/-/** `q` is the folded name (lower case, no accents), so every spelling of a name shares one entry. */-export async function draft(q: string): Promise<Draft | null> {+/** `key` is the folded name (and IKEA's type for it), so every spelling of a name shares one entry; `q` is what the model reads. */+export async function draft(key: string, q: string): Promise<Draft | null> {"use cache: remote";cacheLife("max");+ void key;const { text, model } = await chatText({models: MODELS.text,json: true,diff --git a/src/lib/voice/names.ts b/src/lib/voice/names.tsindex f6b6888..80bd3e6 100644--- a/src/lib/voice/names.ts+++ b/src/lib/voice/names.ts@@ -1,2 +1,60 @@/** How the voice says product names, as Kokoro phonemes. Written by scripts/voice/names.ts. */-export const NAMES: Record<string, string> = {};+export const NAMES: Record<string, string> = {+ "Adde": "ædɪ",+ "Bekväm": "bɛkvɑm",+ "Bestå": "bɛstɔ",+ "Blåliden": "blɔlidɛn",+ "Borgeby": "bɔɹɡɛbi",+ "Busunge": "bʊsʊŋɡɛ",+ "Danderyd": "dændɛɹid",+ "Docksta": "dɔkstɑ",+ "Domsten": "dɔmstɛn",+ "Ekedalen": "iːkədɑlɛn",+ "Fjälkinge": "fjælkɪŋɛ",+ "Frösjön": "fɜʃɜn",+ "Fågelfjället": "fOɡɛlfjælɛt",+ "Garnanäs": "ɡɑɹnɑnæs",+ "Godishus": "Odihʊs",+ "Gunde": "ɡʊndɛ",+ "Gävle": "ɡævlə",+ "Huvudspelare": "hʊvʊdspɛlɑɹe",+ "Hyllis": "hɪlɪs",+ "Högved": "hɜɡvɛd",+ "Ingatorp": "ɪŋɡɑtɔɹp",+ "Jonaxel": "jɔnɑksɛl",+ "Kallax": "kɑlɑks",+ "Kesnacken": "kɛsnækɛn",+ "Kleppstad": "klɛpstɑd",+ "Lastare": "lɑstɑɹɛ",+ "Lillberget": "lɪlbɛɹɡɛt",+ "Lommarp": "lɔmmɑɹp",+ "Metod": "mɛtOd",+ "Minnen": "mɪnnɛn",+ "Nissafors": "nɪssɑfɔɹs",+ "Nordkisa": "nɔɹdkisɑ",+ "Norrmansö": "nɔɹɹmɑnsɜ",+ "Norrmjöle": "nɔɹɹmjɜlɛ",+ "Nämmarö": "nɛmɑɹɜ",+ "Ommjänge": "Omjɛŋɛ",+ "Orreslätt": "Oɹɹɛslɛt",+ "Poäng": "pOɛŋ",+ "Racknäs": "ɹɑkknɛs",+ "Salnö": "sɑlnɜ",+ "Segerön": "sɛɡɛɹɜn",+ "Skogsön": "skɔɡsɜn",+ "Sniglar": "snɪɡlɑɹ",+ "Söderhamn": "sɜdɛɹhɑn",+ "Tegelön": "tɛɡəlɜn",+ "Torparö": "tOɹpaɹɜ",+ "Trones": "tɹOnɛs",+ "Tällåsen": "tælOsɛn",+ "Valnäs": "vɑlnɛs",+ "Vimle": "vɪmlə",+ "Visingsö": "vɪsɪŋsə",+ "Vittskär": "vɪtskæɚ",+ "Väsman": "vɛsmɑn",+ "Yngvar": "jɪŋvɑɚ",+ "Äpplaryd": "æpplɑɹid",+ "Ålhult": "ɑlhʊlt",+ "Övning": "ɜvnɪŋ"+};