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