/** * Shared HTML rendering for OAuth completion pages shown in the browser * after a loopback/redirect OAuth flow completes. */ function escapeHtml(s: string): string { return s .replace(/&/g, "&") .replace(//g, ">") .replace(/"/g, """) .replace(/'/g, "'"); } function formatProviderName(provider: string): string { // Capitalize first letter of each word, handle common acronyms return provider .split(/[-_]/) .map((w) => w.charAt(0).toUpperCase() + w.slice(1)) .join(" "); } export function renderOAuthCompletionPage( message: string, success: boolean, provider?: string, ): string { const displayProvider = provider ? formatProviderName(provider) : ""; const title = success ? displayProvider ? `Connected to ${escapeHtml(displayProvider)}` : "Authorization Successful" : "Authorization Failed"; const subtitle = success ? "You can close this tab and return to your assistant." : escapeHtml(message); const checkmarkSvg = ` `; const errorSvg = ` `; return ` ${escapeHtml(title)}
${success ? checkmarkSvg : errorSvg}

${escapeHtml(title)}

${subtitle}

`; }