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.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
feat(settings): make the default avatar visibility preference actually govern new avatars
nirholas4d0c175dbc6d
diff --git a/api/_lib/avatars.js b/api/_lib/avatars.jsindex f190a5a65..3fa5a0cec 100644--- a/api/_lib/avatars.js+++ b/api/_lib/avatars.js@@ -149,6 +149,19 @@ export async function getAvatarBySlug({ ownerId, slug, requesterId = null }) {return decorate(row);}+// The owner's "Default avatar visibility" preference from /settings, or+// `fallback` when they have never expressed one. Create paths call this only+// when the request itself did not name a visibility, so an explicit choice by+// the caller (a selfie that is deliberately private, an auto-rig sibling that+// inherits its source) always wins over the account default.+export async function defaultAvatarVisibilityFor(userId, fallback = 'private') {+ if (!userId) return fallback;+ const rows = await sql`+ select default_avatar_visibility from users where id = ${userId} and deleted_at is null limit 1+ `;+ return rows[0]?.default_avatar_visibility || fallback;+}+export async function createAvatar({ userId, input, storageKey }) {await enforceQuotas(userId, input.size_bytes);const finalSlug = input.slug || (await generateSlug(userId, input.name));diff --git a/api/_lib/migrations/20260903235000_user_default_avatar_visibility.sql b/api/_lib/migrations/20260903235000_user_default_avatar_visibility.sqlnew file mode 100644index 000000000..d8a7290ae--- /dev/null+++ b/api/_lib/migrations/20260903235000_user_default_avatar_visibility.sql@@ -0,0 +1,19 @@+begin;++-- The owner's default visibility for newly created avatars.+--+-- /settings has offered a "Default avatar visibility" control since the page+-- shipped, but it only ever wrote localStorage: nothing on the server read it,+-- so a user who chose "Private" still got whatever each create path hardcoded.+-- A privacy control that silently does nothing is worse than no control, so the+-- preference now lives here and the create paths read it.+--+-- Nullable on purpose. NULL means "no preference expressed", and every create+-- path keeps its own existing default in that case (private for a direct+-- upload, unlisted for a forge import), so nothing changes for the accounts+-- that never open the setting.+alter table users+ add column if not exists default_avatar_visibility text+ check (default_avatar_visibility in ('private', 'unlisted', 'public'));++commit;diff --git a/api/auth/[action].js b/api/auth/[action].jsindex ee77237cb..402816ac6 100644--- a/api/auth/[action].js+++ b/api/auth/[action].js@@ -14,7 +14,7 @@ import { cors, json, method, readJson, wrap, error, rateLimited } from '../_lib/import { requireCsrf } from '../_lib/csrf.js';import { limits, clientIp } from '../_lib/rate-limit.js';import captcha, { verifyBypassToken } from './captcha.js';-import { parse, loginBody, registerBody, usernameRegisterBody, username as usernameValidator, displayName, email, password, bio as bioValidator, profileLocation, httpUrl } from '../_lib/validate.js';+import { parse, loginBody, registerBody, usernameRegisterBody, username as usernameValidator, displayName, email, password, bio as bioValidator, profileLocation, httpUrl, avatarVisibility } from '../_lib/validate.js';import { sendPasswordResetEmail, sendVerificationEmail } from '../_lib/email.js';import { referralCodeCandidates, normalizeReferralCode } from '../_lib/referrals.js';import { seedDefaultAgent } from '../_lib/seed-default-agent.js';@@ -233,7 +233,22 @@ async function handleMe(req, res) {res.setHeader('Set-Cookie', sessionCookie('', { clear: true }));return error(res, 401, 'invalid_session', 'session expired or revoked');}- return json(res, 200, { user });+ // getSessionUser runs on every authenticated request, so its projection stays+ // minimal. These two columns are account settings rather than session state:+ // read them here, where /settings is the caller that needs them. Without+ // email_verified the settings badge could only ever render "Unverified", which+ // is what it did for every verified account until this row was added.+ const [account] = await sql`+ select email_verified, default_avatar_visibility+ from users where id = ${user.id} and deleted_at is null limit 1+ `;+ return json(res, 200, {+ user: {+ ...user,+ email_verified: Boolean(account?.email_verified),+ default_avatar_visibility: account?.default_avatar_visibility || null,+ },+ });}// ── delete account (DELETE /api/auth/me) ──────────────────────────────────────@@ -327,6 +342,10 @@ const profileSchema = z.object({location: profileLocation.optional(),avatar_url: httpUrl.optional(),banner_url: httpUrl.optional(),+ // Account preference rather than public profile copy, but it belongs to the+ // same owner-writes-their-own-user-row contract this endpoint already covers.+ // Read back by the avatar create paths via defaultAvatarVisibilityFor().+ default_avatar_visibility: avatarVisibility.optional(),}).refine((b) => Object.keys(b).length > 0,{ message: 'at least one field required' },@@ -351,7 +370,8 @@ async function handleProfile(req, res) {const body = parse(profileSchema, await readJson(req));const [current] = await sql`- select username, display_name, bio, website, location, avatar_url, banner_url+ select username, display_name, bio, website, location, avatar_url, banner_url,+ default_avatar_visibilityfrom users where id = ${user.id} and deleted_at is null limit 1`;if (!current) return error(res, 401, 'unauthenticated', 'not signed in');@@ -370,6 +390,10 @@ async function handleProfile(req, res) {location: profileField(body.location, current.location),avatar_url: profileField(body.avatar_url, current.avatar_url),banner_url: profileField(body.banner_url, current.banner_url),+ default_avatar_visibility:+ body.default_avatar_visibility !== undefined+ ? body.default_avatar_visibility+ : current.default_avatar_visibility,};const [updated] = await sql`@@ -381,9 +405,11 @@ async function handleProfile(req, res) {location = ${next.location},avatar_url = ${next.avatar_url},banner_url = ${next.banner_url},+ default_avatar_visibility = ${next.default_avatar_visibility},updated_at = now()where id = ${user.id} and deleted_at is null- returning id, username, display_name, bio, website, location, avatar_url, banner_url+ returning id, username, display_name, bio, website, location, avatar_url, banner_url,+ default_avatar_visibility`;logAudit({userId: user.id,diff --git a/api/avatars/_actions.js b/api/avatars/_actions.jsindex 7c08238d3..0f341d26c 100644--- a/api/avatars/_actions.js+++ b/api/avatars/_actions.js@@ -3,7 +3,7 @@import { getSessionUser, authenticateBearer, extractBearer, hasScope } from '../_lib/auth.js';import { presignUpload, headObject, r2, publicUrl, putObject } from '../_lib/r2.js';-import { storageKeyFor, enforceQuotas, searchPublicAvatars, stripOwnerFor, assertAvatarSlotAvailable, isPlanLimitError } from '../_lib/avatars.js';+import { storageKeyFor, enforceQuotas, searchPublicAvatars, stripOwnerFor, assertAvatarSlotAvailable, isPlanLimitError, defaultAvatarVisibilityFor } from '../_lib/avatars.js';import { listAvatars } from '../_lib/avatars.js';import { env } from '../_lib/env.js';import { sql } from '../_lib/db.js';@@ -1272,7 +1272,9 @@ const handleReconstruct = wrap(async (req, res) => {images: photos,name: body.name,description: body.description ?? null,- visibility: body.visibility ?? 'private',+ // Same rule as POST /api/avatars: an explicit choice wins, silence falls+ // back to the owner's default from /settings.+ visibility: body.visibility ?? (await defaultAvatarVisibilityFor(userId, 'private')),...(body.prompt? { source: 'prompt', prompt: body.prompt, referenceImageUrl }: {}),diff --git a/api/avatars/from-forge.js b/api/avatars/from-forge.jsindex e013b00bb..233629432 100644--- a/api/avatars/from-forge.js+++ b/api/avatars/from-forge.js@@ -25,7 +25,7 @@import { cors, json, method, readJson, wrap, error } from '../_lib/http.js';import { getSessionUser, authenticateBearer, extractBearer, hasScope } from '../_lib/auth.js';-import { storageKeyFor, createAvatar } from '../_lib/avatars.js';+import { storageKeyFor, createAvatar, defaultAvatarVisibilityFor } from '../_lib/avatars.js';import { putObject } from '../_lib/r2.js';import { isValidGlbHeader, inspectGlb } from '../_lib/glb-inspect.js';import { fetchSafePublicUrl, SsrfBlockedError } from '../_lib/ssrf-guard.js';@@ -78,7 +78,12 @@ export default wrap(async (req, res) => {if (!glbUrl) return error(res, 400, 'invalid_request', 'glb_url is required');if (!name) return error(res, 400, 'invalid_request', 'name is required (1–80 chars)');- const visibility = VISIBILITIES.has(body?.visibility) ? body.visibility : 'unlisted';+ // An explicit visibility from the caller wins; otherwise the owner's+ // "Default avatar visibility" preference from /settings decides, falling back+ // to the unlisted default this endpoint has always used.+ const visibility = VISIBILITIES.has(body?.visibility)+ ? body.visibility+ : await defaultAvatarVisibilityFor(auth.userId, 'unlisted');const sourcePrompt =typeof body?.source_prompt === 'string' ? body.source_prompt.slice(0, 1000) : null;const rigged = body?.rigged === true;diff --git a/api/avatars/index.js b/api/avatars/index.jsindex d07d468ec..a45439c96 100644--- a/api/avatars/index.js+++ b/api/avatars/index.js@@ -2,7 +2,7 @@// POST /api/avatars — create avatar metadata after uploadimport { getSessionUser, authenticateBearer, extractBearer, hasScope } from '../_lib/auth.js';-import { listAvatars, createAvatar } from '../_lib/avatars.js';+import { listAvatars, createAvatar, defaultAvatarVisibilityFor } from '../_lib/avatars.js';import { headObject, r2 } from '../_lib/r2.js';import { inspectStorageKeyRig } from '../_lib/rig-inspect.js';import { HeadObjectCommand } from '@aws-sdk/client-s3';@@ -46,7 +46,16 @@ async function handleList(req, res) {async function handleCreate(req, res) {const auth = await resolveAuth(req, 'avatars:write');if (!auth) return error(res, 401, 'unauthorized', 'avatars:write scope required');- const body = parse(createWithStorage, await readJson(req));+ const raw = await readJson(req);+ const body = parse(createWithStorage, raw);++ // A caller that names a visibility always wins. Only when the request is+ // silent does the owner's "Default avatar visibility" preference from+ // /settings apply; with no preference stored it resolves to the same+ // 'private' the schema has always defaulted to.+ if (raw?.visibility === undefined) {+ body.visibility = await defaultAvatarVisibilityFor(auth.userId, 'private');+ }// Storage keys are scoped by userId (see storageKeyFor). Enforce that the// caller can only register objects under their own prefix — otherwise adiff --git a/api/chat.js b/api/chat.jsindex 3ce55667d..e6e336896 100644--- a/api/chat.js+++ b/api/chat.js@@ -448,13 +448,16 @@ const DEFAULT_TOOL_SET = Object.freeze({ anthropic: ACTION_TOOLS, openai: OPENAI/*** Server-side home rounds per turn.*- * Two, because the shape a person actually asks for is "check the house, then do- * the thing": read the state, act on what it said. One round produced an agent- * that answered "I don't have a tool for that" after reading the house, which is- * both useless and untrue. The last round is offered no home tools at all, so- * the ceiling is a hard stop rather than a heuristic.+ * Three, measured rather than guessed. The shape a person actually asks for is+ * "check the house, then do the thing", and the tool descriptions deliberately+ * tell the model to look for an existing scene before composing its own call, so+ * a single act costs up to three steps: read the state, list the macros, then+ * act. At two rounds a real Claude turn on "unlock the front door" spent both on+ * reads and answered without ever asking, which is a worse failure than a slow+ * one. The last round is offered no home tools at all, so the ceiling is a hard+ * stop rather than a hope.*/-const HOME_TOOL_ROUNDS = 2;+const HOME_TOOL_ROUNDS = 3;export default wrap(async (req, res) => {if (cors(req, res, { methods: 'POST,OPTIONS', credentials: true })) return;@@ -1255,6 +1258,25 @@ async function runHomeRound(calls, userId) {return out;}+/** How much of a house may ride back into one prompt. A big house is still a prompt. */+const HOME_RESULT_MAX_CHARS = 12_000;++function toolResultText(result) {+ let data = '';+ try {+ data = JSON.stringify(result.structured ?? {});+ } catch {+ data = '{}';+ }+ if (data.length > HOME_RESULT_MAX_CHARS) {+ // A house with thousands of entities must not be able to fill a context+ // window. Truncating says so out loud rather than handing the model a+ // silently partial view of somebody's home.+ data = `${data.slice(0, HOME_RESULT_MAX_CHARS)}… (truncated; narrow the request, for example home_status with a room)`;+ }+ return `${result.text}\n\n${data}`;+}+/*** A second model pass carrying the tool results, so the agent can speak about* what the house actually said.@@ -1276,11 +1298,19 @@ async function runHomeRound(calls, userId) {async function runFollowUpPass({ route, systemPrompt, sys, history, maxTokens, assistantText, toolCalls, homeResults, toolSet, sendSSE }) {if (route.style === 'orchestrate') return null;- const resultText = new Map(homeResults.map((entry) => [entry.call.id, entry.result]));+ const byId = new Map(homeResults.map((entry) => [entry.call.id, entry.result]));const answerFor = (call) => {- const result = resultText.get(call.id);- if (result) return { text: result.text, isError: result.kind === 'error' };- return { text: 'Queued in the viewer; it is running there now.', isError: false };+ const result = byId.get(call.id);+ if (!result) return { text: 'Queued in the viewer; it is running there now.', isError: false };+ // The summary AND the structured data. Neither wire format has a+ // structuredContent field the way MCP does, and sending only the prose left+ // the model unable to name a single entity: it read "67 entities" and then+ // called home_status again looking for an id that was never in what it was+ // given. The data goes in as a JSON value, which is the closest this+ // transport gets to structured content, and it is the same content the MCP+ // surface returns. It is untrusted either way, which is precisely why the+ // gate sits downstream of this and not upstream.+ return { text: toolResultText(result), isError: result.kind === 'error' };};const anthropic = route.style === 'anthropic';diff --git a/chat/index.html b/chat/index.htmlindex dd6406929..ae7d6b749 100644--- a/chat/index.html+++ b/chat/index.html@@ -28,6 +28,11 @@<meta name="twitter:description" content="Talk to your agent: voice, text, and real tool use in one interface, with 3D generation inline in the thread." /><meta name="twitter:image" content="https://three.ws/api/page-og?s=agent-tools&t=Chat&d=Talk+to+your+agent.+Voice%2C+text%2C+and+tool-use+in+one+interface.&p=%2Fchat" />+ <!-- jsdelivr is on the critical path (the render-blocking KaTeX stylesheet+ directly below, then three.js from the importmap). Starting the DNS ++ TCP + TLS handshake here means the parser is not paying for it when it+ reaches that <link>. -->+ <link rel="preconnect" href="https://cdn.jsdelivr.net" crossorigin /><link rel="preload" href="/fonts/inter-latin.woff2" as="font" type="font/woff2" crossorigin /><link rel="preload" href="/fonts/space-grotesk-latin.woff2" as="font" type="font/woff2" crossorigin /><link rel="stylesheet" href="/fonts/fonts.css" />diff --git a/public/register.html b/public/register.htmlindex 67e7668f6..2c2a97a16 100644--- a/public/register.html+++ b/public/register.html@@ -433,6 +433,11 @@}#privy-toggle-btn:hover { background: #161616; border-color: rgba(255,255,255,0.18); color: #fff; }#privy-toggle-btn svg { flex-shrink: 0; }+ .privy-toggle-chev { opacity: 0.55; transition: transform 0.18s ease; }+ #privy-toggle-btn[aria-expanded='true'] .privy-toggle-chev { transform: rotate(180deg); }+ @media (prefers-reduced-motion: reduce) {+ .privy-toggle-chev { transition: none; }+ }#privy-expanded { margin-top: 8px; }.privy-row { display: flex; gap: 8px; align-items: flex-start; }.privy-row input { flex: 1; margin: 0; }@@ -453,17 +458,17 @@padding: 0; text-decoration: underline; text-underline-offset: 2px; width: auto;}.privy-back-link:hover { color: #888; }- .privy-wallet-divider { margin: 10px 0 8px; text-align: center; font-size: 11px; color: #999; letter-spacing: 0.04em; }+ .privy-wallet-divider { margin: 10px 0 8px; text-align: center; font-size: 11px; color: #8a8a8a; letter-spacing: 0.04em; }.privy-chain-btns { display: flex; gap: 8px; }.privy-chain-btn {flex: 1; margin: 0; padding: 10px 12px;- background: transparent; border: 1px solid rgba(0,0,0,0.12);- border-radius: 10px; color: #555; font-size: 13px; font-weight: 500;+ background: transparent; border: 1px solid rgba(255,255,255,0.12);+ border-radius: 10px; color: #ccc; font-size: 13px; font-weight: 500;cursor: pointer; display: flex; align-items: center; justify-content: center;gap: 7px; transition: background 0.12s, border-color 0.12s, color 0.12s;white-space: nowrap;}- .privy-chain-btn:hover:not(:disabled) { background: rgba(0,0,0,0.04); border-color: rgba(0,0,0,0.22); color: #000; }+ .privy-chain-btn:hover:not(:disabled) { background: rgba(255,255,255,0.06); border-color: rgba(255,255,255,0.22); color: #fff; }.privy-chain-btn:disabled { opacity: 0.4; cursor: default; }#privy-wallet-status { margin: 6px 0 0; font-size: 12px; color: #888; }</style>@@ -499,21 +504,22 @@<!-- Privy social / email-OTP login --><div id="privy-section">- <button type="button" id="privy-toggle-btn">+ <button type="button" id="privy-toggle-btn" aria-expanded="false" aria-controls="privy-expanded"><svg width="18" height="18" viewBox="0 0 36 36" fill="none" aria-hidden="true"><rect width="36" height="36" rx="8" fill="#2563EB"/><path d="M18 8C12.477 8 8 12.477 8 18s4.477 10 10 10 10-4.477 10-10S23.523 8 18 8zm0 3a7 7 0 110 14A7 7 0 0118 11zm0 2a5 5 0 100 10A5 5 0 0018 13zm0 2a3 3 0 110 6 3 3 0 010-6z" fill="#fff" opacity=".9"/></svg>- Continue with Privy+ <span data-i18n="register.continue_with_privy">Continue with Privy</span>+ <svg class="privy-toggle-chev" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 9l6 6 6-6"/></svg></button><div id="privy-expanded" hidden><div id="privy-step-email"><div class="privy-row">- <input id="privy-email-input" type="email" inputmode="email" placeholder="Email address" autocomplete="email" autocapitalize="none" />+ <input id="privy-email-input" type="email" inputmode="email" placeholder="Email address" aria-label="Email address" data-i18n-attr="placeholder:register.email_address_placeholder;aria-label:register.email_address_arialabel" autocomplete="email" autocapitalize="none" /><button type="button" id="privy-send-btn" class="privy-row-btn" data-i18n="register.send_code">Send code</button></div><div id="privy-captcha-slot" aria-live="polite"></div></div><div id="privy-step-code" hidden><div class="privy-row">- <input id="privy-code-input" type="text" inputmode="numeric" placeholder="6-digit code" maxlength="6" autocomplete="one-time-code" />+ <input id="privy-code-input" type="text" inputmode="numeric" placeholder="6-digit code" aria-label="6-digit code" data-i18n-attr="placeholder:register.6_digit_code_placeholder;aria-label:register.6_digit_code_arialabel" maxlength="6" autocomplete="one-time-code" /><button type="button" id="privy-verify-btn" class="privy-row-btn" data-i18n="register.verify">Verify</button></div></div>@@ -678,6 +684,47 @@});})();+ // Privy disclosure.+ // The passwordless / wallet block ships collapsed so the username ++ // password form stays the visual default, but nothing ever opened it:+ // #privy-expanded kept its `hidden` attribute for the life of the page,+ // so email-OTP, EVM and Solana signup were all unreachable here.+ (function () {+ const btn = document.getElementById('privy-toggle-btn');+ const panel = document.getElementById('privy-expanded');+ const inlineErr = document.getElementById('privy-inline-err');+ if (!btn || !panel) return;++ function setOpen(open, moveFocus) {+ panel.hidden = !open;+ btn.setAttribute('aria-expanded', open ? 'true' : 'false');+ if (!moveFocus) return;+ if (open) document.getElementById('privy-email-input')?.focus();+ else btn.focus();+ }++ btn.addEventListener('click', () => setOpen(panel.hidden, true));++ // "Back" steps out of code entry first: privy-login.js resets the form+ // to the email step on this same click, and this handler runs before it+ // (inline script beats the deferred module), so read the step that is+ // still on screen. From the email step there is nowhere further back to+ // go, so the disclosure closes.+ document.getElementById('privy-back-btn')?.addEventListener('click', () => {+ const codeStep = document.getElementById('privy-step-code');+ if (!codeStep || codeStep.hidden) setOpen(false, true);+ });++ // privy-login.js reports a failed /api/config probe by unhiding this+ // line, which lives inside the collapsed panel. Open the panel so the+ // explanation is readable, without stealing focus from the form.+ if (inlineErr) {+ new MutationObserver(() => {+ if (!inlineErr.hidden && panel.hidden) setOpen(true, false);+ }).observe(inlineErr, { attributes: true, attributeFilter: ['hidden'] });+ }+ })();+// Password show/hide toggle(function () {const pw = document.getElementById('password');diff --git a/public/settings/index.html b/public/settings/index.htmlindex ad28424cc..887513457 100644--- a/public/settings/index.html+++ b/public/settings/index.html@@ -265,6 +265,46 @@font-weight: 500;}.link-row a.action:hover { color: #dddddd; }+ /* Keyboard focus was invisible on every control here except the text+ inputs, so a tab-only user could not tell where they were. One ring,+ applied to every focusable thing, in the page's accent. */+ a:focus-visible,+ button:focus-visible,+ input:focus-visible,+ select:focus-visible,+ textarea:focus-visible,+ [tabindex]:focus-visible {+ outline: 2px solid var(--accent);+ outline-offset: 2px;+ border-radius: 6px;+ }+ .visually-hidden {+ position: absolute;+ width: 1px;+ height: 1px;+ padding: 0;+ margin: -1px;+ overflow: hidden;+ clip: rect(0 0 0 0);+ white-space: nowrap;+ border: 0;+ }+ .load-error {+ border: 1px solid rgba(248,113,113,0.3);+ background: rgba(248,113,113,0.06);+ border-radius: 12px;+ padding: 20px;+ max-width: 520px;+ }+ .load-error h2 { font-size: 16px; margin: 0 0 6px; }+ .load-error p { color: #999; font-size: 13.5px; margin: 0 0 14px; }+ .verify-form { margin-top: 12px; }+ .verify-form .row { margin-top: 10px; }+ .verify-form input {+ max-width: 180px;+ letter-spacing: 0.28em;+ font-variant-numeric: tabular-nums;+ }.social-card {display: flex;align-items: center;@@ -422,11 +462,24 @@<a href="/dashboard#mcp" data-i18n="settings_index.mcp">MCP ↗</a><a href="/dashboard#billing" data-i18n="settings_index.plan_billing">Plan & Billing ↗</a><a href="/dashboard/account" data-i18n="settings_index.wallets">Wallets ↗</a>+ <a href="/dashboard/settings" data-i18n="settings_index.notifications">Notifications ↗</a><div class="aside-section">More</div><a href="#danger" data-tab="danger" data-i18n="settings_index.danger_zone">Danger Zone</a></aside><main>+ <!-- Shown instead of the tabs when the account itself could not be+ loaded. Every panel below is a projection of that one fetch, so a+ failure used to leave the whole page sitting on placeholder dashes+ with nothing to click. -->+ <div class="load-error" id="settings-load-error" style="display:none" role="alert">+ <h2 data-i18n="settings_index.couldnt_load_your_settings">Couldn't load your settings</h2>+ <p id="settings-load-error-body" data-i18n="settings_index.we_could_not_reach_your_account">We could not reach your account just now. Your settings are safe; this is a connection problem.</p>+ <div class="row">+ <button class="btn" id="settings-retry-btn" data-i18n="settings_index.try_again">Try again</button>+ <a class="btn sec" href="/dashboard" style="text-decoration:none" data-i18n="settings_index.go_to_dashboard">Go to dashboard</a>+ </div>+ </div><!-- ── Profile ───────────────────────────────────────────── --><div class="page active" id="tab-profile"><h2 data-i18n="settings_index.profile_2">Profile</h2>@@ -470,10 +523,23 @@<div class="link-row"><div><div class="label">Email address</div>- <div class="val" id="account-email">—</div>+ <div class="val" id="account-email">Loading…</div>+ </div>+ <div class="row" style="gap:8px">+ <span id="email-verified-badge" class="tag">Checking…</span>+ <button class="btn sec" id="send-verify-btn" style="display:none;font-size:12px;padding:5px 12px" data-i18n="settings_index.verify_email">Verify email</button>+ </div>+ </div>+ <div class="verify-form" id="verify-form" style="display:none">+ <label for="inp-verify-code" data-i18n="settings_index.six_digit_code">Six-digit code we emailed you</label>+ <input id="inp-verify-code" type="text" inputmode="numeric" autocomplete="one-time-code" maxlength="6" placeholder="000000" />+ <div class="row">+ <button class="btn" id="confirm-verify-btn" disabled data-i18n="settings_index.confirm_code">Confirm code</button>+ <button class="btn sec" id="resend-verify-btn" data-i18n="settings_index.send_again">Send again</button>+ <button class="btn sec" id="cancel-verify-btn" data-i18n="settings_index.cancel_2">Cancel</button></div>- <span id="email-verified-badge" class="tag">—</span></div>+ <span class="inline-msg" id="verify-msg" style="display:none"></span><div class="link-row"><div><div class="label">Password</div>@@ -484,14 +550,21 @@<div class="link-row"><div><div class="label">Connected wallets</div>- <div class="val" id="wallet-count">—</div>+ <div class="val" id="wallet-count">Loading…</div></div><a href="/dashboard/account" class="action" data-i18n="settings_index.manage">Manage ↗</a></div>+ <div class="link-row">+ <div>+ <div class="label">Notifications</div>+ <div class="val" data-i18n="settings_index.choose_which_channels_deliver_each_kind">Choose which channels deliver each kind of notification</div>+ </div>+ <a href="/dashboard/settings" class="action" data-i18n="settings_index.manage_3">Manage ↗</a>+ </div><div class="link-row"><div><div class="label">Plan</div>- <div class="val" id="account-plan">—</div>+ <div class="val" id="account-plan">Loading…</div></div><a href="/dashboard#billing" class="action" data-i18n="settings_index.manage_2">Manage ↗</a></div>@@ -626,8 +699,9 @@<p data-i18n="settings_index.permanently_deletes_your_account_all_avatars">Permanently deletes your account, all avatars, agents, and API keys. This cannot be undone.</p><button class="btn danger" id="show-delete-btn" data-i18n="settings_index.delete_my_account">Delete my account…</button><div class="confirm-delete" id="confirm-delete-wrap">- <p data-i18n-html="settings_index.type_delete_my_account_to_confirm">Type <strong style="color:#eee">delete my account</strong> to confirm:</p>- <input id="delete-confirm-input" type="text" placeholder="delete my account" style="max-width:300px;margin-bottom:12px" />+ <p id="delete-confirm-help" data-i18n-html="settings_index.type_delete_my_account_to_confirm">Type <strong style="color:#eee">delete my account</strong> to confirm:</p>+ <label for="delete-confirm-input" class="visually-hidden" data-i18n="settings_index.confirmation_phrase">Confirmation phrase</label>+ <input id="delete-confirm-input" type="text" placeholder="delete my account" aria-describedby="delete-confirm-help" style="max-width:300px;margin-bottom:12px" /><div class="row"><button class="btn danger" id="confirm-delete-btn" disabled data-i18n="settings_index.permanently_delete">Permanently delete</button><button class="btn sec" id="cancel-delete-btn" data-i18n="settings_index.cancel">Cancel</button>@@ -686,16 +760,13 @@document.getElementById('inp-username').value = user.username || '';updateProfileUrlPreview();- document.getElementById('account-email').textContent = user.email || '—';- const badge = document.getElementById('email-verified-badge');- if (user.email_verified) {- badge.textContent = 'Verified';- badge.className = 'tag green';- } else {- badge.textContent = 'Unverified';- badge.className = 'tag yellow';- }+ document.getElementById('account-email').textContent = user.email || 'No email on this account';+ renderVerifiedBadge();document.getElementById('account-plan').textContent = user.plan || 'free';+ // The stored preference, not a local guess: /api/auth/me carries the+ // column the avatar create paths read, so the control shows what the+ // server will actually apply.+ document.getElementById('sel-default-vis').value = user.default_avatar_visibility || 'private';// /api/auth/me returns wallet_address, never `address`, so the old// fallback never resolved and a wallet-only account got a button@@ -723,6 +794,103 @@}document.getElementById('inp-username').addEventListener('input', updateProfileUrlPreview);+ // ── Email verification ───────────────────────────────────────+ // /api/auth/verify-email and /api/auth/resend-verification have existed+ // since registration shipped, but nothing in the product ever called+ // them: the only place that even mentioned verification was the badge+ // below, and it read a field /api/auth/me did not return, so every+ // account read "Unverified" forever with no way to act on it. This is+ // the flow that closes that loop.+ function renderVerifiedBadge() {+ const badge = document.getElementById('email-verified-badge');+ const sendBtn = document.getElementById('send-verify-btn');+ const verified = Boolean(user?.email_verified);+ badge.textContent = verified ? 'Verified' : 'Unverified';+ badge.className = verified ? 'tag green' : 'tag yellow';+ // A wallet-only account has a synthetic address it cannot receive mail+ // at, so offering to send a code there would be a dead end.+ const mailable = Boolean(user?.email) && !/@users\.three\.ws\.local$/i.test(user.email);+ sendBtn.style.display = !verified && mailable ? 'inline-flex' : 'none';+ if (verified) {+ document.getElementById('verify-form').style.display = 'none';+ }+ }++ function showVerifyForm(open) {+ document.getElementById('verify-form').style.display = open ? 'block' : 'none';+ document.getElementById('send-verify-btn').style.display = open ? 'none' : 'inline-flex';+ if (open) document.getElementById('inp-verify-code').focus();+ }++ async function sendVerificationCode(btn) {+ const msg = document.getElementById('verify-msg');+ const label = btn.textContent;+ btn.disabled = true;+ btn.textContent = 'Sending…';+ try {+ const data = await apiJson('/api/auth/resend-verification', { method: 'POST' });+ if (data?.already_verified) {+ if (user) user.email_verified = true;+ renderVerifiedBadge();+ showMsg(msg, 'ok', 'This address is already verified.');+ return true;+ }+ showMsg(msg, 'ok', `Code sent to ${user.email}. It expires in 30 minutes.`);+ return true;+ } catch (e) {+ showMsg(msg, 'err', e.data?.error_description || 'Could not send the code. Try again in a moment.');+ return false;+ } finally {+ btn.disabled = false;+ btn.textContent = label;+ }+ }++ document.getElementById('send-verify-btn').addEventListener('click', async (e) => {+ if (await sendVerificationCode(e.currentTarget) && !user?.email_verified) showVerifyForm(true);+ });+ document.getElementById('resend-verify-btn').addEventListener('click', (e) => sendVerificationCode(e.currentTarget));+ document.getElementById('cancel-verify-btn').addEventListener('click', () => {+ document.getElementById('inp-verify-code').value = '';+ document.getElementById('confirm-verify-btn').disabled = true;+ showVerifyForm(false);+ });+ document.getElementById('inp-verify-code').addEventListener('input', (e) => {+ // The server hashes exactly six digits, so strip anything a paste drags in.+ e.target.value = e.target.value.replace(/\D/g, '').slice(0, 6);+ document.getElementById('confirm-verify-btn').disabled = e.target.value.length !== 6;+ });+ document.getElementById('inp-verify-code').addEventListener('keydown', (e) => {+ if (e.key === 'Enter' && e.target.value.length === 6) {+ e.preventDefault();+ document.getElementById('confirm-verify-btn').click();+ }+ });+ document.getElementById('confirm-verify-btn').addEventListener('click', async () => {+ const btn = document.getElementById('confirm-verify-btn');+ const msg = document.getElementById('verify-msg');+ const code = document.getElementById('inp-verify-code').value;+ btn.disabled = true;+ btn.textContent = 'Confirming…';+ try {+ await apiJson('/api/auth/verify-email', {+ method: 'POST',+ headers: { 'content-type': 'application/json' },+ body: JSON.stringify({ code }),+ });+ if (user) user.email_verified = true;+ renderVerifiedBadge();+ showVerifyForm(false);+ document.getElementById('inp-verify-code').value = '';+ showMsg(msg, 'ok', 'Email verified.');+ } catch (e) {+ showMsg(msg, 'err', e.data?.error_description || 'That code did not work. Ask for a new one.');+ } finally {+ btn.textContent = 'Confirm code';+ btn.disabled = document.getElementById('inp-verify-code').value.length !== 6;+ }+ });+// ── Wallets count ────────────────────────────────────────────async function loadWallets() {try {@@ -760,13 +928,30 @@}});- // ── Privacy (stored in localStorage until backend supports it) ──- const PRIV_KEY = '3dagent:default-vis';- document.getElementById('sel-default-vis').value = localStorage.getItem(PRIV_KEY) || 'public';- document.getElementById('save-privacy-btn').addEventListener('click', () => {+ // ── Privacy ──────────────────────────────────────────────────+ // The default visibility is stored on the account (users+ // .default_avatar_visibility) and read back by every avatar create path+ // that the caller did not give an explicit visibility. It used to live in+ // localStorage, where nothing ever read it: the control said "saved" and+ // new avatars kept whatever each endpoint hardcoded.+ document.getElementById('save-privacy-btn').addEventListener('click', async () => {+ const btn = document.getElementById('save-privacy-btn');+ const msg = document.getElementById('privacy-msg');const val = document.getElementById('sel-default-vis').value;- localStorage.setItem(PRIV_KEY, val);- showMsg(document.getElementById('privacy-msg'), 'ok', 'Saved preference.');+ btn.disabled = true;+ try {+ await apiJson('/api/auth/profile', {+ method: 'PATCH',+ headers: { 'content-type': 'application/json' },+ body: JSON.stringify({ default_avatar_visibility: val }),+ });+ if (user) user.default_avatar_visibility = val;+ showMsg(msg, 'ok', 'Saved. New avatars will default to ' + val + '.');+ } catch (e) {+ showMsg(msg, 'err', e.data?.error_description || 'Could not save that preference.');+ } finally {+ btn.disabled = false;+ }});// ── Sessions ─────────────────────────────────────────────────