forked from 1e0n/droid2api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.js
More file actions
92 lines (78 loc) · 2.09 KB
/
Copy pathconfig.js
File metadata and controls
92 lines (78 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
let config = null;
let portSource = 'config';
export function loadConfig() {
try {
const configPath = path.join(__dirname, 'config.json');
const configData = fs.readFileSync(configPath, 'utf-8');
config = JSON.parse(configData);
return config;
} catch (error) {
throw new Error(`Failed to load config.json: ${error.message}`);
}
}
export function getConfig() {
if (!config) {
loadConfig();
}
return config;
}
export function getModelById(modelId) {
const cfg = getConfig();
return cfg.models.find(m => m.id === modelId);
}
export function getEndpointByType(type) {
const cfg = getConfig();
return cfg.endpoint.find(e => e.name === type);
}
export function isDevMode() {
const cfg = getConfig();
return cfg.dev_mode === true;
}
export function getPort() {
const envPort = process.env.PORT;
if (envPort) {
const parsedEnvPort = parseInt(envPort, 10);
if (!Number.isNaN(parsedEnvPort) && parsedEnvPort > 0) {
portSource = 'env';
return parsedEnvPort;
}
}
const cfg = getConfig();
const configPort = cfg.port;
if (typeof configPort !== 'undefined') {
const parsedConfigPort = parseInt(configPort, 10);
if (!Number.isNaN(parsedConfigPort) && parsedConfigPort > 0) {
portSource = 'config';
return parsedConfigPort;
}
}
portSource = 'default';
return 3000;
}
export function getPortSource() {
return portSource;
}
export function getSystemPrompt() {
const cfg = getConfig();
return cfg.system_prompt || '';
}
export function getModelReasoning(modelId) {
const model = getModelById(modelId);
if (!model || !model.reasoning) {
return null;
}
const reasoningLevel = model.reasoning.toLowerCase();
if (['low', 'medium', 'high', 'auto'].includes(reasoningLevel)) {
return reasoningLevel;
}
return null;
}
export function getUserAgent() {
const cfg = getConfig();
return cfg.user_agent || 'factory-cli/0.19.3';
}