@workflow/web-shared 5.1.0 → 5.1.1

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 (174) hide show
  1. package/README.md +8 -0
  2. package/dist/components/error-boundary.js +1 -1
  3. package/dist/components/event-list/event-details-panel.d.ts +25 -0
  4. package/dist/components/event-list/event-details-panel.d.ts.map +1 -0
  5. package/dist/components/event-list/event-details-panel.js +156 -0
  6. package/dist/components/event-list/event-list-toolbar.d.ts +6 -0
  7. package/dist/components/event-list/event-list-toolbar.d.ts.map +1 -0
  8. package/dist/components/event-list/event-list-toolbar.js +15 -0
  9. package/dist/components/event-list/event-row.d.ts +29 -0
  10. package/dist/components/event-list/event-row.d.ts.map +1 -0
  11. package/dist/components/event-list/event-row.js +102 -0
  12. package/dist/components/event-list/use-event-search.d.ts +14 -0
  13. package/dist/components/event-list/use-event-search.d.ts.map +1 -0
  14. package/dist/components/event-list/use-event-search.js +74 -0
  15. package/dist/components/event-list-view.d.ts +9 -66
  16. package/dist/components/event-list-view.d.ts.map +1 -1
  17. package/dist/components/event-list-view.js +112 -984
  18. package/dist/components/hook-actions.js +1 -1
  19. package/dist/components/index.js +1 -1
  20. package/dist/components/sidebar/attribute-panel.js +1 -1
  21. package/dist/components/sidebar/attributes-block.js +1 -1
  22. package/dist/components/sidebar/conversation-view.js +1 -1
  23. package/dist/components/sidebar/copyable-data-block.js +1 -1
  24. package/dist/components/sidebar/entity-detail-panel.js +1 -1
  25. package/dist/components/sidebar/events-list.js +1 -1
  26. package/dist/components/sidebar/resolve-hook-modal.js +1 -1
  27. package/dist/components/sidebar/sidebar-data-context.js +1 -1
  28. package/dist/components/sidebar/span-detail-merge.js +1 -1
  29. package/dist/components/sidebar/use-selected-span-detail.js +1 -1
  30. package/dist/components/stream-image-preview.d.ts +4 -0
  31. package/dist/components/stream-image-preview.d.ts.map +1 -0
  32. package/dist/components/stream-image-preview.js +21 -0
  33. package/dist/components/stream-viewer-skeleton.js +1 -1
  34. package/dist/components/stream-viewer.d.ts.map +1 -1
  35. package/dist/components/stream-viewer.js +7 -2
  36. package/dist/components/trace-viewer/components/copy-button.js +1 -1
  37. package/dist/components/trace-viewer/components/detail-panel-shell.d.ts +22 -0
  38. package/dist/components/trace-viewer/components/detail-panel-shell.d.ts.map +1 -0
  39. package/dist/components/trace-viewer/components/detail-panel-shell.js +49 -0
  40. package/dist/components/trace-viewer/components/detail-panel-width.js +1 -1
  41. package/dist/components/trace-viewer/components/detail-panel.d.ts +4 -4
  42. package/dist/components/trace-viewer/components/detail-panel.d.ts.map +1 -1
  43. package/dist/components/trace-viewer/components/detail-panel.js +11 -51
  44. package/dist/components/trace-viewer/components/draggable-border.js +1 -1
  45. package/dist/components/trace-viewer/components/event-list.d.ts +9 -0
  46. package/dist/components/trace-viewer/components/event-list.d.ts.map +1 -1
  47. package/dist/components/trace-viewer/components/event-list.js +10 -3
  48. package/dist/components/trace-viewer/components/middle-truncate/copy-selection.js +1 -1
  49. package/dist/components/trace-viewer/components/middle-truncate/measurement-batch.js +1 -1
  50. package/dist/components/trace-viewer/components/middle-truncate/middle-truncate.js +1 -1
  51. package/dist/components/trace-viewer/components/middle-truncate/truncate.js +1 -1
  52. package/dist/components/trace-viewer/components/middle-truncate/use-middle-truncate.js +1 -1
  53. package/dist/components/trace-viewer/components/minimap.js +1 -1
  54. package/dist/components/trace-viewer/components/pane-constants.js +1 -1
  55. package/dist/components/trace-viewer/components/span-markers.js +1 -1
  56. package/dist/components/trace-viewer/components/split-pane.js +1 -1
  57. package/dist/components/trace-viewer/components/timeline.js +1 -1
  58. package/dist/components/trace-viewer/components/trace-shortcut-helper.js +1 -1
  59. package/dist/components/trace-viewer/components/trace-viewer-skeleton.js +1 -1
  60. package/dist/components/trace-viewer/components/use-alt-held.d.ts +1 -0
  61. package/dist/components/trace-viewer/components/use-alt-held.d.ts.map +1 -1
  62. package/dist/components/trace-viewer/components/use-alt-held.js +2 -2
  63. package/dist/components/trace-viewer/components/use-detail-panel-width.d.ts +19 -0
  64. package/dist/components/trace-viewer/components/use-detail-panel-width.d.ts.map +1 -0
  65. package/dist/components/trace-viewer/components/use-detail-panel-width.js +26 -0
  66. package/dist/components/trace-viewer/components/use-element-width.js +1 -1
  67. package/dist/components/trace-viewer/components/use-row-window.js +1 -1
  68. package/dist/components/trace-viewer/context.d.ts +2 -1
  69. package/dist/components/trace-viewer/context.d.ts.map +1 -1
  70. package/dist/components/trace-viewer/context.js +3 -3
  71. package/dist/components/trace-viewer/icons.js +1 -1
  72. package/dist/components/trace-viewer/search.js +1 -1
  73. package/dist/components/trace-viewer/trace-viewer.d.ts +2 -1
  74. package/dist/components/trace-viewer/trace-viewer.d.ts.map +1 -1
  75. package/dist/components/trace-viewer/trace-viewer.js +3 -12
  76. package/dist/components/trace-viewer/types.js +1 -1
  77. package/dist/components/trace-viewer/util/timing.js +1 -1
  78. package/dist/components/trace-viewer/utils.js +1 -1
  79. package/dist/components/trace-viewer.d.ts +2 -1
  80. package/dist/components/trace-viewer.d.ts.map +1 -1
  81. package/dist/components/trace-viewer.js +3 -3
  82. package/dist/components/ui/alert.js +1 -1
  83. package/dist/components/ui/button.js +1 -1
  84. package/dist/components/ui/card.js +1 -1
  85. package/dist/components/ui/collapsible.d.ts +3 -1
  86. package/dist/components/ui/collapsible.d.ts.map +1 -1
  87. package/dist/components/ui/collapsible.js +3 -3
  88. package/dist/components/ui/context-card.js +1 -1
  89. package/dist/components/ui/data-inspector.js +1 -1
  90. package/dist/components/ui/data-inspector.styles.js +1 -1
  91. package/dist/components/ui/decrypt-button.js +2 -2
  92. package/dist/components/ui/duplicate-event-tooltip.js +1 -1
  93. package/dist/components/ui/error-card.js +2 -2
  94. package/dist/components/ui/error-stack-block.js +1 -1
  95. package/dist/components/ui/icon-button.d.ts +2 -2
  96. package/dist/components/ui/icon-button.js +1 -1
  97. package/dist/components/ui/kbd.d.ts +1 -1
  98. package/dist/components/ui/kbd.js +1 -1
  99. package/dist/components/ui/load-more-button.js +1 -1
  100. package/dist/components/ui/menu-dropdown.js +1 -1
  101. package/dist/components/ui/skeleton.js +1 -1
  102. package/dist/components/ui/spinner.js +1 -1
  103. package/dist/components/ui/timestamp-tooltip.js +1 -1
  104. package/dist/components/ui/tooltip.js +1 -1
  105. package/dist/components/workflow-traces/event-colors.js +1 -1
  106. package/dist/components/workflow-traces/trace-span-construction.js +1 -1
  107. package/dist/components/workflow-traces/trace-time-utils.js +1 -1
  108. package/dist/hooks/use-dark-mode.js +1 -1
  109. package/dist/hooks/use-intersection-observer.js +1 -1
  110. package/dist/hooks/use-load-more-on-scroll.js +1 -1
  111. package/dist/hooks/use-reduced-motion.js +1 -1
  112. package/dist/index.d.ts +1 -0
  113. package/dist/index.d.ts.map +1 -1
  114. package/dist/index.js +2 -1
  115. package/dist/lib/cn.js +1 -1
  116. package/dist/lib/duplicate-events.js +1 -1
  117. package/dist/lib/event-analysis.js +1 -1
  118. package/dist/lib/event-list-model.d.ts +179 -0
  119. package/dist/lib/event-list-model.d.ts.map +1 -0
  120. package/dist/lib/event-list-model.js +459 -0
  121. package/dist/lib/event-materialization.js +1 -1
  122. package/dist/lib/exact-event-search-id.js +1 -1
  123. package/dist/lib/hydration.js +1 -1
  124. package/dist/lib/run-limit-guidance.js +1 -1
  125. package/dist/lib/sealed-events.js +1 -1
  126. package/dist/lib/start-hook.js +1 -1
  127. package/dist/lib/state-hydration.js +1 -1
  128. package/dist/lib/stream-display.js +1 -1
  129. package/dist/lib/stream-image.d.ts +3 -0
  130. package/dist/lib/stream-image.d.ts.map +1 -0
  131. package/dist/lib/stream-image.js +23 -0
  132. package/dist/lib/toast.js +1 -1
  133. package/dist/lib/trace-builder.d.ts +1 -0
  134. package/dist/lib/trace-builder.d.ts.map +1 -1
  135. package/dist/lib/trace-builder.js +5 -1
  136. package/dist/lib/trace-types.js +1 -1
  137. package/dist/lib/utils.js +1 -1
  138. package/dist/lib/zstd-browser-decoder.js +1 -1
  139. package/package.json +7 -5
  140. package/src/components/event-list/event-details-panel.tsx +407 -0
  141. package/src/components/event-list/event-list-toolbar.tsx +47 -0
  142. package/src/components/event-list/event-row.tsx +348 -0
  143. package/src/components/event-list/use-event-search.ts +104 -0
  144. package/src/components/event-list-view.tsx +258 -1848
  145. package/src/components/stream-image-preview.tsx +54 -0
  146. package/src/components/stream-viewer.tsx +16 -6
  147. package/src/components/trace-viewer/components/detail-panel-shell.tsx +143 -0
  148. package/src/components/trace-viewer/components/detail-panel.tsx +37 -176
  149. package/src/components/trace-viewer/components/event-list.tsx +35 -14
  150. package/src/components/trace-viewer/components/use-alt-held.ts +1 -1
  151. package/src/components/trace-viewer/components/use-detail-panel-width.ts +53 -0
  152. package/src/components/trace-viewer/context.tsx +5 -1
  153. package/src/components/trace-viewer/trace-viewer.tsx +6 -11
  154. package/src/components/trace-viewer.tsx +3 -0
  155. package/src/components/ui/collapsible.tsx +11 -0
  156. package/src/components/ui/decrypt-button.tsx +1 -1
  157. package/src/components/ui/error-card.tsx +1 -1
  158. package/src/index.ts +1 -0
  159. package/src/lib/event-list-model.ts +684 -0
  160. package/src/lib/stream-image.ts +21 -0
  161. package/src/lib/trace-builder.ts +5 -0
  162. package/src/components/event-list-view.test.ts +0 -51
  163. package/src/components/trace-viewer/components/detail-panel-width.test.ts +0 -123
  164. package/src/components/trace-viewer/utils.test.ts +0 -492
  165. package/src/components/workflow-traces/event-colors.test.ts +0 -14
  166. package/src/components/workflow-traces/trace-span-construction.test.ts +0 -202
  167. package/src/lib/duplicate-events.test.ts +0 -336
  168. package/src/lib/event-materialization.test.ts +0 -136
  169. package/src/lib/hydration.test.ts +0 -63
  170. package/src/lib/run-limit-guidance.test.ts +0 -90
  171. package/src/lib/start-hook.test.ts +0 -174
  172. package/src/lib/state-hydration.test.ts +0 -332
  173. package/src/lib/trace-builder.test.ts +0 -143
  174. package/src/lib/utils.test.ts +0 -33
@@ -0,0 +1,54 @@
1
+ 'use client';
2
+
3
+ import { useEffect, useState } from 'react';
4
+ import { getStreamImageType } from '../lib/stream-image';
5
+ import { Button } from './ui/button';
6
+
7
+ export function StreamImagePreview({ data }: { data: Uint8Array }) {
8
+ const [source, setSource] = useState<{
9
+ data: Uint8Array;
10
+ url: string;
11
+ } | null>(null);
12
+ const [failed, setFailed] = useState(false);
13
+ const type = getStreamImageType(data);
14
+
15
+ useEffect(() => {
16
+ if (!type) return;
17
+ const url = URL.createObjectURL(new Blob([new Uint8Array(data)], { type }));
18
+ setSource({ data, url });
19
+ setFailed(false);
20
+ return () => URL.revokeObjectURL(url);
21
+ }, [data, type]);
22
+
23
+ const url = source?.data === data ? source.url : null;
24
+ return (
25
+ <div className="min-w-0 w-full">
26
+ <div className="mb-2 flex items-center justify-between gap-2">
27
+ <span className="text-label-12 text-gray-900">Image Preview</span>
28
+ {url ? (
29
+ <Button asChild size="tiny" variant="secondary">
30
+ <a href={url} download={`workflow-stream.${type?.split('/')[1]}`}>
31
+ Download Image
32
+ </a>
33
+ </Button>
34
+ ) : null}
35
+ </div>
36
+ <div className="relative aspect-video w-full">
37
+ {failed ? (
38
+ <output className="text-copy-14 text-gray-900">
39
+ This image can’t be previewed. Download it to view its contents.
40
+ </output>
41
+ ) : url ? (
42
+ <img
43
+ alt="Workflow stream content"
44
+ className="absolute inset-0 h-full w-full object-contain"
45
+ onError={() => setFailed(true)}
46
+ src={url}
47
+ />
48
+ ) : (
49
+ <div className="h-full w-full bg-gray-100" aria-hidden="true" />
50
+ )}
51
+ </div>
52
+ </div>
53
+ );
54
+ }
@@ -2,7 +2,9 @@
2
2
 
3
3
  import React, { useEffect, useRef } from 'react';
4
4
  import { Virtuoso, type VirtuosoHandle } from 'react-virtuoso';
5
+ import { getStreamImageType } from '../lib/stream-image';
5
6
  import { serializeForClipboard } from './sidebar/copyable-data-block';
7
+ import { StreamImagePreview } from './stream-image-preview';
6
8
  import { StreamViewerSkeleton } from './stream-viewer-skeleton';
7
9
  import { CopyButton } from './trace-viewer/components/copy-button';
8
10
  import { DataInspector } from './ui/data-inspector';
@@ -34,10 +36,16 @@ interface StreamViewerProps {
34
36
  // ──────────────────────────────────────────────────────────────────────────
35
37
 
36
38
  const ChunkRow = React.memo(function ChunkRow({ chunk }: { chunk: Chunk }) {
39
+ const image =
40
+ chunk.value instanceof Uint8Array && getStreamImageType(chunk.value)
41
+ ? chunk.value
42
+ : null;
37
43
  return (
38
44
  <div className="flex w-full items-start gap-1 border-b border-gray-alpha-400 px-3 py-2">
39
45
  <div className="min-w-0 flex-1">
40
- {typeof chunk.value === 'string' ? (
46
+ {image ? (
47
+ <StreamImagePreview data={image} />
48
+ ) : typeof chunk.value === 'string' ? (
41
49
  <span className="whitespace-pre-wrap break-words text-label-12 font-mono text-gray-1000">
42
50
  {chunk.value}
43
51
  </span>
@@ -45,11 +53,13 @@ const ChunkRow = React.memo(function ChunkRow({ chunk }: { chunk: Chunk }) {
45
53
  <DataInspector data={chunk.value} expandLevel={1} />
46
54
  )}
47
55
  </div>
48
- <CopyButton
49
- copyText={serializeForClipboard(chunk.value)}
50
- ariaLabel="Copy chunk"
51
- className="shrink-0 -mr-1 [&>div]:h-4 [&>div]:w-4 [&_svg]:h-4 [&_svg]:w-4"
52
- />
56
+ {!image && (
57
+ <CopyButton
58
+ copyText={serializeForClipboard(chunk.value)}
59
+ ariaLabel="Copy chunk"
60
+ className="shrink-0 -mr-1 [&>div]:h-4 [&>div]:w-4 [&_svg]:h-4 [&_svg]:w-4"
61
+ />
62
+ )}
53
63
  </div>
54
64
  );
55
65
  });
@@ -0,0 +1,143 @@
1
+ 'use client';
2
+
3
+ import { ChevronDown, ChevronUp, X } from 'lucide-react';
4
+ import { type ReactNode, useEffect, useRef } from 'react';
5
+ import { IconButton } from '../../ui/icon-button';
6
+ import { Kbd } from '../../ui/kbd';
7
+ import { Tooltip, TooltipContent, TooltipTrigger } from '../../ui/tooltip';
8
+ import { PANEL_DEFAULT_WIDTH, PANEL_MIN_WIDTH } from './detail-panel-width';
9
+ import { DraggableBorder } from './draggable-border';
10
+ import { isTypingTarget } from './use-alt-held';
11
+ import type { DetailPanelWidth } from './use-detail-panel-width';
12
+
13
+ /**
14
+ * The right-hand details aside shared by the Trace and Events tabs: resizable
15
+ * left border, a header with the title, prev/next and close, and a scrolling
16
+ * body. While mounted it handles the shortcuts its header advertises (K or
17
+ * ArrowUp, J or ArrowDown, Escape) anywhere on the page, so mount it only
18
+ * while an item is selected. The width lives with the owner
19
+ * (`useDetailPanelWidth`), which stays mounted while the panel comes and goes.
20
+ */
21
+ export function DetailPanelShell({
22
+ id,
23
+ width,
24
+ title,
25
+ itemLabel,
26
+ onPrev,
27
+ onNext,
28
+ onClose,
29
+ children,
30
+ }: {
31
+ id: string;
32
+ width: DetailPanelWidth;
33
+ title: ReactNode;
34
+ /** What one item is called in labels, e.g. "span" or "event". */
35
+ itemLabel: string;
36
+ onPrev?: () => void;
37
+ onNext?: () => void;
38
+ onClose: () => void;
39
+ children: ReactNode;
40
+ }): ReactNode {
41
+ const asideRef = useRef<HTMLElement | null>(null);
42
+
43
+ // Read through a ref so the listener is registered once, whatever the
44
+ // identity of the callbacks the owner passes on each render.
45
+ const handlersRef = useRef({ onPrev, onNext, onClose });
46
+ handlersRef.current = { onPrev, onNext, onClose };
47
+ useEffect(() => {
48
+ const onKeyDown = (e: KeyboardEvent): void => {
49
+ // Leave keys typed into a field, and presses another handler took (a
50
+ // tree row moving focus, a search box clearing itself).
51
+ if (e.defaultPrevented || isTypingTarget(e.target)) return;
52
+ const handlers = handlersRef.current;
53
+ let handler: (() => void) | undefined;
54
+ if (e.key === 'k' || e.key === 'ArrowUp') handler = handlers.onPrev;
55
+ else if (e.key === 'j' || e.key === 'ArrowDown')
56
+ handler = handlers.onNext;
57
+ else if (e.key === 'Escape') handler = handlers.onClose;
58
+ if (!handler) return;
59
+ e.preventDefault();
60
+ handler();
61
+ };
62
+ window.addEventListener('keydown', onKeyDown);
63
+ return () => window.removeEventListener('keydown', onKeyDown);
64
+ }, []);
65
+
66
+ return (
67
+ <aside
68
+ ref={asideRef}
69
+ id={id}
70
+ className="relative flex flex-col h-full max-h-full shrink-0 bg-background-100 border-l border-gray-alpha-400"
71
+ style={{ width: width.width }}
72
+ >
73
+ <DraggableBorder
74
+ element={asideRef}
75
+ position="left"
76
+ onWidthChange={width.resize}
77
+ onReset={() => width.resize(PANEL_DEFAULT_WIDTH)}
78
+ aria-label={`Resize ${itemLabel} details panel`}
79
+ aria-controls={id}
80
+ aria-valuemin={PANEL_MIN_WIDTH}
81
+ aria-valuemax={width.maxWidth}
82
+ aria-valuenow={Math.min(
83
+ Math.max(Math.round(width.width), PANEL_MIN_WIDTH),
84
+ width.maxWidth
85
+ )}
86
+ />
87
+ {/* Panel header */}
88
+ <div className="flex items-center justify-between gap-2 shrink-0 px-4 py-[7.5px]">
89
+ <div className="flex min-w-0 items-center gap-2 text-label-14 font-medium text-gray-1000">
90
+ {title}
91
+ </div>
92
+ <div className="flex items-center gap-0.5 shrink-0">
93
+ <Tooltip>
94
+ <TooltipTrigger asChild>
95
+ <IconButton
96
+ aria-label="Navigate up"
97
+ aria-keyshortcuts="K"
98
+ onClick={onPrev}
99
+ disabled={!onPrev}
100
+ >
101
+ <ChevronUp className="w-4 h-4" />
102
+ </IconButton>
103
+ </TooltipTrigger>
104
+ {onPrev ? (
105
+ <TooltipContent>
106
+ Navigate up
107
+ <Kbd>K</Kbd>
108
+ </TooltipContent>
109
+ ) : null}
110
+ </Tooltip>
111
+ <Tooltip>
112
+ <TooltipTrigger asChild>
113
+ <IconButton
114
+ aria-label="Navigate down"
115
+ aria-keyshortcuts="J"
116
+ onClick={onNext}
117
+ disabled={!onNext}
118
+ >
119
+ <ChevronDown className="w-4 h-4" />
120
+ </IconButton>
121
+ </TooltipTrigger>
122
+ {onNext ? (
123
+ <TooltipContent>
124
+ Navigate down
125
+ <Kbd>J</Kbd>
126
+ </TooltipContent>
127
+ ) : null}
128
+ </Tooltip>
129
+ <div aria-hidden className="w-px h-4 bg-gray-alpha-400 mx-1" />
130
+ <IconButton
131
+ aria-label={`Close ${itemLabel} details`}
132
+ aria-keyshortcuts="Escape"
133
+ onClick={onClose}
134
+ >
135
+ <X className="w-4 h-4" />
136
+ </IconButton>
137
+ </div>
138
+ </div>
139
+ {/* Panel body */}
140
+ <div className="flex-1 overflow-y-auto">{children}</div>
141
+ </aside>
142
+ );
143
+ }
@@ -1,16 +1,7 @@
1
1
  'use client';
2
2
 
3
3
  import { parseStepName, parseWorkflowName } from '@workflow/utils/parse-name';
4
- import { ChevronDown, ChevronUp, X } from 'lucide-react';
5
- import {
6
- type ReactNode,
7
- type RefObject,
8
- useCallback,
9
- useEffect,
10
- useMemo,
11
- useRef,
12
- useState,
13
- } from 'react';
4
+ import { type ReactNode, type RefObject, useCallback, useMemo } from 'react';
14
5
  import { filterSpanRawEvents } from '../../../lib/trace-builder';
15
6
  import { ErrorBoundary } from '../../error-boundary';
16
7
  import {
@@ -18,20 +9,9 @@ import {
18
9
  type SelectedSpanInfo,
19
10
  } from '../../sidebar/entity-detail-panel';
20
11
  import { useSidebarData } from '../../sidebar/sidebar-data-context';
21
- import { IconButton } from '../../ui/icon-button';
22
- import { Kbd } from '../../ui/kbd';
23
- import { Tooltip, TooltipContent, TooltipTrigger } from '../../ui/tooltip';
24
12
  import { useActiveSpan } from '../context';
25
- import {
26
- clampPanelWidth,
27
- computeMaxPanelWidth,
28
- PANEL_DEFAULT_WIDTH,
29
- PANEL_MIN_WIDTH,
30
- readStoredPanelWidth,
31
- writeStoredPanelWidth,
32
- } from './detail-panel-width';
33
- import { DraggableBorder } from './draggable-border';
34
- import { useElementWidth } from './use-element-width';
13
+ import { DetailPanelShell } from './detail-panel-shell';
14
+ import { useDetailPanelWidth } from './use-detail-panel-width';
35
15
 
36
16
  const DETAIL_PANEL_ID = 'trace-detail-panel';
37
17
 
@@ -61,11 +41,11 @@ function useSelectedSpanInfo(): SelectedSpanInfo | null {
61
41
  }
62
42
 
63
43
  /**
64
- * The span detail aside: content, prev/next/close header, J/K navigation, and
65
- * the resizable left border with its width model (see detail-panel-width.ts).
44
+ * The span detail aside: the selected span's details in `DetailPanelShell`,
45
+ * which supplies the header, its J/K/Escape shortcuts and the resizable border.
66
46
  *
67
- * Always mounted (it renders null without a selection) so the panel width
68
- * survives closing and reopening within a session.
47
+ * Always mounted (it renders null without a selection) and holds the panel
48
+ * width, so the width survives closing and reopening within a session.
69
49
  */
70
50
  export function TraceDetailPanel({
71
51
  containerRef,
@@ -79,28 +59,7 @@ export function TraceDetailPanel({
79
59
  const { activeSpan, activeSpanId, spans } = useActiveSpan();
80
60
  const sidebar = useSidebarData();
81
61
  const selectedSpan = useSelectedSpanInfo();
82
- const isOpen = Boolean(activeSpan);
83
-
84
- const [storedWidth, setStoredWidth] = useState<number>(() =>
85
- readStoredPanelWidth()
86
- );
87
- const containerWidth = useElementWidth(containerRef, isOpen);
88
- const asideRef = useRef<HTMLDivElement | null>(null);
89
-
90
- const handleResize = useCallback(
91
- (next: number) => {
92
- const clamped = clampPanelWidth(next, containerWidth);
93
- setStoredWidth(clamped);
94
- writeStoredPanelWidth(clamped);
95
- },
96
- [containerWidth]
97
- );
98
-
99
- const panelWidth = clampPanelWidth(storedWidth, containerWidth);
100
- const panelMaxWidth = Math.max(
101
- PANEL_MIN_WIDTH,
102
- computeMaxPanelWidth(containerWidth)
103
- );
62
+ const panelWidth = useDetailPanelWidth(containerRef, Boolean(activeSpan));
104
63
 
105
64
  const { prevSpanId, nextSpanId } = useMemo(() => {
106
65
  if (!activeSpanId) return { prevSpanId: null, nextSpanId: null };
@@ -120,38 +79,6 @@ export function TraceDetailPanel({
120
79
  if (nextSpanId) onNavigateToSpan(nextSpanId);
121
80
  }, [nextSpanId, onNavigateToSpan]);
122
81
 
123
- useEffect(() => {
124
- if (!isOpen) return;
125
-
126
- const onKeyDown = (e: KeyboardEvent): void => {
127
- if (
128
- e.key !== 'j' &&
129
- e.key !== 'k' &&
130
- e.key !== 'ArrowDown' &&
131
- e.key !== 'ArrowUp'
132
- ) {
133
- return;
134
- }
135
- const target = e.target as HTMLElement | null;
136
- if (
137
- target instanceof HTMLInputElement ||
138
- target instanceof HTMLTextAreaElement ||
139
- target?.isContentEditable
140
- ) {
141
- return;
142
- }
143
- const targetId =
144
- e.key === 'k' || e.key === 'ArrowUp' ? prevSpanId : nextSpanId;
145
- if (targetId) {
146
- e.preventDefault();
147
- onNavigateToSpan(targetId);
148
- }
149
- };
150
-
151
- window.addEventListener('keydown', onKeyDown);
152
- return () => window.removeEventListener('keydown', onKeyDown);
153
- }, [isOpen, prevSpanId, nextSpanId, onNavigateToSpan]);
154
-
155
82
  // Derive the selected span name for the panel header
156
83
  const selectedSpanName = useMemo(() => {
157
84
  if (!selectedSpan?.data) return 'Details';
@@ -175,102 +102,36 @@ export function TraceDetailPanel({
175
102
  if (!activeSpan) return null;
176
103
 
177
104
  return (
178
- <aside
179
- ref={asideRef}
105
+ <DetailPanelShell
180
106
  id={DETAIL_PANEL_ID}
181
- className="relative flex flex-col h-full max-h-full shrink-0 bg-background-100 border-l border-gray-alpha-400"
182
- style={{ width: panelWidth }}
107
+ width={panelWidth}
108
+ title={<span className="truncate block">{selectedSpanName}</span>}
109
+ itemLabel="span"
110
+ onPrev={prevSpanId ? handleSelectPrev : undefined}
111
+ onNext={nextSpanId ? handleSelectNext : undefined}
112
+ onClose={onClose}
183
113
  >
184
- <DraggableBorder
185
- element={asideRef}
186
- position="left"
187
- onWidthChange={handleResize}
188
- onReset={() => handleResize(PANEL_DEFAULT_WIDTH)}
189
- aria-label="Resize span details panel"
190
- aria-controls={DETAIL_PANEL_ID}
191
- aria-valuemin={PANEL_MIN_WIDTH}
192
- aria-valuemax={panelMaxWidth}
193
- aria-valuenow={Math.min(
194
- Math.max(Math.round(panelWidth), PANEL_MIN_WIDTH),
195
- panelMaxWidth
196
- )}
197
- />
198
- {/* Panel header */}
199
- <div className="flex items-center justify-between gap-2 shrink-0 px-4 py-[7.5px]">
200
- <span className="text-label-14 font-medium text-gray-1000 truncate block">
201
- {selectedSpanName}
202
- </span>
203
- <div className="flex items-center gap-0.5 shrink-0">
204
- <Tooltip>
205
- <TooltipTrigger asChild>
206
- <IconButton
207
- aria-label="Navigate up"
208
- aria-keyshortcuts="K"
209
- onClick={handleSelectPrev}
210
- disabled={!prevSpanId}
211
- >
212
- <ChevronUp className="w-4 h-4" />
213
- </IconButton>
214
- </TooltipTrigger>
215
- {prevSpanId ? (
216
- <TooltipContent>
217
- Navigate up
218
- <Kbd>K</Kbd>
219
- </TooltipContent>
220
- ) : null}
221
- </Tooltip>
222
- <Tooltip>
223
- <TooltipTrigger asChild>
224
- <IconButton
225
- aria-label="Navigate down"
226
- aria-keyshortcuts="J"
227
- onClick={handleSelectNext}
228
- disabled={!nextSpanId}
229
- >
230
- <ChevronDown className="w-4 h-4" />
231
- </IconButton>
232
- </TooltipTrigger>
233
- {nextSpanId ? (
234
- <TooltipContent>
235
- Navigate down
236
- <Kbd>J</Kbd>
237
- </TooltipContent>
238
- ) : null}
239
- </Tooltip>
240
- <div aria-hidden className="w-px h-4 bg-gray-alpha-400 mx-1" />
241
- <IconButton
242
- aria-label="Close span details"
243
- aria-keyshortcuts="Escape"
244
- onClick={onClose}
245
- >
246
- <X className="w-4 h-4" />
247
- </IconButton>
248
- </div>
249
- </div>
250
- {/* Panel body */}
251
- <div className="flex-1 overflow-y-auto">
252
- <ErrorBoundary>
253
- <EntityDetailPanel
254
- run={sidebar.run}
255
- onStreamClick={sidebar.onStreamClick}
256
- onRunClick={sidebar.onRunClick}
257
- fetchSpanDetail={sidebar.fetchSpanDetail}
258
- onWakeUpSleep={sidebar.onWakeUpSleep}
259
- onLoadEventData={sidebar.onLoadEventData}
260
- onResolveHook={sidebar.onResolveHook}
261
- encryptionKey={sidebar.encryptionKey}
262
- onDecrypt={sidebar.onDecrypt}
263
- isDecrypting={sidebar.isDecrypting}
264
- isDecryptDisabled={sidebar.isDecryptDisabled}
265
- decryptDisabledReason={sidebar.decryptDisabledReason}
266
- selectedSpan={selectedSpan}
267
- showSeparateEventOccurrenceTimestamps={
268
- sidebar.showSeparateEventOccurrenceTimestamps
269
- }
270
- getModuleSourceUrl={sidebar.getModuleSourceUrl}
271
- />
272
- </ErrorBoundary>
273
- </div>
274
- </aside>
114
+ <ErrorBoundary>
115
+ <EntityDetailPanel
116
+ run={sidebar.run}
117
+ onStreamClick={sidebar.onStreamClick}
118
+ onRunClick={sidebar.onRunClick}
119
+ fetchSpanDetail={sidebar.fetchSpanDetail}
120
+ onWakeUpSleep={sidebar.onWakeUpSleep}
121
+ onLoadEventData={sidebar.onLoadEventData}
122
+ onResolveHook={sidebar.onResolveHook}
123
+ encryptionKey={sidebar.encryptionKey}
124
+ onDecrypt={sidebar.onDecrypt}
125
+ isDecrypting={sidebar.isDecrypting}
126
+ isDecryptDisabled={sidebar.isDecryptDisabled}
127
+ decryptDisabledReason={sidebar.decryptDisabledReason}
128
+ selectedSpan={selectedSpan}
129
+ showSeparateEventOccurrenceTimestamps={
130
+ sidebar.showSeparateEventOccurrenceTimestamps
131
+ }
132
+ getModuleSourceUrl={sidebar.getModuleSourceUrl}
133
+ />
134
+ </ErrorBoundary>
135
+ </DetailPanelShell>
275
136
  );
276
137
  }
@@ -55,6 +55,36 @@ function getEventStyle(
55
55
  };
56
56
  }
57
57
 
58
+ /**
59
+ * The colored type icon (workflow, step, hook, sleep) with its tooltip. Shared
60
+ * by the Trace span list and the Events tab so both mark entities the same way.
61
+ */
62
+ export function ResourceIcon({
63
+ resource,
64
+ isErrored = false,
65
+ isCancelled = false,
66
+ }: {
67
+ resource: string;
68
+ isErrored?: boolean;
69
+ isCancelled?: boolean;
70
+ }) {
71
+ const {
72
+ icon: Icon,
73
+ className,
74
+ label,
75
+ } = getEventStyle(resource, isErrored, isCancelled);
76
+ return (
77
+ <Tooltip delayDuration={500}>
78
+ <TooltipTrigger asChild>
79
+ <span className={cn('shrink-0', className)}>
80
+ <Icon className="w-4 h-4" />
81
+ </span>
82
+ </TooltipTrigger>
83
+ <TooltipContent side="top">{label}</TooltipContent>
84
+ </Tooltip>
85
+ );
86
+ }
87
+
58
88
  const EventRow = ({
59
89
  span,
60
90
  isSelected,
@@ -69,12 +99,6 @@ const EventRow = ({
69
99
  const durationMs = getSpanDurationMs(span);
70
100
  const isErrored = isSpanErrored(span);
71
101
  const isCancelled = isSpanCancelled(span);
72
- const {
73
- icon: Icon,
74
- className: tagClassName,
75
- label: iconLabel,
76
- } = getEventStyle(span.resource, isErrored, isCancelled);
77
-
78
102
  return (
79
103
  <li
80
104
  className={cn(
@@ -91,14 +115,11 @@ const EventRow = ({
91
115
  <div className="h-full hover:bg-gray-100 group-aria-selected:bg-gray-100 group-aria-selected:hover:bg-gray-200">
92
116
  <div className="flex h-full min-w-0 items-center pl-4 pr-2">
93
117
  <div className="flex min-w-0 flex-1 items-center gap-2">
94
- <Tooltip delayDuration={500}>
95
- <TooltipTrigger asChild>
96
- <span className={cn('shrink-0', tagClassName)}>
97
- <Icon className="w-4 h-4" />
98
- </span>
99
- </TooltipTrigger>
100
- <TooltipContent side="top">{iconLabel}</TooltipContent>
101
- </Tooltip>
118
+ <ResourceIcon
119
+ resource={span.resource}
120
+ isErrored={isErrored}
121
+ isCancelled={isCancelled}
122
+ />
102
123
  <span className="min-w-0 text-label-14">
103
124
  <MiddleTruncate value={span.name} />
104
125
  </span>
@@ -6,7 +6,7 @@ function isAltModifierKey(key: string): boolean {
6
6
  return key === 'Alt' || key === 'AltGraph';
7
7
  }
8
8
 
9
- function isTypingTarget(target: EventTarget | null): boolean {
9
+ export function isTypingTarget(target: EventTarget | null): boolean {
10
10
  return (
11
11
  target instanceof HTMLInputElement ||
12
12
  target instanceof HTMLTextAreaElement ||
@@ -0,0 +1,53 @@
1
+ 'use client';
2
+
3
+ import { type RefObject, useCallback, useState } from 'react';
4
+ import {
5
+ clampPanelWidth,
6
+ computeMaxPanelWidth,
7
+ PANEL_MIN_WIDTH,
8
+ readStoredPanelWidth,
9
+ writeStoredPanelWidth,
10
+ } from './detail-panel-width';
11
+ import { useElementWidth } from './use-element-width';
12
+
13
+ /** The details panel's width, bounded by the container it shares. */
14
+ export interface DetailPanelWidth {
15
+ /** Rendered width (px): the preferred width clamped to the container. */
16
+ width: number;
17
+ /** Widest the container allows (px), for the resize handle. */
18
+ maxWidth: number;
19
+ /** Sets and persists the preferred width, clamped to the container. */
20
+ resize: (width: number) => void;
21
+ }
22
+
23
+ /**
24
+ * Width state for `DetailPanelShell` (model in detail-panel-width.ts). Call it
25
+ * from a component that stays mounted while the panel opens, closes and
26
+ * changes selection, so the width holds across all three in a session;
27
+ * localStorage only carries it to the next one. The container is measured
28
+ * only while `open`.
29
+ */
30
+ export function useDetailPanelWidth(
31
+ containerRef: RefObject<HTMLElement | null>,
32
+ open: boolean
33
+ ): DetailPanelWidth {
34
+ const [storedWidth, setStoredWidth] = useState<number>(() =>
35
+ readStoredPanelWidth()
36
+ );
37
+ const containerWidth = useElementWidth(containerRef, open);
38
+
39
+ const resize = useCallback(
40
+ (next: number) => {
41
+ const clamped = clampPanelWidth(next, containerWidth);
42
+ setStoredWidth(clamped);
43
+ writeStoredPanelWidth(clamped);
44
+ },
45
+ [containerWidth]
46
+ );
47
+
48
+ return {
49
+ width: clampPanelWidth(storedWidth, containerWidth),
50
+ maxWidth: Math.max(PANEL_MIN_WIDTH, computeMaxPanelWidth(containerWidth)),
51
+ resize,
52
+ };
53
+ }
@@ -25,12 +25,16 @@ ActiveSpanContext.displayName = 'ActiveSpanContext';
25
25
 
26
26
  export function ActiveSpanProvider({
27
27
  spans,
28
+ initialSelectedSpanId,
28
29
  children,
29
30
  }: {
30
31
  spans: Span[];
32
+ initialSelectedSpanId?: string;
31
33
  children: ReactNode;
32
34
  }) {
33
- const [activeSpanId, setActiveSpanId] = useState<string | null>(null);
35
+ const [activeSpanId, setActiveSpanId] = useState<string | null>(
36
+ initialSelectedSpanId ?? null
37
+ );
34
38
 
35
39
  useEffect(() => {
36
40
  setActiveSpanId((currentSpanId) => {