The Unified DSL Editor Workspace
Botgami features a powerful, high-fidelity developer workspace that pairs a full-featured code editor with an interactive visual preview canvas. At the center of this experience is the Unified DSL Editorβan in-browser code workspace optimized for writing, formatting, and analyzing .botgami bot scripts.
This page covers the architecture of the DSL editor, its integrated developer features, and how it synchronizes in real time with the visual canvas.
Editor Architectureβ
The Botgami workspace does not rely on a sluggish, server-side language server process. Instead, the entire IDE suite runs completely in-browser inside a dedicated web worker for maximum speed and instant feedback:
- CodeMirror 6: A modular, performant text editor engine providing custom themes (like OLED-first dark mode), linting panels, and keymap bindings.
- Langium LSP Worker: A dedicated web worker running a full language server protocol. Because the LSP is loaded in the browser as a client-side thread, syntax checking, autocomplete completions, and hovers are computed with zero network round-trips and zero lag.
- Server Compilation: When you save (debounced to 150ms), the editor automatically invokes the compiler, lower projections, and runs full static simulations on the backend.
Workspace Featuresβ
The Code mode is packed with classic developer utilities:
1. In-Context Auto-Completionsβ
The editor matches active tokens against Step contracts (gen/contracts.bundle.json) to suggest commands and signatures dynamically:
- Autocompletes statement methods such as
send.text,send.photo, andask.number. - Suggests available variables in the local scope, including read-only context variables (like
user.first_nameandcallback.data). - Lists signatures for all 45+ built-in expressions (e.g.
compact,len,sortBy).
2. High-Fidelity Diagnosticsβ
If your script violates syntax, references an undeclared variable, or violates type safety, a red line highlights the specific line and range.
- LSP Diagnostics: Computed locally by the Langium worker. Shows grammar errors and syntax problems.
- Compiler Projections: When saved, server-side compile checks (typegraph audits, edge pins) are mapped back to source ranges via the DSL Source Map.
3. Smart Hover Tipsβ
Hovering over any built-in statement, variable scope, or function presents descriptive markdown tooltips, parameters, expected return types, and example code snippets.
Bi-Directional Canvas Syncβ
The most unique feature of the Botgami workspace is its bi-directional layout synchronization:
1. Code-to-Canvas Syncβ
- You write code in the DSL editor (e.g. adding a new
send.textline) and save. - The client compiles the DSL to FlowSpec v2 JSON via
compileBotgamiDsland dispatches it over the WebSocket using areplace_specpatch. - The server runs the 14-stage compilation pipeline, generates a fresh
ProjectionBundle(detailing nodes, ports, and layout positions), and returns it. - React Flow renders the new nodes and wires instantly, maintaining a clean visual representation of your code.
2. Canvas-to-Code Syncβ
- You interact with the Visual Canvas (e.g. dragging a node to reorganize the layout or adding a connection wire).
- The canvas dispatches an atomic patch (e.g.
move_layoutorconnect) viaspec/preview_patchover the WebSocket. - The server applies the patch, compiles the graph, and returns the modified FlowSpec JSON.
- The client's Langium printer (
printFlowSpec) takes the new spec, converts it back into formatted.botgamitext, and updates your code editor bufferβall while preserving your comments and formatting!
Isolated Code Focus (Focus Scopes)β
When managing massive bots with hundreds of flows, a single text file can become overwhelming. To resolve this, the workspace supports Focus Scopes:
- Click any node on the Visual Canvas or select a specific flow in the trigger outline, and the workspace can isolate that specific flow in the code panel.
- CodeMirror collapses all surrounding flows and blocks, constraining your cursor and line indexes from 1 to the size of the focused block.
- You edit in clean isolation, while the background Langium parser continues to compile the absolute, full-sized document buffer to ensure all variables and scopes remain completely validated.
Next Stepsβ
- π Telegram Runtime & Interactions β Learn how flows translate to Telegram actions.
- π§© DSL Reference: Statement Reference β Explore the full reference for all actions, inputs, and triggers.
- β‘ Advanced Topics: Expressions β Write advanced logic inside your flows.