@posthog/wizard
Version:
The PostHog wizard helps you to configure your project
101 lines (97 loc) • 4.01 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkAnthropicStatus = checkAnthropicStatus;
exports.checkAnthropicStatusWithPrompt = checkAnthropicStatusWithPrompt;
const clack_1 = __importDefault(require("./clack"));
const chalk_1 = __importDefault(require("chalk"));
const CLAUDE_STATUS_URL = 'https://status.claude.com/api/v2/status.json';
const CLAUDE_STATUS_PAGE = 'https://status.claude.com';
/**
* Check the Anthropic/Claude status page for service health.
* Returns the current status indicator.
*/
async function checkAnthropicStatus() {
try {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 5000); // 5 second timeout
const response = await fetch(CLAUDE_STATUS_URL, {
signal: controller.signal,
});
clearTimeout(timeoutId);
if (!response.ok) {
return {
status: 'unknown',
error: `Status page returned ${response.status}`,
};
}
const data = (await response.json());
const indicator = data.status.indicator;
const description = data.status.description;
switch (indicator) {
case 'none':
return { status: 'operational' };
case 'minor':
return { status: 'degraded', description };
case 'major':
case 'critical':
return { status: 'down', description };
default:
return { status: 'unknown', error: `Unknown indicator: ${indicator}` };
}
}
catch (error) {
if (error instanceof Error && error.name === 'AbortError') {
return { status: 'unknown', error: 'Request timed out' };
}
return {
status: 'unknown',
error: error instanceof Error ? error.message : 'Unknown error',
};
}
}
/**
* Check Anthropic status and handle the result.
* - If down: Show error and exit
* - If degraded: Show warning and ask user to continue
* - If operational or unknown: Continue silently
*
* @returns true if the wizard should continue, false if it should abort
*/
async function checkAnthropicStatusWithPrompt(options = {}) {
const result = await checkAnthropicStatus();
if (result.status === 'down') {
clack_1.default.log.error(`${chalk_1.default.red('Claude/Anthropic services are currently experiencing issues.')}
${chalk_1.default.yellow('Status:')} ${result.description}
${chalk_1.default.yellow('Status page:')} ${CLAUDE_STATUS_PAGE}
The wizard relies on Claude to make changes to your project.
Please check the status page and try again later.`);
return false;
}
if (result.status === 'degraded') {
clack_1.default.log.warn(`${chalk_1.default.yellow('Claude/Anthropic services are partially degraded.')}
${chalk_1.default.yellow('Status:')} ${result.description}
${chalk_1.default.yellow('Status page:')} ${CLAUDE_STATUS_PAGE}
The wizard may not work reliably while services are degraded.`);
// In CI mode, continue with a warning
if (options.ci) {
clack_1.default.log.info('Continuing in CI mode despite degraded status...');
return true;
}
const shouldContinue = await clack_1.default.confirm({
message: 'Do you want to continue anyway?',
initialValue: false,
});
if (clack_1.default.isCancel(shouldContinue) || !shouldContinue) {
clack_1.default.log.info('Wizard cancelled. Please try again later.');
return false;
}
return true;
}
// For 'operational' or 'unknown' status, continue silently
// We don't want to block users if the status check itself fails
return true;
}
//# sourceMappingURL=anthropic-status.js.map