@workflow/web-shared 5.2.0 → 5.3.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.
- package/dist/components/event-list/event-details-panel.d.ts.map +1 -1
- package/dist/components/event-list/event-details-panel.js +3 -3
- package/dist/components/event-list/event-list-toolbar.d.ts +2 -1
- package/dist/components/event-list/event-list-toolbar.d.ts.map +1 -1
- package/dist/components/event-list/event-list-toolbar.js +20 -11
- package/dist/components/event-list/event-row.d.ts +3 -3
- package/dist/components/event-list/event-row.d.ts.map +1 -1
- package/dist/components/event-list/event-row.js +15 -13
- package/dist/components/event-list/use-event-search.d.ts +3 -1
- package/dist/components/event-list/use-event-search.d.ts.map +1 -1
- package/dist/components/event-list/use-event-search.js +19 -20
- package/dist/components/event-list-view.d.ts.map +1 -1
- package/dist/components/event-list-view.js +53 -24
- package/dist/components/hook-actions.d.ts +0 -1
- package/dist/components/hook-actions.d.ts.map +1 -1
- package/dist/components/hook-actions.js +1 -3
- package/dist/components/index.d.ts +5 -9
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +4 -9
- package/dist/components/sidebar/attribute-panel.d.ts +0 -13
- package/dist/components/sidebar/attribute-panel.d.ts.map +1 -1
- package/dist/components/sidebar/attribute-panel.js +5 -5
- package/dist/components/sidebar/attributes-block.d.ts +0 -7
- package/dist/components/sidebar/attributes-block.d.ts.map +1 -1
- package/dist/components/sidebar/attributes-block.js +5 -5
- package/dist/components/sidebar/conversation-view.d.ts.map +1 -1
- package/dist/components/sidebar/conversation-view.js +4 -3
- package/dist/components/sidebar/copyable-data-block.d.ts.map +1 -1
- package/dist/components/sidebar/copyable-data-block.js +8 -6
- package/dist/components/sidebar/entity-detail-panel.d.ts.map +1 -1
- package/dist/components/sidebar/entity-detail-panel.js +2 -3
- package/dist/components/stream-image-preview.js +2 -2
- package/dist/components/stream-viewer.js +3 -3
- package/dist/components/trace-viewer/components/middle-truncate/truncate.d.ts +1 -4
- package/dist/components/trace-viewer/components/middle-truncate/truncate.d.ts.map +1 -1
- package/dist/components/trace-viewer/components/middle-truncate/truncate.js +2 -2
- package/dist/components/trace-viewer/components/minimap.d.ts.map +1 -1
- package/dist/components/trace-viewer/components/minimap.js +6 -4
- package/dist/components/trace-viewer/components/timeline.d.ts +0 -11
- package/dist/components/trace-viewer/components/timeline.d.ts.map +1 -1
- package/dist/components/trace-viewer/components/timeline.js +1 -2
- package/dist/components/trace-viewer/trace-viewer.js +4 -10
- package/dist/components/ui/button.d.ts +28 -17
- package/dist/components/ui/button.d.ts.map +1 -1
- package/dist/components/ui/button.js +47 -43
- package/dist/components/ui/context-card.js +3 -3
- package/dist/components/ui/copy-button.d.ts +15 -0
- package/dist/components/ui/copy-button.d.ts.map +1 -0
- package/dist/components/ui/copy-button.js +41 -0
- package/dist/components/ui/data-inspector.d.ts.map +1 -1
- package/dist/components/ui/data-inspector.js +8 -38
- package/dist/components/ui/decrypt-button.d.ts +3 -2
- package/dist/components/ui/decrypt-button.d.ts.map +1 -1
- package/dist/components/ui/decrypt-button.js +13 -7
- package/dist/components/ui/duplicate-event-tooltip.d.ts +1 -9
- package/dist/components/ui/duplicate-event-tooltip.d.ts.map +1 -1
- package/dist/components/ui/duplicate-event-tooltip.js +2 -10
- package/dist/components/ui/error-stack-block.js +3 -3
- package/dist/components/ui/icon-button.d.ts +2 -2
- package/dist/components/ui/icon-button.d.ts.map +1 -1
- package/dist/components/ui/icon-button.js +2 -3
- package/dist/components/ui/kbd.d.ts +1 -1
- package/dist/components/ui/kbd.d.ts.map +1 -1
- package/dist/components/ui/kbd.js +1 -2
- package/dist/components/ui/search-input.d.ts +19 -0
- package/dist/components/ui/search-input.d.ts.map +1 -0
- package/dist/components/ui/search-input.js +61 -0
- package/dist/components/ui/spinner.d.ts +54 -6
- package/dist/components/ui/spinner.d.ts.map +1 -1
- package/dist/components/ui/spinner.js +84 -46
- package/dist/components/workflow-traces/trace-span-construction.d.ts +1 -22
- package/dist/components/workflow-traces/trace-span-construction.d.ts.map +1 -1
- package/dist/components/workflow-traces/trace-span-construction.js +3 -3
- package/dist/index.d.ts +9 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -11
- package/dist/lib/event-analysis.d.ts +1 -25
- package/dist/lib/event-analysis.d.ts.map +1 -1
- package/dist/lib/event-analysis.js +2 -75
- package/dist/lib/event-list-model.d.ts +4 -2
- package/dist/lib/event-list-model.d.ts.map +1 -1
- package/dist/lib/event-list-model.js +13 -11
- package/dist/lib/exact-event-search-id.d.ts +0 -2
- package/dist/lib/exact-event-search-id.d.ts.map +1 -1
- package/dist/lib/exact-event-search-id.js +1 -12
- package/dist/lib/hydration.d.ts +1 -12
- package/dist/lib/hydration.d.ts.map +1 -1
- package/dist/lib/hydration.js +8 -20
- package/dist/lib/stream-display.d.ts +0 -1
- package/dist/lib/stream-display.d.ts.map +1 -1
- package/dist/lib/stream-display.js +2 -2
- package/dist/lib/trace-builder.d.ts +0 -8
- package/dist/lib/trace-builder.d.ts.map +1 -1
- package/dist/lib/trace-builder.js +2 -2
- package/dist/lib/utils.d.ts +0 -22
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/lib/utils.js +1 -31
- package/dist/styles.css +268 -118
- package/package.json +4 -16
- package/src/components/event-list/event-details-panel.tsx +3 -4
- package/src/components/event-list/event-list-toolbar.tsx +35 -28
- package/src/components/event-list/event-row.tsx +33 -29
- package/src/components/event-list/use-event-search.ts +29 -22
- package/src/components/event-list-view.tsx +180 -52
- package/src/components/hook-actions.tsx +0 -1
- package/src/components/index.ts +4 -20
- package/src/components/sidebar/attribute-panel.tsx +4 -7
- package/src/components/sidebar/attributes-block.tsx +7 -6
- package/src/components/sidebar/conversation-view.tsx +3 -2
- package/src/components/sidebar/copyable-data-block.tsx +17 -14
- package/src/components/sidebar/entity-detail-panel.tsx +2 -7
- package/src/components/stream-image-preview.tsx +1 -1
- package/src/components/stream-viewer.tsx +4 -4
- package/src/components/trace-viewer/components/middle-truncate/truncate.ts +1 -2
- package/src/components/trace-viewer/components/minimap.tsx +4 -3
- package/src/components/trace-viewer/components/timeline.tsx +0 -2
- package/src/components/trace-viewer/trace-viewer.tsx +12 -38
- package/src/components/ui/button.tsx +144 -46
- package/src/components/ui/context-card.tsx +2 -2
- package/src/components/ui/copy-button.tsx +86 -0
- package/src/components/ui/data-inspector.tsx +23 -67
- package/src/components/ui/decrypt-button.tsx +23 -48
- package/src/components/ui/duplicate-event-tooltip.tsx +1 -22
- package/src/components/ui/error-stack-block.tsx +4 -4
- package/src/components/ui/icon-button.tsx +1 -3
- package/src/components/ui/kbd.tsx +0 -2
- package/src/components/ui/search-input.tsx +143 -0
- package/src/components/ui/spinner.tsx +105 -55
- package/src/components/workflow-traces/trace-span-construction.ts +2 -2
- package/src/index.ts +7 -55
- package/src/lib/event-analysis.ts +1 -104
- package/src/lib/event-list-model.ts +15 -12
- package/src/lib/exact-event-search-id.ts +0 -13
- package/src/lib/hydration.ts +6 -31
- package/src/lib/stream-display.ts +1 -1
- package/src/lib/trace-builder.ts +1 -1
- package/src/lib/utils.ts +0 -48
- package/src/styles.css +268 -118
- package/dist/components/trace-viewer/components/copy-button.d.ts +0 -9
- package/dist/components/trace-viewer/components/copy-button.d.ts.map +0 -1
- package/dist/components/trace-viewer/components/copy-button.js +0 -27
- package/dist/components/ui/alert.d.ts +0 -9
- package/dist/components/ui/alert.d.ts.map +0 -1
- package/dist/components/ui/alert.js +0 -23
- package/dist/components/ui/card.d.ts +0 -9
- package/dist/components/ui/card.d.ts.map +0 -1
- package/dist/components/ui/card.js +0 -18
- package/dist/components/ui/load-more-button.d.ts +0 -13
- package/dist/components/ui/load-more-button.d.ts.map +0 -1
- package/dist/components/ui/load-more-button.js +0 -12
- package/dist/components/ui/menu-dropdown.d.ts +0 -16
- package/dist/components/ui/menu-dropdown.d.ts.map +0 -1
- package/dist/components/ui/menu-dropdown.js +0 -30
- package/dist/hooks/use-dark-mode.d.ts +0 -9
- package/dist/hooks/use-dark-mode.d.ts.map +0 -1
- package/dist/hooks/use-dark-mode.js +0 -30
- package/dist/lib/event-materialization.d.ts +0 -91
- package/dist/lib/event-materialization.d.ts.map +0 -1
- package/dist/lib/event-materialization.js +0 -219
- package/src/components/index.d.ts +0 -1
- package/src/components/trace-viewer/components/copy-button.tsx +0 -68
- package/src/components/ui/alert.tsx +0 -59
- package/src/components/ui/card.tsx +0 -79
- package/src/components/ui/load-more-button.tsx +0 -38
- package/src/components/ui/menu-dropdown.tsx +0 -97
- package/src/hooks/use-dark-mode.ts +0 -34
- package/src/index.d.ts +0 -1
- package/src/lib/event-materialization.ts +0 -304
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import * as React from 'react';
|
|
4
|
-
|
|
5
|
-
import { cn } from '../../lib/cn';
|
|
6
|
-
|
|
7
|
-
const Card = React.forwardRef<
|
|
8
|
-
HTMLDivElement,
|
|
9
|
-
React.HTMLAttributes<HTMLDivElement>
|
|
10
|
-
>(({ className, ...props }, ref) => (
|
|
11
|
-
<div
|
|
12
|
-
ref={ref}
|
|
13
|
-
className={cn('rounded-lg border shadow-sm', className)}
|
|
14
|
-
{...props}
|
|
15
|
-
/>
|
|
16
|
-
));
|
|
17
|
-
Card.displayName = 'Card';
|
|
18
|
-
|
|
19
|
-
const CardHeader = React.forwardRef<
|
|
20
|
-
HTMLDivElement,
|
|
21
|
-
React.HTMLAttributes<HTMLDivElement>
|
|
22
|
-
>(({ className, ...props }, ref) => (
|
|
23
|
-
<div
|
|
24
|
-
ref={ref}
|
|
25
|
-
className={cn('flex flex-col space-y-1.5 p-6', className)}
|
|
26
|
-
{...props}
|
|
27
|
-
/>
|
|
28
|
-
));
|
|
29
|
-
CardHeader.displayName = 'CardHeader';
|
|
30
|
-
|
|
31
|
-
const CardTitle = React.forwardRef<
|
|
32
|
-
HTMLDivElement,
|
|
33
|
-
React.HTMLAttributes<HTMLDivElement>
|
|
34
|
-
>(({ className, ...props }, ref) => (
|
|
35
|
-
<div ref={ref} className={cn('text-heading-24', className)} {...props} />
|
|
36
|
-
));
|
|
37
|
-
CardTitle.displayName = 'CardTitle';
|
|
38
|
-
|
|
39
|
-
const CardDescription = React.forwardRef<
|
|
40
|
-
HTMLDivElement,
|
|
41
|
-
React.HTMLAttributes<HTMLDivElement>
|
|
42
|
-
>(({ className, ...props }, ref) => (
|
|
43
|
-
<div
|
|
44
|
-
ref={ref}
|
|
45
|
-
className={cn('text-copy-14', className)}
|
|
46
|
-
style={{ color: 'var(--ds-gray-900)' }}
|
|
47
|
-
{...props}
|
|
48
|
-
/>
|
|
49
|
-
));
|
|
50
|
-
CardDescription.displayName = 'CardDescription';
|
|
51
|
-
|
|
52
|
-
const CardContent = React.forwardRef<
|
|
53
|
-
HTMLDivElement,
|
|
54
|
-
React.HTMLAttributes<HTMLDivElement>
|
|
55
|
-
>(({ className, ...props }, ref) => (
|
|
56
|
-
<div ref={ref} className={cn('p-6 pt-0', className)} {...props} />
|
|
57
|
-
));
|
|
58
|
-
CardContent.displayName = 'CardContent';
|
|
59
|
-
|
|
60
|
-
const CardFooter = React.forwardRef<
|
|
61
|
-
HTMLDivElement,
|
|
62
|
-
React.HTMLAttributes<HTMLDivElement>
|
|
63
|
-
>(({ className, ...props }, ref) => (
|
|
64
|
-
<div
|
|
65
|
-
ref={ref}
|
|
66
|
-
className={cn('flex items-center p-6 pt-0', className)}
|
|
67
|
-
{...props}
|
|
68
|
-
/>
|
|
69
|
-
));
|
|
70
|
-
CardFooter.displayName = 'CardFooter';
|
|
71
|
-
|
|
72
|
-
export {
|
|
73
|
-
Card,
|
|
74
|
-
CardHeader,
|
|
75
|
-
CardFooter,
|
|
76
|
-
CardTitle,
|
|
77
|
-
CardDescription,
|
|
78
|
-
CardContent,
|
|
79
|
-
};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { Spinner } from './spinner';
|
|
4
|
-
|
|
5
|
-
const STYLES = `.wf-load-more{appearance:none;-webkit-appearance:none;border:none;display:inline-flex;align-items:center;justify-content:center;height:32px;padding:0 12px;border-radius:6px;font-size:13px;font-weight:500;line-height:20px;color:var(--ds-gray-1000);background:var(--ds-background-100);box-shadow:0 0 0 1px var(--ds-gray-400);cursor:pointer;white-space:nowrap;gap:6px;transition:background 150ms}.wf-load-more:hover{background:var(--ds-gray-alpha-200)}.wf-load-more:disabled{opacity:.6;cursor:default}.wf-load-more:disabled:hover{background:var(--ds-background-100)}`;
|
|
6
|
-
|
|
7
|
-
interface LoadMoreButtonProps {
|
|
8
|
-
loading?: boolean;
|
|
9
|
-
onClick?: () => void;
|
|
10
|
-
label?: string;
|
|
11
|
-
loadingLabel?: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* A "Load more" button matching Geist's Button type="secondary" size="small"
|
|
16
|
-
* with a spinner prefix when loading.
|
|
17
|
-
*/
|
|
18
|
-
export function LoadMoreButton({
|
|
19
|
-
loading = false,
|
|
20
|
-
onClick,
|
|
21
|
-
label = 'Load more',
|
|
22
|
-
loadingLabel = 'Loading...',
|
|
23
|
-
}: LoadMoreButtonProps) {
|
|
24
|
-
return (
|
|
25
|
-
<>
|
|
26
|
-
<style dangerouslySetInnerHTML={{ __html: STYLES }} />
|
|
27
|
-
<button
|
|
28
|
-
type="button"
|
|
29
|
-
onClick={onClick}
|
|
30
|
-
disabled={loading}
|
|
31
|
-
className="wf-load-more"
|
|
32
|
-
>
|
|
33
|
-
{loading && <Spinner size={14} />}
|
|
34
|
-
{loading ? loadingLabel : label}
|
|
35
|
-
</button>
|
|
36
|
-
</>
|
|
37
|
-
);
|
|
38
|
-
}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { useEffect, useRef, useState } from 'react';
|
|
4
|
-
import { cn } from '../../lib/cn';
|
|
5
|
-
|
|
6
|
-
const STYLES = `.wf-menu-btn{appearance:none;-webkit-appearance:none;border:none;display:inline-flex;align-items:center;justify-content:center;height:40px;padding:0 12px;border-radius:6px;font-size:14px;font-weight:500;line-height:20px;color:var(--ds-gray-1000);background:var(--ds-background-100);box-shadow:0 0 0 1px var(--ds-gray-400);cursor:pointer;white-space:nowrap;transition:background 150ms}.wf-menu-btn:hover{background:var(--ds-gray-alpha-200)}.wf-menu-item{appearance:none;-webkit-appearance:none;border:none;display:flex;align-items:center;width:100%;height:40px;padding:0 8px;border-radius:6px;font-size:14px;color:var(--ds-gray-1000);background:transparent;cursor:pointer;transition:background 150ms}.wf-menu-item:hover{background:var(--ds-gray-alpha-100)}`;
|
|
7
|
-
|
|
8
|
-
export interface MenuDropdownOption<T extends string = string> {
|
|
9
|
-
value: T;
|
|
10
|
-
label: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
interface MenuDropdownProps<T extends string = string> {
|
|
14
|
-
options: MenuDropdownOption<T>[];
|
|
15
|
-
value: T;
|
|
16
|
-
onChange: (value: T) => void;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* A dropdown menu that matches Geist's MenuButton (secondary) + Menu styling.
|
|
21
|
-
* Uses CSS classes with proper :hover specificity (no inline background).
|
|
22
|
-
*/
|
|
23
|
-
export function MenuDropdown<T extends string = string>({
|
|
24
|
-
options,
|
|
25
|
-
value,
|
|
26
|
-
onChange,
|
|
27
|
-
}: MenuDropdownProps<T>) {
|
|
28
|
-
const [open, setOpen] = useState(false);
|
|
29
|
-
const ref = useRef<HTMLDivElement>(null);
|
|
30
|
-
const label =
|
|
31
|
-
options.find((o) => o.value === value)?.label ?? options[0]?.label ?? '';
|
|
32
|
-
|
|
33
|
-
useEffect(() => {
|
|
34
|
-
if (!open) return;
|
|
35
|
-
function handleClickOutside(e: MouseEvent) {
|
|
36
|
-
if (ref.current && !ref.current.contains(e.target as Node)) {
|
|
37
|
-
setOpen(false);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
document.addEventListener('mousedown', handleClickOutside);
|
|
41
|
-
return () => document.removeEventListener('mousedown', handleClickOutside);
|
|
42
|
-
}, [open]);
|
|
43
|
-
|
|
44
|
-
return (
|
|
45
|
-
<div ref={ref} className="relative shrink-0">
|
|
46
|
-
<style dangerouslySetInnerHTML={{ __html: STYLES }} />
|
|
47
|
-
|
|
48
|
-
<button
|
|
49
|
-
type="button"
|
|
50
|
-
className="wf-menu-btn"
|
|
51
|
-
onClick={() => setOpen(!open)}
|
|
52
|
-
>
|
|
53
|
-
<span>{label}</span>
|
|
54
|
-
<svg
|
|
55
|
-
width={16}
|
|
56
|
-
height={16}
|
|
57
|
-
viewBox="0 0 16 16"
|
|
58
|
-
fill="none"
|
|
59
|
-
className="-mr-1 ml-4 text-gray-900"
|
|
60
|
-
>
|
|
61
|
-
<path
|
|
62
|
-
d="M4.5 6L8 9.5L11.5 6"
|
|
63
|
-
stroke="currentColor"
|
|
64
|
-
strokeWidth="1.5"
|
|
65
|
-
strokeLinecap="round"
|
|
66
|
-
strokeLinejoin="round"
|
|
67
|
-
/>
|
|
68
|
-
</svg>
|
|
69
|
-
</button>
|
|
70
|
-
|
|
71
|
-
{open && (
|
|
72
|
-
<div
|
|
73
|
-
className="absolute top-full right-0 z-[2001] mt-1 min-w-[140px] bg-background-100 p-1 material-menu"
|
|
74
|
-
role="menu"
|
|
75
|
-
>
|
|
76
|
-
{options.map((option) => (
|
|
77
|
-
<button
|
|
78
|
-
key={option.value}
|
|
79
|
-
type="button"
|
|
80
|
-
role="menuitem"
|
|
81
|
-
className={cn(
|
|
82
|
-
'wf-menu-item',
|
|
83
|
-
option.value === value ? 'font-medium' : 'font-normal'
|
|
84
|
-
)}
|
|
85
|
-
onClick={() => {
|
|
86
|
-
onChange(option.value);
|
|
87
|
-
setOpen(false);
|
|
88
|
-
}}
|
|
89
|
-
>
|
|
90
|
-
{option.label}
|
|
91
|
-
</button>
|
|
92
|
-
))}
|
|
93
|
-
</div>
|
|
94
|
-
)}
|
|
95
|
-
</div>
|
|
96
|
-
);
|
|
97
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { useEffect, useState } from 'react';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Hook that detects if dark mode is active and reacts to theme changes.
|
|
7
|
-
* Observes the 'dark' class on the document element, which is how
|
|
8
|
-
* next-themes and similar libraries apply the theme.
|
|
9
|
-
*
|
|
10
|
-
* @returns `true` if dark mode is active, `false` otherwise
|
|
11
|
-
*/
|
|
12
|
-
export const useDarkMode = (): boolean => {
|
|
13
|
-
const [isDark, setIsDark] = useState(() => {
|
|
14
|
-
if (typeof document === 'undefined') return false;
|
|
15
|
-
return document.documentElement.classList.contains('dark');
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
useEffect(() => {
|
|
19
|
-
if (typeof document === 'undefined') return;
|
|
20
|
-
|
|
21
|
-
const observer = new MutationObserver(() => {
|
|
22
|
-
setIsDark(document.documentElement.classList.contains('dark'));
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
observer.observe(document.documentElement, {
|
|
26
|
-
attributes: true,
|
|
27
|
-
attributeFilter: ['class'],
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
return () => observer.disconnect();
|
|
31
|
-
}, []);
|
|
32
|
-
|
|
33
|
-
return isDark;
|
|
34
|
-
};
|
package/src/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './index';
|
|
@@ -1,304 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Event materialization helpers.
|
|
3
|
-
*
|
|
4
|
-
* These functions convert a flat list of workflow events into entity-like
|
|
5
|
-
* objects (steps, hooks, waits) by grouping events by correlationId and
|
|
6
|
-
* stitching together lifecycle events.
|
|
7
|
-
*
|
|
8
|
-
* This enables a "top-down" data fetching pattern where the client fetches
|
|
9
|
-
* all events for a run once, then materializes entities client-side instead
|
|
10
|
-
* of making separate API calls for each entity type.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {
|
|
14
|
-
type Event,
|
|
15
|
-
isHookLifecycleEventType,
|
|
16
|
-
isStepEventType,
|
|
17
|
-
isWaitEventType,
|
|
18
|
-
type StepStatus,
|
|
19
|
-
} from '@workflow/world';
|
|
20
|
-
import { findDuplicateEventIds } from './duplicate-events';
|
|
21
|
-
import { findStartHookCreation } from './start-hook';
|
|
22
|
-
|
|
23
|
-
// ---------------------------------------------------------------------------
|
|
24
|
-
// Materialized entity types
|
|
25
|
-
// ---------------------------------------------------------------------------
|
|
26
|
-
|
|
27
|
-
export interface MaterializedStep {
|
|
28
|
-
stepId: string;
|
|
29
|
-
runId: string;
|
|
30
|
-
stepName: string;
|
|
31
|
-
status: StepStatus;
|
|
32
|
-
attempt: number;
|
|
33
|
-
createdAt: Date;
|
|
34
|
-
startedAt?: Date;
|
|
35
|
-
completedAt?: Date;
|
|
36
|
-
updatedAt: Date;
|
|
37
|
-
/** All events for this step, in insertion order */
|
|
38
|
-
events: Event[];
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export interface MaterializedHook {
|
|
42
|
-
hookId: string;
|
|
43
|
-
runId: string;
|
|
44
|
-
token?: string;
|
|
45
|
-
createdAt: Date;
|
|
46
|
-
receivedCount: number;
|
|
47
|
-
lastReceivedAt?: Date;
|
|
48
|
-
disposedAt?: Date;
|
|
49
|
-
/** All events for this hook, in insertion order */
|
|
50
|
-
events: Event[];
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export interface MaterializedWait {
|
|
54
|
-
waitId: string;
|
|
55
|
-
runId: string;
|
|
56
|
-
status: 'waiting' | 'completed';
|
|
57
|
-
createdAt: Date;
|
|
58
|
-
resumeAt?: Date;
|
|
59
|
-
completedAt?: Date;
|
|
60
|
-
/** All events for this wait, in insertion order */
|
|
61
|
-
events: Event[];
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export interface MaterializedEntities {
|
|
65
|
-
steps: MaterializedStep[];
|
|
66
|
-
hooks: MaterializedHook[];
|
|
67
|
-
waits: MaterializedWait[];
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// ---------------------------------------------------------------------------
|
|
71
|
-
// Helper: group events by correlationId
|
|
72
|
-
// ---------------------------------------------------------------------------
|
|
73
|
-
|
|
74
|
-
function groupByCorrelationId(
|
|
75
|
-
events: Event[],
|
|
76
|
-
matchesEventType: (eventType: string) => boolean
|
|
77
|
-
): Map<string, Event[]> {
|
|
78
|
-
const groups = new Map<string, Event[]>();
|
|
79
|
-
for (const event of events) {
|
|
80
|
-
const cid = event.correlationId;
|
|
81
|
-
if (!cid) continue;
|
|
82
|
-
if (!matchesEventType(event.eventType)) continue;
|
|
83
|
-
const existing = groups.get(cid);
|
|
84
|
-
if (existing) {
|
|
85
|
-
existing.push(event);
|
|
86
|
-
} else {
|
|
87
|
-
groups.set(cid, [event]);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return groups;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function getEventTimestamp(event: Event | undefined): Date | undefined {
|
|
94
|
-
const value = event?.occurredAt ?? event?.createdAt;
|
|
95
|
-
if (!value) return undefined;
|
|
96
|
-
|
|
97
|
-
const date = value instanceof Date ? value : new Date(value);
|
|
98
|
-
return Number.isNaN(date.getTime()) ? undefined : date;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// ---------------------------------------------------------------------------
|
|
102
|
-
// materializeSteps
|
|
103
|
-
// ---------------------------------------------------------------------------
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Group step_* events by correlationId and build Step-like entities.
|
|
107
|
-
*
|
|
108
|
-
* Handles partial event lists gracefully: a step may only have a
|
|
109
|
-
* step_created event with no completion yet. A step whose creation the World
|
|
110
|
-
* recorded on its first `step_started` (no `step_created` in the log) is
|
|
111
|
-
* anchored on that start instead.
|
|
112
|
-
*
|
|
113
|
-
* The derived status and timestamps come from the events the run acted on. A
|
|
114
|
-
* repeat of a class the log already records is read past by every replay, so
|
|
115
|
-
* a second terminal event written by a concurrent replay does not move a step
|
|
116
|
-
* off the outcome the first one recorded. Every event stays on the entity's
|
|
117
|
-
* `events` list.
|
|
118
|
-
*
|
|
119
|
-
* That reduction needs the whole log to be sound, so it only runs when
|
|
120
|
-
* `isCompleteHistory` says `events` is it. See {@link findDuplicateEventIds}.
|
|
121
|
-
*/
|
|
122
|
-
export function materializeSteps(
|
|
123
|
-
events: Event[],
|
|
124
|
-
{ isCompleteHistory = false }: { isCompleteHistory?: boolean } = {}
|
|
125
|
-
): MaterializedStep[] {
|
|
126
|
-
const groups = groupByCorrelationId(events, isStepEventType);
|
|
127
|
-
const duplicateEventIds = findDuplicateEventIds(events, {
|
|
128
|
-
isCompleteHistory,
|
|
129
|
-
});
|
|
130
|
-
const steps: MaterializedStep[] = [];
|
|
131
|
-
|
|
132
|
-
for (const [correlationId, stepEvents] of groups) {
|
|
133
|
-
// A World may record an inline step's creation on its `step_started`
|
|
134
|
-
// alone, with no `step_created` in the log. That start is then the step's
|
|
135
|
-
// creation event.
|
|
136
|
-
const created =
|
|
137
|
-
stepEvents.find((e) => e.eventType === 'step_created') ??
|
|
138
|
-
stepEvents.find((e) => e.eventType === 'step_started');
|
|
139
|
-
if (!created) continue;
|
|
140
|
-
|
|
141
|
-
let status: StepStatus = 'pending';
|
|
142
|
-
let attempt = 0;
|
|
143
|
-
let startedAt: Date | undefined;
|
|
144
|
-
let completedAt: Date | undefined;
|
|
145
|
-
let updatedAt = getEventTimestamp(created) ?? created.createdAt;
|
|
146
|
-
|
|
147
|
-
for (const e of stepEvents) {
|
|
148
|
-
if (duplicateEventIds.has(e.eventId)) continue;
|
|
149
|
-
switch (e.eventType) {
|
|
150
|
-
case 'step_started':
|
|
151
|
-
status = 'running';
|
|
152
|
-
attempt += 1;
|
|
153
|
-
if (!startedAt) startedAt = getEventTimestamp(e) ?? e.createdAt;
|
|
154
|
-
completedAt = undefined;
|
|
155
|
-
updatedAt = getEventTimestamp(e) ?? e.createdAt;
|
|
156
|
-
break;
|
|
157
|
-
case 'step_completed':
|
|
158
|
-
status = 'completed';
|
|
159
|
-
completedAt = getEventTimestamp(e) ?? e.createdAt;
|
|
160
|
-
updatedAt = getEventTimestamp(e) ?? e.createdAt;
|
|
161
|
-
break;
|
|
162
|
-
case 'step_failed':
|
|
163
|
-
status = 'failed';
|
|
164
|
-
completedAt = getEventTimestamp(e) ?? e.createdAt;
|
|
165
|
-
updatedAt = getEventTimestamp(e) ?? e.createdAt;
|
|
166
|
-
break;
|
|
167
|
-
case 'step_retrying':
|
|
168
|
-
status = 'pending';
|
|
169
|
-
completedAt = undefined;
|
|
170
|
-
updatedAt = getEventTimestamp(e) ?? e.createdAt;
|
|
171
|
-
break;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
steps.push({
|
|
176
|
-
stepId: correlationId,
|
|
177
|
-
runId: created.runId,
|
|
178
|
-
stepName:
|
|
179
|
-
created.eventType === 'step_created' ||
|
|
180
|
-
created.eventType === 'step_started'
|
|
181
|
-
? (created.eventData?.stepName ?? correlationId)
|
|
182
|
-
: correlationId,
|
|
183
|
-
status,
|
|
184
|
-
attempt,
|
|
185
|
-
createdAt: getEventTimestamp(created) ?? created.createdAt,
|
|
186
|
-
startedAt,
|
|
187
|
-
completedAt,
|
|
188
|
-
updatedAt,
|
|
189
|
-
events: stepEvents,
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
return steps;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// ---------------------------------------------------------------------------
|
|
197
|
-
// materializeHooks
|
|
198
|
-
// ---------------------------------------------------------------------------
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Group hook_* events by correlationId and build Hook-like entities.
|
|
202
|
-
*
|
|
203
|
-
* A run's start Hook has no `hook_created`: the run's creation event stands
|
|
204
|
-
* for it (see {@link findStartHookCreation}), so it is materialized from that
|
|
205
|
-
* even before anything is delivered to it.
|
|
206
|
-
*/
|
|
207
|
-
export function materializeHooks(events: Event[]): MaterializedHook[] {
|
|
208
|
-
const groups = groupByCorrelationId(events, isHookLifecycleEventType);
|
|
209
|
-
const hooks: MaterializedHook[] = [];
|
|
210
|
-
|
|
211
|
-
const startHook = findStartHookCreation(events);
|
|
212
|
-
if (startHook && !groups.has(startHook.hookId)) {
|
|
213
|
-
groups.set(startHook.hookId, []);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
for (const [correlationId, hookEvents] of groups) {
|
|
217
|
-
const created = hookEvents.find((e) => e.eventType === 'hook_created');
|
|
218
|
-
const creation = created
|
|
219
|
-
? {
|
|
220
|
-
runId: created.runId,
|
|
221
|
-
token:
|
|
222
|
-
created.eventType === 'hook_created'
|
|
223
|
-
? created.eventData?.token
|
|
224
|
-
: undefined,
|
|
225
|
-
createdAt: getEventTimestamp(created) ?? created.createdAt,
|
|
226
|
-
}
|
|
227
|
-
: correlationId === startHook?.hookId
|
|
228
|
-
? startHook
|
|
229
|
-
: undefined;
|
|
230
|
-
if (!creation) continue;
|
|
231
|
-
|
|
232
|
-
const receivedEvents = hookEvents.filter(
|
|
233
|
-
(e) => e.eventType === 'hook_received'
|
|
234
|
-
);
|
|
235
|
-
const disposed = hookEvents.find((e) => e.eventType === 'hook_disposed');
|
|
236
|
-
const lastReceived = receivedEvents.at(-1);
|
|
237
|
-
|
|
238
|
-
hooks.push({
|
|
239
|
-
hookId: correlationId,
|
|
240
|
-
runId: creation.runId,
|
|
241
|
-
token: creation.token,
|
|
242
|
-
createdAt: creation.createdAt,
|
|
243
|
-
receivedCount: receivedEvents.length,
|
|
244
|
-
lastReceivedAt: getEventTimestamp(lastReceived),
|
|
245
|
-
disposedAt: getEventTimestamp(disposed),
|
|
246
|
-
events: hookEvents,
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
return hooks;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
// ---------------------------------------------------------------------------
|
|
254
|
-
// materializeWaits
|
|
255
|
-
// ---------------------------------------------------------------------------
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
* Group wait_* events by correlationId and build Wait-like entities.
|
|
259
|
-
*/
|
|
260
|
-
export function materializeWaits(events: Event[]): MaterializedWait[] {
|
|
261
|
-
const groups = groupByCorrelationId(events, isWaitEventType);
|
|
262
|
-
const waits: MaterializedWait[] = [];
|
|
263
|
-
|
|
264
|
-
for (const [correlationId, waitEvents] of groups) {
|
|
265
|
-
const created = waitEvents.find((e) => e.eventType === 'wait_created');
|
|
266
|
-
if (!created) continue;
|
|
267
|
-
|
|
268
|
-
const completed = waitEvents.find((e) => e.eventType === 'wait_completed');
|
|
269
|
-
|
|
270
|
-
waits.push({
|
|
271
|
-
waitId: correlationId,
|
|
272
|
-
runId: created.runId,
|
|
273
|
-
status: completed ? 'completed' : 'waiting',
|
|
274
|
-
createdAt: getEventTimestamp(created) ?? created.createdAt,
|
|
275
|
-
resumeAt:
|
|
276
|
-
created.eventType === 'wait_created'
|
|
277
|
-
? created.eventData?.resumeAt
|
|
278
|
-
: undefined,
|
|
279
|
-
completedAt: getEventTimestamp(completed),
|
|
280
|
-
events: waitEvents,
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
return waits;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
// ---------------------------------------------------------------------------
|
|
288
|
-
// materializeAll
|
|
289
|
-
// ---------------------------------------------------------------------------
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* Convenience function that materializes all entity types from a flat
|
|
293
|
-
* event list.
|
|
294
|
-
*/
|
|
295
|
-
export function materializeAll(
|
|
296
|
-
events: Event[],
|
|
297
|
-
options: { isCompleteHistory?: boolean } = {}
|
|
298
|
-
): MaterializedEntities {
|
|
299
|
-
return {
|
|
300
|
-
steps: materializeSteps(events, options),
|
|
301
|
-
hooks: materializeHooks(events),
|
|
302
|
-
waits: materializeWaits(events),
|
|
303
|
-
};
|
|
304
|
-
}
|