UNPKG

@hotmeshio/hotmesh

Version:

Permanent-Memory Workflows & AI Agents

200 lines (199 loc) 5.42 kB
import { MetricTypes } from './stats'; import { StreamRetryPolicy } from './stream'; type ActivityExecutionType = 'trigger' | 'await' | 'worker' | 'activity' | 'emit' | 'interrupt' | 'cycle' | 'signal' | 'hook'; type Consumes = Record<string, string[]>; interface BaseActivity { title?: string; type?: ActivityExecutionType; subtype?: string; statusThreshold?: number; statusThresholdType?: 'stop' | 'throw' | 'stall'; input?: Record<string, any>; entity?: string; output?: Record<string, any>; settings?: Record<string, any>; job?: Record<string, any>; hook?: Record<string, any>; telemetry?: Record<string, any>; emit?: boolean; sleep?: number; expire?: number; persistent?: boolean; persist?: boolean; retry?: StreamRetryPolicy; cycle?: boolean; collationInt?: number; consumes?: Consumes; PRODUCES?: string[]; produces?: string[]; publishes?: string; subscribes?: string; trigger?: string; parent?: string; ancestors?: string[]; } interface Measure { measure: MetricTypes; target: string; } interface TriggerActivityStats { /** * dependent parent job id; including this allows the parent's * expiration/interruption events to cascade; set * `expire` in the YAML for the dependent graph * to 0 and provide the parent for dependent, * cascading interruption and cleanup */ parent?: string; /** * adjacent parent job id; this is the actual adjacent * parent in the graph, but it is not used for cascading expiration */ adjacent?: string; id?: { [key: string]: unknown; } | string; key?: { [key: string]: unknown; } | string; /** * @deprecated * return 'infinity' to disable */ granularity?: string; /** * @deprecated * what to capture */ measures?: Measure[]; } interface TriggerActivity extends BaseActivity { type: 'trigger'; stats?: TriggerActivityStats; entity?: string; } interface AwaitActivity extends BaseActivity { type: 'await'; eventName: string; timeout: number; await?: boolean; } interface WorkerActivity extends BaseActivity { type: 'worker'; topic: string; timeout: number; } interface CycleActivity extends BaseActivity { type: 'cycle'; ancestor: string; } interface HookActivity extends BaseActivity { type: 'hook'; } interface SignalActivity extends BaseActivity { type: 'signal'; subtype: 'one' | 'all'; topic: string; key_name?: string; key_value?: string; scrub?: boolean; signal?: Record<string, any>; resolver?: Record<string, any>; status?: string; code?: number; } interface InterruptActivity extends BaseActivity { type: 'interrupt'; /** * Optional Reason; will be used as the error `message` when thrown * @default 'Job Interrupted' */ reason?: string; /** * throw JobInterrupted error upon interrupting * @default true */ throw?: boolean; /** * Interrupt child/descendant jobs * @default false */ descend?: boolean; /** * Target job id (if not present the current job will be targeted) */ target?: string; /** * Optional topic to publish the interrupt message (if not present the current job topic will be used */ topic?: string; /** * Optional Error Code; will be used as the error `code` when thrown * @default 410 */ code?: number; /** * Optional stack trace */ stack?: string; } type ActivityType = BaseActivity | TriggerActivity | AwaitActivity | WorkerActivity | InterruptActivity | HookActivity | SignalActivity | CycleActivity; type ActivityData = Record<string, any>; /** * Type definition for activity metadata. */ type ActivityMetadata = { /** * Unique identifier for the activity. */ aid: string; /** * Type of the activity. */ atp: string; /** * Subtype of the activity. */ stp: string; /** * Timestamp when the activity was created, in GMT. */ ac: string; /** * Timestamp when the activity was last updated, in GMT. */ au: string; /** * Optional stringified JSON containing error details such as message, code, and an optional error object. */ err?: string; /** * OpenTelemetry span context for the first leg of the activity. */ l1s?: string; /** * OpenTelemetry span context for the second leg of the activity. */ l2s?: string; /** * Dimensional address, used for additional metadata. */ dad?: string; /** * Status of the activity, could be codes representing different states. */ as?: string; }; type ActivityContext = { data?: ActivityData | null; metadata: ActivityMetadata; hook?: ActivityData; }; type ActivityDuplex = 1 | 2; type ActivityDataType = { data?: Record<string, unknown>; metadata?: Record<string, unknown>; hook?: Record<string, unknown>; }; type ActivityLeg = 1 | 2; export { ActivityContext, ActivityData, ActivityDataType, ActivityDuplex, ActivityLeg, ActivityMetadata, ActivityType, Consumes, TriggerActivityStats, AwaitActivity, CycleActivity, HookActivity, SignalActivity, BaseActivity, InterruptActivity, TriggerActivity, WorkerActivity, };