api

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2026 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Overview

Package api provides an HTTP API server for inspecting and managing the Merkle DAG.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// ListenAddr is the address to listen on (e.g., ":8081")
	ListenAddr string

	// VectorDriver for semantic search (optional, enables MCP server)
	VectorDriver vector.Driver

	// Embedder for converting query text to vectors (optional, enables MCP server)
	Embedder embeddings.Embedder

	// Pricing is the model pricing table used by /v1/sessions/summary to
	// compute per-session cost. When nil, sessions.DefaultPricing() is used.
	Pricing sessions.PricingTable
}

Config is the API server configuration.

type Server

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

Server is the API server for managing and querying the Tapes system

func NewServer

func NewServer(config Config, driver storage.Driver, log *slog.Logger) (*Server, error)

NewServer creates a new API server. The storer is injected to allow sharing with other components (e.g., the proxy when not run as a singleton).

func (*Server) Run

func (s *Server) Run() error

Run starts the API server on the configured address.

func (*Server) RunWithListener

func (s *Server) RunWithListener(listener net.Listener) error

RunWithListener starts the API server using the provided listener.

func (*Server) Shutdown

func (s *Server) Shutdown() error

Shutdown gracefully shuts down the API server.

type SessionListItem added in v0.4.0

type SessionListItem struct {
	Hash      string    `json:"hash"`
	HeadRole  string    `json:"head_role,omitempty"`
	UpdatedAt time.Time `json:"updated_at,omitzero"`
	Project   string    `json:"project,omitempty"`
	AgentName string    `json:"agent_name,omitempty"`
	Model     string    `json:"model,omitempty"`
	Provider  string    `json:"provider,omitempty"`
	Preview   string    `json:"preview,omitempty"`
}

SessionListItem is the per-item shape returned by GET /v1/sessions.

It deliberately omits fields that would require an ancestry walk per item (e.g. started_at, depth, per-session aggregates). Callers that need those should fetch /v1/sessions/:hash for the specific session.

type SessionListResponse added in v0.4.0

type SessionListResponse struct {
	Items      []SessionListItem `json:"items"`
	NextCursor string            `json:"next_cursor,omitempty"`
}

SessionListResponse is the response envelope for GET /v1/sessions.

type SessionResponse added in v0.4.0

type SessionResponse struct {
	// Hash is the head of the returned chain (== the requested hash).
	Hash string `json:"hash"`

	// Depth is the total number of turns in the full ancestry of Hash.
	// When the client passes ?depth=N, the Turns array may contain fewer
	// than Depth items.
	Depth int `json:"depth"`

	// Turns contains the chain in chronological order (root-first).
	// When ?depth=N is supplied, only the last N turns (head + N-1 ancestors)
	// are returned, still in chronological order.
	Turns []Turn `json:"turns"`

	// Truncated is true when the ancestry walk stopped at a parent_hash
	// that could not be resolved in the current store. MissingParent
	// names that hash. This is an expected edge case on stores that
	// trim older data, merge foreign content, or offload history to
	// another source — not an error.
	Truncated     bool   `json:"truncated,omitempty"`
	MissingParent string `json:"missing_parent,omitempty"`
}

SessionResponse is the response for GET /v1/sessions/:hash.

type SessionSummaryListResponse added in v0.4.0

type SessionSummaryListResponse struct {
	Items      []sessions.SessionSummary `json:"items"`
	NextCursor string                    `json:"next_cursor,omitempty"`
}

SessionSummaryListResponse is the response envelope for GET /v1/sessions/summary. Items carry the rich per-session aggregates computed by pkg/sessions.BuildSummary.

type StatsResponse added in v0.4.0

type StatsResponse struct {
	SessionCount int `json:"session_count"`
	TurnCount    int `json:"turn_count"`
	RootCount    int `json:"root_count"`
}

StatsResponse is the response for GET /v1/stats.

type Turn added in v0.4.0

type Turn struct {
	Hash       string             `json:"hash"`
	ParentHash *string            `json:"parent_hash,omitempty"`
	Role       string             `json:"role"`
	Content    []llm.ContentBlock `json:"content"`
	Model      string             `json:"model,omitempty"`
	Provider   string             `json:"provider,omitempty"`
	AgentName  string             `json:"agent_name,omitempty"`
	StopReason string             `json:"stop_reason,omitempty"`
	Usage      *llm.Usage         `json:"usage,omitempty"`
	CreatedAt  time.Time          `json:"created_at,omitzero"`
}

Turn is a single message in a session's chain.

Directories

Path Synopsis
Package mcp provides an MCP (Model Context Protocol) server for the Tapes system.
Package mcp provides an MCP (Model Context Protocol) server for the Tapes system.
Package search provides shared search types and logic for semantic search over stored LLM sessions.
Package search provides shared search types and logic for semantic search over stored LLM sessions.

Jump to

Keyboard shortcuts

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