Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat(www): upgrade to Next.js 16 (#52001)

Ivan Vasilovced4ff82a4e5
diff --git a/apps/www/next.config.mjs b/apps/www/next.config.mjs
index b65878cf727..0e1803a0298 100644
--- a/apps/www/next.config.mjs
+++ b/apps/www/next.config.mjs
@@ -67,6 +67,9 @@ const nextConfig = {
// Next.js build artifacts
'.next/cache/**/*',
'.next/static/**/*',
+ // Next 16 creates `.next/lock` during `next build` and deletes it on exit. Routes that read
+ // `process.cwd()` get the whole app dir traced, so Vercel would try to deploy the missing file.
+ '.next/lock',
// Static assets
'public/**/*',
],
@@ -85,6 +88,11 @@ const nextConfig = {
reactStrictMode: true,
images: {
dangerouslyAllowSVG: false,
+ // Next 16 rejects local images with a query string (e.g. `/images/blog/foo/thumb.png?v=3`,
+ // used for cache busting) unless `localPatterns` allows it. Omitting `search` allows any.
+ localPatterns: [{ pathname: '/**' }],
+ // Next 16 only allows `quality` values listed here (default is [75]); the app uses 75, 80 and 100.
+ qualities: [75, 80, 100],
remotePatterns,
},
async headers() {
@@ -229,10 +237,6 @@ const nextConfig = {
// prod
ignoreBuildErrors: process.env.NEXT_PUBLIC_VERCEL_ENV === 'production' ? false : true,
},
- eslint: {
- // We are already running linting via GH action, this will skip linting during production build on Vercel.
- ignoreDuringBuilds: true,
- },
}
// next.config.js.
@@ -247,8 +251,12 @@ export default withSentryConfig(configExport, {
org: 'supabase',
project: 'www',
- unstable_sentryWebpackPluginOptions: {
- applicationKey: 'supabase-www',
+ applicationKey: 'supabase-www',
+ webpack: {
+ treeshake: {
+ // Automatically tree-shake Sentry logger statements to reduce bundle size
+ removeDebugLogging: true,
+ },
},
// Only print logs for uploading source maps in CI
@@ -265,9 +273,6 @@ export default withSentryConfig(configExport, {
// Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-
// side errors will fail.
// tunnelRoute: "/monitoring",
-
- // Automatically tree-shake Sentry logger statements to reduce bundle size
- disableLogger: true,
})
function getAssetPrefix() {
diff --git a/apps/www/package.json b/apps/www/package.json
index ef7c4a3526c..a325030266d 100644
--- a/apps/www/package.json
+++ b/apps/www/package.json
@@ -5,10 +5,10 @@
"private": true,
"scripts": {
"preinstall": "npx only-allow pnpm",
- "dev": "pnpm run content:build:core && next --port 3000",
+ "dev": "pnpm run content:build:core && next dev --webpack --port 3000",
"prebuild": "pnpm --filter=docs run build:federated-content && pnpm --filter=docs run build:guides-markdown && pnpm run content:build",
"build": "turbo run build:next --filter=www",
- "build:next": "next build && node ./internals/generate-sitemap.mjs",
+ "build:next": "next build --webpack && node ./internals/generate-sitemap.mjs",
"export": "next export",
"start": "next start",
"lint": "eslint .",
@@ -32,8 +32,8 @@
"@heroicons/react": "^1.0.6",
"@mdx-js/mdx": "^3.0.1",
"@mdx-js/react": "^3.0.0",
- "@next/bundle-analyzer": "15.3.1",
- "@next/mdx": "15.3.1",
+ "@next/bundle-analyzer": "16.3.6",
+ "@next/mdx": "16.3.6",
"@octokit/auth-app": "^7.0.0",
"@octokit/core": "^6.0.0",
"@octokit/graphql": "^8.0.0",
@@ -72,7 +72,7 @@
"micromark-extension-gfm": "^2.0.3",
"micromark-extension-mdxjs": "^1.0.1",
"motion": "catalog:",
- "next": "^15.5.24",
+ "next": "catalog:",
"next-mdx-remote-client": "^1.1.7",
"next-seo": "^6.5.0",
"next-themes": "catalog:",
diff --git a/apps/www/middleware.test.ts b/apps/www/proxy.test.ts
similarity index 89%
rename from apps/www/middleware.test.ts
rename to apps/www/proxy.test.ts
index aac6a0de94a..06b0c778a7f 100644
--- a/apps/www/middleware.test.ts
+++ b/apps/www/proxy.test.ts
@@ -2,7 +2,7 @@ import { FIRST_REFERRER_COOKIE_NAME } from 'common/first-referrer-cookie'
import { NextRequest } from 'next/server'
import { describe, expect, it, vi } from 'vitest'
-import { middleware } from './middleware'
+import { proxy } from './proxy'
// content.generated.ts is produced by scripts/generateMdContent.mjs at
// content:build time and gitignored, so it isn't on disk in CI before tests
@@ -34,18 +34,18 @@ function makeRequest(
return req
}
-describe('www middleware', () => {
+describe('www proxy', () => {
describe('cookie stamping on www paths', () => {
it('stamps cookie for external referrer on www path', () => {
const req = makeRequest('/pricing', { referer: 'https://google.com' })
- const res = middleware(req)
+ const res = proxy(req)
expect(res.cookies.get(FIRST_REFERRER_COOKIE_NAME)).toBeDefined()
})
it('does not stamp cookie for internal referrer', () => {
const req = makeRequest('/pricing', { referer: 'https://supabase.com/docs' })
- const res = middleware(req)
+ const res = proxy(req)
expect(res.cookies.get(FIRST_REFERRER_COOKIE_NAME)).toBeUndefined()
})
@@ -54,7 +54,7 @@ describe('www middleware', () => {
describe('cookie stamping on /dashboard paths', () => {
it('stamps cookie for external referrer', () => {
const req = makeRequest('/dashboard/project/123', { referer: 'https://google.com' })
- const res = middleware(req)
+ const res = proxy(req)
expect(res.cookies.get(FIRST_REFERRER_COOKIE_NAME)).toBeDefined()
})
@@ -63,14 +63,14 @@ describe('www middleware', () => {
const req = makeRequest('/dashboard/project/123', {
referer: 'https://supabase.com/pricing',
})
- const res = middleware(req)
+ const res = proxy(req)
expect(res.cookies.get(FIRST_REFERRER_COOKIE_NAME)).toBeUndefined()
})
it('does not stamp cookie for direct navigation (no referrer)', () => {
const req = makeRequest('/dashboard/project/123')
- const res = middleware(req)
+ const res = proxy(req)
expect(res.cookies.get(FIRST_REFERRER_COOKIE_NAME)).toBeUndefined()
})
@@ -79,7 +79,7 @@ describe('www middleware', () => {
describe('cookie stamping on /docs paths', () => {
it('stamps cookie for external referrer', () => {
const req = makeRequest('/docs/guides/auth', { referer: 'https://google.com' })
- const res = middleware(req)
+ const res = proxy(req)
expect(res.cookies.get(FIRST_REFERRER_COOKIE_NAME)).toBeDefined()
})
@@ -88,14 +88,14 @@ describe('www middleware', () => {
const req = makeRequest('/docs/guides/auth', {
referer: 'https://supabase.com/pricing',
})
- const res = middleware(req)
+ const res = proxy(req)
expect(res.cookies.get(FIRST_REFERRER_COOKIE_NAME)).toBeUndefined()
})
it('does not stamp cookie for direct navigation (no referrer)', () => {
const req = makeRequest('/docs/guides/auth')
- const res = middleware(req)
+ const res = proxy(req)
expect(res.cookies.get(FIRST_REFERRER_COOKIE_NAME)).toBeUndefined()
})
@@ -104,35 +104,35 @@ describe('www middleware', () => {
describe('.md suffix routing', () => {
it('rewrites /<slug>.md for allowlisted slugs', () => {
const req = makeRequest('/auth.md')
- const res = middleware(req)
+ const res = proxy(req)
expect(res.headers.get('x-middleware-rewrite')).toBe('https://supabase.com/api-v2/md/auth')
})
it('falls through for non-allowlisted .md slugs', () => {
const req = makeRequest('/not-a-page.md')
- const res = middleware(req)
+ const res = proxy(req)
expect(res.headers.get('x-middleware-rewrite')).toBeNull()
})
it('rewrites /index.md to the homepage markdown', () => {
const req = makeRequest('/index.md')
- const res = middleware(req)
+ const res = proxy(req)
expect(res.headers.get('x-middleware-rewrite')).toBe('https://supabase.com/api-v2/md/index')
})
it('falls back to serving /.md as homepage markdown if the config 308 is ever removed', () => {
const req = makeRequest('/.md')
- const res = middleware(req)
+ const res = proxy(req)
expect(res.headers.get('x-middleware-rewrite')).toBe('https://supabase.com/api-v2/md/index')
})
it('rewrites changelog entry .md requests without doubling the suffix', () => {
const req = makeRequest('/changelog/100.md', { accept: 'text/markdown' })
- const res = middleware(req)
+ const res = proxy(req)
expect(res.headers.get('x-middleware-rewrite')).toBe('https://supabase.com/changelog/100.md')
})
@@ -141,7 +141,7 @@ describe('www middleware', () => {
const req = makeRequest('/changelog/100.md', {
accept: 'application/x-content-negotiation-probe',
})
- const res = middleware(req)
+ const res = proxy(req)
expect(res.status).not.toBe(406)
expect(res.headers.get('x-middleware-rewrite')).toBe('https://supabase.com/changelog/100.md')
@@ -151,7 +151,7 @@ describe('www middleware', () => {
const req = makeRequest('/changelog/pipelines.md', {
accept: 'application/x-content-negotiation-probe',
})
- const res = middleware(req)
+ const res = proxy(req)
expect(res.status).not.toBe(406)
expect(res.headers.get('x-middleware-rewrite')).toBe(
@@ -161,7 +161,7 @@ describe('www middleware', () => {
it('rewrites the changelog index .md request without doubling the suffix', () => {
const req = makeRequest('/changelog.md', { accept: 'text/markdown' })
- const res = middleware(req)
+ const res = proxy(req)
expect(res.headers.get('x-middleware-rewrite')).toBe('https://supabase.com/changelog.md')
})
@@ -170,49 +170,49 @@ describe('www middleware', () => {
describe('Accept: text/markdown content negotiation', () => {
it('rewrites / to the homepage index slug when Accept: text/markdown', () => {
const req = makeRequest('/', { accept: 'text/markdown' })
- const res = middleware(req)
+ const res = proxy(req)
expect(res.headers.get('x-middleware-rewrite')).toBe('https://supabase.com/api-v2/md/index')
})
it('rewrites /<slug> when Accept: text/markdown matches the allowlist', () => {
const req = makeRequest('/auth', { accept: 'text/markdown' })
- const res = middleware(req)
+ const res = proxy(req)
expect(res.headers.get('x-middleware-rewrite')).toBe('https://supabase.com/api-v2/md/auth')
})
it('rewrites /<slug>/ (trailing slash) the same as /<slug>', () => {
const req = makeRequest('/auth/', { accept: 'text/markdown' })
- const res = middleware(req)
+ const res = proxy(req)
expect(res.headers.get('x-middleware-rewrite')).toBe('https://supabase.com/api-v2/md/auth')
})
it('falls through when Accept does not include text/markdown', () => {
const req = makeRequest('/auth', { accept: 'text/html' })
- const res = middleware(req)
+ const res = proxy(req)
expect(res.headers.get('x-middleware-rewrite')).toBeNull()
})
it('falls through when slug is not in the allowlist', () => {
const req = makeRequest('/not-a-page', { accept: 'text/markdown' })
- const res = middleware(req)
+ const res = proxy(req)
expect(res.headers.get('x-middleware-rewrite')).toBeNull()
})
it('rewrites changelog entries to their static .md file', () => {
const req = makeRequest('/changelog/100', { accept: 'text/markdown' })
- const res = middleware(req)
+ const res = proxy(req)
expect(res.headers.get('x-middleware-rewrite')).toBe('https://supabase.com/changelog/100.md')
})
it('negotiates markdown for non-legacy changelog slugs', () => {
const req = makeRequest('/changelog/pipelines', { accept: 'text/markdown' })
- const res = middleware(req)
+ const res = proxy(req)
expect(res.headers.get('x-middleware-rewrite')).toBe(
'https://supabase.com/changelog/pipelines.md'
@@ -221,7 +221,7 @@ describe('www middleware', () => {
it('passes through unpublished numeric-prefix changelog slugs', () => {
const req = makeRequest('/changelog/999-not-published', { accept: 'text/markdown' })
- const res = middleware(req)
+ const res = proxy(req)
expect(res.headers.get('x-middleware-rewrite')).toBeNull()
expect(res.status).not.toBe(406)
@@ -229,7 +229,7 @@ describe('www middleware', () => {
it('passes through deep paths under a published changelog slug', () => {
const req = makeRequest('/changelog/100/bar', { accept: 'text/markdown' })
- const res = middleware(req)
+ const res = proxy(req)
expect(res.headers.get('x-middleware-rewrite')).toBeNull()
expect(res.status).not.toBe(406)
@@ -237,7 +237,7 @@ describe('www middleware', () => {
it('rewrites the bare changelog index to its static .md file', () => {
const req = makeRequest('/changelog', { accept: 'text/markdown' })
- const res = middleware(req)
+ const res = proxy(req)
expect(res.headers.get('x-middleware-rewrite')).toBe('https://supabase.com/changelog.md')
})
@@ -248,21 +248,21 @@ describe('www middleware', () => {
const req = makeRequest('/auth', {
accept: 'text/markdown, text/plain;q=0.9, */*;q=0.8',
})
- const res = middleware(req)
+ const res = proxy(req)
expect(res.headers.get('x-middleware-rewrite')).toBe('https://supabase.com/api-v2/md/auth')
})
it('serves markdown when md and html have equal q-values', () => {
const req = makeRequest('/auth', { accept: 'text/markdown, text/html, */*' })
- const res = middleware(req)
+ const res = proxy(req)
expect(res.headers.get('x-middleware-rewrite')).toBe('https://supabase.com/api-v2/md/auth')
})
it('serves HTML when html q-value beats markdown q-value', () => {
const req = makeRequest('/auth', { accept: 'text/html;q=1.0, text/markdown;q=0.5' })
- const res = middleware(req)
+ const res = proxy(req)
expect(res.headers.get('x-middleware-rewrite')).toBeNull()
})
@@ -271,28 +271,28 @@ describe('www middleware', () => {
const req = makeRequest('/auth', {
accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
})
- const res = middleware(req)
+ const res = proxy(req)
expect(res.headers.get('x-middleware-rewrite')).toBeNull()
})
it('serves markdown when md q-value beats html q-value', () => {
const req = makeRequest('/auth', { accept: 'text/html;q=0.5, text/markdown;q=1.0' })
- const res = middleware(req)
+ const res = proxy(req)
expect(res.headers.get('x-middleware-rewrite')).toBe('https://supabase.com/api-v2/md/auth')
})
it('tolerates OWS around the q parameter (per RFC 9110)', () => {
const req = makeRequest('/auth', { accept: 'text/html ; q = 1.0, text/markdown ; q = 0.5' })
- const res = middleware(req)
+ const res = proxy(req)
expect(res.headers.get('x-middleware-rewrite')).toBeNull()
})
it('ignores out-of-range q-values rather than treating them as preference', () => {
const req = makeRequest('/auth', { accept: 'text/html;q=2.0, text/markdown;q=1.0' })
- const res = middleware(req)
+ const res = proxy(req)
// text/html's q=2.0 is invalid and falls back to default 1.0; tie -> markdown.
expect(res.headers.get('x-middleware-rewrite')).toBe('https://supabase.com/api-v2/md/auth')
@@ -302,7 +302,7 @@ describe('www middleware', () => {
describe('406 Not Acceptable', () => {
it('returns 406 on MD-eligible page when Accept excludes every type we serve', () => {
const req = makeRequest('/pricing', { accept: 'application/x-content-negotiation-probe' })
- const res = middleware(req)
+ const res = proxy(req)
expect(res.status).toBe(406)
expect(res.headers.get('x-middleware-rewrite')).toBeNull()
@@ -310,14 +310,14 @@ describe('www middleware', () => {
it('does not return 406 on non-MD pages (no negotiation contract there)', () => {
const req = makeRequest('/not-a-page', { accept: 'application/x-content-negotiation-probe' })
- const res = middleware(req)
+ const res = proxy(req)
expect(res.status).not.toBe(406)
})
it('does not return 406 when Accept includes */*', () => {
const req = makeRequest('/pricing', { accept: '*/*' })
- const res = middleware(req)
+ const res = proxy(req)
expect(res.status).not.toBe(406)
})
@@ -327,7 +327,7 @@ describe('www middleware', () => {
accept: 'application/x-content-negotiation-probe',
userAgent: 'Claude-User/1.0',
})
- const res = middleware(req)
+ const res = proxy(req)
expect(res.status).toBe(406)
})
@@ -336,7 +336,7 @@ describe('www middleware', () => {
const req = makeRequest('/changelog/100', {
accept: 'application/x-content-negotiation-probe',
})
- const res = middleware(req)
+ const res = proxy(req)
expect(res.status).toBe(406)
})
@@ -345,14 +345,14 @@ describe('www middleware', () => {
const req = makeRequest('/changelog/pipelines', {
accept: 'application/x-content-negotiation-probe',
})
- const res = middleware(req)
+ const res = proxy(req)
expect(res.status).toBe(406)
})
it('sets Cache-Control: no-store and Vary: Accept on 406 responses', () => {
const req = makeRequest('/pricing', { accept: 'application/x-content-negotiation-probe' })
- const res = middleware(req)
+ const res = proxy(req)
expect(res.status).toBe(406)
expect(res.headers.get('Cache-Control')).toBe('no-store')
@@ -374,7 +374,7 @@ describe('www middleware', () => {
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36',
]) {
const req = makeRequest('/auth', { userAgent: ua })
- const res = middleware(req)
+ const res = proxy(req)
expect(res.headers.get('x-middleware-rewrite')).toBeNull()
}
@@ -385,14 +385,14 @@ describe('www middleware', () => {
accept: 'text/markdown',
userAgent: 'Claude-User (claude-code/2.1.119; +https://support.anthropic.com/)',
})
- const res = middleware(req)
+ const res = proxy(req)
expect(res.headers.get('x-middleware-rewrite')).toBe('https://supabase.com/api-v2/md/auth')
})
it('falls through when slug is not in the allowlist', () => {
const req = makeRequest('/not-a-page', { accept: 'text/markdown' })
- const res = middleware(req)
+ const res = proxy(req)
expect(res.headers.get('x-middleware-rewrite')).toBeNull()
})
diff --git a/apps/www/middleware.ts b/apps/www/proxy.ts
similarity index 97%
rename from apps/www/middleware.ts
rename to apps/www/proxy.ts
index 3800925883c..879882a9860 100644
--- a/apps/www/middleware.ts
+++ b/apps/www/proxy.ts
@@ -4,7 +4,7 @@ import { NextResponse, type NextRequest } from 'next/server'
import { CHANGELOG_PAGES, MD_PAGES } from './app/api-v2/md/content.generated'
-export function middleware(request: NextRequest) {
+export function proxy(request: NextRequest) {
const { pathname } = request.nextUrl
const isMarkdownSuffix = pathname.endsWith('.md')
diff --git a/apps/www/public/customers-rss.xml b/apps/www/public/customers-rss.xml
index 727601c6bd2..ad9add9cdde 100644
--- a/apps/www/public/customers-rss.xml
+++ b/apps/www/public/customers-rss.xml
@@ -5,9 +5,37 @@
<link>https://supabase.com</link>
<description>Latest news from Supabase</description>
<language>en</language>
- <lastBuildDate>Thu, 09 Jul 2026 00:00:00 -0700</lastBuildDate>
+ <lastBuildDate>Tue, 06 Oct 2026 00:00:00 -0700</lastBuildDate>
<atom:link href="https://supabase.com/rss.xml" rel="self" type="application/rss+xml"/>
<item>
+ <guid>https://supabase.com/customers/flick-games</guid>
+ <title>How a two-person studio keeps two live games in sync on Supabase</title>
+ <link>https://supabase.com/customers/flick-games</link>
+ <description>Flick Games is an indie UK studio running two live products, Art of Solitaire and Goalman, on Supabase. A single backend covers authentication, cross-device cloud saves, and remote content delivery across iOS, Android, and Steam for a team of two.</description>
+ <pubDate>Tue, 06 Oct 2026 00:00:00 -0700</pubDate>
+</item>
+<item>
+ <guid>https://supabase.com/customers/polymet</guid>
+ <title>How Polymet gives every user a real backend without a backend team</title>
+ <link>https://supabase.com/customers/polymet</link>
+ <description>Polymet is an AI product designer that turns a prompt or an image into working code. A three-person team runs the backend for tens of thousands of user projects a month, on Supabase, without hiring a single backend engineer.</description>
+ <pubDate>Wed, 23 Sep 2026 00:00:00 -0700</pubDate>
+</item>
+<item>
+ <guid>https://supabase.com/customers/lingodotdev</guid>
+ <title>How Lingo.dev clears enterprise security reviews without a single database question</title>
+ <link>https://supabase.com/customers/lingodotdev</link>
+ <description>Lingo.dev is the localization engineering platform behind retrieval augmented localization, translation APIs with a memory for glossary, brand voice, and quality. It has run on Supabase since day one.</description>
+ <pubDate>Wed, 26 Aug 2026 00:00:00 -0700</pubDate>
+</item>
+<item>
+ <guid>https://supabase.com/customers/qa-tech</guid>
+ <title>How QA.tech built enterprise-ready AI testing agents on Supabase</title>
+ <link>https://supabase.com/customers/qa-tech</link>
+ <description>QA.tech is an autonomous AI testing platform whose QA agents run end-to-end testing of web and mobile products by goal and intent. Three years on Supabase took QA.tech from three founders to a global customer base, enterprise-scale daily test volume, and SOC 2 compliance.</description>
+ <pubDate>Tue, 04 Aug 2026 00:00:00 -0700</pubDate>
+</item>
+<item>
<guid>https://supabase.com/customers/lovable</guid>
<title>How Supabase helps power millions of apps on Lovable</title>
<link>https://supabase.com/customers/lovable</link>
diff --git a/packages/ai-commands/package.json b/packages/ai-commands/package.json
index c1de0dd0ef3..422944842b0 100644
--- a/packages/ai-commands/package.json
+++ b/packages/ai-commands/package.json
@@ -17,7 +17,6 @@
"ai": "5.0.52",
"common-tags": "^1.8.2",
"config": "workspace:*",
- "js-tiktoken": "^1.0.10",
"jsonrepair": "^3.5.0",
"openai": "^4.75.1",
"zod": "catalog:"
diff --git a/packages/ai-commands/src/docs.ts b/packages/ai-commands/src/docs.ts
index b51ae24580d..1f624fba78e 100644
--- a/packages/ai-commands/src/docs.ts
+++ b/packages/ai-commands/src/docs.ts
@@ -3,7 +3,7 @@ import { codeBlock, oneLine } from 'common-tags'
import type OpenAI from 'openai'
import { ApplicationError, UserError } from './errors'
-import { getChatRequestTokenCount, getMaxTokenCount, tokenizer } from './tokenizer'
+import { estimateTokenCount, getChatRequestTokenCount, getMaxTokenCount } from './tokenizer'
import type { Message } from './types'
interface PageSection {
@@ -92,8 +92,7 @@ export async function clippy(
for (let i = 0; i < pageSections.length; i++) {
const pageSection = pageSections[i]
const content = pageSection.content
- const encoded = tokenizer.encode(content)
- tokenCount += encoded.length
+ tokenCount += estimateTokenCount(content)
if (tokenCount >= 1500) {
break
diff --git a/packages/ai-commands/src/tokenizer.ts b/packages/ai-commands/src/tokenizer.ts
index 7796ab26f9c..0988719304f 100644
--- a/packages/ai-commands/src/tokenizer.ts
+++ b/packages/ai-commands/src/tokenizer.ts
@@ -1,10 +1,20 @@
-import { getEncoding } from 'js-tiktoken'
import type OpenAI from 'openai'
-export const tokenizer = getEncoding('cl100k_base')
+// Average number of characters per token for English text with OpenAI's tokenizers.
+// We estimate instead of tokenizing exactly, because bundling a tokenizer (js-tiktoken) adds
+// ~3 MB to the edge function that serves the docs chat, which exceeds the Vercel Edge Function
+// size limit.
+const CHARS_PER_TOKEN = 4
/**
- * Count the tokens for multi-message chat completion requests
+ * Estimate the number of tokens in a string.
+ */
+export function estimateTokenCount(text: string): number {
+ return Math.ceil(text.length / CHARS_PER_TOKEN)
+}
+
+/**
+ * Estimate the tokens for multi-message chat completion requests
*/
export function getChatRequestTokenCount(
messages: OpenAI.Chat.Completions.ChatCompletionMessageParam[],
@@ -17,7 +27,7 @@ export function getChatRequestTokenCount(
}
/**
- * Count the tokens for a single message within a chat completion request
+ * Estimate the tokens for a single message within a chat completion request
*
* See "Counting tokens for chat API calls"
* from https://github.com/openai/openai-cookbook/blob/834181d5739740eb8380096dac7056c925578d9a/examples/How_to_count_tokens_with_tiktoken.ipynb
@@ -57,7 +67,7 @@ export function getMessageTokenCount(
}
return Object.entries(message).reduce((acc, [key, value]) => {
- acc += tokenizer.encode(value).length
+ acc += estimateTokenCount(typeof value === 'string' ? value : (JSON.stringify(value) ?? ''))
if (key === 'name') {
acc += tokensPerName
}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 07c70f0b5b6..e58cce83427 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1536,7 +1536,7 @@ importers:
version: 2.11.3(@types/[email protected])([email protected])
next-router-mock:
specifier: ^0.9.13
nitro:
specifier: 3.0.260903-beta
version: 3.0.260903-beta
@@ -1842,11 +1842,11 @@ importers:
specifier: ^3.0.0
version: 3.1.1(@types/[email protected])([email protected])
'@next/bundle-analyzer':
- specifier: 15.3.1
- version: 15.3.1
+ specifier: 16.3.6
+ version: 16.3.6
'@next/mdx':
- specifier: 15.3.1
+ specifier: 16.3.6
'@octokit/auth-app':
specifier: ^7.0.0
version: 7.1.5
@@ -1864,7 +1864,7 @@ importers:
version: 21.1.1
'@sentry/nextjs':
specifier: 'catalog:'
'@supabase/ssr':
specifier: 'catalog:'
version: 0.12.7(@supabase/[email protected](@opentelemetry/[email protected]))
@@ -1962,20 +1962,20 @@ importers:
specifier: 'catalog:'
next:
- specifier: ^15.5.24
+ specifier: 'catalog:'
next-mdx-remote-client:
specifier: ^1.1.7
next-seo:
specifier: ^6.5.0
next-themes:
specifier: 'catalog:'
nuqs:
specifier: ^2.8.1
ogl:
specifier: ^1.0.11
version: 1.0.11
@@ -2050,7 +2050,7 @@ importers:
version: link:../../packages/ui-patterns
unicornstudio-react:
specifier: 2.0.1-1
use-debounce:
specifier: ^7.0.1
version: 7.0.1([email protected])
@@ -2297,9 +2297,6 @@ importers:
config:
specifier: workspace:*
version: link:../config
- js-tiktoken:
- specifier: ^1.0.10
- version: 1.0.10
jsonrepair:
specifier: ^3.5.0
version: 3.5.0
@@ -5699,6 +5696,9 @@ packages:
resolution: {integrity: sha512-aDwW4f4SVqbQDWzSBHQJ1KI6H+lx8oX/vS3xGqzLajUu+KQb7uakK88AIMvRIf7TlIonce67g594rzpxvBuJIw==}
+ resolution: {integrity: sha512-RArYF3j4Lpuv+Wc4sis6SBeeqBQdz6M/SUcU182D/NXtpvK8sEwZN2rhxWTGJXLVELwqFSWKNaGUad3b2NYwTw==}
+
resolution: {integrity: sha512-DuhvCtj4t9Gwrx80dmz2F4t/zKQ4ktN8WrMwOuVzkJfBilwAwGr6v16M5eI8yCuZ63H9TTuEU09Iu2HqkzFPVQ==}
@@ -5722,6 +5722,17 @@ packages:
'@mdx-js/react':
optional: true
+ resolution: {integrity: sha512-zyKSWE8aZDEkJ/EIooGCFqcySAhzgmepx+IOoMXFfJYEipoOranQ0r2uYItm9H9kYw1QLdfMJA0Zmio4/DWO1g==}
+ peerDependencies:
+ '@mdx-js/loader': '>=0.15.0'
+ '@mdx-js/react': '>=0.15.0'
+ peerDependenciesMeta:
+ '@mdx-js/loader':
+ optional: true
+ '@mdx-js/react':
+ optional: true
+
resolution: {integrity: sha512-w+RR0v/QuApnWEjRGm1z6gcObKwGMb5YPA7V3bzBEVSBpMFUXprer0tS27UxjUcEnqbhL7Zuzohej79B6rYmBg==}
engines: {node: '>= 10'}
@@ -13809,9 +13820,6 @@ packages:
resolution: {integrity: sha512-X2BB11YZtrRqY4EnQcLX5Rh373zbK4alC1FW7D7MBhL2gtcC17cTnr6DmfHZeS0s2rTHjUTMMHfG7gO8SSdw+g==}
engines: {node: '>=0.10.0'}
- resolution: {integrity: sha512-ZoSxbGjvGyMT13x6ACo9ebhDha/0FHdKA+OsQcMOWcm1Zs7r90Rhk5lhERLzji+3rA7EKpXCgwXcM5fF3DMpdA==}
-
resolution: {integrity: sha512-lM/UBzQmfJRo9ABXbPWemivdCW8V2G8FHaHdypQaIy523snUjog0W71ayWXTjiR+ixeMyVHN2XcpnTd/liPg/Q==}
@@ -22503,6 +22511,13 @@ snapshots:
- bufferutil
- utf-8-validate
+ dependencies:
+ webpack-bundle-analyzer: 4.10.1
+ transitivePeerDependencies:
+ - bufferutil
+ - utf-8-validate
+
'@next/[email protected]': {}
'@next/[email protected]': {}
@@ -22520,6 +22535,13 @@ snapshots:
'@mdx-js/react': 3.1.1(@types/[email protected])([email protected])
+ dependencies:
+ source-map: 0.7.6
+ optionalDependencies:
+ '@mdx-js/react': 3.1.1(@types/[email protected])([email protected])
+
optional: true
@@ -24904,7 +24926,7 @@ snapshots:
- vite
- webpack
dependencies:
'@opentelemetry/api': 1.9.1
'@rollup/plugin-commonjs': 28.0.1([email protected])
@@ -24912,12 +24934,12 @@ snapshots:
'@sentry/bundler-plugin-core': 5.3.0([email protected])([email protected])
'@sentry/conventions': 0.12.0
'@sentry/core': 10.59.0
'@sentry/opentelemetry': 10.59.0(@opentelemetry/[email protected])(@opentelemetry/[email protected](@opentelemetry/[email protected]))(@opentelemetry/[email protected](@opentelemetry/[email protected]))
'@sentry/react': 10.59.0([email protected])
'@sentry/vercel-edge': 10.59.0
rollup: 4.60.3
stacktrace-parser: 0.1.11
transitivePeerDependencies:
@@ -24930,7 +24952,7 @@ snapshots:
- vite
- webpack
dependencies:
'@opentelemetry/api': 1.9.1
'@rollup/plugin-commonjs': 28.0.1([email protected])
@@ -24938,12 +24960,12 @@ snapshots:
'@sentry/bundler-plugin-core': 5.3.0([email protected])([email protected])
'@sentry/conventions': 0.12.0
'@sentry/core': 10.59.0
'@sentry/opentelemetry': 10.59.0(@opentelemetry/[email protected])(@opentelemetry/[email protected](@opentelemetry/[email protected]))(@opentelemetry/[email protected](@opentelemetry/[email protected]))
'@sentry/react': 10.59.0([email protected])
'@sentry/vercel-edge': 10.59.0
rollup: 4.60.3
stacktrace-parser: 0.1.11
transitivePeerDependencies:
@@ -30454,7 +30476,7 @@ snapshots:
jose: 5.9.6
optionalDependencies:
'@opentelemetry/api': 1.9.1
react: 19.2.6
react-dom: 19.2.6([email protected])
@@ -31822,10 +31844,6 @@ snapshots:
- dependencies:
- base64-js: 1.5.1
-
@@ -33752,14 +33770,19 @@ snapshots:
dependencies:
js-yaml-loader: 1.2.2
dependencies:
react: 19.2.6
+ dependencies:
+ react: 19.2.6
+
dependencies:
react: 19.2.6
react-dom: 19.2.6([email protected])
@@ -33797,24 +33820,53 @@ snapshots:
- '@types/node'
- babel-plugin-macros
dependencies:
- '@next/env': 15.5.25
- '@swc/helpers': 0.5.15
+ '@next/env': 16.3.6
+ '@swc/helpers': 0.5.23
+ baseline-browser-mapping: 2.11.13
caniuse-lite: 1.0.30001809
postcss: 8.5.28
react: 19.2.6
react-dom: 19.2.6([email protected])
optionalDependencies:
- '@next/swc-darwin-arm64': 15.5.25
- '@next/swc-darwin-x64': 15.5.25
- '@next/swc-linux-arm64-gnu': 15.5.25
- '@next/swc-linux-arm64-musl': 15.5.25
- '@next/swc-linux-x64-gnu': 15.5.25
- '@next/swc-linux-x64-musl': 15.5.25
- '@next/swc-win32-arm64-msvc': 15.5.25
- '@next/swc-win32-x64-msvc': 15.5.25
+ '@next/swc-darwin-arm64': 16.3.6
+ '@next/swc-darwin-x64': 16.3.6
+ '@next/swc-linux-arm64-gnu': 16.3.6
+ '@next/swc-linux-arm64-musl': 16.3.6
+ '@next/swc-linux-x64-gnu': 16.3.6
+ '@next/swc-linux-x64-musl': 16.3.6
+ '@next/swc-win32-arm64-msvc': 16.3.6
+ '@next/swc-win32-x64-msvc': 16.3.6
+ '@opentelemetry/api': 1.9.1
+ '@playwright/test': 1.59.1
+ sass: 1.77.4
+ sharp: 0.35.4(@types/[email protected])
+ transitivePeerDependencies:
+ - '@babel/core'
+ - '@types/node'
+ - babel-plugin-macros
+
+ dependencies:
+ '@next/env': 16.3.6
+ '@swc/helpers': 0.5.23
+ baseline-browser-mapping: 2.11.13
+ caniuse-lite: 1.0.30001809
+ postcss: 8.5.28
+ react: 19.2.6
+ react-dom: 19.2.6([email protected])
+ optionalDependencies:
+ '@next/swc-darwin-arm64': 16.3.6
+ '@next/swc-darwin-x64': 16.3.6
+ '@next/swc-linux-arm64-gnu': 16.3.6
+ '@next/swc-linux-arm64-musl': 16.3.6
+ '@next/swc-linux-x64-gnu': 16.3.6
+ '@next/swc-linux-x64-musl': 16.3.6
+ '@next/swc-win32-arm64-msvc': 16.3.6
+ '@next/swc-win32-x64-msvc': 16.3.6
'@opentelemetry/api': 1.9.1
'@playwright/test': 1.59.1
sass: 1.77.4
@@ -33824,7 +33876,7 @@ snapshots:
- '@types/node'
- babel-plugin-macros
dependencies:
'@next/env': 16.3.6
'@swc/helpers': 0.5.23
@@ -34146,13 +34198,13 @@ snapshots:
dependencies:
'@standard-schema/spec': 1.0.0
react: 19.2.6
optionalDependencies:
'@tanstack/react-router': 1.170.44([email protected]([email protected]))([email protected])
@@ -37570,12 +37622,12 @@ snapshots:
dependencies:
react: 19.2.6
react-dom: 19.2.6([email protected])
optionalDependencies:
dependencies: