Documentation
¶
Overview ¶
Package postgres
Index ¶
- func Open(ctx context.Context, dsn string) (*pgxpool.Pool, error)
- type Driver
- func (d *Driver) Ancestry(ctx context.Context, hash string) ([]*merkle.Node, error)
- func (d *Driver) AncestryChain(ctx context.Context, hash string) (*storage.Chain, error)
- func (d *Driver) AncestryChains(ctx context.Context, hashes []string) (map[string]*storage.Chain, error)
- func (d *Driver) BackfillSession(ctx context.Context, req storage.SessionBackfillRequest) (storage.SessionBackfillResult, error)
- func (d *Driver) Close() error
- func (d *Driver) CountSessions(ctx context.Context, opts storage.ListOpts) (storage.SessionStats, error)
- func (d *Driver) DB() *pgxpool.Pool
- func (d *Driver) Depth(ctx context.Context, hash string) (int, error)
- func (d *Driver) Get(ctx context.Context, hash string) (*merkle.Node, error)
- func (d *Driver) GetByParent(ctx context.Context, parentHash *string) ([]*merkle.Node, error)
- func (d *Driver) GetSessionRecord(ctx context.Context, orgID, id string) (*storage.SessionRecord, error)
- func (d *Driver) Has(ctx context.Context, hash string) (bool, error)
- func (d *Driver) IngestTurn(ctx context.Context, req storage.IngestTurnRequest) (storage.IngestTurnResult, error)
- func (d *Driver) Leaves(ctx context.Context) ([]*merkle.Node, error)
- func (d *Driver) List(ctx context.Context) ([]*merkle.Node, error)
- func (d *Driver) ListNodesBySession(ctx context.Context, sessionID string) ([]*merkle.Node, error)
- func (d *Driver) ListParentRefs(ctx context.Context) ([]storage.ParentRef, error)
- func (d *Driver) ListSessionRecords(ctx context.Context, orgID string, limit int, cursorTs *time.Time, ...) ([]storage.SessionRecord, error)
- func (d *Driver) ListSessions(ctx context.Context, opts storage.ListOpts) (*storage.Page[*merkle.Node], error)
- func (d *Driver) LoadDag(ctx context.Context, hash string) (*merkle.Dag, error)
- func (d *Driver) Open(ctx context.Context) error
- func (d *Driver) Put(ctx context.Context, n *merkle.Node) (bool, error)
- func (d *Driver) Roots(ctx context.Context) ([]*merkle.Node, error)
- func (d *Driver) SessionIdentityByHash(ctx context.Context, orgID, hash string) (*storage.SessionIdentity, error)
- func (d *Driver) UpdateUsage(ctx context.Context, hash string, usage *llm.Usage) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Driver ¶
type Driver struct {
// contains filtered or unexported fields
}
func (*Driver) AncestryChain ¶ added in v0.5.0
func (*Driver) AncestryChains ¶ added in v0.5.0
func (*Driver) BackfillSession ¶ added in v0.10.0
func (d *Driver) BackfillSession(ctx context.Context, req storage.SessionBackfillRequest) (storage.SessionBackfillResult, error)
BackfillSession links existing legacy nodes to a session table row. It is used by transcript backfills where the node DAG already exists but the original ingest path predated session envelopes.
func (*Driver) CountSessions ¶ added in v0.5.0
func (*Driver) GetByParent ¶ added in v0.5.0
func (*Driver) GetSessionRecord ¶ added in v0.12.0
func (d *Driver) GetSessionRecord(ctx context.Context, orgID, id string) (*storage.SessionRecord, error)
GetSessionRecord returns a single session by its UUID, or nil if not found.
func (*Driver) IngestTurn ¶ added in v0.10.0
func (d *Driver) IngestTurn(ctx context.Context, req storage.IngestTurnRequest) (storage.IngestTurnResult, error)
IngestTurn implements storage.SessionIngester for the Postgres driver. The session-tracking flow runs in a single transaction: resolve / UPSERT a sessions row, resolve the optional fork-parent FK (placeholder-inserting the parent when its own first turn hasn't landed yet), insert every node in the supplied chain, stamp session_id onto each newly-inserted node, and roll up the per-turn counters.
func (*Driver) ListNodesBySession ¶ added in v0.12.0
ListNodesBySession returns all nodes attributed to a session ordered by created_at ASC (chronological order).
func (*Driver) ListParentRefs ¶ added in v0.5.0
func (*Driver) ListSessionRecords ¶ added in v0.12.0
func (d *Driver) ListSessionRecords( ctx context.Context, orgID string, limit int, cursorTs *time.Time, cursorID *string, ) ([]storage.SessionRecord, error)
ListSessionRecords returns a page of sessions for an org ordered by last_seen_at DESC. Pass nil cursorTs/cursorID to start from the beginning.
func (*Driver) ListSessions ¶ added in v0.5.0
func (*Driver) SessionIdentityByHash ¶ added in v0.10.0
func (d *Driver) SessionIdentityByHash(ctx context.Context, orgID, hash string) (*storage.SessionIdentity, error)
SessionIdentityByHash returns the harness identity for the sessions row attached to a node hash, scoped to orgID. Older rows, legacy Put writes, and non-Postgres stores may not have session tracking metadata; those return nil without error so read APIs can expose the field opportunistically.
The org_id predicate is load-bearing, not cosmetic: nodes is keyed by the composite (org_id, hash), so identical content yields one row per org. A lookup on hash alone would return an arbitrary org's row for shared content, leaking another tenant's harness_session_id. An empty orgID maps to the nil-UUID sentinel bucket (legacy / non-session writes).