UNPKG

framework

Version:

The (AI) Framework: turnkey, zero-config AI orchestration that wraps a coding-agent CLI (Claude Code) as a black box and takes you from an idea to a running app. Vite for AI.

55 lines 2.31 kB
/** The env var behind each credential, so the two tables below cannot drift apart. */ export const ENV_KEYS = { webhook: 'DISCORD_WEBHOOK' }; /** The registry key behind each credential. */ export const SECRET_KEYS = { webhook: 'discordWebhook' }; /** The credential names, once, so every loop over them covers both by construction. */ export const CREDENTIALS = Object.keys(ENV_KEYS); /** The environment variable a credential is read from, for the UI's "set on the daemon" copy. */ export function credentialEnvVar(credential) { return ENV_KEYS[credential]; } /** The credentials to run with: the environment first, the stored value as the fallback. */ export function resolveDiscordCredentials(env, secrets) { const resolved = {}; for (const key of CREDENTIALS) { const value = env[ENV_KEYS[key]]?.trim() || secrets[SECRET_KEYS[key]]?.trim(); if (value) resolved[key] = value; } return resolved; } /** The same resolution, reported as presence + origin. The browser-facing half of the pair above. */ export function discordCredentialStatus(env, secrets) { const status = {}; for (const key of CREDENTIALS) { if (env[ENV_KEYS[key]]?.trim()) status[key] = 'env'; else if (secrets[SECRET_KEYS[key]]?.trim()) status[key] = 'stored'; } return status; } /** * Reject what cannot possibly work, before it is stored and silently does nothing. * * Deliberately shallow: a token is only checked for the shape of a token (one opaque word), and a * webhook for being an http(s) URL rather than for being on discord.com — people front webhooks * with their own proxies, and the daemon has no business refusing a URL it was told to post to. * Whether the credential actually authenticates is Discord's answer to give, and the daemon logs it. */ export function validateCredential(credential, value) { const trimmed = value.trim(); if (!trimmed) return undefined; // clearing is always legal let url; try { url = new URL(trimmed); } catch { return 'That is not a URL.'; } if (url.protocol !== 'https:' && url.protocol !== 'http:') return 'A webhook URL must be http or https.'; return undefined; } //# sourceMappingURL=discord-credentials.js.map