diff --git a/README.md b/README.md index bedc55c..f708cea 100644 --- a/README.md +++ b/README.md @@ -570,6 +570,7 @@ A huge thank you to all our sponsors for their generous support! - @zcutlip - [@Peng-YM](http://github.com/Peng-YM) - @\*更 +- @\*. (If your name is masked, please contact me via my homepage email to update it with your GitHub username.) diff --git a/README_zh.md b/README_zh.md index 37d8efc..8c12175 100644 --- a/README_zh.md +++ b/README_zh.md @@ -539,6 +539,7 @@ jobs: - @zcutlip - [@Peng-YM](http://github.com/Peng-YM) - @\*更 +- @\*. (如果您的名字被屏蔽,请通过我的主页电子邮件与我联系,以便使用您的 GitHub 用户名进行更新。) diff --git a/package.json b/package.json index 16e6cac..1cd4d47 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@musistudio/claude-code-router", - "version": "1.0.44", + "version": "1.0.45", "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.29", + "@musistudio/llms": "^1.0.30", "dotenv": "^16.4.7", "json5": "^2.2.3", "openurl": "^1.1.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 045de68..3363332 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.29 - version: 1.0.29(ws@8.18.3) + specifier: ^1.0.30 + version: 1.0.30(ws@8.18.3) dotenv: specifier: ^16.4.7 version: 16.6.1 @@ -266,8 +266,8 @@ packages: resolution: {integrity: sha512-9I2Zn6+NJLfaGoz9jN3lpwDgAYvfGeNYdbAIjJOqzs4Tpc+VU3Jqq4IofSUBKajiDS8k9fZIg18/z13mpk1bsA==} engines: {node: '>=8'} - '@musistudio/llms@1.0.29': - resolution: {integrity: sha512-U1mAgkFuItc2pSgrT8YZl/v3bGC8MpWjHWcsIhFkce0kS6OKuj7QtZuCBC0MUetUFay8dmkSdRq7jM2qzb3N9A==} + '@musistudio/llms@1.0.30': + resolution: {integrity: sha512-vqeAz+noIm0G53DVDnyyAgv90HxObG/URlPjQE89YQafG10xkRUemHyuyscRgiHKvut9Z0FF0i8m0Uiqat068A==} '@nodelib/fs.scandir@2.1.5': resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==} @@ -1111,7 +1111,7 @@ snapshots: '@lukeed/ms@2.0.2': {} - '@musistudio/llms@1.0.29(ws@8.18.3)': + '@musistudio/llms@1.0.30(ws@8.18.3)': dependencies: '@anthropic-ai/sdk': 0.54.0 '@fastify/cors': 11.1.0 diff --git a/src/agents/image.agent.ts b/src/agents/image.agent.ts index 0a66f7b..b3d3d61 100644 --- a/src/agents/image.agent.ts +++ b/src/agents/image.agent.ts @@ -17,15 +17,8 @@ class ImageCache { }); } - calculateHash(base64Image: string): string { - const hash = createHash('sha256'); - hash.update(base64Image); - return hash.digest('hex'); - } - storeImage(id: string, source: any): void { if (this.hasImage(id)) return; - const base64Image = source.data this.cache.set(id, { source, timestamp: Date.now(), @@ -62,7 +55,7 @@ export class ImageAgent implements IAgent { } shouldHandle(req: any, config: any): boolean { - if (!config.Router.image) return false; + if (!config.Router.image || req.body.model === config.Router.image) return false; const lastMessage = req.body.messages[req.body.messages.length - 1] if (!config.forceUseImageAgent && lastMessage.role === 'user' && Array.isArray(lastMessage.content) &&lastMessage.content.find((item: any) => item.type === 'image')) { req.body.model = config.Router.image @@ -109,6 +102,7 @@ export class ImageAgent implements IAgent { "required": ["imageId", "task"] }, handler: async (args, context) => { + console.log('args', JSON.stringify(args, null, 2)) const imageMessages = []; let imageId; @@ -127,7 +121,6 @@ export class ImageAgent implements IAgent { delete args.imageId; } - // Add text message with the response if (Object.keys(args).length > 0) { imageMessages.push({ type: "text", @@ -146,7 +139,10 @@ export class ImageAgent implements IAgent { model: context.config.Router.image, system: [{ type: 'text', - text: `你需要按照任务去解析图片` + text: `You must interpret and analyze images strictly according to the assigned task. +When an image placeholder is provided, your role is to parse the image content only within the scope of the user’s instructions. +Do not ignore or deviate from the task. +Always ensure that your response reflects a clear, accurate interpretation of the image aligned with the given objective.` }], messages: [ { @@ -159,6 +155,7 @@ export class ImageAgent implements IAgent { }).then(res => res.json()).catch(err => { return null; }); + console.log(agentResponse.content); if (!agentResponse || !agentResponse.content) { return 'analyzeImage Error'; } diff --git a/src/index.ts b/src/index.ts index 837b560..1b72f01 100644 --- a/src/index.ts +++ b/src/index.ts @@ -148,6 +148,9 @@ async function run(options: RunOptions = {}) { // append agent tools if (agent.tools.size) { + if (!req.body?.tools?.length) { + req.body.tools = [] + } req.body.tools.unshift(...Array.from(agent.tools.values()).map(item => { return { name: item.name, @@ -211,6 +214,7 @@ async function run(options: RunOptions = {}) { req, config }); + console.log('result', toolResult) toolMessages.push({ "tool_use_id": currentToolId, "type": "tool_result", diff --git a/src/utils/codeCommand.ts b/src/utils/codeCommand.ts index 87c46f8..19017c1 100644 --- a/src/utils/codeCommand.ts +++ b/src/utils/codeCommand.ts @@ -65,7 +65,6 @@ export async function executeCodeCommand(args: string[] = []) { const stdioConfig: StdioOptions = config.NON_INTERACTIVE_MODE ? ["pipe", "inherit", "inherit"] // Pipe stdin for non-interactive : "inherit"; // Default inherited behavior - console.log(joinedArgs) const claudeProcess = spawn( claudePath + (joinedArgs ? ` ${joinedArgs}` : ""), [],