@motiadev/workbench 0.8.2-beta.140-628177 → 0.8.2-beta.140-027880
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/dist/components.json +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.js +5 -5
- package/dist/middleware.d.ts +1 -1
- package/dist/middleware.js +3 -3
- package/dist/motia-plugin/__tests__/generator.test.js +97 -0
- package/dist/motia-plugin/__tests__/resolver.test.d.ts +1 -0
- package/dist/motia-plugin/__tests__/resolver.test.js +64 -0
- package/dist/motia-plugin/__tests__/validator.test.d.ts +1 -0
- package/dist/motia-plugin/__tests__/validator.test.js +59 -0
- package/dist/motia-plugin/generator.d.ts +78 -0
- package/dist/motia-plugin/generator.js +128 -0
- package/dist/motia-plugin/hmr.d.ts +22 -0
- package/dist/motia-plugin/hmr.js +116 -0
- package/dist/motia-plugin/index.d.ts +3 -0
- package/dist/motia-plugin/index.js +152 -0
- package/dist/motia-plugin/resolver.d.ts +63 -0
- package/dist/motia-plugin/resolver.js +92 -0
- package/dist/motia-plugin/types.d.ts +169 -0
- package/dist/motia-plugin/types.js +36 -0
- package/dist/motia-plugin/utils.d.ts +57 -0
- package/dist/motia-plugin/utils.js +75 -0
- package/dist/motia-plugin/validator.d.ts +19 -0
- package/dist/motia-plugin/validator.js +163 -0
- package/dist/postcss.config.mjs +1 -1
- package/dist/src/App.d.ts +1 -1
- package/dist/src/App.js +1 -18
- package/dist/src/components/flow/base-edge.d.ts +2 -2
- package/dist/src/components/flow/base-edge.js +1 -1
- package/dist/src/components/flow/flow-page.js +2 -2
- package/dist/src/components/flow/flow-tab-menu-item.js +2 -2
- package/dist/src/components/flow/flow-view.d.ts +3 -3
- package/dist/src/components/flow/hooks/use-get-flow-state.d.ts +2 -2
- package/dist/src/components/flow/hooks/use-get-flow-state.js +0 -4
- package/dist/src/components/flow/hooks/use-save-workflow-config.d.ts +1 -1
- package/dist/src/components/flow/node-organizer.d.ts +3 -3
- package/dist/src/components/flow/nodes/api-flow-node.d.ts +1 -1
- package/dist/src/components/flow/nodes/cron-flow-node.d.ts +1 -1
- package/dist/src/components/flow/nodes/event-flow-node.d.ts +1 -1
- package/dist/src/components/flow/nodes/noop-flow-node.d.ts +1 -1
- package/dist/src/components/header/deploy-button.js +2 -2
- package/dist/src/components/header/header.d.ts +1 -1
- package/dist/src/components/header/header.js +2 -2
- package/dist/src/components/root-motia.d.ts +2 -1
- package/dist/src/components/tutorial/engine/tutorial-engine.d.ts +1 -1
- package/dist/src/components/tutorial/hooks/use-tutorial-engine.d.ts +1 -1
- package/dist/src/components/tutorial/hooks/use-tutorial.d.ts +1 -1
- package/dist/src/components/tutorial/tutorial-button.d.ts +1 -1
- package/dist/src/components/tutorial/tutorial-button.js +1 -1
- package/dist/src/components/tutorial/tutorial-step.d.ts +2 -2
- package/dist/src/components/tutorial/tutorial-step.js +1 -1
- package/dist/src/components/tutorial/tutorial.css +8 -8
- package/dist/src/components/ui/json-editor.d.ts +1 -1
- package/dist/src/components/ui/json-editor.js +1 -1
- package/dist/src/components/ui/table.js +1 -1
- package/dist/src/components/ui/theme-toggle.d.ts +1 -1
- package/dist/src/components/ui/tooltip.d.ts +1 -1
- package/dist/src/hooks/use-fetch-flows.js +1 -1
- package/dist/src/hooks/use-update-handle-positions.d.ts +1 -1
- package/dist/src/index.css +5 -5
- package/dist/src/lib/plugins.js +3 -3
- package/dist/src/main.js +2 -3
- package/dist/src/project-view-mode.js +1 -1
- package/dist/src/publicComponents/api-node.d.ts +2 -2
- package/dist/src/publicComponents/base-node/base-handle.d.ts +3 -2
- package/dist/src/publicComponents/base-node/base-node.d.ts +3 -2
- package/dist/src/publicComponents/base-node/base-node.js +1 -1
- package/dist/src/publicComponents/base-node/code-display.d.ts +2 -2
- package/dist/src/publicComponents/base-node/code-display.js +1 -1
- package/dist/src/publicComponents/base-node/emits.d.ts +2 -2
- package/dist/src/publicComponents/base-node/feature-card.d.ts +2 -2
- package/dist/src/publicComponents/base-node/language-indicator.d.ts +2 -2
- package/dist/src/publicComponents/base-node/node-header.d.ts +3 -2
- package/dist/src/publicComponents/base-node/node-sidebar.d.ts +2 -2
- package/dist/src/publicComponents/base-node/subscribe.d.ts +1 -1
- package/dist/src/publicComponents/cron-node.d.ts +3 -2
- package/dist/src/publicComponents/event-node.d.ts +3 -2
- package/dist/src/publicComponents/node-props.d.ts +1 -1
- package/dist/src/publicComponents/noop-node.d.ts +3 -2
- package/dist/src/stores/use-global-store.d.ts +0 -6
- package/dist/src/stores/use-global-store.js +0 -6
- package/dist/src/types/flow.d.ts +1 -1
- package/dist/tsconfig.app.tsbuildinfo +1 -1
- package/dist/tsconfig.node.tsbuildinfo +1 -1
- package/motia-plugin/__tests__/generator.test.ts +129 -0
- package/motia-plugin/__tests__/resolver.test.ts +82 -0
- package/motia-plugin/__tests__/validator.test.ts +71 -0
- package/motia-plugin/generator.ts +130 -0
- package/motia-plugin/hmr.ts +140 -0
- package/motia-plugin/index.ts +182 -0
- package/motia-plugin/resolver.ts +96 -0
- package/motia-plugin/types.ts +198 -0
- package/motia-plugin/utils.ts +70 -0
- package/motia-plugin/validator.ts +197 -0
- package/package.json +9 -9
- package/postcss.config.mjs +1 -1
- package/dist/src/components/observability/events/code/function-call.d.ts +0 -13
- package/dist/src/components/observability/events/code/function-call.js +0 -16
- package/dist/src/components/observability/events/event-icon.d.ts +0 -7
- package/dist/src/components/observability/events/event-icon.js +0 -16
- package/dist/src/components/observability/events/trace-emit-event.d.ts +0 -5
- package/dist/src/components/observability/events/trace-emit-event.js +0 -5
- package/dist/src/components/observability/events/trace-event.d.ts +0 -5
- package/dist/src/components/observability/events/trace-event.js +0 -20
- package/dist/src/components/observability/events/trace-log-event.d.ts +0 -5
- package/dist/src/components/observability/events/trace-log-event.js +0 -5
- package/dist/src/components/observability/events/trace-state-event.d.ts +0 -5
- package/dist/src/components/observability/events/trace-state-event.js +0 -5
- package/dist/src/components/observability/events/trace-stream-event.d.ts +0 -5
- package/dist/src/components/observability/events/trace-stream-event.js +0 -5
- package/dist/src/components/observability/hooks/use-get-endtime.d.ts +0 -2
- package/dist/src/components/observability/hooks/use-get-endtime.js +0 -15
- package/dist/src/components/observability/trace-item/trace-item-detail.d.ts +0 -8
- package/dist/src/components/observability/trace-item/trace-item-detail.js +0 -10
- package/dist/src/components/observability/trace-item/trace-item.d.ts +0 -10
- package/dist/src/components/observability/trace-item/trace-item.js +0 -14
- package/dist/src/components/observability/trace-status.d.ts +0 -8
- package/dist/src/components/observability/trace-status.js +0 -18
- package/dist/src/components/observability/trace-tab-label.d.ts +0 -1
- package/dist/src/components/observability/trace-tab-label.js +0 -5
- package/dist/src/components/observability/trace-timeline.d.ts +0 -6
- package/dist/src/components/observability/trace-timeline.js +0 -30
- package/dist/src/components/observability/traces-groups.d.ts +0 -9
- package/dist/src/components/observability/traces-groups.js +0 -9
- package/dist/src/components/observability/traces-page.d.ts +0 -1
- package/dist/src/components/observability/traces-page.js +0 -33
- package/dist/src/components/states/hooks/states-hooks.d.ts +0 -13
- package/dist/src/components/states/hooks/states-hooks.js +0 -26
- package/dist/src/components/states/state-details.d.ts +0 -7
- package/dist/src/components/states/state-details.js +0 -3
- package/dist/src/components/states/state-editor.d.ts +0 -7
- package/dist/src/components/states/state-editor.js +0 -71
- package/dist/src/components/states/state-sidebar.d.ts +0 -8
- package/dist/src/components/states/state-sidebar.js +0 -17
- package/dist/src/components/states/state-tab-label.d.ts +0 -1
- package/dist/src/components/states/state-tab-label.js +0 -5
- package/dist/src/components/states/states-page.d.ts +0 -1
- package/dist/src/components/states/states-page.js +0 -56
- package/dist/src/types/observability.d.ts +0 -78
- package/dist/vite-plugin-motia-plugins.d.ts +0 -9
- package/dist/vite-plugin-motia-plugins.js +0 -69
- /package/dist/{src/types/observability.js → motia-plugin/__tests__/generator.test.d.ts} +0 -0
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for a single workbench plugin.
|
|
3
|
+
* This interface defines how plugins are registered and configured in the Motia workbench.
|
|
4
|
+
*/
|
|
5
|
+
export interface WorkbenchPlugin {
|
|
6
|
+
/**
|
|
7
|
+
* The package name or local path to the plugin.
|
|
8
|
+
* - For npm packages: use the package name (e.g., '@my-org/my-plugin')
|
|
9
|
+
* - For local plugins: use the tilde prefix (e.g., '~/plugins/my-plugin')
|
|
10
|
+
*/
|
|
11
|
+
packageName: string
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Optional named export to use from the plugin package.
|
|
15
|
+
* If not specified, the default export will be used.
|
|
16
|
+
* Can be overridden by the plugin's own config.
|
|
17
|
+
*/
|
|
18
|
+
componentName?: string
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Position where the plugin tab should appear in the workbench.
|
|
22
|
+
* - 'top': Display in the top tab bar
|
|
23
|
+
* - 'bottom': Display in the bottom tab bar
|
|
24
|
+
* @default 'top'
|
|
25
|
+
*/
|
|
26
|
+
position?: 'top' | 'bottom'
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Display label for the plugin tab.
|
|
30
|
+
* Can be overridden by the plugin's own config.
|
|
31
|
+
*/
|
|
32
|
+
label?: string
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Icon name from lucide-react to display next to the label.
|
|
36
|
+
* Can be overridden by the plugin's own config.
|
|
37
|
+
* @default 'toy-brick'
|
|
38
|
+
*/
|
|
39
|
+
labelIcon?: string
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Array of CSS package imports to inject into the workbench.
|
|
43
|
+
* These will be added to the main index.css file.
|
|
44
|
+
* Example: ['@my-org/my-plugin/styles.css']
|
|
45
|
+
*/
|
|
46
|
+
cssImports?: string[]
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Props to pass to the plugin component when it's rendered.
|
|
50
|
+
* Can be overridden by the plugin's own config.
|
|
51
|
+
*/
|
|
52
|
+
props?: Record<string, any>
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Result of validating a plugin configuration.
|
|
57
|
+
*/
|
|
58
|
+
export interface ValidationResult {
|
|
59
|
+
/**
|
|
60
|
+
* Whether the validation passed
|
|
61
|
+
*/
|
|
62
|
+
valid: boolean
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Array of error messages if validation failed
|
|
66
|
+
*/
|
|
67
|
+
errors: string[]
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Array of warning messages for non-critical issues
|
|
71
|
+
*/
|
|
72
|
+
warnings: string[]
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The validated and normalized plugin configuration (if valid)
|
|
76
|
+
*/
|
|
77
|
+
plugin?: WorkbenchPlugin
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Context object passed to various plugin internals functions.
|
|
82
|
+
* Contains shared state and configuration.
|
|
83
|
+
*/
|
|
84
|
+
export interface PluginContext {
|
|
85
|
+
/**
|
|
86
|
+
* Array of plugin configurations
|
|
87
|
+
*/
|
|
88
|
+
plugins: WorkbenchPlugin[]
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Vite dev server instance (only available in dev mode)
|
|
92
|
+
*/
|
|
93
|
+
server?: any
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Package resolution result.
|
|
98
|
+
*/
|
|
99
|
+
export interface ResolvedPackage {
|
|
100
|
+
/**
|
|
101
|
+
* The original package name from the configuration
|
|
102
|
+
*/
|
|
103
|
+
packageName: string
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Resolved absolute path to the package
|
|
107
|
+
*/
|
|
108
|
+
resolvedPath: string
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Whether this is a local plugin (starts with ~/)
|
|
112
|
+
*/
|
|
113
|
+
isLocal: boolean
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Alias to use for imports
|
|
117
|
+
*/
|
|
118
|
+
alias: string
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Generated virtual module exports interface.
|
|
123
|
+
* This is what consumers will import from 'virtual:motia-plugins'.
|
|
124
|
+
*/
|
|
125
|
+
export interface VirtualModuleExports {
|
|
126
|
+
/**
|
|
127
|
+
* Array of processed plugin configurations ready to be registered
|
|
128
|
+
*/
|
|
129
|
+
plugins: ProcessedPlugin[]
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* A plugin configuration after processing and normalization.
|
|
134
|
+
* This is the format used by the workbench to register tabs.
|
|
135
|
+
*/
|
|
136
|
+
export interface ProcessedPlugin {
|
|
137
|
+
/**
|
|
138
|
+
* Display label for the plugin tab
|
|
139
|
+
*/
|
|
140
|
+
label: string
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Icon name from lucide-react
|
|
144
|
+
*/
|
|
145
|
+
labelIcon: string
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Position in the workbench ('top' or 'bottom')
|
|
149
|
+
*/
|
|
150
|
+
position: 'top' | 'bottom'
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Props to pass to the component
|
|
154
|
+
*/
|
|
155
|
+
props: Record<string, any>
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* The React component to render
|
|
159
|
+
*/
|
|
160
|
+
component: any
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Type guard to check if position is valid.
|
|
165
|
+
*/
|
|
166
|
+
export function isValidPosition(position: any): position is 'top' | 'bottom' {
|
|
167
|
+
return position === 'top' || position === 'bottom'
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Constants used throughout the plugin system.
|
|
172
|
+
*/
|
|
173
|
+
export const CONSTANTS = {
|
|
174
|
+
/**
|
|
175
|
+
* Virtual module ID for importing plugins
|
|
176
|
+
*/
|
|
177
|
+
VIRTUAL_MODULE_ID: 'virtual:motia-plugins',
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Resolved virtual module ID (with null byte prefix for Vite)
|
|
181
|
+
*/
|
|
182
|
+
RESOLVED_VIRTUAL_MODULE_ID: '\0virtual:motia-plugins',
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Log prefix for all plugin messages
|
|
186
|
+
*/
|
|
187
|
+
LOG_PREFIX: '[motia-plugins]',
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Default values for optional plugin fields
|
|
191
|
+
*/
|
|
192
|
+
DEFAULTS: {
|
|
193
|
+
POSITION: 'top' as const,
|
|
194
|
+
LABEL: 'Plugin label',
|
|
195
|
+
ICON: 'toy-brick',
|
|
196
|
+
PROPS: {},
|
|
197
|
+
},
|
|
198
|
+
} as const
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import path from 'path'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Normalizes a file path by replacing backslashes with forward slashes.
|
|
5
|
+
* This is useful for consistent path comparisons across different operating systems.
|
|
6
|
+
*
|
|
7
|
+
* @param filePath - The file path to normalize
|
|
8
|
+
* @returns The normalized file path with forward slashes
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* normalizePath('C:\\Users\\file.ts') // Returns: 'C:/Users/file.ts'
|
|
13
|
+
* normalizePath('/Users/file.ts') // Returns: '/Users/file.ts'
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export function normalizePath(filePath: string): string {
|
|
17
|
+
return filePath.replace(/\\/g, '/')
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Checks if a package name represents a local plugin (starts with ~/).
|
|
22
|
+
*
|
|
23
|
+
* @param packageName - The package name to check
|
|
24
|
+
* @returns True if the package is a local plugin
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* isLocalPlugin('~/plugins/my-plugin') // Returns: true
|
|
29
|
+
* isLocalPlugin('@my-org/my-plugin') // Returns: false
|
|
30
|
+
* isLocalPlugin('my-plugin') // Returns: false
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export function isLocalPlugin(packageName: string): boolean {
|
|
34
|
+
return packageName.startsWith('~/')
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Resolves a local plugin path to an absolute path.
|
|
39
|
+
* Strips the ~/ prefix and joins with the current working directory.
|
|
40
|
+
*
|
|
41
|
+
* @param packageName - The local plugin package name (must start with ~/)
|
|
42
|
+
* @returns The absolute path to the local plugin
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* // If cwd is /Users/project
|
|
47
|
+
* resolveLocalPath('~/plugins/my-plugin')
|
|
48
|
+
* // Returns: '/Users/project/plugins/my-plugin'
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export function resolveLocalPath(packageName: string): string {
|
|
52
|
+
return path.join(process.cwd(), packageName.replace('~/', ''))
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Resolves an npm package path to the node_modules directory.
|
|
57
|
+
*
|
|
58
|
+
* @param packageName - The npm package name
|
|
59
|
+
* @returns The absolute path to the package in node_modules
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* // If cwd is /Users/project
|
|
64
|
+
* resolveNpmPath('@my-org/my-plugin')
|
|
65
|
+
* // Returns: '/Users/project/node_modules/@my-org/my-plugin'
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export function resolveNpmPath(packageName: string): string {
|
|
69
|
+
return path.join(process.cwd(), 'node_modules', packageName)
|
|
70
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { existsSync } from 'fs'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
import type { ValidationResult, WorkbenchPlugin } from './types'
|
|
4
|
+
import { CONSTANTS, isValidPosition } from './types'
|
|
5
|
+
import { isLocalPlugin, resolveLocalPath } from './utils'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Zod schema for WorkbenchPlugin configuration.
|
|
9
|
+
* Provides runtime type validation with detailed error messages.
|
|
10
|
+
*/
|
|
11
|
+
const WorkbenchPluginSchema = z.object({
|
|
12
|
+
packageName: z
|
|
13
|
+
.string()
|
|
14
|
+
.min(1, 'packageName is required and cannot be empty')
|
|
15
|
+
.refine((name) => name.startsWith('~/') || name.startsWith('@') || /^[a-z0-9-_]+$/i.test(name), {
|
|
16
|
+
message: 'packageName must be a valid npm package name or local path (starting with ~/)',
|
|
17
|
+
}),
|
|
18
|
+
|
|
19
|
+
componentName: z.string().optional(),
|
|
20
|
+
|
|
21
|
+
position: z
|
|
22
|
+
.enum(['top', 'bottom'])
|
|
23
|
+
.optional()
|
|
24
|
+
.refine((pos) => pos === undefined || isValidPosition(pos), {
|
|
25
|
+
message: 'position must be either "top" or "bottom"',
|
|
26
|
+
}),
|
|
27
|
+
|
|
28
|
+
label: z.string().optional(),
|
|
29
|
+
|
|
30
|
+
labelIcon: z.string().optional(),
|
|
31
|
+
|
|
32
|
+
cssImports: z.array(z.string()).optional(),
|
|
33
|
+
|
|
34
|
+
props: z.record(z.any()).optional(),
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Validates a single plugin configuration.
|
|
39
|
+
*
|
|
40
|
+
* @param plugin - The plugin configuration to validate
|
|
41
|
+
* @param index - The index of the plugin in the array (for error messages)
|
|
42
|
+
* @returns A validation result with errors, warnings, and normalized plugin
|
|
43
|
+
*/
|
|
44
|
+
export function validatePluginConfig(plugin: any, index: number): ValidationResult {
|
|
45
|
+
const errors: string[] = []
|
|
46
|
+
const warnings: string[] = []
|
|
47
|
+
|
|
48
|
+
if (typeof plugin !== 'object' || plugin === null) {
|
|
49
|
+
return {
|
|
50
|
+
valid: false,
|
|
51
|
+
errors: [`Plugin at index ${index}: expected object, got ${typeof plugin}`],
|
|
52
|
+
warnings: [],
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
const result = WorkbenchPluginSchema.safeParse(plugin)
|
|
58
|
+
|
|
59
|
+
if (!result.success) {
|
|
60
|
+
result.error.errors.forEach((err) => {
|
|
61
|
+
const path = err.path.join('.')
|
|
62
|
+
errors.push(`Plugin at index ${index}, field "${path}": ${err.message}`)
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
return { valid: false, errors, warnings }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const validatedPlugin = result.data as WorkbenchPlugin
|
|
69
|
+
|
|
70
|
+
if (isLocalPlugin(validatedPlugin.packageName)) {
|
|
71
|
+
const resolvedPath = resolveLocalPath(validatedPlugin.packageName)
|
|
72
|
+
if (!existsSync(resolvedPath)) {
|
|
73
|
+
warnings.push(
|
|
74
|
+
`Plugin at index ${index}: local path "${validatedPlugin.packageName}" does not exist at "${resolvedPath}". ` +
|
|
75
|
+
`Make sure the path is correct relative to the project root.`,
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (!validatedPlugin.label) {
|
|
81
|
+
warnings.push(`Plugin at index ${index}: "label" not specified, will use default "${CONSTANTS.DEFAULTS.LABEL}"`)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (!validatedPlugin.labelIcon) {
|
|
85
|
+
warnings.push(
|
|
86
|
+
`Plugin at index ${index}: "labelIcon" not specified, will use default "${CONSTANTS.DEFAULTS.ICON}"`,
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (!validatedPlugin.position) {
|
|
91
|
+
warnings.push(
|
|
92
|
+
`Plugin at index ${index}: "position" not specified, will use default "${CONSTANTS.DEFAULTS.POSITION}"`,
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (validatedPlugin.props && Object.keys(validatedPlugin.props).length === 0) {
|
|
97
|
+
warnings.push(`Plugin at index ${index}: "props" is an empty object`)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (validatedPlugin.cssImports) {
|
|
101
|
+
if (validatedPlugin.cssImports.length === 0) {
|
|
102
|
+
warnings.push(`Plugin at index ${index}: "cssImports" is an empty array`)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
validatedPlugin.cssImports.forEach((cssImport, cssIndex) => {
|
|
106
|
+
if (!cssImport || cssImport.trim() === '') {
|
|
107
|
+
warnings.push(`Plugin at index ${index}: cssImport at index ${cssIndex} is empty or whitespace`)
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
valid: true,
|
|
114
|
+
errors: [],
|
|
115
|
+
warnings,
|
|
116
|
+
plugin: validatedPlugin,
|
|
117
|
+
}
|
|
118
|
+
} catch (error) {
|
|
119
|
+
return {
|
|
120
|
+
valid: false,
|
|
121
|
+
errors: [`Plugin at index ${index}: unexpected validation error: ${error}`],
|
|
122
|
+
warnings: [],
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Validates an array of plugin configurations.
|
|
129
|
+
*
|
|
130
|
+
* @param plugins - Array of plugin configurations to validate
|
|
131
|
+
* @param options - Validation options
|
|
132
|
+
* @returns Combined validation result for all plugins
|
|
133
|
+
*/
|
|
134
|
+
export function validatePlugins(plugins: any[], options: { failFast?: boolean } = {}): ValidationResult {
|
|
135
|
+
const allErrors: string[] = []
|
|
136
|
+
const allWarnings: string[] = []
|
|
137
|
+
const validatedPlugins: WorkbenchPlugin[] = []
|
|
138
|
+
|
|
139
|
+
if (!Array.isArray(plugins)) {
|
|
140
|
+
return {
|
|
141
|
+
valid: false,
|
|
142
|
+
errors: [`Expected plugins to be an array, got ${typeof plugins}`],
|
|
143
|
+
warnings: [],
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (plugins.length === 0) {
|
|
148
|
+
console.warn('[motia-plugins] No plugins provided to validate')
|
|
149
|
+
return {
|
|
150
|
+
valid: true,
|
|
151
|
+
errors: [],
|
|
152
|
+
warnings: ['No plugins configured'],
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
for (let i = 0; i < plugins.length; i++) {
|
|
157
|
+
const result = validatePluginConfig(plugins[i], i)
|
|
158
|
+
|
|
159
|
+
allErrors.push(...result.errors)
|
|
160
|
+
allWarnings.push(...result.warnings)
|
|
161
|
+
|
|
162
|
+
if (result.valid && result.plugin) {
|
|
163
|
+
validatedPlugins.push(result.plugin)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (options.failFast && result.errors.length > 0) {
|
|
167
|
+
break
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const packageNames = validatedPlugins.map((p) => p.packageName)
|
|
172
|
+
const duplicates = packageNames.filter((name, index) => packageNames.indexOf(name) !== index)
|
|
173
|
+
|
|
174
|
+
if (duplicates.length > 0) {
|
|
175
|
+
const uniqueDuplicates = [...new Set(duplicates)]
|
|
176
|
+
uniqueDuplicates.forEach((dup) => {
|
|
177
|
+
allWarnings.push(`Duplicate package name found: "${dup}". This may cause conflicts.`)
|
|
178
|
+
})
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const valid = allErrors.length === 0
|
|
182
|
+
|
|
183
|
+
if (valid) {
|
|
184
|
+
console.log(`[motia-plugins] ✓ Validated ${validatedPlugins.length} plugin(s) successfully`)
|
|
185
|
+
if (allWarnings.length > 0) {
|
|
186
|
+
console.warn(`[motia-plugins] Found ${allWarnings.length} warning(s)`)
|
|
187
|
+
}
|
|
188
|
+
} else {
|
|
189
|
+
console.error(`[motia-plugins] ✗ Validation failed with ${allErrors.length} error(s)`)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return {
|
|
193
|
+
valid,
|
|
194
|
+
errors: allErrors,
|
|
195
|
+
warnings: allWarnings,
|
|
196
|
+
}
|
|
197
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@motiadev/workbench",
|
|
3
3
|
"description": "A web-based interface for building and managing Motia workflows.",
|
|
4
|
-
"version": "0.8.2-beta.140-
|
|
4
|
+
"version": "0.8.2-beta.140-027880",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@monaco-editor/react": "^4.6.1",
|
|
@@ -41,12 +41,11 @@
|
|
|
41
41
|
"typescript": "~5.8.3",
|
|
42
42
|
"typescript-eslint": "^8.32.1",
|
|
43
43
|
"vite": "^6.3.5",
|
|
44
|
+
"zod": "^3.24.1",
|
|
44
45
|
"zustand": "^5.0.6",
|
|
45
|
-
"@motiadev/
|
|
46
|
-
"@motiadev/
|
|
47
|
-
"@motiadev/
|
|
48
|
-
"@motiadev/stream-client-react": "0.8.2-beta.140-628177",
|
|
49
|
-
"@motiadev/ui": "0.8.2-beta.140-628177"
|
|
46
|
+
"@motiadev/core": "0.8.2-beta.140-027880",
|
|
47
|
+
"@motiadev/stream-client-react": "0.8.2-beta.140-027880",
|
|
48
|
+
"@motiadev/ui": "0.8.2-beta.140-027880"
|
|
50
49
|
},
|
|
51
50
|
"devDependencies": {
|
|
52
51
|
"@testing-library/jest-dom": "^6.6.3",
|
|
@@ -66,9 +65,10 @@
|
|
|
66
65
|
"ts-jest": "^29.3.4"
|
|
67
66
|
},
|
|
68
67
|
"scripts": {
|
|
69
|
-
"lint": "
|
|
70
|
-
"lint:
|
|
71
|
-
"lint:
|
|
68
|
+
"lint": "biome check .",
|
|
69
|
+
"lint:plugins": "pnpm run lint:plugins:ts && pnpm run lint:plugins:tsx",
|
|
70
|
+
"lint:plugins:ts": "eslint",
|
|
71
|
+
"lint:plugins:tsx": "eslint --config ../../eslint.config.tsx.js",
|
|
72
72
|
"build": "rm -rf dist && tsc --build && sh post-build.sh",
|
|
73
73
|
"test": "jest",
|
|
74
74
|
"test:watch": "jest --watch"
|
package/postcss.config.mjs
CHANGED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
type Props = {
|
|
3
|
-
topLevelClassName?: string;
|
|
4
|
-
objectName?: string;
|
|
5
|
-
functionName: string;
|
|
6
|
-
args: Array<string | object | false | undefined>;
|
|
7
|
-
callsQuantity?: number;
|
|
8
|
-
};
|
|
9
|
-
export declare const Argument: React.FC<{
|
|
10
|
-
arg: string | object | false;
|
|
11
|
-
}>;
|
|
12
|
-
export declare const FunctionCall: React.FC<Props>;
|
|
13
|
-
export {};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
export const Argument = ({ arg }) => {
|
|
3
|
-
if (typeof arg === 'string') {
|
|
4
|
-
return _jsxs("span", { className: "font-mono text-blue-500", children: ["'", arg, "'"] });
|
|
5
|
-
}
|
|
6
|
-
else if (arg === false) {
|
|
7
|
-
return _jsx("span", { className: "font-mono text-blue-100 font-bold bg-blue-500/50 px-2 rounded-md", children: "value" });
|
|
8
|
-
}
|
|
9
|
-
const entries = Object.entries(arg);
|
|
10
|
-
return (_jsxs(_Fragment, { children: [_jsx("span", { className: "font-mono text-green-500", children: '{ ' }), entries.map(([key, value], index) => (_jsxs("span", { children: [_jsx("span", { className: "font-mono text-green-500", children: key }), _jsx("span", { className: "font-mono text-muted-foreground", children: ":" }), " ", _jsx(Argument, { arg: value }), index < entries.length - 1 && _jsx(_Fragment, { children: ", " })] }, key))), _jsx("span", { className: "font-mono text-green-500", children: ' }' })] }));
|
|
11
|
-
};
|
|
12
|
-
export const FunctionCall = ({ topLevelClassName, objectName, functionName, args, callsQuantity }) => {
|
|
13
|
-
const hasCalls = callsQuantity && callsQuantity > 1;
|
|
14
|
-
const filteredArgs = args.filter((arg) => arg !== undefined);
|
|
15
|
-
return (_jsxs("div", { children: [topLevelClassName && (_jsxs(_Fragment, { children: [_jsx("span", { className: "font-mono text-pink-500", children: topLevelClassName }), "."] })), objectName && (_jsxs(_Fragment, { children: [_jsx("span", { className: "font-mono text-pink-500", children: objectName }), "."] })), _jsx("span", { className: "font-mono text-pink-500", children: functionName }), _jsx("span", { className: "font-mono text-emerald-500", children: "(" }), filteredArgs.map((arg, index) => (_jsxs("span", { children: [_jsx(Argument, { arg: arg }), index < filteredArgs.length - 1 && _jsx(_Fragment, { children: ", " })] }, index))), _jsx("span", { className: "font-mono text-emerald-500", children: ")" }), hasCalls && _jsxs("span", { className: "font-mono text-muted-foreground", children: [" x", callsQuantity] })] }));
|
|
16
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { MessageCircle, Package, Radio, ScrollText } from 'lucide-react';
|
|
3
|
-
export const EventIcon = ({ event }) => {
|
|
4
|
-
if (event.type === 'log') {
|
|
5
|
-
return _jsx(ScrollText, { className: "w-4 h-4 text-muted-foreground" });
|
|
6
|
-
}
|
|
7
|
-
else if (event.type === 'emit') {
|
|
8
|
-
return _jsx(MessageCircle, { className: "w-4 h-4 text-muted-foreground" });
|
|
9
|
-
}
|
|
10
|
-
else if (event.type === 'state') {
|
|
11
|
-
return _jsx(Package, { className: "w-4 h-4 text-muted-foreground" });
|
|
12
|
-
}
|
|
13
|
-
else if (event.type === 'stream') {
|
|
14
|
-
return _jsx(Radio, { className: "w-4 h-4 text-muted-foreground" });
|
|
15
|
-
}
|
|
16
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { memo } from 'react';
|
|
3
|
-
import { TraceEmitEvent } from './trace-emit-event';
|
|
4
|
-
import { TraceLogEvent } from './trace-log-event';
|
|
5
|
-
import { TraceStateEvent } from './trace-state-event';
|
|
6
|
-
import { TraceStreamEvent } from './trace-stream-event';
|
|
7
|
-
export const TraceEvent = memo(({ event }) => {
|
|
8
|
-
if (event.type === 'log') {
|
|
9
|
-
return _jsx(TraceLogEvent, { event: event });
|
|
10
|
-
}
|
|
11
|
-
else if (event.type === 'emit') {
|
|
12
|
-
return _jsx(TraceEmitEvent, { event: event });
|
|
13
|
-
}
|
|
14
|
-
else if (event.type === 'state') {
|
|
15
|
-
return _jsx(TraceStateEvent, { event: event });
|
|
16
|
-
}
|
|
17
|
-
else if (event.type === 'stream') {
|
|
18
|
-
return _jsx(TraceStreamEvent, { event: event });
|
|
19
|
-
}
|
|
20
|
-
});
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { LevelDot } from '@motiadev/ui';
|
|
3
|
-
export const TraceLogEvent = ({ event }) => {
|
|
4
|
-
return (_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(LevelDot, { level: event.level }), " ", event.message] }));
|
|
5
|
-
};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { FunctionCall } from './code/function-call';
|
|
3
|
-
export const TraceStateEvent = ({ event }) => {
|
|
4
|
-
return (_jsx(FunctionCall, { objectName: "state", functionName: event.operation, args: [event.data.traceId, event.data.key, event.data.value ? false : undefined] }));
|
|
5
|
-
};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { FunctionCall } from './code/function-call';
|
|
3
|
-
export const TraceStreamEvent = ({ event }) => {
|
|
4
|
-
return (_jsx(FunctionCall, { topLevelClassName: "streams", objectName: event.streamName, functionName: event.operation, args: [event.data.groupId, event.data.id, event.data.data ? false : undefined], callsQuantity: event.calls }));
|
|
5
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
2
|
-
export const useGetEndTime = (group) => {
|
|
3
|
-
const groupEndTime = group?.endTime;
|
|
4
|
-
const [endTime, setEndTime] = useState(groupEndTime || Date.now());
|
|
5
|
-
useEffect(() => {
|
|
6
|
-
if (groupEndTime) {
|
|
7
|
-
setEndTime(groupEndTime);
|
|
8
|
-
}
|
|
9
|
-
else {
|
|
10
|
-
const interval = setInterval(() => setEndTime(Date.now()), 50);
|
|
11
|
-
return () => clearInterval(interval);
|
|
12
|
-
}
|
|
13
|
-
}, [groupEndTime]);
|
|
14
|
-
return endTime;
|
|
15
|
-
};
|