model

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessLevel

type AccessLevel string

AccessLevel represents the level of access a user has to a conversation group.

const (
	AccessLevelOwner   AccessLevel = "owner"
	AccessLevelManager AccessLevel = "manager"
	AccessLevelWriter  AccessLevel = "writer"
	AccessLevelReader  AccessLevel = "reader"
)

func (AccessLevel) IsAtLeast

func (a AccessLevel) IsAtLeast(level AccessLevel) bool

IsAtLeast returns true if the access level is at least the given level.

type Attachment

type Attachment struct {
	ID          uuid.UUID  `json:"id"                   gorm:"primaryKey;type:uuid"`
	StorageKey  *string    `json:"storageKey,omitempty"`
	Filename    *string    `json:"filename,omitempty"`
	ContentType string     `json:"contentType"          gorm:"not null"`
	Size        *int64     `json:"size,omitempty"`
	SHA256      *string    `json:"sha256,omitempty"`
	UserID      string     `json:"userId"               gorm:"not null"`
	EntryID     *uuid.UUID `json:"entryId,omitempty"    gorm:"type:uuid"`
	Status      string     `json:"status"               gorm:"not null;default:'ready'"`
	SourceURL   *string    `json:"sourceUrl,omitempty"`
	ExpiresAt   *time.Time `json:"expiresAt,omitempty"`
	CreatedAt   time.Time  `json:"createdAt"            gorm:"not null;default:now()"`
	ArchivedAt  *time.Time `json:"archivedAt,omitempty"`
}

Attachment represents file attachment metadata.

func (Attachment) TableName

func (Attachment) TableName() string

type Channel

type Channel string

Channel represents the type of entry channel.

const (
	ChannelHistory Channel = "history"
	ChannelContext Channel = "context"
	ChannelJournal Channel = "journal"
)

type Conversation

type Conversation struct {
	ID                      string                 `json:"id"                                gorm:"primaryKey;type:text"`
	Title                   []byte                 `json:"-"                                 gorm:"type:bytea"` // encrypted
	OwnerUserID             string                 `json:"ownerUserId"                       gorm:"not null"`
	ClientID                string                 `json:"-"                                 gorm:"not null"`
	AgentID                 *string                `json:"agentId,omitempty"`
	Metadata                map[string]interface{} `json:"metadata"                          gorm:"type:jsonb;serializer:json;not null;default:'{}'"` // JSONB
	ConversationGroupID     uuid.UUID              `json:"-"                                 gorm:"not null;type:uuid"`
	ConversationGroup       *ConversationGroup     `json:"-"                                 gorm:"foreignKey:ConversationGroupID"`
	ForkedAtEntryID         *uuid.UUID             `json:"forkedAtEntryId,omitempty"         gorm:"-"`
	ForkedAtConversationID  *string                `json:"forkedAtConversationId,omitempty"  gorm:"-"`
	StartedByConversationID *string                `json:"startedByConversationId,omitempty" gorm:"type:text"`
	StartedByEntryID        *uuid.UUID             `json:"startedByEntryId,omitempty"        gorm:"type:uuid"`
	CreatedAt               time.Time              `json:"createdAt"                         gorm:"not null;default:now()"`
	UpdatedAt               time.Time              `json:"updatedAt"                         gorm:"not null;default:now()"`
	VectorizedAt            *time.Time             `json:"vectorizedAt,omitempty"`
	ArchivedAt              *time.Time             `json:"archivedAt,omitempty"`
}

Conversation represents a single conversation within a group.

func (Conversation) TableName

func (Conversation) TableName() string

type ConversationAncestry added in v0.0.6

type ConversationAncestry struct {
	ConversationGroupID      uuid.UUID  `json:"-"                         gorm:"primaryKey;type:uuid"`
	DescendantConversationID string     `json:"descendantConversationId"  gorm:"primaryKey;type:text"`
	AncestorConversationID   string     `json:"ancestorConversationId"    gorm:"primaryKey;type:text"`
	Depth                    int        `json:"depth"                     gorm:"not null"`
	BeforeEntryID            *uuid.UUID `json:"beforeEntryId,omitempty"   gorm:"type:uuid"`
	ForkedAtEntryID          *uuid.UUID `json:"forkedAtEntryId,omitempty" gorm:"type:uuid"`
}

ConversationAncestry materializes the visible fork path for a conversation.

func (ConversationAncestry) TableName added in v0.0.6

func (ConversationAncestry) TableName() string

type ConversationAncestryFilter

type ConversationAncestryFilter string

ConversationAncestryFilter controls whether list operations return top-level or child conversations.

const (
	ConversationAncestryRoots    ConversationAncestryFilter = "roots"
	ConversationAncestryChildren ConversationAncestryFilter = "children"
	ConversationAncestryAll      ConversationAncestryFilter = "all"
)

type ConversationAncestrySegment added in v0.0.6

type ConversationAncestrySegment struct {
	ConversationID  string
	Depth           int
	BeforeEntryID   *uuid.UUID
	ForkedAtEntryID *uuid.UUID
}

ConversationAncestrySegment is the datastore-neutral ancestry row shape used to construct a descendant's materialized fork path before mapping it back to a store-specific representation.

func BuildConversationAncestrySegments added in v0.0.6

func BuildConversationAncestrySegments(convID string, parentRows []ConversationAncestrySegment, forkedAtEntryID *uuid.UUID, anchorOwnerDepth *int) ([]ConversationAncestrySegment, error)

BuildConversationAncestrySegments returns the complete ancestry path for a new conversation. It always includes the depth-0 self segment. When parentRows is non-empty, it copies the parent's already-materialized closure, increments depths, records the direct fork anchor on the copied parent self row, and applies the exclusive boundary to the ancestor segment that owns the anchor.

type ConversationGroup

type ConversationGroup struct {
	ID         uuid.UUID  `json:"id"                   gorm:"primaryKey;type:uuid"`
	CreatedAt  time.Time  `json:"createdAt"            gorm:"not null;default:now()"`
	ArchivedAt *time.Time `json:"archivedAt,omitempty"`
}

ConversationGroup is the root of a fork tree.

func (ConversationGroup) TableName

func (ConversationGroup) TableName() string

type ConversationListMode

type ConversationListMode string

ConversationListMode controls which conversations from each fork tree are returned.

const (
	ListModeAll        ConversationListMode = "all"
	ListModeRoots      ConversationListMode = "roots"
	ListModeLatestFork ConversationListMode = "latest-fork"
)

type ConversationMembership

type ConversationMembership struct {
	ConversationGroupID uuid.UUID   `json:"-"           gorm:"primaryKey;type:uuid"`
	UserID              string      `json:"userId"      gorm:"primaryKey"`
	AccessLevel         AccessLevel `json:"accessLevel" gorm:"not null"`
	CreatedAt           time.Time   `json:"createdAt"   gorm:"not null;default:now()"`
}

ConversationMembership tracks per-user access to a conversation group.

func (ConversationMembership) TableName

func (ConversationMembership) TableName() string

type Entry

type Entry struct {
	ID                  uuid.UUID  `json:"id"                       gorm:"primaryKey;type:uuid"`
	ConversationID      string     `json:"conversationId"           gorm:"not null;type:text"`
	ConversationGroupID uuid.UUID  `json:"-"                        gorm:"primaryKey;type:uuid"`
	UserID              *string    `json:"userId,omitempty"`
	ClientID            *string    `json:"clientId,omitempty"`
	AgentID             *string    `json:"agentId,omitempty"`
	Channel             Channel    `json:"channel"                  gorm:"not null"`
	Epoch               *int64     `json:"epoch,omitempty"`
	Seq                 *uint32    `json:"seq,omitempty"`
	ContentType         string     `json:"contentType"              gorm:"not null"`
	Content             []byte     `json:"-"                        gorm:"type:bytea;not null"` // encrypted
	IndexedContent      *string    `json:"indexedContent,omitempty"`
	IndexedAt           *time.Time `json:"indexedAt,omitempty"`
	CreatedAt           time.Time  `json:"createdAt"                gorm:"not null;default:now()"`
}

Entry represents a message or context entry in a conversation.

func (Entry) MarshalJSON

func (e Entry) MarshalJSON() ([]byte, error)

MarshalJSON serializes Entry to JSON, including the decrypted content as a raw JSON value. Content is stored as []byte with json:"-" to prevent GORM from leaking encrypted bytes, but API responses need to include the decrypted content.

func (Entry) TableName

func (Entry) TableName() string

func (*Entry) UnmarshalJSON

func (e *Entry) UnmarshalJSON(data []byte) error

UnmarshalJSON restores Entry from JSON including the decrypted content field. This keeps cache round-trips lossless for model.Entry values.

type Memory

type Memory struct {
	// ID is the primary key (UUID).
	ID uuid.UUID `json:"id" gorm:"primaryKey;type:uuid;default:gen_random_uuid()"`

	// Namespace is the RS-encoded namespace string (percent-encoded segments joined with \x1e).
	// Clients always work with []string; this field is for storage only.
	Namespace string `json:"-" gorm:"not null"`

	// Key is the memory key, unique within a namespace (active rows only).
	Key string `json:"key" gorm:"not null"`

	// ValueEncrypted is the AES-256-GCM encrypted JSON value. Decrypted on read.
	// NULL for tombstones (deleted/expired rows after eviction).
	ValueEncrypted []byte `json:"-" gorm:"column:value_encrypted"`

	// PolicyAttributes contains plaintext OPA-extracted attributes for server-side filtering.
	// Never returned to clients.
	PolicyAttributes map[string]interface{} `json:"-" gorm:"type:jsonb;serializer:json;column:policy_attributes"`

	// IndexedContent contains caller-provided redacted text keyed by field path.
	IndexedContent map[string]string `json:"-" gorm:"type:jsonb;serializer:json;column:indexed_content"`

	// Kind records whether this row was a first write (0=add) or a subsequent write (1=update).
	// Set at write time; never changed.
	Kind int16 `json:"-" gorm:"not null;default:0;column:kind"`

	// CreatedAt is when this row was written.
	CreatedAt time.Time `json:"createdAt" gorm:"not null;default:now()"`

	// ExpiresAt is the optional TTL expiry time. NULL means no expiry.
	ExpiresAt *time.Time `json:"expiresAt" gorm:"column:expires_at"`

	// ArchivedAt is set when the row is archived (superseded or key deleted).
	ArchivedAt *time.Time `json:"-" gorm:"column:archived_at"`

	// DeletedReason records why the row was deleted. NULL=active, 0=updated, 1=deleted, 2=expired.
	DeletedReason *int16 `json:"-" gorm:"column:deleted_reason"`

	// IndexedAt tracks vector index sync state. NULL means pending indexing.
	IndexedAt *time.Time `json:"-" gorm:"column:indexed_at"`
}

Memory is a single namespaced episodic memory item. Each row in the memories table represents one write event. The active value of a (namespace, key) pair is the row where ArchivedAt IS NULL.

func (Memory) TableName

func (Memory) TableName() string

TableName implements gorm.Tabler.

type MemoryVector

type MemoryVector struct {
	// MemoryID references the memories.id.
	MemoryID uuid.UUID `gorm:"not null;primaryKey;column:memory_id"`

	// FieldName is the JSON field name within the memory value that was embedded.
	FieldName string `gorm:"not null;primaryKey;column:field_name"`

	// Namespace is a redundant copy of the memory's encoded namespace for prefix filtering.
	Namespace string `gorm:"not null;column:namespace"`

	// PolicyAttributes is a redundant copy of the memory's policy_attributes for filtering.
	PolicyAttributes map[string]interface{} `gorm:"type:jsonb;serializer:json;column:policy_attributes"`
}

MemoryVector stores the embedding for a single (memory_id, field_name) pair. One Memory can produce multiple MemoryVector rows (one per indexed field).

func (MemoryVector) TableName

func (MemoryVector) TableName() string

TableName implements gorm.Tabler.

type OwnershipTransfer

type OwnershipTransfer struct {
	ID                  uuid.UUID `json:"id"         gorm:"primaryKey;type:uuid"`
	ConversationGroupID uuid.UUID `json:"-"          gorm:"not null;type:uuid"`
	FromUserID          string    `json:"fromUserId" gorm:"not null"`
	ToUserID            string    `json:"toUserId"   gorm:"not null"`
	CreatedAt           time.Time `json:"createdAt"  gorm:"not null;default:now()"`
}

OwnershipTransfer represents a pending conversation ownership transfer.

func (OwnershipTransfer) TableName

func (OwnershipTransfer) TableName() string

type Task

type Task struct {
	ID         uuid.UUID              `json:"id"                  gorm:"primaryKey;type:uuid"`
	TaskName   *string                `json:"taskName,omitempty"  gorm:"unique"`
	TaskType   string                 `json:"taskType"            gorm:"not null"`
	TaskBody   map[string]interface{} `json:"taskBody"            gorm:"type:jsonb;serializer:json;not null"`
	CreatedAt  time.Time              `json:"createdAt"           gorm:"not null;default:now()"`
	RetryAt    time.Time              `json:"retryAt"             gorm:"not null;default:now()"`
	LastError  *string                `json:"lastError,omitempty"`
	RetryCount int                    `json:"retryCount"          gorm:"not null;default:0"`
}

Task represents a background task in the task queue.

func (Task) TableName

func (Task) TableName() string

Jump to

Keyboard shortcuts

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