client

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package client provides a typed Go SDK for the Pali HTTP API.

It wraps /health and /v1/* endpoints with request/response models, bearer-token support, and structured API errors.

Pali is early-stage and infrastructure-first; this package is a thin API client, not a complete memory optimization layer.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound     = &APIError{StatusCode: 404, Code: "not_found"}
	ErrUnauthorized = &APIError{StatusCode: 401, Code: "unauthorized"}
	ErrForbidden    = &APIError{StatusCode: 403, Code: "forbidden"}
	ErrConflict     = &APIError{StatusCode: 409, Code: "conflict"}
	ErrRateLimit    = &APIError{StatusCode: 429, Code: "rate_limited"}
)

Sentinel errors for the most common API error conditions. Use with errors.Is:

if errors.Is(err, client.ErrNotFound) { ... }

Functions

This section is empty.

Types

type APIError

type APIError struct {
	// StatusCode is the HTTP status code returned by the server.
	StatusCode int
	// Code is the machine-readable error code from the API response body (e.g. "not_found").
	Code string
	// Message is the human-readable error message.
	Message string
	// RequestID is the value of the X-Request-ID response header, if present.
	// Include this in bug reports and support tickets.
	RequestID string
	// Body is the raw response body, preserved for debugging.
	Body string
}

APIError represents a non-2xx response from the Pali API. Callers should use errors.As to inspect the full error, or errors.Is against the sentinel values (ErrNotFound, ErrUnauthorized, etc.) for common cases.

func (*APIError) Error

func (e *APIError) Error() string

Error implements the error interface.

func (*APIError) Is

func (e *APIError) Is(target error) bool

Is reports whether this error matches target. Two APIErrors are equal when they have the same StatusCode and Code. This enables errors.Is(err, client.ErrNotFound) checks.

type Client

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

Client is a typed HTTP client for the Pali API. It is safe to use concurrently from multiple goroutines.

func New

func New(baseURL string, opts ...Option) (*Client, error)

New is an alias of NewClient.

func NewClient

func NewClient(baseURL string, opts ...Option) (*Client, error)

NewClient constructs a new API client for the provided base URL.

func (*Client) CreateTenant

func (c *Client) CreateTenant(ctx context.Context, req CreateTenantRequest) (CreateTenantResponse, error)

CreateTenant calls POST /v1/tenants.

func (*Client) DeleteMemory

func (c *Client) DeleteMemory(ctx context.Context, tenantID, memoryID string) error

DeleteMemory calls DELETE /v1/memory/:id?tenant_id=...

func (*Client) GetPostprocessJob

func (c *Client) GetPostprocessJob(ctx context.Context, jobID string) (PostprocessJobResponse, error)

GetPostprocessJob calls GET /v1/memory/jobs/:id.

func (*Client) Health

func (c *Client) Health(ctx context.Context) (HealthResponse, error)

Health calls GET /health.

func (*Client) IngestMemory

func (c *Client) IngestMemory(ctx context.Context, req StoreMemoryRequest) (IngestMemoryResponse, error)

IngestMemory calls POST /v1/memory/ingest.

func (*Client) IngestMemoryBatch

func (c *Client) IngestMemoryBatch(ctx context.Context, req StoreMemoryBatchRequest) (IngestMemoryResponse, error)

IngestMemoryBatch calls POST /v1/memory/ingest/batch.

func (*Client) ListPostprocessJobs

ListPostprocessJobs calls GET /v1/memory/jobs with optional filters.

func (*Client) SearchMemory

func (c *Client) SearchMemory(ctx context.Context, req SearchMemoryRequest) (SearchMemoryResponse, error)

SearchMemory calls POST /v1/memory/search.

func (*Client) SetBearerToken

func (c *Client) SetBearerToken(token string)

SetBearerToken updates the bearer token used for subsequent requests.

func (*Client) StoreMemory

func (c *Client) StoreMemory(ctx context.Context, req StoreMemoryRequest) (StoreMemoryResponse, error)

StoreMemory calls POST /v1/memory.

func (*Client) StoreMemoryBatch

StoreMemoryBatch calls POST /v1/memory/batch.

func (*Client) TenantStats

func (c *Client) TenantStats(ctx context.Context, tenantID string) (TenantStatsResponse, error)

TenantStats calls GET /v1/tenants/:id/stats.

type CreateTenantRequest

type CreateTenantRequest struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

CreateTenantRequest is the request payload for POST /v1/tenants.

type CreateTenantResponse

type CreateTenantResponse struct {
	ID        string    `json:"id"`
	Name      string    `json:"name"`
	CreatedAt time.Time `json:"created_at"`
}

CreateTenantResponse is returned by POST /v1/tenants.

type HealthResponse

type HealthResponse struct {
	Status string `json:"status"`
	Time   string `json:"time"`
}

HealthResponse is returned by GET /health.

type IngestMemoryResponse

type IngestMemoryResponse struct {
	IngestID   string    `json:"ingest_id"`
	MemoryIDs  []string  `json:"memory_ids"`
	JobIDs     []string  `json:"job_ids"`
	AcceptedAt time.Time `json:"accepted_at"`
}

IngestMemoryResponse is returned by async ingest endpoints.

type ListPostprocessJobsRequest

type ListPostprocessJobsRequest struct {
	TenantID string
	Statuses []string
	Types    []string
	Limit    int
}

ListPostprocessJobsRequest is the query payload for GET /v1/memory/jobs.

type ListPostprocessJobsResponse

type ListPostprocessJobsResponse struct {
	Items []PostprocessJobResponse `json:"items"`
}

ListPostprocessJobsResponse is returned by GET /v1/memory/jobs.

type MemoryClient

type MemoryClient interface {
	StoreMemory(ctx context.Context, req StoreMemoryRequest) (StoreMemoryResponse, error)
	StoreMemoryBatch(ctx context.Context, req StoreMemoryBatchRequest) (StoreMemoryBatchResponse, error)
	SearchMemory(ctx context.Context, req SearchMemoryRequest) (SearchMemoryResponse, error)
	DeleteMemory(ctx context.Context, tenantID, memoryID string) error
}

MemoryClient is the interface implemented by *Client for memory operations. Callers should use this interface as a parameter type to allow mocking in tests:

type MyService struct { mem client.MemoryClient }

type MemoryResponse

type MemoryResponse struct {
	ID             string    `json:"id"`
	TenantID       string    `json:"tenant_id"`
	Content        string    `json:"content"`
	Tier           string    `json:"tier"`
	Tags           []string  `json:"tags"`
	Source         string    `json:"source"`
	CreatedBy      string    `json:"created_by"`
	Kind           string    `json:"kind"`
	RecallCount    int       `json:"recall_count"`
	CreatedAt      time.Time `json:"created_at"`
	UpdatedAt      time.Time `json:"updated_at"`
	LastAccessedAt time.Time `json:"last_accessed_at"`
	LastRecalledAt time.Time `json:"last_recalled_at"`
}

MemoryResponse is a single memory item returned by search.

type Option

type Option func(*Client)

Option configures a Client at construction time.

func WithBearerToken

func WithBearerToken(token string) Option

WithBearerToken sets a default bearer token on the client.

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) Option

WithHTTPClient overrides the default HTTP client.

type PostprocessJobResponse

type PostprocessJobResponse struct {
	ID          string    `json:"id"`
	IngestID    string    `json:"ingest_id"`
	TenantID    string    `json:"tenant_id"`
	MemoryID    string    `json:"memory_id"`
	Type        string    `json:"type"`
	Status      string    `json:"status"`
	Attempts    int       `json:"attempts"`
	MaxAttempts int       `json:"max_attempts"`
	AvailableAt time.Time `json:"available_at"`
	LeaseOwner  string    `json:"lease_owner,omitempty"`
	LeasedUntil time.Time `json:"leased_until,omitempty"`
	LastError   string    `json:"last_error,omitempty"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

PostprocessJobResponse is a single job item returned by job endpoints.

type SearchMemoryDebug

type SearchMemoryDebug struct {
	Plan    SearchPlanDebug      `json:"plan"`
	Ranking []SearchRankingDebug `json:"ranking,omitempty"`
}

SearchMemoryDebug is debug metadata for search operations.

type SearchMemoryRequest

type SearchMemoryRequest struct {
	TenantID      string   `json:"tenant_id"`
	Query         string   `json:"query"`
	TopK          int      `json:"top_k"`
	MinScore      float64  `json:"min_score,omitempty"`
	Tiers         []string `json:"tiers,omitempty"`
	Kinds         []string `json:"kinds,omitempty"`
	RetrievalKind string   `json:"retrieval_kind,omitempty"`
	DisableTouch  bool     `json:"disable_touch,omitempty"`
	Debug         bool     `json:"debug,omitempty"`
}

SearchMemoryRequest is the request payload for POST /v1/memory/search.

type SearchMemoryResponse

type SearchMemoryResponse struct {
	Items []MemoryResponse   `json:"items"`
	Debug *SearchMemoryDebug `json:"debug,omitempty"`
}

SearchMemoryResponse is returned by POST /v1/memory/search.

type SearchPlanDebug

type SearchPlanDebug struct {
	Intent           string   `json:"intent"`
	Confidence       float64  `json:"confidence"`
	AnswerType       string   `json:"answer_type,omitempty"`
	Entities         []string `json:"entities,omitempty"`
	Relations        []string `json:"relations,omitempty"`
	TimeConstraints  []string `json:"time_constraints,omitempty"`
	RequiredEvidence string   `json:"required_evidence,omitempty"`
	FallbackPath     []string `json:"fallback_path,omitempty"`
}

SearchPlanDebug is planner diagnostics returned when debug mode is enabled.

type SearchRankingDebug

type SearchRankingDebug struct {
	Rank         int     `json:"rank"`
	MemoryID     string  `json:"memory_id"`
	Kind         string  `json:"kind"`
	Tier         string  `json:"tier"`
	LexicalScore float64 `json:"lexical_score"`
	QueryOverlap float64 `json:"query_overlap"`
	RouteFit     float64 `json:"route_fit"`
}

SearchRankingDebug is ranking diagnostics for one memory candidate.

type StoreMemoryBatchRequest

type StoreMemoryBatchRequest struct {
	Items []StoreMemoryRequest `json:"items"`
}

StoreMemoryBatchRequest is the request payload for POST /v1/memory/batch.

type StoreMemoryBatchResponse

type StoreMemoryBatchResponse struct {
	Items []StoreMemoryResponse `json:"items"`
}

StoreMemoryBatchResponse is returned by POST /v1/memory/batch.

type StoreMemoryRequest

type StoreMemoryRequest struct {
	TenantID  string   `json:"tenant_id"`
	Content   string   `json:"content"`
	Tags      []string `json:"tags"`
	Tier      string   `json:"tier"`
	Kind      string   `json:"kind,omitempty"`
	Source    string   `json:"source,omitempty"`
	CreatedBy string   `json:"created_by,omitempty"`
}

StoreMemoryRequest is the request payload for POST /v1/memory.

type StoreMemoryResponse

type StoreMemoryResponse struct {
	ID        string    `json:"id"`
	CreatedAt time.Time `json:"created_at"`
}

StoreMemoryResponse is returned by POST /v1/memory.

type TenantStatsResponse

type TenantStatsResponse struct {
	TenantID    string `json:"tenant_id"`
	MemoryCount int64  `json:"memory_count"`
}

TenantStatsResponse is returned by GET /v1/tenants/:id/stats.

Jump to

Keyboard shortcuts

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