responsestore

package
v0.1.54 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package responsestore provides persistence for OpenAI-compatible Responses lifecycle endpoints.

Index

Constants

View Source
const (
	// DefaultMemoryStoreTTL bounds in-memory response retention by age.
	DefaultMemoryStoreTTL = 24 * time.Hour
	// DefaultMemoryStoreMaxEntries bounds in-memory response retention by count.
	DefaultMemoryStoreMaxEntries = 10000
	// DefaultMemoryStoreMaxBytes bounds in-memory response retention by total
	// serialized size. Agentic clients resend whole conversations as input, so
	// entry counts alone do not bound memory.
	DefaultMemoryStoreMaxBytes = 64 << 20
	// DefaultMemoryStoreCleanupInterval limits full expired-entry sweeps.
	DefaultMemoryStoreCleanupInterval = time.Minute
)
View Source
const (
	// DefaultPersistentStoreTTL bounds stored response retention in persistent
	// backends. Matches OpenAI's documented 30-day retention for stored
	// responses; expired rows are swept hourly.
	DefaultPersistentStoreTTL = 30 * 24 * time.Hour

	// CleanupInterval is how often persistent stores sweep expired snapshots.
	CleanupInterval = 1 * time.Hour
)

Variables

View Source
var ErrNotFound = errors.New("response not found")

ErrNotFound indicates a requested response was not found.

Functions

This section is empty.

Types

type MemoryStore

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

MemoryStore keeps response snapshots in process memory. Data survives across requests but not process restarts.

func NewMemoryStore

func NewMemoryStore(options ...MemoryStoreOption) *MemoryStore

NewMemoryStore creates an empty in-memory response store. By default retention is bounded; pass WithUnboundedRetention to opt out.

func (*MemoryStore) Close

func (s *MemoryStore) Close() error

Close releases resources (no-op for memory store).

func (*MemoryStore) Create

func (s *MemoryStore) Create(_ context.Context, response *StoredResponse) error

Create stores a new response snapshot.

func (*MemoryStore) Delete

func (s *MemoryStore) Delete(_ context.Context, id string) error

Delete removes one response snapshot by id.

func (*MemoryStore) Get

Get retrieves one response snapshot by id.

func (*MemoryStore) Update

func (s *MemoryStore) Update(_ context.Context, response *StoredResponse) error

Update replaces an existing response snapshot.

type MemoryStoreOption

type MemoryStoreOption func(*MemoryStore)

MemoryStoreOption configures bounded in-memory response retention.

func WithMaxBytes

func WithMaxBytes(maxBytes int64) MemoryStoreOption

WithMaxBytes caps the total serialized size of stored responses with FIFO eviction. Non-positive values disable the cap.

func WithMaxEntries

func WithMaxEntries(maxEntries int) MemoryStoreOption

WithMaxEntries caps stored responses with FIFO eviction. Non-positive values disable the cap.

func WithTTL

func WithTTL(ttl time.Duration) MemoryStoreOption

WithTTL expires stored responses after ttl. Non-positive values disable TTL.

func WithUnboundedRetention

func WithUnboundedRetention() MemoryStoreOption

WithUnboundedRetention disables default in-memory retention bounds.

type MongoDBStore

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

MongoDBStore persists response snapshots in MongoDB.

func NewMongoDBStore

func NewMongoDBStore(database *mongo.Database) (*MongoDBStore, error)

NewMongoDBStore creates collection indexes if needed and starts the hourly expired-snapshot sweep.

func (*MongoDBStore) Close

func (s *MongoDBStore) Close() error

Close stops the cleanup loop; client lifecycle is managed by the storage layer.

func (*MongoDBStore) Create

func (s *MongoDBStore) Create(ctx context.Context, response *StoredResponse) error

Create stores a new response snapshot. An existing snapshot with the same id is only replaced when it has already expired.

func (*MongoDBStore) Delete

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

Delete removes one unexpired response snapshot by id.

func (*MongoDBStore) DeleteExpired

func (s *MongoDBStore) DeleteExpired(ctx context.Context) error

DeleteExpired removes all expired response snapshots.

func (*MongoDBStore) Get

func (s *MongoDBStore) Get(ctx context.Context, id string) (*StoredResponse, error)

Get retrieves one response snapshot by id.

func (*MongoDBStore) Update

func (s *MongoDBStore) Update(ctx context.Context, response *StoredResponse) error

Update replaces an existing, unexpired response snapshot. Zero StoredAt or ExpiresAt values preserve the stored retention fields.

type PostgreSQLStore

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

PostgreSQLStore persists response snapshots in PostgreSQL.

func NewPostgreSQLStore

func NewPostgreSQLStore(ctx context.Context, pool *pgxpool.Pool) (*PostgreSQLStore, error)

NewPostgreSQLStore creates the response_snapshots table if needed and starts the hourly expired-snapshot sweep.

func (*PostgreSQLStore) Close

func (s *PostgreSQLStore) Close() error

Close stops the cleanup loop; pool lifecycle is managed by the storage layer.

func (*PostgreSQLStore) Create

func (s *PostgreSQLStore) Create(ctx context.Context, response *StoredResponse) error

Create stores a new response snapshot. An existing snapshot with the same id is only replaced when it has already expired.

func (*PostgreSQLStore) Delete

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

Delete removes one unexpired response snapshot by id.

func (*PostgreSQLStore) DeleteExpired

func (s *PostgreSQLStore) DeleteExpired(ctx context.Context) error

DeleteExpired removes all expired response snapshots.

func (*PostgreSQLStore) Get

Get retrieves one response snapshot by id.

func (*PostgreSQLStore) Update

func (s *PostgreSQLStore) Update(ctx context.Context, response *StoredResponse) error

Update replaces an existing, unexpired response snapshot. Zero StoredAt or ExpiresAt values preserve the stored retention columns.

type Result

type Result struct {
	Store   Store
	Storage storage.Storage
}

Result holds the initialized response store and optional owned storage.

func New

func New(ctx context.Context, cfg *config.Config) (*Result, error)

New creates a response store from app configuration.

func NewWithSharedStorage

func NewWithSharedStorage(ctx context.Context, shared storage.Storage) (*Result, error)

NewWithSharedStorage creates a response store using a shared storage connection.

func (*Result) Close

func (r *Result) Close() error

Close releases resources held by the response store.

type SQLiteStore

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

SQLiteStore persists response snapshots in SQLite.

func NewSQLiteStore

func NewSQLiteStore(db *sql.DB) (*SQLiteStore, error)

NewSQLiteStore creates the response_snapshots table if needed and starts the hourly expired-snapshot sweep.

func (*SQLiteStore) Close

func (s *SQLiteStore) Close() error

Close stops the cleanup loop; DB lifecycle is managed by the storage layer.

func (*SQLiteStore) Create

func (s *SQLiteStore) Create(ctx context.Context, response *StoredResponse) error

Create stores a new response snapshot. An existing snapshot with the same id is only replaced when it has already expired.

func (*SQLiteStore) Delete

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

Delete removes one unexpired response snapshot by id.

func (*SQLiteStore) DeleteExpired

func (s *SQLiteStore) DeleteExpired(ctx context.Context) error

DeleteExpired removes all expired response snapshots.

func (*SQLiteStore) Get

func (s *SQLiteStore) Get(ctx context.Context, id string) (*StoredResponse, error)

Get retrieves one response snapshot by id.

func (*SQLiteStore) Update

func (s *SQLiteStore) Update(ctx context.Context, response *StoredResponse) error

Update replaces an existing, unexpired response snapshot. Zero StoredAt or ExpiresAt values preserve the stored retention columns.

type Store

type Store interface {
	Create(ctx context.Context, response *StoredResponse) error
	Get(ctx context.Context, id string) (*StoredResponse, error)
	Update(ctx context.Context, response *StoredResponse) error
	Delete(ctx context.Context, id string) error
	Close() error
}

Store defines persistence operations for Responses lifecycle APIs.

type StoredResponse

type StoredResponse struct {
	Response           *core.ResponsesResponse `json:"response"`
	InputItems         []json.RawMessage       `json:"input_items,omitempty"`
	Provider           string                  `json:"provider,omitempty"`
	ProviderName       string                  `json:"provider_name,omitempty"`
	ProviderResponseID string                  `json:"provider_response_id,omitempty"`
	RequestID          string                  `json:"request_id,omitempty"`
	UserPath           string                  `json:"user_path,omitempty"`
	WorkflowVersionID  string                  `json:"workflow_version_id,omitempty"`
	StoredAt           time.Time               `json:"stored_at"`
	ExpiresAt          time.Time               `json:"expires_at"`
}

StoredResponse keeps the public response snapshot separate from gateway-only routing and input item metadata.

Jump to

Keyboard shortcuts

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