|
| 1 | +// ============================================================================ |
| 2 | +// Component Props & Hook Return Types |
| 3 | +// ============================================================================ |
| 4 | + |
| 5 | +import type { ReactNode } from 'react' |
| 6 | +import type { ReactFlowInstance } from 'reactflow' |
| 7 | + |
| 8 | +import type { RequestInterceptor } from './api' |
| 9 | +import type { FlowData, FlowDataCallback, FlowNode } from './flow' |
| 10 | +import type { NodeData } from './node' |
| 11 | +import type { ValidationResult } from './validation' |
| 12 | + |
| 13 | +// ============================================================================ |
| 14 | +// Render Props Types |
| 15 | +// ============================================================================ |
| 16 | + |
| 17 | +export interface HeaderRenderProps { |
| 18 | + flowName: string |
| 19 | + isDirty: boolean |
| 20 | + onSave: () => void |
| 21 | + onExport: () => void |
| 22 | + onValidate: () => ValidationResult |
| 23 | +} |
| 24 | + |
| 25 | +export interface PaletteRenderProps { |
| 26 | + availableNodes: NodeData[] |
| 27 | + onAddNode: (nodeType: string, position?: { x: number; y: number }) => void |
| 28 | +} |
| 29 | + |
| 30 | +// ============================================================================ |
| 31 | +// Component Props & Hook Return Types |
| 32 | +// ============================================================================ |
| 33 | + |
| 34 | +export interface AgentflowProps { |
| 35 | + /** Flowise API server endpoint (e.g., "https://flowise-url.com") */ |
| 36 | + apiBaseUrl: string |
| 37 | + |
| 38 | + /** Authentication token for API calls */ |
| 39 | + token?: string |
| 40 | + |
| 41 | + /** Initial flow data to render */ |
| 42 | + initialFlow?: FlowData |
| 43 | + |
| 44 | + /** Flow ID for loading existing flow */ |
| 45 | + flowId?: string |
| 46 | + |
| 47 | + /** Array of allowed node component names to show in palette */ |
| 48 | + components?: string[] |
| 49 | + |
| 50 | + /** Callback when flow changes */ |
| 51 | + onFlowChange?: FlowDataCallback |
| 52 | + |
| 53 | + /** Callback when flow is saved */ |
| 54 | + onSave?: FlowDataCallback |
| 55 | + |
| 56 | + /** Whether to use dark mode (default: false) */ |
| 57 | + isDarkMode?: boolean |
| 58 | + |
| 59 | + /** Whether the canvas is read-only */ |
| 60 | + readOnly?: boolean |
| 61 | + |
| 62 | + /** Custom header renderer - receives save/export handlers */ |
| 63 | + renderHeader?: (props: HeaderRenderProps) => ReactNode |
| 64 | + |
| 65 | + /** Custom node palette renderer - receives available nodes */ |
| 66 | + renderNodePalette?: (props: PaletteRenderProps) => ReactNode |
| 67 | + |
| 68 | + /** Whether to show default header (ignored if renderHeader provided) */ |
| 69 | + showDefaultHeader?: boolean |
| 70 | + |
| 71 | + /** Whether to show default node palette (ignored if renderNodePalette provided) */ |
| 72 | + showDefaultPalette?: boolean |
| 73 | + |
| 74 | + /** Enable the AI flow generator feature (default: true) */ |
| 75 | + enableGenerator?: boolean |
| 76 | + |
| 77 | + /** Callback when flow is generated via AI */ |
| 78 | + onFlowGenerated?: FlowDataCallback |
| 79 | + |
| 80 | + /** |
| 81 | + * Optional callback to customize outgoing API requests (e.g., set `withCredentials`, add headers). |
| 82 | + * Receives the full Axios request config including auth headers — only modify what you need. |
| 83 | + * |
| 84 | + * **Security:** This callback executes in the request pipeline with access to all request |
| 85 | + * data, including authentication tokens. Only pass trusted, developer-authored functions. |
| 86 | + * Never use dynamically evaluated or user-generated code as the interceptor. |
| 87 | + * If the interceptor throws, the error is caught and the original config is used. |
| 88 | + */ |
| 89 | + requestInterceptor?: RequestInterceptor |
| 90 | +} |
| 91 | + |
| 92 | +export interface AgentFlowInstance { |
| 93 | + /** Get current flow data as serializable object */ |
| 94 | + getFlow(): FlowData |
| 95 | + |
| 96 | + /** Convert flow to JSON string */ |
| 97 | + toJSON(): string |
| 98 | + |
| 99 | + /** Validate the current flow */ |
| 100 | + validate(): ValidationResult |
| 101 | + |
| 102 | + /** Fit view to show all nodes */ |
| 103 | + fitView(): void |
| 104 | + |
| 105 | + /** Get the underlying ReactFlow instance */ |
| 106 | + getReactFlowInstance(): ReactFlowInstance | null |
| 107 | + |
| 108 | + /** Programmatically add a node */ |
| 109 | + addNode(nodeData: Partial<FlowNode>): void |
| 110 | + |
| 111 | + /** Clear all nodes and edges */ |
| 112 | + clear(): void |
| 113 | +} |
0 commit comments