Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
198 changes: 198 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ serde_json = "1.0.117"
schemars = "1.2.1"

thiserror = "2.0.18"

jsonwebtoken = "9.3.1"

[dev-dependencies]
serial_test = "3.4.0"
Comment thread
seun-ja marked this conversation as resolved.
7 changes: 2 additions & 5 deletions src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,7 @@ impl AgentWorker for AgentServer {
_context: ::tarpc::context::Context,
user_message: Message,
) -> Result<String, ApiError> {
println!("Message received");
self.providers
.chat(&user_message.to_string())
.await
.map_err(ApiError::from)
let prompt: String = user_message.try_into()?;
self.providers.chat(&prompt).await.map_err(ApiError::from)
}
}
48 changes: 23 additions & 25 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,26 @@ pub enum Error {
/// RPC error: a remote procedure call error occurred.
#[error("rpc error: {0}")]
RpcError(#[from] tarpc::client::RpcError),
/// Invalid JWT credentials: the JWT token is invalid or expired.
#[error("invalid jwt credentials: {0}")]
InvalidJWTCredentials(#[from] jsonwebtoken::errors::Error),
/// No JWT secret found: the JWT secret is not configured.
#[error("no jwt secret found")]
NoJWTSecretFound,
}

impl Error {
fn status(&self) -> u16 {
match self {
Error::AuthenticationError(_) | Error::InvalidJWTCredentials(_) => 401,
Error::HttpError(_)
| Error::Io(_)
| Error::PromptError(_)
| Error::RpcError(_)
| Error::ProviderError(_)
| Error::NoJWTSecretFound => 500,
}
}
}

/// API error type used for provider-specific error responses.
Expand All @@ -41,31 +61,9 @@ impl Display for ApiError {

impl From<Error> for ApiError {
fn from(value: Error) -> Self {
match value {
Error::ProviderError(e) => ApiError {
status: 500,
message: e,
},
Error::HttpError(error) => ApiError {
status: 500,
message: error.to_string(),
},
Error::PromptError(prompt_error) => ApiError {
status: 500,
message: prompt_error.to_string(),
},
Error::Io(error) => ApiError {
status: 500,
message: error.to_string(),
},
Error::AuthenticationError(e) => ApiError {
status: 401,
message: e,
},
Error::RpcError(server_error) => ApiError {
status: 500,
message: server_error.to_string(),
},
Self {
status: value.status(),
message: value.to_string(),
}
}
}
Expand Down
Loading
Loading