@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.
- package/CHANGELOG.md +59 -0
- package/dist/chat/commandClassifier.d.ts +19 -1
- package/dist/chat/commandClassifier.js +33 -1
- package/dist/chat/index.d.ts +1 -1
- package/dist/chat/index.js +1 -1
- package/dist/commands/executor.js +270 -37
- package/dist/commands/index.d.ts +1 -1
- package/dist/commands/parser.js +20 -0
- package/dist/commands/types.d.ts +77 -12
- package/dist/components/App.svelte +8 -0
- package/dist/components/BindablePortListbox.svelte +426 -0
- package/dist/components/BindablePortListbox.svelte.d.ts +23 -0
- package/dist/components/WorkflowInterfaceEditor.svelte +142 -36
- package/dist/components/WorkflowInterfaceEditor.svelte.d.ts +8 -0
- package/dist/components/WorkflowInterfaceEntryCard.svelte +537 -294
- package/dist/components/WorkflowInterfaceEntryCard.svelte.d.ts +6 -3
- package/dist/components/WorkflowInterfaceEntryComposer.svelte +331 -0
- package/dist/components/WorkflowInterfaceEntryComposer.svelte.d.ts +19 -0
- package/dist/components/console/CommandConsole.svelte +8 -0
- package/dist/components/console/formatters.d.ts +9 -1
- package/dist/components/console/formatters.js +54 -0
- package/dist/core/index.d.ts +1 -1
- package/dist/messages/context.d.ts +6 -0
- package/dist/messages/context.js +8 -0
- package/dist/messages/defaults.d.ts +78 -2
- package/dist/messages/defaults.js +50 -3
- package/dist/messages/index.d.ts +1 -1
- package/dist/messages/index.js +1 -1
- package/dist/services/globalSave.d.ts +7 -1
- package/dist/services/globalSave.js +17 -3
- package/dist/stores/instanceContainer.svelte.d.ts +26 -0
- package/dist/stores/instanceContainer.svelte.js +24 -0
- package/dist/stores/workflowStore.svelte.d.ts +10 -0
- package/dist/stores/workflowStore.svelte.js +15 -0
- package/dist/stories/WebMCPFakeAgent.svelte +229 -0
- package/dist/stories/WebMCPFakeAgent.svelte.d.ts +10 -0
- package/dist/styles/base.css +4 -2
- package/dist/styles/tokens.css +6 -0
- package/dist/svelte-app.d.ts +24 -2
- package/dist/svelte-app.js +65 -3
- package/dist/types/index.d.ts +49 -0
- package/dist/utils/focus.d.ts +18 -0
- package/dist/utils/focus.js +24 -0
- package/dist/utils/whenWorkflowLoaded.svelte.d.ts +17 -0
- package/dist/utils/whenWorkflowLoaded.svelte.js +42 -0
- package/dist/utils/workflowInterface.d.ts +47 -3
- package/dist/utils/workflowInterface.js +84 -9
- package/dist/webmcp/WebMCP.stories.svelte +101 -0
- package/dist/webmcp/WebMCP.stories.svelte.d.ts +18 -0
- package/dist/webmcp/WebMCPConfirm.svelte +216 -0
- package/dist/webmcp/WebMCPConfirm.svelte.d.ts +21 -0
- package/dist/webmcp/bridge.d.ts +63 -0
- package/dist/webmcp/bridge.js +106 -0
- package/dist/webmcp/descriptors.d.ts +59 -0
- package/dist/webmcp/descriptors.js +504 -0
- package/dist/webmcp/fake.d.ts +23 -0
- package/dist/webmcp/fake.js +42 -0
- package/dist/webmcp/gate.d.ts +76 -0
- package/dist/webmcp/gate.js +188 -0
- package/dist/webmcp/index.d.ts +36 -0
- package/dist/webmcp/index.js +32 -0
- package/dist/webmcp/register.d.ts +33 -0
- package/dist/webmcp/register.js +504 -0
- package/dist/webmcp/types.d.ts +268 -0
- package/dist/webmcp/types.js +23 -0
- package/dist/webmcp/validate.d.ts +32 -0
- package/dist/webmcp/validate.js +118 -0
- package/package.json +6 -1
package/dist/svelte-app.js
CHANGED
|
@@ -18,6 +18,7 @@ import { mergeFeatures } from './types/events.js';
|
|
|
18
18
|
import { initializeSettings, getBehaviorSettings, onSettingsChange } from './stores/settingsStore.svelte.js';
|
|
19
19
|
import { logger } from './utils/logger.js';
|
|
20
20
|
import { globalSaveWorkflow, globalExportWorkflow } from './services/globalSave.js';
|
|
21
|
+
import { whenWorkflowLoaded } from './utils/whenWorkflowLoaded.svelte.js';
|
|
21
22
|
// ---------------------------------------------------------------------------
|
|
22
23
|
// Instance acquisition
|
|
23
24
|
// ---------------------------------------------------------------------------
|
|
@@ -107,6 +108,30 @@ async function configureInstance(fd, options) {
|
|
|
107
108
|
}
|
|
108
109
|
return config;
|
|
109
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Attach the WebMCP adapter for a `mountFlowDropApp` mount.
|
|
113
|
+
*
|
|
114
|
+
* Adds no request and no mount latency: node types are read lazily from the
|
|
115
|
+
* instance, which `App` fills from the same fetch it already makes (or from
|
|
116
|
+
* the mount's `nodes` option, seeded below), and attachment waits for the
|
|
117
|
+
* workflow to be known so every tool description names it. Resolves
|
|
118
|
+
* `undefined` when the browser has no WebMCP runtime or the mount was
|
|
119
|
+
* destroyed first.
|
|
120
|
+
*/
|
|
121
|
+
function attachWebMCPToMount(fd, options, isDestroyed) {
|
|
122
|
+
return new Promise((resolve) => {
|
|
123
|
+
// Dynamic imports keep the adapter and the rune helper out of the core
|
|
124
|
+
// entry's static graph (see scripts/check-bundle.mjs).
|
|
125
|
+
whenWorkflowLoaded(fd, async () => {
|
|
126
|
+
if (isDestroyed())
|
|
127
|
+
return resolve(undefined);
|
|
128
|
+
const { attachWebMCP } = await import('./webmcp/index.js');
|
|
129
|
+
if (isDestroyed())
|
|
130
|
+
return resolve(undefined);
|
|
131
|
+
resolve(attachWebMCP(fd, options) ?? undefined);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
}
|
|
110
135
|
/**
|
|
111
136
|
* Mount the full FlowDrop App with navbar, sidebars, and workflow editor
|
|
112
137
|
*
|
|
@@ -132,7 +157,7 @@ async function configureInstance(fd, options) {
|
|
|
132
157
|
* ```
|
|
133
158
|
*/
|
|
134
159
|
export async function mountFlowDropApp(container, options = {}) {
|
|
135
|
-
const { workflow, nodes, endpointConfig, portConfig, categories, height = '100vh', width = '100%', showNavbar = false, disableSidebar, configPlacement, consolePlacement, mode, pipelineId, navbarTitle, navbarActions, showSettings, showStatus, authProvider, eventHandlers, features: userFeatures, settings: initialSettings, draftStorageKey: customDraftKey, draftStorage, formatAdapters, workflowFormats, theme, settingsCategories, showSettingsSyncButton, showSettingsResetButton, instanceId } = options;
|
|
160
|
+
const { workflow, nodes, endpointConfig, portConfig, categories, height = '100vh', width = '100%', showNavbar = false, disableSidebar, configPlacement, consolePlacement, mode, pipelineId, navbarTitle, navbarActions, showSettings, showStatus, authProvider, eventHandlers, features: userFeatures, settings: initialSettings, draftStorageKey: customDraftKey, draftStorage, formatAdapters, workflowFormats, theme, settingsCategories, showSettingsSyncButton, showSettingsResetButton, instanceId, webmcp } = options;
|
|
136
161
|
// Per-instance state container — this is what allows multiple FlowDrop
|
|
137
162
|
// editors to coexist on one page without sharing workflow/history state.
|
|
138
163
|
const { fd, isDefault } = acquireInstance(instanceId);
|
|
@@ -170,6 +195,11 @@ export async function mountFlowDropApp(container, options = {}) {
|
|
|
170
195
|
if (eventHandlers?.onWorkflowChange) {
|
|
171
196
|
fd.workflow.setOnWorkflowChange(eventHandlers.onWorkflowChange);
|
|
172
197
|
}
|
|
198
|
+
// The mount's `nodes` seed the instance's node-type list; App replaces it
|
|
199
|
+
// with the merged (props + format nodes) list as soon as it has one.
|
|
200
|
+
if (nodes && nodes.length > 0) {
|
|
201
|
+
fd.nodeTypes.set(nodes);
|
|
202
|
+
}
|
|
173
203
|
// Create the Svelte App component with configuration
|
|
174
204
|
const svelteApp = mount(App, {
|
|
175
205
|
target: container,
|
|
@@ -251,10 +281,20 @@ export async function mountFlowDropApp(container, options = {}) {
|
|
|
251
281
|
eventHandlers: eventHandlers ?? null,
|
|
252
282
|
unsubscribeDraftSettings
|
|
253
283
|
};
|
|
284
|
+
// WebMCP editor tools, opt-in. Attached below, once `mountedApp` exists —
|
|
285
|
+
// its default `onSave` is `mountedApp.save()`.
|
|
286
|
+
let webmcpHandle;
|
|
287
|
+
let destroyed = false;
|
|
254
288
|
// Create the mounted app interface
|
|
255
289
|
const mountedApp = {
|
|
256
290
|
instance: fd,
|
|
291
|
+
get webmcp() {
|
|
292
|
+
return webmcpHandle;
|
|
293
|
+
},
|
|
257
294
|
destroy: () => {
|
|
295
|
+
// Remove the agent-facing tools before anything else goes away.
|
|
296
|
+
destroyed = true;
|
|
297
|
+
webmcpHandle?.detach();
|
|
258
298
|
// Call onBeforeUnmount if provided
|
|
259
299
|
if (state.eventHandlers?.onBeforeUnmount) {
|
|
260
300
|
const currentWorkflow = fd.workflow.current;
|
|
@@ -303,7 +343,7 @@ export async function mountFlowDropApp(container, options = {}) {
|
|
|
303
343
|
},
|
|
304
344
|
getWorkflow: () => fd.workflow.current,
|
|
305
345
|
save: async () => {
|
|
306
|
-
|
|
346
|
+
return globalSaveWorkflow({
|
|
307
347
|
instance: fd,
|
|
308
348
|
onSaved: (saved) => {
|
|
309
349
|
// globalSaveWorkflow does not write the server-assigned ID back to the
|
|
@@ -331,6 +371,28 @@ export async function mountFlowDropApp(container, options = {}) {
|
|
|
331
371
|
return removed;
|
|
332
372
|
}
|
|
333
373
|
};
|
|
374
|
+
// WebMCP editor tools, opt-in. Attaches in the background — mounting does
|
|
375
|
+
// not wait for it — and detaches with the mount. Defaults `onSave` to the
|
|
376
|
+
// mount's own Save so a browser agent's `save` tool persists exactly like
|
|
377
|
+
// clicking Save does; a host that supplies its own `onSave` overrides it.
|
|
378
|
+
if (webmcp) {
|
|
379
|
+
const webmcpOptions = {
|
|
380
|
+
onSave: async () => (await mountedApp.save())
|
|
381
|
+
? undefined
|
|
382
|
+
: {
|
|
383
|
+
ok: false,
|
|
384
|
+
code: 'UNAVAILABLE',
|
|
385
|
+
message: 'Nothing was saved: the host cancelled the save or no workflow is loaded.'
|
|
386
|
+
},
|
|
387
|
+
...(webmcp === true ? {} : webmcp)
|
|
388
|
+
};
|
|
389
|
+
void attachWebMCPToMount(fd, webmcpOptions, () => destroyed).then((handle) => {
|
|
390
|
+
if (destroyed)
|
|
391
|
+
handle?.detach();
|
|
392
|
+
else
|
|
393
|
+
webmcpHandle = handle;
|
|
394
|
+
});
|
|
395
|
+
}
|
|
334
396
|
return mountedApp;
|
|
335
397
|
}
|
|
336
398
|
/**
|
|
@@ -380,7 +442,7 @@ export async function mountWorkflowEditor(container, options = {}) {
|
|
|
380
442
|
markAsSaved: () => fd.workflow.markAsSaved(),
|
|
381
443
|
getWorkflow: () => fd.workflow.current,
|
|
382
444
|
save: async () => {
|
|
383
|
-
|
|
445
|
+
return globalSaveWorkflow({ instance: fd });
|
|
384
446
|
},
|
|
385
447
|
export: () => {
|
|
386
448
|
globalExportWorkflow({ instance: fd });
|
package/dist/types/index.d.ts
CHANGED
|
@@ -761,6 +761,43 @@ export interface NodeMetadata {
|
|
|
761
761
|
* Allows storing additional configuration and UI state data at the node type level
|
|
762
762
|
*/
|
|
763
763
|
extensions?: NodeExtensions;
|
|
764
|
+
/**
|
|
765
|
+
* The host's confirmation policy for instances of this type, when the host
|
|
766
|
+
* publishes one: whether a run pauses for a person before this node acts.
|
|
767
|
+
* Surfaced to browser agents by `describe_type`; the library never reads it.
|
|
768
|
+
*/
|
|
769
|
+
confirmation?: NodeConfirmation;
|
|
770
|
+
/**
|
|
771
|
+
* What the current user may do with this type, computed by the host and
|
|
772
|
+
* passed through untouched. `add: false` means `add_node` will be refused
|
|
773
|
+
* server-side; the tools pre-empt with `FORBIDDEN`.
|
|
774
|
+
*/
|
|
775
|
+
can?: Record<string, boolean>;
|
|
776
|
+
/**
|
|
777
|
+
* Guidance the host writes for agents reading this type — usage notes,
|
|
778
|
+
* example configurations, types it is usually wired to. Surfaced verbatim by
|
|
779
|
+
* `describe_type`; the library never interprets it.
|
|
780
|
+
*/
|
|
781
|
+
agent?: NodeAgentGuidance;
|
|
782
|
+
}
|
|
783
|
+
/**
|
|
784
|
+
* A host's confirmation policy for a node type (see `NodeMetadata.confirmation`).
|
|
785
|
+
*/
|
|
786
|
+
export interface NodeConfirmation {
|
|
787
|
+
/** `ask` — a run pauses for approval before the node acts; `skip` — it does not. */
|
|
788
|
+
policy: 'ask' | 'skip';
|
|
789
|
+
/** Where the policy came from: set on the type, or derived from the plugin. */
|
|
790
|
+
source?: 'policy' | 'plugin' | string;
|
|
791
|
+
/** Controls the instance author may exercise (e.g. `waive`, `require`). */
|
|
792
|
+
authorControls?: string[];
|
|
793
|
+
/** Controls a runtime input may exercise. */
|
|
794
|
+
dynamicControls?: string[];
|
|
795
|
+
}
|
|
796
|
+
/** Host-written guidance for agents (see `NodeMetadata.agent`). */
|
|
797
|
+
export interface NodeAgentGuidance {
|
|
798
|
+
usage?: string;
|
|
799
|
+
examples?: string[];
|
|
800
|
+
pairsWith?: string[];
|
|
764
801
|
}
|
|
765
802
|
/**
|
|
766
803
|
* Common base interface for all schema properties
|
|
@@ -1373,6 +1410,18 @@ export interface Workflow {
|
|
|
1373
1410
|
config?: Record<string, unknown>;
|
|
1374
1411
|
/** Public contract for callers. Absent = the workflow declares no interface. */
|
|
1375
1412
|
interface?: WorkflowInterface;
|
|
1413
|
+
/**
|
|
1414
|
+
* What the current user may do with this workflow, computed by the host and
|
|
1415
|
+
* passed through untouched (`save`, `run`, …). The browser-agent tools
|
|
1416
|
+
* pre-empt with `FORBIDDEN` when a key is `false`; the server stays the
|
|
1417
|
+
* authority either way.
|
|
1418
|
+
*/
|
|
1419
|
+
can?: Record<string, boolean>;
|
|
1420
|
+
/**
|
|
1421
|
+
* The revision the editor loaded, as the host stamps it. Sent back on save
|
|
1422
|
+
* so the server can refuse a stale write with `CONFLICT`.
|
|
1423
|
+
*/
|
|
1424
|
+
revision?: string | number;
|
|
1376
1425
|
}
|
|
1377
1426
|
/**
|
|
1378
1427
|
* API response types
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Focus attachments.
|
|
3
|
+
*
|
|
4
|
+
* `{@attach focusOnMount()}` moves keyboard focus to an element as it enters
|
|
5
|
+
* the DOM — a dialog's primary button, the first choice of a form that just
|
|
6
|
+
* opened, a listbox the author stepped into. An attachment rather than an
|
|
7
|
+
* `$effect` over a `bind:this` because focusing is a fact about the element's
|
|
8
|
+
* arrival, not about state: it runs once when the node mounts and never again.
|
|
9
|
+
*
|
|
10
|
+
* @module utils/focus
|
|
11
|
+
*/
|
|
12
|
+
import type { Attachment } from 'svelte/attachments';
|
|
13
|
+
/**
|
|
14
|
+
* Focus the element when it mounts. Pass `false` to switch it off at a call
|
|
15
|
+
* site that only sometimes wants focus (a listbox that is autofocused in one
|
|
16
|
+
* host and not in another).
|
|
17
|
+
*/
|
|
18
|
+
export declare function focusOnMount(enabled?: boolean): Attachment<HTMLElement>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Focus attachments.
|
|
3
|
+
*
|
|
4
|
+
* `{@attach focusOnMount()}` moves keyboard focus to an element as it enters
|
|
5
|
+
* the DOM — a dialog's primary button, the first choice of a form that just
|
|
6
|
+
* opened, a listbox the author stepped into. An attachment rather than an
|
|
7
|
+
* `$effect` over a `bind:this` because focusing is a fact about the element's
|
|
8
|
+
* arrival, not about state: it runs once when the node mounts and never again.
|
|
9
|
+
*
|
|
10
|
+
* @module utils/focus
|
|
11
|
+
*/
|
|
12
|
+
const noop = () => { };
|
|
13
|
+
/**
|
|
14
|
+
* Focus the element when it mounts. Pass `false` to switch it off at a call
|
|
15
|
+
* site that only sometimes wants focus (a listbox that is autofocused in one
|
|
16
|
+
* host and not in another).
|
|
17
|
+
*/
|
|
18
|
+
export function focusOnMount(enabled = true) {
|
|
19
|
+
if (!enabled)
|
|
20
|
+
return noop;
|
|
21
|
+
return (element) => {
|
|
22
|
+
element.focus();
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run a callback once an instance has a workflow.
|
|
3
|
+
*
|
|
4
|
+
* `fd.workflow.current` is `null` between `createFlowDropInstance()` and the
|
|
5
|
+
* editor's `initialize()`, which the `App` component runs on mount. Anything
|
|
6
|
+
* that wants the workflow's identity at set-up time — the WebMCP adapter puts
|
|
7
|
+
* the workflow's name in every tool description — waits here for it.
|
|
8
|
+
*
|
|
9
|
+
* Fires at once when the workflow is already known. Returns a cancel function
|
|
10
|
+
* for the case where the caller goes away first; after the callback has run
|
|
11
|
+
* the watcher has already disposed itself and cancel is a no-op.
|
|
12
|
+
*
|
|
13
|
+
* @module utils/whenWorkflowLoaded
|
|
14
|
+
*/
|
|
15
|
+
import type { FlowDropInstance } from '../stores/instanceContainer.svelte.js';
|
|
16
|
+
import type { Workflow } from '../types/index.js';
|
|
17
|
+
export declare function whenWorkflowLoaded(instance: FlowDropInstance, callback: (workflow: Workflow) => void): () => void;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run a callback once an instance has a workflow.
|
|
3
|
+
*
|
|
4
|
+
* `fd.workflow.current` is `null` between `createFlowDropInstance()` and the
|
|
5
|
+
* editor's `initialize()`, which the `App` component runs on mount. Anything
|
|
6
|
+
* that wants the workflow's identity at set-up time — the WebMCP adapter puts
|
|
7
|
+
* the workflow's name in every tool description — waits here for it.
|
|
8
|
+
*
|
|
9
|
+
* Fires at once when the workflow is already known. Returns a cancel function
|
|
10
|
+
* for the case where the caller goes away first; after the callback has run
|
|
11
|
+
* the watcher has already disposed itself and cancel is a no-op.
|
|
12
|
+
*
|
|
13
|
+
* @module utils/whenWorkflowLoaded
|
|
14
|
+
*/
|
|
15
|
+
export function whenWorkflowLoaded(instance, callback) {
|
|
16
|
+
const now = instance.workflow.current;
|
|
17
|
+
if (now) {
|
|
18
|
+
callback(now);
|
|
19
|
+
return () => { };
|
|
20
|
+
}
|
|
21
|
+
let done = false;
|
|
22
|
+
const dispose = $effect.root(() => {
|
|
23
|
+
$effect(() => {
|
|
24
|
+
const workflow = instance.workflow.current;
|
|
25
|
+
if (!workflow || done)
|
|
26
|
+
return;
|
|
27
|
+
done = true;
|
|
28
|
+
// Leave the effect before running user code, and dispose the root after
|
|
29
|
+
// it — disposing from inside the effect that is running is undefined.
|
|
30
|
+
queueMicrotask(() => {
|
|
31
|
+
dispose();
|
|
32
|
+
callback(workflow);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
return () => {
|
|
37
|
+
if (done)
|
|
38
|
+
return;
|
|
39
|
+
done = true;
|
|
40
|
+
dispose();
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -200,9 +200,53 @@ export interface BindablePort {
|
|
|
200
200
|
* Mirrors `FormPorts.svelte`'s port list: a node's static metadata ports plus
|
|
201
201
|
* its user-defined dynamic ports, filtered by `isPortExposed`.
|
|
202
202
|
*
|
|
203
|
-
* Control-flow ports are excluded: the reserved `trigger
|
|
204
|
-
*
|
|
205
|
-
* (DN1's grounded fact).
|
|
203
|
+
* Control-flow ports are excluded: the reserved `trigger` dataType, the
|
|
204
|
+
* `loop_back` port and `tool` outputs are intra-graph control flow, not an
|
|
205
|
+
* external surface (DN1's grounded fact). `tool` inputs are offered — see
|
|
206
|
+
* `isControlFlowPort`. The model and validation stay permissive — this only
|
|
206
207
|
* constrains what the authoring picker offers.
|
|
207
208
|
*/
|
|
208
209
|
export declare function listBindablePorts(workflow: Workflow, direction: 'input' | 'output'): BindablePort[];
|
|
210
|
+
/** A bindable port plus what the canvas already does with it. */
|
|
211
|
+
export interface RankedBindablePort extends BindablePort {
|
|
212
|
+
/** An edge already feeds this input, or already drains this output. */
|
|
213
|
+
connected: boolean;
|
|
214
|
+
/** The id of the same-direction interface entry that already binds this port, if any. */
|
|
215
|
+
publishedAs?: string;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* A stable key for a bindable port — `nodeId::portId` — the value a picker
|
|
219
|
+
* highlights by and an entry's single binding is compared against.
|
|
220
|
+
*/
|
|
221
|
+
export declare function bindablePortKey(candidate: BindablePort | {
|
|
222
|
+
nodeId: string;
|
|
223
|
+
portId: string;
|
|
224
|
+
}): string;
|
|
225
|
+
/** A port nothing is using yet — the natural first pick for a new entry. */
|
|
226
|
+
export declare function isFreeBindablePort(candidate: RankedBindablePort): boolean;
|
|
227
|
+
/**
|
|
228
|
+
* `listBindablePorts`, annotated and ordered for a "pick a port to publish"
|
|
229
|
+
* picker: every port nothing is using yet comes first, then the ports that
|
|
230
|
+
* already have an edge or are already published by another entry. Within
|
|
231
|
+
* each group the canvas order is kept, so the list stays stable as the
|
|
232
|
+
* author edits.
|
|
233
|
+
*
|
|
234
|
+
* "Connected" mirrors `validateWorkflowInterface`'s already-connected rule
|
|
235
|
+
* for inputs (an incoming edge on the bound handle) and its natural inverse
|
|
236
|
+
* for outputs (an outgoing edge). Neither is forbidden — an output can be
|
|
237
|
+
* both wired and published — the ranking only says which ports need no
|
|
238
|
+
* second thought.
|
|
239
|
+
*/
|
|
240
|
+
export declare function rankBindablePorts(workflow: Workflow, direction: 'input' | 'output'): RankedBindablePort[];
|
|
241
|
+
/**
|
|
242
|
+
* A complete new entry for a port the author just picked: bound to it, with
|
|
243
|
+
* every field `pullEntryFieldsFromPort` can derive, and an `id` seeded from
|
|
244
|
+
* the port's own id — made unique against `existingIds` with a numeric
|
|
245
|
+
* suffix (`text`, `text_2`, `text_3`, …).
|
|
246
|
+
*
|
|
247
|
+
* Seeding the id from the port is a convenience at creation time only: the
|
|
248
|
+
* author edits it like any other field afterwards, and nothing later
|
|
249
|
+
* re-derives it. DN1's concern — a contract silently keyed on internal port
|
|
250
|
+
* names — is about that ongoing coupling, which this does not introduce.
|
|
251
|
+
*/
|
|
252
|
+
export declare function entryFromBindablePort(candidate: BindablePort, existingIds: Iterable<string>): WorkflowInterfaceEntry;
|
|
@@ -347,12 +347,22 @@ export function pullEntryFieldsFromPort(port) {
|
|
|
347
347
|
return patch;
|
|
348
348
|
}
|
|
349
349
|
/**
|
|
350
|
-
* Whether a port is intra-graph control flow — the reserved `trigger
|
|
351
|
-
*
|
|
352
|
-
* workflow's interface.
|
|
350
|
+
* Whether a port is intra-graph control flow — the reserved `trigger`
|
|
351
|
+
* dataType, the loopback input, or a `tool` *output* — and therefore never
|
|
352
|
+
* publishable in a workflow's interface.
|
|
353
|
+
*
|
|
354
|
+
* A `tool` **input** is deliberately not control flow here. Tools are a typed
|
|
355
|
+
* argument of a workflow's execution (fddo DF9): exposing a consumer's `tool`
|
|
356
|
+
* input (a ToolBox's `tools`, an LLM node's `tools`) in the interface is how a
|
|
357
|
+
* parent hands its tools to a sub-workflow, so the picker must offer it. A
|
|
358
|
+
* `tool` output is the inverse — a workflow *producing* a tool — which is not
|
|
359
|
+
* a composition the runtime supports through the interface (a workflow is
|
|
360
|
+
* made a tool by a different mechanism), so it stays excluded.
|
|
353
361
|
*/
|
|
354
|
-
function isControlFlowPort(port) {
|
|
355
|
-
|
|
362
|
+
function isControlFlowPort(port, direction) {
|
|
363
|
+
if (port.dataType === 'trigger' || port.id === LOOPBACK_PORT_NAME)
|
|
364
|
+
return true;
|
|
365
|
+
return port.dataType === 'tool' && direction === 'output';
|
|
356
366
|
}
|
|
357
367
|
/**
|
|
358
368
|
* Every canvas-exposed port of a workflow, for one direction — the candidate
|
|
@@ -362,9 +372,10 @@ function isControlFlowPort(port) {
|
|
|
362
372
|
* Mirrors `FormPorts.svelte`'s port list: a node's static metadata ports plus
|
|
363
373
|
* its user-defined dynamic ports, filtered by `isPortExposed`.
|
|
364
374
|
*
|
|
365
|
-
* Control-flow ports are excluded: the reserved `trigger
|
|
366
|
-
*
|
|
367
|
-
* (DN1's grounded fact).
|
|
375
|
+
* Control-flow ports are excluded: the reserved `trigger` dataType, the
|
|
376
|
+
* `loop_back` port and `tool` outputs are intra-graph control flow, not an
|
|
377
|
+
* external surface (DN1's grounded fact). `tool` inputs are offered — see
|
|
378
|
+
* `isControlFlowPort`. The model and validation stay permissive — this only
|
|
368
379
|
* constrains what the authoring picker offers.
|
|
369
380
|
*/
|
|
370
381
|
export function listBindablePorts(workflow, direction) {
|
|
@@ -380,7 +391,7 @@ export function listBindablePorts(workflow, direction) {
|
|
|
380
391
|
const portsConfig = node.data?.config?.[PORTS_CONFIG_KEY];
|
|
381
392
|
const entries = portsConfig?.[portsConfigDirection];
|
|
382
393
|
for (const port of [...staticPorts, ...dynamicPorts]) {
|
|
383
|
-
if (isControlFlowPort(port))
|
|
394
|
+
if (isControlFlowPort(port, direction))
|
|
384
395
|
continue;
|
|
385
396
|
if (isPortExposed(port, entries)) {
|
|
386
397
|
result.push({ nodeId: node.id, nodeLabel: node.data?.label ?? node.id, port });
|
|
@@ -389,3 +400,67 @@ export function listBindablePorts(workflow, direction) {
|
|
|
389
400
|
}
|
|
390
401
|
return result;
|
|
391
402
|
}
|
|
403
|
+
/**
|
|
404
|
+
* A stable key for a bindable port — `nodeId::portId` — the value a picker
|
|
405
|
+
* highlights by and an entry's single binding is compared against.
|
|
406
|
+
*/
|
|
407
|
+
export function bindablePortKey(candidate) {
|
|
408
|
+
const portId = 'port' in candidate ? candidate.port.id : candidate.portId;
|
|
409
|
+
return `${candidate.nodeId}::${portId}`;
|
|
410
|
+
}
|
|
411
|
+
/** A port nothing is using yet — the natural first pick for a new entry. */
|
|
412
|
+
export function isFreeBindablePort(candidate) {
|
|
413
|
+
return !candidate.connected && candidate.publishedAs === undefined;
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* `listBindablePorts`, annotated and ordered for a "pick a port to publish"
|
|
417
|
+
* picker: every port nothing is using yet comes first, then the ports that
|
|
418
|
+
* already have an edge or are already published by another entry. Within
|
|
419
|
+
* each group the canvas order is kept, so the list stays stable as the
|
|
420
|
+
* author edits.
|
|
421
|
+
*
|
|
422
|
+
* "Connected" mirrors `validateWorkflowInterface`'s already-connected rule
|
|
423
|
+
* for inputs (an incoming edge on the bound handle) and its natural inverse
|
|
424
|
+
* for outputs (an outgoing edge). Neither is forbidden — an output can be
|
|
425
|
+
* both wired and published — the ranking only says which ports need no
|
|
426
|
+
* second thought.
|
|
427
|
+
*/
|
|
428
|
+
export function rankBindablePorts(workflow, direction) {
|
|
429
|
+
const entries = (direction === 'input' ? workflow.interface?.inputs : workflow.interface?.outputs) ?? [];
|
|
430
|
+
const ranked = listBindablePorts(workflow, direction).map((candidate) => {
|
|
431
|
+
const handleId = buildHandleId(candidate.nodeId, direction, candidate.port.id);
|
|
432
|
+
const connected = workflow.edges.some((edge) => direction === 'input' ? edge.targetHandle === handleId : edge.sourceHandle === handleId);
|
|
433
|
+
const publishedAs = entries.find((entry) => entry.bindings.some((binding) => binding.nodeId === candidate.nodeId && binding.portId === candidate.port.id))?.id;
|
|
434
|
+
return publishedAs === undefined
|
|
435
|
+
? { ...candidate, connected }
|
|
436
|
+
: { ...candidate, connected, publishedAs };
|
|
437
|
+
});
|
|
438
|
+
return [
|
|
439
|
+
...ranked.filter(isFreeBindablePort),
|
|
440
|
+
...ranked.filter((candidate) => !isFreeBindablePort(candidate))
|
|
441
|
+
];
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* A complete new entry for a port the author just picked: bound to it, with
|
|
445
|
+
* every field `pullEntryFieldsFromPort` can derive, and an `id` seeded from
|
|
446
|
+
* the port's own id — made unique against `existingIds` with a numeric
|
|
447
|
+
* suffix (`text`, `text_2`, `text_3`, …).
|
|
448
|
+
*
|
|
449
|
+
* Seeding the id from the port is a convenience at creation time only: the
|
|
450
|
+
* author edits it like any other field afterwards, and nothing later
|
|
451
|
+
* re-derives it. DN1's concern — a contract silently keyed on internal port
|
|
452
|
+
* names — is about that ongoing coupling, which this does not introduce.
|
|
453
|
+
*/
|
|
454
|
+
export function entryFromBindablePort(candidate, existingIds) {
|
|
455
|
+
const taken = new Set(existingIds);
|
|
456
|
+
let id = candidate.port.id;
|
|
457
|
+
for (let n = 2; taken.has(id); n += 1) {
|
|
458
|
+
id = `${candidate.port.id}_${n}`;
|
|
459
|
+
}
|
|
460
|
+
return {
|
|
461
|
+
id,
|
|
462
|
+
dataType: candidate.port.dataType,
|
|
463
|
+
bindings: [{ nodeId: candidate.nodeId, portId: candidate.port.id }],
|
|
464
|
+
...pullEntryFieldsFromPort(candidate.port)
|
|
465
|
+
};
|
|
466
|
+
}
|
|
@@ -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;
|