Questit now provides a lightweight runtime inside every rendered tool so generated code can adopt richer, stateful behaviour without extra build tooling. This page outlines the available APIs and recommended usage patterns.
The helper kit is injected automatically before a tool executes and exposes:
events– publish/subscribe bus for intra-tool communication.const kit = window.questit?.kit; const stop = kit?.events.on('refresh', () => loadData()); kit?.events.emit('refresh');
safeFetch(url, options?, { timeoutMs?, retries?, retryDelayMs?, retryOn? })– wrapper aroundfetchwith timeout + retry safeguards.storage.local/storage.session– JSON-safe read/write helpers backed by localStorage/sessionStorage.publish(event, payload)– broadcast custom events and capture them in the kit history.history()– read the most recent published event payloads (capped to 64 entries).ui– shadcn-aligned helpers for markup generation.ui.classes/ui.snippetsexpose ready-made class names and HTML fragments (questit-ui-button,questit-ui-card,questit-ui-input, etc.).ui.templates.button(label, options)and friends return styled HTML strings you can inject directly when building dynamic interfaces.
Always guard access with optional chaining (window.questit?.kit) so the tool still works when embedded outside the Questit shell.
The runtime tracks every mounted tool and offers integration points:
listTools()– array of tool IDs currently rendered.getToolState(toolId)– snapshot of metadata, container element, and error state.runSelfTest(toolId)– trigger the tool’srunSelfCheckhandler.resetTool(toolId)– re-executes the tool bundle, dispatching aquestit:tool-resetevent.disposeTool(toolId)– unmounts and cleans up listeners for the tool.kitHistory()– convenience alias ofwindow.questit.kit.history().
Example:
const runtime = window.questit?.runtime;
const [toolId] = runtime?.listTools() ?? [];
runtime?.resetTool(toolId);The runtime also automatically assigns a non-enumerable questitUnmount() method to each container element, enabling manual cleanup when embedding via custom mount points.
- Assume pure browser execution; avoid Node-only APIs or server-based helpers unless explicitly provided.
- Prefer the provided
questit-ui-*classes orkit.ui.templateshelpers so the tool matches the workbench’s shadcn design. - Wrap asynchronous work in
try/catchand forward errors withwindow.dispatchEvent(new CustomEvent('questit:tool-error', { detail })). - Keep DOM queries defensive (
document.querySelector(...) ||fallback) so reruns afterresetTool()do not crash. - Reuse the event bus for polling, cross-component coordination, or bridging to external widgets instead of global variables.
- Use
safeFetchwhen hitting external APIs to inherit timeouts and retries automatically.
Refer to src/delivery/browser-kit.js and src/delivery/render-handler.js for the authoritative implementation details.
- In
public/test.html, callwindow.questit.kit.ui.templates.button('Test')to inspect the rendered button inside a generated tool. - Ensure custom HTML uses the
questit-ui-*classes; mismatches will stand out immediately against the shadcn base theme. - When debugging, toggle the questit debug panel and confirm the tool inherits the current color theme (light/dark/base hue).