@ekanos/harness 0.24.0 → 0.26.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.
- package/README.md +3 -4
- package/dist/api-types.d.ts +98 -0
- package/dist/internal/components/approvals-tray.js +1 -1
- package/dist/internal/components/ask-assistant-bridge.js +2 -8
- package/dist/internal/components/connect-panel.js +414 -20
- package/dist/internal/components/dev-toolbar.js +3 -3
- package/dist/internal/components/docs-link.js +1 -1
- package/dist/internal/components/integration-badge.js +3 -3
- package/dist/internal/components/local-oauth-panel.js +28 -2
- package/dist/internal/components/provenance-banner.js +2 -2
- package/dist/internal/components/schema-form.js +1 -1
- package/dist/internal/components/surface-nav.js +20 -20
- package/dist/internal/components/widget-boundary.js +1 -7
- package/dist/internal/lib/console-client.d.ts +22 -5
- package/dist/internal/lib/console-client.js +32 -6
- package/dist/internal/lib/console-context.js +14 -2
- package/dist/internal/lib/console-types.d.ts +11 -1
- package/dist/internal/lib/experience-runtime.d.ts +20 -0
- package/dist/internal/lib/experience-runtime.js +16 -1
- package/dist/internal/lib/oauth-connect-href.d.ts +9 -0
- package/dist/internal/lib/oauth-connect-href.js +14 -0
- package/dist/internal/lib/run-log-view.js +1 -0
- package/dist/internal/lib/trigger-contract.d.ts +19 -0
- package/dist/internal/lib/trigger-runner.js +4 -1
- package/dist/internal/routes/experience-page-host.d.ts +5 -1
- package/dist/internal/routes/experience-page-host.js +9 -8
- package/dist/internal/routes/repo-home-page.js +1 -1
- package/dist/internal/routes/repo-layout.js +3 -5
- package/dist/internal/routes/root-layout.d.ts +0 -1
- package/dist/internal/routes/root-layout.js +2 -4
- package/dist/internal/routes/tile-page.js +1 -1
- package/dist/internal/routes/triggers-page.js +30 -2
- package/dist/internal/server/activation-credentials.d.ts +26 -0
- package/dist/internal/server/activation-credentials.js +56 -0
- package/dist/internal/server/api-router.js +63 -5
- package/dist/internal/server/console-state.d.ts +25 -0
- package/dist/internal/server/console-state.js +44 -0
- package/dist/internal/server/ekanos-api-router.js +168 -4
- package/dist/internal/server/live-context.js +2 -1
- package/dist/internal/server/live-invoker.js +10 -2
- package/dist/internal/server/local-secrets.d.ts +47 -0
- package/dist/internal/server/local-secrets.js +111 -2
- package/dist/internal/server/local-state.d.ts +8 -2
- package/dist/internal/server/local-state.js +26 -9
- package/dist/internal/server/nonce-store.d.ts +2 -0
- package/dist/internal/server/oauth-connections.d.ts +45 -0
- package/dist/internal/server/oauth-connections.js +69 -0
- package/dist/internal/server/oauth-loop.d.ts +1 -1
- package/dist/internal/server/oauth-loop.js +4 -1
- package/dist/internal/server/oauth-persistence.d.ts +13 -0
- package/dist/internal/server/oauth-persistence.js +28 -0
- package/dist/internal/server/operation-runner.js +21 -1
- package/dist/internal/server/person-context.d.ts +35 -0
- package/dist/internal/server/person-context.js +115 -0
- package/dist/internal/server/semantics.d.ts +1 -1
- package/dist/internal/surfaces.d.ts +1 -1
- package/dist/internal/surfaces.js +4 -4
- package/dist/registry.d.ts +7 -0
- package/dist/registry.js +4 -0
- package/dist/styles.css +3 -168
- package/package.json +13 -13
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import Link from "next/link";
|
|
4
4
|
import { notFound, useParams } from "next/navigation";
|
|
5
|
+
import { PageBody } from "@ekanos/ui/page";
|
|
5
6
|
import { cn } from "@ekanos/ui/utils";
|
|
6
7
|
import { WidgetSurface } from "../components/widget-surface.js";
|
|
7
8
|
import { useConsoleLinks, useExperienceSurfaces } from "../lib/console-context.js";
|
|
@@ -25,16 +26,16 @@ function ExperiencePageHost() {
|
|
|
25
26
|
return /* @__PURE__ */ jsxs(
|
|
26
27
|
"div",
|
|
27
28
|
{
|
|
28
|
-
className: "flex flex-col
|
|
29
|
+
className: "flex flex-col",
|
|
29
30
|
"data-test": "experience-page",
|
|
30
31
|
"data-page-kind": kind,
|
|
31
32
|
children: [
|
|
32
|
-
/* @__PURE__ */ jsx("
|
|
33
|
+
/* @__PURE__ */ jsx("h1", { className: "font-heading px-4 pt-4 text-xl font-normal", children: page.title }),
|
|
33
34
|
page.routes && page.routes.length > 0 ? /* @__PURE__ */ jsx(
|
|
34
35
|
"nav",
|
|
35
36
|
{
|
|
36
37
|
"aria-label": `${page.title} sections`,
|
|
37
|
-
className: "flex flex-wrap gap-1",
|
|
38
|
+
className: "flex flex-wrap gap-1 px-4 pt-3",
|
|
38
39
|
"data-test": "experience-page-routes",
|
|
39
40
|
children: [{ path: "", title: page.title }, ...page.routes].map((route) => /* @__PURE__ */ jsx(
|
|
40
41
|
Link,
|
|
@@ -43,7 +44,7 @@ function ExperiencePageHost() {
|
|
|
43
44
|
"aria-current": route.path === sub ? "page" : void 0,
|
|
44
45
|
className: cn(
|
|
45
46
|
"rounded-md px-3 py-2 text-sm",
|
|
46
|
-
route.path === sub ? "bg-accent text-accent-foreground text-sm font-medium" : "text-muted-foreground hover:bg-accent
|
|
47
|
+
route.path === sub ? "bg-accent text-accent-foreground text-sm font-medium" : "text-muted-foreground hover:bg-accent"
|
|
47
48
|
),
|
|
48
49
|
children: route.title
|
|
49
50
|
},
|
|
@@ -51,7 +52,7 @@ function ExperiencePageHost() {
|
|
|
51
52
|
))
|
|
52
53
|
}
|
|
53
54
|
) : null,
|
|
54
|
-
kind === "canvas" ? /* @__PURE__ */ jsx(
|
|
55
|
+
/* @__PURE__ */ jsx(PageBody, { children: kind === "canvas" ? /* @__PURE__ */ jsx(
|
|
55
56
|
WidgetSurface,
|
|
56
57
|
{
|
|
57
58
|
widgets: widgets.filter(
|
|
@@ -59,7 +60,7 @@ function ExperiencePageHost() {
|
|
|
59
60
|
),
|
|
60
61
|
productSlug
|
|
61
62
|
}
|
|
62
|
-
) : Page ? /* @__PURE__ */ jsx(
|
|
63
|
+
) : Page ? /* @__PURE__ */ jsx(Page, { path }) : /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
63
64
|
/* @__PURE__ */ jsx(
|
|
64
65
|
"p",
|
|
65
66
|
{
|
|
@@ -69,7 +70,7 @@ function ExperiencePageHost() {
|
|
|
69
70
|
}
|
|
70
71
|
),
|
|
71
72
|
/* @__PURE__ */ jsx(WidgetSurface, { widgets, productSlug })
|
|
72
|
-
] })
|
|
73
|
+
] }) })
|
|
73
74
|
]
|
|
74
75
|
}
|
|
75
76
|
);
|
|
@@ -25,7 +25,7 @@ function Count({
|
|
|
25
25
|
testId
|
|
26
26
|
}) {
|
|
27
27
|
return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", "data-test": testId, children: [
|
|
28
|
-
/* @__PURE__ */ jsx("span", { className: "font-heading text-2xl
|
|
28
|
+
/* @__PURE__ */ jsx("span", { className: "font-heading font-heading-semibold text-2xl tracking-tight", children: value }),
|
|
29
29
|
/* @__PURE__ */ jsx("span", { className: "text-muted-foreground text-xs", children: label })
|
|
30
30
|
] });
|
|
31
31
|
}
|
|
@@ -7,9 +7,7 @@ import { Icon } from "@ekanos/ui/icon";
|
|
|
7
7
|
import { cn } from "@ekanos/ui/utils";
|
|
8
8
|
import { FOCUS_RING, ScrollableNav } from "../components/scrollable-nav.js";
|
|
9
9
|
import { RepoProviders, useRepo } from "../lib/repo-context.js";
|
|
10
|
-
const TABS = [
|
|
11
|
-
{ href: "/", label: "This repo", icon: "fa-table-list" }
|
|
12
|
-
];
|
|
10
|
+
const TABS = [{ href: "/", label: "This repo", icon: "columns" }];
|
|
13
11
|
function repoName(root) {
|
|
14
12
|
return root.split(/[\\/]/).filter(Boolean).pop() ?? root;
|
|
15
13
|
}
|
|
@@ -19,7 +17,7 @@ function RepoFrame({ children }) {
|
|
|
19
17
|
return /* @__PURE__ */ jsxs("div", { className: "flex min-h-screen flex-col", "data-test": "repo-frame", children: [
|
|
20
18
|
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3 border-b px-4 py-4 sm:px-6", children: [
|
|
21
19
|
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-baseline gap-3", children: [
|
|
22
|
-
/* @__PURE__ */ jsx("h1", { className: "font-heading text-2xl
|
|
20
|
+
/* @__PURE__ */ jsx("h1", { className: "font-heading font-heading-semibold text-2xl tracking-tight", children: repo.data ? repoName(repo.data.root) : "This repo" }),
|
|
23
21
|
/* @__PURE__ */ jsx("code", { className: "text-muted-foreground text-xs", children: "repo" })
|
|
24
22
|
] }),
|
|
25
23
|
/* @__PURE__ */ jsx(ScrollableNav, { label: "Repo", children: TABS.map((tab) => {
|
|
@@ -32,7 +30,7 @@ function RepoFrame({ children }) {
|
|
|
32
30
|
className: cn(
|
|
33
31
|
"flex items-center gap-2 rounded-md px-3 py-2 whitespace-nowrap transition-colors",
|
|
34
32
|
FOCUS_RING,
|
|
35
|
-
active ? "bg-accent text-accent-foreground text-sm font-medium" : "text-muted-foreground hover:bg-accent
|
|
33
|
+
active ? "bg-accent text-accent-foreground text-sm font-medium" : "text-muted-foreground hover:bg-accent text-sm"
|
|
36
34
|
),
|
|
37
35
|
children: [
|
|
38
36
|
/* @__PURE__ */ jsx(Icon, { name: tab.icon, className: "h-4 w-4" }),
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
-
import "@fortawesome/fontawesome-free/css/all.min.css";
|
|
4
|
-
import { IconStyleOverrideProvider } from "@ekanos/ui/icon";
|
|
5
3
|
import { cn } from "@ekanos/ui/utils";
|
|
6
4
|
import { ThemeProvider } from "next-themes";
|
|
7
5
|
import { DevToolbar } from "../components/dev-toolbar.js";
|
|
@@ -18,7 +16,7 @@ function RootLayout({
|
|
|
18
16
|
"body",
|
|
19
17
|
{
|
|
20
18
|
className: cn("bg-background text-foreground min-h-screen antialiased"),
|
|
21
|
-
children: /* @__PURE__ */ jsx(
|
|
19
|
+
children: /* @__PURE__ */ jsx(HarnessRegistryProvider, { integrations, children: /* @__PURE__ */ jsx(I18nProvider, { children: /* @__PURE__ */ jsx(
|
|
22
20
|
ThemeProvider,
|
|
23
21
|
{
|
|
24
22
|
attribute: "class",
|
|
@@ -40,7 +38,7 @@ function RootLayout({
|
|
|
40
38
|
children
|
|
41
39
|
] })
|
|
42
40
|
}
|
|
43
|
-
) }) })
|
|
41
|
+
) }) })
|
|
44
42
|
}
|
|
45
43
|
) });
|
|
46
44
|
}
|
|
@@ -24,7 +24,7 @@ function TilePage() {
|
|
|
24
24
|
return /* @__PURE__ */ jsx("div", { className: "flex min-w-0 flex-col gap-6", "data-test": "tile", children: Tile ? /* @__PURE__ */ jsx(ViewportFrame, { children: /* @__PURE__ */ jsxs("section", { className: "flex flex-col gap-4", children: [
|
|
25
25
|
/* @__PURE__ */ jsxs("header", { children: [
|
|
26
26
|
/* @__PURE__ */ jsxs("div", { className: "flex items-baseline gap-2.5", children: [
|
|
27
|
-
/* @__PURE__ */ jsx("h2", { className: "text-foreground font-heading text-xl
|
|
27
|
+
/* @__PURE__ */ jsx("h2", { className: "text-foreground font-heading font-heading-semibold text-xl", children: "Available integrations" }),
|
|
28
28
|
/* @__PURE__ */ jsx("span", { className: "text-muted-foreground text-sm tabular-nums", children: "3" })
|
|
29
29
|
] }),
|
|
30
30
|
/* @__PURE__ */ jsx("p", { className: "text-muted-foreground mt-1 max-w-prose text-sm", children: "Your tile in the catalogue grid, with two inert neighbours for scale. Column width, gap and heading come from the real marketplace." })
|
|
@@ -4,7 +4,8 @@ import { useMemo, useState } from "react";
|
|
|
4
4
|
import { notFound } from "next/navigation";
|
|
5
5
|
import { isEgressAllowed } from "@ekanos/sdk/context";
|
|
6
6
|
import {
|
|
7
|
-
DEFAULT_SIGNATURE_TOLERANCE_SECONDS
|
|
7
|
+
DEFAULT_SIGNATURE_TOLERANCE_SECONDS,
|
|
8
|
+
joinOAuthScopes
|
|
8
9
|
} from "@ekanos/sdk/integration";
|
|
9
10
|
import { Alert, AlertDescription, AlertTitle } from "@ekanos/ui/alert";
|
|
10
11
|
import { Badge } from "@ekanos/ui/badge";
|
|
@@ -43,6 +44,7 @@ function OutcomePanel({ outcome }) {
|
|
|
43
44
|
outcome.detail ? /* @__PURE__ */ jsx("span", { className: "text-muted-foreground text-sm", children: outcome.detail }) : null
|
|
44
45
|
] }),
|
|
45
46
|
outcome.agentEvents ? /* @__PURE__ */ jsx(RaisedAgentEvents, { events: outcome.agentEvents }) : null,
|
|
47
|
+
outcome.cancels ? /* @__PURE__ */ jsx(StoppedConversations, { cancels: outcome.cancels }) : null,
|
|
46
48
|
outcome.logs.length > 0 ? /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
|
|
47
49
|
/* @__PURE__ */ jsx("span", { className: "text-muted-foreground text-xs", children: "Handler logs" }),
|
|
48
50
|
/* @__PURE__ */ jsx("pre", { className: "bg-muted max-h-48 overflow-auto rounded-md p-3 text-xs", children: outcome.logs.map((log) => `[${log.level}] ${log.message}`).join("\n") })
|
|
@@ -57,6 +59,32 @@ function OutcomePanel({ outcome }) {
|
|
|
57
59
|
] }, scope)) })
|
|
58
60
|
] });
|
|
59
61
|
}
|
|
62
|
+
function StoppedConversations({ cancels }) {
|
|
63
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", "data-test": "stopped-conversations", children: [
|
|
64
|
+
/* @__PURE__ */ jsxs("span", { className: "text-muted-foreground text-xs", children: [
|
|
65
|
+
"Conversations stopped (",
|
|
66
|
+
cancels.length,
|
|
67
|
+
") \u2014 the host cancels every live run of this integration, in this account, started in each one, and calls your channel's ",
|
|
68
|
+
/* @__PURE__ */ jsx("code", { children: "runEnded" }),
|
|
69
|
+
" with status",
|
|
70
|
+
" ",
|
|
71
|
+
/* @__PURE__ */ jsx("code", { children: "cancelled" })
|
|
72
|
+
] }),
|
|
73
|
+
cancels.map((cancel, index) => /* @__PURE__ */ jsxs(
|
|
74
|
+
"div",
|
|
75
|
+
{
|
|
76
|
+
className: "flex flex-wrap items-center gap-2 rounded-md border p-3",
|
|
77
|
+
"data-test": "stopped-conversation",
|
|
78
|
+
children: [
|
|
79
|
+
/* @__PURE__ */ jsx("code", { className: "text-sm", children: cancel.conversationKey }),
|
|
80
|
+
/* @__PURE__ */ jsx(Badge, { variant: cancel.problem ? "destructive" : "secondary", children: cancel.problem ? "ignored" : "would be stopped" }),
|
|
81
|
+
cancel.problem ? /* @__PURE__ */ jsx("p", { className: "text-destructive w-full text-xs", children: cancel.problem }) : null
|
|
82
|
+
]
|
|
83
|
+
},
|
|
84
|
+
`${cancel.conversationKey}:${index}`
|
|
85
|
+
))
|
|
86
|
+
] });
|
|
87
|
+
}
|
|
60
88
|
function RaisedAgentEvents({ events }) {
|
|
61
89
|
return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", "data-test": "raised-agent-events", children: [
|
|
62
90
|
/* @__PURE__ */ jsxs("span", { className: "text-muted-foreground text-xs", children: [
|
|
@@ -324,7 +352,7 @@ function OAuthCard({
|
|
|
324
352
|
const rows = [
|
|
325
353
|
["Authorization URL", oauth.provider.authorizationUrl],
|
|
326
354
|
["Token URL", oauth.provider.tokenUrl],
|
|
327
|
-
["Scopes", oauth.provider
|
|
355
|
+
["Scopes", joinOAuthScopes(oauth.provider) || "(none)"],
|
|
328
356
|
["PKCE", oauth.provider.pkce ? "yes" : "no"],
|
|
329
357
|
["Client id secret", oauth.credentials.clientIdSecretName],
|
|
330
358
|
["Client secret secret", oauth.credentials.clientSecretSecretName]
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { IntegrationDefinition } from '@ekanos/sdk/integration';
|
|
2
|
+
import type { ActivationCredentialStatus } from '../../api-types.js';
|
|
3
|
+
import { type ConsoleSwitches } from './console-state.js';
|
|
4
|
+
/** What the ungrouped secret activation fields are called on the Connect tab. */
|
|
5
|
+
export declare const UNGROUPED_ACTIVATION_LABEL = "Activation keys";
|
|
6
|
+
/**
|
|
7
|
+
* The definition's secret `activation.fields`, grouped by the credential each
|
|
8
|
+
* belongs to, with the level that credential declares: each
|
|
9
|
+
* `activation.credentials` entry, then the secret fields outside every group
|
|
10
|
+
* as one team credential. `set` names the activation fields stored locally.
|
|
11
|
+
* Never a value.
|
|
12
|
+
*/
|
|
13
|
+
export declare function describeActivationCredentials(definition: Pick<IntegrationDefinition, 'activation'>, set: readonly string[],
|
|
14
|
+
/**
|
|
15
|
+
* The per-person tier and the Connect-as switches (plan 261 R6). Given,
|
|
16
|
+
* each credential reports which tier it saves into and whether THAT tier
|
|
17
|
+
* holds each field; absent, every credential is the team's.
|
|
18
|
+
*/
|
|
19
|
+
personal?: {
|
|
20
|
+
slug: string;
|
|
21
|
+
switches: ConsoleSwitches;
|
|
22
|
+
/** Activation fields the local person stored as themselves. */
|
|
23
|
+
set: readonly string[];
|
|
24
|
+
}): ActivationCredentialStatus[];
|
|
25
|
+
/** The declared `activation.fields` names, for checking what a merge may set. */
|
|
26
|
+
export declare function declaredActivationFieldNames(definition: Pick<IntegrationDefinition, 'activation'>): string[];
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { resolveConnectAs } from "./console-state.js";
|
|
2
|
+
const UNGROUPED_ACTIVATION_LABEL = "Activation keys";
|
|
3
|
+
function describeActivationCredentials(definition, set, personal) {
|
|
4
|
+
const fields = definition.activation?.fields ?? [];
|
|
5
|
+
if (fields.length === 0) return [];
|
|
6
|
+
const stored = new Set(set);
|
|
7
|
+
const byName = new Map(fields.map((field) => [field.name, field]));
|
|
8
|
+
const mine = new Set(personal?.set ?? []);
|
|
9
|
+
const describe = (name, connectAs) => {
|
|
10
|
+
const field = byName.get(name);
|
|
11
|
+
return {
|
|
12
|
+
name,
|
|
13
|
+
label: field?.label ?? name,
|
|
14
|
+
required: field?.required !== false,
|
|
15
|
+
set: connectAs === "me" ? mine.has(name) : stored.has(name)
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
const connectAsFor = (id, level) => personal ? resolveConnectAs({
|
|
19
|
+
switches: personal.switches,
|
|
20
|
+
slug: personal.slug,
|
|
21
|
+
credential: `activation:${id}`,
|
|
22
|
+
level
|
|
23
|
+
}) : void 0;
|
|
24
|
+
const grouped = /* @__PURE__ */ new Set();
|
|
25
|
+
const credentials = (definition.activation?.credentials ?? []).map((credential) => {
|
|
26
|
+
for (const name of credential.fields) grouped.add(name);
|
|
27
|
+
const connectAs = connectAsFor(credential.id, credential.level);
|
|
28
|
+
return {
|
|
29
|
+
id: credential.id,
|
|
30
|
+
label: credential.label,
|
|
31
|
+
level: credential.level,
|
|
32
|
+
...connectAs ? { connectAs } : {},
|
|
33
|
+
fields: credential.fields.map((name) => describe(name, connectAs))
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
const ungrouped = fields.filter((field) => field.secret === true && !grouped.has(field.name)).map((field) => field.name);
|
|
37
|
+
if (ungrouped.length > 0) {
|
|
38
|
+
const connectAs = connectAsFor("activation", "team");
|
|
39
|
+
credentials.push({
|
|
40
|
+
id: "activation",
|
|
41
|
+
label: UNGROUPED_ACTIVATION_LABEL,
|
|
42
|
+
level: "team",
|
|
43
|
+
...connectAs ? { connectAs } : {},
|
|
44
|
+
fields: ungrouped.map((name) => describe(name, connectAs))
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return credentials;
|
|
48
|
+
}
|
|
49
|
+
function declaredActivationFieldNames(definition) {
|
|
50
|
+
return (definition.activation?.fields ?? []).map((field) => field.name);
|
|
51
|
+
}
|
|
52
|
+
export {
|
|
53
|
+
UNGROUPED_ACTIVATION_LABEL,
|
|
54
|
+
declaredActivationFieldNames,
|
|
55
|
+
describeActivationCredentials
|
|
56
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { checkAgentRunCancels } from "@ekanos/integration-schema";
|
|
1
2
|
import {
|
|
2
3
|
DEFAULT_OAUTH_CONNECTION_ID,
|
|
3
4
|
resolveOAuthProvider
|
|
@@ -19,6 +20,7 @@ import {
|
|
|
19
20
|
isTriggerRequest
|
|
20
21
|
} from "../lib/trigger-contract.js";
|
|
21
22
|
import { getFixturesActionsState } from "./actions-fixtures-context.js";
|
|
23
|
+
import { readConsoleSwitches, resolveConnectAs } from "./console-state.js";
|
|
22
24
|
import { lookupIntegrationIntegration } from "./integration-lookup.js";
|
|
23
25
|
import {
|
|
24
26
|
WARMUP_BUDGET_MS,
|
|
@@ -33,6 +35,7 @@ import {
|
|
|
33
35
|
writeLocalSecrets
|
|
34
36
|
} from "./local-secrets.js";
|
|
35
37
|
import { loopbackRefusal } from "./loopback-guard.js";
|
|
38
|
+
import { describeOAuthConnections } from "./oauth-connections.js";
|
|
36
39
|
import {
|
|
37
40
|
buildAuthorizeUrl,
|
|
38
41
|
callbackUrl,
|
|
@@ -45,8 +48,14 @@ import {
|
|
|
45
48
|
} from "./oauth-loop.js";
|
|
46
49
|
import {
|
|
47
50
|
persistOauthConnection,
|
|
51
|
+
persistPersonOauthConnection,
|
|
48
52
|
restoreOauthConnections
|
|
49
53
|
} from "./oauth-persistence.js";
|
|
54
|
+
import {
|
|
55
|
+
contextAs,
|
|
56
|
+
machineContext,
|
|
57
|
+
personConnectContext
|
|
58
|
+
} from "./person-context.js";
|
|
50
59
|
import { resolveProjectRoot } from "./project-root.js";
|
|
51
60
|
import { parseStorageQuery, readClientReadableStorage } from "./storage-read.js";
|
|
52
61
|
function asSafeParseSchema(schema) {
|
|
@@ -269,9 +278,17 @@ function oauthConnect(ctx) {
|
|
|
269
278
|
const provider = resolvedProvider(ctx, oauth);
|
|
270
279
|
if (!provider) return oauthError(ctx, returnPath, "not_configured");
|
|
271
280
|
const codeVerifier = provider.pkce ? generateCodeVerifier() : void 0;
|
|
281
|
+
const requestedAs = ctx.url.searchParams.get("as");
|
|
282
|
+
const connectAs = requestedAs === "me" || requestedAs === "team" ? requestedAs : resolveConnectAs({
|
|
283
|
+
switches: readConsoleSwitches(ctx.projectRoot),
|
|
284
|
+
slug: ctx.slug,
|
|
285
|
+
credential: `oauth:${connectionId}`,
|
|
286
|
+
level: oauth.level ?? "team"
|
|
287
|
+
});
|
|
272
288
|
const nonce = ctx.state.nonces.issue({
|
|
273
289
|
returnPath,
|
|
274
290
|
connectionId,
|
|
291
|
+
connectAs,
|
|
275
292
|
...codeVerifier ? { codeVerifier } : {}
|
|
276
293
|
});
|
|
277
294
|
return redirect(
|
|
@@ -328,8 +345,17 @@ async function oauthCallback(ctx) {
|
|
|
328
345
|
);
|
|
329
346
|
return oauthError(ctx, returnPath, "exchange_failed");
|
|
330
347
|
}
|
|
348
|
+
const asPerson = consumed.status === "ok" && consumed.entry.connectAs === "me";
|
|
331
349
|
try {
|
|
332
|
-
await oauth.onTokens(
|
|
350
|
+
await oauth.onTokens(
|
|
351
|
+
asPerson ? personConnectContext({
|
|
352
|
+
base: ctx.state.ctx,
|
|
353
|
+
projectRoot: ctx.projectRoot,
|
|
354
|
+
slug: ctx.slug,
|
|
355
|
+
adminSecrets: ctx.secrets.values
|
|
356
|
+
}) : ctx.state.ctx,
|
|
357
|
+
exchange.tokens
|
|
358
|
+
);
|
|
333
359
|
} catch (error) {
|
|
334
360
|
console.error(
|
|
335
361
|
`[harness:${ctx.slug}] oauth/callback: onTokens threw`,
|
|
@@ -342,6 +368,17 @@ async function oauthCallback(ctx) {
|
|
|
342
368
|
expiresAt: exchange.tokens.expiresAt ?? null,
|
|
343
369
|
scope: exchange.tokens.scope ?? null
|
|
344
370
|
};
|
|
371
|
+
if (asPerson) {
|
|
372
|
+
persistPersonOauthConnection({
|
|
373
|
+
projectRoot: ctx.projectRoot,
|
|
374
|
+
slug: ctx.slug,
|
|
375
|
+
connectionId,
|
|
376
|
+
clientId: credentials.clientId,
|
|
377
|
+
tokens: exchange.tokens,
|
|
378
|
+
fact
|
|
379
|
+
});
|
|
380
|
+
return redirect(successRedirectUrl({ origin: ctx.origin, returnPath }));
|
|
381
|
+
}
|
|
345
382
|
if (connectionId === DEFAULT_OAUTH_CONNECTION_ID) ctx.state.connection = fact;
|
|
346
383
|
else ctx.state.connections[connectionId] = fact;
|
|
347
384
|
persistOauthConnection({
|
|
@@ -421,6 +458,7 @@ async function trigger(ctx) {
|
|
|
421
458
|
ctx.definition,
|
|
422
459
|
result.events
|
|
423
460
|
);
|
|
461
|
+
const cancels = checkAgentRunCancels(result.cancel);
|
|
424
462
|
return {
|
|
425
463
|
kind: request.kind,
|
|
426
464
|
outcome: {
|
|
@@ -429,7 +467,8 @@ async function trigger(ctx) {
|
|
|
429
467
|
...result.detail ? { detail: result.detail } : {},
|
|
430
468
|
logs: liveCtx.logs.slice(logsBefore),
|
|
431
469
|
storage: liveCtx.dumpStorage(),
|
|
432
|
-
...agentEvents ? { agentEvents } : {}
|
|
470
|
+
...agentEvents ? { agentEvents } : {},
|
|
471
|
+
...cancels ? { cancels } : {}
|
|
433
472
|
},
|
|
434
473
|
secretNames
|
|
435
474
|
};
|
|
@@ -457,7 +496,7 @@ async function trigger(ctx) {
|
|
|
457
496
|
ctx.definition,
|
|
458
497
|
body.id,
|
|
459
498
|
body.payload,
|
|
460
|
-
{ context: liveCtx, headers }
|
|
499
|
+
{ context: machineContext(liveCtx), headers }
|
|
461
500
|
);
|
|
462
501
|
return result;
|
|
463
502
|
})
|
|
@@ -473,7 +512,7 @@ async function trigger(ctx) {
|
|
|
473
512
|
return json(
|
|
474
513
|
await finish(body, async () => {
|
|
475
514
|
const { result } = await invokeSchedule(ctx.definition, body.id, {
|
|
476
|
-
context: liveCtx
|
|
515
|
+
context: machineContext(liveCtx)
|
|
477
516
|
});
|
|
478
517
|
return result;
|
|
479
518
|
})
|
|
@@ -540,7 +579,12 @@ async function actionInvoke(ctx, actionName) {
|
|
|
540
579
|
const modeHeader = ctx.request.headers.get(HARNESS_ACTIONS_MODE_HEADER);
|
|
541
580
|
const mode = isDataMode(modeHeader) ? modeHeader : "fixtures";
|
|
542
581
|
try {
|
|
543
|
-
const executionCtx = mode === "live" ?
|
|
582
|
+
const executionCtx = mode === "live" ? contextAs({
|
|
583
|
+
base: ctx.state.ctx,
|
|
584
|
+
runAs: readConsoleSwitches(ctx.projectRoot).runAs,
|
|
585
|
+
projectRoot: ctx.projectRoot,
|
|
586
|
+
slug: ctx.slug
|
|
587
|
+
}) : getFixturesActionsState({
|
|
544
588
|
integration: ctx.integration,
|
|
545
589
|
definition: ctx.definition,
|
|
546
590
|
variant: resolveActionsVariant(ctx)
|
|
@@ -603,6 +647,20 @@ function localSetupResponse(ctx, secrets, connected) {
|
|
|
603
647
|
keys: names.map((name) => ({ name, filled: !missing.has(name) })),
|
|
604
648
|
connected,
|
|
605
649
|
connection: connected ? ctx.state.connection : null,
|
|
650
|
+
...Object.keys(ctx.definition.oauthConnections ?? {}).length > 0 ? {
|
|
651
|
+
connections: describeOAuthConnections({
|
|
652
|
+
definition: ctx.definition,
|
|
653
|
+
filled: [],
|
|
654
|
+
values: secrets.values,
|
|
655
|
+
held: ctx.state,
|
|
656
|
+
stored: {}
|
|
657
|
+
}).map(({ id, label, connected: held, obtainedAt }) => ({
|
|
658
|
+
id,
|
|
659
|
+
label,
|
|
660
|
+
connected: held,
|
|
661
|
+
obtainedAt
|
|
662
|
+
}))
|
|
663
|
+
} : {},
|
|
606
664
|
volatile: true
|
|
607
665
|
};
|
|
608
666
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { HarnessConnectAs, HarnessRunAs, RepoConnectLevel } from '../../api-types.js';
|
|
2
|
+
export interface ConsoleSwitches {
|
|
3
|
+
runAs: HarnessRunAs;
|
|
4
|
+
/** `<slug>:<credential key>` → the tier it connects into. */
|
|
5
|
+
connectAs: Record<string, HarnessConnectAs>;
|
|
6
|
+
}
|
|
7
|
+
/** The switches for the project at `projectRoot`; defaults when absent or unreadable. */
|
|
8
|
+
export declare function readConsoleSwitches(projectRoot: string): ConsoleSwitches;
|
|
9
|
+
export declare function writeConsoleSwitches(args: {
|
|
10
|
+
projectRoot: string;
|
|
11
|
+
runAs?: HarnessRunAs;
|
|
12
|
+
connectAs?: {
|
|
13
|
+
slug: string;
|
|
14
|
+
credential: string;
|
|
15
|
+
as: HarnessConnectAs;
|
|
16
|
+
};
|
|
17
|
+
}): ConsoleSwitches;
|
|
18
|
+
/** `user` connects as the person, anything else as the team. */
|
|
19
|
+
export declare function declaredConnectAs(level: RepoConnectLevel): HarnessConnectAs;
|
|
20
|
+
export declare function resolveConnectAs(args: {
|
|
21
|
+
switches: ConsoleSwitches;
|
|
22
|
+
slug: string;
|
|
23
|
+
credential: string;
|
|
24
|
+
level: RepoConnectLevel;
|
|
25
|
+
}): HarnessConnectAs;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
import { readLocalState, writeLocalState } from "./local-state.js";
|
|
3
|
+
const FILE = path.join(".ekanos", "local-state.json");
|
|
4
|
+
function isRecord(value) {
|
|
5
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6
|
+
}
|
|
7
|
+
function readConsoleSwitches(projectRoot) {
|
|
8
|
+
const stored = readLocalState(path.join(projectRoot, FILE)).switches;
|
|
9
|
+
const connectAs = {};
|
|
10
|
+
if (!isRecord(stored)) return { runAs: "me", connectAs };
|
|
11
|
+
if (isRecord(stored.connectAs)) {
|
|
12
|
+
for (const [key, value] of Object.entries(stored.connectAs)) {
|
|
13
|
+
if (value === "me" || value === "team") connectAs[key] = value;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return { runAs: stored.runAs === "machine" ? "machine" : "me", connectAs };
|
|
17
|
+
}
|
|
18
|
+
function writeConsoleSwitches(args) {
|
|
19
|
+
const current = readConsoleSwitches(args.projectRoot);
|
|
20
|
+
const next = {
|
|
21
|
+
runAs: args.runAs ?? current.runAs,
|
|
22
|
+
connectAs: {
|
|
23
|
+
...current.connectAs,
|
|
24
|
+
...args.connectAs ? {
|
|
25
|
+
[`${args.connectAs.slug}:${args.connectAs.credential}`]: args.connectAs.as
|
|
26
|
+
} : {}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const file = path.join(args.projectRoot, FILE);
|
|
30
|
+
writeLocalState(file, { ...readLocalState(file), switches: next });
|
|
31
|
+
return next;
|
|
32
|
+
}
|
|
33
|
+
function declaredConnectAs(level) {
|
|
34
|
+
return level === "user" ? "me" : "team";
|
|
35
|
+
}
|
|
36
|
+
function resolveConnectAs(args) {
|
|
37
|
+
return args.switches.connectAs[`${args.slug}:${args.credential}`] ?? declaredConnectAs(args.level);
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
declaredConnectAs,
|
|
41
|
+
readConsoleSwitches,
|
|
42
|
+
resolveConnectAs,
|
|
43
|
+
writeConsoleSwitches
|
|
44
|
+
};
|