openagent/api/
response.rs1use crate::_prelude::*;
7
8mod create;
9pub use create::*;
10
11mod event;
12pub use event::*;
13
14mod object;
15pub use object::*;
16
17mod r#type;
18pub use r#type::*;
19
20pub trait ApiResponse
22where
23 Self: ApiBase,
24{
25 fn create_response(
27 &self,
28 mut request: ResponseRequest,
29 ) -> impl Send + Future<Output = Result<ResponseObject>> {
30 async {
31 request.stream = None;
33
34 let resp = self.post_json("/responses", request).await?;
35
36 tracing::debug!("{resp}");
37
38 Ok(serde_json::from_str::<ApiResult<ResponseObject>>(&resp)?.as_result()?)
39 }
40 }
41
42 fn create_response_stream<H>(
44 &self,
45 mut request: ResponseRequest,
46 options: SseOptions<H>,
47 ) -> impl Send + Future<Output = Result<EventStream<H::Event>>>
48 where
49 H: 'static + EventHandler,
50 {
51 async move {
52 request.stream = Some(true);
54
55 self.sse("/responses", request, options).await
56 }
57 }
58}
59impl<T> ApiResponse for T where T: ApiBase {}