Skip to content

TraekCanvas

The main component that renders the interactive conversation canvas: pan/zoom, message nodes, connection lines, input form, search, minimap, and focus mode.

All props are optional — <TraekCanvas /> works standalone and creates its own engine internally. Pass an engine when you need programmatic control (streaming, persistence, reading state).

PropTypeDefaultDescription
engineTraekEngine | nullinternal engineExternally managed engine instance
configPartial<TraekEngineConfig>{}Engine/canvas configuration overrides
componentMapNodeComponentMap{}Map node.type → Svelte component to override node renderers
onSendMessage(input: string, userNode: MessageNode, action?: string | string[]) => voidCalled after the user submits a message. The user node is already added to the engine
onNodesChanged() => voidCalled when nodes are mutated through canvas interactions
onViewportChange(viewport: { scale: number; offset: { x: number; y: number } }) => voidPan/zoom change notifications
initialScalenumberInitial zoom level
initialOffset{ x: number; y: number }Initial pan offset
initialPlacementPadding{ left: number; top: number }{ left: 0, top: 0 }Padding used when placing the first root node
initialOverlaySnippetOverlay rendered until the first node exists (e.g. a welcome screen)
inputActionsSnippet<[InputActionsContext]>Custom content rendered next to the input form
actionsActionDefinition[]Slash-command actions for the input
resolveActionsResolveActionsCustom action resolution logic
registryNodeTypeRegistryNode type registry (custom node types with lifecycle + actions)
defaultNodeActionsNodeTypeAction[]built-insOverride the default node toolbar actions
filterNodeActions(node: Node, actions: NodeTypeAction[]) => NodeTypeAction[]Filter toolbar actions per node
onRetry(nodeId: string) => voidCalled when the user retries an errored node
onEditNode(nodeId: string) => voidCalled when the user starts editing a node
mode'auto' | 'canvas' | 'focus''auto'Force canvas or mobile focus mode ('auto' switches by viewport width)
mobileBreakpointnumber768Width (px) below which focus mode activates in 'auto'
focusConfigPartial<FocusModeConfig>Mobile focus mode configuration
showFpsbooleanfalseShow an FPS counter
showStatsbooleantrueShow canvas stats
tourDelaynumber0Delay (ms) before showing the desktop onboarding tour
minimapMinNodesnumber0Minimum non-thought nodes before the minimap appears
breadcrumbMinNodesnumber0Minimum nodes before the context breadcrumb appears
translationsPartialTraekTranslationsEnglishPartial translation overrides, deep-merged with defaults
<script lang="ts">
import { TraekCanvas, TraekEngine, type MessageNode } from 'traek'
const engine = new TraekEngine()
function handleSend(input: string, userNode: MessageNode) {
// The user node is already in the tree — add the assistant reply:
engine.addNode('Thinking…', 'assistant', { parentIds: [userNode.id] })
}
</script>
<div style="height: 100dvh; width: 100%;">
<TraekCanvas {engine} onSendMessage={handleSend} />
</div>

The canvas fills its parent element, so give the container an explicit size.

Use componentMap to map node.type values (e.g. 'text', or your own custom strings) to Svelte components. See Custom Node Types.

Træk uses --traek-* CSS custom properties for theming (dark theme by default).