From d3c3a4ae0aced5c7dc7faa9f92e728836da1640e Mon Sep 17 00:00:00 2001 From: decolua Date: Tue, 10 Feb 2026 19:18:40 +0700 Subject: [PATCH] Remove Docker publish workflow and update error handling in various modules - Added handling for HTTP_STATUS.NOT_ACCEPTABLE in error types and messages. - Enhanced the `prepareClaudeRequest` function to filter built-in tools for non-Anthropic providers and clean up empty tool arrays. - Updated the `openaiToClaudeRequest` function to handle built-in tools more effectively and ensure proper tool conversion. - Improved the `claudeToOpenAIResponse` function to skip processing for built-in server tool blocks. - Refined error message handling in the `parseUpstreamError` function to ensure meaningful output. - Adjusted command checks for tool installations across various settings routes to use `command -v` for better compatibility. --- .github/workflows/docker-publish.yml | 63 ------------------- open-sse/config/constants.js | 2 + open-sse/translator/helpers/claudeHelper.js | 13 +++- .../translator/request/openai-to-claude.js | 18 ++++-- .../translator/response/claude-to-openai.js | 12 ++++ open-sse/utils/error.js | 7 ++- .../api/cli-tools/claude-settings/route.js | 2 +- src/app/api/cli-tools/codex-settings/route.js | 2 +- src/app/api/cli-tools/droid-settings/route.js | 2 +- .../api/cli-tools/openclaw-settings/route.js | 2 +- 10 files changed, 47 insertions(+), 76 deletions(-) delete mode 100644 .github/workflows/docker-publish.yml diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml deleted file mode 100644 index 7f5cb4f..0000000 --- a/.github/workflows/docker-publish.yml +++ /dev/null @@ -1,63 +0,0 @@ -name: Build and Push Docker Image - -on: - push: - branches: - - master - tags: - - 'v*' - pull_request: - branches: - - master - workflow_dispatch: - -env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} - -jobs: - build-and-push: - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Log in to Container Registry - if: github.event_name != 'pull_request' - uses: docker/login-action@v3 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Extract metadata (tags, labels) - id: meta - uses: docker/metadata-action@v5 - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - tags: | - type=ref,event=branch - type=ref,event=pr - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - type=semver,pattern={{major}} - type=sha,prefix= - type=raw,value=latest,enable={{is_default_branch}} - - - name: Build and push Docker image - uses: docker/build-push-action@v6 - with: - context: . - push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max - platforms: linux/amd64,linux/arm64 diff --git a/open-sse/config/constants.js b/open-sse/config/constants.js index 0e2ddc2..2da1f6b 100644 --- a/open-sse/config/constants.js +++ b/open-sse/config/constants.js @@ -246,6 +246,7 @@ export const ERROR_TYPES = { [HTTP_STATUS.UNAUTHORIZED]: { type: "authentication_error", code: "invalid_api_key" }, [HTTP_STATUS.FORBIDDEN]: { type: "permission_error", code: "insufficient_quota" }, [HTTP_STATUS.NOT_FOUND]: { type: "invalid_request_error", code: "model_not_found" }, + [HTTP_STATUS.NOT_ACCEPTABLE]: { type: "invalid_request_error", code: "model_not_supported" }, [HTTP_STATUS.RATE_LIMITED]: { type: "rate_limit_error", code: "rate_limit_exceeded" }, [HTTP_STATUS.SERVER_ERROR]: { type: "server_error", code: "internal_server_error" }, [HTTP_STATUS.BAD_GATEWAY]: { type: "server_error", code: "bad_gateway" }, @@ -259,6 +260,7 @@ export const DEFAULT_ERROR_MESSAGES = { [HTTP_STATUS.UNAUTHORIZED]: "Invalid API key provided", [HTTP_STATUS.FORBIDDEN]: "You exceeded your current quota", [HTTP_STATUS.NOT_FOUND]: "Model not found", + [HTTP_STATUS.NOT_ACCEPTABLE]: "Model not supported", [HTTP_STATUS.RATE_LIMITED]: "Rate limit exceeded", [HTTP_STATUS.SERVER_ERROR]: "Internal server error", [HTTP_STATUS.BAD_GATEWAY]: "Bad gateway - upstream provider error", diff --git a/open-sse/translator/helpers/claudeHelper.js b/open-sse/translator/helpers/claudeHelper.js index 9c75cd3..efd8bcc 100644 --- a/open-sse/translator/helpers/claudeHelper.js +++ b/open-sse/translator/helpers/claudeHelper.js @@ -164,8 +164,13 @@ export function prepareClaudeRequest(body, provider = null) { } } - // 3. Tools: remove all cache_control, add only to last tool with ttl 1h + // 3. Tools: filter built-in tools for non-Anthropic providers, then handle cache_control if (body.tools && Array.isArray(body.tools)) { + // Strip built-in tools (e.g. web_search_20250305) for providers that don't support them + if (provider !== "claude") { + body.tools = body.tools.filter(tool => !tool.type || tool.type === "function"); + } + body.tools = body.tools.map((tool, i) => { const { cache_control, ...rest } = tool; if (i === body.tools.length - 1) { @@ -173,6 +178,12 @@ export function prepareClaudeRequest(body, provider = null) { } return rest; }); + + // Remove tools array and tool_choice if empty after filtering + if (body.tools.length === 0) { + delete body.tools; + delete body.tool_choice; + } } return body; diff --git a/open-sse/translator/request/openai-to-claude.js b/open-sse/translator/request/openai-to-claude.js index bfed352..05ab08f 100644 --- a/open-sse/translator/request/openai-to-claude.js +++ b/open-sse/translator/request/openai-to-claude.js @@ -114,8 +114,16 @@ export function openaiToClaudeRequest(model, body, stream) { // Tools - convert from OpenAI format to Claude format with prefix for OAuth if (body.tools && Array.isArray(body.tools)) { - result.tools = body.tools.map(tool => { - const toolData = tool.type === "function" && tool.function ? tool.function : tool; + result.tools = []; + for (const tool of body.tools) { + // Pass-through built-in tools (e.g. web_search_20250305) without prefix or conversion + const toolType = tool.type; + if (toolType && toolType !== "function") { + result.tools.push(tool); + continue; + } + + const toolData = toolType === "function" && tool.function ? tool.function : tool; const originalName = toolData.name; // Claude OAuth requires prefixed tool names to avoid conflicts @@ -124,12 +132,12 @@ export function openaiToClaudeRequest(model, body, stream) { // Store mapping for response translation (prefixed → original) toolNameMap.set(toolName, originalName); - return { + result.tools.push({ name: toolName, description: toolData.description || "", input_schema: toolData.parameters || toolData.input_schema || { type: "object", properties: {}, required: [] } - }; - }); + }); + } if (result.tools.length > 0) { result.tools[result.tools.length - 1].cache_control = { type: "ephemeral", ttl: "1h" }; diff --git a/open-sse/translator/response/claude-to-openai.js b/open-sse/translator/response/claude-to-openai.js index 0501393..c3b33fc 100644 --- a/open-sse/translator/response/claude-to-openai.js +++ b/open-sse/translator/response/claude-to-openai.js @@ -34,6 +34,11 @@ export function claudeToOpenAIResponse(chunk, state) { case "content_block_start": { const block = chunk.content_block; + if (block?.type === "server_tool_use") { + // Built-in tool (web search) - Claude handles internally, skip + state.serverToolBlockIndex = chunk.index; + break; + } if (block?.type === "text") { state.textBlockStarted = true; } else if (block?.type === "thinking") { @@ -60,6 +65,8 @@ export function claudeToOpenAIResponse(chunk, state) { } case "content_block_delta": { + // Skip deltas for built-in server tool blocks (web search) + if (chunk.index === state.serverToolBlockIndex) break; const delta = chunk.delta; if (delta?.type === "text_delta" && delta.text) { results.push(createChunk(state, { content: delta.text })); @@ -82,6 +89,11 @@ export function claudeToOpenAIResponse(chunk, state) { } case "content_block_stop": { + // Skip stop for built-in server tool blocks (web search) + if (chunk.index === state.serverToolBlockIndex) { + state.serverToolBlockIndex = -1; + break; + } if (state.inThinkingBlock && chunk.index === state.currentBlockIndex) { results.push(createChunk(state, { reasoning_content: "" })); state.inThinkingBlock = false; diff --git a/open-sse/utils/error.js b/open-sse/utils/error.js index 323f3ae..31497dd 100644 --- a/open-sse/utils/error.js +++ b/open-sse/utils/error.js @@ -110,15 +110,16 @@ export async function parseUpstreamError(response, provider = null) { } const messageStr = typeof message === "string" ? message : JSON.stringify(message); - + const finalMessage = messageStr || DEFAULT_ERROR_MESSAGES[response.status] || `Upstream error: ${response.status}`; + // Parse Antigravity-specific retry time from error message if (provider === "antigravity" && response.status === 429) { - retryAfterMs = parseAntigravityRetryTime(messageStr); + retryAfterMs = parseAntigravityRetryTime(finalMessage); } return { statusCode: response.status, - message: messageStr, + message: finalMessage, retryAfterMs }; } diff --git a/src/app/api/cli-tools/claude-settings/route.js b/src/app/api/cli-tools/claude-settings/route.js index e64d094..29efbbe 100644 --- a/src/app/api/cli-tools/claude-settings/route.js +++ b/src/app/api/cli-tools/claude-settings/route.js @@ -20,7 +20,7 @@ const getClaudeSettingsPath = () => { const checkClaudeInstalled = async () => { try { const isWindows = os.platform() === "win32"; - const command = isWindows ? "where claude" : "which claude"; + const command = isWindows ? "where claude" : "command -v claude"; await execAsync(command); return true; } catch { diff --git a/src/app/api/cli-tools/codex-settings/route.js b/src/app/api/cli-tools/codex-settings/route.js index 18f17eb..90bf85a 100644 --- a/src/app/api/cli-tools/codex-settings/route.js +++ b/src/app/api/cli-tools/codex-settings/route.js @@ -75,7 +75,7 @@ const toToml = (parsed) => { const checkCodexInstalled = async () => { try { const isWindows = os.platform() === "win32"; - const command = isWindows ? "where codex" : "which codex"; + const command = isWindows ? "where codex" : "command -v codex"; await execAsync(command); return true; } catch { diff --git a/src/app/api/cli-tools/droid-settings/route.js b/src/app/api/cli-tools/droid-settings/route.js index 12f6554..cdf044a 100644 --- a/src/app/api/cli-tools/droid-settings/route.js +++ b/src/app/api/cli-tools/droid-settings/route.js @@ -16,7 +16,7 @@ const getDroidSettingsPath = () => path.join(getDroidDir(), "settings.json"); const checkDroidInstalled = async () => { try { const isWindows = os.platform() === "win32"; - const command = isWindows ? "where droid" : "which droid"; + const command = isWindows ? "where droid" : "command -v droid"; await execAsync(command); return true; } catch { diff --git a/src/app/api/cli-tools/openclaw-settings/route.js b/src/app/api/cli-tools/openclaw-settings/route.js index cd46bcd..4c1af02 100644 --- a/src/app/api/cli-tools/openclaw-settings/route.js +++ b/src/app/api/cli-tools/openclaw-settings/route.js @@ -16,7 +16,7 @@ const getOpenClawSettingsPath = () => path.join(getOpenClawDir(), "openclaw.json const checkOpenClawInstalled = async () => { try { const isWindows = os.platform() === "win32"; - const command = isWindows ? "where openclaw" : "which openclaw"; + const command = isWindows ? "where openclaw" : "command -v openclaw"; await execAsync(command); return true; } catch {