99 lines
3.1 KiB
Rust
99 lines
3.1 KiB
Rust
use std::collections::BTreeMap;
|
|
|
|
use crank_core::{ExecutionConfig, Operation, OperationId, Protocol, Target, ToolDescription};
|
|
use crank_mapping::MappingSet;
|
|
use crank_schema::Schema;
|
|
use serde::{Deserialize, Serialize};
|
|
use serde_json::Value;
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct RuntimeOperation {
|
|
pub operation_id: OperationId,
|
|
pub operation_version: u32,
|
|
pub tool_name: String,
|
|
pub protocol: Protocol,
|
|
pub target: Target,
|
|
pub input_schema: Schema,
|
|
pub output_schema: Schema,
|
|
pub input_mapping: MappingSet,
|
|
pub output_mapping: MappingSet,
|
|
pub execution_config: ExecutionConfig,
|
|
pub tool_description: ToolDescription,
|
|
}
|
|
|
|
impl From<Operation<Schema, MappingSet>> for RuntimeOperation {
|
|
fn from(value: Operation<Schema, MappingSet>) -> Self {
|
|
Self {
|
|
operation_id: value.id,
|
|
operation_version: value.version,
|
|
tool_name: value.name,
|
|
protocol: value.protocol,
|
|
target: value.target,
|
|
input_schema: value.input_schema,
|
|
output_schema: value.output_schema,
|
|
input_mapping: value.input_mapping,
|
|
output_mapping: value.output_mapping,
|
|
execution_config: value.execution_config,
|
|
tool_description: value.tool_description,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Default)]
|
|
pub struct PreparedRequest {
|
|
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
|
pub path_params: BTreeMap<String, String>,
|
|
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
|
pub query_params: BTreeMap<String, String>,
|
|
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
|
pub headers: BTreeMap<String, String>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub body: Option<serde_json::Value>,
|
|
#[serde(default)]
|
|
pub timeout_ms: u64,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct AdapterResponse {
|
|
pub status_code: u16,
|
|
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
|
pub headers: BTreeMap<String, String>,
|
|
pub body: Value,
|
|
pub data: Value,
|
|
}
|
|
|
|
impl From<PreparedRequest> for crank_core::PreparedRequest {
|
|
fn from(value: PreparedRequest) -> Self {
|
|
Self {
|
|
path_params: value.path_params,
|
|
query_params: value.query_params,
|
|
headers: value.headers,
|
|
body: value.body,
|
|
timeout_ms: value.timeout_ms,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<crank_core::PreparedRequest> for PreparedRequest {
|
|
fn from(value: crank_core::PreparedRequest) -> Self {
|
|
Self {
|
|
path_params: value.path_params,
|
|
query_params: value.query_params,
|
|
headers: value.headers,
|
|
body: value.body,
|
|
timeout_ms: value.timeout_ms,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<crank_core::AdapterResponse> for AdapterResponse {
|
|
fn from(value: crank_core::AdapterResponse) -> Self {
|
|
Self {
|
|
status_code: value.status_code,
|
|
headers: value.headers,
|
|
body: value.body,
|
|
data: value.data,
|
|
}
|
|
}
|
|
}
|