@enhance-eng/enhance 0.1.6 → 0.1.7
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/{capability-inventory.mapper-DN3TEDbU.mjs → capability-inventory.mapper-DyYXyVBJ.mjs} +2 -1
- package/dist/{failure.mapper-CNRVSTrf.mjs → cli-output-identity.lib-BSUBcRJm.mjs} +960 -140
- package/dist/{file-credential.adapter-WNl4GM58.mjs → file-credential.adapter-rI5HpMEo.mjs} +3 -1
- package/dist/main.mjs +406 -334
- package/dist/mcp-invocation.adapter-Bn41hcLB.mjs +64 -0
- package/dist/mcp-main.mjs +159 -9
- package/dist/{mcp-server.adapter-T8UqHf6A.mjs → mcp-server.adapter-lxpsuDlU.mjs} +145 -144
- package/dist/mcp.mjs +5 -4
- package/dist/{mutation-key.adapter-B7Ss_464.mjs → mutation-key.adapter-EvvklGSw.mjs} +267 -26
- package/dist/remote-mcp-main.mjs +11 -8
- package/package.json +1 -1
- package/dist/mcp-invocation.adapter-D0o0vb_-.mjs +0 -17
package/dist/mcp.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import { t as toCapabilityInventory } from "./capability-inventory.mapper-
|
|
4
|
-
import {
|
|
5
|
-
|
|
2
|
+
import { l as createCapabilityCatalogAdapter, o as toSharedCapabilities } from "./cli-output-identity.lib-BSUBcRJm.mjs";
|
|
3
|
+
import { t as toCapabilityInventory } from "./capability-inventory.mapper-DyYXyVBJ.mjs";
|
|
4
|
+
import { t as createMcpServerAdapter } from "./mcp-server.adapter-lxpsuDlU.mjs";
|
|
5
|
+
|
|
6
|
+
export { createCapabilityCatalogAdapter, createMcpServerAdapter as createEnhanceMcpServer, toCapabilityInventory, toSharedCapabilities };
|
|
@@ -1,17 +1,67 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { $ as
|
|
2
|
+
import { $ as createCanvasConversionOutputSchema, B as getMeOutputSchema, C as CliError, F as getPrototypeArtifactCapabilitiesOutputSchema, G as beginCanvasActivityOutputSchema, H as cliAuthConfigurationSchema, I as getPrototypePublishStatusOutputSchema, J as applyCanvasOperationsOutputSchema, L as prototypeArtifactManifestSchema, M as attachPrototypeArtifactOutputSchema, N as createPrototypeArtifactOutputSchema, P as foldPrototypeArtifactPath, R as prototypeArtifactPathSchema, S as PartialBatchError, U as createAgentTokenOutputSchema, Z as getCanvasDocumentOutputSchema, _ as canvasWriteHtmlCapabilityInputSchema, at as downloadCanvasRenderOutputSchema, b as recordingSnapshotCapabilityInputSchema, et as getCanvasConversionOutputSchema, g as canvasRenderCapabilityInputSchema, h as canvasApplyCapabilityInputSchema, it as createRecordingSnapshotOutputSchema, j as PROTOTYPE_ARTIFACT_MANIFEST_PATH, ot as getCanvasRenderOutputSchema, rt as createCanvasRenderOutputSchema, st as canvasSceneDocumentSchema, v as commentAttentionCapabilityInputSchema, w as transcriptOutputSchema, x as transcriptReadCapabilityInputSchema, y as prototypePublishCapabilityInputSchema, z as submitPrototypeArtifactOutputSchema } from "./cli-output-identity.lib-BSUBcRJm.mjs";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { homedir, tmpdir } from "node:os";
|
|
5
5
|
import process from "node:process";
|
|
6
6
|
import { chmodSync, createReadStream, createWriteStream, mkdirSync, writeFileSync } from "node:fs";
|
|
7
7
|
import path from "node:path";
|
|
8
|
-
import { createHash, randomUUID } from "node:crypto";
|
|
9
|
-
import { setTimeout } from "node:timers/promises";
|
|
8
|
+
import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|
9
|
+
import { setTimeout as setTimeout$1 } from "node:timers/promises";
|
|
10
10
|
import { mkdtemp, realpath, rm, stat } from "node:fs/promises";
|
|
11
11
|
import { Readable, Transform } from "node:stream";
|
|
12
12
|
import { pipeline } from "node:stream/promises";
|
|
13
13
|
import { ZipFile } from "yazl";
|
|
14
14
|
import { createTRPCUntypedClient, httpLink } from "@trpc/client";
|
|
15
|
+
import { spawn } from "node:child_process";
|
|
16
|
+
import { createServer } from "node:http";
|
|
17
|
+
|
|
18
|
+
//#region src/application/auth.use-case.ts
|
|
19
|
+
const TOKEN = /^enh_[\w-]{43}$/;
|
|
20
|
+
const authenticated = (value) => {
|
|
21
|
+
const parsed = getMeOutputSchema.parse(value);
|
|
22
|
+
if (parsed.authentication.kind !== "agent" || parsed.person === null) throw new CliError("UNAUTHORIZED", "The credential is missing, expired, revoked, or invalid.", "Run 'enhance auth login' and complete authentication in the browser.");
|
|
23
|
+
return {
|
|
24
|
+
authenticated: true,
|
|
25
|
+
personId: parsed.person.id,
|
|
26
|
+
displayName: parsed.person.displayName,
|
|
27
|
+
tokenId: parsed.authentication.tokenId,
|
|
28
|
+
tokenLabel: parsed.authentication.tokenLabel,
|
|
29
|
+
expiresAt: parsed.authentication.expiresAt
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
const createAuthUseCase = (credentials, remote, browser) => ({
|
|
33
|
+
loginWithToken: async (token) => {
|
|
34
|
+
if (!TOKEN.test(token)) throw new CliError("BAD_REQUEST", "Agent tokens begin with enh_ and contain 32 base64url bytes.", "Pass a manual token from Settings to 'enhance auth login' through stdin.");
|
|
35
|
+
const status = authenticated(await remote.queryWithToken("person.me", {}, token));
|
|
36
|
+
await credentials.write(token);
|
|
37
|
+
return status;
|
|
38
|
+
},
|
|
39
|
+
loginWithBrowser: async (input) => {
|
|
40
|
+
const configuration = cliAuthConfigurationSchema.parse(await remote.authenticationConfig());
|
|
41
|
+
if (configuration.method === "token") throw new CliError("BAD_REQUEST", "Browser authentication is not configured for this Enhance environment.", "Ask an administrator to configure CLI OAuth, or pass an agent token to 'enhance auth login --token'.");
|
|
42
|
+
const accessToken = await browser.authorize({
|
|
43
|
+
issuer: configuration.issuer,
|
|
44
|
+
clientId: configuration.clientId,
|
|
45
|
+
scope: configuration.scope,
|
|
46
|
+
openBrowser: input.openBrowser,
|
|
47
|
+
onReady: input.onReady
|
|
48
|
+
});
|
|
49
|
+
const created = createAgentTokenOutputSchema.parse(await remote.mutateWithToken("person.createAgentToken", {
|
|
50
|
+
label: input.label,
|
|
51
|
+
expiresAt: null
|
|
52
|
+
}, accessToken));
|
|
53
|
+
const status = authenticated(await remote.queryWithToken("person.me", {}, created.token));
|
|
54
|
+
await credentials.write(created.token);
|
|
55
|
+
return status;
|
|
56
|
+
},
|
|
57
|
+
status: async () => {
|
|
58
|
+
if (await credentials.read() === null) throw new CliError("UNAUTHORIZED", `No credential exists at ${credentials.path}.`, "A human must run 'enhance auth login'.");
|
|
59
|
+
return authenticated(await remote.query("person.me", {}));
|
|
60
|
+
},
|
|
61
|
+
logout: async () => ({ loggedOut: await credentials.remove() })
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
//#endregion
|
|
15
65
|
//#region src/application/render-png.use-case.ts
|
|
16
66
|
const PNG_SIGNATURE = Uint8Array.from(globalThis.atob("iVBORw0KGgo="), (character) => character.codePointAt(0) ?? 0);
|
|
17
67
|
const PNG_HEADER_BYTE_LENGTH = 24;
|
|
@@ -33,6 +83,7 @@ const downloadVerifiedRenderPng = async (remote, job) => {
|
|
|
33
83
|
if (dimensions === null || body.byteLength !== job.result.bytes || dimensions.width !== job.result.width || dimensions.height !== job.result.height) throw new CliError("INTERNAL", "The downloaded render did not match its completed job metadata.", `Do not use the image. Report render job ${job.id}.`);
|
|
34
84
|
return body;
|
|
35
85
|
};
|
|
86
|
+
|
|
36
87
|
//#endregion
|
|
37
88
|
//#region src/application/render-canvas.composite.ts
|
|
38
89
|
const POLL_MS$2 = 250;
|
|
@@ -151,6 +202,7 @@ const createRenderCanvasComposite = (remote, files, now, progress = () => null)
|
|
|
151
202
|
now,
|
|
152
203
|
progress
|
|
153
204
|
}, input) });
|
|
205
|
+
|
|
154
206
|
//#endregion
|
|
155
207
|
//#region src/application/canvas-activity.composite.ts
|
|
156
208
|
const PROCEDURES = {
|
|
@@ -219,6 +271,7 @@ const createCanvasActivityComposite = (remote) => ({
|
|
|
219
271
|
activityId
|
|
220
272
|
}))
|
|
221
273
|
});
|
|
274
|
+
|
|
222
275
|
//#endregion
|
|
223
276
|
//#region src/application/apply-canvas.composite.ts
|
|
224
277
|
const APPLY_PROCEDURE = "canvas.applyOperations";
|
|
@@ -289,6 +342,7 @@ const createApplyCanvasComposite = (remote) => ({ execute: async (input, options
|
|
|
289
342
|
await activity?.finish();
|
|
290
343
|
}
|
|
291
344
|
} });
|
|
345
|
+
|
|
292
346
|
//#endregion
|
|
293
347
|
//#region src/application/write-html-canvas.composite.ts
|
|
294
348
|
const READ_DOCUMENT_PROCEDURE = "canvas.document.get";
|
|
@@ -434,6 +488,7 @@ const createWriteHtmlCanvasComposite = (remote, render) => ({ execute: async (in
|
|
|
434
488
|
await activity?.finish();
|
|
435
489
|
}
|
|
436
490
|
} });
|
|
491
|
+
|
|
437
492
|
//#endregion
|
|
438
493
|
//#region src/infrastructure/render-file.adapter.ts
|
|
439
494
|
const DIRECTORY_MODE = 448;
|
|
@@ -475,6 +530,7 @@ const createRenderFileAdapter = (configDirectory) => ({ write: (input) => {
|
|
|
475
530
|
deleteAfter: new Date(input.at.getTime() + TEMPORARY_TTL_MS)
|
|
476
531
|
};
|
|
477
532
|
} });
|
|
533
|
+
|
|
478
534
|
//#endregion
|
|
479
535
|
//#region src/application/publish-prototype.composite.ts
|
|
480
536
|
const PUBLISH_WAIT_MS = 3e5;
|
|
@@ -496,7 +552,7 @@ const waitUntilSettled = async (remote, input) => {
|
|
|
496
552
|
if (!parsed.success) throw invalidResponse("status");
|
|
497
553
|
if (parsed.data.state === "ready" || parsed.data.state === "failed") return parsed.data;
|
|
498
554
|
if (parsed.data.state === "abandoned") throw new CliError("NOT_FOUND", `Prototype deployment ${input.deploymentId} was abandoned.`, "Publish the directory again with a new client token.");
|
|
499
|
-
await setTimeout(pollMs);
|
|
555
|
+
await setTimeout$1(pollMs);
|
|
500
556
|
pollMs = Math.min(pollMs * 2, MAX_POLL_MS);
|
|
501
557
|
}
|
|
502
558
|
throw new Error("prototype ingestion is still running");
|
|
@@ -572,6 +628,7 @@ const executePublish = async (remote, artifacts, input) => {
|
|
|
572
628
|
}
|
|
573
629
|
};
|
|
574
630
|
const createPublishPrototypeComposite = (remote, artifacts) => ({ execute: async (input) => executePublish(remote, artifacts, input) });
|
|
631
|
+
|
|
575
632
|
//#endregion
|
|
576
633
|
//#region src/application/read-transcript.composite.ts
|
|
577
634
|
const MAX_PREVIEW_COMMANDS = 3;
|
|
@@ -587,6 +644,7 @@ const createReadTranscriptComposite = (remote) => ({ execute: async (input) => {
|
|
|
587
644
|
next: previewCommands(input.canvasId, input.recordingId, parsed.data.cues.map((cue) => cue.startMs))
|
|
588
645
|
};
|
|
589
646
|
} });
|
|
647
|
+
|
|
590
648
|
//#endregion
|
|
591
649
|
//#region src/application/snapshot-recording.composite.ts
|
|
592
650
|
const POLL_MS = 250;
|
|
@@ -661,6 +719,7 @@ const executeSnapshot = async (remote, progress, input) => {
|
|
|
661
719
|
};
|
|
662
720
|
};
|
|
663
721
|
const createSnapshotRecordingComposite = (remote, progress) => ({ execute: async (input) => executeSnapshot(remote, progress, input) });
|
|
722
|
+
|
|
664
723
|
//#endregion
|
|
665
724
|
//#region src/infrastructure/prototype-zip.adapter.ts
|
|
666
725
|
const NORMALIZED_MTIME = /* @__PURE__ */ new Date("1980-01-01T00:00:00.000Z");
|
|
@@ -749,6 +808,7 @@ const createPrototypeZipAdapter = async (input) => {
|
|
|
749
808
|
sha256: hash.digest("hex")
|
|
750
809
|
};
|
|
751
810
|
};
|
|
811
|
+
|
|
752
812
|
//#endregion
|
|
753
813
|
//#region src/infrastructure/prototype-artifact.adapter.ts
|
|
754
814
|
const CONTENT_TYPES = {
|
|
@@ -873,6 +933,7 @@ const packageArtifact = async (input) => {
|
|
|
873
933
|
}
|
|
874
934
|
};
|
|
875
935
|
const createPrototypeArtifactAdapter = () => ({ package: packageArtifact });
|
|
936
|
+
|
|
876
937
|
//#endregion
|
|
877
938
|
//#region src/infrastructure/capability-invocation.adapter.ts
|
|
878
939
|
const renderFor = (input) => createRenderCanvasComposite(input.remote, createRenderFileAdapter(input.configDirectory), input.now ?? (() => /* @__PURE__ */ new Date()), input.progress ?? (() => null));
|
|
@@ -942,19 +1003,156 @@ const createCapabilityInvocationAdapter = (input) => ({ invoke: async ({ capabil
|
|
|
942
1003
|
if (capability.execution.kind === "composite") return invokeComposite(input, capability.id, parsed, selectedClientToken);
|
|
943
1004
|
return capability.operation === "query" ? input.remote.query(capability.execution.procedure, parsed) : input.remote.mutate(capability.execution.procedure, parsed);
|
|
944
1005
|
} });
|
|
1006
|
+
|
|
945
1007
|
//#endregion
|
|
946
|
-
//#region src/infrastructure/
|
|
947
|
-
const
|
|
948
|
-
const
|
|
949
|
-
const
|
|
950
|
-
const
|
|
951
|
-
const
|
|
952
|
-
const
|
|
953
|
-
|
|
954
|
-
|
|
1008
|
+
//#region src/infrastructure/oauth-loopback.adapter.ts
|
|
1009
|
+
const CALLBACK_PATH = "/callback";
|
|
1010
|
+
const AUTHORIZATION_TIMEOUT_MS = 12e4;
|
|
1011
|
+
const ENTROPY_BYTES = 32;
|
|
1012
|
+
const HTTP_OK = 200;
|
|
1013
|
+
const HTTP_BAD_REQUEST = 400;
|
|
1014
|
+
const HTTP_NOT_FOUND = 404;
|
|
1015
|
+
const SUCCESS_PAGE = "<!doctype html><meta charset=\"utf-8\"><title>Enhance authenticated</title><p>Enhance is authenticated. You can close this window.</p>";
|
|
1016
|
+
const endpoint = (issuer, path) => new URL(path, issuer.endsWith("/") ? issuer : `${issuer}/`);
|
|
1017
|
+
const launchBrowser = (url) => {
|
|
1018
|
+
const command = process.platform === "darwin" ? {
|
|
1019
|
+
executable: "open",
|
|
1020
|
+
arguments: [url]
|
|
1021
|
+
} : process.platform === "win32" ? {
|
|
1022
|
+
executable: "rundll32.exe",
|
|
1023
|
+
arguments: ["url.dll,FileProtocolHandler", url]
|
|
1024
|
+
} : {
|
|
1025
|
+
executable: "xdg-open",
|
|
1026
|
+
arguments: [url]
|
|
1027
|
+
};
|
|
1028
|
+
const child = spawn(command.executable, command.arguments, {
|
|
1029
|
+
detached: true,
|
|
1030
|
+
stdio: "ignore"
|
|
1031
|
+
});
|
|
1032
|
+
child.once("error", () => false);
|
|
1033
|
+
child.unref();
|
|
955
1034
|
};
|
|
1035
|
+
const handleCallback = (input, request, response) => {
|
|
1036
|
+
const url = new URL(request.url ?? "/", "http://127.0.0.1");
|
|
1037
|
+
if (request.method !== "GET" || url.pathname !== CALLBACK_PATH) {
|
|
1038
|
+
response.writeHead(HTTP_NOT_FOUND).end();
|
|
1039
|
+
return;
|
|
1040
|
+
}
|
|
1041
|
+
if (url.searchParams.get("state") !== input.state) {
|
|
1042
|
+
response.writeHead(HTTP_BAD_REQUEST).end("The OAuth state did not match. Return to the terminal and retry.");
|
|
1043
|
+
return;
|
|
1044
|
+
}
|
|
1045
|
+
const error = url.searchParams.get("error");
|
|
1046
|
+
const received = url.searchParams.get("code");
|
|
1047
|
+
if (error !== null || received === null || received === "") {
|
|
1048
|
+
response.writeHead(HTTP_BAD_REQUEST).end("Enhance authentication was not approved.");
|
|
1049
|
+
input.completion.reject(new Error(error ?? "the authorization response carried no code"));
|
|
1050
|
+
return;
|
|
1051
|
+
}
|
|
1052
|
+
response.writeHead(HTTP_OK, { "content-type": "text/html; charset=utf-8" }).end(SUCCESS_PAGE);
|
|
1053
|
+
input.completion.resolve(received);
|
|
1054
|
+
};
|
|
1055
|
+
const authorizeUrl = (input) => {
|
|
1056
|
+
const authorize = endpoint(input.issuer, "oauth/authorize");
|
|
1057
|
+
authorize.search = new URLSearchParams({
|
|
1058
|
+
response_type: "code",
|
|
1059
|
+
client_id: input.clientId,
|
|
1060
|
+
redirect_uri: input.redirectUri,
|
|
1061
|
+
scope: input.scope,
|
|
1062
|
+
state: input.state,
|
|
1063
|
+
code_challenge: input.challenge,
|
|
1064
|
+
code_challenge_method: "S256"
|
|
1065
|
+
}).toString();
|
|
1066
|
+
return authorize.href;
|
|
1067
|
+
};
|
|
1068
|
+
const authorizationCode = async (input) => {
|
|
1069
|
+
const completion = Promise.withResolvers();
|
|
1070
|
+
const server = createServer((request, response) => {
|
|
1071
|
+
handleCallback({
|
|
1072
|
+
state: input.state,
|
|
1073
|
+
completion
|
|
1074
|
+
}, request, response);
|
|
1075
|
+
});
|
|
1076
|
+
await new Promise((resolve, reject) => {
|
|
1077
|
+
server.once("error", reject);
|
|
1078
|
+
server.listen(0, "127.0.0.1", resolve);
|
|
1079
|
+
});
|
|
1080
|
+
const address = server.address();
|
|
1081
|
+
if (address === null || typeof address === "string") {
|
|
1082
|
+
server.close();
|
|
1083
|
+
throw new Error("the OAuth callback listener has no TCP port");
|
|
1084
|
+
}
|
|
1085
|
+
const redirectUri = `http://127.0.0.1:${String(address.port)}${CALLBACK_PATH}`;
|
|
1086
|
+
const url = authorizeUrl({
|
|
1087
|
+
...input,
|
|
1088
|
+
redirectUri
|
|
1089
|
+
});
|
|
1090
|
+
input.onReady(url);
|
|
1091
|
+
if (input.openBrowser) launchBrowser(url);
|
|
1092
|
+
const timeout = setTimeout(() => {
|
|
1093
|
+
completion.reject(/* @__PURE__ */ new Error("browser authorization timed out"));
|
|
1094
|
+
}, AUTHORIZATION_TIMEOUT_MS);
|
|
1095
|
+
try {
|
|
1096
|
+
return {
|
|
1097
|
+
code: await completion.promise,
|
|
1098
|
+
redirectUri
|
|
1099
|
+
};
|
|
1100
|
+
} finally {
|
|
1101
|
+
clearTimeout(timeout);
|
|
1102
|
+
await new Promise((resolve) => {
|
|
1103
|
+
server.close(() => {
|
|
1104
|
+
resolve();
|
|
1105
|
+
});
|
|
1106
|
+
});
|
|
1107
|
+
}
|
|
1108
|
+
};
|
|
1109
|
+
const createOauthLoopbackAdapter = (remote) => ({ authorize: async (input) => {
|
|
1110
|
+
try {
|
|
1111
|
+
const verifier = randomBytes(ENTROPY_BYTES).toString("base64url");
|
|
1112
|
+
const challenge = createHash("sha256").update(verifier).digest("base64url");
|
|
1113
|
+
const state = randomBytes(ENTROPY_BYTES).toString("base64url");
|
|
1114
|
+
const authorized = await authorizationCode({
|
|
1115
|
+
...input,
|
|
1116
|
+
challenge,
|
|
1117
|
+
state
|
|
1118
|
+
});
|
|
1119
|
+
return await remote.exchangeOauthCode({
|
|
1120
|
+
issuer: input.issuer,
|
|
1121
|
+
clientId: input.clientId,
|
|
1122
|
+
code: authorized.code,
|
|
1123
|
+
redirectUri: authorized.redirectUri,
|
|
1124
|
+
verifier
|
|
1125
|
+
});
|
|
1126
|
+
} catch (error) {
|
|
1127
|
+
throw new CliError("UNAUTHORIZED", error instanceof Error ? `Browser authentication failed: ${error.message}.` : "Browser authentication failed.", "Run 'enhance auth login' again, complete the browser consent, and keep the terminal open.");
|
|
1128
|
+
}
|
|
1129
|
+
} });
|
|
1130
|
+
|
|
1131
|
+
//#endregion
|
|
1132
|
+
//#region src/infrastructure/environment-profile.lib.ts
|
|
1133
|
+
const explicitValue = (value) => value === void 0 || value === "" ? void 0 : value;
|
|
1134
|
+
const resolveCliConfig = (variables, homeDirectory, release) => {
|
|
1135
|
+
const requestedEnvironment = explicitValue(variables.ENHANCE3_ENVIRONMENT);
|
|
1136
|
+
if (requestedEnvironment !== void 0 && requestedEnvironment !== release.environment) throw new TypeError(`the Enhance ${release.environment} CLI cannot target ${requestedEnvironment}`);
|
|
1137
|
+
const requestedApi = explicitValue(variables.ENHANCE3_API_URL);
|
|
1138
|
+
const expectedConfigDirectory = path.join(homeDirectory, ".config", release.configDirectoryName);
|
|
1139
|
+
const requestedConfigDirectory = explicitValue(variables.ENHANCE3_CONFIG_DIR);
|
|
1140
|
+
if (release.environment === "development") {
|
|
1141
|
+
if (requestedApi !== void 0 && requestedApi !== release.apiUrl) throw new TypeError(`Enhance development cannot use ${requestedApi}`);
|
|
1142
|
+
if (requestedConfigDirectory !== void 0 && path.resolve(requestedConfigDirectory) !== path.resolve(expectedConfigDirectory)) throw new TypeError(`Enhance development credentials must stay in ${expectedConfigDirectory}`);
|
|
1143
|
+
}
|
|
1144
|
+
return {
|
|
1145
|
+
apiUrl: requestedApi ?? release.apiUrl,
|
|
1146
|
+
commandName: release.commandName,
|
|
1147
|
+
configDirectory: requestedConfigDirectory ?? expectedConfigDirectory,
|
|
1148
|
+
mcpServiceName: release.mcpServiceName
|
|
1149
|
+
};
|
|
1150
|
+
};
|
|
1151
|
+
|
|
1152
|
+
//#endregion
|
|
1153
|
+
//#region src/infrastructure/remote-mcp.config.ts
|
|
956
1154
|
const remoteMcpConfigSchema = z.object({
|
|
957
|
-
PORT: z.coerce.number().int().min(
|
|
1155
|
+
PORT: z.coerce.number().int().min(1).max(65535).default(3e3),
|
|
958
1156
|
MCP_HOST: z.string().min(1).default("0.0.0.0"),
|
|
959
1157
|
ENHANCE_API_URL: z.url(),
|
|
960
1158
|
MCP_AUTH_ISSUER: z.url(),
|
|
@@ -963,15 +1161,54 @@ const remoteMcpConfigSchema = z.object({
|
|
|
963
1161
|
MCP_ALLOWED_HOSTS: z.string().min(1),
|
|
964
1162
|
MCP_ALLOWED_ORIGINS: z.string().min(1).default("claude.ai,claude.com")
|
|
965
1163
|
});
|
|
966
|
-
const readRemoteMcpConfig = () => remoteMcpConfigSchema.parse(
|
|
1164
|
+
const readRemoteMcpConfig = (variables) => remoteMcpConfigSchema.parse(variables);
|
|
1165
|
+
|
|
1166
|
+
//#endregion
|
|
1167
|
+
//#region src/infrastructure/environment.config.ts
|
|
1168
|
+
const releaseProfile = {
|
|
1169
|
+
apiUrl: "https://api.enhancelabs.ai",
|
|
1170
|
+
commandName: "enhance",
|
|
1171
|
+
configDirectoryName: "enhance",
|
|
1172
|
+
environment: "production",
|
|
1173
|
+
mcpServiceName: "enhance-mcp"
|
|
1174
|
+
};
|
|
1175
|
+
const CLI_CONFIG = resolveCliConfig(process.env, homedir(), releaseProfile);
|
|
1176
|
+
const readRemoteMcpEnvironment = () => readRemoteMcpConfig(process.env);
|
|
1177
|
+
|
|
967
1178
|
//#endregion
|
|
968
1179
|
//#region src/infrastructure/http-remote.adapter.ts
|
|
969
1180
|
const HEALTH_TIMEOUT_MS = 4e3;
|
|
970
1181
|
const NOT_FOUND_STATUS = 404;
|
|
971
1182
|
const FORBIDDEN_STATUS = 403;
|
|
972
1183
|
const oauthTokenResponseSchema = z.object({ access_token: z.string().min(1) });
|
|
1184
|
+
const networkCodeSchema = z.object({ code: z.string().regex(/^[A-Z][A-Z_0-9]+$/u) });
|
|
1185
|
+
const NETWORK_REMEDIATION = "Check network access and proxy settings for this API, then run enhance doctor again.";
|
|
1186
|
+
const originOf = (input) => new URL(typeof input === "string" ? input : input instanceof URL ? input.href : input.url).origin;
|
|
1187
|
+
const networkReason = (error) => {
|
|
1188
|
+
const parsed = networkCodeSchema.safeParse(error);
|
|
1189
|
+
if (parsed.success) return parsed.data.code;
|
|
1190
|
+
if (error instanceof Error && error.cause !== void 0) return networkReason(error.cause);
|
|
1191
|
+
return error instanceof Error ? error.name : "Network request failed";
|
|
1192
|
+
};
|
|
1193
|
+
const httpFailure = (url, status) => new CliError("INTERNAL", `${originOf(url)} answered HTTP ${String(status)}.`, NETWORK_REMEDIATION);
|
|
1194
|
+
const fetchNetwork = async (input, init) => {
|
|
1195
|
+
try {
|
|
1196
|
+
return await fetch(input, init);
|
|
1197
|
+
} catch (error) {
|
|
1198
|
+
throw new CliError("INTERNAL", `Could not reach ${originOf(input)}: ${networkReason(error)}.`, NETWORK_REMEDIATION);
|
|
1199
|
+
}
|
|
1200
|
+
};
|
|
1201
|
+
const fetchApi = async (input, init) => {
|
|
1202
|
+
const response = await fetchNetwork(input, init);
|
|
1203
|
+
if (!response.ok && response.headers.get("content-type")?.includes("application/json") !== true) throw httpFailure(input, response.status);
|
|
1204
|
+
return response;
|
|
1205
|
+
};
|
|
973
1206
|
const clientFor = (apiUrl, token, idempotencyKey = null) => createTRPCUntypedClient({ links: [httpLink({
|
|
974
1207
|
url: `${apiUrl}/trpc`,
|
|
1208
|
+
fetch: async (input, init) => fetchApi(input, {
|
|
1209
|
+
...init,
|
|
1210
|
+
signal: init?.signal ?? null
|
|
1211
|
+
}),
|
|
975
1212
|
headers: {
|
|
976
1213
|
...token !== null && { authorization: `Bearer ${token}` },
|
|
977
1214
|
...idempotencyKey !== null && { "x-enhance-idempotency-key": idempotencyKey }
|
|
@@ -983,21 +1220,21 @@ const download = async (url) => {
|
|
|
983
1220
|
return new Uint8Array(await response.arrayBuffer());
|
|
984
1221
|
};
|
|
985
1222
|
const authenticationConfig = async (apiUrl) => {
|
|
986
|
-
const response = await
|
|
1223
|
+
const response = await fetchNetwork(`${apiUrl}/v1/cli-auth`);
|
|
987
1224
|
if (!response.ok) {
|
|
988
1225
|
if (response.status === NOT_FOUND_STATUS) throw new CliError("BAD_REQUEST", "This Enhance API does not support browser authentication.", "Deploy a compatible API, or pass an agent token to 'enhance auth login --token'.");
|
|
989
|
-
throw new CliError("INTERNAL",
|
|
1226
|
+
throw new CliError("INTERNAL", `${originOf(apiUrl)} CLI authentication discovery answered HTTP ${String(response.status)}.`, NETWORK_REMEDIATION);
|
|
990
1227
|
}
|
|
991
1228
|
return response.json();
|
|
992
1229
|
};
|
|
993
1230
|
const oauthMetadata = async (issuer) => {
|
|
994
1231
|
const base = issuer.endsWith("/") ? issuer : `${issuer}/`;
|
|
995
|
-
const response = await
|
|
996
|
-
if (!response.ok) throw
|
|
1232
|
+
const response = await fetchNetwork(new URL(".well-known/oauth-authorization-server", base));
|
|
1233
|
+
if (!response.ok) throw httpFailure(issuer, response.status);
|
|
997
1234
|
return response.json();
|
|
998
1235
|
};
|
|
999
1236
|
const exchangeOauthCode = async (input) => {
|
|
1000
|
-
const response = await
|
|
1237
|
+
const response = await fetchNetwork(new URL("oauth/token", input.issuer.endsWith("/") ? input.issuer : `${input.issuer}/`), {
|
|
1001
1238
|
method: "POST",
|
|
1002
1239
|
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
1003
1240
|
body: new URLSearchParams({
|
|
@@ -1008,22 +1245,24 @@ const exchangeOauthCode = async (input) => {
|
|
|
1008
1245
|
code_verifier: input.verifier
|
|
1009
1246
|
})
|
|
1010
1247
|
});
|
|
1011
|
-
if (!response.ok) throw new
|
|
1248
|
+
if (!response.ok) throw new CliError("INTERNAL", `${originOf(input.issuer)} token exchange answered HTTP ${String(response.status)}`, NETWORK_REMEDIATION);
|
|
1012
1249
|
return oauthTokenResponseSchema.parse(await response.json()).access_token;
|
|
1013
1250
|
};
|
|
1014
1251
|
const health = async (apiUrl) => {
|
|
1015
1252
|
try {
|
|
1016
|
-
const response = await
|
|
1253
|
+
const response = await fetchNetwork(`${apiUrl}/health`, { signal: AbortSignal.timeout(HEALTH_TIMEOUT_MS) });
|
|
1017
1254
|
return {
|
|
1018
1255
|
url: apiUrl,
|
|
1019
1256
|
reachable: response.ok,
|
|
1020
|
-
status: response.status
|
|
1257
|
+
status: response.status,
|
|
1258
|
+
...!response.ok && { error: httpFailure(apiUrl, response.status).message }
|
|
1021
1259
|
};
|
|
1022
|
-
} catch {
|
|
1260
|
+
} catch (error) {
|
|
1023
1261
|
return {
|
|
1024
1262
|
url: apiUrl,
|
|
1025
1263
|
reachable: false,
|
|
1026
|
-
status: null
|
|
1264
|
+
status: null,
|
|
1265
|
+
error: error instanceof Error ? error.message : `Could not reach ${originOf(apiUrl)}.`
|
|
1027
1266
|
};
|
|
1028
1267
|
}
|
|
1029
1268
|
};
|
|
@@ -1056,6 +1295,7 @@ const createHttpRemoteAdapter = (apiUrl, credentials, mutationKey) => {
|
|
|
1056
1295
|
health: async () => health(normalized)
|
|
1057
1296
|
};
|
|
1058
1297
|
};
|
|
1298
|
+
|
|
1059
1299
|
//#endregion
|
|
1060
1300
|
//#region src/infrastructure/mutation-key.adapter.ts
|
|
1061
1301
|
const ordered = (value) => {
|
|
@@ -1077,5 +1317,6 @@ const createMutationKeyAdapter = () => {
|
|
|
1077
1317
|
}
|
|
1078
1318
|
};
|
|
1079
1319
|
};
|
|
1320
|
+
|
|
1080
1321
|
//#endregion
|
|
1081
|
-
export {
|
|
1322
|
+
export { createOauthLoopbackAdapter as a, createWriteHtmlCanvasComposite as c, createRenderCanvasComposite as d, createAuthUseCase as f, readRemoteMcpEnvironment as i, createApplyCanvasComposite as l, createHttpRemoteAdapter as n, createCapabilityInvocationAdapter as o, CLI_CONFIG as r, createRenderFileAdapter as s, createMutationKeyAdapter as t, createCanvasActivityComposite as u };
|
package/dist/remote-mcp-main.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import { i as
|
|
4
|
-
import { t as createMcpInvocationAdapter } from "./mcp-invocation.adapter-
|
|
5
|
-
import { t as createMcpServerAdapter } from "./mcp-server.adapter-
|
|
2
|
+
import { B as getMeOutputSchema, V as MCP_AUTH_SCOPE, l as createCapabilityCatalogAdapter } from "./cli-output-identity.lib-BSUBcRJm.mjs";
|
|
3
|
+
import { i as readRemoteMcpEnvironment, n as createHttpRemoteAdapter, t as createMutationKeyAdapter } from "./mutation-key.adapter-EvvklGSw.mjs";
|
|
4
|
+
import { t as createMcpInvocationAdapter } from "./mcp-invocation.adapter-Bn41hcLB.mjs";
|
|
5
|
+
import { t as createMcpServerAdapter } from "./mcp-server.adapter-lxpsuDlU.mjs";
|
|
6
6
|
import os from "node:os";
|
|
7
7
|
import process from "node:process";
|
|
8
8
|
import path from "node:path";
|
|
@@ -10,6 +10,7 @@ import { createServer } from "node:http";
|
|
|
10
10
|
import { OAuthError, OAuthErrorCode, createMcpHandler, getOAuthProtectedResourceMetadataUrl, hostHeaderValidationResponse, oauthMetadataResponse, originValidationResponse, requireBearerAuth } from "@modelcontextprotocol/server";
|
|
11
11
|
import { OAuthMetadataSchema } from "@modelcontextprotocol/core";
|
|
12
12
|
import { toNodeHandler } from "@modelcontextprotocol/node";
|
|
13
|
+
|
|
13
14
|
//#region src/infrastructure/remote-mcp-http.adapter.ts
|
|
14
15
|
const SECOND_MS = 1e3;
|
|
15
16
|
const BAD_REQUEST = 400;
|
|
@@ -106,7 +107,7 @@ const createRemoteMcpHttpAdapter = async (config) => {
|
|
|
106
107
|
const credentials = credentialFor(authInfo.token, config.configDirectory);
|
|
107
108
|
return createMcpServerAdapter({
|
|
108
109
|
version: config.version,
|
|
109
|
-
invocation: createMcpInvocationAdapter(config.apiUrl, credentials, config.configDirectory),
|
|
110
|
+
invocation: createMcpInvocationAdapter(config.apiUrl, credentials, config.configDirectory, config.version),
|
|
110
111
|
catalog,
|
|
111
112
|
delivery: "embedded"
|
|
112
113
|
});
|
|
@@ -132,9 +133,10 @@ const createRemoteMcpHttpAdapter = async (config) => {
|
|
|
132
133
|
}
|
|
133
134
|
};
|
|
134
135
|
};
|
|
136
|
+
|
|
135
137
|
//#endregion
|
|
136
138
|
//#region src/remote-mcp-main.ts
|
|
137
|
-
const config =
|
|
139
|
+
const config = readRemoteMcpEnvironment();
|
|
138
140
|
const server = await createRemoteMcpHttpAdapter({
|
|
139
141
|
apiUrl: config.ENHANCE_API_URL,
|
|
140
142
|
issuer: config.MCP_AUTH_ISSUER,
|
|
@@ -143,7 +145,7 @@ const server = await createRemoteMcpHttpAdapter({
|
|
|
143
145
|
configDirectory: path.join(os.tmpdir(), "enhance-remote-mcp"),
|
|
144
146
|
allowedHosts: config.MCP_ALLOWED_HOSTS.split(",").map((value) => value.trim()),
|
|
145
147
|
allowedOrigins: config.MCP_ALLOWED_ORIGINS.split(",").map((value) => value.trim()),
|
|
146
|
-
version: "0.1.
|
|
148
|
+
version: "0.1.7",
|
|
147
149
|
onerror: (error) => process.stderr.write(`${error.message}\n`)
|
|
148
150
|
});
|
|
149
151
|
await server.listen(config.PORT, config.MCP_HOST);
|
|
@@ -157,5 +159,6 @@ const shutdown = () => {
|
|
|
157
159
|
};
|
|
158
160
|
process.once("SIGINT", shutdown);
|
|
159
161
|
process.once("SIGTERM", shutdown);
|
|
162
|
+
|
|
160
163
|
//#endregion
|
|
161
|
-
export {};
|
|
164
|
+
export { };
|
package/package.json
CHANGED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { a as createCapabilityInvocationAdapter, n as createHttpRemoteAdapter, t as createMutationKeyAdapter } from "./mutation-key.adapter-B7Ss_464.mjs";
|
|
3
|
-
//#region src/infrastructure/mcp-invocation.adapter.ts
|
|
4
|
-
const createMcpInvocationAdapter = (apiUrl, credentials, configDirectory) => ({ invoke: async ({ capability, arguments: offered, clientToken }) => {
|
|
5
|
-
const mutationKey = createMutationKeyAdapter();
|
|
6
|
-
return createCapabilityInvocationAdapter({
|
|
7
|
-
remote: createHttpRemoteAdapter(apiUrl, credentials, mutationKey),
|
|
8
|
-
mutationKey,
|
|
9
|
-
configDirectory
|
|
10
|
-
}).invoke({
|
|
11
|
-
capability,
|
|
12
|
-
arguments: offered,
|
|
13
|
-
clientToken
|
|
14
|
-
});
|
|
15
|
-
} });
|
|
16
|
-
//#endregion
|
|
17
|
-
export { createMcpInvocationAdapter as t };
|