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 ​
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>
</>
);
}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>
);
}
}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
}function ContentProvider() {
const blocks = [
{ type: 'text', text: 'Block 1' },
{ type: 'text', text: 'Block 2' },
];
return (
<Message role="assistant">
<Text>Hello!</Text>
{blocks}
</Message>
);
}Classes ​
| Class | Description |
|---|---|
| FiberCompiler | - |
| StructureRenderer | StructureRenderer: Applies CompiledStructure to COM and formats content. |
Interfaces ​
| Interface | Description |
|---|---|
| AsyncResult | - |
| CompileResult | - |
| CompileStabilizationOptions | Options for the compileUntilStable method. |
| CompileStabilizationResult | Result of the compileUntilStable method. |
| ComponentInstance | Component instance (class component). |
| Effect | An effect to run during a tick phase. |
| FiberCompilerConfig | - |
| FiberNode | - |
| HookState | - |
| RenderContext | Context available during component render. Set by compiler, read by hooks. |
| Update | - |
| UpdateQueue | - |
Type Aliases ​
| Type Alias | Description |
|---|---|
| ClassComponent | Class component constructor. |
| ComponentType | Any component type. |
| ContentBlockType | - |
| Dispatch | - |
| EffectCallback | - |
| EffectCleanup | - |
| EffectPhase | - |
| FiberChild | Valid children in the fiber tree. |
| FiberFlags | - |
| FunctionComponent | Function component. Can receive (props), (props, com), or (props, com, state). |
| HookTag | - |
| NormalizedChild | Normalized child after processing. |
| ReducerHookResult | - |
| RefObject | - |
| StateHookResult | - |
Variables ​
| Variable | Description |
|---|---|
| CONTENT_BLOCK_TYPES | - |
| EffectPhase | Effect phase - when the effect runs in the tick lifecycle. |
| FiberFlags | - |
| HookTag | - |
Functions ​
| Function | Description |
|---|---|
| cloneFiber | Clone a fiber for use in a different location. |
| createFiber | Create a new fiber node. |
| createWorkInProgress | Create a work-in-progress fiber from an existing fiber. This enables double-buffering for safe updates. |
| fiberToDebugString | Create a debug string representation of a fiber. |
| fiberTreeToDebugString | Create a debug tree representation. |
| findFiberByKey | Find a fiber by key among siblings. |
| findNearestRenderer | Find the nearest renderer in the fiber tree. |
| getChildFibers | Get all child fibers as an array. |
| getHookAtIndex | Get hook at a specific index. |
| getHookCount | Get the number of hooks on a fiber. |
| isFragment | Check if a type is a Fragment (works across module boundaries) Fragment is a Symbol, so we check by symbol identity or description |
| setFiberRenderer | Set renderer on fiber and mark for propagation. |
| traverseFiber | Traverse fiber tree depth-first, calling callback on each fiber. |
| traverseFiberBottomUp | Traverse 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