@flowdrop/flowdrop 1.15.0 → 2.0.0-beta.10
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/CHANGELOG.md +648 -0
- package/MIGRATION-2.0.md +642 -0
- package/README.md +28 -28
- package/dist/adapters/WorkflowAdapter.d.ts +1 -1
- package/dist/adapters/WorkflowAdapter.js +18 -13
- package/dist/adapters/agentspec/AgentSpecAdapter.js +10 -10
- package/dist/adapters/agentspec/defaultNodeTypes.js +9 -9
- package/dist/api/enhanced-client.js +6 -11
- package/dist/chat/batchFeedback.d.ts +39 -0
- package/dist/chat/batchFeedback.js +51 -0
- package/dist/commands/executor.js +66 -27
- package/dist/commands/storeIntegration.svelte.d.ts +4 -1
- package/dist/commands/storeIntegration.svelte.js +36 -21
- package/dist/commands/types.d.ts +2 -0
- package/dist/commands/types.js +5 -5
- package/dist/components/App.svelte +696 -565
- package/dist/components/App.svelte.d.ts +63 -16
- package/dist/components/Button.stories.svelte +65 -0
- package/dist/components/Button.stories.svelte.d.ts +19 -0
- package/dist/components/Button.svelte +62 -0
- package/dist/components/Button.svelte.d.ts +24 -0
- package/dist/components/CanvasIconButton.svelte +76 -0
- package/dist/components/CanvasIconButton.svelte.d.ts +18 -0
- package/dist/components/ConfigForm.svelte +181 -552
- package/dist/components/ConfigForm.svelte.d.ts +24 -7
- package/dist/components/ConfigModal.svelte +16 -3
- package/dist/components/ConfigPanel.svelte +234 -15
- package/dist/components/ConfigPanel.svelte.d.ts +6 -0
- package/dist/components/ConnectionLine.svelte +4 -2
- package/dist/components/EditorStatusBar.stories.svelte +44 -0
- package/dist/components/EditorStatusBar.stories.svelte.d.ts +27 -0
- package/dist/components/EditorStatusBar.svelte +99 -0
- package/dist/components/EditorStatusBar.svelte.d.ts +15 -0
- package/dist/components/IconButton.svelte +80 -0
- package/dist/components/IconButton.svelte.d.ts +30 -0
- package/dist/components/Input.svelte +74 -0
- package/dist/components/Input.svelte.d.ts +17 -0
- package/dist/components/LogoWordmark.svelte +113 -0
- package/dist/components/LogoWordmark.svelte.d.ts +26 -0
- package/dist/components/Navbar.svelte +78 -64
- package/dist/components/Navbar.svelte.d.ts +3 -0
- package/dist/components/NodeSidebar.svelte +48 -171
- package/dist/components/NodeStatusOverlay.svelte +94 -6
- package/dist/components/NodeSwapPicker.svelte +22 -38
- package/dist/components/PipelineStatus.svelte +22 -68
- package/dist/components/PipelineStatus.svelte.d.ts +3 -0
- package/dist/components/PortCoordinateTracker.svelte +5 -6
- package/dist/components/PortMappingRow.svelte +0 -2
- package/dist/components/SchemaForm.stories.svelte +1 -3
- package/dist/components/SchemaForm.svelte +22 -39
- package/dist/components/SchemaForm.svelte.d.ts +0 -8
- package/dist/components/Select.svelte +53 -0
- package/dist/components/Select.svelte.d.ts +15 -0
- package/dist/components/SettingsModal.svelte +8 -8
- package/dist/components/SettingsPanel.svelte +44 -10
- package/dist/components/SwapMappingEditor.svelte +67 -49
- package/dist/components/SwapMappingEditor.svelte.d.ts +0 -2
- package/dist/components/Textarea.svelte +39 -0
- package/dist/components/Textarea.svelte.d.ts +12 -0
- package/dist/components/ThemeToggle.svelte +15 -94
- package/dist/components/UniversalNode.svelte +45 -11
- package/dist/components/UniversalNode.svelte.d.ts +1 -1
- package/dist/components/WorkflowEditor.svelte +183 -162
- package/dist/components/WorkflowEditor.svelte.d.ts +39 -10
- package/dist/components/chat/AIChatPanel.svelte +99 -90
- package/dist/components/chat/AIChatPanel.svelte.d.ts +0 -4
- package/dist/components/chat/CommandPreview.svelte +2 -1
- package/dist/components/console/CommandConsole.svelte +7 -5
- package/dist/components/console/ConsoleAutocomplete.svelte +11 -12
- package/dist/components/console/ConsoleAutocomplete.svelte.d.ts +6 -0
- package/dist/components/console/ConsoleInput.svelte +18 -9
- package/dist/components/console/ConsoleOutput.svelte +4 -3
- package/dist/components/form/FormArray.svelte +42 -182
- package/dist/components/form/FormArray.svelte.d.ts +2 -1
- package/dist/components/form/FormAutocomplete.svelte +26 -21
- package/dist/components/form/FormCheckboxGroup.svelte +1 -5
- package/dist/components/form/FormCodeEditor.svelte +9 -7
- package/dist/components/form/FormField.svelte +22 -44
- package/dist/components/form/FormFieldLight.svelte +56 -50
- package/dist/components/form/FormFieldLight.svelte.d.ts +12 -0
- package/dist/components/form/FormFieldset.svelte +45 -11
- package/dist/components/form/FormMarkdownEditor.svelte +17 -9
- package/dist/components/form/FormNumberField.svelte +4 -36
- package/dist/components/form/FormPorts.svelte +262 -0
- package/dist/components/form/FormPorts.svelte.d.ts +13 -0
- package/dist/components/form/FormRangeField.svelte +62 -30
- package/dist/components/form/FormSelect.svelte +13 -75
- package/dist/components/form/FormTemplateEditor.svelte +17 -7
- package/dist/components/form/FormTextField.svelte +3 -35
- package/dist/components/form/FormTextarea.svelte +4 -39
- package/dist/components/form/FormToggle.svelte +5 -16
- package/dist/components/form/FormToggle.svelte.d.ts +4 -2
- package/dist/components/form/FormUISchemaRenderer.svelte +3 -1
- package/dist/components/form/resolveFieldType.d.ts +24 -0
- package/dist/components/form/resolveFieldType.js +55 -0
- package/dist/components/form/templateAutocomplete.js +1 -5
- package/dist/components/form/types.d.ts +1 -14
- package/dist/components/icons/CloseIcon.svelte +6 -0
- package/dist/components/icons/CloseIcon.svelte.d.ts +26 -0
- package/dist/components/icons/CommandLineIcon.svelte +15 -0
- package/dist/components/icons/CommandLineIcon.svelte.d.ts +26 -0
- package/dist/components/icons/MenuIcon.svelte +4 -0
- package/dist/components/icons/MenuIcon.svelte.d.ts +26 -0
- package/dist/components/icons/MenuOpenIcon.svelte +6 -0
- package/dist/components/icons/MenuOpenIcon.svelte.d.ts +26 -0
- package/dist/components/interrupt/ChoicePrompt.svelte +0 -10
- package/dist/components/interrupt/ConfirmationPrompt.svelte +0 -5
- package/dist/components/interrupt/FormPrompt.svelte +3 -2
- package/dist/components/interrupt/InterruptBubble.svelte +25 -27
- package/dist/components/interrupt/ReviewPrompt.svelte +10 -23
- package/dist/components/interrupt/TextInputPrompt.svelte +2 -7
- package/dist/components/layouts/MainLayout.svelte +24 -18
- package/dist/components/layouts/MainLayout.svelte.d.ts +4 -0
- package/dist/components/nodes/AtomNode.svelte +70 -72
- package/dist/components/nodes/AtomNode.svelte.d.ts +1 -1
- package/dist/components/nodes/GatewayNode.svelte +134 -172
- package/dist/components/nodes/GatewayNode.svelte.d.ts +1 -1
- package/dist/components/nodes/IdeaNode.svelte +79 -98
- package/dist/components/nodes/IdeaNode.svelte.d.ts +8 -4
- package/dist/components/nodes/NodeConfigButton.svelte +86 -0
- package/dist/components/nodes/NodeConfigButton.svelte.d.ts +15 -0
- package/dist/components/nodes/NotesNode.svelte +76 -85
- package/dist/components/nodes/NotesNode.svelte.d.ts +8 -4
- package/dist/components/nodes/SimpleNode.svelte +68 -137
- package/dist/components/nodes/SimpleNode.svelte.d.ts +4 -4
- package/dist/components/nodes/SquareNode.svelte +122 -169
- package/dist/components/nodes/SquareNode.svelte.d.ts +4 -4
- package/dist/components/nodes/TerminalNode.svelte +70 -127
- package/dist/components/nodes/TerminalNode.svelte.d.ts +4 -4
- package/dist/components/nodes/ToolNode.svelte +99 -104
- package/dist/components/nodes/ToolNode.svelte.d.ts +6 -6
- package/dist/components/nodes/WorkflowNode.svelte +145 -195
- package/dist/components/nodes/WorkflowNode.svelte.d.ts +1 -1
- package/dist/components/playground/ChatInput.svelte +11 -15
- package/dist/components/playground/ChatPanel.svelte +6 -49
- package/dist/components/playground/ChatPanel.svelte.d.ts +0 -14
- package/dist/components/playground/ControlPanel.svelte +134 -123
- package/dist/components/playground/ControlPanel.svelte.d.ts +3 -0
- package/dist/components/playground/ExecutionLogs.svelte +11 -9
- package/dist/components/playground/InputCollector.svelte +22 -57
- package/dist/components/playground/MessageStream.svelte +17 -23
- package/dist/components/playground/PipelineKanbanView.svelte +69 -8
- package/dist/components/playground/PipelineKanbanView.svelte.d.ts +2 -0
- package/dist/components/playground/PipelinePanel.svelte +31 -8
- package/dist/components/playground/PipelinePanel.svelte.d.ts +2 -0
- package/dist/components/playground/PipelineTableView.svelte +188 -44
- package/dist/components/playground/PipelineTableView.svelte.d.ts +2 -0
- package/dist/components/playground/Playground.svelte +154 -105
- package/dist/components/playground/Playground.svelte.d.ts +5 -0
- package/dist/components/playground/PlaygroundApp.svelte +12 -2
- package/dist/components/playground/PlaygroundApp.svelte.d.ts +6 -0
- package/dist/components/playground/PlaygroundModal.svelte +18 -3
- package/dist/components/playground/PlaygroundModal.svelte.d.ts +6 -0
- package/dist/components/playground/PlaygroundStudio.svelte +40 -37
- package/dist/components/playground/PlaygroundStudio.svelte.d.ts +6 -0
- package/dist/components/playground/SessionManager.svelte +9 -12
- package/dist/components/playground/pipelineViewUtils.svelte.d.ts +30 -1
- package/dist/components/playground/pipelineViewUtils.svelte.js +40 -3
- package/dist/components/surfaces/SurfaceOverlay.svelte +153 -0
- package/dist/components/surfaces/SurfaceOverlay.svelte.d.ts +14 -0
- package/dist/components/surfaces/TabbedSurface.svelte +133 -0
- package/dist/components/surfaces/TabbedSurface.svelte.d.ts +27 -0
- package/dist/config/endpoints.d.ts +23 -7
- package/dist/config/endpoints.js +30 -10
- package/dist/core/index.d.ts +6 -7
- package/dist/core/index.js +8 -12
- package/dist/display/index.d.ts +6 -3
- package/dist/display/index.js +7 -5
- package/dist/editor/index.d.ts +20 -21
- package/dist/editor/index.js +26 -36
- package/dist/form/code.d.ts +25 -15
- package/dist/form/code.js +44 -41
- package/dist/form/fieldRegistry.d.ts +17 -13
- package/dist/form/fieldRegistry.js +32 -12
- package/dist/form/full.d.ts +19 -14
- package/dist/form/full.js +26 -28
- package/dist/form/index.d.ts +3 -4
- package/dist/form/index.js +6 -5
- package/dist/form/markdown.d.ts +13 -8
- package/dist/form/markdown.js +22 -23
- package/dist/helpers/proximityConnect.d.ts +3 -2
- package/dist/helpers/proximityConnect.js +2 -5
- package/dist/helpers/workflowEditorHelper.d.ts +14 -5
- package/dist/helpers/workflowEditorHelper.js +32 -30
- package/dist/index.d.ts +28 -24
- package/dist/index.js +27 -50
- package/dist/messages/defaults.d.ts +2 -5
- package/dist/messages/defaults.js +3 -6
- package/dist/messages/index.d.ts +1 -2
- package/dist/messages/index.js +1 -2
- package/dist/mocks/app-forms.d.ts +6 -2
- package/dist/mocks/app-forms.js +11 -4
- package/dist/openapi/v1/openapi.yaml +38 -26
- package/dist/playground/index.d.ts +4 -5
- package/dist/playground/index.js +4 -32
- package/dist/playground/mount.d.ts +34 -5
- package/dist/playground/mount.js +58 -24
- package/dist/registry/{BaseRegistry.d.ts → BaseRegistry.svelte.d.ts} +22 -1
- package/dist/registry/{BaseRegistry.js → BaseRegistry.svelte.js} +37 -1
- package/dist/registry/builtinFormats.d.ts +9 -18
- package/dist/registry/builtinFormats.js +9 -39
- package/dist/registry/builtinNodeTypes.d.ts +53 -0
- package/dist/registry/builtinNodeTypes.js +67 -0
- package/dist/registry/builtinNodes.d.ts +2 -64
- package/dist/registry/builtinNodes.js +7 -103
- package/dist/registry/index.d.ts +3 -4
- package/dist/registry/index.js +4 -6
- package/dist/registry/nodeComponentRegistry.d.ts +184 -16
- package/dist/registry/nodeComponentRegistry.js +235 -17
- package/dist/registry/workflowFormatRegistry.d.ts +14 -9
- package/dist/registry/workflowFormatRegistry.js +24 -8
- package/dist/{schema → schemas}/index.d.ts +2 -2
- package/dist/{schema → schemas}/index.js +2 -2
- package/dist/schemas/v1/workflow.schema.json +19 -17
- package/dist/services/agentSpecExecutionService.d.ts +0 -2
- package/dist/services/agentSpecExecutionService.js +0 -3
- package/dist/services/apiVariableService.d.ts +2 -1
- package/dist/services/apiVariableService.js +16 -47
- package/dist/services/autoSaveService.d.ts +7 -0
- package/dist/services/autoSaveService.js +6 -4
- package/dist/services/categoriesApi.js +3 -6
- package/dist/services/chatService.d.ts +9 -4
- package/dist/services/chatService.js +23 -28
- package/dist/services/draftStorage.d.ts +129 -13
- package/dist/services/draftStorage.js +185 -37
- package/dist/services/dynamicSchemaService.d.ts +33 -5
- package/dist/services/dynamicSchemaService.js +67 -55
- package/dist/services/globalSave.d.ts +13 -12
- package/dist/services/globalSave.js +29 -51
- package/dist/services/historyService.d.ts +39 -11
- package/dist/services/historyService.js +60 -18
- package/dist/services/interruptService.d.ts +15 -9
- package/dist/services/interruptService.js +35 -37
- package/dist/services/nodeExecutionService.d.ts +18 -3
- package/dist/services/nodeExecutionService.js +71 -45
- package/dist/services/playgroundService.d.ts +16 -10
- package/dist/services/playgroundService.js +42 -43
- package/dist/services/portConfigApi.js +3 -6
- package/dist/services/settingsService.d.ts +9 -4
- package/dist/services/settingsService.js +23 -12
- package/dist/services/variableService.d.ts +2 -1
- package/dist/services/variableService.js +2 -2
- package/dist/services/workflowStorage.js +6 -6
- package/dist/skins/drafter.d.ts +30 -0
- package/dist/skins/drafter.js +198 -0
- package/dist/skins/index.d.ts +2 -1
- package/dist/skins/index.js +4 -2
- package/dist/stores/apiContext.d.ts +56 -0
- package/dist/stores/apiContext.js +80 -0
- package/dist/stores/categoriesStore.svelte.d.ts +28 -23
- package/dist/stores/categoriesStore.svelte.js +69 -64
- package/dist/stores/getInstance.svelte.d.ts +39 -0
- package/dist/stores/getInstance.svelte.js +65 -0
- package/dist/stores/historyStore.svelte.d.ts +89 -91
- package/dist/stores/historyStore.svelte.js +159 -158
- package/dist/stores/instanceContainer.svelte.d.ts +111 -0
- package/dist/stores/instanceContainer.svelte.js +119 -0
- package/dist/stores/interruptStore.svelte.d.ts +112 -82
- package/dist/stores/interruptStore.svelte.js +253 -226
- package/dist/stores/pipelinePanelStore.svelte.d.ts +27 -3
- package/dist/stores/pipelinePanelStore.svelte.js +61 -14
- package/dist/stores/playgroundStore.svelte.d.ts +169 -222
- package/dist/stores/playgroundStore.svelte.js +513 -580
- package/dist/stores/portCoordinateStore.svelte.d.ts +57 -51
- package/dist/stores/portCoordinateStore.svelte.js +109 -98
- package/dist/stores/settingsStore.svelte.d.ts +17 -1
- package/dist/stores/settingsStore.svelte.js +79 -12
- package/dist/stores/workflowStore.svelte.d.ts +212 -210
- package/dist/stores/workflowStore.svelte.js +527 -502
- package/dist/stories/EdgeDecorator.svelte +5 -2
- package/dist/stories/NodeDecorator.svelte +5 -3
- package/dist/styles/base.css +285 -14
- package/dist/styles/tokens.css +60 -2
- package/dist/svelte-app.d.ts +78 -11
- package/dist/svelte-app.js +210 -141
- package/dist/themes/drafter.d.ts +2 -0
- package/dist/themes/drafter.js +15 -0
- package/dist/themes/index.d.ts +2 -1
- package/dist/themes/index.js +8 -2
- package/dist/types/auth.d.ts +9 -51
- package/dist/types/auth.js +4 -54
- package/dist/types/events.d.ts +24 -3
- package/dist/types/events.js +2 -1
- package/dist/types/index.d.ts +117 -32
- package/dist/types/index.js +0 -1
- package/dist/types/navbar.d.ts +7 -0
- package/dist/types/playground.d.ts +18 -3
- package/dist/types/settings.d.ts +30 -1
- package/dist/types/settings.js +5 -2
- package/dist/types/skin.d.ts +1 -1
- package/dist/types/theme.d.ts +16 -2
- package/dist/types/uischema.d.ts +5 -0
- package/dist/utils/colors.d.ts +74 -21
- package/dist/utils/colors.js +92 -68
- package/dist/utils/connections.d.ts +9 -15
- package/dist/utils/connections.js +33 -88
- package/dist/utils/duration.d.ts +13 -0
- package/dist/utils/duration.js +45 -0
- package/dist/utils/edgeStyling.js +9 -5
- package/dist/utils/fetchWithAuth.d.ts +36 -15
- package/dist/utils/fetchWithAuth.js +53 -23
- package/dist/utils/icons.d.ts +5 -2
- package/dist/utils/icons.js +6 -5
- package/dist/utils/nodeIds.d.ts +1 -1
- package/dist/utils/nodeIds.js +1 -1
- package/dist/utils/nodeSwap.d.ts +6 -2
- package/dist/utils/nodeSwap.js +62 -129
- package/dist/utils/nodeTypes.d.ts +17 -8
- package/dist/utils/nodeTypes.js +27 -20
- package/dist/utils/performanceUtils.js +7 -0
- package/dist/utils/portUtils.d.ts +47 -11
- package/dist/utils/portUtils.js +67 -14
- package/dist/utils/portal.d.ts +18 -0
- package/dist/utils/portal.js +34 -0
- package/dist/utils/schemaMerge.d.ts +25 -0
- package/dist/utils/schemaMerge.js +61 -0
- package/package.json +7 -5
- package/dist/messages/deprecation.d.ts +0 -20
- package/dist/messages/deprecation.js +0 -33
- package/dist/registry/plugin.d.ts +0 -215
- package/dist/registry/plugin.js +0 -249
- package/dist/services/api.d.ts +0 -129
- package/dist/services/api.js +0 -217
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @module services/dynamicSchemaService
|
|
7
7
|
*/
|
|
8
|
-
import type { ConfigSchema, DynamicSchemaEndpoint, ExternalEditLink, ConfigEditOptions, WorkflowNode } from '../types/index.js';
|
|
8
|
+
import type { ConfigSchema, DynamicSchemaEndpoint, ExternalEditLink, ConfigEditOptions, UISchemaElement, WorkflowNode } from '../types/index.js';
|
|
9
|
+
import type { EndpointConfig } from '../config/endpoints.js';
|
|
9
10
|
/**
|
|
10
11
|
* Result of a dynamic schema fetch operation
|
|
11
12
|
*/
|
|
@@ -14,11 +15,33 @@ export interface DynamicSchemaResult {
|
|
|
14
15
|
success: boolean;
|
|
15
16
|
/** The fetched config schema (if successful) */
|
|
16
17
|
schema?: ConfigSchema;
|
|
18
|
+
/**
|
|
19
|
+
* The fetched uiSchema, when the endpoint returns one alongside the schema.
|
|
20
|
+
* Lets a server-hydrated response carry its own field grouping/layout so the
|
|
21
|
+
* form isn't stuck with the node's static-metadata uiSchema (which only
|
|
22
|
+
* references the static schema's properties).
|
|
23
|
+
*/
|
|
24
|
+
uiSchema?: UISchemaElement;
|
|
17
25
|
/** Error message (if failed) */
|
|
18
26
|
error?: string;
|
|
19
27
|
/** Whether the schema was loaded from cache */
|
|
20
28
|
fromCache?: boolean;
|
|
21
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Resolves the fetch key for a node's dynamic-schema endpoint: the endpoint URL
|
|
32
|
+
* with all template variables substituted from the node context.
|
|
33
|
+
*
|
|
34
|
+
* The key changes whenever a config value the endpoint's `parameterMapping`
|
|
35
|
+
* references changes (e.g. a trigger node's `event_type`). Callers watch it to
|
|
36
|
+
* refetch the schema when the inputs that shape it change, keeping the rendered
|
|
37
|
+
* form in step with the current configuration.
|
|
38
|
+
*
|
|
39
|
+
* @param endpoint - The dynamic schema endpoint configuration
|
|
40
|
+
* @param node - The workflow node instance
|
|
41
|
+
* @param workflowId - Optional workflow ID for context
|
|
42
|
+
* @returns The resolved endpoint URL, used as a reactive refetch key
|
|
43
|
+
*/
|
|
44
|
+
export declare function resolveDynamicSchemaKey(endpoint: DynamicSchemaEndpoint, node: WorkflowNode, workflowId?: string): string;
|
|
22
45
|
/**
|
|
23
46
|
* Fetches a dynamic configuration schema from a REST endpoint.
|
|
24
47
|
*
|
|
@@ -32,7 +55,7 @@ export interface DynamicSchemaResult {
|
|
|
32
55
|
* const endpoint: DynamicSchemaEndpoint = {
|
|
33
56
|
* url: "/api/nodes/{nodeTypeId}/schema",
|
|
34
57
|
* method: "GET",
|
|
35
|
-
* parameterMapping: { nodeTypeId: "metadata.
|
|
58
|
+
* parameterMapping: { nodeTypeId: "metadata.node_type_id" }
|
|
36
59
|
* };
|
|
37
60
|
*
|
|
38
61
|
* const result = await fetchDynamicSchema(endpoint, node);
|
|
@@ -41,7 +64,7 @@ export interface DynamicSchemaResult {
|
|
|
41
64
|
* }
|
|
42
65
|
* ```
|
|
43
66
|
*/
|
|
44
|
-
export declare function fetchDynamicSchema(endpoint: DynamicSchemaEndpoint, node: WorkflowNode, workflowId?: string): Promise<DynamicSchemaResult>;
|
|
67
|
+
export declare function fetchDynamicSchema(endpointConfig: EndpointConfig | null, endpoint: DynamicSchemaEndpoint, node: WorkflowNode, workflowId?: string): Promise<DynamicSchemaResult>;
|
|
45
68
|
/**
|
|
46
69
|
* Resolves an external edit link URL with template variables.
|
|
47
70
|
*
|
|
@@ -55,7 +78,7 @@ export declare function fetchDynamicSchema(endpoint: DynamicSchemaEndpoint, node
|
|
|
55
78
|
* ```typescript
|
|
56
79
|
* const link: ExternalEditLink = {
|
|
57
80
|
* url: "https://admin.example.com/nodes/{nodeTypeId}/edit/{instanceId}",
|
|
58
|
-
* parameterMapping: { nodeTypeId: "metadata.
|
|
81
|
+
* parameterMapping: { nodeTypeId: "metadata.node_type_id", instanceId: "id" }
|
|
59
82
|
* };
|
|
60
83
|
*
|
|
61
84
|
* const url = resolveExternalEditUrl(link, node, workflowId);
|
|
@@ -81,10 +104,15 @@ export declare function clearSchemaCache(pattern?: string): void;
|
|
|
81
104
|
/**
|
|
82
105
|
* Invalidates a specific schema cache entry for a node.
|
|
83
106
|
*
|
|
107
|
+
* The workflow ID must match the value passed when the schema was fetched:
|
|
108
|
+
* endpoints whose URL references `{workflowId}` resolve to a different cache key
|
|
109
|
+
* without it, so omitting it here would miss the entry the fetch created.
|
|
110
|
+
*
|
|
84
111
|
* @param node - The workflow node to invalidate cache for
|
|
85
112
|
* @param endpoint - The dynamic schema endpoint configuration
|
|
113
|
+
* @param workflowId - Optional workflow ID, matching the fetch context
|
|
86
114
|
*/
|
|
87
|
-
export declare function invalidateSchemaCache(node: WorkflowNode, endpoint: DynamicSchemaEndpoint): void;
|
|
115
|
+
export declare function invalidateSchemaCache(node: WorkflowNode, endpoint: DynamicSchemaEndpoint, workflowId?: string): void;
|
|
88
116
|
/**
|
|
89
117
|
* Checks if a node has config edit options configured.
|
|
90
118
|
*
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @module services/dynamicSchemaService
|
|
7
7
|
*/
|
|
8
|
-
import { getEndpointConfig } from './api.js';
|
|
9
8
|
import { DEFAULT_CACHE_TTL_MS } from '../config/constants.js';
|
|
10
9
|
/**
|
|
11
10
|
* Schema cache with TTL support
|
|
@@ -16,16 +15,16 @@ const schemaCache = new Map();
|
|
|
16
15
|
const DEFAULT_CACHE_TTL = DEFAULT_CACHE_TTL_MS;
|
|
17
16
|
/**
|
|
18
17
|
* Resolves a template variable path from the node context.
|
|
19
|
-
* Supports dot-notation paths like "metadata.
|
|
18
|
+
* Supports dot-notation paths like "metadata.node_type_id", "config.apiKey", "id"
|
|
20
19
|
*
|
|
21
20
|
* @param context - The node context containing all available data
|
|
22
|
-
* @param path - Dot-notation path to resolve (e.g., "metadata.
|
|
21
|
+
* @param path - Dot-notation path to resolve (e.g., "metadata.node_type_id")
|
|
23
22
|
* @returns The resolved value as a string, or undefined if not found
|
|
24
23
|
*
|
|
25
24
|
* @example
|
|
26
25
|
* ```typescript
|
|
27
|
-
* const context = { id: "node-1", metadata: {
|
|
28
|
-
* resolveVariablePath(context, "metadata.
|
|
26
|
+
* const context = { id: "node-1", metadata: { node_type_id: "llm-node" } };
|
|
27
|
+
* resolveVariablePath(context, "metadata.node_type_id"); // Returns "llm-node"
|
|
29
28
|
* resolveVariablePath(context, "id"); // Returns "node-1"
|
|
30
29
|
* ```
|
|
31
30
|
*/
|
|
@@ -61,8 +60,8 @@ function resolveVariablePath(context, path) {
|
|
|
61
60
|
* @example
|
|
62
61
|
* ```typescript
|
|
63
62
|
* const url = "/api/nodes/{nodeTypeId}/schema?instance={instanceId}";
|
|
64
|
-
* const mapping = { nodeTypeId: "metadata.
|
|
65
|
-
* const context = { id: "node-1", metadata: {
|
|
63
|
+
* const mapping = { nodeTypeId: "metadata.node_type_id", instanceId: "id" };
|
|
64
|
+
* const context = { id: "node-1", metadata: { node_type_id: "llm-node" } };
|
|
66
65
|
* resolveTemplate(url, mapping, context);
|
|
67
66
|
* // Returns "/api/nodes/llm-node/schema?instance=node-1"
|
|
68
67
|
* ```
|
|
@@ -105,6 +104,44 @@ function generateCacheKey(endpoint, context) {
|
|
|
105
104
|
const url = resolveTemplate(endpoint.url, endpoint.parameterMapping, context);
|
|
106
105
|
return `schema:${url}`;
|
|
107
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Builds the template-resolution context for a node.
|
|
109
|
+
*
|
|
110
|
+
* Shared by every function that resolves a dynamic-schema URL, external-edit
|
|
111
|
+
* URL, or cache key, so they all read identical values — and therefore compute
|
|
112
|
+
* matching keys — from a single place.
|
|
113
|
+
*
|
|
114
|
+
* @param node - The workflow node instance
|
|
115
|
+
* @param workflowId - Optional workflow ID for context
|
|
116
|
+
* @returns The node context used for template resolution
|
|
117
|
+
*/
|
|
118
|
+
function buildNodeContext(node, workflowId) {
|
|
119
|
+
return {
|
|
120
|
+
id: node.id,
|
|
121
|
+
type: node.type,
|
|
122
|
+
metadata: node.data.metadata,
|
|
123
|
+
config: node.data.config,
|
|
124
|
+
extensions: node.data.extensions,
|
|
125
|
+
workflowId
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Resolves the fetch key for a node's dynamic-schema endpoint: the endpoint URL
|
|
130
|
+
* with all template variables substituted from the node context.
|
|
131
|
+
*
|
|
132
|
+
* The key changes whenever a config value the endpoint's `parameterMapping`
|
|
133
|
+
* references changes (e.g. a trigger node's `event_type`). Callers watch it to
|
|
134
|
+
* refetch the schema when the inputs that shape it change, keeping the rendered
|
|
135
|
+
* form in step with the current configuration.
|
|
136
|
+
*
|
|
137
|
+
* @param endpoint - The dynamic schema endpoint configuration
|
|
138
|
+
* @param node - The workflow node instance
|
|
139
|
+
* @param workflowId - Optional workflow ID for context
|
|
140
|
+
* @returns The resolved endpoint URL, used as a reactive refetch key
|
|
141
|
+
*/
|
|
142
|
+
export function resolveDynamicSchemaKey(endpoint, node, workflowId) {
|
|
143
|
+
return resolveTemplate(endpoint.url, endpoint.parameterMapping, buildNodeContext(node, workflowId));
|
|
144
|
+
}
|
|
108
145
|
/**
|
|
109
146
|
* Checks if a cached schema is still valid (not expired).
|
|
110
147
|
*
|
|
@@ -128,7 +165,7 @@ function isCacheValid(entry, ttl = DEFAULT_CACHE_TTL) {
|
|
|
128
165
|
* const endpoint: DynamicSchemaEndpoint = {
|
|
129
166
|
* url: "/api/nodes/{nodeTypeId}/schema",
|
|
130
167
|
* method: "GET",
|
|
131
|
-
* parameterMapping: { nodeTypeId: "metadata.
|
|
168
|
+
* parameterMapping: { nodeTypeId: "metadata.node_type_id" }
|
|
132
169
|
* };
|
|
133
170
|
*
|
|
134
171
|
* const result = await fetchDynamicSchema(endpoint, node);
|
|
@@ -137,16 +174,9 @@ function isCacheValid(entry, ttl = DEFAULT_CACHE_TTL) {
|
|
|
137
174
|
* }
|
|
138
175
|
* ```
|
|
139
176
|
*/
|
|
140
|
-
export async function fetchDynamicSchema(endpoint, node, workflowId) {
|
|
177
|
+
export async function fetchDynamicSchema(endpointConfig, endpoint, node, workflowId) {
|
|
141
178
|
// Build the context from the node
|
|
142
|
-
const context =
|
|
143
|
-
id: node.id,
|
|
144
|
-
type: node.type,
|
|
145
|
-
metadata: node.data.metadata,
|
|
146
|
-
config: node.data.config,
|
|
147
|
-
extensions: node.data.extensions,
|
|
148
|
-
workflowId
|
|
149
|
-
};
|
|
179
|
+
const context = buildNodeContext(node, workflowId);
|
|
150
180
|
// Generate cache key
|
|
151
181
|
const cacheKey = generateCacheKey(endpoint, context);
|
|
152
182
|
// Check cache first (if caching is enabled)
|
|
@@ -156,6 +186,7 @@ export async function fetchDynamicSchema(endpoint, node, workflowId) {
|
|
|
156
186
|
return {
|
|
157
187
|
success: true,
|
|
158
188
|
schema: cached.schema,
|
|
189
|
+
uiSchema: cached.uiSchema,
|
|
159
190
|
fromCache: true
|
|
160
191
|
};
|
|
161
192
|
}
|
|
@@ -163,13 +194,10 @@ export async function fetchDynamicSchema(endpoint, node, workflowId) {
|
|
|
163
194
|
// Resolve the URL with template variables
|
|
164
195
|
let url = resolveTemplate(endpoint.url, endpoint.parameterMapping, context);
|
|
165
196
|
// If URL is relative, try to prepend base URL from endpoint config
|
|
166
|
-
if (url.startsWith('/')) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
const baseUrl = currentConfig.baseUrl.replace(/\/$/, '');
|
|
171
|
-
url = `${baseUrl}${url}`;
|
|
172
|
-
}
|
|
197
|
+
if (url.startsWith('/') && endpointConfig?.baseUrl) {
|
|
198
|
+
// Remove trailing slash from base URL and leading slash from relative URL
|
|
199
|
+
const baseUrl = endpointConfig.baseUrl.replace(/\/$/, '');
|
|
200
|
+
url = `${baseUrl}${url}`;
|
|
173
201
|
}
|
|
174
202
|
// Prepare request options
|
|
175
203
|
const method = endpoint.method ?? 'GET';
|
|
@@ -179,19 +207,6 @@ export async function fetchDynamicSchema(endpoint, node, workflowId) {
|
|
|
179
207
|
'Content-Type': 'application/json',
|
|
180
208
|
...endpoint.headers
|
|
181
209
|
};
|
|
182
|
-
// Add auth headers from endpoint config if available
|
|
183
|
-
const currentConfig = getEndpointConfig();
|
|
184
|
-
if (currentConfig?.auth) {
|
|
185
|
-
if (currentConfig.auth.type === 'bearer' && currentConfig.auth.token) {
|
|
186
|
-
headers['Authorization'] = `Bearer ${currentConfig.auth.token}`;
|
|
187
|
-
}
|
|
188
|
-
else if (currentConfig.auth.type === 'api_key' && currentConfig.auth.apiKey) {
|
|
189
|
-
headers['X-API-Key'] = currentConfig.auth.apiKey;
|
|
190
|
-
}
|
|
191
|
-
else if (currentConfig.auth.type === 'custom' && currentConfig.auth.headers) {
|
|
192
|
-
Object.assign(headers, currentConfig.auth.headers);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
210
|
// Prepare fetch options
|
|
196
211
|
const fetchOptions = {
|
|
197
212
|
method,
|
|
@@ -249,10 +264,15 @@ export async function fetchDynamicSchema(endpoint, node, workflowId) {
|
|
|
249
264
|
error: 'Invalid schema format received from endpoint'
|
|
250
265
|
};
|
|
251
266
|
}
|
|
267
|
+
// A companion uiSchema may ride alongside the schema (server-hydrated
|
|
268
|
+
// forms). Look for it next to wherever the schema was found — sibling of
|
|
269
|
+
// the envelope, or nested in the same `data`/`schema` wrapper.
|
|
270
|
+
const uiSchema = (data.uiSchema ?? data.data?.uiSchema ?? data.schema?.uiSchema);
|
|
252
271
|
// Cache the schema (if caching is enabled)
|
|
253
272
|
if (endpoint.cacheSchema !== false) {
|
|
254
273
|
schemaCache.set(cacheKey, {
|
|
255
274
|
schema,
|
|
275
|
+
uiSchema,
|
|
256
276
|
cachedAt: Date.now(),
|
|
257
277
|
cacheKey
|
|
258
278
|
});
|
|
@@ -260,6 +280,7 @@ export async function fetchDynamicSchema(endpoint, node, workflowId) {
|
|
|
260
280
|
return {
|
|
261
281
|
success: true,
|
|
262
282
|
schema,
|
|
283
|
+
uiSchema,
|
|
263
284
|
fromCache: false
|
|
264
285
|
};
|
|
265
286
|
}
|
|
@@ -296,7 +317,7 @@ export async function fetchDynamicSchema(endpoint, node, workflowId) {
|
|
|
296
317
|
* ```typescript
|
|
297
318
|
* const link: ExternalEditLink = {
|
|
298
319
|
* url: "https://admin.example.com/nodes/{nodeTypeId}/edit/{instanceId}",
|
|
299
|
-
* parameterMapping: { nodeTypeId: "metadata.
|
|
320
|
+
* parameterMapping: { nodeTypeId: "metadata.node_type_id", instanceId: "id" }
|
|
300
321
|
* };
|
|
301
322
|
*
|
|
302
323
|
* const url = resolveExternalEditUrl(link, node, workflowId);
|
|
@@ -305,14 +326,7 @@ export async function fetchDynamicSchema(endpoint, node, workflowId) {
|
|
|
305
326
|
*/
|
|
306
327
|
export function resolveExternalEditUrl(link, node, workflowId, callbackUrl) {
|
|
307
328
|
// Build the context from the node
|
|
308
|
-
const context =
|
|
309
|
-
id: node.id,
|
|
310
|
-
type: node.type,
|
|
311
|
-
metadata: node.data.metadata,
|
|
312
|
-
config: node.data.config,
|
|
313
|
-
extensions: node.data.extensions,
|
|
314
|
-
workflowId
|
|
315
|
-
};
|
|
329
|
+
const context = buildNodeContext(node, workflowId);
|
|
316
330
|
// Resolve the URL with template variables
|
|
317
331
|
let url = resolveTemplate(link.url, link.parameterMapping, context);
|
|
318
332
|
// Append callback URL if configured
|
|
@@ -384,18 +398,16 @@ export function clearSchemaCache(pattern) {
|
|
|
384
398
|
/**
|
|
385
399
|
* Invalidates a specific schema cache entry for a node.
|
|
386
400
|
*
|
|
401
|
+
* The workflow ID must match the value passed when the schema was fetched:
|
|
402
|
+
* endpoints whose URL references `{workflowId}` resolve to a different cache key
|
|
403
|
+
* without it, so omitting it here would miss the entry the fetch created.
|
|
404
|
+
*
|
|
387
405
|
* @param node - The workflow node to invalidate cache for
|
|
388
406
|
* @param endpoint - The dynamic schema endpoint configuration
|
|
407
|
+
* @param workflowId - Optional workflow ID, matching the fetch context
|
|
389
408
|
*/
|
|
390
|
-
export function invalidateSchemaCache(node, endpoint) {
|
|
391
|
-
const
|
|
392
|
-
id: node.id,
|
|
393
|
-
type: node.type,
|
|
394
|
-
metadata: node.data.metadata,
|
|
395
|
-
config: node.data.config,
|
|
396
|
-
extensions: node.data.extensions
|
|
397
|
-
};
|
|
398
|
-
const cacheKey = generateCacheKey(endpoint, context);
|
|
409
|
+
export function invalidateSchemaCache(node, endpoint, workflowId) {
|
|
410
|
+
const cacheKey = generateCacheKey(endpoint, buildNodeContext(node, workflowId));
|
|
399
411
|
schemaCache.delete(cacheKey);
|
|
400
412
|
}
|
|
401
413
|
/**
|
|
@@ -7,24 +7,15 @@
|
|
|
7
7
|
* reimplementing the logic, ensuring "blur active element" flushing and metadata
|
|
8
8
|
* construction happen in exactly one place.
|
|
9
9
|
*/
|
|
10
|
+
import { type FlowDropInstance } from '../stores/instanceContainer.svelte.js';
|
|
10
11
|
import type { Workflow } from '../types/index.js';
|
|
11
12
|
import type { FlowDropEventHandlers, FlowDropFeatures } from '../types/events.js';
|
|
12
|
-
/**
|
|
13
|
-
* Minimal interface for the enhanced API client used when an authProvider is present.
|
|
14
|
-
* Matches the surface of EnhancedFlowDropApiClient that save needs.
|
|
15
|
-
*/
|
|
16
|
-
export interface SaveApiClient {
|
|
17
|
-
saveWorkflow(workflow: Workflow): Promise<Workflow>;
|
|
18
|
-
updateWorkflow(id: string, workflow: Workflow): Promise<Workflow>;
|
|
19
|
-
}
|
|
20
13
|
/**
|
|
21
14
|
* Options accepted by globalSaveWorkflow().
|
|
22
15
|
* All fields are optional — omitting them falls back to the basic behaviour
|
|
23
|
-
* (no event handlers, always show toasts
|
|
16
|
+
* (no event handlers, always show toasts).
|
|
24
17
|
*/
|
|
25
18
|
export interface GlobalSaveOptions {
|
|
26
|
-
/** Enhanced API client with authProvider support. Falls back to legacy workflowApi when absent. */
|
|
27
|
-
apiClient?: SaveApiClient | null;
|
|
28
19
|
/** Event handler hooks (onBeforeSave, onAfterSave, onSaveError, onApiError). */
|
|
29
20
|
eventHandlers?: FlowDropEventHandlers;
|
|
30
21
|
/** Feature flags (showToasts). Defaults to DEFAULT_FEATURES. */
|
|
@@ -41,6 +32,11 @@ export interface GlobalSaveOptions {
|
|
|
41
32
|
* Use this to update draft storage keys or other ID-dependent state.
|
|
42
33
|
*/
|
|
43
34
|
onSaved?: (savedWorkflow: Workflow) => void;
|
|
35
|
+
/**
|
|
36
|
+
* The FlowDrop instance whose workflow should be saved.
|
|
37
|
+
* Defaults to the page-default instance when omitted.
|
|
38
|
+
*/
|
|
39
|
+
instance?: FlowDropInstance;
|
|
44
40
|
}
|
|
45
41
|
/**
|
|
46
42
|
* Options accepted by globalExportWorkflow().
|
|
@@ -48,6 +44,11 @@ export interface GlobalSaveOptions {
|
|
|
48
44
|
export interface GlobalExportOptions {
|
|
49
45
|
/** Feature flags (showToasts). Defaults to DEFAULT_FEATURES. */
|
|
50
46
|
features?: Partial<FlowDropFeatures>;
|
|
47
|
+
/**
|
|
48
|
+
* The FlowDrop instance whose workflow should be exported.
|
|
49
|
+
* Defaults to the page-default instance when omitted.
|
|
50
|
+
*/
|
|
51
|
+
instance?: FlowDropInstance;
|
|
51
52
|
}
|
|
52
53
|
/**
|
|
53
54
|
* Save the current workflow to the backend.
|
|
@@ -59,7 +60,7 @@ export interface GlobalExportOptions {
|
|
|
59
60
|
* 1. Flush pending form changes (blur active element + tick)
|
|
60
61
|
* 2. Optionally call onBeforeSave — return false cancels the save
|
|
61
62
|
* 3. Build the canonical Workflow object (preserving metadata, format, etc.)
|
|
62
|
-
* 4. Persist via
|
|
63
|
+
* 4. Persist via the instance's API client (fd.api.client)
|
|
63
64
|
* 5. Update the store if the server assigned a new ID
|
|
64
65
|
* 6. Call onMarkAsSaved / onAfterSave hooks
|
|
65
66
|
* 7. Show toast notifications (respecting features.showToasts)
|
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
* construction happen in exactly one place.
|
|
9
9
|
*/
|
|
10
10
|
import { tick } from 'svelte';
|
|
11
|
-
import {
|
|
12
|
-
import { workflowApi, setEndpointConfig } from './api.js';
|
|
11
|
+
import { getDefaultInstance } from '../stores/instanceContainer.svelte.js';
|
|
13
12
|
import { createEndpointConfig } from '../config/endpoints.js';
|
|
14
13
|
import { v4 as uuidv4 } from 'uuid';
|
|
15
14
|
import { DEFAULT_WORKFLOW_FORMAT } from '../types/index.js';
|
|
@@ -19,29 +18,19 @@ import { DEFAULT_FEATURES } from '../types/events.js';
|
|
|
19
18
|
// Internal helpers
|
|
20
19
|
// ---------------------------------------------------------------------------
|
|
21
20
|
/**
|
|
22
|
-
* Ensure API
|
|
23
|
-
* This is needed when the global save function is called from the layout
|
|
24
|
-
* which doesn't initialize the API configuration like
|
|
21
|
+
* Ensure the instance's API context is configured.
|
|
22
|
+
* This is needed when the global save function is called from the layout
|
|
23
|
+
* component which doesn't initialize the API configuration like <App> does.
|
|
25
24
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const currentConfig = getEndpointConfig();
|
|
30
|
-
if (currentConfig && currentConfig.baseUrl) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
catch {
|
|
35
|
-
// Could not check existing API configuration, initializing
|
|
25
|
+
function ensureApiConfiguration(fd) {
|
|
26
|
+
if (fd.api.isConfigured() && fd.api.config?.baseUrl) {
|
|
27
|
+
return;
|
|
36
28
|
}
|
|
37
29
|
// API configuration is not initialized — derive URL from window.location when available
|
|
38
30
|
const apiBaseUrl = typeof window !== 'undefined'
|
|
39
31
|
? `${window.location.protocol}//${window.location.host}/api/flowdrop`
|
|
40
32
|
: '/api/flowdrop';
|
|
41
33
|
const config = createEndpointConfig(apiBaseUrl, {
|
|
42
|
-
auth: {
|
|
43
|
-
type: 'none'
|
|
44
|
-
},
|
|
45
34
|
timeout: 10000,
|
|
46
35
|
retry: {
|
|
47
36
|
enabled: true,
|
|
@@ -50,7 +39,7 @@ async function ensureApiConfiguration() {
|
|
|
50
39
|
backoff: 'exponential'
|
|
51
40
|
}
|
|
52
41
|
});
|
|
53
|
-
|
|
42
|
+
fd.api.configure(config);
|
|
54
43
|
}
|
|
55
44
|
/**
|
|
56
45
|
* Flush any pending form changes by blurring the active element.
|
|
@@ -79,18 +68,21 @@ async function flushPendingFormChanges() {
|
|
|
79
68
|
* 1. Flush pending form changes (blur active element + tick)
|
|
80
69
|
* 2. Optionally call onBeforeSave — return false cancels the save
|
|
81
70
|
* 3. Build the canonical Workflow object (preserving metadata, format, etc.)
|
|
82
|
-
* 4. Persist via
|
|
71
|
+
* 4. Persist via the instance's API client (fd.api.client)
|
|
83
72
|
* 5. Update the store if the server assigned a new ID
|
|
84
73
|
* 6. Call onMarkAsSaved / onAfterSave hooks
|
|
85
74
|
* 7. Show toast notifications (respecting features.showToasts)
|
|
86
75
|
*/
|
|
87
76
|
export async function globalSaveWorkflow(options = {}) {
|
|
88
|
-
const {
|
|
77
|
+
const { eventHandlers, onMarkAsSaved, onSaved } = options;
|
|
89
78
|
const features = { ...DEFAULT_FEATURES, ...options.features };
|
|
79
|
+
// Resolve the target instance; defaults to the page-default instance.
|
|
80
|
+
const fd = options.instance ?? getDefaultInstance();
|
|
81
|
+
const readWorkflow = () => fd.workflow.current;
|
|
90
82
|
// Step 1 — Flush pending form changes (single location for this logic)
|
|
91
83
|
await flushPendingFormChanges();
|
|
92
|
-
// Get current workflow from
|
|
93
|
-
const currentWorkflow =
|
|
84
|
+
// Get current workflow from the instance's store after flush
|
|
85
|
+
const currentWorkflow = readWorkflow();
|
|
94
86
|
if (!currentWorkflow) {
|
|
95
87
|
if (features.showToasts) {
|
|
96
88
|
apiToasts.error('Save workflow', 'No workflow to save');
|
|
@@ -107,7 +99,7 @@ export async function globalSaveWorkflow(options = {}) {
|
|
|
107
99
|
const loadingToast = features.showToasts ? apiToasts.loading('Saving workflow') : null;
|
|
108
100
|
try {
|
|
109
101
|
// Ensure API configuration is initialised (needed when called outside App.svelte)
|
|
110
|
-
|
|
102
|
+
ensureApiConfiguration(fd);
|
|
111
103
|
// Step 3 — Build the canonical workflow object.
|
|
112
104
|
// Preserve all existing metadata fields (format, tags, etc.) so nothing is dropped.
|
|
113
105
|
//
|
|
@@ -124,35 +116,21 @@ export async function globalSaveWorkflow(options = {}) {
|
|
|
124
116
|
edges: currentWorkflow.edges || [],
|
|
125
117
|
metadata: {
|
|
126
118
|
...currentWorkflow.metadata,
|
|
127
|
-
|
|
119
|
+
schemaVersion: currentWorkflow.metadata?.schemaVersion || '1.0.0',
|
|
128
120
|
format: currentWorkflow.metadata?.format || DEFAULT_WORKFLOW_FORMAT,
|
|
129
121
|
createdAt: currentWorkflow.metadata?.createdAt || new Date().toISOString(),
|
|
130
122
|
updatedAt: new Date().toISOString()
|
|
131
123
|
}
|
|
132
124
|
};
|
|
133
|
-
// Step 4 — Persist
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
else {
|
|
140
|
-
savedWorkflow = await apiClient.saveWorkflow(finalWorkflow);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
// Legacy path
|
|
145
|
-
if (isExistingWorkflow) {
|
|
146
|
-
savedWorkflow = await workflowApi.updateWorkflow(finalWorkflow.id, finalWorkflow);
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
const { id: _id, ...workflowData } = finalWorkflow;
|
|
150
|
-
savedWorkflow = await workflowApi.createWorkflow(workflowData);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
125
|
+
// Step 4 — Persist via this instance's API client.
|
|
126
|
+
// id-presence (computed above) decides update vs create — never UUID-regex.
|
|
127
|
+
const apiClient = fd.api.client;
|
|
128
|
+
const savedWorkflow = isExistingWorkflow
|
|
129
|
+
? await apiClient.updateWorkflow(finalWorkflow.id, finalWorkflow)
|
|
130
|
+
: await apiClient.saveWorkflow(finalWorkflow);
|
|
153
131
|
// Step 5 — If the server assigned a new ID, sync the store
|
|
154
132
|
if (savedWorkflow.id && savedWorkflow.id !== finalWorkflow.id) {
|
|
155
|
-
|
|
133
|
+
fd.workflow.batchUpdate({
|
|
156
134
|
nodes: finalWorkflow.nodes,
|
|
157
135
|
edges: finalWorkflow.edges,
|
|
158
136
|
name: finalWorkflow.name,
|
|
@@ -167,8 +145,7 @@ export async function globalSaveWorkflow(options = {}) {
|
|
|
167
145
|
onMarkAsSaved();
|
|
168
146
|
}
|
|
169
147
|
else {
|
|
170
|
-
|
|
171
|
-
storeMarkAsSaved();
|
|
148
|
+
fd.workflow.markAsSaved();
|
|
172
149
|
}
|
|
173
150
|
// Notify caller with the definitive saved workflow (server-assigned ID)
|
|
174
151
|
if (onSaved) {
|
|
@@ -190,7 +167,7 @@ export async function globalSaveWorkflow(options = {}) {
|
|
|
190
167
|
dismissToast(loadingToast);
|
|
191
168
|
const errorObj = error instanceof Error ? error : new Error('Unknown error occurred');
|
|
192
169
|
// onSaveError hook
|
|
193
|
-
const currentWorkflowForError =
|
|
170
|
+
const currentWorkflowForError = readWorkflow();
|
|
194
171
|
if (eventHandlers?.onSaveError && currentWorkflowForError) {
|
|
195
172
|
await eventHandlers.onSaveError(errorObj, currentWorkflowForError);
|
|
196
173
|
}
|
|
@@ -218,7 +195,8 @@ export async function globalExportWorkflow(options = {}) {
|
|
|
218
195
|
try {
|
|
219
196
|
// Flush pending changes before exporting (same discipline as save)
|
|
220
197
|
await flushPendingFormChanges();
|
|
221
|
-
const
|
|
198
|
+
const fd = options.instance ?? getDefaultInstance();
|
|
199
|
+
const currentWorkflow = fd.workflow.current;
|
|
222
200
|
if (!currentWorkflow) {
|
|
223
201
|
if (features.showToasts) {
|
|
224
202
|
apiToasts.error('Export workflow', 'No workflow to export');
|
|
@@ -234,7 +212,7 @@ export async function globalExportWorkflow(options = {}) {
|
|
|
234
212
|
edges: currentWorkflow.edges || [],
|
|
235
213
|
metadata: {
|
|
236
214
|
...currentWorkflow.metadata,
|
|
237
|
-
|
|
215
|
+
schemaVersion: currentWorkflow.metadata?.schemaVersion || '1.0.0',
|
|
238
216
|
format: currentWorkflow.metadata?.format || DEFAULT_WORKFLOW_FORMAT,
|
|
239
217
|
createdAt: currentWorkflow.metadata?.createdAt || new Date().toISOString(),
|
|
240
218
|
updatedAt: new Date().toISOString()
|
|
@@ -49,6 +49,13 @@ export interface PushOptions {
|
|
|
49
49
|
* a complete copy of the workflow state. This trades memory for simplicity
|
|
50
50
|
* and reliability.
|
|
51
51
|
*
|
|
52
|
+
* Snapshot model: the undo stack holds *committed* states, and its **top is the
|
|
53
|
+
* current live state**. `initialize()` seeds it with the starting state, and each
|
|
54
|
+
* mutation pushes the state *after* the change. One `undo()` moves the top back by
|
|
55
|
+
* exactly one committed change, and `redo()` restores the state that was undone.
|
|
56
|
+
* (Callers must push the post-change state — pushing pre-change snapshots makes a
|
|
57
|
+
* single undo skip a step once there are ≥2 sequential edits; see issue #39.)
|
|
58
|
+
*
|
|
52
59
|
* @example
|
|
53
60
|
* ```typescript
|
|
54
61
|
* const historyService = new HistoryService();
|
|
@@ -56,7 +63,7 @@ export interface PushOptions {
|
|
|
56
63
|
* // Initialize with current workflow
|
|
57
64
|
* historyService.initialize(workflow);
|
|
58
65
|
*
|
|
59
|
-
* // Push state
|
|
66
|
+
* // Push state AFTER making changes (the new committed state)
|
|
60
67
|
* historyService.push(workflow, { description: "Add node" });
|
|
61
68
|
*
|
|
62
69
|
* // Undo/Redo
|
|
@@ -95,12 +102,13 @@ export declare class HistoryService {
|
|
|
95
102
|
*/
|
|
96
103
|
initialize(workflow: Workflow): void;
|
|
97
104
|
/**
|
|
98
|
-
* Push
|
|
105
|
+
* Push a new committed state to history
|
|
99
106
|
*
|
|
100
|
-
* Call this
|
|
107
|
+
* Call this AFTER modifying the workflow, with the resulting ("after") state:
|
|
108
|
+
* the stack top is the current live state, so one undo == one committed change.
|
|
101
109
|
* The redo stack is cleared when new changes are pushed.
|
|
102
110
|
*
|
|
103
|
-
* @param workflow - The
|
|
111
|
+
* @param workflow - The workflow state after the change
|
|
104
112
|
* @param options - Options for this history entry
|
|
105
113
|
*/
|
|
106
114
|
push(workflow: Workflow, options?: PushOptions): void;
|
|
@@ -124,18 +132,30 @@ export declare class HistoryService {
|
|
|
124
132
|
* Start a transaction for grouping multiple changes
|
|
125
133
|
*
|
|
126
134
|
* All changes made during a transaction are combined into a single undo entry.
|
|
127
|
-
* Useful for operations like "delete node" which also removes connected edges
|
|
135
|
+
* Useful for operations like "delete node" which also removes connected edges,
|
|
136
|
+
* or coalescing a burst of live config edits into one step. While open, `push()`
|
|
137
|
+
* is suppressed; `commitTransaction()` records a single post-change entry.
|
|
128
138
|
*
|
|
129
|
-
* @param workflow - The current workflow state
|
|
139
|
+
* @param workflow - The current workflow state at transaction start. Retained so
|
|
140
|
+
* {@link cancelTransaction} can restore it; the committed entry is the *final*
|
|
141
|
+
* state passed to {@link commitTransaction}, not this snapshot.
|
|
130
142
|
* @param description - Description for the combined change
|
|
131
143
|
*/
|
|
132
144
|
startTransaction(workflow: Workflow, description?: string): void;
|
|
133
145
|
/**
|
|
134
146
|
* Commit the current transaction
|
|
135
147
|
*
|
|
136
|
-
*
|
|
148
|
+
* Records the transaction's *post-change* state as a single history entry, so
|
|
149
|
+
* one undo reverts the whole grouped operation and redo restores its result.
|
|
150
|
+
*
|
|
151
|
+
* The final state is required: the transaction's owner (the store) holds the
|
|
152
|
+
* live workflow and must supply it. There is deliberately no "commit whatever
|
|
153
|
+
* you captured at start" fallback — that would silently record a pre-change
|
|
154
|
+
* snapshot and reintroduce the off-by-one this model exists to prevent (#39).
|
|
155
|
+
*
|
|
156
|
+
* @param finalWorkflow - The workflow state after the grouped change.
|
|
137
157
|
*/
|
|
138
|
-
commitTransaction(): void;
|
|
158
|
+
commitTransaction(finalWorkflow: Workflow): void;
|
|
139
159
|
/**
|
|
140
160
|
* Cancel the current transaction without committing
|
|
141
161
|
*
|
|
@@ -144,6 +164,8 @@ export declare class HistoryService {
|
|
|
144
164
|
* can restore the store to its pre-transaction state.
|
|
145
165
|
*/
|
|
146
166
|
cancelTransaction(): Workflow | null;
|
|
167
|
+
/** Reset the in-progress transaction bookkeeping. */
|
|
168
|
+
private clearTransaction;
|
|
147
169
|
/**
|
|
148
170
|
* Clear all history
|
|
149
171
|
*
|
|
@@ -202,9 +224,15 @@ export declare class HistoryService {
|
|
|
202
224
|
private notifyChange;
|
|
203
225
|
}
|
|
204
226
|
/**
|
|
205
|
-
*
|
|
227
|
+
* History service of the page-default FlowDrop instance.
|
|
228
|
+
*
|
|
229
|
+
* Kept as a module-level export for backward compatibility (re-exported via
|
|
230
|
+
* `@flowdrop/flowdrop/editor`) — `createFlowDropInstance({ isDefault: true })`
|
|
231
|
+
* adopts this exact object, so legacy `historyService.undo()` calls keep
|
|
232
|
+
* operating on the default editor's history stack. Holds no reactive state,
|
|
233
|
+
* so module-level construction is SSR-safe.
|
|
206
234
|
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
235
|
+
* For additional editor instances, the instance container creates a fresh
|
|
236
|
+
* `new HistoryService()` — use `getInstance().history` in components.
|
|
209
237
|
*/
|
|
210
238
|
export declare const historyService: HistoryService;
|