Documentation
¶
Overview ¶
Package app provides application initialization and dependency injection.
App is the core container that orchestrates all application components using Wire for DI. It initializes Genkit, database connection, DocStore (via Genkit PostgreSQL Plugin), and creates the agent with all necessary dependencies.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type App ¶
type App struct {
// Configuration
Config *config.Config
Genkit *genkit.Genkit
Embedder ai.Embedder // Explicitly exported for Wire
DBPool *pgxpool.Pool // Database connection pool
DocStore *postgresql.DocStore // Genkit PostgreSQL DocStore for indexing
Retriever ai.Retriever // Genkit Retriever for searching
SessionStore *session.Store // Session persistence (concrete type, not interface)
PathValidator *security.Path // Path validator for security
Tools []ai.Tool // Pre-registered tools (injected by Wire)
// contains filtered or unexported fields
}
App is the core application container.
func InitializeApp ¶
InitializeApp is the Wire injector function. Wire will automatically generate the implementation of this function.
func (*App) Close ¶
Close gracefully shuts down App-managed resources. Wire cleanup handles DB pool and OTel (single owner principle).
Shutdown order: 1. Cancel context (signals background tasks to stop) 2. Wait for background goroutines (errgroup)
func (*App) CreateAgent ¶
CreateAgent creates a Chat Agent using pre-registered tools. Tools are registered once at App construction (not lazily). Wire guarantees all dependencies are non-nil.
type OtelShutdown ¶
type OtelShutdown func()
OtelShutdown is a cleanup function for OpenTelemetry resources. Type alias provides clear semantics for Wire dependency ordering.
type RAGComponents ¶
type RAGComponents struct {
DocStore *postgresql.DocStore
Retriever ai.Retriever
}
RAGComponents holds DocStore and Retriever created together by Genkit. Wire doesn't support returning multiple values, so we use a struct.
type Runtime ¶
Runtime provides a fully initialized application runtime with all components ready to use. It encapsulates the common initialization logic used by CLI, HTTP server, and other entry points. Implements io.Closer for resource cleanup.
func NewRuntime ¶
NewRuntime creates a fully initialized runtime with all components ready for use. This is the recommended way to initialize Koopa for any entry point (CLI, HTTP, etc.).
Usage:
runtime, err := app.NewRuntime(ctx, cfg)
if err != nil { ... }
defer runtime.Close() // Single cleanup method (implements io.Closer)
// Use runtime.Flow for agent interactions