Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AGenUI AGenUI IEngineContext

From Leeroopedia
Knowledge Sources
Domains Software_Architecture, UI_Framework
Last Updated 2026-10-24 17:21 GMT

Overview

Read-only accessor interface for engine-level shared services, provided by the AGenUI C++ core.

Description

The `IEngineContext` interface exposes the minimal set of engine-level shared services needed by lower-level modules: `FunctionCallManager`, `TemplateRegistry`, `IComponentPropertySpecManager`, and `PathConfig`. It also provides `isDeepParseProperty()` for querying whether a component property was registered for deep-parse subtree walking.

The interface is implemented by `AGenUIEngine` and made available through two free functions:

  • `getEngineContext()` — global accessor; returns the current context or `nullptr` if the engine is not running. Available after `engine->start()`, invalidated after `engine->stop()`.
  • `setEngineContext(ctx)` — internal setter used only by `AGenUIEngine` during start/stop.

This follows the dependency inversion principle: lower-level modules (template registry, style parsers) depend on the abstract `IEngineContext` interface rather than the concrete `AGenUIEngine` class. This breaks what would otherwise be a circular dependency, since the engine owns these modules but they need access to engine-level services.

Usage

  • Lower-level modules: call `getEngineContext()` to access shared services (e.g. `TemplateRegistry` calls `ctx->getPathConfig()` to find the template directory).
  • Deep-parse queries: call `ctx->isDeepParseProperty(componentType, propertyName)` to check if a property should be walked recursively during parsing.
  • Not for host applications: host applications use `IAGenUIEngine` directly; `IEngineContext` is an internal seam.

Code Reference

Source Location

Signature

// core/src/agenui_engine_context.h
namespace agenui {

class FunctionCallManager;
class TemplateRegistry;
class IComponentPropertySpecManager;
class PathConfig;

class IEngineContext {
public:
    virtual ~IEngineContext() = default;

    virtual FunctionCallManager* getFunctionCallManager() = 0;
    virtual TemplateRegistry* getTemplateRegistry() = 0;
    virtual IComponentPropertySpecManager* getComponentPropertySpecManager() = 0;
    virtual PathConfig* getPathConfig() = 0;

    /// Whether a property was declared a container of dynamic values.
    /// A "*" wildcard component type matches every component type.
    virtual bool isDeepParseProperty(const std::string& componentType,
                                     const std::string& propertyName) = 0;
};

/// Returns the current engine context, or nullptr if engine is not running.
IEngineContext* getEngineContext();

/// Sets the engine context (internal use by AGenUIEngine only).
void setEngineContext(IEngineContext* ctx);

} // namespace agenui

Import

#include "agenui_engine_context.h"

I/O Contract

Inputs

Name Type Required Description
componentType `const std::string&` Yes Component type name (or "*" for wildcard)
propertyName `const std::string&` Yes Property name to check for deep-parse registration
ctx `IEngineContext*` Yes (set) Engine context pointer; nullptr to unregister

Outputs

Name Type Description
getEngineContext() returns `IEngineContext*` Context pointer, or nullptr if engine not running
getFunctionCallManager() returns `FunctionCallManager*` Shared function-call registry
getTemplateRegistry() returns `TemplateRegistry*` Shared template registry
getComponentPropertySpecManager() returns `IComponentPropertySpecManager*` Component property spec manager
getPathConfig() returns `PathConfig*` Path configuration (template dirs, etc.)
isDeepParseProperty() returns `bool` True if property is registered for deep-parse walking

Usage Examples

Accessing Shared Services from a Lower-Level Module

#include "agenui_engine_context.h"

void loadTemplates() {
    // Get engine context (returns nullptr if engine not started)
    auto* ctx = agenui::getEngineContext();
    if (!ctx) {
        return;  // Engine not running
    }

    // Access PathConfig to find the template directory
    auto* pathConfig = ctx->getPathConfig();
    if (!pathConfig) {
        return;
    }

    std::string templateDir = pathConfig->getTemplateDir();
    // Load template files from templateDir...
}

Querying Deep-Parse Properties

#include "agenui_engine_context.h"

// During component parsing, check if a property should be deep-parsed
bool shouldWalkSubtree(const std::string& componentType,
                       const std::string& propertyName) {
    auto* ctx = agenui::getEngineContext();
    if (!ctx) {
        return false;
    }
    // Wildcard "*" registration matches all component types
    return ctx->isDeepParseProperty(componentType, propertyName);
}

Related Pages

Implements Principle

Requires Environment

Related Implementations

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment