artifactize_core/
inspect.rs1pub(crate) mod logs;
3pub mod session;
4pub use crate::store::{Issue, Request, RequestView};
5pub use logs::{DEFAULT_TAIL as DEFAULT_LOG_TAIL_LINES, LogOptions, LogQuery, Stream, logs};
6
7use crate::{config::read_workspace_config, types::RequestId};
8use serde::Serialize;
9use serde_json::{Value, json};
10use std::path::Path;
11
12#[derive(Debug, Serialize)]
13pub struct ConfigCheck {
14 pub ok: bool,
15 pub artifacts: usize,
16 pub evals: usize,
17 #[serde(skip_serializing_if = "Vec::is_empty")]
18 pub notes: Vec<String>,
19}
20pub fn config_check(repo: &Path) -> Result<ConfigCheck, String> {
21 let config = read_workspace_config(repo).map_err(|error| error.to_string())?;
22 Ok(ConfigCheck {
23 notes: config
24 .artifacts
25 .values()
26 .filter_map(|artifact| {
27 crate::scope::validate_file_target(&config.root, artifact)
28 .err()
29 .map(|error| error.to_string())
30 })
31 .collect(),
32 ok: true,
33 artifacts: config.artifacts.len(),
34 evals: config.evals.len(),
35 })
36}
37
38pub async fn request_show(
39 state: &Path,
40 id: &RequestId,
41 now: time::OffsetDateTime,
42) -> Result<Value, String> {
43 Ok(crate::query::request_output(
44 &request(state, id).await?,
45 now,
46 ))
47}
48
49pub async fn request(state: &Path, id: &RequestId) -> Result<RequestView, String> {
51 crate::store::read_request_id(state, id).await
52}
53
54pub struct RequestContext {
56 pub target: crate::review::Target,
57 pub run: crate::runs::RunView,
58 pub requests: Vec<RequestView>,
59}
60
61pub async fn request_context(state: &Path, id: &RequestId) -> Result<RequestContext, String> {
62 let exact = request(state, id).await?;
63 let target = crate::review::Target::from(exact.request.as_ref());
64 let (run, requests) = crate::store::read_run_requests_by_id(state, &target.run).await?;
65 Ok(RequestContext {
66 target,
67 run,
68 requests,
69 })
70}
71
72pub async fn request_list(
73 state: &Path,
74 run: Option<&crate::types::RunId>,
75 repo: Option<&Path>,
76 now: time::OffsetDateTime,
77) -> Result<Vec<Value>, String> {
78 let views = requests(state, run, repo).await?;
79 Ok(request_list_output(&views, now))
80}
81
82pub async fn requests(
84 state: &Path,
85 run: Option<&crate::types::RunId>,
86 repo: Option<&Path>,
87) -> Result<Vec<RequestView>, String> {
88 crate::store::read_requests_for_run(state, run.cloned(), repo).await
89}
90
91pub fn request_list_output(views: &[RequestView], now: time::OffsetDateTime) -> Vec<Value> {
92 views
93 .iter()
94 .map(|view| crate::query::request_output(view, now))
95 .collect()
96}
97
98pub async fn remote_status(state: Option<&Path>, repo: Option<&Path>) -> Result<Value, String> {
99 Ok(remote_output(
100 crate::auth::remote::status(state, repo).await?.as_ref(),
101 ))
102}
103
104pub fn remote_output(status: Option<&crate::auth::remote::Status>) -> Value {
105 match status {
106 Some(status) => {
107 let mut value = json!(status);
108 value["configured"] = json!(true);
109 value
110 }
111 None => json!({"configured": false}),
112 }
113}
114
115pub async fn session_show(
116 state: &Path,
117 selector: &session::Selector,
118 summary: bool,
119) -> Result<session::Shown, String> {
120 session::show(state, selector, summary).await
121}