@workflow/web-shared 5.0.5 → 5.0.6

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 (31) hide show
  1. package/dist/components/event-list-view.d.ts.map +1 -1
  2. package/dist/components/event-list-view.js +14 -4
  3. package/dist/components/sidebar/attribute-panel.d.ts.map +1 -1
  4. package/dist/components/sidebar/attribute-panel.js +9 -2
  5. package/dist/components/workflow-traces/trace-span-construction.d.ts.map +1 -1
  6. package/dist/components/workflow-traces/trace-span-construction.js +8 -4
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +2 -1
  10. package/dist/lib/duplicate-events.d.ts +6 -6
  11. package/dist/lib/duplicate-events.d.ts.map +1 -1
  12. package/dist/lib/duplicate-events.js +18 -18
  13. package/dist/lib/event-materialization.d.ts +3 -1
  14. package/dist/lib/event-materialization.d.ts.map +1 -1
  15. package/dist/lib/event-materialization.js +11 -4
  16. package/dist/lib/run-limit-guidance.d.ts +43 -0
  17. package/dist/lib/run-limit-guidance.d.ts.map +1 -0
  18. package/dist/lib/run-limit-guidance.js +72 -0
  19. package/package.json +4 -4
  20. package/src/components/event-list-view.test.ts +51 -0
  21. package/src/components/event-list-view.tsx +16 -3
  22. package/src/components/sidebar/attribute-panel.tsx +10 -1
  23. package/src/components/workflow-traces/trace-span-construction.test.ts +28 -0
  24. package/src/components/workflow-traces/trace-span-construction.ts +10 -3
  25. package/src/index.ts +7 -0
  26. package/src/lib/duplicate-events.test.ts +8 -11
  27. package/src/lib/duplicate-events.ts +18 -16
  28. package/src/lib/event-materialization.test.ts +19 -0
  29. package/src/lib/event-materialization.ts +11 -3
  30. package/src/lib/run-limit-guidance.test.ts +90 -0
  31. package/src/lib/run-limit-guidance.ts +111 -0
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Guidance for runs that failed because they outgrew the default per-run
3
+ * event limit or replay budget. Pure (no React) so every observability UI
4
+ * (the self-hosted web UI and the Vercel dashboard) can share the decision
5
+ * and the copy while rendering it with its own components.
6
+ */
7
+
8
+ /** Error codes this guidance applies to (`RUN_ERROR_CODES` values). */
9
+ const MAX_EVENTS_EXCEEDED = 'MAX_EVENTS_EXCEEDED';
10
+ const REPLAY_TIMEOUT = 'REPLAY_TIMEOUT';
11
+
12
+ const DOCS_BASE_URL = 'https://workflow-sdk.dev/err';
13
+
14
+ export type RunLimitGuidanceKind = 'max-events-exceeded' | 'replay-timeout';
15
+
16
+ export interface RunLimitGuidance {
17
+ kind: RunLimitGuidanceKind;
18
+ /** Short heading, e.g. for an alert title. */
19
+ title: string;
20
+ /** One or two sentences explaining what to do. Plain text. */
21
+ description: string;
22
+ /** The env var assignment to suggest, for rendering as code. */
23
+ envVar: string;
24
+ /** Docs page for the error code. */
25
+ docsUrl: string;
26
+ }
27
+
28
+ /**
29
+ * The run fields this guidance reads. Accepts both a hydrated run (where
30
+ * `hydrateResourceIO` lifts `workflowVm` / `snapshotThreshold` out of the
31
+ * stripped `executionContext`) and a raw run (with `executionContext`).
32
+ */
33
+ export interface RunLimitGuidanceInput {
34
+ status?: string;
35
+ errorCode?: string | null;
36
+ workflowVm?: unknown;
37
+ snapshotThreshold?: unknown;
38
+ executionContext?: unknown;
39
+ }
40
+
41
+ function readVmPolicy(run: RunLimitGuidanceInput): {
42
+ workflowVm: unknown;
43
+ snapshotThreshold: unknown;
44
+ } {
45
+ const ctx =
46
+ run.executionContext && typeof run.executionContext === 'object'
47
+ ? (run.executionContext as Record<string, unknown>)
48
+ : undefined;
49
+ return {
50
+ workflowVm: run.workflowVm ?? ctx?.workflowVm,
51
+ snapshotThreshold: run.snapshotThreshold ?? ctx?.snapshotThreshold,
52
+ };
53
+ }
54
+
55
+ /**
56
+ * Whether the run was started on the QuickJS VM with snapshotting enabled,
57
+ * which exempts it from the default per-run event limit. Mirrors the World
58
+ * policy (`isEventLimitExemptRun` in `@workflow/world`).
59
+ */
60
+ export function isQuickJSSnapshotRun(run: RunLimitGuidanceInput): boolean {
61
+ const { workflowVm, snapshotThreshold } = readVmPolicy(run);
62
+ return (
63
+ workflowVm === 'quickjs' &&
64
+ typeof snapshotThreshold === 'number' &&
65
+ Number.isSafeInteger(snapshotThreshold) &&
66
+ snapshotThreshold > 0
67
+ );
68
+ }
69
+
70
+ /**
71
+ * Returns guidance to show for a failed run whose error code is
72
+ * `MAX_EVENTS_EXCEEDED` or `REPLAY_TIMEOUT` and that wasn't already running
73
+ * on the QuickJS VM with snapshotting. Returns `null` otherwise.
74
+ */
75
+ export function getRunLimitGuidance(
76
+ run: RunLimitGuidanceInput | null | undefined
77
+ ): RunLimitGuidance | null {
78
+ if (!run || run.status !== 'failed') return null;
79
+ const code = run.errorCode;
80
+ if (code !== MAX_EVENTS_EXCEEDED && code !== REPLAY_TIMEOUT) return null;
81
+ // Already on the recommended configuration; switching wouldn't help.
82
+ if (isQuickJSSnapshotRun(run)) return null;
83
+
84
+ const { workflowVm } = readVmPolicy(run);
85
+ const onQuickJS = workflowVm === 'quickjs';
86
+
87
+ const remediation = onQuickJS
88
+ ? "This run used the QuickJS VM, but a snapshot threshold wasn't recorded when it started (snapshotting was disabled, or the run was started by an older SDK), so the default event limit applied. Set a positive WORKFLOW_SNAPSHOT_THRESHOLD in the environment that starts runs, or upgrade the workflow package, so new runs are exempt."
89
+ : 'Run long-running workflows on the QuickJS VM with snapshotting. Snapshotted runs resume without replaying the full event log and are exempt from the default per-run event limit. Set this in the environment that starts runs; only new runs are affected.';
90
+
91
+ if (code === MAX_EVENTS_EXCEEDED) {
92
+ return {
93
+ kind: 'max-events-exceeded',
94
+ title: 'This run reached the per-run event limit',
95
+ description: remediation,
96
+ envVar: onQuickJS
97
+ ? 'WORKFLOW_SNAPSHOT_THRESHOLD=1000'
98
+ : 'WORKFLOW_VM=quickjs',
99
+ docsUrl: `${DOCS_BASE_URL}/max-events-exceeded`,
100
+ };
101
+ }
102
+ return {
103
+ kind: 'replay-timeout',
104
+ title: 'This run exceeded the workflow replay time limit',
105
+ description: `Replay time grows with the size of the event log. ${remediation}`,
106
+ envVar: onQuickJS
107
+ ? 'WORKFLOW_SNAPSHOT_THRESHOLD=1000'
108
+ : 'WORKFLOW_VM=quickjs',
109
+ docsUrl: `${DOCS_BASE_URL}/replay-timeout`,
110
+ };
111
+ }