@flowdrop/flowdrop 2.0.0-beta.10 → 2.0.0-beta.11

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 (61) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/dist/chat/batchFeedback.js +1 -1
  3. package/dist/chat/commandClassifier.d.ts +11 -0
  4. package/dist/chat/commandClassifier.js +20 -0
  5. package/dist/chat/historyBuilder.d.ts +39 -0
  6. package/dist/chat/historyBuilder.js +82 -0
  7. package/dist/chat/index.d.ts +2 -1
  8. package/dist/chat/index.js +2 -1
  9. package/dist/chat/responseParser.js +16 -12
  10. package/dist/commands/parser.d.ts +12 -0
  11. package/dist/commands/parser.js +33 -6
  12. package/dist/components/ConfigForm.svelte +30 -6
  13. package/dist/components/SettingsPanel.svelte +9 -0
  14. package/dist/components/WorkflowEditor.svelte +5 -2
  15. package/dist/components/chat/AIChatPanel.svelte +42 -6
  16. package/dist/components/chat/CommandPreview.svelte +10 -1
  17. package/dist/components/form/FormPorts.svelte +21 -3
  18. package/dist/components/form/FormRangeField.svelte +5 -3
  19. package/dist/components/form/FormToggle.svelte +27 -2
  20. package/dist/components/form/FormToggle.svelte.d.ts +5 -0
  21. package/dist/components/playground/ChatInput.svelte +316 -26
  22. package/dist/components/playground/ChatInput.svelte.d.ts +31 -1
  23. package/dist/components/playground/ControlPanel.svelte +22 -0
  24. package/dist/components/playground/ControlPanel.svelte.d.ts +13 -0
  25. package/dist/components/playground/Playground.svelte +217 -4
  26. package/dist/config/endpoints.d.ts +48 -1
  27. package/dist/config/endpoints.js +18 -5
  28. package/dist/messages/defaults.d.ts +98 -0
  29. package/dist/messages/defaults.js +58 -1
  30. package/dist/playground/commands/args.d.ts +32 -0
  31. package/dist/playground/commands/args.js +50 -0
  32. package/dist/playground/commands/dispatch.d.ts +143 -0
  33. package/dist/playground/commands/dispatch.js +162 -0
  34. package/dist/playground/commands/index.d.ts +14 -0
  35. package/dist/playground/commands/index.js +10 -0
  36. package/dist/playground/commands/parser.d.ts +38 -0
  37. package/dist/playground/commands/parser.js +163 -0
  38. package/dist/playground/commands/registry.d.ts +42 -0
  39. package/dist/playground/commands/registry.js +122 -0
  40. package/dist/playground/commands/suggest.d.ts +37 -0
  41. package/dist/playground/commands/suggest.js +46 -0
  42. package/dist/playground/commands/types.d.ts +111 -0
  43. package/dist/playground/commands/types.js +15 -0
  44. package/dist/playground/index.d.ts +19 -0
  45. package/dist/playground/index.js +25 -0
  46. package/dist/playground/runAction.d.ts +48 -0
  47. package/dist/playground/runAction.js +31 -0
  48. package/dist/services/pipelineSignalService.d.ts +97 -0
  49. package/dist/services/pipelineSignalService.js +94 -0
  50. package/dist/services/playgroundService.d.ts +12 -0
  51. package/dist/services/playgroundService.js +22 -0
  52. package/dist/services/workflowLaunchService.d.ts +74 -0
  53. package/dist/services/workflowLaunchService.js +74 -0
  54. package/dist/types/chat.d.ts +5 -1
  55. package/dist/types/settings.d.ts +11 -0
  56. package/dist/types/settings.js +2 -1
  57. package/dist/utils/canvasSelection.d.ts +25 -0
  58. package/dist/utils/canvasSelection.js +37 -0
  59. package/dist/utils/nodeFormSchema.d.ts +51 -0
  60. package/dist/utils/nodeFormSchema.js +87 -0
  61. package/package.json +1 -1
@@ -135,7 +135,8 @@
135
135
  <span class="fd-ports__group-label">{group.label}</span>
136
136
  <ul class="fd-ports__list">
137
137
  {#each ordered as port, i (port.id)}
138
- <li class="fd-ports__item">
138
+ {@const exposed = isPortExposed(port, portsConfig[direction])}
139
+ <li class="fd-ports__item" class:fd-ports__item--hidden={!exposed}>
139
140
  <div class="fd-ports__reorder">
140
141
  <button
141
142
  type="button"
@@ -156,9 +157,10 @@
156
157
  <Icon icon="heroicons:chevron-down" />
157
158
  </button>
158
159
  </div>
159
- <span class="fd-ports__name">{port.name}</span>
160
+ <span class="fd-ports__name" title={port.name}>{port.name}</span>
160
161
  <span
161
162
  class="fd-ports__badge"
163
+ title={port.dataType}
162
164
  style="background-color:{getPortBackgroundColorForPort(
163
165
  checker,
164
166
  port,
@@ -172,10 +174,11 @@
172
174
  </span>
173
175
  <FormToggle
174
176
  id={`${id}-${direction}-${port.id}`}
175
- value={isPortExposed(port, portsConfig[direction])}
177
+ value={exposed}
176
178
  onLabel="Exposed"
177
179
  offLabel="Hidden"
178
180
  {disabled}
181
+ hideLabel
179
182
  onChange={(exposed) => setExposed(direction, port.id, exposed)}
180
183
  />
181
184
  </li>
@@ -225,6 +228,13 @@
225
228
  border: 1px solid var(--fd-border-muted);
226
229
  }
227
230
 
231
+ /* The switch alone carries the state now that its label is screen-reader
232
+ only, so dim the row to keep "hidden" legible at a glance. */
233
+ .fd-ports__item--hidden .fd-ports__name,
234
+ .fd-ports__item--hidden .fd-ports__badge {
235
+ opacity: 0.55;
236
+ }
237
+
228
238
  .fd-ports__reorder {
229
239
  display: flex;
230
240
  flex-direction: column;
@@ -247,10 +257,15 @@
247
257
  cursor: default;
248
258
  }
249
259
 
260
+ /* min-width:0 so a long port name ellipsizes instead of widening the row. */
250
261
  .fd-ports__name {
251
262
  flex: 1;
263
+ min-width: 0;
252
264
  font-size: var(--fd-text-xs);
253
265
  font-weight: 500;
266
+ overflow: hidden;
267
+ text-overflow: ellipsis;
268
+ white-space: nowrap;
254
269
  }
255
270
 
256
271
  .fd-ports__badge {
@@ -258,5 +273,8 @@
258
273
  padding: 0 var(--fd-space-1, 0.25rem);
259
274
  border-radius: var(--fd-radius-sm, 4px);
260
275
  white-space: nowrap;
276
+ max-width: 10ch;
277
+ overflow: hidden;
278
+ text-overflow: ellipsis;
261
279
  }
262
280
  </style>
@@ -11,6 +11,8 @@
11
11
  -->
12
12
 
13
13
  <script lang="ts">
14
+ import { untrack } from 'svelte';
15
+
14
16
  interface Props {
15
17
  /** Field identifier */
16
18
  id: string;
@@ -78,15 +80,15 @@
78
80
  * instant the user drags onto a whole number (e.g. 1.0), stranding the slider
79
81
  * on integer increments.
80
82
  */
81
- const initialNumeric = typeof value === 'number' ? value : Number(value);
82
- const inferredStep = ((): number => {
83
+ const inferredStep = untrack((): number => {
84
+ const initialNumeric = typeof value === 'number' ? value : Number(value);
83
85
  const places = Math.max(
84
86
  decimalPlaces(Number.isNaN(initialNumeric) ? min : initialNumeric),
85
87
  decimalPlaces(min),
86
88
  decimalPlaces(max)
87
89
  );
88
90
  return places > 0 ? Math.pow(10, -places) : 1;
89
- })();
91
+ });
90
92
 
91
93
  const effectiveStep = $derived(typeof step === 'number' && step > 0 ? step : inferredStep);
92
94
 
@@ -26,6 +26,11 @@
26
26
  * `messages.form.toggle.disabled`.
27
27
  */
28
28
  offLabel?: string;
29
+ /**
30
+ * Keep the state label as the switch's accessible name only, without
31
+ * rendering it. For dense rows where the switch alone carries the state.
32
+ */
33
+ hideLabel?: boolean;
29
34
  /** Whether the field is disabled (read-only) */
30
35
  disabled?: boolean;
31
36
  /** ARIA description ID */
@@ -39,6 +44,7 @@
39
44
  value = false,
40
45
  onLabel,
41
46
  offLabel,
47
+ hideLabel = false,
42
48
  disabled = false,
43
49
  ariaDescribedBy,
44
50
  onChange
@@ -56,7 +62,7 @@
56
62
  }
57
63
  </script>
58
64
 
59
- <label class="form-toggle">
65
+ <label class="form-toggle" class:form-toggle--compact={hideLabel}>
60
66
  <input
61
67
  {id}
62
68
  type="checkbox"
@@ -69,7 +75,7 @@
69
75
  <span class="form-toggle__track">
70
76
  <span class="form-toggle__thumb"></span>
71
77
  </span>
72
- <span class="form-toggle__label">
78
+ <span class="form-toggle__label" class:form-toggle__label--sr-only={hideLabel}>
73
79
  {value ? resolvedOnLabel : resolvedOffLabel}
74
80
  </span>
75
81
  </label>
@@ -130,4 +136,23 @@
130
136
  .form-toggle__input:checked ~ .form-toggle__label {
131
137
  color: var(--fd-primary-hover);
132
138
  }
139
+
140
+ /* Compact: switch only, no reserved label column and no vertical padding. */
141
+ .form-toggle--compact {
142
+ gap: 0;
143
+ padding: 0;
144
+ }
145
+
146
+ .form-toggle__label--sr-only {
147
+ position: absolute;
148
+ width: 1px;
149
+ height: 1px;
150
+ min-width: 0;
151
+ padding: 0;
152
+ margin: -1px;
153
+ overflow: hidden;
154
+ clip-path: inset(50%);
155
+ white-space: nowrap;
156
+ border: 0;
157
+ }
133
158
  </style>
@@ -13,6 +13,11 @@ interface Props {
13
13
  * `messages.form.toggle.disabled`.
14
14
  */
15
15
  offLabel?: string;
16
+ /**
17
+ * Keep the state label as the switch's accessible name only, without
18
+ * rendering it. For dense rows where the switch alone carries the state.
19
+ */
20
+ hideLabel?: boolean;
16
21
  /** Whether the field is disabled (read-only) */
17
22
  disabled?: boolean;
18
23
  /** ARIA description ID */
@@ -10,10 +10,18 @@
10
10
 
11
11
  <script lang="ts">
12
12
  import Icon from '@iconify/svelte';
13
- import { tick, untrack } from 'svelte';
13
+ import { tick } from 'svelte';
14
14
  import { hasEnableRunFlag } from '../../types/playground.js';
15
15
  import { getInstance } from '../../stores/getInstance.svelte.js';
16
16
  import { m } from '../../messages/index.js';
17
+ import {
18
+ isCommandInput,
19
+ suggestCommands,
20
+ type CommandOutcome,
21
+ type CommandSuggestion
22
+ } from '../../playground/commands/index.js';
23
+ import { resolveRunAction } from '../../playground/runAction.js';
24
+ import ConsoleAutocomplete from '../console/ConsoleAutocomplete.svelte';
17
25
 
18
26
  const fd = getInstance();
19
27
 
@@ -23,10 +31,39 @@
23
31
  showTextarea?: boolean;
24
32
  /** Show the Run button when textarea is hidden (default: true) */
25
33
  showRunButton?: boolean;
26
- /** Message sent when Run is clicked with textarea hidden */
34
+ /**
35
+ * Message sent when Run is clicked, for hosts that deliberately want the
36
+ * run to begin with a specific chat turn.
37
+ *
38
+ * Setting this opts *out* of {@link onRunWorkflow}: an explicitly
39
+ * configured message is a host's intentional choice and is honoured.
40
+ * Leaving it unset is what lets Run launch without fabricating a turn.
41
+ */
27
42
  predefinedMessage?: string;
28
43
  onSendMessage?: (content: string) => void;
29
44
  onStopExecution?: () => void;
45
+ /**
46
+ * Start a run without posting a chat message.
47
+ *
48
+ * Preferred over `onSendMessage` for the Run button. Sending a message to
49
+ * start a run fabricates a user turn that enters the conversation and is
50
+ * replayed as input on the following turn — indistinguishable downstream
51
+ * from something the user actually typed. Hosts that provide this get a Run
52
+ * button that launches instead.
53
+ */
54
+ onRunWorkflow?: () => void;
55
+ /**
56
+ * Enable the slash-command lane (default: false).
57
+ *
58
+ * Opt-in because the lane is only safe where the `onSendMessage` handler
59
+ * actually dispatches commands. A surface that forwards input straight to a
60
+ * backend (ChatPanel) would post `/stop` as literal text — faking a command
61
+ * that nothing implements.
62
+ */
63
+ enableCommands?: boolean;
64
+ /** Transient result of the last slash command. Never a session message. */
65
+ commandFeedback?: CommandOutcome | null;
66
+ onDismissCommandFeedback?: () => void;
30
67
  }
31
68
 
32
69
  let {
@@ -35,13 +72,19 @@
35
72
  showRunButton = true,
36
73
  predefinedMessage,
37
74
  onSendMessage,
38
- onStopExecution
75
+ onStopExecution,
76
+ onRunWorkflow,
77
+ enableCommands = false,
78
+ commandFeedback = null,
79
+ onDismissCommandFeedback
39
80
  }: Props = $props();
40
81
 
41
82
  const actions = $derived(m().playground.actions);
42
83
  const chat = $derived(m().playground.chat);
43
84
  const states = $derived(m().playground.states);
44
85
 
86
+ const commandMessages = $derived(m().playground.commands);
87
+
45
88
  const resolvedPlaceholder = $derived(placeholder ?? chat.placeholder);
46
89
  const resolvedPredefinedMessage = $derived(predefinedMessage ?? chat.predefinedRun);
47
90
 
@@ -57,29 +100,104 @@
57
100
  let inputValue = $state('');
58
101
  let inputField: HTMLTextAreaElement | undefined = $state();
59
102
 
60
- // Count of enableRun messages seen so far — plain let, not $state.
61
- // Written with untrack to make the bookkeeping intent explicit.
103
+ /**
104
+ * Whether the current input is control traffic rather than pipeline data.
105
+ *
106
+ * Used only to relax the send gate (see {@link canSubmit}). Note that this
107
+ * does *not* make commands typable during a run: the textarea is disabled
108
+ * while `isExecuting`, and stopping a run is the Stop button's job.
109
+ */
110
+ const inputIsCommand = $derived(enableCommands && isCommandInput(inputValue));
111
+
112
+ // Unique per instance so two playgrounds on one page don't collide, and
113
+ // shared with the listbox so aria-controls/activedescendant stay consistent.
114
+ const uid = $props.id();
115
+ const listboxId = `${uid}-command-palette-listbox`;
116
+
117
+ /**
118
+ * Command palette state.
119
+ *
120
+ * `dismissed` is separate from "no suggestions": pressing Escape must keep the
121
+ * palette shut while the user keeps typing the same command, and only a fresh
122
+ * edit that changes the completion set should bring it back.
123
+ */
124
+ let paletteDismissed = $state(false);
125
+
126
+ const paletteSuggestions = $derived(
127
+ enableCommands ? suggestCommands(inputValue, fd.api.config, commandMessages.catalog) : []
128
+ );
129
+ const paletteVisible = $derived(!paletteDismissed && paletteSuggestions.length > 0);
130
+
131
+ /**
132
+ * Where the user has moved the highlight, and where it actually lands.
133
+ *
134
+ * Clamped on read rather than corrected in an effect: effects run *after* the
135
+ * DOM updates, so a list that narrows under typing would render one frame
136
+ * with `aria-activedescendant` pointing at an option that no longer exists.
137
+ */
138
+ let paletteCursor = $state(0);
139
+ const paletteIndex = $derived(
140
+ paletteSuggestions.length === 0 ? 0 : Math.min(paletteCursor, paletteSuggestions.length - 1)
141
+ );
142
+
143
+ /**
144
+ * Match the textarea's height to its content, capped.
145
+ *
146
+ * Called from every path that changes `inputValue`, not just typing — the
147
+ * height is a function of the content, so anything that sets the content owes
148
+ * it an update.
149
+ */
150
+ function resizeTextarea(): void {
151
+ if (!inputField) return;
152
+ inputField.style.height = 'auto';
153
+ inputField.style.height = `${Math.min(inputField.scrollHeight, 120)}px`;
154
+ }
155
+
156
+ function acceptSuggestion(suggestion: CommandSuggestion): void {
157
+ inputValue = suggestion.value;
158
+ paletteDismissed = true;
159
+ paletteCursor = 0;
160
+ tick().then(() => {
161
+ resizeTextarea();
162
+ inputField?.focus({ preventScroll: true });
163
+ });
164
+ }
165
+
166
+ /**
167
+ * Commands bypass the send gate; plain text still respects it.
168
+ *
169
+ * This matters for states that are not "executing" but still refuse messages
170
+ * — `awaiting_input` most of all, where the textarea is live but
171
+ * `canSendMessage` is false, so without this a command could be typed and
172
+ * never submitted. Execution itself needs no special case: the button chain
173
+ * already swaps Send for Stop while a run is in flight.
174
+ */
175
+ const canSubmit = $derived(
176
+ inputValue.trim().length > 0 && (inputIsCommand || fd.playground.canSendMessage)
177
+ );
178
+
179
+ // Count of enableRun messages seen so far. A plain `let`, not `$state`: it is
180
+ // bookkeeping for the effects below, never read during render. Because it is
181
+ // not reactive, writing to it inside an effect creates no dependency and
182
+ // needs no `untrack`.
62
183
  let seenEnableRunCount = 0;
63
184
 
64
185
  $effect(() => {
65
- const count = fd.playground.messages.filter((m) => hasEnableRunFlag(m.metadata)).length;
186
+ const count = fd.playground.messages.filter((msg) => hasEnableRunFlag(msg.metadata)).length;
66
187
  if (count > seenEnableRunCount) {
67
- untrack(() => {
68
- seenEnableRunCount = count;
69
- });
188
+ seenEnableRunCount = count;
70
189
  runEnabled = true;
71
190
  }
72
191
  });
73
192
 
74
193
  $effect(() => {
75
194
  if (fd.playground.currentSession?.id) {
76
- untrack(() => {
77
- seenEnableRunCount = 0;
78
- });
195
+ seenEnableRunCount = 0;
79
196
  runEnabled = true;
80
197
  }
81
198
  });
82
199
 
200
+ // Same rationale as `seenEnableRunCount`: plain `let`, no `untrack` needed.
83
201
  let wasExecuting = false;
84
202
 
85
203
  /** Auto-focus input when execution completes */
@@ -88,28 +206,66 @@
88
206
  if (wasExecuting && !nowExecuting && inputField) {
89
207
  tick().then(() => inputField?.focus({ preventScroll: true }));
90
208
  }
91
- untrack(() => {
92
- wasExecuting = nowExecuting;
93
- });
209
+ wasExecuting = nowExecuting;
94
210
  });
95
211
 
96
212
  function handleSend(): void {
97
213
  const trimmedValue = inputValue.trim();
98
- if (!trimmedValue || !fd.playground.canSendMessage) return;
214
+ if (!canSubmit) return;
99
215
 
216
+ onDismissCommandFeedback?.();
100
217
  onSendMessage?.(trimmedValue);
101
218
  inputValue = '';
102
219
 
103
- if (inputField) {
104
- inputField.style.height = 'auto';
105
- }
106
-
107
220
  tick().then(() => {
221
+ resizeTextarea();
108
222
  inputField?.focus({ preventScroll: true });
109
223
  });
110
224
  }
111
225
 
112
226
  function handleKeydown(event: KeyboardEvent): void {
227
+ // The palette owns navigation keys while it is open, mirroring the editor
228
+ // console so the two surfaces behave identically.
229
+ if (paletteVisible) {
230
+ if (event.key === 'ArrowUp') {
231
+ event.preventDefault();
232
+ paletteCursor = paletteIndex > 0 ? paletteIndex - 1 : paletteSuggestions.length - 1;
233
+ return;
234
+ }
235
+ if (event.key === 'ArrowDown') {
236
+ event.preventDefault();
237
+ paletteCursor = paletteIndex < paletteSuggestions.length - 1 ? paletteIndex + 1 : 0;
238
+ return;
239
+ }
240
+ if (event.key === 'Tab') {
241
+ event.preventDefault();
242
+ acceptSuggestion(paletteSuggestions[paletteIndex]);
243
+ return;
244
+ }
245
+ if (event.key === 'Escape') {
246
+ event.preventDefault();
247
+ // Escape must not reach an ancestor here: PlaygroundModal closes on
248
+ // Escape, so without this, dismissing the palette would also close the
249
+ // whole playground.
250
+ event.stopPropagation();
251
+ paletteDismissed = true;
252
+ return;
253
+ }
254
+ if (event.key === 'Enter' && !event.shiftKey) {
255
+ event.preventDefault();
256
+ const suggestion = paletteSuggestions[paletteIndex];
257
+ // Compare trimmed: a completion for an argument-taking command differs
258
+ // from a fully typed name only by its trailing space, and `/run` +
259
+ // Enter should start a run rather than silently insert a space.
260
+ if (suggestion.value.trim() !== inputValue.trim()) {
261
+ acceptSuggestion(suggestion);
262
+ return;
263
+ }
264
+ handleSend();
265
+ return;
266
+ }
267
+ }
268
+
113
269
  if (event.key === 'Enter' && !event.shiftKey) {
114
270
  event.preventDefault();
115
271
  handleSend();
@@ -123,14 +279,33 @@
123
279
  function handleRun(): void {
124
280
  if (fd.playground.isExecuting || !runEnabled) return;
125
281
  runEnabled = false;
126
- onSendMessage?.(resolvedPredefinedMessage);
282
+
283
+ const action = resolveRunAction({
284
+ canLaunch: onRunWorkflow != null,
285
+ predefinedMessage,
286
+ defaultMessage: resolvedPredefinedMessage
287
+ });
288
+
289
+ if (action.kind === 'launch') {
290
+ onRunWorkflow?.();
291
+ return;
292
+ }
293
+
294
+ onSendMessage?.(action.content);
127
295
  }
128
296
 
129
297
  function handleInput(): void {
130
- if (inputField) {
131
- inputField.style.height = 'auto';
132
- inputField.style.height = `${Math.min(inputField.scrollHeight, 120)}px`;
133
- }
298
+ // Typing re-opens the palette: a dismissal applies to the text it was
299
+ // dismissed on, not to the rest of the session.
300
+ paletteDismissed = false;
301
+ // ...and restarts the highlight at the top, as the editor console does.
302
+ // Without this the cursor survives a narrowing list: highlight the third
303
+ // entry, type one more character, and you are now pointed at whatever
304
+ // happens to be third in the *new* list, which is not what you were aiming
305
+ // at. Clamping keeps it in range; only resetting keeps it meaningful.
306
+ paletteCursor = 0;
307
+
308
+ resizeTextarea();
134
309
  }
135
310
  </script>
136
311
 
@@ -141,9 +316,60 @@
141
316
  <span>{states.viewOnlyHelp}</span>
142
317
  </div>
143
318
  {:else}
319
+ <!--
320
+ The live region is always present and only its *contents* come and go.
321
+ A region inserted with its text already in place is usually announced by
322
+ nothing at all — screen readers watch established regions for changes.
323
+
324
+ One fixed politeness, too, rather than swapping role between `status` and
325
+ `alert`: the `{#if}` reuses this node, and role changes on a live node are
326
+ not reliably re-evaluated. Severity is carried visually instead.
327
+ -->
328
+ <div class="chat-input__command-feedback-region" role="status" aria-live="polite">
329
+ {#if commandFeedback}
330
+ <div
331
+ class="chat-input__command-feedback chat-input__command-feedback--{commandFeedback.status}"
332
+ >
333
+ <span class="chat-input__command-feedback-text">{commandFeedback.message}</span>
334
+ <button
335
+ type="button"
336
+ class="chat-input__command-feedback-dismiss"
337
+ onclick={() => onDismissCommandFeedback?.()}
338
+ aria-label={commandMessages.dismiss}
339
+ >
340
+ <Icon icon="mdi:close" />
341
+ </button>
342
+ </div>
343
+ {/if}
344
+ </div>
144
345
  <div class="chat-input__container" class:chat-input__container--run-only={!showTextarea}>
145
346
  {#if showTextarea}
146
347
  <div class="chat-input__wrapper">
348
+ {#if enableCommands}
349
+ <ConsoleAutocomplete
350
+ suggestions={paletteSuggestions}
351
+ visible={paletteVisible}
352
+ selectedIndex={paletteIndex}
353
+ onAccept={acceptSuggestion}
354
+ {listboxId}
355
+ />
356
+ {/if}
357
+ <!--
358
+ `role="combobox"` on a <textarea> is a deliberate, non-conforming
359
+ choice, recorded here so it is not "fixed" by guesswork later.
360
+
361
+ ARIA in HTML permits no role on <textarea> other than its implicit
362
+ `textbox`, and the ARIA 1.2 combobox pattern assumes a single-line
363
+ input. But there is no conforming pattern for "multi-line composer
364
+ with completions", and the strictly-valid alternative — implicit
365
+ `textbox` plus `aria-activedescendant`, dropping `aria-expanded`
366
+ (which `textbox` does not support) — leaves no way to announce that
367
+ the palette opened at all.
368
+
369
+ We take the announcement over the conformance, which is what
370
+ comparable chat composers ship. Revisit if ARIA gains a real pattern
371
+ for this, or if testing shows a screen reader handles it badly.
372
+ -->
147
373
  <textarea
148
374
  bind:this={inputField}
149
375
  bind:value={inputValue}
@@ -153,6 +379,14 @@
153
379
  disabled={fd.playground.isExecuting || !fd.playground.currentSession}
154
380
  onkeydown={handleKeydown}
155
381
  oninput={handleInput}
382
+ onblur={() => (paletteDismissed = true)}
383
+ autocomplete="off"
384
+ role={enableCommands ? 'combobox' : undefined}
385
+ aria-expanded={enableCommands ? paletteVisible : undefined}
386
+ aria-controls={enableCommands ? listboxId : undefined}
387
+ aria-activedescendant={paletteVisible
388
+ ? `${listboxId}-option-${paletteIndex}`
389
+ : undefined}
156
390
  ></textarea>
157
391
  </div>
158
392
  {/if}
@@ -173,7 +407,7 @@
173
407
  type="button"
174
408
  class="chat-input__send-btn"
175
409
  onclick={handleSend}
176
- disabled={!inputValue.trim() || !fd.playground.canSendMessage}
410
+ disabled={!canSubmit}
177
411
  title={actions.sendTitle}
178
412
  aria-label={actions.sendTitle}
179
413
  >
@@ -217,10 +451,66 @@
217
451
  justify-content: flex-end;
218
452
  }
219
453
 
454
+ .chat-input__command-feedback {
455
+ display: flex;
456
+ align-items: flex-start;
457
+ gap: var(--fd-space-sm);
458
+ max-width: 760px;
459
+ margin: 0 auto var(--fd-space-sm);
460
+ padding: var(--fd-space-sm) var(--fd-space-md);
461
+ border-radius: var(--fd-radius-md);
462
+ font-size: var(--fd-font-size-sm);
463
+ line-height: 1.4;
464
+ }
465
+
466
+ .chat-input__command-feedback-text {
467
+ flex: 1;
468
+ /* /help returns a newline-separated list — keep its shape. */
469
+ white-space: pre-wrap;
470
+ }
471
+
472
+ /*
473
+ * Status tokens, not literals: `--fd-*-muted` is a translucent tint that is
474
+ * redefined for dark mode, so these follow the theme. Hardcoded pastels do
475
+ * not, and rendered as bright blocks on a dark UI.
476
+ */
477
+ .chat-input__command-feedback--ok {
478
+ background-color: var(--fd-success-muted);
479
+ color: var(--fd-success);
480
+ }
481
+
482
+ .chat-input__command-feedback--info {
483
+ background-color: var(--fd-info-muted);
484
+ color: var(--fd-info);
485
+ }
486
+
487
+ .chat-input__command-feedback--error {
488
+ background-color: var(--fd-error-muted);
489
+ color: var(--fd-error);
490
+ }
491
+
492
+ .chat-input__command-feedback-dismiss {
493
+ flex-shrink: 0;
494
+ display: flex;
495
+ align-items: center;
496
+ background: none;
497
+ border: none;
498
+ padding: 0;
499
+ cursor: pointer;
500
+ color: inherit;
501
+ opacity: 0.7;
502
+ }
503
+
504
+ .chat-input__command-feedback-dismiss:hover {
505
+ opacity: 1;
506
+ }
507
+
220
508
  .chat-input__wrapper {
221
509
  flex: 1;
222
510
  display: flex;
223
511
  align-items: flex-end;
512
+ /* Positioning context for the command palette, which sits above the input. */
513
+ position: relative;
224
514
  background-color: var(--fd-background);
225
515
  border: 1px solid var(--fd-border);
226
516
  border-radius: var(--fd-radius-xl);
@@ -1,13 +1,43 @@
1
+ import { type CommandOutcome } from '../../playground/commands/index.js';
1
2
  interface Props {
2
3
  placeholder?: string;
3
4
  /** Show the textarea (default: true). When false, only the Run button is shown. */
4
5
  showTextarea?: boolean;
5
6
  /** Show the Run button when textarea is hidden (default: true) */
6
7
  showRunButton?: boolean;
7
- /** Message sent when Run is clicked with textarea hidden */
8
+ /**
9
+ * Message sent when Run is clicked, for hosts that deliberately want the
10
+ * run to begin with a specific chat turn.
11
+ *
12
+ * Setting this opts *out* of {@link onRunWorkflow}: an explicitly
13
+ * configured message is a host's intentional choice and is honoured.
14
+ * Leaving it unset is what lets Run launch without fabricating a turn.
15
+ */
8
16
  predefinedMessage?: string;
9
17
  onSendMessage?: (content: string) => void;
10
18
  onStopExecution?: () => void;
19
+ /**
20
+ * Start a run without posting a chat message.
21
+ *
22
+ * Preferred over `onSendMessage` for the Run button. Sending a message to
23
+ * start a run fabricates a user turn that enters the conversation and is
24
+ * replayed as input on the following turn — indistinguishable downstream
25
+ * from something the user actually typed. Hosts that provide this get a Run
26
+ * button that launches instead.
27
+ */
28
+ onRunWorkflow?: () => void;
29
+ /**
30
+ * Enable the slash-command lane (default: false).
31
+ *
32
+ * Opt-in because the lane is only safe where the `onSendMessage` handler
33
+ * actually dispatches commands. A surface that forwards input straight to a
34
+ * backend (ChatPanel) would post `/stop` as literal text — faking a command
35
+ * that nothing implements.
36
+ */
37
+ enableCommands?: boolean;
38
+ /** Transient result of the last slash command. Never a session message. */
39
+ commandFeedback?: CommandOutcome | null;
40
+ onDismissCommandFeedback?: () => void;
11
41
  }
12
42
  declare const ChatInput: import("svelte").Component<Props, {}, "">;
13
43
  type ChatInput = ReturnType<typeof ChatInput>;