assets

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package assets persists multimodal asset lifecycle state.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildAttachmentBlock

func BuildAttachmentBlock(items []Asset) string

func WithAttachmentBlock

func WithAttachmentBlock(userText string, items []Asset) string

Types

type Asset

type Asset struct {
	ID                string         `json:"id"`
	IdentityID        string         `json:"identity_id"`
	SourceKind        SourceKind     `json:"source_kind"`
	SourceRef         string         `json:"source_ref"`
	ThreadID          string         `json:"thread_id"`
	Scope             Scope          `json:"scope"`
	Modality          Modality       `json:"modality"`
	Status            Status         `json:"status"`
	FileName          string         `json:"file_name"`
	MIMEType          string         `json:"mime_type"`
	DeclaredSizeBytes int64          `json:"declared_size_bytes"`
	SizeBytes         int64          `json:"size_bytes"`
	ContentHash       string         `json:"content_hash"`
	ObjectBucket      string         `json:"object_bucket"`
	ObjectKey         string         `json:"object_key"`
	ObjectETag        string         `json:"object_etag"`
	DocumentID        string         `json:"document_id"`
	Summary           string         `json:"summary"`
	Metadata          map[string]any `json:"metadata"`
	ErrorCode         string         `json:"error_code"`
	ErrorMessage      string         `json:"error_message"`
	CreatedAt         time.Time      `json:"created_at,omitempty"`
	UploadedAt        time.Time      `json:"uploaded_at,omitempty"`
	AcceptedAt        time.Time      `json:"accepted_at,omitempty"`
	ProcessedAt       time.Time      `json:"processed_at,omitempty"`
	SearchableAt      time.Time      `json:"searchable_at,omitempty"`
	CompletedAt       time.Time      `json:"completed_at,omitempty"`
	DeletedAt         time.Time      `json:"deleted_at,omitempty"`
	UpdatedAt         time.Time      `json:"updated_at,omitempty"`
}

Asset is the API-facing view of a persisted multimodal asset record.

type AudioProcessor

type AudioProcessor struct {
	Objects    objectstore.Store
	Config     STTConfig
	HTTPClient *http.Client
}

func NewAudioProcessor

func NewAudioProcessor(objects objectstore.Store, cfg STTConfig) *AudioProcessor

func (*AudioProcessor) ProcessAsset

func (p *AudioProcessor) ProcessAsset(ctx context.Context, asset Asset) (Result, error)

type CreateRequest

type CreateRequest struct {
	IdentityID        string
	SourceKind        SourceKind
	SourceRef         string
	ThreadID          string
	Scope             Scope
	Modality          Modality
	FileName          string
	MIMEType          string
	DeclaredSizeBytes int64
	ObjectBucket      string
	ObjectKey         string
	Metadata          map[string]any
}

CreateRequest carries the fields needed to create a presigned asset record.

type DocumentIngestor

type DocumentIngestor interface {
	IngestPath(ctx context.Context, req documents.IngestRequest, path string) (*documents.Job, error)
}

type DocumentProcessor

type DocumentProcessor struct {
	Objects objectstore.Store
	Ingest  DocumentIngestor
}

func (*DocumentProcessor) ProcessAsset

func (p *DocumentProcessor) ProcessAsset(ctx context.Context, asset Asset) (Result, error)

type ImageProcessor

type ImageProcessor struct {
	Objects    objectstore.Store
	Config     VisionConfig
	HTTPClient *http.Client
}

func NewImageProcessor

func NewImageProcessor(objects objectstore.Store, cfg VisionConfig) *ImageProcessor

func (*ImageProcessor) ProcessAsset

func (p *ImageProcessor) ProcessAsset(ctx context.Context, asset Asset) (Result, error)

type Limits

type Limits struct {
	MaxDocumentBytes int64
	MaxImageBytes    int64
	MaxAudioBytes    int64
}

func (Limits) Validate

func (l Limits) Validate(modality Modality, fileName string, size int64) error

type Modality

type Modality string

Modality describes the asset's content type class.

const (
	ModalityDocument Modality = "document"
	ModalityImage    Modality = "image"
	ModalityAudio    Modality = "audio"
	ModalityUnknown  Modality = "unknown"
)

Supported asset modalities.

func InferModality

func InferModality(fileName, mimeType string) Modality

type PresignRequest

type PresignRequest struct {
	IdentityID        string     `json:"identity_id"`
	SourceKind        SourceKind `json:"source_kind"`
	ThreadID          string     `json:"thread_id"`
	FileName          string     `json:"file_name"`
	MIMEType          string     `json:"mime_type"`
	DeclaredSizeBytes int64      `json:"size_bytes"`
	ModalityHint      Modality   `json:"modality_hint"`
}

type PresignResponse

type PresignResponse struct {
	Asset  Asset                    `json:"asset"`
	Upload objectstore.PresignedPut `json:"upload"`
}

type Processor

type Processor interface {
	ProcessAsset(ctx context.Context, asset Asset) (Result, error)
}

type ProcessorSet

type ProcessorSet struct {
	Document Processor
	Image    Processor
	Audio    Processor
}

func (ProcessorSet) For

func (p ProcessorSet) For(modality Modality) Processor

type Result

type Result struct {
	Status     Status
	DocumentID string
	Summary    string
	Metadata   map[string]any
}

Result carries processing output for an asset.

type STTConfig

type STTConfig struct {
	BaseURL    string
	Model      string
	Language   string
	TimeoutSec int
}

STTConfig configures the speech-to-text sidecar used for audio assets.

type Scope

type Scope string

Scope describes where the asset is visible.

const (
	ScopeThread  Scope = "thread"
	ScopeLibrary Scope = "library"
)

Supported asset scopes.

type Service

type Service struct {
	Store      StoreBackend
	Objects    objectstore.Store
	Processors ProcessorSet
	Limits     Limits
	Bucket     string
	PresignTTL time.Duration
}

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, identityID, assetID string) (Asset, error)

func (*Service) Finalize

func (s *Service) Finalize(ctx context.Context, identityID, assetID string) (Asset, error)

func (*Service) GetForIdentity

func (s *Service) GetForIdentity(ctx context.Context, id, identityID string) (Asset, error)

func (*Service) IngestTelegramFile

func (s *Service) IngestTelegramFile(ctx context.Context, req TelegramIngestRequest) (Asset, error)

func (*Service) ListForThread

func (s *Service) ListForThread(ctx context.Context, identityID, threadID string) ([]Asset, error)

func (*Service) Presign

func (s *Service) Presign(ctx context.Context, req PresignRequest) (PresignResponse, error)

func (*Service) Promote

func (s *Service) Promote(ctx context.Context, identityID, assetID string) (Asset, error)

func (*Service) Retry

func (s *Service) Retry(ctx context.Context, identityID, assetID string) (Asset, error)

type SourceKind

type SourceKind string

SourceKind identifies where an asset upload was initiated.

const (
	SourceWeb      SourceKind = "web"
	SourceTelegram SourceKind = "telegram"
	SourceCLI      SourceKind = "cli"
)

Supported asset source kinds.

type Status

type Status string

Status is the durable lifecycle state for a multimodal asset.

const (
	StatusCreated    Status = "created"
	StatusPresigned  Status = "presigned"
	StatusUploaded   Status = "uploaded"
	StatusAccepted   Status = "accepted"
	StatusProcessing Status = "processing"
	StatusSearchable Status = "searchable"
	StatusEmbedding  Status = "embedding"
	StatusComplete   Status = "complete"
	StatusFailed     Status = "failed"
	StatusRefused    Status = "refused"
	StatusDeleted    Status = "deleted"
	StatusCanceled   Status = "canceled"
)

Asset lifecycle statuses.

type Store

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

Store persists multimodal asset lifecycle state in Postgres.

func NewStore

func NewStore(db sqlc.DBTX) *Store

NewStore builds a Postgres-backed asset store.

func (*Store) Create

func (s *Store) Create(ctx context.Context, req CreateRequest) (Asset, error)

Create inserts a new presigned asset record.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, id, identityID string) (Asset, error)

Delete soft-deletes an asset.

func (*Store) GetForIdentity

func (s *Store) GetForIdentity(ctx context.Context, id, identityID string) (Asset, error)

GetForIdentity returns a non-deleted asset by asset and identity id.

func (*Store) ListForThread

func (s *Store) ListForThread(ctx context.Context, identityID, threadID string) ([]Asset, error)

ListForThread returns non-deleted assets in thread order.

func (*Store) MarkAccepted

func (s *Store) MarkAccepted(ctx context.Context, id, identityID string, size int64, hash, mimeType string) (Asset, error)

MarkAccepted records validation of an uploaded asset.

func (*Store) MarkUploaded

func (s *Store) MarkUploaded(ctx context.Context, id, identityID string, size int64, etag string) (Asset, error)

MarkUploaded records object storage upload completion.

func (*Store) Promote

func (s *Store) Promote(ctx context.Context, id, identityID string) (Asset, error)

Promote moves an asset into the operator library scope.

func (*Store) SetResult

func (s *Store) SetResult(ctx context.Context, id, identityID string, result Result) (Asset, error)

SetResult records processing output and clears prior error fields.

func (*Store) SetStatus

func (s *Store) SetStatus(ctx context.Context, id, identityID string, status Status, code, message string) (Asset, error)

SetStatus records a lifecycle state transition and optional error fields.

type StoreBackend

type StoreBackend interface {
	Create(context.Context, CreateRequest) (Asset, error)
	GetForIdentity(context.Context, string, string) (Asset, error)
	ListForThread(context.Context, string, string) ([]Asset, error)
	MarkUploaded(context.Context, string, string, int64, string) (Asset, error)
	MarkAccepted(context.Context, string, string, int64, string, string) (Asset, error)
	SetStatus(context.Context, string, string, Status, string, string) (Asset, error)
	SetResult(context.Context, string, string, Result) (Asset, error)
	Promote(context.Context, string, string) (Asset, error)
	Delete(context.Context, string, string) (Asset, error)
}

type TelegramIngestRequest

type TelegramIngestRequest struct {
	IdentityID string
	ChatID     int64
	MessageID  int
	FileID     string
	FileName   string
	MIMEType   string
	Modality   Modality
	SizeBytes  int64
	Reader     io.Reader
}

TelegramIngestRequest carries one Telegram media stream into the shared asset pipeline.

type VisionConfig

type VisionConfig struct {
	VisionCloud       bool
	Model             string
	MultimodalBaseURL string
	MultimodalModel   string
	FallbackModel     string
	OpenRouterBaseURL string
	OpenRouterAPIKey  string
	TimeoutSec        int
}

VisionConfig selects the image-analysis sidecar or cloud-compatible route.

Jump to

Keyboard shortcuts

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