@flowdrop/flowdrop 2.4.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.
- package/CHANGELOG.md +49 -0
- package/dist/chat/commandClassifier.d.ts +17 -0
- package/dist/chat/commandClassifier.js +29 -0
- package/dist/chat/index.d.ts +1 -1
- package/dist/chat/index.js +1 -1
- 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/config/defaultPortConfig.js +27 -9
- package/dist/messages/context.d.ts +6 -0
- package/dist/messages/context.js +8 -0
- package/dist/messages/defaults.d.ts +45 -2
- package/dist/messages/defaults.js +36 -3
- package/dist/messages/index.d.ts +1 -1
- package/dist/messages/index.js +1 -1
- package/dist/openapi/v1/openapi.yaml +14 -1
- package/dist/schemas/v1/workflow.schema.json +9 -2
- package/dist/stores/instanceContainer.svelte.d.ts +26 -0
- package/dist/stores/instanceContainer.svelte.js +24 -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 +20 -0
- package/dist/svelte-app.d.ts +20 -0
- package/dist/svelte-app.js +49 -1
- package/dist/types/index.d.ts +26 -1
- 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 +170 -0
- package/dist/webmcp/WebMCPConfirm.svelte.d.ts +11 -0
- package/dist/webmcp/descriptors.d.ts +59 -0
- package/dist/webmcp/descriptors.js +464 -0
- package/dist/webmcp/fake.d.ts +23 -0
- package/dist/webmcp/fake.js +42 -0
- package/dist/webmcp/gate.d.ts +40 -0
- package/dist/webmcp/gate.js +92 -0
- package/dist/webmcp/index.d.ts +34 -0
- package/dist/webmcp/index.js +31 -0
- package/dist/webmcp/register.d.ts +33 -0
- package/dist/webmcp/register.js +267 -0
- package/dist/webmcp/types.d.ts +166 -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
|
@@ -1122,7 +1122,14 @@
|
|
|
1122
1122
|
"description": "Help text describing what this entry represents to external callers."
|
|
1123
1123
|
},
|
|
1124
1124
|
"dataType": {
|
|
1125
|
-
"
|
|
1125
|
+
"allOf": [
|
|
1126
|
+
{
|
|
1127
|
+
"$ref": "#/$defs/NodeDataType"
|
|
1128
|
+
},
|
|
1129
|
+
{
|
|
1130
|
+
"description": "The port's LANE — what it is and what it may connect to — not the JSON\nSchema type of its value, which is `schema.type`. The two vocabularies\noverlap on `string`/`number`/`boolean`/`array` and diverge where it\nmatters: a `messages` port is a JSON `array`, an `error` port a JSON\n`object`. Derived by the server from the bound inner port and ignored\non write.\n"
|
|
1131
|
+
}
|
|
1132
|
+
]
|
|
1126
1133
|
},
|
|
1127
1134
|
"required": {
|
|
1128
1135
|
"type": "boolean",
|
|
@@ -1142,7 +1149,7 @@
|
|
|
1142
1149
|
"$ref": "#/$defs/PortDataSchema"
|
|
1143
1150
|
},
|
|
1144
1151
|
{
|
|
1145
|
-
"description": "JSON Schema
|
|
1152
|
+
"description": "The JSON Schema fragment for this one port — a single property's\nschema (`{\"type\": \"array\"}`), not a whole object schema. Carries the\nstructural contract only: whatever the entry states itself (the lane,\n`name`, `description`, `examples`, `required`) is not repeated inside\nit. Derived by the server from the bound inner port and ignored on\nwrite; absent when the bound port declares no structural contract.\n"
|
|
1146
1153
|
}
|
|
1147
1154
|
]
|
|
1148
1155
|
},
|
|
@@ -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()?.();
|
|
@@ -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;
|
package/dist/styles/base.css
CHANGED
|
@@ -224,9 +224,11 @@ p {
|
|
|
224
224
|
}
|
|
225
225
|
|
|
226
226
|
.flowdrop-btn--sm {
|
|
227
|
-
|
|
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:
|
|
231
|
+
min-height: var(--fd-size-icon-btn);
|
|
230
232
|
}
|
|
231
233
|
|
|
232
234
|
.flowdrop-btn--lg {
|
package/dist/styles/tokens.css
CHANGED
|
@@ -323,6 +323,22 @@
|
|
|
323
323
|
--fd-node-purple: #9333ea; /* @public */
|
|
324
324
|
--fd-node-fuchsia: #d946ef; /* @public */
|
|
325
325
|
|
|
326
|
+
/**
|
|
327
|
+
* The control lane's ink. Deliberately NOT a hue: a trigger handle must read
|
|
328
|
+
* as the same thing as the trigger WIRE, and `--fd-edge-trigger` is ink that
|
|
329
|
+
* flips with the theme rather than a fixed black. Keep the two in step — a
|
|
330
|
+
* literal #18181c handle disappears against the dark canvas.
|
|
331
|
+
*/
|
|
332
|
+
--fd-node-ink: var(--_gray-9); /* @public */
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Worn by the untyped `array` lane, and by nothing else. A TYPED array
|
|
336
|
+
* inherits its element's hue (`string[]` is emerald, `file[]` is teal), so
|
|
337
|
+
* the one array with no element shape needs a hue of its own. It had amber
|
|
338
|
+
* until `tool` took that to match `--fd-edge-tool`.
|
|
339
|
+
*/
|
|
340
|
+
--fd-node-violet: #7c3aed; /* @public */
|
|
341
|
+
|
|
326
342
|
/** Icon on node squircle: dark in light theme, white in dark theme */
|
|
327
343
|
--fd-node-icon: var(--_gray-9); /* @public */
|
|
328
344
|
/** Opacity of the icon squircle background (color-mix percentage). Light mode: 15% / 22% hover; dark mode uses higher values. */
|
|
@@ -469,6 +485,10 @@
|
|
|
469
485
|
--fd-node-purple: #c084fc;
|
|
470
486
|
--fd-node-fuchsia: #e879f9;
|
|
471
487
|
|
|
488
|
+
/* Mirrors --fd-edge-trigger's dark value, so handle and wire stay one colour. */
|
|
489
|
+
--fd-node-ink: var(--_gray-3);
|
|
490
|
+
--fd-node-violet: #a78bfa;
|
|
491
|
+
|
|
472
492
|
/** Icon on node squircle: white in dark theme */
|
|
473
493
|
--fd-node-icon: #ffffff;
|
|
474
494
|
/** Icon squircle background opacity: higher in dark mode for visibility on dark surfaces */
|
package/dist/svelte-app.d.ts
CHANGED
|
@@ -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
|
|
@@ -178,6 +190,14 @@ export interface MountedFlowDropApp {
|
|
|
178
190
|
* @returns The number of entries removed.
|
|
179
191
|
*/
|
|
180
192
|
clearAllDrafts: () => number;
|
|
193
|
+
/**
|
|
194
|
+
* The WebMCP registration when the `webmcp` mount option was set and the
|
|
195
|
+
* browser has the API; `undefined` otherwise. The adapter attaches in the
|
|
196
|
+
* background once the workflow is loaded, so this is `undefined` for a
|
|
197
|
+
* moment after mount even when the API exists. Detached automatically on
|
|
198
|
+
* `destroy()`.
|
|
199
|
+
*/
|
|
200
|
+
readonly webmcp?: WebMCPHandle;
|
|
181
201
|
}
|
|
182
202
|
/**
|
|
183
203
|
* Mount the full FlowDrop App with navbar, sidebars, and workflow editor
|
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,28 @@ export async function mountFlowDropApp(container, options = {}) {
|
|
|
251
281
|
eventHandlers: eventHandlers ?? null,
|
|
252
282
|
unsubscribeDraftSettings
|
|
253
283
|
};
|
|
284
|
+
// WebMCP editor tools, opt-in. Attaches in the background — mounting does
|
|
285
|
+
// not wait for it — and detaches with the mount.
|
|
286
|
+
let webmcpHandle;
|
|
287
|
+
let destroyed = false;
|
|
288
|
+
if (webmcp) {
|
|
289
|
+
void attachWebMCPToMount(fd, webmcp === true ? {} : webmcp, () => destroyed).then((handle) => {
|
|
290
|
+
if (destroyed)
|
|
291
|
+
handle?.detach();
|
|
292
|
+
else
|
|
293
|
+
webmcpHandle = handle;
|
|
294
|
+
});
|
|
295
|
+
}
|
|
254
296
|
// Create the mounted app interface
|
|
255
297
|
const mountedApp = {
|
|
256
298
|
instance: fd,
|
|
299
|
+
get webmcp() {
|
|
300
|
+
return webmcpHandle;
|
|
301
|
+
},
|
|
257
302
|
destroy: () => {
|
|
303
|
+
// Remove the agent-facing tools before anything else goes away.
|
|
304
|
+
destroyed = true;
|
|
305
|
+
webmcpHandle?.detach();
|
|
258
306
|
// Call onBeforeUnmount if provided
|
|
259
307
|
if (state.eventHandlers?.onBeforeUnmount) {
|
|
260
308
|
const currentWorkflow = fd.workflow.current;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1277,6 +1277,15 @@ export interface PortBinding {
|
|
|
1277
1277
|
nodeId: string;
|
|
1278
1278
|
portId: string;
|
|
1279
1279
|
}
|
|
1280
|
+
/**
|
|
1281
|
+
* A single port's JSON Schema fragment as it rides a workflow's contract.
|
|
1282
|
+
*
|
|
1283
|
+
* Derived from {@link InputProperty} rather than restated, so the fragment
|
|
1284
|
+
* vocabulary has one definition; every key is optional because an interface
|
|
1285
|
+
* entry states its own annotations one level up and the server strips them
|
|
1286
|
+
* from the fragment on the way out.
|
|
1287
|
+
*/
|
|
1288
|
+
export type WorkflowInterfaceSchema = Partial<InputProperty>;
|
|
1280
1289
|
/**
|
|
1281
1290
|
* One entry in a workflow's public contract. Owns its own identity: `id` is
|
|
1282
1291
|
* stable and workflow-scoped, independent of whichever inner port it currently
|
|
@@ -1302,7 +1311,23 @@ export interface WorkflowInterfaceEntry {
|
|
|
1302
1311
|
* outputs. Never validated against `schema`.
|
|
1303
1312
|
*/
|
|
1304
1313
|
examples?: unknown[];
|
|
1305
|
-
|
|
1314
|
+
/**
|
|
1315
|
+
* The port's JSON Schema fragment — the shape of the value, as opposed to
|
|
1316
|
+
* `dataType`, which is the lane it travels in. These are two vocabularies
|
|
1317
|
+
* that overlap on `string`/`number`/`boolean`/`array` and diverge exactly
|
|
1318
|
+
* where it matters: a `messages` port is an `array`, an `error` port is an
|
|
1319
|
+
* `object`, and a named shape is whatever its schema says.
|
|
1320
|
+
*
|
|
1321
|
+
* A single PROPERTY fragment, not an object schema — this was typed
|
|
1322
|
+
* `InputSchema | OutputSchema` (a whole `{properties: {...}}` object) while
|
|
1323
|
+
* nothing populated it, which would have been wrong the moment something
|
|
1324
|
+
* did. Every key is optional because the server strips what the entry
|
|
1325
|
+
* already states: no `title`/`description`/`examples`/`required`, and no
|
|
1326
|
+
* lane, since that is `dataType`.
|
|
1327
|
+
*
|
|
1328
|
+
* Absent when the bound port declares no structural contract at all.
|
|
1329
|
+
*/
|
|
1330
|
+
schema?: WorkflowInterfaceSchema;
|
|
1306
1331
|
/**
|
|
1307
1332
|
* Inner ports this entry maps to. Every entry — input or output — must
|
|
1308
1333
|
* resolve to exactly one binding; more than one is reported as `over-bound`.
|
|
@@ -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
|
+
}
|