WIP Hub 1.6.0: AI proxy for Cross Events 2.0

Signed /installs/ai/status and /installs/ai/complete (protocol 3b):
the Hub holds the Claude key, holds each call's worst case against the
licence's monthly cap in a locked transaction, calls Claude Haiku 5.5
and meters real cost and charged amount (markup) in rand. Settings ->
AI, licence markup override, AI use on the install page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-30 09:16:04 +02:00
co-authored by Claude Opus 5.5
parent 0f4d1c360a
commit 49f62aeb75
20 changed files with 1041 additions and 27 deletions
+18 -2
View File
@@ -24,10 +24,20 @@ const DEFAULTS = {
// Written by the sync, not the Settings page.
release_synced_at: '',
release_sync_error: '',
// AI for Cross Events 2.0 (utils/ai.js). Off until a key and the exchange rate are set.
ai_api_key: '',
ai_model: 'claude-haiku-5-5',
// US dollars per million tokens, for prompts under 100K tokens (the Hub refuses bigger ones).
ai_input_usd_per_mtok: '0.10',
ai_output_usd_per_mtok: '0.50',
// Rand per US dollar.
ai_usd_zar: '',
// Default markup on the real cost, in %; a licence can override it.
ai_markup_percent: '40',
};
// Stored encrypted and never sent to the browser: only "is one saved" (<key>_set).
const SECRETS = ['smtp_pass', 'release_repo_token'];
const SECRETS = ['smtp_pass', 'release_repo_token', 'ai_api_key'];
async function rawSettings() {
const rows = await prisma.setting.findMany();
@@ -105,4 +115,10 @@ async function releaseRepoToken() {
return release_repo_token ? decrypt(release_repo_token) : '';
}
module.exports = { DEFAULTS, getSettings, setSettings, smtpSettings, importSmtpFromEnv, releaseRepoToken };
/** The saved Claude API key, decrypted ('' when none). */
async function aiApiKey() {
const { ai_api_key } = await rawSettings();
return ai_api_key ? decrypt(ai_api_key) : '';
}
module.exports = { DEFAULTS, getSettings, setSettings, smtpSettings, importSmtpFromEnv, releaseRepoToken, aiApiKey };