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