opencode_sdk/http/
files.rs1use crate::error::Result;
6use crate::http::HttpClient;
7use crate::types::file::{FileContent, FileInfo, FileStatus};
8use reqwest::Method;
9
10#[derive(Clone)]
12pub struct FilesApi {
13 http: HttpClient,
14}
15
16impl FilesApi {
17 pub fn new(http: HttpClient) -> Self {
19 Self { http }
20 }
21
22 pub async fn list(&self) -> Result<Vec<FileInfo>> {
28 self.http.request_json(Method::GET, "/file", None).await
29 }
30
31 pub async fn read(&self, path: &str) -> Result<FileContent> {
37 let encoded = urlencoding::encode(path);
38 self.http
39 .request_json(
40 Method::GET,
41 &format!("/file/content?path={}", encoded),
42 None,
43 )
44 .await
45 }
46
47 pub async fn status(&self) -> Result<Vec<FileStatus>> {
53 self.http
54 .request_json(Method::GET, "/file/status", None)
55 .await
56 }
57}