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.

2.8 KB
Raw Blame
// @ts-check
// GET /api/cron/changelog-push - automatic changelog delivery to the community
// Telegram channel and the @trythreews X thread.
//
// Runs every 20 minutes. Reads the changelog feed baked into the running
// image (public/changelog.json, regenerated by every deploy build), diffs it
// against DB state, and posts anything new to the community Telegram channel.
// Because the feed ships inside the image, entries go out shortly after the
// deploy that made them live, with no manual `npm run changelog:push` step.
//
// Two lanes, independent of each other:
//   Telegram gets every entry.
//   X gets every entry that passes data/changelog-x-filter.json (nothing about
//     wallets, funds, payment internals, keys, outages, or other coins, and
//     nothing that is only a fix), as replies in one thread under a daily cap.
//     X was retired on 2026-07-18 and turned back on by the owner on 2026-09-24.
// The reviewed feature posts (three a day) are a separate pipeline,
// api/cron/x-content.js.
//
// A lane whose credentials are absent reports { skipped: 'not_configured' }.
//   Telegram: TELEGRAM_BOT_TOKEN + TELEGRAM_CHANGELOG_CHAT_ID
//   X:        X_API_KEY + X_API_SECRET + X_ACCESS_TOKEN + X_ACCESS_SECRET
//
// A failing lane answers 502, which wrapCron records as a failed heartbeat, so
// a stalled lane turns red on /api/ops/health instead of passing silently.
//
// A DB lock (app_settings) keeps overlapping ticks from double-posting.
// Selection, pacing, caps, and message formats live in
// api/_lib/changelog-push.js; the manual scripts in scripts/changelog-*.mjs
// remain for previews (--dry-run) and backfills only.

import { error, json, method, wrapCron } from '../_lib/http.js';
import { acquireLock, releaseLock, loadFeed, pushTelegramLane, pushXLane } from '../_lib/changelog-push.js';
import { requireCron } from '../_lib/cron-auth.js';

export default wrapCron(async (req, res) => {
	if (!method(req, res, ['GET'])) return;
	if (!requireCron(req, res)) return;

	if (!(await acquireLock())) {
		json(res, 200, { ok: true, skipped: 'locked' });
		return;
	}

	let feed;
	try {
		feed = loadFeed();
	} catch (err) {
		await releaseLock().catch(() => {});
		error(res, 500, 'feed_unreadable', String(err?.message || err));
		return;
	}

	try {
		// A throw (DB outage mid-lane) is contained to its own lane and reported
		// like any other lane error, so one lane never stops the other.
		const runLane = (lane) => lane(feed).catch((err) => ({ error: String(err?.message || err) }));
		const telegram = await runLane(pushTelegramLane);
		const x = await runLane(pushXLane);
		const failed = Boolean(telegram.error || x.error);
		if (failed) console.warn('[cron] changelog-push lane error', { telegram, x });
		json(res, failed ? 502 : 200, { ok: !failed, telegram, x });
	} finally {
		await releaseLock().catch(() => {});
	}
});