gensqlc

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AggregateSessionsByModelParams added in v0.8.0

type AggregateSessionsByModelParams struct {
	ProjectFilter  pgtype.Text
	AgentFilter    pgtype.Text
	ModelFilter    pgtype.Text
	ProviderFilter pgtype.Text
	SinceFilter    pgtype.Timestamptz
	UntilFilter    pgtype.Timestamptz
}

type AggregateSessionsByModelRow added in v0.8.0

type AggregateSessionsByModelRow struct {
	Model               pgtype.Text
	InputTokens         int64
	OutputTokens        int64
	CacheCreationTokens int64
	CacheReadTokens     int64
}

type AggregateSessionsParams added in v0.8.0

type AggregateSessionsParams struct {
	ProjectFilter  pgtype.Text
	AgentFilter    pgtype.Text
	ModelFilter    pgtype.Text
	ProviderFilter pgtype.Text
	SinceFilter    pgtype.Timestamptz
	UntilFilter    pgtype.Timestamptz
}

type AggregateSessionsRow added in v0.8.0

type AggregateSessionsRow struct {
	TurnCount           int64
	SessionCount        int64
	RootCount           int64
	CompletedCount      int64
	InputTokens         int64
	OutputTokens        int64
	CacheCreationTokens int64
	CacheReadTokens     int64
	TotalDurationNs     int64
	ToolCalls           int64
}

type AncestryChainsParams

type AncestryChainsParams struct {
	Hashes   []string
	MaxDepth int32
}

type AncestryChainsRow

type AncestryChainsRow struct {
	StartHash                interface{}
	Hash                     interface{}
	ParentHash               interface{}
	Bucket                   interface{}
	Type                     interface{}
	Role                     interface{}
	Content                  interface{}
	Model                    interface{}
	Provider                 interface{}
	AgentName                interface{}
	StopReason               interface{}
	PromptTokens             interface{}
	CompletionTokens         interface{}
	TotalTokens              interface{}
	CacheCreationInputTokens interface{}
	CacheReadInputTokens     interface{}
	TotalDurationNs          interface{}
	PromptDurationNs         interface{}
	Project                  interface{}
	CreatedAt                pgtype.Timestamptz
	Depth                    int32
	HasUsage                 bool
}

type DBTX

type DBTX interface {
	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
	QueryRow(context.Context, string, ...interface{}) pgx.Row
}

type InsertNodeParams

type InsertNodeParams struct {
	Hash                     string
	Bucket                   []byte
	Type                     pgtype.Text
	Role                     pgtype.Text
	Content                  []byte
	Model                    pgtype.Text
	Provider                 pgtype.Text
	AgentName                pgtype.Text
	StopReason               pgtype.Text
	PromptTokens             pgtype.Int4
	CompletionTokens         pgtype.Int4
	TotalTokens              pgtype.Int4
	CacheCreationInputTokens pgtype.Int4
	CacheReadInputTokens     pgtype.Int4
	TotalDurationNs          pgtype.Int8
	PromptDurationNs         pgtype.Int8
	Project                  pgtype.Text
	CreatedAt                pgtype.Timestamptz
	ParentHash               pgtype.Text
}

type ListParentRefsRow

type ListParentRefsRow struct {
	Hash       string
	ParentHash pgtype.Text
}

type ListSessionsParams

type ListSessionsParams struct {
	ProjectFilter   pgtype.Text
	AgentFilter     pgtype.Text
	ModelFilter     pgtype.Text
	ProviderFilter  pgtype.Text
	SinceFilter     pgtype.Timestamptz
	UntilFilter     pgtype.Timestamptz
	CursorCreatedAt pgtype.Timestamptz
	CursorHash      pgtype.Text
	LimitCount      int32
}

type Node

type Node struct {
	Hash                     string
	Bucket                   []byte
	Type                     pgtype.Text
	Role                     pgtype.Text
	Content                  []byte
	Model                    pgtype.Text
	Provider                 pgtype.Text
	AgentName                pgtype.Text
	StopReason               pgtype.Text
	PromptTokens             pgtype.Int4
	CompletionTokens         pgtype.Int4
	TotalTokens              pgtype.Int4
	CacheCreationInputTokens pgtype.Int4
	CacheReadInputTokens     pgtype.Int4
	TotalDurationNs          pgtype.Int8
	PromptDurationNs         pgtype.Int8
	Project                  pgtype.Text
	CreatedAt                pgtype.Timestamptz
	ParentHash               pgtype.Text
}

type Queries

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

func New

func New(db DBTX) *Queries

func (*Queries) AggregateSessions added in v0.8.0

func (q *Queries) AggregateSessions(ctx context.Context, arg AggregateSessionsParams) (AggregateSessionsRow, error)

Single-pass aggregate that powers /v1/stats. All counts and SUMs apply to the set of nodes matching the supplied per-node filters; a "session" is identified as a leaf node (no child references it as parent_hash).

completed_count is leaf-status-only: assistant role plus a terminal stop_reason. It deliberately omits the chain-context overrides (hasToolError / hasGitActivity) that pkg/sessions.DetermineStatus applies, so a single SQL aggregate is sufficient. See StatsResponse in api/v1_handlers.go for the rationale, and PCC-515 for the durable chain-aware fix.

total_duration_ns is wall-clock span MAX(created_at) - MIN(created_at) across the matching set, NOT SUM(nodes.total_duration_ns). The nodes.total_duration_ns column is currently never populated by the proxy (verified against jason@'s local store: 0 of 1460 rows have a non-zero value) — see PCC-514. Until that lands, SUMming the column would always return 0, which is misleading; wall-clock span is a meaningful "Agent Time" proxy that doesn't depend on the dead column.

The tool_calls subquery scans content JSONB per node to count tool_use blocks. This is acceptable at current corpus sizes; if it becomes a bottleneck the right next step is denormalizing tool_use_count onto the nodes table at write time.

func (*Queries) AggregateSessionsByModel added in v0.8.0

func (q *Queries) AggregateSessionsByModel(ctx context.Context, arg AggregateSessionsByModelParams) ([]AggregateSessionsByModelRow, error)

Per-model token rollup that powers the cost fold in /v1/stats. Filters apply per-node, matching aggregate_sessions.sql. Nodes with a NULL or empty model are excluded — they cannot be priced.

The API handler walks these rows, applies pkg/sessions.PricingForModel and pkg/sessions.CostForTokensWithCache to each, and sums into StatsResponse.TotalCost. Pricing intentionally lives in Go.

func (*Queries) AncestryChains

func (q *Queries) AncestryChains(ctx context.Context, arg AncestryChainsParams) ([]AncestryChainsRow, error)

func (*Queries) DuckdbForceExecution

func (q *Queries) DuckdbForceExecution(ctx context.Context) error

func (*Queries) GetNode

func (q *Queries) GetNode(ctx context.Context, hash string) (Node, error)

func (*Queries) GetNodesByParent

func (q *Queries) GetNodesByParent(ctx context.Context, parentHash pgtype.Text) ([]Node, error)

func (*Queries) GetRootNodes

func (q *Queries) GetRootNodes(ctx context.Context) ([]Node, error)

func (*Queries) HasNode

func (q *Queries) HasNode(ctx context.Context, hash string) (bool, error)

func (*Queries) InsertNode

func (q *Queries) InsertNode(ctx context.Context, arg InsertNodeParams) (int64, error)

func (*Queries) ListLeaves

func (q *Queries) ListLeaves(ctx context.Context) ([]Node, error)

func (*Queries) ListNodes

func (q *Queries) ListNodes(ctx context.Context) ([]Node, error)

func (*Queries) ListParentRefs

func (q *Queries) ListParentRefs(ctx context.Context) ([]ListParentRefsRow, error)

func (*Queries) ListSessions

func (q *Queries) ListSessions(ctx context.Context, arg ListSessionsParams) ([]Node, error)

func (*Queries) UpdateUsage

func (q *Queries) UpdateUsage(ctx context.Context, arg UpdateUsageParams) error

func (*Queries) WithTx

func (q *Queries) WithTx(tx pgx.Tx) *Queries

type UpdateUsageParams

type UpdateUsageParams struct {
	Hash                     string
	PromptTokens             pgtype.Int4
	CompletionTokens         pgtype.Int4
	TotalTokens              pgtype.Int4
	CacheCreationInputTokens pgtype.Int4
	CacheReadInputTokens     pgtype.Int4
	TotalDurationNs          pgtype.Int8
	PromptDurationNs         pgtype.Int8
}

Jump to

Keyboard shortcuts

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