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.
This commit is contained in:
decolua
2026-02-10 19:18:40 +07:00
parent 1d8251cb30
commit d3c3a4ae0a
10 changed files with 47 additions and 76 deletions

View File

@@ -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

View File

@@ -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",

View File

@@ -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;

View File

@@ -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" };

View File

@@ -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;

View File

@@ -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
};
}

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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 {