threadstore

package
v0.13.2 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UploadStateStaged   = "staged"
	UploadStateLive     = "live"
	UploadStateDeleting = "deleting"

	UploadRefKindThread  = "thread"
	UploadRefKindStaging = "staging"

	UploadSourceFile     = "uploaded_file"
	UploadSourceLongText = "long_text"

	UploadAttemptReceiving = "receiving"
	UploadAttemptComplete  = "complete"
	UploadAttemptFailed    = "failed"

	UploadStagedOwnerItemLimit        = 100
	UploadStagedOwnerByteLimit        = int64(100 << 20)
	UploadLiveOwnerItemLimit          = 1000
	UploadLiveOwnerByteLimit          = int64(1 << 30)
	UploadLiveThreadItemLimit         = 1000
	UploadLiveThreadByteLimit         = int64(250 << 20)
	AttachmentClaimPolicyMaxCount     = 10
	AttachmentClaimPolicyMaxTurnBytes = int64(25 << 20)
)

Variables

View Source
var (
	ErrUploadIdempotencyConflict  = errors.New("upload idempotency conflict")
	ErrUploadInProgress           = errors.New("upload is still in progress")
	ErrUploadQuotaExceeded        = errors.New("upload quota exceeded")
	ErrLongTextAttachmentRequired = errors.New("long_text_attachment_required")
)
View Source
var ErrCanonicalThreadSettingsConflict = errors.New("canonical thread settings conflict")
View Source
var ErrExecutionAuthorityConflict = errors.New("execution authority conflicts with an existing request")
View Source
var ErrPinPositionConflict = errors.New("pinned conversations changed; refresh the list and try again")

Functions

func Backup added in v0.13.0

func Backup(ctx context.Context, source, destination string) error

Backup snapshots product storage while its service generation is closed.

func CurrentSchemaVersion

func CurrentSchemaVersion() int

CurrentSchemaVersion returns the product-only threadstore schema version.

func EncodeCursor

func EncodeCursor(c ThreadsCursor) string

EncodeCursor encodes a cursor as a URL-safe base64 string.

func Inspect added in v0.13.0

func Inspect(path string) (sqliteutil.Inspection, error)

Inspect checks a product store before any other owner begins an upgrade.

Types

type AttachmentClaimPolicy added in v0.11.0

type AttachmentClaimPolicy struct {
	OwnerUserHash      string
	CapabilityRevision string
	MaxCount           int
	MaxTurnBytes       int64
	SupportsLongText   bool
	Routes             map[string]string
}

type ComputerAccess added in v0.13.0

type ComputerAccess struct {
	Origins         []string `json:"origins"`
	Apps            []string `json:"apps"`
	AllowForeground bool     `json:"allow_foreground"`
}

ComputerAccess is product authorization for a thread, not runtime ownership. Forks start with the empty database default; no permission follows history.

func (ComputerAccess) Validate added in v0.13.0

func (a ComputerAccess) Validate() error

type ExecutionAuthority added in v0.11.0

type ExecutionAuthority struct {
	RequestKey        string
	ThreadID          string
	TurnID            string
	EndpointID        string
	NamespacePublicID string
	ChannelID         string
	UserPublicID      string
	UserEmail         string
	PermissionType    string
	CreatedAtUnixMs   int64
}

ExecutionAuthority is the minimum durable host fact needed to rebuild one provider execution after restart. PermissionType records admission policy for attribution; live tool authorization reads thread settings. It is not a second Agent lifecycle or transcript store; Floret remains authoritative for all execution state.

type ExecutionAuthorityCursor added in v0.13.0

type ExecutionAuthorityCursor struct {
	ThreadID   string
	RequestKey string
}

type PendingInputMigrationHandler added in v0.13.0

PendingInputMigrationHandler converts every supplied retired queue item into canonical Floret state. Returned authorities must correspond one-to-one with the records. The product migration commits those authorities and removes the retired source in the same transaction after the handler succeeds.

type PendingInputMigrationRecord added in v0.13.0

type PendingInputMigrationRecord struct {
	RequestID         string
	EndpointID        string
	ThreadID          string
	ModelID           string
	TextContent       string
	AttachmentsJSON   string
	ContextActionJSON string
	OptionsJSON       string
	SessionMetaJSON   string
	CreatedAtUnixMs   int64
}

PendingInputMigrationRecord is one retired product queue item presented only while an older threadstore is being upgraded. It is never current-schema state and cannot be created by production handlers.

type PendingInputMigrationSource added in v0.13.0

type PendingInputMigrationSource interface {
	GetThreadSettings(context.Context, string, string) (*ThreadSettings, error)
	LegacyPrimaryTargetID(context.Context, string, string) (string, error)
	GetThreadOwnedUpload(context.Context, string, string, string) (*UploadRecord, error)
}

PendingInputMigrationSource exposes only the current product facts needed to convert a retired queue item into Floret's canonical input contract.

type SQLiteCompactionPlan

type SQLiteCompactionPlan struct {
	ShouldCompact  bool
	UseIncremental bool
	PageSize       int64
	PageCount      int64
	FreelistCount  int64
	FreeBytes      int64
	PagesToRelease int64
}

func BuildSQLiteCompactionPlan

func BuildSQLiteCompactionPlan(stats SQLitePageStats) SQLiteCompactionPlan

type SQLitePageStats

type SQLitePageStats struct {
	PageSize       int64
	PageCount      int64
	FreelistCount  int64
	AutoVacuumMode int64
}

type Store

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

Store is a local SQLite-backed persistence layer for Redeven product data.

Notes: - Data is scoped by endpoint_id (env public id). It is intentionally shared within the same env for collaboration. - WAL is enabled to support concurrent reads while writing (multiple browser sessions).

func Open

func Open(path string) (*Store, error)

func OpenWithPendingInputMigration added in v0.13.0

func OpenWithPendingInputMigration(ctx context.Context, path string, migrate PendingInputMigrationHandler) (*Store, error)

OpenWithPendingInputMigration opens the current product store and gives the startup owner one atomic opportunity to convert retired queue inputs into canonical Floret state before their old table is removed.

func (*Store) AdoptCanonicalRootSettings added in v0.11.0

func (s *Store) AdoptCanonicalRootSettings(ctx context.Context, settings ThreadSettings) error

func (*Store) AuthorizeUploadStagingScope added in v0.11.0

func (s *Store) AuthorizeUploadStagingScope(ctx context.Context, endpointID, ownerUserHash, stagingScopeID, capabilityHash string, nowUnixMs int64) (UploadStagingScope, error)

func (*Store) ClaimStagedUploadsToThread added in v0.11.0

func (s *Store) ClaimStagedUploadsToThread(
	ctx context.Context,
	endpointID string,
	threadID string,
	uploadIDs []string,
	admission AttachmentClaimPolicy,
	scope UploadStagingScope,
) error

ClaimStagedUploadsToThread moves product-owned upload references from a transport staging scope to their canonical thread. It does not create a turn, queue item, admission receipt, or any other agent lifecycle state.

func (*Store) Close

func (s *Store) Close() error

func (*Store) CompleteUploadAttemptToStaging added in v0.11.0

func (s *Store) CompleteUploadAttemptToStaging(ctx context.Context, attempt UploadAttemptRecord, rec UploadRecord, scope UploadStagingScope) error

func (*Store) CreateThreadSettings added in v0.10.0

func (s *Store) CreateThreadSettings(ctx context.Context, t ThreadSettings) error

func (*Store) CreateUploadStagingScope added in v0.11.0

func (s *Store) CreateUploadStagingScope(ctx context.Context, scope UploadStagingScope) error

func (*Store) DeleteExecutionAuthorities added in v0.13.0

func (s *Store) DeleteExecutionAuthorities(ctx context.Context, requestKeys []string) (int64, error)

func (*Store) DeleteThreadProductData added in v0.11.0

func (s *Store) DeleteThreadProductData(ctx context.Context, endpointID, threadID string) error

DeleteThreadProductData removes only Redeven-owned catalog and attachment rows. The caller deletes the canonical Floret thread first.

func (*Store) EnsureUpload

func (s *Store) EnsureUpload(ctx context.Context, rec UploadRecord) error

func (*Store) ExpireStaleUploadAttempts added in v0.11.0

func (s *Store) ExpireStaleUploadAttempts(ctx context.Context, staleBeforeUnixMs int64) (int64, error)

func (*Store) FailUploadAttempt added in v0.11.0

func (s *Store) FailUploadAttempt(ctx context.Context, attempt UploadAttemptRecord, errorCode string) error

func (*Store) FinalizeDeletedUploads

func (s *Store) FinalizeDeletedUploads(ctx context.Context, uploadIDs []string) (int64, error)

func (*Store) GetComputerAccess added in v0.13.0

func (s *Store) GetComputerAccess(ctx context.Context, threadID string) (ComputerAccess, error)

func (*Store) GetComputerTarget added in v0.13.0

func (s *Store) GetComputerTarget(ctx context.Context, threadID string) (string, error)

GetComputerTarget reads selection for an already authorized canonical thread. Selection is not an authorization grant and does not imply target readiness.

func (*Store) GetExecutionAuthority added in v0.11.0

func (s *Store) GetExecutionAuthority(ctx context.Context, requestKey string) (*ExecutionAuthority, error)

func (*Store) GetExecutionAuthorityByTurn added in v0.11.0

func (s *Store) GetExecutionAuthorityByTurn(ctx context.Context, threadID, turnID string) (*ExecutionAuthority, error)

func (*Store) GetStagingOwnedUpload added in v0.11.0

func (s *Store) GetStagingOwnedUpload(ctx context.Context, endpointID, ownerUserHash, stagingScopeID, uploadID string) (*UploadRecord, error)

func (*Store) GetThreadOwnedUpload added in v0.10.0

func (s *Store) GetThreadOwnedUpload(ctx context.Context, endpointID string, threadID string, uploadID string) (*UploadRecord, error)

func (*Store) GetThreadSettings added in v0.10.0

func (s *Store) GetThreadSettings(ctx context.Context, endpointID string, threadID string) (*ThreadSettings, error)

func (*Store) GetThreadSettingsByCanonicalThreadID added in v0.11.0

func (s *Store) GetThreadSettingsByCanonicalThreadID(ctx context.Context, threadID string) (*ThreadSettings, error)

func (*Store) GetUpload

func (s *Store) GetUpload(ctx context.Context, endpointID string, uploadID string) (*UploadRecord, error)

func (*Store) GetUserOwnedUpload added in v0.11.0

func (s *Store) GetUserOwnedUpload(ctx context.Context, endpointID string, ownerUserHash string, uploadID string) (*UploadRecord, error)

func (*Store) HasCompletedOwnedUploadAttempt added in v0.11.0

func (s *Store) HasCompletedOwnedUploadAttempt(ctx context.Context, endpointID string, ownerUserHash string, uploadID string) (bool, error)

func (*Store) InsertUpload

func (s *Store) InsertUpload(ctx context.Context, rec UploadRecord) error

func (*Store) InterruptReceivingUploadAttempts added in v0.11.0

func (s *Store) InterruptReceivingUploadAttempts(ctx context.Context, nowUnixMs int64) ([]UploadAttemptRecord, error)

func (*Store) ListExecutionAuthoritiesPage added in v0.13.0

func (s *Store) ListExecutionAuthoritiesPage(ctx context.Context, cursor ExecutionAuthorityCursor, limit int) ([]ExecutionAuthority, ExecutionAuthorityCursor, bool, error)

func (*Store) ListThreadSettings added in v0.10.0

func (s *Store) ListThreadSettings(ctx context.Context, endpointID string, limit int, cursor ThreadsCursor) ([]ThreadSettings, string, error)

func (*Store) ListThreadSettingsForRecoveryPage added in v0.11.0

func (s *Store) ListThreadSettingsForRecoveryPage(ctx context.Context, cursor ThreadSettingsRecoveryCursor, limit int) ([]ThreadSettings, ThreadSettingsRecoveryCursor, bool, error)

ListThreadSettingsForRecoveryPage returns a stable page of host-owned root identities for startup reconciliation. It does not project Agent state.

func (*Store) MaybeCompact

func (s *Store) MaybeCompact(ctx context.Context) (SQLiteCompactionPlan, error)

func (*Store) MovePinnedThread added in v0.13.0

func (s *Store) MovePinnedThread(ctx context.Context, endpointID, threadID, anchorID, placement string) ([]ThreadPinMetadata, error)

MovePinnedThread applies one relative move to the complete current endpoint order. Immediate SQLite transactions serialize it with pin, unpin and deletion.

func (*Store) PrepareExpiredUploadsForDeletion

func (s *Store) PrepareExpiredUploadsForDeletion(ctx context.Context, nowUnixMs int64, limit int) ([]UploadRecord, error)

func (*Store) PrepareUserStagedUploadDeletion added in v0.11.0

func (s *Store) PrepareUserStagedUploadDeletion(ctx context.Context, endpointID string, ownerUserHash string, uploadID string, nowUnixMs int64) (*UploadRecord, error)

func (*Store) ProtectedUploadArtifactNames added in v0.11.0

func (s *Store) ProtectedUploadArtifactNames(ctx context.Context) (map[string]struct{}, error)

func (*Store) PruneTerminalUploadAttemptsPage added in v0.13.0

func (s *Store) PruneTerminalUploadAttemptsPage(ctx context.Context, cutoffUnixMs int64, cursor UploadAttemptPruneCursor, limit int) (UploadAttemptPruneCursor, int64, bool, error)

PruneTerminalUploadAttemptsPage removes one bounded page whose idempotency window has elapsed. Receiving attempts are handled by recovery first.

func (*Store) PutExecutionAuthority added in v0.11.0

func (s *Store) PutExecutionAuthority(ctx context.Context, authority ExecutionAuthority) error

func (*Store) ReleaseExpiredUploadStagingScopes added in v0.11.0

func (s *Store) ReleaseExpiredUploadStagingScopes(ctx context.Context, nowUnixMs int64, limit int) ([]UploadRecord, int, error)

func (*Store) ReleaseUploadStagingScope added in v0.11.0

func (s *Store) ReleaseUploadStagingScope(ctx context.Context, scope UploadStagingScope, nowUnixMs int64) ([]UploadRecord, error)

func (*Store) ReleaseUploadStagingScopeUpload added in v0.11.0

func (s *Store) ReleaseUploadStagingScopeUpload(ctx context.Context, scope UploadStagingScope, uploadID string, nowUnixMs int64) ([]UploadRecord, error)

func (*Store) RequireThreadSettingsWritable added in v0.10.0

func (s *Store) RequireThreadSettingsWritable(ctx context.Context, endpointID, threadID string) error

RequireThreadSettingsWritable verifies product catalog ownership only. Floret owns thread lifecycle and deletion tombstones.

func (*Store) RescheduleUploadDeletion

func (s *Store) RescheduleUploadDeletion(ctx context.Context, uploadIDs []string, retryAtUnixMs int64) error

func (*Store) ReserveUploadAttempt added in v0.11.0

func (s *Store) ReserveUploadAttempt(ctx context.Context, attempt UploadAttemptRecord) (UploadAttemptRecord, bool, error)

func (*Store) RestartFailedUploadAttempt added in v0.11.0

func (s *Store) RestartFailedUploadAttempt(ctx context.Context, attempt UploadAttemptRecord) (bool, error)

func (*Store) RetainCanonicalUploads added in v0.13.0

func (s *Store) RetainCanonicalUploads(ctx context.Context, endpointID, threadID string, uploadIDs []string) error

RetainCanonicalUploads records product resource retention after the caller has verified membership in Floret's canonical history, including fork paths. It does not admit a message or grant access to an attachment.

func (*Store) SQLitePageStats

func (s *Store) SQLitePageStats(ctx context.Context) (SQLitePageStats, error)

func (*Store) SetComputerAccess added in v0.13.0

func (s *Store) SetComputerAccess(ctx context.Context, threadID string, access ComputerAccess) error

func (*Store) SetComputerTarget added in v0.13.0

func (s *Store) SetComputerTarget(ctx context.Context, threadID, targetID string) error

SetComputerTarget changes only the selected target. It never creates thread settings, changes permissions or copies a parent's control session on fork.

func (*Store) SetThreadPinned added in v0.7.1

func (s *Store) SetThreadPinned(ctx context.Context, endpointID, threadID string, pinned bool) (*ThreadPinMetadata, error)

func (*Store) UpdateThreadModelAndReasoningSelection added in v0.7.2

func (s *Store) UpdateThreadModelAndReasoningSelection(ctx context.Context, endpointID string, threadID string, modelID string, reasoningSelectionJSON string) error

func (*Store) UpdateThreadModelID

func (s *Store) UpdateThreadModelID(ctx context.Context, endpointID string, threadID string, modelID string) error

func (*Store) UpdateThreadPermissionType added in v0.7.2

func (s *Store) UpdateThreadPermissionType(ctx context.Context, endpointID string, threadID string, permissionType string) error

func (*Store) UpdateThreadReasoningSelection added in v0.7.2

func (s *Store) UpdateThreadReasoningSelection(ctx context.Context, endpointID string, threadID string, reasoningSelectionJSON string) error

type ThreadPinMetadata added in v0.13.0

type ThreadPinMetadata struct {
	ThreadID         string `json:"thread_id"`
	PinnedAtUnixMs   int64  `json:"pinned_at_unix_ms"`
	PinRank          int64  `json:"pin_rank"`
	SettingsRevision int64  `json:"settings_revision"`
}

ThreadPinMetadata is a product mutation result, never a canonical thread view.

type ThreadSettings added in v0.10.0

type ThreadSettings struct {
	ThreadID               string `json:"thread_id"`
	ParentThreadID         string `json:"parent_thread_id,omitempty"`
	EndpointID             string `json:"endpoint_id"`
	NamespacePublicID      string `json:"namespace_public_id"`
	ModelID                string `json:"model_id"`
	ReasoningSelectionJSON string `json:"reasoning_selection_json"`
	PermissionType         string `json:"permission_type"`
	WorkingDir             string `json:"working_dir"`
	PinnedAtUnixMs         int64  `json:"pinned_at_unix_ms"`
	PinRank                int64  `json:"pin_rank"`

	SettingsCreatedAtUnixMs int64 `json:"settings_created_at_unix_ms"`
	SettingsUpdatedAtUnixMs int64 `json:"settings_updated_at_unix_ms"`
}

type ThreadSettingsRecoveryCursor added in v0.11.0

type ThreadSettingsRecoveryCursor struct {
	EndpointID string
	ThreadID   string
}

type ThreadsCursor

type ThreadsCursor struct {
	PinnedAtUnixMs          int64
	SettingsCreatedAtUnixMs int64
	ThreadID                string
}

func DecodeCursor

func DecodeCursor(raw string) (ThreadsCursor, bool)

type UploadAttemptPruneCursor added in v0.13.0

type UploadAttemptPruneCursor struct {
	UpdatedAtUnixMs int64
	EndpointID      string
	OwnerUserHash   string
	UploadRequestID string
}

type UploadAttemptRecord added in v0.11.0

type UploadAttemptRecord struct {
	EndpointID         string
	OwnerUserHash      string
	UploadRequestID    string
	RequestFingerprint string
	UploadID           string
	Status             string
	ErrorCode          string
	CreatedAtUnixMs    int64
	UpdatedAtUnixMs    int64
}

type UploadQuotaError added in v0.11.0

type UploadQuotaError struct {
	Scope  string
	Metric string
	Limit  int64
}

func (*UploadQuotaError) Error added in v0.11.0

func (e *UploadQuotaError) Error() string

func (*UploadQuotaError) Unwrap added in v0.11.0

func (e *UploadQuotaError) Unwrap() error

type UploadRecord

type UploadRecord struct {
	UploadID          string `json:"upload_id"`
	EndpointID        string `json:"endpoint_id"`
	OwnerUserHash     string `json:"owner_user_hash,omitempty"`
	StorageRelPath    string `json:"storage_relpath"`
	Name              string `json:"name"`
	DetectedMediaType string `json:"detected_media_type"`
	MimeType          string `json:"mime_type"`
	SizeBytes         int64  `json:"size_bytes"`
	ContentSHA256     string `json:"content_sha256,omitempty"`
	UnicodeCodePoints *int64 `json:"unicode_code_points,omitempty"`
	LogicalLineCount  *int64 `json:"logical_line_count,omitempty"`
	Source            string `json:"source"`
	State             string `json:"state"`
	CreatedAtUnixMs   int64  `json:"created_at_unix_ms"`
	DeleteAfterUnixMs int64  `json:"delete_after_unix_ms"`
}

type UploadStagingScope added in v0.11.0

type UploadStagingScope struct {
	StagingScopeID  string `json:"staging_scope_id"`
	EndpointID      string `json:"endpoint_id"`
	OwnerUserHash   string `json:"-"`
	TargetID        string `json:"target_id"`
	CapabilityHash  string `json:"-"`
	ExpiresAtUnixMs int64  `json:"expires_at_unix_ms"`
}

Jump to

Keyboard shortcuts

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