From 09455f9e85b22cdadd8f71c36aebbd807fc3ed63 Mon Sep 17 00:00:00 2001 From: hkfires <10558748+hkfires@users.noreply.github.com> Date: Sat, 27 Dec 2025 20:56:47 +0800 Subject: [PATCH] fix(config): make streaming keepalive and retries ints --- internal/config/sdk_config.go | 8 ++++---- sdk/api/handlers/handlers.go | 8 ++++---- sdk/api/handlers/handlers_stream_bootstrap_test.go | 3 +-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/internal/config/sdk_config.go b/internal/config/sdk_config.go index 7f019520..596cbb2c 100644 --- a/internal/config/sdk_config.go +++ b/internal/config/sdk_config.go @@ -30,13 +30,13 @@ type SDKConfig struct { // StreamingConfig holds server streaming behavior configuration. type StreamingConfig struct { // KeepAliveSeconds controls how often the server emits SSE heartbeats (": keep-alive\n\n"). - // nil means default (15 seconds). <= 0 disables keep-alives. - KeepAliveSeconds *int `yaml:"keepalive-seconds,omitempty" json:"keepalive-seconds,omitempty"` + // <= 0 disables keep-alives. Default is 0. + KeepAliveSeconds int `yaml:"keepalive-seconds,omitempty" json:"keepalive-seconds,omitempty"` // BootstrapRetries controls how many times the server may retry a streaming request before any bytes are sent, // to allow auth rotation / transient recovery. - // nil means default (2). 0 disables bootstrap retries. - BootstrapRetries *int `yaml:"bootstrap-retries,omitempty" json:"bootstrap-retries,omitempty"` + // <= 0 disables bootstrap retries. Default is 0. + BootstrapRetries int `yaml:"bootstrap-retries,omitempty" json:"bootstrap-retries,omitempty"` } // AccessConfig groups request authentication providers. diff --git a/sdk/api/handlers/handlers.go b/sdk/api/handlers/handlers.go index a544ef0c..86ed9276 100644 --- a/sdk/api/handlers/handlers.go +++ b/sdk/api/handlers/handlers.go @@ -104,8 +104,8 @@ func BuildErrorResponseBody(status int, errText string) []byte { // Returning 0 disables keep-alives (default when unset). func StreamingKeepAliveInterval(cfg *config.SDKConfig) time.Duration { seconds := defaultStreamingKeepAliveSeconds - if cfg != nil && cfg.Streaming.KeepAliveSeconds != nil { - seconds = *cfg.Streaming.KeepAliveSeconds + if cfg != nil { + seconds = cfg.Streaming.KeepAliveSeconds } if seconds <= 0 { return 0 @@ -116,8 +116,8 @@ func StreamingKeepAliveInterval(cfg *config.SDKConfig) time.Duration { // StreamingBootstrapRetries returns how many times a streaming request may be retried before any bytes are sent. func StreamingBootstrapRetries(cfg *config.SDKConfig) int { retries := defaultStreamingBootstrapRetries - if cfg != nil && cfg.Streaming.BootstrapRetries != nil { - retries = *cfg.Streaming.BootstrapRetries + if cfg != nil { + retries = cfg.Streaming.BootstrapRetries } if retries < 0 { retries = 0 diff --git a/sdk/api/handlers/handlers_stream_bootstrap_test.go b/sdk/api/handlers/handlers_stream_bootstrap_test.go index 39eefa84..f8ce6aea 100644 --- a/sdk/api/handlers/handlers_stream_bootstrap_test.go +++ b/sdk/api/handlers/handlers_stream_bootstrap_test.go @@ -94,10 +94,9 @@ func TestExecuteStreamWithAuthManager_RetriesBeforeFirstByte(t *testing.T) { registry.GetGlobalRegistry().UnregisterClient(auth2.ID) }) - bootstrapRetries := 1 handler := NewBaseAPIHandlers(&sdkconfig.SDKConfig{ Streaming: sdkconfig.StreamingConfig{ - BootstrapRetries: &bootstrapRetries, + BootstrapRetries: 1, }, }, manager) dataChan, errChan := handler.ExecuteStreamWithAuthManager(context.Background(), "openai", "test-model", []byte(`{"model":"test-model"}`), "")