@flowdrop/flowdrop 2.16.0 → 2.17.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 (84) hide show
  1. package/CHANGELOG.md +80 -0
  2. package/README.md +6 -1
  3. package/dist/components/App.svelte +212 -6
  4. package/dist/components/App.svelte.d.ts +2 -0
  5. package/dist/components/CanvasToolbar.svelte +40 -3
  6. package/dist/components/CanvasToolbar.svelte.d.ts +5 -1
  7. package/dist/components/ConnectPortPicker.svelte +8 -4
  8. package/dist/components/DoctorMenu.svelte +208 -126
  9. package/dist/components/ImpactConfirm.svelte +341 -0
  10. package/dist/components/ImpactConfirm.svelte.d.ts +12 -0
  11. package/dist/components/Navbar.svelte +42 -3
  12. package/dist/components/Navbar.svelte.d.ts +4 -0
  13. package/dist/components/NodeSidebar.svelte +36 -15
  14. package/dist/components/NodeSidebar.svelte.d.ts +2 -0
  15. package/dist/components/NodeSwapPicker.svelte +4 -14
  16. package/dist/components/RunBar.svelte +36 -1
  17. package/dist/components/RunBar.svelte.d.ts +5 -0
  18. package/dist/components/RunInputsDialog.svelte +198 -0
  19. package/dist/components/RunInputsDialog.svelte.d.ts +34 -0
  20. package/dist/components/WorkflowCompareDialog.svelte +177 -0
  21. package/dist/components/WorkflowCompareDialog.svelte.d.ts +10 -0
  22. package/dist/components/WorkflowEditor.svelte +88 -6
  23. package/dist/components/WorkflowEditor.svelte.d.ts +6 -0
  24. package/dist/components/WorkflowInterfaceEditor.svelte +14 -4
  25. package/dist/components/WorkflowInterfaceEntryCard.svelte +19 -3
  26. package/dist/components/WorkflowInterfaceEntryCard.svelte.d.ts +2 -0
  27. package/dist/components/nodes/NodeCard.svelte +2 -2
  28. package/dist/components/toast/DismissibleToast.svelte +25 -6
  29. package/dist/components/toast/DismissibleToast.svelte.d.ts +3 -0
  30. package/dist/config/endpoints.d.ts +7 -0
  31. package/dist/config/endpoints.js +2 -1
  32. package/dist/editor/connectCandidates.d.ts +3 -0
  33. package/dist/editor/connectCandidates.js +14 -5
  34. package/dist/editor/index.d.ts +1 -1
  35. package/dist/editor/index.js +1 -1
  36. package/dist/helpers/workflowEditorHelper.d.ts +15 -0
  37. package/dist/helpers/workflowEditorHelper.js +9 -0
  38. package/dist/index.d.ts +1 -0
  39. package/dist/messages/defaults.d.ts +100 -0
  40. package/dist/messages/defaults.js +91 -1
  41. package/dist/services/draftStorage.d.ts +24 -10
  42. package/dist/services/draftStorage.js +60 -35
  43. package/dist/services/globalSave.d.ts +28 -10
  44. package/dist/services/globalSave.js +135 -31
  45. package/dist/services/impactGate.d.ts +34 -0
  46. package/dist/services/impactGate.js +70 -0
  47. package/dist/services/impactService.d.ts +28 -0
  48. package/dist/services/impactService.js +71 -0
  49. package/dist/services/toastQueue.d.ts +9 -0
  50. package/dist/services/toastService.d.ts +4 -0
  51. package/dist/services/toastService.js +9 -3
  52. package/dist/services/workflowLaunchService.js +3 -1
  53. package/dist/settings/index.d.ts +2 -2
  54. package/dist/settings/index.js +1 -1
  55. package/dist/stores/doctorStore.svelte.d.ts +24 -1
  56. package/dist/stores/doctorStore.svelte.js +105 -2
  57. package/dist/stores/instanceContainer.svelte.d.ts +16 -0
  58. package/dist/stores/instanceContainer.svelte.js +22 -2
  59. package/dist/stores/saveConflictStore.svelte.d.ts +62 -0
  60. package/dist/stores/saveConflictStore.svelte.js +169 -0
  61. package/dist/stores/workflowStore.svelte.d.ts +7 -3
  62. package/dist/stores/workflowStore.svelte.js +14 -5
  63. package/dist/styles/toast.css +10 -1
  64. package/dist/svelte-app.d.ts +2 -0
  65. package/dist/svelte-app.js +74 -2
  66. package/dist/types/doctor.d.ts +3 -1
  67. package/dist/types/events.d.ts +20 -0
  68. package/dist/types/events.js +2 -0
  69. package/dist/types/impact.d.ts +25 -0
  70. package/dist/types/impact.js +7 -0
  71. package/dist/types/settings.d.ts +31 -0
  72. package/dist/types/settings.js +132 -0
  73. package/dist/utils/draftRestore.d.ts +27 -0
  74. package/dist/utils/draftRestore.js +36 -0
  75. package/dist/utils/interfaceTags.js +4 -1
  76. package/dist/utils/nodeSearch.d.ts +10 -0
  77. package/dist/utils/nodeSearch.js +37 -0
  78. package/dist/utils/runOffer.d.ts +21 -0
  79. package/dist/utils/runOffer.js +13 -0
  80. package/dist/utils/workflowCompare.d.ts +35 -0
  81. package/dist/utils/workflowCompare.js +84 -0
  82. package/dist/utils/workflowInterface.d.ts +26 -1
  83. package/dist/utils/workflowInterface.js +91 -11
  84. package/package.json +3 -2
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Compare two versions of a workflow: yours and the saved one.
3
+ *
4
+ * Pure. Steps (nodes) match by id, wires (edges) by their four endpoints.
5
+ */
6
+ import { nodeCanvasLabel } from './workflowInterface.js';
7
+ /** JSON with object keys sorted at every depth, so key order never counts as a change. */
8
+ function stable(value) {
9
+ return JSON.stringify(value ?? null, (_key, v) => {
10
+ if (v && typeof v === 'object' && !Array.isArray(v)) {
11
+ return Object.fromEntries(Object.keys(v)
12
+ .sort()
13
+ .map((k) => [k, v[k]]));
14
+ }
15
+ return v;
16
+ });
17
+ }
18
+ function nodeLabel(node) {
19
+ return nodeCanvasLabel(node);
20
+ }
21
+ function edgeKey(edge) {
22
+ return [edge.source, edge.sourceHandle ?? '', edge.target, edge.targetHandle ?? ''].join('\u0000');
23
+ }
24
+ function countOnlyIn(from, other) {
25
+ const keys = new Set(other.map(edgeKey));
26
+ return from.filter((e) => !keys.has(edgeKey(e))).length;
27
+ }
28
+ export function compareWorkflows(mine, theirs) {
29
+ const myNodes = new Map((mine.nodes ?? []).map((n) => [n.id, n]));
30
+ const theirNodes = new Map((theirs.nodes ?? []).map((n) => [n.id, n]));
31
+ const nodesOnlyMine = [...myNodes.values()]
32
+ .filter((n) => !theirNodes.has(n.id))
33
+ .map((n) => ({ id: n.id, label: nodeLabel(n) }));
34
+ const nodesOnlyTheirs = [...theirNodes.values()]
35
+ .filter((n) => !myNodes.has(n.id))
36
+ .map((n) => ({ id: n.id, label: nodeLabel(n) }));
37
+ const nodesChanged = [];
38
+ for (const [id, a] of myNodes) {
39
+ const b = theirNodes.get(id);
40
+ if (!b)
41
+ continue;
42
+ const what = [];
43
+ if (stable(a.data?.config) !== stable(b.data?.config))
44
+ what.push('settings');
45
+ if ((a.data?.label ?? '') !== (b.data?.label ?? ''))
46
+ what.push('label');
47
+ if (Math.abs((a.position?.x ?? 0) - (b.position?.x ?? 0)) > 1 ||
48
+ Math.abs((a.position?.y ?? 0) - (b.position?.y ?? 0)) > 1) {
49
+ what.push('position');
50
+ }
51
+ if (what.length > 0)
52
+ nodesChanged.push({ id, label: nodeLabel(a), what });
53
+ }
54
+ const edgesOnlyMine = countOnlyIn(mine.edges ?? [], theirs.edges ?? []);
55
+ const edgesOnlyTheirs = countOnlyIn(theirs.edges ?? [], mine.edges ?? []);
56
+ const interfaceChanged = stable(mine.interface) !== stable(theirs.interface);
57
+ const chatChanged = stable(mine.playground) !== stable(theirs.playground);
58
+ const result = {
59
+ nodesOnlyMine,
60
+ nodesOnlyTheirs,
61
+ nodesChanged,
62
+ edgesOnlyMine,
63
+ edgesOnlyTheirs,
64
+ interfaceChanged,
65
+ chatChanged,
66
+ same: false
67
+ };
68
+ if (mine.name !== theirs.name)
69
+ result.name = { mine: mine.name, theirs: theirs.name };
70
+ if ((mine.description ?? '') !== (theirs.description ?? '')) {
71
+ result.description = { mine: mine.description, theirs: theirs.description };
72
+ }
73
+ result.same =
74
+ !result.name &&
75
+ !result.description &&
76
+ nodesOnlyMine.length === 0 &&
77
+ nodesOnlyTheirs.length === 0 &&
78
+ nodesChanged.length === 0 &&
79
+ edgesOnlyMine === 0 &&
80
+ edgesOnlyTheirs === 0 &&
81
+ !interfaceChanged &&
82
+ !chatChanged;
83
+ return result;
84
+ }
@@ -211,6 +211,15 @@ export declare function nodeCanvasLabel(node: {
211
211
  config?: Record<string, unknown>;
212
212
  };
213
213
  }): string;
214
+ /**
215
+ * Tells same-named nodes apart in a picker: when two or more items with
216
+ * different node ids share a label, each of them gets " · <node id>" appended.
217
+ * Unique labels, and several ports of one node, stay as they are.
218
+ */
219
+ export declare function disambiguateLabels<T extends {
220
+ nodeId: string;
221
+ nodeLabel: string;
222
+ }>(items: T[]): T[];
214
223
  /** One inner port a `WorkflowInterfaceEntry` could bind to, plus its owning node. */
215
224
  export interface BindablePort {
216
225
  nodeId: string;
@@ -275,7 +284,23 @@ export declare function rankBindablePorts(workflow: Workflow, direction: 'input'
275
284
  * re-derives it. DN1's concern — a contract silently keyed on internal port
276
285
  * names — is about that ongoing coupling, which this does not introduce.
277
286
  */
278
- export declare function entryFromBindablePort(candidate: BindablePort, existingIds: Iterable<string>): WorkflowInterfaceEntry;
287
+ export declare function entryFromBindablePort(candidate: BindablePort, existingIds: Iterable<string>, workflow?: Workflow, direction?: 'input' | 'output'): WorkflowInterfaceEntry;
288
+ /** Port ids too generic to name a public entry: the node's title names it instead. */
289
+ export declare const GENERIC_PORT_IDS: readonly string[];
290
+ /**
291
+ * The id, title and type to seed a new entry with for a picked port.
292
+ *
293
+ * A generic port id (`data`, `value`, ...) says nothing about the contract, so
294
+ * the bound node's canvas label gives the id (snake_case) and the title. A
295
+ * `mixed` port takes the type of the port at the other end of an edge on its
296
+ * handle, when that one is typed. The id gets a numeric suffix only on a
297
+ * collision with `existingIds`.
298
+ */
299
+ export declare function suggestEntryFromBindablePort(workflow: Workflow | undefined, candidate: BindablePort, existingIds: Iterable<string>, direction?: 'input' | 'output'): {
300
+ id: string;
301
+ name: string;
302
+ dataType: string;
303
+ };
279
304
  /** The turn values an entry of this direction may carry, in selector order. */
280
305
  export declare function turnsFor(direction: 'input' | 'output'): readonly WorkflowInterfaceTurn[];
281
306
  /** Whether a value is in this library's turn vocabulary (either direction). */
@@ -17,7 +17,7 @@ import { dynamicPortToNodePort, WORKFLOW_INTERFACE_INPUT_TURNS, WORKFLOW_INTERFA
17
17
  import { isPortExposed } from './portUtils.js';
18
18
  import { LOOPBACK_PORT_NAME } from './connections.js';
19
19
  import { PORTS_CONFIG_KEY } from './nodeFormSchema.js';
20
- import { buildHandleId } from './handleIds.js';
20
+ import { buildHandleId, extractPortId } from './handleIds.js';
21
21
  import { isPlaygroundChatHalfSet, normalizePlaygroundChat, playgroundBoundInputs, resolvePlaygroundChat } from './playgroundChat.js';
22
22
  /** Precedence used to pick the single reported status when several apply. */
23
23
  const STATUS_PRECEDENCE = [
@@ -412,6 +412,22 @@ export function nodeCanvasLabel(node) {
412
412
  const title = node.data?.config?.instanceTitle;
413
413
  return (typeof title === 'string' && title) || node.data?.label || node.id;
414
414
  }
415
+ /**
416
+ * Tells same-named nodes apart in a picker: when two or more items with
417
+ * different node ids share a label, each of them gets " · <node id>" appended.
418
+ * Unique labels, and several ports of one node, stay as they are.
419
+ */
420
+ export function disambiguateLabels(items) {
421
+ const nodesByLabel = new Map();
422
+ for (const item of items) {
423
+ const ids = nodesByLabel.get(item.nodeLabel) ?? new Set();
424
+ ids.add(item.nodeId);
425
+ nodesByLabel.set(item.nodeLabel, ids);
426
+ }
427
+ return items.map((item) => (nodesByLabel.get(item.nodeLabel)?.size ?? 0) > 1
428
+ ? { ...item, nodeLabel: `${item.nodeLabel} · ${item.nodeId}` }
429
+ : item);
430
+ }
415
431
  /**
416
432
  * Every canvas-exposed port of a workflow, for one direction — the candidate
417
433
  * set a binding picker offers (design decision 3: external ⊂ internal, so an
@@ -449,7 +465,7 @@ export function listBindablePorts(workflow, direction) {
449
465
  }
450
466
  }
451
467
  }
452
- return result;
468
+ return disambiguateLabels(result);
453
469
  }
454
470
  /**
455
471
  * A stable key for a bindable port — `nodeId::portId` — the value a picker
@@ -502,18 +518,82 @@ export function rankBindablePorts(workflow, direction) {
502
518
  * re-derives it. DN1's concern — a contract silently keyed on internal port
503
519
  * names — is about that ongoing coupling, which this does not introduce.
504
520
  */
505
- export function entryFromBindablePort(candidate, existingIds) {
521
+ export function entryFromBindablePort(candidate, existingIds, workflow, direction) {
522
+ const suggestion = suggestEntryFromBindablePort(workflow, candidate, existingIds, direction);
523
+ return {
524
+ ...pullEntryFieldsFromPort(candidate.port),
525
+ ...suggestion,
526
+ bindings: [{ nodeId: candidate.nodeId, portId: candidate.port.id }]
527
+ };
528
+ }
529
+ /** Port ids too generic to name a public entry: the node's title names it instead. */
530
+ export const GENERIC_PORT_IDS = [
531
+ 'data',
532
+ 'value',
533
+ 'input',
534
+ 'output',
535
+ 'result',
536
+ 'text'
537
+ ];
538
+ /**
539
+ * The id, title and type to seed a new entry with for a picked port.
540
+ *
541
+ * A generic port id (`data`, `value`, ...) says nothing about the contract, so
542
+ * the bound node's canvas label gives the id (snake_case) and the title. A
543
+ * `mixed` port takes the type of the port at the other end of an edge on its
544
+ * handle, when that one is typed. The id gets a numeric suffix only on a
545
+ * collision with `existingIds`.
546
+ */
547
+ export function suggestEntryFromBindablePort(workflow, candidate, existingIds, direction) {
548
+ const { port } = candidate;
549
+ const generic = GENERIC_PORT_IDS.includes(port.id);
550
+ // The picker label may carry a " · node id" suffix; an entry is named after the node itself.
551
+ const ownNode = workflow?.nodes.find((n) => n.id === candidate.nodeId);
552
+ const label = ownNode ? nodeCanvasLabel(ownNode) : candidate.nodeLabel;
553
+ // Accents fold to their base letter (Übersetzung -> ubersetzung), ß to ss.
554
+ const fromLabel = label
555
+ .normalize('NFD')
556
+ .replace(/[\u0300-\u036f]/g, '')
557
+ .replace(/ß/g, 'ss')
558
+ .toLowerCase()
559
+ .replace(/[^a-z0-9]+/g, '_')
560
+ .replace(/^_+|_+$/g, '')
561
+ .slice(0, 40)
562
+ .replace(/_+$/g, '');
563
+ const base = generic && fromLabel ? fromLabel : port.id;
506
564
  const taken = new Set(existingIds);
507
- let id = candidate.port.id;
565
+ let id = base;
508
566
  for (let n = 2; taken.has(id); n += 1) {
509
- id = `${candidate.port.id}_${n}`;
567
+ id = `${base}_${n}`;
510
568
  }
511
- return {
512
- id,
513
- dataType: candidate.port.dataType,
514
- bindings: [{ nodeId: candidate.nodeId, portId: candidate.port.id }],
515
- ...pullEntryFieldsFromPort(candidate.port)
516
- };
569
+ let dataType = port.dataType;
570
+ if (dataType === 'mixed' && workflow && direction) {
571
+ const handleId = buildHandleId(candidate.nodeId, direction, port.id);
572
+ const edge = workflow.edges.find((e) => direction === 'input' ? e.targetHandle === handleId : e.sourceHandle === handleId);
573
+ const otherNode = edge
574
+ ? workflow.nodes.find((n) => n.id === (direction === 'input' ? edge.source : edge.target))
575
+ : undefined;
576
+ const otherPortId = edge
577
+ ? extractPortId(direction === 'input' ? edge.sourceHandle : edge.targetHandle)
578
+ : null;
579
+ const otherMetadata = otherNode?.data?.metadata;
580
+ if (otherNode && otherMetadata && otherPortId) {
581
+ const otherDirection = direction === 'input' ? 'output' : 'input';
582
+ const dynamicRaw = otherDirection === 'input'
583
+ ? otherNode.data?.config?.dynamicInputs
584
+ : otherNode.data?.config?.dynamicOutputs;
585
+ const otherPorts = [
586
+ ...(otherDirection === 'input'
587
+ ? (otherMetadata.inputs ?? [])
588
+ : (otherMetadata.outputs ?? [])),
589
+ ...(dynamicRaw ?? []).map((dynamic) => dynamicPortToNodePort(dynamic, otherDirection))
590
+ ];
591
+ const otherType = otherPorts.find((other) => other.id === otherPortId)?.dataType;
592
+ if (otherType && otherType !== 'mixed')
593
+ dataType = otherType;
594
+ }
595
+ }
596
+ return { id, name: generic ? label : port.name, dataType };
517
597
  }
518
598
  // ---------------------------------------------------------------------------
519
599
  // Chat turn ports — deprecated since 2.11.0, removed in 3.0 with interface
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "A drop-in visual workflow editor for any web application. You own the backend. You own the data. You own the orchestration.",
4
4
  "license": "MIT",
5
5
  "private": false,
6
- "version": "2.16.0",
6
+ "version": "2.17.0",
7
7
  "author": "Shibin Das (D34dMan)",
8
8
  "bugs": {
9
9
  "url": "https://github.com/flowdrop-io/flowdrop/issues"
@@ -277,7 +277,8 @@
277
277
  "dag",
278
278
  "agent",
279
279
  "ai-workflow",
280
- "embeddable"
280
+ "embeddable",
281
+ "workflow-specification"
281
282
  ],
282
283
  "dependencies": {
283
284
  "diff": "^8.0.3",