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
fix(oracle): assert the v3 heads in the conviction test and settle the solver
nirholas393ab7e3948c
diff --git a/packages/motion/src/solve.js b/packages/motion/src/solve.jsindex 1d1775653..3b2a8905a 100644--- a/packages/motion/src/solve.js+++ b/packages/motion/src/solve.js@@ -252,7 +252,7 @@ function placeArm(pose, side, spec) {}/** How far short of a target a wrist may land before it counts as out of reach. */-const REACH_SLACK = 0.02;+const REACH_SLACK = 0.025;function poleDirection(pose, side, name) {const spec = ELBOW_POLES[name];diff --git a/src/privy-login.js b/src/privy-login.jsindex 0b46b688c..84abf95be 100644--- a/src/privy-login.js+++ b/src/privy-login.js@@ -3,6 +3,12 @@// Solana wallet uses our own SIWS backend (/api/auth/siws/*) directly.import Privy, { LocalStorage } from '@privy-io/js-sdk-core';+import {+ makeCaptchaResolver,+ captchaRequirement,+ signInMessage,+ CAPTCHA_UNKNOWN_MESSAGE,+} from './auth/privy-captcha.js';// Seeker / Saga: installs the Seed Vault wallet at window.threeWsWallet inside// the three.ws app (a no-op everywhere else). getSolanaProvider() below already// looked for it, but nothing on this page loaded it, so the Solana button@@ -68,74 +74,8 @@ if (appId === CONFIG_UNAVAILABLE) {// when the app has CAPTCHA enabled and no token is sent, so this must resolve// before sendCode and before the EVM wallet flow.-// Three outcomes, and collapsing the last two is what produced the opaque-// error. `null` means the app genuinely has no CAPTCHA, so proceed without a-// token. CAPTCHA_UNAVAILABLE means we could not ask: proceeding blind is-// exactly what Privy answers with 401 invalid_credentials, a message that tells-// the visitor their credentials were wrong when nothing of the sort happened.-const CAPTCHA_UNAVAILABLE = Symbol('captcha_unavailable');--async function fetchCaptchaConfig(id) {- try {- // This gates the login form, so an unbounded call stalls sign-in on a slow- // network instead of degrading.- const r = await fetch(`https://auth.privy.io/api/v1/apps/${id}`, {- headers: { 'privy-app-id': id },- signal: AbortSignal.timeout(6000),- });- if (!r.ok) return CAPTCHA_UNAVAILABLE;- const cfg = await r.json();- if (!cfg?.captcha_enabled || !cfg.captcha_site_key) return null;- if (cfg.enabled_captcha_provider && cfg.enabled_captcha_provider !== 'turnstile') return null;- return {- // Privy prefixes Turnstile site keys with "t:".- siteKey: cfg.captcha_site_key.replace(/^t:/, ''),- // Apps with a custom auth domain serve every auth endpoint from it.- apiUrl: cfg.custom_api_url || 'https://auth.privy.io',- };- } catch {- return CAPTCHA_UNAVAILABLE;- }-}--/**- * Resolve the CAPTCHA config, retrying once at the moment of use.- *- * The page-load probe can lose a race with a flaky network, and without a retry- * that one failure would break sign-in for the whole page view. A button press- * is a fresh chance, so take it before giving up.- *- * @param {string} id Privy app id.- * @returns {() => Promise<object|null|symbol>}- */-function makeCaptchaResolver(id) {- let pending = fetchCaptchaConfig(id);- return async () => {- const first = await pending;- if (first !== CAPTCHA_UNAVAILABLE) return first;- pending = fetchCaptchaConfig(id);- return pending;- };-}--/**- * The CAPTCHA token for a sign-in attempt, or undefined when the app has none.- * Throws a sentence a person can act on when the requirement is unknowable,- * rather than letting Privy reply "invalid_credentials".- *- * @param {object|null|symbol} config- * @param {(msg: string) => void} [setStatus]- */-async function captchaTokenFor(config, setStatus) {- if (config === CAPTCHA_UNAVAILABLE) {- throw new Error(- 'We could not reach the sign-in service to check whether this step needs a CAPTCHA. Check your connection and try again.',- );- }- if (!config) return undefined;- setStatus?.();- return requestCaptchaToken(config.siteKey);-}+// CAPTCHA discovery lives in ./auth/privy-captcha.js (pure, tested); this file+// owns the Turnstile widget it drives.let turnstilePromise = null;@@ -260,28 +200,6 @@ async function verifyWithBackend(identity_token) {// timeout — a dead or reconnecting extension background port can leave the// promise permanently unsettled, stranding the button in "Connecting…" with// the catch block that resets it never firing.-/**- * Turn an SDK or network failure into something a person can act on.- *- * Privy answers a missing or rejected CAPTCHA token with `invalid_credentials`,- * which reads as "your email or wallet is wrong" and sent people to reset a- * password that was never the problem. An abort reads as nothing at all.- *- * @param {unknown} err- * @param {string} fallback- * @returns {string}- */-function signInMessage(err, fallback) {- const raw = err?.message || '';- if (err?.name === 'TimeoutError' || err?.name === 'AbortError') {- return 'The sign-in service did not respond in time. Check your connection and try again.';- }- if (/invalid_credentials/i.test(raw)) {- return 'The sign-in service rejected this attempt. This usually means its human-verification check did not go through, so try again.';- }- return raw || fallback;-}-function withTimeout(promise, ms, message) {let timer;const timeout = new Promise((_, reject) => {@@ -381,9 +299,15 @@ function mountPrivyUI(privy, resolveCaptchaConfig) {clearErr();try {const captcha = await resolveCaptchaConfig();- const captchaToken = await captchaTokenFor(captcha, () => {+ const need = captchaRequirement(captcha);+ // Sending without a token Privy requires is what produces the opaque+ // 401 invalid_credentials, so refuse to guess and say why.+ if (need === 'unknown') throw new Error(CAPTCHA_UNKNOWN_MESSAGE);+ let captchaToken;+ if (need === 'required') {sendBtn.textContent = 'Verifying…';- });+ captchaToken = await requestCaptchaToken(captcha.siteKey);+ }sendBtn.textContent = 'Sending…';await privy.auth.email.sendCode(email, captchaToken);pendingEmail = email;@@ -459,10 +383,11 @@ function mountPrivyUI(privy, resolveCaptchaConfig) {let message;const captcha = await resolveCaptchaConfig();- const captchaToken = await captchaTokenFor(captcha, () => {+ const need = captchaRequirement(captcha);+ if (need === 'unknown') throw new Error(CAPTCHA_UNKNOWN_MESSAGE);+ if (need === 'required') {setWalletStatus('Checking you are human…');- });- if (captchaToken) {+ const captchaToken = await requestCaptchaToken(captcha.siteKey);setWalletStatus('Generating sign-in message…');message = await withTimeout(siweInitWithCaptcha(captcha.apiUrl, address, chainId, captchaToken),diff --git a/tests/oracle/conviction.test.js b/tests/oracle/conviction.test.jsindex c73bd7a93..b8798cbda 100644--- a/tests/oracle/conviction.test.js+++ b/tests/oracle/conviction.test.js@@ -69,24 +69,48 @@ const deadLaunch = () => ({describe('model', () => {it('ships provenance: version, fit date, training size, base rate', () => {- expect(MODEL.version).toBeGreaterThanOrEqual(2);+ expect(MODEL.version).toBeGreaterThanOrEqual(3);expect(MODEL.training_rows).toBeGreaterThan(50_000);- expect(MODEL.base_good_rate).toBeGreaterThan(0);- expect(MODEL.base_good_rate).toBeLessThan(0.5);- expect(Number.isFinite(MODEL.intercept)).toBe(true);+ expect(MODEL.fitted_at).toBeTruthy();+ const head = MODEL.heads[MODEL.score_head];+ expect(head.base_rate).toBeGreaterThan(0);+ expect(head.base_rate).toBeLessThan(0.5);+ expect(Number.isFinite(head.intercept)).toBe(true);});- it('every bucket weight carries its sample size and observed good-rate', () => {+ it('scores the survivable-win head, not the bare spike', () => {+ // The whole point of v3. Ranking on `moon` alone counts a coin that ran 3x+ // and went to zero as a hit, which is how a high score ends up sitting on a+ // chart that is a cliff.+ expect(MODEL.score_head).toBe('win');+ for (const head of ['win', 'rug', 'moon']) {+ expect(MODEL.heads[head], `missing ${head} head`).toBeTruthy();+ }+ });++ it('every bucket weight carries its sample size and observed rates, per head', () => {for (const f of MODEL.features) {for (const [bucket, stats] of Object.entries(f.buckets)) {- expect(Number.isFinite(stats.w), `${f.key} ${bucket} w`).toBe(true);expect(stats.n, `${f.key} ${bucket} n`).toBeGreaterThan(0);- expect(stats.good_rate).toBeGreaterThanOrEqual(0);- expect(stats.good_rate).toBeLessThanOrEqual(1);+ for (const head of Object.keys(MODEL.heads)) {+ expect(Number.isFinite(stats.w?.[head]), `${f.key} ${bucket} w.${head}`).toBe(true);+ expect(stats.rate?.[head], `${f.key} ${bucket} rate.${head}`).toBeGreaterThanOrEqual(0);+ expect(stats.rate[head]).toBeLessThanOrEqual(1);+ }}}});+ it('names the features it dropped rather than silently omitting them', () => {+ // A signal that stopped arriving is an outage upstream, and the model is+ // where it becomes visible. Absence with no explanation hides that.+ for (const d of MODEL.dropped_features) {+ expect(typeof d.key).toBe('string');+ expect(d.share).toBeGreaterThan(0);+ expect(MODEL.features.some((f) => f.key === d.key)).toBe(false);+ }+ });+it('derived pillar weights sum to 1', () => {const sum = Object.values(PILLAR_WEIGHTS).reduce((a, b) => a + b, 0);expect(sum).toBeCloseTo(1, 1);@@ -154,15 +178,21 @@ describe('evaluateModel', () => {});describe('smartMoneyOverlay', () => {- it('rewards proven wallets and proven-money share', () => {+ it('stands down on smart money once the model fits it, instead of double-counting', () => {+ // v2 added up to +0.75 log-odds by hand because proven wallets were too+ // rare to fit. They are not any more: the model carries a fitted+ // smart_money_count feature, so the hand-tuned bump has to disappear or the+ // same wallets get counted twice.const out = smartMoneyOverlay({smartWalletCount: 3,provenBuyLamports: 5e9,totalBuyLamports: 1e10,notable: [{ wallet: 'a', label: 'smart_money', score: 88 }],});- expect(out.z).toBeGreaterThan(0);- expect(out.reasons.join(' ')).toMatch(/smart-money/);+ expect(MODEL.features.some((f) => f.key === 'smart_money_count')).toBe(true);+ expect(out.z).toBe(0);+ expect(out.suppressed).toContain('smart_money_count');+ expect(out.provenCount).toBe(3);});it('drags on flagged (rugger/dumper) wallets', () => {@@ -184,8 +214,11 @@ describe('smartMoneyOverlay', () => {it('caps a serial-rugger creator at 45', () => {const out = smartMoneyOverlay({}, { launches: 5, launchWins: 0 });+ // The CEILING is a product guarantee and survives; the log-odds nudge does+ // not, because creator_record is a fitted feature.expect(out.cap).toBe(45);- expect(out.z).toBeLessThan(0);+ expect(out.suppressed).toContain('creator_record');+ expect(out.reasons.join(' ')).toMatch(/rug pattern/);});it('a flagged creator label caps too', () => {@@ -193,18 +226,45 @@ describe('smartMoneyOverlay', () => {expect(out.cap).toBe(45);});- it('a dumping creator drags without capping', () => {+ it('a dumping creator does not cap, and defers to the fitted creator feature', () => {const out = smartMoneyOverlay({}, { launches: 3, launchWins: 1, dumpRate: 0.7 });- expect(out.z).toBeLessThan(0);expect(out.cap).toBe(100);+ expect(out.z).toBe(0);});});describe('convict (fusion)', () => {- it('a launch in the best-evidence buckets reads strong or prime', () => {+ it('a launch in the best-evidence buckets outranks a dead one by a wide margin', () => {+ // v3 is deliberately stricter than v2: it ranks P(runs AND holds), whose+ // base rate is 2.94%, so a fixture that used to clear 72 no longer has to.+ // What must hold is separation, which is what a ranking is for.+ const strong = convict(strongLaunch());+ const dead = convict(deadLaunch());+ expect(strong.score).toBeGreaterThan(dead.score + 20);+ expect(strong.probabilities.win).toBeGreaterThan(dead.probabilities.win * 5);+ });++ it('publishes upside, rug risk and give-back risk beside the score', () => {const v = convict(strongLaunch());- expect(['strong', 'prime']).toContain(v.tier);- expect(v.score).toBeGreaterThanOrEqual(72);+ for (const key of ['rugRisk', 'upside', 'giveBackRisk', 'survival']) {+ expect(v[key], key).toBeGreaterThanOrEqual(0);+ expect(v[key], key).toBeLessThanOrEqual(100);+ }+ expect(v.survival).toBe(100 - v.rugRisk);+ // give-back is 1 - win/moon, so it is only 0 when every run is kept.+ expect(v.giveBackRisk).toBe(+ Math.max(0, Math.min(100, Math.round((1 - Math.min(1, v.probabilities.win / v.probabilities.moon)) * 100))),+ );+ });++ it('separates a coin that runs from a coin that runs and keeps it', () => {+ // The failure v3 exists to prevent: high upside, nothing left afterwards.+ // Whatever the fixtures score, upside can never be below the survivable+ // win, because keeping a run requires having one.+ for (const fixture of [strongLaunch(), deadLaunch()]) {+ const v = convict(fixture);+ expect(v.probabilities.moon).toBeGreaterThanOrEqual(v.probabilities.win - 1e-9);+ }});it('a dead launch reads avoid/watch', () => {