@enhance-eng/enhance 0.1.168 → 0.1.171

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.
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
- import { $ as canvasAssetImportInputSchema, Dn as getMeOutputSchema, L as canvasPrototypeIntentSchema, On as MCP_AUTH_SCOPE, R as canvasPrototypeOutputSchema, S as PROTOTYPE_UPDATE_GUIDANCE, Tn as prototypeArtifactPathSchema, cn as CliError, di as signedDownloadSchema, et as canvasAssetImportOutputSchema, on as skillTextsFor, rn as MCP_TOOL_BY_CAPABILITY, xn as foldPrototypeArtifactPath } from "./cli-output-identity.lib-DMHqCPUz.mjs";
3
- import { h as createImportCanvasAssetComposite, m as createPublishCanvasPrototypeComposite, n as createMutationKeyAdapter, o as readRemoteMcpEnvironment, p as createPrototypeArtifactAdapter, r as createHttpRemoteAdapter, t as installZodMessages } from "./zod-messages.lib-T23QiUQO.mjs";
4
- import { c as createCapabilityCatalogAdapter, o as createMcpResultAdapter, s as createMcpClientContextAdapter, t as createMcpServerAdapter } from "./mcp-server.adapter-CUuoL6AI.mjs";
5
- import { n as createMcpCanvasProfileAdapter, t as createMcpInvocationAdapter } from "./mcp-invocation.adapter-YFCrLzlc.mjs";
2
+ import { An as foldPrototypeArtifactPath, B as canvasPrototypeOutputSchema, In as getMeOutputSchema, Ln as MCP_AUTH_SCOPE, Pn as prototypeArtifactPathSchema, Ti as signedDownloadSchema, _n as CliError, dn as pointOfUseText, gn as skillTextsFor, nt as canvasAssetImportOutputSchema, sn as MCP_TOOL_BY_CAPABILITY, tt as canvasAssetImportInputSchema, w as PROTOTYPE_UPDATE_GUIDANCE, z as canvasPrototypeIntentSchema } from "./cli-output-identity.lib-BsDqFLVA.mjs";
3
+ import { h as createImportCanvasAssetComposite, m as createPublishCanvasPrototypeComposite, n as createMutationKeyAdapter, o as readRemoteMcpEnvironment, p as createPrototypeArtifactAdapter, r as createHttpRemoteAdapter, t as installZodMessages } from "./zod-messages.lib-B8yowT7b.mjs";
4
+ import { c as withClientTokenNamed, l as createMcpClientContextAdapter, o as createMcpResultAdapter, s as toolClientToken, t as createMcpServerAdapter, u as createCapabilityCatalogAdapter } from "./mcp-server.adapter-CbObvH7Y.mjs";
5
+ import { n as createMcpCanvasProfileAdapter, t as createMcpInvocationAdapter } from "./mcp-invocation.adapter-DGgt79VT.mjs";
6
6
  import process from "node:process";
7
7
  import { z } from "zod";
8
8
  import { mkdir, mkdtemp, readFile, rm } from "node:fs/promises";
@@ -21,6 +21,18 @@ import { lookup } from "node:dns/promises";
21
21
  import { BlockList, isIP } from "node:net";
22
22
  import { open as open$1 } from "yauzl";
23
23
 
24
+ //#region src/infrastructure/api-refusal.lib.ts
25
+ const refusedByApiSchema = z.object({ data: z.looseObject({ code: z.literal("UNAUTHORIZED") }) });
26
+ /**
27
+ * Whether the API itself refused the credential. Only that says the credential is bad: a check
28
+ * that could not be made says nothing about it, and answering "invalid" for one sends a signed-in
29
+ * person to sign in again.
30
+ */
31
+ const isApiRefusal = (error) => error instanceof CliError ? error.code === "UNAUTHORIZED" : refusedByApiSchema.safeParse(error).success;
32
+ /** What to log when the check could not be made: the reason, which names no token. */
33
+ const uncheckedTokenError = (error) => /* @__PURE__ */ new Error(`token verification could not be made: ${error instanceof Error ? error.message : "unknown failure"}`);
34
+
35
+ //#endregion
24
36
  //#region src/infrastructure/mcp-canvas-ui.adapter.ts
25
37
  const HTTP_OK$1 = 200;
26
38
  const UI_TIMEOUT_MS = 15e3;
@@ -537,18 +549,20 @@ const selectedFile = async (remote, source) => {
537
549
  if (source.file !== void 0 && source.stagedUploadId !== void 0) throw new CliError("BAD_REQUEST", "Supply either a file or a staged upload, not both.", "Select one file and retry with the same clientToken.");
538
550
  return source.stagedUploadId === void 0 ? source.file : stagedFile(remote, source.stagedUploadId);
539
551
  };
540
- const transfer = async (action) => {
552
+ /** A transfer's answer, which names the retry token it used: the agent's, or one the tool made. */
553
+ const transfer = async (given, action) => {
554
+ const clientToken = toolClientToken(given);
541
555
  const result = createMcpResultAdapter("Select the same host file with a fresh download URL and reuse the original clientToken after uncertainty.");
542
556
  try {
543
- return await action();
557
+ return withClientTokenNamed(await action(clientToken), clientToken);
544
558
  } catch (error) {
545
- return result.failure(error);
559
+ return withClientTokenNamed(result.failure(error), clientToken);
546
560
  }
547
561
  };
548
562
  const registerAsset = (server, input) => {
549
563
  server.registerTool("asset_import", {
550
564
  title: "Import a canvas asset",
551
- description: "Import one file explicitly uploaded or selected in this host. Supply its authorized file reference, never a local path or an arbitrary URL. Accepts PNG, JPEG, GIF, WebP, AVIF, TTF, OTF, WOFF or WOFF2; verifies actual bytes and native metadata. Returns a durable resource without placing it or changing the canvas version. Retry with the same bytes and clientToken; a refreshed download URL is allowed.",
565
+ description: `Import one file explicitly uploaded or selected in this host. Supply its authorized file reference, never a local path or an arbitrary URL. Accepts PNG, JPEG, GIF, WebP, AVIF, TTF, OTF, WOFF or WOFF2; verifies actual bytes and native metadata. Returns a durable resource without placing it or changing the canvas version. Retry with the same bytes and clientToken; a refreshed download URL is allowed. ${pointOfUseText("import")}`,
552
566
  inputSchema: assetInputSchema,
553
567
  outputSchema: canvasAssetImportOutputSchema,
554
568
  annotations: {
@@ -558,11 +572,14 @@ const registerAsset = (server, input) => {
558
572
  openWorldHint: false
559
573
  },
560
574
  _meta: { "openai/fileParams": ["file"] }
561
- }, async (args, context) => clientContext$1.run(context, async () => transfer(async () => {
562
- const remote = input.remoteFor(args.clientToken);
575
+ }, async (args, context) => clientContext$1.run(context, async () => transfer(args.clientToken, async (clientToken) => {
576
+ const remote = input.remoteFor(clientToken);
563
577
  const file = await selectedFile(remote, args);
564
578
  if (file === void 0) throw new CliError("BAD_REQUEST", "No file was selected.", "Select the file to import and retry with the same clientToken.");
565
- const result = canvasAssetImportOutputSchema.parse(await createImportCanvasAssetComposite(remote, createMcpAssetFileAdapter(input.files, file)).execute(args));
579
+ const result = canvasAssetImportOutputSchema.parse(await createImportCanvasAssetComposite(remote, createMcpAssetFileAdapter(input.files, file)).execute({
580
+ ...args,
581
+ clientToken
582
+ }));
566
583
  return createMcpResultAdapter("Reconnect Enhance and retry the same intent.").structured(result);
567
584
  })));
568
585
  };
@@ -579,14 +596,17 @@ const registerPrototype = (server, input) => {
579
596
  openWorldHint: true
580
597
  },
581
598
  _meta: { "openai/fileParams": ["file"] }
582
- }, async ({ file: selected, stagedUploadId, ...args }, context) => clientContext$1.run(context, async () => transfer(async () => {
583
- const remote = input.remoteFor(args.clientToken);
599
+ }, async ({ file: selected, stagedUploadId, ...args }, context) => clientContext$1.run(context, async () => transfer(args.clientToken, async (clientToken) => {
600
+ const remote = input.remoteFor(clientToken);
584
601
  const file = await selectedFile(remote, {
585
602
  file: selected,
586
603
  stagedUploadId
587
604
  });
588
605
  if (args.source.kind === "build" !== (file !== void 0)) throw new CliError("BAD_REQUEST", "Supply a file only when publishing a new build.", "For a new build select its ZIP. To resume an existing deployment, omit file.");
589
- const result = canvasPrototypeOutputSchema.parse(await createPublishCanvasPrototypeComposite(remote, createMcpPrototypeArtifactAdapter(input.files, file)).execute(args));
606
+ const result = canvasPrototypeOutputSchema.parse(await createPublishCanvasPrototypeComposite(remote, createMcpPrototypeArtifactAdapter(input.files, file)).execute({
607
+ ...args,
608
+ clientToken
609
+ }));
590
610
  return createMcpResultAdapter("Reconnect Enhance and retry the same intent.").structured(result);
591
611
  })));
592
612
  };
@@ -710,7 +730,9 @@ const authVerifier = (config) => ({ verifyAccessToken: async (token) => {
710
730
  };
711
731
  } catch (error) {
712
732
  if (OAuthError.isInstance(error)) throw error;
713
- throw new OAuthError(OAuthErrorCode.InvalidToken, "token verification failed");
733
+ const code = isApiRefusal(error) ? OAuthErrorCode.InvalidToken : OAuthErrorCode.ServerError;
734
+ if (code === OAuthErrorCode.ServerError) config.onerror(uncheckedTokenError(error));
735
+ throw new OAuthError(code, "token verification failed");
714
736
  }
715
737
  } });
716
738
  const healthResponse = () => Response.json({
@@ -828,7 +850,7 @@ const server = await createRemoteMcpHttpAdapter({
828
850
  ...config.MCP_STAGED_UPLOAD_ORIGIN !== void 0 && { stagedUploadOrigin: config.MCP_STAGED_UPLOAD_ORIGIN },
829
851
  allowedHosts: config.MCP_ALLOWED_HOSTS.split(",").map((value) => value.trim()),
830
852
  allowedOrigins: config.MCP_ALLOWED_ORIGINS.split(",").map((value) => value.trim()),
831
- version: "0.1.168",
853
+ version: "0.1.171",
832
854
  ...config.MCP_UI_URL !== void 0 && { uiUrl: config.MCP_UI_URL },
833
855
  onerror: (error) => process.stderr.write(`${error.message}\n`)
834
856
  });