models

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIKey

type APIKey struct {
	ID          APIKeyID    `json:"id"`
	WorkspaceID WorkspaceID `json:"workspace_id"`
	Name        string      `json:"name"`
	KeyPrefix   string      `json:"key_prefix"`
	// KeyHash is the internal lookup value. It must never cross the
	// wire — handlers marshal APIKey directly, so the json:"-" tag is
	// the only guard. See apikey_test.go's golden test.
	KeyHash   string     `json:"-"`
	ExpiresAt *time.Time `json:"expires_at,omitempty"`
	RevokedAt *time.Time `json:"revoked_at,omitempty"`
	CreatedAt time.Time  `json:"created_at"`
}

type APIKeyCreated

type APIKeyCreated struct {
	Plaintext string `json:"plaintext"`
	Record    APIKey `json:"record"`
}

APIKeyCreated is the one-time response from creating an API key. Plaintext is the full token and is never returned again.

type APIKeyID

type APIKeyID string

type APIKeySummary

type APIKeySummary struct {
	ID          APIKeyID    `json:"id"`
	WorkspaceID WorkspaceID `json:"workspace_id"`
	Name        string      `json:"name"`
	KeyPrefix   string      `json:"key_prefix"`
	ExpiresAt   *time.Time  `json:"expires_at,omitempty"`
	RevokedAt   *time.Time  `json:"revoked_at,omitempty"`
	CreatedAt   time.Time   `json:"created_at"`
}

type Brain

type Brain struct {
	ID          EntityID    `json:"id"`
	WorkspaceID WorkspaceID `json:"workspace_id"`
	Slug        Slug        `json:"slug"`
	SoulSlug    Slug        `json:"soul_slug"`
	PersonaSlug Slug        `json:"persona_slug"`
	RuleSlugs   []Slug      `json:"rule_slugs"`
	ModelPrefs  *ModelPrefs `json:"model_prefs,omitempty"`
	CreatedAt   time.Time   `json:"created_at"`
	UpdatedAt   time.Time   `json:"updated_at"`
}

type ComposeBody

type ComposeBody struct {
	Source      ComposeSource `json:"source"`
	ModelPrefs  *ModelPrefs   `json:"model_prefs,omitempty"`
	ProjectSlug Slug          `json:"project_slug,omitempty"`
	Task        string        `json:"task,omitempty"`
}

ComposeBody is the body of POST /api/v1/compose. Mirrors ComposeRequest minus workspace_id — the workspace comes from auth, never from the body. Project in the body acts as a fallback when the corresponding header is absent.

type ComposeRequest

type ComposeRequest struct {
	WorkspaceID WorkspaceID   `json:"workspace_id"`
	Source      ComposeSource `json:"source"`
	ModelPrefs  *ModelPrefs   `json:"model_prefs,omitempty"`
	ProjectSlug Slug          `json:"project_slug,omitempty"`
	Task        string        `json:"task,omitempty"`
}

type ComposeResponse

type ComposeResponse struct {
	Prompt        string        `json:"prompt"`
	Soul          Slug          `json:"soul"`
	Persona       Slug          `json:"persona"`
	Brain         Slug          `json:"brain"`
	Rules         []Slug        `json:"rules"`
	ModelPrefs    *ModelPrefs   `json:"model_prefs,omitempty"`
	TokenEstimate TokenEstimate `json:"token_estimate"`
	Warnings      []string      `json:"warnings"`
}

type ComposeSource

type ComposeSource struct {
	Kind        ComposeSourceKind `json:"kind"`
	BrainSlug   Slug              `json:"brain_slug,omitempty"`
	PersonaSlug Slug              `json:"persona_slug,omitempty"`
	RuleSlugs   []Slug            `json:"rule_slugs,omitempty"`
}

ComposeSource is a discriminated union — brain, persona, and state resolution are mutually exclusive. The Kind field selects the variant.

RuleSlugs is meaningful only when Kind == ComposeFromPersona. When set, it overrides both the state-derived rule chain and the persona's BundledRules so an ad-hoc caller (today: `brainjar shell --persona X --rules a,b`) can pin an exact rule list without touching state.

type ComposeSourceKind

type ComposeSourceKind string
const (
	ComposeFromBrain   ComposeSourceKind = "brain"
	ComposeFromPersona ComposeSourceKind = "persona"
	ComposeFromState   ComposeSourceKind = "state"
)

type ContentType

type ContentType string
const (
	ContentTypeSoul    ContentType = "soul"
	ContentTypePersona ContentType = "persona"
	ContentTypeRule    ContentType = "rule"
)

type ContentVersion

type ContentVersion struct {
	ID          EntityID        `json:"id"`
	ContentType ContentType     `json:"content_type"`
	WorkspaceID WorkspaceID     `json:"workspace_id"`
	Slug        Slug            `json:"slug"`
	Version     int             `json:"version"`
	Content     string          `json:"content,omitempty"`
	Metadata    json.RawMessage `json:"metadata,omitempty"`
	CreatedAt   time.Time       `json:"created_at"`
}

ContentVersion is a historical snapshot of a content entity. Stores hold old versions only — the current version lives in the live entity table. For rules, Content is empty and Metadata holds the entries as JSON.

type CreateAPIKeyRequest

type CreateAPIKeyRequest struct {
	Name string `json:"name"`
}

CreateAPIKeyRequest is the body of POST /api/v1/api-keys.

type CreateWorkspaceRequest

type CreateWorkspaceRequest struct {
	Name string `json:"name"`
}

CreateWorkspaceRequest is the body of POST /api/v1/workspaces.

type EffectiveState

type EffectiveState struct {
	Soul    string   `json:"soul"`
	Persona string   `json:"persona"`
	Rules   []string `json:"rules"`
}

EffectiveState is the resolved state after merging all applicable layers.

type EntityID

type EntityID string

type LayerOverride

type LayerOverride struct {
	WorkspaceID   WorkspaceID `json:"workspace_id"`
	ScopeType     ScopeType   `json:"scope_type"`
	ReferenceID   string      `json:"reference_id"`
	SoulSlug      *string     `json:"soul_slug,omitempty"`
	PersonaSlug   *string     `json:"persona_slug,omitempty"`
	RulesToAdd    []string    `json:"rules_to_add"`
	RulesToRemove []string    `json:"rules_to_remove"`
	CreatedAt     time.Time   `json:"created_at"`
	UpdatedAt     time.Time   `json:"updated_at"`
}

LayerOverride is a single row in the precedence chain, keyed by (WorkspaceID, ScopeType, ReferenceID). Three-way semantics for single-valued fields via *string:

  • nil = absent (no opinion, NULL in SQL)
  • &"" = inherit (clear override, empty string in SQL)
  • &"cto" = set (value in SQL)

type ListAPIKeys

type ListAPIKeys struct {
	APIKeys []APIKeySummary `json:"api_keys"`
}

type ListBrains

type ListBrains struct {
	Brains []Brain `json:"brains"`
}

type ListPersonas

type ListPersonas struct {
	Personas []Persona `json:"personas"`
}

type ListRules

type ListRules struct {
	Rules []Rule `json:"rules"`
}

type ListSouls

type ListSouls struct {
	Souls []Soul `json:"souls"`
}

type ListVersions

type ListVersions struct {
	Versions []VersionSummary `json:"versions"`
}

type ListWorkspaces

type ListWorkspaces struct {
	Workspaces []Workspace `json:"workspaces"`
}

type ModelPrefs

type ModelPrefs struct {
	Model          string         `json:"model,omitempty"`
	Temperature    *float64       `json:"temperature,omitempty"`
	MaxTokens      *int           `json:"max_tokens,omitempty"`
	PlatformExtras map[string]any `json:"platform_extras,omitempty"`
}

ModelPrefs controls how a brain should be instantiated. All fields are optional — omitted fields inherit runtime defaults. Only platform-agnostic fields are first-class. Provider-specific params live in PlatformExtras.

ModelPrefs is attached to Brain as the default, but ComposeRequest can supply a per-call override and ComposeResponse echoes the resolved value.

func (*ModelPrefs) IsZero

func (m *ModelPrefs) IsZero() bool

IsZero returns true when no preferences are set.

type Persona

type Persona struct {
	ID           EntityID    `json:"id"`
	WorkspaceID  WorkspaceID `json:"workspace_id"`
	Slug         Slug        `json:"slug"`
	Content      string      `json:"content"`
	BundledRules []Slug      `json:"bundled_rules"`
	CreatedAt    time.Time   `json:"created_at"`
	UpdatedAt    time.Time   `json:"updated_at"`
}

type RenameWorkspaceRequest

type RenameWorkspaceRequest struct {
	Name string `json:"name"`
}

RenameWorkspaceRequest is the body of PATCH /api/v1/workspaces/{id}.

type Rule

type Rule struct {
	ID          EntityID    `json:"id"`
	WorkspaceID WorkspaceID `json:"workspace_id"`
	Slug        Slug        `json:"slug"`
	Entries     []RuleEntry `json:"entries"`
	CreatedAt   time.Time   `json:"created_at"`
	UpdatedAt   time.Time   `json:"updated_at"`
}

type RuleEntry

type RuleEntry struct {
	SortKey int    `json:"sort_key"`
	Content string `json:"content"`
}

type ScopeType

type ScopeType string
const (
	ScopeWorkspace ScopeType = "workspace"
	ScopeProject   ScopeType = "project"
)

type SetStateRequest

type SetStateRequest struct {
	SoulSlug      *string  `json:"soul_slug,omitempty"`
	PersonaSlug   *string  `json:"persona_slug,omitempty"`
	RulesToAdd    []string `json:"rules_to_add,omitempty"`
	RulesToRemove []string `json:"rules_to_remove,omitempty"`
}

SetStateRequest is the body of PUT /api/v1/state. The target scope is derived from tool args (project > workspace), not from the body. Server-owned fields (workspace_id, scope_type, reference_id, timestamps) never appear here. Slug pointer semantics match LayerOverride: nil = absent, &"" = clear, &"foo" = set.

type Slug

type Slug string

func MustSlug

func MustSlug(raw string) Slug

MustSlug panics on invalid input. Use only in tests and hardcoded constants.

func ParseSlug

func ParseSlug(raw string) (Slug, error)

ParseSlug validates and returns a Slug. Returns an error if the input does not match the slug pattern (lowercase letter start, then lowercase letters, digits, and hyphens), or exceeds maxSlugLen.

type Soul

type Soul struct {
	ID          EntityID    `json:"id"`
	WorkspaceID WorkspaceID `json:"workspace_id"`
	Slug        Slug        `json:"slug"`
	Content     string      `json:"content"`
	CreatedAt   time.Time   `json:"created_at"`
	UpdatedAt   time.Time   `json:"updated_at"`
}

type StateResponse

type StateResponse struct {
	Effective *EffectiveState `json:"effective"`
	Layers    []LayerOverride `json:"layers"`
}

StateResponse is returned by GET/PUT /api/v1/state. The layers slice includes every applicable scope in precedence order (workspace first).

type StatusResponse

type StatusResponse struct {
	WorkspaceID WorkspaceID     `json:"workspace_id"`
	Effective   *EffectiveState `json:"effective"`
	Layers      []LayerOverride `json:"layers"`
}

StatusResponse is a workspace-level summary: effective state and the full layer chain. Unlike GET /state (which is scope-aware), this is always workspace scope — a dashboard overview.

type TokenEstimate

type TokenEstimate struct {
	Soul    int `json:"soul"`
	Persona int `json:"persona"`
	Rules   int `json:"rules"`
	Task    int `json:"task"`
	Total   int `json:"total"`
}

type UpsertBrainRequest

type UpsertBrainRequest struct {
	SoulSlug    Slug        `json:"soul_slug"`
	PersonaSlug Slug        `json:"persona_slug"`
	RuleSlugs   []Slug      `json:"rule_slugs"`
	ModelPrefs  *ModelPrefs `json:"model_prefs,omitempty"`
}

UpsertBrainRequest is the body of PUT /api/v1/brains/{slug}.

type UpsertPersonaRequest

type UpsertPersonaRequest struct {
	Content      string `json:"content"`
	BundledRules []Slug `json:"bundled_rules"`
}

UpsertPersonaRequest is the body of PUT /api/v1/personas/{slug}.

type UpsertRuleRequest

type UpsertRuleRequest struct {
	Entries []RuleEntry `json:"entries"`
}

UpsertRuleRequest is the body of PUT /api/v1/rules/{slug}.

type UpsertSoulRequest

type UpsertSoulRequest struct {
	Content string `json:"content"`
}

UpsertSoulRequest is the body of PUT /api/v1/souls/{slug}. The slug is taken from the path, the workspace from auth — neither appears here.

type ValidationError

type ValidationError struct {
	Message string
}

ValidationError is returned when input fails validation.

func (*ValidationError) Error

func (e *ValidationError) Error() string

type VersionSummary

type VersionSummary struct {
	Version   int       `json:"version"`
	CreatedAt time.Time `json:"created_at"`
}

type Workspace

type Workspace struct {
	ID        WorkspaceID `json:"id"`
	Name      string      `json:"name"`
	CreatedAt time.Time   `json:"created_at"`
	UpdatedAt time.Time   `json:"updated_at"`
}

type WorkspaceID

type WorkspaceID string

Jump to

Keyboard shortcuts

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