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