@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
@@ -0,0 +1,188 @@
1
+ /**
2
+ * WebMCP adapter — approval gate.
3
+ *
4
+ * Tool calls that would change the document pass through here before anything
5
+ * runs. The policy is the host's (`WebMCPOptions.approval`); the default is a
6
+ * confirm dialog rendered inside the page, because the WebMCP permission model
7
+ * is about which origins may *see* tools, not about whether a given call may
8
+ * change the user's document. Any agent or extension on the page can call a
9
+ * tool, so the gate must not be weaker than the chat panel's click-to-apply.
10
+ *
11
+ * Two ergonomics live here too. A batch shows a *summary* of what changes
12
+ * (nodes added, edges connected, config keys set) above the line list, so the
13
+ * person reads what the agent is doing rather than a verb list. And the
14
+ * dialog can offer "apply further edits without asking" for the rest of the
15
+ * page's life — edits only: `save` and `run` are consequential and always ask.
16
+ * The gate cannot tell one agent from another, so the offer is worded as what
17
+ * it is: every caller on the page is covered once it is ticked. It is still a
18
+ * click-to-apply — one the person chose to make once.
19
+ *
20
+ * @module webmcp/gate
21
+ */
22
+ import { mount, unmount } from 'svelte';
23
+ import { defaultMessages, mergeMessages, messagesContext } from '../messages/index.js';
24
+ import { describeCommand } from './descriptors.js';
25
+ import WebMCPConfirm from './WebMCPConfirm.svelte';
26
+ /** A second mutating call arrived while a decision was pending. */
27
+ export class GateBusyError extends Error {
28
+ constructor() {
29
+ super('A previous change is still waiting for approval');
30
+ this.name = 'GateBusyError';
31
+ }
32
+ }
33
+ const CONSEQUENTIAL_TOOLS = new Set(['save', 'run']);
34
+ /**
35
+ * One sentence saying what a list of commands does, for the dialog's hint:
36
+ * "3 changes — adds 2 nodes, connects 1 edge. Applied together, undone together."
37
+ * Returns `undefined` for a single command, whose one line already says it all.
38
+ */
39
+ export function summarizeCommands(commands, m) {
40
+ if (commands.length < 2)
41
+ return undefined;
42
+ let adds = 0;
43
+ let deletes = 0;
44
+ let connects = 0;
45
+ let disconnects = 0;
46
+ let configs = 0;
47
+ let other = 0;
48
+ for (const c of commands) {
49
+ switch (c.type) {
50
+ case 'add_node':
51
+ adds++;
52
+ break;
53
+ case 'delete_node':
54
+ deletes++;
55
+ break;
56
+ case 'connect':
57
+ connects++;
58
+ break;
59
+ case 'disconnect_ports':
60
+ case 'disconnect_node':
61
+ disconnects++;
62
+ break;
63
+ case 'set_config':
64
+ configs++;
65
+ break;
66
+ default:
67
+ other++;
68
+ }
69
+ }
70
+ const parts = [];
71
+ if (adds)
72
+ parts.push(m.summaryAdds({ count: adds }));
73
+ if (deletes)
74
+ parts.push(m.summaryDeletes({ count: deletes }));
75
+ if (connects)
76
+ parts.push(m.summaryConnects({ count: connects }));
77
+ if (disconnects)
78
+ parts.push(m.summaryDisconnects({ count: disconnects }));
79
+ if (configs)
80
+ parts.push(m.summaryConfigs({ count: configs }));
81
+ if (other)
82
+ parts.push(m.summaryOther({ count: other }));
83
+ return m.batchSummary({ count: commands.length, parts: parts.join(', ') });
84
+ }
85
+ export function createApprovalGate(approval, options) {
86
+ let pending = false;
87
+ let dismiss = null;
88
+ let editsPreApproved = false;
89
+ const offerRemember = options.rememberEdits ?? true;
90
+ // The dialog mounts outside any component tree, so it gets its messages
91
+ // through the same context the root component would have provided. Read
92
+ // per access so a getter-driven locale switch shows on the next dialog.
93
+ const messages = () => {
94
+ const override = options.messages;
95
+ return mergeMessages(defaultMessages, typeof override === 'function' ? override() : override);
96
+ };
97
+ const isConsequential = (request) => request.consequential ?? CONSEQUENTIAL_TOOLS.has(request.tool);
98
+ async function decide(commands, request) {
99
+ if (approval === 'auto')
100
+ return true;
101
+ if (typeof approval === 'function')
102
+ return approval(commands, { tool: request.tool });
103
+ // The person's earlier "don't ask again" covers edits, never save or run.
104
+ if (editsPreApproved && !isConsequential(request))
105
+ return true;
106
+ return confirmInPage(commands, request);
107
+ }
108
+ // `lines`/`hint` default from the commands for an ordinary change; `save`
109
+ // and `run` have no commands, so they get their own dialog copy.
110
+ function resolveLines(commands, request) {
111
+ if (request.lines)
112
+ return request.lines;
113
+ const m = messages().webmcp;
114
+ if (request.tool === 'save')
115
+ return [m.saveLine({ name: options.editorName() })];
116
+ if (request.tool === 'run')
117
+ return [m.runLine({ name: options.editorName() })];
118
+ return commands.map(describeCommand);
119
+ }
120
+ function resolveHint(commands, request) {
121
+ if (request.hint !== undefined)
122
+ return request.hint;
123
+ const m = messages().webmcp;
124
+ if (request.tool === 'save')
125
+ return m.saveHint;
126
+ if (request.tool === 'run')
127
+ return m.runHint;
128
+ return summarizeCommands(commands, m);
129
+ }
130
+ function confirmInPage(commands, request) {
131
+ const target = options.container ?? (typeof document !== 'undefined' ? document.body : null);
132
+ if (!target) {
133
+ // No DOM to ask in: refuse rather than silently apply.
134
+ return Promise.resolve(false);
135
+ }
136
+ return new Promise((resolve) => {
137
+ let settled = false;
138
+ const host = document.createElement('div');
139
+ host.className = 'fd-webmcp-confirm-host';
140
+ target.appendChild(host);
141
+ const finish = (approved, remember = false) => {
142
+ if (settled)
143
+ return;
144
+ settled = true;
145
+ dismiss = null;
146
+ void unmount(component);
147
+ host.remove();
148
+ if (approved && remember)
149
+ editsPreApproved = true;
150
+ resolve(approved);
151
+ };
152
+ const component = mount(WebMCPConfirm, {
153
+ target: host,
154
+ context: messagesContext(messages),
155
+ props: {
156
+ editorName: options.editorName(),
157
+ lines: resolveLines(commands, request),
158
+ hint: resolveHint(commands, request),
159
+ offerRemember: offerRemember && !isConsequential(request),
160
+ onResolve: finish
161
+ }
162
+ });
163
+ dismiss = () => finish(false);
164
+ });
165
+ }
166
+ return {
167
+ get busy() {
168
+ return pending;
169
+ },
170
+ get editsPreApproved() {
171
+ return editsPreApproved;
172
+ },
173
+ async request(commands, request) {
174
+ if (pending)
175
+ throw new GateBusyError();
176
+ pending = true;
177
+ try {
178
+ return await decide(commands, request);
179
+ }
180
+ finally {
181
+ pending = false;
182
+ }
183
+ },
184
+ dispose() {
185
+ dismiss?.();
186
+ }
187
+ };
188
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * FlowDrop WebMCP adapter — `@flowdrop/flowdrop/webmcp`
3
+ *
4
+ * Exposes the editor's typed commands as WebMCP **editor tools** that a
5
+ * browser-resident agent (Chrome's, Edge's, Brave Leo, ChatGPT Desktop, …)
6
+ * can discover on the page and call: add and connect nodes, set config, list
7
+ * and inspect, undo. Reads run at once; anything that changes the workflow
8
+ * waits for the person at the keyboard unless the host says otherwise.
9
+ *
10
+ * These are tools for *editing* a workflow in the browser. They are unrelated
11
+ * to the tools a running workflow hands to an LLM node.
12
+ *
13
+ * @module webmcp
14
+ *
15
+ * @example Svelte host
16
+ * ```ts
17
+ * import { attachWebMCP } from '@flowdrop/flowdrop/webmcp';
18
+ * const handle = attachWebMCP(app.instance, { nodeTypes });
19
+ * // later: handle?.detach() — or let instance.destroy() do it
20
+ * ```
21
+ *
22
+ * @example Vanilla / Drupal host
23
+ * ```ts
24
+ * const app = await mountFlowDropApp(el, { endpointConfig, webmcp: true });
25
+ * ```
26
+ */
27
+ export { attachWebMCP, detectModelContext, DEFAULT_PREFIX } from './register.js';
28
+ export { buildToolDescriptors, describeCommand, EXPOSED_COMMAND_TYPES, VIEW_COMMAND_TYPES, EXCLUDED_COMMAND_TYPES, COMPOSITE_VERBS } from './descriptors.js';
29
+ export type { BuildDescriptorsOptions } from './descriptors.js';
30
+ export { validateToolArgs, VALIDATOR_KEYWORDS } from './validate.js';
31
+ export { ToolArgumentError } from './types.js';
32
+ export { createFakeModelContext } from './fake.js';
33
+ export type { FakeModelContext } from './fake.js';
34
+ export { createBridgedModelContext, installBridgedModelContext } from './bridge.js';
35
+ export type { WebMCPWidgetLike, BridgedModelContext } from './bridge.js';
36
+ export type { ToolDescriptor, ToolInputSchema, ToolSchemaProperty, ToolResult, ToolExecuteOptions, RegisteredToolDefinition, RegisterToolOptions, ModelContextLike, WebMCPApproval, WebMCPApprovalRequest, HostCode, HostEnvelope, RunStarted, RunPending, RunStatus, WebMCPOptions, WebMCPMountOptions, WebMCPHandle } from './types.js';
@@ -0,0 +1,32 @@
1
+ /**
2
+ * FlowDrop WebMCP adapter — `@flowdrop/flowdrop/webmcp`
3
+ *
4
+ * Exposes the editor's typed commands as WebMCP **editor tools** that a
5
+ * browser-resident agent (Chrome's, Edge's, Brave Leo, ChatGPT Desktop, …)
6
+ * can discover on the page and call: add and connect nodes, set config, list
7
+ * and inspect, undo. Reads run at once; anything that changes the workflow
8
+ * waits for the person at the keyboard unless the host says otherwise.
9
+ *
10
+ * These are tools for *editing* a workflow in the browser. They are unrelated
11
+ * to the tools a running workflow hands to an LLM node.
12
+ *
13
+ * @module webmcp
14
+ *
15
+ * @example Svelte host
16
+ * ```ts
17
+ * import { attachWebMCP } from '@flowdrop/flowdrop/webmcp';
18
+ * const handle = attachWebMCP(app.instance, { nodeTypes });
19
+ * // later: handle?.detach() — or let instance.destroy() do it
20
+ * ```
21
+ *
22
+ * @example Vanilla / Drupal host
23
+ * ```ts
24
+ * const app = await mountFlowDropApp(el, { endpointConfig, webmcp: true });
25
+ * ```
26
+ */
27
+ export { attachWebMCP, detectModelContext, DEFAULT_PREFIX } from './register.js';
28
+ export { buildToolDescriptors, describeCommand, EXPOSED_COMMAND_TYPES, VIEW_COMMAND_TYPES, EXCLUDED_COMMAND_TYPES, COMPOSITE_VERBS } from './descriptors.js';
29
+ export { validateToolArgs, VALIDATOR_KEYWORDS } from './validate.js';
30
+ export { ToolArgumentError } from './types.js';
31
+ export { createFakeModelContext } from './fake.js';
32
+ export { createBridgedModelContext, installBridgedModelContext } from './bridge.js';
@@ -0,0 +1,33 @@
1
+ /**
2
+ * WebMCP adapter — registration.
3
+ *
4
+ * The only file that touches the runtime (`document.modelContext`, falling
5
+ * back to `navigator.modelContext`). Builds the descriptors, wraps each in an
6
+ * `execute` that validates → maps to commands → gates → runs one
7
+ * `executeBatch` transaction, and registers the lot under one AbortSignal so
8
+ * detaching is a single `abort()`.
9
+ *
10
+ * @module webmcp/register
11
+ */
12
+ import type { FlowDropInstance } from '../stores/instanceContainer.svelte.js';
13
+ import { type ModelContextLike, type WebMCPHandle, type WebMCPOptions } from './types.js';
14
+ export declare const DEFAULT_PREFIX = "flowdrop";
15
+ /**
16
+ * Find the WebMCP runtime on this page, or `null` when the browser has none.
17
+ * Structural: anything with a callable `registerTool` counts.
18
+ */
19
+ export declare function detectModelContext(): ModelContextLike | null;
20
+ /**
21
+ * Register the editor's commands as WebMCP tools for `instance`.
22
+ *
23
+ * Returns `null` — with no console output — when the page has no WebMCP
24
+ * runtime, so hosts can call it unconditionally. Throws when the prefix is
25
+ * already registered on this runtime (two editors on one page need distinct
26
+ * prefixes).
27
+ *
28
+ * Registration settles asynchronously: `handle.tools` lists the tools the
29
+ * runtime has accepted so far and `handle.ready` resolves when every
30
+ * registration has settled. The registration is torn down by
31
+ * `handle.detach()` or automatically when `instance.destroy()` runs.
32
+ */
33
+ export declare function attachWebMCP(instance: FlowDropInstance, options?: WebMCPOptions): WebMCPHandle | null;