@flowdrop/flowdrop 2.7.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.
Files changed (55) hide show
  1. package/CHANGELOG.md +31 -1
  2. package/dist/api/enhanced-client.d.ts +29 -1
  3. package/dist/api/enhanced-client.js +83 -9
  4. package/dist/chat/index.d.ts +5 -1
  5. package/dist/chat/index.js +2 -0
  6. package/dist/chat/toolCatalogue.d.ts +27 -0
  7. package/dist/chat/toolCatalogue.js +35 -0
  8. package/dist/chat/turnDriver.d.ts +143 -0
  9. package/dist/chat/turnDriver.js +124 -0
  10. package/dist/components/App.svelte +47 -56
  11. package/dist/components/SettingsPanel.svelte +13 -0
  12. package/dist/components/WorkflowEditor.svelte +4 -2
  13. package/dist/components/WorkflowEditor.svelte.d.ts +2 -0
  14. package/dist/components/chat/AIChatPanel.svelte +410 -22
  15. package/dist/components/toast/DismissibleToast.svelte +53 -0
  16. package/dist/components/toast/DismissibleToast.svelte.d.ts +24 -0
  17. package/dist/components/toast/WarningIcon.svelte +28 -0
  18. package/dist/components/toast/WarningIcon.svelte.d.ts +26 -0
  19. package/dist/config/constants.d.ts +7 -3
  20. package/dist/config/constants.js +7 -3
  21. package/dist/config/endpoints.d.ts +7 -0
  22. package/dist/config/endpoints.js +2 -1
  23. package/dist/editor/index.d.ts +1 -1
  24. package/dist/editor/index.js +1 -1
  25. package/dist/messages/defaults.d.ts +41 -0
  26. package/dist/messages/defaults.js +20 -0
  27. package/dist/services/chatService.d.ts +21 -3
  28. package/dist/services/chatService.js +33 -1
  29. package/dist/services/globalSave.js +3 -1
  30. package/dist/services/toastService.d.ts +23 -2
  31. package/dist/services/toastService.js +72 -28
  32. package/dist/stores/instanceContainer.svelte.d.ts +34 -0
  33. package/dist/stores/instanceContainer.svelte.js +30 -0
  34. package/dist/styles/toast.css +62 -0
  35. package/dist/svelte-app.d.ts +12 -2
  36. package/dist/svelte-app.js +29 -12
  37. package/dist/types/chat.d.ts +59 -0
  38. package/dist/types/events.d.ts +23 -0
  39. package/dist/types/events.js +3 -1
  40. package/dist/types/settings.d.ts +18 -1
  41. package/dist/types/settings.js +1 -0
  42. package/dist/webmcp/WebMCPConfirm.svelte +129 -68
  43. package/dist/webmcp/WebMCPConfirm.svelte.d.ts +2 -2
  44. package/dist/webmcp/descriptors.d.ts +7 -0
  45. package/dist/webmcp/descriptors.js +51 -0
  46. package/dist/webmcp/gate.d.ts +13 -7
  47. package/dist/webmcp/gate.js +8 -53
  48. package/dist/webmcp/index.d.ts +5 -2
  49. package/dist/webmcp/index.js +3 -1
  50. package/dist/webmcp/register.d.ts +11 -10
  51. package/dist/webmcp/register.js +59 -384
  52. package/dist/webmcp/runtime.d.ts +33 -0
  53. package/dist/webmcp/runtime.js +500 -0
  54. package/dist/webmcp/types.d.ts +92 -0
  55. package/package.json +1 -1
@@ -29,11 +29,15 @@ export const EDGE_MARKER_SIZES = {
29
29
  tool: { width: 16, height: 16 },
30
30
  data: { width: 16, height: 16 }
31
31
  };
32
- /** Toast notification durations in milliseconds */
32
+ /**
33
+ * How long each kind of toast stays, in milliseconds. `Infinity` means it
34
+ * stays until the user closes it: errors and warnings name something to act
35
+ * on, and a message that vanishes mid-read was never delivered.
36
+ */
33
37
  export const TOAST_DURATION = {
34
38
  SUCCESS: 4_000,
35
- ERROR: 6_000,
36
- WARNING: 5_000,
39
+ ERROR: Infinity,
40
+ WARNING: Infinity,
37
41
  INFO: 4_000,
38
42
  CONFIRMATION: 5_000
39
43
  };
@@ -127,6 +127,13 @@ export interface EndpointConfig {
127
127
  getHistory: string;
128
128
  /** Clear conversation history */
129
129
  clearHistory: string;
130
+ /**
131
+ * Continue a tool-calling turn with the results of the tool calls the
132
+ * assistant made (`POST`, `{turnId}` in the path). Optional: a backend
133
+ * without it gets the legacy text mode — the panel sends one message,
134
+ * parses the ```flowdrop block in the reply, and asks before applying.
135
+ */
136
+ toolResults?: string;
130
137
  };
131
138
  templates: {
132
139
  list: string;
@@ -73,7 +73,8 @@ export const defaultEndpointConfig = {
73
73
  chat: {
74
74
  sendMessage: '/workflows/{id}/chat/messages',
75
75
  getHistory: '/workflows/{id}/chat/messages',
76
- clearHistory: '/workflows/{id}/chat/messages'
76
+ clearHistory: '/workflows/{id}/chat/messages',
77
+ toolResults: '/workflows/{id}/chat/turns/{turnId}/tool-results'
77
78
  },
78
79
  templates: {
79
80
  list: '/templates',
@@ -82,7 +82,7 @@ export { fetchCategories, validateCategories } from '../services/categoriesApi.j
82
82
  export { fetchDynamicSchema, resolveExternalEditUrl, getEffectiveConfigEditOptions, clearSchemaCache, invalidateSchemaCache, hasConfigEditOptions, shouldShowExternalEdit, shouldUseDynamicSchema } from '../services/dynamicSchemaService.js';
83
83
  export { getDraftStorageKey, saveDraft, loadDraft, deleteDraft, hasDraft, getDraftMetadata, clearAllDrafts, setDraftStorage, getDraftStorage, resolveDraftStorage, DraftAutoSaveManager } from '../services/draftStorage.js';
84
84
  export type { DraftStorageAdapter, DraftStorageType, DraftStorageOption } from '../services/draftStorage.js';
85
- export { EnhancedFlowDropApiClient, ApiError } from '../api/enhanced-client.js';
85
+ export { EnhancedFlowDropApiClient, ApiError, parseApiErrorBody, errorDetails } from '../api/enhanced-client.js';
86
86
  export { isLoopbackEdge, isValidLoopbackCycle, PortCompatibilityChecker, getPossibleConnections, validateConnection, getConnectionSuggestions, hasCycles, hasInvalidCycles, getExecutionOrder } from '../utils/connections.js';
87
87
  export { SHAPE_GLYPH, portShape, portGlyph } from '../utils/portShape.js';
88
88
  export type { PortShape } from '../utils/portShape.js';
@@ -119,7 +119,7 @@ export { getDraftStorageKey, saveDraft, loadDraft, deleteDraft, hasDraft, getDra
119
119
  // ============================================================================
120
120
  // API Clients
121
121
  // ============================================================================
122
- export { EnhancedFlowDropApiClient, ApiError } from '../api/enhanced-client.js';
122
+ export { EnhancedFlowDropApiClient, ApiError, parseApiErrorBody, errorDetails } from '../api/enhanced-client.js';
123
123
  // ============================================================================
124
124
  // Connection Utilities
125
125
  // ============================================================================
@@ -265,6 +265,47 @@ export declare const defaultMessages: {
265
265
  attempt: number;
266
266
  max: number;
267
267
  }) => string;
268
+ readonly tools: {
269
+ /** Status line while a read tool runs: `Reading: describe_type http_request`. */
270
+ readonly reading: ({ tool, detail }: {
271
+ tool: string;
272
+ detail: string;
273
+ }) => string;
274
+ readonly awaitingApproval: ({ tool }: {
275
+ tool: string;
276
+ }) => string;
277
+ /** Title of the approval dialog when the assistant, not a browser agent, asks. */
278
+ readonly confirmTitle: ({ name }: {
279
+ name: string;
280
+ }) => string;
281
+ /** A read that completed: `Read: describe_type http_request`. */
282
+ readonly read: ({ tool, detail }: {
283
+ tool: string;
284
+ detail: string;
285
+ }) => string;
286
+ readonly applied: ({ tool, detail }: {
287
+ tool: string;
288
+ detail: string;
289
+ }) => string;
290
+ readonly rejected: ({ tool }: {
291
+ tool: string;
292
+ }) => string;
293
+ readonly failed: ({ tool, error }: {
294
+ tool: string;
295
+ error: string;
296
+ }) => string;
297
+ readonly rounds: ({ count }: {
298
+ count: number;
299
+ }) => string;
300
+ readonly legacyFallback: "This backend does not support tool-calling turns; using the text mode for this session.";
301
+ readonly aborted: ({ reason }: {
302
+ reason: string;
303
+ }) => string;
304
+ /** Deterministic warning under the reply when one or more tool calls failed this turn. */
305
+ readonly failedSummary: ({ count }: {
306
+ count: number;
307
+ }) => string;
308
+ };
268
309
  readonly commandPreview: {
269
310
  readonly ariaLabel: "Command preview";
270
311
  readonly applying: "Applying…";
@@ -243,6 +243,26 @@ export const defaultMessages = {
243
243
  placeholder: 'Describe what you want to build...',
244
244
  send: 'Send message',
245
245
  autoRetry: ({ attempt, max }) => `Auto-retrying (attempt ${attempt}/${max})…`,
246
+ // Tool-calling turns (tools mode).
247
+ tools: {
248
+ /** Status line while a read tool runs: `Reading: describe_type http_request`. */
249
+ reading: ({ tool, detail }) => detail ? `Reading: ${tool} ${detail}` : `Reading: ${tool}`,
250
+ awaitingApproval: ({ tool }) => `Waiting for your approval: ${tool}`,
251
+ /** Title of the approval dialog when the assistant, not a browser agent, asks. */
252
+ confirmTitle: ({ name }) => `The assistant wants to change “${name}”`,
253
+ /** A read that completed: `Read: describe_type http_request`. */
254
+ read: ({ tool, detail }) => detail ? `Read: ${tool} ${detail}` : `Read: ${tool}`,
255
+ applied: ({ tool, detail }) => detail ? `Applied: ${detail}` : `Done: ${tool}`,
256
+ rejected: ({ tool }) => `You rejected: ${tool}`,
257
+ failed: ({ tool, error }) => `${tool} failed: ${error}`,
258
+ rounds: ({ count }) => `${count} ${count === 1 ? 'tool round' : 'tool rounds'}`,
259
+ legacyFallback: 'This backend does not support tool-calling turns; using the text mode for this session.',
260
+ aborted: ({ reason }) => `Stopped: ${reason}`,
261
+ /** Deterministic warning under the reply when one or more tool calls failed this turn. */
262
+ failedSummary: ({ count }) => count === 1
263
+ ? 'One tool call failed during this turn. Check the steps above before relying on the reply.'
264
+ : `${count} tool calls failed during this turn. Check the steps above before relying on the reply.`
265
+ },
246
266
  // CommandPreview labels.
247
267
  commandPreview: {
248
268
  ariaLabel: 'Command preview',
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * @module services/chatService
8
8
  */
9
- import type { ChatRequest, ChatResponse, ChatHistoryMessage } from '../types/chat.js';
9
+ import type { ChatRequest, ChatHistoryMessage, ChatToolResultsRequest, ChatTurnResponse } from '../types/chat.js';
10
10
  import type { EndpointConfig } from '../config/endpoints.js';
11
11
  import type { AuthProvider } from '../types/auth.js';
12
12
  /**
@@ -43,13 +43,31 @@ export declare class ChatService {
43
43
  */
44
44
  private request;
45
45
  /**
46
- * Send a message to the chat endpoint
46
+ * Send a message to the chat endpoint.
47
+ *
48
+ * With a {@link ChatTurnRequest} (a `tools` list) a tool-calling server
49
+ * answers a {@link ChatTurnResponse}; a legacy server ignores the list and
50
+ * answers a plain {@link ChatResponse} (no `turnId`). The return type is
51
+ * the union of the two so callers branch on `turnId`.
47
52
  *
48
53
  * @param workflowId - The workflow ID
49
54
  * @param request - The chat request payload
50
55
  * @returns The chat response from the LLM
51
56
  */
52
- sendMessage(endpointConfig: EndpointConfig | null, workflowId: string, request: ChatRequest, authProvider?: AuthProvider): Promise<ChatResponse>;
57
+ sendMessage(endpointConfig: EndpointConfig | null, workflowId: string, request: ChatRequest, authProvider?: AuthProvider): Promise<ChatTurnResponse>;
58
+ /**
59
+ * Whether the configured backend has the tool-results door — the
60
+ * precondition for the panel's tools mode.
61
+ */
62
+ supportsToolTurns(endpointConfig: EndpointConfig | null): boolean;
63
+ /**
64
+ * Continue a tool-calling turn with the results of the calls the assistant
65
+ * made. The server runs the reasoner again and answers either more calls
66
+ * (`done: false`) or the final text (`done: true`).
67
+ *
68
+ * @throws Error when the backend has no `chat.toolResults` endpoint
69
+ */
70
+ sendToolResults(endpointConfig: EndpointConfig | null, workflowId: string, turnId: string, request: ChatToolResultsRequest, authProvider?: AuthProvider): Promise<ChatTurnResponse>;
53
71
  /**
54
72
  * Get conversation history for a workflow
55
73
  *
@@ -75,7 +75,12 @@ export class ChatService {
75
75
  // Chat Operations
76
76
  // =========================================================================
77
77
  /**
78
- * Send a message to the chat endpoint
78
+ * Send a message to the chat endpoint.
79
+ *
80
+ * With a {@link ChatTurnRequest} (a `tools` list) a tool-calling server
81
+ * answers a {@link ChatTurnResponse}; a legacy server ignores the list and
82
+ * answers a plain {@link ChatResponse} (no `turnId`). The return type is
83
+ * the union of the two so callers branch on `turnId`.
79
84
  *
80
85
  * @param workflowId - The workflow ID
81
86
  * @param request - The chat request payload
@@ -92,6 +97,33 @@ export class ChatService {
92
97
  body: JSON.stringify(request)
93
98
  }, authProvider);
94
99
  }
100
+ /**
101
+ * Whether the configured backend has the tool-results door — the
102
+ * precondition for the panel's tools mode.
103
+ */
104
+ supportsToolTurns(endpointConfig) {
105
+ return typeof endpointConfig?.endpoints?.chat?.toolResults === 'string';
106
+ }
107
+ /**
108
+ * Continue a tool-calling turn with the results of the calls the assistant
109
+ * made. The server runs the reasoner again and answers either more calls
110
+ * (`done: false`) or the final text (`done: true`).
111
+ *
112
+ * @throws Error when the backend has no `chat.toolResults` endpoint
113
+ */
114
+ async sendToolResults(endpointConfig, workflowId, turnId, request, authProvider) {
115
+ const config = this.getConfig(endpointConfig);
116
+ const template = config.endpoints.chat.toolResults;
117
+ if (!template) {
118
+ throw new Error('This backend has no chat tool-results endpoint.');
119
+ }
120
+ const url = buildEndpointUrl(config, template, { id: workflowId, turnId });
121
+ logger.debug('[ChatService] Posting tool results to', url);
122
+ return this.request(config, url, {
123
+ method: 'POST',
124
+ body: JSON.stringify(request)
125
+ }, authProvider);
126
+ }
95
127
  /**
96
128
  * Get conversation history for a workflow
97
129
  *
@@ -195,7 +195,9 @@ export async function globalSaveWorkflow(options = {}) {
195
195
  suppressToast = eventHandlers.onApiError(errorObj, 'save') === true;
196
196
  }
197
197
  if (features.showToasts && !suppressToast) {
198
- apiToasts.error('Save workflow', errorObj.message);
198
+ // The error object, not its message: an ApiError carries the server's
199
+ // reasons as `details`, and the toast renders them as a list.
200
+ apiToasts.error('Save workflow', errorObj);
199
201
  }
200
202
  throw error;
201
203
  }
@@ -21,6 +21,17 @@ export type ToastType = 'success' | 'error' | 'warning' | 'info' | 'loading';
21
21
  */
22
22
  export interface ToastOptions {
23
23
  duration?: number;
24
+ /**
25
+ * Reasons behind the message, rendered as a list under it (errors and
26
+ * warnings only). Pass `ApiError.details` here.
27
+ */
28
+ details?: readonly string[];
29
+ /**
30
+ * Stable id: a toast with the same id replaces the one already showing
31
+ * instead of stacking. Errors and warnings default to an id derived from
32
+ * their text, so repeating a failing action does not wallpaper the screen.
33
+ */
34
+ id?: string;
24
35
  position?: 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right';
25
36
  }
26
37
  /**
@@ -28,11 +39,21 @@ export interface ToastOptions {
28
39
  */
29
40
  export declare function showSuccess(message: string, options?: ToastOptions): string;
30
41
  /**
31
- * Show an error toast notification
42
+ * Show an error toast notification.
43
+ *
44
+ * Stays until the user closes it (TOAST_DURATION.ERROR is Infinity). Pass a
45
+ * finite `duration` to opt back into auto-dismiss.
32
46
  */
33
47
  export declare function showError(message: string, options?: ToastOptions): string;
34
48
  /**
35
- * Show a warning toast notification
49
+ * Show a warning toast notification.
50
+ *
51
+ * Persists until dismissed, like an error. The stance behind that: a warning
52
+ * here is not "done, by the way" — the editor reserves it for something the
53
+ * user should act on (an agent's config key that was ignored, an import that
54
+ * dropped nodes), and a message like that must not vanish mid-read. Pass a
55
+ * finite `duration` for a warning that is only informational. Wears its own
56
+ * icon and colour so it is not mistaken for an error.
36
57
  */
37
58
  export declare function showWarning(message: string, options?: ToastOptions): string;
38
59
  /**
@@ -5,6 +5,18 @@
5
5
  */
6
6
  import { toast } from 'svelte-5-french-toast';
7
7
  import { TOAST_DURATION } from '../config/constants.js';
8
+ import { errorDetails } from '../api/enhanced-client.js';
9
+ import DismissibleToast from '../components/toast/DismissibleToast.svelte';
10
+ import WarningIcon from '../components/toast/WarningIcon.svelte';
11
+ /**
12
+ * TYPE DEBT — remove when svelte-5-french-toast types `Renderable` as
13
+ * Svelte 5's `Component` instead of the legacy `SvelteComponent` class
14
+ * (dist/core/types.d.ts). The runtime renders a Svelte 5 component fine;
15
+ * only the declaration is behind, so this is the one place the lie lives.
16
+ */
17
+ const asRenderable = (component) => component;
18
+ const dismissibleToast = asRenderable(DismissibleToast);
19
+ const warningIcon = asRenderable(WarningIcon);
8
20
  /**
9
21
  * Default toast options themed with FlowDrop design tokens.
10
22
  * Use with <Toaster toastOptions={flowdropToastOptions} containerClassName="flowdrop-toaster" />
@@ -34,31 +46,54 @@ export const flowdropToastOptions = {
34
46
  };
35
47
  /** Container class for FlowDrop-themed Toaster (used with toast.css). */
36
48
  export const FLOWDROP_TOASTER_CLASS = 'flowdrop-toaster';
49
+ /** Default id for a persistent toast: one per distinct text. */
50
+ function dedupeId(kind, message, details = []) {
51
+ return `${kind}:${[message, ...details].join('\n')}`;
52
+ }
37
53
  /**
38
54
  * Show a success toast notification
39
55
  */
40
56
  export function showSuccess(message, options) {
41
57
  return toast.success(message, {
42
- duration: options?.duration || TOAST_DURATION.SUCCESS,
43
- position: options?.position || 'bottom-center'
58
+ id: options?.id,
59
+ duration: options?.duration ?? TOAST_DURATION.SUCCESS,
60
+ position: options?.position ?? 'bottom-center'
44
61
  });
45
62
  }
46
63
  /**
47
- * Show an error toast notification
64
+ * Show an error toast notification.
65
+ *
66
+ * Stays until the user closes it (TOAST_DURATION.ERROR is Infinity). Pass a
67
+ * finite `duration` to opt back into auto-dismiss.
48
68
  */
49
69
  export function showError(message, options) {
50
- return toast.error(message, {
51
- duration: options?.duration || TOAST_DURATION.ERROR,
52
- position: options?.position || 'bottom-center'
70
+ const details = options?.details ?? [];
71
+ return toast.error(dismissibleToast, {
72
+ id: options?.id ?? dedupeId('error', message, details),
73
+ props: { text: message, details },
74
+ duration: options?.duration ?? TOAST_DURATION.ERROR,
75
+ position: options?.position ?? 'bottom-center'
53
76
  });
54
77
  }
55
78
  /**
56
- * Show a warning toast notification
79
+ * Show a warning toast notification.
80
+ *
81
+ * Persists until dismissed, like an error. The stance behind that: a warning
82
+ * here is not "done, by the way" — the editor reserves it for something the
83
+ * user should act on (an agent's config key that was ignored, an import that
84
+ * dropped nodes), and a message like that must not vanish mid-read. Pass a
85
+ * finite `duration` for a warning that is only informational. Wears its own
86
+ * icon and colour so it is not mistaken for an error.
57
87
  */
58
88
  export function showWarning(message, options) {
59
- return toast.error(message, {
60
- duration: options?.duration || TOAST_DURATION.WARNING,
61
- position: options?.position || 'bottom-center'
89
+ const details = options?.details ?? [];
90
+ return toast(dismissibleToast, {
91
+ id: options?.id ?? dedupeId('warning', message, details),
92
+ props: { text: message, details },
93
+ icon: warningIcon,
94
+ className: 'flowdrop-toast-bar flowdrop-toast-bar--warning',
95
+ duration: options?.duration ?? TOAST_DURATION.WARNING,
96
+ position: options?.position ?? 'bottom-center'
62
97
  });
63
98
  }
64
99
  /**
@@ -66,8 +101,9 @@ export function showWarning(message, options) {
66
101
  */
67
102
  export function showInfo(message, options) {
68
103
  return toast.success(message, {
69
- duration: options?.duration || TOAST_DURATION.INFO,
70
- position: options?.position || 'bottom-center'
104
+ id: options?.id,
105
+ duration: options?.duration ?? TOAST_DURATION.INFO,
106
+ position: options?.position ?? 'bottom-center'
71
107
  });
72
108
  }
73
109
  /**
@@ -75,8 +111,9 @@ export function showInfo(message, options) {
75
111
  */
76
112
  export function showLoading(message, options) {
77
113
  return toast.loading(message, {
78
- duration: options?.duration || Infinity,
79
- position: options?.position || 'bottom-center'
114
+ id: options?.id,
115
+ duration: options?.duration ?? Infinity,
116
+ position: options?.position ?? 'bottom-center'
80
117
  });
81
118
  }
82
119
  /**
@@ -107,10 +144,17 @@ export function showPromise(promise, { loading, success, error, options }) {
107
144
  */
108
145
  export function showConfirmation(message, options) {
109
146
  return toast(message, {
110
- duration: options?.duration || TOAST_DURATION.CONFIRMATION,
111
- position: options?.position || 'bottom-center'
147
+ id: options?.id,
148
+ duration: options?.duration ?? TOAST_DURATION.CONFIRMATION,
149
+ position: options?.position ?? 'bottom-center'
112
150
  });
113
151
  }
152
+ /** Headline and reasons of a thrown error; see `errorDetails`. */
153
+ function errorParts(error) {
154
+ if (typeof error === 'string')
155
+ return { message: error, details: [] };
156
+ return { message: error.message, details: errorDetails(error) };
157
+ }
114
158
  /**
115
159
  * API-specific toast helpers
116
160
  */
@@ -126,8 +170,8 @@ export const apiToasts = {
126
170
  * Show API error message
127
171
  */
128
172
  error: (operation, error) => {
129
- const errorMessage = error instanceof Error ? error.message : error;
130
- return showError(`${operation} failed: ${errorMessage}`);
173
+ const { message, details } = errorParts(error);
174
+ return showError(`${operation} failed: ${message}`, { details });
131
175
  },
132
176
  /**
133
177
  * Show API loading message
@@ -163,8 +207,8 @@ export const workflowToasts = {
163
207
  * Show workflow save error
164
208
  */
165
209
  saveError: (error) => {
166
- const errorMessage = error instanceof Error ? error.message : error;
167
- return showError(`Failed to save workflow: ${errorMessage}`);
210
+ const { message, details } = errorParts(error);
211
+ return showError(`Failed to save workflow: ${message}`, { details });
168
212
  },
169
213
  /**
170
214
  * Show workflow delete success
@@ -179,8 +223,8 @@ export const workflowToasts = {
179
223
  * Show workflow delete error
180
224
  */
181
225
  deleteError: (error) => {
182
- const errorMessage = error instanceof Error ? error.message : error;
183
- return showError(`Failed to delete workflow: ${errorMessage}`);
226
+ const { message, details } = errorParts(error);
227
+ return showError(`Failed to delete workflow: ${message}`, { details });
184
228
  },
185
229
  /**
186
230
  * Show workflow execution started
@@ -213,8 +257,8 @@ export const workflowToasts = {
213
257
  * Show workflow execution error
214
258
  */
215
259
  executionError: (error) => {
216
- const errorMessage = error instanceof Error ? error.message : error;
217
- return showError(`Workflow execution failed: ${errorMessage}`);
260
+ const { message, details } = errorParts(error);
261
+ return showError(`Workflow execution failed: ${message}`, { details });
218
262
  }
219
263
  };
220
264
  /**
@@ -234,8 +278,8 @@ export const pipelineToasts = {
234
278
  * Show pipeline creation error
235
279
  */
236
280
  creationError: (error) => {
237
- const errorMessage = error instanceof Error ? error.message : error;
238
- return showError(`Failed to create pipeline: ${errorMessage}`);
281
+ const { message, details } = errorParts(error);
282
+ return showError(`Failed to create pipeline: ${message}`, { details });
239
283
  },
240
284
  /**
241
285
  * Show pipeline execution started
@@ -253,8 +297,8 @@ export const pipelineToasts = {
253
297
  * Show pipeline execution error
254
298
  */
255
299
  executionError: (pipelineId, error) => {
256
- const errorMessage = error instanceof Error ? error.message : error;
257
- return showError(`Pipeline ${pipelineId} execution failed: ${errorMessage}`);
300
+ const { message, details } = errorParts(error);
301
+ return showError(`Pipeline ${pipelineId} execution failed: ${message}`, { details });
258
302
  },
259
303
  /**
260
304
  * Show pipeline status update
@@ -14,6 +14,8 @@
14
14
  * @module stores/instanceContainer
15
15
  */
16
16
  import type { NodeMetadata } from '../types/index.js';
17
+ import type { HostHooks } from '../webmcp/types.js';
18
+ import type { ApprovalGate } from '../webmcp/gate.js';
17
19
  import { HistoryService } from '../services/historyService.js';
18
20
  import { WorkflowStore } from './workflowStore.svelte.js';
19
21
  import { HistoryStore } from './historyStore.svelte.js';
@@ -84,6 +86,23 @@ export interface FlowDropInstance {
84
86
  * again (the WebMCP adapter's `list_types`, `add_node`).
85
87
  */
86
88
  readonly nodeTypes: NodeTypesStore;
89
+ /**
90
+ * The host's save/run/status hooks for this editor, as the mount supplied
91
+ * them (`mountFlowDropApp` sets `onSave` to its own Save and copies the
92
+ * `webmcp` option's `onRun`/`onRunStatus`). Read by anything that offers
93
+ * the `save`, `run` and `run_status` tools without a WebMCP runtime — the
94
+ * chat panel's tool loop — so both agents persist and run exactly the way
95
+ * clicking Save does.
96
+ */
97
+ readonly host: HostHooksStore;
98
+ /**
99
+ * The approval gate every agent surface on this editor asks — the WebMCP
100
+ * registration and the chat panel's tool loop. Whichever surface comes
101
+ * first creates its gate and publishes it here; the other reuses it, so one
102
+ * "don't ask again for edits" covers both and two dialogs never stack. The
103
+ * publisher clears it when it goes away. `null` until a surface exists.
104
+ */
105
+ approvalGate: ApprovalGate | null;
87
106
  /**
88
107
  * Run `fn` when this instance is destroyed. Returns an unsubscribe; calling
89
108
  * it before `destroy()` means `fn` never runs. Adapters that bind to an
@@ -109,6 +128,21 @@ export declare class NodeTypesStore {
109
128
  get current(): NodeMetadata[];
110
129
  set(list: NodeMetadata[]): void;
111
130
  }
131
+ /**
132
+ * The hooks actually supplied: an explicit `undefined` is dropped, so it can
133
+ * never shadow a default when the result is spread over one.
134
+ */
135
+ export declare function definedHostHooks(hooks: HostHooks): HostHooks;
136
+ /**
137
+ * The host hooks of one editor. A plain holder, not reactive: hooks are set
138
+ * once by the mount and read at call time.
139
+ */
140
+ export declare class HostHooksStore {
141
+ #private;
142
+ get current(): HostHooks;
143
+ /** Replace the hooks. Keys set to `undefined` are dropped. */
144
+ set(hooks: HostHooks): void;
145
+ }
112
146
  export interface CreateInstanceOptions {
113
147
  /** Explicit instance id; auto-generated (`fd-<n>`) when omitted. */
114
148
  id?: string;
@@ -46,6 +46,34 @@ export class NodeTypesStore {
46
46
  this.#list = list;
47
47
  }
48
48
  }
49
+ /**
50
+ * The hooks actually supplied: an explicit `undefined` is dropped, so it can
51
+ * never shadow a default when the result is spread over one.
52
+ */
53
+ export function definedHostHooks(hooks) {
54
+ const out = {};
55
+ if (hooks.onSave)
56
+ out.onSave = hooks.onSave;
57
+ if (hooks.onRun)
58
+ out.onRun = hooks.onRun;
59
+ if (hooks.onRunStatus)
60
+ out.onRunStatus = hooks.onRunStatus;
61
+ return out;
62
+ }
63
+ /**
64
+ * The host hooks of one editor. A plain holder, not reactive: hooks are set
65
+ * once by the mount and read at call time.
66
+ */
67
+ export class HostHooksStore {
68
+ #hooks = {};
69
+ get current() {
70
+ return this.#hooks;
71
+ }
72
+ /** Replace the hooks. Keys set to `undefined` are dropped. */
73
+ set(hooks) {
74
+ this.#hooks = definedHostHooks(hooks);
75
+ }
76
+ }
49
77
  // Feeds auto-generated ids only (`fd-1`, `fd-2`, …) — cosmetic monotonicity.
50
78
  // Incrementing across SSR requests is harmless; no state hangs off the value.
51
79
  let instanceCounter = 0;
@@ -105,6 +133,8 @@ export function createFlowDropInstance(options = {}) {
105
133
  // The default instance keeps the legacy bare localStorage key.
106
134
  pipelinePanel: new PipelinePanelStore(id),
107
135
  nodeTypes: new NodeTypesStore(),
136
+ host: new HostHooksStore(),
137
+ approvalGate: null,
108
138
  onDestroy(fn) {
109
139
  cleanups.push(fn);
110
140
  return () => {
@@ -33,3 +33,65 @@
33
33
  border-color var(--fd-transition-fast),
34
34
  box-shadow var(--fd-transition-fast);
35
35
  }
36
+
37
+ /*
38
+ * Dismissible toasts (errors, warnings): headline, optional reason list and a
39
+ * close button, rendered by DismissibleToast.svelte inside the library's
40
+ * `.message` flex row.
41
+ */
42
+ .flowdrop-toaster.flowdrop-toaster .flowdrop-toast-text {
43
+ flex: 1 1 auto;
44
+ min-width: 0;
45
+ overflow-wrap: anywhere;
46
+ text-align: start;
47
+ }
48
+
49
+ .flowdrop-toaster.flowdrop-toaster .flowdrop-toast-headline {
50
+ margin: 0;
51
+ }
52
+
53
+ .flowdrop-toaster.flowdrop-toaster .flowdrop-toast-details {
54
+ margin: var(--fd-space-xs, 4px) 0 0;
55
+ padding-inline-start: 1.1em;
56
+ color: var(--fd-muted-foreground, inherit);
57
+ font-size: var(--fd-text-xs, 0.85em);
58
+ }
59
+
60
+ .flowdrop-toaster.flowdrop-toaster .flowdrop-toast-details li + li {
61
+ margin-top: 2px;
62
+ }
63
+
64
+ .flowdrop-toaster.flowdrop-toaster .flowdrop-toast-close {
65
+ flex: 0 0 auto;
66
+ align-self: flex-start;
67
+ display: inline-flex;
68
+ align-items: center;
69
+ justify-content: center;
70
+ margin-inline-start: var(--fd-space-sm, 8px);
71
+ padding: var(--fd-space-xs, 4px);
72
+ border: 0;
73
+ border-radius: var(--fd-radius-sm, 4px);
74
+ background: transparent;
75
+ color: var(--fd-muted-foreground, inherit);
76
+ cursor: pointer;
77
+ line-height: 0;
78
+ }
79
+
80
+ .flowdrop-toaster.flowdrop-toaster .flowdrop-toast-close:hover {
81
+ background: var(--fd-muted, rgba(0, 0, 0, 0.06));
82
+ color: var(--fd-card-foreground, inherit);
83
+ }
84
+
85
+ .flowdrop-toaster.flowdrop-toaster .flowdrop-toast-close:focus-visible {
86
+ outline: 2px solid var(--fd-ring, var(--fd-primary));
87
+ outline-offset: 1px;
88
+ }
89
+
90
+ /* Warning variant: same persistence as an error, its own colour so it reads as one. */
91
+ .flowdrop-toaster.flowdrop-toaster .flowdrop-toast-bar--warning {
92
+ border-color: var(--fd-warning, #f59e0b) !important;
93
+ }
94
+
95
+ .flowdrop-toaster.flowdrop-toaster .flowdrop-toast-warning-icon {
96
+ flex: 0 0 auto;
97
+ }