diff --git a/internal/api/modules/amp/response_rewriter.go b/internal/api/modules/amp/response_rewriter.go index d78af9f1..e6f20c57 100644 --- a/internal/api/modules/amp/response_rewriter.go +++ b/internal/api/modules/amp/response_rewriter.go @@ -95,7 +95,13 @@ func (rw *ResponseRewriter) Write(data []byte) (int, error) { } if rw.isStreaming { - return rw.ResponseWriter.Write(rw.rewriteStreamChunk(data)) + n, err := rw.ResponseWriter.Write(rw.rewriteStreamChunk(data)) + if err == nil { + if flusher, ok := rw.ResponseWriter.(http.Flusher); ok { + flusher.Flush() + } + } + return n, err } return rw.body.Write(data) } diff --git a/internal/registry/model_definitions.go b/internal/registry/model_definitions.go index c6282759..899314bb 100644 --- a/internal/registry/model_definitions.go +++ b/internal/registry/model_definitions.go @@ -648,8 +648,9 @@ func GetIFlowModels() []*ModelInfo { {ID: "glm-4.6", DisplayName: "GLM-4.6", Description: "Zhipu GLM 4.6 general model", Created: 1759190400}, {ID: "kimi-k2", DisplayName: "Kimi-K2", Description: "Moonshot Kimi K2 general model", Created: 1752192000}, {ID: "kimi-k2-thinking", DisplayName: "Kimi-K2-Thinking", Description: "Moonshot Kimi K2 thinking model", Created: 1762387200, Thinking: &ThinkingSupport{Levels: []string{"low", "medium", "high"}}}, - {ID: "deepseek-v3.2-chat", DisplayName: "DeepSeek-V3.2", Description: "DeepSeek V3.2", Created: 1764576000}, - {ID: "deepseek-v3.2", DisplayName: "DeepSeek-V3.2-Exp", Description: "DeepSeek V3.2 experimental", Created: 1759104000}, + {ID: "deepseek-v3.2-chat", DisplayName: "DeepSeek-V3.2", Description: "DeepSeek V3.2 Chat", Created: 1764576000}, + {ID: "deepseek-v3.2-reasoner", DisplayName: "DeepSeek-V3.2", Description: "DeepSeek V3.2 Reasoner", Created: 1764576000}, + {ID: "deepseek-v3.2-exp", DisplayName: "DeepSeek-V3.2-Exp", Description: "DeepSeek V3.2 experimental", Created: 1759104000}, {ID: "deepseek-v3.1", DisplayName: "DeepSeek-V3.1-Terminus", Description: "DeepSeek V3.1 Terminus", Created: 1756339200}, {ID: "deepseek-r1", DisplayName: "DeepSeek-R1", Description: "DeepSeek reasoning model R1", Created: 1737331200, Thinking: &ThinkingSupport{Levels: []string{"low", "medium", "high"}}}, {ID: "deepseek-v3", DisplayName: "DeepSeek-V3-671B", Description: "DeepSeek V3 671B", Created: 1734307200}, diff --git a/internal/runtime/executor/gemini_cli_executor.go b/internal/runtime/executor/gemini_cli_executor.go index 4db33c57..b3acb50f 100644 --- a/internal/runtime/executor/gemini_cli_executor.go +++ b/internal/runtime/executor/gemini_cli_executor.go @@ -11,6 +11,8 @@ import ( "fmt" "io" "net/http" + "regexp" + "strconv" "strings" "time" @@ -784,20 +786,45 @@ func parseRetryDelay(errorBody []byte) (*time.Duration, error) { // Try to parse the retryDelay from the error response // Format: error.details[].retryDelay where @type == "type.googleapis.com/google.rpc.RetryInfo" details := gjson.GetBytes(errorBody, "error.details") - if !details.Exists() || !details.IsArray() { - return nil, fmt.Errorf("no error.details found") + if details.Exists() && details.IsArray() { + for _, detail := range details.Array() { + typeVal := detail.Get("@type").String() + if typeVal == "type.googleapis.com/google.rpc.RetryInfo" { + retryDelay := detail.Get("retryDelay").String() + if retryDelay != "" { + // Parse duration string like "0.847655010s" + duration, err := time.ParseDuration(retryDelay) + if err != nil { + return nil, fmt.Errorf("failed to parse duration") + } + return &duration, nil + } + } + } + + // Fallback: try ErrorInfo.metadata.quotaResetDelay (e.g., "373.801628ms") + for _, detail := range details.Array() { + typeVal := detail.Get("@type").String() + if typeVal == "type.googleapis.com/google.rpc.ErrorInfo" { + quotaResetDelay := detail.Get("metadata.quotaResetDelay").String() + if quotaResetDelay != "" { + duration, err := time.ParseDuration(quotaResetDelay) + if err == nil { + return &duration, nil + } + } + } + } } - for _, detail := range details.Array() { - typeVal := detail.Get("@type").String() - if typeVal == "type.googleapis.com/google.rpc.RetryInfo" { - retryDelay := detail.Get("retryDelay").String() - if retryDelay != "" { - // Parse duration string like "0.847655010s" - duration, err := time.ParseDuration(retryDelay) - if err != nil { - return nil, fmt.Errorf("failed to parse duration") - } + // Fallback: parse from error.message "Your quota will reset after Xs." + message := gjson.GetBytes(errorBody, "error.message").String() + if message != "" { + re := regexp.MustCompile(`after\s+(\d+)s\.?`) + if matches := re.FindStringSubmatch(message); len(matches) > 1 { + seconds, err := strconv.Atoi(matches[1]) + if err == nil { + duration := time.Duration(seconds) * time.Second return &duration, nil } }