ccgo
Version:
Simple Claude Code launcher with config management and environment variable injection
247 lines • 8.86 kB
JavaScript
"use strict";
/**
* 交互式提示
* 提供向导式配置体验
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.showConfigGuide = showConfigGuide;
exports.showConfigPrompts = showConfigPrompts;
exports.selectProfile = selectProfile;
exports.confirmReconfigure = confirmReconfigure;
exports.confirmLaunch = confirmLaunch;
exports.showWelcome = showWelcome;
exports.showConfigSuccess = showConfigSuccess;
exports.showHelp = showHelp;
const inquirer_1 = __importDefault(require("inquirer"));
const chalk_1 = __importDefault(require("chalk"));
const boxen_1 = __importDefault(require("boxen"));
const validator_1 = require("../config/validator");
/**
* 显示配置引导
*/
function showConfigGuide() {
console.log('\n' + (0, boxen_1.default)(chalk_1.default.cyan.bold('🔑 配置说明') + '\n\n' +
chalk_1.default.yellow.bold('必填项:') + '\n' +
chalk_1.default.gray(' • API Base URL: API 服务地址(如 https://api.anthropic.com)\n') +
chalk_1.default.gray(' • API Key: 你的 API 密钥\n\n') +
chalk_1.default.yellow.bold('可选项:') + '\n' +
chalk_1.default.gray(' • Model: 主要使用的模型名称(对应环境变量 ANTHROPIC_MODEL)\n') +
chalk_1.default.gray(' • Small Fast Model: 快速小模型(对应环境变量 ANTHROPIC_SMALL_FAST_MODEL)\n\n') +
chalk_1.default.cyan.bold('常见 API 服务:') + '\n' +
chalk_1.default.white(' 智谱 GLM: ') + chalk_1.default.gray('https://open.bigmodel.cn/api/anthropic\n') +
chalk_1.default.white(' Kimi: ') + chalk_1.default.gray('https://api.moonshot.cn/anthropic\n') +
chalk_1.default.white(' 通义千问: ') + chalk_1.default.gray('https://dashscope.aliyuncs.com/compatible-mode/v1\n') +
chalk_1.default.white(' DeepSeek: ') + chalk_1.default.gray('https://api.deepseek.com'), {
padding: 1,
borderColor: 'cyan',
borderStyle: 'round'
}));
console.log('');
}
/**
* 首次配置提示
*/
async function showConfigPrompts(defaultName) {
console.log(chalk_1.default.cyan('\n🔧 配置 Claude Code API\n'));
// 显示配置引导
showConfigGuide();
// 输入配置名称
const { name } = await inquirer_1.default.prompt([
{
type: 'input',
name: 'name',
message: '配置名称:',
default: defaultName || 'default',
validate: (input) => {
if (!input || !input.trim()) {
return '❌ 配置名称不能为空';
}
if (!/^[a-zA-Z0-9_-]+$/.test(input)) {
return '❌ 配置名称只能包含字母、数字、下划线和短横线';
}
return true;
}
}
]);
// 输入 Base URL
const { baseUrl } = await inquirer_1.default.prompt([
{
type: 'input',
name: 'baseUrl',
message: 'API Base URL:',
validate: (input) => {
if (!input) {
return '❌ Base URL 不能为空';
}
if (!(0, validator_1.validateUrl)(input)) {
return '❌ 请输入有效的 HTTP/HTTPS URL';
}
return true;
}
}
]);
// 获取 API Key
const { apiKey } = await inquirer_1.default.prompt([
{
type: 'password',
name: 'apiKey',
message: 'API Key:',
mask: '*',
validate: (input) => {
if (!input) {
return '❌ API Key 不能为空';
}
if (!(0, validator_1.validateApiKeyFormat)(input)) {
return '❌ API Key 格式不正确(长度应在 20-200 个字符之间)';
}
return true;
}
}
]);
// 询问是否配置可选参数
const { configOptional } = await inquirer_1.default.prompt([
{
type: 'confirm',
name: 'configOptional',
message: '是否配置可选参数(模型名称)?',
default: false
}
]);
let model;
let smallFastModel;
if (configOptional) {
// 输入模型名称
const modelAnswer = await inquirer_1.default.prompt([
{
type: 'input',
name: 'model',
message: 'Model (可选,直接回车跳过):',
default: ''
}
]);
model = modelAnswer.model.trim() || undefined;
// 输入小快速模型
const smallModelAnswer = await inquirer_1.default.prompt([
{
type: 'input',
name: 'smallFastModel',
message: 'Small Fast Model (可选,直接回车跳过):',
default: ''
}
]);
smallFastModel = smallModelAnswer.smallFastModel.trim() || undefined;
}
return {
name: name.trim(),
baseUrl: baseUrl.trim(),
apiKey: apiKey.trim(),
model,
smallFastModel
};
}
/**
* 选择配置
*/
async function selectProfile(profiles) {
const { selected } = await inquirer_1.default.prompt([
{
type: 'list',
name: 'selected',
message: '选择要使用的配置:',
choices: profiles.map(p => {
// 从 baseUrl 提取域名作为显示
const url = new URL(p.config.baseUrl);
const domain = url.hostname;
return {
name: `${p.name} (${domain})`,
value: p.name
};
})
}
]);
return selected;
}
/**
* 重新配置确认
*/
async function confirmReconfigure() {
const { confirm } = await inquirer_1.default.prompt([
{
type: 'confirm',
name: 'confirm',
message: chalk_1.default.yellow('这将覆盖现有配置,确定要继续吗?'),
default: false
}
]);
return confirm;
}
/**
* 确认启动 Claude Code
*/
async function confirmLaunch() {
const { confirm } = await inquirer_1.default.prompt([
{
type: 'confirm',
name: 'confirm',
message: '是否立即启动 Claude Code?',
default: true
}
]);
return confirm;
}
/**
* 显示欢迎信息
*/
function showWelcome() {
console.log('\n' + (0, boxen_1.default)(chalk_1.default.cyan.bold('🚀 CCGO') + '\n' +
chalk_1.default.gray('Claude Code Go - 简单易用的启动器'), {
padding: 1,
borderColor: 'cyan',
borderStyle: 'round',
textAlignment: 'center'
}));
}
/**
* 显示配置成功信息
*/
function showConfigSuccess(profileName) {
console.log('');
console.log(chalk_1.default.green('✓ 配置保存成功!'));
console.log(chalk_1.default.gray(`配置名称: ${profileName}`));
console.log('');
}
/**
* 显示帮助信息
*/
function showHelp() {
console.log('');
console.log(chalk_1.default.cyan.bold('CCGO - Claude Code Go 启动器'));
console.log('');
console.log(chalk_1.default.white('用法:'));
console.log(chalk_1.default.gray(' ccgo [命令] [选项]'));
console.log('');
console.log(chalk_1.default.white('命令:'));
console.log(chalk_1.default.cyan(' config') + chalk_1.default.gray(' 配置 API Key 和 Base URL'));
console.log(chalk_1.default.cyan(' config --list') + chalk_1.default.gray(' 列出所有配置'));
console.log(chalk_1.default.cyan(' config --add') + chalk_1.default.gray(' 添加新配置'));
console.log(chalk_1.default.cyan(' config --remove') + chalk_1.default.gray(' 删除配置'));
console.log(chalk_1.default.cyan(' help') + chalk_1.default.gray(' 显示帮助信息'));
console.log('');
console.log(chalk_1.default.white('选项:'));
console.log(chalk_1.default.cyan(' -v, --version') + chalk_1.default.gray(' 显示版本号'));
console.log('');
console.log(chalk_1.default.white('示例:'));
console.log(chalk_1.default.gray(' # 首次配置'));
console.log(chalk_1.default.yellow(' ccgo config'));
console.log('');
console.log(chalk_1.default.gray(' # 启动 Claude Code'));
console.log(chalk_1.default.yellow(' ccgo'));
console.log('');
console.log(chalk_1.default.gray(' # 添加新配置'));
console.log(chalk_1.default.yellow(' ccgo config --add'));
console.log('');
}
//# sourceMappingURL=prompts.js.map