@iblai/web-containers 2.4.0 → 2.6.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 (89) 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/ai-message-bubble.js +2 -1
  4. package/dist/cjs/components/chat/ai-message-bubble.js.map +1 -1
  5. package/dist/cjs/components/chat/chat-host-context.js.map +1 -1
  6. package/dist/cjs/components/chat/client-ui-tools/definitions.js +187 -0
  7. package/dist/cjs/components/chat/client-ui-tools/definitions.js.map +1 -0
  8. package/dist/cjs/components/chat/client-ui-tools/panel-list.js +91 -0
  9. package/dist/cjs/components/chat/client-ui-tools/panel-list.js.map +1 -0
  10. package/dist/cjs/components/chat/client-ui-tools/panels.js +242 -0
  11. package/dist/cjs/components/chat/client-ui-tools/panels.js.map +1 -0
  12. package/dist/cjs/components/chat/client-ui-tools/runner.js +285 -0
  13. package/dist/cjs/components/chat/client-ui-tools/runner.js.map +1 -0
  14. package/dist/cjs/components/chat/client-ui-tools/store.js +119 -0
  15. package/dist/cjs/components/chat/client-ui-tools/store.js.map +1 -0
  16. package/dist/cjs/components/chat/client-ui-tools/use-client-ui-tools.js +29 -0
  17. package/dist/cjs/components/chat/client-ui-tools/use-client-ui-tools.js.map +1 -0
  18. package/dist/cjs/components/chat/index.js +39 -2
  19. package/dist/cjs/components/chat/index.js.map +1 -1
  20. package/dist/cjs/components/ui/chart.js +2 -0
  21. package/dist/cjs/components/ui/chart.js.map +1 -1
  22. package/dist/cjs/components/workflows/classifier-panel.js +2 -0
  23. package/dist/cjs/components/workflows/classifier-panel.js.map +1 -1
  24. package/dist/cjs/components/workflows/workflow-canvas.js +1 -1
  25. package/dist/cjs/components/workflows/workflow-canvas.js.map +1 -1
  26. package/dist/cjs/components/workflows/workflow-definition.js +5 -2
  27. package/dist/cjs/components/workflows/workflow-definition.js.map +1 -1
  28. package/dist/cjs/components/workflows/workflow-editor.js +87 -241
  29. package/dist/cjs/components/workflows/workflow-editor.js.map +1 -1
  30. package/dist/cjs/components/workflows/workflows-list.js +14 -1
  31. package/dist/cjs/components/workflows/workflows-list.js.map +1 -1
  32. package/dist/cjs/hooks/use-extension-client-tools.js +98 -0
  33. package/dist/cjs/hooks/use-extension-client-tools.js.map +1 -0
  34. package/dist/cjs/i18n/messages/en.json.js +22 -21
  35. package/dist/cjs/i18n/messages/en.json.js.map +1 -1
  36. package/dist/cjs/i18n/messages/es.json.js +22 -21
  37. package/dist/cjs/i18n/messages/es.json.js.map +1 -1
  38. package/dist/cjs/i18n/messages/fr.json.js +22 -21
  39. package/dist/cjs/i18n/messages/fr.json.js.map +1 -1
  40. package/dist/cjs/i18n/messages/zh.json.js +22 -21
  41. package/dist/cjs/i18n/messages/zh.json.js.map +1 -1
  42. package/dist/cjs/next/index.js +16 -0
  43. package/dist/cjs/next/index.js.map +1 -1
  44. package/dist/cjs/node_modules/.pnpm/css-mediaquery@0.1.2/node_modules/css-mediaquery/index.js +1 -1
  45. package/dist/cjs/node_modules/.pnpm/matchmediaquery@0.4.2/node_modules/matchmediaquery/index.js +1 -1
  46. package/dist/cjs/node_modules/.pnpm/prop-types@15.8.1/node_modules/prop-types/index.js +1 -1
  47. package/dist/cjs/web-containers/tsconfig.build.tsbuildinfo +1 -1
  48. package/dist/esm/components/chat/ai-message-bubble.js +2 -1
  49. package/dist/esm/components/chat/ai-message-bubble.js.map +1 -1
  50. package/dist/esm/components/chat/chat-host-context.js.map +1 -1
  51. package/dist/esm/components/chat/client-ui-tools/definitions.js +183 -0
  52. package/dist/esm/components/chat/client-ui-tools/definitions.js.map +1 -0
  53. package/dist/esm/components/chat/client-ui-tools/panel-list.js +89 -0
  54. package/dist/esm/components/chat/client-ui-tools/panel-list.js.map +1 -0
  55. package/dist/esm/components/chat/client-ui-tools/panels.js +240 -0
  56. package/dist/esm/components/chat/client-ui-tools/panels.js.map +1 -0
  57. package/dist/esm/components/chat/client-ui-tools/runner.js +278 -0
  58. package/dist/esm/components/chat/client-ui-tools/runner.js.map +1 -0
  59. package/dist/esm/components/chat/client-ui-tools/store.js +113 -0
  60. package/dist/esm/components/chat/client-ui-tools/store.js.map +1 -0
  61. package/dist/esm/components/chat/client-ui-tools/use-client-ui-tools.js +27 -0
  62. package/dist/esm/components/chat/client-ui-tools/use-client-ui-tools.js.map +1 -0
  63. package/dist/esm/components/chat/index.js +39 -2
  64. package/dist/esm/components/chat/index.js.map +1 -1
  65. package/dist/esm/components/ui/chart.js +2 -1
  66. package/dist/esm/components/ui/chart.js.map +1 -1
  67. package/dist/esm/components/workflows/classifier-panel.js +2 -0
  68. package/dist/esm/components/workflows/classifier-panel.js.map +1 -1
  69. package/dist/esm/components/workflows/workflow-canvas.js +1 -1
  70. package/dist/esm/components/workflows/workflow-canvas.js.map +1 -1
  71. package/dist/esm/components/workflows/workflow-definition.js +5 -2
  72. package/dist/esm/components/workflows/workflow-definition.js.map +1 -1
  73. package/dist/esm/components/workflows/workflow-editor.js +88 -242
  74. package/dist/esm/components/workflows/workflow-editor.js.map +1 -1
  75. package/dist/esm/components/workflows/workflows-list.js +14 -1
  76. package/dist/esm/components/workflows/workflows-list.js.map +1 -1
  77. package/dist/esm/hooks/use-extension-client-tools.js +96 -0
  78. package/dist/esm/hooks/use-extension-client-tools.js.map +1 -0
  79. package/dist/esm/i18n/messages/en.json.js +22 -22
  80. package/dist/esm/i18n/messages/es.json.js +22 -22
  81. package/dist/esm/i18n/messages/fr.json.js +22 -22
  82. package/dist/esm/i18n/messages/zh.json.js +22 -22
  83. package/dist/esm/next/index.js +6 -0
  84. package/dist/esm/next/index.js.map +1 -1
  85. package/dist/esm/web-containers/tsconfig.build.tsbuildinfo +1 -1
  86. package/dist/index.d.ts +8 -1
  87. package/dist/next/index.d.ts +175 -5
  88. package/dist/package.json +6 -2
  89. package/package.json +7 -3
@@ -6,7 +6,7 @@ import { Button } from '../ui/button.js';
6
6
  import { Input } from '../ui/input.js';
7
7
  import { WorkflowPreviewChat } from './workflow-preview-chat.js';
8
8
  import { WorkflowCanvas } from './workflow-canvas.js';
9
- import { IBLAI_DECISION_MODEL, migrateWorkflowDefinition, isAuthoredInstructions, withoutNoteConnectivityWarnings, startVariableDefaults, CLASSIFIER_HANDLES } from './workflow-definition.js';
9
+ import { IBLAI_DECISION_MODEL, migrateWorkflowDefinition, isAuthoredInstructions, startVariableDefaults } from './workflow-definition.js';
10
10
  import { useOverflowFit } from '../chat-input-form/use-overflow-fit.js';
11
11
  import { ActionTooltip } from './action-tooltip.js';
12
12
  import { ariaShortcut, withShortcut } from './shortcuts.js';
@@ -34,6 +34,7 @@ import ListChecks from '../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1
34
34
  import ChevronUp from '../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/chevron-up.js';
35
35
  import ChevronDown from '../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/chevron-down.js';
36
36
  import TriangleAlert from '../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/triangle-alert.js';
37
+ import Info from '../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/info.js';
37
38
  import Plus from '../../node_modules/.pnpm/lucide-react@0.528.0_react@19.1.0/node_modules/lucide-react/dist/esm/icons/plus.js';
38
39
 
39
40
  function getCategoryConfig(t) {
@@ -49,204 +50,30 @@ const nodeCategoryOverride = {
49
50
  };
50
51
  function stepsOf(nodes) {
51
52
  const byId = new Map(nodes.map((node) => [node.id, node]));
52
- return { find: (id) => byId.get(id), at: (index) => nodes[index] };
53
+ return { find: (id) => byId.get(id) };
53
54
  }
54
- 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; };
55
- const BRANCH_NAME_KEYS = new Map([
56
- [CLASSIFIER_HANDLES.yes, 'workflowsWorkflowCanvas.classifierYes'],
57
- [CLASSIFIER_HANDLES.no, 'workflowsWorkflowCanvas.classifierNo'],
58
- [CLASSIFIER_HANDLES.next, 'workflowsWorkflowCanvas.classifierNext'],
59
- [CLASSIFIER_HANDLES.fallback, 'workflowsWorkflowCanvas.classifierFallback'],
60
- ]);
61
- function branchName(step, handle, t) {
62
- var _a, _b;
63
- 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);
64
- if (category === null || category === void 0 ? void 0 : category.label)
65
- return category.label;
66
- const key = BRANCH_NAME_KEYS.get(handle);
67
- return key ? t(key) : handle;
68
- }
69
- // The backend words these in terms of mentors and internal step ids, and
70
- // repeats the runtime and entry-agent checks once per Agent step.
71
- const MENTOR_MESSAGES = [
72
- {
73
- pattern: /^Mentor existence will be validated at runtime/,
74
- key: 'workflowsWorkflowEditor.agentCheckedAtRuntime',
75
- aboutEveryStep: true,
76
- },
77
- {
78
- pattern: /^Node 'mentor' missing required field 'mentor_id'/,
79
- key: 'workflowsWorkflowEditor.agentStepMissingAgent',
80
- },
81
- {
82
- pattern: /^Mentor step needs a mentor/,
83
- key: 'workflowsWorkflowEditor.agentStepMissingAgent',
84
- },
85
- {
86
- pattern: /^A mentor step cannot use this workflow's own entry mentor/,
87
- key: 'workflowsWorkflowEditor.agentStepUsesEntryAgent',
88
- },
89
- {
90
- pattern: /^Mentor step '(.+?)' uses a mentor that does not exist on this platform/,
91
- key: 'workflowsWorkflowEditor.agentStepAgentMissing',
92
- params: (match, steps) => ({ name: stepName(steps, match[1]) }),
93
- },
94
- {
95
- pattern: /^Mentor step 'output_variable' must start with a letter/,
96
- key: 'workflowsWorkflowEditor.agentStepOutputVariableInvalid',
97
- },
98
- {
99
- pattern: /^Classifier '(.+?)' route '(.+?)' goes straight to End/,
100
- key: 'workflowsWorkflowEditor.classifierRouteToEnd',
101
- params: (match, steps, t) => ({
102
- name: stepName(steps, match[1]),
103
- path: branchName(steps.find(match[1]), match[2], t),
104
- }),
105
- },
106
- {
107
- // Only the nodes[<index>] location says which step stores the variable.
108
- pattern: /^(?:Mentor step|Classifier) 'output_variable' '(.+?)' is a variable .+? \('(.+?)'\); this step replaces it with its result at nodes\[(\d+)\]\.data\b/,
109
- key: 'workflowsWorkflowEditor.outputVariableClash',
110
- params: (match, steps) => {
111
- var _a;
112
- const step = steps.at(Number(match[3]));
113
- if (!step)
114
- return null;
115
- return {
116
- name: ((_a = step.data) === null || _a === void 0 ? void 0 : _a.label) || step.id,
117
- variable: match[1],
118
- setter: stepName(steps, match[2]),
119
- };
120
- },
121
- },
122
- {
123
- pattern: /^(?:Mentor step|Classifier) 'output_variable' '(.+?)' is a variable .+? \('(.+?)'\); this step replaces it/,
124
- key: 'workflowsWorkflowEditor.outputVariableClashUnknownStep',
125
- params: (match, steps) => ({ variable: match[1], setter: stepName(steps, match[2]) }),
126
- locationOnly: true,
127
- },
128
- {
129
- // The model is named as resolved, so "ibl.ai Default" shows up as a slug
130
- // the author never picked; staff switch decision models on per deployment.
131
- pattern: /^Classifier '(.+?)' uses '.+?', (?:and ':|which isn't an enabled|which is not a decision)/,
132
- key: 'workflowsWorkflowEditor.classifierModelUnavailable',
133
- params: (match, steps) => ({ name: stepName(steps, match[1]) }),
134
- },
135
- ];
136
- // The backend ends each message with where it found the problem, e.g.
137
- // "at nodes[2].data (field: instructions)" or "at workflow_loops (field: edges)".
138
- const NODE_LOCATION = / at nodes\[(\d+)\](\.data)?(?: \(field: ([^()]+)\))?$/;
139
- const WORKFLOW_LOCATION = / at workflow_\w+(?: \(field: [^()]+\))?$/;
140
- const QUOTED = /'([^'\s]+)'/g;
141
- function problemTarget(message, steps, locationOnly = false, nodeId) {
142
- const target = textTarget(message, steps, locationOnly);
143
- // The step the backend names beats one read from the text, which can quote
144
- // another step; only the text says which field to focus.
145
- if (!nodeId || !steps.find(nodeId))
146
- return target;
147
- return target.stepId === nodeId ? target : { stepId: nodeId };
148
- }
149
- function textTarget(message, steps, locationOnly) {
150
- if (WORKFLOW_LOCATION.test(message))
151
- return {};
152
- // The location names the step at fault; a quoted id in the same message can
153
- // be another step, such as the one that also sets a variable.
154
- const location = NODE_LOCATION.exec(message);
155
- if (location) {
156
- const step = steps.at(Number(location[1]));
157
- if (!step)
158
- return {};
159
- // Outside the step's data the field is its id or type, which no setting shows.
160
- const field = location[2] ? location[3] : undefined;
161
- return field ? { stepId: step.id, field } : { stepId: step.id };
162
- }
163
- if (locationOnly)
164
- return {};
165
- for (const [, quoted] of message.matchAll(QUOTED)) {
166
- if (steps.find(quoted))
167
- return { stepId: quoted };
168
- }
169
- return {};
170
- }
171
- function toProblem({ message, nodeId }, t, steps) {
172
- for (const { pattern, key, params, aboutEveryStep, locationOnly } of MENTOR_MESSAGES) {
173
- const match = pattern.exec(message);
174
- if (!match)
175
- continue;
176
- const values = params === null || params === void 0 ? void 0 : params(match, steps, t);
177
- if (values === null)
178
- continue;
179
- const text = t(key, values);
180
- return aboutEveryStep
181
- ? { text }
182
- : { text, ...problemTarget(message, steps, locationOnly, nodeId) };
183
- }
184
- return { text: message, ...problemTarget(message, steps, false, nodeId) };
185
- }
186
- // iblai-dm-pro#3218 lists each message again in error_details /
187
- // warning_details, in the same order, with the step it is about, and drops the
188
- // " at nodes[<index>]" ending. A detail whose text differs is not trusted.
189
- const issuesOf = (messages, details = []) => messages.map((message, index) => {
190
- const detail = details[index];
191
- return (detail === null || detail === void 0 ? void 0 : detail.message) === message && detail.node_id
192
- ? { message, nodeId: detail.node_id }
193
- : { message };
55
+ // Each *_details list repeats its messages in the same order, with the step
56
+ // each is about. A detail whose text differs is not trusted.
57
+ const problemsOf = (messages = [], details = []) => {
58
+ const problems = messages.map((message, index) => {
59
+ const detail = details[index];
60
+ return (detail === null || detail === void 0 ? void 0 : detail.message) === message && detail.node_id
61
+ ? { text: message, stepId: detail.node_id }
62
+ : { text: message };
63
+ });
64
+ // Two steps can share a name, so the same words about another step stay.
65
+ return problems.filter((problem, index) => problems.findIndex((other) => other.text === problem.text && other.stepId === problem.stepId) === index);
66
+ };
67
+ const validationProblems = (result) => ({
68
+ errors: problemsOf(result.errors, result.error_details),
69
+ warnings: problemsOf(result.warnings, result.warning_details),
70
+ notices: problemsOf(result.notices, result.notice_details),
194
71
  });
195
- const distinct = (lines) => Array.from(new Set(lines));
196
- // A repeated line shows once and goes to the first step it was reported for;
197
- // once that step is fixed, the next check moves it to the next one.
198
- const distinctProblems = (problems) => problems.filter((problem, index) => problems.findIndex((other) => other.text === problem.text) === index);
199
72
  const PROBLEM_LINK = 'cursor-pointer text-left underline-offset-2 hover:underline focus-visible:underline focus-visible:outline-none';
200
- // A placeholder line's first group becomes {placeholder}, quotes included.
201
- const CLASSIFIER_TRY_MESSAGES = [
202
- {
203
- pattern: /^Classifier needs instructions/,
204
- key: 'workflowsClassifierPanel.instructionsRequired',
205
- },
206
- {
207
- pattern: /^Category \d+ needs a 'label'/,
208
- key: 'workflowsClassifierPanel.tryErrorCategoryLabel',
209
- },
210
- { pattern: /^Level \d+ needs a 'label'/, key: 'workflowsClassifierPanel.tryErrorLevelLabel' },
211
- { pattern: /^Duplicate level label/, key: 'workflowsClassifierPanel.tryErrorDuplicateLevel' },
212
- {
213
- pattern: /^('\{\{[^{}]+\}\}') names no step/,
214
- key: 'workflowsClassifierPanel.tryErrorPlaceholderStep',
215
- },
216
- {
217
- pattern: /^('\{\{[^{}]+\}\}') is not a valid variable name/,
218
- key: 'workflowsClassifierPanel.tryErrorPlaceholderVariableName',
219
- },
220
- {
221
- pattern: /^('\{\{[^{}]+\}\}') names a variable the Start node does not declare/,
222
- key: 'workflowsClassifierPanel.tryErrorPlaceholderUnknownVariable',
223
- },
224
- {
225
- pattern: /^('\{\{[^{}]+\}\}') is not a placeholder/,
226
- key: 'workflowsClassifierPanel.tryErrorNotPlaceholder',
227
- },
228
- {
229
- pattern: /^('\{\{[^{}]+\}\}') is always empty/,
230
- key: 'workflowsClassifierPanel.tryErrorPlaceholderEmpty',
231
- },
232
- {
233
- pattern: /^Example \d+ needs 'text' and a 'category'/,
234
- key: 'workflowsClassifierPanel.tryErrorExample',
235
- },
236
- ];
237
- const CLASSIFIER_MODEL_ERROR = /^Classifier '.+?' uses '.+?', /;
238
- function classifierErrorText(line, t) {
239
- if (CLASSIFIER_MODEL_ERROR.test(line))
240
- return t('workflowsClassifierPanel.tryModelUnavailable');
241
- for (const { pattern, key } of CLASSIFIER_TRY_MESSAGES) {
242
- const match = pattern.exec(line);
243
- if (match)
244
- return t(key, match[1] ? { placeholder: match[1] } : undefined);
245
- }
246
- return t('workflowsClassifierPanel.tryErrorOther');
247
- }
248
- function classifierTryFailure(error, t) {
73
+ const distinct = (lines) => Array.from(new Set(lines));
74
+ function classifierTryFailure(error) {
249
75
  const { status, data } = (error !== null && error !== void 0 ? error : {});
76
+ const detail = typeof (data === null || data === void 0 ? void 0 : data.detail) === 'string' && data.detail ? data.detail : undefined;
250
77
  switch (status) {
251
78
  case 400: {
252
79
  const rawErrors = data === null || data === void 0 ? void 0 : data.errors;
@@ -260,16 +87,9 @@ function classifierTryFailure(error, t) {
260
87
  return { ok: false, reason: 'too-long' };
261
88
  if (Array.isArray(data === null || data === void 0 ? void 0 : data.variables))
262
89
  return { ok: false, reason: 'variables-too-long' };
263
- return { ok: false, reason: 'other' };
90
+ return { ok: false, reason: 'other', message: detail };
264
91
  }
265
- if (lines.every((line) => CLASSIFIER_MODEL_ERROR.test(line))) {
266
- return { ok: false, reason: 'model-unavailable' };
267
- }
268
- return {
269
- ok: false,
270
- reason: 'invalid',
271
- errors: distinct(lines.map((line) => classifierErrorText(line, t))),
272
- };
92
+ return { ok: false, reason: 'invalid', message: detail, errors: distinct(lines) };
273
93
  }
274
94
  case 402:
275
95
  return { ok: false, reason: 'credits' };
@@ -278,9 +98,8 @@ function classifierTryFailure(error, t) {
278
98
  case 429:
279
99
  return { ok: false, reason: 'spend-cap' };
280
100
  case 502: {
281
- const detail = data === null || data === void 0 ? void 0 : data.detail;
282
- const unavailable = typeof detail === 'string' &&
283
- /not enabled for this account|not available for this account/.test(detail);
101
+ const unavailable = !!detail &&
102
+ /(?:not|isn't) (?:enabled|available) for this (?:account|organization)/.test(detail);
284
103
  return { ok: false, reason: unavailable ? 'model-unavailable' : 'model-failed' };
285
104
  }
286
105
  default:
@@ -434,6 +253,9 @@ function WorkflowEditor({ tenantKey, workflowId, username, axdToken, baseWsUrl,
434
253
  const [workflowData, setWorkflowData] = useState(null);
435
254
  const [hasUnsavedChanges, setHasUnsavedChanges] = useState(false);
436
255
  const [validationResult, setValidationResult] = useState(null);
256
+ // Half-built steps are normal while building, so a check after a save only
257
+ // updates a banner that is already up; Preview, Publish and Activate show it.
258
+ const [isValidationBannerShown, setIsValidationBannerShown] = useState(false);
437
259
  const [isValidationBannerOpen, setIsValidationBannerOpen] = useState(true);
438
260
  const [stepFocusRequest, setStepFocusRequest] = useState();
439
261
  const isInitialLoad = useRef(true);
@@ -468,20 +290,18 @@ function WorkflowEditor({ tenantKey, workflowId, username, axdToken, baseWsUrl,
468
290
  // What the canvas last reported, so a save that lands after newer edits
469
291
  // leaves them marked Unsaved.
470
292
  const latestGraphRef = useRef(null);
471
- // `nodes` is the definition the result was checked against: the backend
472
- // locates problems by position in it.
473
- const showValidation = (result, nodes) => {
474
- const steps = stepsOf(nodes);
475
- const problems = (issues) => distinctProblems(issues.map((issue) => toProblem(issue, t, steps)));
476
- const errors = problems(issuesOf(result.errors, result.error_details));
477
- const kept = new Set(withoutNoteConnectivityWarnings(result.warnings, nodes));
478
- const warnings = problems(issuesOf(result.warnings, result.warning_details).filter(({ message }) => kept.has(message)));
479
- if (errors.length === 0 && warnings.length === 0) {
293
+ const showValidation = (result, show) => {
294
+ const problems = validationProblems(result);
295
+ if (!problems.errors.length && !problems.warnings.length && !problems.notices.length) {
480
296
  setValidationResult(null);
297
+ setIsValidationBannerShown(false);
481
298
  return;
482
299
  }
483
- setValidationResult({ errors, warnings });
484
- setIsValidationBannerOpen(true);
300
+ setValidationResult(problems);
301
+ if (!show)
302
+ return;
303
+ setIsValidationBannerShown(true);
304
+ setIsValidationBannerOpen(show === 'open');
485
305
  };
486
306
  const showValidationRef = useRef(showValidation);
487
307
  showValidationRef.current = showValidation;
@@ -500,7 +320,7 @@ function WorkflowEditor({ tenantKey, workflowId, username, axdToken, baseWsUrl,
500
320
  org: tenantKey,
501
321
  uniqueId: workflowId,
502
322
  }).unwrap();
503
- showValidationRef.current(result, debouncedWorkflowData.nodes);
323
+ showValidationRef.current(result);
504
324
  }
505
325
  catch (_a) {
506
326
  // Silent fail for validation
@@ -598,29 +418,43 @@ function WorkflowEditor({ tenantKey, workflowId, username, axdToken, baseWsUrl,
598
418
  return { ok: true, output: result.output, model: result.model };
599
419
  }
600
420
  catch (err) {
601
- return classifierTryFailure(err, t);
421
+ return classifierTryFailure(err);
602
422
  }
603
423
  };
604
424
  const tryClassifierRef = useRef(tryClassifier);
605
425
  tryClassifierRef.current = tryClassifier;
606
426
  const handleTryClassifier = useCallback((nodeId, input) => tryClassifierRef.current(nodeId, input), []);
607
427
  const handlePreviewClick = async () => {
428
+ var _a;
429
+ let saved = true;
608
430
  try {
609
431
  await saveDefinitionIfNeeded();
610
432
  }
611
- catch (_a) {
433
+ catch (_b) {
434
+ saved = false;
612
435
  toast.error(t('workflowsWorkflowEditor.failedToSaveWorkflow'));
613
436
  }
614
437
  setPreviewKey((k) => k + 1);
615
438
  setIsPreviewMode(true);
439
+ if (!saved)
440
+ return;
441
+ // A workflow with errors answers "something went wrong", so the banner
442
+ // says why.
443
+ try {
444
+ const result = await validateWorkflow({ org: tenantKey, uniqueId: workflowId }).unwrap();
445
+ showValidation(result, ((_a = result.errors) === null || _a === void 0 ? void 0 : _a.length) ? 'open' : undefined);
446
+ }
447
+ catch (_c) {
448
+ // Preview still runs; Publish reports what is wrong.
449
+ }
616
450
  };
617
451
  const handleClosePreview = () => setIsPreviewMode(false);
618
452
  const handleNewChat = () => setNewChatSignal((signal) => signal + 1);
619
453
  // Preview hides step settings (and, on a phone, the whole canvas), so
620
454
  // going to a step leaves it.
621
- const handleShowStep = (nodeId, field) => {
455
+ const handleShowStep = (nodeId) => {
622
456
  setIsPreviewMode(false);
623
- 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 }); });
457
+ setStepFocusRequest((previous) => { var _a; return ({ nodeId, nonce: ((_a = previous === null || previous === void 0 ? void 0 : previous.nonce) !== null && _a !== void 0 ? _a : 0) + 1 }); });
624
458
  };
625
459
  const handleWorkflowStateChange = useCallback((state) => {
626
460
  var _a, _b;
@@ -733,21 +567,21 @@ function WorkflowEditor({ tenantKey, workflowId, username, axdToken, baseWsUrl,
733
567
  ? { definition: { nodes: workflowData.nodes, edges: workflowData.edges } }
734
568
  : undefined;
735
569
  try {
736
- await publishWorkflow({
570
+ const result = await publishWorkflow({
737
571
  org: tenantKey,
738
572
  uniqueId: workflowId,
739
573
  data,
740
574
  }).unwrap();
741
575
  if (workflowData)
742
576
  markDefinitionSaved(graphString(workflowData));
743
- setValidationResult(null);
577
+ // Warnings and notices never stop publishing, so they show collapsed.
578
+ showValidation(result, 'collapsed');
744
579
  toast.success(t('workflowsWorkflowEditor.workflowPublished'));
745
580
  }
746
581
  catch (err) {
747
582
  const errorData = err === null || err === void 0 ? void 0 : err.data;
748
583
  if (errorData && typeof errorData === 'object' && 'is_valid' in errorData) {
749
- const validation = errorData;
750
- showValidation(validation, currentNodes());
584
+ showValidation(errorData, 'open');
751
585
  toast.error(t('workflowsWorkflowEditor.workflowHasValidationIssues'));
752
586
  }
753
587
  else {
@@ -781,19 +615,18 @@ function WorkflowEditor({ tenantKey, workflowId, username, axdToken, baseWsUrl,
781
615
  uniqueId: workflowId,
782
616
  }).unwrap();
783
617
  if (result.is_valid) {
784
- setValidationResult(null);
618
+ showValidation(result, 'collapsed');
785
619
  toast.success(t('workflowsWorkflowEditor.workflowActivated'));
786
620
  }
787
621
  else {
788
- showValidation(result, currentNodes());
622
+ showValidation(result, 'open');
789
623
  toast.error(t('workflowsWorkflowEditor.workflowHasValidationIssues'));
790
624
  }
791
625
  }
792
626
  catch (err) {
793
627
  const errorData = err === null || err === void 0 ? void 0 : err.data;
794
628
  if (errorData && typeof errorData === 'object' && 'is_valid' in errorData) {
795
- const validation = errorData;
796
- showValidation(validation, currentNodes());
629
+ showValidation(errorData, 'open');
797
630
  toast.error(t('workflowsWorkflowEditor.workflowHasValidationIssues'));
798
631
  }
799
632
  else {
@@ -872,13 +705,18 @@ function WorkflowEditor({ tenantKey, workflowId, username, axdToken, baseWsUrl,
872
705
  // Named from the canvas as it is now: a step deleted since the check has
873
706
  // nothing to show, and a renamed one shows its new name.
874
707
  const shownSteps = stepsOf(currentNodes());
875
- const problemLine = ({ text, stepId, field }) => {
708
+ const problemLine = ({ text, stepId }) => {
876
709
  var _a;
877
710
  const step = stepId ? shownSteps.find(stepId) : undefined;
878
711
  if (!step)
879
712
  return jsx("span", { children: text });
880
- return (jsx(ActionTooltip, { label: t('workflowsWorkflowEditor.goToStep', { name: ((_a = step.data) === null || _a === void 0 ? void 0 : _a.label) || step.id }), children: jsx("button", { type: "button", "data-step-id": step.id, className: PROBLEM_LINK, onClick: () => handleShowStep(step.id, field), children: text }) }));
713
+ return (jsx(ActionTooltip, { label: t('workflowsWorkflowEditor.goToStep', { name: ((_a = step.data) === null || _a === void 0 ? void 0 : _a.label) || step.id }), children: jsx("button", { type: "button", "data-step-id": step.id, className: PROBLEM_LINK, onClick: () => handleShowStep(step.id), children: text }) }));
881
714
  };
715
+ // Steps nothing reaches are skipped, never refused, so a list of only them
716
+ // is not about warnings or errors.
717
+ const onlyNotices = !!validationResult &&
718
+ validationResult.errors.length === 0 &&
719
+ validationResult.warnings.length === 0;
882
720
  canvasShownRef.current = true;
883
721
  return (
884
722
  // Hosts render the editor below their own top bar: a window-tall editor
@@ -921,24 +759,32 @@ function WorkflowEditor({ tenantKey, workflowId, username, axdToken, baseWsUrl,
921
759
  delete: (jsxs(DropdownMenuItem, { onClick: () => setIsDeleteModalOpen(true), className: "text-red-600", children: [jsx(Trash2, {}), t('workflowsWorkflowEditor.delete')] })),
922
760
  };
923
761
  return (jsxs(Fragment, { children: [menuActions.length > 0 && (jsxs(DropdownMenu, { children: [jsx(ActionTooltip, { label: t('workflowsWorkflowEditor.moreOptionsLabel'), children: jsx(DropdownMenuTrigger, { asChild: true, children: jsx(Button, { variant: "ghost", size: "icon", className: "h-9 w-9 shrink-0 text-muted-foreground hover:text-foreground", "aria-label": t('workflowsWorkflowEditor.moreOptionsLabel'), children: jsx(Ellipsis, {}) }) }) }), jsx(DropdownMenuContent, { align: "end", children: menuActions.map((key) => (jsx(Fragment$1, { children: menuItem[key] }, key))) })] })), inlineActions.map((key) => (jsx("div", { ref: headerFit.itemRef(key), "data-header-action": key, className: "shrink-0", children: inlineButton[key] }, key)))] }));
924
- })()) })] }), validationResult &&
925
- (validationResult.errors.length > 0 || validationResult.warnings.length > 0) && (jsx(Collapsible, { open: isValidationBannerOpen, onOpenChange: setIsValidationBannerOpen, children: jsxs("div", { className: "border-border bg-background border-b px-4 py-2", children: [jsx(CollapsibleTrigger, { asChild: true, children: jsxs("button", { className: "flex w-full items-center justify-between gap-2 text-sm", children: [jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-x-2 text-left", children: [jsx(ListChecks, { className: "text-muted-foreground h-4 w-4 shrink-0" }), jsx("span", { className: "text-foreground font-medium", children: t('workflowsWorkflowEditor.problemsTitle') }), jsx("span", { "aria-hidden": "true", className: "text-muted-foreground", children: "\u00B7" }), jsxs("span", { className: "text-muted-foreground", children: [validationResult.errors.length > 0 &&
762
+ })()) })] }), isValidationBannerShown && validationResult && (jsx(Collapsible, { open: isValidationBannerOpen, onOpenChange: setIsValidationBannerOpen, children: jsxs("div", { className: "border-border bg-background border-b px-4 py-2", children: [jsx(CollapsibleTrigger, { asChild: true, children: jsxs("button", { className: "flex w-full items-center justify-between gap-2 text-sm", children: [jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-x-2 text-left", children: [jsx(ListChecks, { className: "text-muted-foreground h-4 w-4 shrink-0" }), jsx("span", { className: "text-foreground font-medium", children: onlyNotices
763
+ ? t('workflowsWorkflowEditor.notConnectedTitle')
764
+ : t('workflowsWorkflowEditor.problemsTitle') }), jsx("span", { "aria-hidden": "true", className: "text-muted-foreground", children: "\u00B7" }), jsx("span", { className: "text-muted-foreground", children: [
765
+ validationResult.errors.length > 0 &&
926
766
  t('workflowsWorkflowEditor.validationErrors', {
927
767
  count: validationResult.errors.length,
928
- }), validationResult.errors.length > 0 &&
929
- validationResult.warnings.length > 0 &&
930
- ', ', validationResult.warnings.length > 0 &&
768
+ }),
769
+ validationResult.warnings.length > 0 &&
931
770
  t('workflowsWorkflowEditor.validationWarnings', {
932
771
  count: validationResult.warnings.length,
933
- })] })] }), jsxs("div", { className: "flex shrink-0 items-center gap-2", children: [isValidationBannerOpen ? (jsx(ChevronUp, { className: "text-muted-foreground h-4 w-4" })) : (jsx(ChevronDown, { className: "text-muted-foreground h-4 w-4" })), jsx("span", { role: "button", tabIndex: 0, className: "text-muted-foreground hover:text-foreground", onClick: (e) => {
772
+ }),
773
+ validationResult.notices.length > 0 &&
774
+ t(onlyNotices
775
+ ? 'workflowsWorkflowEditor.notConnectedSteps'
776
+ : 'workflowsWorkflowEditor.validationNotices', { count: validationResult.notices.length }),
777
+ ]
778
+ .filter(Boolean)
779
+ .join(', ') })] }), jsxs("div", { className: "flex shrink-0 items-center gap-2", children: [isValidationBannerOpen ? (jsx(ChevronUp, { className: "text-muted-foreground h-4 w-4" })) : (jsx(ChevronDown, { className: "text-muted-foreground h-4 w-4" })), jsx("span", { role: "button", tabIndex: 0, className: "text-muted-foreground hover:text-foreground", onClick: (e) => {
934
780
  e.stopPropagation();
935
- setValidationResult(null);
781
+ setIsValidationBannerShown(false);
936
782
  }, onKeyDown: (e) => {
937
783
  if (e.key === 'Enter' || e.key === ' ') {
938
784
  e.stopPropagation();
939
- setValidationResult(null);
785
+ setIsValidationBannerShown(false);
940
786
  }
941
- }, children: jsx(X, { className: "h-4 w-4" }) })] })] }) }), jsx(CollapsibleContent, { children: 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) => (jsxs("div", { className: "flex items-start gap-2 text-sm text-red-600", children: [jsx(CircleAlert, { className: "mt-0.5 h-3.5 w-3.5 shrink-0" }), problemLine(error)] }, `error-${i}`))), validationResult.warnings.map((warning, i) => (jsxs("div", { className: "flex items-start gap-2 text-sm text-amber-600", children: [jsx(TriangleAlert, { className: "mt-0.5 h-3.5 w-3.5 shrink-0" }), problemLine(warning)] }, `warning-${i}`)))] }) })] }) })), jsxs("div", { className: "flex flex-1 overflow-hidden", children: [!isPreviewMode && (jsx(WorkflowSidebar, { className: "hidden md:block", onDragStart: setDraggedItem, onItemClick: handleItemClick, nodeTypes: nodeTypeSections })), jsxs("div", { className: isPreviewMode
787
+ }, children: jsx(X, { className: "h-4 w-4" }) })] })] }) }), jsx(CollapsibleContent, { children: 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) => (jsxs("div", { "data-problem-kind": "error", className: "flex items-start gap-2 text-sm text-red-600", children: [jsx(CircleAlert, { className: "mt-0.5 h-3.5 w-3.5 shrink-0" }), problemLine(error)] }, `error-${i}`))), validationResult.warnings.map((warning, i) => (jsxs("div", { "data-problem-kind": "warning", className: "flex items-start gap-2 text-sm text-amber-600", children: [jsx(TriangleAlert, { className: "mt-0.5 h-3.5 w-3.5 shrink-0" }), problemLine(warning)] }, `warning-${i}`))), validationResult.notices.map((notice, i) => (jsxs("div", { "data-problem-kind": "notice", className: "text-muted-foreground flex items-start gap-2 text-sm", children: [jsx(Info, { className: "mt-0.5 h-3.5 w-3.5 shrink-0" }), problemLine(notice)] }, `notice-${i}`)))] }) })] }) })), jsxs("div", { className: "flex flex-1 overflow-hidden", children: [!isPreviewMode && (jsx(WorkflowSidebar, { className: "hidden md:block", onDragStart: setDraggedItem, onItemClick: handleItemClick, nodeTypes: nodeTypeSections })), jsxs("div", { className: isPreviewMode
942
788
  ? // Kept mounted on phones so Close Preview returns to the same
943
789
  // view and undo history.
944
790
  'hidden h-full md:block md:w-[60%] md:border-r md:border-gray-200'