taskstore

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: Apache-2.0 Imports: 12 Imported by: 2

Documentation

Overview

Package taskstore provides the contract and in-memory implementation of a2a.Task storage.

Index

Constants

This section is empty.

Variables

View Source
var ErrConcurrentModification = errors.New("concurrent modification")

ErrConcurrentModification indicates that optimistic concurrency control failed. Task store implementations MUST return it when the provided [UpdateRequest.PrevVersion] does not match the latest stored task version.

View Source
var ErrTaskAlreadyExists = errors.New("task already exists")

ErrTaskAlreadyExists indicates that a task with the provided ID already exists.

Functions

This section is empty.

Types

type Authenticator

type Authenticator func(context.Context) (string, error)

Authenticator is a function that returns the name of the user who created the task.

type InMemory

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

InMemory is an implementation of Store which stores tasks in memory. This means that store contents do not survive server restarts.

func NewInMemory

func NewInMemory(config *InMemoryStoreConfig) *InMemory

NewInMemory creates an empty InMemory store.

func (*InMemory) Create

func (s *InMemory) Create(ctx context.Context, task *a2a.Task) (TaskVersion, error)

Create implements Store interface.

func (*InMemory) Get

func (s *InMemory) Get(ctx context.Context, taskID a2a.TaskID) (*StoredTask, error)

Get implements Store interface.

func (*InMemory) List

List implements Store interface.

func (*InMemory) Update

func (s *InMemory) Update(ctx context.Context, req *UpdateRequest) (TaskVersion, error)

Update implements Store interface.

type InMemoryStoreConfig

type InMemoryStoreConfig struct {
	Authenticator Authenticator
	TimeProvider  func() time.Time
}

InMemoryStoreConfig is a configuration for InMemory store.

type Store

type Store interface {
	// Create creates a new task. It should return [ErrTaskAlreadyExists] if a task with the provided ID already exists.
	Create(ctx context.Context, task *a2a.Task) (TaskVersion, error)

	// Update updates the stored task. It should return [a2a.ErrTaskNotFound] if a task with the provided ID doesn't exist.
	Update(ctx context.Context, update *UpdateRequest) (TaskVersion, error)

	// Get retrieves a task by ID. If a Task doesn't exist the method should return [a2a.ErrTaskNotFound].
	Get(ctx context.Context, taskID a2a.TaskID) (*StoredTask, error)

	// List retrieves a list of tasks based on the provided request.
	List(ctx context.Context, req *a2a.ListTasksRequest) (*a2a.ListTasksResponse, error)
}

Store is an interface the server stack uses for storing and retrieving tasks.

type StoredTask

type StoredTask struct {
	// Task is the stored data.
	Task *a2a.Task
	// Version is the task store version used for tracking task modifications.
	Version TaskVersion
}

StoredTask represents a task stored in the task store.

type TaskVersion

type TaskVersion int64

TaskVersion is a version of the task stored on the server.

var TaskVersionMissing TaskVersion = 0

TaskVersionMissing is a special value used to denote that task version is not being tracked.

func (TaskVersion) After

func (v TaskVersion) After(another TaskVersion) bool

After returns true if the version is greater than the other version. The methods consider every state "latest" if the version is not tracked (TaskVersionMissing). It is expected that:

v1 := TaskVersionMissing
v2 := TaskVersionMissing
v1.After(v2) == v2.After(v1)

type UpdateRequest

type UpdateRequest struct {
	// Task represents the desired state of the task in the store.
	Task *a2a.Task
	// Event is the event that triggered the update. It can be a user message which is added to task history.
	Event a2a.Event
	// PrevTask is the previous state of the task in the store. It is passed for detecting concurrent udpates.
	PrevTask *a2a.Task
	// PrevVersion is the version of the task before the update. It is passed for detecting concurrent udpates.
	// If the provided version does not match the latest task version the update request MUST be rejected with [ErrConcurrentModification].
	PrevVersion TaskVersion
}

UpdateRequest represents a request to update a task.

Jump to

Keyboard shortcuts

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