@flowdrop/flowdrop 2.5.0 → 2.6.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.
Files changed (52) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/dist/chat/commandClassifier.d.ts +17 -0
  3. package/dist/chat/commandClassifier.js +29 -0
  4. package/dist/chat/index.d.ts +1 -1
  5. package/dist/chat/index.js +1 -1
  6. package/dist/components/App.svelte +8 -0
  7. package/dist/components/BindablePortListbox.svelte +426 -0
  8. package/dist/components/BindablePortListbox.svelte.d.ts +23 -0
  9. package/dist/components/WorkflowInterfaceEditor.svelte +142 -36
  10. package/dist/components/WorkflowInterfaceEditor.svelte.d.ts +8 -0
  11. package/dist/components/WorkflowInterfaceEntryCard.svelte +537 -294
  12. package/dist/components/WorkflowInterfaceEntryCard.svelte.d.ts +6 -3
  13. package/dist/components/WorkflowInterfaceEntryComposer.svelte +331 -0
  14. package/dist/components/WorkflowInterfaceEntryComposer.svelte.d.ts +19 -0
  15. package/dist/messages/context.d.ts +6 -0
  16. package/dist/messages/context.js +8 -0
  17. package/dist/messages/defaults.d.ts +45 -2
  18. package/dist/messages/defaults.js +36 -3
  19. package/dist/messages/index.d.ts +1 -1
  20. package/dist/messages/index.js +1 -1
  21. package/dist/stores/instanceContainer.svelte.d.ts +26 -0
  22. package/dist/stores/instanceContainer.svelte.js +24 -0
  23. package/dist/stories/WebMCPFakeAgent.svelte +229 -0
  24. package/dist/stories/WebMCPFakeAgent.svelte.d.ts +10 -0
  25. package/dist/styles/base.css +4 -2
  26. package/dist/svelte-app.d.ts +20 -0
  27. package/dist/svelte-app.js +49 -1
  28. package/dist/utils/focus.d.ts +18 -0
  29. package/dist/utils/focus.js +24 -0
  30. package/dist/utils/whenWorkflowLoaded.svelte.d.ts +17 -0
  31. package/dist/utils/whenWorkflowLoaded.svelte.js +42 -0
  32. package/dist/utils/workflowInterface.d.ts +47 -3
  33. package/dist/utils/workflowInterface.js +84 -9
  34. package/dist/webmcp/WebMCP.stories.svelte +101 -0
  35. package/dist/webmcp/WebMCP.stories.svelte.d.ts +18 -0
  36. package/dist/webmcp/WebMCPConfirm.svelte +170 -0
  37. package/dist/webmcp/WebMCPConfirm.svelte.d.ts +11 -0
  38. package/dist/webmcp/descriptors.d.ts +59 -0
  39. package/dist/webmcp/descriptors.js +464 -0
  40. package/dist/webmcp/fake.d.ts +23 -0
  41. package/dist/webmcp/fake.js +42 -0
  42. package/dist/webmcp/gate.d.ts +40 -0
  43. package/dist/webmcp/gate.js +92 -0
  44. package/dist/webmcp/index.d.ts +34 -0
  45. package/dist/webmcp/index.js +31 -0
  46. package/dist/webmcp/register.d.ts +33 -0
  47. package/dist/webmcp/register.js +267 -0
  48. package/dist/webmcp/types.d.ts +166 -0
  49. package/dist/webmcp/types.js +23 -0
  50. package/dist/webmcp/validate.d.ts +32 -0
  51. package/dist/webmcp/validate.js +118 -0
  52. package/package.json +6 -1
@@ -0,0 +1,101 @@
1
+ <script module lang="ts">
2
+ import { defineMeta } from '@storybook/addon-svelte-csf';
3
+ import WebMCPFakeAgent from '../stories/WebMCPFakeAgent.svelte';
4
+ import type { NodeMetadata, NodePort, Workflow } from '../types/index.js';
5
+
6
+ // Inline fixtures: importing from src/mocks would make svelte-package emit
7
+ // declaration files outside src/lib.
8
+ const port = (id: string, name: string, type: NodePort['type'], dataType: string): NodePort => ({
9
+ id,
10
+ name,
11
+ type,
12
+ dataType
13
+ });
14
+ const nodes: NodeMetadata[] = [
15
+ {
16
+ node_type_id: 'chat_model',
17
+ name: 'Chat Model',
18
+ description: 'Chat completion using an LLM provider',
19
+ category: 'ai',
20
+ version: '1.0.0',
21
+ type: 'default',
22
+ icon: 'mdi:robot',
23
+ inputs: [port('message', 'Message', 'input', 'string')],
24
+ outputs: [port('response', 'Response', 'output', 'string')],
25
+ configSchema: {
26
+ type: 'object',
27
+ properties: {
28
+ model: { type: 'string', title: 'Model', default: 'gpt-4o' },
29
+ temperature: { type: 'number', title: 'Temperature', default: 0.7 }
30
+ }
31
+ }
32
+ },
33
+ {
34
+ node_type_id: 'chat_output',
35
+ name: 'Chat Output',
36
+ description: 'Show a message to the user',
37
+ category: 'outputs',
38
+ version: '1.0.0',
39
+ type: 'default',
40
+ icon: 'mdi:message-text',
41
+ inputs: [port('message', 'Message', 'input', 'string')],
42
+ outputs: [],
43
+ configSchema: { type: 'object', properties: {} }
44
+ },
45
+ {
46
+ node_type_id: 'text_input',
47
+ name: 'Text Input',
48
+ description: 'Accept text from the user',
49
+ category: 'inputs',
50
+ version: '1.0.0',
51
+ type: 'default',
52
+ icon: 'mdi:text-box',
53
+ inputs: [],
54
+ outputs: [port('value', 'Value', 'output', 'string')],
55
+ configSchema: {
56
+ type: 'object',
57
+ properties: { defaultValue: { type: 'string', title: 'Default value', default: '' } }
58
+ }
59
+ }
60
+ ];
61
+
62
+ const workflow: Workflow = {
63
+ id: 'webmcp-demo',
64
+ name: 'WebMCP demo',
65
+ nodes: [
66
+ {
67
+ id: 'text_input.1',
68
+ type: 'default',
69
+ position: { x: 80, y: 120 },
70
+ data: { label: 'Text Input', config: {}, metadata: nodes[2] }
71
+ }
72
+ ],
73
+ edges: [],
74
+ metadata: {
75
+ schemaVersion: '1.0.0',
76
+ createdAt: '2026-01-01T00:00:00Z',
77
+ updatedAt: '2026-01-01T00:00:00Z'
78
+ }
79
+ };
80
+
81
+ const { Story } = defineMeta({
82
+ title: 'Integrations/WebMCP',
83
+ component: WebMCPFakeAgent,
84
+ tags: ['autodocs'],
85
+ parameters: {
86
+ layout: 'fullscreen',
87
+ docs: {
88
+ description: {
89
+ component:
90
+ 'The editor’s commands registered as WebMCP editor tools, driven by a fake browser agent in the side panel. ' +
91
+ 'Pick a tool, invoke it, and approve or reject the change in the dialog that the real agent would trigger.'
92
+ }
93
+ }
94
+ },
95
+ args: { nodes, workflow }
96
+ });
97
+ </script>
98
+
99
+ <Story name="Fake agent — confirm gate" args={{ approval: 'confirm' }} />
100
+
101
+ <Story name="Fake agent — auto approval" args={{ approval: 'auto' }} />
@@ -0,0 +1,18 @@
1
+ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
2
+ new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
3
+ $$bindings?: Bindings;
4
+ } & Exports;
5
+ (internal: unknown, props: {
6
+ $$events?: Events;
7
+ $$slots?: Slots;
8
+ }): Exports & {
9
+ $set?: any;
10
+ $on?: any;
11
+ };
12
+ z_$$bindings?: Bindings;
13
+ }
14
+ declare const WebMCP: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
15
+ [evt: string]: CustomEvent<any>;
16
+ }, {}, {}, string>;
17
+ type WebMCP = InstanceType<typeof WebMCP>;
18
+ export default WebMCP;
@@ -0,0 +1,170 @@
1
+ <!--
2
+ WebMCPConfirm
3
+
4
+ The built-in approval dialog for mutating editor tools called by a browser
5
+ agent. Lists what is about to run and asks the person at the keyboard.
6
+ Mounted imperatively by `gate.ts` into the host's container (default
7
+ `document.body`), one at a time; a second request while one is open is
8
+ refused upstream with a `busy` error rather than stacking dialogs.
9
+ -->
10
+
11
+ <script lang="ts">
12
+ import { m } from '../messages/index.js';
13
+ import { focusOnMount } from '../utils/focus.js';
14
+
15
+ interface Props {
16
+ /** Editor / workflow name, so two editors on one page are distinguishable. */
17
+ editorName: string;
18
+ /** One human-readable line per command (see `describeCommand`). */
19
+ lines: string[];
20
+ /** Called exactly once with the decision. */
21
+ onResolve: (approved: boolean) => void;
22
+ }
23
+
24
+ let { editorName, lines, onResolve }: Props = $props();
25
+
26
+ let rejectButton = $state<HTMLButtonElement | null>(null);
27
+ let approveButton = $state<HTMLButtonElement | null>(null);
28
+
29
+ // Focus starts on Apply and stays inside the dialog: Tab and Shift+Tab move
30
+ // between the two buttons, Escape rejects. The handler sits on the dialog
31
+ // itself, which holds focus through its buttons, not on the window.
32
+ function handleKeydown(event: KeyboardEvent): void {
33
+ if (event.key === 'Escape') {
34
+ event.preventDefault();
35
+ onResolve(false);
36
+ } else if (event.key === 'Tab') {
37
+ event.preventDefault();
38
+ (document.activeElement === approveButton ? rejectButton : approveButton)?.focus();
39
+ }
40
+ }
41
+ </script>
42
+
43
+ <div class="fd-webmcp-confirm" data-testid="flowdrop-webmcp-confirm">
44
+ <div
45
+ class="fd-webmcp-confirm__dialog"
46
+ role="alertdialog"
47
+ aria-modal="true"
48
+ aria-labelledby="fd-webmcp-confirm-title"
49
+ aria-describedby="fd-webmcp-confirm-list"
50
+ tabindex="-1"
51
+ onkeydown={handleKeydown}
52
+ >
53
+ <h2 id="fd-webmcp-confirm-title" class="fd-webmcp-confirm__title">
54
+ {m().webmcp.confirmTitle({ name: editorName })}
55
+ </h2>
56
+ <p class="fd-webmcp-confirm__hint">
57
+ {m().webmcp.confirmCount({ count: lines.length })}
58
+ </p>
59
+ <ol id="fd-webmcp-confirm-list" class="fd-webmcp-confirm__list">
60
+ {#each lines as line, i (i)}
61
+ <li class="fd-webmcp-confirm__line">{line}</li>
62
+ {/each}
63
+ </ol>
64
+ <div class="fd-webmcp-confirm__actions">
65
+ <button
66
+ type="button"
67
+ class="fd-webmcp-confirm__button fd-webmcp-confirm__button--reject"
68
+ data-testid="flowdrop-webmcp-reject"
69
+ bind:this={rejectButton}
70
+ onclick={() => onResolve(false)}
71
+ >
72
+ {m().webmcp.reject}
73
+ </button>
74
+ <button
75
+ type="button"
76
+ class="fd-webmcp-confirm__button fd-webmcp-confirm__button--approve"
77
+ data-testid="flowdrop-webmcp-approve"
78
+ bind:this={approveButton}
79
+ {@attach focusOnMount()}
80
+ onclick={() => onResolve(true)}
81
+ >
82
+ {m().webmcp.apply}
83
+ </button>
84
+ </div>
85
+ </div>
86
+ </div>
87
+
88
+ <style>
89
+ .fd-webmcp-confirm {
90
+ position: fixed;
91
+ inset: 0;
92
+ z-index: 10000;
93
+ display: flex;
94
+ align-items: center;
95
+ justify-content: center;
96
+ background: rgb(0 0 0 / 0.4);
97
+ font-family: inherit;
98
+ }
99
+
100
+ .fd-webmcp-confirm__dialog {
101
+ min-width: 20rem;
102
+ max-width: min(36rem, calc(100vw - 2rem));
103
+ max-height: calc(100vh - 2rem);
104
+ overflow: auto;
105
+ padding: var(--fd-space-lg, 1rem);
106
+ border: 1px solid var(--fd-border, #d4d4d8);
107
+ border-radius: var(--fd-radius-lg, 0.75rem);
108
+ background: var(--fd-background, #fff);
109
+ color: var(--fd-foreground, #18181b);
110
+ box-shadow: var(--fd-shadow-xl, 0 20px 40px rgb(0 0 0 / 0.25));
111
+ }
112
+
113
+ .fd-webmcp-confirm__title {
114
+ margin: 0 0 var(--fd-space-xs, 0.25rem);
115
+ font-size: var(--fd-text-md, 1rem);
116
+ font-weight: 600;
117
+ }
118
+
119
+ .fd-webmcp-confirm__hint {
120
+ margin: 0 0 var(--fd-space-md, 0.75rem);
121
+ font-size: var(--fd-text-sm, 0.875rem);
122
+ color: var(--fd-muted-foreground, #71717a);
123
+ }
124
+
125
+ .fd-webmcp-confirm__list {
126
+ margin: 0 0 var(--fd-space-lg, 1rem);
127
+ padding: var(--fd-space-sm, 0.5rem) var(--fd-space-sm, 0.5rem) var(--fd-space-sm, 0.5rem)
128
+ var(--fd-space-xl, 1.5rem);
129
+ border-radius: var(--fd-radius-md, 0.5rem);
130
+ background: var(--fd-muted, #f4f4f5);
131
+ font-family: var(--fd-font-mono, ui-monospace, monospace);
132
+ font-size: var(--fd-text-sm, 0.875rem);
133
+ }
134
+
135
+ .fd-webmcp-confirm__line {
136
+ padding: 0.125rem 0;
137
+ overflow-wrap: anywhere;
138
+ }
139
+
140
+ .fd-webmcp-confirm__actions {
141
+ display: flex;
142
+ justify-content: flex-end;
143
+ gap: var(--fd-space-sm, 0.5rem);
144
+ }
145
+
146
+ .fd-webmcp-confirm__button {
147
+ padding: var(--fd-space-xs, 0.375rem) var(--fd-space-md, 0.75rem);
148
+ border: 1px solid var(--fd-border, #d4d4d8);
149
+ border-radius: var(--fd-control-radius, 0.375rem);
150
+ background: var(--fd-background, #fff);
151
+ color: inherit;
152
+ font: inherit;
153
+ cursor: pointer;
154
+ }
155
+
156
+ .fd-webmcp-confirm__button--approve {
157
+ border-color: var(--fd-primary, #2563eb);
158
+ background: var(--fd-primary, #2563eb);
159
+ color: var(--fd-primary-foreground, #fff);
160
+ }
161
+
162
+ .fd-webmcp-confirm__button--approve:hover {
163
+ background: var(--fd-primary-hover, #1d4ed8);
164
+ }
165
+
166
+ .fd-webmcp-confirm__button:focus-visible {
167
+ outline: 2px solid var(--fd-primary, #2563eb);
168
+ outline-offset: 2px;
169
+ }
170
+ </style>
@@ -0,0 +1,11 @@
1
+ interface Props {
2
+ /** Editor / workflow name, so two editors on one page are distinguishable. */
3
+ editorName: string;
4
+ /** One human-readable line per command (see `describeCommand`). */
5
+ lines: string[];
6
+ /** Called exactly once with the decision. */
7
+ onResolve: (approved: boolean) => void;
8
+ }
9
+ declare const WebMCPConfirm: import("svelte").Component<Props, {}, "">;
10
+ type WebMCPConfirm = ReturnType<typeof WebMCPConfirm>;
11
+ export default WebMCPConfirm;
@@ -0,0 +1,59 @@
1
+ /**
2
+ * WebMCP adapter — tool descriptors.
3
+ *
4
+ * Maps the command union to `{verb, description, inputSchema, readOnly,
5
+ * toCommands}` records. Transport-free: no DOM, no Svelte, nothing from the
6
+ * runtime — so the same records can back a server-side MCP endpoint later.
7
+ *
8
+ * The schemas are written by hand next to the interfaces they mirror
9
+ * (`commands/types.ts`). Each exposed command is one record in `COMMANDS`:
10
+ * its description, its input schema, how validated arguments become the
11
+ * command, and how the command reads back to a human in the confirm dialog.
12
+ * The coverage test in `tests/unit/webmcp` asserts every literal of the
13
+ * `Command` union is either exposed here or on the explicit exclusion list,
14
+ * and that every exposed record carries all four parts, so a new DSL verb
15
+ * cannot slip through unclassified or half-described.
16
+ *
17
+ * @module webmcp/descriptors
18
+ */
19
+ import type { Command } from '../commands/types.js';
20
+ import { VIEW_COMMAND_TYPES } from '../chat/commandClassifier.js';
21
+ import { type ToolDescriptor, type ToolInputSchema } from './types.js';
22
+ import { validateToolArgs } from './validate.js';
23
+ export { validateToolArgs };
24
+ /** Command types exposed as one tool each (verb === command type). */
25
+ export declare const EXPOSED_COMMAND_TYPES: readonly ["add_node", "delete_node", "rename_node", "move_node", "swap_node", "set_config", "get_config", "connect", "disconnect_ports", "disconnect_node", "list_nodes", "list_edges", "list_types", "info", "undo", "redo", "auto_layout", "beautify_layout"];
26
+ /**
27
+ * Command types folded into the single `view` tool (its `action` enum). The
28
+ * list itself lives in the command classifier, next to `isViewCommand`, so
29
+ * the chat panel and this adapter cannot disagree about what a view command is.
30
+ */
31
+ export { VIEW_COMMAND_TYPES };
32
+ /**
33
+ * Command types deliberately not exposed.
34
+ * - `clear` wipes the whole workflow; an agent can delete nodes one by one and
35
+ * each deletion is gated.
36
+ * - `help` describes the text DSL; the tool schemas are the help.
37
+ */
38
+ export declare const EXCLUDED_COMMAND_TYPES: readonly ["clear", "help"];
39
+ /** Extra tool verbs that are not command types. */
40
+ export declare const COMPOSITE_VERBS: readonly ["view", "batch"];
41
+ type Args = Record<string, unknown>;
42
+ type ExposedType = (typeof EXPOSED_COMMAND_TYPES)[number];
43
+ /** The record for one exposed command — for tests that check its shape. */
44
+ export declare function commandRecord(type: ExposedType): {
45
+ description: string;
46
+ inputSchema: ToolInputSchema;
47
+ build: (args: Args) => Command;
48
+ summarize: (command: Command) => string;
49
+ };
50
+ export interface BuildDescriptorsOptions {
51
+ /** Register the `view` tool. Default true. */
52
+ view?: boolean;
53
+ }
54
+ /**
55
+ * Build the descriptor list. Pure; call it as often as you like.
56
+ */
57
+ export declare function buildToolDescriptors(options?: BuildDescriptorsOptions): ToolDescriptor[];
58
+ /** One line describing a command for a human about to approve it. */
59
+ export declare function describeCommand(command: Command): string;