@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.
Files changed (106) hide show
  1. package/dist/cjs/_virtual/index2.js +2 -2
  2. package/dist/cjs/_virtual/index3.js +2 -2
  3. package/dist/cjs/components/chat-input-form/use-overflow-fit.js +6 -4
  4. package/dist/cjs/components/chat-input-form/use-overflow-fit.js.map +1 -1
  5. package/dist/cjs/components/mentors/mentor-selection-grid.js +5 -2
  6. package/dist/cjs/components/mentors/mentor-selection-grid.js.map +1 -1
  7. package/dist/cjs/components/modals/edit-mentor-modal/tabs/privacy-tab/labels.js +133 -24
  8. package/dist/cjs/components/modals/edit-mentor-modal/tabs/privacy-tab/labels.js.map +1 -1
  9. package/dist/cjs/components/modals/edit-mentor-modal/tabs/privacy-tab.js +112 -44
  10. package/dist/cjs/components/modals/edit-mentor-modal/tabs/privacy-tab.js.map +1 -1
  11. package/dist/cjs/components/modals/user-profile-modal.js +3 -0
  12. package/dist/cjs/components/modals/user-profile-modal.js.map +1 -1
  13. package/dist/cjs/components/workflows/classifier-panel.js +403 -0
  14. package/dist/cjs/components/workflows/classifier-panel.js.map +1 -0
  15. package/dist/cjs/components/workflows/delete-workflow-modal.js +4 -3
  16. package/dist/cjs/components/workflows/delete-workflow-modal.js.map +1 -1
  17. package/dist/cjs/components/workflows/insert-reference.js +87 -0
  18. package/dist/cjs/components/workflows/insert-reference.js.map +1 -0
  19. package/dist/cjs/components/workflows/node-config-panel.js +133 -69
  20. package/dist/cjs/components/workflows/node-config-panel.js.map +1 -1
  21. package/dist/cjs/components/workflows/panel-fields.js +132 -0
  22. package/dist/cjs/components/workflows/panel-fields.js.map +1 -0
  23. package/dist/cjs/components/workflows/shortcuts.js +84 -0
  24. package/dist/cjs/components/workflows/shortcuts.js.map +1 -0
  25. package/dist/cjs/components/workflows/tool-dialogs.js +11 -11
  26. package/dist/cjs/components/workflows/tool-dialogs.js.map +1 -1
  27. package/dist/cjs/components/workflows/workflow-canvas.js +872 -276
  28. package/dist/cjs/components/workflows/workflow-canvas.js.map +1 -1
  29. package/dist/cjs/components/workflows/workflow-definition.js +239 -7
  30. package/dist/cjs/components/workflows/workflow-definition.js.map +1 -1
  31. package/dist/cjs/components/workflows/workflow-editor.js +491 -80
  32. package/dist/cjs/components/workflows/workflow-editor.js.map +1 -1
  33. package/dist/cjs/components/workflows/workflow-preview-chat.js +4 -0
  34. package/dist/cjs/components/workflows/workflow-preview-chat.js.map +1 -1
  35. package/dist/cjs/components/workflows/workflow-sidebar.js +6 -11
  36. package/dist/cjs/components/workflows/workflow-sidebar.js.map +1 -1
  37. package/dist/cjs/components/workflows/workflow-switch.js +15 -0
  38. package/dist/cjs/components/workflows/workflow-switch.js.map +1 -0
  39. package/dist/cjs/components/workflows/workflow-textarea.js +171 -0
  40. package/dist/cjs/components/workflows/workflow-textarea.js.map +1 -0
  41. package/dist/cjs/i18n/messages/en.json.js +211 -25
  42. package/dist/cjs/i18n/messages/en.json.js.map +1 -1
  43. package/dist/cjs/i18n/messages/es.json.js +207 -21
  44. package/dist/cjs/i18n/messages/es.json.js.map +1 -1
  45. package/dist/cjs/i18n/messages/fr.json.js +207 -21
  46. package/dist/cjs/i18n/messages/fr.json.js.map +1 -1
  47. package/dist/cjs/i18n/messages/zh.json.js +207 -21
  48. package/dist/cjs/i18n/messages/zh.json.js.map +1 -1
  49. package/dist/cjs/index.js +20 -0
  50. package/dist/cjs/index.js.map +1 -1
  51. package/dist/cjs/node_modules/.pnpm/css-mediaquery@0.1.2/node_modules/css-mediaquery/index.js +1 -1
  52. package/dist/cjs/node_modules/.pnpm/matchmediaquery@0.4.2/node_modules/matchmediaquery/index.js +1 -1
  53. package/dist/cjs/node_modules/.pnpm/prop-types@15.8.1/node_modules/prop-types/index.js +1 -1
  54. package/dist/cjs/web-containers/tsconfig.build.tsbuildinfo +1 -1
  55. package/dist/esm/components/chat-input-form/use-overflow-fit.js +7 -5
  56. package/dist/esm/components/chat-input-form/use-overflow-fit.js.map +1 -1
  57. package/dist/esm/components/mentors/mentor-selection-grid.js +5 -2
  58. package/dist/esm/components/mentors/mentor-selection-grid.js.map +1 -1
  59. package/dist/esm/components/modals/edit-mentor-modal/tabs/privacy-tab/labels.js +133 -24
  60. package/dist/esm/components/modals/edit-mentor-modal/tabs/privacy-tab/labels.js.map +1 -1
  61. package/dist/esm/components/modals/edit-mentor-modal/tabs/privacy-tab.js +114 -46
  62. package/dist/esm/components/modals/edit-mentor-modal/tabs/privacy-tab.js.map +1 -1
  63. package/dist/esm/components/modals/user-profile-modal.js +3 -0
  64. package/dist/esm/components/modals/user-profile-modal.js.map +1 -1
  65. package/dist/esm/components/workflows/classifier-panel.js +401 -0
  66. package/dist/esm/components/workflows/classifier-panel.js.map +1 -0
  67. package/dist/esm/components/workflows/delete-workflow-modal.js +4 -3
  68. package/dist/esm/components/workflows/delete-workflow-modal.js.map +1 -1
  69. package/dist/esm/components/workflows/insert-reference.js +81 -0
  70. package/dist/esm/components/workflows/insert-reference.js.map +1 -0
  71. package/dist/esm/components/workflows/node-config-panel.js +135 -71
  72. package/dist/esm/components/workflows/node-config-panel.js.map +1 -1
  73. package/dist/esm/components/workflows/panel-fields.js +125 -0
  74. package/dist/esm/components/workflows/panel-fields.js.map +1 -0
  75. package/dist/esm/components/workflows/shortcuts.js +77 -0
  76. package/dist/esm/components/workflows/shortcuts.js.map +1 -0
  77. package/dist/esm/components/workflows/tool-dialogs.js +11 -11
  78. package/dist/esm/components/workflows/tool-dialogs.js.map +1 -1
  79. package/dist/esm/components/workflows/workflow-canvas.js +874 -278
  80. package/dist/esm/components/workflows/workflow-canvas.js.map +1 -1
  81. package/dist/esm/components/workflows/workflow-definition.js +220 -8
  82. package/dist/esm/components/workflows/workflow-definition.js.map +1 -1
  83. package/dist/esm/components/workflows/workflow-editor.js +495 -84
  84. package/dist/esm/components/workflows/workflow-editor.js.map +1 -1
  85. package/dist/esm/components/workflows/workflow-preview-chat.js +4 -0
  86. package/dist/esm/components/workflows/workflow-preview-chat.js.map +1 -1
  87. package/dist/esm/components/workflows/workflow-sidebar.js +6 -11
  88. package/dist/esm/components/workflows/workflow-sidebar.js.map +1 -1
  89. package/dist/esm/components/workflows/workflow-switch.js +13 -0
  90. package/dist/esm/components/workflows/workflow-switch.js.map +1 -0
  91. package/dist/esm/components/workflows/workflow-textarea.js +168 -0
  92. package/dist/esm/components/workflows/workflow-textarea.js.map +1 -0
  93. package/dist/esm/i18n/messages/en.json.js +211 -26
  94. package/dist/esm/i18n/messages/en.json.js.map +1 -1
  95. package/dist/esm/i18n/messages/es.json.js +207 -22
  96. package/dist/esm/i18n/messages/es.json.js.map +1 -1
  97. package/dist/esm/i18n/messages/fr.json.js +207 -22
  98. package/dist/esm/i18n/messages/fr.json.js.map +1 -1
  99. package/dist/esm/i18n/messages/zh.json.js +207 -22
  100. package/dist/esm/i18n/messages/zh.json.js.map +1 -1
  101. package/dist/esm/index.js +1 -1
  102. package/dist/esm/web-containers/tsconfig.build.tsbuildinfo +1 -1
  103. package/dist/index.d.ts +107 -3
  104. package/dist/next/index.d.ts +125 -16
  105. package/dist/package.json +1 -1
  106. package/package.json +3 -3
@@ -9,11 +9,15 @@ var input = require('../ui/input.js');
9
9
  var workflowPreviewChat = require('./workflow-preview-chat.js');
10
10
  var workflowCanvas = require('./workflow-canvas.js');
11
11
  var workflowDefinition = require('./workflow-definition.js');
12
+ var useOverflowFit = require('../chat-input-form/use-overflow-fit.js');
13
+ var actionTooltip = require('./action-tooltip.js');
14
+ var shortcuts = require('./shortcuts.js');
12
15
  var workflowSidebar = require('./workflow-sidebar.js');
13
16
  var deleteWorkflowModal = require('./delete-workflow-modal.js');
14
17
  var dataLayer = require('@iblai/data-layer');
15
18
  var dropdownMenu = require('../ui/dropdown-menu.js');
16
19
  var collapsible = require('../ui/collapsible.js');
20
+ var sheet = require('../ui/sheet.js');
17
21
  var sonner = require('sonner');
18
22
  var index_module = require('../../node_modules/.pnpm/use-debounce@10.0.4_react@19.1.0/node_modules/use-debounce/dist/index.module.js');
19
23
  var loaderCircle = require('../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/loader-circle.js');
@@ -22,13 +26,17 @@ var chevronLeft = require('../../node_modules/.pnpm/lucide-react@0.528.0_react@1
22
26
  var pencil = require('../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/pencil.js');
23
27
  var x = require('../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/x.js');
24
28
  var rotateCcw = require('../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/rotate-ccw.js');
25
- var ellipsis = require('../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/ellipsis.js');
29
+ var eye = require('../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/eye.js');
26
30
  var power = require('../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/power.js');
27
31
  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');
28
- var eye = require('../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/eye.js');
29
- var triangleAlert = require('../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/triangle-alert.js');
32
+ var save = require('../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/save.js');
33
+ var upload = require('../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/upload.js');
34
+ var ellipsis = require('../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/ellipsis.js');
35
+ var listChecks = require('../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/list-checks.js');
30
36
  var chevronUp = require('../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/chevron-up.js');
31
37
  var chevronDown = require('../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/chevron-down.js');
38
+ var triangleAlert = require('../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/triangle-alert.js');
39
+ var plus = require('../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/plus.js');
32
40
 
33
41
  function getCategoryConfig(t) {
34
42
  return {
@@ -41,25 +49,228 @@ function getCategoryConfig(t) {
41
49
  const nodeCategoryOverride = {
42
50
  note: 'core', // API has it in 'visual' but UI shows it in 'Core'
43
51
  };
44
- // The backend words these in terms of mentors, and repeats the runtime check
45
- // once per Agent step.
52
+ function stepsOf(nodes) {
53
+ const byId = new Map(nodes.map((node) => [node.id, node]));
54
+ return { find: (id) => byId.get(id), at: (index) => nodes[index] };
55
+ }
56
+ const stepName = (steps, id) => { var _a, _b; return ((_b = (_a = steps.find(id)) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.label) || id; };
57
+ const BRANCH_NAME_KEYS = new Map([
58
+ [workflowDefinition.CLASSIFIER_HANDLES.yes, 'workflowsWorkflowCanvas.classifierYes'],
59
+ [workflowDefinition.CLASSIFIER_HANDLES.no, 'workflowsWorkflowCanvas.classifierNo'],
60
+ [workflowDefinition.CLASSIFIER_HANDLES.next, 'workflowsWorkflowCanvas.classifierNext'],
61
+ [workflowDefinition.CLASSIFIER_HANDLES.fallback, 'workflowsWorkflowCanvas.classifierFallback'],
62
+ ]);
63
+ function branchName(step, handle, t) {
64
+ var _a, _b;
65
+ const category = (_b = (_a = step === null || step === void 0 ? void 0 : step.data) === null || _a === void 0 ? void 0 : _a.categories) === null || _b === void 0 ? void 0 : _b.find((candidate) => candidate.id === handle);
66
+ if (category === null || category === void 0 ? void 0 : category.label)
67
+ return category.label;
68
+ const key = BRANCH_NAME_KEYS.get(handle);
69
+ return key ? t(key) : handle;
70
+ }
71
+ // The backend words these in terms of mentors and internal step ids, and
72
+ // repeats the runtime and entry-agent checks once per Agent step.
46
73
  const MENTOR_MESSAGES = [
47
- [
48
- /^Mentor existence will be validated at runtime/,
49
- 'workflowsWorkflowEditor.agentCheckedAtRuntime',
50
- ],
51
- [
52
- /^Node 'mentor' missing required field 'mentor_id'/,
53
- 'workflowsWorkflowEditor.agentStepMissingAgent',
54
- ],
74
+ {
75
+ pattern: /^Mentor existence will be validated at runtime/,
76
+ key: 'workflowsWorkflowEditor.agentCheckedAtRuntime',
77
+ aboutEveryStep: true,
78
+ },
79
+ {
80
+ pattern: /^Node 'mentor' missing required field 'mentor_id'/,
81
+ key: 'workflowsWorkflowEditor.agentStepMissingAgent',
82
+ },
83
+ {
84
+ pattern: /^Mentor step needs a mentor/,
85
+ key: 'workflowsWorkflowEditor.agentStepMissingAgent',
86
+ },
87
+ {
88
+ pattern: /^A mentor step cannot use this workflow's own entry mentor/,
89
+ key: 'workflowsWorkflowEditor.agentStepUsesEntryAgent',
90
+ },
91
+ {
92
+ pattern: /^Mentor step '(.+?)' uses a mentor that does not exist on this platform/,
93
+ key: 'workflowsWorkflowEditor.agentStepAgentMissing',
94
+ params: (match, steps) => ({ name: stepName(steps, match[1]) }),
95
+ },
96
+ {
97
+ pattern: /^Mentor step 'output_variable' must start with a letter/,
98
+ key: 'workflowsWorkflowEditor.agentStepOutputVariableInvalid',
99
+ },
100
+ {
101
+ pattern: /^Classifier '(.+?)' route '(.+?)' goes straight to End/,
102
+ key: 'workflowsWorkflowEditor.classifierRouteToEnd',
103
+ params: (match, steps, t) => ({
104
+ name: stepName(steps, match[1]),
105
+ path: branchName(steps.find(match[1]), match[2], t),
106
+ }),
107
+ },
108
+ {
109
+ // Only the nodes[<index>] location says which step stores the variable.
110
+ pattern: /^(?:Mentor step|Classifier) 'output_variable' '(.+?)' is a variable .+? \('(.+?)'\); this step replaces it with its result at nodes\[(\d+)\]\.data\b/,
111
+ key: 'workflowsWorkflowEditor.outputVariableClash',
112
+ params: (match, steps) => {
113
+ var _a;
114
+ const step = steps.at(Number(match[3]));
115
+ if (!step)
116
+ return null;
117
+ return {
118
+ name: ((_a = step.data) === null || _a === void 0 ? void 0 : _a.label) || step.id,
119
+ variable: match[1],
120
+ setter: stepName(steps, match[2]),
121
+ };
122
+ },
123
+ },
124
+ {
125
+ pattern: /^(?:Mentor step|Classifier) 'output_variable' '(.+?)' is a variable .+? \('(.+?)'\); this step replaces it/,
126
+ key: 'workflowsWorkflowEditor.outputVariableClashUnknownStep',
127
+ params: (match, steps) => ({ variable: match[1], setter: stepName(steps, match[2]) }),
128
+ locationOnly: true,
129
+ },
130
+ {
131
+ // The model is named as resolved, so "ibl.ai Default" shows up as a slug
132
+ // the author never picked; staff switch decision models on per deployment.
133
+ pattern: /^Classifier '(.+?)' uses '.+?', (?:and ':|which isn't an enabled|which is not a decision)/,
134
+ key: 'workflowsWorkflowEditor.classifierModelUnavailable',
135
+ params: (match, steps) => ({ name: stepName(steps, match[1]) }),
136
+ },
55
137
  ];
56
- function inAgentWording(messages, t) {
57
- const reworded = messages.map((message) => {
58
- const match = MENTOR_MESSAGES.find(([pattern]) => pattern.test(message));
59
- return match ? t(match[1]) : message;
60
- });
61
- return Array.from(new Set(reworded));
138
+ // The backend ends each message with where it found the problem, e.g.
139
+ // "at nodes[2].data (field: instructions)" or "at workflow_loops (field: edges)".
140
+ const NODE_LOCATION = / at nodes\[(\d+)\](\.data)?(?: \(field: ([^()]+)\))?$/;
141
+ const WORKFLOW_LOCATION = / at workflow_\w+(?: \(field: [^()]+\))?$/;
142
+ const QUOTED = /'([^'\s]+)'/g;
143
+ function problemTarget(message, steps, locationOnly = false) {
144
+ if (WORKFLOW_LOCATION.test(message))
145
+ return {};
146
+ // The location names the step at fault; a quoted id in the same message can
147
+ // be another step, such as the one that also sets a variable.
148
+ const location = NODE_LOCATION.exec(message);
149
+ if (location) {
150
+ const step = steps.at(Number(location[1]));
151
+ if (!step)
152
+ return {};
153
+ // Outside the step's data the field is its id or type, which no setting shows.
154
+ const field = location[2] ? location[3] : undefined;
155
+ return field ? { stepId: step.id, field } : { stepId: step.id };
156
+ }
157
+ if (locationOnly)
158
+ return {};
159
+ for (const [, quoted] of message.matchAll(QUOTED)) {
160
+ if (steps.find(quoted))
161
+ return { stepId: quoted };
162
+ }
163
+ return {};
164
+ }
165
+ function toProblem(message, t, steps) {
166
+ for (const { pattern, key, params, aboutEveryStep, locationOnly } of MENTOR_MESSAGES) {
167
+ const match = pattern.exec(message);
168
+ if (!match)
169
+ continue;
170
+ const values = params === null || params === void 0 ? void 0 : params(match, steps, t);
171
+ if (values === null)
172
+ continue;
173
+ const text = t(key, values);
174
+ return aboutEveryStep ? { text } : { text, ...problemTarget(message, steps, locationOnly) };
175
+ }
176
+ return { text: message, ...problemTarget(message, steps) };
177
+ }
178
+ const distinct = (lines) => Array.from(new Set(lines));
179
+ // A repeated line shows once and goes to the first step it was reported for;
180
+ // once that step is fixed, the next check moves it to the next one.
181
+ const distinctProblems = (problems) => problems.filter((problem, index) => problems.findIndex((other) => other.text === problem.text) === index);
182
+ const PROBLEM_LINK = 'cursor-pointer text-left underline-offset-2 hover:underline focus-visible:underline focus-visible:outline-none';
183
+ // A placeholder line's first group becomes {placeholder}, quotes included.
184
+ const CLASSIFIER_TRY_MESSAGES = [
185
+ {
186
+ pattern: /^Classifier needs instructions/,
187
+ key: 'workflowsClassifierPanel.instructionsRequired',
188
+ },
189
+ {
190
+ pattern: /^Category \d+ needs a 'label'/,
191
+ key: 'workflowsClassifierPanel.tryErrorCategoryLabel',
192
+ },
193
+ { pattern: /^Level \d+ needs a 'label'/, key: 'workflowsClassifierPanel.tryErrorLevelLabel' },
194
+ { pattern: /^Duplicate level label/, key: 'workflowsClassifierPanel.tryErrorDuplicateLevel' },
195
+ {
196
+ pattern: /^('\{\{[^{}]+\}\}') names no step/,
197
+ key: 'workflowsClassifierPanel.tryErrorPlaceholderStep',
198
+ },
199
+ {
200
+ pattern: /^('\{\{[^{}]+\}\}') is not a valid variable name/,
201
+ key: 'workflowsClassifierPanel.tryErrorPlaceholderVariableName',
202
+ },
203
+ {
204
+ pattern: /^('\{\{[^{}]+\}\}') names a variable the Start node does not declare/,
205
+ key: 'workflowsClassifierPanel.tryErrorPlaceholderUnknownVariable',
206
+ },
207
+ {
208
+ pattern: /^('\{\{[^{}]+\}\}') is not a placeholder/,
209
+ key: 'workflowsClassifierPanel.tryErrorNotPlaceholder',
210
+ },
211
+ {
212
+ pattern: /^('\{\{[^{}]+\}\}') is always empty/,
213
+ key: 'workflowsClassifierPanel.tryErrorPlaceholderEmpty',
214
+ },
215
+ {
216
+ pattern: /^Example \d+ needs 'text' and a 'category'/,
217
+ key: 'workflowsClassifierPanel.tryErrorExample',
218
+ },
219
+ ];
220
+ const CLASSIFIER_MODEL_ERROR = /^Classifier '.+?' uses '.+?', /;
221
+ function classifierErrorText(line, t) {
222
+ if (CLASSIFIER_MODEL_ERROR.test(line))
223
+ return t('workflowsClassifierPanel.tryModelUnavailable');
224
+ for (const { pattern, key } of CLASSIFIER_TRY_MESSAGES) {
225
+ const match = pattern.exec(line);
226
+ if (match)
227
+ return t(key, match[1] ? { placeholder: match[1] } : undefined);
228
+ }
229
+ return t('workflowsClassifierPanel.tryErrorOther');
230
+ }
231
+ function classifierTryFailure(error, t) {
232
+ const { status, data } = (error !== null && error !== void 0 ? error : {});
233
+ switch (status) {
234
+ case 400: {
235
+ const rawErrors = data === null || data === void 0 ? void 0 : data.errors;
236
+ const lines = Array.isArray(rawErrors)
237
+ ? rawErrors.filter((line) => typeof line === 'string')
238
+ : [];
239
+ if (lines.length === 0) {
240
+ // The panel refuses an empty sample itself, so an `input` error is
241
+ // the 20000-character limit.
242
+ if (Array.isArray(data === null || data === void 0 ? void 0 : data.input))
243
+ return { ok: false, reason: 'too-long' };
244
+ if (Array.isArray(data === null || data === void 0 ? void 0 : data.variables))
245
+ return { ok: false, reason: 'variables-too-long' };
246
+ return { ok: false, reason: 'other' };
247
+ }
248
+ if (lines.every((line) => CLASSIFIER_MODEL_ERROR.test(line))) {
249
+ return { ok: false, reason: 'model-unavailable' };
250
+ }
251
+ return {
252
+ ok: false,
253
+ reason: 'invalid',
254
+ errors: distinct(lines.map((line) => classifierErrorText(line, t))),
255
+ };
256
+ }
257
+ case 402:
258
+ return { ok: false, reason: 'credits' };
259
+ case 403:
260
+ return { ok: false, reason: 'not-allowed' };
261
+ case 429:
262
+ return { ok: false, reason: 'spend-cap' };
263
+ case 502: {
264
+ const detail = data === null || data === void 0 ? void 0 : data.detail;
265
+ const unavailable = typeof detail === 'string' &&
266
+ /not enabled for this account|not available for this account/.test(detail);
267
+ return { ok: false, reason: unavailable ? 'model-unavailable' : 'model-failed' };
268
+ }
269
+ default:
270
+ return { ok: false, reason: 'other' };
271
+ }
62
272
  }
273
+ const graphString = ({ nodes, edges }) => JSON.stringify({ nodes, edges });
63
274
  function transformNodeTypesToSections(nodeTypes, t) {
64
275
  if (!(nodeTypes === null || nodeTypes === void 0 ? void 0 : nodeTypes.node_types))
65
276
  return undefined;
@@ -72,6 +283,9 @@ function transformNodeTypesToSections(nodeTypes, t) {
72
283
  // The canvas adds the Start step to every workflow itself.
73
284
  if (nodeId === 'start')
74
285
  return;
286
+ // The backend can't run these yet, and publish refuses one that is connected.
287
+ if (nodeInfo.status === 'planned')
288
+ return;
75
289
  const targetCategory = nodeCategoryOverride[nodeId] || nodeInfo.category;
76
290
  const section = categoryMap.get(targetCategory);
77
291
  if (section) {
@@ -88,6 +302,32 @@ function transformNodeTypesToSections(nodeTypes, t) {
88
302
  .map(([, section]) => section)
89
303
  .filter((section) => section.items.length > 0);
90
304
  }
305
+ // Most important first: as the header narrows, the "…" menu takes them from
306
+ // the end, so Delete and Activate / Deactivate go first and Publish last.
307
+ const HEADER_ACTIONS = ['publish', 'save', 'preview', 'status', 'delete'];
308
+ // Widths to assume for a button that has not been measured inline yet.
309
+ const HEADER_ACTION_ESTIMATES = {
310
+ publish: 80,
311
+ save: 64,
312
+ preview: 104,
313
+ status: 116,
314
+ delete: 92,
315
+ };
316
+ // Until the header has a measured width: Publish, Save and Preview inline.
317
+ const HEADER_UNMEASURED_INLINE = 3;
318
+ // The header's gap-2 and its h-9 w-9 "…" button.
319
+ const HEADER_FIT_OPTIONS = { gap: 8, triggerWidth: 36 };
320
+ const HEADER_BUTTON = 'h-9 gap-1.5 has-[>svg]:px-2.5';
321
+ const HEADER_OUTLINE_BUTTON = `${HEADER_BUTTON} border-border hover:bg-accent bg-transparent`;
322
+ const HEADER_PRIMARY_BUTTON = `${HEADER_BUTTON} bg-[#38A1E5] text-white hover:bg-[#38A1E5]/90`;
323
+ // Long names wrap rather than push the buttons off the header.
324
+ const HEADER_NAME = 'text-foreground min-w-0 font-medium [overflow-wrap:anywhere]';
325
+ // Keeps the label's width while the spinner shows, so the button doesn't
326
+ // shrink and pull its neighbours in and out of the "…" menu.
327
+ function BusyLabel({ busy, children }) {
328
+ return (jsxRuntime.jsxs("span", { className: "relative inline-flex items-center justify-center", children: [jsxRuntime.jsx("span", { className: busy ? 'invisible' : undefined, children: children }), busy && jsxRuntime.jsx(loaderCircle.default, { className: "absolute animate-spin" })] }));
329
+ }
330
+ const HEADER_GHOST_BUTTON = `${HEADER_BUTTON} text-foreground hover:text-foreground hover:bg-accent`;
91
331
  function WorkflowEditor({ tenantKey, workflowId, username, axdToken, baseWsUrl, redirectToAuthSpa, onBack, onDeleted, onOpenAgentSettings, agentSettings, }) {
92
332
  var _a, _b, _c, _d, _e, _f;
93
333
  const t = context.useT();
@@ -106,14 +346,13 @@ function WorkflowEditor({ tenantKey, workflowId, username, axdToken, baseWsUrl,
106
346
  return;
107
347
  const nodeData = node.data;
108
348
  const mentorId = (nodeData === null || nodeData === void 0 ? void 0 : nodeData.mentor_id) ||
109
- (nodeData === null || nodeData === void 0 ? void 0 : nodeData.entry_mentor_id) ||
110
- entryMentorId;
349
+ (nodeData === null || nodeData === void 0 ? void 0 : nodeData.entry_mentor_id);
111
350
  if (mentorId) {
112
351
  ids.add(mentorId);
113
352
  }
114
353
  });
115
354
  return Array.from(ids);
116
- }, [(_b = workflow === null || workflow === void 0 ? void 0 : workflow.definition) === null || _b === void 0 ? void 0 : _b.nodes, entryMentorId]);
355
+ }, [(_b = workflow === null || workflow === void 0 ? void 0 : workflow.definition) === null || _b === void 0 ? void 0 : _b.nodes]);
117
356
  const missingMentorIds = React.useMemo(() => mentorIdsFromDefinition.filter((mentorId) => !Object.prototype.hasOwnProperty.call(mentorSettingsById, mentorId)), [mentorIdsFromDefinition, mentorSettingsById]);
118
357
  React.useEffect(() => {
119
358
  if (!tenantKey || !username || missingMentorIds.length === 0)
@@ -152,7 +391,12 @@ function WorkflowEditor({ tenantKey, workflowId, username, axdToken, baseWsUrl,
152
391
  isActive = false;
153
392
  };
154
393
  }, [missingMentorIds, fetchMentorSettings, tenantKey, username]);
155
- const isWaitingForMentorSettings = mentorIdsFromDefinition.length > 0 &&
394
+ // Once the canvas is open, an agent picked for a step loads in the
395
+ // background: the spinner would unmount the canvas, closing the open panel
396
+ // and losing undo history, the view and edits not yet saved.
397
+ const canvasShownRef = React.useRef(false);
398
+ const isWaitingForMentorSettings = !canvasShownRef.current &&
399
+ mentorIdsFromDefinition.length > 0 &&
156
400
  (!username || missingMentorIds.length > 0 || isMentorSettingsLoading);
157
401
  const [patchWorkflow, { isLoading: isSaving }] = dataLayer.usePatchWorkflowMutation();
158
402
  const [publishWorkflow, { isLoading: isPublishing }] = dataLayer.usePublishWorkflowMutation();
@@ -160,21 +404,31 @@ function WorkflowEditor({ tenantKey, workflowId, username, axdToken, baseWsUrl,
160
404
  const [validateWorkflow] = dataLayer.useValidateWorkflowMutation();
161
405
  const [activateWorkflow, { isLoading: isActivating }] = dataLayer.useActivateWorkflowMutation();
162
406
  const [deleteWorkflow, { isLoading: isDeleting }] = dataLayer.useDeleteWorkflowMutation();
407
+ const [testWorkflowClassifier] = dataLayer.useTestWorkflowClassifierMutation();
163
408
  const [workflowName, setWorkflowName] = React.useState('');
164
409
  const [isEditingName, setIsEditingName] = React.useState(false);
165
410
  const [isDeleteModalOpen, setIsDeleteModalOpen] = React.useState(false);
166
411
  const [draggedItem, setDraggedItem] = React.useState(null);
167
412
  const [clickedItem, setClickedItem] = React.useState(null);
168
413
  const [isPreviewMode, setIsPreviewMode] = React.useState(false);
414
+ const [isStepListOpen, setIsStepListOpen] = React.useState(false);
169
415
  const [previewKey, setPreviewKey] = React.useState(0);
170
416
  const [newChatSignal, setNewChatSignal] = React.useState(0);
171
417
  const [workflowData, setWorkflowData] = React.useState(null);
172
418
  const [hasUnsavedChanges, setHasUnsavedChanges] = React.useState(false);
173
419
  const [validationResult, setValidationResult] = React.useState(null);
174
420
  const [isValidationBannerOpen, setIsValidationBannerOpen] = React.useState(true);
421
+ const [stepFocusRequest, setStepFocusRequest] = React.useState();
175
422
  const isInitialLoad = React.useRef(true);
423
+ // An auto-save landing during a delete would PATCH the workflow being deleted.
424
+ const deleteStartedRef = React.useRef(false);
176
425
  const [debouncedWorkflowData] = index_module.useDebounce(workflowData, 1000);
177
426
  const nodeTypeSections = React.useMemo(() => transformNodeTypesToSections(nodeTypesData, t), [nodeTypesData, t]);
427
+ const classifierModels = React.useMemo(() => {
428
+ var _a, _b, _c, _d;
429
+ const suggestions = (_d = (_c = (_b = (_a = nodeTypesData === null || nodeTypesData === void 0 ? void 0 : nodeTypesData.node_types) === null || _a === void 0 ? void 0 : _a.classifier) === null || _b === void 0 ? void 0 : _b.config_schema) === null || _c === void 0 ? void 0 : _c.model) === null || _d === void 0 ? void 0 : _d.suggestions;
430
+ return (suggestions === null || suggestions === void 0 ? void 0 : suggestions.length) ? suggestions : [workflowDefinition.IBLAI_DECISION_MODEL];
431
+ }, [nodeTypesData]);
178
432
  // Never overwrite an in-progress rename with a cache refetch
179
433
  const syncedNameRef = React.useRef(null);
180
434
  React.useEffect(() => {
@@ -194,9 +448,16 @@ function WorkflowEditor({ tenantKey, workflowId, username, axdToken, baseWsUrl,
194
448
  const definitionNeedsSaveRef = React.useRef(false);
195
449
  const savedDefinitionRef = React.useRef(workflow === null || workflow === void 0 ? void 0 : workflow.definition);
196
450
  savedDefinitionRef.current = workflow === null || workflow === void 0 ? void 0 : workflow.definition;
451
+ // What the canvas last reported, so a save that lands after newer edits
452
+ // leaves them marked Unsaved.
453
+ const latestGraphRef = React.useRef(null);
454
+ // `nodes` is the definition the result was checked against: the backend
455
+ // locates problems by position in it.
197
456
  const showValidation = (result, nodes) => {
198
- const errors = inAgentWording(result.errors, t);
199
- const warnings = inAgentWording(workflowDefinition.withoutNoteConnectivityWarnings(result.warnings, nodes), t);
457
+ const steps = stepsOf(nodes);
458
+ const problems = (messages) => distinctProblems(messages.map((message) => toProblem(message, t, steps)));
459
+ const errors = problems(result.errors);
460
+ const warnings = problems(workflowDefinition.withoutNoteConnectivityWarnings(result.warnings, nodes));
200
461
  if (errors.length === 0 && warnings.length === 0) {
201
462
  setValidationResult(null);
202
463
  return;
@@ -207,19 +468,35 @@ function WorkflowEditor({ tenantKey, workflowId, username, axdToken, baseWsUrl,
207
468
  const showValidationRef = React.useRef(showValidation);
208
469
  showValidationRef.current = showValidation;
209
470
  React.useEffect(() => {
210
- if (!debouncedWorkflowData || !workflow) {
471
+ if (!debouncedWorkflowData || !workflow || deleteStartedRef.current) {
211
472
  return;
212
473
  }
213
- const currentDataStr = JSON.stringify({
214
- nodes: debouncedWorkflowData.nodes,
215
- edges: debouncedWorkflowData.edges,
216
- });
474
+ const currentDataStr = graphString(debouncedWorkflowData);
475
+ // A refetch re-runs this with the delayed graph, which can be older than
476
+ // one Try, Save or Preview has just saved; the newer graph gets its own run.
477
+ if (latestGraphRef.current !== null && currentDataStr !== latestGraphRef.current)
478
+ return;
479
+ const validate = async () => {
480
+ try {
481
+ const result = await validateWorkflow({
482
+ org: tenantKey,
483
+ uniqueId: workflowId,
484
+ }).unwrap();
485
+ showValidationRef.current(result, debouncedWorkflowData.nodes);
486
+ }
487
+ catch (_a) {
488
+ // Silent fail for validation
489
+ }
490
+ };
217
491
  if (isInitialLoad.current) {
492
+ isInitialLoad.current = false;
218
493
  if (currentDataStr === initialWorkflowDataRef.current) {
219
- isInitialLoad.current = false;
494
+ // A converted definition is checked once it is saved: until then the
495
+ // server still holds the old field names.
496
+ if (!definitionNeedsSaveRef.current)
497
+ validate();
220
498
  return;
221
499
  }
222
- isInitialLoad.current = false;
223
500
  }
224
501
  if (currentDataStr === initialWorkflowDataRef.current) {
225
502
  return;
@@ -237,21 +514,13 @@ function WorkflowEditor({ tenantKey, workflowId, username, axdToken, baseWsUrl,
237
514
  uniqueId: workflowId,
238
515
  data: patchData,
239
516
  }).unwrap();
240
- setHasUnsavedChanges(false);
241
517
  definitionNeedsSaveRef.current = false;
242
518
  initialWorkflowDataRef.current = currentDataStr;
243
- try {
244
- const result = await validateWorkflow({
245
- org: tenantKey,
246
- uniqueId: workflowId,
247
- }).unwrap();
248
- showValidationRef.current(result, debouncedWorkflowData.nodes);
249
- }
250
- catch (_a) {
251
- // Silent fail for validation
252
- }
519
+ if (latestGraphRef.current === currentDataStr)
520
+ setHasUnsavedChanges(false);
521
+ await validate();
253
522
  }
254
- catch (_b) {
523
+ catch (_a) {
255
524
  // Silent fail for auto-save, user can manually save
256
525
  }
257
526
  };
@@ -268,24 +537,22 @@ function WorkflowEditor({ tenantKey, workflowId, username, axdToken, baseWsUrl,
268
537
  clearTimeout(clickedItemTimerRef.current);
269
538
  clickedItemTimerRef.current = setTimeout(() => setClickedItem(null), 100);
270
539
  };
271
- const currentNodes = () => {
272
- var _a, _b, _c;
273
- return (_a = workflowData === null || workflowData === void 0 ? void 0 : workflowData.nodes) !== null && _a !== void 0 ? _a : ((_c = (_b = workflow === null || workflow === void 0 ? void 0 : workflow.definition) === null || _b === void 0 ? void 0 : _b.nodes) !== null && _c !== void 0 ? _c : []);
274
- };
275
- const markDefinitionSaved = (data) => {
276
- setHasUnsavedChanges(false);
540
+ const currentNodes = () => { var _a, _b, _c; return (_a = workflowData === null || workflowData === void 0 ? void 0 : workflowData.nodes) !== null && _a !== void 0 ? _a : ((_c = (_b = workflow === null || workflow === void 0 ? void 0 : workflow.definition) === null || _b === void 0 ? void 0 : _b.nodes) !== null && _c !== void 0 ? _c : []); };
541
+ const markDefinitionSaved = (saved) => {
277
542
  definitionNeedsSaveRef.current = false;
278
- initialWorkflowDataRef.current = JSON.stringify({
279
- nodes: data.nodes,
280
- edges: data.edges,
281
- });
543
+ initialWorkflowDataRef.current = saved;
544
+ if (latestGraphRef.current === saved)
545
+ setHasUnsavedChanges(false);
282
546
  };
283
- // Activate and Preview run what the server holds, which must match what
284
- // the canvas shows (e.g. old field names converted on open).
547
+ // Activate, Preview and Try run what the server holds, which must match
548
+ // what the canvas shows (e.g. old field names converted on open). Decided by
549
+ // content: an auto-save can still be on its way, or have landed after
550
+ // newer edits.
285
551
  const saveDefinitionIfNeeded = async () => {
286
552
  if (!workflowData)
287
553
  return;
288
- if (!definitionNeedsSaveRef.current && !hasUnsavedChanges)
554
+ const current = graphString(workflowData);
555
+ if (!definitionNeedsSaveRef.current && current === initialWorkflowDataRef.current)
289
556
  return;
290
557
  await patchWorkflow({
291
558
  org: tenantKey,
@@ -294,8 +561,31 @@ function WorkflowEditor({ tenantKey, workflowId, username, axdToken, baseWsUrl,
294
561
  definition: { nodes: workflowData.nodes, edges: workflowData.edges },
295
562
  },
296
563
  }).unwrap();
297
- markDefinitionSaved(workflowData);
564
+ markDefinitionSaved(current);
565
+ };
566
+ // The backend tries the saved step, so the canvas is saved first.
567
+ const tryClassifier = async (nodeId, input) => {
568
+ try {
569
+ await saveDefinitionIfNeeded();
570
+ }
571
+ catch (_a) {
572
+ return { ok: false, reason: 'save' };
573
+ }
574
+ try {
575
+ const result = await testWorkflowClassifier({
576
+ org: tenantKey,
577
+ uniqueId: workflowId,
578
+ data: { node_id: nodeId, input, variables: workflowDefinition.startVariableDefaults(currentNodes()) },
579
+ }).unwrap();
580
+ return { ok: true, output: result.output, model: result.model };
581
+ }
582
+ catch (err) {
583
+ return classifierTryFailure(err, t);
584
+ }
298
585
  };
586
+ const tryClassifierRef = React.useRef(tryClassifier);
587
+ tryClassifierRef.current = tryClassifier;
588
+ const handleTryClassifier = React.useCallback((nodeId, input) => tryClassifierRef.current(nodeId, input), []);
299
589
  const handlePreviewClick = async () => {
300
590
  try {
301
591
  await saveDefinitionIfNeeded();
@@ -308,14 +598,18 @@ function WorkflowEditor({ tenantKey, workflowId, username, axdToken, baseWsUrl,
308
598
  };
309
599
  const handleClosePreview = () => setIsPreviewMode(false);
310
600
  const handleNewChat = () => setNewChatSignal((signal) => signal + 1);
601
+ // Preview hides step settings (and, on a phone, the whole canvas), so
602
+ // going to a step leaves it.
603
+ const handleShowStep = (nodeId, field) => {
604
+ setIsPreviewMode(false);
605
+ setStepFocusRequest((previous) => { var _a; return ({ nodeId, field, nonce: ((_a = previous === null || previous === void 0 ? void 0 : previous.nonce) !== null && _a !== void 0 ? _a : 0) + 1 }); });
606
+ };
311
607
  const handleWorkflowStateChange = React.useCallback((state) => {
312
608
  var _a, _b;
313
609
  setWorkflowData(state);
610
+ latestGraphRef.current = graphString(state);
314
611
  if (initialWorkflowDataRef.current === null) {
315
- initialWorkflowDataRef.current = JSON.stringify({
316
- nodes: state.nodes,
317
- edges: state.edges,
318
- });
612
+ initialWorkflowDataRef.current = latestGraphRef.current;
319
613
  const saved = savedDefinitionRef.current;
320
614
  const savedNodes = ((_a = saved === null || saved === void 0 ? void 0 : saved.nodes) !== null && _a !== void 0 ? _a : []);
321
615
  const savedEdges = ((_b = saved === null || saved === void 0 ? void 0 : saved.edges) !== null && _b !== void 0 ? _b : []);
@@ -356,13 +650,66 @@ function WorkflowEditor({ tenantKey, workflowId, username, axdToken, baseWsUrl,
356
650
  uniqueId: workflowId,
357
651
  data: patchData,
358
652
  }).unwrap();
359
- markDefinitionSaved(workflowData);
653
+ markDefinitionSaved(graphString(workflowData));
360
654
  sonner.toast.success(t('workflowsWorkflowEditor.workflowSaved'));
361
655
  }
362
656
  catch (_a) {
363
657
  sonner.toast.error(t('workflowsWorkflowEditor.failedToSaveWorkflow'));
364
658
  }
365
659
  };
660
+ const saveShortcutRef = React.useRef(() => { });
661
+ const shortcutSaveWaitingRef = React.useRef(false);
662
+ React.useEffect(() => {
663
+ saveShortcutRef.current = () => {
664
+ if (isPreviewMode)
665
+ return;
666
+ // Clicking Save blurs the name field, which saves the name; a key press
667
+ // leaves it focused.
668
+ if (isEditingName)
669
+ void handleNameSave();
670
+ // An auto-save or rename shares the request: save once it lands rather
671
+ // than drop the press.
672
+ if (isSaving) {
673
+ shortcutSaveWaitingRef.current = true;
674
+ return;
675
+ }
676
+ void handleSave();
677
+ };
678
+ });
679
+ React.useEffect(() => {
680
+ if (isSaving || !shortcutSaveWaitingRef.current)
681
+ return;
682
+ shortcutSaveWaitingRef.current = false;
683
+ saveShortcutRef.current();
684
+ }, [isSaving]);
685
+ // Cmd+S (Ctrl+S off a Mac) would otherwise open the browser's Save Page
686
+ // dialog; people press it out of habit to save their work.
687
+ React.useEffect(() => {
688
+ const onKeyDown = (event) => {
689
+ if (!(event.metaKey || event.ctrlKey) || event.shiftKey || event.altKey)
690
+ return;
691
+ if (event.isComposing)
692
+ return;
693
+ // The physical S key only counts on layouts without Latin letters; on
694
+ // Dvorak it types "o" and Cmd+O must stay Open.
695
+ const isS = /^[a-z]$/i.test(event.key)
696
+ ? event.key.toLowerCase() === 's'
697
+ : event.code === 'KeyS';
698
+ if (!isS)
699
+ return;
700
+ event.preventDefault();
701
+ if (event.repeat)
702
+ return;
703
+ // Another window, such as Edit Agent, may be open over the editor.
704
+ const active = document.activeElement;
705
+ if (active === null || active === void 0 ? void 0 : active.closest('[role="dialog"], [role="alertdialog"]'))
706
+ return;
707
+ saveShortcutRef.current();
708
+ };
709
+ window.addEventListener('keydown', onKeyDown);
710
+ return () => window.removeEventListener('keydown', onKeyDown);
711
+ }, []);
712
+ const headerFit = useOverflowFit.useOverflowFit(HEADER_ACTIONS.map((key) => ({ key, estimate: HEADER_ACTION_ESTIMATES[key] })), [], HEADER_FIT_OPTIONS);
366
713
  const handlePublish = async () => {
367
714
  const data = workflowData
368
715
  ? { definition: { nodes: workflowData.nodes, edges: workflowData.edges } }
@@ -374,7 +721,7 @@ function WorkflowEditor({ tenantKey, workflowId, username, axdToken, baseWsUrl,
374
721
  data,
375
722
  }).unwrap();
376
723
  if (workflowData)
377
- markDefinitionSaved(workflowData);
724
+ markDefinitionSaved(graphString(workflowData));
378
725
  setValidationResult(null);
379
726
  sonner.toast.success(t('workflowsWorkflowEditor.workflowPublished'));
380
727
  }
@@ -437,6 +784,7 @@ function WorkflowEditor({ tenantKey, workflowId, username, axdToken, baseWsUrl,
437
784
  }
438
785
  };
439
786
  const handleDeleteConfirm = async () => {
787
+ deleteStartedRef.current = true;
440
788
  try {
441
789
  await deleteWorkflow({
442
790
  org: tenantKey,
@@ -447,14 +795,15 @@ function WorkflowEditor({ tenantKey, workflowId, username, axdToken, baseWsUrl,
447
795
  onDeleted();
448
796
  }
449
797
  catch (_a) {
798
+ deleteStartedRef.current = false;
450
799
  sonner.toast.error(t('workflowsWorkflowEditor.failedToDeleteWorkflow'));
451
800
  }
452
801
  };
453
802
  if (isLoading || isWaitingForMentorSettings) {
454
- return (jsxRuntime.jsx("div", { className: "flex h-screen items-center justify-center", children: jsxRuntime.jsx(loaderCircle.default, { className: "h-8 w-8 animate-spin text-gray-400" }) }));
803
+ return (jsxRuntime.jsx("div", { className: "flex h-full items-center justify-center", children: jsxRuntime.jsx(loaderCircle.default, { className: "h-8 w-8 animate-spin text-gray-400" }) }));
455
804
  }
456
805
  if (error || !workflow) {
457
- return (jsxRuntime.jsx("div", { className: "flex h-screen items-center justify-center", children: jsxRuntime.jsxs("div", { className: "text-center", children: [jsxRuntime.jsx(circleAlert.default, { className: "mx-auto mb-4 h-12 w-12 text-red-500" }), jsxRuntime.jsx("p", { className: "mb-4 text-gray-600", children: t('workflowsWorkflowEditor.failedToLoadWorkflow') }), jsxRuntime.jsxs(button.Button, { variant: "outline", className: "h-9 has-[>svg]:px-3", onClick: () => onBack(), children: [jsxRuntime.jsx(chevronLeft.default, { className: "mr-2 h-4 w-4" }), t('workflowsWorkflowEditor.goBack')] })] }) }));
806
+ return (jsxRuntime.jsx("div", { className: "flex h-full items-center justify-center", children: jsxRuntime.jsxs("div", { className: "text-center", children: [jsxRuntime.jsx(circleAlert.default, { className: "mx-auto mb-4 h-12 w-12 text-red-500" }), jsxRuntime.jsx("p", { className: "mb-4 text-gray-600", children: t('workflowsWorkflowEditor.failedToLoadWorkflow') }), jsxRuntime.jsxs(button.Button, { variant: "outline", className: "h-9 has-[>svg]:px-3", onClick: () => onBack(), children: [jsxRuntime.jsx(chevronLeft.default, { className: "mr-2 h-4 w-4" }), t('workflowsWorkflowEditor.goBack')] })] }) }));
458
807
  }
459
808
  // Workflows saved with the builder's old field names open with the names
460
809
  // the backend reads; the next save stores them.
@@ -463,23 +812,29 @@ function WorkflowEditor({ tenantKey, workflowId, username, axdToken, baseWsUrl,
463
812
  const nodeData = n.data;
464
813
  if (n.type === 'mentor') {
465
814
  const mentorId = (nodeData === null || nodeData === void 0 ? void 0 : nodeData.mentor_id) ||
466
- (nodeData === null || nodeData === void 0 ? void 0 : nodeData.entry_mentor_id) ||
467
- entryMentorId;
815
+ (nodeData === null || nodeData === void 0 ? void 0 : nodeData.entry_mentor_id);
468
816
  const mentorData = mentorId ? mentorSettingsById[mentorId] : null;
817
+ const systemPrompt = mentorData === null || mentorData === void 0 ? void 0 : mentorData.system_prompt;
818
+ // Earlier builds saved the agent's own prompt, or a placeholder, as the
819
+ // step's instructions; the backend ignores both, so neither is shown or
820
+ // saved again.
821
+ const { instructions: _ignoredInstructions, ...withoutInstructions } = nodeData;
822
+ const stepData = workflowDefinition.isAuthoredInstructions(nodeData.instructions, typeof systemPrompt === 'string' ? systemPrompt : undefined)
823
+ ? nodeData
824
+ : withoutInstructions;
469
825
  return {
470
826
  ...n,
471
827
  draggable: true,
472
828
  selectable: true,
473
829
  connectable: true,
474
830
  data: {
475
- ...nodeData,
831
+ ...stepData,
476
832
  ...(mentorId ? { entry_mentor_id: mentorId } : {}),
477
- // The agent's current settings win over what the step saved.
833
+ // The agent's current name and model win over what the step saved.
478
834
  ...(mentorData && {
479
835
  label: mentorData.display_name ||
480
836
  mentorData.mentor_name ||
481
837
  (nodeData === null || nodeData === void 0 ? void 0 : nodeData.label),
482
- instructions: mentorData.system_prompt || (nodeData === null || nodeData === void 0 ? void 0 : nodeData.instructions),
483
838
  model: mentorData.llm_name || (nodeData === null || nodeData === void 0 ? void 0 : nodeData.model),
484
839
  }),
485
840
  },
@@ -493,14 +848,63 @@ function WorkflowEditor({ tenantKey, workflowId, username, axdToken, baseWsUrl,
493
848
  };
494
849
  });
495
850
  const initialEdges = definition.edges;
496
- return (jsxRuntime.jsxs("div", { className: "flex h-screen flex-col bg-white", children: [jsxRuntime.jsxs("div", { className: `flex items-center justify-between px-4 py-3 ${isPreviewMode ? 'border-b border-gray-200 bg-white' : 'bg-background border-border border-b'}`, children: [jsxRuntime.jsx("div", { className: "flex items-center gap-3", children: isPreviewMode ? (jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [jsxRuntime.jsx("h1", { className: "text-foreground font-medium", children: workflowName }), jsxRuntime.jsx("span", { className: `rounded-md px-2 py-0.5 text-xs ${workflow.is_active ? 'bg-green-100 text-green-700' : 'bg-muted text-muted-foreground'}`, children: workflow.is_active
851
+ // The backend also reports a workflow that was never published as changed.
852
+ const hasUnpublishedChanges = workflow.has_unpublished_changes === true && Boolean(workflow.published_at);
853
+ const unpublishedMarker = hasUnpublishedChanges && (jsxRuntime.jsx("span", { "data-testid": "workflow-unpublished-changes", className: "text-muted-foreground text-xs", children: t('workflowsWorkflowEditor.unpublishedChanges') }));
854
+ // Named from the canvas as it is now: a step deleted since the check has
855
+ // nothing to show, and a renamed one shows its new name.
856
+ const shownSteps = stepsOf(currentNodes());
857
+ const problemLine = ({ text, stepId, field }) => {
858
+ var _a;
859
+ const step = stepId ? shownSteps.find(stepId) : undefined;
860
+ if (!step)
861
+ return jsxRuntime.jsx("span", { children: text });
862
+ return (jsxRuntime.jsx(actionTooltip.ActionTooltip, { label: t('workflowsWorkflowEditor.goToStep', { name: ((_a = step.data) === null || _a === void 0 ? void 0 : _a.label) || step.id }), children: jsxRuntime.jsx("button", { type: "button", className: PROBLEM_LINK, onClick: () => handleShowStep(step.id, field), children: text }) }));
863
+ };
864
+ canvasShownRef.current = true;
865
+ return (
866
+ // Hosts render the editor below their own top bar: a window-tall editor
867
+ // ran past it and the host cut off the preview's message box.
868
+ jsxRuntime.jsxs("div", { className: "flex h-full flex-col bg-white", children: [jsxRuntime.jsxs("div", { className: `bg-background border-border flex items-center justify-between gap-4 border-b px-4 py-3 ${isPreviewMode ? 'max-md:flex-wrap max-md:gap-y-2' : ''}`, children: [jsxRuntime.jsx("div", { className: "flex min-w-0 items-center gap-3", children: isPreviewMode ? (jsxRuntime.jsxs("div", { className: "flex min-w-0 items-center gap-2", children: [jsxRuntime.jsx("h1", { className: HEADER_NAME, children: workflowName }), jsxRuntime.jsx("span", { className: `shrink-0 rounded-md px-2 py-0.5 text-xs whitespace-nowrap ${workflow.is_active ? 'bg-green-100 text-green-700' : 'bg-muted text-muted-foreground'}`, children: workflow.is_active
497
869
  ? t('workflowsWorkflowEditor.statusActive')
498
- : t('workflowsWorkflowEditor.statusDraft') })] })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(button.Button, { variant: "ghost", size: "icon", className: "h-9 w-9 text-muted-foreground hover:text-foreground", onClick: () => onBack(), children: jsxRuntime.jsx(chevronLeft.default, { className: "h-5 w-5" }) }), jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [isEditingName ? (jsxRuntime.jsx(input.Input, { value: workflowName, onChange: (e) => setWorkflowName(e.target.value), onBlur: handleNameSave, onKeyDown: (e) => e.key === 'Enter' && handleNameSave(), className: "text-foreground h-8 w-[200px] font-medium", autoFocus: true, "aria-label": t('workflowsWorkflowEditor.enterWorkflowNameLabel') })) : (jsxRuntime.jsxs("button", { onClick: () => setIsEditingName(true), className: "text-foreground hover:text-foreground/80 flex items-center gap-1 font-medium", "aria-label": t('workflowsWorkflowEditor.editWorkflowNameLabel'), children: [workflowName, jsxRuntime.jsx(pencil.default, { className: "h-3 w-3 opacity-50" })] })), jsxRuntime.jsx("span", { className: `rounded-md px-2 py-0.5 text-xs ${workflow.is_active ? 'bg-green-100 text-green-700' : 'bg-muted text-muted-foreground'}`, children: workflow.is_active
499
- ? t('workflowsWorkflowEditor.statusActive')
500
- : t('workflowsWorkflowEditor.statusDraft') }), hasUnsavedChanges && (jsxRuntime.jsx("span", { className: "text-muted-foreground text-xs", children: t('workflowsWorkflowEditor.unsaved') }))] })] })) }), jsxRuntime.jsx("div", { className: "flex items-center gap-2", children: isPreviewMode ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs(button.Button, { variant: "ghost", size: "sm", className: "h-8 gap-1.5 has-[>svg]:px-2.5 text-foreground hover:text-foreground hover:bg-gray-100", onClick: handleClosePreview, children: [jsxRuntime.jsx(x.default, { className: "mr-2 h-4 w-4" }), t('workflowsWorkflowEditor.closePreview')] }), jsxRuntime.jsxs(button.Button, { variant: "ghost", size: "sm", className: "h-8 gap-1.5 has-[>svg]:px-2.5 text-foreground hover:text-foreground hover:bg-gray-100", onClick: handleNewChat, "aria-label": t('workflowsWorkflowEditor.newChatLabel'), children: [jsxRuntime.jsx(rotateCcw.default, { className: "mr-2 h-4 w-4" }), t('workflowsWorkflowEditor.newChat')] }), jsxRuntime.jsx(button.Button, { size: "sm", className: "h-8 gap-1.5 has-[>svg]:px-2.5 bg-[#38A1E5] text-white hover:bg-[#38A1E5]/90", onClick: handlePublish, disabled: isPublishing, children: isPublishing ? (jsxRuntime.jsx(loaderCircle.default, { className: "h-4 w-4 animate-spin" })) : (t('workflowsWorkflowEditor.publish')) })] })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs(dropdownMenu.DropdownMenu, { children: [jsxRuntime.jsx(dropdownMenu.DropdownMenuTrigger, { asChild: true, children: jsxRuntime.jsx(button.Button, { variant: "ghost", size: "icon", className: "h-9 w-9 text-muted-foreground hover:text-foreground", "aria-label": t('workflowsWorkflowEditor.moreOptionsLabel'), children: jsxRuntime.jsx(ellipsis.default, { className: "h-5 w-5" }) }) }), jsxRuntime.jsxs(dropdownMenu.DropdownMenuContent, { align: "end", children: [workflow.is_active ? (jsxRuntime.jsxs(dropdownMenu.DropdownMenuItem, { onClick: handleDeactivate, children: [jsxRuntime.jsx(power.default, { className: "mr-2 h-4 w-4" }), t('workflowsWorkflowEditor.deactivate')] })) : (jsxRuntime.jsxs(dropdownMenu.DropdownMenuItem, { onClick: handleActivate, disabled: isActivating, children: [jsxRuntime.jsx(power.default, { className: "mr-2 h-4 w-4" }), isActivating
501
- ? t('workflowsWorkflowEditor.activating')
502
- : t('workflowsWorkflowEditor.activate')] })), jsxRuntime.jsxs(dropdownMenu.DropdownMenuItem, { onClick: () => setIsDeleteModalOpen(true), className: "text-red-600", children: [jsxRuntime.jsx(trash2.default, { className: "mr-2 h-4 w-4" }), t('workflowsWorkflowEditor.delete')] })] })] }), jsxRuntime.jsxs(button.Button, { variant: "outline", size: "sm", className: "h-8 gap-1.5 has-[>svg]:px-2.5 text-foreground border-border hover:bg-accent bg-transparent", onClick: handlePreviewClick, children: [jsxRuntime.jsx(eye.default, { className: "mr-2 h-4 w-4" }), t('workflowsWorkflowEditor.preview')] }), jsxRuntime.jsx(button.Button, { size: "sm", className: "h-8 gap-1.5 has-[>svg]:px-2.5 bg-[#38A1E5] text-white hover:bg-[#38A1E5]/90", onClick: handleSave, disabled: isSaving, children: isSaving ? (jsxRuntime.jsx(loaderCircle.default, { className: "h-4 w-4 animate-spin" })) : (t('workflowsWorkflowEditor.save')) }), jsxRuntime.jsx(button.Button, { size: "sm", className: "h-8 gap-1.5 has-[>svg]:px-2.5 bg-[#38A1E5] text-white hover:bg-[#38A1E5]/90", onClick: handlePublish, disabled: isPublishing, children: isPublishing ? (jsxRuntime.jsx(loaderCircle.default, { className: "h-4 w-4 animate-spin" })) : (t('workflowsWorkflowEditor.publish')) })] })) })] }), validationResult &&
503
- (validationResult.errors.length > 0 || validationResult.warnings.length > 0) && (jsxRuntime.jsx(collapsible.Collapsible, { open: isValidationBannerOpen, onOpenChange: setIsValidationBannerOpen, children: jsxRuntime.jsxs("div", { className: "border-border bg-background border-b px-4 py-2", children: [jsxRuntime.jsx(collapsible.CollapsibleTrigger, { asChild: true, children: jsxRuntime.jsxs("button", { className: "flex w-full items-center justify-between text-sm", children: [jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [validationResult.errors.length > 0 ? (jsxRuntime.jsx(circleAlert.default, { className: "h-4 w-4 text-red-500" })) : (jsxRuntime.jsx(triangleAlert.default, { className: "h-4 w-4 text-amber-500" })), jsxRuntime.jsxs("span", { className: validationResult.errors.length > 0 ? 'text-red-700' : 'text-amber-700', children: [validationResult.errors.length > 0 &&
870
+ : t('workflowsWorkflowEditor.statusDraft') }), unpublishedMarker] })) : (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs("div", { className: "flex min-w-0 items-center gap-2", children: [isEditingName ? (jsxRuntime.jsx(input.Input, { value: workflowName, onChange: (e) => setWorkflowName(e.target.value), onBlur: handleNameSave, onKeyDown: (e) => e.key === 'Enter' && handleNameSave(), className: "text-foreground h-9 w-[200px] min-w-0 font-medium", autoFocus: true, "aria-label": t('workflowsWorkflowEditor.enterWorkflowNameLabel') })) : (jsxRuntime.jsxs("div", { className: "flex min-w-0 items-center gap-1", children: [jsxRuntime.jsx("h1", { className: HEADER_NAME, children: workflowName }), jsxRuntime.jsx(actionTooltip.ActionTooltip, { label: t('workflowsWorkflowEditor.editWorkflowNameLabel'), children: jsxRuntime.jsx(button.Button, { variant: "ghost", size: "icon", className: "h-9 w-9 shrink-0 text-muted-foreground hover:text-foreground [&_svg]:size-3.5", onClick: () => setIsEditingName(true), "aria-label": t('workflowsWorkflowEditor.editWorkflowNameLabel'), children: jsxRuntime.jsx(pencil.default, { strokeWidth: 2.25 }) }) })] })), jsxRuntime.jsx("span", { className: `shrink-0 rounded-md px-2 py-0.5 text-xs whitespace-nowrap ${workflow.is_active ? 'bg-green-100 text-green-700' : 'bg-muted text-muted-foreground'}`, children: workflow.is_active
871
+ ? t('workflowsWorkflowEditor.statusActive')
872
+ : t('workflowsWorkflowEditor.statusDraft') }), unpublishedMarker, hasUnsavedChanges ? (jsxRuntime.jsx("span", { className: "text-muted-foreground shrink-0 text-xs whitespace-nowrap", children: t('workflowsWorkflowEditor.unsaved') })) : (
873
+ // Holds the marker's width so the header's buttons don't move
874
+ // in and out of the "…" menu around every edit and auto-save.
875
+ jsxRuntime.jsx("span", { "aria-hidden": "true", "data-label": t('workflowsWorkflowEditor.unsaved'), className: "invisible shrink-0 text-xs whitespace-nowrap after:content-[attr(data-label)]" }))] }) })) }), jsxRuntime.jsx("div", { ref: headerFit.rootRef, "data-testid": "workflow-header-actions", "data-fit": headerFit.visibleCount === null ? 'pending' : 'done',
876
+ // In Preview the three buttons keep their width and their words: the
877
+ // name wraps beside them, and below md they take a row of their own.
878
+ // The edit actions must shrink for the "…" menu to measure.
879
+ className: `flex flex-1 items-center justify-end gap-2 ${isPreviewMode ? 'min-w-fit max-md:basis-full max-md:justify-start' : 'min-w-9'}`, children: isPreviewMode ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs(button.Button, { variant: "ghost", size: "sm", className: HEADER_GHOST_BUTTON, onClick: handleClosePreview, children: [jsxRuntime.jsx(x.default, {}), t('workflowsWorkflowEditor.closePreview')] }), jsxRuntime.jsxs(button.Button, { variant: "ghost", size: "sm", className: HEADER_GHOST_BUTTON, onClick: handleNewChat, "aria-label": t('workflowsWorkflowEditor.newChatLabel'), children: [jsxRuntime.jsx(rotateCcw.default, {}), t('workflowsWorkflowEditor.newChat')] }), jsxRuntime.jsx(button.Button, { size: "sm", className: HEADER_PRIMARY_BUTTON, onClick: handlePublish, disabled: isPublishing, "aria-busy": isPublishing, children: jsxRuntime.jsx(BusyLabel, { busy: isPublishing, children: t('workflowsWorkflowEditor.publish') }) })] })) : ((() => {
880
+ var _a;
881
+ const inlineCount = (_a = headerFit.visibleCount) !== null && _a !== void 0 ? _a : HEADER_UNMEASURED_INLINE;
882
+ const menuActions = HEADER_ACTIONS.slice(inlineCount);
883
+ const inlineActions = HEADER_ACTIONS.slice(0, inlineCount).reverse();
884
+ const statusLabel = workflow.is_active
885
+ ? t('workflowsWorkflowEditor.deactivate')
886
+ : isActivating
887
+ ? t('workflowsWorkflowEditor.activating')
888
+ : t('workflowsWorkflowEditor.activate');
889
+ const onStatus = workflow.is_active ? handleDeactivate : handleActivate;
890
+ const statusDisabled = !workflow.is_active && isActivating;
891
+ const inlineButton = {
892
+ delete: (jsxRuntime.jsxs(button.Button, { variant: "outline", size: "sm", className: `${HEADER_OUTLINE_BUTTON} text-red-600 hover:text-red-700`, onClick: () => setIsDeleteModalOpen(true), children: [jsxRuntime.jsx(trash2.default, {}), t('workflowsWorkflowEditor.delete')] })),
893
+ status: (jsxRuntime.jsxs(button.Button, { variant: "outline", size: "sm", className: `${HEADER_OUTLINE_BUTTON} text-foreground`, onClick: onStatus, disabled: statusDisabled, children: [jsxRuntime.jsx(power.default, {}), statusLabel] })),
894
+ preview: (jsxRuntime.jsxs(button.Button, { variant: "outline", size: "sm", className: `${HEADER_OUTLINE_BUTTON} text-foreground`, onClick: handlePreviewClick, children: [jsxRuntime.jsx(eye.default, {}), t('workflowsWorkflowEditor.preview')] })),
895
+ save: (jsxRuntime.jsx(actionTooltip.ActionTooltip, { label: shortcuts.withShortcut(t('workflowsWorkflowEditor.save'), 'save'), children: jsxRuntime.jsx(button.Button, { size: "sm", className: HEADER_PRIMARY_BUTTON, onClick: handleSave, disabled: isSaving, "aria-busy": isSaving, "aria-keyshortcuts": shortcuts.ariaShortcut('save'), children: jsxRuntime.jsx(BusyLabel, { busy: isSaving, children: t('workflowsWorkflowEditor.save') }) }) })),
896
+ publish: (jsxRuntime.jsx(button.Button, { size: "sm", className: HEADER_PRIMARY_BUTTON, onClick: handlePublish, disabled: isPublishing, "aria-busy": isPublishing, children: jsxRuntime.jsx(BusyLabel, { busy: isPublishing, children: t('workflowsWorkflowEditor.publish') }) })),
897
+ };
898
+ const menuItem = {
899
+ publish: (jsxRuntime.jsxs(dropdownMenu.DropdownMenuItem, { onClick: handlePublish, disabled: isPublishing, children: [jsxRuntime.jsx(upload.default, {}), t('workflowsWorkflowEditor.publish')] })),
900
+ save: (jsxRuntime.jsxs(dropdownMenu.DropdownMenuItem, { onClick: handleSave, disabled: isSaving, children: [jsxRuntime.jsx(save.default, {}), t('workflowsWorkflowEditor.save')] })),
901
+ preview: (jsxRuntime.jsxs(dropdownMenu.DropdownMenuItem, { onClick: handlePreviewClick, children: [jsxRuntime.jsx(eye.default, {}), t('workflowsWorkflowEditor.preview')] })),
902
+ status: (jsxRuntime.jsxs(dropdownMenu.DropdownMenuItem, { onClick: onStatus, disabled: statusDisabled, children: [jsxRuntime.jsx(power.default, {}), statusLabel] })),
903
+ delete: (jsxRuntime.jsxs(dropdownMenu.DropdownMenuItem, { onClick: () => setIsDeleteModalOpen(true), className: "text-red-600", children: [jsxRuntime.jsx(trash2.default, {}), t('workflowsWorkflowEditor.delete')] })),
904
+ };
905
+ return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [menuActions.length > 0 && (jsxRuntime.jsxs(dropdownMenu.DropdownMenu, { children: [jsxRuntime.jsx(actionTooltip.ActionTooltip, { label: t('workflowsWorkflowEditor.moreOptionsLabel'), children: jsxRuntime.jsx(dropdownMenu.DropdownMenuTrigger, { asChild: true, children: jsxRuntime.jsx(button.Button, { variant: "ghost", size: "icon", className: "h-9 w-9 shrink-0 text-muted-foreground hover:text-foreground", "aria-label": t('workflowsWorkflowEditor.moreOptionsLabel'), children: jsxRuntime.jsx(ellipsis.default, {}) }) }) }), jsxRuntime.jsx(dropdownMenu.DropdownMenuContent, { align: "end", children: menuActions.map((key) => (jsxRuntime.jsx(React.Fragment, { children: menuItem[key] }, key))) })] })), inlineActions.map((key) => (jsxRuntime.jsx("div", { ref: headerFit.itemRef(key), "data-header-action": key, className: "shrink-0", children: inlineButton[key] }, key)))] }));
906
+ })()) })] }), validationResult &&
907
+ (validationResult.errors.length > 0 || validationResult.warnings.length > 0) && (jsxRuntime.jsx(collapsible.Collapsible, { open: isValidationBannerOpen, onOpenChange: setIsValidationBannerOpen, children: jsxRuntime.jsxs("div", { className: "border-border bg-background border-b px-4 py-2", children: [jsxRuntime.jsx(collapsible.CollapsibleTrigger, { asChild: true, children: jsxRuntime.jsxs("button", { className: "flex w-full items-center justify-between gap-2 text-sm", children: [jsxRuntime.jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-x-2 text-left", children: [jsxRuntime.jsx(listChecks.default, { className: "text-muted-foreground h-4 w-4 shrink-0" }), jsxRuntime.jsx("span", { className: "text-foreground font-medium", children: t('workflowsWorkflowEditor.problemsTitle') }), jsxRuntime.jsx("span", { "aria-hidden": "true", className: "text-muted-foreground", children: "\u00B7" }), jsxRuntime.jsxs("span", { className: "text-muted-foreground", children: [validationResult.errors.length > 0 &&
504
908
  t('workflowsWorkflowEditor.validationErrors', {
505
909
  count: validationResult.errors.length,
506
910
  }), validationResult.errors.length > 0 &&
@@ -508,7 +912,7 @@ function WorkflowEditor({ tenantKey, workflowId, username, axdToken, baseWsUrl,
508
912
  ', ', validationResult.warnings.length > 0 &&
509
913
  t('workflowsWorkflowEditor.validationWarnings', {
510
914
  count: validationResult.warnings.length,
511
- })] })] }), jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [isValidationBannerOpen ? (jsxRuntime.jsx(chevronUp.default, { className: "text-muted-foreground h-4 w-4" })) : (jsxRuntime.jsx(chevronDown.default, { className: "text-muted-foreground h-4 w-4" })), jsxRuntime.jsx("span", { role: "button", tabIndex: 0, className: "text-muted-foreground hover:text-foreground", onClick: (e) => {
915
+ })] })] }), jsxRuntime.jsxs("div", { className: "flex shrink-0 items-center gap-2", children: [isValidationBannerOpen ? (jsxRuntime.jsx(chevronUp.default, { className: "text-muted-foreground h-4 w-4" })) : (jsxRuntime.jsx(chevronDown.default, { className: "text-muted-foreground h-4 w-4" })), jsxRuntime.jsx("span", { role: "button", tabIndex: 0, className: "text-muted-foreground hover:text-foreground", onClick: (e) => {
512
916
  e.stopPropagation();
513
917
  setValidationResult(null);
514
918
  }, onKeyDown: (e) => {
@@ -516,7 +920,14 @@ function WorkflowEditor({ tenantKey, workflowId, username, axdToken, baseWsUrl,
516
920
  e.stopPropagation();
517
921
  setValidationResult(null);
518
922
  }
519
- }, children: jsxRuntime.jsx(x.default, { className: "h-4 w-4" }) })] })] }) }), jsxRuntime.jsx(collapsible.CollapsibleContent, { children: jsxRuntime.jsxs("div", { className: "mt-2 space-y-1 pb-1", children: [validationResult.errors.map((error, i) => (jsxRuntime.jsxs("div", { className: "flex items-start gap-2 text-sm text-red-600", children: [jsxRuntime.jsx(circleAlert.default, { className: "mt-0.5 h-3.5 w-3.5 shrink-0" }), jsxRuntime.jsx("span", { children: error })] }, `error-${i}`))), validationResult.warnings.map((warning, i) => (jsxRuntime.jsxs("div", { className: "flex items-start gap-2 text-sm text-amber-600", children: [jsxRuntime.jsx(triangleAlert.default, { className: "mt-0.5 h-3.5 w-3.5 shrink-0" }), jsxRuntime.jsx("span", { children: warning })] }, `warning-${i}`)))] }) })] }) })), jsxRuntime.jsxs("div", { className: "flex flex-1 overflow-hidden", children: [!isPreviewMode && (jsxRuntime.jsx(workflowSidebar.WorkflowSidebar, { onDragStart: setDraggedItem, onItemClick: handleItemClick, nodeTypes: nodeTypeSections })), jsxRuntime.jsx("div", { className: isPreviewMode ? 'h-full w-[60%] border-r border-gray-200' : 'h-full flex-1', children: jsxRuntime.jsx(workflowCanvas.WorkflowCanvas, { onDraggedItem: isPreviewMode ? null : draggedItem, onClickedItem: isPreviewMode ? null : clickedItem, previewMode: isPreviewMode, initialNodes: initialNodes, initialEdges: initialEdges, onStateChange: handleWorkflowStateChange, org: tenantKey, defaultMentorId: entryMentorId, username: username, onOpenAgentSettings: onOpenAgentSettings, agentSettings: agentSettings }) }), isPreviewMode && (jsxRuntime.jsx("div", { className: "flex h-full w-[40%] flex-col bg-white", children: jsxRuntime.jsx(workflowPreviewChat.WorkflowPreviewChat, { tenantKey: tenantKey, mentorId: entryMentorId, username: username, axdToken: axdToken, baseWsUrl: baseWsUrl, redirectToAuthSpa: redirectToAuthSpa, newChatSignal: newChatSignal }, previewKey) }))] }), jsxRuntime.jsx(deleteWorkflowModal.DeleteWorkflowModal, { isOpen: isDeleteModalOpen, onClose: () => setIsDeleteModalOpen(false), onConfirm: handleDeleteConfirm, isDeleting: isDeleting, workflowName: workflow.name })] }));
923
+ }, children: jsxRuntime.jsx(x.default, { className: "h-4 w-4" }) })] })] }) }), jsxRuntime.jsx(collapsible.CollapsibleContent, { children: jsxRuntime.jsxs("div", { "data-testid": "workflow-validation-list", className: "mt-2 max-h-40 space-y-1 overflow-y-auto pb-1", children: [validationResult.errors.map((error, i) => (jsxRuntime.jsxs("div", { className: "flex items-start gap-2 text-sm text-red-600", children: [jsxRuntime.jsx(circleAlert.default, { className: "mt-0.5 h-3.5 w-3.5 shrink-0" }), problemLine(error)] }, `error-${i}`))), validationResult.warnings.map((warning, i) => (jsxRuntime.jsxs("div", { className: "flex items-start gap-2 text-sm text-amber-600", children: [jsxRuntime.jsx(triangleAlert.default, { className: "mt-0.5 h-3.5 w-3.5 shrink-0" }), problemLine(warning)] }, `warning-${i}`)))] }) })] }) })), jsxRuntime.jsxs("div", { className: "flex flex-1 overflow-hidden", children: [!isPreviewMode && (jsxRuntime.jsx(workflowSidebar.WorkflowSidebar, { className: "hidden md:block", onDragStart: setDraggedItem, onItemClick: handleItemClick, nodeTypes: nodeTypeSections })), jsxRuntime.jsxs("div", { className: isPreviewMode
924
+ ? // Kept mounted on phones so Close Preview returns to the same
925
+ // view and undo history.
926
+ 'hidden h-full md:block md:w-[60%] md:border-r md:border-gray-200'
927
+ : 'relative h-full min-w-0 flex-1', children: [jsxRuntime.jsx(workflowCanvas.WorkflowCanvas, { onDraggedItem: isPreviewMode ? null : draggedItem, onClickedItem: isPreviewMode ? null : clickedItem, previewMode: isPreviewMode, initialNodes: initialNodes, initialEdges: initialEdges, onStateChange: handleWorkflowStateChange, org: tenantKey, defaultMentorId: entryMentorId, username: username, onOpenAgentSettings: onOpenAgentSettings, agentSettings: agentSettings, classifierModels: classifierModels, onTryClassifier: handleTryClassifier, focusRequest: stepFocusRequest }), !isPreviewMode && (jsxRuntime.jsxs(button.Button, { variant: "outline", size: "sm", className: "bg-card border-border absolute top-3 left-3 z-10 h-9 gap-1.5 shadow-sm md:hidden", onClick: () => setIsStepListOpen(true), children: [jsxRuntime.jsx(plus.default, {}), t('workflowsWorkflowEditor.addStep')] }))] }), isPreviewMode && (jsxRuntime.jsx("div", { className: "flex h-full w-full flex-col bg-white md:w-[40%]", children: jsxRuntime.jsx(workflowPreviewChat.WorkflowPreviewChat, { tenantKey: tenantKey, mentorId: entryMentorId, username: username, axdToken: axdToken, baseWsUrl: baseWsUrl, redirectToAuthSpa: redirectToAuthSpa, newChatSignal: newChatSignal }, previewKey) }))] }), jsxRuntime.jsx(sheet.Sheet, { open: isStepListOpen, onOpenChange: setIsStepListOpen, children: jsxRuntime.jsxs(sheet.SheetContent, { side: "bottom", className: "max-h-[80dvh] gap-0 rounded-t-xl p-0", children: [jsxRuntime.jsxs(sheet.SheetHeader, { className: "border-border border-b p-4", children: [jsxRuntime.jsx(sheet.SheetTitle, { children: t('workflowsWorkflowEditor.addStep') }), jsxRuntime.jsx(sheet.SheetDescription, { className: "sr-only", children: t('workflowsWorkflowEditor.addStepDescription') })] }), jsxRuntime.jsx(workflowSidebar.WorkflowSidebar, { className: "min-h-0 w-full border-r-0", onDragStart: setDraggedItem, onItemClick: (item) => {
928
+ handleItemClick(item);
929
+ setIsStepListOpen(false);
930
+ }, nodeTypes: nodeTypeSections })] }) }), jsxRuntime.jsx(deleteWorkflowModal.DeleteWorkflowModal, { isOpen: isDeleteModalOpen, onClose: () => setIsDeleteModalOpen(false), onConfirm: handleDeleteConfirm, isDeleting: isDeleting, workflowName: workflow.name })] }));
520
931
  }
521
932
 
522
933
  exports.WorkflowEditor = WorkflowEditor;