Skip to content

@codesoul-co/hypha-core / modules/runtime/session-command-worker

Using this module

Use the Session command worker module for executing runtime behavior at this boundary. It exports 1 class, 3 interfaces, 3 types.

Import from the package entrypoint

ts
import {
  DurableSessionCommandWorker,
} from '@codesoul-co/hypha-core';

import type {
  DurableSessionCommandWorkerOptions,
  SessionCommandHandlerContext,
  SessionCommandWorkerResult,
  SessionCommandHandler,
  SessionCommandHandlerResult,
  SessionCommandWorkerDisposition,
} from '@codesoul-co/hypha-core';

Usage patterns

  • Use the 6 type/interface exports as static contracts in application code, adapters, or tests. Import them with import type; they do not exist at runtime.
  • The module exposes 1 class as constructable runtime implementations. Each symbol entry lists its constructor and public methods.

Public exports

SymbolKindSignatureDescription
DurableSessionCommandWorkerclassnew DurableSessionCommandWorker(options: DurableSessionCommandWorkerOptions): DurableSessionCommandWorkerClaims and resolves one durable Session command without owning a polling loop. Command handlers must explicitly classify expected retry and failure outcomes.
DurableSessionCommandWorkerOptionsinterfaceinterface DurableSessionCommandWorkerOptionsDurable Session Command Worker Options interface with 11 public fields or methods.
SessionCommandHandlerContextinterfaceinterface SessionCommandHandlerContextSession Command Handler Context interface with 4 public fields or methods.
SessionCommandWorkerResultinterfaceinterface SessionCommandWorkerResultSession Command Worker Result interface with 5 public fields or methods.
SessionCommandHandlertypetype SessionCommandHandler = (context: Readonly<SessionCommandHandlerContext>) => Promise<SessionCommandHandlerResult>Public type alias for Session Command Handler; the declaration contains its complete type expression.
SessionCommandHandlerResulttypetype SessionCommandHandlerResult = { disposition: 'applied'; resultRunId?: string; resultEventIds?: string[]; } | { disposition: 'retry'; availableAt?: string; } | { disposition: 'failed'; rejectionCode: string; deadLetter?: boolean; }Public type alias for Session Command Handler Result; the declaration contains its complete type expression.
SessionCommandWorkerDispositiontypetype SessionCommandWorkerDisposition = 'idle' | 'applied' | 'retry_scheduled' | 'failed' | 'dead_lettered' | 'lease_lost' | 'aborted'Public type alias for Session Command Worker Disposition; the declaration contains its complete type expression.

DurableSessionCommandWorker

Claims and resolves one durable Session command without owning a polling loop. Command handlers must explicitly classify expected retry and failure outcomes.

Declaration

text
export declare class DurableSessionCommandWorker {
    constructor(options: DurableSessionCommandWorkerOptions);
    processNext(scope?: SessionQueueScope, signal?: AbortSignal): Promise<SessionCommandWorkerResult>;
}

Public members

MemberKindSignatureDescription
constructorconstructor(options: DurableSessionCommandWorkerOptions): DurableSessionCommandWorkerCreates an instance of this class.
processNextmethodprocessNext(scope?: SessionQueueScope, signal?: AbortSignal): Promise<SessionCommandWorkerResult>Public method; parameters and return type are shown in the signature.

DurableSessionCommandWorkerOptions

Durable Session Command Worker Options interface with 11 public fields or methods.

Declaration

text
export interface DurableSessionCommandWorkerOptions {
    queue: SessionQueue;
    workerId: string;
    leaseMs: number;
    handlers: Partial<Record<SessionCommandType, SessionCommandHandler>>;
    now?: () => string;
    renewalIntervalMs?: number;
    maxHandlerDurationMs?: number;
    wait?: (delayMs: number, signal: AbortSignal) => Promise<void>;
    onLeaseRenewalFailure?: (error: unknown, claim: Readonly<SessionCommandClaim>) => void;
    operationalTelemetry?: RuntimeOperationalTelemetry;
    monotonicNow?: () => number;
}

Contract members

MemberKindSignatureDescription
handlerspropertyhandlers: Partial<Record<"user_input" | "cancel" | "signal" | "start_run" | "resume" | "transition" | "continue_react" | "close_session", SessionCommandHandler>>Public property; its type, readonly modifier and optionality are shown in the signature.
leaseMspropertyleaseMs: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
maxHandlerDurationMspropertymaxHandlerDurationMs?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
monotonicNowmethodmonotonicNow?(): numberPublic method; parameters and return type are shown in the signature.
nowmethodnow?(): stringPublic method; parameters and return type are shown in the signature.
onLeaseRenewalFailuremethodonLeaseRenewalFailure?(error: unknown, claim: Readonly<SessionCommandClaim>): voidPublic method; parameters and return type are shown in the signature.
operationalTelemetrypropertyoperationalTelemetry?: RuntimeOperationalTelemetryPublic property; its type, readonly modifier and optionality are shown in the signature.
queuepropertyqueue: SessionQueuePublic property; its type, readonly modifier and optionality are shown in the signature.
renewalIntervalMspropertyrenewalIntervalMs?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
waitmethodwait?(delayMs: number, signal: AbortSignal): Promise<void>Public method; parameters and return type are shown in the signature.
workerIdpropertyworkerId: stringPublic property; its type, readonly modifier and optionality are shown in the signature.

SessionCommandHandlerContext

Session Command Handler Context interface with 4 public fields or methods.

Declaration

text
export interface SessionCommandHandlerContext {
    command: Readonly<SessionCommandRecord>;
    signal: AbortSignal;
    claimToken: string;
    leaseEpoch: number;
}

Contract members

MemberKindSignatureDescription
claimTokenpropertyclaimToken: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
commandpropertycommand: Readonly<SessionCommandRecord>Public property; its type, readonly modifier and optionality are shown in the signature.
leaseEpochpropertyleaseEpoch: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
signalpropertysignal: AbortSignalPublic property; its type, readonly modifier and optionality are shown in the signature.

SessionCommandWorkerResult

Session Command Worker Result interface with 5 public fields or methods.

Declaration

text
export interface SessionCommandWorkerResult {
    disposition: SessionCommandWorkerDisposition;
    commandId?: string;
    commandType?: SessionCommandType;
    attempts?: number;
    rejectionCode?: string;
}

Contract members

MemberKindSignatureDescription
attemptspropertyattempts?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
commandIdpropertycommandId?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
commandTypepropertycommandType?: "user_input" | "cancel" | "signal" | "start_run" | "resume" | "transition" | "continue_react" | "close_session"Public property; its type, readonly modifier and optionality are shown in the signature.
dispositionpropertydisposition: SessionCommandWorkerDispositionPublic property; its type, readonly modifier and optionality are shown in the signature.
rejectionCodepropertyrejectionCode?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.

SessionCommandHandler

Public type alias for Session Command Handler; the declaration contains its complete type expression.

Declaration

text
export type SessionCommandHandler = (context: Readonly<SessionCommandHandlerContext>) => Promise<SessionCommandHandlerResult>;

SessionCommandHandlerResult

Public type alias for Session Command Handler Result; the declaration contains its complete type expression.

Declaration

text
export type SessionCommandHandlerResult = {
    disposition: 'applied';
    resultRunId?: string;
    resultEventIds?: string[];
} | {
    disposition: 'retry';
    availableAt?: string;
} | {
    disposition: 'failed';
    rejectionCode: string;
    deadLetter?: boolean;
};

SessionCommandWorkerDisposition

Public type alias for Session Command Worker Disposition; the declaration contains its complete type expression.

Declaration

text
export type SessionCommandWorkerDisposition = 'idle' | 'applied' | 'retry_scheduled' | 'failed' | 'dead_lettered' | 'lease_lost' | 'aborted';