context

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrKeyNotFound     = errors.New("context key not found")
	ErrVersionConflict = errors.New("version conflict")
	ErrInvalidMerge    = errors.New("cannot merge incompatible types")
	ErrEmptyKey        = errors.New("context key cannot be empty")
)

Common errors returned by the context engine.

Functions

This section is empty.

Types

type Engine

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

Engine implements the workflow context logic layer. It orchestrates storage operations and provides merge functionality.

func NewEngine

func NewEngine(store storage.Backend, cfg *config.ContextConfig) (*Engine, error)

NewEngine creates a new context engine.

func (*Engine) CleanupExpired

func (e *Engine) CleanupExpired(ctx context.Context) (int64, error)

CleanupExpired removes all context entries past their TTL expiration.

func (*Engine) CleanupRun

func (e *Engine) CleanupRun(ctx context.Context, namespace, runID string) error

CleanupRun removes all context entries for a specific run.

func (*Engine) Delete

func (e *Engine) Delete(ctx context.Context, namespace, key string, runID *string) error

Delete removes a context entry.

func (*Engine) Get

func (e *Engine) Get(ctx context.Context, namespace, key string, opts *GetOpts) (*GetResult, error)

Get retrieves a context entry by key.

func (*Engine) History

func (e *Engine) History(ctx context.Context, namespace, key string, opts *HistoryOpts) (*HistoryResult, error)

History retrieves the version history for a key.

func (*Engine) List

func (e *Engine) List(ctx context.Context, namespace string, opts *ListOpts) (*ListResult, error)

List returns all keys matching the criteria.

func (*Engine) Merge

func (e *Engine) Merge(ctx context.Context, namespace, key string, value any, opts *MergeOpts) (*MergeResult, error)

Merge combines a new value with an existing context entry.

func (*Engine) Set

func (e *Engine) Set(ctx context.Context, namespace, key string, value any, opts *SetOpts) (*SetResult, error)

Set stores a context entry.

type GetOpts

type GetOpts struct {
	RunID *string // Optional: nil for persistent context
}

GetOpts contains options for retrieving context.

type GetResult

type GetResult struct {
	Key       string    `json:"key"`
	Value     any       `json:"value"`
	Version   int64     `json:"version"`
	UpdatedAt time.Time `json:"updated_at"`
	Exists    bool      `json:"exists"`
}

GetResult contains the result of a context get operation.

type HistoryOpts

type HistoryOpts struct {
	RunID  *string // Optional: nil for persistent context
	Cursor string  // Pagination cursor
	Limit  int     // Max entries to return (0 = default)
}

HistoryOpts contains options for retrieving context history.

type HistoryResult

type HistoryResult struct {
	Key        string                       `json:"key"`
	History    []*types.ContextHistoryEntry `json:"history"`
	NextCursor string                       `json:"next_cursor,omitempty"`
}

HistoryResult contains the result of a context history operation.

type ListOpts

type ListOpts struct {
	RunID  *string // Optional: nil for persistent context
	Prefix *string // Optional key prefix filter
	Cursor string  // Pagination cursor
	Limit  int     // Max keys to return (0 = default)
}

ListOpts contains options for listing context keys.

type ListResult

type ListResult struct {
	Keys       []string `json:"keys"`
	Count      int      `json:"count"`
	NextCursor string   `json:"next_cursor,omitempty"`
}

ListResult contains the result of a context list operation.

type MergeOpts

type MergeOpts struct {
	RunID           *string             // Optional: nil for persistent context
	ExpectedVersion *int64              // For optimistic concurrency
	Strategy        types.MergeStrategy // Merge strategy (default: deep_merge)
	ArrayStrategy   types.ArrayStrategy // How to handle arrays in deep_merge
	UpdatedBy       string              // Agent/task identifier
}

MergeOpts contains options for merging context.

type MergeResult

type MergeResult struct {
	Key         string `json:"key"`
	Version     int64  `json:"version"`
	MergedValue any    `json:"merged_value"`
}

MergeResult contains the result of a context merge operation.

type SetOpts

type SetOpts struct {
	RunID           *string       // Optional: nil for persistent context
	ExpectedVersion *int64        // For optimistic concurrency
	TTL             time.Duration // Auto-expire duration (0 = no expiration)
	UpdatedBy       string        // Agent/task identifier
}

SetOpts contains options for setting context.

type SetResult

type SetResult struct {
	Key             string `json:"key"`
	Version         int64  `json:"version"`
	PreviousVersion int64  `json:"previous_version"`
}

SetResult contains the result of a context set operation.

Jump to

Keyboard shortcuts

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