mod envelope;
use crate::canonical::{CanonicalError, CanonicalRequest, Event};
use crate::protocol::google_genai::decode::{decode_frame, decode_full_with};
use crate::protocol::{
Collection, DecodeState, Frame, Framing, Method, ModelKeys, ModelsShape, Protocol, ProviderCtx,
Shapes, Tuning, WireRequest,
};
pub struct GoogleCloudCode;
impl Protocol for GoogleCloudCode {
fn encode(
&self,
req: &CanonicalRequest,
ctx: &ProviderCtx,
) -> Result<WireRequest, CanonicalError> {
envelope::encode(req, ctx)
}
fn path(&self, _ctx: &ProviderCtx) -> String {
envelope::request_path(true).to_owned()
}
fn content_type(&self) -> &str {
"application/json"
}
fn decode(&self, frame: Frame, state: &mut DecodeState) -> Result<Vec<Event>, CanonicalError> {
decode_frame(frame, state, envelope::unwrap)
}
fn decode_full(
&self,
body: &[u8],
state: &mut DecodeState,
) -> Result<Vec<Event>, CanonicalError> {
decode_full_with(body, state, envelope::unwrap)
}
fn framing(&self) -> Framing {
Framing::Sse
}
fn tuning(&self) -> Tuning {
Tuning {
effort: true,
budget: true,
priority: false,
image: true,
}
}
fn shapes(&self) -> Shapes {
Shapes {
tools: true,
multi_turn: true,
}
}
fn models_shape(&self) -> Option<ModelsShape> {
Some(ModelsShape {
method: Method::Post,
path: "/v1internal:fetchAvailableModels",
keys: ModelKeys {
collection: Collection::Map { key: "models" },
strip: "",
context_key: "maxTokens",
max_output_key: "maxOutputTokens",
display_name_key: "displayName",
default_key: "defaultAgentModelId",
},
})
}
}