@flowdrop/flowdrop 2.10.1 → 2.11.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 +162 -0
- package/dist/components/App.svelte +112 -29
- package/dist/components/ConfigForm.svelte +5 -5
- package/dist/components/ConfigModal.svelte +2 -2
- package/dist/components/ConfigModal.svelte.d.ts +1 -1
- package/dist/components/ConnectionLine.svelte +1 -1
- package/dist/components/LogsSidebar.svelte +15 -12
- package/dist/components/MarkdownDisplay.svelte +1 -1
- package/dist/components/PipelineStatus.svelte +5 -18
- package/dist/components/SchemaForm.svelte +1 -1
- package/dist/components/SettingsModal.svelte +1 -1
- package/dist/components/SettingsPanel.svelte +1 -1
- package/dist/components/WorkflowEditor.svelte +63 -37
- package/dist/components/WorkflowInterfaceEditor.svelte +43 -8
- package/dist/components/WorkflowInterfaceEditor.svelte.d.ts +12 -1
- package/dist/components/WorkflowInterfaceEntryCard.svelte +117 -44
- package/dist/components/WorkflowInterfaceEntryCard.svelte.d.ts +14 -1
- package/dist/components/WorkflowPlaygroundSettings.svelte +551 -0
- package/dist/components/WorkflowPlaygroundSettings.svelte.d.ts +20 -0
- package/dist/components/chat/AIChatPanel.svelte +1 -1
- package/dist/components/form/index.d.ts +2 -2
- package/dist/components/form/index.js +2 -2
- package/dist/components/nodes/ToolNode.svelte +1 -1
- package/dist/components/playground/ControlPanel.svelte +30 -0
- package/dist/components/playground/ControlPanel.svelte.d.ts +5 -0
- package/dist/components/playground/Playground.svelte +94 -42
- package/dist/components/playground/PlaygroundApp.svelte +1 -1
- package/dist/components/playground/PlaygroundModal.svelte +1 -1
- package/dist/components/playground/PlaygroundStudio.svelte +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/helpers/workflowEditorHelper.d.ts +12 -0
- package/dist/helpers/workflowEditorHelper.js +31 -0
- package/dist/messages/defaults.d.ts +53 -0
- package/dist/messages/defaults.js +48 -2
- package/dist/openapi/v1/openapi.yaml +113 -5
- package/dist/playground/index.d.ts +3 -1
- package/dist/playground/index.js +2 -1
- package/dist/playground/mount.d.ts +6 -10
- package/dist/playground/mount.js +43 -24
- package/dist/schemas/index.js +1 -1
- package/dist/schemas/v1/workflow.schema.json +140 -2
- package/dist/services/globalSave.js +11 -1
- package/dist/services/playgroundService.d.ts +6 -1
- package/dist/services/playgroundService.js +5 -0
- package/dist/skins/default.d.ts +1 -1
- package/dist/skins/drafter.d.ts +1 -1
- package/dist/skins/index.d.ts +4 -4
- package/dist/skins/index.js +3 -3
- package/dist/skins/slate.d.ts +1 -1
- package/dist/stores/instanceContainer.svelte.d.ts +15 -0
- package/dist/stores/instanceContainer.svelte.js +11 -1
- package/dist/stores/playgroundStore.svelte.d.ts +8 -0
- package/dist/stores/playgroundStore.svelte.js +18 -4
- package/dist/stores/workflowStore.svelte.d.ts +4 -1
- package/dist/stores/workflowStore.svelte.js +8 -1
- package/dist/styles/base.css +14 -3
- package/dist/styles/tokenAliases.d.ts +13 -0
- package/dist/styles/tokenAliases.js +89 -0
- package/dist/themes/scopedSkinCss.d.ts +30 -0
- package/dist/themes/scopedSkinCss.js +95 -0
- package/dist/types/index.d.ts +86 -4
- package/dist/types/index.js +15 -3
- package/dist/types/skin.d.ts +2 -2
- package/dist/utils/playgroundChat.d.ts +121 -0
- package/dist/utils/playgroundChat.js +275 -0
- package/dist/utils/portal.d.ts +8 -0
- package/dist/utils/portal.js +15 -0
- package/dist/utils/workflowInterface.d.ts +88 -20
- package/dist/utils/workflowInterface.js +179 -18
- package/dist/webmcp/WebMCPConfirm.svelte +68 -18
- package/dist/webmcp/gate.d.ts +6 -0
- package/dist/webmcp/gate.js +4 -0
- package/dist/webmcp/runtime.js +2 -1
- package/package.json +7 -6
- package/dist/components/Button.stories.svelte +0 -65
- package/dist/components/Button.stories.svelte.d.ts +0 -19
- package/dist/components/CanvasBanner.stories.svelte +0 -30
- package/dist/components/CanvasBanner.stories.svelte.d.ts +0 -27
- package/dist/components/CanvasContextMenu.stories.svelte +0 -63
- package/dist/components/CanvasContextMenu.stories.svelte.d.ts +0 -19
- package/dist/components/ConfigPanel.stories.svelte +0 -47
- package/dist/components/ConfigPanel.stories.svelte.d.ts +0 -27
- package/dist/components/EditorStatusBar.stories.svelte +0 -44
- package/dist/components/EditorStatusBar.stories.svelte.d.ts +0 -27
- package/dist/components/FlowDropEdge.stories.svelte +0 -197
- package/dist/components/FlowDropEdge.stories.svelte.d.ts +0 -26
- package/dist/components/LoadingSpinner.stories.svelte +0 -30
- package/dist/components/LoadingSpinner.stories.svelte.d.ts +0 -27
- package/dist/components/Logo.stories.svelte +0 -22
- package/dist/components/Logo.stories.svelte.d.ts +0 -27
- package/dist/components/MarkdownDisplay.stories.svelte +0 -38
- package/dist/components/MarkdownDisplay.stories.svelte.d.ts +0 -27
- package/dist/components/Navbar.stories.svelte +0 -58
- package/dist/components/Navbar.stories.svelte.d.ts +0 -27
- package/dist/components/NodeStatusOverlay.stories.svelte +0 -85
- package/dist/components/NodeStatusOverlay.stories.svelte.d.ts +0 -27
- package/dist/components/SchemaForm.stories.svelte +0 -122
- package/dist/components/SchemaForm.stories.svelte.d.ts +0 -27
- package/dist/components/StatusIcon.stories.svelte +0 -60
- package/dist/components/StatusIcon.stories.svelte.d.ts +0 -27
- package/dist/components/StatusLabel.stories.svelte +0 -17
- package/dist/components/StatusLabel.stories.svelte.d.ts +0 -27
- package/dist/components/ThemeToggle.stories.svelte +0 -25
- package/dist/components/ThemeToggle.stories.svelte.d.ts +0 -27
- package/dist/components/console/CommandConsole.stories.svelte +0 -111
- package/dist/components/console/CommandConsole.stories.svelte.d.ts +0 -27
- package/dist/components/form/FormCheckboxGroup.stories.svelte +0 -28
- package/dist/components/form/FormCheckboxGroup.stories.svelte.d.ts +0 -27
- package/dist/components/form/FormFieldWrapper.stories.svelte +0 -53
- package/dist/components/form/FormFieldWrapper.stories.svelte.d.ts +0 -27
- package/dist/components/form/FormNumberField.stories.svelte +0 -36
- package/dist/components/form/FormNumberField.stories.svelte.d.ts +0 -27
- package/dist/components/form/FormRangeField.stories.svelte +0 -31
- package/dist/components/form/FormRangeField.stories.svelte.d.ts +0 -27
- package/dist/components/form/FormSelect.stories.svelte +0 -50
- package/dist/components/form/FormSelect.stories.svelte.d.ts +0 -27
- package/dist/components/form/FormTextField.stories.svelte +0 -30
- package/dist/components/form/FormTextField.stories.svelte.d.ts +0 -27
- package/dist/components/form/FormTextarea.stories.svelte +0 -34
- package/dist/components/form/FormTextarea.stories.svelte.d.ts +0 -27
- package/dist/components/form/FormToggle.stories.svelte +0 -30
- package/dist/components/form/FormToggle.stories.svelte.d.ts +0 -27
- package/dist/components/interrupt/ChoicePrompt.stories.svelte +0 -68
- package/dist/components/interrupt/ChoicePrompt.stories.svelte.d.ts +0 -27
- package/dist/components/interrupt/ConfirmationPrompt.stories.svelte +0 -71
- package/dist/components/interrupt/ConfirmationPrompt.stories.svelte.d.ts +0 -27
- package/dist/components/interrupt/ReviewPrompt.stories.svelte +0 -77
- package/dist/components/interrupt/ReviewPrompt.stories.svelte.d.ts +0 -27
- package/dist/components/interrupt/TextInputPrompt.stories.svelte +0 -51
- package/dist/components/interrupt/TextInputPrompt.stories.svelte.d.ts +0 -27
- package/dist/components/nodes/CaptionNode.stories.svelte +0 -65
- package/dist/components/nodes/CaptionNode.stories.svelte.d.ts +0 -18
- package/dist/components/nodes/GatewayNode.stories.svelte +0 -108
- package/dist/components/nodes/GatewayNode.stories.svelte.d.ts +0 -26
- package/dist/components/nodes/IdeaNode.stories.svelte +0 -52
- package/dist/components/nodes/IdeaNode.stories.svelte.d.ts +0 -26
- package/dist/components/nodes/NotesNode.stories.svelte +0 -76
- package/dist/components/nodes/NotesNode.stories.svelte.d.ts +0 -26
- package/dist/components/nodes/SimpleNode.stories.svelte +0 -223
- package/dist/components/nodes/SimpleNode.stories.svelte.d.ts +0 -26
- package/dist/components/nodes/SquareNode.stories.svelte +0 -127
- package/dist/components/nodes/SquareNode.stories.svelte.d.ts +0 -26
- package/dist/components/nodes/TerminalNode.stories.svelte +0 -25
- package/dist/components/nodes/TerminalNode.stories.svelte.d.ts +0 -26
- package/dist/components/nodes/ToolNode.stories.svelte +0 -189
- package/dist/components/nodes/ToolNode.stories.svelte.d.ts +0 -26
- package/dist/components/nodes/WorkflowNode.stories.svelte +0 -188
- package/dist/components/nodes/WorkflowNode.stories.svelte.d.ts +0 -26
- package/dist/components/playground/MessageBubble.stories.svelte +0 -151
- package/dist/components/playground/MessageBubble.stories.svelte.d.ts +0 -27
- package/dist/mocks/app-environment.d.ts +0 -8
- package/dist/mocks/app-environment.js +0 -16
- package/dist/mocks/app-forms.d.ts +0 -6
- package/dist/mocks/app-forms.js +0 -29
- package/dist/mocks/app-navigation.d.ts +0 -5
- package/dist/mocks/app-navigation.js +0 -36
- package/dist/mocks/app-stores.d.ts +0 -14
- package/dist/mocks/app-stores.js +0 -26
- package/dist/stories/CanvasDecorator.svelte +0 -49
- package/dist/stories/CanvasDecorator.svelte.d.ts +0 -8
- package/dist/stories/EdgeDecorator.svelte +0 -125
- package/dist/stories/EdgeDecorator.svelte.d.ts +0 -17
- package/dist/stories/NodeDecorator.svelte +0 -75
- package/dist/stories/NodeDecorator.svelte.d.ts +0 -8
- package/dist/stories/WebMCPFakeAgent.svelte +0 -229
- package/dist/stories/WebMCPFakeAgent.svelte.d.ts +0 -10
- package/dist/stories/utils.d.ts +0 -93
- package/dist/stories/utils.js +0 -156
- package/dist/webmcp/WebMCP.stories.svelte +0 -101
- package/dist/webmcp/WebMCP.stories.svelte.d.ts +0 -18
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A workflow's chat binding (its Playground settings).
|
|
3
|
+
*
|
|
4
|
+
* Which interface input the person's message fills, which one receives recent
|
|
5
|
+
* messages and the two ids, and which node output ports print as replies.
|
|
6
|
+
* Stored per workflow by the Playground (`workflow.playground.chat`) and saved
|
|
7
|
+
* with the workflow. A workflow without stored settings falls back to the
|
|
8
|
+
* deprecated interface `turn` annotations until 3.0, and otherwise has no
|
|
9
|
+
* chat until somebody sets it up.
|
|
10
|
+
*
|
|
11
|
+
* Pure functions over the workflow document: no store, no node graph (the
|
|
12
|
+
* graph-aware checks are `playgroundChatIssues` in `workflowInterface.ts`),
|
|
13
|
+
* never throw, never mutate their arguments.
|
|
14
|
+
*
|
|
15
|
+
* @module utils/playgroundChat
|
|
16
|
+
*/
|
|
17
|
+
import type { PlaygroundChatBinding, PlaygroundChatSource, Workflow, WorkflowInterface, WorkflowPlayground } from '../types/index.js';
|
|
18
|
+
/** The binding in effect for a workflow, and where it came from. */
|
|
19
|
+
export interface ResolvedPlaygroundChat {
|
|
20
|
+
binding: PlaygroundChatBinding;
|
|
21
|
+
source: PlaygroundChatSource;
|
|
22
|
+
}
|
|
23
|
+
/** A binding that binds nothing. */
|
|
24
|
+
export declare function emptyPlaygroundChat(): PlaygroundChatBinding;
|
|
25
|
+
/**
|
|
26
|
+
* A binding in its full shape, every key present. Malformed parts are dropped
|
|
27
|
+
* rather than trusted (the server refuses them on save); a history limit that
|
|
28
|
+
* is not a positive integer falls back to the default.
|
|
29
|
+
*/
|
|
30
|
+
export declare function normalizePlaygroundChat(chat: unknown): PlaygroundChatBinding;
|
|
31
|
+
/**
|
|
32
|
+
* The binding the deprecated interface `turn` annotations declare, or `null`
|
|
33
|
+
* when no entry declares one. The first input per turn value wins (as on the
|
|
34
|
+
* server); every output with `turn: reply` becomes a reply on the port it is
|
|
35
|
+
* bound to.
|
|
36
|
+
*
|
|
37
|
+
* @deprecated since 2.11.0, removed in 3.0 with interface `turn`.
|
|
38
|
+
*/
|
|
39
|
+
export declare function interfaceTurnChat(workflowInterface: WorkflowInterface | undefined): PlaygroundChatBinding | null;
|
|
40
|
+
/**
|
|
41
|
+
* The binding in effect for the workflow as it is now, or `null` when the
|
|
42
|
+
* workflow carries no `playground` key (a server before FlowDrop 2.7.0: the
|
|
43
|
+
* caller keeps its pre-settings behaviour).
|
|
44
|
+
*
|
|
45
|
+
* The same rule the server applies: stored settings win, then the deprecated
|
|
46
|
+
* interface `turn`, else nothing. An input name the interface no longer has
|
|
47
|
+
* binds nothing. Computed from the document rather than read from
|
|
48
|
+
* `playground.resolved`, which goes stale on the first edit.
|
|
49
|
+
*/
|
|
50
|
+
export declare function resolvePlaygroundChat(workflow: Pick<Workflow, 'interface' | 'playground'> | null | undefined): ResolvedPlaygroundChat | null;
|
|
51
|
+
/** The interface inputs a binding fills (so a form must not ask for them). */
|
|
52
|
+
export declare function playgroundBoundInputs(binding: PlaygroundChatBinding): Set<string>;
|
|
53
|
+
/** Whether a binding states anything at all (else it is the same as none). */
|
|
54
|
+
export declare function isPlaygroundChatSet(binding: PlaygroundChatBinding): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Whether a binding is half set: a message input is bound but no reply is,
|
|
57
|
+
* so the person can type but nothing ever answers.
|
|
58
|
+
*/
|
|
59
|
+
export declare function isPlaygroundChatHalfSet(binding: PlaygroundChatBinding): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* The `playground` value after replacing its stored binding. `null` (or a
|
|
62
|
+
* binding that binds nothing) clears it: the workflow then has no stored
|
|
63
|
+
* settings. Server-computed `resolved`/`source` are dropped, since they no
|
|
64
|
+
* longer describe the workflow.
|
|
65
|
+
*/
|
|
66
|
+
export declare function withPlaygroundChat(playground: WorkflowPlayground | undefined, chat: PlaygroundChatBinding | null): WorkflowPlayground;
|
|
67
|
+
/**
|
|
68
|
+
* The `playground` value a save sends: only the stored binding (`chat`), or
|
|
69
|
+
* `undefined` when the workflow carries no Playground settings at all (a
|
|
70
|
+
* server before FlowDrop 2.7.0, which must not receive the key).
|
|
71
|
+
*/
|
|
72
|
+
export declare function playgroundForSave(playground: WorkflowPlayground | undefined): {
|
|
73
|
+
chat: PlaygroundChatBinding | null;
|
|
74
|
+
} | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* An interface edit that changes which input ids exist: one renamed (`id` →
|
|
77
|
+
* `to`) or removed. Reported by `WorkflowInterfaceEditor` only when no other
|
|
78
|
+
* input still carries `id`.
|
|
79
|
+
*/
|
|
80
|
+
export type InterfaceInputEdit = {
|
|
81
|
+
kind: 'rename';
|
|
82
|
+
id: string;
|
|
83
|
+
to: string;
|
|
84
|
+
} | {
|
|
85
|
+
kind: 'remove';
|
|
86
|
+
id: string;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* The `playground` value that follows an interface edit: a renamed input is
|
|
90
|
+
* renamed in the stored binding, a removed one is unbound (so the binding
|
|
91
|
+
* never names an input the interface no longer has, which the server refuses
|
|
92
|
+
* on save). The same object when the binding does not name the input, or
|
|
93
|
+
* nothing is stored.
|
|
94
|
+
*/
|
|
95
|
+
export declare function followInterfaceInputEdit(playground: WorkflowPlayground | undefined, edit: InterfaceInputEdit): WorkflowPlayground | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* The `playground` value after a node swap: replies on `oldNodeId` move to
|
|
98
|
+
* `newNodeId`, each on the output port its mapping names. A reply whose port
|
|
99
|
+
* has no mapping is left as it was, so it shows as a reply on a missing node
|
|
100
|
+
* rather than vanishing (as interface bindings do). The same object when no
|
|
101
|
+
* reply is on the old node.
|
|
102
|
+
*/
|
|
103
|
+
export declare function rewritePlaygroundReplies(playground: WorkflowPlayground | undefined, oldNodeId: string, newNodeId: string, portMappings: ReadonlyArray<{
|
|
104
|
+
direction: 'input' | 'output';
|
|
105
|
+
oldPortId: string;
|
|
106
|
+
newPortId: string;
|
|
107
|
+
}>): WorkflowPlayground | undefined;
|
|
108
|
+
/**
|
|
109
|
+
* Whether the interface still carries a deprecated `turn` mark this library
|
|
110
|
+
* knows (one `withoutInterfaceTurns` removes).
|
|
111
|
+
*/
|
|
112
|
+
export declare function hasKnownInterfaceTurns(workflowInterface: WorkflowInterface | undefined): boolean;
|
|
113
|
+
/**
|
|
114
|
+
* The interface with every deprecated `turn` mark this library knows removed
|
|
115
|
+
* (and a history entry's `meta.limit`, which only `turn: history` gave a
|
|
116
|
+
* meaning), for the step that moves the marks into Playground settings. Other
|
|
117
|
+
* `meta` keys stay; an entry left with an empty `meta` loses the key. A turn
|
|
118
|
+
* value from a newer server is not part of the move, so it stays and
|
|
119
|
+
* round-trips verbatim.
|
|
120
|
+
*/
|
|
121
|
+
export declare function withoutInterfaceTurns(workflowInterface: WorkflowInterface | undefined): WorkflowInterface | undefined;
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A workflow's chat binding (its Playground settings).
|
|
3
|
+
*
|
|
4
|
+
* Which interface input the person's message fills, which one receives recent
|
|
5
|
+
* messages and the two ids, and which node output ports print as replies.
|
|
6
|
+
* Stored per workflow by the Playground (`workflow.playground.chat`) and saved
|
|
7
|
+
* with the workflow. A workflow without stored settings falls back to the
|
|
8
|
+
* deprecated interface `turn` annotations until 3.0, and otherwise has no
|
|
9
|
+
* chat until somebody sets it up.
|
|
10
|
+
*
|
|
11
|
+
* Pure functions over the workflow document: no store, no node graph (the
|
|
12
|
+
* graph-aware checks are `playgroundChatIssues` in `workflowInterface.ts`),
|
|
13
|
+
* never throw, never mutate their arguments.
|
|
14
|
+
*
|
|
15
|
+
* @module utils/playgroundChat
|
|
16
|
+
*/
|
|
17
|
+
import { DEFAULT_HISTORY_TURN_LIMIT, WORKFLOW_INTERFACE_INPUT_TURNS, WORKFLOW_INTERFACE_OUTPUT_TURNS } from '../types/index.js';
|
|
18
|
+
/** A binding that binds nothing. */
|
|
19
|
+
export function emptyPlaygroundChat() {
|
|
20
|
+
return {
|
|
21
|
+
message: null,
|
|
22
|
+
history: null,
|
|
23
|
+
session_id: null,
|
|
24
|
+
message_id: null,
|
|
25
|
+
replies: [],
|
|
26
|
+
sub_workflow_replies: false
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A binding in its full shape, every key present. Malformed parts are dropped
|
|
31
|
+
* rather than trusted (the server refuses them on save); a history limit that
|
|
32
|
+
* is not a positive integer falls back to the default.
|
|
33
|
+
*/
|
|
34
|
+
export function normalizePlaygroundChat(chat) {
|
|
35
|
+
const source = isRecord(chat) ? chat : {};
|
|
36
|
+
const name = (value) => typeof value === 'string' && value !== '' ? value : null;
|
|
37
|
+
const history = isRecord(source.history) ? source.history : null;
|
|
38
|
+
const historyInput = history ? name(history.input) : null;
|
|
39
|
+
const limit = history?.limit;
|
|
40
|
+
const replies = [];
|
|
41
|
+
for (const reply of Array.isArray(source.replies) ? source.replies : []) {
|
|
42
|
+
const nodeId = isRecord(reply) ? name(reply.node_id) : null;
|
|
43
|
+
const port = isRecord(reply) ? name(reply.port) : null;
|
|
44
|
+
if (nodeId !== null && port !== null)
|
|
45
|
+
replies.push({ node_id: nodeId, port });
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
message: name(source.message),
|
|
49
|
+
history: historyInput === null
|
|
50
|
+
? null
|
|
51
|
+
: {
|
|
52
|
+
input: historyInput,
|
|
53
|
+
limit: typeof limit === 'number' && Number.isInteger(limit) && limit >= 1
|
|
54
|
+
? limit
|
|
55
|
+
: DEFAULT_HISTORY_TURN_LIMIT
|
|
56
|
+
},
|
|
57
|
+
session_id: name(source.session_id),
|
|
58
|
+
message_id: name(source.message_id),
|
|
59
|
+
replies,
|
|
60
|
+
sub_workflow_replies: source.sub_workflow_replies === true
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The binding the deprecated interface `turn` annotations declare, or `null`
|
|
65
|
+
* when no entry declares one. The first input per turn value wins (as on the
|
|
66
|
+
* server); every output with `turn: reply` becomes a reply on the port it is
|
|
67
|
+
* bound to.
|
|
68
|
+
*
|
|
69
|
+
* @deprecated since 2.11.0, removed in 3.0 with interface `turn`.
|
|
70
|
+
*/
|
|
71
|
+
export function interfaceTurnChat(workflowInterface) {
|
|
72
|
+
const inputs = workflowInterface?.inputs ?? [];
|
|
73
|
+
const outputs = workflowInterface?.outputs ?? [];
|
|
74
|
+
if (![...inputs, ...outputs].some((entry) => Boolean(entry.turn)))
|
|
75
|
+
return null;
|
|
76
|
+
const first = (turn) => inputs.find((entry) => entry.turn === turn);
|
|
77
|
+
const history = first('history');
|
|
78
|
+
const limit = history?.meta?.limit;
|
|
79
|
+
const replies = [];
|
|
80
|
+
for (const entry of outputs) {
|
|
81
|
+
const target = entry.bindings[0];
|
|
82
|
+
if (entry.turn === 'reply' && target) {
|
|
83
|
+
replies.push({ node_id: target.nodeId, port: target.portId });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
message: first('message')?.id ?? null,
|
|
88
|
+
history: history
|
|
89
|
+
? {
|
|
90
|
+
input: history.id,
|
|
91
|
+
limit: typeof limit === 'number' && Number.isInteger(limit) && limit > 0
|
|
92
|
+
? limit
|
|
93
|
+
: DEFAULT_HISTORY_TURN_LIMIT
|
|
94
|
+
}
|
|
95
|
+
: null,
|
|
96
|
+
session_id: first('session_id')?.id ?? null,
|
|
97
|
+
message_id: first('message_id')?.id ?? null,
|
|
98
|
+
replies,
|
|
99
|
+
sub_workflow_replies: false
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The binding in effect for the workflow as it is now, or `null` when the
|
|
104
|
+
* workflow carries no `playground` key (a server before FlowDrop 2.7.0: the
|
|
105
|
+
* caller keeps its pre-settings behaviour).
|
|
106
|
+
*
|
|
107
|
+
* The same rule the server applies: stored settings win, then the deprecated
|
|
108
|
+
* interface `turn`, else nothing. An input name the interface no longer has
|
|
109
|
+
* binds nothing. Computed from the document rather than read from
|
|
110
|
+
* `playground.resolved`, which goes stale on the first edit.
|
|
111
|
+
*/
|
|
112
|
+
export function resolvePlaygroundChat(workflow) {
|
|
113
|
+
const playground = workflow?.playground;
|
|
114
|
+
if (playground === undefined)
|
|
115
|
+
return null;
|
|
116
|
+
const stored = playground.chat ? normalizePlaygroundChat(playground.chat) : null;
|
|
117
|
+
const fromTurn = stored ? null : interfaceTurnChat(workflow?.interface);
|
|
118
|
+
const binding = stored ?? fromTurn;
|
|
119
|
+
if (binding === null)
|
|
120
|
+
return { binding: emptyPlaygroundChat(), source: 'none' };
|
|
121
|
+
const inputIds = new Set((workflow?.interface?.inputs ?? []).map((entry) => entry.id));
|
|
122
|
+
const known = (id) => (id !== null && inputIds.has(id) ? id : null);
|
|
123
|
+
const historyInput = binding.history ? known(binding.history.input) : null;
|
|
124
|
+
return {
|
|
125
|
+
binding: {
|
|
126
|
+
...binding,
|
|
127
|
+
message: known(binding.message),
|
|
128
|
+
history: binding.history && historyInput !== null ? binding.history : null,
|
|
129
|
+
session_id: known(binding.session_id),
|
|
130
|
+
message_id: known(binding.message_id)
|
|
131
|
+
},
|
|
132
|
+
source: stored ? 'settings' : 'interface_turn'
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
/** The interface inputs a binding fills (so a form must not ask for them). */
|
|
136
|
+
export function playgroundBoundInputs(binding) {
|
|
137
|
+
const ids = [
|
|
138
|
+
binding.message,
|
|
139
|
+
binding.history?.input ?? null,
|
|
140
|
+
binding.session_id,
|
|
141
|
+
binding.message_id
|
|
142
|
+
];
|
|
143
|
+
return new Set(ids.filter((id) => id !== null));
|
|
144
|
+
}
|
|
145
|
+
/** Whether a binding states anything at all (else it is the same as none). */
|
|
146
|
+
export function isPlaygroundChatSet(binding) {
|
|
147
|
+
return (playgroundBoundInputs(binding).size > 0 ||
|
|
148
|
+
binding.replies.length > 0 ||
|
|
149
|
+
binding.sub_workflow_replies);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Whether a binding is half set: a message input is bound but no reply is,
|
|
153
|
+
* so the person can type but nothing ever answers.
|
|
154
|
+
*/
|
|
155
|
+
export function isPlaygroundChatHalfSet(binding) {
|
|
156
|
+
return binding.message !== null && binding.replies.length === 0;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* The `playground` value after replacing its stored binding. `null` (or a
|
|
160
|
+
* binding that binds nothing) clears it: the workflow then has no stored
|
|
161
|
+
* settings. Server-computed `resolved`/`source` are dropped, since they no
|
|
162
|
+
* longer describe the workflow.
|
|
163
|
+
*/
|
|
164
|
+
export function withPlaygroundChat(playground, chat) {
|
|
165
|
+
const next = chat && isPlaygroundChatSet(chat) ? normalizePlaygroundChat(chat) : null;
|
|
166
|
+
const rest = { ...(playground ?? { chat: null }), chat: next };
|
|
167
|
+
delete rest.resolved;
|
|
168
|
+
delete rest.source;
|
|
169
|
+
return rest;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* The `playground` value a save sends: only the stored binding (`chat`), or
|
|
173
|
+
* `undefined` when the workflow carries no Playground settings at all (a
|
|
174
|
+
* server before FlowDrop 2.7.0, which must not receive the key).
|
|
175
|
+
*/
|
|
176
|
+
export function playgroundForSave(playground) {
|
|
177
|
+
if (playground === undefined)
|
|
178
|
+
return undefined;
|
|
179
|
+
return { chat: playground.chat ? normalizePlaygroundChat(playground.chat) : null };
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* The `playground` value that follows an interface edit: a renamed input is
|
|
183
|
+
* renamed in the stored binding, a removed one is unbound (so the binding
|
|
184
|
+
* never names an input the interface no longer has, which the server refuses
|
|
185
|
+
* on save). The same object when the binding does not name the input, or
|
|
186
|
+
* nothing is stored.
|
|
187
|
+
*/
|
|
188
|
+
export function followInterfaceInputEdit(playground, edit) {
|
|
189
|
+
if (!playground?.chat)
|
|
190
|
+
return playground;
|
|
191
|
+
const chat = normalizePlaygroundChat(playground.chat);
|
|
192
|
+
if (!playgroundBoundInputs(chat).has(edit.id))
|
|
193
|
+
return playground;
|
|
194
|
+
const to = edit.kind === 'rename' && edit.to !== '' ? edit.to : null;
|
|
195
|
+
const swap = (id) => (id === edit.id ? to : id);
|
|
196
|
+
return withPlaygroundChat(playground, {
|
|
197
|
+
...chat,
|
|
198
|
+
message: swap(chat.message),
|
|
199
|
+
history: chat.history && chat.history.input === edit.id
|
|
200
|
+
? to === null
|
|
201
|
+
? null
|
|
202
|
+
: { ...chat.history, input: to }
|
|
203
|
+
: chat.history,
|
|
204
|
+
session_id: swap(chat.session_id),
|
|
205
|
+
message_id: swap(chat.message_id)
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* The `playground` value after a node swap: replies on `oldNodeId` move to
|
|
210
|
+
* `newNodeId`, each on the output port its mapping names. A reply whose port
|
|
211
|
+
* has no mapping is left as it was, so it shows as a reply on a missing node
|
|
212
|
+
* rather than vanishing (as interface bindings do). The same object when no
|
|
213
|
+
* reply is on the old node.
|
|
214
|
+
*/
|
|
215
|
+
export function rewritePlaygroundReplies(playground, oldNodeId, newNodeId, portMappings) {
|
|
216
|
+
if (!playground?.chat)
|
|
217
|
+
return playground;
|
|
218
|
+
const chat = normalizePlaygroundChat(playground.chat);
|
|
219
|
+
if (!chat.replies.some((reply) => reply.node_id === oldNodeId))
|
|
220
|
+
return playground;
|
|
221
|
+
const replies = chat.replies.map((reply) => {
|
|
222
|
+
if (reply.node_id !== oldNodeId)
|
|
223
|
+
return reply;
|
|
224
|
+
const mapping = portMappings.find((candidate) => candidate.direction === 'output' && candidate.oldPortId === reply.port);
|
|
225
|
+
return mapping ? { node_id: newNodeId, port: mapping.newPortId } : reply;
|
|
226
|
+
});
|
|
227
|
+
return withPlaygroundChat(playground, { ...chat, replies });
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Whether the interface still carries a deprecated `turn` mark this library
|
|
231
|
+
* knows (one `withoutInterfaceTurns` removes).
|
|
232
|
+
*/
|
|
233
|
+
export function hasKnownInterfaceTurns(workflowInterface) {
|
|
234
|
+
const entries = [...(workflowInterface?.inputs ?? []), ...(workflowInterface?.outputs ?? [])];
|
|
235
|
+
return entries.some((entry) => entry.turn !== undefined && KNOWN_TURNS.has(entry.turn));
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* The interface with every deprecated `turn` mark this library knows removed
|
|
239
|
+
* (and a history entry's `meta.limit`, which only `turn: history` gave a
|
|
240
|
+
* meaning), for the step that moves the marks into Playground settings. Other
|
|
241
|
+
* `meta` keys stay; an entry left with an empty `meta` loses the key. A turn
|
|
242
|
+
* value from a newer server is not part of the move, so it stays and
|
|
243
|
+
* round-trips verbatim.
|
|
244
|
+
*/
|
|
245
|
+
export function withoutInterfaceTurns(workflowInterface) {
|
|
246
|
+
if (workflowInterface === undefined)
|
|
247
|
+
return undefined;
|
|
248
|
+
const strip = (entry) => {
|
|
249
|
+
if (entry.turn === undefined || !KNOWN_TURNS.has(entry.turn))
|
|
250
|
+
return entry;
|
|
251
|
+
const next = { ...entry };
|
|
252
|
+
delete next.turn;
|
|
253
|
+
if (entry.turn === 'history' && next.meta && 'limit' in next.meta) {
|
|
254
|
+
const meta = { ...next.meta };
|
|
255
|
+
delete meta.limit;
|
|
256
|
+
if (Object.keys(meta).length > 0)
|
|
257
|
+
next.meta = meta;
|
|
258
|
+
else
|
|
259
|
+
delete next.meta;
|
|
260
|
+
}
|
|
261
|
+
return next;
|
|
262
|
+
};
|
|
263
|
+
return {
|
|
264
|
+
...workflowInterface,
|
|
265
|
+
...(workflowInterface.inputs && { inputs: workflowInterface.inputs.map(strip) }),
|
|
266
|
+
...(workflowInterface.outputs && { outputs: workflowInterface.outputs.map(strip) })
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
const KNOWN_TURNS = new Set([
|
|
270
|
+
...WORKFLOW_INTERFACE_INPUT_TURNS,
|
|
271
|
+
...WORKFLOW_INTERFACE_OUTPUT_TURNS
|
|
272
|
+
]);
|
|
273
|
+
function isRecord(value) {
|
|
274
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
275
|
+
}
|
package/dist/utils/portal.d.ts
CHANGED
|
@@ -9,9 +9,17 @@
|
|
|
9
9
|
* mis-centering. Portalling the node to `document.body` sidesteps this by
|
|
10
10
|
* escaping those ancestors entirely.
|
|
11
11
|
*
|
|
12
|
+
* The node leaves `.flowdrop-root`, so it takes the editor's skin scope with
|
|
13
|
+
* it: `data-fd-scope` is copied from the nearest scoped ancestor (read before
|
|
14
|
+
* the move) and the node gets the `flowdrop-portal` class, which the base
|
|
15
|
+
* stylesheet treats as a FlowDrop root.
|
|
16
|
+
*
|
|
12
17
|
* Usage: `<div use:portal>…</div>` or `<div use:portal={targetElement}>…</div>`.
|
|
13
18
|
* No-op during SSR (no `document`).
|
|
14
19
|
*/
|
|
20
|
+
/** Attribute that scopes one editor's skin (on `.flowdrop-root`, copied onto overlays). */
|
|
21
|
+
export declare const SCOPE_ATTR = "data-fd-scope";
|
|
22
|
+
export declare const PORTAL_CLASS = "flowdrop-portal";
|
|
15
23
|
export declare function portal(node: HTMLElement, target?: HTMLElement | undefined): {
|
|
16
24
|
update(nextTarget: HTMLElement | undefined): void;
|
|
17
25
|
destroy(): void;
|
package/dist/utils/portal.js
CHANGED
|
@@ -9,16 +9,31 @@
|
|
|
9
9
|
* mis-centering. Portalling the node to `document.body` sidesteps this by
|
|
10
10
|
* escaping those ancestors entirely.
|
|
11
11
|
*
|
|
12
|
+
* The node leaves `.flowdrop-root`, so it takes the editor's skin scope with
|
|
13
|
+
* it: `data-fd-scope` is copied from the nearest scoped ancestor (read before
|
|
14
|
+
* the move) and the node gets the `flowdrop-portal` class, which the base
|
|
15
|
+
* stylesheet treats as a FlowDrop root.
|
|
16
|
+
*
|
|
12
17
|
* Usage: `<div use:portal>…</div>` or `<div use:portal={targetElement}>…</div>`.
|
|
13
18
|
* No-op during SSR (no `document`).
|
|
14
19
|
*/
|
|
20
|
+
/** Attribute that scopes one editor's skin (on `.flowdrop-root`, copied onto overlays). */
|
|
21
|
+
export const SCOPE_ATTR = 'data-fd-scope';
|
|
22
|
+
export const PORTAL_CLASS = 'flowdrop-portal';
|
|
15
23
|
export function portal(node, target = undefined) {
|
|
16
24
|
let host = null;
|
|
25
|
+
// Remembered across updates: after the first move the node no longer has the
|
|
26
|
+
// editor as an ancestor to look the scope up on.
|
|
27
|
+
let scope = null;
|
|
17
28
|
function mount(to) {
|
|
18
29
|
if (typeof document === 'undefined')
|
|
19
30
|
return;
|
|
31
|
+
scope ??= node.closest(`[${SCOPE_ATTR}]`)?.getAttribute(SCOPE_ATTR) ?? null;
|
|
20
32
|
host = to ?? document.body;
|
|
21
33
|
host.appendChild(node);
|
|
34
|
+
node.classList.add(PORTAL_CLASS);
|
|
35
|
+
if (scope !== null)
|
|
36
|
+
node.setAttribute(SCOPE_ATTR, scope);
|
|
22
37
|
}
|
|
23
38
|
mount(target);
|
|
24
39
|
return {
|
|
@@ -12,8 +12,9 @@
|
|
|
12
12
|
*
|
|
13
13
|
* @module utils/workflowInterface
|
|
14
14
|
*/
|
|
15
|
-
import type { ConfigSchema, NodePort, PortBinding, Workflow, WorkflowInterface, WorkflowInterfaceEntry, WorkflowInterfaceTurn, WorkflowNode } from '../types/index.js';
|
|
15
|
+
import type { ConfigSchema, NodePort, PortBinding, Workflow, WorkflowInterface, WorkflowInterfaceEntry, WorkflowInterfaceTurn, WorkflowNode, WorkflowPlayground, PlaygroundChatBinding, PlaygroundReplyPort } from '../types/index.js';
|
|
16
16
|
import type { PortMapping } from './nodeSwap.js';
|
|
17
|
+
import { type ResolvedPlaygroundChat } from './playgroundChat.js';
|
|
17
18
|
/**
|
|
18
19
|
* A binding resolved against the live node graph: the node and port it
|
|
19
20
|
* points at, and which side of that node the port lives on.
|
|
@@ -278,31 +279,98 @@ export declare function historyLimitPatch(entry: WorkflowInterfaceEntry, raw: st
|
|
|
278
279
|
/** The `meta.limit` a history entry states, when it is a positive integer. */
|
|
279
280
|
export declare function historyLimitOf(entry: WorkflowInterfaceEntry): number | undefined;
|
|
280
281
|
/**
|
|
281
|
-
* How the Playground collects a turn, read from the workflow
|
|
282
|
+
* How the Playground collects a turn, read from the workflow's chat binding.
|
|
282
283
|
*
|
|
283
|
-
* - `chat`: an input
|
|
284
|
-
* any other
|
|
285
|
-
* - `form`:
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
* - `run`:
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
284
|
+
* - `chat`: an input is bound to the message. The chat box sends `content`;
|
|
285
|
+
* any other unbound inputs render as a form beside it.
|
|
286
|
+
* - `form`: no message input is bound, and the interface has unbound inputs.
|
|
287
|
+
* A form and a Run button; the turn sends `inputs` only (the server refuses
|
|
288
|
+
* `content` for such a workflow).
|
|
289
|
+
* - `run`: no message input and no unbound input. Just a Run button.
|
|
290
|
+
* - `legacy`: only for a server before FlowDrop 2.7.0 (the workflow carries
|
|
291
|
+
* no `playground` key) whose interface declares no `turn` either. That
|
|
292
|
+
* server guesses the chat input from the nodes, so the Playground keeps its
|
|
293
|
+
* old behaviour too.
|
|
294
|
+
*
|
|
295
|
+
* The binding is the workflow's Playground settings, else the deprecated
|
|
296
|
+
* interface `turn` (see `resolvePlaygroundChat`). A workflow with neither has
|
|
297
|
+
* no chat until somebody sets it up: `form` or `run`, never `legacy`.
|
|
294
298
|
*/
|
|
295
299
|
export type PlaygroundInputMode = 'chat' | 'form' | 'run' | 'legacy';
|
|
296
|
-
/**
|
|
300
|
+
/**
|
|
301
|
+
* Whether any entry of the interface, on either side, declares a `turn`.
|
|
302
|
+
*
|
|
303
|
+
* @deprecated since 2.11.0, removed in 3.0 with interface `turn`.
|
|
304
|
+
*/
|
|
297
305
|
export declare function declaresTurnPorts(workflowInterface: WorkflowInterface | undefined): boolean;
|
|
298
306
|
/**
|
|
299
|
-
* The input entries a person fills in: every input
|
|
300
|
-
*
|
|
301
|
-
*
|
|
307
|
+
* The input entries a person fills in: every input the chat binding does not
|
|
308
|
+
* fill. With `playground` (a server from FlowDrop 2.7.0 on) those are the
|
|
309
|
+
* inputs its binding names (and, while the binding comes from `turn` marks,
|
|
310
|
+
* every input carrying one); without it, the inputs carrying a `turn`
|
|
311
|
+
* (`message`, `history`, `session_id`, `message_id`, and any value a newer
|
|
312
|
+
* server adds). The session fills those, never the form.
|
|
313
|
+
*/
|
|
314
|
+
export declare function interfaceFormEntries(workflowInterface: WorkflowInterface | undefined, playground?: WorkflowPlayground): WorkflowInterfaceEntry[];
|
|
315
|
+
/**
|
|
316
|
+
* {@link interfaceFormEntries} for a binding already resolved with
|
|
317
|
+
* `resolvePlaygroundChat` (`null` = the workflow carries no `playground`).
|
|
318
|
+
*/
|
|
319
|
+
export declare function interfaceFormEntriesFor(workflowInterface: WorkflowInterface | undefined, resolved: ResolvedPlaygroundChat | null): WorkflowInterfaceEntry[];
|
|
320
|
+
/**
|
|
321
|
+
* Resolve the Playground's input mode from a workflow's interface and, from
|
|
322
|
+
* FlowDrop 2.7.0 on, its Playground settings (`workflow.playground`).
|
|
323
|
+
*/
|
|
324
|
+
export declare function resolvePlaygroundInputMode(workflowInterface: WorkflowInterface | undefined, playground?: WorkflowPlayground): PlaygroundInputMode;
|
|
325
|
+
/**
|
|
326
|
+
* {@link resolvePlaygroundInputMode} for a binding already resolved with
|
|
327
|
+
* `resolvePlaygroundChat` (`null` = the workflow carries no `playground`).
|
|
302
328
|
*/
|
|
303
|
-
export declare function
|
|
304
|
-
/**
|
|
305
|
-
export
|
|
329
|
+
export declare function playgroundInputModeFor(workflowInterface: WorkflowInterface | undefined, resolved: ResolvedPlaygroundChat | null): PlaygroundInputMode;
|
|
330
|
+
/** Which part of a chat binding names an interface input. */
|
|
331
|
+
export type PlaygroundChatInputKey = 'message' | 'history' | 'session_id' | 'message_id';
|
|
332
|
+
/** Something wrong, or worth knowing, about a workflow's chat binding. */
|
|
333
|
+
export interface PlaygroundChatIssue {
|
|
334
|
+
severity: 'error' | 'warning';
|
|
335
|
+
code: 'playground-input-missing' | 'playground-input-duplicate' | 'playground-reply-node-missing' | 'playground-reply-port-missing' | 'playground-half-set';
|
|
336
|
+
/**
|
|
337
|
+
* The issue in English, for logs and agents. A UI formats its own text
|
|
338
|
+
* from `code` and the fields below (see `playgroundSettings.issues`).
|
|
339
|
+
*/
|
|
340
|
+
message: string;
|
|
341
|
+
/** The binding key an input issue is about. */
|
|
342
|
+
key?: PlaygroundChatInputKey;
|
|
343
|
+
/** The input an input issue names. */
|
|
344
|
+
input?: string;
|
|
345
|
+
/** `playground-input-duplicate`: the key that has the input already. */
|
|
346
|
+
otherKey?: PlaygroundChatInputKey;
|
|
347
|
+
/** The reply a reply issue is about. */
|
|
348
|
+
reply?: PlaygroundReplyPort;
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* What is wrong with a chat binding against the workflow as it is now.
|
|
352
|
+
*
|
|
353
|
+
* Errors mirror the server's checks (an input the interface no longer has,
|
|
354
|
+
* an input bound twice, a reply on a node or port that is gone), so the
|
|
355
|
+
* editor shows what the save would refuse. A reply's port is judged against
|
|
356
|
+
* the node's static and dynamic outputs; a node without metadata is not
|
|
357
|
+
* judged. The one warning is a half-set binding (a message input but no
|
|
358
|
+
* reply). Defaults to the workflow's stored binding. The binding is
|
|
359
|
+
* normalised first, so one from the wire that leaves out its nullable keys
|
|
360
|
+
* (the schema requires only `replies`) reads as unbound there, not as bound
|
|
361
|
+
* to an input that is missing.
|
|
362
|
+
*/
|
|
363
|
+
export declare function playgroundChatIssues(workflow: Workflow, binding?: PlaygroundChatBinding | null): PlaygroundChatIssue[];
|
|
364
|
+
/**
|
|
365
|
+
* The node output port a reply names, with the node's label: any output the
|
|
366
|
+
* node has, exposed on the canvas or not (the same ports
|
|
367
|
+
* `playgroundChatIssues` accepts). `null` when the node or port is gone, or
|
|
368
|
+
* the node carries no metadata to tell.
|
|
369
|
+
*/
|
|
370
|
+
export declare function findReplyPort(workflow: Workflow, reply: PlaygroundReplyPort): {
|
|
371
|
+
nodeLabel: string;
|
|
372
|
+
port: NodePort;
|
|
373
|
+
} | null;
|
|
306
374
|
/**
|
|
307
375
|
* The object schema a form renders for the given entries: one property per
|
|
308
376
|
* entry, keyed by its `id` (the name the server matches inputs on). The
|