Skip to main content

objectiveai_cli/command/viewer/
send.rs

1//! `viewer send <path> <body>` — POST a JSON body to the viewer's HTTP
2//! server and return its `(status, body)`. Bypasses the SDK's
3//! fire-and-forget viewer client because callers want to see the
4//! response synchronously.
5//!
6//! Address/signature resolution lives in `Context::viewer_client()`
7//! (config `viewer.address`, else the `viewer spawn` flow's published
8//! lock URL; signature env `VIEWER_SIGNATURE`, else
9//! `viewer.signature`). Non-2xx status codes are not an error; the
10//! response is returned as-is with the status set on the `Response`.
11
12use objectiveai_sdk::cli::command::viewer::send::{Request, Response};
13
14use crate::context::Context;
15use crate::error::Error;
16
17pub async fn execute(ctx: &Context, request: Request) -> Result<Response, Error> {
18    let Request { path, body, .. } = request;
19    let (status, body) = ctx.viewer_client().await?.send(&path, &body).await?;
20    Ok(Response { status, body })
21}
22
23pub mod request_schema {
24    use objectiveai_sdk::cli::command::viewer::send as sdk;
25    use objectiveai_sdk::cli::command::viewer::send::request_schema::{Request, Response};
26
27    use crate::context::Context;
28    use crate::error::Error;
29
30    pub async fn execute(_ctx: &Context, _request: Request) -> Result<Response, Error> {
31        Ok(objectiveai_sdk::cli::command::ResponseSchema(schemars::schema_for!(sdk::Request)))
32    }
33}
34
35pub mod response_schema {
36    use objectiveai_sdk::cli::command::viewer::send as sdk;
37    use objectiveai_sdk::cli::command::viewer::send::response_schema::{Request, Response};
38
39    use crate::context::Context;
40    use crate::error::Error;
41
42    pub async fn execute(_ctx: &Context, _request: Request) -> Result<Response, Error> {
43        Ok(objectiveai_sdk::cli::command::ResponseSchema(schemars::schema_for!(sdk::Response)))
44    }
45}