app

package
v0.0.0-...-26e635b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 22, 2025 License: MIT Imports: 21 Imported by: 0

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

func InitializeApp(ctx context.Context, cfg *config.Config) (*App, func(), error)

InitializeApp is the Wire injector function. Wire will automatically generate the implementation of this function.

func (*App) Close

func (a *App) Close() error

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

func (a *App) CreateAgent(_ context.Context) (*chat.Chat, error)

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.

func (*App) Go

func (a *App) Go(f func() error)

Go starts a new background goroutine tracked by the app's errgroup. Use this for any background tasks that should be waited on during shutdown.

func (*App) Wait

func (a *App) Wait() error

Wait blocks until all background goroutines complete. This is useful for waiting on background tasks without closing resources.

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

type Runtime struct {
	App  *App
	Flow *chat.Flow
	// contains filtered or unexported fields
}

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

func NewRuntime(ctx context.Context, cfg *config.Config) (*Runtime, error)

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

func (*Runtime) Close

func (r *Runtime) Close() error

Close releases all resources. Implements io.Closer. Shutdown order: App.Close (goroutines) → Wire cleanup (DB pool, OTel).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL