• Creates a typed proxy for calling activity functions with durable execution, automatic retry, and deterministic replay. This is the primary way to invoke side-effectful code (HTTP calls, database writes, file I/O) from within a workflow function.

    Activities execute on a separate worker process via message queue, isolating side effects from the deterministic workflow function. Each proxied call is assigned a unique execution index, and on replay the stored result is returned without re-executing the activity.

    • Default: Activities route to {workflowTaskQueue}-activity.
    • Explicit taskQueue: Activities route to {taskQueue}-activity, enabling shared/global activity worker pools across workflows.
    Option Default Description
    maximumAttempts 50 Max retries before the activity is marked as failed
    backoffCoefficient 2 Exponential backoff multiplier
    maximumInterval '5m' Cap on delay between retries
    throwOnError true Throw on activity failure (set false to return the error)
    import { Durable } from '@hotmeshio/hotmesh';
    import * as activities from './activities';

    // Standard pattern: register and proxy activities inline
    export async function orderWorkflow(orderId: string): Promise<string> {
    const { validateOrder, chargePayment, sendConfirmation } =
    Durable.workflow.proxyActivities<typeof activities>({
    activities,
    retryPolicy: {
    maximumAttempts: 3,
    backoffCoefficient: 2,
    maximumInterval: '30s',
    },
    });

    await validateOrder(orderId);
    const receipt = await chargePayment(orderId);
    await sendConfirmation(orderId, receipt);
    return receipt;
    }
    // Remote activities: reference a pre-registered worker pool by taskQueue
    interface PaymentActivities {
    processPayment: (amount: number) => Promise<string>;
    refundPayment: (txId: string) => Promise<void>;
    }

    export async function refundWorkflow(txId: string): Promise<void> {
    const { refundPayment } =
    Durable.workflow.proxyActivities<PaymentActivities>({
    taskQueue: 'payments',
    retryPolicy: { maximumAttempts: 5 },
    });

    await refundPayment(txId);
    }
    // Interceptor with shared activity pool
    const auditInterceptor: WorkflowInterceptor = {
    async execute(ctx, next) {
    const { auditLog } = Durable.workflow.proxyActivities<{
    auditLog: (id: string, action: string) => Promise<void>;
    }>({
    taskQueue: 'shared-audit',
    retryPolicy: { maximumAttempts: 3 },
    });

    await auditLog(ctx.get('workflowId'), 'started');
    const result = await next();
    await auditLog(ctx.get('workflowId'), 'completed');
    return result;
    },
    };
    // Graceful error handling (no throw)
    const { riskyOperation } = Durable.workflow.proxyActivities<typeof activities>({
    activities,
    retryPolicy: { maximumAttempts: 1, throwOnError: false },
    });

    const result = await riskyOperation();
    if (result instanceof Error) {
    // handle gracefully
    }

    Type Parameters

    • ACT

      The activity type map (use typeof activities for inline registration).

    Parameters

    • Optionaloptions: ActivityConfig

      Activity configuration including retry policy and routing.

    Returns ProxyType<ACT>

    A typed proxy object mapping activity names to their durable wrappers.