Skip to content

Commit 0e805d0

Browse files
committed
docs: Add custom WASM engine documentation
- Update ui/README.md with custom engine usage examples - Update docs/src/ui/overview.md with custom engine section - Add engine exports documentation to both files
1 parent 2f677fa commit 0e805d0

2 files changed

Lines changed: 93 additions & 3 deletions

File tree

docs/src/ui/overview.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,13 @@ import {
105105
WorkflowVisualizer,
106106
DebuggerProvider,
107107
DebuggerControls,
108+
defaultEngineFactory,
108109
useDebugger
109110
} from '@goplasmatic/dataflow-ui';
110111

111112
function DebugView() {
112113
return (
113-
<DebuggerProvider>
114+
<DebuggerProvider engineFactory={defaultEngineFactory}>
114115
<WorkflowVisualizer
115116
workflows={workflows}
116117
debugMode={true}
@@ -121,6 +122,47 @@ function DebugView() {
121122
}
122123
```
123124

125+
## Custom WASM Engine
126+
127+
Use a custom WASM engine with plugins or custom functions for debugging. Implement the `DataflowEngine` interface:
128+
129+
```tsx
130+
import {
131+
WorkflowVisualizer,
132+
DebuggerProvider,
133+
DataflowEngine,
134+
Workflow
135+
} from '@goplasmatic/dataflow-ui';
136+
import { MyCustomWasmEngine } from './my-custom-wasm';
137+
138+
class MyEngineAdapter implements DataflowEngine {
139+
private engine: MyCustomWasmEngine;
140+
141+
constructor(workflows: Workflow[]) {
142+
this.engine = new MyCustomWasmEngine(JSON.stringify(workflows));
143+
}
144+
145+
async processWithTrace(payload: Record<string, unknown>) {
146+
const result = await this.engine.process_with_trace(JSON.stringify(payload));
147+
return JSON.parse(result);
148+
}
149+
150+
dispose() {
151+
this.engine.free();
152+
}
153+
}
154+
155+
function CustomDebugView() {
156+
return (
157+
<DebuggerProvider engineFactory={(workflows) => new MyEngineAdapter(workflows)}>
158+
<WorkflowVisualizer workflows={workflows} debugMode={true} />
159+
</DebuggerProvider>
160+
);
161+
}
162+
```
163+
164+
The `engineFactory` is called whenever workflows change, ensuring the engine always has the latest workflow definitions.
165+
124166
### Debugger Controls
125167

126168
```tsx
@@ -201,6 +243,13 @@ function MyComponent() {
201243
- `useTaskDebugState` - Debug state for a specific task
202244
- `useWorkflowDebugState` - Debug state for a workflow
203245

246+
### Engine
247+
248+
- `WasmEngineAdapter` - Default WASM engine adapter
249+
- `defaultEngineFactory` - Factory function for default engine
250+
- `DataflowEngine` - Interface for custom engines
251+
- `EngineFactory` - Type for engine factory functions
252+
204253
### Types
205254

206255
All TypeScript types are exported for workflow definitions, tasks, messages, and execution traces.

ui/README.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,53 @@ interface WorkflowVisualizerProps {
9191
Enable step-by-step execution visualization:
9292

9393
```tsx
94-
import { WorkflowVisualizer, DebuggerProvider, DebuggerControls } from '@goplasmatic/dataflow-ui';
94+
import { WorkflowVisualizer, DebuggerProvider, DebuggerControls, defaultEngineFactory } from '@goplasmatic/dataflow-ui';
9595

9696
function DebugView() {
9797
return (
98-
<DebuggerProvider>
98+
<DebuggerProvider engineFactory={defaultEngineFactory}>
9999
<WorkflowVisualizer workflows={workflows} debugMode={true} />
100100
<DebuggerControls />
101101
</DebuggerProvider>
102102
);
103103
}
104104
```
105105

106+
### Custom WASM Engine
107+
108+
Use a custom WASM engine with plugins or custom functions:
109+
110+
```tsx
111+
import { WorkflowVisualizer, DebuggerProvider, DataflowEngine } from '@goplasmatic/dataflow-ui';
112+
import { MyCustomWasmEngine } from './my-custom-wasm';
113+
114+
// Implement the DataflowEngine interface
115+
class MyEngineAdapter implements DataflowEngine {
116+
private engine: MyCustomWasmEngine;
117+
118+
constructor(workflows: Workflow[]) {
119+
this.engine = new MyCustomWasmEngine(JSON.stringify(workflows));
120+
}
121+
122+
async processWithTrace(payload: Record<string, unknown>) {
123+
const result = await this.engine.process_with_trace(JSON.stringify(payload));
124+
return JSON.parse(result);
125+
}
126+
127+
dispose() {
128+
this.engine.free();
129+
}
130+
}
131+
132+
function CustomDebugView() {
133+
return (
134+
<DebuggerProvider engineFactory={(workflows) => new MyEngineAdapter(workflows)}>
135+
<WorkflowVisualizer workflows={workflows} debugMode={true} />
136+
</DebuggerProvider>
137+
);
138+
}
139+
```
140+
106141
## Exports
107142

108143
### Components
@@ -116,6 +151,12 @@ function DebugView() {
116151
- `useDebugger` - Access debugger state and controls
117152
- `useTaskDebugState` - Get debug state for a specific task
118153

154+
### Engine
155+
- `WasmEngineAdapter` - Default WASM engine adapter
156+
- `defaultEngineFactory` - Factory function for default engine
157+
- `DataflowEngine` - Interface for custom engines
158+
- `EngineFactory` - Type for engine factory functions
159+
119160
### Types
120161
All TypeScript types are exported for workflow definitions, tasks, messages, and execution traces.
121162

0 commit comments

Comments
 (0)