app

package
v1.21.1 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package app provides multi-app (multi-tenant) management for Hector.

Each app represents an isolated workspace with its own:

  • Configuration (agents, tools, LLMs)
  • Data (sessions, tasks, memory)
  • Authentication (JWT tokens)

Apps are stored in the database and managed via the Admin API.

Index

Constants

View Source
const (
	// AppContextKey is the context key for storing the current app.
	AppContextKey contextKey = "hector_app"
)

Variables

View Source
var ErrAppNotFound = fmt.Errorf("app not found")

ErrAppNotFound is returned when an app is not found.

Functions

func IDFromContext

func IDFromContext(ctx context.Context) string

IDFromContext extracts the app ID from the context. Returns "default" if no app is set.

func WithApp

func WithApp(ctx context.Context, app *App) context.Context

WithApp returns a new context with the given app.

func WithAppID

func WithAppID(ctx context.Context, appID string) context.Context

WithAppID returns a new context with a minimal app containing just the ID. This is useful when you only have the app ID (e.g., from auth claims).

Types

type App

type App struct {
	// ID is the unique identifier for the app (also used as app_name/tenant_id)
	ID string `json:"id"`

	// Name is the human-readable display name
	Name string `json:"name"`

	// ConfigJSON stores the full hector configuration as JSON/YAML
	ConfigJSON string `json:"config_json,omitempty"`

	// CreatedAt is when the app was created
	CreatedAt time.Time `json:"created_at"`

	// UpdatedAt is when the app was last modified
	UpdatedAt time.Time `json:"updated_at"`
}

App represents a tenant/workspace in the multi-app system.

func FromContext

func FromContext(ctx context.Context) *App

FromContext extracts the current app from the context. Returns nil if no app is set.

func (*App) ParseConfig

func (a *App) ParseConfig() (map[string]any, error)

ParseConfig parses the ConfigJSON field into a config.Config struct. This is a forward declaration - actual implementation depends on config package.

type SQLStore

type SQLStore struct {
	// contains filtered or unexported fields
}

SQLStore implements Store using a SQL database.

func NewSQLStore

func NewSQLStore(db *sql.DB, dialect string) (*SQLStore, error)

NewSQLStore creates a new SQL-based app store.

func (*SQLStore) Create

func (s *SQLStore) Create(ctx context.Context, app *App) (*App, error)

Create creates a new app.

func (*SQLStore) Delete

func (s *SQLStore) Delete(ctx context.Context, id string) error

Delete removes an app by ID.

func (*SQLStore) Exists

func (s *SQLStore) Exists(ctx context.Context, id string) (bool, error)

Exists checks if an app exists.

func (*SQLStore) Get

func (s *SQLStore) Get(ctx context.Context, id string) (*App, error)

Get retrieves an app by ID.

func (*SQLStore) List

func (s *SQLStore) List(ctx context.Context) ([]*App, error)

List returns all apps.

func (*SQLStore) Update

func (s *SQLStore) Update(ctx context.Context, app *App) error

Update updates an existing app.

type Store

type Store interface {
	// Create creates a new app and returns it with generated ID if not provided.
	Create(ctx context.Context, app *App) (*App, error)

	// Get retrieves an app by ID.
	Get(ctx context.Context, id string) (*App, error)

	// List returns all apps.
	List(ctx context.Context) ([]*App, error)

	// Update updates an existing app's configuration.
	Update(ctx context.Context, app *App) error

	// Delete removes an app by ID.
	Delete(ctx context.Context, id string) error

	// Exists checks if an app with the given ID exists.
	Exists(ctx context.Context, id string) (bool, error)
}

Store provides CRUD operations for apps.

Jump to

Keyboard shortcuts

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