1use std::path::PathBuf;
2
3use std::collections::BTreeMap;
4
5use serde::{Deserialize, Serialize};
6use serde_json::Value;
7
8use crate::client_gen::generator::GeneratorConfig;
9use crate::compression::engine::Tool;
10use crate::server::{BackendServerConfig, JustBashCommandSpec, JustBashProviderSpec};
11
12#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
13pub struct FfiTool {
14 pub name: String,
15 pub description: Option<String>,
16 pub input_schema: Value,
17}
18
19#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
20pub struct FfiMcpServer {
21 pub name: String,
22 pub command: String,
23 pub args: Vec<String>,
24 pub env: Vec<(String, String)>,
25 pub cli_prefix: String,
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
29pub struct FfiJustBashProviderSpec {
30 pub provider_name: String,
31 pub help_tool_name: String,
32 pub tools: Vec<FfiJustBashCommandSpec>,
33}
34
35#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
36pub struct FfiJustBashCommandSpec {
37 pub command_name: String,
38 pub backend_tool_name: String,
39 pub description: Option<String>,
40 pub input_schema: Value,
41 pub invoke_tool_name: String,
42}
43
44#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
45pub struct FfiBackendTool {
46 pub server_name: String,
47 pub tool: FfiTool,
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
51pub struct FfiGeneratorConfig {
52 pub cli_name: String,
53 pub bridge_url: String,
54 pub token: String,
55 pub tools: Vec<FfiTool>,
56 pub session_pid: u32,
57 pub output_dir: PathBuf,
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
61pub struct FfiBackendConfig {
62 pub name: String,
63 pub command_or_url: String,
64 #[serde(default)]
65 pub args: Vec<String>,
66 pub oauth_app_name: Option<String>,
67}
68
69#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
70#[serde(untagged)]
71pub enum FfiSdkServerConfig {
72 CommandOrUrl(String),
73 Structured {
74 command: Option<String>,
75 url: Option<String>,
76 #[serde(default)]
77 args: Vec<String>,
78 #[serde(default)]
79 headers: BTreeMap<String, String>,
80 #[serde(default, alias = "oauthAppName")]
81 oauth_app_name: Option<String>,
82 },
83}
84
85pub type FfiSdkServersConfig = BTreeMap<String, FfiSdkServerConfig>;
86
87#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
88pub struct FfiCompressedSessionConfig {
89 pub compression_level: String,
90 pub server_name: Option<String>,
91 #[serde(default)]
92 pub include_tools: Vec<String>,
93 #[serde(default)]
94 pub exclude_tools: Vec<String>,
95 #[serde(default)]
96 pub toonify: bool,
97 pub transform_mode: Option<String>,
98}
99
100#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
101pub struct FfiCompressedSessionInfo {
102 pub bridge_url: String,
103 pub token: String,
104 pub frontend_tools: Vec<FfiTool>,
105 pub backend_tools: Vec<FfiTool>,
106 pub backend_tools_by_server: Vec<FfiBackendTool>,
107 pub just_bash_providers: Vec<FfiJustBashProviderSpec>,
108}
109
110impl From<FfiBackendConfig> for BackendServerConfig {
111 fn from(value: FfiBackendConfig) -> Self {
112 let mut backend = BackendServerConfig::new(value.name, value.command_or_url, value.args);
113 if let Some(app_name) = value.oauth_app_name {
114 backend = backend.with_oauth_app_name(app_name);
115 }
116 backend
117 }
118}
119
120impl From<FfiGeneratorConfig> for GeneratorConfig {
121 fn from(value: FfiGeneratorConfig) -> Self {
122 Self {
123 cli_name: value.cli_name,
124 bridge_url: value.bridge_url,
125 token: value.token,
126 tools: value.tools.into_iter().map(Into::into).collect(),
127 session_pid: value.session_pid,
128 output_dir: value.output_dir,
129 extra_cli_bridges: Vec::new(),
130 }
131 }
132}
133
134impl From<FfiTool> for Tool {
135 fn from(value: FfiTool) -> Self {
136 Tool::new(value.name, value.description, value.input_schema)
137 }
138}
139
140impl From<Tool> for FfiTool {
141 fn from(value: Tool) -> Self {
142 Self {
143 name: value.name,
144 description: value.description,
145 input_schema: value.input_schema,
146 }
147 }
148}
149
150impl From<JustBashProviderSpec> for FfiJustBashProviderSpec {
151 fn from(value: JustBashProviderSpec) -> Self {
152 Self {
153 provider_name: value.provider_name,
154 help_tool_name: value.help_tool_name,
155 tools: value.tools.into_iter().map(Into::into).collect(),
156 }
157 }
158}
159
160impl From<JustBashCommandSpec> for FfiJustBashCommandSpec {
161 fn from(value: JustBashCommandSpec) -> Self {
162 Self {
163 command_name: value.command_name,
164 backend_tool_name: value.backend_tool_name,
165 description: value.description,
166 input_schema: value.input_schema,
167 invoke_tool_name: value.invoke_tool_name,
168 }
169 }
170}