@marktoflow/core 2.0.0-alpha.3 → 2.0.0-alpha.4
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 +305 -0
- package/package.json +3 -2
package/README.md
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
# @marktoflow/core
|
|
2
|
+
|
|
3
|
+
Core engine for marktoflow - parser, executor, and state management.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
`@marktoflow/core` is the foundation of the marktoflow automation framework. It provides the core workflow engine, state management, scheduling, and execution infrastructure.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Workflow Parser** - Parse markdown + YAML workflow definitions
|
|
12
|
+
- **Execution Engine** - Step-by-step workflow execution with retry and error handling
|
|
13
|
+
- **State Management** - SQLite-based persistent state tracking
|
|
14
|
+
- **Scheduling** - Cron-based workflow scheduling
|
|
15
|
+
- **Queue System** - Support for Redis, RabbitMQ, and in-memory queues
|
|
16
|
+
- **Webhooks** - HTTP webhook trigger support
|
|
17
|
+
- **File Watching** - Monitor files for changes and trigger workflows
|
|
18
|
+
- **Security** - RBAC, approval workflows, and audit logging
|
|
19
|
+
- **Cost Tracking** - Track and manage API usage costs
|
|
20
|
+
- **Plugin System** - Extensible plugin architecture with 17 hook types
|
|
21
|
+
- **Templates** - Reusable workflow templates with variables
|
|
22
|
+
- **Tool Registry** - Support for MCP, OpenAPI, and custom tools
|
|
23
|
+
- **Agent Routing** - Multi-agent workflow support with routing strategies
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install @marktoflow/core
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
### Basic Workflow Execution
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { WorkflowParser, WorkflowEngine } from '@marktoflow/core';
|
|
37
|
+
|
|
38
|
+
// Parse workflow
|
|
39
|
+
const parser = new WorkflowParser();
|
|
40
|
+
const workflow = await parser.parseWorkflow('workflow.md');
|
|
41
|
+
|
|
42
|
+
// Execute workflow
|
|
43
|
+
const engine = new WorkflowEngine();
|
|
44
|
+
const result = await engine.execute(workflow, {
|
|
45
|
+
inputs: { message: 'Hello World' },
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
console.log(result);
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### With State Management
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { WorkflowEngine, StateManager } from '@marktoflow/core';
|
|
55
|
+
|
|
56
|
+
// Initialize state manager
|
|
57
|
+
const stateManager = new StateManager({
|
|
58
|
+
dbPath: '.marktoflow/state.db',
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// Execute workflow with state
|
|
62
|
+
const engine = new WorkflowEngine({ stateManager });
|
|
63
|
+
const result = await engine.execute(workflow);
|
|
64
|
+
|
|
65
|
+
// Query state
|
|
66
|
+
const history = await stateManager.getWorkflowHistory(workflow.id);
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Scheduling
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import { Scheduler } from '@marktoflow/core';
|
|
73
|
+
|
|
74
|
+
// Create scheduler
|
|
75
|
+
const scheduler = new Scheduler();
|
|
76
|
+
|
|
77
|
+
// Schedule workflow (cron format)
|
|
78
|
+
await scheduler.schedule({
|
|
79
|
+
workflowId: 'daily-report',
|
|
80
|
+
cron: '0 9 * * 1-5', // 9 AM weekdays
|
|
81
|
+
workflowPath: './workflows/daily-report.md',
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// Start scheduler
|
|
85
|
+
await scheduler.start();
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Webhooks
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
import { WebhookServer } from '@marktoflow/core';
|
|
92
|
+
|
|
93
|
+
// Create webhook server
|
|
94
|
+
const webhookServer = new WebhookServer({ port: 3000 });
|
|
95
|
+
|
|
96
|
+
// Register webhook
|
|
97
|
+
await webhookServer.registerWebhook({
|
|
98
|
+
path: '/github',
|
|
99
|
+
workflowPath: './workflows/github-pr.md',
|
|
100
|
+
secret: process.env.GITHUB_WEBHOOK_SECRET,
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// Start server
|
|
104
|
+
await webhookServer.start();
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Plugin System
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
import { PluginRegistry } from '@marktoflow/core';
|
|
111
|
+
|
|
112
|
+
// Register plugin
|
|
113
|
+
const registry = new PluginRegistry();
|
|
114
|
+
await registry.register({
|
|
115
|
+
name: 'my-plugin',
|
|
116
|
+
hooks: {
|
|
117
|
+
beforeWorkflowStart: async (context) => {
|
|
118
|
+
console.log('Starting workflow:', context.workflow.id);
|
|
119
|
+
},
|
|
120
|
+
afterStepComplete: async (context) => {
|
|
121
|
+
console.log('Completed step:', context.step.action);
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Workflow Format
|
|
128
|
+
|
|
129
|
+
Workflows are written in markdown with YAML frontmatter:
|
|
130
|
+
|
|
131
|
+
```markdown
|
|
132
|
+
---
|
|
133
|
+
workflow:
|
|
134
|
+
id: example
|
|
135
|
+
name: Example Workflow
|
|
136
|
+
|
|
137
|
+
tools:
|
|
138
|
+
slack:
|
|
139
|
+
sdk: '@slack/web-api'
|
|
140
|
+
auth:
|
|
141
|
+
token: '${SLACK_BOT_TOKEN}'
|
|
142
|
+
|
|
143
|
+
triggers:
|
|
144
|
+
- type: schedule
|
|
145
|
+
cron: '0 9 * * *'
|
|
146
|
+
|
|
147
|
+
inputs:
|
|
148
|
+
message:
|
|
149
|
+
type: string
|
|
150
|
+
required: true
|
|
151
|
+
|
|
152
|
+
outputs:
|
|
153
|
+
result:
|
|
154
|
+
type: string
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
# Example Workflow
|
|
158
|
+
|
|
159
|
+
This workflow posts a message to Slack.
|
|
160
|
+
|
|
161
|
+
## Step 1: Post Message
|
|
162
|
+
|
|
163
|
+
\`\`\`yaml
|
|
164
|
+
action: slack.chat.postMessage
|
|
165
|
+
inputs:
|
|
166
|
+
channel: '#general'
|
|
167
|
+
text: '{{ inputs.message }}'
|
|
168
|
+
output_variable: result
|
|
169
|
+
\`\`\`
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## Architecture
|
|
173
|
+
|
|
174
|
+
### Core Components
|
|
175
|
+
|
|
176
|
+
1. **Parser** (`parser.ts`) - Parse markdown + YAML workflow definitions
|
|
177
|
+
2. **Engine** (`engine.ts`) - Execute workflows with retry/circuit breaker
|
|
178
|
+
3. **State Manager** (`state.ts`) - SQLite-based state persistence
|
|
179
|
+
4. **Scheduler** (`scheduler.ts`) - Cron-based workflow scheduling
|
|
180
|
+
5. **Queue** (`queue.ts`) - Redis/RabbitMQ/InMemory queue support
|
|
181
|
+
6. **Webhook** (`webhook.ts`) - HTTP webhook triggers
|
|
182
|
+
7. **File Watcher** (`filewatcher.ts`) - File change monitoring
|
|
183
|
+
8. **Security** (`security.ts`) - RBAC and audit logging
|
|
184
|
+
9. **Cost Tracker** (`costs.ts`) - API usage cost management
|
|
185
|
+
10. **Plugin System** (`plugins.ts`) - Extensible hooks
|
|
186
|
+
11. **Templates** (`templates.ts`) - Reusable workflow patterns
|
|
187
|
+
12. **Tool Registry** (`tool-registry.ts`) - MCP/OpenAPI/Custom tools
|
|
188
|
+
13. **Agent Routing** (`routing.ts`) - Multi-agent coordination
|
|
189
|
+
|
|
190
|
+
### Execution Flow
|
|
191
|
+
|
|
192
|
+
```
|
|
193
|
+
Parser → Validate → Security Check → Execute Steps → Save State → Output
|
|
194
|
+
↓ ↓ ↓ ↓
|
|
195
|
+
Schema RBAC Retry/Failover Audit Log
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## Configuration
|
|
199
|
+
|
|
200
|
+
### Environment Variables
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
# Database
|
|
204
|
+
MARKTOFLOW_DB_PATH=.marktoflow/state.db
|
|
205
|
+
|
|
206
|
+
# Queue (Redis)
|
|
207
|
+
REDIS_HOST=localhost
|
|
208
|
+
REDIS_PORT=6379
|
|
209
|
+
|
|
210
|
+
# Queue (RabbitMQ)
|
|
211
|
+
RABBITMQ_URL=amqp://localhost
|
|
212
|
+
|
|
213
|
+
# Security
|
|
214
|
+
MARKTOFLOW_SECRET_KEY=your-secret-key
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Configuration File
|
|
218
|
+
|
|
219
|
+
Create `.marktoflow/config.yaml`:
|
|
220
|
+
|
|
221
|
+
```yaml
|
|
222
|
+
state:
|
|
223
|
+
dbPath: .marktoflow/state.db
|
|
224
|
+
|
|
225
|
+
queue:
|
|
226
|
+
type: redis # redis, rabbitmq, or memory
|
|
227
|
+
redis:
|
|
228
|
+
host: localhost
|
|
229
|
+
port: 6379
|
|
230
|
+
|
|
231
|
+
security:
|
|
232
|
+
rbac:
|
|
233
|
+
enabled: true
|
|
234
|
+
auditLog:
|
|
235
|
+
enabled: true
|
|
236
|
+
|
|
237
|
+
costs:
|
|
238
|
+
budget:
|
|
239
|
+
daily: 100
|
|
240
|
+
monthly: 3000
|
|
241
|
+
alerts:
|
|
242
|
+
- threshold: 50
|
|
243
|
+
emails: [admin@example.com]
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## API Reference
|
|
247
|
+
|
|
248
|
+
### WorkflowParser
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
class WorkflowParser {
|
|
252
|
+
parseWorkflow(filePath: string): Promise<Workflow>;
|
|
253
|
+
parseYAML(content: string): Workflow;
|
|
254
|
+
validate(workflow: Workflow): ValidationResult;
|
|
255
|
+
}
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### WorkflowEngine
|
|
259
|
+
|
|
260
|
+
```typescript
|
|
261
|
+
class WorkflowEngine {
|
|
262
|
+
constructor(options?: EngineOptions);
|
|
263
|
+
execute(workflow: Workflow, context?: ExecutionContext): Promise<WorkflowResult>;
|
|
264
|
+
stop(): Promise<void>;
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
### StateManager
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
class StateManager {
|
|
272
|
+
constructor(options: StateOptions);
|
|
273
|
+
getWorkflowHistory(workflowId: string): Promise<WorkflowRun[]>;
|
|
274
|
+
getWorkflowState(runId: string): Promise<WorkflowState>;
|
|
275
|
+
saveWorkflowState(state: WorkflowState): Promise<void>;
|
|
276
|
+
}
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### Scheduler
|
|
280
|
+
|
|
281
|
+
```typescript
|
|
282
|
+
class Scheduler {
|
|
283
|
+
schedule(config: ScheduleConfig): Promise<void>;
|
|
284
|
+
unschedule(workflowId: string): Promise<void>;
|
|
285
|
+
start(): Promise<void>;
|
|
286
|
+
stop(): Promise<void>;
|
|
287
|
+
}
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
## Testing
|
|
291
|
+
|
|
292
|
+
```bash
|
|
293
|
+
npm test
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
## Links
|
|
297
|
+
|
|
298
|
+
- [Main Repository](https://github.com/scottgl9/marktoflow)
|
|
299
|
+
- [Documentation](https://github.com/scottgl9/marktoflow#readme)
|
|
300
|
+
- [CLI Package](@marktoflow/cli)
|
|
301
|
+
- [Integrations Package](@marktoflow/integrations)
|
|
302
|
+
|
|
303
|
+
## License
|
|
304
|
+
|
|
305
|
+
Apache-2.0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marktoflow/core",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.4",
|
|
4
4
|
"description": "Core engine for marktoflow - parser, executor, state management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -46,7 +46,8 @@
|
|
|
46
46
|
"typescript": "^5.0.0"
|
|
47
47
|
},
|
|
48
48
|
"files": [
|
|
49
|
-
"dist"
|
|
49
|
+
"dist",
|
|
50
|
+
"README.md"
|
|
50
51
|
],
|
|
51
52
|
"keywords": [
|
|
52
53
|
"marktoflow",
|