@q1k-oss/btree-workflows 0.0.1
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/.claude/settings.local.json +31 -0
- package/CLAUDE.md +181 -0
- package/LICENSE +21 -0
- package/README.md +920 -0
- package/behaviour-tree-workflows-landing/index.html +16 -0
- package/behaviour-tree-workflows-landing/package-lock.json +2074 -0
- package/behaviour-tree-workflows-landing/package.json +31 -0
- package/behaviour-tree-workflows-landing/public/favicon.svg +17 -0
- package/behaviour-tree-workflows-landing/src/App.css +103 -0
- package/behaviour-tree-workflows-landing/src/App.tsx +176 -0
- package/behaviour-tree-workflows-landing/src/components/BlackboardInspector.css +89 -0
- package/behaviour-tree-workflows-landing/src/components/BlackboardInspector.tsx +64 -0
- package/behaviour-tree-workflows-landing/src/components/ExampleSelector.css +64 -0
- package/behaviour-tree-workflows-landing/src/components/ExampleSelector.tsx +34 -0
- package/behaviour-tree-workflows-landing/src/components/ExecutionLog.css +107 -0
- package/behaviour-tree-workflows-landing/src/components/ExecutionLog.tsx +85 -0
- package/behaviour-tree-workflows-landing/src/components/Header.css +50 -0
- package/behaviour-tree-workflows-landing/src/components/Header.tsx +26 -0
- package/behaviour-tree-workflows-landing/src/components/StatusBadge.css +45 -0
- package/behaviour-tree-workflows-landing/src/components/StatusBadge.tsx +15 -0
- package/behaviour-tree-workflows-landing/src/components/Toolbar.css +74 -0
- package/behaviour-tree-workflows-landing/src/components/Toolbar.tsx +53 -0
- package/behaviour-tree-workflows-landing/src/components/TreeVisualizer.css +67 -0
- package/behaviour-tree-workflows-landing/src/components/TreeVisualizer.tsx +192 -0
- package/behaviour-tree-workflows-landing/src/components/YamlEditor.css +18 -0
- package/behaviour-tree-workflows-landing/src/components/YamlEditor.tsx +96 -0
- package/behaviour-tree-workflows-landing/src/lib/count-nodes.ts +11 -0
- package/behaviour-tree-workflows-landing/src/lib/execution-engine.ts +96 -0
- package/behaviour-tree-workflows-landing/src/lib/tree-layout.ts +136 -0
- package/behaviour-tree-workflows-landing/src/lib/yaml-examples.ts +549 -0
- package/behaviour-tree-workflows-landing/src/main.tsx +9 -0
- package/behaviour-tree-workflows-landing/src/stubs/activepieces.ts +18 -0
- package/behaviour-tree-workflows-landing/src/stubs/fs.ts +24 -0
- package/behaviour-tree-workflows-landing/src/stubs/path.ts +16 -0
- package/behaviour-tree-workflows-landing/src/stubs/temporal-activity.ts +6 -0
- package/behaviour-tree-workflows-landing/src/stubs/temporal-workflow.ts +22 -0
- package/behaviour-tree-workflows-landing/tsconfig.json +25 -0
- package/behaviour-tree-workflows-landing/vite.config.ts +40 -0
- package/demo-google-sheets.ts +181 -0
- package/demo-runtime-variables.ts +174 -0
- package/demo-template.ts +208 -0
- package/docs/ARCHITECTURE_SUMMARY.md +613 -0
- package/docs/NODE_REFERENCE.md +504 -0
- package/docs/README.md +53 -0
- package/docs/custom-nodes-architecture.md +826 -0
- package/docs/observability.md +175 -0
- package/docs/yaml-specification.md +990 -0
- package/examples/temporal/README.md +117 -0
- package/examples/temporal/activities.ts +373 -0
- package/examples/temporal/client.ts +115 -0
- package/examples/temporal/python-worker/activities.py +339 -0
- package/examples/temporal/python-worker/requirements.txt +12 -0
- package/examples/temporal/python-worker/worker.py +106 -0
- package/examples/temporal/worker.ts +66 -0
- package/examples/temporal/workflows.ts +6 -0
- package/examples/temporal/yaml-workflow-loader.ts +105 -0
- package/examples/yaml-test.ts +97 -0
- package/examples/yaml-workflows/01-simple-sequence.yaml +25 -0
- package/examples/yaml-workflows/02-parallel-timeout.yaml +45 -0
- package/examples/yaml-workflows/03-ecommerce-checkout.yaml +94 -0
- package/examples/yaml-workflows/04-ai-agent-workflow.yaml +346 -0
- package/examples/yaml-workflows/05-order-processing.yaml +146 -0
- package/examples/yaml-workflows/06-activity-test.yaml +71 -0
- package/examples/yaml-workflows/07-activity-simple-test.yaml +43 -0
- package/examples/yaml-workflows/08-file-processing.yaml +141 -0
- package/examples/yaml-workflows/09-http-request.yaml +137 -0
- package/examples/yaml-workflows/README.md +211 -0
- package/package.json +38 -0
- package/src/actions/code-execution.schema.ts +27 -0
- package/src/actions/code-execution.ts +218 -0
- package/src/actions/generate-file.test.ts +516 -0
- package/src/actions/generate-file.ts +166 -0
- package/src/actions/http-request.test.ts +784 -0
- package/src/actions/http-request.ts +228 -0
- package/src/actions/index.ts +20 -0
- package/src/actions/parse-file.test.ts +448 -0
- package/src/actions/parse-file.ts +139 -0
- package/src/actions/python-script.test.ts +439 -0
- package/src/actions/python-script.ts +154 -0
- package/src/base-node.test.ts +511 -0
- package/src/base-node.ts +605 -0
- package/src/behavior-tree.test.ts +431 -0
- package/src/behavior-tree.ts +283 -0
- package/src/blackboard.test.ts +222 -0
- package/src/blackboard.ts +192 -0
- package/src/composites/conditional.schema.ts +19 -0
- package/src/composites/conditional.test.ts +309 -0
- package/src/composites/conditional.ts +129 -0
- package/src/composites/for-each.schema.ts +23 -0
- package/src/composites/for-each.test.ts +254 -0
- package/src/composites/for-each.ts +132 -0
- package/src/composites/index.ts +15 -0
- package/src/composites/memory-sequence.schema.ts +19 -0
- package/src/composites/memory-sequence.test.ts +223 -0
- package/src/composites/memory-sequence.ts +98 -0
- package/src/composites/parallel.schema.ts +28 -0
- package/src/composites/parallel.test.ts +502 -0
- package/src/composites/parallel.ts +157 -0
- package/src/composites/reactive-sequence.schema.ts +19 -0
- package/src/composites/reactive-sequence.test.ts +170 -0
- package/src/composites/reactive-sequence.ts +85 -0
- package/src/composites/recovery.schema.ts +19 -0
- package/src/composites/recovery.test.ts +366 -0
- package/src/composites/recovery.ts +90 -0
- package/src/composites/selector.schema.ts +19 -0
- package/src/composites/selector.test.ts +387 -0
- package/src/composites/selector.ts +85 -0
- package/src/composites/sequence.schema.ts +19 -0
- package/src/composites/sequence.test.ts +337 -0
- package/src/composites/sequence.ts +72 -0
- package/src/composites/sub-tree.schema.ts +21 -0
- package/src/composites/sub-tree.test.ts +893 -0
- package/src/composites/sub-tree.ts +177 -0
- package/src/composites/while.schema.ts +24 -0
- package/src/composites/while.test.ts +381 -0
- package/src/composites/while.ts +149 -0
- package/src/data-store/index.ts +10 -0
- package/src/data-store/memory-store.ts +161 -0
- package/src/data-store/types.ts +94 -0
- package/src/debug/breakpoint.test.ts +47 -0
- package/src/debug/breakpoint.ts +30 -0
- package/src/debug/index.ts +17 -0
- package/src/debug/resume-point.test.ts +49 -0
- package/src/debug/resume-point.ts +29 -0
- package/src/decorators/delay.schema.ts +21 -0
- package/src/decorators/delay.test.ts +261 -0
- package/src/decorators/delay.ts +140 -0
- package/src/decorators/force-result.schema.ts +32 -0
- package/src/decorators/force-result.test.ts +133 -0
- package/src/decorators/force-result.ts +63 -0
- package/src/decorators/index.ts +13 -0
- package/src/decorators/invert.schema.ts +19 -0
- package/src/decorators/invert.test.ts +135 -0
- package/src/decorators/invert.ts +42 -0
- package/src/decorators/keep-running.schema.ts +20 -0
- package/src/decorators/keep-running.test.ts +105 -0
- package/src/decorators/keep-running.ts +49 -0
- package/src/decorators/precondition.schema.ts +19 -0
- package/src/decorators/precondition.test.ts +351 -0
- package/src/decorators/precondition.ts +139 -0
- package/src/decorators/repeat.schema.ts +21 -0
- package/src/decorators/repeat.test.ts +187 -0
- package/src/decorators/repeat.ts +94 -0
- package/src/decorators/run-once.schema.ts +19 -0
- package/src/decorators/run-once.test.ts +140 -0
- package/src/decorators/run-once.ts +61 -0
- package/src/decorators/soft-assert.schema.ts +19 -0
- package/src/decorators/soft-assert.test.ts +107 -0
- package/src/decorators/soft-assert.ts +68 -0
- package/src/decorators/timeout.schema.ts +21 -0
- package/src/decorators/timeout.test.ts +274 -0
- package/src/decorators/timeout.ts +159 -0
- package/src/errors.test.ts +63 -0
- package/src/errors.ts +34 -0
- package/src/events.test.ts +347 -0
- package/src/events.ts +183 -0
- package/src/index.ts +80 -0
- package/src/integrations/index.ts +30 -0
- package/src/integrations/integration-action.test.ts +571 -0
- package/src/integrations/integration-action.ts +233 -0
- package/src/integrations/piece-executor.ts +320 -0
- package/src/observability/execution-tracker.ts +320 -0
- package/src/observability/index.ts +23 -0
- package/src/observability/sinks.ts +138 -0
- package/src/observability/types.ts +130 -0
- package/src/registry-utils.ts +147 -0
- package/src/registry.test.ts +466 -0
- package/src/registry.ts +334 -0
- package/src/schemas/base.schema.ts +104 -0
- package/src/schemas/index.ts +223 -0
- package/src/schemas/integration.test.ts +238 -0
- package/src/schemas/tree-definition.schema.ts +170 -0
- package/src/schemas/validation.test.ts +146 -0
- package/src/schemas/validation.ts +122 -0
- package/src/scripting/index.ts +22 -0
- package/src/templates/template-loader.test.ts +281 -0
- package/src/templates/template-loader.ts +152 -0
- package/src/temporal-integration.test.ts +213 -0
- package/src/test-nodes.ts +259 -0
- package/src/types.ts +503 -0
- package/src/utilities/index.ts +17 -0
- package/src/utilities/log-message.test.ts +275 -0
- package/src/utilities/log-message.ts +134 -0
- package/src/utilities/regex-extract.test.ts +138 -0
- package/src/utilities/regex-extract.ts +108 -0
- package/src/utilities/variable-resolver.test.ts +416 -0
- package/src/utilities/variable-resolver.ts +318 -0
- package/src/utils/error-handler.test.ts +117 -0
- package/src/utils/error-handler.ts +48 -0
- package/src/utils/signal-check.test.ts +234 -0
- package/src/utils/signal-check.ts +140 -0
- package/src/yaml/errors.ts +143 -0
- package/src/yaml/index.ts +30 -0
- package/src/yaml/loader.ts +39 -0
- package/src/yaml/parser.ts +286 -0
- package/src/yaml/validation/semantic-validator.ts +196 -0
- package/templates/google-sheets/insert-row.yaml +76 -0
- package/templates/notification-sender.yaml +33 -0
- package/templates/order-validation.yaml +44 -0
- package/tsconfig.json +24 -0
- package/vitest.config.ts +25 -0
- package/workflows/order-processor.yaml +59 -0
- package/workflows/process-order-workflow.yaml +142 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import React, { useRef, useEffect } from 'react';
|
|
2
|
+
import type { NodeEvent } from '@btree/events';
|
|
3
|
+
import './ExecutionLog.css';
|
|
4
|
+
|
|
5
|
+
interface ExecutionLogProps {
|
|
6
|
+
events: NodeEvent<unknown>[];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function formatTime(ts: number, base: number): string {
|
|
10
|
+
const diff = ts - base;
|
|
11
|
+
return `+${diff}ms`;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function getEventIcon(type: string, data?: Record<string, unknown>): string {
|
|
15
|
+
if (type === 'tick_start') return '>';
|
|
16
|
+
if (type === 'tick_end') {
|
|
17
|
+
const status = data?.status as string | undefined;
|
|
18
|
+
if (status === 'SUCCESS') return 'ok';
|
|
19
|
+
if (status === 'FAILURE') return '!!';
|
|
20
|
+
if (status === 'RUNNING') return '..';
|
|
21
|
+
return '--';
|
|
22
|
+
}
|
|
23
|
+
if (type === 'error') return 'ERR';
|
|
24
|
+
if (type === 'log') return 'LOG';
|
|
25
|
+
return ' ';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function getEventClass(type: string, data?: Record<string, unknown>): string {
|
|
29
|
+
if (type === 'error') return 'log-entry--error';
|
|
30
|
+
if (type === 'tick_end') {
|
|
31
|
+
const status = data?.status as string | undefined;
|
|
32
|
+
if (status === 'SUCCESS') return 'log-entry--success';
|
|
33
|
+
if (status === 'FAILURE') return 'log-entry--failure';
|
|
34
|
+
if (status === 'RUNNING') return 'log-entry--running';
|
|
35
|
+
}
|
|
36
|
+
return '';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const ExecutionLog: React.FC<ExecutionLogProps> = ({ events }) => {
|
|
40
|
+
const scrollRef = useRef<HTMLDivElement>(null);
|
|
41
|
+
const baseTime = events.length > 0 ? events[0].timestamp : 0;
|
|
42
|
+
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (scrollRef.current) {
|
|
45
|
+
scrollRef.current.scrollTop = scrollRef.current.scrollHeight;
|
|
46
|
+
}
|
|
47
|
+
}, [events.length]);
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<div className="execution-log">
|
|
51
|
+
<div className="execution-log__header">
|
|
52
|
+
Execution Log
|
|
53
|
+
<span className="execution-log__count">{events.length} events</span>
|
|
54
|
+
</div>
|
|
55
|
+
<div className="execution-log__body" ref={scrollRef}>
|
|
56
|
+
{events.length === 0 ? (
|
|
57
|
+
<div className="execution-log__empty">Run a workflow to see events</div>
|
|
58
|
+
) : (
|
|
59
|
+
events.map((event, i) => {
|
|
60
|
+
const data = event.data as Record<string, unknown> | undefined;
|
|
61
|
+
return (
|
|
62
|
+
<div
|
|
63
|
+
key={i}
|
|
64
|
+
className={`log-entry ${getEventClass(event.type, data)}`}
|
|
65
|
+
>
|
|
66
|
+
<span className="log-entry__time">{formatTime(event.timestamp, baseTime)}</span>
|
|
67
|
+
<span className="log-entry__icon">{getEventIcon(event.type, data)}</span>
|
|
68
|
+
<span className="log-entry__type">{event.nodeType}</span>
|
|
69
|
+
<span className="log-entry__name">{event.nodeName || event.nodeId}</span>
|
|
70
|
+
{data?.status && (
|
|
71
|
+
<span className="log-entry__status">{data.status as string}</span>
|
|
72
|
+
)}
|
|
73
|
+
{data?.error && (
|
|
74
|
+
<span className="log-entry__error">
|
|
75
|
+
{(data.error as Record<string, string>).message}
|
|
76
|
+
</span>
|
|
77
|
+
)}
|
|
78
|
+
</div>
|
|
79
|
+
);
|
|
80
|
+
})
|
|
81
|
+
)}
|
|
82
|
+
</div>
|
|
83
|
+
</div>
|
|
84
|
+
);
|
|
85
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
.header {
|
|
2
|
+
display: flex;
|
|
3
|
+
align-items: center;
|
|
4
|
+
justify-content: space-between;
|
|
5
|
+
padding: 0 20px;
|
|
6
|
+
height: 48px;
|
|
7
|
+
background: var(--color-surface-1);
|
|
8
|
+
border-bottom: 1px solid var(--color-border);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.header__brand {
|
|
12
|
+
display: flex;
|
|
13
|
+
align-items: center;
|
|
14
|
+
gap: 10px;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.header__logo {
|
|
18
|
+
flex-shrink: 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.header__title {
|
|
22
|
+
font-weight: 600;
|
|
23
|
+
font-size: 15px;
|
|
24
|
+
color: var(--color-text);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.header__badge {
|
|
28
|
+
font-size: 11px;
|
|
29
|
+
font-weight: 500;
|
|
30
|
+
padding: 2px 8px;
|
|
31
|
+
border-radius: 10px;
|
|
32
|
+
background: rgba(129, 140, 248, 0.15);
|
|
33
|
+
color: #818cf8;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.header__links {
|
|
37
|
+
display: flex;
|
|
38
|
+
gap: 16px;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.header__links a {
|
|
42
|
+
font-size: 13px;
|
|
43
|
+
color: var(--color-text-muted);
|
|
44
|
+
text-decoration: none;
|
|
45
|
+
transition: color 0.15s;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.header__links a:hover {
|
|
49
|
+
color: var(--color-text);
|
|
50
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import './Header.css';
|
|
3
|
+
|
|
4
|
+
export const Header: React.FC = () => {
|
|
5
|
+
return (
|
|
6
|
+
<header className="header">
|
|
7
|
+
<div className="header__brand">
|
|
8
|
+
<svg className="header__logo" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg" width="28" height="28">
|
|
9
|
+
<circle cx="16" cy="4" r="3.5" fill="#818cf8" stroke="#6366f1" strokeWidth="1"/>
|
|
10
|
+
<circle cx="6" cy="16" r="3" fill="#34d399" stroke="#10b981" strokeWidth="1"/>
|
|
11
|
+
<circle cx="16" cy="16" r="3" fill="#fbbf24" stroke="#f59e0b" strokeWidth="1"/>
|
|
12
|
+
<circle cx="26" cy="16" r="3" fill="#34d399" stroke="#10b981" strokeWidth="1"/>
|
|
13
|
+
<line x1="16" y1="7.5" x2="6" y2="13" stroke="#475569" strokeWidth="1.2"/>
|
|
14
|
+
<line x1="16" y1="7.5" x2="16" y2="13" stroke="#475569" strokeWidth="1.2"/>
|
|
15
|
+
<line x1="16" y1="7.5" x2="26" y2="13" stroke="#475569" strokeWidth="1.2"/>
|
|
16
|
+
</svg>
|
|
17
|
+
<span className="header__title">btree-workflows</span>
|
|
18
|
+
<span className="header__badge">Playground</span>
|
|
19
|
+
</div>
|
|
20
|
+
<nav className="header__links">
|
|
21
|
+
<a href="https://github.com/nicholasgriffintn/behaviour-tree-workflows" target="_blank" rel="noopener noreferrer">GitHub</a>
|
|
22
|
+
<a href="https://www.npmjs.com/package/@wayfarer-ai/btree-workflows" target="_blank" rel="noopener noreferrer">npm</a>
|
|
23
|
+
</nav>
|
|
24
|
+
</header>
|
|
25
|
+
);
|
|
26
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
.status-badge {
|
|
2
|
+
display: inline-flex;
|
|
3
|
+
align-items: center;
|
|
4
|
+
font-family: 'JetBrains Mono', monospace;
|
|
5
|
+
font-weight: 500;
|
|
6
|
+
border-radius: 6px;
|
|
7
|
+
text-transform: uppercase;
|
|
8
|
+
letter-spacing: 0.05em;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.status-badge--md {
|
|
12
|
+
font-size: 12px;
|
|
13
|
+
padding: 4px 10px;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.status-badge--sm {
|
|
17
|
+
font-size: 10px;
|
|
18
|
+
padding: 2px 6px;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.status-badge--idle {
|
|
22
|
+
background: var(--color-surface-2);
|
|
23
|
+
color: var(--color-text-muted);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.status-badge--success {
|
|
27
|
+
background: rgba(52, 211, 153, 0.15);
|
|
28
|
+
color: #34d399;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.status-badge--failure {
|
|
32
|
+
background: rgba(248, 113, 113, 0.15);
|
|
33
|
+
color: #f87171;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.status-badge--running {
|
|
37
|
+
background: rgba(251, 191, 36, 0.15);
|
|
38
|
+
color: #fbbf24;
|
|
39
|
+
animation: pulse-badge 1.5s ease-in-out infinite;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@keyframes pulse-badge {
|
|
43
|
+
0%, 100% { opacity: 1; }
|
|
44
|
+
50% { opacity: 0.6; }
|
|
45
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import './StatusBadge.css';
|
|
3
|
+
|
|
4
|
+
interface StatusBadgeProps {
|
|
5
|
+
status: string;
|
|
6
|
+
size?: 'sm' | 'md';
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const StatusBadge: React.FC<StatusBadgeProps> = ({ status, size = 'md' }) => {
|
|
10
|
+
return (
|
|
11
|
+
<span className={`status-badge status-badge--${status.toLowerCase()} status-badge--${size}`}>
|
|
12
|
+
{status}
|
|
13
|
+
</span>
|
|
14
|
+
);
|
|
15
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
.toolbar {
|
|
2
|
+
display: flex;
|
|
3
|
+
align-items: center;
|
|
4
|
+
justify-content: space-between;
|
|
5
|
+
padding: 8px 20px;
|
|
6
|
+
background: var(--color-surface-1);
|
|
7
|
+
border-bottom: 1px solid var(--color-border);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.toolbar__left,
|
|
11
|
+
.toolbar__right {
|
|
12
|
+
display: flex;
|
|
13
|
+
align-items: center;
|
|
14
|
+
gap: 8px;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.toolbar__btn {
|
|
18
|
+
font-family: 'Inter', sans-serif;
|
|
19
|
+
font-size: 13px;
|
|
20
|
+
font-weight: 500;
|
|
21
|
+
padding: 6px 16px;
|
|
22
|
+
border: 1px solid var(--color-border);
|
|
23
|
+
border-radius: 6px;
|
|
24
|
+
background: var(--color-surface-2);
|
|
25
|
+
color: var(--color-text);
|
|
26
|
+
cursor: pointer;
|
|
27
|
+
display: flex;
|
|
28
|
+
align-items: center;
|
|
29
|
+
gap: 6px;
|
|
30
|
+
transition: all 0.15s;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.toolbar__btn:hover:not(:disabled) {
|
|
34
|
+
border-color: var(--color-accent);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.toolbar__btn:disabled {
|
|
38
|
+
opacity: 0.5;
|
|
39
|
+
cursor: not-allowed;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.toolbar__btn--run {
|
|
43
|
+
background: rgba(129, 140, 248, 0.15);
|
|
44
|
+
border-color: var(--color-accent);
|
|
45
|
+
color: var(--color-accent);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.toolbar__btn--run:hover:not(:disabled) {
|
|
49
|
+
background: rgba(129, 140, 248, 0.25);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.toolbar__spinner {
|
|
53
|
+
width: 14px;
|
|
54
|
+
height: 14px;
|
|
55
|
+
border: 2px solid transparent;
|
|
56
|
+
border-top-color: var(--color-accent);
|
|
57
|
+
border-radius: 50%;
|
|
58
|
+
animation: spin 0.6s linear infinite;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@keyframes spin {
|
|
62
|
+
to { transform: rotate(360deg); }
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.toolbar__hint {
|
|
66
|
+
font-size: 11px;
|
|
67
|
+
color: #fbbf24;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.toolbar__info {
|
|
71
|
+
font-size: 12px;
|
|
72
|
+
color: var(--color-text-muted);
|
|
73
|
+
font-family: 'JetBrains Mono', monospace;
|
|
74
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { StatusBadge } from './StatusBadge';
|
|
3
|
+
import './Toolbar.css';
|
|
4
|
+
|
|
5
|
+
interface ToolbarProps {
|
|
6
|
+
status: string;
|
|
7
|
+
isRunning: boolean;
|
|
8
|
+
executable: boolean;
|
|
9
|
+
nodeCount: number;
|
|
10
|
+
onRun: () => void;
|
|
11
|
+
onReset: () => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const Toolbar: React.FC<ToolbarProps> = ({
|
|
15
|
+
status,
|
|
16
|
+
isRunning,
|
|
17
|
+
executable,
|
|
18
|
+
nodeCount,
|
|
19
|
+
onRun,
|
|
20
|
+
onReset,
|
|
21
|
+
}) => {
|
|
22
|
+
return (
|
|
23
|
+
<div className="toolbar">
|
|
24
|
+
<div className="toolbar__left">
|
|
25
|
+
<button
|
|
26
|
+
className="toolbar__btn toolbar__btn--run"
|
|
27
|
+
onClick={onRun}
|
|
28
|
+
disabled={isRunning || !executable}
|
|
29
|
+
title={!executable ? 'This example requires Temporal activities and can only be visualized' : ''}
|
|
30
|
+
>
|
|
31
|
+
{isRunning ? (
|
|
32
|
+
<span className="toolbar__spinner" />
|
|
33
|
+
) : (
|
|
34
|
+
<svg width="14" height="14" viewBox="0 0 14 14" fill="currentColor">
|
|
35
|
+
<path d="M3 1.5v11l9-5.5z"/>
|
|
36
|
+
</svg>
|
|
37
|
+
)}
|
|
38
|
+
{isRunning ? 'Running...' : 'Run'}
|
|
39
|
+
</button>
|
|
40
|
+
<button className="toolbar__btn" onClick={onReset} disabled={isRunning}>
|
|
41
|
+
Reset
|
|
42
|
+
</button>
|
|
43
|
+
{!executable && (
|
|
44
|
+
<span className="toolbar__hint">View-only: requires Temporal activities</span>
|
|
45
|
+
)}
|
|
46
|
+
</div>
|
|
47
|
+
<div className="toolbar__right">
|
|
48
|
+
<span className="toolbar__info">{nodeCount} nodes</span>
|
|
49
|
+
<StatusBadge status={status} />
|
|
50
|
+
</div>
|
|
51
|
+
</div>
|
|
52
|
+
);
|
|
53
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
.tree-visualizer {
|
|
2
|
+
width: 100%;
|
|
3
|
+
height: 100%;
|
|
4
|
+
position: relative;
|
|
5
|
+
overflow: hidden;
|
|
6
|
+
background: var(--color-bg);
|
|
7
|
+
background-image:
|
|
8
|
+
radial-gradient(circle, var(--color-border) 1px, transparent 1px);
|
|
9
|
+
background-size: 24px 24px;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.tree-visualizer--empty {
|
|
13
|
+
display: flex;
|
|
14
|
+
align-items: center;
|
|
15
|
+
justify-content: center;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.tree-visualizer--empty p {
|
|
19
|
+
font-size: 13px;
|
|
20
|
+
color: var(--color-text-muted);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.tree-visualizer__svg {
|
|
24
|
+
width: 100%;
|
|
25
|
+
height: 100%;
|
|
26
|
+
cursor: grab;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.tree-visualizer__svg:active {
|
|
30
|
+
cursor: grabbing;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.tree-node--running {
|
|
34
|
+
animation: pulse-node 1.5s ease-in-out infinite;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@keyframes pulse-node {
|
|
38
|
+
0%, 100% { stroke-opacity: 1; }
|
|
39
|
+
50% { stroke-opacity: 0.4; }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.tree-visualizer__legend {
|
|
43
|
+
position: absolute;
|
|
44
|
+
bottom: 8px;
|
|
45
|
+
right: 8px;
|
|
46
|
+
display: flex;
|
|
47
|
+
gap: 12px;
|
|
48
|
+
background: var(--color-surface-1);
|
|
49
|
+
border: 1px solid var(--color-border);
|
|
50
|
+
border-radius: 6px;
|
|
51
|
+
padding: 4px 10px;
|
|
52
|
+
font-size: 11px;
|
|
53
|
+
color: var(--color-text-muted);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.tree-visualizer__legend span {
|
|
57
|
+
display: flex;
|
|
58
|
+
align-items: center;
|
|
59
|
+
gap: 4px;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.legend-dot {
|
|
63
|
+
display: inline-block;
|
|
64
|
+
width: 8px;
|
|
65
|
+
height: 8px;
|
|
66
|
+
border-radius: 50%;
|
|
67
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import React, { useRef, useState, useCallback, useEffect } from 'react';
|
|
2
|
+
import type { TreeNode } from '@btree/types';
|
|
3
|
+
import { layoutTree, type LayoutNode, type LayoutEdge } from '../lib/tree-layout';
|
|
4
|
+
import './TreeVisualizer.css';
|
|
5
|
+
|
|
6
|
+
interface TreeVisualizerProps {
|
|
7
|
+
tree: TreeNode | null;
|
|
8
|
+
nodeStates: Map<string, string>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const CATEGORY_COLORS: Record<string, string> = {
|
|
12
|
+
composite: '#818cf8',
|
|
13
|
+
decorator: '#fbbf24',
|
|
14
|
+
action: '#34d399',
|
|
15
|
+
condition: '#60a5fa',
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const STATUS_BORDER: Record<string, string> = {
|
|
19
|
+
idle: '#475569',
|
|
20
|
+
running: '#fbbf24',
|
|
21
|
+
success: '#34d399',
|
|
22
|
+
failure: '#f87171',
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const PADDING = 40;
|
|
26
|
+
|
|
27
|
+
function NodeRect({ node }: { node: LayoutNode }) {
|
|
28
|
+
const fill = CATEGORY_COLORS[node.category] || '#818cf8';
|
|
29
|
+
const stroke = STATUS_BORDER[node.status] || STATUS_BORDER.idle;
|
|
30
|
+
const isRunning = node.status === 'running';
|
|
31
|
+
|
|
32
|
+
// Truncate name
|
|
33
|
+
const displayName = node.name.length > 18 ? node.name.slice(0, 16) + '...' : node.name;
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<g>
|
|
37
|
+
<rect
|
|
38
|
+
x={node.x}
|
|
39
|
+
y={node.y}
|
|
40
|
+
width={node.width}
|
|
41
|
+
height={node.height}
|
|
42
|
+
rx={8}
|
|
43
|
+
ry={8}
|
|
44
|
+
fill={`${fill}20`}
|
|
45
|
+
stroke={stroke}
|
|
46
|
+
strokeWidth={isRunning ? 2.5 : 1.5}
|
|
47
|
+
className={isRunning ? 'tree-node--running' : ''}
|
|
48
|
+
/>
|
|
49
|
+
<text
|
|
50
|
+
x={node.x + node.width / 2}
|
|
51
|
+
y={node.y + 16}
|
|
52
|
+
textAnchor="middle"
|
|
53
|
+
fill={fill}
|
|
54
|
+
fontSize={10}
|
|
55
|
+
fontFamily="'JetBrains Mono', monospace"
|
|
56
|
+
fontWeight={500}
|
|
57
|
+
>
|
|
58
|
+
{node.type}
|
|
59
|
+
</text>
|
|
60
|
+
<text
|
|
61
|
+
x={node.x + node.width / 2}
|
|
62
|
+
y={node.y + 32}
|
|
63
|
+
textAnchor="middle"
|
|
64
|
+
fill="#94a3b8"
|
|
65
|
+
fontSize={10}
|
|
66
|
+
fontFamily="'Inter', sans-serif"
|
|
67
|
+
>
|
|
68
|
+
{displayName}
|
|
69
|
+
</text>
|
|
70
|
+
</g>
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function EdgeLine({ edge }: { edge: LayoutEdge }) {
|
|
75
|
+
const midY = (edge.fromY + edge.toY) / 2;
|
|
76
|
+
const d = `M ${edge.fromX} ${edge.fromY} C ${edge.fromX} ${midY}, ${edge.toX} ${midY}, ${edge.toX} ${edge.toY}`;
|
|
77
|
+
return (
|
|
78
|
+
<path
|
|
79
|
+
d={d}
|
|
80
|
+
fill="none"
|
|
81
|
+
stroke="#334155"
|
|
82
|
+
strokeWidth={1.2}
|
|
83
|
+
/>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function RenderTree({ node }: { node: LayoutNode }) {
|
|
88
|
+
return (
|
|
89
|
+
<>
|
|
90
|
+
<NodeRect node={node} />
|
|
91
|
+
{node.children.map((child) => (
|
|
92
|
+
<RenderTree key={child.id} node={child} />
|
|
93
|
+
))}
|
|
94
|
+
</>
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export const TreeVisualizer: React.FC<TreeVisualizerProps> = ({ tree, nodeStates }) => {
|
|
99
|
+
const svgRef = useRef<SVGSVGElement>(null);
|
|
100
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
101
|
+
const [viewBox, setViewBox] = useState({ x: 0, y: 0, w: 800, h: 600 });
|
|
102
|
+
const [isPanning, setIsPanning] = useState(false);
|
|
103
|
+
const panStart = useRef({ x: 0, y: 0, vx: 0, vy: 0 });
|
|
104
|
+
|
|
105
|
+
const layout = tree ? layoutTree(tree, nodeStates) : null;
|
|
106
|
+
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
if (layout) {
|
|
109
|
+
setViewBox({
|
|
110
|
+
x: -PADDING,
|
|
111
|
+
y: -PADDING,
|
|
112
|
+
w: layout.width + PADDING * 2,
|
|
113
|
+
h: layout.height + PADDING * 2,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}, [layout?.width, layout?.height]);
|
|
117
|
+
|
|
118
|
+
const handleWheel = useCallback((e: React.WheelEvent) => {
|
|
119
|
+
e.preventDefault();
|
|
120
|
+
const factor = e.deltaY > 0 ? 1.1 : 0.9;
|
|
121
|
+
setViewBox((vb) => {
|
|
122
|
+
const mx = e.nativeEvent.offsetX;
|
|
123
|
+
const my = e.nativeEvent.offsetY;
|
|
124
|
+
const svg = svgRef.current;
|
|
125
|
+
if (!svg) return vb;
|
|
126
|
+
const rect = svg.getBoundingClientRect();
|
|
127
|
+
const px = vb.x + (mx / rect.width) * vb.w;
|
|
128
|
+
const py = vb.y + (my / rect.height) * vb.h;
|
|
129
|
+
const nw = vb.w * factor;
|
|
130
|
+
const nh = vb.h * factor;
|
|
131
|
+
return {
|
|
132
|
+
x: px - (mx / rect.width) * nw,
|
|
133
|
+
y: py - (my / rect.height) * nh,
|
|
134
|
+
w: nw,
|
|
135
|
+
h: nh,
|
|
136
|
+
};
|
|
137
|
+
});
|
|
138
|
+
}, []);
|
|
139
|
+
|
|
140
|
+
const handleMouseDown = useCallback((e: React.MouseEvent) => {
|
|
141
|
+
setIsPanning(true);
|
|
142
|
+
panStart.current = { x: e.clientX, y: e.clientY, vx: viewBox.x, vy: viewBox.y };
|
|
143
|
+
}, [viewBox]);
|
|
144
|
+
|
|
145
|
+
const handleMouseMove = useCallback((e: React.MouseEvent) => {
|
|
146
|
+
if (!isPanning) return;
|
|
147
|
+
const svg = svgRef.current;
|
|
148
|
+
if (!svg) return;
|
|
149
|
+
const rect = svg.getBoundingClientRect();
|
|
150
|
+
const dx = ((e.clientX - panStart.current.x) / rect.width) * viewBox.w;
|
|
151
|
+
const dy = ((e.clientY - panStart.current.y) / rect.height) * viewBox.h;
|
|
152
|
+
setViewBox((vb) => ({ ...vb, x: panStart.current.vx - dx, y: panStart.current.vy - dy }));
|
|
153
|
+
}, [isPanning, viewBox.w, viewBox.h]);
|
|
154
|
+
|
|
155
|
+
const handleMouseUp = useCallback(() => {
|
|
156
|
+
setIsPanning(false);
|
|
157
|
+
}, []);
|
|
158
|
+
|
|
159
|
+
if (!tree || !layout) {
|
|
160
|
+
return (
|
|
161
|
+
<div className="tree-visualizer tree-visualizer--empty">
|
|
162
|
+
<p>Write or select a YAML workflow to visualize the tree</p>
|
|
163
|
+
</div>
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return (
|
|
168
|
+
<div className="tree-visualizer" ref={containerRef}>
|
|
169
|
+
<svg
|
|
170
|
+
ref={svgRef}
|
|
171
|
+
className="tree-visualizer__svg"
|
|
172
|
+
viewBox={`${viewBox.x} ${viewBox.y} ${viewBox.w} ${viewBox.h}`}
|
|
173
|
+
onWheel={handleWheel}
|
|
174
|
+
onMouseDown={handleMouseDown}
|
|
175
|
+
onMouseMove={handleMouseMove}
|
|
176
|
+
onMouseUp={handleMouseUp}
|
|
177
|
+
onMouseLeave={handleMouseUp}
|
|
178
|
+
>
|
|
179
|
+
{layout.edges.map((edge, i) => (
|
|
180
|
+
<EdgeLine key={i} edge={edge} />
|
|
181
|
+
))}
|
|
182
|
+
<RenderTree node={layout.root} />
|
|
183
|
+
</svg>
|
|
184
|
+
<div className="tree-visualizer__legend">
|
|
185
|
+
<span><span className="legend-dot" style={{ background: '#818cf8' }}/>Composite</span>
|
|
186
|
+
<span><span className="legend-dot" style={{ background: '#fbbf24' }}/>Decorator</span>
|
|
187
|
+
<span><span className="legend-dot" style={{ background: '#34d399' }}/>Action</span>
|
|
188
|
+
<span><span className="legend-dot" style={{ background: '#60a5fa' }}/>Condition</span>
|
|
189
|
+
</div>
|
|
190
|
+
</div>
|
|
191
|
+
);
|
|
192
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
.yaml-editor {
|
|
2
|
+
width: 100%;
|
|
3
|
+
height: 100%;
|
|
4
|
+
overflow: hidden;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.yaml-editor .cm-editor {
|
|
8
|
+
height: 100%;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.yaml-editor .cm-editor.cm-focused {
|
|
12
|
+
outline: none;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.yaml-editor .cm-gutters {
|
|
16
|
+
border-right: 1px solid var(--color-border);
|
|
17
|
+
background: var(--color-surface-1);
|
|
18
|
+
}
|