From 66b6363ad4a5e8a25f54973268d6b176b75277e3 Mon Sep 17 00:00:00 2001 From: bee4come Date: Wed, 15 Oct 2025 13:26:58 +0800 Subject: [PATCH] feat: improve Droid provider implementation and configuration - Add --skip-permissions-unsafe flag to droid exec commands for non-interactive execution - Improve error handling to accept output from both stdout and stderr - Map droid protocol to claude in getProtocolPrefix for proper request conversion - Add DROID_AUTH_FILE and DROID_COMMAND to config.json.example - Add droid-factory-oauth provider pool example to provider_pools.json.example Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> --- config.json.example | 2 ++ package-lock.json | 2 +- provider_pools.json.example | 13 +++++++++++++ src/common.js | 11 +++++++++-- src/droid/droid-core.js | 12 +++++++----- 5 files changed, 32 insertions(+), 8 deletions(-) diff --git a/config.json.example b/config.json.example index c032ffa..c1aa668 100644 --- a/config.json.example +++ b/config.json.example @@ -13,6 +13,8 @@ "KIRO_OAUTH_CREDS_BASE64": null, "KIRO_OAUTH_CREDS_FILE_PATH": null, "QWEN_OAUTH_CREDS_FILE_PATH": null, + "DROID_AUTH_FILE": null, + "DROID_COMMAND": "droid", "SYSTEM_PROMPT_FILE_PATH": "input_system_prompt.txt", "SYSTEM_PROMPT_MODE": "overwrite", "PROMPT_LOG_BASE_NAME": "prompt_log", diff --git a/package-lock.json b/package-lock.json index 3779e5c..95af3d8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "AIClient2API", + "name": "AIClient-2-API", "lockfileVersion": 3, "requires": true, "packages": { diff --git a/provider_pools.json.example b/provider_pools.json.example index 460d804..b30dd55 100644 --- a/provider_pools.json.example +++ b/provider_pools.json.example @@ -104,5 +104,18 @@ "errorCount": 0, "lastErrorTime": null } + ], + "droid-factory-oauth": [ + { + "DROID_AUTH_FILE": "~/.factory/auth.json", + "DROID_COMMAND": "droid", + "uuid": "9d8e7f6a-5c4b-3a2d-1e0f-9a8b7c6d5e4f", + "checkModelName": null, + "isHealthy": true, + "lastUsed": null, + "usageCount": 0, + "errorCount": 0, + "lastErrorTime": null + } ] } \ No newline at end of file diff --git a/src/common.js b/src/common.js index 91b8a2e..88d685d 100644 --- a/src/common.js +++ b/src/common.js @@ -37,10 +37,17 @@ export const MODEL_PROVIDER = { */ export function getProtocolPrefix(provider) { const hyphenIndex = provider.indexOf('-'); + let prefix = provider; if (hyphenIndex !== -1) { - return provider.substring(0, hyphenIndex); + prefix = provider.substring(0, hyphenIndex); } - return provider; // Return original if no hyphen is found + + // Map droid protocol to claude (since droid uses Claude API) + if (prefix === 'droid') { + return 'claude'; + } + + return prefix; } export const ENDPOINT_TYPE = { diff --git a/src/droid/droid-core.js b/src/droid/droid-core.js index cd07e89..dea7898 100644 --- a/src/droid/droid-core.js +++ b/src/droid/droid-core.js @@ -53,10 +53,12 @@ export class DroidApiService { }); droid.on('close', (code) => { - if (code !== 0) { - reject(new Error(`Droid command failed: ${stderr || stdout}`)); + // Droid CLI may output to stderr even on success + const output = stdout || stderr; + if (code !== 0 && !output) { + reject(new Error(`Droid command failed with code ${code}: ${stderr || stdout}`)); } else { - resolve(stdout); + resolve(output); } }); @@ -97,7 +99,7 @@ export class DroidApiService { try { const prompt = this.messagesToPrompt(requestBody.messages); - const output = await this.executeDroidCommand(['exec', prompt]); + const output = await this.executeDroidCommand(['exec', '--skip-permissions-unsafe', prompt]); return { id: `msg_${Date.now()}`, @@ -149,7 +151,7 @@ export class DroidApiService { content_block: { type: 'text', text: '' } }; - const droid = spawn(this.droidCommand, ['exec', prompt]); + const droid = spawn(this.droidCommand, ['exec', '--skip-permissions-unsafe', prompt]); let buffer = ''; for await (const chunk of droid.stdout) {