systemprompt-client
HTTP client library for communicating with the SystemPrompt API server.
Overview
This crate provides a type-safe, async HTTP client for interacting with the SystemPrompt API. It serves as the primary interface for external applications (TUI, CLI tools, third-party integrations) to communicate with the SystemPrompt server without depending on internal business logic.
Design Principles
- Decoupled Architecture: Communicates exclusively via HTTP, no direct access to repositories or services
- Type Safety: Leverages
systemprompt-identifiersfor typed IDs (ContextId,JwtToken) - Error Transparency: Structured error types with
thiserrorfor clear failure modes - Async-First: Built on
reqwestandtokiofor non-blocking I/O
File Structure
src/
├── lib.rs # Crate root - public API exports
├── client.rs # SystempromptClient struct and all API methods
├── error.rs # ClientError enum and ClientResult type alias
└── http.rs # Internal HTTP helper functions (get, post, put, delete)
Module Breakdown
lib.rs
Minimal public interface exposing only:
SystempromptClient- the main client structClientError- error enum for all failure modesClientResult<T>- type alias forResult<T, ClientError>
client.rs
The core client implementation containing:
- Construction:
new(),with_timeout(),with_token() - Token Management:
set_token(),token() - Agent Operations:
list_agents(),get_agent_card() - Context Operations:
list_contexts(),get_context(),create_context(),delete_context(),update_context_name(),fetch_or_create_context(),create_context_auto_name() - Task Operations:
list_tasks(),delete_task() - Artifact Operations:
list_artifacts(),list_all_artifacts() - Messaging:
send_message()(JSON-RPC format) - Admin Operations:
list_logs(),list_users(),get_analytics() - Health:
check_health(),verify_token()
error.rs
Comprehensive error handling with variants:
| Variant | Description |
|---|---|
HttpError |
Network/transport failures (wraps reqwest::Error) |
ApiError |
Server returned non-2xx response with status and body |
JsonError |
Response body failed to deserialize |
AuthError |
Authentication/authorization failures |
NotFound |
Requested resource does not exist |
Timeout |
Request exceeded time limit |
ServerUnavailable |
Server unreachable |
ConfigError |
Invalid client configuration |
Other |
Catch-all for unexpected errors |
Includes is_retryable() helper for retry logic.
http.rs
Internal module providing low-level HTTP operations:
get<T>()- GET request with optional auth, returns deserialized responsepost<T, B>()- POST with JSON body, returns deserialized responseput<B>()- PUT with JSON body, returns unitdelete()- DELETE request, returns unit
All functions handle authorization headers and error response parsing uniformly.
Usage
use ;
use JwtToken;
async
API Operations
| Category | Methods |
|---|---|
| Agents | list_agents, get_agent_card |
| Contexts | list_contexts, get_context, create_context, create_context_auto_name, fetch_or_create_context, update_context_name, delete_context |
| Tasks | list_tasks, delete_task |
| Artifacts | list_artifacts, list_all_artifacts |
| Messages | send_message |
| Admin | list_logs, list_users, get_analytics |
| Health | check_health, verify_token |
Error Handling
All fallible operations return ClientResult<T>. Pattern match on ClientError for specific handling:
use ;
async
Dependencies
| Crate | Purpose |
|---|---|
reqwest |
HTTP client with async support |
tokio |
Async runtime |
serde / serde_json |
JSON serialization |
chrono |
DateTime handling for auto-naming |
thiserror |
Derive macro for error types |
anyhow |
Error wrapping for Other variant |
tracing |
Structured logging for error diagnostics |
systemprompt-models |
Shared API types (AgentCard, Task, etc.) |
systemprompt-identifiers |
Typed identifiers (ContextId, JwtToken) |
Configuration
Timeout
Default timeout is 30 seconds. Custom timeout:
let client = with_timeout?;
Authentication
Token can be set at construction or later:
// At construction (builder pattern)
let client = new?.with_token;
// After construction (mutation)
let mut client = new?;
client.set_token;
License
See workspace Cargo.toml for license information.