@ekanos/harness 0.27.0 → 0.28.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 (154) hide show
  1. package/README.md +6 -4
  2. package/dist/internal/components/approvals-tray.d.ts +44 -6
  3. package/dist/internal/components/approvals-tray.js +252 -30
  4. package/dist/internal/components/connect-controls.js +4 -2
  5. package/dist/internal/components/connect-dialog.d.ts +8 -1
  6. package/dist/internal/components/connect-dialog.js +23 -10
  7. package/dist/internal/components/connect-panel.d.ts +3 -2
  8. package/dist/internal/components/connect-panel.js +680 -340
  9. package/dist/internal/components/connect-steps.d.ts +72 -0
  10. package/dist/internal/components/connect-steps.js +341 -0
  11. package/dist/internal/components/console-not-found.d.ts +14 -0
  12. package/dist/internal/components/console-not-found.js +57 -0
  13. package/dist/internal/components/dashboard-grid.d.ts +10 -5
  14. package/dist/internal/components/dashboard-grid.js +8 -9
  15. package/dist/internal/components/dev-toolbar.d.ts +27 -5
  16. package/dist/internal/components/dev-toolbar.js +214 -176
  17. package/dist/internal/components/ekanos-logo.d.ts +18 -0
  18. package/dist/internal/components/ekanos-logo.js +74 -0
  19. package/dist/internal/components/events-panel.d.ts +13 -4
  20. package/dist/internal/components/events-panel.js +478 -81
  21. package/dist/internal/components/harness-widget-provider.d.ts +6 -8
  22. package/dist/internal/components/harness-widget-provider.js +5 -19
  23. package/dist/internal/components/health-panel.d.ts +8 -1
  24. package/dist/internal/components/health-panel.js +328 -31
  25. package/dist/internal/components/integration-badge.js +4 -2
  26. package/dist/internal/components/integration-tab-skeletons.d.ts +8 -0
  27. package/dist/internal/components/integration-tab-skeletons.js +76 -0
  28. package/dist/internal/components/not-found-state.d.ts +39 -0
  29. package/dist/internal/components/not-found-state.js +127 -0
  30. package/dist/internal/components/operation-runner-panel.d.ts +1 -1
  31. package/dist/internal/components/operation-runner-panel.js +624 -189
  32. package/dist/internal/components/operation-scope.d.ts +13 -0
  33. package/dist/internal/components/operation-scope.js +79 -0
  34. package/dist/internal/components/page-skeletons.d.ts +11 -0
  35. package/dist/internal/components/page-skeletons.js +61 -0
  36. package/dist/internal/components/provenance-banner.d.ts +13 -4
  37. package/dist/internal/components/provenance-banner.js +35 -10
  38. package/dist/internal/components/run-log-copy.d.ts +17 -0
  39. package/dist/internal/components/run-log-copy.js +67 -0
  40. package/dist/internal/components/run-log-detail.d.ts +22 -0
  41. package/dist/internal/components/run-log-detail.js +295 -0
  42. package/dist/internal/components/run-log-empty.d.ts +13 -0
  43. package/dist/internal/components/run-log-empty.js +46 -0
  44. package/dist/internal/components/run-log.d.ts +23 -3
  45. package/dist/internal/components/run-log.js +384 -130
  46. package/dist/internal/components/runtime-strip.d.ts +5 -1
  47. package/dist/internal/components/runtime-strip.js +82 -5
  48. package/dist/internal/components/schema-form.d.ts +2 -1
  49. package/dist/internal/components/schema-form.js +212 -79
  50. package/dist/internal/components/scrollable-nav.js +14 -2
  51. package/dist/internal/components/segmented-control.d.ts +19 -0
  52. package/dist/internal/components/segmented-control.js +46 -0
  53. package/dist/internal/components/shell-header.d.ts +25 -0
  54. package/dist/internal/components/shell-header.js +126 -0
  55. package/dist/internal/components/surface-nav.d.ts +12 -4
  56. package/dist/internal/components/surface-nav.js +77 -77
  57. package/dist/internal/components/widget-surface.d.ts +5 -1
  58. package/dist/internal/components/widget-surface.js +86 -14
  59. package/dist/internal/components/workflow-runner.d.ts +23 -10
  60. package/dist/internal/components/workflow-runner.js +451 -69
  61. package/dist/internal/lib/connect-model.d.ts +134 -0
  62. package/dist/internal/lib/connect-model.js +282 -0
  63. package/dist/internal/lib/connection-facts.js +2 -1
  64. package/dist/internal/lib/console-client.js +5 -2
  65. package/dist/internal/lib/console-hooks.d.ts +4 -1
  66. package/dist/internal/lib/console-hooks.js +3 -2
  67. package/dist/internal/lib/console-types.d.ts +6 -0
  68. package/dist/internal/lib/docs-links.d.ts +28 -0
  69. package/dist/internal/lib/docs-links.js +57 -1
  70. package/dist/internal/lib/event-delivery.d.ts +33 -0
  71. package/dist/internal/lib/event-delivery.js +66 -0
  72. package/dist/internal/lib/font-files/OFL-BricolageGrotesque.txt +93 -0
  73. package/dist/internal/lib/font-files/OFL-Figtree.txt +93 -0
  74. package/dist/internal/lib/font-files/bricolage-grotesque-latin-variable.woff2 +0 -0
  75. package/dist/internal/lib/font-files/figtree-latin-variable.woff2 +0 -0
  76. package/dist/internal/lib/fonts.js +13 -12
  77. package/dist/internal/lib/health-model.d.ts +58 -0
  78. package/dist/internal/lib/health-model.js +140 -0
  79. package/dist/internal/lib/integration-console-href.d.ts +5 -0
  80. package/dist/internal/lib/integration-console-href.js +7 -1
  81. package/dist/internal/lib/oauth-setup-guide.d.ts +28 -0
  82. package/dist/internal/lib/oauth-setup-guide.js +35 -1
  83. package/dist/internal/lib/operation-catalog.d.ts +70 -0
  84. package/dist/internal/lib/operation-catalog.js +261 -0
  85. package/dist/internal/lib/overview-model.d.ts +34 -0
  86. package/dist/internal/lib/overview-model.js +91 -0
  87. package/dist/internal/lib/registry-entry.d.ts +8 -0
  88. package/dist/internal/lib/registry-entry.js +11 -0
  89. package/dist/internal/lib/repo-name.d.ts +9 -0
  90. package/dist/internal/lib/repo-name.js +21 -0
  91. package/dist/internal/lib/run-log-view.d.ts +66 -1
  92. package/dist/internal/lib/run-log-view.js +183 -4
  93. package/dist/internal/lib/runner-view.d.ts +15 -0
  94. package/dist/internal/lib/runner-view.js +18 -0
  95. package/dist/internal/lib/schema-form-model.d.ts +17 -0
  96. package/dist/internal/lib/schema-form-model.js +50 -0
  97. package/dist/internal/lib/setup-checklist.d.ts +34 -0
  98. package/dist/internal/lib/setup-checklist.js +79 -0
  99. package/dist/internal/lib/toolbar-context.d.ts +0 -1
  100. package/dist/internal/lib/toolbar-context.js +0 -2
  101. package/dist/internal/lib/toolbar-visibility.d.ts +9 -2
  102. package/dist/internal/lib/toolbar-visibility.js +5 -0
  103. package/dist/internal/lib/use-operation-effects.d.ts +7 -0
  104. package/dist/internal/lib/use-operation-effects.js +28 -0
  105. package/dist/internal/lib/use-run-log-query.d.ts +9 -0
  106. package/dist/internal/lib/use-run-log-query.js +35 -0
  107. package/dist/internal/lib/widget-grid-gaps.d.ts +18 -0
  108. package/dist/internal/lib/widget-grid-gaps.js +41 -0
  109. package/dist/internal/lib/workflow-summary.d.ts +54 -0
  110. package/dist/internal/lib/workflow-summary.js +147 -0
  111. package/dist/internal/routes/console-home-page.js +2 -1
  112. package/dist/internal/routes/experience-connect-page.js +46 -17
  113. package/dist/internal/routes/experience-layout-page.js +75 -26
  114. package/dist/internal/routes/experience-page-host.js +63 -5
  115. package/dist/internal/routes/experience-review-queue-page.d.ts +4 -1
  116. package/dist/internal/routes/experience-review-queue-page.js +108 -12
  117. package/dist/internal/routes/experience-runs-page.js +57 -4
  118. package/dist/internal/routes/experience-summary-page.d.ts +19 -0
  119. package/dist/internal/routes/experience-summary-page.js +212 -52
  120. package/dist/internal/routes/experience-widget-page.js +58 -7
  121. package/dist/internal/routes/experience-widgets-page.d.ts +2 -3
  122. package/dist/internal/routes/experience-widgets-page.js +29 -4
  123. package/dist/internal/routes/experience-workflow-page.js +81 -9
  124. package/dist/internal/routes/experience-workflows-page.js +85 -21
  125. package/dist/internal/routes/integration-layout.js +28 -3
  126. package/dist/internal/routes/integrations-connect-page.js +16 -6
  127. package/dist/internal/routes/integrations-events-page.js +22 -1
  128. package/dist/internal/routes/integrations-health-page.js +16 -1
  129. package/dist/internal/routes/integrations-layout.js +28 -4
  130. package/dist/internal/routes/integrations-list-page.d.ts +0 -1
  131. package/dist/internal/routes/integrations-list-page.js +11 -9
  132. package/dist/internal/routes/integrations-operation-page.js +53 -17
  133. package/dist/internal/routes/integrations-operations-page.js +539 -49
  134. package/dist/internal/routes/integrations-overview-page.js +332 -69
  135. package/dist/internal/routes/integrations-runs-page.js +53 -3
  136. package/dist/internal/routes/integrations-scope.d.ts +15 -2
  137. package/dist/internal/routes/integrations-scope.js +66 -18
  138. package/dist/internal/routes/preview-index-page.js +2 -2
  139. package/dist/internal/routes/repo-home-page.d.ts +2 -2
  140. package/dist/internal/routes/repo-home-page.js +428 -236
  141. package/dist/internal/routes/repo-layout.d.ts +12 -0
  142. package/dist/internal/routes/repo-layout.js +50 -38
  143. package/dist/internal/routes/repo-package-layouts.js +22 -8
  144. package/dist/internal/routes/single-widget-page.d.ts +1 -1
  145. package/dist/internal/routes/single-widget-page.js +28 -5
  146. package/dist/internal/routes/tile-page.d.ts +1 -1
  147. package/dist/internal/routes/tile-page.js +1 -2
  148. package/dist/internal/routes/widgets-page.d.ts +1 -1
  149. package/dist/internal/routes/widgets-page.js +5 -3
  150. package/dist/registry.d.ts +4 -5
  151. package/dist/registry.js +0 -1
  152. package/dist/routes.d.ts +5 -0
  153. package/dist/routes.js +2 -0
  154. package/package.json +8 -8
@@ -1,104 +1,486 @@
1
1
  "use client";
2
- import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ import Link from "next/link";
3
4
  import { Alert, AlertDescription } from "@ekanos/ui/alert";
4
5
  import { Button } from "@ekanos/ui/button";
5
6
  import { Card } from "@ekanos/ui/card";
7
+ import { Icon } from "@ekanos/ui/icon";
6
8
  import { StatusBadge } from "@ekanos/ui/status-badge";
7
- import { useApprovals, useConsoleMutation } from "../lib/console-hooks.js";
8
- const SIMULATED_STEP_TYPES = [
9
- "fusion_tool",
10
- "approval_gate",
11
- "ai_step"
12
- ];
13
- function isSimulated(step) {
14
- return SIMULATED_STEP_TYPES.includes(step.type);
15
- }
9
+ import { cn } from "@ekanos/ui/utils";
10
+ import {
11
+ useMutation,
12
+ useMutationState,
13
+ useQueryClient
14
+ } from "@tanstack/react-query";
15
+ import { useConsoleClient, useConsoleLinks } from "../lib/console-context.js";
16
+ import { consoleKeys, useApprovals, useProject } from "../lib/console-hooks.js";
17
+ import { integrationConsoleHref } from "../lib/integration-console-href.js";
18
+ import { shortName } from "../lib/setup-checklist.js";
19
+ import {
20
+ gateStepId,
21
+ groupSteps,
22
+ humanizeStepLabel,
23
+ isSimulated,
24
+ splitOpKey,
25
+ stepTypeLabel
26
+ } from "../lib/workflow-summary.js";
27
+ import { ApprovalList, DecisionLog, ProposalText } from "./approvals-tray.js";
28
+ import { FOCUS_RING } from "./scrollable-nav.js";
29
+ import { SIMULATED_STEP_TYPES, isSimulated as isSimulated2 } from "../lib/workflow-summary.js";
16
30
  const TONES = {
31
+ idle: "neutral",
17
32
  pending: "neutral",
33
+ queued: "neutral",
18
34
  running: "info",
35
+ waiting: "warning",
19
36
  done: "success",
20
37
  rejected: "destructive",
21
38
  failed: "destructive",
22
39
  not_simulated: "neutral"
23
40
  };
24
41
  const LABELS = {
25
- pending: "pending",
26
- running: "running",
27
- done: "done",
28
- rejected: "rejected",
29
- failed: "failed",
30
- not_simulated: "not simulated"
42
+ idle: "",
43
+ pending: "Not reached",
44
+ queued: "Queued",
45
+ running: "Running",
46
+ waiting: "Waiting for you",
47
+ done: "Done",
48
+ rejected: "Rejected",
49
+ failed: "Failed",
50
+ not_simulated: "Not simulated"
51
+ };
52
+ const TYPE_ICON = {
53
+ fusion_tool: "wrench",
54
+ ai_step: "sparkle",
55
+ approval_gate: "hand"
31
56
  };
57
+ function displayFor(step, index, context) {
58
+ if (!isSimulated(step)) return "not_simulated";
59
+ if (context.running) {
60
+ if (context.waitingGateIndex === -1) return "running";
61
+ if (index < context.waitingGateIndex) return "done";
62
+ return index === context.waitingGateIndex ? "waiting" : "queued";
63
+ }
64
+ if (!context.run) return "idle";
65
+ return context.run.steps.find((entry) => entry.id === step.id)?.status ?? "pending";
66
+ }
67
+ function OperationRef({
68
+ step,
69
+ integrations
70
+ }) {
71
+ if (!step.integration || !step.opKey) return null;
72
+ const op = splitOpKey(step.opKey);
73
+ const owner = integrations.find(
74
+ (entry) => entry.integration === step.integration
75
+ );
76
+ const base = owner ? integrationConsoleHref(owner) : null;
77
+ const name = op?.name ?? step.opKey;
78
+ const text = /* @__PURE__ */ jsxs(Fragment, { children: [
79
+ /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: shortName(step.integration) }),
80
+ " ",
81
+ /* @__PURE__ */ jsx("code", { className: "text-foreground", children: name })
82
+ ] });
83
+ return base && op ? /* @__PURE__ */ jsx(
84
+ Link,
85
+ {
86
+ href: `${base}/operations/${op.kind}/${op.name}`,
87
+ className: cn(
88
+ "rounded-sm text-xs underline-offset-2 hover:underline",
89
+ FOCUS_RING
90
+ ),
91
+ title: `Open ${step.integration} ${step.opKey} in the operation runner`,
92
+ "data-test": "workflow-step-op",
93
+ children: text
94
+ }
95
+ ) : /* @__PURE__ */ jsx("span", { className: "text-xs", title: `${step.integration} ${step.opKey}`, children: text });
96
+ }
97
+ function StepRow({
98
+ step,
99
+ index,
100
+ status,
101
+ detail,
102
+ output,
103
+ integrations,
104
+ effect,
105
+ compact
106
+ }) {
107
+ return /* @__PURE__ */ jsxs(
108
+ "li",
109
+ {
110
+ className: cn("relative flex min-w-0 gap-3", compact ? "py-1.5" : "py-3"),
111
+ "data-test": "workflow-step",
112
+ "data-step-id": step.id,
113
+ "data-status": status === "idle" ? "pending" : status,
114
+ children: [
115
+ /* @__PURE__ */ jsx(
116
+ "span",
117
+ {
118
+ className: cn(
119
+ "bg-background text-muted-foreground relative z-10 flex shrink-0 items-center justify-center rounded-full border text-xs tabular-nums",
120
+ compact ? "mt-0.5 size-6" : "size-8",
121
+ status === "done" && "border-success text-success",
122
+ status === "waiting" && "border-warning text-warning",
123
+ (status === "failed" || status === "rejected") && "border-destructive text-destructive"
124
+ ),
125
+ "aria-hidden": "true",
126
+ children: status === "done" ? /* @__PURE__ */ jsx(Icon, { name: "check", className: "h-3.5 w-3.5" }) : index + 1
127
+ }
128
+ ),
129
+ /* @__PURE__ */ jsxs(
130
+ "div",
131
+ {
132
+ className: cn(
133
+ "flex min-w-0 flex-1 flex-col justify-center gap-1",
134
+ compact ? "min-h-6" : "min-h-8"
135
+ ),
136
+ children: [
137
+ /* @__PURE__ */ jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1", children: [
138
+ /* @__PURE__ */ jsxs("span", { className: "sr-only", children: [
139
+ "Step ",
140
+ index + 1,
141
+ ":"
142
+ ] }),
143
+ /* @__PURE__ */ jsx("span", { className: "text-sm font-medium", children: humanizeStepLabel(step.label) }),
144
+ compact ? null : /* @__PURE__ */ jsxs("span", { className: "text-muted-foreground flex items-center gap-1 text-xs", children: [
145
+ /* @__PURE__ */ jsx(
146
+ Icon,
147
+ {
148
+ name: TYPE_ICON[step.type] ?? "circle",
149
+ className: "h-3.5 w-3.5"
150
+ }
151
+ ),
152
+ stepTypeLabel(step.type),
153
+ effect ? ` \xB7 ${effect}` : null
154
+ ] }),
155
+ compact ? null : /* @__PURE__ */ jsx(OperationRef, { step, integrations }),
156
+ LABELS[status] ? /* @__PURE__ */ jsx(StatusBadge, { tone: TONES[status], className: "ml-auto", children: LABELS[status] }) : null
157
+ ] }),
158
+ detail && step.type === "approval_gate" && status === "done" ? /* @__PURE__ */ jsx(
159
+ ProposalText,
160
+ {
161
+ text: detail,
162
+ className: "text-muted-foreground text-xs"
163
+ }
164
+ ) : detail ? /* @__PURE__ */ jsx(
165
+ "p",
166
+ {
167
+ className: cn(
168
+ "text-xs break-words whitespace-pre-line",
169
+ status === "failed" ? "text-destructive" : "text-muted-foreground"
170
+ ),
171
+ role: status === "failed" ? "alert" : void 0,
172
+ children: detail.charAt(0).toUpperCase() + detail.slice(1)
173
+ }
174
+ ) : null,
175
+ output !== void 0 ? /* @__PURE__ */ jsxs("details", { className: "group", children: [
176
+ /* @__PURE__ */ jsx(
177
+ "summary",
178
+ {
179
+ className: cn(
180
+ "text-muted-foreground hover:text-foreground w-fit cursor-pointer rounded-sm text-xs",
181
+ FOCUS_RING
182
+ ),
183
+ children: "Output"
184
+ }
185
+ ),
186
+ /* @__PURE__ */ jsx("pre", { className: "bg-muted mt-1 max-h-48 overflow-auto rounded-md p-2 text-xs", children: JSON.stringify(output, null, 2) })
187
+ ] }) : null
188
+ ]
189
+ }
190
+ )
191
+ ]
192
+ }
193
+ );
194
+ }
195
+ function GroupBlock({
196
+ group,
197
+ statusOf,
198
+ run,
199
+ integrations,
200
+ effectOf
201
+ }) {
202
+ const [first] = group.steps;
203
+ if (!first) return null;
204
+ const effectFor = (step) => step.integration && step.opKey ? effectOf(step.integration, step.opKey) : void 0;
205
+ const rows = (compact) => group.steps.map(({ step, index }) => {
206
+ const state = run?.steps.find((entry) => entry.id === step.id);
207
+ const effect2 = effectFor(step);
208
+ return /* @__PURE__ */ jsx(
209
+ StepRow,
210
+ {
211
+ step,
212
+ index,
213
+ status: statusOf(step, index),
214
+ ...state?.detail ? { detail: state.detail } : {},
215
+ ...state?.output !== void 0 ? { output: state.output } : {},
216
+ integrations,
217
+ ...effect2 ? { effect: effect2 } : {},
218
+ compact
219
+ },
220
+ step.id
221
+ );
222
+ });
223
+ if (group.steps.length === 1) return /* @__PURE__ */ jsx(Fragment, { children: rows(false) });
224
+ const effect = effectFor(first.step);
225
+ return /* @__PURE__ */ jsx("li", { className: "py-3", "data-test": "workflow-step-group", children: /* @__PURE__ */ jsxs(Card, { layout: "bleed", className: "flex flex-col px-3 py-2", children: [
226
+ /* @__PURE__ */ jsxs("p", { className: "text-muted-foreground flex flex-wrap items-center gap-1 pb-1 text-xs", children: [
227
+ /* @__PURE__ */ jsx(
228
+ Icon,
229
+ {
230
+ name: TYPE_ICON[first.step.type] ?? "circle",
231
+ className: "h-3.5 w-3.5"
232
+ }
233
+ ),
234
+ group.steps.length,
235
+ " ",
236
+ stepTypeLabel(first.step.type).toLowerCase(),
237
+ "s",
238
+ effect ? ` (${effect}s)` : null,
239
+ " to the same operation:",
240
+ /* @__PURE__ */ jsx(OperationRef, { step: first.step, integrations })
241
+ ] }),
242
+ /* @__PURE__ */ jsx("ol", { className: "flex flex-col", children: rows(true) })
243
+ ] }) });
244
+ }
245
+ function WhatRunDoes({
246
+ template,
247
+ integrations
248
+ }) {
249
+ const links = useConsoleLinks();
250
+ const used = [
251
+ ...new Set(
252
+ template.steps.flatMap(
253
+ (step) => step.integration ? [step.integration] : []
254
+ )
255
+ )
256
+ ];
257
+ const live = used.filter(
258
+ (name) => integrations.find((entry) => entry.integration === name)?.runtime?.facts.answers === "live"
259
+ );
260
+ const fixtures = used.filter((name) => !live.includes(name));
261
+ const hasAi = template.steps.some((step) => step.type === "ai_step");
262
+ const hasGate = template.steps.some((step) => step.type === "approval_gate");
263
+ return /* @__PURE__ */ jsxs(
264
+ "div",
265
+ {
266
+ className: "bg-secondary text-muted-foreground flex flex-col gap-1.5 rounded-lg border px-4 py-3 text-sm",
267
+ "data-test": "workflow-run-explainer",
268
+ children: [
269
+ /* @__PURE__ */ jsx("p", { className: "text-foreground font-medium", children: "What Run now does" }),
270
+ /* @__PURE__ */ jsxs("ul", { className: "flex list-disc flex-col gap-1 pl-5", children: [
271
+ /* @__PURE__ */ jsx("li", { children: "Runs every step below here in the harness, in order." }),
272
+ fixtures.length > 0 ? /* @__PURE__ */ jsxs("li", { children: [
273
+ "Tool calls to ",
274
+ fixtures.map(shortName).join(", "),
275
+ " answer from fixtures, so nothing reaches",
276
+ " ",
277
+ fixtures.length === 1 ? "the real service" : "the real services",
278
+ "."
279
+ ] }) : null,
280
+ live.length > 0 ? /* @__PURE__ */ jsxs("li", { children: [
281
+ live.map(shortName).join(", "),
282
+ " ",
283
+ live.length === 1 ? "is" : "are",
284
+ " ",
285
+ "connected: reads run live with your local credentials, and writes run live once you approve them."
286
+ ] }) : null,
287
+ hasAi ? /* @__PURE__ */ jsxs("li", { children: [
288
+ "AI steps answer from ",
289
+ /* @__PURE__ */ jsx("code", { children: "fixtures/ai/" }),
290
+ ", not a model."
291
+ ] }) : null,
292
+ hasGate ? /* @__PURE__ */ jsxs("li", { children: [
293
+ "The run stops at each approval gate until you approve or reject it, here or in the",
294
+ " ",
295
+ /* @__PURE__ */ jsx(
296
+ Link,
297
+ {
298
+ href: `${links.experience}/review-queue`,
299
+ className: cn(
300
+ "text-foreground rounded-sm underline underline-offset-2",
301
+ FOCUS_RING
302
+ ),
303
+ children: "Review queue"
304
+ }
305
+ ),
306
+ "."
307
+ ] }) : null
308
+ ] })
309
+ ]
310
+ }
311
+ );
312
+ }
313
+ const workflowRunKey = (id) => ["console", "workflow-run", id];
314
+ const RUN_GC_MS = 60 * 6e4;
315
+ function isRunState(value) {
316
+ return typeof value === "object" && value !== null && "steps" in value;
317
+ }
318
+ function useWorkflowRun(id) {
319
+ const client = useConsoleClient();
320
+ const queryClient = useQueryClient();
321
+ const start = useMutation({
322
+ mutationKey: workflowRunKey(id),
323
+ gcTime: RUN_GC_MS,
324
+ mutationFn: (templateId) => client.startWorkflow(templateId),
325
+ onSettled: () => Promise.all([
326
+ queryClient.invalidateQueries({ queryKey: consoleKeys.runs }),
327
+ queryClient.invalidateQueries({ queryKey: consoleKeys.approvals })
328
+ ])
329
+ });
330
+ const latest = useMutationState({
331
+ filters: { mutationKey: workflowRunKey(id) },
332
+ select: (mutation) => ({
333
+ status: mutation.state.status,
334
+ data: mutation.state.data,
335
+ error: mutation.state.error?.message ?? null,
336
+ startedAt: mutation.state.submittedAt
337
+ })
338
+ }).at(-1);
339
+ return {
340
+ run: () => start.mutate(id),
341
+ running: latest?.status === "pending",
342
+ result: latest?.status === "success" && isRunState(latest.data) ? latest.data : void 0,
343
+ error: latest?.status === "error" ? latest.error : null,
344
+ startedAt: latest?.startedAt ?? 0
345
+ };
346
+ }
32
347
  function WorkflowRunner({
33
- template
348
+ template,
349
+ effectOf = () => void 0
34
350
  }) {
35
- const start = useConsoleMutation((c, id) => c.startWorkflow(id));
351
+ const links = useConsoleLinks();
352
+ const current = useWorkflowRun(template.id);
36
353
  const approvals = useApprovals();
37
- const waiting = start.isPending ? approvals.data?.length ?? 0 : 0;
38
- const run = start.data;
39
- return /* @__PURE__ */ jsxs("section", { className: "flex flex-col gap-4", "data-test": "workflow-runner", children: [
354
+ const project = useProject();
355
+ const integrations = project.data?.integrations ?? [];
356
+ const run = current.running ? void 0 : current.result;
357
+ const mine = current.running ? (approvals.data ?? []).filter(
358
+ (approval) => approval.integration === template.id || approval.channel === "workflow"
359
+ ) : [];
360
+ const waitingGate = mine.map(
361
+ (approval) => approval.integration === template.id ? gateStepId(approval.opKey) : null
362
+ ).find((id) => id !== null);
363
+ const waitingGateIndex = waitingGate ? template.steps.findIndex((step) => step.id === waitingGate) : -1;
364
+ const context = { running: current.running, run, waitingGateIndex };
365
+ const statusOf = (step, index) => displayFor(step, index, context);
366
+ const counts = run ? {
367
+ done: run.steps.filter((step) => step.status === "done").length,
368
+ total: template.steps.filter(isSimulated).length
369
+ } : null;
370
+ const ended = Boolean(run) || current.error !== null;
371
+ const stopped = run?.steps.find(
372
+ (step) => step.status === "failed" || step.status === "rejected"
373
+ );
374
+ const stoppedStep = stopped ? template.steps.find((step) => step.id === stopped.id) : void 0;
375
+ const stoppedAt = stopped && stoppedStep ? {
376
+ status: stopped.status,
377
+ label: humanizeStepLabel(stoppedStep.label)
378
+ } : void 0;
379
+ return /* @__PURE__ */ jsxs("section", { className: "flex flex-col gap-5", "data-test": "workflow-runner", children: [
380
+ /* @__PURE__ */ jsx(WhatRunDoes, { template, integrations }),
40
381
  /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-3", children: [
41
- /* @__PURE__ */ jsx(
382
+ /* @__PURE__ */ jsxs(
42
383
  Button,
43
384
  {
44
385
  type: "button",
45
- disabled: start.isPending,
386
+ disabled: current.running,
46
387
  "data-test": "workflow-run",
47
- onClick: () => start.mutate(template.id),
48
- children: start.isPending ? "Running\u2026" : run ? "Run again" : "Run now"
388
+ onClick: current.run,
389
+ children: [
390
+ /* @__PURE__ */ jsx(Icon, { name: ended ? "arrow-clockwise" : "play", className: "h-4 w-4" }),
391
+ current.running ? "Running\u2026" : ended ? "Run again" : "Run now"
392
+ ]
49
393
  }
50
394
  ),
51
- run?.completed ? /* @__PURE__ */ jsx(StatusBadge, { tone: "success", children: "finished" }) : null,
52
- waiting > 0 ? /* @__PURE__ */ jsxs(StatusBadge, { tone: "warning", children: [
53
- waiting,
54
- " approval",
55
- waiting === 1 ? "" : "s",
56
- " waiting in the tray above"
57
- ] }) : null
58
- ] }),
59
- start.isError ? /* @__PURE__ */ jsx(Alert, { variant: "destructive", children: /* @__PURE__ */ jsx(AlertDescription, { children: start.error.message }) }) : null,
60
- /* @__PURE__ */ jsx("ol", { className: "flex flex-col gap-3", children: template.steps.map((step, index) => {
61
- const state = start.isPending ? void 0 : run?.steps.find((entry) => entry.id === step.id);
62
- const status = !isSimulated(step) ? "not_simulated" : start.isPending ? "running" : state?.status ?? "pending";
63
- return /* @__PURE__ */ jsxs(
64
- Card,
395
+ run?.completed ? /* @__PURE__ */ jsxs(StatusBadge, { tone: "success", "data-test": "workflow-result", children: [
396
+ "Run finished \xB7 ",
397
+ counts?.done,
398
+ " of ",
399
+ counts?.total,
400
+ " steps done"
401
+ ] }) : run ? /* @__PURE__ */ jsxs(
402
+ StatusBadge,
65
403
  {
66
- layout: "bleed",
67
- render: /* @__PURE__ */ jsx("li", {}),
68
- className: "flex flex-col gap-2 p-4",
69
- "data-test": "workflow-step",
70
- "data-step-id": step.id,
71
- "data-status": status,
404
+ tone: stoppedAt?.status === "failed" ? "destructive" : "warning",
405
+ "data-test": "workflow-result",
72
406
  children: [
73
- /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [
74
- /* @__PURE__ */ jsx("span", { className: "text-muted-foreground text-xs", children: index + 1 }),
75
- /* @__PURE__ */ jsx("span", { className: "text-sm font-medium", children: step.label }),
76
- /* @__PURE__ */ jsx("code", { className: "text-muted-foreground text-xs", children: step.type }),
77
- step.integration && step.opKey ? /* @__PURE__ */ jsxs("code", { className: "text-xs", children: [
78
- step.integration,
79
- ":",
80
- step.opKey
81
- ] }) : null,
82
- /* @__PURE__ */ jsx(StatusBadge, { tone: TONES[status], children: LABELS[status] })
83
- ] }),
84
- state?.detail ? /* @__PURE__ */ jsx(
85
- "p",
86
- {
87
- className: status === "failed" || status === "rejected" ? "text-destructive text-xs" : "text-muted-foreground text-xs",
88
- role: status === "failed" ? "alert" : void 0,
89
- children: state.detail
90
- }
91
- ) : null,
92
- state?.output !== void 0 ? /* @__PURE__ */ jsx("pre", { className: "bg-muted max-h-48 overflow-auto rounded-md p-2 text-xs", children: JSON.stringify(state.output, null, 2) }) : null
407
+ stoppedAt ? `Run ${stoppedAt.status === "failed" ? "failed" : "stopped"} at ${stoppedAt.label}` : "Run stopped",
408
+ " ",
409
+ "\xB7 ",
410
+ counts?.done,
411
+ " of ",
412
+ counts?.total,
413
+ " steps done"
414
+ ]
415
+ }
416
+ ) : null,
417
+ current.running && mine.length === 0 ? /* @__PURE__ */ jsx("span", { className: "text-muted-foreground text-sm", role: "status", children: "Running the steps\u2026" }) : null,
418
+ ended ? /* @__PURE__ */ jsxs(
419
+ Link,
420
+ {
421
+ href: `${links.experience}/runs`,
422
+ className: cn(
423
+ "text-muted-foreground hover:text-foreground ml-auto flex items-center gap-1.5 rounded-sm text-sm underline-offset-2 hover:underline",
424
+ FOCUS_RING
425
+ ),
426
+ title: "Every operation this run made is in the run log, on the workflow channel",
427
+ "data-test": "workflow-run-log",
428
+ children: [
429
+ /* @__PURE__ */ jsx(Icon, { name: "clock-counter-clockwise", className: "h-4 w-4" }),
430
+ "See its calls in the run log"
93
431
  ]
432
+ }
433
+ ) : null
434
+ ] }),
435
+ current.error !== null ? /* @__PURE__ */ jsx(Alert, { variant: "destructive", "data-test": "workflow-run-error", children: /* @__PURE__ */ jsxs(AlertDescription, { children: [
436
+ "The run could not finish: ",
437
+ current.error,
438
+ ". Check the terminal running ",
439
+ /* @__PURE__ */ jsx("code", { children: "ekanos dev" }),
440
+ ", then run it again."
441
+ ] }) }) : null,
442
+ current.startedAt > 0 ? /* @__PURE__ */ jsx(DecisionLog, { workflowId: template.id, since: current.startedAt }) : null,
443
+ mine.length > 0 ? /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", "data-test": "workflow-waiting", children: [
444
+ /* @__PURE__ */ jsxs("p", { className: "text-sm font-medium", role: "status", children: [
445
+ mine.length,
446
+ " approval",
447
+ mine.length === 1 ? "" : "s",
448
+ " waiting for you. The run continues once you decide."
449
+ ] }),
450
+ /* @__PURE__ */ jsx(
451
+ ApprovalList,
452
+ {
453
+ approvals: mine,
454
+ workflowTitles: { [template.id]: template.title },
455
+ workflowId: template.id
456
+ }
457
+ )
458
+ ] }) : null,
459
+ /* @__PURE__ */ jsxs("div", { className: "relative", children: [
460
+ /* @__PURE__ */ jsx(
461
+ "span",
462
+ {
463
+ "aria-hidden": "true",
464
+ className: "bg-border absolute top-4 bottom-4 left-4 w-px"
465
+ }
466
+ ),
467
+ /* @__PURE__ */ jsx("ol", { className: "relative flex flex-col", "aria-label": "Steps", children: groupSteps(template.steps).map((group) => /* @__PURE__ */ jsx(
468
+ GroupBlock,
469
+ {
470
+ group,
471
+ statusOf,
472
+ run,
473
+ integrations,
474
+ effectOf
94
475
  },
95
- step.id
96
- );
97
- }) })
476
+ group.steps[0]?.step.id
477
+ )) })
478
+ ] })
98
479
  ] });
99
480
  }
100
481
  export {
101
482
  SIMULATED_STEP_TYPES,
102
483
  WorkflowRunner,
103
- isSimulated
484
+ isSimulated2 as isSimulated,
485
+ useWorkflowRun
104
486
  };