Skip to content
Français

TaskContext

import type { TaskContext } from "@elie-laloum/outpost";
  • quotaOptional
    WorkflowQuotaPause | undefined
    Quota pause resumed by this attempt, with the captured conversation and retained branch when known; present only on the first attempt after the pause and never persisted separately.
  • interactionOptional
    TaskInteractionContext | undefined
    Durable state and suspension operations, supplied only for tasks declaring an interaction.
  • idempotencyKeyRequired
    string
    Stable SHA-256 identity of executionId and task key, preserved across retries and checkpoint replay. Pass it to an effect service with persistent deduplication.
  • observationOptional
    ObservationHub | undefined
    Task-scoped hub with workflow execution, task key and attempt; pass it to custom nested work such as speculate.
  • signalRequired
    AbortSignal
    Aborted when the workflow is cancelled, stops on an error or times out, or when this attempt’s timeoutMs expires.
  • attemptRequired
    number
    One-based attempt number, cumulative across retries and checkpoint resumes; 0 in condition and cache key callbacks.
  • executionIdRequired
    string
    Identity of the workflow execution, preserved across checkpoint resumption.
  • reportUsageRequired
    (usage: Usage) => void
    Add token usage to the workflow budget; throws outside the active attempt. Agent task definitions report their usage themselves.
  • reportUsageOnceOptional
    ((receipt: string, usage: Usage) => void) | undefined
    Add token usage only if the receipt ID has not already been recorded, including across checkpoint resumes.
  • checkpointOptional
    (() => Promise<void>) | undefined
    Save the workflow state now; does nothing without a checkpoint.
  • valueRequired
    <T>(dependency: Task<T>) => T
    Return the output of a task listed in after; throws for an undeclared dependency.
export interface TaskContext {
  /** Quota pause resumed by this attempt; present only on the first attempt after it. */
  readonly quota?: WorkflowQuotaPause;
  readonly interaction?: TaskInteractionContext;
  readonly idempotencyKey: string;
  readonly observation?: ObservationHub;
  readonly signal: AbortSignal;
  readonly attempt: number;
  readonly executionId: string;
  reportUsage(usage: Usage): void;
  reportUsageOnce?(receipt: string, usage: Usage): void;
  checkpoint?(): Promise<void>;
  value<T>(dependency: Task<T>): T;
}