@flowdrop/flowdrop 2.0.0-beta.8 → 2.0.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 (74) hide show
  1. package/CHANGELOG.md +89 -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/commands/storeIntegration.svelte.js +11 -1
  13. package/dist/components/App.svelte +56 -17
  14. package/dist/components/ConfigForm.svelte +98 -23
  15. package/dist/components/ConfigForm.svelte.d.ts +21 -2
  16. package/dist/components/ConfigModal.svelte +9 -0
  17. package/dist/components/ConfigPanel.svelte +7 -1
  18. package/dist/components/SettingsPanel.svelte +9 -0
  19. package/dist/components/WorkflowEditor.svelte +5 -2
  20. package/dist/components/chat/AIChatPanel.svelte +42 -6
  21. package/dist/components/chat/CommandPreview.svelte +10 -1
  22. package/dist/components/form/FormPorts.svelte +21 -3
  23. package/dist/components/form/FormRangeField.svelte +5 -3
  24. package/dist/components/form/FormToggle.svelte +27 -2
  25. package/dist/components/form/FormToggle.svelte.d.ts +5 -0
  26. package/dist/components/playground/ChatInput.svelte +316 -26
  27. package/dist/components/playground/ChatInput.svelte.d.ts +31 -1
  28. package/dist/components/playground/ControlPanel.svelte +22 -0
  29. package/dist/components/playground/ControlPanel.svelte.d.ts +13 -0
  30. package/dist/components/playground/Playground.svelte +217 -4
  31. package/dist/components/surfaces/SurfaceOverlay.svelte +7 -1
  32. package/dist/config/endpoints.d.ts +48 -1
  33. package/dist/config/endpoints.js +18 -5
  34. package/dist/messages/defaults.d.ts +98 -0
  35. package/dist/messages/defaults.js +58 -1
  36. package/dist/playground/commands/args.d.ts +32 -0
  37. package/dist/playground/commands/args.js +50 -0
  38. package/dist/playground/commands/dispatch.d.ts +143 -0
  39. package/dist/playground/commands/dispatch.js +162 -0
  40. package/dist/playground/commands/index.d.ts +14 -0
  41. package/dist/playground/commands/index.js +10 -0
  42. package/dist/playground/commands/parser.d.ts +38 -0
  43. package/dist/playground/commands/parser.js +163 -0
  44. package/dist/playground/commands/registry.d.ts +42 -0
  45. package/dist/playground/commands/registry.js +122 -0
  46. package/dist/playground/commands/suggest.d.ts +37 -0
  47. package/dist/playground/commands/suggest.js +46 -0
  48. package/dist/playground/commands/types.d.ts +111 -0
  49. package/dist/playground/commands/types.js +15 -0
  50. package/dist/playground/index.d.ts +19 -0
  51. package/dist/playground/index.js +25 -0
  52. package/dist/playground/runAction.d.ts +48 -0
  53. package/dist/playground/runAction.js +31 -0
  54. package/dist/services/historyService.d.ts +30 -8
  55. package/dist/services/historyService.js +51 -15
  56. package/dist/services/pipelineSignalService.d.ts +97 -0
  57. package/dist/services/pipelineSignalService.js +94 -0
  58. package/dist/services/playgroundService.d.ts +12 -0
  59. package/dist/services/playgroundService.js +22 -0
  60. package/dist/services/workflowLaunchService.d.ts +74 -0
  61. package/dist/services/workflowLaunchService.js +74 -0
  62. package/dist/stores/historyStore.svelte.d.ts +17 -3
  63. package/dist/stores/historyStore.svelte.js +30 -3
  64. package/dist/stores/instanceContainer.svelte.js +5 -0
  65. package/dist/stores/workflowStore.svelte.d.ts +41 -4
  66. package/dist/stores/workflowStore.svelte.js +103 -13
  67. package/dist/types/chat.d.ts +5 -1
  68. package/dist/types/settings.d.ts +11 -0
  69. package/dist/types/settings.js +2 -1
  70. package/dist/utils/canvasSelection.d.ts +25 -0
  71. package/dist/utils/canvasSelection.js +37 -0
  72. package/dist/utils/nodeFormSchema.d.ts +51 -0
  73. package/dist/utils/nodeFormSchema.js +87 -0
  74. package/package.json +1 -1
@@ -25,10 +25,20 @@
25
25
  } from '../../types/playground.js';
26
26
  import { playgroundService } from '../../services/playgroundService.js';
27
27
  import { interruptService } from '../../services/interruptService.js';
28
+ import { pipelineSignalService } from '../../services/pipelineSignalService.js';
29
+ import { workflowLaunchService } from '../../services/workflowLaunchService.js';
28
30
  import { provideInstance } from '../../stores/getInstance.svelte.js';
29
31
  import type { FlowDropInstance } from '../../stores/instanceContainer.svelte.js';
30
32
  import type { PlaygroundMessagesApiResponse } from '../../types/playground.js';
31
33
  import { logger } from '../../utils/logger.js';
34
+ import { m } from '../../messages/index.js';
35
+ import {
36
+ parseSlashCommand,
37
+ dispatchCommand,
38
+ describeLaunchResult,
39
+ type CommandOutcome
40
+ } from '../../playground/commands/index.js';
41
+ import { resolveRunAction } from '../../playground/runAction.js';
32
42
 
33
43
  interface Props {
34
44
  workflowId: string;
@@ -68,6 +78,20 @@
68
78
  let loadedInitialSessionId = $state<string | undefined>(undefined);
69
79
  let autoRunTriggered = $state(false);
70
80
  let isRefreshing = $state(false);
81
+ /**
82
+ * Transient result of the last slash command. Deliberately component state,
83
+ * not a session message — see runCommand.
84
+ */
85
+ let commandFeedback = $state<CommandOutcome | null>(null);
86
+ /**
87
+ * A signal accepted but not yet observed as effective.
88
+ *
89
+ * Backends refuse a second signal on the same pipeline, so we hold this to
90
+ * disable rather than fire a request guaranteed to be rejected. Cleared when
91
+ * the session status changes — that transition is the signal taking effect
92
+ * (or the run ending on its own).
93
+ */
94
+ let pendingSignal = $state<{ pipelineId: string; signal: string } | null>(null);
71
95
  // Monotonic token so a slow session load can't overwrite a newer one when the
72
96
  // user switches sessions faster than the network responds (last-load wins).
73
97
  let loadToken = 0;
@@ -187,9 +211,8 @@
187
211
 
188
212
  if (config.autoRun && !autoRunTriggered) {
189
213
  autoRunTriggered = true;
190
- const predefinedMessage = config.predefinedMessage ?? 'Run workflow';
191
- logger.debug('[Playground] Auto-run triggered with message:', predefinedMessage);
192
- await handleSendMessage(predefinedMessage);
214
+ logger.debug('[Playground] Auto-run triggered');
215
+ await startRun();
193
216
  }
194
217
  } catch (err) {
195
218
  logger.error('[Playground] Initialization error:', err);
@@ -396,9 +419,195 @@
396
419
  }
397
420
  }
398
421
 
422
+ /**
423
+ * Reset a stuck session to idle.
424
+ *
425
+ * Mirrors handleStopExecution: tear down polling and force the local status
426
+ * back to idle even on failure, since the point of reset is to escape a state
427
+ * the client and server disagree about.
428
+ */
429
+ async function handleResetSession(): Promise<void> {
430
+ const sessionId = fd.playground.currentSession?.id;
431
+ if (!sessionId) return;
432
+
433
+ try {
434
+ await playgroundService.resetSession(fd.api.config, sessionId, fd.api.authProvider);
435
+ playgroundService.stopPolling();
436
+ fd.playground.updateSessionStatus('idle');
437
+ fd.playground.setError(null);
438
+ } catch (err) {
439
+ playgroundService.stopPolling();
440
+ fd.playground.updateSessionStatus('idle');
441
+ logger.error('Failed to reset session:', err);
442
+ throw err;
443
+ }
444
+ }
445
+
446
+ /**
447
+ * Launch a run with named inputs and no chat message.
448
+ *
449
+ * Creates a session first when there is none, so the run has a conversation
450
+ * to report into — the launch endpoint accepts a session id precisely so its
451
+ * messages land somewhere the user is looking.
452
+ */
453
+ async function handleLaunchWorkflow(inputs: Record<string, string>) {
454
+ if (!fd.playground.currentSession) {
455
+ await handleCreateSession();
456
+ }
457
+
458
+ const sessionId = fd.playground.currentSession?.id;
459
+
460
+ const result = await workflowLaunchService.launch(
461
+ fd.api.config,
462
+ workflowId,
463
+ { inputs, sessionId },
464
+ fd.api.authProvider
465
+ );
466
+
467
+ if (result.status === 'launched' && sessionId) {
468
+ // Mirror handleSendMessage: reflect the run optimistically and tail it.
469
+ fd.playground.updateSessionStatus('running');
470
+ fd.playground.pinExecution(null);
471
+ fd.playground.setError(null);
472
+ if (!playgroundService.isPolling()) {
473
+ startPolling(sessionId, true);
474
+ }
475
+ }
476
+
477
+ return result;
478
+ }
479
+
480
+ /**
481
+ * Start a run from a button or auto-run, without posting a chat message.
482
+ *
483
+ * Falls back to sending `predefinedMessage` only where the backend has no
484
+ * launch verb — there a message is genuinely the only way to start a run, so
485
+ * the fabricated turn is the lesser evil. Everywhere else this is what stops
486
+ * "Run workflow" appearing in the conversation as though a user typed it.
487
+ */
488
+ async function startRun(): Promise<void> {
489
+ const action = resolveRunAction({
490
+ canLaunch: workflowLaunchService.isSupported(fd.api.config),
491
+ predefinedMessage: config.predefinedMessage,
492
+ defaultMessage: m().playground.chat.predefinedRun
493
+ });
494
+
495
+ if (action.kind === 'message') {
496
+ logger.debug('[Playground] Starting run by message:', action.content);
497
+ await handleSendMessage(action.content);
498
+ return;
499
+ }
500
+
501
+ const result = await handleLaunchWorkflow({});
502
+
503
+ // Only failures need reporting: a successful launch is evident from the run
504
+ // itself appearing in the console.
505
+ if (result.status !== 'launched') {
506
+ commandFeedback = describeLaunchResult(result, m().playground.commands);
507
+ }
508
+ }
509
+
510
+ /**
511
+ * Send an operator signal to a specific pipeline.
512
+ *
513
+ * Records the signal as pending on acceptance so a second one is refused
514
+ * client-side rather than by the backend.
515
+ */
516
+ async function handleSendSignal(
517
+ signal: 'pause' | 'resume' | 'cancel',
518
+ pipelineId: string,
519
+ reason?: string
520
+ ) {
521
+ const result = await pipelineSignalService[signal](
522
+ fd.api.config,
523
+ pipelineId,
524
+ { reason },
525
+ fd.api.authProvider
526
+ );
527
+
528
+ if (result.status === 'accepted') {
529
+ pendingSignal = { pipelineId, signal };
530
+ }
531
+
532
+ return result;
533
+ }
534
+
535
+ /**
536
+ * Clear a pending signal once the session status moves.
537
+ *
538
+ * The status transition is the observable consequence of the signal landing
539
+ * — or of the run ending by itself, which equally means the signal is moot.
540
+ */
541
+ $effect(() => {
542
+ // Track the status so this re-runs on every change.
543
+ void fd.playground.currentSession?.status;
544
+ untrack(() => {
545
+ if (pendingSignal) pendingSignal = null;
546
+ });
547
+ });
548
+
549
+ /**
550
+ * Run a slash command and surface its outcome as transient composer feedback.
551
+ *
552
+ * Commands are never posted as session messages — control traffic must not
553
+ * enter conversation history, or it returns as the next turn's chat input.
554
+ */
555
+ async function runCommand(input: string): Promise<void> {
556
+ const parsed = parseSlashCommand(input);
557
+ const msgs = m().playground.commands;
558
+
559
+ if (parsed.kind === 'unknown') {
560
+ commandFeedback = {
561
+ status: 'error',
562
+ message: parsed.suggestions.length
563
+ ? msgs.unknownWithSuggestions({
564
+ name: parsed.name,
565
+ suggestions: parsed.suggestions.map((s) => `/${s}`).join(', ')
566
+ })
567
+ : msgs.unknown({ name: parsed.name })
568
+ };
569
+ return;
570
+ }
571
+
572
+ if (parsed.kind !== 'command') return;
573
+
574
+ commandFeedback = await dispatchCommand(parsed.command, {
575
+ config: fd.api.config,
576
+ sessionId: fd.playground.currentSession?.id ?? null,
577
+ // The active run: pinned if the user pinned one, else the latest main
578
+ // run. Sub-flows are excluded upstream, so `/pause` targets the run the
579
+ // user means rather than whichever inner iteration is on screen.
580
+ pipelineId: fd.playground.activeExecutionId,
581
+ pendingSignal,
582
+ handlers: {
583
+ createSession: handleCreateSession,
584
+ deleteSession: handleDeleteSession,
585
+ stopExecution: handleStopExecution,
586
+ resetSession: handleResetSession,
587
+ sendSignal: handleSendSignal,
588
+ launchWorkflow: handleLaunchWorkflow
589
+ },
590
+ messages: msgs
591
+ });
592
+ }
593
+
399
594
  async function handleSendMessage(content: string): Promise<void> {
595
+ // Commands are intercepted *before* the executing guard: /stop is only
596
+ // useful while a run is in flight, which is exactly when plain text is
597
+ // refused.
598
+ const parsed = parseSlashCommand(content);
599
+ if (parsed.kind === 'command' || parsed.kind === 'unknown') {
600
+ await runCommand(content);
601
+ return;
602
+ }
603
+
604
+ commandFeedback = null;
605
+
400
606
  if (fd.playground.isExecuting) return;
401
607
 
608
+ // An escaped message (`//foo`) is sent as its literal text (`/foo`).
609
+ const messageContent = parsed.kind === 'message' ? parsed.content : content;
610
+
402
611
  if (!fd.playground.currentSession) {
403
612
  await handleCreateSession();
404
613
  if (!fd.playground.currentSession) return;
@@ -414,7 +623,7 @@
414
623
  const message = await playgroundService.sendMessage(
415
624
  fd.api.config,
416
625
  sessionId,
417
- content,
626
+ messageContent,
418
627
  {},
419
628
  fd.api.authProvider
420
629
  );
@@ -592,7 +801,11 @@
592
801
  onDeleteSession={handleDeleteSession}
593
802
  onSendMessage={handleSendMessage}
594
803
  onStopExecution={handleStopExecution}
804
+ onRunWorkflow={startRun}
595
805
  onRefresh={refreshFromServer}
806
+ enableCommands
807
+ {commandFeedback}
808
+ onDismissCommandFeedback={() => (commandFeedback = null)}
596
809
  showChatInput={config.showChatInput ?? true}
597
810
  showRunButton={config.showRunButton ?? true}
598
811
  predefinedMessage={config.predefinedMessage}
@@ -43,7 +43,6 @@
43
43
  }
44
44
  </script>
45
45
 
46
- <!-- svelte-ignore a11y_click_events_have_key_events -->
47
46
  <!-- svelte-ignore a11y_no_static_element_interactions -->
48
47
  <div
49
48
  class="surface-overlay__backdrop"
@@ -72,6 +71,13 @@
72
71
  .surface-overlay__backdrop {
73
72
  position: fixed;
74
73
  inset: 0;
74
+ /*
75
+ Portalled to document.body, this shell sits outside the editor container
76
+ that carries the app font, so it would otherwise inherit the host page's
77
+ default (e.g. serif on a bare Drupal page). Re-establish the font here,
78
+ mirroring the mount container's declaration.
79
+ */
80
+ font-family: var(--fd-font-family, system-ui, -apple-system, sans-serif);
75
81
  background-color: var(--fd-backdrop, rgba(0, 0, 0, 0.5));
76
82
  display: flex;
77
83
  align-items: center;
@@ -26,6 +26,17 @@ export interface EndpointConfig {
26
26
  validate: string;
27
27
  export: string;
28
28
  import: string;
29
+ /**
30
+ * Launch a run with schema-resolved named inputs, returning the new
31
+ * pipeline id.
32
+ *
33
+ * The semantically correct verb for "start this workflow" — as opposed to
34
+ * posting a chat message and relying on the side effect of a run starting.
35
+ *
36
+ * Optional: a backend without an explicit launch verb omits it, and the
37
+ * `/run` command is not offered.
38
+ */
39
+ run?: string;
29
40
  };
30
41
  executions: {
31
42
  execute: string;
@@ -60,6 +71,42 @@ export interface EndpointConfig {
60
71
  sendMessage: string;
61
72
  /** Stop execution in a session */
62
73
  stopExecution: string;
74
+ /**
75
+ * Reset a stuck session to idle.
76
+ *
77
+ * Optional: a backend that cannot reset a session simply omits this key,
78
+ * and the `/reset` command is not offered. Absence of an endpoint is
79
+ * absence of a capability — see the slash-command registry.
80
+ */
81
+ resetSession?: string;
82
+ };
83
+ /**
84
+ * Operator signals into a *running* pipeline — pause, resume, cancel.
85
+ *
86
+ * Distinct from `interrupts`, which are raised *by* a pipeline and awaited
87
+ * (human-in-the-loop). These travel the other way: an external party acting
88
+ * on a run that never asked.
89
+ *
90
+ * Optional as a whole: a backend with no signal plane omits the block, and
91
+ * the corresponding commands are not offered.
92
+ */
93
+ signals?: {
94
+ /**
95
+ * Root for signal routes, when the backend serves them from a different
96
+ * prefix than {@link EndpointConfig.baseUrl}.
97
+ *
98
+ * Needed because API roots are not always uniform — the reference backend
99
+ * serves signals from `/flowdrop/api` while everything else lives under
100
+ * `/api/flowdrop`, and a single base cannot express both. Omit to use the
101
+ * global `baseUrl`.
102
+ */
103
+ baseUrl?: string;
104
+ /** Pause a running pipeline */
105
+ pause: string;
106
+ /** Resume a paused pipeline */
107
+ resume: string;
108
+ /** Cancel a running pipeline */
109
+ cancel: string;
63
110
  };
64
111
  interrupts: {
65
112
  /** Get interrupt details by ID */
@@ -151,7 +198,7 @@ export declare function createEndpointConfig(baseUrl: string, overrides?: Partia
151
198
  /**
152
199
  * Build full URL for an endpoint
153
200
  */
154
- export declare function buildEndpointUrl(config: EndpointConfig, endpointPath: string, params?: Record<string, string>): string;
201
+ export declare function buildEndpointUrl(config: EndpointConfig, endpointPath: string, params?: Record<string, string>, baseUrlOverride?: string): string;
155
202
  /**
156
203
  * Get HTTP method for an endpoint
157
204
  */
@@ -24,7 +24,9 @@ export const defaultEndpointConfig = {
24
24
  delete: '/workflows/{id}',
25
25
  validate: '/workflows/validate',
26
26
  export: '/workflows/{id}/export',
27
- import: '/workflows/import'
27
+ import: '/workflows/import',
28
+ // Singular `workflow` here is the reference backend's spelling, not a typo.
29
+ run: '/workflow/{workflowId}/run'
28
30
  },
29
31
  executions: {
30
32
  execute: '/workflows/{id}/execute',
@@ -51,7 +53,15 @@ export const defaultEndpointConfig = {
51
53
  deleteSession: '/playground/sessions/{sessionId}',
52
54
  getMessages: '/playground/sessions/{sessionId}/messages',
53
55
  sendMessage: '/playground/sessions/{sessionId}/messages',
54
- stopExecution: '/playground/sessions/{sessionId}/stop'
56
+ stopExecution: '/playground/sessions/{sessionId}/stop',
57
+ resetSession: '/playground/sessions/{sessionId}/reset'
58
+ },
59
+ signals: {
60
+ // The reference backend transposes its prefix for these routes.
61
+ baseUrl: '/flowdrop/api',
62
+ pause: '/pipelines/{pipelineId}/pause',
63
+ resume: '/pipelines/{pipelineId}/resume',
64
+ cancel: '/pipelines/{pipelineId}/cancel'
55
65
  },
56
66
  interrupts: {
57
67
  get: '/interrupts/{interruptId}',
@@ -105,7 +115,7 @@ export function createEndpointConfig(baseUrl, overrides) {
105
115
  /**
106
116
  * Build full URL for an endpoint
107
117
  */
108
- export function buildEndpointUrl(config, endpointPath, params) {
118
+ export function buildEndpointUrl(config, endpointPath, params, baseUrlOverride) {
109
119
  let url = endpointPath;
110
120
  // Replace path parameters
111
121
  if (params) {
@@ -113,9 +123,12 @@ export function buildEndpointUrl(config, endpointPath, params) {
113
123
  url = url.replace(`{${key}}`, encodeURIComponent(value));
114
124
  });
115
125
  }
116
- // Ensure URL starts with base URL
126
+ // Ensure URL starts with base URL. `baseUrlOverride` lets a group of
127
+ // endpoints hang off a different root than the global one — backends do not
128
+ // always serve every API from a single prefix.
129
+ const base = baseUrlOverride ?? config.baseUrl;
117
130
  if (!url.startsWith('http') && !url.startsWith('//')) {
118
- url = `${config.baseUrl}${url.startsWith('/') ? url : `/${url}`}`;
131
+ url = `${base}${url.startsWith('/') ? url : `/${url}`}`;
119
132
  }
120
133
  return url;
121
134
  }
@@ -271,6 +271,7 @@ export declare const defaultMessages: {
271
271
  readonly dismissed: "Dismissed";
272
272
  readonly applyAll: "Apply All";
273
273
  readonly cancel: "Cancel";
274
+ readonly layoutSkipped: "Skipped — AI layout changes are disabled in Settings";
274
275
  };
275
276
  };
276
277
  readonly playground: {
@@ -284,6 +285,103 @@ export declare const defaultMessages: {
284
285
  readonly processing: "Processing...";
285
286
  readonly viewOnlyHelp: "View-only mode. Workflow execution is controlled externally.";
286
287
  };
288
+ readonly commands: {
289
+ readonly unknown: ({ name }: {
290
+ name: string;
291
+ }) => string;
292
+ readonly unknownWithSuggestions: ({ name, suggestions }: {
293
+ name: string;
294
+ suggestions: string;
295
+ }) => string;
296
+ readonly unavailable: ({ name }: {
297
+ name: string;
298
+ }) => string;
299
+ readonly needsSession: ({ name }: {
300
+ name: string;
301
+ }) => string;
302
+ readonly helpHeading: "Available commands";
303
+ readonly helpEscapeHint: "To send a message starting with a slash, type it twice: //like this";
304
+ readonly catalog: {
305
+ readonly help: {
306
+ readonly usage: "/help";
307
+ readonly summary: "List the commands available here";
308
+ };
309
+ readonly run: {
310
+ readonly usage: "/run [--input=value ...]";
311
+ readonly summary: "Start a run, optionally with named inputs";
312
+ };
313
+ readonly new: {
314
+ readonly usage: "/new";
315
+ readonly summary: "Start a new session";
316
+ };
317
+ readonly stop: {
318
+ readonly usage: "/stop";
319
+ readonly summary: "Stop what this session is running";
320
+ };
321
+ readonly reset: {
322
+ readonly usage: "/reset";
323
+ readonly summary: "Reset a stuck session to idle";
324
+ };
325
+ readonly delete: {
326
+ readonly usage: "/delete";
327
+ readonly summary: "Delete the current session";
328
+ };
329
+ readonly pause: {
330
+ readonly usage: "/pause [reason]";
331
+ readonly summary: "Ask the active run to pause";
332
+ };
333
+ readonly resume: {
334
+ readonly usage: "/resume [reason]";
335
+ readonly summary: "Resume the paused run";
336
+ };
337
+ readonly cancel: {
338
+ readonly usage: "/cancel [reason]";
339
+ readonly summary: "Cancel the active run — cannot be undone";
340
+ };
341
+ };
342
+ readonly dismiss: "Dismiss";
343
+ readonly stopped: "Execution stopped";
344
+ readonly reset: "Session reset";
345
+ readonly created: "New session created";
346
+ readonly deleted: "Session deleted";
347
+ readonly failed: ({ name, error }: {
348
+ name: string;
349
+ error: string;
350
+ }) => string;
351
+ readonly needsRun: ({ name }: {
352
+ name: string;
353
+ }) => string;
354
+ readonly signalPending: ({ signal }: {
355
+ signal: string;
356
+ }) => string;
357
+ readonly pauseRequested: "Pause requested — finishing the current step";
358
+ readonly resumeRequested: "Resume requested";
359
+ readonly cancelRequested: "Cancel requested — finishing the current step";
360
+ readonly refusedTerminal: ({ name }: {
361
+ name: string;
362
+ }) => string;
363
+ readonly refusedDuplicate: "A signal is already pending for this run";
364
+ readonly refusedNotPaused: "Nothing to resume — this run is not paused";
365
+ readonly refusedNotFound: "That run no longer exists";
366
+ readonly refusedForbidden: ({ name }: {
367
+ name: string;
368
+ }) => string;
369
+ readonly refusedOther: ({ name, error }: {
370
+ name: string;
371
+ error: string;
372
+ }) => string;
373
+ readonly runStarted: "Run started";
374
+ readonly runInvalidInput: ({ error }: {
375
+ error: string;
376
+ }) => string;
377
+ readonly runInvalidWorkflow: ({ error }: {
378
+ error: string;
379
+ }) => string;
380
+ readonly runInvalidWorkflowDetail: ({ locator, message }: {
381
+ locator: string;
382
+ message: string;
383
+ }) => string;
384
+ };
287
385
  readonly actions: {
288
386
  readonly stopTitle: "Stop execution";
289
387
  readonly stop: "Stop";
@@ -249,7 +249,8 @@ export const defaultMessages = {
249
249
  applied: 'Applied',
250
250
  dismissed: 'Dismissed',
251
251
  applyAll: 'Apply All',
252
- cancel: 'Cancel'
252
+ cancel: 'Cancel',
253
+ layoutSkipped: 'Skipped — AI layout changes are disabled in Settings'
253
254
  }
254
255
  },
255
256
  playground: {
@@ -263,6 +264,62 @@ export const defaultMessages = {
263
264
  processing: 'Processing...',
264
265
  viewOnlyHelp: 'View-only mode. Workflow execution is controlled externally.'
265
266
  },
267
+ // Slash commands — the composer's out-of-band control lane. Feedback is
268
+ // transient UI, never a session message: control traffic must not enter
269
+ // conversation history, or it feeds back into the next turn's input.
270
+ commands: {
271
+ unknown: ({ name }) => `Unknown command: /${name}`,
272
+ unknownWithSuggestions: ({ name, suggestions }) => `Unknown command: /${name}. Did you mean ${suggestions}?`,
273
+ unavailable: ({ name }) => `/${name} is not supported by this backend`,
274
+ needsSession: ({ name }) => `/${name} needs an active session`,
275
+ helpHeading: 'Available commands',
276
+ helpEscapeHint: 'To send a message starting with a slash, type it twice: //like this',
277
+ // Display text for each command, shown by `/help` and by the palette.
278
+ // Lives here rather than in the command registry so translators reach it
279
+ // through the same channel as everything else; the registry keeps only
280
+ // the structural facts (does it take arguments, is it available).
281
+ catalog: {
282
+ help: { usage: '/help', summary: 'List the commands available here' },
283
+ run: {
284
+ usage: '/run [--input=value ...]',
285
+ summary: 'Start a run, optionally with named inputs'
286
+ },
287
+ new: { usage: '/new', summary: 'Start a new session' },
288
+ stop: { usage: '/stop', summary: 'Stop what this session is running' },
289
+ reset: { usage: '/reset', summary: 'Reset a stuck session to idle' },
290
+ delete: { usage: '/delete', summary: 'Delete the current session' },
291
+ pause: { usage: '/pause [reason]', summary: 'Ask the active run to pause' },
292
+ resume: { usage: '/resume [reason]', summary: 'Resume the paused run' },
293
+ cancel: { usage: '/cancel [reason]', summary: 'Cancel the active run — cannot be undone' }
294
+ },
295
+ dismiss: 'Dismiss',
296
+ stopped: 'Execution stopped',
297
+ reset: 'Session reset',
298
+ created: 'New session created',
299
+ deleted: 'Session deleted',
300
+ failed: ({ name, error }) => `/${name} failed: ${error}`,
301
+ // Pipeline signals. Wording matters: a backend acknowledges a signal
302
+ // before acting on it, so these say "requested" and let the status poll
303
+ // report the real state. Claiming "Paused" on acknowledgement would be
304
+ // wrong exactly when the current step is slow.
305
+ needsRun: ({ name }) => `/${name} needs an active run`,
306
+ signalPending: ({ signal }) => `A ${signal} is already pending for this run`,
307
+ pauseRequested: 'Pause requested — finishing the current step',
308
+ resumeRequested: 'Resume requested',
309
+ cancelRequested: 'Cancel requested — finishing the current step',
310
+ refusedTerminal: ({ name }) => `Cannot ${name}: the run already finished`,
311
+ refusedDuplicate: 'A signal is already pending for this run',
312
+ refusedNotPaused: 'Nothing to resume — this run is not paused',
313
+ refusedNotFound: 'That run no longer exists',
314
+ refusedForbidden: ({ name }) => `You do not have permission to ${name} this run`,
315
+ refusedOther: ({ name, error }) => `/${name} refused: ${error}`,
316
+ // Launch. Bad inputs and an invalid workflow are separated on purpose —
317
+ // one is the caller's to fix, the other is an authoring problem.
318
+ runStarted: 'Run started',
319
+ runInvalidInput: ({ error }) => `Cannot start: ${error}`,
320
+ runInvalidWorkflow: ({ error }) => `Cannot start — this workflow has errors: ${error}`,
321
+ runInvalidWorkflowDetail: ({ locator, message }) => locator ? ` • ${locator}: ${message}` : ` • ${message}`
322
+ },
266
323
  actions: {
267
324
  stopTitle: 'Stop execution',
268
325
  stop: 'Stop',
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Command Argument Parsing
3
+ *
4
+ * Turns `/run --topic=foo --tone=formal` into named launch inputs.
5
+ *
6
+ * Deliberately thin: the client does **not** validate these. A workflow's
7
+ * launch inputs are declared server-side as a manifest, and the backend already
8
+ * gates them — unknown keys and wrong types are refused there, with per-input
9
+ * error locators. Re-implementing that here would create a second, divergent
10
+ * schema and reject inputs the backend would have accepted.
11
+ *
12
+ * @module playground/commands/args
13
+ */
14
+ /** Result of reading flags off a command's argument list. */
15
+ export interface ParsedArgs {
16
+ /** Named `--key=value` inputs, in source order. */
17
+ inputs: Record<string, string>;
18
+ /** Tokens that were not flags, joined — used as free text (e.g. a reason). */
19
+ rest: string;
20
+ }
21
+ /**
22
+ * Parse `--key=value` flags out of a token list.
23
+ *
24
+ * Supported forms:
25
+ * - `--key=value` — the canonical form
26
+ * - `--key value` — two tokens, when the next token is not itself a flag
27
+ * - `--key` — a bare flag, treated as the string `"true"`
28
+ *
29
+ * Values arrive already unquoted by the tokenizer, so `--topic="Q2 revenue"`
30
+ * yields `{topic: 'Q2 revenue'}`.
31
+ */
32
+ export declare function parseArgs(tokens: readonly string[]): ParsedArgs;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Command Argument Parsing
3
+ *
4
+ * Turns `/run --topic=foo --tone=formal` into named launch inputs.
5
+ *
6
+ * Deliberately thin: the client does **not** validate these. A workflow's
7
+ * launch inputs are declared server-side as a manifest, and the backend already
8
+ * gates them — unknown keys and wrong types are refused there, with per-input
9
+ * error locators. Re-implementing that here would create a second, divergent
10
+ * schema and reject inputs the backend would have accepted.
11
+ *
12
+ * @module playground/commands/args
13
+ */
14
+ /**
15
+ * Parse `--key=value` flags out of a token list.
16
+ *
17
+ * Supported forms:
18
+ * - `--key=value` — the canonical form
19
+ * - `--key value` — two tokens, when the next token is not itself a flag
20
+ * - `--key` — a bare flag, treated as the string `"true"`
21
+ *
22
+ * Values arrive already unquoted by the tokenizer, so `--topic="Q2 revenue"`
23
+ * yields `{topic: 'Q2 revenue'}`.
24
+ */
25
+ export function parseArgs(tokens) {
26
+ const inputs = {};
27
+ const rest = [];
28
+ for (let i = 0; i < tokens.length; i++) {
29
+ const token = tokens[i];
30
+ if (!token.startsWith('--') || token.length <= 2) {
31
+ rest.push(token);
32
+ continue;
33
+ }
34
+ const body = token.slice(2);
35
+ const equals = body.indexOf('=');
36
+ if (equals !== -1) {
37
+ inputs[body.slice(0, equals)] = body.slice(equals + 1);
38
+ continue;
39
+ }
40
+ // `--key value`, unless the next token is another flag.
41
+ const next = tokens[i + 1];
42
+ if (next !== undefined && !next.startsWith('--')) {
43
+ inputs[body] = next;
44
+ i++;
45
+ continue;
46
+ }
47
+ inputs[body] = 'true';
48
+ }
49
+ return { inputs, rest: rest.join(' ') };
50
+ }