Skip to main content

cc_lb_plugin_wire/v2/
shape.rs

1//! v2 is a fork of v1 to allow additive cache-related fields. v1 is FROZEN.
2
3extern crate alloc;
4
5use alloc::{string::String, vec::Vec};
6use serde::{Deserialize, Serialize};
7
8use crate::v2::common::{HeaderWire, Principal, RequestWire, UpstreamWire};
9use crate::wire_function::{FallbackPolicy, WireFunction};
10
11#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
12#[serde(deny_unknown_fields)]
13pub struct ShapeRequest {
14    pub request: RequestWire,
15    pub upstream: UpstreamWire,
16    pub principal: Principal,
17    #[serde(default, skip_serializing_if = "Option::is_none")]
18    pub upstream_base_url: Option<String>,
19}
20
21impl ShapeRequest {
22    pub fn dry_run_sample() -> Self {
23        Self {
24            request: RequestWire::dry_run_sample(),
25            upstream: UpstreamWire::dry_run_sample(),
26            principal: Principal::dry_run_sample(),
27            upstream_base_url: None,
28        }
29    }
30}
31
32#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
33#[serde(deny_unknown_fields)]
34pub struct ShapeResponse {
35    pub url: String,
36    pub method: String,
37    pub headers: Vec<HeaderWire>,
38    pub body_base64: String,
39}
40
41impl ShapeResponse {
42    pub fn dry_run_sample() -> Self {
43        Self {
44            url: String::from("https://api.anthropic.com/v1/messages"),
45            method: String::from("POST"),
46            headers: Vec::new(),
47            body_base64: String::new(),
48        }
49    }
50}
51
52pub struct ShapeFn;
53
54impl WireFunction for ShapeFn {
55    const NAME: &'static str = "shape";
56    const FALLBACK: FallbackPolicy = FallbackPolicy::FailRequest;
57    const SUPPORTED_VERSIONS: &'static [u32] = &[1];
58
59    type Request = ShapeRequest;
60    type Response = ShapeResponse;
61
62    fn dry_run_request() -> Self::Request {
63        ShapeRequest::dry_run_sample()
64    }
65
66    fn dry_run_response() -> Self::Response {
67        ShapeResponse::dry_run_sample()
68    }
69}