Skip to main content

artifactize_core/
inspect.rs

1//! Shared non-interactive JSON projections. Interfaces add rendering and paging only.
2mod logs;
3pub mod session;
4pub use logs::{LogQuery, Stream, logs};
5
6use crate::{config::read_workspace_config, types::RequestId};
7use serde::Serialize;
8use serde_json::{Value, json};
9use std::path::Path;
10
11#[derive(Debug, Serialize)]
12pub struct ConfigCheck {
13    pub ok: bool,
14    pub artifacts: usize,
15    pub evals: usize,
16}
17pub fn config_check(repo: &Path) -> Result<ConfigCheck, String> {
18    let config = read_workspace_config(repo).map_err(|error| error.to_string())?;
19    Ok(ConfigCheck {
20        ok: true,
21        artifacts: config.artifacts.len(),
22        evals: config.evals.len(),
23    })
24}
25
26pub async fn request_show(
27    state: &Path,
28    id: &RequestId,
29    now: time::OffsetDateTime,
30) -> Result<Value, String> {
31    Ok(crate::query::request_output(
32        &crate::store::read_request(state, id).await?,
33        now,
34    ))
35}
36
37pub async fn request_list(
38    state: &Path,
39    run: Option<&crate::types::RunId>,
40    repo: Option<&Path>,
41    now: time::OffsetDateTime,
42) -> Result<Vec<Value>, String> {
43    let views =
44        crate::store::read_requests_in(state, run.map(crate::types::RunId::as_str), repo).await?;
45    Ok(views
46        .iter()
47        .map(|view| crate::query::request_output(view, now))
48        .collect())
49}
50
51pub async fn remote_status(state: Option<&Path>, repo: Option<&Path>) -> Result<Value, String> {
52    Ok(remote_output(
53        crate::auth::remote::status(state, repo).await?.as_ref(),
54    ))
55}
56
57pub fn remote_output(status: Option<&crate::auth::remote::Status>) -> Value {
58    match status {
59        Some(status) => {
60            let mut value = json!(status);
61            value["configured"] = json!(true);
62            value
63        }
64        None => json!({"configured": false}),
65    }
66}
67
68pub async fn session_show(state: &Path, reference: &str, summary: bool) -> Result<Value, String> {
69    session::show(state, reference, summary).await
70}