@flowdrop/flowdrop 2.0.0-beta.9 → 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 +81 -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 +0 -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 +0 -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
@@ -0,0 +1,143 @@
1
+ /**
2
+ * Playground Slash Command Dispatch
3
+ *
4
+ * Maps a parsed command onto the session operations the host already provides.
5
+ *
6
+ * Two invariants live here:
7
+ *
8
+ * 1. **Commands never become session messages.** A `/stop` that posted a user
9
+ * message would pollute the `history` the backend feeds into the next turn's
10
+ * chat input — control traffic would come back as conversation. Feedback is
11
+ * returned to the caller as a {@link CommandOutcome} for transient display.
12
+ * 2. **Availability is checked before dispatch.** An unavailable command
13
+ * reports that it is unsupported rather than calling an endpoint the host
14
+ * never configured.
15
+ *
16
+ * @module playground/commands/dispatch
17
+ */
18
+ import type { EndpointConfig } from '../../config/endpoints.js';
19
+ import type { SignalResult } from '../../services/pipelineSignalService.js';
20
+ import type { LaunchResult } from '../../services/workflowLaunchService.js';
21
+ import type { CommandLabels, CommandOutcome, SlashCommand } from './types.js';
22
+ /**
23
+ * The session operations a command can invoke.
24
+ *
25
+ * Deliberately expressed as callbacks rather than a service import: the host
26
+ * component already owns error handling, polling teardown and store updates for
27
+ * each of these, and duplicating that here would create a second, subtly
28
+ * different code path for the same operations.
29
+ */
30
+ export interface CommandHandlers {
31
+ createSession: () => Promise<void>;
32
+ deleteSession: (sessionId: string) => Promise<void>;
33
+ stopExecution: () => Promise<void>;
34
+ resetSession: () => Promise<void>;
35
+ /** Send an operator signal to a specific pipeline. */
36
+ sendSignal: (signal: 'pause' | 'resume' | 'cancel', pipelineId: string, reason?: string) => Promise<SignalResult>;
37
+ /** Launch a run with named inputs and no chat message. */
38
+ launchWorkflow: (inputs: Record<string, string>) => Promise<LaunchResult>;
39
+ }
40
+ /** Everything dispatch needs to know about the current surface. */
41
+ export interface CommandContext {
42
+ config: EndpointConfig | null;
43
+ /** Current session id, or null when none is active. */
44
+ sessionId: string | null;
45
+ /**
46
+ * The pipeline signals should target — the run the user means by "this run".
47
+ *
48
+ * Resolved by the caller from the active run (pinned if the user pinned one,
49
+ * otherwise the latest *main* run). Sub-flow runs must never appear here:
50
+ * pausing what looks like "the run" has to pause the root, not whichever
51
+ * inner iteration happens to be on screen.
52
+ */
53
+ pipelineId: string | null;
54
+ /**
55
+ * A signal already awaiting acknowledgement on {@link pipelineId}, if any.
56
+ *
57
+ * Backends reject a second signal on the same pipeline, so the client
58
+ * disables rather than firing a request that is guaranteed to be refused —
59
+ * a slash command is exactly the frantic-double-submit surface that guard
60
+ * exists for.
61
+ */
62
+ pendingSignal?: {
63
+ pipelineId: string;
64
+ signal: string;
65
+ } | null;
66
+ handlers: CommandHandlers;
67
+ /** Message accessors, passed in so this module stays free of Svelte context. */
68
+ messages: CommandMessages;
69
+ }
70
+ /** The message shapes dispatch needs. Mirrors `m().playground.commands`. */
71
+ export interface CommandMessages {
72
+ /** Display text per command, for `/help`. */
73
+ catalog: CommandLabels;
74
+ unavailable: (p: {
75
+ name: string;
76
+ }) => string;
77
+ needsSession: (p: {
78
+ name: string;
79
+ }) => string;
80
+ helpHeading: string;
81
+ helpEscapeHint: string;
82
+ stopped: string;
83
+ reset: string;
84
+ created: string;
85
+ deleted: string;
86
+ failed: (p: {
87
+ name: string;
88
+ error: string;
89
+ }) => string;
90
+ needsRun: (p: {
91
+ name: string;
92
+ }) => string;
93
+ signalPending: (p: {
94
+ signal: string;
95
+ }) => string;
96
+ pauseRequested: string;
97
+ resumeRequested: string;
98
+ cancelRequested: string;
99
+ refusedTerminal: (p: {
100
+ name: string;
101
+ }) => string;
102
+ refusedDuplicate: string;
103
+ refusedNotPaused: string;
104
+ refusedNotFound: string;
105
+ refusedForbidden: (p: {
106
+ name: string;
107
+ }) => string;
108
+ refusedOther: (p: {
109
+ name: string;
110
+ error: string;
111
+ }) => string;
112
+ runStarted: string;
113
+ runInvalidInput: (p: {
114
+ error: string;
115
+ }) => string;
116
+ runInvalidWorkflow: (p: {
117
+ error: string;
118
+ }) => string;
119
+ runInvalidWorkflowDetail: (p: {
120
+ locator: string;
121
+ message: string;
122
+ }) => string;
123
+ }
124
+ /**
125
+ * Execute a parsed command.
126
+ *
127
+ * Never throws: every failure is reported as an `error` outcome so the composer
128
+ * has something to show. Callers render the outcome transiently and discard it.
129
+ */
130
+ export declare function dispatchCommand(command: SlashCommand, context: CommandContext): Promise<CommandOutcome>;
131
+ /**
132
+ * Turn a launch result into user-facing feedback.
133
+ *
134
+ * The two failure modes are kept apart deliberately: bad *inputs* are the
135
+ * caller's to fix, while an invalid stored *workflow* is an authoring problem
136
+ * nothing about the command can address. Collapsing them would send users
137
+ * hunting through their arguments for a fault that is in the graph.
138
+ *
139
+ * Exported because the Run button and auto-run launch through the same service
140
+ * and must report identically — a launch failure should not look like one thing
141
+ * from a command and another from a button.
142
+ */
143
+ export declare function describeLaunchResult(result: LaunchResult, messages: CommandMessages): CommandOutcome;
@@ -0,0 +1,162 @@
1
+ /**
2
+ * Playground Slash Command Dispatch
3
+ *
4
+ * Maps a parsed command onto the session operations the host already provides.
5
+ *
6
+ * Two invariants live here:
7
+ *
8
+ * 1. **Commands never become session messages.** A `/stop` that posted a user
9
+ * message would pollute the `history` the backend feeds into the next turn's
10
+ * chat input — control traffic would come back as conversation. Feedback is
11
+ * returned to the caller as a {@link CommandOutcome} for transient display.
12
+ * 2. **Availability is checked before dispatch.** An unavailable command
13
+ * reports that it is unsupported rather than calling an endpoint the host
14
+ * never configured.
15
+ *
16
+ * @module playground/commands/dispatch
17
+ */
18
+ import { getAvailableCommands, isCommandAvailable, SIGNAL_COMMANDS } from './registry.js';
19
+ import { parseArgs } from './args.js';
20
+ /** Commands that cannot do anything useful without an active session. */
21
+ const REQUIRES_SESSION = new Set(['stop', 'reset', 'delete']);
22
+ /**
23
+ * Execute a parsed command.
24
+ *
25
+ * Never throws: every failure is reported as an `error` outcome so the composer
26
+ * has something to show. Callers render the outcome transiently and discard it.
27
+ */
28
+ export async function dispatchCommand(command, context) {
29
+ const { name } = command;
30
+ const { config, sessionId, pipelineId, pendingSignal, handlers, messages } = context;
31
+ if (!isCommandAvailable(name, config)) {
32
+ return { status: 'error', message: messages.unavailable({ name }) };
33
+ }
34
+ if (REQUIRES_SESSION.has(name) && !sessionId) {
35
+ return { status: 'error', message: messages.needsSession({ name }) };
36
+ }
37
+ if (SIGNAL_COMMANDS.has(name)) {
38
+ if (!pipelineId) {
39
+ return { status: 'error', message: messages.needsRun({ name }) };
40
+ }
41
+ if (pendingSignal && pendingSignal.pipelineId === pipelineId) {
42
+ return {
43
+ status: 'error',
44
+ message: messages.signalPending({ signal: pendingSignal.signal })
45
+ };
46
+ }
47
+ }
48
+ try {
49
+ switch (name) {
50
+ case 'help':
51
+ return { status: 'info', message: buildHelp(config, messages) };
52
+ case 'new':
53
+ await handlers.createSession();
54
+ return { status: 'ok', message: messages.created };
55
+ case 'stop':
56
+ await handlers.stopExecution();
57
+ return { status: 'ok', message: messages.stopped };
58
+ case 'reset':
59
+ await handlers.resetSession();
60
+ return { status: 'ok', message: messages.reset };
61
+ case 'delete':
62
+ await handlers.deleteSession(sessionId);
63
+ return { status: 'ok', message: messages.deleted };
64
+ case 'run': {
65
+ // Named inputs only; loose words are ignored rather than smuggled in as
66
+ // a fake message. `/run` exists precisely to not post one.
67
+ const { inputs } = parseArgs(command.args);
68
+ return describeLaunchResult(await handlers.launchWorkflow(inputs), messages);
69
+ }
70
+ case 'pause':
71
+ case 'resume':
72
+ case 'cancel': {
73
+ const result = await handlers.sendSignal(name, pipelineId, command.args.join(' ') || undefined);
74
+ return describeSignalResult(name, result, messages);
75
+ }
76
+ }
77
+ }
78
+ catch (err) {
79
+ const error = err instanceof Error ? err.message : String(err);
80
+ return { status: 'error', message: messages.failed({ name, error }) };
81
+ }
82
+ }
83
+ /**
84
+ * Turn a signal result into user-facing feedback.
85
+ *
86
+ * Accepted signals report **requested**, never done. Backends observe signals
87
+ * cooperatively — the reference implementation polls between job steps, so the
88
+ * step in flight always finishes first. Rendering "Paused" on acceptance would
89
+ * be a lie precisely when the current step is slow, which is exactly when
90
+ * someone reaches for `/pause`. The status poll flips it to the real state.
91
+ */
92
+ function describeSignalResult(name, result, messages) {
93
+ if (result.status === 'unsupported') {
94
+ return { status: 'error', message: messages.unavailable({ name }) };
95
+ }
96
+ if (result.status === 'accepted') {
97
+ const requested = {
98
+ pause: messages.pauseRequested,
99
+ resume: messages.resumeRequested,
100
+ cancel: messages.cancelRequested
101
+ }[name];
102
+ return { status: 'info', message: requested };
103
+ }
104
+ switch (result.reason) {
105
+ case 'terminal':
106
+ return { status: 'error', message: messages.refusedTerminal({ name }) };
107
+ case 'duplicate':
108
+ return { status: 'error', message: messages.refusedDuplicate };
109
+ case 'not-paused':
110
+ return { status: 'error', message: messages.refusedNotPaused };
111
+ case 'not-found':
112
+ return { status: 'error', message: messages.refusedNotFound };
113
+ case 'forbidden':
114
+ return { status: 'error', message: messages.refusedForbidden({ name }) };
115
+ default:
116
+ return {
117
+ status: 'error',
118
+ message: messages.refusedOther({ name, error: result.message })
119
+ };
120
+ }
121
+ }
122
+ /**
123
+ * Turn a launch result into user-facing feedback.
124
+ *
125
+ * The two failure modes are kept apart deliberately: bad *inputs* are the
126
+ * caller's to fix, while an invalid stored *workflow* is an authoring problem
127
+ * nothing about the command can address. Collapsing them would send users
128
+ * hunting through their arguments for a fault that is in the graph.
129
+ *
130
+ * Exported because the Run button and auto-run launch through the same service
131
+ * and must report identically — a launch failure should not look like one thing
132
+ * from a command and another from a button.
133
+ */
134
+ export function describeLaunchResult(result, messages) {
135
+ switch (result.status) {
136
+ case 'launched':
137
+ return { status: 'ok', message: messages.runStarted };
138
+ case 'unsupported':
139
+ return { status: 'error', message: messages.unavailable({ name: 'run' }) };
140
+ case 'invalid-input':
141
+ return { status: 'error', message: messages.runInvalidInput({ error: result.message }) };
142
+ case 'invalid-workflow': {
143
+ // Surface the backend's own per-error locators rather than a summary —
144
+ // they name the offending parameter, which is the only actionable part.
145
+ const details = result.errors.map((e) => messages.runInvalidWorkflowDetail({ locator: e.locator ?? '', message: e.message }));
146
+ return {
147
+ status: 'error',
148
+ message: [messages.runInvalidWorkflow({ error: result.message }), ...details].join('\n')
149
+ };
150
+ }
151
+ case 'failed':
152
+ return { status: 'error', message: messages.failed({ name: 'run', error: result.message }) };
153
+ }
154
+ }
155
+ /**
156
+ * Build help text from what is actually available here, not from the full
157
+ * command list — so a backend without session reset never advertises `/reset`.
158
+ */
159
+ function buildHelp(config, messages) {
160
+ const lines = getAvailableCommands(config).map((d) => `${messages.catalog[d.name].usage} — ${messages.catalog[d.name].summary}`);
161
+ return [messages.helpHeading, ...lines, '', messages.helpEscapeHint].join('\n');
162
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Playground slash commands — the composer's out-of-band control lane.
3
+ *
4
+ * @module playground/commands
5
+ */
6
+ export type { SlashCommand, SlashCommandName, SlashCommandDescriptor, CommandLabel, CommandLabels, ParseResult, CommandOutcome } from './types.js';
7
+ export type { CommandHandlers, CommandContext, CommandMessages } from './dispatch.js';
8
+ export type { ParsedArgs } from './args.js';
9
+ export type { CommandSuggestion } from './suggest.js';
10
+ export { suggestCommands } from './suggest.js';
11
+ export { parseSlashCommand, isKnownCommand, isCommandInput, tokenize } from './parser.js';
12
+ export { parseArgs } from './args.js';
13
+ export { dispatchCommand, describeLaunchResult } from './dispatch.js';
14
+ export { COMMAND_NAMES, COMMAND_DESCRIPTORS, SIGNAL_COMMANDS, getDescriptor, getAvailableCommands, isCommandAvailable } from './registry.js';
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Playground slash commands — the composer's out-of-band control lane.
3
+ *
4
+ * @module playground/commands
5
+ */
6
+ export { suggestCommands } from './suggest.js';
7
+ export { parseSlashCommand, isKnownCommand, isCommandInput, tokenize } from './parser.js';
8
+ export { parseArgs } from './args.js';
9
+ export { dispatchCommand, describeLaunchResult } from './dispatch.js';
10
+ export { COMMAND_NAMES, COMMAND_DESCRIPTORS, SIGNAL_COMMANDS, getDescriptor, getAvailableCommands, isCommandAvailable } from './registry.js';
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Playground Slash Command Parser
3
+ *
4
+ * Pure, synchronous, dependency-free: given composer input, decide whether it
5
+ * is a command, a message, or a typo. No network, no store, no config — so the
6
+ * escape rule and the command grammar can be tested in isolation.
7
+ *
8
+ * @module playground/commands/parser
9
+ */
10
+ import type { ParseResult, SlashCommandName } from './types.js';
11
+ /**
12
+ * Split a command body into tokens, keeping quoted runs together.
13
+ *
14
+ * Needed because launch arguments carry real prose — `/run --topic="Q2 revenue"`
15
+ * is one argument, not two. Both quote styles are accepted so a value can
16
+ * contain the other, and a quote may open mid-token (`--topic="a b"`) since
17
+ * that is how flags are naturally written.
18
+ *
19
+ * An unterminated quote runs to end of input rather than failing: the user is
20
+ * mid-typing, and refusing to parse would make the composer feel broken.
21
+ */
22
+ export declare function tokenize(body: string): string[];
23
+ /**
24
+ * Parse composer input into a command, a message, or an unknown-command error.
25
+ *
26
+ * Unknown commands are **not** forwarded as messages. A typo like `/stpo` must
27
+ * not silently launch a pipeline with `/stpo` as its input — the whole point of
28
+ * the lane is that control traffic and pipeline data never cross.
29
+ */
30
+ export declare function parseSlashCommand(input: string): ParseResult;
31
+ /** Type guard narrowing an arbitrary string to a known command name. */
32
+ export declare function isKnownCommand(name: string): name is SlashCommandName;
33
+ /**
34
+ * True when input would be routed to the control plane rather than sent as a
35
+ * message. Used by the composer to keep commands submittable while a run is in
36
+ * flight (when plain text is not).
37
+ */
38
+ export declare function isCommandInput(input: string): boolean;
@@ -0,0 +1,163 @@
1
+ /**
2
+ * Playground Slash Command Parser
3
+ *
4
+ * Pure, synchronous, dependency-free: given composer input, decide whether it
5
+ * is a command, a message, or a typo. No network, no store, no config — so the
6
+ * escape rule and the command grammar can be tested in isolation.
7
+ *
8
+ * @module playground/commands/parser
9
+ */
10
+ import { COMMAND_NAMES } from './registry.js';
11
+ /**
12
+ * The escape sequence for a message that genuinely starts with a slash.
13
+ *
14
+ * `//deploy the thing` sends the literal text `/deploy the thing`. Exactly one
15
+ * leading slash is consumed, so `///x` sends `//x` — the rule composes rather
16
+ * than special-casing depth.
17
+ *
18
+ * This must stay decided and documented: once users have sent messages
19
+ * beginning with `/`, changing the escape silently rewrites their intent.
20
+ */
21
+ const ESCAPE_PREFIX = '//';
22
+ /** Longest command name, used to bound the typo search. */
23
+ const MAX_NAME_LENGTH = Math.max(...COMMAND_NAMES.map((n) => n.length));
24
+ /**
25
+ * Split a command body into tokens, keeping quoted runs together.
26
+ *
27
+ * Needed because launch arguments carry real prose — `/run --topic="Q2 revenue"`
28
+ * is one argument, not two. Both quote styles are accepted so a value can
29
+ * contain the other, and a quote may open mid-token (`--topic="a b"`) since
30
+ * that is how flags are naturally written.
31
+ *
32
+ * An unterminated quote runs to end of input rather than failing: the user is
33
+ * mid-typing, and refusing to parse would make the composer feel broken.
34
+ */
35
+ export function tokenize(body) {
36
+ const tokens = [];
37
+ let current = '';
38
+ let quote = null;
39
+ let started = false;
40
+ for (const char of body) {
41
+ if (quote) {
42
+ if (char === quote)
43
+ quote = null;
44
+ else
45
+ current += char;
46
+ continue;
47
+ }
48
+ if (char === '"' || char === "'") {
49
+ quote = char;
50
+ started = true;
51
+ continue;
52
+ }
53
+ if (/\s/.test(char)) {
54
+ if (started)
55
+ tokens.push(current);
56
+ current = '';
57
+ started = false;
58
+ continue;
59
+ }
60
+ current += char;
61
+ started = true;
62
+ }
63
+ if (started)
64
+ tokens.push(current);
65
+ return tokens;
66
+ }
67
+ /**
68
+ * Suggest commands for an unrecognised name.
69
+ *
70
+ * Deliberately conservative — prefix matches first, then single-edit
71
+ * neighbours. A wrong suggestion is worse than none: the user is one keystroke
72
+ * from running something they did not intend.
73
+ */
74
+ function suggest(name) {
75
+ const lower = name.toLowerCase();
76
+ if (!lower)
77
+ return [...COMMAND_NAMES];
78
+ const prefixed = COMMAND_NAMES.filter((n) => n.startsWith(lower));
79
+ if (prefixed.length > 0)
80
+ return prefixed;
81
+ if (lower.length > MAX_NAME_LENGTH + 2)
82
+ return [];
83
+ return COMMAND_NAMES.filter((n) => isSingleEditApart(lower, n));
84
+ }
85
+ /**
86
+ * True when `a` and `b` differ by at most one insertion, deletion,
87
+ * substitution, **or transposition of adjacent characters**.
88
+ *
89
+ * The transposition arm matters more than the rest: `/stpo` for `/stop` is the
90
+ * single most common way to mistype a short word, and plain Levenshtein scores
91
+ * it as two edits — so omitting it would leave the most likely typo
92
+ * unsuggested. This is Damerau-Levenshtein restricted to distance 1, which
93
+ * stays cheap and predictable for strings this short.
94
+ */
95
+ function isSingleEditApart(a, b) {
96
+ if (a === b)
97
+ return true;
98
+ const [shorter, longer] = a.length <= b.length ? [a, b] : [b, a];
99
+ if (longer.length - shorter.length > 1)
100
+ return false;
101
+ // Locate the first and last positions where the two disagree.
102
+ let head = 0;
103
+ while (head < shorter.length && shorter[head] === longer[head])
104
+ head++;
105
+ let tail = 0;
106
+ while (tail < shorter.length - head &&
107
+ shorter[shorter.length - 1 - tail] === longer[longer.length - 1 - tail]) {
108
+ tail++;
109
+ }
110
+ // Characters left unmatched in the middle of each string.
111
+ const shorterRemainder = shorter.length - head - tail;
112
+ const longerRemainder = longer.length - head - tail;
113
+ // One substitution (1/1), or one insertion/deletion (0/1).
114
+ if (longerRemainder <= 1 && shorterRemainder <= 1)
115
+ return true;
116
+ // One transposition: exactly two mismatched characters, equal lengths, swapped.
117
+ return (shorterRemainder === 2 &&
118
+ longerRemainder === 2 &&
119
+ shorter[head] === longer[head + 1] &&
120
+ shorter[head + 1] === longer[head]);
121
+ }
122
+ /**
123
+ * Parse composer input into a command, a message, or an unknown-command error.
124
+ *
125
+ * Unknown commands are **not** forwarded as messages. A typo like `/stpo` must
126
+ * not silently launch a pipeline with `/stpo` as its input — the whole point of
127
+ * the lane is that control traffic and pipeline data never cross.
128
+ */
129
+ export function parseSlashCommand(input) {
130
+ const trimmed = input.trim();
131
+ if (!trimmed)
132
+ return { kind: 'empty' };
133
+ if (trimmed.startsWith(ESCAPE_PREFIX)) {
134
+ return { kind: 'message', content: trimmed.slice(1) };
135
+ }
136
+ if (!trimmed.startsWith('/')) {
137
+ return { kind: 'message', content: trimmed };
138
+ }
139
+ const body = trimmed.slice(1);
140
+ const parts = tokenize(body);
141
+ const rawName = parts[0] ?? '';
142
+ const name = rawName.toLowerCase();
143
+ if (!isKnownCommand(name)) {
144
+ return { kind: 'unknown', name: rawName, suggestions: suggest(name) };
145
+ }
146
+ return {
147
+ kind: 'command',
148
+ command: { name, args: parts.slice(1), raw: trimmed }
149
+ };
150
+ }
151
+ /** Type guard narrowing an arbitrary string to a known command name. */
152
+ export function isKnownCommand(name) {
153
+ return COMMAND_NAMES.includes(name);
154
+ }
155
+ /**
156
+ * True when input would be routed to the control plane rather than sent as a
157
+ * message. Used by the composer to keep commands submittable while a run is in
158
+ * flight (when plain text is not).
159
+ */
160
+ export function isCommandInput(input) {
161
+ const result = parseSlashCommand(input);
162
+ return result.kind === 'command' || result.kind === 'unknown';
163
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Playground Slash Command Registry
3
+ *
4
+ * The single source of truth for which commands exist and when they are
5
+ * offered. Availability is derived from the *configured endpoints*, never from
6
+ * knowledge of a particular backend: FlowDrop ships as a standalone library and
7
+ * may be pointed at any API implementing the shape.
8
+ *
9
+ * @module playground/commands/registry
10
+ */
11
+ import type { EndpointConfig } from '../../config/endpoints.js';
12
+ import type { SlashCommandDescriptor, SlashCommandName } from './types.js';
13
+ /**
14
+ * Canonical command list. Order is the order shown by `/help`.
15
+ *
16
+ * Declared as a plain tuple so the parser can bound its typo search and the
17
+ * type system keeps {@link SlashCommandName} and this array in lockstep.
18
+ */
19
+ export declare const COMMAND_NAMES: readonly ["help", "run", "new", "stop", "reset", "delete", "pause", "resume", "cancel"];
20
+ /**
21
+ * Structure only — no display text. What each command *says* lives in
22
+ * `m().playground.commands.catalog` so it can be translated; what each command
23
+ * *is* lives here so pure logic never has to parse prose.
24
+ */
25
+ export declare const COMMAND_DESCRIPTORS: readonly SlashCommandDescriptor[];
26
+ /**
27
+ * Commands that act on a specific pipeline and cannot run without a resolved
28
+ * target. Distinct from session commands, which act on the conversation.
29
+ */
30
+ export declare const SIGNAL_COMMANDS: ReadonlySet<SlashCommandName>;
31
+ /** Look up a descriptor by name. */
32
+ export declare function getDescriptor(name: SlashCommandName): SlashCommandDescriptor | undefined;
33
+ /**
34
+ * The commands offerable against a given configuration.
35
+ *
36
+ * Callers should gate both the palette and dispatch on this: a command that is
37
+ * parseable but unavailable must report "not supported here", never issue a
38
+ * request to an endpoint that was never configured.
39
+ */
40
+ export declare function getAvailableCommands(config: EndpointConfig | null): SlashCommandDescriptor[];
41
+ /** True when the named command can run against this configuration. */
42
+ export declare function isCommandAvailable(name: SlashCommandName, config: EndpointConfig | null): boolean;