@iblai/iblai-js 2.70.0 → 2.71.1

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 (137) hide show
  1. package/dist/web-containers/source/chat/index.js +7 -2
  2. package/dist/web-containers/source/chat/index.js.map +1 -1
  3. package/dist/web-containers/source/chat-input-form/use-overflow-fit.js +7 -5
  4. package/dist/web-containers/source/chat-input-form/use-overflow-fit.js.map +1 -1
  5. package/dist/web-containers/source/chat-input-form.js +5 -3
  6. package/dist/web-containers/source/chat-input-form.js.map +1 -1
  7. package/dist/web-containers/source/classifier-panel.js +401 -0
  8. package/dist/web-containers/source/classifier-panel.js.map +1 -0
  9. package/dist/web-containers/source/components/chat/index.js +7 -2
  10. package/dist/web-containers/source/components/chat/index.js.map +1 -1
  11. package/dist/web-containers/source/components/chat-input-form/use-overflow-fit.js +7 -5
  12. package/dist/web-containers/source/components/chat-input-form/use-overflow-fit.js.map +1 -1
  13. package/dist/web-containers/source/components/chat-input-form.js +5 -3
  14. package/dist/web-containers/source/components/chat-input-form.js.map +1 -1
  15. package/dist/web-containers/source/components/mentors/mentor-selection-grid.js +5 -2
  16. package/dist/web-containers/source/components/mentors/mentor-selection-grid.js.map +1 -1
  17. package/dist/web-containers/source/components/modals/user-profile-modal.js +3 -0
  18. package/dist/web-containers/source/components/modals/user-profile-modal.js.map +1 -1
  19. package/dist/web-containers/source/components/workflows/classifier-panel.js +401 -0
  20. package/dist/web-containers/source/components/workflows/classifier-panel.js.map +1 -0
  21. package/dist/web-containers/source/components/workflows/delete-workflow-modal.js +4 -3
  22. package/dist/web-containers/source/components/workflows/delete-workflow-modal.js.map +1 -1
  23. package/dist/web-containers/source/components/workflows/insert-reference.js +81 -0
  24. package/dist/web-containers/source/components/workflows/insert-reference.js.map +1 -0
  25. package/dist/web-containers/source/components/workflows/node-config-panel.js +135 -71
  26. package/dist/web-containers/source/components/workflows/node-config-panel.js.map +1 -1
  27. package/dist/web-containers/source/components/workflows/panel-fields.js +125 -0
  28. package/dist/web-containers/source/components/workflows/panel-fields.js.map +1 -0
  29. package/dist/web-containers/source/components/workflows/shortcuts.js +77 -0
  30. package/dist/web-containers/source/components/workflows/shortcuts.js.map +1 -0
  31. package/dist/web-containers/source/components/workflows/tool-dialogs.js +11 -11
  32. package/dist/web-containers/source/components/workflows/tool-dialogs.js.map +1 -1
  33. package/dist/web-containers/source/components/workflows/workflow-canvas.js +874 -278
  34. package/dist/web-containers/source/components/workflows/workflow-canvas.js.map +1 -1
  35. package/dist/web-containers/source/components/workflows/workflow-definition.js +220 -8
  36. package/dist/web-containers/source/components/workflows/workflow-definition.js.map +1 -1
  37. package/dist/web-containers/source/components/workflows/workflow-editor.js +495 -84
  38. package/dist/web-containers/source/components/workflows/workflow-editor.js.map +1 -1
  39. package/dist/web-containers/source/components/workflows/workflow-preview-chat.js +4 -0
  40. package/dist/web-containers/source/components/workflows/workflow-preview-chat.js.map +1 -1
  41. package/dist/web-containers/source/components/workflows/workflow-sidebar.js +6 -11
  42. package/dist/web-containers/source/components/workflows/workflow-sidebar.js.map +1 -1
  43. package/dist/web-containers/source/components/workflows/workflow-switch.js +13 -0
  44. package/dist/web-containers/source/components/workflows/workflow-switch.js.map +1 -0
  45. package/dist/web-containers/source/components/workflows/workflow-textarea.js +168 -0
  46. package/dist/web-containers/source/components/workflows/workflow-textarea.js.map +1 -0
  47. package/dist/web-containers/source/delete-workflow-modal.js +4 -3
  48. package/dist/web-containers/source/delete-workflow-modal.js.map +1 -1
  49. package/dist/web-containers/source/en.json.js +138 -9
  50. package/dist/web-containers/source/en.json.js.map +1 -1
  51. package/dist/web-containers/source/es.json.js +135 -6
  52. package/dist/web-containers/source/es.json.js.map +1 -1
  53. package/dist/web-containers/source/fr.json.js +135 -6
  54. package/dist/web-containers/source/fr.json.js.map +1 -1
  55. package/dist/web-containers/source/i18n/messages/en.json.js +138 -9
  56. package/dist/web-containers/source/i18n/messages/en.json.js.map +1 -1
  57. package/dist/web-containers/source/i18n/messages/es.json.js +135 -6
  58. package/dist/web-containers/source/i18n/messages/es.json.js.map +1 -1
  59. package/dist/web-containers/source/i18n/messages/fr.json.js +135 -6
  60. package/dist/web-containers/source/i18n/messages/fr.json.js.map +1 -1
  61. package/dist/web-containers/source/i18n/messages/zh.json.js +135 -6
  62. package/dist/web-containers/source/i18n/messages/zh.json.js.map +1 -1
  63. package/dist/web-containers/source/insert-reference.js +81 -0
  64. package/dist/web-containers/source/insert-reference.js.map +1 -0
  65. package/dist/web-containers/source/mentor-selection-grid.js +5 -2
  66. package/dist/web-containers/source/mentor-selection-grid.js.map +1 -1
  67. package/dist/web-containers/source/mentors/mentor-selection-grid.js +5 -2
  68. package/dist/web-containers/source/mentors/mentor-selection-grid.js.map +1 -1
  69. package/dist/web-containers/source/messages/en.json.js +138 -9
  70. package/dist/web-containers/source/messages/en.json.js.map +1 -1
  71. package/dist/web-containers/source/messages/es.json.js +135 -6
  72. package/dist/web-containers/source/messages/es.json.js.map +1 -1
  73. package/dist/web-containers/source/messages/fr.json.js +135 -6
  74. package/dist/web-containers/source/messages/fr.json.js.map +1 -1
  75. package/dist/web-containers/source/messages/zh.json.js +135 -6
  76. package/dist/web-containers/source/messages/zh.json.js.map +1 -1
  77. package/dist/web-containers/source/modals/user-profile-modal.js +3 -0
  78. package/dist/web-containers/source/modals/user-profile-modal.js.map +1 -1
  79. package/dist/web-containers/source/node-config-panel.js +135 -71
  80. package/dist/web-containers/source/node-config-panel.js.map +1 -1
  81. package/dist/web-containers/source/panel-fields.js +125 -0
  82. package/dist/web-containers/source/panel-fields.js.map +1 -0
  83. package/dist/web-containers/source/shortcuts.js +77 -0
  84. package/dist/web-containers/source/shortcuts.js.map +1 -0
  85. package/dist/web-containers/source/tool-dialogs.js +11 -11
  86. package/dist/web-containers/source/tool-dialogs.js.map +1 -1
  87. package/dist/web-containers/source/tsconfig.build.tsbuildinfo +1 -1
  88. package/dist/web-containers/source/use-overflow-fit.js +7 -5
  89. package/dist/web-containers/source/use-overflow-fit.js.map +1 -1
  90. package/dist/web-containers/source/user-profile-modal.js +3 -0
  91. package/dist/web-containers/source/user-profile-modal.js.map +1 -1
  92. package/dist/web-containers/source/web-containers/tsconfig.build.tsbuildinfo +1 -1
  93. package/dist/web-containers/source/workflow-canvas.js +874 -278
  94. package/dist/web-containers/source/workflow-canvas.js.map +1 -1
  95. package/dist/web-containers/source/workflow-definition.js +220 -8
  96. package/dist/web-containers/source/workflow-definition.js.map +1 -1
  97. package/dist/web-containers/source/workflow-editor.js +495 -84
  98. package/dist/web-containers/source/workflow-editor.js.map +1 -1
  99. package/dist/web-containers/source/workflow-preview-chat.js +4 -0
  100. package/dist/web-containers/source/workflow-preview-chat.js.map +1 -1
  101. package/dist/web-containers/source/workflow-sidebar.js +6 -11
  102. package/dist/web-containers/source/workflow-sidebar.js.map +1 -1
  103. package/dist/web-containers/source/workflow-switch.js +13 -0
  104. package/dist/web-containers/source/workflow-switch.js.map +1 -0
  105. package/dist/web-containers/source/workflow-textarea.js +168 -0
  106. package/dist/web-containers/source/workflow-textarea.js.map +1 -0
  107. package/dist/web-containers/source/workflows/classifier-panel.js +401 -0
  108. package/dist/web-containers/source/workflows/classifier-panel.js.map +1 -0
  109. package/dist/web-containers/source/workflows/delete-workflow-modal.js +4 -3
  110. package/dist/web-containers/source/workflows/delete-workflow-modal.js.map +1 -1
  111. package/dist/web-containers/source/workflows/insert-reference.js +81 -0
  112. package/dist/web-containers/source/workflows/insert-reference.js.map +1 -0
  113. package/dist/web-containers/source/workflows/node-config-panel.js +135 -71
  114. package/dist/web-containers/source/workflows/node-config-panel.js.map +1 -1
  115. package/dist/web-containers/source/workflows/panel-fields.js +125 -0
  116. package/dist/web-containers/source/workflows/panel-fields.js.map +1 -0
  117. package/dist/web-containers/source/workflows/shortcuts.js +77 -0
  118. package/dist/web-containers/source/workflows/shortcuts.js.map +1 -0
  119. package/dist/web-containers/source/workflows/tool-dialogs.js +11 -11
  120. package/dist/web-containers/source/workflows/tool-dialogs.js.map +1 -1
  121. package/dist/web-containers/source/workflows/workflow-canvas.js +874 -278
  122. package/dist/web-containers/source/workflows/workflow-canvas.js.map +1 -1
  123. package/dist/web-containers/source/workflows/workflow-definition.js +220 -8
  124. package/dist/web-containers/source/workflows/workflow-definition.js.map +1 -1
  125. package/dist/web-containers/source/workflows/workflow-editor.js +495 -84
  126. package/dist/web-containers/source/workflows/workflow-editor.js.map +1 -1
  127. package/dist/web-containers/source/workflows/workflow-preview-chat.js +4 -0
  128. package/dist/web-containers/source/workflows/workflow-preview-chat.js.map +1 -1
  129. package/dist/web-containers/source/workflows/workflow-sidebar.js +6 -11
  130. package/dist/web-containers/source/workflows/workflow-sidebar.js.map +1 -1
  131. package/dist/web-containers/source/workflows/workflow-switch.js +13 -0
  132. package/dist/web-containers/source/workflows/workflow-switch.js.map +1 -0
  133. package/dist/web-containers/source/workflows/workflow-textarea.js +168 -0
  134. package/dist/web-containers/source/workflows/workflow-textarea.js.map +1 -0
  135. package/dist/web-containers/source/zh.json.js +135 -6
  136. package/dist/web-containers/source/zh.json.js.map +1 -1
  137. package/package.json +5 -5
@@ -1,4 +1,4 @@
1
- import { jsxs, jsx } from 'react/jsx-runtime';
1
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
2
2
  import { useState, useRef, useEffect, useCallback, useMemo } from 'react';
3
3
  import { useLazyGetMentorSettingsQuery } from '@iblai/data-layer';
4
4
  import { useT } from '../../i18n/context.js';
@@ -6,18 +6,24 @@ import '../../packages/i18n/dist/index.esm.js';
6
6
  import { MentorSelectionGrid } from '../mentors/mentor-selection-grid.js';
7
7
  import { Button } from '../ui/button.js';
8
8
  import { Dialog, DialogContent, DialogHeader, DialogTitle } from '../ui/dialog.js';
9
- import { Textarea } from '../ui/textarea.js';
9
+ import { WorkflowTextarea } from './workflow-textarea.js';
10
+ import { useCopyToClipboard } from '../chat/markdown/use-copy-to-clipboard.js';
10
11
  import { ActionTooltip } from './action-tooltip.js';
11
12
  import { NodeConfigPanel } from './node-config-panel.js';
12
- import { canReceiveConnection, edgeIdFor, collectWorkflowVariables, collectVariableUsages, WHILE_LOOP_HANDLE, WHILE_DONE_HANDLE, getConditionCount, reindexConditionEdges, getConditions } from './workflow-definition.js';
13
+ import { ariaShortcut, withShortcut, letterOf, historyKeyOf } from './shortcuts.js';
14
+ import { isClassifierType, canReceiveConnection, edgeIdFor, collectWorkflowVariables, collectVariableUsages, stepHasResult, stepPlaceholder, WHILE_LOOP_HANDLE, WHILE_DONE_HANDLE, getConditionCount, classifierBranches, placeholderSources, reindexConditionEdges, getConditions, reconcileClassifierEdges, newClassifierData } from './workflow-definition.js';
13
15
  import X from '../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/x.js';
16
+ import Check from '../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/check.js';
17
+ import Copy from '../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/copy.js';
14
18
  import Trash2 from '../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/trash-2.js';
15
19
  import Play from '../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/play.js';
16
20
  import RefreshCw from '../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/refresh-cw.js';
17
21
  import GitBranch from '../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/git-branch.js';
22
+ import Split from '../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/split.js';
18
23
  import ThumbsUp from '../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/thumbs-up.js';
19
24
  import Bot from '../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/bot.js';
20
25
  import Pencil from '../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/pencil.js';
26
+ import Settings from '../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/settings.js';
21
27
  import Hand from '../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/hand.js';
22
28
  import MousePointer from '../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/mouse-pointer.js';
23
29
  import Undo from '../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/undo.js';
@@ -25,50 +31,132 @@ import Redo from '../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/nod
25
31
  import ZoomOut from '../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/zoom-out.js';
26
32
  import ZoomIn from '../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/zoom-in.js';
27
33
 
28
- const DEFAULT_MENTOR_LABELS = new Set([
29
- 'my agent',
30
- 'agent',
31
- 'agent node',
32
- 'my mentor',
33
- 'mentor',
34
- 'mentor node',
35
- ]);
36
- const isDefaultMentorLabel = (label) => {
37
- if (!label)
38
- return true;
39
- return DEFAULT_MENTOR_LABELS.has(label.trim().toLowerCase());
40
- };
41
34
  // API may use 'conditional' as the node type key for if-else nodes
42
35
  const isConditionalType = (type) => type === 'if-else' || type === 'conditional';
43
36
  // Cards with one labelled row per outgoing branch.
44
- const isBranchingType = (type) => isConditionalType(type) || type === 'while' || type === 'user-approval';
37
+ const isBranchingType = (type) => isConditionalType(type) || isClassifierType(type) || type === 'while' || type === 'user-approval';
38
+ const branchRowCount = (type, data) => {
39
+ if (isConditionalType(type))
40
+ return getConditionCount(data) + 1;
41
+ if (isClassifierType(type))
42
+ return classifierBranches(data).length;
43
+ return 2;
44
+ };
45
45
  // Branch rows sit under a 68px header, 44px tall with an 8px gap.
46
46
  const branchRowCenter = (index) => 90 + index * 52;
47
47
  const branchCardHeight = (rows) => 76 + rows * 52;
48
- // Rendered card sizes, for placing new steps and for box selection.
48
+ // Rendered card sizes, for placing new steps, drawing connections and box selection.
49
49
  const nodeSize = (node) => {
50
- if (isConditionalType(node.type)) {
51
- const conditions = node.data ? getConditionCount(node.data) : 1;
52
- return { width: 280, height: branchCardHeight(conditions + 1) };
53
- }
54
50
  if (isBranchingType(node.type)) {
55
- return { width: 280, height: branchCardHeight(2) };
51
+ return { width: 280, height: branchCardHeight(branchRowCount(node.type, node.data)) };
56
52
  }
57
53
  if (node.type === 'note') {
58
54
  return { width: node.width || 200, height: node.height || 120 };
59
55
  }
60
56
  return { width: 140, height: 50 };
61
57
  };
62
- const SIDE_HANDLES = new Set(['left', 'right', 'top', 'bottom']);
63
- // If/Else rows, While Loop/Done and Approve/Reject, as opposed to a plain
64
- // step's side points.
65
- const isBranchHandle = (handle) => !SIDE_HANDLES.has(handle);
66
- // The only steps the backend runs that write to step_results.
67
- const STEPS_WITH_RESULTS = new Set(['mentor', 'transform', 'set-state', 'while']);
68
58
  const NODE_PANEL_SELECTOR = '[data-testid="workflow-node-panel"]';
59
+ const TEXT_ENTRY_SELECTOR = 'input, textarea, [contenteditable]:not([contenteditable="false"])';
69
60
  // The floating zoom/undo toolbar covers the bottom of the canvas.
70
61
  const TOOLBAR_CLEARANCE = 80;
62
+ const MIN_ZOOM = 0.5;
63
+ const MAX_ZOOM = 2;
64
+ const ZOOM_STEP = 0.1;
65
+ const clampZoom = (value) => Math.min(MAX_ZOOM, Math.max(MIN_ZOOM, value));
66
+ // A trackpad pinch arrives as many small ctrl+wheel deltas; each scales the
67
+ // zoom by e^(-delta / 100).
68
+ const WHEEL_ZOOM_RATE = 0.01;
69
+ // A mouse wheel notch is ~100 px at once; capped, a notch zooms ~10% like a
70
+ // toolbar step instead of jumping 2.7x.
71
+ const MAX_WHEEL_ZOOM_DELTA = 10;
72
+ // Firefox reports a mouse wheel in lines, and some devices in pages.
73
+ const WHEEL_LINE_HEIGHT = 16;
74
+ // Each paste of the same copy lands this much further down and right, so
75
+ // copies never stack exactly on top of each other.
76
+ const PASTE_OFFSET = 40;
77
+ // The settings panel a focusRequest opens covers the right of the canvas on a
78
+ // desktop: its 320px plus the 16px gap (PANEL_SHELL in node-config-panel).
79
+ const PANEL_COVER = 336;
80
+ // How far a press may move and still count as a click. A fingertip wobbles
81
+ // more than a mouse, so a tap on a step must not read as a drag.
82
+ const MOUSE_SLOP = 3;
83
+ const TOUCH_SLOP = 8;
84
+ // Phones open with every step fitted into view; the margin keeps the outer
85
+ // connection dots reachable.
86
+ const PHONE_QUERY = '(max-width: 767px)';
87
+ const FIT_MARGIN = 24;
88
+ // The phone's Add Step button floats over the top of the canvas.
89
+ const PHONE_TOP_INSET = 56;
90
+ // Gated on the window, not the canvas: a narrow canvas in a desktop window
91
+ // keeps its usual view.
92
+ const isPhone = () => typeof window.matchMedia === 'function' && window.matchMedia(PHONE_QUERY).matches;
93
+ // A window open over the canvas (Edit Agent, Change Agent, the Add Step
94
+ // sheet) owns the keyboard.
95
+ const OPEN_DIALOG_SELECTOR = '[role="dialog"]:not([data-state="closed"]), [role="alertdialog"]:not([data-state="closed"])';
96
+ // The step panel and an open menu or list keep their own keys: an undo there
97
+ // would leave the panel showing the values it was opened with.
98
+ const OWN_KEYS_SELECTOR = `${NODE_PANEL_SELECTOR}, [role="listbox"], [role="menu"]`;
99
+ const TYPING_SELECTOR = `${TEXT_ENTRY_SELECTOR}, select`;
100
+ const ZOOM_KEYS = {
101
+ '=': 'zoomIn',
102
+ '+': 'zoomIn',
103
+ '-': 'zoomOut',
104
+ '0': 'resetZoom',
105
+ };
106
+ const centerOf = (a, b) => ({ x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 });
107
+ // A finger stays with the element it pressed, so no other step ever sees it
108
+ // enter; the drop target is whatever step is under it on release.
109
+ const nodeIdAt = (x, y) => { var _a, _b, _c, _d; return (_d = (_c = (_b = (_a = document.elementFromPoint) === null || _a === void 0 ? void 0 : _a.call(document, x, y)) === null || _b === void 0 ? void 0 : _b.closest('[data-node-id]')) === null || _c === void 0 ? void 0 : _c.dataset.nodeId) !== null && _d !== void 0 ? _d : null; };
110
+ const isScrollable = (element) => {
111
+ const { overflowX, overflowY } = getComputedStyle(element);
112
+ return ((/auto|scroll/.test(overflowY) && element.scrollHeight > element.clientHeight) ||
113
+ (/auto|scroll/.test(overflowX) && element.scrollWidth > element.clientWidth));
114
+ };
115
+ const scrollsInsideCard = (target) => {
116
+ const card = target.closest('[data-node-id]');
117
+ for (let element = target; card && element; element = element.parentElement) {
118
+ if (element instanceof HTMLElement && isScrollable(element))
119
+ return true;
120
+ if (element === card)
121
+ return false;
122
+ }
123
+ return false;
124
+ };
125
+ const freshStepId = (type, taken) => {
126
+ let stamp = Date.now();
127
+ while (taken.has(`${type}-${stamp}`))
128
+ stamp += 1;
129
+ return `${type}-${stamp}`;
130
+ };
131
+ const unusedName = (name, taken) => {
132
+ if (!taken.has(name))
133
+ return name;
134
+ let suffix = 2;
135
+ while (taken.has(`${name}_${suffix}`))
136
+ suffix += 1;
137
+ return `${name}_${suffix}`;
138
+ };
139
+ const CARD_ACTION = 'bg-card border-border text-muted-foreground flex h-6 w-6 cursor-pointer items-center justify-center rounded-full border shadow-sm transition-opacity group-hover:opacity-100 focus-visible:opacity-100';
140
+ // Without hover, an unselected card's actions stay invisible on touch, so a
141
+ // tap there must select the step rather than hit a button nobody can see.
142
+ const cardActionVisibility = (selected) => selected ? 'opacity-100' : 'opacity-0 pointer-coarse:pointer-events-none';
143
+ // Touch screens never hover, so coarse pointers always show the dots. A
144
+ // ::before gives a fingertip-sized target without resizing the dot, whose
145
+ // place the connection lines are drawn to. It grows away from the card only:
146
+ // a finger on the card's name must still select or drag the step.
147
+ const TOUCH_TARGET = "pointer-coarse:before:absolute pointer-coarse:before:content-['']";
148
+ const INPUT_DOT = 'border-background absolute h-3 w-3 rounded-full border-2 opacity-0 transition-opacity group-hover:opacity-100 pointer-coarse:opacity-100';
149
+ const OUTPUT_DOT = `${INPUT_DOT} cursor-crosshair ${TOUCH_TARGET}`;
150
+ const RIGHT_DOT = `${OUTPUT_DOT} top-1/2 -right-2 -translate-y-1/2 pointer-coarse:before:-inset-y-3 pointer-coarse:before:left-1 pointer-coarse:before:-right-7`;
151
+ const TOP_DOT = `${OUTPUT_DOT} -top-2 left-1/2 -translate-x-1/2 pointer-coarse:before:-inset-x-3 pointer-coarse:before:-top-7 pointer-coarse:before:bottom-1`;
152
+ const BOTTOM_DOT = `${OUTPUT_DOT} -bottom-2 left-1/2 -translate-x-1/2 pointer-coarse:before:-inset-x-3 pointer-coarse:before:top-1 pointer-coarse:before:-bottom-7`;
153
+ // A branch row's dot sits in the card's right margin, beside the row's name.
154
+ const ROW_DOT = `${OUTPUT_DOT} top-1/2 -right-[18px] -translate-y-1/2 pointer-coarse:before:-inset-y-3 pointer-coarse:before:left-0 pointer-coarse:before:-right-6`;
155
+ const RESIZE_TARGET = `${TOUCH_TARGET} pointer-coarse:before:top-0 pointer-coarse:before:left-0 pointer-coarse:before:-right-5 pointer-coarse:before:-bottom-5`;
156
+ // Grown only up and down: the Agent card's two icons sit side by side.
157
+ const ICON_TOUCH_TARGET = "relative pointer-coarse:before:absolute pointer-coarse:before:inset-x-0 pointer-coarse:before:-inset-y-2 pointer-coarse:before:content-['']";
71
158
  const isDeletableNode = (node) => node.type !== 'start' && node.deletable !== false;
159
+ const agentOf = (data) => data.mentor_id || data.entry_mentor_id;
72
160
  // Helper to strip UI-only properties from nodes for comparison/saving
73
161
  function stripUiProperties(nodes) {
74
162
  return nodes.map(({ selected, dragging, hidden, ...rest }) => rest);
@@ -107,7 +195,7 @@ const DEFAULT_EDGES = [
107
195
  targetHandle: 'left',
108
196
  },
109
197
  ];
110
- function WorkflowCanvas({ onDraggedItem: _onDraggedItem, onClickedItem, previewMode = false, initialNodes, initialEdges, initialViewport, onStateChange, org, defaultMentorId, username, onOpenAgentSettings, agentSettings, }) {
198
+ function WorkflowCanvas({ onDraggedItem: _onDraggedItem, onClickedItem, previewMode = false, initialNodes, initialEdges, initialViewport, onStateChange, org, defaultMentorId, username, onOpenAgentSettings, agentSettings, classifierModels, onTryClassifier, focusRequest, }) {
111
199
  var _a;
112
200
  const t = useT();
113
201
  // Use initialNodes if provided (from API), otherwise use defaults for new workflows
@@ -119,8 +207,8 @@ function WorkflowCanvas({ onDraggedItem: _onDraggedItem, onClickedItem, previewM
119
207
  { nodes: [...nodes], edges: [...edges] },
120
208
  ]);
121
209
  const [historyIndex, setHistoryIndex] = useState(0);
122
- // Saves can run after an await (mentor prefill); a closed-over index would
123
- // cut off entries added in the meantime.
210
+ // Saves can run after an await (picking an agent); a closed-over index
211
+ // would cut off entries added in the meantime.
124
212
  const historyIndexRef = useRef(0);
125
213
  const [draggedNode, setDraggedNode] = useState(null);
126
214
  const [dragOffset, setDragOffset] = useState({ x: 0, y: 0 });
@@ -128,6 +216,8 @@ function WorkflowCanvas({ onDraggedItem: _onDraggedItem, onClickedItem, previewM
128
216
  const [panOffset, setPanOffset] = useState(initialViewport ? { x: initialViewport.x, y: initialViewport.y } : { x: 0, y: 0 });
129
217
  const [panStart, setPanStart] = useState({ x: 0, y: 0 });
130
218
  const [hoveredNode, setHoveredNode] = useState(null);
219
+ const [copiedNodeId, setCopiedNodeId] = useState(null);
220
+ const { copy: copyToClipboard, status: copyStatus } = useCopyToClipboard(1500);
131
221
  const [connectingFrom, setConnectingFrom] = useState(null);
132
222
  const [tempConnectionPos, setTempConnectionPos] = useState(null);
133
223
  const [editingNote, setEditingNote] = useState(null);
@@ -144,8 +234,12 @@ function WorkflowCanvas({ onDraggedItem: _onDraggedItem, onClickedItem, previewM
144
234
  // False once the user clicks into a settings panel or a dialog, so a
145
235
  // Delete meant for a dropdown or button there never removes the step.
146
236
  const canvasHasPointerRef = useRef(true);
237
+ // Cmd/Ctrl with +, - and 0 zoom the canvas only after a press on it;
238
+ // anywhere else they stay the browser's page zoom, which people with low
239
+ // vision rely on.
240
+ const canvasOwnsZoomKeysRef = useRef(false);
147
241
  const canvasRef = useRef(null);
148
- // Read by callbacks that run after an await (mentor prefill), which must
242
+ // Read by callbacks that run after an await (picking an agent), which must
149
243
  // not write back a stale copy of the graph.
150
244
  const nodesRef = useRef(nodes);
151
245
  const edgesRef = useRef(edges);
@@ -153,7 +247,30 @@ function WorkflowCanvas({ onDraggedItem: _onDraggedItem, onClickedItem, previewM
153
247
  edgesRef.current = edges;
154
248
  const dragStartRef = useRef(null);
155
249
  const dragMovedRef = useRef(false);
156
- const suppressMentorClickRef = useRef(false);
250
+ // Only the pointer that started a drag, pan or connection moves it; a
251
+ // second finger elsewhere on the page must not.
252
+ const gesturePointerRef = useRef(null);
253
+ const pendingPanelRef = useRef(null);
254
+ // Touch opens a step's panel on the tap's click rather than its release: a
255
+ // panel opened on release would sit under the finger and take that click.
256
+ const tappedNodeRef = useRef(null);
257
+ // The button a press landed on. A button that appears under a finger during
258
+ // a tap (a card's actions once its step is selected, Delete Connection once
259
+ // its connection is) must not act on that tap's click.
260
+ const pressedRef = useRef(null);
261
+ const touchPointsRef = useRef(new Map());
262
+ const pinchRef = useRef(null);
263
+ const [isPinching, setIsPinching] = useState(false);
264
+ // Several wheel events can land between renders; each must build on the
265
+ // view the one before it left.
266
+ const viewRef = useRef({ zoom, pan: panOffset });
267
+ viewRef.current = { zoom, pan: panOffset };
268
+ const clipboardRef = useRef(null);
269
+ const handledFocusNonceRef = useRef(null);
270
+ // The panel focuses a field when its focusField changes, so each request
271
+ // goes through `pending` (no field) first: asking for the same field again
272
+ // must focus it again.
273
+ const [focusTarget, setFocusTarget] = useState(null);
157
274
  // Track if we've loaded initial data from props
158
275
  const hasLoadedInitialData = useRef(false);
159
276
  // Track last emitted state to avoid duplicate onStateChange calls
@@ -191,8 +308,175 @@ function WorkflowCanvas({ onDraggedItem: _onDraggedItem, onClickedItem, previewM
191
308
  setPanOffset({ x: initialViewport.x, y: initialViewport.y });
192
309
  }
193
310
  }, [previewMode, initialViewport]);
194
- const saveToHistory = useCallback((newNodes, newEdges) => {
311
+ // Steps are laid out for a desktop canvas, so most start off a phone screen.
312
+ useEffect(() => {
313
+ if (!isPhone())
314
+ return;
315
+ const canvas = canvasRef.current;
316
+ const rect = canvas === null || canvas === void 0 ? void 0 : canvas.getBoundingClientRect();
317
+ if (!canvas || !rect || nodes.length === 0)
318
+ return;
319
+ const width = rect.width - FIT_MARGIN * 2;
320
+ const height = rect.height - PHONE_TOP_INSET - TOOLBAR_CLEARANCE - FIT_MARGIN * 2;
321
+ if (width <= 0 || height <= 0)
322
+ return;
323
+ // An Agent card grows with its name past the size nodeSize gives it.
324
+ const drawn = new Map();
325
+ canvas.querySelectorAll('[data-node-id]').forEach((card) => {
326
+ const { nodeId } = card.dataset;
327
+ if (nodeId && card.offsetWidth && card.offsetHeight) {
328
+ drawn.set(nodeId, { width: card.offsetWidth, height: card.offsetHeight });
329
+ }
330
+ });
331
+ const box = nodes.reduce((acc, node) => {
332
+ var _a;
333
+ const size = (_a = drawn.get(node.id)) !== null && _a !== void 0 ? _a : nodeSize(node);
334
+ return {
335
+ left: Math.min(acc.left, node.position.x),
336
+ top: Math.min(acc.top, node.position.y),
337
+ right: Math.max(acc.right, node.position.x + size.width),
338
+ bottom: Math.max(acc.bottom, node.position.y + size.height),
339
+ };
340
+ }, { left: Infinity, top: Infinity, right: -Infinity, bottom: -Infinity });
341
+ const boxWidth = box.right - box.left;
342
+ const boxHeight = box.bottom - box.top;
343
+ const fitZoom = Math.max(MIN_ZOOM, Math.min(1, width / boxWidth, height / boxHeight));
344
+ setZoom(fitZoom);
345
+ setPanOffset({
346
+ x: FIT_MARGIN + (width - boxWidth * fitZoom) / 2 - box.left * fitZoom,
347
+ y: PHONE_TOP_INSET + FIT_MARGIN + (height - boxHeight * fitZoom) / 2 - box.top * fitZoom,
348
+ });
349
+ }, []);
350
+ useEffect(() => {
351
+ const notePress = (e) => {
352
+ var _a, _b;
353
+ const target = e.target;
354
+ canvasOwnsZoomKeysRef.current =
355
+ !!target && !!((_a = canvasRef.current) === null || _a === void 0 ? void 0 : _a.contains(target)) && !((_b = target.closest) === null || _b === void 0 ? void 0 : _b.call(target, NODE_PANEL_SELECTOR));
356
+ };
357
+ document.addEventListener('pointerdown', notePress, true);
358
+ return () => document.removeEventListener('pointerdown', notePress, true);
359
+ }, []);
360
+ // iOS Safari zooms the whole page on a pinch, touch-none or not.
361
+ useEffect(() => {
362
+ const root = rootRef.current;
363
+ if (!root)
364
+ return;
365
+ const keepPageZoom = (e) => e.preventDefault();
366
+ root.addEventListener('gesturestart', keepPageZoom, { passive: false });
367
+ return () => root.removeEventListener('gesturestart', keepPageZoom);
368
+ }, []);
369
+ const setView = useCallback((nextZoom, nextPan) => {
370
+ viewRef.current = { zoom: nextZoom, pan: nextPan };
371
+ setZoom(nextZoom);
372
+ setPanOffset(nextPan);
373
+ }, []);
374
+ // Keeps the canvas point under `anchor` (relative to the canvas) in place.
375
+ const zoomTo = useCallback((target, anchor) => {
376
+ const { zoom: current, pan } = viewRef.current;
377
+ const next = clampZoom(target);
378
+ if (next === current)
379
+ return false;
380
+ setView(next, {
381
+ x: anchor.x - ((anchor.x - pan.x) * next) / current,
382
+ y: anchor.y - ((anchor.y - pan.y) * next) / current,
383
+ });
384
+ return true;
385
+ }, [setView]);
386
+ const zoomAroundCenter = (target) => {
387
+ var _a, _b, _c;
388
+ const rect = (_a = canvasRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
389
+ return zoomTo(target, { x: ((_b = rect === null || rect === void 0 ? void 0 : rect.width) !== null && _b !== void 0 ? _b : 0) / 2, y: ((_c = rect === null || rect === void 0 ? void 0 : rect.height) !== null && _c !== void 0 ? _c : 0) / 2 });
390
+ };
391
+ // Rounded to whole percents, so steps land on 110%, 120% and back on 100%
392
+ // rather than drifting by float error.
393
+ const stepZoom = (delta) => zoomAroundCenter(Math.round((viewRef.current.zoom + delta) * 100) / 100);
394
+ const handleZoomIn = () => stepZoom(ZOOM_STEP);
395
+ const handleZoomOut = () => stepZoom(-ZOOM_STEP);
396
+ const handleResetZoom = () => zoomAroundCenter(1);
397
+ // React's onWheel is passive, and only a cancelled ctrl+wheel keeps the
398
+ // browser from zooming the whole page on a trackpad pinch.
399
+ useEffect(() => {
400
+ const canvas = canvasRef.current;
401
+ if (!canvas)
402
+ return;
403
+ const handleWheel = (e) => {
404
+ var _a;
405
+ const target = e.target;
406
+ if ((_a = target.closest) === null || _a === void 0 ? void 0 : _a.call(target, `${NODE_PANEL_SELECTOR}, ${TYPING_SELECTOR}`))
407
+ return;
408
+ if (scrollsInsideCard(target))
409
+ return;
410
+ const rect = canvas.getBoundingClientRect();
411
+ const unit = e.deltaMode === 1 ? WHEEL_LINE_HEIGHT : e.deltaMode === 2 ? rect.height : 1;
412
+ const deltaX = e.deltaX * unit;
413
+ const deltaY = e.deltaY * unit;
414
+ if (e.ctrlKey || e.metaKey) {
415
+ e.preventDefault();
416
+ const step = Math.max(-MAX_WHEEL_ZOOM_DELTA, Math.min(MAX_WHEEL_ZOOM_DELTA, deltaY));
417
+ zoomTo(viewRef.current.zoom * Math.exp(-step * WHEEL_ZOOM_RATE), {
418
+ x: e.clientX - rect.left,
419
+ y: e.clientY - rect.top,
420
+ });
421
+ return;
422
+ }
423
+ if (!deltaX && !deltaY)
424
+ return;
425
+ e.preventDefault();
426
+ const { zoom: current, pan } = viewRef.current;
427
+ setView(current, { x: pan.x - deltaX, y: pan.y - deltaY });
428
+ };
429
+ canvas.addEventListener('wheel', handleWheel, { passive: false });
430
+ return () => canvas.removeEventListener('wheel', handleWheel);
431
+ }, [setView, zoomTo]);
432
+ // Every finger on the canvas, so a second one can turn the gesture into a
433
+ // pinch. Listened to for the canvas's whole life: a finger left down after
434
+ // a pinch ends no gesture, but its release must still be forgotten.
435
+ useEffect(() => {
436
+ const points = touchPointsRef.current;
437
+ const track = (e) => {
438
+ if (points.has(e.pointerId))
439
+ points.set(e.pointerId, { x: e.clientX, y: e.clientY });
440
+ };
441
+ const forget = (e) => {
442
+ points.delete(e.pointerId);
443
+ };
444
+ window.addEventListener('pointermove', track);
445
+ window.addEventListener('pointerup', forget);
446
+ window.addEventListener('pointercancel', forget);
447
+ return () => {
448
+ window.removeEventListener('pointermove', track);
449
+ window.removeEventListener('pointerup', forget);
450
+ window.removeEventListener('pointercancel', forget);
451
+ };
452
+ }, []);
453
+ // Typing in a step's settings updates the step on every key; one undo step
454
+ // per run of typing in one field, until it loses focus, keeps the 50
455
+ // entries for changes to the graph. Adding a row or flipping a switch is a
456
+ // step of its own.
457
+ const lastNodeEditRef = useRef(null);
458
+ useEffect(() => {
459
+ const endTypingRun = (event) => {
460
+ var _a;
461
+ if (((_a = lastNodeEditRef.current) === null || _a === void 0 ? void 0 : _a.field) === event.target)
462
+ lastNodeEditRef.current = null;
463
+ };
464
+ document.addEventListener('focusout', endTypingRun);
465
+ return () => document.removeEventListener('focusout', endTypingRun);
466
+ }, []);
467
+ // An open step panel copies the step's settings when it opens, so an undo
468
+ // that changes them has to reopen it.
469
+ const [panelVersion, setPanelVersion] = useState(0);
470
+ const saveToHistory = useCallback((newNodes, newEdges, replaceLast = false) => {
195
471
  const index = historyIndexRef.current;
472
+ if (replaceLast && index > 0) {
473
+ setHistory((prev) => [
474
+ ...prev.slice(0, index),
475
+ { nodes: [...newNodes], edges: [...newEdges] },
476
+ ]);
477
+ return;
478
+ }
479
+ lastNodeEditRef.current = null;
196
480
  setHistory((prev) => {
197
481
  const newHistory = prev.slice(0, index + 1);
198
482
  newHistory.push({ nodes: [...newNodes], edges: [...newEdges] });
@@ -202,6 +486,14 @@ function WorkflowCanvas({ onDraggedItem: _onDraggedItem, onClickedItem, previewM
202
486
  setHistoryIndex(historyIndexRef.current);
203
487
  }, []);
204
488
  const restoreHistory = (newIndex) => {
489
+ // History and state keep separate copies of a step's settings.
490
+ const dataOf = (list) => { var _a; return JSON.stringify((_a = list.find((n) => n.id === selectedNodeForConfig)) === null || _a === void 0 ? void 0 : _a.data); };
491
+ if (selectedNodeForConfig && dataOf(history[newIndex].nodes) !== dataOf(nodesRef.current)) {
492
+ setPanelVersion((version) => version + 1);
493
+ // The reopened panel would focus a problem's field again.
494
+ setFocusTarget(null);
495
+ }
496
+ lastNodeEditRef.current = null;
205
497
  historyIndexRef.current = newIndex;
206
498
  setHistoryIndex(newIndex);
207
499
  setNodes(history[newIndex].nodes);
@@ -209,19 +501,19 @@ function WorkflowCanvas({ onDraggedItem: _onDraggedItem, onClickedItem, previewM
209
501
  setSelectedEdgeId(null);
210
502
  setHoveredEdgeId(null);
211
503
  };
504
+ const canUndo = historyIndex > 0;
505
+ const canRedo = historyIndex < history.length - 1;
212
506
  const handleUndo = () => {
213
- if (historyIndex > 0)
214
- restoreHistory(historyIndex - 1);
507
+ if (!canUndo)
508
+ return false;
509
+ restoreHistory(historyIndex - 1);
510
+ return true;
215
511
  };
216
512
  const handleRedo = () => {
217
- if (historyIndex < history.length - 1)
218
- restoreHistory(historyIndex + 1);
219
- };
220
- const handleZoomIn = () => {
221
- setZoom((prev) => Math.min(prev + 0.1, 2));
222
- };
223
- const handleZoomOut = () => {
224
- setZoom((prev) => Math.max(prev - 0.1, 0.5));
513
+ if (!canRedo)
514
+ return false;
515
+ restoreHistory(historyIndex + 1);
516
+ return true;
225
517
  };
226
518
  const handleUpdateNode = useCallback((nodeId, updates) => {
227
519
  const target = nodesRef.current.find((node) => node.id === nodeId);
@@ -235,70 +527,32 @@ function WorkflowCanvas({ onDraggedItem: _onDraggedItem, onClickedItem, previewM
235
527
  : updates;
236
528
  const applyUpdate = (node) => node.id === nodeId ? { ...node, data: { ...node.data, ...normalizedUpdates } } : node;
237
529
  const { conditions } = updates;
238
- const moveBranchEdges = (current) => isConditionalType(target.type) && conditions
239
- ? reindexConditionEdges(current, nodeId, getConditions(target.data), conditions)
240
- : current;
530
+ const reshapesClassifier = isClassifierType(target.type) && ('answer_type' in updates || 'categories' in updates);
531
+ const moveBranchEdges = (current) => {
532
+ if (isConditionalType(target.type) && conditions) {
533
+ return reindexConditionEdges(current, nodeId, getConditions(target.data), conditions);
534
+ }
535
+ if (reshapesClassifier) {
536
+ return reconcileClassifierEdges(current, nodeId, target.data, {
537
+ ...target.data,
538
+ ...normalizedUpdates,
539
+ });
540
+ }
541
+ return current;
542
+ };
241
543
  const newNodes = nodesRef.current.map(applyUpdate);
242
544
  const newEdges = moveBranchEdges(edgesRef.current);
243
545
  nodesRef.current = newNodes;
244
546
  edgesRef.current = newEdges;
245
547
  setNodes((prev) => prev.map(applyUpdate));
246
548
  setEdges(moveBranchEdges);
247
- saveToHistory(newNodes, newEdges);
549
+ const active = document.activeElement;
550
+ const typingField = (active === null || active === void 0 ? void 0 : active.matches(TEXT_ENTRY_SELECTOR)) && active.closest(NODE_PANEL_SELECTOR) ? active : null;
551
+ const key = `${nodeId}:${Object.keys(updates).sort().join(',')}`;
552
+ const last = lastNodeEditRef.current;
553
+ saveToHistory(newNodes, newEdges, !!typingField && (last === null || last === void 0 ? void 0 : last.key) === key && last.field === typingField);
554
+ lastNodeEditRef.current = typingField ? { key, field: typingField } : null;
248
555
  }, [saveToHistory]);
249
- const prefillMentorNode = useCallback(async (nodeId, mentorId, existingData) => {
250
- if (!mentorId || !org || !username)
251
- return;
252
- try {
253
- const settings = (await fetchMentorSettings({
254
- mentor: mentorId,
255
- org,
256
- }).unwrap());
257
- const mentorLabel = settings.display_name || settings.mentor_name;
258
- const mentorInstructions = settings.system_prompt;
259
- const mentorModel = settings.llm_name;
260
- const updates = {};
261
- if (mentorLabel && isDefaultMentorLabel(existingData === null || existingData === void 0 ? void 0 : existingData.label)) {
262
- updates.label = mentorLabel;
263
- }
264
- if (mentorInstructions && !(existingData === null || existingData === void 0 ? void 0 : existingData.instructions)) {
265
- updates.instructions = mentorInstructions;
266
- }
267
- if (mentorModel && !(existingData === null || existingData === void 0 ? void 0 : existingData.model)) {
268
- updates.model = mentorModel;
269
- }
270
- if (Object.keys(updates).length > 0) {
271
- handleUpdateNode(nodeId, updates);
272
- }
273
- }
274
- catch (error) {
275
- console.error('Failed to prefill mentor node data:', error);
276
- }
277
- }, [fetchMentorSettings, handleUpdateNode, org, username]);
278
- useEffect(() => {
279
- if (!defaultMentorId || previewMode)
280
- return;
281
- const mentorNodesMissingId = nodes.filter((node) => node.type === 'mentor' && !node.data.entry_mentor_id && !node.data.mentor_id);
282
- if (mentorNodesMissingId.length === 0)
283
- return;
284
- setNodes((prev) => prev.map((node) => {
285
- if (node.type !== 'mentor')
286
- return node;
287
- if (node.data.entry_mentor_id || node.data.mentor_id)
288
- return node;
289
- return {
290
- ...node,
291
- data: {
292
- ...node.data,
293
- entry_mentor_id: defaultMentorId,
294
- mentor_id: defaultMentorId,
295
- },
296
- };
297
- }));
298
- mentorNodesMissingId.forEach((node) => {
299
- prefillMentorNode(node.id, defaultMentorId, node.data);
300
- });
301
- }, [defaultMentorId, previewMode, nodes, prefillMentorNode]);
302
556
  const closeMentorModal = useCallback(() => {
303
557
  setShowMentorModal(false);
304
558
  setMentorSearchQuery('');
@@ -331,7 +585,6 @@ function WorkflowCanvas({ onDraggedItem: _onDraggedItem, onClickedItem, previewM
331
585
  mentor.name ||
332
586
  (currentData === null || currentData === void 0 ? void 0 : currentData.label) ||
333
587
  'Agent',
334
- instructions: settings.system_prompt || (currentData === null || currentData === void 0 ? void 0 : currentData.instructions),
335
588
  model: settings.llm_name || (currentData === null || currentData === void 0 ? void 0 : currentData.model),
336
589
  };
337
590
  }
@@ -363,11 +616,9 @@ function WorkflowCanvas({ onDraggedItem: _onDraggedItem, onClickedItem, previewM
363
616
  setMentorSearchQuery('');
364
617
  setShowMentorModal(true);
365
618
  }, [previewMode]);
366
- const findNonOverlappingPosition = useCallback((baseX, baseY, nodeType, view) => {
619
+ const findNonOverlappingPosition = useCallback((baseX, baseY, step, view) => {
367
620
  var _a, _b, _c;
368
- const { width: nodeWidth, height: nodeHeight } = nodeSize({
369
- type: nodeType,
370
- });
621
+ const { width: nodeWidth, height: nodeHeight } = nodeSize(step);
371
622
  const SPACING = 20; // Minimum spacing between nodes
372
623
  const hasOverlap = ({ x, y }) => nodes.some((node) => {
373
624
  const existing = nodeSize(node);
@@ -413,11 +664,56 @@ function WorkflowCanvas({ onDraggedItem: _onDraggedItem, onClickedItem, previewM
413
664
  const top = -panOffset.y / zoom || 0;
414
665
  return {
415
666
  left,
416
- top,
667
+ top: top + (isPhone() ? PHONE_TOP_INSET / zoom : 0),
417
668
  right: left + rect.width / zoom,
418
669
  bottom: top + Math.max(0, rect.height - TOOLBAR_CLEARANCE) / zoom,
419
670
  };
420
671
  };
672
+ // Agent steps start with no agent: the workflow's own agent can't run as
673
+ // one of its steps.
674
+ const newStep = (type, label) => {
675
+ if (type === 'mentor') {
676
+ return { type, data: { label, subtitle: 'Agent', color: 'chart-1' } };
677
+ }
678
+ if (isClassifierType(type)) {
679
+ return {
680
+ type,
681
+ data: newClassifierData(label, [
682
+ t('workflowsWorkflowCanvas.defaultCategoryLabel', { number: 1 }),
683
+ t('workflowsWorkflowCanvas.defaultCategoryLabel', { number: 2 }),
684
+ ]),
685
+ };
686
+ }
687
+ if (isConditionalType(type)) {
688
+ return {
689
+ type,
690
+ data: {
691
+ label,
692
+ conditions: [{ id: '1', caseName: '', expression: '' }],
693
+ conditionCount: 1,
694
+ },
695
+ };
696
+ }
697
+ if (type === 'note') {
698
+ return { type, data: { label, content: 'Sticky Note' }, width: 200, height: 120 };
699
+ }
700
+ return { type, data: { label } };
701
+ };
702
+ const addStep = (step, base, view) => {
703
+ const newNode = {
704
+ id: `${step.type}-${Date.now()}`,
705
+ type: step.type,
706
+ position: findNonOverlappingPosition(base.x, base.y, step, view),
707
+ data: step.data,
708
+ ...(step.width !== undefined && { width: step.width, height: step.height }),
709
+ draggable: true,
710
+ selectable: true,
711
+ connectable: true,
712
+ };
713
+ const newNodes = [...nodes, newNode];
714
+ setNodes(newNodes);
715
+ saveToHistory(newNodes, edges);
716
+ };
421
717
  useEffect(() => {
422
718
  if (previewMode)
423
719
  return; // Don't add nodes in preview mode
@@ -430,36 +726,12 @@ function WorkflowCanvas({ onDraggedItem: _onDraggedItem, onClickedItem, previewM
430
726
  const rect = canvasRef.current.getBoundingClientRect();
431
727
  const centerX = (rect.width / 2 - panOffset.x) / zoom;
432
728
  const centerY = (rect.height / 2 - panOffset.y) / zoom;
433
- const size = nodeSize({ type: onClickedItem.id });
434
- const { x, y } = findNonOverlappingPosition(centerX - size.width / 2, centerY - size.height / 2, onClickedItem.id, visibleBounds(rect));
435
- const newNode = {
436
- id: `${onClickedItem.id}-${Date.now()}`,
437
- type: onClickedItem.id,
438
- position: { x, y },
439
- data: {
440
- label: onClickedItem.label,
441
- ...(onClickedItem.id === 'mentor' && {
442
- subtitle: 'Agent',
443
- color: 'chart-1',
444
- entry_mentor_id: defaultMentorId,
445
- mentor_id: defaultMentorId,
446
- }),
447
- ...(onClickedItem.id === 'note' && { content: 'Sticky Note' }),
448
- },
449
- ...(onClickedItem.id === 'note' && { width: 200, height: 120 }),
450
- draggable: true,
451
- selectable: true,
452
- connectable: true,
453
- };
454
- const newNodes = [...nodes, newNode];
455
- setNodes(newNodes);
456
- saveToHistory(newNodes, edges);
457
- if (onClickedItem.id === 'mentor' && defaultMentorId) {
458
- prefillMentorNode(newNode.id, defaultMentorId, newNode.data);
459
- }
729
+ const step = newStep(onClickedItem.id, onClickedItem.label);
730
+ const size = nodeSize(step);
731
+ addStep(step, { x: centerX - size.width / 2, y: centerY - size.height / 2 }, visibleBounds(rect));
460
732
  }
461
- }, [onClickedItem, defaultMentorId, edges, prefillMentorNode]);
462
- const handleNodeMouseDown = (e, nodeId) => {
733
+ }, [onClickedItem, edges]);
734
+ const handleNodePointerDown = (e, nodeId) => {
463
735
  if (previewMode)
464
736
  return; // Prevent node dragging in preview mode
465
737
  if (e.button !== 0)
@@ -469,23 +741,23 @@ function WorkflowCanvas({ onDraggedItem: _onDraggedItem, onClickedItem, previewM
469
741
  if (!node)
470
742
  return;
471
743
  setSelectedEdgeId(null);
744
+ pendingPanelRef.current = null;
472
745
  if (e.ctrlKey || e.metaKey) {
473
746
  setNodes((prev) => prev.map((n) => (n.id === nodeId ? { ...n, selected: !n.selected } : n)));
474
- if (node.type === 'mentor') {
475
- setSelectedNodeForConfig(null);
476
- }
477
- suppressMentorClickRef.current = true;
478
747
  }
479
748
  else {
480
749
  setNodes((prev) => prev.map((n) => ({ ...n, selected: n.id === nodeId })));
481
- if (node.type !== 'mentor') {
750
+ if (e.pointerType === 'mouse') {
482
751
  setSelectedNodeForConfig(nodeId);
483
752
  }
484
753
  else {
485
- setSelectedNodeForConfig(null);
754
+ // On a phone the panel covers the canvas, hiding the step a finger
755
+ // may be about to drag, so touch waits for the tap to end.
756
+ setSelectedNodeForConfig((current) => (current === nodeId ? current : null));
757
+ pendingPanelRef.current = nodeId;
486
758
  }
487
- suppressMentorClickRef.current = false;
488
759
  }
760
+ gesturePointerRef.current = { id: e.pointerId, type: e.pointerType };
489
761
  dragStartRef.current = { x: e.clientX, y: e.clientY };
490
762
  dragMovedRef.current = false;
491
763
  setDraggedNode(nodeId);
@@ -498,6 +770,7 @@ function WorkflowCanvas({ onDraggedItem: _onDraggedItem, onClickedItem, previewM
498
770
  if (previewMode)
499
771
  return; // Prevent connection creation in preview mode
500
772
  e.stopPropagation();
773
+ gesturePointerRef.current = { id: e.pointerId, type: e.pointerType };
501
774
  setConnectingFrom({ nodeId, handle });
502
775
  };
503
776
  const handleResizeStart = (e, nodeId, corner) => {
@@ -507,6 +780,7 @@ function WorkflowCanvas({ onDraggedItem: _onDraggedItem, onClickedItem, previewM
507
780
  const node = nodes.find((n) => n.id === nodeId);
508
781
  if (!node)
509
782
  return;
783
+ gesturePointerRef.current = { id: e.pointerId, type: e.pointerType };
510
784
  setResizingNote({
511
785
  nodeId,
512
786
  corner,
@@ -516,21 +790,106 @@ function WorkflowCanvas({ onDraggedItem: _onDraggedItem, onClickedItem, previewM
516
790
  startHeight: node.height || 120,
517
791
  });
518
792
  };
519
- const handleCanvasMouseDown = (e) => {
793
+ const resetGesture = () => {
794
+ dragMovedRef.current = false;
795
+ dragStartRef.current = null;
796
+ pendingPanelRef.current = null;
797
+ gesturePointerRef.current = null;
798
+ setDraggedNode(null);
799
+ setIsPanning(false);
800
+ setConnectingFrom(null);
801
+ setTempConnectionPos(null);
802
+ setResizingNote(null);
803
+ setSelectionBox(null);
804
+ };
805
+ // A second finger always zooms and pans, whatever the first one was doing.
806
+ const startPinch = () => {
807
+ var _a;
808
+ const [first, second] = [...touchPointsRef.current.entries()];
809
+ const rect = (_a = canvasRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
810
+ if (!first || !second || !rect)
811
+ return;
812
+ if (draggedNode && dragMovedRef.current) {
813
+ setNodes((prev) => prev.map((n) => ({ ...n, dragging: false })));
814
+ saveToHistory(nodesRef.current, edgesRef.current);
815
+ }
816
+ resetGesture();
817
+ pinchRef.current = {
818
+ ids: [first[0], second[0]],
819
+ startDistance: Math.hypot(second[1].x - first[1].x, second[1].y - first[1].y) || 1,
820
+ startCenter: centerOf(first[1], second[1]),
821
+ startZoom: zoom,
822
+ startPan: panOffset,
823
+ origin: { x: rect.left, y: rect.top },
824
+ };
825
+ setIsPinching(true);
826
+ };
827
+ const movePinch = (e) => {
828
+ const pinch = pinchRef.current;
829
+ if (!pinch || !pinch.ids.includes(e.pointerId))
830
+ return;
831
+ const points = touchPointsRef.current;
832
+ points.set(e.pointerId, { x: e.clientX, y: e.clientY });
833
+ const a = points.get(pinch.ids[0]);
834
+ const b = points.get(pinch.ids[1]);
835
+ if (!a || !b)
836
+ return;
837
+ const nextZoom = clampZoom((pinch.startZoom * Math.hypot(b.x - a.x, b.y - a.y)) / pinch.startDistance);
838
+ // The canvas point under the fingers' starting centre stays under their
839
+ // current centre, so spreading zooms around them and sliding pans.
840
+ const anchorX = (pinch.startCenter.x - pinch.origin.x - pinch.startPan.x) / pinch.startZoom;
841
+ const anchorY = (pinch.startCenter.y - pinch.origin.y - pinch.startPan.y) / pinch.startZoom;
842
+ const center = centerOf(a, b);
843
+ setZoom(nextZoom);
844
+ setPanOffset({
845
+ x: center.x - pinch.origin.x - anchorX * nextZoom,
846
+ y: center.y - pinch.origin.y - anchorY * nextZoom,
847
+ });
848
+ };
849
+ const handleTouchPointerDown = (e) => {
850
+ if (e.pointerType === 'mouse')
851
+ return;
852
+ const canvas = canvasRef.current;
853
+ const target = e.target;
854
+ if (!(canvas === null || canvas === void 0 ? void 0 : canvas.contains(target)) || target.closest(NODE_PANEL_SELECTOR))
855
+ return;
856
+ // iOS keeps a text field focused, keyboard up, when the press lands on
857
+ // something that can't take focus.
858
+ const active = document.activeElement;
859
+ if (active instanceof HTMLElement &&
860
+ canvas.contains(active) &&
861
+ active.matches(TEXT_ENTRY_SELECTOR) &&
862
+ !active.contains(target)) {
863
+ active.blur();
864
+ }
865
+ const points = touchPointsRef.current;
866
+ points.set(e.pointerId, { x: e.clientX, y: e.clientY });
867
+ if (points.size < 2)
868
+ return;
869
+ e.stopPropagation();
870
+ if (!pinchRef.current && points.size === 2)
871
+ startPinch();
872
+ };
873
+ const handleCanvasPointerDown = (e) => {
520
874
  var _a, _b;
521
875
  if (e.button !== 0 || draggedNode || connectingFrom)
522
876
  return;
523
- // Dialogs render in portals, so their backdrop's mousedown still bubbles
877
+ // Dialogs render in portals, so their backdrop's press still bubbles
524
878
  // here through the React tree.
525
879
  if (!((_a = canvasRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.target)))
526
880
  return;
527
881
  const target = e.target;
882
+ // The settings panel renders inside the canvas, and a drag in a note's
883
+ // text selects text rather than moving the view.
884
+ if (target.closest(`${NODE_PANEL_SELECTOR}, ${TEXT_ENTRY_SELECTOR}`))
885
+ return;
528
886
  const isCanvasClick = target === e.currentTarget || target.tagName === 'svg' || target.tagName === 'rect';
529
887
  if (isCanvasClick && !previewMode) {
530
888
  setSelectedNodeForConfig(null);
531
889
  setSelectedEdgeId(null);
532
890
  }
533
891
  if (tool === 'hand') {
892
+ gesturePointerRef.current = { id: e.pointerId, type: e.pointerType };
534
893
  setIsPanning(true);
535
894
  setPanStart({ x: e.clientX - panOffset.x, y: e.clientY - panOffset.y });
536
895
  }
@@ -538,21 +897,39 @@ function WorkflowCanvas({ onDraggedItem: _onDraggedItem, onClickedItem, previewM
538
897
  const rect = (_b = canvasRef.current) === null || _b === void 0 ? void 0 : _b.getBoundingClientRect();
539
898
  if (!rect)
540
899
  return;
900
+ gesturePointerRef.current = { id: e.pointerId, type: e.pointerType };
541
901
  const x = (e.clientX - rect.left - panOffset.x) / zoom;
542
902
  const y = (e.clientY - rect.top - panOffset.y) / zoom;
543
903
  setSelectionBox({ startX: x, startY: y, currentX: x, currentY: y });
544
904
  setNodes((prev) => prev.map((n) => ({ ...n, selected: false })));
545
905
  }
546
906
  };
547
- const handleMouseMove = useCallback((e) => {
907
+ // A mouse has one pointer whatever id it reports; fingers are told apart.
908
+ const isOtherPointer = (e) => {
909
+ const gesture = gesturePointerRef.current;
910
+ if (!gesture)
911
+ return false;
912
+ return gesture.type === 'mouse' ? e.pointerType !== 'mouse' : e.pointerId !== gesture.id;
913
+ };
914
+ const handlePointerMove = useCallback((e) => {
915
+ if (pinchRef.current) {
916
+ movePinch(e);
917
+ return;
918
+ }
919
+ if (isOtherPointer(e))
920
+ return;
548
921
  if (draggedNode) {
922
+ const isMouse = e.pointerType === 'mouse';
549
923
  if (dragStartRef.current) {
924
+ const slop = isMouse ? MOUSE_SLOP : TOUCH_SLOP;
550
925
  const movedX = Math.abs(e.clientX - dragStartRef.current.x);
551
926
  const movedY = Math.abs(e.clientY - dragStartRef.current.y);
552
- if (movedX > 3 || movedY > 3) {
927
+ if (movedX > slop || movedY > slop) {
553
928
  dragMovedRef.current = true;
554
929
  }
555
930
  }
931
+ if (!isMouse && !dragMovedRef.current)
932
+ return;
556
933
  const draggedNodeData = nodes.find((n) => n.id === draggedNode);
557
934
  if (!draggedNodeData)
558
935
  return;
@@ -633,9 +1010,30 @@ function WorkflowCanvas({ onDraggedItem: _onDraggedItem, onClickedItem, previewM
633
1010
  nodes,
634
1011
  zoom,
635
1012
  ]);
636
- const handleMouseUp = useCallback(() => {
1013
+ const handlePointerUp = useCallback((e) => {
637
1014
  var _a;
638
- const targetNode = hoveredNode ? nodes.find((n) => n.id === hoveredNode) : undefined;
1015
+ const pinch = pinchRef.current;
1016
+ if (pinch) {
1017
+ // The finger left down is ignored until it lifts too.
1018
+ if (pinch.ids.includes(e.pointerId)) {
1019
+ pinchRef.current = null;
1020
+ setIsPinching(false);
1021
+ }
1022
+ return;
1023
+ }
1024
+ if (isOtherPointer(e))
1025
+ return;
1026
+ // A cancel (a system gesture, the phone rotating) keeps what was
1027
+ // dragged but connects nothing and opens nothing.
1028
+ const cancelled = e.type === 'pointercancel';
1029
+ // A tap fires mouse events too, which leave the hover on the last step
1030
+ // tapped, so only a mouse release may trust it.
1031
+ const dropTargetId = cancelled || !connectingFrom
1032
+ ? null
1033
+ : e.pointerType === 'mouse'
1034
+ ? hoveredNode
1035
+ : nodeIdAt(e.clientX, e.clientY);
1036
+ const targetNode = dropTargetId ? nodes.find((n) => n.id === dropTargetId) : undefined;
639
1037
  if (connectingFrom &&
640
1038
  targetNode &&
641
1039
  connectingFrom.nodeId !== targetNode.id &&
@@ -650,14 +1048,16 @@ function WorkflowCanvas({ onDraggedItem: _onDraggedItem, onClickedItem, previewM
650
1048
  sourceHandle: handle,
651
1049
  targetHandle: 'left',
652
1050
  };
653
- // The backend routes each branch output to a single step and keeps
654
- // only the last connection, so drawing one replaces the others - even
655
- // when it repeats a connection an older save already had.
656
- const newEdges = isBranchHandle(handle)
657
- ? [...edges.filter((edge) => !fromSameOutput(edge)), connection]
658
- : existing
659
- ? edges
660
- : [...edges, connection];
1051
+ // The backend keeps only the last connection of each branch output, and
1052
+ // publish refuses any other step that leads to more than one step. So a
1053
+ // new connection replaces the others from the same branch output, or
1054
+ // from every dot of a step that doesn't branch - even when it repeats
1055
+ // one an older save already had.
1056
+ const sourceNode = nodes.find((node) => node.id === nodeId);
1057
+ const replaces = isBranchingType(sourceNode === null || sourceNode === void 0 ? void 0 : sourceNode.type)
1058
+ ? fromSameOutput
1059
+ : (edge) => edge.source === nodeId;
1060
+ const newEdges = [...edges.filter((edge) => !replaces(edge)), connection];
661
1061
  if (existing ? newEdges.length !== edges.length : true) {
662
1062
  setEdges(newEdges);
663
1063
  saveToHistory(nodes, newEdges);
@@ -665,41 +1065,30 @@ function WorkflowCanvas({ onDraggedItem: _onDraggedItem, onClickedItem, previewM
665
1065
  }
666
1066
  if (draggedNode) {
667
1067
  setNodes((prev) => prev.map((n) => ({ ...n, dragging: false })));
668
- saveToHistory(nodes, edges);
669
- if (!previewMode && !dragMovedRef.current && !suppressMentorClickRef.current) {
670
- const clickedNode = nodes.find((node) => node.id === draggedNode);
671
- if ((clickedNode === null || clickedNode === void 0 ? void 0 : clickedNode.type) === 'mentor') {
672
- onOpenAgentSettings === null || onOpenAgentSettings === void 0 ? void 0 : onOpenAgentSettings((_a = clickedNode.data.mentor_id) !== null && _a !== void 0 ? _a : clickedNode.data.entry_mentor_id);
673
- }
1068
+ // A click on a step moves nothing; saving it would make Undo do nothing.
1069
+ const saved = (_a = history[historyIndexRef.current]) === null || _a === void 0 ? void 0 : _a.nodes;
1070
+ const moved = nodes.some((node) => {
1071
+ var _a;
1072
+ const before = (_a = saved === null || saved === void 0 ? void 0 : saved.find((n) => n.id === node.id)) === null || _a === void 0 ? void 0 : _a.position;
1073
+ return !before || before.x !== node.position.x || before.y !== node.position.y;
1074
+ });
1075
+ if (moved)
1076
+ saveToHistory(nodes, edges);
1077
+ if (!cancelled && !dragMovedRef.current && pendingPanelRef.current === draggedNode) {
1078
+ tappedNodeRef.current = draggedNode;
674
1079
  }
675
1080
  }
676
- dragMovedRef.current = false;
677
- dragStartRef.current = null;
678
- suppressMentorClickRef.current = false;
679
- setDraggedNode(null);
680
- setIsPanning(false);
681
- setConnectingFrom(null);
682
- setTempConnectionPos(null);
683
- setResizingNote(null);
684
- setSelectionBox(null);
685
- }, [
686
- connectingFrom,
687
- hoveredNode,
688
- draggedNode,
689
- nodes,
690
- edges,
691
- saveToHistory,
692
- onOpenAgentSettings,
693
- previewMode,
694
- defaultMentorId,
695
- ]);
1081
+ resetGesture();
1082
+ }, [connectingFrom, hoveredNode, draggedNode, nodes, edges, history, saveToHistory]);
696
1083
  useEffect(() => {
697
- if (draggedNode || isPanning || connectingFrom || resizingNote || selectionBox) {
698
- window.addEventListener('mousemove', handleMouseMove);
699
- window.addEventListener('mouseup', handleMouseUp);
1084
+ if (draggedNode || isPanning || connectingFrom || resizingNote || selectionBox || isPinching) {
1085
+ window.addEventListener('pointermove', handlePointerMove);
1086
+ window.addEventListener('pointerup', handlePointerUp);
1087
+ window.addEventListener('pointercancel', handlePointerUp);
700
1088
  return () => {
701
- window.removeEventListener('mousemove', handleMouseMove);
702
- window.removeEventListener('mouseup', handleMouseUp);
1089
+ window.removeEventListener('pointermove', handlePointerMove);
1090
+ window.removeEventListener('pointerup', handlePointerUp);
1091
+ window.removeEventListener('pointercancel', handlePointerUp);
703
1092
  };
704
1093
  }
705
1094
  }, [
@@ -708,8 +1097,9 @@ function WorkflowCanvas({ onDraggedItem: _onDraggedItem, onClickedItem, previewM
708
1097
  connectingFrom,
709
1098
  resizingNote,
710
1099
  selectionBox,
711
- handleMouseMove,
712
- handleMouseUp,
1100
+ isPinching,
1101
+ handlePointerMove,
1102
+ handlePointerUp,
713
1103
  ]);
714
1104
  const handleDrop = (e) => {
715
1105
  if (previewMode)
@@ -722,32 +1112,7 @@ function WorkflowCanvas({ onDraggedItem: _onDraggedItem, onClickedItem, previewM
722
1112
  const baseY = (e.clientY - rect.top - panOffset.y) / zoom;
723
1113
  try {
724
1114
  const data = JSON.parse(e.dataTransfer.getData('application/json'));
725
- const { x, y } = findNonOverlappingPosition(baseX, baseY, data.id, visibleBounds(rect));
726
- const newNode = {
727
- id: `${data.id}-${Date.now()}`,
728
- type: data.id,
729
- position: { x, y },
730
- data: {
731
- label: data.label,
732
- ...(data.id === 'mentor' && {
733
- subtitle: 'Agent',
734
- color: 'chart-1',
735
- entry_mentor_id: defaultMentorId,
736
- mentor_id: defaultMentorId,
737
- }),
738
- ...(data.id === 'note' && { content: 'Sticky Note' }),
739
- },
740
- ...(data.id === 'note' && { width: 200, height: 120 }),
741
- draggable: true,
742
- selectable: true,
743
- connectable: true,
744
- };
745
- const newNodes = [...nodes, newNode];
746
- setNodes(newNodes);
747
- saveToHistory(newNodes, edges);
748
- if (data.id === 'mentor' && defaultMentorId) {
749
- prefillMentorNode(newNode.id, defaultMentorId, newNode.data);
750
- }
1115
+ addStep(newStep(data.id, data.label), { x: baseX, y: baseY }, visibleBounds(rect));
751
1116
  }
752
1117
  catch (error) {
753
1118
  console.error('Failed to parse dropped data:', error);
@@ -756,26 +1121,19 @@ function WorkflowCanvas({ onDraggedItem: _onDraggedItem, onClickedItem, previewM
756
1121
  const handleDragOver = (e) => {
757
1122
  e.preventDefault();
758
1123
  };
759
- const getHandlePosition = (node, handle) => {
760
- let nodeWidth = 140;
761
- let nodeHeight = 50;
762
- if (node.type === 'start') {
763
- nodeWidth = 100;
764
- nodeHeight = 50;
765
- }
766
- else if (node.type === 'while' || node.type === 'user-approval') {
767
- nodeWidth = 280;
768
- nodeHeight = branchCardHeight(2);
769
- }
770
- else if (isConditionalType(node.type)) {
771
- nodeWidth = 280;
772
- nodeHeight = branchCardHeight(getConditionCount(node.data) + 1);
773
- }
774
- else if (node.type === 'note') {
775
- nodeWidth = node.width || 200;
776
- nodeHeight = node.height || 120;
777
- }
1124
+ const getHandlePosition = (node, handle, end = 'source') => {
1125
+ const { width: nodeWidth, height: nodeHeight } = node.type === 'start' ? { width: 100, height: 50 } : nodeSize(node);
778
1126
  const HANDLE_OFFSET = 8;
1127
+ // Checked first: a category id can be any word, 'left' or 'else' included.
1128
+ if (end === 'source' && isClassifierType(node.type)) {
1129
+ const row = classifierBranches(node.data).findIndex((branch) => branch.handle === handle);
1130
+ if (row !== -1) {
1131
+ return {
1132
+ x: node.position.x + nodeWidth + HANDLE_OFFSET,
1133
+ y: node.position.y + branchRowCenter(row),
1134
+ };
1135
+ }
1136
+ }
779
1137
  switch (handle) {
780
1138
  case 'left':
781
1139
  return {
@@ -862,42 +1220,218 @@ function WorkflowCanvas({ onDraggedItem: _onDraggedItem, onClickedItem, previewM
862
1220
  setSelectedNodeForConfig(null);
863
1221
  setNodes((prev) => prev.map((n) => ({ ...n, selected: false })));
864
1222
  };
865
- const handleDeleteSelection = useCallback(() => {
1223
+ const notePress = (e) => {
1224
+ e.stopPropagation();
1225
+ pressedRef.current = e.currentTarget;
1226
+ };
1227
+ // A click from the keyboard has no detail.
1228
+ const wasPressed = (e) => e.detail === 0 || pressedRef.current === e.currentTarget;
1229
+ const selectedSteps = nodes.filter((node) => node.selected && isDeletableNode(node));
1230
+ const handleDeleteSelection = () => {
866
1231
  if (selectedEdgeId && edges.some((edge) => edge.id === selectedEdgeId)) {
867
1232
  deleteEdge(selectedEdgeId);
868
- return;
1233
+ return true;
869
1234
  }
870
- deleteNodes(nodes.filter((node) => node.selected).map((node) => node.id));
871
- }, [selectedEdgeId, edges, deleteEdge, deleteNodes, nodes]);
1235
+ if (selectedSteps.length === 0)
1236
+ return false;
1237
+ deleteNodes(selectedSteps.map((node) => node.id));
1238
+ return true;
1239
+ };
1240
+ const copySelection = () => {
1241
+ const picked = nodesRef.current.filter((node) => node.selected && isDeletableNode(node));
1242
+ if (picked.length === 0)
1243
+ return false;
1244
+ const ids = new Set(picked.map((node) => node.id));
1245
+ clipboardRef.current = {
1246
+ nodes: stripUiProperties(picked),
1247
+ edges: stripEdgeUiProperties(edgesRef.current.filter((edge) => ids.has(edge.source) && ids.has(edge.target))),
1248
+ pastes: 0,
1249
+ };
1250
+ return true;
1251
+ };
1252
+ const pasteClipboard = () => {
1253
+ const clipboard = clipboardRef.current;
1254
+ if (!clipboard)
1255
+ return false;
1256
+ clipboard.pastes += 1;
1257
+ const offset = PASTE_OFFSET * clipboard.pastes;
1258
+ const current = nodesRef.current;
1259
+ const takenIds = new Set(current.map((node) => node.id));
1260
+ // Two steps saving into one variable would overwrite each other's result.
1261
+ const takenNames = new Set([
1262
+ ...collectWorkflowVariables(current),
1263
+ ...current.flatMap((node) => { var _a; return (_a = node.data.output_variable) !== null && _a !== void 0 ? _a : []; }),
1264
+ ]);
1265
+ const idFor = new Map();
1266
+ const pasted = clipboard.nodes.map((node) => {
1267
+ var _a;
1268
+ const id = freshStepId((_a = node.type) !== null && _a !== void 0 ? _a : 'step', takenIds);
1269
+ takenIds.add(id);
1270
+ idFor.set(node.id, id);
1271
+ const data = JSON.parse(JSON.stringify(node.data));
1272
+ if (data.output_variable) {
1273
+ data.output_variable = unusedName(data.output_variable, takenNames);
1274
+ takenNames.add(data.output_variable);
1275
+ }
1276
+ return {
1277
+ ...node,
1278
+ id,
1279
+ data,
1280
+ position: { x: node.position.x + offset, y: node.position.y + offset },
1281
+ selected: true,
1282
+ };
1283
+ });
1284
+ const pastedEdges = clipboard.edges.map((edge) => {
1285
+ var _a, _b;
1286
+ const source = (_a = idFor.get(edge.source)) !== null && _a !== void 0 ? _a : edge.source;
1287
+ const target = (_b = idFor.get(edge.target)) !== null && _b !== void 0 ? _b : edge.target;
1288
+ return {
1289
+ ...edge,
1290
+ id: edgeIdFor(source, edge.sourceHandle || 'right', target),
1291
+ source,
1292
+ target,
1293
+ };
1294
+ });
1295
+ const newNodes = [
1296
+ ...current.map((node) => (node.selected ? { ...node, selected: false } : node)),
1297
+ ...pasted,
1298
+ ];
1299
+ const newEdges = [...edgesRef.current, ...pastedEdges];
1300
+ nodesRef.current = newNodes;
1301
+ edgesRef.current = newEdges;
1302
+ setNodes(newNodes);
1303
+ setEdges(newEdges);
1304
+ setSelectedNodeForConfig(null);
1305
+ setSelectedEdgeId(null);
1306
+ saveToHistory(newNodes, newEdges);
1307
+ return true;
1308
+ };
1309
+ // The shortcuts are listened for once, and act on the latest graph.
1310
+ const shortcutsRef = useRef({
1311
+ undo: handleUndo,
1312
+ redo: handleRedo,
1313
+ remove: handleDeleteSelection,
1314
+ copy: copySelection,
1315
+ paste: pasteClipboard,
1316
+ zoomIn: handleZoomIn,
1317
+ zoomOut: handleZoomOut,
1318
+ resetZoom: handleResetZoom,
1319
+ });
1320
+ shortcutsRef.current = {
1321
+ undo: handleUndo,
1322
+ redo: handleRedo,
1323
+ remove: handleDeleteSelection,
1324
+ copy: copySelection,
1325
+ paste: pasteClipboard,
1326
+ zoomIn: handleZoomIn,
1327
+ zoomOut: handleZoomOut,
1328
+ resetZoom: handleResetZoom,
1329
+ };
872
1330
  useEffect(() => {
873
1331
  if (previewMode)
874
1332
  return;
875
1333
  const handleKeyDown = (e) => {
876
- var _a, _b;
877
- if (e.key !== 'Delete' && e.key !== 'Backspace')
1334
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1335
+ if (e.isComposing)
878
1336
  return;
879
1337
  const target = e.target;
880
- if (target.tagName === 'INPUT' ||
881
- target.tagName === 'TEXTAREA' ||
882
- target.isContentEditable ||
883
- ((_a = target.closest) === null || _a === void 0 ? void 0 : _a.call(target, NODE_PANEL_SELECTOR)) ||
884
- !canvasHasPointerRef.current) {
1338
+ // Text being typed keeps the browser's own undo and Backspace.
1339
+ if (((_a = target.closest) === null || _a === void 0 ? void 0 : _a.call(target, TYPING_SELECTOR)) || target.isContentEditable)
1340
+ return;
1341
+ if (document.querySelector(OPEN_DIALOG_SELECTOR))
1342
+ return;
1343
+ if ((_c = (_b = document.activeElement) === null || _b === void 0 ? void 0 : _b.closest) === null || _c === void 0 ? void 0 : _c.call(_b, OWN_KEYS_SELECTOR))
1344
+ return;
1345
+ const { undo, redo, remove, copy, paste } = shortcutsRef.current;
1346
+ const withCommand = (e.metaKey || e.ctrlKey) && !e.altKey;
1347
+ const letter = withCommand ? letterOf(e) : '';
1348
+ const historyKey = historyKeyOf(e);
1349
+ if (historyKey) {
1350
+ if (historyKey === 'undo' ? undo() : redo())
1351
+ e.preventDefault();
885
1352
  return;
886
1353
  }
887
- // Dialogs and menus (Edit Agent, Add State Variable, selects) render in
888
- // portals; a key pressed there must not delete the step behind them.
889
- const active = document.activeElement;
890
- if (active && active !== document.body && !((_b = rootRef.current) === null || _b === void 0 ? void 0 : _b.contains(active))) {
1354
+ if ((letter === 'c' || letter === 'v') && !e.shiftKey) {
1355
+ // Text selected on the page is what a person means to copy.
1356
+ if (letter === 'c' && ((_e = (_d = window.getSelection) === null || _d === void 0 ? void 0 : _d.call(window)) === null || _e === void 0 ? void 0 : _e.toString()))
1357
+ return;
1358
+ if (letter === 'c' ? copy() : paste())
1359
+ e.preventDefault();
891
1360
  return;
892
1361
  }
893
- e.preventDefault();
894
- handleDeleteSelection();
1362
+ const zoomAction = withCommand ? ZOOM_KEYS[e.key] : undefined;
1363
+ if (zoomAction) {
1364
+ const active = document.activeElement;
1365
+ const focusOnCanvas = !active || active === document.body || !!((_f = rootRef.current) === null || _f === void 0 ? void 0 : _f.contains(active));
1366
+ if (canvasOwnsZoomKeysRef.current && focusOnCanvas && shortcutsRef.current[zoomAction]()) {
1367
+ e.preventDefault();
1368
+ }
1369
+ return;
1370
+ }
1371
+ if (!e.metaKey && !e.ctrlKey && !e.altKey && !e.shiftKey) {
1372
+ const key = letterOf(e);
1373
+ if (key === 'h' || key === 'v') {
1374
+ setTool(key === 'h' ? 'hand' : 'pointer');
1375
+ e.preventDefault();
1376
+ return;
1377
+ }
1378
+ }
1379
+ if (e.key !== 'Delete' && e.key !== 'Backspace')
1380
+ return;
1381
+ if (((_g = target.closest) === null || _g === void 0 ? void 0 : _g.call(target, NODE_PANEL_SELECTOR)) || !canvasHasPointerRef.current)
1382
+ return;
1383
+ // A select's menu renders in a portal; a key pressed there must not
1384
+ // delete the step behind it.
1385
+ const active = document.activeElement;
1386
+ if (active && active !== document.body && !((_h = rootRef.current) === null || _h === void 0 ? void 0 : _h.contains(active)))
1387
+ return;
1388
+ if (remove())
1389
+ e.preventDefault();
895
1390
  };
896
1391
  window.addEventListener('keydown', handleKeyDown);
897
1392
  return () => {
898
1393
  window.removeEventListener('keydown', handleKeyDown);
899
1394
  };
900
- }, [previewMode, handleDeleteSelection]);
1395
+ }, [previewMode]);
1396
+ useEffect(() => {
1397
+ if (!focusRequest || handledFocusNonceRef.current === focusRequest.nonce)
1398
+ return;
1399
+ handledFocusNonceRef.current = focusRequest.nonce;
1400
+ if (previewMode)
1401
+ return;
1402
+ const node = nodesRef.current.find((n) => n.id === focusRequest.nodeId);
1403
+ const canvas = canvasRef.current;
1404
+ if (!node || !canvas)
1405
+ return;
1406
+ // An Agent card grows with its name past the size nodeSize gives it.
1407
+ const card = Array.from(canvas.querySelectorAll('[data-node-id]')).find((element) => element.dataset.nodeId === node.id);
1408
+ const size = (card === null || card === void 0 ? void 0 : card.offsetWidth) && card.offsetHeight
1409
+ ? { width: card.offsetWidth, height: card.offsetHeight }
1410
+ : nodeSize(node);
1411
+ const rect = canvas.getBoundingClientRect();
1412
+ const { zoom: current } = viewRef.current;
1413
+ const phone = isPhone();
1414
+ const besidePanel = rect.width - PANEL_COVER;
1415
+ const right = !phone && besidePanel >= size.width * current ? besidePanel : rect.width;
1416
+ const top = phone ? PHONE_TOP_INSET : 0;
1417
+ const bottom = Math.max(top, rect.height - TOOLBAR_CLEARANCE);
1418
+ setView(current, {
1419
+ x: right / 2 - (node.position.x + size.width / 2) * current,
1420
+ y: (top + bottom) / 2 - (node.position.y + size.height / 2) * current,
1421
+ });
1422
+ setNodes((prev) => prev.map((n) => ({ ...n, selected: n.id === node.id })));
1423
+ setSelectedEdgeId(null);
1424
+ setSelectedNodeForConfig(node.id);
1425
+ setFocusTarget({ nodeId: node.id, pending: focusRequest.field });
1426
+ }, [focusRequest, previewMode, setView]);
1427
+ useEffect(() => {
1428
+ if (!focusTarget || focusTarget.pending === undefined)
1429
+ return;
1430
+ setFocusTarget({ nodeId: focusTarget.nodeId, field: focusTarget.pending });
1431
+ }, [focusTarget]);
1432
+ useEffect(() => {
1433
+ setFocusTarget((current) => current && current.nodeId !== selectedNodeForConfig ? null : current);
1434
+ }, [selectedNodeForConfig]);
901
1435
  useEffect(() => {
902
1436
  if (onStateChange && !previewMode) {
903
1437
  // Strip UI-only properties for comparison to avoid triggering on selection changes
@@ -921,13 +1455,29 @@ function WorkflowCanvas({ onDraggedItem: _onDraggedItem, onClickedItem, previewM
921
1455
  }, [nodes, edges, zoom, panOffset, previewMode, onStateChange]);
922
1456
  const workflowVariables = useMemo(() => collectWorkflowVariables(nodes), [nodes]);
923
1457
  const variableUsages = useMemo(() => collectVariableUsages(nodes), [nodes]);
1458
+ const isOutputConnected = (nodeId, handle) => edges.some((edge) => edge.source === nodeId && (edge.sourceHandle || 'right') === handle);
1459
+ const unconnectedNote = (nodeId, handle) => previewMode || isOutputConnected(nodeId, handle) ? null : (jsx("span", { "data-testid": `workflow-branch-unconnected-${nodeId}-${handle}`, className: "text-muted-foreground text-xs", children: t('workflowsWorkflowCanvas.notConnected') }));
1460
+ const classifierRowLabel = (branch) => {
1461
+ switch (branch.kind) {
1462
+ case 'yes':
1463
+ return t('workflowsWorkflowCanvas.classifierYes');
1464
+ case 'no':
1465
+ return t('workflowsWorkflowCanvas.classifierNo');
1466
+ case 'next':
1467
+ return t('workflowsWorkflowCanvas.classifierNext');
1468
+ case 'fallback':
1469
+ return t('workflowsWorkflowCanvas.classifierFallback');
1470
+ default:
1471
+ return branch.label;
1472
+ }
1473
+ };
924
1474
  const edgeGeometry = edges.flatMap((edge) => {
925
1475
  const fromNode = nodes.find((n) => n.id === edge.source);
926
1476
  const toNode = nodes.find((n) => n.id === edge.target);
927
1477
  if (!fromNode || !toNode)
928
1478
  return [];
929
1479
  const from = getHandlePosition(fromNode, edge.sourceHandle || 'right');
930
- const to = getHandlePosition(toNode, edge.targetHandle || 'left');
1480
+ const to = getHandlePosition(toNode, edge.targetHandle || 'left', 'target');
931
1481
  // getConnectionPath's control points mirror each other, so the curve
932
1482
  // passes through the plain midpoint of its ends.
933
1483
  const midpoint = { x: (from.x + to.x) / 2, y: (from.y + to.y) / 2 };
@@ -938,14 +1488,21 @@ function WorkflowCanvas({ onDraggedItem: _onDraggedItem, onClickedItem, previewM
938
1488
  : undefined;
939
1489
  const activeMentorId = (_a = activeMentorNode === null || activeMentorNode === void 0 ? void 0 : activeMentorNode.data.mentor_id) !== null && _a !== void 0 ? _a : activeMentorNode === null || activeMentorNode === void 0 ? void 0 : activeMentorNode.data.entry_mentor_id;
940
1490
  const selectedMentorIds = activeMentorId ? [activeMentorId] : [];
941
- return (jsxs("div", { ref: rootRef, onMouseDownCapture: (e) => {
942
- var _a;
1491
+ return (jsxs("div", { ref: rootRef, onPointerDownCapture: (e) => {
1492
+ var _a, _b, _c;
943
1493
  const target = e.target;
944
1494
  canvasHasPointerRef.current =
945
1495
  !!((_a = rootRef.current) === null || _a === void 0 ? void 0 : _a.contains(target)) && !target.closest(NODE_PANEL_SELECTOR);
946
- }, "data-testid": "workflow-canvas", className: "bg-background relative h-full w-full overflow-hidden select-none", children: [jsxs("div", { ref: canvasRef, className: `absolute inset-0 ${tool === 'hand' ? (isPanning ? 'cursor-grabbing' : 'cursor-grab') : 'cursor-default'}`, onMouseDown: handleCanvasMouseDown, onDrop: handleDrop, onDragOver: handleDragOver, children: [jsxs("svg", { className: "pointer-events-none h-full w-full", children: [jsx("defs", { children: jsx("pattern", { id: "grid", width: "20", height: "20", patternUnits: "userSpaceOnUse", children: jsx("circle", { cx: "1", cy: "1", r: "0.5", fill: "hsl(var(--muted-foreground) / 0.2)" }) }) }), jsx("rect", { width: "100%", height: "100%", fill: "url(#grid)" }), jsxs("g", { transform: `translate(${panOffset.x}, ${panOffset.y}) scale(${zoom})`, children: [edgeGeometry.map(({ edge, path }) => {
1496
+ // A press on this unselectable surface keeps a text selection made
1497
+ // elsewhere, which Cmd+C would then copy instead of the steps.
1498
+ if (canvasHasPointerRef.current && !target.closest(TEXT_ENTRY_SELECTOR)) {
1499
+ (_c = (_b = window.getSelection) === null || _b === void 0 ? void 0 : _b.call(window)) === null || _c === void 0 ? void 0 : _c.removeAllRanges();
1500
+ }
1501
+ pressedRef.current = null;
1502
+ tappedNodeRef.current = null;
1503
+ }, "data-testid": "workflow-canvas", className: "bg-background relative h-full w-full overflow-hidden select-none", children: [jsxs("div", { ref: canvasRef, className: `absolute inset-0 touch-none ${tool === 'hand' ? (isPanning ? 'cursor-grabbing' : 'cursor-grab') : 'cursor-default'}`, onPointerDownCapture: handleTouchPointerDown, onPointerDown: handleCanvasPointerDown, onDrop: handleDrop, onDragOver: handleDragOver, children: [jsxs("svg", { className: "pointer-events-none h-full w-full", children: [jsx("defs", { children: jsx("pattern", { id: "grid", width: "20", height: "20", patternUnits: "userSpaceOnUse", children: jsx("circle", { cx: "1", cy: "1", r: "0.5", fill: "hsl(var(--muted-foreground) / 0.2)" }) }) }), jsx("rect", { width: "100%", height: "100%", fill: "url(#grid)" }), jsxs("g", { transform: `translate(${panOffset.x}, ${panOffset.y}) scale(${zoom})`, children: [edgeGeometry.map(({ edge, path }) => {
947
1504
  const isActive = !previewMode && (edge.id === selectedEdgeId || edge.id === hoveredEdgeId);
948
- return (jsxs("g", { children: [jsx("path", { d: path, stroke: isActive ? '#1D7FC0' : '#38A1E5', strokeWidth: isActive ? 3 : 2, fill: "none", strokeLinecap: "round" }), !previewMode && (jsx("path", { "data-testid": `workflow-edge-${edge.id}`, d: path, stroke: "transparent", strokeWidth: 16, fill: "none", className: "cursor-pointer", style: { pointerEvents: 'stroke' }, onMouseDown: (e) => {
1505
+ return (jsxs("g", { children: [jsx("path", { d: path, stroke: isActive ? '#1D7FC0' : '#38A1E5', strokeWidth: isActive ? 3 : 2, fill: "none", strokeLinecap: "round" }), !previewMode && (jsx("path", { "data-testid": `workflow-edge-${edge.id}`, d: path, stroke: "transparent", strokeWidth: 16, fill: "none", className: "cursor-pointer pointer-coarse:[stroke-width:32px]", style: { pointerEvents: 'stroke' }, onPointerDown: (e) => {
949
1506
  if (e.button !== 0)
950
1507
  return;
951
1508
  e.stopPropagation();
@@ -963,55 +1520,94 @@ function WorkflowCanvas({ onDraggedItem: _onDraggedItem, onClickedItem, previewM
963
1520
  transform: `translate(${panOffset.x}px, ${panOffset.y}px) scale(${zoom})`,
964
1521
  transformOrigin: '0 0',
965
1522
  }, children: [!previewMode &&
966
- edgeGeometry.map(({ edge, midpoint }) => edge.id === selectedEdgeId || edge.id === hoveredEdgeId ? (jsx(ActionTooltip, { label: t('workflowsWorkflowCanvas.deleteConnection'), children: jsx("button", { type: "button", "aria-label": t('workflowsWorkflowCanvas.deleteConnection'), "data-testid": `workflow-edge-delete-${edge.id}`, className: "bg-card border-border text-muted-foreground hover:text-destructive pointer-events-auto absolute z-10 flex h-6 w-6 -translate-x-1/2 -translate-y-1/2 cursor-pointer items-center justify-center rounded-full border shadow-sm", style: { left: `${midpoint.x}px`, top: `${midpoint.y}px` }, onMouseDown: (e) => e.stopPropagation(), onMouseEnter: () => setHoveredEdgeId(edge.id), onMouseLeave: () => setHoveredEdgeId(null), onClick: (e) => {
1523
+ edgeGeometry.map(({ edge, midpoint }) => edge.id === selectedEdgeId || edge.id === hoveredEdgeId ? (jsx(ActionTooltip, { label: t('workflowsWorkflowCanvas.deleteConnection'), children: jsx("button", { type: "button", "aria-label": t('workflowsWorkflowCanvas.deleteConnection'), "data-testid": `workflow-edge-delete-${edge.id}`, className: "bg-card border-border text-muted-foreground hover:text-destructive pointer-events-auto absolute z-10 flex h-6 w-6 -translate-x-1/2 -translate-y-1/2 cursor-pointer items-center justify-center rounded-full border shadow-sm pointer-coarse:size-9", style: { left: `${midpoint.x}px`, top: `${midpoint.y}px` }, onPointerDown: notePress, onMouseEnter: () => setHoveredEdgeId(edge.id), onMouseLeave: () => setHoveredEdgeId(null), onClick: (e) => {
1524
+ if (!wasPressed(e))
1525
+ return;
967
1526
  e.stopPropagation();
968
1527
  deleteEdge(edge.id);
969
- }, children: jsx(X, { className: "h-3.5 w-3.5" }) }) }, edge.id)) : null), nodes.map((node) => (jsxs("div", { "data-testid": `workflow-node-${node.id}`, "data-node-type": node.type, className: `group pointer-events-auto absolute ${node.selected ? 'ring-offset-background rounded-xl ring-2 ring-[#38A1E5] ring-offset-2' : ''}`, style: {
1528
+ }, children: jsx(X, { className: "h-3.5 w-3.5" }) }) }, edge.id)) : null), nodes.map((node) => (jsxs("div", { "data-testid": `workflow-node-${node.id}`, "data-node-id": node.id, "data-node-type": node.type, className: `group pointer-events-auto absolute ${node.selected ? 'ring-offset-background rounded-xl ring-2 ring-[#38A1E5] ring-offset-2' : ''}`, style: {
970
1529
  left: `${node.position.x}px`,
971
1530
  top: `${node.position.y}px`,
972
- }, onMouseDown: (e) => {
1531
+ }, onPointerDown: (e) => {
973
1532
  if (node.type !== 'note' || !editingNote) {
974
- handleNodeMouseDown(e, node.id);
1533
+ handleNodePointerDown(e, node.id);
975
1534
  }
976
- }, onMouseEnter: () => setHoveredNode(node.id), onMouseLeave: () => setHoveredNode(null), children: [!previewMode && isDeletableNode(node) && (jsx(ActionTooltip, { label: t('workflowsWorkflowCanvas.deleteNode', { label: node.data.label }), children: jsx("button", { type: "button", "aria-label": t('workflowsWorkflowCanvas.deleteNode', { label: node.data.label }), className: `bg-card border-border text-muted-foreground hover:text-destructive absolute -top-3 -right-3 z-10 flex h-6 w-6 cursor-pointer items-center justify-center rounded-full border shadow-sm transition-opacity group-hover:opacity-100 focus-visible:opacity-100 ${node.selected ? 'opacity-100' : 'opacity-0'}`, onMouseDown: (e) => e.stopPropagation(), onClick: (e) => {
977
- e.stopPropagation();
978
- deleteNodes([node.id]);
979
- }, children: jsx(Trash2, { className: "h-3.5 w-3.5" }) }) })), node.type === 'start' ? (jsxs("div", { className: "bg-card border-border relative flex cursor-grab items-center gap-3 rounded-xl border px-4 py-3 transition-colors hover:border-[#38A1E5] active:cursor-grabbing", children: [jsx("div", { className: "flex h-6 w-6 items-center justify-center rounded", style: { backgroundColor: 'rgba(56, 161, 229, 0.2)' }, children: jsx(Play, { className: "h-4 w-4", style: { color: '#38A1E5' } }) }), jsx("span", { className: "text-foreground font-medium", children: node.data.label }), jsx("div", { className: "border-background absolute top-1/2 -right-2 h-3 w-3 -translate-y-1/2 cursor-crosshair rounded-full border-2 opacity-0 transition-opacity group-hover:opacity-100", style: { backgroundColor: '#38A1E5' }, onMouseDown: (e) => handleConnectionStart(e, node.id, 'right') })] })) : node.type === 'while' ? (jsxs("div", { className: "border-border bg-card relative cursor-grab rounded-2xl border transition-colors hover:border-[#38A1E5] active:cursor-grabbing", style: { width: '280px' }, children: [jsxs("div", { className: "flex items-center gap-3 p-4 pb-3", children: [jsx("div", { className: "flex h-10 w-10 items-center justify-center rounded-lg", style: { backgroundColor: 'rgba(56, 161, 229, 0.2)' }, children: jsx(RefreshCw, { className: "h-5 w-5", style: { color: '#38A1E5' } }) }), jsx("span", { className: "text-foreground font-medium", children: node.data.label })] }), jsx("div", { className: "space-y-2 px-4 pb-4", children: [
1535
+ }, onClick: () => {
1536
+ if (tappedNodeRef.current !== node.id)
1537
+ return;
1538
+ tappedNodeRef.current = null;
1539
+ setSelectedNodeForConfig(node.id);
1540
+ }, onMouseEnter: () => setHoveredNode(node.id), onMouseLeave: () => setHoveredNode(null), children: [!previewMode && (isDeletableNode(node) || stepHasResult(node.type)) && (jsxs("div", { className: "absolute -top-3 -right-3 z-10 flex gap-1", children: [stepHasResult(node.type) && (jsx(ActionTooltip, { label: t('workflowsNodeConfigPanel.copyPlaceholder', {
1541
+ placeholder: stepPlaceholder(node.id),
1542
+ }), children: jsx("button", { type: "button", "aria-label": t('workflowsNodeConfigPanel.copyPlaceholder', {
1543
+ placeholder: stepPlaceholder(node.id),
1544
+ }), className: `${CARD_ACTION} hover:text-foreground ${cardActionVisibility(node.selected)}`, onPointerDown: notePress, onClick: (e) => {
1545
+ if (!wasPressed(e))
1546
+ return;
1547
+ e.stopPropagation();
1548
+ void copyToClipboard(stepPlaceholder(node.id));
1549
+ setCopiedNodeId(node.id);
1550
+ }, children: copyStatus === 'success' && copiedNodeId === node.id ? (jsx(Check, { className: "h-3.5 w-3.5" })) : (jsx(Copy, { className: "h-3.5 w-3.5" })) }) })), isDeletableNode(node) && (jsx(ActionTooltip, { label: withShortcut(t('workflowsWorkflowCanvas.deleteNode', { label: node.data.label }), 'delete'), children: jsx("button", { type: "button", "aria-label": t('workflowsWorkflowCanvas.deleteNode', {
1551
+ label: node.data.label,
1552
+ }), "aria-keyshortcuts": ariaShortcut('delete'), className: `${CARD_ACTION} hover:text-destructive ${cardActionVisibility(node.selected)}`, onPointerDown: notePress, onClick: (e) => {
1553
+ if (!wasPressed(e))
1554
+ return;
1555
+ e.stopPropagation();
1556
+ deleteNodes([node.id]);
1557
+ }, children: jsx(Trash2, { className: "h-3.5 w-3.5" }) }) }))] })), node.type === 'start' ? (jsxs("div", { className: "bg-card border-border relative flex cursor-grab items-center gap-3 rounded-xl border px-4 py-3 transition-colors hover:border-[#38A1E5] active:cursor-grabbing", children: [jsx("div", { className: "flex h-6 w-6 items-center justify-center rounded", style: { backgroundColor: 'rgba(56, 161, 229, 0.2)' }, children: jsx(Play, { className: "h-4 w-4", style: { color: '#38A1E5' } }) }), jsx("span", { className: "text-foreground font-medium", children: node.data.label }), jsx("div", { className: RIGHT_DOT, style: { backgroundColor: '#38A1E5' }, onPointerDown: (e) => handleConnectionStart(e, node.id, 'right') })] })) : node.type === 'while' ? (jsxs("div", { className: "border-border bg-card relative cursor-grab rounded-2xl border transition-colors hover:border-[#38A1E5] active:cursor-grabbing", style: { width: '280px' }, children: [jsxs("div", { className: "flex items-center gap-3 p-4 pb-3", children: [jsx("div", { className: "flex h-10 w-10 items-center justify-center rounded-lg", style: { backgroundColor: 'rgba(56, 161, 229, 0.2)' }, children: jsx(RefreshCw, { className: "h-5 w-5", style: { color: '#38A1E5' } }) }), jsx("span", { className: "text-foreground font-medium", children: node.data.label })] }), jsx("div", { className: "space-y-2 px-4 pb-4", children: [
980
1558
  { handle: WHILE_LOOP_HANDLE, label: t('workflowsWorkflowCanvas.whileLoop') },
981
1559
  { handle: WHILE_DONE_HANDLE, label: t('workflowsWorkflowCanvas.whileDone') },
982
- ].map(({ handle, label }) => (jsxs("div", { className: "bg-muted/50 relative flex items-center justify-between rounded-lg px-4 py-3", children: [jsx("span", { className: "text-muted-foreground text-sm", children: label }), jsx("div", { "data-testid": `workflow-handle-${node.id}-${handle}`, className: "border-background absolute top-1/2 -right-[18px] h-3 w-3 -translate-y-1/2 cursor-crosshair rounded-full border-2 opacity-0 transition-opacity group-hover:opacity-100", style: { backgroundColor: '#38A1E5' }, onMouseDown: (e) => handleConnectionStart(e, node.id, handle) })] }, handle))) }), jsx("div", { className: "border-background absolute top-1/2 -left-2 h-3 w-3 -translate-y-1/2 rounded-full border-2 opacity-0 transition-opacity group-hover:opacity-100", style: { backgroundColor: '#38A1E5' } })] })) : isConditionalType(node.type) ? ((() => {
1560
+ ].map(({ handle, label }) => (jsxs("div", { className: "bg-muted/50 relative flex items-center justify-between rounded-lg px-4 py-3", children: [jsx("span", { className: "text-muted-foreground text-sm", children: label }), unconnectedNote(node.id, handle), jsx("div", { "data-testid": `workflow-handle-${node.id}-${handle}`, className: ROW_DOT, style: { backgroundColor: '#38A1E5' }, onPointerDown: (e) => handleConnectionStart(e, node.id, handle) })] }, handle))) }), jsx("div", { className: `${INPUT_DOT} top-1/2 -left-2 -translate-y-1/2`, style: { backgroundColor: '#38A1E5' } })] })) : isConditionalType(node.type) ? ((() => {
983
1561
  const conditionCount = getConditionCount(node.data);
984
1562
  const nodeHeight = branchCardHeight(conditionCount + 1);
985
1563
  return (jsxs("div", { className: "border-border bg-card relative cursor-grab rounded-2xl border transition-colors hover:border-[#38A1E5] active:cursor-grabbing", style: { width: '280px', minHeight: `${nodeHeight}px` }, children: [jsxs("div", { className: "flex items-center gap-3 p-4 pb-3", children: [jsx("div", { className: "flex h-10 w-10 items-center justify-center rounded-lg", style: { backgroundColor: 'rgba(56, 161, 229, 0.2)' }, children: jsx(GitBranch, { className: "h-5 w-5", style: { color: '#38A1E5' } }) }), jsx("span", { className: "text-foreground font-medium", children: node.data.label })] }), jsxs("div", { className: "space-y-2 px-4 pb-4", children: [Array.from({ length: conditionCount }).map((_, index) => (jsxs("div", { className: "bg-muted/50 relative flex items-center justify-between rounded-lg px-4 py-3", children: [jsx("span", { className: "text-muted-foreground text-sm", children: index === 0
986
1564
  ? t('workflowsWorkflowCanvas.ifCondition')
987
- : t('workflowsWorkflowCanvas.elseIf', { index }) }), jsx("div", { "data-testid": `workflow-handle-${node.id}-condition-${index}`, className: "border-background absolute top-1/2 -right-[18px] h-3 w-3 -translate-y-1/2 cursor-crosshair rounded-full border-2 opacity-0 transition-opacity group-hover:opacity-100", style: { backgroundColor: '#38A1E5' }, onMouseDown: (e) => handleConnectionStart(e, node.id, `condition-${index}`) })] }, index))), jsxs("div", { className: "bg-muted/50 relative flex items-center justify-between rounded-lg px-4 py-3", children: [jsx("span", { className: "text-muted-foreground text-sm", children: t('workflowsWorkflowCanvas.elseCondition') }), jsx("div", { "data-testid": `workflow-handle-${node.id}-else`, className: "border-background absolute top-1/2 -right-[18px] h-3 w-3 -translate-y-1/2 cursor-crosshair rounded-full border-2 opacity-0 transition-opacity group-hover:opacity-100", style: { backgroundColor: '#38A1E5' }, onMouseDown: (e) => handleConnectionStart(e, node.id, 'else') })] })] }), jsx("div", { className: "border-background absolute top-1/2 -left-2 h-3 w-3 -translate-y-1/2 rounded-full border-2 opacity-0 transition-opacity group-hover:opacity-100", style: { backgroundColor: '#38A1E5' } })] }));
988
- })()) : node.type === 'user-approval' ? (jsxs("div", { className: "border-border bg-card relative cursor-grab rounded-2xl border transition-colors hover:border-[#38A1E5] active:cursor-grabbing", style: { width: '280px' }, children: [jsxs("div", { className: "flex items-center gap-3 p-4 pb-3", children: [jsx("div", { className: "flex h-10 w-10 items-center justify-center rounded-lg", style: { backgroundColor: 'rgba(56, 161, 229, 0.2)' }, children: jsx(ThumbsUp, { className: "h-5 w-5", style: { color: '#38A1E5' } }) }), jsx("span", { className: "text-foreground font-medium", children: node.data.label })] }), jsxs("div", { className: "space-y-2 px-4 pb-4", children: [jsxs("div", { className: "bg-muted/50 relative flex items-center justify-between rounded-lg px-4 py-3", children: [jsx("span", { className: "text-muted-foreground text-sm", children: t('workflowsWorkflowCanvas.approve') }), jsx("div", { className: "border-background absolute top-1/2 -right-[18px] h-3 w-3 -translate-y-1/2 cursor-crosshair rounded-full border-2 opacity-0 transition-opacity group-hover:opacity-100", style: { backgroundColor: '#38A1E5' }, onMouseDown: (e) => handleConnectionStart(e, node.id, 'approve') })] }), jsxs("div", { className: "bg-muted/50 relative flex items-center justify-between rounded-lg px-4 py-3", children: [jsx("span", { className: "text-muted-foreground text-sm", children: t('workflowsWorkflowCanvas.reject') }), jsx("div", { className: "border-background absolute top-1/2 -right-[18px] h-3 w-3 -translate-y-1/2 cursor-crosshair rounded-full border-2 opacity-0 transition-opacity group-hover:opacity-100", style: { backgroundColor: '#38A1E5' }, onMouseDown: (e) => handleConnectionStart(e, node.id, 'reject') })] })] }), jsx("div", { className: "border-background absolute top-1/2 -left-2 h-3 w-3 -translate-y-1/2 rounded-full border-2 opacity-0 transition-opacity group-hover:opacity-100", style: { backgroundColor: '#38A1E5' } })] })) : node.type === 'transform' ||
1565
+ : t('workflowsWorkflowCanvas.elseIf', { index }) }), unconnectedNote(node.id, `condition-${index}`), jsx("div", { "data-testid": `workflow-handle-${node.id}-condition-${index}`, className: ROW_DOT, style: { backgroundColor: '#38A1E5' }, onPointerDown: (e) => handleConnectionStart(e, node.id, `condition-${index}`) })] }, index))), jsxs("div", { className: "bg-muted/50 relative flex items-center justify-between rounded-lg px-4 py-3", children: [jsx("span", { className: "text-muted-foreground text-sm", children: t('workflowsWorkflowCanvas.elseCondition') }), unconnectedNote(node.id, 'else'), jsx("div", { "data-testid": `workflow-handle-${node.id}-else`, className: ROW_DOT, style: { backgroundColor: '#38A1E5' }, onPointerDown: (e) => handleConnectionStart(e, node.id, 'else') })] })] }), jsx("div", { className: `${INPUT_DOT} top-1/2 -left-2 -translate-y-1/2`, style: { backgroundColor: '#38A1E5' } })] }));
1566
+ })()) : isClassifierType(node.type) ? ((() => {
1567
+ const branches = classifierBranches(node.data);
1568
+ return (jsxs("div", { className: "border-border bg-card relative cursor-grab rounded-2xl border transition-colors hover:border-[#38A1E5] active:cursor-grabbing", style: {
1569
+ width: '280px',
1570
+ minHeight: `${branchCardHeight(branches.length)}px`,
1571
+ }, children: [jsxs("div", { className: "flex items-center gap-3 p-4 pb-3", children: [jsx("div", { className: "flex h-10 w-10 shrink-0 items-center justify-center rounded-lg", style: { backgroundColor: 'rgba(56, 161, 229, 0.2)' }, children: jsx(Split, { className: "h-5 w-5", style: { color: '#38A1E5' } }) }), jsx(ActionTooltip, { label: node.data.label, children: jsx("span", { className: "text-foreground min-w-0 truncate font-medium", children: node.data.label }) })] }), jsx("div", { className: "space-y-2 px-4 pb-4", children: branches.map((branch) => {
1572
+ const rowLabel = (jsx("span", { className: "text-muted-foreground min-w-0 flex-1 truncate text-sm", children: classifierRowLabel(branch) }));
1573
+ return (jsxs("div", { className: "bg-muted/50 relative flex items-center justify-between gap-2 rounded-lg px-4 py-3", children: [branch.kind === 'category' && branch.label ? (jsx(ActionTooltip, { label: branch.label, children: rowLabel })) : (rowLabel), unconnectedNote(node.id, branch.handle), jsx("div", { "data-testid": `workflow-handle-${node.id}-${branch.handle}`, className: ROW_DOT, style: { backgroundColor: '#38A1E5' }, onPointerDown: (e) => handleConnectionStart(e, node.id, branch.handle) })] }, branch.handle));
1574
+ }) }), jsx("div", { className: `${INPUT_DOT} top-1/2 -left-2 -translate-y-1/2`, style: { backgroundColor: '#38A1E5' } })] }));
1575
+ })()) : node.type === 'user-approval' ? (jsxs("div", { className: "border-border bg-card relative cursor-grab rounded-2xl border transition-colors hover:border-[#38A1E5] active:cursor-grabbing", style: { width: '280px' }, children: [jsxs("div", { className: "flex items-center gap-3 p-4 pb-3", children: [jsx("div", { className: "flex h-10 w-10 items-center justify-center rounded-lg", style: { backgroundColor: 'rgba(56, 161, 229, 0.2)' }, children: jsx(ThumbsUp, { className: "h-5 w-5", style: { color: '#38A1E5' } }) }), jsx("span", { className: "text-foreground font-medium", children: node.data.label })] }), jsxs("div", { className: "space-y-2 px-4 pb-4", children: [jsxs("div", { className: "bg-muted/50 relative flex items-center justify-between rounded-lg px-4 py-3", children: [jsx("span", { className: "text-muted-foreground text-sm", children: t('workflowsWorkflowCanvas.approve') }), jsx("div", { className: ROW_DOT, style: { backgroundColor: '#38A1E5' }, onPointerDown: (e) => handleConnectionStart(e, node.id, 'approve') })] }), jsxs("div", { className: "bg-muted/50 relative flex items-center justify-between rounded-lg px-4 py-3", children: [jsx("span", { className: "text-muted-foreground text-sm", children: t('workflowsWorkflowCanvas.reject') }), jsx("div", { className: ROW_DOT, style: { backgroundColor: '#38A1E5' }, onPointerDown: (e) => handleConnectionStart(e, node.id, 'reject') })] })] }), jsx("div", { className: `${INPUT_DOT} top-1/2 -left-2 -translate-y-1/2`, style: { backgroundColor: '#38A1E5' } })] })) : node.type === 'transform' ||
989
1576
  node.type === 'set-state' ||
990
1577
  node.type === 'guardrails' ||
991
1578
  node.type === 'file-search' ||
992
- node.type === 'mcp' ? (jsxs("div", { className: "bg-card border-border relative min-w-[140px] cursor-grab rounded-xl border px-4 py-3 transition-colors hover:border-[#38A1E5] active:cursor-grabbing", children: [jsxs("div", { className: "flex items-center gap-2", children: [jsx("div", { className: "flex h-5 w-5 items-center justify-center rounded", style: { backgroundColor: 'rgba(56, 161, 229, 0.2)' }, children: jsx(Bot, { className: "h-3 w-3", style: { color: '#38A1E5' } }) }), jsx("span", { className: "text-foreground text-sm font-medium", children: node.data.label })] }), jsx("div", { className: "border-background absolute top-1/2 -left-2 h-3 w-3 -translate-y-1/2 rounded-full border-2 opacity-0 transition-opacity group-hover:opacity-100", style: { backgroundColor: '#38A1E5' } }), jsx("div", { className: "border-background absolute top-1/2 -right-2 h-3 w-3 -translate-y-1/2 cursor-crosshair rounded-full border-2 opacity-0 transition-opacity group-hover:opacity-100", style: { backgroundColor: '#38A1E5' }, onMouseDown: (e) => handleConnectionStart(e, node.id, 'right') }), jsx("div", { className: "border-background absolute -top-2 left-1/2 h-3 w-3 -translate-x-1/2 cursor-crosshair rounded-full border-2 opacity-0 transition-opacity group-hover:opacity-100", style: { backgroundColor: '#38A1E5' }, onMouseDown: (e) => handleConnectionStart(e, node.id, 'top') }), jsx("div", { className: "border-background absolute -bottom-2 left-1/2 h-3 w-3 -translate-x-1/2 cursor-crosshair rounded-full border-2 opacity-0 transition-opacity group-hover:opacity-100", style: { backgroundColor: '#38A1E5' }, onMouseDown: (e) => handleConnectionStart(e, node.id, 'bottom') })] })) : node.type === 'note' ? (jsxs("div", { className: "border-border relative cursor-grab rounded-lg border bg-amber-50 transition-colors hover:border-[#38A1E5] active:cursor-grabbing dark:bg-amber-950/20", style: {
1579
+ node.type === 'mcp' ? (jsxs("div", { className: "bg-card border-border relative min-w-[140px] cursor-grab rounded-xl border px-4 py-3 transition-colors hover:border-[#38A1E5] active:cursor-grabbing", children: [jsxs("div", { className: "flex items-center gap-2", children: [jsx("div", { className: "flex h-5 w-5 items-center justify-center rounded", style: { backgroundColor: 'rgba(56, 161, 229, 0.2)' }, children: jsx(Bot, { className: "h-3 w-3", style: { color: '#38A1E5' } }) }), jsx("span", { className: "text-foreground text-sm font-medium", children: node.data.label })] }), jsx("div", { className: `${INPUT_DOT} top-1/2 -left-2 -translate-y-1/2`, style: { backgroundColor: '#38A1E5' } }), jsx("div", { className: RIGHT_DOT, style: { backgroundColor: '#38A1E5' }, onPointerDown: (e) => handleConnectionStart(e, node.id, 'right') }), jsx("div", { className: TOP_DOT, style: { backgroundColor: '#38A1E5' }, onPointerDown: (e) => handleConnectionStart(e, node.id, 'top') }), jsx("div", { className: BOTTOM_DOT, style: { backgroundColor: '#38A1E5' }, onPointerDown: (e) => handleConnectionStart(e, node.id, 'bottom') })] })) : node.type === 'note' ? (jsxs("div", { className: "border-border relative cursor-grab rounded-lg border bg-amber-50 transition-colors hover:border-[#38A1E5] active:cursor-grabbing dark:bg-amber-950/20", style: {
993
1580
  width: `${node.width || 200}px`,
994
1581
  height: `${node.height || 120}px`,
995
1582
  }, onClick: (e) => {
996
1583
  e.stopPropagation();
997
1584
  setEditingNote(node.id);
998
- }, children: [editingNote === node.id ? (jsx(Textarea, { autoFocus: true, className: "h-full w-full resize-none border-0 bg-transparent text-sm focus-visible:ring-0", value: node.data.content || '', onChange: (e) => {
1585
+ }, children: [editingNote === node.id ? (jsx(WorkflowTextarea, { autoFocus: true, className: "h-full w-full resize-none border-0 bg-transparent text-sm focus-visible:ring-0", value: node.data.content || '', onChange: (e) => {
999
1586
  setNodes((prev) => prev.map((n) => n.id === node.id
1000
1587
  ? {
1001
1588
  ...n,
1002
1589
  data: { ...n.data, content: e.target.value },
1003
1590
  }
1004
1591
  : n));
1005
- }, onBlur: () => setEditingNote(null) })) : (jsx("div", { className: "text-foreground p-3 text-sm whitespace-pre-wrap", children: node.data.content || t('workflowsWorkflowCanvas.stickyNote') })), jsx("div", { className: "border-background absolute -right-1 -bottom-1 h-4 w-4 cursor-nwse-resize rounded-full border-2 opacity-0 transition-opacity group-hover:opacity-100", style: { backgroundColor: '#38A1E5' }, onMouseDown: (e) => handleResizeStart(e, node.id, 'bottom-right') })] })) : (jsxs("div", { className: "bg-card border-border relative min-w-[140px] cursor-grab rounded-xl border px-4 py-3 transition-colors hover:border-[#38A1E5] active:cursor-grabbing", children: [jsxs("div", { className: "mb-1 flex items-center gap-2", children: [jsx("div", { className: "flex h-5 w-5 items-center justify-center rounded", style: { backgroundColor: 'rgba(56, 161, 229, 0.2)' }, children: jsx(Bot, { className: "h-3 w-3", style: { color: '#38A1E5' } }) }), jsx("span", { className: "text-foreground text-sm font-medium", children: node.data.label }), node.type === 'mentor' && !previewMode && (jsx(ActionTooltip, { label: t('workflowsWorkflowCanvas.changeAgent'), children: jsx("button", { type: "button", "aria-label": t('workflowsWorkflowCanvas.changeAgent'), className: "text-muted-foreground hover:text-foreground ml-auto cursor-pointer p-1 transition-colors", onMouseDown: (e) => e.stopPropagation(), onClick: (e) => {
1592
+ }, onBlur: () => setEditingNote(null) })) : (jsx("div", { className: "text-foreground p-3 text-sm whitespace-pre-wrap", children: node.data.content || t('workflowsWorkflowCanvas.stickyNote') })), jsx("div", { className: `border-background absolute -right-1 -bottom-1 h-4 w-4 cursor-nwse-resize rounded-full border-2 opacity-0 transition-opacity group-hover:opacity-100 pointer-coarse:opacity-100 ${RESIZE_TARGET}`, style: { backgroundColor: '#38A1E5' }, onPointerDown: (e) => handleResizeStart(e, node.id, 'bottom-right') })] })) : (jsxs("div", { className: "bg-card border-border relative min-w-[140px] cursor-grab rounded-xl border px-4 py-3 transition-colors hover:border-[#38A1E5] active:cursor-grabbing", children: [jsxs("div", { className: "mb-1 flex items-center gap-2", children: [jsx("div", { className: "flex h-5 w-5 items-center justify-center rounded", style: { backgroundColor: 'rgba(56, 161, 229, 0.2)' }, children: jsx(Bot, { className: "h-3 w-3", style: { color: '#38A1E5' } }) }), jsx("span", { className: "text-foreground text-sm font-medium", children: node.data.label }), node.type === 'mentor' && !previewMode && (jsx(ActionTooltip, { label: t('workflowsWorkflowCanvas.changeAgent'), children: jsx("button", { type: "button", "aria-label": t('workflowsWorkflowCanvas.changeAgent'), className: `text-muted-foreground hover:text-foreground ml-auto cursor-pointer p-1 transition-colors ${ICON_TOUCH_TARGET}`, onPointerDown: (e) => e.stopPropagation(), onClick: (e) => {
1006
1593
  e.stopPropagation();
1007
1594
  handleMentorChangeClick(node.id);
1008
- }, children: jsx(Pencil, { className: "h-3.5 w-3.5" }) }) }))] }), node.data.subtitle && (jsx("p", { className: "text-muted-foreground ml-7 text-xs", children: node.data.subtitle })), jsx("div", { className: "border-background absolute top-1/2 -left-2 h-3 w-3 -translate-y-1/2 rounded-full border-2 opacity-0 transition-opacity group-hover:opacity-100", style: { backgroundColor: '#38A1E5' } }), jsx("div", { className: "border-background absolute top-1/2 -right-2 h-3 w-3 -translate-y-1/2 cursor-crosshair rounded-full border-2 opacity-0 transition-opacity group-hover:opacity-100", style: { backgroundColor: '#38A1E5' }, onMouseDown: (e) => handleConnectionStart(e, node.id, 'right') }), jsx("div", { className: "border-background absolute -top-2 left-1/2 h-3 w-3 -translate-x-1/2 cursor-crosshair rounded-full border-2 opacity-0 transition-opacity group-hover:opacity-100", style: { backgroundColor: '#38A1E5' }, onMouseDown: (e) => handleConnectionStart(e, node.id, 'top') }), jsx("div", { className: "border-background absolute -bottom-2 left-1/2 h-3 w-3 -translate-x-1/2 cursor-crosshair rounded-full border-2 opacity-0 transition-opacity group-hover:opacity-100", style: { backgroundColor: '#38A1E5' }, onMouseDown: (e) => handleConnectionStart(e, node.id, 'bottom') })] }))] }, node.id)))] }), !previewMode &&
1595
+ }, children: jsx(Pencil, { className: "h-3.5 w-3.5" }) }) })), node.type === 'mentor' &&
1596
+ !previewMode &&
1597
+ onOpenAgentSettings &&
1598
+ !!agentOf(node.data) && (jsx(ActionTooltip, { label: t('workflowsWorkflowCanvas.agentSettings'), children: jsx("button", { type: "button", "aria-label": t('workflowsWorkflowCanvas.agentSettings'), className: `text-muted-foreground hover:text-foreground cursor-pointer p-1 transition-colors ${ICON_TOUCH_TARGET}`, onPointerDown: (e) => e.stopPropagation(), onClick: (e) => {
1599
+ e.stopPropagation();
1600
+ onOpenAgentSettings === null || onOpenAgentSettings === void 0 ? void 0 : onOpenAgentSettings(agentOf(node.data));
1601
+ }, children: jsx(Settings, { className: "h-3.5 w-3.5" }) }) }))] }), node.data.subtitle && (jsx("p", { className: "text-muted-foreground ml-7 text-xs", children: node.data.subtitle })), jsx("div", { className: `${INPUT_DOT} top-1/2 -left-2 -translate-y-1/2`, style: { backgroundColor: '#38A1E5' } }), jsx("div", { className: RIGHT_DOT, style: { backgroundColor: '#38A1E5' }, onPointerDown: (e) => handleConnectionStart(e, node.id, 'right') }), jsx("div", { className: TOP_DOT, style: { backgroundColor: '#38A1E5' }, onPointerDown: (e) => handleConnectionStart(e, node.id, 'top') }), jsx("div", { className: BOTTOM_DOT, style: { backgroundColor: '#38A1E5' }, onPointerDown: (e) => handleConnectionStart(e, node.id, 'bottom') })] }))] }, node.id)))] }), !previewMode &&
1009
1602
  selectedNodeForConfig &&
1010
1603
  (() => {
1011
1604
  const node = nodes.find((n) => n.id === selectedNodeForConfig);
1012
- return node && node.type !== 'mentor' ? (jsx(NodeConfigPanel, { nodeId: node.id, nodeType: node.type || '', nodeData: node.data, onClose: () => setSelectedNodeForConfig(null), onUpdateNode: handleUpdateNode, onDeleteNode: isDeletableNode(node) ? () => deleteNodes([node.id]) : undefined, workflowVariables: workflowVariables, variableUsages: variableUsages, stepReferences: nodes
1013
- .filter((other) => { var _a; return other.id !== node.id && STEPS_WITH_RESULTS.has((_a = other.type) !== null && _a !== void 0 ? _a : ''); })
1014
- .map((other) => ({ id: other.id, label: other.data.label })), org: org, defaultMentorId: defaultMentorId, username: username, agentSettings: agentSettings }, node.id)) : null;
1605
+ if (!node)
1606
+ return null;
1607
+ const placeholders = placeholderSources(node.id, nodes, edges);
1608
+ return (jsx(NodeConfigPanel, { nodeId: node.id, nodeType: node.type || '', nodeData: node.data, onClose: () => setSelectedNodeForConfig(null), onUpdateNode: handleUpdateNode, onDeleteNode: isDeletableNode(node) ? () => deleteNodes([node.id]) : undefined, workflowVariables: workflowVariables, variableUsages: variableUsages, stepReferences: nodes
1609
+ .filter((other) => other.id !== node.id && stepHasResult(other.type))
1610
+ .map((other) => ({ id: other.id, label: other.data.label })), placeholderVariables: placeholders.variables, placeholderSteps: placeholders.steps, org: org, defaultMentorId: defaultMentorId, username: username, agentSettings: agentSettings, classifierModels: classifierModels, onTryClassifier: onTryClassifier, focusField: (focusTarget === null || focusTarget === void 0 ? void 0 : focusTarget.nodeId) === node.id ? focusTarget.field : undefined }, `${node.id}-${panelVersion}`));
1015
1611
  })(), !previewMode && (jsx(Dialog, { open: showMentorModal, onOpenChange: (open) => {
1016
1612
  if (open) {
1017
1613
  setShowMentorModal(true);
@@ -1019,7 +1615,7 @@ function WorkflowCanvas({ onDraggedItem: _onDraggedItem, onClickedItem, previewM
1019
1615
  else {
1020
1616
  closeMentorModal();
1021
1617
  }
1022
- }, children: jsxs(DialogContent, { className: "w-[calc(100%-2rem)] max-w-3xl rounded-lg", children: [jsx(DialogHeader, { children: jsx(DialogTitle, { children: t('workflowsWorkflowCanvas.changeAgent') }) }), jsx(MentorSelectionGrid, { tenantKey: org !== null && org !== void 0 ? org : '', selectedMentorIds: selectedMentorIds, onMentorSelect: handleMentorSelect, searchQuery: mentorSearchQuery, onSearchChange: setMentorSearchQuery, minHeight: "360px" })] }) }))] }), !previewMode && (jsx("div", { className: "pointer-events-auto absolute bottom-6 left-1/2 -translate-x-1/2 transform", children: jsxs("div", { className: "bg-card border-border flex items-center gap-2 rounded-full border px-3 py-2 shadow-lg", children: [jsx(ActionTooltip, { label: t('workflowsWorkflowCanvas.panTool'), children: jsx(Button, { variant: tool === 'hand' ? 'default' : 'ghost', "aria-label": t('workflowsWorkflowCanvas.panTool'), size: "icon", className: `h-8 w-8 ${tool === 'hand' ? 'bg-[#38A1E5] text-white hover:bg-[#38A1E5]' : ''}`, onClick: () => setTool('hand'), children: jsx(Hand, { className: "h-4 w-4" }) }) }), jsx(ActionTooltip, { label: t('workflowsWorkflowCanvas.selectTool'), children: jsx(Button, { variant: tool === 'pointer' ? 'default' : 'ghost', "aria-label": t('workflowsWorkflowCanvas.selectTool'), size: "icon", className: `h-8 w-8 ${tool === 'pointer' ? 'bg-[#38A1E5] text-white hover:bg-[#38A1E5]' : ''}`, onClick: () => setTool('pointer'), children: jsx(MousePointer, { className: "h-4 w-4" }) }) }), jsx("div", { className: "bg-border mx-1 h-6 w-px" }), jsx(ActionTooltip, { label: t('workflowsWorkflowCanvas.undo'), children: jsx(Button, { variant: "ghost", size: "icon", className: "text-muted-foreground hover:text-foreground h-8 w-8 disabled:opacity-30", onClick: handleUndo, "aria-label": t('workflowsWorkflowCanvas.undo'), disabled: historyIndex <= 0, children: jsx(Undo, { className: "h-4 w-4" }) }) }), jsx(ActionTooltip, { label: t('workflowsWorkflowCanvas.redo'), children: jsx(Button, { variant: "ghost", size: "icon", className: "text-muted-foreground hover:text-foreground h-8 w-8 disabled:opacity-30", onClick: handleRedo, "aria-label": t('workflowsWorkflowCanvas.redo'), disabled: historyIndex >= history.length - 1, children: jsx(Redo, { className: "h-4 w-4" }) }) }), jsx("div", { className: "bg-border mx-1 h-6 w-px" }), jsx(ActionTooltip, { label: t('workflowsWorkflowCanvas.zoomOut'), children: jsx(Button, { variant: "ghost", size: "icon", className: "text-muted-foreground hover:text-foreground h-8 w-8", onClick: handleZoomOut, "aria-label": t('workflowsWorkflowCanvas.zoomOut'), children: jsx(ZoomOut, { className: "h-4 w-4" }) }) }), jsxs("span", { className: "text-muted-foreground min-w-[3ch] text-center text-xs", children: [Math.round(zoom * 100), "%"] }), jsx(ActionTooltip, { label: t('workflowsWorkflowCanvas.zoomIn'), children: jsx(Button, { variant: "ghost", size: "icon", className: "text-muted-foreground hover:text-foreground h-8 w-8", onClick: handleZoomIn, "aria-label": t('workflowsWorkflowCanvas.zoomIn'), children: jsx(ZoomIn, { className: "h-4 w-4" }) }) })] }) }))] }));
1618
+ }, children: jsxs(DialogContent, { className: "w-[calc(100%-2rem)] max-w-3xl rounded-lg", children: [jsx(DialogHeader, { children: jsx(DialogTitle, { children: t('workflowsWorkflowCanvas.changeAgent') }) }), jsx(MentorSelectionGrid, { tenantKey: org !== null && org !== void 0 ? org : '', selectedMentorIds: selectedMentorIds, excludedMentorIds: defaultMentorId ? [defaultMentorId] : undefined, onMentorSelect: handleMentorSelect, searchQuery: mentorSearchQuery, onSearchChange: setMentorSearchQuery, minHeight: "360px" })] }) }))] }), !previewMode && (jsx("div", { className: "pointer-events-auto absolute bottom-6 left-1/2 -translate-x-1/2 transform touch-manipulation", children: jsxs("div", { className: "bg-card border-border flex items-center gap-2 rounded-full border px-3 py-2 shadow-lg max-md:gap-1 max-md:px-2", children: [jsx(ActionTooltip, { label: withShortcut(t('workflowsWorkflowCanvas.panTool'), 'pan'), children: jsx(Button, { variant: tool === 'hand' ? 'default' : 'ghost', "aria-label": t('workflowsWorkflowCanvas.panTool'), "aria-keyshortcuts": ariaShortcut('pan'), size: "icon", className: `h-8 w-8 ${tool === 'hand' ? 'bg-[#38A1E5] text-white hover:bg-[#38A1E5]' : ''}`, onClick: () => setTool('hand'), children: jsx(Hand, { className: "h-4 w-4" }) }) }), jsx(ActionTooltip, { label: withShortcut(t('workflowsWorkflowCanvas.selectTool'), 'select'), children: jsx(Button, { variant: tool === 'pointer' ? 'default' : 'ghost', "aria-label": t('workflowsWorkflowCanvas.selectTool'), "aria-keyshortcuts": ariaShortcut('select'), size: "icon", className: `h-8 w-8 ${tool === 'pointer' ? 'bg-[#38A1E5] text-white hover:bg-[#38A1E5]' : ''}`, onClick: () => setTool('pointer'), children: jsx(MousePointer, { className: "h-4 w-4" }) }) }), jsx("div", { className: "bg-border mx-1 h-6 w-px" }), jsx(ActionTooltip, { label: withShortcut(t('workflowsWorkflowCanvas.undo'), 'undo'), children: jsx(Button, { variant: "ghost", size: "icon", className: "text-muted-foreground hover:text-foreground h-8 w-8 disabled:opacity-30", onClick: handleUndo, "aria-label": t('workflowsWorkflowCanvas.undo'), "aria-keyshortcuts": ariaShortcut('undo'), disabled: !canUndo, children: jsx(Undo, { className: "h-4 w-4" }) }) }), jsx(ActionTooltip, { label: withShortcut(t('workflowsWorkflowCanvas.redo'), 'redo'), children: jsx(Button, { variant: "ghost", size: "icon", className: "text-muted-foreground hover:text-foreground h-8 w-8 disabled:opacity-30", onClick: handleRedo, "aria-label": t('workflowsWorkflowCanvas.redo'), "aria-keyshortcuts": ariaShortcut('redo'), disabled: !canRedo, children: jsx(Redo, { className: "h-4 w-4" }) }) }), jsx("div", { className: "bg-border mx-1 h-6 w-px" }), jsx(ActionTooltip, { label: withShortcut(t('workflowsWorkflowCanvas.zoomOut'), 'zoomOut'), children: jsx(Button, { variant: "ghost", size: "icon", className: "text-muted-foreground hover:text-foreground h-8 w-8", onClick: handleZoomOut, "aria-label": t('workflowsWorkflowCanvas.zoomOut'), "aria-keyshortcuts": ariaShortcut('zoomOut'), children: jsx(ZoomOut, { className: "h-4 w-4" }) }) }), jsxs("span", { className: "text-muted-foreground min-w-[3ch] text-center text-xs", children: [Math.round(zoom * 100), "%"] }), jsx(ActionTooltip, { label: withShortcut(t('workflowsWorkflowCanvas.zoomIn'), 'zoomIn'), children: jsx(Button, { variant: "ghost", size: "icon", className: "text-muted-foreground hover:text-foreground h-8 w-8", onClick: handleZoomIn, "aria-label": t('workflowsWorkflowCanvas.zoomIn'), "aria-keyshortcuts": ariaShortcut('zoomIn'), children: jsx(ZoomIn, { className: "h-4 w-4" }) }) }), selectedSteps.length > 1 && (jsxs(Fragment, { children: [jsx("div", { className: "bg-border mx-1 hidden h-6 w-px pointer-coarse:block" }), jsx(ActionTooltip, { label: withShortcut(t('workflowsWorkflowCanvas.deleteSelection'), 'delete'), children: jsx(Button, { variant: "ghost", size: "icon", className: "text-muted-foreground hover:text-destructive hidden h-8 w-8 pointer-coarse:flex", onClick: handleDeleteSelection, "aria-label": t('workflowsWorkflowCanvas.deleteSelection'), "aria-keyshortcuts": ariaShortcut('delete'), children: jsx(Trash2, { className: "h-4 w-4" }) }) })] }))] }) }))] }));
1023
1619
  }
1024
1620
 
1025
1621
  export { WorkflowCanvas };