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