Skip to main content

Module translate

Module translate 

Source
Expand description

Translation between the runtime’s generic chat/tool shape and the Gemini Code Assist streamGenerateContent wire format (Vertex-style contents + function calls). Also decodes the SSE line format used by cloudcode-pa.googleapis.com when called with ?alt=sse.

Structs§

GeminiContent
GeminiFunctionCall
GeminiFunctionResponse
GeminiGenerateRequest
Envelope matching the Code Assist streamGenerateContent request shape: { model, project?, user_prompt_id?, request: VertexGenerateContentRequest }.
GeminiGenerateRequestInner
GeminiRole
GeminiSystemInstruction
GeminiTool
GeminiToolFunctionDeclaration
GeminiUsage
Provider-reported usage decoded from a stream chunk’s usageMetadata. Every field is optional: absent upstream counts stay absent.
ToolSpec

Enums§

ChatTurn
Minimal, generic input shape callers assemble before calling the translator. Kept intentionally small: text / tool-call / tool-response only. Media payloads are unsupported in this experimental slice.
GeminiPart
GeminiRoleName
GeminiStreamEvent
A decoded, runtime-facing event from the Gemini stream. Text fragments and tool calls are surfaced separately so the runtime can route them without re-parsing the vendor shape.

Constants§

MAX_INBOUND_LINE_BYTES
Maximum bytes we will buffer for a single SSE line before failing closed. Google’s Code Assist emits reasonably small JSON chunks; refusing anything bigger prevents a hostile upstream from ballooning memory.

Functions§

from_stream_line
Decode one inbound SSE data: line into runtime events. Empty/comment lines yield an empty vec; data: [DONE] yields Finish { reason: None }. Malformed JSON is surfaced as an Err so the caller can decide whether to terminate the stream (spec: fail closed on structurally invalid frames).
translate_generate_content_request
Translate a normalized conversation + tool set into a GeminiGenerateRequest ready for /v1internal:streamGenerateContent.