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