1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//! Memory blocks API endpoints.
use crate::client::LettaClient;
use crate::error::LettaResult;
use crate::types::{Block, CreateBlockRequest, LettaId, ListBlocksParams, UpdateBlockRequest};
/// Memory blocks API operations.
#[derive(Debug)]
pub struct BlocksApi<'a> {
client: &'a LettaClient,
}
impl<'a> BlocksApi<'a> {
/// Create a new blocks API instance.
pub fn new(client: &'a LettaClient) -> Self {
Self { client }
}
/// List all memory blocks.
///
/// # Arguments
///
/// * `params` - Optional parameters for filtering the list
///
/// # Errors
///
/// Returns a [crate::error::LettaError] if the request fails or if the response cannot be parsed.
pub async fn list(&self, params: Option<ListBlocksParams>) -> LettaResult<Vec<Block>> {
self.client
.get_with_query("v1/blocks/", ¶ms.unwrap_or_default())
.await
}
/// Create a new memory block.
///
/// # Arguments
///
/// * `request` - The block creation request
///
/// # Errors
///
/// Returns a [crate::error::LettaError] if the request fails or if the response cannot be parsed.
pub async fn create(&self, request: CreateBlockRequest) -> LettaResult<Block> {
self.client.post("v1/blocks/", &request).await
}
/// Get a specific memory block by ID.
///
/// # Arguments
///
/// * `block_id` - The ID of the block to retrieve
///
/// # Errors
///
/// Returns a [crate::error::LettaError] if the request fails or if the response cannot be parsed.
pub async fn get(&self, block_id: &LettaId) -> LettaResult<Block> {
self.client.get(&format!("v1/blocks/{}", block_id)).await
}
/// Update a memory block.
///
/// # Arguments
///
/// * `block_id` - The ID of the block to update
/// * `request` - The update request
///
/// # Errors
///
/// Returns a [crate::error::LettaError] if the request fails or if the response cannot be parsed.
pub async fn update(
&self,
block_id: &LettaId,
request: UpdateBlockRequest,
) -> LettaResult<Block> {
self.client
.patch(&format!("v1/blocks/{}", block_id), &request)
.await
}
/// Delete a memory block.
///
/// # Arguments
///
/// * `block_id` - The ID of the block to delete
///
/// # Errors
///
/// Returns a [crate::error::LettaError] if the request fails.
pub async fn delete(&self, block_id: &LettaId) -> LettaResult<()> {
self.client
.delete_no_response(&format!("v1/blocks/{}", block_id))
.await
}
/// Get the count of memory blocks.
///
/// # Errors
///
/// Returns a [crate::error::LettaError] if the request fails or if the response cannot be parsed.
pub async fn count(&self) -> LettaResult<u32> {
self.client.get("v1/blocks/count").await
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::client::ClientConfig;
#[test]
fn test_blocks_api_creation() {
let config = ClientConfig::new("http://localhost:8283").unwrap();
let client = LettaClient::new(config).unwrap();
let _api = BlocksApi::new(&client);
}
}