@flowdrop/flowdrop 2.8.0 → 2.10.0
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 +227 -0
- package/dist/commands/executor.js +52 -8
- package/dist/commands/types.d.ts +3 -0
- package/dist/components/App.svelte +8 -0
- package/dist/components/App.svelte.d.ts +6 -0
- package/dist/components/CanvasContextMenu.stories.svelte +63 -0
- package/dist/components/CanvasContextMenu.stories.svelte.d.ts +19 -0
- package/dist/components/CanvasContextMenu.svelte +259 -0
- package/dist/components/CanvasContextMenu.svelte.d.ts +16 -0
- package/dist/components/CanvasController.svelte +23 -1
- package/dist/components/CanvasController.svelte.d.ts +16 -0
- package/dist/components/UniversalNode.svelte +12 -13
- package/dist/components/WorkflowEditor.svelte +364 -27
- package/dist/components/WorkflowEditor.svelte.d.ts +7 -0
- package/dist/components/WorkflowInterfaceEditor.svelte +28 -3
- package/dist/components/WorkflowInterfaceEntryCard.svelte +112 -2
- package/dist/components/WorkflowInterfaceEntryCard.svelte.d.ts +3 -1
- package/dist/components/form/FieldFactory.svelte +478 -0
- package/dist/components/form/FieldFactory.svelte.d.ts +14 -0
- package/dist/components/form/FormField.svelte +19 -404
- package/dist/components/form/FormField.svelte.d.ts +2 -27
- package/dist/components/form/FormFieldLight.svelte +11 -424
- package/dist/components/form/FormFieldLight.svelte.d.ts +2 -28
- package/dist/components/form/FormMarkdownEditor.svelte +11 -4
- package/dist/components/form/FormTemplateEditor.svelte +12 -5
- package/dist/components/form/resolveFieldType.d.ts +18 -15
- package/dist/components/form/resolveFieldType.js +33 -12
- package/dist/components/form/types.d.ts +14 -2
- package/dist/components/nodes/CaptionNode.stories.svelte +65 -0
- package/dist/components/nodes/CaptionNode.stories.svelte.d.ts +18 -0
- package/dist/components/nodes/CaptionNode.svelte +313 -0
- package/dist/components/nodes/CaptionNode.svelte.d.ts +16 -0
- package/dist/components/nodes/NotesNode.svelte +6 -0
- package/dist/components/playground/ChatBubble.svelte +2 -0
- package/dist/components/playground/ChatInput.svelte +18 -34
- package/dist/components/playground/ChatInput.svelte.d.ts +7 -0
- package/dist/components/playground/ControlPanel.svelte +27 -0
- package/dist/components/playground/ControlPanel.svelte.d.ts +12 -0
- package/dist/components/playground/ExecutionLogs.svelte +11 -8
- package/dist/components/playground/InterfaceInputForm.svelte +74 -0
- package/dist/components/playground/InterfaceInputForm.svelte.d.ts +14 -0
- package/dist/components/playground/LogRow.svelte +2 -0
- package/dist/components/playground/MessageCard.svelte +15 -3
- package/dist/components/playground/MessageNotice.svelte +2 -0
- package/dist/components/playground/MessageStream.svelte +87 -23
- package/dist/components/playground/OriginBadge.svelte +48 -0
- package/dist/components/playground/OriginBadge.svelte.d.ts +7 -0
- package/dist/components/playground/Playground.svelte +155 -38
- package/dist/components/playground/messageDisplay.d.ts +23 -1
- package/dist/components/playground/messageDisplay.js +49 -0
- package/dist/config/endpoints.d.ts +65 -0
- package/dist/config/endpoints.js +39 -0
- package/dist/core/index.d.ts +6 -3
- package/dist/core/index.js +2 -1
- package/dist/editor/contextMenu.d.ts +107 -0
- package/dist/editor/contextMenu.js +134 -0
- package/dist/editor/index.d.ts +2 -0
- package/dist/editor/index.js +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/messages/defaults.d.ts +63 -0
- package/dist/messages/defaults.js +59 -0
- package/dist/openapi/v1/openapi.yaml +356 -7
- package/dist/playground/commands/registry.js +4 -2
- package/dist/playground/index.d.ts +3 -2
- package/dist/playground/index.js +2 -1
- package/dist/registry/builtinNodeTypes.d.ts +1 -1
- package/dist/registry/builtinNodeTypes.js +1 -0
- package/dist/registry/builtinNodes.js +13 -0
- package/dist/registry/nodeComponentRegistry.d.ts +18 -0
- package/dist/registry/nodeComponentRegistry.js +14 -2
- package/dist/schemas/v1/workflow.schema.json +22 -1
- package/dist/services/historyService.d.ts +1 -1
- package/dist/services/historyService.js +2 -2
- package/dist/services/playgroundService.d.ts +35 -1
- package/dist/services/playgroundService.js +82 -36
- package/dist/stores/inlineEditStore.svelte.d.ts +35 -0
- package/dist/stores/inlineEditStore.svelte.js +63 -0
- package/dist/stores/instanceContainer.svelte.d.ts +6 -0
- package/dist/stores/instanceContainer.svelte.js +2 -0
- package/dist/stores/playgroundStore.svelte.d.ts +59 -2
- package/dist/stores/playgroundStore.svelte.js +128 -2
- package/dist/styles/base.css +8 -0
- package/dist/styles/tokens.css +8 -0
- package/dist/svelte-app.d.ts +15 -0
- package/dist/svelte-app.js +6 -4
- package/dist/types/index.d.ts +34 -1
- package/dist/types/index.js +11 -0
- package/dist/types/playground.d.ts +90 -9
- package/dist/types/playground.js +12 -4
- package/dist/utils/captionText.d.ts +43 -0
- package/dist/utils/captionText.js +49 -0
- package/dist/utils/focus.d.ts +16 -0
- package/dist/utils/focus.js +40 -0
- package/dist/utils/nodeTypes.js +1 -0
- package/dist/utils/nodeWrapper.js +2 -0
- package/dist/utils/workflowInterface.d.ts +83 -1
- package/dist/utils/workflowInterface.js +192 -1
- package/package.json +1 -1
package/dist/utils/focus.d.ts
CHANGED
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
* `$effect` over a `bind:this` because focusing is a fact about the element's
|
|
8
8
|
* arrival, not about state: it runs once when the node mounts and never again.
|
|
9
9
|
*
|
|
10
|
+
* `{@attach focusWhenVisible()}` is the same for an element inside a canvas
|
|
11
|
+
* node, which xyflow keeps `visibility: hidden` until it has measured it.
|
|
12
|
+
*
|
|
10
13
|
* @module utils/focus
|
|
11
14
|
*/
|
|
12
15
|
import type { Attachment } from 'svelte/attachments';
|
|
@@ -16,3 +19,16 @@ import type { Attachment } from 'svelte/attachments';
|
|
|
16
19
|
* host and not in another).
|
|
17
20
|
*/
|
|
18
21
|
export declare function focusOnMount(enabled?: boolean): Attachment<HTMLElement>;
|
|
22
|
+
/**
|
|
23
|
+
* Focus the element as soon as it can take focus, for an element that mounts
|
|
24
|
+
* inside an xyflow node. xyflow renders the node wrapper
|
|
25
|
+
* (`.svelte-flow__node`) with an inline `visibility: hidden` until the node
|
|
26
|
+
* has dimensions, and a hidden element cannot be focused, so a node that was
|
|
27
|
+
* just added to the canvas cannot take focus on mount. If the element is
|
|
28
|
+
* already visible it is focused at once; otherwise the wrapper's `style` is
|
|
29
|
+
* watched and the element is focused when the visibility flips. The observer
|
|
30
|
+
* goes away on success and on cleanup.
|
|
31
|
+
*
|
|
32
|
+
* @param onFocused - runs after the element took focus (e.g. to select its text)
|
|
33
|
+
*/
|
|
34
|
+
export declare function focusWhenVisible(onFocused?: (element: HTMLElement) => void): Attachment<HTMLElement>;
|
package/dist/utils/focus.js
CHANGED
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
* `$effect` over a `bind:this` because focusing is a fact about the element's
|
|
8
8
|
* arrival, not about state: it runs once when the node mounts and never again.
|
|
9
9
|
*
|
|
10
|
+
* `{@attach focusWhenVisible()}` is the same for an element inside a canvas
|
|
11
|
+
* node, which xyflow keeps `visibility: hidden` until it has measured it.
|
|
12
|
+
*
|
|
10
13
|
* @module utils/focus
|
|
11
14
|
*/
|
|
12
15
|
const noop = () => { };
|
|
@@ -22,3 +25,40 @@ export function focusOnMount(enabled = true) {
|
|
|
22
25
|
element.focus();
|
|
23
26
|
};
|
|
24
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Focus the element as soon as it can take focus, for an element that mounts
|
|
30
|
+
* inside an xyflow node. xyflow renders the node wrapper
|
|
31
|
+
* (`.svelte-flow__node`) with an inline `visibility: hidden` until the node
|
|
32
|
+
* has dimensions, and a hidden element cannot be focused, so a node that was
|
|
33
|
+
* just added to the canvas cannot take focus on mount. If the element is
|
|
34
|
+
* already visible it is focused at once; otherwise the wrapper's `style` is
|
|
35
|
+
* watched and the element is focused when the visibility flips. The observer
|
|
36
|
+
* goes away on success and on cleanup.
|
|
37
|
+
*
|
|
38
|
+
* @param onFocused - runs after the element took focus (e.g. to select its text)
|
|
39
|
+
*/
|
|
40
|
+
export function focusWhenVisible(onFocused) {
|
|
41
|
+
return (element) => {
|
|
42
|
+
function tryFocus() {
|
|
43
|
+
// Visibility is inherited, so the element's own computed value covers the wrapper's.
|
|
44
|
+
if (getComputedStyle(element).visibility === 'hidden')
|
|
45
|
+
return false;
|
|
46
|
+
element.focus({ preventScroll: true });
|
|
47
|
+
if (document.activeElement !== element)
|
|
48
|
+
return false;
|
|
49
|
+
onFocused?.(element);
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
if (tryFocus())
|
|
53
|
+
return;
|
|
54
|
+
const wrapper = element.closest('.svelte-flow__node');
|
|
55
|
+
if (!wrapper)
|
|
56
|
+
return;
|
|
57
|
+
const observer = new MutationObserver(() => {
|
|
58
|
+
if (tryFocus())
|
|
59
|
+
observer.disconnect();
|
|
60
|
+
});
|
|
61
|
+
observer.observe(wrapper, { attributes: true, attributeFilter: ['style', 'class'] });
|
|
62
|
+
return () => observer.disconnect();
|
|
63
|
+
};
|
|
64
|
+
}
|
package/dist/utils/nodeTypes.js
CHANGED
|
@@ -15,6 +15,7 @@ import { resolveBuiltinAlias, isBuiltinType } from '../registry/builtinNodeTypes
|
|
|
15
15
|
*/
|
|
16
16
|
const TYPE_DISPLAY_NAMES = {
|
|
17
17
|
note: 'Note (sticky note style)',
|
|
18
|
+
caption: 'Caption (short label text)',
|
|
18
19
|
simple: 'Simple (compact layout)',
|
|
19
20
|
square: 'Square (geometric layout)',
|
|
20
21
|
atom: 'Atom (minimal value/transform)',
|
|
@@ -38,6 +38,7 @@ export function getOptimalStatusPosition(nodeType) {
|
|
|
38
38
|
case 'tool':
|
|
39
39
|
return 'top-left';
|
|
40
40
|
case 'note':
|
|
41
|
+
case 'caption':
|
|
41
42
|
return 'bottom-right';
|
|
42
43
|
case 'simple':
|
|
43
44
|
case 'square':
|
|
@@ -53,6 +54,7 @@ export function getOptimalStatusSize(nodeType) {
|
|
|
53
54
|
case 'tool':
|
|
54
55
|
return 'sm';
|
|
55
56
|
case 'note':
|
|
57
|
+
case 'caption':
|
|
56
58
|
return 'sm';
|
|
57
59
|
case 'simple':
|
|
58
60
|
case 'square':
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
*
|
|
13
13
|
* @module utils/workflowInterface
|
|
14
14
|
*/
|
|
15
|
-
import type { NodePort, PortBinding, Workflow, WorkflowInterface, WorkflowInterfaceEntry, WorkflowNode } from '../types/index.js';
|
|
15
|
+
import type { ConfigSchema, NodePort, PortBinding, Workflow, WorkflowInterface, WorkflowInterfaceEntry, WorkflowInterfaceTurn, WorkflowNode } from '../types/index.js';
|
|
16
16
|
import type { PortMapping } from './nodeSwap.js';
|
|
17
17
|
/**
|
|
18
18
|
* A binding resolved against the live node graph: the node and port it
|
|
@@ -250,3 +250,85 @@ export declare function rankBindablePorts(workflow: Workflow, direction: 'input'
|
|
|
250
250
|
* names — is about that ongoing coupling, which this does not introduce.
|
|
251
251
|
*/
|
|
252
252
|
export declare function entryFromBindablePort(candidate: BindablePort, existingIds: Iterable<string>): WorkflowInterfaceEntry;
|
|
253
|
+
/** The turn values an entry of this direction may carry, in selector order. */
|
|
254
|
+
export declare function turnsFor(direction: 'input' | 'output'): readonly WorkflowInterfaceTurn[];
|
|
255
|
+
/** Whether a value is in this library's turn vocabulary (either direction). */
|
|
256
|
+
export declare function isKnownTurn(value: string): value is WorkflowInterfaceTurn;
|
|
257
|
+
/**
|
|
258
|
+
* The id of the first OTHER input entry already carrying `entry`'s turn
|
|
259
|
+
* value, or `undefined`. Every input turn is at most one per workflow; the
|
|
260
|
+
* first entry in list order keeps the value, later ones are reported. Only
|
|
261
|
+
* meaningful for inputs — `reply` on outputs is unbounded.
|
|
262
|
+
*/
|
|
263
|
+
export declare function turnTakenBy(inputs: readonly WorkflowInterfaceEntry[], entry: WorkflowInterfaceEntry): string | undefined;
|
|
264
|
+
/**
|
|
265
|
+
* The patch that sets (or with `''` clears) an entry's turn. Never writes a
|
|
266
|
+
* `turn` key for "none" (the key is set to `undefined`, which the editor's
|
|
267
|
+
* commit drops), and drops `meta.limit` when the entry stops being `history`
|
|
268
|
+
* — leaving every other `meta` key, and `meta` itself when others remain,
|
|
269
|
+
* untouched.
|
|
270
|
+
*/
|
|
271
|
+
export declare function turnPatch(entry: WorkflowInterfaceEntry, next: WorkflowInterfaceEntry['turn'] | ''): Partial<WorkflowInterfaceEntry>;
|
|
272
|
+
/**
|
|
273
|
+
* The patch that sets a `history` entry's `meta.limit` from a raw field
|
|
274
|
+
* value. Empty, non-numeric or non-positive input removes the key, so the
|
|
275
|
+
* server's default applies; other `meta` keys are kept.
|
|
276
|
+
*/
|
|
277
|
+
export declare function historyLimitPatch(entry: WorkflowInterfaceEntry, raw: string): Partial<WorkflowInterfaceEntry>;
|
|
278
|
+
/** The `meta.limit` a history entry states, when it is a positive integer. */
|
|
279
|
+
export declare function historyLimitOf(entry: WorkflowInterfaceEntry): number | undefined;
|
|
280
|
+
/**
|
|
281
|
+
* How the Playground collects a turn, read from the workflow interface.
|
|
282
|
+
*
|
|
283
|
+
* - `chat`: an input carries `turn: message`. The chat box sends `content`;
|
|
284
|
+
* any other non-turn inputs render as a form beside it.
|
|
285
|
+
* - `form`: the interface declares turn ports but no `message` input, and has
|
|
286
|
+
* non-turn inputs. A form and a Run button; the turn sends `inputs` only
|
|
287
|
+
* (the server refuses `content` for such a workflow).
|
|
288
|
+
* - `run`: the interface declares turn ports, no `message` input and no
|
|
289
|
+
* non-turn input. Just a Run button.
|
|
290
|
+
* - `legacy`: the interface is absent or declares no `turn` on any entry.
|
|
291
|
+
* The server falls back to guessing the chat input from the nodes
|
|
292
|
+
* (deprecated, until FlowDrop 3.0), so the Playground keeps its old
|
|
293
|
+
* behaviour too. Also what every server that predates turn ports gets.
|
|
294
|
+
*/
|
|
295
|
+
export type PlaygroundInputMode = 'chat' | 'form' | 'run' | 'legacy';
|
|
296
|
+
/** Whether any entry of the interface, on either side, declares a `turn`. */
|
|
297
|
+
export declare function declaresTurnPorts(workflowInterface: WorkflowInterface | undefined): boolean;
|
|
298
|
+
/**
|
|
299
|
+
* The input entries a person fills in: every input without a `turn`. Turn
|
|
300
|
+
* inputs (`message`, `history`, `session_id`, `message_id`, and any value a
|
|
301
|
+
* newer server adds) are filled by the session, never by the form.
|
|
302
|
+
*/
|
|
303
|
+
export declare function interfaceFormEntries(workflowInterface: WorkflowInterface | undefined): WorkflowInterfaceEntry[];
|
|
304
|
+
/** Resolve the Playground's input mode from a workflow interface. */
|
|
305
|
+
export declare function resolvePlaygroundInputMode(workflowInterface: WorkflowInterface | undefined): PlaygroundInputMode;
|
|
306
|
+
/**
|
|
307
|
+
* The object schema a form renders for the given entries: one property per
|
|
308
|
+
* entry, keyed by its `id` (the name the server matches inputs on). The
|
|
309
|
+
* entry's own schema fragment wins over what the entry states one level up;
|
|
310
|
+
* the type falls back to the entry's `dataType` lane.
|
|
311
|
+
*/
|
|
312
|
+
export declare function interfaceFormSchema(entries: readonly WorkflowInterfaceEntry[]): ConfigSchema;
|
|
313
|
+
/**
|
|
314
|
+
* The inputs a form turn sends: the values of the given entries, without
|
|
315
|
+
* blank optional values (an empty string or `undefined` is "not given", so
|
|
316
|
+
* the server's default applies). Keys outside the entries are dropped.
|
|
317
|
+
*/
|
|
318
|
+
export declare function interfaceFormInputs(entries: readonly WorkflowInterfaceEntry[], values: Record<string, unknown>): Record<string, unknown>;
|
|
319
|
+
/** What {@link collectInterfaceInputs} found. */
|
|
320
|
+
export type InterfaceInputsResult = {
|
|
321
|
+
ok: true;
|
|
322
|
+
inputs: Record<string, unknown>;
|
|
323
|
+
} | {
|
|
324
|
+
ok: false;
|
|
325
|
+
missing: WorkflowInterfaceEntry[];
|
|
326
|
+
};
|
|
327
|
+
/**
|
|
328
|
+
* The inputs a form turn would send, or the required entries that are still
|
|
329
|
+
* blank. An entry is missing when it is required, has no default for the
|
|
330
|
+
* server to fall back on, and has no value (see {@link interfaceFormInputs}
|
|
331
|
+
* for what counts as blank). Missing inputs are data, not an exception, so
|
|
332
|
+
* a Run control can open the form instead of failing.
|
|
333
|
+
*/
|
|
334
|
+
export declare function collectInterfaceInputs(entries: readonly WorkflowInterfaceEntry[], values: Record<string, unknown>): InterfaceInputsResult;
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
*
|
|
13
13
|
* @module utils/workflowInterface
|
|
14
14
|
*/
|
|
15
|
-
import { dynamicPortToNodePort } from '../types/index.js';
|
|
15
|
+
import { dynamicPortToNodePort, WORKFLOW_INTERFACE_INPUT_TURNS, WORKFLOW_INTERFACE_OUTPUT_TURNS } from '../types/index.js';
|
|
16
16
|
import { isPortExposed } from './portUtils.js';
|
|
17
17
|
import { LOOPBACK_PORT_NAME } from './connections.js';
|
|
18
18
|
import { PORTS_CONFIG_KEY } from './nodeFormSchema.js';
|
|
@@ -174,6 +174,34 @@ export function validateWorkflowInterface(workflow) {
|
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
176
|
}
|
|
177
|
+
for (const entry of workflow.interface.inputs ?? []) {
|
|
178
|
+
const otherId = turnTakenBy(workflow.interface.inputs ?? [], entry);
|
|
179
|
+
if (otherId !== undefined) {
|
|
180
|
+
issues.push({
|
|
181
|
+
entryId: entry.id,
|
|
182
|
+
direction: 'input',
|
|
183
|
+
severity: 'warning',
|
|
184
|
+
code: 'interface-turn-duplicate',
|
|
185
|
+
message: `Interface input "${entry.id}" has chat turn "${entry.turn}", which input "${otherId}" already has; a workflow takes at most one input per turn value.`
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
for (const direction of ['input', 'output']) {
|
|
190
|
+
const entries = (direction === 'input' ? workflow.interface.inputs : workflow.interface.outputs) ?? [];
|
|
191
|
+
for (const entry of entries) {
|
|
192
|
+
if (entry.turn !== undefined &&
|
|
193
|
+
isKnownTurn(entry.turn) &&
|
|
194
|
+
!turnsFor(direction).includes(entry.turn)) {
|
|
195
|
+
issues.push({
|
|
196
|
+
entryId: entry.id,
|
|
197
|
+
direction,
|
|
198
|
+
severity: 'warning',
|
|
199
|
+
code: 'interface-turn-direction',
|
|
200
|
+
message: `Interface ${direction} "${entry.id}" has chat turn "${entry.turn}", which only applies to ${direction === 'input' ? 'outputs' : 'inputs'}.`
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
177
205
|
for (const direction of ['input', 'output']) {
|
|
178
206
|
const entries = (direction === 'input' ? workflow.interface.inputs : workflow.interface.outputs) ?? [];
|
|
179
207
|
const seenCounts = new Map();
|
|
@@ -464,3 +492,166 @@ export function entryFromBindablePort(candidate, existingIds) {
|
|
|
464
492
|
...pullEntryFieldsFromPort(candidate.port)
|
|
465
493
|
};
|
|
466
494
|
}
|
|
495
|
+
// ---------------------------------------------------------------------------
|
|
496
|
+
// Chat turn ports
|
|
497
|
+
// ---------------------------------------------------------------------------
|
|
498
|
+
/** The turn values an entry of this direction may carry, in selector order. */
|
|
499
|
+
export function turnsFor(direction) {
|
|
500
|
+
return direction === 'input' ? WORKFLOW_INTERFACE_INPUT_TURNS : WORKFLOW_INTERFACE_OUTPUT_TURNS;
|
|
501
|
+
}
|
|
502
|
+
/** Whether a value is in this library's turn vocabulary (either direction). */
|
|
503
|
+
export function isKnownTurn(value) {
|
|
504
|
+
return (WORKFLOW_INTERFACE_INPUT_TURNS.includes(value) ||
|
|
505
|
+
WORKFLOW_INTERFACE_OUTPUT_TURNS.includes(value));
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* The id of the first OTHER input entry already carrying `entry`'s turn
|
|
509
|
+
* value, or `undefined`. Every input turn is at most one per workflow; the
|
|
510
|
+
* first entry in list order keeps the value, later ones are reported. Only
|
|
511
|
+
* meaningful for inputs — `reply` on outputs is unbounded.
|
|
512
|
+
*/
|
|
513
|
+
export function turnTakenBy(inputs, entry) {
|
|
514
|
+
if (entry.turn === undefined)
|
|
515
|
+
return undefined;
|
|
516
|
+
const index = inputs.indexOf(entry);
|
|
517
|
+
const first = inputs.findIndex((other) => other.turn === entry.turn);
|
|
518
|
+
if (first === -1 || first === index || index === -1)
|
|
519
|
+
return undefined;
|
|
520
|
+
return inputs[first].id;
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* The patch that sets (or with `''` clears) an entry's turn. Never writes a
|
|
524
|
+
* `turn` key for "none" (the key is set to `undefined`, which the editor's
|
|
525
|
+
* commit drops), and drops `meta.limit` when the entry stops being `history`
|
|
526
|
+
* — leaving every other `meta` key, and `meta` itself when others remain,
|
|
527
|
+
* untouched.
|
|
528
|
+
*/
|
|
529
|
+
export function turnPatch(entry, next) {
|
|
530
|
+
const patch = { turn: next === '' ? undefined : next };
|
|
531
|
+
if (next !== 'history' && entry.meta && 'limit' in entry.meta) {
|
|
532
|
+
patch.meta = metaWithLimit(entry.meta, undefined);
|
|
533
|
+
}
|
|
534
|
+
return patch;
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* The patch that sets a `history` entry's `meta.limit` from a raw field
|
|
538
|
+
* value. Empty, non-numeric or non-positive input removes the key, so the
|
|
539
|
+
* server's default applies; other `meta` keys are kept.
|
|
540
|
+
*/
|
|
541
|
+
export function historyLimitPatch(entry, raw) {
|
|
542
|
+
const parsed = Number(raw);
|
|
543
|
+
const limit = raw.trim() !== '' && Number.isInteger(parsed) && parsed > 0 ? parsed : undefined;
|
|
544
|
+
return { meta: metaWithLimit(entry.meta, limit) };
|
|
545
|
+
}
|
|
546
|
+
/** The `meta.limit` a history entry states, when it is a positive integer. */
|
|
547
|
+
export function historyLimitOf(entry) {
|
|
548
|
+
const limit = entry.meta?.limit;
|
|
549
|
+
return typeof limit === 'number' && Number.isInteger(limit) && limit > 0 ? limit : undefined;
|
|
550
|
+
}
|
|
551
|
+
function metaWithLimit(meta, limit) {
|
|
552
|
+
const next = { ...(meta ?? {}) };
|
|
553
|
+
if (limit === undefined)
|
|
554
|
+
delete next.limit;
|
|
555
|
+
else
|
|
556
|
+
next.limit = limit;
|
|
557
|
+
return Object.keys(next).length > 0 ? next : undefined;
|
|
558
|
+
}
|
|
559
|
+
/** Whether any entry of the interface, on either side, declares a `turn`. */
|
|
560
|
+
export function declaresTurnPorts(workflowInterface) {
|
|
561
|
+
const entries = [...(workflowInterface?.inputs ?? []), ...(workflowInterface?.outputs ?? [])];
|
|
562
|
+
return entries.some((entry) => Boolean(entry.turn));
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* The input entries a person fills in: every input without a `turn`. Turn
|
|
566
|
+
* inputs (`message`, `history`, `session_id`, `message_id`, and any value a
|
|
567
|
+
* newer server adds) are filled by the session, never by the form.
|
|
568
|
+
*/
|
|
569
|
+
export function interfaceFormEntries(workflowInterface) {
|
|
570
|
+
return (workflowInterface?.inputs ?? []).filter((entry) => !entry.turn);
|
|
571
|
+
}
|
|
572
|
+
/** Resolve the Playground's input mode from a workflow interface. */
|
|
573
|
+
export function resolvePlaygroundInputMode(workflowInterface) {
|
|
574
|
+
if (!declaresTurnPorts(workflowInterface))
|
|
575
|
+
return 'legacy';
|
|
576
|
+
if ((workflowInterface?.inputs ?? []).some((entry) => entry.turn === 'message'))
|
|
577
|
+
return 'chat';
|
|
578
|
+
return interfaceFormEntries(workflowInterface).length > 0 ? 'form' : 'run';
|
|
579
|
+
}
|
|
580
|
+
/** JSON Schema `type` for an interface entry's lane, when its schema states none. */
|
|
581
|
+
function formFieldType(dataType) {
|
|
582
|
+
const lane = dataType.toLowerCase();
|
|
583
|
+
if (lane === 'number' || lane === 'float')
|
|
584
|
+
return 'number';
|
|
585
|
+
if (lane === 'integer')
|
|
586
|
+
return 'integer';
|
|
587
|
+
if (lane === 'boolean')
|
|
588
|
+
return 'boolean';
|
|
589
|
+
if (lane === 'array' || lane === 'messages' || lane.endsWith('[]'))
|
|
590
|
+
return 'array';
|
|
591
|
+
if (lane === 'json' || lane === 'object')
|
|
592
|
+
return 'object';
|
|
593
|
+
return 'string';
|
|
594
|
+
}
|
|
595
|
+
const FORM_FIELD_TYPES = [
|
|
596
|
+
'string',
|
|
597
|
+
'number',
|
|
598
|
+
'boolean',
|
|
599
|
+
'array',
|
|
600
|
+
'object',
|
|
601
|
+
'integer'
|
|
602
|
+
];
|
|
603
|
+
/**
|
|
604
|
+
* The object schema a form renders for the given entries: one property per
|
|
605
|
+
* entry, keyed by its `id` (the name the server matches inputs on). The
|
|
606
|
+
* entry's own schema fragment wins over what the entry states one level up;
|
|
607
|
+
* the type falls back to the entry's `dataType` lane.
|
|
608
|
+
*/
|
|
609
|
+
export function interfaceFormSchema(entries) {
|
|
610
|
+
const properties = {};
|
|
611
|
+
const required = [];
|
|
612
|
+
for (const entry of entries) {
|
|
613
|
+
const fragment = (entry.schema ?? {});
|
|
614
|
+
const fragmentType = typeof fragment.type === 'string' ? fragment.type : undefined;
|
|
615
|
+
const type = fragmentType && FORM_FIELD_TYPES.includes(fragmentType)
|
|
616
|
+
? fragmentType
|
|
617
|
+
: formFieldType(entry.dataType);
|
|
618
|
+
const property = { ...fragment, type, title: entry.name ?? entry.id };
|
|
619
|
+
if (entry.description !== undefined)
|
|
620
|
+
property.description = entry.description;
|
|
621
|
+
if (entry.defaultValue !== undefined)
|
|
622
|
+
property.default = entry.defaultValue;
|
|
623
|
+
properties[entry.id] = property;
|
|
624
|
+
if (entry.required)
|
|
625
|
+
required.push(entry.id);
|
|
626
|
+
}
|
|
627
|
+
return required.length > 0
|
|
628
|
+
? { type: 'object', properties, required }
|
|
629
|
+
: { type: 'object', properties };
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* The inputs a form turn sends: the values of the given entries, without
|
|
633
|
+
* blank optional values (an empty string or `undefined` is "not given", so
|
|
634
|
+
* the server's default applies). Keys outside the entries are dropped.
|
|
635
|
+
*/
|
|
636
|
+
export function interfaceFormInputs(entries, values) {
|
|
637
|
+
const inputs = {};
|
|
638
|
+
for (const entry of entries) {
|
|
639
|
+
const value = values[entry.id];
|
|
640
|
+
if (value === undefined || value === '')
|
|
641
|
+
continue;
|
|
642
|
+
inputs[entry.id] = value;
|
|
643
|
+
}
|
|
644
|
+
return inputs;
|
|
645
|
+
}
|
|
646
|
+
/**
|
|
647
|
+
* The inputs a form turn would send, or the required entries that are still
|
|
648
|
+
* blank. An entry is missing when it is required, has no default for the
|
|
649
|
+
* server to fall back on, and has no value (see {@link interfaceFormInputs}
|
|
650
|
+
* for what counts as blank). Missing inputs are data, not an exception, so
|
|
651
|
+
* a Run control can open the form instead of failing.
|
|
652
|
+
*/
|
|
653
|
+
export function collectInterfaceInputs(entries, values) {
|
|
654
|
+
const inputs = interfaceFormInputs(entries, values);
|
|
655
|
+
const missing = entries.filter((entry) => entry.required && entry.defaultValue === undefined && !(entry.id in inputs));
|
|
656
|
+
return missing.length > 0 ? { ok: false, missing } : { ok: true, inputs };
|
|
657
|
+
}
|
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.
|
|
6
|
+
"version": "2.10.0",
|
|
7
7
|
"author": "Shibin Das (D34dMan)",
|
|
8
8
|
"bugs": {
|
|
9
9
|
"url": "https://github.com/flowdrop-io/flowdrop/issues"
|