Skip to main content

IntoNode

Trait IntoNode 

Source
pub trait IntoNode<S>
where S: State,
{ // Required method fn into_node(self, name: &str) -> Arc<dyn Node<S>> ; }
Expand description

Conversion trait for creating nodes from async functions

This trait allows async functions with various signatures to be used as nodes in a Juncture graph.

§Supported Function Signatures

The trait supports multiple function signatures for flexibility:

§Forms A-D (existing, without Runtime)

use juncture_core::{IntoNode, State, Node, Command};
use juncture_core::node::NodeFnUpdate;
use std::sync::Arc;


// Form A: fn(S) -> Result<S::Update>
async fn simple_node(state: MyState) -> Result<MyStateUpdate, juncture_core::JunctureError> {
    Ok(MyStateUpdate)
}

// Form B: fn(S, RunnableConfig) -> Result<S::Update>
async fn with_config(state: MyState, config: RunnableConfig) -> Result<MyStateUpdate, juncture_core::JunctureError> {
    Ok(MyStateUpdate)
}

// Form C: fn(S) -> Result<Command<S>>
async fn with_command(state: MyState) -> Result<Command<MyState>, juncture_core::JunctureError> {
    Ok(Command::end())
}

// Form D: fn(S, RunnableConfig) -> Result<Command<S>>
async fn full_form(state: MyState, config: RunnableConfig) -> Result<Command<MyState>, juncture_core::JunctureError> {
    Ok(Command::end())
}

§Forms E-F (new, with Runtime for dependency injection)

use juncture_core::{IntoNode, State, Runtime};
use juncture_core::node::NodeFnUpdateWithRuntime;


// Form E: fn(S, Runtime<C>) -> Result<S::Update>
async fn with_runtime(state: MyState, runtime: Runtime<MyContext>) -> Result<MyStateUpdate, juncture_core::JunctureError> {
    // Access runtime context
    let user_id = &runtime.context.user_id;
    Ok(MyStateUpdate)
}

// Form F: fn(S, RunnableConfig, Runtime<C>) -> Result<S::Update>
async fn with_all(state: MyState, config: RunnableConfig, runtime: Runtime<MyContext>) -> Result<MyStateUpdate, juncture_core::JunctureError> {
    // Full access to state, config, and runtime
    Ok(MyStateUpdate)
}

§Examples

use juncture_core::{IntoNode, State, Runtime};
use juncture_core::node::NodeFnUpdateWithRuntime;
use std::sync::Arc;


// Create a Runtime with custom context
let runtime = Runtime::with_context(MyContext { user_id: "user-123".to_string() });

// Wrap a Runtime-aware function
let wrapper = NodeFnUpdateWithRuntime::new(
    async fn my_node(state: MyState, runtime: Runtime<MyContext>) -> Result<MyStateUpdate, JunctureError> {
        // Use runtime context
        Ok(MyStateUpdate)
    },
    runtime
);

// Convert to a node
let node: Arc<dyn Node<MyState>> = wrapper.into_node("my_node");

Required Methods§

Source

fn into_node(self, name: &str) -> Arc<dyn Node<S>>

Convert this value into a node with the given name

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<M: ChatModel> IntoNode<MessagesState> for AgentNode<M>

Source§

impl<S, F, Fut, C> IntoNode<S> for NodeFnCommandWithConfigAndRuntime<F, C>
where S: State, C: Clone + Send + Sync + 'static, F: Fn(&S, RunnableConfig, Runtime<C>) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<Command<S>, JunctureError>> + Send + 'static,

Source§

impl<S, F, Fut, C> IntoNode<S> for NodeFnCommandWithRuntime<F, C>
where S: State, C: Clone + Send + Sync + 'static, F: Fn(&S, Runtime<C>) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<Command<S>, JunctureError>> + Send + 'static,

Source§

impl<S, F, Fut, C> IntoNode<S> for NodeFnUpdateWithConfigAndRuntime<F, C>
where S: State, C: Clone + Send + Sync + 'static, F: Fn(&S, RunnableConfig, Runtime<C>) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<<S as State>::Update, JunctureError>> + Send + 'static,

Source§

impl<S, F, Fut, C> IntoNode<S> for NodeFnUpdateWithRuntime<F, C>
where S: State, C: Clone + Send + Sync + 'static, F: Fn(&S, Runtime<C>) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<<S as State>::Update, JunctureError>> + Send + 'static,

Source§

impl<S, F, Fut> IntoNode<S> for NodeFnCommand<F>
where S: State, F: Fn(&S) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<Command<S>, JunctureError>> + Send + 'static,

Source§

impl<S, F, Fut> IntoNode<S> for NodeFnCommandWithConfig<F>
where S: State, F: Fn(&S, RunnableConfig) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<Command<S>, JunctureError>> + Send + 'static,

Source§

impl<S, F, Fut> IntoNode<S> for NodeFnUpdate<F>
where S: State, F: Fn(&S) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<<S as State>::Update, JunctureError>> + Send + 'static,

Source§

impl<S, F, Fut> IntoNode<S> for NodeFnUpdateWithConfig<F>
where S: State, F: Fn(&S, RunnableConfig) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<<S as State>::Update, JunctureError>> + Send + 'static,