thal 0.0.1

Reactive semantic runtime — molecules, reactions, and effect actors for building LLM-backed applications as dataflow programs.
Documentation
use crate::value::{MoleculeKindId, Value};
use std::collections::BTreeMap;

use super::delta::LogicalTime;

#[derive(Clone, Debug)]
pub struct Molecule {
    pub kind: MoleculeKindId,
    pub kind_name: String,
    pub fields: BTreeMap<String, Value>,
    pub ts: LogicalTime,
}

impl Molecule {
    pub fn builder(kind_name: impl Into<String>) -> MoleculeBuilder {
        MoleculeBuilder {
            kind_name: kind_name.into(),
            fields: BTreeMap::new(),
        }
    }
}

pub struct MoleculeBuilder {
    kind_name: String,
    fields: BTreeMap<String, Value>,
}

impl MoleculeBuilder {
    pub fn field(mut self, name: impl Into<String>, value: Value) -> Self {
        self.fields.insert(name.into(), value);
        self
    }

    /// Builds an unbound molecule. The runtime resolves `kind` against the
    /// type registry when it enters the reactor; until then `kind` is set
    /// to a sentinel.
    pub fn build(self) -> Molecule {
        Molecule {
            kind: MoleculeKindId(u32::MAX),
            kind_name: self.kind_name,
            fields: self.fields,
            ts: LogicalTime(0),
        }
    }
}

#[derive(Clone, Debug, PartialEq, Eq, Hash, Ord, PartialOrd)]
pub struct PrimaryKey(pub Vec<Value>);