@flowdrop/flowdrop 2.0.0-beta.10 → 2.0.0-beta.11

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.
Files changed (61) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/dist/chat/batchFeedback.js +1 -1
  3. package/dist/chat/commandClassifier.d.ts +11 -0
  4. package/dist/chat/commandClassifier.js +20 -0
  5. package/dist/chat/historyBuilder.d.ts +39 -0
  6. package/dist/chat/historyBuilder.js +82 -0
  7. package/dist/chat/index.d.ts +2 -1
  8. package/dist/chat/index.js +2 -1
  9. package/dist/chat/responseParser.js +16 -12
  10. package/dist/commands/parser.d.ts +12 -0
  11. package/dist/commands/parser.js +33 -6
  12. package/dist/components/ConfigForm.svelte +30 -6
  13. package/dist/components/SettingsPanel.svelte +9 -0
  14. package/dist/components/WorkflowEditor.svelte +5 -2
  15. package/dist/components/chat/AIChatPanel.svelte +42 -6
  16. package/dist/components/chat/CommandPreview.svelte +10 -1
  17. package/dist/components/form/FormPorts.svelte +21 -3
  18. package/dist/components/form/FormRangeField.svelte +5 -3
  19. package/dist/components/form/FormToggle.svelte +27 -2
  20. package/dist/components/form/FormToggle.svelte.d.ts +5 -0
  21. package/dist/components/playground/ChatInput.svelte +316 -26
  22. package/dist/components/playground/ChatInput.svelte.d.ts +31 -1
  23. package/dist/components/playground/ControlPanel.svelte +22 -0
  24. package/dist/components/playground/ControlPanel.svelte.d.ts +13 -0
  25. package/dist/components/playground/Playground.svelte +217 -4
  26. package/dist/config/endpoints.d.ts +48 -1
  27. package/dist/config/endpoints.js +18 -5
  28. package/dist/messages/defaults.d.ts +98 -0
  29. package/dist/messages/defaults.js +58 -1
  30. package/dist/playground/commands/args.d.ts +32 -0
  31. package/dist/playground/commands/args.js +50 -0
  32. package/dist/playground/commands/dispatch.d.ts +143 -0
  33. package/dist/playground/commands/dispatch.js +162 -0
  34. package/dist/playground/commands/index.d.ts +14 -0
  35. package/dist/playground/commands/index.js +10 -0
  36. package/dist/playground/commands/parser.d.ts +38 -0
  37. package/dist/playground/commands/parser.js +163 -0
  38. package/dist/playground/commands/registry.d.ts +42 -0
  39. package/dist/playground/commands/registry.js +122 -0
  40. package/dist/playground/commands/suggest.d.ts +37 -0
  41. package/dist/playground/commands/suggest.js +46 -0
  42. package/dist/playground/commands/types.d.ts +111 -0
  43. package/dist/playground/commands/types.js +15 -0
  44. package/dist/playground/index.d.ts +19 -0
  45. package/dist/playground/index.js +25 -0
  46. package/dist/playground/runAction.d.ts +48 -0
  47. package/dist/playground/runAction.js +31 -0
  48. package/dist/services/pipelineSignalService.d.ts +97 -0
  49. package/dist/services/pipelineSignalService.js +94 -0
  50. package/dist/services/playgroundService.d.ts +12 -0
  51. package/dist/services/playgroundService.js +22 -0
  52. package/dist/services/workflowLaunchService.d.ts +74 -0
  53. package/dist/services/workflowLaunchService.js +74 -0
  54. package/dist/types/chat.d.ts +5 -1
  55. package/dist/types/settings.d.ts +11 -0
  56. package/dist/types/settings.js +2 -1
  57. package/dist/utils/canvasSelection.d.ts +25 -0
  58. package/dist/utils/canvasSelection.js +37 -0
  59. package/dist/utils/nodeFormSchema.d.ts +51 -0
  60. package/dist/utils/nodeFormSchema.js +87 -0
  61. package/package.json +1 -1
@@ -123,6 +123,18 @@ export declare class PlaygroundService {
123
123
  * @param sessionId - The session UUID
124
124
  */
125
125
  stopExecution(endpointConfig: EndpointConfig | null, sessionId: string, authProvider?: AuthProvider): Promise<void>;
126
+ /**
127
+ * Reset a stuck session to idle, cancelling pending messages and clearing
128
+ * interrupt state.
129
+ *
130
+ * The endpoint is optional in {@link EndpointConfig} — a backend that cannot
131
+ * reset omits it. Callers should check availability first (the slash-command
132
+ * registry does); calling without a configured endpoint throws rather than
133
+ * silently hitting a wrong URL.
134
+ *
135
+ * @param sessionId - The session UUID
136
+ */
137
+ resetSession(endpointConfig: EndpointConfig | null, sessionId: string, authProvider?: AuthProvider): Promise<void>;
126
138
  /**
127
139
  * Start polling for new messages
128
140
  *
@@ -243,6 +243,28 @@ export class PlaygroundService {
243
243
  method: 'POST'
244
244
  }, authProvider);
245
245
  }
246
+ /**
247
+ * Reset a stuck session to idle, cancelling pending messages and clearing
248
+ * interrupt state.
249
+ *
250
+ * The endpoint is optional in {@link EndpointConfig} — a backend that cannot
251
+ * reset omits it. Callers should check availability first (the slash-command
252
+ * registry does); calling without a configured endpoint throws rather than
253
+ * silently hitting a wrong URL.
254
+ *
255
+ * @param sessionId - The session UUID
256
+ */
257
+ async resetSession(endpointConfig, sessionId, authProvider) {
258
+ const config = this.getConfig(endpointConfig);
259
+ const endpoint = config.endpoints.playground.resetSession;
260
+ if (!endpoint) {
261
+ throw new Error('Session reset is not supported by this backend');
262
+ }
263
+ const url = buildEndpointUrl(config, endpoint, { sessionId });
264
+ await this.request(config, url, {
265
+ method: 'POST'
266
+ }, authProvider);
267
+ }
246
268
  // =========================================================================
247
269
  // Polling
248
270
  // =========================================================================
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Workflow Launch Service
3
+ *
4
+ * Starts a workflow run with named inputs — the explicit verb for "run this",
5
+ * as opposed to posting a chat message and relying on a run starting as a side
6
+ * effect.
7
+ *
8
+ * Why this matters beyond tidiness: launching by message fabricates a user turn
9
+ * that enters the conversation and is fed back as input on the next turn. A
10
+ * launch has no message, so nothing is fabricated.
11
+ *
12
+ * Like {@link pipelineSignalService}, this returns a typed result rather than
13
+ * throwing — invalid inputs and an invalid stored workflow are expected
14
+ * outcomes with distinct, per-field presentation, not exceptional ones.
15
+ *
16
+ * @module services/workflowLaunchService
17
+ */
18
+ import type { EndpointConfig } from '../config/endpoints.js';
19
+ import type { AuthProvider } from '../types/auth.js';
20
+ /** A single per-input validation failure reported by the backend. */
21
+ export interface LaunchInputError {
22
+ /** Machine-readable error code. */
23
+ code: string;
24
+ /** Human-readable explanation. */
25
+ message: string;
26
+ /** Which input the error belongs to, when the backend can attribute it. */
27
+ locator?: string;
28
+ }
29
+ export type LaunchResult =
30
+ /** The run was created. `status` is the backend's own lifecycle value. */
31
+ {
32
+ status: 'launched';
33
+ pipelineId: string;
34
+ runStatus?: string;
35
+ queued?: boolean;
36
+ }
37
+ /** Inputs were refused — unknown key, wrong type, missing required. */
38
+ | {
39
+ status: 'invalid-input';
40
+ message: string;
41
+ }
42
+ /**
43
+ * The *stored workflow* is structurally invalid, with per-error locators.
44
+ * Distinct from bad inputs: nothing the caller passed is at fault.
45
+ */
46
+ | {
47
+ status: 'invalid-workflow';
48
+ message: string;
49
+ errors: LaunchInputError[];
50
+ } | {
51
+ status: 'failed';
52
+ message: string;
53
+ } | {
54
+ status: 'unsupported';
55
+ };
56
+ export interface LaunchOptions {
57
+ /** Named inputs, resolved server-side against the workflow's declared manifest. */
58
+ inputs?: Record<string, unknown>;
59
+ /** Attribute the run to a session, so its messages land in that conversation. */
60
+ sessionId?: string;
61
+ }
62
+ declare class WorkflowLaunchService {
63
+ /** True when this configuration exposes an explicit launch verb. */
64
+ isSupported(config: EndpointConfig | null): boolean;
65
+ /**
66
+ * Launch a workflow run.
67
+ *
68
+ * An empty `inputs` is meaningful and supported — it means "run with no
69
+ * inputs", which is a legitimate thing to want and is why this verb exists.
70
+ */
71
+ launch(config: EndpointConfig | null, workflowId: string, options?: LaunchOptions, authProvider?: AuthProvider): Promise<LaunchResult>;
72
+ }
73
+ export declare const workflowLaunchService: WorkflowLaunchService;
74
+ export { WorkflowLaunchService };
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Workflow Launch Service
3
+ *
4
+ * Starts a workflow run with named inputs — the explicit verb for "run this",
5
+ * as opposed to posting a chat message and relying on a run starting as a side
6
+ * effect.
7
+ *
8
+ * Why this matters beyond tidiness: launching by message fabricates a user turn
9
+ * that enters the conversation and is fed back as input on the next turn. A
10
+ * launch has no message, so nothing is fabricated.
11
+ *
12
+ * Like {@link pipelineSignalService}, this returns a typed result rather than
13
+ * throwing — invalid inputs and an invalid stored workflow are expected
14
+ * outcomes with distinct, per-field presentation, not exceptional ones.
15
+ *
16
+ * @module services/workflowLaunchService
17
+ */
18
+ import { buildEndpointUrl } from '../config/endpoints.js';
19
+ import { authenticatedFetch } from '../utils/fetchWithAuth.js';
20
+ import { logger } from '../utils/logger.js';
21
+ class WorkflowLaunchService {
22
+ /** True when this configuration exposes an explicit launch verb. */
23
+ isSupported(config) {
24
+ return config?.endpoints?.workflows?.run != null;
25
+ }
26
+ /**
27
+ * Launch a workflow run.
28
+ *
29
+ * An empty `inputs` is meaningful and supported — it means "run with no
30
+ * inputs", which is a legitimate thing to want and is why this verb exists.
31
+ */
32
+ async launch(config, workflowId, options = {}, authProvider) {
33
+ const endpoint = config?.endpoints?.workflows?.run;
34
+ if (!config || !endpoint)
35
+ return { status: 'unsupported' };
36
+ const url = buildEndpointUrl(config, endpoint, { workflowId });
37
+ const body = {};
38
+ if (options.inputs && Object.keys(options.inputs).length > 0)
39
+ body.inputs = options.inputs;
40
+ if (options.sessionId)
41
+ body.sessionId = options.sessionId;
42
+ const response = await authenticatedFetch(url, {
43
+ method: 'POST',
44
+ headers: { 'Content-Type': 'application/json' },
45
+ body: JSON.stringify(body)
46
+ }, { config, endpointKey: 'workflows', authProvider });
47
+ const payload = (await response.json().catch(() => ({})));
48
+ if (response.ok) {
49
+ const pipelineId = payload.data?.pipelineId;
50
+ if (!pipelineId) {
51
+ return { status: 'failed', message: 'Launch succeeded but returned no pipeline id' };
52
+ }
53
+ return {
54
+ status: 'launched',
55
+ pipelineId,
56
+ runStatus: payload.data?.status,
57
+ queued: payload.data?.queued
58
+ };
59
+ }
60
+ const message = payload.error ?? payload.message ?? `HTTP ${response.status}: ${response.statusText}`;
61
+ logger.warn(`Workflow launch refused for ${workflowId}:`, message);
62
+ // 422 carries per-error locators for a structurally invalid stored
63
+ // definition — a different problem from the caller passing bad inputs.
64
+ if (response.status === 422) {
65
+ return { status: 'invalid-workflow', message, errors: payload.details ?? [] };
66
+ }
67
+ if (response.status === 400) {
68
+ return { status: 'invalid-input', message };
69
+ }
70
+ return { status: 'failed', message };
71
+ }
72
+ }
73
+ export const workflowLaunchService = new WorkflowLaunchService();
74
+ export { WorkflowLaunchService };
@@ -48,8 +48,12 @@ export interface ExtractedCommands {
48
48
  }
49
49
  /**
50
50
  * Status of a single command in the preview
51
+ *
52
+ * `skipped` means the command was intentionally not run (e.g. a layout command
53
+ * while `chatAllowLayoutChanges` is off) — it is not a failure and does not
54
+ * trigger retry feedback.
51
55
  */
52
- export type CommandExecutionStatus = 'pending' | 'executing' | 'success' | 'error';
56
+ export type CommandExecutionStatus = 'pending' | 'executing' | 'success' | 'error' | 'skipped';
53
57
  /**
54
58
  * A single command shown in the command preview UI
55
59
  */
@@ -107,6 +107,17 @@ export interface BehaviorSettings {
107
107
  confirmDelete: boolean;
108
108
  /** Automatically re-submit batch failures to the AI for self-correction */
109
109
  chatAutoRetry: boolean;
110
+ /**
111
+ * Allow the AI assistant's commands to reposition nodes
112
+ * (`layout auto`, `layout beautify`).
113
+ *
114
+ * Turn off to protect a hand-crafted layout: those commands are then skipped
115
+ * (not failed) when a batch is applied, so the rest of the change set still
116
+ * lands. Positioning nodes explicitly via `add ... at <x>,<y>` and viewport
117
+ * commands (`canvas fitview`) are unaffected — they don't overwrite the
118
+ * arrangement of existing nodes.
119
+ */
120
+ chatAllowLayoutChanges: boolean;
110
121
  }
111
122
  /**
112
123
  * API connection and request settings
@@ -75,7 +75,8 @@ export const DEFAULT_BEHAVIOR_SETTINGS = {
75
75
  storeDraftsInBrowser: true,
76
76
  undoHistoryLimit: 50,
77
77
  confirmDelete: false,
78
- chatAutoRetry: true
78
+ chatAutoRetry: true,
79
+ chatAllowLayoutChanges: true
79
80
  };
80
81
  /**
81
82
  * Default API settings
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Canvas Selection Utilities
3
+ *
4
+ * Keeps canvas pointer gestures from turning into browser text-selection drags.
5
+ */
6
+ /**
7
+ * Suppress the text-selection drag a port handle mousedown would otherwise start.
8
+ *
9
+ * All canvas chrome is `user-select: none` (xyflow sets it on the node, pane and
10
+ * viewport), but WebKit still begins a selection drag from a mousedown on
11
+ * unselectable content: it anchors at the nearest selectable text *outside* the
12
+ * canvas — sidebar, toolbar, status bar or the surrounding host page — and
13
+ * extends it as the pointer moves, so drawing a connection paints a selection
14
+ * across the app (#37). Chromium and Firefox never start the gesture.
15
+ *
16
+ * Only handles need this: xyflow already suppresses the default for node drags
17
+ * (d3-drag) and pane drags. Handles are the one canvas drag started from a plain
18
+ * mousedown handler, so we suppress the default here — nothing in the connect
19
+ * flow depends on it, since xyflow tracks the drag on its own pointer listeners.
20
+ * The default action also moves focus, so re-apply it to keep the focus ring
21
+ * (`.svelte-flow__handle:focus` in base.css) behaving as before.
22
+ *
23
+ * Bind in the capture phase so xyflow's handle handler still receives the event.
24
+ */
25
+ export declare function suppressPortDragSelection(event: MouseEvent): void;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Canvas Selection Utilities
3
+ *
4
+ * Keeps canvas pointer gestures from turning into browser text-selection drags.
5
+ */
6
+ /**
7
+ * Suppress the text-selection drag a port handle mousedown would otherwise start.
8
+ *
9
+ * All canvas chrome is `user-select: none` (xyflow sets it on the node, pane and
10
+ * viewport), but WebKit still begins a selection drag from a mousedown on
11
+ * unselectable content: it anchors at the nearest selectable text *outside* the
12
+ * canvas — sidebar, toolbar, status bar or the surrounding host page — and
13
+ * extends it as the pointer moves, so drawing a connection paints a selection
14
+ * across the app (#37). Chromium and Firefox never start the gesture.
15
+ *
16
+ * Only handles need this: xyflow already suppresses the default for node drags
17
+ * (d3-drag) and pane drags. Handles are the one canvas drag started from a plain
18
+ * mousedown handler, so we suppress the default here — nothing in the connect
19
+ * flow depends on it, since xyflow tracks the drag on its own pointer listeners.
20
+ * The default action also moves focus, so re-apply it to keep the focus ring
21
+ * (`.svelte-flow__handle:focus` in base.css) behaving as before.
22
+ *
23
+ * Bind in the capture phase so xyflow's handle handler still receives the event.
24
+ */
25
+ export function suppressPortDragSelection(event) {
26
+ // Primary button only — other buttons never start a selection.
27
+ if (event.button !== 0)
28
+ return;
29
+ const target = event.target;
30
+ if (typeof target?.closest !== 'function')
31
+ return;
32
+ const handle = target.closest('.svelte-flow__handle');
33
+ if (!handle)
34
+ return;
35
+ event.preventDefault();
36
+ handle.focus();
37
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Node-level form contributions — the config fields the *editor* owns for every
3
+ * node, independent of what the node type's own `configSchema` declares.
4
+ *
5
+ * Today that is the port order + exposure widget bound to the reserved
6
+ * `config.ports` key (see {@link PORTS_CONFIG_KEY}). It is a library feature —
7
+ * `PortsConfig` is read by the canvas, not by the engine — so the library
8
+ * injects it rather than expecting every backend to serve it.
9
+ *
10
+ * Why this matters beyond convenience: `ConfigForm` renders its whole form only
11
+ * when it has a schema, so a node type contributing no `configSchema` used to
12
+ * fall straight through to "No configuration options available" and lose the
13
+ * node-level settings with it (#34). Injecting here gives such a node a schema,
14
+ * and the panel something to render.
15
+ *
16
+ * Kept as pure functions so they can be unit-tested directly against the same
17
+ * code `ConfigForm` runs, rather than through the component.
18
+ */
19
+ import type { ConfigSchema, WorkflowNode } from '../types/index.js';
20
+ import type { UISchemaElement } from '../types/uischema.js';
21
+ /**
22
+ * Reserved config key holding the instance's `PortsConfig` (per-direction
23
+ * ordered port list with optional exposure overrides).
24
+ */
25
+ export declare const PORTS_CONFIG_KEY = "ports";
26
+ /**
27
+ * Append the reserved `ports` property to a node's effective config schema.
28
+ *
29
+ * A no-op when there is no node (the standalone `schema`/`values` mode), when
30
+ * the schema already declares `ports` (a backend that serves the field itself
31
+ * stays authoritative), or when the node has no ports to configure — in which
32
+ * case a schema-less node keeps falling through to the empty state, as it
33
+ * should.
34
+ *
35
+ * @returns The schema to render — `base` untouched, or a copy with the field
36
+ * appended (last, so it renders below the node type's own fields).
37
+ */
38
+ export declare function withPortsField(base: ConfigSchema | undefined, node: WorkflowNode | undefined): ConfigSchema | undefined;
39
+ /**
40
+ * Mirror {@link withPortsField} in the UI schema.
41
+ *
42
+ * The UISchema renderer draws only the controls the tree lists, so an injected
43
+ * property is invisible unless a control is added for it. Wraps the authored
44
+ * tree and the new control in a `VerticalLayout`, keeping the author's layout
45
+ * intact and putting the ports control in its own collapsible group below it.
46
+ *
47
+ * @param uiSchema - The authored UI schema, if any. When absent, nothing to do:
48
+ * `ConfigForm` renders the schema's properties flat and picks the field up.
49
+ * @param injected - Whether {@link withPortsField} actually added the property.
50
+ */
51
+ export declare function withPortsControl(uiSchema: UISchemaElement | undefined, injected: boolean): UISchemaElement | undefined;
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Reserved config key holding the instance's `PortsConfig` (per-direction
3
+ * ordered port list with optional exposure overrides).
4
+ */
5
+ export const PORTS_CONFIG_KEY = 'ports';
6
+ /** Config properties whose presence means the node can grow ports at runtime. */
7
+ const DYNAMIC_PORT_KEYS = ['dynamicInputs', 'dynamicOutputs'];
8
+ /**
9
+ * Whether the node has anything for the ports widget to show: a static
10
+ * metadata port, or a config field through which the author adds dynamic ones.
11
+ *
12
+ * Deliberately reads only `metadata` and the schema — never `data.config`.
13
+ * `ConfigForm` drops its in-flight `edits` buffer whenever the effective schema
14
+ * changes identity, so a decision that moved with config values would discard a
15
+ * user's half-typed edit the moment it flipped.
16
+ */
17
+ function hasConfigurablePorts(node, schema) {
18
+ const meta = node.data.metadata;
19
+ if ((meta?.inputs?.length ?? 0) > 0 || (meta?.outputs?.length ?? 0) > 0)
20
+ return true;
21
+ const properties = schema?.properties;
22
+ if (!properties)
23
+ return false;
24
+ return DYNAMIC_PORT_KEYS.some((key) => key in properties);
25
+ }
26
+ /**
27
+ * Append the reserved `ports` property to a node's effective config schema.
28
+ *
29
+ * A no-op when there is no node (the standalone `schema`/`values` mode), when
30
+ * the schema already declares `ports` (a backend that serves the field itself
31
+ * stays authoritative), or when the node has no ports to configure — in which
32
+ * case a schema-less node keeps falling through to the empty state, as it
33
+ * should.
34
+ *
35
+ * @returns The schema to render — `base` untouched, or a copy with the field
36
+ * appended (last, so it renders below the node type's own fields).
37
+ */
38
+ export function withPortsField(base, node) {
39
+ if (!node)
40
+ return base;
41
+ if (base?.properties && PORTS_CONFIG_KEY in base.properties)
42
+ return base;
43
+ if (!hasConfigurablePorts(node, base))
44
+ return base;
45
+ return {
46
+ ...(base ?? { type: 'object', properties: {} }),
47
+ properties: {
48
+ ...(base?.properties ?? {}),
49
+ [PORTS_CONFIG_KEY]: {
50
+ type: 'object',
51
+ // The signal FormField/FormFieldLight match to render <FormPorts>.
52
+ format: 'ports',
53
+ title: 'Ports',
54
+ description: 'Order the node’s ports and choose which ones are exposed.'
55
+ }
56
+ }
57
+ };
58
+ }
59
+ /**
60
+ * Mirror {@link withPortsField} in the UI schema.
61
+ *
62
+ * The UISchema renderer draws only the controls the tree lists, so an injected
63
+ * property is invisible unless a control is added for it. Wraps the authored
64
+ * tree and the new control in a `VerticalLayout`, keeping the author's layout
65
+ * intact and putting the ports control in its own collapsible group below it.
66
+ *
67
+ * @param uiSchema - The authored UI schema, if any. When absent, nothing to do:
68
+ * `ConfigForm` renders the schema's properties flat and picks the field up.
69
+ * @param injected - Whether {@link withPortsField} actually added the property.
70
+ */
71
+ export function withPortsControl(uiSchema, injected) {
72
+ if (!uiSchema || !injected)
73
+ return uiSchema;
74
+ return {
75
+ type: 'VerticalLayout',
76
+ elements: [
77
+ uiSchema,
78
+ {
79
+ type: 'Group',
80
+ label: 'Ports',
81
+ collapsible: true,
82
+ defaultOpen: false,
83
+ elements: [{ type: 'Control', scope: `#/properties/${PORTS_CONFIG_KEY}` }]
84
+ }
85
+ ]
86
+ };
87
+ }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "A drop-in visual workflow editor for any web application. You own the backend. You own the data. You own the orchestration.",
4
4
  "license": "MIT",
5
5
  "private": false,
6
- "version": "2.0.0-beta.10",
6
+ "version": "2.0.0-beta.11",
7
7
  "author": "Shibin Das (D34dMan)",
8
8
  "bugs": {
9
9
  "url": "https://github.com/flowdrop-io/flowdrop/issues"