diff --git a/package.json b/package.json index fcd1635..b87318a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@musistudio/claude-code-router", - "version": "1.0.38", + "version": "1.0.39", "description": "Use Claude Code without an Anthropics account and route it to another LLM provider", "bin": { "ccr": "./dist/cli.js" @@ -20,7 +20,7 @@ "license": "MIT", "dependencies": { "@fastify/static": "^8.2.0", - "@musistudio/llms": "^1.0.24", + "@musistudio/llms": "^1.0.25", "dotenv": "^16.4.7", "json5": "^2.2.3", "openurl": "^1.1.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cf223d8..5c6938d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12,8 +12,8 @@ importers: specifier: ^8.2.0 version: 8.2.0 '@musistudio/llms': - specifier: ^1.0.24 - version: 1.0.24(ws@8.18.3)(zod@3.25.67) + specifier: ^1.0.25 + version: 1.0.25(ws@8.18.3)(zod@3.25.67) dotenv: specifier: ^16.4.7 version: 16.6.1 @@ -260,8 +260,8 @@ packages: resolution: {integrity: sha512-9I2Zn6+NJLfaGoz9jN3lpwDgAYvfGeNYdbAIjJOqzs4Tpc+VU3Jqq4IofSUBKajiDS8k9fZIg18/z13mpk1bsA==} engines: {node: '>=8'} - '@musistudio/llms@1.0.24': - resolution: {integrity: sha512-Hz6ZT92/ZM/eR5kTdCBHD6zoEMOvT5u6g/vfCir5Hwvl4QGHk3g30EmX1pZAXJf83kLnB/lSEq/HQimFIXHIhQ==} + '@musistudio/llms@1.0.25': + resolution: {integrity: sha512-l+MbVrCrUN/BbYDAJVqpDCkQm4i/baYigxv9ZhNLaQXUU1OVFRvxMq7nQrZdv4AsmVExsKzLNw+m/+B181Ot6Q==} '@nodelib/fs.scandir@2.1.5': resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==} @@ -1112,7 +1112,7 @@ snapshots: '@lukeed/ms@2.0.2': {} - '@musistudio/llms@1.0.24(ws@8.18.3)(zod@3.25.67)': + '@musistudio/llms@1.0.25(ws@8.18.3)(zod@3.25.67)': dependencies: '@anthropic-ai/sdk': 0.54.0 '@fastify/cors': 11.0.1 diff --git a/src/index.ts b/src/index.ts index ecb7e11..8d0954d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -89,7 +89,7 @@ async function run(options: RunOptions = {}) { // Configure logger based on config settings const loggerConfig = config.LOG !== false ? { - level: config.LOG_LEVEL || "info", + level: config.LOG_LEVEL || "debug", stream: createWriteStream({ path: HOME_DIR, filename: config.LOGNAME || `./logs/ccr-${+new Date()}.log`, diff --git a/src/utils/codeCommand.ts b/src/utils/codeCommand.ts index 14e1ee3..29eb896 100644 --- a/src/utils/codeCommand.ts +++ b/src/utils/codeCommand.ts @@ -16,6 +16,18 @@ export async function executeCodeCommand(args: string[] = []) { API_TIMEOUT_MS: String(config.API_TIMEOUT_MS ?? 600000), // Default to 10 minutes if not set }; + const settingsFlag: Record = {}; + if (config?.StatusLine?.enabled) { + settingsFlag.statusLine = { + type: "command", + command: "ccr statusline", + padding: 0, + }; + } + if (Object.keys(settingsFlag).length > 0) { + args.push(`--settings=${JSON.stringify(settingsFlag)}`); + } + // Non-interactive mode for automation environments if (config.NON_INTERACTIVE_MODE) { env.CI = "true"; @@ -39,21 +51,28 @@ export async function executeCodeCommand(args: string[] = []) { // Execute claude command const claudePath = process.env.CLAUDE_PATH || "claude"; - + // Properly join arguments to preserve spaces in quotes // Wrap each argument in double quotes to preserve single and double quotes inside arguments - const joinedArgs = args.length > 0 ? args.map(arg => `"${arg.replace(/\"/g, '\\"')}"`).join(" ") : ""; + const joinedArgs = + args.length > 0 + ? args.map((arg) => `"${arg.replace(/\"/g, '\\"')}"`).join(" ") + : ""; // 🔥 CONFIG-DRIVEN: stdio configuration based on environment const stdioConfig: StdioOptions = config.NON_INTERACTIVE_MODE ? ["pipe", "inherit", "inherit"] // Pipe stdin for non-interactive : "inherit"; // Default inherited behavior - const claudeProcess = spawn(claudePath + (joinedArgs ? ` ${joinedArgs}` : ""), [], { - env, - stdio: stdioConfig, - shell: true, - }); + const claudeProcess = spawn( + claudePath + (joinedArgs ? ` ${joinedArgs}` : ""), + [], + { + env, + stdio: stdioConfig, + shell: true, + } + ); // Close stdin for non-interactive mode if (config.NON_INTERACTIVE_MODE) { diff --git a/src/utils/router.ts b/src/utils/router.ts index d3683dc..f592d4d 100644 --- a/src/utils/router.ts +++ b/src/utils/router.ts @@ -125,7 +125,14 @@ const getUseModel = async (req: any, tokenCount: number, config: any) => { return config.Router!.default; }; -export const router = async (req: any, _res: any, config: any) => { +export const router = async (req: any, _res: any, config: any) => { + // Parse sessionId from metadata.user_id + if (req.body.metadata?.user_id) { + const parts = req.body.metadata.user_id.split('_session_'); + if (parts.length > 1) { + req.sessionId = parts[1]; + } + } const { messages, system = [], tools }: MessageCreateParamsBase = req.body; try { const tokenCount = calculateTokenCount(