API / @aihu/arbor

@aihu/arbor

Runtime core

Reactive component tree (the rendering layer that consumes @aihu/signals).

version
2.0.0
exports
20
values
8
types
12
01

_getComponentInstanceRegistry

functionagent
function _getComponentInstanceRegistry(): ReadonlyMap<string, LiveBinding[]>

Export the registry getter for injection into `@aihu/agent-service`.

02

branch

function
function branch(tag: string | null, attrs?: AttrMap, children?: ChildList): Branch

`branch(tag, attrs?, children?)` — public factory for branch nodes per `.team/phase-3/spec-arbor.md` §1.2.

03

each

function
function each<T>( list: Signal<T[]>, key: (item: T) => string | number, grow: (item: T, index: number) => Node, ): StructuralNode
04

hydrate

function
function hydrate( component: () => Node, host: Element | ShadowRoot, snapshot: Snapshot, options?: MountOptions, ): ReturnType<typeof mount>

Attach reactive effects from `component`'s arbor tree to pre-rendered DOM nodes under `host` without re-creating elements.

05

mount

function
function mount(node: Node, host: Element | ShadowRoot, options?: MountOptions): MountScope

Materialize `node` into `host` synchronously and return a `MountScope` owning the lifecycle.

06

when

function
function when(condition: Signal<boolean>, grow: () => Node): StructuralNode

`when()` and `each()` — v1 reconciler per spec §2 (Plan 1.1).

07

leaf

const
const leaf: LeafFactory
08

slot

const
const slot = (name?: string): Leaf => …

`slot(name?)` — creates a `<slot>` DOM element for Shadow DOM content projection per Plan 1.4.

09

AgentBindingSpec

interfaceagent
interface AgentBindingSpec {
  readonly tag: string
  readonly actions: Record<string, (args: unknown) => unknown>
  readonly reads: Record<string, () => unknown>
  readonly writes: Record<string, (v: unknown) => void>
  readonly scope: string | undefined
  readonly rateLimit: string | undefined
}

Shape of the `__agentBinding` named export emitted by the compiler into server artifacts for components with an `@agent` block (RFC §3).

10

AgentContext

interfaceagent
interface AgentContext {
  readonly _brand: 'AgentContext'
  /** Root ID from the mount scope (only present on live contexts). */
  readonly rootId?: number
  /** Tag name (only present on live contexts). */
  readonly tag?: string
  /** Read the current value of a named signal (live context only). */
  readonly readSignal?: (name: string) => unknown
  /** Write a value to a named writable signal (live context only). */
  readonly writeSignal?: (name: string, value: unknown) => void
  /** Invoke a named action (live context only). */
  readonly callAction?: (name: string, args: unknown[]) => Promise<unknown>
}

Agent context attached to a `MountScope`.

11

Branch

interface
interface Branch {
  readonly kind: 'branch'
  readonly tag: string | null
  readonly attrs: AttrMap | null
  readonly children: ChildList
  /** Written by `_materialize`; undefined until the branch is mounted. */
  el?: Element
}

A `branch` node.

12

Leaf

interface
interface Leaf {
  readonly kind: 'leaf'
  readonly leafKind: 'text' | 'element'
  readonly value: Signal<string> | string | null
  readonly tag: string | null
  readonly attrs: AttrMap | null
}

A `leaf` node — either a text leaf (`leaf(value)`) or a terminal element leaf (`leaf.element(tag, attrs?)`).

13

MountOptions

interface
interface MountOptions {
  /** Error boundary handler. See ErrorHandler. */
  onError?: ErrorHandler
  /**
   * v0.3.0 — the `__agentBinding` export from the component's server artifact.
   * When present, `mount()` registers a `LiveBinding` in the
   * `componentInstanceRegistry`. Components without an `@agent` block
   * never pass this option (zero overhead on the non-agent path).
   */
  agentBinding?: AgentBindingSpec
}

Options for mount().

14

MountScope

interface
interface MountScope {
  dispose(): void
  readonly agent: AgentContext
  serialize(): Snapshot
}

Public `MountScope` returned by `mount()`.

15

AttrMap

type
type AttrMap = Record<string, string | number | boolean | Signal<unknown> | EventHandler>

Attribute map.

16

ChildList

type
type ChildList = ReadonlyArray<Branch | Leaf | StructuralNode>

Children are static at construction time.

17

ErrorHandler

type
type ErrorHandler = (error: unknown, path: string) => Node | undefined

Error handler for a mount scope.

18

EventHandler

type
type EventHandler = (event: Event) => void

Event listener handler.

19

Node

type
type Node = Branch | Leaf | StructuralNode

Discriminated union of node kinds accepted by `mount()`.

20

Snapshot

type
type Snapshot = Record<string, unknown>

Sub-project #6 — SSR/serialize and hydration (Plan 3.2).