@ekanos/harness 0.27.0 → 0.29.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 (158) 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/ask-assistant-bridge.js +7 -1
  5. package/dist/internal/components/connect-controls.js +4 -2
  6. package/dist/internal/components/connect-dialog.d.ts +8 -1
  7. package/dist/internal/components/connect-dialog.js +23 -10
  8. package/dist/internal/components/connect-panel.d.ts +3 -2
  9. package/dist/internal/components/connect-panel.js +680 -340
  10. package/dist/internal/components/connect-steps.d.ts +72 -0
  11. package/dist/internal/components/connect-steps.js +341 -0
  12. package/dist/internal/components/console-not-found.d.ts +14 -0
  13. package/dist/internal/components/console-not-found.js +57 -0
  14. package/dist/internal/components/dashboard-grid.d.ts +10 -5
  15. package/dist/internal/components/dashboard-grid.js +8 -9
  16. package/dist/internal/components/dev-toolbar.d.ts +27 -5
  17. package/dist/internal/components/dev-toolbar.js +214 -176
  18. package/dist/internal/components/ekanos-logo.d.ts +18 -0
  19. package/dist/internal/components/ekanos-logo.js +74 -0
  20. package/dist/internal/components/events-panel.d.ts +13 -4
  21. package/dist/internal/components/events-panel.js +478 -81
  22. package/dist/internal/components/harness-widget-provider.d.ts +6 -8
  23. package/dist/internal/components/harness-widget-provider.js +5 -19
  24. package/dist/internal/components/health-panel.d.ts +8 -1
  25. package/dist/internal/components/health-panel.js +328 -31
  26. package/dist/internal/components/integration-badge.js +4 -2
  27. package/dist/internal/components/integration-tab-skeletons.d.ts +8 -0
  28. package/dist/internal/components/integration-tab-skeletons.js +76 -0
  29. package/dist/internal/components/not-found-state.d.ts +39 -0
  30. package/dist/internal/components/not-found-state.js +127 -0
  31. package/dist/internal/components/operation-runner-panel.d.ts +1 -1
  32. package/dist/internal/components/operation-runner-panel.js +624 -189
  33. package/dist/internal/components/operation-scope.d.ts +13 -0
  34. package/dist/internal/components/operation-scope.js +79 -0
  35. package/dist/internal/components/page-skeletons.d.ts +11 -0
  36. package/dist/internal/components/page-skeletons.js +61 -0
  37. package/dist/internal/components/provenance-banner.d.ts +13 -4
  38. package/dist/internal/components/provenance-banner.js +35 -10
  39. package/dist/internal/components/run-log-copy.d.ts +17 -0
  40. package/dist/internal/components/run-log-copy.js +67 -0
  41. package/dist/internal/components/run-log-detail.d.ts +22 -0
  42. package/dist/internal/components/run-log-detail.js +295 -0
  43. package/dist/internal/components/run-log-empty.d.ts +13 -0
  44. package/dist/internal/components/run-log-empty.js +46 -0
  45. package/dist/internal/components/run-log.d.ts +23 -3
  46. package/dist/internal/components/run-log.js +384 -130
  47. package/dist/internal/components/runtime-strip.d.ts +5 -1
  48. package/dist/internal/components/runtime-strip.js +82 -5
  49. package/dist/internal/components/schema-form.d.ts +2 -1
  50. package/dist/internal/components/schema-form.js +212 -79
  51. package/dist/internal/components/scrollable-nav.js +14 -2
  52. package/dist/internal/components/segmented-control.d.ts +19 -0
  53. package/dist/internal/components/segmented-control.js +46 -0
  54. package/dist/internal/components/shell-header.d.ts +25 -0
  55. package/dist/internal/components/shell-header.js +126 -0
  56. package/dist/internal/components/surface-nav.d.ts +12 -4
  57. package/dist/internal/components/surface-nav.js +79 -80
  58. package/dist/internal/components/widget-surface.d.ts +5 -1
  59. package/dist/internal/components/widget-surface.js +86 -14
  60. package/dist/internal/components/workflow-runner.d.ts +23 -10
  61. package/dist/internal/components/workflow-runner.js +451 -69
  62. package/dist/internal/lib/connect-model.d.ts +134 -0
  63. package/dist/internal/lib/connect-model.js +282 -0
  64. package/dist/internal/lib/connection-facts.js +2 -1
  65. package/dist/internal/lib/console-client.js +5 -2
  66. package/dist/internal/lib/console-hooks.d.ts +4 -1
  67. package/dist/internal/lib/console-hooks.js +3 -2
  68. package/dist/internal/lib/console-types.d.ts +6 -0
  69. package/dist/internal/lib/docs-links.d.ts +27 -0
  70. package/dist/internal/lib/docs-links.js +55 -1
  71. package/dist/internal/lib/event-delivery.d.ts +33 -0
  72. package/dist/internal/lib/event-delivery.js +66 -0
  73. package/dist/internal/lib/font-files/OFL-BricolageGrotesque.txt +93 -0
  74. package/dist/internal/lib/font-files/OFL-Figtree.txt +93 -0
  75. package/dist/internal/lib/font-files/bricolage-grotesque-latin-variable.woff2 +0 -0
  76. package/dist/internal/lib/font-files/figtree-latin-variable.woff2 +0 -0
  77. package/dist/internal/lib/fonts.js +13 -12
  78. package/dist/internal/lib/health-model.d.ts +58 -0
  79. package/dist/internal/lib/health-model.js +140 -0
  80. package/dist/internal/lib/integration-console-href.d.ts +5 -0
  81. package/dist/internal/lib/integration-console-href.js +7 -1
  82. package/dist/internal/lib/oauth-setup-guide.d.ts +28 -0
  83. package/dist/internal/lib/oauth-setup-guide.js +35 -1
  84. package/dist/internal/lib/operation-catalog.d.ts +70 -0
  85. package/dist/internal/lib/operation-catalog.js +261 -0
  86. package/dist/internal/lib/overview-model.d.ts +34 -0
  87. package/dist/internal/lib/overview-model.js +91 -0
  88. package/dist/internal/lib/registry-entry.d.ts +8 -0
  89. package/dist/internal/lib/registry-entry.js +11 -0
  90. package/dist/internal/lib/repo-name.d.ts +9 -0
  91. package/dist/internal/lib/repo-name.js +21 -0
  92. package/dist/internal/lib/run-log-view.d.ts +66 -1
  93. package/dist/internal/lib/run-log-view.js +183 -4
  94. package/dist/internal/lib/runner-view.d.ts +15 -0
  95. package/dist/internal/lib/runner-view.js +18 -0
  96. package/dist/internal/lib/schema-form-model.d.ts +17 -0
  97. package/dist/internal/lib/schema-form-model.js +50 -0
  98. package/dist/internal/lib/setup-checklist.d.ts +34 -0
  99. package/dist/internal/lib/setup-checklist.js +79 -0
  100. package/dist/internal/lib/toolbar-context.d.ts +0 -1
  101. package/dist/internal/lib/toolbar-context.js +0 -2
  102. package/dist/internal/lib/toolbar-visibility.d.ts +9 -2
  103. package/dist/internal/lib/toolbar-visibility.js +5 -0
  104. package/dist/internal/lib/use-operation-effects.d.ts +7 -0
  105. package/dist/internal/lib/use-operation-effects.js +28 -0
  106. package/dist/internal/lib/use-run-log-query.d.ts +9 -0
  107. package/dist/internal/lib/use-run-log-query.js +35 -0
  108. package/dist/internal/lib/widget-grid-gaps.d.ts +18 -0
  109. package/dist/internal/lib/widget-grid-gaps.js +41 -0
  110. package/dist/internal/lib/workflow-summary.d.ts +54 -0
  111. package/dist/internal/lib/workflow-summary.js +147 -0
  112. package/dist/internal/routes/console-home-page.js +2 -1
  113. package/dist/internal/routes/experience-connect-page.js +46 -17
  114. package/dist/internal/routes/experience-layout-page.d.ts +6 -6
  115. package/dist/internal/routes/experience-layout-page.js +3 -119
  116. package/dist/internal/routes/experience-page-host.js +61 -5
  117. package/dist/internal/routes/experience-pages-page.d.ts +5 -0
  118. package/dist/internal/routes/experience-pages-page.js +118 -0
  119. package/dist/internal/routes/experience-review-queue-page.d.ts +4 -1
  120. package/dist/internal/routes/experience-review-queue-page.js +108 -12
  121. package/dist/internal/routes/experience-runs-page.js +57 -4
  122. package/dist/internal/routes/experience-summary-page.d.ts +19 -0
  123. package/dist/internal/routes/experience-summary-page.js +212 -52
  124. package/dist/internal/routes/experience-widget-page.js +58 -7
  125. package/dist/internal/routes/experience-widgets-page.d.ts +2 -3
  126. package/dist/internal/routes/experience-widgets-page.js +29 -4
  127. package/dist/internal/routes/experience-workflow-page.js +81 -9
  128. package/dist/internal/routes/experience-workflows-page.js +85 -21
  129. package/dist/internal/routes/integration-layout.js +28 -3
  130. package/dist/internal/routes/integrations-connect-page.js +16 -6
  131. package/dist/internal/routes/integrations-events-page.js +22 -1
  132. package/dist/internal/routes/integrations-health-page.js +16 -1
  133. package/dist/internal/routes/integrations-layout.js +28 -4
  134. package/dist/internal/routes/integrations-list-page.d.ts +0 -1
  135. package/dist/internal/routes/integrations-list-page.js +11 -9
  136. package/dist/internal/routes/integrations-operation-page.js +53 -17
  137. package/dist/internal/routes/integrations-operations-page.js +539 -49
  138. package/dist/internal/routes/integrations-overview-page.js +332 -69
  139. package/dist/internal/routes/integrations-runs-page.js +53 -3
  140. package/dist/internal/routes/integrations-scope.d.ts +15 -2
  141. package/dist/internal/routes/integrations-scope.js +66 -18
  142. package/dist/internal/routes/preview-index-page.js +2 -2
  143. package/dist/internal/routes/repo-home-page.d.ts +2 -2
  144. package/dist/internal/routes/repo-home-page.js +429 -236
  145. package/dist/internal/routes/repo-layout.d.ts +12 -0
  146. package/dist/internal/routes/repo-layout.js +50 -38
  147. package/dist/internal/routes/repo-package-layouts.js +22 -8
  148. package/dist/internal/routes/single-widget-page.d.ts +1 -1
  149. package/dist/internal/routes/single-widget-page.js +28 -5
  150. package/dist/internal/routes/tile-page.d.ts +1 -1
  151. package/dist/internal/routes/tile-page.js +1 -2
  152. package/dist/internal/routes/widgets-page.d.ts +1 -1
  153. package/dist/internal/routes/widgets-page.js +5 -3
  154. package/dist/registry.d.ts +4 -5
  155. package/dist/registry.js +0 -1
  156. package/dist/routes.d.ts +8 -1
  157. package/dist/routes.js +4 -0
  158. package/package.json +14 -14
@@ -6,14 +6,24 @@ import {
6
6
  } from "@ekanos/sdk/hooks";
7
7
  import { Alert, AlertDescription, AlertTitle } from "@ekanos/ui/alert";
8
8
  import { Button } from "@ekanos/ui/button";
9
+ import { Card } from "@ekanos/ui/card";
9
10
  import { ConfirmDialog } from "@ekanos/ui/confirm-dialog";
10
- import { Input } from "@ekanos/ui/input";
11
- import { Label } from "@ekanos/ui/label";
11
+ import { Icon } from "@ekanos/ui/icon";
12
+ import { Skeleton } from "@ekanos/ui/skeleton";
12
13
  import { StatusBadge } from "@ekanos/ui/status-badge";
13
- import { useQueryClient } from "@tanstack/react-query";
14
+ import { cn } from "@ekanos/ui/utils";
15
+ import { useQuery, useQueryClient } from "@tanstack/react-query";
14
16
  import { NextIntlClientProvider } from "next-intl";
15
17
  import { TeamAccountWorkspaceContextProvider } from "../../mocks/team-account-workspace.js";
16
18
  import { HARNESS_ACCOUNT_ID } from "../../registry.js";
19
+ import {
20
+ activationRows,
21
+ authorizeBlocker,
22
+ connectSteps,
23
+ credentialHints,
24
+ formatWhen,
25
+ groupKeys
26
+ } from "../lib/connect-model.js";
17
27
  import { useConsoleClient } from "../lib/console-context.js";
18
28
  import {
19
29
  consoleKeys,
@@ -21,6 +31,18 @@ import {
21
31
  useConsoleMutation
22
32
  } from "../lib/console-hooks.js";
23
33
  import { oauthConnectHref } from "../lib/oauth-connect-href.js";
34
+ import { buildConnectionSetupGuide } from "../lib/oauth-setup-guide.js";
35
+ import { resolveOriginalFetch } from "../lib/original-fetch.js";
36
+ import { registryEntryFor } from "../lib/registry-entry.js";
37
+ import { fetchLocalSetup } from "../lib/trigger-runner.js";
38
+ import { useOptionalHarnessRegistry } from "../registry-context.js";
39
+ import {
40
+ ConnectStepItem,
41
+ ConnectStepList,
42
+ CredentialGroup,
43
+ CredentialRow,
44
+ SetupGuide
45
+ } from "./connect-steps.js";
24
46
  import { ConnectionChip } from "./connection-chip.js";
25
47
  const LEVEL_LABEL = {
26
48
  source: "For the Source",
@@ -88,21 +110,37 @@ function ConnectAsSwitch({
88
110
  const change = useConsoleMutation(
89
111
  (c, as) => c.setSwitches(integration, { connectAs: { credential, as } })
90
112
  );
91
- return /* @__PURE__ */ jsx(
92
- TierSwitch,
93
- {
94
- label: "Connect as",
95
- value,
96
- options: CONNECT_AS_OPTIONS,
97
- testId,
98
- disabled: change.isPending,
99
- onChange: (as) => change.mutate(as, {
100
- onSuccess: () => queryClient.invalidateQueries({
101
- queryKey: consoleKeys.connection(integration)
113
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
114
+ /* @__PURE__ */ jsx(
115
+ TierSwitch,
116
+ {
117
+ label: "Connect as",
118
+ value,
119
+ options: CONNECT_AS_OPTIONS,
120
+ testId,
121
+ disabled: change.isPending,
122
+ onChange: (as) => change.mutate(as, {
123
+ onSuccess: () => queryClient.invalidateQueries({
124
+ queryKey: consoleKeys.connection(integration)
125
+ })
102
126
  })
103
- })
104
- }
105
- );
127
+ }
128
+ ),
129
+ /* @__PURE__ */ jsxs(
130
+ "p",
131
+ {
132
+ className: "text-muted-foreground text-xs",
133
+ "data-test": `${testId}-explain`,
134
+ children: [
135
+ "Me: only your own calls get it, in ",
136
+ /* @__PURE__ */ jsx("code", { children: "ctx.identity" }),
137
+ ". The team: every call gets it, in ",
138
+ /* @__PURE__ */ jsx("code", { children: "ctx.secrets" }),
139
+ "."
140
+ ]
141
+ }
142
+ )
143
+ ] });
106
144
  }
107
145
  function RunAsSwitch({
108
146
  integration,
@@ -112,7 +150,8 @@ function RunAsSwitch({
112
150
  const change = useConsoleMutation(
113
151
  (c, runAs) => c.setSwitches(integration, { runAs })
114
152
  );
115
- return /* @__PURE__ */ jsxs("div", { className: "flex max-w-xl flex-col gap-1", "data-test": "run-as", children: [
153
+ return /* @__PURE__ */ jsxs("section", { className: "flex flex-col gap-2 border-t pt-6", "data-test": "run-as", children: [
154
+ /* @__PURE__ */ jsx("h3", { className: "font-heading font-heading-title text-base", children: "How calls run" }),
116
155
  /* @__PURE__ */ jsx(
117
156
  TierSwitch,
118
157
  {
@@ -132,9 +171,43 @@ function RunAsSwitch({
132
171
  value === "me" ? "Calls act as you, with ctx.identity holding only what you connected as yourself." : "Calls act as a machine: no person, and never a ctx.identity.",
133
172
  " ",
134
173
  "ctx.secrets stays the team's either way."
135
- ] })
174
+ ] }),
175
+ change.isError ? /* @__PURE__ */ jsx("p", { className: "text-destructive text-xs", role: "alert", children: change.error.message }) : null
136
176
  ] });
137
177
  }
178
+ function ConnectSkeleton() {
179
+ return /* @__PURE__ */ jsxs(
180
+ "div",
181
+ {
182
+ className: "flex w-full flex-col gap-6",
183
+ "data-test": "connect-loading",
184
+ "aria-busy": "true",
185
+ "aria-label": "Loading the connection",
186
+ children: [
187
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-16 w-full rounded-lg" }),
188
+ [0, 1].map((step) => /* @__PURE__ */ jsxs("div", { className: "flex gap-4", children: [
189
+ /* @__PURE__ */ jsx(Skeleton, { className: "size-7 rounded-full" }),
190
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col gap-3", children: [
191
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-5 w-48" }),
192
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-28 w-full rounded-lg" })
193
+ ] })
194
+ ] }, step))
195
+ ]
196
+ }
197
+ );
198
+ }
199
+ function summaryLine(state, oauth) {
200
+ switch (state.facts.state) {
201
+ case "connected":
202
+ return state.facts.answers === "live" ? "Operations that name no mode run live with these credentials." : "Connected. Calls answer from fixtures while this integration is pinned to them.";
203
+ case "no_connection_needed":
204
+ return "This integration works without credentials.";
205
+ case "unreadable":
206
+ return state.facts.detail ?? "The harness could not read the stored credentials.";
207
+ default:
208
+ return oauth ? "Add your app keys, then authorize. Until then, calls answer from fixtures." : "Add your keys to run live. Until then, calls answer from fixtures.";
209
+ }
210
+ }
138
211
  function ConnectPanel({
139
212
  integration,
140
213
  oauth = false,
@@ -143,24 +216,35 @@ function ConnectPanel({
143
216
  returnPath,
144
217
  surface = "page"
145
218
  }) {
146
- const connection = useConnection(integration.integration);
219
+ const slug = integration.integration;
220
+ const connection = useConnection(slug);
147
221
  const queryClient = useQueryClient();
148
- const [drafts, setDrafts] = useState({});
149
- const save = useConsoleMutation(
150
- (c, values) => c.saveSecrets(integration.integration, values)
151
- );
222
+ const registry = useOptionalHarnessRegistry();
223
+ const entry = registryEntryFor(registry, slug);
224
+ const hints = credentialHints(entry?.definition);
152
225
  const disconnect = useConsoleMutation(
153
- (c, clearKeys) => c.disconnect(integration.integration, clearKeys)
226
+ (c, clearKeys) => c.disconnect(slug, clearKeys)
154
227
  );
155
228
  if (connection.isError) {
156
- return /* @__PURE__ */ jsx(Alert, { variant: "destructive", children: /* @__PURE__ */ jsxs(AlertDescription, { children: [
157
- "Could not load the connection: ",
158
- connection.error.message
159
- ] }) });
160
- }
161
- if (!connection.data) {
162
- return /* @__PURE__ */ jsx("p", { className: "text-muted-foreground text-sm", children: "Loading\u2026" });
229
+ return /* @__PURE__ */ jsxs(Alert, { variant: "destructive", "data-test": "connect-error", children: [
230
+ /* @__PURE__ */ jsx(AlertTitle, { children: "Could not load the connection" }),
231
+ /* @__PURE__ */ jsxs(AlertDescription, { children: [
232
+ /* @__PURE__ */ jsx("p", { children: connection.error.message }),
233
+ /* @__PURE__ */ jsx(
234
+ Button,
235
+ {
236
+ variant: "outline",
237
+ size: "sm",
238
+ className: "mt-2",
239
+ onClick: () => void connection.refetch(),
240
+ "data-test": "connect-retry",
241
+ children: "Try again"
242
+ }
243
+ )
244
+ ] })
245
+ ] });
163
246
  }
247
+ if (!connection.data) return /* @__PURE__ */ jsx(ConnectSkeleton, {});
164
248
  const state = connection.data;
165
249
  if (state.managed) {
166
250
  return /* @__PURE__ */ jsxs(Alert, { variant: "info", "data-test": "connect-managed", children: [
@@ -170,164 +254,352 @@ function ConnectPanel({
170
254
  }
171
255
  const noConnectionNeeded = state.facts.state === "no_connection_needed";
172
256
  const inDialog = surface === "dialog";
173
- const dirty = Object.values(drafts).some((value) => value !== "");
174
257
  const showActivationForm = state.fields.length === 0 && activationForm;
258
+ const activationCredentials = state.activationCredentials ?? [];
259
+ const keyNames = new Set(state.fields.map((field) => field.key));
260
+ const extraCredentials = activationCredentials.map((credential) => ({
261
+ ...credential,
262
+ fields: credential.fields.filter((field) => !keyNames.has(field.name))
263
+ })).filter((credential) => credential.fields.length > 0);
264
+ const steps = connectSteps(state, oauth, hints);
265
+ const activationNames = new Set(
266
+ activationCredentials.flatMap(
267
+ (credential) => credential.fields.map((field) => field.name)
268
+ )
269
+ );
270
+ const refresh = () => queryClient.invalidateQueries({ queryKey: consoleKeys.connection(slug) });
271
+ const keysForm = state.fields.length > 0 ? /* @__PURE__ */ jsx(
272
+ KeysForm,
273
+ {
274
+ slug,
275
+ state,
276
+ hints,
277
+ entry,
278
+ oauth,
279
+ saveLabel: noConnectionNeeded ? "Save settings" : "Save keys",
280
+ required: !noConnectionNeeded,
281
+ activationNames,
282
+ onSaved: async () => {
283
+ onChanged?.();
284
+ await refresh();
285
+ }
286
+ }
287
+ ) : null;
288
+ const oauthStep = oauth ? /* @__PURE__ */ jsx(
289
+ OAuthConnections,
290
+ {
291
+ integration: slug,
292
+ connections: state.oauthConnections ?? [],
293
+ hints,
294
+ disconnectable: !inDialog,
295
+ ...returnPath ? { returnPath } : {},
296
+ ...onChanged ? { onChanged } : {}
297
+ }
298
+ ) : null;
175
299
  return /* @__PURE__ */ jsxs(
176
300
  "div",
177
301
  {
178
- className: "flex w-full max-w-full min-w-0 flex-col gap-6",
302
+ className: "flex w-full max-w-full min-w-0 flex-col gap-8",
179
303
  "data-test": "connect-panel",
180
304
  children: [
181
- inDialog ? null : /* @__PURE__ */ jsx("p", { className: "text-muted-foreground text-xs", children: "Credentials are stored on this machine, in the integration repo. They never reach the browser, so a saved key shows as set, not its value." }),
182
305
  /* @__PURE__ */ jsxs(
183
- "div",
306
+ Card,
184
307
  {
185
- className: "flex max-w-xl flex-wrap items-center gap-x-3 gap-y-2",
186
- "data-test": "connect-target",
308
+ layout: "bleed",
309
+ render: /* @__PURE__ */ jsx("section", {}),
310
+ className: "flex min-w-0 flex-col gap-2 p-4",
311
+ "data-test": "connect-summary",
187
312
  children: [
188
- /* @__PURE__ */ jsx(ConnectionChip, { facts: state.facts }),
189
- noConnectionNeeded ? /* @__PURE__ */ jsx(
190
- "span",
313
+ /* @__PURE__ */ jsxs(
314
+ "div",
191
315
  {
192
- className: "text-muted-foreground text-xs",
193
- "data-test": "connect-optional",
194
- children: "Settings below are optional."
316
+ className: "flex min-w-0 flex-wrap items-center gap-x-3 gap-y-2",
317
+ "data-test": "connect-target",
318
+ children: [
319
+ /* @__PURE__ */ jsx(ConnectionChip, { facts: state.facts }),
320
+ noConnectionNeeded ? /* @__PURE__ */ jsx(
321
+ "span",
322
+ {
323
+ className: "text-muted-foreground text-xs",
324
+ "data-test": "connect-optional",
325
+ children: "Settings below are optional."
326
+ }
327
+ ) : null,
328
+ state.hasStored && !inDialog ? /* @__PURE__ */ jsx("span", { className: "ml-auto", children: /* @__PURE__ */ jsx(
329
+ ConfirmDialog,
330
+ {
331
+ trigger: /* @__PURE__ */ jsx(
332
+ Button,
333
+ {
334
+ variant: "destructive-ghost",
335
+ size: "sm",
336
+ disabled: disconnect.isPending,
337
+ "data-test": "disconnect",
338
+ children: "Disconnect"
339
+ }
340
+ ),
341
+ title: `Disconnect ${slug}?`,
342
+ description: oauth ? "This removes the stored connection data for this integration from this machine. The OAuth app keys stay; you can authorize again afterwards." : "This removes the stored keys for this integration from this machine, in its own folder only. You can enter new values afterwards.",
343
+ confirmLabel: "Disconnect",
344
+ confirmTestId: "confirm-disconnect",
345
+ onConfirm: async () => {
346
+ try {
347
+ await disconnect.mutateAsync(!oauth);
348
+ await refresh();
349
+ onChanged?.();
350
+ return true;
351
+ } catch (error) {
352
+ console.error("[harness] disconnect failed", error);
353
+ return false;
354
+ }
355
+ }
356
+ }
357
+ ) }) : null
358
+ ]
195
359
  }
196
- ) : null,
197
- state.hasStored && !inDialog ? /* @__PURE__ */ jsx(
198
- ConfirmDialog,
360
+ ),
361
+ state.facts.state === "not_connected" && !inDialog ? null : /* @__PURE__ */ jsx("p", { className: "text-sm", "data-test": "connect-summary-line", children: summaryLine(state, oauth) }),
362
+ inDialog ? null : /* @__PURE__ */ jsxs(
363
+ "p",
199
364
  {
200
- trigger: /* @__PURE__ */ jsx(
201
- Button,
202
- {
203
- variant: "ghost",
204
- size: "sm",
205
- disabled: disconnect.isPending,
206
- "data-test": "disconnect",
207
- children: "Disconnect"
208
- }
209
- ),
210
- title: `Disconnect ${integration.integration}?`,
211
- description: oauth ? "This removes the stored connection data for this integration from this machine. The OAuth app keys stay; you can connect again afterwards." : "This removes the stored keys for this integration from this machine, in its own folder only. You can enter new values afterwards.",
212
- confirmLabel: "Disconnect",
213
- onConfirm: async () => {
214
- try {
215
- await disconnect.mutateAsync(!oauth);
216
- setDrafts({});
217
- await queryClient.invalidateQueries({
218
- queryKey: consoleKeys.connection(integration.integration)
219
- });
220
- onChanged?.();
221
- return true;
222
- } catch (error) {
223
- console.error("[harness] disconnect failed", error);
224
- return false;
225
- }
226
- }
365
+ className: "text-muted-foreground flex gap-2 text-xs",
366
+ "data-test": "store-root",
367
+ children: [
368
+ /* @__PURE__ */ jsx(Icon, { name: "lock-simple", className: "mt-0.5 size-3.5 shrink-0" }),
369
+ /* @__PURE__ */ jsxs("span", { children: [
370
+ "Saved on this machine in",
371
+ " ",
372
+ /* @__PURE__ */ jsxs("code", { title: state.root, children: [
373
+ state.displayRoot ?? state.root ?? "the integration folder",
374
+ "/.ekanos/local-secrets.json"
375
+ ] }),
376
+ ", outside git. Values never reach the browser: a saved key shows as Set, never its value."
377
+ ] })
378
+ ]
227
379
  }
228
- ) : null
380
+ ),
381
+ disconnect.isError ? /* @__PURE__ */ jsx(Alert, { variant: "destructive", children: /* @__PURE__ */ jsxs(AlertDescription, { children: [
382
+ "Disconnect failed: ",
383
+ disconnect.error.message
384
+ ] }) }) : null
229
385
  ]
230
386
  }
231
387
  ),
232
- disconnect.isError ? /* @__PURE__ */ jsx(Alert, { variant: "destructive", children: /* @__PURE__ */ jsx(AlertDescription, { children: disconnect.error.message }) }) : null,
233
- state.runAs ? /* @__PURE__ */ jsx(
234
- RunAsSwitch,
235
- {
236
- integration: integration.integration,
237
- value: state.runAs
238
- }
239
- ) : null,
240
- /* @__PURE__ */ jsxs(
241
- "form",
388
+ steps.length > 0 ? /* @__PURE__ */ jsx(ConnectStepList, { children: steps.map((step, index) => /* @__PURE__ */ jsx(
389
+ ConnectStepItem,
242
390
  {
243
- className: "flex w-full max-w-xl min-w-0 flex-col gap-4",
244
- onSubmit: (event) => {
245
- event.preventDefault();
246
- const values = Object.fromEntries(
247
- Object.entries(drafts).filter(([, value]) => value !== "")
248
- );
249
- save.mutate(values, {
250
- onSuccess: () => {
251
- setDrafts({});
252
- onChanged?.();
253
- return queryClient.invalidateQueries({
254
- queryKey: consoleKeys.connection(integration.integration)
255
- });
256
- }
257
- });
258
- },
259
- children: [
260
- state.root ? /* @__PURE__ */ jsxs("p", { className: "text-muted-foreground text-xs", "data-test": "store-root", children: [
261
- "Store:",
262
- " ",
263
- /* @__PURE__ */ jsx("code", { title: state.root, children: state.displayRoot ?? state.root })
264
- ] }) : null,
265
- state.fields.length === 0 && !activationForm && (state.activationCredentials ?? []).length === 0 ? /* @__PURE__ */ jsx("p", { className: "text-muted-foreground text-sm", children: "This integration declares no keys." }) : null,
266
- state.fields.map((field) => /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1.5", children: [
267
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
268
- /* @__PURE__ */ jsx(
269
- Label,
270
- {
271
- htmlFor: `connect-${field.key}`,
272
- className: "text-sm font-medium",
273
- children: field.label
274
- }
275
- ),
276
- /* @__PURE__ */ jsx(StatusBadge, { tone: field.set ? "success" : "neutral", children: field.set ? "set" : "not set" })
277
- ] }),
278
- /* @__PURE__ */ jsx(
279
- Input,
280
- {
281
- id: `connect-${field.key}`,
282
- type: field.secret ? "password" : "text",
283
- autoComplete: "off",
284
- placeholder: field.set ? "Set" : "",
285
- value: drafts[field.key] ?? "",
286
- onChange: (event) => setDrafts({ ...drafts, [field.key]: event.target.value })
287
- }
288
- )
289
- ] }, field.key)),
290
- save.isError ? /* @__PURE__ */ jsx(Alert, { variant: "destructive", children: /* @__PURE__ */ jsx(AlertDescription, { children: save.error.message }) }) : null,
291
- state.fields.length > 0 ? /* @__PURE__ */ jsx(
292
- Button,
293
- {
294
- type: "submit",
295
- className: "self-start",
296
- disabled: !dirty || save.isPending,
297
- "data-test": "save-secrets",
298
- children: save.isPending ? "Saving\u2026" : noConnectionNeeded ? "Save settings" : "Save keys"
299
- }
300
- ) : null
301
- ]
302
- }
303
- ),
391
+ number: index + 1,
392
+ title: step.title,
393
+ status: step.status,
394
+ summary: step.summary,
395
+ last: index === steps.length - 1,
396
+ testId: `connect-step-${step.id}`,
397
+ children: step.id === "keys" ? keysForm : oauthStep
398
+ },
399
+ step.id
400
+ )) }) : /* @__PURE__ */ jsxs(Fragment, { children: [
401
+ keysForm,
402
+ oauthStep
403
+ ] }),
404
+ state.fields.length === 0 && !activationForm && activationCredentials.length === 0 ? /* @__PURE__ */ jsx("p", { className: "text-muted-foreground text-sm", children: "This integration declares no keys." }) : null,
304
405
  showActivationForm ? /* @__PURE__ */ jsx(
305
406
  ActivationConnect,
306
407
  {
307
- integration: integration.integration,
408
+ integration: slug,
308
409
  Form: showActivationForm,
309
410
  saveLabel: noConnectionNeeded,
310
411
  ...onChanged ? { onChanged } : {}
311
412
  }
312
413
  ) : null,
313
- !showActivationForm && (state.activationCredentials ?? []).length > 0 ? /* @__PURE__ */ jsx(
414
+ !showActivationForm && extraCredentials.length > 0 ? /* @__PURE__ */ jsx(
314
415
  ActivationCredentials,
315
416
  {
316
- integration: integration.integration,
317
- credentials: state.activationCredentials ?? [],
417
+ integration: slug,
418
+ credentials: extraCredentials,
419
+ hints,
318
420
  ...onChanged ? { onChanged } : {}
319
421
  }
320
422
  ) : null,
321
- oauth ? /* @__PURE__ */ jsx(
322
- OAuthConnections,
323
- {
324
- integration: integration.integration,
325
- connections: state.oauthConnections ?? [],
326
- disconnectable: !inDialog,
327
- ...returnPath ? { returnPath } : {},
328
- ...onChanged ? { onChanged } : {}
423
+ state.runAs ? /* @__PURE__ */ jsx(RunAsSwitch, { integration: slug, value: state.runAs }) : null
424
+ ]
425
+ }
426
+ );
427
+ }
428
+ function KeysForm({
429
+ slug,
430
+ state,
431
+ hints,
432
+ entry,
433
+ oauth,
434
+ saveLabel,
435
+ required,
436
+ activationNames,
437
+ onSaved
438
+ }) {
439
+ const [form, setForm] = useState({ drafts: {}, saved: null });
440
+ const save = useConsoleMutation(
441
+ (c, values) => c.saveSecrets(slug, values)
442
+ );
443
+ const remove = useConsoleMutation(
444
+ (c, key) => c.saveSecrets(slug, { [key]: "" })
445
+ );
446
+ const definition = entry?.definition;
447
+ const setup = useQuery({
448
+ queryKey: ["ekanos-harness", "local-setup", slug],
449
+ queryFn: () => fetchLocalSetup(
450
+ slug,
451
+ (input, init) => resolveOriginalFetch()(input, init)
452
+ ),
453
+ enabled: oauth && definition?.oauth !== void 0,
454
+ retry: false,
455
+ staleTime: Infinity
456
+ });
457
+ const redirectUri = setup.data?.redirectUri ?? null;
458
+ const groups = groupKeys(state, { slug, hints, required });
459
+ const typed = Object.fromEntries(
460
+ Object.entries(form.drafts).filter(([, value]) => value.trim() !== "")
461
+ );
462
+ const typedCount = Object.keys(typed).length;
463
+ return /* @__PURE__ */ jsxs(
464
+ "form",
465
+ {
466
+ className: "flex w-full min-w-0 flex-col gap-4",
467
+ "data-test": "keys-form",
468
+ autoComplete: "off",
469
+ onSubmit: (event) => {
470
+ event.preventDefault();
471
+ save.mutate(typed, {
472
+ onSuccess: async () => {
473
+ setForm({ drafts: {}, saved: typedCount });
474
+ await onSaved();
329
475
  }
330
- ) : null
476
+ });
477
+ },
478
+ children: [
479
+ groups.map((group) => {
480
+ const guide = group.connectionId && definition ? buildConnectionSetupGuide({
481
+ definition,
482
+ ...entry ? { entry } : {},
483
+ connectionId: group.connectionId,
484
+ redirectUri
485
+ }) : null;
486
+ return /* @__PURE__ */ jsx(
487
+ CredentialGroup,
488
+ {
489
+ title: group.title,
490
+ ...group.description ? { description: group.description } : {},
491
+ testId: `key-group-${group.id}`,
492
+ ...guide ? {
493
+ guide: /* @__PURE__ */ jsx(
494
+ SetupGuide,
495
+ {
496
+ guide,
497
+ testId: `setup-guide-${group.connectionId}`
498
+ }
499
+ )
500
+ } : {},
501
+ children: group.rows.map((row) => /* @__PURE__ */ jsx(
502
+ CredentialRow,
503
+ {
504
+ id: `connect-${row.name}`,
505
+ name: row.name,
506
+ label: row.label,
507
+ ...row.description ? { description: row.description } : {},
508
+ ...activationNames.has(row.name) ? {
509
+ note: "The activation form takes this too; when both hold a value, code reads this one."
510
+ } : {},
511
+ requirement: row.purpose.label,
512
+ primary: row.purpose.primary,
513
+ secret: row.secret,
514
+ set: row.set,
515
+ value: form.drafts[row.name] ?? "",
516
+ disabled: save.isPending,
517
+ testId: `key-${row.name}`,
518
+ onChange: (value) => setForm({
519
+ drafts: { ...form.drafts, [row.name]: value },
520
+ saved: null
521
+ }),
522
+ action: row.set ? /* @__PURE__ */ jsx(
523
+ ConfirmDialog,
524
+ {
525
+ trigger: /* @__PURE__ */ jsx(
526
+ Button,
527
+ {
528
+ type: "button",
529
+ variant: "ghost",
530
+ size: "xs",
531
+ disabled: remove.isPending,
532
+ "data-test": `remove-key-${row.name}`,
533
+ children: "Remove"
534
+ }
535
+ ),
536
+ title: `Remove ${row.label}?`,
537
+ description: `This clears ${row.name} from this machine. You can paste a new value afterwards.`,
538
+ confirmLabel: "Remove",
539
+ confirmTestId: `confirm-remove-key-${row.name}`,
540
+ onConfirm: async () => {
541
+ try {
542
+ await remove.mutateAsync(row.name);
543
+ await onSaved();
544
+ return true;
545
+ } catch (error) {
546
+ console.error(
547
+ "[harness] removing a key failed",
548
+ error
549
+ );
550
+ return false;
551
+ }
552
+ }
553
+ }
554
+ ) : void 0
555
+ },
556
+ row.name
557
+ ))
558
+ },
559
+ group.id
560
+ );
561
+ }),
562
+ remove.isError ? /* @__PURE__ */ jsx(Alert, { variant: "destructive", children: /* @__PURE__ */ jsxs(AlertDescription, { children: [
563
+ "Could not remove the key: ",
564
+ remove.error.message
565
+ ] }) }) : null,
566
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-3", children: [
567
+ /* @__PURE__ */ jsx(
568
+ Button,
569
+ {
570
+ type: "submit",
571
+ disabled: typedCount === 0 || save.isPending,
572
+ "data-test": "save-secrets",
573
+ children: save.isPending ? "Saving\u2026" : saveLabel
574
+ }
575
+ ),
576
+ save.isError ? /* @__PURE__ */ jsxs(
577
+ "span",
578
+ {
579
+ className: "text-destructive text-sm",
580
+ role: "alert",
581
+ "data-test": "save-secrets-error",
582
+ children: [
583
+ "Not saved: ",
584
+ save.error.message
585
+ ]
586
+ }
587
+ ) : form.saved !== null ? /* @__PURE__ */ jsxs(
588
+ "span",
589
+ {
590
+ className: "text-muted-foreground text-sm",
591
+ role: "status",
592
+ "data-test": "save-secrets-done",
593
+ children: [
594
+ "Saved ",
595
+ form.saved,
596
+ " ",
597
+ form.saved === 1 ? "key" : "keys",
598
+ "."
599
+ ]
600
+ }
601
+ ) : /* @__PURE__ */ jsx("span", { className: "text-muted-foreground text-xs", children: typedCount === 0 ? "Type a value to save it. Blank fields keep what is saved." : `${typedCount} ${typedCount === 1 ? "key" : "keys"} to save. Blank fields keep what is saved.` })
602
+ ] })
331
603
  ]
332
604
  }
333
605
  );
@@ -335,6 +607,7 @@ function ConnectPanel({
335
607
  function OAuthConnections({
336
608
  integration,
337
609
  connections,
610
+ hints,
338
611
  disconnectable,
339
612
  returnPath,
340
613
  onChanged
@@ -354,136 +627,189 @@ function OAuthConnections({
354
627
  }
355
628
  ];
356
629
  const single = connections.length === 0;
357
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", "data-test": "oauth-block", children: [
358
- /* @__PURE__ */ jsx("h3", { className: "text-sm font-medium", children: "OAuth" }),
630
+ return /* @__PURE__ */ jsxs("div", { className: "flex min-w-0 flex-col gap-3", "data-test": "oauth-block", children: [
359
631
  /* @__PURE__ */ jsxs("p", { className: "text-muted-foreground text-xs", children: [
360
- "Runs the real authorize and callback loop on localhost, with your own provider app credentials (save them above first).",
632
+ "Authorize runs the real sign-in and callback loop on localhost with your app keys, then comes back here.",
361
633
  rows.length > 1 ? " Each connection has its own app, consent and tokens." : ""
362
634
  ] }),
363
- disconnect.isError ? /* @__PURE__ */ jsx(Alert, { variant: "destructive", children: /* @__PURE__ */ jsx(AlertDescription, { children: disconnect.error.message }) }) : null,
364
- rows.map((connection) => {
365
- const missing = connection.keys.filter((key) => !key.set);
366
- const params = Object.entries(connection.authorizationParams ?? {});
367
- return /* @__PURE__ */ jsxs(
368
- "div",
369
- {
370
- className: "flex max-w-xl flex-col gap-2 rounded-md border p-3",
371
- "data-test": `oauth-connection-${connection.id}`,
372
- children: [
373
- single ? null : /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [
374
- /* @__PURE__ */ jsx("span", { className: "text-sm font-medium", children: connection.label }),
375
- /* @__PURE__ */ jsx("code", { className: "text-muted-foreground text-xs", children: connection.id }),
376
- /* @__PURE__ */ jsx(
377
- StatusBadge,
378
- {
379
- tone: connection.connected ? "success" : "neutral",
380
- children: connection.connected ? "connected" : "not connected"
381
- }
382
- ),
383
- /* @__PURE__ */ jsx(
384
- LevelBadge,
385
- {
386
- level: connection.level ?? "team",
387
- testId: `oauth-connection-level-${connection.id}`
388
- }
389
- )
390
- ] }),
391
- connection.description ? /* @__PURE__ */ jsx("p", { className: "text-muted-foreground text-xs", children: connection.description }) : null,
392
- connection.teamApp ? /* @__PURE__ */ jsxs("p", { className: "text-muted-foreground text-xs", children: [
393
- "The team brings its own app for this connection. Here, its fields are the keys above:",
394
- " ",
395
- connection.keys.map((key) => key.label).join(", "),
396
- "."
397
- ] }) : null,
398
- params.length > 0 ? /* @__PURE__ */ jsxs("p", { className: "text-muted-foreground text-xs", children: [
399
- "Sends",
400
- " ",
401
- params.map(([key, value]) => /* @__PURE__ */ jsxs("code", { className: "mr-1", children: [
402
- key,
403
- "=",
404
- value
405
- ] }, key)),
406
- "to the provider."
407
- ] }) : null,
408
- connection.connectAs ? /* @__PURE__ */ jsx(
409
- ConnectAsSwitch,
410
- {
411
- integration,
412
- credential: `oauth:${connection.id}`,
413
- value: connection.connectAs,
414
- testId: `oauth-connect-as-${connection.id}`
415
- }
416
- ) : null,
417
- missing.length > 0 ? /* @__PURE__ */ jsxs(
418
- "p",
419
- {
420
- className: "text-muted-foreground text-xs",
421
- "data-test": `oauth-connection-missing-${connection.id}`,
422
- children: [
423
- "Save ",
424
- missing.map((key) => key.label).join(", "),
425
- " first."
426
- ]
427
- }
428
- ) : null,
429
- /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [
430
- /* @__PURE__ */ jsx(
431
- Button,
432
- {
433
- variant: "outline",
434
- className: "self-start",
435
- "data-test": connection.id === "default" ? "start-oauth" : `start-oauth-${connection.id}`,
436
- nativeButton: false,
437
- render: /* @__PURE__ */ jsx(
438
- "a",
635
+ /* @__PURE__ */ jsx(
636
+ "div",
637
+ {
638
+ className: cn(
639
+ "grid min-w-0 gap-3",
640
+ rows.length > 1 && "lg:grid-cols-2"
641
+ ),
642
+ children: rows.map((connection) => {
643
+ const blocker = authorizeBlocker(connection, hints, integration);
644
+ const params = Object.entries(connection.authorizationParams ?? {});
645
+ const name = connection.id === "default" ? connection.label.toLowerCase() : connection.label;
646
+ const label = single ? "Authorize with OAuth" : connection.connected ? `Reauthorize ${name}` : `Authorize ${name}`;
647
+ const testId = connection.id === "default" ? "start-oauth" : `start-oauth-${connection.id}`;
648
+ const failed = disconnect.isError && disconnect.variables?.connection === connection.id;
649
+ return /* @__PURE__ */ jsxs(
650
+ Card,
651
+ {
652
+ layout: "bleed",
653
+ className: "flex min-w-0 flex-col gap-3 p-4",
654
+ "data-test": `oauth-connection-${connection.id}`,
655
+ children: [
656
+ single ? null : /* @__PURE__ */ jsxs("div", { className: "flex min-w-0 items-baseline justify-between gap-2", children: [
657
+ /* @__PURE__ */ jsx("span", { className: "text-sm font-semibold", children: connection.label }),
658
+ /* @__PURE__ */ jsx(
659
+ "code",
439
660
  {
440
- href: oauthConnectHref(
441
- integration,
442
- connection.id,
443
- returnPath,
444
- connection.connectAs
445
- )
661
+ className: "text-muted-foreground truncate font-mono text-xs",
662
+ title: "Connection id",
663
+ children: connection.id
664
+ }
665
+ )
666
+ ] }),
667
+ /* @__PURE__ */ jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-2", children: [
668
+ /* @__PURE__ */ jsx(
669
+ StatusBadge,
670
+ {
671
+ tone: connection.connected ? "success" : "neutral",
672
+ "data-test": `oauth-connection-status-${connection.id}`,
673
+ children: connection.connected ? "Authorized" : "Not authorized"
446
674
  }
447
675
  ),
448
- children: single ? "Connect with OAuth" : connection.connected ? `Reconnect ${connection.label}` : `Connect ${connection.label}`
449
- }
450
- ),
451
- disconnectable && connection.connected ? /* @__PURE__ */ jsx(
452
- Button,
453
- {
454
- variant: "ghost",
455
- size: "sm",
456
- disabled: disconnect.isPending,
457
- "data-test": `disconnect-oauth-${connection.id}`,
458
- onClick: () => disconnect.mutate(
459
- { connection: connection.id, as: connection.connectAs },
676
+ single ? null : /* @__PURE__ */ jsx(
677
+ LevelBadge,
460
678
  {
461
- onSuccess: async () => {
462
- await queryClient.invalidateQueries({
463
- queryKey: consoleKeys.connection(integration)
464
- });
465
- onChanged?.();
466
- }
679
+ level: connection.level ?? "team",
680
+ testId: `oauth-connection-level-${connection.id}`
681
+ }
682
+ )
683
+ ] }),
684
+ connection.description ? /* @__PURE__ */ jsx("p", { className: "text-muted-foreground text-xs", children: connection.description }) : null,
685
+ connection.connected && connection.obtainedAt ? /* @__PURE__ */ jsxs(
686
+ "p",
687
+ {
688
+ className: "text-sm",
689
+ "data-test": `oauth-connection-since-${connection.id}`,
690
+ children: [
691
+ "Authorized ",
692
+ formatWhen(connection.obtainedAt),
693
+ ". Tokens live in the dev server's memory; a restart means authorizing again."
694
+ ]
695
+ }
696
+ ) : null,
697
+ params.length > 0 ? /* @__PURE__ */ jsxs("p", { className: "text-muted-foreground text-xs", children: [
698
+ "Sends",
699
+ " ",
700
+ params.map(([key, value]) => /* @__PURE__ */ jsxs("code", { className: "mr-1 font-mono", children: [
701
+ key,
702
+ "=",
703
+ value
704
+ ] }, key)),
705
+ "to the provider."
706
+ ] }) : null,
707
+ connection.connectAs ? /* @__PURE__ */ jsx(
708
+ ConnectAsSwitch,
709
+ {
710
+ integration,
711
+ credential: `oauth:${connection.id}`,
712
+ value: connection.connectAs,
713
+ testId: `oauth-connect-as-${connection.id}`
714
+ }
715
+ ) : null,
716
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [
717
+ blocker ? /* @__PURE__ */ jsx(
718
+ Button,
719
+ {
720
+ type: "button",
721
+ variant: connection.connected ? "outline" : "default",
722
+ disabled: true,
723
+ "aria-describedby": `oauth-connection-missing-${connection.id}`,
724
+ "data-test": testId,
725
+ children: label
726
+ }
727
+ ) : /* @__PURE__ */ jsx(
728
+ Button,
729
+ {
730
+ variant: connection.connected ? "outline" : "default",
731
+ "data-test": testId,
732
+ nativeButton: false,
733
+ render: /* @__PURE__ */ jsx(
734
+ "a",
735
+ {
736
+ href: oauthConnectHref(
737
+ integration,
738
+ connection.id,
739
+ returnPath,
740
+ connection.connectAs
741
+ )
742
+ }
743
+ ),
744
+ children: label
467
745
  }
468
746
  ),
469
- children: "Disconnect"
470
- }
471
- ) : null
472
- ] })
473
- ]
474
- },
475
- connection.id
476
- );
477
- })
747
+ disconnectable && connection.connected ? /* @__PURE__ */ jsx(
748
+ ConfirmDialog,
749
+ {
750
+ trigger: /* @__PURE__ */ jsx(
751
+ Button,
752
+ {
753
+ variant: "destructive-ghost",
754
+ size: "sm",
755
+ disabled: disconnect.isPending,
756
+ "data-test": `disconnect-oauth-${connection.id}`,
757
+ children: "Disconnect"
758
+ }
759
+ ),
760
+ title: `Disconnect ${connection.label}?`,
761
+ description: "This forgets this connection's tokens on this machine. Its app keys and the other connections stay.",
762
+ confirmLabel: "Disconnect",
763
+ confirmTestId: `confirm-disconnect-oauth-${connection.id}`,
764
+ onConfirm: async () => {
765
+ try {
766
+ await disconnect.mutateAsync({
767
+ connection: connection.id,
768
+ as: connection.connectAs
769
+ });
770
+ await queryClient.invalidateQueries({
771
+ queryKey: consoleKeys.connection(integration)
772
+ });
773
+ onChanged?.();
774
+ return true;
775
+ } catch (error) {
776
+ console.error("[harness] disconnect failed", error);
777
+ return false;
778
+ }
779
+ }
780
+ }
781
+ ) : null
782
+ ] }),
783
+ blocker ? /* @__PURE__ */ jsx(
784
+ "p",
785
+ {
786
+ id: `oauth-connection-missing-${connection.id}`,
787
+ className: "text-muted-foreground text-xs",
788
+ "data-test": `oauth-connection-missing-${connection.id}`,
789
+ children: blocker
790
+ }
791
+ ) : null,
792
+ failed ? /* @__PURE__ */ jsxs("p", { className: "text-destructive text-xs", role: "alert", children: [
793
+ "Disconnect failed: ",
794
+ disconnect.error.message
795
+ ] }) : null
796
+ ]
797
+ },
798
+ connection.id
799
+ );
800
+ })
801
+ }
802
+ )
478
803
  ] });
479
804
  }
480
805
  function ActivationCredentials({
481
806
  integration,
482
807
  credentials,
808
+ hints,
483
809
  onChanged
484
810
  }) {
485
811
  const queryClient = useQueryClient();
486
- const [drafts, setDrafts] = useState({});
812
+ const [form, setForm] = useState({ drafts: {}, saved: null });
487
813
  const save = useConsoleMutation(
488
814
  async (c, groups) => {
489
815
  for (const [as, values] of groups) {
@@ -494,20 +820,25 @@ function ActivationCredentials({
494
820
  }
495
821
  }
496
822
  );
497
- const dirty = Object.values(drafts).some((value) => value !== "");
823
+ const typed = Object.fromEntries(
824
+ Object.entries(form.drafts).filter(([, value]) => value !== "")
825
+ );
826
+ const typedCount = Object.keys(typed).length;
498
827
  const perPerson = credentials.some(
499
828
  (credential) => credential.level === "user" && !credential.connectAs
500
829
  );
830
+ const allOptional = credentials.every(
831
+ (credential) => credential.fields.every((field) => !field.required)
832
+ );
833
+ const single = credentials.length === 1;
501
834
  return /* @__PURE__ */ jsxs(
502
835
  "form",
503
836
  {
504
- className: "flex w-full max-w-xl min-w-0 flex-col gap-3",
837
+ className: "flex w-full min-w-0 flex-col gap-4 border-t pt-6",
505
838
  "data-test": "activation-credentials",
839
+ autoComplete: "off",
506
840
  onSubmit: (event) => {
507
841
  event.preventDefault();
508
- const typed = Object.fromEntries(
509
- Object.entries(drafts).filter(([, value]) => value !== "")
510
- );
511
842
  const groups = /* @__PURE__ */ new Map();
512
843
  for (const credential of credentials) {
513
844
  for (const field of credential.fields) {
@@ -521,7 +852,7 @@ function ActivationCredentials({
521
852
  }
522
853
  save.mutate([...groups], {
523
854
  onSuccess: () => {
524
- setDrafts({});
855
+ setForm({ drafts: {}, saved: typedCount });
525
856
  onChanged?.();
526
857
  return queryClient.invalidateQueries({
527
858
  queryKey: consoleKeys.connection(integration)
@@ -530,24 +861,32 @@ function ActivationCredentials({
530
861
  });
531
862
  },
532
863
  children: [
533
- /* @__PURE__ */ jsx("h3", { className: "text-sm font-medium", children: "Activation credentials" }),
534
- perPerson ? /* @__PURE__ */ jsx("p", { className: "text-muted-foreground text-xs", children: "The harness keeps one local store, so a credential for you is stored beside the team's and every call can read it." }) : null,
535
- credentials.map((credential) => /* @__PURE__ */ jsxs(
536
- "div",
864
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
865
+ /* @__PURE__ */ jsx("h3", { className: "font-heading font-heading-title text-base", children: allOptional ? "Optional credentials" : "More credentials" }),
866
+ /* @__PURE__ */ jsxs("p", { className: "text-muted-foreground text-xs", children: [
867
+ "The integration's own fields, read with",
868
+ " ",
869
+ /* @__PURE__ */ jsx("code", { className: "font-mono", children: "ctx.secrets.get(name)" }),
870
+ ".",
871
+ " ",
872
+ allOptional ? "Connecting does not need them; add the ones your code uses." : "Stored beside the keys above.",
873
+ " ",
874
+ perPerson ? "The harness keeps one local store, so a credential for you is stored beside the team\u2019s and every call can read it." : null
875
+ ] })
876
+ ] }),
877
+ credentials.map((credential) => /* @__PURE__ */ jsx(
878
+ CredentialGroup,
537
879
  {
538
- className: "flex flex-col gap-2 rounded-md border p-3",
539
- "data-test": `activation-credential-${credential.id}`,
540
- children: [
541
- /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [
542
- /* @__PURE__ */ jsx("span", { className: "text-sm font-medium", children: credential.label }),
543
- /* @__PURE__ */ jsx(
544
- LevelBadge,
545
- {
546
- level: credential.level,
547
- testId: `activation-credential-level-${credential.id}`
548
- }
549
- )
550
- ] }),
880
+ title: single && credential.id === "activation" ? "" : credential.label,
881
+ testId: `activation-credential-${credential.id}`,
882
+ aside: /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-start gap-2 pt-1", children: [
883
+ /* @__PURE__ */ jsx(
884
+ LevelBadge,
885
+ {
886
+ level: credential.level,
887
+ testId: `activation-credential-level-${credential.id}`
888
+ }
889
+ ),
551
890
  credential.connectAs ? /* @__PURE__ */ jsx(
552
891
  ConnectAsSwitch,
553
892
  {
@@ -556,52 +895,53 @@ function ActivationCredentials({
556
895
  value: credential.connectAs,
557
896
  testId: `activation-connect-as-${credential.id}`
558
897
  }
559
- ) : null,
560
- credential.fields.map((field) => /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1.5", children: [
561
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
562
- /* @__PURE__ */ jsxs(
563
- Label,
564
- {
565
- htmlFor: `activation-${field.name}`,
566
- className: "text-sm font-medium",
567
- children: [
568
- field.label,
569
- field.required ? null : /* @__PURE__ */ jsxs("span", { className: "text-muted-foreground font-normal", children: [
570
- " ",
571
- "(optional)"
572
- ] })
573
- ]
574
- }
575
- ),
576
- /* @__PURE__ */ jsx(StatusBadge, { tone: field.set ? "success" : "neutral", children: field.set ? "set" : "not set" })
577
- ] }),
578
- /* @__PURE__ */ jsx(
579
- Input,
580
- {
581
- id: `activation-${field.name}`,
582
- type: "password",
583
- autoComplete: "off",
584
- placeholder: field.set ? "Set" : "",
585
- value: drafts[field.name] ?? "",
586
- onChange: (event) => setDrafts({ ...drafts, [field.name]: event.target.value })
587
- }
588
- )
589
- ] }, field.name))
590
- ]
898
+ ) : null
899
+ ] }),
900
+ children: activationRows(credential, { hints }).map((row) => /* @__PURE__ */ jsx(
901
+ CredentialRow,
902
+ {
903
+ id: `activation-${row.name}`,
904
+ name: row.name,
905
+ label: row.label,
906
+ ...row.description ? { description: row.description } : {},
907
+ requirement: row.required ? "Required" : "Optional",
908
+ secret: true,
909
+ set: row.set,
910
+ value: form.drafts[row.name] ?? "",
911
+ disabled: save.isPending,
912
+ testId: `activation-field-${row.name}`,
913
+ onChange: (value) => setForm({
914
+ drafts: { ...form.drafts, [row.name]: value },
915
+ saved: null
916
+ })
917
+ },
918
+ row.name
919
+ ))
591
920
  },
592
921
  credential.id
593
922
  )),
594
- save.isError ? /* @__PURE__ */ jsx(Alert, { variant: "destructive", children: /* @__PURE__ */ jsx(AlertDescription, { children: save.error.message }) }) : null,
595
- /* @__PURE__ */ jsx(
596
- Button,
597
- {
598
- type: "submit",
599
- className: "self-start",
600
- disabled: !dirty || save.isPending,
601
- "data-test": "save-activation-credentials",
602
- children: save.isPending ? "Saving\u2026" : "Save credentials"
603
- }
604
- )
923
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-3", children: [
924
+ /* @__PURE__ */ jsx(
925
+ Button,
926
+ {
927
+ type: "submit",
928
+ variant: "outline",
929
+ disabled: typedCount === 0 || save.isPending,
930
+ "data-test": "save-activation-credentials",
931
+ children: save.isPending ? "Saving\u2026" : "Save credentials"
932
+ }
933
+ ),
934
+ save.isError ? /* @__PURE__ */ jsxs("span", { className: "text-destructive text-sm", role: "alert", children: [
935
+ "Not saved: ",
936
+ save.error.message
937
+ ] }) : form.saved !== null ? /* @__PURE__ */ jsxs("span", { className: "text-muted-foreground text-sm", role: "status", children: [
938
+ "Saved ",
939
+ form.saved,
940
+ " ",
941
+ form.saved === 1 ? "credential" : "credentials",
942
+ "."
943
+ ] }) : /* @__PURE__ */ jsx("span", { className: "text-muted-foreground text-xs", children: typedCount === 0 ? "Type a value to save it. Blank fields keep what is saved." : `${typedCount} to save.` })
944
+ ] })
605
945
  ]
606
946
  }
607
947
  );
@@ -642,11 +982,11 @@ function ActivationConnect({
642
982
  return /* @__PURE__ */ jsxs(
643
983
  "div",
644
984
  {
645
- className: "flex w-full max-w-xl min-w-0 flex-col gap-3 [&_*]:min-w-0 [&_.grid]:grid-cols-[minmax(0,1fr)] [&_fieldset]:min-w-0 [&_form]:min-w-0 [&_input]:max-w-full [&_label]:[overflow-wrap:anywhere] [&_p]:[overflow-wrap:anywhere] [&_textarea]:max-w-full",
985
+ className: "flex w-full max-w-3xl min-w-0 flex-col gap-3 [&_*]:min-w-0 [&_.grid]:grid-cols-[minmax(0,1fr)] [&_fieldset]:min-w-0 [&_form]:min-w-0 [&_input]:max-w-full [&_label]:[overflow-wrap:anywhere] [&_p]:[overflow-wrap:anywhere] [&_textarea]:max-w-full",
646
986
  "data-test": "connect-activation",
647
987
  children: [
648
988
  /* @__PURE__ */ jsx("p", { className: "text-muted-foreground text-xs", children: "This is the integration's own connect form. What you enter is stored on this machine as its local credentials, and live operations read it from there." }),
649
- /* @__PURE__ */ jsx(IntegrationActivationProvider, { actions, children: /* @__PURE__ */ jsx(TeamAccountWorkspaceContextProvider, { children: /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(SettingsLabels, { enabled: saveLabel, children: /* @__PURE__ */ jsx(
989
+ /* @__PURE__ */ jsx(IntegrationActivationProvider, { actions, children: /* @__PURE__ */ jsx(TeamAccountWorkspaceContextProvider, { children: /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx(Skeleton, { className: "h-40 w-full rounded-lg" }), children: /* @__PURE__ */ jsx(SettingsLabels, { enabled: saveLabel, children: /* @__PURE__ */ jsx(
650
990
  Form,
651
991
  {
652
992
  accountId: HARNESS_ACCOUNT_ID,