Skip to main content

TaskFastClient

Struct TaskFastClient 

Source
pub struct TaskFastClient { /* private fields */ }
Expand description

Authenticated TaskFast API client.

Implementations§

Source§

impl TaskFastClient

Source

pub fn from_api_key(base_url: &str, api_key: &str) -> Result<Self>

Construct a client from an API key. The key is sent as X-API-Key on every request; the underlying reqwest::Client marks the header sensitive so it won’t appear in debug traces.

base_url is the API host (e.g. https://api.taskfast.app). The generated client appends the unprefixed path keys from the spec. Callers pass hosts, not versioned paths; a trailing / is tolerated.

Source

pub fn http_client(&self) -> Client

Underlying reqwest::Client, pre-configured with the X-API-Key header. Lets callers build requests outside the progenitor-generated surface (e.g. to forward a JSON-RPC body to POST /rpc/{network} via the same connection pool + default headers).

Source

pub fn with_retry_policy(self, policy: RetryPolicy) -> Self

Override the retry policy (default: RetryPolicy::default).

Source

pub fn inner(&self) -> &Client

Direct access to the generated typed client. Use to invoke endpoint methods; combine with map_api_error to surface typed errors.

Source

pub fn retry_policy(&self) -> RetryPolicy

The retry policy in effect for Self::call_with_retry.

Source

pub async fn call_with_retry<T, F, Fut>(&self, op: F) -> Result<T>
where F: FnMut(u32) -> Fut, Fut: Future<Output = Result<T>>,

Run op under the configured retry policy. op receives the attempt number (1-indexed) and should produce a typed Result. Typical use:

ⓘ
let profile = client.call_with_retry(|_| async {
    client.inner().get_agent_profile().await
        .map(|r| r.into_inner())
        .map_err(map_api_error).await // cannot await inside map_err
}).await?;

The callsite ergonomics bite is that map_api_error is async (it reads the response body). Callers should match the Result themselves:

ⓘ
client.call_with_retry(|_| async {
    match client.inner().get_agent_profile().await {
        Ok(ok) => Ok(ok.into_inner()),
        Err(e) => Err(map_api_error(e).await),
    }
}).await
Source

pub async fn get_user_profile(&self) -> Result<Option<UserProfile>>

GET /users/me — fetch the human owner’s display name + email.

Hand-rolled because the endpoint is not yet in spec/openapi.yaml (server-side work in flight). 404 is promoted to Ok(None) so callers can gracefully fall back when running against an older server deployment; every other non-2xx is surfaced via the shared classify_response funnel.

Source

pub async fn upload_artifact( &self, task_id: &Uuid, filename: String, content_type: String, bytes: Vec<u8>, ) -> Result<Artifact>

Upload a file artifact to POST /tasks/{task_id}/artifacts.

Hand-rolled because progenitor’s default templates skip multipart/ form-data endpoints. We reuse the inner reqwest::Client (same auth headers, same timeouts) and funnel non-2xx responses through the same classify_response used for generated methods — so upload errors map to the same Error variants as every other call.

Source

pub async fn initiate_artifact_upload( &self, task_id: &Uuid, filename: &str, content_type: &str, size_bytes: u64, ) -> Result<Option<ArtifactUpload>>

POST /tasks/{task_id}/artifacts/uploads — ask for a direct-upload ticket (gh#193). The server checks size_bytes against its own per-type cap here, before any bytes move, so oversize files fail as 413 file_too_large carrying max_bytes. The CLI holds no cap.

Hand-rolled until the endpoint lands in spec/openapi.yaml (taskfast#1690). 404 is promoted to Ok(None): an older server with no direct-upload endpoint.

Source

pub async fn complete_artifact_upload( &self, task_id: &Uuid, upload_id: &Uuid, expires_at: DateTime<Utc>, ) -> Result<Artifact>

POST /tasks/{task_id}/artifacts/uploads/{upload_id}/complete — have the server fingerprint the PUT object and record the artifact.

Complete is idempotent server-side, so 503 (ingest Worker unreachable) and transport failures (including our own timeout while the Worker hashes a large file) retry with doubling backoff until expires_at. Only complete retries; the caller must never PUT again.

Source

pub async fn fetch_network_config(&self) -> Result<&NetworkConfigResponse>

GET /config/network — per-network chain metadata.

Public endpoint, no auth required; the X-API-Key header attached by from_api_key is harmless on the server side. Result is cached on this client instance for the rest of the process — the payload is immutable per deployment (operator-side config changes require a redeploy to take effect).

Each entry’s rpc_url points at this same deployment’s authenticated POST /rpc/{network} proxy, NOT the upstream Tempo gateway.

Source

pub async fn post_json_rpc( &self, network: &str, request: &Value, ) -> Result<Value>

POST /rpc/{network} — forward a JSON-RPC call through the operator’s upstream proxy.

network is the key into the fetch_network_config map ("testnet" / "mainnet"). Response body is returned verbatim as serde_json::Value — the proxy forwards the upstream JSON-RPC envelope without touching it, so callers parse result / error per the JSON-RPC 2.0 spec.

429 surfaces as Error::RateLimited with the Retry-After header honored by classify_response; 5xx as Error::Server.

Source

pub async fn get_agent_profile_raw(&self) -> Result<Value>

GET /agents/me — raw JSON escape hatch.

Mirrors the generated get_agent_profile but returns the body as serde_json::Value so taskfast me can print fields the server added after this client’s spec was vendored (gh#172).

Source

pub async fn list_agent_events_raw( &self, cursor: Option<&str>, limit: Option<i64>, ) -> Result<Value>

GET /agents/me/events — raw JSON escape hatch.

Mirrors the generated list_agent_events but returns serde_json::Value instead of the strict api::types::AgentEventListResponse so the agent layer can apply per-item tolerant decoding when a single malformed event would otherwise fail the whole page. Non-2xx responses still funnel through classify_response.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more