Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

feat: default avatars to public, gate private behind Pro + add X posting

nirholasfc20cfcc5154
diff --git a/api/_lib/migrations/2026-05-13-avatars-default-public.sql b/api/_lib/migrations/2026-05-13-avatars-default-public.sql
new file mode 100644
index 000000000..e22e71942
--- /dev/null
+++ b/api/_lib/migrations/2026-05-13-avatars-default-public.sql
@@ -0,0 +1,4 @@
+-- Avatars are now public by default. Private visibility is gated to paid plans.
+-- This only changes the column default for new rows; existing rows are not modified.
+
+alter table avatars alter column visibility set default 'public';
diff --git a/api/_lib/migrations/2026-05-13-x-post-quota.sql b/api/_lib/migrations/2026-05-13-x-post-quota.sql
new file mode 100644
index 000000000..a3c34f1cf
--- /dev/null
+++ b/api/_lib/migrations/2026-05-13-x-post-quota.sql
@@ -0,0 +1,17 @@
+-- Quota tracking for automated X posts.
+-- Free tier: 5 posts per calendar month. Pro tier (via subscriptions table) bypasses.
+
+alter table social_connections add column if not exists posts_this_month int not null default 0;
+alter table social_connections add column if not exists month_resets_at timestamptz not null default date_trunc('month', now()) + interval '1 month';
+
+create table if not exists x_posts (
+ id uuid primary key default gen_random_uuid(),
+ user_id uuid not null references users(id) on delete cascade,
+ agent_id text,
+ tweet_id text not null,
+ text text not null,
+ created_at timestamptz not null default now()
+);
+
+create index if not exists x_posts_user_idx on x_posts(user_id, created_at desc);
+create index if not exists x_posts_agent_idx on x_posts(agent_id, created_at desc);
diff --git a/api/_lib/plans.js b/api/_lib/plans.js
new file mode 100644
index 000000000..3d8e81890
--- /dev/null
+++ b/api/_lib/plans.js
@@ -0,0 +1,17 @@
+import { sql } from './db.js';
+
+const PAID_PLANS = new Set(['pro', 'team', 'enterprise', 'admin']);
+
+export async function getUserPlan(userId) {
+ if (!userId) return 'free';
+ const rows = await sql`select plan from users where id = ${userId} limit 1`;
+ return rows[0]?.plan || 'free';
+}
+
+export function isPaidPlan(plan) {
+ return PAID_PLANS.has(plan);
+}
+
+export async function userHasPaidPlan(userId) {
+ return isPaidPlan(await getUserPlan(userId));
+}
diff --git a/api/_lib/schema.sql b/api/_lib/schema.sql
index 9a6c53893..3e926e5e9 100644
--- a/api/_lib/schema.sql
+++ b/api/_lib/schema.sql
@@ -41,7 +41,7 @@ create table if not exists avatars (
source text not null default 'upload' check (source in ('upload','avaturn','import')),
source_meta jsonb not null default '{}'::jsonb,
thumbnail_key text,
- visibility text not null default 'private' check (visibility in ('private','unlisted','public')),
+ visibility text not null default 'public' check (visibility in ('private','unlisted','public')),
tags text[] not null default '{}',
checksum_sha256 text,
version int not null default 1,
diff --git a/api/_lib/validate.js b/api/_lib/validate.js
index d820fd80e..0747146e3 100644
--- a/api/_lib/validate.js
+++ b/api/_lib/validate.js
@@ -48,7 +48,7 @@ export const createAvatarBody = z.object({
name: z.string().trim().min(1).max(120),
slug: slug.optional(),
description: z.string().trim().max(2000).optional(),
- visibility: avatarVisibility.default('private'),
+ visibility: avatarVisibility.default('public'),
tags: z.array(z.string().trim().min(1).max(40)).max(20).default([]),
source: z.enum(['upload', 'avaturn', 'import', 'direct-upload']).default('upload'),
parent_avatar_id: z.string().uuid().optional(),
diff --git a/api/auth/x/[action].js b/api/auth/x/[action].js
index a78d71c02..775c68e26 100644
--- a/api/auth/x/[action].js
+++ b/api/auth/x/[action].js
@@ -86,7 +86,7 @@ async function handleConnect(req, res) {
authUrl.searchParams.set('response_type', 'code');
authUrl.searchParams.set('client_id', env.X_OAUTH_CLIENT_ID);
authUrl.searchParams.set('redirect_uri', `${env.APP_ORIGIN}/api/auth/x/callback`);
- authUrl.searchParams.set('scope', 'tweet.read users.read offline.access');
+ authUrl.searchParams.set('scope', 'tweet.read tweet.write users.read offline.access');
authUrl.searchParams.set('state', state);
authUrl.searchParams.set('code_challenge', codeChallenge);
authUrl.searchParams.set('code_challenge_method', 'S256');
diff --git a/api/avatars/[id].js b/api/avatars/[id].js
index a5fa45ce6..9d0c97afa 100644
--- a/api/avatars/[id].js
+++ b/api/avatars/[id].js
@@ -20,6 +20,7 @@ import { recordEvent } from '../_lib/usage.js';
import { z } from 'zod';
import { avatarVisibility, parse } from '../_lib/validate.js';
import { DEMO_AVATARS } from '../_lib/demo-avatars.js';
+import { userHasPaidPlan } from '../_lib/plans.js';
const patchSchema = z.object({
name: z.string().trim().min(1).max(120).optional(),
@@ -101,6 +102,14 @@ export default wrap(async (req, res) => {
return handleGlbPatch(res, auth, id, body.glbUrl);
}
const patch = parse(patchSchema, body);
+ if (patch.visibility === 'private' && !(await userHasPaidPlan(auth.userId))) {
+ return error(
+ res,
+ 402,
+ 'plan_required',
+ 'private avatars require a Pro plan — upgrade at /dashboard/#billing or set visibility to public/unlisted',
+ );
+ }
const avatar = await updateAvatar({ id, userId: auth.userId, patch });
if (!avatar) return error(res, 404, 'not_found', 'avatar not found or not yours');
return json(res, 200, { avatar });
diff --git a/api/avatars/index.js b/api/avatars/index.js
index 24bb87c9f..c672732a4 100644
--- a/api/avatars/index.js
+++ b/api/avatars/index.js
@@ -11,6 +11,7 @@ import { cors, json, method, readJson, wrap, error } from '../_lib/http.js';
import { parse, createAvatarBody } from '../_lib/validate.js';
import { recordEvent } from '../_lib/usage.js';
import { defaultStorageMode } from '../_lib/storage-mode.js';
+import { userHasPaidPlan } from '../_lib/plans.js';
import { z } from 'zod';
const createWithStorage = createAvatarBody.extend({
@@ -44,6 +45,15 @@ async function handleCreate(req, res) {
if (!auth) return error(res, 401, 'unauthorized', 'avatars:write scope required');
const body = parse(createWithStorage, await readJson(req));
+ if (body.visibility === 'private' && !(await userHasPaidPlan(auth.userId))) {
+ return error(
+ res,
+ 402,
+ 'plan_required',
+ 'private avatars require a Pro plan — upgrade at /dashboard/#billing or set visibility to public/unlisted',
+ );
+ }
+
// Storage keys are scoped by userId (see storageKeyFor). Enforce that the
// caller can only register objects under their own prefix — otherwise a
// user could claim another user's freshly uploaded object.
diff --git a/api/x/post.js b/api/x/post.js
new file mode 100644
index 000000000..1d15e77a3
--- /dev/null
+++ b/api/x/post.js
@@ -0,0 +1,122 @@
+// POST /api/x/post — publish a tweet on behalf of the signed-in user's
+// connected X account. Free tier: 5 posts per calendar month. When over the
+// limit, returns 402 with an upgrade pointer.
+
+import { sql } from '../_lib/db.js';
+import { getSessionUser } from '../_lib/auth.js';
+import { cors, method, wrap, error, readJson, json } from '../_lib/http.js';
+import { env } from '../_lib/env.js';
+import { encryptToken, decryptToken } from '../auth/x/[action].js';
+
+const FREE_MONTHLY_QUOTA = 5;
+const MAX_TWEET_LEN = 280;
+
+async function refreshIfNeeded(conn) {
+ const expiresAt = conn.expires_at ? new Date(conn.expires_at).getTime() : 0;
+ const stillValid = expiresAt - Date.now() > 60_000;
+ if (stillValid) return decryptToken(conn.access_token);
+ if (!conn.refresh_token) throw Object.assign(new Error('refresh_token missing — reconnect X account'), { status: 401, code: 'reauth_required' });
+
+ const refreshToken = decryptToken(conn.refresh_token);
+ const creds = Buffer.from(`${env.X_OAUTH_CLIENT_ID}:${env.X_OAUTH_CLIENT_SECRET}`).toString('base64');
+ const r = await fetch('https://api.twitter.com/2/oauth2/token', {
+ method: 'POST',
+ headers: { 'content-type': 'application/x-www-form-urlencoded', authorization: `Basic ${creds}` },
+ body: new URLSearchParams({ grant_type: 'refresh_token', refresh_token: refreshToken, client_id: env.X_OAUTH_CLIENT_ID }).toString(),
+ });
+ if (!r.ok) throw Object.assign(new Error(`X token refresh failed: ${await r.text()}`), { status: 401, code: 'reauth_required' });
+ const tok = await r.json();
+ const newExpiresAt = new Date(Date.now() + (tok.expires_in ?? 7200) * 1000).toISOString();
+ await sql`
+ update social_connections
+ set access_token = ${encryptToken(tok.access_token)},
+ refresh_token = ${tok.refresh_token ? encryptToken(tok.refresh_token) : conn.refresh_token},
+ expires_at = ${newExpiresAt},
+ updated_at = now()
+ where id = ${conn.id}
+ `;
+ return tok.access_token;
+}
+
+export default wrap(async (req, res) => {
+ if (cors(req, res, { methods: 'POST,OPTIONS', credentials: true })) return;
+ if (!method(req, res, ['POST'])) return;
+
+ if (!env.X_OAUTH_CLIENT_ID || !env.X_OAUTH_CLIENT_SECRET) {
+ return error(res, 501, 'not_configured', 'X OAuth is not configured');
+ }
+
+ const user = await getSessionUser(req);
+ if (!user) return error(res, 401, 'unauthorized', 'sign in required');
+
+ const body = await readJson(req);
+ const text = typeof body?.text === 'string' ? body.text.trim() : '';
+ const agentId = typeof body?.agent_id === 'string' ? body.agent_id : null;
+ if (!text) return error(res, 400, 'validation_error', 'text required');
+ if (text.length > MAX_TWEET_LEN) return error(res, 400, 'validation_error', `text exceeds ${MAX_TWEET_LEN} chars`);
+
+ const rows = await sql`
+ select * from social_connections
+ where user_id = ${user.id} and provider = 'x' and disconnected_at is null
+ limit 1
+ `;
+ const conn = rows[0];
+ if (!conn) return error(res, 400, 'not_connected', 'connect X account first at /api/auth/x/connect');
+
+ // Reset monthly counter if we crossed the boundary.
+ if (new Date(conn.month_resets_at) <= new Date()) {
+ await sql`
+ update social_connections
+ set posts_this_month = 0,
+ month_resets_at = date_trunc('month', now()) + interval '1 month'
+ where id = ${conn.id}
+ `;
+ conn.posts_this_month = 0;
+ }
+
+ if (conn.posts_this_month >= FREE_MONTHLY_QUOTA) {
+ return error(res, 402, 'quota_exceeded', `free tier limit of ${FREE_MONTHLY_QUOTA} posts/month reached`, {
+ posts_used: conn.posts_this_month,
+ quota: FREE_MONTHLY_QUOTA,
+ month_resets_at: conn.month_resets_at,
+ upgrade_url: '/pricing',
+ });
+ }
+
+ let accessToken;
+ try {
+ accessToken = await refreshIfNeeded(conn);
+ } catch (err) {
+ return error(res, err.status || 500, err.code || 'token_error', err.message);
+ }
+
+ const tweetRes = await fetch('https://api.twitter.com/2/tweets', {
+ method: 'POST',
+ headers: { 'content-type': 'application/json', authorization: `Bearer ${accessToken}` },
+ body: JSON.stringify({ text }),
+ });
+ if (!tweetRes.ok) {
+ const detail = await tweetRes.text();
+ console.error('[x-post] tweet failed', tweetRes.status, detail);
+ return error(res, 502, 'tweet_failed', `X API error: ${detail.slice(0, 200)}`);
+ }
+ const { data } = await tweetRes.json();
+
+ await sql`
+ update social_connections
+ set posts_this_month = posts_this_month + 1,
+ updated_at = now()
+ where id = ${conn.id}
+ `;
+ await sql`
+ insert into x_posts (user_id, agent_id, tweet_id, text)
+ values (${user.id}, ${agentId}, ${data.id}, ${text})
+ `;
+
+ return json(res, 200, {
+ tweet_id: data.id,
+ url: `https://x.com/${conn.username}/status/${data.id}`,
+ posts_used: conn.posts_this_month + 1,
+ quota: FREE_MONTHLY_QUOTA,
+ });
+});
diff --git a/public/dashboard/dashboard.js b/public/dashboard/dashboard.js
index 2546eb755..1663a0a3f 100644
--- a/public/dashboard/dashboard.js
+++ b/public/dashboard/dashboard.js
@@ -484,9 +484,9 @@ function renderUpload(root) {
<label style="display:block;margin-top:12px">Description<textarea id="desc" rows="2" style="width:100%"></textarea></label>
<label style="display:block;margin-top:12px">Visibility
<select id="vis" style="width:100%">
- <option value="private">Private (only you)</option>
+ <option value="public" selected>Public (discoverable)</option>
<option value="unlisted">Unlisted (anyone with link)</option>
- <option value="public">Public (discoverable)</option>
+ <option value="private" data-paid>Private (Pro plan)</option>
</select>
</label>
<label style="display:block;margin-top:12px">Tags (comma separated)<input id="tags" style="width:100%"></label>
@@ -622,7 +622,7 @@ async function saveAvaturnAvatar(blob) {
content_type: contentType,
checksum_sha256: checksum,
name: `Avatar ${new Date().toLocaleDateString()}`,
- visibility: 'private',
+ visibility: 'public',
tags: [],
source: 'import',
source_meta: { provider: 'avaturn' },
diff --git a/vercel.json b/vercel.json
index f64916969..504275250 100644
--- a/vercel.json
+++ b/vercel.json
@@ -212,6 +212,11 @@
"src": "/dashboard/embed-policy",
"dest": "/dashboard/embed-policy.html"
},
+ {
+ "src": "/dashboard/(avatars|create|upload|animations|widgets|embed|keys|mcp|monetization|payments|subscriptions|billing|revenue|earnings|account)/?",
+ "status": 308,
+ "headers": { "Location": "/dashboard#$1" }
+ },
{
"src": "/dashboard/(.*)",
"dest": "/dashboard/$1"