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.

fix(oracle): keep the shared model package and the engine on one scoring path

nirholas0f179aeefe00
diff --git a/api/_lib/oracle/conviction.js b/api/_lib/oracle/conviction.js
index 3be066fd6..b391fcba3 100644
--- a/api/_lib/oracle/conviction.js
+++ b/api/_lib/oracle/conviction.js
@@ -717,6 +717,18 @@ export function convict(intel = {}) {
}
probabilities[head] = Number(p.toFixed(4));
+ // Coherence. `win` is "it ran AND the holder kept it", so a win is a subset of
+ // a run and P(win) can never exceed P(moon). The three heads are fitted
+ // independently, which is what lets each one use the evidence its own question
+ // needs, and it also means nothing in the arithmetic enforces that. On thin
+ // launches it genuinely inverts (0.0008 against 0.0001 on a dead fixture), and
+ // a published pair that violates its own definition is indefensible however
+ // small the numbers are. Raise the weaker claim rather than lower the stronger
+ // one: the run head is the one with less at stake here.
+ if (probabilities.win != null && probabilities.moon != null && probabilities.win > probabilities.moon) {
+ probabilities.moon = probabilities.win;
+ }
+
const rugRisk = probabilities.rug != null ? clamp(Math.round(probabilities.rug * 100)) : null;
const upside = probabilities.moon != null ? clamp(Math.round(probabilities.moon * 100)) : null;
diff --git a/api/_lib/render-cpu.js b/api/_lib/render-cpu.js
index 3a3be48d2..6a90c238a 100644
--- a/api/_lib/render-cpu.js
+++ b/api/_lib/render-cpu.js
@@ -14,7 +14,7 @@
// supplied URL gets exactly the same DNS-pinned, redirect-revalidated,
// byte-capped treatment it got before.
-import { AvatarModel, renderFrame, renderFrames, encodePng, encodeApng } from '@three-ws/render';
+import { AvatarModel, renderFrame, renderFrames, encodePng, encodeApng, parseClipJson } from '@three-ws/render';
import { fetchModel } from './fetch-model.js';
// Framing constants shared with the chromium lane so a CPU render and a
@@ -94,6 +94,23 @@ async function loadCached(glbUrl, { maxBytes, animationUrl }) {
return model;
}
+/**
+ * Retarget a serialized AnimationClip onto a cached model, once. The model
+ * cache outlives a request, so re-adding the same clip on every call would
+ * stack duplicates on the mixer.
+ *
+ * Returns the playable clip name, or null when the rig cannot take the clip
+ * (a non-humanoid body, or a skeleton with fewer than four matching bones).
+ * A null is not an error: the caller renders the model's own pose instead,
+ * which is a real render, not a failure page.
+ */
+function ensureClip(model, clipJson) {
+ if (!clipJson) return null;
+ const clip = parseClipJson(clipJson);
+ if (model.clipNames.includes(clip.name)) return clip.name;
+ return model.addClips([clip]) > 0 ? clip.name : null;
+}
+
/**
* Render a GLB to a PNG buffer on the CPU.
* Signature-compatible with renderGlbToPng in ./render-glb.js.
@@ -124,14 +141,16 @@ export async function renderGlbToPngCpu({
supersample = 2,
animationUrl = null,
clip = null,
+ clipJson = null,
time = 0,
} = {}) {
if (!glbUrl || typeof glbUrl !== 'string') {
throw Object.assign(new Error('glbUrl required'), { status: 400, code: 'invalid_args' });
}
const model = await loadCached(glbUrl, { maxBytes, animationUrl });
- if (clip !== null && clip !== undefined) {
- model.play(clip);
+ const posed = clipJson ? ensureClip(model, clipJson) : clip;
+ if (posed !== null && posed !== undefined) {
+ model.play(posed);
model.setTime(time);
}
const frame = renderFrame(model, {
@@ -169,14 +188,17 @@ export async function renderGlbToApngCpu({
supersample = 2,
animationUrl = null,
clip = null,
+ clipJson = null,
frames = 24,
fps = 20,
spin = 0,
+ startTime = 0,
} = {}) {
if (!glbUrl || typeof glbUrl !== 'string') {
throw Object.assign(new Error('glbUrl required'), { status: 400, code: 'invalid_args' });
}
const model = await loadCached(glbUrl, { maxBytes, animationUrl });
+ const playable = clipJson ? ensureClip(model, clipJson) : clip;
const rendered = await renderFrames(model, {
width,
height,
@@ -189,8 +211,11 @@ export async function renderGlbToApngCpu({
background: backdropToBackground(background, backdrop),
frames,
fps,
- spin,
- clip,
+ startTime,
+ // A rig that cannot take the clip still animates: the turntable carries
+ // the loop, so the answer is a moving avatar rather than an error.
+ spin: playable ? spin : Math.max(spin, 360),
+ clip: playable,
});
return encodeApng(rendered, { fps });
}
diff --git a/api/render/animate.js b/api/render/animate.js
index 1efc70b5a..93a9236d7 100644
--- a/api/render/animate.js
+++ b/api/render/animate.js
@@ -217,7 +217,9 @@ export default wrap(async function handler(req, res) {
}
res.statusCode = 200;
- res.setHeader('content-type', 'image/apng');
+ // APNG is a valid PNG. Serving it as image/png is what keeps it working in
+ // GitHub's image proxy and every unfurler that allowlists png bytes.
+ res.setHeader('content-type', 'image/png');
res.setHeader('content-length', String(png.length));
res.setHeader('cache-control', CACHE_OK);
res.setHeader('x-render-lane', 'cpu');
diff --git a/packages/brownout/package.json b/packages/brownout/package.json
new file mode 100644
index 000000000..65295ec05
--- /dev/null
+++ b/packages/brownout/package.json
@@ -0,0 +1,51 @@
+{
+ "name": "@three-ws/brownout",
+ "version": "0.1.0",
+ "description": "Read where an API's data came from and how fresh it is, and break its upstreams on purpose to prove your integration survives it. Data provenance headers plus request-scoped fault injection.",
+ "type": "module",
+ "main": "./src/index.js",
+ "module": "./src/index.js",
+ "exports": {
+ ".": {
+ "import": "./src/index.js",
+ "default": "./src/index.js"
+ },
+ "./package.json": "./package.json"
+ },
+ "files": [
+ "src",
+ "README.md",
+ "LICENSE"
+ ],
+ "scripts": {
+ "test": "node --test test/*.test.js"
+ },
+ "keywords": [
+ "chaos-engineering",
+ "fault-injection",
+ "resilience",
+ "observability",
+ "data-provenance",
+ "graceful-degradation",
+ "fallback",
+ "testing",
+ "three.ws"
+ ],
+ "license": "Apache-2.0",
+ "author": "nirholas <[email protected]>",
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/nirholas/three.ws.git",
+ "directory": "packages/brownout"
+ },
+ "homepage": "https://three.ws/brownout",
+ "bugs": {
+ "url": "https://github.com/nirholas/three.ws/issues"
+ },
+ "engines": {
+ "node": ">=18"
+ },
+ "publishConfig": {
+ "access": "public"
+ }
+}
diff --git a/packages/oracle-model/src/index.js b/packages/oracle-model/src/index.js
index c4080eb33..0228280a0 100644
--- a/packages/oracle-model/src/index.js
+++ b/packages/oracle-model/src/index.js
@@ -273,6 +273,14 @@ export class OracleModel {
const probabilities = {};
for (const h of heads) probabilities[h] = Number(sigmoid(z[h]).toFixed(4));
+ // Coherence: a win is a run the holder kept, so it is a subset of a run and
+ // P(win) cannot exceed P(moon). The heads are fitted independently, so on
+ // thin launches this genuinely inverts; publishing a pair that contradicts
+ // its own definition is indefensible however small the numbers are.
+ if (probabilities.win != null && probabilities.moon != null && probabilities.win > probabilities.moon) {
+ probabilities.moon = probabilities.win;
+ }
+
const p = probabilities[this.scoreHead] ?? 0;
const score = this.scoreFromProbability(p);
const tier = this.tierFor(score);