@gravito/flux 1.0.0-beta.1 → 1.0.0-beta.2
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.zh-TW.md +220 -1
- package/bin/flux.js +96 -0
- package/dev/viewer/app.js +131 -0
- package/dev/viewer/index.html +52 -0
- package/dev/viewer/styles.css +163 -0
- package/package.json +9 -2
package/README.zh-TW.md
CHANGED
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
# @gravito/flux
|
|
2
2
|
|
|
3
|
-
> Gravito
|
|
3
|
+
> Gravito 的高效能工作流程引擎,跨平台、型別安全的狀態機,強調可追蹤、可重播與可靠重試。
|
|
4
|
+
|
|
5
|
+
## 核心特色
|
|
6
|
+
|
|
7
|
+
- **純狀態機模型** - 以明確狀態描述流程,讓每一步清晰可控
|
|
8
|
+
- **鏈式 Builder API** - 型別安全的流程定義方式
|
|
9
|
+
- **儲存介面** - Memory、Bun SQLite,其他儲存可自訂
|
|
10
|
+
- **重試與逾時** - Step 可設定 retries/timeout/when,面對不穩定依賴也能自動恢復
|
|
11
|
+
- **同步/非同步** - 同時支援同步流程與非同步長流程
|
|
12
|
+
- **事件 Hooks** - 監聽流程與步驟生命週期
|
|
13
|
+
- **事件 Hooks** - 監聽流程與步驟生命周期
|
|
14
|
+
- **雙平台支援** - Bun 與 Node.js 均可使用
|
|
4
15
|
|
|
5
16
|
## 安裝
|
|
6
17
|
|
|
7
18
|
```bash
|
|
8
19
|
bun add @gravito/flux
|
|
20
|
+
|
|
21
|
+
# npm
|
|
22
|
+
npm install @gravito/flux
|
|
9
23
|
```
|
|
10
24
|
|
|
11
25
|
## 快速開始
|
|
@@ -28,3 +42,208 @@ const orderFlow = createWorkflow('order-process')
|
|
|
28
42
|
const engine = new FluxEngine()
|
|
29
43
|
const result = await engine.execute(orderFlow, { orderId: '123' })
|
|
30
44
|
```
|
|
45
|
+
|
|
46
|
+
## 範例
|
|
47
|
+
|
|
48
|
+
### 訂單履約
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
const orderWorkflow = createWorkflow('order-fulfillment')
|
|
52
|
+
.input<{ orderId: string; items: Item[] }>()
|
|
53
|
+
.step('validate', async (ctx) => {
|
|
54
|
+
for (const item of ctx.input.items) {
|
|
55
|
+
const stock = await db.products.getStock(item.productId)
|
|
56
|
+
if (stock < item.qty) throw new Error(`Out of stock: ${item.productId}`)
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
.step(
|
|
60
|
+
'payment',
|
|
61
|
+
async (ctx) => {
|
|
62
|
+
ctx.data.payment = await payment.charge(ctx.input.orderId)
|
|
63
|
+
},
|
|
64
|
+
{ retries: 3, timeout: 30_000 }
|
|
65
|
+
)
|
|
66
|
+
.commit('deduct', async (ctx) => {
|
|
67
|
+
await inventory.deduct(ctx.data.reservationIds)
|
|
68
|
+
})
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### 影像處理
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
const uploadWorkflow = createWorkflow('image-processing')
|
|
75
|
+
.input<{ fileBuffer: Buffer; fileName: string; userId: string }>()
|
|
76
|
+
.step('validate', async (ctx) => {
|
|
77
|
+
if (ctx.input.fileBuffer.length > 10 * 1024 * 1024) {
|
|
78
|
+
throw new Error('File size exceeds 10MB')
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
.step('resize', async (ctx) => {
|
|
82
|
+
ctx.data.thumbnail = await sharp(ctx.input.fileBuffer).resize(200).toBuffer()
|
|
83
|
+
})
|
|
84
|
+
.commit('upload', async (ctx) => {
|
|
85
|
+
ctx.data.url = await s3.upload(ctx.input.fileName, ctx.data.thumbnail)
|
|
86
|
+
})
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### 報表生成
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
const reportWorkflow = createWorkflow('generate-report')
|
|
93
|
+
.input<{ reportType: string; dateRange: DateRange; requestedBy: string }>()
|
|
94
|
+
.step('fetch-data', async (ctx) => {
|
|
95
|
+
ctx.data.sales = await db.orders.aggregate(ctx.input.dateRange)
|
|
96
|
+
}, { timeout: 60_000 })
|
|
97
|
+
.step('calculate', async (ctx) => {
|
|
98
|
+
ctx.data.metrics = { revenue: 0, orders: 0 }
|
|
99
|
+
})
|
|
100
|
+
.commit('upload', async (ctx) => {
|
|
101
|
+
ctx.data.url = await s3.upload(`reports/${ctx.id}.pdf`, ctx.data.pdf)
|
|
102
|
+
})
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## API
|
|
106
|
+
|
|
107
|
+
### `createWorkflow(name)`
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
const flow = createWorkflow('my-workflow')
|
|
111
|
+
.input<{ value: number }>()
|
|
112
|
+
.step('step1', handler)
|
|
113
|
+
.step('step2', handler, { retries: 3 })
|
|
114
|
+
.commit('save', handler)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### `FluxEngine`
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
const engine = new FluxEngine({
|
|
121
|
+
storage: new MemoryStorage(),
|
|
122
|
+
defaultRetries: 3,
|
|
123
|
+
defaultTimeout: 30_000,
|
|
124
|
+
logger: new FluxConsoleLogger(),
|
|
125
|
+
on: {
|
|
126
|
+
stepStart: (step, ctx) => {},
|
|
127
|
+
stepComplete: (step, ctx, result) => {},
|
|
128
|
+
stepError: (step, ctx, error) => {},
|
|
129
|
+
workflowComplete: (ctx) => {},
|
|
130
|
+
workflowError: (ctx, error) => {},
|
|
131
|
+
},
|
|
132
|
+
})
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Step Options
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
.step('name', handler, {
|
|
139
|
+
retries: 5,
|
|
140
|
+
timeout: 60_000,
|
|
141
|
+
when: (ctx) => ctx.data.x > 0,
|
|
142
|
+
})
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## 分支流程(多支點)
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
const flow = createWorkflow('event-routing')
|
|
149
|
+
.input<{ payload: EventPayload }>()
|
|
150
|
+
.step('classify', async (ctx) => {
|
|
151
|
+
ctx.data.route = classify(ctx.input.payload)
|
|
152
|
+
})
|
|
153
|
+
.step(
|
|
154
|
+
'auto-handle',
|
|
155
|
+
async (ctx) => {
|
|
156
|
+
ctx.data.result = await autoProcess(ctx.input.payload)
|
|
157
|
+
},
|
|
158
|
+
{ when: (ctx) => ctx.data.route === 'auto' }
|
|
159
|
+
)
|
|
160
|
+
.step(
|
|
161
|
+
'manual-review',
|
|
162
|
+
async (ctx) => {
|
|
163
|
+
ctx.data.ticketId = await ticketing.create(ctx.input.payload)
|
|
164
|
+
},
|
|
165
|
+
{ when: (ctx) => ctx.data.route === 'manual' }
|
|
166
|
+
)
|
|
167
|
+
.step(
|
|
168
|
+
'risk-audit',
|
|
169
|
+
async (ctx) => {
|
|
170
|
+
ctx.data.auditId = await auditQueue.enqueue(ctx.input.payload)
|
|
171
|
+
},
|
|
172
|
+
{ when: (ctx) => ctx.data.route === 'risk' }
|
|
173
|
+
)
|
|
174
|
+
.commit('notify', async (ctx) => {
|
|
175
|
+
await notifier.send(ctx.data)
|
|
176
|
+
})
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## 本地開發視覺化
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
import { FluxEngine, JsonFileTraceSink } from '@gravito/flux'
|
|
183
|
+
|
|
184
|
+
const engine = new FluxEngine({
|
|
185
|
+
trace: new JsonFileTraceSink({ path: './.flux/trace.ndjson', reset: true }),
|
|
186
|
+
})
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
flux dev --trace ./.flux/trace.ndjson --port 4280
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### 驗證流程(本 repo)
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
bun run examples/trace-viewer.ts
|
|
197
|
+
bun run dev:viewer
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## 企業級追蹤
|
|
201
|
+
|
|
202
|
+
透過 `FluxTraceSink` 可以把事件流送到你自己的監控、排程或分析模組,建立完整的執行查詢、重播與告警能力。
|
|
203
|
+
|
|
204
|
+
## 儲存介面
|
|
205
|
+
|
|
206
|
+
### MemoryStorage
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
import { FluxEngine, MemoryStorage } from '@gravito/flux'
|
|
210
|
+
const engine = new FluxEngine({ storage: new MemoryStorage() })
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### BunSQLiteStorage (Bun only)
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
import { FluxEngine } from '@gravito/flux'
|
|
217
|
+
import { BunSQLiteStorage } from '@gravito/flux/bun'
|
|
218
|
+
|
|
219
|
+
const engine = new FluxEngine({
|
|
220
|
+
storage: new BunSQLiteStorage({ path: './data/workflows.db' })
|
|
221
|
+
})
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Gravito 整合
|
|
225
|
+
|
|
226
|
+
```typescript
|
|
227
|
+
import { OrbitFlux } from '@gravito/flux'
|
|
228
|
+
|
|
229
|
+
const core = await PlanetCore.boot({
|
|
230
|
+
orbits: [
|
|
231
|
+
new OrbitFlux({
|
|
232
|
+
storage: 'sqlite',
|
|
233
|
+
dbPath: './data/workflows.db',
|
|
234
|
+
})
|
|
235
|
+
]
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
const flux = core.services.get<FluxEngine>('flux')
|
|
239
|
+
await flux.execute(myWorkflow, input)
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## 平台支援
|
|
243
|
+
|
|
244
|
+
| Feature | Bun | Node.js |
|
|
245
|
+
|---------|-----|---------|
|
|
246
|
+
| FluxEngine | ✅ | ✅ |
|
|
247
|
+
| MemoryStorage | ✅ | ✅ |
|
|
248
|
+
| BunSQLiteStorage | ✅ | ❌ |
|
|
249
|
+
| OrbitFlux | ✅ | ✅ |
|
package/bin/flux.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createServer } from 'node:http'
|
|
3
|
+
import { readFile } from 'node:fs/promises'
|
|
4
|
+
import { dirname, extname, join, resolve } from 'node:path'
|
|
5
|
+
import { fileURLToPath } from 'node:url'
|
|
6
|
+
|
|
7
|
+
const args = process.argv.slice(2)
|
|
8
|
+
const command = args[0]
|
|
9
|
+
|
|
10
|
+
const help = () => {
|
|
11
|
+
console.log(`Flux CLI
|
|
12
|
+
|
|
13
|
+
Usage:
|
|
14
|
+
flux dev --trace ./.flux/trace.ndjson --port 4280
|
|
15
|
+
`)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (!command || command === '--help' || command === '-h') {
|
|
19
|
+
help()
|
|
20
|
+
process.exit(0)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (command !== 'dev') {
|
|
24
|
+
console.error(`Unknown command: ${command}`)
|
|
25
|
+
help()
|
|
26
|
+
process.exit(1)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const getArg = (name, fallback) => {
|
|
30
|
+
const idx = args.indexOf(name)
|
|
31
|
+
if (idx === -1) return fallback
|
|
32
|
+
return args[idx + 1] ?? fallback
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const port = Number(getArg('--port', '4280'))
|
|
36
|
+
const host = getArg('--host', '127.0.0.1')
|
|
37
|
+
const tracePath = resolve(getArg('--trace', './.flux/trace.ndjson'))
|
|
38
|
+
|
|
39
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
40
|
+
const __dirname = dirname(__filename)
|
|
41
|
+
const viewerRoot = resolve(join(__dirname, '..', 'dev', 'viewer'))
|
|
42
|
+
|
|
43
|
+
const contentType = (filePath) => {
|
|
44
|
+
const ext = extname(filePath)
|
|
45
|
+
switch (ext) {
|
|
46
|
+
case '.html':
|
|
47
|
+
return 'text/html; charset=utf-8'
|
|
48
|
+
case '.js':
|
|
49
|
+
return 'text/javascript; charset=utf-8'
|
|
50
|
+
case '.css':
|
|
51
|
+
return 'text/css; charset=utf-8'
|
|
52
|
+
case '.json':
|
|
53
|
+
return 'application/json; charset=utf-8'
|
|
54
|
+
case '.svg':
|
|
55
|
+
return 'image/svg+xml'
|
|
56
|
+
default:
|
|
57
|
+
return 'text/plain; charset=utf-8'
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const server = createServer(async (req, res) => {
|
|
62
|
+
try {
|
|
63
|
+
const url = new URL(req.url ?? '/', `http://${host}:${port}`)
|
|
64
|
+
if (url.pathname === '/trace') {
|
|
65
|
+
try {
|
|
66
|
+
const data = await readFile(tracePath, 'utf8')
|
|
67
|
+
res.writeHead(200, {
|
|
68
|
+
'content-type': 'text/plain; charset=utf-8',
|
|
69
|
+
'cache-control': 'no-store',
|
|
70
|
+
})
|
|
71
|
+
res.end(data)
|
|
72
|
+
} catch {
|
|
73
|
+
res.writeHead(204, { 'cache-control': 'no-store' })
|
|
74
|
+
res.end('')
|
|
75
|
+
}
|
|
76
|
+
return
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const reqPath = url.pathname === '/' ? '/index.html' : url.pathname
|
|
80
|
+
const filePath = join(viewerRoot, reqPath)
|
|
81
|
+
const data = await readFile(filePath)
|
|
82
|
+
res.writeHead(200, {
|
|
83
|
+
'content-type': contentType(filePath),
|
|
84
|
+
'cache-control': 'no-store',
|
|
85
|
+
})
|
|
86
|
+
res.end(data)
|
|
87
|
+
} catch (err) {
|
|
88
|
+
res.writeHead(404, { 'content-type': 'text/plain; charset=utf-8' })
|
|
89
|
+
res.end('Not Found')
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
server.listen(port, host, () => {
|
|
94
|
+
console.log(`Flux dev viewer running at http://${host}:${port}`)
|
|
95
|
+
console.log(`Trace file: ${tracePath}`)
|
|
96
|
+
})
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
const pathEl = document.getElementById('tracePath')
|
|
2
|
+
const updateEl = document.getElementById('lastUpdate')
|
|
3
|
+
const pathElContainer = document.getElementById('path')
|
|
4
|
+
const statusEl = document.getElementById('status')
|
|
5
|
+
const eventsEl = document.getElementById('events')
|
|
6
|
+
|
|
7
|
+
const state = {
|
|
8
|
+
events: [],
|
|
9
|
+
lastHash: '',
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const formatTime = (ts) => new Date(ts).toLocaleTimeString()
|
|
13
|
+
|
|
14
|
+
const parseNdjson = (text) =>
|
|
15
|
+
text
|
|
16
|
+
.split('\n')
|
|
17
|
+
.map((line) => line.trim())
|
|
18
|
+
.filter(Boolean)
|
|
19
|
+
.map((line) => {
|
|
20
|
+
try {
|
|
21
|
+
return JSON.parse(line)
|
|
22
|
+
} catch {
|
|
23
|
+
return null
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
.filter(Boolean)
|
|
27
|
+
|
|
28
|
+
const hashText = (text) => {
|
|
29
|
+
let hash = 0
|
|
30
|
+
for (let i = 0; i < text.length; i += 1) {
|
|
31
|
+
hash = (hash << 5) - hash + text.charCodeAt(i)
|
|
32
|
+
hash |= 0
|
|
33
|
+
}
|
|
34
|
+
return String(hash)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const renderPath = (events) => {
|
|
38
|
+
const steps = []
|
|
39
|
+
const seen = new Set()
|
|
40
|
+
for (const event of events) {
|
|
41
|
+
if (event.stepName && event.type.startsWith('step:')) {
|
|
42
|
+
if (!seen.has(event.stepName)) {
|
|
43
|
+
seen.add(event.stepName)
|
|
44
|
+
steps.push(event.stepName)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (!steps.length) {
|
|
50
|
+
pathElContainer.innerHTML = '<div class="empty">No execution data yet.</div>'
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
pathElContainer.innerHTML = steps
|
|
55
|
+
.map((step, index) => {
|
|
56
|
+
const node = `<span class="node">${step}</span>`
|
|
57
|
+
const arrow = index < steps.length - 1 ? '<span class="arrow">-></span>' : ''
|
|
58
|
+
return `${node}${arrow}`
|
|
59
|
+
})
|
|
60
|
+
.join('')
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const renderStatus = (events) => {
|
|
64
|
+
if (!events.length) {
|
|
65
|
+
statusEl.innerHTML = '<div class="empty">No trace events.</div>'
|
|
66
|
+
return
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const lastWorkflow = [...events]
|
|
70
|
+
.reverse()
|
|
71
|
+
.find((event) => event.type.startsWith('workflow:'))
|
|
72
|
+
|
|
73
|
+
const status = lastWorkflow?.status ?? 'unknown'
|
|
74
|
+
const badgeClass = status === 'completed' ? 'ok' : status === 'failed' ? 'fail' : ''
|
|
75
|
+
|
|
76
|
+
statusEl.innerHTML = `
|
|
77
|
+
<div>Workflow: <span class="badge ${badgeClass}">${status}</span></div>
|
|
78
|
+
<div>Workflow ID: ${lastWorkflow?.workflowId ?? '-'}</div>
|
|
79
|
+
<div>Workflow Name: ${lastWorkflow?.workflowName ?? '-'}</div>
|
|
80
|
+
<div>Duration: ${lastWorkflow?.duration ? `${lastWorkflow.duration}ms` : '-'}</div>
|
|
81
|
+
`
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const renderEvents = (events) => {
|
|
85
|
+
if (!events.length) {
|
|
86
|
+
eventsEl.innerHTML = '<tr><td colspan="6" class="empty">No events yet.</td></tr>'
|
|
87
|
+
return
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
eventsEl.innerHTML = events
|
|
91
|
+
.slice()
|
|
92
|
+
.reverse()
|
|
93
|
+
.map((event) => {
|
|
94
|
+
const retry =
|
|
95
|
+
typeof event.retries === 'number'
|
|
96
|
+
? `${event.retries}${event.maxRetries ? `/${event.maxRetries}` : ''}`
|
|
97
|
+
: '-'
|
|
98
|
+
const duration = event.duration ? `${event.duration}ms` : '-'
|
|
99
|
+
const msg = event.error ?? ''
|
|
100
|
+
return `
|
|
101
|
+
<tr>
|
|
102
|
+
<td>${formatTime(event.timestamp)}</td>
|
|
103
|
+
<td>${event.type}</td>
|
|
104
|
+
<td>${event.stepName ?? '-'}</td>
|
|
105
|
+
<td>${retry}</td>
|
|
106
|
+
<td>${duration}</td>
|
|
107
|
+
<td>${msg}</td>
|
|
108
|
+
</tr>
|
|
109
|
+
`
|
|
110
|
+
})
|
|
111
|
+
.join('')
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const refresh = async () => {
|
|
115
|
+
const res = await fetch('/trace', { cache: 'no-store' })
|
|
116
|
+
const text = await res.text()
|
|
117
|
+
const hash = hashText(text)
|
|
118
|
+
if (hash === state.lastHash) return
|
|
119
|
+
|
|
120
|
+
state.lastHash = hash
|
|
121
|
+
state.events = parseNdjson(text)
|
|
122
|
+
pathEl.textContent = 'Trace: /trace'
|
|
123
|
+
updateEl.textContent = `Updated: ${new Date().toLocaleTimeString()}`
|
|
124
|
+
|
|
125
|
+
renderPath(state.events)
|
|
126
|
+
renderStatus(state.events)
|
|
127
|
+
renderEvents(state.events)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
refresh()
|
|
131
|
+
setInterval(refresh, 1500)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
|
6
|
+
<title>Flux Dev Viewer</title>
|
|
7
|
+
<link rel="stylesheet" href="/styles.css" />
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<header class="topbar">
|
|
11
|
+
<div>
|
|
12
|
+
<h1>Flux Dev Viewer</h1>
|
|
13
|
+
<p class="subtitle">Local workflow trace explorer</p>
|
|
14
|
+
</div>
|
|
15
|
+
<div class="meta">
|
|
16
|
+
<div id="tracePath">Trace: -</div>
|
|
17
|
+
<div id="lastUpdate">Updated: -</div>
|
|
18
|
+
</div>
|
|
19
|
+
</header>
|
|
20
|
+
|
|
21
|
+
<main class="grid">
|
|
22
|
+
<section class="card">
|
|
23
|
+
<h2>Execution Path</h2>
|
|
24
|
+
<div id="path" class="path"></div>
|
|
25
|
+
</section>
|
|
26
|
+
|
|
27
|
+
<section class="card">
|
|
28
|
+
<h2>Status</h2>
|
|
29
|
+
<div id="status" class="status"></div>
|
|
30
|
+
</section>
|
|
31
|
+
|
|
32
|
+
<section class="card full">
|
|
33
|
+
<h2>Timeline</h2>
|
|
34
|
+
<table class="timeline">
|
|
35
|
+
<thead>
|
|
36
|
+
<tr>
|
|
37
|
+
<th>Time</th>
|
|
38
|
+
<th>Event</th>
|
|
39
|
+
<th>Step</th>
|
|
40
|
+
<th>Retry</th>
|
|
41
|
+
<th>Duration</th>
|
|
42
|
+
<th>Message</th>
|
|
43
|
+
</tr>
|
|
44
|
+
</thead>
|
|
45
|
+
<tbody id="events"></tbody>
|
|
46
|
+
</table>
|
|
47
|
+
</section>
|
|
48
|
+
</main>
|
|
49
|
+
|
|
50
|
+
<script src="/app.js"></script>
|
|
51
|
+
</body>
|
|
52
|
+
</html>
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
* {
|
|
2
|
+
box-sizing: border-box;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
body {
|
|
6
|
+
margin: 0;
|
|
7
|
+
font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;
|
|
8
|
+
background: #0c0f14;
|
|
9
|
+
color: #e6eaf2;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.topbar {
|
|
13
|
+
display: flex;
|
|
14
|
+
justify-content: space-between;
|
|
15
|
+
align-items: center;
|
|
16
|
+
padding: 20px 32px;
|
|
17
|
+
border-bottom: 1px solid #1d2330;
|
|
18
|
+
background: linear-gradient(120deg, #111826, #0f1420);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.topbar h1 {
|
|
22
|
+
margin: 0 0 6px;
|
|
23
|
+
font-size: 20px;
|
|
24
|
+
letter-spacing: 0.04em;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.subtitle {
|
|
28
|
+
margin: 0;
|
|
29
|
+
color: #93a0b4;
|
|
30
|
+
font-size: 13px;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.meta {
|
|
34
|
+
text-align: right;
|
|
35
|
+
font-size: 12px;
|
|
36
|
+
color: #9aa6ba;
|
|
37
|
+
line-height: 1.6;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.grid {
|
|
41
|
+
display: grid;
|
|
42
|
+
gap: 18px;
|
|
43
|
+
padding: 24px 32px 40px;
|
|
44
|
+
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.card {
|
|
48
|
+
background: #131a26;
|
|
49
|
+
border: 1px solid #1d2330;
|
|
50
|
+
border-radius: 14px;
|
|
51
|
+
padding: 18px 18px 12px;
|
|
52
|
+
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.card.full {
|
|
56
|
+
grid-column: 1 / -1;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.card h2 {
|
|
60
|
+
margin: 0 0 14px;
|
|
61
|
+
font-size: 14px;
|
|
62
|
+
color: #c7d1e6;
|
|
63
|
+
letter-spacing: 0.08em;
|
|
64
|
+
text-transform: uppercase;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.path {
|
|
68
|
+
display: flex;
|
|
69
|
+
flex-wrap: wrap;
|
|
70
|
+
gap: 10px;
|
|
71
|
+
align-items: center;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.node {
|
|
75
|
+
padding: 8px 12px;
|
|
76
|
+
border-radius: 999px;
|
|
77
|
+
background: #1a2333;
|
|
78
|
+
border: 1px solid #2b3a52;
|
|
79
|
+
font-size: 12px;
|
|
80
|
+
color: #d6deec;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.arrow {
|
|
84
|
+
color: #7c8da7;
|
|
85
|
+
font-size: 14px;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.status {
|
|
89
|
+
display: grid;
|
|
90
|
+
gap: 8px;
|
|
91
|
+
font-size: 13px;
|
|
92
|
+
color: #b9c5d9;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.badge {
|
|
96
|
+
display: inline-block;
|
|
97
|
+
padding: 2px 8px;
|
|
98
|
+
border-radius: 999px;
|
|
99
|
+
font-size: 11px;
|
|
100
|
+
text-transform: uppercase;
|
|
101
|
+
letter-spacing: 0.08em;
|
|
102
|
+
background: #1e2532;
|
|
103
|
+
color: #9db0cc;
|
|
104
|
+
border: 1px solid #2b364a;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.badge.ok {
|
|
108
|
+
background: rgba(34, 197, 94, 0.15);
|
|
109
|
+
color: #7ee4a6;
|
|
110
|
+
border-color: rgba(34, 197, 94, 0.3);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.badge.fail {
|
|
114
|
+
background: rgba(248, 113, 113, 0.15);
|
|
115
|
+
color: #fca5a5;
|
|
116
|
+
border-color: rgba(248, 113, 113, 0.3);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.timeline {
|
|
120
|
+
width: 100%;
|
|
121
|
+
border-collapse: collapse;
|
|
122
|
+
font-size: 12px;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
.timeline th,
|
|
126
|
+
.timeline td {
|
|
127
|
+
padding: 10px 8px;
|
|
128
|
+
border-bottom: 1px solid #1d2330;
|
|
129
|
+
text-align: left;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.timeline th {
|
|
133
|
+
color: #91a0b7;
|
|
134
|
+
font-weight: 600;
|
|
135
|
+
font-size: 11px;
|
|
136
|
+
text-transform: uppercase;
|
|
137
|
+
letter-spacing: 0.08em;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
.timeline tr:last-child td {
|
|
141
|
+
border-bottom: none;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.empty {
|
|
145
|
+
color: #7f8ba3;
|
|
146
|
+
font-size: 12px;
|
|
147
|
+
padding: 10px 0;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
@media (max-width: 900px) {
|
|
151
|
+
.grid {
|
|
152
|
+
grid-template-columns: 1fr;
|
|
153
|
+
}
|
|
154
|
+
.meta {
|
|
155
|
+
text-align: left;
|
|
156
|
+
margin-top: 10px;
|
|
157
|
+
}
|
|
158
|
+
.topbar {
|
|
159
|
+
flex-direction: column;
|
|
160
|
+
align-items: flex-start;
|
|
161
|
+
gap: 12px;
|
|
162
|
+
}
|
|
163
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravito/flux",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.2",
|
|
4
4
|
"description": "Platform-agnostic workflow engine for Gravito",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/node/index.cjs",
|
|
@@ -28,12 +28,19 @@
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
|
+
"bin": {
|
|
32
|
+
"flux": "./bin/flux.js"
|
|
33
|
+
},
|
|
31
34
|
"files": [
|
|
32
35
|
"dist",
|
|
33
|
-
"README.md"
|
|
36
|
+
"README.md",
|
|
37
|
+
"README.zh-TW.md",
|
|
38
|
+
"bin",
|
|
39
|
+
"dev"
|
|
34
40
|
],
|
|
35
41
|
"scripts": {
|
|
36
42
|
"build": "bun run build.ts",
|
|
43
|
+
"dev:viewer": "node ./bin/flux.js dev --trace ./.flux/trace.ndjson --port 4280",
|
|
37
44
|
"typecheck": "tsc --noEmit",
|
|
38
45
|
"test": "bun test"
|
|
39
46
|
},
|