@runtypelabs/react-flow 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +289 -0
- package/example/.env.example +3 -0
- package/example/index.html +25 -0
- package/example/node_modules/.bin/browserslist +21 -0
- package/example/node_modules/.bin/terser +21 -0
- package/example/node_modules/.bin/tsc +21 -0
- package/example/node_modules/.bin/tsserver +21 -0
- package/example/node_modules/.bin/vite +21 -0
- package/example/package.json +26 -0
- package/example/src/App.tsx +1744 -0
- package/example/src/main.tsx +11 -0
- package/example/tsconfig.json +21 -0
- package/example/vite.config.ts +13 -0
- package/package.json +65 -0
- package/src/components/RuntypeFlowEditor.tsx +528 -0
- package/src/components/nodes/BaseNode.tsx +357 -0
- package/src/components/nodes/CodeNode.tsx +252 -0
- package/src/components/nodes/ConditionalNode.tsx +264 -0
- package/src/components/nodes/FetchUrlNode.tsx +299 -0
- package/src/components/nodes/PromptNode.tsx +270 -0
- package/src/components/nodes/SendEmailNode.tsx +311 -0
- package/src/hooks/useFlowValidation.ts +424 -0
- package/src/hooks/useRuntypeFlow.ts +414 -0
- package/src/index.ts +28 -0
- package/src/types/index.ts +332 -0
- package/src/utils/adapter.ts +544 -0
- package/src/utils/layout.ts +284 -0
- package/tsconfig.json +29 -0
- package/tsup.config.ts +15 -0
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import type { Node, Edge, NodeProps } from '@xyflow/react'
|
|
2
|
+
import type { FlowStepType, PromptStepMode } from '@travrse/shared'
|
|
3
|
+
import type { RuntypeClient } from '@runtypelabs/sdk'
|
|
4
|
+
|
|
5
|
+
// ============================================================================
|
|
6
|
+
// Flow Step Types (matching Runtype API)
|
|
7
|
+
// ============================================================================
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Core FlowStep interface matching the Runtype API structure
|
|
11
|
+
*/
|
|
12
|
+
export interface FlowStep {
|
|
13
|
+
id: string
|
|
14
|
+
type: FlowStepType
|
|
15
|
+
name: string
|
|
16
|
+
order: number
|
|
17
|
+
enabled: boolean
|
|
18
|
+
config: FlowStepConfig
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Union type for all step configurations
|
|
23
|
+
*/
|
|
24
|
+
export type FlowStepConfig =
|
|
25
|
+
| PromptStepConfig
|
|
26
|
+
| FetchUrlStepConfig
|
|
27
|
+
| TransformDataStepConfig
|
|
28
|
+
| ConditionalStepConfig
|
|
29
|
+
| SendEmailStepConfig
|
|
30
|
+
| GenericStepConfig
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Prompt step configuration
|
|
34
|
+
*/
|
|
35
|
+
export interface PromptStepConfig {
|
|
36
|
+
mode?: PromptStepMode
|
|
37
|
+
model: string
|
|
38
|
+
systemPrompt?: string
|
|
39
|
+
userPrompt: string
|
|
40
|
+
previousMessages?: string
|
|
41
|
+
responseFormat?: 'json' | 'markdown' | 'text' | 'html' | 'xml'
|
|
42
|
+
temperature?: number
|
|
43
|
+
maxTokens?: number
|
|
44
|
+
outputVariable: string
|
|
45
|
+
tools?: {
|
|
46
|
+
toolIds: string[]
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Fetch URL step configuration
|
|
52
|
+
*/
|
|
53
|
+
export interface FetchUrlStepConfig {
|
|
54
|
+
http: {
|
|
55
|
+
url: string
|
|
56
|
+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
|
|
57
|
+
headers?: Record<string, string>
|
|
58
|
+
body?: string
|
|
59
|
+
timeout?: number
|
|
60
|
+
}
|
|
61
|
+
auth?: {
|
|
62
|
+
type: 'none' | 'bearer' | 'basic' | 'api-key'
|
|
63
|
+
token?: string
|
|
64
|
+
username?: string
|
|
65
|
+
password?: string
|
|
66
|
+
apiKey?: string
|
|
67
|
+
headerName?: string
|
|
68
|
+
}
|
|
69
|
+
responseType?: 'json' | 'text' | 'xml'
|
|
70
|
+
outputVariable: string
|
|
71
|
+
errorHandling?: 'fail' | 'continue' | 'default'
|
|
72
|
+
defaultValue?: unknown
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Transform data (code) step configuration
|
|
77
|
+
*/
|
|
78
|
+
export interface TransformDataStepConfig {
|
|
79
|
+
script: string
|
|
80
|
+
outputVariable: string
|
|
81
|
+
sandboxProvider?: 'quickjs' | 'daytona'
|
|
82
|
+
language?: 'javascript' | 'typescript' | 'python'
|
|
83
|
+
errorHandling?: 'fail' | 'continue' | 'default'
|
|
84
|
+
defaultValue?: unknown
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Conditional step configuration
|
|
89
|
+
*/
|
|
90
|
+
export interface ConditionalStepConfig {
|
|
91
|
+
condition: string
|
|
92
|
+
trueSteps: FlowStep[]
|
|
93
|
+
falseSteps?: FlowStep[]
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Send email step configuration
|
|
98
|
+
*/
|
|
99
|
+
export interface SendEmailStepConfig {
|
|
100
|
+
from: string
|
|
101
|
+
to: string
|
|
102
|
+
subject: string
|
|
103
|
+
replyTo?: string
|
|
104
|
+
cc?: string
|
|
105
|
+
bcc?: string
|
|
106
|
+
html?: string
|
|
107
|
+
text?: string
|
|
108
|
+
attachments?: Array<{
|
|
109
|
+
filename: string
|
|
110
|
+
content: string
|
|
111
|
+
contentType?: string
|
|
112
|
+
}>
|
|
113
|
+
outputVariable: string
|
|
114
|
+
errorHandling?: 'fail' | 'continue' | 'default'
|
|
115
|
+
defaultValue?: unknown
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Generic step config for extensibility
|
|
120
|
+
*/
|
|
121
|
+
export interface GenericStepConfig {
|
|
122
|
+
[key: string]: unknown
|
|
123
|
+
outputVariable?: string
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// ============================================================================
|
|
127
|
+
// React Flow Node Types
|
|
128
|
+
// ============================================================================
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Base data structure for all Runtype nodes
|
|
132
|
+
* Uses index signature to satisfy React Flow's Record<string, unknown> constraint
|
|
133
|
+
*/
|
|
134
|
+
export interface RuntypeNodeData extends Record<string, unknown> {
|
|
135
|
+
step: FlowStep
|
|
136
|
+
label: string
|
|
137
|
+
onChange?: (stepId: string, updates: Partial<FlowStep>) => void
|
|
138
|
+
onDelete?: (stepId: string) => void
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Runtype node extending React Flow's Node type
|
|
143
|
+
*/
|
|
144
|
+
export type RuntypeNode = Node<RuntypeNodeData, FlowStepType>
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Runtype edge type
|
|
148
|
+
*/
|
|
149
|
+
export type RuntypeEdge = Edge<{ stepOrder?: number }>
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Props for node components
|
|
153
|
+
*/
|
|
154
|
+
export type RuntypeNodeProps = NodeProps
|
|
155
|
+
|
|
156
|
+
// ============================================================================
|
|
157
|
+
// Node Type Registry
|
|
158
|
+
// ============================================================================
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Supported node types that have custom components
|
|
162
|
+
*/
|
|
163
|
+
export const SUPPORTED_NODE_TYPES = [
|
|
164
|
+
'prompt',
|
|
165
|
+
'fetch-url',
|
|
166
|
+
'transform-data',
|
|
167
|
+
'conditional',
|
|
168
|
+
'send-email',
|
|
169
|
+
] as const
|
|
170
|
+
|
|
171
|
+
export type SupportedNodeType = typeof SUPPORTED_NODE_TYPES[number]
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Check if a step type has a custom node component
|
|
175
|
+
*/
|
|
176
|
+
export function isSupportedNodeType(type: FlowStepType): type is SupportedNodeType {
|
|
177
|
+
return SUPPORTED_NODE_TYPES.includes(type as SupportedNodeType)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// ============================================================================
|
|
181
|
+
// Editor Configuration
|
|
182
|
+
// ============================================================================
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Configuration for the RuntypeFlowEditor component
|
|
186
|
+
*/
|
|
187
|
+
export interface RuntypeFlowEditorProps {
|
|
188
|
+
/** Runtype API client instance */
|
|
189
|
+
client: RuntypeClient
|
|
190
|
+
/** ID of an existing flow to load */
|
|
191
|
+
flowId?: string
|
|
192
|
+
/** Initial flow name (for new flows) */
|
|
193
|
+
initialName?: string
|
|
194
|
+
/** Initial flow description */
|
|
195
|
+
initialDescription?: string
|
|
196
|
+
/** Initial steps to populate the editor */
|
|
197
|
+
initialSteps?: FlowStep[]
|
|
198
|
+
/** Callback when flow is saved */
|
|
199
|
+
onSave?: (flow: SavedFlow) => void
|
|
200
|
+
/** Callback when flow changes */
|
|
201
|
+
onChange?: (nodes: RuntypeNode[], edges: RuntypeEdge[]) => void
|
|
202
|
+
/** Callback when a step is selected */
|
|
203
|
+
onStepSelect?: (step: FlowStep | null) => void
|
|
204
|
+
/** Whether to show the toolbar */
|
|
205
|
+
showToolbar?: boolean
|
|
206
|
+
/** Whether the editor is read-only */
|
|
207
|
+
readOnly?: boolean
|
|
208
|
+
/** Custom class name for the editor container */
|
|
209
|
+
className?: string
|
|
210
|
+
/** Available models for prompt steps */
|
|
211
|
+
availableModels?: ModelOption[]
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Model option for prompt step configuration
|
|
216
|
+
*/
|
|
217
|
+
export interface ModelOption {
|
|
218
|
+
id: string
|
|
219
|
+
name: string
|
|
220
|
+
provider: string
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Saved flow data returned after save operations
|
|
225
|
+
*/
|
|
226
|
+
export interface SavedFlow {
|
|
227
|
+
id: string
|
|
228
|
+
name: string
|
|
229
|
+
description?: string
|
|
230
|
+
steps: FlowStep[]
|
|
231
|
+
createdAt?: string
|
|
232
|
+
updatedAt?: string
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// ============================================================================
|
|
236
|
+
// Hook Types
|
|
237
|
+
// ============================================================================
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Return type for useRuntypeFlow hook
|
|
241
|
+
*/
|
|
242
|
+
export interface UseRuntypeFlowReturn {
|
|
243
|
+
/** Current React Flow nodes */
|
|
244
|
+
nodes: RuntypeNode[]
|
|
245
|
+
/** Current React Flow edges */
|
|
246
|
+
edges: RuntypeEdge[]
|
|
247
|
+
/** Handler for node changes */
|
|
248
|
+
onNodesChange: (changes: unknown) => void
|
|
249
|
+
/** Handler for edge changes */
|
|
250
|
+
onEdgesChange: (changes: unknown) => void
|
|
251
|
+
/** Handler for new connections */
|
|
252
|
+
onConnect: (connection: unknown) => void
|
|
253
|
+
/** Flow metadata */
|
|
254
|
+
flowName: string
|
|
255
|
+
flowDescription: string
|
|
256
|
+
flowId: string | null
|
|
257
|
+
/** Set flow name */
|
|
258
|
+
setFlowName: (name: string) => void
|
|
259
|
+
/** Set flow description */
|
|
260
|
+
setFlowDescription: (description: string) => void
|
|
261
|
+
/** Load a flow by ID */
|
|
262
|
+
loadFlow: (flowId: string) => Promise<void>
|
|
263
|
+
/** Save the current flow */
|
|
264
|
+
saveFlow: () => Promise<SavedFlow>
|
|
265
|
+
/** Create a new flow */
|
|
266
|
+
createFlow: (name: string, description?: string) => Promise<SavedFlow>
|
|
267
|
+
/** Delete a step */
|
|
268
|
+
deleteStep: (stepId: string) => void
|
|
269
|
+
/** Update a step's configuration */
|
|
270
|
+
updateStep: (stepId: string, updates: Partial<FlowStep>) => void
|
|
271
|
+
/** Add a new step */
|
|
272
|
+
addStep: (type: FlowStepType, position?: { x: number; y: number }) => void
|
|
273
|
+
/** Loading state */
|
|
274
|
+
isLoading: boolean
|
|
275
|
+
/** Saving state */
|
|
276
|
+
isSaving: boolean
|
|
277
|
+
/** Error state */
|
|
278
|
+
error: Error | null
|
|
279
|
+
/** Whether there are unsaved changes */
|
|
280
|
+
hasUnsavedChanges: boolean
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Validation result for a flow
|
|
285
|
+
*/
|
|
286
|
+
export interface FlowValidationResult {
|
|
287
|
+
isValid: boolean
|
|
288
|
+
errors: ValidationError[]
|
|
289
|
+
warnings: ValidationWarning[]
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export interface ValidationError {
|
|
293
|
+
stepId: string
|
|
294
|
+
field?: string
|
|
295
|
+
message: string
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export interface ValidationWarning {
|
|
299
|
+
stepId: string
|
|
300
|
+
field?: string
|
|
301
|
+
message: string
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// ============================================================================
|
|
305
|
+
// Event Types
|
|
306
|
+
// ============================================================================
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Event emitted when a step is updated
|
|
310
|
+
*/
|
|
311
|
+
export interface StepUpdateEvent {
|
|
312
|
+
stepId: string
|
|
313
|
+
updates: Partial<FlowStep>
|
|
314
|
+
previousValue: FlowStep
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Event emitted when a step is deleted
|
|
319
|
+
*/
|
|
320
|
+
export interface StepDeleteEvent {
|
|
321
|
+
stepId: string
|
|
322
|
+
step: FlowStep
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Event emitted when a step is added
|
|
327
|
+
*/
|
|
328
|
+
export interface StepAddEvent {
|
|
329
|
+
step: FlowStep
|
|
330
|
+
position: { x: number; y: number }
|
|
331
|
+
}
|
|
332
|
+
|