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(settings): stop offering a GitHub connect button a deployment cannot honor

nirholas52aea91be245
diff --git a/api/auth/github/[action].js b/api/auth/github/[action].js
index 17f15bb9e..3ddcd1e3c 100644
--- a/api/auth/github/[action].js
+++ b/api/auth/github/[action].js
@@ -173,12 +173,17 @@ async function handleStatus(req, res) {
const session = await getSessionUser(req);
if (!session) return error(res, 401, 'unauthorized', 'sign in required');
+ // Whether this deployment has a GitHub OAuth app at all. Without it every
+ // connect click lands on a raw 501 from /connect, so the card needs to know
+ // before it renders a button that cannot work.
+ const configured = Boolean(env.GITHUB_OAUTH_CLIENT_ID && env.GITHUB_OAUTH_CLIENT_SECRET);
+
const [row] = await sql`
SELECT username, connected_at FROM social_connections
WHERE user_id = ${session.id} AND provider = 'github'
`;
- if (!row) return json(res, 200, { connected: false, seeded_fact_count: 0 });
+ if (!row) return json(res, 200, { connected: false, configured, seeded_fact_count: 0 });
const [seeded] = await sql`
SELECT count(*)::int AS n
@@ -189,6 +194,7 @@ async function handleStatus(req, res) {
return json(res, 200, {
connected: true,
+ configured,
username: row.username,
connected_at: row.connected_at,
seeded_fact_count: seeded?.n ?? 0,
diff --git a/docs/github-memory-seeding.md b/docs/github-memory-seeding.md
index 5676dfeb1..a2f5fe33b 100644
--- a/docs/github-memory-seeding.md
+++ b/docs/github-memory-seeding.md
@@ -96,6 +96,34 @@ behind a broken replacement.
---
+## Configuration
+
+The consent catalog, the seed, and the revoke all run off a user's own OAuth
+token, so a deployment needs a GitHub OAuth app before the Connect button can
+do anything. Register one at
+[github.com/settings/developers](https://github.com/settings/developers) with
+the authorization callback URL set to `<your origin>/api/auth/github/callback`
+(production: `https://three.ws/api/auth/github/callback`), then set two
+variables on the API service:
+
+| Variable | Purpose |
+|---|---|
+| `GITHUB_OAUTH_CLIENT_ID` | The OAuth app's client ID, sent on the authorize redirect |
+| `GITHUB_OAUTH_CLIENT_SECRET` | The client secret, used for the code exchange and for revoking the grant on disconnect |
+
+The app requests `read:user` and `public_repo`, both read-only, and the access
+token is encrypted with a key derived from `JWT_SECRET` before it is stored, so
+rotating `JWT_SECRET` invalidates stored tokens (users reconnect) rather than
+decrypting them into garbage.
+
+Until both variables are present, `GET /api/auth/github/status` answers
+`configured: false`, `/api/auth/github/connect` answers `501 not_configured`,
+and the Settings card renders an explicit "unavailable on this deployment"
+state instead of a button that cannot work. Everything else on the lane is
+unaffected: no other feature depends on these variables.
+
+---
+
## API
All three calls are owner-only: the session (or bearer) user must own the
diff --git a/public/settings/index.html b/public/settings/index.html
index 5dd950d8c..077e95484 100644
--- a/public/settings/index.html
+++ b/public/settings/index.html
@@ -876,6 +876,12 @@
seedArea.style.display = 'block';
mountSeedPanel();
}
+ } else if (data.configured === false) {
+ // No OAuth app on this deployment. Say so plainly rather than
+ // offering a button whose only outcome is a 501 error page.
+ statusEl.textContent = 'GitHub connect is unavailable on this deployment';
+ actionsEl.innerHTML = '<span class="tag">Unavailable</span><a href="/docs/github-memory-seeding" class="btn sec" style="font-size:12px;padding:5px 14px;text-decoration:none">How this works</a>';
+ if (seedArea) seedArea.style.display = 'none';
} else {
statusEl.textContent = 'Not connected';
const agentId = _urlP.get('agent_id') || '';
@@ -891,7 +897,7 @@
if (ghMsg && ghResult) {
if (ghResult === 'connected') showMsg(ghMsg, 'ok', 'GitHub connected successfully.');
else if (ghResult === 'denied') showMsg(ghMsg, 'err', 'GitHub connection was cancelled.');
- else if (ghResult === 'error') showMsg(ghMsg, 'err', 'GitHub connection failed — please try again.');
+ else if (ghResult === 'error') showMsg(ghMsg, 'err', 'GitHub connection failed. Please try again.');
}
}
@@ -904,6 +910,22 @@
const esc = (s) => String(s ?? '').replace(/[&<>"]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]));
+ // Every seeding panel needs the account's agents. /api/agents returns the
+ // full list; /api/agents/me returns one agent and creates it on first
+ // call, so it is the fallback that guarantees a brand-new account still
+ // has something to seed instead of an empty picker.
+ async function loadMyAgents() {
+ try {
+ const list = (await apiJson('/api/agents'))?.agents;
+ if (Array.isArray(list) && list.length) return list;
+ } catch {}
+ try {
+ const one = (await apiJson('/api/agents/me'))?.agent;
+ return one ? [one] : [];
+ } catch {}
+ return [];
+ }
+
function seedSelection() {
const root = document.getElementById('seed-catalog');
if (!root) return { include_profile: false, repos: [], readmes: [] };
@@ -922,7 +944,7 @@
const summary = document.getElementById('consent-summary-text');
if (!root || !btn) return;
// A README can only be read for a repo that is itself selected, which is
- // also what the server enforces — keeping the checkbox in lockstep means
+ // also what the server enforces, and keeping the checkbox in lockstep means
// the user never assembles a selection the API will reject.
const chosen = new Set([...root.querySelectorAll('input[data-repo]:checked')].map((i) => i.dataset.repo));
for (const box of root.querySelectorAll('input[data-readme]')) {
@@ -935,7 +957,7 @@
btn.disabled = count === 0;
if (summary) {
summary.textContent = count === 0
- ? 'Nothing selected — your agent will read nothing.'
+ ? 'Nothing selected: your agent will read nothing.'
: `${count} item${count === 1 ? '' : 's'} selected${sel.readmes.length ? `, ${sel.readmes.length} README${sel.readmes.length === 1 ? '' : 's'}` : ''}. Nothing else is read or stored.`;
}
}
@@ -960,7 +982,7 @@
const p = data.catalog.profile;
const repos = data.catalog.repos || [];
const seededNote = data.seeded_at
- ? `<p class="muted" style="font-size:12px;margin:0 0 8px">Last seeded ${new Date(data.seeded_at).toLocaleString()} — ${data.fact_count} ${data.fact_count === 1 ? 'memory' : 'memories'} stored. Seeding again replaces them.</p>`
+ ? `<p class="muted" style="font-size:12px;margin:0 0 8px">Last seeded ${new Date(data.seeded_at).toLocaleString()}, ${data.fact_count} ${data.fact_count === 1 ? 'memory' : 'memories'} stored. Seeding again replaces them.</p>`
: '';
const profileRow = p ? `
@@ -1026,10 +1048,7 @@
const fallback = document.getElementById('seed-agent-fallback');
const preset = _urlP.get('agent_id') || '';
- let agents = [];
- try {
- agents = (await apiJson('/api/agents/me'))?.agents || [];
- } catch { agents = []; }
+ const agents = await loadMyAgents();
if (agents.length) {
select.innerHTML = agents.map((a) => `<option value="${esc(a.id)}">${esc(a.name || a.id)}</option>`).join('');
@@ -1117,13 +1136,7 @@
// Seeding always targets one agent. With no ?agent_id= in the
// URL, fall back to the account's first agent so the card is
// usable from a bare /settings visit.
- let agentId = null;
- try {
- const agents = await apiJson('/api/agents/me');
- agentId = agents?.agents?.[0]?.id ?? null;
- } catch {
- agentId = null;
- }
+ const agentId = (await loadMyAgents())[0]?.id ?? null;
if (agentId) {
renderXStatus(el, agentId, connectUrl);
} else {
diff --git a/tests/github-memory-seed.test.js b/tests/github-memory-seed.test.js
index b26c4a7f1..0040c8ab7 100644
--- a/tests/github-memory-seed.test.js
+++ b/tests/github-memory-seed.test.js
@@ -1,3 +1,4 @@
+import { readFileSync } from 'node:fs';
import { describe, it, expect } from 'vitest';
import {
buildCatalog,
@@ -388,3 +389,31 @@ describe('toMemoryRows', () => {
});
});
});
+
+// The consent screen is part of the contract: if the panel cannot list the
+// account's agents, or offers a Connect button on a deployment that has no
+// GitHub OAuth app, the guarantees above never get a chance to apply.
+describe('settings consent panel wiring', () => {
+ const html = readFileSync(new URL('../public/settings/index.html', import.meta.url), 'utf8');
+
+ it('reads the agent list from /api/agents, which is the endpoint that returns one', () => {
+ expect(html).toContain("apiJson('/api/agents')");
+ // /api/agents/me answers { agent }, never { agents }. Reading .agents off it
+ // left every account with an empty picker and the manual-id fallback.
+ expect(html).not.toContain("apiJson('/api/agents/me'))?.agents");
+ expect(html).not.toContain('agents?.agents?.[0]?.id');
+ });
+
+ it('falls back to the single agent /api/agents/me returns', () => {
+ expect(html).toContain("apiJson('/api/agents/me'))?.agent");
+ });
+
+ it('renders an unavailable state instead of a dead Connect button when OAuth is unconfigured', () => {
+ expect(html).toContain('data.configured === false');
+ expect(html).toContain('GitHub connect is unavailable on this deployment');
+ });
+
+ it('sends only ticked repos, and a README only for a repo that is also ticked', () => {
+ expect(html).toContain('readmes: readmes.filter((k) => repos.includes(k))');
+ });
+});