feat: retro Claude ekip konsolunu kur
This commit is contained in:
94
server/config.js
Normal file
94
server/config.js
Normal file
@@ -0,0 +1,94 @@
|
||||
import dotenv from "dotenv";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
dotenv.config({ path: path.resolve(process.cwd(), ".env") });
|
||||
|
||||
function toBool(value, fallback = false) {
|
||||
if (value == null) {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
return String(value).toLowerCase() === "true";
|
||||
}
|
||||
|
||||
export function getActiveApiKey() {
|
||||
const activeKey = (process.env.ACTIVE_KEY ?? "pro").toLowerCase();
|
||||
if (activeKey === "lite") {
|
||||
return process.env.API_KEY_LITE ?? "";
|
||||
}
|
||||
|
||||
return process.env.API_KEY_PRO ?? "";
|
||||
}
|
||||
|
||||
export function getRuntimeConfig() {
|
||||
const claudeBin = resolveClaudeBinary(process.env.CLAUDE_BIN ?? "claude");
|
||||
return {
|
||||
port: Number(process.env.PORT ?? 3001),
|
||||
nodeEnv: process.env.NODE_ENV ?? "development",
|
||||
claudeBin,
|
||||
shell: process.env.CLAUDE_SHELL ?? "/bin/zsh",
|
||||
workspaceDir: process.env.CLAUDE_WORKSPACE_DIR
|
||||
? path.resolve(process.env.CLAUDE_WORKSPACE_DIR)
|
||||
: process.cwd(),
|
||||
anthropicBaseUrl: process.env.ANTHROPIC_BASE_URL ?? "",
|
||||
anthropicModel: process.env.ANTHROPIC_MODEL ?? "",
|
||||
activeKey: (process.env.ACTIVE_KEY ?? "pro").toLowerCase(),
|
||||
claudeArgs: process.env.CLAUDE_ARGS?.trim() ? process.env.CLAUDE_ARGS.trim().split(/\s+/) : ["--dangerously-skip-permissions"],
|
||||
watchLogLimit: Number(process.env.WATCH_LOG_LIMIT ?? 400),
|
||||
chatChunkLimit: Number(process.env.CHAT_CHUNK_LIMIT ?? 2000),
|
||||
logToConsole: toBool(process.env.LOG_TO_CONSOLE, true)
|
||||
};
|
||||
}
|
||||
|
||||
function resolveClaudeBinary(rawValue) {
|
||||
const candidates = [];
|
||||
|
||||
if (rawValue) {
|
||||
candidates.push(rawValue);
|
||||
}
|
||||
|
||||
candidates.push("/Users/wisecolt-macmini/.local/bin/claude");
|
||||
candidates.push("/usr/local/bin/claude");
|
||||
candidates.push("/opt/homebrew/bin/claude");
|
||||
|
||||
for (const candidate of candidates) {
|
||||
if (path.isAbsolute(candidate) && fs.existsSync(candidate)) {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
|
||||
const pathEntries = String(process.env.PATH ?? "").split(path.delimiter);
|
||||
for (const entry of pathEntries) {
|
||||
const candidate = path.join(entry, rawValue);
|
||||
if (fs.existsSync(candidate)) {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
|
||||
return rawValue;
|
||||
}
|
||||
|
||||
export function getClaudeEnv(config) {
|
||||
const cleanEnv = { ...process.env };
|
||||
delete cleanEnv.ANTHROPIC_AUTH_TOKEN;
|
||||
|
||||
return {
|
||||
...cleanEnv,
|
||||
ANTHROPIC_API_KEY: getActiveApiKey(),
|
||||
ANTHROPIC_BASE_URL: config.anthropicBaseUrl,
|
||||
ANTHROPIC_MODEL: config.anthropicModel,
|
||||
TERM: "xterm-256color",
|
||||
COLORTERM: "truecolor"
|
||||
};
|
||||
}
|
||||
|
||||
export function getPublicRuntimeConfig(config) {
|
||||
return {
|
||||
claudeBin: config.claudeBin,
|
||||
anthropicBaseUrl: config.anthropicBaseUrl,
|
||||
anthropicModel: config.anthropicModel,
|
||||
activeKey: config.activeKey,
|
||||
workspaceDir: config.workspaceDir
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user