1
+/* oxlint-disable next/no-img-element -- Satori renders raw <img>, next/image does not apply here */
2
import { ImageResponse } from 'next/og';
3
+import { readFile } from 'fs/promises';
4
+import { join } from 'path';
5
3
-export function GET(request: Request) {
6
+// Social preview cards for every docs page. One shared shell, one slot per
7
+// section. Palette and type follow app/global.css: dark DEV surface by
8
+// default, light on request, deep electric blue brand accent, square corners.
9
+// Geist Sans / Mono are vendored in app/fonts because Satori cannot read the
10
+// site's woff2 files.
11
+
12
+export const OG_WIDTH = 1200;
13
+export const OG_HEIGHT = 630;
14
+
15
+const THEMES = {
16
+ dark: {
17
+ ground: '#0f0f0f',
18
+ card: '#1a1a1a',
19
+ ink: '#fafafa',
20
+ soft: '#d4d4d4',
21
+ muted: '#a1a1a1',
22
+ line: '#2a2a2a',
23
+ brand: '#51a2ff',
24
+ wordmarkFile: 'Composio Logo Dark.svg',
25
+ logoTheme: 'dark',
26
+ backgroundFile: 'og/bg-dark.jpg' as string | null,
27
+ },
28
+ light: {
29
+ ground: '#fbfbfb',
30
+ card: '#ffffff',
31
+ ink: '#0f0f0f',
32
+ soft: '#3d3d3d',
33
+ muted: '#6b6b6b',
34
+ line: '#e5e5e5',
35
+ brand: '#0007cd',
36
+ wordmarkFile: 'Composio Logo.svg',
37
+ logoTheme: null,
38
+ backgroundFile: null as string | null,
39
+ },
40
+} as const;
41
+export type OgTheme = keyof typeof THEMES;
42
+type Palette = (typeof THEMES)[OgTheme];
43
+
44
+const SECTIONS = ['docs', 'toolkits', 'reference', 'changelog', 'home'] as const;
45
+export type OgSection = (typeof SECTIONS)[number];
46
+
47
+const SECTION_LABELS: Record<OgSection, string> = {
48
+ docs: 'Docs',
49
+ toolkits: 'Toolkits',
50
+ reference: 'API Reference',
51
+ changelog: 'Changelog',
52
+ home: 'Docs',
53
+};
54
+
55
+const LOGO_HOSTS = new Set(['logos.composio.dev', 'assets.composio.dev']);
56
+
57
+const TITLE_MAX = 120;
58
+const DESCRIPTION_MAX = 200;
59
+
60
+// --- assets -----------------------------------------------------------------
61
+
62
+// Resolved per call, not at import time, so the app root is whatever cwd is
63
+// when the first request lands (matches lib/toolkit-data.ts).
64
+const fontsDir = () => join(process.cwd(), 'app/fonts');
65
+const publicDir = () => join(process.cwd(), 'public');
66
+
67
+type FontSpec = { name: string; data: ArrayBuffer; weight: 400 | 500; style: 'normal' };
68
+
69
+async function loadFont(file: string, name: string, weight: 400 | 500): Promise<FontSpec | null> {
70
+ try {
71
+ const buf = await readFile(join(fontsDir(), file));
72
+ return { name, data: buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength), weight, style: 'normal' };
73
+ } catch {
74
+ return null;
75
+ }
76
+}
77
+
78
+let fontsPromise: Promise<FontSpec[]> | null = null;
79
+function getFonts(): Promise<FontSpec[]> {
80
+ if (!fontsPromise) {
81
+ fontsPromise = Promise.all([
82
+ loadFont('Geist-Regular.ttf', 'Geist', 400),
83
+ loadFont('Geist-Medium.ttf', 'Geist', 500),
84
+ loadFont('GeistMono-Regular.ttf', 'Geist Mono', 400),
85
+ loadFont('GeistMono-Medium.ttf', 'Geist Mono', 500),
86
+ ]).then((fonts) => fonts.filter((f): f is FontSpec => f !== null));
87
+ }
88
+ return fontsPromise;
89
+}
90
+
91
+interface Brand {
92
+ /** Full wordmark as a data URI. */
93
+ wordmark: string | null;
94
+ /** Icon glyph only, as a data URI. */
95
+ mark: string | null;
96
+ /** Full-bleed background as a data URI, when the theme has one. */
97
+ background: string | null;
98
+}
99
+
100
+const toDataUri = (svg: string) => `data:image/svg+xml;base64,${Buffer.from(svg).toString('base64')}`;
101
+
102
+const brandPromises: Partial<Record<OgTheme, Promise<Brand>>> = {};
103
+function getBrand(theme: OgTheme): Promise<Brand> {
104
+ let promise = brandPromises[theme];
105
+ if (!promise) {
106
+ const { wordmarkFile, backgroundFile } = THEMES[theme];
107
+ const background = backgroundFile
108
+ ? readFile(join(publicDir(), backgroundFile))
109
+ .then((buf) => `data:image/jpeg;base64,${buf.toString('base64')}`)
110
+ .catch(() => null)
111
+ : Promise.resolve(null);
112
+ promise = Promise.all([readFile(join(publicDir(), wordmarkFile), 'utf8').catch(() => null), background])
113
+ .then(([svg, background]) => {
114
+ if (!svg) return { wordmark: null, mark: null, background };
115
+ // The first two <path>s of the wordmark are the icon glyph; the rest are letterforms.
116
+ const paths = svg.match(/<path[^>]*\/>/g)?.slice(0, 2) ?? [];
117
+ const mark = paths.length === 2
118
+ ? toDataUri(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 104 121" fill="none">${paths.join('')}</svg>`)
119
+ : null;
120
+ return { wordmark: toDataUri(svg), mark, background };
121
+ });
122
+ brandPromises[theme] = promise;
123
+ }
124
+ return promise;
125
+}
126
+
127
+// --- params -----------------------------------------------------------------
128
+
129
+export interface OgParams {
130
+ section: OgSection;
131
+ theme: OgTheme;
132
+ title: string;
133
+ description: string;
134
+ logo: string | null;
135
+ date: string | null;
136
+ version: string | null;
137
+}
138
+
139
+function clip(value: string | null, max: number): string {
140
+ return Array.from((value ?? '').trim()).slice(0, max).join('');
141
+}
142
+
143
+function safeLogo(value: string | null, theme: OgTheme): string | null {
144
+ if (!value) return null;
145
+ try {
146
+ const url = new URL(value);
147
+ if (url.protocol !== 'https:' || !LOGO_HOSTS.has(url.hostname)) return null;
148
+ const logoTheme = THEMES[theme].logoTheme;
149
+ if (logoTheme) url.searchParams.set('theme', logoTheme);
150
+ return url.toString();
151
+ } catch {
152
+ return null;
153
+ }
154
+}
155
+
156
+export function parseOgParams(request: Request): OgParams {
157
const params = new URL(request.url).searchParams;
5
- const input = params.get('title')?.trim();
6
- const title = Array.from(input || 'Composio Docs').slice(0, 120).join('');
158
+ const rawSection = params.get('section') ?? (params.get('variant') === 'home' ? 'home' : 'docs');
159
+ const section = (SECTIONS as readonly string[]).includes(rawSection) ? (rawSection as OgSection) : 'docs';
160
+ const theme: OgTheme = params.get('theme') === 'light' ? 'light' : 'dark';
161
+ const title = clip(params.get('title'), TITLE_MAX) || (section === 'home' ? '' : 'Composio Docs');
162
+ return {
163
+ section,
164
+ theme,
165
+ title,
166
+ description: clip(params.get('description'), DESCRIPTION_MAX),
167
+ logo: safeLogo(params.get('logo'), theme),
168
+ date: clip(params.get('date'), 40) || null,
169
+ version: clip(params.get('version'), 12) || null,
170
+ };
171
+}
172
+
173
+// --- primitives -------------------------------------------------------------
174
+
175
+const sans = 'Geist, ui-sans-serif, system-ui, sans-serif';
176
+const mono = '"Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace';
177
+
178
+interface Ctx {
179
+ c: Palette;
180
+ brand: Brand;
181
+}
182
+
183
+function Stack({ children, gap = 24 }: { children: React.ReactNode; gap?: number }) {
184
+ // Satori flattens fragments into the parent's flex row, so every card
185
+ // slot wraps its pieces in an explicit column.
186
+ return <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', textAlign: 'center', gap }}>{children}</div>;
187
+}
188
+
189
+function Eyebrow({ children, color }: { children: string; color: string }) {
190
+ return (
191
+ <div style={{ display: 'flex', fontFamily: mono, fontSize: 20, fontWeight: 500, letterSpacing: 2.4, textTransform: 'uppercase', color }}>
192
+ {children}
193
+ </div>
194
+ );
195
+}
196
+
197
+function Chip({ children, c }: { children: string; c: Palette }) {
198
+ return (
199
+ <div style={{
200
+ display: 'flex', alignItems: 'center', padding: '8px 14px',
201
+ border: `1px solid ${c.line}`, background: c.card,
202
+ fontFamily: mono, fontSize: 18, letterSpacing: 1.2, textTransform: 'uppercase', color: c.muted,
203
+ }}>
204
+ {children}
205
+ </div>
206
+ );
207
+}
208
+
209
+function Title({ children, size, c }: { children: string; size: number; c: Palette }) {
210
+ return (
211
+ <div style={{
212
+ display: 'flex', fontFamily: sans, fontWeight: 500, fontSize: size, lineHeight: 1.08,
213
+ letterSpacing: size >= 60 ? -2 : -1.2, color: c.ink, maxWidth: 1000, lineClamp: 3,
214
+ justifyContent: 'center', textAlign: 'center', textWrap: 'balance',
215
+ }}>
216
+ {children}
217
+ </div>
218
+ );
219
+}
220
+
221
+function titleSize(title: string, base = 72): number {
222
+ const n = title.length;
223
+ if (n > 90) return base - 28;
224
+ if (n > 60) return base - 16;
225
+ if (n > 36) return base - 8;
226
+ return base;
227
+}
228
+
229
+function Description({ children, c }: { children: string; c: Palette }) {
230
+ if (!children) return null;
231
+ return (
232
+ <div style={{
233
+ display: 'flex', fontFamily: sans, fontSize: 30, lineHeight: 1.4, color: c.soft, maxWidth: 900, lineClamp: 2,
234
+ justifyContent: 'center', textAlign: 'center', textWrap: 'balance',
235
+ }}>
236
+ {children}
237
+ </div>
238
+ );
239
+}
240
+
241
+function Node({ children, c }: { children: React.ReactNode; c: Palette }) {
242
+ return (
243
+ <div style={{
244
+ display: 'flex', alignItems: 'center', justifyContent: 'center',
245
+ width: 112, height: 112, background: c.card, border: `1px solid ${c.line}`,
246
+ }}>
247
+ {children}
248
+ </div>
249
+ );
250
+}
251
+
252
+// --- shell ------------------------------------------------------------------
253
+
254
+function Shell({ ctx, label, children }: { ctx: Ctx; label: string; children: React.ReactNode }) {
255
+ const { c, brand } = ctx;
256
+ return (
257
+ <div style={{
258
+ display: 'flex', flexDirection: 'column', justifyContent: 'space-between',
259
+ width: '100%', height: '100%', padding: '56px 64px',
260
+ background: c.ground, color: c.ink, fontFamily: sans, position: 'relative',
261
+ }}>
262
+ {brand.background ? (
263
+ <img src={brand.background} width={OG_WIDTH} height={OG_HEIGHT} alt=""
264
+ style={{ position: 'absolute', top: 0, left: 0, width: OG_WIDTH, height: OG_HEIGHT, opacity: 0.7 }} />
265
+ ) : null}
266
+ <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
267
+ {brand.wordmark ? (
268
+ <img src={brand.wordmark} width={165} height={30} alt="" />
269
+ ) : (
270
+ <div style={{ display: 'flex', fontSize: 28, fontWeight: 500 }}>Composio</div>
271
+ )}
272
+ <Eyebrow color={c.brand}>{label}</Eyebrow>
273
+ </div>
274
8
- return new ImageResponse(
9
- params.get('variant') === 'home' ? (
275
<div style={{
11
- display: 'flex', width: '100%', height: '100%',
12
- background: '#131211', color: '#faf9f6', fontFamily: 'sans-serif',
276
+ display: 'flex', flexDirection: 'column', gap: 24, flexGrow: 1,
277
+ justifyContent: 'center', alignItems: 'center', textAlign: 'center', paddingTop: 24,
278
}}>
14
- <div style={{
15
- display: 'flex', flexDirection: 'column', justifyContent: 'space-between',
16
- width: 810, padding: '60px 64px',
17
- }}>
18
- <div style={{ display: 'flex', alignItems: 'center', gap: 16, fontSize: 28 }}>
19
- <div style={{ width: 24, height: 24, background: '#f76b15', borderRadius: 5 }} />
20
- Composio Docs
21
- </div>
22
- <div style={{ display: 'flex', flexDirection: 'column', gap: 24 }}>
23
- <div style={{ display: 'flex', flexDirection: 'column', fontSize: 76, lineHeight: 1.04, letterSpacing: -3 }}>
24
- <span>Build and operate</span>
25
- <span style={{ color: '#ff8a42' }}>AI agents.</span>
26
- </div>
27
- <div style={{ display: 'flex', fontSize: 27, lineHeight: 1.4, color: '#bbb7b0', maxWidth: 620 }}>
28
- Tools, managed authentication, and secure execution for your agents.
29
- </div>
30
- </div>
31
- <div style={{ display: 'flex', fontSize: 23, color: '#bbb7b0' }}>docs.composio.dev</div>
279
+ {children}
280
+ </div>
281
+ </div>
282
+ );
283
+}
284
+
285
+// --- section slots ----------------------------------------------------------
286
+
287
+type CardProps = { p: OgParams; ctx: Ctx };
288
+
289
+function DocsCard({ p, ctx: { c } }: CardProps) {
290
+ return (
291
+ <Stack>
292
+ <Title size={titleSize(p.title)} c={c}>{p.title}</Title>
293
+ <Description c={c}>{p.description}</Description>
294
+ </Stack>
295
+ );
296
+}
297
+
298
+function ToolkitCard({ p, ctx: { c, brand } }: CardProps) {
299
+ const name = p.title.replace(/\s*-\s*Composio Toolkit\s*$/i, '');
300
+ return (
301
+ <Stack>
302
+ {p.logo ? (
303
+ <div style={{ display: 'flex', alignItems: 'center', marginBottom: 16 }}>
304
+ <Node c={c}>
305
+ {brand.mark ? <img src={brand.mark} width={56} height={65} alt="" /> : <div style={{ display: 'flex', fontSize: 40, fontWeight: 500 }}>C</div>}
306
+ </Node>
307
+ <div style={{ display: 'flex', width: 72, height: 4, background: c.muted }} />
308
+ <Node c={c}>
309
+ <img src={p.logo} width={72} height={72} alt="" style={{ objectFit: 'contain' }} />
310
+ </Node>
311
</div>
312
+ ) : null}
313
+ <Title size={titleSize(`${name} Toolkit`, 64)} c={c}>{`${name} Toolkit`}</Title>
314
+ <Description c={c}>{p.description || `Connect your AI agent to ${name} with Composio.`}</Description>
315
+ </Stack>
316
+ );
317
+}
318
+
319
+function ReferenceCard({ p, ctx: { c } }: CardProps) {
320
+ return (
321
+ <Stack>
322
+ <div style={{ display: 'flex', justifyContent: 'center', gap: 10 }}>
323
<div style={{
34
- display: 'flex', flexDirection: 'column', justifyContent: 'space-between',
35
- width: 390, padding: '64px 40px', background: '#f76b15', color: '#131211',
324
+ display: 'flex', alignItems: 'center', padding: '8px 14px',
325
+ background: c.brand, color: c.ground,
326
+ fontFamily: mono, fontSize: 18, fontWeight: 500, letterSpacing: 1.2,
327
}}>
37
- <div style={{ display: 'flex', fontSize: 20, letterSpacing: 3 }}>FROM THE DOCS</div>
38
- <div style={{ display: 'flex', flexDirection: 'column', gap: 24 }}>
39
- {['SDK', 'CLI', 'MCP'].map((label) => (
40
- <div key={label} style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', borderBottom: '1px solid #b84c0b', paddingBottom: 20 }}>
41
- <span style={{ fontSize: 48 }}>{label}</span>
42
- <span style={{ fontSize: 32 }}>↗</span>
43
- </div>
44
- ))}
45
- </div>
46
- <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '18px 22px', borderRadius: 8, background: '#131211', color: '#faf9f6', fontSize: 26 }}>
47
- <span>Start building</span><span>→</span>
48
- </div>
328
+ REST API
329
</div>
330
+ {p.version ? <Chip c={c}>{p.version}</Chip> : null}
331
</div>
51
- ) : (
52
- <div style={{
53
- display: 'flex', flexDirection: 'column', justifyContent: 'space-between',
54
- width: '100%', height: '100%', padding: 72, background: '#131211', color: '#faf9f6',
55
- fontFamily: 'sans-serif',
56
- }}>
57
- <div style={{ display: 'flex', alignItems: 'center', gap: 18, fontSize: 32 }}>
58
- <div style={{ width: 28, height: 28, background: '#f76b15', borderRadius: 6 }} />
59
- Composio Docs
60
- </div>
61
- <div style={{ display: 'flex', fontSize: title.length > 60 ? 48 : 68, lineHeight: 1.12,
62
- letterSpacing: -2, maxWidth: 1056, overflowWrap: 'break-word' }}>
63
- {title}
64
- </div>
65
- <div style={{ display: 'flex', justifyContent: 'space-between', fontSize: 24, color: '#bbb7b0' }}>
66
- <span>Build and operate agents</span>
67
- <span>docs.composio.dev</span>
332
+ <Title size={titleSize(p.title)} c={c}>{p.title}</Title>
333
+ <Description c={c}>{p.description}</Description>
334
+ </Stack>
335
+ );
336
+}
337
+
338
+function ChangelogCard({ p, ctx: { c } }: CardProps) {
339
+ return (
340
+ <Stack>
341
+ {p.date ? <Eyebrow color={c.muted}>{p.date}</Eyebrow> : null}
342
+ <Title size={titleSize(p.title)} c={c}>{p.title}</Title>
343
+ {/* The page description is "Updates from <date>", which the eyebrow already says. */}
344
+ {p.date ? null : <Description c={c}>{p.description}</Description>}
345
+ </Stack>
346
+ );
347
+}
348
+
349
+function HomeCard({ p, ctx: { c } }: CardProps) {
350
+ return (
351
+ <Stack>
352
+ <div style={{
353
+ display: 'flex', flexDirection: 'column', alignItems: 'center',
354
+ fontFamily: sans, fontWeight: 500, fontSize: 84, lineHeight: 1.02, letterSpacing: -3, color: c.ink,
355
+ }}>
356
+ <span>Build and operate</span>
357
+ <span style={{ color: c.brand }}>AI agents.</span>
358
</div>
69
- </div>
70
- ),
71
- { width: 1200, height: 630, headers: { 'Cache-Control': 'public, max-age=86400' } },
359
+ <Description c={c}>{p.description || 'Tools, managed authentication, and secure execution for your agents.'}</Description>
360
+ </Stack>
361
+ );
362
+}
363
+
364
+const CARDS: Record<OgSection, (props: CardProps) => React.ReactElement> = {
365
+ docs: DocsCard,
366
+ toolkits: ToolkitCard,
367
+ reference: ReferenceCard,
368
+ changelog: ChangelogCard,
369
+ home: HomeCard,
370
+};
371
+
372
+// --- handler ----------------------------------------------------------------
373
+
374
+export async function GET(request: Request) {
375
+ const p = parseOgParams(request);
376
+ const [fonts, brand] = await Promise.all([getFonts(), getBrand(p.theme)]);
377
+ const ctx: Ctx = { c: THEMES[p.theme], brand };
378
+ const Card = CARDS[p.section];
379
+
380
+ return new ImageResponse(
381
+ <Shell ctx={ctx} label={SECTION_LABELS[p.section]}>
382
+ <Card p={p} ctx={ctx} />
383
+ </Shell>,
384
+ {
385
+ width: OG_WIDTH,
386
+ height: OG_HEIGHT,
387
+ fonts,
388
+ headers: { 'Cache-Control': 'public, max-age=86400, s-maxage=86400' },
389
+ },
390
);
391
}