mod logs;
pub mod session;
pub use logs::{DEFAULT_TAIL as DEFAULT_LOG_TAIL_LINES, LogOptions, LogQuery, Stream, logs};
use crate::{config::read_workspace_config, types::RequestId};
use serde::Serialize;
use serde_json::{Value, json};
use std::path::Path;
#[derive(Debug, Serialize)]
pub struct ConfigCheck {
pub ok: bool,
pub artifacts: usize,
pub evals: usize,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub notes: Vec<String>,
}
pub fn config_check(repo: &Path) -> Result<ConfigCheck, String> {
let config = read_workspace_config(repo).map_err(|error| error.to_string())?;
Ok(ConfigCheck {
notes: config
.artifacts
.values()
.filter_map(|artifact| {
crate::scope::validate_file_target(&config.root, artifact)
.err()
.map(|error| error.to_string())
})
.collect(),
ok: true,
artifacts: config.artifacts.len(),
evals: config.evals.len(),
})
}
pub async fn request_show(
state: &Path,
id: &RequestId,
now: time::OffsetDateTime,
) -> Result<Value, String> {
Ok(crate::query::request_output(
&crate::store::read_request(state, id).await?,
now,
))
}
pub async fn request_list(
state: &Path,
run: Option<&crate::types::RunId>,
repo: Option<&Path>,
now: time::OffsetDateTime,
) -> Result<Vec<Value>, String> {
let views = crate::store::read_requests_for_run(state, run.cloned(), repo).await?;
Ok(views
.iter()
.map(|view| crate::query::request_output(view, now))
.collect())
}
pub async fn remote_status(state: Option<&Path>, repo: Option<&Path>) -> Result<Value, String> {
Ok(remote_output(
crate::auth::remote::status(state, repo).await?.as_ref(),
))
}
pub fn remote_output(status: Option<&crate::auth::remote::Status>) -> Value {
match status {
Some(status) => {
let mut value = json!(status);
value["configured"] = json!(true);
value
}
None => json!({"configured": false}),
}
}
pub async fn session_show(
state: &Path,
selector: &session::Selector,
summary: bool,
) -> Result<session::Shown, String> {
session::show(state, selector, summary).await
}