mirror of
https://github.com/jasonxu114514/opencode2api.git
synced 2026-12-06 00:03:11 +00:00
fix(gateway): harden free-tier retries and client compatibility
Preserve upstream HTTP failures across transport retries, classify title requests before shaping, and rename legacy functions exactly once. Keep adjacent Responses assistant items together, including interleaved text and calls. Add opt-in prompt environment overrides with matching shell descriptions, strict validation, and WebUI round-trip preservation. Document compatibility boundaries and retain existing defaults. Include the requested test/ ignore rule. Offline zz_ regressions passed and were removed after validation as requested; vet and Windows/Linux builds passed. Refs #173, #175, #176, #178, #179, #181
This commit is contained in:
1 parent
b296a61d0e
commit
14faec7654
13 files changed
+304
-94
No files matched your search
@@ -540,7 +540,9 @@ func decodeBridgeRequest(protocol Protocol, input map[string]any) (bridgeRequest
|
||||
request.System = append(request.System, blocks...)
|
||||
} else if role == "developer" {
|
||||
request.Developer = append(request.Developer, blocks...)
|
||||
} else if role == "user" || role == "assistant" {
|
||||
} else if role == "assistant" {
|
||||
appendBridgeBlock(&request.Messages, role, blocks...)
|
||||
} else if role == "user" {
|
||||
request.Messages = append(request.Messages, bridgeMessage{Role: role, Blocks: blocks})
|
||||
}
|
||||
default:
|
||||
@@ -659,19 +661,19 @@ func decodeBridgeRequest(protocol Protocol, input map[string]any) (bridgeRequest
|
||||
return request, nil
|
||||
}
|
||||
|
||||
// appendBridgeBlock adds a block decoded from a standalone Responses item. It
|
||||
// joins the previous message when that has the same role and holds only tool
|
||||
// calls or results, so consecutive function_call (or function_call_output)
|
||||
// items form one turn; otherwise the block starts a new message.
|
||||
func appendBridgeBlock(messages *[]bridgeMessage, role string, block bridgeBlock) {
|
||||
// appendBridgeBlock adds blocks decoded from a standalone Responses item. It
|
||||
// joins adjacent assistant items into one turn, including interleaved text,
|
||||
// reasoning and tool calls. Tool results join only a preceding tool-only user
|
||||
// message, so results and user input keep assistant turns separate.
|
||||
func appendBridgeBlock(messages *[]bridgeMessage, role string, blocks ...bridgeBlock) {
|
||||
if len(*messages) > 0 {
|
||||
last := &(*messages)[len(*messages)-1]
|
||||
if last.Role == role && bridgeBlocksOnlyTools(last.Blocks) {
|
||||
last.Blocks = append(last.Blocks, block)
|
||||
if last.Role == role && (role == "assistant" || bridgeBlocksOnlyTools(last.Blocks)) {
|
||||
last.Blocks = append(last.Blocks, blocks...)
|
||||
return
|
||||
}
|
||||
}
|
||||
*messages = append(*messages, bridgeMessage{Role: role, Blocks: []bridgeBlock{block}})
|
||||
*messages = append(*messages, bridgeMessage{Role: role, Blocks: blocks})
|
||||
}
|
||||
|
||||
// bridgeBlocksOnlyTools reports whether blocks is non-empty and holds only
|
||||
|
||||
Reference in new issue
Block a user