use bb_ir::proto::onnx::NodeProto;
use bb_runtime::atomic::DispatchResult;
use bb_runtime::bus::{OpError, OpErrorKind};
use bb_runtime::runtime::RuntimeResourceRef;
use bb_runtime::slot_value::SlotValue;
use bb_runtime::syscall::values::CompositeValue;
pub const DOMAIN: &str = "ai.bytesandbrains.composite";
pub const OP_TYPE: &str = "Bundle";
pub const PORT_BUNDLE: &str = "bundle";
pub fn invoke(
_node: &NodeProto,
inputs: &[(&str, &dyn SlotValue)],
_ctx: &mut RuntimeResourceRef<'_>,
) -> Result<DispatchResult, OpError> {
if inputs.is_empty() {
return Err(OpError {
kind: OpErrorKind::MissingSlot,
reason: "bundle_no_children",
detail: "composite.Bundle: at least one child input required".into(),
});
}
let mut children: Vec<Box<dyn SlotValue>> = Vec::with_capacity(inputs.len());
for (_slot_name, value) in inputs {
children.push(value.clone_boxed());
}
Ok(DispatchResult::Immediate(vec![(
PORT_BUNDLE.to_string(),
Box::new(CompositeValue { children }) as Box<dyn SlotValue>,
)]))
}
bb_derive::register_op! {
domain: "ai.bytesandbrains.composite",
op_type: "Bundle",
invoke: invoke,
}