Class VoiceNodeBuilder

Fluent DSL builder for voice graph nodes.

Collects exit-reason -> target-node mappings via on and produces a fully-specified GraphNode via build.

The builder is designed to be chained. Each on() call returns this, enabling a declarative voice node definition:

voiceNode('listen', { mode: 'conversation', maxTurns: 5 })
.on('completed', 'summarize')
.on('interrupted', 'listen')
.on('hangup', 'end')

See

voiceNode -- the factory function that creates builder instances. See VoiceNodeExecutor for the runtime that resolves exit reasons and edge routing.

Constructors

Methods

Properties

Constructors

Methods

  • Register an exit-reason -> target-node route.

    When the voice node's session ends with exitReason, the graph transitions to target. Multiple calls to on() accumulate routes; calling on() with a reason that was already registered overwrites the previous target.

    Common exit reasons

    Reason When it fires
    'completed' Session ended normally (catch-all).
    'turns-exhausted' maxTurns reached.
    'hangup' Transport disconnected.
    'interrupted' User barged in (VoiceInterruptError).
    'silence-timeout' No speech activity for 30 seconds.
    'keyword:<word>' A final_transcript contained an exit keyword.

    Parameters

    • exitReason: string

      The reason string returned by the voice executor.

    • target: string | {
          id: string;
      }

      Either the string id of the target node, or an object with an id property (compatible with other builder instances, e.g. voiceNode('other', ...)).

    Returns this

    this for fluent chaining.

    Example

    builder
    .on('completed', 'next-node')
    .on('hangup', { id: 'cleanup-node' });
  • Produce a GraphNode IR object from the accumulated builder state.

    The returned node has:

    • type: 'voice' in sync with executorConfig.type.
    • executionMode: 'react_bounded' -- voice nodes run a multi-turn loop.
    • effectClass: 'external' -- voice I/O touches the real world.
    • checkpoint: 'before' -- snapshot taken before the session starts so the run can be resumed from the start of the voice turn if the process crashes.
    • edges -- plain object mapping exit-reason strings to target node ids, populated from all on() calls. The compiler is responsible for expanding these into GraphEdge instances.

    Returns GraphNode

    A GraphNode with the edges extension field. Cast to any to accommodate the edges field not present on the base interface.

    Example

    const node = voiceNode('greet', { mode: 'conversation' })
    .on('completed', 'process')
    .build();

    console.log(node.type); // 'voice'
    console.log(node.edges.completed); // 'process'

Properties

id: string

The node id assigned at construction time.