@flowdrop/flowdrop 2.9.0 → 2.10.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 (88) hide show
  1. package/CHANGELOG.md +187 -0
  2. package/dist/commands/executor.js +52 -8
  3. package/dist/commands/types.d.ts +3 -0
  4. package/dist/components/App.svelte +8 -0
  5. package/dist/components/App.svelte.d.ts +6 -0
  6. package/dist/components/CanvasContextMenu.stories.svelte +63 -0
  7. package/dist/components/CanvasContextMenu.stories.svelte.d.ts +19 -0
  8. package/dist/components/CanvasContextMenu.svelte +259 -0
  9. package/dist/components/CanvasContextMenu.svelte.d.ts +16 -0
  10. package/dist/components/CanvasController.svelte +23 -1
  11. package/dist/components/CanvasController.svelte.d.ts +16 -0
  12. package/dist/components/UniversalNode.svelte +12 -13
  13. package/dist/components/WorkflowEditor.svelte +364 -27
  14. package/dist/components/WorkflowEditor.svelte.d.ts +7 -0
  15. package/dist/components/WorkflowInterfaceEditor.svelte +28 -3
  16. package/dist/components/WorkflowInterfaceEntryCard.svelte +112 -2
  17. package/dist/components/WorkflowInterfaceEntryCard.svelte.d.ts +3 -1
  18. package/dist/components/nodes/CaptionNode.stories.svelte +65 -0
  19. package/dist/components/nodes/CaptionNode.stories.svelte.d.ts +18 -0
  20. package/dist/components/nodes/CaptionNode.svelte +313 -0
  21. package/dist/components/nodes/CaptionNode.svelte.d.ts +16 -0
  22. package/dist/components/nodes/NotesNode.svelte +6 -0
  23. package/dist/components/playground/ChatBubble.svelte +2 -0
  24. package/dist/components/playground/ChatInput.svelte +18 -34
  25. package/dist/components/playground/ChatInput.svelte.d.ts +7 -0
  26. package/dist/components/playground/ControlPanel.svelte +27 -0
  27. package/dist/components/playground/ControlPanel.svelte.d.ts +12 -0
  28. package/dist/components/playground/ExecutionLogs.svelte +11 -8
  29. package/dist/components/playground/InterfaceInputForm.svelte +74 -0
  30. package/dist/components/playground/InterfaceInputForm.svelte.d.ts +14 -0
  31. package/dist/components/playground/LogRow.svelte +2 -0
  32. package/dist/components/playground/MessageCard.svelte +15 -3
  33. package/dist/components/playground/MessageNotice.svelte +2 -0
  34. package/dist/components/playground/MessageStream.svelte +87 -23
  35. package/dist/components/playground/OriginBadge.svelte +48 -0
  36. package/dist/components/playground/OriginBadge.svelte.d.ts +7 -0
  37. package/dist/components/playground/Playground.svelte +155 -38
  38. package/dist/components/playground/messageDisplay.d.ts +23 -1
  39. package/dist/components/playground/messageDisplay.js +49 -0
  40. package/dist/config/endpoints.d.ts +65 -0
  41. package/dist/config/endpoints.js +39 -0
  42. package/dist/core/index.d.ts +6 -3
  43. package/dist/core/index.js +2 -1
  44. package/dist/editor/contextMenu.d.ts +107 -0
  45. package/dist/editor/contextMenu.js +134 -0
  46. package/dist/editor/index.d.ts +2 -0
  47. package/dist/editor/index.js +1 -0
  48. package/dist/index.d.ts +1 -1
  49. package/dist/index.js +1 -1
  50. package/dist/messages/defaults.d.ts +63 -0
  51. package/dist/messages/defaults.js +59 -0
  52. package/dist/openapi/v1/openapi.yaml +356 -7
  53. package/dist/playground/commands/registry.js +4 -2
  54. package/dist/playground/index.d.ts +3 -2
  55. package/dist/playground/index.js +2 -1
  56. package/dist/registry/builtinNodeTypes.d.ts +1 -1
  57. package/dist/registry/builtinNodeTypes.js +1 -0
  58. package/dist/registry/builtinNodes.js +13 -0
  59. package/dist/registry/nodeComponentRegistry.d.ts +18 -0
  60. package/dist/registry/nodeComponentRegistry.js +14 -2
  61. package/dist/schemas/v1/workflow.schema.json +22 -1
  62. package/dist/services/historyService.d.ts +1 -1
  63. package/dist/services/historyService.js +2 -2
  64. package/dist/services/playgroundService.d.ts +35 -1
  65. package/dist/services/playgroundService.js +82 -36
  66. package/dist/stores/inlineEditStore.svelte.d.ts +35 -0
  67. package/dist/stores/inlineEditStore.svelte.js +63 -0
  68. package/dist/stores/instanceContainer.svelte.d.ts +6 -0
  69. package/dist/stores/instanceContainer.svelte.js +2 -0
  70. package/dist/stores/playgroundStore.svelte.d.ts +59 -2
  71. package/dist/stores/playgroundStore.svelte.js +128 -2
  72. package/dist/styles/base.css +8 -0
  73. package/dist/styles/tokens.css +8 -0
  74. package/dist/svelte-app.d.ts +15 -0
  75. package/dist/svelte-app.js +6 -4
  76. package/dist/types/index.d.ts +34 -1
  77. package/dist/types/index.js +11 -0
  78. package/dist/types/playground.d.ts +90 -9
  79. package/dist/types/playground.js +12 -4
  80. package/dist/utils/captionText.d.ts +43 -0
  81. package/dist/utils/captionText.js +49 -0
  82. package/dist/utils/focus.d.ts +16 -0
  83. package/dist/utils/focus.js +40 -0
  84. package/dist/utils/nodeTypes.js +1 -0
  85. package/dist/utils/nodeWrapper.js +2 -0
  86. package/dist/utils/workflowInterface.d.ts +83 -1
  87. package/dist/utils/workflowInterface.js +192 -1
  88. package/package.json +1 -1
@@ -11,7 +11,6 @@
11
11
  <script lang="ts">
12
12
  import Icon from '@iconify/svelte';
13
13
  import { tick } from 'svelte';
14
- import { hasEnableRunFlag } from '../../types/playground.js';
15
14
  import { getInstance } from '../../stores/getInstance.svelte.js';
16
15
  import { m } from '../../messages/index.js';
17
16
  import {
@@ -52,6 +51,13 @@
52
51
  * button that launches instead.
53
52
  */
54
53
  onRunWorkflow?: () => void;
54
+ /**
55
+ * When true (the default, the original protocol for hosts using ChatInput
56
+ * directly), a Run click locks Run until the backend posts a message with
57
+ * `enableRun` metadata. The Playground turns it off for turn-port
58
+ * workflows, whose server never sends that message.
59
+ */
60
+ awaitEnableRun?: boolean;
55
61
  /**
56
62
  * Enable the slash-command lane (default: false).
57
63
  *
@@ -74,6 +80,7 @@
74
80
  onSendMessage,
75
81
  onStopExecution,
76
82
  onRunWorkflow,
83
+ awaitEnableRun = true,
77
84
  enableCommands = false,
78
85
  commandFeedback = null,
79
86
  onDismissCommandFeedback
@@ -90,13 +97,6 @@
90
97
 
91
98
  const noInputsAvailable = $derived(!showTextarea && !showRunButton);
92
99
 
93
- /**
94
- * Tracks whether the Run button is enabled. Starts as true; becomes false
95
- * after Run is clicked; re-enabled when the backend sends a message with
96
- * enableRun: true metadata.
97
- */
98
- let runEnabled = $state(true);
99
-
100
100
  let inputValue = $state('');
101
101
  let inputField: HTMLTextAreaElement | undefined = $state();
102
102
 
@@ -176,28 +176,8 @@
176
176
  inputValue.trim().length > 0 && (inputIsCommand || fd.playground.canSendMessage)
177
177
  );
178
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`.
183
- let seenEnableRunCount = 0;
184
-
185
- $effect(() => {
186
- const count = fd.playground.messages.filter((msg) => hasEnableRunFlag(msg.metadata)).length;
187
- if (count > seenEnableRunCount) {
188
- seenEnableRunCount = count;
189
- runEnabled = true;
190
- }
191
- });
192
-
193
- $effect(() => {
194
- if (fd.playground.currentSession?.id) {
195
- seenEnableRunCount = 0;
196
- runEnabled = true;
197
- }
198
- });
199
-
200
- // Same rationale as `seenEnableRunCount`: plain `let`, no `untrack` needed.
179
+ // A plain `let`, not `$state`: bookkeeping for the effect below, never read
180
+ // during render, so writing it inside the effect creates no dependency.
201
181
  let wasExecuting = false;
202
182
 
203
183
  /** Auto-focus input when execution completes */
@@ -277,8 +257,8 @@
277
257
  }
278
258
 
279
259
  function handleRun(): void {
280
- if (fd.playground.isExecuting || !runEnabled) return;
281
- runEnabled = false;
260
+ if (!fd.playground.canRun) return;
261
+ if (awaitEnableRun) fd.playground.lockRunUntilEnabled();
282
262
 
283
263
  const action = resolveRunAction({
284
264
  canLaunch: onRunWorkflow != null,
@@ -292,6 +272,10 @@
292
272
  }
293
273
 
294
274
  onSendMessage?.(action.content);
275
+
276
+ // A slash command (a `predefinedMessage` of `/help`, say) runs without
277
+ // taking a turn, so no `enableRun` message will ever follow to free the lock.
278
+ if (awaitEnableRun && isCommandInput(action.content)) fd.playground.releaseRunLock();
295
279
  }
296
280
 
297
281
  function handleInput(): void {
@@ -414,12 +398,12 @@
414
398
  {actions.send}
415
399
  </button>
416
400
  {:else if showRunButton}
417
- {@const runLabel = runEnabled ? actions.runTitle : actions.runWaitingTitle}
401
+ {@const runLabel = fd.playground.canRun ? actions.runTitle : actions.runWaitingTitle}
418
402
  <button
419
403
  type="button"
420
404
  class="chat-input__run-btn"
421
405
  onclick={handleRun}
422
- disabled={!runEnabled}
406
+ disabled={!fd.playground.canRun}
423
407
  title={runLabel}
424
408
  aria-label={runLabel}
425
409
  >
@@ -26,6 +26,13 @@ interface Props {
26
26
  * button that launches instead.
27
27
  */
28
28
  onRunWorkflow?: () => void;
29
+ /**
30
+ * When true (the default, the original protocol for hosts using ChatInput
31
+ * directly), a Run click locks Run until the backend posts a message with
32
+ * `enableRun` metadata. The Playground turns it off for turn-port
33
+ * workflows, whose server never sends that message.
34
+ */
35
+ awaitEnableRun?: boolean;
29
36
  /**
30
37
  * Enable the slash-command lane (default: false).
31
38
  *
@@ -10,6 +10,8 @@
10
10
  <script lang="ts">
11
11
  import Icon from '@iconify/svelte';
12
12
  import ChatInput from './ChatInput.svelte';
13
+ import InterfaceInputForm from './InterfaceInputForm.svelte';
14
+ import type { WorkflowInterfaceEntry } from '../../types/index.js';
13
15
  import { getInstance } from '../../stores/getInstance.svelte.js';
14
16
  import { m } from '../../messages/index.js';
15
17
  import type { CommandOutcome } from '../../playground/commands/index.js';
@@ -27,6 +29,8 @@
27
29
  onStopExecution: () => void;
28
30
  /** Start a run without posting a chat message. See ChatInput. */
29
31
  onRunWorkflow?: () => void;
32
+ /** Whether a Run click waits for the backend's `enableRun`. See ChatInput. */
33
+ awaitEnableRun?: boolean;
30
34
  /**
31
35
  * Enable the slash-command lane (default: false).
32
36
  *
@@ -48,6 +52,15 @@
48
52
  showRunButton?: boolean;
49
53
  predefinedMessage?: string;
50
54
  placeholder?: string;
55
+ /**
56
+ * Interface inputs to collect in a form above the composer (inputs
57
+ * without a chat turn). Empty or absent renders no form.
58
+ */
59
+ formEntries?: WorkflowInterfaceEntry[];
60
+ /** Current form values, keyed by entry id. */
61
+ formValues?: Record<string, unknown>;
62
+ /** Called with the complete form values on every change. */
63
+ onFormChange?: (values: Record<string, unknown>) => void;
51
64
  // Session UI config
52
65
  showSessionHeader?: boolean;
53
66
  showNewSessionButton?: boolean;
@@ -63,6 +76,7 @@
63
76
  onSendMessage,
64
77
  onStopExecution,
65
78
  onRunWorkflow,
79
+ awaitEnableRun = true,
66
80
  enableCommands = false,
67
81
  commandFeedback = null,
68
82
  onDismissCommandFeedback,
@@ -74,6 +88,9 @@
74
88
  showRunButton = true,
75
89
  predefinedMessage,
76
90
  placeholder,
91
+ formEntries = [],
92
+ formValues = {},
93
+ onFormChange,
77
94
  showSessionHeader = true,
78
95
  showNewSessionButton = true,
79
96
  showSessionList = true,
@@ -267,6 +284,15 @@
267
284
  </header>
268
285
  {/if}
269
286
 
287
+ {#if formEntries.length > 0}
288
+ <InterfaceInputForm
289
+ entries={formEntries}
290
+ values={formValues}
291
+ onChange={(values) => onFormChange?.(values)}
292
+ disabled={fd.playground.isExecuting}
293
+ />
294
+ {/if}
295
+
270
296
  <ChatInput
271
297
  showTextarea={showChatInput}
272
298
  {showRunButton}
@@ -275,6 +301,7 @@
275
301
  {onSendMessage}
276
302
  {onStopExecution}
277
303
  {onRunWorkflow}
304
+ {awaitEnableRun}
278
305
  {enableCommands}
279
306
  {commandFeedback}
280
307
  {onDismissCommandFeedback}
@@ -1,3 +1,4 @@
1
+ import type { WorkflowInterfaceEntry } from '../../types/index.js';
1
2
  import type { CommandOutcome } from '../../playground/commands/index.js';
2
3
  interface Props {
3
4
  onCreateSession: () => void;
@@ -8,6 +9,8 @@ interface Props {
8
9
  onStopExecution: () => void;
9
10
  /** Start a run without posting a chat message. See ChatInput. */
10
11
  onRunWorkflow?: () => void;
12
+ /** Whether a Run click waits for the backend's `enableRun`. See ChatInput. */
13
+ awaitEnableRun?: boolean;
11
14
  /**
12
15
  * Enable the slash-command lane (default: false).
13
16
  *
@@ -26,6 +29,15 @@ interface Props {
26
29
  showRunButton?: boolean;
27
30
  predefinedMessage?: string;
28
31
  placeholder?: string;
32
+ /**
33
+ * Interface inputs to collect in a form above the composer (inputs
34
+ * without a chat turn). Empty or absent renders no form.
35
+ */
36
+ formEntries?: WorkflowInterfaceEntry[];
37
+ /** Current form values, keyed by entry id. */
38
+ formValues?: Record<string, unknown>;
39
+ /** Called with the complete form values on every change. */
40
+ onFormChange?: (values: Record<string, unknown>) => void;
29
41
  showSessionHeader?: boolean;
30
42
  showNewSessionButton?: boolean;
31
43
  showSessionList?: boolean;
@@ -9,7 +9,7 @@
9
9
  <script lang="ts">
10
10
  import Icon from '@iconify/svelte';
11
11
  import { slide } from 'svelte/transition';
12
- import type { PlaygroundMessageLevel } from '../../types/playground.js';
12
+ import { isHiddenMessage, type PlaygroundMessageLevel } from '../../types/playground.js';
13
13
  import { getInstance } from '../../stores/getInstance.svelte.js';
14
14
 
15
15
  const fd = getInstance();
@@ -34,24 +34,27 @@
34
34
  /** Reference to logs container for auto-scroll */
35
35
  let logsContainer = $state<HTMLDivElement>();
36
36
 
37
+ /** Log rows to render: `display: 'hidden'` rows are noise, not shown. */
38
+ const visibleLogs = $derived(fd.playground.logMessages.filter((log) => !isHiddenMessage(log)));
39
+
37
40
  /**
38
41
  * Filter logs based on selected level
39
42
  */
40
43
  const filteredLogs = $derived(
41
44
  levelFilter === 'all'
42
- ? fd.playground.logMessages
43
- : fd.playground.logMessages.filter((log) => log.metadata?.level === levelFilter)
45
+ ? visibleLogs
46
+ : visibleLogs.filter((log) => log.metadata?.level === levelFilter)
44
47
  );
45
48
 
46
49
  /**
47
50
  * Count of logs by level
48
51
  */
49
52
  const logCounts = $derived({
50
- all: fd.playground.logMessages.length,
51
- info: fd.playground.logMessages.filter((l) => l.metadata?.level === 'info').length,
52
- warning: fd.playground.logMessages.filter((l) => l.metadata?.level === 'warning').length,
53
- error: fd.playground.logMessages.filter((l) => l.metadata?.level === 'error').length,
54
- debug: fd.playground.logMessages.filter((l) => l.metadata?.level === 'debug').length
53
+ all: visibleLogs.length,
54
+ info: visibleLogs.filter((l) => l.metadata?.level === 'info').length,
55
+ warning: visibleLogs.filter((l) => l.metadata?.level === 'warning').length,
56
+ error: visibleLogs.filter((l) => l.metadata?.level === 'error').length,
57
+ debug: visibleLogs.filter((l) => l.metadata?.level === 'debug').length
55
58
  });
56
59
 
57
60
  /**
@@ -0,0 +1,74 @@
1
+ <!--
2
+ InterfaceInputForm Component
3
+
4
+ The form a workflow's interface inputs render as in the Playground: one
5
+ field per input entry without a chat turn (the session fills turn ports, so
6
+ they never appear here). Values are keyed by entry id, the name the server
7
+ matches `inputs` on. Rendering is SchemaForm's; this component only builds
8
+ the schema and frames it.
9
+ -->
10
+
11
+ <script lang="ts">
12
+ import Icon from '@iconify/svelte';
13
+ import SchemaForm from '../SchemaForm.svelte';
14
+ import type { WorkflowInterfaceEntry } from '../../types/index.js';
15
+ import { interfaceFormSchema } from '../../utils/workflowInterface.js';
16
+ import { m } from '../../messages/index.js';
17
+
18
+ interface Props {
19
+ /** The interface input entries to render (inputs without a `turn`). */
20
+ entries: WorkflowInterfaceEntry[];
21
+ /** Current values, keyed by entry id. */
22
+ values: Record<string, unknown>;
23
+ /** Called with the complete values on every change. */
24
+ onChange: (values: Record<string, unknown>) => void;
25
+ /** Disable every field (e.g. while a turn runs). */
26
+ disabled?: boolean;
27
+ }
28
+
29
+ let { entries, values, onChange, disabled = false }: Props = $props();
30
+
31
+ const schema = $derived(interfaceFormSchema(entries));
32
+ const labels = $derived(m().playground.inputForm);
33
+ </script>
34
+
35
+ <section class="interface-input-form" aria-label={labels.title}>
36
+ <header class="interface-input-form__header">
37
+ <Icon icon="mdi:form-textbox" />
38
+ <span>{labels.title}</span>
39
+ </header>
40
+ <div class="interface-input-form__body">
41
+ <SchemaForm {schema} {values} {onChange} {disabled} />
42
+ </div>
43
+ </section>
44
+
45
+ <style>
46
+ /* Grows into the control panel's free height and scrolls there, so the
47
+ composer below it keeps its place however many inputs there are. */
48
+ .interface-input-form {
49
+ flex: 1 1 auto;
50
+ min-height: 0;
51
+ overflow-y: auto;
52
+ width: 100%;
53
+ padding: var(--fd-space-md) var(--fd-space-3xl) 0;
54
+ box-sizing: border-box;
55
+ }
56
+
57
+ .interface-input-form__header,
58
+ .interface-input-form__body {
59
+ max-width: 760px;
60
+ margin-left: auto;
61
+ margin-right: auto;
62
+ }
63
+
64
+ .interface-input-form__header {
65
+ display: flex;
66
+ align-items: center;
67
+ gap: var(--fd-space-xs);
68
+ font-size: var(--fd-text-sm);
69
+ font-weight: 600;
70
+ color: var(--fd-muted-foreground);
71
+ margin-bottom: var(--fd-space-sm);
72
+ margin-top: 0;
73
+ }
74
+ </style>
@@ -0,0 +1,14 @@
1
+ import type { WorkflowInterfaceEntry } from '../../types/index.js';
2
+ interface Props {
3
+ /** The interface input entries to render (inputs without a `turn`). */
4
+ entries: WorkflowInterfaceEntry[];
5
+ /** Current values, keyed by entry id. */
6
+ values: Record<string, unknown>;
7
+ /** Called with the complete values on every change. */
8
+ onChange: (values: Record<string, unknown>) => void;
9
+ /** Disable every field (e.g. while a turn runs). */
10
+ disabled?: boolean;
11
+ }
12
+ declare const InterfaceInputForm: import("svelte").Component<Props, {}, "">;
13
+ type InterfaceInputForm = ReturnType<typeof InterfaceInputForm>;
14
+ export default InterfaceInputForm;
@@ -9,6 +9,7 @@
9
9
  import type { PlaygroundMessage } from '../../types/playground.js';
10
10
  import HierarchyTrail from './HierarchyTrail.svelte';
11
11
  import MessageTagStrip from './MessageTagStrip.svelte';
12
+ import OriginBadge from './OriginBadge.svelte';
12
13
  import { formatTimestamp, getLogLevelIcon } from './messageDisplay.js';
13
14
 
14
15
  interface Props {
@@ -39,6 +40,7 @@
39
40
  {#if message.metadata?.source}
40
41
  <span class="log-row__source">{message.metadata.source}</span>
41
42
  {/if}
43
+ <OriginBadge {message} />
42
44
  <HierarchyTrail items={hierarchy} />
43
45
  {#if message.metadata?.nodeLabel ?? message.nodeId}
44
46
  <span class="log-row__node">{message.metadata?.nodeLabel ?? message.nodeId}</span>
@@ -7,8 +7,9 @@
7
7
  import type { PlaygroundMessage } from '../../types/playground.js';
8
8
  import HierarchyTrail from './HierarchyTrail.svelte';
9
9
  import MessageTagStrip from './MessageTagStrip.svelte';
10
+ import OriginBadge from './OriginBadge.svelte';
10
11
  import MessageMarkdown from './MessageMarkdown.svelte';
11
- import { formatTimestamp, getRoleLabel } from './messageDisplay.js';
12
+ import { formatTimestamp, getOriginBadge, getRoleLabel } from './messageDisplay.js';
12
13
  import { m } from '../../messages/index.js';
13
14
 
14
15
  interface Props {
@@ -24,6 +25,7 @@
24
25
  const hierarchy = $derived(message.hierarchy ?? []);
25
26
  const tags = $derived(message.tags ?? []);
26
27
  const roleLabel = $derived(getRoleLabel(message, m().playground.roles));
28
+ const hasOriginBadge = $derived(getOriginBadge(message) !== null);
27
29
  // Logs render as plain text; everything else respects enableMarkdown.
28
30
  const markdown = $derived(enableMarkdown && message.role !== 'log');
29
31
  </script>
@@ -35,9 +37,12 @@
35
37
  class:message-card--warning={level === 'warning'}
36
38
  aria-label={roleLabel}
37
39
  >
38
- {#if hierarchy.length > 0 || showTimestamp}
40
+ {#if hierarchy.length > 0 || showTimestamp || hasOriginBadge}
39
41
  <header class="message-card__header">
40
- <HierarchyTrail items={hierarchy} />
42
+ <span class="message-card__lead">
43
+ <OriginBadge {message} />
44
+ <HierarchyTrail items={hierarchy} />
45
+ </span>
41
46
  {#if showTimestamp}
42
47
  <time
43
48
  class="message-card__timestamp"
@@ -91,6 +96,13 @@
91
96
  min-width: 0;
92
97
  }
93
98
 
99
+ .message-card__lead {
100
+ display: flex;
101
+ align-items: center;
102
+ gap: var(--fd-space-xs);
103
+ min-width: 0;
104
+ }
105
+
94
106
  .message-card__timestamp {
95
107
  flex-shrink: 0;
96
108
  font-size: 0.625rem;
@@ -8,6 +8,7 @@
8
8
  import type { PlaygroundMessage } from '../../types/playground.js';
9
9
  import HierarchyTrail from './HierarchyTrail.svelte';
10
10
  import MessageTagStrip from './MessageTagStrip.svelte';
11
+ import OriginBadge from './OriginBadge.svelte';
11
12
  import { formatTimestamp, getLogLevelIcon } from './messageDisplay.js';
12
13
 
13
14
  interface Props {
@@ -34,6 +35,7 @@
34
35
  {#if message.metadata?.source}
35
36
  <span class="system-notice__source">{message.metadata.source}</span>
36
37
  {/if}
38
+ <OriginBadge {message} />
37
39
  <HierarchyTrail items={hierarchy} />
38
40
  <span class="system-notice__text">{message.content}</span>
39
41
  <MessageTagStrip {tags} />
@@ -13,7 +13,12 @@
13
13
  import { tick, untrack, type Snippet } from 'svelte';
14
14
  import MessageBubble from './MessageBubble.svelte';
15
15
  import { InterruptBubble } from '../interrupt/index.js';
16
- import type { PlaygroundMessage } from '../../types/playground.js';
16
+ import {
17
+ isHiddenMessage,
18
+ resolveMessageDisplay,
19
+ type PlaygroundMessage
20
+ } from '../../types/playground.js';
21
+ import { groupAdjacent } from './messageDisplay.js';
17
22
  import {
18
23
  isInterruptMetadata,
19
24
  extractInterruptMetadata,
@@ -74,6 +79,25 @@
74
79
  allowLogs && fd.playground.showLogs ? fd.playground.messages : fd.playground.chatMessages
75
80
  );
76
81
 
82
+ /**
83
+ * What is actually rendered: `display: 'hidden'` rows are dropped. They stay
84
+ * in the store (cursors, interrupt sync) — hiding is about noise, never
85
+ * about secrecy, since the row has already reached the browser.
86
+ */
87
+ const visibleMessages = $derived(displayMessages.filter((msg) => !isHiddenMessage(msg)));
88
+
89
+ /** Runs of three or more adjacent log-layout rows fold into a collapsible group. */
90
+ const rows = $derived(
91
+ groupAdjacent(
92
+ visibleMessages,
93
+ (msg) =>
94
+ !isInterruptMessage(msg) && resolveMessageDisplay(msg, { compactSystemMessages }) === 'log',
95
+ (msg) => msg.id
96
+ )
97
+ );
98
+
99
+ const lastVisibleId = $derived(visibleMessages.at(-1)?.id);
100
+
77
101
  let previousMessageCount = 0;
78
102
  let userScrolledUp = false;
79
103
  let isLoadingOlder = $state(false);
@@ -181,9 +205,9 @@
181
205
  return interruptsByMessageId.get(message.id);
182
206
  }
183
207
 
184
- const showWelcome = $derived(!fd.playground.currentSession && displayMessages.length === 0);
208
+ const showWelcome = $derived(!fd.playground.currentSession && visibleMessages.length === 0);
185
209
  const showEmptyChat = $derived(
186
- fd.playground.currentSession !== null && displayMessages.length === 0
210
+ fd.playground.currentSession !== null && visibleMessages.length === 0
187
211
  );
188
212
 
189
213
  // Reset scroll-tracking when session changes
@@ -194,7 +218,7 @@
194
218
  });
195
219
 
196
220
  $effect(() => {
197
- const currentCount = displayMessages.length;
221
+ const currentCount = visibleMessages.length;
198
222
 
199
223
  if (!autoScroll || !messagesContainer) {
200
224
  untrack(() => {
@@ -220,6 +244,29 @@
220
244
  });
221
245
  </script>
222
246
 
247
+ {#snippet messageRow(message: PlaygroundMessage)}
248
+ {#if isInterruptMessage(message)}
249
+ {@const interrupt = getInterruptForMessage(message)}
250
+ {#if interrupt}
251
+ <InterruptBubble
252
+ {interrupt}
253
+ showTimestamp={showTimestamps}
254
+ onResolved={onInterruptResolved}
255
+ hierarchy={message.hierarchy}
256
+ tags={message.tags}
257
+ />
258
+ {/if}
259
+ {:else}
260
+ <MessageBubble
261
+ {message}
262
+ showTimestamp={showTimestamps}
263
+ isLast={message.id === lastVisibleId}
264
+ {enableMarkdown}
265
+ {compactSystemMessages}
266
+ />
267
+ {/if}
268
+ {/snippet}
269
+
223
270
  <div
224
271
  class="message-stream"
225
272
  role="log"
@@ -242,26 +289,18 @@
242
289
  <span class="message-stream__loading-older-spinner"></span>
243
290
  </div>
244
291
  {/if}
245
- {#each displayMessages as message, index (message.id)}
246
- {#if isInterruptMessage(message)}
247
- {@const interrupt = getInterruptForMessage(message)}
248
- {#if interrupt}
249
- <InterruptBubble
250
- {interrupt}
251
- showTimestamp={showTimestamps}
252
- onResolved={onInterruptResolved}
253
- hierarchy={message.hierarchy}
254
- tags={message.tags}
255
- />
256
- {/if}
292
+ {#each rows as row (row.kind === 'group' ? `group:${row.key}` : row.item.id)}
293
+ {#if row.kind === 'group'}
294
+ <details class="message-stream__log-group" open>
295
+ <summary class="message-stream__log-group-summary">
296
+ {m().playground.logGroup.summary({ count: row.items.length })}
297
+ </summary>
298
+ {#each row.items as message (message.id)}
299
+ {@render messageRow(message)}
300
+ {/each}
301
+ </details>
257
302
  {:else}
258
- <MessageBubble
259
- {message}
260
- showTimestamp={showTimestamps}
261
- isLast={index === displayMessages.length - 1}
262
- {enableMarkdown}
263
- {compactSystemMessages}
264
- />
303
+ {@render messageRow(row.item)}
265
304
  {/if}
266
305
  {/each}
267
306
 
@@ -386,6 +425,31 @@
386
425
  }
387
426
  }
388
427
 
428
+ /* A run of adjacent log rows, collapsible. Muted, no chrome beyond a
429
+ hairline so it reads as one quiet block rather than a card. */
430
+ .message-stream__log-group {
431
+ margin: var(--fd-space-3xs) 0;
432
+ }
433
+
434
+ .message-stream__log-group-summary {
435
+ cursor: pointer;
436
+ padding: var(--fd-space-3xs) var(--fd-space-xl);
437
+ font-family: var(--fd-font-mono);
438
+ font-size: var(--fd-text-xs);
439
+ color: var(--fd-muted-foreground);
440
+ opacity: 0.8;
441
+ user-select: none;
442
+ }
443
+
444
+ .message-stream__log-group-summary:hover {
445
+ opacity: 1;
446
+ }
447
+
448
+ .message-stream__log-group-summary:focus-visible {
449
+ outline: 2px solid var(--fd-ring);
450
+ outline-offset: -2px;
451
+ }
452
+
389
453
  /* Overlay, out of flow — its presence must not shift message layout, or it
390
454
  would corrupt the scroll anchoring in loadOlder(). */
391
455
  .message-stream__loading-older {
@@ -0,0 +1,48 @@
1
+ <!--
2
+ OriginBadge — small, subtle chip naming which component posted a message
3
+ (engine, playground, interrupt). Renders nothing for user/workflow rows or
4
+ rows from servers that do not send `origin`. Colours come from currentColor
5
+ so the chip reads on any bubble background (user bubbles are primary-bg).
6
+ -->
7
+
8
+ <script lang="ts">
9
+ import type { PlaygroundMessage } from '../../types/playground.js';
10
+ import { getOriginBadge } from './messageDisplay.js';
11
+ import { m } from '../../messages/index.js';
12
+
13
+ interface Props {
14
+ message: Pick<PlaygroundMessage, 'origin'>;
15
+ }
16
+
17
+ let { message }: Props = $props();
18
+
19
+ const origin = $derived(getOriginBadge(message));
20
+ const labels = $derived(m().playground.origins);
21
+ </script>
22
+
23
+ {#if origin}
24
+ <span
25
+ class="origin-badge origin-badge--{origin}"
26
+ title={labels.postedBy({ origin: labels[origin] })}
27
+ data-origin={origin}>{labels[origin]}</span
28
+ >
29
+ {/if}
30
+
31
+ <style>
32
+ .origin-badge {
33
+ flex-shrink: 0;
34
+ display: inline-flex;
35
+ align-items: center;
36
+ padding: 0 0.3125rem;
37
+ border: 1px solid currentColor;
38
+ border-radius: var(--fd-radius-sm);
39
+ font-size: 0.625rem;
40
+ font-weight: 500;
41
+ line-height: 1.4;
42
+ letter-spacing: 0.04em;
43
+ text-transform: uppercase;
44
+ opacity: 0.6;
45
+ color: inherit;
46
+ background-color: transparent;
47
+ }
48
+ </style>
@@ -0,0 +1,7 @@
1
+ import type { PlaygroundMessage } from '../../types/playground.js';
2
+ interface Props {
3
+ message: Pick<PlaygroundMessage, 'origin'>;
4
+ }
5
+ declare const OriginBadge: import("svelte").Component<Props, {}, "">;
6
+ type OriginBadge = ReturnType<typeof OriginBadge>;
7
+ export default OriginBadge;