tasks¶
Package tasks provides a client for the Emergent Tasks API.
Tasks are human-review items — such as AI-generated suggestions or flagged content — that require explicit acceptance, rejection, or cancellation. They are project-scoped and tied to a review/resolution workflow.
Note: This client tracks reviewable work items, not background job execution. See monitoring for extraction job monitoring.
Import¶
Client¶
Obtained via sdk.Client.Tasks after calling client.SetContext(orgID, projectID).
SetContext¶
Updates the X-Org-ID and X-Project-ID headers sent with every request. Thread-safe.
Methods¶
List¶
Returns paginated tasks for the context project. Pass opts.ProjectID to override the header-based project.
Endpoint: GET /api/tasks
GetCounts¶
Returns task counts broken down by status for a specific project.
Endpoint: GET /api/tasks/counts
ListAll¶
Returns paginated tasks across all projects accessible to the authenticated user. Useful for global dashboards.
Endpoint: GET /api/tasks/all
GetAllCounts¶
Returns aggregated task counts across all projects for the authenticated user.
Endpoint: GET /api/tasks/all/counts
GetByID¶
Returns a specific task by ID. projectID may be provided as a query param or left empty to use the context header.
Endpoint: GET /api/tasks/{taskID}
Resolve¶
func (c *Client) Resolve(ctx context.Context, taskID, projectID string, resolveReq *ResolveTaskRequest) error
Marks a task as accepted or rejected. Resolution must be "accepted" or "rejected".
Endpoint: POST /api/tasks/{taskID}/resolve
Cancel¶
Cancels a pending task. Only pending tasks may be cancelled.
Endpoint: POST /api/tasks/{taskID}/cancel
Types¶
Task¶
type Task struct {
ID string `json:"id"`
ProjectID string `json:"projectId"`
Title string `json:"title"`
Description *string `json:"description,omitempty"`
Type string `json:"type"`
Status string `json:"status"`
ResolvedAt *time.Time `json:"resolvedAt,omitempty"`
ResolvedBy *string `json:"resolvedBy,omitempty"`
ResolutionNotes *string `json:"resolutionNotes,omitempty"`
SourceType *string `json:"sourceType,omitempty"`
SourceID *string `json:"sourceId,omitempty"`
Metadata json.RawMessage `json:"metadata,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
| Field | Description |
|---|---|
Type |
Category of task (e.g., "suggestion", "review") |
Status |
"pending", "accepted", "rejected", "cancelled" |
SourceType / SourceID |
The resource that generated this task |
ResolvedBy |
User ID who resolved the task |
ResolutionNotes |
Optional notes attached at resolution |
TaskCounts¶
type TaskCounts struct {
Pending int64 `json:"pending"`
Accepted int64 `json:"accepted"`
Rejected int64 `json:"rejected"`
Cancelled int64 `json:"cancelled"`
}
TaskListResponse¶
TaskResponse¶
ResolveTaskRequest¶
type ResolveTaskRequest struct {
Resolution string `json:"resolution"` // "accepted" or "rejected"
ResolutionNotes *string `json:"resolutionNotes,omitempty"`
}
ListOptions¶
type ListOptions struct {
ProjectID string // Override context project; passed as query param
Status string // "pending", "accepted", "rejected", "cancelled"
Type string // Filter by task type
Limit int // Max results (1–100)
Offset int // Pagination offset
}
Example¶
// Count pending tasks in the current project
counts, err := client.Tasks.GetCounts(ctx, "")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Pending review items: %d\n", counts.Pending)
// List and resolve each pending task
list, err := client.Tasks.List(ctx, &tasks.ListOptions{Status: "pending"})
if err != nil {
log.Fatal(err)
}
for _, t := range list.Data {
fmt.Printf("Reviewing: %s (%s)\n", t.Title, t.Type)
notes := "Looks good"
err := client.Tasks.Resolve(ctx, t.ID, t.ProjectID, &tasks.ResolveTaskRequest{
Resolution: "accepted",
ResolutionNotes: ¬es,
})
if err != nil {
log.Printf("failed to resolve task %s: %v", t.ID, err)
}
}