@flowdrop/flowdrop 2.6.0 → 2.8.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 +56 -0
- package/dist/api/enhanced-client.d.ts +29 -1
- package/dist/api/enhanced-client.js +83 -9
- package/dist/chat/commandClassifier.d.ts +2 -1
- package/dist/chat/commandClassifier.js +4 -1
- package/dist/chat/index.d.ts +5 -1
- package/dist/chat/index.js +2 -0
- package/dist/chat/toolCatalogue.d.ts +27 -0
- package/dist/chat/toolCatalogue.js +35 -0
- package/dist/chat/turnDriver.d.ts +143 -0
- package/dist/chat/turnDriver.js +124 -0
- 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 +47 -56
- package/dist/components/SettingsPanel.svelte +13 -0
- package/dist/components/WorkflowEditor.svelte +4 -2
- package/dist/components/WorkflowEditor.svelte.d.ts +2 -0
- package/dist/components/chat/AIChatPanel.svelte +410 -22
- 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/components/toast/DismissibleToast.svelte +53 -0
- package/dist/components/toast/DismissibleToast.svelte.d.ts +24 -0
- package/dist/components/toast/WarningIcon.svelte +28 -0
- package/dist/components/toast/WarningIcon.svelte.d.ts +26 -0
- package/dist/config/constants.d.ts +7 -3
- package/dist/config/constants.js +7 -3
- package/dist/config/endpoints.d.ts +7 -0
- package/dist/config/endpoints.js +2 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/editor/index.d.ts +1 -1
- package/dist/editor/index.js +1 -1
- package/dist/messages/defaults.d.ts +74 -0
- package/dist/messages/defaults.js +35 -1
- package/dist/services/chatService.d.ts +21 -3
- package/dist/services/chatService.js +33 -1
- package/dist/services/globalSave.d.ts +7 -1
- package/dist/services/globalSave.js +20 -4
- package/dist/services/toastService.d.ts +23 -2
- package/dist/services/toastService.js +72 -28
- package/dist/stores/instanceContainer.svelte.d.ts +34 -0
- package/dist/stores/instanceContainer.svelte.js +30 -0
- package/dist/stores/workflowStore.svelte.d.ts +10 -0
- package/dist/stores/workflowStore.svelte.js +15 -0
- package/dist/styles/toast.css +62 -0
- package/dist/styles/tokens.css +6 -0
- package/dist/svelte-app.d.ts +16 -4
- package/dist/svelte-app.js +45 -14
- package/dist/types/chat.d.ts +59 -0
- package/dist/types/events.d.ts +23 -0
- package/dist/types/events.js +3 -1
- package/dist/types/index.d.ts +49 -0
- package/dist/types/settings.d.ts +18 -1
- package/dist/types/settings.js +1 -0
- package/dist/webmcp/WebMCPConfirm.svelte +168 -61
- package/dist/webmcp/WebMCPConfirm.svelte.d.ts +14 -4
- package/dist/webmcp/bridge.d.ts +63 -0
- package/dist/webmcp/bridge.js +106 -0
- package/dist/webmcp/descriptors.d.ts +8 -1
- package/dist/webmcp/descriptors.js +108 -17
- package/dist/webmcp/gate.d.ts +44 -2
- package/dist/webmcp/gate.js +61 -10
- package/dist/webmcp/index.d.ts +7 -2
- package/dist/webmcp/index.js +4 -1
- package/dist/webmcp/register.d.ts +11 -10
- package/dist/webmcp/register.js +72 -160
- package/dist/webmcp/runtime.d.ts +33 -0
- package/dist/webmcp/runtime.js +500 -0
- package/dist/webmcp/types.d.ts +196 -2
- package/package.json +1 -1
|
@@ -38,6 +38,8 @@ export const EXPOSED_COMMAND_TYPES = [
|
|
|
38
38
|
'list_nodes',
|
|
39
39
|
'list_edges',
|
|
40
40
|
'list_types',
|
|
41
|
+
'describe_type',
|
|
42
|
+
'search_types',
|
|
41
43
|
'info',
|
|
42
44
|
'undo',
|
|
43
45
|
'redo',
|
|
@@ -65,7 +67,15 @@ export const COMPOSITE_VERBS = ['view', 'batch'];
|
|
|
65
67
|
// ============================================================================
|
|
66
68
|
// Schema fragments
|
|
67
69
|
// ============================================================================
|
|
68
|
-
const NODE_ID_DESCRIPTION = 'Node id in short form, e.g. "
|
|
70
|
+
const NODE_ID_DESCRIPTION = 'Node id in short form, e.g. "http_request.1" — the `nodeId` values returned by list_nodes and add_node. Full ids are accepted too.';
|
|
71
|
+
/**
|
|
72
|
+
* The recommended call order, appended to the tools where it applies —
|
|
73
|
+
* add_node, set_config, swap_node and batch, the ones that take a type or a
|
|
74
|
+
* config key. For a browser agent the tool descriptions are the whole manual,
|
|
75
|
+
* so the manual says how the tools fit together; saying it once per relevant
|
|
76
|
+
* tool keeps the manual short.
|
|
77
|
+
*/
|
|
78
|
+
const CALL_ORDER = ' Call describe_type before adding or configuring a type you have not seen; group several changes in one batch; save when done.';
|
|
69
79
|
const nodeId = (description = NODE_ID_DESCRIPTION) => ({
|
|
70
80
|
type: 'string',
|
|
71
81
|
description
|
|
@@ -121,11 +131,12 @@ const PORT_PAIR = object({
|
|
|
121
131
|
/** One record per exposed command, keyed by command type. */
|
|
122
132
|
const COMMANDS = {
|
|
123
133
|
add_node: {
|
|
124
|
-
description:
|
|
134
|
+
description: "Add a node of the given type to the workflow. Returns the new node id; the node starts with the type's default config." +
|
|
135
|
+
CALL_ORDER,
|
|
125
136
|
inputSchema: object({
|
|
126
137
|
nodeTypeId: {
|
|
127
138
|
type: 'string',
|
|
128
|
-
description: 'Node type id as returned by list_types (`typeId`), e.g. "
|
|
139
|
+
description: 'Node type id as returned by list_types / search_types (`typeId`), e.g. "http_request". Unknown ids fail and name near misses.'
|
|
129
140
|
},
|
|
130
141
|
position: {
|
|
131
142
|
...position,
|
|
@@ -158,12 +169,13 @@ const COMMANDS = {
|
|
|
158
169
|
summarize: (c) => `Move ${c.nodeId} to ${at(c.position)}`
|
|
159
170
|
},
|
|
160
171
|
swap_node: {
|
|
161
|
-
description: 'Replace a node with one of another type, keeping compatible connections and config. Reports what was dropped.'
|
|
172
|
+
description: 'Replace a node with one of another type, keeping compatible connections and config. Reports what was dropped.' +
|
|
173
|
+
CALL_ORDER,
|
|
162
174
|
inputSchema: object({
|
|
163
175
|
nodeId: nodeId('Node to replace.'),
|
|
164
176
|
newTypeId: {
|
|
165
177
|
type: 'string',
|
|
166
|
-
description: 'Replacement node type id (see list_types). Compatible ports and config carry over.'
|
|
178
|
+
description: 'Replacement node type id (see list_types / describe_type). Compatible ports and config carry over.'
|
|
167
179
|
}
|
|
168
180
|
}, ['nodeId', 'newTypeId']),
|
|
169
181
|
build: (a) => ({
|
|
@@ -174,12 +186,13 @@ const COMMANDS = {
|
|
|
174
186
|
summarize: (c) => `Swap ${c.nodeId} for a ${c.newTypeId}`
|
|
175
187
|
},
|
|
176
188
|
set_config: {
|
|
177
|
-
description: 'Set one configuration value on a node.
|
|
189
|
+
description: 'Set one configuration value on a node. A value outside the enum, of the wrong type, or under a key the schema does not declare is stored with a warning that names the allowed values / keys — fatal only when strict.' +
|
|
190
|
+
CALL_ORDER,
|
|
178
191
|
inputSchema: object({
|
|
179
192
|
nodeId: nodeId(),
|
|
180
193
|
key: {
|
|
181
194
|
type: 'string',
|
|
182
|
-
description: 'Config key, as listed under `config` by
|
|
195
|
+
description: 'Config key, as listed under `config` by describe_type (with type, enum and default) or get_config.'
|
|
183
196
|
},
|
|
184
197
|
value: configValue,
|
|
185
198
|
strict: {
|
|
@@ -197,13 +210,23 @@ const COMMANDS = {
|
|
|
197
210
|
summarize: (c) => `Set ${c.nodeId}.${c.key} = ${c.value}`
|
|
198
211
|
},
|
|
199
212
|
get_config: {
|
|
200
|
-
description: 'Read
|
|
201
|
-
inputSchema: object({
|
|
202
|
-
|
|
203
|
-
|
|
213
|
+
description: 'Read configuration from a node. With `key`: that value and its schema entry (type, enum, default). Without: every current value under `values` plus the whole config schema.',
|
|
214
|
+
inputSchema: object({
|
|
215
|
+
nodeId: nodeId(),
|
|
216
|
+
key: {
|
|
217
|
+
type: 'string',
|
|
218
|
+
description: 'Config key to read; omit for all values and the schema.'
|
|
219
|
+
}
|
|
220
|
+
}, ['nodeId']),
|
|
221
|
+
build: (a) => ({
|
|
222
|
+
type: 'get_config',
|
|
223
|
+
nodeId: a.nodeId,
|
|
224
|
+
...(a.key !== undefined ? { key: a.key } : {})
|
|
225
|
+
}),
|
|
226
|
+
summarize: (c) => c.key !== undefined ? `Read ${c.nodeId}.${c.key}` : `Read config of ${c.nodeId}`
|
|
204
227
|
},
|
|
205
228
|
connect: {
|
|
206
|
-
description: 'Connect an output port of one node to an input port of another.
|
|
229
|
+
description: 'Connect an output port of one node to an input port of another. An unknown port fails and lists the ports on both sides; the existing edge is kept when the connection is already there.',
|
|
207
230
|
inputSchema: PORT_PAIR,
|
|
208
231
|
build: (a) => ({
|
|
209
232
|
type: 'connect',
|
|
@@ -245,19 +268,36 @@ const COMMANDS = {
|
|
|
245
268
|
summarize: () => 'List edges'
|
|
246
269
|
},
|
|
247
270
|
list_types: {
|
|
248
|
-
description: 'List
|
|
271
|
+
description: 'List every node type that can be added: `typeId`, name, category, description, tags. A type not in this list is unavailable in this editor. Use search_types to narrow, describe_type for ports and config.',
|
|
249
272
|
inputSchema: EMPTY,
|
|
250
273
|
build: () => ({ type: 'list_types' }),
|
|
251
274
|
summarize: () => 'List node types'
|
|
252
275
|
},
|
|
276
|
+
describe_type: {
|
|
277
|
+
description: 'Describe one node type before using it: input and output ports (id, data type, required), config keys (type, enum, default, description), and — when the host publishes them — the confirmation policy (`ask` means a run pauses for a person at this node), what you may do with it (`can`) and host guidance (`agent`). Call this before add_node and set_config.',
|
|
278
|
+
inputSchema: object({
|
|
279
|
+
nodeTypeId: {
|
|
280
|
+
type: 'string',
|
|
281
|
+
description: 'Node type id (`typeId` from list_types / search_types), e.g. "http_request".'
|
|
282
|
+
}
|
|
283
|
+
}, ['nodeTypeId']),
|
|
284
|
+
build: (a) => ({ type: 'describe_type', nodeTypeId: a.nodeTypeId }),
|
|
285
|
+
summarize: (c) => `Describe type ${c.nodeTypeId}`
|
|
286
|
+
},
|
|
287
|
+
search_types: {
|
|
288
|
+
description: 'Find node types by a case-insensitive substring of their id, name, description or tags, e.g. "markdown" or "http". Returns the same rows as list_types.',
|
|
289
|
+
inputSchema: object({ query: { type: 'string', description: 'Text to look for.' } }, ['query']),
|
|
290
|
+
build: (a) => ({ type: 'search_types', query: a.query }),
|
|
291
|
+
summarize: (c) => `Search types for ${q(c.query)}`
|
|
292
|
+
},
|
|
253
293
|
info: {
|
|
254
|
-
description:
|
|
294
|
+
description: "Describe one node instance: type, position, current config values, input and output ports, and connected edges. For the type's schema and defaults use describe_type.",
|
|
255
295
|
inputSchema: object({ nodeId: nodeId() }, ['nodeId']),
|
|
256
296
|
build: (a) => ({ type: 'info', nodeId: a.nodeId }),
|
|
257
297
|
summarize: (c) => `Describe ${c.nodeId}`
|
|
258
298
|
},
|
|
259
299
|
undo: {
|
|
260
|
-
description: 'Undo the last change. Each tool call that changed the workflow is one undo step.',
|
|
300
|
+
description: 'Undo the last change. Each tool call that changed the workflow is one undo step; a save cannot be undone.',
|
|
261
301
|
inputSchema: EMPTY,
|
|
262
302
|
build: () => ({ type: 'undo' }),
|
|
263
303
|
summarize: () => 'Undo'
|
|
@@ -359,7 +399,7 @@ const BATCH_ITEM_TYPES = [...EXPOSED_COMMAND_TYPES, 'view'];
|
|
|
359
399
|
const BATCH_SCHEMA = object({
|
|
360
400
|
commands: {
|
|
361
401
|
type: 'array',
|
|
362
|
-
description: 'Commands to run in order. Each item is the argument object of one tool plus a `type` naming that tool (without the prefix), e.g. {"type":"add_node","nodeTypeId":"
|
|
402
|
+
description: 'Commands to run in order. Each item is the argument object of one tool plus a `type` naming that tool (without the prefix), e.g. {"type":"add_node","nodeTypeId":"http_request"}. Read-only items are allowed but pointless here.',
|
|
363
403
|
items: {
|
|
364
404
|
type: 'object',
|
|
365
405
|
properties: {
|
|
@@ -430,7 +470,7 @@ export function buildToolDescriptors(options = {}) {
|
|
|
430
470
|
: [];
|
|
431
471
|
const batch = {
|
|
432
472
|
verb: 'batch',
|
|
433
|
-
description: 'Run several commands as one transaction: all succeed or none apply, and one undo reverts them all. Prefer this over many single calls when building a flow.',
|
|
473
|
+
description: 'Run several commands as one transaction: all succeed or none apply, one approval covers them all, and one undo reverts them all. Prefer this over many single calls when building a flow — describe the types first, batch the adds, connects and set_configs, then save.',
|
|
434
474
|
inputSchema: BATCH_SCHEMA,
|
|
435
475
|
readOnly: false,
|
|
436
476
|
toCommands: (args) => buildBatchCommands(args, viewEnabled)
|
|
@@ -462,3 +502,54 @@ export function describeCommand(command) {
|
|
|
462
502
|
}
|
|
463
503
|
return OTHER_SUMMARIES[type](command);
|
|
464
504
|
}
|
|
505
|
+
/**
|
|
506
|
+
* One sentence saying what a list of commands does, for the approval dialog's hint and the chat transcript:
|
|
507
|
+
* "3 changes — adds 2 nodes, connects 1 edge. Applied together, undone together."
|
|
508
|
+
* Returns `undefined` for a single command, whose one line already says it all.
|
|
509
|
+
*/
|
|
510
|
+
export function summarizeCommands(commands, m) {
|
|
511
|
+
if (commands.length < 2)
|
|
512
|
+
return undefined;
|
|
513
|
+
let adds = 0;
|
|
514
|
+
let deletes = 0;
|
|
515
|
+
let connects = 0;
|
|
516
|
+
let disconnects = 0;
|
|
517
|
+
let configs = 0;
|
|
518
|
+
let other = 0;
|
|
519
|
+
for (const c of commands) {
|
|
520
|
+
switch (c.type) {
|
|
521
|
+
case 'add_node':
|
|
522
|
+
adds++;
|
|
523
|
+
break;
|
|
524
|
+
case 'delete_node':
|
|
525
|
+
deletes++;
|
|
526
|
+
break;
|
|
527
|
+
case 'connect':
|
|
528
|
+
connects++;
|
|
529
|
+
break;
|
|
530
|
+
case 'disconnect_ports':
|
|
531
|
+
case 'disconnect_node':
|
|
532
|
+
disconnects++;
|
|
533
|
+
break;
|
|
534
|
+
case 'set_config':
|
|
535
|
+
configs++;
|
|
536
|
+
break;
|
|
537
|
+
default:
|
|
538
|
+
other++;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
const parts = [];
|
|
542
|
+
if (adds)
|
|
543
|
+
parts.push(m.summaryAdds({ count: adds }));
|
|
544
|
+
if (deletes)
|
|
545
|
+
parts.push(m.summaryDeletes({ count: deletes }));
|
|
546
|
+
if (connects)
|
|
547
|
+
parts.push(m.summaryConnects({ count: connects }));
|
|
548
|
+
if (disconnects)
|
|
549
|
+
parts.push(m.summaryDisconnects({ count: disconnects }));
|
|
550
|
+
if (configs)
|
|
551
|
+
parts.push(m.summaryConfigs({ count: configs }));
|
|
552
|
+
if (other)
|
|
553
|
+
parts.push(m.summaryOther({ count: other }));
|
|
554
|
+
return m.batchSummary({ count: commands.length, parts: parts.join(', ') });
|
|
555
|
+
}
|
package/dist/webmcp/gate.d.ts
CHANGED
|
@@ -8,20 +8,60 @@
|
|
|
8
8
|
* change the user's document. Any agent or extension on the page can call a
|
|
9
9
|
* tool, so the gate must not be weaker than the chat panel's click-to-apply.
|
|
10
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
|
+
*
|
|
11
20
|
* @module webmcp/gate
|
|
12
21
|
*/
|
|
13
22
|
import type { Command } from '../commands/types.js';
|
|
14
23
|
import type { MessagesOverride } from '../messages/index.js';
|
|
15
|
-
import type { WebMCPApproval } from './types.js';
|
|
24
|
+
import type { WebMCPApproval, WebMCPApprovalRequest } from './types.js';
|
|
25
|
+
/** What the gate needs to know about the call it is asking approval for. */
|
|
26
|
+
export interface GateRequest extends WebMCPApprovalRequest {
|
|
27
|
+
/**
|
|
28
|
+
* Dialog lines, one per command. Defaults to `commands.map(describeCommand)`;
|
|
29
|
+
* `save` and `run` have no commands to describe, so the gate fills in their
|
|
30
|
+
* line itself when this is omitted.
|
|
31
|
+
*/
|
|
32
|
+
lines?: string[];
|
|
33
|
+
/** Extra sentence shown under the title, e.g. "This cannot be undone." */
|
|
34
|
+
hint?: string;
|
|
35
|
+
/**
|
|
36
|
+
* The dialog's title — who is asking. Defaults to the WebMCP wording ("A
|
|
37
|
+
* browser agent wants to change …"); the chat panel passes its own so a
|
|
38
|
+
* shared gate still says which surface is asking.
|
|
39
|
+
*/
|
|
40
|
+
title?: string;
|
|
41
|
+
/**
|
|
42
|
+
* A consequential call (`save`, `run`) is never covered by the "don't ask
|
|
43
|
+
* again for edits" choice and never offers it. Defaults to `tool` being
|
|
44
|
+
* `save` or `run`.
|
|
45
|
+
*/
|
|
46
|
+
consequential?: boolean;
|
|
47
|
+
}
|
|
16
48
|
export interface ApprovalGate {
|
|
17
49
|
/**
|
|
18
50
|
* Ask whether `commands` may run. Resolves `true` to run. Rejects with
|
|
19
51
|
* {@link GateBusyError} when a decision is already pending — the caller
|
|
20
52
|
* turns that into a `busy` tool error instead of stacking dialogs.
|
|
21
53
|
*/
|
|
22
|
-
request(commands: Command[]): Promise<boolean>;
|
|
54
|
+
request(commands: Command[], request: GateRequest): Promise<boolean>;
|
|
23
55
|
/** True while a decision is pending. */
|
|
24
56
|
readonly busy: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Whether this gate can ask at all. `false` under `approval: 'auto'`, where
|
|
59
|
+
* every request resolves at once; a caller announcing "waiting for your
|
|
60
|
+
* approval" reads this rather than guessing from how it got the gate.
|
|
61
|
+
*/
|
|
62
|
+
readonly asks: boolean;
|
|
63
|
+
/** True once the person chose to apply further edits without asking. */
|
|
64
|
+
readonly editsPreApproved: boolean;
|
|
25
65
|
/** Dismiss any open dialog (as a rejection) and release resources. */
|
|
26
66
|
dispose(): void;
|
|
27
67
|
}
|
|
@@ -36,5 +76,7 @@ export interface CreateGateOptions {
|
|
|
36
76
|
editorName: () => string;
|
|
37
77
|
/** Strings for the dialog, as a partial override or a getter for one. */
|
|
38
78
|
messages?: MessagesOverride | (() => MessagesOverride);
|
|
79
|
+
/** Offer the "don't ask again for edits" choice. Default true. */
|
|
80
|
+
rememberEdits?: boolean;
|
|
39
81
|
}
|
|
40
82
|
export declare function createApprovalGate(approval: WebMCPApproval, options: CreateGateOptions): ApprovalGate;
|
package/dist/webmcp/gate.js
CHANGED
|
@@ -8,11 +8,20 @@
|
|
|
8
8
|
* change the user's document. Any agent or extension on the page can call a
|
|
9
9
|
* tool, so the gate must not be weaker than the chat panel's click-to-apply.
|
|
10
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
|
+
*
|
|
11
20
|
* @module webmcp/gate
|
|
12
21
|
*/
|
|
13
22
|
import { mount, unmount } from 'svelte';
|
|
14
23
|
import { defaultMessages, mergeMessages, messagesContext } from '../messages/index.js';
|
|
15
|
-
import { describeCommand } from './descriptors.js';
|
|
24
|
+
import { describeCommand, summarizeCommands } from './descriptors.js';
|
|
16
25
|
import WebMCPConfirm from './WebMCPConfirm.svelte';
|
|
17
26
|
/** A second mutating call arrived while a decision was pending. */
|
|
18
27
|
export class GateBusyError extends Error {
|
|
@@ -21,9 +30,12 @@ export class GateBusyError extends Error {
|
|
|
21
30
|
this.name = 'GateBusyError';
|
|
22
31
|
}
|
|
23
32
|
}
|
|
33
|
+
const CONSEQUENTIAL_TOOLS = new Set(['save', 'run']);
|
|
24
34
|
export function createApprovalGate(approval, options) {
|
|
25
35
|
let pending = false;
|
|
26
36
|
let dismiss = null;
|
|
37
|
+
let editsPreApproved = false;
|
|
38
|
+
const offerRemember = options.rememberEdits ?? true;
|
|
27
39
|
// The dialog mounts outside any component tree, so it gets its messages
|
|
28
40
|
// through the same context the root component would have provided. Read
|
|
29
41
|
// per access so a getter-driven locale switch shows on the next dialog.
|
|
@@ -31,14 +43,43 @@ export function createApprovalGate(approval, options) {
|
|
|
31
43
|
const override = options.messages;
|
|
32
44
|
return mergeMessages(defaultMessages, typeof override === 'function' ? override() : override);
|
|
33
45
|
};
|
|
34
|
-
|
|
46
|
+
const isConsequential = (request) => request.consequential ?? CONSEQUENTIAL_TOOLS.has(request.tool);
|
|
47
|
+
async function decide(commands, request) {
|
|
35
48
|
if (approval === 'auto')
|
|
36
49
|
return true;
|
|
37
50
|
if (typeof approval === 'function')
|
|
38
|
-
return approval(commands);
|
|
39
|
-
|
|
51
|
+
return approval(commands, { tool: request.tool });
|
|
52
|
+
// The person's earlier "don't ask again" covers edits, never save or run.
|
|
53
|
+
if (editsPreApproved && !isConsequential(request))
|
|
54
|
+
return true;
|
|
55
|
+
return confirmInPage(commands, request);
|
|
56
|
+
}
|
|
57
|
+
// `lines`/`hint` default from the commands for an ordinary change; `save`
|
|
58
|
+
// and `run` have no commands, so they get their own dialog copy.
|
|
59
|
+
function resolveLines(commands, request) {
|
|
60
|
+
if (request.lines)
|
|
61
|
+
return request.lines;
|
|
62
|
+
const m = messages().webmcp;
|
|
63
|
+
if (request.tool === 'save')
|
|
64
|
+
return [m.saveLine({ name: options.editorName() })];
|
|
65
|
+
if (request.tool === 'run')
|
|
66
|
+
return [m.runLine({ name: options.editorName() })];
|
|
67
|
+
return commands.map(describeCommand);
|
|
68
|
+
}
|
|
69
|
+
function resolveTitle(request) {
|
|
70
|
+
return request.title ?? messages().webmcp.confirmTitle({ name: options.editorName() });
|
|
40
71
|
}
|
|
41
|
-
function
|
|
72
|
+
function resolveHint(commands, request) {
|
|
73
|
+
if (request.hint !== undefined)
|
|
74
|
+
return request.hint;
|
|
75
|
+
const m = messages().webmcp;
|
|
76
|
+
if (request.tool === 'save')
|
|
77
|
+
return m.saveHint;
|
|
78
|
+
if (request.tool === 'run')
|
|
79
|
+
return m.runHint;
|
|
80
|
+
return summarizeCommands(commands, m);
|
|
81
|
+
}
|
|
82
|
+
function confirmInPage(commands, request) {
|
|
42
83
|
const target = options.container ?? (typeof document !== 'undefined' ? document.body : null);
|
|
43
84
|
if (!target) {
|
|
44
85
|
// No DOM to ask in: refuse rather than silently apply.
|
|
@@ -49,21 +90,25 @@ export function createApprovalGate(approval, options) {
|
|
|
49
90
|
const host = document.createElement('div');
|
|
50
91
|
host.className = 'fd-webmcp-confirm-host';
|
|
51
92
|
target.appendChild(host);
|
|
52
|
-
const finish = (approved) => {
|
|
93
|
+
const finish = (approved, remember = false) => {
|
|
53
94
|
if (settled)
|
|
54
95
|
return;
|
|
55
96
|
settled = true;
|
|
56
97
|
dismiss = null;
|
|
57
98
|
void unmount(component);
|
|
58
99
|
host.remove();
|
|
100
|
+
if (approved && remember)
|
|
101
|
+
editsPreApproved = true;
|
|
59
102
|
resolve(approved);
|
|
60
103
|
};
|
|
61
104
|
const component = mount(WebMCPConfirm, {
|
|
62
105
|
target: host,
|
|
63
106
|
context: messagesContext(messages),
|
|
64
107
|
props: {
|
|
65
|
-
|
|
66
|
-
lines: commands
|
|
108
|
+
title: resolveTitle(request),
|
|
109
|
+
lines: resolveLines(commands, request),
|
|
110
|
+
hint: resolveHint(commands, request),
|
|
111
|
+
offerRemember: offerRemember && !isConsequential(request),
|
|
67
112
|
onResolve: finish
|
|
68
113
|
}
|
|
69
114
|
});
|
|
@@ -74,12 +119,18 @@ export function createApprovalGate(approval, options) {
|
|
|
74
119
|
get busy() {
|
|
75
120
|
return pending;
|
|
76
121
|
},
|
|
77
|
-
|
|
122
|
+
get asks() {
|
|
123
|
+
return approval !== 'auto';
|
|
124
|
+
},
|
|
125
|
+
get editsPreApproved() {
|
|
126
|
+
return editsPreApproved;
|
|
127
|
+
},
|
|
128
|
+
async request(commands, request) {
|
|
78
129
|
if (pending)
|
|
79
130
|
throw new GateBusyError();
|
|
80
131
|
pending = true;
|
|
81
132
|
try {
|
|
82
|
-
return await decide(commands);
|
|
133
|
+
return await decide(commands, request);
|
|
83
134
|
}
|
|
84
135
|
finally {
|
|
85
136
|
pending = false;
|
package/dist/webmcp/index.d.ts
CHANGED
|
@@ -25,10 +25,15 @@
|
|
|
25
25
|
* ```
|
|
26
26
|
*/
|
|
27
27
|
export { attachWebMCP, detectModelContext, DEFAULT_PREFIX } from './register.js';
|
|
28
|
-
export {
|
|
28
|
+
export { createToolRuntime, buildHostToolDescriptors } from './runtime.js';
|
|
29
|
+
export { createApprovalGate, GateBusyError } from './gate.js';
|
|
30
|
+
export type { ApprovalGate, GateRequest, CreateGateOptions } from './gate.js';
|
|
31
|
+
export { buildToolDescriptors, describeCommand, summarizeCommands, EXPOSED_COMMAND_TYPES, VIEW_COMMAND_TYPES, EXCLUDED_COMMAND_TYPES, COMPOSITE_VERBS } from './descriptors.js';
|
|
29
32
|
export type { BuildDescriptorsOptions } from './descriptors.js';
|
|
30
33
|
export { validateToolArgs, VALIDATOR_KEYWORDS } from './validate.js';
|
|
31
34
|
export { ToolArgumentError } from './types.js';
|
|
32
35
|
export { createFakeModelContext } from './fake.js';
|
|
33
36
|
export type { FakeModelContext } from './fake.js';
|
|
34
|
-
export
|
|
37
|
+
export { createBridgedModelContext, installBridgedModelContext } from './bridge.js';
|
|
38
|
+
export type { WebMCPWidgetLike, BridgedModelContext } from './bridge.js';
|
|
39
|
+
export type { ToolDescriptor, ToolInputSchema, ToolSchemaProperty, ToolResult, ToolExecuteOptions, RegisteredToolDefinition, RegisterToolOptions, ModelContextLike, WebMCPApproval, WebMCPApprovalRequest, HostCode, HostEnvelope, RunStarted, RunPending, RunStatus, WebMCPOptions, WebMCPMountOptions, WebMCPHandle, HostHooks, HostToolDescriptor, ToolPreview, ToolRuntime, ToolRuntimeOptions } from './types.js';
|
package/dist/webmcp/index.js
CHANGED
|
@@ -25,7 +25,10 @@
|
|
|
25
25
|
* ```
|
|
26
26
|
*/
|
|
27
27
|
export { attachWebMCP, detectModelContext, DEFAULT_PREFIX } from './register.js';
|
|
28
|
-
export {
|
|
28
|
+
export { createToolRuntime, buildHostToolDescriptors } from './runtime.js';
|
|
29
|
+
export { createApprovalGate, GateBusyError } from './gate.js';
|
|
30
|
+
export { buildToolDescriptors, describeCommand, summarizeCommands, EXPOSED_COMMAND_TYPES, VIEW_COMMAND_TYPES, EXCLUDED_COMMAND_TYPES, COMPOSITE_VERBS } from './descriptors.js';
|
|
29
31
|
export { validateToolArgs, VALIDATOR_KEYWORDS } from './validate.js';
|
|
30
32
|
export { ToolArgumentError } from './types.js';
|
|
31
33
|
export { createFakeModelContext } from './fake.js';
|
|
34
|
+
export { createBridgedModelContext, installBridgedModelContext } from './bridge.js';
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WebMCP adapter — registration.
|
|
3
3
|
*
|
|
4
|
-
* The only file that touches the
|
|
5
|
-
* back to `navigator.modelContext`). Builds
|
|
6
|
-
*
|
|
7
|
-
* `
|
|
8
|
-
* detaching is a single `abort()`.
|
|
4
|
+
* The only file that touches the browser's model context
|
|
5
|
+
* (`document.modelContext`, falling back to `navigator.modelContext`). Builds
|
|
6
|
+
* a tool runtime for the instance, registers each of its tools with an
|
|
7
|
+
* `execute` that delegates to `runTool()`, and registers the lot under one
|
|
8
|
+
* AbortSignal so detaching is a single `abort()`. What a call *does* — validation, the gate, the batch —
|
|
9
|
+
* lives in `runtime.ts`, which the chat panel shares.
|
|
9
10
|
*
|
|
10
11
|
* @module webmcp/register
|
|
11
12
|
*/
|
|
12
13
|
import type { FlowDropInstance } from '../stores/instanceContainer.svelte.js';
|
|
13
|
-
import {
|
|
14
|
+
import type { ModelContextLike, WebMCPHandle, WebMCPOptions } from './types.js';
|
|
14
15
|
export declare const DEFAULT_PREFIX = "flowdrop";
|
|
15
16
|
/**
|
|
16
|
-
* Find the WebMCP
|
|
17
|
+
* Find the WebMCP model context on this page, or `null` when the browser has none.
|
|
17
18
|
* Structural: anything with a callable `registerTool` counts.
|
|
18
19
|
*/
|
|
19
20
|
export declare function detectModelContext(): ModelContextLike | null;
|
|
@@ -21,12 +22,12 @@ export declare function detectModelContext(): ModelContextLike | null;
|
|
|
21
22
|
* Register the editor's commands as WebMCP tools for `instance`.
|
|
22
23
|
*
|
|
23
24
|
* Returns `null` — with no console output — when the page has no WebMCP
|
|
24
|
-
*
|
|
25
|
-
* already registered on this
|
|
25
|
+
* model context, so hosts can call it unconditionally. Throws when the prefix is
|
|
26
|
+
* already registered on this model context (two editors on one page need distinct
|
|
26
27
|
* prefixes).
|
|
27
28
|
*
|
|
28
29
|
* Registration settles asynchronously: `handle.tools` lists the tools the
|
|
29
|
-
*
|
|
30
|
+
* model context has accepted so far and `handle.ready` resolves when every
|
|
30
31
|
* registration has settled. The registration is torn down by
|
|
31
32
|
* `handle.detach()` or automatically when `instance.destroy()` runs.
|
|
32
33
|
*/
|