systemprompt_agent/models/
external_integrations.rs1use serde::{Deserialize, Serialize};
2use systemprompt_identifiers::{AgentId, McpServerId};
3use systemprompt_models::ai::tools::McpTool;
4use thiserror::Error;
5
6#[derive(Error, Debug)]
7pub enum IntegrationError {
8 #[error("OAuth error: {0}")]
9 OAuth(String),
10 #[error("MCP error: {0}")]
11 Mcp(String),
12 #[error("Webhook error: {0}")]
13 Webhook(String),
14 #[error("Repository error: {0}")]
15 Repository(#[from] crate::repository::RepositoryError),
16 #[error("Serialization error: {0}")]
17 Serialization(#[from] serde_json::Error),
18 #[error("HTTP error: {0}")]
19 Http(#[from] reqwest::Error),
20 #[error("OAuth2 error: {0}")]
21 OAuth2(String),
22 #[error("Invalid token")]
23 InvalidToken,
24 #[error("Token expired")]
25 TokenExpired,
26 #[error("Server not found: {0}")]
27 ServerNotFound(String),
28 #[error("Tool not found: {0}")]
29 ToolNotFound(String),
30 #[error("Invalid signature")]
31 InvalidSignature,
32}
33
34pub type IntegrationResult<T> = Result<T, IntegrationError>;
35
36#[derive(Debug, Clone, Serialize, Deserialize)]
37pub struct TokenInfo {
38 pub access_token: String,
39 pub token_type: String,
40 pub expires_in: Option<u64>,
41 pub refresh_token: Option<String>,
42 pub scopes: Vec<String>,
43 pub created_at: chrono::DateTime<chrono::Utc>,
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
47pub struct AuthorizationRequest {
48 pub authorization_url: String,
49 pub state: String,
50 pub expires_at: chrono::DateTime<chrono::Utc>,
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
54pub struct AuthorizationResult {
55 pub agent_id: AgentId,
56 pub provider: String,
57 pub success: bool,
58 pub tokens: Option<TokenInfo>,
59 pub error: Option<String>,
60}
61
62#[derive(Debug, Clone, Serialize, Deserialize)]
63pub struct CallbackParams {
64 pub code: Option<String>,
65 pub state: String,
66 pub error: Option<String>,
67 pub error_description: Option<String>,
68}
69
70#[derive(Debug, Clone, Serialize, Deserialize)]
71pub struct RegisteredMcpServer {
72 pub id: McpServerId,
73 pub name: String,
74 pub url: String,
75 pub status: String,
76 pub capabilities: Vec<String>,
77 pub tools: Vec<McpTool>,
78 pub discovered_at: chrono::DateTime<chrono::Utc>,
79 pub last_seen: chrono::DateTime<chrono::Utc>,
80}
81
82#[derive(Debug, Clone, Serialize, Deserialize)]
83pub struct ToolExecutionResult {
84 pub tool_name: String,
85 pub server_id: McpServerId,
86 pub result: serde_json::Value,
87 pub execution_time_ms: u64,
88 pub metadata: Option<serde_json::Value>,
89}
90
91#[derive(Debug, Clone, Serialize, Deserialize)]
92pub struct WebhookEndpoint {
93 pub id: String,
94 pub url: String,
95 pub events: Vec<String>,
96 pub secret: Option<String>,
97 pub headers: std::collections::HashMap<String, String>,
98 pub active: bool,
99}
100
101#[derive(Debug, Clone, Serialize, Deserialize)]
102pub struct WebhookRequest {
103 pub headers: std::collections::HashMap<String, String>,
104 pub body: serde_json::Value,
105 pub signature: Option<String>,
106}
107
108#[derive(Debug, Clone, Serialize, Deserialize)]
109pub struct WebhookResponse {
110 pub status: u16,
111 pub body: Option<serde_json::Value>,
112}