@brickkit/cli 0.12.0 → 0.13.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 (119) hide show
  1. package/dashboard-dist/{api-reference-B-bZRtNV.js → api-reference-mT9VNcPb.js} +69 -69
  2. package/dashboard-dist/app.js +12 -13
  3. package/dashboard-dist/{client-BJJtVSVr.js → client-CwATkLJa.js} +1 -1
  4. package/dashboard-dist/{core-Z7NJFk0K.js → core-BEUWp6B5.js} +1 -1
  5. package/dashboard-dist/docs-BRrtyxDB.js +4 -0
  6. package/dashboard-dist/kit.js +1 -1
  7. package/dashboard-dist/popover-Bj9x-88h.js +1 -0
  8. package/dist/bin.js +154 -217
  9. package/dist/bin.js.map +1 -1
  10. package/dist/build.js +463 -0
  11. package/dist/build.js.map +1 -0
  12. package/dist/client-contract-file.js +356 -1
  13. package/dist/client-contract-file.js.map +1 -0
  14. package/dist/compiler.d.ts +12 -2
  15. package/dist/compiler2.js +12 -5
  16. package/dist/compiler2.js.map +1 -1
  17. package/dist/config.d.ts +3 -0
  18. package/dist/config.js +1 -250
  19. package/dist/config2.d.ts +122 -0
  20. package/dist/config2.js +207 -0
  21. package/dist/config2.js.map +1 -0
  22. package/dist/dashboard-extension.d.ts +3 -0
  23. package/dist/{dev-telemetry-store.js → dashboard-host.js} +1533 -1574
  24. package/dist/dashboard-host.js.map +1 -0
  25. package/dist/dashboard-protocol.js +189 -0
  26. package/dist/dashboard-protocol.js.map +1 -0
  27. package/dist/dashboard.d.ts +4 -1
  28. package/dist/definitions.js +33 -0
  29. package/dist/definitions.js.map +1 -0
  30. package/dist/dev-application.js +34 -0
  31. package/dist/dev-application.js.map +1 -0
  32. package/dist/dev-protocol.js +21 -0
  33. package/dist/dev-protocol.js.map +1 -0
  34. package/dist/dev-reporter.js +2 -1
  35. package/dist/dev-reporter.js.map +1 -1
  36. package/dist/dev-telemetry.js +5 -20
  37. package/dist/dev-telemetry.js.map +1 -1
  38. package/dist/dev-worker.js +79 -19
  39. package/dist/dev-worker.js.map +1 -1
  40. package/dist/index.d.ts +15 -74
  41. package/dist/index.js +12 -5
  42. package/dist/index.js.map +1 -0
  43. package/dist/lint/oxlint.js +5 -3
  44. package/dist/lint/oxlint.js.map +1 -1
  45. package/dist/own-module.js +7 -0
  46. package/dist/own-module.js.map +1 -0
  47. package/dist/plugin.d.ts +6 -5
  48. package/dist/plugin.js +5 -39
  49. package/dist/plugin.js.map +1 -1
  50. package/dist/production-dashboard.d.ts +2 -0
  51. package/dist/production-dashboard.js +51 -0
  52. package/dist/production-dashboard.js.map +1 -0
  53. package/dist/production-dashboard2.d.ts +34 -0
  54. package/dist/{presets.js → project.js} +104 -106
  55. package/dist/project.js.map +1 -0
  56. package/dist/serve.d.ts +24 -0
  57. package/dist/serve.js +1 -0
  58. package/dist/serve2.js +49 -0
  59. package/dist/serve2.js.map +1 -0
  60. package/dist/vite.js +26 -47
  61. package/dist/vite.js.map +1 -1
  62. package/dist/workflows.d.ts +2 -2
  63. package/dist/workflows2.js +59 -37
  64. package/dist/workflows2.js.map +1 -1
  65. package/inspector-dist/client/assets/app-CeSwVsRm.css +2 -0
  66. package/inspector-dist/client/assets/{highlighted-body-B3W2YXNL-DYVdwGy2.js → highlighted-body-B3W2YXNL-CfRnuITN.js} +1 -1
  67. package/inspector-dist/client/assets/{home-CyjkvtII.js → home-hwPlkNhv.js} +1529 -378
  68. package/inspector-dist/client/assets/manifest-0e76e9ac.js +1 -0
  69. package/inspector-dist/client/assets/mermaid-3ZIDBTTL-ZDR2PNY_.js +1 -0
  70. package/inspector-dist/client/assets/root-ChBNTZd2.css +2 -0
  71. package/inspector-dist/client/assets/{root-DX9wtogx.js → root-SLeEf-sT.js} +17 -29
  72. package/inspector-dist/client/assets/{run-detail-C69EJGql.js → run-detail-DYbVkIFH.js} +398 -76
  73. package/inspector-dist/client/assets/{tabs-B6B88IjT.js → tabs-CaJisoyb.js} +189 -2130
  74. package/inspector-dist/client/assets/{zstd-browser-decoder-ByUgcY9H.js → zstd-browser-decoder-D94wmfAU.js} +1 -1
  75. package/inspector-dist/server/assets/{app-WoDoT62X.js → app-DGlfWVUI.js} +69783 -70608
  76. package/inspector-dist/server/assets/{chunk-RLXIAIE6-CbvDIAEa.js → chunk-RLXIAIE6-F0SJZlei.js} +4 -6
  77. package/inspector-dist/server/assets/{dist-qR-969AD.js → dist-BCbwm6jl.js} +2 -4
  78. package/inspector-dist/server/assets/{dist-CQnQcIJg.js → dist-CG2aVufI.js} +0 -2
  79. package/inspector-dist/server/assets/{dist-BRxZSWUN.js → dist-Ce0I2PUv.js} +2 -5
  80. package/inspector-dist/server/assets/{dist-DqRd9pyS.js → dist-DY0UlahA.js} +0 -2
  81. package/inspector-dist/server/assets/{encryption-_PuklZNX.js → encryption-DdQgC8Rk.js} +2 -4
  82. package/inspector-dist/server/assets/{event-metadata-BVakQJ_y.js → event-metadata-n7E4zEmT.js} +0 -2
  83. package/inspector-dist/server/assets/{functions-CImcpqNl.js → functions-CNVQtbgg.js} +2 -4
  84. package/inspector-dist/server/assets/{global-singleton-CPirHxFh.js → global-singleton-D8sIN5du.js} +0 -2
  85. package/inspector-dist/server/assets/{highlighted-body-B3W2YXNL-fPMB_t7F.js → highlighted-body-B3W2YXNL-CWRzMxYD.js} +2 -4
  86. package/inspector-dist/server/assets/mermaid-3ZIDBTTL-D0v0ngVr.js +1 -0
  87. package/inspector-dist/server/assets/{parse-D9Vvgzt9.js → parse-Begau9cA.js} +0 -2
  88. package/inspector-dist/server/assets/{rolldown-runtime-CLg409Sh.js → rolldown-runtime-C1I3wEg2.js} +1 -2
  89. package/inspector-dist/server/assets/{serialization-format-DDtsVTU1.js → serialization-format-BbuGfHog.js} +6 -8
  90. package/inspector-dist/server/assets/{token-BW4GdQZh.js → token-BgMmJNP5.js} +2 -4
  91. package/inspector-dist/server/assets/{token-D6FXdkJT.js → token-BrUX0bxz.js} +2 -4
  92. package/inspector-dist/server/assets/{token-util-BoNmi-wE.js → token-util-DZN32qmT.js} +1 -3
  93. package/inspector-dist/server/assets/{wrapper-wiqsGXcE.js → wrapper-CIC3w0oC.js} +1 -3
  94. package/inspector-dist/server/assets/{ws-transport-DV7oG4mL.js → ws-transport-CxTYB11n.js} +24094 -24096
  95. package/inspector-dist/server/assets/{zstd-browser-decoder-Cswf0KO6.js → zstd-browser-decoder-D7bCXbGg.js} +2 -4
  96. package/inspector-dist/server/index.js +1 -3
  97. package/package.json +12 -2
  98. package/dashboard-dist/docs-Dpfc0wJb.js +0 -4
  99. package/dashboard-dist/popover-BzejBolB.js +0 -1
  100. package/dist/app-entry.js +0 -1
  101. package/dist/app-entry2.js +0 -18
  102. package/dist/app-entry2.js.map +0 -1
  103. package/dist/client-contract-file2.js +0 -33
  104. package/dist/client-contract-file2.js.map +0 -1
  105. package/dist/client-contract.js +0 -1
  106. package/dist/client-contract2.js +0 -296
  107. package/dist/client-contract2.js.map +0 -1
  108. package/dist/config.js.map +0 -1
  109. package/dist/dev-telemetry-store.js.map +0 -1
  110. package/dist/emit.d.ts +0 -5
  111. package/dist/presets.js.map +0 -1
  112. package/dist/runner.js +0 -519
  113. package/dist/runner.js.map +0 -1
  114. package/inspector-dist/client/assets/app-CCzpuUz_.css +0 -2
  115. package/inspector-dist/client/assets/manifest-ba30b52d.js +0 -1
  116. package/inspector-dist/client/assets/mermaid-3ZIDBTTL-Dy6IVqPy.js +0 -1
  117. package/inspector-dist/client/assets/root-8BMab1lL.css +0 -2
  118. package/inspector-dist/client/assets/world-config-context-C3BqXPIv.js +0 -30
  119. package/inspector-dist/server/assets/mermaid-3ZIDBTTL-bADXySE3.js +0 -3
@@ -1,5 +1,5 @@
1
1
  import { F as require_react, M as withComponentProps, O as useNavigate, R as __toESM, j as useSearchParams, k as useParams, r as Link, t as require_jsx_runtime } from "./jsx-runtime-CPEah4WQ.js";
2
- import { $t as parseWorkflowName, A as fetchEventsByCorrelationId, At as buttonVariants, B as Portal, Bt as ErrorBoundary, D as unwrapServerActionResult, Dt as TooltipTrigger, E as getErrorTitle, Et as TooltipContent, Ft as isEncryptedData, J as FocusScopeBranchProvider, K as useId, L as ReactRemoveScroll, M as getEncryptionKeyForRun, Mt as getWebRevivers, Nt as hydrateResourceIOAsync, O as fetchEvent, Ot as DecryptButton, Pt as hydrateData, Q as useDismissableLayerSurface, Qt as createLucideIcon, R as hideOthers, Rt as decrypt, T as getErrorMessage, Tt as Tooltip, Ut as Lock, X as useFocusGuards, Y as useFocusScopeBranchRegistry, Yt as ChevronRight, Z as DismissableLayer, _ as wakeUpRun, a as RunActionsButtons, at as useLayoutEffect2, b as useWorkflowTraceViewerData, c as Skeleton, ct as composeEventHandlers, dt as AlertTitle, f as cancelRun, ft as LIVE_UPDATE_INTERVAL_MS, g as resumeHook, gt as StreamViewerSkeleton, ht as StreamViewer, i as TabsTrigger, it as useControllableState, jt as Slot$1, k as fetchEvents, l as RelativeTime, lt as Alert, m as recreateRun, mt as TraceViewer, n as TabsContent, nt as Primitive, ot as createContextScope, pt as cn, q as FocusScope, qt as CircleAlert, r as TabsList, rt as createSlot, s as StatusBadge, st as useComposedRefs, t as Tabs, u as CopyableText, ut as AlertDescription, v as useWorkflowStreams, wt as EventListView, x as fetchSpanDetailResource, y as readStream, z as Presence, zt as deriveRunPayloadKeys } from "./tabs-B6B88IjT.js";
2
+ import { $ as LIVE_UPDATE_INTERVAL_MS$1, At as deriveRunPayloadKeys, Bt as ChevronRight, Ct as hydrateResourceIO, D as Portal, E as Presence, Et as isEncryptedData, F as FocusScopeBranchProvider, G as useControllableState, I as useFocusScopeBranchRegistry, J as useComposedRefs, K as useLayoutEffect2, L as useFocusGuards, N as useId, P as FocusScope, Pt as Lock, Q as AlertTitle, R as DismissableLayer, Rt as CircleAlert, St as hasEncryptedFields, T as hideOthers, Tt as hydrateData, U as Primitive, Ut as createLucideIcon, W as createSlot, Wt as parseWorkflowName, X as Alert, Y as composeEventHandlers, Z as AlertDescription, _ as unwrapOrThrow, _t as DecryptButton, a as RunActionsButtons, at as StreamViewerSkeleton, bt as Slot$1, d as rpc, et as cn, f as API_PATHS, g as getErrorMessage, gt as TooltipTrigger, h as WorkflowWebAPIError, ht as TooltipContent, i as TabsTrigger, it as StreamViewer, jt as ErrorBoundary, kt as decrypt, l as Skeleton, m as STREAM_DONE_HEADER, mt as Tooltip, n as TabsContent, nt as TraceViewer, p as STREAM_CURSOR_HEADER, pt as EventListView, q as createContextScope, r as TabsList, rt as waitEventsToWaitEntity, s as StatusBadge, t as Tabs, u as RelativeTime, v as unwrapServerActionResult, w as ReactRemoveScroll, wt as hydrateResourceIOAsync, xt as getWebRevivers, y as CopyableText, yt as buttonVariants, z as useDismissableLayerSurface } from "./tabs-CaJisoyb.js";
3
3
  import { n as toast } from "./dist-BK8w6xOr.js";
4
4
  /**
5
5
  * @license lucide-react v0.575.0 - ISC
@@ -567,14 +567,15 @@ function getCancellationReason(events) {
567
567
  * Reads the cancellation reason from loaded trace events, falling back to the
568
568
  * terminal event for long runs whose initial trace page does not include it.
569
569
  */
570
- function useCancellationReason(env, runId, status, events) {
570
+ function useCancellationReason(runId, status, events) {
571
571
  const loadedReason = (0, import_react.useMemo)(() => getCancellationReason(events), [events]);
572
572
  const [terminalReason, setTerminalReason] = (0, import_react.useState)();
573
573
  (0, import_react.useEffect)(() => {
574
574
  setTerminalReason(void 0);
575
575
  if (status !== "cancelled" || loadedReason) return;
576
576
  let ignore = false;
577
- unwrapServerActionResult(fetchEvents(env, runId, {
577
+ unwrapServerActionResult(rpc("fetchEvents", {
578
+ runId,
578
579
  sortOrder: "desc",
579
580
  limit: 1,
580
581
  withData: false
@@ -585,7 +586,6 @@ function useCancellationReason(env, runId, status, events) {
585
586
  ignore = true;
586
587
  };
587
588
  }, [
588
- env,
589
589
  runId,
590
590
  status,
591
591
  loadedReason
@@ -593,15 +593,13 @@ function useCancellationReason(env, runId, status, events) {
593
593
  return loadedReason ?? terminalReason;
594
594
  }
595
595
  // app/lib/client/hooks/use-events-list-data.ts
596
- var INITIAL_PAGE_SIZE = 100;
597
- var LOAD_MORE_PAGE_SIZE = 100;
596
+ var INITIAL_PAGE_SIZE$1 = 100;
597
+ var LOAD_MORE_PAGE_SIZE$1 = 100;
598
598
  /**
599
599
  * Max pages when fetching correlation ID search results (100 events/page).
600
600
  *
601
- * Kept low for the storage read path, which filters server-side and so can
602
- * cost considerably more to produce a page than the page returns. The
603
- * previous 30 was sized for the analytics path, where the same scan was
604
- * much cheaper.
601
+ * Kept low: the world filters server-side, so a page can cost considerably
602
+ * more to produce than it returns.
605
603
  */
606
604
  var MAX_CORRELATION_SEARCH_PAGES = 5;
607
605
  /**
@@ -609,7 +607,7 @@ var MAX_CORRELATION_SEARCH_PAGES = 5;
609
607
  * Separate from the trace viewer's events so sort order changes
610
608
  * don't affect the trace viewer.
611
609
  */
612
- function useEventsListData(env, runId, options = {}) {
610
+ function useEventsListData(runId, options = {}) {
613
611
  const { sortOrder = "asc", encryptionKey, enabled = true } = options;
614
612
  const [events, setEvents] = (0, import_react.useState)([]);
615
613
  const [loading, setLoading] = (0, import_react.useState)(true);
@@ -633,9 +631,10 @@ function useEventsListData(env, runId, options = {}) {
633
631
  setCursor(void 0);
634
632
  setHasMore(false);
635
633
  try {
636
- const { error: fetchError, result } = await unwrapServerActionResult(fetchEvents(env, runId, {
634
+ const { error: fetchError, result } = await unwrapServerActionResult(rpc("fetchEvents", {
635
+ runId,
637
636
  sortOrder,
638
- limit: INITIAL_PAGE_SIZE,
637
+ limit: INITIAL_PAGE_SIZE$1,
639
638
  withData: false
640
639
  }));
641
640
  if (fetchError) setError(fetchError);
@@ -651,7 +650,6 @@ function useEventsListData(env, runId, options = {}) {
651
650
  isFetchingRef.current = false;
652
651
  }
653
652
  }, [
654
- env,
655
653
  runId,
656
654
  sortOrder,
657
655
  hydrateEvents
@@ -679,10 +677,11 @@ function useEventsListData(env, runId, options = {}) {
679
677
  if (loadingMore || !cursor) return;
680
678
  setLoadingMore(true);
681
679
  try {
682
- const { error: fetchError, result } = await unwrapServerActionResult(fetchEvents(env, runId, {
680
+ const { error: fetchError, result } = await unwrapServerActionResult(rpc("fetchEvents", {
681
+ runId,
683
682
  cursor,
684
683
  sortOrder,
685
- limit: LOAD_MORE_PAGE_SIZE,
684
+ limit: LOAD_MORE_PAGE_SIZE$1,
686
685
  withData: false
687
686
  }));
688
687
  if (fetchError) setError(fetchError);
@@ -700,7 +699,6 @@ function useEventsListData(env, runId, options = {}) {
700
699
  setLoadingMore(false);
701
700
  }
702
701
  }, [
703
- env,
704
702
  runId,
705
703
  sortOrder,
706
704
  cursor,
@@ -710,7 +708,11 @@ function useEventsListData(env, runId, options = {}) {
710
708
  searchByExactId: (0, import_react.useCallback)(async (id, kind, signal) => {
711
709
  if (signal?.aborted) throw new DOMException("Aborted", "AbortError");
712
710
  if (kind === "event") {
713
- const { error: fetchError, result } = await unwrapServerActionResult(fetchEvent(env, runId, id, "none"));
711
+ const { error: fetchError, result } = await unwrapServerActionResult(rpc("fetchEvent", {
712
+ runId,
713
+ eventId: id,
714
+ resolveData: "none"
715
+ }));
714
716
  if (fetchError || signal?.aborted) return fetchError ? {
715
717
  status: "error",
716
718
  message: fetchError.message
@@ -729,7 +731,8 @@ function useEventsListData(env, runId, options = {}) {
729
731
  let truncated = false;
730
732
  do {
731
733
  if (signal?.aborted) throw new DOMException("Aborted", "AbortError");
732
- const { error: fetchError, result } = await unwrapServerActionResult(fetchEventsByCorrelationId(env, id, {
734
+ const { error: fetchError, result } = await unwrapServerActionResult(rpc("fetchEventsByCorrelationId", {
735
+ correlationId: id,
733
736
  cursor: nextCursor,
734
737
  sortOrder,
735
738
  limit: 100,
@@ -754,13 +757,51 @@ function useEventsListData(env, runId, options = {}) {
754
757
  truncated: truncated || void 0
755
758
  } : { status: "not_found" };
756
759
  }, [
757
- env,
758
760
  runId,
759
761
  sortOrder,
760
762
  hydrateEvents
761
763
  ])
762
764
  };
763
765
  }
766
+ // app/lib/client/workflow-streams.ts
767
+ function isServerActionError(value) {
768
+ return typeof value === "object" && value !== null && "message" in value && "layer" in value;
769
+ }
770
+ async function readStream(streamId, runId, signal, cursor) {
771
+ try {
772
+ const params = new URLSearchParams({ runId });
773
+ if (cursor) params.set("cursor", cursor);
774
+ const url = `/workflows/${API_PATHS.stream}${encodeURIComponent(streamId)}?${params.toString()}`;
775
+ const response = await fetch(url, { signal });
776
+ if (!response.ok) {
777
+ const errorData = await response.json().catch(() => null);
778
+ if (errorData && isServerActionError(errorData)) throw new WorkflowWebAPIError(errorData.message, {
779
+ layer: "client",
780
+ cause: errorData.cause,
781
+ request: errorData.request
782
+ });
783
+ throw new WorkflowWebAPIError(`Failed to read stream: ${response.status}`, { layer: "client" });
784
+ }
785
+ if (!response.body) throw new WorkflowWebAPIError("Failed to read stream: no body", { layer: "client" });
786
+ const responseCursor = response.headers.get(STREAM_CURSOR_HEADER);
787
+ const streamDone = response.headers.get(STREAM_DONE_HEADER) === "true";
788
+ return {
789
+ body: response.body,
790
+ cursor: responseCursor,
791
+ done: streamDone
792
+ };
793
+ } catch (error) {
794
+ if (error instanceof WorkflowWebAPIError) throw error;
795
+ throw new WorkflowWebAPIError("Failed to read stream", {
796
+ layer: "client",
797
+ cause: error
798
+ });
799
+ }
800
+ }
801
+ /** List all stream IDs for a run */
802
+ async function listStreams(runId) {
803
+ return unwrapOrThrow(rpc("fetchStreams", { runId }));
804
+ }
764
805
  // app/lib/hooks/use-stream-reader.ts
765
806
  var FRAME_HEADER_SIZE = 4;
766
807
  var ENCRYPTED_PLACEHOLDER = "[Encrypted]";
@@ -776,14 +817,13 @@ function detectEncoding(data) {
776
817
  if (len > 0 && len <= 10485760) return "framed";
777
818
  return "legacy";
778
819
  }
779
- function useStreamReader(env, streamId, runId, encryptionKey, runStatus) {
820
+ function useStreamReader(streamId, runId, encryptionKey, runStatus) {
780
821
  const [chunks, setChunks] = (0, import_react.useState)([]);
781
822
  const [isLive, setIsLive] = (0, import_react.useState)(false);
782
823
  const [isInitialLoading, setIsInitialLoading] = (0, import_react.useState)(Boolean(streamId && runId));
783
824
  const [error, setError] = (0, import_react.useState)(null);
784
825
  const abortControllerRef = (0, import_react.useRef)(null);
785
826
  const chunkIdRef = (0, import_react.useRef)(0);
786
- const frameCountRef = (0, import_react.useRef)(0);
787
827
  const pollTimerRef = (0, import_react.useRef)(null);
788
828
  const runStatusRef = (0, import_react.useRef)(runStatus);
789
829
  runStatusRef.current = runStatus;
@@ -817,7 +857,6 @@ function useStreamReader(env, streamId, runId, encryptionKey, runStatus) {
817
857
  setIsLive(false);
818
858
  setIsInitialLoading(Boolean(streamId && runId));
819
859
  chunkIdRef.current = 0;
820
- frameCountRef.current = 0;
821
860
  serverCursorRef.current = null;
822
861
  if (pollTimerRef.current) {
823
862
  clearTimeout(pollTimerRef.current);
@@ -847,19 +886,16 @@ function useStreamReader(env, streamId, runId, encryptionKey, runStatus) {
847
886
  /**
848
887
  * Fetch stream data and parse frames.
849
888
  *
850
- * When `cursor` is provided, the server only returns chunks after that
851
- * position (incremental fetch). `skipFrames` skips N frames from the
852
- * response to handle the overlap from cursor-based pagination.
889
+ * When `cursor` is provided, the server only returns chunks written after
890
+ * the response that gave it (incremental fetch).
853
891
  */
854
- const fetchAndParse = async (targetBuffer, cryptoKey, options) => {
855
- const streamResponse = await readStream(env, streamId, runId, abortController.signal, options?.cursor);
856
- const skipFrames = options?.skipFrames ?? 0;
892
+ const fetchAndParse = async (targetBuffer, cryptoKey, cursor) => {
893
+ const streamResponse = await readStream(streamId, runId, abortController.signal, cursor);
857
894
  const reader = streamResponse.body.getReader();
858
895
  const decoder = new TextDecoder();
859
896
  let buffer = /* @__PURE__ */ new Uint8Array(0);
860
897
  let encoding = null;
861
898
  let textRemainder = "";
862
- let frameIndex = 0;
863
899
  const appendToBuffer = (data) => {
864
900
  const newBuffer = new Uint8Array(buffer.length + data.length);
865
901
  newBuffer.set(buffer, 0);
@@ -871,8 +907,7 @@ function useStreamReader(env, streamId, runId, encryptionKey, runStatus) {
871
907
  const { value, done } = await reader.read();
872
908
  if (done) {
873
909
  if (encoding === "legacy" && textRemainder.trim()) {
874
- frameIndex++;
875
- if (frameIndex > skipFrames) targetBuffer.push(parseLegacyLine(textRemainder.trim()));
910
+ targetBuffer.push(parseLegacyLine(textRemainder.trim()));
876
911
  textRemainder = "";
877
912
  }
878
913
  break;
@@ -891,10 +926,7 @@ function useStreamReader(env, streamId, runId, encryptionKey, runStatus) {
891
926
  textRemainder = lines.pop() ?? "";
892
927
  for (const line of lines) {
893
928
  const trimmed = line.trim();
894
- if (trimmed) {
895
- frameIndex++;
896
- if (frameIndex > skipFrames) targetBuffer.push(parseLegacyLine(trimmed));
897
- }
929
+ if (trimmed) targetBuffer.push(parseLegacyLine(trimmed));
898
930
  }
899
931
  continue;
900
932
  }
@@ -906,8 +938,6 @@ function useStreamReader(env, streamId, runId, encryptionKey, runStatus) {
906
938
  if (offset + FRAME_HEADER_SIZE + frameLength > buffer.length) break;
907
939
  const frameData = buffer.slice(offset + FRAME_HEADER_SIZE, offset + FRAME_HEADER_SIZE + frameLength);
908
940
  offset += FRAME_HEADER_SIZE + frameLength;
909
- frameIndex++;
910
- if (frameIndex <= skipFrames) continue;
911
941
  const result = await processFrame(frameData, cryptoKey, revivers);
912
942
  if (result.encrypted) {
913
943
  reader.cancel().catch(() => {});
@@ -924,7 +954,6 @@ function useStreamReader(env, streamId, runId, encryptionKey, runStatus) {
924
954
  }
925
955
  return {
926
956
  encrypted: false,
927
- frameCount: frameIndex,
928
957
  cursor: streamResponse.cursor,
929
958
  done: streamResponse.done
930
959
  };
@@ -942,7 +971,6 @@ function useStreamReader(env, streamId, runId, encryptionKey, runStatus) {
942
971
  }
943
972
  return;
944
973
  }
945
- frameCountRef.current = result.frameCount;
946
974
  serverCursorRef.current = result.cursor;
947
975
  if (!mounted || abortController.signal.aborted) return;
948
976
  setChunks(initialChunks);
@@ -957,12 +985,8 @@ function useStreamReader(env, streamId, runId, encryptionKey, runStatus) {
957
985
  if (!mounted || abortController.signal.aborted) return;
958
986
  try {
959
987
  const newChunks = [];
960
- const pollResult = await fetchAndParse(newChunks, cryptoKey, {
961
- cursor: serverCursorRef.current,
962
- skipFrames: frameCountRef.current
963
- });
988
+ const pollResult = await fetchAndParse(newChunks, cryptoKey, serverCursorRef.current);
964
989
  if (!pollResult.encrypted) {
965
- frameCountRef.current = pollResult.frameCount;
966
990
  if (pollResult.cursor) serverCursorRef.current = pollResult.cursor;
967
991
  if (newChunks.length > 0 && mounted) setChunks((prev) => [...prev, ...newChunks]);
968
992
  if (pollResult.done) {
@@ -996,7 +1020,6 @@ function useStreamReader(env, streamId, runId, encryptionKey, runStatus) {
996
1020
  }
997
1021
  };
998
1022
  }, [
999
- env,
1000
1023
  streamId,
1001
1024
  runId,
1002
1025
  encryptionKey,
@@ -1025,16 +1048,311 @@ function LiveStatus({ hasError, errorMessage }) {
1025
1048
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1026
1049
  className: "flex items-center gap-1.5",
1027
1050
  children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: `w-2 h-2 rounded-full ${hasError ? "bg-red-500" : "bg-green-500 animate-pulse"}` }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
1028
- className: `text-xs $
1029
- hasError
1030
- ? 'text-red-600 dark:text-red-400'
1031
- : 'text-muted-foreground'`,
1051
+ className: `text-xs ${hasError ? "text-red-600 dark:text-red-400" : "text-muted-foreground"}`,
1032
1052
  children: hasError ? "Error" : "Live"
1033
1053
  })]
1034
1054
  })
1035
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipContent, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: hasError ? `Error updating data: ${errorMessage}` : `Content updates every ${LIVE_UPDATE_INTERVAL_MS / 1e3} seconds` }) })] })
1055
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipContent, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: hasError ? `Error updating data: ${errorMessage}` : `Content updates every ${LIVE_UPDATE_INTERVAL_MS$1 / 1e3} seconds` }) })] })
1036
1056
  });
1037
1057
  }
1058
+ // app/lib/client/hooks/use-resource-data.ts
1059
+ async function fetchResourceWithCorrelationId(resource, resourceId, options = {}) {
1060
+ const resolveData = options.resolveData ?? "all";
1061
+ let resourceData;
1062
+ let correlationId;
1063
+ if (resource === "run") {
1064
+ resourceData = await unwrapOrThrow(rpc("fetchRun", {
1065
+ runId: resourceId,
1066
+ resolveData
1067
+ }));
1068
+ correlationId = resourceData.runId;
1069
+ } else if (resource === "step") {
1070
+ const { runId } = options;
1071
+ if (!runId) throw new WorkflowWebAPIError("runId is required for step resource", { layer: "client" });
1072
+ resourceData = await unwrapOrThrow(rpc("fetchStep", {
1073
+ runId,
1074
+ stepId: resourceId,
1075
+ resolveData
1076
+ }));
1077
+ correlationId = resourceData.stepId;
1078
+ } else if (resource === "hook") {
1079
+ resourceData = await unwrapOrThrow(rpc("fetchHook", {
1080
+ hookId: resourceId,
1081
+ resolveData
1082
+ }));
1083
+ correlationId = resourceData.hookId;
1084
+ } else throw new WorkflowWebAPIError(`Unknown resource type: ${resource}`, { layer: "client" });
1085
+ return {
1086
+ data: resourceData,
1087
+ correlationId
1088
+ };
1089
+ }
1090
+ async function fetchSpanDetailResource(selection, options = {}) {
1091
+ const { resource, resourceId, runId } = selection;
1092
+ const { encryptionKey } = options;
1093
+ const hydrate = async (value) => hydrateResourceIOAsync(value, encryptionKey);
1094
+ if (resource === "hook") return hydrate(await unwrapOrThrow(rpc("fetchHook", {
1095
+ hookId: resourceId,
1096
+ resolveData: "all"
1097
+ })));
1098
+ if (resource === "sleep") {
1099
+ if (!runId) throw new WorkflowWebAPIError("runId is required for loading sleep details", { layer: "client" });
1100
+ const result = await unwrapOrThrow(rpc("fetchEvents", {
1101
+ runId,
1102
+ sortOrder: "asc",
1103
+ limit: 1e3,
1104
+ withData: true
1105
+ }));
1106
+ const waitEvents = await Promise.all(result.data.filter((e) => e.correlationId === resourceId).map(hydrate));
1107
+ const data = waitEventsToWaitEntity(waitEvents);
1108
+ if (data === null) throw new WorkflowWebAPIError(`Failed to load ${resource} details: missing required event data`, { layer: "client" });
1109
+ return data;
1110
+ }
1111
+ const { data } = await fetchResourceWithCorrelationId(resource, resourceId, { runId });
1112
+ return hydrate(data);
1113
+ }
1114
+ // app/lib/client/workflow-primitives.ts
1115
+ /**
1116
+ * Merges two arrays by a unique ID key, with later items overriding earlier ones.
1117
+ */
1118
+ function mergeById(prev, next, idKey) {
1119
+ const combined = [...prev, ...next];
1120
+ const uniqueById = new Map(combined.map((item) => [item[idKey], item]));
1121
+ return Array.from(uniqueById.values());
1122
+ }
1123
+ /**
1124
+ * Polls a paginated resource for new items, merging them into existing state.
1125
+ * Returns true if new items were found.
1126
+ *
1127
+ * @param cursorStrategy - 'always': advance cursor whenever one is returned.
1128
+ * 'onHasMore': only advance when hasMore is true (re-fetches existing items to catch status updates).
1129
+ * @param transform - Optional transform applied to each new item before merging (e.g. hydrateResourceIO).
1130
+ */
1131
+ async function pollResource(opts) {
1132
+ const { fetchFn, setItems, setCursor, setError, idKey, cursorStrategy = "always", transform } = opts;
1133
+ const { error, result } = await fetchFn();
1134
+ if (error) {
1135
+ setError(error);
1136
+ return false;
1137
+ }
1138
+ if (result.data.length > 0) {
1139
+ const newData = transform ? result.data.map(transform) : result.data;
1140
+ setItems((prev) => mergeById(prev, newData, idKey));
1141
+ if (cursorStrategy === "onHasMore" ? !!(result.cursor && result.hasMore) : !!result.cursor) setCursor(result.cursor);
1142
+ return true;
1143
+ }
1144
+ return false;
1145
+ }
1146
+ // app/lib/client/hooks/use-trace-viewer.ts
1147
+ var LIVE_POLL_LIMIT = 100;
1148
+ var INITIAL_PAGE_SIZE = 500;
1149
+ var LOAD_MORE_PAGE_SIZE = 100;
1150
+ var LIVE_UPDATE_INTERVAL_MS = 5e3;
1151
+ var AUTO_LOAD_MAX_EVENTS = 500;
1152
+ /**
1153
+ * Returns (and keeps up-to-date) the Run and Events for a workflow run.
1154
+ * The trace viewer builds spans entirely from events — Steps and Hooks
1155
+ * are fetched on-demand by the detail sidebar, not here.
1156
+ */
1157
+ function useWorkflowTraceViewerData(runId, options = {}) {
1158
+ const { live = false } = options;
1159
+ const [run, setRun] = (0, import_react.useState)(null);
1160
+ const [events, setEvents] = (0, import_react.useState)([]);
1161
+ const [loading, setLoading] = (0, import_react.useState)(true);
1162
+ const [error, setError] = (0, import_react.useState)(null);
1163
+ const [eventsCursor, setEventsCursor] = (0, import_react.useState)();
1164
+ const [eventsHasMore, setEventsHasMore] = (0, import_react.useState)(false);
1165
+ const [isLoadingMoreTraceData, setIsLoadingMoreTraceData] = (0, import_react.useState)(false);
1166
+ const [hasEncryptedData, setHasEncryptedData] = (0, import_react.useState)(false);
1167
+ const isFetchingRef = (0, import_react.useRef)(false);
1168
+ const mountedRef = (0, import_react.useRef)(true);
1169
+ const [initialLoadCompleted, setInitialLoadCompleted] = (0, import_react.useState)(false);
1170
+ const fetchAllData = (0, import_react.useCallback)(async () => {
1171
+ if (isFetchingRef.current) return;
1172
+ isFetchingRef.current = true;
1173
+ setLoading(true);
1174
+ setError(null);
1175
+ const [runResult, eventsResult] = await Promise.all([unwrapServerActionResult(rpc("fetchRun", {
1176
+ runId,
1177
+ resolveData: "none"
1178
+ })), unwrapServerActionResult(rpc("fetchEvents", {
1179
+ runId,
1180
+ sortOrder: "asc",
1181
+ limit: INITIAL_PAGE_SIZE,
1182
+ withData: false
1183
+ }))]);
1184
+ if (runResult.error) setError(runResult.error);
1185
+ else setRun(hydrateResourceIO(runResult.result));
1186
+ const initialEvents = eventsResult.error ? [] : eventsResult.result.data.map(hydrateResourceIO);
1187
+ setEvents(mergeById([], initialEvents, "eventId"));
1188
+ setEventsCursor(eventsResult.error || !eventsResult.result.hasMore ? void 0 : eventsResult.result.cursor);
1189
+ setEventsHasMore(Boolean(!eventsResult.error && eventsResult.result.hasMore));
1190
+ setLoading(false);
1191
+ setInitialLoadCompleted(true);
1192
+ isFetchingRef.current = false;
1193
+ if (!runResult.error && eventsResult.error) setError(eventsResult.error);
1194
+ if (!runResult.error) {
1195
+ const ctx = runResult.result.executionContext;
1196
+ if (ctx?.features && ctx.features.encryption) setHasEncryptedData(true);
1197
+ else unwrapServerActionResult(rpc("fetchEvents", {
1198
+ runId,
1199
+ sortOrder: "asc",
1200
+ limit: 1,
1201
+ withData: true
1202
+ })).then((probeResult) => {
1203
+ if (mountedRef.current && !probeResult.error && probeResult.result.data.some((e) => hasEncryptedFields(hydrateResourceIO(e)))) setHasEncryptedData(true);
1204
+ }).catch(() => {});
1205
+ }
1206
+ }, [runId]);
1207
+ const loadMoreTraceData = (0, import_react.useCallback)(async () => {
1208
+ if (isFetchingRef.current || !initialLoadCompleted || isLoadingMoreTraceData || !eventsHasMore) return;
1209
+ setIsLoadingMoreTraceData(true);
1210
+ try {
1211
+ const nextEventsResult = await unwrapServerActionResult(rpc("fetchEvents", {
1212
+ runId,
1213
+ cursor: eventsCursor,
1214
+ sortOrder: "asc",
1215
+ limit: LOAD_MORE_PAGE_SIZE,
1216
+ withData: false
1217
+ }));
1218
+ if (nextEventsResult.error) setError(nextEventsResult.error);
1219
+ else {
1220
+ const nextEvents = nextEventsResult.result.data.map(hydrateResourceIO);
1221
+ if (nextEvents.length > 0) setEvents((prev) => mergeById(prev, nextEvents, "eventId"));
1222
+ setEventsHasMore(Boolean(nextEventsResult.result.hasMore));
1223
+ setEventsCursor(nextEventsResult.result.hasMore ? nextEventsResult.result.cursor : void 0);
1224
+ }
1225
+ } finally {
1226
+ setIsLoadingMoreTraceData(false);
1227
+ }
1228
+ }, [
1229
+ runId,
1230
+ initialLoadCompleted,
1231
+ isLoadingMoreTraceData,
1232
+ eventsHasMore,
1233
+ eventsCursor
1234
+ ]);
1235
+ (0, import_react.useEffect)(() => {
1236
+ if (events.length >= AUTO_LOAD_MAX_EVENTS) return;
1237
+ loadMoreTraceData();
1238
+ }, [events.length, loadMoreTraceData]);
1239
+ const pollRun = (0, import_react.useCallback)(async () => {
1240
+ if (run?.completedAt) return false;
1241
+ const { error, result } = await unwrapServerActionResult(rpc("fetchRun", {
1242
+ runId,
1243
+ resolveData: "none"
1244
+ }));
1245
+ if (error) {
1246
+ setError(error);
1247
+ return false;
1248
+ }
1249
+ setError(null);
1250
+ setRun(hydrateResourceIO(result));
1251
+ return true;
1252
+ }, [runId, run?.completedAt]);
1253
+ const pollEvents = (0, import_react.useCallback)(() => pollResource({
1254
+ fetchFn: () => unwrapServerActionResult(rpc("fetchEvents", {
1255
+ runId,
1256
+ cursor: eventsCursor,
1257
+ sortOrder: "asc",
1258
+ limit: LIVE_POLL_LIMIT,
1259
+ withData: false
1260
+ })),
1261
+ setItems: setEvents,
1262
+ setCursor: setEventsCursor,
1263
+ setError,
1264
+ idKey: "eventId",
1265
+ transform: hydrateResourceIO
1266
+ }), [runId, eventsCursor]);
1267
+ const update = (0, import_react.useCallback)(async () => {
1268
+ if (isFetchingRef.current || !initialLoadCompleted) return { foundNewItems: false };
1269
+ let foundNewItems = false;
1270
+ try {
1271
+ const [_, eventsUpdated] = await Promise.all([pollRun(), pollEvents()]);
1272
+ foundNewItems = eventsUpdated;
1273
+ } catch (err) {
1274
+ console.error("Update error:", err);
1275
+ }
1276
+ return { foundNewItems };
1277
+ }, [
1278
+ pollEvents,
1279
+ initialLoadCompleted,
1280
+ pollRun
1281
+ ]);
1282
+ (0, import_react.useEffect)(() => {
1283
+ fetchAllData();
1284
+ }, [fetchAllData]);
1285
+ (0, import_react.useEffect)(() => {
1286
+ mountedRef.current = true;
1287
+ return () => {
1288
+ mountedRef.current = false;
1289
+ };
1290
+ }, []);
1291
+ (0, import_react.useEffect)(() => {
1292
+ if (!live || !initialLoadCompleted || run?.completedAt) return;
1293
+ const interval = setInterval(() => {
1294
+ update();
1295
+ }, LIVE_UPDATE_INTERVAL_MS);
1296
+ return () => {
1297
+ clearInterval(interval);
1298
+ };
1299
+ }, [
1300
+ live,
1301
+ initialLoadCompleted,
1302
+ update,
1303
+ run?.completedAt
1304
+ ]);
1305
+ return {
1306
+ run,
1307
+ events,
1308
+ loading,
1309
+ error,
1310
+ update,
1311
+ loadMoreTraceData,
1312
+ hasMoreTraceData: eventsHasMore,
1313
+ isLoadingMoreTraceData,
1314
+ hasEncryptedData
1315
+ };
1316
+ }
1317
+ // app/lib/client/hooks/use-workflow-streams.ts
1318
+ var STREAMS_REFRESH_INTERVAL_MS = 1e4;
1319
+ /**
1320
+ * Hook to fetch and manage stream list for a run
1321
+ */
1322
+ function useWorkflowStreams(runId, refreshInterval = STREAMS_REFRESH_INTERVAL_MS) {
1323
+ const [streams, setStreams] = (0, import_react.useState)([]);
1324
+ const [loading, setLoading] = (0, import_react.useState)(true);
1325
+ const [error, setError] = (0, import_react.useState)(null);
1326
+ const hasFetchedRef = (0, import_react.useRef)(false);
1327
+ const fetchData = (0, import_react.useCallback)(async () => {
1328
+ if (!hasFetchedRef.current) setLoading(true);
1329
+ setError(null);
1330
+ try {
1331
+ const result = await listStreams(runId);
1332
+ setStreams(result);
1333
+ } catch (err) {
1334
+ setError(err instanceof Error ? err : new Error(String(err)));
1335
+ } finally {
1336
+ hasFetchedRef.current = true;
1337
+ setLoading(false);
1338
+ }
1339
+ }, [runId]);
1340
+ (0, import_react.useEffect)(() => {
1341
+ hasFetchedRef.current = false;
1342
+ fetchData();
1343
+ }, [fetchData]);
1344
+ (0, import_react.useEffect)(() => {
1345
+ if (!refreshInterval || refreshInterval <= 0) return;
1346
+ const interval = setInterval(fetchData, refreshInterval);
1347
+ return () => clearInterval(interval);
1348
+ }, [refreshInterval, fetchData]);
1349
+ return {
1350
+ streams,
1351
+ loading,
1352
+ error,
1353
+ refresh: fetchData
1354
+ };
1355
+ }
1038
1356
  // app/components/run-detail-view.tsx
1039
1357
  var TABS = [
1040
1358
  "trace",
@@ -1048,7 +1366,6 @@ function RunDetailView({ runId, selectedId: _selectedId }) {
1048
1366
  const [rerunning, setRerunning] = (0, import_react.useState)(false);
1049
1367
  const [showCancelDialog, setShowCancelDialog] = (0, import_react.useState)(false);
1050
1368
  const [showRerunDialog, setShowRerunDialog] = (0, import_react.useState)(false);
1051
- const env = (0, import_react.useMemo)(() => ({}), []);
1052
1369
  const activeTab = TABS.find((tab) => tab === searchParams.get("tab")) ?? "trace";
1053
1370
  const selectedStreamId = searchParams.get("streamId");
1054
1371
  const updateSearchParams = (0, import_react.useCallback)((updates) => {
@@ -1077,37 +1394,47 @@ function RunDetailView({ runId, selectedId: _selectedId }) {
1077
1394
  navigate(`/run/${encodeURIComponent(targetRunId)}`);
1078
1395
  }, [navigate]);
1079
1396
  const handleWakeUpSleep = (0, import_react.useCallback)(async (runId, correlationId) => {
1080
- return wakeUpRun(env, runId, { correlationIds: [correlationId] });
1081
- }, [env]);
1397
+ return unwrapOrThrow(rpc("wakeUpRun", {
1398
+ runId,
1399
+ correlationIds: [correlationId]
1400
+ }));
1401
+ }, []);
1082
1402
  const encryptionKeyRef = (0, import_react.useRef)(null);
1083
1403
  const handleResolveHook = (0, import_react.useCallback)(async (hookToken, payload) => {
1084
- await resumeHook(env, hookToken, payload);
1085
- }, [env]);
1404
+ await unwrapOrThrow(rpc("resumeHook", {
1405
+ token: hookToken,
1406
+ payload
1407
+ }));
1408
+ }, []);
1086
1409
  const handleLoadEventData = (0, import_react.useCallback)(async (event) => {
1087
- const { error, result } = await unwrapServerActionResult(fetchEvent(env, event.runId, event.eventId, "all"));
1410
+ const { error, result } = await unwrapServerActionResult(rpc("fetchEvent", {
1411
+ runId: event.runId,
1412
+ eventId: event.eventId,
1413
+ resolveData: "all"
1414
+ }));
1088
1415
  if (error) throw error;
1089
1416
  const fullEvent = await hydrateResourceIOAsync(result, encryptionKeyRef.current ?? void 0);
1090
1417
  if ("eventData" in fullEvent) return fullEvent.eventData;
1091
1418
  return null;
1092
- }, [env]);
1093
- const { run: runData, events: allEvents, loading, error, update, hasEncryptedData, loadMoreTraceData, hasMoreTraceData, isLoadingMoreTraceData } = useWorkflowTraceViewerData(env, runId, { live: true });
1419
+ }, []);
1420
+ const { run: runData, events: allEvents, loading, error, update, hasEncryptedData, loadMoreTraceData, hasMoreTraceData, isLoadingMoreTraceData } = useWorkflowTraceViewerData(runId, { live: true });
1094
1421
  const run = runData ?? {};
1095
- const cancelReason = useCancellationReason(env, runId, run.status, allEvents);
1422
+ const cancelReason = useCancellationReason(runId, run.status, allEvents);
1096
1423
  const [encryptionKey, setEncryptionKey] = (0, import_react.useState)(null);
1097
1424
  encryptionKeyRef.current = encryptionKey;
1098
1425
  const [eventsSortOrder, setEventsSortOrder] = (0, import_react.useState)("asc");
1099
- const { events: eventsListData, loading: eventsListLoading, hasMore: hasMoreEventsTab, loadingMore: loadingMoreEventsTab, loadMore: loadMoreEventsTab, searchByExactId } = useEventsListData(env, runId, {
1426
+ const { events: eventsListData, loading: eventsListLoading, hasMore: hasMoreEventsTab, loadingMore: loadingMoreEventsTab, loadMore: loadMoreEventsTab, searchByExactId } = useEventsListData(runId, {
1100
1427
  sortOrder: eventsSortOrder,
1101
1428
  encryptionKey: encryptionKey ?? void 0,
1102
1429
  enabled: activeTab === "events"
1103
1430
  });
1104
- const fetchSpanDetail = (0, import_react.useCallback)((selection) => fetchSpanDetailResource(env, selection, { encryptionKey: encryptionKey ?? void 0 }), [env, encryptionKey]);
1431
+ const fetchSpanDetail = (0, import_react.useCallback)((selection) => fetchSpanDetailResource(selection, { encryptionKey: encryptionKey ?? void 0 }), [encryptionKey]);
1105
1432
  const [isDecrypting, setIsDecrypting] = (0, import_react.useState)(false);
1106
1433
  const handleDecrypt = (0, import_react.useCallback)(async () => {
1107
1434
  if (encryptionKey) return;
1108
1435
  setIsDecrypting(true);
1109
1436
  try {
1110
- const { error: keyError, result: keyResult } = await unwrapServerActionResult(getEncryptionKeyForRun(env, runId));
1437
+ const { error: keyError, result: keyResult } = await unwrapServerActionResult(rpc("getEncryptionKeyForRun", { runId }));
1111
1438
  if (keyError) {
1112
1439
  toast.error(`Failed to fetch encryption key: ${keyError.message}`);
1113
1440
  return;
@@ -1120,11 +1447,7 @@ function RunDetailView({ runId, selectedId: _selectedId }) {
1120
1447
  } finally {
1121
1448
  setIsDecrypting(false);
1122
1449
  }
1123
- }, [
1124
- encryptionKey,
1125
- env,
1126
- runId
1127
- ]);
1450
+ }, [encryptionKey, runId]);
1128
1451
  const sidebarData = (0, import_react.useMemo)(() => ({
1129
1452
  run,
1130
1453
  events: allEvents ?? [],
@@ -1152,8 +1475,8 @@ function RunDetailView({ runId, selectedId: _selectedId }) {
1152
1475
  isDecrypting,
1153
1476
  hasEncryptedData
1154
1477
  ]);
1155
- const { streams, loading: streamsLoading, error: streamsError } = useWorkflowStreams(env, runId);
1156
- const { chunks: streamChunks, isLive: streamIsLive, isInitialLoading: streamIsInitialLoading, error: streamError } = useStreamReader(env, selectedStreamId, runId, encryptionKey, run.status);
1478
+ const { streams, loading: streamsLoading, error: streamsError } = useWorkflowStreams(runId);
1479
+ const { chunks: streamChunks, isLive: streamIsLive, isInitialLoading: streamIsInitialLoading, error: streamError } = useStreamReader(selectedStreamId, runId, encryptionKey, run.status);
1157
1480
  const handleCancelClick = () => {
1158
1481
  setShowCancelDialog(true);
1159
1482
  };
@@ -1162,7 +1485,7 @@ function RunDetailView({ runId, selectedId: _selectedId }) {
1162
1485
  try {
1163
1486
  setCancelling(true);
1164
1487
  setShowCancelDialog(false);
1165
- await cancelRun(env, runId);
1488
+ await unwrapOrThrow(rpc("cancelRun", { runId }));
1166
1489
  await update();
1167
1490
  toast.success("Run cancelled");
1168
1491
  } catch (err) {
@@ -1182,7 +1505,7 @@ function RunDetailView({ runId, selectedId: _selectedId }) {
1182
1505
  try {
1183
1506
  setRerunning(true);
1184
1507
  setShowRerunDialog(false);
1185
- const newRunId = await recreateRun(env, run.runId);
1508
+ const newRunId = await unwrapOrThrow(rpc("recreateRun", { runId: run.runId }));
1186
1509
  toast.success("New run started", { description: `Run ID: ${newRunId}` });
1187
1510
  navigate(`/run/${newRunId}`);
1188
1511
  } catch (err) {
@@ -1198,7 +1521,7 @@ function RunDetailView({ runId, selectedId: _selectedId }) {
1198
1521
  className: "m-4",
1199
1522
  children: [
1200
1523
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CircleAlert, { className: "h-4 w-4" }),
1201
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlertTitle, { children: getErrorTitle(error, "Error loading workflow run") }),
1524
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlertTitle, { children: "Error loading workflow run" }),
1202
1525
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlertDescription, { children: getErrorMessage(error) })
1203
1526
  ]
1204
1527
  });
@@ -1251,10 +1574,9 @@ function RunDetailView({ runId, selectedId: _selectedId }) {
1251
1574
  }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
1252
1575
  className: "flex items-center justify-between gap-2",
1253
1576
  children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(LiveStatus, {
1254
- hasError: false,
1255
- errorMessage: ""
1577
+ hasError: error !== null,
1578
+ errorMessage: error ? getErrorMessage(error) : ""
1256
1579
  }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RunActionsButtons, {
1257
- env,
1258
1580
  runId,
1259
1581
  runStatus: run.status,
1260
1582
  events: allEvents,