Skip to content

[Feature]: WebChannel v8 state-machine parity, Native Lyria 3.5 CreateInteractionStream, Applet follow-up RPCs & Bidi protocol alignments #370

Backlog

Description

@giryaby-by

想要什么,用来做什么 / What you want and what for

想要什么,用来做什么 / What you want and what for

An audit of internal/aistudio/ (webchannel.go, bidi.go, assistant.go, video_frames.go, hidden_models.go, models.go) on v0.3.17 (5deae85) against 43 live AI Studio web client bundles (_b.js, kFCXGf.js, YUh4Se.js, o5OUtc.js, AgQvWc.js) revealed several concrete protocol and transport gaps that can be closed cleanly without overlapping #369, #368, #363, or #362:

WebChannel v8 Backchannel State-Machine & Framing Parity (webchannel.go): AID duplicate suppression, backchannel reconnection backoff, HTTP 400 "Unknown SID" handling, and 4096-byte forward batch chunk threshold.
Native Lyria 3 / 3.5 Music Generation via CreateInteractionStream (models.go, interaction.go, kFCXGf.js VKj/WKj): Stream HTTP protocol specification for models/lyria-3.5 and thoughtSignature handling.
Applet Agent Follow-Up RPCs (assistant.go, b.js .E0b/.D0b/.C0b, o5OUtc.js jYd): Protocol specifications for SendAgentFollowUpMessage, EditAgentFollowUpMessage, and CancelAgentFollowUpMessage.
Live Bidi Setup Protocol Alignments (bidi.go, YUh4Se.js oQc/gAi/gRc): extra_high thinking level (level 5) and Setup safetySettings wire field 5.
StreamExtractVideoFrames Wire Parameter Extensions (video_frames.go, _b.js brb): field 4 (URL source) and field 8 (GenerationConfig / mediaResolution).
Multi-Chunk Hidden Model Discovery (hidden_models.go): Scanning beyond the single prompts/new_chat chunk (AgQvWc) to discover models declared across lazy feature chunks (kFCXGf, YUh4Se).

  1. WebChannel v8 State-Machine & Framing Parity (internal/aistudio/webchannel.go)

In internal/aistudio/webchannel.go, the WebChannel v8 transport implementation exhibits several differences from the official client (AgQvWc.js@306928, 310472, 317521):

Missing AID Duplicate Frame Suppression (webchannel.go:919-923): In consumeBackchannelFrame, when the server replays or flushes buffered messages:

go
s.stateMu.Lock()
if aid > s.aid {
s.aid = aid
}
s.stateMu.Unlock()

If a backchannel reconnects and re-receives an envelope with aid <= s.aid, the events inside envelope[1] are still decoded and passed to s.emit(event). In WebChannel v8, frames with aid <= current_aid must be ignored as duplicate delivery:

go
s.stateMu.Lock()
if aid <= s.aid {
s.stateMu.Unlock()
return 0, nil
}
s.aid = aid
s.stateMu.Unlock()

Fixed 250ms Backchannel Reconnect Without Backoff (webchannel.go:814-822): When readBackchannel encounters a transient network error (bidiBackchannelNetworkError), it pauses for an unjittered, static 250 * time.Millisecond. Adding exponential backoff (e.g. 100ms up to 2s with jitter) prevents tight retry loops when a network interface transitions.

HTTP 400 "Unknown SID" Session Expiry Handling (webchannel.go:859-865): In AgQvWc.js@310472:

javascript
e == 400 && d.indexOf("Unknown SID") > 0 ? (a.fa = 3, a.H.warning("XMLHTTP Unknown SID (" + a.R + ")"))

Currently, webchannel.go treats HTTP 400 as a generic RPCError, which aborts the session. Detecting "Unknown SID" in the 400 body allows classifying the session as expired and cleanly signaling re-handshake / resumption.

Forward Batch Chunk Threshold (webchannel.go:651, 725-729): AgQvWc.js@317521 verifies total post buffer length against a 4096-byte chunk limit when queuing multiple reqX___data__ entries. Ensuring total batched URL-encoded length stays within standard proxy/gateway limits avoids mid-flight 413 or header truncation.

  1. Native Lyria 3 / 3.5 Music Generation via CreateInteractionStream (kFCXGf.js, interaction.go, models.go)

While #369 tracks the WebSocket route BidiGenerateMusic, AI Studio's web UI generates Lyria music via the HTTP RPC CreateInteractionStream (kFCXGf.js@2835418 VKj, WKj):

A. Supported Models (ZKj)
models/lyria-3.5
models/lyria-3-pro-preview
models/lyria-3-clip-preview
models/lyria-realtime-exp
B. Request Schema (VKj -> WKj, kFCXGf.js / _b.js)
Endpoint: POST /$rpc/google.internal.alkali.applications.makersuite.v1.MakerSuiteService/CreateInteractionStream
Outer _.by request envelope:
wire[0] (field 1, _.obb): true (stream)
wire[1] (field 2, _.pbb): false (note: interaction.go:172, 179 currently hardcodes int64(1) = true)
wire[3] (field 4, _.rbb): inner _.mx Interaction message
wire[4] (field 5, _.Tc(b, 5, c)): waaProof string bound to prompt content via _.fyb(b)
wire[5] (field 6, _.sbb): true
Inner _.mx Interaction message:
interaction[13] (field 14): responseModalities = [3] (3 = Audio)
interaction[17] (field 18, _.X9a): model target _.ax ([ "models/lyria-3.5" ])
interaction[26] (field 27, _.ix): .dx steps array:
User Prompt Content: [ { id: "music-prompt-text", Cb: "text", role: "user", text: prompt } ]
Thought Signature: if previous model turn had thoughtSignature (
.Ma), it is wrapped via .Ow field 3 (.u7a field 1) before the model turn step.
3. Applet Agent Follow-Up RPCs (internal/aistudio/assistant.go, _b.js, o5OUtc.js)

For Applet generation and assistant workflows (internal/aistudio/assistant.go), o5OUtc.js@1935044 (jYd) and _b.js@1893009 define follow-up interaction RPCs that are not yet exposed:

A. SendAgentFollowUpMessage (.E0b, o5OUtc.js jYd)
Endpoint: POST /$rpc/google.internal.alkali.applications.makersuite.v1.applets.AppletGenerationService/SendAgentFollowUpMessage
Request schema (
.y0b):
wire[0] (field 1): appletId (string)
wire[1] (field 2): taskId / generationId (string)
wire[2] (field 3): content (Content proto .Mv)
wire[3] (field 4, optional): artifactComments (repeated ArtifactComment)
wire[4] (field 5, optional): tuc (bool / int64)
wire[5] (field 6, optional): followUpMessageId (string)
Note: verified in o5OUtc.js jYd line 54, SendAgentFollowUpMessage is invoked directly as a standard gRPC-Web unary call without WAA proof (
.Zy(h.F, h.H + ".../SendAgentFollowUpMessage", g, {}, .E0b)).
B. EditAgentFollowUpMessage (
.D0b, .w0b)
Endpoint: POST /$rpc/google.internal.alkali.applications.makersuite.v1.applets.AppletGenerationService/EditAgentFollowUpMessage
Verified request accessors in b.js@1892737 (.w0b):
wire[1] (field 2, nj()): message / generation ID (string)
wire[3] (field 4, qc() / Cd()): updated Content proto (
.Mv)
C. CancelAgentFollowUpMessage (_.C0b, .u0b)
Endpoint: POST /$rpc/google.internal.alkali.applications.makersuite.v1.applets.AppletGenerationService/CancelAgentFollowUpMessage
Request schema (
.u0b):
wire[1] (field 2, nj()): message / task ID
4. Live Bidi Setup Protocol Alignments (internal/aistudio/bidi.go)

extra_high Thinking Level in Bidi (bidi.go:56): internal/aistudio/bidi.go:56 maps:

go
var bidiThinkingLevels = map[string]int64{"low": 1, "medium": 2, "high": 3, "minimal": 4}

In YUh4Se.js@246269 (oQc) and gAi:

javascript
oQc = function(a) { switch(a) { case 4: return 1; case 1: return 2; case 2: return 3; case 3: return 4; case 5: return 5 } };
gAi = function(a) { switch(a) { case 4: return "MINIMAL"; case 1: return "LOW"; case 2: return "MEDIUM"; case 3: return "HIGH"; case 5: return "XHIGH" } };

extra_high (code 5, API string "EXTRA_HIGH" / "XHIGH") is supported in web client and buildThinkingLevels[5], but omitted from bidiThinkingLevels. Fix: Add "extra_high": 5 to bidiThinkingLevels.

Bidi Setup safetySettings Wire Field 5 (bidi.go:EncodeBidiSetupRequest): In YUh4Se.js@251744 (gRc):

javascript
b.safetySettings.length > 0 && _.on(e, 5, _.hn, b.safetySettings);

In Live Bidi Setup, field 5 encodes safetySettings (repeated SafetySetting). Currently EncodeBidiSetupRequest does not encode safety settings onto setup. Fix: When request.SafetySettings is provided, encode via existing encodeSafetySettings and set setup[4].

  1. StreamExtractVideoFrames Wire Parameter Extensions (internal/aistudio/video_frames.go)

In video_frames.go:24-35:

go
func encodeVideoFramesRequest(request VideoFramesRequest) ([]byte, error) {
wire := []any{wireModelName(request.Model), nil, []any{request.FileID}}
...

Comparing with _b.js@846336, 1301401-1301891 (brb, NHb, OHb, QHb):

field 4 (wire[3], oneof $qb = [2, 3, 4]): non-Drive source video URI/URL string (_.Ln(c, 4, $qb, b)).
field 8 (wire[7]): .Il (GenerationConfig) message (.Rc(b, _.Il, 8, e)), which carries mediaResolution at nested field 18 via _.Hxa (low=1, medium=2, high=3). Adding these fields to VideoFramesRequest allows extracting video frame tokens directly from external URLs with configurable resolution.
6. Multi-Chunk Hidden Model Discovery (internal/aistudio/hidden_models.go)

In internal/aistudio/hidden_models.go:40-46, 204-212, frontendChatModulePattern only resolves the single lazy chunk for path: "prompts/new_chat" (AgQvWc, which is also shared with prompts/new_image).

Across 43 live gstatic bundles in production AI Studio, additional model families and music/live blocks are partitioned into separate lazy route chunks (_b.js@1504322):

kFCXGf.js (loaded by path: "new_music"): holds {id:"lyria-music", type:"music"} and models/lyria-3.5 / lyria-3-pro-preview / lyria-3-clip-preview.
YUh4Se.js (Live chunk): holds {id:"gemini-live", type:"live"} and models/gemini-3.8-live / models/gemini-3.8-live-extended-thinking / models/gemini-4-live (as well as models/gemini-4-argon, models/gemini-4-hydrogen, models/gemini-4-neon, etc.).

Suggested fix: In frontendModels, inspect the chunk route map in _b.js to discover and fetch additional feature chunks (such as new_music -> kFCXGf and the Live module chunk YUh4Se) alongside prompts/new_chat, allowing DiscoverHiddenModels to locate all unlisted experimental models automatically.

版本 / Version

v0.3.17 (5deae85)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions