diff --git a/cmd/creator-web/server.go b/cmd/creator-web/server.go index cfa9a72..5249318 100644 --- a/cmd/creator-web/server.go +++ b/cmd/creator-web/server.go @@ -28,7 +28,11 @@ import ( const ( maxRequestBytes = 8 << 10 maxAdvisoryRequestBytes = 20 << 10 - maxResponseBytes = 1 << 20 + // Chat responses may contain a locally generated image encoded as base64. + // Keep the gateway limit aligned with the bounded media transport (32 MiB), + // otherwise a successfully generated image is incorrectly surfaced as an + // unavailable runtime to the human. + maxResponseBytes = 32 << 20 ) //go:embed static diff --git a/cmd/creator-web/server_test.go b/cmd/creator-web/server_test.go index 7a6e277..d92c2ab 100644 --- a/cmd/creator-web/server_test.go +++ b/cmd/creator-web/server_test.go @@ -1,6 +1,7 @@ package main import ( + "bytes" "encoding/json" "fmt" "io" @@ -13,6 +14,25 @@ import ( "git.cin.su/m/Assistant/contracts/interaction" ) +func TestMaxResponseBytesAcceptsGeneratedImagePayload(t *testing.T) { + // A 1024px PNG can exceed the former 1 MiB gateway limit once base64 + // encoded. The browser gateway must forward that successful core response. + payload, err := json.Marshal(interaction.ChatMessageResponse{ + GeneratedImageContentType: "image/png", + GeneratedImageBase64: strings.Repeat("A", 2<<20), + }) + if err != nil { + t.Fatal(err) + } + var decoded interaction.ChatMessageResponse + if err := decodeStrictJSON(bytes.NewReader(payload), maxResponseBytes, &decoded); err != nil { + t.Fatalf("generated image response must fit gateway limit: %v", err) + } + if len(decoded.GeneratedImageBase64) != 2<<20 { + t.Fatalf("generated image payload was truncated: %d", len(decoded.GeneratedImageBase64)) + } +} + func TestLocalChatContextIncludesDomovoyIdentityAndOptionalActiveProject(t *testing.T) { context := localChatContext(interaction.ChatMessageResponse{AssistantName: "Фея", ActiveProjectName: "Домовой"}) if len(context) != 2 || context[0].SourceID != "domovoy" || !strings.Contains(context[0].Text, "Ты — Фея") || !strings.Contains(context[0].Text, "Меня зовут Фея") || context[1].Text != "Текущий проект: Домовой" {