Portal Community

Installation

pnpm add @edge-stream/workflow-events

Key Exports

import {
  WorkflowEventPlugin,     // IMessagePlugin implementation
  WorkflowTopics,          // topic constants
  WorkflowEventTypes,      // message type constants

  // TypeScript interfaces
  type WorkflowStartedEvent,
  type WorkflowCompletedEvent,
  type WorkflowFailedEvent,
  type NodeExecutionStartedEvent,
  type NodeExecutionCompletedEvent,
  type NodeExecutionFailedEvent,
  type WorkflowSuspendedEvent,
  type WorkflowResumedEvent,
} from '@edge-stream/workflow-events';

Topic Constants

import { WorkflowTopics } from '@edge-stream/workflow-events';

// Use constants instead of string literals — avoids typos
WorkflowTopics.STARTED              // 'workflow.started'
WorkflowTopics.COMPLETED            // 'workflow.completed'
WorkflowTopics.FAILED               // 'workflow.failed'
WorkflowTopics.SUSPENDED            // 'workflow.suspended'
WorkflowTopics.RESUMED              // 'workflow.resumed'
WorkflowTopics.NODE_STARTED         // 'workflow.nodeExecutionStarted'
WorkflowTopics.NODE_COMPLETED       // 'workflow.nodeExecutionCompleted'
WorkflowTopics.NODE_FAILED          // 'workflow.nodeExecutionFailed'
WorkflowTopics.NAMESPACE_PATTERN    // 'workflow.*'

Setup

import { WorkflowEventPlugin, WorkflowTopics } from '@edge-stream/workflow-events';

const plugin = new WorkflowEventPlugin();

// Register default hooks (NormalizationHook + WorkflowMapper + AuditLog)
plugin.createDefaultHooks().forEach(hook =>
  server.incomingPipeline.addHook(hook)
);

// Type-safe subscriptions
stream.subscribe<NodeExecutionCompletedEvent>(
  'bas',
  WorkflowTopics.NODE_COMPLETED,
  (envelope) => {
    observerPanel.updateNode(envelope.body.nodeId, 'completed', {
      duration: envelope.body.durationMs,
      output: envelope.body.outputData,
    });
  }
);

Observer Panel Integration

// Complete Observer Panel setup with typed handlers
import {
  WorkflowEventPlugin, WorkflowTopics,
  type NodeExecutionCompletedEvent, type WorkflowSuspendedEvent,
} from '@edge-stream/workflow-events';

function setupObserverPanel(stream, executionId: string) {
  const onNodeComplete = (envelope: IEnvelope<NodeExecutionCompletedEvent>) => {
    if (envelope.body.executionId !== executionId) return;
    panel.markNodeComplete(envelope.body.nodeId, envelope.body.durationMs);
  };

  const onSuspended = (envelope: IEnvelope<WorkflowSuspendedEvent>) => {
    if (envelope.body.executionId !== executionId) return;
    panel.showHilPrompt(envelope.body.hilTaskId);
  };

  stream.subscribe('bas', WorkflowTopics.NODE_COMPLETED, onNodeComplete);
  stream.subscribe('bas', WorkflowTopics.SUSPENDED, onSuspended);
}