@ekanos/harness 0.18.0 → 0.20.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/dist/api-types.d.ts +490 -0
- package/dist/api-types.js +6 -0
- package/dist/api.d.ts +33 -0
- package/dist/api.js +36 -1
- package/dist/app.js +6 -1
- package/dist/internal/components/approvals-tray.d.ts +17 -0
- package/dist/internal/components/approvals-tray.js +116 -0
- package/dist/internal/components/ask-assistant-bridge.js +1 -1
- package/dist/internal/components/connect-controls.d.ts +12 -0
- package/dist/internal/components/connect-controls.js +69 -0
- package/dist/internal/components/connect-dialog.d.ts +19 -0
- package/dist/internal/components/connect-dialog.js +61 -0
- package/dist/internal/components/connect-panel.d.ts +25 -0
- package/dist/internal/components/connect-panel.js +292 -0
- package/dist/internal/components/connection-chip.d.ts +14 -0
- package/dist/internal/components/connection-chip.js +75 -0
- package/dist/internal/components/dashboard-grid.js +38 -24
- package/dist/internal/components/dev-toolbar.js +176 -103
- package/dist/internal/components/events-panel.d.ts +10 -0
- package/dist/internal/components/events-panel.js +111 -0
- package/dist/internal/components/health-panel.d.ts +4 -0
- package/dist/internal/components/health-panel.js +56 -0
- package/dist/internal/components/integration-badge.d.ts +29 -0
- package/dist/internal/components/integration-badge.js +105 -0
- package/dist/internal/components/local-oauth-panel.js +21 -1
- package/dist/internal/components/operation-runner-panel.d.ts +12 -0
- package/dist/internal/components/operation-runner-panel.js +331 -0
- package/dist/internal/components/provenance-banner.d.ts +12 -0
- package/dist/internal/components/provenance-banner.js +107 -0
- package/dist/internal/components/repo-connection.d.ts +10 -0
- package/dist/internal/components/repo-connection.js +32 -0
- package/dist/internal/components/run-log.d.ts +9 -0
- package/dist/internal/components/run-log.js +228 -0
- package/dist/internal/components/runtime-strip.d.ts +12 -0
- package/dist/internal/components/runtime-strip.js +158 -0
- package/dist/internal/components/schema-form.d.ts +13 -0
- package/dist/internal/components/schema-form.js +382 -0
- package/dist/internal/components/scrollable-nav.d.ts +12 -0
- package/dist/internal/components/scrollable-nav.js +68 -0
- package/dist/internal/components/surface-nav.d.ts +31 -1
- package/dist/internal/components/surface-nav.js +244 -31
- package/dist/internal/components/workflow-runner.d.ts +14 -0
- package/dist/internal/components/workflow-runner.js +104 -0
- package/dist/internal/lib/bundled-secrets.d.ts +9 -0
- package/dist/internal/lib/bundled-secrets.js +24 -0
- package/dist/internal/lib/chrome-slot.d.ts +2 -0
- package/dist/internal/lib/chrome-slot.js +25 -0
- package/dist/internal/lib/connection-facts.d.ts +44 -0
- package/dist/internal/lib/connection-facts.js +116 -0
- package/dist/internal/lib/console-client.d.ts +55 -0
- package/dist/internal/lib/console-client.js +295 -0
- package/dist/internal/lib/console-context.d.ts +56 -0
- package/dist/internal/lib/console-context.js +67 -0
- package/dist/internal/lib/console-hooks.d.ts +33 -0
- package/dist/internal/lib/console-hooks.js +118 -0
- package/dist/internal/lib/console-types.d.ts +279 -0
- package/dist/internal/lib/console-types.js +0 -0
- package/dist/internal/lib/experience-runtime.d.ts +8 -0
- package/dist/internal/lib/experience-runtime.js +22 -0
- package/dist/internal/lib/preview-sections.d.ts +13 -0
- package/dist/internal/lib/preview-sections.js +32 -0
- package/dist/internal/lib/repo-context.d.ts +20 -0
- package/dist/internal/lib/repo-context.js +64 -0
- package/dist/internal/lib/run-log-view.d.ts +24 -0
- package/dist/internal/lib/run-log-view.js +57 -0
- package/dist/internal/lib/schema-form-model.d.ts +34 -0
- package/dist/internal/lib/schema-form-model.js +272 -0
- package/dist/internal/lib/toolbar-context.d.ts +9 -1
- package/dist/internal/lib/toolbar-context.js +13 -3
- package/dist/internal/lib/toolbar-visibility.d.ts +16 -0
- package/dist/internal/lib/toolbar-visibility.js +31 -0
- package/dist/internal/registry-context.d.ts +2 -0
- package/dist/internal/registry-context.js +11 -9
- package/dist/internal/routes/activation-page.js +44 -20
- package/dist/internal/routes/console-home-page.d.ts +5 -0
- package/dist/internal/routes/console-home-page.js +18 -0
- package/dist/internal/routes/experience-connect-page.d.ts +6 -0
- package/dist/internal/routes/experience-connect-page.js +127 -0
- package/dist/internal/routes/experience-layout-page.d.ts +8 -0
- package/dist/internal/routes/experience-layout-page.js +126 -0
- package/dist/internal/routes/experience-page-host.d.ts +7 -0
- package/dist/internal/routes/experience-page-host.js +79 -0
- package/dist/internal/routes/experience-review-queue-page.d.ts +2 -0
- package/dist/internal/routes/experience-review-queue-page.js +60 -0
- package/dist/internal/routes/experience-runs-page.d.ts +1 -0
- package/dist/internal/routes/experience-runs-page.js +13 -0
- package/dist/internal/routes/experience-summary-page.d.ts +1 -0
- package/dist/internal/routes/experience-summary-page.js +101 -0
- package/dist/internal/routes/experience-widget-page.d.ts +1 -0
- package/dist/internal/routes/experience-widget-page.js +26 -0
- package/dist/internal/routes/experience-widgets-page.d.ts +6 -0
- package/dist/internal/routes/experience-widgets-page.js +22 -0
- package/dist/internal/routes/experience-workflow-page.d.ts +1 -0
- package/dist/internal/routes/experience-workflow-page.js +24 -0
- package/dist/internal/routes/experience-workflows-page.d.ts +1 -0
- package/dist/internal/routes/experience-workflows-page.js +44 -0
- package/dist/internal/routes/index-page.d.ts +10 -9
- package/dist/internal/routes/index-page.js +3 -68
- package/dist/internal/routes/integration-layout.d.ts +12 -1
- package/dist/internal/routes/integration-layout.js +20 -6
- package/dist/internal/routes/integrations-connect-page.d.ts +1 -0
- package/dist/internal/routes/integrations-connect-page.js +19 -0
- package/dist/internal/routes/integrations-events-page.d.ts +1 -0
- package/dist/internal/routes/integrations-events-page.js +10 -0
- package/dist/internal/routes/integrations-health-page.d.ts +1 -0
- package/dist/internal/routes/integrations-health-page.js +10 -0
- package/dist/internal/routes/integrations-layout.d.ts +17 -0
- package/dist/internal/routes/integrations-layout.js +106 -0
- package/dist/internal/routes/integrations-list-page.d.ts +2 -0
- package/dist/internal/routes/integrations-list-page.js +94 -0
- package/dist/internal/routes/integrations-operation-page.d.ts +1 -0
- package/dist/internal/routes/integrations-operation-page.js +29 -0
- package/dist/internal/routes/integrations-operations-page.d.ts +1 -0
- package/dist/internal/routes/integrations-operations-page.js +61 -0
- package/dist/internal/routes/integrations-overview-page.d.ts +1 -0
- package/dist/internal/routes/integrations-overview-page.js +90 -0
- package/dist/internal/routes/integrations-runs-page.d.ts +1 -0
- package/dist/internal/routes/integrations-runs-page.js +14 -0
- package/dist/internal/routes/integrations-scope.d.ts +12 -0
- package/dist/internal/routes/integrations-scope.js +39 -0
- package/dist/internal/routes/legacy-preview-redirect.d.ts +6 -0
- package/dist/internal/routes/legacy-preview-redirect.js +12 -0
- package/dist/internal/routes/preview-index-page.d.ts +2 -0
- package/dist/internal/routes/preview-index-page.js +14 -0
- package/dist/internal/routes/repo-connections-page.d.ts +6 -0
- package/dist/internal/routes/repo-connections-page.js +8 -0
- package/dist/internal/routes/repo-home-page.d.ts +2 -0
- package/dist/internal/routes/repo-home-page.js +320 -0
- package/dist/internal/routes/repo-layout.d.ts +7 -0
- package/dist/internal/routes/repo-layout.js +76 -0
- package/dist/internal/routes/repo-package-layouts.d.ts +20 -0
- package/dist/internal/routes/repo-package-layouts.js +104 -0
- package/dist/internal/routes/root-layout.d.ts +3 -1
- package/dist/internal/routes/root-layout.js +13 -3
- package/dist/internal/routes/single-widget-page.js +5 -12
- package/dist/internal/routes/tile-page.js +20 -41
- package/dist/internal/routes/triggers-page.js +55 -62
- package/dist/internal/routes/widgets-page.js +1 -1
- package/dist/internal/server/api-router.js +46 -4
- package/dist/internal/server/approvals.d.ts +44 -0
- package/dist/internal/server/approvals.js +76 -0
- package/dist/internal/server/contract-sources.d.ts +28 -0
- package/dist/internal/server/contract-sources.js +83 -0
- package/dist/internal/server/definition-loader.d.ts +22 -0
- package/dist/internal/server/definition-loader.js +125 -0
- package/dist/internal/server/ekanos-api-router.d.ts +34 -0
- package/dist/internal/server/ekanos-api-router.js +835 -0
- package/dist/internal/server/experience-loader.d.ts +57 -0
- package/dist/internal/server/experience-loader.js +146 -0
- package/dist/internal/server/integration-lookup.d.ts +29 -0
- package/dist/internal/server/integration-lookup.js +33 -0
- package/dist/internal/server/integration-resolver.d.ts +121 -0
- package/dist/internal/server/integration-resolver.js +605 -0
- package/dist/internal/server/live-invoker.d.ts +11 -0
- package/dist/internal/server/live-invoker.js +106 -0
- package/dist/internal/server/local-secrets.d.ts +82 -1
- package/dist/internal/server/local-secrets.js +112 -1
- package/dist/internal/server/local-state.d.ts +12 -0
- package/dist/internal/server/local-state.js +45 -0
- package/dist/internal/server/oauth-persistence.d.ts +19 -0
- package/dist/internal/server/oauth-persistence.js +76 -0
- package/dist/internal/server/operation-runner.d.ts +95 -0
- package/dist/internal/server/operation-runner.js +231 -0
- package/dist/internal/server/project-manifest.d.ts +71 -0
- package/dist/internal/server/project-manifest.js +215 -0
- package/dist/internal/server/registry-cache.d.ts +68 -0
- package/dist/internal/server/registry-cache.js +328 -0
- package/dist/internal/server/repo-api-router.d.ts +33 -0
- package/dist/internal/server/repo-api-router.js +391 -0
- package/dist/internal/server/run-log.d.ts +22 -0
- package/dist/internal/server/run-log.js +32 -0
- package/dist/internal/server/semantics.d.ts +28 -0
- package/dist/internal/server/semantics.js +67 -0
- package/dist/internal/server/session-catalog.d.ts +67 -0
- package/dist/internal/server/session-catalog.js +18 -0
- package/dist/internal/server/workflow-runner.d.ts +36 -0
- package/dist/internal/server/workflow-runner.js +183 -0
- package/dist/registry.d.ts +7 -0
- package/dist/resolver.d.ts +145 -0
- package/dist/resolver.js +211 -0
- package/dist/routes.d.ts +66 -2
- package/dist/routes.js +61 -3
- package/dist/runtime.d.ts +46 -0
- package/dist/runtime.js +60 -0
- package/package.json +23 -9
- package/dist/internal/routes/integration-index-page.d.ts +0 -13
- package/dist/internal/routes/integration-index-page.js +0 -17
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
import {
|
|
2
|
+
discoverRepo
|
|
3
|
+
} from "@ekanos/integration-schema/repo";
|
|
4
|
+
import { deriveConnectionFacts } from "../lib/connection-facts.js";
|
|
5
|
+
import {
|
|
6
|
+
createEkanosApiRouter
|
|
7
|
+
} from "./ekanos-api-router.js";
|
|
8
|
+
import { getLiveStore } from "./live-context.js";
|
|
9
|
+
import { isLoopbackHost, loopbackRefusal } from "./loopback-guard.js";
|
|
10
|
+
import { hasStoredOauthConnection } from "./oauth-persistence.js";
|
|
11
|
+
import { readSessionCatalog } from "./session-catalog.js";
|
|
12
|
+
function json(body, init = {}) {
|
|
13
|
+
return new Response(JSON.stringify(body), {
|
|
14
|
+
...init,
|
|
15
|
+
headers: {
|
|
16
|
+
"content-type": "application/json",
|
|
17
|
+
"cache-control": "private, no-store",
|
|
18
|
+
...init.headers ?? {}
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function apiError(status, code, message) {
|
|
23
|
+
const body = { error: { code, message } };
|
|
24
|
+
return json(body, { status });
|
|
25
|
+
}
|
|
26
|
+
const LEVELS = {
|
|
27
|
+
source: "source",
|
|
28
|
+
team: "team",
|
|
29
|
+
user: "user"
|
|
30
|
+
};
|
|
31
|
+
const MODE_LEVEL = {
|
|
32
|
+
team: "team",
|
|
33
|
+
invoker: "user",
|
|
34
|
+
user: "user"
|
|
35
|
+
};
|
|
36
|
+
const KIND_TYPE = {
|
|
37
|
+
none: "shipped",
|
|
38
|
+
keys: "keys",
|
|
39
|
+
oauth: "oauth"
|
|
40
|
+
};
|
|
41
|
+
const STATE_STATUS = {
|
|
42
|
+
connected: "connected",
|
|
43
|
+
not_connected: "not_connected",
|
|
44
|
+
no_connection_needed: "not_needed",
|
|
45
|
+
managed: "managed",
|
|
46
|
+
unreadable: "not_connected"
|
|
47
|
+
};
|
|
48
|
+
const AUTH_TYPE = {
|
|
49
|
+
none: "shipped",
|
|
50
|
+
api_key: "keys",
|
|
51
|
+
oauth2: "oauth"
|
|
52
|
+
};
|
|
53
|
+
const pkgKey = (pkg) => `${pkg.kind}:${pkg.name}`;
|
|
54
|
+
function createRepoApiRouter(partial) {
|
|
55
|
+
const env = partial.env ?? process.env;
|
|
56
|
+
const discover = partial.discover ?? discoverRepo;
|
|
57
|
+
const hasOauthConnection = partial.hasOauthConnection ?? ((slug, root) => {
|
|
58
|
+
const state = getLiveStore().get(slug);
|
|
59
|
+
return Boolean(
|
|
60
|
+
state && (state.connection || Object.keys(state.connections).length > 0)
|
|
61
|
+
) || hasStoredOauthConnection(root, slug);
|
|
62
|
+
});
|
|
63
|
+
const forgetOauthConnection = partial.forgetOauthConnection ?? ((slug) => {
|
|
64
|
+
getLiveStore().delete(slug);
|
|
65
|
+
});
|
|
66
|
+
const catalog = readSessionCatalog(partial.repoRoot);
|
|
67
|
+
const routers = /* @__PURE__ */ new Map();
|
|
68
|
+
function routerFor(pkg) {
|
|
69
|
+
let router = routers.get(pkgKey(pkg));
|
|
70
|
+
if (!router) {
|
|
71
|
+
router = partial.createPackageRouter ? partial.createPackageRouter(pkg) : createEkanosApiRouter({
|
|
72
|
+
env,
|
|
73
|
+
projectRoot: pkg.dir,
|
|
74
|
+
resolve: { catalog }
|
|
75
|
+
});
|
|
76
|
+
routers.set(pkgKey(pkg), router);
|
|
77
|
+
}
|
|
78
|
+
return router;
|
|
79
|
+
}
|
|
80
|
+
async function call(request, pkg, segments, init = {}) {
|
|
81
|
+
const url = new URL(request.url);
|
|
82
|
+
const inner = new Request(
|
|
83
|
+
`${url.origin}/__ekanos/api/${segments.join("/")}`,
|
|
84
|
+
{
|
|
85
|
+
method: init.method ?? "GET",
|
|
86
|
+
headers: request.headers,
|
|
87
|
+
...init.body === void 0 ? {} : { body: JSON.stringify(init.body) }
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
const response = await routerFor(pkg)(inner, segments);
|
|
91
|
+
if (!response.ok) {
|
|
92
|
+
const text = await response.text();
|
|
93
|
+
try {
|
|
94
|
+
const parsed = JSON.parse(text);
|
|
95
|
+
return { ok: false, message: parsed.error.message };
|
|
96
|
+
} catch {
|
|
97
|
+
return { ok: false, message: text || `${response.status}` };
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return { ok: true, data: await response.json() };
|
|
101
|
+
}
|
|
102
|
+
function levelsOf(contract) {
|
|
103
|
+
return contract.connection.levels.flatMap((level) => {
|
|
104
|
+
const known = LEVELS[level];
|
|
105
|
+
return known ? [known] : [];
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
async function connectionOf(request, pkg, contract) {
|
|
109
|
+
const contractAuth = contract.connection.auth;
|
|
110
|
+
const levels = levelsOf(contract);
|
|
111
|
+
const creds = await call(request, pkg, [
|
|
112
|
+
"credentials",
|
|
113
|
+
pkg.name
|
|
114
|
+
]);
|
|
115
|
+
const data = creds.ok ? creds.data : null;
|
|
116
|
+
const manageable = data?.manageable ?? false;
|
|
117
|
+
const facts = deriveConnectionFacts({
|
|
118
|
+
contractAuth,
|
|
119
|
+
usesOauth: data?.oauth ?? false,
|
|
120
|
+
declared: data?.declared ?? [],
|
|
121
|
+
missing: data?.missing ?? [],
|
|
122
|
+
activationFieldsSet: data?.activationFieldsSet ?? [],
|
|
123
|
+
oauthHeld: manageable && (data?.oauth ?? contractAuth === "oauth2") && hasOauthConnection(pkg.name, pkg.dir),
|
|
124
|
+
manageable,
|
|
125
|
+
target: data?.target ?? [],
|
|
126
|
+
supportsLive: manageable,
|
|
127
|
+
forced: data?.facts?.forced ?? false,
|
|
128
|
+
defaultMode: "fixtures",
|
|
129
|
+
...creds.ok ? {} : { unreadable: creds.message }
|
|
130
|
+
});
|
|
131
|
+
return {
|
|
132
|
+
type: KIND_TYPE[facts.kind],
|
|
133
|
+
status: STATE_STATUS[facts.state],
|
|
134
|
+
...facts.detail ? { detail: facts.detail } : {},
|
|
135
|
+
levels,
|
|
136
|
+
...data ? { storeRoot: data.root } : {},
|
|
137
|
+
...data?.displayRoot ? { displayRoot: data.displayRoot } : {},
|
|
138
|
+
...facts.state === "connected" ? { target: facts.target } : {},
|
|
139
|
+
facts
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
async function integrationRow(request, pkg) {
|
|
143
|
+
const base = {
|
|
144
|
+
name: pkg.name,
|
|
145
|
+
version: pkg.version,
|
|
146
|
+
consoleHref: `/integrations/${pkg.name}`,
|
|
147
|
+
usedBy: []
|
|
148
|
+
};
|
|
149
|
+
const failed = (message) => ({
|
|
150
|
+
row: { ...base, contractVersion: null, connection: null, error: message },
|
|
151
|
+
connection: null
|
|
152
|
+
});
|
|
153
|
+
try {
|
|
154
|
+
const contract = await call(request, pkg, [
|
|
155
|
+
"contract",
|
|
156
|
+
pkg.name
|
|
157
|
+
]);
|
|
158
|
+
if (!contract.ok) return failed(contract.message);
|
|
159
|
+
const connection = await connectionOf(
|
|
160
|
+
request,
|
|
161
|
+
pkg,
|
|
162
|
+
contract.data.contract
|
|
163
|
+
);
|
|
164
|
+
return {
|
|
165
|
+
row: {
|
|
166
|
+
...base,
|
|
167
|
+
contractVersion: contract.data.contract.contractVersion,
|
|
168
|
+
connection
|
|
169
|
+
},
|
|
170
|
+
connection
|
|
171
|
+
};
|
|
172
|
+
} catch (error) {
|
|
173
|
+
console.error(
|
|
174
|
+
`[harness:repo-api] integration ${pkg.name} could not be read`,
|
|
175
|
+
error
|
|
176
|
+
);
|
|
177
|
+
return failed(error instanceof Error ? error.message : String(error));
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
async function experienceRow(request, pkg, connections, repoNames) {
|
|
181
|
+
const row = {
|
|
182
|
+
name: pkg.name,
|
|
183
|
+
version: pkg.version,
|
|
184
|
+
viewHref: `/experiences/${pkg.name}`,
|
|
185
|
+
connectHref: `/experiences/${pkg.name}/connect`
|
|
186
|
+
};
|
|
187
|
+
const resolved = await call(request, pkg, [
|
|
188
|
+
"integrations"
|
|
189
|
+
]);
|
|
190
|
+
if (!resolved.ok) {
|
|
191
|
+
return { ...row, integrations: [], error: resolved.message };
|
|
192
|
+
}
|
|
193
|
+
const integrations = [];
|
|
194
|
+
for (const view of resolved.data.integrations) {
|
|
195
|
+
const sameRepo = repoNames.has(view.integration);
|
|
196
|
+
let connection = null;
|
|
197
|
+
if (sameRepo) {
|
|
198
|
+
connection = connections.get(view.integration) ?? null;
|
|
199
|
+
} else {
|
|
200
|
+
const contract = await call(request, pkg, [
|
|
201
|
+
"contract",
|
|
202
|
+
view.integration
|
|
203
|
+
]);
|
|
204
|
+
connection = contract.ok ? {
|
|
205
|
+
type: AUTH_TYPE[contract.data.contract.connection.auth] ?? "shipped",
|
|
206
|
+
status: "managed",
|
|
207
|
+
levels: levelsOf(contract.data.contract),
|
|
208
|
+
facts: deriveConnectionFacts({
|
|
209
|
+
contractAuth: contract.data.contract.connection.auth,
|
|
210
|
+
usesOauth: false,
|
|
211
|
+
declared: [],
|
|
212
|
+
missing: [],
|
|
213
|
+
activationFieldsSet: [],
|
|
214
|
+
oauthHeld: false,
|
|
215
|
+
manageable: false,
|
|
216
|
+
target: [],
|
|
217
|
+
supportsLive: false,
|
|
218
|
+
forced: false,
|
|
219
|
+
defaultMode: "fixtures"
|
|
220
|
+
})
|
|
221
|
+
} : null;
|
|
222
|
+
}
|
|
223
|
+
const asked = [...new Set(view.modes.map((mode) => MODE_LEVEL[mode]))];
|
|
224
|
+
const supported = connection?.levels ?? [];
|
|
225
|
+
const levels = supported.length ? asked.filter((level) => supported.includes(level)) : asked;
|
|
226
|
+
const unsupported = asked.filter((level) => !levels.includes(level));
|
|
227
|
+
integrations.push({
|
|
228
|
+
name: view.integration,
|
|
229
|
+
modes: view.modes,
|
|
230
|
+
sameRepo,
|
|
231
|
+
connection,
|
|
232
|
+
levels,
|
|
233
|
+
...unsupported.length > 0 ? {
|
|
234
|
+
levelProblem: `Asks for ${unsupported.join(", ")} but ${view.integration} supports ${supported.join(", ") || "no level"}.`
|
|
235
|
+
} : {},
|
|
236
|
+
connectHref: sameRepo ? `/integrations/${view.integration}/connect` : null
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
return { ...row, integrations };
|
|
240
|
+
}
|
|
241
|
+
async function overview(request) {
|
|
242
|
+
const repo = discover(partial.repoRoot);
|
|
243
|
+
const integrationPackages = repo.packages.filter(
|
|
244
|
+
(p) => p.kind === "integration"
|
|
245
|
+
);
|
|
246
|
+
const experiencePackages = repo.packages.filter(
|
|
247
|
+
(p) => p.kind === "experience"
|
|
248
|
+
);
|
|
249
|
+
const repoNames = new Set(integrationPackages.map((p) => p.name));
|
|
250
|
+
const connections = /* @__PURE__ */ new Map();
|
|
251
|
+
const integrations = [];
|
|
252
|
+
for (const pkg of integrationPackages) {
|
|
253
|
+
const { row, connection } = await integrationRow(request, pkg);
|
|
254
|
+
connections.set(pkg.name, connection);
|
|
255
|
+
integrations.push(row);
|
|
256
|
+
}
|
|
257
|
+
const experiences = [];
|
|
258
|
+
for (const pkg of experiencePackages) {
|
|
259
|
+
experiences.push(
|
|
260
|
+
await experienceRow(request, pkg, connections, repoNames)
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
for (const experience of experiences) {
|
|
264
|
+
for (const used of experience.integrations) {
|
|
265
|
+
integrations.find((row) => row.name === used.name)?.usedBy.push(experience.name);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
const connectable = integrations.filter(
|
|
269
|
+
(row) => row.connection && row.connection.status !== "not_needed" && row.connection.status !== "managed"
|
|
270
|
+
);
|
|
271
|
+
const noConnectionNeeded = integrations.filter(
|
|
272
|
+
(row) => row.connection?.facts.state === "no_connection_needed"
|
|
273
|
+
).length;
|
|
274
|
+
return {
|
|
275
|
+
root: repo.root,
|
|
276
|
+
counts: {
|
|
277
|
+
integrations: integrations.length,
|
|
278
|
+
experiences: experiences.length,
|
|
279
|
+
connected: connectable.filter(
|
|
280
|
+
(row) => row.connection?.status === "connected"
|
|
281
|
+
).length,
|
|
282
|
+
notConnected: connectable.filter(
|
|
283
|
+
(row) => row.connection?.status === "not_connected"
|
|
284
|
+
).length,
|
|
285
|
+
noConnectionNeeded
|
|
286
|
+
},
|
|
287
|
+
integrations,
|
|
288
|
+
experiences,
|
|
289
|
+
problems: repo.problems
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
return async (request, segments) => {
|
|
293
|
+
const refusal = loopbackRefusal(request, env);
|
|
294
|
+
if (refusal) return refusal;
|
|
295
|
+
const origin = request.headers.get("origin");
|
|
296
|
+
if (origin && env.EKANOS_HARNESS_EXPOSED !== "1") {
|
|
297
|
+
let originHost = "";
|
|
298
|
+
try {
|
|
299
|
+
originHost = new URL(origin).host;
|
|
300
|
+
} catch {
|
|
301
|
+
originHost = "";
|
|
302
|
+
}
|
|
303
|
+
if (!isLoopbackHost(originHost)) {
|
|
304
|
+
return apiError(
|
|
305
|
+
403,
|
|
306
|
+
"cross_origin",
|
|
307
|
+
"Cross-origin requests to the harness API are refused."
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
const method = request.method.toUpperCase();
|
|
312
|
+
const [head, second, third, fourth] = segments;
|
|
313
|
+
try {
|
|
314
|
+
if (head === "repo" && segments.length === 1) {
|
|
315
|
+
if (method !== "GET") {
|
|
316
|
+
return apiError(405, "method_not_allowed", "GET only.");
|
|
317
|
+
}
|
|
318
|
+
return json(await overview(request));
|
|
319
|
+
}
|
|
320
|
+
if (head === "repo" && second === "connections" && third && fourth === "disconnect" && segments.length === 4) {
|
|
321
|
+
if (method !== "POST") {
|
|
322
|
+
return apiError(405, "method_not_allowed", "POST only.");
|
|
323
|
+
}
|
|
324
|
+
const repo = discover(partial.repoRoot);
|
|
325
|
+
const pkg = repo.packages.find(
|
|
326
|
+
(p) => p.kind === "integration" && p.name === third
|
|
327
|
+
);
|
|
328
|
+
if (!pkg) {
|
|
329
|
+
return apiError(
|
|
330
|
+
404,
|
|
331
|
+
"unknown_integration",
|
|
332
|
+
`No integration "${third}" in this repo.`
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
const contract = await call(request, pkg, [
|
|
336
|
+
"contract",
|
|
337
|
+
pkg.name
|
|
338
|
+
]);
|
|
339
|
+
if (!contract.ok) return apiError(409, "no_contract", contract.message);
|
|
340
|
+
const type = (await connectionOf(request, pkg, contract.data.contract)).type;
|
|
341
|
+
if (type === "keys" || type === "oauth") {
|
|
342
|
+
const cleared = await call(
|
|
343
|
+
request,
|
|
344
|
+
pkg,
|
|
345
|
+
["credentials", pkg.name, "disconnect"],
|
|
346
|
+
{ method: "POST", body: { clearKeys: type === "keys" } }
|
|
347
|
+
);
|
|
348
|
+
if (!cleared.ok) return apiError(400, "rejected", cleared.message);
|
|
349
|
+
}
|
|
350
|
+
if (type === "oauth") {
|
|
351
|
+
forgetOauthConnection(pkg.name);
|
|
352
|
+
}
|
|
353
|
+
const body = {
|
|
354
|
+
integration: pkg.name,
|
|
355
|
+
connection: await connectionOf(request, pkg, contract.data.contract)
|
|
356
|
+
};
|
|
357
|
+
return json(body);
|
|
358
|
+
}
|
|
359
|
+
if (head === "packages" && (second === "integrations" || second === "experiences") && third && segments.length > 3) {
|
|
360
|
+
const kind = second === "integrations" ? "integration" : "experience";
|
|
361
|
+
const repo = discover(partial.repoRoot);
|
|
362
|
+
const pkg = repo.packages.find(
|
|
363
|
+
(p) => p.kind === kind && p.name === third
|
|
364
|
+
);
|
|
365
|
+
if (!pkg) {
|
|
366
|
+
return apiError(
|
|
367
|
+
404,
|
|
368
|
+
"unknown_package",
|
|
369
|
+
`No ${kind} "${third}" in this repo.`
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
return routerFor(pkg)(request, segments.slice(3));
|
|
373
|
+
}
|
|
374
|
+
return apiError(
|
|
375
|
+
404,
|
|
376
|
+
"not_found",
|
|
377
|
+
`No harness API route at /__ekanos/api/${segments.join("/")}.`
|
|
378
|
+
);
|
|
379
|
+
} catch (error) {
|
|
380
|
+
console.error("[harness:repo-api] handler failed", error);
|
|
381
|
+
return apiError(
|
|
382
|
+
500,
|
|
383
|
+
"internal",
|
|
384
|
+
error instanceof Error ? error.message : String(error)
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
export {
|
|
390
|
+
createRepoApiRouter
|
|
391
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { RunRecord } from '../../api-types.js';
|
|
2
|
+
/**
|
|
3
|
+
* In-memory ring of every operation call from any surface. 200 entries, newest
|
|
4
|
+
* last, with a monotonic `seq` so the UI can poll `?after=<cursor>`.
|
|
5
|
+
*
|
|
6
|
+
* Rows carry provenance and sizes, NEVER payloads or credentials: that is
|
|
7
|
+
* what makes it safe to render, screenshot and paste.
|
|
8
|
+
*/
|
|
9
|
+
export declare const RUN_LOG_CAPACITY = 200;
|
|
10
|
+
export type NewRun = Omit<RunRecord, 'id' | 'seq' | 'ts'>;
|
|
11
|
+
export interface RunLog {
|
|
12
|
+
append(run: NewRun): RunRecord;
|
|
13
|
+
list(afterSeq?: number): {
|
|
14
|
+
runs: RunRecord[];
|
|
15
|
+
cursor: number;
|
|
16
|
+
};
|
|
17
|
+
clear(): void;
|
|
18
|
+
}
|
|
19
|
+
export declare function createRunLog(options?: {
|
|
20
|
+
capacity?: number;
|
|
21
|
+
now?: () => Date;
|
|
22
|
+
}): RunLog;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
const RUN_LOG_CAPACITY = 200;
|
|
3
|
+
function createRunLog(options = {}) {
|
|
4
|
+
const capacity = options.capacity ?? RUN_LOG_CAPACITY;
|
|
5
|
+
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
6
|
+
let seq = 0;
|
|
7
|
+
let rows = [];
|
|
8
|
+
return {
|
|
9
|
+
append(run) {
|
|
10
|
+
seq += 1;
|
|
11
|
+
const record = {
|
|
12
|
+
...run,
|
|
13
|
+
id: randomUUID(),
|
|
14
|
+
seq,
|
|
15
|
+
ts: now().toISOString()
|
|
16
|
+
};
|
|
17
|
+
rows.push(record);
|
|
18
|
+
if (rows.length > capacity) rows = rows.slice(rows.length - capacity);
|
|
19
|
+
return record;
|
|
20
|
+
},
|
|
21
|
+
list(afterSeq = 0) {
|
|
22
|
+
return { runs: rows.filter((row) => row.seq > afterSeq), cursor: seq };
|
|
23
|
+
},
|
|
24
|
+
clear() {
|
|
25
|
+
rows = [];
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
RUN_LOG_CAPACITY,
|
|
31
|
+
createRunLog
|
|
32
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type ContractOperation, EXECUTOR_LIMITS } from '@ekanos/integration-schema';
|
|
2
|
+
/**
|
|
3
|
+
* Executor semantics the harness mirrors from the host
|
|
4
|
+
* (its experience executor and output validation).
|
|
5
|
+
*
|
|
6
|
+
* Limits, reasons and messages come from `@ekanos/integration-schema`'s
|
|
7
|
+
* `executor-semantics.ts` (shared with the host and the conformance table), so
|
|
8
|
+
* a refusal reads the same locally as in prod. The input/output validators are
|
|
9
|
+
* the host's `validate-output.ts` behaviour, ported.
|
|
10
|
+
*/
|
|
11
|
+
export { EXECUTOR_LIMITS };
|
|
12
|
+
export type ExecutorLimits = {
|
|
13
|
+
maxInputBytes: number;
|
|
14
|
+
maxOutputBytes: number;
|
|
15
|
+
deadlineMs: number;
|
|
16
|
+
};
|
|
17
|
+
export declare const REFUSAL_MESSAGES: Record<"binding_missing" | "confirmation_required" | "deadline_exceeded" | "execution_failed" | "input_too_large" | "invalid_input" | "mode_not_permitted" | "operation_not_declared" | "operation_not_in_contract" | "output_invalid" | "output_too_large" | "product_unavailable" | "rate_limited" | "slot_unknown" | "write_not_approved" | "write_refused_on_channel", string>;
|
|
18
|
+
export type ValidationOutcome = {
|
|
19
|
+
valid: true;
|
|
20
|
+
} | {
|
|
21
|
+
valid: false;
|
|
22
|
+
reason: 'schema' | 'too_large' | 'opaque' | 'unserializable';
|
|
23
|
+
errors: string[];
|
|
24
|
+
};
|
|
25
|
+
export declare function jsonBytes(value: unknown): number | null;
|
|
26
|
+
export declare function validateInput(operation: ContractOperation, args: unknown, maxBytes?: number): ValidationOutcome;
|
|
27
|
+
/** Fail-closed: an opaque output half can never be shown to match anything. */
|
|
28
|
+
export declare function validateOutput(operation: ContractOperation, output: unknown, maxBytes?: number): ValidationOutcome;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EXECUTOR_LIMITS,
|
|
3
|
+
OPERATION_REFUSAL_MESSAGES,
|
|
4
|
+
validateAgainstSchema
|
|
5
|
+
} from "@ekanos/integration-schema";
|
|
6
|
+
const REFUSAL_MESSAGES = OPERATION_REFUSAL_MESSAGES;
|
|
7
|
+
function jsonBytes(value) {
|
|
8
|
+
try {
|
|
9
|
+
const text = JSON.stringify(value);
|
|
10
|
+
return text === void 0 ? null : Buffer.byteLength(text, "utf8");
|
|
11
|
+
} catch {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const MAX_REPORTED_ERRORS = 10;
|
|
16
|
+
function validateInput(operation, args, maxBytes = EXECUTOR_LIMITS.maxInputBytes) {
|
|
17
|
+
const size = jsonBytes(args ?? {});
|
|
18
|
+
if (size === null) {
|
|
19
|
+
return { valid: false, reason: "unserializable", errors: ["not JSON"] };
|
|
20
|
+
}
|
|
21
|
+
if (size > maxBytes) {
|
|
22
|
+
return {
|
|
23
|
+
valid: false,
|
|
24
|
+
reason: "too_large",
|
|
25
|
+
errors: [`input is ${size} bytes, above ${maxBytes}`]
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const errors = validateAgainstSchema(operation.input, args ?? {});
|
|
29
|
+
return errors.length === 0 ? { valid: true } : {
|
|
30
|
+
valid: false,
|
|
31
|
+
reason: "schema",
|
|
32
|
+
errors: errors.slice(0, MAX_REPORTED_ERRORS)
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function validateOutput(operation, output, maxBytes = EXECUTOR_LIMITS.maxOutputBytes) {
|
|
36
|
+
if (operation.opaque.output) {
|
|
37
|
+
return {
|
|
38
|
+
valid: false,
|
|
39
|
+
reason: "opaque",
|
|
40
|
+
errors: ["output is opaque: no executable validator"]
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const size = jsonBytes(output);
|
|
44
|
+
if (size === null) {
|
|
45
|
+
return { valid: false, reason: "unserializable", errors: ["not JSON"] };
|
|
46
|
+
}
|
|
47
|
+
if (size > maxBytes) {
|
|
48
|
+
return {
|
|
49
|
+
valid: false,
|
|
50
|
+
reason: "too_large",
|
|
51
|
+
errors: [`output is ${size} bytes, above ${maxBytes}`]
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const errors = validateAgainstSchema(operation.output, output);
|
|
55
|
+
return errors.length === 0 ? { valid: true } : {
|
|
56
|
+
valid: false,
|
|
57
|
+
reason: "schema",
|
|
58
|
+
errors: errors.slice(0, MAX_REPORTED_ERRORS)
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export {
|
|
62
|
+
EXECUTOR_LIMITS,
|
|
63
|
+
REFUSAL_MESSAGES,
|
|
64
|
+
jsonBytes,
|
|
65
|
+
validateInput,
|
|
66
|
+
validateOutput
|
|
67
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/** The dev's Source catalog as `ekanos dev` last handed it over (no token in it). */
|
|
2
|
+
export declare function readSessionCatalog(projectRoot: string): {
|
|
3
|
+
source: {
|
|
4
|
+
id: string;
|
|
5
|
+
slug: string;
|
|
6
|
+
name: string | null;
|
|
7
|
+
};
|
|
8
|
+
viewer: {
|
|
9
|
+
roles: ("developer" | "source_admin")[];
|
|
10
|
+
};
|
|
11
|
+
products: {
|
|
12
|
+
slug: string;
|
|
13
|
+
name: string;
|
|
14
|
+
summary: string | null;
|
|
15
|
+
kind: "experience" | "feature" | "integration";
|
|
16
|
+
availability: "available" | "enabled" | "turned-off";
|
|
17
|
+
partner: boolean;
|
|
18
|
+
owned?: boolean | undefined;
|
|
19
|
+
registered?: boolean | undefined;
|
|
20
|
+
scope: "team" | "user" | null;
|
|
21
|
+
selfServe: boolean;
|
|
22
|
+
requiresActivation: boolean;
|
|
23
|
+
requires: string[];
|
|
24
|
+
tools: {
|
|
25
|
+
name: string;
|
|
26
|
+
description: string;
|
|
27
|
+
effect: "read" | "write";
|
|
28
|
+
sensitivity: "financial" | "internal" | "pii" | "public" | "undeclared";
|
|
29
|
+
inputSchema?: Record<string, unknown> | undefined;
|
|
30
|
+
}[];
|
|
31
|
+
agentEvents: {
|
|
32
|
+
id: string;
|
|
33
|
+
label: string;
|
|
34
|
+
description: string;
|
|
35
|
+
filterFields: string[];
|
|
36
|
+
}[];
|
|
37
|
+
agentReplyTool: string | null;
|
|
38
|
+
teamApps: {
|
|
39
|
+
connectionId: string;
|
|
40
|
+
label: string | null;
|
|
41
|
+
description: string | null;
|
|
42
|
+
fields: {
|
|
43
|
+
label: string;
|
|
44
|
+
description: string | null;
|
|
45
|
+
sensitive: boolean;
|
|
46
|
+
}[];
|
|
47
|
+
guideUrl: string | null;
|
|
48
|
+
}[];
|
|
49
|
+
connectedTeams: number | null;
|
|
50
|
+
connectedPeople?: number | null | undefined;
|
|
51
|
+
connection?: {
|
|
52
|
+
connectedBy: "nobody" | "person" | "team";
|
|
53
|
+
runsUse: "creator" | "none" | "team";
|
|
54
|
+
sourceConnection: "connected" | "not_connected" | "unsupported";
|
|
55
|
+
} | undefined;
|
|
56
|
+
setupSteps: {
|
|
57
|
+
key: string;
|
|
58
|
+
title: string;
|
|
59
|
+
detail: string;
|
|
60
|
+
actor: "ekanos" | "source_admin" | "team";
|
|
61
|
+
state: "done" | "todo" | "unknown";
|
|
62
|
+
guideUrl: string | null;
|
|
63
|
+
consoleUrl?: string | null | undefined;
|
|
64
|
+
instructions?: string[] | undefined;
|
|
65
|
+
}[];
|
|
66
|
+
}[];
|
|
67
|
+
} | null;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SourceCatalogSchema } from "@ekanos/integration-schema";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
function readSessionCatalog(projectRoot) {
|
|
5
|
+
try {
|
|
6
|
+
const raw = fs.readFileSync(
|
|
7
|
+
path.join(projectRoot, ".ekanos", "session-catalog.json"),
|
|
8
|
+
"utf8"
|
|
9
|
+
);
|
|
10
|
+
const parsed = SourceCatalogSchema.safeParse(JSON.parse(raw));
|
|
11
|
+
return parsed.success ? parsed.data : null;
|
|
12
|
+
} catch {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
readSessionCatalog
|
|
18
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { InternalWriteGate, WorkflowRunResponse } from '../../api-types.js';
|
|
2
|
+
import type { ApprovalsTray } from './approvals.js';
|
|
3
|
+
import type { WorkflowDsl } from './experience-loader.js';
|
|
4
|
+
import type { RunOutcome } from './operation-runner.js';
|
|
5
|
+
/**
|
|
6
|
+
* Steps a workflow template through the operation runner, locally.
|
|
7
|
+
*
|
|
8
|
+
* fusion_tool -> runOperation on channel `workflow` (the integration is named by
|
|
9
|
+
* the step; integration, line and connection are derived)
|
|
10
|
+
* approval_gate -> a `gate` approval in the tray; approving it is the
|
|
11
|
+
* upstream gate the host demands before a write
|
|
12
|
+
* ai_step -> the fixture `fixtures/ai/<outputSchemaRef>.json`; none is
|
|
13
|
+
* a clear error, never an invented answer
|
|
14
|
+
* anything else -> listed `not-simulated`
|
|
15
|
+
*
|
|
16
|
+
* A write is gated by the most recent approved gate until a write to a
|
|
17
|
+
* DIFFERENT integration (one gate covers an integration's consecutive writes — the same rule
|
|
18
|
+
* `findWritesWithoutOwnGate` holds the template to).
|
|
19
|
+
*/
|
|
20
|
+
export interface WorkflowRunnerDeps {
|
|
21
|
+
projectRoot: string;
|
|
22
|
+
approvals: ApprovalsTray;
|
|
23
|
+
run: (request: {
|
|
24
|
+
integration: string;
|
|
25
|
+
op: string;
|
|
26
|
+
input: unknown;
|
|
27
|
+
channel: 'workflow';
|
|
28
|
+
origin: string;
|
|
29
|
+
}, gate: InternalWriteGate | undefined) => Promise<RunOutcome>;
|
|
30
|
+
approvalTimeoutMs?: number;
|
|
31
|
+
/** Read or write, from the resolved contract; wins over a step's own `effect`. */
|
|
32
|
+
effectOf?: (integration: string, op: string) => 'read' | 'write' | undefined;
|
|
33
|
+
}
|
|
34
|
+
/** Resolve `{ref:'a.b'}` objects and `{{a.b}}` templates against prior outputs. */
|
|
35
|
+
export declare function resolveArgs(value: unknown, context: Record<string, unknown>): unknown;
|
|
36
|
+
export declare function runWorkflow(workflow: WorkflowDsl, deps: WorkflowRunnerDeps): Promise<WorkflowRunResponse>;
|