Skip to main content

objectiveai_sdk/functions/expression/
input_value_log.rs

1//! `InputValueLog` — on-disk shape of [`super::InputValue`].
2//!
3//! Mirrors `InputValue`'s recursive tree but every leaf becomes a
4//! [`LogReference`] to its own file. Object/Array branches preserve
5//! structure as `IndexMap<String, LogReference>` and
6//! `Vec<LogReference>` respectively — each value/element references
7//! a per-leaf file (which itself may be a sub-tree if the original
8//! child was an Object or Array; in that case the file's content is
9//! the serialized `InputValueLog` of that sub-tree).
10//!
11//! Per-leaf file naming: paths nest under
12//! `<route_base>/input/<dotted-key-path>/<id>.<ext>` so the on-disk
13//! layout mirrors the input tree shape directly.
14//!
15//! Three top-level variants, JSON-distinguishable when untagged:
16//!
17//! - `Reference` (object with `"type":"reference","path":"…"`) — the
18//!   leaf was a primitive (`String`/`Integer`/`Number`/`Boolean`) or
19//!   a `RichContentPart`. The referenced file contains the value
20//!   itself (raw text for strings, JSON for everything else).
21//! - `Object` (JSON map of refs) — the original was
22//!   [`super::InputValue::Object`].
23//! - `Array` (JSON list of refs) — the original was
24//!   [`super::InputValue::Array`].
25//!
26//! Readers branching on JSON shape can pattern-match in that order
27//! without ambiguity (LogReference has a known `"type"` discriminator;
28//! Object and Array are map vs list at the JSON level).
29
30use indexmap::IndexMap;
31use schemars::JsonSchema;
32use serde::{Deserialize, Serialize};
33
34use crate::logs::LogReference;
35
36#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
37#[serde(untagged)]
38#[schemars(rename = "functions.expression.InputValueLog")]
39pub enum InputValueLog {
40    #[schemars(title = "Reference")]
41    Reference(LogReference),
42    #[schemars(title = "Object")]
43    Object(IndexMap<String, LogReference>),
44    #[schemars(title = "Array")]
45    Array(Vec<LogReference>),
46}