objectiveai_cli/command/viewer/
spawn.rs1use objectiveai_sdk::cli::command::viewer::spawn::{Request, Response};
10
11use crate::context::Context;
12use crate::error::Error;
13
14pub async fn spawn(ctx: &Context) -> Result<String, Error> {
19 let mut config = ctx
20 .filesystem
21 .read_config_view(objectiveai_sdk::cli::command::GetScope::Final)
22 .await?;
23 let secret = config.viewer().get_secret().map(String::from);
24
25 let bin = if cfg!(windows) {
26 "objectiveai-viewer.exe"
27 } else {
28 "objectiveai-viewer"
29 };
30 let exe = ctx.filesystem.bin_dir().join(bin);
31 let lock_dir = ctx.filesystem.state_dir().join("locks");
32
33 crate::spawn::spawn_until_lock_published(&exe, &lock_dir, "viewer", |cmd| {
44 cmd.env_remove("ADDRESS");
45 cmd.env_remove("PORT");
46 cmd.env_remove("VIEWER_SECRET");
47 cmd.env("OBJECTIVEAI_DIR", ctx.filesystem.dir())
48 .env("OBJECTIVEAI_STATE", ctx.filesystem.state())
49 .env("SUPPRESS_OUTPUT", "true");
50 if let Some(secret) = secret {
51 cmd.env("VIEWER_SECRET", secret);
52 }
53 })
54 .await
55}
56
57pub async fn execute(ctx: &Context, _request: Request) -> Result<Response, Error> {
58 Ok(Response {
59 listening: spawn(ctx).await?,
60 })
61}
62
63pub mod request_schema {
64 use objectiveai_sdk::cli::command::viewer::spawn as sdk;
65 use objectiveai_sdk::cli::command::viewer::spawn::request_schema::{Request, Response};
66
67 use crate::context::Context;
68 use crate::error::Error;
69
70 pub async fn execute(_ctx: &Context, _request: Request) -> Result<Response, Error> {
71 Ok(objectiveai_sdk::cli::command::ResponseSchema(schemars::schema_for!(sdk::Request)))
72 }
73}
74
75pub mod response_schema {
76 use objectiveai_sdk::cli::command::viewer::spawn as sdk;
77 use objectiveai_sdk::cli::command::viewer::spawn::response_schema::{Request, Response};
78
79 use crate::context::Context;
80 use crate::error::Error;
81
82 pub async fn execute(_ctx: &Context, _request: Request) -> Result<Response, Error> {
83 Ok(objectiveai_sdk::cli::command::ResponseSchema(schemars::schema_for!(sdk::Response)))
84 }
85}