Snodo.Extensions.Tasks.Task (snodo_tasks v0.1.0)

Copy Markdown View Source

Application-facing task state for the io.modelcontextprotocol/tasks extension.

The struct contains a small amount of private bookkeeping (used_input_keys) that never appears on the wire. State changes are explicit and terminal states are immutable, which lets an atomic store resolve cancellation/completion races.

Summary

Functions

Returns the flat SEP-2663 creation result, without detailed payload fields.

Returns the flat status-specific tasks/get result.

Returns the complete status-specific payload for notifications/tasks.

Returns an RFC 3339/ISO 8601 UTC timestamp at millisecond precision.

Types

status()

@type status() :: :working | :input_required | :completed | :failed | :cancelled

t()

@type t() :: %Snodo.Extensions.Tasks.Task{
  created_at: String.t(),
  error: map() | nil,
  id: String.t(),
  input_requests: map(),
  last_updated_at: String.t(),
  poll_interval_ms: pos_integer() | nil,
  result: map() | nil,
  status: status(),
  status_message: String.t() | nil,
  ttl_ms: pos_integer() | nil,
  used_input_keys: MapSet.t(String.t())
}

Functions

add_input(task, key, request, now)

@spec add_input(t(), String.t(), map(), String.t()) ::
  {:ok, t()}
  | {:error, :duplicate_input_key | :terminal | :invalid_input_request}

cancel(task, now, status_message \\ nil)

@spec cancel(t(), String.t(), String.t() | nil) :: {:ok, t()} | {:terminal, t()}

complete(task, result, now)

@spec complete(t(), map(), String.t()) :: {:ok, t()} | {:terminal, t()}

creation_result(task)

@spec creation_result(t()) :: map()

Returns the flat SEP-2663 creation result, without detailed payload fields.

detailed_result(task)

@spec detailed_result(t()) :: map()

Returns the flat status-specific tasks/get result.

fail(task, error, now, status_message \\ nil)

@spec fail(t(), map(), String.t(), String.t() | nil) :: {:ok, t()} | {:terminal, t()}

fulfill_inputs(task, keys, now)

@spec fulfill_inputs(t(), [String.t()], String.t()) :: {:ok, t(), [String.t()]}

new!(opts)

@spec new!(keyword()) :: t()

notification_params(task)

@spec notification_params(t()) :: map()

Returns the complete status-specific payload for notifications/tasks.

terminal?(task)

@spec terminal?(t()) :: boolean()

timestamp()

@spec timestamp() :: String.t()

Returns an RFC 3339/ISO 8601 UTC timestamp at millisecond precision.