PersistentAI API Documentation / @persistentai/fireflow-types
@persistentai/fireflow-types
Core type definitions and utilities for the PersistentAI flow-based programming framework. This package serves as the foundation for the entire PersistentAI ecosystem, providing a robust and type-safe infrastructure for building visual programming nodes, ports, flows, and execution engines.
Overview
@persistentai/fireflow-types provides:
- Type-Safe Port System: Define ports with rich type systems including primitives, objects, arrays, streams, and more
- Decorator-Based Node Creation: Build nodes using intuitive TypeScript decorators
- Event Management: Powerful event handling mechanisms for node and flow communication
- Flow Execution Engine: Core classes for executing computational graphs
- Serialization Utilities: Robust serialization/deserialization support for all components
This package is designed to handle the complex type relationships between nodes, ports, and flows while providing a developer-friendly API for building visual programming components.
Installation
# Before installing, make sure you have set up authentication for GitHub Packages
npm install @persistentai/fireflow-types
# or
yarn add @persistentai/fireflow-types
# or
pnpm add @persistentai/fireflow-typesAuthentication for GitHub Packages
To use this package, you need to configure npm to authenticate with GitHub Packages:
- Create a personal access token (PAT) with the
read:packagesscope on GitHub. - Add the following to your project's
.npmrcfile or to your global~/.npmrcfile:
@persistentai:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=YOUR_GITHUB_PATReplace YOUR_GITHUB_PAT with your actual GitHub personal access token.
Usage
Creating a Node with Decorators
import {
BaseNode,
ExecutionContext,
NodeExecutionResult,
Node,
Input,
Output,
String,
Number
} from '@persistentai/fireflow-types';
@Node({
title: 'Addition Node',
description: 'Adds two numbers together',
category: 'math',
})
class AdditionNode extends BaseNode {
@Input()
@Number({ defaultValue: 0 })
a: number = 0;
@Input()
@Number({ defaultValue: 0 })
b: number = 0;
@Output()
@Number()
result: number = 0;
async execute(context: ExecutionContext): Promise<NodeExecutionResult> {
this.result = this.a + this.b;
return {};
}
}Handling Complex Port Types
Object Ports
import { ObjectSchema, Port, PortObject, String, Number } from '@persistentai/fireflow-types';
@ObjectSchema()
class UserProfile {
@String()
name: string = '';
@Number({ min: 0, max: 120 })
age: number = 0;
}
// In your node class:
@PortObject({
schema: UserProfile,
defaultValue: new UserProfile()
})
profile: UserProfile = new UserProfile();Array Ports
import { PortArray, PortArrayNumber } from '@persistentai/fireflow-types';
// Array of numbers
@PortArrayNumber({ defaultValue: [1, 2, 3] })
numbers: number[] = [];
// Array with custom item configuration
@PortArray({
itemConfig: {
type: 'string',
minLength: 2
}
})
strings: string[] = [];Stream Ports
import { PortStream, MultiChannel } from '@persistentai/fireflow-types';
// Stream of strings
@PortStream({
itemConfig: { type: 'string' }
})
dataStream: MultiChannel<string> = new MultiChannel<string>();
// Later in your code:
async processStream() {
// Send data to the stream
this.dataStream.send("Hello");
this.dataStream.send("World");
// Close the stream when done
this.dataStream.close();
}
// Reading from a stream
async readStream() {
for await (const item of this.dataStream) {
console.log(item); // Prints "Hello", then "World"
}
}Enum Ports
import {
StringEnum,
NumberEnum,
PortEnumFromNative
} from '@persistentai/fireflow-types';
// String enum
@StringEnum(['Red', 'Green', 'Blue'], { defaultValue: 'Red' })
color: string = 'Red';
// Number enum
@NumberEnum([10, 20, 30], { defaultValue: '10' })
size: string = '10';
// From TypeScript enum
enum Direction {
Up = 'UP',
Down = 'DOWN',
Left = 'LEFT',
Right = 'RIGHT'
}
@PortEnumFromNative(Direction, { defaultValue: Direction.Up })
direction: Direction = Direction.Up;Creating and Executing a Flow
import {
Flow,
ExecutionContext,
ExecutionEngine
} from '@persistentai/fireflow-types';
// Create a flow
const flow = new Flow({ name: "Simple Calculation Flow" });
// Add nodes
const addNode = new AdditionNode('add1');
addNode.initialize();
flow.addNode(addNode);
// Set values
addNode.a = 5;
addNode.b = 10;
// Execute the flow
const abortController = new AbortController();
const context = new ExecutionContext(flow.id, abortController);
const executionEngine = new ExecutionEngine(flow, context);
// Subscribe to events
executionEngine.onAll((event) => {
console.log(`Event: ${event.type}`, event.data);
});
// Run the flow
await executionEngine.execute();
// Check results
console.log(`Result: ${addNode.result}`); // Should print 15Port Visibility Rules
import {
PortVisibility,
Boolean,
String
} from '@persistentai/fireflow-types';
class ConditionalNode extends BaseNode {
@Boolean({ defaultValue: false })
showAdvanced: boolean = false;
@PortVisibility({
showIf: (node) => (node as ConditionalNode).showAdvanced
})
@String()
advancedOption: string = '';
// The advancedOption port will only be visible when showAdvanced is true
}Core Components
Nodes
The BaseNode class is the foundation for all computational nodes and implements the INode interface. It provides:
- Port management
- Event handling
- Serialization/deserialization
- Execution lifecycle methods
Ports
Ports are the inputs and outputs of nodes. The system supports various port types:
- Primitive Ports: String, Number, Boolean
- Complex Ports: Array, Object
- Special Ports: Stream, Enum, Any
Flows
The Flow class represents a computational graph composed of nodes and edges. It provides:
- Node and edge management
- Graph validation
- Event propagation
- Serialization/deserialization
Execution Engine
The ExecutionEngine handles flow execution with features like:
- Parallel execution support
- Dependency resolution
- Error handling
- Execution events
- Debugging capabilities
Advanced Features
Decorators
The package includes a rich set of decorators for defining nodes and ports:
- @Node: Main node class decorator
- @Port: Generic port decorator
- @Input/@Output: Port direction decorators
- @String, @Number, @Boolean: Basic type decorators
- @PortArray, @PortObject, @PortStream: Complex type decorators
- @PortVisibility: Conditional visibility control
Event System
A comprehensive event system allows communication between components:
- Node events (status change, port updates)
- Flow events (node additions, edge connections)
- Execution events (start, completion, errors)
Debugging Tools
Built-in debugging capabilities include:
- Breakpoints
- Step-by-step execution
- Execution event monitoring
License
BUSL-1.1 - Business Source License
Related Packages
- @persistentai/fireflow-frontend: Frontend components for visual flow programming
- @persistentai/fireflow-backend: Backend services for flow execution
- @persistentai/fireflow-nodes: Collection of pre-built nodes
Enumerations
- EdgeStatus
- ExecutionEventEnum
- FlowEventType
- NodeEventType
- NodeExecutionStatus
- NodeStatus
- PortErrorType
- ValidationMessageType
Classes
- AnyPort
- ArrayPort
- AsyncQueue
- BaseNode
- BasePort
- BooleanPort
- DeterministicExecutionEngine
- Edge
- EdgeTransferService
- EnumPort
- EventManager
- EventNode
- EventQueue
- EventSchema
- ExecutionContext
- ExecutionEngine
- ExecutionEventImpl
- Flow
- FlowDebugger
- FlowMigration
- FlowRefPort
- MultiChannel
- NodeCatalog
- NodeRegistry
- NumberPort
- ObjectPort
- PlanInterpreter
- PortConfigProcessor
- PortError
- PortFactory
- PortPluginRegistry
- PortResolver
- RuleBuilder
- SecretPort
- Semaphore
- SPTreeExecutionEngine
- StreamPort
- StringPort
- TransferEngine
Interfaces
- AdjacencyList
- AnyPortConfig
- ArrayPortConfig
- ArrayPortItemConfigObject
- BasePortConfig
- BooleanPortConfig
- BoundaryInputs
- CategorizedNodes
- CategoryMetadata
- CategoryStyle
- ClusterDetectionResult
- Connection
- Context
- DebuggerController
- DebuggerState
- DeterministicExecutionOptions
- Dimensions
- EdgeAddedEventData
- EdgeAnchor
- EdgeErrorEvent
- EdgeEvent
- EdgeMetadata
- EdgeMetadataUpdatedEventData
- EdgeRemovedEventData
- EdgesAddedEventData
- EdgeStatusChangeEvent
- EdgeStyle
- EdgeTransferEvent
- EdgeUpdatedEventData
- EdgeValidationEvent
- EmittedEvent
- EncryptedSecretValue
- EngineState
- EnumPortConfig
- EventDataMap
- EventTypeToInterface
- ExecutionEvent
- ExecutionEventData
- FileResolverDependencies
- FlowEvent
- FlowInitEnd
- FlowInitStart
- FlowMetadata
- FlowPorts
- ForkJoinRegion
- FusedClusterUnit
- FusedPlan
- HandleEventOptions
- HandleExecutionEventOptions
- IBranchHandle
- IBranchParams
- ICommitResult
- ICoreNode
- IDBOSContextService
- IEdge
- IEditResult
- IExecutionServices
- IFileEdit
- IFileStat
- IFlow
- IGlobOptions
- IGrepMatch
- IGrepOptions
- INode
- IObjectSchema
- IPort
- IPortPlugin
- IPresignedUrlResult
- IStatusEntry
- IStepOptions
- ISubflowHandle
- ISubflowParams
- ISubflowResult
- ITreeNode
- IVFSContextService
- IVFSWriteContextService
- IWorkflowStatus
- IWriteResult
- JSONObject
- JsonSchema7Meta
- JsonSchema7RefType
- LeafPlan
- MetadataUpdatedEventData
- NodeAddedEventData
- NodeEventBase
- NodeExecutionAnnotations
- NodeExecutionContext
- NodeExecutionResult
- NodeMetadata
- NodeMetadataWithPorts
- NodeParentChangeEvent
- NodeParentUpdatedEventData
- NodeRemovedEventData
- NodesAddedEventData
- NodeStatusChangeEvent
- NodesUpdatedEventData
- NodeTitleChangeEvent
- NodeUIChangedEventData
- NodeUIChangeEvent
- NodeUIDimensionsChangedEventData
- NodeUIDimensionsChangeEvent
- NodeUIMetadata
- NodeUIPositionChangedEventData
- NodeUIPositionChangeEvent
- NodeUIState
- NodeUIStyle
- NodeUpdatedEventData
- NodeValidationResult
- NumberPortConfig
- ObjectPortConfig
- ObjectSchemaCopyToConfig
- ParallelPlan
- PortConnectedEvent
- PortCreatedEventData
- PortCreateEvent
- PortDeleteEvent
- PortDisconnectedEvent
- PortRemovedEventData
- PortUpdateConfig
- PortUpdatedEventData
- PortUpdateEvent
- PortVisibilityConfig
- Position
- PostExecuteResult
- PreExecuteResult
- PureCluster
- RegistryPlugin
- ResolveOptions
- SecretPortConfig
- SecretTypeMetadata
- SeriesPlan
- SPTreeExecutionOptions
- StreamBridgeEdges
- StreamPortConfig
- StringPortConfig
- TransferContext
- TransferEngineOptions
- TransferResult
- TransferRule
- TransformerTraceCallbacks
- ValidationMessage
Type Aliases
- AllExecutionEvents
- AnyPortValue
- ArrayPortConfigUIType
- ArrayPortItemConfig
- ArrayPortItemConfigArray
- ArrayPortValue
- BasePortConfigType
- BasePortConfigUIType
- BooleanPortConfigUIType
- BooleanPortValue
- ConfigTypeMap
- DebuggerCommand
- EdgeEvents
- EdgeEventType
- EmittedEventContext
- EnsureJSONSerializable
- EnumPortConfigUIType
- EnumPortValue
- EventDataType
- EventReturnType
- ExecutionEventDataType
- ExecutionEventHandler
- ExecutionEventHandlerMap
- ExecutionEventType
- ExecutionExternalEvent
- ExecutionOptions
- ExecutionPlan
- ExtractValue
- FileInput
- FileInputType
- FileMetadata
- FileReference
- FileReferenceArray
- FileReferenceOrNull
- FlowEventHandler
- FlowEventHandlerMap
- FlowEvents
- FlowRef
- IntegrationContext
- IPortConfig
- IPortConfigForDecorator
- IPortValue
- JSONArray
- JSONPrimitive
- JsonSchema7AnyType
- JsonSchema7ArrayType
- JsonSchema7BooleanType
- JsonSchema7EnumType
- JsonSchema7LiteralType
- JsonSchema7NullType
- JsonSchema7NumberType
- JsonSchema7ObjectType
- JsonSchema7StringType
- JsonSchema7Type
- JsonSchema7TypeUnion
- JsonSchema7UnionType
- JSONValue
- Manifest
- NodeCategory
- NodeClass
- NodeConstructor
- NodeEvent
- NodeEventDataType
- NumberPortConfigUIType
- NumberPortValue
- ObjectPortConfigUIType
- ObjectPortOptions
- ObjectPortSchemaInput
- ObjectPortValue
- ObjectPortValueFromSchema
- OnPortResolvedCallback
- OnStreamPublishedCallback
- PersistentAIContext
- PortConfigByType
- PortDecoratorOptions
- PortDirectionEnum
- PortInstance
- PortInstanceFromConfig
- PortPredicate
- PortType
- PortUpdateHandler
- RunnerType
- SecretPortValue
- SecretType
- SecretTypeMap
- SerializedEdge
- SerializedFlow
- SerializedNodeType
- SerializedNodeTypeV1Legacy
- StreamPortConfigUIType
- StreamPortValue
- StringPortConfigUIType
- StringPortValue
- TargetPortPredicate
- TextFileContentType
- TransferStrategy
- ValueTypeMap
- WalletContext
Variables
- AnyPortPlugin
- arrayPortConfigUISchema
- ArrayPortPlugin
- basePortConfigSchema
- basePortConfigUISchema
- booleanPortConfigUISchema
- BooleanPortPlugin
- compatibleSecretTypes
- DEFAULT_SUBFLOW_LIMITS
- DEFAULT_SUBFLOW_TIMEOUT_MS
- DefaultPosition
- defaultTransferRules
- EdgeAnchorSchema
- EdgeMetadataSchema
- enumPortConfigUISchema
- EnumPortPlugin
- ExecutionCancelledReason
- ExecutionExternalEventSchema
- ExecutionOptionsSchema
- ExecutionStoppedByDebugger
- FileInputSchema
- FileMetadataSchema
- FileReferenceSchema
- FlowPortsSchema
- FlowRefSchema
- IntegrationContextSchema
- JSONPrimitiveSchema
- JSONValueSchema
- ManifestSchema
- MultiChannelSchema
- NodeExecutionResultSchema
- NodeMetadataSchema
- NodeUIMetadataSchema
- NodeValidationResultSchema
- numberPortConfigUISchema
- NumberPortPlugin
- objectPortConfigUISchema
- ObjectPortPlugin
- PersistentAIContextSchema
- PORT_TYPES
- PortDirection
- portRegistry
- Predicates
- SecretPortPlugin
- secretTypeMetadata
- secretTypeSchemas
- SerializedEdgeSchema
- SerializedFlowMetadataSchema
- SerializedFlowSchema
- SerializedNodeSchema
- SerializedNodeSchemaV1Legacy
- SerializedPortSchema
- SP_LOG_PREFIX
- Strategies
- streamPortConfigUISchema
- StreamPortPlugin
- stringPortConfigUISchema
- StringPortPlugin
- TEXT_FILE_CONTENT_TYPES
- ValidationMessageSchema
- WalletContextSchema
Functions
- applyPortUpdateHandlers
- applyVisibilityRules
- areTypesCompatible
- branchContainsDBOSNodes
- branchRequiresSequentialExecution
- buildAdjacencyList
- buildExecutionPlan
- buildUnion
- canConnect
- checkSchemaCompatibility
- classifyNode
- classifyStreamBridgeEdges
- cleanupPortConfigFromIds
- collectAllNodeIds
- computePostDominators
- createAnyConfig
- createAnyPortConfig
- createAnyValue
- createArrayValue
- createBooleanConfig
- createBooleanValue
- createDataUri
- createDefaultTransferEngine
- createEnumConfig
- createEnumPortConfig
- createEnumValue
- createEventHandler
- createExecutionEventHandler
- createFileReference
- createImageFileReference
- createNumberConfig
- createNumberValue
- createObjectConfig
- createObjectPortConfig
- createObjectSchema
- createObjectValue
- createQueueIterator
- createStreamConfig
- createStreamPortConfig
- createStreamValue
- createStringConfig
- createStringValue
- createTypedExecutionHandler
- createTypedHandler
- deepCopy
- DefaultValue
- Description
- deserialize
- detectDisconnectedComponents
- detectFileInputType
- detectForkJoinRegions
- detectPureClusters
- executeFusedCluster
- executeLeafNode
- executeLeafNodePhase1
- filterPorts
- findBoundaryInputEdges
- findBoundaryOutputEdges
- findPort
- findPortByKey
- findStreamChannelsInValue
- findStreamFieldsInSchema
- flowInputStreamKey
- flowOutputStreamKey
- formatFileSize
- generateFileID
- generateFileRefID
- generatePortID
- generatePortIDArrayElement
- generateShareID
- getDefaultTransferEngine
- getEffectiveType
- getExtensionFromMimeType
- getFirstNodeId
- getNodeMetadata
- getNodeRegistryInstance
- getObjectSchema
- getObjectSchemaCopyToConfigs
- getObjectSchemaMetadata
- getOrCreateNodeMetadata
- getPortMetadata
- getPortsMetadata
- getPortUpdateHandlers
- getSuperJSONInstance
- getTransformerTraceCallbacks
- getVisibilityRules
- handleExecutionEvent
- handleFlowEvent
- hasCycle
- Id
- Input
- isAnyPortConfig
- isAnyPortValue
- isArrayPortConfig
- isArrayPortValue
- isBooleanPortConfig
- isBooleanPortValue
- isCompatibleSecretType
- isDeepEqual
- isEnumPortConfig
- isEnumPortValue
- isFileID
- isFileReference
- isFileReferenceArray
- isFileRefID
- isIPort
- isNodeEventType
- isNumberPortConfig
- isNumberPortValue
- isObjectPortConfig
- isObjectPortValue
- isShareID
- isStreamingEdge
- isStreamPortConfig
- isStreamPortValue
- isStringPortConfig
- isStringPortValue
- isSupportedSecretType
- isTextContentType
- jsonSchemaToPortConfig
- mapPorts
- Metadata
- Name
- newEvent
- Node
- NumberEnum
- ObjectSchema
- ObjectSchemaCopyTo
- OnPortUpdate
- Output
- parseDataUri
- Passthrough
- Port
- PortAny
- PortArray
- PortArrayBoolean
- PortArrayNested
- PortArrayNumber
- PortArrayObject
- PortArrayString
- PortBoolean
- PortEnum
- PortEnumFromNative
- PortEnumFromObject
- portKey
- PortNumber
- PortObject
- PortSecret
- PortStream
- portStreamKey
- PortString
- PortVisibility
- pumpChannelToDBOSStream
- pumpDBOSStreamToChannel
- reducePorts
- registerEdgeTransformers
- registerFlowTransformers
- registerNodeTransformers
- registerSuperjsonTransformers
- resetDefaultEngine
- resolveFileInput
- resolveFileInputArray
- resolveObjectSchema
- resolvePortConfig
- restoreOutputPorts
- serialize
- serializeOutputPorts
- serializePlan
- setNestedValue
- setNodeMetadata
- setObjectSchemaMetadata
- setPortMetadata
- setPortsMetadata
- setTransformerTraceCallbacks
- startInboundBridge
- startOutboundBridge
- streamKeyForEdge
- StringEnum
- Title
- topologicalSort
- topologicalSortCluster
- traversePorts
- unwrapAnyPort
- updateNodeMetadata
- updateObjectSchemaMetadata
- updatePortMetadata
- validateAnyValue
- validateArrayValue
- validateDAG
- validateEnumValue
- validateNumberValue
- validateObjectValue
- validateStreamValue
- validateStringValue
- withTimeout
- wrapSecret