@flowdrop/flowdrop 2.5.0 → 2.7.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 (68) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/dist/chat/commandClassifier.d.ts +19 -1
  3. package/dist/chat/commandClassifier.js +33 -1
  4. package/dist/chat/index.d.ts +1 -1
  5. package/dist/chat/index.js +1 -1
  6. package/dist/commands/executor.js +270 -37
  7. package/dist/commands/index.d.ts +1 -1
  8. package/dist/commands/parser.js +20 -0
  9. package/dist/commands/types.d.ts +77 -12
  10. package/dist/components/App.svelte +8 -0
  11. package/dist/components/BindablePortListbox.svelte +426 -0
  12. package/dist/components/BindablePortListbox.svelte.d.ts +23 -0
  13. package/dist/components/WorkflowInterfaceEditor.svelte +142 -36
  14. package/dist/components/WorkflowInterfaceEditor.svelte.d.ts +8 -0
  15. package/dist/components/WorkflowInterfaceEntryCard.svelte +537 -294
  16. package/dist/components/WorkflowInterfaceEntryCard.svelte.d.ts +6 -3
  17. package/dist/components/WorkflowInterfaceEntryComposer.svelte +331 -0
  18. package/dist/components/WorkflowInterfaceEntryComposer.svelte.d.ts +19 -0
  19. package/dist/components/console/CommandConsole.svelte +8 -0
  20. package/dist/components/console/formatters.d.ts +9 -1
  21. package/dist/components/console/formatters.js +54 -0
  22. package/dist/core/index.d.ts +1 -1
  23. package/dist/messages/context.d.ts +6 -0
  24. package/dist/messages/context.js +8 -0
  25. package/dist/messages/defaults.d.ts +78 -2
  26. package/dist/messages/defaults.js +50 -3
  27. package/dist/messages/index.d.ts +1 -1
  28. package/dist/messages/index.js +1 -1
  29. package/dist/services/globalSave.d.ts +7 -1
  30. package/dist/services/globalSave.js +17 -3
  31. package/dist/stores/instanceContainer.svelte.d.ts +26 -0
  32. package/dist/stores/instanceContainer.svelte.js +24 -0
  33. package/dist/stores/workflowStore.svelte.d.ts +10 -0
  34. package/dist/stores/workflowStore.svelte.js +15 -0
  35. package/dist/stories/WebMCPFakeAgent.svelte +229 -0
  36. package/dist/stories/WebMCPFakeAgent.svelte.d.ts +10 -0
  37. package/dist/styles/base.css +4 -2
  38. package/dist/styles/tokens.css +6 -0
  39. package/dist/svelte-app.d.ts +24 -2
  40. package/dist/svelte-app.js +65 -3
  41. package/dist/types/index.d.ts +49 -0
  42. package/dist/utils/focus.d.ts +18 -0
  43. package/dist/utils/focus.js +24 -0
  44. package/dist/utils/whenWorkflowLoaded.svelte.d.ts +17 -0
  45. package/dist/utils/whenWorkflowLoaded.svelte.js +42 -0
  46. package/dist/utils/workflowInterface.d.ts +47 -3
  47. package/dist/utils/workflowInterface.js +84 -9
  48. package/dist/webmcp/WebMCP.stories.svelte +101 -0
  49. package/dist/webmcp/WebMCP.stories.svelte.d.ts +18 -0
  50. package/dist/webmcp/WebMCPConfirm.svelte +216 -0
  51. package/dist/webmcp/WebMCPConfirm.svelte.d.ts +21 -0
  52. package/dist/webmcp/bridge.d.ts +63 -0
  53. package/dist/webmcp/bridge.js +106 -0
  54. package/dist/webmcp/descriptors.d.ts +59 -0
  55. package/dist/webmcp/descriptors.js +504 -0
  56. package/dist/webmcp/fake.d.ts +23 -0
  57. package/dist/webmcp/fake.js +42 -0
  58. package/dist/webmcp/gate.d.ts +76 -0
  59. package/dist/webmcp/gate.js +188 -0
  60. package/dist/webmcp/index.d.ts +36 -0
  61. package/dist/webmcp/index.js +32 -0
  62. package/dist/webmcp/register.d.ts +33 -0
  63. package/dist/webmcp/register.js +504 -0
  64. package/dist/webmcp/types.d.ts +268 -0
  65. package/dist/webmcp/types.js +23 -0
  66. package/dist/webmcp/validate.d.ts +32 -0
  67. package/dist/webmcp/validate.js +118 -0
  68. package/package.json +6 -1
@@ -445,8 +445,6 @@ export const defaultMessages = {
445
445
  outputsHeading: 'Outputs',
446
446
  addInput: 'Add input',
447
447
  addOutput: 'Add output',
448
- noInputs: 'No inputs declared yet.',
449
- noOutputs: 'No outputs declared yet.',
450
448
  idLabel: 'ID',
451
449
  nameLabel: 'Name',
452
450
  descriptionLabel: 'Description',
@@ -463,12 +461,61 @@ export const defaultMessages = {
463
461
  removeExample: 'Remove example',
464
462
  bindingLabel: 'Bound port',
465
463
  bindingUnbound: 'Not bound',
464
+ bindingChange: 'Change the bound port',
465
+ bindingChoose: 'Choose a port to bind',
466
+ bindingCurrent: 'Current',
467
+ bindingUnbind: 'Unbind',
468
+ bindingDangling: ({ nodeId, portId }) => `${nodeId} › ${portId} (missing)`,
466
469
  moreOptions: 'More options',
467
470
  pullFromPort: 'Pull from port',
468
471
  pullFromPortTitle: "Fill name, data type, description, required and default from the bound port's own declaration",
469
472
  removeEntry: ({ id }) => `Remove interface entry "${id}"`,
470
473
  moveUp: ({ id }) => `Move "${id}" up`,
471
474
  moveDown: ({ id }) => `Move "${id}" down`,
472
- metaDisclosure: 'Server metadata (read-only)'
475
+ metaDisclosure: 'Server metadata (read-only)',
476
+ // The inline composer that opens from "Add input" / "Add output".
477
+ composerTitleInput: 'New input',
478
+ composerTitleOutput: 'New output',
479
+ composerStep: ({ step, total }) => `Step ${step} of ${total}`,
480
+ composerClose: 'Close without adding',
481
+ composerQuestion: 'Bind it to an existing port?',
482
+ composerBindYes: 'Yes, bind to a port',
483
+ composerBindYesHint: 'Pick an exposed port. The entry takes its id, name, type and description from it.',
484
+ composerBindNo: 'No, add a custom entry',
485
+ composerBindNoHint: 'Start with an empty entry. Bind it later, or leave it unbound.',
486
+ composerSearchLabel: 'Search ports',
487
+ composerSearchPlaceholder: 'Search by node, port or type…',
488
+ composerListLabelInput: 'Exposed input ports',
489
+ composerListLabelOutput: 'Exposed output ports',
490
+ composerGroupFree: 'Available',
491
+ composerGroupTaken: 'Connected or already published',
492
+ composerNoPorts: 'No exposed ports to bind yet. Expose a port on a node first.',
493
+ composerNoMatches: 'No ports match your search.',
494
+ composerConnected: 'Connected',
495
+ composerPublishedAs: ({ id }) => `Published as ${id}`,
496
+ composerRequired: 'Required',
497
+ composerBack: 'Back',
498
+ composerCancel: 'Cancel'
499
+ },
500
+ // The confirm dialog the WebMCP adapter shows before a browser agent's change runs.
501
+ webmcp: {
502
+ confirmTitle: ({ name }) => `A browser agent wants to change “${name}”`,
503
+ confirmCount: ({ count }) => `${count === 1 ? '1 change' : `${count} changes`} — applied together, undone together.`,
504
+ reject: 'Reject',
505
+ apply: 'Apply',
506
+ saveLine: ({ name }) => `Save “${name}” to the server`,
507
+ saveHint: 'Writes the workflow to the server. This cannot be undone from the editor.',
508
+ runLine: ({ name }) => `Run “${name}” on the server`,
509
+ runHint: 'Starts a run of the saved workflow. Unsaved changes are not part of it.',
510
+ /** One clause per kind of change; joined into the batch summary. */
511
+ summaryAdds: ({ count }) => `adds ${count} ${count === 1 ? 'node' : 'nodes'}`,
512
+ summaryDeletes: ({ count }) => `deletes ${count} ${count === 1 ? 'node' : 'nodes'}`,
513
+ summaryConnects: ({ count }) => `connects ${count} ${count === 1 ? 'edge' : 'edges'}`,
514
+ summaryDisconnects: ({ count }) => `removes ${count} ${count === 1 ? 'edge' : 'edges'}`,
515
+ summaryConfigs: ({ count }) => `sets ${count} config ${count === 1 ? 'key' : 'keys'}`,
516
+ summaryOther: ({ count }) => `${count} other ${count === 1 ? 'change' : 'changes'}`,
517
+ /** `{count} changes — adds 2 nodes, connects 1 edge. Applied together, undone together.` */
518
+ batchSummary: ({ count, parts }) => `${count} changes — ${parts}. Applied together, undone together.`,
519
+ rememberEdits: 'Apply further edits from any agent on this page without asking, until this page is closed'
473
520
  }
474
521
  };
@@ -6,5 +6,5 @@
6
6
  */
7
7
  export { defaultMessages } from './defaults.js';
8
8
  export { mergeMessages } from './merge.js';
9
- export { setMessages, getMessages, m } from './context.js';
9
+ export { setMessages, getMessages, messagesContext, m } from './context.js';
10
10
  export type { Messages, MessagesOverride, DeepPartial } from './types.js';
@@ -6,4 +6,4 @@
6
6
  */
7
7
  export { defaultMessages } from './defaults.js';
8
8
  export { mergeMessages } from './merge.js';
9
- export { setMessages, getMessages, m } from './context.js';
9
+ export { setMessages, getMessages, messagesContext, m } from './context.js';
@@ -65,7 +65,13 @@ export interface GlobalExportOptions {
65
65
  * 6. Call onMarkAsSaved / onAfterSave hooks
66
66
  * 7. Show toast notifications (respecting features.showToasts)
67
67
  */
68
- export declare function globalSaveWorkflow(options?: GlobalSaveOptions): Promise<void>;
68
+ /**
69
+ * Resolves `true` when the workflow was written, `false` when nothing was
70
+ * saved because there was no workflow or `onBeforeSave` cancelled. A failed
71
+ * request throws. Callers that relay the outcome (the WebMCP `save` tool)
72
+ * must not read a quiet return as a save.
73
+ */
74
+ export declare function globalSaveWorkflow(options?: GlobalSaveOptions): Promise<boolean>;
69
75
  /**
70
76
  * Export the current workflow as a downloadable JSON file.
71
77
  *
@@ -73,6 +73,12 @@ async function flushPendingFormChanges() {
73
73
  * 6. Call onMarkAsSaved / onAfterSave hooks
74
74
  * 7. Show toast notifications (respecting features.showToasts)
75
75
  */
76
+ /**
77
+ * Resolves `true` when the workflow was written, `false` when nothing was
78
+ * saved because there was no workflow or `onBeforeSave` cancelled. A failed
79
+ * request throws. Callers that relay the outcome (the WebMCP `save` tool)
80
+ * must not read a quiet return as a save.
81
+ */
76
82
  export async function globalSaveWorkflow(options = {}) {
77
83
  const { eventHandlers, onMarkAsSaved, onSaved } = options;
78
84
  const features = { ...DEFAULT_FEATURES, ...options.features };
@@ -87,13 +93,13 @@ export async function globalSaveWorkflow(options = {}) {
87
93
  if (features.showToasts) {
88
94
  apiToasts.error('Save workflow', 'No workflow to save');
89
95
  }
90
- return;
96
+ return false;
91
97
  }
92
98
  // Step 2 — Allow the parent to cancel the save
93
99
  if (eventHandlers?.onBeforeSave) {
94
100
  const shouldContinue = await eventHandlers.onBeforeSave(currentWorkflow);
95
101
  if (shouldContinue === false) {
96
- return;
102
+ return false;
97
103
  }
98
104
  }
99
105
  const loadingToast = features.showToasts ? apiToasts.loading('Saving workflow') : null;
@@ -124,7 +130,10 @@ export async function globalSaveWorkflow(options = {}) {
124
130
  // Explicit key list, so every contract field must be named here:
125
131
  // omitting `interface` silently strips the declared contract on save
126
132
  // (absent means "declares no interface" to the server).
127
- ...(currentWorkflow.interface !== undefined && { interface: currentWorkflow.interface })
133
+ ...(currentWorkflow.interface !== undefined && { interface: currentWorkflow.interface }),
134
+ // The revision the editor loaded, so a server that checks it can refuse
135
+ // a stale write (409 CONFLICT) instead of letting the last write win.
136
+ ...(currentWorkflow.revision !== undefined && { revision: currentWorkflow.revision })
128
137
  };
129
138
  // Step 4 — Persist via this instance's API client.
130
139
  // id-presence (computed above) decides update vs create — never UUID-regex.
@@ -144,6 +153,10 @@ export async function globalSaveWorkflow(options = {}) {
144
153
  }
145
154
  });
146
155
  }
156
+ // Step 5b — The save minted a new revision (and may have refreshed what the
157
+ // user may do); take the server's word so the next save sends the current
158
+ // stamp rather than the one this save just superseded.
159
+ fd.workflow.acknowledgeServer({ revision: savedWorkflow.revision, can: savedWorkflow.can });
147
160
  // Step 6a — Mark dirty state as clean
148
161
  if (onMarkAsSaved) {
149
162
  onMarkAsSaved();
@@ -165,6 +178,7 @@ export async function globalSaveWorkflow(options = {}) {
165
178
  if (eventHandlers?.onAfterSave) {
166
179
  await eventHandlers.onAfterSave(savedWorkflow);
167
180
  }
181
+ return true;
168
182
  }
169
183
  catch (error) {
170
184
  if (loadingToast)
@@ -13,6 +13,7 @@
13
13
  *
14
14
  * @module stores/instanceContainer
15
15
  */
16
+ import type { NodeMetadata } from '../types/index.js';
16
17
  import { HistoryService } from '../services/historyService.js';
17
18
  import { WorkflowStore } from './workflowStore.svelte.js';
18
19
  import { HistoryStore } from './historyStore.svelte.js';
@@ -76,6 +77,20 @@ export interface FlowDropInstance {
76
77
  readonly portCoordinates: PortCoordinateStore;
77
78
  /** Pipeline panel open/close state (instance-scoped persistence). */
78
79
  readonly pipelinePanel: PipelinePanelStore;
80
+ /**
81
+ * The node types this editor currently knows: what `App` fetched (or was
82
+ * given), merged with the format-provided nodes. Written by the editor as
83
+ * its fetch lands; read by anything that needs the list without fetching
84
+ * again (the WebMCP adapter's `list_types`, `add_node`).
85
+ */
86
+ readonly nodeTypes: NodeTypesStore;
87
+ /**
88
+ * Run `fn` when this instance is destroyed. Returns an unsubscribe; calling
89
+ * it before `destroy()` means `fn` never runs. Adapters that bind to an
90
+ * instance (WebMCP, host integrations) hook their teardown here instead of
91
+ * wrapping `destroy`.
92
+ */
93
+ onDestroy(fn: () => void): () => void;
79
94
  /**
80
95
  * Dispose all per-instance resources (subscriptions, effect roots,
81
96
  * external callbacks). Safe to call more than once. Must not touch
@@ -83,6 +98,17 @@ export interface FlowDropInstance {
83
98
  */
84
99
  destroy(): void;
85
100
  }
101
+ /**
102
+ * The instance's node-type list. A getter and a setter over one `$state`, so
103
+ * a reader inside an effect tracks it and a reader outside one just gets the
104
+ * current array.
105
+ */
106
+ export declare class NodeTypesStore {
107
+ #private;
108
+ /** The list as last set; empty until the editor's fetch lands. */
109
+ get current(): NodeMetadata[];
110
+ set(list: NodeMetadata[]): void;
111
+ }
86
112
  export interface CreateInstanceOptions {
87
113
  /** Explicit instance id; auto-generated (`fd-<n>`) when omitted. */
88
114
  id?: string;
@@ -31,6 +31,21 @@ import { BUILTIN_NODE_COMPONENTS } from '../registry/builtinNodes.js';
31
31
  import { getBuiltinFormatAdapters } from '../registry/builtinFormats.js';
32
32
  /** Storage key prefix shared by the default instance and legacy consumers. */
33
33
  export const DEFAULT_DRAFT_PREFIX = 'flowdrop:draft';
34
+ /**
35
+ * The instance's node-type list. A getter and a setter over one `$state`, so
36
+ * a reader inside an effect tracks it and a reader outside one just gets the
37
+ * current array.
38
+ */
39
+ export class NodeTypesStore {
40
+ #list = $state([]);
41
+ /** The list as last set; empty until the editor's fetch lands. */
42
+ get current() {
43
+ return this.#list;
44
+ }
45
+ set(list) {
46
+ this.#list = list;
47
+ }
48
+ }
34
49
  // Feeds auto-generated ids only (`fd-1`, `fd-2`, …) — cosmetic monotonicity.
35
50
  // Incrementing across SSR requests is harmless; no state hangs off the value.
36
51
  let instanceCounter = 0;
@@ -89,6 +104,15 @@ export function createFlowDropInstance(options = {}) {
89
104
  portCompatibility: new PortCompatibilityChecker(DEFAULT_PORT_CONFIG),
90
105
  // The default instance keeps the legacy bare localStorage key.
91
106
  pipelinePanel: new PipelinePanelStore(id),
107
+ nodeTypes: new NodeTypesStore(),
108
+ onDestroy(fn) {
109
+ cleanups.push(fn);
110
+ return () => {
111
+ const i = cleanups.indexOf(fn);
112
+ if (i !== -1)
113
+ cleanups.splice(i, 1);
114
+ };
115
+ },
92
116
  destroy() {
93
117
  while (cleanups.length > 0) {
94
118
  cleanups.pop()?.();
@@ -180,6 +180,16 @@ export declare class WorkflowStore {
180
180
  * Call this after a successful backend save.
181
181
  */
182
182
  markAsSaved(): void;
183
+ /**
184
+ * Take the server's word on the workflow's revision and permissions after a
185
+ * save (the load path sets them with the payload). Bookkeeping only: no history entry, no dirty flag, no
186
+ * change notification — the document the user edits is unchanged. Keys the
187
+ * server did not send are left as they were.
188
+ */
189
+ acknowledgeServer(state: {
190
+ revision?: Workflow['revision'];
191
+ can?: Workflow['can'];
192
+ }): void;
183
193
  /**
184
194
  * Set the restoring from history flag.
185
195
  *
@@ -324,6 +324,21 @@ export class WorkflowStore {
324
324
  this.#onDirtyStateChange(false);
325
325
  }
326
326
  }
327
+ /**
328
+ * Take the server's word on the workflow's revision and permissions after a
329
+ * save (the load path sets them with the payload). Bookkeeping only: no history entry, no dirty flag, no
330
+ * change notification — the document the user edits is unchanged. Keys the
331
+ * server did not send are left as they were.
332
+ */
333
+ acknowledgeServer(state) {
334
+ if (!this.#workflow)
335
+ return;
336
+ this.#workflow = {
337
+ ...this.#workflow,
338
+ ...(state.revision !== undefined && { revision: state.revision }),
339
+ ...(state.can !== undefined && { can: state.can })
340
+ };
341
+ }
327
342
  /**
328
343
  * Set the restoring from history flag.
329
344
  *
@@ -0,0 +1,229 @@
1
+ <!--
2
+ WebMCPFakeAgent
3
+
4
+ Storybook harness for the WebMCP adapter. Mounts a full editor, attaches the
5
+ editor tools to a fake `modelContext`, and shows a side panel that plays the
6
+ browser agent: pick a tool, type its JSON arguments, invoke it, read the
7
+ result. The approval dialog appears exactly as it would for a real agent, so
8
+ the gate and the results are visible to a human without Chrome's origin trial.
9
+ -->
10
+
11
+ <script lang="ts">
12
+ import { onMount, untrack } from 'svelte';
13
+ import App from '../components/App.svelte';
14
+ import { createFlowDropInstance } from '../stores/instanceContainer.svelte.js';
15
+ import { attachWebMCP } from '../webmcp/register.js';
16
+ import { createFakeModelContext } from '../webmcp/fake.js';
17
+ import type { WebMCPApproval, WebMCPHandle } from '../webmcp/types.js';
18
+ import type { NodeMetadata, Workflow } from '../types/index.js';
19
+
20
+ interface Props {
21
+ nodes: NodeMetadata[];
22
+ workflow: Workflow;
23
+ approval?: WebMCPApproval;
24
+ }
25
+
26
+ let { nodes, workflow, approval = 'confirm' }: Props = $props();
27
+
28
+ const fd = createFlowDropInstance({ id: 'webmcp-story' });
29
+ // Seed once; later prop changes are the story's business, not the editor's.
30
+ fd.workflow.initialize(untrack(() => workflow));
31
+
32
+ const runtime = createFakeModelContext();
33
+ let handle = $state<WebMCPHandle | null>(null);
34
+ let toolNames = $state<string[]>([]);
35
+ let selected = $state('flowdrop_list_types');
36
+ let argsText = $state('{}');
37
+ let log = $state<Array<{ tool: string; args: string; result: string; error: boolean }>>([]);
38
+ let running = $state(false);
39
+
40
+ const SAMPLES: Record<string, string> = {
41
+ flowdrop_list_types: '{}',
42
+ flowdrop_list_nodes: '{}',
43
+ flowdrop_info: '{ "nodeId": "chat_model.1" }',
44
+ flowdrop_add_node: '{ "nodeTypeId": "chat_model" }',
45
+ flowdrop_set_config: '{ "nodeId": "chat_model.1", "key": "model", "value": "gpt-4o-mini" }',
46
+ flowdrop_connect:
47
+ '{ "sourceNodeId": "text_input.1", "sourcePort": "value", "targetNodeId": "chat_model.1", "targetPort": "message" }',
48
+ flowdrop_batch:
49
+ '{ "commands": [\n { "type": "add_node", "nodeTypeId": "chat_model" },\n { "type": "add_node", "nodeTypeId": "chat_output" }\n] }',
50
+ flowdrop_undo: '{}'
51
+ };
52
+
53
+ onMount(() => {
54
+ handle = attachWebMCP(fd, { nodeTypes: () => nodes, approval, modelContext: runtime });
55
+ const sync = () => (toolNames = [...runtime.tools.keys()]);
56
+ sync();
57
+ const off = runtime.onToolChange(sync);
58
+ return () => {
59
+ off();
60
+ handle?.detach();
61
+ };
62
+ });
63
+
64
+ function pick(name: string): void {
65
+ selected = name;
66
+ argsText = SAMPLES[name] ?? '{}';
67
+ }
68
+
69
+ async function invoke(): Promise<void> {
70
+ let input: unknown;
71
+ try {
72
+ input = JSON.parse(argsText || '{}');
73
+ } catch (err) {
74
+ log = [{ tool: selected, args: argsText, result: String(err), error: true }, ...log];
75
+ return;
76
+ }
77
+ running = true;
78
+ try {
79
+ const result = await runtime.executeTool(selected, input);
80
+ const pretty = JSON.stringify(JSON.parse(result.content[0].text), null, 2);
81
+ log = [{ tool: selected, args: argsText, result: pretty, error: !!result.isError }, ...log];
82
+ } finally {
83
+ running = false;
84
+ }
85
+ }
86
+ </script>
87
+
88
+ <div class="webmcp-story">
89
+ <div class="webmcp-story__editor">
90
+ <App instance={fd} {nodes} {workflow} height="100%" />
91
+ </div>
92
+
93
+ <aside class="webmcp-story__agent">
94
+ <h3 class="webmcp-story__title">Fake browser agent</h3>
95
+ <p class="webmcp-story__hint">
96
+ {toolNames.length} tools registered on <code>document.modelContext</code> (fake). Reads run at
97
+ once; changes ask first{approval === 'auto' ? ' — except here: approval is auto' : ''}.
98
+ </p>
99
+
100
+ <label class="webmcp-story__label">
101
+ Tool
102
+ <select
103
+ class="webmcp-story__select"
104
+ data-testid="webmcp-tool"
105
+ value={selected}
106
+ onchange={(e) => pick((e.currentTarget as HTMLSelectElement).value)}
107
+ >
108
+ {#each toolNames as name (name)}
109
+ <option value={name}>{name}</option>
110
+ {/each}
111
+ </select>
112
+ </label>
113
+
114
+ <label class="webmcp-story__label">
115
+ Arguments (JSON)
116
+ <textarea class="webmcp-story__args" data-testid="webmcp-args" rows="5" bind:value={argsText}
117
+ ></textarea>
118
+ </label>
119
+
120
+ <button
121
+ type="button"
122
+ class="webmcp-story__invoke"
123
+ data-testid="webmcp-invoke"
124
+ disabled={running || !handle}
125
+ onclick={invoke}
126
+ >
127
+ {running ? 'Waiting…' : 'Invoke'}
128
+ </button>
129
+
130
+ <ol class="webmcp-story__log" data-testid="webmcp-log">
131
+ {#each log as entry, i (log.length - i)}
132
+ <li class="webmcp-story__entry" class:webmcp-story__entry--error={entry.error}>
133
+ <div class="webmcp-story__call">{entry.tool} {entry.args}</div>
134
+ <pre class="webmcp-story__result">{entry.result}</pre>
135
+ </li>
136
+ {/each}
137
+ </ol>
138
+ </aside>
139
+ </div>
140
+
141
+ <style>
142
+ .webmcp-story {
143
+ display: grid;
144
+ grid-template-columns: minmax(0, 1fr) 22rem;
145
+ height: 100vh;
146
+ font-family: system-ui, sans-serif;
147
+ }
148
+ .webmcp-story__editor {
149
+ min-width: 0;
150
+ height: 100%;
151
+ }
152
+ .webmcp-story__agent {
153
+ display: flex;
154
+ flex-direction: column;
155
+ gap: 0.5rem;
156
+ padding: 0.75rem;
157
+ border-left: 1px solid #e4e4e7;
158
+ background: #fafafa;
159
+ overflow: auto;
160
+ font-size: 0.8125rem;
161
+ }
162
+ .webmcp-story__title {
163
+ margin: 0;
164
+ font-size: 0.9375rem;
165
+ }
166
+ .webmcp-story__hint {
167
+ margin: 0;
168
+ color: #71717a;
169
+ }
170
+ .webmcp-story__label {
171
+ display: flex;
172
+ flex-direction: column;
173
+ gap: 0.25rem;
174
+ font-weight: 600;
175
+ }
176
+ .webmcp-story__select,
177
+ .webmcp-story__args {
178
+ font: inherit;
179
+ font-family: ui-monospace, monospace;
180
+ font-weight: 400;
181
+ padding: 0.375rem;
182
+ border: 1px solid #d4d4d8;
183
+ border-radius: 0.375rem;
184
+ background: #fff;
185
+ }
186
+ .webmcp-story__invoke {
187
+ align-self: flex-start;
188
+ padding: 0.375rem 0.75rem;
189
+ border: 1px solid #2563eb;
190
+ border-radius: 0.375rem;
191
+ background: #2563eb;
192
+ color: #fff;
193
+ font: inherit;
194
+ cursor: pointer;
195
+ }
196
+ .webmcp-story__invoke:disabled {
197
+ opacity: 0.6;
198
+ cursor: default;
199
+ }
200
+ .webmcp-story__log {
201
+ margin: 0;
202
+ padding: 0;
203
+ list-style: none;
204
+ display: flex;
205
+ flex-direction: column;
206
+ gap: 0.5rem;
207
+ }
208
+ .webmcp-story__entry {
209
+ padding: 0.5rem;
210
+ border: 1px solid #e4e4e7;
211
+ border-radius: 0.375rem;
212
+ background: #fff;
213
+ }
214
+ .webmcp-story__entry--error {
215
+ border-color: #fca5a5;
216
+ }
217
+ .webmcp-story__call {
218
+ font-family: ui-monospace, monospace;
219
+ font-weight: 600;
220
+ margin-bottom: 0.25rem;
221
+ overflow-wrap: anywhere;
222
+ }
223
+ .webmcp-story__result {
224
+ margin: 0;
225
+ font-size: 0.75rem;
226
+ white-space: pre-wrap;
227
+ overflow-wrap: anywhere;
228
+ }
229
+ </style>
@@ -0,0 +1,10 @@
1
+ import type { WebMCPApproval } from '../webmcp/types.js';
2
+ import type { NodeMetadata, Workflow } from '../types/index.js';
3
+ interface Props {
4
+ nodes: NodeMetadata[];
5
+ workflow: Workflow;
6
+ approval?: WebMCPApproval;
7
+ }
8
+ declare const WebMCPFakeAgent: import("svelte").Component<Props, {}, "">;
9
+ type WebMCPFakeAgent = ReturnType<typeof WebMCPFakeAgent>;
10
+ export default WebMCPFakeAgent;
@@ -224,9 +224,11 @@ p {
224
224
  }
225
225
 
226
226
  .flowdrop-btn--sm {
227
- padding: var(--fd-space-2xs) var(--fd-space-md);
227
+ /* Same height as IconButton's sm (--fd-size-icon-btn), so the two sit on one
228
+ line without callers overriding either. */
229
+ padding: 0 var(--fd-space-md);
228
230
  font-size: var(--fd-text-xs);
229
- min-height: 2rem;
231
+ min-height: var(--fd-size-icon-btn);
230
232
  }
231
233
 
232
234
  .flowdrop-btn--lg {
@@ -282,6 +282,12 @@
282
282
  --fd-leading-relaxed: 1.6; /* @public */
283
283
 
284
284
  /* ----- FONT FAMILIES ----- */
285
+ /* The editor inherits the host page's font. This stack is for UI the
286
+ library mounts outside the editor's subtree (the WebMCP confirm dialog
287
+ on document.body), where "inherit" means whatever the host's body has —
288
+ on Drupal admin themes, the browser's serif fallback. */
289
+ --fd-font-sans:
290
+ system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; /* @public */
285
291
  --fd-font-mono:
286
292
  ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace; /* @public */
287
293
 
@@ -16,7 +16,9 @@ import { type FlowDropInstance } from './stores/instanceContainer.svelte.js';
16
16
  import { type DraftStorageOption } from './services/draftStorage.js';
17
17
  import type { PartialSettings, SettingsCategory, SurfacePlacement } from './types/settings.js';
18
18
  import type { NavbarAction } from './types/navbar.js';
19
+ import type { WebMCPHandle, WebMCPMountOptions } from './webmcp/types.js';
19
20
  export type { NavbarAction };
21
+ export type { WebMCPHandle, WebMCPMountOptions };
20
22
  /**
21
23
  * Mount options for FlowDrop App
22
24
  */
@@ -129,6 +131,16 @@ export interface FlowDropMountOptions {
129
131
  * enabled, so keys stay stable across page loads.
130
132
  */
131
133
  instanceId?: string;
134
+ /**
135
+ * Expose the editor's commands as WebMCP **editor tools** for a
136
+ * browser-resident agent (Chrome 149+ / Edge 150+ origin trial, Brave Leo,
137
+ * ChatGPT Desktop). `true` uses the defaults — prefix `flowdrop`, mutations
138
+ * behind a confirm dialog; pass a {@link WebMCPMountOptions} to change them.
139
+ * The adapter is loaded on demand (`@flowdrop/flowdrop/webmcp`), so the
140
+ * core bundle is unchanged when this is off. No-op in browsers without the
141
+ * API. Default off.
142
+ */
143
+ webmcp?: boolean | WebMCPMountOptions;
132
144
  }
133
145
  /**
134
146
  * Return type for mounted FlowDrop app
@@ -159,9 +171,11 @@ export interface MountedFlowDropApp {
159
171
  */
160
172
  getWorkflow: () => Workflow | null;
161
173
  /**
162
- * Trigger save operation
174
+ * Trigger save operation. Resolves `true` when the workflow was written,
175
+ * `false` when the save was cancelled (`onBeforeSave`) or there was nothing
176
+ * to save; rejects when the request failed.
163
177
  */
164
- save: () => Promise<void>;
178
+ save: () => Promise<boolean>;
165
179
  /**
166
180
  * Trigger export operation (downloads JSON)
167
181
  */
@@ -178,6 +192,14 @@ export interface MountedFlowDropApp {
178
192
  * @returns The number of entries removed.
179
193
  */
180
194
  clearAllDrafts: () => number;
195
+ /**
196
+ * The WebMCP registration when the `webmcp` mount option was set and the
197
+ * browser has the API; `undefined` otherwise. The adapter attaches in the
198
+ * background once the workflow is loaded, so this is `undefined` for a
199
+ * moment after mount even when the API exists. Detached automatically on
200
+ * `destroy()`.
201
+ */
202
+ readonly webmcp?: WebMCPHandle;
181
203
  }
182
204
  /**
183
205
  * Mount the full FlowDrop App with navbar, sidebars, and workflow editor