Documentation
¶
Overview ¶
Package taskstore provides the contract and in-memory implementation of a2a.Task storage.
Index ¶
- Variables
- type Authenticator
- type InMemory
- func (s *InMemory) Create(ctx context.Context, task *a2a.Task) (TaskVersion, error)
- func (s *InMemory) Get(ctx context.Context, taskID a2a.TaskID) (*StoredTask, error)
- func (s *InMemory) List(ctx context.Context, req *a2a.ListTasksRequest) (*a2a.ListTasksResponse, error)
- func (s *InMemory) Update(ctx context.Context, req *UpdateRequest) (TaskVersion, error)
- type InMemoryStoreConfig
- type Store
- type StoredTask
- type TaskVersion
- type UpdateRequest
Constants ¶
This section is empty.
Variables ¶
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.
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 ¶
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) List ¶
func (s *InMemory) List(ctx context.Context, req *a2a.ListTasksRequest) (*a2a.ListTasksResponse, error)
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.