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.

Changelog and retention-doc updates plus vertex-anchor surface tests

nirholas2302d56ead14
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5083a7602..09b1395e5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,7 +11,9 @@ Public history for [three.ws](https://three.ws), newest first. New pages come fr
- **Animation Studio toolbar cleanup** — The Animation Studio (/pose) got a UI pass: toolbar buttons no longer render as oversized circles behind FK and Save, the toolbar fits on laptop screens with pose import/export and screenshots collected under a new overflow menu, the language picker moved into the footer so it stops covering the timeline, error messages show their warning color again, and on phones the animation library and pose presets are reachable instead of hidden. (`/pose`) `[improvement, fix]`
- **Avatar Studio: a Parametric base with 120+ face and body sliders** — The Avatar Studio has a second base body: Parametric. Built on the open-source MakeHuman body (CC0, fully licensed), it turns the Sculpt tab into a real character creator with over 120 sliders: nose width and hump, lip volume, pointed elf ears, eye tilt, jawline, head shape, plus whole-body controls for feminine or masculine build, muscle, weight, age, height, waist, hips, shoulders, arms, and legs. Mirror left/right or unlock them for asymmetry. Every combination stays fully rigged and walks, dances, and emotes with the entire animation library, and hats, glasses, and skin tones work like on any avatar. Pick Parametric in the Base switcher at the top of the studio. (`/avatar-studio`) `[feature]`
- **Coin detail pages stay up when market data is throttled** — Coin profile pages (the /coin/:id view with price, market cap, links, and developer stats) were returning an error whenever the upstream market-data provider hit its rate limit, which happens under heavy crawling. Now the page serves the most recent good data through those throttling windows instead of failing, and only shows an error for a coin that genuinely has no data. Prices refresh as soon as the provider recovers. (`/coins`) `[fix]`
+- **Coin pages stay live through market-data outages** — Every coin page (prices, markets, exchanges, charts) now keeps a shared last-good copy of its market data. When the upstream data provider rate-limits or goes down, pages serve slightly older numbers instead of an error, even right after a fresh server starts. The exchanges directory was the last surface that could still show an error during a data-provider storm; now it rides through. (`/exchanges`) `[fix, improvement]`
- **Commit feed posts now render a branded three.ws card** — The automatic commit feed (every change that lands on the main branch) used to post to Telegram as bare text: a scope, the raw commit subject, and a GitHub link. It now previews the same designed three.ws poster the changelog feed uses, so each commit reads as a proper card with the change, the date, and the author. Engineering shorthand in the title is translated too, so 'feat' shows as 'Feature', 'fix' as 'Fix', and so on, while real scopes like 'Avatar Studio' pass through unchanged. Clicking the card still opens the exact commit on GitHub. `[improvement]`
+- **Database storage now heals itself** — The platform database reclaimed 770 MB of dead space and learned to do this on its own: when storage runs tight, the retention job now compacts its own bloated tables instead of waiting for an operator. Background jobs that pause under storage pressure resume automatically. Intel model training also got a memory bound so it keeps learning from the freshest coins without ever outgrowing its worker. `[infra, fix]`
- **Menus no longer show raw translation codes** — A few navigation entries (Daily Match, Character Library, Object Library, and others added recently) could render as internal translation codes like "nav.c3spxn" instead of their real names. Fixed at both ends: the translation runtime now leaves the original English text in place whenever a string is missing from the language catalogs, and the missing menu strings were added and localized into all 11 languages. `[fix]`
- **Take the wheel: drive your agent's computer** — Every agent already had a live screen you could watch. Now, if you own the agent, you can grab the wheel of its real browser and drive it yourself: mouse, click and drag, scroll, keyboard, and a URL bar to go anywhere. Open your agent's screen, wait for it to go live, and click Take control. Your agent steps aside while you drive and picks its task back up the moment you let go. It is owner-only, and the browser you drive holds no wallet or keys, so control can never sign a transaction or move funds. This is the first step toward giving every agent its own computer that you and the agent can both operate. (`/agent-screen`) `[feature]`
- **What's new, at a glance: newest features on /features and /sitemap** — You no longer have to scroll the changelog to see what just shipped. The Features page opens with a 'New on three.ws' strip: the six latest features and page launches, each card linking straight to the live page. The sitemap gained a matching 'Newest' section listing the most recently launched pages with their dates. Both update themselves with every release. (`/features`) `[improvement]`
diff --git a/data/changelog.json b/data/changelog.json
index 990c9bd95..1ab9dc339 100644
--- a/data/changelog.json
+++ b/data/changelog.json
@@ -15426,6 +15426,25 @@
"fix"
]
},
+ {
+ "date": "2026-07-22",
+ "title": "Coin pages stay live through market-data outages",
+ "summary": "Every coin page (prices, markets, exchanges, charts) now keeps a shared last-good copy of its market data. When the upstream data provider rate-limits or goes down, pages serve slightly older numbers instead of an error, even right after a fresh server starts. The exchanges directory was the last surface that could still show an error during a data-provider storm; now it rides through.",
+ "tags": [
+ "fix",
+ "improvement"
+ ],
+ "link": "/exchanges"
+ },
+ {
+ "date": "2026-07-22",
+ "title": "Database storage now heals itself",
+ "summary": "The platform database reclaimed 770 MB of dead space and learned to do this on its own: when storage runs tight, the retention job now compacts its own bloated tables instead of waiting for an operator. Background jobs that pause under storage pressure resume automatically. Intel model training also got a memory bound so it keeps learning from the freshest coins without ever outgrowing its worker.",
+ "tags": [
+ "infra",
+ "fix"
+ ]
+ },
{
"date": "2026-07-22",
"title": "Animation Studio toolbar cleanup",
diff --git a/docs/ops/db-retention.md b/docs/ops/db-retention.md
index 29c202a11..dbc885288 100644
--- a/docs/ops/db-retention.md
+++ b/docs/ops/db-retention.md
@@ -53,8 +53,20 @@ Bounded + idempotent. Each tick:
(win/loss ground truth) are **never** touched.
- **Avatar job hygiene** — deletes terminal jobs past 30 days and strips base64
source images from terminal jobs past a day.
-- **VACUUM** (plain, never `FULL`) of the pruned tables so freed pages become
- reusable and Neon's storage GC can return the space.
+- **VACUUM** (plain) of the pruned tables so freed pages become reusable by
+ future inserts.
+- **Compaction under pressure.** Plain `VACUUM` never shrinks the relation
+ *files*, so on Neon `pg_database_size` stays high after a prune and the
+ storage-pressure gate (`isStoragePressured` / `requireWriteCapacity`) can
+ latch permanently: the July 2026 recurrence had **770 MB** of dead file space
+ across the pruned tables while every write-heavy cron sat skipped. When a
+ tick starts over the high-water mark, the cron now measures reclaimable space
+ per managed table (`pgstattuple_approx`, extension auto-installed) and
+ `VACUUM FULL`s the worst offenders — smallest file first (each rewrite needs
+ headroom about equal to the table's live size), bounded per tick, and only
+ ever on tables this cron itself manages. The rewrites returned
+ `pump_coin_intel` 576→194 MB and `oracle_conviction` 386→137 MB in ~2 s each
+ during the 2026-07-22 recovery.
**The self-healing valve.** The retention window self-tunes: normally
`PUMP_INTEL_RETENTION_DAYS`, but whenever the branch is at/above
@@ -70,6 +82,9 @@ fires one deduped `db:retention-pressure` alert.
| `PUMP_INTEL_RETENTION_DAYS` | `14` | Normal firehose window (days). Clamped `[2, 365]`. Raise after a Neon plan upgrade. |
| `PUMP_INTEL_MIN_RETENTION_DAYS` | `3` | Floor the valve tightens to under pressure. Clamped `[1, retention]`. |
| `DB_RETENTION_HIGH_WATER_MB` | `470` | Engage the valve at/above this size. Clamped `[128, 100000]`. |
+| `DB_COMPACT_ENABLED` | `1` | Set `0` to disable the `VACUUM FULL` compaction step entirely. |
+| `DB_COMPACT_MIN_FREE_MB` | `25` | Only rewrite a table holding at least this much reclaimable space (and at least 30% of its file). |
+| `DB_COMPACT_MAX_TABLES` | `3` | Most tables one tick may rewrite. |
## Upgrade trigger
diff --git a/public/changelog.json b/public/changelog.json
index c283e3a28..97a92ed39 100644
--- a/public/changelog.json
+++ b/public/changelog.json
@@ -1,5 +1,5 @@
{
- "generated_at": "2026-07-22T21:50:44.862Z",
+ "generated_at": "2026-07-22T22:12:49.151Z",
"generated_by": "scripts/build-page-index.mjs from data/pages.json + data/changelog.json",
"site": {
"name": "three.ws",
@@ -57,6 +57,17 @@
"fix"
]
},
+ {
+ "date": "2026-07-22",
+ "type": "update",
+ "title": "Coin pages stay live through market-data outages",
+ "summary": "Every coin page (prices, markets, exchanges, charts) now keeps a shared last-good copy of its market data. When the upstream data provider rate-limits or goes down, pages serve slightly older numbers instead of an error, even right after a fresh server starts. The exchanges directory was the last surface that could still show an error during a data-provider storm; now it rides through.",
+ "link": "/exchanges",
+ "tags": [
+ "fix",
+ "improvement"
+ ]
+ },
{
"date": "2026-07-22",
"type": "update",
@@ -67,6 +78,17 @@
"improvement"
]
},
+ {
+ "date": "2026-07-22",
+ "type": "update",
+ "title": "Database storage now heals itself",
+ "summary": "The platform database reclaimed 770 MB of dead space and learned to do this on its own: when storage runs tight, the retention job now compacts its own bloated tables instead of waiting for an operator. Background jobs that pause under storage pressure resume automatically. Intel model training also got a memory bound so it keeps learning from the freshest coins without ever outgrowing its worker.",
+ "link": null,
+ "tags": [
+ "infra",
+ "fix"
+ ]
+ },
{
"date": "2026-07-22",
"type": "update",
diff --git a/public/changelog.xml b/public/changelog.xml
index b2a6f6a1e..77cdee1ea 100644
--- a/public/changelog.xml
+++ b/public/changelog.xml
@@ -46,6 +46,14 @@
<category>fix</category>
<description>Coin profile pages (the /coin/:id view with price, market cap, links, and developer stats) were returning an error whenever the upstream market-data provider hit its rate limit, which happens under heavy crawling. Now the page serves the most recent good data through those throttling windows instead of failing, and only shows an error for a coin that genuinely has no data. Prices refresh as soon as the provider recovers.</description>
</item>
+ <item>
+ <title>Coin pages stay live through market-data outages</title>
+ <link>https://three.ws/exchanges</link>
+ <guid isPermaLink="false">2026-07-22:Coin pages stay live through market-data outages</guid>
+ <pubDate>Wed, 22 Jul 2026 12:00:00 GMT</pubDate>
+ <category>fix</category>
+ <description>Every coin page (prices, markets, exchanges, charts) now keeps a shared last-good copy of its market data. When the upstream data provider rate-limits or goes down, pages serve slightly older numbers instead of an error, even right after a fresh server starts. The exchanges directory was the last surface that could still show an error during a data-provider storm; now it rides through.</description>
+ </item>
<item>
<title>Commit feed posts now render a branded three.ws card</title>
<link>https://three.ws/changelog</link>
@@ -54,6 +62,14 @@
<category>improvement</category>
<description>The automatic commit feed (every change that lands on the main branch) used to post to Telegram as bare text: a scope, the raw commit subject, and a GitHub link. It now previews the same designed three.ws poster the changelog feed uses, so each commit reads as a proper card with the change, the date, and the author. Engineering shorthand in the title is translated too, so 'feat' shows as 'Feature', 'fix' as 'Fix', and so on, while real scopes like 'Avatar Studio' pass through unchanged. Clicking the card still opens the exact commit on GitHub.</description>
</item>
+ <item>
+ <title>Database storage now heals itself</title>
+ <link>https://three.ws/changelog</link>
+ <guid isPermaLink="false">2026-07-22:Database storage now heals itself</guid>
+ <pubDate>Wed, 22 Jul 2026 12:00:00 GMT</pubDate>
+ <category>infra</category>
+ <description>The platform database reclaimed 770 MB of dead space and learned to do this on its own: when storage runs tight, the retention job now compacts its own bloated tables instead of waiting for an operator. Background jobs that pause under storage pressure resume automatically. Intel model training also got a memory bound so it keeps learning from the freshest coins without ever outgrowing its worker.</description>
+ </item>
<item>
<title>Menus no longer show raw translation codes</title>
<link>https://three.ws/changelog</link>
diff --git a/public/features.json b/public/features.json
index b04a712df..be23ac75d 100644
--- a/public/features.json
+++ b/public/features.json
@@ -1,5 +1,5 @@
{
- "generated_at": "2026-07-22T21:50:44.785Z",
+ "generated_at": "2026-07-22T22:12:49.139Z",
"generated_by": "scripts/build-page-index.mjs from data/pages.json",
"site": {
"name": "three.ws",
diff --git a/tests/api/llm-vertex-anchor-surfaces.test.js b/tests/api/llm-vertex-anchor-surfaces.test.js
new file mode 100644
index 000000000..7d5db3085
--- /dev/null
+++ b/tests/api/llm-vertex-anchor-surfaces.test.js
@@ -0,0 +1,282 @@
+// Regression guard: every LLM surface keeps the credits-funded Vertex Gemini
+// anchor in its fallback chain (the api/chat.js fix pattern, commit 2b3d00254).
+//
+// The 2026-07-21 production diagnosis: brain, widgets, copilot, vision, and the
+// anthropic-proxy each hand-rolled their model fallback chains WITHOUT the
+// keyless Vertex Gemini rung, so a simultaneous throttle of the free lanes
+// (groq/openrouter/nvidia) surfaced 5xx even though GCP credits could answer —
+// the prod OPENAI_API_KEY is billing-dead (429 billing_not_active) and the
+// OpenRouter host key must never route to paid models. These tests lock the
+// chat.js semantics onto every surface, via the shared api/_lib/vertex-gemini.js:
+// • the anchor is present whenever GOOGLE_CLOUD_PROJECT is set,
+// • it survives when other provider keys (OPENAI_API_KEY etc.) are present,
+// • it sits at the tail (never a primary),
+// • an anonymous/keyless deployment still gets a working chain from it,
+// • it is absent (no behavior change) without a GCP project.
+
+import { describe, it, expect, beforeEach, afterEach } from 'vitest';
+
+import {
+ vertexGeminiAvailable,
+ vertexGeminiModel,
+ vertexGeminiChatUrl,
+ vertexGeminiOpenAIBase,
+} from '../../api/_lib/vertex-gemini.js';
+import { freeFallbackChain } from '../../api/brain/chat.js';
+import { providerChain as copilotProviderChain } from '../../api/agents/copilot.js';
+import { pickProviderChain as widgetProviderChain } from '../../api/widgets/[id]/[action].js';
+import { visionChain, visionConfigured } from '../../api/_lib/vision.js';
+import { modelFallbackChain, resolveModelRoute } from '../../api/llm/anthropic.js';
+
+// Every env var these chains read. Saved/restored around each test so the
+// suite is deterministic regardless of the host environment.
+const ENV_KEYS = [
+ 'GOOGLE_CLOUD_PROJECT',
+ 'GOOGLE_CLOUD_LOCATION_GEMINI',
+ 'VERTEX_GEMINI_MODEL',
+ 'VERTEX_CLAUDE_ENABLED',
+ 'VERTEX_CLAUDE_PRIMARY',
+ 'GROQ_API_KEY',
+ 'CEREBRAS_API_KEY',
+ 'OPENROUTER_API_KEY',
+ 'OPENROUTER_FALLBACK_KEYS',
+ 'NVIDIA_API_KEY',
+ 'GEMINI_API_KEY',
+ 'ANTHROPIC_API_KEY',
+ 'OPENAI_API_KEY',
+ 'GROK_API_KEY',
+ 'WATSONX_API_KEY',
+ 'CHAT_MODEL',
+];
+
+const saved = {};
+beforeEach(() => {
+ for (const k of ENV_KEYS) {
+ saved[k] = process.env[k];
+ delete process.env[k];
+ }
+});
+afterEach(() => {
+ for (const k of ENV_KEYS) {
+ if (saved[k] === undefined) delete process.env[k];
+ else process.env[k] = saved[k];
+ }
+});
+
+// The prod repro: every free key AND the (billing-dead) paid keys present.
+// The anchor must never be evicted by any of them.
+function setAllProviderKeys() {
+ process.env.GROQ_API_KEY = 'gsk-test';
+ process.env.OPENROUTER_API_KEY = 'or-test';
+ process.env.NVIDIA_API_KEY = 'nv-test';
+ process.env.ANTHROPIC_API_KEY = 'sk-ant-test';
+ process.env.OPENAI_API_KEY = 'sk-test';
+ process.env.GROK_API_KEY = 'xai-test';
+}
+
+describe('shared vertex-gemini helper (api/_lib/vertex-gemini.js)', () => {
+ it('is unavailable without a GCP project and available with one', () => {
+ expect(vertexGeminiAvailable()).toBe(false);
+ process.env.GOOGLE_CLOUD_PROJECT = 'test-project';
+ expect(vertexGeminiAvailable()).toBe(true);
+ });
+
+ it('builds the OpenAI-compatible Vertex endpoint from the env knobs', () => {
+ process.env.GOOGLE_CLOUD_PROJECT = 'test-project';
+ expect(vertexGeminiChatUrl()).toBe(
+ 'https://aiplatform.googleapis.com/v1beta1/projects/test-project/locations/global/endpoints/openapi/chat/completions',
+ );
+ expect(vertexGeminiChatUrl()).toBe(`${vertexGeminiOpenAIBase()}/chat/completions`);
+ process.env.GOOGLE_CLOUD_LOCATION_GEMINI = 'us-central1';
+ expect(vertexGeminiChatUrl()).toContain('https://us-central1-aiplatform.googleapis.com/');
+ expect(vertexGeminiChatUrl()).toContain('/locations/us-central1/');
+ });
+
+ it('defaults to full Gemini Flash and honors the VERTEX_GEMINI_MODEL override', () => {
+ expect(vertexGeminiModel()).toBe('google/gemini-2.5-flash');
+ process.env.VERTEX_GEMINI_MODEL = 'google/gemini-2.5-pro';
+ expect(vertexGeminiModel()).toBe('google/gemini-2.5-pro');
+ });
+});
+
+describe('brain (api/brain/chat.js) — freeFallbackChain anchor', () => {
+ const spec = { openrouterModel: 'openai/gpt-oss-120b:free' };
+
+ it('appends the anchor at the tail when a GCP project is set', () => {
+ process.env.GOOGLE_CLOUD_PROJECT = 'test-project';
+ setAllProviderKeys();
+ const chain = freeFallbackChain('gpt-oss-120b', spec, { via: 'native' });
+ expect(chain.length).toBeGreaterThan(1);
+ const last = chain[chain.length - 1];
+ expect(last.vertexGemini).toBe(true);
+ expect(last.label).toBe('vertex-gemini/google/gemini-2.5-flash');
+ // Exactly one anchor entry — never doubled.
+ expect(chain.filter((a) => a.vertexGemini)).toHaveLength(1);
+ });
+
+ it('still provides a working chain with ZERO provider keys (anon/keyless deploy)', () => {
+ process.env.GOOGLE_CLOUD_PROJECT = 'test-project';
+ const chain = freeFallbackChain('gpt-oss-120b', spec, null);
+ expect(chain).toHaveLength(1);
+ expect(chain[0].vertexGemini).toBe(true);
+ });
+
+ it('omits the anchor entirely without a GCP project (no behavior change)', () => {
+ setAllProviderKeys();
+ const chain = freeFallbackChain('gpt-oss-120b', spec, { via: 'native' });
+ expect(chain.some((a) => a.vertexGemini)).toBe(false);
+ });
+});
+
+describe('copilot (api/agents/copilot.js) — providerChain anchor', () => {
+ it('keeps the keyless anchor as the final rung past every present provider key', () => {
+ process.env.GOOGLE_CLOUD_PROJECT = 'test-project';
+ setAllProviderKeys();
+ const chain = copilotProviderChain();
+ const last = chain[chain.length - 1];
+ expect(last.name).toBe('vertex-gemini');
+ expect(last.model).toBe('google/gemini-2.5-flash');
+ expect(last.url).toContain('aiplatform.googleapis.com');
+ expect(last.url).toContain('test-project');
+ expect(last.key).toBeNull(); // keyless: auth minted per request
+ expect(typeof last.getHeaders).toBe('function');
+ // The (billing-dead) paid OpenAI rung may exist, but never after the anchor.
+ expect(chain.findIndex((p) => p.name === 'openai')).toBeLessThan(
+ chain.findIndex((p) => p.name === 'vertex-gemini'),
+ );
+ });
+
+ it('serves a non-empty chain with zero provider keys — the 503 gate opens on credits alone', () => {
+ process.env.GOOGLE_CLOUD_PROJECT = 'test-project';
+ const chain = copilotProviderChain();
+ expect(chain).toHaveLength(1);
+ expect(chain[0].name).toBe('vertex-gemini');
+ });
+
+ it('adds no anchor without a GCP project', () => {
+ setAllProviderKeys();
+ const chain = copilotProviderChain();
+ expect(chain.some((p) => p.name === 'vertex-gemini')).toBe(false);
+ });
+});
+
+describe('widgets (api/widgets/[id]/[action].js) — pickProviderChain anchor', () => {
+ it('appends the anchor after every configured route and never as the primary', () => {
+ process.env.GOOGLE_CLOUD_PROJECT = 'test-project';
+ setAllProviderKeys();
+ const chain = widgetProviderChain('auto', null);
+ expect(chain[0].name).not.toBe('vertex-gemini');
+ const last = chain[chain.length - 1];
+ expect(last.name).toBe('vertex-gemini');
+ expect(last.cfg.style).toBe('openai');
+ expect(last.cfg.url).toContain('aiplatform.googleapis.com');
+ expect(typeof last.cfg.resolveHeaders).toBe('function');
+ expect(last.model).toBe('google/gemini-2.5-flash');
+ expect(chain.filter((r) => r.name === 'vertex-gemini')).toHaveLength(1);
+ });
+
+ it('honors the VERTEX_GEMINI_MODEL override', () => {
+ process.env.GOOGLE_CLOUD_PROJECT = 'test-project';
+ process.env.VERTEX_GEMINI_MODEL = 'google/gemini-2.5-pro';
+ const chain = widgetProviderChain('auto', null);
+ expect(chain[chain.length - 1].model).toBe('google/gemini-2.5-pro');
+ });
+
+ it('anonymous embeds on a keyless deploy still get a working chain', () => {
+ process.env.GOOGLE_CLOUD_PROJECT = 'test-project';
+ const chain = widgetProviderChain('auto', null);
+ expect(chain).toHaveLength(1);
+ expect(chain[0].name).toBe('vertex-gemini');
+ });
+
+ it('adds no anchor without a GCP project', () => {
+ setAllProviderKeys();
+ const chain = widgetProviderChain('auto', null);
+ expect(chain.some((r) => r.name === 'vertex-gemini')).toBe(false);
+ });
+});
+
+describe('vision (api/_lib/vision.js) — visionChain anchor', () => {
+ it('sits after the free NIM lanes and ahead of the paid OpenAI backstop', () => {
+ process.env.GOOGLE_CLOUD_PROJECT = 'test-project';
+ process.env.NVIDIA_API_KEY = 'nv-test';
+ process.env.OPENAI_API_KEY = 'sk-test';
+ const chain = visionChain();
+ const names = chain.map((p) => p.name);
+ const anchorAt = names.indexOf('vertex-gemini');
+ expect(anchorAt).toBeGreaterThan(-1);
+ expect(anchorAt).toBeGreaterThan(names.lastIndexOf('nvidia'));
+ expect(anchorAt).toBeLessThan(names.indexOf('openai'));
+ const anchor = chain[anchorAt];
+ expect(anchor.url).toContain('aiplatform.googleapis.com');
+ expect(anchor.model).toBe('google/gemini-2.5-flash');
+ expect(typeof anchor.getHeaders).toBe('function');
+ expect(anchor.headers).toBeUndefined(); // keyless: no static bearer header
+ });
+
+ it('visionConfigured() is true on a GCP project alone — the multimodal anchor serves', () => {
+ expect(visionConfigured()).toBe(false);
+ process.env.GOOGLE_CLOUD_PROJECT = 'test-project';
+ expect(visionConfigured()).toBe(true);
+ const chain = visionChain();
+ expect(chain).toHaveLength(1);
+ expect(chain[0].name).toBe('vertex-gemini');
+ });
+
+ it('adds no anchor without a GCP project', () => {
+ process.env.NVIDIA_API_KEY = 'nv-test';
+ expect(visionChain().some((p) => p.name === 'vertex-gemini')).toBe(false);
+ });
+
+ it('the anchor builds a standard OpenAI multimodal body', () => {
+ process.env.GOOGLE_CLOUD_PROJECT = 'test-project';
+ const [anchor] = visionChain();
+ const parts = [
+ { type: 'text', text: 'describe' },
+ { type: 'image_url', image_url: { url: 'data:image/png;base64,AAAA' } },
+ ];
+ const body = anchor.buildBody('sys', parts, 256);
+ expect(body.model).toBe('google/gemini-2.5-flash');
+ expect(body.messages[0]).toEqual({ role: 'system', content: 'sys' });
+ expect(body.messages[1]).toEqual({ role: 'user', content: parts });
+ });
+});
+
+describe('anthropic-proxy (api/llm/anthropic.js) — model fallback anchor', () => {
+ it('appends the anchor model as the final fallback when a GCP project is set', () => {
+ process.env.GOOGLE_CLOUD_PROJECT = 'test-project';
+ setAllProviderKeys();
+ const chain = modelFallbackChain('meta-llama/llama-3.3-70b-instruct:free');
+ expect(chain[chain.length - 1]).toBe('google/gemini-2.5-flash');
+ // Paid Anthropic stays ahead of it; the anchor is strictly last resort.
+ expect(chain.indexOf('claude-haiku-4-5-20251001')).toBeLessThan(
+ chain.indexOf('google/gemini-2.5-flash'),
+ );
+ expect(chain.filter((m) => m === 'google/gemini-2.5-flash')).toHaveLength(1);
+ });
+
+ it('resolves the anchor model to a keyless openai-kind vertex-gemini route', () => {
+ process.env.GOOGLE_CLOUD_PROJECT = 'test-project';
+ expect(resolveModelRoute('google/gemini-2.5-flash')).toEqual({
+ kind: 'openai',
+ provider: 'vertex-gemini',
+ });
+ // Static allowlist entries are untouched.
+ expect(resolveModelRoute('llama-3.3-70b-versatile')).toMatchObject({ provider: 'groq' });
+ // Unknown models still resolve to nothing (the 400 allowlist gate).
+ expect(resolveModelRoute('made-up/model')).toBeNull();
+ });
+
+ it('without a GCP project the anchor neither resolves nor joins the chain', () => {
+ const chain = modelFallbackChain('meta-llama/llama-3.3-70b-instruct:free');
+ expect(chain).not.toContain('google/gemini-2.5-flash');
+ expect(resolveModelRoute('google/gemini-2.5-flash')).toBeNull();
+ });
+
+ it('dedupes when the caller requests the anchor model directly', () => {
+ process.env.GOOGLE_CLOUD_PROJECT = 'test-project';
+ const chain = modelFallbackChain('google/gemini-2.5-flash');
+ expect(chain[0]).toBe('google/gemini-2.5-flash');
+ expect(chain.filter((m) => m === 'google/gemini-2.5-flash')).toHaveLength(1);
+ });
+});