@powerhousedao/workflow 6.2.3-dev.84 → 6.2.3-dev.85

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 (123) hide show
  1. package/dist/browser/{BlockSelector-CtoMNZ9A.js → BlockSelector-BKAJwJ4Y.js} +74 -6
  2. package/dist/browser/BlockSelector-BKAJwJ4Y.js.map +1 -0
  3. package/dist/browser/{PieceMarkdown-U6OUTwRi.js → PieceMarkdown-DSdZd-Jc.js} +34 -8
  4. package/dist/browser/PieceMarkdown-DSdZd-Jc.js.map +1 -0
  5. package/dist/browser/{connection-form-_H-tP2Vk.js → connection-form-DltdMa8F.js} +3 -3
  6. package/dist/browser/{connection-form-_H-tP2Vk.js.map → connection-form-DltdMa8F.js.map} +1 -1
  7. package/dist/browser/{data-tree-CjWQllC7.js → data-tree-DAw8e0j8.js} +25 -12
  8. package/dist/browser/data-tree-DAw8e0j8.js.map +1 -0
  9. package/dist/browser/document-models/index.js +2 -2
  10. package/dist/browser/document-models/workflow/index.js +2 -2
  11. package/dist/browser/{document-models-DSK5cn8B.js → document-models-C2SAP1SX.js} +2 -2
  12. package/dist/browser/{document-models-DSK5cn8B.js.map → document-models-C2SAP1SX.js.map} +1 -1
  13. package/dist/browser/{editor-B1AzXxaF.js → editor--J61vLSC.js} +435 -51
  14. package/dist/browser/editor--J61vLSC.js.map +1 -0
  15. package/dist/browser/{editor-DgdTF2up.js → editor-CZLe6CAF.js} +5 -5
  16. package/dist/browser/{editor-DgdTF2up.js.map → editor-CZLe6CAF.js.map} +1 -1
  17. package/dist/browser/{editor-B9069RYZ.js → editor-Dl6lzxkM.js} +26 -18
  18. package/dist/browser/{editor-B9069RYZ.js.map → editor-Dl6lzxkM.js.map} +1 -1
  19. package/dist/browser/editors/connection-editor/module.js +1 -1
  20. package/dist/browser/editors/runtime/index.js +1 -1
  21. package/dist/browser/editors/workflow-editor/module.js +1 -1
  22. package/dist/browser/editors/workflow-studio/module.js +1 -1
  23. package/dist/browser/index.js +3 -3
  24. package/dist/browser/{module-eOpxJVIl.js → module-mFCt9WHJ.js} +2 -2
  25. package/dist/browser/module-mFCt9WHJ.js.map +1 -0
  26. package/dist/browser/reactor/index.js +2 -2
  27. package/dist/browser/{runtime-queries-LAcyniYz.js → runtime-queries-D81Ghpok.js} +105 -4
  28. package/dist/browser/runtime-queries-D81Ghpok.js.map +1 -0
  29. package/dist/browser/{trigger-text-BgpPIXEJ.js → trigger-text-BSVi5oGZ.js} +392 -387
  30. package/dist/browser/trigger-text-BSVi5oGZ.js.map +1 -0
  31. package/dist/browser/{upgrade-manifests-CLYUPqBs.js → upgrade-manifests-C2Qa6myy.js} +2 -2
  32. package/dist/browser/{upgrade-manifests-CLYUPqBs.js.map → upgrade-manifests-C2Qa6myy.js.map} +1 -1
  33. package/dist/browser/{workflow-Cn1UP-eJ.js → workflow-BFdnSGRD.js} +2 -2
  34. package/dist/browser/{workflow-Cn1UP-eJ.js.map → workflow-BFdnSGRD.js.map} +1 -1
  35. package/dist/node/{BlockSelector-CbdgYJfp.mjs → BlockSelector-Bcb5NJ_X.mjs} +74 -6
  36. package/dist/node/BlockSelector-Bcb5NJ_X.mjs.map +1 -0
  37. package/dist/node/{PieceMarkdown-DwpCBISY.mjs → PieceMarkdown-CUSdTMH4.mjs} +34 -8
  38. package/dist/node/{PieceMarkdown-DwpCBISY.mjs.map → PieceMarkdown-CUSdTMH4.mjs.map} +1 -1
  39. package/dist/node/{connection-form-DPbyrUIm.mjs → connection-form-DF5418sz.mjs} +3 -3
  40. package/dist/node/{connection-form-DPbyrUIm.mjs.map → connection-form-DF5418sz.mjs.map} +1 -1
  41. package/dist/node/{data-tree-CXa2kEuD.mjs → data-tree-CebWVI_P.mjs} +25 -12
  42. package/dist/node/{data-tree-CXa2kEuD.mjs.map → data-tree-CebWVI_P.mjs.map} +1 -1
  43. package/dist/node/document-models/index.mjs +2 -2
  44. package/dist/node/document-models/workflow/index.mjs +2 -2
  45. package/dist/node/{editor-D3MlbYBN.mjs → editor-BmRWQvRs.mjs} +435 -51
  46. package/dist/node/editor-BmRWQvRs.mjs.map +1 -0
  47. package/dist/node/{editor-DzxyNgYk.mjs → editor-J0op3mM7.mjs} +5 -5
  48. package/dist/node/{editor-DzxyNgYk.mjs.map → editor-J0op3mM7.mjs.map} +1 -1
  49. package/dist/node/{editor-BGz1Ljdk.mjs → editor-UzRtZp-A.mjs} +26 -18
  50. package/dist/node/{editor-BGz1Ljdk.mjs.map → editor-UzRtZp-A.mjs.map} +1 -1
  51. package/dist/node/editors/connection-editor/module.mjs +1 -1
  52. package/dist/node/editors/runtime/index.mjs +1 -1
  53. package/dist/node/editors/workflow-editor/module.mjs +1 -1
  54. package/dist/node/editors/workflow-studio/module.mjs +1 -1
  55. package/dist/node/index.mjs +3 -3
  56. package/dist/node/{module-D9Zx5Zow.mjs → module-CuTg45ct.mjs} +2 -2
  57. package/dist/{browser/module-eOpxJVIl.js.map → node/module-CuTg45ct.mjs.map} +1 -1
  58. package/dist/node/pieces/ai/descriptor.json +1 -1
  59. package/dist/node/pieces/ai/package.json +1 -1
  60. package/dist/node/pieces/reactor/descriptor.json +1 -1
  61. package/dist/node/pieces/reactor/package.json +1 -1
  62. package/dist/node/{runtime-queries-CatdoDey.mjs → runtime-queries-VXJsWno5.mjs} +110 -5
  63. package/dist/node/runtime-queries-VXJsWno5.mjs.map +1 -0
  64. package/dist/node/{trigger-text-yNCaB6pd.mjs → trigger-text-BvEzEani.mjs} +392 -387
  65. package/dist/node/trigger-text-BvEzEani.mjs.map +1 -0
  66. package/dist/node/{upgrade-manifests-C4akaA_X.mjs → upgrade-manifests-BA5OaR4H.mjs} +2 -2
  67. package/dist/node/{upgrade-manifests-C4akaA_X.mjs.map → upgrade-manifests-BA5OaR4H.mjs.map} +1 -1
  68. package/dist/node/{workflow-DqF9VsBQ.mjs → workflow-BgURVzdc.mjs} +2 -2
  69. package/dist/node/{workflow-DqF9VsBQ.mjs.map → workflow-BgURVzdc.mjs.map} +1 -1
  70. package/dist/powerhouse.manifest.json +2 -2
  71. package/dist/style.css +1 -1
  72. package/dist/types/document-models/workflow/v1/gen/schema/types.d.ts +1 -1
  73. package/dist/types/document-models/workflow/v1/gen/schema/types.d.ts.map +1 -1
  74. package/dist/types/editors/shared/controls.d.ts.map +1 -1
  75. package/dist/types/editors/shared/data-tree.d.ts.map +1 -1
  76. package/dist/types/editors/shared/icons.d.ts +1 -0
  77. package/dist/types/editors/shared/icons.d.ts.map +1 -1
  78. package/dist/types/editors/workflow-editor/editor.d.ts.map +1 -1
  79. package/dist/types/editors/workflow-editor/runtime-client.d.ts +39 -0
  80. package/dist/types/editors/workflow-editor/runtime-client.d.ts.map +1 -1
  81. package/dist/types/editors/workflow-editor/runtime-context.d.ts +10 -1
  82. package/dist/types/editors/workflow-editor/runtime-context.d.ts.map +1 -1
  83. package/dist/types/editors/workflow-editor/runtime-queries.d.ts +21 -1
  84. package/dist/types/editors/workflow-editor/runtime-queries.d.ts.map +1 -1
  85. package/dist/types/editors/workflow-editor/ui/BlockSelector.d.ts.map +1 -1
  86. package/dist/types/editors/workflow-editor/ui/PieceMarkdown.d.ts +2 -1
  87. package/dist/types/editors/workflow-editor/ui/PieceMarkdown.d.ts.map +1 -1
  88. package/dist/types/editors/workflow-editor/ui/PropertyForm.d.ts +4 -0
  89. package/dist/types/editors/workflow-editor/ui/PropertyForm.d.ts.map +1 -1
  90. package/dist/types/editors/workflow-editor/ui/block-meta.d.ts.map +1 -1
  91. package/dist/types/editors/workflow-editor/ui/blocks.d.ts +4 -0
  92. package/dist/types/editors/workflow-editor/ui/blocks.d.ts.map +1 -1
  93. package/dist/types/editors/workflow-editor/ui/query-keys.d.ts +9 -0
  94. package/dist/types/editors/workflow-editor/ui/query-keys.d.ts.map +1 -1
  95. package/dist/types/editors/workflow-studio/components/RunsTable.d.ts.map +1 -1
  96. package/dist/types/editors/workflow-studio/components/Sidebar.d.ts +3 -0
  97. package/dist/types/editors/workflow-studio/components/Sidebar.d.ts.map +1 -1
  98. package/dist/types/editors/workflow-studio/components/Waitpoints.d.ts +49 -0
  99. package/dist/types/editors/workflow-studio/components/Waitpoints.d.ts.map +1 -0
  100. package/dist/types/editors/workflow-studio/components/WorkflowBoard.d.ts +3 -0
  101. package/dist/types/editors/workflow-studio/components/WorkflowBoard.d.ts.map +1 -1
  102. package/dist/types/editors/workflow-studio/components/WorkflowStudio.d.ts.map +1 -1
  103. package/dist/types/editors/workflow-studio/components/run-format.d.ts +2 -1
  104. package/dist/types/editors/workflow-studio/components/run-format.d.ts.map +1 -1
  105. package/dist/types/editors/workflow-studio/components/waitpoints-view.test.d.ts +2 -0
  106. package/dist/types/editors/workflow-studio/components/waitpoints-view.test.d.ts.map +1 -0
  107. package/dist/types/editors/workflow-studio/components/waitpoints.test.d.ts +2 -0
  108. package/dist/types/editors/workflow-studio/components/waitpoints.test.d.ts.map +1 -0
  109. package/dist/types/test/waitpoint-record.d.ts +3 -0
  110. package/dist/types/test/waitpoint-record.d.ts.map +1 -0
  111. package/dist/workflow.css +2 -0
  112. package/package.json +9 -9
  113. package/dist/browser/BlockSelector-CtoMNZ9A.js.map +0 -1
  114. package/dist/browser/PieceMarkdown-U6OUTwRi.js.map +0 -1
  115. package/dist/browser/data-tree-CjWQllC7.js.map +0 -1
  116. package/dist/browser/editor-B1AzXxaF.js.map +0 -1
  117. package/dist/browser/runtime-queries-LAcyniYz.js.map +0 -1
  118. package/dist/browser/trigger-text-BgpPIXEJ.js.map +0 -1
  119. package/dist/node/BlockSelector-CbdgYJfp.mjs.map +0 -1
  120. package/dist/node/editor-D3MlbYBN.mjs.map +0 -1
  121. package/dist/node/module-D9Zx5Zow.mjs.map +0 -1
  122. package/dist/node/runtime-queries-CatdoDey.mjs.map +0 -1
  123. package/dist/node/trigger-text-yNCaB6pd.mjs.map +0 -1
@@ -1,12 +1,12 @@
1
- import { A as MANUAL_TRIGGER, R as sameBlock, V as triggerBlock, k as CORE_PIECE, l as runsOfPages, z as stepBlock } from "./runtime-queries-LAcyniYz.js";
2
- import { y as actions } from "./module-eOpxJVIl.js";
3
- import { r as useWorkflowDocumentsInSelectedDrive } from "./workflow-Cn1UP-eJ.js";
4
- import { A as runStats, Bt as Icon, C as canRerun, Ct as ITEM_PARAM, D as formatMs, E as formatDuration, Et as Button, F as toneOf, Ht as DocumentErrorBoundary, I as workflowHealth, M as runTimeline, Mt as Select, N as runTone, Nt as Switch, O as formatTrigger, P as statusLabel, Rt as textAreaClass, S as TONE_TEXT, T as formatAbsolute, Tt as useSearchParamDraft, Ut as DocumentLoadError, Wt as errorMessage, _ as CONNECTION_TONE, _t as useRunPagesQuery, b as STEP_TONE, f as blockMeta, g as usePieceLogos, j as runStatusLabel, k as formatWhen, pt as WorkflowRuntimeProvider, t as BlockLogo, v as RUN_STATUSES, vt as useRunQuery, w as durationMs, wt as useSearchParam, x as TONE_DOT, xt as useRuntimeActions, y as RUN_TONE, zt as textInputClass } from "./BlockSelector-CtoMNZ9A.js";
5
- import { g as StatusToggle, i as DataViewer, l as StepError, o as PropertyForm, p as PublishState, r as describeTrigger } from "./trigger-text-BgpPIXEJ.js";
1
+ import { K as triggerBlock, N as MANUAL_TRIGGER, U as sameBlock, W as stepBlock, j as CORE_PIECE, l as runsOfPages } from "./runtime-queries-D81Ghpok.js";
2
+ import { y as actions } from "./module-mFCt9WHJ.js";
3
+ import { r as useWorkflowDocumentsInSelectedDrive } from "./workflow-BFdnSGRD.js";
4
+ import { A as formatWhen, Bt as textAreaClass, C as canRerun, D as formatMs, Dt as useSearchParamDraft, E as formatDuration, Et as useSearchParam, F as statusLabel, Ft as Switch, Gt as DocumentLoadError, Ht as Icon, I as toneOf, Kt as errorMessage, L as workflowHealth, M as runStatusLabel, N as runTimeline, O as formatTrigger, Ot as Button, P as runTone, Pt as Select, S as TONE_TEXT, St as useRuntimeActions, T as formatAbsolute, Tt as ITEM_PARAM, Vt as textInputClass, Wt as DocumentErrorBoundary, _ as CONNECTION_TONE, b as STEP_TONE, f as blockMeta, g as usePieceLogos, j as runStats, k as formatUntil, mt as WorkflowRuntimeProvider, t as BlockLogo, v as RUN_STATUSES, vt as useRunPagesQuery, w as durationMs, wt as useWaitingRunsQuery, x as TONE_DOT, y as RUN_TONE, yt as useRunQuery } from "./BlockSelector-BKAJwJ4Y.js";
5
+ import { a as StepError, b as PropertyForm, f as StatusToggle, i as DataViewer, l as PublishState, r as describeTrigger } from "./trigger-text-BSVi5oGZ.js";
6
6
  import { addDocument, addFolder, deleteNode, getPHStore, showDeleteNodeModal, useDispatch, useDocumentSafe, useFileNodesInSelectedDrive, useNodesInSelectedDrive, usePHToast, useSearchParams, useSelectedDrive, useSelectedNode, useSetPHAppConfig, useSetSearchParams, useSetSelectedNode } from "@powerhousedao/reactor-browser";
7
7
  import { generateId } from "document-model";
8
8
  import { ManualPayloadError, coerceManualPayload, manualDefault, parseManualInputs } from "@powerhousedao/pieces-framework/workflow";
9
- import { Fragment, useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
9
+ import { Fragment, Suspense, lazy, useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
10
10
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
11
11
  import { ConnectTooltip, ConnectTooltipProvider, Modal } from "@powerhousedao/design-system/connect";
12
12
  import { addFolder as addFolder$1, moveNode, updateNode } from "@powerhousedao/shared/document-drive";
@@ -527,6 +527,318 @@ function RunStrip(props) {
527
527
  }) });
528
528
  }
529
529
  //#endregion
530
+ //#region editors/workflow-studio/components/Waitpoints.tsx
531
+ const PieceMarkdown = lazy(() => import("./PieceMarkdown-DSdZd-Jc.js"));
532
+ const WAITING_POLL_MS = 3e4;
533
+ function isOpenApproval(waitpoint) {
534
+ return waitpoint.status === "PENDING" && waitpoint.kind === "approval";
535
+ }
536
+ function waitDescription(waitpoint, stepName) {
537
+ if (waitpoint.kind === "delay") return waitpoint.resumeAt ? `${stepName} is waiting until ${formatAbsolute(waitpoint.resumeAt)}` : `${stepName} is waiting for its delay`;
538
+ return `${stepName} is waiting for a webhook callback${waitpoint.expiresAt ? `, until ${formatAbsolute(waitpoint.expiresAt)}` : ""}`;
539
+ }
540
+ function cancelFailure(result) {
541
+ if (!result) return "The run was not found";
542
+ if (result.status === "CANCELLED") return null;
543
+ return result.error ?? `The run is ${result.status}`;
544
+ }
545
+ function countPendingApprovals(runs, limit) {
546
+ const byWorkflow = /* @__PURE__ */ new Map();
547
+ let total = 0;
548
+ for (const run of runs ?? []) {
549
+ const open = (run.waitpoints ?? []).filter(isOpenApproval).length;
550
+ if (open === 0) continue;
551
+ total += open;
552
+ byWorkflow.set(run.workflowId, (byWorkflow.get(run.workflowId) ?? 0) + open);
553
+ }
554
+ return {
555
+ total,
556
+ byWorkflow,
557
+ capped: (runs?.length ?? 0) >= limit
558
+ };
559
+ }
560
+ function approvalCountText(count, capped) {
561
+ return capped ? `${count}+` : String(count);
562
+ }
563
+ function approvalCountLabel(count, capped) {
564
+ const noun = count === 1 && !capped ? "approval" : "approvals";
565
+ return `${approvalCountText(count, capped)} ${noun} waiting`;
566
+ }
567
+ function usePendingApprovals(driveId) {
568
+ return countPendingApprovals(useWaitingRunsQuery({
569
+ driveId,
570
+ first: 100
571
+ }, { pollMs: WAITING_POLL_MS }).data, 100);
572
+ }
573
+ function ApprovalBadge(props) {
574
+ if (props.count === 0) return null;
575
+ const label = approvalCountLabel(props.count, props.capped);
576
+ const className = `inline-flex h-5 shrink-0 items-center gap-1 rounded-full bg-wf-warn/12 px-1.5 text-[11px] font-medium tabular-nums text-wf-warn ${props.className ?? ""}`;
577
+ const content = /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(Icon, {
578
+ name: "clock",
579
+ className: "h-3 w-3"
580
+ }), approvalCountText(props.count, props.capped)] });
581
+ return props.onClick ? /* @__PURE__ */ jsx("button", {
582
+ type: "button",
583
+ title: label,
584
+ "aria-label": label,
585
+ className: `${className} hover:bg-wf-warn/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,
586
+ onClick: (event) => {
587
+ event.stopPropagation();
588
+ props.onClick();
589
+ },
590
+ children: content
591
+ }) : /* @__PURE__ */ jsx("span", {
592
+ role: "img",
593
+ title: label,
594
+ "aria-label": label,
595
+ className,
596
+ children: content
597
+ });
598
+ }
599
+ function reasonRequired(waitpoint, approved) {
600
+ const policy = waitpoint.approval?.reasonRequiredOn ?? "none";
601
+ return policy === "both" || policy === "reject" && !approved;
602
+ }
603
+ function errorText(error) {
604
+ return error instanceof Error ? error.message : String(error);
605
+ }
606
+ function ApprovalCard(props) {
607
+ const { waitpoint } = props;
608
+ const { resolveWaitpoint } = useRuntimeActions();
609
+ const reasonId = useId();
610
+ const [reason, setReason] = useState("");
611
+ const [busy, setBusy] = useState(null);
612
+ const [error, setError] = useState(null);
613
+ const approval = waitpoint.approval;
614
+ const stepName = props.stepName ?? waitpoint.stepKey;
615
+ const policy = approval?.reasonRequiredOn ?? "none";
616
+ const expiresIn = waitpoint.expiresAt ? formatUntil(waitpoint.expiresAt) : null;
617
+ const decide = (approved) => {
618
+ const trimmed = reason.trim();
619
+ if (reasonRequired(waitpoint, approved) && !trimmed) {
620
+ setError(`Give a reason to ${approved ? "approve" : "disapprove"} this request.`);
621
+ return;
622
+ }
623
+ setBusy(approved);
624
+ setError(null);
625
+ resolveWaitpoint(waitpoint, approved, trimmed || void 0).then(() => props.onResolved?.()).catch((resolveError) => setError(errorText(resolveError))).finally(() => setBusy(null));
626
+ };
627
+ return /* @__PURE__ */ jsxs("section", {
628
+ "aria-label": `Approval for ${stepName}`,
629
+ className: "overflow-hidden rounded-xl border border-solid border-foreground/10 bg-card",
630
+ children: [/* @__PURE__ */ jsxs("div", {
631
+ className: "flex items-start gap-3 px-4 py-3.5",
632
+ children: [/* @__PURE__ */ jsx("span", {
633
+ "aria-hidden": true,
634
+ className: "flex h-7 w-7 shrink-0 items-center justify-center rounded-full bg-wf-warn/12 text-wf-warn",
635
+ children: /* @__PURE__ */ jsx(Icon, {
636
+ name: "clock",
637
+ className: "h-3.5 w-3.5"
638
+ })
639
+ }), /* @__PURE__ */ jsxs("div", {
640
+ className: "min-w-0 grow space-y-3",
641
+ children: [
642
+ /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("h3", {
643
+ className: "text-[13px] font-semibold text-foreground",
644
+ children: approval?.title || `Waiting at ${stepName}`
645
+ }), /* @__PURE__ */ jsxs("p", {
646
+ className: "mt-0.5 flex flex-wrap items-center gap-x-3 gap-y-0.5 text-xs text-muted-foreground",
647
+ children: [
648
+ props.meta,
649
+ /* @__PURE__ */ jsxs("span", {
650
+ title: formatAbsolute(waitpoint.createdAt),
651
+ children: ["Asked ", formatWhen(waitpoint.createdAt)]
652
+ }),
653
+ waitpoint.expiresAt ? /* @__PURE__ */ jsx("span", {
654
+ title: formatAbsolute(waitpoint.expiresAt),
655
+ className: expiresIn ? void 0 : "text-wf-warn",
656
+ children: expiresIn ? `Expires ${expiresIn}` : "Expired"
657
+ }) : null
658
+ ]
659
+ })] }),
660
+ approval?.body ? /* @__PURE__ */ jsx(Suspense, {
661
+ fallback: /* @__PURE__ */ jsx("p", {
662
+ className: "whitespace-pre-wrap text-[13px] text-foreground",
663
+ children: approval.body
664
+ }),
665
+ children: /* @__PURE__ */ jsx(PieceMarkdown, {
666
+ text: approval.body,
667
+ className: "max-w-prose text-[13px] text-foreground"
668
+ })
669
+ }) : null,
670
+ approval && approval.approvers.length > 0 ? /* @__PURE__ */ jsxs("p", {
671
+ className: "text-xs text-muted-foreground",
672
+ title: approval.approvers.join("\n"),
673
+ children: [
674
+ "Only ",
675
+ approval.approvers.length,
676
+ " listed",
677
+ " ",
678
+ approval.approvers.length === 1 ? "approver" : "approvers",
679
+ " can decide."
680
+ ]
681
+ }) : null
682
+ ]
683
+ })]
684
+ }), /* @__PURE__ */ jsxs("div", {
685
+ className: "border-t border-solid border-border bg-muted/40 px-4 py-3",
686
+ children: [
687
+ /* @__PURE__ */ jsxs("label", {
688
+ htmlFor: reasonId,
689
+ className: "mb-1.5 flex items-baseline gap-1.5 text-[13px] font-medium text-foreground",
690
+ children: ["Reason", /* @__PURE__ */ jsx("span", {
691
+ className: "text-xs font-normal text-muted-foreground",
692
+ children: policy === "none" ? "Optional" : policy === "reject" ? "Required to disapprove" : "Required"
693
+ })]
694
+ }),
695
+ /* @__PURE__ */ jsx("textarea", {
696
+ id: reasonId,
697
+ className: `${textAreaClass} min-h-16 resize-y`,
698
+ rows: 2,
699
+ value: reason,
700
+ onChange: (event) => setReason(event.target.value)
701
+ }),
702
+ /* @__PURE__ */ jsxs("div", {
703
+ className: "mt-3 flex flex-wrap items-center justify-end gap-2",
704
+ children: [
705
+ error ? /* @__PURE__ */ jsx("span", {
706
+ role: "alert",
707
+ className: "mr-auto text-xs text-wf-fail",
708
+ children: error
709
+ }) : null,
710
+ /* @__PURE__ */ jsxs(Button, {
711
+ variant: "destructive",
712
+ disabled: busy !== null,
713
+ onClick: () => decide(false),
714
+ children: [/* @__PURE__ */ jsx(Icon, {
715
+ name: "close",
716
+ className: "h-3.5 w-3.5"
717
+ }), busy === false ? "Disapproving…" : approval?.rejectLabel || "Disapprove"]
718
+ }),
719
+ /* @__PURE__ */ jsxs(Button, {
720
+ variant: "primary",
721
+ disabled: busy !== null,
722
+ onClick: () => decide(true),
723
+ children: [/* @__PURE__ */ jsx(Icon, {
724
+ name: "check",
725
+ className: "h-3.5 w-3.5"
726
+ }), busy === true ? "Approving…" : approval?.approveLabel || "Approve"]
727
+ })
728
+ ]
729
+ })
730
+ ]
731
+ })]
732
+ });
733
+ }
734
+ function RunWaitpoints(props) {
735
+ const open = props.waitpoints.filter((waitpoint) => waitpoint.status === "PENDING");
736
+ if (open.length === 0) return null;
737
+ return /* @__PURE__ */ jsx("div", {
738
+ className: "space-y-2",
739
+ children: open.map((waitpoint) => waitpoint.kind === "approval" ? /* @__PURE__ */ jsx(ApprovalCard, {
740
+ waitpoint,
741
+ stepName: props.names.get(waitpoint.stepKey),
742
+ onResolved: props.onChanged
743
+ }, waitpoint.id) : /* @__PURE__ */ jsxs("p", {
744
+ className: "flex items-center gap-2 rounded-md bg-wf-warn/10 px-3 py-2 text-[13px] text-wf-warn",
745
+ children: [/* @__PURE__ */ jsx(Icon, {
746
+ name: "clock",
747
+ className: "h-3.5 w-3.5"
748
+ }), waitDescription(waitpoint, props.names.get(waitpoint.stepKey) ?? waitpoint.stepKey)]
749
+ }, waitpoint.id))
750
+ });
751
+ }
752
+ function CancelRunButton(props) {
753
+ const { cancelRun } = useRuntimeActions();
754
+ const [cancelling, setCancelling] = useState(false);
755
+ const [error, setError] = useState(null);
756
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs(Button, {
757
+ variant: "danger",
758
+ disabled: cancelling,
759
+ onClick: () => {
760
+ setCancelling(true);
761
+ setError(null);
762
+ cancelRun(props.run.id).then((result) => setError(cancelFailure(result))).catch((cancelError) => setError(errorText(cancelError))).finally(() => {
763
+ setCancelling(false);
764
+ props.onChanged();
765
+ });
766
+ },
767
+ children: [/* @__PURE__ */ jsx(Icon, {
768
+ name: "close",
769
+ className: "h-3.5 w-3.5"
770
+ }), cancelling ? "Cancelling…" : "Cancel run"]
771
+ }), error ? /* @__PURE__ */ jsx("span", {
772
+ className: "text-wf-fail",
773
+ children: error
774
+ }) : null] });
775
+ }
776
+ function WaitingApprovals(props) {
777
+ const query = useWaitingRunsQuery({
778
+ driveId: props.driveId,
779
+ workflowId: props.workflowId,
780
+ first: 100
781
+ }, { pollMs: WAITING_POLL_MS });
782
+ const entries = (query.data ?? []).flatMap((run) => (run.waitpoints ?? []).filter(isOpenApproval).map((waitpoint) => ({
783
+ run,
784
+ waitpoint
785
+ })));
786
+ const capped = (query.data?.length ?? 0) >= 100;
787
+ const sectionRef = useRef(null);
788
+ const handled = useRef(0);
789
+ const shown = entries.length > 0;
790
+ useEffect(() => {
791
+ const request = props.focusRequest ?? 0;
792
+ if (!shown || request === handled.current) return;
793
+ handled.current = request;
794
+ sectionRef.current?.scrollIntoView({
795
+ behavior: "smooth",
796
+ block: "start"
797
+ });
798
+ sectionRef.current?.focus({ preventScroll: true });
799
+ }, [props.focusRequest, shown]);
800
+ if (!shown) return null;
801
+ return /* @__PURE__ */ jsxs("section", {
802
+ ref: sectionRef,
803
+ tabIndex: -1,
804
+ "aria-label": "Waiting for approval",
805
+ className: "mb-8 scroll-mt-4 focus:outline-none",
806
+ children: [/* @__PURE__ */ jsxs("h2", {
807
+ className: "mb-4 flex items-center gap-2 text-[15px] font-semibold text-foreground",
808
+ children: ["Waiting for approval", /* @__PURE__ */ jsx(ApprovalBadge, {
809
+ count: entries.length,
810
+ capped
811
+ })]
812
+ }), /* @__PURE__ */ jsx("div", {
813
+ className: "space-y-3",
814
+ children: entries.map(({ run, waitpoint }) => {
815
+ const names = props.stepNames.get(run.workflowId);
816
+ return /* @__PURE__ */ jsx(ApprovalCard, {
817
+ waitpoint,
818
+ stepName: names?.get(waitpoint.stepKey),
819
+ onResolved: props.onChanged,
820
+ meta: /* @__PURE__ */ jsxs(Fragment$1, { children: [props.showWorkflow ? /* @__PURE__ */ jsx("span", {
821
+ className: "font-medium text-foreground",
822
+ children: run.workflowName
823
+ }) : null, /* @__PURE__ */ jsxs("span", {
824
+ title: formatAbsolute(run.startedAt),
825
+ children: [
826
+ "Run ",
827
+ /* @__PURE__ */ jsx("span", {
828
+ className: "font-mono",
829
+ children: run.id.slice(0, 8)
830
+ }),
831
+ " ",
832
+ "started ",
833
+ formatWhen(run.startedAt)
834
+ ]
835
+ })] })
836
+ }, waitpoint.id);
837
+ })
838
+ })]
839
+ });
840
+ }
841
+ //#endregion
530
842
  //#region editors/workflow-studio/components/RunsTable.tsx
531
843
  const STATUS_FILTERS = ["ALL", ...RUN_STATUSES];
532
844
  /** The runs table's query params. */
@@ -750,6 +1062,11 @@ function RunDetail(props) {
750
1062
  className: "rounded-md bg-wf-fail/10 px-3 py-2 text-[13px] text-wf-fail",
751
1063
  children: describeRunError(run.error, names)
752
1064
  }) : null,
1065
+ run.waitpoints ? /* @__PURE__ */ jsx(RunWaitpoints, {
1066
+ waitpoints: run.waitpoints,
1067
+ names,
1068
+ onChanged: props.onChanged
1069
+ }) : null,
753
1070
  run.warningNotes.length > 0 ? /* @__PURE__ */ jsx("ul", {
754
1071
  "aria-label": "Run warnings",
755
1072
  className: "space-y-1 rounded-md bg-wf-warn/10 px-3 py-2 text-[13px] text-wf-warn",
@@ -786,6 +1103,13 @@ function RunDetail(props) {
786
1103
  rerunError ? /* @__PURE__ */ jsx("span", {
787
1104
  className: "text-wf-fail",
788
1105
  children: rerunError
1106
+ }) : null,
1107
+ run.status === "WAITING" ? /* @__PURE__ */ jsx("span", {
1108
+ className: "ml-auto flex items-center gap-2",
1109
+ children: /* @__PURE__ */ jsx(CancelRunButton, {
1110
+ run,
1111
+ onChanged: props.onChanged
1112
+ })
789
1113
  }) : null
790
1114
  ]
791
1115
  }),
@@ -868,6 +1192,7 @@ function RunsTable(props) {
868
1192
  const counts = useMemo(() => ({
869
1193
  ALL: scoped.length,
870
1194
  RUNNING: scoped.filter((run) => run.status === "RUNNING").length,
1195
+ WAITING: scoped.filter((run) => run.status === "WAITING").length,
871
1196
  SUCCEEDED: scoped.filter((run) => run.status === "SUCCEEDED").length,
872
1197
  FAILED: scoped.filter((run) => run.status === "FAILED").length
873
1198
  }), [scoped]);
@@ -1557,24 +1882,33 @@ function NodeRow(props) {
1557
1882
  keyShortcuts: props.keyShortcuts,
1558
1883
  trailing: /* @__PURE__ */ jsxs("span", {
1559
1884
  className: "mr-1.5 flex shrink-0 items-center",
1560
- children: [props.onEdit ? /* @__PURE__ */ jsx("button", {
1561
- type: "button",
1562
- title: "Open in editor",
1563
- "aria-label": `Open ${documentName(document, node.name)} in the editor`,
1564
- className: ROW_ACTION,
1565
- onClick: props.onEdit,
1566
- children: /* @__PURE__ */ jsx(Icon, {
1567
- name: "pencil",
1568
- className: "h-3.5 w-3.5"
1885
+ children: [
1886
+ /* @__PURE__ */ jsx(ApprovalBadge, {
1887
+ count: props.approvals ?? 0,
1888
+ capped: props.approvalsCapped ?? false,
1889
+ onClick: props.onShowApprovals,
1890
+ className: "mr-0.5"
1891
+ }),
1892
+ props.onEdit ? /* @__PURE__ */ jsx("button", {
1893
+ type: "button",
1894
+ title: "Open in editor",
1895
+ "aria-label": `Open ${documentName(document, node.name)} in the editor`,
1896
+ className: ROW_ACTION,
1897
+ onClick: props.onEdit,
1898
+ children: /* @__PURE__ */ jsx(Icon, {
1899
+ name: "pencil",
1900
+ className: "h-3.5 w-3.5"
1901
+ })
1902
+ }) : null,
1903
+ isWorkflow && document ? /* @__PURE__ */ jsx(WorkflowMenu, {
1904
+ subtle: true,
1905
+ document,
1906
+ nodeName: node.name
1907
+ }) : /* @__PURE__ */ jsx(DeleteButton, {
1908
+ node,
1909
+ label: documentName(document, node.name)
1569
1910
  })
1570
- }) : null, isWorkflow && document ? /* @__PURE__ */ jsx(WorkflowMenu, {
1571
- subtle: true,
1572
- document,
1573
- nodeName: node.name
1574
- }) : /* @__PURE__ */ jsx(DeleteButton, {
1575
- node,
1576
- label: documentName(document, node.name)
1577
- })]
1911
+ ]
1578
1912
  }),
1579
1913
  children: [/* @__PURE__ */ jsx("span", {
1580
1914
  title: label,
@@ -1665,6 +1999,9 @@ function Section(props) {
1665
1999
  /* @__PURE__ */ jsx(NodeRow, {
1666
2000
  node,
1667
2001
  lastRunStatus: props.lastRuns?.get(node.id),
2002
+ approvals: props.approvals?.byWorkflow.get(node.id),
2003
+ approvalsCapped: props.approvals?.capped,
2004
+ onShowApprovals: props.onShowApprovals ? () => props.onShowApprovals(node) : void 0,
1668
2005
  active: props.activeId === node.id,
1669
2006
  onOpen: () => props.onOpen(node),
1670
2007
  onEdit: props.onEdit ? () => props.onEdit(node) : void 0,
@@ -1693,6 +2030,12 @@ function Sidebar(props) {
1693
2030
  /* @__PURE__ */ jsxs(Row, {
1694
2031
  active: props.allRunsActive,
1695
2032
  onClick: props.onShowAllRuns,
2033
+ trailing: /* @__PURE__ */ jsx(ApprovalBadge, {
2034
+ count: props.approvals.total,
2035
+ capped: props.approvals.capped,
2036
+ onClick: () => props.onShowApprovals(),
2037
+ className: "mr-2"
2038
+ }),
1696
2039
  children: [/* @__PURE__ */ jsx(Icon, {
1697
2040
  name: "list",
1698
2041
  className: "text-muted-foreground"
@@ -1704,6 +2047,8 @@ function Sidebar(props) {
1704
2047
  empty: "No workflows yet.",
1705
2048
  nodes: props.workflows,
1706
2049
  lastRuns: props.lastRuns,
2050
+ approvals: props.approvals,
2051
+ onShowApprovals: (node) => props.onShowApprovals(node.id),
1707
2052
  activeId: props.activeId,
1708
2053
  onOpen: props.onOpenWorkflow,
1709
2054
  onEdit: props.onEditWorkflow,
@@ -2313,6 +2658,7 @@ function summary(rows) {
2313
2658
  return parts.join(", ");
2314
2659
  }
2315
2660
  function WorkflowBoard(props) {
2661
+ const { approvals, onShowApprovals } = props;
2316
2662
  usePieceLogos();
2317
2663
  const { isCollapsed, toggle } = useCollapsed();
2318
2664
  const documents = useWorkflowDocumentsInSelectedDrive() ?? [];
@@ -2339,9 +2685,17 @@ function WorkflowBoard(props) {
2339
2685
  children: [/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("h2", {
2340
2686
  className: "text-2xl font-semibold tracking-tight text-foreground",
2341
2687
  children: "Workflows"
2342
- }), /* @__PURE__ */ jsx("p", {
2343
- className: "mt-1 text-[13px] text-muted-foreground",
2344
- children: rows.length === 0 ? "Automations in this drive" : summary(rows)
2688
+ }), /* @__PURE__ */ jsxs("p", {
2689
+ className: "mt-1 flex flex-wrap items-center gap-2 text-[13px] text-muted-foreground",
2690
+ children: [rows.length === 0 ? "Automations in this drive" : summary(rows), approvals && approvals.total > 0 ? /* @__PURE__ */ jsxs("button", {
2691
+ type: "button",
2692
+ className: "inline-flex items-center gap-1 rounded-full bg-wf-warn/12 px-2 py-0.5 text-xs font-medium text-wf-warn hover:bg-wf-warn/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
2693
+ onClick: () => onShowApprovals?.(),
2694
+ children: [/* @__PURE__ */ jsx(Icon, {
2695
+ name: "clock",
2696
+ className: "h-3 w-3"
2697
+ }), approvalCountLabel(approvals.total, approvals.capped)]
2698
+ }) : null]
2345
2699
  })] }), /* @__PURE__ */ jsxs(Button, {
2346
2700
  variant: "primary",
2347
2701
  disabled: props.creating,
@@ -2447,7 +2801,15 @@ function WorkflowBoard(props) {
2447
2801
  })]
2448
2802
  }), /* @__PURE__ */ jsxs("span", {
2449
2803
  className: "mt-4 flex h-6 shrink-0 items-center gap-1 pr-3",
2450
- children: [/* @__PURE__ */ jsx(RowToggle, { document: row.document }), /* @__PURE__ */ jsx(WorkflowMenu, { document: row.document })]
2804
+ children: [
2805
+ /* @__PURE__ */ jsx(ApprovalBadge, {
2806
+ count: approvals?.byWorkflow.get(row.id) ?? 0,
2807
+ capped: approvals?.capped ?? false,
2808
+ onClick: onShowApprovals ? () => onShowApprovals(row.id) : void 0
2809
+ }),
2810
+ /* @__PURE__ */ jsx(RowToggle, { document: row.document }),
2811
+ /* @__PURE__ */ jsx(WorkflowMenu, { document: row.document })
2812
+ ]
2451
2813
  })]
2452
2814
  }), collapsed ? null : /* @__PURE__ */ jsxs("button", {
2453
2815
  type: "button",
@@ -2808,11 +3170,18 @@ function Studio(props) {
2808
3170
  ]);
2809
3171
  const focusedWorkflow = liveTarget;
2810
3172
  const driveFeed = useRuns({ driveId });
3173
+ const approvals = usePendingApprovals(driveId);
3174
+ const [waitingFocus, setWaitingFocus] = useState(0);
3175
+ const showApprovals = (workflowId) => {
3176
+ go(workflowId);
3177
+ setWaitingFocus((request) => request + 1);
3178
+ };
2811
3179
  const workflowFeed = useRuns({ workflowId: focusedWorkflow?.id }, Boolean(focusedWorkflow));
2812
3180
  const feed = focusedWorkflow ? workflowFeed : driveFeed;
2813
3181
  const { runs, error: runsError, reload: reloadRuns } = feed;
2814
3182
  const lastRuns = /* @__PURE__ */ new Map();
2815
3183
  for (const run of driveFeed.runs ?? []) if (!lastRuns.has(run.workflowId)) lastRuns.set(run.workflowId, run.status);
3184
+ const stepNames = new Map(workflowDocuments.map((document) => [document.header.id, new Map(document.state.global.steps.map((step) => [step.key, step.name || step.key]))]));
2816
3185
  const { data: targetDocument } = useDocumentSafe(liveTarget?.id ?? null);
2817
3186
  const targetTrigger = targetDocument?.header.documentType === WORKFLOW_TYPE ? targetDocument.state.global.trigger : null;
2818
3187
  const manualTrigger = Boolean(targetTrigger && sameBlock(triggerBlock(targetTrigger), MANUAL_TRIGGER));
@@ -2825,6 +3194,8 @@ function Studio(props) {
2825
3194
  workflows,
2826
3195
  connections,
2827
3196
  lastRuns,
3197
+ approvals,
3198
+ onShowApprovals: showApprovals,
2828
3199
  activeId: selectedId,
2829
3200
  allRunsActive: !selectedId,
2830
3201
  creating,
@@ -2850,29 +3221,42 @@ function Studio(props) {
2850
3221
  })
2851
3222
  }) : /* @__PURE__ */ jsxs("div", {
2852
3223
  className: "mx-auto w-full max-w-6xl px-4 py-6 md:px-8 md:py-10",
2853
- children: [liveTarget ? /* @__PURE__ */ jsx(WorkflowHeader, {
2854
- node: liveTarget,
2855
- runs,
2856
- onEdit: () => go(liveTarget.id, liveTarget.id),
2857
- onDeleted: () => select(void 0, { replace: true })
2858
- }, liveTarget.id) : /* @__PURE__ */ jsx(WorkflowBoard, {
2859
- runs,
2860
- order: workflows.map((node) => node.id),
2861
- creating,
2862
- onOpen: (workflowId) => go(workflowId),
2863
- onCreate: () => create(WORKFLOW_TYPE, "Workflow", workflows.length)
2864
- }), /* @__PURE__ */ jsx(RunsView, {
2865
- title: liveTarget ? "Runs" : "Recent runs",
2866
- runs,
2867
- error: runsError,
2868
- reload: reloadRuns,
2869
- showWorkflow: liveTarget === null,
2870
- hasMore: feed.hasMore,
2871
- loadingMore: feed.loadingMore,
2872
- onLoadMore: feed.loadMore,
2873
- onFire: liveTarget && manualTrigger ? (payload) => fireWorkflow(liveTarget.id, payload).then((result) => result.error) : void 0,
2874
- fireInputs
2875
- })]
3224
+ children: [
3225
+ liveTarget ? /* @__PURE__ */ jsx(WorkflowHeader, {
3226
+ node: liveTarget,
3227
+ runs,
3228
+ onEdit: () => go(liveTarget.id, liveTarget.id),
3229
+ onDeleted: () => select(void 0, { replace: true })
3230
+ }, liveTarget.id) : /* @__PURE__ */ jsx(WorkflowBoard, {
3231
+ runs,
3232
+ order: workflows.map((node) => node.id),
3233
+ creating,
3234
+ onOpen: (workflowId) => go(workflowId),
3235
+ approvals,
3236
+ onShowApprovals: showApprovals,
3237
+ onCreate: () => create(WORKFLOW_TYPE, "Workflow", workflows.length)
3238
+ }),
3239
+ /* @__PURE__ */ jsx(WaitingApprovals, {
3240
+ driveId: liveTarget ? void 0 : driveId,
3241
+ workflowId: liveTarget?.id,
3242
+ showWorkflow: liveTarget === null,
3243
+ stepNames,
3244
+ onChanged: reloadRuns,
3245
+ focusRequest: waitingFocus
3246
+ }),
3247
+ /* @__PURE__ */ jsx(RunsView, {
3248
+ title: liveTarget ? "Runs" : "Recent runs",
3249
+ runs,
3250
+ error: runsError,
3251
+ reload: reloadRuns,
3252
+ showWorkflow: liveTarget === null,
3253
+ hasMore: feed.hasMore,
3254
+ loadingMore: feed.loadingMore,
3255
+ onLoadMore: feed.loadMore,
3256
+ onFire: liveTarget && manualTrigger ? (payload) => fireWorkflow(liveTarget.id, payload).then((result) => result.error) : void 0,
3257
+ fireInputs
3258
+ })
3259
+ ]
2876
3260
  })
2877
3261
  })]
2878
3262
  });
@@ -2900,4 +3284,4 @@ function Editor(props) {
2900
3284
  //#endregion
2901
3285
  export { Editor as default };
2902
3286
 
2903
- //# sourceMappingURL=editor-B1AzXxaF.js.map
3287
+ //# sourceMappingURL=editor--J61vLSC.js.map