Skip to content

AIDK API Reference / aidk/compiler

aidk/compiler ​

Compiler - Tick-Based Agent Architecture

A React-inspired fiber architecture designed specifically for AI agent execution. Unlike React, this compiler is async-first and tick-based - no concurrent mode needed.

Key Features:

  • Hooks in function components (useState, useEffect, etc.)
  • AI-specific hooks (useComState, useTickStart, useAfterCompile)
  • Full class component support (signals, lifecycle methods)
  • Pure content block rendering
  • Async-first (effects can be async)
  • Compile stabilization (recompile until stable)

Examples ​

tsx
function ChatAgent({ maxTurns }: { maxTurns: number }) {
  const [turns, setTurns] = useState(0);
  const [timeline, setTimeline] = useComState('timeline', []);

  useTickStart((com, state) => {
    if (state.current?.timeline) {
      setTimeline(t => [...t, ...state.current.timeline]);
      setTurns(t => t + 1);
    }
  });

  useTickEnd((com, state) => {
    if (turns >= maxTurns) {
      state.stop('max turns reached');
    }
  });

  useEffect(async () => {
    await logToServer({ turns, messageCount: timeline.length });
  }, [turns]);

  return (
    <>
      <Section id="system">
        <Text>You are a helpful assistant.</Text>
      </Section>
      <Timeline>
        {timeline.map((msg, i) => (
          <Message key={i} role={msg.role}>{msg.content}</Message>
        ))}
      </Timeline>
    </>
  );
}
tsx
class ChatAgent extends Component {
  timeline = comState<Message[]>('timeline', []);
  turns = signal(0);

  async onTickStart(com, state) {
    if (state.current?.timeline) {
      this.timeline.update(t => [...t, ...state.current.timeline]);
      this.turns.update(t => t + 1);
    }
  }

  render(com, state) {
    return (
      <Timeline>
        {this.timeline().map(...)}
      </Timeline>
    );
  }
}
tsx
function ExecutionController() {
  const [turns, setTurns] = useState(0);

  useTickEnd((com, state) => {
    setTurns(t => t + 1);
    if (turns >= 10) state.stop('max turns');
  });

  return null;  // No output - just manages execution
}
tsx
function ContentProvider() {
  const blocks = [
    { type: 'text', text: 'Block 1' },
    { type: 'text', text: 'Block 2' },
  ];

  return (
    <Message role="assistant">
      <Text>Hello!</Text>
      {blocks}
    </Message>
  );
}

Classes ​

ClassDescription
FiberCompiler-
StructureRendererStructureRenderer: Applies CompiledStructure to COM and formats content.

Interfaces ​

InterfaceDescription
AsyncResult-
CompileResult-
CompileStabilizationOptionsOptions for the compileUntilStable method.
CompileStabilizationResultResult of the compileUntilStable method.
ComponentInstanceComponent instance (class component).
EffectAn effect to run during a tick phase.
FiberCompilerConfig-
FiberNode-
HookState-
RenderContextContext available during component render. Set by compiler, read by hooks.
Update-
UpdateQueue-

Type Aliases ​

Type AliasDescription
ClassComponentClass component constructor.
ComponentTypeAny component type.
ContentBlockType-
Dispatch-
EffectCallback-
EffectCleanup-
EffectPhase-
FiberChildValid children in the fiber tree.
FiberFlags-
FunctionComponentFunction component. Can receive (props), (props, com), or (props, com, state).
HookTag-
NormalizedChildNormalized child after processing.
ReducerHookResult-
RefObject-
StateHookResult-

Variables ​

VariableDescription
CONTENT_BLOCK_TYPES-
EffectPhaseEffect phase - when the effect runs in the tick lifecycle.
FiberFlags-
HookTag-

Functions ​

FunctionDescription
cloneFiberClone a fiber for use in a different location.
createFiberCreate a new fiber node.
createWorkInProgressCreate a work-in-progress fiber from an existing fiber. This enables double-buffering for safe updates.
fiberToDebugStringCreate a debug string representation of a fiber.
fiberTreeToDebugStringCreate a debug tree representation.
findFiberByKeyFind a fiber by key among siblings.
findNearestRendererFind the nearest renderer in the fiber tree.
getChildFibersGet all child fibers as an array.
getHookAtIndexGet hook at a specific index.
getHookCountGet the number of hooks on a fiber.
isFragmentCheck if a type is a Fragment (works across module boundaries) Fragment is a Symbol, so we check by symbol identity or description
setFiberRendererSet renderer on fiber and mark for propagation.
traverseFiberTraverse fiber tree depth-first, calling callback on each fiber.
traverseFiberBottomUpTraverse fiber tree bottom-up (children first, then parent).

References ​

getCurrentContext ​

Re-exports getCurrentContext


getCurrentFiber ​

Re-exports getCurrentFiber


isContentBlock ​

Re-exports isContentBlock


setRenderContext ​

Re-exports setRenderContext


setScheduleWork ​

Re-exports setScheduleWork


useAbortSignal ​

Re-exports useAbortSignal


useAfterCompile ​

Re-exports useAfterCompile


useAsync ​

Re-exports useAsync


useCallback ​

Re-exports useCallback


useComputed ​

Re-exports useComputed


useCOMRef ​

Re-exports useCOMRef


useComState ​

Re-exports useComState


useCounter ​

Re-exports useCounter


useDebugValue ​

Re-exports useDebugValue


useEffect ​

Re-exports useEffect


useInit ​

Re-exports useInit


useInput ​

Re-exports useInput


useMemo ​

Re-exports useMemo


useOnMount ​

Re-exports useOnMount


useOnUnmount ​

Re-exports useOnUnmount


usePrevious ​

Re-exports usePrevious


useReducer ​

Re-exports useReducer


useRef ​

Re-exports useRef


useSignal ​

Re-exports useSignal


useState ​

Re-exports useState


useTickEnd ​

Re-exports useTickEnd


useTickStart ​

Re-exports useTickStart


useToggle ​

Re-exports useToggle


useWatch ​

Re-exports useWatch

Released under the MIT License.