mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-12-06 16:04:24 +00:00
The antigravity response processors, which now also render Vertex /v1/messages responses, mapped every finish reason except MAX_TOKENS to end_turn (or tool_use). A blocked or broken turn then looked like a successful empty answer: Claude Code ends the turn and the run reports success. Failure modes this commit guards against: - SAFETY, PROHIBITED_CONTENT, SPII, BLOCKLIST, IMAGE_SAFETY or RECITATION ends as end_turn. It is now stop_reason "refusal", in stream and non-stream. - A prompt blocked by promptFeedback.blockReason, with no candidates, ends as end_turn. It is now "refusal". - MALFORMED_FUNCTION_CALL, UNEXPECTED_TOOL_CALL, TOO_MANY_TOOL_CALLS or MALFORMED_RESPONSE with no text and no tool_use ends as an empty end_turn. Thinking blocks do not count as content: with thinking on, a thought summary comes before almost every invalid call. The stream now ends with an SSE error event of type api_error, which Claude Code retries. Non-stream returns ErrMalformedFunctionCall or ErrInvalidOutputWithoutContent, which callers write as a 502. - The same reasons after text or a tool call must still end normally (end_turn, or tool_use after a call). Non-stream MALFORMED_FUNCTION_CALL with text now gives end_turn too; the antigravity collect path still fails it before conversion, as before. - After the error event, no later chunk may emit content, message_delta or message_stop, and the usage must still be collected for billing. - STOP, MAX_TOKENS, OTHER and tool calls without a refusal reason keep their mapping. A refusal reason wins over tool_use. Only the mapping changes; no safetySettings are added. Effects on the other antigravity paths: - Claude, chat-completions and responses non-stream now return 502 for UNEXPECTED_TOOL_CALL, TOO_MANY_TOOL_CALLS and MALFORMED_RESPONSE without text or tool calls, where they returned an empty 200 before. - The chat-completions and responses stream adapters buffer the error event like the empty end_turn before it, so they still report an empty stream. - Not mapped, and so still end_turn: MODEL_ARMOR, IMAGE_PROHIBITED_CONTENT, IMAGE_RECITATION, IMAGE_OTHER, NO_IMAGE and CONTINUATION. Tests: pkg/antigravity/finish_reason_test.go (stream and non-stream per reason), gemini_messages_vertex_finish_test.go (Vertex /v1/messages through Forward).