lis3456/droid2api
0
1import fs from 'fs';2import path from 'path';3import { fileURLToPath } from 'url';4 5const __filename = fileURLToPath(import.meta.url);6const __dirname = path.dirname(__filename);7 8let config = null;9 10export function loadConfig() {11 try {12 const configPath = path.join(__dirname, 'config.json');13 const configData = fs.readFileSync(configPath, 'utf-8');14 config = JSON.parse(configData);15 return config;16 } catch (error) {17 throw new Error(`Failed to load config.json: ${error.message}`);18 }19}20 21export function getConfig() {22 if (!config) {23 loadConfig();24 }25 return config;26}27 28export function getModelById(modelId) {29 const cfg = getConfig();30 return cfg.models.find(m => m.id === modelId);31}32 33export function getEndpointByType(type) {34 const cfg = getConfig();35 return cfg.endpoint.find(e => e.name === type);36}37 38export function isDevMode() {39 return process.env.NODE_ENV === 'development';40}41 42export function getPort() {43 const cfg = getConfig();44 return cfg.port || 3000;45}46 47export function getSystemPrompt() {48 const cfg = getConfig();49 return cfg.system_prompt || '';50}51 52export function getModelReasoning(modelId) {53 const model = getModelById(modelId);54 if (!model || !model.reasoning) {55 return null;56 }57 const reasoningLevel = model.reasoning.toLowerCase();58 if (['low', 'medium', 'high', 'auto'].includes(reasoningLevel)) {59 return reasoningLevel;60 }61 return null;62}63 64export function getUserAgent() {65 const cfg = getConfig();66 return cfg.user_agent || 'factory-cli/0.19.3';67}68 