AIStudio2API icon indicating copy to clipboard operation
AIStudio2API copied to clipboard

[Bug] encodeBuildGenerationConfig runs Playground's encodeResponseSchema validator on Build-only ResponseJSONSchema, rejecting schemas RequestNeedsBuild routed to Build

Open photobrand opened this issue 1 week ago • 1 comments

发生了什么 / What happened

Summary

RequestNeedsBuild (internal/aistudio/schema.go:997-1002) specifically routes requests using JSON Schema features unsupported by Playground (boolean schemas true/false, not, root $ref, etc.) to the Build channel.

However, encodeBuildGenerationConfig (internal/aistudio/build.go:469-506) passes config unchanged into resolveGenerationSettings:

func encodeBuildGenerationConfig(config GenerationConfig, defaults GenerationDefaults) (map[string]any, error) {
	defaults.ContinuedOutputTokens = 0
	settings, err := resolveGenerationSettings(config, defaults)
	if err != nil {
		return nil, err
	}
...
	if len(config.ResponseSchema) == 0 && len(config.ResponseJSONSchema) > 0 {
		delete(encoded, "responseMimeType")
		encoded["responseFormat"] = map[string]any{"text": map[string]any{"mimeType": "APPLICATION_JSON", "schema": config.ResponseJSONSchema}}
	}

Trigger & Consequence

resolveGenerationSettings (internal/aistudio/generate.go:185-190) calls Playground's encodeResponseSchema(config.responseSchema()), which rejects those exact Build-only JSON Schemas—even though lines 503-506 do not use settings.responseSchema at all and send raw config.ResponseJSONSchema in responseFormat.

Suggested Fix

Before calling resolveGenerationSettings in encodeBuildGenerationConfig, save jsonSchema := config.ResponseJSONSchema and clear config.ResponseJSONSchema = nil when len(config.ResponseSchema) == 0 && len(jsonSchema) > 0 (then emit jsonSchema at lines 503-506).

版本 / Version

v0.3.14

photobrand avatar Nov 22 '26 15:11 photobrand

每人最多同时打开 3 个 Issue,这个 Issue 已自动关闭。请等已有的 Issue 处理完再提,或把内容补充到已有的 Issue 里。

Each user can have at most 3 open issues at a time, so this one was closed automatically. Please wait until your existing issues are resolved, or add this to one of them.

github-actions[bot] avatar Nov 22 '26 15:11 github-actions[bot]